def test_jacobi(): assert jacobi(0, a, b, x) == 1 assert jacobi(1, a, b, x) == a / 2 - b / 2 + x * (a / 2 + b / 2 + 1) assert (jacobi(2, a, b, x) == a**2 / 8 - a * b / 4 - a / 8 + b**2 / 8 - b / 8 + x**2 * (a**2 / 8 + a * b / 4 + 7 * a / 8 + b**2 / 8 + 7 * b / 8 + Rational(3, 2)) + x * (a**2 / 4 + 3 * a / 4 - b**2 / 4 - 3 * b / 4) - S.Half) assert jacobi(n, a, a, x) == RisingFactorial(a + 1, n) * gegenbauer( n, a + Rational(1, 2), x) / RisingFactorial(2 * a + 1, n) assert jacobi(n, a, -a, x) == ((-1)**a * (-x + 1)**(-a / 2) * (x + 1)**(a / 2) * assoc_legendre(n, a, x) * factorial(-a + n) * gamma(a + n + 1) / (factorial(a + n) * gamma(n + 1))) assert jacobi(n, -b, b, x) == ((-x + 1)**(b / 2) * (x + 1)**(-b / 2) * assoc_legendre(n, b, x) * gamma(-b + n + 1) / gamma(n + 1)) assert jacobi(n, 0, 0, x) == legendre(n, x) assert jacobi(n, S.Half, S.Half, x) == RisingFactorial(Rational( 3, 2), n) * chebyshevu(n, x) / factorial(n + 1) assert jacobi(n, -S.Half, -S.Half, x) == RisingFactorial( Rational(1, 2), n) * chebyshevt(n, x) / factorial(n) X = jacobi(n, a, b, x) assert isinstance(X, jacobi) assert jacobi(n, a, b, -x) == (-1)**n * jacobi(n, b, a, x) assert jacobi(n, a, b, 0) == 2**(-n) * gamma(a + n + 1) * hyper( (-b - n, -n), (a + 1, ), -1) / (factorial(n) * gamma(a + 1)) assert jacobi(n, a, b, 1) == RisingFactorial(a + 1, n) / factorial(n) m = Symbol("m", positive=True) assert jacobi(m, a, b, oo) == oo * RisingFactorial(a + b + m + 1, m) assert conjugate(jacobi(m, a, b, x)) == \ jacobi(m, conjugate(a), conjugate(b), conjugate(x)) assert diff(jacobi(n, a, b, x), n) == Derivative(jacobi(n, a, b, x), n) assert diff(jacobi(n, a, b, x), x) == \ (a/2 + b/2 + n/2 + Rational(1, 2))*jacobi(n - 1, a + 1, b + 1, x) # XXX see issue sympy/sympy#5539 assert str(jacobi(n, a, b, x).diff(a)) == \ ("Sum((jacobi(n, a, b, x) + (a + b + 2*_k + 1)*RisingFactorial(b + " "_k + 1, n - _k)*jacobi(_k, a, b, x)/((n - _k)*RisingFactorial(a + " "b + _k + 1, n - _k)))/(a + b + n + _k + 1), (_k, 0, n - 1))") assert str(jacobi(n, a, b, x).diff(b)) == \ ("Sum(((-1)**(n - _k)*(a + b + 2*_k + 1)*RisingFactorial(a + " "_k + 1, n - _k)*jacobi(_k, a, b, x)/((n - _k)*RisingFactorial(a + " "b + _k + 1, n - _k)) + jacobi(n, a, b, x))/(a + b + n + " "_k + 1), (_k, 0, n - 1))") assert jacobi_normalized(n, a, b, x) == \ (jacobi(n, a, b, x)/sqrt(2**(a + b + 1)*gamma(a + n + 1)*gamma(b + n + 1) / ((a + b + 2*n + 1)*factorial(n)*gamma(a + b + n + 1)))) pytest.raises(ValueError, lambda: jacobi(-2.1, a, b, x)) pytest.raises(ValueError, lambda: jacobi(Dummy(positive=True, integer=True), 1, 2, oo)) pytest.raises(ArgumentIndexError, lambda: jacobi(n, a, b, x).fdiff(5))
def test_jacobi(): assert jacobi(0, a, b, x) == 1 assert jacobi(1, a, b, x) == a/2 - b/2 + x*(a/2 + b/2 + 1) assert (jacobi(2, a, b, x) == a**2/8 - a*b/4 - a/8 + b**2/8 - b/8 + x**2*(a**2/8 + a*b/4 + 7*a/8 + b**2/8 + 7*b/8 + Rational(3, 2)) + x*(a**2/4 + 3*a/4 - b**2/4 - 3*b/4) - Rational(1, 2)) assert jacobi(n, a, a, x) == RisingFactorial( a + 1, n)*gegenbauer(n, a + Rational(1, 2), x)/RisingFactorial(2*a + 1, n) assert jacobi(n, a, -a, x) == ((-1)**a*(-x + 1)**(-a/2)*(x + 1)**(a/2)*assoc_legendre(n, a, x) * factorial(-a + n)*gamma(a + n + 1)/(factorial(a + n)*gamma(n + 1))) assert jacobi(n, -b, b, x) == ((-x + 1)**(b/2)*(x + 1)**(-b/2)*assoc_legendre(n, b, x) * gamma(-b + n + 1)/gamma(n + 1)) assert jacobi(n, 0, 0, x) == legendre(n, x) assert jacobi(n, Rational(1, 2), Rational(1, 2), x) == RisingFactorial( Rational(3, 2), n)*chebyshevu(n, x)/factorial(n + 1) assert jacobi(n, Rational(-1, 2), Rational(-1, 2), x) == RisingFactorial( Rational(1, 2), n)*chebyshevt(n, x)/factorial(n) X = jacobi(n, a, b, x) assert isinstance(X, jacobi) assert jacobi(n, a, b, -x) == (-1)**n*jacobi(n, b, a, x) assert jacobi(n, a, b, 0) == 2**(-n)*gamma(a + n + 1)*hyper( (-b - n, -n), (a + 1,), -1)/(factorial(n)*gamma(a + 1)) assert jacobi(n, a, b, 1) == RisingFactorial(a + 1, n)/factorial(n) m = Symbol("m", positive=True) assert jacobi(m, a, b, oo) == oo*RisingFactorial(a + b + m + 1, m) assert jacobi(n, a, b, oo) == jacobi(n, a, b, oo, evaluate=False) assert conjugate(jacobi(m, a, b, x)) == \ jacobi(m, conjugate(a), conjugate(b), conjugate(x)) assert diff(jacobi(n, a, b, x), n) == Derivative(jacobi(n, a, b, x), n) assert diff(jacobi(n, a, b, x), x) == \ (a/2 + b/2 + n/2 + Rational(1, 2))*jacobi(n - 1, a + 1, b + 1, x) # XXX see issue sympy/sympy#5539 assert str(jacobi(n, a, b, x).diff(a)) == \ ("Sum((jacobi(n, a, b, x) + (a + b + 2*_k + 1)*RisingFactorial(b + " "_k + 1, n - _k)*jacobi(_k, a, b, x)/((n - _k)*RisingFactorial(a + " "b + _k + 1, n - _k)))/(a + b + n + _k + 1), (_k, 0, n - 1))") assert str(jacobi(n, a, b, x).diff(b)) == \ ("Sum(((-1)**(n - _k)*(a + b + 2*_k + 1)*RisingFactorial(a + " "_k + 1, n - _k)*jacobi(_k, a, b, x)/((n - _k)*RisingFactorial(a + " "b + _k + 1, n - _k)) + jacobi(n, a, b, x))/(a + b + n + " "_k + 1), (_k, 0, n - 1))") assert jacobi_normalized(n, a, b, x) == \ (jacobi(n, a, b, x)/sqrt(2**(a + b + 1)*gamma(a + n + 1)*gamma(b + n + 1) / ((a + b + 2*n + 1)*factorial(n)*gamma(a + b + n + 1)))) pytest.raises(ValueError, lambda: jacobi(-2.1, a, b, x)) pytest.raises(ValueError, lambda: jacobi(Dummy(positive=True, integer=True), 1, 2, oo)) pytest.raises(ArgumentIndexError, lambda: jacobi(n, a, b, x).fdiff(5))
def test_gegenbauer(): assert gegenbauer(0, a, x) == 1 assert gegenbauer(1, a, x) == 2 * a * x assert gegenbauer(2, a, x) == -a + x**2 * (2 * a**2 + 2 * a) assert gegenbauer(3, a, x) == \ x**3*(4*a**3/3 + 4*a**2 + 8*a/3) + x*(-2*a**2 - 2*a) assert gegenbauer(-1, a, x) == 0 assert gegenbauer(n, Rational(1, 2), x) == legendre(n, x) assert gegenbauer(n, 1, x) == chebyshevu(n, x) assert gegenbauer(n, -1, x) == 0 X = gegenbauer(n, a, x) assert isinstance(X, gegenbauer) assert gegenbauer(n, a, -x) == (-1)**n * gegenbauer(n, a, x) assert gegenbauer(n, a, 0) == 2**n*sqrt(pi) * \ gamma(a + n/2)/(gamma(a)*gamma(-n/2 + Rational(1, 2))*gamma(n + 1)) assert gegenbauer(n, a, 1) == gamma(2 * a + n) / (gamma(2 * a) * gamma(n + 1)) assert gegenbauer(n, Rational(3, 4), -1) == zoo m = Symbol("m", positive=True) assert gegenbauer(m, a, oo) == oo * RisingFactorial(a, m) assert conjugate(gegenbauer(n, a, x)) == gegenbauer(n, conjugate(a), conjugate(x)) assert diff(gegenbauer(n, a, x), n) == Derivative(gegenbauer(n, a, x), n) assert diff(gegenbauer(n, a, x), x) == 2 * a * gegenbauer(n - 1, a + 1, x) pytest.raises(ArgumentIndexError, lambda: gegenbauer(n, a, x).fdiff(4)) # XXX see issue sympy/sympy#5539 assert str(gegenbauer(n, a, x).diff(a)) == \ ("Sum((2*(-1)**(n - _k) + 2)*(a + _k)*gegenbauer(_k, a, x)/((n - " "_k)*(2*a + n + _k)) + (2/(2*a + n + _k) + (2*_k + 2)/((2*a + " "_k)*(2*a + 2*_k + 1)))*gegenbauer(n, a, x), (_k, 0, n - 1))")
def test_gegenbauer(): assert gegenbauer(0, a, x) == 1 assert gegenbauer(1, a, x) == 2*a*x assert gegenbauer(2, a, x) == -a + x**2*(2*a**2 + 2*a) assert gegenbauer(3, a, x) == \ x**3*(4*a**3/3 + 4*a**2 + 8*a/3) + x*(-2*a**2 - 2*a) assert gegenbauer(-1, a, x) == 0 assert gegenbauer(n, Rational(1, 2), x) == legendre(n, x) assert gegenbauer(n, 1, x) == chebyshevu(n, x) assert gegenbauer(n, -1, x) == 0 assert gegenbauer(n, -2, -1) == gegenbauer(n, -2, -1, evaluate=False) X = gegenbauer(n, a, x) assert isinstance(X, gegenbauer) assert gegenbauer(n, a, -x) == (-1)**n*gegenbauer(n, a, x) assert gegenbauer(n, a, 0) == 2**n*sqrt(pi) * \ gamma(a + n/2)/(gamma(a)*gamma(-n/2 + Rational(1, 2))*gamma(n + 1)) assert gegenbauer(n, a, 1) == gamma(2*a + n)/(gamma(2*a)*gamma(n + 1)) assert gegenbauer(n, Rational(3, 4), -1) == zoo m = Symbol("m", positive=True) assert gegenbauer(m, a, oo) == oo*RisingFactorial(a, m) assert gegenbauer(n, a, oo) == gegenbauer(n, a, oo, evaluate=False) assert conjugate(gegenbauer(n, a, x)) == gegenbauer(n, conjugate(a), conjugate(x)) assert diff(gegenbauer(n, a, x), n) == Derivative(gegenbauer(n, a, x), n) assert diff(gegenbauer(n, a, x), x) == 2*a*gegenbauer(n - 1, a + 1, x) pytest.raises(ArgumentIndexError, lambda: gegenbauer(n, a, x).fdiff(4)) # XXX see issue sympy/sympy#5539 assert str(gegenbauer(n, a, x).diff(a)) == \ ("Sum((2*(-1)**(n - _k) + 2)*(a + _k)*gegenbauer(_k, a, x)/((n - " "_k)*(2*a + n + _k)) + (2/(2*a + n + _k) + (2*_k + 2)/((2*a + " "_k)*(2*a + 2*_k + 1)))*gegenbauer(n, a, x), (_k, 0, n - 1))")