Exemple #1
0
def rubi_integrate(expr, var, showsteps=False):
    """
    Rule based algorithm for integration. Integrates the expression by applying
    transformation rules to the expression.

    Returns `Integrate` if an expression cannot be integrated.

    Parameters
    ==========
    expr : integrand expression
    var : variable of integration

    Returns Integral object if unable to integrate.
    """
    rubi = LoadRubiReplacer().load()
    expr = expr.replace(sym_exp, rubi_exp)
    expr = process_trig(expr)
    expr = rubi_powsimp(expr)
    if isinstance(expr, (int, Integer)) or isinstance(expr, (float, Float)):
        return S(expr) * var
    if isinstance(expr, Add):
        results = 0
        for ex in expr.args:
            results += rubi.replace(Integral(ex, var))
        return process_final_integral(results)

    results = util_rubi_integrate(Integral(expr, var))
    return process_final_integral(results)
Exemple #2
0
def rubi_integrate(expr, var, showsteps=False):
    '''
    Rule based algorithm for integration. Integrates the expression by applying
    transformation rules to the expression.

    Returns `Integrate` if an expression cannot be integrated.

    Parameters
    ==========
    expr : integrand expression
    var : variable of integration

    Returns Integral object if unable to integrate.
    '''
    expr = expr.replace(sym_exp, exp)
    rules_applied[:] = []
    expr = process_trig(expr)
    expr = rubi_powsimp(expr)
    if isinstance(expr, (int, Integer)) or isinstance(expr, (float, Float)):
        return S(expr) * var
    if isinstance(expr, Add):
        results = 0
        for ex in expr.args:
            rules_applied[:] = []
            results += rubi.replace(Integral(ex, var))
            rules_applied[:] = []
        return process_final_integral(results)

    results = rubi.replace(Integral(expr, var), max_count=10)
    return process_final_integral(results)
Exemple #3
0
def rubi_integrate(expr, var, showsteps=False):
    '''
    Rule based algorithm for integration. Integrates the expression by applying
    transformation rules to the expression.

    Returns `Integrate` if an expression cannot be integrated.

    Parameters
    ==========
    expr : integrand expression
    var : variable of integration

    Returns Integral object if unable to integrate.
    '''
    expr = expr.replace(sym_exp, exp)
    rules_applied[:] = []
    expr = process_trig(expr)
    expr = rubi_powsimp(expr)
    if isinstance(expr, (int, Integer)) or isinstance(expr, (float, Float)):
        return S(expr)*var
    if isinstance(expr, Add):
        results = 0
        for ex in expr.args:
            rules_applied[:] = []
            results += rubi.replace(Integral(ex, var))
            rules_applied[:] = []
        return process_final_integral(results)

    results = rubi.replace(Integral(expr, var), max_count = 10)
    return process_final_integral(results)
Exemple #4
0
def util_rubi_integrate(expr, showsteps=False, max_loop=10):
    rubi = LoadRubiReplacer().load()
    expr = process_trig(expr)
    expr = expr.replace(sym_exp, rubi_exp)
    for i in range(max_loop):
        results = expr.replace(lambda x: isinstance(x, Integral),
                               lambda x: rubi.replace(x, max_count=10))
        if expr == results:
            return results
    return results
Exemple #5
0
def util_rubi_integrate(expr, var, showsteps=False):
    expr = process_trig(expr)
    expr = expr.replace(sym_exp, exp)
    if isinstance(expr, (int, Integer)) or isinstance(expr, (float, Float)):
        return S(expr) * var
    if isinstance(expr, Add):
        return rubi_integrate(expr, var)
    if len(rules_applied) > 10:
        if _has_cycle() or len(rules_applied) > 20:
            return Integrate(expr, var)
    results = rubi.replace(Integral(expr, var), max_count=10)
    rules_applied[:] = []
    return results
Exemple #6
0
def util_rubi_integrate(expr, var, showsteps=False):
    expr = process_trig(expr)
    expr = expr.replace(sym_exp, exp)
    if isinstance(expr, (int, Integer)) or isinstance(expr, (float, Float)):
        return S(expr)*var
    if isinstance(expr, Add):
        return rubi_integrate(expr, var)
    if len(rules_applied) > 10:
        if _has_cycle() or len(rules_applied) > 20:
            return Integrate(expr, var)
    results = rubi.replace(Integral(expr, var), max_count = 10)
    rules_applied[:] = []
    return results