"Not Used Elsewhere" Is Not "Unused" in a Lean Formalization of the Riemann Hypothesis: Reverse Lookup Against the Compiled Index, Based on Eduinformatics

Kunihiko Takamatsu, Katsuhiko Murakami, Sayaka Matsumoto, Tomohiro Akiyama, Shimpei Matsumoto, Katsuyuki Kunida, Satoshi Takahashi, Tokuro Matsuo, Sachio Hirokawa, Kazuya Tsuruta, Ryosuke Kozaki, Shuto Nishida, Koma Takamatsu, Ford Lumban Gaol, Masao MoriarXiv 2026

TL;DR

When an AI helps generate a colossal, 17-million-line formal proof of the Riemann Hypothesis, how do human volunteers safely prune the dead code without breaking the build? Relying on naive text searches or checking if a declaration is "used in other files" turns out to be a trap—over 96% of declarations ignored by other files are quietly doing vital work right at home in their own file. By indexing the compiler's own ground truth rather than raw source text, the authors show why simple heuristics fail and lay out a foolproof protocol for cleaning up massive, machine-written mathematics.

What Problem Does This Paper Address?

Picture this: on November 20, 2026, a massive Lean 4 formalization of the Riemann Hypothesis drops—175,187 files and over 17.3 million lines of code, largely written by an AI (Claude) alongside mathematician Levent Alpöge. Lean's kernel verifies that the logic holds from the axioms, which is a triumph. However, kernel acceptance doesn't tell humans which parts carry the actual argument and which parts are redundant bloat.

Within days, around 200 GitHub volunteers jumped in to consolidate files and prune dead code. When deleting code, volunteers relied on a seemingly sensible rule of thumb: if no other file uses a declaration, delete it. Even when contributors ran regex text searches inside the declaring file just to be safe, things broke—for example, a search missed thZero because it was invoked via dot-notation as V.thZero, breaking the build within minutes.

Deciding that a piece of code is "unused" is a reverse lookup ("who points to B?"), which is only as reliable as the forward links ("A uses B") you collect. When dealing with an AI-generated artifact too vast for any human to read, our cleanup tools become part of the verification process itself. How far can we trust them?

Methods

Drawing from Eduinformatics—an approach emphasizing the exhaustive collection of primary records rather than relying on aggregated approximations—the authors bypassed fragile source-text parsing altogether.

Instead, they wrote a Lean program to walk the compiled .olean binaries, where Lean’s elaborator has already resolved every ambiguous namespace, notation, and type-class instance into exact kernel terms. They extracted all declarations ($D$), cross-file uses ($U$), and same-file uses ($S$), carefully folding compiler-generated helper constants (like _proof_1 or equation lemmas) back into their parent declarations so theorems wouldn't artificially "use" themselves.

Next, they evaluated how badly source-text heuristics perform against this compiled ground truth using capture–recapture—a statistical technique borrowed from ecology (used to estimate animal populations) and software inspection. Treating the compiled index as both the first capture and the ground truth, and three regex-based text matchers of varying sophistication as the second capture, they analyzed how false matches distort usage estimates, and even formalized the resulting algebraic identity in Lean 4.

Datasets

The primary dataset is a fixed snapshot of the volunteer-consolidated Lean 4 repository (rohanarun/riemann-hypothesis, commit e497a66), comprising 47,780 compiled modules and 871,784 real declarations.

To check if bundling files skewed their findings, the authors also mapped declarations back to the pre-consolidation archive (40e56bab02, containing 174,793 .lean files). Finally, for the capture–recapture text-matcher evaluation, they drew a random sample of 1,000 modules containing 88,003 compiled use-pairs.

Key Insights and Ideas

  • "Not used elsewhere" is a massive false-zero trap: Checking only cross-file links omits an entire edge type (same-file uses). Because helper lemmas naturally live right next to the theorems they serve, ignoring same-file links misclassifies almost everything as dead weight.
  • File bundling isn't to blame: You might suspect same-file uses spiked only because volunteers merged 175k tiny files into 47k larger bundles. By projecting the exact same use-graph back onto the original 174,793-file layout, the authors proved the helpers were already sitting in the same files as their callers before consolidation.
  • In text-based capture–recapture, false positives act like "ghost animals": In ecology, misidentifying a tag creates a "ghost" animal that inflates population estimates. Here, when comparing a text matcher against the complete compiled truth, the Lincoln–Petersen estimate divided by the truth algebraically simplifies to 1 / precision—meaning recall completely cancels out, and name collisions across namespaces directly inflate usage estimates.
  • Elaboration is invisible to text search: Type-class instances, macros, notations, and coercions leave no explicit name in the .lean text. Any tool that only reads source text is permanently blind to over half of cross-file dependencies.

Key Results

  • Out of 871,784 declarations, 454,574 have zero uses from other files. However, 96.5% (438,545) of those are actively used within their own file! Only 16,029 (1.8%) have no recorded use at all.
Breakdown of real declarations showing 96.5% of declarations unused by other files are used in their own file
  • Restoring the pre-consolidation 174,793-file partition barely moves the needle: the false-zero share is 96.73% after consolidation vs. 96.72% before—only 0.048% of false zeros actually crossed file boundaries during the merge.
  • Across 1,000 sampled modules, a simple regex matcher achieved 81.8% precision and 16.1% recall on cross-file uses, inflating the capture–recapture total to 1.22x the truth. Resolving open and namespace scopes bumped precision to 87.4% (inflation 1.14x) and recall to 45.2%, still missing 40,949 of 74,660 cross-file uses.
Fig. 2. Ratio of the capture–recapture estimate to the compiled truth against the precision of the text matcher, for 1,000 random modules. Solid line: 1/precision, the identity (1) that holds when the compiled index is both a capture and the truth. Points: Chapman estimates (filled circles: cross-file; open circles: same-file; squares: all pairs; labels A, B, C give the matcher).
  • Guided by these lessons, the authors propose a three-step safe deletion rule: verify zero uses in a fresh compiled index (including same-file uses), ensure the index matches the target commit, and build locally while checking the git diff.

Limitations and Future Work

The compiled index isn't omniscient: it misses metaprogram references, attributes, and definitional rfl lemmas consumed silently by tactics like simp or dsimp without leaving a constant in the final proof term—making a local test build mandatory before deleting anything. Furthermore, the metrics reflect a single historical commit snapshot and approximate regex matchers rather than full syntax-tree parsers. Future work includes breaking down the 40,949 missed cross-file uses by elaboration type (instances vs. notation) and testing truly compile-free capture–recapture where neither list has access to compiler ground truth.

Summary updated

BibTeX
@misc{takamatsu2026not,
  author = {Kunihiko Takamatsu and Katsuhiko Murakami and Sayaka Matsumoto and Tomohiro Akiyama and Shimpei Matsumoto and Katsuyuki Kunida and Satoshi Takahashi and Tokuro Matsuo and Sachio Hirokawa and Kazuya Tsuruta and Ryosuke Kozaki and Shuto Nishida and Koma Takamatsu and Ford Lumban Gaol and Masao Mori},
  title = {{"Not Used Elsewhere" Is Not "Unused" in a Lean Formalization of the Riemann Hypothesis: Reverse Lookup Against the Compiled Index, Based on Eduinformatics}},
  year = {2026},
  eprint = {2611.37167},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.37167},
}
Figure