def test_specfun(): 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(uppergamma(n, x)) == "gammainc(x, n, 'upper')" assert octave_code(lowergamma(n, x)) == "gammainc(x, n, 'lower')" 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' assert octave_code(Chi(x)) == 'coshint(x)' assert octave_code(Ci(x)) == 'cosint(x)' assert octave_code(laguerre(n, x)) == 'laguerreL(n, x)' assert octave_code(li(x)) == 'logint(x)' assert octave_code(loggamma(x)) == 'gammaln(x)' assert octave_code(polygamma(n, x)) == 'psi(n, x)' assert octave_code(Shi(x)) == 'sinhint(x)' assert octave_code(Si(x)) == 'sinint(x)' assert octave_code(LambertW(x)) == 'lambertw(x)' assert octave_code(LambertW(x, n)) == 'lambertw(n, x)' assert octave_code(zeta(x)) == 'zeta(x)' assert octave_code(zeta( x, y)) == '% Not supported in Octave:\n% zeta\nzeta(x, y)'
def test_airybi(): z = Symbol('z', extended_real=False) t = Symbol('t', negative=True) p = Symbol('p', positive=True) assert isinstance(airybi(z), airybi) assert airybi(0) == 3**Rational(5, 6) / (3 * gamma(Rational(2, 3))) assert airybi(oo) == oo assert airybi(-oo) == 0 assert diff(airybi(z), z) == airybiprime(z) assert series(airybi(z), z, 0, 3) == (cbrt(3) * gamma(Rational(1, 3)) / (2 * pi) + 3**Rational(2, 3) * z * gamma(Rational(2, 3)) / (2 * pi) + O(z**3)) l = Limit( airybi(I / x) / (exp(Rational(2, 3) * (I / x)**Rational(3, 2)) * sqrt(pi * sqrt(I / x))), x, 0) assert l.doit() == l assert airybi(z).rewrite(hyper) == (root(3, 6) * z * hyper( (), (Rational(4, 3), ), z**3 / 9) / gamma(Rational(1, 3)) + 3**Rational(5, 6) * hyper( (), (Rational(2, 3), ), z**3 / 9) / (3 * gamma(Rational(2, 3)))) assert isinstance(airybi(z).rewrite(besselj), airybi) assert (airybi(t).rewrite(besselj) == sqrt(3) * sqrt(-t) * (besselj(-1 / 3, 2 * (-t)**Rational(3, 2) / 3) - besselj(Rational(1, 3), 2 * (-t)**Rational(3, 2) / 3)) / 3) assert airybi(z).rewrite(besseli) == ( sqrt(3) * (z * besseli(Rational(1, 3), 2 * z**Rational(3, 2) / 3) / cbrt(z**Rational(3, 2)) + cbrt(z**Rational(3, 2)) * besseli(-Rational(1, 3), 2 * z**Rational(3, 2) / 3)) / 3) assert airybi(p).rewrite(besseli) == ( sqrt(3) * sqrt(p) * (besseli(-Rational(1, 3), 2 * p**Rational(3, 2) / 3) + besseli(Rational(1, 3), 2 * p**Rational(3, 2) / 3)) / 3) assert airybi(p).rewrite(besselj) == airybi(p) assert expand_func(airybi( 2 * cbrt(3 * z**5))) == (sqrt(3) * (1 - cbrt(z**5) / z**Rational(5, 3)) * airyai(2 * cbrt(3) * z**Rational(5, 3)) / 2 + (1 + cbrt(z**5) / z**Rational(5, 3)) * airybi(2 * cbrt(3) * z**Rational(5, 3)) / 2) assert expand_func(airybi(x * y)) == airybi(x * y) assert expand_func(airybi(log(x))) == airybi(log(x)) assert expand_func(airybi(2 * root(3 * z**5, 5))) == airybi( 2 * root(3 * z**5, 5)) assert airybi(x).taylor_term(-1, x) == 0
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_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_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)