Class XJep

java.lang.Object
com.singularsys.jep.Jep
com.singularsys.extensions.xjep.XJep
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DJep

public class XJep extends Jep
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 Details

  • Constructor Details

    • XJep

      public XJep()
      Create a new XJep with all the function of Jep plus simplification and other features.
    • XJep

      public XJep(JepComponent... components)
      Create a new XJep instance using specified components and default components if necessary.
      Parameters:
      components -
    • XJep

      public XJep(ComponentSet components)
      Create a new XJep instance using specified components set and default components if necessary.
      Parameters:
      components -
  • Method Details

    • setXComponentInternal

      protected void setXComponentInternal(JepComponent comp)
    • preprocess

      public Node preprocess(Node node) throws ParseException
      Pre-processes an equation to allow the diff and eval operators to be used. Uses the CommandVisitor
      Throws:
      ParseException
    • deepCopy

      public Node deepCopy(Node node) throws ParseException
      Returns a deep copy of an expression tree.
      Throws:
      ParseException
      See Also:
    • clean

      public Node clean(Node node) throws ParseException
      Returns a cleaned up version of an expression tree. First does a deep copy of the tree.
      Throws:
      ParseException
      See Also:
    • simplify

      public Node simplify(Node node) throws ParseException
      Returns a simplification of an expression tree.
      Throws:
      ParseException
      See Also:
    • expand

      public Node expand(Node node) throws ParseException
      Expand brackets in an expression
      Parameters:
      node - expression to expand
      Returns:
      expanded version of expression
      Throws:
      ParseException
      See Also:
    • equals

      public boolean equals(Node lhs, Node rhs) throws ParseException
      Compare two expressions symbolically.
      Parameters:
      lhs -
      rhs -
      Returns:
      true if symbolically equal after rearrangement
      Throws:
      ParseException
      See Also:
    • substitute

      public Node substitute(Node orig, String name, Object value) throws ParseException
      Substitute all occurrences of a named variable with a constant value.
      Parameters:
      orig - expression to substitute into
      name - name of variable to substitute
      value - its replacement value
      Returns:
      expression after substitution
      Throws:
      ParseException
    • substitute

      public Node substitute(Node orig, String name, Node replacement) throws ParseException
      Substitute all occurrences of a named variable with an expression.
      Parameters:
      orig - expression to substitute into
      name - name of variable to substitute
      replacement - expression to
      Returns:
      expression after substitution
      Throws:
      ParseException
    • substitute

      public Node substitute(Node orig, Node sub) throws ParseException
      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 into
      sub - expression of the form x=....
      Returns:
      expression after substitution
      Throws:
      ParseException
    • substitute

      public Node substitute(Node orig, String[] names, Object[] values) throws ParseException
      Substitute all occurrences of the variables with their values.
      Throws:
      ParseException
    • substitute

      public Node substitute(Node orig, Node[] subs) throws ParseException
      Substitute a set of expressions into the original.
      Parameters:
      orig - expression to substitute into
      subs - array of expressions of the form x=....
      Returns:
      expression after substitution
      Throws:
      ParseException
    • substitute

      public Node substitute(Node orig, String[] names, Node[] replacements) throws ParseException
      Substitute all occurrences of a set of named variable with a set of expression tree.
      Throws:
      ParseException
    • substituteConstantVariables

      public Node substituteConstantVariables(Node orig) throws ParseException
      Replace all constant variables like pi by their values.
      Parameters:
      orig - the input
      Returns:
      a copy of the input with all constant variables substituted by their values.
      Throws:
      ParseException
    • replaceRHSVariablesByEquations

      public Node replaceRHSVariablesByEquations(Node node) throws JepException
      Replace variables on the right had side of an assignment by their equations
      Parameters:
      node - an equation of the form g:=f^2-1
      Returns:
      a copy of the node
      Throws:
      JepException
    • replaceVariablesByExpressions

      public Node replaceVariablesByExpressions(Node node) throws JepException
      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

      public Object calcVarValue(String name, boolean force) throws EvaluationException
      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 variable
      force - whether to force re-evaluation if the variable has a valid value
      Returns:
      value of variable
      Throws:
      EvaluationException
    • getVarsInEquation

      public Set<Variable> getVarsInEquation(Node n)
      Finds all the variables in an equation.
      Parameters:
      n - the top node of the expression
      Returns:
      v
    • getVarsInEquation

      public Set<Variable> getVarsInEquation(Node n, Set<Variable> vars)
      Finds all the variables in an equation.
      Parameters:
      n - the top node of the expression
      vars - 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+b and a=c+d, b=c+e then the result will be the sequence (c,d,a,e,b) For this method to work the equations must be preprocessed using preprocess(com.singularsys.jep.parser.Node). From version 2.1 returns a sorted list rather than an ordered set.

      Parameters:
      n - top node
      vars - 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

      public Node rewrite(Node node, boolean clean) throws ParseException
      Throws:
      ParseException
    • addRewriteRule

      public boolean addRewriteRule(RewriteRuleI rule)
    • getTreeUtils

      public TreeUtils getTreeUtils()
      Returns the TreeUtilities, used for examining properties of nodes.
    • getCopier

      public DeepCopyVisitor getCopier()
    • getSubstitutionVisitor

      public SubstitutionVisitor getSubstitutionVisitor()
    • getExpressionCleaner

      public ExpressionCleaner getExpressionCleaner()
    • getCommandVisitor

      public CommandVisitor getCommandVisitor()
    • getPolynomialCreator

      public PolynomialCreator getPolynomialCreator()
    • getRewriteVisitor

      public RewriteVisitor getRewriteVisitor()
    • getExtractor

      public EquationExtractor<?> getExtractor()