MathParser\Parsing\Nodes\Factories\ExponentiationNodeFactory Class Reference

Factory for creating an ExpressionNode representing '^'. More...

Inheritance diagram for MathParser\Parsing\Nodes\Factories\ExponentiationNodeFactory:
MathParser\Parsing\Nodes\Interfaces\ExpressionNodeFactory

Public Member Functions

 makeNode ($leftOperand, $rightOperand)
 Create a Node representing '$leftOperand^$rightOperand'. More...
 

Private Member Functions

 numericExponent ($leftOperand, $rightOperand)
 Simplify an expression x^y, when y is numeric. More...
 
 doubleExponentiation ($leftOperand, $rightOperand)
 Simplify (x^a)^b when a and b are both numeric. More...
 

Detailed Description

Factory for creating an ExpressionNode representing '^'.

Some basic simplification is applied to the resulting Node.

Member Function Documentation

MathParser\Parsing\Nodes\Factories\ExponentiationNodeFactory::doubleExponentiation (   $leftOperand,
  $rightOperand 
)
private

Simplify (x^a)^b when a and b are both numeric.

Parameters
Node$leftOperand
Node$rightOperand
Return values
Node|null
MathParser\Parsing\Nodes\Factories\ExponentiationNodeFactory::makeNode (   $leftOperand,
  $rightOperand 
)

Create a Node representing '$leftOperand^$rightOperand'.

Using some simplification rules, create a NumberNode or ExpressionNode giving an AST correctly representing '$leftOperand^$rightOperand'.

Simplification rules:

  • To simplify the use of the function, convert integer params to NumberNodes
  • If $leftOperand and $rightOperand are both NumberNodes, return a single NumberNode containing x^y
  • If $rightOperand is a NumberNode representing 0, return '1'
  • If $rightOperand is a NumberNode representing 1, return $leftOperand
  • If $leftOperand is already a power x=a^b and $rightOperand is a NumberNode, return a^(b*y)
Parameters
Node | int$leftOperandMinuend
Node | int$rightOperandSubtrahend
Return values
Node

Implements MathParser\Parsing\Nodes\Interfaces\ExpressionNodeFactory.

MathParser\Parsing\Nodes\Factories\ExponentiationNodeFactory::numericExponent (   $leftOperand,
  $rightOperand 
)
private

Simplify an expression x^y, when y is numeric.

Parameters
Node$leftOperand
Node$rightOperand
Return values
Node|null

The documentation for this class was generated from the following file: