@@ -7,48 +7,13 @@ prelude
77import Iterator.Combinators.Monadic.FilterMap
88import Iterator.Lemmas.Monadic.Consumers
99
10- theorem Iterator.step_hcongr {α : Type w} {m : Type w → Type w'} {β : Type v} [Iterator α m β]
11- {it₁ it₂ : IterM (α := α) m β} (h : it₁ = it₂) : Iterator.step (m := m) it₁ = h ▸ Iterator.step (m := m) it₂ := by
12- cases h; rfl
13-
14- theorem Iterator.bind_hcongr {α : Type w} {m : Type w → Type w'} [Bind m] {β : Type v}
15- [Iterator α m β] {it it' : IterM (α := α) m β}
16- {γ}
17- {x : m (USquash it.Step)}
18- {x' : m (USquash it.Step)}
19- {f : (USquash it.Step) → m γ}
20- {f' : (USquash it.Step) → m γ}
21- (h : it = it') (h' : x = h ▸ x') (h'' : ∀ s hs, (f (.deflate ⟨s, hs⟩)) = (f' (.deflate ⟨s, h ▸ hs⟩))) :
22- x >>= f = x' >>= f' := by
23- cases h
24- dsimp only at h'
25- rw [h']
26- apply bind_congr
27- intro step
28- rw [← USquash.deflate_inflate (x := step)]
29- generalize step.inflate = step
30- cases step with
31- | mk step h => exact h'' step h
32-
33- theorem Iterator.bind_hcongr' {α : Type w} {m : Type w → Type w'} [Bind m] {β : Type w} [Iterator α m β]
34- {it it' : IterM (α := α) m β} {γ}
35- {x : m it.Step}
36- {f : it.Step → m γ}
37- (h : it = it') :
38- x >>= f = (h ▸ x : m it'.Step) >>= (fun step => f ⟨step.1 , h ▸ step.2 ⟩) := by
39- cases h
40- dsimp only
41- apply bind_congr
42- intro a
43- rfl
44-
4510section StepH
4611
4712variable {α : Type w} {m : Type w → Type w'} {β : Type v} {β' : Type v'}
4813 [Iterator α m β] (it : IterM (α := α) m β) [Monad m]
4914 (f : β → HetT m (Option β'))
5015
51- theorem IterM.filterMapMH_stepH [LawfulMonad m] :
16+ theorem IterM.stepH_filterMapMH [LawfulMonad m] :
5217 (it.filterMapMH f).stepH = (do
5318 match (← it.stepH).inflate with
5419 | .yield it' out h => do
@@ -69,7 +34,7 @@ theorem IterM.filterMapMH_stepH [LawfulMonad m] :
6934 | .skip it' h => rfl
7035 | .done h => rfl
7136
72- theorem IterM.filterMapH_stepH [LawfulMonad m] {f : β → Option β'} :
37+ theorem IterM.stepH_filterMapH [LawfulMonad m] {f : β → Option β'} :
7338 (it.filterMapH f).stepH = (do
7439 match (← it.stepH).inflate with
7540 | .yield it' out h => do
@@ -82,7 +47,7 @@ theorem IterM.filterMapH_stepH [LawfulMonad m] {f : β → Option β'} :
8247 pure <| .deflate <| .skip (it'.filterMapH f) (.skip h)
8348 | .done h =>
8449 pure <| .deflate <| .done (.done h)) := by
85- simp only [IterM.filterMapH, filterMapMH_stepH , pure]
50+ simp only [IterM.filterMapH, stepH_filterMapMH , pure]
8651 apply bind_congr
8752 intro step
8853 generalize step.inflate = step
@@ -92,7 +57,7 @@ theorem IterM.filterMapH_stepH [LawfulMonad m] {f : β → Option β'} :
9257 · simp
9358 · simp
9459
95- theorem IterM.mapMH_stepH [LawfulMonad m] {f : β → HetT m β'} :
60+ theorem IterM.stepH_mapMH [LawfulMonad m] {f : β → HetT m β'} :
9661 (it.mapMH f).stepH = (do
9762 match (← it.stepH).inflate with
9863 | .yield it' out h => do
@@ -103,7 +68,7 @@ theorem IterM.mapMH_stepH [LawfulMonad m] {f : β → HetT m β'} :
10368 | .done h =>
10469 pure <| .deflate <| .done (.done h)) := by
10570 change (it.filterMapMH _).stepH = _
106- rw [filterMapMH_stepH ]
71+ rw [stepH_filterMapMH ]
10772 apply bind_congr
10873 intro step
10974 generalize step.inflate = step
@@ -122,7 +87,7 @@ theorem IterM.stepH_mapH [LawfulMonad m] {f : β → β'} :
12287 | .skip it' h =>
12388 pure <| .deflate <| .skip (it'.mapH f) (.skip h)
12489 | .done h => pure <| .deflate <| .done (.done h)) := by
125- simp only [mapH, IterM.mapMH_stepH ]
90+ simp only [mapH, IterM.stepH_mapMH ]
12691 apply bind_congr
12792 intro step
12893 generalize step.inflate = step
@@ -142,7 +107,7 @@ theorem IterM.stepH_filter [LawfulMonad m] {f : β → Bool} :
142107 | .skip it' h =>
143108 pure <| .deflate <| .skip (it'.filter f) (.skip h)
144109 | .done h => pure <| .deflate <| .done (.done h)) := by
145- simp only [filter, IterM.filterMapH_stepH ]
110+ simp only [filter, IterM.stepH_filterMapH ]
146111 apply bind_congr
147112 intro step
148113 generalize step.inflate = step
@@ -165,7 +130,7 @@ variable {α : Type w} {m : Type w → Type w'} {β : Type v} {β' : Type w}
165130 [Iterator α m β] (it : IterM (α := α) m β) [Monad m]
166131 (f : β → m (USquash <| Option β'))
167132
168- theorem IterM.filterMapH_step [LawfulMonad m] {f : β → Option β'} :
133+ theorem IterM.step_filterMapH [LawfulMonad m] {f : β → Option β'} :
169134 (it.filterMapH f).step = (do
170135 match (← it.stepH).inflate with
171136 | .yield it' out h => do
@@ -178,7 +143,7 @@ theorem IterM.filterMapH_step [LawfulMonad m] {f : β → Option β'} :
178143 pure <| .skip (it'.filterMapH f) (.skip h)
179144 | .done h =>
180145 pure <| .done (.done h)) := by
181- simp only [IterM.step, filterMapH_stepH , map_eq_pure_bind, bind_assoc]
146+ simp only [IterM.step, stepH_filterMapH , map_eq_pure_bind, bind_assoc]
182147 refine congrArg (_ >>= ·) ?_
183148 ext step
184149 simp only [Function.comp_apply, bind_pure_comp]
@@ -210,7 +175,7 @@ instance {f : β → HetT m γ} [LawfulMonad m] [IteratorToArray α m]
210175 induction it using IterM.induct with | step it ih_yield ih_skip =>
211176 rw [IterM.DefaultConsumers.toArrayMapped_of_stepH]
212177 rw [IterM.DefaultConsumers.toArrayMapped_of_stepH]
213- simp only [IterM.mapMH_stepH , bind_assoc]
178+ simp only [IterM.stepH_mapMH , bind_assoc]
214179 apply bind_congr
215180 intro step
216181 generalize step.inflate = step
@@ -271,7 +236,7 @@ theorem IterM.toList_filterMapH {α : Type w} {m : Type w → Type w'} [Monad m]
271236 rename_i it ihy ihs
272237 rw [IterM.toList_of_step, IterM.toList_of_step]
273238 simp
274- rw [filterMapH_step ]
239+ rw [step_filterMapH ]
275240 simp only [bind_assoc, IterM.step, map_eq_pure_bind]
276241 apply bind_congr
277242 intro step
0 commit comments