Hashing Theorems Modulo Rewrites and Binder Permutation Enables Equivalence Search over 200k Mathlib Theorems
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.
| Quantity | Count |
|---|---|
| Theorem statements extracted | 286,264 |
| Duplicate classes (≥2 members) | 7,525 |
| Kernel-checked certificate pairs | 8,309 |
| Pairs definitionally equal | 6,293 (76%) |
| Pairs not definitionally equal | 2,016 |
