Skip to main content

Unified symbolic-numeric expression runtime with EML lowering

Project description

uninum

A symbolic-numeric expression runtime for Python with EML lowering.

Build mathematical expressions as Python objects, then evaluate, differentiate, simplify, compile to fast callables, or lower to a universal representation where every expression becomes a tree of a single binary operator.

Based off of the work and research presented in the paper "All elementary functions from a single operator" - (Odrzywolek, 2026) https://arxiv.org/pdf/2603.21852

Features

  • Expression building with natural Python syntax (+, -, *, /, **) and standard math functions (sin, cos, exp, ln, sqrt, ...)
  • Symbolic differentiation with automatic chain rule, product rule, and all standard derivatives
  • Algebraic simplification via identity elimination, constant folding, and inverse cancellation
  • Compilation to fast callables with a numpy (vectorized) or pure-Python backend
  • EML lowering -- rewrite any expression to a tree of a single operator eml(x, y) = exp(x) - ln(y) plus the constant 1

Install

Requires Python >= 3.10.

python -m venv .venv
source .venv/bin/activate      # Linux/macOS
# .venv\Scripts\activate       # Windows

pip install .                  # core
pip install .[numpy]           # with numpy backend support
pip install .[dev]             # with pytest for running tests

Quickstart

from uninum import var, sin, ln, compile_expr

x = var("x")
y = var("y")

# Build an expression
expr = (x + y) * sin(x) / ln(y)
print(expr)                              # (x + y) * sin(x) / ln(y)

# Evaluate numerically
print(expr.evaluate(x=1.2, y=3.4))      # 3.503404...

# Differentiate and simplify
df = expr.diff(x).simplify()
print(df)

# Compile to a fast callable
fn = compile_expr(expr, backend="python")
print(fn(x=1.2, y=3.4))

# Lower to pure EML form
lowered = expr.to_eml()
print(lowered.evaluate(x=1.2, y=3.4))   # same result

API Overview

Category Name Description
Node types Expr Base class for all expression nodes
Const(value, name=None) Numeric constant
Var(name) Variable
UnaryOp(op, arg) Unary function application
BinOp(op, left, right) Binary operation
Constructors var(name) Create a variable
exp, ln, log Exponential and natural log (log is alias for ln)
sin, cos, tan Trigonometric functions
asin, acos, atan Inverse trigonometric functions
sinh, cosh, tanh Hyperbolic functions
sqrt Square root
eml(x, y) The EML operator: exp(x) - ln(y)
Constants e, pi, I Euler's number, pi, imaginary unit
Methods .evaluate(**kwargs) Numeric evaluation with variable bindings
.diff(wrt) Symbolic derivative (accepts Var or str)
.simplify() Algebraic simplification
.to_eml() Lower to pure EML representation
.to_latex() Render as LaTeX math string
Compilation compile_expr(expr, backend) Compile to callable; "numpy" or "python"
Rendering to_latex(expr) Convert expression to LaTeX

EML in 30 Seconds

The EML operator eml(x, y) = exp(x) - ln(y) is a single binary function that, combined with the constant 1, can express all elementary mathematics. This was shown by Odrzywolek (2024).

from uninum import var, sin, exp

x = var("x")
f = sin(x) + exp(x)

lowered = f.to_eml()                     # pure eml(S, S) tree with leaves = 1 or x
print(lowered.evaluate(x=1.0))           # matches f.evaluate(x=1.0)

The grammar of every lowered expression is simply S -> 1 | x | eml(S, S). See docs/eml_explained.md for the full theory.

Examples

Script What it covers
01_expressions.py Building expressions, evaluation, named constants
02_differentiation.py Symbolic derivatives, chain rule, numerical verification
03_simplification.py Simplification rules, capabilities, and limitations
04_compilation.py Python and numpy backends, vectorized evaluation
05_eml_lowering.py EML operator, lowering process, correctness verification
06_full_workflow.py End-to-end: build, diff, simplify, compile, lower

Documentation

Running Tests

pip install .[dev]
pytest tests/ -v

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

uninum-0.2.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

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

uninum-0.2.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file uninum-0.2.0.tar.gz.

File metadata

  • Download URL: uninum-0.2.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for uninum-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6f378acbc4b7d5e6dac6e4c11339841535b9dad848cf6b20d20eb3e63c54f58a
MD5 73aaea13cb61ca7bfb1cc5359b5831e3
BLAKE2b-256 95ccf36635b8e5880119d92af967fb918ba51a7301408e21321dcdde17d25bb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for uninum-0.2.0.tar.gz:

Publisher: publish.yml on Brumbelow/uninum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file uninum-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: uninum-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for uninum-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2f708e82af6fb4202b352db26f1b61d6979ffae3381f6d00deb0d6c6cb748ab
MD5 7e60cf599f5a05ab2e3207ef6d6a5105
BLAKE2b-256 d85dec3c0c01a14f5d6c4e72c4698bd34115e30b49b9dc2be15c3602a93bbb52

See more details on using hashes here.

Provenance

The following attestation bundles were made for uninum-0.2.0-py3-none-any.whl:

Publisher: publish.yml on Brumbelow/uninum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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