← All papers
First page of Hashing Theorems Modulo Rewrites and Binder Permutation Enables Equivalence Search over 200k Mathlib Theorems

Hashing Theorems Modulo Rewrites and Binder Permutation Enables Equivalence Search over 200k Mathlib Theorems

Samuel Leßmann, Simon Henniger, Gabriel Poesia, Nada Amin

cs.LO Nov 22, 2026 · v1 cs.PL
Implements a Lean tool that normalizes Mathlib theorem statements to detect duplicates, emitting kernel-checked equivalence certificates; its rewrite-system metatheory is proved in Lean.
Like all code, Lean libraries accumulate technical debt and structural deficiencies over the course of their development. A particular concern is duplicate theorems: different parts of a big library can unwittingly contain and prove the same theorem, duplicating maintenance efforts. Tools can help detect redundancy and clean up. For instance, Mathlib's duplicate-declarations linter compares theorem types syntactically after sorting top-level binders and erasing binder information and universe levels. If detecting an equivalence requires unfolding, reorientation, or logical transformations, it escapes this comparison. In this work, we present a method to detect theorems which are equivalent with regard to argument order and currying/uncurrying of dependent types. We implement our method for Lean. By applying it to Mathlib, a library of more than 200k theorems, we demonstrate that it is computationally cheap and scalable. We discuss how our work may enhance efforts to tackle the maintenance burden of Lean libraries.

Large Lean libraries such as Mathlib accumulate duplicate theorems that waste maintenance effort. Mathlib's duplicate-declarations linter only compares statements syntactically, so it misses equivalences up to argument reordering, currying/uncurrying, or simple unfoldings.

Lean propositions are embedded into a syntactic term fragment and normalized with a terminating eight-rule rewrite system based on type isomorphisms for dependent products and sums. Normal forms are represented as annotated graphs, bucketed by a color-refinement signature, and compared by graph isomorphism up to binder permutation and renaming. Each detected pair is certified by a Lean proof term of T1 ↔ T2 that is checked by the kernel. The metatheory of the rewrite system and isomorphism procedure is proved in Lean.

On 286,264 statements from Lean core, Batteries and Mathlib, the run took about half an hour on an 8-vCPU server. It found 7,525 duplicate classes and produced 8,309 kernel-checked certificates, 2,016 of them for pairs that are not definitionally equal. It also identified 873 maintenance candidates.

QuantityCount
Theorem statements extracted286,264
Duplicate classes (≥2 members)7,525
Kernel-checked certificate pairs8,309
Pairs definitionally equal6,293 (76%)
Pairs not definitionally equal2,016
Tool run over Lean core, Batteries and Mathlib (selected rows)