Class ChainRuleDiffRules

java.lang.Object
com.singularsys.extensions.djep.diffRules.ChainRuleDiffRules
All Implemented Interfaces:
DiffRulesI, JepComponent, Serializable
Direct Known Subclasses:
MacroDiffRules, MacroFunctionDiffRules

public abstract class ChainRuleDiffRules extends Object implements DiffRulesI
Abstract base class for function which are differentiated using the chain rule. All subclasses should specify the name pfmc rules and descriptions fields. The rules specify the derivative of the function wrt i-th argument which is supplied as a Node Variable names in rules MUST be x,y for 1 to 2 variables. So for the function f(x,y) with two arguments if rules representing df/dx and df/dy are specified and x and y are functions of a further variable z then the derivative wrt z is found using the chain rule df(x,y)/dz -> df/dx * dx/dz + df/dy * dy/dz.
See Also:
  • Field Details

  • Constructor Details

    • ChainRuleDiffRules

      protected ChainRuleDiffRules(DJep djep)
      Constructor. Subclasses should call a setup method to complete construction.
  • Method Details

    • setup

      protected void setup(String funName, PostfixMathCommandI pfmc, Node rule, String description)
      Set the internal variables for unary function with argument named 'x'
      Parameters:
      funName - name of function
      pfmc - Jep function
      rule - expression for derivative wrt 'x'
      description - string rep of derivative
    • setup

      protected void setup(String funName, PostfixMathCommandI pfmc, Node rule1, Node rule2, String description1, String description2)
      Set the internal variables for binary function with arguments named 'x' 'y'
      Parameters:
      funName - name of function
      pfmc - Jep function
      rule1 - expression for derivative wrt 'x'
      rule2 - expression for derivative wrt 'y'
      description1 - string rep of derivative
      description2 - string rep of derivative
    • setup

      protected void setup(String funName, PostfixMathCommandI pfmc, Node[] rules, String[] descriptions, String[] argNames)
      Set the internal variables for function with multiple arguments
      Parameters:
      funName - name of function
      pfmc - Jep function
      rules - expression for derivatives
      descriptions - text rep of derivatives
      argNames - names of the variables of the function
    • differentiate

      public Node differentiate(ASTFunNode node, String var, Node[] children, Node[] dchildren) throws JepException
      Use the chain rule to differentiate. diff(f(g(x),h(x)),x) -> df/dg * dg/dx + df/dh * dh/dx
      Specified by:
      differentiate in interface DiffRulesI
      Parameters:
      var - The name of variable to differentiate wrt to.
      children - the arguments of the function
      dchildren - the derivatives of each argument of the function.
      Returns:
      top node of and expression tree for the derivative.
      Throws:
      JepException
    • init

      public void init(Jep djep)
      Description copied from interface: JepComponent
      Initialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.
      Specified by:
      init in interface JepComponent
      Parameters:
      djep - the current Jep instance
    • getLightWeightInstance

      public JepComponent getLightWeightInstance()
      Description copied from interface: JepComponent
      Gets a light-weight instance suitable for using in multiple threads.
      Specified by:
      getLightWeightInstance in interface JepComponent
      Returns:
      either a new instance, null or 'this'.
    • getName

      public String getName()
      returns the name of the function
      Specified by:
      getName in interface DiffRulesI
    • getPfmc

      public PostfixMathCommandI getPfmc()
      returns the PostfixMathCommandI for the function.
    • getNumRules

      public int getNumRules()
      Returns the number of rules which should be number of arguments of function
    • getRule

      public Node getRule(int i)
      returns the i-th rule as an expression tree.
    • getDescriptions

      public String[] getDescriptions()
    • getArgNames

      public String[] getArgNames()
    • toString

      public String toString()
      Description copied from interface: DiffRulesI
      Returns a string representation of the rule.
      Specified by:
      toString in interface DiffRulesI
      Overrides:
      toString in class Object