public class DifferentiationVisitor extends DeepCopyVisitor
Jep j = ...; Node in = ...; DifferentiationVisitor dv = new DifferentiationVisitor(jep); dv.addStandardDiffRules(); Node out = dv.differentiate(in,"x");The class follows the visitor pattern described in
ParserVisitor.
The rules for differentiating specific functions are contained in
object which implement
DiffRulesI
A number of inner classes which use this interface are defined for specific
function types.
In particular
MacroDiffRules
allow the rule for differentiation to be specified by strings.
New rules can be added using
DJep.addDiffRule(com.singularsys.extensions.djep.DiffRulesI) method.| Modifier and Type | Field and Description |
|---|---|
protected DJep |
djep |
protected TreeUtils |
tu |
| Constructor and Description |
|---|
DifferentiationVisitor() |
| Modifier and Type | Method and Description |
|---|---|
Node |
differentiate(Node node,
java.lang.String var)
Differentiates an expression tree wrt a variable var.
|
DiffRulesI |
getDiffRule(java.lang.String name)
finds the rule for function with given name.
|
void |
init(Jep j)
Initialize the component.
|
boolean |
isConstantVar(XVariable var) |
void |
printDiffRules()
Prints all the differentiation rules for all functions on System.out.
|
void |
printDiffRules(java.io.PrintStream out)
Prints all the differentiation rules for all functions on specified
stream.
|
java.lang.Object |
visit(ASTConstant node,
java.lang.Object data)
Differentiates a constant.
|
java.lang.Object |
visit(ASTFunNode node,
java.lang.Object data)
Applies differentiation to a function.
|
java.lang.Object |
visit(ASTOpNode node,
java.lang.Object data)
Now the recursive calls to differentiate the tree
|
java.lang.Object |
visit(ASTVarNode node,
java.lang.Object data)
Differentiates a variable.
|
deepCopychildrenHaveChanged, copyChildrenIfNeeded, getFunctionTable, getLightWeightInstance, getNodeFactory, getOperatorTable, getVariableTable, visit, visitChildren, visitNodepublic void init(Jep j)
JepComponentinit in interface JepComponentinit in class DoNothingVisitorj - the current Jep instancepublic DiffRulesI getDiffRule(java.lang.String name)
public void printDiffRules()
public void printDiffRules(java.io.PrintStream out)
public Node differentiate(Node node, java.lang.String var) throws ParseException
node - the top node of the expression treevar - the variable to differentiate wrtParseException - if some error occurred while trying to differentiate, for instance of no rule supplied for given function.java.lang.IllegalArgumentExceptionpublic java.lang.Object visit(ASTOpNode node, java.lang.Object data) throws JepException
visit in interface ParserVisitorvisit in class DeepCopyVisitorJepExceptionpublic java.lang.Object visit(ASTFunNode node, java.lang.Object data) throws JepException
DiffRulesI.visit in interface ParserVisitorvisit in class DeepCopyVisitornode - The node of the function.data - The variable to differentiate wrt.JepExceptionpublic boolean isConstantVar(XVariable var)
public java.lang.Object visit(ASTVarNode node, java.lang.Object data) throws ParseException
visit in interface ParserVisitorvisit in class DeepCopyVisitorParseExceptionpublic java.lang.Object visit(ASTConstant node, java.lang.Object data) throws ParseException
visit in interface ParserVisitorvisit in class DeepCopyVisitorParseExceptionCopyright © 2018 Singular Systems http://www.singularsys.com/jep