Esempio n. 1
0
def test_trigintegrate_mixed():
    assert trigintegrate(sin(x) * sec(x), x) == -log(sin(x)**2 - 1) / 2
    assert trigintegrate(sin(x) * csc(x), x) == x
    assert trigintegrate(sin(x) * cot(x), x) == sin(x)

    assert trigintegrate(cos(x) * sec(x), x) == x
    assert trigintegrate(cos(x) * csc(x), x) == log(cos(x)**2 - 1) / 2
    assert trigintegrate(cos(x) * tan(x), x) == -cos(x)
    assert trigintegrate(cos(x)*cot(x), x) == log(cos(x) - 1)/2 \
        - log(cos(x) + 1)/2 + cos(x)
Esempio n. 2
0
def test_sech():
    k = Symbol('k', integer=True)
    n = Symbol('n', positive=True)

    assert sech(nan) == nan
    assert sech(zoo) == 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) == zoo
    assert sech(-pi * I / 2) == zoo
    assert sech((-3 * 10**73 + 1) * pi * I / 2) == zoo
    assert sech((7 * 10**103 + 1) * pi * I / 2) == 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(-2 * pi * I / 3) == -2

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

    assert sech(pi * I / 6) == 2 / sqrt(3)
    assert sech(-pi * I / 6) == 2 / sqrt(3)
    assert sech(7 * pi * I / 6) == -2 / sqrt(3)
    assert sech(-5 * pi * I / 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_extended_real is True
    assert csch(n).is_finite is None

    pytest.raises(ArgumentIndexError, lambda: sech(x).fdiff(2))
Esempio n. 3
0
def test_sech():
    k = Symbol('k', integer=True)
    n = Symbol('n', positive=True)

    assert sech(nan) == nan
    assert sech(zoo) == 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) == zoo
    assert sech(-pi*I/2) == zoo
    assert sech((-3*10**73 + 1)*pi*I/2) == zoo
    assert sech((7*10**103 + 1)*pi*I/2) == 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(-2*pi*I/3) == -2

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

    assert sech(pi*I/6) == 2/sqrt(3)
    assert sech(-pi*I/6) == 2/sqrt(3)
    assert sech(7*pi*I/6) == -2/sqrt(3)
    assert sech(-5*pi*I/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_extended_real is True
    assert csch(n).is_finite is None

    pytest.raises(ArgumentIndexError, lambda: sech(x).fdiff(2))
Esempio n. 4
0
def test_inverses():
    pytest.raises(AttributeError, lambda: sin(x).inverse())
    pytest.raises(AttributeError, lambda: cos(x).inverse())
    assert tan(x).inverse() == atan
    assert cot(x).inverse() == acot
    pytest.raises(AttributeError, lambda: csc(x).inverse())
    pytest.raises(AttributeError, lambda: sec(x).inverse())
    assert asin(x).inverse() == sin
    assert acos(x).inverse() == cos
    assert atan(x).inverse() == tan
    assert acot(x).inverse() == cot
Esempio n. 5
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. 6
0
def test_sec():
    x = symbols('x', extended_real=True)
    z = symbols('z')

    assert sec.nargs == FiniteSet(1)

    assert sec(0) == 1
    assert sec(pi) == -1
    assert sec(pi/2) == zoo
    assert sec(-pi/2) == zoo
    assert sec(pi/6) == 2*sqrt(3)/3
    assert sec(pi/3) == 2
    assert sec(5*pi/2) == zoo
    assert sec(9*pi/7) == -sec(2*pi/7)
    assert sec(3*pi/4) == -sqrt(2)  # issue sympy/sympy#8421
    assert sec(I) == sech(1)
    assert sec(x*I) == sech(x)
    assert sec(-x) == sec(x)

    assert sec(asec(x)) == x

    assert sec(x).rewrite(exp) == 1/(exp(I*x)/2 + exp(-I*x)/2)
    assert sec(x).rewrite(sin) == sec(x)
    assert sec(x).rewrite(cos) == 1/cos(x)
    assert sec(x).rewrite(tan) == (tan(x/2)**2 + 1)/(-tan(x/2)**2 + 1)
    assert sec(x).rewrite(sqrt) == sec(x)
    assert sec(z).rewrite(cot) == (cot(z/2)**2 + 1)/(cot(z/2)**2 - 1)

    assert sec(z).conjugate() == sec(conjugate(z))

    assert (sec(z).as_real_imag() ==
            (cos(re(z))*cosh(im(z))/(sin(re(z))**2*sinh(im(z))**2 +
                                     cos(re(z))**2*cosh(im(z))**2),
             sin(re(z))*sinh(im(z))/(sin(re(z))**2*sinh(im(z))**2 +
                                     cos(re(z))**2*cosh(im(z))**2)))

    assert sec(x).expand(trig=True) == 1/cos(x)
    assert sec(2*x).expand(trig=True) == 1/(2*cos(x)**2 - 1)

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

    assert sec(x).as_leading_term() == sec(x)

    assert sec(0).is_finite
    assert sec(x).is_finite is None
    assert sec(pi/2).is_finite is False

    assert series(sec(x), x, x0=0, n=6) == 1 + x**2/2 + 5*x**4/24 + O(x**6)

    # https://github.com/sympy/sympy/issues/7166
    assert series(sqrt(sec(x))) == 1 + x**2/4 + 7*x**4/96 + O(x**6)

    # https://github.com/sympy/sympy/issues/7167
    assert (series(sqrt(sec(x)), x, x0=pi*3/2, n=4) ==
            1/sqrt(x - 3*pi/2) + (x - 3*pi/2)**Rational(3, 2)/12 +
            (x - 3*pi/2)**Rational(7, 2)/160 + O((x - 3*pi/2)**4, (x, 3*pi/2)))

    assert sec(x).diff(x) == tan(x)*sec(x)

    # Taylor Term checks
    assert sec(z).taylor_term(4, z) == 5*z**4/24
    assert sec(z).taylor_term(6, z) == 61*z**6/720
    assert sec(z).taylor_term(5, z) == 0

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