Differentiate an abstract syntax tree (AST). More...
Public Member Functions | |
__construct ($variable) | |
Class constructor. More... | |
visitExpressionNode (ExpressionNode $node) | |
Differentiate an ExpressionNode. More... | |
visitNumberNode (NumberNode $node) | |
Differentiate a NumberNode. More... | |
visitIntegerNode (IntegerNode $node) | |
Interface function for visiting IntegerNodes. More... | |
visitRationalNode (RationalNode $node) | |
Interface function for visiting RationalNodes. More... | |
visitVariableNode (VariableNode $node) | |
Differentiate a VariableNode. More... | |
visitFunctionNode (FunctionNode $node) | |
Differentiate a FunctionNode. More... | |
visitConstantNode (ConstantNode $node) | |
Differentiate a ConstantNode. More... | |
Protected Attributes | |
$variable | |
Variable that we differentiate with respect to. | |
$nodeFactory | |
NodeFactory $nodeFactory used for building the resulting AST. More... | |
Differentiate an abstract syntax tree (AST).
Implementation of a Visitor, transforming an AST into another AST representing the derivative of the original AST.
The class implements differentiation rules for all arithmetic operators as well as every elementary function recognized by StdMathLexer and StdmathParser, handling for example the product rule and the chain rule correctly.
To keep the resulting AST reasonably simple, a number of simplification rules are built in.
TODO: handle user specified functions
MathParser\Interpreting\Differentiator::__construct | ( | $variable | ) |
Class constructor.
string | $variable | Differentiation variable |
MathParser\Interpreting\Differentiator::visitConstantNode | ( | ConstantNode | $node | ) |
Differentiate a ConstantNode.
Create a NumberNode representing '0'. (The derivative of a constant is indentically 0).
ConstantNode | $node | AST to be differentiated |
Node |
Implements MathParser\Interpreting\Visitors\Visitor.
MathParser\Interpreting\Differentiator::visitExpressionNode | ( | ExpressionNode | $node | ) |
Differentiate an ExpressionNode.
Using the usual rules for differentiating, create an ExpressionNode giving an AST correctly representing the derivative (x op y)'
where op
is one of +
, -
, *
, /
or ^
UnknownOperatorException | if the operator is something other than + , - , * , / or ^ |
ExpressionNode | $node | AST to be differentiated |
Node |
Implements MathParser\Interpreting\Visitors\Visitor.
MathParser\Interpreting\Differentiator::visitFunctionNode | ( | FunctionNode | $node | ) |
Differentiate a FunctionNode.
Create an ExpressionNode giving an AST correctly representing the derivative f'
where f
is an elementary function.
UnknownFunctionException | if the function name doesn't match one of the above |
FunctionNode | $node | AST to be differentiated |
Node |
Implements MathParser\Interpreting\Visitors\Visitor.
MathParser\Interpreting\Differentiator::visitIntegerNode | ( | IntegerNode | $node | ) |
Interface function for visiting IntegerNodes.
IntegerNode | $node | Node to visit. |
Implements MathParser\Interpreting\Visitors\Visitor.
MathParser\Interpreting\Differentiator::visitNumberNode | ( | NumberNode | $node | ) |
Differentiate a NumberNode.
Create a NumberNode representing '0'. (The derivative of a constant is indentically 0).
NumberNode | $node | AST to be differentiated |
Node |
Implements MathParser\Interpreting\Visitors\Visitor.
MathParser\Interpreting\Differentiator::visitRationalNode | ( | RationalNode | $node | ) |
Interface function for visiting RationalNodes.
RationalNode | $node | Node to visit. |
Implements MathParser\Interpreting\Visitors\Visitor.
MathParser\Interpreting\Differentiator::visitVariableNode | ( | VariableNode | $node | ) |
Differentiate a VariableNode.
Create a NumberNode representing '0' or '1' depending on the differetiation variable.
NumberNode | $node | AST to be differentiated |
Node |
Implements MathParser\Interpreting\Visitors\Visitor.
|
protected |
NodeFactory $nodeFactory used for building the resulting AST.