Search in sources :

Example 71 with EvalEngine

use of org.matheclipse.core.eval.EvalEngine 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 72 with EvalEngine

use of org.matheclipse.core.eval.EvalEngine 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)

Example 73 with EvalEngine

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

the class MainTestCase method testSystem400.

public void testSystem400() {
    EvalEngine engine = EvalEngine.get();
    IExpr exprNumerator = engine.parse("8+12*x+20*x^2+12*x^3+8*x^4+3*x^5");
    IExpr exprDenominator = engine.parse("8*x+12*x^3+6*x^5+x^7");
    IExpr[] result = Algebra.cancelGCD(exprNumerator, exprDenominator);
    assertEquals(result[0].toString(), "1");
    assertEquals(result[1].toString(), "4+6*x+8*x^2+3*x^3");
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 74 with EvalEngine

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

the class MathMLPresentationTestCase method setUp.

/**
	 * The JUnit setup method
	 */
protected void setUp() {
    try {
        // F.initSymbols();
        EvalEngine engine = new EvalEngine(false);
        mathUtil = new MathMLUtilities(engine, false, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
// fParser = new Parser(null);
// ExpressionFactory factory = new ExpressionFactory(new Namespace());
// fParser.setFactory(factory);
// fMathMLFactory = new MathMLFormFactory(factory);
}
Also used : MathMLUtilities(org.matheclipse.core.eval.MathMLUtilities) EvalEngine(org.matheclipse.core.eval.EvalEngine)

Example 75 with EvalEngine

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

the class PatternMatchingTestCase method checkPattern.

public void checkPattern(String patternString, String evalString, String resultString) {
    try {
        ASTNode node = fParser.parse(patternString);
        EvalEngine engine = EvalEngine.get();
        IExpr pat = new AST2Expr(false, engine).convert(node);
        node = fParser.parse(evalString);
        IExpr eval = new AST2Expr(false, engine).convert(node);
        PatternMatcher matcher = new PatternMatcher(pat);
        if (matcher.test(eval)) {
            ArrayList<IExpr> resultList = new ArrayList<IExpr>();
            matcher.getPatterns(resultList, pat);
            assertEquals(resultList.toString(), resultString);
            return;
        }
        assertEquals("", resultString);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("", resultString);
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) EvalEngine(org.matheclipse.core.eval.EvalEngine) ArrayList(java.util.ArrayList) IExpr(org.matheclipse.core.interfaces.IExpr) PatternMatcher(org.matheclipse.core.patternmatching.PatternMatcher) AST2Expr(org.matheclipse.core.convert.AST2Expr)

Aggregations

EvalEngine (org.matheclipse.core.eval.EvalEngine)131 IExpr (org.matheclipse.core.interfaces.IExpr)71 IAST (org.matheclipse.core.interfaces.IAST)39 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)20 ISymbol (org.matheclipse.core.interfaces.ISymbol)20 IOException (java.io.IOException)13 F (org.matheclipse.core.expression.F)12 ExprEvaluator (org.matheclipse.core.eval.ExprEvaluator)11 S (org.matheclipse.core.expression.S)11 IInteger (org.matheclipse.core.interfaces.IInteger)11 ASTNode (org.matheclipse.parser.client.ast.ASTNode)11 LogManager (org.apache.logging.log4j.LogManager)10 Logger (org.apache.logging.log4j.Logger)10 AST2Expr (org.matheclipse.core.convert.AST2Expr)9 ExprParser (org.matheclipse.core.parser.ExprParser)9 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)8 MathException (org.matheclipse.parser.client.math.MathException)8 ArrayList (java.util.ArrayList)7 Config (org.matheclipse.core.basic.Config)7 IASTMutable (org.matheclipse.core.interfaces.IASTMutable)7