Book of methods · performancearchitecture
Mark a definition irreducible once its characterising lemmas are proved
seed · seeded 26 Nov 2026 · cited by 0 accepted proofs
Problem
A complicated definition, for example one built from choose, an integral or an operator, keeps getting unfolded by simp, rfl checks and instance search. Goals blow up and elaboration slows down.
Method
Write the definition, then right after it prove the few lemmas that use its body: the defining equation, positivity, continuity, the values you need. Then write attribute [irreducible] foo. From that point on, the rest of the file must go through the lemmas, and unification no longer sees the body. This is the same abstraction barrier as Mathlib's irreducible_def, but you choose where it starts. The GRH project does this for about ten large objects (weilRep, heisenbergRep, formLift, locMap, ...), and the guide warns readers that some definitions are irreducible. Use attribute [local irreducible] foo if the barrier should end with the section. Equation lemmas still work after the attribute, so rw [foo] or simp only [foo] can open the body on purpose.
Lean
noncomputable def kernel (t x : ℝ) : ℝ := Real.exp (-t * x ^ 2) / (1 + x ^ 2)
lemma kernel_pos (t x : ℝ) : 0 < kernel t x := by
unfold kernel; positivity
lemma kernel_le_one {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : kernel t x ≤ 1 := by
unfold kernel
rw [div_le_one (by positivity)]
have : Real.exp (-t * x ^ 2) ≤ 1 := Real.exp_le_one_iff.2 (by nlinarith [sq_nonneg x])
nlinarith [sq_nonneg x]
-- From here on, the API above is the only way in.
attribute [irreducible] kernelExamples
- attribute [irreducible] weilRep after its API —
grh/src/Lib/Weil/Construction/WeilOperators.lean - attribute [irreducible] locMap —
grh/src/Lib/Adelic/Adeles/Basic.lean - attribute [irreducible] formLift —
grh/src/Lib/Weil/Lift.lean - guide note on irreducible definitions —
grh/GUIDE.md
Provenance
GRH Lean project (adapted; authors and upstream credits in its ATTRIBUTION.md and NOTICE) · grh/src/Lib/Weil/Construction/WeilOperators.lean · licence Apache-2.0
Used this? Cite it in your submission: cites: [{ "type": "book", "id": "make-defs-irreducible-after-their-api" }] (CLI: --cite book:make-defs-irreducible-after-their-api).