Simplification Rules
Simplification Rules
This module defines the specific simplification rules used by the SimplificationEngine. The rules are organized into an object, keyed by the omdNode type they apply to.
Rule Structure
Each rule is an instance of SimplificationEngine.SimplificationRule and has three main parts:
matchfunction: Determines if the rule can be applied to a given node.transformfunction: Executes the simplification and returns a new, transformed node.messagefunction: Generates a human-readable description of the transformation.
Available Rules
The rules object contains arrays of rules for each of the following node types:
binary (for omdBinaryExpressionNode)
- Same Term Cancellation:
a - asimplifies to0. - Opposite Term Cancellation:
a + (-a)simplifies to0. - Cancel Constants in Sums:
x + 2 - 2simplifies tox + 0. - Constant Folding: Evaluates operations on constants (e.g.,
2 + 3->5). Includes rules foradd,subtract,multiply, anddivide. - Identity Operations: Simplifies operations with identity elements (e.g.,
x + 0->x,y * 1->y). - Zero Multiplication:
x * 0simplifies to0. - Combine Coefficients:
2 * 3xsimplifies to6x. - Distributive Property:
2 * (x + 3)expands to2x + 6. - Expand Polynomial Multiplication:
(x + 2)(x + 3)expands tox^2 + 5x + 6. - Multiply Monomials:
2x * 3xsimplifies to6x^2. - Combine Like Factors:
x * xsimplifies tox^2. - Combine Multiple Constants in Sums:
x + 2 + 3simplifies tox + 5. - Combine Like Terms:
2x + 3xsimplifies to5x.
rational (for omdRationalNode)
- Variable Self Division:
x / xsimplifies to1. - Power Base Division:
x^n / xsimplifies tox^(n-1). - Monomial Variable Division:
cx / xsimplifies toc. - Simplify Fraction: Reduces constant fractions to their simplest form (e.g.,
6/8->3/4). - Simplify Multiplication in Rational:
(4x)/3restructures to(4/3) * x. - Simplify Rational Division:
(4x + 6) / 2distributes the division to2x + 3.
parenthesis (for omdParenthesisNode)
- Remove Redundant Parentheses:
((x))simplifies to(x).
unary (for omdUnaryExpressionNode)
- Simplify Double Negation:
-(-x)simplifies tox. - Remove Unary Plus:
+xsimplifies tox.
power (for omdPowerNode)
- Calculate Powers: Evaluates constant powers (e.g.,
2^3->8). - Power of Zero:
x^0simplifies to1. - Power of One:
x^1simplifies tox. - Expand Polynomial Power:
(x - 2)^2expands tox^2 - 4x + 4. - Square of Square Root:
(sqrt(x))^2simplifies tox. - Fractional Exponent to Square Root:
x^(1/2)converts tosqrt(x).
sqrt (for omdSqrtNode)
- Simplify Square Root of Constant:
sqrt(9)simplifies to3. - Square Root of Square:
sqrt(x^2)simplifies tox(assumingx >= 0).
function (for omdFunctionNode)
- Function Inverse Simplification:
sin(arcsin(x))simplifies tox. - Function to Sqrt Node: Converts
sqrt(x)from a function representation to the dedicatedomdSqrtNode.
Rule Lookup
The getRulesForNode(node) function is used by the simplification engine to retrieve the appropriate list of rules for a given node based on its type.
See Also
omdSimplification: The top-level module that uses these rules.SimplificationEngine: The engine that provides the helpers to create and apply these rules.