Skip to contents

Three for the constants under the unit sky, Seven for the powers in their halls of base, Nine for the trig that wax and wane and die, One for the formula on its symbolic place, One eml to rule them all, one eml to find them, One eml to bring them all and in the AST bind them.

R implementation of the EML (Exp-Minus-Log) Sheffer operator from Odrzywołek, A. (2026). All elementary functions from a single binary operator. arXiv:2603.21852.

The paper proves a remarkable result: 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 — sums, products, powers, logarithms, trigonometric functions, π, i, the lot — over the complex numbers (principal branch). emlR operationalises that result in idiomatic R for symbolic manipulation, symbolic regression, and pedagogical exploration.

Note. All mathematical results in this package are due to Odrzywołek (2026). emlR is an independent R implementation; please cite the paper if you use it in published work — see Citation below.

Installation

install.packages("Deriv")
# install.packages("remotes")
remotes::install_github("pjt222/emlR")

The package depends only on base R and Deriv.

Quick start

library(emlR)

# The three sacred identities (paper, §1 + Eq. 5)
simplify_native(quote(eml(x, 1)))                          #> exp(x)
simplify_native(quote(eml(1, 1)))                          #> exp(1) ≈ 2.718
simplify_native(quote(eml(1, eml(eml(1, x), 1))))           #> log(x)

# Vectorised evaluation through the bytecode fast path
xs <- seq(0.5, 5, length.out = 30)
bc <- compile_eml(quote(eml(1, eml(eml(1, x), 1))))
Re(run_bytecode(bc, list(x = xs)))                          # log(xs)

# Symbolic regression: recover ln(x) from data with the master formula
fit <- eml_fit(xs, log(xs), depth = 3, n_restarts = 10)
fit$snap_mse                                                # ~0 ⇒ exact recovery

Workflow

The pipeline below is auto-generated from # put annotations in R/*.R by putior. Edit annotations next to the function definition; CI regenerates the diagram on every push to main.

flowchart LR
    con_build(["Construct EML AST"])
    ins_metrics[["Inspect: K, depth, RPN"]]
    ev_eval[["eml_eval (one-off)"]]
    bc_compile["compile_eml"]
    bc_run[["run_bytecode (vectorised)"]]
    simp_native["simplify_native (collapse to base R)"]
    cat_catalog(["eml_catalog (18 primitives)"])
    cat_verify[["verify_catalog"]]
    mas_build["build_master (depth-n formula)"]
    mas_data(["Training data (x, y)"])
    mas_fit["eml_fit (L-BFGS-B + Deriv gradient)"]
    mas_recover[["Recovered AST (snap to one-hot)"]]

    %% Connections
    con_build --> ins_metrics
    con_build --> ev_eval
    con_build --> bc_compile
    bc_compile --> bc_run
    con_build --> simp_native
    cat_catalog --> cat_verify
    mas_data --> mas_fit
    mas_build --> mas_fit
    mas_fit --> mas_recover

    %% Styling
    classDef inputStyle fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e40af
    class con_build inputStyle
    class cat_catalog inputStyle
    class mas_data inputStyle
    classDef processStyle fill:#ede9fe,stroke:#7c3aed,stroke-width:2px,color:#5b21b6
    class bc_compile processStyle
    class simp_native processStyle
    class mas_build processStyle
    class mas_fit processStyle
    classDef outputStyle fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#15803d
    class ins_metrics outputStyle
    class ev_eval outputStyle
    class bc_run outputStyle
    class cat_verify outputStyle
    class mas_recover outputStyle

What’s in the box

Operator eml(), eml_real() — complex-domain, principal branch
AST Native R call objects; free interop with deparse, bquote, Deriv::Deriv, eval
Inspect eml_K(), eml_depth(), eml_rpn()
Evaluate eml_eval(), plus a stack-machine compile_eml() / run_bytecode() for vectorised input
Simplify simplify_eml() (stays in EML), simplify_native() (collapses to base-R primitives)
Catalog tree_* constructors and eml_catalog() for every standard primitive; verify_catalog() to confirm
SR build_master() + eml_fit() with L-BFGS-B and analytic gradients via Deriv

See the package website at https://pjt222.github.io/emlR/ for full documentation and articles.

If you use this package, you may also be interested in the following implementations of the same operator and identities:

Project Language Author Purpose
VA00/SymbolicRegressionPackage Mathematica + Rust Andrzej Odrzywołek Author’s reference; includes the EML toolkit and the Log_fit.nb symbolic-regression notebook reproduced as a vignette here
cool-japan/oxieml Rust KitaSan AI Pure-Rust crate implementing the operator and bytecode evaluator
tomdif/eml-lean Lean 4 tomdif Formal verification of the paper’s identity chain
emlR R Philipp Thoss This package — peephole simplifier, vectorised bytecode, and SR fitter

The Lean 4 project is particularly valuable as a sanity check: every identity it verifies, emlR’s simplify_native() should produce the corresponding base-R primitive.

Status

Release candidate: 0.1.0, the first CRAN submission. The API and feature set for this release are frozen (see NEWS.md); not yet on CRAN.

Scope and limitations

What this release covers and what it does not:

  • Variables. Univariate and bivariate expressions are tested exhaustively (every catalog entry, the SR fitter, the bytecode evaluator). The infrastructure does not preclude x, y, z, ... but cases beyond two variables are not part of the test surface.
  • Operator family. Only the EML operator eml(x, y) = exp(x) − log(y) is implemented. The EDL variant exp(x) / log(y) and the swapped form −eml(y, x) from the paper Eq. (4b/4c) are out of scope for this release.
  • Symbolic regression. eml_fit() uses the paper’s master-formula approach with L-BFGS-B + analytic gradients. Tree-topology search (genetic-programming style) is not provided; the master formula at fixed depth is sufficient for reproducing the paper’s results.
  • Acceleration. Pure base R + Deriv. No Rcpp, no torch, no parallelisation. The bytecode evaluator vectorises over input bindings within a single R loop, which is fast enough for the paper’s reproducibility scale; it is not a benchmark machine.
  • Branch semantics. Everything is on the principal complex branch (log(-1) = iπ). Multi-valued or alternative-branch evaluation is not supported.
  • Numerical tolerance. The simplifier’s atomic-equality check uses a 1e-12 tolerance to absorb round-off from complex exp/log chains in catalog constructions like tree_i() = exp(log(-1)/2). User constants below that magnitude are preserved unless paired with a dominantly large component; see ?simplify_native for the full rule.

Citation

If you use emlR in published work, please cite both the paper and the package:

@article{odrzywolek2026eml,
  title         = {All elementary functions from a single binary operator},
  author        = {Odrzywołek, Andrzej},
  year          = {2026},
  eprint        = {2603.21852},
  archivePrefix = {arXiv},
  primaryClass  = {cs.SC},
  url           = {https://arxiv.org/abs/2603.21852}
}

@software{emlR,
  author = {Thoss, Philipp},
  title  = {{emlR}: All elementary functions from a single binary
            operator, in {R}},
  year   = {2026},
  url    = {https://github.com/pjt222/emlR},
  note   = {Independent R implementation of arXiv:2603.21852}
}

License

MIT (see LICENSE). The paper itself is CC BY 4.0; all mathematical results are due to Odrzywołek (2026), and emlR is an independent R implementation. Cite the paper for any reuse of the results.