def test_atan(): assert atan(nan) == nan assert atan.nargs == FiniteSet(1) assert atan(oo) == pi/2 assert atan(-oo) == -pi/2 assert atan(0) == 0 assert atan(1) == pi/4 assert atan(sqrt(3)) == pi/3 assert atan(oo) == pi/2 assert atan(x).diff(x) == 1/(1 + x**2) assert atan(r).is_extended_real is True assert atan(-2*I) == -I*atanh(2) assert atan(p).is_positive is True assert atan(n).is_positive is False assert atan(x).is_positive is None assert atan(0, evaluate=False).is_rational assert atan(1, evaluate=False).is_rational is False z = Symbol('z', zero=True) rn = Symbol('rn', rational=True, nonzero=True) assert atan(z).is_rational assert atan(rn).is_rational is False assert atan(x).is_rational is None pytest.raises(ArgumentIndexError, lambda: atan(x).fdiff(2))
def test_inverses(): assert sinh(x).inverse() == asinh pytest.raises(AttributeError, lambda: cosh(x).inverse()) assert tanh(x).inverse() == atanh assert coth(x).inverse() == acoth assert asinh(x).inverse() == sinh assert acosh(x).inverse() == cosh assert atanh(x).inverse() == tanh assert acoth(x).inverse() == coth
def test_derivs(): assert coth(x).diff(x) == -sinh(x)**(-2) assert sinh(x).diff(x) == cosh(x) assert cosh(x).diff(x) == sinh(x) assert tanh(x).diff(x) == -tanh(x)**2 + 1 assert csch(x).diff(x) == -coth(x)*csch(x) assert sech(x).diff(x) == -tanh(x)*sech(x) assert acoth(x).diff(x) == 1/(-x**2 + 1) assert asinh(x).diff(x) == 1/sqrt(x**2 + 1) assert acosh(x).diff(x) == 1/sqrt(x**2 - 1) assert atanh(x).diff(x) == 1/(-x**2 + 1)
def test_derivs(): assert coth(x).diff(x) == -sinh(x)**(-2) assert sinh(x).diff(x) == cosh(x) assert cosh(x).diff(x) == sinh(x) assert tanh(x).diff(x) == -tanh(x)**2 + 1 assert csch(x).diff(x) == -coth(x) * csch(x) assert sech(x).diff(x) == -tanh(x) * sech(x) assert acoth(x).diff(x) == 1 / (-x**2 + 1) assert asinh(x).diff(x) == 1 / sqrt(x**2 + 1) assert acosh(x).diff(x) == 1 / sqrt(x**2 - 1) assert atanh(x).diff(x) == 1 / (-x**2 + 1)
def test_hyperbolic(): assert sinh(x).series(x, n=7) == x + x**3/6 + x**5/120 + O(x**7) assert cosh(x).series(x) == 1 + x**2/2 + x**4/24 + O(x**6) assert tanh(x).series(x, n=7) == x - x**3/3 + 2*x**5/15 + O(x**7) assert coth(x).series(x, n=7) == \ 1/x - x**3/45 + x/3 + 2*x**5/945 + O(x**7) assert asinh(x).series(x, n=7) == x - x**3/6 + 3*x**5/40 + O(x**7) assert acosh(x).series(x, n=7) == \ pi*I/2 - I*x - 3*I*x**5/40 - I*x**3/6 + O(x**7) assert atanh(x).series(x, n=7) == x + x**3/3 + x**5/5 + O(x**7) assert acoth(x).series(x, n=7) == -I*pi/2 + x + x**3/3 + x**5/5 + O(x**7)
def test_hyperbolic(): assert sinh(x).nseries(x, n=6) == x + x**3/6 + x**5/120 + O(x**7) assert cosh(x).nseries(x, n=5) == 1 + x**2/2 + x**4/24 + O(x**6) assert tanh(x).nseries(x, n=6) == x - x**3/3 + 2*x**5/15 + O(x**7) assert coth(x).nseries(x, n=6) == \ 1/x - x**3/45 + x/3 + 2*x**5/945 + O(x**7) assert asinh(x).nseries(x, n=6) == x - x**3/6 + 3*x**5/40 + O(x**7) assert acosh(x).nseries(x, n=6) == \ pi*I/2 - I*x - 3*I*x**5/40 - I*x**3/6 + O(x**7) assert atanh(x).nseries(x, n=6) == x + x**3/3 + x**5/5 + O(x**7) assert acoth(x).nseries(x, n=6) == x + x**3/3 + x**5/5 + pi*I/2 + O(x**7)
def test_simplifications(): assert sinh(asinh(x)) == x assert sinh(acosh(x)) == sqrt(x - 1) * sqrt(x + 1) assert sinh(atanh(x)) == x/sqrt(1 - x**2) assert sinh(acoth(x)) == 1/(sqrt(x - 1) * sqrt(x + 1)) assert cosh(asinh(x)) == sqrt(1 + x**2) assert cosh(acosh(x)) == x assert cosh(atanh(x)) == 1/sqrt(1 - x**2) assert cosh(acoth(x)) == x/(sqrt(x - 1) * sqrt(x + 1)) assert tanh(asinh(x)) == x/sqrt(1 + x**2) assert tanh(acosh(x)) == sqrt(x - 1) * sqrt(x + 1) / x assert tanh(atanh(x)) == x assert tanh(acoth(x)) == 1/x assert coth(asinh(x)) == sqrt(1 + x**2)/x assert coth(acosh(x)) == x/(sqrt(x - 1) * sqrt(x + 1)) assert coth(atanh(x)) == 1/x assert coth(acoth(x)) == x assert csch(asinh(x)) == 1/x assert csch(acosh(x)) == 1/(sqrt(x - 1) * sqrt(x + 1)) assert csch(atanh(x)) == sqrt(1 - x**2)/x assert csch(acoth(x)) == sqrt(x - 1) * sqrt(x + 1) assert sech(asinh(x)) == 1/sqrt(1 + x**2) assert sech(acosh(x)) == 1/x assert sech(atanh(x)) == sqrt(1 - x**2) assert sech(acoth(x)) == sqrt(x - 1) * sqrt(x + 1)/x
def test_simplifications(): assert sinh(asinh(x)) == x assert sinh(acosh(x)) == sqrt(x - 1) * sqrt(x + 1) assert sinh(atanh(x)) == x / sqrt(1 - x**2) assert sinh(acoth(x)) == 1 / (sqrt(x - 1) * sqrt(x + 1)) assert cosh(asinh(x)) == sqrt(1 + x**2) assert cosh(acosh(x)) == x assert cosh(atanh(x)) == 1 / sqrt(1 - x**2) assert cosh(acoth(x)) == x / (sqrt(x - 1) * sqrt(x + 1)) assert tanh(asinh(x)) == x / sqrt(1 + x**2) assert tanh(acosh(x)) == sqrt(x - 1) * sqrt(x + 1) / x assert tanh(atanh(x)) == x assert tanh(acoth(x)) == 1 / x assert coth(asinh(x)) == sqrt(1 + x**2) / x assert coth(acosh(x)) == x / (sqrt(x - 1) * sqrt(x + 1)) assert coth(atanh(x)) == 1 / x assert coth(acoth(x)) == x assert csch(asinh(x)) == 1 / x assert csch(acosh(x)) == 1 / (sqrt(x - 1) * sqrt(x + 1)) assert csch(atanh(x)) == sqrt(1 - x**2) / x assert csch(acoth(x)) == sqrt(x - 1) * sqrt(x + 1) assert sech(asinh(x)) == 1 / sqrt(1 + x**2) assert sech(acosh(x)) == 1 / x assert sech(atanh(x)) == sqrt(1 - x**2) assert sech(acoth(x)) == sqrt(x - 1) * sqrt(x + 1) / x
def test_hyperexpand_bases(): assert hyperexpand(hyper([2], [a], z)) == \ a + z**(-a + 1)*(-a**2 + 3*a + z*(a - 1) - 2)*exp(z) * \ lowergamma(a - 1, z) - 1 # TODO [a+1, a+Rational(-1, 2)], [2*a] assert hyperexpand(hyper([1, 2], [3], z)) == -2/z - 2*log(-z + 1)/z**2 assert hyperexpand(hyper([Rational(1, 2), 2], [Rational(3, 2)], z)) == \ -1/(2*z - 2) + atanh(sqrt(z))/sqrt(z)/2 assert hyperexpand(hyper([Rational(1, 2), Rational(1, 2)], [Rational(5, 2)], z)) == \ (-3*z + 3)/4/(z*sqrt(-z + 1)) \ + (6*z - 3)*asin(sqrt(z))/(4*z**Rational(3, 2)) assert hyperexpand(hyper([1, 2], [Rational(3, 2)], z)) == -1/(2*z - 2) \ - asin(sqrt(z))/(sqrt(z)*(2*z - 2)*sqrt(-z + 1)) assert hyperexpand(hyper([Rational(-1, 2) - 1, 1, 2], [Rational(1, 2), 3], z)) == \ sqrt(z)*(6*z/7 - Rational(6, 5))*atanh(sqrt(z)) \ + (-30*z**2 + 32*z - 6)/35/z - 6*log(-z + 1)/(35*z**2) assert hyperexpand(hyper([1 + Rational(1, 2), 1, 1], [2, 2], z)) == \ -4*log(sqrt(-z + 1)/2 + Rational(1, 2))/z # TODO hyperexpand(hyper([a], [2*a + 1], z)) # TODO [Rational(1, 2), a], [Rational(3, 2), a+1] assert hyperexpand(hyper([2], [b, 1], z)) == \ z**(-b/2 + Rational(1, 2))*besseli(b - 1, 2*sqrt(z))*gamma(b) \ + z**(-b/2 + 1)*besseli(b, 2*sqrt(z))*gamma(b)
def test_hyperexpand_bases(): assert hyperexpand(hyper([2], [a], z)) == \ a + z**(-a + 1)*(-a**2 + 3*a + z*(a - 1) - 2)*exp(z) * \ lowergamma(a - 1, z) - 1 # TODO [a+1, a-S.Half], [2*a] assert hyperexpand(hyper([1, 2], [3], z)) == -2/z - 2*log(-z + 1)/z**2 assert hyperexpand(hyper([S.Half, 2], [Rational(3, 2)], z)) == \ -1/(2*z - 2) + atanh(sqrt(z))/sqrt(z)/2 assert hyperexpand(hyper([Rational(1, 2), Rational(1, 2)], [Rational(5, 2)], z)) == \ (-3*z + 3)/4/(z*sqrt(-z + 1)) \ + (6*z - 3)*asin(sqrt(z))/(4*z**Rational(3, 2)) assert hyperexpand(hyper([1, 2], [Rational(3, 2)], z)) == -1/(2*z - 2) \ - asin(sqrt(z))/(sqrt(z)*(2*z - 2)*sqrt(-z + 1)) assert hyperexpand(hyper([-S.Half - 1, 1, 2], [S.Half, 3], z)) == \ sqrt(z)*(6*z/7 - Rational(6, 5))*atanh(sqrt(z)) \ + (-30*z**2 + 32*z - 6)/35/z - 6*log(-z + 1)/(35*z**2) assert hyperexpand(hyper([1 + S.Half, 1, 1], [2, 2], z)) == \ -4*log(sqrt(-z + 1)/2 + Rational(1, 2))/z # TODO hyperexpand(hyper([a], [2*a + 1], z)) # TODO [S.Half, a], [Rational(3, 2), a+1] assert hyperexpand(hyper([2], [b, 1], z)) == \ z**(-b/2 + Rational(1, 2))*besseli(b - 1, 2*sqrt(z))*gamma(b) \ + z**(-b/2 + 1)*besseli(b, 2*sqrt(z))*gamma(b)
def test_P(): assert P(0, z, m) == F(z, m) assert P(1, z, m) == F(z, m) + \ (sqrt(1 - m*sin(z)**2)*tan(z) - E(z, m))/(1 - m) assert P(n, i*pi/2, m) == i*P(n, m) assert P(n, z, 0) == atanh(sqrt(n - 1)*tan(z))/sqrt(n - 1) assert P(n, z, n) == F(z, n) - P(1, z, n) + tan(z)/sqrt(1 - n*sin(z)**2) assert P(oo, z, m) == 0 assert P(-oo, z, m) == 0 assert P(n, z, oo) == 0 assert P(n, z, -oo) == 0 assert P(0, m) == K(m) assert P(1, m) == zoo assert P(n, 0) == pi/(2*sqrt(1 - n)) assert P(2, 1) == -oo assert P(-1, 1) == oo assert P(n, n) == E(n)/(1 - n) assert P(oo, m) == 0 assert P(n, oo) == 0 assert P(n, -z, m) == -P(n, z, m) ni, mi = Symbol('n', extended_real=False), Symbol('m', extended_real=False) assert P(ni, z, mi).conjugate() == \ P(ni.conjugate(), z.conjugate(), mi.conjugate()) nr, mr = Symbol('n', extended_real=True, negative=True), \ Symbol('m', extended_real=True, negative=True) assert P(nr, z, mr).conjugate() == P(nr, z.conjugate(), mr) assert P(n, m).conjugate() == P(n.conjugate(), m.conjugate()) assert P(n, z, m).diff(n) == (E(z, m) + (m - n)*F(z, m)/n + (n**2 - m)*P(n, z, m)/n - n*sqrt(1 - m*sin(z)**2)*sin(2*z)/(2*(1 - n*sin(z)**2)))/(2*(m - n)*(n - 1)) assert P(n, z, m).diff(z) == 1/(sqrt(1 - m*sin(z)**2)*(1 - n*sin(z)**2)) assert P(n, z, m).diff(m) == (E(z, m)/(m - 1) + P(n, z, m) - m*sin(2*z)/(2*(m - 1)*sqrt(1 - m*sin(z)**2)))/(2*(n - m)) assert P(n, m).diff(n) == (E(m) + (m - n)*K(m)/n + (n**2 - m)*P(n, m)/n)/(2*(m - n)*(n - 1)) assert P(n, m).diff(m) == (E(m)/(m - 1) + P(n, m))/(2*(n - m)) rx, ry = randcplx(), randcplx() assert td(P(n, rx, ry), n) assert td(P(rx, z, ry), z) assert td(P(rx, ry, m), m) pytest.raises(ArgumentIndexError, lambda: P(n, z, m).fdiff(4)) pytest.raises(ArgumentIndexError, lambda: P(n, m).fdiff(3)) assert P(n, z, m).series(z) == z + z**3*(m/6 + n/3) + \ z**5*(3*m**2/40 + m*n/10 - m/30 + n**2/5 - n/15) + O(z**6)
def test_mathml_trig(): mml = mp._print(sin(x)) assert mml.childNodes[0].nodeName == 'sin' mml = mp._print(cos(x)) assert mml.childNodes[0].nodeName == 'cos' mml = mp._print(tan(x)) assert mml.childNodes[0].nodeName == 'tan' mml = mp._print(asin(x)) assert mml.childNodes[0].nodeName == 'arcsin' mml = mp._print(acos(x)) assert mml.childNodes[0].nodeName == 'arccos' mml = mp._print(atan(x)) assert mml.childNodes[0].nodeName == 'arctan' mml = mp._print(sinh(x)) assert mml.childNodes[0].nodeName == 'sinh' mml = mp._print(cosh(x)) assert mml.childNodes[0].nodeName == 'cosh' mml = mp._print(tanh(x)) assert mml.childNodes[0].nodeName == 'tanh' mml = mp._print(asinh(x)) assert mml.childNodes[0].nodeName == 'arcsinh' mml = mp._print(atanh(x)) assert mml.childNodes[0].nodeName == 'arctanh' mml = mp._print(acosh(x)) assert mml.childNodes[0].nodeName == 'arccosh'
def test_atanh(): # TODO please write more tests -- see issue 3751 # From http://functions.wolfram.com/ElementaryFunctions/ArcTanh/03/01/ # at specific points x = Symbol('x') # at specific points assert atanh(0) == 0 assert atanh(I) == I * pi / 4 assert atanh(-I) == -I * pi / 4 assert atanh(1) == oo assert atanh(-1) == -oo # at infinites assert atanh(I * oo) == I * pi / 2 assert atanh(-I * oo) == -I * pi / 2 assert atanh(zoo) == nan # properties assert atanh(-x) == -atanh(x) assert atanh(I / sqrt(3)) == I * pi / 6 assert atanh(-I / sqrt(3)) == -I * pi / 6 assert atanh(I * sqrt(3)) == I * pi / 3 assert atanh(-I * sqrt(3)) == -I * pi / 3 assert atanh(I * (1 + sqrt(2))) == 3 * pi * I / 8 assert atanh(I * (sqrt(2) - 1)) == pi * I / 8 assert atanh(I * (1 - sqrt(2))) == -pi * I / 8 assert atanh(-I * (1 + sqrt(2))) == -3 * pi * I / 8 assert atanh(I * sqrt(5 + 2 * sqrt(5))) == 2 * I * pi / 5 assert atanh(-I * sqrt(5 + 2 * sqrt(5))) == -2 * I * pi / 5 assert atanh(I * (2 - sqrt(3))) == pi * I / 12 assert atanh(I * (sqrt(3) - 2)) == -pi * I / 12 assert atanh(oo) == -I * pi / 2
def test_atanh_infinities(): assert atanh(oo) == -I * pi / 2 assert atanh(-oo) == I * pi / 2
def test_atanh(): # TODO please write more tests -- see issue sympy/sympy#3751 # From http://functions.wolfram.com/ElementaryFunctions/ArcTanh/03/01/ # at specific points # at specific points assert atanh(0) == 0 assert atanh(I) == I*pi/4 assert atanh(-I) == -I*pi/4 assert atanh(1) == oo assert atanh(-1) == -oo assert atanh(-2) == -atanh(2) # at infinites assert atanh(I*oo) == I*pi/2 assert atanh(-I*oo) == -I*pi/2 assert atanh(zoo) == nan # properties assert atanh(-x) == -atanh(x) assert atanh(I/sqrt(3)) == I*pi/6 assert atanh(-I/sqrt(3)) == -I*pi/6 assert atanh(I*sqrt(3)) == I*pi/3 assert atanh(-I*sqrt(3)) == -I*pi/3 assert atanh(I*(1 + sqrt(2))) == 3*pi*I/8 assert atanh(I*(sqrt(2) - 1)) == pi*I/8 assert atanh(I*(1 - sqrt(2))) == -pi*I/8 assert atanh(-I*(1 + sqrt(2))) == -3*pi*I/8 assert atanh(I*sqrt(5 + 2*sqrt(5))) == 2*I*pi/5 assert atanh(-I*sqrt(5 + 2*sqrt(5))) == -2*I*pi/5 assert atanh(I*(2 - sqrt(3))) == pi*I/12 assert atanh(I*(sqrt(3) - 2)) == -pi*I/12 assert atanh(oo) == -I*pi/2 assert atanh(-oo) == I*pi/2 pytest.raises(ArgumentIndexError, lambda: atanh(x).fdiff(2))
def test_atanh_series(): assert atanh(x).series(x, 0, 10) == \ x + x**3/3 + x**5/5 + x**7/7 + x**9/9 + O(x**10)
def test_atanh_rewrite(): assert atanh(x).rewrite(log) == (log(1 + x) - log(1 - x)) / 2
def test_Function(): assert mathematica_code(f(x, y, z)) == 'f[x, y, z]' assert mathematica_code(sin(x)**cos(x)) == 'Sin[x]^Cos[x]' assert mathematica_code(sign(x)) == 'Sign[x]' assert mathematica_code(atanh(x), user_functions={'atanh': 'ArcTanh'}) == 'ArcTanh[x]' assert (mathematica_code(meijerg( ((1, 1), (3, 4)), ((1, ), ()), x)) == 'MeijerG[{{1, 1}, {3, 4}}, {{1}, {}}, x]') assert (mathematica_code(hyper( (1, 2, 3), (3, 4), x)) == 'HypergeometricPFQ[{1, 2, 3}, {3, 4}, x]') assert mathematica_code(Min(x, y)) == 'Min[x, y]' assert mathematica_code(Max(x, y)) == 'Max[x, y]' assert mathematica_code(Max(x, 2)) == 'Max[2, x]' # issue sympy/sympy#15344 assert mathematica_code(binomial(x, y)) == 'Binomial[x, y]' assert mathematica_code(log(x)) == 'Log[x]' assert mathematica_code(tan(x)) == 'Tan[x]' assert mathematica_code(cot(x)) == 'Cot[x]' assert mathematica_code(asin(x)) == 'ArcSin[x]' assert mathematica_code(acos(x)) == 'ArcCos[x]' assert mathematica_code(atan(x)) == 'ArcTan[x]' assert mathematica_code(acot(x)) == 'ArcCot[x]' assert mathematica_code(sinh(x)) == 'Sinh[x]' assert mathematica_code(cosh(x)) == 'Cosh[x]' assert mathematica_code(tanh(x)) == 'Tanh[x]' assert mathematica_code(coth(x)) == 'Coth[x]' assert mathematica_code(asinh(x)) == 'ArcSinh[x]' assert mathematica_code(acosh(x)) == 'ArcCosh[x]' assert mathematica_code(atanh(x)) == 'ArcTanh[x]' assert mathematica_code(acoth(x)) == 'ArcCoth[x]' assert mathematica_code(sech(x)) == 'Sech[x]' assert mathematica_code(csch(x)) == 'Csch[x]' assert mathematica_code(erf(x)) == 'Erf[x]' assert mathematica_code(erfi(x)) == 'Erfi[x]' assert mathematica_code(erfc(x)) == 'Erfc[x]' assert mathematica_code(conjugate(x)) == 'Conjugate[x]' assert mathematica_code(re(x)) == 'Re[x]' assert mathematica_code(im(x)) == 'Im[x]' assert mathematica_code(polygamma(x, y)) == 'PolyGamma[x, y]' assert mathematica_code(factorial(x)) == 'Factorial[x]' assert mathematica_code(factorial2(x)) == 'Factorial2[x]' assert mathematica_code(rf(x, y)) == 'Pochhammer[x, y]' assert mathematica_code(gamma(x)) == 'Gamma[x]' assert mathematica_code(zeta(x)) == 'Zeta[x]' assert mathematica_code(Heaviside(x)) == 'UnitStep[x]' assert mathematica_code(fibonacci(x)) == 'Fibonacci[x]' assert mathematica_code(polylog(x, y)) == 'PolyLog[x, y]' assert mathematica_code(loggamma(x)) == 'LogGamma[x]' assert mathematica_code(uppergamma(x, y)) == 'Gamma[x, y]' class MyFunc1(Function): @classmethod def eval(cls, x): pass class MyFunc2(Function): @classmethod def eval(cls, x, y): pass pytest.raises( ValueError, lambda: mathematica_code(MyFunc1(x), user_functions={'MyFunc1': ['Myfunc1']})) assert mathematica_code(MyFunc1(x), user_functions={'MyFunc1': 'Myfunc1'}) == 'Myfunc1[x]' assert mathematica_code( MyFunc2(x, y), user_functions={'MyFunc2': [(lambda *x: False, 'Myfunc2')]}) == 'MyFunc2[x, y]'
def test_elliptic_pi(): assert elliptic_pi(0, z, m) == elliptic_f(z, m) assert elliptic_pi(1, z, m) == elliptic_f(z, m) + \ (sqrt(1 - m*sin(z)**2)*tan(z) - elliptic_e(z, m))/(1 - m) assert elliptic_pi(n, i * pi / 2, m) == i * elliptic_pi(n, m) assert elliptic_pi(n, z, 0) == atanh(sqrt(n - 1) * tan(z)) / sqrt(n - 1) assert elliptic_pi(n, z, n) == elliptic_f(z, n) - elliptic_pi( 1, z, n) + tan(z) / sqrt(1 - n * sin(z)**2) assert elliptic_pi(oo, z, m) == 0 assert elliptic_pi(-oo, z, m) == 0 assert elliptic_pi(n, z, oo) == 0 assert elliptic_pi(n, z, -oo) == 0 assert elliptic_pi(0, m) == elliptic_k(m) assert elliptic_pi(1, m) == zoo assert elliptic_pi(n, 0) == pi / (2 * sqrt(1 - n)) assert elliptic_pi(2, 1) == -oo assert elliptic_pi(-1, 1) == oo assert elliptic_pi(n, n) == elliptic_e(n) / (1 - n) assert elliptic_pi(oo, m) == 0 assert elliptic_pi(n, oo) == 0 assert elliptic_pi(n, -z, m) == -elliptic_pi(n, z, m) ni, mi = Symbol('n', extended_real=False), Symbol('m', extended_real=False) assert elliptic_pi(ni, z, mi).conjugate() == \ elliptic_pi(ni.conjugate(), z.conjugate(), mi.conjugate()) nr, mr = Symbol('n', extended_real=True, negative=True), \ Symbol('m', extended_real=True, negative=True) assert elliptic_pi(nr, z, mr).conjugate() == elliptic_pi(nr, z.conjugate(), mr) assert elliptic_pi(n, m).conjugate() == elliptic_pi(n.conjugate(), m.conjugate()) assert elliptic_pi(n, z, m).conjugate() == conjugate(elliptic_pi(n, z, m)) assert elliptic_pi( n, z, m).diff(n) == (elliptic_e(z, m) + (m - n) * elliptic_f(z, m) / n + (n**2 - m) * elliptic_pi(n, z, m) / n - n * sqrt(1 - m * sin(z)**2) * sin(2 * z) / (2 * (1 - n * sin(z)**2))) / (2 * (m - n) * (n - 1)) assert elliptic_pi(n, z, m).diff(z) == 1 / (sqrt(1 - m * sin(z)**2) * (1 - n * sin(z)**2)) assert elliptic_pi( n, z, m).diff(m) == (elliptic_e(z, m) / (m - 1) + elliptic_pi(n, z, m) - m * sin(2 * z) / (2 * (m - 1) * sqrt(1 - m * sin(z)**2))) / (2 * (n - m)) assert elliptic_pi( n, m).diff(n) == (elliptic_e(m) + (m - n) * elliptic_k(m) / n + (n**2 - m) * elliptic_pi(n, m) / n) / (2 * (m - n) * (n - 1)) assert elliptic_pi( n, m).diff(m) == (elliptic_e(m) / (m - 1) + elliptic_pi(n, m)) / (2 * (n - m)) # workaround fredrik-johansson/mpmath#571, suggested by Kalevi Suominen # in https://github.com/sympy/sympy/issues/20933#issuecomment-779077562 bounds = {'a': -0.9, 'b': -0.9, 'c': 0.9, 'd': 0.9} rx, ry = randcplx(**bounds), randcplx(**bounds) assert td(elliptic_pi(n, rx, ry), n, **bounds) assert td(elliptic_pi(rx, z, ry), z, **bounds) assert td(elliptic_pi(rx, ry, m), m, **bounds) pytest.raises(ArgumentIndexError, lambda: elliptic_pi(n, z, m).fdiff(4)) pytest.raises(ArgumentIndexError, lambda: elliptic_pi(n, m).fdiff(3)) assert elliptic_pi(n, z, m).series(z) == z + z**3*(m/6 + n/3) + \ z**5*(3*m**2/40 + m*n/10 - m/30 + n**2/5 - n/15) + O(z**6)
def test_atanh(): # TODO please write more tests -- see issue sympy/sympy#3751 # From http://functions.wolfram.com/ElementaryFunctions/ArcTanh/03/01/ # at specific points # at specific points assert atanh(0) == 0 assert atanh(I) == I * pi / 4 assert atanh(-I) == -I * pi / 4 assert atanh(1) == oo assert atanh(-1) == -oo assert atanh(-2) == -atanh(2) # at infinites assert atanh(I * oo) == I * pi / 2 assert atanh(-I * oo) == -I * pi / 2 assert atanh(zoo) == nan # properties assert atanh(-x) == -atanh(x) assert atanh(I / sqrt(3)) == I * pi / 6 assert atanh(-I / sqrt(3)) == -I * pi / 6 assert atanh(I * sqrt(3)) == I * pi / 3 assert atanh(-I * sqrt(3)) == -I * pi / 3 assert atanh(I * (1 + sqrt(2))) == 3 * pi * I / 8 assert atanh(I * (sqrt(2) - 1)) == pi * I / 8 assert atanh(I * (1 - sqrt(2))) == -pi * I / 8 assert atanh(-I * (1 + sqrt(2))) == -3 * pi * I / 8 assert atanh(I * sqrt(5 + 2 * sqrt(5))) == 2 * I * pi / 5 assert atanh(-I * sqrt(5 + 2 * sqrt(5))) == -2 * I * pi / 5 assert atanh(I * (2 - sqrt(3))) == pi * I / 12 assert atanh(I * (sqrt(3) - 2)) == -pi * I / 12 assert atanh(oo) == -I * pi / 2 assert atanh(-oo) == I * pi / 2 pytest.raises(ArgumentIndexError, lambda: atanh(x).fdiff(2))