@@ -172,35 +172,96 @@ public def Zipper.iter (t : Zipper α β) : Iter (α := Zipper α β) ((a : α)
172172public def Zipper.iter_of_tree (t : Internal.Impl α β) : Iter (α := Zipper α β) ((a : α) × β a) :=
173173 Zipper.iter <| Zipper.done.prependMap t
174174
175- public instance { z : Zipper α β} : ToIterator z Id ((a : α) × β a) where
175+ public instance {z : Zipper α β} : ToIterator z Id ((a : α) × β a) where
176176 State := Zipper α β
177177 iterMInternal := Iter.toIterM <| Zipper.iter z
178178
179- public theorem correctness_lemma {α β}
180- {z : Zipper α β} :
181- (Zipper.iter z).toList = z.toList := by
182- induction z
183- case done =>
184- sorry
185- case cons k v tree next next_ih =>
186- induction tree generalizing next
187- case leaf =>
179+ public theorem step_Zipper_eq_match {it : IterM (α := Zipper α β) Id ((a : α) × β a)} :
180+ it.step = ⟨match it.internalState.iter with
181+ | ⟨Zipper.done⟩ => IterStep.done
182+ | ⟨Zipper.cons k v t z⟩ => IterStep.yield { internalState := Zipper.prependMap t z } ⟨k, v⟩,
183+ (by
184+ simp only [IterM.IsPlausibleStep, Iterator.IsPlausibleStep, Zipper.step]; split; all_goals (rename_i heq; simp [heq, Zipper.iter]))⟩ := by
185+ simp [IterM.step, Iterator.step, Zipper.step]
186+ ext
187+ congr 1
188+ congr 1
189+ cases it
190+ next =>
191+ rename_i internalState
192+ simp
193+ congr 1
194+ cases internalState
195+ case done =>
196+ simp only [Zipper.iter]
197+ case cons k v tree next =>
198+ simp only [Zipper.iter]
199+
200+ public theorem val_step_Zipper_eq_match {α β}
201+ {it : Iter (α := Zipper α β) (Sigma β)} :
202+ it.step.val =
203+ match it.internalState.iter with
204+ | ⟨Zipper.done⟩ => IterStep.done
205+ | ⟨Zipper.cons k v t it'⟩ =>
206+ IterStep.yield { internalState := Zipper.prependMap t it' } ⟨k, v⟩
207+ := by
208+ rcases it with ⟨z, upper⟩
209+ rw [Iter.step]
210+ rw [step_Zipper_eq_match]
211+ simp only [Iter.toIterM]
212+ split
213+ · simp [Zipper.iter, IterM.Step.toPure, IterStep.mapIterator, Id.run]
214+ · rename_i heq
215+ simp [Zipper.iter] at heq
216+ . split
217+ case h_1 =>
218+ rename_i heq
219+ simp [Zipper.iter] at heq
220+ case h_2 k v tree next x k v t it' heq =>
221+ simp only [Zipper.iter] at heq
222+ injections
223+ rename_i k_eq v_eq tree_eq next_eq
224+ simp [Iter.step, Iter.toIterM, IterM.step, Id.run, Iterator.step, Zipper.step, IterM.toIter]
225+ simp_all
226+
227+ public theorem toList_Zipper {α β}
228+ {z : Zipper α β}:
229+ (⟨z⟩ : Iter (Sigma β)).toList =
230+ z.toList := by
231+ rw [Iter.toList_eq_match_step]
232+ generalize hit : (⟨z⟩ : Iter (Sigma β)).step.val = step
233+ rw [val_step_Zipper_eq_match] at hit
234+ simp only at hit
235+ split at hit <;> rename_i heq
236+ · simp [← hit]
237+ cases z
238+ . simp [Zipper.toList]
239+ . simp [Zipper.iter] at heq
240+ . rename_i x k v t it'
241+ simp [← hit]
242+ rw [toList_Zipper]
243+ . generalize heq2 : Zipper.cons k v t it' = y
244+ rw [heq2] at heq
245+ simp [Zipper.iter] at heq
246+ rw [heq]
247+ rw [← heq2]
188248 simp [Zipper.toList]
189- simp [Zipper.iter]
190- rw [Iter.toList_eq_match_step]
191- simp [Iter.step]
192- simp [Id.run]
193- simp [Iter.toIterM]
194- simp [IterM.step]
195- simp [Iterator.step]
196- simp [Zipper.step]
197- simp [Zipper.prependMap]
198- simp [Id.run]
199- sorry
200- case inner _ k v l r l_ih r_ih =>
201- sorry
249+ rw [Zipper.prependMap_to_list]
250+ termination_by z.size
251+ decreasing_by
252+ simp_all
253+ rename_i t _ _ heq
254+ simp [Zipper.iter] at heq
255+ rw [heq]
256+ simp [Zipper.size]
257+ induction t
258+ case leaf =>
259+ simp [Zipper.prependMap]
260+ simp [Internal.Impl.treeSize]
261+ case inner =>
262+ rw [Zipper.prependMap_size]
263+ simp [Internal.Impl.treeSize]
202264end ZipperIterator
203-
204265section Rxc
205266
206267public structure RxcIterator (α : Type u) (β : α → Type v) (cmp : α → α → Ordering) where
@@ -265,13 +326,6 @@ def instFinitenessRelation : FinitenessRelation (RxcIterator α β cmp) Id where
265326public instance instFinite : Finite (RxcIterator α β cmp) Id :=
266327 .of_finitenessRelation instFinitenessRelation
267328
268- public theorem toList_lemma {it : Iter (α := RxcIterator α β cmp) ((a : α) × β a)} : it.toList = it.internalState.iter.toList.filter (fun e => (cmp e.fst bound).isLE) := by
269- unfold Iter.toList
270- simp [Iter.toIterM]
271- unfold Iter.internalState
272- simp [instIteratorCollectRxcIteratorIdSigma]
273- sorry
274-
275329public theorem step_rxcIterator_eq_match {cmp : α → α → Ordering} {it : IterM (α := RxcIterator α β cmp) Id ((a : α) × β a)} :
276330 it.step = ⟨match it.internalState.iter with
277331 | Zipper.done => IterStep.done
0 commit comments