Ejemplo 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def test_Function():
    assert mcode(f(x, y, z)) == "f[x, y, z]"
    assert mcode(sin(x)**cos(x)) == "Sin[x]^Cos[x]"
    assert mcode(sign(x)) == "Sign[x]"

    assert mcode(atanh(x), user_functions={"atanh": "ArcTanh"}) == "ArcTanh[x]"

    assert (mcode(meijerg(((1, 1), (3, 4)), ((1, ), ()),
                          x)) == "MeijerG[{{1, 1}, {3, 4}}, {{1}, {}}, x]")
    assert (mcode(hyper((1, 2, 3), (3, 4),
                        x)) == "HypergeometricPFQ[{1, 2, 3}, {3, 4}, x]")

    assert mcode(Min(x, y)) == "Min[x, y]"
    assert mcode(Max(x, y)) == "Max[x, y]"
    assert mcode(Max(x, 2)) == "Max[2, x]"  # issue sympy/sympy#15344

    assert mcode(binomial(x, y)) == "Binomial[x, y]"

    assert mcode(log(x)) == "Log[x]"
    assert mcode(tan(x)) == "Tan[x]"
    assert mcode(cot(x)) == "Cot[x]"
    assert mcode(asin(x)) == "ArcSin[x]"
    assert mcode(acos(x)) == "ArcCos[x]"
    assert mcode(atan(x)) == "ArcTan[x]"
    assert mcode(sinh(x)) == "Sinh[x]"
    assert mcode(cosh(x)) == "Cosh[x]"
    assert mcode(tanh(x)) == "Tanh[x]"
    assert mcode(coth(x)) == "Coth[x]"
    assert mcode(sech(x)) == "Sech[x]"
    assert mcode(csch(x)) == "Csch[x]"
    assert mcode(erfc(x)) == "Erfc[x]"
    assert mcode(conjugate(x)) == "Conjugate[x]"
    assert mcode(re(x)) == "Re[x]"
    assert mcode(im(x)) == "Im[x]"
    assert mcode(polygamma(x, y)) == "PolyGamma[x, y]"

    class myfunc1(Function):
        @classmethod
        def eval(cls, x):
            pass

    class myfunc2(Function):
        @classmethod
        def eval(cls, x, y):
            pass

    pytest.raises(
        ValueError,
        lambda: mcode(myfunc1(x), user_functions={"myfunc1": ["Myfunc1"]}))
    assert mcode(myfunc1(x), user_functions={"myfunc1":
                                             "Myfunc1"}) == "Myfunc1[x]"
    assert mcode(myfunc2(x, y),
                 user_functions={"myfunc2": [(lambda *x: False, "Myfunc2")]
                                 }) == "myfunc2[x, y]"
Ejemplo n.º 4
0
def test_trigintegrate_symbolic():
    n = Symbol('n', integer=True)
    assert trigintegrate(cos(x)**n, x) is None
    assert trigintegrate(sin(x)**n, x) is None
    assert trigintegrate(cot(x)**n, x) is None
Ejemplo n.º 5
0
def test_trigintegrate_symbolic():
    n = Symbol('n', integer=True)
    assert trigintegrate(cos(x)**n, x) is None
    assert trigintegrate(sin(x)**n, x) is None
    assert trigintegrate(cot(x)**n, x) is None
Ejemplo n.º 6
0
def test_harmonic_rational():
    ne = Integer(6)
    no = Integer(5)
    pe = Integer(8)
    po = Integer(9)
    qe = Integer(10)
    qo = Integer(13)

    Heee = harmonic(ne + pe / qe)
    Aeee = (-log(10) + 2 * (-1 / Integer(4) + sqrt(5) / 4) *
            log(sqrt(-sqrt(5) / 8 + 5 / Integer(8))) + 2 *
            (-sqrt(5) / 4 - 1 / Integer(4)) *
            log(sqrt(sqrt(5) / 8 + 5 / Integer(8))) + pi *
            (1 / Integer(4) + sqrt(5) / 4) /
            (2 * sqrt(-sqrt(5) / 8 + 5 / Integer(8))) +
            13944145 / Integer(4720968))

    Heeo = harmonic(ne + pe / qo)
    Aeeo = (-log(26) + 2 * log(sin(3 * pi / 13)) * cos(4 * pi / 13) +
            2 * log(sin(2 * pi / 13)) * cos(32 * pi / 13) +
            2 * log(sin(5 * pi / 13)) * cos(80 * pi / 13) -
            2 * log(sin(6 * pi / 13)) * cos(5 * pi / 13) -
            2 * log(sin(4 * pi / 13)) * cos(pi / 13) +
            pi * cot(5 * pi / 13) / 2 -
            2 * log(sin(pi / 13)) * cos(3 * pi / 13) +
            2422020029 / Integer(702257080))

    Heoe = harmonic(ne + po / qe)
    Aeoe = (
        -log(20) + 2 *
        (1 / Integer(4) + sqrt(5) / 4) * log(-1 / Integer(4) + sqrt(5) / 4) +
        2 * (-1 / Integer(4) + sqrt(5) / 4) *
        log(sqrt(-sqrt(5) / 8 + 5 / Integer(8))) + 2 *
        (-sqrt(5) / 4 - 1 / Integer(4)) *
        log(sqrt(sqrt(5) / 8 + 5 / Integer(8))) + 2 *
        (-sqrt(5) / 4 + 1 / Integer(4)) * log(1 / Integer(4) + sqrt(5) / 4) +
        11818877030 / Integer(4286604231) + pi *
        (sqrt(5) / 8 + 5 / Integer(8)) / sqrt(-sqrt(5) / 8 + 5 / Integer(8)))

    Heoo = harmonic(ne + po / qo)
    Aeoo = (-log(26) + 2 * log(sin(3 * pi / 13)) * cos(54 * pi / 13) +
            2 * log(sin(4 * pi / 13)) * cos(6 * pi / 13) +
            2 * log(sin(6 * pi / 13)) * cos(108 * pi / 13) -
            2 * log(sin(5 * pi / 13)) * cos(pi / 13) -
            2 * log(sin(pi / 13)) * cos(5 * pi / 13) +
            pi * cot(4 * pi / 13) / 2 -
            2 * log(sin(2 * pi / 13)) * cos(3 * pi / 13) +
            11669332571 / Integer(3628714320))

    Hoee = harmonic(no + pe / qe)
    Aoee = (-log(10) + 2 * (-1 / Integer(4) + sqrt(5) / 4) *
            log(sqrt(-sqrt(5) / 8 + 5 / Integer(8))) + 2 *
            (-sqrt(5) / 4 - 1 / Integer(4)) *
            log(sqrt(sqrt(5) / 8 + 5 / Integer(8))) + pi *
            (1 / Integer(4) + sqrt(5) / 4) /
            (2 * sqrt(-sqrt(5) / 8 + 5 / Integer(8))) +
            779405 / Integer(277704))

    Hoeo = harmonic(no + pe / qo)
    Aoeo = (-log(26) + 2 * log(sin(3 * pi / 13)) * cos(4 * pi / 13) +
            2 * log(sin(2 * pi / 13)) * cos(32 * pi / 13) +
            2 * log(sin(5 * pi / 13)) * cos(80 * pi / 13) -
            2 * log(sin(6 * pi / 13)) * cos(5 * pi / 13) -
            2 * log(sin(4 * pi / 13)) * cos(pi / 13) +
            pi * cot(5 * pi / 13) / 2 -
            2 * log(sin(pi / 13)) * cos(3 * pi / 13) +
            53857323 / Integer(16331560))

    Hooe = harmonic(no + po / qe)
    Aooe = (
        -log(20) + 2 *
        (1 / Integer(4) + sqrt(5) / 4) * log(-1 / Integer(4) + sqrt(5) / 4) +
        2 * (-1 / Integer(4) + sqrt(5) / 4) *
        log(sqrt(-sqrt(5) / 8 + 5 / Integer(8))) + 2 *
        (-sqrt(5) / 4 - 1 / Integer(4)) *
        log(sqrt(sqrt(5) / 8 + 5 / Integer(8))) + 2 *
        (-sqrt(5) / 4 + 1 / Integer(4)) * log(1 / Integer(4) + sqrt(5) / 4) +
        486853480 / Integer(186374097) + pi *
        (sqrt(5) / 8 + 5 / Integer(8)) / sqrt(-sqrt(5) / 8 + 5 / Integer(8)))

    Hooo = harmonic(no + po / qo)
    Aooo = (-log(26) + 2 * log(sin(3 * pi / 13)) * cos(54 * pi / 13) +
            2 * log(sin(4 * pi / 13)) * cos(6 * pi / 13) +
            2 * log(sin(6 * pi / 13)) * cos(108 * pi / 13) -
            2 * log(sin(5 * pi / 13)) * cos(pi / 13) -
            2 * log(sin(pi / 13)) * cos(5 * pi / 13) +
            pi * cot(4 * pi / 13) / 2 -
            2 * log(sin(2 * pi / 13)) * cos(3 * pi / 13) +
            383693479 / Integer(125128080))

    H = [Heee, Heeo, Heoe, Heoo, Hoee, Hoeo, Hooe, Hooo]
    A = [Aeee, Aeeo, Aeoe, Aeoo, Aoee, Aoeo, Aooe, Aooo]

    for h, a in zip(H, A):
        e = expand_func(h).doit()
        assert cancel(e / a) == 1
        assert h.n() == a.n()
Ejemplo n.º 7
0
def test_Function():
    assert mcode(f(x, y, z)) == "f[x, y, z]"
    assert mcode(sin(x) ** cos(x)) == "Sin[x]^Cos[x]"
    assert mcode(sign(x)) == "Sign[x]"

    assert mcode(atanh(x), user_functions={"atanh": "ArcTanh"}) == "ArcTanh[x]"

    assert (mcode(meijerg(((1, 1), (3, 4)), ((1,), ()), x)) ==
            "MeijerG[{{1, 1}, {3, 4}}, {{1}, {}}, x]")
    assert (mcode(hyper((1, 2, 3), (3, 4), x)) ==
            "HypergeometricPFQ[{1, 2, 3}, {3, 4}, x]")

    assert mcode(Min(x, y)) == "Min[x, y]"
    assert mcode(Max(x, y)) == "Max[x, y]"
    assert mcode(Max(x, 2)) == "Max[2, x]"  # issue sympy/sympy#15344

    assert mcode(binomial(x, y)) == "Binomial[x, y]"

    assert mcode(log(x)) == "Log[x]"
    assert mcode(tan(x)) == "Tan[x]"
    assert mcode(cot(x)) == "Cot[x]"
    assert mcode(asin(x)) == "ArcSin[x]"
    assert mcode(acos(x)) == "ArcCos[x]"
    assert mcode(atan(x)) == "ArcTan[x]"
    assert mcode(sinh(x)) == "Sinh[x]"
    assert mcode(cosh(x)) == "Cosh[x]"
    assert mcode(tanh(x)) == "Tanh[x]"
    assert mcode(coth(x)) == "Coth[x]"
    assert mcode(sech(x)) == "Sech[x]"
    assert mcode(csch(x)) == "Csch[x]"
    assert mcode(erfc(x)) == "Erfc[x]"
    assert mcode(conjugate(x)) == "Conjugate[x]"
    assert mcode(re(x)) == "Re[x]"
    assert mcode(im(x)) == "Im[x]"
    assert mcode(polygamma(x, y)) == "PolyGamma[x, y]"
    assert mcode(factorial(x)) == "Factorial[x]"
    assert mcode(factorial2(x)) == "Factorial2[x]"
    assert mcode(rf(x, y)) == "Pochhammer[x, y]"
    assert mcode(gamma(x)) == "Gamma[x]"
    assert mcode(zeta(x)) == "Zeta[x]"
    assert mcode(asinh(x)) == "ArcSinh[x]"
    assert mcode(Heaviside(x)) == "UnitStep[x]"
    assert mcode(fibonacci(x)) == "Fibonacci[x]"
    assert mcode(polylog(x, y)) == "PolyLog[x, y]"
    assert mcode(atanh(x)) == "ArcTanh[x]"

    class myfunc1(Function):
        @classmethod
        def eval(cls, x):
            pass

    class myfunc2(Function):
        @classmethod
        def eval(cls, x, y):
            pass

    pytest.raises(ValueError,
                  lambda: mcode(myfunc1(x),
                                user_functions={"myfunc1": ["Myfunc1"]}))
    assert mcode(myfunc1(x),
                 user_functions={"myfunc1": "Myfunc1"}) == "Myfunc1[x]"
    assert mcode(myfunc2(x, y),
                 user_functions={"myfunc2": [(lambda *x: False,
                                              "Myfunc2")]}) == "myfunc2[x, y]"
Ejemplo n.º 8
0
def test_harmonic_rational():
    ne = Integer(6)
    no = Integer(5)
    pe = Integer(8)
    po = Integer(9)
    qe = Integer(10)
    qo = Integer(13)

    Heee = harmonic(ne + pe/qe)
    Aeee = (-log(10) + 2*(Rational(-1, 4) + sqrt(5)/4)*log(sqrt(-sqrt(5)/8 + Rational(5, 8)))
            + 2*(-sqrt(5)/4 - Rational(1, 4))*log(sqrt(sqrt(5)/8 + Rational(5, 8)))
            + pi*(Rational(1, 4) + sqrt(5)/4)/(2*sqrt(-sqrt(5)/8 + Rational(5, 8)))
            + Rational(13944145, 4720968))

    Heeo = harmonic(ne + pe/qo)
    Aeeo = (-log(26) + 2*log(sin(3*pi/13))*cos(4*pi/13) + 2*log(sin(2*pi/13))*cos(32*pi/13)
            + 2*log(sin(5*pi/13))*cos(80*pi/13) - 2*log(sin(6*pi/13))*cos(5*pi/13)
            - 2*log(sin(4*pi/13))*cos(pi/13) + pi*cot(5*pi/13)/2 - 2*log(sin(pi/13))*cos(3*pi/13)
            + Rational(2422020029, 702257080))

    Heoe = harmonic(ne + po/qe)
    Aeoe = (-log(20) + 2*(Rational(1, 4) + sqrt(5)/4)*log(Rational(-1, 4) + sqrt(5)/4)
            + 2*(Rational(-1, 4) + sqrt(5)/4)*log(sqrt(-sqrt(5)/8 + Rational(5, 8)))
            + 2*(-sqrt(5)/4 - Rational(1, 4))*log(sqrt(sqrt(5)/8 + Rational(5, 8)))
            + 2*(-sqrt(5)/4 + Rational(1, 4))*log(Rational(1, 4) + sqrt(5)/4)
            + Rational(11818877030, 4286604231) + pi*(sqrt(5)/8 + Rational(5, 8))/sqrt(-sqrt(5)/8 + Rational(5, 8)))

    Heoo = harmonic(ne + po/qo)
    Aeoo = (-log(26) + 2*log(sin(3*pi/13))*cos(54*pi/13) + 2*log(sin(4*pi/13))*cos(6*pi/13)
            + 2*log(sin(6*pi/13))*cos(108*pi/13) - 2*log(sin(5*pi/13))*cos(pi/13)
            - 2*log(sin(pi/13))*cos(5*pi/13) + pi*cot(4*pi/13)/2
            - 2*log(sin(2*pi/13))*cos(3*pi/13) + Rational(11669332571, 3628714320))

    Hoee = harmonic(no + pe/qe)
    Aoee = (-log(10) + 2*(Rational(-1, 4) + sqrt(5)/4)*log(sqrt(-sqrt(5)/8 + Rational(5, 8)))
            + 2*(-sqrt(5)/4 - Rational(1, 4))*log(sqrt(sqrt(5)/8 + Rational(5, 8)))
            + pi*(Rational(1, 4) + sqrt(5)/4)/(2*sqrt(-sqrt(5)/8 + Rational(5, 8)))
            + Rational(779405, 277704))

    Hoeo = harmonic(no + pe/qo)
    Aoeo = (-log(26) + 2*log(sin(3*pi/13))*cos(4*pi/13) + 2*log(sin(2*pi/13))*cos(32*pi/13)
            + 2*log(sin(5*pi/13))*cos(80*pi/13) - 2*log(sin(6*pi/13))*cos(5*pi/13)
            - 2*log(sin(4*pi/13))*cos(pi/13) + pi*cot(5*pi/13)/2
            - 2*log(sin(pi/13))*cos(3*pi/13) + Rational(53857323, 16331560))

    Hooe = harmonic(no + po/qe)
    Aooe = (-log(20) + 2*(Rational(1, 4) + sqrt(5)/4)*log(Rational(-1, 4) + sqrt(5)/4)
            + 2*(Rational(-1, 4) + sqrt(5)/4)*log(sqrt(-sqrt(5)/8 + Rational(5, 8)))
            + 2*(-sqrt(5)/4 - Rational(1, 4))*log(sqrt(sqrt(5)/8 + Rational(5, 8)))
            + 2*(-sqrt(5)/4 + Rational(1, 4))*log(Rational(1, 4) + sqrt(5)/4)
            + Rational(486853480, 186374097) + pi*(sqrt(5)/8 + Rational(5, 8))/sqrt(-sqrt(5)/8 + Rational(5, 8)))

    Hooo = harmonic(no + po/qo)
    Aooo = (-log(26) + 2*log(sin(3*pi/13))*cos(54*pi/13) + 2*log(sin(4*pi/13))*cos(6*pi/13)
            + 2*log(sin(6*pi/13))*cos(108*pi/13) - 2*log(sin(5*pi/13))*cos(pi/13)
            - 2*log(sin(pi/13))*cos(5*pi/13) + pi*cot(4*pi/13)/2
            - 2*log(sin(2*pi/13))*cos(3*pi/13) + Rational(383693479, 125128080))

    H = [Heee, Heeo, Heoe, Heoo, Hoee, Hoeo, Hooe, Hooo]
    A = [Aeee, Aeeo, Aeoe, Aeoo, Aoee, Aoeo, Aooe, Aooo]

    for h, a in zip(H, A):
        e = expand_func(h).doit()
        assert cancel(e/a) == 1
        assert h.evalf() == a.evalf()
Ejemplo n.º 9
0
def test_harmonic_rational():
    ne = Integer(6)
    no = Integer(5)
    pe = Integer(8)
    po = Integer(9)
    qe = Integer(10)
    qo = Integer(13)

    Heee = harmonic(ne + pe / qe)
    Aeee = (-log(10) + 2 * (Rational(-1, 4) + sqrt(5) / 4) *
            log(sqrt(-sqrt(5) / 8 + Rational(5, 8))) + 2 *
            (-sqrt(5) / 4 - Rational(1, 4)) *
            log(sqrt(sqrt(5) / 8 + Rational(5, 8))) + pi *
            (Rational(1, 4) + sqrt(5) / 4) /
            (2 * sqrt(-sqrt(5) / 8 + Rational(5, 8))) +
            Rational(13944145, 4720968))

    Heeo = harmonic(ne + pe / qo)
    Aeeo = (-log(26) + 2 * log(sin(3 * pi / 13)) * cos(4 * pi / 13) +
            2 * log(sin(2 * pi / 13)) * cos(32 * pi / 13) +
            2 * log(sin(5 * pi / 13)) * cos(80 * pi / 13) -
            2 * log(sin(6 * pi / 13)) * cos(5 * pi / 13) -
            2 * log(sin(4 * pi / 13)) * cos(pi / 13) +
            pi * cot(5 * pi / 13) / 2 -
            2 * log(sin(pi / 13)) * cos(3 * pi / 13) +
            Rational(2422020029, 702257080))

    Heoe = harmonic(ne + po / qe)
    Aeoe = (
        -log(20) + 2 *
        (Rational(1, 4) + sqrt(5) / 4) * log(Rational(-1, 4) + sqrt(5) / 4) +
        2 * (Rational(-1, 4) + sqrt(5) / 4) *
        log(sqrt(-sqrt(5) / 8 + Rational(5, 8))) + 2 *
        (-sqrt(5) / 4 - Rational(1, 4)) *
        log(sqrt(sqrt(5) / 8 + Rational(5, 8))) + 2 *
        (-sqrt(5) / 4 + Rational(1, 4)) * log(Rational(1, 4) + sqrt(5) / 4) +
        Rational(11818877030, 4286604231) + pi *
        (sqrt(5) / 8 + Rational(5, 8)) / sqrt(-sqrt(5) / 8 + Rational(5, 8)))

    Heoo = harmonic(ne + po / qo)
    Aeoo = (-log(26) + 2 * log(sin(3 * pi / 13)) * cos(54 * pi / 13) +
            2 * log(sin(4 * pi / 13)) * cos(6 * pi / 13) +
            2 * log(sin(6 * pi / 13)) * cos(108 * pi / 13) -
            2 * log(sin(5 * pi / 13)) * cos(pi / 13) -
            2 * log(sin(pi / 13)) * cos(5 * pi / 13) +
            pi * cot(4 * pi / 13) / 2 -
            2 * log(sin(2 * pi / 13)) * cos(3 * pi / 13) +
            Rational(11669332571, 3628714320))

    Hoee = harmonic(no + pe / qe)
    Aoee = (-log(10) + 2 * (Rational(-1, 4) + sqrt(5) / 4) *
            log(sqrt(-sqrt(5) / 8 + Rational(5, 8))) + 2 *
            (-sqrt(5) / 4 - Rational(1, 4)) *
            log(sqrt(sqrt(5) / 8 + Rational(5, 8))) + pi *
            (Rational(1, 4) + sqrt(5) / 4) /
            (2 * sqrt(-sqrt(5) / 8 + Rational(5, 8))) +
            Rational(779405, 277704))

    Hoeo = harmonic(no + pe / qo)
    Aoeo = (-log(26) + 2 * log(sin(3 * pi / 13)) * cos(4 * pi / 13) +
            2 * log(sin(2 * pi / 13)) * cos(32 * pi / 13) +
            2 * log(sin(5 * pi / 13)) * cos(80 * pi / 13) -
            2 * log(sin(6 * pi / 13)) * cos(5 * pi / 13) -
            2 * log(sin(4 * pi / 13)) * cos(pi / 13) +
            pi * cot(5 * pi / 13) / 2 -
            2 * log(sin(pi / 13)) * cos(3 * pi / 13) +
            Rational(53857323, 16331560))

    Hooe = harmonic(no + po / qe)
    Aooe = (
        -log(20) + 2 *
        (Rational(1, 4) + sqrt(5) / 4) * log(Rational(-1, 4) + sqrt(5) / 4) +
        2 * (Rational(-1, 4) + sqrt(5) / 4) *
        log(sqrt(-sqrt(5) / 8 + Rational(5, 8))) + 2 *
        (-sqrt(5) / 4 - Rational(1, 4)) *
        log(sqrt(sqrt(5) / 8 + Rational(5, 8))) + 2 *
        (-sqrt(5) / 4 + Rational(1, 4)) * log(Rational(1, 4) + sqrt(5) / 4) +
        Rational(486853480, 186374097) + pi *
        (sqrt(5) / 8 + Rational(5, 8)) / sqrt(-sqrt(5) / 8 + Rational(5, 8)))

    Hooo = harmonic(no + po / qo)
    Aooo = (-log(26) + 2 * log(sin(3 * pi / 13)) * cos(54 * pi / 13) +
            2 * log(sin(4 * pi / 13)) * cos(6 * pi / 13) +
            2 * log(sin(6 * pi / 13)) * cos(108 * pi / 13) -
            2 * log(sin(5 * pi / 13)) * cos(pi / 13) -
            2 * log(sin(pi / 13)) * cos(5 * pi / 13) +
            pi * cot(4 * pi / 13) / 2 -
            2 * log(sin(2 * pi / 13)) * cos(3 * pi / 13) +
            Rational(383693479, 125128080))

    H = [Heee, Heeo, Heoe, Heoo, Hoee, Hoeo, Hooe, Hooo]
    A = [Aeee, Aeeo, Aeoe, Aeoo, Aoee, Aoeo, Aooe, Aooo]

    for h, a in zip(H, A):
        e = expand_func(h).doit()
        assert cancel(e / a) == 1
        assert h.evalf() == a.evalf()
Ejemplo n.º 10
0
def _trigpats():
    global _trigpat
    a, b, c = symbols('a b c', cls=Wild)
    d = Wild('d', commutative=False)

    # for the simplifications like sinh/cosh -> tanh:
    # DO NOT REORDER THE FIRST 14 since these are assumed to be in this
    # order in _match_div_rewrite.
    matchers_division = (
        (a * sin(b)**c / cos(b)**c, a * tan(b)**c, sin(b), cos(b)),
        (a * tan(b)**c * cos(b)**c, a * sin(b)**c, sin(b), cos(b)),
        (a * cot(b)**c * sin(b)**c, a * cos(b)**c, sin(b), cos(b)),
        (a * tan(b)**c / sin(b)**c, a / cos(b)**c, sin(b), cos(b)),
        (a * cot(b)**c / cos(b)**c, a / sin(b)**c, sin(b), cos(b)),
        (a * cot(b)**c * tan(b)**c, a, sin(b), cos(b)),
        (a * (cos(b) + 1)**c * (cos(b) - 1)**c, a * (-sin(b)**2)**c,
         cos(b) + 1, cos(b) - 1),
        (a * (sin(b) + 1)**c * (sin(b) - 1)**c, a * (-cos(b)**2)**c,
         sin(b) + 1, sin(b) - 1),
        (a * sinh(b)**c / cosh(b)**c, a * tanh(b)**c, S.One, S.One),
        (a * tanh(b)**c * cosh(b)**c, a * sinh(b)**c, S.One, S.One),
        (a * coth(b)**c * sinh(b)**c, a * cosh(b)**c, S.One, S.One),
        (a * tanh(b)**c / sinh(b)**c, a / cosh(b)**c, S.One, S.One),
        (a * coth(b)**c / cosh(b)**c, a / sinh(b)**c, S.One, S.One),
        (a * coth(b)**c * tanh(b)**c, a, S.One, S.One),
        (c * (tanh(a) + tanh(b)) / (1 + tanh(a) * tanh(b)), tanh(a + b) * c,
         S.One, S.One),
    )

    matchers_add = (
        (c * sin(a) * cos(b) + c * cos(a) * sin(b) + d, sin(a + b) * c + d),
        (c * cos(a) * cos(b) - c * sin(a) * sin(b) + d, cos(a + b) * c + d),
        (c * sin(a) * cos(b) - c * cos(a) * sin(b) + d, sin(a - b) * c + d),
        (c * cos(a) * cos(b) + c * sin(a) * sin(b) + d, cos(a - b) * c + d),
        (c * sinh(a) * cosh(b) + c * sinh(b) * cosh(a) + d,
         sinh(a + b) * c + d),
        (c * cosh(a) * cosh(b) + c * sinh(a) * sinh(b) + d,
         cosh(a + b) * c + d),
    )

    # for cos(x)**2 + sin(x)**2 -> 1
    matchers_identity = (
        (a * sin(b)**2, a - a * cos(b)**2),
        (a * tan(b)**2, a * (1 / cos(b))**2 - a),
        (a * cot(b)**2, a * (1 / sin(b))**2 - a),
        (a * sin(b + c), a * (sin(b) * cos(c) + sin(c) * cos(b))),
        (a * cos(b + c), a * (cos(b) * cos(c) - sin(b) * sin(c))),
        (a * tan(b + c), a * ((tan(b) + tan(c)) / (1 - tan(b) * tan(c)))),
        (a * sinh(b)**2, a * cosh(b)**2 - a),
        (a * tanh(b)**2, a - a * (1 / cosh(b))**2),
        (a * coth(b)**2, a + a * (1 / sinh(b))**2),
        (a * sinh(b + c), a * (sinh(b) * cosh(c) + sinh(c) * cosh(b))),
        (a * cosh(b + c), a * (cosh(b) * cosh(c) + sinh(b) * sinh(c))),
        (a * tanh(b + c), a * ((tanh(b) + tanh(c)) / (1 + tanh(b) * tanh(c)))),
    )

    # Reduce any lingering artifacts, such as sin(x)**2 changing
    # to 1-cos(x)**2 when sin(x)**2 was "simpler"
    artifacts = (
        (a - a * cos(b)**2 + c, a * sin(b)**2 + c, cos),
        (a - a * (1 / cos(b))**2 + c, -a * tan(b)**2 + c, cos),
        (a - a * (1 / sin(b))**2 + c, -a * cot(b)**2 + c, sin),
        (a - a * cosh(b)**2 + c, -a * sinh(b)**2 + c, cosh),
        (a - a * (1 / cosh(b))**2 + c, a * tanh(b)**2 + c, cosh),
        (a + a * (1 / sinh(b))**2 + c, a * coth(b)**2 + c, sinh),

        # same as above but with noncommutative prefactor
        (a * d - a * d * cos(b)**2 + c, a * d * sin(b)**2 + c, cos),
        (a * d - a * d * (1 / cos(b))**2 + c, -a * d * tan(b)**2 + c, cos),
        (a * d - a * d * (1 / sin(b))**2 + c, -a * d * cot(b)**2 + c, sin),
        (a * d - a * d * cosh(b)**2 + c, -a * d * sinh(b)**2 + c, cosh),
        (a * d - a * d * (1 / cosh(b))**2 + c, a * d * tanh(b)**2 + c, cosh),
        (a * d + a * d * (1 / sinh(b))**2 + c, a * d * coth(b)**2 + c, sinh),
    )

    _trigpat = (a, b, c, d, matchers_division, matchers_add, matchers_identity,
                artifacts)
    return _trigpat