Skip to content

Commit ed0d70f

Browse files
chore: remove redundant open scoped Classical (#41423)
This PR removes all redundant/unused `open scoped Classical in`. Furthermore, if the `open scoped Classical` is only needed for the proof of a declaration, it moves it there (and convert it to `classical` when in tactic mode). Excludes MathlibTest. This was done with a script bruteforcing everything, made by Claude code. Only thing remaining would be to check if all `classical` are really needed, but there are quite a lot of them (>3k). Co-authored-by: Batixx <s59fpern@uni-bonn.de>
1 parent 27c42f4 commit ed0d70f

24 files changed

Lines changed: 55 additions & 87 deletions

File tree

Archive/Imo/Imo1998Q2.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def A : Finset (AgreedTriple C J) :=
9898
Finset.univ.filter @fun (a : AgreedTriple C J) =>
9999
(a.judgePair.Agree r a.contestant ∧ a.judgePair.Distinct)
100100

101-
open scoped Classical in
102101
theorem A_maps_to_offDiag_judgePair (a : AgreedTriple C J) :
103102
a ∈ A r → a.judgePair ∈ Finset.offDiag (@Finset.univ J _) := by simp [A, Finset.mem_offDiag]
104103

Mathlib/Analysis/Normed/Lp/ProdLp.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ section EDist
162162

163163
variable [EDist α] [EDist β]
164164

165-
open scoped Classical in
166165
/-- Endowing the space `WithLp p (α × β)` with the `L^p` edistance. We register this instance
167166
separate from `WithLp.instProdPseudoEMetric` since the latter requires the type class hypothesis
168167
`[Fact (1 ≤ p)]` in order to prove the triangle inequality.
@@ -231,7 +230,6 @@ section Dist
231230

232231
variable [Dist α] [Dist β]
233232

234-
open scoped Classical in
235233
/-- Endowing the space `WithLp p (α × β)` with the `L^p` distance. We register this instance
236234
separate from `WithLp.instProdPseudoMetricSpace` since the latter requires the type class hypothesis
237235
`[Fact (1 ≤ p)]` in order to prove the triangle inequality.
@@ -268,7 +266,6 @@ section Norm
268266

269267
variable [Norm α] [Norm β]
270268

271-
open scoped Classical in
272269
/-- Endowing the space `WithLp p (α × β)` with the `L^p` norm. We register this instance
273270
separate from `WithLp.instProdSeminormedAddCommGroup` since the latter requires the type class
274271
hypothesis `[Fact (1 ≤ p)]` in order to prove the triangle inequality.

Mathlib/Combinatorics/Extremal/RuzsaSzemeredi.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ noncomputable def ruzsaSzemerediNumber : ℕ := by
5252
exact Nat.findGreatest (fun m ↦ ∃ (G : SimpleGraph α) (_ : DecidableRel G.Adj),
5353
#(G.cliqueFinset 3) = m ∧ G.LocallyLinear) ((card α).choose 3)
5454

55-
open scoped Classical in
56-
lemma ruzsaSzemerediNumber_le : ruzsaSzemerediNumber α ≤ (card α).choose 3 := Nat.findGreatest_le _
55+
lemma ruzsaSzemerediNumber_le : ruzsaSzemerediNumber α ≤ (card α).choose 3 := by
56+
classical
57+
exact Nat.findGreatest_le _
5758

5859
lemma ruzsaSzemerediNumber_spec :
5960
∃ (G : SimpleGraph α) (_ : DecidableRel G.Adj),

Mathlib/Combinatorics/SimpleGraph/Clique.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,9 @@ lemma CliqueFree.mem_of_sup_edge_isNClique {x y : α} {t : Finset α} {n : ℕ}
549549
open scoped Classical in
550550
/-- Adding an edge increases the clique number by at most one. -/
551551
protected theorem CliqueFree.sup_edge (h : G.CliqueFree n) (v w : α) :
552-
(G ⊔ edge v w).CliqueFree (n + 1) :=
553-
fun _ hs ↦ (hs.erase_of_sup_edge_of_mem <|
552+
(G ⊔ edge v w).CliqueFree (n + 1) := by
553+
classical
554+
exact fun _ hs ↦ (hs.erase_of_sup_edge_of_mem <|
554555
(h.mono n.le_succ).mem_of_sup_edge_isNClique hs).not_cliqueFree h
555556

556557
lemma IsNClique.exists_not_adj_of_cliqueFree_succ (hc : G.IsNClique n s)

Mathlib/FieldTheory/Perfect.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ noncomputable def rootsExpandToRoots : (expand R p f).roots.toFinset ↪ f.roots
455455
@[simp]
456456
theorem rootsExpandToRoots_apply (x) : (rootsExpandToRoots p f x : R) = x ^ p := rfl
457457

458-
open scoped Classical in
459458
/-- If `f` is a polynomial over an integral domain `R` of characteristic `p`, then there is
460459
a map from the set of roots of `Polynomial.expand R (p ^ n) f` to the set of roots of `f`.
461460
It's given by `x ↦ x ^ (p ^ n)`, see `rootsExpandPowToRoots_apply`. -/

Mathlib/FieldTheory/PurelyInseparable/Exponent.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ open scoped Classical in
118118
variable {K} in
119119
theorem elemExponent_eq_zero_of_mem_range {a : L} (h : a ∈ (algebraMap K L).range) :
120120
elemExponent K a = 0 := by
121+
classical
121122
apply (Nat.find_eq_zero _).mpr
122123
rw [pow_zero, pow_one]
123124
obtain ⟨y, hy⟩ := h

Mathlib/Geometry/Manifold/ChartedSpace.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ def ChartedSpace.sum_of_nonempty [Nonempty H] : ChartedSpace H (M ⊕ M') where
523523
right
524524
use ChartedSpace.chartAt x, cm'.chart_mem_atlas x
525525

526-
open scoped Classical in
527526
instance ChartedSpace.sum : ChartedSpace H (M ⊕ M') := by
528527
by_cases! h : Nonempty H
529528
· exact ChartedSpace.sum_of_nonempty

Mathlib/GroupTheory/Coxeter/Length.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ theorem exists_isReduced (w : W) : ∃ ω : List B, cs.IsReduced ω ∧ w = π
9090
@[deprecated (since := "2026-03-25")] alias exists_reduced_word := exists_isReduced
9191
@[deprecated (since := "2026-03-25")] alias exists_reduced_word' := exists_isReduced
9292

93-
open scoped Classical in
94-
theorem length_wordProd_le (ω : List B) : ℓ (π ω) ≤ ω.length :=
95-
Nat.find_min' (cs.exists_word_with_prod (π ω)) ⟨ω, rfl, rfl⟩
93+
theorem length_wordProd_le (ω : List B) : ℓ (π ω) ≤ ω.length := by
94+
classical
95+
exact Nat.find_min' (cs.exists_word_with_prod (π ω)) ⟨ω, rfl, rfl⟩
9696

9797
@[simp] theorem length_one : ℓ (1 : W) = 0 := Nat.eq_zero_of_le_zero (cs.length_wordProd_le [])
9898

Mathlib/GroupTheory/FreeAbelianGroup.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ end lift
146146

147147
section
148148

149-
open scoped Classical in
150-
theorem of_injective : Function.Injective (of : α → FreeAbelianGroup α) :=
151-
fun x y hoxy ↦ Classical.by_contradiction fun hxy : x ≠ y ↦
149+
theorem of_injective : Function.Injective (of : α → FreeAbelianGroup α) := by
150+
classical
151+
exact fun x y hoxy ↦ Classical.by_contradiction fun hxy : x ≠ y ↦
152152
let f : FreeAbelianGroup α →+ ℤ := lift fun z ↦ if x = z then (1 : ℤ) else 0
153153
have hfx1 : f (of x) = 1 := (lift_apply_of _ _).trans <| if_pos rfl
154154
have hfy1 : f (of y) = 1 := hoxy ▸ hfx1

Mathlib/GroupTheory/Perm/ViaEmbedding.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ open scoped Classical in
2929
noncomputable def viaEmbedding : Perm β :=
3030
extendDomain e (ofInjective ι.1 ι.2)
3131

32-
open scoped Classical in
33-
theorem viaEmbedding_apply (x : α) : e.viaEmbedding ι (ι x) = ι (e x) :=
34-
extendDomain_apply_image e (ofInjective ι.1 ι.2) x
32+
theorem viaEmbedding_apply (x : α) : e.viaEmbedding ι (ι x) = ι (e x) := by
33+
classical
34+
exact extendDomain_apply_image e (ofInjective ι.1 ι.2) x
3535

36-
open scoped Classical in
37-
theorem viaEmbedding_apply_of_notMem (x : β) (hx : x ∉ Set.range ι) : e.viaEmbedding ι x = x :=
38-
extendDomain_apply_not_subtype e (ofInjective ι.1 ι.2) hx
36+
theorem viaEmbedding_apply_of_notMem (x : β) (hx : x ∉ Set.range ι) : e.viaEmbedding ι x = x := by
37+
classical
38+
exact extendDomain_apply_not_subtype e (ofInjective ι.1 ι.2) hx
3939

4040
open scoped Classical in
4141
/-- `viaEmbedding` as a group homomorphism -/
@@ -45,9 +45,9 @@ noncomputable def viaEmbeddingHom : Perm α →* Perm β :=
4545
theorem viaEmbeddingHom_apply : viaEmbeddingHom ι e = viaEmbedding e ι :=
4646
rfl
4747

48-
open scoped Classical in
49-
theorem viaEmbeddingHom_injective : Function.Injective (viaEmbeddingHom ι) :=
50-
extendDomainHom_injective (ofInjective ι.1 ι.2)
48+
theorem viaEmbeddingHom_injective : Function.Injective (viaEmbeddingHom ι) := by
49+
classical
50+
exact extendDomainHom_injective (ofInjective ι.1 ι.2)
5151

5252
end Perm
5353

0 commit comments

Comments
 (0)