@@ -241,6 +241,16 @@ def IterStep.successor : IterStep α β → Option α
241241 | .skip it => some it
242242 | .done => none
243243
244+ @[simp]
245+ theorem IterStep.successor_yield {it : α} {out : β} :
246+ (IterStep.yield it out).successor = some it := rfl
247+
248+ @[simp]
249+ theorem IterStep.successor_skip {it : α} : (IterStep.skip (β := β) it).successor = some it := rfl
250+
251+ @[simp]
252+ theorem IterStep.successor_done : (IterStep.done (α := α) (β := β)).successor = none := rfl
253+
244254/--
245255If present, applies `f` to the iterator of an `IterStep` and replaces the iterator
246256with the result of the application of `f`.
@@ -543,6 +553,10 @@ def Iter.IsPlausibleSuccessorOf {α : Type w} {β : Type w} [Iterator α Id β]
543553 (it' it : Iter (α := α) β) : Prop :=
544554 it'.toIterM.IsPlausibleSuccessorOf it.toIterM
545555
556+ theorem Iter.isPlausibleSuccessorOf_eq_invImage {α : Type w} {β : Type w} [Iterator α Id β] :
557+ IsPlausibleSuccessorOf (α := α) (β := β) =
558+ InvImage (IterM.IsPlausibleSuccessorOf (α := α) (β := β) (m := Id)) Iter.toIterM := rfl
559+
546560theorem Iter.isPlausibleSuccessorOf_iff_exists {α : Type w} {β : Type w} [Iterator α Id β]
547561 {it' it : Iter (α := α) β} :
548562 it'.IsPlausibleSuccessorOf it ↔ ∃ step, step.successor = some it' ∧ it.IsPlausibleStep step := by
@@ -555,6 +569,16 @@ theorem Iter.isPlausibleSuccessorOf_iff_exists {α : Type w} {β : Type w} [Iter
555569 exact ⟨step.mapIterator Iter.toIterM,
556570 by cases step <;> simp_all [IterStep.successor, Iter.IsPlausibleStep]⟩
557571
572+ theorem Iter.IsPlausibleStep.isPlausibleSuccessor_of_yield {α : Type w} {β : Type w}
573+ [Iterator α Id β] {it' it : Iter (α := α) β} {out : β}
574+ (h : it.IsPlausibleStep (.yield it' out)) : it'.IsPlausibleSuccessorOf it := by
575+ simpa [isPlausibleSuccessorOf_iff_exists] using ⟨.yield it' out, by simp [h]⟩
576+
577+ theorem Iter.IsPlausibleStep.isPlausibleSuccessor_of_skip {α : Type w} {β : Type w}
578+ [Iterator α Id β] {it' it : Iter (α := α) β} (h : it.IsPlausibleStep (.skip it')) :
579+ it'.IsPlausibleSuccessorOf it := by
580+ simpa [isPlausibleSuccessorOf_iff_exists] using ⟨.skip it', by simp [h]⟩
581+
558582/--
559583Asserts that a certain iterator `it` could plausibly yield the value `out` after an arbitrary
560584number of steps.
@@ -656,6 +680,10 @@ Given this typeclass, termination proofs for well-founded recursion over an iter
656680class Finite (α : Type w) (m : Type w → Type w') {β : Type w} [Iterator α m β] : Prop where
657681 wf : WellFounded (IterM.IsPlausibleSuccessorOf (α := α) (m := m))
658682
683+ theorem Finite.wf_of_id {α : Type w} {β : Type w} [Iterator α Id β] [Finite α Id] :
684+ WellFounded (Iter.IsPlausibleSuccessorOf (α := α)) := by
685+ simpa [Iter.isPlausibleSuccessorOf_eq_invImage] using InvImage.wf _ Finite.wf
686+
659687/--
660688This type is a wrapper around `IterM` so that it becomes a useful termination measure for
661689recursion over finite iterators. See also `IterM.finitelyManySteps` and `Iter.finitelyManySteps`.
0 commit comments