Пример #1
0
def finite_check(f, x, L):
    def check_fx(exprs, x):
        return x not in exprs.free_symbols

    def check_sincos(expr, x, L):
        if type(expr) == sin or type(expr) == cos:
            sincos_args = expr.args[0]

            if sincos_args.match(a * (pi / L) * x + b) is not None:
                return True
            else:
                return False

    expr = sincos_to_sum(TR2(TR1(f)))
    res_expr = S.Zero
    add_coeff = expr.as_coeff_add()
    res_expr += add_coeff[0]

    a = Wild('a', properties=[
        lambda k: k.is_Integer,
        lambda k: k != S.Zero,
    ])
    b = Wild('b',
             properties=[
                 lambda k: x not in k.free_symbols or k == S.Zero,
             ])

    for s in add_coeff[1]:
        mul_coeffs = s.as_coeff_mul()[1]
        for t in mul_coeffs:
            if not (check_fx(t, x) or check_sincos(t, x, L)):
                return False, f
        res_expr += TR10(s)
    return True, res_expr.collect(
        [sin(a * (pi / L) * x), cos(a * (pi / L) * x)])
Пример #2
0
def finite_check(f, x, L):
    def check_fx(exprs, x):
        return x not in exprs.free_symbols

    def check_sincos(_expr, x, L):
        if isinstance(_expr, (sin, cos)):
            sincos_args = _expr.args[0]

            if sincos_args.match(a * (pi / L) * x + b) is not None:
                return True
            else:
                return False

    _expr = sincos_to_sum(TR2(TR1(f)))
    add_coeff = _expr.as_coeff_add()

    a = Wild('a', properties=[
        lambda k: k.is_Integer,
        lambda k: k != S.Zero,
    ])
    b = Wild('b', properties=[
        lambda k: x not in k.free_symbols,
    ])

    for s in add_coeff[1]:
        mul_coeffs = s.as_coeff_mul()[1]
        for t in mul_coeffs:
            if not (check_fx(t, x) or check_sincos(t, x, L)):
                return False, f

    return True, _expr
Пример #3
0
def _futrig(e, **kwargs):
    """Helper for futrig."""
    from sympy.simplify.fu import (
        TR1, TR2, TR3, TR2i, TR10, L, TR10i,
        TR8, TR6, TR15, TR16, TR111, TR5, TRmorrie, TR11, TR14, TR22,
        TR12)
    from sympy.core.compatibility import _nodes

    if not e.has(TrigonometricFunction):
        return e

    if e.is_Mul:
        coeff, e = e.as_independent(TrigonometricFunction)
    else:
        coeff = S.One

    Lops = lambda x: (L(x), x.count_ops(), _nodes(x), len(x.args), x.is_Add)
    trigs = lambda x: x.has(TrigonometricFunction)

    tree = [identity,
        (
        TR3,  # canonical angles
        TR1,  # sec-csc -> cos-sin
        TR12,  # expand tan of sum
        lambda x: _eapply(factor, x, trigs),
        TR2,  # tan-cot -> sin-cos
        [identity, lambda x: _eapply(_mexpand, x, trigs)],
        TR2i,  # sin-cos ratio -> tan
        lambda x: _eapply(lambda i: factor(i.normal()), x, trigs),
        TR14,  # factored identities
        TR5,  # sin-pow -> cos_pow
        TR10,  # sin-cos of sums -> sin-cos prod
        TR11, TR6, # reduce double angles and rewrite cos pows
        lambda x: _eapply(factor, x, trigs),
        TR14,  # factored powers of identities
        [identity, lambda x: _eapply(_mexpand, x, trigs)],
        TRmorrie,
        TR10i,  # sin-cos products > sin-cos of sums
        [identity, TR8],  # sin-cos products -> sin-cos of sums
        [identity, lambda x: TR2i(TR2(x))],  # tan -> sin-cos -> tan
        [
            lambda x: _eapply(expand_mul, TR5(x), trigs),
            lambda x: _eapply(
                expand_mul, TR15(x), trigs)], # pos/neg powers of sin
        [
            lambda x:  _eapply(expand_mul, TR6(x), trigs),
            lambda x:  _eapply(
                expand_mul, TR16(x), trigs)], # pos/neg powers of cos
        TR111,  # tan, sin, cos to neg power -> cot, csc, sec
        [identity, TR2i],  # sin-cos ratio to tan
        [identity, lambda x: _eapply(
            expand_mul, TR22(x), trigs)],  # tan-cot to sec-csc
        TR1, TR2, TR2i,
        [identity, lambda x: _eapply(
            factor_terms, TR12(x), trigs)],  # expand tan of sum
        )]
    e = greedy(tree, objective=Lops)(e)

    return coeff*e
Пример #4
0
def test_TR2():
    assert TR2(tan(x)) == sin(x) / cos(x)
    assert TR2(cot(x)) == cos(x) / sin(x)
    assert TR2(tan(tan(x) - sin(x) / cos(x))) == 0