Package com.singularsys.extensions.djep
Class DJep
- java.lang.Object
-
- com.singularsys.jep.Jep
-
- com.singularsys.extensions.xjep.XJep
-
- com.singularsys.extensions.djep.DJep
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
MDJep
public class DJep extends XJep
Adds differentiation facilities to Jep. For exampleDJep j = new DJep(); j.addStandardDiffRules(); .... Node node = j.parse("x^3"); Node diff = j.differentiate(node,"x"); Node simp = j.simplify(diff); j.println(simp); Node node2 = j.parse("diff(x^4,x)"); Node proc = j.preprocess(node2); Node simp2 = j.simplify(proc); j.println(simp2);
- Author:
- Rich Morris Created on 16-Nov-2003
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected DifferentiationVisitor
dv
-
Fields inherited from class com.singularsys.extensions.xjep.XJep
cleaner, commandv, copier, extractor, polyv, rewritev, subv, tu
-
Fields inherited from class com.singularsys.jep.Jep
additionalComponents, allowAssignment, allowUndeclared, evaluator, funTab, implicitMul, lastRootNode, nodeFac, numFac, opTab, parser, pv, varFac, varTab
-
-
Constructor Summary
Constructors Constructor Description DJep()
Standard constructor.DJep(ComponentSet dJepComponents)
DJep(JepComponent... components)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDiffRule(DiffRulesI rule)
Adds a rule with instruction on how to differentiate a function.boolean
addStandardDiffRules()
Adds the standard set of differentiation rules.DVariable
differentiate(DVariable var, java.lang.String... names)
Finds the derivative of a differentiable variable.Node
differentiate(Node node, java.lang.String name)
Differentiate an equation with respect to a variable.DifferentiationVisitor
getDifferentationVisitor()
Returns the visitor used for differentiation.Node
replacePartialDerivativeByExpressions(Node node)
Replace any partial derivatives found in the expression by their expressions.protected void
setXComponentInternal(JepComponent comp)
-
Methods inherited from class com.singularsys.extensions.xjep.XJep
addRewriteRule, calcVarValue, clean, deepCopy, equals, expand, getCommandVisitor, getCopier, getExpressionCleaner, getExtractor, getPolynomialCreator, getRewriteVisitor, getSubstitutionVisitor, getTreeUtils, getVarsInEquation, getVarsInEquation, preprocess, recursiveGetVarsInEquation, replaceRHSVariablesByEquations, replaceVariableByExpressions, rewrite, simplify, substitute, substitute, substitute, substitute, substitute, substitute, substituteConstantVariables
-
Methods inherited from class com.singularsys.jep.Jep
addConstant, addDefaultComponents, addFunction, addStandardConstants, addVariable, addVariable, addVariable, addVariable, continueParsing, evaluate, evaluate, evaluateD, getAdditionalComponent, getAdditionalComponents, getAllowAssignment, getAllowUndeclared, getDefaultValue, getEvaluator, getFunctionTable, getImplicitMul, getLastRootNode, getNodeFactory, getNumberFactory, getOperatorTable, getParser, getPrintVisitor, getVariable, getVariableFactory, getVariableTable, getVariableValue, initMultiParse, initMultiParse, parse, parse, print, print, print, println, println, println, reinitializeComponents, rootNodeToString, setAllowAssignment, setAllowUndeclared, setComponent, setComponentInternal, setComponents, setComponentsInternal, setDefaultValue, setImplicitMul, setVariable, toString, tryAddConstant
-
-
-
-
Field Detail
-
dv
protected DifferentiationVisitor dv
-
-
Constructor Detail
-
DJep
public DJep()
Standard constructor. Use this instead of Jep or Jep if differentiation facilities are required.
-
DJep
public DJep(JepComponent... components)
-
DJep
public DJep(ComponentSet dJepComponents)
-
-
Method Detail
-
setXComponentInternal
protected void setXComponentInternal(JepComponent comp)
- Overrides:
setXComponentInternal
in classXJep
-
getDifferentationVisitor
public DifferentiationVisitor getDifferentationVisitor()
Returns the visitor used for differentiation. Allows more advanced functions.
-
addStandardDiffRules
public boolean addStandardDiffRules()
Adds the standard set of differentiation rules. Corresponds to all standard functions in the Jep plus a few more.sin,cos,tan,asin,acos,atan,sinh,cosh,tanh,asinh,acosh,atanh sqrt,log,ln,abs,angle sum,im,re are handled separately. rand and mod currently un-handled Also adds rules for functions not in Jep function list: sec,cosec,cot,exp,pow,sgn
- Returns:
- false on error
-
addDiffRule
public void addDiffRule(DiffRulesI rule)
Adds a rule with instruction on how to differentiate a function.- Parameters:
rule
-
-
differentiate
public Node differentiate(Node node, java.lang.String name) throws ParseException
Differentiate an equation with respect to a variable.- Parameters:
node
- top node of the expression tree to differentiate.name
- differentiate with respect to this variable.- Returns:
- the top node of a new parse tree representing the derivative.
- Throws:
ParseException
java.lang.IllegalArgumentException
-
replacePartialDerivativeByExpressions
public Node replacePartialDerivativeByExpressions(Node node) throws JepException
Replace any partial derivatives found in the expression by their expressions.- Parameters:
node
- expression to process, may be modified- Returns:
- the expression after replacement
- Throws:
JepException
-
differentiate
public DVariable differentiate(DVariable var, java.lang.String... names) throws ParseException
Finds the derivative of a differentiable variable. Will look up existing derivative if it exists or calculate the derivative if needed.- Parameters:
var
- variable to differentiatenames
- names of the partial derivatives to find, either a single name "x" or an array of names to find higher derivatives- Returns:
- a variable representing the partial derivative
- Throws:
ParseException
-
-