Пример #1
0
def test_TRpower():
    assert TRpower(1/sin(x)**2) == 1/sin(x)**2
    assert TRpower(cos(x)**3*sin(x/2)**4) == \
        (3*cos(x)/4 + cos(3*x)/4)*(-cos(x)/2 + cos(2*x)/8 + S(3)/8)
    for k in range(2, 8):
        assert verify_numerically(sin(x)**k, TRpower(sin(x)**k))
        assert verify_numerically(cos(x)**k, TRpower(cos(x)**k))
Пример #2
0
def test_roots_quartic():
    assert roots_quartic(Poly(x**4, x)) == [0, 0, 0, 0]
    assert roots_quartic(Poly(x**4 + x**3, x)) in [
        [-1, 0, 0, 0],
        [0, -1, 0, 0],
        [0, 0, -1, 0],
        [0, 0, 0, -1]
    ]
    assert roots_quartic(Poly(x**4 - x**3, x)) in [
        [1, 0, 0, 0],
        [0, 1, 0, 0],
        [0, 0, 1, 0],
        [0, 0, 0, 1]
    ]

    lhs = roots_quartic(Poly(x**4 + x, x))
    rhs = [S.Half + I*sqrt(3)/2, S.Half - I*sqrt(3)/2, S.Zero, -S.One]

    assert sorted(lhs, key=hash) == sorted(rhs, key=hash)

    # test of all branches of roots quartic
    for i, (a, b, c, d) in enumerate([(1, 2, 3, 0),
                                      (3, -7, -9, 9),
                                      (1, 2, 3, 4),
                                      (1, 2, 3, 4),
                                      (-7, -3, 3, -6),
                                      (-3, 5, -6, -4),
                                      (6, -5, -10, -3)]):
        if i == 2:
            c = -a*(a**2/S(8) - b/S(2))
        elif i == 3:
            d = a*(a*(3*a**2/S(256) - b/S(16)) + c/S(4))
        eq = x**4 + a*x**3 + b*x**2 + c*x + d
        ans = roots_quartic(Poly(eq, x))
        assert all(eq.subs(x, ai).n(chop=True) == 0 for ai in ans)

    # not all symbolic quartics are unresolvable
    eq = Poly(q*x + q/4 + x**4 + x**3 + 2*x**2 - Rational(1, 3), x)
    sol = roots_quartic(eq)
    assert all(verify_numerically(eq.subs(x, i), 0) for i in sol)
    z = symbols('z', negative=True)
    eq = x**4 + 2*x**3 + 3*x**2 + x*(z + 11) + 5
    zans = roots_quartic(Poly(eq, x))
    assert all([verify_numerically(eq.subs(((x, i), (z, -1))), 0) for i in zans])
    # but some are (see also issue 4989)
    # it's ok if the solution is not Piecewise, but the tests below should pass
    eq = Poly(y*x**4 + x**3 - x + z, x)
    ans = roots_quartic(eq)
    assert all(type(i) == Piecewise for i in ans)
    reps = (
        dict(y=-Rational(1, 3), z=-Rational(1, 4)),  # 4 real
        dict(y=-Rational(1, 3), z=-Rational(1, 2)),  # 2 real
        dict(y=-Rational(1, 3), z=-2))  # 0 real
    for rep in reps:
        sol = roots_quartic(Poly(eq.subs(rep), x))
        assert all([verify_numerically(w.subs(rep) - s, 0) for w, s in zip(ans, sol)])
Пример #3
0
 def t(a, b, arg, n):
     from sympy import Mul
     m1 = meijerg(a, b, arg)
     m2 = Mul(*_inflate_g(m1, n))
     # NOTE: (the random number)**9 must still be on the principal sheet.
     # Thus make b&d small to create random numbers of small imaginary part.
     return verify_numerically(m1.subs(subs), m2.subs(subs), x, b=0.1, d=-0.1)
Пример #4
0
 def t(fac, arg):
     g = meijerg([a], [b], [c], [d], arg)*fac
     subs = {a: randcplx()/10, b: randcplx()/10 + I,
             c: randcplx(), d: randcplx()}
     integral = meijerint_indefinite(g, x)
     assert integral is not None
     assert verify_numerically(g.subs(subs), integral.diff(x).subs(subs), x)
Пример #5
0
 def t(fac, arg):
     g = meijerg([a], [b], [c], [d], arg)*fac
     subs = {a: randcplx()/10, b: randcplx()/10 + I,
             c: randcplx(), d: randcplx()}
     integral = meijerint_indefinite(g, x)
     assert integral is not None
     assert verify_numerically(g.subs(subs), integral.diff(x).subs(subs), x)
Пример #6
0
def test_TR9():
    a = S(1)/2
    b = 3*a
    assert TR9(a) == a
    assert TR9(cos(1) + cos(2)) == 2*cos(a)*cos(b)
    assert TR9(cos(1) - cos(2)) == 2*sin(a)*sin(b)
    assert TR9(sin(1) - sin(2)) == -2*sin(a)*cos(b)
    assert TR9(sin(1) + sin(2)) == 2*sin(b)*cos(a)
    assert TR9(cos(1) + 2*sin(1) + 2*sin(2)) == cos(1) + 4*sin(b)*cos(a)
    assert TR9(cos(4) + cos(2) + 2*cos(1)*cos(3)) == 4*cos(1)*cos(3)
    assert TR9((cos(4) + cos(2))/cos(3)/2 + cos(3)) == 2*cos(1)*cos(2)
    assert TR9(cos(3) + cos(4) + cos(5) + cos(6)) == \
        4*cos(S(1)/2)*cos(1)*cos(S(9)/2)
    assert TR9(cos(3) + cos(3)*cos(2)) == cos(3) + cos(2)*cos(3)
    assert TR9(-cos(y) + cos(x*y)) == -2*sin(x*y/2 - y/2)*sin(x*y/2 + y/2)
    assert TR9(-sin(y) + sin(x*y)) == 2*sin(x*y/2 - y/2)*cos(x*y/2 + y/2)
    c = cos(x)
    s = sin(x)
    for si in ((1, 1), (1, -1), (-1, 1), (-1, -1)):
        for a in ((c, s), (s, c), (cos(x), cos(x*y)), (sin(x), sin(x*y))):
            args = zip(si, a)
            ex = Add(*[Mul(*ai) for ai in args])
            t = TR9(ex)
            assert not (a[0].func == a[1].func and (
                not verify_numerically(ex, t.expand(trig=True)) or t.is_Add)
                or a[1].func != a[0].func and ex != t)
Пример #7
0
def test_TR9():
    a = S(1) / 2
    b = 3 * a
    assert TR9(a) == a
    assert TR9(cos(1) + cos(2)) == 2 * cos(a) * cos(b)
    assert TR9(cos(1) - cos(2)) == 2 * sin(a) * sin(b)
    assert TR9(sin(1) - sin(2)) == -2 * sin(a) * cos(b)
    assert TR9(sin(1) + sin(2)) == 2 * sin(b) * cos(a)
    assert TR9(cos(1) + 2 * sin(1) +
               2 * sin(2)) == cos(1) + 4 * sin(b) * cos(a)
    assert TR9(cos(4) + cos(2) + 2 * cos(1) * cos(3)) == 4 * cos(1) * cos(3)
    assert TR9((cos(4) + cos(2)) / cos(3) / 2 + cos(3)) == 2 * cos(1) * cos(2)
    assert TR9(cos(3) + cos(4) + cos(5) + cos(6)) == \
        4*cos(S(1)/2)*cos(1)*cos(S(9)/2)
    assert TR9(cos(3) + cos(3) * cos(2)) == cos(3) + cos(2) * cos(3)
    assert TR9(-cos(y) +
               cos(x *
                   y)) == -2 * sin(x * y / 2 - y / 2) * sin(x * y / 2 + y / 2)
    assert TR9(-sin(y) + sin(x * y)) == 2 * sin(x * y / 2 -
                                                y / 2) * cos(x * y / 2 + y / 2)
    c = cos(x)
    s = sin(x)
    for si in ((1, 1), (1, -1), (-1, 1), (-1, -1)):
        for a in ((c, s), (s, c), (cos(x), cos(x * y)), (sin(x), sin(x * y))):
            args = zip(si, a)
            ex = Add(*[Mul(*ai) for ai in args])
            t = TR9(ex)
            assert not (a[0].func == a[1].func and
                        (not verify_numerically(ex, t.expand(trig=True))
                         or t.is_Add) or a[1].func != a[0].func and ex != t)
Пример #8
0
 def t(a, b, arg, n):
     from sympy import Mul
     m1 = meijerg(a, b, arg)
     m2 = Mul(*_inflate_g(m1, n))
     # NOTE: (the random number)**9 must still be on the principal sheet.
     # Thus make b&d small to create random numbers of small imaginary part.
     return verify_numerically(m1.subs(subs), m2.subs(subs), x, b=0.1, d=-0.1)
Пример #9
0
def mytn(expr1, expr2, expr3, x, d=0):
    from sympy.utilities.randtest import verify_numerically, random_complex_number
    subs = {}
    for a in expr1.free_symbols:
        if a != x:
            subs[a] = random_complex_number()
    return expr2 == expr3 and verify_numerically(expr1.subs(subs),
                                               expr2.subs(subs), x, d=d)
Пример #10
0
def test_TR3():
    assert TR3(cos(y - x * (y - x))) == cos(x * (x - y) + y)
    assert cos(pi / 2 + x) == -sin(x)
    assert cos(30 * pi / 2 + x) == -cos(x)

    for f in (cos, sin, tan, cot, csc, sec):
        i = f(3 * pi / 7)
        j = TR3(i)
        assert verify_numerically(i, j) and i.func != j.func
Пример #11
0
def test_TR3():
    assert TR3(cos(y - x*(y - x))) == cos(x*(x - y) + y)
    assert cos(pi/2 + x) == -sin(x)
    assert cos(30*pi/2 + x) == -cos(x)

    for f in (cos, sin, tan, cot, csc, sec):
        i = f(3*pi/7)
        j = TR3(i)
        assert verify_numerically(i, j) and i.func != j.func
Пример #12
0
def test_reflect():
    b = Symbol("b")
    m = Symbol("m")
    l = Line((0, b), slope=m)
    p = Point(x, y)
    r = p.reflect(l)
    dp = l.perpendicular_segment(p).length
    dr = l.perpendicular_segment(r).length
    assert verify_numerically(dp, dr)
    t = Triangle((0, 0), (1, 0), (2, 3))
    assert t.area == -t.reflect(l).area
    e = Ellipse((1, 0), 1, 2)
    assert e.area == -e.reflect(Line((1, 0), slope=0)).area
    assert e.area == -e.reflect(Line((1, 0), slope=oo)).area
    raises(NotImplementedError, lambda: e.reflect(Line((1, 0), slope=m)))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=oo)) == Triangle(
        Point(5, 0), Point(4, 0), Point(4, 2)
    )
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=oo)) == Triangle(
        Point(-1, 0), Point(-2, 0), Point(-2, 2)
    )
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=0)) == Triangle(
        Point(1, 6), Point(2, 6), Point(2, 4)
    )
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=0)) == Triangle(
        Point(1, 0), Point(2, 0), Point(2, -2)
    )

    # test entity overrides
    c = Circle((x, y), 3)
    cr = c.reflect(l)
    assert cr == Circle(r, -3)
    assert c.area == -cr.area
    pent = RegularPolygon((1, 2), 1, 5)
    l = Line((0, pi), slope=sqrt(2))
    rpent = pent.reflect(l)
    poly_pent = Polygon(*pent.vertices)
    assert rpent.center == pent.center.reflect(l)
    assert str([w.n(3) for w in rpent.vertices]) == (
        "[Point2D(-0.586, 4.27), Point2D(-1.69, 4.66), "
        "Point2D(-2.41, 3.73), Point2D(-1.74, 2.76), "
        "Point2D(-0.616, 3.10)]"
    )
    assert pent.area.equals(-rpent.area)
Пример #13
0
def test_reflect():
    x = Symbol('x', real=True)
    y = Symbol('y', real=True)
    b = Symbol('b')
    m = Symbol('m')
    l = Line((0, b), slope=m)
    p = Point(x, y)
    r = p.reflect(l)
    dp = l.perpendicular_segment(p).length
    dr = l.perpendicular_segment(r).length

    assert verify_numerically(dp, dr)

    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=oo)) \
        == Triangle(Point(5, 0), Point(4, 0), Point(4, 2))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=oo)) \
        == Triangle(Point(-1, 0), Point(-2, 0), Point(-2, 2))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=0)) \
        == Triangle(Point(1, 6), Point(2, 6), Point(2, 4))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=0)) \
        == Triangle(Point(1, 0), Point(2, 0), Point(2, -2))
Пример #14
0
def test_reflect():
    x = Symbol('x', real=True)
    y = Symbol('y', real=True)
    b = Symbol('b')
    m = Symbol('m')
    l = Line((0, b), slope=m)
    p = Point(x, y)
    r = p.reflect(l)
    dp = l.perpendicular_segment(p).length
    dr = l.perpendicular_segment(r).length

    assert verify_numerically(dp, dr)
    t = Triangle((0, 0), (1, 0), (2, 3))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=oo)) \
        == Triangle(Point(5, 0), Point(4, 0), Point(4, 2))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=oo)) \
        == Triangle(Point(-1, 0), Point(-2, 0), Point(-2, 2))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=0)) \
        == Triangle(Point(1, 6), Point(2, 6), Point(2, 4))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=0)) \
        == Triangle(Point(1, 0), Point(2, 0), Point(2, -2))
Пример #15
0
def test_reflect():
    b = Symbol('b')
    m = Symbol('m')
    l = Line((0, b), slope=m)
    p = Point(x, y)
    r = p.reflect(l)
    dp = l.perpendicular_segment(p).length
    dr = l.perpendicular_segment(r).length
    assert verify_numerically(dp, dr)
    t = Triangle((0, 0), (1, 0), (2, 3))
    assert t.area == -t.reflect(l).area
    e = Ellipse((1, 0), 1, 2)
    assert e.area == -e.reflect(Line((1, 0), slope=0)).area
    assert e.area == -e.reflect(Line((1, 0), slope=oo)).area
    raises(NotImplementedError, lambda: e.reflect(Line((1, 0), slope=m)))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=oo)) \
        == Triangle(Point(5, 0), Point(4, 0), Point(4, 2))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=oo)) \
        == Triangle(Point(-1, 0), Point(-2, 0), Point(-2, 2))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=0)) \
        == Triangle(Point(1, 6), Point(2, 6), Point(2, 4))
    assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=0)) \
        == Triangle(Point(1, 0), Point(2, 0), Point(2, -2))

    # test entity overrides
    c = Circle((x, y), 3)
    cr = c.reflect(l)
    assert cr == Circle(r, -3)
    assert c.area == -cr.area
    pent = RegularPolygon((1, 2), 1, 5)
    l = Line((0, pi), slope=sqrt(2))
    rpent = pent.reflect(l)
    poly_pent = Polygon(*pent.vertices)
    assert rpent.center == pent.center.reflect(l)
    assert str([w.n(3) for w in rpent.vertices]) == (
        '[Point2D(-0.586, 4.27), Point2D(-1.69, 4.66), '
        'Point2D(-2.41, 3.73), Point2D(-1.74, 2.76), '
        'Point2D(-0.616, 3.10)]')
    assert pent.area.equals(-rpent.area)
Пример #16
0
 def u(expr, x):
     from sympy import Add, exp, exp_polar
     r = _rewrite_single(expr, x)
     e = Add(*[res[0] * res[2] for res in r[0]]).replace(exp_polar,
                                                         exp)  # XXX Hack?
     assert verify_numerically(e, expr, x)
Пример #17
0
def test_fresnel():
    assert fresnels(0) == 0
    assert fresnels(oo) == S.Half
    assert fresnels(-oo) == -S.Half
    assert fresnels(I * oo) == -I * S.Half

    assert unchanged(fresnels, z)
    assert fresnels(-z) == -fresnels(z)
    assert fresnels(I * z) == -I * fresnels(z)
    assert fresnels(-I * z) == I * fresnels(z)

    assert conjugate(fresnels(z)) == fresnels(conjugate(z))

    assert fresnels(z).diff(z) == sin(pi * z**2 / 2)

    assert fresnels(z).rewrite(erf) == (S.One + I) / 4 * (erf(
        (S.One + I) / 2 * sqrt(pi) * z) - I * erf(
            (S.One - I) / 2 * sqrt(pi) * z))

    assert fresnels(z).rewrite(hyper) == \
        pi*z**3/6 * hyper([S(3)/4], [S(3)/2, S(7)/4], -pi**2*z**4/16)

    assert fresnels(z).series(z, n=15) == \
        pi*z**3/6 - pi**3*z**7/336 + pi**5*z**11/42240 + O(z**15)

    assert fresnels(w).is_extended_real is True
    assert fresnels(w).is_finite is True

    assert fresnels(z).is_extended_real is None
    assert fresnels(z).is_finite is None

    assert fresnels(z).as_real_imag() == (
        fresnels(re(z) - I * im(z)) / 2 + fresnels(re(z) + I * im(z)) / 2,
        -I * (-fresnels(re(z) - I * im(z)) + fresnels(re(z) + I * im(z))) / 2)

    assert fresnels(z).as_real_imag(deep=False) == (
        fresnels(re(z) - I * im(z)) / 2 + fresnels(re(z) + I * im(z)) / 2,
        -I * (-fresnels(re(z) - I * im(z)) + fresnels(re(z) + I * im(z))) / 2)

    assert fresnels(w).as_real_imag() == (fresnels(w), 0)
    assert fresnels(w).as_real_imag(deep=True) == (fresnels(w), 0)

    assert fresnels(2 + 3 * I).as_real_imag() == (
        fresnels(2 + 3 * I) / 2 + fresnels(2 - 3 * I) / 2,
        -I * (fresnels(2 + 3 * I) - fresnels(2 - 3 * I)) / 2)

    assert expand_func(integrate(fresnels(z), z)) == \
        z*fresnels(z) + cos(pi*z**2/2)/pi

    assert fresnels(z).rewrite(meijerg) == sqrt(2)*pi*z**(S(9)/4) * \
        meijerg(((), (1,)), ((S(3)/4,),
        (S(1)/4, 0)), -pi**2*z**4/16)/(2*(-z)**(S(3)/4)*(z**2)**(S(3)/4))

    assert fresnelc(0) == 0
    assert fresnelc(oo) == S.Half
    assert fresnelc(-oo) == -S.Half
    assert fresnelc(I * oo) == I * S.Half

    assert unchanged(fresnelc, z)
    assert fresnelc(-z) == -fresnelc(z)
    assert fresnelc(I * z) == I * fresnelc(z)
    assert fresnelc(-I * z) == -I * fresnelc(z)

    assert conjugate(fresnelc(z)) == fresnelc(conjugate(z))

    assert fresnelc(z).diff(z) == cos(pi * z**2 / 2)

    assert fresnelc(z).rewrite(erf) == (S.One - I) / 4 * (erf(
        (S.One + I) / 2 * sqrt(pi) * z) + I * erf(
            (S.One - I) / 2 * sqrt(pi) * z))

    assert fresnelc(z).rewrite(hyper) == \
        z * hyper([S.One/4], [S.One/2, S(5)/4], -pi**2*z**4/16)

    assert fresnelc(w).is_extended_real is True

    assert fresnelc(z).as_real_imag() == \
        (fresnelc(re(z) - I*im(z))/2 + fresnelc(re(z) + I*im(z))/2,
         -I*(-fresnelc(re(z) - I*im(z)) + fresnelc(re(z) + I*im(z)))/2)

    assert fresnelc(z).as_real_imag(deep=False) == \
        (fresnelc(re(z) - I*im(z))/2 + fresnelc(re(z) + I*im(z))/2,
         -I*(-fresnelc(re(z) - I*im(z)) + fresnelc(re(z) + I*im(z)))/2)

    assert fresnelc(2 + 3 * I).as_real_imag() == (
        fresnelc(2 - 3 * I) / 2 + fresnelc(2 + 3 * I) / 2,
        -I * (fresnelc(2 + 3 * I) - fresnelc(2 - 3 * I)) / 2)

    assert expand_func(integrate(fresnelc(z), z)) == \
        z*fresnelc(z) - sin(pi*z**2/2)/pi

    assert fresnelc(z).rewrite(meijerg) == sqrt(2)*pi*z**(S(3)/4) * \
        meijerg(((), (1,)), ((S(1)/4,),
        (S(3)/4, 0)), -pi**2*z**4/16)/(2*(-z)**(S(1)/4)*(z**2)**(S(1)/4))

    from sympy.utilities.randtest import verify_numerically

    verify_numerically(re(fresnels(z)), fresnels(z).as_real_imag()[0], z)
    verify_numerically(im(fresnels(z)), fresnels(z).as_real_imag()[1], z)
    verify_numerically(fresnels(z), fresnels(z).rewrite(hyper), z)
    verify_numerically(fresnels(z), fresnels(z).rewrite(meijerg), z)

    verify_numerically(re(fresnelc(z)), fresnelc(z).as_real_imag()[0], z)
    verify_numerically(im(fresnelc(z)), fresnelc(z).as_real_imag()[1], z)
    verify_numerically(fresnelc(z), fresnelc(z).rewrite(hyper), z)
    verify_numerically(fresnelc(z), fresnelc(z).rewrite(meijerg), z)

    raises(ArgumentIndexError, lambda: fresnels(z).fdiff(2))
    raises(ArgumentIndexError, lambda: fresnelc(z).fdiff(2))

    assert fresnels(x).taylor_term(-1, x) == S.Zero
    assert fresnelc(x).taylor_term(-1, x) == S.Zero
    assert fresnelc(x).taylor_term(1, x) == -pi**2 * x**5 / 40
Пример #18
0
def test_issue_6828():
    f = 1 / (1.08 * x**2 - 4.3)
    g = integrate(f, x).diff(x)
    assert verify_numerically(f, g, tol=1e-12)
Пример #19
0
def test_fresnel():
    assert fresnels(0) == 0
    assert fresnels(oo) == S.Half
    assert fresnels(-oo) == -S.Half

    assert fresnels(z) == fresnels(z)
    assert fresnels(-z) == -fresnels(z)
    assert fresnels(I*z) == -I*fresnels(z)
    assert fresnels(-I*z) == I*fresnels(z)

    assert conjugate(fresnels(z)) == fresnels(conjugate(z))

    assert fresnels(z).diff(z) == sin(pi*z**2/2)

    assert fresnels(z).rewrite(erf) == (S.One + I)/4 * (
        erf((S.One + I)/2*sqrt(pi)*z) - I*erf((S.One - I)/2*sqrt(pi)*z))

    assert fresnels(z).rewrite(hyper) == \
        pi*z**3/6 * hyper([S(3)/4], [S(3)/2, S(7)/4], -pi**2*z**4/16)

    assert fresnels(z).series(z, n=15) == \
        pi*z**3/6 - pi**3*z**7/336 + pi**5*z**11/42240 + O(z**15)

    assert fresnels(w).is_real is True

    assert fresnels(z).as_real_imag() == \
        ((fresnels(re(z) - I*re(z)*Abs(im(z))/Abs(re(z)))/2 +
          fresnels(re(z) + I*re(z)*Abs(im(z))/Abs(re(z)))/2,
          I*(fresnels(re(z) - I*re(z)*Abs(im(z))/Abs(re(z))) -
          fresnels(re(z) + I*re(z)*Abs(im(z))/Abs(re(z)))) *
          re(z)*Abs(im(z))/(2*im(z)*Abs(re(z)))))

    assert fresnels(2 + 3*I).as_real_imag() == (
        fresnels(2 + 3*I)/2 + fresnels(2 - 3*I)/2,
        I*(fresnels(2 - 3*I) - fresnels(2 + 3*I))/2
    )

    assert expand_func(integrate(fresnels(z), z)) == \
        z*fresnels(z) + cos(pi*z**2/2)/pi

    assert fresnels(z).rewrite(meijerg) == sqrt(2)*pi*z**(S(9)/4) * \
        meijerg(((), (1,)), ((S(3)/4,),
        (S(1)/4, 0)), -pi**2*z**4/16)/(2*(-z)**(S(3)/4)*(z**2)**(S(3)/4))

    assert fresnelc(0) == 0
    assert fresnelc(oo) == S.Half
    assert fresnelc(-oo) == -S.Half

    assert fresnelc(z) == fresnelc(z)
    assert fresnelc(-z) == -fresnelc(z)
    assert fresnelc(I*z) == I*fresnelc(z)
    assert fresnelc(-I*z) == -I*fresnelc(z)

    assert conjugate(fresnelc(z)) == fresnelc(conjugate(z))

    assert fresnelc(z).diff(z) == cos(pi*z**2/2)

    assert fresnelc(z).rewrite(erf) == (S.One - I)/4 * (
        erf((S.One + I)/2*sqrt(pi)*z) + I*erf((S.One - I)/2*sqrt(pi)*z))

    assert fresnelc(z).rewrite(hyper) == \
        z * hyper([S.One/4], [S.One/2, S(5)/4], -pi**2*z**4/16)

    assert fresnelc(z).series(z, n=15) == \
        z - pi**2*z**5/40 + pi**4*z**9/3456 - pi**6*z**13/599040 + O(z**15)

    # issue 6510
    assert fresnels(z).series(z, S.Infinity) == \
        (-1/(pi**2*z**3) + O(z**(-6), (z, oo)))*sin(pi*z**2/2) + \
        (3/(pi**3*z**5) - 1/(pi*z) + O(z**(-6), (z, oo)))*cos(pi*z**2/2) + S.Half
    assert fresnelc(z).series(z, S.Infinity) == \
        (-1/(pi**2*z**3) + O(z**(-6), (z, oo)))*cos(pi*z**2/2) + \
        (-3/(pi**3*z**5) + 1/(pi*z) + O(z**(-6), (z, oo)))*sin(pi*z**2/2) + S.Half
    assert fresnels(1/z).series(z) == \
        (-z**3/pi**2 + O(z**6))*sin(pi/(2*z**2)) + (-z/pi + 3*z**5/pi**3 + \
        O(z**6))*cos(pi/(2*z**2)) + S.Half
    assert fresnelc(1/z).series(z) == \
        (-z**3/pi**2 + O(z**6))*cos(pi/(2*z**2)) + (z/pi - 3*z**5/pi**3 + \
        O(z**6))*sin(pi/(2*z**2)) + S.Half

    assert fresnelc(w).is_real is True

    assert fresnelc(z).as_real_imag() == \
        ((fresnelc(re(z) - I*re(z)*Abs(im(z))/Abs(re(z)))/2 +
          fresnelc(re(z) + I*re(z)*Abs(im(z))/Abs(re(z)))/2,
          I*(fresnelc(re(z) - I*re(z)*Abs(im(z))/Abs(re(z))) -
          fresnelc(re(z) + I*re(z)*Abs(im(z))/Abs(re(z)))) *
          re(z)*Abs(im(z))/(2*im(z)*Abs(re(z)))))

    assert fresnelc(2 + 3*I).as_real_imag() == (
        fresnelc(2 - 3*I)/2 + fresnelc(2 + 3*I)/2,
        I*(fresnelc(2 - 3*I) - fresnelc(2 + 3*I))/2
    )

    assert expand_func(integrate(fresnelc(z), z)) == \
        z*fresnelc(z) - sin(pi*z**2/2)/pi

    assert fresnelc(z).rewrite(meijerg) == sqrt(2)*pi*z**(S(3)/4) * \
        meijerg(((), (1,)), ((S(1)/4,),
        (S(3)/4, 0)), -pi**2*z**4/16)/(2*(-z)**(S(1)/4)*(z**2)**(S(1)/4))

    from sympy.utilities.randtest import verify_numerically

    verify_numerically(re(fresnels(z)), fresnels(z).as_real_imag()[0], z)
    verify_numerically(im(fresnels(z)), fresnels(z).as_real_imag()[1], z)
    verify_numerically(fresnels(z), fresnels(z).rewrite(hyper), z)
    verify_numerically(fresnels(z), fresnels(z).rewrite(meijerg), z)

    verify_numerically(re(fresnelc(z)), fresnelc(z).as_real_imag()[0], z)
    verify_numerically(im(fresnelc(z)), fresnelc(z).as_real_imag()[1], z)
    verify_numerically(fresnelc(z), fresnelc(z).rewrite(hyper), z)
    verify_numerically(fresnelc(z), fresnelc(z).rewrite(meijerg), z)
Пример #20
0
    def u(expr, x):
        from sympy import Add, exp, exp_polar

        r = _rewrite_single(expr, x)
        e = Add(*[res[0] * res[2] for res in r[0]]).replace(exp_polar, exp)  # XXX Hack?
        assert verify_numerically(e, expr, x)
Пример #21
0
 def ok(a, b, n):
     e = (a + I*b)**n
     return verify_numerically(e, expand_multinomial(e))
Пример #22
0
 def ok(a, b, n):
     e = (a + I*b)**n
     return verify_numerically(e, expand_multinomial(e))
Пример #23
0
def test_issue_6828():
    f = 1/(1.08*x**2 - 4.3)
    g = integrate(f, x).diff(x)
    assert verify_numerically(f, g, tol=1e-12)