@@ -8,3 +8,81 @@ def Iter.toIterM {α : Type w} {β : Type v} (it : Iter (α := α) β) : IterM (
88
99def IterM.toPureIter {α : Type w} {β : Type v} (it : IterM (α := α) Id β) : Iter (α := α) β :=
1010 ⟨it.inner⟩
11+
12+ @[simp]
13+ theorem Iter.toPureIter_toIterM {α : Type w} {β : Type v} (it : Iter (α := α) β) :
14+ it.toIterM.toPureIter = it :=
15+ rfl
16+
17+ @[simp]
18+ theorem Iter.toIterM_toPureIter {α : Type w} {β : Type v} (it : IterM (α := α) Id β) :
19+ it.toPureIter.toIterM = it :=
20+ rfl
21+
22+ def Iter.plausible_step {α : Type w} {β : Type v} [Iterator α Id β]
23+ (it : Iter (α := α) β) (step : IterStep (Iter (α := α) β) β) : Prop :=
24+ it.toIterM.plausible_step (step.map Iter.toIterM id)
25+
26+ def Iter.Step {α : Type w} {β : Type v} [Iterator α Id β] (it : Iter (α := α) β) :=
27+ PlausibleIterStep (Iter.plausible_step it)
28+
29+ def Iter.plausible_output {α : Type w} {β : Type v} [Iterator α Id β]
30+ (it : Iter (α := α) β) (out : β) : Prop :=
31+ ∃ it', it.plausible_step (.yield it' out)
32+
33+ def Iter.plausible_successor_of {α : Type w} {β : Type v} [Iterator α Id β]
34+ (it' it : Iter (α := α) β) : Prop :=
35+ ∃ step, step.successor = some it' ∧ it.plausible_step step
36+
37+ def Iter.plausible_skip_successor_of {α : Type w} {β : Type v} [Iterator α Id β]
38+ (it' it : Iter (α := α) β) : Prop :=
39+ it.plausible_step (.skip it')
40+
41+ @[always_inline, inline]
42+ def Iter.step {α : Type w} {β : Type w} [Iterator α Id β] [Functor Id]
43+ (it : Iter (α := α) β) : it.Step := by
44+ refine it.toIterM.stepH.run.inflate.map IterM.toPureIter id _ ?_
45+ intro step hp
46+ simp only [Iter.plausible_step, IterStep.map_map, id_eq, IterStep.map_id', toIterM_toPureIter, hp]
47+
48+ section Finite
49+
50+ def Iter.finitelyManySteps {α : Type w} {β : Type v} [Iterator α Id β] [Finite α Id]
51+ (it : Iter (α := α) β) : IterM.TerminationMeasures.Finite α Id :=
52+ it.toIterM.finitelyManySteps
53+
54+ theorem Iter.TerminationMeasures.Finite.rel_of_yield
55+ {α : Type w} {β : Type v} [Iterator α Id β]
56+ {it it' : Iter (α := α) β} {out : β} (h : it.plausible_step (.yield it' out)) :
57+ IterM.TerminationMeasures.Finite.rel ⟨it'.toIterM⟩ ⟨it.toIterM⟩ :=
58+ IterM.TerminationMeasures.Finite.rel_of_yield h
59+
60+ theorem Iter.TerminationMeasures.Finite.rel_of_skip
61+ {α : Type w} {β : Type v} [Iterator α Id β]
62+ {it it' : Iter (α := α) β} (h : it.plausible_step (.skip it')) :
63+ IterM.TerminationMeasures.Finite.rel ⟨it'.toIterM⟩ ⟨it.toIterM⟩ :=
64+ IterM.TerminationMeasures.Finite.rel_of_skip h
65+
66+ macro_rules | `(tactic| decreasing_trivial) => `(tactic|
67+ first
68+ | exact Iter.TerminationMeasures.Finite.rel_of_yield ‹_›
69+ | exact Iter.TerminationMeasures.Finite.rel_of_skip ‹_›)
70+
71+ end Finite
72+
73+ section Productive
74+
75+ def Iter.finitelyManySkips {α : Type w} {β : Type v} [Iterator α Id β] [Productive α Id]
76+ (it : Iter (α := α) β) : IterM.TerminationMeasures.Productive α Id :=
77+ it.toIterM.finitelyManySkips
78+
79+ theorem Iter.TerminationMeasures.Productive.rel_of_skip
80+ {α : Type w} {β : Type v} [Iterator α Id β]
81+ {it it' : Iter (α := α) β} (h : it.plausible_step (.skip it')) :
82+ IterM.TerminationMeasures.Productive.rel ⟨it'.toIterM⟩ ⟨it.toIterM⟩ :=
83+ IterM.TerminationMeasures.Productive.rel_of_skip h
84+
85+ macro_rules | `(tactic| decreasing_trivial) => `(tactic|
86+ exact Iter.TerminationMeasures.Productive.rel_of_skip ‹_›)
87+
88+ end Productive
0 commit comments