In a recent development, on November 20, 2026, Levent Alpöge and Claude released a Lean 4 proof of the Riemann Hypothesis: roughly 17 million lines of code across more than 175,000 files. Within a day, the Lean FRO and Mathlib Initiative verified that the exported proof passed independent checkers (Lean's kernel and nanoda) against Mathlib's vetted statement of the hypothesis, relying only on Lean's three standard axioms (propext, Classical.choice, and Quot.sound) with zero sorry placeholders.
Five days later, the community repository (leanprover-community/riemann-hypothesis) moved to a condensed edition of roughly 300,000 lines across 800+ files, and a compact edition has since been verified at around 76,000 lines.
Over the past week, I had over 20 refactoring pull requests merged into that repository. Here are three of them:.
I cannot write Lean, I do not know what a complete Witt splitting or a Bessel cutoff argument is, and I do not understand the proof.
Recent findings suggest that my workflow was standard software engineering. I took two maintenance tools I had already built for normal codebases, dry-lint (a code-duplication linter for Python, TypeScript, and Lua) and [CI-esta](https://github.com/gigaverse-app/ci-esta) (a CI profiler and build-acceleration toolkit), and had coding agents (Claude and Codex) add Lean support. The linter found duplicated declarations and proof blocks; the agents refactored the Lean code to remove lines and reuse abstractions; Lean's kernel and CI verified that every change preserved the theorem. My role was supplying the token budget, auditing what the tools missed, and pushing the agents to generalize the tooling to find larger simplifications.
This post is a technical writeup of what we built, what we measured on a 300,000-line formal proof, and the bugs we found in our own tools along the way. In a follow-up piece, I will cover the broader theory of what I call mathematical engineering and what this implies for AI and mathematics.
At 800+ files and roughly 22,000 declarations, a formal proof has the same maintenance problems as a large Python or TypeScript monorepo. Nobody can hold 22,000 declarations in working memory, so the same logic gets written repeatedly in different files.
When we pointed dry-lint at the Riemann repository, three distinct patterns of repetition revealed up:.
In the first two days, dry-lint generated the candidates behind nearly 30 refactoring PRs, cutting over 2,000 lines while adding a few hundred.
The most useful engineering lesson came from checking what our tool could not see.
Industry observers note that A static analyzer that reports "no duplicates" is only meaningful if it actually parsed the repository. Because Lean records the location of every declaration during compilation, we could audit dry-lint's extractor directly against the compiler's ground truth:.
In a recent development, our first parser was silently blind to over 60% of the proof because custom notation and wrappers like omit ... in broke the grammar. Turning on strict validation (--require-complete) rejected almost every file in the repository.
Dropping the full grammar in favor of scanning top-level command boundaries directly from source text solved the problem. It raised coverage to nearly 100% on the Riemann proof and, without any tuning, scanned Mathlib's 240,000+ declarations with the same accuracy. Once coverage hit ~100%, the scan immediately caught the private continuous_finsetSum duplicate mentioned above.
Running a Python/TypeScript linter on ~22,000 declarations exposed two algorithmic slow paths that did not show up on smaller repos:.
Both optimizations live in the shared engine, so Python and TypeScript scans got the same speedups for free.
Sources indicate that in Lean, continuous integration is the trust boundary that lets maintainers accept PRs from contributors who do not understand the math. On every pull request in the Riemann repository, a green CI check enforces four invariants:.
Because every refactor has to clear this gate, CI latency sets the pace of iteration. When we profiled the repository's GitHub Actions workflows with CI-esta on November 26, we found two completely different bottlenecks depending on which queue a job landed in:.
Those two bottlenecks require different fixes.
It has been revealed that to cut the 2-minute Mathlib download without weakening verification, we built restore-lean-packages in CI-esta. A runner operator builds a read-only dependency seed once outside the PR loop (a one-time ~3-minute job containing the pinned Lean toolchain, checkouts, and compiled .olean artifacts). At job start, the action verifies lean-toolchain, lakefile.toml, and lake-manifest.json byte-for-byte along with the pinned Git revisions of every package. On a mismatch, it falls back to the normal download path.
It has been revealed that on a hit, it populates .lake/packages using Btrfs copy-on-write reflinks. Each job gets an isolated writable workspace sharing underlying disk blocks with the read-only seed until modified, while lake build and every axiom check run unchanged.
In paired replays on GitHub-hosted Linux runners (measured in a fork, not yet adopted on the upstream project's runners):.
Restoring the seed took ~13 seconds on Btrfs (compared to ~49 seconds on ext4, showing how much copy-on-write reflinks matter here).
Sources indicate that no cache speeds up a 10-hour runner queue. When a one-file cleanup broke a downstream BorelSpace instance in CayleyChart.lean, a contributor did not need a full CI run just to see if their fix worked.
Sources indicate that we built ci-esta-lean retry to parse a failed Lake build log and print the exact lake build command for the failing modules. On a local checkout with baseline caches restored, that targeted build reproduced the exact CayleyChart diagnostic in ~16 seconds.
We also built ci-esta-lean compare to diff elaborated theorem types directly from compiled .olean files (ignoring binder and universe parameter names while preserving visibility and type structure). This lets a contributor verify locally that a refactor preserved the exact signatures of the five headline theorems before pushing to the queue.
Industry observers note that note on test selection: we checked whether our test-selection tool (pytest-selective) had a role inside Lean builds and found none. Lake already handles incremental module rebuilds from its own import graph; test selection only helped on the repository's Python automation tests.
Everything we built for the Riemann proof is open source and runs without API keys, it can easily find dups in your python/typescript code to de-slop it.
Find duplicated declarations and repeated proof blocks in a Lean project:.
Measure CI queue waits and extract targeted local retry commands from a failed Lake build:.
Both dry-lint blocks and ci-esta retry work on Python, TypeScript, and Bun repositories as well.
