Example #1
0
def test_sympyissue_22878():
    assert (fu(8*sqrt(2)*(-exp(2*I*x)*sin(2*x) +
                          (-1 + 2*I)*exp(2*I*x)*cos(2*x) +
                          1 + I)*exp(-x*(1 + 2*I))) ==
            8*sqrt(2)*exp(-x*(1 + 2*I))*(-exp(2*I*x)*sin(2*x) +
                                         exp(2*I*x)*(-1 + 2*I)*cos(2*x) +
                                         1 + I))
Example #2
0
def test_hyper_as_trig():
    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)
Example #3
0
def test_objective():
    assert fu(sin(x)/cos(x), measure=lambda x: x.count_ops()) == \
        tan(x)
    assert fu(sin(x)/cos(x), measure=lambda x: -x.count_ops()) == \
        sin(x)/cos(x)
Example #4
0
def test_fu():
    assert fu(sin(50)**2 + cos(50)**2 + sin(pi / 6)) == Rational(3, 2)
    assert fu(sqrt(6) * cos(x) +
              sqrt(2) * sin(x)) == 2 * sqrt(2) * sin(x + pi / 3)

    eq = sin(x)**4 - cos(y)**2 + sin(y)**2 + 2 * cos(x)**2
    assert fu(eq) == cos(x)**4 - 2 * cos(y)**2 + 2

    assert fu(Rational(1, 2) - cos(2 * x) / 2) == sin(x)**2

    assert fu(sin(a)*(cos(b) - sin(b)) + cos(a)*(sin(b) + cos(b))) == \
        sqrt(2)*sin(a + b + pi/4)

    assert fu(sqrt(3) * cos(x) / 2 + sin(x) / 2) == sin(x + pi / 3)

    assert fu(1 - sin(2*x)**2/4 - sin(y)**2 - cos(x)**4) == \
        -cos(x)**2 + cos(y)**2

    assert fu(cos(4 * pi / 9)) == sin(pi / 18)
    assert fu(
        cos(pi / 9) * cos(2 * pi / 9) * cos(3 * pi / 9) *
        cos(4 * pi / 9)) == Rational(1, 16)

    assert fu(
        tan(7*pi/18) + tan(5*pi/18) - sqrt(3)*tan(5*pi/18)*tan(7*pi/18)) == \
        -sqrt(3)

    assert fu(tan(1) * tan(2)) == tan(1) * tan(2)

    expr = Mul(*[cos(2**i) for i in range(10)])
    assert fu(expr) == sin(1024) / (1024 * sin(1))