Esempio n. 1
0
def test_hyper_as_trig():
    from diofant.simplify.fu import _osborne as o, _osbornei as i, TR12

    eq = sinh(x)**2 + cosh(x)**2
    t, f = hyper_as_trig(eq)
    assert f(fu(t)) == cosh(2*x)
    e, f = hyper_as_trig(tanh(x + y))
    assert f(TR12(e)) == (tanh(x) + tanh(y))/(tanh(x)*tanh(y) + 1)

    d = Dummy()
    assert o(sinh(x), d) == I*sin(x*d)
    assert o(tanh(x), d) == I*tan(x*d)
    assert o(coth(x), d) == cot(x*d)/I
    assert o(cosh(x), d) == cos(x*d)
    for func in (sinh, cosh, tanh, coth):
        h = func(pi)
        assert i(o(h, d), d) == h
    # /!\ the _osborne functions are not meant to work
    # in the o(i(trig, d), d) direction so we just check
    # that they work as they are supposed to work
    assert i(cos(x*y), y) == cosh(x)
    assert i(sin(x*y), y) == sinh(x)/I
    assert i(tan(x*y), y) == tanh(x)/I
    assert i(cot(x*y), y) == coth(x)*I
    assert i(sec(x*y), y) == 1/cosh(x)
    assert i(csc(x*y), y) == I/sinh(x)
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
def test_tan_rewrite():
    neg_exp, pos_exp = exp(-x*I), exp(x*I)
    assert tan(x).rewrite(exp) == I*(neg_exp - pos_exp)/(neg_exp + pos_exp)
    assert tan(x).rewrite(sin) == 2*sin(x)**2/sin(2*x)
    assert tan(x).rewrite(cos) == -cos(x + pi/2)/cos(x)
    assert tan(x).rewrite(cot) == 1/cot(x)
    assert (tan(sinh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            tan(x).rewrite(exp).subs({x: sinh(3)}).evalf())
    assert (tan(cosh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            tan(x).rewrite(exp).subs({x: cosh(3)}).evalf())
    assert (tan(tanh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            tan(x).rewrite(exp).subs({x: tanh(3)}).evalf())
    assert (tan(coth(x)).rewrite(exp).subs({x: 3}).evalf() ==
            tan(x).rewrite(exp).subs({x: coth(3)}).evalf())
    assert (tan(sin(x)).rewrite(exp).subs({x: 3}).evalf() ==
            tan(x).rewrite(exp).subs({x: sin(3)}).evalf())
    assert (tan(cos(x)).rewrite(exp).subs({x: 3}).evalf() ==
            tan(x).rewrite(exp).subs({x: cos(3)}).evalf())
    assert (tan(tan(x)).rewrite(exp).subs({x: 3}).evalf() ==
            tan(x).rewrite(exp).subs({x: tan(3)}).evalf())
    assert (tan(cot(x)).rewrite(exp).subs({x: 3}).evalf() ==
            tan(x).rewrite(exp).subs({x: cot(3)}).evalf())
    assert tan(log(x)).rewrite(Pow) == I*(x**-I - x**I)/(x**-I + x**I)
    assert tan(x).rewrite(Pow) == tan(x)
    assert 0 == (cos(pi/34)*tan(pi/34) - sin(pi/34)).rewrite(sqrt)
    assert 0 == (cos(pi/17)*tan(pi/17) - sin(pi/17)).rewrite(sqrt)
    assert tan(pi/19).rewrite(sqrt) == tan(pi/19)
    assert tan(8*pi/19).rewrite(sqrt) == tan(8*pi/19)
Esempio n. 5
0
def test_coth_rewrite():
    x = Symbol('x')
    assert coth(x).rewrite(exp) == (exp(x) + exp(-x))/(exp(x) - exp(-x)) \
        == coth(x).rewrite('tractable')
    assert coth(x).rewrite(sinh) == -I * sinh(I * pi / 2 - x) / sinh(x)
    assert coth(x).rewrite(cosh) == -I * cosh(x) / cosh(I * pi / 2 - x)
    assert coth(x).rewrite(tanh) == 1 / tanh(x)
Esempio n. 6
0
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)
Esempio n. 7
0
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)
Esempio n. 8
0
def test_gruntz_hyperbolic():
    assert gruntz(cosh(x), x) == oo
    assert gruntz(cosh(-x), x) == oo
    assert gruntz(sinh(x), x) == oo
    assert gruntz(sinh(-x), x) == -oo
    assert gruntz(2 * cosh(x) * exp(x), x) == oo
    assert gruntz(2 * cosh(-x) * exp(-x), x) == 1
    assert gruntz(2 * sinh(x) * exp(x), x) == oo
    assert gruntz(2 * sinh(-x) * exp(-x), x) == -1
    assert gruntz(tanh(x), x) == 1
    assert gruntz(tanh(-x), x) == -1
    assert gruntz(coth(x), x) == 1
    assert gruntz(coth(-x), x) == -1
Esempio n. 9
0
def test_gruntz_hyperbolic():
    assert gruntz(cosh(x), x) == oo
    assert gruntz(cosh(-x), x) == oo
    assert gruntz(sinh(x), x) == oo
    assert gruntz(sinh(-x), x) == -oo
    assert gruntz(2*cosh(x)*exp(x), x) == oo
    assert gruntz(2*cosh(-x)*exp(-x), x) == 1
    assert gruntz(2*sinh(x)*exp(x), x) == oo
    assert gruntz(2*sinh(-x)*exp(-x), x) == -1
    assert gruntz(tanh(x), x) == 1
    assert gruntz(tanh(-x), x) == -1
    assert gruntz(coth(x), x) == 1
    assert gruntz(coth(-x), x) == -1
Esempio n. 10
0
def test_trigsimp1a():
    assert trigsimp(sin(2)**2*cos(3)*exp(2)/cos(2)**2) == tan(2)**2*cos(3)*exp(2)
    assert trigsimp(tan(2)**2*cos(3)*exp(2)*cos(2)**2) == sin(2)**2*cos(3)*exp(2)
    assert trigsimp(cot(2)*cos(3)*exp(2)*sin(2)) == cos(3)*exp(2)*cos(2)
    assert trigsimp(tan(2)*cos(3)*exp(2)/sin(2)) == cos(3)*exp(2)/cos(2)
    assert trigsimp(cot(2)*cos(3)*exp(2)/cos(2)) == cos(3)*exp(2)/sin(2)
    assert trigsimp(cot(2)*cos(3)*exp(2)*tan(2)) == cos(3)*exp(2)
    assert trigsimp(sinh(2)*cos(3)*exp(2)/cosh(2)) == tanh(2)*cos(3)*exp(2)
    assert trigsimp(tanh(2)*cos(3)*exp(2)*cosh(2)) == sinh(2)*cos(3)*exp(2)
    assert trigsimp(coth(2)*cos(3)*exp(2)*sinh(2)) == cosh(2)*cos(3)*exp(2)
    assert trigsimp(tanh(2)*cos(3)*exp(2)/sinh(2)) == cos(3)*exp(2)/cosh(2)
    assert trigsimp(coth(2)*cos(3)*exp(2)/cosh(2)) == cos(3)*exp(2)/sinh(2)
    assert trigsimp(coth(2)*cos(3)*exp(2)*tanh(2)) == cos(3)*exp(2)
Esempio n. 11
0
def test_trigsimp1a():
    assert trigsimp(sin(2)**2*cos(3)*exp(2)/cos(2)**2) == tan(2)**2*cos(3)*exp(2)
    assert trigsimp(tan(2)**2*cos(3)*exp(2)*cos(2)**2) == sin(2)**2*cos(3)*exp(2)
    assert trigsimp(cot(2)*cos(3)*exp(2)*sin(2)) == cos(3)*exp(2)*cos(2)
    assert trigsimp(tan(2)*cos(3)*exp(2)/sin(2)) == cos(3)*exp(2)/cos(2)
    assert trigsimp(cot(2)*cos(3)*exp(2)/cos(2)) == cos(3)*exp(2)/sin(2)
    assert trigsimp(cot(2)*cos(3)*exp(2)*tan(2)) == cos(3)*exp(2)
    assert trigsimp(sinh(2)*cos(3)*exp(2)/cosh(2)) == tanh(2)*cos(3)*exp(2)
    assert trigsimp(tanh(2)*cos(3)*exp(2)*cosh(2)) == sinh(2)*cos(3)*exp(2)
    assert trigsimp(coth(2)*cos(3)*exp(2)*sinh(2)) == cosh(2)*cos(3)*exp(2)
    assert trigsimp(tanh(2)*cos(3)*exp(2)/sinh(2)) == cos(3)*exp(2)/cosh(2)
    assert trigsimp(coth(2)*cos(3)*exp(2)/cosh(2)) == cos(3)*exp(2)/sinh(2)
    assert trigsimp(coth(2)*cos(3)*exp(2)*tanh(2)) == cos(3)*exp(2)
Esempio n. 12
0
def test_gruntz_hyperbolic():
    assert limit(cosh(x), x, oo) == oo
    assert limit(cosh(-x), x, oo) == oo
    assert limit(sinh(x), x, oo) == oo
    assert limit(sinh(-x), x, oo) == -oo
    assert limit(2*cosh(x)*exp(x), x, oo) == oo
    assert limit(2*cosh(-x)*exp(-x), x, oo) == 1
    assert limit(2*sinh(x)*exp(x), x, oo) == oo
    assert limit(2*sinh(-x)*exp(-x), x, oo) == -1
    assert limit(tanh(x), x, oo) == 1
    assert limit(tanh(-x), x, oo) == -1
    assert limit(coth(x), x, oo) == 1
    assert limit(coth(-x), x, oo) == -1
Esempio n. 13
0
def test_hyperbolic_simp():
    assert trigsimp(sinh(x)**2 + 1) == cosh(x)**2
    assert trigsimp(cosh(x)**2 - 1) == sinh(x)**2
    assert trigsimp(cosh(x)**2 - sinh(x)**2) == 1
    assert trigsimp(1 - tanh(x)**2) == 1 / cosh(x)**2
    assert trigsimp(1 - 1 / cosh(x)**2) == tanh(x)**2
    assert trigsimp(tanh(x)**2 + 1 / cosh(x)**2) == 1
    assert trigsimp(coth(x)**2 - 1) == 1 / sinh(x)**2
    assert trigsimp(1 / sinh(x)**2 + 1) == 1 / tanh(x)**2
    assert trigsimp(coth(x)**2 - 1 / sinh(x)**2) == 1

    assert trigsimp(5 * cosh(x)**2 - 5 * sinh(x)**2) == 5
    assert trigsimp(5 * cosh(x / 2)**2 -
                    2 * sinh(x / 2)**2) == 3 * cosh(x) / 2 + Rational(7, 2)

    assert trigsimp(sinh(x) / cosh(x)) == tanh(x)
    assert trigsimp(tanh(x)) == trigsimp(sinh(x) / cosh(x))
    assert trigsimp(cosh(x) / sinh(x)) == 1 / tanh(x)
    assert trigsimp(2 * tanh(x) * cosh(x)) == 2 * sinh(x)
    assert trigsimp(coth(x)**3 * sinh(x)**3) == cosh(x)**3
    assert trigsimp(y * tanh(x)**2 / sinh(x)**2) == y / cosh(x)**2
    assert trigsimp(coth(x) / cosh(x)) == 1 / sinh(x)

    e = 2 * cosh(x)**2 - 2 * sinh(x)**2
    assert trigsimp(log(e)) == log(2)

    assert trigsimp(cosh(x)**2 * cosh(y)**2 - cosh(x)**2 * sinh(y)**2 -
                    sinh(x)**2,
                    recursive=True) == 1
    assert trigsimp(sinh(x)**2 * sinh(y)**2 - sinh(x)**2 * cosh(y)**2 +
                    cosh(x)**2,
                    recursive=True) == 1

    assert abs(trigsimp(2.0 * cosh(x)**2 - 2.0 * sinh(x)**2) - 2.0) < 1e-10

    assert trigsimp(sinh(x)**2 / cosh(x)**2) == tanh(x)**2
    assert trigsimp(sinh(x)**3 / cosh(x)**3) == tanh(x)**3
    assert trigsimp(sinh(x)**10 / cosh(x)**10) == tanh(x)**10
    assert trigsimp(cosh(x)**3 / sinh(x)**3) == 1 / tanh(x)**3

    assert trigsimp(cosh(x) / sinh(x)) == 1 / tanh(x)
    assert trigsimp(cosh(x)**2 / sinh(x)**2) == 1 / tanh(x)**2
    assert trigsimp(cosh(x)**10 / sinh(x)**10) == 1 / tanh(x)**10

    assert trigsimp(x * cosh(x) * tanh(x)) == x * sinh(x)
    assert trigsimp(-sinh(x) + cosh(x) * tanh(x)) == 0

    assert tan(x) != 1 / cot(x)  # cot doesn't auto-simplify

    assert trigsimp(tan(x) - 1 / cot(x)) == 0
    assert trigsimp(3 * tanh(x)**7 - 2 / coth(x)**7) == tanh(x)**7
Esempio n. 14
0
def test_hyperbolic_simp():
    assert trigsimp(sinh(x)**2 + 1) == cosh(x)**2
    assert trigsimp(cosh(x)**2 - 1) == sinh(x)**2
    assert trigsimp(cosh(x)**2 - sinh(x)**2) == 1
    assert trigsimp(1 - tanh(x)**2) == 1/cosh(x)**2
    assert trigsimp(1 - 1/cosh(x)**2) == tanh(x)**2
    assert trigsimp(tanh(x)**2 + 1/cosh(x)**2) == 1
    assert trigsimp(coth(x)**2 - 1) == 1/sinh(x)**2
    assert trigsimp(1/sinh(x)**2 + 1) == 1/tanh(x)**2
    assert trigsimp(coth(x)**2 - 1/sinh(x)**2) == 1

    assert trigsimp(5*cosh(x)**2 - 5*sinh(x)**2) == 5
    assert trigsimp(5*cosh(x/2)**2 - 2*sinh(x/2)**2) == 3*cosh(x)/2 + Rational(7, 2)

    assert trigsimp(sinh(x)/cosh(x)) == tanh(x)
    assert trigsimp(tanh(x)) == trigsimp(sinh(x)/cosh(x))
    assert trigsimp(cosh(x)/sinh(x)) == 1/tanh(x)
    assert trigsimp(2*tanh(x)*cosh(x)) == 2*sinh(x)
    assert trigsimp(coth(x)**3*sinh(x)**3) == cosh(x)**3
    assert trigsimp(y*tanh(x)**2/sinh(x)**2) == y/cosh(x)**2
    assert trigsimp(coth(x)/cosh(x)) == 1/sinh(x)

    e = 2*cosh(x)**2 - 2*sinh(x)**2
    assert trigsimp(log(e)) == log(2)

    assert trigsimp(cosh(x)**2*cosh(y)**2 - cosh(x)**2*sinh(y)**2 - sinh(x)**2,
                    recursive=True) == 1
    assert trigsimp(sinh(x)**2*sinh(y)**2 - sinh(x)**2*cosh(y)**2 + cosh(x)**2,
                    recursive=True) == 1

    assert abs(trigsimp(2.0*cosh(x)**2 - 2.0*sinh(x)**2) - 2.0) < 1e-10

    assert trigsimp(sinh(x)**2/cosh(x)**2) == tanh(x)**2
    assert trigsimp(sinh(x)**3/cosh(x)**3) == tanh(x)**3
    assert trigsimp(sinh(x)**10/cosh(x)**10) == tanh(x)**10
    assert trigsimp(cosh(x)**3/sinh(x)**3) == 1/tanh(x)**3

    assert trigsimp(cosh(x)/sinh(x)) == 1/tanh(x)
    assert trigsimp(cosh(x)**2/sinh(x)**2) == 1/tanh(x)**2
    assert trigsimp(cosh(x)**10/sinh(x)**10) == 1/tanh(x)**10

    assert trigsimp(x*cosh(x)*tanh(x)) == x*sinh(x)
    assert trigsimp(-sinh(x) + cosh(x)*tanh(x)) == 0

    assert tan(x) != 1/cot(x)  # cot doesn't auto-simplify

    assert trigsimp(tan(x) - 1/cot(x)) == 0
    assert trigsimp(3*tanh(x)**7 - 2/coth(x)**7) == tanh(x)**7
Esempio n. 15
0
def test_cosh_rewrite():
    assert cosh(x).rewrite(exp) == (exp(x) + exp(-x))/2 \
        == cosh(x).rewrite('tractable')
    assert cosh(x).rewrite(sinh) == -I * sinh(x + I * pi / 2)
    tanh_half = tanh(S.Half * x)**2
    assert cosh(x).rewrite(tanh) == (1 + tanh_half) / (1 - tanh_half)
    coth_half = coth(S.Half * x)**2
    assert cosh(x).rewrite(coth) == (coth_half + 1) / (coth_half - 1)
Esempio n. 16
0
def test_sinh_rewrite():
    assert sinh(x).rewrite(exp) == (exp(x) - exp(-x))/2 \
        == sinh(x).rewrite('tractable')
    assert sinh(x).rewrite(cosh) == -I * cosh(x + I * pi / 2)
    tanh_half = tanh(S.Half * x)
    assert sinh(x).rewrite(tanh) == 2 * tanh_half / (1 - tanh_half**2)
    coth_half = coth(S.Half * x)
    assert sinh(x).rewrite(coth) == 2 * coth_half / (coth_half**2 - 1)
Esempio n. 17
0
def test_csch_rewrite():
    assert csch(x).rewrite(exp) == 1 / (exp(x)/2 - exp(-x)/2) \
        == csch(x).rewrite('tractable')
    assert csch(x).rewrite(cosh) == I / cosh(x + I * pi / 2)
    tanh_half = tanh(S.Half * x)
    assert csch(x).rewrite(tanh) == (1 - tanh_half**2) / (2 * tanh_half)
    coth_half = coth(S.Half * x)
    assert csch(x).rewrite(coth) == (coth_half**2 - 1) / (2 * coth_half)
Esempio n. 18
0
def test_sech_rewrite():
    assert sech(x).rewrite(exp) == 1 / (exp(x)/2 + exp(-x)/2) \
        == sech(x).rewrite('tractable')
    assert sech(x).rewrite(sinh) == I / sinh(x + I * pi / 2)
    tanh_half = tanh(S.Half * x)**2
    assert sech(x).rewrite(tanh) == (1 - tanh_half) / (1 + tanh_half)
    coth_half = coth(S.Half * x)**2
    assert sech(x).rewrite(coth) == (coth_half - 1) / (coth_half + 1)
Esempio n. 19
0
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
Esempio n. 20
0
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
Esempio n. 21
0
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)
Esempio n. 22
0
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)
Esempio n. 23
0
def test_conjugate():
    a = Symbol('a', extended_real=True)
    b = Symbol('b', extended_real=True)
    c = Symbol('c', imaginary=True)
    d = Symbol('d', imaginary=True)
    z = a + I * b + c + I * d
    zc = a - I * b - c + I * d
    assert conjugate(z) == zc
    assert conjugate(exp(z)) == exp(zc)
    assert conjugate(exp(I * x)) == exp(-I * conjugate(x))
    assert conjugate(z**5) == zc**5
    assert conjugate(abs(x)) == abs(x)
    assert conjugate(sign(z)) == sign(zc)
    assert conjugate(sin(z)) == sin(zc)
    assert conjugate(cos(z)) == cos(zc)
    assert conjugate(tan(z)) == tan(zc)
    assert conjugate(cot(z)) == cot(zc)
    assert conjugate(sinh(z)) == sinh(zc)
    assert conjugate(cosh(z)) == cosh(zc)
    assert conjugate(tanh(z)) == tanh(zc)
    assert conjugate(coth(z)) == coth(zc)
Esempio n. 24
0
def test_trigsimp_old(capsys):
    e = 2 * sin(x)**2 + 2 * cos(x)**2
    assert trigsimp(e, old=True) == 2
    e = 3 * tanh(x)**7 - 2 / coth(x)**7
    assert trigsimp(e, method='old') == e
    e = (-sin(x) + 1) / cos(x) + cos(x) / (-sin(x) + 1)
    assert (trigsimp(e, method='old') == (-sin(x) + 1) / cos(x) - cos(x) /
            (sin(x) - 1))
    e = (-sin(x) + 1) / cos(x) + cos(x) / (-sin(x) + 1)
    assert trigsimp(e, method='groebner', old=True) == 2 / cos(x)

    assert trigsimp(1 / cot(x)**2, compare=True, old=True) == cot(x)**(-2)
    assert capsys.readouterr().out == '\tfutrig: tan(x)**2\n'
Esempio n. 25
0
def test_cot_rewrite():
    neg_exp, pos_exp = exp(-x*I), exp(x*I)
    assert cot(x).rewrite(exp) == I*(pos_exp + neg_exp)/(pos_exp - neg_exp)
    assert cot(x).rewrite(sin) == 2*sin(2*x)/sin(x)**2
    assert cot(x).rewrite(cos) == -cos(x)/cos(x + pi/2)
    assert cot(x).rewrite(tan) == 1/tan(x)
    assert (cot(sinh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cot(x).rewrite(exp).subs({x: sinh(3)}).evalf())
    assert (cot(cosh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cot(x).rewrite(exp).subs({x: cosh(3)}).evalf())
    assert (cot(tanh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cot(x).rewrite(exp).subs({x: tanh(3)}).evalf())
    assert (cot(coth(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cot(x).rewrite(exp).subs({x: coth(3)}).evalf())
    assert (cot(sin(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cot(x).rewrite(exp).subs({x: sin(3)}).evalf())
    assert (cot(tan(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cot(x).rewrite(exp).subs({x: tan(3)}).evalf())
    assert cot(log(x)).rewrite(Pow) == -I*(x**-I + x**I)/(x**-I - x**I)
    assert cot(4*pi/34).rewrite(sqrt).ratsimp() == (cos(4*pi/34)/sin(4*pi/34)).rewrite(sqrt).ratsimp()
    assert cot(4*pi/17).rewrite(sqrt) == (cos(4*pi/17)/sin(4*pi/17)).rewrite(sqrt)
    assert cot(pi/19).rewrite(sqrt) == cot(pi/19)
Esempio n. 26
0
def test_conjugate():
    a = Symbol("a", extended_real=True)
    b = Symbol("b", extended_real=True)
    c = Symbol("c", imaginary=True)
    d = Symbol("d", imaginary=True)
    x = Symbol('x')
    z = a + I*b + c + I*d
    zc = a - I*b - c + I*d
    assert conjugate(z) == zc
    assert conjugate(exp(z)) == exp(zc)
    assert conjugate(exp(I*x)) == exp(-I*conjugate(x))
    assert conjugate(z**5) == zc**5
    assert conjugate(abs(x)) == abs(x)
    assert conjugate(sign(z)) == sign(zc)
    assert conjugate(sin(z)) == sin(zc)
    assert conjugate(cos(z)) == cos(zc)
    assert conjugate(tan(z)) == tan(zc)
    assert conjugate(cot(z)) == cot(zc)
    assert conjugate(sinh(z)) == sinh(zc)
    assert conjugate(cosh(z)) == cosh(zc)
    assert conjugate(tanh(z)) == tanh(zc)
    assert conjugate(coth(z)) == coth(zc)
Esempio n. 27
0
def test_cos_rewrite():
    assert cos(x).rewrite(exp) == exp(I*x)/2 + exp(-I*x)/2
    assert cos(x).rewrite(tan) == (1 - tan(x/2)**2)/(1 + tan(x/2)**2)
    assert cos(x).rewrite(cot) == -(1 - cot(x/2)**2)/(1 + cot(x/2)**2)
    assert (cos(sinh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cos(x).rewrite(exp).subs({x: sinh(3)}).evalf())
    assert (cos(cosh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cos(x).rewrite(exp).subs({x: cosh(3)}).evalf())
    assert (cos(tanh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cos(x).rewrite(exp).subs({x: tanh(3)}).evalf())
    assert (cos(coth(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cos(x).rewrite(exp).subs({x: coth(3)}).evalf())
    assert (cos(sin(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cos(x).rewrite(exp).subs({x: sin(3)}).evalf())
    assert (cos(cos(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cos(x).rewrite(exp).subs({x: cos(3)}).evalf())
    assert (cos(tan(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cos(x).rewrite(exp).subs({x: tan(3)}).evalf())
    assert (cos(cot(x)).rewrite(exp).subs({x: 3}).evalf() ==
            cos(x).rewrite(exp).subs({x: cot(3)}).evalf())
    assert cos(log(x)).rewrite(Pow) == x**I/2 + x**-I/2
    assert cos(x).rewrite(Pow) == cos(x)
    assert cos(x).rewrite(sec) == 1/sec(x)
Esempio n. 28
0
def test_sin_rewrite():
    assert sin(x).rewrite(exp) == -I*(exp(I*x) - exp(-I*x))/2
    assert sin(x).rewrite(tan) == 2*tan(x/2)/(1 + tan(x/2)**2)
    assert sin(x).rewrite(cot) == 2*cot(x/2)/(1 + cot(x/2)**2)
    assert (sin(sinh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            sin(x).rewrite(exp).subs({x: sinh(3)}).evalf())
    assert (sin(cosh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            sin(x).rewrite(exp).subs({x: cosh(3)}).evalf())
    assert (sin(tanh(x)).rewrite(exp).subs({x: 3}).evalf() ==
            sin(x).rewrite(exp).subs({x: tanh(3)}).evalf())
    assert (sin(coth(x)).rewrite(exp).subs({x: 3}).evalf() ==
            sin(x).rewrite(exp).subs({x: coth(3)}).evalf())
    assert (sin(sin(x)).rewrite(exp).subs({x: 3}).evalf() ==
            sin(x).rewrite(exp).subs({x: sin(3)}).evalf())
    assert (sin(cos(x)).rewrite(exp).subs({x: 3}).evalf() ==
            sin(x).rewrite(exp).subs({x: cos(3)}).evalf())
    assert (sin(tan(x)).rewrite(exp).subs({x: 3}).evalf() ==
            sin(x).rewrite(exp).subs({x: tan(3)}).evalf())
    assert (sin(cot(x)).rewrite(exp).subs({x: 3}).evalf() ==
            sin(x).rewrite(exp).subs({x: cot(3)}).evalf())
    assert sin(log(x)).rewrite(Pow) == I*x**-I / 2 - I*x**I / 2
    assert sin(x).rewrite(Pow) == sin(x)  # issue sympy/sympy#7171
    assert sin(x).rewrite(csc) == 1/csc(x)
Esempio n. 29
0
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
Esempio n. 30
0
def test_hyper_as_trig():
    eq = sinh(x)**2 + cosh(x)**2
    t, f = hyper_as_trig(eq)
    assert f(fu(t)) == cosh(2*x)
    e, f = hyper_as_trig(tanh(x + y))
    assert f(TR12(e)) == (tanh(x) + tanh(y))/(tanh(x)*tanh(y) + 1)

    d = Dummy()
    assert o(sinh(x), d) == I*sin(x*d)
    assert o(tanh(x), d) == I*tan(x*d)
    assert o(coth(x), d) == cot(x*d)/I
    assert o(cosh(x), d) == cos(x*d)
    for func in (sinh, cosh, tanh, coth):
        h = func(pi)
        assert i(o(h, d), d) == h
    # /!\ the _osborne functions are not meant to work
    # in the o(i(trig, d), d) direction so we just check
    # that they work as they are supposed to work
    assert i(cos(x*y), y) == cosh(x)
    assert i(sin(x*y), y) == sinh(x)/I
    assert i(tan(x*y), y) == tanh(x)/I
    assert i(cot(x*y), y) == coth(x)*I
    assert i(sec(x*y), y) == 1/cosh(x)
    assert i(csc(x*y), y) == I/sinh(x)
Esempio n. 31
0
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
Esempio n. 32
0
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
Esempio n. 33
0
def test_complex():
    a, b = symbols('a,b', extended_real=True)
    z = a + b*I
    for func in [sinh, cosh, tanh, coth, sech, csch]:
        assert func(z).conjugate() == func(a - b*I)
    for deep in [True, False]:
        assert sinh(z).expand(
            complex=True, deep=deep) == sinh(a)*cos(b) + I*cosh(a)*sin(b)
        assert cosh(z).expand(
            complex=True, deep=deep) == cosh(a)*cos(b) + I*sinh(a)*sin(b)
        assert tanh(z).expand(complex=True, deep=deep) == sinh(a)*cosh(
            a)/(cos(b)**2 + sinh(a)**2) + I*sin(b)*cos(b)/(cos(b)**2 + sinh(a)**2)
        assert coth(z).expand(complex=True, deep=deep) == sinh(a)*cosh(
            a)/(sin(b)**2 + sinh(a)**2) - I*sin(b)*cos(b)/(sin(b)**2 + sinh(a)**2)
        assert csch(z).expand(complex=True, deep=deep) == cos(b) * sinh(a) / (sin(b)**2
                                                                              * cosh(a)**2 + cos(b)**2 * sinh(a)**2) - I*sin(b) * cosh(a) / (sin(b)**2
                                                                                                                                             * cosh(a)**2 + cos(b)**2 * sinh(a)**2)
        assert sech(z).expand(complex=True, deep=deep) == cos(b) * cosh(a) / (sin(b)**2
                                                                              * sinh(a)**2 + cos(b)**2 * cosh(a)**2) - I*sin(b) * sinh(a) / (sin(b)**2
                                                                                                                                             * sinh(a)**2 + cos(b)**2 * cosh(a)**2)
Esempio n. 34
0
def test_complex():
    a, b = symbols('a,b', extended_real=True)
    z = a + b*I
    for func in [sinh, cosh, tanh, coth, sech, csch]:
        assert func(z).conjugate() == func(a - b*I)
    for deep in [True, False]:
        assert sinh(z).expand(
            complex=True, deep=deep) == sinh(a)*cos(b) + I*cosh(a)*sin(b)
        assert cosh(z).expand(
            complex=True, deep=deep) == cosh(a)*cos(b) + I*sinh(a)*sin(b)
        assert tanh(z).expand(complex=True, deep=deep) == sinh(a)*cosh(
            a)/(cos(b)**2 + sinh(a)**2) + I*sin(b)*cos(b)/(cos(b)**2 + sinh(a)**2)
        assert coth(z).expand(complex=True, deep=deep) == sinh(a)*cosh(
            a)/(sin(b)**2 + sinh(a)**2) - I*sin(b)*cos(b)/(sin(b)**2 + sinh(a)**2)
        assert csch(z).expand(complex=True, deep=deep) == cos(b) * sinh(a) / (sin(b)**2
                                                                              * cosh(a)**2 + cos(b)**2 * sinh(a)**2) - I*sin(b) * cosh(a) / (sin(b)**2
                                                                                                                                             * cosh(a)**2 + cos(b)**2 * sinh(a)**2)
        assert sech(z).expand(complex=True, deep=deep) == cos(b) * cosh(a) / (sin(b)**2
                                                                              * sinh(a)**2 + cos(b)**2 * cosh(a)**2) - I*sin(b) * sinh(a) / (sin(b)**2
                                                                                                                                             * sinh(a)**2 + cos(b)**2 * cosh(a)**2)
Esempio n. 35
0
def test_coth():
    k = Symbol('k', integer=True)

    assert coth(nan) == nan
    assert coth(zoo) == nan

    assert coth(oo) == 1
    assert coth(-oo) == -1

    assert coth(0) == coth(0)
    assert coth(0) == zoo
    assert coth(1) == coth(1)
    assert coth(-1) == -coth(1)

    assert coth(x) == coth(x)
    assert coth(-x) == -coth(x)

    assert coth(pi*I) == -I*cot(pi)
    assert coth(-pi*I) == cot(pi)*I

    assert coth(2**1024 * E) == coth(2**1024 * E)
    assert coth(-2**1024 * E) == -coth(2**1024 * E)

    assert coth(pi*I) == -I*cot(pi)
    assert coth(-pi*I) == I*cot(pi)
    assert coth(2*pi*I) == -I*cot(2*pi)
    assert coth(-2*pi*I) == I*cot(2*pi)
    assert coth(-3*10**73*pi*I) == I*cot(3*10**73*pi)
    assert coth(7*10**103*pi*I) == -I*cot(7*10**103*pi)

    assert coth(pi*I/2) == 0
    assert coth(-pi*I/2) == 0
    assert coth(5*pi*I/2) == 0
    assert coth(7*pi*I/2) == 0

    assert coth(pi*I/3) == -I/sqrt(3)
    assert coth(-2*pi*I/3) == -I/sqrt(3)

    assert coth(pi*I/4) == -I
    assert coth(-pi*I/4) == I
    assert coth(17*pi*I/4) == -I
    assert coth(-3*pi*I/4) == -I

    assert coth(pi*I/6) == -sqrt(3)*I
    assert coth(-pi*I/6) == sqrt(3)*I
    assert coth(7*pi*I/6) == -sqrt(3)*I
    assert coth(-5*pi*I/6) == -sqrt(3)*I

    assert coth(pi*I/105) == -cot(pi/105)*I
    assert coth(-pi*I/105) == cot(pi/105)*I

    assert coth(2 + 3*I) == coth(2 + 3*I)

    assert coth(x*I) == -cot(x)*I

    assert coth(k*pi*I) == -cot(k*pi)*I
    assert coth(17*k*pi*I) == -cot(17*k*pi)*I

    assert coth(k*pi*I) == -cot(k*pi)*I

    pytest.raises(ArgumentIndexError, lambda: coth(x).fdiff(2))

    a, b = symbols('a b', extended_real=True)
    z = a + b*I
    for deep in [True, False]:
        d = sinh(a)**2 + sin(b)**2
        assert coth(z).as_real_imag(deep=deep) == (sinh(a)*cosh(a)/d,
                                                   -sin(b)*cos(b)/d)
        assert coth(a).as_real_imag(deep=deep) == (coth(a), 0)
Esempio n. 36
0
def test_coth_series():
    assert coth(x).series(x, 0, 8) == \
        1/x + x/3 - x**3/45 + 2*x**5/945 - x**7/4725 + O(x**8)
Esempio n. 37
0
def test_sinh_rewrite():
    assert sinh(x).rewrite(exp) == (exp(x) - exp(-x))/2 \
        == sinh(x).rewrite('tractable')
    assert sinh(x).rewrite(cosh) == -I*cosh(x + I*pi/2)
    assert sinh(x).rewrite(tanh) == 2*tanh(x/2)/(1 - tanh(x/2)**2)
    assert sinh(x).rewrite(coth) == 2*coth(x/2)/(coth(x/2)**2 - 1)
Esempio n. 38
0
def test_coth_series():
    assert coth(x).series(x, 0, 8) == \
        1/x + x/3 - x**3/45 + 2*x**5/945 - x**7/4725 + O(x**8)
Esempio n. 39
0
def test_csch_rewrite():
    assert csch(x).rewrite(exp) == 1 / (exp(x)/2 - exp(-x)/2) \
        == csch(x).rewrite('tractable')
    assert csch(x).rewrite(cosh) == I / cosh(x + I * pi / 2)
    assert csch(x).rewrite(tanh) == (1 - tanh(x / 2)**2) / (2 * tanh(x / 2))
    assert csch(x).rewrite(coth) == (coth(x / 2)**2 - 1) / (2 * coth(x / 2))
Esempio n. 40
0
def test_tanh_rewrite():
    assert tanh(x).rewrite(exp) == (exp(x) - exp(-x))/(exp(x) + exp(-x)) \
        == tanh(x).rewrite('tractable')
    assert tanh(x).rewrite(sinh) == I * sinh(x) / sinh(I * pi / 2 - x)
    assert tanh(x).rewrite(cosh) == I * cosh(I * pi / 2 - x) / cosh(x)
    assert tanh(x).rewrite(coth) == 1 / coth(x)
Esempio n. 41
0
def test_cosh_rewrite():
    assert cosh(x).rewrite(exp) == (exp(x) + exp(-x))/2 \
        == cosh(x).rewrite('tractable')
    assert cosh(x).rewrite(sinh) == -I * sinh(x + I * pi / 2)
    assert cosh(x).rewrite(tanh) == (1 + tanh(x / 2)**2) / (1 - tanh(x / 2)**2)
    assert cosh(x).rewrite(coth) == (coth(x / 2)**2 + 1) / (coth(x / 2)**2 - 1)
Esempio n. 42
0
def test_sinh_rewrite():
    assert sinh(x).rewrite(exp) == (exp(x) - exp(-x))/2 \
        == sinh(x).rewrite('tractable')
    assert sinh(x).rewrite(cosh) == -I * cosh(x + I * pi / 2)
    assert sinh(x).rewrite(tanh) == 2 * tanh(x / 2) / (1 - tanh(x / 2)**2)
    assert sinh(x).rewrite(coth) == 2 * coth(x / 2) / (coth(x / 2)**2 - 1)
Esempio n. 43
0
def test_coth_rewrite():
    assert coth(x).rewrite(exp) == (exp(x) + exp(-x))/(exp(x) - exp(-x)) \
        == coth(x).rewrite('tractable')
    assert coth(x).rewrite(sinh) == -I*sinh(I*pi/2 - x)/sinh(x)
    assert coth(x).rewrite(cosh) == -I*cosh(x)/cosh(I*pi/2 - x)
    assert coth(x).rewrite(tanh) == 1/tanh(x)
Esempio n. 44
0
def test_csch_rewrite():
    assert csch(x).rewrite(exp) == 1 / (exp(x)/2 - exp(-x)/2) \
        == csch(x).rewrite('tractable')
    assert csch(x).rewrite(cosh) == I/cosh(x + I*pi/2)
    assert csch(x).rewrite(tanh) == (1 - tanh(x/2)**2)/(2*tanh(x/2))
    assert csch(x).rewrite(coth) == (coth(x/2)**2 - 1)/(2*coth(x/2))
Esempio n. 45
0
def test_sech_rewrite():
    assert sech(x).rewrite(exp) == 1 / (exp(x)/2 + exp(-x)/2) \
        == sech(x).rewrite('tractable')
    assert sech(x).rewrite(sinh) == I / sinh(x + I * pi / 2)
    assert sech(x).rewrite(tanh) == (1 - tanh(x / 2)**2) / (1 + tanh(x / 2)**2)
    assert sech(x).rewrite(coth) == (coth(x / 2)**2 - 1) / (coth(x / 2)**2 + 1)
Esempio n. 46
0
def test_cosh_rewrite():
    assert cosh(x).rewrite(exp) == (exp(x) + exp(-x))/2 \
        == cosh(x).rewrite('tractable')
    assert cosh(x).rewrite(sinh) == -I*sinh(x + I*pi/2)
    assert cosh(x).rewrite(tanh) == (1 + tanh(x/2)**2)/(1 - tanh(x/2)**2)
    assert cosh(x).rewrite(coth) == (coth(x/2)**2 + 1)/(coth(x/2)**2 - 1)
Esempio n. 47
0
def test_sech_rewrite():
    assert sech(x).rewrite(exp) == 1 / (exp(x)/2 + exp(-x)/2) \
        == sech(x).rewrite('tractable')
    assert sech(x).rewrite(sinh) == I/sinh(x + I*pi/2)
    assert sech(x).rewrite(tanh) == (1 - tanh(x/2)**2)/(1 + tanh(x/2)**2)
    assert sech(x).rewrite(coth) == (coth(x/2)**2 - 1)/(coth(x/2)**2 + 1)
Esempio n. 48
0
def test_coth():
    k = Symbol('k', integer=True)

    assert coth(nan) == nan
    assert coth(zoo) == nan

    assert coth(oo) == 1
    assert coth(-oo) == -1

    assert coth(0) == coth(0)
    assert coth(0) == zoo
    assert coth(1) == coth(1)
    assert coth(-1) == -coth(1)

    assert coth(x) == coth(x)
    assert coth(-x) == -coth(x)

    assert coth(pi * I) == -I * cot(pi)
    assert coth(-pi * I) == cot(pi) * I

    assert coth(2**1024 * E) == coth(2**1024 * E)
    assert coth(-2**1024 * E) == -coth(2**1024 * E)

    assert coth(pi * I) == -I * cot(pi)
    assert coth(-pi * I) == I * cot(pi)
    assert coth(2 * pi * I) == -I * cot(2 * pi)
    assert coth(-2 * pi * I) == I * cot(2 * pi)
    assert coth(-3 * 10**73 * pi * I) == I * cot(3 * 10**73 * pi)
    assert coth(7 * 10**103 * pi * I) == -I * cot(7 * 10**103 * pi)

    assert coth(pi * I / 2) == 0
    assert coth(-pi * I / 2) == 0
    assert coth(5 * pi * I / 2) == 0
    assert coth(7 * pi * I / 2) == 0

    assert coth(pi * I / 3) == -I / sqrt(3)
    assert coth(-2 * pi * I / 3) == -I / sqrt(3)

    assert coth(pi * I / 4) == -I
    assert coth(-pi * I / 4) == I
    assert coth(17 * pi * I / 4) == -I
    assert coth(-3 * pi * I / 4) == -I

    assert coth(pi * I / 6) == -sqrt(3) * I
    assert coth(-pi * I / 6) == sqrt(3) * I
    assert coth(7 * pi * I / 6) == -sqrt(3) * I
    assert coth(-5 * pi * I / 6) == -sqrt(3) * I

    assert coth(pi * I / 105) == -cot(pi / 105) * I
    assert coth(-pi * I / 105) == cot(pi / 105) * I

    assert coth(2 + 3 * I) == coth(2 + 3 * I)

    assert coth(x * I) == -cot(x) * I

    assert coth(k * pi * I) == -cot(k * pi) * I
    assert coth(17 * k * pi * I) == -cot(17 * k * pi) * I

    assert coth(k * pi * I) == -cot(k * pi) * I

    pytest.raises(ArgumentIndexError, lambda: coth(x).fdiff(2))

    a, b = symbols('a b', extended_real=True)
    z = a + b * I
    for deep in [True, False]:
        d = sinh(a)**2 + sin(b)**2
        assert coth(z).as_real_imag(deep=deep) == (sinh(a) * cosh(a) / d,
                                                   -sin(b) * cos(b) / d)
        assert coth(a).as_real_imag(deep=deep) == (coth(a), 0)