Skip to content

Commit efe2ab4

Browse files
authored
chore: remove duplicate instances (#8397)
This PR cleans up many duplicate instances (or, in some cases, needlessly duplicated `def X := ...; instance Y := X`).
1 parent 831026b commit efe2ab4

File tree

23 files changed

+40
-101
lines changed

23 files changed

+40
-101
lines changed

src/Init/Classical.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ noncomputable def epsilon {α : Sort u} [h : Nonempty α] (p : α → Prop) : α
107107
theorem epsilon_spec_aux {α : Sort u} (h : Nonempty α) (p : α → Prop) : (∃ y, p y) → p (@epsilon α h p) :=
108108
(strongIndefiniteDescription p h).property
109109

110-
theorem epsilon_spec {α : Sort u} {p : α → Prop} (hex : ∃ y, p y) : p (@epsilon α (nonempty_of_exists hex) p) :=
111-
epsilon_spec_aux (nonempty_of_exists hex) p hex
110+
theorem epsilon_spec {α : Sort u} {p : α → Prop} (hex : ∃ y, p y) : p (@epsilon α hex.nonempty p) :=
111+
epsilon_spec_aux hex.nonempty p hex
112112

113113
theorem epsilon_singleton {α : Sort u} (x : α) : @epsilon α ⟨x⟩ (fun y => y = x) = x :=
114114
@epsilon_spec α (fun y => y = x) ⟨x, rfl⟩

src/Init/Core.lean

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,10 +1212,7 @@ abbrev noConfusionEnum {α : Sort u} {β : Sort v} [inst : DecidableEq β] (f :
12121212
instance : Inhabited Prop where
12131213
default := True
12141214

1215-
deriving instance Inhabited for NonScalar, PNonScalar, True, ForInStep
1216-
1217-
theorem nonempty_of_exists {α : Sort u} {p : α → Prop} : Exists (fun x => p x) → Nonempty α
1218-
| ⟨w, _⟩ => ⟨w⟩
1215+
deriving instance Inhabited for NonScalar, PNonScalar, True
12191216

12201217
/-! # Subsingleton -/
12211218

@@ -1389,16 +1386,7 @@ instance Sum.nonemptyLeft [h : Nonempty α] : Nonempty (Sum α β) :=
13891386
instance Sum.nonemptyRight [h : Nonempty β] : Nonempty (Sum α β) :=
13901387
Nonempty.elim h (fun b => ⟨Sum.inr b⟩)
13911388

1392-
instance {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] : DecidableEq (Sum α β) := fun a b =>
1393-
match a, b with
1394-
| Sum.inl a, Sum.inl b =>
1395-
if h : a = b then isTrue (h ▸ rfl)
1396-
else isFalse fun h' => Sum.noConfusion h' fun h' => absurd h' h
1397-
| Sum.inr a, Sum.inr b =>
1398-
if h : a = b then isTrue (h ▸ rfl)
1399-
else isFalse fun h' => Sum.noConfusion h' fun h' => absurd h' h
1400-
| Sum.inr _, Sum.inl _ => isFalse fun h => Sum.noConfusion h
1401-
| Sum.inl _, Sum.inr _ => isFalse fun h => Sum.noConfusion h
1389+
deriving instance DecidableEq for Sum
14021390

14031391
end
14041392

src/Init/Data/Float.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ This function does not reduce in the kernel. It is compiled to the C inequality
161161
match a, b with
162162
| ⟨a⟩, ⟨b⟩ => floatSpec.decLe a b
163163

164-
instance floatDecLt (a b : Float) : Decidable (a < b) := Float.decLt a b
165-
instance floatDecLe (a b : Float) : Decidable (a ≤ b) := Float.decLe a b
164+
attribute [instance] Float.decLt Float.decLe
166165

167166
/--
168167
Converts a floating-point number to a string.

src/Init/Data/Float32.lean

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Compares two floating point numbers for strict inequality.
145145
146146
This function does not reduce in the kernel. It is compiled to the C inequality operator.
147147
-/
148-
@[extern "lean_float32_decLt"] opaque Float32.decLt (a b : Float32) : Decidable (a < b) :=
148+
@[extern "lean_float32_decLt", instance] opaque Float32.decLt (a b : Float32) : Decidable (a < b) :=
149149
match a, b with
150150
| ⟨a⟩, ⟨b⟩ => float32Spec.decLt a b
151151

@@ -154,13 +154,10 @@ Compares two floating point numbers for non-strict inequality.
154154
155155
This function does not reduce in the kernel. It is compiled to the C inequality operator.
156156
-/
157-
@[extern "lean_float32_decLe"] opaque Float32.decLe (a b : Float32) : Decidable (a ≤ b) :=
157+
@[extern "lean_float32_decLe", instance] opaque Float32.decLe (a b : Float32) : Decidable (a ≤ b) :=
158158
match a, b with
159159
| ⟨a⟩, ⟨b⟩ => float32Spec.decLe a b
160160

161-
instance float32DecLt (a b : Float32) : Decidable (a < b) := Float32.decLt a b
162-
instance float32DecLe (a b : Float32) : Decidable (a ≤ b) := Float32.decLe a b
163-
164161
/--
165162
Converts a floating-point number to a string.
166163

src/Init/Data/Hashable.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ instance : Hashable UInt64 where
5757
instance : Hashable USize where
5858
hash n := n.toUInt64
5959

60-
instance : Hashable ByteArray where
61-
hash as := as.foldl (fun r a => mixHash r (hash a)) 7
62-
6360
instance : Hashable (Fin n) where
6461
hash v := v.val.toUInt64
6562

src/Init/Data/Int/LemmasAux.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ theorem toNat_lt_toNat {n m : Int} (hn : 0 < m) : n.toNat < m.toNat ↔ n < m :=
121121
/-! ### min and max -/
122122

123123
@[simp] protected theorem min_assoc : ∀ (a b c : Int), min (min a b) c = min a (min b c) := by omega
124-
instance : Std.Associative (α := Nat) min := ⟨Nat.min_assoc⟩
124+
instance : Std.Associative (α := Int) min := ⟨Int.min_assoc⟩
125125

126126
@[simp] protected theorem min_self_assoc {m n : Int} : min m (min m n) = min m n := by
127127
rw [← Int.min_assoc, Int.min_self]
@@ -130,7 +130,7 @@ instance : Std.Associative (α := Nat) min := ⟨Nat.min_assoc⟩
130130
rw [Int.min_comm m n, ← Int.min_assoc, Int.min_self]
131131

132132
@[simp] protected theorem max_assoc (a b c : Int) : max (max a b) c = max a (max b c) := by omega
133-
instance : Std.Associative (α := Nat) max := ⟨Nat.max_assoc⟩
133+
instance : Std.Associative (α := Int) max := ⟨Int.max_assoc⟩
134134

135135
@[simp] protected theorem max_self_assoc {m n : Int} : max m (max m n) = max m n := by
136136
rw [← Int.max_assoc, Int.max_self]

src/Init/Data/Ord.lean

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -849,13 +849,4 @@ comparisons.
849849
protected def lex' (ord₁ ord₂ : Ord α) : Ord α where
850850
compare := compareLex ord₁.compare ord₂.compare
851851

852-
/--
853-
Constructs an order which compares elements of an `Array` in lexicographic order.
854-
-/
855-
protected def arrayOrd [a : Ord α] : Ord (Array α) where
856-
compare x y :=
857-
let _ : LT α := a.toLT
858-
let _ : BEq α := a.toBEq
859-
if List.lex x.toList y.toList then .lt else if x == y then .eq else .gt
860-
861852
end Ord

src/Init/Data/SInt/Basic.lean

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ Examples:
429429
def Int8.decLe (a b : Int8) : Decidable (a ≤ b) :=
430430
inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
431431

432-
instance (a b : Int8) : Decidable (a < b) := Int8.decLt a b
433-
instance (a b : Int8) : Decidable (a ≤ b) := Int8.decLe a b
432+
attribute [instance] Int8.decLt Int8.decLe
433+
434434
instance : Max Int8 := maxOfLe
435435
instance : Min Int8 := minOfLe
436436

@@ -800,8 +800,8 @@ Examples:
800800
def Int16.decLe (a b : Int16) : Decidable (a ≤ b) :=
801801
inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
802802

803-
instance (a b : Int16) : Decidable (a < b) := Int16.decLt a b
804-
instance (a b : Int16) : Decidable (a ≤ b) := Int16.decLe a b
803+
attribute [instance] Int16.decLt Int16.decLe
804+
805805
instance : Max Int16 := maxOfLe
806806
instance : Min Int16 := minOfLe
807807

@@ -1187,8 +1187,8 @@ Examples:
11871187
def Int32.decLe (a b : Int32) : Decidable (a ≤ b) :=
11881188
inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
11891189

1190-
instance (a b : Int32) : Decidable (a < b) := Int32.decLt a b
1191-
instance (a b : Int32) : Decidable (a ≤ b) := Int32.decLe a b
1190+
attribute [instance] Int32.decLt Int32.decLe
1191+
11921192
instance : Max Int32 := maxOfLe
11931193
instance : Min Int32 := minOfLe
11941194

@@ -1593,8 +1593,8 @@ Examples:
15931593
def Int64.decLe (a b : Int64) : Decidable (a ≤ b) :=
15941594
inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
15951595

1596-
instance (a b : Int64) : Decidable (a < b) := Int64.decLt a b
1597-
instance (a b : Int64) : Decidable (a ≤ b) := Int64.decLe a b
1596+
attribute [instance] Int64.decLt Int64.decLe
1597+
15981598
instance : Max Int64 := maxOfLe
15991599
instance : Min Int64 := minOfLe
16001600

@@ -1986,7 +1986,7 @@ Examples:
19861986
def ISize.decLe (a b : ISize) : Decidable (a ≤ b) :=
19871987
inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
19881988

1989-
instance (a b : ISize) : Decidable (a < b) := ISize.decLt a b
1990-
instance (a b : ISize) : Decidable (a ≤ b) := ISize.decLe a b
1989+
attribute [instance] ISize.decLt ISize.decLe
1990+
19911991
instance : Max ISize := maxOfLe
19921992
instance : Min ISize := minOfLe

src/Init/Data/String/Lemmas.lean

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,4 @@ protected theorem ne_of_lt {a b : String} (h : a < b) : a ≠ b := by
3232
have := String.lt_irrefl a
3333
intro h; subst h; contradiction
3434

35-
instance ltIrrefl : Std.Irrefl (· < · : Char → Char → Prop) where
36-
irrefl := Char.lt_irrefl
37-
38-
instance leRefl : Std.Refl (· ≤ · : Char → Char → Prop) where
39-
refl := Char.le_refl
40-
41-
instance leTrans : Trans (· ≤ · : Char → Char → Prop) (· ≤ ·) (· ≤ ·) where
42-
trans := Char.le_trans
43-
44-
instance leAntisymm : Std.Antisymm (· ≤ · : Char → Char → Prop) where
45-
antisymm _ _ := Char.le_antisymm
46-
47-
instance ltAsymm : Std.Asymm (· < · : Char → Char → Prop) where
48-
asymm _ _ := Char.lt_asymm
49-
50-
instance leTotal : Std.Total (· ≤ · : Char → Char → Prop) where
51-
total := Char.le_total
52-
5335
end String

src/Init/Data/Sum/Basic.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ universe signature in consequence. The `Prop` version is `Or`.
4444

4545
namespace Sum
4646

47-
deriving instance DecidableEq for Sum
4847
deriving instance BEq for Sum
4948

5049
section get

0 commit comments

Comments
 (0)