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.
|
deepCopy
visit, visit
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
visit, visit
public 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.IllegalArgumentException
public Object visit(ASTFunNode node, Object data) throws ParseException
DiffRulesI
.visit
in interface ParserVisitor
visit
in class DeepCopyVisitor
node
- The node of the function.data
- The variable to differentiate wrt.ParseException
public boolean isConstantVar(XVariable var)
public Object visit(ASTVarNode node, Object data) throws ParseException
visit
in interface ParserVisitor
visit
in class DeepCopyVisitor
ParseException
public Object visit(ASTConstant node, Object data) throws ParseException
visit
in interface ParserVisitor
visit
in class DeepCopyVisitor
ParseException
Jas4pp 1.5 © Java Analysis Studio for Particle Physics