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(org.lsmp.djep.djep.DiffRulesI) method.| Constructor and Description |
|---|
DifferentiationVisitor(DJep jep)
Construction with a given set of tree utilities
|
| Modifier and Type | Method and Description |
|---|---|
Node |
differentiate(Node node,
String var,
DJep djep)
Differentiates an expression tree wrt a variable var.
|
boolean |
isConstantVar(XVariable var) |
void |
printDiffRules()
Prints all the differentation rules for all functions on System.out.
|
void |
printDiffRules(PrintStream out)
Prints all the differentation rules for all functions on specified stream.
|
Object |
visit(ASTConstant node,
Object data)
Differentiates a constant.
|
Object |
visit(ASTFunNode node,
Object data)
Applies differentiation to a function.
|
Object |
visit(ASTVarNode node,
Object data)
Differentiates a variable.
|
deepCopyacceptChildrenAsArray, visit, visitclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitvisit, visitpublic DifferentiationVisitor(DJep jep)
public void printDiffRules()
public void printDiffRules(PrintStream out)
public Node differentiate(Node node, String var, DJep djep) throws ParseException, IllegalArgumentException
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.IllegalArgumentExceptionpublic Object visit(ASTFunNode node, Object data) throws ParseException
DiffRulesI.visit in interface ParserVisitorvisit in class DeepCopyVisitornode - The node of the function.data - The variable to differentiate wrt.ParseExceptionpublic boolean isConstantVar(XVariable var)
public Object visit(ASTVarNode node, Object data) throws ParseException
visit in interface ParserVisitorvisit in class DeepCopyVisitorParseExceptionpublic Object visit(ASTConstant node, Object data) throws ParseException
visit in interface ParserVisitorvisit in class DeepCopyVisitorParseExceptionCopyright © 2018. All rights reserved.