Imports
/-
Copyright (c) 2026 Google LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
-/
module
public import Cryptids.Riemann95Definition
public import Cryptids.ReductionSupport.Riemann95.ControllerSchema95Decoder and tape correctness
@[expose] public sectionRecursive decoder
sectionRecursive decoder prefix for the 95-state machine. This proves arbitrary repetition and arbitrary suffix behavior of the read-preserving rightward parser, not the whole machine or caller-language closure.
namespace ConjectureMachines.Riemann95.Parseropen Turingdef walkInternal (q : Fin 95) : List (Fin 2) → Option (Fin 95)
| [] => some q
| b :: bs =>
match ConjectureMachines.Riemann95.machine.transition q b with
| some (w, .right, next) =>
if w = b then walkInternal next bs else none
| _ => nonetheorem walkInternal_append (q : Fin 95) (a b : List (Fin 2)) :
walkInternal q (a ++ b) = (walkInternal q a).bind (fun r => walkInternal r b) := q:Fin 95a:List (Fin 2)b:List (Fin 2)⊢ walkInternal q (a ++ b) = (walkInternal q a).bind fun r ↦ walkInternal r b
induction a generalizing q with
b:List (Fin 2)q:Fin 95⊢ walkInternal q ([] ++ b) = (walkInternal q []).bind fun r ↦ walkInternal r b All goals completed! 🐙
b:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95⊢ walkInternal q (x :: xs ++ b) = (walkInternal q (x :: xs)).bind fun r ↦ walkInternal r b
b:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95⊢ (match machine.transition q x with
| some (w, Dir.right, next) => if w = x then walkInternal next (xs ++ b) else none
| x => none) =
(match machine.transition q x with
| some (w, Dir.right, next) => if w = x then walkInternal next xs else none
| x => none).bind
fun r ↦ walkInternal r b
cases ht : ConjectureMachines.Riemann95.machine.transition q x with
b:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95ht:machine.transition q x = none⊢ (match none with
| some (w, Dir.right, next) => if w = x then walkInternal next (xs ++ b) else none
| x => none) =
(match none with
| some (w, Dir.right, next) => if w = x then walkInternal next xs else none
| x => none).bind
fun r ↦ walkInternal r b All goals completed! 🐙
b:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95triple:Fin 2 × Dir × Fin 95ht:machine.transition q x = some triple⊢ (match some triple with
| some (w, Dir.right, next) => if w = x then walkInternal next (xs ++ b) else none
| x => none) =
(match some triple with
| some (w, Dir.right, next) => if w = x then walkInternal next xs else none
| x => none).bind
fun r ↦ walkInternal r b
b:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95w:Fin 2dir:Dirnext:Fin 95ht:machine.transition q x = some (w, dir, next)⊢ (match some (w, dir, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next (xs ++ b) else none
| x => none) =
(match some (w, dir, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next xs else none
| x => none).bind
fun r ↦ walkInternal r b
cases dir with
b:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95w:Fin 2next:Fin 95ht:machine.transition q x = some (w, Dir.left, next)⊢ (match some (w, Dir.left, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next (xs ++ b) else none
| x => none) =
(match some (w, Dir.left, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next xs else none
| x => none).bind
fun r ↦ walkInternal r b All goals completed! 🐙
b:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95w:Fin 2next:Fin 95ht:machine.transition q x = some (w, Dir.right, next)⊢ (match some (w, Dir.right, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next (xs ++ b) else none
| x => none) =
(match some (w, Dir.right, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next xs else none
| x => none).bind
fun r ↦ walkInternal r b
b:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95w:Fin 2next:Fin 95ht:machine.transition q x = some (w, Dir.right, next)h:w = x⊢ (match some (w, Dir.right, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next (xs ++ b) else none
| x => none) =
(match some (w, Dir.right, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next xs else none
| x => none).bind
fun r ↦ walkInternal r bb:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95w:Fin 2next:Fin 95ht:machine.transition q x = some (w, Dir.right, next)h:¬w = x⊢ (match some (w, Dir.right, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next (xs ++ b) else none
| x => none) =
(match some (w, Dir.right, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next xs else none
| x => none).bind
fun r ↦ walkInternal r b
b:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95w:Fin 2next:Fin 95ht:machine.transition q x = some (w, Dir.right, next)h:w = x⊢ (match some (w, Dir.right, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next (xs ++ b) else none
| x => none) =
(match some (w, Dir.right, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next xs else none
| x => none).bind
fun r ↦ walkInternal r b All goals completed! 🐙
b:List (Fin 2)x:Fin 2xs:List (Fin 2)ih:∀ (q : Fin 95), walkInternal q (xs ++ b) = (walkInternal q xs).bind fun r ↦ walkInternal r bq:Fin 95w:Fin 2next:Fin 95ht:machine.transition q x = some (w, Dir.right, next)h:¬w = x⊢ (match some (w, Dir.right, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next (xs ++ b) else none
| x => none) =
(match some (w, Dir.right, next) with
| some (w, Dir.right, next) => if w = x then walkInternal next xs else none
| x => none).bind
fun r ↦ walkInternal r b All goals completed! 🐙def prefixBits : List (Fin 2) := [1,1,1,1,1,0]def block : List (Fin 2) := [1,1,1,1,0]def repetitions : Nat → List (Fin 2)
| 0 => []
| n + 1 => block ++ repetitions ntheorem actual_prefix : walkInternal 15 prefixBits = some 46 := ⊢ walkInternal 15 prefixBits = some 46 All goals completed! 🐙theorem actual_cycle : walkInternal 46 block = some 46 := ⊢ walkInternal 46 block = some 46 All goals completed! 🐙theorem repetitions_parse (n : Nat) (tail : List (Fin 2)) :
walkInternal 46 (repetitions n ++ tail) = walkInternal 46 tail := n:ℕtail:List (Fin 2)⊢ walkInternal 46 (repetitions n ++ tail) = walkInternal 46 tail
induction n with
tail:List (Fin 2)⊢ walkInternal 46 (repetitions 0 ++ tail) = walkInternal 46 tail All goals completed! 🐙
tail:List (Fin 2)n:ℕih:walkInternal 46 (repetitions n ++ tail) = walkInternal 46 tail⊢ walkInternal 46 (repetitions (n + 1) ++ tail) = walkInternal 46 tail
All goals completed! 🐙theorem prefix_parse (n : Nat) (tail : List (Fin 2)) :
walkInternal 15 (prefixBits ++ repetitions n ++ tail) = walkInternal 46 tail := by n:ℕtail:List (Fin 2)⊢ walkInternal 15 (prefixBits ++ repetitions n ++ tail) = walkInternal 46 tail
rw [List.append_assoc, n:ℕtail:List (Fin 2)⊢ walkInternal 15 (prefixBits ++ (repetitions n ++ tail)) = walkInternal 46 tail walkInternal_append, n:ℕtail:List (Fin 2)⊢ ((walkInternal 15 prefixBits).bind fun r ↦ walkInternal r (repetitions n ++ tail)) = walkInternal 46 tail actual_prefix, n:ℕtail:List (Fin 2)⊢ ((some 46).bind fun r ↦ walkInternal r (repetitions n ++ tail)) = walkInternal 46 tail
Option.bind_some, n:ℕtail:List (Fin 2)⊢ walkInternal 46 (repetitions n ++ tail) = walkInternal 46 tail repetitions_parse n:ℕtail:List (Fin 2)⊢ walkInternal 46 tail = walkInternal 46 tail] All goals completed! 🐙end ConjectureMachines.Riemann95.ParserendTape interpretation
sectionnamespace ConjectureMachines.Riemann95.Parseropen Turing ConjectureMachinesopen ConjectureMachines.Riemann95A successful read-preserving parser walk is its exact physical tape traversal.
theorem walkInternal_nSteps (bits : List (Fin 2)) (q q' : Fin 95)
(L R : ListBlank (Fin 2)) (hwalk : walkInternal q bits = some q') :
nSteps bits.length ⟨q, Tape.mk' L (ListBlank.append bits R)⟩ =
some ⟨q', Tape.mk' (ListBlank.append bits.reverse L) R⟩ := by bits:List (Fin 2)q:Fin 95q':Fin 95L:ListBlank (Fin 2)R:ListBlank (Fin 2)hwalk:walkInternal q bits = some q'⊢ nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }
induction bits generalizing q q' L with
| nil => nil R:ListBlank (Fin 2)q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:walkInternal q [] = some q'⊢ nSteps [].length { state := q, tape := Tape.mk' L (ListBlank.append [] R) } =
some { state := q', tape := Tape.mk' (ListBlank.append [].reverse L) R }
simp only [walkInternal, Option.some.injEq] at hwalk nil R:ListBlank (Fin 2)q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:q = q'⊢ nSteps [].length { state := q, tape := Tape.mk' L (ListBlank.append [] R) } =
some { state := q', tape := Tape.mk' (ListBlank.append [].reverse L) R }
subst q' nil R:ListBlank (Fin 2)q:Fin 95L:ListBlank (Fin 2)⊢ nSteps [].length { state := q, tape := Tape.mk' L (ListBlank.append [] R) } =
some { state := q, tape := Tape.mk' (ListBlank.append [].reverse L) R }
rfl All goals completed! 🐙
| cons bit bits ih => cons R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:walkInternal q (bit :: bits) = some q'⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }
rw [walkInternal cons R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }] at hwalk cons R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }
cases ht : machine.transition q bit with
| none => cons.none R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'ht:machine.transition q bit = none⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R } simp only [ht] at hwalk cons.none R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)ht:machine.transition q bit = nonehwalk:none = some q'⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }; cases hwalk All goals completed! 🐙
| some triple => cons.some R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'triple:Fin 2 × Dir × Fin 95ht:machine.transition q bit = some triple⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }
rcases triple with ⟨w, direction, next⟩ cons.some R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'w:Fin 2direction:Dirnext:Fin 95ht:machine.transition q bit = some (w, direction, next)⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }
cases direction with
| left => cons.some.left R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'w:Fin 2next:Fin 95ht:machine.transition q bit = some (w, Dir.left, next)⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R } simp only [ht] at hwalk cons.some.left R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)w:Fin 2next:Fin 95ht:machine.transition q bit = some (w, Dir.left, next)hwalk:none = some q'⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }; cases hwalk All goals completed! 🐙
| right => cons.some.right R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'w:Fin 2next:Fin 95ht:machine.transition q bit = some (w, Dir.right, next)⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }
by_cases hw : w = bit pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'w:Fin 2next:Fin 95ht:machine.transition q bit = some (w, Dir.right, next)hw:w = bit⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }neg R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'w:Fin 2next:Fin 95ht:machine.transition q bit = some (w, Dir.right, next)hw:¬w = bit⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }
· pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'w:Fin 2next:Fin 95ht:machine.transition q bit = some (w, Dir.right, next)hw:w = bit⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R } subst w pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'next:Fin 95ht:machine.transition q bit = some (bit, Dir.right, next)⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }
simp only [ht, ite_true] at hwalk pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)next:Fin 95ht:machine.transition q bit = some (bit, Dir.right, next)hwalk:walkInternal next bits = some q'⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }
have hstep : step machine
⟨q, Tape.mk' L (ListBlank.cons bit (ListBlank.append bits R))⟩ =
some ⟨next, Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R)⟩ := by bits:List (Fin 2)q:Fin 95q':Fin 95L:ListBlank (Fin 2)R:ListBlank (Fin 2)hwalk:walkInternal q bits = some q'⊢ nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }
simp [step, ht, Tape.mk', Tape.write, Tape.move] pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)next:Fin 95ht:machine.transition q bit = some (bit, Dir.right, next)hwalk:walkInternal next bits = some q'hstep:step machine { state := q, tape := Tape.mk' L (ListBlank.cons bit (ListBlank.append bits R)) } =
some { state := next, tape := Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R) }⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }
rw [List.length_cons, pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)next:Fin 95ht:machine.transition q bit = some (bit, Dir.right, next)hwalk:walkInternal next bits = some q'hstep:step machine { state := q, tape := Tape.mk' L (ListBlank.cons bit (ListBlank.append bits R)) } =
some { state := next, tape := Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R) }⊢ nSteps (bits.length + 1) { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R } nSteps, pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)next:Fin 95ht:machine.transition q bit = some (bit, Dir.right, next)hwalk:walkInternal next bits = some q'hstep:step machine { state := q, tape := Tape.mk' L (ListBlank.cons bit (ListBlank.append bits R)) } =
some { state := next, tape := Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R) }⊢ (step machine { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) }).bind (nSteps bits.length) =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R } ListBlank.append, pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)next:Fin 95ht:machine.transition q bit = some (bit, Dir.right, next)hwalk:walkInternal next bits = some q'hstep:step machine { state := q, tape := Tape.mk' L (ListBlank.cons bit (ListBlank.append bits R)) } =
some { state := next, tape := Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R) }⊢ (step machine { state := q, tape := Tape.mk' L (ListBlank.cons bit (ListBlank.append bits R)) }).bind
(nSteps bits.length) =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R } hstep, pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)next:Fin 95ht:machine.transition q bit = some (bit, Dir.right, next)hwalk:walkInternal next bits = some q'hstep:step machine { state := q, tape := Tape.mk' L (ListBlank.cons bit (ListBlank.append bits R)) } =
some { state := next, tape := Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R) }⊢ (some { state := next, tape := Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R) }).bind (nSteps bits.length) =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R } Option.bind_some pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)next:Fin 95ht:machine.transition q bit = some (bit, Dir.right, next)hwalk:walkInternal next bits = some q'hstep:step machine { state := q, tape := Tape.mk' L (ListBlank.cons bit (ListBlank.append bits R)) } =
some { state := next, tape := Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R) }⊢ nSteps bits.length { state := next, tape := Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }] pos R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)next:Fin 95ht:machine.transition q bit = some (bit, Dir.right, next)hwalk:walkInternal next bits = some q'hstep:step machine { state := q, tape := Tape.mk' L (ListBlank.cons bit (ListBlank.append bits R)) } =
some { state := next, tape := Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R) }⊢ nSteps bits.length { state := next, tape := Tape.mk' (ListBlank.cons bit L) (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }
simpa only [List.reverse_cons, ListBlank.append_assoc, ListBlank.append] using
ih next q' (ListBlank.cons bit L) hwalk All goals completed! 🐙
· neg R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)hwalk:(match machine.transition q bit with
| some (w, Dir.right, next) => if w = bit then walkInternal next bits else none
| x => none) =
some q'w:Fin 2next:Fin 95ht:machine.transition q bit = some (w, Dir.right, next)hw:¬w = bit⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R } simp only [ht, hw, ite_false] at hwalk neg R:ListBlank (Fin 2)bit:Fin 2bits:List (Fin 2)ih:∀ (q q' : Fin 95) (L : ListBlank (Fin 2)),
walkInternal q bits = some q' →
nSteps bits.length { state := q, tape := Tape.mk' L (ListBlank.append bits R) } =
some { state := q', tape := Tape.mk' (ListBlank.append bits.reverse L) R }q:Fin 95q':Fin 95L:ListBlank (Fin 2)w:Fin 2next:Fin 95ht:machine.transition q bit = some (w, Dir.right, next)hw:¬w = bithwalk:none = some q'⊢ nSteps (bit :: bits).length { state := q, tape := Tape.mk' L (ListBlank.append (bit :: bits) R) } =
some { state := q', tape := Tape.mk' (ListBlank.append (bit :: bits).reverse L) R }; cases hwalk All goals completed! 🐙end ConjectureMachines.Riemann95.ParserendDecoder correctness
sectionnamespace ConjectureMachines.Riemann95.Parseropen Turing ConjectureMachinesopen ConjectureMachines.Riemann95theorem repetitions_snoc (d : Nat) : repetitions (d + 1) = repetitions d ++ block := by d:ℕ⊢ repetitions (d + 1) = repetitions d ++ block
induction d with
| zero => zero ⊢ repetitions (0 + 1) = repetitions 0 ++ block rfl All goals completed! 🐙
| succ d ih => succ d:ℕih:repetitions (d + 1) = repetitions d ++ block⊢ repetitions (d + 1 + 1) = repetitions (d + 1) ++ block
change block ++ repetitions (d + 1) = (block ++ repetitions d) ++ block succ d:ℕih:repetitions (d + 1) = repetitions d ++ block⊢ block ++ repetitions (d + 1) = block ++ repetitions d ++ block
rw [ih, succ d:ℕih:repetitions (d + 1) = repetitions d ++ block⊢ block ++ (repetitions d ++ block) = block ++ repetitions d ++ block List.append_assoc succ d:ℕih:repetitions (d + 1) = repetitions d ++ block⊢ block ++ (repetitions d ++ block) = block ++ (repetitions d ++ block)] All goals completed! 🐙theorem callerPrefix_eq (d : Nat) : Schema.callerPrefix d = prefixBits ++ repetitions d := by d:ℕ⊢ Schema.callerPrefix d = prefixBits ++ repetitions d
induction d with
| zero => zero ⊢ Schema.callerPrefix 0 = prefixBits ++ repetitions 0 rfl All goals completed! 🐙
| succ d ih => succ d:ℕih:Schema.callerPrefix d = prefixBits ++ repetitions d⊢ Schema.callerPrefix (d + 1) = prefixBits ++ repetitions (d + 1)
rw [Schema.callerPrefix, succ d:ℕih:Schema.callerPrefix d = prefixBits ++ repetitions d⊢ Schema.callerPrefix d ++ [1, 1, 1, 1, 0] = prefixBits ++ repetitions (d + 1) ih, succ d:ℕih:Schema.callerPrefix d = prefixBits ++ repetitions d⊢ prefixBits ++ repetitions d ++ [1, 1, 1, 1, 0] = prefixBits ++ repetitions (d + 1) repetitions_snoc, succ d:ℕih:Schema.callerPrefix d = prefixBits ++ repetitions d⊢ prefixBits ++ repetitions d ++ [1, 1, 1, 1, 0] = prefixBits ++ (repetitions d ++ block) ← List.append_assoc succ d:ℕih:Schema.callerPrefix d = prefixBits ++ repetitions d⊢ prefixBits ++ repetitions d ++ [1, 1, 1, 1, 0] = prefixBits ++ repetitions d ++ block] succ d:ℕih:Schema.callerPrefix d = prefixBits ++ repetitions d⊢ prefixBits ++ repetitions d ++ [1, 1, 1, 1, 0] = prefixBits ++ repetitions d ++ block
rfl All goals completed! 🐙def localTerminal (s : Fin 22) : Fin 95 :=
(walkInternal 46 (Schema.localWalkSuffix s)).getD 0def outsideTerminal (s : Fin 97) : Fin 95 :=
(walkInternal 15 (Schema.outsideWalk s)).getD 0theorem localTerminal_walk : ∀ s : Fin 22,
walkInternal 46 (Schema.localWalkSuffix s) = some (localTerminal s) := by ⊢ ∀ (s : Fin 22), walkInternal 46 (Schema.localWalkSuffix s) = some (localTerminal s)
decide +kernel All goals completed! 🐙theorem outsideTerminal_walk : ∀ s : Fin 97,
walkInternal 15 (Schema.outsideWalk s) = some (outsideTerminal s) := by ⊢ ∀ (s : Fin 97), walkInternal 15 (Schema.outsideWalk s) = some (outsideTerminal s)
decide +kernel All goals completed! 🐙Every local suffix follows the exact physical decoder at every recursion depth.
theorem localWalk_parse (d : Nat) (s : Fin 22) :
walkInternal 15 (Schema.localWalk d s) = some (localTerminal s) := by d:ℕs:Fin 22⊢ walkInternal 15 (Schema.localWalk d s) = some (localTerminal s)
rw [Schema.localWalk, d:ℕs:Fin 22⊢ walkInternal 15 (Schema.callerPrefix d ++ Schema.localWalkSuffix s) = some (localTerminal s) callerPrefix_eq, d:ℕs:Fin 22⊢ walkInternal 15 (prefixBits ++ repetitions d ++ Schema.localWalkSuffix s) = some (localTerminal s) prefix_parse d:ℕs:Fin 22⊢ walkInternal 46 (Schema.localWalkSuffix s) = some (localTerminal s)] d:ℕs:Fin 22⊢ walkInternal 46 (Schema.localWalkSuffix s) = some (localTerminal s)
exact localTerminal_walk s All goals completed! 🐙Entry inspects the mandatory zero after the regular prefix and reaches native DECj.
theorem entryWalk_parse (d : Nat) :
walkInternal 15 (Schema.callerPrefix d ++ [0]) = some 58 := by d:ℕ⊢ walkInternal 15 (Schema.callerPrefix d ++ [0]) = some 58
rw [callerPrefix_eq, d:ℕ⊢ walkInternal 15 (prefixBits ++ repetitions d ++ [0]) = some 58 prefix_parse d:ℕ⊢ walkInternal 46 [0] = some 58] d:ℕ⊢ walkInternal 46 [0] = some 58
rfl All goals completed! 🐙end ConjectureMachines.Riemann95.Parserend