Skip to contents

The EML operator

Odrzywołek (2026, arXiv:2603.21852) proves that the single binary operator

eml(x,y)=exp⁡(x)−ln⁡(y)\mathrm{eml}(x, y) \;=\; \exp(x) - \ln(y)

together with the constant 1, generates every elementary function on the principal branch of the complex numbers. emlR implements the operator, a catalog of canonical EML expressions for every elementary primitive, a two-mode simplifier, a stack-machine bytecode evaluator, and an L-BFGS-B fitter for symbolic regression.

The operator itself:

eml(1, 1) # exp(1) - log(1) = e
#> [1] 2.718282+0i
eml(0, 1) # exp(0) - log(1) = 1
#> [1] 1+0i
eml(0, -1) # 1 - i*pi (principal-branch log of -1)
#> [1] 1-3.141593i

It is internally complex (the principal branch of log is required for log(-1) = iπ). For real-valued inputs known to produce real results use the wrapper:

eml_real(1, 1)
#> [1] 2.718282
eml_real(0.5, 1)
#> [1] 1.648721

Three sacred identities

The paper proves three identities that every EML simplifier must preserve. emlR verifies them in simplify_native(), the rewriter that collapses recognised EML patterns to base-R primitives.

simplify_native(quote(eml(x, 1))) # exp(x)
#> exp(x)
simplify_native(quote(eml(1, 1))) # e (folded)
#> [1] 2.718282
simplify_native(quote(eml(1, eml(eml(1, x), 1)))) # log(x), paper Eq. 5, K=7
#> log(x)

The third identity is the headline of the paper: with K = 7 nodes (or seven RPN tokens, 1 1 x E 1 E E), eml(1, eml(eml(1, x), 1)) is exactly log(x).

log_expr <- quote(eml(1, eml(eml(1, x), 1)))
eml_K(log_expr) # 7  (paper K)
#> [1] 7
eml_depth(log_expr) # 3
#> [1] 3
eml_rpn(log_expr) # "1 1 x E 1 E E"
#> [1] "1 1 x E 1 E E"

Native R AST

EML expressions are not a custom S3 class; they are ordinary R call objects. That means every existing R language tool just works:

e <- quote(eml(1, eml(eml(1, x), 1)))
deparse(e)
#> [1] "eml(1, eml(eml(1, x), 1))"
all.vars(e)
#> [1] "x"
identical(e, bquote(eml(1, eml(eml(1, .(quote(x))), 1))))
#> [1] TRUE

You can also build expressions programmatically:

eml_node(1, "x") # eml(1, x)
#> eml(1, x)
eml_node(1, eml_node(eml_node(1, "x"), 1)) # paper Eq. 5
#> eml(1, eml(eml(1, x), 1))

Evaluating expressions

Two evaluators are available:

xs <- seq(0.5, 5, length.out = 30)
log_expr <- quote(eml(1, eml(eml(1, x), 1)))

# Direct evaluation
v1 <- Re(eml_eval(log_expr, list(x = xs)))

# Bytecode
bc <- compile_eml(log_expr)
v2 <- Re(run_bytecode(bc, list(x = xs)))

max(abs(v1 - v2))
#> [1] 0
max(abs(v1 - log(xs)))
#> [1] 1.665335e-16

The bytecode evaluator is what powers eml_fit() (see vignette("symbolic-regression")); it lets the inner loop of an optimisation run vectorised over hundreds of input points without the overhead of recursive eval().

The catalog

eml_catalog() returns a named list with every elementary primitive as an EML expression:

catalog <- eml_catalog()
names(catalog)
#>  [1] "one"     "e"       "zero"    "neg_one" "two"     "i"       "pi"     
#>  [8] "exp"     "log"     "minus"   "add"     "sub"     "mul"     "div"    
#> [15] "pow"     "sqrt"    "sin"     "cos"
catalog$log
#> eml(1, eml(eml(1, x), 1))
catalog$sub
#> eml(eml(1, eml(eml(1, x), 1)), eml(y, 1))

Each entry numerically evaluates to the right value (verify_catalog() checks all 18 entries):

verify_catalog(verbose = FALSE)

simplify_native() collapses every catalog entry — including the trigonometric and root constructions — to its base-R form literally:

simplify_native(catalog$mul) # x * y
#> x * y
simplify_native(catalog$div) # x / y
#> x/y
simplify_native(catalog$pow) # x ^ y
#> x^y
simplify_native(catalog$sqrt) # x^0.5
#> x^0.5
simplify_native(catalog$sin) # sin(x)
#> sin(x)
simplify_native(catalog$cos) # cos(x)
#> cos(x)
simplify_native(catalog$pi) # ≈ pi
#> [1] 3.141593

Reaching sin(x) and cos(x) requires the cleanup rule exp(_C + log(_x)) → exp(_C) * _x to absorb numeric constants that emerge mid-collapse, plus a small (1e-12) tolerance in the matcher to absorb the round-off in tree_i() = exp(log(-1)/2). Both are applied automatically; see ?simplify_native and SPEC §5.3 for the full mechanism.

Where to next

References

Odrzywołek, A. (2026). All elementary functions from a single binary operator. arXiv:2603.21852.