def test_specfun(): n = Symbol('n') for f in [besselj, bessely, besseli, besselk]: assert octave_code(f(n, x)) == f.__name__ + '(n, x)' assert octave_code(hankel1(n, x)) == 'besselh(n, 1, x)' assert octave_code(hankel2(n, x)) == 'besselh(n, 2, x)' assert octave_code(airyai(x)) == 'airy(0, x)' assert octave_code(airyaiprime(x)) == 'airy(1, x)' assert octave_code(airybi(x)) == 'airy(2, x)' assert octave_code(airybiprime(x)) == 'airy(3, x)' assert octave_code(jn(n, x)) == 'sqrt(2)*sqrt(pi)*sqrt(1./x).*besselj(n + 1/2, x)/2' assert octave_code(yn(n, x)) == 'sqrt(2)*sqrt(pi)*sqrt(1./x).*bessely(n + 1/2, x)/2'
def test_airyai(): z = Symbol('z', extended_real=False) r = Symbol('r', extended_real=True) t = Symbol('t', negative=True) p = Symbol('p', positive=True) assert isinstance(airyai(z), airyai) assert airyai(0) == cbrt(3)/(3*gamma(Rational(2, 3))) assert airyai(oo) == 0 assert airyai(-oo) == 0 assert diff(airyai(z), z) == airyaiprime(z) assert series(airyai(z), z, 0, 3) == ( 3**Rational(5, 6)*gamma(Rational(1, 3))/(6*pi) - root(3, 6)*z*gamma(Rational(2, 3))/(2*pi) + O(z**3)) l = Limit(airyai(I/x)/(exp(-Rational(2, 3)*(I/x)**Rational(3, 2))*sqrt(pi*sqrt(I/x))/2), x, 0) assert l.doit() == l # cover _airyais._eval_aseries assert airyai(z).rewrite(hyper) == ( -3**Rational(2, 3)*z*hyper((), (Rational(4, 3),), z**3/9)/(3*gamma(Rational(1, 3))) + cbrt(3)*hyper((), (Rational(2, 3),), z**3/9)/(3*gamma(Rational(2, 3)))) assert isinstance(airyai(z).rewrite(besselj), airyai) assert airyai(t).rewrite(besselj) == ( sqrt(-t)*(besselj(-Rational(1, 3), 2*(-t)**Rational(3, 2)/3) + besselj(Rational(1, 3), 2*(-t)**Rational(3, 2)/3))/3) assert airyai(z).rewrite(besseli) == ( -z*besseli(Rational(1, 3), 2*z**Rational(3, 2)/3)/(3*cbrt(z**Rational(3, 2))) + cbrt(z**Rational(3, 2))*besseli(-Rational(1, 3), 2*z**Rational(3, 2)/3)/3) assert airyai(p).rewrite(besseli) == ( sqrt(p)*(besseli(-Rational(1, 3), 2*p**Rational(3, 2)/3) - besseli(Rational(1, 3), 2*p**Rational(3, 2)/3))/3) assert expand_func(airyai(2*cbrt(3*z**5))) == ( -sqrt(3)*(-1 + cbrt(z**5)/z**Rational(5, 3))*airybi(2*cbrt(3)*z**Rational(5, 3))/6 + (1 + cbrt(z**5)/z**Rational(5, 3))*airyai(2*cbrt(3)*z**Rational(5, 3))/2) assert expand_func(airyai(x*y)) == airyai(x*y) assert expand_func(airyai(log(x))) == airyai(log(x)) assert expand_func(airyai(2*root(3*z**5, 5))) == airyai(2*root(3*z**5, 5)) assert (airyai(r).as_real_imag() == airyai(r).as_real_imag(deep=False) == (airyai(r), 0)) assert airyai(x).as_real_imag() == airyai(x).as_real_imag(deep=False) assert (airyai(x).as_real_imag() == (airyai(re(x) - I*re(x)*abs(im(x))/abs(re(x)))/2 + airyai(re(x) + I*re(x)*abs(im(x))/abs(re(x)))/2, I*(airyai(re(x) - I*re(x)*abs(im(x))/abs(re(x))) - airyai(re(x) + I*re(x)*abs(im(x))/Abs(re(x)))) * re(x)*abs(im(x))/(2*im(x)*abs(re(x))))) assert airyai(x).taylor_term(-1, x) == 0
def test_airybiprime(): z = Symbol('z', extended_real=False) t = Symbol('t', negative=True) p = Symbol('p', positive=True) assert isinstance(airybiprime(z), airybiprime) assert airybiprime(0) == root(3, 6) / gamma(Rational(1, 3)) assert airybiprime(oo) == oo assert airybiprime(-oo) == 0 assert diff(airybiprime(z), z) == z * airybi(z) assert series(airybiprime(z), z, 0, 3) == (root(3, 6) / gamma(Rational(1, 3)) + 3**Rational(5, 6) * z**2 / (6 * gamma(Rational(2, 3))) + O(z**3)) assert airybiprime(z).rewrite(hyper) == ( 3**Rational(5, 6) * z**2 * hyper((), (Rational(5, 3), ), z**3 / 9) / (6 * gamma(Rational(2, 3))) + root(3, 6) * hyper( (), (Rational(1, 3), ), z**3 / 9) / gamma(Rational(1, 3))) assert isinstance(airybiprime(z).rewrite(besselj), airybiprime) assert (airybiprime(t).rewrite(besselj) == -sqrt(3) * t * (besselj(-Rational(2, 3), 2 * (-t)**Rational(3, 2) / 3) + besselj(Rational(2, 3), 2 * (-t)**Rational(3, 2) / 3)) / 3) assert airybiprime(z).rewrite(besseli) == ( sqrt(3) * (z**2 * besseli(Rational(2, 3), 2 * z**Rational(3, 2) / 3) / (z**Rational(3, 2))**Rational(2, 3) + (z**Rational(3, 2))**Rational(2, 3) * besseli(-Rational(2, 3), 2 * z**Rational(3, 2) / 3)) / 3) assert airybiprime(p).rewrite(besseli) == ( sqrt(3) * p * (besseli(-Rational(2, 3), 2 * p**Rational(3, 2) / 3) + besseli(Rational(2, 3), 2 * p**Rational(3, 2) / 3)) / 3) assert airybiprime(p).rewrite(besselj) == airybiprime(p) assert expand_func(airybiprime( 2 * cbrt(3 * z**5))) == (sqrt(3) * (z**Rational(5, 3) / cbrt(z**5) - 1) * airyaiprime(2 * cbrt(3) * z**Rational(5, 3)) / 2 + (z**Rational(5, 3) / cbrt(z**5) + 1) * airybiprime(2 * cbrt(3) * z**Rational(5, 3)) / 2) assert expand_func(airybiprime(x * y)) == airybiprime(x * y) assert expand_func(airybiprime(log(x))) == airybiprime(log(x)) assert expand_func(airybiprime(2 * root(3 * z**5, 5))) == airybiprime( 2 * root(3 * z**5, 5)) assert airybiprime(-2).evalf(50) == Float( '0.27879516692116952268509756941098324140300059345163131', dps=50)
def test_diff(): assert besselj(n, z).diff(z) == besselj(n - 1, z)/2 - besselj(n + 1, z)/2 assert bessely(n, z).diff(z) == bessely(n - 1, z)/2 - bessely(n + 1, z)/2 assert besseli(n, z).diff(z) == besseli(n - 1, z)/2 + besseli(n + 1, z)/2 assert besselk(n, z).diff(z) == -besselk(n - 1, z)/2 - besselk(n + 1, z)/2 assert hankel1(n, z).diff(z) == hankel1(n - 1, z)/2 - hankel1(n + 1, z)/2 assert hankel2(n, z).diff(z) == hankel2(n - 1, z)/2 - hankel2(n + 1, z)/2 pytest.raises(ArgumentIndexError, lambda: besselj(n, z).fdiff(3)) pytest.raises(ArgumentIndexError, lambda: jn(n, z).fdiff(3)) pytest.raises(ArgumentIndexError, lambda: airyai(z).fdiff(2)) pytest.raises(ArgumentIndexError, lambda: airybi(z).fdiff(2)) pytest.raises(ArgumentIndexError, lambda: airyaiprime(z).fdiff(2)) pytest.raises(ArgumentIndexError, lambda: airybiprime(z).fdiff(2))
def test_airyai(): z = Symbol('z', extended_real=False) t = Symbol('t', negative=True) p = Symbol('p', positive=True) assert isinstance(airyai(z), airyai) assert airyai(0) == 3**Rational(1, 3) / (3 * gamma(Rational(2, 3))) assert airyai(oo) == 0 assert airyai(-oo) == 0 assert diff(airyai(z), z) == airyaiprime(z) assert series(airyai(z), z, 0, 3) == (3**Rational(5, 6) * gamma(Rational(1, 3)) / (6 * pi) - 3**Rational(1, 6) * z * gamma(Rational(2, 3)) / (2 * pi) + O(z**3)) assert airyai(z).rewrite(hyper) == (-3**Rational(2, 3) * z * hyper( (), (Rational(4, 3), ), z**Integer(3) / 9) / (3 * gamma(Rational(1, 3))) + 3**Rational(1, 3) * hyper( (), (Rational(2, 3), ), z**Integer(3) / 9) / (3 * gamma(Rational(2, 3)))) assert isinstance(airyai(z).rewrite(besselj), airyai) assert airyai(t).rewrite(besselj) == ( sqrt(-t) * (besselj(-Rational(1, 3), 2 * (-t)**Rational(3, 2) / 3) + besselj(Rational(1, 3), 2 * (-t)**Rational(3, 2) / 3)) / 3) assert airyai(z).rewrite(besseli) == ( -z * besseli(Rational(1, 3), 2 * z**Rational(3, 2) / 3) / (3 * (z**Rational(3, 2))**Rational(1, 3)) + (z**Rational(3, 2))**Rational(1, 3) * besseli(-Rational(1, 3), 2 * z**Rational(3, 2) / 3) / 3) assert airyai(p).rewrite(besseli) == ( sqrt(p) * (besseli(-Rational(1, 3), 2 * p**Rational(3, 2) / 3) - besseli(Rational(1, 3), 2 * p**Rational(3, 2) / 3)) / 3) assert expand_func(airyai(2 * (3 * z**5)**Rational(1, 3))) == ( -sqrt(3) * (-1 + (z**5)**Rational(1, 3) / z**Rational(5, 3)) * airybi(2 * 3**Rational(1, 3) * z**Rational(5, 3)) / 6 + (1 + (z**5)**Rational(1, 3) / z**Rational(5, 3)) * airyai(2 * 3**Rational(1, 3) * z**Rational(5, 3)) / 2)
def test_diff(): assert besselj(n, z).diff(z) == besselj(n - 1, z) / 2 - besselj(n + 1, z) / 2 assert bessely(n, z).diff(z) == bessely(n - 1, z) / 2 - bessely(n + 1, z) / 2 assert besseli(n, z).diff(z) == besseli(n - 1, z) / 2 + besseli(n + 1, z) / 2 assert besselk(n, z).diff(z) == -besselk(n - 1, z) / 2 - besselk(n + 1, z) / 2 assert hankel1(n, z).diff(z) == hankel1(n - 1, z) / 2 - hankel1(n + 1, z) / 2 assert hankel2(n, z).diff(z) == hankel2(n - 1, z) / 2 - hankel2(n + 1, z) / 2 pytest.raises(ArgumentIndexError, lambda: besselj(n, z).fdiff(3)) pytest.raises(ArgumentIndexError, lambda: jn(n, z).fdiff(3)) pytest.raises(ArgumentIndexError, lambda: airyai(z).fdiff(2)) pytest.raises(ArgumentIndexError, lambda: airybi(z).fdiff(2)) pytest.raises(ArgumentIndexError, lambda: airyaiprime(z).fdiff(2)) pytest.raises(ArgumentIndexError, lambda: airybiprime(z).fdiff(2))
def test_airybiprime(): z = Symbol('z', extended_real=False) t = Symbol('t', negative=True) p = Symbol('p', positive=True) assert isinstance(airybiprime(z), airybiprime) assert airybiprime(0) == root(3, 6)/gamma(Rational(1, 3)) assert airybiprime(oo) == oo assert airybiprime(-oo) == 0 assert diff(airybiprime(z), z) == z*airybi(z) assert series(airybiprime(z), z, 0, 3) == ( root(3, 6)/gamma(Rational(1, 3)) + 3**Rational(5, 6)*z**2/(6*gamma(Rational(2, 3))) + O(z**3)) assert airybiprime(z).rewrite(hyper) == ( 3**Rational(5, 6)*z**2*hyper((), (Rational(5, 3),), z**3/9)/(6*gamma(Rational(2, 3))) + root(3, 6)*hyper((), (Rational(1, 3),), z**3/9)/gamma(Rational(1, 3))) assert isinstance(airybiprime(z).rewrite(besselj), airybiprime) assert (airybiprime(t).rewrite(besselj) == -sqrt(3)*t*(besselj(-Rational(2, 3), 2*(-t)**Rational(3, 2)/3) + besselj(Rational(2, 3), 2*(-t)**Rational(3, 2)/3))/3) assert airybiprime(z).rewrite(besseli) == ( sqrt(3)*(z**2*besseli(Rational(2, 3), 2*z**Rational(3, 2)/3)/(z**Rational(3, 2))**Rational(2, 3) + (z**Rational(3, 2))**Rational(2, 3)*besseli(-Rational(2, 3), 2*z**Rational(3, 2)/3))/3) assert airybiprime(p).rewrite(besseli) == ( sqrt(3)*p*(besseli(-Rational(2, 3), 2*p**Rational(3, 2)/3) + besseli(Rational(2, 3), 2*p**Rational(3, 2)/3))/3) assert airybiprime(p).rewrite(besselj) == airybiprime(p) assert expand_func(airybiprime(2*cbrt(3*z**5))) == ( sqrt(3)*(z**Rational(5, 3)/cbrt(z**5) - 1)*airyaiprime(2*cbrt(3)*z**Rational(5, 3))/2 + (z**Rational(5, 3)/cbrt(z**5) + 1)*airybiprime(2*cbrt(3)*z**Rational(5, 3))/2) assert expand_func(airybiprime(x*y)) == airybiprime(x*y) assert expand_func(airybiprime(log(x))) == airybiprime(log(x)) assert expand_func(airybiprime(2*root(3*z**5, 5))) == airybiprime(2*root(3*z**5, 5)) assert airybiprime(-2).evalf(50) == Float('0.27879516692116952268509756941098324140300059345163131', dps=50)
def test_airyaiprime(): z = Symbol('z', extended_real=False) t = Symbol('t', negative=True) p = Symbol('p', positive=True) assert isinstance(airyaiprime(z), airyaiprime) assert airyaiprime(0) == -3**Rational(2, 3) / (3 * gamma(Rational(1, 3))) assert airyaiprime(oo) == 0 assert diff(airyaiprime(z), z) == z * airyai(z) assert series(airyaiprime(z), z, 0, 3) == (-3**Rational(2, 3) / (3 * gamma(Rational(1, 3))) + cbrt(3) * z**2 / (6 * gamma(Rational(2, 3))) + O(z**3)) assert airyaiprime(z).rewrite(hyper) == ( cbrt(3) * z**2 * hyper((), (Rational(5, 3), ), z**3 / 9) / (6 * gamma(Rational(2, 3))) - 3**Rational(2, 3) * hyper( (), (Rational(1, 3), ), z**3 / 9) / (3 * gamma(Rational(1, 3)))) assert isinstance(airyaiprime(z).rewrite(besselj), airyaiprime) assert (airyaiprime(t).rewrite(besselj) == t * (besselj(-Rational(2, 3), 2 * (-t)**Rational(3, 2) / 3) - besselj(Rational(2, 3), 2 * (-t)**Rational(3, 2) / 3)) / 3) assert airyaiprime(z).rewrite(besseli) == ( z**2 * besseli(Rational(2, 3), 2 * z**Rational(3, 2) / 3) / (3 * (z**Rational(3, 2))**Rational(2, 3)) - (z**Rational(3, 2))**Rational(2, 3) * besseli(-Rational(1, 3), 2 * z**Rational(3, 2) / 3) / 3) assert airyaiprime(p).rewrite(besseli) == ( p * (-besseli(-Rational(2, 3), 2 * p**Rational(3, 2) / 3) + besseli(Rational(2, 3), 2 * p**Rational(3, 2) / 3)) / 3) assert airyaiprime(p).rewrite(besselj) == airyaiprime(p) assert expand_func(airyaiprime( 2 * cbrt(3 * z**5))) == (sqrt(3) * (z**Rational(5, 3) / cbrt(z**5) - 1) * airybiprime(2 * cbrt(3) * z**Rational(5, 3)) / 6 + (z**Rational(5, 3) / cbrt(z**5) + 1) * airyaiprime(2 * cbrt(3) * z**Rational(5, 3)) / 2) assert expand_func(airyaiprime(x * y)) == airyaiprime(x * y) assert expand_func(airyaiprime(log(x))) == airyaiprime(log(x)) assert expand_func(airyaiprime(2 * root(3 * z**5, 5))) == airyaiprime( 2 * root(3 * z**5, 5)) assert airyaiprime(-2).evalf(50) == Float( '0.61825902074169104140626429133247528291577794512414753', dps=50)
def test_airyai(): z = Symbol('z', extended_real=False) r = Symbol('r', extended_real=True) t = Symbol('t', negative=True) p = Symbol('p', positive=True) assert isinstance(airyai(z), airyai) assert airyai(0) == cbrt(3) / (3 * gamma(Rational(2, 3))) assert airyai(oo) == 0 assert airyai(-oo) == 0 assert diff(airyai(z), z) == airyaiprime(z) assert series(airyai(z), z, 0, 3) == (3**Rational(5, 6) * gamma(Rational(1, 3)) / (6 * pi) - root(3, 6) * z * gamma(Rational(2, 3)) / (2 * pi) + O(z**3)) l = Limit( airyai(I / x) / (exp(-Rational(2, 3) * (I / x)**Rational(3, 2)) * sqrt(pi * sqrt(I / x)) / 2), x, 0) assert l.doit() == l # cover _airyais._eval_aseries assert airyai(z).rewrite(hyper) == (-3**Rational(2, 3) * z * hyper( (), (Rational(4, 3), ), z**3 / 9) / (3 * gamma(Rational(1, 3))) + cbrt(3) * hyper( (), (Rational(2, 3), ), z**3 / 9) / (3 * gamma(Rational(2, 3)))) assert isinstance(airyai(z).rewrite(besselj), airyai) assert airyai(t).rewrite(besselj) == ( sqrt(-t) * (besselj(-Rational(1, 3), 2 * (-t)**Rational(3, 2) / 3) + besselj(Rational(1, 3), 2 * (-t)**Rational(3, 2) / 3)) / 3) assert airyai(z).rewrite(besseli) == ( -z * besseli(Rational(1, 3), 2 * z**Rational(3, 2) / 3) / (3 * cbrt(z**Rational(3, 2))) + cbrt(z**Rational(3, 2)) * besseli(-Rational(1, 3), 2 * z**Rational(3, 2) / 3) / 3) assert airyai(p).rewrite(besseli) == ( sqrt(p) * (besseli(-Rational(1, 3), 2 * p**Rational(3, 2) / 3) - besseli(Rational(1, 3), 2 * p**Rational(3, 2) / 3)) / 3) assert expand_func(airyai( 2 * cbrt(3 * z**5))) == (-sqrt(3) * (-1 + cbrt(z**5) / z**Rational(5, 3)) * airybi(2 * cbrt(3) * z**Rational(5, 3)) / 6 + (1 + cbrt(z**5) / z**Rational(5, 3)) * airyai(2 * cbrt(3) * z**Rational(5, 3)) / 2) assert expand_func(airyai(x * y)) == airyai(x * y) assert expand_func(airyai(log(x))) == airyai(log(x)) assert expand_func(airyai(2 * root(3 * z**5, 5))) == airyai( 2 * root(3 * z**5, 5)) assert (airyai(r).as_real_imag() == airyai(r).as_real_imag(deep=False) == (airyai(r), 0)) assert airyai(x).as_real_imag() == airyai(x).as_real_imag(deep=False) assert (airyai(x).as_real_imag() == ( airyai(re(x) - I * re(x) * abs(im(x)) / abs(re(x))) / 2 + airyai(re(x) + I * re(x) * abs(im(x)) / abs(re(x))) / 2, I * (airyai(re(x) - I * re(x) * abs(im(x)) / abs(re(x))) - airyai(re(x) + I * re(x) * abs(im(x)) / Abs(re(x)))) * re(x) * abs(im(x)) / (2 * im(x) * abs(re(x))))) assert airyai(x).taylor_term(-1, x) == 0
def test_airyaiprime(): z = Symbol('z', extended_real=False) t = Symbol('t', negative=True) p = Symbol('p', positive=True) assert isinstance(airyaiprime(z), airyaiprime) assert airyaiprime(0) == -3**Rational(2, 3)/(3*gamma(Rational(1, 3))) assert airyaiprime(oo) == 0 assert diff(airyaiprime(z), z) == z*airyai(z) assert series(airyaiprime(z), z, 0, 3) == ( -3**Rational(2, 3)/(3*gamma(Rational(1, 3))) + cbrt(3)*z**2/(6*gamma(Rational(2, 3))) + O(z**3)) assert airyaiprime(z).rewrite(hyper) == ( cbrt(3)*z**2*hyper((), (Rational(5, 3),), z**3/9)/(6*gamma(Rational(2, 3))) - 3**Rational(2, 3)*hyper((), (Rational(1, 3),), z**3/9)/(3*gamma(Rational(1, 3)))) assert isinstance(airyaiprime(z).rewrite(besselj), airyaiprime) assert (airyaiprime(t).rewrite(besselj) == t*(besselj(-Rational(2, 3), 2*(-t)**Rational(3, 2)/3) - besselj(Rational(2, 3), 2*(-t)**Rational(3, 2)/3))/3) assert airyaiprime(z).rewrite(besseli) == ( z**2*besseli(Rational(2, 3), 2*z**Rational(3, 2)/3)/(3*(z**Rational(3, 2))**Rational(2, 3)) - (z**Rational(3, 2))**Rational(2, 3)*besseli(-Rational(1, 3), 2*z**Rational(3, 2)/3)/3) assert airyaiprime(p).rewrite(besseli) == ( p*(-besseli(-Rational(2, 3), 2*p**Rational(3, 2)/3) + besseli(Rational(2, 3), 2*p**Rational(3, 2)/3))/3) assert airyaiprime(p).rewrite(besselj) == airyaiprime(p) assert expand_func(airyaiprime(2*cbrt(3*z**5))) == ( sqrt(3)*(z**Rational(5, 3)/cbrt(z**5) - 1)*airybiprime(2*cbrt(3)*z**Rational(5, 3))/6 + (z**Rational(5, 3)/cbrt(z**5) + 1)*airyaiprime(2*cbrt(3)*z**Rational(5, 3))/2) assert expand_func(airyaiprime(x*y)) == airyaiprime(x*y) assert expand_func(airyaiprime(log(x))) == airyaiprime(log(x)) assert expand_func(airyaiprime(2*root(3*z**5, 5))) == airyaiprime(2*root(3*z**5, 5)) assert airyaiprime(-2).evalf(50) == Float('0.61825902074169104140626429133247528291577794512414753', dps=50)