Lean Kernel Arena (Preview) / perf/let-ladder

Test "perf/let-ladder"

Expected: 👍 accept · Size: 457.9 KB · Lines: 10.4 k · lean4export: 3.2.0 · Lean: 4.38.0-nightly-2026-12-03 · Timeout: 40.0 s · 📄 Declaration · 🔗 Source

The declaration to check has type Nat and value

let x₃ := 0; x₃ + (let x₂ := 0; x₂ + (let x₁ := 0; x₁ + (x₃ + (x₂ + (x₁ + 0)))))

shown at n=3: n let bindings, each separated from the next by an addition, over an innermost sum that names every binding.

Substituting a binding into the body before checking it traverses O(n) nodes at each of the n bindings, for Θ(n²) in time and in allocated nodes. Recording the binding and reading it where the body names it costs O(1) per binding, for Θ(n).

The additions are what keep the bindings apart: a run of adjacent lets could be opened by a single substitution; not so here. Nat.add is the only application head, so no beta reduction is involved.

N=2000 in the Lean source.

Checker Result ⏱️ 🧠
gruszka 👍 4.22 ms (÷110) 119.3 MB (÷2.9)
nano-lean 👍 2.75 ms (÷169) 43.3 MB (÷8.0)
pestka 👍 49.4 ms (÷9.4) 59.2 MB (÷5.9)
con-leche 👍 475 ms (+3%) 229.4 MB (-34%)
con-ron 👍 768 ms (+66%) 303.8 MB (-12%)
nucleus 🚫 125 ms 16.5 MB
official 👍 464 ms 346.7 MB