Search in sources :

Example 1 with RecursionLimitExceeded

use of org.matheclipse.core.eval.exception.RecursionLimitExceeded in project symja_android_library by axkr.

the class Limit method lHospitalesRule.

/**
	 * Try L'hospitales rule. See <a href="http://en.wikipedia.org/wiki/L%27H%C3%B4pital%27s_rule"> Wikipedia
	 * L'Hôpital's rule</a>
	 * 
	 * @param numerator
	 * @param denominator
	 * @param data
	 *            the limits data definition
	 * @return
	 */
private static IExpr lHospitalesRule(IExpr numerator, IExpr denominator, LimitData data) {
    EvalEngine engine = EvalEngine.get();
    ISymbol x = data.getSymbol();
    int recursionLimit = engine.getRecursionLimit();
    if (recursionLimit > 0) {
        IExpr expr = F.evalQuiet(F.Times(F.D(numerator, x), F.Power(F.D(denominator, x), F.CN1)));
        return evalLimit(expr, data, false);
    }
    try {
        if (recursionLimit <= 0) {
            // set recursion limit for using l'Hospitales rule
            engine.setRecursionLimit(128);
        }
        IExpr expr = F.evalQuiet(F.Times(F.D(numerator, x), F.Power(F.D(denominator, x), F.CN1)));
        return evalLimit(expr, data, false);
    } catch (RecursionLimitExceeded rle) {
        engine.setRecursionLimit(recursionLimit);
    } finally {
        engine.setRecursionLimit(recursionLimit);
    }
    return F.NIL;
}
Also used : RecursionLimitExceeded(org.matheclipse.core.eval.exception.RecursionLimitExceeded) ISymbol(org.matheclipse.core.interfaces.ISymbol) EvalEngine(org.matheclipse.core.eval.EvalEngine) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 2 with RecursionLimitExceeded

use of org.matheclipse.core.eval.exception.RecursionLimitExceeded in project symja_android_library by axkr.

the class Integrate method integrateByParts.

/**
	 * <p>
	 * Integrate by parts rule:
	 * <code>Integrate(f'(x) * g(x), x) = f(x) * g(x) - Integrate(f(x) * g'(x),x )</code>
	 * .
	 * </p>
	 * 
	 * See
	 * <a href="http://en.wikipedia.org/wiki/Integration_by_parts">Wikipedia-
	 * Integration by parts</a>
	 * 
	 * @param f
	 *            <code>f(x)</code>
	 * @param g
	 *            <code>g(x)</code>
	 * @param x
	 * @return <code>f(x) * g(x) - Integrate(f(x) * g'(x),x )</code>
	 */
private static IExpr integrateByParts(IExpr f, IExpr g, ISymbol x) {
    EvalEngine engine = EvalEngine.get();
    int limit = engine.getRecursionLimit();
    try {
        if (limit <= 0) {
            // set recursion limit
            engine.setRecursionLimit(128);
        }
        IExpr firstIntegrate = F.eval(F.Integrate(f, x));
        if (!firstIntegrate.isFreeAST(Integrate)) {
            return F.NIL;
        }
        IExpr gDerived = F.eval(F.D(g, x));
        IExpr second2Integrate = F.eval(F.Integrate(F.Times(gDerived, firstIntegrate), x));
        if (!second2Integrate.isFreeAST(Integrate)) {
            return F.NIL;
        }
        return F.eval(F.Subtract(F.Times(g, firstIntegrate), second2Integrate));
    } catch (RecursionLimitExceeded rle) {
        engine.setRecursionLimit(limit);
    } finally {
        engine.setRecursionLimit(limit);
    }
    return F.NIL;
}
Also used : RecursionLimitExceeded(org.matheclipse.core.eval.exception.RecursionLimitExceeded) EvalEngine(org.matheclipse.core.eval.EvalEngine) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

EvalEngine (org.matheclipse.core.eval.EvalEngine)2 RecursionLimitExceeded (org.matheclipse.core.eval.exception.RecursionLimitExceeded)2 IExpr (org.matheclipse.core.interfaces.IExpr)2 ISymbol (org.matheclipse.core.interfaces.ISymbol)1