Esempio n. 1
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
Esempio n. 2
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. 3
0
def test_csch():
    x, y = symbols('x,y')

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

    assert csch(nan) is nan
    assert csch(zoo) is nan

    assert csch(oo) == 0
    assert csch(-oo) == 0

    assert csch(0) is zoo

    assert csch(-1) == -csch(1)

    assert csch(-x) == -csch(x)
    assert csch(-pi) == -csch(pi)
    assert csch(-2**1024 * E) == -csch(2**1024 * E)

    assert csch(pi * I) is zoo
    assert csch(-pi * I) is zoo
    assert csch(2 * pi * I) is zoo
    assert csch(-2 * pi * I) is zoo
    assert csch(-3 * 10**73 * pi * I) is zoo
    assert csch(7 * 10**103 * pi * I) is zoo

    assert csch(pi * I / 2) == -I
    assert csch(-pi * I / 2) == I
    assert csch(pi * I * Rational(5, 2)) == -I
    assert csch(pi * I * Rational(7, 2)) == I

    assert csch(pi * I / 3) == -2 / sqrt(3) * I
    assert csch(pi * I * Rational(-2, 3)) == 2 / sqrt(3) * I

    assert csch(pi * I / 4) == -sqrt(2) * I
    assert csch(-pi * I / 4) == sqrt(2) * I
    assert csch(pi * I * Rational(7, 4)) == sqrt(2) * I
    assert csch(pi * I * Rational(-3, 4)) == sqrt(2) * I

    assert csch(pi * I / 6) == -2 * I
    assert csch(-pi * I / 6) == 2 * I
    assert csch(pi * I * Rational(7, 6)) == 2 * I
    assert csch(pi * I * Rational(-7, 6)) == -2 * I
    assert csch(pi * I * Rational(-5, 6)) == 2 * I

    assert csch(pi * I / 105) == -1 / sin(pi / 105) * I
    assert csch(-pi * I / 105) == 1 / sin(pi / 105) * I

    assert csch(x * I) == -1 / sin(x) * I

    assert csch(k * pi * I) is zoo
    assert csch(17 * k * pi * I) is zoo

    assert csch(k * pi * I / 2) == -1 / sin(k * pi / 2) * I

    assert csch(n).is_real is True

    assert expand_trig(csch(x +
                            y)) == 1 / (sinh(x) * cosh(y) + cosh(x) * sinh(y))
Esempio n. 4
0
def test_manualintegrate_trigonometry():
    assert manualintegrate(sin(x), x) == -cos(x)
    assert manualintegrate(tan(x), x) == -log(cos(x))

    assert manualintegrate(sec(x), x) == log(sec(x) + tan(x))
    assert manualintegrate(csc(x), x) == -log(csc(x) + cot(x))

    assert manualintegrate(sin(x) * cos(x),
                           x) in [sin(x)**2 / 2, -cos(x)**2 / 2]
    assert manualintegrate(-sec(x) * tan(x), x) == -sec(x)
    assert manualintegrate(csc(x) * cot(x), x) == -csc(x)
    assert manualintegrate(sec(x)**2, x) == tan(x)
    assert manualintegrate(csc(x)**2, x) == -cot(x)

    assert manualintegrate(x * sec(x**2), x) == log(tan(x**2) + sec(x**2)) / 2
    assert manualintegrate(cos(x) * csc(sin(x)),
                           x) == -log(cot(sin(x)) + csc(sin(x)))
    assert manualintegrate(cos(3 * x) * sec(x), x) == -x + sin(2 * x)
    assert manualintegrate(sin(3*x)*sec(x), x) == \
        -3*log(cos(x)) + 2*log(cos(x)**2) - 2*cos(x)**2

    assert_is_integral_of(sinh(2 * x), cosh(2 * x) / 2)
    assert_is_integral_of(x * cosh(x**2), sinh(x**2) / 2)
    assert_is_integral_of(tanh(x), log(cosh(x)))
    assert_is_integral_of(coth(x), log(sinh(x)))
    f, F = sech(x), 2 * atan(tanh(x / 2))
    assert manualintegrate(f, x) == F
    assert (F.diff(x) -
            f).rewrite(exp).simplify() == 0  # todo: equals returns None
    f, F = csch(x), log(tanh(x / 2))
    assert manualintegrate(f, x) == F
    assert (F.diff(x) - f).rewrite(exp).simplify() == 0
Esempio n. 5
0
def test_issue_17450():
    assert (erf(cosh(1)**7)**I).is_real is None
    assert (erf(cosh(1)**7)**I).is_imaginary is False
    assert (Pow(exp(1 + sqrt(2)),
                ((1 - sqrt(2)) * I * pi), evaluate=False)).is_real is None
    assert ((-10)**(10 * I * pi / 3)).is_real is False
    assert ((-5)**(4 * I * pi)).is_real is False
Esempio n. 6
0
def test_ode_solutions():
    # only a few examples here, the rest will be tested in the actual dsolve tests
    assert constant_renumber(constantsimp(C1*exp(2*x) + exp(x)*(C2 + C3), [C1, C2, C3])) == \
        constant_renumber(C1*exp(x) + C2*exp(2*x))
    assert constant_renumber(
        constantsimp(Eq(f(x),
                        I * C1 * sinh(x / 3) + C2 * cosh(x / 3)),
                     [C1, C2])) == constant_renumber(
                         Eq(f(x),
                            C1 * sinh(x / 3) + C2 * cosh(x / 3)))
    assert constant_renumber(constantsimp(Eq(f(x), acos((-C1)/cos(x))), [C1])) == \
        Eq(f(x), acos(C1/cos(x)))
    assert constant_renumber(
        constantsimp(Eq(log(f(x) / C1) + 2 * exp(x / f(x)), 0),
                     [C1])) == Eq(log(C1 * f(x)) + 2 * exp(x / f(x)), 0)
    assert constant_renumber(constantsimp(Eq(log(x*sqrt(2)*sqrt(1/x)*sqrt(f(x))
        /C1) + x**2/(2*f(x)**2), 0), [C1])) == \
        Eq(log(C1*sqrt(x)*sqrt(f(x))) + x**2/(2*f(x)**2), 0)
    assert constant_renumber(constantsimp(Eq(-exp(-f(x)/x)*sin(f(x)/x)/2 + log(x/C1) -
        cos(f(x)/x)*exp(-f(x)/x)/2, 0), [C1])) == \
        Eq(-exp(-f(x)/x)*sin(f(x)/x)/2 + log(C1*x) - cos(f(x)/x)*
           exp(-f(x)/x)/2, 0)
    assert constant_renumber(constantsimp(Eq(-Integral(-1/(sqrt(1 - u2**2)*u2),
        (u2, _a, x/f(x))) + log(f(x)/C1), 0), [C1])) == \
        Eq(-Integral(-1/(u2*sqrt(1 - u2**2)), (u2, _a, x/f(x))) +
        log(C1*f(x)), 0)
    assert [constantsimp(i, [C1]) for i in [Eq(f(x), sqrt(-C1*x + x**2)), Eq(f(x), -sqrt(-C1*x + x**2))]] == \
        [Eq(f(x), sqrt(x*(C1 + x))), Eq(f(x), -sqrt(x*(C1 + x)))]
Esempio n. 7
0
def test_manualintegrate_special():
    f, F = 4*exp(-x**2/3), 2*sqrt(3)*sqrt(pi)*erf(sqrt(3)*x/3)
    assert_is_integral_of(f, F)
    f, F = 3*exp(4*x**2), 3*sqrt(pi)*erfi(2*x)/4
    assert_is_integral_of(f, F)
    f, F = x**Rational(1, 3)*exp(-x/8), -16*uppergamma(Rational(4, 3), x/8)
    assert_is_integral_of(f, F)
    f, F = exp(2*x)/x, Ei(2*x)
    assert_is_integral_of(f, F)
    f, F = exp(1 + 2*x - x**2), sqrt(pi)*exp(2)*erf(x - 1)/2
    assert_is_integral_of(f, F)
    f = sin(x**2 + 4*x + 1)
    F = (sqrt(2)*sqrt(pi)*(-sin(3)*fresnelc(sqrt(2)*(2*x + 4)/(2*sqrt(pi))) +
        cos(3)*fresnels(sqrt(2)*(2*x + 4)/(2*sqrt(pi))))/2)
    assert_is_integral_of(f, F)
    f, F = cos(4*x**2), sqrt(2)*sqrt(pi)*fresnelc(2*sqrt(2)*x/sqrt(pi))/4
    assert_is_integral_of(f, F)
    f, F = sin(3*x + 2)/x, sin(2)*Ci(3*x) + cos(2)*Si(3*x)
    assert_is_integral_of(f, F)
    f, F = sinh(3*x - 2)/x, -sinh(2)*Chi(3*x) + cosh(2)*Shi(3*x)
    assert_is_integral_of(f, F)
    f, F = 5*cos(2*x - 3)/x, 5*cos(3)*Ci(2*x) + 5*sin(3)*Si(2*x)
    assert_is_integral_of(f, F)
    f, F = cosh(x/2)/x, Chi(x/2)
    assert_is_integral_of(f, F)
    f, F = cos(x**2)/x, Ci(x**2)/2
    assert_is_integral_of(f, F)
    f, F = 1/log(2*x + 1), li(2*x + 1)/2
    assert_is_integral_of(f, F)
    f, F = polylog(2, 5*x)/x, polylog(3, 5*x)
    assert_is_integral_of(f, F)
    f, F = 5/sqrt(3 - 2*sin(x)**2), 5*sqrt(3)*elliptic_f(x, Rational(2, 3))/3
    assert_is_integral_of(f, F)
    f, F = sqrt(4 + 9*sin(x)**2), 2*elliptic_e(x, Rational(-9, 4))
    assert_is_integral_of(f, F)
Esempio n. 8
0
def test_sinh_expansion():
    x, y = symbols('x,y')
    assert sinh(x +
                y).expand(trig=True) == sinh(x) * cosh(y) + cosh(x) * sinh(y)
    assert sinh(2 * x).expand(trig=True) == 2 * sinh(x) * cosh(x)
    assert sinh(3*x).expand(trig=True).expand() == \
        sinh(x)**3 + 3*sinh(x)*cosh(x)**2
Esempio n. 9
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)
    e, f = hyper_as_trig(tanh(x + y))
    assert f(TR12(e)) == (tanh(x) + tanh(y)) / (tanh(x) * tanh(y) + 1)

    d = Dummy()
    assert _osborne(sinh(x), d) == I * sin(x * d)
    assert _osborne(tanh(x), d) == I * tan(x * d)
    assert _osborne(coth(x), d) == cot(x * d) / I
    assert _osborne(cosh(x), d) == cos(x * d)
    assert _osborne(sech(x), d) == sec(x * d)
    assert _osborne(csch(x), d) == csc(x * d) / I
    for func in (sinh, cosh, tanh, coth, sech, csch):
        h = func(pi)
        assert _osbornei(_osborne(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 _osbornei(cos(x * y + z), y) == cosh(x + z * I)
    assert _osbornei(sin(x * y + z), y) == sinh(x + z * I) / I
    assert _osbornei(tan(x * y + z), y) == tanh(x + z * I) / I
    assert _osbornei(cot(x * y + z), y) == coth(x + z * I) * I
    assert _osbornei(sec(x * y + z), y) == sech(x + z * I)
    assert _osbornei(csc(x * y + z), y) == csch(x + z * I) * I
Esempio n. 10
0
def test_expint():
    """ Test various exponential integrals. """
    from sympy.core.symbol import Symbol
    from sympy.functions.elementary.complexes import unpolarify
    from sympy.functions.elementary.hyperbolic import sinh
    from sympy.functions.special.error_functions import (Chi, Ci, Ei, Shi, Si,
                                                         expint)
    assert simplify(
        unpolarify(
            integrate(exp(-z * x) / x**y, (x, 1, oo),
                      meijerg=True,
                      conds='none').rewrite(expint).expand(
                          func=True))) == expint(y, z)

    assert integrate(exp(-z*x)/x, (x, 1, oo), meijerg=True,
                     conds='none').rewrite(expint).expand() == \
        expint(1, z)
    assert integrate(exp(-z*x)/x**2, (x, 1, oo), meijerg=True,
                     conds='none').rewrite(expint).expand() == \
        expint(2, z).rewrite(Ei).rewrite(expint)
    assert integrate(exp(-z*x)/x**3, (x, 1, oo), meijerg=True,
                     conds='none').rewrite(expint).expand() == \
        expint(3, z).rewrite(Ei).rewrite(expint).expand()

    t = Symbol('t', positive=True)
    assert integrate(-cos(x) / x, (x, t, oo), meijerg=True).expand() == Ci(t)
    assert integrate(-sin(x)/x, (x, t, oo), meijerg=True).expand() == \
        Si(t) - pi/2
    assert integrate(sin(x) / x, (x, 0, z), meijerg=True) == Si(z)
    assert integrate(sinh(x) / x, (x, 0, z), meijerg=True) == Shi(z)
    assert integrate(exp(-x)/x, x, meijerg=True).expand().rewrite(expint) == \
        I*pi - expint(1, x)
    assert integrate(exp(-x)/x**2, x, meijerg=True).rewrite(expint).expand() \
        == expint(1, x) - exp(-x)/x - I*pi

    u = Symbol('u', polar=True)
    assert integrate(cos(u)/u, u, meijerg=True).expand().as_independent(u)[1] \
        == Ci(u)
    assert integrate(cosh(u)/u, u, meijerg=True).expand().as_independent(u)[1] \
        == Chi(u)

    assert integrate(
        expint(1, x), x,
        meijerg=True).rewrite(expint).expand() == x * expint(1, x) - exp(-x)
    assert integrate(expint(2, x), x, meijerg=True
            ).rewrite(expint).expand() == \
        -x**2*expint(1, x)/2 + x*exp(-x)/2 - exp(-x)/2
    assert simplify(unpolarify(integrate(expint(y, x), x,
                 meijerg=True).rewrite(expint).expand(func=True))) == \
        -expint(y + 1, x)

    assert integrate(Si(x), x, meijerg=True) == x * Si(x) + cos(x)
    assert integrate(Ci(u), u, meijerg=True).expand() == u * Ci(u) - sin(u)
    assert integrate(Shi(x), x, meijerg=True) == x * Shi(x) - cosh(x)
    assert integrate(Chi(u), u, meijerg=True).expand() == u * Chi(u) - sinh(u)

    assert integrate(Si(x) * exp(-x), (x, 0, oo), meijerg=True) == pi / 4
    assert integrate(expint(1, x) * sin(x), (x, 0, oo),
                     meijerg=True) == log(2) / 2
Esempio n. 11
0
def test_cosh_rewrite():
    x = Symbol('x')
    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. 12
0
def test_cosh_nonnegative():
    k = symbols('k', real=True)
    n = symbols('n', integer=True)

    assert cosh(k, evaluate=False).is_nonnegative is True
    assert cosh(k + 2 * n * pi * I, evaluate=False).is_nonnegative is True
    assert cosh(I * pi / 4, evaluate=False).is_nonnegative is True
    assert cosh(3 * I * pi / 4, evaluate=False).is_nonnegative is False
    assert cosh(S.Zero, evaluate=False).is_nonnegative is True
Esempio n. 13
0
def test_sech():
    x, y = symbols('x, y')

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

    assert sech(nan) is nan
    assert sech(zoo) is nan

    assert sech(oo) == 0
    assert sech(-oo) == 0

    assert sech(0) == 1

    assert sech(-1) == sech(1)
    assert sech(-x) == sech(x)

    assert sech(pi * I) == sec(pi)

    assert sech(-pi * I) == sec(pi)
    assert sech(-2**1024 * E) == sech(2**1024 * E)

    assert sech(pi * I / 2) is zoo
    assert sech(-pi * I / 2) is zoo
    assert sech((-3 * 10**73 + 1) * pi * I / 2) is zoo
    assert sech((7 * 10**103 + 1) * pi * I / 2) is zoo

    assert sech(pi * I) == -1
    assert sech(-pi * I) == -1
    assert sech(5 * pi * I) == -1
    assert sech(8 * pi * I) == 1

    assert sech(pi * I / 3) == 2
    assert sech(pi * I * Rational(-2, 3)) == -2

    assert sech(pi * I / 4) == sqrt(2)
    assert sech(-pi * I / 4) == sqrt(2)
    assert sech(pi * I * Rational(5, 4)) == -sqrt(2)
    assert sech(pi * I * Rational(-5, 4)) == -sqrt(2)

    assert sech(pi * I / 6) == 2 / sqrt(3)
    assert sech(-pi * I / 6) == 2 / sqrt(3)
    assert sech(pi * I * Rational(7, 6)) == -2 / sqrt(3)
    assert sech(pi * I * Rational(-5, 6)) == -2 / sqrt(3)

    assert sech(pi * I / 105) == 1 / cos(pi / 105)
    assert sech(-pi * I / 105) == 1 / cos(pi / 105)

    assert sech(x * I) == 1 / cos(x)

    assert sech(k * pi * I) == 1 / cos(k * pi)
    assert sech(17 * k * pi * I) == 1 / cos(17 * k * pi)

    assert sech(n).is_real is True

    assert expand_trig(sech(x +
                            y)) == 1 / (cosh(x) * cosh(y) + sinh(x) * sinh(y))
Esempio n. 14
0
def test_heurisch_hyperbolic():
    assert heurisch(sinh(x), x) == cosh(x)
    assert heurisch(cosh(x), x) == sinh(x)

    assert heurisch(x * sinh(x), x) == x * cosh(x) - sinh(x)
    assert heurisch(x * cosh(x), x) == x * sinh(x) - cosh(x)

    assert heurisch(
        x * asinh(x / 2),
        x) == x**2 * asinh(x / 2) / 2 + asinh(x / 2) - x * sqrt(4 + x**2) / 4
Esempio n. 15
0
def test_cosh_positive():
    # See issue 11721
    # cosh(x) is positive for real values of x
    k = symbols('k', real=True)
    n = symbols('n', integer=True)

    assert cosh(k, evaluate=False).is_positive is True
    assert cosh(k + 2 * n * pi * I, evaluate=False).is_positive is True
    assert cosh(I * pi / 4, evaluate=False).is_positive is True
    assert cosh(3 * I * pi / 4, evaluate=False).is_positive is False
Esempio n. 16
0
def test_gruntz_hyperbolic():
    assert gruntz(cosh(x), x, oo) == oo
    assert gruntz(cosh(x), x, -oo) == oo
    assert gruntz(sinh(x), x, oo) == oo
    assert gruntz(sinh(x), x, -oo) == -oo
    assert gruntz(2*cosh(x)*exp(x), x, oo) == oo
    assert gruntz(2*cosh(x)*exp(x), x, -oo) == 1
    assert gruntz(2*sinh(x)*exp(x), x, oo) == oo
    assert gruntz(2*sinh(x)*exp(x), x, -oo) == -1
    assert gruntz(tanh(x), x, oo) == 1
    assert gruntz(tanh(x), x, -oo) == -1
    assert gruntz(coth(x), x, oo) == 1
    assert gruntz(coth(x), x, -oo) == -1
Esempio n. 17
0
def test_gruntz_hyperbolic():
    assert gruntz(cosh(x), x, oo) is oo
    assert gruntz(cosh(x), x, -oo) is oo
    assert gruntz(sinh(x), x, oo) is oo
    assert gruntz(sinh(x), x, -oo) is -oo
    assert gruntz(2 * cosh(x) * exp(x), x, oo) is oo
    assert gruntz(2 * cosh(x) * exp(x), x, -oo) == 1
    assert gruntz(2 * sinh(x) * exp(x), x, oo) is oo
    assert gruntz(2 * sinh(x) * exp(x), x, -oo) == -1
    assert gruntz(tanh(x), x, oo) == 1
    assert gruntz(tanh(x), x, -oo) == -1
    assert gruntz(coth(x), x, oo) == 1
    assert gruntz(coth(x), x, -oo) == -1
Esempio n. 18
0
def test_cosh_expansion():
    x, y = symbols('x,y')
    assert cosh(x +
                y).expand(trig=True) == cosh(x) * cosh(y) + sinh(x) * sinh(y)
    assert cosh(2 * x).expand(trig=True) == cosh(x)**2 + sinh(x)**2
    assert cosh(3*x).expand(trig=True).expand() == \
        3*sinh(x)**2*cosh(x) + cosh(x)**3
Esempio 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)
    assert asech(x).diff(x) == -1 / (x * sqrt(1 - x**2))
    assert acsch(x).diff(x) == -1 / (x**2 * sqrt(1 + x**(-2)))
Esempio n. 20
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
Esempio n. 21
0
def test_to_expr():
    x = symbols('x')
    R, Dx = DifferentialOperators(ZZ.old_poly_ring(x), 'Dx')
    p = HolonomicFunction(Dx - 1, x, 0, [1]).to_expr()
    q = exp(x)
    assert p == q
    p = HolonomicFunction(Dx**2 + 1, x, 0, [1, 0]).to_expr()
    q = cos(x)
    assert p == q
    p = HolonomicFunction(Dx**2 - 1, x, 0, [1, 0]).to_expr()
    q = cosh(x)
    assert p == q
    p = HolonomicFunction(2 + (4*x - 1)*Dx + \
        (x**2 - x)*Dx**2, x, 0, [1, 2]).to_expr().expand()
    q = 1 / (x**2 - 2 * x + 1)
    assert p == q
    p = expr_to_holonomic(sin(x)**2 / x).integrate((x, 0, x)).to_expr()
    q = (sin(x)**2 / x).integrate((x, 0, x))
    assert p == q
    C_0, C_1, C_2, C_3 = symbols('C_0, C_1, C_2, C_3')
    p = expr_to_holonomic(log(1 + x**2)).to_expr()
    q = C_2 * log(x**2 + 1)
    assert p == q
    p = expr_to_holonomic(log(1 + x**2)).diff().to_expr()
    q = C_0 * x / (x**2 + 1)
    assert p == q
    p = expr_to_holonomic(erf(x) + x).to_expr()
    q = 3 * C_3 * x - 3 * sqrt(pi) * C_3 * erf(x) / 2 + x + 2 * x / sqrt(pi)
    assert p == q
    p = expr_to_holonomic(sqrt(x), x0=1).to_expr()
    assert p == sqrt(x)
    assert expr_to_holonomic(sqrt(x)).to_expr() == sqrt(x)
    p = expr_to_holonomic(sqrt(1 + x**2)).to_expr()
    assert p == sqrt(1 + x**2)
    p = expr_to_holonomic((2 * x**2 + 1)**Rational(2, 3)).to_expr()
    assert p == (2 * x**2 + 1)**Rational(2, 3)
    p = expr_to_holonomic(sqrt(-x**2 + 2 * x)).to_expr()
    assert p == sqrt(x) * sqrt(-x + 2)
    p = expr_to_holonomic((-2 * x**3 + 7 * x)**Rational(2, 3)).to_expr()
    q = x**Rational(2, 3) * (-2 * x**2 + 7)**Rational(2, 3)
    assert p == q
    p = from_hyper(hyper((-2, -3), (S.Half, ), x))
    s = hyperexpand(hyper((-2, -3), (S.Half, ), x))
    D_0 = Symbol('D_0')
    C_0 = Symbol('C_0')
    assert (p.to_expr().subs({C_0: 1, D_0: 0}) - s).simplify() == 0
    p.y0 = {0: [1], S.Half: [0]}
    assert p.to_expr() == s
    assert expr_to_holonomic(x**5).to_expr() == x**5
    assert expr_to_holonomic(2*x**3-3*x**2).to_expr().expand() == \
        2*x**3-3*x**2
    a = symbols("a")
    p = (expr_to_holonomic(1.4 * x) * expr_to_holonomic(a * x, x)).to_expr()
    q = 1.4 * a * x**2
    assert p == q
    p = (expr_to_holonomic(1.4 * x) + expr_to_holonomic(a * x, x)).to_expr()
    q = x * (a + 1.4)
    assert p == q
    p = (expr_to_holonomic(1.4 * x) + expr_to_holonomic(x)).to_expr()
    assert p == 2.4 * x
Esempio n. 22
0
def test_heurisch_trigonometric():
    assert heurisch(sin(x), x) == -cos(x)
    assert heurisch(pi * sin(x) + 1, x) == x - pi * cos(x)

    assert heurisch(cos(x), x) == sin(x)
    assert heurisch(tan(x), x) in [
        log(1 + tan(x)**2) / 2,
        log(tan(x) + I) + I * x,
        log(tan(x) - I) - I * x,
    ]

    assert heurisch(sin(x) * sin(y), x) == -cos(x) * sin(y)
    assert heurisch(sin(x) * sin(y), y) == -cos(y) * sin(x)

    # gives sin(x) in answer when run via setup.py and cos(x) when run via py.test
    assert heurisch(sin(x) * cos(x), x) in [sin(x)**2 / 2, -cos(x)**2 / 2]
    assert heurisch(cos(x) / sin(x), x) == log(sin(x))

    assert heurisch(x * sin(7 * x), x) == sin(7 * x) / 49 - x * cos(7 * x) / 7
    assert heurisch(
        1 / pi / 4 * x**2 * cos(x),
        x) == 1 / pi / 4 * (x**2 * sin(x) - 2 * sin(x) + 2 * x * cos(x))

    assert heurisch(acos(x/4) * asin(x/4), x) == 2*x - (sqrt(16 - x**2))*asin(x/4) \
        + (sqrt(16 - x**2))*acos(x/4) + x*asin(x/4)*acos(x/4)

    assert heurisch(sin(x) / (cos(x)**2 + 1),
                    x) == -atan(cos(x))  #fixes issue 13723
    assert heurisch(1 / (cos(x) + 2),
                    x) == 2 * sqrt(3) * atan(sqrt(3) * tan(x / 2) / 3) / 3
    assert heurisch(
        2 * sin(x) * cos(x) / (sin(x)**4 + 1),
        x) == atan(sqrt(2) * sin(x) - 1) - atan(sqrt(2) * sin(x) + 1)

    assert heurisch(1 / cosh(x), x) == 2 * atan(tanh(x / 2))
Esempio n. 23
0
def test_inverse_laplace_transform():
    from sympy.core.exprtools import factor_terms
    from sympy.functions.special.delta_functions import DiracDelta
    from sympy.simplify.simplify import simplify
    ILT = inverse_laplace_transform
    a, b, c, = symbols('a b c', positive=True)
    t = symbols('t')

    def simp_hyp(expr):
        return factor_terms(expand_mul(expr)).rewrite(sin)

    assert ILT(1, s, t) == DiracDelta(t)
    assert ILT(1/s, s, t) == Heaviside(t)
    assert ILT(a/(a + s), s, t) == a*exp(-a*t)*Heaviside(t)
    assert ILT(s/(a + s), s, t) == -a*exp(-a*t)*Heaviside(t) + DiracDelta(t)
    assert ILT((a + s)**(-2), s, t) == t*exp(-a*t)*Heaviside(t)
    assert ILT((a + s)**(-5), s, t) == t**4*exp(-a*t)*Heaviside(t)/24
    assert ILT(a/(a**2 + s**2), s, t) == sin(a*t)*Heaviside(t)
    assert ILT(s/(s**2 + a**2), s, t) == cos(a*t)*Heaviside(t)
    assert ILT(b/(b**2 + (a + s)**2), s, t) == exp(-a*t)*sin(b*t)*Heaviside(t)
    assert ILT(b*s/(b**2 + (a + s)**2), s, t) +\
        (a*sin(b*t) - b*cos(b*t))*exp(-a*t)*Heaviside(t) == 0
    assert ILT(exp(-a*s)/s, s, t) == Heaviside(-a + t)
    assert ILT(exp(-a*s)/(b + s), s, t) == exp(b*(a - t))*Heaviside(-a + t)
    assert ILT((b + s)/(a**2 + (b + s)**2), s, t) == \
        exp(-b*t)*cos(a*t)*Heaviside(t)
    assert ILT(exp(-a*s)/s**b, s, t) == \
        (-a + t)**(b - 1)*Heaviside(-a + t)/gamma(b)
    assert ILT(exp(-a*s)/sqrt(s**2 + 1), s, t) == \
        Heaviside(-a + t)*besselj(0, a - t)
    assert ILT(1/(s*sqrt(s + 1)), s, t) == Heaviside(t)*erf(sqrt(t))
    assert ILT(1/(s**2*(s**2 + 1)), s, t) == (t - sin(t))*Heaviside(t)
    assert ILT(s**2/(s**2 + 1), s, t) == -sin(t)*Heaviside(t) + DiracDelta(t)
    assert ILT(1 - 1/(s**2 + 1), s, t) == -sin(t)*Heaviside(t) + DiracDelta(t)
    assert ILT(1/s**2, s, t) == t*Heaviside(t)
    assert ILT(1/s**5, s, t) == t**4*Heaviside(t)/24
    assert simp_hyp(ILT(a/(s**2 - a**2), s, t)) == sinh(a*t)*Heaviside(t)
    assert simp_hyp(ILT(s/(s**2 - a**2), s, t)) == cosh(a*t)*Heaviside(t)
    # TODO sinh/cosh shifted come out a mess. also delayed trig is a mess
    # TODO should this simplify further?
    assert ILT(exp(-a*s)/s**b, s, t) == \
        (t - a)**(b - 1)*Heaviside(t - a)/gamma(b)
    assert ILT(exp(-a*s)/sqrt(1 + s**2), s, t) == \
        Heaviside(t - a)*besselj(0, a - t)  # note: besselj(0, x) is even
    # XXX ILT turns these branch factor into trig functions ...
    assert simplify(ILT(a**b*(s + sqrt(s**2 - a**2))**(-b)/sqrt(s**2 - a**2),
                    s, t).rewrite(exp)) == \
        Heaviside(t)*besseli(b, a*t)
    assert ILT(a**b*(s + sqrt(s**2 + a**2))**(-b)/sqrt(s**2 + a**2),
               s, t).rewrite(exp) == \
        Heaviside(t)*besselj(b, a*t)

    assert ILT(1/(s*sqrt(s + 1)), s, t) == Heaviside(t)*erf(sqrt(t))
    # TODO can we make erf(t) work?

    assert ILT(1/(s**2*(s**2 + 1)),s,t) == (t - sin(t))*Heaviside(t)

    assert ILT( (s * eye(2) - Matrix([[1, 0], [0, 2]])).inv(), s, t) ==\
        Matrix([[exp(t)*Heaviside(t), 0], [0, exp(2*t)*Heaviside(t)]])
Esempio n. 24
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
Esempio n. 25
0
def test_sinh_rewrite():
    x = Symbol('x')
    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. 26
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)
Esempio n. 27
0
def test_issue_3210():
    eqs = (
        sin(2) * cos(3) + sin(3) * cos(2),
        -sin(2) * sin(3) + cos(2) * cos(3),
        sin(2) * cos(3) - sin(3) * cos(2),
        sin(2) * sin(3) + cos(2) * cos(3),
        sin(2) * sin(3) + cos(2) * cos(3) + cos(2),
        sinh(2) * cosh(3) + sinh(3) * cosh(2),
        sinh(2) * sinh(3) + cosh(2) * cosh(3),
    )
    assert [trigsimp(e) for e in eqs] == [
        sin(5),
        cos(5),
        -sin(1),
        cos(1),
        cos(1) + cos(2),
        sinh(5),
        cosh(5),
    ]
Esempio n. 28
0
def test_hyperbolic():
    assert sinh(x).nseries(x, n=6) == x + x**3 / 6 + x**5 / 120 + O(x**6)
    assert cosh(x).nseries(x, n=5) == 1 + x**2 / 2 + x**4 / 24 + O(x**5)
    assert tanh(x).nseries(x, n=6) == x - x**3 / 3 + 2 * x**5 / 15 + O(x**6)
    assert coth(x).nseries(x, n=6) == \
        1/x - x**3/45 + x/3 + 2*x**5/945 + O(x**6)
    assert asinh(x).nseries(x, n=6) == x - x**3 / 6 + 3 * x**5 / 40 + O(x**6)
    assert acosh(x).nseries(x, n=6) == \
        pi*I/2 - I*x - 3*I*x**5/40 - I*x**3/6 + O(x**6)
    assert atanh(x).nseries(x, n=6) == x + x**3 / 3 + x**5 / 5 + O(x**6)
    assert acoth(x).nseries(
        x, n=6) == x + x**3 / 3 + x**5 / 5 + pi * I / 2 + O(x**6)
Esempio n. 29
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
    assert asech(x).inverse() == sech
    assert acsch(x).inverse() == csch
Esempio n. 30
0
def test_evalc():
    x = Symbol("x", real=True)
    y = Symbol("y", real=True)
    z = Symbol("z")
    assert ((x + I * y)**2).expand(complex=True) == x**2 + 2 * I * x * y - y**2
    assert expand_complex(z**(2 * I)) == (re(
        (re(z) + I * im(z))**(2 * I)) + I * im((re(z) + I * im(z))**(2 * I)))
    assert expand_complex(z**(2 * I),
                          deep=False) == I * im(z**(2 * I)) + re(z**(2 * I))

    assert exp(I * x) != cos(x) + I * sin(x)
    assert exp(I * x).expand(complex=True) == cos(x) + I * sin(x)
    assert exp(I * x +
               y).expand(complex=True) == exp(y) * cos(x) + I * sin(x) * exp(y)

    assert sin(I * x).expand(complex=True) == I * sinh(x)
    assert sin(x + I*y).expand(complex=True) == sin(x)*cosh(y) + \
        I * sinh(y) * cos(x)

    assert cos(I * x).expand(complex=True) == cosh(x)
    assert cos(x + I*y).expand(complex=True) == cos(x)*cosh(y) - \
        I * sinh(y) * sin(x)

    assert tan(I * x).expand(complex=True) == tanh(x) * I
    assert tan(x + I * y).expand(
        complex=True) == (sin(2 * x) / (cos(2 * x) + cosh(2 * y)) +
                          I * sinh(2 * y) / (cos(2 * x) + cosh(2 * y)))

    assert sinh(I * x).expand(complex=True) == I * sin(x)
    assert sinh(x + I*y).expand(complex=True) == sinh(x)*cos(y) + \
        I * sin(y) * cosh(x)

    assert cosh(I * x).expand(complex=True) == cos(x)
    assert cosh(x + I*y).expand(complex=True) == cosh(x)*cos(y) + \
        I * sin(y) * sinh(x)

    assert tanh(I * x).expand(complex=True) == tan(x) * I
    assert tanh(x + I * y).expand(
        complex=True) == ((sinh(x) * cosh(x) + I * cos(y) * sin(y)) /
                          (sinh(x)**2 + cos(y)**2)).expand()
Esempio n. 31
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)
Esempio n. 32
0
def test_sympy__functions__elementary__hyperbolic__cosh():
    from sympy.functions.elementary.hyperbolic import cosh
    assert _test_args(cosh(2))