Skip to content

Commit 74ff77b

Browse files
committed
move lemmas to Init
1 parent 13c82fb commit 74ff77b

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/Init/Data/Array/Lemmas.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,6 +2994,10 @@ theorem extract_empty_of_size_le_start {xs : Array α} {start stop : Nat} (h : x
29942994
apply ext'
29952995
simp
29962996

2997+
theorem _root_.List.toArray_drop {l : List α} {k : Nat} :
2998+
(l.drop k).toArray = l.toArray.extract k := by
2999+
rw [List.drop_eq_extract, List.extract_toArray, List.size_toArray]
3000+
29973001
@[deprecated extract_size (since := "2025-02-27")]
29983002
theorem take_size {xs : Array α} : xs.take xs.size = xs := by
29993003
cases xs

src/Init/Data/List/TakeDrop.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ theorem dropLast_eq_take {l : List α} : l.dropLast = l.take (l.length - 1) := b
257257
dsimp
258258
rw [map_drop]
259259

260+
theorem drop_eq_extract {l : List α} {k : Nat} :
261+
l.drop k = l.extract k := by
262+
induction l generalizing k
263+
case nil => simp
264+
case cons _ _ ih =>
265+
match k with
266+
| 0 => simp
267+
| _ + 1 =>
268+
simp only [List.drop_succ_cons, List.length_cons, ih]
269+
simp only [List.extract_eq_drop_take, List.drop_succ_cons, Nat.succ_sub_succ]
270+
260271
/-! ### takeWhile and dropWhile -/
261272

262273
theorem takeWhile_cons {p : α → Bool} {a : α} {l : List α} :

src/Std/Data/Iterators/Lemmas/Combinators/Drop.lean

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,22 @@ theorem Iter.toListRev_drop {α β} [Iterator α Id β] {n : Nat}
5757
(it.drop n).toListRev = (it.toList.reverse.take (it.toList.length - n)) := by
5858
rw [toListRev_eq, toList_drop, List.reverse_drop]
5959

60-
-- TODO: Init.Data.Array.Lemmas
61-
theorem _root_.List.drop_toArray {l : List α} {k : Nat} :
62-
(l.drop k).toArray = l.toArray.extract k := by
60+
theorem List.drop_eq_extract {l : List α} {k : Nat} :
61+
l.drop k = l.extract k := by
6362
induction l generalizing k
6463
case nil => simp
65-
case cons l' ih =>
64+
case cons _ _ ih =>
6665
match k with
6766
| 0 => simp
68-
| k' + 1 => simp [List.drop_succ_cons, ih]
67+
| _ + 1 =>
68+
simp only [List.drop_succ_cons, List.length_cons, Nat.reduceSubDiff, ih]
69+
simp only [List.extract_eq_drop_take, Nat.reduceSubDiff, List.drop_succ_cons]
6970

7071
@[simp]
7172
theorem Iter.toArray_drop {α β} [Iterator α Id β] {n : Nat}
7273
[Finite α Id] [IteratorCollect α Id] [LawfulIteratorCollect α Id]
7374
{it : Iter (α := α) β} :
7475
(it.drop n).toArray = it.toArray.extract n := by
75-
rw [← toArray_toList, ← toArray_toList, ← List.drop_toArray, toList_drop]
76+
rw [← toArray_toList, ← toArray_toList, ← List.toArray_drop, toList_drop]
7677

7778
end Std.Iterators

0 commit comments

Comments
 (0)