def test_K(): assert K(0) == pi / 2 assert K(S(1) / 2) == 8 * pi ** (S(3) / 2) / gamma(-S(1) / 4) ** 2 assert K(1) == zoo assert K(-1) == gamma(S(1) / 4) ** 2 / (4 * sqrt(2 * pi)) assert K(oo) == 0 assert K(-oo) == 0 assert K(I * oo) == 0 assert K(-I * oo) == 0 assert K(zoo) == 0 assert K(z).diff(z) == (E(z) - (1 - z) * K(z)) / (2 * z * (1 - z)) assert td(K(z), z) zi = Symbol("z", real=False) assert K(zi).conjugate() == K(zi.conjugate()) zr = Symbol("z", real=True, negative=True) assert K(zr).conjugate() == K(zr) assert K(z).rewrite(hyper) == (pi / 2) * hyper((S.Half, S.Half), (S.One,), z) assert tn(K(z), (pi / 2) * hyper((S.Half, S.Half), (S.One,), z)) assert K(z).rewrite(meijerg) == meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z) / 2 assert tn(K(z), meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z) / 2) assert K(z).series( z ) == pi / 2 + pi * z / 8 + 9 * pi * z ** 2 / 128 + 25 * pi * z ** 3 / 512 + 1225 * pi * z ** 4 / 32768 + 3969 * pi * z ** 5 / 131072 + O( z ** 6 )
def test_cosine_transform(): from sympy import sinh, cosh, Si, Ci t = symbols("t") w = symbols("w") a = symbols("a") f = Function("f") # Test unevaluated form assert cosine_transform(f(t), t, w) == CosineTransform(f(t), t, w) assert inverse_cosine_transform(f(w), w, t) == InverseCosineTransform(f(w), w, t) assert cosine_transform(1/sqrt(t), t, w) == 1/sqrt(w) assert inverse_cosine_transform(1/sqrt(w), w, t) == 1/sqrt(t) assert cosine_transform(1/(a**2+t**2), t, w) == sqrt(2)*sqrt(pi)*(-sinh(a*w) + cosh(a*w))/(2*a) assert cosine_transform(t**(-a), t, w) == 2**(-a + S(1)/2)*w**(a - 1)*gamma((-a + 1)/2)/gamma(a/2) assert inverse_cosine_transform(2**(-a + S(1)/2)*w**(a - 1)*gamma(-a/2 + S(1)/2)/gamma(a/2), w, t) == t**(-a) assert cosine_transform(exp(-a*t), t, w) == sqrt(2)*a/(sqrt(pi)*(a**2 + w**2)) assert inverse_cosine_transform(sqrt(2)*a/(sqrt(pi)*(a**2 + w**2)), w, t) == -sinh(a*t) + cosh(a*t) assert cosine_transform(exp(-a*sqrt(t))*cos(a*sqrt(t)), t, w) == a*(-sinh(a**2/(2*w)) + cosh(a**2/(2*w)))/(2*w**(S(3)/2)) assert cosine_transform(1/(a+t), t, w) == -sqrt(2)*((2*Si(a*w) - pi)*sin(a*w) + 2*cos(a*w)*Ci(a*w))/(2*sqrt(pi)) assert inverse_cosine_transform(sqrt(2)*meijerg(((S(1)/2, 0), ()), ((S(1)/2, 0, 0), (S(1)/2,)), a**2*w**2/4)/(2*pi), w, t) == 1/(a + t) assert cosine_transform(1/sqrt(a**2+t**2), t, w) == sqrt(2)*meijerg(((S(1)/2,), ()), ((0, 0), (S(1)/2,)), a**2*w**2/4)/(2*sqrt(pi)) assert inverse_cosine_transform(sqrt(2)*meijerg(((S(1)/2,), ()), ((0, 0), (S(1)/2,)), a**2*w**2/4)/(2*sqrt(pi)), w, t) == 1/(t*sqrt(a**2/t**2 + 1))
def test_E(): assert E(z, 0) == z assert E(0, m) == 0 assert E(i*pi/2, m) == i*E(m) assert E(z, oo) == zoo assert E(z, -oo) == zoo assert E(0) == pi/2 assert E(1) == 1 assert E(oo) == I*oo assert E(-oo) == oo assert E(zoo) == zoo assert E(-z, m) == -E(z, m) assert E(z, m).diff(z) == sqrt(1 - m*sin(z)**2) assert E(z, m).diff(m) == (E(z, m) - F(z, m))/(2*m) assert E(z).diff(z) == (E(z) - K(z))/(2*z) r = randcplx() assert td(E(r, m), m) assert td(E(z, r), z) assert td(E(z), z) mi = Symbol('m', real=False) assert E(z, mi).conjugate() == E(z.conjugate(), mi.conjugate()) mr = Symbol('m', real=True, negative=True) assert E(z, mr).conjugate() == E(z.conjugate(), mr) assert E(z).rewrite(hyper) == (pi/2)*hyper((-S.Half, S.Half), (S.One,), z) assert tn(E(z), (pi/2)*hyper((-S.Half, S.Half), (S.One,), z)) assert E(z).rewrite(meijerg) == \ -meijerg(((S.Half, S(3)/2), []), ((S.Zero,), (S.Zero,)), -z)/4 assert tn(E(z), -meijerg(((S.Half, S(3)/2), []), ((S.Zero,), (S.Zero,)), -z)/4)
def test_meijerg_eval(): from sympy import besseli, exp_polar from sympy.abc import l a = randcplx() arg = x*exp_polar(k*pi*I) expr1 = pi*meijerg([[], [(a + 1)/2]], [[a/2], [-a/2, (a + 1)/2]], arg**2/4) expr2 = besseli(a, arg) # Test that the two expressions agree for all arguments. for x_ in [0.5, 1.5]: for k_ in [0.0, 0.1, 0.3, 0.5, 0.8, 1, 5.751, 15.3]: assert abs((expr1 - expr2).n(subs={x: x_, k: k_})) < 1e-10 assert abs((expr1 - expr2).n(subs={x: x_, k: -k_})) < 1e-10 # Test continuity independently eps = 1e-13 expr2 = expr1.subs(k, l) for x_ in [0.5, 1.5]: for k_ in [0.5, S(1)/3, 0.25, 0.75, S(2)/3, 1.0, 1.5]: assert abs((expr1 - expr2).n( subs={x: x_, k: k_ + eps, l: k_ - eps})) < 1e-10 assert abs((expr1 - expr2).n( subs={x: x_, k: -k_ + eps, l: -k_ - eps})) < 1e-10 expr = (meijerg(((0.5,), ()), ((0.5, 0, 0.5), ()), exp_polar(-I*pi)/4) + meijerg(((0.5,), ()), ((0.5, 0, 0.5), ()), exp_polar(I*pi)/4)) \ /(2*sqrt(pi)) assert (expr - pi/exp(1)).n(chop=True) == 0
def test_K(): assert K(0) == pi/2 assert K(S(1)/2) == 8*pi**(S(3)/2)/gamma(-S(1)/4)**2 assert K(1) == zoo assert K(-1) == gamma(S(1)/4)**2/(4*sqrt(2*pi)) assert K(oo) == 0 assert K(-oo) == 0 assert K(I*oo) == 0 assert K(-I*oo) == 0 assert K(zoo) == 0 assert K(z).diff(z) == (E(z) - (1 - z)*K(z))/(2*z*(1 - z)) assert td(K(z), z) zi = Symbol('z', real=False) assert K(zi).conjugate() == K(zi.conjugate()) zr = Symbol('z', real=True, negative=True) assert K(zr).conjugate() == K(zr) assert K(z).rewrite(hyper) == \ (pi/2)*hyper((S.Half, S.Half), (S.One,), z) assert tn(K(z), (pi/2)*hyper((S.Half, S.Half), (S.One,), z)) assert K(z).rewrite(meijerg) == \ meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z)/2 assert tn(K(z), meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z)/2)
def test_rewrite1(): assert _rewrite1(x ** 3 * meijerg([a], [b], [c], [d], x ** 2 + y * x ** 2) * 5, x) == ( 5, x ** 3, [(1, 0, meijerg([a], [b], [c], [d], x ** 2 * (y + 1)))], True, )
def can_do_meijer(a1, a2, b1, b2, numeric=True): """ This helper function tries to hyperexpand() the meijer g-function corresponding to the parameters a1, a2, b1, b2. It returns False if this expansion still contains g-functions. If numeric is True, it also tests the so-obtained formula numerically (at random values) and returns False if the test fails. Else it returns True. """ from sympy import unpolarify, expand r = hyperexpand(meijerg(a1, a2, b1, b2, z)) if r.has(meijerg): return False # NOTE hyperexpand() returns a truly branched function, whereas numerical # evaluation only works on the main branch. Since we are evaluating on # the main branch, this should not be a problem, but expressions like # exp_polar(I*pi/2*x)**a are evaluated incorrectly. We thus have to get # rid of them. The expand heuristically does this... r = unpolarify(expand(r, force=True, power_base=True, power_exp=False, mul=False, log=False, multinomial=False, basic=False)) if not numeric: return True repl = {} for n, a in enumerate(meijerg(a1, a2, b1, b2, z).free_symbols - set([z])): repl[a] = randcplx(n) return tn(meijerg(a1, a2, b1, b2, z).subs(repl), r.subs(repl), z)
def test_issue_10798(): from sympy import integrate, pi, I, log, polylog, exp_polar, Piecewise, meijerg, Abs from sympy.abc import x, y assert integrate(1/(1-(x*y)**2), (x, 0, 1), y) == \ -Piecewise((I*pi*log(y) - polylog(2, y), Abs(y) < 1), (-I*pi*log(1/y) - polylog(2, y), Abs(1/y) < 1), \ (-I*pi*meijerg(((), (1, 1)), ((0, 0), ()), y) + I*pi*meijerg(((1, 1), ()), ((), (0, 0)), y) - polylog(2, y), True))/2 \ - log(y)*log(1 - 1/y)/2 + log(y)*log(1 + 1/y)/2 + log(y)*log(y - 1)/2 \ - log(y)*log(y + 1)/2 + I*pi*log(y)/2 - polylog(2, y*exp_polar(I*pi))/2
def test_meijerg_lookup(): from sympy import uppergamma assert hyperexpand(meijerg([a], [], [b, a], [], z)) == z ** b * exp(z) * gamma(-a + b + 1) * uppergamma(a - b, z) assert hyperexpand(meijerg([0], [], [0, 0], [], z)) == exp(z) * uppergamma(0, z) assert can_do_meijer([a], [], [b, a + 1], []) assert can_do_meijer([a], [], [b + 2, a], []) assert can_do_meijer([a], [], [b - 2, a], [])
def test_limits(): k, x = symbols('k, x') assert hyper((1,), (S(4)/3, S(5)/3), k**2).series(k) == \ hyper((1,), (S(4)/3, S(5)/3), 0) + \ 9*k**2*hyper((2,), (S(7)/3, S(8)/3), 0)/20 + \ 81*k**4*hyper((3,), (S(10)/3, S(11)/3), 0)/1120 + \ O(k**6) # issue 6350 assert limit(meijerg((), (), (1,), (0,), -x), x, 0) == \ meijerg(((), ()), ((1,), (0,)), 0) # issue 6052
def test_meijerint(): from sympy import symbols, expand, arg s, t, mu = symbols("s t mu", real=True) assert integrate( meijerg([], [], [0], [], s * t) * meijerg([], [], [mu / 2], [-mu / 2], t ** 2 / 4), (t, 0, oo) ).is_Piecewise s = symbols("s", positive=True) assert integrate(x ** s * meijerg([[], []], [[0], []], x), (x, 0, oo)) == gamma(s + 1) assert integrate(x ** s * meijerg([[], []], [[0], []], x), (x, 0, oo), meijerg=True) == gamma(s + 1) assert isinstance(integrate(x ** s * meijerg([[], []], [[0], []], x), (x, 0, oo), meijerg=False), Integral) assert meijerint_indefinite(exp(x), x) == exp(x) # TODO what simplifications should be done automatically? # This tests "extra case" for antecedents_1. a, b = symbols("a b", positive=True) assert simplify(meijerint_definite(x ** a, x, 0, b)[0]) == b ** (a + 1) / (a + 1) # This tests various conditions and expansions: meijerint_definite((x + 1) ** 3 * exp(-x), x, 0, oo) == (16, True) # Again, how about simplifications? sigma, mu = symbols("sigma mu", positive=True) i, c = meijerint_definite(exp(-((x - mu) / (2 * sigma)) ** 2), x, 0, oo) assert simplify(i) == sqrt(pi) * sigma * (erf(mu / (2 * sigma)) + 1) assert c is True i, _ = meijerint_definite(exp(-mu * x) * exp(sigma * x), x, 0, oo) # TODO it would be nice to test the condition assert simplify(i) == 1 / (mu - sigma) # Test substitutions to change limits assert meijerint_definite(exp(x), x, -oo, 2) == (exp(2), True) assert expand(meijerint_definite(exp(x), x, 0, I)[0]) == exp(I) - 1 assert expand(meijerint_definite(exp(-x), x, 0, x)[0]) == 1 - exp(-exp(I * arg(x)) * abs(x)) # Test -oo to oo assert meijerint_definite(exp(-x ** 2), x, -oo, oo) == (sqrt(pi), True) assert meijerint_definite(exp(-abs(x)), x, -oo, oo) == (2, True) assert meijerint_definite(exp(-(2 * x - 3) ** 2), x, -oo, oo) == (sqrt(pi) / 2, True) assert meijerint_definite(exp(-abs(2 * x - 3)), x, -oo, oo) == (1, True) assert meijerint_definite(exp(-((x - mu) / sigma) ** 2 / 2) / sqrt(2 * pi * sigma ** 2), x, -oo, oo) == (1, True) # Test one of the extra conditions for 2 g-functinos assert meijerint_definite(exp(-x) * sin(x), x, 0, oo) == (S(1) / 2, True) # Test a bug def res(n): return (1 / (1 + x ** 2)).diff(x, n).subs(x, 1) * (-1) ** n for n in range(6): assert integrate(exp(-x) * sin(x) * x ** n, (x, 0, oo), meijerg=True) == res(n) # Test trigexpand: assert integrate(exp(-x) * sin(x + a), (x, 0, oo), meijerg=True) == sin(a) / 2 + cos(a) / 2
def test_meijerg_shift_operators(): # carefully set up the parameters. XXX this still fails sometimes a1, a2, a3, a4, a5, b1, b2, b3, b4, b5 = \ map(lambda n: randcplx(n), range(10)) g = meijerg([a1], [a3, a4], [b1], [b3, b4], z) assert tn(MeijerShiftA(b1).apply(g, op), meijerg([a1], [a3, a4], [b1 + 1], [b3, b4], z), z) assert tn(MeijerShiftB(a1).apply(g, op), meijerg([a1 - 1], [a3, a4], [b1], [b3, b4], z), z) assert tn(MeijerShiftC(b3).apply(g, op), meijerg([a1], [a3, a4], [b1], [b3 + 1, b4], z), z) assert tn(MeijerShiftD(a3).apply(g, op), meijerg([a1], [a3 - 1, a4], [b1], [b3, b4], z), z) s = MeijerUnShiftA([a1], [a3, a4], [b1], [b3, b4], 0, z) assert tn( s.apply(g, op), meijerg([a1], [a3, a4], [b1 - 1], [b3, b4], z), z) s = MeijerUnShiftC([a1], [a3, a4], [b1], [b3, b4], 0, z) assert tn( s.apply(g, op), meijerg([a1], [a3, a4], [b1], [b3 - 1, b4], z), z) s = MeijerUnShiftB([a1], [a3, a4], [b1], [b3, b4], 0, z) assert tn( s.apply(g, op), meijerg([a1 + 1], [a3, a4], [b1], [b3, b4], z), z) s = MeijerUnShiftD([a1], [a3, a4], [b1], [b3, b4], 0, z) assert tn( s.apply(g, op), meijerg([a1], [a3 + 1, a4], [b1], [b3, b4], z), z)
def test_meijerg(): expr = meijerg([pi, pi, x], [1], [0, 1], [1, 2, 3], z) ucode_str = \ u"""\ ╭─╮2, 3 ⎛π, π, x 1 │ ⎞\n\ │╶┐ ⎜ │ z⎟\n\ ╰─╯4, 5 ⎝ 0, 1 1, 2, 3 │ ⎠\ """ ascii_str = \ """\ __2, 3 /pi, pi, x 1 | \\\n\ /__ | | z|\n\ \_|4, 5 \\ 0, 1 1, 2, 3 | /\ """ assert pretty(expr) == ascii_str assert upretty(expr) == ucode_str expr = meijerg([1, pi/7], [2, pi, 5], [], [], z**2) ucode_str = \ u"""\ ⎛ π │ ⎞\n\ ╭─╮0, 2 ⎜1, ─ 2, π, 5 │ 2⎟\n\ │╶┐ ⎜ 7 │ z ⎟\n\ ╰─╯5, 0 ⎜ │ ⎟\n\ ⎝ │ ⎠\ """ ascii_str = \ """\ / pi | \\\n\ __0, 2 |1, -- 2, pi, 5 | 2|\n\ /__ | 7 | z |\n\ \_|5, 0 | | |\n\ \\ | /\ """ assert pretty(expr) == ascii_str assert upretty(expr) == ucode_str ucode_str = \ u"""\ ╭─╮ 1, 10 ⎛1, 1, 1, 1, 1, 1, 1, 1, 1, 1 1 │ ⎞\n\ │╶┐ ⎜ │ z⎟\n\ ╰─╯11, 2 ⎝ 1 1 │ ⎠\ """ ascii_str = \ """\ __ 1, 10 /1, 1, 1, 1, 1, 1, 1, 1, 1, 1 1 | \\\n\ /__ | | z|\n\ \_|11, 2 \\ 1 1 | /\ """ expr = meijerg([1]*10, [1], [1], [1], z) assert pretty(expr) == ascii_str assert upretty(expr) == ucode_str
def test_gh_issue_2711(): x = Symbol('x') f = meijerg(((), ()), ((0,), ()), x) a = Wild('a') b = Wild('b') assert f.find(a) == set([(S.Zero,), ((), ()), ((S.Zero,), ()), x, S.Zero, (), meijerg(((), ()), ((S.Zero,), ()), x)]) assert f.find(a + b) == \ {meijerg(((), ()), ((S.Zero,), ()), x), x, S.Zero} assert f.find(a**2) == {meijerg(((), ()), ((S.Zero,), ()), x), x}
def test_expand_func(): # evaluation at 1 of Gauss' hypergeometric function: from sympy.abc import a, b, c from sympy import gamma, expand_func a1, b1, c1 = randcplx(), randcplx(), randcplx() + 5 assert expand_func(hyper([a, b], [c], 1)) == gamma(c) * gamma(-a - b + c) / (gamma(-a + c) * gamma(-b + c)) assert abs(expand_func(hyper([a1, b1], [c1], 1)).n() - hyper([a1, b1], [c1], 1).n()) < 1e-10 # hyperexpand wrapper for hyper: assert expand_func(hyper([], [], z)) == exp(z) assert expand_func(hyper([1, 2, 3], [], z)) == hyper([1, 2, 3], [], z) assert expand_func(meijerg([[1, 1], []], [[1], [0]], z)) == log(z + 1) assert expand_func(meijerg([[1, 1], []], [[], []], z)) == meijerg([[1, 1], []], [[], []], z)
def test_hyper_printing(): from sympy import pi, Tuple from sympy.abc import x, z assert latex(meijerg(Tuple(pi, pi, x), Tuple(1), \ (0,1), Tuple(1, 2, 3/pi),z)) == \ r'{G_{4, 5}^{2, 3}\left.\left(\begin{matrix} \pi, \pi, x & 1 \\0, 1 & 1, 2, \frac{3}{\pi} \end{matrix} \right| {z} \right)}' assert latex(meijerg(Tuple(), Tuple(1), (0,), Tuple(),z)) == \ r'{G_{1, 1}^{1, 0}\left.\left(\begin{matrix} & 1 \\0 & \end{matrix} \right| {z} \right)}' assert latex(hyper((x, 2), (3,), z)) == \ r'{{}_{2}F_{1}\left.\left(\begin{matrix} x, 2 ' \ r'\\ 3 \end{matrix}\right| {z} \right)}' assert latex(hyper(Tuple(), Tuple(1), z)) == \ r'{{}_{0}F_{1}\left.\left(\begin{matrix} ' \ r'\\ 1 \end{matrix}\right| {z} \right)}'
def test_meijerg_lookup(): from sympy import uppergamma, Si, Ci assert hyperexpand(meijerg([a], [], [b, a], [], z)) == \ z**b*exp(z)*gamma(-a + b + 1)*uppergamma(a - b, z) assert hyperexpand(meijerg([0], [], [0, 0], [], z)) == \ exp(z)*uppergamma(0, z) assert can_do_meijer([a], [], [b, a + 1], []) assert can_do_meijer([a], [], [b + 2, a], []) assert can_do_meijer([a], [], [b - 2, a], []) assert hyperexpand(meijerg([a], [], [a, a, a - S(1)/2], [], z)) == \ -sqrt(pi)*z**(a - S(1)/2)*(2*cos(2*sqrt(z))*(Si(2*sqrt(z)) - pi/2) - 2*sin(2*sqrt(z))*Ci(2*sqrt(z))) == \ hyperexpand(meijerg([a], [], [a, a - S(1)/2, a], [], z)) == \ hyperexpand(meijerg([a], [], [a - S(1)/2, a, a], [], z)) assert can_do_meijer([a - 1], [], [a + 2, a - S(3)/2, a + 1], [])
def test_branch_bug(): assert hyperexpand(hyper((-S(1)/3, S(1)/2), (S(2)/3, S(3)/2), -z)) == \ -z**S('1/3')*lowergamma(exp_polar(I*pi)/3, z)/5 \ + sqrt(pi)*erf(sqrt(z))/(5*sqrt(z)) assert hyperexpand(meijerg([S(7)/6, 1], [], [S(2)/3], [S(1)/6, 0], z)) == \ 2*z**S('2/3')*(2*sqrt(pi)*erf(sqrt(z))/sqrt(z) - 2*lowergamma( S(2)/3, z)/z**S('2/3'))*gamma(S(2)/3)/gamma(S(5)/3)
def test_meijerg_with_Floats(): # see issue #10681 from sympy import RR f = meijerg(((3.0, 1), ()), ((S(3)/2,), (0,)), z) a = -2.3632718012073 g = a*z**(S(3)/2)*hyper((-0.5, S(3)/2), (S(5)/2,), z*exp_polar(I*pi)) assert RR.almosteq((hyperexpand(f)/g).n(), 1.0, 1e-12)
def test_from_meijerg(): x = symbols('x') R, Dx = DifferentialOperators(QQ.old_poly_ring(x), 'Dx') p = from_meijerg(meijerg(([], [S(3)/2]), ([S(1)/2], [S(1)/2, 1]), x)) q = HolonomicFunction(x/2 - 1/4 + (-x**2 + x/4)*Dx + x**2*Dx**2 + x**3*Dx**3, x, 1, \ [1/sqrt(pi), 1/(2*sqrt(pi)), -1/(4*sqrt(pi))]) assert p == q p = from_meijerg(meijerg(([], []), ([0], []), x)) q = HolonomicFunction(1 + Dx, x, 0, [1]) assert p == q p = from_meijerg(meijerg(([1], []), ([S(1)/2], [0]), x)) q = HolonomicFunction((x + 1/2)*Dx + x*Dx**2, x, 1, [sqrt(pi)*erf(1), exp(-1)]) assert p == q p = from_meijerg(meijerg(([0], [1]), ([0], []), 2*x**2)) q = HolonomicFunction((3*x**2 - 1)*Dx + x**3*Dx**2, x, 1, [-exp(-S(1)/2) + 1, -exp(-S(1)/2)]) assert p == q
def test_uppergamma(): from sympy import meijerg, exp_polar, I, expint assert uppergamma(4, 0) == 6 assert uppergamma(x, y).diff(y) == -y**(x-1)*exp(-y) assert td(uppergamma(randcplx(), y), y) assert uppergamma(x, y).diff(x) == \ uppergamma(x, y)*log(y) + meijerg([], [1, 1], [0, 0, x], [], y) assert td(uppergamma(x, randcplx()), x) assert uppergamma(S.Half, x) == sqrt(pi)*(1 - erf(sqrt(x))) assert not uppergamma(S.Half - 3, x).has(uppergamma) assert not uppergamma(S.Half + 3, x).has(uppergamma) assert uppergamma(S.Half, x, evaluate=False).has(uppergamma) assert tn(uppergamma(S.Half + 3, x, evaluate=False), uppergamma(S.Half + 3, x), x) assert tn(uppergamma(S.Half - 3, x, evaluate=False), uppergamma(S.Half - 3, x), x) assert uppergamma(x, y).rewrite(lowergamma) == gamma(x) - lowergamma(x, y) assert tn_branch(-3, uppergamma) assert tn_branch(-4, uppergamma) assert tn_branch(S(1)/3, uppergamma) assert tn_branch(pi, uppergamma) assert uppergamma(3, exp_polar(4*pi*I)*x) == uppergamma(3, x) assert uppergamma(y, exp_polar(5*pi*I)*x) == \ exp(4*I*pi*y)*uppergamma(y, x*exp_polar(pi*I)) + gamma(y)*(1-exp(4*pi*I*y)) assert uppergamma(-2, exp_polar(5*pi*I)*x) == \ uppergamma(-2, x*exp_polar(I*pi)) - 2*pi*I assert uppergamma(-2, x) == expint(3, x)/x**2 assert uppergamma(x, y).rewrite(expint) == y**x*expint(-x + 1, y)
def test_lowergamma(): from sympy import meijerg, exp_polar, I, expint assert lowergamma(x, y).diff(y) == y**(x-1)*exp(-y) assert td(lowergamma(randcplx(), y), y) assert lowergamma(x, y).diff(x) == \ gamma(x)*polygamma(0, x) - uppergamma(x, y)*log(y) \ + meijerg([], [1, 1], [0, 0, x], [], y) assert lowergamma(S.Half, x) == sqrt(pi)*erf(sqrt(x)) assert not lowergamma(S.Half - 3, x).has(lowergamma) assert not lowergamma(S.Half + 3, x).has(lowergamma) assert lowergamma(S.Half, x, evaluate=False).has(lowergamma) assert tn(lowergamma(S.Half + 3, x, evaluate=False), lowergamma(S.Half + 3, x), x) assert tn(lowergamma(S.Half - 3, x, evaluate=False), lowergamma(S.Half - 3, x), x) assert lowergamma(x, y).rewrite(uppergamma) == gamma(x) - uppergamma(x, y) assert tn_branch(-3, lowergamma) assert tn_branch(-4, lowergamma) assert tn_branch(S(1)/3, lowergamma) assert tn_branch(pi, lowergamma) assert lowergamma(3, exp_polar(4*pi*I)*x) == lowergamma(3, x) assert lowergamma(y, exp_polar(5*pi*I)*x) == \ exp(4*I*pi*y)*lowergamma(y, x*exp_polar(pi*I)) assert lowergamma(-2, exp_polar(5*pi*I)*x) == \ lowergamma(-2, x*exp_polar(I*pi)) + 2*pi*I assert lowergamma(x, y).rewrite(expint) == -y**x*expint(-x + 1, y) + gamma(x) k = Symbol('k', integer=True) assert lowergamma(k, y).rewrite(expint) == -y**k*expint(-k + 1, y) + gamma(k) k = Symbol('k', integer=True, positive=False) assert lowergamma(k, y).rewrite(expint) == lowergamma(k, y)
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)
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)
def test_issue_8368(): assert integrate(exp(-s*x)*cosh(x), (x, 0, oo)) == \ Piecewise( ( pi*Piecewise( ( -s/(pi*(-s**2 + 1)), Abs(s**2) < 1), ( 1/(pi*s*(1 - 1/s**2)), Abs(s**(-2)) < 1), ( meijerg( ((S(1)/2,), (0, 0)), ((0, S(1)/2), (0,)), polar_lift(s)**2), True) ), And( Abs(periodic_argument(polar_lift(s)**2, oo)) < pi, cos(Abs(periodic_argument(polar_lift(s)**2, oo))/2)*sqrt(Abs(s**2)) - 1 > 0, Ne(s**2, 1)) ), ( Integral(exp(-s*x)*cosh(x), (x, 0, oo)), True)) assert integrate(exp(-s*x)*sinh(x), (x, 0, oo)) == \ Piecewise( ( -1/(s + 1)/2 - 1/(-s + 1)/2, And( Ne(1/s, 1), Abs(periodic_argument(s, oo)) < pi/2, Abs(periodic_argument(s, oo)) <= pi/2, cos(Abs(periodic_argument(s, oo)))*Abs(s) - 1 > 0)), ( Integral(exp(-s*x)*sinh(x), (x, 0, oo)), True))
def test_expint(): assert mytn(expint(x, y), expint(x, y).rewrite(uppergamma), y ** (x - 1) * uppergamma(1 - x, y), x) assert mytd(expint(x, y), -y ** (x - 1) * meijerg([], [1, 1], [0, 0, 1 - x], [], y), x) assert mytd(expint(x, y), -expint(x - 1, y), y) assert mytn(expint(1, x), expint(1, x).rewrite(Ei), -Ei(x * polar_lift(-1)) + I * pi, x) assert ( expint(-4, x) == exp(-x) / x + 4 * exp(-x) / x ** 2 + 12 * exp(-x) / x ** 3 + 24 * exp(-x) / x ** 4 + 24 * exp(-x) / x ** 5 ) assert expint(-S(3) / 2, x) == exp(-x) / x + 3 * exp(-x) / (2 * x ** 2) - 3 * sqrt(pi) * erf(sqrt(x)) / ( 4 * x ** S("5/2") ) + 3 * sqrt(pi) / (4 * x ** S("5/2")) assert tn_branch(expint, 1) assert tn_branch(expint, 2) assert tn_branch(expint, 3) assert tn_branch(expint, 1.7) assert tn_branch(expint, pi) assert expint(y, x * exp_polar(2 * I * pi)) == x ** (y - 1) * (exp(2 * I * pi * y) - 1) * gamma(-y + 1) + expint( y, x ) assert expint(y, x * exp_polar(-2 * I * pi)) == x ** (y - 1) * (exp(-2 * I * pi * y) - 1) * gamma(-y + 1) + expint( y, x ) assert expint(2, x * exp_polar(2 * I * pi)) == 2 * I * pi * x + expint(2, x) assert expint(2, x * exp_polar(-2 * I * pi)) == -2 * I * pi * x + expint(2, x) assert expint(1, x).rewrite(Ei).rewrite(expint) == expint(1, x) assert mytn(E1(x), E1(x).rewrite(Shi), Shi(x) - Chi(x), x) assert mytn(E1(polar_lift(I) * x), E1(polar_lift(I) * x).rewrite(Si), -Ci(x) + I * Si(x) - I * pi / 2, x) assert mytn(expint(2, x), expint(2, x).rewrite(Ei).rewrite(expint), -x * E1(x) + exp(-x), x) assert mytn(expint(3, x), expint(3, x).rewrite(Ei).rewrite(expint), x ** 2 * E1(x) / 2 + (1 - x) * exp(-x) / 2, x)
def test_meijerg_formulae(): from sympy.simplify.hyperexpand import MeijerFormulaCollection formulae = MeijerFormulaCollection().formulae for sig in formulae: for formula in formulae[sig]: g = meijerg(formula.func.an, formula.func.ap, formula.func.bm, formula.func.bq, formula.z) rep = {} for sym in formula.symbols: rep[sym] = randcplx() # first test if the closed-form is actually correct g = g.subs(rep) closed_form = formula.closed_form.subs(rep) z = formula.z assert tn(g, closed_form, z) # now test the computed matrix cl = (formula.C * formula.B)[0].subs(rep) assert tn(closed_form, cl, z) deriv1 = z*formula.B.diff(z) deriv2 = formula.M * formula.B for d1, d2 in zip(deriv1, deriv2): assert tn(d1.subs(rep), d2.subs(rep), z)
def test_lerchphi(): from sympy import combsimp, exp_polar, polylog, log, lerchphi assert hyperexpand(hyper([1, a], [a + 1], z)/a) == lerchphi(z, 1, a) assert hyperexpand( hyper([1, a, a], [a + 1, a + 1], z)/a**2) == lerchphi(z, 2, a) assert hyperexpand(hyper([1, a, a, a], [a + 1, a + 1, a + 1], z)/a**3) == \ lerchphi(z, 3, a) assert hyperexpand(hyper([1] + [a]*10, [a + 1]*10, z)/a**10) \ == lerchphi(z, 10, a) assert combsimp(hyperexpand(meijerg([0, 1 - a], [], [0], [-a], exp_polar(-I*pi)*z))) == \ lerchphi(z, 1, a) assert combsimp(hyperexpand(meijerg([0, 1 - a, 1 - a], [], [0], [-a, -a], exp_polar(-I*pi)*z))) == \ lerchphi(z, 2, a) assert combsimp( hyperexpand(meijerg([0, 1 - a, 1 - a, 1 - a], [], [0], [-a, -a, -a], exp_polar(-I*pi)*z))) == \ lerchphi(z, 3, a) assert hyperexpand(z*hyper([1, 1], [2], z)) == -log(1 + -z) assert hyperexpand(z*hyper([1, 1, 1], [2, 2], z)) == polylog(2, z) assert hyperexpand(z*hyper([1, 1, 1, 1], [2, 2, 2], z)) == polylog(3, z) assert hyperexpand(hyper([1, a, 1 + S(1)/2], [a + 1, S(1)/2], z)) == \ -2*a/(z - 1) + (-2*a**2 + a)*lerchphi(z, 1, a) # Now numerical tests. These make sure reductions etc are carried out # correctly # a rational function (polylog at negative integer order) assert can_do([2, 2, 2], [1, 1]) # NOTE these contain log(1-x) etc ... better make sure we have |z| < 1 # reduction of order for polylog assert can_do([1, 1, 1, b + 5], [2, 2, b], div=10) # reduction of order for lerchphi # XXX lerchphi in mpmath is flaky assert can_do( [1, a, a, a, b + 5], [a + 1, a + 1, a + 1, b], numerical=False) # test a bug from sympy import Abs assert hyperexpand(hyper([S(1)/2, S(1)/2, S(1)/2, 1], [S(3)/2, S(3)/2, S(3)/2], S(1)/4)) == \ Abs(-polylog(3, exp_polar(I*pi)/2) + polylog(3, S(1)/2))
def fdiff(self, argindex): from sympy import meijerg nu, z = self.args if argindex == 1: return -z**(nu - 1)*meijerg([], [1, 1], [0, 0, 1 - nu], [], z) elif argindex == 2: return -expint(nu - 1, z) else: raise ArgumentIndexError(self, argindex)
def fdiff(self, argindex=2): from sympy import meijerg if argindex == 2: a, z = self.args return -C.exp(-z)*z**(a-1) elif argindex == 1: a, z = self.args return uppergamma(a, z)*log(z) + meijerg([], [1, 1], [0, 0, a], [], z) else: raise ArgumentIndexError(self, argindex)
def test_limits(): k, x = symbols('k, x') assert hyper((1,), (Rational(4, 3), Rational(5, 3)), k**2).series(k) == \ 1 + 9*k**2/20 + 81*k**4/1120 + O(k**6) # issue 6350 assert limit(meijerg((), (), (1,), (0,), -x), x, 0) == \ meijerg(((), ()), ((1,), (0,)), 0) # issue 6052
def test_erf(): assert erf(nan) is nan assert erf(oo) == 1 assert erf(-oo) == -1 assert erf(0) == 0 assert erf(I * oo) == oo * I assert erf(-I * oo) == -oo * I assert erf(-2) == -erf(2) assert erf(-x * y) == -erf(x * y) assert erf(-x - y) == -erf(x + y) assert erf(erfinv(x)) == x assert erf(erfcinv(x)) == 1 - x assert erf(erf2inv(0, x)) == x assert erf(erf2inv(0, x, evaluate=False)) == x # To cover code in erf assert erf(erf2inv(0, erf(erfcinv(1 - erf(erfinv(x)))))) == x assert erf(I).is_real == False assert erf(0).is_real == True assert conjugate(erf(z)) == erf(conjugate(z)) assert erf(x).as_leading_term(x) == 2 * x / sqrt(pi) assert erf(x * y).as_leading_term(y) == 2 * x * y / sqrt(pi) assert (erf(x * y) / erf(y)).as_leading_term(y) == x assert erf(1 / x).as_leading_term(x) == erf(1 / x) assert erf(z).rewrite('uppergamma') == sqrt(z** 2) * (1 - erfc(sqrt(z**2))) / z assert erf(z).rewrite('erfc') == S.One - erfc(z) assert erf(z).rewrite('erfi') == -I * erfi(I * z) assert erf(z).rewrite('fresnels') == (1 + I) * ( fresnelc(z * (1 - I) / sqrt(pi)) - I * fresnels(z * (1 - I) / sqrt(pi))) assert erf(z).rewrite('fresnelc') == (1 + I) * ( fresnelc(z * (1 - I) / sqrt(pi)) - I * fresnels(z * (1 - I) / sqrt(pi))) assert erf(z).rewrite('hyper') == 2 * z * hyper([S.Half], [3 * S.Half], -z**2) / sqrt(pi) assert erf(z).rewrite('meijerg') == z * meijerg( [S.Half], [], [0], [Rational(-1, 2)], z**2) / sqrt(pi) assert erf(z).rewrite( 'expint') == sqrt(z**2) / z - z * expint(S.Half, z**2) / sqrt(S.Pi) assert limit(exp(x)*exp(x**2)*(erf(x + 1/exp(x)) - erf(x)), x, oo) == \ 2/sqrt(pi) assert limit((1 - erf(z)) * exp(z**2) * z, z, oo) == 1 / sqrt(pi) assert limit((1 - erf(x)) * exp(x**2) * sqrt(pi) * x, x, oo) == 1 assert limit(((1 - erf(x)) * exp(x**2) * sqrt(pi) * x - 1) * 2 * x**2, x, oo) == -1 assert limit(erf(x) / x, x, 0) == 2 / sqrt(pi) assert limit(x**(-4) - sqrt(pi) * erf(x**2) / (2 * x**6), x, 0) == S(1) / 3 assert erf(x).as_real_imag() == \ (erf(re(x) - I*im(x))/2 + erf(re(x) + I*im(x))/2, -I*(-erf(re(x) - I*im(x)) + erf(re(x) + I*im(x)))/2) assert erf(x).as_real_imag(deep=False) == \ (erf(re(x) - I*im(x))/2 + erf(re(x) + I*im(x))/2, -I*(-erf(re(x) - I*im(x)) + erf(re(x) + I*im(x)))/2) assert erf(w).as_real_imag() == (erf(w), 0) assert erf(w).as_real_imag(deep=False) == (erf(w), 0) # issue 13575 assert erf(I).as_real_imag() == (0, -I * erf(I)) raises(ArgumentIndexError, lambda: erf(x).fdiff(2)) assert erf(x).inverse() == erfinv
def test_meijer(): raises(TypeError, lambda: meijerg(1, z)) raises(TypeError, lambda: meijerg(((1,), (2,)), (3,), (4,), z)) assert meijerg(((1, 2), (3,)), ((4,), (5,)), z) == meijerg( Tuple(1, 2), Tuple(3), Tuple(4), Tuple(5), z ) g = meijerg((1, 2), (3, 4, 5), (6, 7, 8, 9), (10, 11, 12, 13, 14), z) assert g.an == Tuple(1, 2) assert g.ap == Tuple(1, 2, 3, 4, 5) assert g.aother == Tuple(3, 4, 5) assert g.bm == Tuple(6, 7, 8, 9) assert g.bq == Tuple(6, 7, 8, 9, 10, 11, 12, 13, 14) assert g.bother == Tuple(10, 11, 12, 13, 14) assert g.argument == z assert g.nu == 75 assert g.delta == -1 assert g.is_commutative is True assert g.is_number is False # issue 13071 assert meijerg([[], []], [[S.Half], [0]], 1).is_number is True assert meijerg([1, 2], [3], [4], [5], z).delta == S.Half # just a few checks to make sure that all arguments go where they should assert tn(meijerg(Tuple(), Tuple(), Tuple(0), Tuple(), -z), exp(z), z) assert tn( sqrt(pi) * meijerg(Tuple(), Tuple(), Tuple(0), Tuple(S.Half), z ** 2 / 4), cos(z), z, ) assert tn(meijerg(Tuple(1, 1), Tuple(), Tuple(1), Tuple(0), z), log(1 + z), z) # test exceptions raises(ValueError, lambda: meijerg(((3, 1), (2,)), ((oo,), (2, 0)), x)) raises(ValueError, lambda: meijerg(((3, 1), (2,)), ((1,), (2, 0)), x)) # differentiation g = meijerg( (randcplx(),), (randcplx() + 2 * I,), Tuple(), (randcplx(), randcplx()), z ) assert td(g, z) g = meijerg(Tuple(), (randcplx(),), Tuple(), (randcplx(), randcplx()), z) assert td(g, z) g = meijerg(Tuple(), Tuple(), Tuple(randcplx()), Tuple(randcplx(), randcplx()), z) assert td(g, z) a1, a2, b1, b2, c1, c2, d1, d2 = symbols("a1:3, b1:3, c1:3, d1:3") assert ( meijerg((a1, a2), (b1, b2), (c1, c2), (d1, d2), z).diff(z) == ( meijerg((a1 - 1, a2), (b1, b2), (c1, c2), (d1, d2), z) + (a1 - 1) * meijerg((a1, a2), (b1, b2), (c1, c2), (d1, d2), z) ) / z ) assert meijerg([z, z], [], [], [], z).diff(z) == Derivative( meijerg([z, z], [], [], [], z), z ) # meijerg is unbranched wrt parameters from sympy import polar_lift as pl assert meijerg([pl(a1)], [pl(a2)], [pl(b1)], [pl(b2)], pl(z)) == meijerg( [a1], [a2], [b1], [b2], pl(z) ) # integrand from sympy.abc import a, b, c, d, s assert meijerg([a], [b], [c], [d], z).integrand(s) == z ** s * gamma(c - s) * gamma( -a + s + 1 ) / (gamma(b - s) * gamma(-d + s + 1))
def test_fresnel(): assert fresnels(0) == 0 assert fresnels(oo) == S.Half assert fresnels(-oo) == Rational(-1, 2) 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([Rational(3, 4)], [Rational(3, 2), Rational(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 == True assert fresnels(w).is_finite == 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**Rational(9, 4) * \ meijerg(((), (1,)), ((Rational(3, 4),), (Rational(1, 4), 0)), -pi**2*z**4/16)/(2*(-z)**Rational(3, 4)*(z**2)**Rational(3, 4)) assert fresnelc(0) == 0 assert fresnelc(oo) == S.Half assert fresnelc(-oo) == Rational(-1, 2) 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([Rational(1, 4)], [S.Half, Rational(5, 4)], -pi**2*z**4/16) assert fresnelc(w).is_extended_real == 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**Rational(3, 4) * \ meijerg(((), (1,)), ((Rational(1, 4),), (Rational(3, 4), 0)), -pi**2*z**4/16)/(2*(-z)**Rational(1, 4)*(z**2)**Rational(1, 4)) from sympy.testing.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) is S.Zero assert fresnelc(x).taylor_term(-1, x) is S.Zero assert fresnelc(x).taylor_term(1, x) == -pi**2 * x**5 / 40
def test_expint(): assert mytn(expint(x, y), expint(x, y).rewrite(uppergamma), y**(x - 1) * uppergamma(1 - x, y), x) assert mytd(expint(x, y), -y**(x - 1) * meijerg([], [1, 1], [0, 0, 1 - x], [], y), x) assert mytd(expint(x, y), -expint(x - 1, y), y) assert mytn(expint(1, x), expint(1, x).rewrite(Ei), -Ei(x * polar_lift(-1)) + I * pi, x) assert expint(-4, x) == exp(-x)/x + 4*exp(-x)/x**2 + 12*exp(-x)/x**3 \ + 24*exp(-x)/x**4 + 24*exp(-x)/x**5 assert expint(Rational(-3, 2), x) == \ exp(-x)/x + 3*exp(-x)/(2*x**2) + 3*sqrt(pi)*erfc(sqrt(x))/(4*x**S('5/2')) assert tn_branch(expint, 1) assert tn_branch(expint, 2) assert tn_branch(expint, 3) assert tn_branch(expint, 1.7) assert tn_branch(expint, pi) assert expint(y, x*exp_polar(2*I*pi)) == \ x**(y - 1)*(exp(2*I*pi*y) - 1)*gamma(-y + 1) + expint(y, x) assert expint(y, x*exp_polar(-2*I*pi)) == \ x**(y - 1)*(exp(-2*I*pi*y) - 1)*gamma(-y + 1) + expint(y, x) assert expint(2, x * exp_polar(2 * I * pi)) == 2 * I * pi * x + expint(2, x) assert expint(2, x * exp_polar(-2 * I * pi)) == -2 * I * pi * x + expint(2, x) assert expint(1, x).rewrite(Ei).rewrite(expint) == expint(1, x) assert expint(x, y).rewrite(Ei) == expint(x, y) assert expint(x, y).rewrite(Ci) == expint(x, y) assert mytn(E1(x), E1(x).rewrite(Shi), Shi(x) - Chi(x), x) assert mytn(E1(polar_lift(I) * x), E1(polar_lift(I) * x).rewrite(Si), -Ci(x) + I * Si(x) - I * pi / 2, x) assert mytn(expint(2, x), expint(2, x).rewrite(Ei).rewrite(expint), -x * E1(x) + exp(-x), x) assert mytn(expint(3, x), expint(3, x).rewrite(Ei).rewrite(expint), x**2 * E1(x) / 2 + (1 - x) * exp(-x) / 2, x) assert expint(Rational(3, 2), z).nseries(z) == \ 2 + 2*z - z**2/3 + z**3/15 - z**4/84 + z**5/540 - \ 2*sqrt(pi)*sqrt(z) + O(z**6) assert E1(z).series(z) == -EulerGamma - log(z) + z - \ z**2/4 + z**3/18 - z**4/96 + z**5/600 + O(z**6) assert expint(4, z).series(z) == Rational(1, 3) - z/2 + z**2/2 + \ z**3*(log(z)/6 - Rational(11, 36) + EulerGamma/6 - I*pi/6) - z**4/24 + \ z**5/240 + O(z**6) assert expint(z, y).series(z, 0, 2) == exp(-y) / y - z * meijerg( ((), (1, 1)), ((0, 0, 1), ()), y) / y + O(z**2) raises(ArgumentIndexError, lambda: expint(x, y).fdiff(3)) neg = Symbol('neg', negative=True) assert Ei(neg).rewrite(Si) == Shi(neg) + Chi(neg) - I * pi
def plot_and_save(name): tmp_file = TmpFileManager.tmp_file x = Symbol('x') y = Symbol('y') z = Symbol('z') ### # Examples from the 'introduction' notebook ### p = plot(x) p = plot(x * sin(x), x * cos(x)) p.extend(p) p[0].line_color = lambda a: a p[1].line_color = 'b' p.title = 'Big title' p.xlabel = 'the x axis' p[1].label = 'straight line' p.legend = True p.aspect_ratio = (1, 1) p.xlim = (-15, 20) p.save(tmp_file('%s_basic_options_and_colors' % name)) p._backend.close() p.extend(plot(x + 1)) p.append(plot(x + 3, x**2)[1]) p.save(tmp_file('%s_plot_extend_append' % name)) p[2] = plot(x**2, (x, -2, 3)) p.save(tmp_file('%s_plot_setitem' % name)) p._backend.close() p = plot(sin(x), (x, -2 * pi, 4 * pi)) p.save(tmp_file('%s_line_explicit' % name)) p._backend.close() p = plot(sin(x)) p.save(tmp_file('%s_line_default_range' % name)) p._backend.close() p = plot((x**2, (x, -5, 5)), (x**3, (x, -3, 3))) p.save(tmp_file('%s_line_multiple_range' % name)) p._backend.close() raises(ValueError, lambda: plot(x, y)) p = plot(Piecewise((1, x > 0), (0, True)), (x, -1, 1)) p.save(tmp_file('%s_plot_piecewise' % name)) p._backend.close() #parametric 2d plots. #Single plot with default range. plot_parametric(sin(x), cos(x)).save(tmp_file()) #Single plot with range. p = plot_parametric(sin(x), cos(x), (x, -5, 5)) p.save(tmp_file('%s_parametric_range' % name)) p._backend.close() #Multiple plots with same range. p = plot_parametric((sin(x), cos(x)), (x, sin(x))) p.save(tmp_file('%s_parametric_multiple' % name)) p._backend.close() #Multiple plots with different ranges. p = plot_parametric((sin(x), cos(x), (x, -3, 3)), (x, sin(x), (x, -5, 5))) p.save(tmp_file('%s_parametric_multiple_ranges' % name)) p._backend.close() #depth of recursion specified. p = plot_parametric(x, sin(x), depth=13) p.save(tmp_file('%s_recursion_depth' % name)) p._backend.close() #No adaptive sampling. p = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500) p.save(tmp_file('%s_adaptive' % name)) p._backend.close() #3d parametric plots p = plot3d_parametric_line(sin(x), cos(x), x) p.save(tmp_file('%s_3d_line' % name)) p._backend.close() p = plot3d_parametric_line((sin(x), cos(x), x, (x, -5, 5)), (cos(x), sin(x), x, (x, -3, 3))) p.save(tmp_file('%s_3d_line_multiple' % name)) p._backend.close() p = plot3d_parametric_line(sin(x), cos(x), x, nb_of_points=30) p.save(tmp_file('%s_3d_line_points' % name)) p._backend.close() # 3d surface single plot. p = plot3d(x * y) p.save(tmp_file('%s_surface' % name)) p._backend.close() # Multiple 3D plots with same range. p = plot3d(-x * y, x * y, (x, -5, 5)) p.save(tmp_file('%s_surface_multiple' % name)) p._backend.close() # Multiple 3D plots with different ranges. p = plot3d((x * y, (x, -3, 3), (y, -3, 3)), (-x * y, (x, -3, 3), (y, -3, 3))) p.save(tmp_file('%s_surface_multiple_ranges' % name)) p._backend.close() # Single Parametric 3D plot p = plot3d_parametric_surface(sin(x + y), cos(x - y), x - y) p.save(tmp_file('%s_parametric_surface' % name)) p._backend.close() # Multiple Parametric 3D plots. p = plot3d_parametric_surface( (x * sin(z), x * cos(z), z, (x, -5, 5), (z, -5, 5)), (sin(x + y), cos(x - y), x - y, (x, -5, 5), (y, -5, 5))) p.save(tmp_file('%s_parametric_surface' % name)) p._backend.close() ### # Examples from the 'colors' notebook ### p = plot(sin(x)) p[0].line_color = lambda a: a p.save(tmp_file('%s_colors_line_arity1' % name)) p[0].line_color = lambda a, b: b p.save(tmp_file('%s_colors_line_arity2' % name)) p._backend.close() p = plot(x * sin(x), x * cos(x), (x, 0, 10)) p[0].line_color = lambda a: a p.save(tmp_file('%s_colors_param_line_arity1' % name)) p[0].line_color = lambda a, b: a p.save(tmp_file('%s_colors_param_line_arity2a' % name)) p[0].line_color = lambda a, b: b p.save(tmp_file('%s_colors_param_line_arity2b' % name)) p._backend.close() p = plot3d_parametric_line( sin(x) + 0.1 * sin(x) * cos(7 * x), cos(x) + 0.1 * cos(x) * cos(7 * x), 0.1 * sin(7 * x), (x, 0, 2 * pi)) p[0].line_color = lambdify_(x, sin(4 * x)) p.save(tmp_file('%s_colors_3d_line_arity1' % name)) p[0].line_color = lambda a, b: b p.save(tmp_file('%s_colors_3d_line_arity2' % name)) p[0].line_color = lambda a, b, c: c p.save(tmp_file('%s_colors_3d_line_arity3' % name)) p._backend.close() p = plot3d(sin(x) * y, (x, 0, 6 * pi), (y, -5, 5)) p[0].surface_color = lambda a: a p.save(tmp_file('%s_colors_surface_arity1' % name)) p[0].surface_color = lambda a, b: b p.save(tmp_file('%s_colors_surface_arity2' % name)) p[0].surface_color = lambda a, b, c: c p.save(tmp_file('%s_colors_surface_arity3a' % name)) p[0].surface_color = lambdify_((x, y, z), sqrt((x - 3 * pi)**2 + y**2)) p.save(tmp_file('%s_colors_surface_arity3b' % name)) p._backend.close() p = plot3d_parametric_surface(x * cos(4 * y), x * sin(4 * y), y, (x, -1, 1), (y, -1, 1)) p[0].surface_color = lambda a: a p.save(tmp_file('%s_colors_param_surf_arity1' % name)) p[0].surface_color = lambda a, b: a * b p.save(tmp_file('%s_colors_param_surf_arity2' % name)) p[0].surface_color = lambdify_((x, y, z), sqrt(x**2 + y**2 + z**2)) p.save(tmp_file('%s_colors_param_surf_arity3' % name)) p._backend.close() ### # Examples from the 'advanced' notebook ### # XXX: This raises the warning "The evaluation of the expression is # problematic. We are trying a failback method that may still work. Please # report this as a bug." It has to use the fallback because using evalf() # is the only way to evaluate the integral. We should perhaps just remove # that warning. with warnings.catch_warnings(record=True) as w: i = Integral(log((sin(x)**2 + 1) * sqrt(x**2 + 1)), (x, 0, y)) p = plot(i, (y, 1, 5)) p.save(tmp_file('%s_advanced_integral' % name)) p._backend.close() # Make sure no other warnings were raised assert len(w) == 1 assert issubclass(w[-1].category, UserWarning) assert "The evaluation of the expression is problematic" in str( w[0].message) s = Sum(1 / x**y, (x, 1, oo)) p = plot(s, (y, 2, 10)) p.save(tmp_file('%s_advanced_inf_sum' % name)) p._backend.close() p = plot(Sum(1 / x, (x, 1, y)), (y, 2, 10), show=False) p[0].only_integers = True p[0].steps = True p.save(tmp_file('%s_advanced_fin_sum' % name)) p._backend.close() ### # Test expressions that can not be translated to np and generate complex # results. ### plot(sin(x) + I * cos(x)).save(tmp_file()) plot(sqrt(sqrt(-x))).save(tmp_file()) plot(LambertW(x)).save(tmp_file()) plot(sqrt(LambertW(x))).save(tmp_file()) #Characteristic function of a StudentT distribution with nu=10 plot((meijerg( ((1 / 2, ), ()), ((5, 0, 1 / 2), ()), 5 * x**2 * exp_polar(-I * pi) / 2) + meijerg( ((1 / 2, ), ()), ((5, 0, 1 / 2), ()), 5 * x**2 * exp_polar(I * pi) / 2)) / (48 * pi), (x, 1e-6, 1e-2)).save(tmp_file())
def test_meijerint(): from sympy import symbols, expand, arg s, t, mu = symbols('s t mu', real=True) assert integrate( meijerg([], [], [0], [], s * t) * meijerg([], [], [mu / 2], [-mu / 2], t**2 / 4), (t, 0, oo)).is_Piecewise s = symbols('s', positive=True) assert integrate(x**s*meijerg([[],[]], [[0],[]], x), (x, 0, oo)) \ == gamma(s + 1) assert integrate(x**s * meijerg([[], []], [[0], []], x), (x, 0, oo), meijerg=True) == gamma(s + 1) assert isinstance( integrate(x**s * meijerg([[], []], [[0], []], x), (x, 0, oo), meijerg=False), Integral) assert meijerint_indefinite(exp(x), x) == exp(x) # TODO what simplifications should be done automatically? # This tests "extra case" for antecedents_1. a, b = symbols('a b', positive=True) assert simplify(meijerint_definite(x**a, x, 0, b)[0]) \ == b**(a + 1)/(a + 1) # This tests various conditions and expansions: meijerint_definite((x + 1)**3 * exp(-x), x, 0, oo) == (16, True) # Again, how about simplifications? sigma, mu = symbols('sigma mu', positive=True) i, c = meijerint_definite(exp(-((x - mu) / (2 * sigma))**2), x, 0, oo) assert simplify(i) \ == sqrt(pi)*sigma*(erf(mu/(2*sigma)) + 1) assert c is True i, _ = meijerint_definite(exp(-mu * x) * exp(sigma * x), x, 0, oo) # TODO it would be nice to test the condition assert simplify(i) == 1 / (mu - sigma) # Test substitutions to change limits assert meijerint_definite(exp(x), x, -oo, 2) == (exp(2), True) assert expand(meijerint_definite(exp(x), x, 0, I)[0]) == exp(I) - 1 assert expand(meijerint_definite(exp(-x), x, 0, x)[0]) == \ 1 - exp(-exp(I*arg(x))*abs(x)) # Test -oo to oo assert meijerint_definite(exp(-x**2), x, -oo, oo) == (sqrt(pi), True) assert meijerint_definite(exp(-abs(x)), x, -oo, oo) == (2, True) assert meijerint_definite(exp(-(2 * x - 3)**2), x, -oo, oo) == (sqrt(pi) / 2, True) assert meijerint_definite(exp(-abs(2 * x - 3)), x, -oo, oo) == (1, True) assert meijerint_definite( exp(-((x - mu) / sigma)**2 / 2) / sqrt(2 * pi * sigma**2), x, -oo, oo) == (1, True) # Test one of the extra conditions for 2 g-functinos assert meijerint_definite(exp(-x) * sin(x), x, 0, oo) == (S(1) / 2, True) # Test a bug def res(n): return (1 / (1 + x**2)).diff(x, n).subs(x, 1) * (-1)**n for n in range(6): assert integrate(exp(-x) * sin(x) * x**n, (x, 0, oo), meijerg=True) == res(n) # Test trigexpand: assert integrate(exp(-x)*sin(x + a), (x, 0, oo), meijerg=True) == \ sin(a)/2 + cos(a)/2
def test_lowergamma(): from sympy import meijerg, exp_polar, I, expint assert lowergamma(x, 0) == 0 assert lowergamma(x, y).diff(y) == y**(x - 1) * exp(-y) assert td(lowergamma(randcplx(), y), y) assert td(lowergamma(x, randcplx()), x) assert lowergamma(x, y).diff(x) == \ gamma(x)*digamma(x) - uppergamma(x, y)*log(y) \ - meijerg([], [1, 1], [0, 0, x], [], y) assert lowergamma(S.Half, x) == sqrt(pi) * erf(sqrt(x)) assert not lowergamma(S.Half - 3, x).has(lowergamma) assert not lowergamma(S.Half + 3, x).has(lowergamma) assert lowergamma(S.Half, x, evaluate=False).has(lowergamma) assert tn(lowergamma(S.Half + 3, x, evaluate=False), lowergamma(S.Half + 3, x), x) assert tn(lowergamma(S.Half - 3, x, evaluate=False), lowergamma(S.Half - 3, x), x) assert tn_branch(-3, lowergamma) assert tn_branch(-4, lowergamma) assert tn_branch(Rational(1, 3), lowergamma) assert tn_branch(pi, lowergamma) assert lowergamma(3, exp_polar(4 * pi * I) * x) == lowergamma(3, x) assert lowergamma(y, exp_polar(5*pi*I)*x) == \ exp(4*I*pi*y)*lowergamma(y, x*exp_polar(pi*I)) assert lowergamma(-2, exp_polar(5*pi*I)*x) == \ lowergamma(-2, x*exp_polar(I*pi)) + 2*pi*I assert conjugate(lowergamma(x, y)) == lowergamma(conjugate(x), conjugate(y)) assert conjugate(lowergamma(x, 0)) == 0 assert unchanged(conjugate, lowergamma(x, -oo)) assert lowergamma(0, x)._eval_is_meromorphic(x, 0) == False assert lowergamma(S(1) / 3, x)._eval_is_meromorphic(x, 0) == False assert lowergamma(1, x, evaluate=False)._eval_is_meromorphic(x, 0) == True assert lowergamma(x, x)._eval_is_meromorphic(x, 0) == False assert lowergamma(x + 1, x)._eval_is_meromorphic(x, 0) == False assert lowergamma(1 / x, x)._eval_is_meromorphic(x, 0) == False assert lowergamma(0, x + 1)._eval_is_meromorphic(x, 0) == False assert lowergamma(S(1) / 3, x + 1)._eval_is_meromorphic(x, 0) == True assert lowergamma(1, x + 1, evaluate=False)._eval_is_meromorphic(x, 0) == True assert lowergamma(x, x + 1)._eval_is_meromorphic(x, 0) == True assert lowergamma(x + 1, x + 1)._eval_is_meromorphic(x, 0) == True assert lowergamma(1 / x, x + 1)._eval_is_meromorphic(x, 0) == False assert lowergamma(0, 1 / x)._eval_is_meromorphic(x, 0) == False assert lowergamma(S(1) / 3, 1 / x)._eval_is_meromorphic(x, 0) == False assert lowergamma(1, 1 / x, evaluate=False)._eval_is_meromorphic(x, 0) == False assert lowergamma(x, 1 / x)._eval_is_meromorphic(x, 0) == False assert lowergamma(x + 1, 1 / x)._eval_is_meromorphic(x, 0) == False assert lowergamma(1 / x, 1 / x)._eval_is_meromorphic(x, 0) == False assert lowergamma(x, 2).series(x, oo, 3) == \ 2**x*(1 + 2/(x + 1))*exp(-2)/x + O(exp(x*log(2))/x**3, (x, oo)) assert lowergamma( x, y).rewrite(expint) == -y**x * expint(-x + 1, y) + gamma(x) k = Symbol('k', integer=True) assert lowergamma( k, y).rewrite(expint) == -y**k * expint(-k + 1, y) + gamma(k) k = Symbol('k', integer=True, positive=False) assert lowergamma(k, y).rewrite(expint) == lowergamma(k, y) assert lowergamma(x, y).rewrite(uppergamma) == gamma(x) - uppergamma(x, y) assert lowergamma(70, 6) == factorial( 69 ) - 69035724522603011058660187038367026272747334489677105069435923032634389419656200387949342530805432320 * exp( -6) assert (lowergamma(S(77) / 2, 6) - lowergamma(S(77) / 2, 6, evaluate=False)).evalf() < 1e-16 assert (lowergamma(-S(77) / 2, 6) - lowergamma(-S(77) / 2, 6, evaluate=False)).evalf() < 1e-16
def test_meijerg_expand(): from sympy import combsimp, simplify # from mpmath docs assert hyperexpand(meijerg([[], []], [[0], []], -z)) == exp(z) assert hyperexpand(meijerg([[1,1],[]], [[1],[0]], z)) == \ log(z + 1) assert hyperexpand(meijerg([[1,1],[]], [[1],[1]], z)) == \ z/(z + 1) assert hyperexpand(meijerg([[],[]], [[S(1)/2],[0]], (z/2)**2)) \ == sin(z)/sqrt(pi) assert hyperexpand(meijerg([[],[]], [[0], [S(1)/2]], (z/2)**2)) \ == cos(z)/sqrt(pi) assert can_do_meijer([], [a], [a - 1, a - S.Half], []) assert can_do_meijer([], [], [a / 2], [-a / 2], False) # branches... assert can_do_meijer([a], [b], [a], [b, a - 1]) # wikipedia assert hyperexpand(meijerg([1], [], [], [0], z)) == \ Piecewise((0, abs(z) < 1), (1, abs(1/z) < 1), (meijerg([1], [], [], [0], z), True)) assert hyperexpand(meijerg([], [1], [0], [], z)) == \ Piecewise((1, abs(z) < 1), (0, abs(1/z) < 1), (meijerg([], [1], [0], [], z), True)) # The Special Functions and their Approximations assert can_do_meijer([], [], [a + b / 2], [a, a - b / 2, a + S.Half]) assert can_do_meijer([], [], [a], [b], False) # branches only agree for small z assert can_do_meijer([], [S.Half], [a], [-a]) assert can_do_meijer([], [], [a, b], []) assert can_do_meijer([], [], [a, b], []) assert can_do_meijer([], [], [a, a + S.Half], [b, b + S.Half]) assert can_do_meijer([], [], [a, -a], [0, S.Half], False) # dito assert can_do_meijer([], [], [a, a + S.Half, b, b + S.Half], []) assert can_do_meijer([S.Half], [], [0], [a, -a]) assert can_do_meijer([S.Half], [], [a], [0, -a], False) # dito assert can_do_meijer([], [a - S.Half], [a, b], [a - S.Half], False) assert can_do_meijer([], [a + S.Half], [a + b, a - b, a], [], False) assert can_do_meijer([a + S.Half], [], [b, 2 * a - b, a], [], False) # This for example is actually zero. assert can_do_meijer([], [], [], [a, b]) # Testing a bug: assert hyperexpand(meijerg([0, 2], [], [], [-1, 1], z)) == \ Piecewise((0, abs(z) < 1), (z*(1 - 1/z**2)/2, abs(1/z) < 1), (meijerg([0, 2], [], [], [-1, 1], z), True)) # Test that the simplest possible answer is returned: assert combsimp(simplify(hyperexpand(meijerg([1], [1-a], [-a/2, -a/2 + S(1)/2], [], 1/z)))) == \ -2*sqrt(pi)*(sqrt(z + 1) + 1)**a/a
def tn(expr): assert _rewrite_single(meijerg([a], [b], [c], [d], expr), x) is None
def t(expr, c, m): e = _rewrite_single(meijerg([a], [b], [c], [d], expr), x) assert e is not None assert isinstance(e[0][0][2], meijerg) assert e[0][0][2].argument.as_coeff_mul(x) == (c, (m, ))
def test_meijerg_derivative(): assert meijerg([], [1, 1], [0, 0, x], [], z).diff(x) == log(z) * meijerg( [], [1, 1], [0, 0, x], [], z ) + 2 * meijerg([], [1, 1, 1], [0, 0, x, 0], [], z) y = randcplx() a = 5 # mpmath chokes with non-real numbers, and Mod1 with floats assert td(meijerg([x], [], [], [], y), x) assert td(meijerg([x ** 2], [], [], [], y), x) assert td(meijerg([], [x], [], [], y), x) assert td(meijerg([], [], [x], [], y), x) assert td(meijerg([], [], [], [x], y), x) assert td(meijerg([x], [a], [a + 1], [], y), x) assert td(meijerg([x], [a + 1], [a], [], y), x) assert td(meijerg([x, a], [], [], [a + 1], y), x) assert td(meijerg([x, a + 1], [], [], [a], y), x) b = Rational(3, 2) assert td(meijerg([a + 2], [b], [b - 3, x], [a], y), x)
def test_rewrite1(): assert _rewrite1(x**3*meijerg([a], [b], [c], [d], x**2 + y*x**2)*5, x) == \ (5, x**3, [(1, 0, meijerg([a], [b], [c], [d], x**2*(y + 1)))], True)
def test_branch_bug(): assert hyperexpand(hyper((-S(1)/3, S(1)/2), (S(2)/3, S(3)/2), -z)) == \ -z**S('1/3')*lowergamma(exp_polar(I*pi)/3, z)/5 \ + sqrt(pi)*erf(sqrt(z))/(5*sqrt(z)) assert hyperexpand(meijerg([S(7)/6, 1], [], [S(2)/3], [S(1)/6, 0], z)) == \ 2*z**S('2/3')*(2*sqrt(pi)*erf(sqrt(z))/sqrt(z) - 2*lowergamma(S(2)/3, z)/z**S('2/3'))*gamma(S(2)/3)/gamma(S(5)/3)
def plot_and_save(name): tmp_file = TmpFileManager.tmp_file x = Symbol('x') y = Symbol('y') z = Symbol('z') ### # Examples from the 'introduction' notebook ### p = plot(x) p = plot(x * sin(x), x * cos(x)) p.extend(p) p[0].line_color = lambda a: a p[1].line_color = 'b' p.title = 'Big title' p.xlabel = 'the x axis' p[1].label = 'straight line' p.legend = True p.aspect_ratio = (1, 1) p.xlim = (-15, 20) p.save(tmp_file('%s_basic_options_and_colors' % name)) p.extend(plot(x + 1)) p.append(plot(x + 3, x**2)[1]) p.save(tmp_file('%s_plot_extend_append' % name)) p[2] = plot(x**2, (x, -2, 3)) p.save(tmp_file('%s_plot_setitem' % name)) p = plot(sin(x), (x, -2 * pi, 4 * pi)) p.save(tmp_file('%s_line_explicit' % name)) p = plot(sin(x)) p.save(tmp_file('%s_line_default_range' % name)) p = plot((x**2, (x, -5, 5)), (x**3, (x, -3, 3))) p.save(tmp_file('%s_line_multiple_range' % name)) raises(ValueError, lambda: plot(x, y)) #parametric 2d plots. #Single plot with default range. plot_parametric(sin(x), cos(x)).save(tmp_file()) #Single plot with range. p = plot_parametric(sin(x), cos(x), (x, -5, 5)) p.save(tmp_file('%s_parametric_range' % name)) #Multiple plots with same range. p = plot_parametric((sin(x), cos(x)), (x, sin(x))) p.save(tmp_file('%s_parametric_multiple' % name)) #Multiple plots with different ranges. p = plot_parametric((sin(x), cos(x), (x, -3, 3)), (x, sin(x), (x, -5, 5))) p.save(tmp_file('%s_parametric_multiple_ranges' % name)) #depth of recursion specified. p = plot_parametric(x, sin(x), depth=13) p.save(tmp_file('%s_recursion_depth' % name)) #No adaptive sampling. p = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500) p.save(tmp_file('%s_adaptive' % name)) #3d parametric plots p = plot3d_parametric_line(sin(x), cos(x), x) p.save(tmp_file('%s_3d_line' % name)) p = plot3d_parametric_line((sin(x), cos(x), x, (x, -5, 5)), (cos(x), sin(x), x, (x, -3, 3))) p.save(tmp_file('%s_3d_line_multiple' % name)) p = plot3d_parametric_line(sin(x), cos(x), x, nb_of_points=30) p.save(tmp_file('%s_3d_line_points' % name)) # 3d surface single plot. p = plot3d(x * y) p.save(tmp_file('%s_surface' % name)) # Multiple 3D plots with same range. p = plot3d(-x * y, x * y, (x, -5, 5)) p.save(tmp_file('%s_surface_multiple' % name)) # Multiple 3D plots with different ranges. p = plot3d((x * y, (x, -3, 3), (y, -3, 3)), (-x * y, (x, -3, 3), (y, -3, 3))) p.save(tmp_file('%s_surface_multiple_ranges' % name)) # Single Parametric 3D plot p = plot3d_parametric_surface(sin(x + y), cos(x - y), x - y) p.save(tmp_file('%s_parametric_surface' % name)) # Multiple Parametric 3D plots. p = plot3d_parametric_surface( (x * sin(z), x * cos(z), z, (x, -5, 5), (z, -5, 5)), (sin(x + y), cos(x - y), x - y, (x, -5, 5), (y, -5, 5))) p.save(tmp_file('%s_parametric_surface' % name)) ### # Examples from the 'colors' notebook ### p = plot(sin(x)) p[0].line_color = lambda a: a p.save(tmp_file('%s_colors_line_arity1' % name)) p[0].line_color = lambda a, b: b p.save(tmp_file('%s_colors_line_arity2' % name)) p = plot(x * sin(x), x * cos(x), (x, 0, 10)) p[0].line_color = lambda a: a p.save(tmp_file('%s_colors_param_line_arity1' % name)) p[0].line_color = lambda a, b: a p.save(tmp_file('%s_colors_param_line_arity2a' % name)) p[0].line_color = lambda a, b: b p.save(tmp_file('%s_colors_param_line_arity2b' % name)) p = plot3d_parametric_line( sin(x) + 0.1 * sin(x) * cos(7 * x), cos(x) + 0.1 * cos(x) * cos(7 * x), 0.1 * sin(7 * x), (x, 0, 2 * pi)) p[0].line_color = lambda a: sin(4 * a) p.save(tmp_file('%s_colors_3d_line_arity1' % name)) p[0].line_color = lambda a, b: b p.save(tmp_file('%s_colors_3d_line_arity2' % name)) p[0].line_color = lambda a, b, c: c p.save(tmp_file('%s_colors_3d_line_arity3' % name)) p = plot3d(sin(x) * y, (x, 0, 6 * pi), (y, -5, 5)) p[0].surface_color = lambda a: a p.save(tmp_file('%s_colors_surface_arity1' % name)) p[0].surface_color = lambda a, b: b p.save(tmp_file('%s_colors_surface_arity2' % name)) p[0].surface_color = lambda a, b, c: c p.save(tmp_file('%s_colors_surface_arity3a' % name)) p[0].surface_color = lambda a, b, c: sqrt((a - 3 * pi)**2 + b**2) p.save(tmp_file('%s_colors_surface_arity3b' % name)) p = plot3d_parametric_surface(x * cos(4 * y), x * sin(4 * y), y, (x, -1, 1), (y, -1, 1)) p[0].surface_color = lambda a: a p.save(tmp_file('%s_colors_param_surf_arity1' % name)) p[0].surface_color = lambda a, b: a * b p.save(tmp_file('%s_colors_param_surf_arity2' % name)) p[0].surface_color = lambda a, b, c: sqrt(a**2 + b**2 + c**2) p.save(tmp_file('%s_colors_param_surf_arity3' % name)) ### # Examples from the 'advanced' notebook ### i = Integral(log((sin(x)**2 + 1) * sqrt(x**2 + 1)), (x, 0, y)) p = plot(i, (y, 1, 5)) p.save(tmp_file('%s_advanced_integral' % name)) s = summation(1 / x**y, (x, 1, oo)) p = plot(s, (y, 2, 10)) p.save(tmp_file('%s_advanced_inf_sum' % name)) p = plot(summation(1 / x, (x, 1, y)), (y, 2, 10), show=False) p[0].only_integers = True p[0].steps = True p.save(tmp_file('%s_advanced_fin_sum' % name)) ### # Test expressions that can not be translated to np and generate complex # results. ### plot(sin(x) + I * cos(x)).save(tmp_file()) plot(sqrt(sqrt(-x))).save(tmp_file()) plot(LambertW(x)).save(tmp_file()) plot(sqrt(LambertW(x))).save(tmp_file()) #Characteristic function of a StudentT distribution with nu=10 plot((meijerg( ((1 / 2, ), ()), ((5, 0, 1 / 2), ()), 5 * x**2 * exp_polar(-I * pi) / 2) + meijerg( ((1 / 2, ), ()), ((5, 0, 1 / 2), ()), 5 * x**2 * exp_polar(I * pi) / 2)) / (48 * pi), (x, 1e-6, 1e-2)).save(tmp_file())
def test_Mod1_behavior(): from sympy import Symbol, simplify, lowergamma n = Symbol('n', integer=True) # Note: this should not hang. assert simplify(hyperexpand(meijerg([1], [], [n + 1], [0], z))) == \ lowergamma(n + 1, z)
def u(an, ap, bm, bq): m = meijerg(an, ap, bm, bq, z) m2 = hyperexpand(m, allow_hyper=True) if m2.has(meijerg) and not (m2.is_Piecewise and len(m2.args) == 3): return False return tn(m, m2, z)
def test_meijerint(): from sympy import symbols, expand, arg s, t, mu = symbols('s t mu', real=True) assert integrate( meijerg([], [], [0], [], s * t) * meijerg([], [], [mu / 2], [-mu / 2], t**2 / 4), (t, 0, oo)).is_Piecewise s = symbols('s', positive=True) assert integrate(x**s*meijerg([[], []], [[0], []], x), (x, 0, oo)) == \ gamma(s + 1) assert integrate(x**s * meijerg([[], []], [[0], []], x), (x, 0, oo), meijerg=True) == gamma(s + 1) assert isinstance( integrate(x**s * meijerg([[], []], [[0], []], x), (x, 0, oo), meijerg=False), Integral) assert meijerint_indefinite(exp(x), x) == exp(x) # TODO what simplifications should be done automatically? # This tests "extra case" for antecedents_1. a, b = symbols('a b', positive=True) assert simplify(meijerint_definite(x**a, x, 0, b)[0]) == \ b**(a + 1)/(a + 1) # This tests various conditions and expansions: meijerint_definite((x + 1)**3 * exp(-x), x, 0, oo) == (16, True) # Again, how about simplifications? sigma, mu = symbols('sigma mu', positive=True) i, c = meijerint_definite(exp(-((x - mu) / (2 * sigma))**2), x, 0, oo) assert simplify(i) == sqrt(pi) * sigma * (erf(mu / (2 * sigma)) + 1) assert c == True i, _ = meijerint_definite(exp(-mu * x) * exp(sigma * x), x, 0, oo) # TODO it would be nice to test the condition assert simplify(i) == 1 / (mu - sigma) # Test substitutions to change limits assert meijerint_definite(exp(x), x, -oo, 2) == (exp(2), True) assert expand(meijerint_definite(exp(x), x, 0, I)[0]) == exp(I) - 1 assert expand(meijerint_definite(exp(-x), x, 0, x)[0]) == \ 1 - exp(-exp(I*arg(x))*abs(x)) # Test -oo to oo assert meijerint_definite(exp(-x**2), x, -oo, oo) == (sqrt(pi), True) assert meijerint_definite(exp(-abs(x)), x, -oo, oo) == (2, True) assert meijerint_definite(exp(-(2*x - 3)**2), x, -oo, oo) == \ (sqrt(pi)/2, True) assert meijerint_definite(exp(-abs(2 * x - 3)), x, -oo, oo) == (1, True) assert meijerint_definite( exp(-((x - mu) / sigma)**2 / 2) / sqrt(2 * pi * sigma**2), x, -oo, oo) == (1, True) # Test one of the extra conditions for 2 g-functinos assert meijerint_definite(exp(-x) * sin(x), x, 0, oo) == (S(1) / 2, True) # Test a bug def res(n): return (1 / (1 + x**2)).diff(x, n).subs(x, 1) * (-1)**n for n in range(6): assert integrate(exp(-x)*sin(x)*x**n, (x, 0, oo), meijerg=True) == \ res(n) # This used to test trigexpand... now it is done by linear substitution assert simplify(integrate(exp(-x) * sin(x + a), (x, 0, oo), meijerg=True)) == sqrt(2) * sin(a + pi / 4) / 2 # Test the condition 14 from prudnikov. # (This is besselj*besselj in disguise, to stop the product from being # recognised in the tables.) a, b, s = symbols('a b s') from sympy import And, re assert meijerint_definite(meijerg([], [], [a/2], [-a/2], x/4) *meijerg([], [], [b/2], [-b/2], x/4)*x**(s - 1), x, 0, oo) == \ (4*2**(2*s - 2)*gamma(-2*s + 1)*gamma(a/2 + b/2 + s) /(gamma(-a/2 + b/2 - s + 1)*gamma(a/2 - b/2 - s + 1) *gamma(a/2 + b/2 - s + 1)), And(0 < -2*re(4*s) + 8, 0 < re(a/2 + b/2 + s), re(2*s) < 1)) # test a bug assert integrate(sin(x**a)*sin(x**b), (x, 0, oo), meijerg=True) == \ Integral(sin(x**a)*sin(x**b), (x, 0, oo)) # test better hyperexpand assert integrate(exp(-x**2)*log(x), (x, 0, oo), meijerg=True) == \ (sqrt(pi)*polygamma(0, S(1)/2)/4).expand() # Test hyperexpand bug. from sympy import lowergamma n = symbols('n', integer=True) assert simplify(integrate(exp(-x)*x**n, x, meijerg=True)) == \ lowergamma(n + 1, x) # Test a bug with argument 1/x alpha = symbols('alpha', positive=True) assert meijerint_definite((2 - x)**alpha*sin(alpha/x), x, 0, 2) == \ (sqrt(pi)*alpha*gamma(alpha + 1)*meijerg(((), (alpha/2 + S(1)/2, alpha/2 + 1)), ((0, 0, S(1)/2), (-S(1)/2,)), alpha**S(2)/16)/4, True) # test a bug related to 3016 a, s = symbols('a s', positive=True) assert simplify(integrate(x**s*exp(-a*x**2), (x, -oo, oo))) == \ a**(-s/2 - S(1)/2)*((-1)**s + 1)*gamma(s/2 + S(1)/2)/2
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) 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 test_numerically test_numerically(re(fresnels(z)), fresnels(z).as_real_imag()[0], z) test_numerically(im(fresnels(z)), fresnels(z).as_real_imag()[1], z) test_numerically(fresnels(z), fresnels(z).rewrite(hyper), z) test_numerically(fresnels(z), fresnels(z).rewrite(meijerg), z) test_numerically(re(fresnelc(z)), fresnelc(z).as_real_imag()[0], z) test_numerically(im(fresnelc(z)), fresnelc(z).as_real_imag()[1], z) test_numerically(fresnelc(z), fresnelc(z).rewrite(hyper), z) test_numerically(fresnelc(z), fresnelc(z).rewrite(meijerg), z)
def test_meijerg_expand(): from sympy import gammasimp, simplify # from mpmath docs assert hyperexpand(meijerg([[], []], [[0], []], -z)) == exp(z) assert hyperexpand(meijerg([[1, 1], []], [[1], [0]], z)) == log(z + 1) assert hyperexpand(meijerg([[1, 1], []], [[1], [1]], z)) == z / (z + 1) assert hyperexpand(meijerg([[], []], [[S.Half], [0]], (z / 2)**2)) == sin(z) / sqrt(pi) assert hyperexpand(meijerg([[], []], [[0], [S.Half]], (z / 2)**2)) == cos(z) / sqrt(pi) assert can_do_meijer([], [a], [a - 1, a - S.Half], []) assert can_do_meijer([], [], [a / 2], [-a / 2], False) # branches... assert can_do_meijer([a], [b], [a], [b, a - 1]) # wikipedia assert hyperexpand(meijerg([1], [], [], [0], z)) == Piecewise( (0, abs(z) < 1), (1, abs(1 / z) < 1), (meijerg([1], [], [], [0], z), True)) assert hyperexpand(meijerg([], [1], [0], [], z)) == Piecewise( (1, abs(z) < 1), (0, abs(1 / z) < 1), (meijerg([], [1], [0], [], z), True)) # The Special Functions and their Approximations assert can_do_meijer([], [], [a + b / 2], [a, a - b / 2, a + S.Half]) assert can_do_meijer([], [], [a], [b], False) # branches only agree for small z assert can_do_meijer([], [S.Half], [a], [-a]) assert can_do_meijer([], [], [a, b], []) assert can_do_meijer([], [], [a, b], []) assert can_do_meijer([], [], [a, a + S.Half], [b, b + S.Half]) assert can_do_meijer([], [], [a, -a], [0, S.Half], False) # dito assert can_do_meijer([], [], [a, a + S.Half, b, b + S.Half], []) assert can_do_meijer([S.Half], [], [0], [a, -a]) assert can_do_meijer([S.Half], [], [a], [0, -a], False) # dito assert can_do_meijer([], [a - S.Half], [a, b], [a - S.Half], False) assert can_do_meijer([], [a + S.Half], [a + b, a - b, a], [], False) assert can_do_meijer([a + S.Half], [], [b, 2 * a - b, a], [], False) # This for example is actually zero. assert can_do_meijer([], [], [], [a, b]) # Testing a bug: assert hyperexpand(meijerg([0, 2], [], [], [-1, 1], z)) == Piecewise( (0, abs(z) < 1), (z / 2 - 1 / (2 * z), abs(1 / z) < 1), (meijerg([0, 2], [], [], [-1, 1], z), True), ) # Test that the simplest possible answer is returned: assert (gammasimp( simplify( hyperexpand( meijerg([1], [1 - a], [-a / 2, -a / 2 + S.Half], [], 1 / z)))) == -2 * sqrt(pi) * (sqrt(z + 1) + 1)**a / a) # Test that hyper is returned assert (hyperexpand(meijerg([1], [], [a], [0, 0], z)) == hyper( (a, ), (a + 1, a + 1), z * exp_polar(I * pi)) * z**a * gamma(a) / gamma(a + 1)**2) # Test place option f = meijerg(((0, 1), ()), ((S.Half, ), (0, )), z**2) assert hyperexpand(f) == sqrt(pi) / sqrt(1 + z**(-2)) assert hyperexpand(f, place=0) == sqrt(pi) * z / sqrt(z**2 + 1)
def test_meijer(): raises(TypeError, 'meijerg(1, z)') raises(TypeError, 'meijerg(((1,), (2,)), (3,), (4,), z)') assert meijerg(((1, 2), (3,)), ((4,), (5,)), z) == \ meijerg(Tuple(1, 2), Tuple(3), Tuple(4), Tuple(5), z) g = meijerg((1, 2), (3, 4, 5), (6, 7, 8, 9), (10, 11, 12, 13, 14), z) assert g.an == Tuple(1, 2) assert g.ap == Tuple(1, 2, 3, 4, 5) assert g.aother == Tuple(3, 4, 5) assert g.bm == Tuple(6, 7, 8, 9) assert g.bq == Tuple(6, 7, 8, 9, 10, 11, 12, 13, 14) assert g.bother == Tuple(10, 11, 12, 13, 14) assert g.argument == z assert g.nu == 75 assert g.delta == -1 assert meijerg([1, 2], [3], [4], [5], z).delta == S(1) / 2 # just a few checks to make sure that all arguments go where they should assert tn(meijerg(Tuple(), Tuple(), Tuple(0), Tuple(), -z), exp(z), z) assert tn( sqrt(pi) * meijerg(Tuple(), Tuple(), Tuple(0), Tuple(S(1) / 2), z**2 / 4), cos(z), z) assert tn(meijerg(Tuple(1, 1), Tuple(), Tuple(1), Tuple(0), z), log(1 + z), z) # differentiation g = meijerg((randcplx(), ), (randcplx() + 2 * I, ), Tuple(), (randcplx(), randcplx()), z) assert td(g, z) g = meijerg(Tuple(), (randcplx(), ), Tuple(), (randcplx(), randcplx()), z) assert td(g, z) g = meijerg(Tuple(), Tuple(), Tuple(randcplx()), Tuple(randcplx(), randcplx()), z) assert td(g, z) a1, a2, b1, b2, c1, c2, d1, d2 = symbols('a1:3, b1:3, c1:3, d1:3') assert meijerg((a1, a2), (b1, b2), (c1, c2), (d1, d2), z).diff(z) == \ (meijerg((a1-1, a2), (b1, b2), (c1, c2), (d1, d2), z) \ + (a1 - 1)*meijerg((a1, a2), (b1, b2), (c1, c2), (d1, d2), z))/z raises(NotImplementedError, 'meijerg((z,), (), (), (), z).diff(z)')
def test_issue587(): # remove this when fresnel itegrals are implemented from sympy import meijerg assert integrate(sin(x**2), x) == \ sqrt(2*pi)*meijerg([1], [], [S(3)/4], [S(1)/4, 0], x**4/4)/4
def test_atom_bug(): from sympy import meijerg from sympy.integrals.heurisch import heurisch assert heurisch(meijerg([], [], [1], [], x), x) is None
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) # issues 6510, 10102 fs = (S.Half - sin(pi * z**2 / 2) / (pi**2 * z**3) + (-1 / (pi * z) + 3 / (pi**3 * z**5)) * cos(pi * z**2 / 2)) fc = (S.Half - cos(pi * z**2 / 2) / (pi**2 * z**3) + (1 / (pi * z) - 3 / (pi**3 * z**5)) * sin(pi * z**2 / 2)) assert fresnels(z).series(z, oo) == fs + O(z**(-6), (z, oo)) assert fresnelc(z).series(z, oo) == fc + O(z**(-6), (z, oo)) assert (fresnels(z).series(z, -oo) + fs.subs(z, -z)).expand().is_Order assert (fresnelc(z).series(z, -oo) + fc.subs(z, -z)).expand().is_Order assert (fresnels(1 / z).series(z) - fs.subs(z, 1 / z)).expand().is_Order assert (fresnelc(1 / z).series(z) - fc.subs(z, 1 / z)).expand().is_Order assert ((2 * fresnels(3 * z)).series(z, oo) - 2 * fs.subs(z, 3 * z)).expand().is_Order assert ((3 * fresnelc(2 * z)).series(z, oo) - 3 * fc.subs(z, 2 * z)).expand().is_Order 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)