lean-inf
Compute with infinities (H) and infinitesimals (ε = 1/H) in Lean 4 — with zero-sorry verified fast algorithms, discontinuous automatic differentiation, and a live calculator web app.
Highlights
- Exact Levi-Civita arithmetic with rational exponents and rational coefficients (
H * ε = 1,2H + 1 > 2H,ε² < ε < √ε < 1 < H). - Zero-
sorryverified refactors (FastLCvs original naive HashMapLeviCivitaNum,#print axiomsclean — only[propext, Classical.choice, Quot.sound]):O(1)signumFastvsO(n log n)sort (311× – 540× faster)O(n + m)two-pointer sorted merge addition (addMerge)- Verified Karatsuba multiplication (
O(n^1.585)) + balanced-tree sparse fallback (mulTree) (5.8× faster at n=512) O(log k)binary exponentiation (powFast) (4.3× faster at k=48)O(log N)quadratically convergent Newton-Raphson inversion (newton_order_doubles) (13.8× faster at order=40)
- Step function → Dirac delta via pure Levi-Civita AD (
LeanInf/StepFunction.lean): differentiatesL_H(x) = 1 / (1 + e^{-Hx})automatically with stepε²(yielding(1/4)H - (1/48)ε + ...atx = 0and hyperfinite area≈ 1.000), plus finite specializationevalFinite(H ↦ N,ε ↦ 1/N). - 122-test differential & expression suite (
lake exe inf test) covering Crowell'sTest.js, algebraic laws, naive-vs-fast equivalence, and step-function AD. - Live HTTP API & Blog Calculator (
server/server.ts,~/blog/inf/index.html).
Quick Start
lake build
.lake/build/bin/inf test # 122/122 differential & expression tests
.lake/build/bin/inf bench # Naive HashMap vs Verified FastLC benchmarks
.lake/build/bin/inf step-demo --N 100 # Step function -> Dirac delta & H -> 100 eval
.lake/build/bin/inf eval "dstep(0)" --N 100
.lake/build/bin/inf repl # Interactive calculator
uv run scripts/generate_plots.py # Regenerate plots from Lean 4 JSON
bun run server/server.ts # Start Lean 4 HTTP API on 127.0.0.1:4420