Esempio n. 1
0
    def get_rubi_object():
        """
        Returns rubi ManyToOneReplacer by adding all rules from different modules.

        Uncomment the lines to add integration capabilities of that module.

        Currently, there are parsing issues with special_function,
        derivative and miscellaneous_integration. Hence they are commented.
        """
        from sympy.integrals.rubi.rules.integrand_simplification import (
            integrand_simplification, )
        from sympy.integrals.rubi.rules.linear_products import linear_products
        from sympy.integrals.rubi.rules.quadratic_products import quadratic_products
        from sympy.integrals.rubi.rules.binomial_products import binomial_products
        from sympy.integrals.rubi.rules.trinomial_products import trinomial_products
        from sympy.integrals.rubi.rules.miscellaneous_algebraic import (
            miscellaneous_algebraic, )
        from sympy.integrals.rubi.rules.exponential import exponential
        from sympy.integrals.rubi.rules.logarithms import logarithms
        from sympy.integrals.rubi.rules.sine import sine
        from sympy.integrals.rubi.rules.tangent import tangent
        from sympy.integrals.rubi.rules.secant import secant
        from sympy.integrals.rubi.rules.miscellaneous_trig import miscellaneous_trig
        from sympy.integrals.rubi.rules.inverse_trig import inverse_trig
        from sympy.integrals.rubi.rules.hyperbolic import hyperbolic
        from sympy.integrals.rubi.rules.inverse_hyperbolic import inverse_hyperbolic
        from sympy.integrals.rubi.rules.special_functions import special_functions

        # from sympy.integrals.rubi.rules.derivative import derivative
        # from sympy.integrals.rubi.rules.piecewise_linear import piecewise_linear
        from sympy.integrals.rubi.rules.miscellaneous_integration import (
            miscellaneous_integration, )

        rules = []

        rules += integrand_simplification()
        rules += linear_products()
        rules += quadratic_products()
        rules += binomial_products()
        rules += trinomial_products()
        rules += miscellaneous_algebraic()
        rules += exponential()
        rules += logarithms()
        rules += special_functions()
        rules += sine()
        rules += tangent()
        rules += secant()
        rules += miscellaneous_trig()
        rules += inverse_trig()
        rules += hyperbolic()
        rules += inverse_hyperbolic()
        # rubi = piecewise_linear(rubi)
        rules += miscellaneous_integration()

        rubi = ManyToOneReplacer(*rules)
        return rubi, rules
Esempio n. 2
0
    def rubi_object():
        '''
        Returns rubi ManyToOneReplacer by adding all rules form different modules.

        Uncomment the lines to add integration capabilities of that module.

        Currently, there are parsing issues with special_function,
        derivative nad miscellaneous_integration. Hence they are commented.
        '''
        from sympy.integrals.rubi.rules.integrand_simplification import integrand_simplification
        from sympy.integrals.rubi.rules.linear_products import linear_products
        from sympy.integrals.rubi.rules.quadratic_products import quadratic_products
        from sympy.integrals.rubi.rules.binomial_products import binomial_products
        from sympy.integrals.rubi.rules.trinomial_products import trinomial_products
        from sympy.integrals.rubi.rules.miscellaneous_algebraic import miscellaneous_algebraic
        from sympy.integrals.rubi.rules.exponential import exponential
        from sympy.integrals.rubi.rules.logarithms import logarithms
        from sympy.integrals.rubi.rules.sine import sine
        from sympy.integrals.rubi.rules.tangent import tangent
        from sympy.integrals.rubi.rules.secant import secant
        from sympy.integrals.rubi.rules.miscellaneous_trig import miscellaneous_trig
        from sympy.integrals.rubi.rules.inverse_trig import inverse_trig
        from sympy.integrals.rubi.rules.hyperbolic import hyperbolic
        from sympy.integrals.rubi.rules.inverse_hyperbolic import inverse_hyperbolic
        #from sympy.integrals.rubi.rules.special_function import special_function
        #from sympy.integrals.rubi.rules.derivative import derivative
        from sympy.integrals.rubi.rules.piecewise_linear import piecewise_linear
        #from sympy.integrals.rubi.rules.miscellaneous_integration import miscellaneous_integration

        rubi = ManyToOneReplacer()
        #rubi = integrand_simplification(rubi)
        rubi = linear_products(rubi)
        rubi = quadratic_products(rubi)
        rubi = binomial_products(rubi)
        #rubi = trinomial_products(rubi)
        #rubi = miscellaneous_algebraic(rubi)
        #rubi = exponential(rubi)
        #rubi = logarithms(rubi)
        #rubi = sine(rubi)
        #rubi = tangent(rubi)
        #rubi = secant(rubi)
        #rubi = miscellaneous_trig(rubi)
        #rubi = inverse_trig(rubi)
        #rubi = hyperbolic(rubi)
        #rubi = inverse_hyperbolic(rubi)
        #rubi = piecewise_linear(rubi)
        #rubi = miscellaneous_integration(rubi)

        return rubi
Esempio n. 3
0
def test_matchpy_optional():
    if matchpy is None:
        skip("matchpy not installed")

    from matchpy import Pattern, Substitution
    from matchpy import ManyToOneReplacer, ReplacementRule

    p = WildDot("p", optional=1)
    q = WildDot("q", optional=0)

    pattern = p*x + q

    expr1 = 2*x
    pa, subst = _get_first_match(expr1, pattern)
    assert pa == Pattern(pattern)
    assert subst == Substitution({'p': 2, 'q': 0})

    expr2 = x + 3
    pa, subst = _get_first_match(expr2, pattern)
    assert pa == Pattern(pattern)
    assert subst == Substitution({'p': 1, 'q': 3})

    expr3 = x
    pa, subst = _get_first_match(expr3, pattern)
    assert pa == Pattern(pattern)
    assert subst == Substitution({'p': 1, 'q': 0})

    expr4 = x*y + z
    pa, subst = _get_first_match(expr4, pattern)
    assert pa == Pattern(pattern)
    assert subst == Substitution({'p': y, 'q': z})

    replacer = ManyToOneReplacer()
    replacer.add(ReplacementRule(Pattern(pattern), lambda p, q: sin(p)*cos(q)))
    assert replacer.replace(expr1) == sin(2)*cos(0)
    assert replacer.replace(expr2) == sin(1)*cos(3)
    assert replacer.replace(expr3) == sin(1)*cos(0)
    assert replacer.replace(expr4) == sin(y)*cos(z)
Esempio n. 4
0
a, b, c, d, e, f, g, h, x = map(VariableSymbol, 'abcdefghx')
n, m = map(VariableSymbol, 'nm')
a_, b_, c_, d_, e_, f_, g_, h_ = map(Wildcard.dot, 'abcdefgh')
n_, m_ = map(Wildcard.dot, 'nm')

x_ = Wildcard.symbol('x')
u_ = Wildcard.symbol('u')

one = ConstantSymbol(1)
m_one = ConstantSymbol(-1)

pattern1 = Pattern(Int(Mul(a_, Pow(x_, -1)), x), FreeQ((a, ), x))
rule1 = ReplacementRule(pattern1, lambda a, x: Mul(a, Log(x)))

pattern2 = Pattern(Int(Pow(x_, m_), x), FreeQ((m, ), x),
                   NonzeroQ(Add(m_, one), (m, )))
rule2 = ReplacementRule(
    pattern2, lambda m, x: Mul(Pow(x, Add(m, one)), Pow(Add(m, one), m_one)))

rubi = ManyToOneReplacer(rule1)
rubi.add(rule2)

test = [[
    Int(Pow(x, one), x),
    Mul(Pow(Add(one, one), m_one), Pow(x, Add(one, one)))
], [Int(Mul(a, Pow(x, -1)), x), Mul(Log(x), a)]]

for i in test:
    assert rubi.replace(i[0]) == i[1]