Ejemplo n.º 1
0
def test_asech():
    x = Symbol('x')

    assert unchanged(asech, -x)

    # values at fixed points
    assert asech(1) == 0
    assert asech(-1) == pi * I
    assert asech(0) is oo
    assert asech(2) == I * pi / 3
    assert asech(-2) == 2 * I * pi / 3
    assert asech(nan) is nan

    # at infinites
    assert asech(oo) == I * pi / 2
    assert asech(-oo) == I * pi / 2
    assert asech(zoo) == I * AccumBounds(-pi / 2, pi / 2)

    assert asech(I) == log(1 + sqrt(2)) - I * pi / 2
    assert asech(-I) == log(1 + sqrt(2)) + I * pi / 2
    assert asech(sqrt(2) - sqrt(6)) == 11 * I * pi / 12
    assert asech(sqrt(2 - 2 / sqrt(5))) == I * pi / 10
    assert asech(-sqrt(2 - 2 / sqrt(5))) == 9 * I * pi / 10
    assert asech(2 / sqrt(2 + sqrt(2))) == I * pi / 8
    assert asech(-2 / sqrt(2 + sqrt(2))) == 7 * I * pi / 8
    assert asech(sqrt(5) - 1) == I * pi / 5
    assert asech(1 - sqrt(5)) == 4 * I * pi / 5
    assert asech(-sqrt(2 * (2 + sqrt(2)))) == 5 * I * pi / 8

    # properties
    # asech(x) == acosh(1/x)
    assert asech(sqrt(2)) == acosh(1 / sqrt(2))
    assert asech(2 / sqrt(3)) == acosh(sqrt(3) / 2)
    assert asech(2 / sqrt(2 + sqrt(2))) == acosh(sqrt(2 + sqrt(2)) / 2)
    assert asech(2) == acosh(S.Half)

    # asech(x) == I*acos(1/x)
    # (Note: the exact formula is asech(x) == +/- I*acos(1/x))
    assert asech(-sqrt(2)) == I * acos(-1 / sqrt(2))
    assert asech(-2 / sqrt(3)) == I * acos(-sqrt(3) / 2)
    assert asech(-S(2)) == I * acos(Rational(-1, 2))
    assert asech(-2 / sqrt(2)) == I * acos(-sqrt(2) / 2)

    # sech(asech(x)) / x == 1
    assert expand_mul(sech(asech(sqrt(6) - sqrt(2))) /
                      (sqrt(6) - sqrt(2))) == 1
    assert expand_mul(sech(asech(sqrt(6) + sqrt(2))) /
                      (sqrt(6) + sqrt(2))) == 1
    assert (sech(asech(sqrt(2 + 2 / sqrt(5)))) /
            (sqrt(2 + 2 / sqrt(5)))).simplify() == 1
    assert (sech(asech(-sqrt(2 + 2 / sqrt(5)))) /
            (-sqrt(2 + 2 / sqrt(5)))).simplify() == 1
    assert (sech(asech(sqrt(2 * (2 + sqrt(2))))) /
            (sqrt(2 * (2 + sqrt(2))))).simplify() == 1
    assert expand_mul(sech(asech(1 + sqrt(5))) / (1 + sqrt(5))) == 1
    assert expand_mul(sech(asech(-1 - sqrt(5))) / (-1 - sqrt(5))) == 1
    assert expand_mul(sech(asech(-sqrt(6) - sqrt(2))) /
                      (-sqrt(6) - sqrt(2))) == 1

    # numerical evaluation
    assert str(asech(5 * I).n(6)) == '0.19869 - 1.5708*I'
    assert str(asech(-5 * I).n(6)) == '0.19869 + 1.5708*I'
Ejemplo n.º 2
0
def test_sympy__functions__elementary__hyperbolic__acosh():
    from sympy.functions.elementary.hyperbolic import acosh
    assert _test_args(acosh(2))
Ejemplo n.º 3
0
def test_acosh_rewrite():
    x = Symbol('x')
    assert acosh(x).rewrite(log) == log(x + sqrt(x - 1) * sqrt(x + 1))
Ejemplo n.º 4
0
def test_acosh_fdiff():
    x = Symbol('x')
    raises(ArgumentIndexError, lambda: acosh(x).fdiff(2))
Ejemplo n.º 5
0
def test_acosh():
    x = Symbol('x')

    assert unchanged(acosh, -x)

    #at specific points
    assert acosh(1) == 0
    assert acosh(-1) == pi * I
    assert acosh(0) == I * pi / 2
    assert acosh(S.Half) == I * pi / 3
    assert acosh(Rational(-1, 2)) == pi * I * Rational(2, 3)
    assert acosh(nan) is nan

    # at infinites
    assert acosh(oo) is oo
    assert acosh(-oo) is oo

    assert acosh(I * oo) == oo + I * pi / 2
    assert acosh(-I * oo) == oo - I * pi / 2

    assert acosh(zoo) is zoo

    assert acosh(I) == log(I * (1 + sqrt(2)))
    assert acosh(-I) == log(-I * (1 + sqrt(2)))
    assert acosh((sqrt(3) - 1) / (2 * sqrt(2))) == pi * I * Rational(5, 12)
    assert acosh(-(sqrt(3) - 1) / (2 * sqrt(2))) == pi * I * Rational(7, 12)
    assert acosh(sqrt(2) / 2) == I * pi / 4
    assert acosh(-sqrt(2) / 2) == I * pi * Rational(3, 4)
    assert acosh(sqrt(3) / 2) == I * pi / 6
    assert acosh(-sqrt(3) / 2) == I * pi * Rational(5, 6)
    assert acosh(sqrt(2 + sqrt(2)) / 2) == I * pi / 8
    assert acosh(-sqrt(2 + sqrt(2)) / 2) == I * pi * Rational(7, 8)
    assert acosh(sqrt(2 - sqrt(2)) / 2) == I * pi * Rational(3, 8)
    assert acosh(-sqrt(2 - sqrt(2)) / 2) == I * pi * Rational(5, 8)
    assert acosh((1 + sqrt(3)) / (2 * sqrt(2))) == I * pi / 12
    assert acosh(-(1 + sqrt(3)) / (2 * sqrt(2))) == I * pi * Rational(11, 12)
    assert acosh((sqrt(5) + 1) / 4) == I * pi / 5
    assert acosh(-(sqrt(5) + 1) / 4) == I * pi * Rational(4, 5)

    assert str(acosh(5 * I).n(6)) == '2.31244 + 1.5708*I'
    assert str(acosh(-5 * I).n(6)) == '2.31244 - 1.5708*I'

    # inverse composition
    assert unchanged(acosh, Symbol('v1'))

    assert acosh(cosh(-3, evaluate=False)) == 3
    assert acosh(cosh(3, evaluate=False)) == 3
    assert acosh(cosh(0, evaluate=False)) == 0
    assert acosh(cosh(I, evaluate=False)) == I
    assert acosh(cosh(-I, evaluate=False)) == I
    assert acosh(cosh(7 * I, evaluate=False)) == -2 * I * pi + 7 * I
    assert acosh(cosh(1 + I)) == 1 + I
    assert acosh(cosh(3 - 3 * I)) == 3 - 3 * I
    assert acosh(cosh(-3 + 2 * I)) == 3 - 2 * I
    assert acosh(cosh(-5 - 17 * I)) == 5 - 6 * I * pi + 17 * I
    assert acosh(cosh(-21 + 11 * I)) == 21 - 11 * I + 4 * I * pi
    assert acosh(cosh(cosh(1) + I)) == cosh(1) + I
    assert acosh(1, evaluate=False).is_zero is True
Ejemplo n.º 6
0
def test_issue_17421():
    assert N(acos(-I + acosh(cosh(cosh(1) + I)))) == 1.0 * I
Ejemplo n.º 7
0
def test_manualintegrate_inversetrig():
    # atan
    assert manualintegrate(exp(x) / (1 + exp(2 * x)), x) == atan(exp(x))
    assert manualintegrate(1 / (4 + 9 * x**2), x) == atan(3 * x / 2) / 6
    assert manualintegrate(1 / (16 + 16 * x**2), x) == atan(x) / 16
    assert manualintegrate(1 / (4 + x**2), x) == atan(x / 2) / 2
    assert manualintegrate(1 / (1 + 4 * x**2), x) == atan(2 * x) / 2
    ra = Symbol('a', real=True)
    rb = Symbol('b', real=True)
    assert manualintegrate(1/(ra + rb*x**2), x) == \
        Piecewise((atan(x/sqrt(ra/rb))/(rb*sqrt(ra/rb)), ra/rb > 0),
                  (-acoth(x/sqrt(-ra/rb))/(rb*sqrt(-ra/rb)), And(ra/rb < 0, x**2 > -ra/rb)),
                  (-atanh(x/sqrt(-ra/rb))/(rb*sqrt(-ra/rb)), And(ra/rb < 0, x**2 < -ra/rb)))
    assert manualintegrate(1/(4 + rb*x**2), x) == \
        Piecewise((atan(x/(2*sqrt(1/rb)))/(2*rb*sqrt(1/rb)), 4/rb > 0),
                  (-acoth(x/(2*sqrt(-1/rb)))/(2*rb*sqrt(-1/rb)), And(4/rb < 0, x**2 > -4/rb)),
                  (-atanh(x/(2*sqrt(-1/rb)))/(2*rb*sqrt(-1/rb)), And(4/rb < 0, x**2 < -4/rb)))
    assert manualintegrate(1/(ra + 4*x**2), x) == \
        Piecewise((atan(2*x/sqrt(ra))/(2*sqrt(ra)), ra/4 > 0),
                  (-acoth(2*x/sqrt(-ra))/(2*sqrt(-ra)), And(ra/4 < 0, x**2 > -ra/4)),
                  (-atanh(2*x/sqrt(-ra))/(2*sqrt(-ra)), And(ra/4 < 0, x**2 < -ra/4)))
    assert manualintegrate(1 / (4 + 4 * x**2), x) == atan(x) / 4

    assert manualintegrate(1 / (a + b * x**2),
                           x) == atan(x / sqrt(a / b)) / (b * sqrt(a / b))

    # asin
    assert manualintegrate(1 / sqrt(1 - x**2), x) == asin(x)
    assert manualintegrate(1 / sqrt(4 - 4 * x**2), x) == asin(x) / 2
    assert manualintegrate(3 / sqrt(1 - 9 * x**2), x) == asin(3 * x)
    assert manualintegrate(1 / sqrt(4 - 9 * x**2),
                           x) == asin(x * Rational(3, 2)) / 3

    # asinh
    assert manualintegrate(1/sqrt(x**2 + 1), x) == \
        asinh(x)
    assert manualintegrate(1/sqrt(x**2 + 4), x) == \
        asinh(x/2)
    assert manualintegrate(1/sqrt(4*x**2 + 4), x) == \
        asinh(x)/2
    assert manualintegrate(1/sqrt(4*x**2 + 1), x) == \
        asinh(2*x)/2
    assert manualintegrate(1/sqrt(ra*x**2 + 1), x) == \
        Piecewise((asin(x*sqrt(-ra))/sqrt(-ra), ra < 0), (asinh(sqrt(ra)*x)/sqrt(ra), ra > 0))
    assert manualintegrate(1/sqrt(ra + x**2), x) == \
        Piecewise((asinh(x*sqrt(1/ra)), ra > 0), (acosh(x*sqrt(-1/ra)), ra < 0))

    # acosh
    assert manualintegrate(1/sqrt(x**2 - 1), x) == \
        acosh(x)
    assert manualintegrate(1/sqrt(x**2 - 4), x) == \
        acosh(x/2)
    assert manualintegrate(1/sqrt(4*x**2 - 4), x) == \
        acosh(x)/2
    assert manualintegrate(1/sqrt(9*x**2 - 1), x) == \
        acosh(3*x)/3
    assert manualintegrate(1/sqrt(ra*x**2 - 4), x) == \
        Piecewise((acosh(sqrt(ra)*x/2)/sqrt(ra), ra > 0))
    assert manualintegrate(1/sqrt(-ra + 4*x**2), x) == \
        Piecewise((asinh(2*x*sqrt(-1/ra))/2, -ra > 0), (acosh(2*x*sqrt(1/ra))/2, -ra < 0))

    # From https://www.wikiwand.com/en/List_of_integrals_of_inverse_trigonometric_functions
    # asin
    assert manualintegrate(asin(x), x) == x * asin(x) + sqrt(1 - x**2)
    assert manualintegrate(asin(a * x), x) == Piecewise(
        ((a * x * asin(a * x) + sqrt(-a**2 * x**2 + 1)) / a, Ne(a, 0)),
        (0, True))
    assert manualintegrate(x * asin(a * x), x) == -a * Integral(
        x**2 / sqrt(-a**2 * x**2 + 1), x) / 2 + x**2 * asin(a * x) / 2
    # acos
    assert manualintegrate(acos(x), x) == x * acos(x) - sqrt(1 - x**2)
    assert manualintegrate(acos(a * x), x) == Piecewise(
        ((a * x * acos(a * x) - sqrt(-a**2 * x**2 + 1)) / a, Ne(a, 0)),
        (pi * x / 2, True))
    assert manualintegrate(x * acos(a * x), x) == a * Integral(
        x**2 / sqrt(-a**2 * x**2 + 1), x) / 2 + x**2 * acos(a * x) / 2
    # atan
    assert manualintegrate(atan(x), x) == x * atan(x) - log(x**2 + 1) / 2
    assert manualintegrate(atan(a * x), x) == Piecewise(
        ((a * x * atan(a * x) - log(a**2 * x**2 + 1) / 2) / a, Ne(a, 0)),
        (0, True))
    assert manualintegrate(
        x * atan(a * x),
        x) == -a * (x / a**2 - atan(x / sqrt(a**(-2))) /
                    (a**4 * sqrt(a**(-2)))) / 2 + x**2 * atan(a * x) / 2
    # acsc
    assert manualintegrate(
        acsc(x), x) == x * acsc(x) + Integral(1 / (x * sqrt(1 - 1 / x**2)), x)
    assert manualintegrate(
        acsc(a * x),
        x) == x * acsc(a * x) + Integral(1 / (x * sqrt(1 - 1 /
                                                       (a**2 * x**2))), x) / a
    assert manualintegrate(x * acsc(a * x),
                           x) == x**2 * acsc(a * x) / 2 + Integral(
                               1 / sqrt(1 - 1 / (a**2 * x**2)), x) / (2 * a)
    # asec
    assert manualintegrate(
        asec(x), x) == x * asec(x) - Integral(1 / (x * sqrt(1 - 1 / x**2)), x)
    assert manualintegrate(
        asec(a * x),
        x) == x * asec(a * x) - Integral(1 / (x * sqrt(1 - 1 /
                                                       (a**2 * x**2))), x) / a
    assert manualintegrate(x * asec(a * x),
                           x) == x**2 * asec(a * x) / 2 - Integral(
                               1 / sqrt(1 - 1 / (a**2 * x**2)), x) / (2 * a)
    # acot
    assert manualintegrate(acot(x), x) == x * acot(x) + log(x**2 + 1) / 2
    assert manualintegrate(acot(a * x), x) == Piecewise(
        ((a * x * acot(a * x) + log(a**2 * x**2 + 1) / 2) / a, Ne(a, 0)),
        (pi * x / 2, True))
    assert manualintegrate(
        x * acot(a * x),
        x) == a * (x / a**2 - atan(x / sqrt(a**(-2))) /
                   (a**4 * sqrt(a**(-2)))) / 2 + x**2 * acot(a * x) / 2

    # piecewise
    assert manualintegrate(1/sqrt(ra-rb*x**2), x) == \
        Piecewise((asin(x*sqrt(rb/ra))/sqrt(rb), And(-rb < 0, ra > 0)),
                  (asinh(x*sqrt(-rb/ra))/sqrt(-rb), And(-rb > 0, ra > 0)),
                  (acosh(x*sqrt(rb/ra))/sqrt(-rb), And(-rb > 0, ra < 0)))
    assert manualintegrate(1/sqrt(ra + rb*x**2), x) == \
        Piecewise((asin(x*sqrt(-rb/ra))/sqrt(-rb), And(ra > 0, rb < 0)),
                  (asinh(x*sqrt(rb/ra))/sqrt(rb), And(ra > 0, rb > 0)),
                  (acosh(x*sqrt(-rb/ra))/sqrt(rb), And(ra < 0, rb > 0)))
Ejemplo n.º 8
0
def test_issue_5112_5430():
    assert homogeneous_order(-log(x) + acosh(x), x) is None
    assert homogeneous_order(y - log(x), x, y) is None
Ejemplo n.º 9
0
def test_sympy__functions__elementary__hyperbolic__acosh():
    from sympy.functions.elementary.hyperbolic import acosh
    assert _test_args(acosh(2))