use of org.matheclipse.parser.client.math.MathException in project symja_android_library by axkr.
the class EvalControlledCallable method call.
@Override
public IExpr call() {
EvalEngine.remove();
EvalEngine.setReset(fEngine);
final StringWriter buf = new StringWriter();
try {
// fEngine.reset();<>
IExpr preRead = S.$PreRead.assignedValue();
IExpr temp;
try {
if (preRead != null && preRead.isPresent()) {
temp = fEngine.evaluate(F.unaryAST1(preRead, fExpr));
} else {
temp = fEngine.evaluate(fExpr);
}
} catch (final IterationLimitExceeded e) {
// Iteration limit of `1` exceeded.
int iterationLimit = fEngine.getIterationLimit();
IOFunctions.printMessage(S.$IterationLimit, "itlim", F.list(iterationLimit < 0 ? F.CInfinity : F.ZZ(iterationLimit), fExpr), fEngine);
temp = F.Hold(fExpr);
} catch (final RecursionLimitExceeded e) {
// Recursion depth of `1` exceeded during evaluation of `2`.
int recursionLimit = fEngine.getRecursionLimit();
IOFunctions.printMessage(S.$RecursionLimit, "reclim2", F.list(recursionLimit < 0 ? F.CInfinity : F.ZZ(recursionLimit), fExpr), fEngine);
temp = F.Hold(fExpr);
}
// IExpr temp = fEngine.evaluate(fExpr);
if (!fEngine.isOutListDisabled()) {
fEngine.addInOut(fExpr, temp);
}
return temp;
} catch (org.matheclipse.core.eval.exception.TimeoutException e) {
return S.$Aborted;
} catch (final SyntaxError se) {
LOGGER.error("EvalControlledCallable.call() failed", se);
} catch (final RuntimeException re) {
Throwable me = re.getCause();
if (me instanceof MathException) {
Validate.printException(buf, me);
} else {
Validate.printException(buf, re);
}
LOGGER.error(buf);
} catch (final Exception | OutOfMemoryError | StackOverflowError e) {
LOGGER.debug("EvalControlledCallable.call() failed", e);
Validate.printException(buf, e);
LOGGER.error(buf);
}
return S.$Aborted;
}
use of org.matheclipse.parser.client.math.MathException in project symja_android_library by axkr.
the class ExprEvaluatorTest method testFactorInteger.
/**
* Test the <a href=
* "https://github.com/axkr/symja_android_library/blob/master/symja_android_library/doc/functions/FactorInteger.md">FactorInteger</a>
* function.
*/
public void testFactorInteger() {
try {
ExprEvaluator util = new ExprEvaluator(false, (short) 100);
IAST function = F.FactorInteger(F.ZZ(new BigInteger("44343535354351600000003434353")));
IExpr result = util.eval(function);
assertEquals("{{149,1},{329569479697,1},{903019357561501,1}}", result.toString());
} catch (SyntaxError e) {
// catch Symja parser errors here
assertTrue(false);
} catch (MathException me) {
// catch Symja math errors here
assertTrue(false);
} catch (final Exception ex) {
assertTrue(false);
} catch (final StackOverflowError soe) {
assertTrue(false);
} catch (final OutOfMemoryError oome) {
assertTrue(false);
}
}
use of org.matheclipse.parser.client.math.MathException in project symja_android_library by axkr.
the class ExprEvaluatorTest method testStringEval004.
public void testStringEval004() {
try {
ExprEvaluator util = new ExprEvaluator();
util.defineVariable("x", 1.0);
util.defineVariable("y", 1.0);
IExpr expr = util.eval("If(x*x+y*y==0,1,Sin(x*x+y*y)/(x*x+y*y))");
assertEquals("0.454649", expr.toString());
} catch (SyntaxError e) {
// catch Symja parser errors here
System.out.println(e.getMessage());
} catch (MathException me) {
// catch Symja math errors here
System.out.println(me.getMessage());
} catch (Exception e) {
e.printStackTrace();
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
use of org.matheclipse.parser.client.math.MathException in project symja_android_library by axkr.
the class ExprEvaluatorTest method testStringEval003.
public void testStringEval003() {
try {
ExprEvaluator util = new ExprEvaluator();
IExpr expr = util.eval("x^2+y+a*x+b*y+c");
assertEquals("c+a*x+x^2+y+b*y", expr.toString());
final IAST variables = F.List(F.symbol("x"), F.symbol("y"));
ExprPolynomialRing ring = new ExprPolynomialRing(ExprRingFactory.CONST, variables, variables.argSize(), ExprTermOrderByName.Lexicographic, false);
ExprPolynomial poly = ring.create(expr);
assertEquals("x^2 + a x + ( 1+b ) y + c ", poly.toString());
// x degree
assertEquals(2, poly.degree(0));
// y degree
assertEquals(1, poly.degree(1));
// show internal structure:
assertEquals("{{2,0}->1,{1,0}->a,{0,1}->1+b,{0,0}->c}", poly.coefficientRules().toString());
System.out.println(poly.coefficientRules());
for (ExprMonomial monomial : poly) {
System.out.println(monomial.toString());
}
} catch (SyntaxError e) {
// catch Symja parser errors here
System.out.println(e.getMessage());
} catch (MathException me) {
// catch Symja math errors here
System.out.println(me.getMessage());
} catch (Exception e) {
e.printStackTrace();
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
use of org.matheclipse.parser.client.math.MathException in project symja_android_library by axkr.
the class ExprEvaluatorTest method testStringVariables001.
public void testStringVariables001() {
try {
ExprEvaluator util = new ExprEvaluator(false, (short) 100);
IExpr result = util.eval("Variables(termquery$$fuchs*(termquery$$huhn*(1-termquery$$schaf)+termquery$$schaf)+(1-termquery$$fuchs)*termquery$$schaf*termquery$$wolf)");
assertEquals("{termquery$$fuchs,termquery$$huhn,termquery$$schaf,termquery$$wolf}", result.toString());
} catch (SyntaxError e) {
// catch Symja parser errors here
assertTrue(false);
} catch (MathException me) {
// catch Symja math errors here
assertTrue(false);
} catch (final Exception ex) {
assertTrue(false);
} catch (final StackOverflowError soe) {
assertTrue(false);
} catch (final OutOfMemoryError oome) {
assertTrue(false);
}
}
Aggregations