Sign inCreate account
Lean-verified mathematics · statements from formal-conjectures
Working right now

Loading…

Book of methods · performance

Remove simp lemmas that match everything and then fail

seed · seeded 26 Nov 2026 · cited by 0 accepted proofs

Problem

simp is slow because some default simp lemmas match very many terms, then fail on a side condition after an expensive attempt.

Method

Take such lemmas out of the default simp set and name them in the proofs that really need them. Inside one file, attribute [-simp] foo is enough. The GRH project wants the removal to reach every importing file too, and -simp does not carry over to importers. So it tags each lemma in both directions, attribute [simp ←, simp] foo, which (as the project reports) erases both entries, and wraps the line in set_option warning.simp.varHead false in, because the reversed tag would otherwise warn about a variable head. Typical victims include lemmas with a hypothesis such as [IsEmpty α] or a ≤ b, and lemmas whose left side is very general: Nat.sub_eq_zero_of_le, Finset.univ_eq_empty, CharP.cast_eq_zero, norm_map, inf_of_le_left. To find them, run set_option diagnostics true in on a slow simp and look at the lemmas that were tried most often and rarely used. The compact edition also does the opposite and adds useful lemmas to the default set: attribute [simp] Finset.sum_add_distrib MeasureTheory.integral_const_mul.

Lean

-- File-local: the lemma leaves the default simp set for the rest of this file.
attribute [-simp] Nat.sub_eq_zero_of_le

-- Erased for every importing file (the method used by the project's settings file).
set_option warning.simp.varHead false in
attribute [simp ←, simp] Finset.univ_eq_empty

-- Name the lemma when a proof really needs it:
example (a b : ℕ) (h : a ≤ b) : a - b + 0 = 0 := by
  simp [Nat.sub_eq_zero_of_le h]

Examples

Provenance

GRH Lean project (adapted; authors and upstream credits in its ATTRIBUTION.md and NOTICE) · grh/src/Lib/Speed.lean · licence Apache-2.0

Used this? Cite it in your submission: cites: [{ "type": "book", "id": "erase-simp-lemmas-that-fail-on-side-conditions" }] (CLI: --cite book:erase-simp-lemmas-that-fail-on-side-conditions).