/** * Assign the associated EvalEngine to the current thread. Every subsequent action evaluation in this thread affects * the EvalEngine in this class. */ public void startRequest() { EvalEngine.set(fEvalEngine); }
/** * Constructor for an <code>IExpr</code> object evaluator. By default no output history for the <code>Out()</code> * function is stored in the evaluation engine. <code>$ans</code> won't get evaluate to the last result. * * @parm engine * @param outListDisabled * if <code>false</code> create a <code>LastCalculationsHistory(historyCapacity)</code>, otherwise no * history of the last calculations will be saved and the <code>Out()</code> function (or * <code>$ans</code> variable or the <code>%</code> operator) will be unevaluated. * @param historyCapacity * the number of last entries of the calculations which should be stored. */ public ExprEvaluator(EvalEngine engine, boolean outListDisabled, int historyCapacity) { this.fVariableMap = new IdentityHashMap<>(); this.fVariables = new ArrayList<>(); this.engine = engine; EvalEngine.set(engine); if (!outListDisabled) { engine.setOutListDisabled(outListDisabled, historyCapacity); } }
/** * Runs the evaluation of the given math formula <code>String</code> in a time * limited thread * * @param traceEvaluation * */ public IExpr constrainedEval(final Writer writer, final String inputString, boolean traceEvaluation) throws Exception { fEvaluationResult = null; fException = null; fParsedExpression = null; fEvalEngine.setStopRequested(false); fTraceEvaluation = traceEvaluation; try { EvalEngine.set(fEvalEngine); fParsedExpression = fEvalEngine.parse(inputString); } catch (final RuntimeException e) { throw e; } return constrainedEval(writer, fParsedExpression); }
/** * Assign the associated EvalEngine to the current thread. Every subsequent * action evaluation in this thread affects the EvalEngine in this class. */ public void startRequest() { EvalEngine.set(fEvalEngine); }
/** * Runs the evaluation of the given math formula <code>String</code> in a time * limited thread * * @param traceEvaluation * */ public IExpr constrainedEval(final Writer writer, final String inputString, boolean traceEvaluation) throws Exception { fEvaluationResult = F.NIL; fException = null; fParsedExpression = null; fEvalEngine.setStopRequested(false); fTraceEvaluation = traceEvaluation; try { EvalEngine.set(fEvalEngine); fParsedExpression = fEvalEngine.parse(inputString); } catch (final RuntimeException e) { throw e; } return constrainedEval(writer, fParsedExpression); }
/** * Copied from MathMLUtilities.startRequest() - the parent class of EvalUtilities: Assign the associated EvalEngine * to the current thread. Every subsequent action evaluation in this thread affects the EvalEngine in this class. */ public void evalEngineAttach() { EvalEngine.set(myEvalEngine); }
/** * Assign the associated EvalEngine to the current thread. Every subsequent * action evaluation in this thread affects the EvalEngine in this class. */ public void startRequest() { EvalEngine.set(fEvalEngine); }
/** * Assign the associated EvalEngine to the current thread. Every subsequent action evaluation in this thread affects * the EvalEngine in this class. */ public void startRequest() { EvalEngine.set(fEvalEngine); }
public EvalEngine(final String sessionID, final int recursionLimit, final int iterationLimit, final PrintStream out, boolean relaxedSyntax) { fSessionID = sessionID; // fExpressionFactory = f; fRecursionLimit = recursionLimit; fIterationLimit = iterationLimit; fOutPrintStream = out; fRelaxedSyntax = relaxedSyntax; // fNamespace = fExpressionFactory.getNamespace(); init(); // set this EvalEngine to the thread local set(this); // set up global symbols // F.initSymbols(); }
/** * * @param evalEngine * @param relaxedSyntax * if <code>true</code> use '(...)' instead of '[...]' to * parenthesize the arguments of a function. */ public TeXUtilities(final EvalEngine evalEngine, final boolean relaxedSyntax) { fEvalEngine = evalEngine; // set the thread local instance EvalEngine.set(evalEngine); fTeXFactory = new TeXFormFactory(); fParser = new ExprParser(evalEngine, relaxedSyntax); }
public TeXUtilities(final EvalEngine evalEngine) { fEvalEngine = evalEngine; // set the thread local instance EvalEngine.set(evalEngine); fTeXFactory = new TeXFormFactory(); fParser = new Parser(); }
/** * 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; }
/** * 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; }
/** {@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(); } } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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(); } }
/** * 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; }