Skip to contents

Applies 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.

Usage

simplify_native(expr, include_euler = TRUE, trace = FALSE)

Arguments

expr

an EML expression (or any R call for re-application).

include_euler

include the Euler rules E1 (sin) and E2 (cos). Default TRUE.

trace

if TRUE, return a list (result, rules, intermediates) capturing every rule firing in order. For debugging only.

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.

Examples

simplify_native(quote(eml(x, 1))) # exp(x)
#> exp(x)
simplify_native(quote(eml(1, eml(eml(1, x), 1)))) # log(x)
#> log(x)
simplify_native(quote(eml(log(a), exp(b)))) # a - b
#> a - b