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.Defs
Basic Lemmas for BusyBeaver Turing Machines (BusyBeaver.Basic)
Foundational lemmas for reasoning about BusyBeaver.Machine execution, multi-step reachability
(multiStep, ReachesIn, ReachesStar, ReachesPlus), halting/non-halting invariants
(HaltsFrom, NeverHaltsFrom), finite block repetition (l ^ n), and directed-head tape
configurations (Cfg.headRight, Cfg.headLeft).
@[expose] public sectionnamespace BusyBeaveropen Turingvariable {Γ Λ : Type*} [Inhabited Γ] [Inhabited Λ]
Multi-Step Execution (multiStep)
@[simp]
theorem step_none (M : Machine Γ Λ) (T : Tape Γ) :
step M ⟨none, T⟩ = none :=
rfl@[simp]
theorem multiStep_zero (M : Machine Γ Λ) (c : Cfg Γ Λ) :
multiStep M c 0 = some c :=
rfl@[simp]
theorem multiStep_one (M : Machine Γ Λ) (c : Cfg Γ Λ) :
multiStep M c 1 = step M c :=
rflprivate theorem iterate_bind_step_none (M : Machine Γ Λ) (n : ℕ) :
(Option.bind · (step M))^[n] none = none := Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λn:ℕ⊢ (fun x ↦ x.bind (step M))^[n] none = none
induction n with
Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λ⊢ (fun x ↦ x.bind (step M))^[0] none = none All goals completed! 🐙
Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λn:ℕih:(fun x ↦ x.bind (step M))^[n] none = none⊢ (fun x ↦ x.bind (step M))^[n + 1] none = none
All goals completed! 🐙
Split multiStep at the first step: n + 1 steps from c is one step from c followed by
n steps.
theorem multiStep_succ (M : Machine Γ Λ) (c : Cfg Γ Λ) (n : ℕ) :
multiStep M c (n + 1) = (step M c).bind (fun c' => multiStep M c' n) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕ⊢ multiStep M c (n + 1) = (step M c).bind fun c' ↦ multiStep M c' n
unfold multiStep Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕ⊢ (fun x ↦ x.bind (step M))^[n + 1] (some c) = (step M c).bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')
rw [Function.iterate_succ_apply Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕ⊢ (fun x ↦ x.bind (step M))^[n] ((some c).bind (step M)) =
(step M c).bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')] Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕ⊢ (fun x ↦ x.bind (step M))^[n] ((some c).bind (step M)) =
(step M c).bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')
rcases h : step M c with _ | c' none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕh:step M c = none⊢ (fun x ↦ x.bind (step M))^[n] ((some c).bind (step M)) = none.bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕc':Cfg Γ Λh:c [M]⊢ c'⊢ (fun x ↦ x.bind (step M))^[n] ((some c).bind (step M)) = (some c').bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')
· none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕh:step M c = none⊢ (fun x ↦ x.bind (step M))^[n] ((some c).bind (step M)) = none.bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c') change (Option.bind · (step M))^[n] (step M c) = _ none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕh:step M c = none⊢ (fun x ↦ x.bind (step M))^[n] (step M c) = none.bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')
rw [h, none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕh:step M c = none⊢ (fun x ↦ x.bind (step M))^[n] none = none.bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c') iterate_bind_step_none, none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕh:step M c = none⊢ none = none.bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c') Option.bind_none none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕh:step M c = none⊢ none = none] All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕc':Cfg Γ Λh:c [M]⊢ c'⊢ (fun x ↦ x.bind (step M))^[n] ((some c).bind (step M)) = (some c').bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c') change (Option.bind · (step M))^[n] (step M c) = _ some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕc':Cfg Γ Λh:c [M]⊢ c'⊢ (fun x ↦ x.bind (step M))^[n] (step M c) = (some c').bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')
rw [h some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕc':Cfg Γ Λh:c [M]⊢ c'⊢ (fun x ↦ x.bind (step M))^[n] (some c') = (some c').bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')] some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕc':Cfg Γ Λh:c [M]⊢ c'⊢ (fun x ↦ x.bind (step M))^[n] (some c') = (some c').bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')
rfl All goals completed! 🐙
Split multiStep at the last step: n + 1 steps from c is n steps from c followed by
one step.
theorem multiStep_succ' (M : Machine Γ Λ) (c : Cfg Γ Λ) (n : ℕ) :
multiStep M c (n + 1) = (multiStep M c n).bind (step M) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕ⊢ multiStep M c (n + 1) = (multiStep M c n).bind (step M)
unfold multiStep Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕ⊢ (fun x ↦ x.bind (step M))^[n + 1] (some c) = ((fun x ↦ x.bind (step M))^[n] (some c)).bind (step M)
rw [Function.iterate_succ_apply' Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λn:ℕ⊢ ((fun x ↦ x.bind (step M))^[n] (some c)).bind (step M) = ((fun x ↦ x.bind (step M))^[n] (some c)).bind (step M)] All goals completed! 🐙theorem multiStep_of_step {M : Machine Γ Λ} {c c' : Cfg Γ Λ}
(h : step M c = some c') (n : ℕ) :
multiStep M c (n + 1) = multiStep M c' n := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λc':Cfg Γ Λh:c [M]⊢ c'n:ℕ⊢ multiStep M c (n + 1) = multiStep M c' n
rw [multiStep_succ, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λc':Cfg Γ Λh:c [M]⊢ c'n:ℕ⊢ ((step M c).bind fun c' ↦ multiStep M c' n) = multiStep M c' n h, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λc':Cfg Γ Λh:c [M]⊢ c'n:ℕ⊢ ((some c').bind fun c' ↦ multiStep M c' n) = multiStep M c' n Option.bind_some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λc':Cfg Γ Λh:c [M]⊢ c'n:ℕ⊢ multiStep M c' n = multiStep M c' n] All goals completed! 🐙theorem multiStep_of_step_eq_none {M : Machine Γ Λ} {c : Cfg Γ Λ}
(h : step M c = none) (n : ℕ) :
multiStep M c (n + 1) = none := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λh:step M c = nonen:ℕ⊢ multiStep M c (n + 1) = none
rw [multiStep_succ, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λh:step M c = nonen:ℕ⊢ ((step M c).bind fun c' ↦ multiStep M c' n) = none h, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λh:step M c = nonen:ℕ⊢ (none.bind fun c' ↦ multiStep M c' n) = none Option.bind_none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λh:step M c = nonen:ℕ⊢ none = none] All goals completed! 🐙
Addition law for multiStep: m + n steps is m steps followed by n steps.
theorem multiStep_add (M : Machine Γ Λ) (c : Cfg Γ Λ) (m n : ℕ) :
multiStep M c (m + n) = (multiStep M c m).bind (fun c' => multiStep M c' n) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕ⊢ multiStep M c (m + n) = (multiStep M c m).bind fun c' ↦ multiStep M c' n
unfold multiStep Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕ⊢ (fun x ↦ x.bind (step M))^[m + n] (some c) =
((fun x ↦ x.bind (step M))^[m] (some c)).bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')
rw [Nat.add_comm m n, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕ⊢ (fun x ↦ x.bind (step M))^[n + m] (some c) =
((fun x ↦ x.bind (step M))^[m] (some c)).bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c') Function.iterate_add_apply Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕ⊢ (fun x ↦ x.bind (step M))^[n] ((fun x ↦ x.bind (step M))^[m] (some c)) =
((fun x ↦ x.bind (step M))^[m] (some c)).bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')] Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕ⊢ (fun x ↦ x.bind (step M))^[n] ((fun x ↦ x.bind (step M))^[m] (some c)) =
((fun x ↦ x.bind (step M))^[m] (some c)).bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')
rcases h : (Option.bind · (step M))^[m] (some c) with _ | c' none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕh:(fun x ↦ x.bind (step M))^[m] (some c) = none⊢ (fun x ↦ x.bind (step M))^[n] none = none.bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕc':Cfg Γ Λh:(fun x ↦ x.bind (step M))^[m] (some c) = some c'⊢ (fun x ↦ x.bind (step M))^[n] (some c') = (some c').bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c')
· none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕh:(fun x ↦ x.bind (step M))^[m] (some c) = none⊢ (fun x ↦ x.bind (step M))^[n] none = none.bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c') rw [iterate_bind_step_none, none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕh:(fun x ↦ x.bind (step M))^[m] (some c) = none⊢ none = none.bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c') Option.bind_none none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕh:(fun x ↦ x.bind (step M))^[m] (some c) = none⊢ none = none] All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λm:ℕn:ℕc':Cfg Γ Λh:(fun x ↦ x.bind (step M))^[m] (some c) = some c'⊢ (fun x ↦ x.bind (step M))^[n] (some c') = (some c').bind fun c' ↦ (fun x ↦ x.bind (step M))^[n] (some c') rfl All goals completed! 🐙theorem multiStep_trans {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ} {m n : ℕ}
(h₁ : multiStep M c₁ m = some c₂) (h₂ : multiStep M c₂ n = some c₃) :
multiStep M c₁ (m + n) = some c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λm:ℕn:ℕh₁:c₁ [M]⊢^{m} c₂h₂:c₂ [M]⊢^{n} c₃⊢ c₁ [M]⊢^{m + n} c₃
rw [multiStep_add, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λm:ℕn:ℕh₁:c₁ [M]⊢^{m} c₂h₂:c₂ [M]⊢^{n} c₃⊢ ((multiStep M c₁ m).bind fun c' ↦ multiStep M c' n) = some c₃ h₁, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λm:ℕn:ℕh₁:c₁ [M]⊢^{m} c₂h₂:c₂ [M]⊢^{n} c₃⊢ ((some c₂).bind fun c' ↦ multiStep M c' n) = some c₃ Option.bind_some, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λm:ℕn:ℕh₁:c₁ [M]⊢^{m} c₂h₂:c₂ [M]⊢^{n} c₃⊢ c₂ [M]⊢^{n} c₃ h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λm:ℕn:ℕh₁:c₁ [M]⊢^{m} c₂h₂:c₂ [M]⊢^{n} c₃⊢ some c₃ = some c₃] All goals completed! 🐙Exact, Reflexive-Transitive, and Positive Reachability
@[simp]
theorem ReachesIn.zero (M : Machine Γ Λ) (c : Cfg Γ Λ) :
ReachesIn M 0 c c :=
rfltheorem ReachesIn.single {M : Machine Γ Λ} {c₁ c₂ : Cfg Γ Λ}
(h : step M c₁ = some c₂) :
ReachesIn M 1 c₁ c₂ :=
htheorem ReachesIn.step_left {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ} {n : ℕ}
(h₁ : step M c₁ = some c₂) (h₂ : ReachesIn M n c₂ c₃) :
ReachesIn M (n + 1) c₁ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λn:ℕh₁:c₁ [M]⊢ c₂h₂:ReachesIn M n c₂ c₃⊢ ReachesIn M (n + 1) c₁ c₃
unfold ReachesIn at * Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λn:ℕh₁:c₁ [M]⊢ c₂h₂:c₂ [M]⊢^{n} c₃⊢ c₁ [M]⊢^{n + 1} c₃
rw [multiStep_of_step h₁, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λn:ℕh₁:c₁ [M]⊢ c₂h₂:c₂ [M]⊢^{n} c₃⊢ c₂ [M]⊢^{n} c₃ h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λn:ℕh₁:c₁ [M]⊢ c₂h₂:c₂ [M]⊢^{n} c₃⊢ some c₃ = some c₃] All goals completed! 🐙theorem ReachesIn.step_right {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ} {n : ℕ}
(h₁ : ReachesIn M n c₁ c₂) (h₂ : step M c₂ = some c₃) :
ReachesIn M (n + 1) c₁ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λn:ℕh₁:ReachesIn M n c₁ c₂h₂:c₂ [M]⊢ c₃⊢ ReachesIn M (n + 1) c₁ c₃
unfold ReachesIn at * Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λn:ℕh₁:c₁ [M]⊢^{n} c₂h₂:c₂ [M]⊢ c₃⊢ c₁ [M]⊢^{n + 1} c₃
rw [multiStep_succ', Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λn:ℕh₁:c₁ [M]⊢^{n} c₂h₂:c₂ [M]⊢ c₃⊢ (multiStep M c₁ n).bind (step M) = some c₃ h₁, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λn:ℕh₁:c₁ [M]⊢^{n} c₂h₂:c₂ [M]⊢ c₃⊢ (some c₂).bind (step M) = some c₃ Option.bind_some, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λn:ℕh₁:c₁ [M]⊢^{n} c₂h₂:c₂ [M]⊢ c₃⊢ c₂ [M]⊢ c₃ h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λn:ℕh₁:c₁ [M]⊢^{n} c₂h₂:c₂ [M]⊢ c₃⊢ some c₃ = some c₃] All goals completed! 🐙theorem ReachesIn.trans {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ} {m n : ℕ}
(h₁ : ReachesIn M m c₁ c₂) (h₂ : ReachesIn M n c₂ c₃) :
ReachesIn M (m + n) c₁ c₃ :=
multiStep_trans h₁ h₂theorem ReachesIn.to_star {M : Machine Γ Λ} {n : ℕ} {c₁ c₂ : Cfg Γ Λ}
(h : ReachesIn M n c₁ c₂) :
ReachesStar M c₁ c₂ :=
⟨n, h⟩theorem ReachesIn.to_plus {M : Machine Γ Λ} {n : ℕ} {c₁ c₂ : Cfg Γ Λ}
(hn : n > 0) (h : ReachesIn M n c₁ c₂) :
ReachesPlus M c₁ c₂ :=
⟨n, hn, h⟩@[refl, simp]
theorem ReachesStar.refl (M : Machine Γ Λ) (c : Cfg Γ Λ) :
ReachesStar M c c :=
⟨0, rfl⟩theorem ReachesStar.single {M : Machine Γ Λ} {c₁ c₂ : Cfg Γ Λ}
(h : step M c₁ = some c₂) :
ReachesStar M c₁ c₂ :=
⟨1, h⟩theorem ReachesStar.head {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ}
(h₁ : step M c₁ = some c₂) (h₂ : ReachesStar M c₂ c₃) :
ReachesStar M c₁ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢ c₂h₂:c₂ [M]⊢* c₃⊢ c₁ [M]⊢* c₃
obtain ⟨n, hn⟩ := h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢ c₂n:ℕhn:c₂ [M]⊢^{n} c₃⊢ c₁ [M]⊢* c₃
exact ⟨n + 1, ReachesIn.step_left h₁ hn⟩ All goals completed! 🐙theorem ReachesStar.tail {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ}
(h₁ : ReachesStar M c₁ c₂) (h₂ : step M c₂ = some c₃) :
ReachesStar M c₁ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢* c₂h₂:c₂ [M]⊢ c₃⊢ c₁ [M]⊢* c₃
obtain ⟨n, hn⟩ := h₁ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₂:c₂ [M]⊢ c₃n:ℕhn:c₁ [M]⊢^{n} c₂⊢ c₁ [M]⊢* c₃
exact ⟨n + 1, ReachesIn.step_right hn h₂⟩ All goals completed! 🐙theorem ReachesStar.trans {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ}
(h₁ : ReachesStar M c₁ c₂) (h₂ : ReachesStar M c₂ c₃) :
ReachesStar M c₁ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢* c₂h₂:c₂ [M]⊢* c₃⊢ c₁ [M]⊢* c₃
obtain ⟨m, hm⟩ := h₁ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₂:c₂ [M]⊢* c₃m:ℕhm:c₁ [M]⊢^{m} c₂⊢ c₁ [M]⊢* c₃
obtain ⟨n, hn⟩ := h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λm:ℕhm:c₁ [M]⊢^{m} c₂n:ℕhn:c₂ [M]⊢^{n} c₃⊢ c₁ [M]⊢* c₃
exact ⟨m + n, multiStep_trans hm hn⟩ All goals completed! 🐙theorem ReachesPlus.single {M : Machine Γ Λ} {c₁ c₂ : Cfg Γ Λ}
(h : step M c₁ = some c₂) :
ReachesPlus M c₁ c₂ :=
⟨1, Nat.one_pos, h⟩theorem ReachesPlus.to_star {M : Machine Γ Λ} {c₁ c₂ : Cfg Γ Λ}
(h : ReachesPlus M c₁ c₂) :
ReachesStar M c₁ c₂ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh:c₁ [M]⊢⁺ c₂⊢ c₁ [M]⊢* c₂
obtain ⟨n, _, hn⟩ := h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λn:ℕleft✝:n > 0hn:c₁ [M]⊢^{n} c₂⊢ c₁ [M]⊢* c₂
exact ⟨n, hn⟩ All goals completed! 🐙theorem ReachesPlus.head {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ}
(h₁ : step M c₁ = some c₂) (h₂ : ReachesStar M c₂ c₃) :
ReachesPlus M c₁ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢ c₂h₂:c₂ [M]⊢* c₃⊢ c₁ [M]⊢⁺ c₃
obtain ⟨n, hn⟩ := h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢ c₂n:ℕhn:c₂ [M]⊢^{n} c₃⊢ c₁ [M]⊢⁺ c₃
exact ⟨n + 1, Nat.succ_pos n, ReachesIn.step_left h₁ hn⟩ All goals completed! 🐙theorem ReachesPlus.tail {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ}
(h₁ : ReachesStar M c₁ c₂) (h₂ : step M c₂ = some c₃) :
ReachesPlus M c₁ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢* c₂h₂:c₂ [M]⊢ c₃⊢ c₁ [M]⊢⁺ c₃
obtain ⟨n, hn⟩ := h₁ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₂:c₂ [M]⊢ c₃n:ℕhn:c₁ [M]⊢^{n} c₂⊢ c₁ [M]⊢⁺ c₃
exact ⟨n + 1, Nat.succ_pos n, ReachesIn.step_right hn h₂⟩ All goals completed! 🐙theorem ReachesPlus.trans {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ}
(h₁ : ReachesPlus M c₁ c₂) (h₂ : ReachesPlus M c₂ c₃) :
ReachesPlus M c₁ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢⁺ c₂h₂:c₂ [M]⊢⁺ c₃⊢ c₁ [M]⊢⁺ c₃
obtain ⟨m, hm_pos, hm⟩ := h₁ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₂:c₂ [M]⊢⁺ c₃m:ℕhm_pos:m > 0hm:c₁ [M]⊢^{m} c₂⊢ c₁ [M]⊢⁺ c₃
obtain ⟨n, hn_pos, hn⟩ := h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λm:ℕhm_pos:m > 0hm:c₁ [M]⊢^{m} c₂n:ℕhn_pos:n > 0hn:c₂ [M]⊢^{n} c₃⊢ c₁ [M]⊢⁺ c₃
exact ⟨m + n, Nat.add_pos_left hm_pos n, multiStep_trans hm hn⟩ All goals completed! 🐙theorem ReachesPlus.trans_star {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ}
(h₁ : ReachesPlus M c₁ c₂) (h₂ : ReachesStar M c₂ c₃) :
ReachesPlus M c₁ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢⁺ c₂h₂:c₂ [M]⊢* c₃⊢ c₁ [M]⊢⁺ c₃
obtain ⟨m, hm_pos, hm⟩ := h₁ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₂:c₂ [M]⊢* c₃m:ℕhm_pos:m > 0hm:c₁ [M]⊢^{m} c₂⊢ c₁ [M]⊢⁺ c₃
obtain ⟨n, hn⟩ := h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λm:ℕhm_pos:m > 0hm:c₁ [M]⊢^{m} c₂n:ℕhn:c₂ [M]⊢^{n} c₃⊢ c₁ [M]⊢⁺ c₃
exact ⟨m + n, Nat.add_pos_left hm_pos n, multiStep_trans hm hn⟩ All goals completed! 🐙theorem ReachesStar.trans_plus {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ}
(h₁ : ReachesStar M c₁ c₂) (h₂ : ReachesPlus M c₂ c₃) :
ReachesPlus M c₁ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢* c₂h₂:c₂ [M]⊢⁺ c₃⊢ c₁ [M]⊢⁺ c₃
obtain ⟨m, hm⟩ := h₁ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₂:c₂ [M]⊢⁺ c₃m:ℕhm:c₁ [M]⊢^{m} c₂⊢ c₁ [M]⊢⁺ c₃
obtain ⟨n, hn_pos, hn⟩ := h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λm:ℕhm:c₁ [M]⊢^{m} c₂n:ℕhn_pos:n > 0hn:c₂ [M]⊢^{n} c₃⊢ c₁ [M]⊢⁺ c₃
exact ⟨m + n, Nat.add_pos_right m hn_pos, multiStep_trans hm hn⟩ All goals completed! 🐙theorem ReachesPlus.of_star_ne {M : Machine Γ Λ} {c₁ c₂ : Cfg Γ Λ}
(h : ReachesStar M c₁ c₂) (hne : c₁ ≠ c₂) :
ReachesPlus M c₁ c₂ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh:c₁ [M]⊢* c₂hne:c₁ ≠ c₂⊢ c₁ [M]⊢⁺ c₂
obtain ⟨n, hn⟩ := h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λhne:c₁ ≠ c₂n:ℕhn:c₁ [M]⊢^{n} c₂⊢ c₁ [M]⊢⁺ c₂
rcases n with _ | n zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λhne:c₁ ≠ c₂hn:c₁ [M]⊢^{0} c₂⊢ c₁ [M]⊢⁺ c₂succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λhne:c₁ ≠ c₂n:ℕhn:c₁ [M]⊢^{n + 1} c₂⊢ c₁ [M]⊢⁺ c₂
· zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λhne:c₁ ≠ c₂hn:c₁ [M]⊢^{0} c₂⊢ c₁ [M]⊢⁺ c₂ simp only [multiStep_zero, Option.some.injEq] at hn zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λhne:c₁ ≠ c₂hn:c₁ = c₂⊢ c₁ [M]⊢⁺ c₂
exact absurd hn hne All goals completed! 🐙
· succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λhne:c₁ ≠ c₂n:ℕhn:c₁ [M]⊢^{n + 1} c₂⊢ c₁ [M]⊢⁺ c₂ exact ⟨n + 1, Nat.succ_pos n, hn⟩ All goals completed! 🐙instance (M : Machine Γ Λ) : Trans (ReachesStar M) (ReachesStar M) (ReachesStar M) :=
⟨ReachesStar.trans⟩instance (M : Machine Γ Λ) : Trans (ReachesPlus M) (ReachesPlus M) (ReachesPlus M) :=
⟨ReachesPlus.trans⟩instance (M : Machine Γ Λ) : Trans (ReachesPlus M) (ReachesStar M) (ReachesPlus M) :=
⟨ReachesPlus.trans_star⟩instance (M : Machine Γ Λ) : Trans (ReachesStar M) (ReachesPlus M) (ReachesPlus M) :=
⟨ReachesStar.trans_plus⟩Reachability Aliases for Proof Modules
abbrev stepStar_trans := @ReachesStar.transabbrev stepPlus_stepStar := @ReachesPlus.to_starabbrev stepPlus_trans := @ReachesPlus.transabbrev stepPlus_stepStar_stepPlus := @ReachesPlus.trans_starabbrev stepStar_stepPlus_stepPlus := @ReachesStar.trans_plusabbrev stepPlus_stepStar_trans := @ReachesPlus.trans_starabbrev stepStar_stepPlus_trans := @ReachesStar.trans_plusabbrev stepPlus_to_stepStar := @ReachesPlus.to_starabbrev stepStar_of_multiStep := @ReachesIn.to_starabbrev stepStar_refl := @ReachesStar.refltheorem step_multiStep (M : Machine Γ Λ) (c₁ c₂ : Cfg Γ Λ) (h : step M c₁ = some c₂) :
c₁ [M]⊢^{1} c₂ :=
htheorem step_stepStar (M : Machine Γ Λ) (c₁ c₂ : Cfg Γ Λ) (h : step M c₁ = some c₂) :
c₁ [M]⊢* c₂ :=
⟨1, h⟩theorem step_stepPlus (M : Machine Γ Λ) (c₁ c₂ : Cfg Γ Λ) (h : step M c₁ = some c₂) :
c₁ [M]⊢⁺ c₂ :=
⟨1, by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh:c₁ [M]⊢ c₂⊢ 1 > 0 decide All goals completed! 🐙, h⟩theorem step_stepStar_stepPlus {M : Machine Γ Λ} {c₁ c₂ c₃ : Cfg Γ Λ}
(h₁ : c₁ [M]⊢ c₂) (h₂ : c₂ [M]⊢* c₃) :
c₁ [M]⊢⁺ c₃ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢ c₂h₂:c₂ [M]⊢* c₃⊢ c₁ [M]⊢⁺ c₃
obtain ⟨m, hm⟩ := h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢ c₂m:ℕhm:c₂ [M]⊢^{m} c₃⊢ c₁ [M]⊢⁺ c₃
exact ⟨1 + m, by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λc₃:Cfg Γ Λh₁:c₁ [M]⊢ c₂m:ℕhm:c₂ [M]⊢^{m} c₃⊢ 1 + m > 0 omega All goals completed! 🐙, multiStep_trans h₁ hm⟩Halting and Non-Halting Invariants
M eventually reaches a halting configuration starting from c.
def HaltsFrom (M : Machine Γ Λ) (c : Cfg Γ Λ) : Prop :=
∃ cfg : Cfg Γ Λ, ReachesStar M c cfg ∧ (step M cfg).isNone
Every configuration reachable by M from c has a well-defined successor.
def NeverHaltsFrom (M : Machine Γ Λ) (c : Cfg Γ Λ) : Prop :=
∀ cfg : Cfg Γ Λ, ReachesStar M c cfg → (step M cfg).isSome@[simp]
theorem isHalt_iff_haltsFrom_init (M : Machine Γ Λ) :
IsHalt M ↔ HaltsFrom M (init []) :=
Iff.rfl@[simp]
theorem isNotHalt_iff_neverHaltsFrom_init (M : Machine Γ Λ) :
IsNotHalt M ↔ NeverHaltsFrom M (init []) :=
Iff.rfltheorem HaltsFrom.of_reachesStar {M : Machine Γ Λ} {c₁ c₂ : Cfg Γ Λ}
(h₁ : ReachesStar M c₁ c₂) (h₂ : HaltsFrom M c₂) :
HaltsFrom M c₁ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh₁:c₁ [M]⊢* c₂h₂:HaltsFrom M c₂⊢ HaltsFrom M c₁
obtain ⟨cfg, hreach, hnone⟩ := h₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh₁:c₁ [M]⊢* c₂cfg:Cfg Γ Λhreach:c₂ [M]⊢* cfghnone:(step M cfg).isNone = true⊢ HaltsFrom M c₁
exact ⟨cfg, h₁.trans hreach, hnone⟩ All goals completed! 🐙theorem NeverHaltsFrom.of_reachesStar {M : Machine Γ Λ} {c₁ c₂ : Cfg Γ Λ}
(h₁ : ReachesStar M c₁ c₂) (h₂ : NeverHaltsFrom M c₁) :
NeverHaltsFrom M c₂ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh₁:c₁ [M]⊢* c₂h₂:NeverHaltsFrom M c₁⊢ NeverHaltsFrom M c₂
intro cfg hreach Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh₁:c₁ [M]⊢* c₂h₂:NeverHaltsFrom M c₁cfg:Cfg Γ Λhreach:c₂ [M]⊢* cfg⊢ (step M cfg).isSome = true
exact h₂ cfg (h₁.trans hreach) All goals completed! 🐙theorem multiStep_eq_none_of_isNone {M : Machine Γ Λ} {c cfg : Cfg Γ Λ} {k d : ℕ}
(hk : multiStep M c k = some cfg) (hnone : (step M cfg).isNone) (hd : d > 0) :
multiStep M c (k + d) = none := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λcfg:Cfg Γ Λk:ℕd:ℕhk:c [M]⊢^{k} cfghnone:(step M cfg).isNone = truehd:d > 0⊢ multiStep M c (k + d) = none
obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le' hd Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λcfg:Cfg Γ Λk:ℕhk:c [M]⊢^{k} cfghnone:(step M cfg).isNone = truem:ℕhd:m + Nat.succ 0 > 0⊢ multiStep M c (k + (m + Nat.succ 0)) = none
rw [multiStep_add, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λcfg:Cfg Γ Λk:ℕhk:c [M]⊢^{k} cfghnone:(step M cfg).isNone = truem:ℕhd:m + Nat.succ 0 > 0⊢ ((multiStep M c k).bind fun c' ↦ multiStep M c' (m + Nat.succ 0)) = none hk, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λcfg:Cfg Γ Λk:ℕhk:c [M]⊢^{k} cfghnone:(step M cfg).isNone = truem:ℕhd:m + Nat.succ 0 > 0⊢ ((some cfg).bind fun c' ↦ multiStep M c' (m + Nat.succ 0)) = none Option.bind_some, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λcfg:Cfg Γ Λk:ℕhk:c [M]⊢^{k} cfghnone:(step M cfg).isNone = truem:ℕhd:m + Nat.succ 0 > 0⊢ multiStep M cfg (m + Nat.succ 0) = none multiStep_of_step_eq_none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λcfg:Cfg Γ Λk:ℕhk:c [M]⊢^{k} cfghnone:(step M cfg).isNone = truem:ℕhd:m + Nat.succ 0 > 0⊢ none = noneh Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λcfg:Cfg Γ Λk:ℕhk:c [M]⊢^{k} cfghnone:(step M cfg).isNone = truem:ℕhd:m + Nat.succ 0 > 0⊢ step M cfg = none] h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λc:Cfg Γ Λcfg:Cfg Γ Λk:ℕhk:c [M]⊢^{k} cfghnone:(step M cfg).isNone = truem:ℕhd:m + Nat.succ 0 > 0⊢ step M cfg = none
exact Option.isNone_iff_eq_none.mp hnone All goals completed! 🐙
If P is a configuration invariant starting at c₀ such that every P-configuration steps
in ReachesPlus (n > 0 steps) to another P-configuration, then M never halts from c₀.
theorem NeverHaltsFrom.of_reachesPlus_invariant {M : Machine Γ Λ} {P : Cfg Γ Λ → Prop}
(hstep : ∀ c, P c → ∃ c', ReachesPlus M c c' ∧ P c') {c₀ : Cfg Γ Λ} (h₀ : P c₀) :
NeverHaltsFrom M c₀ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀⊢ NeverHaltsFrom M c₀
have h_unbounded : ∀ k : ℕ, ∃ N ≥ k, ∃ c', multiStep M c₀ N = some c' ∧ P c' := by
intro k Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀k:ℕ⊢ ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'
induction k with
| zero => zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀⊢ ∃ N ≥ 0, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c' exact ⟨0, Nat.le_refl 0, c₀, rfl, h₀⟩ All goals completed! 🐙
| succ k ih => succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀k:ℕih:∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'⊢ ∃ N ≥ k + 1, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'
obtain ⟨N, hNk, c₁, hms₁, hP₁⟩ := ih succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀k:ℕN:ℕhNk:N ≥ kc₁:Cfg Γ Λhms₁:c₀ [M]⊢^{N} c₁hP₁:P c₁⊢ ∃ N ≥ k + 1, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'
obtain ⟨c₂, ⟨m, hm_pos, hms₂⟩, hP₂⟩ := hstep c₁ hP₁ succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀k:ℕN:ℕhNk:N ≥ kc₁:Cfg Γ Λhms₁:c₀ [M]⊢^{N} c₁hP₁:P c₁c₂:Cfg Γ ΛhP₂:P c₂m:ℕhm_pos:m > 0hms₂:c₁ [M]⊢^{m} c₂⊢ ∃ N ≥ k + 1, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'
refine ⟨N + m, by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀k:ℕN:ℕhNk:N ≥ kc₁:Cfg Γ Λhms₁:c₀ [M]⊢^{N} c₁hP₁:P c₁c₂:Cfg Γ ΛhP₂:P c₂m:ℕhm_pos:m > 0hms₂:c₁ [M]⊢^{m} c₂⊢ N + m ≥ k + 1 omega All goals completed! 🐙, c₂, multiStep_trans hms₁ hms₂, hP₂⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'⊢ NeverHaltsFrom M c₀
intro cfg ⟨k, hk⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfg⊢ (step M cfg).isSome = true
rcases hstep_cfg : step M cfg with _ | _ none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = none⊢ none.isSome = truesome Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfgval✝:Cfg Γ Λhstep_cfg:cfg [M]⊢ val✝⊢ (some val✝).isSome = true
· none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = none⊢ none.isSome = true obtain ⟨N, hNk, c', hmsN, _⟩ := h_unbounded (k + 1) none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = noneN:ℕhNk:N ≥ k + 1c':Cfg Γ ΛhmsN:c₀ [M]⊢^{N} c'right✝:P c'⊢ none.isSome = true
have hnone : (step M cfg).isNone := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀⊢ NeverHaltsFrom M c₀ simp [hstep_cfg] none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = noneN:ℕhNk:N ≥ k + 1c':Cfg Γ ΛhmsN:c₀ [M]⊢^{N} c'right✝:P c'hnone:(step M cfg).isNone = true⊢ none.isSome = true
have hnoneN : multiStep M c₀ N = none := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀⊢ NeverHaltsFrom M c₀
have hsplit : N = k + (N - k) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀⊢ NeverHaltsFrom M c₀ omega Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = noneN:ℕhNk:N ≥ k + 1c':Cfg Γ ΛhmsN:c₀ [M]⊢^{N} c'right✝:P c'hnone:(step M cfg).isNone = truehsplit:N = k + (N - k)⊢ multiStep M c₀ N = none
rw [hsplit Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = noneN:ℕhNk:N ≥ k + 1c':Cfg Γ ΛhmsN:c₀ [M]⊢^{N} c'right✝:P c'hnone:(step M cfg).isNone = truehsplit:N = k + (N - k)⊢ multiStep M c₀ (k + (N - k)) = none] Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = noneN:ℕhNk:N ≥ k + 1c':Cfg Γ ΛhmsN:c₀ [M]⊢^{N} c'right✝:P c'hnone:(step M cfg).isNone = truehsplit:N = k + (N - k)⊢ multiStep M c₀ (k + (N - k)) = none
exact multiStep_eq_none_of_isNone hk hnone (by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = noneN:ℕhNk:N ≥ k + 1c':Cfg Γ ΛhmsN:c₀ [M]⊢^{N} c'right✝:P c'hnone:(step M cfg).isNone = truehsplit:N = k + (N - k)⊢ N - k > 0 omega All goals completed! 🐙) none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = noneN:ℕhNk:N ≥ k + 1c':Cfg Γ ΛhmsN:c₀ [M]⊢^{N} c'right✝:P c'hnone:(step M cfg).isNone = truehnoneN:multiStep M c₀ N = none⊢ none.isSome = true
rw [hnoneN none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = noneN:ℕhNk:N ≥ k + 1c':Cfg Γ ΛhmsN:none = some c'right✝:P c'hnone:(step M cfg).isNone = truehnoneN:multiStep M c₀ N = none⊢ none.isSome = true] at hmsN none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfghstep_cfg:step M cfg = noneN:ℕhNk:N ≥ k + 1c':Cfg Γ ΛhmsN:none = some c'right✝:P c'hnone:(step M cfg).isNone = truehnoneN:multiStep M c₀ N = none⊢ none.isSome = true
cases hmsN All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Prophstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'c₀:Cfg Γ Λh₀:P c₀h_unbounded:∀ (k : ℕ), ∃ N ≥ k, ∃ c', (c₀ [M]⊢^{N} c') ∧ P c'cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k} cfgval✝:Cfg Γ Λhstep_cfg:cfg [M]⊢ val✝⊢ (some val✝).isSome = true rfl All goals completed! 🐙
If M reaches an invariant P from init [] that is closed under ReachesPlus, then
IsNotHalt M.
theorem IsNotHalt.of_reachesPlus_invariant {M : Machine Γ Λ} {P : Cfg Γ Λ → Prop}
{c₀ : Cfg Γ Λ} (hinit : ReachesStar M (init []) c₀) (h₀ : P c₀)
(hstep : ∀ c, P c → ∃ c', ReachesPlus M c c' ∧ P c') :
IsNotHalt M := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λhinit:init [] [M]⊢* c₀h₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'⊢ IsNotHalt M
have h_never_c₀ := NeverHaltsFrom.of_reachesPlus_invariant hstep h₀ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λhinit:init [] [M]⊢* c₀h₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀⊢ IsNotHalt M
obtain ⟨k₀, hk₀⟩ := hinit Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀⊢ IsNotHalt M
intro cfg ⟨k, hk⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfg⊢ (step M cfg).isSome = true
rcases Nat.lt_or_ge k k₀ with hlt | hge inl Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀⊢ (step M cfg).isSome = trueinr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghge:k ≥ k₀⊢ (step M cfg).isSome = true
· inl Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀⊢ (step M cfg).isSome = true rcases hstep_cfg : step M cfg with _ | _ inl.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀hstep_cfg:step M cfg = none⊢ none.isSome = trueinl.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀val✝:Cfg Γ Λhstep_cfg:cfg [M]⊢ val✝⊢ (some val✝).isSome = true
· inl.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀hstep_cfg:step M cfg = none⊢ none.isSome = true have hnone : (step M cfg).isNone := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λhinit:init [] [M]⊢* c₀h₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'⊢ IsNotHalt M simp [hstep_cfg] inl.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀hstep_cfg:step M cfg = nonehnone:(step M cfg).isNone = true⊢ none.isSome = true
have hnone_k₀ : multiStep M (init []) k₀ = none := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λhinit:init [] [M]⊢* c₀h₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'⊢ IsNotHalt M
have hsplit : k₀ = k + (k₀ - k) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λhinit:init [] [M]⊢* c₀h₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'⊢ IsNotHalt M omega Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀hstep_cfg:step M cfg = nonehnone:(step M cfg).isNone = truehsplit:k₀ = k + (k₀ - k)⊢ multiStep M (init []) k₀ = none
rw [hsplit Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀hstep_cfg:step M cfg = nonehnone:(step M cfg).isNone = truehsplit:k₀ = k + (k₀ - k)⊢ multiStep M (init []) (k + (k₀ - k)) = none] Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀hstep_cfg:step M cfg = nonehnone:(step M cfg).isNone = truehsplit:k₀ = k + (k₀ - k)⊢ multiStep M (init []) (k + (k₀ - k)) = none
exact multiStep_eq_none_of_isNone hk hnone (by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀hstep_cfg:step M cfg = nonehnone:(step M cfg).isNone = truehsplit:k₀ = k + (k₀ - k)⊢ k₀ - k > 0 omega All goals completed! 🐙) inl.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀hstep_cfg:step M cfg = nonehnone:(step M cfg).isNone = truehnone_k₀:multiStep M (init []) k₀ = none⊢ none.isSome = true
rw [hnone_k₀ inl.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:none = some c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀hstep_cfg:step M cfg = nonehnone:(step M cfg).isNone = truehnone_k₀:multiStep M (init []) k₀ = none⊢ none.isSome = true] at hk₀ inl.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:none = some c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀hstep_cfg:step M cfg = nonehnone:(step M cfg).isNone = truehnone_k₀:multiStep M (init []) k₀ = none⊢ none.isSome = true
cases hk₀ All goals completed! 🐙
· inl.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghlt:k < k₀val✝:Cfg Γ Λhstep_cfg:cfg [M]⊢ val✝⊢ (some val✝).isSome = true rfl All goals completed! 🐙
· inr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghge:k ≥ k₀⊢ (step M cfg).isSome = true have hsplit : k = k₀ + (k - k₀) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λhinit:init [] [M]⊢* c₀h₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'⊢ IsNotHalt M omega inr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k} cfghge:k ≥ k₀hsplit:k = k₀ + (k - k₀)⊢ (step M cfg).isSome = true
rw [hsplit, inr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:init [] [M]⊢^{k₀ + (k - k₀)} cfghge:k ≥ k₀hsplit:k = k₀ + (k - k₀)⊢ (step M cfg).isSome = true multiStep_add, inr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:((multiStep M (init []) k₀).bind fun c' ↦ multiStep M c' (k - k₀)) = some cfghge:k ≥ k₀hsplit:k = k₀ + (k - k₀)⊢ (step M cfg).isSome = true hk₀, inr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:((some c₀).bind fun c' ↦ multiStep M c' (k - k₀)) = some cfghge:k ≥ k₀hsplit:k = k₀ + (k - k₀)⊢ (step M cfg).isSome = true Option.bind_some inr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k - k₀} cfghge:k ≥ k₀hsplit:k = k₀ + (k - k₀)⊢ (step M cfg).isSome = true] at hk inr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛP:Cfg Γ Λ → Propc₀:Cfg Γ Λh₀:P c₀hstep:∀ (c : Cfg Γ Λ), P c → ∃ c', (c [M]⊢⁺ c') ∧ P c'h_never_c₀:NeverHaltsFrom M c₀k₀:ℕhk₀:init [] [M]⊢^{k₀} c₀cfg:Cfg Γ Λk:ℕhk:c₀ [M]⊢^{k - k₀} cfghge:k ≥ k₀hsplit:k = k₀ + (k - k₀)⊢ (step M cfg).isSome = true
exact h_never_c₀ cfg ⟨k - k₀, hk⟩ All goals completed! 🐙
Finite Block Repetition (l ^ n)
section ListPowomit [Inhabited Γ]@[simp]
theorem list_pow_zero (l : List Γ) : l ^ (0 : ℕ) = [] :=
rfl@[simp]
theorem list_pow_one (l : List Γ) : l ^ (1 : ℕ) = l := by Γ:Type u_1l:List Γ⊢ l ^ 1 = l
simp [HPow.hPow] All goals completed! 🐙theorem list_pow_succ (l : List Γ) (n : ℕ) : l ^ (n + 1) = l ++ l ^ n :=
rfltheorem list_pow_add (l : List Γ) (m n : ℕ) : l ^ (m + n) = l ^ m ++ l ^ n := by Γ:Type u_1l:List Γm:ℕn:ℕ⊢ l ^ (m + n) = l ^ m ++ l ^ n
change (List.replicate (m + n) l).flatten =
(List.replicate m l).flatten ++ (List.replicate n l).flatten Γ:Type u_1l:List Γm:ℕn:ℕ⊢ (List.replicate (m + n) l).flatten = (List.replicate m l).flatten ++ (List.replicate n l).flatten
rw [List.replicate_add, Γ:Type u_1l:List Γm:ℕn:ℕ⊢ (List.replicate m l ++ List.replicate n l).flatten = (List.replicate m l).flatten ++ (List.replicate n l).flatten List.flatten_append Γ:Type u_1l:List Γm:ℕn:ℕ⊢ (List.replicate m l).flatten ++ (List.replicate n l).flatten =
(List.replicate m l).flatten ++ (List.replicate n l).flatten] All goals completed! 🐙theorem list_pow_succ' (l : List Γ) (n : ℕ) : l ^ (n + 1) = l ^ n ++ l := by Γ:Type u_1l:List Γn:ℕ⊢ l ^ (n + 1) = l ^ n ++ l
rw [list_pow_add, Γ:Type u_1l:List Γn:ℕ⊢ l ^ n ++ l ^ 1 = l ^ n ++ l list_pow_one Γ:Type u_1l:List Γn:ℕ⊢ l ^ n ++ l = l ^ n ++ l] All goals completed! 🐙theorem list_pow_add_comm (l : List Γ) (m n : ℕ) : l ^ m ++ l ^ n = l ^ n ++ l ^ m := by Γ:Type u_1l:List Γm:ℕn:ℕ⊢ l ^ m ++ l ^ n = l ^ n ++ l ^ m
rw [← list_pow_add, Γ:Type u_1l:List Γm:ℕn:ℕ⊢ l ^ (m + n) = l ^ n ++ l ^ m ← list_pow_add, Γ:Type u_1l:List Γm:ℕn:ℕ⊢ l ^ (m + n) = l ^ (n + m) Nat.add_comm Γ:Type u_1l:List Γm:ℕn:ℕ⊢ l ^ (n + m) = l ^ (n + m)] All goals completed! 🐙@[simp]
theorem nil_pow (n : ℕ) : ([] : List Γ) ^ n = [] := by Γ:Type u_1n:ℕ⊢ [] ^ n = []
induction n with
| zero => zero Γ:Type u_1⊢ [] ^ 0 = [] rfl All goals completed! 🐙
| succ n ih => succ Γ:Type u_1n:ℕih:[] ^ n = []⊢ [] ^ (n + 1) = [] rw [list_pow_succ, succ Γ:Type u_1n:ℕih:[] ^ n = []⊢ [] ++ [] ^ n = [] List.nil_append, succ Γ:Type u_1n:ℕih:[] ^ n = []⊢ [] ^ n = [] ih succ Γ:Type u_1n:ℕih:[] ^ n = []⊢ [] = []] All goals completed! 🐙theorem singleton_pow (a : Γ) (n : ℕ) : ([a] : List Γ) ^ n = List.replicate n a := by Γ:Type u_1a:Γn:ℕ⊢ [a] ^ n = List.replicate n a
induction n with
| zero => zero Γ:Type u_1a:Γ⊢ [a] ^ 0 = List.replicate 0 a rfl All goals completed! 🐙
| succ n ih => succ Γ:Type u_1a:Γn:ℕih:[a] ^ n = List.replicate n a⊢ [a] ^ (n + 1) = List.replicate (n + 1) a rw [list_pow_succ, succ Γ:Type u_1a:Γn:ℕih:[a] ^ n = List.replicate n a⊢ [a] ++ [a] ^ n = List.replicate (n + 1) a List.singleton_append, succ Γ:Type u_1a:Γn:ℕih:[a] ^ n = List.replicate n a⊢ a :: [a] ^ n = List.replicate (n + 1) a ih, succ Γ:Type u_1a:Γn:ℕih:[a] ^ n = List.replicate n a⊢ a :: List.replicate n a = List.replicate (n + 1) a List.replicate_succ succ Γ:Type u_1a:Γn:ℕih:[a] ^ n = List.replicate n a⊢ a :: List.replicate n a = a :: List.replicate n a] All goals completed! 🐙theorem list_pow_mul (l : List Γ) (m n : ℕ) : l ^ (m * n) = (l ^ m) ^ n := by Γ:Type u_1l:List Γm:ℕn:ℕ⊢ l ^ (m * n) = (l ^ m) ^ n
induction n with
| zero => zero Γ:Type u_1l:List Γm:ℕ⊢ l ^ (m * 0) = (l ^ m) ^ 0 simp All goals completed! 🐙
| succ n ih => succ Γ:Type u_1l:List Γm:ℕn:ℕih:l ^ (m * n) = (l ^ m) ^ n⊢ l ^ (m * (n + 1)) = (l ^ m) ^ (n + 1) rw [Nat.mul_succ, succ Γ:Type u_1l:List Γm:ℕn:ℕih:l ^ (m * n) = (l ^ m) ^ n⊢ l ^ (m * n + m) = (l ^ m) ^ (n + 1) list_pow_add, succ Γ:Type u_1l:List Γm:ℕn:ℕih:l ^ (m * n) = (l ^ m) ^ n⊢ l ^ (m * n) ++ l ^ m = (l ^ m) ^ (n + 1) ih, succ Γ:Type u_1l:List Γm:ℕn:ℕih:l ^ (m * n) = (l ^ m) ^ n⊢ (l ^ m) ^ n ++ l ^ m = (l ^ m) ^ (n + 1) list_pow_succ' succ Γ:Type u_1l:List Γm:ℕn:ℕih:l ^ (m * n) = (l ^ m) ^ n⊢ (l ^ m) ^ n ++ l ^ m = (l ^ m) ^ n ++ l ^ m] All goals completed! 🐙theorem pair_pow_eq_singleton_pow_two_mul (a : Γ) (k : ℕ) :
([a, a] : List Γ) ^ k = ([a] : List Γ) ^ (2 * k) := by Γ:Type u_1a:Γk:ℕ⊢ [a, a] ^ k = [a] ^ (2 * k)
induction k with
| zero => zero Γ:Type u_1a:Γ⊢ [a, a] ^ 0 = [a] ^ (2 * 0) rfl All goals completed! 🐙
| succ k ih => succ Γ:Type u_1a:Γk:ℕih:[a, a] ^ k = [a] ^ (2 * k)⊢ [a, a] ^ (k + 1) = [a] ^ (2 * (k + 1))
rw [Nat.mul_succ, succ Γ:Type u_1a:Γk:ℕih:[a, a] ^ k = [a] ^ (2 * k)⊢ [a, a] ^ (k + 1) = [a] ^ (2 * k + 2) list_pow_add, succ Γ:Type u_1a:Γk:ℕih:[a, a] ^ k = [a] ^ (2 * k)⊢ [a, a] ^ k ++ [a, a] ^ 1 = [a] ^ (2 * k + 2) ih, succ Γ:Type u_1a:Γk:ℕih:[a, a] ^ k = [a] ^ (2 * k)⊢ [a] ^ (2 * k) ++ [a, a] ^ 1 = [a] ^ (2 * k + 2) list_pow_add succ Γ:Type u_1a:Γk:ℕih:[a, a] ^ k = [a] ^ (2 * k)⊢ [a] ^ (2 * k) ++ [a, a] ^ 1 = [a] ^ (2 * k) ++ [a] ^ 2] succ Γ:Type u_1a:Γk:ℕih:[a, a] ^ k = [a] ^ (2 * k)⊢ [a] ^ (2 * k) ++ [a, a] ^ 1 = [a] ^ (2 * k) ++ [a] ^ 2
rfl All goals completed! 🐙theorem one_pow_two_mul (k : ℕ) :
([1, 1] : List (Fin 2)) ^ k = ([1] : List (Fin 2)) ^ (2 * k) :=
pair_pow_eq_singleton_pow_two_mul 1 ktheorem nat_even_or_odd_two_mul (n : ℕ) :
(∃ k, n = 2 * k) ∨ (∃ k, n = 2 * k + 1) := by n:ℕ⊢ (∃ k, n = 2 * k) ∨ ∃ k, n = 2 * k + 1
induction n with
| zero => zero ⊢ (∃ k, 0 = 2 * k) ∨ ∃ k, 0 = 2 * k + 1 exact Or.inl ⟨0, rfl⟩ All goals completed! 🐙
| succ n ih => succ n:ℕih:(∃ k, n = 2 * k) ∨ ∃ k, n = 2 * k + 1⊢ (∃ k, n + 1 = 2 * k) ∨ ∃ k, n + 1 = 2 * k + 1
rcases ih with ⟨k, rfl⟩ | ⟨k, rfl⟩ succ.inl k:ℕ⊢ (∃ k_1, 2 * k + 1 = 2 * k_1) ∨ ∃ k_1, 2 * k + 1 = 2 * k_1 + 1succ.inr k:ℕ⊢ (∃ k_1, 2 * k + 1 + 1 = 2 * k_1) ∨ ∃ k_1, 2 * k + 1 + 1 = 2 * k_1 + 1
· succ.inl k:ℕ⊢ (∃ k_1, 2 * k + 1 = 2 * k_1) ∨ ∃ k_1, 2 * k + 1 = 2 * k_1 + 1 exact Or.inr ⟨k, rfl⟩ All goals completed! 🐙
· succ.inr k:ℕ⊢ (∃ k_1, 2 * k + 1 + 1 = 2 * k_1) ∨ ∃ k_1, 2 * k + 1 + 1 = 2 * k_1 + 1 exact Or.inl ⟨k + 1, by k:ℕ⊢ 2 * k + 1 + 1 = 2 * (k + 1) omega All goals completed! 🐙⟩end ListPow
Half-Tape (ListBlank) & Directed-Head (Cfg.headRight / Cfg.headLeft) Lemmas
@[simp]
theorem ListBlank.mk_nil : ListBlank.mk ([] : List Γ) = default :=
rfl@[simp]
theorem ListBlank.head_default : (default : ListBlank Γ).head = default :=
rfl@[simp]
theorem ListBlank.head_default_fin {n : ℕ} [NeZero n] :
(default : ListBlank (Fin n)).head = 0 :=
rfl@[simp]
theorem ListBlank.tail_default : (default : ListBlank Γ).tail = default :=
Quotient.sound' (Or.inl ⟨0, rfl⟩)@[simp]
theorem ListBlank.cons_default_default :
ListBlank.cons (default : Γ) (default : ListBlank Γ) = default := by Γ:Type u_1inst✝:Inhabited Γ⊢ default >> default = default
simpa using ListBlank.cons_head_tail (default : ListBlank Γ) All goals completed! 🐙@[simp]
theorem ListBlank.cons_zero_default {n : ℕ} [NeZero n] :
ListBlank.cons (0 : Fin n) (default : ListBlank (Fin n)) = default :=
ListBlank.cons_default_defaulttheorem ListBlank.default_eq_append_default :
(default : ListBlank Γ) = ListBlank.append [default] default := by Γ:Type u_1inst✝:Inhabited Γ⊢ default = [default] +> default
simp All goals completed! 🐙theorem ListBlank.default_eq_append_zero {n : ℕ} [NeZero n] :
(default : ListBlank (Fin n)) = ListBlank.append [0] default := by n:ℕinst✝:NeZero n⊢ default = [0] +> default
simp All goals completed! 🐙@[simp]
theorem ListBlank.append_nil (L : ListBlank Γ) :
ListBlank.append ([] : List Γ) L = L :=
rfl@[simp]
theorem ListBlank.append_cons (a : Γ) (l : List Γ) (L : ListBlank Γ) :
ListBlank.append (a :: l) L = ListBlank.cons a (ListBlank.append l L) :=
rfltheorem ListBlank.append_append (s : ListBlank Γ) (l₁ l₂ : List Γ) :
ListBlank.append l₂ (ListBlank.append l₁ s) = ListBlank.append (l₂ ++ l₁) s :=
(ListBlank.append_assoc l₂ l₁ s).symmtheorem ListBlank.append_comm_of_comm {l₁ l₂ : List Γ} (h : l₁ ++ l₂ = l₂ ++ l₁)
(s : ListBlank Γ) :
ListBlank.append l₂ (ListBlank.append l₁ s) = ListBlank.append l₁ (ListBlank.append l₂ s) := by Γ:Type u_1inst✝:Inhabited Γl₁:List Γl₂:List Γh:l₁ ++ l₂ = l₂ ++ l₁s:ListBlank Γ⊢ l₂ +> l₁ +> s = l₁ +> l₂ +> s
rw [ListBlank.append_append, Γ:Type u_1inst✝:Inhabited Γl₁:List Γl₂:List Γh:l₁ ++ l₂ = l₂ ++ l₁s:ListBlank Γ⊢ (l₂ ++ l₁) +> s = l₁ +> l₂ +> s ← h, Γ:Type u_1inst✝:Inhabited Γl₁:List Γl₂:List Γh:l₁ ++ l₂ = l₂ ++ l₁s:ListBlank Γ⊢ (l₁ ++ l₂) +> s = l₁ +> l₂ +> s ← ListBlank.append_append Γ:Type u_1inst✝:Inhabited Γl₁:List Γl₂:List Γh:l₁ ++ l₂ = l₂ ++ l₁s:ListBlank Γ⊢ l₁ +> l₂ +> s = l₁ +> l₂ +> s] All goals completed! 🐙theorem ListBlank.append_pow_comm (u : List Γ) (k : ℕ) (s : ListBlank Γ) :
ListBlank.append (u ^ k) (ListBlank.append u s) =
ListBlank.append u (ListBlank.append (u ^ k) s) := by Γ:Type u_1inst✝:Inhabited Γu:List Γk:ℕs:ListBlank Γ⊢ u ^ k +> u +> s = u +> u ^ k +> s
apply ListBlank.append_comm_of_comm Γ:Type u_1inst✝:Inhabited Γu:List Γk:ℕs:ListBlank Γ⊢ u ++ u ^ k = u ^ k ++ u
rw [← list_pow_succ, Γ:Type u_1inst✝:Inhabited Γu:List Γk:ℕs:ListBlank Γ⊢ u ^ (k + 1) = u ^ k ++ u ← list_pow_succ' Γ:Type u_1inst✝:Inhabited Γu:List Γk:ℕs:ListBlank Γ⊢ u ^ (k + 1) = u ^ (k + 1)] All goals completed! 🐙theorem swap_single_pair_pow (a : Γ) (k : ℕ) (s : ListBlank Γ) :
ListBlank.append (([a, a] : List Γ) ^ k) (ListBlank.append [a] s) =
ListBlank.append [a] (ListBlank.append (([a, a] : List Γ) ^ k) s) := by Γ:Type u_1inst✝:Inhabited Γa:Γk:ℕs:ListBlank Γ⊢ [a, a] ^ k +> [a] +> s = [a] +> [a, a] ^ k +> s
rw [pair_pow_eq_singleton_pow_two_mul, Γ:Type u_1inst✝:Inhabited Γa:Γk:ℕs:ListBlank Γ⊢ [a] ^ (2 * k) +> [a] +> s = [a] +> [a] ^ (2 * k) +> s ListBlank.append_pow_comm Γ:Type u_1inst✝:Inhabited Γa:Γk:ℕs:ListBlank Γ⊢ [a] +> [a] ^ (2 * k) +> s = [a] +> [a] ^ (2 * k) +> s] All goals completed! 🐙theorem swap_1_11_pow (k : ℕ) (s : ListBlank (Fin 2)) :
ListBlank.append (([1, 1] : List (Fin 2)) ^ k) (ListBlank.append [1] s) =
ListBlank.append [1] (ListBlank.append (([1, 1] : List (Fin 2)) ^ k) s) :=
swap_single_pair_pow 1 k stheorem ListBlank.append_pow_succ (l : List Γ) (n : ℕ) (L : ListBlank Γ) :
ListBlank.append (l ^ (n + 1)) L = ListBlank.append l (ListBlank.append (l ^ n) L) := by Γ:Type u_1inst✝:Inhabited Γl:List Γn:ℕL:ListBlank Γ⊢ l ^ (n + 1) +> L = l +> l ^ n +> L
rw [list_pow_succ, Γ:Type u_1inst✝:Inhabited Γl:List Γn:ℕL:ListBlank Γ⊢ (l ++ l ^ n) +> L = l +> l ^ n +> L ListBlank.append_assoc Γ:Type u_1inst✝:Inhabited Γl:List Γn:ℕL:ListBlank Γ⊢ l +> l ^ n +> L = l +> l ^ n +> L] All goals completed! 🐙theorem ListBlank.append_pow_add (l : List Γ) (m n : ℕ) (L : ListBlank Γ) :
ListBlank.append (l ^ (m + n)) L = ListBlank.append (l ^ m) (ListBlank.append (l ^ n) L) := by Γ:Type u_1inst✝:Inhabited Γl:List Γm:ℕn:ℕL:ListBlank Γ⊢ l ^ (m + n) +> L = l ^ m +> l ^ n +> L
rw [list_pow_add, Γ:Type u_1inst✝:Inhabited Γl:List Γm:ℕn:ℕL:ListBlank Γ⊢ (l ^ m ++ l ^ n) +> L = l ^ m +> l ^ n +> L ListBlank.append_assoc Γ:Type u_1inst✝:Inhabited Γl:List Γm:ℕn:ℕL:ListBlank Γ⊢ l ^ m +> l ^ n +> L = l ^ m +> l ^ n +> L] All goals completed! 🐙theorem append_10_pow_one (k : ℕ) (s : ListBlank (Fin 2)) :
ListBlank.append (([1, 0] : List (Fin 2)) ^ k) (ListBlank.append [1] s) =
ListBlank.append [1] (ListBlank.append (([0, 1] : List (Fin 2)) ^ k) s) := by k:ℕs:ListBlank (Fin 2)⊢ [1, 0] ^ k +> [1] +> s = [1] +> [0, 1] ^ k +> s
induction k generalizing s with
| zero => zero s:ListBlank (Fin 2)⊢ [1, 0] ^ 0 +> [1] +> s = [1] +> [0, 1] ^ 0 +> s rfl All goals completed! 🐙
| succ k ih => succ k:ℕih:∀ (s : ListBlank (Fin 2)), [1, 0] ^ k +> [1] +> s = [1] +> [0, 1] ^ k +> ss:ListBlank (Fin 2)⊢ [1, 0] ^ (k + 1) +> [1] +> s = [1] +> [0, 1] ^ (k + 1) +> s
rw [ListBlank.append_pow_succ, succ k:ℕih:∀ (s : ListBlank (Fin 2)), [1, 0] ^ k +> [1] +> s = [1] +> [0, 1] ^ k +> ss:ListBlank (Fin 2)⊢ [1, 0] +> [1, 0] ^ k +> [1] +> s = [1] +> [0, 1] ^ (k + 1) +> s ListBlank.append_pow_succ, succ k:ℕih:∀ (s : ListBlank (Fin 2)), [1, 0] ^ k +> [1] +> s = [1] +> [0, 1] ^ k +> ss:ListBlank (Fin 2)⊢ [1, 0] +> [1, 0] ^ k +> [1] +> s = [1] +> [0, 1] +> [0, 1] ^ k +> s ih succ k:ℕih:∀ (s : ListBlank (Fin 2)), [1, 0] ^ k +> [1] +> s = [1] +> [0, 1] ^ k +> ss:ListBlank (Fin 2)⊢ [1, 0] +> [1] +> [0, 1] ^ k +> s = [1] +> [0, 1] +> [0, 1] ^ k +> s] succ k:ℕih:∀ (s : ListBlank (Fin 2)), [1, 0] ^ k +> [1] +> s = [1] +> [0, 1] ^ k +> ss:ListBlank (Fin 2)⊢ [1, 0] +> [1] +> [0, 1] ^ k +> s = [1] +> [0, 1] +> [0, 1] ^ k +> s
rfl All goals completed! 🐙theorem append_01_pow_zero (k : ℕ) (s : ListBlank (Fin 2)) :
ListBlank.append (([0, 1] : List (Fin 2)) ^ k) (ListBlank.append [0] s) =
ListBlank.append [0] (ListBlank.append (([1, 0] : List (Fin 2)) ^ k) s) := by k:ℕs:ListBlank (Fin 2)⊢ [0, 1] ^ k +> [0] +> s = [0] +> [1, 0] ^ k +> s
induction k generalizing s with
| zero => zero s:ListBlank (Fin 2)⊢ [0, 1] ^ 0 +> [0] +> s = [0] +> [1, 0] ^ 0 +> s rfl All goals completed! 🐙
| succ k ih => succ k:ℕih:∀ (s : ListBlank (Fin 2)), [0, 1] ^ k +> [0] +> s = [0] +> [1, 0] ^ k +> ss:ListBlank (Fin 2)⊢ [0, 1] ^ (k + 1) +> [0] +> s = [0] +> [1, 0] ^ (k + 1) +> s
rw [ListBlank.append_pow_succ, succ k:ℕih:∀ (s : ListBlank (Fin 2)), [0, 1] ^ k +> [0] +> s = [0] +> [1, 0] ^ k +> ss:ListBlank (Fin 2)⊢ [0, 1] +> [0, 1] ^ k +> [0] +> s = [0] +> [1, 0] ^ (k + 1) +> s ListBlank.append_pow_succ, succ k:ℕih:∀ (s : ListBlank (Fin 2)), [0, 1] ^ k +> [0] +> s = [0] +> [1, 0] ^ k +> ss:ListBlank (Fin 2)⊢ [0, 1] +> [0, 1] ^ k +> [0] +> s = [0] +> [1, 0] +> [1, 0] ^ k +> s ih succ k:ℕih:∀ (s : ListBlank (Fin 2)), [0, 1] ^ k +> [0] +> s = [0] +> [1, 0] ^ k +> ss:ListBlank (Fin 2)⊢ [0, 1] +> [0] +> [1, 0] ^ k +> s = [0] +> [1, 0] +> [1, 0] ^ k +> s] succ k:ℕih:∀ (s : ListBlank (Fin 2)), [0, 1] ^ k +> [0] +> s = [0] +> [1, 0] ^ k +> ss:ListBlank (Fin 2)⊢ [0, 1] +> [0] +> [1, 0] ^ k +> s = [0] +> [1, 0] +> [1, 0] ^ k +> s
rfl All goals completed! 🐙theorem append_zero_10_pow_one (k : ℕ) (s : ListBlank (Fin 2)) :
ListBlank.append [0]
(ListBlank.append (([1, 0] : List (Fin 2)) ^ k) (ListBlank.append [1] s)) =
ListBlank.append (([0, 1] : List (Fin 2)) ^ k) (ListBlank.append [0, 1] s) := by k:ℕs:ListBlank (Fin 2)⊢ [0] +> [1, 0] ^ k +> [1] +> s = [0, 1] ^ k +> [0, 1] +> s
rw [append_10_pow_one k:ℕs:ListBlank (Fin 2)⊢ [0] +> [1] +> [0, 1] ^ k +> s = [0, 1] ^ k +> [0, 1] +> s] k:ℕs:ListBlank (Fin 2)⊢ [0] +> [1] +> [0, 1] ^ k +> s = [0, 1] ^ k +> [0, 1] +> s
change ListBlank.append [0, 1] (ListBlank.append (([0, 1] : List (Fin 2)) ^ k) s) = _ k:ℕs:ListBlank (Fin 2)⊢ [0, 1] +> [0, 1] ^ k +> s = [0, 1] ^ k +> [0, 1] +> s
exact (ListBlank.append_pow_comm ([0, 1] : List (Fin 2)) k s).symm All goals completed! 🐙theorem append_zero_10_pow_one_succ (k : ℕ) (s : ListBlank (Fin 2)) :
ListBlank.append [0]
(ListBlank.append (([1, 0] : List (Fin 2)) ^ k) (ListBlank.append [1] s)) =
ListBlank.append (([0, 1] : List (Fin 2)) ^ (k + 1)) s := by k:ℕs:ListBlank (Fin 2)⊢ [0] +> [1, 0] ^ k +> [1] +> s = [0, 1] ^ (k + 1) +> s
rw [append_10_pow_one, k:ℕs:ListBlank (Fin 2)⊢ [0] +> [1] +> [0, 1] ^ k +> s = [0, 1] ^ (k + 1) +> s ListBlank.append_pow_succ k:ℕs:ListBlank (Fin 2)⊢ [0] +> [1] +> [0, 1] ^ k +> s = [0, 1] +> [0, 1] ^ k +> s] k:ℕs:ListBlank (Fin 2)⊢ [0] +> [1] +> [0, 1] ^ k +> s = [0, 1] +> [0, 1] ^ k +> s
rfl All goals completed! 🐙Standard List, ListBlank, and Power Lemmas
Common List and ListBlank lemmas used across official proofs.
theorem pow_zero_list {α : Type*} (u : List α) : u ^ (0 : ℕ) = [] := rfltheorem pow_succ_list {α : Type*} (u : List α) (n : ℕ) : u ^ (n + 1) = u ++ u ^ n := rfltheorem nil_append_list {α : Type*} (l : List α) : ([] : List α) ++ l = l := rfltheorem cons_append_list {α : Type*} (x : α) (xs ys : List α) :
(x :: xs) ++ ys = x :: (xs ++ ys) := rfltheorem append_nil_list {α : Type*} (l : List α) : l ++ [] = l := List.append_nil ltheorem listblank_append_nil {α : Type*} [Inhabited α] (b : ListBlank α) :
([] : List α) +> b = b := rfltheorem listblank_append_cons {α : Type*} [Inhabited α] (x : α) (xs : List α) (b : ListBlank α) :
(x :: xs) +> b = x >> (xs +> b) := rfltheorem default_head : (default : ListBlank (Fin 2)).head = 0 := rfltheorem default_tail : (default : ListBlank (Fin 2)).tail = default := rfltheorem zero_cons_default : (0 : Fin 2) >> default = default := ListBlank.cons_zero_defaulttheorem init_nil : (init ([] : List (Fin 2))) = ⟨some (0 : Fin 6), ⟨0, default, default⟩⟩ := rfltheorem listblank_append_right_assoc {α : Type*} [Inhabited α] (l₁ l₂ : List α) (s : ListBlank α) :
(l₁ ++ l₂) +> s = l₁ +> (l₂ +> s) := by α:Type u_3inst✝:Inhabited αl₁:List αl₂:List αs:ListBlank α⊢ (l₁ ++ l₂) +> s = l₁ +> l₂ +> s
induction l₁ with
| nil => nil α:Type u_3inst✝:Inhabited αl₂:List αs:ListBlank α⊢ ([] ++ l₂) +> s = [] +> l₂ +> s rfl All goals completed! 🐙
| cons x xs ih => cons α:Type u_3inst✝:Inhabited αl₂:List αs:ListBlank αx:αxs:List αih:(xs ++ l₂) +> s = xs +> l₂ +> s⊢ (x :: xs ++ l₂) +> s = (x :: xs) +> l₂ +> s simp only [List.cons_append, ListBlank.append, ih] All goals completed! 🐙theorem listblank_append_append {α : Type*} [Inhabited α] (s : ListBlank α) (l₁ l₂ : List α) :
(s <+ l₁) <+ l₂ = s <+ (l₂ ++ l₁) :=
ListBlank.append_append s l₁ l₂theorem list_pow_append_one {α : Type*} (u : List α) (k : ℕ) :
u ^ k ++ u = u ^ (k + 1) :=
(list_pow_succ' u k).symmtheorem pow_append_pow {α : Type*} [Inhabited α] (u : List α) (n m : ℕ) (T : ListBlank α) :
(u ^ n) +> ((u ^ m) +> T) = (u ^ (n + m)) +> T := by α:Type u_3inst✝:Inhabited αu:List αn:ℕm:ℕT:ListBlank α⊢ u ^ n +> u ^ m +> T = u ^ (n + m) +> T
rw [list_pow_add, α:Type u_3inst✝:Inhabited αu:List αn:ℕm:ℕT:ListBlank α⊢ u ^ n +> u ^ m +> T = (u ^ n ++ u ^ m) +> T listblank_append_right_assoc α:Type u_3inst✝:Inhabited αu:List αn:ℕm:ℕT:ListBlank α⊢ u ^ n +> u ^ m +> T = u ^ n +> u ^ m +> T] All goals completed! 🐙theorem ones_append_cons_one (n : ℕ) (T : ListBlank (Fin 2)) :
(([1] : List (Fin 2)) ^ n) +> ((1 : Fin 2) >> T) =
(1 : Fin 2) >> ((([1] : List (Fin 2)) ^ n) +> T) := by n:ℕT:ListBlank (Fin 2)⊢ [1] ^ n +> 1 >> T = 1 >> [1] ^ n +> T
induction n with
| zero => zero T:ListBlank (Fin 2)⊢ [1] ^ 0 +> 1 >> T = 1 >> [1] ^ 0 +> T rfl All goals completed! 🐙
| succ k ih => succ T:ListBlank (Fin 2)k:ℕih:[1] ^ k +> 1 >> T = 1 >> [1] ^ k +> T⊢ [1] ^ (k + 1) +> 1 >> T = 1 >> [1] ^ (k + 1) +> T
simp only [pow_succ_list, cons_append_list, nil_append_list, listblank_append_cons, ih] All goals completed! 🐙theorem zeros_append_cons_zero (n : ℕ) (T : ListBlank (Fin 2)) :
(([0] : List (Fin 2)) ^ n) +> ((0 : Fin 2) >> T) =
(0 : Fin 2) >> ((([0] : List (Fin 2)) ^ n) +> T) := by n:ℕT:ListBlank (Fin 2)⊢ [0] ^ n +> 0 >> T = 0 >> [0] ^ n +> T
induction n with
| zero => zero T:ListBlank (Fin 2)⊢ [0] ^ 0 +> 0 >> T = 0 >> [0] ^ 0 +> T rfl All goals completed! 🐙
| succ k ih => succ T:ListBlank (Fin 2)k:ℕih:[0] ^ k +> 0 >> T = 0 >> [0] ^ k +> T⊢ [0] ^ (k + 1) +> 0 >> T = 0 >> [0] ^ (k + 1) +> T
simp only [pow_succ_list, cons_append_list, nil_append_list, listblank_append_cons, ih] All goals completed! 🐙theorem zeros_append_default (n : ℕ) :
(([0] : List (Fin 2)) ^ n) +> (default : ListBlank (Fin 2)) = default := by n:ℕ⊢ [0] ^ n +> default = default
induction n with
| zero => zero ⊢ [0] ^ 0 +> default = default rfl All goals completed! 🐙
| succ k ih => succ k:ℕih:[0] ^ k +> default = default⊢ [0] ^ (k + 1) +> default = default
simp only [pow_succ_list, cons_append_list, nil_append_list, listblank_append_cons, ih,
zero_cons_default] All goals completed! 🐙theorem listblank_eq_one_cons_tail {Z : ListBlank (Fin 2)} (hZ : Z.head = 1) :
Z = (1 : Fin 2) >> Z.tail := by Z:ListBlank (Fin 2)hZ:Z.head = 1⊢ Z = 1 >> Z.tail
rw [← hZ, Z:ListBlank (Fin 2)hZ:Z.head = 1⊢ Z = Z.head >> Z.tail Turing.ListBlank.cons_head_tail Z:ListBlank (Fin 2)hZ:Z.head = 1⊢ Z = Z] All goals completed! 🐙theorem init_nil_eq_headRight :
(init ([] : List Γ) : Cfg Γ Λ) = Cfg.headRight default default default :=
rfltheorem init_nil_eq_headLeft :
(init ([] : List Γ) : Cfg Γ Λ) = Cfg.headLeft default default default := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited Λ⊢ init [] = Cfg.headLeft default default default
simp [init, Cfg.headLeft, Tape.mk₁, Tape.mk₂, Tape.mk'] All goals completed! 🐙omit [Inhabited Λ] in
theorem Cfg.headRight_cons (q : Λ) (a : Γ) (l r : ListBlank Γ) :
Cfg.headRight q l (ListBlank.cons a r) = Cfg.headLeft q (ListBlank.cons a l) r := by Γ:Type u_1Λ:Type u_2inst✝:Inhabited Γq:Λa:Γl:ListBlank Γr:ListBlank Γ⊢ headRight q l (a >> r) = headLeft q (a >> l) r
simp [Cfg.headRight, Cfg.headLeft] All goals completed! 🐙omit [Inhabited Λ] in
theorem Cfg.headLeft_cons (q : Λ) (a : Γ) (l r : ListBlank Γ) :
Cfg.headLeft q (ListBlank.cons a l) r = Cfg.headRight q l (ListBlank.cons a r) := by Γ:Type u_1Λ:Type u_2inst✝:Inhabited Γq:Λa:Γl:ListBlank Γr:ListBlank Γ⊢ headLeft q (a >> l) r = headRight q l (a >> r)
simp [Cfg.headRight, Cfg.headLeft] All goals completed! 🐙theorem step_headRight_right {M : Machine Γ Λ} {q q' : Λ} {a b : Γ}
(hM : M q a = some (some q', Stmt.write b Dir.right)) (l r : ListBlank Γ) :
step M (Cfg.headRight q l (ListBlank.cons a r)) =
some (Cfg.headRight q' (ListBlank.cons b l) r) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λq:Λq':Λa:Γb:ΓhM:M q a = some (some q', { symbol := b, dir := Dir.right })l:ListBlank Γr:ListBlank Γ⊢ Cfg.headRight q l (a >> r) [M]⊢ Cfg.headRight q' (b >> l) r
simp [Cfg.headRight, step, hM, Tape.write, Tape.move] All goals completed! 🐙theorem step_headRight_left {M : Machine Γ Λ} {q q' : Λ} {a b : Γ}
(hM : M q a = some (some q', Stmt.write b Dir.left)) (l r : ListBlank Γ) :
step M (Cfg.headRight q l (ListBlank.cons a r)) =
some (Cfg.headLeft q' l (ListBlank.cons b r)) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λq:Λq':Λa:Γb:ΓhM:M q a = some (some q', { symbol := b, dir := Dir.left })l:ListBlank Γr:ListBlank Γ⊢ Cfg.headRight q l (a >> r) [M]⊢ Cfg.headLeft q' l (b >> r)
simp [Cfg.headLeft, step, hM, Tape.write, Tape.move] All goals completed! 🐙theorem step_headLeft_right {M : Machine Γ Λ} {q q' : Λ} {a b : Γ}
(hM : M q a = some (some q', Stmt.write b Dir.right)) (l r : ListBlank Γ) :
step M (Cfg.headLeft q (ListBlank.cons a l) r) =
some (Cfg.headRight q' (ListBlank.cons b l) r) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λq:Λq':Λa:Γb:ΓhM:M q a = some (some q', { symbol := b, dir := Dir.right })l:ListBlank Γr:ListBlank Γ⊢ Cfg.headLeft q (a >> l) r [M]⊢ Cfg.headRight q' (b >> l) r
simp [Cfg.headRight, step, hM, Tape.write, Tape.move] All goals completed! 🐙theorem step_headLeft_left {M : Machine Γ Λ} {q q' : Λ} {a b : Γ}
(hM : M q a = some (some q', Stmt.write b Dir.left)) (l r : ListBlank Γ) :
step M (Cfg.headLeft q (ListBlank.cons a l) r) =
some (Cfg.headLeft q' l (ListBlank.cons b r)) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λq:Λq':Λa:Γb:ΓhM:M q a = some (some q', { symbol := b, dir := Dir.left })l:ListBlank Γr:ListBlank Γ⊢ Cfg.headLeft q (a >> l) r [M]⊢ Cfg.headLeft q' l (b >> r)
simp [Cfg.headLeft, step, hM, Tape.write, Tape.move] All goals completed! 🐙theorem step_headRight_none {M : Machine Γ Λ} {q : Λ} {a : Γ}
(hM : M q a = none) (l r : ListBlank Γ) :
step M (Cfg.headRight q l (ListBlank.cons a r)) = none := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λq:Λa:ΓhM:M q a = nonel:ListBlank Γr:ListBlank Γ⊢ step M (Cfg.headRight q l (a >> r)) = none
simp [step, hM] All goals completed! 🐙theorem step_headLeft_none {M : Machine Γ Λ} {q : Λ} {a : Γ}
(hM : M q a = none) (l r : ListBlank Γ) :
step M (Cfg.headLeft q (ListBlank.cons a l) r) = none := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λq:Λa:ΓhM:M q a = nonel:ListBlank Γr:ListBlank Γ⊢ step M (Cfg.headLeft q (a >> l) r) = none
simp [step, hM] All goals completed! 🐙theorem step_headRight_default_right {M : Machine Γ Λ} {q q' : Λ} {b : Γ}
(hM : M q default = some (some q', Stmt.write b Dir.right)) (l : ListBlank Γ) :
step M (Cfg.headRight q l default) =
some (Cfg.headRight q' (ListBlank.cons b l) default) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λq:Λq':Λb:ΓhM:M q default = some (some q', { symbol := b, dir := Dir.right })l:ListBlank Γ⊢ Cfg.headRight q l default [M]⊢ Cfg.headRight q' (b >> l) default
simpa using step_headRight_right hM l default All goals completed! 🐙theorem step_headRight_default_left {M : Machine Γ Λ} {q q' : Λ} {b : Γ}
(hM : M q default = some (some q', Stmt.write b Dir.left)) (l : ListBlank Γ) :
step M (Cfg.headRight q l default) =
some (Cfg.headLeft q' l (ListBlank.cons b default)) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λq:Λq':Λb:ΓhM:M q default = some (some q', { symbol := b, dir := Dir.left })l:ListBlank Γ⊢ Cfg.headRight q l default [M]⊢ Cfg.headLeft q' l (b >> default)
simpa using step_headRight_left hM l default All goals completed! 🐙theorem step_headLeft_default_right {M : Machine Γ Λ} {q q' : Λ} {b : Γ}
(hM : M q default = some (some q', Stmt.write b Dir.right)) (r : ListBlank Γ) :
step M (Cfg.headLeft q default r) =
some (Cfg.headRight q' (ListBlank.cons b default) r) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λq:Λq':Λb:ΓhM:M q default = some (some q', { symbol := b, dir := Dir.right })r:ListBlank Γ⊢ Cfg.headLeft q default r [M]⊢ Cfg.headRight q' (b >> default) r
simpa using step_headLeft_right hM default r All goals completed! 🐙theorem step_headLeft_default_left {M : Machine Γ Λ} {q q' : Λ} {b : Γ}
(hM : M q default = some (some q', Stmt.write b Dir.left)) (r : ListBlank Γ) :
step M (Cfg.headLeft q default r) =
some (Cfg.headLeft q' default (ListBlank.cons b r)) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λq:Λq':Λb:ΓhM:M q default = some (some q', { symbol := b, dir := Dir.left })r:ListBlank Γ⊢ Cfg.headLeft q default r [M]⊢ Cfg.headLeft q' default (b >> r)
simpa using step_headLeft_left hM default r All goals completed! 🐙
Tape Pattern Evaluation (evalTapeExpr, evalTapePattern)
@[simp]
theorem evalTapeExpr_default (vars : ℕ → ℕ) :
evalTapeExpr (TapeExpr.default : TapeExpr Γ) vars = default :=
rfl@[simp]
theorem evalTapeExpr_sym (a : Γ) (rest : TapeExpr Γ) (vars : ℕ → ℕ) :
evalTapeExpr (.sym a rest) vars = ListBlank.cons a (evalTapeExpr rest vars) :=
rfl@[simp]
theorem evalTapeExpr_rep (blk : List Γ) (v : ℕ) (rest : TapeExpr Γ) (vars : ℕ → ℕ) :
evalTapeExpr (.rep blk v rest) vars =
ListBlank.append (blk ^ vars v) (evalTapeExpr rest vars) :=
rfl@[simp]
theorem evalTapePattern_some (q : Λ) (l r : TapeExpr Γ) (vars : ℕ → ℕ) :
evalTapePattern ⟨l, some q, r⟩ vars =
Cfg.headRight q (evalTapeExpr l vars) (evalTapeExpr r vars) :=
rfl
Configuration cfg advances in ReachesPlus either to a member of ps or to a halting
configuration of M.
def StepsToClosed (M : Machine Γ Λ) (ps : TapePatternSet Γ Λ) (cfg : Cfg Γ Λ) : Prop :=
∃ cfg', ReachesPlus M cfg cfg' ∧
(IsInPatternSet ps cfg' ∨ (step M cfg').isNone)theorem StepsToClosed.of_reachesPlus {M : Machine Γ Λ} {ps : TapePatternSet Γ Λ}
{c₁ c₂ : Cfg Γ Λ} (h : ReachesPlus M c₁ c₂) (hc₂ : StepsToClosed M ps c₂) :
StepsToClosed M ps c₁ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λps:TapePatternSet Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh:c₁ [M]⊢⁺ c₂hc₂:StepsToClosed M ps c₂⊢ StepsToClosed M ps c₁
obtain ⟨cfg', h', h_end⟩ := hc₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λps:TapePatternSet Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh:c₁ [M]⊢⁺ c₂cfg':Cfg Γ Λh':c₂ [M]⊢⁺ cfg'h_end:IsInPatternSet ps cfg' ∨ (step M cfg').isNone = true⊢ StepsToClosed M ps c₁
exact ⟨cfg', h.trans h', h_end⟩ All goals completed! 🐙theorem StepsToClosed.of_reachesStar {M : Machine Γ Λ} {ps : TapePatternSet Γ Λ}
{c₁ c₂ : Cfg Γ Λ} (h : ReachesStar M c₁ c₂) (hc₂ : StepsToClosed M ps c₂) :
StepsToClosed M ps c₁ := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λps:TapePatternSet Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh:c₁ [M]⊢* c₂hc₂:StepsToClosed M ps c₂⊢ StepsToClosed M ps c₁
obtain ⟨cfg', h', h_end⟩ := hc₂ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ Λps:TapePatternSet Γ Λc₁:Cfg Γ Λc₂:Cfg Γ Λh:c₁ [M]⊢* c₂cfg':Cfg Γ Λh':c₂ [M]⊢⁺ cfg'h_end:IsInPatternSet ps cfg' ∨ (step M cfg').isNone = true⊢ StepsToClosed M ps c₁
exact ⟨cfg', h.trans_plus h', h_end⟩ All goals completed! 🐙theorem StepsToClosed.of_isInPatternSet {M : Machine Γ Λ} {ps : TapePatternSet Γ Λ}
{c₁ c₂ : Cfg Γ Λ} (h : ReachesPlus M c₁ c₂) (hc₂ : IsInPatternSet ps c₂) :
StepsToClosed M ps c₁ :=
⟨c₂, h, Or.inl hc₂⟩theorem StepsToClosed.of_halting {M : Machine Γ Λ} {ps : TapePatternSet Γ Λ}
{c₁ c₂ : Cfg Γ Λ} (h : ReachesPlus M c₁ c₂) (hc₂ : (step M c₂).isNone) :
StepsToClosed M ps c₁ :=
⟨c₂, h, Or.inr hc₂⟩
Collatz-Like Acceleration (CollatzHalts, IsValidAcceleration)
theorem CollatzHalts.of_next_eq_none {S : Type*} {next : S → Option S} {s : S}
(h : next s = none) :
CollatzHalts next s :=
⟨1, by S:Type u_3next:S → Option Ss:Sh:next s = none⊢ ((fun x ↦ x.bind next)^[1] (some s)).isNone = true simp [h] All goals completed! 🐙⟩theorem CollatzHalts.of_next_eq_some {S : Type*} {next : S → Option S} {s s' : S}
(h : next s = some s') (h' : CollatzHalts next s') :
CollatzHalts next s := by S:Type u_3next:S → Option Ss:Ss':Sh:next s = some s'h':CollatzHalts next s'⊢ CollatzHalts next s
obtain ⟨n, hn⟩ := h' S:Type u_3next:S → Option Ss:Ss':Sh:next s = some s'n:ℕhn:((fun x ↦ x.bind next)^[n] (some s')).isNone = true⊢ CollatzHalts next s
refine ⟨n + 1, ?_⟩ S:Type u_3next:S → Option Ss:Ss':Sh:next s = some s'n:ℕhn:((fun x ↦ x.bind next)^[n] (some s')).isNone = true⊢ ((fun x ↦ x.bind next)^[n + 1] (some s)).isNone = true
rw [Function.iterate_succ_apply S:Type u_3next:S → Option Ss:Ss':Sh:next s = some s'n:ℕhn:((fun x ↦ x.bind next)^[n] (some s')).isNone = true⊢ ((fun x ↦ x.bind next)^[n] ((some s).bind next)).isNone = true] S:Type u_3next:S → Option Ss:Ss':Sh:next s = some s'n:ℕhn:((fun x ↦ x.bind next)^[n] (some s')).isNone = true⊢ ((fun x ↦ x.bind next)^[n] ((some s).bind next)).isNone = true
simpa [h] using hn All goals completed! 🐙theorem IsValidAcceleration.haltsFrom_of_collatzHalts {M : Machine Γ Λ} {S : Type*}
{start : S} {encode : S → Cfg Γ Λ} {next : S → Option S}
(h : IsValidAcceleration M start encode next) {s : S} (hs : CollatzHalts next s) :
HaltsFrom M (encode s) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts:Shs:CollatzHalts next s⊢ HaltsFrom M (encode s)
obtain ⟨n, hn⟩ := hs Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts:Sn:ℕhn:((fun x ↦ x.bind next)^[n] (some s)).isNone = true⊢ HaltsFrom M (encode s)
induction n generalizing s with
| zero => zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts:Shn:((fun x ↦ x.bind next)^[0] (some s)).isNone = true⊢ HaltsFrom M (encode s)
simp at hn All goals completed! 🐙
| succ n ih => succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nextn:ℕih:∀ {s : S}, ((fun x ↦ x.bind next)^[n] (some s)).isNone = true → HaltsFrom M (encode s)s:Shn:((fun x ↦ x.bind next)^[n + 1] (some s)).isNone = true⊢ HaltsFrom M (encode s)
rw [Function.iterate_succ_apply succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nextn:ℕih:∀ {s : S}, ((fun x ↦ x.bind next)^[n] (some s)).isNone = true → HaltsFrom M (encode s)s:Shn:((fun x ↦ x.bind next)^[n] ((some s).bind next)).isNone = true⊢ HaltsFrom M (encode s)] at hn succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nextn:ℕih:∀ {s : S}, ((fun x ↦ x.bind next)^[n] (some s)).isNone = true → HaltsFrom M (encode s)s:Shn:((fun x ↦ x.bind next)^[n] ((some s).bind next)).isNone = true⊢ HaltsFrom M (encode s)
rcases hnext : next s with _ | s' succ.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nextn:ℕih:∀ {s : S}, ((fun x ↦ x.bind next)^[n] (some s)).isNone = true → HaltsFrom M (encode s)s:Shn:((fun x ↦ x.bind next)^[n] ((some s).bind next)).isNone = truehnext:next s = none⊢ HaltsFrom M (encode s)succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nextn:ℕih:∀ {s : S}, ((fun x ↦ x.bind next)^[n] (some s)).isNone = true → HaltsFrom M (encode s)s:Shn:((fun x ↦ x.bind next)^[n] ((some s).bind next)).isNone = trues':Shnext:next s = some s'⊢ HaltsFrom M (encode s)
· succ.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nextn:ℕih:∀ {s : S}, ((fun x ↦ x.bind next)^[n] (some s)).isNone = true → HaltsFrom M (encode s)s:Shn:((fun x ↦ x.bind next)^[n] ((some s).bind next)).isNone = truehnext:next s = none⊢ HaltsFrom M (encode s) exact h.step_none s hnext All goals completed! 🐙
· succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nextn:ℕih:∀ {s : S}, ((fun x ↦ x.bind next)^[n] (some s)).isNone = true → HaltsFrom M (encode s)s:Shn:((fun x ↦ x.bind next)^[n] ((some s).bind next)).isNone = trues':Shnext:next s = some s'⊢ HaltsFrom M (encode s) refine HaltsFrom.of_reachesStar (h.step_some s s' hnext).to_star (ih ?_) succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nextn:ℕih:∀ {s : S}, ((fun x ↦ x.bind next)^[n] (some s)).isNone = true → HaltsFrom M (encode s)s:Shn:((fun x ↦ x.bind next)^[n] ((some s).bind next)).isNone = trues':Shnext:next s = some s'⊢ ((fun x ↦ x.bind next)^[n] (some s')).isNone = true
simpa [hnext] using hn All goals completed! 🐙
A valid Collatz-like acceleration of M preserves and reflects halting: M halts from the
blank tape if and only if the accelerated transition function next halts from start.
theorem IsValidAcceleration.isHalt_iff {M : Machine Γ Λ} {S : Type*}
{start : S} {encode : S → Cfg Γ Λ} {next : S → Option S}
(h : IsValidAcceleration M start encode next) :
IsHalt M ↔ CollatzHalts next start := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode next⊢ IsHalt M ↔ CollatzHalts next start
constructor mp Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode next⊢ IsHalt M → CollatzHalts next startmpr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode next⊢ CollatzHalts next start → IsHalt M
· mp Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode next⊢ IsHalt M → CollatzHalts next start intro h_halt mp Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt M⊢ CollatzHalts next start
by_contra h_not_collatz mp Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt Mh_not_collatz:¬CollatzHalts next start⊢ False
have h_not_halt : IsNotHalt M :=
IsNotHalt.of_reachesPlus_invariant
(P := fun cfg => ∃ s, cfg = encode s ∧ ¬ CollatzHalts next s)
h.init_reaches
⟨start, rfl, h_not_collatz⟩
(fun cfg hP => by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt Mh_not_collatz:¬CollatzHalts next startcfg:Cfg Γ ΛhP:∃ s, cfg = encode s ∧ ¬CollatzHalts next s⊢ ∃ c', (cfg [M]⊢⁺ c') ∧ ∃ s, c' = encode s ∧ ¬CollatzHalts next s
obtain ⟨s, rfl, hns⟩ := hP Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt Mh_not_collatz:¬CollatzHalts next starts:Shns:¬CollatzHalts next s⊢ ∃ c', (encode s [M]⊢⁺ c') ∧ ∃ s, c' = encode s ∧ ¬CollatzHalts next s
rcases hnext : next s with _ | s' none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt Mh_not_collatz:¬CollatzHalts next starts:Shns:¬CollatzHalts next shnext:next s = none⊢ ∃ c', (encode s [M]⊢⁺ c') ∧ ∃ s, c' = encode s ∧ ¬CollatzHalts next ssome Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt Mh_not_collatz:¬CollatzHalts next starts:Shns:¬CollatzHalts next ss':Shnext:next s = some s'⊢ ∃ c', (encode s [M]⊢⁺ c') ∧ ∃ s, c' = encode s ∧ ¬CollatzHalts next s
· none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt Mh_not_collatz:¬CollatzHalts next starts:Shns:¬CollatzHalts next shnext:next s = none⊢ ∃ c', (encode s [M]⊢⁺ c') ∧ ∃ s, c' = encode s ∧ ¬CollatzHalts next s exact False.elim (hns (CollatzHalts.of_next_eq_none hnext)) All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt Mh_not_collatz:¬CollatzHalts next starts:Shns:¬CollatzHalts next ss':Shnext:next s = some s'⊢ ∃ c', (encode s [M]⊢⁺ c') ∧ ∃ s, c' = encode s ∧ ¬CollatzHalts next s refine ⟨encode s', h.step_some s s' hnext, s', rfl, ?_⟩ some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt Mh_not_collatz:¬CollatzHalts next starts:Shns:¬CollatzHalts next ss':Shnext:next s = some s'⊢ ¬CollatzHalts next s'
intro hs' some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt Mh_not_collatz:¬CollatzHalts next starts:Shns:¬CollatzHalts next ss':Shnext:next s = some s'hs':CollatzHalts next s'⊢ False
exact hns (CollatzHalts.of_next_eq_some hnext hs') All goals completed! 🐙) mp Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_halt:IsHalt Mh_not_collatz:¬CollatzHalts next starth_not_halt:IsNotHalt M⊢ False
obtain ⟨cfg, hreach, hnone⟩ := h_halt mp Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_not_collatz:¬CollatzHalts next starth_not_halt:IsNotHalt Mcfg:Cfg Γ Λhreach:init [] [M]⊢* cfghnone:(step M cfg).isNone = true⊢ False
have hsome := h_not_halt cfg hreach mp Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_not_collatz:¬CollatzHalts next starth_not_halt:IsNotHalt Mcfg:Cfg Γ Λhreach:init [] [M]⊢* cfghnone:(step M cfg).isNone = truehsome:(step M cfg).isSome = true⊢ False
rw [Option.isNone_iff_eq_none mp Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_not_collatz:¬CollatzHalts next starth_not_halt:IsNotHalt Mcfg:Cfg Γ Λhreach:init [] [M]⊢* cfghnone:step M cfg = nonehsome:(step M cfg).isSome = true⊢ False] at hnone mp Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_not_collatz:¬CollatzHalts next starth_not_halt:IsNotHalt Mcfg:Cfg Γ Λhreach:init [] [M]⊢* cfghnone:step M cfg = nonehsome:(step M cfg).isSome = true⊢ False
simp [hnone] at hsome All goals completed! 🐙
· mpr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode next⊢ CollatzHalts next start → IsHalt M intro h_collatz mpr Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexth_collatz:CollatzHalts next start⊢ IsHalt M
exact HaltsFrom.of_reachesStar h.init_reaches (h.haltsFrom_of_collatzHalts h_collatz) All goals completed! 🐙
Standard 6-State Labels (SixState)
Standard control state labels A..F (0..5 : Fin 6) for 6-state Busy Beaver machines.
namespace SixState
State A (0 : Fin 6), the initial state.
abbrev A : Fin 6 := 0
State B (1 : Fin 6).
abbrev B : Fin 6 := 1
State C (2 : Fin 6).
abbrev C : Fin 6 := 2
State D (3 : Fin 6).
abbrev D : Fin 6 := 3
State E (4 : Fin 6).
abbrev E : Fin 6 := 4
State F (5 : Fin 6).
abbrev F : Fin 6 := 5end SixState
Standard 3-State Labels (ThreeState)
Standard control state labels A..C (0..2 : Fin 3) for 3-state Busy Beaver machines.
namespace ThreeState
State A (0 : Fin 3), the initial state.
abbrev A : Fin 3 := 0
State B (1 : Fin 3).
abbrev B : Fin 3 := 1
State C (2 : Fin 3).
abbrev C : Fin 3 := 2end ThreeState
Concrete Step Execution Tactics (bb_refl, bb_step, bb_steps, bb_halt)
Close a reflexive ReachesStar goal after normalizing directed-head configurations and
ListBlank prefixes.
macro "bb_refl" : tactic =>
`(tactic| (
try simp only [Cfg.headRight, Cfg.headLeft, init, Tape.mk₁, Tape.mk₂, Tape.mk',
List.cons_append, List.nil_append, List.append_nil,
ListBlank.mk_nil, ListBlank.append, ListBlank.head_cons, ListBlank.tail_cons,
ListBlank.head_default, ListBlank.head_default_fin, ListBlank.tail_default,
ListBlank.cons_default_default, ListBlank.cons_zero_default]
exact ReachesStar.refl _ _))
Execute one concrete BusyBeaver.step on a ReachesPlus or ReachesStar goal and normalize
the resulting tape configuration.
macro "bb_step" : tactic =>
`(tactic| (
first
| refine ReachesPlus.head (by
try simp only [Cfg.headRight, Cfg.headLeft, init, Tape.mk₁, Tape.mk₂, Tape.mk',
List.cons_append, List.nil_append, List.append_nil,
ListBlank.mk_nil, ListBlank.append, ListBlank.head_cons, ListBlank.tail_cons,
ListBlank.head_default, ListBlank.head_default_fin, ListBlank.tail_default,
ListBlank.cons_default_default, ListBlank.cons_zero_default]
rfl) ?_
| refine ReachesStar.head (by
try simp only [Cfg.headRight, Cfg.headLeft, init, Tape.mk₁, Tape.mk₂, Tape.mk',
List.cons_append, List.nil_append, List.append_nil,
ListBlank.mk_nil, ListBlank.append, ListBlank.head_cons, ListBlank.tail_cons,
ListBlank.head_default, ListBlank.head_default_fin, ListBlank.tail_default,
ListBlank.cons_default_default, ListBlank.cons_zero_default]
rfl) ?_
try simp only [Tape.write, Tape.move, ListBlank.head_cons, ListBlank.tail_cons,
ListBlank.head_default, ListBlank.head_default_fin, ListBlank.tail_default,
ListBlank.cons_default_default, ListBlank.cons_zero_default]))
Repeatedly step a ReachesPlus or ReachesStar goal until it closes by reflexivity (bb_refl)
or reaches a symbolic head symbol.
macro "bb_steps" : tactic =>
`(tactic| repeat (first | bb_refl | bb_step))
Close a (step M cfg).isNone halting goal after normalizing directed-head configurations and
ListBlank prefixes.
macro "bb_halt" : tactic =>
`(tactic| (
try simp only [Cfg.headRight, Cfg.headLeft, init, Tape.mk₁, Tape.mk₂, Tape.mk',
List.cons_append, List.nil_append, List.append_nil,
ListBlank.mk_nil, ListBlank.append, ListBlank.head_cons, ListBlank.tail_cons,
ListBlank.head_default, ListBlank.head_default_fin, ListBlank.tail_default,
ListBlank.cons_default_default, ListBlank.cons_zero_default]
rfl))Directed-Head and Reachability Notations
(Defined in BusyBeaver.Defs)
Additional Half-Tape Power Lemmas
Reversed addition law for repeated block appendages on a ListBlank.
theorem ListBlank.append_pow_add_rev (s : ListBlank Γ) (u : List Γ) (m n : ℕ) :
ListBlank.append (u ^ (m + n)) s = ListBlank.append (u ^ n) (ListBlank.append (u ^ m) s) := by Γ:Type u_1inst✝:Inhabited Γs:ListBlank Γu:List Γm:ℕn:ℕ⊢ u ^ (m + n) +> s = u ^ n +> u ^ m +> s
rw [Nat.add_comm, Γ:Type u_1inst✝:Inhabited Γs:ListBlank Γu:List Γm:ℕn:ℕ⊢ u ^ (n + m) +> s = u ^ n +> u ^ m +> s ListBlank.append_pow_add Γ:Type u_1inst✝:Inhabited Γs:ListBlank Γu:List Γm:ℕn:ℕ⊢ u ^ n +> u ^ m +> s = u ^ n +> u ^ m +> s] All goals completed! 🐙
Absorb one trailing copy of u into u ^ k on a ListBlank.
theorem ListBlank.append_pow_succ' (u : List Γ) (k : ℕ) (r : ListBlank Γ) :
ListBlank.append (u ^ k) (ListBlank.append u r) = ListBlank.append (u ^ (k + 1)) r := by Γ:Type u_1inst✝:Inhabited Γu:List Γk:ℕr:ListBlank Γ⊢ u ^ k +> u +> r = u ^ (k + 1) +> r
rw [ListBlank.append_append, Γ:Type u_1inst✝:Inhabited Γu:List Γk:ℕr:ListBlank Γ⊢ (u ^ k ++ u) +> r = u ^ (k + 1) +> r list_pow_succ' Γ:Type u_1inst✝:Inhabited Γu:List Γk:ℕr:ListBlank Γ⊢ (u ^ k ++ u) +> r = (u ^ k ++ u) +> r] All goals completed! 🐙
Shift [0, 1] ^ c on the blank half-tape into 0 :: [1, 0] ^ c.
theorem default_append_01_pow (c : ℕ) :
ListBlank.append (([0, 1] : List (Fin 2)) ^ c) default =
ListBlank.cons 0 (ListBlank.append (([1, 0] : List (Fin 2)) ^ c) default) := by c:ℕ⊢ [0, 1] ^ c +> default = 0 >> [1, 0] ^ c +> default
conv_lhs => rw [ListBlank.default_eq_append_zero] c:ℕ| [0, 1] ^ c +> [0] +> default
exact append_01_pow_zero c default All goals completed! 🐙
Construct IsValidAcceleration from an initial reachability proof and a unified step theorem
dispatching on next s.
theorem IsValidAcceleration.of_step {M : Machine Γ Λ} {S : Type*}
{start : S} {encode : S → Cfg Γ Λ} {next : S → Option S}
(h_init : ReachesStar M (init []) (encode start))
(h_step : ∀ s, match next s with
| some s' => ReachesPlus M (encode s) (encode s')
| none => ∃ cfg', ReachesStar M (encode s) cfg' ∧ (step M cfg').isNone) :
IsValidAcceleration M start encode next where
init_reaches := h_init
step_some s s' h := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh_init:init [] [M]⊢* encode starth_step:∀ (s : S),
match next s with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = trues:Ss':Sh:next s = some s'⊢ encode s [M]⊢⁺ encode s'
have hs := h_step s Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh_init:init [] [M]⊢* encode starth_step:∀ (s : S),
match next s with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = trues:Ss':Sh:next s = some s'hs:match next s with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = true⊢ encode s [M]⊢⁺ encode s'
rw [h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh_init:init [] [M]⊢* encode starth_step:∀ (s : S),
match next s with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = trues:Ss':Sh:next s = some s'hs:match some s' with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = true⊢ encode s [M]⊢⁺ encode s'] at hs Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh_init:init [] [M]⊢* encode starth_step:∀ (s : S),
match next s with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = trues:Ss':Sh:next s = some s'hs:match some s' with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = true⊢ encode s [M]⊢⁺ encode s'
exact hs All goals completed! 🐙
step_none s h := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh_init:init [] [M]⊢* encode starth_step:∀ (s : S),
match next s with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = trues:Sh:next s = none⊢ ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = true
have hs := h_step s Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh_init:init [] [M]⊢* encode starth_step:∀ (s : S),
match next s with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = trues:Sh:next s = nonehs:match next s with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = true⊢ ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = true
rw [h Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh_init:init [] [M]⊢* encode starth_step:∀ (s : S),
match next s with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = trues:Sh:next s = nonehs:match none with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = true⊢ ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = true] at hs Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sh_init:init [] [M]⊢* encode starth_step:∀ (s : S),
match next s with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = trues:Sh:next s = nonehs:match none with
| some s' => encode s [M]⊢⁺ encode s'
| none => ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = true⊢ ∃ cfg', (encode s [M]⊢* cfg') ∧ (step M cfg').isNone = true
exact hs All goals completed! 🐙
Derive IsClosedPatternSet M ps from a valid acceleration IsValidAcceleration M start encode next whose image encode characterizes ps and whose halting states step in ReachesPlus to a
halting configuration.
theorem IsValidAcceleration.isClosedPatternSet {M : Machine Γ Λ} {S : Type*}
{start : S} {encode : S → Cfg Γ Λ} {next : S → Option S}
{ps : TapePatternSet Γ Λ}
(h : IsValidAcceleration M start encode next)
(h_in : ∀ s, IsInPatternSet ps (encode s))
(h_of_in : ∀ cfg, IsInPatternSet ps cfg → ∃ s, cfg = encode s)
(h_halt_plus : ∀ s, next s = none →
∃ cfg', ReachesPlus M (encode s) cfg' ∧ (step M cfg').isNone) :
IsClosedPatternSet M ps := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:TapePatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = true⊢ IsClosedPatternSet M ps
refine ⟨⟨encode start, h.init_reaches, h_in start⟩, fun cfg hcfg => ?_⟩ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:TapePatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = truecfg:Cfg Γ Λhcfg:IsInPatternSet ps cfg⊢ ∃ cfg', (cfg [M]⊢⁺ cfg') ∧ (IsInPatternSet ps cfg' ∨ (step M cfg').isNone = true)
obtain ⟨s, rfl⟩ := h_of_in cfg hcfg Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:TapePatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trues:Shcfg:IsInPatternSet ps (encode s)⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInPatternSet ps cfg' ∨ (step M cfg').isNone = true)
rcases hnext : next s with _ | s' none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:TapePatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trues:Shcfg:IsInPatternSet ps (encode s)hnext:next s = none⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInPatternSet ps cfg' ∨ (step M cfg').isNone = true)some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:TapePatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trues:Shcfg:IsInPatternSet ps (encode s)s':Shnext:next s = some s'⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInPatternSet ps cfg' ∨ (step M cfg').isNone = true)
· none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:TapePatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trues:Shcfg:IsInPatternSet ps (encode s)hnext:next s = none⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInPatternSet ps cfg' ∨ (step M cfg').isNone = true) obtain ⟨cfg', hplus, hnone⟩ := h_halt_plus s hnext none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:TapePatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trues:Shcfg:IsInPatternSet ps (encode s)hnext:next s = nonecfg':Cfg Γ Λhplus:encode s [M]⊢⁺ cfg'hnone:(step M cfg').isNone = true⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInPatternSet ps cfg' ∨ (step M cfg').isNone = true)
exact ⟨cfg', hplus, Or.inr hnone⟩ All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:TapePatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trues:Shcfg:IsInPatternSet ps (encode s)s':Shnext:next s = some s'⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInPatternSet ps cfg' ∨ (step M cfg').isNone = true) exact ⟨encode s', h.step_some s s' hnext, Or.inl (h_in s')⟩ All goals completed! 🐙
Derive IsClosedStackPatternSet M ps from a valid acceleration IsValidAcceleration M start encode next whose image encode characterizes a well-formed ps and whose halting states step in
ReachesPlus to a halting configuration.
theorem IsValidAcceleration.isClosedStackPatternSet [DecidableEq Γ] {M : Machine Γ Λ} {S : Type*}
{start : S} {encode : S → Cfg Γ Λ} {next : S → Option S}
{ps : StackPatternSet Γ Λ}
(h : IsValidAcceleration M start encode next)
(h_in : ∀ s, IsInStackPatternSet ps (encode s))
(h_of_in : ∀ cfg, IsInStackPatternSet ps cfg → ∃ s, cfg = encode s)
(h_halt_plus : ∀ s, next s = none →
∃ cfg', ReachesPlus M (encode s) cfg' ∧ (step M cfg').isNone)
(h_wf : IsWellFormedStackPatternSet ps := by rfl) :
IsClosedStackPatternSet M ps := by Γ:Type u_1Λ:Type u_2inst✝²:Inhabited Γinst✝¹:Inhabited Λinst✝:DecidableEq ΓM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:StackPatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInStackPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInStackPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trueh_wf:IsWellFormedStackPatternSet ps⊢ IsClosedStackPatternSet M ps
refine ⟨h_wf, ⟨encode start, h.init_reaches, h_in start⟩, fun cfg hcfg => ?_⟩ Γ:Type u_1Λ:Type u_2inst✝²:Inhabited Γinst✝¹:Inhabited Λinst✝:DecidableEq ΓM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:StackPatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInStackPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInStackPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trueh_wf:IsWellFormedStackPatternSet pscfg:Cfg Γ Λhcfg:IsInStackPatternSet ps cfg⊢ ∃ cfg', (cfg [M]⊢⁺ cfg') ∧ (IsInStackPatternSet ps cfg' ∨ (step M cfg').isNone = true)
obtain ⟨s, rfl⟩ := h_of_in cfg hcfg Γ:Type u_1Λ:Type u_2inst✝²:Inhabited Γinst✝¹:Inhabited Λinst✝:DecidableEq ΓM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:StackPatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInStackPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInStackPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trueh_wf:IsWellFormedStackPatternSet pss:Shcfg:IsInStackPatternSet ps (encode s)⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInStackPatternSet ps cfg' ∨ (step M cfg').isNone = true)
rcases hnext : next s with _ | s' none Γ:Type u_1Λ:Type u_2inst✝²:Inhabited Γinst✝¹:Inhabited Λinst✝:DecidableEq ΓM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:StackPatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInStackPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInStackPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trueh_wf:IsWellFormedStackPatternSet pss:Shcfg:IsInStackPatternSet ps (encode s)hnext:next s = none⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInStackPatternSet ps cfg' ∨ (step M cfg').isNone = true)some Γ:Type u_1Λ:Type u_2inst✝²:Inhabited Γinst✝¹:Inhabited Λinst✝:DecidableEq ΓM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:StackPatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInStackPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInStackPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trueh_wf:IsWellFormedStackPatternSet pss:Shcfg:IsInStackPatternSet ps (encode s)s':Shnext:next s = some s'⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInStackPatternSet ps cfg' ∨ (step M cfg').isNone = true)
· none Γ:Type u_1Λ:Type u_2inst✝²:Inhabited Γinst✝¹:Inhabited Λinst✝:DecidableEq ΓM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:StackPatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInStackPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInStackPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trueh_wf:IsWellFormedStackPatternSet pss:Shcfg:IsInStackPatternSet ps (encode s)hnext:next s = none⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInStackPatternSet ps cfg' ∨ (step M cfg').isNone = true) obtain ⟨cfg', hplus, hnone⟩ := h_halt_plus s hnext none Γ:Type u_1Λ:Type u_2inst✝²:Inhabited Γinst✝¹:Inhabited Λinst✝:DecidableEq ΓM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:StackPatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInStackPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInStackPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trueh_wf:IsWellFormedStackPatternSet pss:Shcfg:IsInStackPatternSet ps (encode s)hnext:next s = nonecfg':Cfg Γ Λhplus:encode s [M]⊢⁺ cfg'hnone:(step M cfg').isNone = true⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInStackPatternSet ps cfg' ∨ (step M cfg').isNone = true)
exact ⟨cfg', hplus, Or.inr hnone⟩ All goals completed! 🐙
· some Γ:Type u_1Λ:Type u_2inst✝²:Inhabited Γinst✝¹:Inhabited Λinst✝:DecidableEq ΓM:Machine Γ ΛS:Type u_3start:Sencode:S → Cfg Γ Λnext:S → Option Sps:StackPatternSet Γ Λh:IsValidAcceleration M start encode nexth_in:∀ (s : S), IsInStackPatternSet ps (encode s)h_of_in:∀ (cfg : Cfg Γ Λ), IsInStackPatternSet ps cfg → ∃ s, cfg = encode sh_halt_plus:∀ (s : S), next s = none → ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (step M cfg').isNone = trueh_wf:IsWellFormedStackPatternSet pss:Shcfg:IsInStackPatternSet ps (encode s)s':Shnext:next s = some s'⊢ ∃ cfg', (encode s [M]⊢⁺ cfg') ∧ (IsInStackPatternSet ps cfg' ∨ (step M cfg').isNone = true) exact ⟨encode s', h.step_some s s' hnext, Or.inl (h_in s')⟩ All goals completed! 🐙omit [Inhabited Γ] in
private theorem evalStackSeg_two_word_of_bool (a₀ a₁ : Γ) (w : List Bool) :
(((w.map fun b => if b then 1 else 0).map fun d =>
([[a₀], [a₁]] : List (List Γ)).getD d []).flatten) =
w.map (fun b => if b then a₁ else a₀) := by Γ:Type u_1a₀:Γa₁:Γw:List Bool⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) w)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) w
induction w with
| nil => nil Γ:Type u_1a₀:Γa₁:Γ⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) [])).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) [] rfl All goals completed! 🐙
| cons b rest ih => cons Γ:Type u_1a₀:Γa₁:Γb:Boolrest:List Boolih:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) rest⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) (b :: rest))).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) (b :: rest)
cases b cons.false Γ:Type u_1a₀:Γa₁:Γrest:List Boolih:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) rest⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) (false :: rest))).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) (false :: rest)cons.true Γ:Type u_1a₀:Γa₁:Γrest:List Boolih:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) rest⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) (true :: rest))).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) (true :: rest) <;> cons.false Γ:Type u_1a₀:Γa₁:Γrest:List Boolih:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) rest⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) (false :: rest))).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) (false :: rest)cons.true Γ:Type u_1a₀:Γa₁:Γrest:List Boolih:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) rest⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) (true :: rest))).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) (true :: rest) simpa using ih All goals completed! 🐙omit [Inhabited Γ] in
private theorem exists_bool_of_evalStackSeg_two_word (a₀ a₁ : Γ) (ds : List ℕ) :
∃ w : List Bool,
((ds.map fun d => ([[a₀], [a₁]] : List (List Γ)).getD d []).flatten) =
w.map (fun b => if b then a₁ else a₀) := by Γ:Type u_1a₀:Γa₁:Γds:List ℕ⊢ ∃ w, (List.map (fun d ↦ [[a₀], [a₁]].getD d []) ds).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w
induction ds with
| nil => nil Γ:Type u_1a₀:Γa₁:Γ⊢ ∃ w, (List.map (fun d ↦ [[a₀], [a₁]].getD d []) []).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w exact ⟨[], rfl⟩ All goals completed! 🐙
| cons d rest ih => cons Γ:Type u_1a₀:Γa₁:Γd:ℕrest:List ℕih:∃ w, (List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ ∃ w, (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (d :: rest)).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w
obtain ⟨w, hw⟩ := ih cons Γ:Type u_1a₀:Γa₁:Γd:ℕrest:List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ ∃ w, (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (d :: rest)).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w
rcases d with _ | _ | d cons.zero Γ:Type u_1a₀:Γa₁:Γrest:List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ ∃ w, (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (0 :: rest)).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) wcons.succ.zero Γ:Type u_1a₀:Γa₁:Γrest:List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ ∃ w,
(List.map (fun d ↦ [[a₀], [a₁]].getD d []) ((0 + 1) :: rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) wcons.succ.succ Γ:Type u_1a₀:Γa₁:Γrest:List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) wd:ℕ⊢ ∃ w,
(List.map (fun d ↦ [[a₀], [a₁]].getD d []) ((d + 1 + 1) :: rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) w
· cons.zero Γ:Type u_1a₀:Γa₁:Γrest:List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ ∃ w, (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (0 :: rest)).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w refine ⟨false :: w, ?_⟩ cons.zero Γ:Type u_1a₀:Γa₁:Γrest:List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (0 :: rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) (false :: w)
simpa using hw All goals completed! 🐙
· cons.succ.zero Γ:Type u_1a₀:Γa₁:Γrest:List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ ∃ w,
(List.map (fun d ↦ [[a₀], [a₁]].getD d []) ((0 + 1) :: rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) w refine ⟨true :: w, ?_⟩ cons.succ.zero Γ:Type u_1a₀:Γa₁:Γrest:List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) ((0 + 1) :: rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) (true :: w)
simpa using hw All goals completed! 🐙
· cons.succ.succ Γ:Type u_1a₀:Γa₁:Γrest:List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) wd:ℕ⊢ ∃ w,
(List.map (fun d ↦ [[a₀], [a₁]].getD d []) ((d + 1 + 1) :: rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) w refine ⟨w, ?_⟩ cons.succ.succ Γ:Type u_1a₀:Γa₁:Γrest:List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) rest).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) wd:ℕ⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) ((d + 1 + 1) :: rest)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) w
simpa using hw All goals completed! 🐙
Characterize a single two-symbol .word [[a₀], [a₁]] 0 StackExpr as the image of a
List Bool word w mapped by fun b => if b then a₁ else a₀.
theorem exists_evalStackExpr_single_word_iff (a₀ a₁ : Γ) (s : ListBlank Γ) :
(∃ (vars : ℕ → ℕ) (stks : ℕ → List ℕ),
s = evalStackExpr [.word [[a₀], [a₁]] 0] vars stks) ↔
∃ w : List Bool,
s = ListBlank.append (w.map (fun b => if b then a₁ else a₀)) default := by Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γs:ListBlank Γ⊢ (∃ vars stks, s = evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] vars stks) ↔
∃ w, s = List.map (fun b ↦ if b = true then a₁ else a₀) w +> default
constructor mp Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γs:ListBlank Γ⊢ (∃ vars stks, s = evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] vars stks) →
∃ w, s = List.map (fun b ↦ if b = true then a₁ else a₀) w +> defaultmpr Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γs:ListBlank Γ⊢ (∃ w, s = List.map (fun b ↦ if b = true then a₁ else a₀) w +> default) →
∃ vars stks, s = evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] vars stks
· mp Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γs:ListBlank Γ⊢ (∃ vars stks, s = evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] vars stks) →
∃ w, s = List.map (fun b ↦ if b = true then a₁ else a₀) w +> default rintro ⟨vars, stks, rfl⟩ mp Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γvars:ℕ → ℕstks:ℕ → List ℕ⊢ ∃ w,
evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] vars stks = List.map (fun b ↦ if b = true then a₁ else a₀) w +> default
obtain ⟨w, hw⟩ := exists_bool_of_evalStackSeg_two_word a₀ a₁ (stks 0) mp Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γvars:ℕ → ℕstks:ℕ → List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (stks 0)).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ ∃ w,
evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] vars stks = List.map (fun b ↦ if b = true then a₁ else a₀) w +> default
refine ⟨w, ?_⟩ mp Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γvars:ℕ → ℕstks:ℕ → List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (stks 0)).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] vars stks = List.map (fun b ↦ if b = true then a₁ else a₀) w +> default
dsimp only [evalStackExpr, evalStackSeg] mp Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γvars:ℕ → ℕstks:ℕ → List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (stks 0)).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ (List.map (fun d ↦ [[a₀], [a₁]].getD d []) (stks 0)).flatten +> default =
List.map (fun b ↦ if b = true then a₁ else a₀) w +> default
rw [hw mp Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γvars:ℕ → ℕstks:ℕ → List ℕw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (stks 0)).flatten = List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ List.map (fun b ↦ if b = true then a₁ else a₀) w +> default =
List.map (fun b ↦ if b = true then a₁ else a₀) w +> default] All goals completed! 🐙
· mpr Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γs:ListBlank Γ⊢ (∃ w, s = List.map (fun b ↦ if b = true then a₁ else a₀) w +> default) →
∃ vars stks, s = evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] vars stks rintro ⟨w, rfl⟩ mpr Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γw:List Bool⊢ ∃ vars stks,
List.map (fun b ↦ if b = true then a₁ else a₀) w +> default = evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] vars stks
refine ⟨fun _ => 0, fun _ => w.map (fun b => if b then 1 else 0), ?_⟩ mpr Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γw:List Bool⊢ List.map (fun b ↦ if b = true then a₁ else a₀) w +> default =
evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] (fun x ↦ 0) fun x ↦ List.map (fun b ↦ if b = true then 1 else 0) w
have hw := evalStackSeg_two_word_of_bool a₀ a₁ w mpr Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) w)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ List.map (fun b ↦ if b = true then a₁ else a₀) w +> default =
evalStackExpr [StackSeg.word [[a₀], [a₁]] 0] (fun x ↦ 0) fun x ↦ List.map (fun b ↦ if b = true then 1 else 0) w
dsimp only [evalStackExpr, evalStackSeg] mpr Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) w)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ List.map (fun b ↦ if b = true then a₁ else a₀) w +> default =
(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) w)).flatten +> default
rw [hw mpr Γ:Type u_1inst✝:Inhabited Γa₀:Γa₁:Γw:List Boolhw:(List.map (fun d ↦ [[a₀], [a₁]].getD d []) (List.map (fun b ↦ if b = true then 1 else 0) w)).flatten =
List.map (fun b ↦ if b = true then a₁ else a₀) w⊢ List.map (fun b ↦ if b = true then a₁ else a₀) w +> default =
List.map (fun b ↦ if b = true then a₁ else a₀) w +> default] All goals completed! 🐙
Higher-Level Acceleration Reduction (CollatzReachesStar, CollatzStepsTo)
Any two valid Collatz-like accelerations of the same machine M have equivalent halting
problems.
theorem IsValidAcceleration.collatzHalts_iff {M : Machine Γ Λ} {S₁ S₂ : Type*}
{start₁ : S₁} {encode₁ : S₁ → Cfg Γ Λ} {next₁ : S₁ → Option S₁}
{start₂ : S₂} {encode₂ : S₂ → Cfg Γ Λ} {next₂ : S₂ → Option S₂}
(h₁ : IsValidAcceleration M start₁ encode₁ next₁)
(h₂ : IsValidAcceleration M start₂ encode₂ next₂) :
CollatzHalts next₁ start₁ ↔ CollatzHalts next₂ start₂ :=
h₁.isHalt_iff.symm.trans h₂.isHalt_iff
next reaches s₂ from s₁ in n steps.
def CollatzReachesIn {S : Type*} (next : S → Option S) (n : ℕ) (s₁ s₂ : S) : Prop :=
(Option.bind · next)^[n] (some s₁) = some s₂
next reaches s₂ from s₁ in zero or more steps.
def CollatzReachesStar {S : Type*} (next : S → Option S) (s₁ s₂ : S) : Prop :=
∃ n : ℕ, CollatzReachesIn next n s₁ s₂
next reaches s₂ from s₁ in one or more steps.
def CollatzReachesPlus {S : Type*} (next : S → Option S) (s₁ s₂ : S) : Prop :=
∃ n : ℕ, n > 0 ∧ CollatzReachesIn next n s₁ s₂
next from s either reaches s' in one or more steps (some s') or halts (none).
def CollatzStepsTo {S : Type*} (next : S → Option S) (s : S) : Option S → Prop
| some s' => CollatzReachesPlus next s s'
| none => CollatzHalts next s@[simp]
private theorem iterate_bind_none {S : Type*} (next : S → Option S) (n : ℕ) :
(Option.bind · next)^[n] none = none := by S:Type u_3next:S → Option Sn:ℕ⊢ (fun x ↦ x.bind next)^[n] none = none
induction n with
| zero => zero S:Type u_3next:S → Option S⊢ (fun x ↦ x.bind next)^[0] none = none rfl All goals completed! 🐙
| succ n ih => succ S:Type u_3next:S → Option Sn:ℕih:(fun x ↦ x.bind next)^[n] none = none⊢ (fun x ↦ x.bind next)^[n + 1] none = none
rw [Function.iterate_succ_apply, succ S:Type u_3next:S → Option Sn:ℕih:(fun x ↦ x.bind next)^[n] none = none⊢ (fun x ↦ x.bind next)^[n] (none.bind next) = none Option.bind_none, succ S:Type u_3next:S → Option Sn:ℕih:(fun x ↦ x.bind next)^[n] none = none⊢ (fun x ↦ x.bind next)^[n] none = none ih succ S:Type u_3next:S → Option Sn:ℕih:(fun x ↦ x.bind next)^[n] none = none⊢ none = none] All goals completed! 🐙variable {S : Type*}private theorem CollatzReachesIn.head {next : S → Option S} {n : ℕ} {s₁ s₂ s₃ : S}
(h₁ : next s₁ = some s₂) (h₂ : CollatzReachesIn next n s₂ s₃) :
CollatzReachesIn next (n + 1) s₁ s₃ := by S:Type u_3next:S → Option Sn:ℕs₁:Ss₂:Ss₃:Sh₁:next s₁ = some s₂h₂:CollatzReachesIn next n s₂ s₃⊢ CollatzReachesIn next (n + 1) s₁ s₃
unfold CollatzReachesIn at * S:Type u_3next:S → Option Sn:ℕs₁:Ss₂:Ss₃:Sh₁:next s₁ = some s₂h₂:(fun x ↦ x.bind next)^[n] (some s₂) = some s₃⊢ (fun x ↦ x.bind next)^[n + 1] (some s₁) = some s₃
rw [Function.iterate_succ_apply S:Type u_3next:S → Option Sn:ℕs₁:Ss₂:Ss₃:Sh₁:next s₁ = some s₂h₂:(fun x ↦ x.bind next)^[n] (some s₂) = some s₃⊢ (fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₃] S:Type u_3next:S → Option Sn:ℕs₁:Ss₂:Ss₃:Sh₁:next s₁ = some s₂h₂:(fun x ↦ x.bind next)^[n] (some s₂) = some s₃⊢ (fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₃
simpa [h₁] using h₂ All goals completed! 🐙private theorem CollatzReachesIn.trans {next : S → Option S} {m n : ℕ} {s₁ s₂ s₃ : S}
(h₁ : CollatzReachesIn next m s₁ s₂) (h₂ : CollatzReachesIn next n s₂ s₃) :
CollatzReachesIn next (m + n) s₁ s₃ := by S:Type u_3next:S → Option Sm:ℕn:ℕs₁:Ss₂:Ss₃:Sh₁:CollatzReachesIn next m s₁ s₂h₂:CollatzReachesIn next n s₂ s₃⊢ CollatzReachesIn next (m + n) s₁ s₃
unfold CollatzReachesIn at * S:Type u_3next:S → Option Sm:ℕn:ℕs₁:Ss₂:Ss₃:Sh₁:(fun x ↦ x.bind next)^[m] (some s₁) = some s₂h₂:(fun x ↦ x.bind next)^[n] (some s₂) = some s₃⊢ (fun x ↦ x.bind next)^[m + n] (some s₁) = some s₃
rw [Nat.add_comm, S:Type u_3next:S → Option Sm:ℕn:ℕs₁:Ss₂:Ss₃:Sh₁:(fun x ↦ x.bind next)^[m] (some s₁) = some s₂h₂:(fun x ↦ x.bind next)^[n] (some s₂) = some s₃⊢ (fun x ↦ x.bind next)^[n + m] (some s₁) = some s₃ Function.iterate_add_apply, S:Type u_3next:S → Option Sm:ℕn:ℕs₁:Ss₂:Ss₃:Sh₁:(fun x ↦ x.bind next)^[m] (some s₁) = some s₂h₂:(fun x ↦ x.bind next)^[n] (some s₂) = some s₃⊢ (fun x ↦ x.bind next)^[n] ((fun x ↦ x.bind next)^[m] (some s₁)) = some s₃ h₁, S:Type u_3next:S → Option Sm:ℕn:ℕs₁:Ss₂:Ss₃:Sh₁:(fun x ↦ x.bind next)^[m] (some s₁) = some s₂h₂:(fun x ↦ x.bind next)^[n] (some s₂) = some s₃⊢ (fun x ↦ x.bind next)^[n] (some s₂) = some s₃ h₂ S:Type u_3next:S → Option Sm:ℕn:ℕs₁:Ss₂:Ss₃:Sh₁:(fun x ↦ x.bind next)^[m] (some s₁) = some s₂h₂:(fun x ↦ x.bind next)^[n] (some s₂) = some s₃⊢ some s₃ = some s₃] All goals completed! 🐙theorem CollatzReachesStar.refl (next : S → Option S) (s : S) :
CollatzReachesStar next s s :=
⟨0, rfl⟩theorem CollatzReachesStar.head {next : S → Option S} {s₁ s₂ s₃ : S}
(h₁ : next s₁ = some s₂) (h₂ : CollatzReachesStar next s₂ s₃) :
CollatzReachesStar next s₁ s₃ :=
let ⟨n, hn⟩ := h₂
⟨n + 1, CollatzReachesIn.head h₁ hn⟩theorem CollatzReachesStar.single {next : S → Option S} {s₁ s₂ : S}
(h : next s₁ = some s₂) :
CollatzReachesStar next s₁ s₂ :=
CollatzReachesStar.head h (CollatzReachesStar.refl next s₂)theorem CollatzReachesPlus.single {next : S → Option S} {s₁ s₂ : S}
(h : next s₁ = some s₂) :
CollatzReachesPlus next s₁ s₂ :=
⟨1, Nat.succ_pos 0, CollatzReachesIn.head h rfl⟩theorem CollatzReachesPlus.to_star {next : S → Option S} {s₁ s₂ : S}
(h : CollatzReachesPlus next s₁ s₂) :
CollatzReachesStar next s₁ s₂ :=
let ⟨n, _, hn⟩ := h
⟨n, hn⟩theorem CollatzReachesPlus.head {next : S → Option S} {s₁ s₂ s₃ : S}
(h₁ : next s₁ = some s₂) (h₂ : CollatzReachesStar next s₂ s₃) :
CollatzReachesPlus next s₁ s₃ :=
let ⟨n, hn⟩ := h₂
⟨n + 1, Nat.succ_pos n, CollatzReachesIn.head h₁ hn⟩private theorem CollatzReachesStar.trans_plus {next : S → Option S} {s₁ s₂ s₃ : S}
(h₁ : CollatzReachesStar next s₁ s₂) (h₂ : CollatzReachesPlus next s₂ s₃) :
CollatzReachesPlus next s₁ s₃ :=
let ⟨m, hm⟩ := h₁
let ⟨n, hn_pos, hn⟩ := h₂
⟨m + n, Nat.add_pos_right m hn_pos, hm.trans hn⟩private theorem CollatzHalts.of_reachesStar {next : S → Option S} {s₁ s₂ : S}
(h₁ : CollatzReachesStar next s₁ s₂) (h₂ : CollatzHalts next s₂) :
CollatzHalts next s₁ := by S:Type u_3next:S → Option Ss₁:Ss₂:Sh₁:CollatzReachesStar next s₁ s₂h₂:CollatzHalts next s₂⊢ CollatzHalts next s₁
obtain ⟨m, hm⟩ := h₁ S:Type u_3next:S → Option Ss₁:Ss₂:Sh₂:CollatzHalts next s₂m:ℕhm:CollatzReachesIn next m s₁ s₂⊢ CollatzHalts next s₁
obtain ⟨n, hn⟩ := h₂ S:Type u_3next:S → Option Ss₁:Ss₂:Sm:ℕhm:CollatzReachesIn next m s₁ s₂n:ℕhn:((fun x ↦ x.bind next)^[n] (some s₂)).isNone = true⊢ CollatzHalts next s₁
refine ⟨m + n, ?_⟩ S:Type u_3next:S → Option Ss₁:Ss₂:Sm:ℕhm:CollatzReachesIn next m s₁ s₂n:ℕhn:((fun x ↦ x.bind next)^[n] (some s₂)).isNone = true⊢ ((fun x ↦ x.bind next)^[m + n] (some s₁)).isNone = true
unfold CollatzReachesIn at hm S:Type u_3next:S → Option Ss₁:Ss₂:Sm:ℕhm:(fun x ↦ x.bind next)^[m] (some s₁) = some s₂n:ℕhn:((fun x ↦ x.bind next)^[n] (some s₂)).isNone = true⊢ ((fun x ↦ x.bind next)^[m + n] (some s₁)).isNone = true
rw [Nat.add_comm, S:Type u_3next:S → Option Ss₁:Ss₂:Sm:ℕhm:(fun x ↦ x.bind next)^[m] (some s₁) = some s₂n:ℕhn:((fun x ↦ x.bind next)^[n] (some s₂)).isNone = true⊢ ((fun x ↦ x.bind next)^[n + m] (some s₁)).isNone = true Function.iterate_add_apply, S:Type u_3next:S → Option Ss₁:Ss₂:Sm:ℕhm:(fun x ↦ x.bind next)^[m] (some s₁) = some s₂n:ℕhn:((fun x ↦ x.bind next)^[n] (some s₂)).isNone = true⊢ ((fun x ↦ x.bind next)^[n] ((fun x ↦ x.bind next)^[m] (some s₁))).isNone = true hm, S:Type u_3next:S → Option Ss₁:Ss₂:Sm:ℕhm:(fun x ↦ x.bind next)^[m] (some s₁) = some s₂n:ℕhn:((fun x ↦ x.bind next)^[n] (some s₂)).isNone = true⊢ ((fun x ↦ x.bind next)^[n] (some s₂)).isNone = true hn S:Type u_3next:S → Option Ss₁:Ss₂:Sm:ℕhm:(fun x ↦ x.bind next)^[m] (some s₁) = some s₂n:ℕhn:((fun x ↦ x.bind next)^[n] (some s₂)).isNone = true⊢ true = true] All goals completed! 🐙theorem CollatzStepsTo.of_eq {next : S → Option S} {s : S} {res : Option S}
(h : next s = res) :
CollatzStepsTo next s res := by S:Type u_3next:S → Option Ss:Sres:Option Sh:next s = res⊢ CollatzStepsTo next s res
rcases res with _ | s' none S:Type u_3next:S → Option Ss:Sh:next s = none⊢ CollatzStepsTo next s nonesome S:Type u_3next:S → Option Ss:Ss':Sh:next s = some s'⊢ CollatzStepsTo next s (some s')
· none S:Type u_3next:S → Option Ss:Sh:next s = none⊢ CollatzStepsTo next s none exact CollatzHalts.of_next_eq_none h All goals completed! 🐙
· some S:Type u_3next:S → Option Ss:Ss':Sh:next s = some s'⊢ CollatzStepsTo next s (some s') exact CollatzReachesPlus.single h All goals completed! 🐙theorem CollatzStepsTo.head {next : S → Option S} {s₁ s₂ : S} {res : Option S}
(h₁ : next s₁ = some s₂) (h₂ : CollatzStepsTo next s₂ res) :
CollatzStepsTo next s₁ res := by S:Type u_3next:S → Option Ss₁:Ss₂:Sres:Option Sh₁:next s₁ = some s₂h₂:CollatzStepsTo next s₂ res⊢ CollatzStepsTo next s₁ res
rcases res with _ | s' none S:Type u_3next:S → Option Ss₁:Ss₂:Sh₁:next s₁ = some s₂h₂:CollatzStepsTo next s₂ none⊢ CollatzStepsTo next s₁ nonesome S:Type u_3next:S → Option Ss₁:Ss₂:Sh₁:next s₁ = some s₂s':Sh₂:CollatzStepsTo next s₂ (some s')⊢ CollatzStepsTo next s₁ (some s')
· none S:Type u_3next:S → Option Ss₁:Ss₂:Sh₁:next s₁ = some s₂h₂:CollatzStepsTo next s₂ none⊢ CollatzStepsTo next s₁ none exact CollatzHalts.of_next_eq_some h₁ h₂ All goals completed! 🐙
· some S:Type u_3next:S → Option Ss₁:Ss₂:Sh₁:next s₁ = some s₂s':Sh₂:CollatzStepsTo next s₂ (some s')⊢ CollatzStepsTo next s₁ (some s') exact CollatzReachesPlus.head h₁ h₂.to_star All goals completed! 🐙theorem CollatzStepsTo.of_reachesStar {next : S → Option S} {s₁ s₂ : S} {res : Option S}
(h₁ : CollatzReachesStar next s₁ s₂) (h₂ : CollatzStepsTo next s₂ res) :
CollatzStepsTo next s₁ res := by S:Type u_3next:S → Option Ss₁:Ss₂:Sres:Option Sh₁:CollatzReachesStar next s₁ s₂h₂:CollatzStepsTo next s₂ res⊢ CollatzStepsTo next s₁ res
rcases res with _ | s' none S:Type u_3next:S → Option Ss₁:Ss₂:Sh₁:CollatzReachesStar next s₁ s₂h₂:CollatzStepsTo next s₂ none⊢ CollatzStepsTo next s₁ nonesome S:Type u_3next:S → Option Ss₁:Ss₂:Sh₁:CollatzReachesStar next s₁ s₂s':Sh₂:CollatzStepsTo next s₂ (some s')⊢ CollatzStepsTo next s₁ (some s')
· none S:Type u_3next:S → Option Ss₁:Ss₂:Sh₁:CollatzReachesStar next s₁ s₂h₂:CollatzStepsTo next s₂ none⊢ CollatzStepsTo next s₁ none exact CollatzHalts.of_reachesStar h₁ h₂ All goals completed! 🐙
· some S:Type u_3next:S → Option Ss₁:Ss₂:Sh₁:CollatzReachesStar next s₁ s₂s':Sh₂:CollatzStepsTo next s₂ (some s')⊢ CollatzStepsTo next s₁ (some s') exact h₁.trans_plus h₂ All goals completed! 🐙private theorem IsValidAcceleration.reachesStar_of_collatzReachesIn {M : Machine Γ Λ} {S : Type*}
{start : S} {encode : S → Cfg Γ Λ} {next : S → Option S}
(h : IsValidAcceleration M start encode next) {n : ℕ} {s₁ s₂ : S}
(hs : CollatzReachesIn next n s₁ s₂) :
ReachesStar M (encode s₁) (encode s₂) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nextn:ℕs₁:Ss₂:Shs:CollatzReachesIn next n s₁ s₂⊢ encode s₁ [M]⊢* encode s₂
induction n generalizing s₁ with
| zero => zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Ss₁:Shs:CollatzReachesIn next 0 s₁ s₂⊢ encode s₁ [M]⊢* encode s₂
unfold CollatzReachesIn at hs zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Ss₁:Shs:(fun x ↦ x.bind next)^[0] (some s₁) = some s₂⊢ encode s₁ [M]⊢* encode s₂
simp only [Function.iterate_zero_apply, Option.some.injEq] at hs zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Ss₁:Shs:s₁ = s₂⊢ encode s₁ [M]⊢* encode s₂
subst hs zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:S⊢ encode s₁ [M]⊢* encode s₁
exact ReachesStar.refl M (encode s₁) All goals completed! 🐙
| succ n ih => succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Sn:ℕih:∀ {s₁ : S}, CollatzReachesIn next n s₁ s₂ → encode s₁ [M]⊢* encode s₂s₁:Shs:CollatzReachesIn next (n + 1) s₁ s₂⊢ encode s₁ [M]⊢* encode s₂
unfold CollatzReachesIn at hs succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Sn:ℕih:∀ {s₁ : S}, CollatzReachesIn next n s₁ s₂ → encode s₁ [M]⊢* encode s₂s₁:Shs:(fun x ↦ x.bind next)^[n + 1] (some s₁) = some s₂⊢ encode s₁ [M]⊢* encode s₂
rw [Function.iterate_succ_apply succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Sn:ℕih:∀ {s₁ : S}, CollatzReachesIn next n s₁ s₂ → encode s₁ [M]⊢* encode s₂s₁:Shs:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂⊢ encode s₁ [M]⊢* encode s₂] at hs succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Sn:ℕih:∀ {s₁ : S}, CollatzReachesIn next n s₁ s₂ → encode s₁ [M]⊢* encode s₂s₁:Shs:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂⊢ encode s₁ [M]⊢* encode s₂
rcases hnext : next s₁ with _ | s' succ.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Sn:ℕih:∀ {s₁ : S}, CollatzReachesIn next n s₁ s₂ → encode s₁ [M]⊢* encode s₂s₁:Shs:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂hnext:next s₁ = none⊢ encode s₁ [M]⊢* encode s₂succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Sn:ℕih:∀ {s₁ : S}, CollatzReachesIn next n s₁ s₂ → encode s₁ [M]⊢* encode s₂s₁:Shs:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂s':Shnext:next s₁ = some s'⊢ encode s₁ [M]⊢* encode s₂
· succ.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Sn:ℕih:∀ {s₁ : S}, CollatzReachesIn next n s₁ s₂ → encode s₁ [M]⊢* encode s₂s₁:Shs:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂hnext:next s₁ = none⊢ encode s₁ [M]⊢* encode s₂ simp [hnext] at hs All goals completed! 🐙
· succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Sn:ℕih:∀ {s₁ : S}, CollatzReachesIn next n s₁ s₂ → encode s₁ [M]⊢* encode s₂s₁:Shs:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂s':Shnext:next s₁ = some s'⊢ encode s₁ [M]⊢* encode s₂ refine (h.step_some s₁ s' hnext).to_star.trans (ih ?_) succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Sn:ℕih:∀ {s₁ : S}, CollatzReachesIn next n s₁ s₂ → encode s₁ [M]⊢* encode s₂s₁:Shs:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂s':Shnext:next s₁ = some s'⊢ CollatzReachesIn next n s' s₂
change (Option.bind · next)^[n] (some s') = some s₂ succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₂:Sn:ℕih:∀ {s₁ : S}, CollatzReachesIn next n s₁ s₂ → encode s₁ [M]⊢* encode s₂s₁:Shs:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂s':Shnext:next s₁ = some s'⊢ (fun x ↦ x.bind next)^[n] (some s') = some s₂
simpa [hnext] using hs All goals completed! 🐙private theorem IsValidAcceleration.reachesStar_of_collatzReachesStar {M : Machine Γ Λ} {S : Type*}
{start : S} {encode : S → Cfg Γ Λ} {next : S → Option S}
(h : IsValidAcceleration M start encode next) {s₁ s₂ : S}
(hs : CollatzReachesStar next s₁ s₂) :
ReachesStar M (encode s₁) (encode s₂) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Shs:CollatzReachesStar next s₁ s₂⊢ encode s₁ [M]⊢* encode s₂
obtain ⟨n, hn⟩ := hs Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn:CollatzReachesIn next n s₁ s₂⊢ encode s₁ [M]⊢* encode s₂
exact h.reachesStar_of_collatzReachesIn hn All goals completed! 🐙private theorem IsValidAcceleration.reachesPlus_of_collatzReachesPlus {M : Machine Γ Λ} {S : Type*}
{start : S} {encode : S → Cfg Γ Λ} {next : S → Option S}
(h : IsValidAcceleration M start encode next) {s₁ s₂ : S}
(hs : CollatzReachesPlus next s₁ s₂) :
ReachesPlus M (encode s₁) (encode s₂) := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Shs:CollatzReachesPlus next s₁ s₂⊢ encode s₁ [M]⊢⁺ encode s₂
obtain ⟨n, hn_pos, hn⟩ := hs Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n > 0hn:CollatzReachesIn next n s₁ s₂⊢ encode s₁ [M]⊢⁺ encode s₂
rcases n with _ | n zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Shn_pos:0 > 0hn:CollatzReachesIn next 0 s₁ s₂⊢ encode s₁ [M]⊢⁺ encode s₂succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:CollatzReachesIn next (n + 1) s₁ s₂⊢ encode s₁ [M]⊢⁺ encode s₂
· zero Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Shn_pos:0 > 0hn:CollatzReachesIn next 0 s₁ s₂⊢ encode s₁ [M]⊢⁺ encode s₂ omega All goals completed! 🐙
· succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:CollatzReachesIn next (n + 1) s₁ s₂⊢ encode s₁ [M]⊢⁺ encode s₂ unfold CollatzReachesIn at hn succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:(fun x ↦ x.bind next)^[n + 1] (some s₁) = some s₂⊢ encode s₁ [M]⊢⁺ encode s₂
rw [Function.iterate_succ_apply succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂⊢ encode s₁ [M]⊢⁺ encode s₂] at hn succ Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂⊢ encode s₁ [M]⊢⁺ encode s₂
rcases hnext : next s₁ with _ | s' succ.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂hnext:next s₁ = none⊢ encode s₁ [M]⊢⁺ encode s₂succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂s':Shnext:next s₁ = some s'⊢ encode s₁ [M]⊢⁺ encode s₂
· succ.none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂hnext:next s₁ = none⊢ encode s₁ [M]⊢⁺ encode s₂ simp [hnext] at hn All goals completed! 🐙
· succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂s':Shnext:next s₁ = some s'⊢ encode s₁ [M]⊢⁺ encode s₂ refine (h.step_some s₁ s' hnext).trans_star (h.reachesStar_of_collatzReachesIn (n := n) ?_) succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂s':Shnext:next s₁ = some s'⊢ CollatzReachesIn next n s' s₂
unfold CollatzReachesIn succ.some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4start:Sencode:S → Cfg Γ Λnext:S → Option Sh:IsValidAcceleration M start encode nexts₁:Ss₂:Sn:ℕhn_pos:n + 1 > 0hn:(fun x ↦ x.bind next)^[n] ((some s₁).bind next) = some s₂s':Shnext:next s₁ = some s'⊢ (fun x ↦ x.bind next)^[n] (some s') = some s₂
simpa [hnext] using hn All goals completed! 🐙
Construct a higher-level IsValidAcceleration from a base IsValidAcceleration by showing
that start reaches embed highLevelStart under next and each step of highLevelNext is
simulated by one or more steps of next.
theorem IsValidAcceleration.of_collatz {M : Machine Γ Λ} {S H : Type*}
{start : S} {encode : S → Cfg Γ Λ} {next : S → Option S}
{highLevelStart : H} {embed : H → S} {highLevelNext : H → Option H}
(h : IsValidAcceleration M start encode next)
(h_init : CollatzReachesStar next start (embed highLevelStart))
(h_step : ∀ u, CollatzStepsTo next (embed u) ((highLevelNext u).map embed)) :
IsValidAcceleration M highLevelStart (fun u => encode (embed u)) highLevelNext where
init_reaches := h.init_reaches.trans (h.reachesStar_of_collatzReachesStar h_init)
step_some u u' hu := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4H:Type u_5start:Sencode:S → Cfg Γ Λnext:S → Option ShighLevelStart:Hembed:H → ShighLevelNext:H → Option Hh:IsValidAcceleration M start encode nexth_init:CollatzReachesStar next start (embed highLevelStart)h_step:∀ (u : H), CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))u:Hu':Hhu:highLevelNext u = some u'⊢ encode (embed u) [M]⊢⁺ encode (embed u')
have hs := h_step u Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4H:Type u_5start:Sencode:S → Cfg Γ Λnext:S → Option ShighLevelStart:Hembed:H → ShighLevelNext:H → Option Hh:IsValidAcceleration M start encode nexth_init:CollatzReachesStar next start (embed highLevelStart)h_step:∀ (u : H), CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))u:Hu':Hhu:highLevelNext u = some u'hs:CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))⊢ encode (embed u) [M]⊢⁺ encode (embed u')
rw [hu, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4H:Type u_5start:Sencode:S → Cfg Γ Λnext:S → Option ShighLevelStart:Hembed:H → ShighLevelNext:H → Option Hh:IsValidAcceleration M start encode nexth_init:CollatzReachesStar next start (embed highLevelStart)h_step:∀ (u : H), CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))u:Hu':Hhu:highLevelNext u = some u'hs:CollatzStepsTo next (embed u) (Option.map embed (some u'))⊢ encode (embed u) [M]⊢⁺ encode (embed u') Option.map_some Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4H:Type u_5start:Sencode:S → Cfg Γ Λnext:S → Option ShighLevelStart:Hembed:H → ShighLevelNext:H → Option Hh:IsValidAcceleration M start encode nexth_init:CollatzReachesStar next start (embed highLevelStart)h_step:∀ (u : H), CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))u:Hu':Hhu:highLevelNext u = some u'hs:CollatzStepsTo next (embed u) (some (embed u'))⊢ encode (embed u) [M]⊢⁺ encode (embed u')] at hs Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4H:Type u_5start:Sencode:S → Cfg Γ Λnext:S → Option ShighLevelStart:Hembed:H → ShighLevelNext:H → Option Hh:IsValidAcceleration M start encode nexth_init:CollatzReachesStar next start (embed highLevelStart)h_step:∀ (u : H), CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))u:Hu':Hhu:highLevelNext u = some u'hs:CollatzStepsTo next (embed u) (some (embed u'))⊢ encode (embed u) [M]⊢⁺ encode (embed u')
exact h.reachesPlus_of_collatzReachesPlus hs All goals completed! 🐙
step_none u hu := by Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4H:Type u_5start:Sencode:S → Cfg Γ Λnext:S → Option ShighLevelStart:Hembed:H → ShighLevelNext:H → Option Hh:IsValidAcceleration M start encode nexth_init:CollatzReachesStar next start (embed highLevelStart)h_step:∀ (u : H), CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))u:Hhu:highLevelNext u = none⊢ ∃ cfg', (encode (embed u) [M]⊢* cfg') ∧ (step M cfg').isNone = true
have hs := h_step u Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4H:Type u_5start:Sencode:S → Cfg Γ Λnext:S → Option ShighLevelStart:Hembed:H → ShighLevelNext:H → Option Hh:IsValidAcceleration M start encode nexth_init:CollatzReachesStar next start (embed highLevelStart)h_step:∀ (u : H), CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))u:Hhu:highLevelNext u = nonehs:CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))⊢ ∃ cfg', (encode (embed u) [M]⊢* cfg') ∧ (step M cfg').isNone = true
rw [hu, Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4H:Type u_5start:Sencode:S → Cfg Γ Λnext:S → Option ShighLevelStart:Hembed:H → ShighLevelNext:H → Option Hh:IsValidAcceleration M start encode nexth_init:CollatzReachesStar next start (embed highLevelStart)h_step:∀ (u : H), CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))u:Hhu:highLevelNext u = nonehs:CollatzStepsTo next (embed u) (Option.map embed none)⊢ ∃ cfg', (encode (embed u) [M]⊢* cfg') ∧ (step M cfg').isNone = true Option.map_none Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4H:Type u_5start:Sencode:S → Cfg Γ Λnext:S → Option ShighLevelStart:Hembed:H → ShighLevelNext:H → Option Hh:IsValidAcceleration M start encode nexth_init:CollatzReachesStar next start (embed highLevelStart)h_step:∀ (u : H), CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))u:Hhu:highLevelNext u = nonehs:CollatzStepsTo next (embed u) none⊢ ∃ cfg', (encode (embed u) [M]⊢* cfg') ∧ (step M cfg').isNone = true] at hs Γ:Type u_1Λ:Type u_2inst✝¹:Inhabited Γinst✝:Inhabited ΛM:Machine Γ ΛS:Type u_4H:Type u_5start:Sencode:S → Cfg Γ Λnext:S → Option ShighLevelStart:Hembed:H → ShighLevelNext:H → Option Hh:IsValidAcceleration M start encode nexth_init:CollatzReachesStar next start (embed highLevelStart)h_step:∀ (u : H), CollatzStepsTo next (embed u) (Option.map embed (highLevelNext u))u:Hhu:highLevelNext u = nonehs:CollatzStepsTo next (embed u) none⊢ ∃ cfg', (encode (embed u) [M]⊢* cfg') ∧ (step M cfg').isNone = true
exact h.haltsFrom_of_collatzHalts hs All goals completed! 🐙end BusyBeaver