
Simplify by collapsing recognised EML patterns to base-R primitives
Source:R/07_simplify.R
simplify_native.RdApplies a top-down rewrite system to fixed point. The output may
contain exp, log, +, -, *, /, ^, and (with
include_euler = TRUE) sin, cos — anything eval() can handle.
Value
The simplified expression, or — if trace = TRUE — a list
containing the simplified expression plus the firing trace.
Details
Rule list (SPEC §3.3, with order tuned to ensure N3 fires before N1
on the structured log pattern):
- N3
eml(1, eml(eml(1, _x), 1))→log(_x)- N4
eml(log(_x), exp(_y))→_x - _y- N5
eml(log(_x), 1)→_x- N7
eml(_x, exp(_y))→exp(_x) - _y- N6
eml(0, _y)→1 - log(_y)- N2
eml(1, 1)→exp(1)- N1
eml(_x, 1)→exp(_x)- C-log-exp
log(exp(_x))→_x- C-exp-log
exp(log(_x))→_x
Constant subtrees are folded as a final step.
See also
simplify_eml() for the mode that stays inside the EML
grammar (constant folding only); eml_catalog() / verify_catalog()
for the test surface this rule set is tuned against.