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
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_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_conjugate(): n, z, x = Symbol('n'), Symbol('z', extended_real=False), Symbol( 'x', extended_real=True) y, t = Symbol('y', extended_real=True, positive=True), Symbol('t', negative=True) for f in [besseli, besselj, besselk, bessely, jn, yn, hankel1, hankel2]: assert f(n, -1).conjugate() != f(conjugate(n), -1) assert f(n, x).conjugate() != f(conjugate(n), x) assert f(n, t).conjugate() != f(conjugate(n), t) rz = randcplx(b=0.5) for f in [besseli, besselj, besselk, bessely, jn, yn]: assert f(n, 1 + I).conjugate() == f(conjugate(n), 1 - I) assert f(n, 0).conjugate() == f(conjugate(n), 0) assert f(n, 1).conjugate() == f(conjugate(n), 1) assert f(n, z).conjugate() == f(conjugate(n), conjugate(z)) assert f(n, y).conjugate() == f(conjugate(n), y) assert tn(f(n, rz).conjugate(), f(conjugate(n), conjugate(rz))) assert hankel1(n, 1 + I).conjugate() == hankel2(conjugate(n), 1 - I) assert hankel1(n, 0).conjugate() == hankel2(conjugate(n), 0) assert hankel1(n, 1).conjugate() == hankel2(conjugate(n), 1) assert hankel1(n, y).conjugate() == hankel2(conjugate(n), y) assert hankel1(n, z).conjugate() == hankel2(conjugate(n), conjugate(z)) assert tn(hankel1(n, rz).conjugate(), hankel2(conjugate(n), conjugate(rz))) assert hankel2(n, 1 + I).conjugate() == hankel1(conjugate(n), 1 - I) assert hankel2(n, 0).conjugate() == hankel1(conjugate(n), 0) assert hankel2(n, 1).conjugate() == hankel1(conjugate(n), 1) assert hankel2(n, y).conjugate() == hankel1(conjugate(n), y) assert hankel2(n, z).conjugate() == hankel1(conjugate(n), conjugate(z)) assert tn(hankel2(n, rz).conjugate(), hankel1(conjugate(n), conjugate(rz)))
def test_conjugate(): n, z, x = Symbol('n'), Symbol('z', extended_real=False), Symbol('x', extended_real=True) y, t = Symbol('y', extended_real=True, positive=True), Symbol('t', negative=True) for f in [besseli, besselj, besselk, bessely, jn, yn, hankel1, hankel2]: assert f(n, -1).conjugate() != f(conjugate(n), -1) assert f(n, x).conjugate() != f(conjugate(n), x) assert f(n, t).conjugate() != f(conjugate(n), t) rz = randcplx(b=0.5) for f in [besseli, besselj, besselk, bessely, jn, yn]: assert f(n, 1 + I).conjugate() == f(conjugate(n), 1 - I) assert f(n, 0).conjugate() == f(conjugate(n), 0) assert f(n, 1).conjugate() == f(conjugate(n), 1) assert f(n, z).conjugate() == f(conjugate(n), conjugate(z)) assert f(n, y).conjugate() == f(conjugate(n), y) assert tn(f(n, rz).conjugate(), f(conjugate(n), conjugate(rz))) assert hankel1(n, 1 + I).conjugate() == hankel2(conjugate(n), 1 - I) assert hankel1(n, 0).conjugate() == hankel2(conjugate(n), 0) assert hankel1(n, 1).conjugate() == hankel2(conjugate(n), 1) assert hankel1(n, y).conjugate() == hankel2(conjugate(n), y) assert hankel1(n, z).conjugate() == hankel2(conjugate(n), conjugate(z)) assert tn(hankel1(n, rz).conjugate(), hankel2(conjugate(n), conjugate(rz))) assert hankel2(n, 1 + I).conjugate() == hankel1(conjugate(n), 1 - I) assert hankel2(n, 0).conjugate() == hankel1(conjugate(n), 0) assert hankel2(n, 1).conjugate() == hankel1(conjugate(n), 1) assert hankel2(n, y).conjugate() == hankel1(conjugate(n), y) assert hankel2(n, z).conjugate() == hankel1(conjugate(n), conjugate(z)) assert tn(hankel2(n, rz).conjugate(), hankel1(conjugate(n), conjugate(rz)))