Skip to content

Commit 73f6b10

Browse files
committed
chore: deprecate more duplications
1 parent 19533ab commit 73f6b10

File tree

15 files changed

+66
-47
lines changed

15 files changed

+66
-47
lines changed

src/Init/ByCases.lean

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,10 @@ theorem apply_ite (f : α → β) (P : Prop) [Decidable P] (x y : α) :
4444
/-- A `dite` whose results do not actually depend on the condition may be reduced to an `ite`. -/
4545
@[simp] theorem dite_eq_ite [Decidable P] :
4646
(dite P (fun _ => a) (fun _ => b)) = ite P a b := rfl
47+
48+
-- Remark: dite and ite are "defally equal" when we ignore the proofs.
49+
@[deprecated dite_eq_ite (since := "2025-10-29")]
50+
theorem dif_eq_if (c : Prop) {h : Decidable c} {α : Sort u} (t : α) (e : α) : dite c (fun _ => t) (fun _ => e) = ite c t e :=
51+
match h with
52+
| isTrue _ => rfl
53+
| isFalse _ => rfl

src/Init/Core.lean

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,12 +1196,6 @@ theorem dif_neg {c : Prop} {h : Decidable c} (hnc : ¬c) {α : Sort u} {t : c
11961196
| isTrue hc => absurd hc hnc
11971197
| isFalse _ => rfl
11981198

1199-
-- Remark: dite and ite are "defally equal" when we ignore the proofs.
1200-
theorem dif_eq_if (c : Prop) {h : Decidable c} {α : Sort u} (t : α) (e : α) : dite c (fun _ => t) (fun _ => e) = ite c t e :=
1201-
match h with
1202-
| isTrue _ => rfl
1203-
| isFalse _ => rfl
1204-
12051199
@[macro_inline]
12061200
instance {c t e : Prop} [dC : Decidable c] [dT : Decidable t] [dE : Decidable e] : Decidable (if c then t else e) :=
12071201
match dC with

src/Init/Data/Array/Lemmas.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,8 +2238,6 @@ theorem flatMap_def {xs : Array α} {f : α → Array β} : xs.flatMap f = flatt
22382238
rcases xs with ⟨l⟩
22392239
simp [flatten_toArray, Function.comp_def, List.flatMap_def]
22402240

2241-
@[simp, grind =] theorem flatMap_empty {β} {f : α → Array β} : (#[] : Array α).flatMap f = #[] := rfl
2242-
22432241
theorem flatMap_toList {xs : Array α} {f : α → List β} :
22442242
xs.toList.flatMap f = (xs.flatMap (fun a => (f a).toArray)).toList := by
22452243
rcases xs with ⟨l⟩
@@ -2250,6 +2248,7 @@ theorem flatMap_toList {xs : Array α} {f : α → List β} :
22502248
rcases xs with ⟨l⟩
22512249
simp
22522250

2251+
@[deprecated List.flatMap_toArray_cons (since := "2025-10-29")]
22532252
theorem flatMap_toArray_cons {β} {f : α → Array β} {a : α} {as : List α} :
22542253
(a :: as).toArray.flatMap f = f a ++ as.toArray.flatMap f := by
22552254
simp [flatMap]
@@ -2260,6 +2259,7 @@ theorem flatMap_toArray_cons {β} {f : α → Array β} {a : α} {as : List α}
22602259
intro cs
22612260
induction as generalizing cs <;> simp_all
22622261

2262+
@[deprecated List.flatMap_toArray (since := "2025-10-29")]
22632263
theorem flatMap_toArray {β} {f : α → Array β} {as : List α} :
22642264
as.toArray.flatMap f = (as.flatMap (fun a => (f a).toList)).toArray := by
22652265
simp

src/Init/Data/BitVec/Lemmas.lean

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ theorem getElem?_eq_none_iff {l : BitVec w} : l[n]? = none ↔ w ≤ n := by
6464
theorem none_eq_getElem?_iff {l : BitVec w} : none = l[n]? ↔ w ≤ n := by
6565
simp
6666

67+
@[simp]
6768
theorem getElem?_eq_none {l : BitVec w} (h : w ≤ n) : l[n]? = none := getElem?_eq_none_iff.mpr h
6869

6970
theorem getElem?_eq (l : BitVec w) (i : Nat) :
@@ -161,7 +162,8 @@ theorem getLsbD_eq_getMsbD (x : BitVec w) (i : Nat) : x.getLsbD i = (decide (i <
161162
apply getLsbD_of_ge
162163
omega
163164

164-
@[simp] theorem getElem?_of_ge (x : BitVec w) (i : Nat) (ge : w ≤ i) : x[i]? = none := by
165+
@[deprecated getElem?_eq_none (since := "2025-10-29")]
166+
theorem getElem?_of_ge (x : BitVec w) (i : Nat) (ge : w ≤ i) : x[i]? = none := by
165167
simp [ge]
166168

167169
@[simp] theorem getMsb?_of_ge (x : BitVec w) (i : Nat) (ge : w ≤ i) : getMsb? x i = none := by
@@ -421,9 +423,15 @@ theorem getElem?_zero_ofBool (b : Bool) : (ofBool b)[0]? = some b := by
421423
simp only [ofBool, ofNat_eq_ofNat, cond_eq_if]
422424
split <;> simp_all
423425

424-
@[simp, grind =] theorem getElem_zero_ofBool (b : Bool) : (ofBool b)[0] = b := by
426+
@[simp, grind =]
427+
theorem getElem_ofBool_zero {b : Bool} : (ofBool b)[0] = b := by
425428
rw [getElem_eq_iff, getElem?_zero_ofBool]
426429

430+
431+
@[deprecated getElem_ofBool_zero (since := "2025-10-29")]
432+
theorem getElem_zero_ofBool (b : Bool) : (ofBool b)[0] = b := by
433+
simp
434+
427435
theorem getElem?_succ_ofBool (b : Bool) (i : Nat) : (ofBool b)[i + 1]? = none := by
428436
simp
429437

@@ -434,8 +442,6 @@ theorem getLsbD_ofBool (b : Bool) (i : Nat) : (ofBool b).getLsbD i = ((i = 0) &&
434442
· simp only [ofBool, ofNat_eq_ofNat, cond_true, getLsbD_ofNat, Bool.and_true]
435443
by_cases hi : i = 0 <;> simp [hi] <;> omega
436444

437-
theorem getElem_ofBool_zero {b : Bool} : (ofBool b)[0] = b := by simp
438-
439445
@[simp]
440446
theorem getElem_ofBool {b : Bool} {h : i < 1}: (ofBool b)[i] = b := by
441447
simp [← getLsbD_eq_getElem]
@@ -987,7 +993,14 @@ theorem msb_setWidth' (x : BitVec w) (h : w ≤ v) : (x.setWidth' h).msb = (deci
987993
theorem msb_setWidth'' (x : BitVec w) : (x.setWidth (k + 1)).msb = x.getLsbD k := by
988994
simp [BitVec.msb, getMsbD]
989995

996+
/-- Truncating to width 1 produces a bitvector equal to the least significant bit. -/
997+
theorem setWidth_one {x : BitVec w} :
998+
x.setWidth 1 = ofBool (x.getLsbD 0) := by
999+
ext i
1000+
simp [show i = 0 by omega]
1001+
9901002
/-- zero extending a bitvector to width 1 equals the boolean of the lsb. -/
1003+
@[deprecated setWidth_one (since := "2025-10-29")]
9911004
theorem setWidth_one_eq_ofBool_getLsb_zero (x : BitVec w) :
9921005
x.setWidth 1 = BitVec.ofBool (x.getLsbD 0) := by
9931006
ext i h
@@ -1003,12 +1016,6 @@ theorem setWidth_ofNat_one_eq_ofNat_one_of_lt {v w : Nat} (hv : 0 < v) :
10031016
have hv := (@Nat.testBit_one_eq_true_iff_self_eq_zero i)
10041017
by_cases h : Nat.testBit 1 i = true <;> simp_all
10051018

1006-
/-- Truncating to width 1 produces a bitvector equal to the least significant bit. -/
1007-
theorem setWidth_one {x : BitVec w} :
1008-
x.setWidth 1 = ofBool (x.getLsbD 0) := by
1009-
ext i
1010-
simp [show i = 0 by omega]
1011-
10121019
@[simp, grind =] theorem setWidth_ofNat_of_le (h : v ≤ w) (x : Nat) : setWidth v (BitVec.ofNat w x) = BitVec.ofNat v x := by
10131020
apply BitVec.eq_of_toNat_eq
10141021
simp only [toNat_setWidth, toNat_ofNat]

src/Init/Data/Bool.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ theorem exists_bool {p : Bool → Prop} : (∃ b, p b) ↔ p false ∨ p true :=
514514
theorem cond_eq_ite {α} (b : Bool) (t e : α) : cond b t e = if b then t else e := by
515515
cases b <;> simp
516516

517+
@[deprecated cond_eq_ite (since := "2025-10-29")]
517518
theorem cond_eq_if : (bif b then x else y) = (if b then x else y) := cond_eq_ite b x y
518519

519520
@[simp] theorem cond_not (b : Bool) (t e : α) : cond (!b) t e = cond b e t := by

src/Init/Data/Fin/Lemmas.lean

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,15 +585,20 @@ theorem castSucc_pos [NeZero n] {i : Fin n} (h : 0 < i) : 0 < i.castSucc := by
585585
theorem castSucc_ne_zero_iff [NeZero n] {a : Fin n} : a.castSucc ≠ 0 ↔ a ≠ 0 :=
586586
not_congr <| castSucc_eq_zero_iff
587587

588+
@[simp, grind _=_]
589+
theorem castSucc_succ (i : Fin n) : i.succ.castSucc = i.castSucc.succ := rfl
590+
591+
@[deprecated castSucc_succ (since := "2025-10-29")]
588592
theorem castSucc_fin_succ (n : Nat) (j : Fin n) :
589-
j.succ.castSucc = (j.castSucc).succ := by simp [Fin.ext_iff]
593+
j.succ.castSucc = (j.castSucc).succ := by simp
590594

591595
@[simp]
592596
theorem coeSucc_eq_succ {a : Fin n} : a.castSucc + 1 = a.succ := by
593597
cases n
594598
· exact a.elim0
595599
· simp [Fin.ext_iff, add_def, Nat.mod_eq_of_lt (Nat.succ_lt_succ a.is_lt)]
596600

601+
@[deprecated castSucc_lt_succ (since := "2025-10-29")]
597602
theorem lt_succ {a : Fin n} : a.castSucc < a.succ := by
598603
rw [castSucc, lt_def, coe_castAdd, val_succ]; exact Nat.lt_succ_self a.val
599604

@@ -697,9 +702,6 @@ theorem rev_castSucc (k : Fin n) : rev (castSucc k) = succ (rev k) := k.rev_cast
697702

698703
theorem rev_succ (k : Fin n) : rev (succ k) = castSucc (rev k) := k.rev_addNat 1
699704

700-
@[simp, grind _=_]
701-
theorem castSucc_succ (i : Fin n) : i.succ.castSucc = i.castSucc.succ := rfl
702-
703705
@[simp, grind =]
704706
theorem castLE_refl (h : n ≤ n) (i : Fin n) : i.castLE h = i := rfl
705707

src/Init/Data/Int/Basic.lean

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ protected theorem zero_ne_one : (0 : Int) ≠ 1 := nofun
8080

8181
/-! ## Coercions -/
8282

83-
@[simp] theorem ofNat_eq_coe : Int.ofNat n = Nat.cast n := rfl
83+
@[simp] theorem ofNat_eq_natCast (n : Nat) : Int.ofNat n = n := rfl
84+
85+
@[deprecated ofNat_eq_natCast (since := "2025-10-29")]
86+
theorem ofNat_eq_coe : Int.ofNat n = Nat.cast n := rfl
8487

8588
@[simp] theorem ofNat_zero : ((0 : Nat) : Int) = 0 := rfl
8689

src/Init/Data/Int/DivMod/Lemmas.lean

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,6 +2477,10 @@ theorem bmod_eq_self_sub_mul_bdiv (x : Int) (m : Nat) : bmod x m = x - m * bdiv
24772477
theorem bmod_eq_self_sub_bdiv_mul (x : Int) (m : Nat) : bmod x m = x - bdiv x m * m := by
24782478
rw [← Int.add_sub_cancel (bmod x m), bmod_add_bdiv']
24792479

2480+
theorem bmod_eq_emod_of_lt {x : Int} {m : Nat} (hx : x % m < (m + 1) / 2) : bmod x m = x % m := by
2481+
simp [bmod, hx]
2482+
2483+
@[deprecated Int.bmod_eq_emod_of_lt (since := "2025-10-29")]
24802484
theorem bmod_pos (x : Int) (m : Nat) (p : x % m < (m + 1) / 2) : bmod x m = x % m := by
24812485
simp [bmod_def, p]
24822486

@@ -2486,7 +2490,7 @@ theorem bmod_neg (x : Int) (m : Nat) (p : x % m ≥ (m + 1) / 2) : bmod x m = (x
24862490
theorem bmod_eq_emod (x : Int) (m : Nat) : bmod x m = x % m - if x % m ≥ (m + 1) / 2 then m else 0 := by
24872491
split
24882492
· rwa [bmod_neg]
2489-
· rw [bmod_pos] <;> simp_all
2493+
· rw [bmod_eq_emod_of_lt] <;> simp_all
24902494

24912495
@[simp]
24922496
theorem bmod_one (x : Int) : Int.bmod x 1 = 0 := by
@@ -2723,9 +2727,6 @@ theorem bmod_eq_iff {a : Int} {b : Nat} {c : Int} (hb : 0 < b) :
27232727
have := bmod_lt (x := a) (m := b) hb
27242728
omega
27252729

2726-
theorem bmod_eq_emod_of_lt {x : Int} {m : Nat} (hx : x % m < (m + 1) / 2) : bmod x m = x % m := by
2727-
simp [bmod, hx]
2728-
27292730
theorem bmod_eq_neg {n : Nat} {m : Int} (hm : 0 ≤ m) (hn : n = 2 * m) : m.bmod n = -m := by
27302731
by_cases h : m = 0
27312732
· subst h; simp
@@ -2766,7 +2767,7 @@ theorem one_bmod_two : Int.bmod 1 2 = -1 := by simp
27662767

27672768
theorem one_bmod {b : Nat} (h : 3 ≤ b) : Int.bmod 1 b = 1 := by
27682769
have hb : 1 % (b : Int) = 1 := by rw [one_emod]; omega
2769-
rw [bmod_pos _ _ (by omega), hb]
2770+
rw [bmod_eq_emod_of_lt (by omega), hb]
27702771

27712772
theorem bmod_two_eq (x : Int) : x.bmod 2 = -1 ∨ x.bmod 2 = 0 := by
27722773
have := le_bmod (x := x) (m := 2) (by omega)

src/Init/Data/Int/LemmasAux.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ protected theorem ofNat_mul_out (m n : Nat) : ↑m * ↑n = (↑(m * n) : Int) :
4747

4848
protected theorem ofNat_add_one_out (n : Nat) : ↑n + (1 : Int) = ↑(Nat.succ n) := rfl
4949

50-
@[simp] theorem ofNat_eq_natCast (n : Nat) : Int.ofNat n = n := rfl
51-
5250
@[norm_cast] theorem natCast_inj {m n : Nat} : (m : Int) = (n : Int) ↔ m = n := ofNat_inj
5351

5452
@[norm_cast]

src/Init/Data/List/ToArray.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ theorem _root_.Array.replicate_eq_toArray_replicate :
548548
Array.replicate n v = (List.replicate n v).toArray := by
549549
simp
550550

551-
@[simp, grind =] theorem flatMap_empty {β} (f : α → Array β) : (#[] : Array α).flatMap f = #[] := rfl
551+
@[simp, grind =] theorem _root_.Array.flatMap_empty {β} (f : α → Array β) :
552+
(#[] : Array α).flatMap f = #[] := rfl
552553

553554
theorem flatMap_toArray_cons {β} (f : α → Array β) (a : α) (as : List α) :
554555
(a :: as).toArray.flatMap f = f a ++ as.toArray.flatMap f := by

0 commit comments

Comments
 (0)