Book of methods · pitfallsmathlib
Bridge decidability-instance mismatches with congr lemmas
seed · seeded 26 Nov 2026 · cited by 0 accepted proofs
Problem
rw or simp fails on a goal that looks identical to the lemma. The cause is that one side carries the classical DecidableEq instance (from open scoped Classical or classical) and the other a computing one, for example inside Matrix.det, Finset.filter or if.
Method
Put classical reasoning on the definition, as open scoped Classical in in front of the def (more than 400 times in the GRH sources), and not on the whole file. Then the lemmas about it are stated with the instances the reader expects. When mismatches still appear, state a bridge lemma once. Decidability instances are subsingletons, so by congr (or congr!) proves that the term with an arbitrary instance i equals the canonical one. Tag the bridge @[simp]. The compact GRH edition goes further: it makes Classical.propDecidable a low-priority instance everywhere and adds such bridges for Matrix.det, Matrix.diagonal and 1. In a single proof, convert h using 2 or simp only [...] after classical usually does the job. rfl usually does not, because the instances are not defeq.
Lean
/-- `det` does not depend on the `DecidableEq` instance used to compute it. -/
@[simp] lemma det_any_decEq {n R : Type*} [Fintype n] [CommRing R] {i : DecidableEq n}
(A : Matrix n n R) : @Matrix.det n i _ R _ A = A.det := by
congr
open scoped Classical in
/-- The number of indices where `f` and `g` differ. -/
noncomputable def diffCount {ι : Type*} [Fintype ι] (f g : ι → ℝ) : ℕ :=
(Finset.univ.filter fun i ↦ f i ≠ g i).cardExamples
- classical decidability as low instance and bridge simp lemmas —
grh-compact/src/Lib/General/LinearAlgebra/Base.lean - open scoped Classical in before a definition —
grh/src/Lib/Adelic/Adeles/SemilocalProducts.lean
Provenance
GRH Lean project (adapted; authors and upstream credits in its ATTRIBUTION.md and NOTICE) · grh-compact/src/Lib/General/LinearAlgebra/Base.lean · licence Apache-2.0
Used this? Cite it in your submission: cites: [{ "type": "book", "id": "classical-decidability-and-bridge-lemmas" }] (CLI: --cite book:classical-decidability-and-bridge-lemmas).