org.matheclipse.core.eval
Class EvalEngine
- java.lang.Object
-
- org.matheclipse.core.eval.EvalEngine
-
- All Implemented Interfaces:
- java.io.Serializable, IEvaluationEngine
public class EvalEngine extends java.lang.Object implements java.io.Serializable, IEvaluationEngine
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static booleanDEBUG
-
Constructor Summary
Constructors Constructor and Description EvalEngine()Public constructor for serialization.EvalEngine(boolean relaxedSyntax)EvalEngine(boolean relaxedSyntax, boolean outListDisabled)EvalEngine(F f, java.io.PrintStream out)EvalEngine(java.lang.String sessionID, int recursionLimit, int iterationLimit, java.io.PrintStream out, boolean relaxedSyntax, boolean outListDisabled)EvalEngine(java.lang.String sessionID, int recursionLimit, java.io.PrintStream out, boolean relaxedSyntax, boolean outListDisabled)Constructor for an EvaluationEngineEvalEngine(java.lang.String sessionID, java.io.PrintStream out)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanaddModifiedVariable(ISymbol arg0)For every evaluation store the list of modified variables in an internal list.booleanaddOut(IExpr arg0)Add an expression to theOut[]list.voidaddRules(IAST ruleList)voidbeginTrace(Predicate<IExpr> matcher, IAST list)IASTendTrace()static IExpreval(IExpr expr)Evaluate an expression.IExprevalAST(IAST ast)Evaluate an AST.IExprevalLoop(IExpr expr)Evaluate an object, if evaluation is not possible returnnull.static IExprevalNull(IExpr expr)Evaluate an expression.IASTevalSetAttributes(IAST ast)Transform the ast recursively, according to the attributes Flat, HoldAll, HoldFirst, HoldRest, Orderless for the left-hand-side of a Set[] or SetDelayed[] expressionIASTevalTrace(IExpr expr, Predicate<IExpr> matcher, IAST list)Evaluate the expression and return theTrace[expr](i.e.booleanevalTrue(IExpr expr)Test ifexprcould be evaluated toTrue.IExprevaluate(IExpr expr)Store the current numeric mode and evaluate the expressionexpr.IExprevaluate(java.lang.String expression)Parse the givenexpression Stringinto an IExpr and evaluate it.IExprevaluateNull(IExpr expr)Evaluate an object and reset the numeric mode to the value before the evaluation step.IExprevalWithoutNumericReset(IExpr expr)Evaluate an object without resetting the numeric mode after the evaluation step.static EvalEngineget()Get the thread local evaluation engine instanceIExprgetAnswer()Get the last result ("answer") expression of this evaluation engine.intgetIterationLimit()java.util.Map<ISymbol,java.util.Stack<IExpr>>getLocalVariableStackMap()java.util.Set<ISymbol>getModifiedVariables()Get the list of modified variablesstatic intgetNextAnonymousCounter()static java.lang.StringgetNextCounter()IExprgetOut(int index)Get the expression of theOut[]list at the given indexjava.util.List<IExpr>getOutList()java.io.PrintStreamgetOutPrintStream()IASTgetReapList()intgetRecursionLimit()java.lang.StringgetSessionID()ISymbolgetUserVariable(java.lang.String symbolName)Returns theISymbolvariable created in this thread to which the specifiedsymbolNameis mapped, ornullif this map contains no mapping for thesymbolName.intincModuleCounter()Increment the module counter by 1 and return the result.voidinit()Resets internal flags and states:booleanisEvalLHSMode()The engine evaluates the left-hand-side of aSet, SetDelayed,...expression.booleanisNumericMode()booleanisOutListDisabled()booleanisPackageMode()booleanisQuietMode()Iftruethe engine evaluates in "quiet" mode (i.e.booleanisRelaxedSyntax()booleanisStopRequested()booleanisTraceMode()If the trace mode is set the system writes an evaluation trace list or if additionally the stop after evaluation mode is set returns the first evaluated result.static java.util.Stack<IExpr>localStack(ISymbol symbol)Get the local variable stack for a given symbol name.static java.util.Stack<IExpr>localStackCreate(ISymbol symbol)Get the local variable stack for a given symbol name.IExprparse(java.lang.String expression)Parse the givenexpression Stringinto an IExpr without evaluation.ASTNodeparseNode(java.lang.String expression)Parse the givenexpression Stringinto anASTNodewithout evaluation.ISymbolputUserVariable(java.lang.String symbolName, ISymbol symbol)Associates thesymbolNamekey with theISymbolvalue.static voidremove()Removes the current thread's value for the EvalEngine's thread-local variable.voidremoveUserVariables(java.util.Map<ISymbol,ISymbol> moduleVariables)Remove allmoduleVariablesfrom this evaluation engine.voidreset()Reset the numeric mode flag and the recursion counterstatic voidset(EvalEngine engine)Set the thread local evaluation engine instancevoidsetIterationLimit(int i)voidsetNumericMode(boolean b)voidsetOutListDisabled(boolean outListDisabled)voidsetOutPrintStream(java.io.PrintStream outPrintStream)voidsetPackageMode(boolean packageMode)voidsetQuietMode(boolean quietMode)Iftruethe engine evaluates in "quiet" mode (i.e.voidsetReapList(IAST reapList)voidsetRecursionLimit(int i)voidsetRelaxedSyntax(boolean fRelaxedSyntax)voidsetSessionID(java.lang.String string)voidsetStopRequested(boolean stopRequested)voidsetTraceMode(boolean b)intsizeOut()The size of theOut[]listvoidstopRequest()static IASTthreadASTListArgs(IAST ast)java.lang.StringtoString()
-
-
-
Field Detail
-
DEBUG
public static final boolean DEBUG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EvalEngine
public EvalEngine()
Public constructor for serialization.
-
EvalEngine
public EvalEngine(boolean relaxedSyntax)
-
EvalEngine
public EvalEngine(boolean relaxedSyntax, boolean outListDisabled)
-
EvalEngine
public EvalEngine(F f, java.io.PrintStream out)
-
EvalEngine
public EvalEngine(java.lang.String sessionID, int recursionLimit, int iterationLimit, java.io.PrintStream out, boolean relaxedSyntax, boolean outListDisabled)
-
EvalEngine
public EvalEngine(java.lang.String sessionID, int recursionLimit, java.io.PrintStream out, boolean relaxedSyntax, boolean outListDisabled)Constructor for an EvaluationEngine- Parameters:
sessionID- an ID which uniquely identifies this sessionrecursionLimit- the maximum allowed recursion limit (if set to zero, no limit will be proofed)out-relaxedSyntax-- See Also:
javax.servlet.http.HttpSession#getID()
-
EvalEngine
public EvalEngine(java.lang.String sessionID, java.io.PrintStream out)
-
-
Method Detail
-
eval
public static final IExpr eval(IExpr expr)
Evaluate an expression. If evaluation is not possible return the input object.- Parameters:
expr- the expression which should be evaluated- Returns:
- the evaluated object
- See Also:
evalWithoutNumericReset(IExpr)
-
evalNull
public static final IExpr evalNull(IExpr expr)
Evaluate an expression. If evaluation is not possible return the input object.- Parameters:
expr- the expression which should be evaluated- Returns:
- the evaluated object or
nullif no evaluation was possible - See Also:
evalWithoutNumericReset(IExpr)
-
getNextAnonymousCounter
public static int getNextAnonymousCounter()
-
getNextCounter
public static java.lang.String getNextCounter()
-
localStack
public static final java.util.Stack<IExpr> localStack(ISymbol symbol)
Get the local variable stack for a given symbol name. If the local variable stack doesn't exist, returnnull- Parameters:
symbolName-- Returns:
nullif the stack doesn't exist
-
localStackCreate
public static java.util.Stack<IExpr> localStackCreate(ISymbol symbol)
Get the local variable stack for a given symbol name. If the local variable stack doesn't exist, create a new one for the symbol.- Parameters:
symbolName-- Returns:
-
set
public static void set(EvalEngine engine)
Set the thread local evaluation engine instance
-
get
public static EvalEngine get()
Get the thread local evaluation engine instance- Returns:
-
remove
public static void remove()
Removes the current thread's value for the EvalEngine's thread-local variable.- See Also:
ThreadLocal.remove()
-
addModifiedVariable
public boolean addModifiedVariable(ISymbol arg0)
For every evaluation store the list of modified variables in an internal list.- Parameters:
arg0-- Returns:
-
addOut
public boolean addOut(IExpr arg0)
Add an expression to theOut[]list. To avoid memory leaks you can disable the appending of expressions to the output history.- See Also:
setOutListDisabled(boolean)
-
addRules
public void addRules(IAST ruleList)
-
endTrace
public IAST endTrace()
-
evalAST
public IExpr evalAST(IAST ast)
Evaluate an AST. The evaluation steps are controlled by the header attributes.- Parameters:
ast-- Returns:
-
evalLoop
public IExpr evalLoop(IExpr expr)
Evaluate an object, if evaluation is not possible returnnull.- Parameters:
expr- the expression which should be evaluated- Returns:
- the evaluated expression or
nullis evasluation isn't possible - See Also:
evalWithoutNumericReset(IExpr)
-
evalSetAttributes
public IAST evalSetAttributes(IAST ast)
Transform the ast recursively, according to the attributes Flat, HoldAll, HoldFirst, HoldRest, Orderless for the left-hand-side of a Set[] or SetDelayed[] expression- Parameters:
ast-- Returns:
-
evalTrace
public final IAST evalTrace(IExpr expr, Predicate<IExpr> matcher, IAST list)
Evaluate the expression and return theTrace[expr](i.e. all (sub-)expressions needed to calculate the result).- Parameters:
expr- the expression which should be evaluated.matcher- a filter which determines the expressions which should be traced, If the matcher is set tonull, all expressions are traced.list- an IAST object which will be cloned for containing the traced expressions. Typically aF.List()will be used.- Returns:
-
evalTrue
public final boolean evalTrue(IExpr expr)
Test ifexprcould be evaluated toTrue. If aorg.matheclipse.parser.client.math.MathExceptionoccurs during evaluation, returnFalse.- Parameters:
expr-- Returns:
-
evaluate
public final IExpr evaluate(IExpr expr)
Store the current numeric mode and evaluate the expressionexpr. After evaluation reset the numeric mode to the value stored before the evaluation starts. If evaluation is not possible return the input object.- Parameters:
expr- the object which should be evaluated- Returns:
- the evaluated object
-
evaluate
public final IExpr evaluate(java.lang.String expression)
Parse the givenexpression Stringinto an IExpr and evaluate it.- Parameters:
astString- an expression in math formula notation- Returns:
- Throws:
SyntaxError- if a parsing error occurs
-
evaluateNull
public final IExpr evaluateNull(IExpr expr)
Evaluate an object and reset the numeric mode to the value before the evaluation step. If evaluation is not possible returnnull.- Parameters:
expr- the object which should be evaluated- Returns:
- the evaluated object of
nullif no evaluation was possible
-
evalWithoutNumericReset
public final IExpr evalWithoutNumericReset(IExpr expr)
Evaluate an object without resetting the numeric mode after the evaluation step. If evaluation is not possible return the input object,- Specified by:
evalWithoutNumericResetin interfaceIEvaluationEngine- Parameters:
expr- the object which should be evaluated- Returns:
- the evaluated object
-
getAnswer
public IExpr getAnswer()
Get the last result ("answer") expression of this evaluation engine.- Returns:
nullif no answer is stored in the evaluation engine.
-
getIterationLimit
public int getIterationLimit()
-
getLocalVariableStackMap
public final java.util.Map<ISymbol,java.util.Stack<IExpr>> getLocalVariableStackMap()
-
getModifiedVariables
public java.util.Set<ISymbol> getModifiedVariables()
Get the list of modified variables- Returns:
-
getOut
public IExpr getOut(int index)
Get the expression of theOut[]list at the given index- Parameters:
index-- Returns:
-
getOutList
public java.util.List<IExpr> getOutList()
-
getOutPrintStream
public java.io.PrintStream getOutPrintStream()
-
getReapList
public IAST getReapList()
- Returns:
- the reapList
-
getRecursionLimit
public int getRecursionLimit()
- Returns:
-
getSessionID
public java.lang.String getSessionID()
- Returns:
-
getUserVariable
public ISymbol getUserVariable(java.lang.String symbolName)
Returns theISymbolvariable created in this thread to which the specifiedsymbolNameis mapped, ornullif this map contains no mapping for thesymbolName.- Parameters:
name-- Returns:
-
putUserVariable
public ISymbol putUserVariable(java.lang.String symbolName, ISymbol symbol)
Associates thesymbolNamekey with theISymbolvalue.- Parameters:
symbolName-symbol-- Returns:
-
removeUserVariables
public void removeUserVariables(java.util.Map<ISymbol,ISymbol> moduleVariables)
Remove allmoduleVariablesfrom this evaluation engine.- Parameters:
moduleVariables-
-
incModuleCounter
public int incModuleCounter()
Increment the module counter by 1 and return the result.- Returns:
- the module counter
-
init
public final void init()
Description copied from interface:IEvaluationEngineResets internal flags and states:- Specified by:
initin interfaceIEvaluationEngine
-
isEvalLHSMode
public boolean isEvalLHSMode()
The engine evaluates the left-hand-side of aSet, SetDelayed,...expression.- Returns:
-
isNumericMode
public boolean isNumericMode()
- Returns:
-
isOutListDisabled
public boolean isOutListDisabled()
-
isPackageMode
public boolean isPackageMode()
-
isQuietMode
public boolean isQuietMode()
Iftruethe engine evaluates in "quiet" mode (i.e. no warning messages are showw in the evaluation).- See Also:
Quiet
-
isRelaxedSyntax
public boolean isRelaxedSyntax()
- Returns:
- the fRelaxedSyntax
-
isStopRequested
public boolean isStopRequested()
- Returns:
- Returns the stopRequested.
-
isTraceMode
public boolean isTraceMode()
If the trace mode is set the system writes an evaluation trace list or if additionally the stop after evaluation mode is set returns the first evaluated result.- Returns:
- See Also:
Trace
-
parse
public final IExpr parse(java.lang.String expression)
Parse the givenexpression Stringinto an IExpr without evaluation.- Parameters:
astString- an expression in math formula notation- Returns:
- Throws:
SyntaxError- if a parsing error occurs
-
parseNode
public final ASTNode parseNode(java.lang.String expression)
Parse the givenexpression Stringinto anASTNodewithout evaluation.- Parameters:
astString- an expression in math formula notation- Returns:
- Throws:
SyntaxError- if a parsing error occurs
-
reset
public void reset()
Reset the numeric mode flag and the recursion counter
-
setIterationLimit
public void setIterationLimit(int i)
-
setNumericMode
public void setNumericMode(boolean b)
- Parameters:
b-
-
setOutListDisabled
public void setOutListDisabled(boolean outListDisabled)
-
setOutPrintStream
public void setOutPrintStream(java.io.PrintStream outPrintStream)
-
setPackageMode
public void setPackageMode(boolean packageMode)
-
setQuietMode
public void setQuietMode(boolean quietMode)
Iftruethe engine evaluates in "quiet" mode (i.e. no warning messages are showw in the evaluation).- Parameters:
quietMode-
-
setReapList
public void setReapList(IAST reapList)
- Parameters:
reapList- the reapList to set
-
setRecursionLimit
public void setRecursionLimit(int i)
- Parameters:
i-
-
setRelaxedSyntax
public void setRelaxedSyntax(boolean fRelaxedSyntax)
- Parameters:
fRelaxedSyntax- the fRelaxedSyntax to set
-
setSessionID
public void setSessionID(java.lang.String string)
- Parameters:
string-
-
setStopRequested
public void setStopRequested(boolean stopRequested)
- Parameters:
stopRequested- The stopRequested to set.
-
setTraceMode
public void setTraceMode(boolean b)
- Parameters:
b-
-
sizeOut
public int sizeOut()
The size of theOut[]list- Returns:
-
stopRequest
public void stopRequest()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG