|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.lsmp.djep.xjep.DoNothingVisitor
org.lsmp.djep.xjep.DeepCopyVisitor
org.lsmp.djep.djep.DifferentiationVisitor
public class DifferentiationVisitor
A class for performing differentation of an expression. To use do
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 Summary | |
---|---|
DifferentiationVisitor(DJep jep)
Construction with a given set of tree utilities |
Method Summary | |
---|---|
Node |
differentiate(Node node,
java.lang.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(java.io.PrintStream out)
Prints all the differentation 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(ASTVarNode node,
java.lang.Object data)
Differentiates a variable. |
Methods inherited from class org.lsmp.djep.xjep.DeepCopyVisitor |
---|
deepCopy |
Methods inherited from class org.lsmp.djep.xjep.DoNothingVisitor |
---|
acceptChildrenAsArray, visit, visit |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.nfunk.jep.ParserVisitor |
---|
visit, visit |
Constructor Detail |
---|
public DifferentiationVisitor(DJep jep)
Method Detail |
---|
public void printDiffRules()
public void printDiffRules(java.io.PrintStream out)
public Node differentiate(Node node, java.lang.String var, DJep djep) throws ParseException, java.lang.IllegalArgumentException
node
- the top node of the expression treevar
- the variable to differentiate wrt
ParseException
- if some error occurred while trying to differentiate, for instance of no rule supplied for given function.
java.lang.IllegalArgumentException
public java.lang.Object visit(ASTFunNode node, java.lang.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 java.lang.Object visit(ASTVarNode node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
visit
in class DeepCopyVisitor
ParseException
public java.lang.Object visit(ASTConstant node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
visit
in class DeepCopyVisitor
ParseException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |