Skip to content

Commit e51c04e

Browse files
committed
toArray, toListRev lemmas
1 parent 01440c8 commit e51c04e

File tree

1 file changed

+29
-23
lines changed
  • src/Std/Data/Iterators/Lemmas/Combinators

1 file changed

+29
-23
lines changed

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

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,32 @@ theorem Iter.step_take {α β} [Iterator α Id β] {n : Nat}
2727
| .done h => .done (.done h)) := by
2828
simp only [Iter.step, Iter.step, Iter.take_eq, IterM.step_take, toIterM_toIter]
2929
cases n
30-
case zero =>
31-
simp [Id.run, PlausibleIterStep.done]
30+
case zero => simp [Id.run, PlausibleIterStep.done]
3231
case succ k =>
3332
simp only [Id.pure_eq, Id.bind_eq, Id.run, take_eq]
3433
generalize it.toIterM.step = step
3534
obtain ⟨step, h⟩ := step
3635
cases step <;>
3736
simp [PlausibleIterStep.yield, PlausibleIterStep.skip, PlausibleIterStep.done]
3837

38+
theorem Iter.atIdxSlow?_take {α β}
39+
[Iterator α Id β] [Productive α Id] {k l : Nat}
40+
{it : Iter (α := α) β} :
41+
(it.take k).atIdxSlow? l = if l < k then it.atIdxSlow? l else none := by
42+
fun_induction it.atIdxSlow? l generalizing k
43+
case case1 it it' out h h' =>
44+
simp only [atIdxSlow?.eq_def (it := it.take k), step_take, h']
45+
cases k <;> simp
46+
case case2 it it' out h h' l ih =>
47+
simp only [Nat.succ_eq_add_one, atIdxSlow?.eq_def (it := it.take k), step_take, h']
48+
cases k <;> cases l <;> simp [ih]
49+
case case3 l it it' h h' ih =>
50+
simp only [atIdxSlow?.eq_def (it := it.take k), step_take, h']
51+
cases k <;> cases l <;> simp [ih]
52+
case case4 l it h h' =>
53+
simp only [atIdxSlow?.eq_def (it := it.take k), atIdxSlow?.eq_def (it := it), step_take, h']
54+
cases k <;> cases l <;> simp
55+
3956
theorem Iter.toList_take_of_finite {α β} [Iterator α Id β] {n : Nat}
4057
[Finite α Id] [IteratorCollect α Id] [LawfulIteratorCollect α Id]
4158
{it : Iter (α := α) β} :
@@ -52,27 +69,16 @@ theorem Iter.toList_take_of_finite {α β} [Iterator α Id β] {n : Nat}
5269
· simp [ihs h]
5370
· simp
5471

55-
theorem Iter.atIdxSlow?_take {α β}
56-
[Iterator α Id β] [Productive α Id] {k l : Nat}
72+
theorem Iter.toListRev_take_of_finite {α β} [Iterator α Id β] {n : Nat}
73+
[Finite α Id] [IteratorCollect α Id] [LawfulIteratorCollect α Id]
5774
{it : Iter (α := α) β} :
58-
(it.take k).atIdxSlow? l = if l < k then it.atIdxSlow? l else none := by
59-
revert k
60-
fun_induction it.atIdxSlow? l
61-
case case1 it it' out h h' =>
62-
intro k
63-
simp [atIdxSlow?.eq_def (it := it.take k), atIdxSlow?.eq_def (it := it), step_take, h']
64-
cases k <;> simp
65-
case case2 it it' out h h' l ih =>
66-
intro k
67-
simp [atIdxSlow?.eq_def (it := it.take k), atIdxSlow?.eq_def (it := it), step_take, h']
68-
cases k <;> cases l <;> simp [ih]
69-
case case3 l it it' h h' ih =>
70-
intro k
71-
simp [atIdxSlow?.eq_def (it := it.take k), atIdxSlow?.eq_def (it := it), step_take, h']
72-
cases k <;> cases l <;> simp [ih]
73-
case case4 l it h h' =>
74-
intro k
75-
simp only [atIdxSlow?.eq_def (it := it.take k), atIdxSlow?.eq_def (it := it), step_take, h']
76-
cases k <;> cases l <;> simp
75+
(it.take n).toListRev = it.toListRev.drop (it.toList.length - n) := by
76+
rw [toListRev_eq, toList_take_of_finite, List.reverse_take, toListRev_eq]
77+
78+
theorem Iter.toArray_take_of_finite {α β} [Iterator α Id β] {n : Nat}
79+
[Finite α Id] [IteratorCollect α Id] [LawfulIteratorCollect α Id]
80+
{it : Iter (α := α) β} :
81+
(it.take n).toArray = it.toArray.take n := by
82+
rw [← toArray_toList, ← toArray_toList, List.take_toArray, toList_take_of_finite]
7783

7884
end Std.Iterators

0 commit comments

Comments
 (0)