Skip to content

Commit b39e9ff

Browse files
committed
fix: remove undercover open Classicals (#23750)
`attribute [local instance] Classical.propDecidable` is much worse than `open scoped Classical`, as it introduces the instance with a default priority that overrides other better decidable instances.
1 parent dafc764 commit b39e9ff

File tree

10 files changed

+74
-72
lines changed

10 files changed

+74
-72
lines changed

Archive/Imo/Imo1988Q6.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ and apply this to prove Q6 of IMO1988.
2323
To illustrate the technique, we also prove a similar result.
2424
-/
2525

26-
27-
-- open_locale classical
28-
attribute [local instance] Classical.propDecidable
29-
3026
attribute [local simp] sq
3127

3228
namespace Imo1988Q6

Mathlib/Analysis/NormedSpace/ENormedSpace.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ normed space, extended norm
3434

3535
noncomputable section
3636

37-
attribute [local instance] Classical.propDecidable
3837
set_option linter.deprecated false
3938

4039
open ENNReal
@@ -119,7 +118,7 @@ instance partialOrder : PartialOrder (ENormedSpace 𝕜 V) where
119118

120119
/-- The `ENormedSpace` sending each non-zero vector to infinity. -/
121120
noncomputable instance : Top (ENormedSpace 𝕜 V) :=
122-
⟨{ toFun := fun x => if x = 0 then 0 else
121+
⟨{ toFun := fun x => open scoped Classical in if x = 0 then 0 else
123122
eq_zero' := fun x => by split_ifs <;> simp [*]
124123
map_add_le' := fun x y => by
125124
split_ifs with hxy hx hy hy hx hy hy <;> try simp [*]
@@ -140,7 +139,7 @@ theorem top_map {x : V} (hx : x ≠ 0) : (⊤ : ENormedSpace 𝕜 V) x = ⊤ :=
140139

141140
noncomputable instance : OrderTop (ENormedSpace 𝕜 V) where
142141
top := ⊤
143-
le_top e x := if h : x = 0 then by simp [h] else by simp [top_map h]
142+
le_top e x := by obtain h | h := eq_or_ne x 0 <;> simp [top_map, h]
144143

145144
noncomputable instance : SemilatticeSup (ENormedSpace 𝕜 V) :=
146145
{ ENormedSpace.partialOrder with

Mathlib/Data/PFunctor/Univariate/M.lean

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,8 @@ theorem ext_aux [Inhabited (M F)] [DecidableEq F.A] {n : ℕ} (x y z : M F) (hx
505505

506506
open PFunctor.Approx
507507

508-
attribute [local instance] Classical.propDecidable
509-
510-
theorem ext [Inhabited (M F)] (x y : M F) (H : ∀ ps : Path F, iselect ps x = iselect ps y) :
508+
theorem ext [Inhabited (M F)] [DecidableEq F.A] (x y : M F)
509+
(H : ∀ ps : Path F, iselect ps x = iselect ps y) :
511510
x = y := by
512511
apply ext'; intro i
513512
induction' i with i i_ih
@@ -538,7 +537,8 @@ structure IsBisimulation : Prop where
538537
/-- The tails are equal -/
539538
tail : ∀ {a} {f f' : F.B a → M F}, M.mk ⟨a, f⟩ ~ M.mk ⟨a, f'⟩ → ∀ i : F.B a, f i ~ f' i
540539

541-
theorem nth_of_bisim [Inhabited (M F)] (bisim : IsBisimulation R) (s₁ s₂) (ps : Path F) :
540+
theorem nth_of_bisim [Inhabited (M F)] [DecidableEq F.A]
541+
(bisim : IsBisimulation R) (s₁ s₂) (ps : Path F) :
542542
(R s₁ s₂) →
543543
IsPath ps s₁ ∨ IsPath ps s₂ →
544544
iselect ps s₁ = iselect ps s₂ ∧
@@ -567,6 +567,7 @@ theorem nth_of_bisim [Inhabited (M F)] (bisim : IsBisimulation R) (s₁ s₂) (p
567567

568568
theorem eq_of_bisim [Nonempty (M F)] (bisim : IsBisimulation R) : ∀ s₁ s₂, R s₁ s₂ → s₁ = s₂ := by
569569
inhabit M F
570+
classical
570571
introv Hr; apply ext
571572
introv
572573
by_cases h : IsPath ps s₁ ∨ IsPath ps s₂

Mathlib/Data/Set/Function.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,11 +884,10 @@ namespace Function
884884

885885
variable {s : Set α} {f : α → β} {a : α} {b : β}
886886

887-
attribute [local instance] Classical.propDecidable
888-
889887
/-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f`
890888
on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/
891889
noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α :=
890+
open scoped Classical in
892891
if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α›
893892

894893
variable [Nonempty α]

Mathlib/Logic/Basic.lean

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Classical versions are in the namespace `Classical`.
2323
-/
2424

2525
open Function
26-
attribute [local instance 10] Classical.propDecidable
2726

2827
section Miscellany
2928

@@ -115,10 +114,12 @@ section Propositional
115114
alias Iff.imp := imp_congr
116115

117116
-- This is a duplicate of `Classical.imp_iff_right_iff`. Deprecate?
118-
theorem imp_iff_right_iff {a b : Prop} : (a → b ↔ b) ↔ a ∨ b := Decidable.imp_iff_right_iff
117+
theorem imp_iff_right_iff {a b : Prop} : (a → b ↔ b) ↔ a ∨ b :=
118+
open scoped Classical in Decidable.imp_iff_right_iff
119119

120120
-- This is a duplicate of `Classical.and_or_imp`. Deprecate?
121-
theorem and_or_imp {a b c : Prop} : a ∧ b ∨ (a → c) ↔ a → b ∨ c := Decidable.and_or_imp
121+
theorem and_or_imp {a b c : Prop} : a ∧ b ∨ (a → c) ↔ a → b ∨ c :=
122+
open scoped Classical in Decidable.and_or_imp
122123

123124
/-- Provide modus tollens (`mt`) as dot notation for implications. -/
124125
protected theorem Function.mt {a b : Prop} : (a → b) → ¬b → ¬a := mt
@@ -145,10 +146,11 @@ theorem eq_or_ne {α : Sort*} (x y : α) : x = y ∨ x ≠ y := em <| x = y
145146

146147
theorem ne_or_eq {α : Sort*} (x y : α) : x ≠ y ∨ x = y := em' <| x = y
147148

148-
theorem by_contradiction {p : Prop} : (¬p → False) → p := Decidable.byContradiction
149+
theorem by_contradiction {p : Prop} : (¬p → False) → p :=
150+
open scoped Classical in Decidable.byContradiction
149151

150152
theorem by_cases {p q : Prop} (hpq : p → q) (hnpq : ¬p → q) : q :=
151-
if hp : p then hpq hp else hnpq hp
153+
open scoped Classical in if hp : p then hpq hp else hnpq hp
152154

153155
alias by_contra := by_contradiction
154156

@@ -181,15 +183,15 @@ theorem of_not_not {a : Prop} : ¬¬a → a := by_contra
181183

182184
theorem not_ne_iff {α : Sort*} {a b : α} : ¬a ≠ b ↔ a = b := not_not
183185

184-
theorem of_not_imp : ¬(a → b) → a := Decidable.of_not_imp
186+
theorem of_not_imp : ¬(a → b) → a := open scoped Classical in Decidable.of_not_imp
185187

186188
alias Not.decidable_imp_symm := Decidable.not_imp_symm
187189

188-
theorem Not.imp_symm : (¬a → b) → ¬b → a := Not.decidable_imp_symm
190+
theorem Not.imp_symm : (¬a → b) → ¬b → a := open scoped Classical in Not.decidable_imp_symm
189191

190-
theorem not_imp_comm : ¬a → b ↔ ¬b → a := Decidable.not_imp_comm
192+
theorem not_imp_comm : ¬a → b ↔ ¬b → a := open scoped Classical in Decidable.not_imp_comm
191193

192-
@[simp] theorem not_imp_self : ¬a → a ↔ a := Decidable.not_imp_self
194+
@[simp] theorem not_imp_self : ¬a → a ↔ a := open scoped Classical in Decidable.not_imp_self
193195

194196
theorem Imp.swap {a b : Sort*} {c : Prop} : a → b → c ↔ b → a → c :=
195197
fun h x y ↦ h y x, fun h x y ↦ h y x⟩
@@ -257,29 +259,31 @@ theorem Or.imp3 {d e c f : Prop} (had : a → d) (hbe : b → e) (hcf : c → f)
257259

258260
export Classical (or_iff_not_imp_left or_iff_not_imp_right)
259261

260-
theorem not_or_of_imp : (a → b) → ¬a ∨ b := Decidable.not_or_of_imp
262+
theorem not_or_of_imp : (a → b) → ¬a ∨ b := open scoped Classical in Decidable.not_or_of_imp
261263

262264
-- See Note [decidable namespace]
263265
protected theorem Decidable.or_not_of_imp [Decidable a] (h : a → b) : b ∨ ¬a :=
264266
dite _ (Or.inl ∘ h) Or.inr
265267

266-
theorem or_not_of_imp : (a → b) → b ∨ ¬a := Decidable.or_not_of_imp
268+
theorem or_not_of_imp : (a → b) → b ∨ ¬a := open scoped Classical in Decidable.or_not_of_imp
267269

268-
theorem imp_iff_not_or : a → b ↔ ¬a ∨ b := Decidable.imp_iff_not_or
270+
theorem imp_iff_not_or : a → b ↔ ¬a ∨ b := open scoped Classical in Decidable.imp_iff_not_or
269271

270-
theorem imp_iff_or_not {b a : Prop} : b → a ↔ a ∨ ¬b := Decidable.imp_iff_or_not
272+
theorem imp_iff_or_not {b a : Prop} : b → a ↔ a ∨ ¬b :=
273+
open scoped Classical in Decidable.imp_iff_or_not
271274

272-
theorem not_imp_not : ¬a → ¬b ↔ b → a := Decidable.not_imp_not
275+
theorem not_imp_not : ¬a → ¬b ↔ b → a := open scoped Classical in Decidable.not_imp_not
273276

274277
theorem imp_and_neg_imp_iff (p q : Prop) : (p → q) ∧ (¬p → q) ↔ q := by simp
275278

276279
/-- Provide the reverse of modus tollens (`mt`) as dot notation for implications. -/
277280
protected theorem Function.mtr : (¬a → ¬b) → b → a := not_imp_not.mp
278281

279282
theorem or_congr_left' {c a b : Prop} (h : ¬c → (a ↔ b)) : a ∨ c ↔ b ∨ c :=
280-
Decidable.or_congr_left' h
283+
open scoped Classical in Decidable.or_congr_left' h
281284

282-
theorem or_congr_right' {c : Prop} (h : ¬a → (b ↔ c)) : a ∨ b ↔ a ∨ c := Decidable.or_congr_right' h
285+
theorem or_congr_right' {c : Prop} (h : ¬a → (b ↔ c)) : a ∨ b ↔ a ∨ c :=
286+
open scoped Classical in Decidable.or_congr_right' h
283287

284288
/-! ### Declarations about distributivity -/
285289

@@ -290,39 +294,44 @@ alias Iff.iff := iff_congr
290294
-- @[simp] -- FIXME simp ignores proof rewrites
291295
theorem iff_mpr_iff_true_intro {P : Prop} (h : P) : Iff.mpr (iff_true_intro h) True.intro = h := rfl
292296

293-
theorem imp_or {a b c : Prop} : a → b ∨ c ↔ (a → b) ∨ (a → c) := Decidable.imp_or
297+
theorem imp_or {a b c : Prop} : a → b ∨ c ↔ (a → b) ∨ (a → c) :=
298+
open scoped Classical in Decidable.imp_or
294299

295-
theorem imp_or' {a : Sort*} {b c : Prop} : a → b ∨ c ↔ (a → b) ∨ (a → c) := Decidable.imp_or'
300+
theorem imp_or' {a : Sort*} {b c : Prop} : a → b ∨ c ↔ (a → b) ∨ (a → c) :=
301+
open scoped Classical in Decidable.imp_or'
296302

297-
theorem not_imp : ¬(a → b) ↔ a ∧ ¬b := Decidable.not_imp_iff_and_not
303+
theorem not_imp : ¬(a → b) ↔ a ∧ ¬b := open scoped Classical in Decidable.not_imp_iff_and_not
298304

299-
theorem peirce (a b : Prop) : ((a → b) → a) → a := Decidable.peirce _ _
305+
theorem peirce (a b : Prop) : ((a → b) → a) → a := open scoped Classical in Decidable.peirce _ _
300306

301-
theorem not_iff_not : (¬a ↔ ¬b) ↔ (a ↔ b) := Decidable.not_iff_not
307+
theorem not_iff_not : (¬a ↔ ¬b) ↔ (a ↔ b) := open scoped Classical in Decidable.not_iff_not
302308

303-
theorem not_iff_comm : (¬a ↔ b) ↔ (¬b ↔ a) := Decidable.not_iff_comm
309+
theorem not_iff_comm : (¬a ↔ b) ↔ (¬b ↔ a) := open scoped Classical in Decidable.not_iff_comm
304310

305-
theorem not_iff : ¬(a ↔ b) ↔ (¬a ↔ b) := Decidable.not_iff
311+
theorem not_iff : ¬(a ↔ b) ↔ (¬a ↔ b) := open scoped Classical in Decidable.not_iff
306312

307-
theorem iff_not_comm : (a ↔ ¬b) ↔ (b ↔ ¬a) := Decidable.iff_not_comm
313+
theorem iff_not_comm : (a ↔ ¬b) ↔ (b ↔ ¬a) := open scoped Classical in Decidable.iff_not_comm
308314

309315
theorem iff_iff_and_or_not_and_not : (a ↔ b) ↔ a ∧ b ∨ ¬a ∧ ¬b :=
310-
Decidable.iff_iff_and_or_not_and_not
316+
open scoped Classical in Decidable.iff_iff_and_or_not_and_not
311317

312318
theorem iff_iff_not_or_and_or_not : (a ↔ b) ↔ (¬a ∨ b) ∧ (a ∨ ¬b) :=
313-
Decidable.iff_iff_not_or_and_or_not
319+
open scoped Classical in Decidable.iff_iff_not_or_and_or_not
314320

315-
theorem not_and_not_right : ¬(a ∧ ¬b) ↔ a → b := Decidable.not_and_not_right
321+
theorem not_and_not_right : ¬(a ∧ ¬b) ↔ a → b :=
322+
open scoped Classical in Decidable.not_and_not_right
316323

317324
/-! ### De Morgan's laws -/
318325

319326
/-- One of **de Morgan's laws**: the negation of a conjunction is logically equivalent to the
320327
disjunction of the negations. -/
321-
theorem not_and_or : ¬(a ∧ b) ↔ ¬a ∨ ¬b := Decidable.not_and_iff_not_or_not
328+
theorem not_and_or : ¬(a ∧ b) ↔ ¬a ∨ ¬b := open scoped Classical in Decidable.not_and_iff_not_or_not
322329

323-
theorem or_iff_not_and_not : a ∨ b ↔ ¬(¬a ∧ ¬b) := Decidable.or_iff_not_not_and_not
330+
theorem or_iff_not_and_not : a ∨ b ↔ ¬(¬a ∧ ¬b) :=
331+
open scoped Classical in Decidable.or_iff_not_not_and_not
324332

325-
theorem and_iff_not_or_not : a ∧ b ↔ ¬(¬a ∨ ¬b) := Decidable.and_iff_not_not_or_not
333+
theorem and_iff_not_or_not : a ∧ b ↔ ¬(¬a ∨ ¬b) :=
334+
open scoped Classical in Decidable.and_iff_not_not_or_not
326335

327336
@[simp] theorem not_xor (P Q : Prop) : ¬Xor' P Q ↔ (P ↔ Q) := by
328337
simp only [not_and, Xor', not_or, not_not, ← iff_iff_implies_and_implies]
@@ -495,7 +504,8 @@ theorem exists_and_exists_comm {P : α → Prop} {Q : β → Prop} :
495504

496505
export Classical (not_forall)
497506

498-
theorem not_forall_not : (¬∀ x, ¬p x) ↔ ∃ x, p x := Decidable.not_forall_not
507+
theorem not_forall_not : (¬∀ x, ¬p x) ↔ ∃ x, p x :=
508+
open scoped Classical in Decidable.not_forall_not
499509

500510
export Classical (not_exists_not)
501511

@@ -507,6 +517,7 @@ lemma exists_or_forall_not (P : α → Prop) : (∃ a, P a) ∨ ∀ a, ¬ P a :=
507517

508518
theorem forall_imp_iff_exists_imp {α : Sort*} {p : α → Prop} {b : Prop} [ha : Nonempty α] :
509519
(∀ x, p x) → b ↔ ∃ x, p x → b := by
520+
classical
510521
let ⟨a⟩ := ha
511522
refine ⟨fun h ↦ not_forall_not.1 fun h' ↦ ?_, fun ⟨x, hx⟩ h ↦ hx (h x)⟩
512523
exact if hb : b then h' a fun _ ↦ hb else hb <| h fun x ↦ (_root_.not_imp.1 (h' x)).1
@@ -531,7 +542,7 @@ theorem Decidable.and_forall_ne [DecidableEq α] (a : α) {p : α → Prop} :
531542
simp only [← @forall_eq _ p a, ← forall_and, ← or_imp, Decidable.em, forall_const]
532543

533544
theorem and_forall_ne (a : α) : (p a ∧ ∀ b, b ≠ a → p b) ↔ ∀ b, p b :=
534-
Decidable.and_forall_ne a
545+
open scoped Classical in Decidable.and_forall_ne a
535546

536547
theorem Ne.ne_or_ne {x y : α} (z : α) (h : x ≠ y) : x ≠ z ∨ y ≠ z :=
537548
not_and_or.1 <| mt (and_imp.2 (· ▸ ·)) h.symm
@@ -610,14 +621,14 @@ protected theorem Decidable.forall_or_left {q : Prop} {p : α → Prop} [Decidab
610621
Or.inr fun x ↦ (h x).resolve_left hq, forall_or_of_or_forall⟩
611622

612623
theorem forall_or_left {q} {p : α → Prop} : (∀ x, q ∨ p x) ↔ q ∨ ∀ x, p x :=
613-
Decidable.forall_or_left
624+
open scoped Classical in Decidable.forall_or_left
614625

615626
-- See Note [decidable namespace]
616627
protected theorem Decidable.forall_or_right {q} {p : α → Prop} [Decidable q] :
617628
(∀ x, p x ∨ q) ↔ (∀ x, p x) ∨ q := by simp [or_comm, Decidable.forall_or_left]
618629

619630
theorem forall_or_right {q} {p : α → Prop} : (∀ x, p x ∨ q) ↔ (∀ x, p x) ∨ q :=
620-
Decidable.forall_or_right
631+
open scoped Classical in Decidable.forall_or_right
621632

622633
theorem Exists.fst {b : Prop} {p : b → Prop} : Exists p → b
623634
| ⟨h, _⟩ => h
@@ -775,7 +786,8 @@ protected theorem Decidable.not_forall₂ [Decidable (∃ x h, ¬P x h)] [∀ x
775786
⟨Not.decidable_imp_symm fun nx x h ↦ nx.decidable_imp_symm
776787
fun h' ↦ ⟨x, h, h'⟩, not_forall₂_of_exists₂_not⟩
777788

778-
theorem not_forall₂ : (¬∀ x h, P x h) ↔ ∃ x h, ¬P x h := Decidable.not_forall₂
789+
theorem not_forall₂ : (¬∀ x h, P x h) ↔ ∃ x h, ¬P x h :=
790+
open scoped Classical in Decidable.not_forall₂
779791

780792
theorem forall₂_and : (∀ x h, P x h ∧ Q x h) ↔ (∀ x h, P x h) ∧ ∀ x h, Q x h :=
781793
Iff.trans (forall_congr' fun _ ↦ forall_and) forall_and
@@ -948,9 +960,9 @@ end ite
948960
theorem not_beq_of_ne {α : Type*} [BEq α] [LawfulBEq α] {a b : α} (ne : a ≠ b) : ¬(a == b) :=
949961
fun h => ne (eq_of_beq h)
950962

951-
theorem beq_eq_decide {α : Type*} [BEq α] [LawfulBEq α] {a b : α} : (a == b) = decide (a = b) := by
952-
rw [← beq_iff_eq (a := a) (b := b)]
953-
cases a == b <;> simp
963+
theorem beq_eq_decide {α : Type*} [BEq α] [LawfulBEq α] {a b : α} [Decidable (a = b)] :
964+
(a == b) = decide (a = b) := by
965+
by_cases a = b <;> simp_all [beq_iff_eq]
954966

955967
@[simp] lemma beq_eq_beq {α β : Type*} [BEq α] [LawfulBEq α] [BEq β] [LawfulBEq β] {a₁ a₂ : α}
956968
{b₁ b₂ : β} : (a₁ == a₂) = (b₁ == b₂) ↔ (a₁ = a₂ ↔ b₁ = b₂) := by rw [Bool.eq_iff_iff]; simp
@@ -970,4 +982,5 @@ theorem lawful_beq_subsingleton {α : Type*} (inst1 : BEq α) (inst2 : BEq α)
970982
inst1 = inst2 := by
971983
apply beq_ext
972984
intro x y
985+
classical
973986
simp only [beq_eq_decide]

0 commit comments

Comments
 (0)