Imports
/-
Copyright (c) 2026 Google LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
-/
module
public import BusyBeaver.Basic
Spatial Word-Vocabulary Run-Length Simulation (BusyBeaver.WordRLE)
Reusable, machine-polymorphic infrastructure for kernel-verified Turing machine simulation over run-length-encoded (RLE) stacks of finite spatial words:
withNat — Call-by-value ℕ normalizer (withNat n k = k n) forcing intermediate arithmetic
results to weak-head normal form in Lean's C++ kernel.
BTree & NatTrie — Logarithmic-depth tree and radix-trie containers for compact certificates.
dirCfg & WordExit — Translation-invariant directed configurations (Cfg.headRight /
Cfg.headLeft over ListBlank Γ) and verified local word-exit transitions.
simWord & sweepWord_sound — Certified single-word zipper execution and k-copy homogeneous
sweeps (ReachesIn M (dt * k) ...).
simSubwords — Certified composite-word exit computation from a verified base-word exit table.
EntryCfg & EntryReaches — Concrete RLE stack simulator with pluggable macro-transition
hooks and O(1) chunked certificate composition.
@[expose] public sectionnamespace BusyBeaver.WordRLEopen Turing
Call-by-Value Kernel Normalizer (withNat)
Force n : ℕ to weak-head normal form (0 or Nat.succ m) before passing it to k,
preventing call-by-name thunk accumulation during decide +kernel reduction while remaining
definitionally equal to k n on numerals and provably k n for all n.
@[inline]
def withNat {α : Type*} (n : ℕ) (k : ℕ → α) : α :=
match n with
| 0 => k 0
| m + 1 => k (Nat.succ m)@[simp]
theorem withNat_eq {α : Type*} (n : ℕ) (k : ℕ → α) : withNat n k = k n := α:Type u_1n:ℕk:ℕ → α⊢ withNat n k = k n
α:Type u_1k:ℕ → α⊢ withNat 0 k = k 0α:Type u_1k:ℕ → αn✝:ℕ⊢ withNat (n✝ + 1) k = k (n✝ + 1) α:Type u_1k:ℕ → α⊢ withNat 0 k = k 0α:Type u_1k:ℕ → αn✝:ℕ⊢ withNat (n✝ + 1) k = k (n✝ + 1) All goals completed! 🐙
Force b : Bool to weak-head normal form (true or false) before passing it to k.
@[inline]
def withBool {α : Type*} (b : Bool) (k : Bool → α) : α :=
if b then k true else k false@[simp]
theorem withBool_eq {α : Type*} (b : Bool) (k : Bool → α) : withBool b k = k b := α:Type u_1b:Boolk:Bool → α⊢ withBool b k = k b
α:Type u_1k:Bool → α⊢ withBool false k = k falseα:Type u_1k:Bool → α⊢ withBool true k = k true α:Type u_1k:Bool → α⊢ withBool false k = k falseα:Type u_1k:Bool → α⊢ withBool true k = k true All goals completed! 🐙
Balanced Binary Trees (BTree) and ℕ-Keyed Radix Tries (NatTrie)
Balanced binary tree keeping certificate expression depth logarithmic (O(log N)).
inductive BTree (α : Type) whereEmpty tree.
| empty : BTree αSingle element leaf.
| leaf (val : α) : BTree αInternal binary node.
| node (left right : BTree α) : BTree α
deriving DecidableEq, Inhabited
Convert a BTree α to a List α in left-to-right order with accumulator acc.
def BTree.toListAcc {α : Type} : BTree α → List α → List α
| .empty, acc => acc
| .leaf x, acc => x :: acc
| .node l r, acc => l.toListAcc (r.toListAcc acc)
Convert a BTree α to a List α in left-to-right order.
def BTree.toList {α : Type} (t : BTree α) : List α :=
t.toListAcc []
Little-endian binary radix trie keyed by ℕ, enabling O(log N) constructor-match lookups
inside the Lean kernel with zero rebuild overhead when emitted directly as a certificate tree.
inductive NatTrie (α : Type) whereEmpty subtrie.
| leaf : NatTrie α
Binary trie node with optional value at key 0 and even/odd child subtries.
| node (val : Option α) (even odd : NatTrie α) : NatTrie α
deriving DecidableEq, Inhabitednamespace NatTrie
Look up key n in radix trie t.
def find? {α : Type} : NatTrie α → ℕ → Option α
| .leaf, _ => none
| .node v _ _, 0 => v
| .node _ l r, n + 1 =>
let m := n + 1
if Nat.beq (m % 2) 0 then find? l (m / 2) else find? r (m / 2)Fuel-bounded radix-trie insertion helper.
def insFuel {α : Type} : ℕ → NatTrie α → ℕ → α → NatTrie α
| 0, t, _, _ => t
| _ + 1, .leaf, 0, val => .node (some val) .leaf .leaf
| fuel + 1, .leaf, n + 1, val =>
let m := n + 1
if Nat.beq (m % 2) 0 then .node none (insFuel fuel .leaf (m / 2) val) .leaf
else .node none .leaf (insFuel fuel .leaf (m / 2) val)
| _ + 1, .node _ l r, 0, val => .node (some val) l r
| fuel + 1, .node v l r, n + 1, val =>
let m := n + 1
if Nat.beq (m % 2) 0 then .node v (insFuel fuel l (m / 2) val) r
else .node v l (insFuel fuel r (m / 2) val)
Insert (k, val) into radix trie t (supports keys up to 2^32 - 1).
def insert {α : Type} (t : NatTrie α) (k : ℕ) (val : α) : NatTrie α :=
insFuel 33 t k val
Check predicate p key val on every stored entry in t, reconstructing keys as
keyPrefix + localKey * bitMul.
def checkAll {α : Type} (p : ℕ → α → Bool) (keyPrefix bitMul : ℕ) : NatTrie α → Bool
| .leaf => true
| .node val? l r =>
let selfOk := match val? with | none => true | some v => p keyPrefix v
selfOk &&
checkAll p keyPrefix (bitMul * 2) l &&
checkAll p (keyPrefix + bitMul) (bitMul * 2) rtheorem checkAll_node_iff {α : Type} (p : ℕ → α → Bool) (keyPrefix bitMul : ℕ)
(val? : Option α) (l r : NatTrie α) :
checkAll p keyPrefix bitMul (.node val? l r) = true ↔
(match val? with | none => true | some v => p keyPrefix v) = true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧
checkAll p (keyPrefix + bitMul) (bitMul * 2) r = true := α:Typep:ℕ → α → BoolkeyPrefix:ℕbitMul:ℕval?:Option αl:NatTrie αr:NatTrie α⊢ checkAll p keyPrefix bitMul (node val? l r) = true ↔
(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = true
All goals completed! 🐙
Any value found via NatTrie.find? in a checkAll-verified subtrie satisfies p.
theorem checkAll_find? {α : Type} {p : ℕ → α → Bool} :
∀ (t : NatTrie α) (keyPrefix bitMul n : ℕ) (val : α),
checkAll p keyPrefix bitMul t = true →
t.find? n = some val →
p (keyPrefix + n * bitMul) val = true
α:Typep:ℕ → α → Boolx✝⁴:ℕx✝³:ℕx✝²:ℕx✝¹:αx✝:checkAll p x✝⁴ x✝³ leaf = truehf:leaf.find? x✝² = some x✝¹⊢ p (x✝⁴ + x✝² * x✝³) x✝¹ = true α:Typep:ℕ → α → Boolx✝⁴:ℕx✝³:ℕx✝²:ℕx✝¹:αx✝:checkAll p x✝⁴ x✝³ leaf = truehf:leaf.find? x✝² = some x✝¹⊢ p (x✝⁴ + x✝² * x✝³) x✝¹ = true All goals completed! 🐙
α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕval:αhc:checkAll p keyPrefix bitMul (node val? l r) = truehf:(node val? l r).find? 0 = some val⊢ p (keyPrefix + 0 * bitMul) val = true α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕval:αhc:checkAll p keyPrefix bitMul (node val? l r) = truehf:(node val? l r).find? 0 = some val⊢ p (keyPrefix + 0 * bitMul) val = true
α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehf:(node val? l r).find? 0 = some val⊢ p (keyPrefix + 0 * bitMul) val = true
simp only [find?] at hf α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehf:val? = some val⊢ p (keyPrefix + 0 * bitMul) val = true
subst hf α:Typep:ℕ → α → Booll:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕval:αhc:(match some val with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = true⊢ p (keyPrefix + 0 * bitMul) val = true
simpa using hc.1 All goals completed! 🐙
| .node val? l r, keyPrefix, bitMul, n + 1, val, hc, hf => α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:checkAll p keyPrefix bitMul (node val? l r) = truehf:(node val? l r).find? (n + 1) = some val⊢ p (keyPrefix + (n + 1) * bitMul) val = true by α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:checkAll p keyPrefix bitMul (node val? l r) = truehf:(node val? l r).find? (n + 1) = some val⊢ p (keyPrefix + (n + 1) * bitMul) val = true
rw [checkAll_node_iff α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehf:(node val? l r).find? (n + 1) = some val⊢ p (keyPrefix + (n + 1) * bitMul) val = true] at hc α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehf:(node val? l r).find? (n + 1) = some val⊢ p (keyPrefix + (n + 1) * bitMul) val = true
simp only [find?] at hf α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehf:(if ((n + 1) % 2).beq 0 = true then l.find? ((n + 1) / 2) else r.find? ((n + 1) / 2)) = some val⊢ p (keyPrefix + (n + 1) * bitMul) val = true
by_cases hev : Nat.beq ((n + 1) % 2) 0 = true pos α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehf:(if ((n + 1) % 2).beq 0 = true then l.find? ((n + 1) / 2) else r.find? ((n + 1) / 2)) = some valhev:((n + 1) % 2).beq 0 = true⊢ p (keyPrefix + (n + 1) * bitMul) val = trueneg α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehf:(if ((n + 1) % 2).beq 0 = true then l.find? ((n + 1) / 2) else r.find? ((n + 1) / 2)) = some valhev:¬((n + 1) % 2).beq 0 = true⊢ p (keyPrefix + (n + 1) * bitMul) val = true
· pos α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehf:(if ((n + 1) % 2).beq 0 = true then l.find? ((n + 1) / 2) else r.find? ((n + 1) / 2)) = some valhev:((n + 1) % 2).beq 0 = true⊢ p (keyPrefix + (n + 1) * bitMul) val = true simp only [hev, ↓reduceIte] at hf pos α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some val⊢ p (keyPrefix + (n + 1) * bitMul) val = true
have hmod : (n + 1) % 2 = 0 := Nat.eq_of_beq_eq_true hev pos α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 0⊢ p (keyPrefix + (n + 1) * bitMul) val = true
have ih := checkAll_find? l keyPrefix (bitMul * 2) ((n + 1) / 2) val hc.2.1 hf pos α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 0ih:p (keyPrefix + (n + 1) / 2 * (bitMul * 2)) val = true⊢ p (keyPrefix + (n + 1) * bitMul) val = true
have hkey : keyPrefix + (n + 1) / 2 * (bitMul * 2) = keyPrefix + (n + 1) * bitMul := by
have hdiv : (n + 1) / 2 * 2 = n + 1 := by α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:checkAll p keyPrefix bitMul (node val? l r) = truehf:(node val? l r).find? (n + 1) = some val⊢ p (keyPrefix + (n + 1) * bitMul) val = true omega α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 0ih:p (keyPrefix + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:(n + 1) / 2 * 2 = n + 1⊢ keyPrefix + (n + 1) / 2 * (bitMul * 2) = keyPrefix + (n + 1) * bitMul
rw [Nat.mul_comm bitMul 2, α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 0ih:p (keyPrefix + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:(n + 1) / 2 * 2 = n + 1⊢ keyPrefix + (n + 1) / 2 * (2 * bitMul) = keyPrefix + (n + 1) * bitMul ← Nat.mul_assoc, α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 0ih:p (keyPrefix + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:(n + 1) / 2 * 2 = n + 1⊢ keyPrefix + (n + 1) / 2 * 2 * bitMul = keyPrefix + (n + 1) * bitMul Nat.mul_comm ((n + 1) / 2) 2 α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 0ih:p (keyPrefix + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:(n + 1) / 2 * 2 = n + 1⊢ keyPrefix + 2 * ((n + 1) / 2) * bitMul = keyPrefix + (n + 1) * bitMul] α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 0ih:p (keyPrefix + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:(n + 1) / 2 * 2 = n + 1⊢ keyPrefix + 2 * ((n + 1) / 2) * bitMul = keyPrefix + (n + 1) * bitMul
have h2 : 2 * ((n + 1) / 2) = n + 1 := by α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:checkAll p keyPrefix bitMul (node val? l r) = truehf:(node val? l r).find? (n + 1) = some val⊢ p (keyPrefix + (n + 1) * bitMul) val = true omega α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 0ih:p (keyPrefix + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:(n + 1) / 2 * 2 = n + 1h2:2 * ((n + 1) / 2) = n + 1⊢ keyPrefix + 2 * ((n + 1) / 2) * bitMul = keyPrefix + (n + 1) * bitMul
rw [h2 α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 0ih:p (keyPrefix + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:(n + 1) / 2 * 2 = n + 1h2:2 * ((n + 1) / 2) = n + 1⊢ keyPrefix + (n + 1) * bitMul = keyPrefix + (n + 1) * bitMul] pos α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:((n + 1) % 2).beq 0 = truehf:l.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 0ih:p (keyPrefix + (n + 1) / 2 * (bitMul * 2)) val = truehkey:keyPrefix + (n + 1) / 2 * (bitMul * 2) = keyPrefix + (n + 1) * bitMul⊢ p (keyPrefix + (n + 1) * bitMul) val = true
rwa [hkey] at ih All goals completed! 🐙
· neg α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehf:(if ((n + 1) % 2).beq 0 = true then l.find? ((n + 1) / 2) else r.find? ((n + 1) / 2)) = some valhev:¬((n + 1) % 2).beq 0 = true⊢ p (keyPrefix + (n + 1) * bitMul) val = true have hne : Nat.beq ((n + 1) % 2) 0 = false := Bool.eq_false_iff.mpr hev neg α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehf:(if ((n + 1) % 2).beq 0 = true then l.find? ((n + 1) / 2) else r.find? ((n + 1) / 2)) = some valhev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = false⊢ p (keyPrefix + (n + 1) * bitMul) val = true
simp only [hne, Bool.false_eq_true, ↓reduceIte] at hf neg α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some val⊢ p (keyPrefix + (n + 1) * bitMul) val = true
have hmod : (n + 1) % 2 = 1 := by
have hnz : (n + 1) % 2 ≠ 0 := fun h0 ↦ hev (by α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valh0:(n + 1) % 2 = 0⊢ ((n + 1) % 2).beq 0 = true rw [h0 α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valh0:(n + 1) % 2 = 0⊢ Nat.beq 0 0 = true] α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valh0:(n + 1) % 2 = 0⊢ Nat.beq 0 0 = true; rfl All goals completed! 🐙) α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhnz:(n + 1) % 2 ≠ 0⊢ (n + 1) % 2 = 1
omega neg α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1⊢ p (keyPrefix + (n + 1) * bitMul) val = true
have ih := checkAll_find? r (keyPrefix + bitMul) (bitMul * 2) ((n + 1) / 2) val hc.2.2 hf neg α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = true⊢ p (keyPrefix + (n + 1) * bitMul) val = true
have hkey :
keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2) = keyPrefix + (n + 1) * bitMul := by
have hdiv : 2 * ((n + 1) / 2) + 1 = n + 1 := by α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:checkAll p keyPrefix bitMul (node val? l r) = truehf:(node val? l r).find? (n + 1) = some val⊢ p (keyPrefix + (n + 1) * bitMul) val = true omega α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2) = keyPrefix + (n + 1) * bitMul
calc
keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)
= keyPrefix + (bitMul + (n + 1) / 2 * (2 * bitMul)) := by α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2) = keyPrefix + (bitMul + (n + 1) / 2 * (2 * bitMul))
rw [Nat.mul_comm bitMul 2, α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + bitMul + (n + 1) / 2 * (2 * bitMul) = keyPrefix + (bitMul + (n + 1) / 2 * (2 * bitMul)) Nat.add_assoc α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + (bitMul + (n + 1) / 2 * (2 * bitMul)) = keyPrefix + (bitMul + (n + 1) / 2 * (2 * bitMul))] All goals completed! 🐙
_ = keyPrefix + (1 * bitMul + (n + 1) / 2 * 2 * bitMul) := by α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + (bitMul + (n + 1) / 2 * (2 * bitMul)) = keyPrefix + (1 * bitMul + (n + 1) / 2 * 2 * bitMul)
rw [Nat.one_mul, α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + (bitMul + (n + 1) / 2 * (2 * bitMul)) = keyPrefix + (bitMul + (n + 1) / 2 * 2 * bitMul) Nat.mul_assoc α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + (bitMul + (n + 1) / 2 * (2 * bitMul)) = keyPrefix + (bitMul + (n + 1) / 2 * (2 * bitMul))] All goals completed! 🐙
_ = keyPrefix + (2 * ((n + 1) / 2) + 1) * bitMul := by α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + (1 * bitMul + (n + 1) / 2 * 2 * bitMul) = keyPrefix + (2 * ((n + 1) / 2) + 1) * bitMul
rw [Nat.add_comm (1 * bitMul), α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + ((n + 1) / 2 * 2 * bitMul + 1 * bitMul) = keyPrefix + (2 * ((n + 1) / 2) + 1) * bitMul ← Nat.add_mul, α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + ((n + 1) / 2 * 2 + 1) * bitMul = keyPrefix + (2 * ((n + 1) / 2) + 1) * bitMul Nat.mul_comm ((n + 1) / 2) 2 α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + (2 * ((n + 1) / 2) + 1) * bitMul = keyPrefix + (2 * ((n + 1) / 2) + 1) * bitMul] All goals completed! 🐙
_ = keyPrefix + (n + 1) * bitMul := by α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + (2 * ((n + 1) / 2) + 1) * bitMul = keyPrefix + (n + 1) * bitMul rw [hdiv α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehdiv:2 * ((n + 1) / 2) + 1 = n + 1⊢ keyPrefix + (n + 1) * bitMul = keyPrefix + (n + 1) * bitMul] neg α:Typep:ℕ → α → Boolval?:Option αl:NatTrie αr:NatTrie αkeyPrefix:ℕbitMul:ℕn:ℕval:αhc:(match val? with
| none => true
| some v => p keyPrefix v) =
true ∧
checkAll p keyPrefix (bitMul * 2) l = true ∧ checkAll p (keyPrefix + bitMul) (bitMul * 2) r = truehev:¬((n + 1) % 2).beq 0 = truehne:((n + 1) % 2).beq 0 = falsehf:r.find? ((n + 1) / 2) = some valhmod:(n + 1) % 2 = 1ih:p (keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2)) val = truehkey:keyPrefix + bitMul + (n + 1) / 2 * (bitMul * 2) = keyPrefix + (n + 1) * bitMul⊢ p (keyPrefix + (n + 1) * bitMul) val = true
rwa [hkey] at ih All goals completed! 🐙
Root-level specialization of checkAll_find?: if checkAll p 0 1 t = true and
t.find? n = some val, then p n val = true.
theorem checkAll_sound {α : Type} {p : ℕ → α → Bool} {t : NatTrie α}
(hc : checkAll p 0 1 t = true) {n : ℕ} {val : α} (hf : t.find? n = some val) :
p n val = true := by α:Typep:ℕ → α → Boolt:NatTrie αhc:checkAll p 0 1 t = truen:ℕval:αhf:t.find? n = some val⊢ p n val = true
simpa using checkAll_find? t 0 1 n val hc hf All goals completed! 🐙end NatTrieWord Repetition, Rotation, Concatenation, and Blank-Tape Identities
section ListIdentitiesvariable {Γ : Type*}
Reversing u ^ n reverses the base word u.
theorem reverse_pow (u : List Γ) (n : ℕ) : (u ^ n).reverse = u.reverse ^ n := by Γ:Type u_1u:List Γn:ℕ⊢ (u ^ n).reverse = u.reverse ^ n
induction n with
| zero => zero Γ:Type u_1u:List Γ⊢ (u ^ 0).reverse = u.reverse ^ 0 rfl All goals completed! 🐙
| succ n ih => succ Γ:Type u_1u:List Γn:ℕih:(u ^ n).reverse = u.reverse ^ n⊢ (u ^ (n + 1)).reverse = u.reverse ^ (n + 1)
rw [list_pow_succ, succ Γ:Type u_1u:List Γn:ℕih:(u ^ n).reverse = u.reverse ^ n⊢ (u ++ u ^ n).reverse = u.reverse ^ (n + 1) List.reverse_append, succ Γ:Type u_1u:List Γn:ℕih:(u ^ n).reverse = u.reverse ^ n⊢ (u ^ n).reverse ++ u.reverse = u.reverse ^ (n + 1) ih, succ Γ:Type u_1u:List Γn:ℕih:(u ^ n).reverse = u.reverse ^ n⊢ u.reverse ^ n ++ u.reverse = u.reverse ^ (n + 1) ← list_pow_succ' succ Γ:Type u_1u:List Γn:ℕih:(u ^ n).reverse = u.reverse ^ n⊢ u.reverse ^ (n + 1) = u.reverse ^ (n + 1)] All goals completed! 🐙
Word-power rotation identity: (u ++ w) ^ n ++ u = u ++ (w ++ u) ^ n.
theorem lpow_rot (u w : List Γ) (n : ℕ) : (u ++ w) ^ n ++ u = u ++ (w ++ u) ^ n := by Γ:Type u_1u:List Γw:List Γn:ℕ⊢ (u ++ w) ^ n ++ u = u ++ (w ++ u) ^ n
induction n with
| zero => zero Γ:Type u_1u:List Γw:List Γ⊢ (u ++ w) ^ 0 ++ u = u ++ (w ++ u) ^ 0 simp All goals completed! 🐙
| succ n ih => succ Γ:Type u_1u:List Γw:List Γn:ℕih:(u ++ w) ^ n ++ u = u ++ (w ++ u) ^ n⊢ (u ++ w) ^ (n + 1) ++ u = u ++ (w ++ u) ^ (n + 1)
rw [list_pow_succ, succ Γ:Type u_1u:List Γw:List Γn:ℕih:(u ++ w) ^ n ++ u = u ++ (w ++ u) ^ n⊢ u ++ w ++ (u ++ w) ^ n ++ u = u ++ (w ++ u) ^ (n + 1) list_pow_succ, succ Γ:Type u_1u:List Γw:List Γn:ℕih:(u ++ w) ^ n ++ u = u ++ (w ++ u) ^ n⊢ u ++ w ++ (u ++ w) ^ n ++ u = u ++ (w ++ u ++ (w ++ u) ^ n) List.append_assoc, succ Γ:Type u_1u:List Γw:List Γn:ℕih:(u ++ w) ^ n ++ u = u ++ (w ++ u) ^ n⊢ u ++ w ++ ((u ++ w) ^ n ++ u) = u ++ (w ++ u ++ (w ++ u) ^ n) ih succ Γ:Type u_1u:List Γw:List Γn:ℕih:(u ++ w) ^ n ++ u = u ++ (w ++ u) ^ n⊢ u ++ w ++ (u ++ (w ++ u) ^ n) = u ++ (w ++ u ++ (w ++ u) ^ n)] succ Γ:Type u_1u:List Γw:List Γn:ℕih:(u ++ w) ^ n ++ u = u ++ (w ++ u) ^ n⊢ u ++ w ++ (u ++ (w ++ u) ^ n) = u ++ (w ++ u ++ (w ++ u) ^ n)
simp [List.append_assoc] All goals completed! 🐙
Concatenate a list of subword indices left-to-right using baseWord : ℕ → List Γ.
def concatSubwords (baseWord : ℕ → List Γ) : List ℕ → List Γ
| [] => []
| s :: ss => baseWord s ++ concatSubwords baseWord ss@[simp]
theorem concatSubwords_append (baseWord : ℕ → List Γ) (xs ys : List ℕ) :
concatSubwords baseWord (xs ++ ys) =
concatSubwords baseWord xs ++ concatSubwords baseWord ys := by Γ:Type u_1baseWord:ℕ → List Γxs:List ℕys:List ℕ⊢ concatSubwords baseWord (xs ++ ys) = concatSubwords baseWord xs ++ concatSubwords baseWord ys
induction xs with
| nil => nil Γ:Type u_1baseWord:ℕ → List Γys:List ℕ⊢ concatSubwords baseWord ([] ++ ys) = concatSubwords baseWord [] ++ concatSubwords baseWord ys rfl All goals completed! 🐙
| cons x xs ih => cons Γ:Type u_1baseWord:ℕ → List Γys:List ℕx:ℕxs:List ℕih:concatSubwords baseWord (xs ++ ys) = concatSubwords baseWord xs ++ concatSubwords baseWord ys⊢ concatSubwords baseWord (x :: xs ++ ys) = concatSubwords baseWord (x :: xs) ++ concatSubwords baseWord ys simp [concatSubwords, ih, List.append_assoc] All goals completed! 🐙theorem lb_blank_word [Inhabited Γ] (z : List Γ) (hz : ∀ x ∈ z, x = default) :
ListBlank.append z default = default := by Γ:Type u_1inst✝:Inhabited Γz:List Γhz:∀ x ∈ z, x = default⊢ z +> default = default
induction z with
| nil => nil Γ:Type u_1inst✝:Inhabited Γhz:∀ x ∈ [], x = default⊢ [] +> default = default rfl All goals completed! 🐙
| cons x z ih => cons Γ:Type u_1inst✝:Inhabited Γx:Γz:List Γih:(∀ x ∈ z, x = default) → z +> default = defaulthz:∀ x_1 ∈ x :: z, x_1 = default⊢ (x :: z) +> default = default
rw [ListBlank.append_cons, cons Γ:Type u_1inst✝:Inhabited Γx:Γz:List Γih:(∀ x ∈ z, x = default) → z +> default = defaulthz:∀ x_1 ∈ x :: z, x_1 = default⊢ x >> z +> default = default ih (fun y hy ↦ hz y (List.mem_cons_of_mem _ hy)), cons Γ:Type u_1inst✝:Inhabited Γx:Γz:List Γih:(∀ x ∈ z, x = default) → z +> default = defaulthz:∀ x_1 ∈ x :: z, x_1 = default⊢ x >> default = default
hz x List.mem_cons_self, cons Γ:Type u_1inst✝:Inhabited Γx:Γz:List Γih:(∀ x ∈ z, x = default) → z +> default = defaulthz:∀ x_1 ∈ x :: z, x_1 = default⊢ default >> default = default ListBlank.cons_default_default cons Γ:Type u_1inst✝:Inhabited Γx:Γz:List Γih:(∀ x ∈ z, x = default) → z +> default = defaulthz:∀ x_1 ∈ x :: z, x_1 = default⊢ default = default] All goals completed! 🐙theorem lb_blank_pow [Inhabited Γ] (z : List Γ) (hz : ∀ x ∈ z, x = default) (n : ℕ) :
ListBlank.append (z ^ n) default = default := by Γ:Type u_1inst✝:Inhabited Γz:List Γhz:∀ x ∈ z, x = defaultn:ℕ⊢ z ^ n +> default = default
induction n with
| zero => zero Γ:Type u_1inst✝:Inhabited Γz:List Γhz:∀ x ∈ z, x = default⊢ z ^ 0 +> default = default rfl All goals completed! 🐙
| succ n ih => succ Γ:Type u_1inst✝:Inhabited Γz:List Γhz:∀ x ∈ z, x = defaultn:ℕih:z ^ n +> default = default⊢ z ^ (n + 1) +> default = default
rw [list_pow_succ, succ Γ:Type u_1inst✝:Inhabited Γz:List Γhz:∀ x ∈ z, x = defaultn:ℕih:z ^ n +> default = default⊢ (z ++ z ^ n) +> default = default ListBlank.append_assoc, succ Γ:Type u_1inst✝:Inhabited Γz:List Γhz:∀ x ∈ z, x = defaultn:ℕih:z ^ n +> default = default⊢ z +> z ^ n +> default = default ih, succ Γ:Type u_1inst✝:Inhabited Γz:List Γhz:∀ x ∈ z, x = defaultn:ℕih:z ^ n +> default = default⊢ z +> default = default lb_blank_word z hz succ Γ:Type u_1inst✝:Inhabited Γz:List Γhz:∀ x ∈ z, x = defaultn:ℕih:z ^ n +> default = default⊢ default = default] All goals completed! 🐙end ListIdentitiesDirected Configurations and Local Word-Exit Semantics
section WordSemanticsvariable {Γ Λ : Type*} [Inhabited Γ] [Inhabited Λ]
Directed machine configuration: Cfg.headRight when dir = true and Cfg.headLeft when
dir = false, indexing control states via qOf : ℕ → Λ.
def dirCfg (qOf : ℕ → Λ) (q : ℕ) (dir : Bool) (l r : ListBlank Γ) : Cfg Γ Λ :=
if dir then Cfg.headRight (qOf q) l r else Cfg.headLeft (qOf q) l r
Agreement between a pure ℕ-indexed transition function stepCode and M : Machine Γ Λ.
def StepCodeAgrees (M : Machine Γ Λ) (qOf : ℕ → Λ)
(stepCode : ℕ → Γ → Option (Γ × Bool × ℕ)) : Prop :=
∀ q a b dir' q', stepCode q a = some (b, dir', q') →
M (qOf q) a = some (some (qOf q'), Stmt.write b (if dir' then Dir.right else Dir.left))
Place spatial word w (written left-to-right) adjacent to the head on side side (true for
right half-tape, false for left half-tape where nearest-to-head comes first via w.reverse).
def placeSide (side : Bool) (w : List Γ) (l r : ListBlank Γ) : ListBlank Γ × ListBlank Γ :=
if side then (l, ListBlank.append w r) else (ListBlank.append w.reverse l, r)
Semantic specification of a local finite-word exit: entering spatial word u in state q
moving in direction dir exits in dt steps leaving spatial word v behind the head in state q'
moving in direction dir', for arbitrary surrounding half-tapes l and r.
def WordExit (M : Machine Γ Λ) (qOf : ℕ → Λ)
(u : List Γ) (q : ℕ) (dir : Bool) (v : List Γ) (q' : ℕ) (dir' : Bool) (dt : ℕ) : Prop :=
∀ l r : ListBlank Γ,
let (l₁, r₁) := placeSide dir u l r
let (l₂, r₂) := placeSide (!dir') v l r
ReachesIn M dt (dirCfg qOf q dir l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)Local symbol-level finite-word zipper simulator.
def simWord (stepCode : ℕ → Γ → Option (Γ × Bool × ℕ)) :
ℕ → ℕ → Bool → List Γ → List Γ → ℕ → Option (List Γ × ℕ × Bool × ℕ)
| 0, _, _, _, _, _ => none
| _ + 1, q, true, lw, [], dt =>
withNat q fun q' ↦ withNat dt fun d ↦ some (lw.reverse, q', true, d)
| fuel + 1, q, true, lw, a :: rw, dt =>
match stepCode q a with
| none => none
| some (b, true, q') =>
withNat (dt + 1) fun dt' ↦ simWord stepCode fuel q' true (b :: lw) rw dt'
| some (b, false, q') =>
withNat (dt + 1) fun dt' ↦ simWord stepCode fuel q' false lw (b :: rw) dt'
| _ + 1, q, false, [], rw, dt =>
withNat q fun q' ↦ withNat dt fun d ↦ some (rw, q', false, d)
| fuel + 1, q, false, a :: lw, rw, dt =>
match stepCode q a with
| none => none
| some (b, true, q') =>
withNat (dt + 1) fun dt' ↦ simWord stepCode fuel q' true (b :: lw) rw dt'
| some (b, false, q') =>
withNat (dt + 1) fun dt' ↦ simWord stepCode fuel q' false lw (b :: rw) dt'
Run simWord on spatial word u from state q and entry direction dir.
def runWordExit (stepCode : ℕ → Γ → Option (Γ × Bool × ℕ)) (fuel : ℕ)
(u : List Γ) (q : ℕ) (dir : Bool) : Option (List Γ × ℕ × Bool × ℕ) :=
if dir then simWord stepCode fuel q true [] u 0
else simWord stepCode fuel q false u.reverse [] 0private theorem simWord_sound_aux {M : Machine Γ Λ} {qOf : ℕ → Λ}
{stepCode : ℕ → Γ → Option (Γ × Bool × ℕ)} (hag : StepCodeAgrees M qOf stepCode) :
∀ (fuel q : ℕ) (dir : Bool) (lw rw : List Γ) (dt : ℕ)
(v : List Γ) (q' : ℕ) (dir' : Bool) (dtOut : ℕ) (l r : ListBlank Γ),
simWord stepCode fuel q dir lw rw dt = some (v, q', dir', dtOut) →
dt ≤ dtOut ∧
let (l₂, r₂) := placeSide (!dir') v l r
ReachesIn M (dtOut - dt)
(dirCfg qOf q dir (ListBlank.append lw l) (ListBlank.append rw r))
(dirCfg qOf q' dir' l₂ r₂)
| 0, _, _, _, _, _, _, _, _, _, _, _, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodex✝¹⁰:ℕx✝⁹:Boolx✝⁸:List Γx✝⁷:List Γx✝⁶:ℕx✝⁵:List Γx✝⁴:ℕx✝³:Boolx✝²:ℕx✝¹:ListBlank Γx✝:ListBlank Γh:simWord stepCode 0 x✝¹⁰ x✝⁹ x✝⁸ x✝⁷ x✝⁶ = some (x✝⁵, x✝⁴, x✝³, x✝²)⊢ x✝⁶ ≤ x✝² ∧
match placeSide (!x✝³) x✝⁵ x✝¹ x✝ with
| (l₂, r₂) => ReachesIn M (x✝² - x✝⁶) (dirCfg qOf x✝¹⁰ x✝⁹ (x✝⁸ +> x✝¹) (x✝⁷ +> x✝)) (dirCfg qOf x✝⁴ x✝³ l₂ r₂) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodex✝¹⁰:ℕx✝⁹:Boolx✝⁸:List Γx✝⁷:List Γx✝⁶:ℕx✝⁵:List Γx✝⁴:ℕx✝³:Boolx✝²:ℕx✝¹:ListBlank Γx✝:ListBlank Γh:simWord stepCode 0 x✝¹⁰ x✝⁹ x✝⁸ x✝⁷ x✝⁶ = some (x✝⁵, x✝⁴, x✝³, x✝²)⊢ x✝⁶ ≤ x✝² ∧
match placeSide (!x✝³) x✝⁵ x✝¹ x✝ with
| (l₂, r₂) => ReachesIn M (x✝² - x✝⁶) (dirCfg qOf x✝¹⁰ x✝⁹ (x✝⁸ +> x✝¹) (x✝⁷ +> x✝)) (dirCfg qOf x✝⁴ x✝³ l₂ r₂) simp [simWord] at h All goals completed! 🐙
| _ + 1, q, true, lw, [], dt, v, q', dir', dtOut, l, r, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCoden✝:ℕq:ℕlw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (n✝ + 1) q true lw [] dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ([] +> r)) (dirCfg qOf q' dir' l₂ r₂) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCoden✝:ℕq:ℕlw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (n✝ + 1) q true lw [] dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ([] +> r)) (dirCfg qOf q' dir' l₂ r₂)
simp only [simWord, withNat_eq, Option.some.injEq, Prod.mk.injEq] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCoden✝:ℕq:ℕlw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:lw.reverse = v ∧ q = q' ∧ true = dir' ∧ dt = dtOut⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ([] +> r)) (dirCfg qOf q' dir' l₂ r₂)
rcases h with ⟨rfl, rfl, rfl, rfl⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCoden✝:ℕq:ℕlw:List Γdt:ℕl:ListBlank Γr:ListBlank Γ⊢ dt ≤ dt ∧
match placeSide (!true) lw.reverse l r with
| (l₂, r₂) => ReachesIn M (dt - dt) (dirCfg qOf q true (lw +> l) ([] +> r)) (dirCfg qOf q true l₂ r₂)
refine ⟨Nat.le_refl dt, ?_⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCoden✝:ℕq:ℕlw:List Γdt:ℕl:ListBlank Γr:ListBlank Γ⊢ match placeSide (!true) lw.reverse l r with
| (l₂, r₂) => ReachesIn M (dt - dt) (dirCfg qOf q true (lw +> l) ([] +> r)) (dirCfg qOf q true l₂ r₂)
simp [placeSide, List.reverse_reverse] All goals completed! 🐙
| fuel + 1, q, true, lw, a :: rw, dt, v, q', dir', dtOut, l, r, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (fuel + 1) q true lw (a :: rw) dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (fuel + 1) q true lw (a :: rw) dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
simp only [simWord, withNat_eq] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match stepCode q a with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
rcases hsc : stepCode q a with _ | ⟨b, dNext, qNext⟩ none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match stepCode q a with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = none⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match stepCode q a with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)b:ΓdNext:BoolqNext:ℕhsc:stepCode q a = some (b, dNext, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
· none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match stepCode q a with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = none⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂) simp [hsc] at h All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match stepCode q a with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)b:ΓdNext:BoolqNext:ℕhsc:stepCode q a = some (b, dNext, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂) rw [hsc some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓdNext:BoolqNext:ℕh:(match some (b, dNext, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, dNext, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)] at h some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓdNext:BoolqNext:ℕh:(match some (b, dNext, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, dNext, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
cases dNext some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:(match some (b, false, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:(match some (b, true, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
· some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:(match some (b, false, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂) simp only at h some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
obtain ⟨hle, hreach⟩ :=
simWord_sound_aux hag fuel qNext false lw (b :: rw) (dt + 1) v q' dir' dtOut l r h some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
have hstep := step_headRight_left (hag q a b false qNext hsc)
(ListBlank.append lw l) (ListBlank.append rw r) some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headRight (qOf q) (lw +> l) (a >> rw +> r) [M]⊢ Cfg.headLeft (qOf qNext) (lw +> l) (b >> rw +> r)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
refine ⟨by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headRight (qOf q) (lw +> l) (a >> rw +> r) [M]⊢ Cfg.headLeft (qOf qNext) (lw +> l) (b >> rw +> r)⊢ dt ≤ dtOut omega All goals completed! 🐙, ?_⟩
have hsub : dtOut - dt = (dtOut - (dt + 1)) + 1 := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (fuel + 1) q true lw (a :: rw) dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂) omega some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headRight (qOf q) (lw +> l) (a >> rw +> r) [M]⊢ Cfg.headLeft (qOf qNext) (lw +> l) (b >> rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
rw [hsub some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headRight (qOf q) (lw +> l) (a >> rw +> r) [M]⊢ Cfg.headLeft (qOf qNext) (lw +> l) (b >> rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1) + 1) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)] some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headRight (qOf q) (lw +> l) (a >> rw +> r) [M]⊢ Cfg.headLeft (qOf qNext) (lw +> l) (b >> rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1) + 1) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
exact ReachesIn.step_left hstep hreach All goals completed! 🐙
· some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:(match some (b, true, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂) simp only at h some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
obtain ⟨hle, hreach⟩ :=
simWord_sound_aux hag fuel qNext true (b :: lw) rw (dt + 1) v q' dir' dtOut l r h some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
have hstep := step_headRight_right (hag q a b true qNext hsc)
(ListBlank.append lw l) (ListBlank.append rw r) some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headRight (qOf q) (lw +> l) (a >> rw +> r) [M]⊢ Cfg.headRight (qOf qNext) (b >> lw +> l) (rw +> r)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
refine ⟨by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headRight (qOf q) (lw +> l) (a >> rw +> r) [M]⊢ Cfg.headRight (qOf qNext) (b >> lw +> l) (rw +> r)⊢ dt ≤ dtOut omega All goals completed! 🐙, ?_⟩
have hsub : dtOut - dt = (dtOut - (dt + 1)) + 1 := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (fuel + 1) q true lw (a :: rw) dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂) omega some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headRight (qOf q) (lw +> l) (a >> rw +> r) [M]⊢ Cfg.headRight (qOf qNext) (b >> lw +> l) (rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
rw [hsub some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headRight (qOf q) (lw +> l) (a >> rw +> r) [M]⊢ Cfg.headRight (qOf qNext) (b >> lw +> l) (rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1) + 1) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)] some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕlw:List Γa:Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headRight (qOf q) (lw +> l) (a >> rw +> r) [M]⊢ Cfg.headRight (qOf qNext) (b >> lw +> l) (rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1) + 1) (dirCfg qOf q true (lw +> l) ((a :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)
exact ReachesIn.step_left hstep hreach All goals completed! 🐙
| _ + 1, q, false, [], rw, dt, v, q', dir', dtOut, l, r, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCoden✝:ℕq:ℕrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (n✝ + 1) q false [] rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ([] +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCoden✝:ℕq:ℕrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (n✝ + 1) q false [] rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ([] +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
simp only [simWord, withNat_eq, Option.some.injEq, Prod.mk.injEq] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCoden✝:ℕq:ℕrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:rw = v ∧ q = q' ∧ false = dir' ∧ dt = dtOut⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ([] +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
rcases h with ⟨rfl, rfl, rfl, rfl⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCoden✝:ℕq:ℕrw:List Γdt:ℕl:ListBlank Γr:ListBlank Γ⊢ dt ≤ dt ∧
match placeSide (!false) rw l r with
| (l₂, r₂) => ReachesIn M (dt - dt) (dirCfg qOf q false ([] +> l) (rw +> r)) (dirCfg qOf q false l₂ r₂)
refine ⟨Nat.le_refl dt, ?_⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCoden✝:ℕq:ℕrw:List Γdt:ℕl:ListBlank Γr:ListBlank Γ⊢ match placeSide (!false) rw l r with
| (l₂, r₂) => ReachesIn M (dt - dt) (dirCfg qOf q false ([] +> l) (rw +> r)) (dirCfg qOf q false l₂ r₂)
simp [placeSide] All goals completed! 🐙
| fuel + 1, q, false, a :: lw, rw, dt, v, q', dir', dtOut, l, r, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (fuel + 1) q false (a :: lw) rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (fuel + 1) q false (a :: lw) rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
simp only [simWord, withNat_eq] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match stepCode q a with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
rcases hsc : stepCode q a with _ | ⟨b, dNext, qNext⟩ none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match stepCode q a with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = none⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match stepCode q a with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)b:ΓdNext:BoolqNext:ℕhsc:stepCode q a = some (b, dNext, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
· none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match stepCode q a with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = none⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂) simp [hsc] at h All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match stepCode q a with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)b:ΓdNext:BoolqNext:ℕhsc:stepCode q a = some (b, dNext, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂) rw [hsc some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓdNext:BoolqNext:ℕh:(match some (b, dNext, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, dNext, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)] at h some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓdNext:BoolqNext:ℕh:(match some (b, dNext, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, dNext, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
cases dNext some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:(match some (b, false, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:(match some (b, true, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
· some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:(match some (b, false, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂) simp only at h some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
obtain ⟨hle, hreach⟩ :=
simWord_sound_aux hag fuel qNext false lw (b :: rw) (dt + 1) v q' dir' dtOut l r h some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
have hstep := step_headLeft_left (hag q a b false qNext hsc)
(ListBlank.append lw l) (ListBlank.append rw r) some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headLeft (qOf q) (a >> lw +> l) (rw +> r) [M]⊢ Cfg.headLeft (qOf qNext) (lw +> l) (b >> rw +> r)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
refine ⟨by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headLeft (qOf q) (a >> lw +> l) (rw +> r) [M]⊢ Cfg.headLeft (qOf qNext) (lw +> l) (b >> rw +> r)⊢ dt ≤ dtOut omega All goals completed! 🐙, ?_⟩
have hsub : dtOut - dt = (dtOut - (dt + 1)) + 1 := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (fuel + 1) q false (a :: lw) rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂) omega some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headLeft (qOf q) (a >> lw +> l) (rw +> r) [M]⊢ Cfg.headLeft (qOf qNext) (lw +> l) (b >> rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
rw [hsub some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headLeft (qOf q) (a >> lw +> l) (rw +> r) [M]⊢ Cfg.headLeft (qOf qNext) (lw +> l) (b >> rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1) + 1) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)] some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext false lw (b :: rw) (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, false, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext false (lw +> l) ((b :: rw) +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headLeft (qOf q) (a >> lw +> l) (rw +> r) [M]⊢ Cfg.headLeft (qOf qNext) (lw +> l) (b >> rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1) + 1) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
exact ReachesIn.step_left hstep hreach All goals completed! 🐙
· some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:(match some (b, true, qNext) with
| none => none
| some (b, true, q') => simWord stepCode fuel q' true (b :: lw) rw (dt + 1)
| some (b, false, q') => simWord stepCode fuel q' false lw (b :: rw) (dt + 1)) =
some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂) simp only at h some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
obtain ⟨hle, hreach⟩ :=
simWord_sound_aux hag fuel qNext true (b :: lw) rw (dt + 1) v q' dir' dtOut l r h some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
have hstep := step_headLeft_right (hag q a b true qNext hsc)
(ListBlank.append lw l) (ListBlank.append rw r) some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headLeft (qOf q) (a >> lw +> l) (rw +> r) [M]⊢ Cfg.headRight (qOf qNext) (b >> lw +> l) (rw +> r)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
refine ⟨by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headLeft (qOf q) (a >> lw +> l) (rw +> r) [M]⊢ Cfg.headRight (qOf qNext) (b >> lw +> l) (rw +> r)⊢ dt ≤ dtOut omega All goals completed! 🐙, ?_⟩
have hsub : dtOut - dt = (dtOut - (dt + 1)) + 1 := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode (fuel + 1) q false (a :: lw) rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂) omega some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headLeft (qOf q) (a >> lw +> l) (rw +> r) [M]⊢ Cfg.headRight (qOf qNext) (b >> lw +> l) (rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M (dtOut - dt) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
rw [hsub some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headLeft (qOf q) (a >> lw +> l) (rw +> r) [M]⊢ Cfg.headRight (qOf qNext) (b >> lw +> l) (rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1) + 1) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)] some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕq:ℕa:Γlw:List Γrw:List Γdt:ℕv:List Γq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γb:ΓqNext:ℕh:simWord stepCode fuel qNext true (b :: lw) rw (dt + 1) = some (v, q', dir', dtOut)hsc:stepCode q a = some (b, true, qNext)hle:dt + 1 ≤ dtOuthreach:match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1)) (dirCfg qOf qNext true ((b :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)hstep:Cfg.headLeft (qOf q) (a >> lw +> l) (rw +> r) [M]⊢ Cfg.headRight (qOf qNext) (b >> lw +> l) (rw +> r)hsub:dtOut - dt = dtOut - (dt + 1) + 1⊢ match placeSide (!dir') v l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + 1) + 1) (dirCfg qOf q false ((a :: lw) +> l) (rw +> r)) (dirCfg qOf q' dir' l₂ r₂)
exact ReachesIn.step_left hstep hreach All goals completed! 🐙
Soundness of runWordExit: a successful finite-word zipper run establishes WordExit.
theorem runWordExit_sound {M : Machine Γ Λ} {qOf : ℕ → Λ}
{stepCode : ℕ → Γ → Option (Γ × Bool × ℕ)} (hag : StepCodeAgrees M qOf stepCode)
{fuel : ℕ} {u : List Γ} {q : ℕ} {dir : Bool}
{v : List Γ} {q' : ℕ} {dir' : Bool} {dt : ℕ}
(h : runWordExit stepCode fuel u q dir = some (v, q', dir', dt)) :
WordExit M qOf u q dir v q' dir' dt := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕu:List Γq:ℕdir:Boolv:List Γq':ℕdir':Booldt:ℕh:runWordExit stepCode fuel u q dir = some (v, q', dir', dt)⊢ WordExit M qOf u q dir v q' dir' dt
intro l r Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕu:List Γq:ℕdir:Boolv:List Γq':ℕdir':Booldt:ℕh:runWordExit stepCode fuel u q dir = some (v, q', dir', dt)l:ListBlank Γr:ListBlank Γ⊢ match placeSide dir u l r with
| (l₁, r₁) =>
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q dir l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
unfold runWordExit at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕu:List Γq:ℕdir:Boolv:List Γq':ℕdir':Booldt:ℕh:(if dir = true then simWord stepCode fuel q true [] u 0 else simWord stepCode fuel q false u.reverse [] 0) =
some (v, q', dir', dt)l:ListBlank Γr:ListBlank Γ⊢ match placeSide dir u l r with
| (l₁, r₁) =>
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q dir l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
cases dir false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕu:List Γq:ℕv:List Γq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:(if false = true then simWord stepCode fuel q true [] u 0 else simWord stepCode fuel q false u.reverse [] 0) =
some (v, q', dir', dt)⊢ match placeSide false u l r with
| (l₁, r₁) =>
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q false l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕu:List Γq:ℕv:List Γq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:(if true = true then simWord stepCode fuel q true [] u 0 else simWord stepCode fuel q false u.reverse [] 0) =
some (v, q', dir', dt)⊢ match placeSide true u l r with
| (l₁, r₁) =>
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q true l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
· false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕu:List Γq:ℕv:List Γq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:(if false = true then simWord stepCode fuel q true [] u 0 else simWord stepCode fuel q false u.reverse [] 0) =
some (v, q', dir', dt)⊢ match placeSide false u l r with
| (l₁, r₁) =>
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q false l₁ r₁) (dirCfg qOf q' dir' l₂ r₂) simp only [Bool.false_eq_true, ↓reduceIte] at h false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕu:List Γq:ℕv:List Γq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode fuel q false u.reverse [] 0 = some (v, q', dir', dt)⊢ match placeSide false u l r with
| (l₁, r₁) =>
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q false l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
simpa [placeSide] using (simWord_sound_aux hag fuel q false u.reverse [] 0 v q' dir' dt l r h).2 All goals completed! 🐙
· true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕu:List Γq:ℕv:List Γq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:(if true = true then simWord stepCode fuel q true [] u 0 else simWord stepCode fuel q false u.reverse [] 0) =
some (v, q', dir', dt)⊢ match placeSide true u l r with
| (l₁, r₁) =>
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q true l₁ r₁) (dirCfg qOf q' dir' l₂ r₂) simp only [↓reduceIte] at h true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛstepCode:ℕ → Γ → Option (Γ × Bool × ℕ)hag:StepCodeAgrees M qOf stepCodefuel:ℕu:List Γq:ℕv:List Γq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:simWord stepCode fuel q true [] u 0 = some (v, q', dir', dt)⊢ match placeSide true u l r with
| (l₁, r₁) =>
match placeSide (!dir') v l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q true l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
simpa [placeSide] using (simWord_sound_aux hag fuel q true [] u 0 v q' dir' dt l r h).2 All goals completed! 🐙
Homogeneous k-copy sweep: if (u, q, dir) exits in the same state and direction (q, dir)
leaving v in dt steps, then u ^ k exits in (q, dir) leaving v ^ k in dt * k steps.
theorem sweepWord_sound {M : Machine Γ Λ} {qOf : ℕ → Λ}
{u v : List Γ} {q : ℕ} {dir : Bool} {dt : ℕ}
(hex : WordExit M qOf u q dir v q dir dt) (k : ℕ) :
WordExit M qOf (u ^ k) q dir (v ^ k) q dir (dt * k) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdir:Booldt:ℕhex:WordExit M qOf u q dir v q dir dtk:ℕ⊢ WordExit M qOf (u ^ k) q dir (v ^ k) q dir (dt * k)
induction k with
| zero => zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdir:Booldt:ℕhex:WordExit M qOf u q dir v q dir dt⊢ WordExit M qOf (u ^ 0) q dir (v ^ 0) q dir (dt * 0)
intro l r zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdir:Booldt:ℕhex:WordExit M qOf u q dir v q dir dtl:ListBlank Γr:ListBlank Γ⊢ match placeSide dir (u ^ 0) l r with
| (l₁, r₁) =>
match placeSide (!dir) (v ^ 0) l r with
| (l₂, r₂) => ReachesIn M (dt * 0) (dirCfg qOf q dir l₁ r₁) (dirCfg qOf q dir l₂ r₂)
simp [placeSide] All goals completed! 🐙
| succ k ih => succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdir:Booldt:ℕhex:WordExit M qOf u q dir v q dir dtk:ℕih:WordExit M qOf (u ^ k) q dir (v ^ k) q dir (dt * k)⊢ WordExit M qOf (u ^ (k + 1)) q dir (v ^ (k + 1)) q dir (dt * (k + 1))
intro l r succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdir:Booldt:ℕhex:WordExit M qOf u q dir v q dir dtk:ℕih:WordExit M qOf (u ^ k) q dir (v ^ k) q dir (dt * k)l:ListBlank Γr:ListBlank Γ⊢ match placeSide dir (u ^ (k + 1)) l r with
| (l₁, r₁) =>
match placeSide (!dir) (v ^ (k + 1)) l r with
| (l₂, r₂) => ReachesIn M (dt * (k + 1)) (dirCfg qOf q dir l₁ r₁) (dirCfg qOf q dir l₂ r₂)
cases dir succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)⊢ match placeSide false (u ^ (k + 1)) l r with
| (l₁, r₁) =>
match placeSide (!false) (v ^ (k + 1)) l r with
| (l₂, r₂) => ReachesIn M (dt * (k + 1)) (dirCfg qOf q false l₁ r₁) (dirCfg qOf q false l₂ r₂)succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)⊢ match placeSide true (u ^ (k + 1)) l r with
| (l₁, r₁) =>
match placeSide (!true) (v ^ (k + 1)) l r with
| (l₂, r₂) => ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l₁ r₁) (dirCfg qOf q true l₂ r₂)
· succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)⊢ match placeSide false (u ^ (k + 1)) l r with
| (l₁, r₁) =>
match placeSide (!false) (v ^ (k + 1)) l r with
| (l₂, r₂) => ReachesIn M (dt * (k + 1)) (dirCfg qOf q false l₁ r₁) (dirCfg qOf q false l₂ r₂) simp only [placeSide, Bool.false_eq_true, ↓reduceIte, Bool.not_false] succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false ((u ^ (k + 1)).reverse +> l) r) (dirCfg qOf q false l (v ^ (k + 1) +> r))
rw [list_pow_succ' u k, succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false ((u ^ k ++ u).reverse +> l) r) (dirCfg qOf q false l (v ^ (k + 1) +> r)) List.reverse_append, succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false ((u.reverse ++ (u ^ k).reverse) +> l) r)
(dirCfg qOf q false l (v ^ (k + 1) +> r)) ListBlank.append_assoc, succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ (k + 1) +> r))
list_pow_succ' v k, succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l ((v ^ k ++ v) +> r)) ListBlank.append_assoc succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))] succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))
have h1 := hex (ListBlank.append (u ^ k).reverse l) r succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)h1:match placeSide false u ((u ^ k).reverse +> l) r with
| (l₁, r₁) =>
match placeSide (!false) v ((u ^ k).reverse +> l) r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q false l₁ r₁) (dirCfg qOf q false l₂ r₂)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))
simp only [placeSide, Bool.false_eq_true, ↓reduceIte, Bool.not_false] at h1 succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)h1:ReachesIn M dt (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r))⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))
have h2 := ih l (ListBlank.append v r) succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)h1:ReachesIn M dt (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r))h2:match placeSide false (u ^ k) l (v +> r) with
| (l₁, r₁) =>
match placeSide (!false) (v ^ k) l (v +> r) with
| (l₂, r₂) => ReachesIn M (dt * k) (dirCfg qOf q false l₁ r₁) (dirCfg qOf q false l₂ r₂)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))
simp only [placeSide, Bool.false_eq_true, ↓reduceIte, Bool.not_false] at h2 succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)h1:ReachesIn M dt (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r))h2:ReachesIn M (dt * k) (dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r)) (dirCfg qOf q false l (v ^ k +> v +> r))⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))
have htr := h1.trans h2 succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)h1:ReachesIn M dt (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r))h2:ReachesIn M (dt * k) (dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r)) (dirCfg qOf q false l (v ^ k +> v +> r))htr:ReachesIn M (dt + dt * k) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))
have hdt : dt + dt * k = dt * (k + 1) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdir:Booldt:ℕhex:WordExit M qOf u q dir v q dir dtk:ℕ⊢ WordExit M qOf (u ^ k) q dir (v ^ k) q dir (dt * k) rw [Nat.mul_succ, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)h1:ReachesIn M dt (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r))h2:ReachesIn M (dt * k) (dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r)) (dirCfg qOf q false l (v ^ k +> v +> r))htr:ReachesIn M (dt + dt * k) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))⊢ dt + dt * k = dt * k + dt Nat.add_comm Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)h1:ReachesIn M dt (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r))h2:ReachesIn M (dt * k) (dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r)) (dirCfg qOf q false l (v ^ k +> v +> r))htr:ReachesIn M (dt + dt * k) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))⊢ dt * k + dt = dt * k + dt] succ.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q false v q false dtih:WordExit M qOf (u ^ k) q false (v ^ k) q false (dt * k)h1:ReachesIn M dt (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r))h2:ReachesIn M (dt * k) (dirCfg qOf q false ((u ^ k).reverse +> l) (v +> r)) (dirCfg qOf q false l (v ^ k +> v +> r))htr:ReachesIn M (dt + dt * k) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))hdt:dt + dt * k = dt * (k + 1)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q false (u.reverse +> (u ^ k).reverse +> l) r)
(dirCfg qOf q false l (v ^ k +> v +> r))
rwa [hdt] at htr All goals completed! 🐙
· succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)⊢ match placeSide true (u ^ (k + 1)) l r with
| (l₁, r₁) =>
match placeSide (!true) (v ^ (k + 1)) l r with
| (l₂, r₂) => ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l₁ r₁) (dirCfg qOf q true l₂ r₂) simp only [placeSide, Bool.false_eq_true, ↓reduceIte, Bool.not_true] succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u ^ (k + 1) +> r)) (dirCfg qOf q true ((v ^ (k + 1)).reverse +> l) r)
rw [list_pow_succ u k, succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l ((u ++ u ^ k) +> r)) (dirCfg qOf q true ((v ^ (k + 1)).reverse +> l) r) ListBlank.append_assoc, succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r)) (dirCfg qOf q true ((v ^ (k + 1)).reverse +> l) r)
list_pow_succ v k, succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r)) (dirCfg qOf q true ((v ++ v ^ k).reverse +> l) r) List.reverse_append, succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true (((v ^ k).reverse ++ v.reverse) +> l) r) ListBlank.append_assoc succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)] succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)
have h1 := hex l (ListBlank.append (u ^ k) r) succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)h1:match placeSide true u l (u ^ k +> r) with
| (l₁, r₁) =>
match placeSide (!true) v l (u ^ k +> r) with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q true l₁ r₁) (dirCfg qOf q true l₂ r₂)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)
simp only [placeSide, Bool.false_eq_true, ↓reduceIte, Bool.not_true] at h1 succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)h1:ReachesIn M dt (dirCfg qOf q true l (u +> u ^ k +> r)) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)
have h2 := ih (ListBlank.append v.reverse l) r succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)h1:ReachesIn M dt (dirCfg qOf q true l (u +> u ^ k +> r)) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))h2:match placeSide true (u ^ k) (v.reverse +> l) r with
| (l₁, r₁) =>
match placeSide (!true) (v ^ k) (v.reverse +> l) r with
| (l₂, r₂) => ReachesIn M (dt * k) (dirCfg qOf q true l₁ r₁) (dirCfg qOf q true l₂ r₂)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)
simp only [placeSide, Bool.false_eq_true, ↓reduceIte, Bool.not_true] at h2 succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)h1:ReachesIn M dt (dirCfg qOf q true l (u +> u ^ k +> r)) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))h2:ReachesIn M (dt * k) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)
have htr := h1.trans h2 succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)h1:ReachesIn M dt (dirCfg qOf q true l (u +> u ^ k +> r)) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))h2:ReachesIn M (dt * k) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)htr:ReachesIn M (dt + dt * k) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)
have hdt : dt + dt * k = dt * (k + 1) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdir:Booldt:ℕhex:WordExit M qOf u q dir v q dir dtk:ℕ⊢ WordExit M qOf (u ^ k) q dir (v ^ k) q dir (dt * k) rw [Nat.mul_succ, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)h1:ReachesIn M dt (dirCfg qOf q true l (u +> u ^ k +> r)) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))h2:ReachesIn M (dt * k) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)htr:ReachesIn M (dt + dt * k) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)⊢ dt + dt * k = dt * k + dt Nat.add_comm Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)h1:ReachesIn M dt (dirCfg qOf q true l (u +> u ^ k +> r)) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))h2:ReachesIn M (dt * k) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)htr:ReachesIn M (dt + dt * k) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)⊢ dt * k + dt = dt * k + dt] succ.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → Λu:List Γv:List Γq:ℕdt:ℕk:ℕl:ListBlank Γr:ListBlank Γhex:WordExit M qOf u q true v q true dtih:WordExit M qOf (u ^ k) q true (v ^ k) q true (dt * k)h1:ReachesIn M dt (dirCfg qOf q true l (u +> u ^ k +> r)) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))h2:ReachesIn M (dt * k) (dirCfg qOf q true (v.reverse +> l) (u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)htr:ReachesIn M (dt + dt * k) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)hdt:dt + dt * k = dt * (k + 1)⊢ ReachesIn M (dt * (k + 1)) (dirCfg qOf q true l (u +> u ^ k +> r))
(dirCfg qOf q true ((v ^ k).reverse +> v.reverse +> l) r)
rwa [hdt] at htr All goals completed! 🐙
Composite Subword Zipper (simSubwords)
Soundness predicate for a base-word exit function (q, dir, s) ↦ (s', q', dir', dt).
def BaseExitSound (M : Machine Γ Λ) (qOf : ℕ → Λ) (baseWord : ℕ → List Γ)
(baseExit : ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)) : Prop :=
∀ q dir s s' q' dir' dt,
baseExit q dir s = some (s', q', dir', dt) →
WordExit M qOf (baseWord s) q dir (baseWord s') q' dir' dt
Subword-level local zipper simulator over a verified baseExit table.
def simSubwords (baseExit : ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)) :
ℕ → ℕ → Bool → List ℕ → List ℕ → ℕ → Option (List ℕ × ℕ × Bool × ℕ)
| 0, _, _, _, _, _ => none
| _ + 1, q, true, lw, [], dt =>
withNat q fun q' ↦ withNat dt fun d ↦ some (lw.reverse, q', true, d)
| fuel + 1, q, true, lw, a :: rw, dt =>
match baseExit q true a with
| none => none
| some (s', q', dir', exDt) =>
withNat (dt + exDt) fun dt' ↦
if dir' then simSubwords baseExit fuel q' true (s' :: lw) rw dt'
else simSubwords baseExit fuel q' false lw (s' :: rw) dt'
| _ + 1, q, false, [], rw, dt =>
withNat q fun q' ↦ withNat dt fun d ↦ some (rw, q', false, d)
| fuel + 1, q, false, a :: lw, rw, dt =>
match baseExit q false a with
| none => none
| some (s', q', dir', exDt) =>
withNat (dt + exDt) fun dt' ↦
if dir' then simSubwords baseExit fuel q' true (s' :: lw) rw dt'
else simSubwords baseExit fuel q' false lw (s' :: rw) dt'
Compute the composite exit of subword list u from (q, dir) using baseExit.
def runCompositeExit (baseExit : ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ))
(u : List ℕ) (q : ℕ) (dir : Bool) : Option (List ℕ × ℕ × Bool × ℕ) :=
withNat (u.length * 16 + 16) fun fuel ↦
if dir then simSubwords baseExit fuel q true [] u 0
else simSubwords baseExit fuel q false u.reverse [] 0private def leftSubTape (baseWord : ℕ → List Γ) : List ℕ → ListBlank Γ → ListBlank Γ
| [], l => l
| s :: lw, l => ListBlank.append (baseWord s).reverse (leftSubTape baseWord lw l)private def rightSubTape (baseWord : ℕ → List Γ) : List ℕ → ListBlank Γ → ListBlank Γ
| [], r => r
| s :: rw, r => ListBlank.append (baseWord s) (rightSubTape baseWord rw r)private theorem rightSubTape_eq (baseWord : ℕ → List Γ) (rw : List ℕ) (r : ListBlank Γ) :
rightSubTape baseWord rw r = ListBlank.append (concatSubwords baseWord rw) r := by Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γrw:List ℕr:ListBlank Γ⊢ rightSubTape baseWord rw r = concatSubwords baseWord rw +> r
induction rw with
| nil => nil Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γr:ListBlank Γ⊢ rightSubTape baseWord [] r = concatSubwords baseWord [] +> r rfl All goals completed! 🐙
| cons s rw ih => cons Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γr:ListBlank Γs:ℕrw:List ℕih:rightSubTape baseWord rw r = concatSubwords baseWord rw +> r⊢ rightSubTape baseWord (s :: rw) r = concatSubwords baseWord (s :: rw) +> r
simp [rightSubTape, concatSubwords, ih, ListBlank.append_assoc] All goals completed! 🐙private theorem leftSubTape_append (baseWord : ℕ → List Γ) (xs ys : List ℕ) (l : ListBlank Γ) :
leftSubTape baseWord (xs ++ ys) l = leftSubTape baseWord xs (leftSubTape baseWord ys l) := by Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γxs:List ℕys:List ℕl:ListBlank Γ⊢ leftSubTape baseWord (xs ++ ys) l = leftSubTape baseWord xs (leftSubTape baseWord ys l)
induction xs with
| nil => nil Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γys:List ℕl:ListBlank Γ⊢ leftSubTape baseWord ([] ++ ys) l = leftSubTape baseWord [] (leftSubTape baseWord ys l) rfl All goals completed! 🐙
| cons x xs ih => cons Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γys:List ℕl:ListBlank Γx:ℕxs:List ℕih:leftSubTape baseWord (xs ++ ys) l = leftSubTape baseWord xs (leftSubTape baseWord ys l)⊢ leftSubTape baseWord (x :: xs ++ ys) l = leftSubTape baseWord (x :: xs) (leftSubTape baseWord ys l) simp [leftSubTape, ih] All goals completed! 🐙private theorem leftSubTape_reverse_eq (baseWord : ℕ → List Γ) (u : List ℕ) (l : ListBlank Γ) :
leftSubTape baseWord u.reverse l =
ListBlank.append (concatSubwords baseWord u).reverse l := by Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γu:List ℕl:ListBlank Γ⊢ leftSubTape baseWord u.reverse l = (concatSubwords baseWord u).reverse +> l
induction u generalizing l with
| nil => nil Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γl:ListBlank Γ⊢ leftSubTape baseWord [].reverse l = (concatSubwords baseWord []).reverse +> l rfl All goals completed! 🐙
| cons s u ih => cons Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γs:ℕu:List ℕih:∀ (l : ListBlank Γ), leftSubTape baseWord u.reverse l = (concatSubwords baseWord u).reverse +> ll:ListBlank Γ⊢ leftSubTape baseWord (s :: u).reverse l = (concatSubwords baseWord (s :: u)).reverse +> l
simp only [List.reverse_cons, leftSubTape_append, leftSubTape, concatSubwords,
List.reverse_append, ListBlank.append_assoc] cons Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γs:ℕu:List ℕih:∀ (l : ListBlank Γ), leftSubTape baseWord u.reverse l = (concatSubwords baseWord u).reverse +> ll:ListBlank Γ⊢ leftSubTape baseWord u.reverse ((baseWord s).reverse +> l) =
(concatSubwords baseWord u).reverse +> (baseWord s).reverse +> l
rw [ih cons Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γs:ℕu:List ℕih:∀ (l : ListBlank Γ), leftSubTape baseWord u.reverse l = (concatSubwords baseWord u).reverse +> ll:ListBlank Γ⊢ (concatSubwords baseWord u).reverse +> (baseWord s).reverse +> l =
(concatSubwords baseWord u).reverse +> (baseWord s).reverse +> l] All goals completed! 🐙private theorem leftSubTape_eq (baseWord : ℕ → List Γ) (lw : List ℕ) (l : ListBlank Γ) :
leftSubTape baseWord lw l =
ListBlank.append (concatSubwords baseWord lw.reverse).reverse l := by Γ:Type u_1inst✝:Inhabited ΓbaseWord:ℕ → List Γlw:List ℕl:ListBlank Γ⊢ leftSubTape baseWord lw l = (concatSubwords baseWord lw.reverse).reverse +> l
simpa using leftSubTape_reverse_eq baseWord lw.reverse l All goals completed! 🐙private theorem simSubwords_sound_aux {M : Machine Γ Λ} {qOf : ℕ → Λ} {baseWord : ℕ → List Γ}
{baseExit : ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)}
(hbase : BaseExitSound M qOf baseWord baseExit) :
∀ (fuel q : ℕ) (dir : Bool) (lw rw : List ℕ) (dt : ℕ)
(v : List ℕ) (q' : ℕ) (dir' : Bool) (dtOut : ℕ) (l r : ListBlank Γ),
simSubwords baseExit fuel q dir lw rw dt = some (v, q', dir', dtOut) →
dt ≤ dtOut ∧
let (l₂, r₂) := placeSide (!dir') (concatSubwords baseWord v) l r
ReachesIn M (dtOut - dt)
(dirCfg qOf q dir (leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
| 0, _, _, _, _, _, _, _, _, _, _, _, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitx✝¹⁰:ℕx✝⁹:Boolx✝⁸:List ℕx✝⁷:List ℕx✝⁶:ℕx✝⁵:List ℕx✝⁴:ℕx✝³:Boolx✝²:ℕx✝¹:ListBlank Γx✝:ListBlank Γh:simSubwords baseExit 0 x✝¹⁰ x✝⁹ x✝⁸ x✝⁷ x✝⁶ = some (x✝⁵, x✝⁴, x✝³, x✝²)⊢ x✝⁶ ≤ x✝² ∧
match placeSide (!x✝³) (concatSubwords baseWord x✝⁵) x✝¹ x✝ with
| (l₂, r₂) =>
ReachesIn M (x✝² - x✝⁶) (dirCfg qOf x✝¹⁰ x✝⁹ (leftSubTape baseWord x✝⁸ x✝¹) (rightSubTape baseWord x✝⁷ x✝))
(dirCfg qOf x✝⁴ x✝³ l₂ r₂) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitx✝¹⁰:ℕx✝⁹:Boolx✝⁸:List ℕx✝⁷:List ℕx✝⁶:ℕx✝⁵:List ℕx✝⁴:ℕx✝³:Boolx✝²:ℕx✝¹:ListBlank Γx✝:ListBlank Γh:simSubwords baseExit 0 x✝¹⁰ x✝⁹ x✝⁸ x✝⁷ x✝⁶ = some (x✝⁵, x✝⁴, x✝³, x✝²)⊢ x✝⁶ ≤ x✝² ∧
match placeSide (!x✝³) (concatSubwords baseWord x✝⁵) x✝¹ x✝ with
| (l₂, r₂) =>
ReachesIn M (x✝² - x✝⁶) (dirCfg qOf x✝¹⁰ x✝⁹ (leftSubTape baseWord x✝⁸ x✝¹) (rightSubTape baseWord x✝⁷ x✝))
(dirCfg qOf x✝⁴ x✝³ l₂ r₂) simp [simSubwords] at h All goals completed! 🐙
| _ + 1, q, true, lw, [], dt, v, q', dir', dtOut, l, r, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitn✝:ℕq:ℕlw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (n✝ + 1) q true lw [] dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord [] r))
(dirCfg qOf q' dir' l₂ r₂) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitn✝:ℕq:ℕlw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (n✝ + 1) q true lw [] dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord [] r))
(dirCfg qOf q' dir' l₂ r₂)
simp only [simSubwords, withNat_eq, Option.some.injEq, Prod.mk.injEq] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitn✝:ℕq:ℕlw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:lw.reverse = v ∧ q = q' ∧ true = dir' ∧ dt = dtOut⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord [] r))
(dirCfg qOf q' dir' l₂ r₂)
rcases h with ⟨rfl, rfl, rfl, rfl⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitn✝:ℕq:ℕlw:List ℕdt:ℕl:ListBlank Γr:ListBlank Γ⊢ dt ≤ dt ∧
match placeSide (!true) (concatSubwords baseWord lw.reverse) l r with
| (l₂, r₂) =>
ReachesIn M (dt - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord [] r))
(dirCfg qOf q true l₂ r₂)
refine ⟨Nat.le_refl dt, ?_⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitn✝:ℕq:ℕlw:List ℕdt:ℕl:ListBlank Γr:ListBlank Γ⊢ match placeSide (!true) (concatSubwords baseWord lw.reverse) l r with
| (l₂, r₂) =>
ReachesIn M (dt - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord [] r))
(dirCfg qOf q true l₂ r₂)
simp [placeSide, leftSubTape_eq, rightSubTape] All goals completed! 🐙
| fuel + 1, q, true, lw, a :: rw, dt, v, q', dir', dtOut, l, r, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (fuel + 1) q true lw (a :: rw) dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (fuel + 1) q true lw (a :: rw) dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
simp only [simSubwords, withNat_eq] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match baseExit q true a with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
rcases hb : baseExit q true a with _ | ⟨s', qNext, dNext, exDt⟩ none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match baseExit q true a with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q true a = none⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match baseExit q true a with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)s':ℕqNext:ℕdNext:BoolexDt:ℕhb:baseExit q true a = some (s', qNext, dNext, exDt)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
· none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match baseExit q true a with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q true a = none⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂) simp [hb] at h All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match baseExit q true a with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)s':ℕqNext:ℕdNext:BoolexDt:ℕhb:baseExit q true a = some (s', qNext, dNext, exDt)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂) rw [hb some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕdNext:BoolexDt:ℕh:(match some (s', qNext, dNext, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q true a = some (s', qNext, dNext, exDt)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)] at h some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕdNext:BoolexDt:ℕh:(match some (s', qNext, dNext, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q true a = some (s', qNext, dNext, exDt)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
have hex := hbase q true a s' qNext dNext exDt hb
(leftSubTape baseWord lw l) (rightSubTape baseWord rw r) some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕdNext:BoolexDt:ℕh:(match some (s', qNext, dNext, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q true a = some (s', qNext, dNext, exDt)hex:match placeSide true (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!dNext) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q true l₁ r₁) (dirCfg qOf qNext dNext l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
cases dNext some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕh:(match some (s', qNext, false, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q true a = some (s', qNext, false, exDt)hex:match placeSide true (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!false) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q true l₁ r₁) (dirCfg qOf qNext false l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕh:(match some (s', qNext, true, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q true a = some (s', qNext, true, exDt)hex:match placeSide true (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!true) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q true l₁ r₁) (dirCfg qOf qNext true l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
· some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕh:(match some (s', qNext, false, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q true a = some (s', qNext, false, exDt)hex:match placeSide true (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!false) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q true l₁ r₁) (dirCfg qOf qNext false l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂) simp only [Bool.false_eq_true, ↓reduceIte] at h some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, false, exDt)hex:match placeSide true (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!false) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q true l₁ r₁) (dirCfg qOf qNext false l₂ r₂)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
simp only [placeSide, ↓reduceIte, Bool.not_false] at hex some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
obtain ⟨hle, hreach⟩ :=
simSubwords_sound_aux hbase fuel qNext false lw (s' :: rw) (dt + exDt) v q' dir' dtOut
l r h some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (rightSubTape baseWord (s' :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
refine ⟨by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (rightSubTape baseWord (s' :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut omega All goals completed! 🐙, ?_⟩
have hsub : dtOut - dt = exDt + (dtOut - (dt + exDt)) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (fuel + 1) q true lw (a :: rw) dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂) omega some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (rightSubTape baseWord (s' :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
rw [hsub some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (rightSubTape baseWord (s' :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (exDt + (dtOut - (dt + exDt)))
(dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)] some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (rightSubTape baseWord (s' :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (exDt + (dtOut - (dt + exDt)))
(dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)
exact hex.trans hreach All goals completed! 🐙
· some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕh:(match some (s', qNext, true, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q true a = some (s', qNext, true, exDt)hex:match placeSide true (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!true) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q true l₁ r₁) (dirCfg qOf qNext true l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂) simp only [↓reduceIte] at h some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, true, exDt)hex:match placeSide true (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!true) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q true l₁ r₁) (dirCfg qOf qNext true l₂ r₂)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
simp only [placeSide, ↓reduceIte, Bool.not_true] at hex some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext true
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).1
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).2)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
obtain ⟨hle, hreach⟩ :=
simSubwords_sound_aux hbase fuel qNext true (s' :: lw) rw (dt + exDt) v q' dir' dtOut
l r h some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext true
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).1
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).2)hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext true (leftSubTape baseWord (s' :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
refine ⟨by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext true
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).1
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).2)hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext true (leftSubTape baseWord (s' :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut omega All goals completed! 🐙, ?_⟩
have hsub : dtOut - dt = exDt + (dtOut - (dt + exDt)) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (fuel + 1) q true lw (a :: rw) dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂) omega some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext true
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).1
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).2)hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext true (leftSubTape baseWord (s' :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r))
(dirCfg qOf q' dir' l₂ r₂)
rw [hsub some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext true
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).1
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).2)hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext true (leftSubTape baseWord (s' :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (exDt + (dtOut - (dt + exDt)))
(dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)] some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕlw:List ℕa:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q true a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q true (leftSubTape baseWord lw l) (baseWord a +> rightSubTape baseWord rw r))
(dirCfg qOf qNext true
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).1
(if false = true then (leftSubTape baseWord lw l, baseWord s' +> rightSubTape baseWord rw r)
else ((baseWord s').reverse +> leftSubTape baseWord lw l, rightSubTape baseWord rw r)).2)hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext true (leftSubTape baseWord (s' :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (exDt + (dtOut - (dt + exDt)))
(dirCfg qOf q true (leftSubTape baseWord lw l) (rightSubTape baseWord (a :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)
exact hex.trans hreach All goals completed! 🐙
| _ + 1, q, false, [], rw, dt, v, q', dir', dtOut, l, r, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitn✝:ℕq:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (n✝ + 1) q false [] rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord [] l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitn✝:ℕq:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (n✝ + 1) q false [] rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord [] l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
simp only [simSubwords, withNat_eq, Option.some.injEq, Prod.mk.injEq] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitn✝:ℕq:ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:rw = v ∧ q = q' ∧ false = dir' ∧ dt = dtOut⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord [] l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
rcases h with ⟨rfl, rfl, rfl, rfl⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitn✝:ℕq:ℕrw:List ℕdt:ℕl:ListBlank Γr:ListBlank Γ⊢ dt ≤ dt ∧
match placeSide (!false) (concatSubwords baseWord rw) l r with
| (l₂, r₂) =>
ReachesIn M (dt - dt) (dirCfg qOf q false (leftSubTape baseWord [] l) (rightSubTape baseWord rw r))
(dirCfg qOf q false l₂ r₂)
refine ⟨Nat.le_refl dt, ?_⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitn✝:ℕq:ℕrw:List ℕdt:ℕl:ListBlank Γr:ListBlank Γ⊢ match placeSide (!false) (concatSubwords baseWord rw) l r with
| (l₂, r₂) =>
ReachesIn M (dt - dt) (dirCfg qOf q false (leftSubTape baseWord [] l) (rightSubTape baseWord rw r))
(dirCfg qOf q false l₂ r₂)
simp [placeSide, leftSubTape, rightSubTape_eq] All goals completed! 🐙
| fuel + 1, q, false, a :: lw, rw, dt, v, q', dir', dtOut, l, r, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (fuel + 1) q false (a :: lw) rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (fuel + 1) q false (a :: lw) rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
simp only [simSubwords, withNat_eq] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match baseExit q false a with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
rcases hb : baseExit q false a with _ | ⟨s', qNext, dNext, exDt⟩ none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match baseExit q false a with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q false a = none⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match baseExit q false a with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)s':ℕqNext:ℕdNext:BoolexDt:ℕhb:baseExit q false a = some (s', qNext, dNext, exDt)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
· none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match baseExit q false a with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q false a = none⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂) simp [hb] at h All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:(match baseExit q false a with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)s':ℕqNext:ℕdNext:BoolexDt:ℕhb:baseExit q false a = some (s', qNext, dNext, exDt)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂) rw [hb some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕdNext:BoolexDt:ℕh:(match some (s', qNext, dNext, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q false a = some (s', qNext, dNext, exDt)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)] at h some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕdNext:BoolexDt:ℕh:(match some (s', qNext, dNext, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q false a = some (s', qNext, dNext, exDt)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
have hex := hbase q false a s' qNext dNext exDt hb
(leftSubTape baseWord lw l) (rightSubTape baseWord rw r) some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕdNext:BoolexDt:ℕh:(match some (s', qNext, dNext, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q false a = some (s', qNext, dNext, exDt)hex:match placeSide false (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!dNext) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q false l₁ r₁) (dirCfg qOf qNext dNext l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
cases dNext some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕh:(match some (s', qNext, false, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q false a = some (s', qNext, false, exDt)hex:match placeSide false (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!false) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q false l₁ r₁) (dirCfg qOf qNext false l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕh:(match some (s', qNext, true, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q false a = some (s', qNext, true, exDt)hex:match placeSide false (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!true) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q false l₁ r₁) (dirCfg qOf qNext true l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
· some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕh:(match some (s', qNext, false, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q false a = some (s', qNext, false, exDt)hex:match placeSide false (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!false) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q false l₁ r₁) (dirCfg qOf qNext false l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂) simp only [Bool.false_eq_true, ↓reduceIte] at h some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, false, exDt)hex:match placeSide false (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!false) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q false l₁ r₁) (dirCfg qOf qNext false l₂ r₂)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
simp only [placeSide, Bool.false_eq_true, ↓reduceIte, Bool.not_false] at hex some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
obtain ⟨hle, hreach⟩ :=
simSubwords_sound_aux hbase fuel qNext false lw (s' :: rw) (dt + exDt) v q' dir' dtOut
l r h some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (rightSubTape baseWord (s' :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
refine ⟨by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (rightSubTape baseWord (s' :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut omega All goals completed! 🐙, ?_⟩
have hsub : dtOut - dt = exDt + (dtOut - (dt + exDt)) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (fuel + 1) q false (a :: lw) rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂) omega some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (rightSubTape baseWord (s' :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
rw [hsub some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (rightSubTape baseWord (s' :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (exDt + (dtOut - (dt + exDt)))
(dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)] some.false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, false, exDt)h:simSubwords baseExit fuel qNext false lw (s' :: rw) (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (baseWord s' +> rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext false (leftSubTape baseWord lw l) (rightSubTape baseWord (s' :: rw) r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (exDt + (dtOut - (dt + exDt)))
(dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)
exact hex.trans hreach All goals completed! 🐙
· some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕh:(match some (s', qNext, true, exDt) with
| none => none
| some (s', q', dir', exDt) =>
if dir' = true then simSubwords baseExit fuel q' true (s' :: lw) rw (dt + exDt)
else simSubwords baseExit fuel q' false lw (s' :: rw) (dt + exDt)) =
some (v, q', dir', dtOut)hb:baseExit q false a = some (s', qNext, true, exDt)hex:match placeSide false (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!true) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q false l₁ r₁) (dirCfg qOf qNext true l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂) simp only [↓reduceIte] at h some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, true, exDt)hex:match placeSide false (baseWord a) (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₁, r₁) =>
match placeSide (!true) (baseWord s') (leftSubTape baseWord lw l) (rightSubTape baseWord rw r) with
| (l₂, r₂) => ReachesIn M exDt (dirCfg qOf q false l₁ r₁) (dirCfg qOf qNext true l₂ r₂)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
simp only [placeSide, Bool.false_eq_true, ↓reduceIte, Bool.not_true] at hex some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext true ((baseWord s').reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
obtain ⟨hle, hreach⟩ :=
simSubwords_sound_aux hbase fuel qNext true (s' :: lw) rw (dt + exDt) v q' dir' dtOut
l r h some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext true ((baseWord s').reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext true (leftSubTape baseWord (s' :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
refine ⟨by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext true ((baseWord s').reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext true (leftSubTape baseWord (s' :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)⊢ dt ≤ dtOut omega All goals completed! 🐙, ?_⟩
have hsub : dtOut - dt = exDt + (dtOut - (dt + exDt)) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (fuel + 1) q false (a :: lw) rw dt = some (v, q', dir', dtOut)⊢ dt ≤ dtOut ∧
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂) omega some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext true ((baseWord s').reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext true (leftSubTape baseWord (s' :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - dt) (dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r))
(dirCfg qOf q' dir' l₂ r₂)
rw [hsub some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext true ((baseWord s').reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext true (leftSubTape baseWord (s' :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (exDt + (dtOut - (dt + exDt)))
(dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)] some.true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitfuel:ℕq:ℕa:ℕlw:List ℕrw:List ℕdt:ℕv:List ℕq':ℕdir':BooldtOut:ℕl:ListBlank Γr:ListBlank Γs':ℕqNext:ℕexDt:ℕhb:baseExit q false a = some (s', qNext, true, exDt)h:simSubwords baseExit fuel qNext true (s' :: lw) rw (dt + exDt) = some (v, q', dir', dtOut)hex:ReachesIn M exDt (dirCfg qOf q false ((baseWord a).reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))
(dirCfg qOf qNext true ((baseWord s').reverse +> leftSubTape baseWord lw l) (rightSubTape baseWord rw r))hle:dt + exDt ≤ dtOuthreach:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dtOut - (dt + exDt))
(dirCfg qOf qNext true (leftSubTape baseWord (s' :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)hsub:dtOut - dt = exDt + (dtOut - (dt + exDt))⊢ match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (exDt + (dtOut - (dt + exDt)))
(dirCfg qOf q false (leftSubTape baseWord (a :: lw) l) (rightSubTape baseWord rw r)) (dirCfg qOf q' dir' l₂ r₂)
exact hex.trans hreach All goals completed! 🐙
Soundness of runCompositeExit: lifts base-word exits to composite subword exits.
theorem runCompositeExit_sound {M : Machine Γ Λ} {qOf : ℕ → Λ} {baseWord : ℕ → List Γ}
{baseExit : ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)}
(hbase : BaseExitSound M qOf baseWord baseExit)
{u : List ℕ} {q : ℕ} {dir : Bool} {v : List ℕ} {q' : ℕ} {dir' : Bool} {dt : ℕ}
(h : runCompositeExit baseExit u q dir = some (v, q', dir', dt)) :
WordExit M qOf (concatSubwords baseWord u) q dir (concatSubwords baseWord v) q' dir' dt := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕdir:Boolv:List ℕq':ℕdir':Booldt:ℕh:runCompositeExit baseExit u q dir = some (v, q', dir', dt)⊢ WordExit M qOf (concatSubwords baseWord u) q dir (concatSubwords baseWord v) q' dir' dt
intro l r Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕdir:Boolv:List ℕq':ℕdir':Booldt:ℕh:runCompositeExit baseExit u q dir = some (v, q', dir', dt)l:ListBlank Γr:ListBlank Γ⊢ match placeSide dir (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q dir l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
unfold runCompositeExit at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕdir:Boolv:List ℕq':ℕdir':Booldt:ℕh:(withNat (u.length * 16 + 16) fun fuel ↦
if dir = true then simSubwords baseExit fuel q true [] u 0 else simSubwords baseExit fuel q false u.reverse [] 0) =
some (v, q', dir', dt)l:ListBlank Γr:ListBlank Γ⊢ match placeSide dir (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q dir l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
rw [withNat_eq Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕdir:Boolv:List ℕq':ℕdir':Booldt:ℕh:(if dir = true then simSubwords baseExit (u.length * 16 + 16) q true [] u 0
else simSubwords baseExit (u.length * 16 + 16) q false u.reverse [] 0) =
some (v, q', dir', dt)l:ListBlank Γr:ListBlank Γ⊢ match placeSide dir (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q dir l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕdir:Boolv:List ℕq':ℕdir':Booldt:ℕh:(if dir = true then simSubwords baseExit (u.length * 16 + 16) q true [] u 0
else simSubwords baseExit (u.length * 16 + 16) q false u.reverse [] 0) =
some (v, q', dir', dt)l:ListBlank Γr:ListBlank Γ⊢ match placeSide dir (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q dir l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
cases dir false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕv:List ℕq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:(if false = true then simSubwords baseExit (u.length * 16 + 16) q true [] u 0
else simSubwords baseExit (u.length * 16 + 16) q false u.reverse [] 0) =
some (v, q', dir', dt)⊢ match placeSide false (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q false l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕv:List ℕq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:(if true = true then simSubwords baseExit (u.length * 16 + 16) q true [] u 0
else simSubwords baseExit (u.length * 16 + 16) q false u.reverse [] 0) =
some (v, q', dir', dt)⊢ match placeSide true (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q true l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
· false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕv:List ℕq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:(if false = true then simSubwords baseExit (u.length * 16 + 16) q true [] u 0
else simSubwords baseExit (u.length * 16 + 16) q false u.reverse [] 0) =
some (v, q', dir', dt)⊢ match placeSide false (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q false l₁ r₁) (dirCfg qOf q' dir' l₂ r₂) simp only [Bool.false_eq_true, ↓reduceIte] at h false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕv:List ℕq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (u.length * 16 + 16) q false u.reverse [] 0 = some (v, q', dir', dt)⊢ match placeSide false (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q false l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
have ⟨_, hr⟩ := simSubwords_sound_aux hbase (u.length * 16 + 16) q false u.reverse [] 0
v q' dir' dt l r h false Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕv:List ℕq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (u.length * 16 + 16) q false u.reverse [] 0 = some (v, q', dir', dt)left✝:0 ≤ dthr:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dt - 0) (dirCfg qOf q false (leftSubTape baseWord u.reverse l) (rightSubTape baseWord [] r))
(dirCfg qOf q' dir' l₂ r₂)⊢ match placeSide false (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q false l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
simpa [placeSide, leftSubTape_reverse_eq, rightSubTape] using hr All goals completed! 🐙
· true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕv:List ℕq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:(if true = true then simSubwords baseExit (u.length * 16 + 16) q true [] u 0
else simSubwords baseExit (u.length * 16 + 16) q false u.reverse [] 0) =
some (v, q', dir', dt)⊢ match placeSide true (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q true l₁ r₁) (dirCfg qOf q' dir' l₂ r₂) simp only [↓reduceIte] at h true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕv:List ℕq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (u.length * 16 + 16) q true [] u 0 = some (v, q', dir', dt)⊢ match placeSide true (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q true l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
have ⟨_, hr⟩ := simSubwords_sound_aux hbase (u.length * 16 + 16) q true [] u 0
v q' dir' dt l r h true Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛbaseWord:ℕ → List ΓbaseExit:ℕ → Bool → ℕ → Option (ℕ × ℕ × Bool × ℕ)hbase:BaseExitSound M qOf baseWord baseExitu:List ℕq:ℕv:List ℕq':ℕdir':Booldt:ℕl:ListBlank Γr:ListBlank Γh:simSubwords baseExit (u.length * 16 + 16) q true [] u 0 = some (v, q', dir', dt)left✝:0 ≤ dthr:match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) =>
ReachesIn M (dt - 0) (dirCfg qOf q true (leftSubTape baseWord [] l) (rightSubTape baseWord u r))
(dirCfg qOf q' dir' l₂ r₂)⊢ match placeSide true (concatSubwords baseWord u) l r with
| (l₁, r₁) =>
match placeSide (!dir') (concatSubwords baseWord v) l r with
| (l₂, r₂) => ReachesIn M dt (dirCfg qOf q true l₁ r₁) (dirCfg qOf q' dir' l₂ r₂)
simpa [placeSide, leftSubTape, rightSubTape_eq] using hr All goals completed! 🐙Concrete RLE Stack Configurations and Multi-Step Reachability
A concrete run of count copies of vocabulary word sym (sym = 0 denotes the blank word).
structure Run whereVocabulary index of the repeated spatial word.
sym : ℕ
Repetition count (count ≥ 1 in normalized stacks).
count : ℕ
deriving DecidableEq, Inhabited
Concrete RLE configuration with head state q, direction dir, and RLE half-tape stacks.
structure EntryCfg whereCurrent state index.
q : ℕ
Head direction (true = right, false = left).
dir : BoolLeft half-tape stack (nearest-to-head run first).
left : List RunRight half-tape stack (nearest-to-head run first).
right : List Run
deriving DecidableEq, Inhabited
Push count ≥ 1 copies of sym onto stk, suppressing leading blank runs (sym = 0 on [])
and merging adjacent runs of the same word.
@[inline]
def pushLit (sym count : ℕ) : List Run → List Run
| [] => if Nat.beq sym 0 then [] else [⟨sym, count⟩]
| ⟨ts, tc⟩ :: rest =>
if Nat.beq ts sym then withNat (tc + count) fun c ↦ ⟨ts, c⟩ :: rest
else ⟨sym, count⟩ :: ⟨ts, tc⟩ :: rest
Safe push handling count = 0 as a no-op.
def pushRun (sym count : ℕ) (stk : List Run) : List Run :=
if Nat.beq count 0 then stk else pushLit sym count stk
Push a spatial left-to-right list of (sym, count) runs onto a left RLE stack so the last pair
in the list sits closest to the head.
def pushRunsLeft : List (ℕ × ℕ) → List Run → List Run
| [], stk => stk
| (s, n) :: rest, stk => pushRunsLeft rest (pushRun s n stk)
Evaluate an RLE stack on side side (true = right stack using wordOf w ^ c, false = left
stack using (wordOf w).reverse ^ c).
def evalSide (side : Bool) (wordOf : ℕ → List Γ) : List Run → ListBlank Γ
| [] => default
| ⟨w, c⟩ :: rest =>
if side then ListBlank.append (wordOf w ^ c) (evalSide true wordOf rest)
else ListBlank.append ((wordOf w).reverse ^ c) (evalSide false wordOf rest)
Evaluate a concrete EntryCfg into a BusyBeaver.Cfg Γ Λ.
def evalEntryCfg (qOf : ℕ → Λ) (wordOf : ℕ → List Γ) (c : EntryCfg) : Cfg Γ Λ :=
dirCfg qOf c.q c.dir (evalSide false wordOf c.left) (evalSide true wordOf c.right)
Soundness of pushLit when wordOf 0 consists solely of blank symbols (default).
theorem evalSide_pushLit {wordOf : ℕ → List Γ} (hz : ∀ x ∈ wordOf 0, x = default)
(side : Bool) (sym count : ℕ) (stk : List Run) :
evalSide side wordOf (pushLit sym count stk) =
if side then ListBlank.append (wordOf sym ^ count) (evalSide true wordOf stk)
else ListBlank.append ((wordOf sym).reverse ^ count) (evalSide false wordOf stk) := by Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Run⊢ evalSide side wordOf (pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk
have hzRev : ∀ x ∈ (wordOf 0).reverse, x = default := by
intro x hx Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Runx:Γhx:x ∈ (wordOf 0).reverse⊢ x = default; exact hz x (List.mem_reverse.mp hx) Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List RunhzRev:∀ x ∈ (wordOf 0).reverse, x = default⊢ evalSide side wordOf (pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk
cases stk with
| nil => nil Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = default⊢ evalSide side wordOf (pushLit sym count []) =
if side = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf []
simp only [pushLit] nil Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = default⊢ evalSide side wordOf (if sym.beq 0 = true then [] else [{ sym := sym, count := count }]) =
if side = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf []
by_cases hs : Nat.beq sym 0 = true pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:sym.beq 0 = true⊢ evalSide side wordOf (if sym.beq 0 = true then [] else [{ sym := sym, count := count }]) =
if side = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf []neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:¬sym.beq 0 = true⊢ evalSide side wordOf (if sym.beq 0 = true then [] else [{ sym := sym, count := count }]) =
if side = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf []
· pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:sym.beq 0 = true⊢ evalSide side wordOf (if sym.beq 0 = true then [] else [{ sym := sym, count := count }]) =
if side = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf [] have h0 : sym = 0 := Nat.eq_of_beq_eq_true hs pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:sym.beq 0 = trueh0:sym = 0⊢ evalSide side wordOf (if sym.beq 0 = true then [] else [{ sym := sym, count := count }]) =
if side = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf []
subst h0 pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:Nat.beq 0 0 = true⊢ evalSide side wordOf (if Nat.beq 0 0 = true then [] else [{ sym := 0, count := count }]) =
if side = true then wordOf 0 ^ count +> evalSide true wordOf []
else (wordOf 0).reverse ^ count +> evalSide false wordOf []
cases side pos.false Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:Nat.beq 0 0 = true⊢ evalSide false wordOf (if Nat.beq 0 0 = true then [] else [{ sym := 0, count := count }]) =
if false = true then wordOf 0 ^ count +> evalSide true wordOf []
else (wordOf 0).reverse ^ count +> evalSide false wordOf []pos.true Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:Nat.beq 0 0 = true⊢ evalSide true wordOf (if Nat.beq 0 0 = true then [] else [{ sym := 0, count := count }]) =
if true = true then wordOf 0 ^ count +> evalSide true wordOf []
else (wordOf 0).reverse ^ count +> evalSide false wordOf [] <;> pos.false Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:Nat.beq 0 0 = true⊢ evalSide false wordOf (if Nat.beq 0 0 = true then [] else [{ sym := 0, count := count }]) =
if false = true then wordOf 0 ^ count +> evalSide true wordOf []
else (wordOf 0).reverse ^ count +> evalSide false wordOf []pos.true Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:Nat.beq 0 0 = true⊢ evalSide true wordOf (if Nat.beq 0 0 = true then [] else [{ sym := 0, count := count }]) =
if true = true then wordOf 0 ^ count +> evalSide true wordOf []
else (wordOf 0).reverse ^ count +> evalSide false wordOf [] simp [evalSide, lb_blank_pow _ hz, lb_blank_pow _ hzRev] All goals completed! 🐙
· neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:¬sym.beq 0 = true⊢ evalSide side wordOf (if sym.beq 0 = true then [] else [{ sym := sym, count := count }]) =
if side = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf [] have hne : Nat.beq sym 0 = false := Bool.eq_false_iff.mpr hs neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:¬sym.beq 0 = truehne:sym.beq 0 = false⊢ evalSide side wordOf (if sym.beq 0 = true then [] else [{ sym := sym, count := count }]) =
if side = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf []
rw [hne neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:¬sym.beq 0 = truehne:sym.beq 0 = false⊢ evalSide side wordOf (if false = true then [] else [{ sym := sym, count := count }]) =
if side = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf []] neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:¬sym.beq 0 = truehne:sym.beq 0 = false⊢ evalSide side wordOf (if false = true then [] else [{ sym := sym, count := count }]) =
if side = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf []
cases side neg.false Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:¬sym.beq 0 = truehne:sym.beq 0 = false⊢ evalSide false wordOf (if false = true then [] else [{ sym := sym, count := count }]) =
if false = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf []neg.true Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:¬sym.beq 0 = truehne:sym.beq 0 = false⊢ evalSide true wordOf (if false = true then [] else [{ sym := sym, count := count }]) =
if true = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf [] <;> neg.false Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:¬sym.beq 0 = truehne:sym.beq 0 = false⊢ evalSide false wordOf (if false = true then [] else [{ sym := sym, count := count }]) =
if false = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf []neg.true Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulths:¬sym.beq 0 = truehne:sym.beq 0 = false⊢ evalSide true wordOf (if false = true then [] else [{ sym := sym, count := count }]) =
if true = true then wordOf sym ^ count +> evalSide true wordOf []
else (wordOf sym).reverse ^ count +> evalSide false wordOf [] rfl All goals completed! 🐙
| cons top rest => cons Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaulttop:Runrest:List Run⊢ evalSide side wordOf (pushLit sym count (top :: rest)) =
if side = true then wordOf sym ^ count +> evalSide true wordOf (top :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf (top :: rest)
rcases top with ⟨ts, tc⟩ cons Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕ⊢ evalSide side wordOf (pushLit sym count ({ sym := ts, count := tc } :: rest)) =
if side = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)
simp only [pushLit] cons Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕ⊢ evalSide side wordOf
(if ts.beq sym = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if side = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)
by_cases hs : Nat.beq ts sym = true pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:ts.beq sym = true⊢ evalSide side wordOf
(if ts.beq sym = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if side = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:¬ts.beq sym = true⊢ evalSide side wordOf
(if ts.beq sym = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if side = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)
· pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:ts.beq sym = true⊢ evalSide side wordOf
(if ts.beq sym = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if side = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest) have heq : ts = sym := Nat.eq_of_beq_eq_true hs pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:ts.beq sym = trueheq:ts = sym⊢ evalSide side wordOf
(if ts.beq sym = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if side = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)
subst heq pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:ts.beq ts = true⊢ evalSide side wordOf
(if ts.beq ts = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := ts, count := count } :: { sym := ts, count := tc } :: rest) =
if side = true then wordOf ts ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf ts).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)
simp only [hs, ↓reduceIte, withNat_eq] pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:ts.beq ts = true⊢ evalSide side wordOf ({ sym := ts, count := tc + count } :: rest) =
if side = true then wordOf ts ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf ts).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)
cases side pos.false Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:ts.beq ts = true⊢ evalSide false wordOf ({ sym := ts, count := tc + count } :: rest) =
if false = true then wordOf ts ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf ts).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)pos.true Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:ts.beq ts = true⊢ evalSide true wordOf ({ sym := ts, count := tc + count } :: rest) =
if true = true then wordOf ts ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf ts).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest) <;> pos.false Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:ts.beq ts = true⊢ evalSide false wordOf ({ sym := ts, count := tc + count } :: rest) =
if false = true then wordOf ts ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf ts).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)pos.true Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:ts.beq ts = true⊢ evalSide true wordOf ({ sym := ts, count := tc + count } :: rest) =
if true = true then wordOf ts ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf ts).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)
simp [evalSide, ListBlank.append_append, ← list_pow_add, Nat.add_comm] All goals completed! 🐙
· neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:¬ts.beq sym = true⊢ evalSide side wordOf
(if ts.beq sym = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if side = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest) have hne : Nat.beq ts sym = false := Bool.eq_false_iff.mpr hs neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:¬ts.beq sym = truehne:ts.beq sym = false⊢ evalSide side wordOf
(if ts.beq sym = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if side = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)
rw [hne neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:¬ts.beq sym = truehne:ts.beq sym = false⊢ evalSide side wordOf
(if false = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if side = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)] neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:¬ts.beq sym = truehne:ts.beq sym = false⊢ evalSide side wordOf
(if false = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if side = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)
cases side neg.false Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:¬ts.beq sym = truehne:ts.beq sym = false⊢ evalSide false wordOf
(if false = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if false = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)neg.true Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:¬ts.beq sym = truehne:ts.beq sym = false⊢ evalSide true wordOf
(if false = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if true = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest) <;> neg.false Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:¬ts.beq sym = truehne:ts.beq sym = false⊢ evalSide false wordOf
(if false = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if false = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest)neg.true Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕcount:ℕhzRev:∀ x ∈ (wordOf 0).reverse, x = defaultrest:List Runts:ℕtc:ℕhs:¬ts.beq sym = truehne:ts.beq sym = false⊢ evalSide true wordOf
(if false = true then withNat (tc + count) fun c ↦ { sym := ts, count := c } :: rest
else { sym := sym, count := count } :: { sym := ts, count := tc } :: rest) =
if true = true then wordOf sym ^ count +> evalSide true wordOf ({ sym := ts, count := tc } :: rest)
else (wordOf sym).reverse ^ count +> evalSide false wordOf ({ sym := ts, count := tc } :: rest) rfl All goals completed! 🐙theorem evalSide_pushRun {wordOf : ℕ → List Γ} (hz : ∀ x ∈ wordOf 0, x = default)
(side : Bool) (sym count : ℕ) (stk : List Run) :
evalSide side wordOf (pushRun sym count stk) =
if side then ListBlank.append (wordOf sym ^ count) (evalSide true wordOf stk)
else ListBlank.append ((wordOf sym).reverse ^ count) (evalSide false wordOf stk) := by Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Run⊢ evalSide side wordOf (pushRun sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk
unfold pushRun Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Run⊢ evalSide side wordOf (if count.beq 0 = true then stk else pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk
by_cases hc : Nat.beq count 0 = true pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Runhc:count.beq 0 = true⊢ evalSide side wordOf (if count.beq 0 = true then stk else pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stkneg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Runhc:¬count.beq 0 = true⊢ evalSide side wordOf (if count.beq 0 = true then stk else pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk
· pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Runhc:count.beq 0 = true⊢ evalSide side wordOf (if count.beq 0 = true then stk else pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk have h0 : count = 0 := Nat.eq_of_beq_eq_true hc pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Runhc:count.beq 0 = trueh0:count = 0⊢ evalSide side wordOf (if count.beq 0 = true then stk else pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk
subst h0 pos Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕstk:List Runhc:Nat.beq 0 0 = true⊢ evalSide side wordOf (if Nat.beq 0 0 = true then stk else pushLit sym 0 stk) =
if side = true then wordOf sym ^ 0 +> evalSide true wordOf stk
else (wordOf sym).reverse ^ 0 +> evalSide false wordOf stk
cases side pos.false Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕstk:List Runhc:Nat.beq 0 0 = true⊢ evalSide false wordOf (if Nat.beq 0 0 = true then stk else pushLit sym 0 stk) =
if false = true then wordOf sym ^ 0 +> evalSide true wordOf stk
else (wordOf sym).reverse ^ 0 +> evalSide false wordOf stkpos.true Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕstk:List Runhc:Nat.beq 0 0 = true⊢ evalSide true wordOf (if Nat.beq 0 0 = true then stk else pushLit sym 0 stk) =
if true = true then wordOf sym ^ 0 +> evalSide true wordOf stk
else (wordOf sym).reverse ^ 0 +> evalSide false wordOf stk <;> pos.false Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕstk:List Runhc:Nat.beq 0 0 = true⊢ evalSide false wordOf (if Nat.beq 0 0 = true then stk else pushLit sym 0 stk) =
if false = true then wordOf sym ^ 0 +> evalSide true wordOf stk
else (wordOf sym).reverse ^ 0 +> evalSide false wordOf stkpos.true Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultsym:ℕstk:List Runhc:Nat.beq 0 0 = true⊢ evalSide true wordOf (if Nat.beq 0 0 = true then stk else pushLit sym 0 stk) =
if true = true then wordOf sym ^ 0 +> evalSide true wordOf stk
else (wordOf sym).reverse ^ 0 +> evalSide false wordOf stk simp All goals completed! 🐙
· neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Runhc:¬count.beq 0 = true⊢ evalSide side wordOf (if count.beq 0 = true then stk else pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk have hne : Nat.beq count 0 = false := Bool.eq_false_iff.mpr hc neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Runhc:¬count.beq 0 = truehne:count.beq 0 = false⊢ evalSide side wordOf (if count.beq 0 = true then stk else pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk
rw [hne neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Runhc:¬count.beq 0 = truehne:count.beq 0 = false⊢ evalSide side wordOf (if false = true then stk else pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk] neg Γ:Type u_1inst✝:Inhabited ΓwordOf:ℕ → List Γhz:∀ x ∈ wordOf 0, x = defaultside:Boolsym:ℕcount:ℕstk:List Runhc:¬count.beq 0 = truehne:count.beq 0 = false⊢ evalSide side wordOf (if false = true then stk else pushLit sym count stk) =
if side = true then wordOf sym ^ count +> evalSide true wordOf stk
else (wordOf sym).reverse ^ count +> evalSide false wordOf stk
exact evalSide_pushLit hz side sym count stk All goals completed! 🐙
Soundness predicate for a single-step concrete RLE transition function stepFn.
def StepFnSound (M : Machine Γ Λ) (qOf : ℕ → Λ) (wordOf : ℕ → List Γ)
(stepFn : ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)) : Prop :=
∀ q dir l r dt c',
stepFn q dir l r = some (dt, c') →
ReachesIn M dt (evalEntryCfg qOf wordOf ⟨q, dir, l, r⟩) (evalEntryCfg qOf wordOf c')
Execute exactly fuel accelerated RLE steps using stepFn, accumulating exact TM steps.
def runExact (stepFn : ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)) :
ℕ → ℕ → EntryCfg → Option (ℕ × EntryCfg)
| 0, acc, c => some (acc, c)
| fuel + 1, acc, ⟨q, dir, l, r⟩ =>
match stepFn q dir l r with
| none => none
| some (dt, c') => withNat (acc + dt) fun acc' ↦ runExact stepFn fuel acc' c'
Boolean check that runExact stepFn fuel 0 c yields (expDt, expC).
def checkRunExact (stepFn : ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg))
(fuel expDt : ℕ) (c expC : EntryCfg) : Bool :=
match runExact stepFn fuel 0 c with
| none => false
| some (dt, c') => Nat.beq dt expDt && (c' == expC)private theorem runExact_sound_aux {M : Machine Γ Λ} {qOf : ℕ → Λ} {wordOf : ℕ → List Γ}
{stepFn : ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)}
(hs : StepFnSound M qOf wordOf stepFn) :
∀ (fuel acc : ℕ) (c : EntryCfg) (accOut : ℕ) (cOut : EntryCfg),
runExact stepFn fuel acc c = some (accOut, cOut) →
acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf cOut)
| 0, acc, c, accOut, cOut, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnacc:ℕc:EntryCfgaccOut:ℕcOut:EntryCfgh:runExact stepFn 0 acc c = some (accOut, cOut)⊢ acc ≤ accOut ∧ ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf cOut) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnacc:ℕc:EntryCfgaccOut:ℕcOut:EntryCfgh:runExact stepFn 0 acc c = some (accOut, cOut)⊢ acc ≤ accOut ∧ ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf cOut)
simp only [runExact, Option.some.injEq, Prod.mk.injEq] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnacc:ℕc:EntryCfgaccOut:ℕcOut:EntryCfgh:acc = accOut ∧ c = cOut⊢ acc ≤ accOut ∧ ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf cOut)
rcases h with ⟨rfl, rfl⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnacc:ℕc:EntryCfg⊢ acc ≤ acc ∧ ReachesIn M (acc - acc) (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c)
exact ⟨Nat.le_refl acc, by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnacc:ℕc:EntryCfg⊢ ReachesIn M (acc - acc) (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c) simp All goals completed! 🐙⟩
| fuel + 1, acc, ⟨q, dir, l, r⟩, accOut, cOut, h => Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgh:runExact stepFn (fuel + 1) acc { q := q, dir := dir, left := l, right := r } = some (accOut, cOut)⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut) by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgh:runExact stepFn (fuel + 1) acc { q := q, dir := dir, left := l, right := r } = some (accOut, cOut)⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)
simp only [runExact] at h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgh:(match stepFn q dir l r with
| none => none
| some (dt, c') => withNat (acc + dt) fun acc' ↦ runExact stepFn fuel acc' c') =
some (accOut, cOut)⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)
rcases hst : stepFn q dir l r with _ | ⟨dt, c'⟩ none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgh:(match stepFn q dir l r with
| none => none
| some (dt, c') => withNat (acc + dt) fun acc' ↦ runExact stepFn fuel acc' c') =
some (accOut, cOut)hst:stepFn q dir l r = none⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgh:(match stepFn q dir l r with
| none => none
| some (dt, c') => withNat (acc + dt) fun acc' ↦ runExact stepFn fuel acc' c') =
some (accOut, cOut)dt:ℕc':EntryCfghst:stepFn q dir l r = some (dt, c')⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)
· none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgh:(match stepFn q dir l r with
| none => none
| some (dt, c') => withNat (acc + dt) fun acc' ↦ runExact stepFn fuel acc' c') =
some (accOut, cOut)hst:stepFn q dir l r = none⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut) simp [hst] at h All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgh:(match stepFn q dir l r with
| none => none
| some (dt, c') => withNat (acc + dt) fun acc' ↦ runExact stepFn fuel acc' c') =
some (accOut, cOut)dt:ℕc':EntryCfghst:stepFn q dir l r = some (dt, c')⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut) rw [hst some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgdt:ℕc':EntryCfgh:(match some (dt, c') with
| none => none
| some (dt, c') => withNat (acc + dt) fun acc' ↦ runExact stepFn fuel acc' c') =
some (accOut, cOut)hst:stepFn q dir l r = some (dt, c')⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)] at h some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgdt:ℕc':EntryCfgh:(match some (dt, c') with
| none => none
| some (dt, c') => withNat (acc + dt) fun acc' ↦ runExact stepFn fuel acc' c') =
some (accOut, cOut)hst:stepFn q dir l r = some (dt, c')⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)
simp only [withNat_eq] at h some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgdt:ℕc':EntryCfghst:stepFn q dir l r = some (dt, c')h:runExact stepFn fuel (acc + dt) c' = some (accOut, cOut)⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)
obtain ⟨hle, hrest⟩ := runExact_sound_aux hs fuel (acc + dt) c' accOut cOut h some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgdt:ℕc':EntryCfghst:stepFn q dir l r = some (dt, c')h:runExact stepFn fuel (acc + dt) c' = some (accOut, cOut)hle:acc + dt ≤ accOuthrest:ReachesIn M (accOut - (acc + dt)) (evalEntryCfg qOf wordOf c') (evalEntryCfg qOf wordOf cOut)⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)
have h1 := hs q dir l r dt c' hst some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgdt:ℕc':EntryCfghst:stepFn q dir l r = some (dt, c')h:runExact stepFn fuel (acc + dt) c' = some (accOut, cOut)hle:acc + dt ≤ accOuthrest:ReachesIn M (accOut - (acc + dt)) (evalEntryCfg qOf wordOf c') (evalEntryCfg qOf wordOf cOut)h1:ReachesIn M dt (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r }) (evalEntryCfg qOf wordOf c')⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)
refine ⟨by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgdt:ℕc':EntryCfghst:stepFn q dir l r = some (dt, c')h:runExact stepFn fuel (acc + dt) c' = some (accOut, cOut)hle:acc + dt ≤ accOuthrest:ReachesIn M (accOut - (acc + dt)) (evalEntryCfg qOf wordOf c') (evalEntryCfg qOf wordOf cOut)h1:ReachesIn M dt (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r }) (evalEntryCfg qOf wordOf c')⊢ acc ≤ accOut omega All goals completed! 🐙, ?_⟩
have hsub : accOut - acc = dt + (accOut - (acc + dt)) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgh:runExact stepFn (fuel + 1) acc { q := q, dir := dir, left := l, right := r } = some (accOut, cOut)⊢ acc ≤ accOut ∧
ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut) omega some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgdt:ℕc':EntryCfghst:stepFn q dir l r = some (dt, c')h:runExact stepFn fuel (acc + dt) c' = some (accOut, cOut)hle:acc + dt ≤ accOuthrest:ReachesIn M (accOut - (acc + dt)) (evalEntryCfg qOf wordOf c') (evalEntryCfg qOf wordOf cOut)h1:ReachesIn M dt (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r }) (evalEntryCfg qOf wordOf c')hsub:accOut - acc = dt + (accOut - (acc + dt))⊢ ReachesIn M (accOut - acc) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)
rw [hsub some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgdt:ℕc':EntryCfghst:stepFn q dir l r = some (dt, c')h:runExact stepFn fuel (acc + dt) c' = some (accOut, cOut)hle:acc + dt ≤ accOuthrest:ReachesIn M (accOut - (acc + dt)) (evalEntryCfg qOf wordOf c') (evalEntryCfg qOf wordOf cOut)h1:ReachesIn M dt (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r }) (evalEntryCfg qOf wordOf c')hsub:accOut - acc = dt + (accOut - (acc + dt))⊢ ReachesIn M (dt + (accOut - (acc + dt))) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)] some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFnfuel:ℕacc:ℕq:ℕdir:Booll:List Runr:List RunaccOut:ℕcOut:EntryCfgdt:ℕc':EntryCfghst:stepFn q dir l r = some (dt, c')h:runExact stepFn fuel (acc + dt) c' = some (accOut, cOut)hle:acc + dt ≤ accOuthrest:ReachesIn M (accOut - (acc + dt)) (evalEntryCfg qOf wordOf c') (evalEntryCfg qOf wordOf cOut)h1:ReachesIn M dt (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r }) (evalEntryCfg qOf wordOf c')hsub:accOut - acc = dt + (accOut - (acc + dt))⊢ ReachesIn M (dt + (accOut - (acc + dt))) (evalEntryCfg qOf wordOf { q := q, dir := dir, left := l, right := r })
(evalEntryCfg qOf wordOf cOut)
exact h1.trans hrest All goals completed! 🐙
Inductive certificate tree chaining kernel-checked checkRunExact chunks with O(1) proof
composition.
inductive EntryReaches (stepFn : ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)) :
ℕ → EntryCfg → EntryCfg → Prop whereZero-step reflexive reachability.
| refl (c : EntryCfg) : EntryReaches stepFn 0 c c
Single kernel-checked fuel-loop chunk.
| chunk {fuel dt : ℕ} {c c' : EntryCfg} :
checkRunExact stepFn fuel dt c c' = true →
EntryReaches stepFn dt c c'Transitive composition of two chunks.
| trans {d₁ d₂ : ℕ} {c₁ c₂ c₃ : EntryCfg} :
EntryReaches stepFn d₁ c₁ c₂ → EntryReaches stepFn d₂ c₂ c₃ →
EntryReaches stepFn (d₁ + d₂) c₁ c₃
Cast the accumulated step sum d₁ to a normalized ℕ literal d₂ via Nat.beq.
theorem EntryReaches.cast_dt {stepFn : ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)}
{d₁ d₂ : ℕ} {c₁ c₂ : EntryCfg}
(h : EntryReaches stepFn d₁ c₁ c₂) (heq : Nat.beq d₁ d₂ = true) :
EntryReaches stepFn d₂ c₁ c₂ := by stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕd₂:ℕc₁:EntryCfgc₂:EntryCfgh:EntryReaches stepFn d₁ c₁ c₂heq:d₁.beq d₂ = true⊢ EntryReaches stepFn d₂ c₁ c₂
have hd : d₁ = d₂ := Nat.eq_of_beq_eq_true heq stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕd₂:ℕc₁:EntryCfgc₂:EntryCfgh:EntryReaches stepFn d₁ c₁ c₂heq:d₁.beq d₂ = truehd:d₁ = d₂⊢ EntryReaches stepFn d₂ c₁ c₂
exact hd ▸ h All goals completed! 🐙
Boolean check that (d₁, c₁, c₂) matches target (d₂, c₁', c₂').
def checkEntryEnds (d₁ d₂ : ℕ) (c₁ c₁' c₂ c₂' : EntryCfg) : Bool :=
Nat.beq d₁ d₂ && (c₁ == c₁') && (c₂ == c₂')
Cast (d₁, c₁, c₂) to target expressions (d₂, c₁', c₂') via a kernel-checked Bool
certificate, avoiding elaborator isDefEq unfolding on large closed-form milestones.
theorem EntryReaches.cast_ends {stepFn : ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)}
{d₁ d₂ : ℕ} {c₁ c₁' c₂ c₂' : EntryCfg}
(h : EntryReaches stepFn d₁ c₁ c₂)
(heq : checkEntryEnds d₁ d₂ c₁ c₁' c₂ c₂' = true) :
EntryReaches stepFn d₂ c₁' c₂' := by stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕd₂:ℕc₁:EntryCfgc₁':EntryCfgc₂:EntryCfgc₂':EntryCfgh:EntryReaches stepFn d₁ c₁ c₂heq:checkEntryEnds d₁ d₂ c₁ c₁' c₂ c₂' = true⊢ EntryReaches stepFn d₂ c₁' c₂'
unfold checkEntryEnds at heq stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕd₂:ℕc₁:EntryCfgc₁':EntryCfgc₂:EntryCfgc₂':EntryCfgh:EntryReaches stepFn d₁ c₁ c₂heq:(d₁.beq d₂ && c₁ == c₁' && c₂ == c₂') = true⊢ EntryReaches stepFn d₂ c₁' c₂'
simp only [Bool.and_eq_true] at heq stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕd₂:ℕc₁:EntryCfgc₁':EntryCfgc₂:EntryCfgc₂':EntryCfgh:EntryReaches stepFn d₁ c₁ c₂heq:(d₁.beq d₂ = true ∧ (c₁ == c₁') = true) ∧ (c₂ == c₂') = true⊢ EntryReaches stepFn d₂ c₁' c₂'
have hd : d₁ = d₂ := Nat.eq_of_beq_eq_true heq.1.1 stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕd₂:ℕc₁:EntryCfgc₁':EntryCfgc₂:EntryCfgc₂':EntryCfgh:EntryReaches stepFn d₁ c₁ c₂heq:(d₁.beq d₂ = true ∧ (c₁ == c₁') = true) ∧ (c₂ == c₂') = truehd:d₁ = d₂⊢ EntryReaches stepFn d₂ c₁' c₂'
have hc1 : c₁ = c₁' := eq_of_beq heq.1.2 stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕd₂:ℕc₁:EntryCfgc₁':EntryCfgc₂:EntryCfgc₂':EntryCfgh:EntryReaches stepFn d₁ c₁ c₂heq:(d₁.beq d₂ = true ∧ (c₁ == c₁') = true) ∧ (c₂ == c₂') = truehd:d₁ = d₂hc1:c₁ = c₁'⊢ EntryReaches stepFn d₂ c₁' c₂'
have hc2 : c₂ = c₂' := eq_of_beq heq.2 stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕd₂:ℕc₁:EntryCfgc₁':EntryCfgc₂:EntryCfgc₂':EntryCfgh:EntryReaches stepFn d₁ c₁ c₂heq:(d₁.beq d₂ = true ∧ (c₁ == c₁') = true) ∧ (c₂ == c₂') = truehd:d₁ = d₂hc1:c₁ = c₁'hc2:c₂ = c₂'⊢ EntryReaches stepFn d₂ c₁' c₂'
subst hd stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕc₁:EntryCfgc₁':EntryCfgc₂:EntryCfgc₂':EntryCfgh:EntryReaches stepFn d₁ c₁ c₂hc1:c₁ = c₁'hc2:c₂ = c₂'heq:(d₁.beq d₁ = true ∧ (c₁ == c₁') = true) ∧ (c₂ == c₂') = true⊢ EntryReaches stepFn d₁ c₁' c₂'; subst hc1 stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕc₁:EntryCfgc₂:EntryCfgc₂':EntryCfgh:EntryReaches stepFn d₁ c₁ c₂hc2:c₂ = c₂'heq:(d₁.beq d₁ = true ∧ (c₁ == c₁) = true) ∧ (c₂ == c₂') = true⊢ EntryReaches stepFn d₁ c₁ c₂'; subst hc2 stepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)d₁:ℕc₁:EntryCfgc₂:EntryCfgh:EntryReaches stepFn d₁ c₁ c₂heq:(d₁.beq d₁ = true ∧ (c₁ == c₁) = true) ∧ (c₂ == c₂) = true⊢ EntryReaches stepFn d₁ c₁ c₂
exact h All goals completed! 🐙
Soundness of EntryReaches: translates any EntryReaches derivation into ReachesIn M.
theorem EntryReaches.sound {M : Machine Γ Λ} {qOf : ℕ → Λ} {wordOf : ℕ → List Γ}
{stepFn : ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)}
(hs : StepFnSound M qOf wordOf stepFn) {dt : ℕ} {c₁ c₂ : EntryCfg}
(h : EntryReaches stepFn dt c₁ c₂) :
ReachesIn M dt (evalEntryCfg qOf wordOf c₁) (evalEntryCfg qOf wordOf c₂) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgh:EntryReaches stepFn dt c₁ c₂⊢ ReachesIn M dt (evalEntryCfg qOf wordOf c₁) (evalEntryCfg qOf wordOf c₂)
induction h with
| refl c => refl Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgc:EntryCfg⊢ ReachesIn M 0 (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c) exact ReachesIn.zero M _ All goals completed! 🐙
| @chunk fuel d c c' hc => chunk Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfghc:checkRunExact stepFn fuel d c c' = true⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c')
unfold checkRunExact at hc chunk Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfghc:(match runExact stepFn fuel 0 c with
| none => false
| some (dt, c'_1) => dt.beq d && c'_1 == c') =
true⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c')
rcases hr : runExact stepFn fuel 0 c with _ | ⟨dOut, cOut⟩ chunk.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfghc:(match runExact stepFn fuel 0 c with
| none => false
| some (dt, c'_1) => dt.beq d && c'_1 == c') =
truehr:runExact stepFn fuel 0 c = none⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c')chunk.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfghc:(match runExact stepFn fuel 0 c with
| none => false
| some (dt, c'_1) => dt.beq d && c'_1 == c') =
truedOut:ℕcOut:EntryCfghr:runExact stepFn fuel 0 c = some (dOut, cOut)⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c')
· chunk.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfghc:(match runExact stepFn fuel 0 c with
| none => false
| some (dt, c'_1) => dt.beq d && c'_1 == c') =
truehr:runExact stepFn fuel 0 c = none⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c') simp [hr] at hc All goals completed! 🐙
· chunk.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfghc:(match runExact stepFn fuel 0 c with
| none => false
| some (dt, c'_1) => dt.beq d && c'_1 == c') =
truedOut:ℕcOut:EntryCfghr:runExact stepFn fuel 0 c = some (dOut, cOut)⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c') rw [hr chunk.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfgdOut:ℕcOut:EntryCfghc:(match some (dOut, cOut) with
| none => false
| some (dt, c'_1) => dt.beq d && c'_1 == c') =
truehr:runExact stepFn fuel 0 c = some (dOut, cOut)⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c')] at hc chunk.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfgdOut:ℕcOut:EntryCfghc:(match some (dOut, cOut) with
| none => false
| some (dt, c'_1) => dt.beq d && c'_1 == c') =
truehr:runExact stepFn fuel 0 c = some (dOut, cOut)⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c')
simp only [Bool.and_eq_true] at hc chunk.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfgdOut:ℕcOut:EntryCfghr:runExact stepFn fuel 0 c = some (dOut, cOut)hc:dOut.beq d = true ∧ (cOut == c') = true⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c')
have hd : dOut = d := Nat.eq_of_beq_eq_true hc.1 chunk.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfgdOut:ℕcOut:EntryCfghr:runExact stepFn fuel 0 c = some (dOut, cOut)hc:dOut.beq d = true ∧ (cOut == c') = truehd:dOut = d⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c')
have hcEq : cOut = c' := eq_of_beq hc.2 chunk.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕd:ℕc:EntryCfgc':EntryCfgdOut:ℕcOut:EntryCfghr:runExact stepFn fuel 0 c = some (dOut, cOut)hc:dOut.beq d = true ∧ (cOut == c') = truehd:dOut = dhcEq:cOut = c'⊢ ReachesIn M d (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c')
subst hd chunk.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕc:EntryCfgc':EntryCfgdOut:ℕcOut:EntryCfghr:runExact stepFn fuel 0 c = some (dOut, cOut)hcEq:cOut = c'hc:dOut.beq dOut = true ∧ (cOut == c') = true⊢ ReachesIn M dOut (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf c')
subst hcEq chunk.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgfuel:ℕc:EntryCfgdOut:ℕcOut:EntryCfghr:runExact stepFn fuel 0 c = some (dOut, cOut)hc:dOut.beq dOut = true ∧ (cOut == cOut) = true⊢ ReachesIn M dOut (evalEntryCfg qOf wordOf c) (evalEntryCfg qOf wordOf cOut)
simpa using (runExact_sound_aux hs fuel 0 c dOut cOut hr).2 All goals completed! 🐙
| trans _ _ ih₁ ih₂ => trans Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛqOf:ℕ → ΛwordOf:ℕ → List ΓstepFn:ℕ → Bool → List Run → List Run → Option (ℕ × EntryCfg)hs:StepFnSound M qOf wordOf stepFndt:ℕc₁:EntryCfgc₂:EntryCfgd₁✝:ℕd₂✝:ℕc₁✝:EntryCfgc₂✝:EntryCfgc₃✝:EntryCfga✝¹:EntryReaches stepFn d₁✝ c₁✝ c₂✝a✝:EntryReaches stepFn d₂✝ c₂✝ c₃✝ih₁:ReachesIn M d₁✝ (evalEntryCfg qOf wordOf c₁✝) (evalEntryCfg qOf wordOf c₂✝)ih₂:ReachesIn M d₂✝ (evalEntryCfg qOf wordOf c₂✝) (evalEntryCfg qOf wordOf c₃✝)⊢ ReachesIn M (d₁✝ + d₂✝) (evalEntryCfg qOf wordOf c₁✝) (evalEntryCfg qOf wordOf c₃✝) exact ih₁.trans ih₂ All goals completed! 🐙end WordSemanticsend BusyBeaver.WordRLEend