use of org.matheclipse.core.eval.exception.AbortException in project symja_android_library by axkr.
the class TeXParser method msubsup.
private IExpr msubsup(NodeList list, NodeList parentList, int[] position, int precedence) {
// \\int_0^\\infty a dx
if (list.getLength() > 0) {
Node arg0 = list.item(0);
IExpr head = toExpr(arg0);
if (head.isBuiltInSymbol()) {
ISymbol dummySymbol = F.Dummy("msubsup$" + counter++);
IExpr arg2 = dummySymbol;
if (list.getLength() >= 2) {
Node arg1 = list.item(1);
IExpr a1 = toExpr(arg1);
if (list.getLength() == 3) {
IExpr a2 = toExpr(list.item(2));
arg2 = F.list(dummySymbol, a1, a2);
} else if (list.getLength() == 2) {
arg2 = F.list(dummySymbol, a1);
}
}
if (parentList != null) {
while (position[0] < parentList.getLength()) {
if (head.equals(S.Integrate)) {
return integrate(parentList, position, dummySymbol, arg2);
} else {
IExpr arg1 = convert(parentList, position, null, Integer.MAX_VALUE);
return F.binaryAST2(head, arg1, arg2);
}
}
}
}
}
if (list.getLength() == 3) {
Node node = list.item(0);
IExpr a1 = toExpr(node);
node = list.item(1);
IExpr a2 = toExpr(node);
node = list.item(2);
IExpr a3 = toExpr(node);
return F.ternaryAST3(S.Subsuperscript, a1, a2, a3);
}
throw new AbortException();
}
use of org.matheclipse.core.eval.exception.AbortException in project symja_android_library by axkr.
the class TeXParser method munderover.
private IExpr munderover(NodeList list, NodeList parentList, int[] position, int precedence) {
if (list.getLength() > 0) {
Node arg0 = list.item(0);
IExpr head = toExpr(arg0);
if (head.isBuiltInSymbol()) {
ISymbol sym = F.Dummy("munderover$" + counter++);
IExpr arg2 = sym;
if (list.getLength() >= 2) {
Node arg1 = list.item(1);
IExpr a1 = toExpr(arg1);
if (a1.isEqual() && a1.first().isSymbol()) {
sym = (ISymbol) a1.first();
arg2 = sym;
a1 = a1.second();
}
if (list.getLength() == 3) {
IExpr a2 = toExpr(list.item(2));
arg2 = F.list(sym, a1, a2);
} else if (list.getLength() == 2) {
arg2 = F.list(sym, a1);
}
}
if (parentList != null && position[0] < parentList.getLength()) {
IExpr arg1 = convert(parentList, position, null, Integer.MAX_VALUE);
return F.binaryAST2(head, arg1, arg2);
}
}
}
// }
throw new AbortException();
}
use of org.matheclipse.core.eval.exception.AbortException in project symja_android_library by axkr.
the class TeXParser method msub.
private IExpr msub(NodeList list) {
if (list.getLength() == 2) {
Node arg1 = list.item(0);
Node arg2 = list.item(1);
IExpr a1 = toExpr(arg1);
IExpr a2 = toExpr(arg2);
if (a1.equals(S.Limit)) {
// Limit(#,a2)&
return F.Function(F.Limit(F.Slot1, a2));
}
return F.binaryAST2(S.Subscript, a1, a2);
}
throw new AbortException();
}
use of org.matheclipse.core.eval.exception.AbortException in project symja_android_library by axkr.
the class TeXParser method mfrac.
private IExpr mfrac(NodeList list) {
IASTAppendable frac = F.TimesAlloc(2);
if (list.getLength() > 0) {
Node temp = list.item(0);
frac.append(toExpr(temp));
if (1 < list.getLength()) {
temp = list.item(1);
frac.append(F.Power(toExpr(temp), -1));
} else {
throw new AbortException();
}
}
if (frac.isTimes() && frac.first().isSymbol() && frac.size() == 3 && frac.second().isPowerReciprocal()) {
ISymbol d = (ISymbol) frac.first();
if (d.getSymbolName().equals("d")) {
IExpr dDenominator = frac.second().first();
if (dDenominator.isSymbol()) {
String str = ((ISymbol) dDenominator).getSymbolName();
if (str.startsWith("d")) {
str = str.substring(1);
return F.Function(F.D(F.Slot1, F.$s(str)));
}
}
}
}
return frac;
}
use of org.matheclipse.core.eval.exception.AbortException in project symja_android_library by axkr.
the class Integrate method integrateByRubiRules.
/**
* Use the <a href="http://www.apmaths.uwo.ca/~arich/">Rubi - Symbolic Integration Rules</a> to
* integrate the expression.
*
* @param ast
* @return
*/
private static IExpr integrateByRubiRules(IAST arg1, IExpr x, IAST ast, EvalEngine engine) {
// EvalEngine engine = EvalEngine.get();
if (arg1.isFreeAST(s -> s.isSymbol() && ((ISymbol) s).isContext(Context.RUBI))) {
int limit = engine.getRecursionLimit();
boolean quietMode = engine.isQuietMode();
ISymbol head = arg1.topHead();
if (head.isNumericFunctionAttribute() || INT_RUBI_FUNCTIONS.contains(head) || head.getSymbolName().startsWith("ยง")) {
boolean newCache = false;
try {
if (engine.rememberASTCache != null) {
IExpr result = engine.rememberASTCache.getIfPresent(ast);
if (result != null) {
// &&engine.getRecursionCounter()>0) {
if (result.isPresent()) {
return result;
}
return callRestIntegrate(arg1, x, engine);
}
} else {
newCache = true;
engine.rememberASTCache = CacheBuilder.newBuilder().maximumSize(50).build();
}
try {
engine.setQuietMode(true);
if (limit <= 0 || limit > Config.INTEGRATE_RUBI_RULES_RECURSION_LIMIT) {
engine.setRecursionLimit(Config.INTEGRATE_RUBI_RULES_RECURSION_LIMIT);
}
engine.rememberASTCache.put(ast, F.NIL);
IExpr temp = S.Integrate.evalDownRule(EvalEngine.get(), ast);
if (temp.isPresent()) {
if (temp.equals(ast)) {
if (LOGGER.isDebugEnabled()) {
engine.setQuietMode(false);
IOFunctions.printMessage(S.Integrate, "rubiendless", F.list(temp), engine);
}
return F.NIL;
}
if (temp.isAST()) {
engine.rememberASTCache.put(ast, temp);
}
return temp;
}
} catch (RecursionLimitExceeded rle) {
// engine.printMessage("Integrate(Rubi recursion): " +
// Config.INTEGRATE_RUBI_RULES_RECURSION_LIMIT
// + " exceeded: " + ast.toString());
engine.setRecursionLimit(limit);
LOGGER.log(engine.getLogLevel(), "Integrate(Rubi recursion)", rle);
return F.NIL;
} catch (RuntimeException rex) {
engine.setRecursionLimit(limit);
LOGGER.log(engine.getLogLevel(), "Integrate Rubi recursion limit {} RuntimeException: {}", Config.INTEGRATE_RUBI_RULES_RECURSION_LIMIT, ast, rex);
return F.NIL;
}
} catch (AbortException ae) {
LOGGER.debug("Integrate.integrateByRubiRules() aborted", ae);
} catch (final FailedException fe) {
LOGGER.debug("Integrate.integrateByRubiRules() failed", fe);
} finally {
engine.setRecursionLimit(limit);
if (newCache) {
engine.rememberASTCache = null;
}
engine.setQuietMode(quietMode);
}
}
}
return F.NIL;
}
Aggregations