Skip to main content

Compile elementary-function formulas into pure EML (Exp-Minus-Log) form

Project description

emltree

Compile elementary-function formulas into pure EML (Exp-Minus-Log) form, where the only operator is

eml(x, y) = exp(x) − ln(y)

and the only constant is 1.

Paper

This project is an implementation of ideas introduced in:

Andrzej Odrzywolek. All elementary functions from a single operator. arXiv:2603.21852 (2026). https://arxiv.org/abs/2603.21852

The paper proves that the single binary operator eml(x, y) = exp(x) − ln(y) together with the constant 1 generates the entire scientific-calculator basis (arithmetic, roots, logs, all trig and hyperbolic functions, the constants e, π, i). Every elementary expression becomes a binary tree whose only internal node is eml. This package is the inverse direction: it takes an ordinary formula and compiles it into that tree. A sibling Rust crate, OxiEML, covers the Rust ecosystem; emltree focuses on the Python side.

Quick start

uv venv --python 3.11
uv pip install -e ".[dev]"

# Compile a formula
uv run emltree "sin(x) + exp(y)" -v x -v y

# ASCII tree
uv run emltree "log(x)" -v x -f tree

# Numerical sanity check
uv run emltree "sin(x)**2 + cos(x)**2" -v x=0.9 --verify

Library use

from emltree import compile_formula, evaluate

tree = compile_formula("sqrt(x**2 + y**2)", variables=["x", "y"])
print(tree.to_nested())
print(evaluate(tree, {"x": 3.0, "y": 4.0}))   # ≈ 5+0j

The returned tree is an immutable ADT (One / Var / Eml) — walk it, hash it, render as RPN (1 x E 1 E), or ship it into an FPGA/analog circuit as the paper suggests.

Why the trees are large

This compiler is compositional, not optimal. Every primitive bottoms out in exp / ln / sub, so sin(x) produces a tree with hundreds of nodes. The paper's direct-search results (Table 4) are vastly shorter — integrating that search is one of the open directions below.

Tests

uv run pytest

Contributing

Contributions are very welcome — this is an early-stage package and there's plenty of room to improve. A few directions that would make a great first PR:

  • Shorter trees — hand-curated or searched EML identities to replace the naive compositional expansions (see paper Table 4).
  • More primitivesabs, sign, floor, ceil, erf, etc. (many require tricks; see the paper's supplementary).
  • Better output — LaTeX, GraphViz / Mermaid, Jupyter rich repr.
  • Batched evaluation — a vectorised numpy/torch evaluator for large input arrays.
  • Optional Rust backend — PyO3 bindings to OxiEML for expensive search and symbolic regression.
  • Docs & examples — walk-throughs of the paper's identities, notebooks showing symbolic-regression use cases.

Please open an issue to discuss before sending a large PR. Bug reports, documentation fixes, and additional test cases are also very welcome — no contribution is too small.

Development

uv venv --python 3.11
uv pip install -e ".[dev]"
uv run pytest

License

MIT — see LICENSE.

Citation

If you use emltree in academic work, please cite the underlying paper:

@article{odrzywolek2026eml,
  title   = {All elementary functions from a single operator},
  author  = {Odrzywolek, Andrzej},
  journal = {arXiv preprint arXiv:2603.21852},
  year    = {2026}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

emltree-0.1.0.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

emltree-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file emltree-0.1.0.tar.gz.

File metadata

  • Download URL: emltree-0.1.0.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for emltree-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6c802c15d81675e42ada9a570c5b0f3b3ef2c5a1f7bc762b9c3a7f02470dac55
MD5 66b11bed61bd7092122f391b4db9af63
BLAKE2b-256 483044159ef59b5a87d8d0cf23f2061f18de5aaa49e97a812715d8512f78d398

See more details on using hashes here.

File details

Details for the file emltree-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: emltree-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for emltree-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5867e298626119fb6bd4b19a999e99d82e53dc05907b7502e501d1502e89c6ed
MD5 9f9e26c57a8e0cb3f70d628f1ac159d7
BLAKE2b-256 d66c970fa88676537fc13204c60f45f526b1d0c2d901fca2924e595cac665fdb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page