public class DoubleEvaluator
extends java.lang.Object
double numbers.| Modifier and Type | Field and Description |
|---|---|
static double |
EPSILON |
protected boolean |
fRelaxedSyntax |
| Constructor and Description |
|---|
DoubleEvaluator() |
DoubleEvaluator(ASTNode node,
boolean relaxedSyntax) |
DoubleEvaluator(boolean relaxedSyntax) |
| Modifier and Type | Method and Description |
|---|---|
void |
clearVariables()
Clear all defined variables for this evaluator.
|
void |
defineVariable(java.lang.String variableName)
Define a value for a given variable name.
|
void |
defineVariable(java.lang.String variableName,
BooleanVariable value)
Define a boolean value for a given variable name.
|
void |
defineVariable(java.lang.String variableName,
double value)
Define a value for a given variable name.
|
void |
defineVariable(java.lang.String variableName,
IDoubleValue value)
Define a value for a given variable name.
|
ASTNode |
derivative(ASTNode node,
java.lang.String var) |
ASTNode |
derivative(ASTNode node,
SymbolNode var)
TODO: add more derivation rules
|
double |
evaluate()
Reevaluate the
expression (possibly after a new Variable assignment) |
double |
evaluate(java.lang.String expression)
Parse the given
expression String and evaluate it to a double value |
double |
evaluateFunction(FunctionNode functionNode)
Evaluate an already parsed in
FunctionNode into a souble number value. |
boolean |
evaluateFunctionLogical(FunctionNode functionNode) |
double |
evaluateNode(ASTNode node)
Evaluate an already parsed in abstract syntax tree node into a
double number value. |
boolean |
evaluateNodeLogical(ASTNode node) |
IDoubleCallbackFunction |
getCallbackFunction()
A callback function for unknown function names.
|
IDoubleValue |
getVariable(java.lang.String variableName)
Returns the double variable value to which the specified variableName is mapped, or
null if this map contains no
mapping for the variableName. |
static void |
getVariables(ASTNode node,
java.util.Set<java.lang.String> result)
Get the variable names from the given AST node.
|
static void |
getVariables(java.lang.String expression,
java.util.Set<java.lang.String> result)
Get the variable names from the given expression.
|
static void |
getVariables(java.lang.String expression,
java.util.Set<java.lang.String> result,
boolean relaxedSyntax)
Get the variable names from the given expression.
|
boolean |
isSymbol(SymbolNode symbol1,
java.lang.String symbol2Name)
Check if the given symbol is a
SymbolNode and test if the names are equal. |
boolean |
isSymbol(SymbolNode symbol1,
SymbolNode symbol2)
Check if the given symbol is a
SymbolNode and test if the names are equal. |
ASTNode |
optimizeFunction(FunctionNode functionNode)
Optimize an already parsed in
functionNode into an ASTNode. |
ASTNode |
parse(java.lang.String expression)
Parse the given
expression String and store the resulting ASTNode in this DoubleEvaluator |
static ASTNode |
parseNode(java.lang.String expression,
boolean relaxedSyntax)
Parse the given
expression String and return the resulting ASTNode |
void |
setCallbackFunction(IDoubleCallbackFunction callbackFunction)
Set a callback function for unknown function names.
|
public static double EPSILON
protected final boolean fRelaxedSyntax
public DoubleEvaluator()
public DoubleEvaluator(boolean relaxedSyntax)
public DoubleEvaluator(ASTNode node, boolean relaxedSyntax)
public IDoubleCallbackFunction getCallbackFunction()
public void setCallbackFunction(IDoubleCallbackFunction callbackFunction)
callbackFunction - the callback function to setpublic ASTNode parse(java.lang.String expression)
expression String and store the resulting ASTNode in this DoubleEvaluatorexpression - SyntaxErrorpublic static ASTNode parseNode(java.lang.String expression, boolean relaxedSyntax)
expression String and return the resulting ASTNodeexpression - SyntaxErrorpublic double evaluate(java.lang.String expression)
expression String and evaluate it to a double valueexpression - SyntaxErrorpublic double evaluate()
expression (possibly after a new Variable assignment)Expression - SyntaxErrorpublic double evaluateNode(ASTNode node)
double number value.node - abstract syntax tree nodeArithmeticMathException - if the node cannot be evaluated.public double evaluateFunction(FunctionNode functionNode)
FunctionNode into a souble number value.functionNode - ArithmeticMathException - if the functionNode cannot be evaluated.public boolean isSymbol(SymbolNode symbol1, java.lang.String symbol2Name)
SymbolNode and test if the names are equal.symbol1 - symbol2Name - public boolean isSymbol(SymbolNode symbol1, SymbolNode symbol2)
SymbolNode and test if the names are equal.symbol1 - symbol2 - public ASTNode derivative(ASTNode node, java.lang.String var)
node - var - public ASTNode derivative(ASTNode node, SymbolNode var)
node - var - public boolean evaluateNodeLogical(ASTNode node)
public boolean evaluateFunctionLogical(FunctionNode functionNode)
public ASTNode optimizeFunction(FunctionNode functionNode)
functionNode into an ASTNode.functionNode - public void defineVariable(java.lang.String variableName,
double value)
variableName - value - public void defineVariable(java.lang.String variableName,
IDoubleValue value)
variableName - value - public void defineVariable(java.lang.String variableName)
variableName - value - public IDoubleValue getVariable(java.lang.String variableName)
null if this map contains no
mapping for the variableName.variableName - public void defineVariable(java.lang.String variableName,
BooleanVariable value)
variableName - value - public void clearVariables()
public static void getVariables(java.lang.String expression,
java.util.Set<java.lang.String> result)
expression - result - a set which contains the variable namespublic static void getVariables(java.lang.String expression,
java.util.Set<java.lang.String> result,
boolean relaxedSyntax)
expression - result - a set which contains the variable namesrelaxedSyntax - if true us e function syntax like sin(x) otherwise use Sin[x].public static void getVariables(ASTNode node, java.util.Set<java.lang.String> result)
node - an already parsed AST noderesult - a set which contains the variable names