def test_heurisch_hyperbolic(): assert heurisch(sinh(x), x) == cosh(x) assert heurisch(cosh(x), x) == sinh(x) assert heurisch(x*sinh(x), x) == x*cosh(x) - sinh(x) assert heurisch(x*cosh(x), x) == x*sinh(x) - cosh(x) assert heurisch( x*asinh(x/2), x) == x**2*asinh(x/2)/2 + asinh(x/2) - x*sqrt(4 + x**2)/4
def test_heurisch_hacking(): assert (heurisch(sqrt(1 + 7*x**2), x, hints=[]) == x*sqrt(1 + 7*x**2)/2 + sqrt(7)*asinh(sqrt(7)*x)/14) assert (heurisch(sqrt(1 - 7*x**2), x, hints=[]) == x*sqrt(1 - 7*x**2)/2 + sqrt(7)*asin(sqrt(7)*x)/14) assert (heurisch(1/sqrt(1 + 7*x**2), x, hints=[]) == sqrt(7)*asinh(sqrt(7)*x)/7) assert (heurisch(1/sqrt(1 - 7*x**2), x, hints=[]) == sqrt(7)*asin(sqrt(7)*x)/7) assert (heurisch(exp(-7*x**2), x, hints=[]) == sqrt(7*pi)*erf(sqrt(7)*x)/14) assert heurisch(1/sqrt(9 - 4*x**2), x, hints=[]) == asin(2*x/3)/2 assert heurisch(1/sqrt(9 + 4*x**2), x, hints=[]) == asinh(2*x/3)/2 assert heurisch(li(x), x, hints=[]) == x*li(x) - Ei(2*log(x))
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).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_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_asin(): assert asin(nan) == nan assert asin.nargs == FiniteSet(1) assert asin(oo) == -I*oo assert asin(-oo) == I*oo # Note: asin(-x) = - asin(x) assert asin(0) == 0 assert asin(1) == pi/2 assert asin(-1) == -pi/2 assert asin(sqrt(3)/2) == pi/3 assert asin(-sqrt(3)/2) == -pi/3 assert asin(sqrt(2)/2) == pi/4 assert asin(-sqrt(2)/2) == -pi/4 assert asin(sqrt((5 - sqrt(5))/8)) == pi/5 assert asin(-sqrt((5 - sqrt(5))/8)) == -pi/5 assert asin(Rational(1, 2)) == pi/6 assert asin(-Rational(1, 2)) == -pi/6 assert asin((sqrt(2 - sqrt(2)))/2) == pi/8 assert asin(-(sqrt(2 - sqrt(2)))/2) == -pi/8 assert asin((sqrt(5) - 1)/4) == pi/10 assert asin(-(sqrt(5) - 1)/4) == -pi/10 assert asin((sqrt(3) - 1)/sqrt(2**3)) == pi/12 assert asin(-(sqrt(3) - 1)/sqrt(2**3)) == -pi/12 assert asin(x).diff(x) == 1/sqrt(1 - x**2) assert asin(c).is_complex assert asin(x).is_complex is None assert asin(0.2).is_extended_real is True assert asin(-2).is_extended_real is False assert asin(r).is_extended_real is None assert asin(0, evaluate=False).is_rational assert asin(1, evaluate=False).is_rational is False z = Symbol('z', zero=True) rn = Symbol('rn', rational=True, nonzero=True) assert asin(z).is_rational assert asin(rn).is_rational is False assert asin(x).is_rational is None assert asin(-2*I) == -I*asinh(2) assert asin(Rational(1, 7), evaluate=False).is_positive is True assert asin(Rational(-1, 7), evaluate=False).is_positive is False assert asin(p).is_positive is None pytest.raises(ArgumentIndexError, lambda: asin(x).fdiff(2))
def test_numexprprinter(): p = NumExprPrinter() M = MatrixSymbol('M', 1, 2) pytest.raises(TypeError, lambda: p.doprint(M)) pytest.raises(TypeError, lambda: p.doprint([x, y])) assert p.doprint(I) == "evaluate('1j')" assert p.doprint(sin(x)) == "evaluate('sin(x)')" assert p.doprint(asinh(x)) == "evaluate('arcsinh(x)')" f = implemented_function('f', lambda x: 2 * x) assert p.doprint(f(x)) == "evaluate('(2*x)')" g = Function('g') pytest.raises(TypeError, lambda: p.doprint(g(x)))
def test_numexprprinter(): p = NumExprPrinter() M = MatrixSymbol('M', 1, 2) pytest.raises(TypeError, lambda: p.doprint(M)) pytest.raises(TypeError, lambda: p.doprint([x, y])) assert p.doprint(I) == "evaluate('1j')" assert p.doprint(sin(x)) == "evaluate('sin(x)')" assert p.doprint(asinh(x)) == "evaluate('arcsinh(x)')" f = implemented_function('f', lambda x: 2*x) assert p.doprint(f(x)) == "evaluate('(2*x)')" g = Function('g') pytest.raises(TypeError, lambda: p.doprint(g(x)))
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_RR(): # Make sure the algorithm does the right thing if the ring is RR. See # issue sympy/sympy#8685. assert heurisch(sqrt(1 + 0.25*x**2), x, hints=[]) == \ 0.5*x*sqrt(0.25*x**2 + 1) + 1.0*asinh(0.5*x)
def test_sympyissue_4422(): assert integrate(1/sqrt(16 + 4*x**2), x) == asinh(x/2) / 2
def test_sympyissue_4422(): assert integrate(1 / sqrt(16 + 4 * x**2), x) == asinh(x / 2) / 2
def test_asinh(): x, y = symbols('x,y') assert asinh(x) == asinh(x) assert asinh(-x) == -asinh(x) assert asinh(nan) == nan assert asinh(0) == 0 assert asinh(+1) == log(sqrt(2) + 1) assert asinh(-1) == log(sqrt(2) - 1) assert asinh(I) == pi * I / 2 assert asinh(-I) == -pi * I / 2 assert asinh(I / 2) == pi * I / 6 assert asinh(-I / 2) == -pi * I / 6 assert asinh(oo) == oo assert asinh(-oo) == -oo assert asinh(I * oo) == oo assert asinh(-I * oo) == -oo assert asinh(zoo) == zoo assert asinh(I * (sqrt(3) - 1) / 2**Rational(3, 2)) == pi * I / 12 assert asinh(-I * (sqrt(3) - 1) / 2**Rational(3, 2)) == -pi * I / 12 assert asinh(I * (sqrt(5) - 1) / 4) == pi * I / 10 assert asinh(-I * (sqrt(5) - 1) / 4) == -pi * I / 10 assert asinh(I * (sqrt(5) + 1) / 4) == 3 * pi * I / 10 assert asinh(-I * (sqrt(5) + 1) / 4) == -3 * pi * I / 10
def test_sympyissue_4136(): assert cosh(asinh(Rational(3, 2))) == sqrt(Rational(13, 4))
def test_asinh_series(): assert asinh(x).series(x, 0, 8) == \ x - x**3/6 + 3*x**5/40 - 5*x**7/112 + O(x**8) t5 = asinh(x).taylor_term(5, x) assert t5 == 3 * x**5 / 40 assert asinh(x).taylor_term(7, x, t5, 0) == -5 * x**7 / 112
def test_asinh_rewrite(): assert asinh(x).rewrite(log) == log(x + sqrt(x**2 + 1))
def test_asinh(): assert asinh(+x) == +asinh(x) assert asinh(-x) == -asinh(x) assert asinh(-2) == -asinh(2) assert asinh(nan) == nan assert asinh(0) == 0 assert asinh(+1) == log(sqrt(2) + 1) assert asinh(-1) == log(sqrt(2) - 1) assert asinh(+I) == +pi * I / 2 assert asinh(-I) == -pi * I / 2 assert asinh(+I / 2) == +pi * I / 6 assert asinh(-I / 2) == -pi * I / 6 assert asinh(+oo) == +oo assert asinh(-oo) == -oo assert asinh(+I * oo) == +oo assert asinh(-I * oo) == -oo assert asinh(zoo) == zoo assert asinh(+I * (sqrt(3) - 1) / 2**Rational(3, 2)) == +pi * I / 12 assert asinh(-I * (sqrt(3) - 1) / 2**Rational(3, 2)) == -pi * I / 12 assert asinh(+I * (sqrt(5) - 1) / 4) == +pi * I / 10 assert asinh(-I * (sqrt(5) - 1) / 4) == -pi * I / 10 assert asinh(+I * (sqrt(5) + 1) / 4) == +3 * pi * I / 10 assert asinh(-I * (sqrt(5) + 1) / 4) == -3 * pi * I / 10 pytest.raises(ArgumentIndexError, lambda: asinh(x).fdiff(2))
def test_asinh(): assert asinh(x) == asinh(x) assert asinh(-x) == -asinh(x) assert asinh(-2) == -asinh(2) assert asinh(nan) == nan assert asinh( 0) == 0 assert asinh(+1) == log(sqrt(2) + 1) assert asinh(-1) == log(sqrt(2) - 1) assert asinh(I) == pi*I/2 assert asinh(-I) == -pi*I/2 assert asinh(I/2) == pi*I/6 assert asinh(-I/2) == -pi*I/6 assert asinh(oo) == oo assert asinh(-oo) == -oo assert asinh(I*oo) == oo assert asinh(-I*oo) == -oo assert asinh(zoo) == zoo assert asinh(I*(sqrt(3) - 1)/2**Rational(3, 2)) == pi*I/12 assert asinh(-I*(sqrt(3) - 1)/2**Rational(3, 2)) == -pi*I/12 assert asinh(I*(sqrt(5) - 1)/4) == pi*I/10 assert asinh(-I*(sqrt(5) - 1)/4) == -pi*I/10 assert asinh(I*(sqrt(5) + 1)/4) == 3*pi*I/10 assert asinh(-I*(sqrt(5) + 1)/4) == -3*pi*I/10 pytest.raises(ArgumentIndexError, lambda: asinh(x).fdiff(2))
def test_asinh_series(): assert asinh(x).series(x, 0, 8) == \ x - x**3/6 + 3*x**5/40 - 5*x**7/112 + O(x**8) t5 = asinh(x).taylor_term(5, x) assert t5 == 3*x**5/40 assert asinh(x).taylor_term(7, x, t5, 0) == -5*x**7/112
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]'