def test_issue_75(): assert limit(abs(log(x)), x, oo) == oo assert limit(tan(abs(pi/2 + 1/x))/acosh(pi/2 + 1/x), x, oo) == -oo assert limit(tan(abs(pi/2 - 1/x))/acosh(pi/2 - 1/x), x, oo) == +oo assert limit(abs(log(2 + 1/x)) - log(2 + 1/x), x, oo) == 0 assert limit(abs(log(2 - 1/x)) - log(2 - 1/x), x, oo) == 0
def test_diofantissue_75(): assert gruntz(abs(log(x)), x) == oo assert gruntz(tan(abs(pi / 2 + 1 / x)) / acosh(pi / 2 + 1 / x), x) == -oo assert gruntz(tan(abs(pi / 2 - 1 / x)) / acosh(pi / 2 - 1 / x), x) == +oo assert gruntz(abs(log(2 + 1 / x)) - log(2 + 1 / x), x) == 0 assert gruntz(abs(log(2 - 1 / x)) - log(2 - 1 / x), x) == 0
def test_acosh_series(): x = Symbol('x') assert acosh(x).series(x, 0, 8) == \ -I*x + pi*I/2 - I*x**3/6 - 3*I*x**5/40 - 5*I*x**7/112 + O(x**8) t5 = acosh(x).taylor_term(5, x) assert t5 == -3 * I * x**5 / 40 assert acosh(x).taylor_term(7, x, t5, 0) == -5 * I * x**7 / 112
def test_diofantissue_75(): assert gruntz(abs(log(x)), x) == oo assert gruntz(tan(abs(pi/2 + 1/x))/acosh(pi/2 + 1/x), x) == -oo assert gruntz(tan(abs(pi/2 - 1/x))/acosh(pi/2 - 1/x), x) == +oo assert gruntz(abs(log(2 + 1/x)) - log(2 + 1/x), x) == 0 assert gruntz(abs(log(2 - 1/x)) - log(2 - 1/x), x) == 0
def test_acosh_series(): assert (acosh(x).series(x, 0, 8) == -I * x + pi * I / 2 - I * x**3 / 6 - 3 * I * x**5 / 40 - 5 * I * x**7 / 112 + O(x**8)) t5 = acosh(x).taylor_term(5, x) assert t5 == -3 * I * x**5 / 40 assert acosh(x).taylor_term(7, x, t5, 0) == -5 * I * x**7 / 112 assert (acosh(x).series(x, x0=1, n=2) == sqrt(2) * sqrt(x - 1) - sqrt(2) * sqrt(x - 1)**3 / 12 + O((x - 1)**2, (x, 1)))
def test_acosh(): assert limit(acosh(I*x), x, 0) == 2*log(1 + I) - log(2) assert limit(acosh(I*x), x, 0, 1) == 2*log(1 - I) - log(2) assert limit(acosh(-I*x), x, 0) == 2*log(1 - I) - log(2) assert limit(acosh(-I*x), x, 0, 1) == 2*log(1 + I) - log(2) pytest.raises(PoleError, lambda: limit(acosh(I*x), x, 0, Reals)) assert limit(acosh(x - I*x), x, 0) == 2*log(1 - I) - log(2) assert limit(acosh(x - I*x), x, 0, 1) == 2*log(1 + I) - log(2) pytest.raises(PoleError, lambda: limit(acosh(x - I*x), x, 0, Reals)) assert limit(acosh(I*x**2), x, 0, Reals) == 2*log(1 + I) - log(2) assert limit(acosh(x**2 - I*x**2), x, 0, Reals) == 2*log(1 - I) - log(2)
def test_intractable(): assert limit(1/gamma(x), x, oo) == 0 assert limit(1/loggamma(x), x, oo) == 0 assert limit(gamma(x)/loggamma(x), x, oo) == oo assert limit(exp(gamma(x))/gamma(x), x, oo) == oo assert limit(gamma(3 + 1/x), x, oo) == 2 assert limit(gamma(Rational(1, 7) + 1/x), x, oo) == gamma(Rational(1, 7)) assert limit(log(x**x)/log(gamma(x)), x, oo) == 1 assert limit(log(gamma(gamma(x)))/exp(x), x, oo) == oo assert limit(acosh(1 + 1/x)*sqrt(x), x, oo) == sqrt(2) # issue sympy/sympy#10804 assert limit(2*airyai(x)*root(x, 4) * exp(2*x**Rational(3, 2)/3), x, oo) == 1/sqrt(pi) assert limit(airybi(x)*root(x, 4) * exp(-2*x**Rational(3, 2)/3), x, oo) == 1/sqrt(pi) assert limit(airyai(1/x), x, oo) == (3**Rational(5, 6) * gamma(Rational(1, 3))/(6*pi)) assert limit(airybi(1/x), x, oo) == cbrt(3)*gamma(Rational(1, 3))/(2*pi) assert limit(airyai(2 + 1/x), x, oo) == airyai(2) assert limit(airybi(2 + 1/x), x, oo) == airybi(2) # issue sympy/sympy#10976 assert limit(erf(m/x)/erf(1/x), x, oo) == m assert limit(Max(x**2, x, exp(x))/x, x, oo) == oo
def test_messy(): assert laplace_transform(Si(x), x, s) == ((-atan(s) + pi/2)/s, 0, True) assert laplace_transform(Shi(x), x, s) == (acoth(s)/s, 1, True) # where should the logs be simplified? assert laplace_transform(Chi(x), x, s) == \ ((log(s**(-2)) - log((s**2 - 1)/s**2))/(2*s), 1, True) # TODO maybe simplify the inequalities? assert laplace_transform(besselj(a, x), x, s)[1:] == \ (0, And(Integer(0) < re(a/2) + Rational(1, 2), Integer(0) < re(a/2) + 1)) # NOTE s < 0 can be done, but argument reduction is not good enough yet assert fourier_transform(besselj(1, x)/x, x, s, noconds=False) == \ (Piecewise((0, 4*abs(pi**2*s**2) > 1), (2*sqrt(-4*pi**2*s**2 + 1), True)), s > 0) # TODO FT(besselj(0,x)) - conditions are messy (but for acceptable reasons) # - folding could be better assert integrate(E1(x)*besselj(0, x), (x, 0, oo), meijerg=True) == \ log(1 + sqrt(2)) assert integrate(E1(x)*besselj(1, x), (x, 0, oo), meijerg=True) == \ log(Rational(1, 2) + sqrt(2)/2) assert integrate(1/x/sqrt(1 - x**2), x, meijerg=True) == \ Piecewise((-acosh(1/x), 1 < abs(x**(-2))), (I*asin(1/x), True))
def test_messy(): assert laplace_transform(Si(x), x, s) == ((-atan(s) + pi / 2) / s, 0, True) assert laplace_transform(Shi(x), x, s) == (acoth(s) / s, 1, True) # where should the logs be simplified? assert laplace_transform(Chi(x), x, s) == \ ((log(s**(-2)) - log((s**2 - 1)/s**2))/(2*s), 1, True) # TODO maybe simplify the inequalities? assert laplace_transform(besselj(a, x), x, s)[1:] == \ (0, And(Integer(0) < re(a/2) + Rational(1, 2), Integer(0) < re(a/2) + 1)) # NOTE s < 0 can be done, but argument reduction is not good enough yet assert fourier_transform(besselj(1, x)/x, x, s, noconds=False) == \ (Piecewise((0, 4*abs(pi**2*s**2) > 1), (2*sqrt(-4*pi**2*s**2 + 1), True)), s > 0) # TODO FT(besselj(0,x)) - conditions are messy (but for acceptable reasons) # - folding could be better assert integrate(E1(x)*besselj(0, x), (x, 0, oo), meijerg=True) == \ log(1 + sqrt(2)) assert integrate(E1(x)*besselj(1, x), (x, 0, oo), meijerg=True) == \ log(Rational(1, 2) + sqrt(2)/2) assert integrate(1/x/sqrt(1 - x**2), x, meijerg=True) == \ Piecewise((-acosh(1/x), 1 < abs(x**(-2))), (I*asin(1/x), True))
def test_numpy_numexpr(): a, b, c = numpy.random.randn(3, 128, 128) # ensure that numpy and numexpr return same value for complicated expression expr = (sin(x) + cos(y) + tan(z)**2 + Abs(z - y)*acos(sin(y*z)) + Abs(y - z)*acosh(2 + exp(y - x)) - sqrt(x**2 + I*y**2)) npfunc = lambdify((x, y, z), expr, modules='numpy') nefunc = lambdify((x, y, z), expr, modules='numexpr') assert numpy.allclose(npfunc(a, b, c), nefunc(a, b, c))
def test_sympyissue_4492(): assert simplify(integrate(x**2 * sqrt(5 - x**2), x)) == Piecewise( (I * (2 * x**5 - 15 * x**3 + 25 * x - 25 * sqrt(x**2 - 5) * acosh(sqrt(5) * x / 5)) / (8 * sqrt(x**2 - 5)), 1 < Abs(x**2) / 5), ((-2 * x**5 + 15 * x**3 - 25 * x + 25 * sqrt(-x**2 + 5) * asin(sqrt(5) * x / 5)) / (8 * sqrt(-x**2 + 5)), True))
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_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_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_sympyissue_4403(): x = Symbol('x') z = Symbol('z', positive=True) assert integrate(sqrt(x**2 + z**2), x) == \ z**2*asinh(x/z)/2 + x*sqrt(x**2 + z**2)/2 assert integrate(sqrt(x**2 - z**2), x) == \ -z**2*acosh(x/z)/2 + x*sqrt(x**2 - z**2)/2 x = Symbol('x', extended_real=True) y = Symbol('y', nonzero=True, extended_real=True) assert integrate(1/(x**2 + y**2)**Rational(3, 2), x) == \ 1/(y**2*sqrt(1 + y**2/x**2))
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_leading_term(): assert cosh(x).as_leading_term(x) == 1 assert coth(x).as_leading_term(x) == 1 / x assert acosh(x).as_leading_term(x) == I * pi / 2 assert acoth(x).as_leading_term(x) == -I * pi / 2 for func in [sinh, tanh, asinh, atanh]: assert func(x).as_leading_term(x) == x for func in [sinh, cosh, tanh, coth, asinh, acosh, atanh, acoth]: for arg in (1 / x, Rational(1, 2)): eq = func(arg) assert eq.as_leading_term(x) == eq for func in [csch, sech]: eq = func(Rational(1, 2)) assert eq.as_leading_term(x) == eq assert csch(x).as_leading_term(x) == 1 / x
def test_leading_term(): assert cosh(x).as_leading_term(x) == 1 assert coth(x).as_leading_term(x) == 1/x assert acosh(x).as_leading_term(x) == I*pi/2 assert acoth(x).as_leading_term(x) == I*pi/2 for func in [sinh, tanh, asinh, atanh]: assert func(x).as_leading_term(x) == x for func in [sinh, cosh, tanh, coth, asinh, acosh, atanh, acoth]: for arg in (1/x, Rational(1, 2)): eq = func(arg) assert eq.as_leading_term(x) == eq for func in [csch, sech]: eq = func(Rational(1, 2)) assert eq.as_leading_term(x) == eq assert csch(x).as_leading_term(x) == 1/x
def test_leading_term(): x = Symbol('x') assert cosh(x).as_leading_term(x) == 1 assert coth(x).as_leading_term(x) == 1 / x assert acosh(x).as_leading_term(x) == I * pi / 2 assert acoth(x).as_leading_term(x) == I * pi / 2 for func in [sinh, tanh, asinh, atanh]: assert func(x).as_leading_term(x) == x for func in [sinh, cosh, tanh, coth, asinh, acosh, atanh, acoth]: for arg in (1 / x, S.Half): eq = func(arg) assert eq.as_leading_term(x) == eq for func in [csch, sech]: eq = func(S.Half) assert eq.as_leading_term(x) == eq
def test_intractable(): assert gruntz(1/gamma(x), x) == 0 assert gruntz(1/loggamma(x), x) == 0 assert gruntz(gamma(x)/loggamma(x), x) == oo assert gruntz(exp(gamma(x))/gamma(x), x) == oo assert gruntz(gamma(3 + 1/x), x) == 2 assert gruntz(gamma(Rational(1, 7) + 1/x), x) == gamma(Rational(1, 7)) assert gruntz(log(x**x)/log(gamma(x)), x) == 1 assert gruntz(log(gamma(gamma(x)))/exp(x), x) == oo assert gruntz(acosh(1 + 1/x)*sqrt(x), x) == sqrt(2) # issue sympy/sympy#10804 assert gruntz(2*airyai(x)*root(x, 4) * exp(2*x**Rational(3, 2)/3), x) == 1/sqrt(pi) assert gruntz(airybi(x)*root(x, 4) * exp(-2*x**Rational(3, 2)/3), x) == 1/sqrt(pi) assert gruntz(airyai(1/x), x) == (3**Rational(5, 6) * gamma(Rational(1, 3))/(6*pi)) assert gruntz(airybi(1/x), x) == cbrt(3)*gamma(Rational(1, 3))/(2*pi) assert gruntz(airyai(2 + 1/x), x) == airyai(2) assert gruntz(airybi(2 + 1/x), x) == airybi(2)
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_acosh(): # TODO please write more tests -- see issue sympy/sympy#3751 # From http://functions.wolfram.com/ElementaryFunctions/ArcCosh/03/01/ # at specific points assert acosh(-x) == acosh(-x) assert acosh(1) == 0 assert acosh(-1) == pi * I assert acosh(0) == I * pi / 2 assert acosh(Rational(1, 2)) == I * pi / 3 assert acosh(Rational(-1, 2)) == 2 * pi * I / 3 assert acosh(+oo) == oo assert acosh(-oo) == oo assert acosh(+I * oo) == oo assert acosh(-I * oo) == oo assert acosh(zoo) == oo assert acosh(I) == log(I * (1 + sqrt(2))) assert acosh(-I) == log(-I * (1 + sqrt(2))) assert acosh((sqrt(3) - 1) / (2 * sqrt(2))) == 5 * pi * I / 12 assert acosh(-(sqrt(3) - 1) / (2 * sqrt(2))) == 7 * pi * I / 12 assert acosh(sqrt(2) / 2) == I * pi / 4 assert acosh(-sqrt(2) / 2) == 3 * I * pi / 4 assert acosh(sqrt(3) / 2) == I * pi / 6 assert acosh(-sqrt(3) / 2) == 5 * I * pi / 6 assert acosh(sqrt(2 + sqrt(2)) / 2) == I * pi / 8 assert acosh(-sqrt(2 + sqrt(2)) / 2) == 7 * I * pi / 8 assert acosh(sqrt(2 - sqrt(2)) / 2) == 3 * I * pi / 8 assert acosh(-sqrt(2 - sqrt(2)) / 2) == 5 * I * pi / 8 assert acosh((1 + sqrt(3)) / (2 * sqrt(2))) == I * pi / 12 assert acosh(-(1 + sqrt(3)) / (2 * sqrt(2))) == 11 * I * pi / 12 assert acosh((sqrt(5) + 1) / 4) == I * pi / 5 assert acosh(-(sqrt(5) + 1) / 4) == 4 * I * pi / 5 assert str(acosh(5 * I).evalf(6)) == '2.31244 + 1.5708*I' assert str(acosh(-5 * I).evalf(6)) == '2.31244 - 1.5708*I' pytest.raises(ArgumentIndexError, lambda: acosh(x).fdiff(2))
def test_acosh_series(): assert acosh(x).series(x, 0, 8) == \ -I*x + pi*I/2 - I*x**3/6 - 3*I*x**5/40 - 5*I*x**7/112 + O(x**8) t5 = acosh(x).taylor_term(5, x) assert t5 == - 3*I*x**5/40 assert acosh(x).taylor_term(7, x, t5, 0) == - 5*I*x**7/112
def test_sympyissue_22986(): assert limit(acosh(1 + 1/x)*sqrt(x), x, oo) == sqrt(2)
def test_sympyissue_4492(): assert simplify(integrate(x**2 * sqrt(5 - x**2), x)) == Piecewise( (I*(2*x**5 - 15*x**3 + 25*x - 25*sqrt(x**2 - 5)*acosh(sqrt(5)*x/5)) / (8*sqrt(x**2 - 5)), 1 < Abs(x**2)/5), ((-2*x**5 + 15*x**3 - 25*x + 25*sqrt(-x**2 + 5)*asin(sqrt(5)*x/5)) / (8*sqrt(-x**2 + 5)), True))
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_sympyissue_4551(): assert (integrate(1/(x*sqrt(1 - x**2)), x) == Piecewise((-acosh(1/x), abs(x**-2) > 1), (I*asin(1/x), True)))
def test_acosh_infinities(): assert acosh(oo) == oo assert acosh(-oo) == oo assert acosh(I * oo) == oo assert acosh(-I * oo) == oo
def test_acosh_rewrite(): assert acosh(x).rewrite(log) == 2 * log(sqrt(x - 1) + sqrt(x + 1)) - log(2)
def test_sympyissue_4551(): assert (integrate(1/(x*sqrt(1 - x**2)), x) == Piecewise((-acosh(1/x), Abs(x**(-2)) > 1), (I*asin(1/x), True)))
def test_acosh(): # TODO please write more tests -- see issue 3751 # From http://functions.wolfram.com/ElementaryFunctions/ArcCosh/03/01/ # at specific points x = Symbol('x') assert acosh(-x) == acosh(-x) assert acosh(1) == 0 assert acosh(-1) == pi * I assert acosh(0) == I * pi / 2 assert acosh(Rational(1, 2)) == I * pi / 3 assert acosh(Rational(-1, 2)) == 2 * pi * I / 3 assert acosh(zoo) == oo assert acosh(I) == log(I * (1 + sqrt(2))) assert acosh(-I) == log(-I * (1 + sqrt(2))) assert acosh((sqrt(3) - 1) / (2 * sqrt(2))) == 5 * pi * I / 12 assert acosh(-(sqrt(3) - 1) / (2 * sqrt(2))) == 7 * pi * I / 12 assert acosh(sqrt(2) / 2) == I * pi / 4 assert acosh(-sqrt(2) / 2) == 3 * I * pi / 4 assert acosh(sqrt(3) / 2) == I * pi / 6 assert acosh(-sqrt(3) / 2) == 5 * I * pi / 6 assert acosh(sqrt(2 + sqrt(2)) / 2) == I * pi / 8 assert acosh(-sqrt(2 + sqrt(2)) / 2) == 7 * I * pi / 8 assert acosh(sqrt(2 - sqrt(2)) / 2) == 3 * I * pi / 8 assert acosh(-sqrt(2 - sqrt(2)) / 2) == 5 * I * pi / 8 assert acosh((1 + sqrt(3)) / (2 * sqrt(2))) == I * pi / 12 assert acosh(-(1 + sqrt(3)) / (2 * sqrt(2))) == 11 * I * pi / 12 assert acosh((sqrt(5) + 1) / 4) == I * pi / 5 assert acosh(-(sqrt(5) + 1) / 4) == 4 * I * pi / 5 assert str(acosh(5 * I).n(6)) == '2.31244 + 1.5708*I' assert str(acosh(-5 * I).n(6)) == '2.31244 - 1.5708*I'
def test_acosh(): # TODO please write more tests -- see issue sympy/sympy#3751 # From http://functions.wolfram.com/ElementaryFunctions/ArcCosh/03/01/ # at specific points assert acosh(-x) == acosh(-x) assert acosh(1) == 0 assert acosh(-1) == pi*I assert acosh(0) == I*pi/2 assert acosh(Rational(1, 2)) == I*pi/3 assert acosh(Rational(-1, 2)) == 2*pi*I/3 assert acosh(+oo) == oo assert acosh(-oo) == oo assert acosh(+I*oo) == oo assert acosh(-I*oo) == oo assert acosh(zoo) == oo assert acosh(I) == log(I*(1 + sqrt(2))) assert acosh(-I) == log(-I*(1 + sqrt(2))) assert acosh((sqrt(3) - 1)/(2*sqrt(2))) == 5*pi*I/12 assert acosh(-(sqrt(3) - 1)/(2*sqrt(2))) == 7*pi*I/12 assert acosh(sqrt(2)/2) == I*pi/4 assert acosh(-sqrt(2)/2) == 3*I*pi/4 assert acosh(sqrt(3)/2) == I*pi/6 assert acosh(-sqrt(3)/2) == 5*I*pi/6 assert acosh(sqrt(2 + sqrt(2))/2) == I*pi/8 assert acosh(-sqrt(2 + sqrt(2))/2) == 7*I*pi/8 assert acosh(sqrt(2 - sqrt(2))/2) == 3*I*pi/8 assert acosh(-sqrt(2 - sqrt(2))/2) == 5*I*pi/8 assert acosh((1 + sqrt(3))/(2*sqrt(2))) == I*pi/12 assert acosh(-(1 + sqrt(3))/(2*sqrt(2))) == 11*I*pi/12 assert acosh((sqrt(5) + 1)/4) == I*pi/5 assert acosh(-(sqrt(5) + 1)/4) == 4*I*pi/5 assert str(acosh(5*I).evalf(6)) == '2.31244 + 1.5708*I' assert str(acosh(-5*I).evalf(6)) == '2.31244 - 1.5708*I' pytest.raises(ArgumentIndexError, lambda: acosh(x).fdiff(2))