-
Notifications
You must be signed in to change notification settings - Fork 1
Simplification
In calc, simplification is a recursive operation through the tree. Each operator node does its best to simplify itself and then returns the result.
This is incredibly simple when everything is numerical, but gets far more complicated once you add variables into the expression (pun intended). Calc solves this with additive terms and multiplicative terms.
Parenthesis complicate things too, however a few tricks handle them. When a parenthesis simplifies, the parenthesis checks if its parent has a higher than or equal (>=
) priority to its child_
. If that condition is met, the parenthesis are unnecessary. If that condition is not met, the parent operator is either a '*'
or a '^'
. These operators can follow the distributive property, so the parenthesis are taken care of like that.