File size: 9,542 Bytes
760f90e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import OAI.Computability.StarHeight.StreamTranslation

namespace OAI

namespace GeneralizedStarHeight

universe u
universe uAlphabet uAlphabet2 uJ uC uAlphabet3 uM uV uK
universe uP uC2 uAlphabet4 uM2 uV2 uK2 uP2 uC3
universe uAlphabet5 uAlphabet6 uJ2 uC4 uAlphabet7

namespace CanonicalEpisodes.Parameters

open WordIntervals LocalMarkers EpisodeEnd
variable {Alphabet : Type uAlphabet} (C : CanonicalEpisodes.Parameters Alphabet)

lemma end_congr {f g : ℤ → Alphabet} {s b z : ℤ}
    (hv : C.Visible s b z) (he : AgreesOn f g s b)
    (hf : EndAt C.d C.K C.tail f z (C.small f z) b) :
    EndAt C.d C.K C.tail g z (C.small g z) b := by
  rw [←(C.searches_congr hv he).1]
  cases hη : C.small f z with
  | some q => simpa only [hη,EndAt] using hf
  | none =>
    rw [hη] at hf
    obtain ⟨v,hv',hm⟩ := hf
    refine ⟨v,(shortCont_congr (fun x hx hx' => he x (hv.2.2.1.trans hx)
      (hx'.trans_le hv.2.2.2))).mp hv',hm.1,?_,?_⟩
    · intro h
      apply hm.2.1
      exact (he _ (by have := hm.1; have := hv.2.2.1;omega) (by have := C.tail_pos;omega)).trans h
    · intro x hx hx'
      exact (he x (hv.2.2.1.trans hx) (by have := C.tail_pos;omega)).symm.trans (hm.2.2 x hx hx')

lemma complete_realizes {lag : ℤ} {w : List Alphabet} (hw : w∈C.complete lag)
    {f : ℤ → Alphabet} (hf : Realizes w 0 f) :
    C.Visible 0 w.length (lag+C.offset) ∧
      EndAt C.d C.K C.tail f (lag+C.offset) (C.small f (lag+C.offset)) w.length := by
  obtain ⟨g,hg,hv,he⟩ := hw
  refine ⟨hv,C.end_congr hv ?_ he⟩
  simpa only [zero_add] using hg.same hf

end CanonicalEpisodes.Parameters

namespace ExceptionalOrigins.Parameters

open WordIntervals LocalMarkers
variable {Alphabet : Type uAlphabet2} {J : Type uJ} {C : Type uC} (A : ExceptionalOrigins.Parameters Alphabet J C)

lemma anchor_congr {f g : ℤ → Alphabet} {s b t Q : ℤ}
    (hv : A.Visible s b t Q) (he : AgreesOn f g s b) :
    A.anchor f (b-A.endRule.tail) t=A.anchor g (b-A.endRule.tail) t := by
  unfold anchor
  rw [(A.endRule.searches_congr hv.base he).2]

lemma failedLanguage_iff {f : ℤ → Alphabet} {w : List Alphabet} {t : ℤ}
    (hw₀ : 0≤A.w₀) (hv : A.Visible 0 w.length t (A.anchor f (w.length-A.endRule.tail) t)) (hf : Realizes w 0 f) :
    w∈A.failedLanguage t ↔ A.Failed f t (A.anchor f (w.length-A.endRule.tail) t) := by
  constructor
  · rintro ⟨g,hg,hg'⟩
    have he : AgreesOn g f 0 w.length := by simpa only [zero_add] using hg.same hf
    have hq := A.anchor_congr hv he
    rw [hq] at hg'
    exact (A.Failed_congr hw₀ hv he).mp hg'
  · exact fun hh => ⟨f,hf,hh⟩

end ExceptionalOrigins.Parameters

namespace OuterStream

open WordIntervals LocalMarkers BoundarySnapshot SplitMetadata
variable {Alphabet : Type uAlphabet3} {M : Type uM} {V : Type uV} {K : Type uK} {P : Type uP} {C : Type uC2} [Monoid M] [Field K] [AddCommGroup V] [Module K V]
    [Fintype M] [Fintype V] [Fintype P] [Fintype C] {g : ℕ}
variable (A : ExceptionalOrigins.Parameters Alphabet (Fin (g+1)) C)
    (clock : RobustClock.Specification (Tag M V g A.B) P C)
    (T : FreeMonoid Alphabet →* M) (ρ : M → (V →ₗ[K] V))
    (β : M → M → (Fin g → M) → V)

omit [Fintype M] [Fintype C] in
lemma snapshot_congr {f f' : ℤ → Alphabet} {s b t : ℤ} (hs : s≤b)
    (he : AgreesOn f f' s b) (hw₀ : 0≤A.w₀)
    (hv : A.Visible s b t (A.anchor f (b-A.endRule.tail) t)) :
    snapshot A T f s b t=snapshot A T f' s b t := by
  have hq := A.anchor_congr hv he
  have hsearch : search A f (A.residue (A.anchor f (b-A.endRule.tail) t-t)) t=
      search A f' (A.residue (A.anchor f' (b-A.endRule.tail) t-t)) t := by
    rw [←hq]
    funext j
    exact A.inner_congr (hv.innerVisible A hw₀ j) he
  apply ClockAffine.Snapshot.ext (product_congr T hs he)
  change factors T f s b _=factors T f' s b _
  rw [←hsearch]
  exact factors_congr T he

lemma update_congr {f f' : ℤ → Alphabet} {s b t : ℤ} (hs : s≤b)
    (he : AgreesOn f f' s b) (hw₀ : 0≤A.w₀)
    (hv : A.Visible s b t (A.anchor f (b-A.endRule.tail) t)) (x : V) :
    update A clock T ρ β f s b t x=update A clock T ρ β f' s b t x := by
  unfold update
  rw [A.anchor_congr hv he,snapshot_congr A T hs he hw₀ hv]

noncomputable def wordUpdate [Nonempty Alphabet] (lag : ℤ) (w : List Alphabet) (x : V) : V :=
  update A clock T ρ β (stream w) 0 w.length lag x

lemma wordUpdate_eq [Nonempty Alphabet] {lag : ℤ} {w : List Alphabet} {f : ℤ → Alphabet}
    (hf : Realizes w 0 f) (hw₀ : 0≤A.w₀)
    (hv : A.Visible 0 w.length lag (A.anchor f (w.length-A.endRule.tail) lag)) (x : V) :
    wordUpdate A clock T ρ β lag w x=update A clock T ρ β f 0 w.length lag x := by
  symm
  apply update_congr A clock T ρ β (Int.natCast_nonneg _) _ hw₀ hv
  simpa only [zero_add] using hf.same (stream_realizes w)

end OuterStream

namespace InnerStream

open WordIntervals LocalMarkers SplitMetadata
variable {Alphabet : Type uAlphabet4} {M : Type uM2} {V : Type uV2} {K : Type uK2} {P : Type uP2} {C : Type uC3} [Monoid M] [Field K] [AddCommGroup V] [Module K V]
    [Fintype M] [Fintype V] [Fintype P] [Fintype C] {g g' : ℕ}
variable (A : ExceptionalOrigins.Parameters Alphabet (Fin (g+1)) C)
    (clock : RobustClock.Specification (Tag M V g A.B) P C)
    (T : FreeMonoid Alphabet →* M) (ρ : M → (V →ₗ[K] V))
    (β : M → M → (Fin g → M) → V) (early : Fin (g'+1) → ℤ)
    (γ : (M → (V × K →ₗ[K] V × K)) → (Fin g' → M) → V × K)

lemma update_congr (hm : Monotone early) (h₀ : early 0=0)
    {f f' : ℤ → Alphabet} {s b t : ℤ} (hb : s+early (Fin.last g')≤b)
    (he : AgreesOn f f' s b) (hw₀ : 0≤A.w₀)
    (hv : A.Visible s b t (A.anchor f (b-A.endRule.tail) t)) (x : V × K) :
    update A clock T ρ β early γ f s b t x=update A clock T ρ β early γ f' s b t x := by
  have hmin (i : Fin (g'+1)) : 0≤early i := by rw [←h₀];exact hm (Fin.zero_le i)
  have hψ := hypothetical_congr A clock T ρ β early (by have := hmin (Fin.last g');omega)
    hb he (A.anchor_congr hv he) (fun j => hv.innerVisible A hw₀ j)
  have hd : (fun i : Fin g' => product T f (s+early i.castSucc) (s+early i.succ))=
      fun i : Fin g' => product T f' (s+early i.castSucc) (s+early i.succ) := by
    funext i
    apply product_congr T (by have := hm (Fin.castSucc_le_succ i);omega)
    intro z hz hz'
    exact he z (by have := hmin i.castSucc;omega) (by have := hm (Fin.le_last i.succ);omega)
  unfold update
  rw [hψ,hd]

noncomputable def wordUpdate [Nonempty Alphabet] (lag : ℤ) (w : List Alphabet) (x : V × K) : V × K :=
  update A clock T ρ β early γ (stream w) 0 w.length lag x

lemma wordUpdate_eq [Nonempty Alphabet] (hm : Monotone early) (h₀ : early 0=0)
    {lag : ℤ} {w : List Alphabet} {f : ℤ → Alphabet} (hb : early (Fin.last g')≤w.length)
    (hf : Realizes w 0 f) (hw₀ : 0≤A.w₀)
    (hv : A.Visible 0 w.length lag (A.anchor f (w.length-A.endRule.tail) lag)) (x : V × K) :
    wordUpdate A clock T ρ β early γ lag w x=update A clock T ρ β early γ f 0 w.length lag x := by
  symm
  apply update_congr A clock T ρ β early γ hm h₀ (by simpa only [zero_add] using hb) _ hw₀ hv
  simpa only [zero_add] using hf.same (stream_realizes w)

end InnerStream

namespace CanonicalEpisodes.Parameters

open WordIntervals
variable {Alphabet : Type uAlphabet5} (C : CanonicalEpisodes.Parameters Alphabet)

lemma subset_height [Finite Alphabet] {L : Language Alphabet} (lag : ℤ)
    (hreg : L.IsRegular) (hL : L≤C.complete lag) : HasHeightAtMost L 1 := by
  apply C.ending_height L hreg lag.natAbs
  intro w hw
  obtain ⟨f,hf,_,he⟩ := hL hw
  exact ⟨f,lag,hf,by simp only [Int.natCast_natAbs];exact le_rfl,he⟩

lemma complete_height [Finite Alphabet] (lag : ℤ) : HasHeightAtMost (C.complete lag) 1 :=
  C.subset_height lag (C.complete_regular lag) le_rfl

end CanonicalEpisodes.Parameters

namespace ExceptionalOrigins.Parameters

variable {Alphabet : Type uAlphabet6} {J : Type uJ2} {C : Type uC4} (A : ExceptionalOrigins.Parameters Alphabet J C)

def failedDomain (lag : ℤ) : Language Alphabet := A.endRule.complete lag ⊓ A.failedLanguage lag

lemma failedDomain_subset (lag : ℤ) : A.failedDomain lag≤A.endRule.complete lag := inf_le_left

lemma failedDomain_height [Finite Alphabet] [Fintype J] (n : ℕ) (hn : 0<n)
    (hφ : A.φ (n:ℤ)=0) (hw₀ : 0≤A.w₀) (lag : ℤ) : HasHeightAtMost (A.failedDomain lag) 1 :=
  A.endRule.subset_height lag ((A.endRule.complete_regular lag).inf (A.failed_regular n hn hφ hw₀ lag))
    (A.failedDomain_subset lag)

end ExceptionalOrigins.Parameters

namespace WordIntervals

variable {Alphabet : Type uAlphabet7}

lemma realizes_cut {w : List Alphabet} {f : ℤ → Alphabet} (hf : Realizes w 0 f)
    {k : ℤ} (hk : 0≤k) (hkb : k≤w.length) :
    ∃ u v : List Alphabet, w=u++v ∧ (u.length:ℤ)=k ∧ Realizes u 0 f ∧ Realizes v k f := by
  let u := w.take k.toNat
  let v := w.drop k.toNat
  have hw : w=u++v := (List.take_append_drop k.toNat w).symm
  have hu : (u.length:ℤ)=k := by simp only [u,List.length_take];omega
  have hh : Realizes (u++v) 0 f := hw ▸ hf
  refine ⟨u,v,hw,hu,hh.append_left,?_⟩
  simpa only [zero_add,hu] using hh.append_right

lemma prefix_eq_of_length {u v w : List Alphabet} (hu : u<+:w) (hv : v<+:w)
    (hl : u.length=v.length) : u=v := by
  rcases List.prefix_or_prefix_of_prefix hu hv with h|h
  · exact h.eq_of_length hl
  · exact (h.eq_of_length hl.symm).symm

end WordIntervals

end GeneralizedStarHeight

end OAI