org.matheclipse.parser.client.eval
Class DoubleEvaluator
- java.lang.Object
-
- org.matheclipse.parser.client.eval.DoubleEvaluator
-
- Direct Known Subclasses:
- EvalDouble
public class DoubleEvaluator extends java.lang.ObjectEvaluate math expressions todoublenumbers.
-
-
Field Summary
Fields Modifier and Type Field and Description static doubleEPSILON
-
Constructor Summary
Constructors Constructor and Description DoubleEvaluator()DoubleEvaluator(ASTNode node, boolean relaxedSyntax)DoubleEvaluator(boolean relaxedSyntax)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclearVariables()Clear all defined variables for this evaluator.voiddefineVariable(java.lang.String variableName)Define a value for a given variable name.voiddefineVariable(java.lang.String variableName, BooleanVariable value)Define a boolean value for a given variable name.voiddefineVariable(java.lang.String variableName, double value)Define a value for a given variable name.voiddefineVariable(java.lang.String variableName, IDoubleValue value)Define a value for a given variable name.ASTNodederivative(ASTNode node, java.lang.String var)ASTNodederivative(ASTNode node, SymbolNode var)TODO: add more derivation rulesdoubleevaluate()Reevaluate theexpression(possibly after a new Variable assignment)doubleevaluate(java.lang.String expression)Parse the givenexpression Stringand evaluate it to a double valuedoubleevaluateFunction(FunctionNode functionNode)Evaluate an already parsed inFunctionNodeinto asoublenumber value.booleanevaluateFunctionLogical(FunctionNode functionNode)doubleevaluateNode(ASTNode node)Evaluate an already parsed in abstract syntax tree node into adoublenumber value.booleanevaluateNodeLogical(ASTNode node)IDoubleCallbackFunctiongetCallbackFunction()A callback function for unknown function names.IDoubleValuegetVariable(java.lang.String variableName)Returns the double variable value to which the specified variableName is mapped, ornullif this map contains no mapping for the variableName.static voidgetVariables(ASTNode node, java.util.Set<java.lang.String> result)Get the variable names from the given AST node.voidgetVariables(java.lang.String expression, java.util.Set<java.lang.String> result)Get the variable names from the given expression.booleanisSymbol(SymbolNode symbol1, java.lang.String symbol2Name)Check if the given symbol is aSymbolNodeand test if the names are equal.booleanisSymbol(SymbolNode symbol1, SymbolNode symbol2)Check if the given symbol is aSymbolNodeand test if the names are equal.ASTNodeoptimizeFunction(FunctionNode functionNode)Optimize an already parsed infunctionNodeinto anASTNode.ASTNodeparse(java.lang.String expression)Parse the givenexpression Stringand store the resulting ASTNode in this DoubleEvaluatorstatic ASTNodeparseNode(java.lang.String expression, boolean relaxedSyntax)Parse the givenexpression Stringand return the resulting ASTNodevoidsetCallbackFunction(IDoubleCallbackFunction callbackFunction)Set a callback function for unknown function names.
-
-
-
Constructor Detail
-
DoubleEvaluator
public DoubleEvaluator()
-
DoubleEvaluator
public DoubleEvaluator(boolean relaxedSyntax)
-
DoubleEvaluator
public DoubleEvaluator(ASTNode node, boolean relaxedSyntax)
-
-
Method Detail
-
getCallbackFunction
public IDoubleCallbackFunction getCallbackFunction()
A callback function for unknown function names.- Returns:
- the callback function
-
setCallbackFunction
public void setCallbackFunction(IDoubleCallbackFunction callbackFunction)
Set a callback function for unknown function names.- Parameters:
callbackFunction- the callback function to set
-
parse
public ASTNode parse(java.lang.String expression)
Parse the givenexpression Stringand store the resulting ASTNode in this DoubleEvaluator- Parameters:
expression-- Returns:
- Throws:
SyntaxError
-
parseNode
public static ASTNode parseNode(java.lang.String expression, boolean relaxedSyntax)
Parse the givenexpression Stringand return the resulting ASTNode- Parameters:
expression-- Returns:
- Throws:
SyntaxError
-
evaluate
public double evaluate(java.lang.String expression)
Parse the givenexpression Stringand evaluate it to a double value- Parameters:
expression-- Returns:
- Throws:
SyntaxError
-
evaluate
public double evaluate()
Reevaluate theexpression(possibly after a new Variable assignment)- Parameters:
Expression-- Returns:
- Throws:
SyntaxError
-
evaluateNode
public double evaluateNode(ASTNode node)
Evaluate an already parsed in abstract syntax tree node into adoublenumber value.- Parameters:
node- abstract syntax tree node- Returns:
- the evaluated double number
- Throws:
ArithmeticMathException- if thenodecannot be evaluated.
-
evaluateFunction
public double evaluateFunction(FunctionNode functionNode)
Evaluate an already parsed inFunctionNodeinto asoublenumber value.- Parameters:
functionNode-- Returns:
- Throws:
ArithmeticMathException- if thefunctionNodecannot be evaluated.
-
isSymbol
public boolean isSymbol(SymbolNode symbol1, java.lang.String symbol2Name)
Check if the given symbol is aSymbolNodeand test if the names are equal.- Parameters:
symbol1-symbol2Name-- Returns:
-
isSymbol
public boolean isSymbol(SymbolNode symbol1, SymbolNode symbol2)
Check if the given symbol is aSymbolNodeand test if the names are equal.- Parameters:
symbol1-symbol2-- Returns:
-
derivative
public ASTNode derivative(ASTNode node, java.lang.String var)
- Parameters:
node-var-- Returns:
-
derivative
public ASTNode derivative(ASTNode node, SymbolNode var)
TODO: add more derivation rules- Parameters:
node-var-- Returns:
-
evaluateNodeLogical
public boolean evaluateNodeLogical(ASTNode node)
-
evaluateFunctionLogical
public boolean evaluateFunctionLogical(FunctionNode functionNode)
-
optimizeFunction
public ASTNode optimizeFunction(FunctionNode functionNode)
Optimize an already parsed infunctionNodeinto anASTNode.- Parameters:
functionNode-- Returns:
-
defineVariable
public void defineVariable(java.lang.String variableName, double value)Define a value for a given variable name.- Parameters:
variableName-value-
-
defineVariable
public void defineVariable(java.lang.String variableName, IDoubleValue value)Define a value for a given variable name.- Parameters:
variableName-value-
-
defineVariable
public void defineVariable(java.lang.String variableName)
Define a value for a given variable name.- Parameters:
variableName-value-
-
getVariable
public IDoubleValue getVariable(java.lang.String variableName)
Returns the double variable value to which the specified variableName is mapped, ornullif this map contains no mapping for the variableName.- Parameters:
variableName-- Returns:
-
defineVariable
public void defineVariable(java.lang.String variableName, BooleanVariable value)Define a boolean value for a given variable name.- Parameters:
variableName-value-
-
clearVariables
public void clearVariables()
Clear all defined variables for this evaluator.
-
getVariables
public void getVariables(java.lang.String expression, java.util.Set<java.lang.String> result)Get the variable names from the given expression.- Parameters:
expression-result- a set which contains the variable names
-
getVariables
public static void getVariables(ASTNode node, java.util.Set<java.lang.String> result)
Get the variable names from the given AST node.- Parameters:
node- an already parsed AST noderesult- a set which contains the variable names
-
-
DMelt 3.0 © DataMelt by jWork.ORG