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;
}
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;
}
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");
}
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);
}
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);
}
}
Aggregations