emlgrad is a tiny scalar autograd toy with strong micrograd vibes.
The twist is that it only has one primitive math op:
eml(x, y) = exp(x) - ln(y)
This project is mostly inspired by:
- Andrej Karpathy's
micrograd - Andrzej Odrzywolek's paper, "All elementary functions from a single binary operator"
So the basic idea is:
What if a micrograd-style engine kept the same small DAG + backprop feel, but built its math by composing EML?
- emlgrad/engine.py: the scalar
Valueengine and backward pass - emlgrad/nn.py: a very small
micrograd-styleMLPwrapper - demo.ipynb: a notebook in the spirit of the original
micrograddemo
Higher ops like log, +, -, *, /, **, and relu are all lowered into eml.
- complex-domain first
- principal-branch
log - branch cuts and
log(0)are not hidden away - some paths can still produce
infornan
This repo is meant to stay small, readable, and a little weird.
This repo uses uv.
uv sync --group dev
uv run python -m unittest discover -s tests
uv run --group dev ruff check .To open the notebook:
uv run --with jupyter jupyter notebook demo.ipynb