applied-ai-018 commited on
Commit
660f2ea
·
verified ·
1 Parent(s): 6b0b284

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/__init__.py +0 -0
  2. env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_bessel.py +759 -0
  3. env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_bsplines.py +167 -0
  4. env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_delta_functions.py +165 -0
  5. env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_error_functions.py +816 -0
  6. env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_gamma_functions.py +741 -0
  7. env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_hyper.py +387 -0
  8. env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_mathieu.py +29 -0
  9. env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_singularity_functions.py +115 -0
  10. env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_spec_polynomials.py +475 -0
  11. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/__init__.cpython-310.pyc +0 -0
  12. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/anticommutator.cpython-310.pyc +0 -0
  13. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/boson.cpython-310.pyc +0 -0
  14. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/cartesian.cpython-310.pyc +0 -0
  15. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/cg.cpython-310.pyc +0 -0
  16. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/circuitplot.cpython-310.pyc +0 -0
  17. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/circuitutils.cpython-310.pyc +0 -0
  18. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/dagger.cpython-310.pyc +0 -0
  19. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/density.cpython-310.pyc +0 -0
  20. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/fermion.cpython-310.pyc +0 -0
  21. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/grover.cpython-310.pyc +0 -0
  22. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/hilbert.cpython-310.pyc +0 -0
  23. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/innerproduct.cpython-310.pyc +0 -0
  24. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/matrixutils.cpython-310.pyc +0 -0
  25. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/operator.cpython-310.pyc +0 -0
  26. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/qasm.cpython-310.pyc +0 -0
  27. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/qexpr.cpython-310.pyc +0 -0
  28. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/qft.cpython-310.pyc +0 -0
  29. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/represent.cpython-310.pyc +0 -0
  30. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/tensorproduct.cpython-310.pyc +0 -0
  31. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__init__.py +0 -0
  32. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_anticommutator.cpython-310.pyc +0 -0
  33. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_cartesian.cpython-310.pyc +0 -0
  34. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_cg.cpython-310.pyc +0 -0
  35. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_circuitplot.cpython-310.pyc +0 -0
  36. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_circuitutils.cpython-310.pyc +0 -0
  37. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_commutator.cpython-310.pyc +0 -0
  38. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_constants.cpython-310.pyc +0 -0
  39. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_density.cpython-310.pyc +0 -0
  40. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_gate.cpython-310.pyc +0 -0
  41. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_grover.cpython-310.pyc +0 -0
  42. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_hilbert.cpython-310.pyc +0 -0
  43. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_identitysearch.cpython-310.pyc +0 -0
  44. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_innerproduct.cpython-310.pyc +0 -0
  45. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_operatorset.cpython-310.pyc +0 -0
  46. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_pauli.cpython-310.pyc +0 -0
  47. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_piab.cpython-310.pyc +0 -0
  48. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_qapply.cpython-310.pyc +0 -0
  49. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_qexpr.cpython-310.pyc +0 -0
  50. env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_qubit.cpython-310.pyc +0 -0
env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/__init__.py ADDED
File without changes
env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_bessel.py ADDED
@@ -0,0 +1,759 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from itertools import product
2
+
3
+ from sympy.concrete.summations import Sum
4
+ from sympy.core.function import (diff, expand_func)
5
+ from sympy.core.numbers import (I, Rational, oo, pi)
6
+ from sympy.core.singleton import S
7
+ from sympy.core.symbol import (Symbol, symbols)
8
+ from sympy.functions.elementary.complexes import (conjugate, polar_lift)
9
+ from sympy.functions.elementary.exponential import (exp, exp_polar, log)
10
+ from sympy.functions.elementary.hyperbolic import (cosh, sinh)
11
+ from sympy.functions.elementary.miscellaneous import sqrt
12
+ from sympy.functions.elementary.trigonometric import (cos, sin)
13
+ from sympy.functions.special.bessel import (besseli, besselj, besselk, bessely, hankel1, hankel2, hn1, hn2, jn, jn_zeros, yn)
14
+ from sympy.functions.special.gamma_functions import (gamma, uppergamma)
15
+ from sympy.functions.special.hyper import hyper
16
+ from sympy.integrals.integrals import Integral
17
+ from sympy.series.order import O
18
+ from sympy.series.series import series
19
+ from sympy.functions.special.bessel import (airyai, airybi,
20
+ airyaiprime, airybiprime, marcumq)
21
+ from sympy.core.random import (random_complex_number as randcplx,
22
+ verify_numerically as tn,
23
+ test_derivative_numerically as td,
24
+ _randint)
25
+ from sympy.simplify import besselsimp
26
+ from sympy.testing.pytest import raises, slow
27
+
28
+ from sympy.abc import z, n, k, x
29
+
30
+ randint = _randint()
31
+
32
+
33
+ def test_bessel_rand():
34
+ for f in [besselj, bessely, besseli, besselk, hankel1, hankel2]:
35
+ assert td(f(randcplx(), z), z)
36
+
37
+ for f in [jn, yn, hn1, hn2]:
38
+ assert td(f(randint(-10, 10), z), z)
39
+
40
+
41
+ def test_bessel_twoinputs():
42
+ for f in [besselj, bessely, besseli, besselk, hankel1, hankel2, jn, yn]:
43
+ raises(TypeError, lambda: f(1))
44
+ raises(TypeError, lambda: f(1, 2, 3))
45
+
46
+
47
+ def test_besselj_leading_term():
48
+ assert besselj(0, x).as_leading_term(x) == 1
49
+ assert besselj(1, sin(x)).as_leading_term(x) == x/2
50
+ assert besselj(1, 2*sqrt(x)).as_leading_term(x) == sqrt(x)
51
+
52
+ # https://github.com/sympy/sympy/issues/21701
53
+ assert (besselj(z, x)/x**z).as_leading_term(x) == 1/(2**z*gamma(z + 1))
54
+
55
+
56
+ def test_bessely_leading_term():
57
+ assert bessely(0, x).as_leading_term(x) == (2*log(x) - 2*log(2) + 2*S.EulerGamma)/pi
58
+ assert bessely(1, sin(x)).as_leading_term(x) == -2/(pi*x)
59
+ assert bessely(1, 2*sqrt(x)).as_leading_term(x) == -1/(pi*sqrt(x))
60
+
61
+
62
+ def test_besseli_leading_term():
63
+ assert besseli(0, x).as_leading_term(x) == 1
64
+ assert besseli(1, sin(x)).as_leading_term(x) == x/2
65
+ assert besseli(1, 2*sqrt(x)).as_leading_term(x) == sqrt(x)
66
+
67
+
68
+ def test_besselk_leading_term():
69
+ assert besselk(0, x).as_leading_term(x) == -log(x) - S.EulerGamma + log(2)
70
+ assert besselk(1, sin(x)).as_leading_term(x) == 1/x
71
+ assert besselk(1, 2*sqrt(x)).as_leading_term(x) == 1/(2*sqrt(x))
72
+
73
+
74
+ def test_besselj_series():
75
+ assert besselj(0, x).series(x) == 1 - x**2/4 + x**4/64 + O(x**6)
76
+ assert besselj(0, x**(1.1)).series(x) == 1 + x**4.4/64 - x**2.2/4 + O(x**6)
77
+ assert besselj(0, x**2 + x).series(x) == 1 - x**2/4 - x**3/2\
78
+ - 15*x**4/64 + x**5/16 + O(x**6)
79
+ assert besselj(0, sqrt(x) + x).series(x, n=4) == 1 - x/4 - 15*x**2/64\
80
+ + 215*x**3/2304 - x**Rational(3, 2)/2 + x**Rational(5, 2)/16\
81
+ + 23*x**Rational(7, 2)/384 + O(x**4)
82
+ assert besselj(0, x/(1 - x)).series(x) == 1 - x**2/4 - x**3/2 - 47*x**4/64\
83
+ - 15*x**5/16 + O(x**6)
84
+ assert besselj(0, log(1 + x)).series(x) == 1 - x**2/4 + x**3/4\
85
+ - 41*x**4/192 + 17*x**5/96 + O(x**6)
86
+ assert besselj(1, sin(x)).series(x) == x/2 - 7*x**3/48 + 73*x**5/1920 + O(x**6)
87
+ assert besselj(1, 2*sqrt(x)).series(x) == sqrt(x) - x**Rational(3, 2)/2\
88
+ + x**Rational(5, 2)/12 - x**Rational(7, 2)/144 + x**Rational(9, 2)/2880\
89
+ - x**Rational(11, 2)/86400 + O(x**6)
90
+ assert besselj(-2, sin(x)).series(x, n=4) == besselj(2, sin(x)).series(x, n=4)
91
+
92
+
93
+ def test_bessely_series():
94
+ const = 2*S.EulerGamma/pi - 2*log(2)/pi + 2*log(x)/pi
95
+ assert bessely(0, x).series(x, n=4) == const + x**2*(-log(x)/(2*pi)\
96
+ + (2 - 2*S.EulerGamma)/(4*pi) + log(2)/(2*pi)) + O(x**4*log(x))
97
+ assert bessely(1, x).series(x, n=4) == -2/(pi*x) + x*(log(x)/pi - log(2)/pi - \
98
+ (1 - 2*S.EulerGamma)/(2*pi)) + x**3*(-log(x)/(8*pi) + \
99
+ (S(5)/2 - 2*S.EulerGamma)/(16*pi) + log(2)/(8*pi)) + O(x**4*log(x))
100
+ assert bessely(2, x).series(x, n=4) == -4/(pi*x**2) - 1/pi + x**2*(log(x)/(4*pi) - \
101
+ log(2)/(4*pi) - (S(3)/2 - 2*S.EulerGamma)/(8*pi)) + O(x**4*log(x))
102
+ assert bessely(3, x).series(x, n=4) == -16/(pi*x**3) - 2/(pi*x) - \
103
+ x/(4*pi) + x**3*(log(x)/(24*pi) - log(2)/(24*pi) - \
104
+ (S(11)/6 - 2*S.EulerGamma)/(48*pi)) + O(x**4*log(x))
105
+ assert bessely(0, x**(1.1)).series(x, n=4) == 2*S.EulerGamma/pi\
106
+ - 2*log(2)/pi + 2.2*log(x)/pi + x**2.2*(-0.55*log(x)/pi\
107
+ + (2 - 2*S.EulerGamma)/(4*pi) + log(2)/(2*pi)) + O(x**4*log(x))
108
+ assert bessely(0, x**2 + x).series(x, n=4) == \
109
+ const - (2 - 2*S.EulerGamma)*(-x**3/(2*pi) - x**2/(4*pi)) + 2*x/pi\
110
+ + x**2*(-log(x)/(2*pi) - 1/pi + log(2)/(2*pi))\
111
+ + x**3*(-log(x)/pi + 1/(6*pi) + log(2)/pi) + O(x**4*log(x))
112
+ assert bessely(0, x/(1 - x)).series(x, n=3) == const\
113
+ + 2*x/pi + x**2*(-log(x)/(2*pi) + (2 - 2*S.EulerGamma)/(4*pi)\
114
+ + log(2)/(2*pi) + 1/pi) + O(x**3*log(x))
115
+ assert bessely(0, log(1 + x)).series(x, n=3) == const\
116
+ - x/pi + x**2*(-log(x)/(2*pi) + (2 - 2*S.EulerGamma)/(4*pi)\
117
+ + log(2)/(2*pi) + 5/(12*pi)) + O(x**3*log(x))
118
+ assert bessely(1, sin(x)).series(x, n=4) == -1/(pi*(-x**3/12 + x/2)) - \
119
+ (1 - 2*S.EulerGamma)*(-x**3/12 + x/2)/pi + x*(log(x)/pi - log(2)/pi) + \
120
+ x**3*(-7*log(x)/(24*pi) - 1/(6*pi) + (S(5)/2 - 2*S.EulerGamma)/(16*pi) +
121
+ 7*log(2)/(24*pi)) + O(x**4*log(x))
122
+ assert bessely(1, 2*sqrt(x)).series(x, n=3) == -1/(pi*sqrt(x)) + \
123
+ sqrt(x)*(log(x)/pi - (1 - 2*S.EulerGamma)/pi) + x**(S(3)/2)*(-log(x)/(2*pi) + \
124
+ (S(5)/2 - 2*S.EulerGamma)/(2*pi)) + x**(S(5)/2)*(log(x)/(12*pi) - \
125
+ (S(10)/3 - 2*S.EulerGamma)/(12*pi)) + O(x**3*log(x))
126
+ assert bessely(-2, sin(x)).series(x, n=4) == bessely(2, sin(x)).series(x, n=4)
127
+
128
+
129
+ def test_besseli_series():
130
+ assert besseli(0, x).series(x) == 1 + x**2/4 + x**4/64 + O(x**6)
131
+ assert besseli(0, x**(1.1)).series(x) == 1 + x**4.4/64 + x**2.2/4 + O(x**6)
132
+ assert besseli(0, x**2 + x).series(x) == 1 + x**2/4 + x**3/2 + 17*x**4/64 + \
133
+ x**5/16 + O(x**6)
134
+ assert besseli(0, sqrt(x) + x).series(x, n=4) == 1 + x/4 + 17*x**2/64 + \
135
+ 217*x**3/2304 + x**(S(3)/2)/2 + x**(S(5)/2)/16 + 25*x**(S(7)/2)/384 + O(x**4)
136
+ assert besseli(0, x/(1 - x)).series(x) == 1 + x**2/4 + x**3/2 + 49*x**4/64 + \
137
+ 17*x**5/16 + O(x**6)
138
+ assert besseli(0, log(1 + x)).series(x) == 1 + x**2/4 - x**3/4 + 47*x**4/192 - \
139
+ 23*x**5/96 + O(x**6)
140
+ assert besseli(1, sin(x)).series(x) == x/2 - x**3/48 - 47*x**5/1920 + O(x**6)
141
+ assert besseli(1, 2*sqrt(x)).series(x) == sqrt(x) + x**(S(3)/2)/2 + x**(S(5)/2)/12 + \
142
+ x**(S(7)/2)/144 + x**(S(9)/2)/2880 + x**(S(11)/2)/86400 + O(x**6)
143
+ assert besseli(-2, sin(x)).series(x, n=4) == besseli(2, sin(x)).series(x, n=4)
144
+
145
+
146
+ def test_besselk_series():
147
+ const = log(2) - S.EulerGamma - log(x)
148
+ assert besselk(0, x).series(x, n=4) == const + \
149
+ x**2*(-log(x)/4 - S.EulerGamma/4 + log(2)/4 + S(1)/4) + O(x**4*log(x))
150
+ assert besselk(1, x).series(x, n=4) == 1/x + x*(log(x)/2 - log(2)/2 - \
151
+ S(1)/4 + S.EulerGamma/2) + x**3*(log(x)/16 - S(5)/64 - log(2)/16 + \
152
+ S.EulerGamma/16) + O(x**4*log(x))
153
+ assert besselk(2, x).series(x, n=4) == 2/x**2 - S(1)/2 + x**2*(-log(x)/8 - \
154
+ S.EulerGamma/8 + log(2)/8 + S(3)/32) + O(x**4*log(x))
155
+ assert besselk(0, x**(1.1)).series(x, n=4) == log(2) - S.EulerGamma - \
156
+ 1.1*log(x) + x**2.2*(-0.275*log(x) - S.EulerGamma/4 + \
157
+ log(2)/4 + S(1)/4) + O(x**4*log(x))
158
+ assert besselk(0, x**2 + x).series(x, n=4) == const + \
159
+ (2 - 2*S.EulerGamma)*(x**3/4 + x**2/8) - x + x**2*(-log(x)/4 + \
160
+ log(2)/4 + S(1)/2) + x**3*(-log(x)/2 - S(7)/12 + log(2)/2) + O(x**4*log(x))
161
+ assert besselk(0, x/(1 - x)).series(x, n=3) == const - x + x**2*(-log(x)/4 - \
162
+ S(1)/4 - S.EulerGamma/4 + log(2)/4) + O(x**3*log(x))
163
+ assert besselk(0, log(1 + x)).series(x, n=3) == const + x/2 + \
164
+ x**2*(-log(x)/4 - S.EulerGamma/4 + S(1)/24 + log(2)/4) + O(x**3*log(x))
165
+ assert besselk(1, 2*sqrt(x)).series(x, n=3) == 1/(2*sqrt(x)) + \
166
+ sqrt(x)*(log(x)/2 - S(1)/2 + S.EulerGamma) + x**(S(3)/2)*(log(x)/4 - S(5)/8 + \
167
+ S.EulerGamma/2) + x**(S(5)/2)*(log(x)/24 - S(5)/36 + S.EulerGamma/12) + O(x**3*log(x))
168
+ assert besselk(-2, sin(x)).series(x, n=4) == besselk(2, sin(x)).series(x, n=4)
169
+
170
+
171
+ def test_diff():
172
+ assert besselj(n, z).diff(z) == besselj(n - 1, z)/2 - besselj(n + 1, z)/2
173
+ assert bessely(n, z).diff(z) == bessely(n - 1, z)/2 - bessely(n + 1, z)/2
174
+ assert besseli(n, z).diff(z) == besseli(n - 1, z)/2 + besseli(n + 1, z)/2
175
+ assert besselk(n, z).diff(z) == -besselk(n - 1, z)/2 - besselk(n + 1, z)/2
176
+ assert hankel1(n, z).diff(z) == hankel1(n - 1, z)/2 - hankel1(n + 1, z)/2
177
+ assert hankel2(n, z).diff(z) == hankel2(n - 1, z)/2 - hankel2(n + 1, z)/2
178
+
179
+
180
+ def test_rewrite():
181
+ assert besselj(n, z).rewrite(jn) == sqrt(2*z/pi)*jn(n - S.Half, z)
182
+ assert bessely(n, z).rewrite(yn) == sqrt(2*z/pi)*yn(n - S.Half, z)
183
+ assert besseli(n, z).rewrite(besselj) == \
184
+ exp(-I*n*pi/2)*besselj(n, polar_lift(I)*z)
185
+ assert besselj(n, z).rewrite(besseli) == \
186
+ exp(I*n*pi/2)*besseli(n, polar_lift(-I)*z)
187
+
188
+ nu = randcplx()
189
+
190
+ assert tn(besselj(nu, z), besselj(nu, z).rewrite(besseli), z)
191
+ assert tn(besselj(nu, z), besselj(nu, z).rewrite(bessely), z)
192
+
193
+ assert tn(besseli(nu, z), besseli(nu, z).rewrite(besselj), z)
194
+ assert tn(besseli(nu, z), besseli(nu, z).rewrite(bessely), z)
195
+
196
+ assert tn(bessely(nu, z), bessely(nu, z).rewrite(besselj), z)
197
+ assert tn(bessely(nu, z), bessely(nu, z).rewrite(besseli), z)
198
+
199
+ assert tn(besselk(nu, z), besselk(nu, z).rewrite(besselj), z)
200
+ assert tn(besselk(nu, z), besselk(nu, z).rewrite(besseli), z)
201
+ assert tn(besselk(nu, z), besselk(nu, z).rewrite(bessely), z)
202
+
203
+ # check that a rewrite was triggered, when the order is set to a generic
204
+ # symbol 'nu'
205
+ assert yn(nu, z) != yn(nu, z).rewrite(jn)
206
+ assert hn1(nu, z) != hn1(nu, z).rewrite(jn)
207
+ assert hn2(nu, z) != hn2(nu, z).rewrite(jn)
208
+ assert jn(nu, z) != jn(nu, z).rewrite(yn)
209
+ assert hn1(nu, z) != hn1(nu, z).rewrite(yn)
210
+ assert hn2(nu, z) != hn2(nu, z).rewrite(yn)
211
+
212
+ # rewriting spherical bessel functions (SBFs) w.r.t. besselj, bessely is
213
+ # not allowed if a generic symbol 'nu' is used as the order of the SBFs
214
+ # to avoid inconsistencies (the order of bessel[jy] is allowed to be
215
+ # complex-valued, whereas SBFs are defined only for integer orders)
216
+ order = nu
217
+ for f in (besselj, bessely):
218
+ assert hn1(order, z) == hn1(order, z).rewrite(f)
219
+ assert hn2(order, z) == hn2(order, z).rewrite(f)
220
+
221
+ assert jn(order, z).rewrite(besselj) == sqrt(2)*sqrt(pi)*sqrt(1/z)*besselj(order + S.Half, z)/2
222
+ assert jn(order, z).rewrite(bessely) == (-1)**nu*sqrt(2)*sqrt(pi)*sqrt(1/z)*bessely(-order - S.Half, z)/2
223
+
224
+ # for integral orders rewriting SBFs w.r.t bessel[jy] is allowed
225
+ N = Symbol('n', integer=True)
226
+ ri = randint(-11, 10)
227
+ for order in (ri, N):
228
+ for f in (besselj, bessely):
229
+ assert yn(order, z) != yn(order, z).rewrite(f)
230
+ assert jn(order, z) != jn(order, z).rewrite(f)
231
+ assert hn1(order, z) != hn1(order, z).rewrite(f)
232
+ assert hn2(order, z) != hn2(order, z).rewrite(f)
233
+
234
+ for func, refunc in product((yn, jn, hn1, hn2),
235
+ (jn, yn, besselj, bessely)):
236
+ assert tn(func(ri, z), func(ri, z).rewrite(refunc), z)
237
+
238
+
239
+ def test_expand():
240
+ assert expand_func(besselj(S.Half, z).rewrite(jn)) == \
241
+ sqrt(2)*sin(z)/(sqrt(pi)*sqrt(z))
242
+ assert expand_func(bessely(S.Half, z).rewrite(yn)) == \
243
+ -sqrt(2)*cos(z)/(sqrt(pi)*sqrt(z))
244
+
245
+ # XXX: teach sin/cos to work around arguments like
246
+ # x*exp_polar(I*pi*n/2). Then change besselsimp -> expand_func
247
+ assert besselsimp(besselj(S.Half, z)) == sqrt(2)*sin(z)/(sqrt(pi)*sqrt(z))
248
+ assert besselsimp(besselj(Rational(-1, 2), z)) == sqrt(2)*cos(z)/(sqrt(pi)*sqrt(z))
249
+ assert besselsimp(besselj(Rational(5, 2), z)) == \
250
+ -sqrt(2)*(z**2*sin(z) + 3*z*cos(z) - 3*sin(z))/(sqrt(pi)*z**Rational(5, 2))
251
+ assert besselsimp(besselj(Rational(-5, 2), z)) == \
252
+ -sqrt(2)*(z**2*cos(z) - 3*z*sin(z) - 3*cos(z))/(sqrt(pi)*z**Rational(5, 2))
253
+
254
+ assert besselsimp(bessely(S.Half, z)) == \
255
+ -(sqrt(2)*cos(z))/(sqrt(pi)*sqrt(z))
256
+ assert besselsimp(bessely(Rational(-1, 2), z)) == sqrt(2)*sin(z)/(sqrt(pi)*sqrt(z))
257
+ assert besselsimp(bessely(Rational(5, 2), z)) == \
258
+ sqrt(2)*(z**2*cos(z) - 3*z*sin(z) - 3*cos(z))/(sqrt(pi)*z**Rational(5, 2))
259
+ assert besselsimp(bessely(Rational(-5, 2), z)) == \
260
+ -sqrt(2)*(z**2*sin(z) + 3*z*cos(z) - 3*sin(z))/(sqrt(pi)*z**Rational(5, 2))
261
+
262
+ assert besselsimp(besseli(S.Half, z)) == sqrt(2)*sinh(z)/(sqrt(pi)*sqrt(z))
263
+ assert besselsimp(besseli(Rational(-1, 2), z)) == \
264
+ sqrt(2)*cosh(z)/(sqrt(pi)*sqrt(z))
265
+ assert besselsimp(besseli(Rational(5, 2), z)) == \
266
+ sqrt(2)*(z**2*sinh(z) - 3*z*cosh(z) + 3*sinh(z))/(sqrt(pi)*z**Rational(5, 2))
267
+ assert besselsimp(besseli(Rational(-5, 2), z)) == \
268
+ sqrt(2)*(z**2*cosh(z) - 3*z*sinh(z) + 3*cosh(z))/(sqrt(pi)*z**Rational(5, 2))
269
+
270
+ assert besselsimp(besselk(S.Half, z)) == \
271
+ besselsimp(besselk(Rational(-1, 2), z)) == sqrt(pi)*exp(-z)/(sqrt(2)*sqrt(z))
272
+ assert besselsimp(besselk(Rational(5, 2), z)) == \
273
+ besselsimp(besselk(Rational(-5, 2), z)) == \
274
+ sqrt(2)*sqrt(pi)*(z**2 + 3*z + 3)*exp(-z)/(2*z**Rational(5, 2))
275
+
276
+ n = Symbol('n', integer=True, positive=True)
277
+
278
+ assert expand_func(besseli(n + 2, z)) == \
279
+ besseli(n, z) + (-2*n - 2)*(-2*n*besseli(n, z)/z + besseli(n - 1, z))/z
280
+ assert expand_func(besselj(n + 2, z)) == \
281
+ -besselj(n, z) + (2*n + 2)*(2*n*besselj(n, z)/z - besselj(n - 1, z))/z
282
+ assert expand_func(besselk(n + 2, z)) == \
283
+ besselk(n, z) + (2*n + 2)*(2*n*besselk(n, z)/z + besselk(n - 1, z))/z
284
+ assert expand_func(bessely(n + 2, z)) == \
285
+ -bessely(n, z) + (2*n + 2)*(2*n*bessely(n, z)/z - bessely(n - 1, z))/z
286
+
287
+ assert expand_func(besseli(n + S.Half, z).rewrite(jn)) == \
288
+ (sqrt(2)*sqrt(z)*exp(-I*pi*(n + S.Half)/2) *
289
+ exp_polar(I*pi/4)*jn(n, z*exp_polar(I*pi/2))/sqrt(pi))
290
+ assert expand_func(besselj(n + S.Half, z).rewrite(jn)) == \
291
+ sqrt(2)*sqrt(z)*jn(n, z)/sqrt(pi)
292
+
293
+ r = Symbol('r', real=True)
294
+ p = Symbol('p', positive=True)
295
+ i = Symbol('i', integer=True)
296
+
297
+ for besselx in [besselj, bessely, besseli, besselk]:
298
+ assert besselx(i, p).is_extended_real is True
299
+ assert besselx(i, x).is_extended_real is None
300
+ assert besselx(x, z).is_extended_real is None
301
+
302
+ for besselx in [besselj, besseli]:
303
+ assert besselx(i, r).is_extended_real is True
304
+ for besselx in [bessely, besselk]:
305
+ assert besselx(i, r).is_extended_real is None
306
+
307
+ for besselx in [besselj, bessely, besseli, besselk]:
308
+ assert expand_func(besselx(oo, x)) == besselx(oo, x, evaluate=False)
309
+ assert expand_func(besselx(-oo, x)) == besselx(-oo, x, evaluate=False)
310
+
311
+
312
+ # Quite varying time, but often really slow
313
+ @slow
314
+ def test_slow_expand():
315
+ def check(eq, ans):
316
+ return tn(eq, ans) and eq == ans
317
+
318
+ rn = randcplx(a=1, b=0, d=0, c=2)
319
+
320
+ for besselx in [besselj, bessely, besseli, besselk]:
321
+ ri = S(2*randint(-11, 10) + 1) / 2 # half integer in [-21/2, 21/2]
322
+ assert tn(besselsimp(besselx(ri, z)), besselx(ri, z))
323
+
324
+ assert check(expand_func(besseli(rn, x)),
325
+ besseli(rn - 2, x) - 2*(rn - 1)*besseli(rn - 1, x)/x)
326
+ assert check(expand_func(besseli(-rn, x)),
327
+ besseli(-rn + 2, x) + 2*(-rn + 1)*besseli(-rn + 1, x)/x)
328
+
329
+ assert check(expand_func(besselj(rn, x)),
330
+ -besselj(rn - 2, x) + 2*(rn - 1)*besselj(rn - 1, x)/x)
331
+ assert check(expand_func(besselj(-rn, x)),
332
+ -besselj(-rn + 2, x) + 2*(-rn + 1)*besselj(-rn + 1, x)/x)
333
+
334
+ assert check(expand_func(besselk(rn, x)),
335
+ besselk(rn - 2, x) + 2*(rn - 1)*besselk(rn - 1, x)/x)
336
+ assert check(expand_func(besselk(-rn, x)),
337
+ besselk(-rn + 2, x) - 2*(-rn + 1)*besselk(-rn + 1, x)/x)
338
+
339
+ assert check(expand_func(bessely(rn, x)),
340
+ -bessely(rn - 2, x) + 2*(rn - 1)*bessely(rn - 1, x)/x)
341
+ assert check(expand_func(bessely(-rn, x)),
342
+ -bessely(-rn + 2, x) + 2*(-rn + 1)*bessely(-rn + 1, x)/x)
343
+
344
+
345
+ def mjn(n, z):
346
+ return expand_func(jn(n, z))
347
+
348
+
349
+ def myn(n, z):
350
+ return expand_func(yn(n, z))
351
+
352
+
353
+ def test_jn():
354
+ z = symbols("z")
355
+ assert jn(0, 0) == 1
356
+ assert jn(1, 0) == 0
357
+ assert jn(-1, 0) == S.ComplexInfinity
358
+ assert jn(z, 0) == jn(z, 0, evaluate=False)
359
+ assert jn(0, oo) == 0
360
+ assert jn(0, -oo) == 0
361
+
362
+ assert mjn(0, z) == sin(z)/z
363
+ assert mjn(1, z) == sin(z)/z**2 - cos(z)/z
364
+ assert mjn(2, z) == (3/z**3 - 1/z)*sin(z) - (3/z**2) * cos(z)
365
+ assert mjn(3, z) == (15/z**4 - 6/z**2)*sin(z) + (1/z - 15/z**3)*cos(z)
366
+ assert mjn(4, z) == (1/z + 105/z**5 - 45/z**3)*sin(z) + \
367
+ (-105/z**4 + 10/z**2)*cos(z)
368
+ assert mjn(5, z) == (945/z**6 - 420/z**4 + 15/z**2)*sin(z) + \
369
+ (-1/z - 945/z**5 + 105/z**3)*cos(z)
370
+ assert mjn(6, z) == (-1/z + 10395/z**7 - 4725/z**5 + 210/z**3)*sin(z) + \
371
+ (-10395/z**6 + 1260/z**4 - 21/z**2)*cos(z)
372
+
373
+ assert expand_func(jn(n, z)) == jn(n, z)
374
+
375
+ # SBFs not defined for complex-valued orders
376
+ assert jn(2+3j, 5.2+0.3j).evalf() == jn(2+3j, 5.2+0.3j)
377
+
378
+ assert eq([jn(2, 5.2+0.3j).evalf(10)],
379
+ [0.09941975672 - 0.05452508024*I])
380
+
381
+
382
+ def test_yn():
383
+ z = symbols("z")
384
+ assert myn(0, z) == -cos(z)/z
385
+ assert myn(1, z) == -cos(z)/z**2 - sin(z)/z
386
+ assert myn(2, z) == -((3/z**3 - 1/z)*cos(z) + (3/z**2)*sin(z))
387
+ assert expand_func(yn(n, z)) == yn(n, z)
388
+
389
+ # SBFs not defined for complex-valued orders
390
+ assert yn(2+3j, 5.2+0.3j).evalf() == yn(2+3j, 5.2+0.3j)
391
+
392
+ assert eq([yn(2, 5.2+0.3j).evalf(10)],
393
+ [0.185250342 + 0.01489557397*I])
394
+
395
+
396
+ def test_sympify_yn():
397
+ assert S(15) in myn(3, pi).atoms()
398
+ assert myn(3, pi) == 15/pi**4 - 6/pi**2
399
+
400
+
401
+ def eq(a, b, tol=1e-6):
402
+ for u, v in zip(a, b):
403
+ if not (abs(u - v) < tol):
404
+ return False
405
+ return True
406
+
407
+
408
+ def test_jn_zeros():
409
+ assert eq(jn_zeros(0, 4), [3.141592, 6.283185, 9.424777, 12.566370])
410
+ assert eq(jn_zeros(1, 4), [4.493409, 7.725251, 10.904121, 14.066193])
411
+ assert eq(jn_zeros(2, 4), [5.763459, 9.095011, 12.322940, 15.514603])
412
+ assert eq(jn_zeros(3, 4), [6.987932, 10.417118, 13.698023, 16.923621])
413
+ assert eq(jn_zeros(4, 4), [8.182561, 11.704907, 15.039664, 18.301255])
414
+
415
+
416
+ def test_bessel_eval():
417
+ n, m, k = Symbol('n', integer=True), Symbol('m'), Symbol('k', integer=True, zero=False)
418
+
419
+ for f in [besselj, besseli]:
420
+ assert f(0, 0) is S.One
421
+ assert f(2.1, 0) is S.Zero
422
+ assert f(-3, 0) is S.Zero
423
+ assert f(-10.2, 0) is S.ComplexInfinity
424
+ assert f(1 + 3*I, 0) is S.Zero
425
+ assert f(-3 + I, 0) is S.ComplexInfinity
426
+ assert f(-2*I, 0) is S.NaN
427
+ assert f(n, 0) != S.One and f(n, 0) != S.Zero
428
+ assert f(m, 0) != S.One and f(m, 0) != S.Zero
429
+ assert f(k, 0) is S.Zero
430
+
431
+ assert bessely(0, 0) is S.NegativeInfinity
432
+ assert besselk(0, 0) is S.Infinity
433
+ for f in [bessely, besselk]:
434
+ assert f(1 + I, 0) is S.ComplexInfinity
435
+ assert f(I, 0) is S.NaN
436
+
437
+ for f in [besselj, bessely]:
438
+ assert f(m, S.Infinity) is S.Zero
439
+ assert f(m, S.NegativeInfinity) is S.Zero
440
+
441
+ for f in [besseli, besselk]:
442
+ assert f(m, I*S.Infinity) is S.Zero
443
+ assert f(m, I*S.NegativeInfinity) is S.Zero
444
+
445
+ for f in [besseli, besselk]:
446
+ assert f(-4, z) == f(4, z)
447
+ assert f(-3, z) == f(3, z)
448
+ assert f(-n, z) == f(n, z)
449
+ assert f(-m, z) != f(m, z)
450
+
451
+ for f in [besselj, bessely]:
452
+ assert f(-4, z) == f(4, z)
453
+ assert f(-3, z) == -f(3, z)
454
+ assert f(-n, z) == (-1)**n*f(n, z)
455
+ assert f(-m, z) != (-1)**m*f(m, z)
456
+
457
+ for f in [besselj, besseli]:
458
+ assert f(m, -z) == (-z)**m*z**(-m)*f(m, z)
459
+
460
+ assert besseli(2, -z) == besseli(2, z)
461
+ assert besseli(3, -z) == -besseli(3, z)
462
+
463
+ assert besselj(0, -z) == besselj(0, z)
464
+ assert besselj(1, -z) == -besselj(1, z)
465
+
466
+ assert besseli(0, I*z) == besselj(0, z)
467
+ assert besseli(1, I*z) == I*besselj(1, z)
468
+ assert besselj(3, I*z) == -I*besseli(3, z)
469
+
470
+
471
+ def test_bessel_nan():
472
+ # FIXME: could have these return NaN; for now just fix infinite recursion
473
+ for f in [besselj, bessely, besseli, besselk, hankel1, hankel2, yn, jn]:
474
+ assert f(1, S.NaN) == f(1, S.NaN, evaluate=False)
475
+
476
+
477
+ def test_meromorphic():
478
+ assert besselj(2, x).is_meromorphic(x, 1) == True
479
+ assert besselj(2, x).is_meromorphic(x, 0) == True
480
+ assert besselj(2, x).is_meromorphic(x, oo) == False
481
+ assert besselj(S(2)/3, x).is_meromorphic(x, 1) == True
482
+ assert besselj(S(2)/3, x).is_meromorphic(x, 0) == False
483
+ assert besselj(S(2)/3, x).is_meromorphic(x, oo) == False
484
+ assert besselj(x, 2*x).is_meromorphic(x, 2) == False
485
+ assert besselk(0, x).is_meromorphic(x, 1) == True
486
+ assert besselk(2, x).is_meromorphic(x, 0) == True
487
+ assert besseli(0, x).is_meromorphic(x, 1) == True
488
+ assert besseli(2, x).is_meromorphic(x, 0) == True
489
+ assert bessely(0, x).is_meromorphic(x, 1) == True
490
+ assert bessely(0, x).is_meromorphic(x, 0) == False
491
+ assert bessely(2, x).is_meromorphic(x, 0) == True
492
+ assert hankel1(3, x**2 + 2*x).is_meromorphic(x, 1) == True
493
+ assert hankel1(0, x).is_meromorphic(x, 0) == False
494
+ assert hankel2(11, 4).is_meromorphic(x, 5) == True
495
+ assert hn1(6, 7*x**3 + 4).is_meromorphic(x, 7) == True
496
+ assert hn2(3, 2*x).is_meromorphic(x, 9) == True
497
+ assert jn(5, 2*x + 7).is_meromorphic(x, 4) == True
498
+ assert yn(8, x**2 + 11).is_meromorphic(x, 6) == True
499
+
500
+
501
+ def test_conjugate():
502
+ n = Symbol('n')
503
+ z = Symbol('z', extended_real=False)
504
+ x = Symbol('x', extended_real=True)
505
+ y = Symbol('y', positive=True)
506
+ t = Symbol('t', negative=True)
507
+
508
+ for f in [besseli, besselj, besselk, bessely, hankel1, hankel2]:
509
+ assert f(n, -1).conjugate() != f(conjugate(n), -1)
510
+ assert f(n, x).conjugate() != f(conjugate(n), x)
511
+ assert f(n, t).conjugate() != f(conjugate(n), t)
512
+
513
+ rz = randcplx(b=0.5)
514
+
515
+ for f in [besseli, besselj, besselk, bessely]:
516
+ assert f(n, 1 + I).conjugate() == f(conjugate(n), 1 - I)
517
+ assert f(n, 0).conjugate() == f(conjugate(n), 0)
518
+ assert f(n, 1).conjugate() == f(conjugate(n), 1)
519
+ assert f(n, z).conjugate() == f(conjugate(n), conjugate(z))
520
+ assert f(n, y).conjugate() == f(conjugate(n), y)
521
+ assert tn(f(n, rz).conjugate(), f(conjugate(n), conjugate(rz)))
522
+
523
+ assert hankel1(n, 1 + I).conjugate() == hankel2(conjugate(n), 1 - I)
524
+ assert hankel1(n, 0).conjugate() == hankel2(conjugate(n), 0)
525
+ assert hankel1(n, 1).conjugate() == hankel2(conjugate(n), 1)
526
+ assert hankel1(n, y).conjugate() == hankel2(conjugate(n), y)
527
+ assert hankel1(n, z).conjugate() == hankel2(conjugate(n), conjugate(z))
528
+ assert tn(hankel1(n, rz).conjugate(), hankel2(conjugate(n), conjugate(rz)))
529
+
530
+ assert hankel2(n, 1 + I).conjugate() == hankel1(conjugate(n), 1 - I)
531
+ assert hankel2(n, 0).conjugate() == hankel1(conjugate(n), 0)
532
+ assert hankel2(n, 1).conjugate() == hankel1(conjugate(n), 1)
533
+ assert hankel2(n, y).conjugate() == hankel1(conjugate(n), y)
534
+ assert hankel2(n, z).conjugate() == hankel1(conjugate(n), conjugate(z))
535
+ assert tn(hankel2(n, rz).conjugate(), hankel1(conjugate(n), conjugate(rz)))
536
+
537
+
538
+ def test_branching():
539
+ assert besselj(polar_lift(k), x) == besselj(k, x)
540
+ assert besseli(polar_lift(k), x) == besseli(k, x)
541
+
542
+ n = Symbol('n', integer=True)
543
+ assert besselj(n, exp_polar(2*pi*I)*x) == besselj(n, x)
544
+ assert besselj(n, polar_lift(x)) == besselj(n, x)
545
+ assert besseli(n, exp_polar(2*pi*I)*x) == besseli(n, x)
546
+ assert besseli(n, polar_lift(x)) == besseli(n, x)
547
+
548
+ def tn(func, s):
549
+ from sympy.core.random import uniform
550
+ c = uniform(1, 5)
551
+ expr = func(s, c*exp_polar(I*pi)) - func(s, c*exp_polar(-I*pi))
552
+ eps = 1e-15
553
+ expr2 = func(s + eps, -c + eps*I) - func(s + eps, -c - eps*I)
554
+ return abs(expr.n() - expr2.n()).n() < 1e-10
555
+
556
+ nu = Symbol('nu')
557
+ assert besselj(nu, exp_polar(2*pi*I)*x) == exp(2*pi*I*nu)*besselj(nu, x)
558
+ assert besseli(nu, exp_polar(2*pi*I)*x) == exp(2*pi*I*nu)*besseli(nu, x)
559
+ assert tn(besselj, 2)
560
+ assert tn(besselj, pi)
561
+ assert tn(besselj, I)
562
+ assert tn(besseli, 2)
563
+ assert tn(besseli, pi)
564
+ assert tn(besseli, I)
565
+
566
+
567
+ def test_airy_base():
568
+ z = Symbol('z')
569
+ x = Symbol('x', real=True)
570
+ y = Symbol('y', real=True)
571
+
572
+ assert conjugate(airyai(z)) == airyai(conjugate(z))
573
+ assert airyai(x).is_extended_real
574
+
575
+ assert airyai(x+I*y).as_real_imag() == (
576
+ airyai(x - I*y)/2 + airyai(x + I*y)/2,
577
+ I*(airyai(x - I*y) - airyai(x + I*y))/2)
578
+
579
+
580
+ def test_airyai():
581
+ z = Symbol('z', real=False)
582
+ t = Symbol('t', negative=True)
583
+ p = Symbol('p', positive=True)
584
+
585
+ assert isinstance(airyai(z), airyai)
586
+
587
+ assert airyai(0) == 3**Rational(1, 3)/(3*gamma(Rational(2, 3)))
588
+ assert airyai(oo) == 0
589
+ assert airyai(-oo) == 0
590
+
591
+ assert diff(airyai(z), z) == airyaiprime(z)
592
+
593
+ assert series(airyai(z), z, 0, 3) == (
594
+ 3**Rational(5, 6)*gamma(Rational(1, 3))/(6*pi) - 3**Rational(1, 6)*z*gamma(Rational(2, 3))/(2*pi) + O(z**3))
595
+
596
+ assert airyai(z).rewrite(hyper) == (
597
+ -3**Rational(2, 3)*z*hyper((), (Rational(4, 3),), z**3/9)/(3*gamma(Rational(1, 3))) +
598
+ 3**Rational(1, 3)*hyper((), (Rational(2, 3),), z**3/9)/(3*gamma(Rational(2, 3))))
599
+
600
+ assert isinstance(airyai(z).rewrite(besselj), airyai)
601
+ assert airyai(t).rewrite(besselj) == (
602
+ sqrt(-t)*(besselj(Rational(-1, 3), 2*(-t)**Rational(3, 2)/3) +
603
+ besselj(Rational(1, 3), 2*(-t)**Rational(3, 2)/3))/3)
604
+ assert airyai(z).rewrite(besseli) == (
605
+ -z*besseli(Rational(1, 3), 2*z**Rational(3, 2)/3)/(3*(z**Rational(3, 2))**Rational(1, 3)) +
606
+ (z**Rational(3, 2))**Rational(1, 3)*besseli(Rational(-1, 3), 2*z**Rational(3, 2)/3)/3)
607
+ assert airyai(p).rewrite(besseli) == (
608
+ sqrt(p)*(besseli(Rational(-1, 3), 2*p**Rational(3, 2)/3) -
609
+ besseli(Rational(1, 3), 2*p**Rational(3, 2)/3))/3)
610
+
611
+ assert expand_func(airyai(2*(3*z**5)**Rational(1, 3))) == (
612
+ -sqrt(3)*(-1 + (z**5)**Rational(1, 3)/z**Rational(5, 3))*airybi(2*3**Rational(1, 3)*z**Rational(5, 3))/6 +
613
+ (1 + (z**5)**Rational(1, 3)/z**Rational(5, 3))*airyai(2*3**Rational(1, 3)*z**Rational(5, 3))/2)
614
+
615
+
616
+ def test_airybi():
617
+ z = Symbol('z', real=False)
618
+ t = Symbol('t', negative=True)
619
+ p = Symbol('p', positive=True)
620
+
621
+ assert isinstance(airybi(z), airybi)
622
+
623
+ assert airybi(0) == 3**Rational(5, 6)/(3*gamma(Rational(2, 3)))
624
+ assert airybi(oo) is oo
625
+ assert airybi(-oo) == 0
626
+
627
+ assert diff(airybi(z), z) == airybiprime(z)
628
+
629
+ assert series(airybi(z), z, 0, 3) == (
630
+ 3**Rational(1, 3)*gamma(Rational(1, 3))/(2*pi) + 3**Rational(2, 3)*z*gamma(Rational(2, 3))/(2*pi) + O(z**3))
631
+
632
+ assert airybi(z).rewrite(hyper) == (
633
+ 3**Rational(1, 6)*z*hyper((), (Rational(4, 3),), z**3/9)/gamma(Rational(1, 3)) +
634
+ 3**Rational(5, 6)*hyper((), (Rational(2, 3),), z**3/9)/(3*gamma(Rational(2, 3))))
635
+
636
+ assert isinstance(airybi(z).rewrite(besselj), airybi)
637
+ assert airyai(t).rewrite(besselj) == (
638
+ sqrt(-t)*(besselj(Rational(-1, 3), 2*(-t)**Rational(3, 2)/3) +
639
+ besselj(Rational(1, 3), 2*(-t)**Rational(3, 2)/3))/3)
640
+ assert airybi(z).rewrite(besseli) == (
641
+ sqrt(3)*(z*besseli(Rational(1, 3), 2*z**Rational(3, 2)/3)/(z**Rational(3, 2))**Rational(1, 3) +
642
+ (z**Rational(3, 2))**Rational(1, 3)*besseli(Rational(-1, 3), 2*z**Rational(3, 2)/3))/3)
643
+ assert airybi(p).rewrite(besseli) == (
644
+ sqrt(3)*sqrt(p)*(besseli(Rational(-1, 3), 2*p**Rational(3, 2)/3) +
645
+ besseli(Rational(1, 3), 2*p**Rational(3, 2)/3))/3)
646
+
647
+ assert expand_func(airybi(2*(3*z**5)**Rational(1, 3))) == (
648
+ sqrt(3)*(1 - (z**5)**Rational(1, 3)/z**Rational(5, 3))*airyai(2*3**Rational(1, 3)*z**Rational(5, 3))/2 +
649
+ (1 + (z**5)**Rational(1, 3)/z**Rational(5, 3))*airybi(2*3**Rational(1, 3)*z**Rational(5, 3))/2)
650
+
651
+
652
+ def test_airyaiprime():
653
+ z = Symbol('z', real=False)
654
+ t = Symbol('t', negative=True)
655
+ p = Symbol('p', positive=True)
656
+
657
+ assert isinstance(airyaiprime(z), airyaiprime)
658
+
659
+ assert airyaiprime(0) == -3**Rational(2, 3)/(3*gamma(Rational(1, 3)))
660
+ assert airyaiprime(oo) == 0
661
+
662
+ assert diff(airyaiprime(z), z) == z*airyai(z)
663
+
664
+ assert series(airyaiprime(z), z, 0, 3) == (
665
+ -3**Rational(2, 3)/(3*gamma(Rational(1, 3))) + 3**Rational(1, 3)*z**2/(6*gamma(Rational(2, 3))) + O(z**3))
666
+
667
+ assert airyaiprime(z).rewrite(hyper) == (
668
+ 3**Rational(1, 3)*z**2*hyper((), (Rational(5, 3),), z**3/9)/(6*gamma(Rational(2, 3))) -
669
+ 3**Rational(2, 3)*hyper((), (Rational(1, 3),), z**3/9)/(3*gamma(Rational(1, 3))))
670
+
671
+ assert isinstance(airyaiprime(z).rewrite(besselj), airyaiprime)
672
+ assert airyai(t).rewrite(besselj) == (
673
+ sqrt(-t)*(besselj(Rational(-1, 3), 2*(-t)**Rational(3, 2)/3) +
674
+ besselj(Rational(1, 3), 2*(-t)**Rational(3, 2)/3))/3)
675
+ assert airyaiprime(z).rewrite(besseli) == (
676
+ z**2*besseli(Rational(2, 3), 2*z**Rational(3, 2)/3)/(3*(z**Rational(3, 2))**Rational(2, 3)) -
677
+ (z**Rational(3, 2))**Rational(2, 3)*besseli(Rational(-1, 3), 2*z**Rational(3, 2)/3)/3)
678
+ assert airyaiprime(p).rewrite(besseli) == (
679
+ p*(-besseli(Rational(-2, 3), 2*p**Rational(3, 2)/3) + besseli(Rational(2, 3), 2*p**Rational(3, 2)/3))/3)
680
+
681
+ assert expand_func(airyaiprime(2*(3*z**5)**Rational(1, 3))) == (
682
+ sqrt(3)*(z**Rational(5, 3)/(z**5)**Rational(1, 3) - 1)*airybiprime(2*3**Rational(1, 3)*z**Rational(5, 3))/6 +
683
+ (z**Rational(5, 3)/(z**5)**Rational(1, 3) + 1)*airyaiprime(2*3**Rational(1, 3)*z**Rational(5, 3))/2)
684
+
685
+
686
+ def test_airybiprime():
687
+ z = Symbol('z', real=False)
688
+ t = Symbol('t', negative=True)
689
+ p = Symbol('p', positive=True)
690
+
691
+ assert isinstance(airybiprime(z), airybiprime)
692
+
693
+ assert airybiprime(0) == 3**Rational(1, 6)/gamma(Rational(1, 3))
694
+ assert airybiprime(oo) is oo
695
+ assert airybiprime(-oo) == 0
696
+
697
+ assert diff(airybiprime(z), z) == z*airybi(z)
698
+
699
+ assert series(airybiprime(z), z, 0, 3) == (
700
+ 3**Rational(1, 6)/gamma(Rational(1, 3)) + 3**Rational(5, 6)*z**2/(6*gamma(Rational(2, 3))) + O(z**3))
701
+
702
+ assert airybiprime(z).rewrite(hyper) == (
703
+ 3**Rational(5, 6)*z**2*hyper((), (Rational(5, 3),), z**3/9)/(6*gamma(Rational(2, 3))) +
704
+ 3**Rational(1, 6)*hyper((), (Rational(1, 3),), z**3/9)/gamma(Rational(1, 3)))
705
+
706
+ assert isinstance(airybiprime(z).rewrite(besselj), airybiprime)
707
+ assert airyai(t).rewrite(besselj) == (
708
+ sqrt(-t)*(besselj(Rational(-1, 3), 2*(-t)**Rational(3, 2)/3) +
709
+ besselj(Rational(1, 3), 2*(-t)**Rational(3, 2)/3))/3)
710
+ assert airybiprime(z).rewrite(besseli) == (
711
+ sqrt(3)*(z**2*besseli(Rational(2, 3), 2*z**Rational(3, 2)/3)/(z**Rational(3, 2))**Rational(2, 3) +
712
+ (z**Rational(3, 2))**Rational(2, 3)*besseli(Rational(-2, 3), 2*z**Rational(3, 2)/3))/3)
713
+ assert airybiprime(p).rewrite(besseli) == (
714
+ sqrt(3)*p*(besseli(Rational(-2, 3), 2*p**Rational(3, 2)/3) + besseli(Rational(2, 3), 2*p**Rational(3, 2)/3))/3)
715
+
716
+ assert expand_func(airybiprime(2*(3*z**5)**Rational(1, 3))) == (
717
+ sqrt(3)*(z**Rational(5, 3)/(z**5)**Rational(1, 3) - 1)*airyaiprime(2*3**Rational(1, 3)*z**Rational(5, 3))/2 +
718
+ (z**Rational(5, 3)/(z**5)**Rational(1, 3) + 1)*airybiprime(2*3**Rational(1, 3)*z**Rational(5, 3))/2)
719
+
720
+
721
+ def test_marcumq():
722
+ m = Symbol('m')
723
+ a = Symbol('a')
724
+ b = Symbol('b')
725
+
726
+ assert marcumq(0, 0, 0) == 0
727
+ assert marcumq(m, 0, b) == uppergamma(m, b**2/2)/gamma(m)
728
+ assert marcumq(2, 0, 5) == 27*exp(Rational(-25, 2))/2
729
+ assert marcumq(0, a, 0) == 1 - exp(-a**2/2)
730
+ assert marcumq(0, pi, 0) == 1 - exp(-pi**2/2)
731
+ assert marcumq(1, a, a) == S.Half + exp(-a**2)*besseli(0, a**2)/2
732
+ assert marcumq(2, a, a) == S.Half + exp(-a**2)*besseli(0, a**2)/2 + exp(-a**2)*besseli(1, a**2)
733
+
734
+ assert diff(marcumq(1, a, 3), a) == a*(-marcumq(1, a, 3) + marcumq(2, a, 3))
735
+ assert diff(marcumq(2, 3, b), b) == -b**2*exp(-b**2/2 - Rational(9, 2))*besseli(1, 3*b)/3
736
+
737
+ x = Symbol('x')
738
+ assert marcumq(2, 3, 4).rewrite(Integral, x=x) == \
739
+ Integral(x**2*exp(-x**2/2 - Rational(9, 2))*besseli(1, 3*x), (x, 4, oo))/3
740
+ assert eq([marcumq(5, -2, 3).rewrite(Integral).evalf(10)],
741
+ [0.7905769565])
742
+
743
+ k = Symbol('k')
744
+ assert marcumq(-3, -5, -7).rewrite(Sum, k=k) == \
745
+ exp(-37)*Sum((Rational(5, 7))**k*besseli(k, 35), (k, 4, oo))
746
+ assert eq([marcumq(1, 3, 1).rewrite(Sum).evalf(10)],
747
+ [0.9891705502])
748
+
749
+ assert marcumq(1, a, a, evaluate=False).rewrite(besseli) == S.Half + exp(-a**2)*besseli(0, a**2)/2
750
+ assert marcumq(2, a, a, evaluate=False).rewrite(besseli) == S.Half + exp(-a**2)*besseli(0, a**2)/2 + \
751
+ exp(-a**2)*besseli(1, a**2)
752
+ assert marcumq(3, a, a).rewrite(besseli) == (besseli(1, a**2) + besseli(2, a**2))*exp(-a**2) + \
753
+ S.Half + exp(-a**2)*besseli(0, a**2)/2
754
+ assert marcumq(5, 8, 8).rewrite(besseli) == exp(-64)*besseli(0, 64)/2 + \
755
+ (besseli(4, 64) + besseli(3, 64) + besseli(2, 64) + besseli(1, 64))*exp(-64) + S.Half
756
+ assert marcumq(m, a, a).rewrite(besseli) == marcumq(m, a, a)
757
+
758
+ x = Symbol('x', integer=True)
759
+ assert marcumq(x, a, a).rewrite(besseli) == marcumq(x, a, a)
env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_bsplines.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.functions import bspline_basis_set, interpolating_spline
2
+ from sympy.core.numbers import Rational
3
+ from sympy.core.singleton import S
4
+ from sympy.core.symbol import symbols
5
+ from sympy.functions.elementary.piecewise import Piecewise
6
+ from sympy.logic.boolalg import And
7
+ from sympy.sets.sets import Interval
8
+ from sympy.testing.pytest import slow
9
+
10
+ x, y = symbols('x,y')
11
+
12
+
13
+ def test_basic_degree_0():
14
+ d = 0
15
+ knots = range(5)
16
+ splines = bspline_basis_set(d, knots, x)
17
+ for i in range(len(splines)):
18
+ assert splines[i] == Piecewise((1, Interval(i, i + 1).contains(x)),
19
+ (0, True))
20
+
21
+
22
+ def test_basic_degree_1():
23
+ d = 1
24
+ knots = range(5)
25
+ splines = bspline_basis_set(d, knots, x)
26
+ assert splines[0] == Piecewise((x, Interval(0, 1).contains(x)),
27
+ (2 - x, Interval(1, 2).contains(x)),
28
+ (0, True))
29
+ assert splines[1] == Piecewise((-1 + x, Interval(1, 2).contains(x)),
30
+ (3 - x, Interval(2, 3).contains(x)),
31
+ (0, True))
32
+ assert splines[2] == Piecewise((-2 + x, Interval(2, 3).contains(x)),
33
+ (4 - x, Interval(3, 4).contains(x)),
34
+ (0, True))
35
+
36
+
37
+ def test_basic_degree_2():
38
+ d = 2
39
+ knots = range(5)
40
+ splines = bspline_basis_set(d, knots, x)
41
+ b0 = Piecewise((x**2/2, Interval(0, 1).contains(x)),
42
+ (Rational(-3, 2) + 3*x - x**2, Interval(1, 2).contains(x)),
43
+ (Rational(9, 2) - 3*x + x**2/2, Interval(2, 3).contains(x)),
44
+ (0, True))
45
+ b1 = Piecewise((S.Half - x + x**2/2, Interval(1, 2).contains(x)),
46
+ (Rational(-11, 2) + 5*x - x**2, Interval(2, 3).contains(x)),
47
+ (8 - 4*x + x**2/2, Interval(3, 4).contains(x)),
48
+ (0, True))
49
+ assert splines[0] == b0
50
+ assert splines[1] == b1
51
+
52
+
53
+ def test_basic_degree_3():
54
+ d = 3
55
+ knots = range(5)
56
+ splines = bspline_basis_set(d, knots, x)
57
+ b0 = Piecewise(
58
+ (x**3/6, Interval(0, 1).contains(x)),
59
+ (Rational(2, 3) - 2*x + 2*x**2 - x**3/2, Interval(1, 2).contains(x)),
60
+ (Rational(-22, 3) + 10*x - 4*x**2 + x**3/2, Interval(2, 3).contains(x)),
61
+ (Rational(32, 3) - 8*x + 2*x**2 - x**3/6, Interval(3, 4).contains(x)),
62
+ (0, True)
63
+ )
64
+ assert splines[0] == b0
65
+
66
+
67
+ def test_repeated_degree_1():
68
+ d = 1
69
+ knots = [0, 0, 1, 2, 2, 3, 4, 4]
70
+ splines = bspline_basis_set(d, knots, x)
71
+ assert splines[0] == Piecewise((1 - x, Interval(0, 1).contains(x)),
72
+ (0, True))
73
+ assert splines[1] == Piecewise((x, Interval(0, 1).contains(x)),
74
+ (2 - x, Interval(1, 2).contains(x)),
75
+ (0, True))
76
+ assert splines[2] == Piecewise((-1 + x, Interval(1, 2).contains(x)),
77
+ (0, True))
78
+ assert splines[3] == Piecewise((3 - x, Interval(2, 3).contains(x)),
79
+ (0, True))
80
+ assert splines[4] == Piecewise((-2 + x, Interval(2, 3).contains(x)),
81
+ (4 - x, Interval(3, 4).contains(x)),
82
+ (0, True))
83
+ assert splines[5] == Piecewise((-3 + x, Interval(3, 4).contains(x)),
84
+ (0, True))
85
+
86
+
87
+ def test_repeated_degree_2():
88
+ d = 2
89
+ knots = [0, 0, 1, 2, 2, 3, 4, 4]
90
+ splines = bspline_basis_set(d, knots, x)
91
+
92
+ assert splines[0] == Piecewise(((-3*x**2/2 + 2*x), And(x <= 1, x >= 0)),
93
+ (x**2/2 - 2*x + 2, And(x <= 2, x >= 1)),
94
+ (0, True))
95
+ assert splines[1] == Piecewise((x**2/2, And(x <= 1, x >= 0)),
96
+ (-3*x**2/2 + 4*x - 2, And(x <= 2, x >= 1)),
97
+ (0, True))
98
+ assert splines[2] == Piecewise((x**2 - 2*x + 1, And(x <= 2, x >= 1)),
99
+ (x**2 - 6*x + 9, And(x <= 3, x >= 2)),
100
+ (0, True))
101
+ assert splines[3] == Piecewise((-3*x**2/2 + 8*x - 10, And(x <= 3, x >= 2)),
102
+ (x**2/2 - 4*x + 8, And(x <= 4, x >= 3)),
103
+ (0, True))
104
+ assert splines[4] == Piecewise((x**2/2 - 2*x + 2, And(x <= 3, x >= 2)),
105
+ (-3*x**2/2 + 10*x - 16, And(x <= 4, x >= 3)),
106
+ (0, True))
107
+
108
+ # Tests for interpolating_spline
109
+
110
+
111
+ def test_10_points_degree_1():
112
+ d = 1
113
+ X = [-5, 2, 3, 4, 7, 9, 10, 30, 31, 34]
114
+ Y = [-10, -2, 2, 4, 7, 6, 20, 45, 19, 25]
115
+ spline = interpolating_spline(d, x, X, Y)
116
+
117
+ assert spline == Piecewise((x*Rational(8, 7) - Rational(30, 7), (x >= -5) & (x <= 2)), (4*x - 10, (x >= 2) & (x <= 3)),
118
+ (2*x - 4, (x >= 3) & (x <= 4)), (x, (x >= 4) & (x <= 7)),
119
+ (-x/2 + Rational(21, 2), (x >= 7) & (x <= 9)), (14*x - 120, (x >= 9) & (x <= 10)),
120
+ (x*Rational(5, 4) + Rational(15, 2), (x >= 10) & (x <= 30)), (-26*x + 825, (x >= 30) & (x <= 31)),
121
+ (2*x - 43, (x >= 31) & (x <= 34)))
122
+
123
+
124
+ def test_3_points_degree_2():
125
+ d = 2
126
+ X = [-3, 10, 19]
127
+ Y = [3, -4, 30]
128
+ spline = interpolating_spline(d, x, X, Y)
129
+
130
+ assert spline == Piecewise((505*x**2/2574 - x*Rational(4921, 2574) - Rational(1931, 429), (x >= -3) & (x <= 19)))
131
+
132
+
133
+ def test_5_points_degree_2():
134
+ d = 2
135
+ X = [-3, 2, 4, 5, 10]
136
+ Y = [-1, 2, 5, 10, 14]
137
+ spline = interpolating_spline(d, x, X, Y)
138
+
139
+ assert spline == Piecewise((4*x**2/329 + x*Rational(1007, 1645) + Rational(1196, 1645), (x >= -3) & (x <= 3)),
140
+ (2701*x**2/1645 - x*Rational(15079, 1645) + Rational(5065, 329), (x >= 3) & (x <= Rational(9, 2))),
141
+ (-1319*x**2/1645 + x*Rational(21101, 1645) - Rational(11216, 329), (x >= Rational(9, 2)) & (x <= 10)))
142
+
143
+
144
+ @slow
145
+ def test_6_points_degree_3():
146
+ d = 3
147
+ X = [-1, 0, 2, 3, 9, 12]
148
+ Y = [-4, 3, 3, 7, 9, 20]
149
+ spline = interpolating_spline(d, x, X, Y)
150
+
151
+ assert spline == Piecewise((6058*x**3/5301 - 18427*x**2/5301 + x*Rational(12622, 5301) + 3, (x >= -1) & (x <= 2)),
152
+ (-8327*x**3/5301 + 67883*x**2/5301 - x*Rational(159998, 5301) + Rational(43661, 1767), (x >= 2) & (x <= 3)),
153
+ (5414*x**3/47709 - 1386*x**2/589 + x*Rational(4267, 279) - Rational(12232, 589), (x >= 3) & (x <= 12)))
154
+
155
+
156
+ def test_issue_19262():
157
+ Delta = symbols('Delta', positive=True)
158
+ knots = [i*Delta for i in range(4)]
159
+ basis = bspline_basis_set(1, knots, x)
160
+ y = symbols('y', nonnegative=True)
161
+ basis2 = bspline_basis_set(1, knots, y)
162
+ assert basis[0].subs(x, y) == basis2[0]
163
+ assert interpolating_spline(1, x,
164
+ [Delta*i for i in [1, 2, 4, 7]], [3, 6, 5, 7]
165
+ ) == Piecewise((3*x/Delta, (Delta <= x) & (x <= 2*Delta)),
166
+ (7 - x/(2*Delta), (x >= 2*Delta) & (x <= 4*Delta)),
167
+ (Rational(7, 3) + 2*x/(3*Delta), (x >= 4*Delta) & (x <= 7*Delta)))
env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_delta_functions.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.numbers import (I, nan, oo, pi)
2
+ from sympy.core.relational import (Eq, Ne)
3
+ from sympy.core.singleton import S
4
+ from sympy.core.symbol import (Symbol, symbols)
5
+ from sympy.functions.elementary.complexes import (adjoint, conjugate, sign, transpose)
6
+ from sympy.functions.elementary.miscellaneous import sqrt
7
+ from sympy.functions.elementary.piecewise import Piecewise
8
+ from sympy.functions.special.delta_functions import (DiracDelta, Heaviside)
9
+ from sympy.functions.special.singularity_functions import SingularityFunction
10
+ from sympy.simplify.simplify import signsimp
11
+
12
+
13
+ from sympy.testing.pytest import raises
14
+
15
+ from sympy.core.expr import unchanged
16
+
17
+ from sympy.core.function import ArgumentIndexError
18
+
19
+
20
+ x, y = symbols('x y')
21
+ i = symbols('t', nonzero=True)
22
+ j = symbols('j', positive=True)
23
+ k = symbols('k', negative=True)
24
+
25
+ def test_DiracDelta():
26
+ assert DiracDelta(1) == 0
27
+ assert DiracDelta(5.1) == 0
28
+ assert DiracDelta(-pi) == 0
29
+ assert DiracDelta(5, 7) == 0
30
+ assert DiracDelta(x, 0) == DiracDelta(x)
31
+ assert DiracDelta(i) == 0
32
+ assert DiracDelta(j) == 0
33
+ assert DiracDelta(k) == 0
34
+ assert DiracDelta(nan) is nan
35
+ assert DiracDelta(0).func is DiracDelta
36
+ assert DiracDelta(x).func is DiracDelta
37
+ # FIXME: this is generally undefined @ x=0
38
+ # But then limit(Delta(c)*Heaviside(x),x,-oo)
39
+ # need's to be implemented.
40
+ # assert 0*DiracDelta(x) == 0
41
+
42
+ assert adjoint(DiracDelta(x)) == DiracDelta(x)
43
+ assert adjoint(DiracDelta(x - y)) == DiracDelta(x - y)
44
+ assert conjugate(DiracDelta(x)) == DiracDelta(x)
45
+ assert conjugate(DiracDelta(x - y)) == DiracDelta(x - y)
46
+ assert transpose(DiracDelta(x)) == DiracDelta(x)
47
+ assert transpose(DiracDelta(x - y)) == DiracDelta(x - y)
48
+
49
+ assert DiracDelta(x).diff(x) == DiracDelta(x, 1)
50
+ assert DiracDelta(x, 1).diff(x) == DiracDelta(x, 2)
51
+
52
+ assert DiracDelta(x).is_simple(x) is True
53
+ assert DiracDelta(3*x).is_simple(x) is True
54
+ assert DiracDelta(x**2).is_simple(x) is False
55
+ assert DiracDelta(sqrt(x)).is_simple(x) is False
56
+ assert DiracDelta(x).is_simple(y) is False
57
+
58
+ assert DiracDelta(x*y).expand(diracdelta=True, wrt=x) == DiracDelta(x)/abs(y)
59
+ assert DiracDelta(x*y).expand(diracdelta=True, wrt=y) == DiracDelta(y)/abs(x)
60
+ assert DiracDelta(x**2*y).expand(diracdelta=True, wrt=x) == DiracDelta(x**2*y)
61
+ assert DiracDelta(y).expand(diracdelta=True, wrt=x) == DiracDelta(y)
62
+ assert DiracDelta((x - 1)*(x - 2)*(x - 3)).expand(diracdelta=True, wrt=x) == (
63
+ DiracDelta(x - 3)/2 + DiracDelta(x - 2) + DiracDelta(x - 1)/2)
64
+
65
+ assert DiracDelta(2*x) != DiracDelta(x) # scaling property
66
+ assert DiracDelta(x) == DiracDelta(-x) # even function
67
+ assert DiracDelta(-x, 2) == DiracDelta(x, 2)
68
+ assert DiracDelta(-x, 1) == -DiracDelta(x, 1) # odd deriv is odd
69
+ assert DiracDelta(-oo*x) == DiracDelta(oo*x)
70
+ assert DiracDelta(x - y) != DiracDelta(y - x)
71
+ assert signsimp(DiracDelta(x - y) - DiracDelta(y - x)) == 0
72
+
73
+ assert DiracDelta(x*y).expand(diracdelta=True, wrt=x) == DiracDelta(x)/abs(y)
74
+ assert DiracDelta(x*y).expand(diracdelta=True, wrt=y) == DiracDelta(y)/abs(x)
75
+ assert DiracDelta(x**2*y).expand(diracdelta=True, wrt=x) == DiracDelta(x**2*y)
76
+ assert DiracDelta(y).expand(diracdelta=True, wrt=x) == DiracDelta(y)
77
+ assert DiracDelta((x - 1)*(x - 2)*(x - 3)).expand(diracdelta=True) == (
78
+ DiracDelta(x - 3)/2 + DiracDelta(x - 2) + DiracDelta(x - 1)/2)
79
+
80
+ raises(ArgumentIndexError, lambda: DiracDelta(x).fdiff(2))
81
+ raises(ValueError, lambda: DiracDelta(x, -1))
82
+ raises(ValueError, lambda: DiracDelta(I))
83
+ raises(ValueError, lambda: DiracDelta(2 + 3*I))
84
+
85
+
86
+ def test_heaviside():
87
+ assert Heaviside(-5) == 0
88
+ assert Heaviside(1) == 1
89
+ assert Heaviside(0) == S.Half
90
+
91
+ assert Heaviside(0, x) == x
92
+ assert unchanged(Heaviside,x, nan)
93
+ assert Heaviside(0, nan) == nan
94
+
95
+ h0 = Heaviside(x, 0)
96
+ h12 = Heaviside(x, S.Half)
97
+ h1 = Heaviside(x, 1)
98
+
99
+ assert h0.args == h0.pargs == (x, 0)
100
+ assert h1.args == h1.pargs == (x, 1)
101
+ assert h12.args == (x, S.Half)
102
+ assert h12.pargs == (x,) # default 1/2 suppressed
103
+
104
+ assert adjoint(Heaviside(x)) == Heaviside(x)
105
+ assert adjoint(Heaviside(x - y)) == Heaviside(x - y)
106
+ assert conjugate(Heaviside(x)) == Heaviside(x)
107
+ assert conjugate(Heaviside(x - y)) == Heaviside(x - y)
108
+ assert transpose(Heaviside(x)) == Heaviside(x)
109
+ assert transpose(Heaviside(x - y)) == Heaviside(x - y)
110
+
111
+ assert Heaviside(x).diff(x) == DiracDelta(x)
112
+ assert Heaviside(x + I).is_Function is True
113
+ assert Heaviside(I*x).is_Function is True
114
+
115
+ raises(ArgumentIndexError, lambda: Heaviside(x).fdiff(2))
116
+ raises(ValueError, lambda: Heaviside(I))
117
+ raises(ValueError, lambda: Heaviside(2 + 3*I))
118
+
119
+
120
+ def test_rewrite():
121
+ x, y = Symbol('x', real=True), Symbol('y')
122
+ assert Heaviside(x).rewrite(Piecewise) == (
123
+ Piecewise((0, x < 0), (Heaviside(0), Eq(x, 0)), (1, True)))
124
+ assert Heaviside(y).rewrite(Piecewise) == (
125
+ Piecewise((0, y < 0), (Heaviside(0), Eq(y, 0)), (1, True)))
126
+ assert Heaviside(x, y).rewrite(Piecewise) == (
127
+ Piecewise((0, x < 0), (y, Eq(x, 0)), (1, True)))
128
+ assert Heaviside(x, 0).rewrite(Piecewise) == (
129
+ Piecewise((0, x <= 0), (1, True)))
130
+ assert Heaviside(x, 1).rewrite(Piecewise) == (
131
+ Piecewise((0, x < 0), (1, True)))
132
+ assert Heaviside(x, nan).rewrite(Piecewise) == (
133
+ Piecewise((0, x < 0), (nan, Eq(x, 0)), (1, True)))
134
+
135
+ assert Heaviside(x).rewrite(sign) == \
136
+ Heaviside(x, H0=Heaviside(0)).rewrite(sign) == \
137
+ Piecewise(
138
+ (sign(x)/2 + S(1)/2, Eq(Heaviside(0), S(1)/2)),
139
+ (Piecewise(
140
+ (sign(x)/2 + S(1)/2, Ne(x, 0)), (Heaviside(0), True)), True)
141
+ )
142
+
143
+ assert Heaviside(y).rewrite(sign) == Heaviside(y)
144
+ assert Heaviside(x, S.Half).rewrite(sign) == (sign(x)+1)/2
145
+ assert Heaviside(x, y).rewrite(sign) == \
146
+ Piecewise(
147
+ (sign(x)/2 + S(1)/2, Eq(y, S(1)/2)),
148
+ (Piecewise(
149
+ (sign(x)/2 + S(1)/2, Ne(x, 0)), (y, True)), True)
150
+ )
151
+
152
+ assert DiracDelta(y).rewrite(Piecewise) == Piecewise((DiracDelta(0), Eq(y, 0)), (0, True))
153
+ assert DiracDelta(y, 1).rewrite(Piecewise) == DiracDelta(y, 1)
154
+ assert DiracDelta(x - 5).rewrite(Piecewise) == (
155
+ Piecewise((DiracDelta(0), Eq(x - 5, 0)), (0, True)))
156
+
157
+ assert (x*DiracDelta(x - 10)).rewrite(SingularityFunction) == x*SingularityFunction(x, 10, -1)
158
+ assert 5*x*y*DiracDelta(y, 1).rewrite(SingularityFunction) == 5*x*y*SingularityFunction(y, 0, -2)
159
+ assert DiracDelta(0).rewrite(SingularityFunction) == SingularityFunction(0, 0, -1)
160
+ assert DiracDelta(0, 1).rewrite(SingularityFunction) == SingularityFunction(0, 0, -2)
161
+
162
+ assert Heaviside(x).rewrite(SingularityFunction) == SingularityFunction(x, 0, 0)
163
+ assert 5*x*y*Heaviside(y + 1).rewrite(SingularityFunction) == 5*x*y*SingularityFunction(y, -1, 0)
164
+ assert ((x - 3)**3*Heaviside(x - 3)).rewrite(SingularityFunction) == (x - 3)**3*SingularityFunction(x, 3, 0)
165
+ assert Heaviside(0).rewrite(SingularityFunction) == S.Half
env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_error_functions.py ADDED
@@ -0,0 +1,816 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.function import (diff, expand, expand_func)
2
+ from sympy.core import EulerGamma
3
+ from sympy.core.numbers import (E, Float, I, Rational, nan, oo, pi)
4
+ from sympy.core.singleton import S
5
+ from sympy.core.symbol import (Symbol, symbols)
6
+ from sympy.functions.elementary.complexes import (conjugate, im, polar_lift, re)
7
+ from sympy.functions.elementary.exponential import (exp, exp_polar, log)
8
+ from sympy.functions.elementary.hyperbolic import (cosh, sinh)
9
+ from sympy.functions.elementary.miscellaneous import sqrt
10
+ from sympy.functions.elementary.trigonometric import (cos, sin, sinc)
11
+ from sympy.functions.special.error_functions import (Chi, Ci, E1, Ei, Li, Shi, Si, erf, erf2, erf2inv, erfc, erfcinv, erfi, erfinv, expint, fresnelc, fresnels, li)
12
+ from sympy.functions.special.gamma_functions import (gamma, uppergamma)
13
+ from sympy.functions.special.hyper import (hyper, meijerg)
14
+ from sympy.integrals.integrals import (Integral, integrate)
15
+ from sympy.series.gruntz import gruntz
16
+ from sympy.series.limits import limit
17
+ from sympy.series.order import O
18
+ from sympy.core.expr import unchanged
19
+ from sympy.core.function import ArgumentIndexError
20
+ from sympy.functions.special.error_functions import _erfs, _eis
21
+ from sympy.testing.pytest import raises
22
+
23
+ x, y, z = symbols('x,y,z')
24
+ w = Symbol("w", real=True)
25
+ n = Symbol("n", integer=True)
26
+
27
+
28
+ def test_erf():
29
+ assert erf(nan) is nan
30
+
31
+ assert erf(oo) == 1
32
+ assert erf(-oo) == -1
33
+
34
+ assert erf(0) is S.Zero
35
+
36
+ assert erf(I*oo) == oo*I
37
+ assert erf(-I*oo) == -oo*I
38
+
39
+ assert erf(-2) == -erf(2)
40
+ assert erf(-x*y) == -erf(x*y)
41
+ assert erf(-x - y) == -erf(x + y)
42
+
43
+ assert erf(erfinv(x)) == x
44
+ assert erf(erfcinv(x)) == 1 - x
45
+ assert erf(erf2inv(0, x)) == x
46
+ assert erf(erf2inv(0, x, evaluate=False)) == x # To cover code in erf
47
+ assert erf(erf2inv(0, erf(erfcinv(1 - erf(erfinv(x)))))) == x
48
+
49
+ assert erf(I).is_real is False
50
+ assert erf(0, evaluate=False).is_real
51
+ assert erf(0, evaluate=False).is_zero
52
+
53
+ assert conjugate(erf(z)) == erf(conjugate(z))
54
+
55
+ assert erf(x).as_leading_term(x) == 2*x/sqrt(pi)
56
+ assert erf(x*y).as_leading_term(y) == 2*x*y/sqrt(pi)
57
+ assert (erf(x*y)/erf(y)).as_leading_term(y) == x
58
+ assert erf(1/x).as_leading_term(x) == S.One
59
+
60
+ assert erf(z).rewrite('uppergamma') == sqrt(z**2)*(1 - erfc(sqrt(z**2)))/z
61
+ assert erf(z).rewrite('erfc') == S.One - erfc(z)
62
+ assert erf(z).rewrite('erfi') == -I*erfi(I*z)
63
+ assert erf(z).rewrite('fresnels') == (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) -
64
+ I*fresnels(z*(1 - I)/sqrt(pi)))
65
+ assert erf(z).rewrite('fresnelc') == (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) -
66
+ I*fresnels(z*(1 - I)/sqrt(pi)))
67
+ assert erf(z).rewrite('hyper') == 2*z*hyper([S.Half], [3*S.Half], -z**2)/sqrt(pi)
68
+ assert erf(z).rewrite('meijerg') == z*meijerg([S.Half], [], [0], [Rational(-1, 2)], z**2)/sqrt(pi)
69
+ assert erf(z).rewrite('expint') == sqrt(z**2)/z - z*expint(S.Half, z**2)/sqrt(S.Pi)
70
+
71
+ assert limit(exp(x)*exp(x**2)*(erf(x + 1/exp(x)) - erf(x)), x, oo) == \
72
+ 2/sqrt(pi)
73
+ assert limit((1 - erf(z))*exp(z**2)*z, z, oo) == 1/sqrt(pi)
74
+ assert limit((1 - erf(x))*exp(x**2)*sqrt(pi)*x, x, oo) == 1
75
+ assert limit(((1 - erf(x))*exp(x**2)*sqrt(pi)*x - 1)*2*x**2, x, oo) == -1
76
+ assert limit(erf(x)/x, x, 0) == 2/sqrt(pi)
77
+ assert limit(x**(-4) - sqrt(pi)*erf(x**2) / (2*x**6), x, 0) == S(1)/3
78
+
79
+ assert erf(x).as_real_imag() == \
80
+ (erf(re(x) - I*im(x))/2 + erf(re(x) + I*im(x))/2,
81
+ -I*(-erf(re(x) - I*im(x)) + erf(re(x) + I*im(x)))/2)
82
+
83
+ assert erf(x).as_real_imag(deep=False) == \
84
+ (erf(re(x) - I*im(x))/2 + erf(re(x) + I*im(x))/2,
85
+ -I*(-erf(re(x) - I*im(x)) + erf(re(x) + I*im(x)))/2)
86
+
87
+ assert erf(w).as_real_imag() == (erf(w), 0)
88
+ assert erf(w).as_real_imag(deep=False) == (erf(w), 0)
89
+ # issue 13575
90
+ assert erf(I).as_real_imag() == (0, -I*erf(I))
91
+
92
+ raises(ArgumentIndexError, lambda: erf(x).fdiff(2))
93
+
94
+ assert erf(x).inverse() == erfinv
95
+
96
+
97
+ def test_erf_series():
98
+ assert erf(x).series(x, 0, 7) == 2*x/sqrt(pi) - \
99
+ 2*x**3/3/sqrt(pi) + x**5/5/sqrt(pi) + O(x**7)
100
+
101
+ assert erf(x).series(x, oo) == \
102
+ -exp(-x**2)*(3/(4*x**5) - 1/(2*x**3) + 1/x + O(x**(-6), (x, oo)))/sqrt(pi) + 1
103
+ assert erf(x**2).series(x, oo, n=8) == \
104
+ (-1/(2*x**6) + x**(-2) + O(x**(-8), (x, oo)))*exp(-x**4)/sqrt(pi)*-1 + 1
105
+ assert erf(sqrt(x)).series(x, oo, n=3) == (sqrt(1/x) - (1/x)**(S(3)/2)/2\
106
+ + 3*(1/x)**(S(5)/2)/4 + O(x**(-3), (x, oo)))*exp(-x)/sqrt(pi)*-1 + 1
107
+
108
+
109
+ def test_erf_evalf():
110
+ assert abs( erf(Float(2.0)) - 0.995322265 ) < 1E-8 # XXX
111
+
112
+
113
+ def test__erfs():
114
+ assert _erfs(z).diff(z) == -2/sqrt(S.Pi) + 2*z*_erfs(z)
115
+
116
+ assert _erfs(1/z).series(z) == \
117
+ z/sqrt(pi) - z**3/(2*sqrt(pi)) + 3*z**5/(4*sqrt(pi)) + O(z**6)
118
+
119
+ assert expand(erf(z).rewrite('tractable').diff(z).rewrite('intractable')) \
120
+ == erf(z).diff(z)
121
+ assert _erfs(z).rewrite("intractable") == (-erf(z) + 1)*exp(z**2)
122
+ raises(ArgumentIndexError, lambda: _erfs(z).fdiff(2))
123
+
124
+
125
+ def test_erfc():
126
+ assert erfc(nan) is nan
127
+
128
+ assert erfc(oo) is S.Zero
129
+ assert erfc(-oo) == 2
130
+
131
+ assert erfc(0) == 1
132
+
133
+ assert erfc(I*oo) == -oo*I
134
+ assert erfc(-I*oo) == oo*I
135
+
136
+ assert erfc(-x) == S(2) - erfc(x)
137
+ assert erfc(erfcinv(x)) == x
138
+
139
+ assert erfc(I).is_real is False
140
+ assert erfc(0, evaluate=False).is_real
141
+ assert erfc(0, evaluate=False).is_zero is False
142
+
143
+ assert erfc(erfinv(x)) == 1 - x
144
+
145
+ assert conjugate(erfc(z)) == erfc(conjugate(z))
146
+
147
+ assert erfc(x).as_leading_term(x) is S.One
148
+ assert erfc(1/x).as_leading_term(x) == S.Zero
149
+
150
+ assert erfc(z).rewrite('erf') == 1 - erf(z)
151
+ assert erfc(z).rewrite('erfi') == 1 + I*erfi(I*z)
152
+ assert erfc(z).rewrite('fresnels') == 1 - (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) -
153
+ I*fresnels(z*(1 - I)/sqrt(pi)))
154
+ assert erfc(z).rewrite('fresnelc') == 1 - (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) -
155
+ I*fresnels(z*(1 - I)/sqrt(pi)))
156
+ assert erfc(z).rewrite('hyper') == 1 - 2*z*hyper([S.Half], [3*S.Half], -z**2)/sqrt(pi)
157
+ assert erfc(z).rewrite('meijerg') == 1 - z*meijerg([S.Half], [], [0], [Rational(-1, 2)], z**2)/sqrt(pi)
158
+ assert erfc(z).rewrite('uppergamma') == 1 - sqrt(z**2)*(1 - erfc(sqrt(z**2)))/z
159
+ assert erfc(z).rewrite('expint') == S.One - sqrt(z**2)/z + z*expint(S.Half, z**2)/sqrt(S.Pi)
160
+ assert erfc(z).rewrite('tractable') == _erfs(z)*exp(-z**2)
161
+ assert expand_func(erf(x) + erfc(x)) is S.One
162
+
163
+ assert erfc(x).as_real_imag() == \
164
+ (erfc(re(x) - I*im(x))/2 + erfc(re(x) + I*im(x))/2,
165
+ -I*(-erfc(re(x) - I*im(x)) + erfc(re(x) + I*im(x)))/2)
166
+
167
+ assert erfc(x).as_real_imag(deep=False) == \
168
+ (erfc(re(x) - I*im(x))/2 + erfc(re(x) + I*im(x))/2,
169
+ -I*(-erfc(re(x) - I*im(x)) + erfc(re(x) + I*im(x)))/2)
170
+
171
+ assert erfc(w).as_real_imag() == (erfc(w), 0)
172
+ assert erfc(w).as_real_imag(deep=False) == (erfc(w), 0)
173
+ raises(ArgumentIndexError, lambda: erfc(x).fdiff(2))
174
+
175
+ assert erfc(x).inverse() == erfcinv
176
+
177
+
178
+ def test_erfc_series():
179
+ assert erfc(x).series(x, 0, 7) == 1 - 2*x/sqrt(pi) + \
180
+ 2*x**3/3/sqrt(pi) - x**5/5/sqrt(pi) + O(x**7)
181
+
182
+ assert erfc(x).series(x, oo) == \
183
+ (3/(4*x**5) - 1/(2*x**3) + 1/x + O(x**(-6), (x, oo)))*exp(-x**2)/sqrt(pi)
184
+
185
+
186
+ def test_erfc_evalf():
187
+ assert abs( erfc(Float(2.0)) - 0.00467773 ) < 1E-8 # XXX
188
+
189
+
190
+ def test_erfi():
191
+ assert erfi(nan) is nan
192
+
193
+ assert erfi(oo) is S.Infinity
194
+ assert erfi(-oo) is S.NegativeInfinity
195
+
196
+ assert erfi(0) is S.Zero
197
+
198
+ assert erfi(I*oo) == I
199
+ assert erfi(-I*oo) == -I
200
+
201
+ assert erfi(-x) == -erfi(x)
202
+
203
+ assert erfi(I*erfinv(x)) == I*x
204
+ assert erfi(I*erfcinv(x)) == I*(1 - x)
205
+ assert erfi(I*erf2inv(0, x)) == I*x
206
+ assert erfi(I*erf2inv(0, x, evaluate=False)) == I*x # To cover code in erfi
207
+
208
+ assert erfi(I).is_real is False
209
+ assert erfi(0, evaluate=False).is_real
210
+ assert erfi(0, evaluate=False).is_zero
211
+
212
+ assert conjugate(erfi(z)) == erfi(conjugate(z))
213
+
214
+ assert erfi(x).as_leading_term(x) == 2*x/sqrt(pi)
215
+ assert erfi(x*y).as_leading_term(y) == 2*x*y/sqrt(pi)
216
+ assert (erfi(x*y)/erfi(y)).as_leading_term(y) == x
217
+ assert erfi(1/x).as_leading_term(x) == erfi(1/x)
218
+
219
+ assert erfi(z).rewrite('erf') == -I*erf(I*z)
220
+ assert erfi(z).rewrite('erfc') == I*erfc(I*z) - I
221
+ assert erfi(z).rewrite('fresnels') == (1 - I)*(fresnelc(z*(1 + I)/sqrt(pi)) -
222
+ I*fresnels(z*(1 + I)/sqrt(pi)))
223
+ assert erfi(z).rewrite('fresnelc') == (1 - I)*(fresnelc(z*(1 + I)/sqrt(pi)) -
224
+ I*fresnels(z*(1 + I)/sqrt(pi)))
225
+ assert erfi(z).rewrite('hyper') == 2*z*hyper([S.Half], [3*S.Half], z**2)/sqrt(pi)
226
+ assert erfi(z).rewrite('meijerg') == z*meijerg([S.Half], [], [0], [Rational(-1, 2)], -z**2)/sqrt(pi)
227
+ assert erfi(z).rewrite('uppergamma') == (sqrt(-z**2)/z*(uppergamma(S.Half,
228
+ -z**2)/sqrt(S.Pi) - S.One))
229
+ assert erfi(z).rewrite('expint') == sqrt(-z**2)/z - z*expint(S.Half, -z**2)/sqrt(S.Pi)
230
+ assert erfi(z).rewrite('tractable') == -I*(-_erfs(I*z)*exp(z**2) + 1)
231
+ assert expand_func(erfi(I*z)) == I*erf(z)
232
+
233
+ assert erfi(x).as_real_imag() == \
234
+ (erfi(re(x) - I*im(x))/2 + erfi(re(x) + I*im(x))/2,
235
+ -I*(-erfi(re(x) - I*im(x)) + erfi(re(x) + I*im(x)))/2)
236
+ assert erfi(x).as_real_imag(deep=False) == \
237
+ (erfi(re(x) - I*im(x))/2 + erfi(re(x) + I*im(x))/2,
238
+ -I*(-erfi(re(x) - I*im(x)) + erfi(re(x) + I*im(x)))/2)
239
+
240
+ assert erfi(w).as_real_imag() == (erfi(w), 0)
241
+ assert erfi(w).as_real_imag(deep=False) == (erfi(w), 0)
242
+
243
+ raises(ArgumentIndexError, lambda: erfi(x).fdiff(2))
244
+
245
+
246
+ def test_erfi_series():
247
+ assert erfi(x).series(x, 0, 7) == 2*x/sqrt(pi) + \
248
+ 2*x**3/3/sqrt(pi) + x**5/5/sqrt(pi) + O(x**7)
249
+
250
+ assert erfi(x).series(x, oo) == \
251
+ (3/(4*x**5) + 1/(2*x**3) + 1/x + O(x**(-6), (x, oo)))*exp(x**2)/sqrt(pi) - I
252
+
253
+
254
+ def test_erfi_evalf():
255
+ assert abs( erfi(Float(2.0)) - 18.5648024145756 ) < 1E-13 # XXX
256
+
257
+
258
+ def test_erf2():
259
+
260
+ assert erf2(0, 0) is S.Zero
261
+ assert erf2(x, x) is S.Zero
262
+ assert erf2(nan, 0) is nan
263
+
264
+ assert erf2(-oo, y) == erf(y) + 1
265
+ assert erf2( oo, y) == erf(y) - 1
266
+ assert erf2( x, oo) == 1 - erf(x)
267
+ assert erf2( x,-oo) == -1 - erf(x)
268
+ assert erf2(x, erf2inv(x, y)) == y
269
+
270
+ assert erf2(-x, -y) == -erf2(x,y)
271
+ assert erf2(-x, y) == erf(y) + erf(x)
272
+ assert erf2( x, -y) == -erf(y) - erf(x)
273
+ assert erf2(x, y).rewrite('fresnels') == erf(y).rewrite(fresnels)-erf(x).rewrite(fresnels)
274
+ assert erf2(x, y).rewrite('fresnelc') == erf(y).rewrite(fresnelc)-erf(x).rewrite(fresnelc)
275
+ assert erf2(x, y).rewrite('hyper') == erf(y).rewrite(hyper)-erf(x).rewrite(hyper)
276
+ assert erf2(x, y).rewrite('meijerg') == erf(y).rewrite(meijerg)-erf(x).rewrite(meijerg)
277
+ assert erf2(x, y).rewrite('uppergamma') == erf(y).rewrite(uppergamma) - erf(x).rewrite(uppergamma)
278
+ assert erf2(x, y).rewrite('expint') == erf(y).rewrite(expint)-erf(x).rewrite(expint)
279
+
280
+ assert erf2(I, 0).is_real is False
281
+ assert erf2(0, 0, evaluate=False).is_real
282
+ assert erf2(0, 0, evaluate=False).is_zero
283
+ assert erf2(x, x, evaluate=False).is_zero
284
+ assert erf2(x, y).is_zero is None
285
+
286
+ assert expand_func(erf(x) + erf2(x, y)) == erf(y)
287
+
288
+ assert conjugate(erf2(x, y)) == erf2(conjugate(x), conjugate(y))
289
+
290
+ assert erf2(x, y).rewrite('erf') == erf(y) - erf(x)
291
+ assert erf2(x, y).rewrite('erfc') == erfc(x) - erfc(y)
292
+ assert erf2(x, y).rewrite('erfi') == I*(erfi(I*x) - erfi(I*y))
293
+
294
+ assert erf2(x, y).diff(x) == erf2(x, y).fdiff(1)
295
+ assert erf2(x, y).diff(y) == erf2(x, y).fdiff(2)
296
+ assert erf2(x, y).diff(x) == -2*exp(-x**2)/sqrt(pi)
297
+ assert erf2(x, y).diff(y) == 2*exp(-y**2)/sqrt(pi)
298
+ raises(ArgumentIndexError, lambda: erf2(x, y).fdiff(3))
299
+
300
+ assert erf2(x, y).is_extended_real is None
301
+ xr, yr = symbols('xr yr', extended_real=True)
302
+ assert erf2(xr, yr).is_extended_real is True
303
+
304
+
305
+ def test_erfinv():
306
+ assert erfinv(0) is S.Zero
307
+ assert erfinv(1) is S.Infinity
308
+ assert erfinv(nan) is S.NaN
309
+ assert erfinv(-1) is S.NegativeInfinity
310
+
311
+ assert erfinv(erf(w)) == w
312
+ assert erfinv(erf(-w)) == -w
313
+
314
+ assert erfinv(x).diff() == sqrt(pi)*exp(erfinv(x)**2)/2
315
+ raises(ArgumentIndexError, lambda: erfinv(x).fdiff(2))
316
+
317
+ assert erfinv(z).rewrite('erfcinv') == erfcinv(1-z)
318
+ assert erfinv(z).inverse() == erf
319
+
320
+
321
+ def test_erfinv_evalf():
322
+ assert abs( erfinv(Float(0.2)) - 0.179143454621292 ) < 1E-13
323
+
324
+
325
+ def test_erfcinv():
326
+ assert erfcinv(1) is S.Zero
327
+ assert erfcinv(0) is S.Infinity
328
+ assert erfcinv(nan) is S.NaN
329
+
330
+ assert erfcinv(x).diff() == -sqrt(pi)*exp(erfcinv(x)**2)/2
331
+ raises(ArgumentIndexError, lambda: erfcinv(x).fdiff(2))
332
+
333
+ assert erfcinv(z).rewrite('erfinv') == erfinv(1-z)
334
+ assert erfcinv(z).inverse() == erfc
335
+
336
+
337
+ def test_erf2inv():
338
+ assert erf2inv(0, 0) is S.Zero
339
+ assert erf2inv(0, 1) is S.Infinity
340
+ assert erf2inv(1, 0) is S.One
341
+ assert erf2inv(0, y) == erfinv(y)
342
+ assert erf2inv(oo, y) == erfcinv(-y)
343
+ assert erf2inv(x, 0) == x
344
+ assert erf2inv(x, oo) == erfinv(x)
345
+ assert erf2inv(nan, 0) is nan
346
+ assert erf2inv(0, nan) is nan
347
+
348
+ assert erf2inv(x, y).diff(x) == exp(-x**2 + erf2inv(x, y)**2)
349
+ assert erf2inv(x, y).diff(y) == sqrt(pi)*exp(erf2inv(x, y)**2)/2
350
+ raises(ArgumentIndexError, lambda: erf2inv(x, y).fdiff(3))
351
+
352
+
353
+ # NOTE we multiply by exp_polar(I*pi) and need this to be on the principal
354
+ # branch, hence take x in the lower half plane (d=0).
355
+
356
+
357
+ def mytn(expr1, expr2, expr3, x, d=0):
358
+ from sympy.core.random import verify_numerically, random_complex_number
359
+ subs = {}
360
+ for a in expr1.free_symbols:
361
+ if a != x:
362
+ subs[a] = random_complex_number()
363
+ return expr2 == expr3 and verify_numerically(expr1.subs(subs),
364
+ expr2.subs(subs), x, d=d)
365
+
366
+
367
+ def mytd(expr1, expr2, x):
368
+ from sympy.core.random import test_derivative_numerically, \
369
+ random_complex_number
370
+ subs = {}
371
+ for a in expr1.free_symbols:
372
+ if a != x:
373
+ subs[a] = random_complex_number()
374
+ return expr1.diff(x) == expr2 and test_derivative_numerically(expr1.subs(subs), x)
375
+
376
+
377
+ def tn_branch(func, s=None):
378
+ from sympy.core.random import uniform
379
+
380
+ def fn(x):
381
+ if s is None:
382
+ return func(x)
383
+ return func(s, x)
384
+ c = uniform(1, 5)
385
+ expr = fn(c*exp_polar(I*pi)) - fn(c*exp_polar(-I*pi))
386
+ eps = 1e-15
387
+ expr2 = fn(-c + eps*I) - fn(-c - eps*I)
388
+ return abs(expr.n() - expr2.n()).n() < 1e-10
389
+
390
+
391
+ def test_ei():
392
+ assert Ei(0) is S.NegativeInfinity
393
+ assert Ei(oo) is S.Infinity
394
+ assert Ei(-oo) is S.Zero
395
+
396
+ assert tn_branch(Ei)
397
+ assert mytd(Ei(x), exp(x)/x, x)
398
+ assert mytn(Ei(x), Ei(x).rewrite(uppergamma),
399
+ -uppergamma(0, x*polar_lift(-1)) - I*pi, x)
400
+ assert mytn(Ei(x), Ei(x).rewrite(expint),
401
+ -expint(1, x*polar_lift(-1)) - I*pi, x)
402
+ assert Ei(x).rewrite(expint).rewrite(Ei) == Ei(x)
403
+ assert Ei(x*exp_polar(2*I*pi)) == Ei(x) + 2*I*pi
404
+ assert Ei(x*exp_polar(-2*I*pi)) == Ei(x) - 2*I*pi
405
+
406
+ assert mytn(Ei(x), Ei(x).rewrite(Shi), Chi(x) + Shi(x), x)
407
+ assert mytn(Ei(x*polar_lift(I)), Ei(x*polar_lift(I)).rewrite(Si),
408
+ Ci(x) + I*Si(x) + I*pi/2, x)
409
+
410
+ assert Ei(log(x)).rewrite(li) == li(x)
411
+ assert Ei(2*log(x)).rewrite(li) == li(x**2)
412
+
413
+ assert gruntz(Ei(x+exp(-x))*exp(-x)*x, x, oo) == 1
414
+
415
+ assert Ei(x).series(x) == EulerGamma + log(x) + x + x**2/4 + \
416
+ x**3/18 + x**4/96 + x**5/600 + O(x**6)
417
+ assert Ei(x).series(x, 1, 3) == Ei(1) + E*(x - 1) + O((x - 1)**3, (x, 1))
418
+ assert Ei(x).series(x, oo) == \
419
+ (120/x**5 + 24/x**4 + 6/x**3 + 2/x**2 + 1/x + 1 + O(x**(-6), (x, oo)))*exp(x)/x
420
+
421
+ assert str(Ei(cos(2)).evalf(n=10)) == '-0.6760647401'
422
+ raises(ArgumentIndexError, lambda: Ei(x).fdiff(2))
423
+
424
+
425
+ def test_expint():
426
+ assert mytn(expint(x, y), expint(x, y).rewrite(uppergamma),
427
+ y**(x - 1)*uppergamma(1 - x, y), x)
428
+ assert mytd(
429
+ expint(x, y), -y**(x - 1)*meijerg([], [1, 1], [0, 0, 1 - x], [], y), x)
430
+ assert mytd(expint(x, y), -expint(x - 1, y), y)
431
+ assert mytn(expint(1, x), expint(1, x).rewrite(Ei),
432
+ -Ei(x*polar_lift(-1)) + I*pi, x)
433
+
434
+ assert expint(-4, x) == exp(-x)/x + 4*exp(-x)/x**2 + 12*exp(-x)/x**3 \
435
+ + 24*exp(-x)/x**4 + 24*exp(-x)/x**5
436
+ assert expint(Rational(-3, 2), x) == \
437
+ exp(-x)/x + 3*exp(-x)/(2*x**2) + 3*sqrt(pi)*erfc(sqrt(x))/(4*x**S('5/2'))
438
+
439
+ assert tn_branch(expint, 1)
440
+ assert tn_branch(expint, 2)
441
+ assert tn_branch(expint, 3)
442
+ assert tn_branch(expint, 1.7)
443
+ assert tn_branch(expint, pi)
444
+
445
+ assert expint(y, x*exp_polar(2*I*pi)) == \
446
+ x**(y - 1)*(exp(2*I*pi*y) - 1)*gamma(-y + 1) + expint(y, x)
447
+ assert expint(y, x*exp_polar(-2*I*pi)) == \
448
+ x**(y - 1)*(exp(-2*I*pi*y) - 1)*gamma(-y + 1) + expint(y, x)
449
+ assert expint(2, x*exp_polar(2*I*pi)) == 2*I*pi*x + expint(2, x)
450
+ assert expint(2, x*exp_polar(-2*I*pi)) == -2*I*pi*x + expint(2, x)
451
+ assert expint(1, x).rewrite(Ei).rewrite(expint) == expint(1, x)
452
+ assert expint(x, y).rewrite(Ei) == expint(x, y)
453
+ assert expint(x, y).rewrite(Ci) == expint(x, y)
454
+
455
+ assert mytn(E1(x), E1(x).rewrite(Shi), Shi(x) - Chi(x), x)
456
+ assert mytn(E1(polar_lift(I)*x), E1(polar_lift(I)*x).rewrite(Si),
457
+ -Ci(x) + I*Si(x) - I*pi/2, x)
458
+
459
+ assert mytn(expint(2, x), expint(2, x).rewrite(Ei).rewrite(expint),
460
+ -x*E1(x) + exp(-x), x)
461
+ assert mytn(expint(3, x), expint(3, x).rewrite(Ei).rewrite(expint),
462
+ x**2*E1(x)/2 + (1 - x)*exp(-x)/2, x)
463
+
464
+ assert expint(Rational(3, 2), z).nseries(z) == \
465
+ 2 + 2*z - z**2/3 + z**3/15 - z**4/84 + z**5/540 - \
466
+ 2*sqrt(pi)*sqrt(z) + O(z**6)
467
+
468
+ assert E1(z).series(z) == -EulerGamma - log(z) + z - \
469
+ z**2/4 + z**3/18 - z**4/96 + z**5/600 + O(z**6)
470
+
471
+ assert expint(4, z).series(z) == Rational(1, 3) - z/2 + z**2/2 + \
472
+ z**3*(log(z)/6 - Rational(11, 36) + EulerGamma/6 - I*pi/6) - z**4/24 + \
473
+ z**5/240 + O(z**6)
474
+
475
+ assert expint(n, x).series(x, oo, n=3) == \
476
+ (n*(n + 1)/x**2 - n/x + 1 + O(x**(-3), (x, oo)))*exp(-x)/x
477
+
478
+ assert expint(z, y).series(z, 0, 2) == exp(-y)/y - z*meijerg(((), (1, 1)),
479
+ ((0, 0, 1), ()), y)/y + O(z**2)
480
+ raises(ArgumentIndexError, lambda: expint(x, y).fdiff(3))
481
+
482
+ neg = Symbol('neg', negative=True)
483
+ assert Ei(neg).rewrite(Si) == Shi(neg) + Chi(neg) - I*pi
484
+
485
+
486
+ def test__eis():
487
+ assert _eis(z).diff(z) == -_eis(z) + 1/z
488
+
489
+ assert _eis(1/z).series(z) == \
490
+ z + z**2 + 2*z**3 + 6*z**4 + 24*z**5 + O(z**6)
491
+
492
+ assert Ei(z).rewrite('tractable') == exp(z)*_eis(z)
493
+ assert li(z).rewrite('tractable') == z*_eis(log(z))
494
+
495
+ assert _eis(z).rewrite('intractable') == exp(-z)*Ei(z)
496
+
497
+ assert expand(li(z).rewrite('tractable').diff(z).rewrite('intractable')) \
498
+ == li(z).diff(z)
499
+
500
+ assert expand(Ei(z).rewrite('tractable').diff(z).rewrite('intractable')) \
501
+ == Ei(z).diff(z)
502
+
503
+ assert _eis(z).series(z, n=3) == EulerGamma + log(z) + z*(-log(z) - \
504
+ EulerGamma + 1) + z**2*(log(z)/2 - Rational(3, 4) + EulerGamma/2)\
505
+ + O(z**3*log(z))
506
+ raises(ArgumentIndexError, lambda: _eis(z).fdiff(2))
507
+
508
+
509
+ def tn_arg(func):
510
+ def test(arg, e1, e2):
511
+ from sympy.core.random import uniform
512
+ v = uniform(1, 5)
513
+ v1 = func(arg*x).subs(x, v).n()
514
+ v2 = func(e1*v + e2*1e-15).n()
515
+ return abs(v1 - v2).n() < 1e-10
516
+ return test(exp_polar(I*pi/2), I, 1) and \
517
+ test(exp_polar(-I*pi/2), -I, 1) and \
518
+ test(exp_polar(I*pi), -1, I) and \
519
+ test(exp_polar(-I*pi), -1, -I)
520
+
521
+
522
+ def test_li():
523
+ z = Symbol("z")
524
+ zr = Symbol("z", real=True)
525
+ zp = Symbol("z", positive=True)
526
+ zn = Symbol("z", negative=True)
527
+
528
+ assert li(0) is S.Zero
529
+ assert li(1) is -oo
530
+ assert li(oo) is oo
531
+
532
+ assert isinstance(li(z), li)
533
+ assert unchanged(li, -zp)
534
+ assert unchanged(li, zn)
535
+
536
+ assert diff(li(z), z) == 1/log(z)
537
+
538
+ assert conjugate(li(z)) == li(conjugate(z))
539
+ assert conjugate(li(-zr)) == li(-zr)
540
+ assert unchanged(conjugate, li(-zp))
541
+ assert unchanged(conjugate, li(zn))
542
+
543
+ assert li(z).rewrite(Li) == Li(z) + li(2)
544
+ assert li(z).rewrite(Ei) == Ei(log(z))
545
+ assert li(z).rewrite(uppergamma) == (-log(1/log(z))/2 - log(-log(z)) +
546
+ log(log(z))/2 - expint(1, -log(z)))
547
+ assert li(z).rewrite(Si) == (-log(I*log(z)) - log(1/log(z))/2 +
548
+ log(log(z))/2 + Ci(I*log(z)) + Shi(log(z)))
549
+ assert li(z).rewrite(Ci) == (-log(I*log(z)) - log(1/log(z))/2 +
550
+ log(log(z))/2 + Ci(I*log(z)) + Shi(log(z)))
551
+ assert li(z).rewrite(Shi) == (-log(1/log(z))/2 + log(log(z))/2 +
552
+ Chi(log(z)) - Shi(log(z)))
553
+ assert li(z).rewrite(Chi) == (-log(1/log(z))/2 + log(log(z))/2 +
554
+ Chi(log(z)) - Shi(log(z)))
555
+ assert li(z).rewrite(hyper) ==(log(z)*hyper((1, 1), (2, 2), log(z)) -
556
+ log(1/log(z))/2 + log(log(z))/2 + EulerGamma)
557
+ assert li(z).rewrite(meijerg) == (-log(1/log(z))/2 - log(-log(z)) + log(log(z))/2 -
558
+ meijerg(((), (1,)), ((0, 0), ()), -log(z)))
559
+
560
+ assert gruntz(1/li(z), z, oo) is S.Zero
561
+ assert li(z).series(z) == log(z)**5/600 + log(z)**4/96 + log(z)**3/18 + log(z)**2/4 + \
562
+ log(z) + log(log(z)) + EulerGamma
563
+ raises(ArgumentIndexError, lambda: li(z).fdiff(2))
564
+
565
+
566
+ def test_Li():
567
+ assert Li(2) is S.Zero
568
+ assert Li(oo) is oo
569
+
570
+ assert isinstance(Li(z), Li)
571
+
572
+ assert diff(Li(z), z) == 1/log(z)
573
+
574
+ assert gruntz(1/Li(z), z, oo) is S.Zero
575
+ assert Li(z).rewrite(li) == li(z) - li(2)
576
+ assert Li(z).series(z) == \
577
+ log(z)**5/600 + log(z)**4/96 + log(z)**3/18 + log(z)**2/4 + log(z) + log(log(z)) - li(2) + EulerGamma
578
+ raises(ArgumentIndexError, lambda: Li(z).fdiff(2))
579
+
580
+
581
+ def test_si():
582
+ assert Si(I*x) == I*Shi(x)
583
+ assert Shi(I*x) == I*Si(x)
584
+ assert Si(-I*x) == -I*Shi(x)
585
+ assert Shi(-I*x) == -I*Si(x)
586
+ assert Si(-x) == -Si(x)
587
+ assert Shi(-x) == -Shi(x)
588
+ assert Si(exp_polar(2*pi*I)*x) == Si(x)
589
+ assert Si(exp_polar(-2*pi*I)*x) == Si(x)
590
+ assert Shi(exp_polar(2*pi*I)*x) == Shi(x)
591
+ assert Shi(exp_polar(-2*pi*I)*x) == Shi(x)
592
+
593
+ assert Si(oo) == pi/2
594
+ assert Si(-oo) == -pi/2
595
+ assert Shi(oo) is oo
596
+ assert Shi(-oo) is -oo
597
+
598
+ assert mytd(Si(x), sin(x)/x, x)
599
+ assert mytd(Shi(x), sinh(x)/x, x)
600
+
601
+ assert mytn(Si(x), Si(x).rewrite(Ei),
602
+ -I*(-Ei(x*exp_polar(-I*pi/2))/2
603
+ + Ei(x*exp_polar(I*pi/2))/2 - I*pi) + pi/2, x)
604
+ assert mytn(Si(x), Si(x).rewrite(expint),
605
+ -I*(-expint(1, x*exp_polar(-I*pi/2))/2 +
606
+ expint(1, x*exp_polar(I*pi/2))/2) + pi/2, x)
607
+ assert mytn(Shi(x), Shi(x).rewrite(Ei),
608
+ Ei(x)/2 - Ei(x*exp_polar(I*pi))/2 + I*pi/2, x)
609
+ assert mytn(Shi(x), Shi(x).rewrite(expint),
610
+ expint(1, x)/2 - expint(1, x*exp_polar(I*pi))/2 - I*pi/2, x)
611
+
612
+ assert tn_arg(Si)
613
+ assert tn_arg(Shi)
614
+
615
+ assert Si(x).nseries(x, n=8) == \
616
+ x - x**3/18 + x**5/600 - x**7/35280 + O(x**9)
617
+ assert Shi(x).nseries(x, n=8) == \
618
+ x + x**3/18 + x**5/600 + x**7/35280 + O(x**9)
619
+ assert Si(sin(x)).nseries(x, n=5) == x - 2*x**3/9 + 17*x**5/450 + O(x**6)
620
+ assert Si(x).nseries(x, 1, n=3) == \
621
+ Si(1) + (x - 1)*sin(1) + (x - 1)**2*(-sin(1)/2 + cos(1)/2) + O((x - 1)**3, (x, 1))
622
+
623
+ assert Si(x).series(x, oo) == pi/2 - (- 6/x**3 + 1/x \
624
+ + O(x**(-7), (x, oo)))*sin(x)/x - (24/x**4 - 2/x**2 + 1 \
625
+ + O(x**(-7), (x, oo)))*cos(x)/x
626
+
627
+ t = Symbol('t', Dummy=True)
628
+ assert Si(x).rewrite(sinc) == Integral(sinc(t), (t, 0, x))
629
+
630
+ assert limit(Shi(x), x, S.Infinity) == S.Infinity
631
+ assert limit(Shi(x), x, S.NegativeInfinity) == S.NegativeInfinity
632
+
633
+
634
+ def test_ci():
635
+ m1 = exp_polar(I*pi)
636
+ m1_ = exp_polar(-I*pi)
637
+ pI = exp_polar(I*pi/2)
638
+ mI = exp_polar(-I*pi/2)
639
+
640
+ assert Ci(m1*x) == Ci(x) + I*pi
641
+ assert Ci(m1_*x) == Ci(x) - I*pi
642
+ assert Ci(pI*x) == Chi(x) + I*pi/2
643
+ assert Ci(mI*x) == Chi(x) - I*pi/2
644
+ assert Chi(m1*x) == Chi(x) + I*pi
645
+ assert Chi(m1_*x) == Chi(x) - I*pi
646
+ assert Chi(pI*x) == Ci(x) + I*pi/2
647
+ assert Chi(mI*x) == Ci(x) - I*pi/2
648
+ assert Ci(exp_polar(2*I*pi)*x) == Ci(x) + 2*I*pi
649
+ assert Chi(exp_polar(-2*I*pi)*x) == Chi(x) - 2*I*pi
650
+ assert Chi(exp_polar(2*I*pi)*x) == Chi(x) + 2*I*pi
651
+ assert Ci(exp_polar(-2*I*pi)*x) == Ci(x) - 2*I*pi
652
+
653
+ assert Ci(oo) is S.Zero
654
+ assert Ci(-oo) == I*pi
655
+ assert Chi(oo) is oo
656
+ assert Chi(-oo) is oo
657
+
658
+ assert mytd(Ci(x), cos(x)/x, x)
659
+ assert mytd(Chi(x), cosh(x)/x, x)
660
+
661
+ assert mytn(Ci(x), Ci(x).rewrite(Ei),
662
+ Ei(x*exp_polar(-I*pi/2))/2 + Ei(x*exp_polar(I*pi/2))/2, x)
663
+ assert mytn(Chi(x), Chi(x).rewrite(Ei),
664
+ Ei(x)/2 + Ei(x*exp_polar(I*pi))/2 - I*pi/2, x)
665
+
666
+ assert tn_arg(Ci)
667
+ assert tn_arg(Chi)
668
+
669
+ assert Ci(x).nseries(x, n=4) == \
670
+ EulerGamma + log(x) - x**2/4 + x**4/96 + O(x**5)
671
+ assert Chi(x).nseries(x, n=4) == \
672
+ EulerGamma + log(x) + x**2/4 + x**4/96 + O(x**5)
673
+
674
+ assert Ci(x).series(x, oo) == -cos(x)*(-6/x**3 + 1/x \
675
+ + O(x**(-7), (x, oo)))/x + (24/x**4 - 2/x**2 + 1 \
676
+ + O(x**(-7), (x, oo)))*sin(x)/x
677
+ assert limit(log(x) - Ci(2*x), x, 0) == -log(2) - EulerGamma
678
+ assert Ci(x).rewrite(uppergamma) == -expint(1, x*exp_polar(-I*pi/2))/2 -\
679
+ expint(1, x*exp_polar(I*pi/2))/2
680
+ assert Ci(x).rewrite(expint) == -expint(1, x*exp_polar(-I*pi/2))/2 -\
681
+ expint(1, x*exp_polar(I*pi/2))/2
682
+ raises(ArgumentIndexError, lambda: Ci(x).fdiff(2))
683
+
684
+
685
+ def test_fresnel():
686
+ assert fresnels(0) is S.Zero
687
+ assert fresnels(oo) is S.Half
688
+ assert fresnels(-oo) == Rational(-1, 2)
689
+ assert fresnels(I*oo) == -I*S.Half
690
+
691
+ assert unchanged(fresnels, z)
692
+ assert fresnels(-z) == -fresnels(z)
693
+ assert fresnels(I*z) == -I*fresnels(z)
694
+ assert fresnels(-I*z) == I*fresnels(z)
695
+
696
+ assert conjugate(fresnels(z)) == fresnels(conjugate(z))
697
+
698
+ assert fresnels(z).diff(z) == sin(pi*z**2/2)
699
+
700
+ assert fresnels(z).rewrite(erf) == (S.One + I)/4 * (
701
+ erf((S.One + I)/2*sqrt(pi)*z) - I*erf((S.One - I)/2*sqrt(pi)*z))
702
+
703
+ assert fresnels(z).rewrite(hyper) == \
704
+ pi*z**3/6 * hyper([Rational(3, 4)], [Rational(3, 2), Rational(7, 4)], -pi**2*z**4/16)
705
+
706
+ assert fresnels(z).series(z, n=15) == \
707
+ pi*z**3/6 - pi**3*z**7/336 + pi**5*z**11/42240 + O(z**15)
708
+
709
+ assert fresnels(w).is_extended_real is True
710
+ assert fresnels(w).is_finite is True
711
+
712
+ assert fresnels(z).is_extended_real is None
713
+ assert fresnels(z).is_finite is None
714
+
715
+ assert fresnels(z).as_real_imag() == (fresnels(re(z) - I*im(z))/2 +
716
+ fresnels(re(z) + I*im(z))/2,
717
+ -I*(-fresnels(re(z) - I*im(z)) + fresnels(re(z) + I*im(z)))/2)
718
+
719
+ assert fresnels(z).as_real_imag(deep=False) == (fresnels(re(z) - I*im(z))/2 +
720
+ fresnels(re(z) + I*im(z))/2,
721
+ -I*(-fresnels(re(z) - I*im(z)) + fresnels(re(z) + I*im(z)))/2)
722
+
723
+ assert fresnels(w).as_real_imag() == (fresnels(w), 0)
724
+ assert fresnels(w).as_real_imag(deep=True) == (fresnels(w), 0)
725
+
726
+ assert fresnels(2 + 3*I).as_real_imag() == (
727
+ fresnels(2 + 3*I)/2 + fresnels(2 - 3*I)/2,
728
+ -I*(fresnels(2 + 3*I) - fresnels(2 - 3*I))/2
729
+ )
730
+
731
+ assert expand_func(integrate(fresnels(z), z)) == \
732
+ z*fresnels(z) + cos(pi*z**2/2)/pi
733
+
734
+ assert fresnels(z).rewrite(meijerg) == sqrt(2)*pi*z**Rational(9, 4) * \
735
+ meijerg(((), (1,)), ((Rational(3, 4),),
736
+ (Rational(1, 4), 0)), -pi**2*z**4/16)/(2*(-z)**Rational(3, 4)*(z**2)**Rational(3, 4))
737
+
738
+ assert fresnelc(0) is S.Zero
739
+ assert fresnelc(oo) == S.Half
740
+ assert fresnelc(-oo) == Rational(-1, 2)
741
+ assert fresnelc(I*oo) == I*S.Half
742
+
743
+ assert unchanged(fresnelc, z)
744
+ assert fresnelc(-z) == -fresnelc(z)
745
+ assert fresnelc(I*z) == I*fresnelc(z)
746
+ assert fresnelc(-I*z) == -I*fresnelc(z)
747
+
748
+ assert conjugate(fresnelc(z)) == fresnelc(conjugate(z))
749
+
750
+ assert fresnelc(z).diff(z) == cos(pi*z**2/2)
751
+
752
+ assert fresnelc(z).rewrite(erf) == (S.One - I)/4 * (
753
+ erf((S.One + I)/2*sqrt(pi)*z) + I*erf((S.One - I)/2*sqrt(pi)*z))
754
+
755
+ assert fresnelc(z).rewrite(hyper) == \
756
+ z * hyper([Rational(1, 4)], [S.Half, Rational(5, 4)], -pi**2*z**4/16)
757
+
758
+ assert fresnelc(w).is_extended_real is True
759
+
760
+ assert fresnelc(z).as_real_imag() == \
761
+ (fresnelc(re(z) - I*im(z))/2 + fresnelc(re(z) + I*im(z))/2,
762
+ -I*(-fresnelc(re(z) - I*im(z)) + fresnelc(re(z) + I*im(z)))/2)
763
+
764
+ assert fresnelc(z).as_real_imag(deep=False) == \
765
+ (fresnelc(re(z) - I*im(z))/2 + fresnelc(re(z) + I*im(z))/2,
766
+ -I*(-fresnelc(re(z) - I*im(z)) + fresnelc(re(z) + I*im(z)))/2)
767
+
768
+ assert fresnelc(2 + 3*I).as_real_imag() == (
769
+ fresnelc(2 - 3*I)/2 + fresnelc(2 + 3*I)/2,
770
+ -I*(fresnelc(2 + 3*I) - fresnelc(2 - 3*I))/2
771
+ )
772
+
773
+ assert expand_func(integrate(fresnelc(z), z)) == \
774
+ z*fresnelc(z) - sin(pi*z**2/2)/pi
775
+
776
+ assert fresnelc(z).rewrite(meijerg) == sqrt(2)*pi*z**Rational(3, 4) * \
777
+ meijerg(((), (1,)), ((Rational(1, 4),),
778
+ (Rational(3, 4), 0)), -pi**2*z**4/16)/(2*(-z)**Rational(1, 4)*(z**2)**Rational(1, 4))
779
+
780
+ from sympy.core.random import verify_numerically
781
+
782
+ verify_numerically(re(fresnels(z)), fresnels(z).as_real_imag()[0], z)
783
+ verify_numerically(im(fresnels(z)), fresnels(z).as_real_imag()[1], z)
784
+ verify_numerically(fresnels(z), fresnels(z).rewrite(hyper), z)
785
+ verify_numerically(fresnels(z), fresnels(z).rewrite(meijerg), z)
786
+
787
+ verify_numerically(re(fresnelc(z)), fresnelc(z).as_real_imag()[0], z)
788
+ verify_numerically(im(fresnelc(z)), fresnelc(z).as_real_imag()[1], z)
789
+ verify_numerically(fresnelc(z), fresnelc(z).rewrite(hyper), z)
790
+ verify_numerically(fresnelc(z), fresnelc(z).rewrite(meijerg), z)
791
+
792
+ raises(ArgumentIndexError, lambda: fresnels(z).fdiff(2))
793
+ raises(ArgumentIndexError, lambda: fresnelc(z).fdiff(2))
794
+
795
+ assert fresnels(x).taylor_term(-1, x) is S.Zero
796
+ assert fresnelc(x).taylor_term(-1, x) is S.Zero
797
+ assert fresnelc(x).taylor_term(1, x) == -pi**2*x**5/40
798
+
799
+
800
+ def test_fresnel_series():
801
+ assert fresnelc(z).series(z, n=15) == \
802
+ z - pi**2*z**5/40 + pi**4*z**9/3456 - pi**6*z**13/599040 + O(z**15)
803
+
804
+ # issues 6510, 10102
805
+ fs = (S.Half - sin(pi*z**2/2)/(pi**2*z**3)
806
+ + (-1/(pi*z) + 3/(pi**3*z**5))*cos(pi*z**2/2))
807
+ fc = (S.Half - cos(pi*z**2/2)/(pi**2*z**3)
808
+ + (1/(pi*z) - 3/(pi**3*z**5))*sin(pi*z**2/2))
809
+ assert fresnels(z).series(z, oo) == fs + O(z**(-6), (z, oo))
810
+ assert fresnelc(z).series(z, oo) == fc + O(z**(-6), (z, oo))
811
+ assert (fresnels(z).series(z, -oo) + fs.subs(z, -z)).expand().is_Order
812
+ assert (fresnelc(z).series(z, -oo) + fc.subs(z, -z)).expand().is_Order
813
+ assert (fresnels(1/z).series(z) - fs.subs(z, 1/z)).expand().is_Order
814
+ assert (fresnelc(1/z).series(z) - fc.subs(z, 1/z)).expand().is_Order
815
+ assert ((2*fresnels(3*z)).series(z, oo) - 2*fs.subs(z, 3*z)).expand().is_Order
816
+ assert ((3*fresnelc(2*z)).series(z, oo) - 3*fc.subs(z, 2*z)).expand().is_Order
env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_gamma_functions.py ADDED
@@ -0,0 +1,741 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.function import expand_func, Subs
2
+ from sympy.core import EulerGamma
3
+ from sympy.core.numbers import (I, Rational, nan, oo, pi, zoo)
4
+ from sympy.core.singleton import S
5
+ from sympy.core.symbol import (Dummy, Symbol)
6
+ from sympy.functions.combinatorial.factorials import factorial
7
+ from sympy.functions.combinatorial.numbers import harmonic
8
+ from sympy.functions.elementary.complexes import (Abs, conjugate, im, re)
9
+ from sympy.functions.elementary.exponential import (exp, exp_polar, log)
10
+ from sympy.functions.elementary.hyperbolic import tanh
11
+ from sympy.functions.elementary.miscellaneous import sqrt
12
+ from sympy.functions.elementary.trigonometric import (cos, sin, atan)
13
+ from sympy.functions.special.error_functions import (Ei, erf, erfc)
14
+ from sympy.functions.special.gamma_functions import (digamma, gamma, loggamma, lowergamma, multigamma, polygamma, trigamma, uppergamma)
15
+ from sympy.functions.special.zeta_functions import zeta
16
+ from sympy.series.order import O
17
+
18
+ from sympy.core.expr import unchanged
19
+ from sympy.core.function import ArgumentIndexError
20
+ from sympy.testing.pytest import raises
21
+ from sympy.core.random import (test_derivative_numerically as td,
22
+ random_complex_number as randcplx,
23
+ verify_numerically as tn)
24
+
25
+ x = Symbol('x')
26
+ y = Symbol('y')
27
+ n = Symbol('n', integer=True)
28
+ w = Symbol('w', real=True)
29
+
30
+ def test_gamma():
31
+ assert gamma(nan) is nan
32
+ assert gamma(oo) is oo
33
+
34
+ assert gamma(-100) is zoo
35
+ assert gamma(0) is zoo
36
+ assert gamma(-100.0) is zoo
37
+
38
+ assert gamma(1) == 1
39
+ assert gamma(2) == 1
40
+ assert gamma(3) == 2
41
+
42
+ assert gamma(102) == factorial(101)
43
+
44
+ assert gamma(S.Half) == sqrt(pi)
45
+
46
+ assert gamma(Rational(3, 2)) == sqrt(pi)*S.Half
47
+ assert gamma(Rational(5, 2)) == sqrt(pi)*Rational(3, 4)
48
+ assert gamma(Rational(7, 2)) == sqrt(pi)*Rational(15, 8)
49
+
50
+ assert gamma(Rational(-1, 2)) == -2*sqrt(pi)
51
+ assert gamma(Rational(-3, 2)) == sqrt(pi)*Rational(4, 3)
52
+ assert gamma(Rational(-5, 2)) == sqrt(pi)*Rational(-8, 15)
53
+
54
+ assert gamma(Rational(-15, 2)) == sqrt(pi)*Rational(256, 2027025)
55
+
56
+ assert gamma(Rational(
57
+ -11, 8)).expand(func=True) == Rational(64, 33)*gamma(Rational(5, 8))
58
+ assert gamma(Rational(
59
+ -10, 3)).expand(func=True) == Rational(81, 280)*gamma(Rational(2, 3))
60
+ assert gamma(Rational(
61
+ 14, 3)).expand(func=True) == Rational(880, 81)*gamma(Rational(2, 3))
62
+ assert gamma(Rational(
63
+ 17, 7)).expand(func=True) == Rational(30, 49)*gamma(Rational(3, 7))
64
+ assert gamma(Rational(
65
+ 19, 8)).expand(func=True) == Rational(33, 64)*gamma(Rational(3, 8))
66
+
67
+ assert gamma(x).diff(x) == gamma(x)*polygamma(0, x)
68
+
69
+ assert gamma(x - 1).expand(func=True) == gamma(x)/(x - 1)
70
+ assert gamma(x + 2).expand(func=True, mul=False) == x*(x + 1)*gamma(x)
71
+
72
+ assert conjugate(gamma(x)) == gamma(conjugate(x))
73
+
74
+ assert expand_func(gamma(x + Rational(3, 2))) == \
75
+ (x + S.Half)*gamma(x + S.Half)
76
+
77
+ assert expand_func(gamma(x - S.Half)) == \
78
+ gamma(S.Half + x)/(x - S.Half)
79
+
80
+ # Test a bug:
81
+ assert expand_func(gamma(x + Rational(3, 4))) == gamma(x + Rational(3, 4))
82
+
83
+ # XXX: Not sure about these tests. I can fix them by defining e.g.
84
+ # exp_polar.is_integer but I'm not sure if that makes sense.
85
+ assert gamma(3*exp_polar(I*pi)/4).is_nonnegative is False
86
+ assert gamma(3*exp_polar(I*pi)/4).is_extended_nonpositive is True
87
+
88
+ y = Symbol('y', nonpositive=True, integer=True)
89
+ assert gamma(y).is_real == False
90
+ y = Symbol('y', positive=True, noninteger=True)
91
+ assert gamma(y).is_real == True
92
+
93
+ assert gamma(-1.0, evaluate=False).is_real == False
94
+ assert gamma(0, evaluate=False).is_real == False
95
+ assert gamma(-2, evaluate=False).is_real == False
96
+
97
+
98
+ def test_gamma_rewrite():
99
+ assert gamma(n).rewrite(factorial) == factorial(n - 1)
100
+
101
+
102
+ def test_gamma_series():
103
+ assert gamma(x + 1).series(x, 0, 3) == \
104
+ 1 - EulerGamma*x + x**2*(EulerGamma**2/2 + pi**2/12) + O(x**3)
105
+ assert gamma(x).series(x, -1, 3) == \
106
+ -1/(x + 1) + EulerGamma - 1 + (x + 1)*(-1 - pi**2/12 - EulerGamma**2/2 + \
107
+ EulerGamma) + (x + 1)**2*(-1 - pi**2/12 - EulerGamma**2/2 + EulerGamma**3/6 - \
108
+ polygamma(2, 1)/6 + EulerGamma*pi**2/12 + EulerGamma) + O((x + 1)**3, (x, -1))
109
+
110
+
111
+ def tn_branch(s, func):
112
+ from sympy.core.random import uniform
113
+ c = uniform(1, 5)
114
+ expr = func(s, c*exp_polar(I*pi)) - func(s, c*exp_polar(-I*pi))
115
+ eps = 1e-15
116
+ expr2 = func(s + eps, -c + eps*I) - func(s + eps, -c - eps*I)
117
+ return abs(expr.n() - expr2.n()).n() < 1e-10
118
+
119
+
120
+ def test_lowergamma():
121
+ from sympy.functions.special.error_functions import expint
122
+ from sympy.functions.special.hyper import meijerg
123
+ assert lowergamma(x, 0) == 0
124
+ assert lowergamma(x, y).diff(y) == y**(x - 1)*exp(-y)
125
+ assert td(lowergamma(randcplx(), y), y)
126
+ assert td(lowergamma(x, randcplx()), x)
127
+ assert lowergamma(x, y).diff(x) == \
128
+ gamma(x)*digamma(x) - uppergamma(x, y)*log(y) \
129
+ - meijerg([], [1, 1], [0, 0, x], [], y)
130
+
131
+ assert lowergamma(S.Half, x) == sqrt(pi)*erf(sqrt(x))
132
+ assert not lowergamma(S.Half - 3, x).has(lowergamma)
133
+ assert not lowergamma(S.Half + 3, x).has(lowergamma)
134
+ assert lowergamma(S.Half, x, evaluate=False).has(lowergamma)
135
+ assert tn(lowergamma(S.Half + 3, x, evaluate=False),
136
+ lowergamma(S.Half + 3, x), x)
137
+ assert tn(lowergamma(S.Half - 3, x, evaluate=False),
138
+ lowergamma(S.Half - 3, x), x)
139
+
140
+ assert tn_branch(-3, lowergamma)
141
+ assert tn_branch(-4, lowergamma)
142
+ assert tn_branch(Rational(1, 3), lowergamma)
143
+ assert tn_branch(pi, lowergamma)
144
+ assert lowergamma(3, exp_polar(4*pi*I)*x) == lowergamma(3, x)
145
+ assert lowergamma(y, exp_polar(5*pi*I)*x) == \
146
+ exp(4*I*pi*y)*lowergamma(y, x*exp_polar(pi*I))
147
+ assert lowergamma(-2, exp_polar(5*pi*I)*x) == \
148
+ lowergamma(-2, x*exp_polar(I*pi)) + 2*pi*I
149
+
150
+ assert conjugate(lowergamma(x, y)) == lowergamma(conjugate(x), conjugate(y))
151
+ assert conjugate(lowergamma(x, 0)) == 0
152
+ assert unchanged(conjugate, lowergamma(x, -oo))
153
+
154
+ assert lowergamma(0, x)._eval_is_meromorphic(x, 0) == False
155
+ assert lowergamma(S(1)/3, x)._eval_is_meromorphic(x, 0) == False
156
+ assert lowergamma(1, x, evaluate=False)._eval_is_meromorphic(x, 0) == True
157
+ assert lowergamma(x, x)._eval_is_meromorphic(x, 0) == False
158
+ assert lowergamma(x + 1, x)._eval_is_meromorphic(x, 0) == False
159
+ assert lowergamma(1/x, x)._eval_is_meromorphic(x, 0) == False
160
+ assert lowergamma(0, x + 1)._eval_is_meromorphic(x, 0) == False
161
+ assert lowergamma(S(1)/3, x + 1)._eval_is_meromorphic(x, 0) == True
162
+ assert lowergamma(1, x + 1, evaluate=False)._eval_is_meromorphic(x, 0) == True
163
+ assert lowergamma(x, x + 1)._eval_is_meromorphic(x, 0) == True
164
+ assert lowergamma(x + 1, x + 1)._eval_is_meromorphic(x, 0) == True
165
+ assert lowergamma(1/x, x + 1)._eval_is_meromorphic(x, 0) == False
166
+ assert lowergamma(0, 1/x)._eval_is_meromorphic(x, 0) == False
167
+ assert lowergamma(S(1)/3, 1/x)._eval_is_meromorphic(x, 0) == False
168
+ assert lowergamma(1, 1/x, evaluate=False)._eval_is_meromorphic(x, 0) == False
169
+ assert lowergamma(x, 1/x)._eval_is_meromorphic(x, 0) == False
170
+ assert lowergamma(x + 1, 1/x)._eval_is_meromorphic(x, 0) == False
171
+ assert lowergamma(1/x, 1/x)._eval_is_meromorphic(x, 0) == False
172
+
173
+ assert lowergamma(x, 2).series(x, oo, 3) == \
174
+ 2**x*(1 + 2/(x + 1))*exp(-2)/x + O(exp(x*log(2))/x**3, (x, oo))
175
+
176
+ assert lowergamma(
177
+ x, y).rewrite(expint) == -y**x*expint(-x + 1, y) + gamma(x)
178
+ k = Symbol('k', integer=True)
179
+ assert lowergamma(
180
+ k, y).rewrite(expint) == -y**k*expint(-k + 1, y) + gamma(k)
181
+ k = Symbol('k', integer=True, positive=False)
182
+ assert lowergamma(k, y).rewrite(expint) == lowergamma(k, y)
183
+ assert lowergamma(x, y).rewrite(uppergamma) == gamma(x) - uppergamma(x, y)
184
+
185
+ assert lowergamma(70, 6) == factorial(69) - 69035724522603011058660187038367026272747334489677105069435923032634389419656200387949342530805432320 * exp(-6)
186
+ assert (lowergamma(S(77) / 2, 6) - lowergamma(S(77) / 2, 6, evaluate=False)).evalf() < 1e-16
187
+ assert (lowergamma(-S(77) / 2, 6) - lowergamma(-S(77) / 2, 6, evaluate=False)).evalf() < 1e-16
188
+
189
+
190
+ def test_uppergamma():
191
+ from sympy.functions.special.error_functions import expint
192
+ from sympy.functions.special.hyper import meijerg
193
+ assert uppergamma(4, 0) == 6
194
+ assert uppergamma(x, y).diff(y) == -y**(x - 1)*exp(-y)
195
+ assert td(uppergamma(randcplx(), y), y)
196
+ assert uppergamma(x, y).diff(x) == \
197
+ uppergamma(x, y)*log(y) + meijerg([], [1, 1], [0, 0, x], [], y)
198
+ assert td(uppergamma(x, randcplx()), x)
199
+
200
+ p = Symbol('p', positive=True)
201
+ assert uppergamma(0, p) == -Ei(-p)
202
+ assert uppergamma(p, 0) == gamma(p)
203
+ assert uppergamma(S.Half, x) == sqrt(pi)*erfc(sqrt(x))
204
+ assert not uppergamma(S.Half - 3, x).has(uppergamma)
205
+ assert not uppergamma(S.Half + 3, x).has(uppergamma)
206
+ assert uppergamma(S.Half, x, evaluate=False).has(uppergamma)
207
+ assert tn(uppergamma(S.Half + 3, x, evaluate=False),
208
+ uppergamma(S.Half + 3, x), x)
209
+ assert tn(uppergamma(S.Half - 3, x, evaluate=False),
210
+ uppergamma(S.Half - 3, x), x)
211
+
212
+ assert unchanged(uppergamma, x, -oo)
213
+ assert unchanged(uppergamma, x, 0)
214
+
215
+ assert tn_branch(-3, uppergamma)
216
+ assert tn_branch(-4, uppergamma)
217
+ assert tn_branch(Rational(1, 3), uppergamma)
218
+ assert tn_branch(pi, uppergamma)
219
+ assert uppergamma(3, exp_polar(4*pi*I)*x) == uppergamma(3, x)
220
+ assert uppergamma(y, exp_polar(5*pi*I)*x) == \
221
+ exp(4*I*pi*y)*uppergamma(y, x*exp_polar(pi*I)) + \
222
+ gamma(y)*(1 - exp(4*pi*I*y))
223
+ assert uppergamma(-2, exp_polar(5*pi*I)*x) == \
224
+ uppergamma(-2, x*exp_polar(I*pi)) - 2*pi*I
225
+
226
+ assert uppergamma(-2, x) == expint(3, x)/x**2
227
+
228
+ assert conjugate(uppergamma(x, y)) == uppergamma(conjugate(x), conjugate(y))
229
+ assert unchanged(conjugate, uppergamma(x, -oo))
230
+
231
+ assert uppergamma(x, y).rewrite(expint) == y**x*expint(-x + 1, y)
232
+ assert uppergamma(x, y).rewrite(lowergamma) == gamma(x) - lowergamma(x, y)
233
+
234
+ assert uppergamma(70, 6) == 69035724522603011058660187038367026272747334489677105069435923032634389419656200387949342530805432320*exp(-6)
235
+ assert (uppergamma(S(77) / 2, 6) - uppergamma(S(77) / 2, 6, evaluate=False)).evalf() < 1e-16
236
+ assert (uppergamma(-S(77) / 2, 6) - uppergamma(-S(77) / 2, 6, evaluate=False)).evalf() < 1e-16
237
+
238
+
239
+ def test_polygamma():
240
+ assert polygamma(n, nan) is nan
241
+
242
+ assert polygamma(0, oo) is oo
243
+ assert polygamma(0, -oo) is oo
244
+ assert polygamma(0, I*oo) is oo
245
+ assert polygamma(0, -I*oo) is oo
246
+ assert polygamma(1, oo) == 0
247
+ assert polygamma(5, oo) == 0
248
+
249
+ assert polygamma(0, -9) is zoo
250
+
251
+ assert polygamma(0, -9) is zoo
252
+ assert polygamma(0, -1) is zoo
253
+ assert polygamma(Rational(3, 2), -1) is zoo
254
+
255
+ assert polygamma(0, 0) is zoo
256
+
257
+ assert polygamma(0, 1) == -EulerGamma
258
+ assert polygamma(0, 7) == Rational(49, 20) - EulerGamma
259
+
260
+ assert polygamma(1, 1) == pi**2/6
261
+ assert polygamma(1, 2) == pi**2/6 - 1
262
+ assert polygamma(1, 3) == pi**2/6 - Rational(5, 4)
263
+ assert polygamma(3, 1) == pi**4 / 15
264
+ assert polygamma(3, 5) == 6*(Rational(-22369, 20736) + pi**4/90)
265
+ assert polygamma(5, 1) == 8 * pi**6 / 63
266
+
267
+ assert polygamma(1, S.Half) == pi**2 / 2
268
+ assert polygamma(2, S.Half) == -14*zeta(3)
269
+ assert polygamma(11, S.Half) == 176896*pi**12
270
+
271
+ def t(m, n):
272
+ x = S(m)/n
273
+ r = polygamma(0, x)
274
+ if r.has(polygamma):
275
+ return False
276
+ return abs(polygamma(0, x.n()).n() - r.n()).n() < 1e-10
277
+ assert t(1, 2)
278
+ assert t(3, 2)
279
+ assert t(-1, 2)
280
+ assert t(1, 4)
281
+ assert t(-3, 4)
282
+ assert t(1, 3)
283
+ assert t(4, 3)
284
+ assert t(3, 4)
285
+ assert t(2, 3)
286
+ assert t(123, 5)
287
+
288
+ assert polygamma(0, x).rewrite(zeta) == polygamma(0, x)
289
+ assert polygamma(1, x).rewrite(zeta) == zeta(2, x)
290
+ assert polygamma(2, x).rewrite(zeta) == -2*zeta(3, x)
291
+ assert polygamma(I, 2).rewrite(zeta) == polygamma(I, 2)
292
+ n1 = Symbol('n1')
293
+ n2 = Symbol('n2', real=True)
294
+ n3 = Symbol('n3', integer=True)
295
+ n4 = Symbol('n4', positive=True)
296
+ n5 = Symbol('n5', positive=True, integer=True)
297
+ assert polygamma(n1, x).rewrite(zeta) == polygamma(n1, x)
298
+ assert polygamma(n2, x).rewrite(zeta) == polygamma(n2, x)
299
+ assert polygamma(n3, x).rewrite(zeta) == polygamma(n3, x)
300
+ assert polygamma(n4, x).rewrite(zeta) == polygamma(n4, x)
301
+ assert polygamma(n5, x).rewrite(zeta) == (-1)**(n5 + 1) * factorial(n5) * zeta(n5 + 1, x)
302
+
303
+ assert polygamma(3, 7*x).diff(x) == 7*polygamma(4, 7*x)
304
+
305
+ assert polygamma(0, x).rewrite(harmonic) == harmonic(x - 1) - EulerGamma
306
+ assert polygamma(2, x).rewrite(harmonic) == 2*harmonic(x - 1, 3) - 2*zeta(3)
307
+ ni = Symbol("n", integer=True)
308
+ assert polygamma(ni, x).rewrite(harmonic) == (-1)**(ni + 1)*(-harmonic(x - 1, ni + 1)
309
+ + zeta(ni + 1))*factorial(ni)
310
+
311
+ # Polygamma of non-negative integer order is unbranched:
312
+ k = Symbol('n', integer=True, nonnegative=True)
313
+ assert polygamma(k, exp_polar(2*I*pi)*x) == polygamma(k, x)
314
+
315
+ # but negative integers are branched!
316
+ k = Symbol('n', integer=True)
317
+ assert polygamma(k, exp_polar(2*I*pi)*x).args == (k, exp_polar(2*I*pi)*x)
318
+
319
+ # Polygamma of order -1 is loggamma:
320
+ assert polygamma(-1, x) == loggamma(x) - log(2*pi) / 2
321
+
322
+ # But smaller orders are iterated integrals and don't have a special name
323
+ assert polygamma(-2, x).func is polygamma
324
+
325
+ # Test a bug
326
+ assert polygamma(0, -x).expand(func=True) == polygamma(0, -x)
327
+
328
+ assert polygamma(2, 2.5).is_positive == False
329
+ assert polygamma(2, -2.5).is_positive == False
330
+ assert polygamma(3, 2.5).is_positive == True
331
+ assert polygamma(3, -2.5).is_positive is True
332
+ assert polygamma(-2, -2.5).is_positive is None
333
+ assert polygamma(-3, -2.5).is_positive is None
334
+
335
+ assert polygamma(2, 2.5).is_negative == True
336
+ assert polygamma(3, 2.5).is_negative == False
337
+ assert polygamma(3, -2.5).is_negative == False
338
+ assert polygamma(2, -2.5).is_negative is True
339
+ assert polygamma(-2, -2.5).is_negative is None
340
+ assert polygamma(-3, -2.5).is_negative is None
341
+
342
+ assert polygamma(I, 2).is_positive is None
343
+ assert polygamma(I, 3).is_negative is None
344
+
345
+ # issue 17350
346
+ assert (I*polygamma(I, pi)).as_real_imag() == \
347
+ (-im(polygamma(I, pi)), re(polygamma(I, pi)))
348
+ assert (tanh(polygamma(I, 1))).rewrite(exp) == \
349
+ (exp(polygamma(I, 1)) - exp(-polygamma(I, 1)))/(exp(polygamma(I, 1)) + exp(-polygamma(I, 1)))
350
+ assert (I / polygamma(I, 4)).rewrite(exp) == \
351
+ I*exp(-I*atan(im(polygamma(I, 4))/re(polygamma(I, 4))))/Abs(polygamma(I, 4))
352
+
353
+ # issue 12569
354
+ assert unchanged(im, polygamma(0, I))
355
+ assert polygamma(Symbol('a', positive=True), Symbol('b', positive=True)).is_real is True
356
+ assert polygamma(0, I).is_real is None
357
+
358
+ assert str(polygamma(pi, 3).evalf(n=10)) == "0.1169314564"
359
+ assert str(polygamma(2.3, 1.0).evalf(n=10)) == "-3.003302909"
360
+ assert str(polygamma(-1, 1).evalf(n=10)) == "-0.9189385332" # not zero
361
+ assert str(polygamma(I, 1).evalf(n=10)) == "-3.109856569 + 1.89089016*I"
362
+ assert str(polygamma(1, I).evalf(n=10)) == "-0.5369999034 - 0.7942335428*I"
363
+ assert str(polygamma(I, I).evalf(n=10)) == "6.332362889 + 45.92828268*I"
364
+
365
+
366
+ def test_polygamma_expand_func():
367
+ assert polygamma(0, x).expand(func=True) == polygamma(0, x)
368
+ assert polygamma(0, 2*x).expand(func=True) == \
369
+ polygamma(0, x)/2 + polygamma(0, S.Half + x)/2 + log(2)
370
+ assert polygamma(1, 2*x).expand(func=True) == \
371
+ polygamma(1, x)/4 + polygamma(1, S.Half + x)/4
372
+ assert polygamma(2, x).expand(func=True) == \
373
+ polygamma(2, x)
374
+ assert polygamma(0, -1 + x).expand(func=True) == \
375
+ polygamma(0, x) - 1/(x - 1)
376
+ assert polygamma(0, 1 + x).expand(func=True) == \
377
+ 1/x + polygamma(0, x )
378
+ assert polygamma(0, 2 + x).expand(func=True) == \
379
+ 1/x + 1/(1 + x) + polygamma(0, x)
380
+ assert polygamma(0, 3 + x).expand(func=True) == \
381
+ polygamma(0, x) + 1/x + 1/(1 + x) + 1/(2 + x)
382
+ assert polygamma(0, 4 + x).expand(func=True) == \
383
+ polygamma(0, x) + 1/x + 1/(1 + x) + 1/(2 + x) + 1/(3 + x)
384
+ assert polygamma(1, 1 + x).expand(func=True) == \
385
+ polygamma(1, x) - 1/x**2
386
+ assert polygamma(1, 2 + x).expand(func=True, multinomial=False) == \
387
+ polygamma(1, x) - 1/x**2 - 1/(1 + x)**2
388
+ assert polygamma(1, 3 + x).expand(func=True, multinomial=False) == \
389
+ polygamma(1, x) - 1/x**2 - 1/(1 + x)**2 - 1/(2 + x)**2
390
+ assert polygamma(1, 4 + x).expand(func=True, multinomial=False) == \
391
+ polygamma(1, x) - 1/x**2 - 1/(1 + x)**2 - \
392
+ 1/(2 + x)**2 - 1/(3 + x)**2
393
+ assert polygamma(0, x + y).expand(func=True) == \
394
+ polygamma(0, x + y)
395
+ assert polygamma(1, x + y).expand(func=True) == \
396
+ polygamma(1, x + y)
397
+ assert polygamma(1, 3 + 4*x + y).expand(func=True, multinomial=False) == \
398
+ polygamma(1, y + 4*x) - 1/(y + 4*x)**2 - \
399
+ 1/(1 + y + 4*x)**2 - 1/(2 + y + 4*x)**2
400
+ assert polygamma(3, 3 + 4*x + y).expand(func=True, multinomial=False) == \
401
+ polygamma(3, y + 4*x) - 6/(y + 4*x)**4 - \
402
+ 6/(1 + y + 4*x)**4 - 6/(2 + y + 4*x)**4
403
+ assert polygamma(3, 4*x + y + 1).expand(func=True, multinomial=False) == \
404
+ polygamma(3, y + 4*x) - 6/(y + 4*x)**4
405
+ e = polygamma(3, 4*x + y + Rational(3, 2))
406
+ assert e.expand(func=True) == e
407
+ e = polygamma(3, x + y + Rational(3, 4))
408
+ assert e.expand(func=True, basic=False) == e
409
+
410
+ assert polygamma(-1, x, evaluate=False).expand(func=True) == \
411
+ loggamma(x) - log(pi)/2 - log(2)/2
412
+ p2 = polygamma(-2, x).expand(func=True) + x**2/2 - x/2 + S(1)/12
413
+ assert isinstance(p2, Subs)
414
+ assert p2.point == (-1,)
415
+
416
+
417
+ def test_digamma():
418
+ assert digamma(nan) == nan
419
+
420
+ assert digamma(oo) == oo
421
+ assert digamma(-oo) == oo
422
+ assert digamma(I*oo) == oo
423
+ assert digamma(-I*oo) == oo
424
+
425
+ assert digamma(-9) == zoo
426
+
427
+ assert digamma(-9) == zoo
428
+ assert digamma(-1) == zoo
429
+
430
+ assert digamma(0) == zoo
431
+
432
+ assert digamma(1) == -EulerGamma
433
+ assert digamma(7) == Rational(49, 20) - EulerGamma
434
+
435
+ def t(m, n):
436
+ x = S(m)/n
437
+ r = digamma(x)
438
+ if r.has(digamma):
439
+ return False
440
+ return abs(digamma(x.n()).n() - r.n()).n() < 1e-10
441
+ assert t(1, 2)
442
+ assert t(3, 2)
443
+ assert t(-1, 2)
444
+ assert t(1, 4)
445
+ assert t(-3, 4)
446
+ assert t(1, 3)
447
+ assert t(4, 3)
448
+ assert t(3, 4)
449
+ assert t(2, 3)
450
+ assert t(123, 5)
451
+
452
+ assert digamma(x).rewrite(zeta) == polygamma(0, x)
453
+
454
+ assert digamma(x).rewrite(harmonic) == harmonic(x - 1) - EulerGamma
455
+
456
+ assert digamma(I).is_real is None
457
+
458
+ assert digamma(x,evaluate=False).fdiff() == polygamma(1, x)
459
+
460
+ assert digamma(x,evaluate=False).is_real is None
461
+
462
+ assert digamma(x,evaluate=False).is_positive is None
463
+
464
+ assert digamma(x,evaluate=False).is_negative is None
465
+
466
+ assert digamma(x,evaluate=False).rewrite(polygamma) == polygamma(0, x)
467
+
468
+
469
+ def test_digamma_expand_func():
470
+ assert digamma(x).expand(func=True) == polygamma(0, x)
471
+ assert digamma(2*x).expand(func=True) == \
472
+ polygamma(0, x)/2 + polygamma(0, Rational(1, 2) + x)/2 + log(2)
473
+ assert digamma(-1 + x).expand(func=True) == \
474
+ polygamma(0, x) - 1/(x - 1)
475
+ assert digamma(1 + x).expand(func=True) == \
476
+ 1/x + polygamma(0, x )
477
+ assert digamma(2 + x).expand(func=True) == \
478
+ 1/x + 1/(1 + x) + polygamma(0, x)
479
+ assert digamma(3 + x).expand(func=True) == \
480
+ polygamma(0, x) + 1/x + 1/(1 + x) + 1/(2 + x)
481
+ assert digamma(4 + x).expand(func=True) == \
482
+ polygamma(0, x) + 1/x + 1/(1 + x) + 1/(2 + x) + 1/(3 + x)
483
+ assert digamma(x + y).expand(func=True) == \
484
+ polygamma(0, x + y)
485
+
486
+ def test_trigamma():
487
+ assert trigamma(nan) == nan
488
+
489
+ assert trigamma(oo) == 0
490
+
491
+ assert trigamma(1) == pi**2/6
492
+ assert trigamma(2) == pi**2/6 - 1
493
+ assert trigamma(3) == pi**2/6 - Rational(5, 4)
494
+
495
+ assert trigamma(x, evaluate=False).rewrite(zeta) == zeta(2, x)
496
+ assert trigamma(x, evaluate=False).rewrite(harmonic) == \
497
+ trigamma(x).rewrite(polygamma).rewrite(harmonic)
498
+
499
+ assert trigamma(x,evaluate=False).fdiff() == polygamma(2, x)
500
+
501
+ assert trigamma(x,evaluate=False).is_real is None
502
+
503
+ assert trigamma(x,evaluate=False).is_positive is None
504
+
505
+ assert trigamma(x,evaluate=False).is_negative is None
506
+
507
+ assert trigamma(x,evaluate=False).rewrite(polygamma) == polygamma(1, x)
508
+
509
+ def test_trigamma_expand_func():
510
+ assert trigamma(2*x).expand(func=True) == \
511
+ polygamma(1, x)/4 + polygamma(1, Rational(1, 2) + x)/4
512
+ assert trigamma(1 + x).expand(func=True) == \
513
+ polygamma(1, x) - 1/x**2
514
+ assert trigamma(2 + x).expand(func=True, multinomial=False) == \
515
+ polygamma(1, x) - 1/x**2 - 1/(1 + x)**2
516
+ assert trigamma(3 + x).expand(func=True, multinomial=False) == \
517
+ polygamma(1, x) - 1/x**2 - 1/(1 + x)**2 - 1/(2 + x)**2
518
+ assert trigamma(4 + x).expand(func=True, multinomial=False) == \
519
+ polygamma(1, x) - 1/x**2 - 1/(1 + x)**2 - \
520
+ 1/(2 + x)**2 - 1/(3 + x)**2
521
+ assert trigamma(x + y).expand(func=True) == \
522
+ polygamma(1, x + y)
523
+ assert trigamma(3 + 4*x + y).expand(func=True, multinomial=False) == \
524
+ polygamma(1, y + 4*x) - 1/(y + 4*x)**2 - \
525
+ 1/(1 + y + 4*x)**2 - 1/(2 + y + 4*x)**2
526
+
527
+ def test_loggamma():
528
+ raises(TypeError, lambda: loggamma(2, 3))
529
+ raises(ArgumentIndexError, lambda: loggamma(x).fdiff(2))
530
+
531
+ assert loggamma(-1) is oo
532
+ assert loggamma(-2) is oo
533
+ assert loggamma(0) is oo
534
+ assert loggamma(1) == 0
535
+ assert loggamma(2) == 0
536
+ assert loggamma(3) == log(2)
537
+ assert loggamma(4) == log(6)
538
+
539
+ n = Symbol("n", integer=True, positive=True)
540
+ assert loggamma(n) == log(gamma(n))
541
+ assert loggamma(-n) is oo
542
+ assert loggamma(n/2) == log(2**(-n + 1)*sqrt(pi)*gamma(n)/gamma(n/2 + S.Half))
543
+
544
+ assert loggamma(oo) is oo
545
+ assert loggamma(-oo) is zoo
546
+ assert loggamma(I*oo) is zoo
547
+ assert loggamma(-I*oo) is zoo
548
+ assert loggamma(zoo) is zoo
549
+ assert loggamma(nan) is nan
550
+
551
+ L = loggamma(Rational(16, 3))
552
+ E = -5*log(3) + loggamma(Rational(1, 3)) + log(4) + log(7) + log(10) + log(13)
553
+ assert expand_func(L).doit() == E
554
+ assert L.n() == E.n()
555
+
556
+ L = loggamma(Rational(19, 4))
557
+ E = -4*log(4) + loggamma(Rational(3, 4)) + log(3) + log(7) + log(11) + log(15)
558
+ assert expand_func(L).doit() == E
559
+ assert L.n() == E.n()
560
+
561
+ L = loggamma(Rational(23, 7))
562
+ E = -3*log(7) + log(2) + loggamma(Rational(2, 7)) + log(9) + log(16)
563
+ assert expand_func(L).doit() == E
564
+ assert L.n() == E.n()
565
+
566
+ L = loggamma(Rational(19, 4) - 7)
567
+ E = -log(9) - log(5) + loggamma(Rational(3, 4)) + 3*log(4) - 3*I*pi
568
+ assert expand_func(L).doit() == E
569
+ assert L.n() == E.n()
570
+
571
+ L = loggamma(Rational(23, 7) - 6)
572
+ E = -log(19) - log(12) - log(5) + loggamma(Rational(2, 7)) + 3*log(7) - 3*I*pi
573
+ assert expand_func(L).doit() == E
574
+ assert L.n() == E.n()
575
+
576
+ assert loggamma(x).diff(x) == polygamma(0, x)
577
+ s1 = loggamma(1/(x + sin(x)) + cos(x)).nseries(x, n=4)
578
+ s2 = (-log(2*x) - 1)/(2*x) - log(x/pi)/2 + (4 - log(2*x))*x/24 + O(x**2) + \
579
+ log(x)*x**2/2
580
+ assert (s1 - s2).expand(force=True).removeO() == 0
581
+ s1 = loggamma(1/x).series(x)
582
+ s2 = (1/x - S.Half)*log(1/x) - 1/x + log(2*pi)/2 + \
583
+ x/12 - x**3/360 + x**5/1260 + O(x**7)
584
+ assert ((s1 - s2).expand(force=True)).removeO() == 0
585
+
586
+ assert loggamma(x).rewrite('intractable') == log(gamma(x))
587
+
588
+ s1 = loggamma(x).series(x).cancel()
589
+ assert s1 == -log(x) - EulerGamma*x + pi**2*x**2/12 + x**3*polygamma(2, 1)/6 + \
590
+ pi**4*x**4/360 + x**5*polygamma(4, 1)/120 + O(x**6)
591
+ assert s1 == loggamma(x).rewrite('intractable').series(x).cancel()
592
+
593
+ assert conjugate(loggamma(x)) == loggamma(conjugate(x))
594
+ assert conjugate(loggamma(0)) is oo
595
+ assert conjugate(loggamma(1)) == loggamma(conjugate(1))
596
+ assert conjugate(loggamma(-oo)) == conjugate(zoo)
597
+
598
+ assert loggamma(Symbol('v', positive=True)).is_real is True
599
+ assert loggamma(Symbol('v', zero=True)).is_real is False
600
+ assert loggamma(Symbol('v', negative=True)).is_real is False
601
+ assert loggamma(Symbol('v', nonpositive=True)).is_real is False
602
+ assert loggamma(Symbol('v', nonnegative=True)).is_real is None
603
+ assert loggamma(Symbol('v', imaginary=True)).is_real is None
604
+ assert loggamma(Symbol('v', real=True)).is_real is None
605
+ assert loggamma(Symbol('v')).is_real is None
606
+
607
+ assert loggamma(S.Half).is_real is True
608
+ assert loggamma(0).is_real is False
609
+ assert loggamma(Rational(-1, 2)).is_real is False
610
+ assert loggamma(I).is_real is None
611
+ assert loggamma(2 + 3*I).is_real is None
612
+
613
+ def tN(N, M):
614
+ assert loggamma(1/x)._eval_nseries(x, n=N).getn() == M
615
+ tN(0, 0)
616
+ tN(1, 1)
617
+ tN(2, 2)
618
+ tN(3, 3)
619
+ tN(4, 4)
620
+ tN(5, 5)
621
+
622
+
623
+ def test_polygamma_expansion():
624
+ # A. & S., pa. 259 and 260
625
+ assert polygamma(0, 1/x).nseries(x, n=3) == \
626
+ -log(x) - x/2 - x**2/12 + O(x**3)
627
+ assert polygamma(1, 1/x).series(x, n=5) == \
628
+ x + x**2/2 + x**3/6 + O(x**5)
629
+ assert polygamma(3, 1/x).nseries(x, n=11) == \
630
+ 2*x**3 + 3*x**4 + 2*x**5 - x**7 + 4*x**9/3 + O(x**11)
631
+
632
+
633
+ def test_polygamma_leading_term():
634
+ expr = -log(1/x) + polygamma(0, 1 + 1/x) + S.EulerGamma
635
+ assert expr.as_leading_term(x, logx=-y) == S.EulerGamma
636
+
637
+
638
+ def test_issue_8657():
639
+ n = Symbol('n', negative=True, integer=True)
640
+ m = Symbol('m', integer=True)
641
+ o = Symbol('o', positive=True)
642
+ p = Symbol('p', negative=True, integer=False)
643
+ assert gamma(n).is_real is False
644
+ assert gamma(m).is_real is None
645
+ assert gamma(o).is_real is True
646
+ assert gamma(p).is_real is True
647
+ assert gamma(w).is_real is None
648
+
649
+
650
+ def test_issue_8524():
651
+ x = Symbol('x', positive=True)
652
+ y = Symbol('y', negative=True)
653
+ z = Symbol('z', positive=False)
654
+ p = Symbol('p', negative=False)
655
+ q = Symbol('q', integer=True)
656
+ r = Symbol('r', integer=False)
657
+ e = Symbol('e', even=True, negative=True)
658
+ assert gamma(x).is_positive is True
659
+ assert gamma(y).is_positive is None
660
+ assert gamma(z).is_positive is None
661
+ assert gamma(p).is_positive is None
662
+ assert gamma(q).is_positive is None
663
+ assert gamma(r).is_positive is None
664
+ assert gamma(e + S.Half).is_positive is True
665
+ assert gamma(e - S.Half).is_positive is False
666
+
667
+ def test_issue_14450():
668
+ assert uppergamma(Rational(3, 8), x).evalf() == uppergamma(Rational(3, 8), x)
669
+ assert lowergamma(x, Rational(3, 8)).evalf() == lowergamma(x, Rational(3, 8))
670
+ # some values from Wolfram Alpha for comparison
671
+ assert abs(uppergamma(Rational(3, 8), 2).evalf() - 0.07105675881) < 1e-9
672
+ assert abs(lowergamma(Rational(3, 8), 2).evalf() - 2.2993794256) < 1e-9
673
+
674
+ def test_issue_14528():
675
+ k = Symbol('k', integer=True, nonpositive=True)
676
+ assert isinstance(gamma(k), gamma)
677
+
678
+ def test_multigamma():
679
+ from sympy.concrete.products import Product
680
+ p = Symbol('p')
681
+ _k = Dummy('_k')
682
+
683
+ assert multigamma(x, p).dummy_eq(pi**(p*(p - 1)/4)*\
684
+ Product(gamma(x + (1 - _k)/2), (_k, 1, p)))
685
+
686
+ assert conjugate(multigamma(x, p)).dummy_eq(pi**((conjugate(p) - 1)*\
687
+ conjugate(p)/4)*Product(gamma(conjugate(x) + (1-conjugate(_k))/2), (_k, 1, p)))
688
+ assert conjugate(multigamma(x, 1)) == gamma(conjugate(x))
689
+
690
+ p = Symbol('p', positive=True)
691
+ assert conjugate(multigamma(x, p)).dummy_eq(pi**((p - 1)*p/4)*\
692
+ Product(gamma(conjugate(x) + (1-conjugate(_k))/2), (_k, 1, p)))
693
+
694
+ assert multigamma(nan, 1) is nan
695
+ assert multigamma(oo, 1).doit() is oo
696
+
697
+ assert multigamma(1, 1) == 1
698
+ assert multigamma(2, 1) == 1
699
+ assert multigamma(3, 1) == 2
700
+
701
+ assert multigamma(102, 1) == factorial(101)
702
+ assert multigamma(S.Half, 1) == sqrt(pi)
703
+
704
+ assert multigamma(1, 2) == pi
705
+ assert multigamma(2, 2) == pi/2
706
+
707
+ assert multigamma(1, 3) is zoo
708
+ assert multigamma(2, 3) == pi**2/2
709
+ assert multigamma(3, 3) == 3*pi**2/2
710
+
711
+ assert multigamma(x, 1).diff(x) == gamma(x)*polygamma(0, x)
712
+ assert multigamma(x, 2).diff(x) == sqrt(pi)*gamma(x)*gamma(x - S.Half)*\
713
+ polygamma(0, x) + sqrt(pi)*gamma(x)*gamma(x - S.Half)*polygamma(0, x - S.Half)
714
+
715
+ assert multigamma(x - 1, 1).expand(func=True) == gamma(x)/(x - 1)
716
+ assert multigamma(x + 2, 1).expand(func=True, mul=False) == x*(x + 1)*\
717
+ gamma(x)
718
+ assert multigamma(x - 1, 2).expand(func=True) == sqrt(pi)*gamma(x)*\
719
+ gamma(x + S.Half)/(x**3 - 3*x**2 + x*Rational(11, 4) - Rational(3, 4))
720
+ assert multigamma(x - 1, 3).expand(func=True) == pi**Rational(3, 2)*gamma(x)**2*\
721
+ gamma(x + S.Half)/(x**5 - 6*x**4 + 55*x**3/4 - 15*x**2 + x*Rational(31, 4) - Rational(3, 2))
722
+
723
+ assert multigamma(n, 1).rewrite(factorial) == factorial(n - 1)
724
+ assert multigamma(n, 2).rewrite(factorial) == sqrt(pi)*\
725
+ factorial(n - Rational(3, 2))*factorial(n - 1)
726
+ assert multigamma(n, 3).rewrite(factorial) == pi**Rational(3, 2)*\
727
+ factorial(n - 2)*factorial(n - Rational(3, 2))*factorial(n - 1)
728
+
729
+ assert multigamma(Rational(-1, 2), 3, evaluate=False).is_real == False
730
+ assert multigamma(S.Half, 3, evaluate=False).is_real == False
731
+ assert multigamma(0, 1, evaluate=False).is_real == False
732
+ assert multigamma(1, 3, evaluate=False).is_real == False
733
+ assert multigamma(-1.0, 3, evaluate=False).is_real == False
734
+ assert multigamma(0.7, 3, evaluate=False).is_real == True
735
+ assert multigamma(3, 3, evaluate=False).is_real == True
736
+
737
+ def test_gamma_as_leading_term():
738
+ assert gamma(x).as_leading_term(x) == 1/x
739
+ assert gamma(2 + x).as_leading_term(x) == S(1)
740
+ assert gamma(cos(x)).as_leading_term(x) == S(1)
741
+ assert gamma(sin(x)).as_leading_term(x) == 1/x
env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_hyper.py ADDED
@@ -0,0 +1,387 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.containers import Tuple
2
+ from sympy.core.function import Derivative
3
+ from sympy.core.numbers import (I, Rational, oo, pi)
4
+ from sympy.core.singleton import S
5
+ from sympy.core.symbol import symbols
6
+ from sympy.functions.elementary.exponential import (exp, log)
7
+ from sympy.functions.elementary.miscellaneous import sqrt
8
+ from sympy.functions.elementary.trigonometric import cos
9
+ from sympy.functions.special.gamma_functions import gamma
10
+ from sympy.functions.special.hyper import (appellf1, hyper, meijerg)
11
+ from sympy.series.order import O
12
+ from sympy.abc import x, z, k
13
+ from sympy.series.limits import limit
14
+ from sympy.testing.pytest import raises, slow
15
+ from sympy.core.random import (
16
+ random_complex_number as randcplx,
17
+ verify_numerically as tn,
18
+ test_derivative_numerically as td)
19
+
20
+
21
+ def test_TupleParametersBase():
22
+ # test that our implementation of the chain rule works
23
+ p = hyper((), (), z**2)
24
+ assert p.diff(z) == p*2*z
25
+
26
+
27
+ def test_hyper():
28
+ raises(TypeError, lambda: hyper(1, 2, z))
29
+
30
+ assert hyper((1, 2), (1,), z) == hyper(Tuple(1, 2), Tuple(1), z)
31
+
32
+ h = hyper((1, 2), (3, 4, 5), z)
33
+ assert h.ap == Tuple(1, 2)
34
+ assert h.bq == Tuple(3, 4, 5)
35
+ assert h.argument == z
36
+ assert h.is_commutative is True
37
+
38
+ # just a few checks to make sure that all arguments go where they should
39
+ assert tn(hyper(Tuple(), Tuple(), z), exp(z), z)
40
+ assert tn(z*hyper((1, 1), Tuple(2), -z), log(1 + z), z)
41
+
42
+ # differentiation
43
+ h = hyper(
44
+ (randcplx(), randcplx(), randcplx()), (randcplx(), randcplx()), z)
45
+ assert td(h, z)
46
+
47
+ a1, a2, b1, b2, b3 = symbols('a1:3, b1:4')
48
+ assert hyper((a1, a2), (b1, b2, b3), z).diff(z) == \
49
+ a1*a2/(b1*b2*b3) * hyper((a1 + 1, a2 + 1), (b1 + 1, b2 + 1, b3 + 1), z)
50
+
51
+ # differentiation wrt parameters is not supported
52
+ assert hyper([z], [], z).diff(z) == Derivative(hyper([z], [], z), z)
53
+
54
+ # hyper is unbranched wrt parameters
55
+ from sympy.functions.elementary.complexes import polar_lift
56
+ assert hyper([polar_lift(z)], [polar_lift(k)], polar_lift(x)) == \
57
+ hyper([z], [k], polar_lift(x))
58
+
59
+ # hyper does not automatically evaluate anyway, but the test is to make
60
+ # sure that the evaluate keyword is accepted
61
+ assert hyper((1, 2), (1,), z, evaluate=False).func is hyper
62
+
63
+
64
+ def test_expand_func():
65
+ # evaluation at 1 of Gauss' hypergeometric function:
66
+ from sympy.abc import a, b, c
67
+ from sympy.core.function import expand_func
68
+ a1, b1, c1 = randcplx(), randcplx(), randcplx() + 5
69
+ assert expand_func(hyper([a, b], [c], 1)) == \
70
+ gamma(c)*gamma(-a - b + c)/(gamma(-a + c)*gamma(-b + c))
71
+ assert abs(expand_func(hyper([a1, b1], [c1], 1)).n()
72
+ - hyper([a1, b1], [c1], 1).n()) < 1e-10
73
+
74
+ # hyperexpand wrapper for hyper:
75
+ assert expand_func(hyper([], [], z)) == exp(z)
76
+ assert expand_func(hyper([1, 2, 3], [], z)) == hyper([1, 2, 3], [], z)
77
+ assert expand_func(meijerg([[1, 1], []], [[1], [0]], z)) == log(z + 1)
78
+ assert expand_func(meijerg([[1, 1], []], [[], []], z)) == \
79
+ meijerg([[1, 1], []], [[], []], z)
80
+
81
+
82
+ def replace_dummy(expr, sym):
83
+ from sympy.core.symbol import Dummy
84
+ dum = expr.atoms(Dummy)
85
+ if not dum:
86
+ return expr
87
+ assert len(dum) == 1
88
+ return expr.xreplace({dum.pop(): sym})
89
+
90
+
91
+ def test_hyper_rewrite_sum():
92
+ from sympy.concrete.summations import Sum
93
+ from sympy.core.symbol import Dummy
94
+ from sympy.functions.combinatorial.factorials import (RisingFactorial, factorial)
95
+ _k = Dummy("k")
96
+ assert replace_dummy(hyper((1, 2), (1, 3), x).rewrite(Sum), _k) == \
97
+ Sum(x**_k / factorial(_k) * RisingFactorial(2, _k) /
98
+ RisingFactorial(3, _k), (_k, 0, oo))
99
+
100
+ assert hyper((1, 2, 3), (-1, 3), z).rewrite(Sum) == \
101
+ hyper((1, 2, 3), (-1, 3), z)
102
+
103
+
104
+ def test_radius_of_convergence():
105
+ assert hyper((1, 2), [3], z).radius_of_convergence == 1
106
+ assert hyper((1, 2), [3, 4], z).radius_of_convergence is oo
107
+ assert hyper((1, 2, 3), [4], z).radius_of_convergence == 0
108
+ assert hyper((0, 1, 2), [4], z).radius_of_convergence is oo
109
+ assert hyper((-1, 1, 2), [-4], z).radius_of_convergence == 0
110
+ assert hyper((-1, -2, 2), [-1], z).radius_of_convergence is oo
111
+ assert hyper((-1, 2), [-1, -2], z).radius_of_convergence == 0
112
+ assert hyper([-1, 1, 3], [-2, 2], z).radius_of_convergence == 1
113
+ assert hyper([-1, 1], [-2, 2], z).radius_of_convergence is oo
114
+ assert hyper([-1, 1, 3], [-2], z).radius_of_convergence == 0
115
+ assert hyper((-1, 2, 3, 4), [], z).radius_of_convergence is oo
116
+
117
+ assert hyper([1, 1], [3], 1).convergence_statement == True
118
+ assert hyper([1, 1], [2], 1).convergence_statement == False
119
+ assert hyper([1, 1], [2], -1).convergence_statement == True
120
+ assert hyper([1, 1], [1], -1).convergence_statement == False
121
+
122
+
123
+ def test_meijer():
124
+ raises(TypeError, lambda: meijerg(1, z))
125
+ raises(TypeError, lambda: meijerg(((1,), (2,)), (3,), (4,), z))
126
+
127
+ assert meijerg(((1, 2), (3,)), ((4,), (5,)), z) == \
128
+ meijerg(Tuple(1, 2), Tuple(3), Tuple(4), Tuple(5), z)
129
+
130
+ g = meijerg((1, 2), (3, 4, 5), (6, 7, 8, 9), (10, 11, 12, 13, 14), z)
131
+ assert g.an == Tuple(1, 2)
132
+ assert g.ap == Tuple(1, 2, 3, 4, 5)
133
+ assert g.aother == Tuple(3, 4, 5)
134
+ assert g.bm == Tuple(6, 7, 8, 9)
135
+ assert g.bq == Tuple(6, 7, 8, 9, 10, 11, 12, 13, 14)
136
+ assert g.bother == Tuple(10, 11, 12, 13, 14)
137
+ assert g.argument == z
138
+ assert g.nu == 75
139
+ assert g.delta == -1
140
+ assert g.is_commutative is True
141
+ assert g.is_number is False
142
+ #issue 13071
143
+ assert meijerg([[],[]], [[S.Half],[0]], 1).is_number is True
144
+
145
+ assert meijerg([1, 2], [3], [4], [5], z).delta == S.Half
146
+
147
+ # just a few checks to make sure that all arguments go where they should
148
+ assert tn(meijerg(Tuple(), Tuple(), Tuple(0), Tuple(), -z), exp(z), z)
149
+ assert tn(sqrt(pi)*meijerg(Tuple(), Tuple(),
150
+ Tuple(0), Tuple(S.Half), z**2/4), cos(z), z)
151
+ assert tn(meijerg(Tuple(1, 1), Tuple(), Tuple(1), Tuple(0), z),
152
+ log(1 + z), z)
153
+
154
+ # test exceptions
155
+ raises(ValueError, lambda: meijerg(((3, 1), (2,)), ((oo,), (2, 0)), x))
156
+ raises(ValueError, lambda: meijerg(((3, 1), (2,)), ((1,), (2, 0)), x))
157
+
158
+ # differentiation
159
+ g = meijerg((randcplx(),), (randcplx() + 2*I,), Tuple(),
160
+ (randcplx(), randcplx()), z)
161
+ assert td(g, z)
162
+
163
+ g = meijerg(Tuple(), (randcplx(),), Tuple(),
164
+ (randcplx(), randcplx()), z)
165
+ assert td(g, z)
166
+
167
+ g = meijerg(Tuple(), Tuple(), Tuple(randcplx()),
168
+ Tuple(randcplx(), randcplx()), z)
169
+ assert td(g, z)
170
+
171
+ a1, a2, b1, b2, c1, c2, d1, d2 = symbols('a1:3, b1:3, c1:3, d1:3')
172
+ assert meijerg((a1, a2), (b1, b2), (c1, c2), (d1, d2), z).diff(z) == \
173
+ (meijerg((a1 - 1, a2), (b1, b2), (c1, c2), (d1, d2), z)
174
+ + (a1 - 1)*meijerg((a1, a2), (b1, b2), (c1, c2), (d1, d2), z))/z
175
+
176
+ assert meijerg([z, z], [], [], [], z).diff(z) == \
177
+ Derivative(meijerg([z, z], [], [], [], z), z)
178
+
179
+ # meijerg is unbranched wrt parameters
180
+ from sympy.functions.elementary.complexes import polar_lift as pl
181
+ assert meijerg([pl(a1)], [pl(a2)], [pl(b1)], [pl(b2)], pl(z)) == \
182
+ meijerg([a1], [a2], [b1], [b2], pl(z))
183
+
184
+ # integrand
185
+ from sympy.abc import a, b, c, d, s
186
+ assert meijerg([a], [b], [c], [d], z).integrand(s) == \
187
+ z**s*gamma(c - s)*gamma(-a + s + 1)/(gamma(b - s)*gamma(-d + s + 1))
188
+
189
+
190
+ def test_meijerg_derivative():
191
+ assert meijerg([], [1, 1], [0, 0, x], [], z).diff(x) == \
192
+ log(z)*meijerg([], [1, 1], [0, 0, x], [], z) \
193
+ + 2*meijerg([], [1, 1, 1], [0, 0, x, 0], [], z)
194
+
195
+ y = randcplx()
196
+ a = 5 # mpmath chokes with non-real numbers, and Mod1 with floats
197
+ assert td(meijerg([x], [], [], [], y), x)
198
+ assert td(meijerg([x**2], [], [], [], y), x)
199
+ assert td(meijerg([], [x], [], [], y), x)
200
+ assert td(meijerg([], [], [x], [], y), x)
201
+ assert td(meijerg([], [], [], [x], y), x)
202
+ assert td(meijerg([x], [a], [a + 1], [], y), x)
203
+ assert td(meijerg([x], [a + 1], [a], [], y), x)
204
+ assert td(meijerg([x, a], [], [], [a + 1], y), x)
205
+ assert td(meijerg([x, a + 1], [], [], [a], y), x)
206
+ b = Rational(3, 2)
207
+ assert td(meijerg([a + 2], [b], [b - 3, x], [a], y), x)
208
+
209
+
210
+ def test_meijerg_period():
211
+ assert meijerg([], [1], [0], [], x).get_period() == 2*pi
212
+ assert meijerg([1], [], [], [0], x).get_period() == 2*pi
213
+ assert meijerg([], [], [0], [], x).get_period() == 2*pi # exp(x)
214
+ assert meijerg(
215
+ [], [], [0], [S.Half], x).get_period() == 2*pi # cos(sqrt(x))
216
+ assert meijerg(
217
+ [], [], [S.Half], [0], x).get_period() == 4*pi # sin(sqrt(x))
218
+ assert meijerg([1, 1], [], [1], [0], x).get_period() is oo # log(1 + x)
219
+
220
+
221
+ def test_hyper_unpolarify():
222
+ from sympy.functions.elementary.exponential import exp_polar
223
+ a = exp_polar(2*pi*I)*x
224
+ b = x
225
+ assert hyper([], [], a).argument == b
226
+ assert hyper([0], [], a).argument == a
227
+ assert hyper([0], [0], a).argument == b
228
+ assert hyper([0, 1], [0], a).argument == a
229
+ assert hyper([0, 1], [0], exp_polar(2*pi*I)).argument == 1
230
+
231
+
232
+ @slow
233
+ def test_hyperrep():
234
+ from sympy.functions.special.hyper import (HyperRep, HyperRep_atanh,
235
+ HyperRep_power1, HyperRep_power2, HyperRep_log1, HyperRep_asin1,
236
+ HyperRep_asin2, HyperRep_sqrts1, HyperRep_sqrts2, HyperRep_log2,
237
+ HyperRep_cosasin, HyperRep_sinasin)
238
+ # First test the base class works.
239
+ from sympy.functions.elementary.exponential import exp_polar
240
+ from sympy.functions.elementary.piecewise import Piecewise
241
+ a, b, c, d, z = symbols('a b c d z')
242
+
243
+ class myrep(HyperRep):
244
+ @classmethod
245
+ def _expr_small(cls, x):
246
+ return a
247
+
248
+ @classmethod
249
+ def _expr_small_minus(cls, x):
250
+ return b
251
+
252
+ @classmethod
253
+ def _expr_big(cls, x, n):
254
+ return c*n
255
+
256
+ @classmethod
257
+ def _expr_big_minus(cls, x, n):
258
+ return d*n
259
+ assert myrep(z).rewrite('nonrep') == Piecewise((0, abs(z) > 1), (a, True))
260
+ assert myrep(exp_polar(I*pi)*z).rewrite('nonrep') == \
261
+ Piecewise((0, abs(z) > 1), (b, True))
262
+ assert myrep(exp_polar(2*I*pi)*z).rewrite('nonrep') == \
263
+ Piecewise((c, abs(z) > 1), (a, True))
264
+ assert myrep(exp_polar(3*I*pi)*z).rewrite('nonrep') == \
265
+ Piecewise((d, abs(z) > 1), (b, True))
266
+ assert myrep(exp_polar(4*I*pi)*z).rewrite('nonrep') == \
267
+ Piecewise((2*c, abs(z) > 1), (a, True))
268
+ assert myrep(exp_polar(5*I*pi)*z).rewrite('nonrep') == \
269
+ Piecewise((2*d, abs(z) > 1), (b, True))
270
+ assert myrep(z).rewrite('nonrepsmall') == a
271
+ assert myrep(exp_polar(I*pi)*z).rewrite('nonrepsmall') == b
272
+
273
+ def t(func, hyp, z):
274
+ """ Test that func is a valid representation of hyp. """
275
+ # First test that func agrees with hyp for small z
276
+ if not tn(func.rewrite('nonrepsmall'), hyp, z,
277
+ a=Rational(-1, 2), b=Rational(-1, 2), c=S.Half, d=S.Half):
278
+ return False
279
+ # Next check that the two small representations agree.
280
+ if not tn(
281
+ func.rewrite('nonrepsmall').subs(
282
+ z, exp_polar(I*pi)*z).replace(exp_polar, exp),
283
+ func.subs(z, exp_polar(I*pi)*z).rewrite('nonrepsmall'),
284
+ z, a=Rational(-1, 2), b=Rational(-1, 2), c=S.Half, d=S.Half):
285
+ return False
286
+ # Next check continuity along exp_polar(I*pi)*t
287
+ expr = func.subs(z, exp_polar(I*pi)*z).rewrite('nonrep')
288
+ if abs(expr.subs(z, 1 + 1e-15).n() - expr.subs(z, 1 - 1e-15).n()) > 1e-10:
289
+ return False
290
+ # Finally check continuity of the big reps.
291
+
292
+ def dosubs(func, a, b):
293
+ rv = func.subs(z, exp_polar(a)*z).rewrite('nonrep')
294
+ return rv.subs(z, exp_polar(b)*z).replace(exp_polar, exp)
295
+ for n in [0, 1, 2, 3, 4, -1, -2, -3, -4]:
296
+ expr1 = dosubs(func, 2*I*pi*n, I*pi/2)
297
+ expr2 = dosubs(func, 2*I*pi*n + I*pi, -I*pi/2)
298
+ if not tn(expr1, expr2, z):
299
+ return False
300
+ expr1 = dosubs(func, 2*I*pi*(n + 1), -I*pi/2)
301
+ expr2 = dosubs(func, 2*I*pi*n + I*pi, I*pi/2)
302
+ if not tn(expr1, expr2, z):
303
+ return False
304
+ return True
305
+
306
+ # Now test the various representatives.
307
+ a = Rational(1, 3)
308
+ assert t(HyperRep_atanh(z), hyper([S.Half, 1], [Rational(3, 2)], z), z)
309
+ assert t(HyperRep_power1(a, z), hyper([-a], [], z), z)
310
+ assert t(HyperRep_power2(a, z), hyper([a, a - S.Half], [2*a], z), z)
311
+ assert t(HyperRep_log1(z), -z*hyper([1, 1], [2], z), z)
312
+ assert t(HyperRep_asin1(z), hyper([S.Half, S.Half], [Rational(3, 2)], z), z)
313
+ assert t(HyperRep_asin2(z), hyper([1, 1], [Rational(3, 2)], z), z)
314
+ assert t(HyperRep_sqrts1(a, z), hyper([-a, S.Half - a], [S.Half], z), z)
315
+ assert t(HyperRep_sqrts2(a, z),
316
+ -2*z/(2*a + 1)*hyper([-a - S.Half, -a], [S.Half], z).diff(z), z)
317
+ assert t(HyperRep_log2(z), -z/4*hyper([Rational(3, 2), 1, 1], [2, 2], z), z)
318
+ assert t(HyperRep_cosasin(a, z), hyper([-a, a], [S.Half], z), z)
319
+ assert t(HyperRep_sinasin(a, z), 2*a*z*hyper([1 - a, 1 + a], [Rational(3, 2)], z), z)
320
+
321
+
322
+ @slow
323
+ def test_meijerg_eval():
324
+ from sympy.functions.elementary.exponential import exp_polar
325
+ from sympy.functions.special.bessel import besseli
326
+ from sympy.abc import l
327
+ a = randcplx()
328
+ arg = x*exp_polar(k*pi*I)
329
+ expr1 = pi*meijerg([[], [(a + 1)/2]], [[a/2], [-a/2, (a + 1)/2]], arg**2/4)
330
+ expr2 = besseli(a, arg)
331
+
332
+ # Test that the two expressions agree for all arguments.
333
+ for x_ in [0.5, 1.5]:
334
+ for k_ in [0.0, 0.1, 0.3, 0.5, 0.8, 1, 5.751, 15.3]:
335
+ assert abs((expr1 - expr2).n(subs={x: x_, k: k_})) < 1e-10
336
+ assert abs((expr1 - expr2).n(subs={x: x_, k: -k_})) < 1e-10
337
+
338
+ # Test continuity independently
339
+ eps = 1e-13
340
+ expr2 = expr1.subs(k, l)
341
+ for x_ in [0.5, 1.5]:
342
+ for k_ in [0.5, Rational(1, 3), 0.25, 0.75, Rational(2, 3), 1.0, 1.5]:
343
+ assert abs((expr1 - expr2).n(
344
+ subs={x: x_, k: k_ + eps, l: k_ - eps})) < 1e-10
345
+ assert abs((expr1 - expr2).n(
346
+ subs={x: x_, k: -k_ + eps, l: -k_ - eps})) < 1e-10
347
+
348
+ expr = (meijerg(((0.5,), ()), ((0.5, 0, 0.5), ()), exp_polar(-I*pi)/4)
349
+ + meijerg(((0.5,), ()), ((0.5, 0, 0.5), ()), exp_polar(I*pi)/4)) \
350
+ /(2*sqrt(pi))
351
+ assert (expr - pi/exp(1)).n(chop=True) == 0
352
+
353
+
354
+ def test_limits():
355
+ k, x = symbols('k, x')
356
+ assert hyper((1,), (Rational(4, 3), Rational(5, 3)), k**2).series(k) == \
357
+ 1 + 9*k**2/20 + 81*k**4/1120 + O(k**6) # issue 6350
358
+
359
+ # https://github.com/sympy/sympy/issues/11465
360
+ assert limit(1/hyper((1, ), (1, ), x), x, 0) == 1
361
+
362
+
363
+ def test_appellf1():
364
+ a, b1, b2, c, x, y = symbols('a b1 b2 c x y')
365
+ assert appellf1(a, b2, b1, c, y, x) == appellf1(a, b1, b2, c, x, y)
366
+ assert appellf1(a, b1, b1, c, y, x) == appellf1(a, b1, b1, c, x, y)
367
+ assert appellf1(a, b1, b2, c, S.Zero, S.Zero) is S.One
368
+
369
+ f = appellf1(a, b1, b2, c, S.Zero, S.Zero, evaluate=False)
370
+ assert f.func is appellf1
371
+ assert f.doit() is S.One
372
+
373
+
374
+ def test_derivative_appellf1():
375
+ from sympy.core.function import diff
376
+ a, b1, b2, c, x, y, z = symbols('a b1 b2 c x y z')
377
+ assert diff(appellf1(a, b1, b2, c, x, y), x) == a*b1*appellf1(a + 1, b2, b1 + 1, c + 1, y, x)/c
378
+ assert diff(appellf1(a, b1, b2, c, x, y), y) == a*b2*appellf1(a + 1, b1, b2 + 1, c + 1, x, y)/c
379
+ assert diff(appellf1(a, b1, b2, c, x, y), z) == 0
380
+ assert diff(appellf1(a, b1, b2, c, x, y), a) == Derivative(appellf1(a, b1, b2, c, x, y), a)
381
+
382
+
383
+ def test_eval_nseries():
384
+ a1, b1, a2, b2 = symbols('a1 b1 a2 b2')
385
+ assert hyper((1,2), (1,2,3), x**2)._eval_nseries(x, 7, None) == 1 + x**2/3 + x**4/24 + x**6/360 + O(x**7)
386
+ assert exp(x)._eval_nseries(x,7,None) == hyper((a1, b1), (a1, b1), x)._eval_nseries(x, 7, None)
387
+ assert hyper((a1, a2), (b1, b2), x)._eval_nseries(z, 7, None) == hyper((a1, a2), (b1, b2), x) + O(z**7)
env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_mathieu.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.function import diff
2
+ from sympy.functions.elementary.complexes import conjugate
3
+ from sympy.functions.elementary.miscellaneous import sqrt
4
+ from sympy.functions.elementary.trigonometric import (cos, sin)
5
+ from sympy.functions.special.mathieu_functions import (mathieuc, mathieucprime, mathieus, mathieusprime)
6
+
7
+ from sympy.abc import a, q, z
8
+
9
+
10
+ def test_mathieus():
11
+ assert isinstance(mathieus(a, q, z), mathieus)
12
+ assert mathieus(a, 0, z) == sin(sqrt(a)*z)
13
+ assert conjugate(mathieus(a, q, z)) == mathieus(conjugate(a), conjugate(q), conjugate(z))
14
+ assert diff(mathieus(a, q, z), z) == mathieusprime(a, q, z)
15
+
16
+ def test_mathieuc():
17
+ assert isinstance(mathieuc(a, q, z), mathieuc)
18
+ assert mathieuc(a, 0, z) == cos(sqrt(a)*z)
19
+ assert diff(mathieuc(a, q, z), z) == mathieucprime(a, q, z)
20
+
21
+ def test_mathieusprime():
22
+ assert isinstance(mathieusprime(a, q, z), mathieusprime)
23
+ assert mathieusprime(a, 0, z) == sqrt(a)*cos(sqrt(a)*z)
24
+ assert diff(mathieusprime(a, q, z), z) == (-a + 2*q*cos(2*z))*mathieus(a, q, z)
25
+
26
+ def test_mathieucprime():
27
+ assert isinstance(mathieucprime(a, q, z), mathieucprime)
28
+ assert mathieucprime(a, 0, z) == -sqrt(a)*sin(sqrt(a)*z)
29
+ assert diff(mathieucprime(a, q, z), z) == (-a + 2*q*cos(2*z))*mathieuc(a, q, z)
env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_singularity_functions.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.function import (Derivative, diff)
2
+ from sympy.core.numbers import (Float, I, nan, oo, pi)
3
+ from sympy.core.relational import Eq
4
+ from sympy.core.symbol import (Symbol, symbols)
5
+ from sympy.functions.elementary.piecewise import Piecewise
6
+ from sympy.functions.special.delta_functions import (DiracDelta, Heaviside)
7
+ from sympy.functions.special.singularity_functions import SingularityFunction
8
+ from sympy.series.order import O
9
+
10
+
11
+ from sympy.core.expr import unchanged
12
+ from sympy.core.function import ArgumentIndexError
13
+ from sympy.testing.pytest import raises
14
+
15
+ x, y, a, n = symbols('x y a n')
16
+
17
+
18
+ def test_fdiff():
19
+ assert SingularityFunction(x, 4, 5).fdiff() == 5*SingularityFunction(x, 4, 4)
20
+ assert SingularityFunction(x, 4, -1).fdiff() == SingularityFunction(x, 4, -2)
21
+ assert SingularityFunction(x, 4, 0).fdiff() == SingularityFunction(x, 4, -1)
22
+
23
+ assert SingularityFunction(y, 6, 2).diff(y) == 2*SingularityFunction(y, 6, 1)
24
+ assert SingularityFunction(y, -4, -1).diff(y) == SingularityFunction(y, -4, -2)
25
+ assert SingularityFunction(y, 4, 0).diff(y) == SingularityFunction(y, 4, -1)
26
+ assert SingularityFunction(y, 4, 0).diff(y, 2) == SingularityFunction(y, 4, -2)
27
+
28
+ n = Symbol('n', positive=True)
29
+ assert SingularityFunction(x, a, n).fdiff() == n*SingularityFunction(x, a, n - 1)
30
+ assert SingularityFunction(y, a, n).diff(y) == n*SingularityFunction(y, a, n - 1)
31
+
32
+ expr_in = 4*SingularityFunction(x, a, n) + 3*SingularityFunction(x, a, -1) + -10*SingularityFunction(x, a, 0)
33
+ expr_out = n*4*SingularityFunction(x, a, n - 1) + 3*SingularityFunction(x, a, -2) - 10*SingularityFunction(x, a, -1)
34
+ assert diff(expr_in, x) == expr_out
35
+
36
+ assert SingularityFunction(x, -10, 5).diff(evaluate=False) == (
37
+ Derivative(SingularityFunction(x, -10, 5), x))
38
+
39
+ raises(ArgumentIndexError, lambda: SingularityFunction(x, 4, 5).fdiff(2))
40
+
41
+
42
+ def test_eval():
43
+ assert SingularityFunction(x, a, n).func == SingularityFunction
44
+ assert unchanged(SingularityFunction, x, 5, n)
45
+ assert SingularityFunction(5, 3, 2) == 4
46
+ assert SingularityFunction(3, 5, 1) == 0
47
+ assert SingularityFunction(3, 3, 0) == 1
48
+ assert SingularityFunction(4, 4, -1) is oo
49
+ assert SingularityFunction(4, 2, -1) == 0
50
+ assert SingularityFunction(4, 7, -1) == 0
51
+ assert SingularityFunction(5, 6, -2) == 0
52
+ assert SingularityFunction(4, 2, -2) == 0
53
+ assert SingularityFunction(4, 4, -2) is oo
54
+ assert (SingularityFunction(6.1, 4, 5)).evalf(5) == Float('40.841', '5')
55
+ assert SingularityFunction(6.1, pi, 2) == (-pi + 6.1)**2
56
+ assert SingularityFunction(x, a, nan) is nan
57
+ assert SingularityFunction(x, nan, 1) is nan
58
+ assert SingularityFunction(nan, a, n) is nan
59
+
60
+ raises(ValueError, lambda: SingularityFunction(x, a, I))
61
+ raises(ValueError, lambda: SingularityFunction(2*I, I, n))
62
+ raises(ValueError, lambda: SingularityFunction(x, a, -3))
63
+
64
+
65
+ def test_leading_term():
66
+ l = Symbol('l', positive=True)
67
+ assert SingularityFunction(x, 3, 2).as_leading_term(x) == 0
68
+ assert SingularityFunction(x, -2, 1).as_leading_term(x) == 2
69
+ assert SingularityFunction(x, 0, 0).as_leading_term(x) == 1
70
+ assert SingularityFunction(x, 0, 0).as_leading_term(x, cdir=-1) == 0
71
+ assert SingularityFunction(x, 0, -1).as_leading_term(x) == 0
72
+ assert SingularityFunction(x, 0, -2).as_leading_term(x) == 0
73
+ assert (SingularityFunction(x + l, 0, 1)/2\
74
+ - SingularityFunction(x + l, l/2, 1)\
75
+ + SingularityFunction(x + l, l, 1)/2).as_leading_term(x) == -x/2
76
+
77
+
78
+ def test_series():
79
+ l = Symbol('l', positive=True)
80
+ assert SingularityFunction(x, -3, 2).series(x) == x**2 + 6*x + 9
81
+ assert SingularityFunction(x, -2, 1).series(x) == x + 2
82
+ assert SingularityFunction(x, 0, 0).series(x) == 1
83
+ assert SingularityFunction(x, 0, 0).series(x, dir='-') == 0
84
+ assert SingularityFunction(x, 0, -1).series(x) == 0
85
+ assert SingularityFunction(x, 0, -2).series(x) == 0
86
+ assert (SingularityFunction(x + l, 0, 1)/2\
87
+ - SingularityFunction(x + l, l/2, 1)\
88
+ + SingularityFunction(x + l, l, 1)/2).nseries(x) == -x/2 + O(x**6)
89
+
90
+
91
+ def test_rewrite():
92
+ assert SingularityFunction(x, 4, 5).rewrite(Piecewise) == (
93
+ Piecewise(((x - 4)**5, x - 4 > 0), (0, True)))
94
+ assert SingularityFunction(x, -10, 0).rewrite(Piecewise) == (
95
+ Piecewise((1, x + 10 > 0), (0, True)))
96
+ assert SingularityFunction(x, 2, -1).rewrite(Piecewise) == (
97
+ Piecewise((oo, Eq(x - 2, 0)), (0, True)))
98
+ assert SingularityFunction(x, 0, -2).rewrite(Piecewise) == (
99
+ Piecewise((oo, Eq(x, 0)), (0, True)))
100
+
101
+ n = Symbol('n', nonnegative=True)
102
+ assert SingularityFunction(x, a, n).rewrite(Piecewise) == (
103
+ Piecewise(((x - a)**n, x - a > 0), (0, True)))
104
+
105
+ expr_in = SingularityFunction(x, 4, 5) + SingularityFunction(x, -3, -1) - SingularityFunction(x, 0, -2)
106
+ expr_out = (x - 4)**5*Heaviside(x - 4) + DiracDelta(x + 3) - DiracDelta(x, 1)
107
+ assert expr_in.rewrite(Heaviside) == expr_out
108
+ assert expr_in.rewrite(DiracDelta) == expr_out
109
+ assert expr_in.rewrite('HeavisideDiracDelta') == expr_out
110
+
111
+ expr_in = SingularityFunction(x, a, n) + SingularityFunction(x, a, -1) - SingularityFunction(x, a, -2)
112
+ expr_out = (x - a)**n*Heaviside(x - a) + DiracDelta(x - a) + DiracDelta(a - x, 1)
113
+ assert expr_in.rewrite(Heaviside) == expr_out
114
+ assert expr_in.rewrite(DiracDelta) == expr_out
115
+ assert expr_in.rewrite('HeavisideDiracDelta') == expr_out
env-llmeval/lib/python3.10/site-packages/sympy/functions/special/tests/test_spec_polynomials.py ADDED
@@ -0,0 +1,475 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.concrete.summations import Sum
2
+ from sympy.core.function import (Derivative, diff)
3
+ from sympy.core.numbers import (Rational, oo, pi, zoo)
4
+ from sympy.core.singleton import S
5
+ from sympy.core.symbol import (Dummy, Symbol)
6
+ from sympy.functions.combinatorial.factorials import (RisingFactorial, binomial, factorial)
7
+ from sympy.functions.elementary.complexes import conjugate
8
+ from sympy.functions.elementary.exponential import exp
9
+ from sympy.functions.elementary.integers import floor
10
+ from sympy.functions.elementary.miscellaneous import sqrt
11
+ from sympy.functions.elementary.trigonometric import cos
12
+ from sympy.functions.special.gamma_functions import gamma
13
+ from sympy.functions.special.hyper import hyper
14
+ from sympy.functions.special.polynomials import (assoc_laguerre, assoc_legendre, chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, gegenbauer, hermite, hermite_prob, jacobi, jacobi_normalized, laguerre, legendre)
15
+ from sympy.polys.orthopolys import laguerre_poly
16
+ from sympy.polys.polyroots import roots
17
+
18
+ from sympy.core.expr import unchanged
19
+ from sympy.core.function import ArgumentIndexError
20
+ from sympy.testing.pytest import raises
21
+
22
+
23
+ x = Symbol('x')
24
+
25
+
26
+ def test_jacobi():
27
+ n = Symbol("n")
28
+ a = Symbol("a")
29
+ b = Symbol("b")
30
+
31
+ assert jacobi(0, a, b, x) == 1
32
+ assert jacobi(1, a, b, x) == a/2 - b/2 + x*(a/2 + b/2 + 1)
33
+
34
+ assert jacobi(n, a, a, x) == RisingFactorial(
35
+ a + 1, n)*gegenbauer(n, a + S.Half, x)/RisingFactorial(2*a + 1, n)
36
+ assert jacobi(n, a, -a, x) == ((-1)**a*(-x + 1)**(-a/2)*(x + 1)**(a/2)*assoc_legendre(n, a, x)*
37
+ factorial(-a + n)*gamma(a + n + 1)/(factorial(a + n)*gamma(n + 1)))
38
+ assert jacobi(n, -b, b, x) == ((-x + 1)**(b/2)*(x + 1)**(-b/2)*assoc_legendre(n, b, x)*
39
+ gamma(-b + n + 1)/gamma(n + 1))
40
+ assert jacobi(n, 0, 0, x) == legendre(n, x)
41
+ assert jacobi(n, S.Half, S.Half, x) == RisingFactorial(
42
+ Rational(3, 2), n)*chebyshevu(n, x)/factorial(n + 1)
43
+ assert jacobi(n, Rational(-1, 2), Rational(-1, 2), x) == RisingFactorial(
44
+ S.Half, n)*chebyshevt(n, x)/factorial(n)
45
+
46
+ X = jacobi(n, a, b, x)
47
+ assert isinstance(X, jacobi)
48
+
49
+ assert jacobi(n, a, b, -x) == (-1)**n*jacobi(n, b, a, x)
50
+ assert jacobi(n, a, b, 0) == 2**(-n)*gamma(a + n + 1)*hyper(
51
+ (-b - n, -n), (a + 1,), -1)/(factorial(n)*gamma(a + 1))
52
+ assert jacobi(n, a, b, 1) == RisingFactorial(a + 1, n)/factorial(n)
53
+
54
+ m = Symbol("m", positive=True)
55
+ assert jacobi(m, a, b, oo) == oo*RisingFactorial(a + b + m + 1, m)
56
+ assert unchanged(jacobi, n, a, b, oo)
57
+
58
+ assert conjugate(jacobi(m, a, b, x)) == \
59
+ jacobi(m, conjugate(a), conjugate(b), conjugate(x))
60
+
61
+ _k = Dummy('k')
62
+ assert diff(jacobi(n, a, b, x), n) == Derivative(jacobi(n, a, b, x), n)
63
+ assert diff(jacobi(n, a, b, x), a).dummy_eq(Sum((jacobi(n, a, b, x) +
64
+ (2*_k + a + b + 1)*RisingFactorial(_k + b + 1, -_k + n)*jacobi(_k, a,
65
+ b, x)/((-_k + n)*RisingFactorial(_k + a + b + 1, -_k + n)))/(_k + a
66
+ + b + n + 1), (_k, 0, n - 1)))
67
+ assert diff(jacobi(n, a, b, x), b).dummy_eq(Sum(((-1)**(-_k + n)*(2*_k +
68
+ a + b + 1)*RisingFactorial(_k + a + 1, -_k + n)*jacobi(_k, a, b, x)/
69
+ ((-_k + n)*RisingFactorial(_k + a + b + 1, -_k + n)) + jacobi(n, a,
70
+ b, x))/(_k + a + b + n + 1), (_k, 0, n - 1)))
71
+ assert diff(jacobi(n, a, b, x), x) == \
72
+ (a/2 + b/2 + n/2 + S.Half)*jacobi(n - 1, a + 1, b + 1, x)
73
+
74
+ assert jacobi_normalized(n, a, b, x) == \
75
+ (jacobi(n, a, b, x)/sqrt(2**(a + b + 1)*gamma(a + n + 1)*gamma(b + n + 1)
76
+ /((a + b + 2*n + 1)*factorial(n)*gamma(a + b + n + 1))))
77
+
78
+ raises(ValueError, lambda: jacobi(-2.1, a, b, x))
79
+ raises(ValueError, lambda: jacobi(Dummy(positive=True, integer=True), 1, 2, oo))
80
+
81
+ assert jacobi(n, a, b, x).rewrite(Sum).dummy_eq(Sum((S.Half - x/2)
82
+ **_k*RisingFactorial(-n, _k)*RisingFactorial(_k + a + 1, -_k + n)*
83
+ RisingFactorial(a + b + n + 1, _k)/factorial(_k), (_k, 0, n))/factorial(n))
84
+ assert jacobi(n, a, b, x).rewrite("polynomial").dummy_eq(Sum((S.Half - x/2)
85
+ **_k*RisingFactorial(-n, _k)*RisingFactorial(_k + a + 1, -_k + n)*
86
+ RisingFactorial(a + b + n + 1, _k)/factorial(_k), (_k, 0, n))/factorial(n))
87
+ raises(ArgumentIndexError, lambda: jacobi(n, a, b, x).fdiff(5))
88
+
89
+
90
+ def test_gegenbauer():
91
+ n = Symbol("n")
92
+ a = Symbol("a")
93
+
94
+ assert gegenbauer(0, a, x) == 1
95
+ assert gegenbauer(1, a, x) == 2*a*x
96
+ assert gegenbauer(2, a, x) == -a + x**2*(2*a**2 + 2*a)
97
+ assert gegenbauer(3, a, x) == \
98
+ x**3*(4*a**3/3 + 4*a**2 + a*Rational(8, 3)) + x*(-2*a**2 - 2*a)
99
+
100
+ assert gegenbauer(-1, a, x) == 0
101
+ assert gegenbauer(n, S.Half, x) == legendre(n, x)
102
+ assert gegenbauer(n, 1, x) == chebyshevu(n, x)
103
+ assert gegenbauer(n, -1, x) == 0
104
+
105
+ X = gegenbauer(n, a, x)
106
+ assert isinstance(X, gegenbauer)
107
+
108
+ assert gegenbauer(n, a, -x) == (-1)**n*gegenbauer(n, a, x)
109
+ assert gegenbauer(n, a, 0) == 2**n*sqrt(pi) * \
110
+ gamma(a + n/2)/(gamma(a)*gamma(-n/2 + S.Half)*gamma(n + 1))
111
+ assert gegenbauer(n, a, 1) == gamma(2*a + n)/(gamma(2*a)*gamma(n + 1))
112
+
113
+ assert gegenbauer(n, Rational(3, 4), -1) is zoo
114
+ assert gegenbauer(n, Rational(1, 4), -1) == (sqrt(2)*cos(pi*(n + S.One/4))*
115
+ gamma(n + S.Half)/(sqrt(pi)*gamma(n + 1)))
116
+
117
+ m = Symbol("m", positive=True)
118
+ assert gegenbauer(m, a, oo) == oo*RisingFactorial(a, m)
119
+ assert unchanged(gegenbauer, n, a, oo)
120
+
121
+ assert conjugate(gegenbauer(n, a, x)) == gegenbauer(n, conjugate(a), conjugate(x))
122
+
123
+ _k = Dummy('k')
124
+
125
+ assert diff(gegenbauer(n, a, x), n) == Derivative(gegenbauer(n, a, x), n)
126
+ assert diff(gegenbauer(n, a, x), a).dummy_eq(Sum((2*(-1)**(-_k + n) + 2)*
127
+ (_k + a)*gegenbauer(_k, a, x)/((-_k + n)*(_k + 2*a + n)) + ((2*_k +
128
+ 2)/((_k + 2*a)*(2*_k + 2*a + 1)) + 2/(_k + 2*a + n))*gegenbauer(n, a
129
+ , x), (_k, 0, n - 1)))
130
+ assert diff(gegenbauer(n, a, x), x) == 2*a*gegenbauer(n - 1, a + 1, x)
131
+
132
+ assert gegenbauer(n, a, x).rewrite(Sum).dummy_eq(
133
+ Sum((-1)**_k*(2*x)**(-2*_k + n)*RisingFactorial(a, -_k + n)
134
+ /(factorial(_k)*factorial(-2*_k + n)), (_k, 0, floor(n/2))))
135
+ assert gegenbauer(n, a, x).rewrite("polynomial").dummy_eq(
136
+ Sum((-1)**_k*(2*x)**(-2*_k + n)*RisingFactorial(a, -_k + n)
137
+ /(factorial(_k)*factorial(-2*_k + n)), (_k, 0, floor(n/2))))
138
+
139
+ raises(ArgumentIndexError, lambda: gegenbauer(n, a, x).fdiff(4))
140
+
141
+
142
+ def test_legendre():
143
+ assert legendre(0, x) == 1
144
+ assert legendre(1, x) == x
145
+ assert legendre(2, x) == ((3*x**2 - 1)/2).expand()
146
+ assert legendre(3, x) == ((5*x**3 - 3*x)/2).expand()
147
+ assert legendre(4, x) == ((35*x**4 - 30*x**2 + 3)/8).expand()
148
+ assert legendre(5, x) == ((63*x**5 - 70*x**3 + 15*x)/8).expand()
149
+ assert legendre(6, x) == ((231*x**6 - 315*x**4 + 105*x**2 - 5)/16).expand()
150
+
151
+ assert legendre(10, -1) == 1
152
+ assert legendre(11, -1) == -1
153
+ assert legendre(10, 1) == 1
154
+ assert legendre(11, 1) == 1
155
+ assert legendre(10, 0) != 0
156
+ assert legendre(11, 0) == 0
157
+
158
+ assert legendre(-1, x) == 1
159
+ k = Symbol('k')
160
+ assert legendre(5 - k, x).subs(k, 2) == ((5*x**3 - 3*x)/2).expand()
161
+
162
+ assert roots(legendre(4, x), x) == {
163
+ sqrt(Rational(3, 7) - Rational(2, 35)*sqrt(30)): 1,
164
+ -sqrt(Rational(3, 7) - Rational(2, 35)*sqrt(30)): 1,
165
+ sqrt(Rational(3, 7) + Rational(2, 35)*sqrt(30)): 1,
166
+ -sqrt(Rational(3, 7) + Rational(2, 35)*sqrt(30)): 1,
167
+ }
168
+
169
+ n = Symbol("n")
170
+
171
+ X = legendre(n, x)
172
+ assert isinstance(X, legendre)
173
+ assert unchanged(legendre, n, x)
174
+
175
+ assert legendre(n, 0) == sqrt(pi)/(gamma(S.Half - n/2)*gamma(n/2 + 1))
176
+ assert legendre(n, 1) == 1
177
+ assert legendre(n, oo) is oo
178
+ assert legendre(-n, x) == legendre(n - 1, x)
179
+ assert legendre(n, -x) == (-1)**n*legendre(n, x)
180
+ assert unchanged(legendre, -n + k, x)
181
+
182
+ assert conjugate(legendre(n, x)) == legendre(n, conjugate(x))
183
+
184
+ assert diff(legendre(n, x), x) == \
185
+ n*(x*legendre(n, x) - legendre(n - 1, x))/(x**2 - 1)
186
+ assert diff(legendre(n, x), n) == Derivative(legendre(n, x), n)
187
+
188
+ _k = Dummy('k')
189
+ assert legendre(n, x).rewrite(Sum).dummy_eq(Sum((-1)**_k*(S.Half -
190
+ x/2)**_k*(x/2 + S.Half)**(-_k + n)*binomial(n, _k)**2, (_k, 0, n)))
191
+ assert legendre(n, x).rewrite("polynomial").dummy_eq(Sum((-1)**_k*(S.Half -
192
+ x/2)**_k*(x/2 + S.Half)**(-_k + n)*binomial(n, _k)**2, (_k, 0, n)))
193
+ raises(ArgumentIndexError, lambda: legendre(n, x).fdiff(1))
194
+ raises(ArgumentIndexError, lambda: legendre(n, x).fdiff(3))
195
+
196
+
197
+ def test_assoc_legendre():
198
+ Plm = assoc_legendre
199
+ Q = sqrt(1 - x**2)
200
+
201
+ assert Plm(0, 0, x) == 1
202
+ assert Plm(1, 0, x) == x
203
+ assert Plm(1, 1, x) == -Q
204
+ assert Plm(2, 0, x) == (3*x**2 - 1)/2
205
+ assert Plm(2, 1, x) == -3*x*Q
206
+ assert Plm(2, 2, x) == 3*Q**2
207
+ assert Plm(3, 0, x) == (5*x**3 - 3*x)/2
208
+ assert Plm(3, 1, x).expand() == (( 3*(1 - 5*x**2)/2 ).expand() * Q).expand()
209
+ assert Plm(3, 2, x) == 15*x * Q**2
210
+ assert Plm(3, 3, x) == -15 * Q**3
211
+
212
+ # negative m
213
+ assert Plm(1, -1, x) == -Plm(1, 1, x)/2
214
+ assert Plm(2, -2, x) == Plm(2, 2, x)/24
215
+ assert Plm(2, -1, x) == -Plm(2, 1, x)/6
216
+ assert Plm(3, -3, x) == -Plm(3, 3, x)/720
217
+ assert Plm(3, -2, x) == Plm(3, 2, x)/120
218
+ assert Plm(3, -1, x) == -Plm(3, 1, x)/12
219
+
220
+ n = Symbol("n")
221
+ m = Symbol("m")
222
+ X = Plm(n, m, x)
223
+ assert isinstance(X, assoc_legendre)
224
+
225
+ assert Plm(n, 0, x) == legendre(n, x)
226
+ assert Plm(n, m, 0) == 2**m*sqrt(pi)/(gamma(-m/2 - n/2 +
227
+ S.Half)*gamma(-m/2 + n/2 + 1))
228
+
229
+ assert diff(Plm(m, n, x), x) == (m*x*assoc_legendre(m, n, x) -
230
+ (m + n)*assoc_legendre(m - 1, n, x))/(x**2 - 1)
231
+
232
+ _k = Dummy('k')
233
+ assert Plm(m, n, x).rewrite(Sum).dummy_eq(
234
+ (1 - x**2)**(n/2)*Sum((-1)**_k*2**(-m)*x**(-2*_k + m - n)*factorial
235
+ (-2*_k + 2*m)/(factorial(_k)*factorial(-_k + m)*factorial(-2*_k + m
236
+ - n)), (_k, 0, floor(m/2 - n/2))))
237
+ assert Plm(m, n, x).rewrite("polynomial").dummy_eq(
238
+ (1 - x**2)**(n/2)*Sum((-1)**_k*2**(-m)*x**(-2*_k + m - n)*factorial
239
+ (-2*_k + 2*m)/(factorial(_k)*factorial(-_k + m)*factorial(-2*_k + m
240
+ - n)), (_k, 0, floor(m/2 - n/2))))
241
+ assert conjugate(assoc_legendre(n, m, x)) == \
242
+ assoc_legendre(n, conjugate(m), conjugate(x))
243
+ raises(ValueError, lambda: Plm(0, 1, x))
244
+ raises(ValueError, lambda: Plm(-1, 1, x))
245
+ raises(ArgumentIndexError, lambda: Plm(n, m, x).fdiff(1))
246
+ raises(ArgumentIndexError, lambda: Plm(n, m, x).fdiff(2))
247
+ raises(ArgumentIndexError, lambda: Plm(n, m, x).fdiff(4))
248
+
249
+
250
+ def test_chebyshev():
251
+ assert chebyshevt(0, x) == 1
252
+ assert chebyshevt(1, x) == x
253
+ assert chebyshevt(2, x) == 2*x**2 - 1
254
+ assert chebyshevt(3, x) == 4*x**3 - 3*x
255
+
256
+ for n in range(1, 4):
257
+ for k in range(n):
258
+ z = chebyshevt_root(n, k)
259
+ assert chebyshevt(n, z) == 0
260
+ raises(ValueError, lambda: chebyshevt_root(n, n))
261
+
262
+ for n in range(1, 4):
263
+ for k in range(n):
264
+ z = chebyshevu_root(n, k)
265
+ assert chebyshevu(n, z) == 0
266
+ raises(ValueError, lambda: chebyshevu_root(n, n))
267
+
268
+ n = Symbol("n")
269
+ X = chebyshevt(n, x)
270
+ assert isinstance(X, chebyshevt)
271
+ assert unchanged(chebyshevt, n, x)
272
+ assert chebyshevt(n, -x) == (-1)**n*chebyshevt(n, x)
273
+ assert chebyshevt(-n, x) == chebyshevt(n, x)
274
+
275
+ assert chebyshevt(n, 0) == cos(pi*n/2)
276
+ assert chebyshevt(n, 1) == 1
277
+ assert chebyshevt(n, oo) is oo
278
+
279
+ assert conjugate(chebyshevt(n, x)) == chebyshevt(n, conjugate(x))
280
+
281
+ assert diff(chebyshevt(n, x), x) == n*chebyshevu(n - 1, x)
282
+
283
+ X = chebyshevu(n, x)
284
+ assert isinstance(X, chebyshevu)
285
+
286
+ y = Symbol('y')
287
+ assert chebyshevu(n, -x) == (-1)**n*chebyshevu(n, x)
288
+ assert chebyshevu(-n, x) == -chebyshevu(n - 2, x)
289
+ assert unchanged(chebyshevu, -n + y, x)
290
+
291
+ assert chebyshevu(n, 0) == cos(pi*n/2)
292
+ assert chebyshevu(n, 1) == n + 1
293
+ assert chebyshevu(n, oo) is oo
294
+
295
+ assert conjugate(chebyshevu(n, x)) == chebyshevu(n, conjugate(x))
296
+
297
+ assert diff(chebyshevu(n, x), x) == \
298
+ (-x*chebyshevu(n, x) + (n + 1)*chebyshevt(n + 1, x))/(x**2 - 1)
299
+
300
+ _k = Dummy('k')
301
+ assert chebyshevt(n, x).rewrite(Sum).dummy_eq(Sum(x**(-2*_k + n)
302
+ *(x**2 - 1)**_k*binomial(n, 2*_k), (_k, 0, floor(n/2))))
303
+ assert chebyshevt(n, x).rewrite("polynomial").dummy_eq(Sum(x**(-2*_k + n)
304
+ *(x**2 - 1)**_k*binomial(n, 2*_k), (_k, 0, floor(n/2))))
305
+ assert chebyshevu(n, x).rewrite(Sum).dummy_eq(Sum((-1)**_k*(2*x)
306
+ **(-2*_k + n)*factorial(-_k + n)/(factorial(_k)*
307
+ factorial(-2*_k + n)), (_k, 0, floor(n/2))))
308
+ assert chebyshevu(n, x).rewrite("polynomial").dummy_eq(Sum((-1)**_k*(2*x)
309
+ **(-2*_k + n)*factorial(-_k + n)/(factorial(_k)*
310
+ factorial(-2*_k + n)), (_k, 0, floor(n/2))))
311
+ raises(ArgumentIndexError, lambda: chebyshevt(n, x).fdiff(1))
312
+ raises(ArgumentIndexError, lambda: chebyshevt(n, x).fdiff(3))
313
+ raises(ArgumentIndexError, lambda: chebyshevu(n, x).fdiff(1))
314
+ raises(ArgumentIndexError, lambda: chebyshevu(n, x).fdiff(3))
315
+
316
+
317
+ def test_hermite():
318
+ assert hermite(0, x) == 1
319
+ assert hermite(1, x) == 2*x
320
+ assert hermite(2, x) == 4*x**2 - 2
321
+ assert hermite(3, x) == 8*x**3 - 12*x
322
+ assert hermite(4, x) == 16*x**4 - 48*x**2 + 12
323
+ assert hermite(6, x) == 64*x**6 - 480*x**4 + 720*x**2 - 120
324
+
325
+ n = Symbol("n")
326
+ assert unchanged(hermite, n, x)
327
+ assert hermite(n, -x) == (-1)**n*hermite(n, x)
328
+ assert unchanged(hermite, -n, x)
329
+
330
+ assert hermite(n, 0) == 2**n*sqrt(pi)/gamma(S.Half - n/2)
331
+ assert hermite(n, oo) is oo
332
+
333
+ assert conjugate(hermite(n, x)) == hermite(n, conjugate(x))
334
+
335
+ _k = Dummy('k')
336
+ assert hermite(n, x).rewrite(Sum).dummy_eq(factorial(n)*Sum((-1)
337
+ **_k*(2*x)**(-2*_k + n)/(factorial(_k)*factorial(-2*_k + n)), (_k,
338
+ 0, floor(n/2))))
339
+ assert hermite(n, x).rewrite("polynomial").dummy_eq(factorial(n)*Sum((-1)
340
+ **_k*(2*x)**(-2*_k + n)/(factorial(_k)*factorial(-2*_k + n)), (_k,
341
+ 0, floor(n/2))))
342
+
343
+ assert diff(hermite(n, x), x) == 2*n*hermite(n - 1, x)
344
+ assert diff(hermite(n, x), n) == Derivative(hermite(n, x), n)
345
+ raises(ArgumentIndexError, lambda: hermite(n, x).fdiff(3))
346
+
347
+ assert hermite(n, x).rewrite(hermite_prob) == \
348
+ sqrt(2)**n * hermite_prob(n, x*sqrt(2))
349
+
350
+
351
+ def test_hermite_prob():
352
+ assert hermite_prob(0, x) == 1
353
+ assert hermite_prob(1, x) == x
354
+ assert hermite_prob(2, x) == x**2 - 1
355
+ assert hermite_prob(3, x) == x**3 - 3*x
356
+ assert hermite_prob(4, x) == x**4 - 6*x**2 + 3
357
+ assert hermite_prob(6, x) == x**6 - 15*x**4 + 45*x**2 - 15
358
+
359
+ n = Symbol("n")
360
+ assert unchanged(hermite_prob, n, x)
361
+ assert hermite_prob(n, -x) == (-1)**n*hermite_prob(n, x)
362
+ assert unchanged(hermite_prob, -n, x)
363
+
364
+ assert hermite_prob(n, 0) == sqrt(pi)/gamma(S.Half - n/2)
365
+ assert hermite_prob(n, oo) is oo
366
+
367
+ assert conjugate(hermite_prob(n, x)) == hermite_prob(n, conjugate(x))
368
+
369
+ _k = Dummy('k')
370
+ assert hermite_prob(n, x).rewrite(Sum).dummy_eq(factorial(n) *
371
+ Sum((-S.Half)**_k * x**(n-2*_k) / (factorial(_k) * factorial(n-2*_k)),
372
+ (_k, 0, floor(n/2))))
373
+ assert hermite_prob(n, x).rewrite("polynomial").dummy_eq(factorial(n) *
374
+ Sum((-S.Half)**_k * x**(n-2*_k) / (factorial(_k) * factorial(n-2*_k)),
375
+ (_k, 0, floor(n/2))))
376
+
377
+ assert diff(hermite_prob(n, x), x) == n*hermite_prob(n-1, x)
378
+ assert diff(hermite_prob(n, x), n) == Derivative(hermite_prob(n, x), n)
379
+ raises(ArgumentIndexError, lambda: hermite_prob(n, x).fdiff(3))
380
+
381
+ assert hermite_prob(n, x).rewrite(hermite) == \
382
+ sqrt(2)**(-n) * hermite(n, x/sqrt(2))
383
+
384
+
385
+ def test_laguerre():
386
+ n = Symbol("n")
387
+ m = Symbol("m", negative=True)
388
+
389
+ # Laguerre polynomials:
390
+ assert laguerre(0, x) == 1
391
+ assert laguerre(1, x) == -x + 1
392
+ assert laguerre(2, x) == x**2/2 - 2*x + 1
393
+ assert laguerre(3, x) == -x**3/6 + 3*x**2/2 - 3*x + 1
394
+ assert laguerre(-2, x) == (x + 1)*exp(x)
395
+
396
+ X = laguerre(n, x)
397
+ assert isinstance(X, laguerre)
398
+
399
+ assert laguerre(n, 0) == 1
400
+ assert laguerre(n, oo) == (-1)**n*oo
401
+ assert laguerre(n, -oo) is oo
402
+
403
+ assert conjugate(laguerre(n, x)) == laguerre(n, conjugate(x))
404
+
405
+ _k = Dummy('k')
406
+
407
+ assert laguerre(n, x).rewrite(Sum).dummy_eq(
408
+ Sum(x**_k*RisingFactorial(-n, _k)/factorial(_k)**2, (_k, 0, n)))
409
+ assert laguerre(n, x).rewrite("polynomial").dummy_eq(
410
+ Sum(x**_k*RisingFactorial(-n, _k)/factorial(_k)**2, (_k, 0, n)))
411
+ assert laguerre(m, x).rewrite(Sum).dummy_eq(
412
+ exp(x)*Sum((-x)**_k*RisingFactorial(m + 1, _k)/factorial(_k)**2,
413
+ (_k, 0, -m - 1)))
414
+ assert laguerre(m, x).rewrite("polynomial").dummy_eq(
415
+ exp(x)*Sum((-x)**_k*RisingFactorial(m + 1, _k)/factorial(_k)**2,
416
+ (_k, 0, -m - 1)))
417
+
418
+ assert diff(laguerre(n, x), x) == -assoc_laguerre(n - 1, 1, x)
419
+
420
+ k = Symbol('k')
421
+ assert laguerre(-n, x) == exp(x)*laguerre(n - 1, -x)
422
+ assert laguerre(-3, x) == exp(x)*laguerre(2, -x)
423
+ assert unchanged(laguerre, -n + k, x)
424
+
425
+ raises(ValueError, lambda: laguerre(-2.1, x))
426
+ raises(ValueError, lambda: laguerre(Rational(5, 2), x))
427
+ raises(ArgumentIndexError, lambda: laguerre(n, x).fdiff(1))
428
+ raises(ArgumentIndexError, lambda: laguerre(n, x).fdiff(3))
429
+
430
+
431
+ def test_assoc_laguerre():
432
+ n = Symbol("n")
433
+ m = Symbol("m")
434
+ alpha = Symbol("alpha")
435
+
436
+ # generalized Laguerre polynomials:
437
+ assert assoc_laguerre(0, alpha, x) == 1
438
+ assert assoc_laguerre(1, alpha, x) == -x + alpha + 1
439
+ assert assoc_laguerre(2, alpha, x).expand() == \
440
+ (x**2/2 - (alpha + 2)*x + (alpha + 2)*(alpha + 1)/2).expand()
441
+ assert assoc_laguerre(3, alpha, x).expand() == \
442
+ (-x**3/6 + (alpha + 3)*x**2/2 - (alpha + 2)*(alpha + 3)*x/2 +
443
+ (alpha + 1)*(alpha + 2)*(alpha + 3)/6).expand()
444
+
445
+ # Test the lowest 10 polynomials with laguerre_poly, to make sure it works:
446
+ for i in range(10):
447
+ assert assoc_laguerre(i, 0, x).expand() == laguerre_poly(i, x)
448
+
449
+ X = assoc_laguerre(n, m, x)
450
+ assert isinstance(X, assoc_laguerre)
451
+
452
+ assert assoc_laguerre(n, 0, x) == laguerre(n, x)
453
+ assert assoc_laguerre(n, alpha, 0) == binomial(alpha + n, alpha)
454
+ p = Symbol("p", positive=True)
455
+ assert assoc_laguerre(p, alpha, oo) == (-1)**p*oo
456
+ assert assoc_laguerre(p, alpha, -oo) is oo
457
+
458
+ assert diff(assoc_laguerre(n, alpha, x), x) == \
459
+ -assoc_laguerre(n - 1, alpha + 1, x)
460
+ _k = Dummy('k')
461
+ assert diff(assoc_laguerre(n, alpha, x), alpha).dummy_eq(
462
+ Sum(assoc_laguerre(_k, alpha, x)/(-alpha + n), (_k, 0, n - 1)))
463
+
464
+ assert conjugate(assoc_laguerre(n, alpha, x)) == \
465
+ assoc_laguerre(n, conjugate(alpha), conjugate(x))
466
+
467
+ assert assoc_laguerre(n, alpha, x).rewrite(Sum).dummy_eq(
468
+ gamma(alpha + n + 1)*Sum(x**_k*RisingFactorial(-n, _k)/
469
+ (factorial(_k)*gamma(_k + alpha + 1)), (_k, 0, n))/factorial(n))
470
+ assert assoc_laguerre(n, alpha, x).rewrite("polynomial").dummy_eq(
471
+ gamma(alpha + n + 1)*Sum(x**_k*RisingFactorial(-n, _k)/
472
+ (factorial(_k)*gamma(_k + alpha + 1)), (_k, 0, n))/factorial(n))
473
+ raises(ValueError, lambda: assoc_laguerre(-2.1, alpha, x))
474
+ raises(ArgumentIndexError, lambda: assoc_laguerre(n, alpha, x).fdiff(1))
475
+ raises(ArgumentIndexError, lambda: assoc_laguerre(n, alpha, x).fdiff(4))
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (1.61 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/anticommutator.cpython-310.pyc ADDED
Binary file (4.73 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/boson.cpython-310.pyc ADDED
Binary file (8.48 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/cartesian.cpython-310.pyc ADDED
Binary file (11.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/cg.cpython-310.pyc ADDED
Binary file (22 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/circuitplot.cpython-310.pyc ADDED
Binary file (10.7 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/circuitutils.cpython-310.pyc ADDED
Binary file (11 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/dagger.cpython-310.pyc ADDED
Binary file (2.86 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/density.cpython-310.pyc ADDED
Binary file (10.4 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/fermion.cpython-310.pyc ADDED
Binary file (5.74 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/grover.cpython-310.pyc ADDED
Binary file (9.64 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/hilbert.cpython-310.pyc ADDED
Binary file (19.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/innerproduct.cpython-310.pyc ADDED
Binary file (4.29 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/matrixutils.cpython-310.pyc ADDED
Binary file (7.38 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/operator.cpython-310.pyc ADDED
Binary file (19.8 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/qasm.cpython-310.pyc ADDED
Binary file (8.18 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/qexpr.cpython-310.pyc ADDED
Binary file (13 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/qft.cpython-310.pyc ADDED
Binary file (7.21 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/represent.cpython-310.pyc ADDED
Binary file (15.1 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/__pycache__/tensorproduct.cpython-310.pyc ADDED
Binary file (13.5 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__init__.py ADDED
File without changes
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_anticommutator.cpython-310.pyc ADDED
Binary file (2.35 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_cartesian.cpython-310.pyc ADDED
Binary file (3.9 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_cg.cpython-310.pyc ADDED
Binary file (7.04 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_circuitplot.cpython-310.pyc ADDED
Binary file (2.8 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_circuitutils.cpython-310.pyc ADDED
Binary file (8.81 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_commutator.cpython-310.pyc ADDED
Binary file (3.46 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_constants.cpython-310.pyc ADDED
Binary file (601 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_density.cpython-310.pyc ADDED
Binary file (8.46 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_gate.cpython-310.pyc ADDED
Binary file (12 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_grover.cpython-310.pyc ADDED
Binary file (3.45 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_hilbert.cpython-310.pyc ADDED
Binary file (2.93 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_identitysearch.cpython-310.pyc ADDED
Binary file (10.1 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_innerproduct.cpython-310.pyc ADDED
Binary file (2.83 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_operatorset.cpython-310.pyc ADDED
Binary file (2.51 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_pauli.cpython-310.pyc ADDED
Binary file (5.31 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_piab.cpython-310.pyc ADDED
Binary file (1.6 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_qapply.cpython-310.pyc ADDED
Binary file (6.35 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_qexpr.cpython-310.pyc ADDED
Binary file (1.9 kB). View file
 
env-llmeval/lib/python3.10/site-packages/sympy/physics/quantum/tests/__pycache__/test_qubit.cpython-310.pyc ADDED
Binary file (7.98 kB). View file