rh-lean-decomposition Finds the Seams in a 17.5-Million-Line Proof

A Python script reads the import graph of Levent Alpöge's Lean release and asks whether 175,187 modules can be broken into parts. The answer is a single door.

8 min read • View on GitHub • More from drew2apps

A colossal wall built from thousands of rectangular stone blocks rises out of frame. At its base, a tiny surveyor works a theodolite and marks dotted seam lines across the face of the wall, dividing it into a few large panels. The illustration captures the scale of an enormous structure and the act of finding where it can be split into parts.
A 17.5-million-line artifact, and someone drawing the first seam lines across it.
Key Takeaways

A Proof the Size of a Library

Levent Alpöge published a Lean 4 release that claims to formalize the Riemann Hypothesis. Whatever you think of that claim, the artifact itself is a genuine object: fourteen archive parts, a joined SHA-256, and a source tree that no human being can hold in their head.

Here is the size of it. 175,187 modules. 17,549,402 lines of Lean. 753,261 distinct project-to-project imports, with the longest import chain running 202 modules deep. "Big" is the wrong word. This is the size of a mid-sized software library, and it happens to be a single mathematical argument.

You cannot read it. You cannot grep it into comprehension. So the only useful question is not "is it correct" but "what shape is it." That is the question rh-lean-decomposition answers, and the answer is stranger and more useful than a verdict.

Everything Hangs on One Door

The headline finding is a chokepoint you can point at. Everything below the root module, Main, is reached through one module: Supplements.Kernels.MainTheoremsAll. Under it, the dominator tree of the import graph splits the project into components that the rest of the proof touches only through a single entry module.

Read that again, because it is the whole story. A 17.5-million-line artifact does not present as a flat tangle. It presents as a set of rooms, and most of those rooms have exactly one door. If nothing outside a component imports anything inside it except its entry, then the component is self-contained: you can reason about it, test it, or rebuild it without dragging the rest of the proof along.

The dominator tree of the import graph, computed live: a chaotic graph collapses into components, each with a single glowing entry.

That is what a dominator tree is for. A module dominates another if every path from the root to that module passes through it. The dominator tree is the skeleton of the dependency structure, and here the skeleton has a spine you can name.

A tight close-up of a single small keyhole door set into a massive stone wall. Through the doorway, dozens of fine taut threads run inward and fan out toward distant rooms, each thread passing through the doorway before reaching its destination. The image is a literal picture of the dominator concept: one mandatory waypoint that every downstream path must cross.
No thread reaches a room without passing through the door. That is what it means for one module to dominate the rest.

Why Map a Proof You Cannot Check

The project started with a question, not a claim. In the Lean Zulip thread around Alpöge's release, someone asked whether the 175,187-module tree could be broken into manageable parts, and where the seams were. That is a maintainability question. It is the question you ask about a codebase, not a theorem.

The repo is disciplined about its own scope, and the discipline is the point. It analyzes the import graph and nothing else. It does not check the proof. It does not redistribute the source. It derives everything from import lines, file sizes, and keyword counts. No verifier, no kernel, no axioms, no opinion on whether the Riemann Hypothesis has fallen.

That restraint is not modesty. It is method. A structural claim about a giant codebase is checkable by anyone with the tarball and a Python interpreter. A mathematical claim is not. By refusing the second, the repo keeps the first airtight.

How an Import Graph Becomes a Tree

Two scripts do all the work. extract.py walks the release and pulls out the raw material: every import line, every file size, keyword counts per module. It writes a data set, not a conclusion.

analyze.py then takes that data set, builds a directed graph, and computes the dominator tree from the root. The rest is bookkeeping: it emits components.csv and folders.csv, the two maps you actually read. The graph step is the heart of it.

# analyze.py (abridged)
import networkx as nx

G = nx.DiGraph()
for module, deps in graph.items():
    for dep in deps:
        G.add_edge(module, dep)

# immediate dominators from the root module
idom = nx.immediate_dominators(G, start="Main")

# a component is self-contained when every inbound edge
# from outside lands on a single entry module

The math behind it is older than Lean. Dominance analysis comes from compilers, where it answers the same question for control-flow graphs: which basic blocks must execute before this one. Here the blocks are modules, the edges are imports, and the mandatory waypoint is a file path. In plain terms: a module dominates another when every path from the root to that module passes through it, and the dominator tree collects those must-pass nodes into a hierarchy.

The payoff arrives twice. First as navigation: here are the rooms, here is the door to each. Second as a to-do list: any component with a single clean entry is a candidate to be pulled out, checked, or rebuilt on its own.

The 77.6% Problem

The same analysis that found the spine found the bloat. 136,003 modules, 77.6% of the entire release, import Mathlib wholesale. Not a slice of Mathlib. The whole library, pulled in by roughly three out of every four modules.

That is not a proof architecture. It is a dependency habit, and it is the single largest cleanup target the map exposes. When 77.6% of your modules reach for the same giant library, your build graph stops telling you anything useful about what actually depends on what. Every module looks coupled to everything.

This is exactly where a structural map earns its keep. The single-entry components tell you where the proof is genuinely modular. The wholesale-Mathlib number tells you where it only looks modular, because the imports are hiding the real relationships. One finding is a map of the seams. The other is a map of the stitches that still need to be cut.

Mapping, Replaying, Proving

It helps to separate three activities that all get filed under "Lean and the Riemann Hypothesis." They are different jobs with different deliverables, and this repo is cleanly one of them.

ProjectGoalMethodOutput
rh-lean-decompositionMap the structure of a releaseParse import graph, compute dominator treeComponent and folder maps, cleanup targets
TristenHarr/RiemannHypothesisFormalize an anti-Herglotz RH argumentModular Lean 4 / Mathlib refactor of a monolithA proof development, incrementally buildable
rohanarun/alpoge-rh-replayIndependently verify a claimed proofArchive integrity, pinned deps, kernel replayReproducible verification evidence
Mathlib / Lean 4Provide the language and libraryKernel, elaborator, Lake build system, reusable mathInfrastructure, not a proof

Formalizing builds a proof. Replaying audits someone else's. Mapping describes the shape of what already exists. The first two argue about truth. The third just tells you where the walls are, and that is a job nobody else in the list is doing.

The value of a map does not depend on whether the territory is correct. Even if Alpöge's release turns out to be wrong, the import graph is still exactly what it is, and the seams are still exactly where the map says they are. That is a strange kind of contribution, and a durable one.


Sources