public IExpr evalParsedExpr(final IExpr parsedExpr, boolean attachFlag, boolean resetFlag) throws RuntimeException { if (parsedExpr != null) { if (attachFlag) { evalEngineAttach(); } if (resetFlag) { myEvalEngine.reset(); } IExpr temp = myEvalEngine.evaluate(parsedExpr); // Stu B22 - Commented out this line as recommended by Axel. // It is keeping a history of values for future access via the Out[] function. // But this causes RAM usage to grow over time! myEvalEngine.addOut(temp); return temp; } return null; } /**
/** * Converts the objectExpression into a TeX expression and writes the result * to the given <code>Writer</code> * * @param objectExpression * @param out */ synchronized public void toTeX(final IExpr objectExpression, final Writer out) { final StringBuilder buf = new StringBuilder(); if (objectExpression != null) { IExpr result = objectExpression; if (objectExpression.isAST()) { fEvalEngine.reset(); result = fEvalEngine.evalHoldPattern((IAST) objectExpression, true, true); } fTeXFactory.convert(buf, result, 0); try { out.write(buf.toString()); } catch (final Throwable e) { // parsedExpression == null ==> fError occured } } }
/** * Parse the given <code>expression String</code> without evaluation * * @param inputExpression * @return * @throws SyntaxError */ public IExpr parse(final String inputExpression) { // try { if (inputExpression != null) { EvalEngine.set(engine); engine.reset(); return engine.parse(inputExpression); } // } finally { // EvalEngine.remove(); // } return null; }
/** * Evaluate the <code>inputExpression</code> and return the resulting * expression. * * @param inputExpression * the expression which should be evaluated. * @return */ public IExpr evaluate(final String inputExpression) throws Exception { IExpr parsedExpression = null; if (inputExpression != null) { startRequest(); fEvalEngine.reset(); parsedExpression = fEvalEngine.parse(inputExpression); if (parsedExpression != null) { fEvalEngine.reset(); IExpr temp = fEvalEngine.evaluate(parsedExpression); fEvalEngine.addOut(temp); return temp; } } return null; }
public IExpr evalMathText(final String inTextExpr) throws Exception { IExpr parsedExpression = null; if (inTextExpr != null) { evalEngineAttach(); myEvalEngine.reset(); parsedExpression = myEvalEngine.parse(inTextExpr); return evalParsedExpr(parsedExpression, false, true); } return null; }
/** * Evaluate the <code>parsedExpression</code> and return the * <code>Trace[parsedExpression]</code> (i.e. all (sub-)expressions needed to * calculate the result). * * @param parsedExpression * the expression which should be evaluated. * @param matcher * a filter which determines the expressions which should be traced, * If the matcher is set to <code>null</code>, all expressions are * traced. * @param list * an IAST object which will be cloned for containing the traced * expressions. Typically a <code>F.List()</code> will be used. * @return */ public IAST evalTrace(final IExpr parsedExpression, Predicate<IExpr> matcher, IAST list) throws RuntimeException { if (parsedExpression != null) { startRequest(); fEvalEngine.reset(); IAST temp = fEvalEngine.evalTrace(parsedExpression, matcher, list); return temp; } return null; }
/** * Parse the given <code>expression String</code> and evaluate it to an IExpr value * * @param inputExpression * @return * @throws SyntaxError */ public IExpr eval(final String inputExpression) { if (inputExpression != null) { EvalEngine.set(engine); engine.reset(); fExpr = engine.parse(inputExpression); if (fExpr != null) { return eval(fExpr); } // call EvalEngine.remove() at the end of the thread if necessary } return null; }
/** * Evaluate the <code>inputExpression</code> and return the resulting * expression. * * @param inputExpression * the expression which should be evaluated. * @return <code>F.NIL</code>, if the inputExpression is <code>null</code> * */ public IExpr evaluate(final String inputExpression) throws MathException { if (inputExpression != null) { startRequest(); EvalEngine.set(fEvalEngine);; fEvalEngine.reset(); IExpr parsedExpression = fEvalEngine.parse(inputExpression); if (parsedExpression != null) { // F.join(); fEvalEngine.reset(); IExpr temp = fEvalEngine.evaluate(parsedExpression); fEvalEngine.addOut(temp); return temp; } } return F.NIL; }
/** * Evaluate the <code>parsedExpression</code> and return the resulting * expression. * * @param parsedExpression * the expression which should be evaluated. * @return */ public IExpr evaluate(final IExpr parsedExpression) throws RuntimeException { if (parsedExpression != null) { startRequest(); fEvalEngine.reset(); IExpr temp = fEvalEngine.evaluate(parsedExpression); fEvalEngine.addOut(temp); return temp; } return null; }
/** * Evaluate the <code>parsedExpression</code> and return the * <code>Trace[parsedExpression]</code> (i.e. all (sub-)expressions needed * to calculate the result). * * @param parsedExpression * the expression which should be evaluated. * @param matcher * a filter which determines the expressions which should be * traced, If the matcher is set to <code>null</code>, all * expressions are traced. * @param list * an IAST object which will be cloned for containing the traced * expressions. Typically a <code>F.List()</code> will be used. * @return */ public IAST evalTrace(final IExpr parsedExpression, Predicate<IExpr> matcher, IAST list) throws RuntimeException { if (parsedExpression != null) { // F.join(); startRequest(); EvalEngine.set(fEvalEngine); fEvalEngine.reset(); IAST temp = fEvalEngine.evalTrace(parsedExpression, matcher, list); return temp; } return F.NIL; }
/** * Evaluate an expression. If evaluation is not possible return the input object. * * @param expr * the expression which should be evaluated * @return the evaluated object */ public IExpr eval(final IExpr expr) { fExpr = expr; // F.join(); EvalEngine.set(engine); engine.reset(); IExpr temp = engine.evaluate(expr); if (!engine.isOutListDisabled()) { engine.addOut(temp); } return temp; }
/** {@inheritDoc} */ @Override synchronized public void toMathML(final String inputExpression, final Writer out) { try { EvalEngine.set(fEvalEngine); fEvalEngine.reset(); final IExpr result = evaluate(inputExpression); if (result.isPresent()) { toMathML(result, out); } } catch (final Throwable e) { if (Config.SHOW_STACKTRACE) { e.printStackTrace(); } } }
/** * Converts the inputExpression string into a MathML expression and writes * the result to the given <code>Writer</code> * * @param inputExpression * @param out */ public String toJavaForm(final String inputExpression) throws MathException { if (inputExpression != null) { EvalEngine.set(fEvalEngine); fEvalEngine.reset(); ExprParser parser = new ExprParser(fEvalEngine); IExpr parsedExpression = parser.parse(inputExpression); // node = fEvalEngine.parseNode(inputExpression); // parsedExpression = AST2Expr.CONST.convert(node, fEvalEngine); return parsedExpression.internalFormString(false, 0); } return ""; }
/** * Evaluate the <code>parsedExpression</code> and return the resulting * expression. * * @param parsedExpression * the expression which should be evaluated. * @return */ public IExpr evaluate(final IExpr parsedExpression) throws MathException { if (parsedExpression != null) { // F.join(); startRequest(); EvalEngine.set(fEvalEngine); fEvalEngine.reset(); IExpr temp = fEvalEngine.evaluate(parsedExpression); fEvalEngine.addOut(temp); return temp; } return F.NIL; }
/** * Evaluate an expression to a double value. * * @param expr * a Symja expression * @return <code>Double.NaN</code> if no <code>double</code> value could be evaluated */ public double evalf(final IExpr expr) { EvalEngine.set(engine); engine.reset(); IExpr temp = eval(F.N(expr)); if (temp.isReal()) { return ((ISignedNumber) temp).doubleValue(); } return Double.NaN; }
if (parsedExpression != null) { fEvalEngine.reset(); IAST temp = fEvalEngine.evalTrace(parsedExpression, matcher, list); fEvalEngine.addOut(temp);
/** * Parse the given <code>inputExpression</code> String and evaluate it to a <code>double</code> value if possible. * * @param inputExpression * an input expression * @return <code>Double.NaN</code> if no <code>double</code> value could be evaluated * @throws SyntaxError */ public double evalf(final String inputExpression) { if (inputExpression != null) { EvalEngine.set(engine); engine.reset(); fExpr = engine.parse(inputExpression); if (fExpr != null) { IExpr temp = eval(F.N(fExpr)); if (temp.isReal()) { return ((ISignedNumber) temp).doubleValue(); } } } return Double.NaN; }
/** * Basic call which catches no exceptions */ @Override public IExpr call() throws Exception { EvalEngine.remove(); EvalEngine.set(fEngine); try { fEngine.reset(); IExpr temp = fEngine.evaluate(fExpr); if (!fEngine.isOutListDisabled()) { fEngine.addOut(temp); } return temp; } catch (org.matheclipse.core.eval.exception.TimeoutException e) { return F.$Aborted; // } catch (RuntimeException rex) { // rex.printStackTrace(); // return F.$Aborted; } finally { EvalEngine.remove(); } }
evalEngine.reset(); IExpr temp = evalEngine.evaluate(parsedExpression); evalEngine.addOut(temp);