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_acosh(): # TODO please write more tests -- see #652 # From http://functions.wolfram.com/ElementaryFunctions/ArcCosh/03/01/ # at specific points 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
def test_asech(): x = Symbol('x') assert asech(-x) == asech(-x) # values at fixed points assert asech(1) == 0 assert asech(-1) == pi*I assert asech(0) == oo assert asech(2) == I*pi/3 assert asech(-2) == 2*I*pi / 3 # at infinites assert asech(oo) == I*pi/2 assert asech(-oo) == I*pi/2 assert asech(zoo) == nan assert asech(I) == log(1 + sqrt(2)) - I*pi/2 assert asech(-I) == log(1 + sqrt(2)) + I*pi/2 assert asech(sqrt(2) - sqrt(6)) == 11*I*pi / 12 assert asech(sqrt(2 - 2/sqrt(5))) == I*pi / 10 assert asech(-sqrt(2 - 2/sqrt(5))) == 9*I*pi / 10 assert asech(2 / sqrt(2 + sqrt(2))) == I*pi / 8 assert asech(-2 / sqrt(2 + sqrt(2))) == 7*I*pi / 8 assert asech(sqrt(5) - 1) == I*pi / 5 assert asech(1 - sqrt(5)) == 4*I*pi / 5 assert asech(-sqrt(2*(2 + sqrt(2)))) == 5*I*pi / 8 # properties # asech(x) == acosh(1/x) assert asech(sqrt(2)) == acosh(1/sqrt(2)) assert asech(2/sqrt(3)) == acosh(sqrt(3)/2) assert asech(2/sqrt(2 + sqrt(2))) == acosh(sqrt(2 + sqrt(2))/2) assert asech(S(2)) == acosh(1/S(2)) # asech(x) == I*acos(1/x) # (Note: the exact formula is asech(x) == +/- I*acos(1/x)) assert asech(-sqrt(2)) == I*acos(-1/sqrt(2)) assert asech(-2/sqrt(3)) == I*acos(-sqrt(3)/2) assert asech(-S(2)) == I*acos(-S.Half) assert asech(-2/sqrt(2)) == I*acos(-sqrt(2)/2) # sech(asech(x)) / x == 1 assert expand_mul(sech(asech(sqrt(6) - sqrt(2))) / (sqrt(6) - sqrt(2))) == 1 assert expand_mul(sech(asech(sqrt(6) + sqrt(2))) / (sqrt(6) + sqrt(2))) == 1 assert (sech(asech(sqrt(2 + 2/sqrt(5)))) / (sqrt(2 + 2/sqrt(5)))).simplify() == 1 assert (sech(asech(-sqrt(2 + 2/sqrt(5)))) / (-sqrt(2 + 2/sqrt(5)))).simplify() == 1 assert (sech(asech(sqrt(2*(2 + sqrt(2))))) / (sqrt(2*(2 + sqrt(2))))).simplify() == 1 assert expand_mul(sech(asech((1 + sqrt(5)))) / ((1 + sqrt(5)))) == 1 assert expand_mul(sech(asech((-1 - sqrt(5)))) / ((-1 - sqrt(5)))) == 1 assert expand_mul(sech(asech((-sqrt(6) - sqrt(2)))) / ((-sqrt(6) - sqrt(2)))) == 1 # numerical evaluation assert str(asech(5*I).n(6)) == '0.19869 - 1.5708*I' assert str(asech(-5*I).n(6)) == '0.19869 + 1.5708*I'
def test_manualintegrate_inversetrig(): # atan assert manualintegrate(exp(x) / (1 + exp(2*x)), x) == atan(exp(x)) assert manualintegrate(1 / (4 + 9 * x**2), x) == atan(3 * x/2) / 6 assert manualintegrate(1 / (16 + 16 * x**2), x) == atan(x) / 16 assert manualintegrate(1 / (4 + x**2), x) == atan(x / 2) / 2 assert manualintegrate(1 / (1 + 4 * x**2), x) == atan(2*x) / 2 assert manualintegrate(1/(a + b*x**2), x) == \ Piecewise(((sqrt(a/b)*atan(x*sqrt(b/a))/a), And(a > 0, b > 0))) assert manualintegrate(1/(4 + b*x**2), x) == \ Piecewise((sqrt(1/b)*atan(sqrt(b)*x/2)/2, b > 0)) assert manualintegrate(1/(a + 4*x**2), x) == \ Piecewise((atan(2*x*sqrt(1/a))/(2*sqrt(a)), a > 0)) assert manualintegrate(1/(4 + 4*x**2), x) == atan(x) / 4 # asin assert manualintegrate(1/sqrt(1-x**2), x) == asin(x) assert manualintegrate(1/sqrt(4-4*x**2), x) == asin(x)/2 assert manualintegrate(3/sqrt(1-9*x**2), x) == asin(3*x) assert manualintegrate(1/sqrt(4-9*x**2), x) == asin(3*x/2)/3 # asinh assert manualintegrate(1/sqrt(x**2 + 1), x) == \ asinh(x) assert manualintegrate(1/sqrt(x**2 + 4), x) == \ asinh(x/2) assert manualintegrate(1/sqrt(4*x**2 + 4), x) == \ asinh(x)/2 assert manualintegrate(1/sqrt(4*x**2 + 1), x) == \ asinh(2*x)/2 assert manualintegrate(1/sqrt(a*x**2 + 1), x) == \ Piecewise((sqrt(-1/a)*asin(x*sqrt(-a)), a < 0), (sqrt(1/a)*asinh(sqrt(a)*x), a > 0)) assert manualintegrate(1/sqrt(a + x**2), x) == \ Piecewise((asinh(x*sqrt(1/a)), a > 0), (acosh(x*sqrt(-1/a)), a < 0)) # acosh assert manualintegrate(1/sqrt(x**2 - 1), x) == \ acosh(x) assert manualintegrate(1/sqrt(x**2 - 4), x) == \ acosh(x/2) assert manualintegrate(1/sqrt(4*x**2 - 4), x) == \ acosh(x)/2 assert manualintegrate(1/sqrt(9*x**2 - 1), x) == \ acosh(3*x)/3 assert manualintegrate(1/sqrt(a*x**2 - 4), x) == \ Piecewise((sqrt(1/a)*acosh(sqrt(a)*x/2), a > 0)) assert manualintegrate(1/sqrt(-a + 4*x**2), x) == \ Piecewise((asinh(2*x*sqrt(-1/a))/2, -a > 0), (acosh(2*x*sqrt(1/a))/2, -a < 0)) # piecewise assert manualintegrate(1/sqrt(a-b*x**2), x) == \ Piecewise((sqrt(a/b)*asin(x*sqrt(b/a))/sqrt(a), And(-b < 0, a > 0)), (sqrt(-a/b)*asinh(x*sqrt(-b/a))/sqrt(a), And(-b > 0, a > 0)), (sqrt(a/b)*acosh(x*sqrt(b/a))/sqrt(-a), And(-b > 0, a < 0))) assert manualintegrate(1/sqrt(a + b*x**2), x) == \ Piecewise((sqrt(-a/b)*asin(x*sqrt(-b/a))/sqrt(a), And(a > 0, b < 0)), (sqrt(a/b)*asinh(x*sqrt(b/a))/sqrt(a), And(a > 0, b > 0)), (sqrt(-a/b)*acosh(x*sqrt(-b/a))/sqrt(-a), And(a < 0, b > 0)))
def test_simplifications(): x = Symbol("x") 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 cosh(asinh(x)) == sqrt(1 + x ** 2) assert cosh(acosh(x)) == x assert cosh(atanh(x)) == 1 / sqrt(1 - x ** 2) 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
def test_messy(): from sympy import (laplace_transform, Si, Shi, Chi, atan, Piecewise, acoth, E1, besselj, acosh, asin, And, re, fourier_transform, sqrt) 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(S(0) < re(a/2) + S(1)/2, S(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(S(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_issue_1304(): z = Symbol("z", positive=True) assert integrate(sqrt(x ** 2 + z ** 2), x) == z ** 2 * asinh(x / z) / 2 + x * (x ** 2 + z ** 2) ** (S(1) / 2) / 2 assert integrate(sqrt(x ** 2 - z ** 2), x) == -z ** 2 * acosh(x / z) / 2 + x * (x ** 2 - z ** 2) ** (S(1) / 2) / 2 assert ( integrate(sqrt(-x ** 2 - 4), x) == -2 * atan(x / (-4 - x ** 2) ** (S(1) / 2)) + x * (-4 - x ** 2) ** (S(1) / 2) / 2 )
def test_derivs(): x = Symbol('x') 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 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_inverses(): x = Symbol('x') assert sinh(x).inverse() == asinh 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(): x = Symbol("x") assert sinh(x).nseries(x, 0, 6) == x + x**3/6 + x**5/120 + O(x**6) assert cosh(x).nseries(x, 0, 5) == 1 + x**2/2 + x**4/24 + O(x**5) assert tanh(x).nseries(x, 0, 6) == x - x**3/3 + 2*x**5/15 + O(x**6) assert coth(x).nseries(x, 0, 6) == 1/x - x**3/45 + x/3 + 2*x**5/945 + O(x**6) assert asinh(x).nseries(x, 0, 6) == x - x**3/6 + 3*x**5/40 + O(x**6) assert acosh(x).nseries(x, 0, 6) == pi*I/2 - I*x - 3*I*x**5/40 - I*x**3/6 + O(x**6) assert atanh(x).nseries(x, 0, 6) == x + x**3/3 + x**5/5 + O(x**6) assert acoth(x).nseries(x, 0, 6) == x + x**3/3 + x**5/5 + pi*I/2 + O(x**6)
def test_conv12b(): x = sympy.Symbol("x") y = sympy.Symbol("y") assert sympify(sympy.sinh(x/3)) == sinh(Symbol("x") / 3) assert sympify(sympy.cosh(x/3)) == cosh(Symbol("x") / 3) assert sympify(sympy.tanh(x/3)) == tanh(Symbol("x") / 3) assert sympify(sympy.coth(x/3)) == coth(Symbol("x") / 3) assert sympify(sympy.asinh(x/3)) == asinh(Symbol("x") / 3) assert sympify(sympy.acosh(x/3)) == acosh(Symbol("x") / 3) assert sympify(sympy.atanh(x/3)) == atanh(Symbol("x") / 3) assert sympify(sympy.acoth(x/3)) == acoth(Symbol("x") / 3)
def test_inverses(): x = Symbol('x') assert sinh(x).inverse() == asinh 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 assert asech(x).inverse() == sech
def test_hyperbolic(): assert sinh(x).nseries(x, n=6) == x + x**3/6 + x**5/120 + O(x**6) assert cosh(x).nseries(x, n=5) == 1 + x**2/2 + x**4/24 + O(x**5) assert tanh(x).nseries(x, n=6) == x - x**3/3 + 2*x**5/15 + O(x**6) assert coth(x).nseries(x, n=6) == \ 1/x - x**3/45 + x/3 + 2*x**5/945 + O(x**6) assert asinh(x).nseries(x, n=6) == x - x**3/6 + 3*x**5/40 + O(x**6) assert acosh(x).nseries(x, n=6) == \ pi*I/2 - I*x - 3*I*x**5/40 - I*x**3/6 + O(x**6) assert atanh(x).nseries(x, n=6) == x + x**3/3 + x**5/5 + O(x**6) assert acoth(x).nseries(x, n=6) == x + x**3/3 + x**5/5 + pi*I/2 + O(x**6)
def test_numpy_numexpr(): if not numpy: skip("numpy not installed.") if not numexpr: skip("numexpr not installed.") 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_derivs(): x = Symbol('x') 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_issue_1304(): z = Symbol('z', positive=True) assert integrate( sqrt(x**2 + z**2), x) == z**2 * asinh(x / z) / 2 + x * (x**2 + z**2)**(S(1) / 2) / 2 assert integrate( sqrt(x**2 - z**2), x) == -z**2 * acosh(x / z) / 2 + x * (x**2 - z**2)**(S(1) / 2) / 2 assert integrate( sqrt(-x**2 - 4), x) == -2 * atan(x / (-4 - x**2)** (S(1) / 2)) + x * (-4 - x**2)**(S(1) / 2) / 2
def test_simplifications(): x = Symbol('x') 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
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
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
def test_simplifications(): x = Symbol('x') 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_issue_4403(): x = Symbol('x') y = Symbol('y') 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', real=True) y = Symbol('y', nonzero=True, real=True) assert integrate(1/(x**2 + y**2)**S('3/2'), x) == \ 1/(y**2*sqrt(1 + y**2/x**2))
def test_issue_4403(): x = Symbol('x') y = Symbol('y') 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', real=True) y = Symbol('y', positive=True) assert integrate(1/(x**2 + y**2)**S('3/2'), x) == \ x/(y**2*sqrt(x**2 + y**2))
def test_fps__hyper(): f = sin(x) assert fps(f, x).truncate() == x - x ** 3 / 6 + x ** 5 / 120 + O(x ** 6) f = cos(x) assert fps(f, x).truncate() == 1 - x ** 2 / 2 + x ** 4 / 24 + O(x ** 6) f = exp(x) assert fps(f, x).truncate() == 1 + x + x ** 2 / 2 + x ** 3 / 6 + x ** 4 / 24 + x ** 5 / 120 + O(x ** 6) f = atan(x) assert fps(f, x).truncate() == x - x ** 3 / 3 + x ** 5 / 5 + O(x ** 6) f = exp(acos(x)) assert fps(f, x).truncate() == ( exp(pi / 2) - x * exp(pi / 2) + x ** 2 * exp(pi / 2) / 2 - x ** 3 * exp(pi / 2) / 3 + 5 * x ** 4 * exp(pi / 2) / 24 - x ** 5 * exp(pi / 2) / 6 + O(x ** 6) ) f = exp(acosh(x)) assert fps(f, x).truncate() == I + x - I * x ** 2 / 2 - I * x ** 4 / 8 + O(x ** 6) f = atan(1 / x) assert fps(f, x).truncate() == pi / 2 - x + x ** 3 / 3 - x ** 5 / 5 + O(x ** 6) f = x * atan(x) - log(1 + x ** 2) / 2 assert fps(f, x, rational=False).truncate() == x ** 2 / 2 - x ** 4 / 12 + O(x ** 6) f = log(1 + x) assert fps(f, x, rational=False).truncate() == x - x ** 2 / 2 + x ** 3 / 3 - x ** 4 / 4 + x ** 5 / 5 + O(x ** 6) f = airyai(x ** 2) assert fps(f, x).truncate() == ( 3 ** Rational(5, 6) * gamma(Rational(1, 3)) / (6 * pi) - 3 ** Rational(2, 3) * x ** 2 / (3 * gamma(Rational(1, 3))) + O(x ** 6) ) f = exp(x) * sin(x) assert fps(f, x).truncate() == x + x ** 2 + x ** 3 / 3 - x ** 5 / 30 + O(x ** 6) f = exp(x) * sin(x) / x assert fps(f, x).truncate() == 1 + x + x ** 2 / 3 - x ** 4 / 30 - x ** 5 / 90 + O(x ** 6) f = sin(x) * cos(x) assert fps(f, x).truncate() == x - 2 * x ** 3 / 3 + 2 * x ** 5 / 15 + O(x ** 6)
def test_fps__hyper(): f = sin(x) assert fps(f, x).truncate() == x - x**3 / 6 + x**5 / 120 + O(x**6) f = cos(x) assert fps(f, x).truncate() == 1 - x**2 / 2 + x**4 / 24 + O(x**6) f = exp(x) assert fps(f, x).truncate( ) == 1 + x + x**2 / 2 + x**3 / 6 + x**4 / 24 + x**5 / 120 + O(x**6) f = atan(x) assert fps(f, x).truncate() == x - x**3 / 3 + x**5 / 5 + O(x**6) f = exp(acos(x)) assert fps( f, x).truncate() == (exp(pi / 2) - x * exp(pi / 2) + x**2 * exp(pi / 2) / 2 - x**3 * exp(pi / 2) / 3 + 5 * x**4 * exp(pi / 2) / 24 - x**5 * exp(pi / 2) / 6 + O(x**6)) f = exp(acosh(x)) assert fps(f, x).truncate() == I + x - I * x**2 / 2 - I * x**4 / 8 + O(x**6) f = atan(1 / x) assert fps(f, x).truncate() == pi / 2 - x + x**3 / 3 - x**5 / 5 + O(x**6) f = x * atan(x) - log(1 + x**2) / 2 assert fps(f, x, rational=False).truncate() == x**2 / 2 - x**4 / 12 + O(x**6) f = log(1 + x) assert fps(f, x, rational=False).truncate( ) == x - x**2 / 2 + x**3 / 3 - x**4 / 4 + x**5 / 5 + O(x**6) f = airyai(x**2) assert fps(f, x).truncate() == (3**Rational(5, 6) * gamma(Rational(1, 3)) / (6 * pi) - 3**Rational(2, 3) * x**2 / (3 * gamma(Rational(1, 3))) + O(x**6)) f = exp(x) * sin(x) assert fps(f, x).truncate() == x + x**2 + x**3 / 3 - x**5 / 30 + O(x**6) f = exp(x) * sin(x) / x assert fps( f, x).truncate() == 1 + x + x**2 / 3 - x**4 / 30 - x**5 / 90 + O(x**6) f = sin(x) * cos(x) assert fps(f, x).truncate() == x - 2 * x**3 / 3 + 2 * x**5 / 15 + O(x**6)
def test_derivs(): x = Symbol('x') 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) assert asech(x).diff(x) == -1/(x*sqrt(1 - x**2)) assert acsch(x).diff(x) == -1/(x**2*sqrt(1 + x**(-2)))
def test_derivs(): x = Symbol("x") 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) assert asech(x).diff(x) == -1 / (x * sqrt(1 - x ** 2)) assert acsch(x).diff(x) == -1 / (x ** 2 * sqrt(1 + x ** (-2)))
def solve_cubic(a, b, c, d): """ Return possible roots of ax³+bx²+cx=d a, b, c, d are SymPy symbols (assuming real numbers) """ from sympy import sympify, simplify from sympy import sqrt, sin, asin, sinh, asinh, cosh, acosh, pi a, b, c, d = sympify(a), sympify(b), sympify(c), sympify(d) b, c, d = b / a, c / a, d / a # shift the cubic function so it becomes x³+px+q f = -b / 3 p = 3 * f**2 + 2 * b * f + c q = f**3 + b * f**2 + c * f + d # different cases when the sign of p is different u = simplify(2 * sqrt(-p / 3)) mq = simplify((4 / u**3) * q) v = simplify(2 * sqrt(p / 3)) nq = simplify((4 / v**3) * q) # three roots r1 = [u * sin(asin(mq) / 3) + f, -v * sinh(asinh(nq) / 3) + f] r2 = [u * sin((asin(mq) - 2 * pi) / 3) + f, -u * cosh(acosh(mq) / 3) + f] r3 = [u * sin((asin(mq) + 2 * pi) / 3) + f, u * cosh(-acosh(-mq) / 3) + f] # return roots return [r1, r2, r3] # deprived because SymPy isn't quite smart in doing this return [[simplify(r[0]), simplify(r[1])] for r in [r1, r2, r3]]
def test_conv12(): x = Symbol("x") y = Symbol("y") assert sinh(x/3) == sinh(sympy.Symbol("x") / 3) assert cosh(x/3) == cosh(sympy.Symbol("x") / 3) assert tanh(x/3) == tanh(sympy.Symbol("x") / 3) assert coth(x/3) == coth(sympy.Symbol("x") / 3) assert asinh(x/3) == asinh(sympy.Symbol("x") / 3) assert acosh(x/3) == acosh(sympy.Symbol("x") / 3) assert atanh(x/3) == atanh(sympy.Symbol("x") / 3) assert acoth(x/3) == acoth(sympy.Symbol("x") / 3) assert sinh(x/3)._sympy_() == sympy.sinh(sympy.Symbol("x") / 3) assert cosh(x/3)._sympy_() == sympy.cosh(sympy.Symbol("x") / 3) assert tanh(x/3)._sympy_() == sympy.tanh(sympy.Symbol("x") / 3) assert coth(x/3)._sympy_() == sympy.coth(sympy.Symbol("x") / 3) assert asinh(x/3)._sympy_() == sympy.asinh(sympy.Symbol("x") / 3) assert acosh(x/3)._sympy_() == sympy.acosh(sympy.Symbol("x") / 3) assert atanh(x/3)._sympy_() == sympy.atanh(sympy.Symbol("x") / 3) assert acoth(x/3)._sympy_() == sympy.acoth(sympy.Symbol("x") / 3)
def test_conv12(): x = Symbol("x") y = Symbol("y") assert sinh(x / 3) == sinh(sympy.Symbol("x") / 3) assert cosh(x / 3) == cosh(sympy.Symbol("x") / 3) assert tanh(x / 3) == tanh(sympy.Symbol("x") / 3) assert coth(x / 3) == coth(sympy.Symbol("x") / 3) assert asinh(x / 3) == asinh(sympy.Symbol("x") / 3) assert acosh(x / 3) == acosh(sympy.Symbol("x") / 3) assert atanh(x / 3) == atanh(sympy.Symbol("x") / 3) assert acoth(x / 3) == acoth(sympy.Symbol("x") / 3) assert sinh(x / 3)._sympy_() == sympy.sinh(sympy.Symbol("x") / 3) assert cosh(x / 3)._sympy_() == sympy.cosh(sympy.Symbol("x") / 3) assert tanh(x / 3)._sympy_() == sympy.tanh(sympy.Symbol("x") / 3) assert coth(x / 3)._sympy_() == sympy.coth(sympy.Symbol("x") / 3) assert asinh(x / 3)._sympy_() == sympy.asinh(sympy.Symbol("x") / 3) assert acosh(x / 3)._sympy_() == sympy.acosh(sympy.Symbol("x") / 3) assert atanh(x / 3)._sympy_() == sympy.atanh(sympy.Symbol("x") / 3) assert acoth(x / 3)._sympy_() == sympy.acoth(sympy.Symbol("x") / 3)
def test_bng_printer(): # Constants assert _bng_print(sympy.pi) == '_pi' assert _bng_print(sympy.E) == '_e' x, y = sympy.symbols('x y') # Binary functions assert _bng_print(sympy.sympify('x & y')) == 'x && y' assert _bng_print(sympy.sympify('x | y')) == 'x || y' # Trig functions assert _bng_print(sympy.sin(x)) == 'sin(x)' assert _bng_print(sympy.cos(x)) == 'cos(x)' assert _bng_print(sympy.tan(x)) == 'tan(x)' assert _bng_print(sympy.asin(x)) == 'asin(x)' assert _bng_print(sympy.acos(x)) == 'acos(x)' assert _bng_print(sympy.atan(x)) == 'atan(x)' assert _bng_print(sympy.sinh(x)) == 'sinh(x)' assert _bng_print(sympy.cosh(x)) == 'cosh(x)' assert _bng_print(sympy.tanh(x)) == 'tanh(x)' assert _bng_print(sympy.asinh(x)) == 'asinh(x)' assert _bng_print(sympy.acosh(x)) == 'acosh(x)' assert _bng_print(sympy.atanh(x)) == 'atanh(x)' # Logs and powers assert _bng_print(sympy.log(x)) == 'ln(x)' assert _bng_print(sympy.exp(x)) == 'exp(x)' assert _bng_print(sympy.sqrt(x)) == 'sqrt(x)' # Rounding assert _bng_print(sympy.Abs(x)) == 'abs(x)' assert _bng_print(sympy.floor(x)) == 'rint(x - 0.5)' assert _bng_print(sympy.ceiling(x)) == '(rint(x + 1) - 1)' # Min/max assert _bng_print(sympy.Min(x, y)) == 'min(x, y)' assert _bng_print(sympy.Max(x, y)) == 'max(x, y)'
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_presentation_mathml_trig(): mml = mpp._print(sin(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'sin' mml = mpp._print(cos(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'cos' mml = mpp._print(tan(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'tan' mml = mpp._print(asin(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'arcsin' mml = mpp._print(acos(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'arccos' mml = mpp._print(atan(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'arctan' mml = mpp._print(sinh(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'sinh' mml = mpp._print(cosh(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'cosh' mml = mpp._print(tanh(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'tanh' mml = mpp._print(asinh(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'arcsinh' mml = mpp._print(atanh(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'arctanh' mml = mpp._print(acosh(x)) assert mml.childNodes[0].childNodes[0].nodeValue == 'arccosh'
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_issue_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_issue_1304(): 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
def test_acosh_rewrite(): x = Symbol('x') assert acosh(x).rewrite(log) == log(x + sqrt(x - 1) * sqrt(x + 1))
def test_issue_5112_5430(): assert homogeneous_order(-log(x) + acosh(x), x) is None assert homogeneous_order(y - log(x), x, y) is None
def test_acosh_noimpl(): 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
def test_acosh_rewrite(): x = Symbol('x') assert acosh(x).rewrite(log) == log(x + sqrt(x - 1)*sqrt(x + 1))
class TestAllGood(object): # These latex strings should parse to the corresponding SymPy expression GOOD_PAIRS = [ ("0", Rational(0)), ("1", Rational(1)), ("-3.14", Rational(-314, 100)), ("5-3", _Add(5, _Mul(-1, 3))), ("(-7.13)(1.5)", _Mul(Rational('-7.13'), Rational('1.5'))), ("\\left(-7.13\\right)\\left(1.5\\right)", _Mul(Rational('-7.13'), Rational('1.5'))), ("x", x), ("2x", 2 * x), ("x^2", x**2), ("x^{3 + 1}", x**_Add(3, 1)), ("x^{\\left\\{3 + 1\\right\\}}", x**_Add(3, 1)), ("-3y + 2x", _Add(_Mul(2, x), Mul(-1, 3, y, evaluate=False))), ("-c", -c), ("a \\cdot b", a * b), ("a / b", a / b), ("a \\div b", a / b), ("a + b", a + b), ("a + b - a", Add(a, b, _Mul(-1, a), evaluate=False)), ("a^2 + b^2 = c^2", Eq(a**2 + b**2, c**2)), ("a^2 + b^2 != 2c^2", Ne(a**2 + b**2, 2 * c**2)), ("a\\mod b", Mod(a, b)), ("\\sin \\theta", sin(theta)), ("\\sin(\\theta)", sin(theta)), ("\\sin\\left(\\theta\\right)", sin(theta)), ("\\sin^{-1} a", asin(a)), ("\\sin a \\cos b", _Mul(sin(a), cos(b))), ("\\sin \\cos \\theta", sin(cos(theta))), ("\\sin(\\cos \\theta)", sin(cos(theta))), ("\\arcsin(a)", asin(a)), ("\\arccos(a)", acos(a)), ("\\arctan(a)", atan(a)), ("\\sinh(a)", sinh(a)), ("\\cosh(a)", cosh(a)), ("\\tanh(a)", tanh(a)), ("\\sinh^{-1}(a)", asinh(a)), ("\\cosh^{-1}(a)", acosh(a)), ("\\tanh^{-1}(a)", atanh(a)), ("\\arcsinh(a)", asinh(a)), ("\\arccosh(a)", acosh(a)), ("\\arctanh(a)", atanh(a)), ("\\arsinh(a)", asinh(a)), ("\\arcosh(a)", acosh(a)), ("\\artanh(a)", atanh(a)), ("\\operatorname{arcsinh}(a)", asinh(a)), ("\\operatorname{arccosh}(a)", acosh(a)), ("\\operatorname{arctanh}(a)", atanh(a)), ("\\operatorname{arsinh}(a)", asinh(a)), ("\\operatorname{arcosh}(a)", acosh(a)), ("\\operatorname{artanh}(a)", atanh(a)), ("\\operatorname{gcd}(a, b)", UnevaluatedExpr(gcd(a, b))), ("\\operatorname{lcm}(a, b)", UnevaluatedExpr(lcm(a, b))), ("\\operatorname{gcd}(a,b)", UnevaluatedExpr(gcd(a, b))), ("\\operatorname{lcm}(a,b)", UnevaluatedExpr(lcm(a, b))), ("\\operatorname{floor}(a)", floor(a)), ("\\operatorname{ceil}(b)", ceiling(b)), ("\\cos^2(x)", cos(x)**2), ("\\cos(x)^2", cos(x)**2), ("\\gcd(a, b)", UnevaluatedExpr(gcd(a, b))), ("\\lcm(a, b)", UnevaluatedExpr(lcm(a, b))), ("\\gcd(a,b)", UnevaluatedExpr(gcd(a, b))), ("\\lcm(a,b)", UnevaluatedExpr(lcm(a, b))), ("\\floor(a)", floor(a)), ("\\ceil(b)", ceiling(b)), ("\\max(a, b)", Max(a, b)), ("\\min(a, b)", Min(a, b)), ("\\frac{a}{b}", a / b), ("\\frac{a + b}{c}", _Mul(a + b, _Pow(c, -1))), ("\\frac{7}{3}", Rational(7, 3)), ("(\\csc x)(\\sec y)", csc(x) * sec(y)), ("\\lim_{x \\to 3} a", Limit(a, x, 3)), ("\\lim_{x \\rightarrow 3} a", Limit(a, x, 3)), ("\\lim_{x \\Rightarrow 3} a", Limit(a, x, 3)), ("\\lim_{x \\longrightarrow 3} a", Limit(a, x, 3)), ("\\lim_{x \\Longrightarrow 3} a", Limit(a, x, 3)), ("\\lim_{x \\to 3^{+}} a", Limit(a, x, 3, dir='+')), ("\\lim_{x \\to 3^{-}} a", Limit(a, x, 3, dir='-')), ("\\infty", oo), ("\\infty\\%", oo), ("\\$\\infty", oo), ("-\\infty", -oo), ("-\\infty\\%", -oo), ("-\\$\\infty", -oo), ("\\lim_{x \\to \\infty} \\frac{1}{x}", Limit(_Mul(1, _Pow(x, -1)), x, oo)), ("\\frac{d}{dx} x", Derivative(x, x)), ("\\frac{d}{dt} x", Derivative(x, t)), # ("f(x)", f(x)), # ("f(x, y)", f(x, y)), # ("f(x, y, z)", f(x, y, z)), # ("\\frac{d f(x)}{dx}", Derivative(f(x), x)), # ("\\frac{d\\theta(x)}{dx}", Derivative(theta(x), x)), ("|x|", _Abs(x)), ("\\left|x\\right|", _Abs(x)), ("||x||", _Abs(_Abs(x))), ("|x||y|", _Abs(x) * _Abs(y)), ("||x||y||", _Abs(_Abs(x) * _Abs(y))), ("\\lfloor x\\rfloor", floor(x)), ("\\lceil y\\rceil", ceiling(y)), ("\\pi^{|xy|}", pi**_Abs(x * y)), ("\\frac{\\pi}{3}", _Mul(pi, _Pow(3, -1))), ("\\sin{\\frac{\\pi}{2}}", sin(_Mul(pi, _Pow(2, -1)), evaluate=False)), ("a+bI", a + I * b), ("e^{I\\pi}", Integer(-1)), ("\\int x dx", Integral(x, x)), ("\\int x d\\theta", Integral(x, theta)), ("\\int (x^2 - y)dx", Integral(x**2 - y, x)), ("\\int x + a dx", Integral(_Add(x, a), x)), ("\\int da", Integral(1, a)), ("\\int_0^7 dx", Integral(1, (x, 0, 7))), ("\\int_a^b x dx", Integral(x, (x, a, b))), ("\\int^b_a x dx", Integral(x, (x, a, b))), ("\\int_{a}^b x dx", Integral(x, (x, a, b))), ("\\int^{b}_a x dx", Integral(x, (x, a, b))), ("\\int_{a}^{b} x dx", Integral(x, (x, a, b))), ("\\int_{ }^{}x dx", Integral(x, x)), ("\\int^{ }_{ }x dx", Integral(x, x)), ("\\int^{b}_{a} x dx", Integral(x, (x, a, b))), # ("\\int_{f(a)}^{f(b)} f(z) dz", Integral(f(z), (z, f(a), f(b)))), ("\\int (x+a)", Integral(_Add(x, a), x)), ("\\int a + b + c dx", Integral(Add(a, b, c, evaluate=False), x)), ("\\int \\frac{dz}{z}", Integral(Pow(z, -1), z)), ("\\int \\frac{3 dz}{z}", Integral(3 * Pow(z, -1), z)), ("\\int \\frac{1}{x} dx", Integral(Pow(x, -1), x)), ("\\int \\frac{1}{a} + \\frac{1}{b} dx", Integral(_Add(_Pow(a, -1), Pow(b, -1)), x)), ("\\int \\frac{3 \\cdot d\\theta}{\\theta}", Integral(3 * _Pow(theta, -1), theta)), ("\\int \\frac{1}{x} + 1 dx", Integral(_Add(_Pow(x, -1), 1), x)), ("x_0", Symbol('x_0', real=True, positive=True)), ("x_{1}", Symbol('x_1', real=True, positive=True)), ("x_a", Symbol('x_a', real=True, positive=True)), ("x_{b}", Symbol('x_b', real=True, positive=True)), ("h_\\theta", Symbol('h_{\\theta}', real=True, positive=True)), ("h_\\theta ", Symbol('h_{\\theta}', real=True, positive=True)), ("h_{\\theta}", Symbol('h_{\\theta}', real=True, positive=True)), # ("h_{\\theta}(x_0, x_1)", Symbol('h_{theta}', real=True)(Symbol('x_{0}', real=True), Symbol('x_{1}', real=True))), ("x!", _factorial(x)), ("100!", _factorial(100)), ("\\theta!", _factorial(theta)), ("(x + 1)!", _factorial(_Add(x, 1))), ("\\left(x + 1\\right)!", _factorial(_Add(x, 1))), ("(x!)!", _factorial(_factorial(x))), ("x!!!", _factorial(_factorial(_factorial(x)))), ("5!7!", _Mul(_factorial(5), _factorial(7))), ("\\sqrt{x}", sqrt(x)), ("\\sqrt{x + b}", sqrt(_Add(x, b))), ("\\sqrt[3]{\\sin x}", root(sin(x), 3)), ("\\sqrt[y]{\\sin x}", root(sin(x), y)), ("\\sqrt[\\theta]{\\sin x}", root(sin(x), theta)), ("x < y", StrictLessThan(x, y)), ("x \\leq y", LessThan(x, y)), ("x > y", StrictGreaterThan(x, y)), ("x \\geq y", GreaterThan(x, y)), ("\\sum_{k = 1}^{3} c", Sum(c, (k, 1, 3))), ("\\sum_{k = 1}^3 c", Sum(c, (k, 1, 3))), ("\\sum^{3}_{k = 1} c", Sum(c, (k, 1, 3))), ("\\sum^3_{k = 1} c", Sum(c, (k, 1, 3))), ("\\sum_{k = 1}^{10} k^2", Sum(k**2, (k, 1, 10))), ("\\sum_{n = 0}^{\\infty} \\frac{1}{n!}", Sum(_Pow(_factorial(n), -1), (n, 0, oo))), ("\\prod_{a = b}^{c} x", Product(x, (a, b, c))), ("\\prod_{a = b}^c x", Product(x, (a, b, c))), ("\\prod^{c}_{a = b} x", Product(x, (a, b, c))), ("\\prod^c_{a = b} x", Product(x, (a, b, c))), ("\\ln x", _log(x, E)), ("\\ln xy", _log(x * y, E)), ("\\log x", _log(x, 10)), ("\\log xy", _log(x * y, 10)), # ("\\log_2 x", _log(x, 2)), ("\\log_{2} x", _log(x, 2)), # ("\\log_a x", _log(x, a)), ("\\log_{a} x", _log(x, a)), ("\\log_{11} x", _log(x, 11)), ("\\log_{a^2} x", _log(x, _Pow(a, 2))), ("[x]", x), ("[a + b]", _Add(a, b)), ("\\frac{d}{dx} [ \\tan x ]", Derivative(tan(x), x)), ("2\\overline{x}", 2 * Symbol('xbar', real=True, positive=True)), ("2\\overline{x}_n", 2 * Symbol('xbar_n', real=True, positive=True)), ("\\frac{x}{\\overline{x}_n}", x / Symbol('xbar_n', real=True, positive=True)), ("\\frac{\\sin(x)}{\\overline{x}_n}", sin(x) / Symbol('xbar_n', real=True, positive=True)), ("2\\bar{x}", 2 * Symbol('xbar', real=True, positive=True)), ("2\\bar{x}_n", 2 * Symbol('xbar_n', real=True, positive=True)), ("\\sin\\left(\\theta\\right) \\cdot4", sin(theta) * 4), ("\\ln\\left(\\theta\\right)", _log(theta, E)), ("\\ln\\left(x-\\theta\\right)", _log(x - theta, E)), ("\\ln\\left(\\left(x-\\theta\\right)\\right)", _log(x - theta, E)), ("\\ln\\left(\\left[x-\\theta\\right]\\right)", _log(x - theta, E)), ("\\ln\\left(\\left\\{x-\\theta\\right\\}\\right)", _log(x - theta, E)), ("\\ln\\left(\\left|x-\\theta\\right|\\right)", _log(_Abs(x - theta), E)), ("\\frac{1}{2}xy(x+y)", Mul(Rational(1, 2), x, y, (x + y), evaluate=False)), ("\\frac{1}{2}\\theta(x+y)", Mul(Rational(1, 2), theta, (x + y), evaluate=False)), ("1-f(x)", 1 - f * x), ("\\begin{matrix}1&2\\\\3&4\\end{matrix}", Matrix([[1, 2], [3, 4]])), ("\\begin{matrix}x&x^2\\\\\\sqrt{x}&x\\end{matrix}", Matrix([[x, x**2], [_Pow(x, S.Half), x]])), ("\\begin{matrix}\\sqrt{x}\\\\\\sin(\\theta)\\end{matrix}", Matrix([_Pow(x, S.Half), sin(theta)])), ("\\begin{pmatrix}1&2\\\\3&4\\end{pmatrix}", Matrix([[1, 2], [3, 4]])), ("\\begin{bmatrix}1&2\\\\3&4\\end{bmatrix}", Matrix([[1, 2], [3, 4]])), # scientific notation ("2.5\\times 10^2", Rational(250)), ("1,500\\times 10^{-1}", Rational(150)), # e notation ("2.5E2", Rational(250)), ("1,500E-1", Rational(150)), # multiplication without cmd ("2x2y", Mul(2, x, 2, y, evaluate=False)), ("2x2", Mul(2, x, 2, evaluate=False)), ("x2", x * 2), # lin alg processing ("\\theta\\begin{matrix}1&2\\\\3&4\\end{matrix}", MatMul(theta, Matrix([[1, 2], [3, 4]]), evaluate=False)), ("\\theta\\begin{matrix}1\\\\3\\end{matrix} - \\begin{matrix}-1\\\\2\\end{matrix}", MatAdd(MatMul(theta, Matrix([[1], [3]]), evaluate=False), MatMul(-1, Matrix([[-1], [2]]), evaluate=False), evaluate=False)), ("\\theta\\begin{matrix}1&0\\\\0&1\\end{matrix}*\\begin{matrix}3\\\\-2\\end{matrix}", MatMul(theta, Matrix([[1, 0], [0, 1]]), Matrix([3, -2]), evaluate=False)), ("\\frac{1}{9}\\theta\\begin{matrix}1&2\\\\3&4\\end{matrix}", MatMul(Rational(1, 9), theta, Matrix([[1, 2], [3, 4]]), evaluate=False)), ("\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix},\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix}", [Matrix([1, 2, 3]), Matrix([4, 3, 1])]), ("\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix};\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix}", [Matrix([1, 2, 3]), Matrix([4, 3, 1])]), ("\\left\\{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix},\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix}\\right\\}", [Matrix([1, 2, 3]), Matrix([4, 3, 1])]), ("\\left\\{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix},\\begin{pmatrix}4\\\\3\\\\1\\end{pmatrix},\\begin{pmatrix}1\\\\1\\\\1\\end{pmatrix}\\right\\}", [Matrix([1, 2, 3]), Matrix([4, 3, 1]), Matrix([1, 1, 1])]), ("\\left\\{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix}\\right\\}", Matrix([1, 2, 3])), ("\\left{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix}\\right}", Matrix([1, 2, 3])), ("{\\begin{pmatrix}1\\\\2\\\\3\\end{pmatrix}}", Matrix([1, 2, 3])), # us dollars ("\\$1,000.00", Rational(1000)), ("\\$543.21", Rational(54321, 100)), ("\\$0.009", Rational(9, 1000)), # percentages ("100\\%", Rational(1)), ("1.5\\%", Rational(15, 1000)), ("0.05\\%", Rational(5, 10000)), # empty set ("\\emptyset", S.EmptySet), # divide by zero ("\\frac{1}{0}", _Pow(0, -1)), ("1+\\frac{5}{0}", _Add(1, _Mul(5, _Pow(0, -1)))), # adjacent single char sub sup ("4^26^2", _Mul(_Pow(4, 2), _Pow(6, 2))), ("x_22^2", _Mul(Symbol('x_2', real=True, positive=True), _Pow(2, 2))) ] def test_good_pair(self, s, eq): assert_equal(s, eq)
def test_manualintegrate_inversetrig(): # atan assert manualintegrate(exp(x) / (1 + exp(2 * x)), x) == atan(exp(x)) assert manualintegrate(1 / (4 + 9 * x**2), x) == atan(3 * x / 2) / 6 assert manualintegrate(1 / (16 + 16 * x**2), x) == atan(x) / 16 assert manualintegrate(1 / (4 + x**2), x) == atan(x / 2) / 2 assert manualintegrate(1 / (1 + 4 * x**2), x) == atan(2 * x) / 2 ra = Symbol('a', real=True) rb = Symbol('b', real=True) assert manualintegrate(1/(ra + rb*x**2), x) == \ Piecewise((atan(x/sqrt(ra/rb))/(rb*sqrt(ra/rb)), ra/rb > 0), (-acoth(x/sqrt(-ra/rb))/(rb*sqrt(-ra/rb)), And(ra/rb < 0, x**2 > -ra/rb)), (-atanh(x/sqrt(-ra/rb))/(rb*sqrt(-ra/rb)), And(ra/rb < 0, x**2 < -ra/rb))) assert manualintegrate(1/(4 + rb*x**2), x) == \ Piecewise((atan(x/(2*sqrt(1/rb)))/(2*rb*sqrt(1/rb)), 4/rb > 0), (-acoth(x/(2*sqrt(-1/rb)))/(2*rb*sqrt(-1/rb)), And(4/rb < 0, x**2 > -4/rb)), (-atanh(x/(2*sqrt(-1/rb)))/(2*rb*sqrt(-1/rb)), And(4/rb < 0, x**2 < -4/rb))) assert manualintegrate(1/(ra + 4*x**2), x) == \ Piecewise((atan(2*x/sqrt(ra))/(2*sqrt(ra)), ra/4 > 0), (-acoth(2*x/sqrt(-ra))/(2*sqrt(-ra)), And(ra/4 < 0, x**2 > -ra/4)), (-atanh(2*x/sqrt(-ra))/(2*sqrt(-ra)), And(ra/4 < 0, x**2 < -ra/4))) assert manualintegrate(1 / (4 + 4 * x**2), x) == atan(x) / 4 assert manualintegrate(1 / (a + b * x**2), x) == atan(x / sqrt(a / b)) / (b * sqrt(a / b)) # asin assert manualintegrate(1 / sqrt(1 - x**2), x) == asin(x) assert manualintegrate(1 / sqrt(4 - 4 * x**2), x) == asin(x) / 2 assert manualintegrate(3 / sqrt(1 - 9 * x**2), x) == asin(3 * x) assert manualintegrate(1 / sqrt(4 - 9 * x**2), x) == asin(x * Rational(3, 2)) / 3 # asinh assert manualintegrate(1/sqrt(x**2 + 1), x) == \ asinh(x) assert manualintegrate(1/sqrt(x**2 + 4), x) == \ asinh(x/2) assert manualintegrate(1/sqrt(4*x**2 + 4), x) == \ asinh(x)/2 assert manualintegrate(1/sqrt(4*x**2 + 1), x) == \ asinh(2*x)/2 assert manualintegrate(1/sqrt(a*x**2 + 1), x) == \ Piecewise((sqrt(-1/a)*asin(x*sqrt(-a)), a < 0), (sqrt(1/a)*asinh(sqrt(a)*x), a > 0)) assert manualintegrate(1/sqrt(a + x**2), x) == \ Piecewise((asinh(x*sqrt(1/a)), a > 0), (acosh(x*sqrt(-1/a)), a < 0)) # acosh assert manualintegrate(1/sqrt(x**2 - 1), x) == \ acosh(x) assert manualintegrate(1/sqrt(x**2 - 4), x) == \ acosh(x/2) assert manualintegrate(1/sqrt(4*x**2 - 4), x) == \ acosh(x)/2 assert manualintegrate(1/sqrt(9*x**2 - 1), x) == \ acosh(3*x)/3 assert manualintegrate(1/sqrt(a*x**2 - 4), x) == \ Piecewise((sqrt(1/a)*acosh(sqrt(a)*x/2), a > 0)) assert manualintegrate(1/sqrt(-a + 4*x**2), x) == \ Piecewise((asinh(2*x*sqrt(-1/a))/2, -a > 0), (acosh(2*x*sqrt(1/a))/2, -a < 0)) # piecewise assert manualintegrate(1/sqrt(a-b*x**2), x) == \ Piecewise((sqrt(a/b)*asin(x*sqrt(b/a))/sqrt(a), And(-b < 0, a > 0)), (sqrt(-a/b)*asinh(x*sqrt(-b/a))/sqrt(a), And(-b > 0, a > 0)), (sqrt(a/b)*acosh(x*sqrt(b/a))/sqrt(-a), And(-b > 0, a < 0))) assert manualintegrate(1/sqrt(a + b*x**2), x) == \ Piecewise((sqrt(-a/b)*asin(x*sqrt(-b/a))/sqrt(a), And(a > 0, b < 0)), (sqrt(a/b)*asinh(x*sqrt(b/a))/sqrt(a), And(a > 0, b > 0)), (sqrt(-a/b)*acosh(x*sqrt(-b/a))/sqrt(-a), And(a < 0, b > 0)))
def test_manualintegrate_inversetrig(): # atan assert manualintegrate(exp(x) / (1 + exp(2 * x)), x) == atan(exp(x)) assert manualintegrate(1 / (4 + 9 * x**2), x) == atan(3 * x / 2) / 6 assert manualintegrate(1 / (16 + 16 * x**2), x) == atan(x) / 16 assert manualintegrate(1 / (4 + x**2), x) == atan(x / 2) / 2 assert manualintegrate(1 / (1 + 4 * x**2), x) == atan(2 * x) / 2 assert manualintegrate(1/(a + b*x**2), x) == \ Piecewise((atan(x/sqrt(a/b))/(b*sqrt(a/b)), a/b > 0), \ (-acoth(x/sqrt(-a/b))/(b*sqrt(-a/b)), And(a/b < 0, x**2 > -a/b)), \ (-atanh(x/sqrt(-a/b))/(b*sqrt(-a/b)), And(a/b < 0, x**2 < -a/b))) assert manualintegrate(1/(4 + b*x**2), x) == \ Piecewise((atan(x/(2*sqrt(1/b)))/(2*b*sqrt(1/b)), 4/b > 0), \ (-acoth(x/(2*sqrt(-1/b)))/(2*b*sqrt(-1/b)), And(4/b < 0, x**2 > -4/b)), \ (-atanh(x/(2*sqrt(-1/b)))/(2*b*sqrt(-1/b)), And(4/b < 0, x**2 < -4/b))) assert manualintegrate(1/(a + 4*x**2), x) == \ Piecewise((atan(2*x/sqrt(a))/(2*sqrt(a)), a/4 > 0), \ (-acoth(2*x/sqrt(-a))/(2*sqrt(-a)), And(a/4 < 0, x**2 > -a/4)), \ (-atanh(2*x/sqrt(-a))/(2*sqrt(-a)), And(a/4 < 0, x**2 < -a/4))) assert manualintegrate(1 / (4 + 4 * x**2), x) == atan(x) / 4 # asin assert manualintegrate(1 / sqrt(1 - x**2), x) == asin(x) assert manualintegrate(1 / sqrt(4 - 4 * x**2), x) == asin(x) / 2 assert manualintegrate(3 / sqrt(1 - 9 * x**2), x) == asin(3 * x) assert manualintegrate(1 / sqrt(4 - 9 * x**2), x) == asin(3 * x / 2) / 3 # asinh assert manualintegrate(1/sqrt(x**2 + 1), x) == \ asinh(x) assert manualintegrate(1/sqrt(x**2 + 4), x) == \ asinh(x/2) assert manualintegrate(1/sqrt(4*x**2 + 4), x) == \ asinh(x)/2 assert manualintegrate(1/sqrt(4*x**2 + 1), x) == \ asinh(2*x)/2 assert manualintegrate(1/sqrt(a*x**2 + 1), x) == \ Piecewise((sqrt(-1/a)*asin(x*sqrt(-a)), a < 0), (sqrt(1/a)*asinh(sqrt(a)*x), a > 0)) assert manualintegrate(1/sqrt(a + x**2), x) == \ Piecewise((asinh(x*sqrt(1/a)), a > 0), (acosh(x*sqrt(-1/a)), a < 0)) # acosh assert manualintegrate(1/sqrt(x**2 - 1), x) == \ acosh(x) assert manualintegrate(1/sqrt(x**2 - 4), x) == \ acosh(x/2) assert manualintegrate(1/sqrt(4*x**2 - 4), x) == \ acosh(x)/2 assert manualintegrate(1/sqrt(9*x**2 - 1), x) == \ acosh(3*x)/3 assert manualintegrate(1/sqrt(a*x**2 - 4), x) == \ Piecewise((sqrt(1/a)*acosh(sqrt(a)*x/2), a > 0)) assert manualintegrate(1/sqrt(-a + 4*x**2), x) == \ Piecewise((asinh(2*x*sqrt(-1/a))/2, -a > 0), (acosh(2*x*sqrt(1/a))/2, -a < 0)) # piecewise assert manualintegrate(1/sqrt(a-b*x**2), x) == \ Piecewise((sqrt(a/b)*asin(x*sqrt(b/a))/sqrt(a), And(-b < 0, a > 0)), (sqrt(-a/b)*asinh(x*sqrt(-b/a))/sqrt(a), And(-b > 0, a > 0)), (sqrt(a/b)*acosh(x*sqrt(b/a))/sqrt(-a), And(-b > 0, a < 0))) assert manualintegrate(1/sqrt(a + b*x**2), x) == \ Piecewise((sqrt(-a/b)*asin(x*sqrt(-b/a))/sqrt(a), And(a > 0, b < 0)), (sqrt(a/b)*asinh(x*sqrt(b/a))/sqrt(a), And(a > 0, b > 0)), (sqrt(-a/b)*acosh(x*sqrt(-b/a))/sqrt(-a), And(a < 0, b > 0)))
import sympy from enumerate_over_gcf import multi_core_enumeration_wrapper, g_N_verify_terms from enumerate_over_signed_rcf import esma_search_wrapper import series_generators import lhs_generators import constants # declares constants as sympy Singeltons, "not" used is intended g_const_dict = { 'zeta': sympy.zeta, 'e': sympy.E, 'pi': sympy.pi, 'catalan': sympy.Catalan, 'golden_ratio': sympy.GoldenRatio, 'khinchin': sympy.S.Khinchin, 'euler-mascheroni': sympy.EulerGamma, 'pi-acosh_2': sympy.pi * sympy.acosh(2) } def get_custom_an_generator(args): """ custom {an} generators. create a new one and add it here and include in 'init_custom_an_generator_parser'. :param args: program args :return: generator function , number of free coefficients """ if args.zeta3_an: return series_generators.CartesianProductZeta3An(), 2 elif args.zeta5_an: return series_generators.CartesianProductZeta5An(), 3 elif args.polynomial_shift1_an: return series_generators.CartesianProductAnShift1(), None
def test_acosh(): # TODO please write more tests -- see issue 3751 # From http://functions.wolfram.com/ElementaryFunctions/ArcCosh/03/01/ # at specific points 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
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_infinities(): assert acosh(oo) == oo assert acosh(-oo) == oo + I*pi assert acosh(I*oo) == oo + I*pi/2 assert acosh(-I*oo) == oo - I*pi/2
def test_acosh(): # TODO please write more tests -- see #652 assert acosh(1) == 0 assert acosh(Rational(1, 2)) == I * pi / 3
def test_acosh(): x = Symbol('x') assert acosh(-x) == acosh(-x) #at specific points 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 # at infinites 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).n(6)) == '2.31244 + 1.5708*I' assert str(acosh(-5*I).n(6)) == '2.31244 - 1.5708*I'
'cube': lambda x: x**3, 'plus': lambda x, y: x + y, 'sub': lambda x, y: x - y, 'neg': lambda x: -x, 'pow': lambda x, y: sympy.sign(x) * abs(x)**y, 'cos': lambda x: sympy.cos(x), 'sin': lambda x: sympy.sin(x), 'tan': lambda x: sympy.tan(x), 'cosh': lambda x: sympy.cosh(x), 'sinh': lambda x: sympy.sinh(x), 'tanh': lambda x: sympy.tanh(x), 'exp': lambda x: sympy.exp(x), 'acos': lambda x: sympy.acos(x), 'asin': lambda x: sympy.asin(x), 'atan': lambda x: sympy.atan(x), 'acosh': lambda x: sympy.acosh(x), 'asinh': lambda x: sympy.asinh(x), 'atanh': lambda x: sympy.atanh(x), 'abs': lambda x: abs(x), 'mod': lambda x, y: sympy.Mod(x, y), 'erf': lambda x: sympy.erf(x), 'erfc': lambda x: sympy.erfc(x), 'logm': lambda x: sympy.log(abs(x)), 'logm10': lambda x: sympy.log10(abs(x)), 'logm2': lambda x: sympy.log2(abs(x)), 'log1p': lambda x: sympy.log(x + 1), 'floor': lambda x: sympy.floor(x), 'ceil': lambda x: sympy.ceil(x), 'sign': lambda x: sympy.sign(x), 'round': lambda x: sympy.round(x), }
def test_acosh(): # TODO please write more tests -- see issue 3751 # From http://functions.wolfram.com/ElementaryFunctions/ArcCosh/03/01/ # at specific points 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
def test_acosh_noimpl(): 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
def test_acosh_fdiff(): x = Symbol('x') raises(ArgumentIndexError, lambda: acosh(x).fdiff(2))
def test_acosh(): x = Symbol('x') assert unchanged(acosh, -x) #at specific points 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(nan) == nan # at infinites assert acosh(oo) == oo assert acosh(-oo) == oo assert acosh(I * oo) == oo + I * pi / 2 assert acosh(-I * oo) == oo - I * pi / 2 assert acosh(zoo) == zoo 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_asech(): x = Symbol('x') assert unchanged(asech, -x) # values at fixed points assert asech(1) == 0 assert asech(-1) == pi * I assert asech(0) == oo assert asech(2) == I * pi / 3 assert asech(-2) == 2 * I * pi / 3 assert asech(nan) == nan # at infinites assert asech(oo) == I * pi / 2 assert asech(-oo) == I * pi / 2 assert asech(zoo) == I * AccumBounds(-pi / 2, pi / 2) assert asech(I) == log(1 + sqrt(2)) - I * pi / 2 assert asech(-I) == log(1 + sqrt(2)) + I * pi / 2 assert asech(sqrt(2) - sqrt(6)) == 11 * I * pi / 12 assert asech(sqrt(2 - 2 / sqrt(5))) == I * pi / 10 assert asech(-sqrt(2 - 2 / sqrt(5))) == 9 * I * pi / 10 assert asech(2 / sqrt(2 + sqrt(2))) == I * pi / 8 assert asech(-2 / sqrt(2 + sqrt(2))) == 7 * I * pi / 8 assert asech(sqrt(5) - 1) == I * pi / 5 assert asech(1 - sqrt(5)) == 4 * I * pi / 5 assert asech(-sqrt(2 * (2 + sqrt(2)))) == 5 * I * pi / 8 # properties # asech(x) == acosh(1/x) assert asech(sqrt(2)) == acosh(1 / sqrt(2)) assert asech(2 / sqrt(3)) == acosh(sqrt(3) / 2) assert asech(2 / sqrt(2 + sqrt(2))) == acosh(sqrt(2 + sqrt(2)) / 2) assert asech(S(2)) == acosh(1 / S(2)) # asech(x) == I*acos(1/x) # (Note: the exact formula is asech(x) == +/- I*acos(1/x)) assert asech(-sqrt(2)) == I * acos(-1 / sqrt(2)) assert asech(-2 / sqrt(3)) == I * acos(-sqrt(3) / 2) assert asech(-S(2)) == I * acos(-S.Half) assert asech(-2 / sqrt(2)) == I * acos(-sqrt(2) / 2) # sech(asech(x)) / x == 1 assert expand_mul(sech(asech(sqrt(6) - sqrt(2))) / (sqrt(6) - sqrt(2))) == 1 assert expand_mul(sech(asech(sqrt(6) + sqrt(2))) / (sqrt(6) + sqrt(2))) == 1 assert (sech(asech(sqrt(2 + 2 / sqrt(5)))) / (sqrt(2 + 2 / sqrt(5)))).simplify() == 1 assert (sech(asech(-sqrt(2 + 2 / sqrt(5)))) / (-sqrt(2 + 2 / sqrt(5)))).simplify() == 1 assert (sech(asech(sqrt(2 * (2 + sqrt(2))))) / (sqrt(2 * (2 + sqrt(2))))).simplify() == 1 assert expand_mul(sech(asech((1 + sqrt(5)))) / ((1 + sqrt(5)))) == 1 assert expand_mul(sech(asech((-1 - sqrt(5)))) / ((-1 - sqrt(5)))) == 1 assert expand_mul( sech(asech((-sqrt(6) - sqrt(2)))) / ((-sqrt(6) - sqrt(2)))) == 1 # numerical evaluation assert str(asech(5 * I).n(6)) == '0.19869 - 1.5708*I' assert str(asech(-5 * I).n(6)) == '0.19869 + 1.5708*I'