Exemplo n.º 1
0
def test_hyper_as_trig():
    from sympy.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)
    assert o(sech(x), d) == sec(x*d)
    assert o(csch(x), d) == csc(x*d)/I
    for func in (sinh, cosh, tanh, coth, sech, csch):
        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 + z), y) == cosh(x + z*I)
    assert i(sin(x*y + z), y) == sinh(x + z*I)/I
    assert i(tan(x*y + z), y) == tanh(x + z*I)/I
    assert i(cot(x*y + z), y) == coth(x + z*I)*I
    assert i(sec(x*y + z), y) == sech(x + z*I)
    assert i(csc(x*y + z), y) == csch(x + z*I)*I
Exemplo n.º 2
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 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
Exemplo n.º 3
0
def test_tan_rewrite():
    x = Symbol('x')
    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 + S.Pi / 2) / cos(x)
    assert tan(x).rewrite(cot) == 1 / cot(x)
    assert tan(sinh(x)).rewrite(exp).subs(x,
                                          3).n() == tan(x).rewrite(exp).subs(
                                              x, sinh(3)).n()
    assert tan(cosh(x)).rewrite(exp).subs(x,
                                          3).n() == tan(x).rewrite(exp).subs(
                                              x, cosh(3)).n()
    assert tan(tanh(x)).rewrite(exp).subs(x,
                                          3).n() == tan(x).rewrite(exp).subs(
                                              x, tanh(3)).n()
    assert tan(coth(x)).rewrite(exp).subs(x,
                                          3).n() == tan(x).rewrite(exp).subs(
                                              x, coth(3)).n()
    assert tan(sin(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(
        x, sin(3)).n()
    assert tan(cos(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(
        x, cos(3)).n()
    assert tan(tan(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(
        x, tan(3)).n()
    assert tan(cot(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(
        x, cot(3)).n()
    assert tan(log(x)).rewrite(Pow) == I * (x**-I - x**I) / (x**-I + x**I)
Exemplo n.º 4
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)
Exemplo n.º 5
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 + S.Pi / 2) / cos(x)
    assert tan(x).rewrite(cot) == 1 / cot(x)
    assert tan(sinh(x)).rewrite(exp).subs(x,
                                          3).n() == tan(x).rewrite(exp).subs(
                                              x, sinh(3)).n()
    assert tan(cosh(x)).rewrite(exp).subs(x,
                                          3).n() == tan(x).rewrite(exp).subs(
                                              x, cosh(3)).n()
    assert tan(tanh(x)).rewrite(exp).subs(x,
                                          3).n() == tan(x).rewrite(exp).subs(
                                              x, tanh(3)).n()
    assert tan(coth(x)).rewrite(exp).subs(x,
                                          3).n() == tan(x).rewrite(exp).subs(
                                              x, coth(3)).n()
    assert tan(sin(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(
        x, sin(3)).n()
    assert tan(cos(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(
        x, cos(3)).n()
    assert tan(tan(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(
        x, tan(3)).n()
    assert tan(cot(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(
        x, cot(3)).n()
    assert tan(log(x)).rewrite(Pow) == I * (x**-I - x**I) / (x**-I + x**I)
    assert 0 == (cos(pi / 15) * tan(pi / 15) - sin(pi / 15)).rewrite(pow)
    assert tan(pi / 19).rewrite(pow) == tan(pi / 19)
    assert tan(8 * pi / 19).rewrite(sqrt) == tan(8 * pi / 19)
Exemplo n.º 6
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).n() == sin(x).rewrite(exp).subs(
                                              x, sinh(3)).n()
    assert sin(cosh(x)).rewrite(exp).subs(x,
                                          3).n() == sin(x).rewrite(exp).subs(
                                              x, cosh(3)).n()
    assert sin(tanh(x)).rewrite(exp).subs(x,
                                          3).n() == sin(x).rewrite(exp).subs(
                                              x, tanh(3)).n()
    assert sin(coth(x)).rewrite(exp).subs(x,
                                          3).n() == sin(x).rewrite(exp).subs(
                                              x, coth(3)).n()
    assert sin(sin(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(
        x, sin(3)).n()
    assert sin(cos(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(
        x, cos(3)).n()
    assert sin(tan(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(
        x, tan(3)).n()
    assert sin(cot(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(
        x, cot(3)).n()
    assert sin(log(x)).rewrite(Pow) == I * x**-I / 2 - I * x**I / 2
    assert sin(x).rewrite(csc) == 1 / csc(x)
Exemplo n.º 7
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 + S.Pi / 2)
    assert cot(x).rewrite(tan) == 1 / tan(x)
    assert cot(sinh(x)).rewrite(exp).subs(x,
                                          3).n() == cot(x).rewrite(exp).subs(
                                              x, sinh(3)).n()
    assert cot(cosh(x)).rewrite(exp).subs(x,
                                          3).n() == cot(x).rewrite(exp).subs(
                                              x, cosh(3)).n()
    assert cot(tanh(x)).rewrite(exp).subs(x,
                                          3).n() == cot(x).rewrite(exp).subs(
                                              x, tanh(3)).n()
    assert cot(coth(x)).rewrite(exp).subs(x,
                                          3).n() == cot(x).rewrite(exp).subs(
                                              x, coth(3)).n()
    assert cot(sin(x)).rewrite(exp).subs(x, 3).n() == cot(x).rewrite(exp).subs(
        x, sin(3)).n()
    assert cot(tan(x)).rewrite(exp).subs(x, 3).n() == cot(x).rewrite(exp).subs(
        x, tan(3)).n()
    assert cot(log(x)).rewrite(Pow) == -I * (x**-I + x**I) / (x**-I - x**I)
    assert cot(4 * pi / 15).rewrite(pow) == (cos(4 * pi / 15) /
                                             sin(4 * pi / 15)).rewrite(pow)
    assert cot(pi / 19).rewrite(pow) == cot(pi / 19)
    assert cot(pi / 19).rewrite(sqrt) == cot(pi / 19)
Exemplo n.º 8
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).n() == cos(x).rewrite(exp).subs(
                                              x, sinh(3)).n()
    assert cos(cosh(x)).rewrite(exp).subs(x,
                                          3).n() == cos(x).rewrite(exp).subs(
                                              x, cosh(3)).n()
    assert cos(tanh(x)).rewrite(exp).subs(x,
                                          3).n() == cos(x).rewrite(exp).subs(
                                              x, tanh(3)).n()
    assert cos(coth(x)).rewrite(exp).subs(x,
                                          3).n() == cos(x).rewrite(exp).subs(
                                              x, coth(3)).n()
    assert cos(sin(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(
        x, sin(3)).n()
    assert cos(cos(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(
        x, cos(3)).n()
    assert cos(tan(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(
        x, tan(3)).n()
    assert cos(cot(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(
        x, cot(3)).n()
    assert cos(log(x)).rewrite(Pow) == x**I / 2 + x**-I / 2
    assert cos(x).rewrite(sec) == 1 / sec(x)
Exemplo n.º 9
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)
Exemplo n.º 10
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 + S.Pi/2)/cos(x)
    assert tan(x).rewrite(cot) == 1/cot(x)
    assert tan(sinh(x)).rewrite(
        exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, sinh(3)).n()
    assert tan(cosh(x)).rewrite(
        exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, cosh(3)).n()
    assert tan(tanh(x)).rewrite(
        exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, tanh(3)).n()
    assert tan(coth(x)).rewrite(
        exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, coth(3)).n()
    assert tan(sin(x)).rewrite(
        exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, sin(3)).n()
    assert tan(cos(x)).rewrite(
        exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, cos(3)).n()
    assert tan(tan(x)).rewrite(
        exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, tan(3)).n()
    assert tan(cot(x)).rewrite(
        exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, cot(3)).n()
    assert tan(log(x)).rewrite(Pow) == I*(x**-I - x**I)/(x**-I + x**I)
    assert 0 == (cos(pi/15)*tan(pi/15) - sin(pi/15)).rewrite(pow)
    assert tan(pi/19).rewrite(pow) == tan(pi/19)
    assert tan(8*pi/19).rewrite(sqrt) == tan(8*pi/19)
Exemplo n.º 11
0
def test_hyper_as_trig():
    from sympy.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)
Exemplo n.º 12
0
def test_hyperbolic_simp():
    x, y = symbols('x,y')

    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)

    for a in (pi / 6 * I, pi / 4 * I, pi / 3 * I):
        assert trigsimp(sinh(a) * cosh(x) + cosh(a) * sinh(x)) == sinh(x + a)
        assert trigsimp(-sinh(a) * cosh(x) + cosh(a) * sinh(x)) == sinh(x - a)

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

    # issue 19535:
    assert trigsimp(sqrt(cosh(x)**2 - 1)) == sqrt(sinh(x)**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
Exemplo n.º 13
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 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
Exemplo n.º 14
0
def test_cot():
    assert cot(nan) == nan

    assert cot.nargs == FiniteSet(1)
    assert cot(oo*I) == -I
    assert cot(-oo*I) == I

    assert cot(0) == zoo
    assert cot(2*pi) == zoo

    assert cot(acot(x)) == x
    assert cot(atan(x)) == 1 / x
    assert cot(asin(x)) == sqrt(1 - x**2) / x
    assert cot(acos(x)) == x / sqrt(1 - x**2)
    assert cot(atan2(y, x)) == x/y

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

    assert cot(pi) == cot(2*pi) == cot(3*pi)
    assert cot(-pi) == cot(-2*pi) == cot(-3*pi)

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

    assert cot(pi/3) == 1/sqrt(3)
    assert cot(-2*pi/3) == 1/sqrt(3)

    assert cot(pi/4) == S.One
    assert cot(-pi/4) == -S.One
    assert cot(17*pi/4) == S.One
    assert cot(-3*pi/4) == S.One

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

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

    assert cot(r).is_real is True

    assert cot(a).is_algebraic is None
    assert cot(na).is_algebraic is False

    assert cot(10*pi/7) == cot(3*pi/7)
    assert cot(11*pi/7) == -cot(3*pi/7)
    assert cot(-11*pi/7) == cot(3*pi/7)

    assert cot(x).is_finite is None
    assert cot(r).is_finite is None
    i = Symbol('i', imaginary=True)
    assert cot(i).is_finite is True

    assert cot(x).subs(x, 3*pi) == zoo
Exemplo n.º 15
0
def test_cot():
    assert cot(nan) == nan

    assert cot.nargs == FiniteSet(1)
    assert cot(oo*I) == -I
    assert cot(-oo*I) == I

    assert cot(0) == zoo
    assert cot(2*pi) == zoo

    assert cot(acot(x)) == x
    assert cot(atan(x)) == 1 / x
    assert cot(asin(x)) == sqrt(1 - x**2) / x
    assert cot(acos(x)) == x / sqrt(1 - x**2)
    assert cot(atan2(y, x)) == x/y

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

    assert cot(pi) == cot(2*pi) == cot(3*pi)
    assert cot(-pi) == cot(-2*pi) == cot(-3*pi)

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

    assert cot(pi/3) == 1/sqrt(3)
    assert cot(-2*pi/3) == 1/sqrt(3)

    assert cot(pi/4) == S.One
    assert cot(-pi/4) == -S.One
    assert cot(17*pi/4) == S.One
    assert cot(-3*pi/4) == S.One

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

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

    assert cot(r).is_real is True

    assert cot(a).is_algebraic is None
    assert cot(na).is_algebraic is False

    assert cot(10*pi/7) == cot(3*pi/7)
    assert cot(11*pi/7) == -cot(3*pi/7)
    assert cot(-11*pi/7) == cot(3*pi/7)

    assert cot(x).is_finite is None
    assert cot(r).is_finite is None
    i = Symbol('i', imaginary=True)
    assert cot(i).is_finite is True

    assert cot(x).subs(x, 3*pi) == zoo
Exemplo n.º 16
0
def test_cot():
    x, y = symbols('x,y')

    r = Symbol('r', real=True)

    k = Symbol('k', integer=True)

    assert cot(nan) == nan

    assert cot(oo*I) == -I
    assert cot(-oo*I) == I

    assert cot(0) == zoo
    assert cot(2*pi) == zoo

    assert cot(acot(x)) == x
    assert cot(atan(x)) == 1 / x
    assert cot(asin(x)) == sqrt(1 - x**2) / x
    assert cot(acos(x)) == x / sqrt(1 - x**2)
    assert cot(atan2(y, x)) == x/y

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

    assert cot(pi) == cot(2*pi) == cot(3*pi)
    assert cot(-pi) == cot(-2*pi) == cot(-3*pi)

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

    assert cot(pi/3) == 1/sqrt(3)
    assert cot(-2*pi/3) == 1/sqrt(3)

    assert cot(pi/4) == S.One
    assert cot(-pi/4) == -S.One
    assert cot(17*pi/4) == S.One
    assert cot(-3*pi/4) == S.One

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

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

    assert cot(r).is_real is True

    assert cot(10*pi/7) == cot(3*pi/7)
    assert cot(11*pi/7) == -cot(3*pi/7)
    assert cot(-11*pi/7) == cot(3*pi/7)
Exemplo n.º 17
0
def test_cot():
    x, y = symbols('x,y')

    r = Symbol('r', real=True)

    k = Symbol('k', integer=True)

    assert cot(nan) == nan

    assert cot(oo * I) == -I
    assert cot(-oo * I) == I

    assert cot(0) == zoo
    assert cot(2 * pi) == zoo

    assert cot(acot(x)) == x
    assert cot(atan(x)) == 1 / x
    assert cot(asin(x)) == sqrt(1 - x**2) / x
    assert cot(acos(x)) == x / sqrt(1 - x**2)
    assert cot(atan2(y, x)) == x / y

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

    assert cot(pi) == cot(2 * pi) == cot(3 * pi)
    assert cot(-pi) == cot(-2 * pi) == cot(-3 * pi)

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

    assert cot(pi / 3) == 1 / sqrt(3)
    assert cot(-2 * pi / 3) == 1 / sqrt(3)

    assert cot(pi / 4) == S.One
    assert cot(-pi / 4) == -S.One
    assert cot(17 * pi / 4) == S.One
    assert cot(-3 * pi / 4) == S.One

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

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

    assert cot(r).is_real == True

    assert cot(10 * pi / 7) == cot(3 * pi / 7)
    assert cot(11 * pi / 7) == -cot(3 * pi / 7)
    assert cot(-11 * pi / 7) == cot(3 * pi / 7)
Exemplo n.º 18
0
def test_hyperbolic_simp():
    x, y = symbols('x,y')

    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 + S(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)

    for a in (pi/6*I, pi/4*I, pi/3*I):
        assert trigsimp(sinh(a)*cosh(x) + cosh(a)*sinh(x)) == sinh(x + a)
        assert trigsimp(-sinh(a)*cosh(x) + cosh(a)*sinh(x)) == sinh(x - a)

    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
Exemplo n.º 19
0
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)
Exemplo n.º 20
0
def test_hyperbolic_simp():
    x, y = symbols('x,y')

    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 + S(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
Exemplo n.º 21
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).n() == sin(x).rewrite(exp).subs(x, sinh(3)).n()
    assert sin(cosh(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(x, cosh(3)).n()
    assert sin(tanh(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(x, tanh(3)).n()
    assert sin(coth(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(x, coth(3)).n()
    assert sin(sin(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(x, sin(3)).n()
    assert sin(cos(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(x, cos(3)).n()
    assert sin(tan(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(x, tan(3)).n()
    assert sin(cot(x)).rewrite(exp).subs(x, 3).n() == sin(x).rewrite(exp).subs(x, cot(3)).n()
    assert sin(log(x)).rewrite(Pow) == I * x ** -I / 2 - I * x ** I / 2
Exemplo n.º 22
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).n() == cos(x).rewrite(exp).subs(x, sinh(3)).n()
    assert cos(cosh(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(x, cosh(3)).n()
    assert cos(tanh(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(x, tanh(3)).n()
    assert cos(coth(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(x, coth(3)).n()
    assert cos(sin(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(x, sin(3)).n()
    assert cos(cos(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(x, cos(3)).n()
    assert cos(tan(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(x, tan(3)).n()
    assert cos(cot(x)).rewrite(exp).subs(x, 3).n() == cos(x).rewrite(exp).subs(x, cot(3)).n()
    assert cos(log(x)).rewrite(Pow) == x ** I / 2 + x ** -I / 2
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)
Exemplo n.º 24
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)
Exemplo n.º 25
0
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)))
Exemplo n.º 26
0
def test_cot_rewrite():
    x = Symbol('x')
    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 + S.Pi/2)
    assert cot(x).rewrite(tan) == 1/tan(x)
    assert cot(sinh(x)).rewrite(exp).subs(x, 3).n() == cot(x).rewrite(exp).subs(x, sinh(3)).n()
    assert cot(cosh(x)).rewrite(exp).subs(x, 3).n() == cot(x).rewrite(exp).subs(x, cosh(3)).n()
    assert cot(tanh(x)).rewrite(exp).subs(x, 3).n() == cot(x).rewrite(exp).subs(x, tanh(3)).n()
    assert cot(coth(x)).rewrite(exp).subs(x, 3).n() == cot(x).rewrite(exp).subs(x, coth(3)).n()
    assert cot(sin(x)).rewrite(exp).subs(x, 3).n() == cot(x).rewrite(exp).subs(x, sin(3)).n()
    assert cot(tan(x)).rewrite(exp).subs(x, 3).n() == cot(x).rewrite(exp).subs(x, tan(3)).n()
    assert cot(log(x)).rewrite(Pow) == -I*(x**-I + x**I)/(x**-I - x**I)
Exemplo n.º 27
0
def test_cot():
    assert cot(nan) == nan

    assert cot.nargs == FiniteSet(1)
    assert cot(oo*I) == -I
    assert cot(-oo*I) == I

    assert cot(0) == zoo
    assert cot(2*pi) == zoo

    assert cot(acot(x)) == x
    assert cot(atan(x)) == 1 / x
    assert cot(asin(x)) == sqrt(1 - x**2) / x
    assert cot(acos(x)) == x / sqrt(1 - x**2)
    assert cot(atan2(y, x)) == x/y

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

    assert cot(pi) == cot(2*pi) == cot(3*pi)
    assert cot(-pi) == cot(-2*pi) == cot(-3*pi)

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

    assert cot(pi/3) == 1/sqrt(3)
    assert cot(-2*pi/3) == 1/sqrt(3)

    assert cot(pi/4) == S.One
    assert cot(-pi/4) == -S.One
    assert cot(17*pi/4) == S.One
    assert cot(-3*pi/4) == S.One

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

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

    assert cot(r).is_real is True

    assert cot(10*pi/7) == cot(3*pi/7)
    assert cot(11*pi/7) == -cot(3*pi/7)
    assert cot(-11*pi/7) == cot(3*pi/7)
Exemplo n.º 28
0
def test_cot():
    assert cot(nan) == nan

    assert cot.nargs == FiniteSet(1)
    assert cot(oo*I) == -I
    assert cot(-oo*I) == I

    assert cot(0) == zoo
    assert cot(2*pi) == zoo

    assert cot(acot(x)) == x
    assert cot(atan(x)) == 1 / x
    assert cot(asin(x)) == sqrt(1 - x**2) / x
    assert cot(acos(x)) == x / sqrt(1 - x**2)
    assert cot(atan2(y, x)) == x/y

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

    assert cot(pi) == cot(2*pi) == cot(3*pi)
    assert cot(-pi) == cot(-2*pi) == cot(-3*pi)

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

    assert cot(pi/3) == 1/sqrt(3)
    assert cot(-2*pi/3) == 1/sqrt(3)

    assert cot(pi/4) == S.One
    assert cot(-pi/4) == -S.One
    assert cot(17*pi/4) == S.One
    assert cot(-3*pi/4) == S.One

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

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

    assert cot(r).is_real is True

    assert cot(10*pi/7) == cot(3*pi/7)
    assert cot(11*pi/7) == -cot(3*pi/7)
    assert cot(-11*pi/7) == cot(3*pi/7)
Exemplo n.º 29
0
def test_sign_assumptions():
    p = Symbol('p', positive=True)
    n = Symbol('n', negative=True)
    assert sinh(n).is_negative is True
    assert sinh(p).is_positive is True
    assert cosh(n).is_positive is True
    assert cosh(p).is_positive is True
    assert tanh(n).is_negative is True
    assert tanh(p).is_positive is True
    assert csch(n).is_negative is True
    assert csch(p).is_positive is True
    assert sech(n).is_positive is True
    assert sech(p).is_positive is True
    assert coth(n).is_negative is True
    assert coth(p).is_positive is True
Exemplo n.º 30
0
def test_sign_assumptions():
    p = Symbol('p', positive=True)
    n = Symbol('n', negative=True)
    assert sinh(n).is_negative is True
    assert sinh(p).is_positive is True
    assert cosh(n).is_positive is True
    assert cosh(p).is_positive is True
    assert tanh(n).is_negative is True
    assert tanh(p).is_positive is True
    assert csch(n).is_negative is True
    assert csch(p).is_positive is True
    assert sech(n).is_positive is True
    assert sech(p).is_positive is True
    assert coth(n).is_negative is True
    assert coth(p).is_positive is True
def FJC(F):
    EEDss = []
    for Fext in force:
        x = Lss * (coth(Fext * b / 4.1) - 4.1 / (Fext * b)) * (1 + Fext / Sss)
        EEDss.append(x)
    EEDss = np.array(EEDss)
    return (EEDss)
Exemplo n.º 32
0
def test_complex():
    a, b = symbols("a,b", 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
        )
Exemplo n.º 33
0
def test_hyper_as_trig():
    from sympy.simplify.fu import _osborne, _osbornei

    eq = sinh(x)**2 + cosh(x)**2
    t, f = hyper_as_trig(eq)
    assert f(fu(t)) == cosh(2 * x)
    assert _osborne(cosh(x)) == cos(x)
    assert _osborne(sinh(x)) == I * sin(x)
    assert _osborne(tanh(x)) == I * tan(x)
    assert _osborne(coth(x)) == cot(x) / I
    assert _osbornei(cos(x)) == cosh(x)
    assert _osbornei(sin(x)) == sinh(x) / I
    assert _osbornei(tan(x)) == tanh(x) / I
    assert _osbornei(cot(x)) == coth(x) * I
    assert _osbornei(sec(x)) == 1 / cosh(x)
    assert _osbornei(csc(x)) == I / sinh(x)
Exemplo n.º 34
0
def test_hyper_as_trig():
    from sympy.simplify.fu import _osborne, _osbornei

    eq = sinh(x)**2 + cosh(x)**2
    t, f = hyper_as_trig(eq)
    assert f(fu(t)) == cosh(2*x)
    assert _osborne(cosh(x)) == cos(x)
    assert _osborne(sinh(x)) == I*sin(x)
    assert _osborne(tanh(x)) == I*tan(x)
    assert _osborne(coth(x)) == cot(x)/I
    assert _osbornei(cos(x)) == cosh(x)
    assert _osbornei(sin(x)) == sinh(x)/I
    assert _osbornei(tan(x)) == tanh(x)/I
    assert _osbornei(cot(x)) == coth(x)*I
    assert _osbornei(sec(x)) == 1/cosh(x)
    assert _osbornei(csc(x)) == I/sinh(x)
    def test_trig_functions(self, printer, x):
        # Trig functions
        assert printer.doprint(sp.acos(x)) == 'acos(x)'
        assert printer.doprint(sp.acosh(x)) == 'acosh(x)'
        assert printer.doprint(sp.asin(x)) == 'asin(x)'
        assert printer.doprint(sp.asinh(x)) == 'asinh(x)'
        assert printer.doprint(sp.atan(x)) == 'atan(x)'
        assert printer.doprint(sp.atanh(x)) == 'atanh(x)'
        assert printer.doprint(sp.ceiling(x)) == 'ceil(x)'
        assert printer.doprint(sp.cos(x)) == 'cos(x)'
        assert printer.doprint(sp.cosh(x)) == 'cosh(x)'
        assert printer.doprint(sp.exp(x)) == 'exp(x)'
        assert printer.doprint(sp.factorial(x)) == 'factorial(x)'
        assert printer.doprint(sp.floor(x)) == 'floor(x)'
        assert printer.doprint(sp.log(x)) == 'log(x)'
        assert printer.doprint(sp.sin(x)) == 'sin(x)'
        assert printer.doprint(sp.sinh(x)) == 'sinh(x)'
        assert printer.doprint(sp.tan(x)) == 'tan(x)'
        assert printer.doprint(sp.tanh(x)) == 'tanh(x)'

        # extra trig functions
        assert printer.doprint(sp.sec(x)) == '1 / cos(x)'
        assert printer.doprint(sp.csc(x)) == '1 / sin(x)'
        assert printer.doprint(sp.cot(x)) == '1 / tan(x)'
        assert printer.doprint(sp.asec(x)) == 'acos(1 / x)'
        assert printer.doprint(sp.acsc(x)) == 'asin(1 / x)'
        assert printer.doprint(sp.acot(x)) == 'atan(1 / x)'
        assert printer.doprint(sp.sech(x)) == '1 / cosh(x)'
        assert printer.doprint(sp.csch(x)) == '1 / sinh(x)'
        assert printer.doprint(sp.coth(x)) == '1 / tanh(x)'
        assert printer.doprint(sp.asech(x)) == 'acosh(1 / x)'
        assert printer.doprint(sp.acsch(x)) == 'asinh(1 / x)'
        assert printer.doprint(sp.acoth(x)) == 'atanh(1 / x)'
Exemplo n.º 36
0
def test_tan_rewrite():
    x = Symbol('x')
    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 + S.Pi/2)/cos(x)
    assert tan(x).rewrite(cot) == 1/cot(x)
    assert tan(sinh(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, sinh(3)).n()
    assert tan(cosh(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, cosh(3)).n()
    assert tan(tanh(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, tanh(3)).n()
    assert tan(coth(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, coth(3)).n()
    assert tan(sin(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, sin(3)).n()
    assert tan(cos(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, cos(3)).n()
    assert tan(tan(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, tan(3)).n()
    assert tan(cot(x)).rewrite(exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, cot(3)).n()
    assert tan(log(x)).rewrite(Pow) == I*(x**-I - x**I)/(x**-I + x**I)
Exemplo n.º 37
0
def test_cosh_rewrite():
    x = Symbol('x')
    assert cosh(x).rewrite(exp) == (exp(x)+exp(-x))/2
    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)
Exemplo n.º 38
0
def test_real_assumptions():
    z = Symbol('z', real=False)
    assert sinh(z).is_real is None
    assert cosh(z).is_real is None
    assert tanh(z).is_real is None
    assert sech(z).is_real is None
    assert csch(z).is_real is None
    assert coth(z).is_real is None
Exemplo n.º 39
0
def test_sech_rewrite():
    x = Symbol("x")
    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)
Exemplo n.º 40
0
def test_real_assumptions():
    z = Symbol('z', real=False)
    assert sinh(z).is_real is None
    assert cosh(z).is_real is None
    assert tanh(z).is_real is None
    assert sech(z).is_real is None
    assert csch(z).is_real is None
    assert coth(z).is_real is None
Exemplo n.º 41
0
def test_sinh_rewrite():
    x = Symbol('x')
    assert sinh(x).rewrite(exp) == (exp(x)-exp(-x))/2
    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)
Exemplo n.º 42
0
def test_cosh_rewrite():
    x = Symbol('x')
    assert cosh(x).rewrite(exp) == (exp(x) + exp(-x)) / 2
    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)
Exemplo n.º 43
0
def test_hyperbolic_simp():
    x, y = symbols('x,y')

    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) == coth(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) in \
                [2 + 3*cosh(x/2)**2, 5 + 3*sinh(x/2)**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), deep=True) == 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
Exemplo n.º 44
0
def test_sinh_rewrite():
    x = Symbol('x')
    assert sinh(x).rewrite(exp) == (exp(x) - exp(-x)) / 2
    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)
Exemplo n.º 45
0
def test_csch_rewrite():
    x = Symbol("x")
    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)
Exemplo n.º 46
0
def test_hyperbolic_simp():
    x, y = symbols('x,y')

    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) == coth(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) in \
                [2 + 3*cosh(x/2)**2, 5 + 3*sinh(x/2)**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), deep=True) == 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
Exemplo n.º 47
0
def test_sech_rewrite():
    x = Symbol('x')
    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)
Exemplo n.º 48
0
def test_csch_rewrite():
    x = Symbol('x')
    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)
Exemplo n.º 49
0
def test_latex_functions():
    assert latex(exp(x)) == "e^{x}"
    assert latex(exp(1) + exp(2)) == "e + e^{2}"

    f = Function('f')
    assert latex(f(x)) == '\\operatorname{f}{\\left (x \\right )}'

    beta = Function('beta')

    assert latex(beta(x)) == r"\beta{\left (x \right )}"
    assert latex(sin(x)) == r"\sin{\left (x \right )}"
    assert latex(sin(x), fold_func_brackets=True) == r"\sin {x}"
    assert latex(sin(2*x**2), fold_func_brackets=True) == \
    r"\sin {2 x^{2}}"
    assert latex(sin(x**2), fold_func_brackets=True) == \
    r"\sin {x^{2}}"

    assert latex(asin(x)**2) == r"\operatorname{asin}^{2}{\left (x \right )}"
    assert latex(asin(x)**2,inv_trig_style="full") == \
        r"\arcsin^{2}{\left (x \right )}"
    assert latex(asin(x)**2,inv_trig_style="power") == \
        r"\sin^{-1}{\left (x \right )}^{2}"
    assert latex(asin(x**2),inv_trig_style="power",fold_func_brackets=True) == \
        r"\sin^{-1} {x^{2}}"

    assert latex(factorial(k)) == r"k!"
    assert latex(factorial(-k)) == r"\left(- k\right)!"

    assert latex(factorial2(k)) == r"k!!"
    assert latex(factorial2(-k)) == r"\left(- k\right)!!"

    assert latex(binomial(2, k)) == r"{\binom{2}{k}}"

    assert latex(FallingFactorial(3,
                                  k)) == r"{\left(3\right)}_{\left(k\right)}"
    assert latex(RisingFactorial(3, k)) == r"{\left(3\right)}^{\left(k\right)}"

    assert latex(floor(x)) == r"\lfloor{x}\rfloor"
    assert latex(ceiling(x)) == r"\lceil{x}\rceil"
    assert latex(Abs(x)) == r"\lvert{x}\rvert"
    assert latex(re(x)) == r"\Re{x}"
    assert latex(re(x + y)) == r"\Re {\left (x + y \right )}"
    assert latex(im(x)) == r"\Im{x}"
    assert latex(conjugate(x)) == r"\overline{x}"
    assert latex(gamma(x)) == r"\Gamma\left(x\right)"
    assert latex(Order(x)) == r"\mathcal{O}\left(x\right)"
    assert latex(lowergamma(x, y)) == r'\gamma\left(x, y\right)'
    assert latex(uppergamma(x, y)) == r'\Gamma\left(x, y\right)'

    assert latex(cot(x)) == r'\cot{\left (x \right )}'
    assert latex(coth(x)) == r'\coth{\left (x \right )}'
    assert latex(re(x)) == r'\Re{x}'
    assert latex(im(x)) == r'\Im{x}'
    assert latex(root(x, y)) == r'x^{\frac{1}{y}}'
    assert latex(arg(x)) == r'\arg{\left (x \right )}'
    assert latex(zeta(x)) == r'\zeta{\left (x \right )}'
Exemplo n.º 50
0
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
Exemplo n.º 51
0
def test_complex():
    a,b = symbols('a,b', real=True)
    z = a + b*I
    for func in [sinh, cosh, tanh, coth]:
        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)
Exemplo n.º 52
0
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)
Exemplo n.º 53
0
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
Exemplo n.º 54
0
def test_latex_functions():
    assert latex(exp(x)) == "e^{x}"
    assert latex(exp(1)+exp(2)) == "e + e^{2}"

    f = Function('f')
    assert latex(f(x)) == '\\operatorname{f}{\\left (x \\right )}'

    beta = Function('beta')

    assert latex(beta(x)) == r"\beta{\left (x \right )}"
    assert latex(sin(x)) == r"\sin{\left (x \right )}"
    assert latex(sin(x), fold_func_brackets=True) == r"\sin {x}"
    assert latex(sin(2*x**2), fold_func_brackets=True) == \
    r"\sin {2 x^{2}}"
    assert latex(sin(x**2), fold_func_brackets=True) == \
    r"\sin {x^{2}}"

    assert latex(asin(x)**2) == r"\operatorname{asin}^{2}{\left (x \right )}"
    assert latex(asin(x)**2,inv_trig_style="full") == \
        r"\arcsin^{2}{\left (x \right )}"
    assert latex(asin(x)**2,inv_trig_style="power") == \
        r"\sin^{-1}{\left (x \right )}^{2}"
    assert latex(asin(x**2),inv_trig_style="power",fold_func_brackets=True) == \
        r"\sin^{-1} {x^{2}}"

    assert latex(factorial(k)) == r"k!"
    assert latex(factorial(-k)) == r"\left(- k\right)!"

    assert latex(factorial2(k)) == r"k!!"
    assert latex(factorial2(-k)) == r"\left(- k\right)!!"

    assert latex(binomial(2,k)) == r"{\binom{2}{k}}"

    assert latex(FallingFactorial(3,k)) == r"{\left(3\right)}_{\left(k\right)}"
    assert latex(RisingFactorial(3,k)) == r"{\left(3\right)}^{\left(k\right)}"

    assert latex(floor(x)) == r"\lfloor{x}\rfloor"
    assert latex(ceiling(x)) == r"\lceil{x}\rceil"
    assert latex(Abs(x)) == r"\lvert{x}\rvert"
    assert latex(re(x)) == r"\Re{x}"
    assert latex(re(x+y)) == r"\Re {\left (x + y \right )}"
    assert latex(im(x)) == r"\Im{x}"
    assert latex(conjugate(x)) == r"\overline{x}"
    assert latex(gamma(x)) == r"\Gamma\left(x\right)"
    assert latex(Order(x)) == r"\mathcal{O}\left(x\right)"
    assert latex(lowergamma(x, y)) == r'\gamma\left(x, y\right)'
    assert latex(uppergamma(x, y)) == r'\Gamma\left(x, y\right)'

    assert latex(cot(x)) == r'\cot{\left (x \right )}'
    assert latex(coth(x)) == r'\coth{\left (x \right )}'
    assert latex(re(x)) == r'\Re{x}'
    assert latex(im(x)) == r'\Im{x}'
    assert latex(root(x,y)) == r'x^{\frac{1}{y}}'
    assert latex(arg(x)) == r'\arg{\left (x \right )}'
    assert latex(zeta(x)) == r'\zeta{\left (x \right )}'
Exemplo n.º 55
0
def test_conjugate():
    a = Symbol("a", real=True)
    b = Symbol("b", real=True)
    x = Symbol("x")
    z = a + I * b
    zc = a - I * b
    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(x)) == sign(x)
    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)
Exemplo n.º 56
0
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)
Exemplo n.º 57
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
Exemplo n.º 58
0
def test_conjugate():
    a = Symbol("a", real=True)
    b = Symbol("b", 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)