Package com.singularsys.extensions.xjep
Class XJep
java.lang.Object
com.singularsys.jep.Jep
com.singularsys.extensions.xjep.XJep
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DJep
An extended version of Jep adds various routines for working with trees.
Has a NodeFactory, and OperatorTable, TreeUtils
and Visitors DoNothingVisitor,
- Author:
- Rich Morris Created on 16-Nov-2003
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ExpressionCleanerprotected CommandVisitorprotected DeepCopyVisitorprotected EquationExtractor<?> protected PolynomialCreatorprotected RewriteVisitorprotected SubstitutionVisitorprotected TreeUtilsA few utility functions.Fields inherited from class com.singularsys.jep.Jep
additionalComponents, allowAssignment, allowUndeclared, evaluator, funTab, implicitMul, lastRootNode, nodeFac, numFac, opTab, parser, pv, varFac, varTab -
Constructor Summary
ConstructorsConstructorDescriptionXJep()Create a new XJep with all the function of Jep plus simplification and other features.XJep(ComponentSet components) Create a new XJep instance using specified components set and default components if necessary.XJep(JepComponent... components) Create a new XJep instance using specified components and default components if necessary. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddRewriteRule(RewriteRuleI rule) calcVarValue(String name, boolean force) Calculates the value for the variables equation and returns that value.Returns a cleaned up version of an expression tree.Returns a deep copy of an expression tree.booleanCompare two expressions symbolically.Expand brackets in an expressionReturns the TreeUtilities, used for examining properties of nodes.Finds all the variables in an equation.getVarsInEquation(Node n, Set<Variable> vars) Finds all the variables in an equation.preprocess(Node node) Pre-processes an equation to allow the diff and eval operators to be used.recursiveGetVarsInEquation(Node n, List<XVariable> vars) Finds all the variables in an equation and if any of those variables are defined by equations find the variables in those equations as well.Replace variables on the right had side of an assignment by their equationsReplace all symbolic variable by their equationsprotected voidReturns a simplification of an expression tree.substitute(Node orig, Node sub) Substitute all occurrences of the variable on the left-hand side of sub with the expression tree on the right-hand side.substitute(Node orig, Node[] subs) Substitute a set of expressions into the original.substitute(Node orig, String[] names, Node[] replacements) Substitute all occurrences of a set of named variable with a set of expression tree.substitute(Node orig, String[] names, Object[] values) Substitute all occurrences of the variables with their values.substitute(Node orig, String name, Node replacement) Substitute all occurrences of a named variable with an expression.substitute(Node orig, String name, Object value) Substitute all occurrences of a named variable with a constant value.Replace all constant variables likepiby their values.Methods inherited from class com.singularsys.jep.Jep
addConstant, addDefaultComponents, addFunction, addStandardConstants, addVariable, addVariable, addVariable, addVariable, continueParsing, evaluate, evaluate, evaluateD, getAdditionalComponent, getAdditionalComponentExact, getAdditionalComponents, getAllowAssignment, getAllowUndeclared, getDefaultValue, getEvaluator, getFunctionTable, getImplicitMul, getLastRootNode, getNodeFactory, getNumberFactory, getOperatorTable, getOperatorTable2, 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, setVariableValue, toString, tryAddConstant
-
Field Details
-
tu
A few utility functions. -
copier
-
subv
-
cleaner
-
commandv
-
polyv
-
rewritev
-
extractor
-
-
Constructor Details
-
XJep
public XJep()Create a new XJep with all the function of Jep plus simplification and other features. -
XJep
Create a new XJep instance using specified components and default components if necessary.- Parameters:
components-
-
XJep
Create a new XJep instance using specified components set and default components if necessary.- Parameters:
components-
-
-
Method Details
-
setXComponentInternal
-
preprocess
Pre-processes an equation to allow the diff and eval operators to be used. Uses theCommandVisitor- Throws:
ParseException
-
deepCopy
Returns a deep copy of an expression tree.- Throws:
ParseException- See Also:
-
clean
Returns a cleaned up version of an expression tree. First does a deep copy of the tree.- Throws:
ParseException- See Also:
-
simplify
Returns a simplification of an expression tree.- Throws:
ParseException- See Also:
-
expand
Expand brackets in an expression- Parameters:
node- expression to expand- Returns:
- expanded version of expression
- Throws:
ParseException- See Also:
-
equals
Compare two expressions symbolically.- Parameters:
lhs-rhs-- Returns:
- true if symbolically equal after rearrangement
- Throws:
ParseException- See Also:
-
substitute
Substitute all occurrences of a named variable with a constant value.- Parameters:
orig- expression to substitute intoname- name of variable to substitutevalue- its replacement value- Returns:
- expression after substitution
- Throws:
ParseException
-
substitute
Substitute all occurrences of a named variable with an expression.- Parameters:
orig- expression to substitute intoname- name of variable to substitutereplacement- expression to- Returns:
- expression after substitution
- Throws:
ParseException
-
substitute
Substitute all occurrences of the variable on the left-hand side of sub with the expression tree on the right-hand side.- Parameters:
orig- expression to substitute intosub- expression of the form x=....- Returns:
- expression after substitution
- Throws:
ParseException
-
substitute
Substitute all occurrences of the variables with their values.- Throws:
ParseException
-
substitute
Substitute a set of expressions into the original.- Parameters:
orig- expression to substitute intosubs- array of expressions of the formx=....- Returns:
- expression after substitution
- Throws:
ParseException
-
substitute
Substitute all occurrences of a set of named variable with a set of expression tree.- Throws:
ParseException
-
substituteConstantVariables
Replace all constant variables likepiby their values.- Parameters:
orig- the input- Returns:
- a copy of the input with all constant variables substituted by their values.
- Throws:
ParseException
-
replaceRHSVariablesByEquations
Replace variables on the right had side of an assignment by their equations- Parameters:
node- an equation of the formg:=f^2-1- Returns:
- a copy of the node
- Throws:
JepException
-
replaceVariablesByExpressions
Replace all symbolic variable by their equations- Parameters:
node- root of expression- Returns:
- copy of node with variables replaced by their equations
- Throws:
JepException
-
calcVarValue
Calculates the value for the variables equation and returns that value. If the variable does not have an equation just return its value. Recursively calculates the values of any variable with equations which appear.- Parameters:
name- name of variableforce- whether to force re-evaluation if the variable has a valid value- Returns:
- value of variable
- Throws:
EvaluationException
-
getVarsInEquation
Finds all the variables in an equation.- Parameters:
n- the top node of the expression- Returns:
- v
-
getVarsInEquation
Finds all the variables in an equation.- Parameters:
n- the top node of the expressionvars- the list of variables (new variables will be added on end)- Returns:
- v
-
recursiveGetVarsInEquation
public List<XVariable> recursiveGetVarsInEquation(Node n, List<XVariable> vars) throws ParseException Finds all the variables in an equation and if any of those variables are defined by equations find the variables in those equations as well. The result is an ordered sequence, evaluating each variable in turn will correctly allow the final equation to be evaluated.For example if the equation is
a+banda=c+d,b=c+ethen the result will be the sequence(c,d,a,e,b)For this method to work the equations must be preprocessed usingpreprocess(com.singularsys.jep.parser.Node). From version 2.1 returns a sorted list rather than an ordered set.- Parameters:
n- top nodevars- list of variables, new variables will be added on the end.- Returns:
- v, the ordered sequence of variables
- Throws:
ParseException- if equation is recursive i.e.x=y; y=x+1;
-
rewrite
- Throws:
ParseException
-
addRewriteRule
-
getTreeUtils
Returns the TreeUtilities, used for examining properties of nodes. -
getCopier
-
getSubstitutionVisitor
-
getExpressionCleaner
-
getCommandVisitor
-
getPolynomialCreator
-
getRewriteVisitor
-
getExtractor
-