Building EMLVM: A Single-Instruction Machine for All Math
What if I told you that you could compute any elementary mathematical function using only a single instruction and the constant 1?
That's the premise behind a recent paper I read: "All elementary functions from a single operator" (arXiv 2603.21852). It introduces the EML operator (Exponential Minus Logarithm):
eml(x, y) = exp(x) - ln(y)
Just like the NAND gate is Turing-complete for boolean logic, this single operator can bootstrap the rest of mathematics.
EMLVM, a terminal-based stack machine to explore this concept interactively in WezTerm. It's essentially a cursed, math-centric version of Forth. emlvm.
How it works
The virtual machine is absurdly simple. It evaluates Reverse Polish Notation (RPN) strings like 11xE1EE where:
1pushes the constant1.0xpushes an input variableEpopsy, popsx, and computeseml(x, y)
It turns out 11xE1EE mathematically simplifies exactly to ln(x). By composing these sequences, we can build identity, addition, multiplication, and complex functions.
Proving it with SymPy
Playing around with a calculator to see if 11xE1EE looks like ln(x) is fun, but I wanted hard proof. I integrated a symbolic evaluator using Python's sympy library.
Now, we can execute EML programs symbolically:
$ emlvm algebra '11xE1EE'
# ... builds a symbolic trace proving it collapses to log(x)
We also built an equivalence checker. If we write a wrapper around exp(x) and ln(x) like 11x1EE1EE, we can run an algebraic proof to verify emlvm equiv 11x1EE1EE x to confirm that ln(exp(x)) == x.
Golfing for unknown functions
While the paper lays out the basics, there are plenty of operations—like negation (-x)—that have huge minimum program lengths (e.g., $K=15$).
To find these, I built a golf CLI command. It does an exhaustive search over all valid RPN trees up to a max length $K$, filtering them at C-speed using numpy and exact complex numbers, and then verifying candidates against algebraically independent transcendental numbers using mpmath to guarantee correctness.
It computes trig functions by accident
Because the entire VM uses complex math representations under the hood (via mpmath.mpc), we get trigonometric functions for free via Euler's formula.
Normally, computing sin(x) on purely real numbers with EML takes at least 75 tokens! But if we simply compute exp(i * x) on the VM with an imaginary input, it prints out the correct cos and sin components instantly.
If you want to check it out, the codebase is a pure Python playground waiting for more wild derivations.