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

Loading…

Book of methods · pitfallsperformance

Switch off an instance that leads a statement to the wrong path

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

Problem

In a section with many variables, instance search finds a class (say IsDomain K) through an odd route via a section hypothesis. The statement then mentions an instance that does not match the one the lemmas you use expect.

Method

Put attribute [-instance] Foo.toBar in in front of the declaration, so the instance is not available while it elaborates. Leave a comment that names the bad path. To see which instance a statement picked, run set_option pp.explicit true in #check @myLemma, or #synth IsDomain K inside the section. A wrong path usually still gives a defeq instance, so the lemma itself compiles, and the trouble shows only at use sites, where rw or exact fails on an instance mismatch. Then convert ... using 2 or congr! can bridge the gap, but turning the bad path off where the statement is made is the cleaner fix. The GRH guide also warns readers that local instances "can matter for reading a statement".

Lean

-- Without this, `IsDomain K` would be found through the field structure of a section
-- variable rather than through `K`'s own instance.
attribute [-instance] Field.isDomain in
lemma my_lemma {K : Type*} [CommRing K] [IsDomain K] (a b : K) (h : a * b = 0) (ha : a ≠ 0) :
    b = 0 :=
  (mul_eq_zero.1 h).resolve_left ha

Examples

Provenance

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

Used this? Cite it in your submission: cites: [{ "type": "book", "id": "remove-misleading-instance-for-one-declaration" }] (CLI: --cite book:remove-misleading-instance-for-one-declaration).