Imports
/-
Copyright (c) 2026 Google LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
-/
module
public import Cryptids.MachinesErdosTernary15
The 15-state Turing machine erdos_ternary_15 halts on the blank tape if and only if some power
2 ^ n with n > 8 has no digit 2 in base 3, i.e. if and only if Erdős's conjecture on the
ternary digits of powers of two is false.
Provenance and Attribution
Tristan Stérin and Damien Woods, Hardness of busy beaver value BB(15)
(https://arxiv.org/abs/2107.12475, 2021): the 5-state, 4-symbol machine powers_of_two_5_4 and
its 15-state, 2-symbol compilation powers_of_two_15_2, published in
https://github.com/tcosmo/bbsim (machines/powers_of_two_15_2.txt, commit 3f655ba2c73b) and
mirrored at https://docs.bbchallenge.org/other/powers_of_two_15_2.txt. The file is kept verbatim
in baselines/sources/erdos_ternary_15_sterin_woods.txt; verify.py re-derives
baselines/tables/erdos_ternary_15.txt from it and checks that they match: the start state
mul2_G_sim becomes 0, the other states are numbered in order of appearance, and the blank
symbol b becomes 0 and a becomes 1. Their correctness proof is on paper; this file gives a
Lean proof.
Machine Layout
The machine simulates a 4-symbol machine whose symbols 0, 1, 2, # are stored as cell
pairs 01, 10, 11, 00. Between two passes the tape reads, from left to right,
[counter] # d₀ d₁ … dₖ, where d₀ … dₖ are the base-3 digits of 2 ^ n, least significant
first, and the counter cell holds #, 0, 1 or 2 when 0, 1, 2 or 3 of the powers
2 ^ 0, …, 2 ^ n have no digit 2. One pass doubles the number (states 0–3, 7–9), scans
the digits from the most significant one for a 2 (states 4–6), returns to the first digit
(states 10–12) and, if no 2 was found, increments the counter (states 13, 14). Some
states are shared: rewinding also uses 8, and incrementing the counter also uses 8, 9 and
12. The machine halts at the fourth power without a digit 2; the first three are 2 ^ 0,
2 ^ 2 and 2 ^ 8.
@[expose] public sectionnamespace ConjectureMachines.ErdosTernary15open Turing (Dir)open StateTransition
15-state Erdős ternary machine (erdos_ternary_15, Stérin & Woods 2021).
abbrev erdosTernary15 : Machine 15 2 := Machines.erdosTernary15Base-3 Doubling
Doubles a base-3 digit list (least significant digit first) and adds the carry c.
def dbl : List ℕ → ℕ → List ℕ
| [], c => if c = 0 then [] else [c]
| d :: ds, c => (2 * d + c) % 3 :: dbl ds ((2 * d + c) / 3)theorem dbl_lt (ds : List ℕ) (hds : ∀ d ∈ ds, d < 3) (c : ℕ) (hc : c ≤ 1) :
∀ d ∈ dbl ds c, d < 3 := ds:List ℕhds:∀ d ∈ ds, d < 3c:ℕhc:c ≤ 1⊢ ∀ d ∈ dbl ds c, d < 3
induction ds generalizing c with
hds:∀ d ∈ [], d < 3c:ℕhc:c ≤ 1⊢ ∀ d ∈ dbl [] c, d < 3
hds:∀ d ∈ [], d < 3c:ℕhc:c ≤ 1d:ℕhd:d ∈ dbl [] c⊢ d < 3
rcases (hds:∀ d ∈ [], d < 3c:ℕhc:c ≤ 1d:ℕhd:d ∈ dbl [] c⊢ c = 0 ∨ c = 1 All goals completed! 🐙 : c = 0 ∨ c = 1) with rfl | rfl
hds:∀ d ∈ [], d < 3d:ℕhc:0 ≤ 1hd:d ∈ dbl [] 0⊢ d < 3 All goals completed! 🐙
hds:∀ d ∈ [], d < 3d:ℕhc:1 ≤ 1hd:d ∈ dbl [] 1⊢ d < 3 hds:∀ d ∈ [], d < 3d:ℕhc:1 ≤ 1hd:d = 1⊢ d < 3; All goals completed! 🐙
x:ℕxs:List ℕih:(∀ d ∈ xs, d < 3) → ∀ c ≤ 1, ∀ d ∈ dbl xs c, d < 3hds:∀ d ∈ x :: xs, d < 3c:ℕhc:c ≤ 1⊢ ∀ d ∈ dbl (x :: xs) c, d < 3
x:ℕxs:List ℕih:(∀ d ∈ xs, d < 3) → ∀ c ≤ 1, ∀ d ∈ dbl xs c, d < 3hds:∀ d ∈ x :: xs, d < 3c:ℕhc:c ≤ 1d:ℕhd:d ∈ dbl (x :: xs) c⊢ d < 3
cons x:ℕxs:List ℕih:(∀ d ∈ xs, d < 3) → ∀ c ≤ 1, ∀ d ∈ dbl xs c, d < 3hds:∀ d ∈ x :: xs, d < 3c:ℕhc:c ≤ 1d:ℕhd:d ∈ dbl (x :: xs) chx:x < 3⊢ d < 3
simp only [dbl, List.mem_cons] at hd cons x:ℕxs:List ℕih:(∀ d ∈ xs, d < 3) → ∀ c ≤ 1, ∀ d ∈ dbl xs c, d < 3hds:∀ d ∈ x :: xs, d < 3c:ℕhc:c ≤ 1d:ℕhx:x < 3hd:d = (2 * x + c) % 3 ∨ d ∈ dbl xs ((2 * x + c) / 3)⊢ d < 3
rcases hd with rfl | hd cons.inl x:ℕxs:List ℕih:(∀ d ∈ xs, d < 3) → ∀ c ≤ 1, ∀ d ∈ dbl xs c, d < 3hds:∀ d ∈ x :: xs, d < 3c:ℕhc:c ≤ 1hx:x < 3⊢ (2 * x + c) % 3 < 3cons.inr x:ℕxs:List ℕih:(∀ d ∈ xs, d < 3) → ∀ c ≤ 1, ∀ d ∈ dbl xs c, d < 3hds:∀ d ∈ x :: xs, d < 3c:ℕhc:c ≤ 1d:ℕhx:x < 3hd:d ∈ dbl xs ((2 * x + c) / 3)⊢ d < 3
· cons.inl x:ℕxs:List ℕih:(∀ d ∈ xs, d < 3) → ∀ c ≤ 1, ∀ d ∈ dbl xs c, d < 3hds:∀ d ∈ x :: xs, d < 3c:ℕhc:c ≤ 1hx:x < 3⊢ (2 * x + c) % 3 < 3 omega All goals completed! 🐙
· cons.inr x:ℕxs:List ℕih:(∀ d ∈ xs, d < 3) → ∀ c ≤ 1, ∀ d ∈ dbl xs c, d < 3hds:∀ d ∈ x :: xs, d < 3c:ℕhc:c ≤ 1d:ℕhx:x < 3hd:d ∈ dbl xs ((2 * x + c) / 3)⊢ d < 3 exact ih (fun y hy => hds y (List.mem_cons_of_mem x hy)) _ (by x:ℕxs:List ℕih:(∀ d ∈ xs, d < 3) → ∀ c ≤ 1, ∀ d ∈ dbl xs c, d < 3hds:∀ d ∈ x :: xs, d < 3c:ℕhc:c ≤ 1d:ℕhx:x < 3hd:d ∈ dbl xs ((2 * x + c) / 3)⊢ (2 * x + c) / 3 ≤ 1 omega All goals completed! 🐙) d hd
The base-3 digits of 2 ^ n, computed by repeated doubling.
def pw : ℕ → List ℕ
| 0 => [1]
| n + 1 => dbl (pw n) 0theorem pw_lt (n : ℕ) : ∀ d ∈ pw n, d < 3 := by n:ℕ⊢ ∀ d ∈ pw n, d < 3
induction n with
| zero => zero ⊢ ∀ d ∈ pw 0, d < 3 simp [pw] All goals completed! 🐙
| succ n ih => succ n:ℕih:∀ d ∈ pw n, d < 3⊢ ∀ d ∈ pw (n + 1), d < 3 exact dbl_lt (pw n) ih 0 (by n:ℕih:∀ d ∈ pw n, d < 3⊢ 0 ≤ 1 omega All goals completed! 🐙)
The number of k ≤ n such that 2 ^ k has no digit 2 in base 3.
def cnt : ℕ → ℕ
| 0 => 1
| n + 1 => cnt n + if 2 ∈ pw (n + 1) then 0 else 1theorem cnt_succ_of_mem {n : ℕ} (h : 2 ∈ pw (n + 1)) : cnt (n + 1) = cnt n := by n:ℕh:2 ∈ pw (n + 1)⊢ cnt (n + 1) = cnt n
simp [cnt, h] All goals completed! 🐙theorem cnt_succ_of_not_mem {n : ℕ} (h : 2 ∉ pw (n + 1)) : cnt (n + 1) = cnt n + 1 := by n:ℕh:2 ∉ pw (n + 1)⊢ cnt (n + 1) = cnt n + 1
simp [cnt, h] All goals completed! 🐙
2 ^ 0 = 1, 2 ^ 2 = 11₃ and 2 ^ 8 = 100111₃ are the only powers 2 ^ k with k ≤ 8
without a digit 2.
theorem cnt_eight : cnt 8 = 3 := by ⊢ cnt 8 = 3 decide All goals completed! 🐙Tape Encoding
Left cell of the pair encoding the digit d (0 ↦ 01, 1 ↦ 10, 2 ↦ 11).
def hi : ℕ → Fin 2
| 0 => 0
| _ => 1
Right cell of the pair encoding the digit d.
def lo : ℕ → Fin 2
| 1 => 0
| _ => 1@[simp] theorem hi_zero : hi 0 = 0 := rfl@[simp] theorem hi_one : hi 1 = 1 := rfl@[simp] theorem hi_two : hi 2 = 1 := rfl@[simp] theorem lo_zero : lo 0 = 1 := rfl@[simp] theorem lo_one : lo 1 = 0 := rfl@[simp] theorem lo_two : lo 2 = 1 := rflThe cells of a digit list, read from left to right.
def encR : List ℕ → List (Fin 2)
| [] => []
| d :: ds => hi d :: lo d :: encR dsThe cells of a digit list, read from right to left.
def encL : List ℕ → List (Fin 2)
| [] => []
| d :: ds => encL ds ++ [lo d, hi d]
Left cell of the counter pair (0 ↦ 00, 1 ↦ 01, 2 ↦ 10, 3 ↦ 11).
def chi : ℕ → Fin 2
| 0 => 0
| 1 => 0
| _ => 1Right cell of the counter pair.
def clo : ℕ → Fin 2
| 1 => 1
| 3 => 1
| _ => 0def B0 : ListBlank (Fin 2) := ListBlank.mk []theorem B0_cons_zero : B0.cons 0 = B0 :=
ListBlank.cons_head_tail B0
Head on the first cell of L.
def Tape.mkL (L R : ListBlank (Fin 2)) : Tape (Fin 2) :=
⟨L.head, L.tail, R⟩@[simp]
theorem Tape.mkL_cons (a : Fin 2) (L R : ListBlank (Fin 2)) :
Tape.mkL (L.cons a) R = ⟨a, L, R⟩ := by a:Fin 2L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ mkL (ListBlank.cons a L) R = { head := a, left := L, right := R }
simp [Tape.mkL] All goals completed! 🐙@[simp]
theorem Tape.mk'_cons (a : Fin 2) (L R : ListBlank (Fin 2)) :
Tape.mk' L (R.cons a) = ⟨a, L, R⟩ := by a:Fin 2L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ Tape.mk' L (ListBlank.cons a R) = { head := a, left := L, right := R }
simp [Tape.mk'] All goals completed! 🐙@[simp]
theorem Tape.mk'_B0 (L : ListBlank (Fin 2)) : Tape.mk' L B0 = ⟨0, L, B0⟩ :=
rfl
The cells left of the first digit: the # pair, then the counter pair.
def LH (c : ℕ) : ListBlank (Fin 2) :=
ListBlank.append [0, 0, clo c, chi c] B0
Start of the pass that doubles 2 ^ n, with counter c.
def stageCfg (c n : ℕ) : Cfg 15 2 :=
⟨1, Tape.mk' (LH c) (ListBlank.append (encR (pw n)) B0)⟩Step Infrastructure
sectionvariable {Q : ℕ}
n steps of M from c, or none if M halts first.
def nSteps (M : Machine Q 2) (n : ℕ) : Cfg Q 2 → Option (Cfg Q 2) :=
Nat.rec (motive := fun _ => Cfg Q 2 → Option (Cfg Q 2))
(fun c => some c)
(fun _ ih c => (step M c).bind ih)
n@[simp]
theorem nSteps_zero (M : Machine Q 2) (c : Cfg Q 2) :
nSteps M 0 c = some c := rfl@[simp]
theorem nSteps_succ (M : Machine Q 2) (n : ℕ) (c : Cfg Q 2) :
nSteps M (n + 1) c = (step M c).bind (nSteps M n) := rflattribute [eqns nSteps_zero nSteps_succ] nStepstheorem nSteps_reaches {M : Machine Q 2} {n : ℕ} {c c' : Cfg Q 2}
(h : nSteps M n c = some c') : Reaches (step M) c c' := by Q:ℕM:Machine Q 2n:ℕc:Cfg Q 2c':Cfg Q 2h:nSteps M n c = some c'⊢ Reaches (step M) c c'
induction n generalizing c with
| zero => zero Q:ℕM:Machine Q 2c':Cfg Q 2c:Cfg Q 2h:nSteps M 0 c = some c'⊢ Reaches (step M) c c'
injection h with h' zero Q:ℕM:Machine Q 2c':Cfg Q 2c:Cfg Q 2h':c = c'⊢ Reaches (step M) c c'
subst h' zero Q:ℕM:Machine Q 2c:Cfg Q 2⊢ Reaches (step M) c c
exact Relation.ReflTransGen.refl All goals completed! 🐙
| succ n ih => succ Q:ℕM:Machine Q 2c':Cfg Q 2n:ℕih:∀ {c : Cfg Q 2}, nSteps M n c = some c' → Reaches (step M) c c'c:Cfg Q 2h:nSteps M (n + 1) c = some c'⊢ Reaches (step M) c c'
simp only [nSteps, Option.bind_eq_some_iff] at h succ Q:ℕM:Machine Q 2c':Cfg Q 2n:ℕih:∀ {c : Cfg Q 2}, nSteps M n c = some c' → Reaches (step M) c c'c:Cfg Q 2h:∃ a,
step M c = some a ∧
Nat.rec (motive := fun x ↦ Cfg Q 2 → Option (Cfg Q 2)) (fun c ↦ some c) (fun x ih c ↦ (step M c).bind ih) n a =
some c'⊢ Reaches (step M) c c'
obtain ⟨c₁, hstep, hrest⟩ := h succ Q:ℕM:Machine Q 2c':Cfg Q 2n:ℕih:∀ {c : Cfg Q 2}, nSteps M n c = some c' → Reaches (step M) c c'c:Cfg Q 2c₁:Cfg Q 2hstep:step M c = some c₁hrest:Nat.rec (motive := fun x ↦ Cfg Q 2 → Option (Cfg Q 2)) (fun c ↦ some c) (fun x ih c ↦ (step M c).bind ih) n c₁ = some c'⊢ Reaches (step M) c c'
exact Relation.ReflTransGen.head hstep (ih hrest) All goals completed! 🐙theorem nSteps_add {M : Machine Q 2} (m n : ℕ) (c : Cfg Q 2) :
nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n) := by Q:ℕM:Machine Q 2m:ℕn:ℕc:Cfg Q 2⊢ nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n)
induction m generalizing c with
| zero => zero Q:ℕM:Machine Q 2n:ℕc:Cfg Q 2⊢ nSteps M (0 + n) c = (nSteps M 0 c).bind (nSteps M n) simp [nSteps] All goals completed! 🐙
| succ m ih => succ Q:ℕM:Machine Q 2n:ℕm:ℕih:∀ (c : Cfg Q 2), nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n)c:Cfg Q 2⊢ nSteps M (m + 1 + n) c = (nSteps M (m + 1) c).bind (nSteps M n)
rw [Nat.succ_add, succ Q:ℕM:Machine Q 2n:ℕm:ℕih:∀ (c : Cfg Q 2), nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n)c:Cfg Q 2⊢ nSteps M (m + n).succ c = (nSteps M (m + 1) c).bind (nSteps M n) nSteps, succ Q:ℕM:Machine Q 2n:ℕm:ℕih:∀ (c : Cfg Q 2), nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n)c:Cfg Q 2⊢ (step M c).bind (nSteps M (m + n)) = (nSteps M (m + 1) c).bind (nSteps M n) nSteps succ Q:ℕM:Machine Q 2n:ℕm:ℕih:∀ (c : Cfg Q 2), nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n)c:Cfg Q 2⊢ (step M c).bind (nSteps M (m + n)) = ((step M c).bind (nSteps M m)).bind (nSteps M n)] succ Q:ℕM:Machine Q 2n:ℕm:ℕih:∀ (c : Cfg Q 2), nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n)c:Cfg Q 2⊢ (step M c).bind (nSteps M (m + n)) = ((step M c).bind (nSteps M m)).bind (nSteps M n)
cases step M c succ.none Q:ℕM:Machine Q 2n:ℕm:ℕih:∀ (c : Cfg Q 2), nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n)c:Cfg Q 2⊢ none.bind (nSteps M (m + n)) = (none.bind (nSteps M m)).bind (nSteps M n)succ.some Q:ℕM:Machine Q 2n:ℕm:ℕih:∀ (c : Cfg Q 2), nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n)c:Cfg Q 2val✝:Cfg Q 2⊢ (some val✝).bind (nSteps M (m + n)) = ((some val✝).bind (nSteps M m)).bind (nSteps M n) <;> succ.none Q:ℕM:Machine Q 2n:ℕm:ℕih:∀ (c : Cfg Q 2), nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n)c:Cfg Q 2⊢ none.bind (nSteps M (m + n)) = (none.bind (nSteps M m)).bind (nSteps M n)succ.some Q:ℕM:Machine Q 2n:ℕm:ℕih:∀ (c : Cfg Q 2), nSteps M (m + n) c = (nSteps M m c).bind (nSteps M n)c:Cfg Q 2val✝:Cfg Q 2⊢ (some val✝).bind (nSteps M (m + n)) = ((some val✝).bind (nSteps M m)).bind (nSteps M n) simp [ih] All goals completed! 🐙theorem nSteps_bind_eq {M : Machine Q 2} {m n : ℕ} {c c₁ c₂ : Cfg Q 2}
(h₁ : nSteps M m c = some c₁) (h₂ : nSteps M n c₁ = some c₂) :
nSteps M (m + n) c = some c₂ := by Q:ℕM:Machine Q 2m:ℕn:ℕc:Cfg Q 2c₁:Cfg Q 2c₂:Cfg Q 2h₁:nSteps M m c = some c₁h₂:nSteps M n c₁ = some c₂⊢ nSteps M (m + n) c = some c₂
rw [nSteps_add, Q:ℕM:Machine Q 2m:ℕn:ℕc:Cfg Q 2c₁:Cfg Q 2c₂:Cfg Q 2h₁:nSteps M m c = some c₁h₂:nSteps M n c₁ = some c₂⊢ (nSteps M m c).bind (nSteps M n) = some c₂ h₁, Q:ℕM:Machine Q 2m:ℕn:ℕc:Cfg Q 2c₁:Cfg Q 2c₂:Cfg Q 2h₁:nSteps M m c = some c₁h₂:nSteps M n c₁ = some c₂⊢ (some c₁).bind (nSteps M n) = some c₂ Option.bind_some, Q:ℕM:Machine Q 2m:ℕn:ℕc:Cfg Q 2c₁:Cfg Q 2c₂:Cfg Q 2h₁:nSteps M m c = some c₁h₂:nSteps M n c₁ = some c₂⊢ nSteps M n c₁ = some c₂ h₂ Q:ℕM:Machine Q 2m:ℕn:ℕc:Cfg Q 2c₁:Cfg Q 2c₂:Cfg Q 2h₁:nSteps M m c = some c₁h₂:nSteps M n c₁ = some c₂⊢ some c₂ = some c₂] All goals completed! 🐙theorem step_one {M : Machine Q 2} {c c₁ : Cfg Q 2} (h : step M c = some c₁) :
nSteps M 1 c = some c₁ := by Q:ℕM:Machine Q 2c:Cfg Q 2c₁:Cfg Q 2h:step M c = some c₁⊢ nSteps M 1 c = some c₁
rw [nSteps, Q:ℕM:Machine Q 2c:Cfg Q 2c₁:Cfg Q 2h:step M c = some c₁⊢ (step M c).bind (nSteps M 0) = some c₁ h Q:ℕM:Machine Q 2c:Cfg Q 2c₁:Cfg Q 2h:step M c = some c₁⊢ (some c₁).bind (nSteps M 0) = some c₁] Q:ℕM:Machine Q 2c:Cfg Q 2c₁:Cfg Q 2h:step M c = some c₁⊢ (some c₁).bind (nSteps M 0) = some c₁; rfl All goals completed! 🐙theorem reaches_imp_nSteps {M : Machine Q 2} {a b : Cfg Q 2}
(h : Reaches (step M) a b) : ∃ k, nSteps M k a = some b := by Q:ℕM:Machine Q 2a:Cfg Q 2b:Cfg Q 2h:Reaches (step M) a b⊢ ∃ k, nSteps M k a = some b
induction h with
| refl => refl Q:ℕM:Machine Q 2a:Cfg Q 2b:Cfg Q 2⊢ ∃ k, nSteps M k a = some a exact ⟨0, rfl⟩ All goals completed! 🐙
| tail _ hstep ih => tail Q:ℕM:Machine Q 2a:Cfg Q 2b:Cfg Q 2b✝:Cfg Q 2c✝:Cfg Q 2a✝:Relation.ReflTransGen (fun a b ↦ b ∈ step M a) a b✝hstep:c✝ ∈ step M b✝ih:∃ k, nSteps M k a = some b✝⊢ ∃ k, nSteps M k a = some c✝
obtain ⟨k, hk⟩ := ih tail Q:ℕM:Machine Q 2a:Cfg Q 2b:Cfg Q 2b✝:Cfg Q 2c✝:Cfg Q 2a✝:Relation.ReflTransGen (fun a b ↦ b ∈ step M a) a b✝hstep:c✝ ∈ step M b✝k:ℕhk:nSteps M k a = some b✝⊢ ∃ k, nSteps M k a = some c✝
exact ⟨k + 1, nSteps_bind_eq hk (step_one hstep)⟩ All goals completed! 🐙theorem nSteps_eq_none_of_step_none {M : Machine Q 2} {k : ℕ} (s : ℕ) {a b : Cfg Q 2}
(hk : nSteps M k a = some b) (hnone : step M b = none) (hks : k < s) :
nSteps M s a = none := by Q:ℕM:Machine Q 2k:ℕs:ℕa:Cfg Q 2b:Cfg Q 2hk:nSteps M k a = some bhnone:step M b = nonehks:k < s⊢ nSteps M s a = none
have hs : s = k + ((s - k - 1) + 1) := by omega Q:ℕM:Machine Q 2k:ℕs:ℕa:Cfg Q 2b:Cfg Q 2hk:nSteps M k a = some bhnone:step M b = nonehks:k < shs:s = k + (s - k - 1 + 1)⊢ nSteps M s a = none
rw [hs, Q:ℕM:Machine Q 2k:ℕs:ℕa:Cfg Q 2b:Cfg Q 2hk:nSteps M k a = some bhnone:step M b = nonehks:k < shs:s = k + (s - k - 1 + 1)⊢ nSteps M (k + (s - k - 1 + 1)) a = none nSteps_add, Q:ℕM:Machine Q 2k:ℕs:ℕa:Cfg Q 2b:Cfg Q 2hk:nSteps M k a = some bhnone:step M b = nonehks:k < shs:s = k + (s - k - 1 + 1)⊢ (nSteps M k a).bind (nSteps M (s - k - 1 + 1)) = none hk, Q:ℕM:Machine Q 2k:ℕs:ℕa:Cfg Q 2b:Cfg Q 2hk:nSteps M k a = some bhnone:step M b = nonehks:k < shs:s = k + (s - k - 1 + 1)⊢ (some b).bind (nSteps M (s - k - 1 + 1)) = none Option.bind_some, Q:ℕM:Machine Q 2k:ℕs:ℕa:Cfg Q 2b:Cfg Q 2hk:nSteps M k a = some bhnone:step M b = nonehks:k < shs:s = k + (s - k - 1 + 1)⊢ nSteps M (s - k - 1 + 1) b = none nSteps_succ, Q:ℕM:Machine Q 2k:ℕs:ℕa:Cfg Q 2b:Cfg Q 2hk:nSteps M k a = some bhnone:step M b = nonehks:k < shs:s = k + (s - k - 1 + 1)⊢ (step M b).bind (nSteps M (s - k - 1)) = none hnone, Q:ℕM:Machine Q 2k:ℕs:ℕa:Cfg Q 2b:Cfg Q 2hk:nSteps M k a = some bhnone:step M b = nonehks:k < shs:s = k + (s - k - 1 + 1)⊢ none.bind (nSteps M (s - k - 1)) = none Option.bind_none Q:ℕM:Machine Q 2k:ℕs:ℕa:Cfg Q 2b:Cfg Q 2hk:nSteps M k a = some bhnone:step M b = nonehks:k < shs:s = k + (s - k - 1 + 1)⊢ none = none] All goals completed! 🐙endTransition Table
theorem stepR {q q' : Fin 15} {a b : Fin 2}
(h : erdosTernary15.transition q a = some (b, .right, q'))
(L R : ListBlank (Fin 2)) :
step erdosTernary15 ⟨q, ⟨a, L, R⟩⟩ = some ⟨q', Tape.mk' (L.cons b) R⟩ := by q:Fin 15q':Fin 15a:Fin 2b:Fin 2h:erdosTernary15.transition q a = some (b, Dir.right, q')L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ step erdosTernary15 { state := q, tape := { head := a, left := L, right := R } } =
some { state := q', tape := Tape.mk' (ListBlank.cons b L) R }
simp only [step, h, Option.map_some] q:Fin 15q':Fin 15a:Fin 2b:Fin 2h:erdosTernary15.transition q a = some (b, Dir.right, q')L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ some { state := q', tape := Tape.move Dir.right (Tape.write b { head := a, left := L, right := R }) } =
some { state := q', tape := Tape.mk' (ListBlank.cons b L) R }; rfl All goals completed! 🐙theorem stepL {q q' : Fin 15} {a b : Fin 2}
(h : erdosTernary15.transition q a = some (b, .left, q'))
(L R : ListBlank (Fin 2)) :
step erdosTernary15 ⟨q, ⟨a, L, R⟩⟩ = some ⟨q', Tape.mkL L (R.cons b)⟩ := by q:Fin 15q':Fin 15a:Fin 2b:Fin 2h:erdosTernary15.transition q a = some (b, Dir.left, q')L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ step erdosTernary15 { state := q, tape := { head := a, left := L, right := R } } =
some { state := q', tape := Tape.mkL L (ListBlank.cons b R) }
simp only [step, h, Option.map_some] q:Fin 15q':Fin 15a:Fin 2b:Fin 2h:erdosTernary15.transition q a = some (b, Dir.left, q')L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ some { state := q', tape := Tape.move Dir.left (Tape.write b { head := a, left := L, right := R }) } =
some { state := q', tape := Tape.mkL L (ListBlank.cons b R) }; rfl All goals completed! 🐙theorem s0_0 (L R) : step erdosTernary15 ⟨0, ⟨0, L, R⟩⟩ = some ⟨8, Tape.mk' (L.cons 1) R⟩ :=
stepR rfl L Rtheorem s0_1 (L R) : step erdosTernary15 ⟨0, ⟨1, L, R⟩⟩ = some ⟨7, Tape.mk' (L.cons 1) R⟩ :=
stepR rfl L Rtheorem s1_0 (L R) : step erdosTernary15 ⟨1, ⟨0, L, R⟩⟩ = some ⟨3, Tape.mk' (L.cons 0) R⟩ :=
stepR rfl L Rtheorem s1_1 (L R) : step erdosTernary15 ⟨1, ⟨1, L, R⟩⟩ = some ⟨2, Tape.mk' (L.cons 1) R⟩ :=
stepR rfl L Rtheorem s2_0 (L R) : step erdosTernary15 ⟨2, ⟨0, L, R⟩⟩ = some ⟨1, Tape.mk' (L.cons 1) R⟩ :=
stepR rfl L Rtheorem s2_1 (L R) : step erdosTernary15 ⟨2, ⟨1, L, R⟩⟩ = some ⟨0, Tape.mk' (L.cons 0) R⟩ :=
stepR rfl L Rtheorem s3_0 (L R) : step erdosTernary15 ⟨3, ⟨0, L, R⟩⟩ = some ⟨5, Tape.mkL L (R.cons 0)⟩ :=
stepL rfl L Rtheorem s3_1 (L R) : step erdosTernary15 ⟨3, ⟨1, L, R⟩⟩ = some ⟨1, Tape.mk' (L.cons 1) R⟩ :=
stepR rfl L Rtheorem s4_0 (L R) : step erdosTernary15 ⟨4, ⟨0, L, R⟩⟩ = some ⟨6, Tape.mkL L (R.cons 0)⟩ :=
stepL rfl L Rtheorem s4_1 (L R) : step erdosTernary15 ⟨4, ⟨1, L, R⟩⟩ = some ⟨5, Tape.mkL L (R.cons 1)⟩ :=
stepL rfl L Rtheorem s5_0 (L R) : step erdosTernary15 ⟨5, ⟨0, L, R⟩⟩ = some ⟨4, Tape.mkL L (R.cons 0)⟩ :=
stepL rfl L Rtheorem s5_1 (L R) : step erdosTernary15 ⟨5, ⟨1, L, R⟩⟩ = some ⟨10, Tape.mkL L (R.cons 1)⟩ :=
stepL rfl L Rtheorem s6_0 (L R) : step erdosTernary15 ⟨6, ⟨0, L, R⟩⟩ = some ⟨13, Tape.mkL L (R.cons 0)⟩ :=
stepL rfl L Rtheorem s6_1 (L R) : step erdosTernary15 ⟨6, ⟨1, L, R⟩⟩ = some ⟨4, Tape.mkL L (R.cons 1)⟩ :=
stepL rfl L Rtheorem s7_0 (L R) : step erdosTernary15 ⟨7, ⟨0, L, R⟩⟩ = some ⟨9, Tape.mkL L (R.cons 1)⟩ :=
stepL rfl L Rtheorem s7_1 (L R) : step erdosTernary15 ⟨7, ⟨1, L, R⟩⟩ = some ⟨0, Tape.mk' (L.cons 1) R⟩ :=
stepR rfl L Rtheorem s8_0 (L R) : step erdosTernary15 ⟨8, ⟨0, L, R⟩⟩ = some ⟨1, Tape.mk' (L.cons 0) R⟩ :=
stepR rfl L Rtheorem s8_1 (L R) : step erdosTernary15 ⟨8, ⟨1, L, R⟩⟩ = some ⟨1, Tape.mk' (L.cons 0) R⟩ :=
stepR rfl L Rtheorem s9_0 (L R) : step erdosTernary15 ⟨9, ⟨0, L, R⟩⟩ = some ⟨12, Tape.mk' (L.cons 0) R⟩ :=
stepR rfl L Rtheorem s9_1 (L R) : step erdosTernary15 ⟨9, ⟨1, L, R⟩⟩ = some ⟨7, Tape.mk' (L.cons 0) R⟩ :=
stepR rfl L Rtheorem s10_0 (L R) : step erdosTernary15 ⟨10, ⟨0, L, R⟩⟩ = some ⟨12, Tape.mkL L (R.cons 0)⟩ :=
stepL rfl L Rtheorem s10_1 (L R) : step erdosTernary15 ⟨10, ⟨1, L, R⟩⟩ = some ⟨11, Tape.mkL L (R.cons 1)⟩ :=
stepL rfl L Rtheorem s11_0 (L R) : step erdosTernary15 ⟨11, ⟨0, L, R⟩⟩ = some ⟨10, Tape.mkL L (R.cons 0)⟩ :=
stepL rfl L Rtheorem s11_1 (L R) : step erdosTernary15 ⟨11, ⟨1, L, R⟩⟩ = some ⟨10, Tape.mkL L (R.cons 1)⟩ :=
stepL rfl L Rtheorem s12_0 (L R) : step erdosTernary15 ⟨12, ⟨0, L, R⟩⟩ = some ⟨8, Tape.mk' (L.cons 0) R⟩ :=
stepR rfl L Rtheorem s12_1 (L R) : step erdosTernary15 ⟨12, ⟨1, L, R⟩⟩ = some ⟨10, Tape.mkL L (R.cons 1)⟩ :=
stepL rfl L Rtheorem s13_0 (L R) : step erdosTernary15 ⟨13, ⟨0, L, R⟩⟩ = some ⟨12, Tape.mk' (L.cons 1) R⟩ :=
stepR rfl L Rtheorem s13_1 (L R) : step erdosTernary15 ⟨13, ⟨1, L, R⟩⟩ = some ⟨14, Tape.mkL L (R.cons 0)⟩ :=
stepL rfl L Rtheorem s14_0 (L R) : step erdosTernary15 ⟨14, ⟨0, L, R⟩⟩ = some ⟨9, Tape.mk' (L.cons 1) R⟩ :=
stepR rfl L Rtheorem s14_1 (L R : ListBlank (Fin 2)) : step erdosTernary15 ⟨14, ⟨1, L, R⟩⟩ = none := rflRuns the machine through a fixed sequence of steps on a concrete tape.
local macro "tm_run" : tactic => `(tactic| simp only [nSteps_succ, nSteps_zero, Option.bind_some,
s0_0, s0_1, s1_0, s1_1, s2_0, s2_1, s3_0, s3_1, s4_0, s4_1, s5_0, s5_1, s6_0, s6_1, s7_0,
s7_1, s8_0, s8_1, s9_0, s9_1, s10_0, s10_1, s11_0, s11_1, s12_0, s12_1, s13_0, s13_1, s14_0,
Tape.mk'_cons, Tape.mkL_cons, Tape.mk'_B0, ListBlank.append, hi_zero, hi_one, hi_two, lo_zero,
lo_one, lo_two])
Doubling Pass (States 0–3, 7–9)
The doubling state for carry c: mul2_F (1) for carry 0, mul2_G (0) for carry 1.
def st : ℕ → Fin 15
| 0 => 1
| _ => 0theorem digit_step (d c : ℕ) (hd : d < 3) (hc : c ≤ 1) (L R : ListBlank (Fin 2)) :
∃ s, nSteps erdosTernary15 s ⟨st c, ⟨hi d, L, R.cons (lo d)⟩⟩ =
some ⟨st ((2 * d + c) / 3),
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) R⟩ := by d:ℕc:ℕhd:d < 3hc:c ≤ 1L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := { head := hi d, left := L, right := ListBlank.cons (lo d) R } } =
some
{ state := st ((2 * d + c) / 3),
tape := Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) R }
rcases (by d:ℕc:ℕhd:d < 3hc:c ≤ 1L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ d = 0 ∨ d = 1 ∨ d = 2 omega All goals completed! 🐙 : d = 0 ∨ d = 1 ∨ d = 2) with rfl | rfl | rfl <;> inl c:ℕhc:c ≤ 1L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := { head := hi 0, left := L, right := ListBlank.cons (lo 0) R } } =
some
{ state := st ((2 * 0 + c) / 3),
tape := Tape.mk' (ListBlank.append [lo ((2 * 0 + c) % 3), hi ((2 * 0 + c) % 3)] L) R }inr.inl c:ℕhc:c ≤ 1L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := { head := hi 1, left := L, right := ListBlank.cons (lo 1) R } } =
some
{ state := st ((2 * 1 + c) / 3),
tape := Tape.mk' (ListBlank.append [lo ((2 * 1 + c) % 3), hi ((2 * 1 + c) % 3)] L) R }inr.inr c:ℕhc:c ≤ 1L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := { head := hi 2, left := L, right := ListBlank.cons (lo 2) R } } =
some
{ state := st ((2 * 2 + c) / 3),
tape := Tape.mk' (ListBlank.append [lo ((2 * 2 + c) % 3), hi ((2 * 2 + c) % 3)] L) R }
rcases (by c:ℕhc:c ≤ 1L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3⊢ c = 0 ∨ c = 1 omega All goals completed! 🐙 : c = 0 ∨ c = 1) with rfl | rfl <;> inl.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3hc:0 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := st 0, tape := { head := hi 0, left := L, right := ListBlank.cons (lo 0) R } } =
some
{ state := st ((2 * 0 + 0) / 3),
tape := Tape.mk' (ListBlank.append [lo ((2 * 0 + 0) % 3), hi ((2 * 0 + 0) % 3)] L) R }inl.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3hc:1 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := st 1, tape := { head := hi 0, left := L, right := ListBlank.cons (lo 0) R } } =
some
{ state := st ((2 * 0 + 1) / 3),
tape := Tape.mk' (ListBlank.append [lo ((2 * 0 + 1) % 3), hi ((2 * 0 + 1) % 3)] L) R }inr.inl.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3hc:0 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := st 0, tape := { head := hi 1, left := L, right := ListBlank.cons (lo 1) R } } =
some
{ state := st ((2 * 1 + 0) / 3),
tape := Tape.mk' (ListBlank.append [lo ((2 * 1 + 0) % 3), hi ((2 * 1 + 0) % 3)] L) R }inr.inl.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3hc:1 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := st 1, tape := { head := hi 1, left := L, right := ListBlank.cons (lo 1) R } } =
some
{ state := st ((2 * 1 + 1) / 3),
tape := Tape.mk' (ListBlank.append [lo ((2 * 1 + 1) % 3), hi ((2 * 1 + 1) % 3)] L) R }inr.inr.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3hc:0 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := st 0, tape := { head := hi 2, left := L, right := ListBlank.cons (lo 2) R } } =
some
{ state := st ((2 * 2 + 0) / 3),
tape := Tape.mk' (ListBlank.append [lo ((2 * 2 + 0) % 3), hi ((2 * 2 + 0) % 3)] L) R }inr.inr.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3hc:1 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := st 1, tape := { head := hi 2, left := L, right := ListBlank.cons (lo 2) R } } =
some
{ state := st ((2 * 2 + 1) / 3),
tape := Tape.mk' (ListBlank.append [lo ((2 * 2 + 1) % 3), hi ((2 * 2 + 1) % 3)] L) R }
simp only [st, Nat.reduceMul, Nat.reduceAdd, Nat.reduceMod, Nat.reduceDiv] inr.inr.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3hc:1 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := 0, tape := { head := hi 2, left := L, right := ListBlank.cons (lo 2) R } } =
some { state := 0, tape := Tape.mk' (ListBlank.append [lo 2, hi 2] L) R }
· inl.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3hc:0 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := 1, tape := { head := hi 0, left := L, right := ListBlank.cons (lo 0) R } } =
some { state := 1, tape := Tape.mk' (ListBlank.append [lo 0, hi 0] L) R } exact ⟨2, by L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3hc:0 ≤ 1⊢ nSteps erdosTernary15 2 { state := 1, tape := { head := hi 0, left := L, right := ListBlank.cons (lo 0) R } } =
some { state := 1, tape := Tape.mk' (ListBlank.append [lo 0, hi 0] L) R } tm_run All goals completed! 🐙⟩
· inl.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3hc:1 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := 0, tape := { head := hi 0, left := L, right := ListBlank.cons (lo 0) R } } =
some { state := 1, tape := Tape.mk' (ListBlank.append [lo 1, hi 1] L) R } exact ⟨2, by L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3hc:1 ≤ 1⊢ nSteps erdosTernary15 2 { state := 0, tape := { head := hi 0, left := L, right := ListBlank.cons (lo 0) R } } =
some { state := 1, tape := Tape.mk' (ListBlank.append [lo 1, hi 1] L) R } tm_run All goals completed! 🐙⟩
· inr.inl.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3hc:0 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := 1, tape := { head := hi 1, left := L, right := ListBlank.cons (lo 1) R } } =
some { state := 1, tape := Tape.mk' (ListBlank.append [lo 2, hi 2] L) R } exact ⟨2, by L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3hc:0 ≤ 1⊢ nSteps erdosTernary15 2 { state := 1, tape := { head := hi 1, left := L, right := ListBlank.cons (lo 1) R } } =
some { state := 1, tape := Tape.mk' (ListBlank.append [lo 2, hi 2] L) R } tm_run All goals completed! 🐙⟩
· inr.inl.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3hc:1 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := 0, tape := { head := hi 1, left := L, right := ListBlank.cons (lo 1) R } } =
some { state := 0, tape := Tape.mk' (ListBlank.append [lo 0, hi 0] L) R } exact ⟨4, by L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3hc:1 ≤ 1⊢ nSteps erdosTernary15 4 { state := 0, tape := { head := hi 1, left := L, right := ListBlank.cons (lo 1) R } } =
some { state := 0, tape := Tape.mk' (ListBlank.append [lo 0, hi 0] L) R } tm_run All goals completed! 🐙⟩
· inr.inr.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3hc:0 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := 1, tape := { head := hi 2, left := L, right := ListBlank.cons (lo 2) R } } =
some { state := 0, tape := Tape.mk' (ListBlank.append [lo 1, hi 1] L) R } exact ⟨2, by L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3hc:0 ≤ 1⊢ nSteps erdosTernary15 2 { state := 1, tape := { head := hi 2, left := L, right := ListBlank.cons (lo 2) R } } =
some { state := 0, tape := Tape.mk' (ListBlank.append [lo 1, hi 1] L) R } tm_run All goals completed! 🐙⟩
· inr.inr.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3hc:1 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := 0, tape := { head := hi 2, left := L, right := ListBlank.cons (lo 2) R } } =
some { state := 0, tape := Tape.mk' (ListBlank.append [lo 2, hi 2] L) R } exact ⟨2, by L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3hc:1 ≤ 1⊢ nSteps erdosTernary15 2 { state := 0, tape := { head := hi 2, left := L, right := ListBlank.cons (lo 2) R } } =
some { state := 0, tape := Tape.mk' (ListBlank.append [lo 2, hi 2] L) R } tm_run All goals completed! 🐙⟩theorem blank_step (L : ListBlank (Fin 2)) :
nSteps erdosTernary15 3 ⟨1, Tape.mk' L B0⟩ = some ⟨4, Tape.mkL L B0⟩ := by L:ListBlank (Fin 2)⊢ nSteps erdosTernary15 3 { state := 1, tape := Tape.mk' L B0 } = some { state := 4, tape := Tape.mkL L B0 }
tm_run L:ListBlank (Fin 2)⊢ some { state := 4, tape := Tape.mkL L (ListBlank.cons 0 (ListBlank.cons 0 B0)) } =
some { state := 4, tape := Tape.mkL L B0 }
rw [B0_cons_zero, L:ListBlank (Fin 2)⊢ some { state := 4, tape := Tape.mkL L (ListBlank.cons 0 B0) } = some { state := 4, tape := Tape.mkL L B0 } B0_cons_zero L:ListBlank (Fin 2)⊢ some { state := 4, tape := Tape.mkL L B0 } = some { state := 4, tape := Tape.mkL L B0 }] All goals completed! 🐙
One pass doubles the digit list ds with carry c; it ends in state 4 on the right cell
of the most significant digit.
theorem mul2_pass (ds : List ℕ) (hds : ∀ d ∈ ds, d < 3) (c : ℕ) (hc : c ≤ 1)
(L : ListBlank (Fin 2)) :
∃ s, nSteps erdosTernary15 s ⟨st c, Tape.mk' L (ListBlank.append (encR ds) B0)⟩ =
some ⟨4, Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0⟩ := by ds:List ℕhds:∀ d ∈ ds, d < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }
induction ds generalizing c L with
| nil => nil hds:∀ d ∈ [], d < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] c)) L) B0 }
rcases (by hds:∀ d ∈ [], d < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)⊢ c = 0 ∨ c = 1 omega All goals completed! 🐙 : c = 0 ∨ c = 1) with rfl | rfl
· nil.inl hds:∀ d ∈ [], d < 3L:ListBlank (Fin 2)hc:0 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := st 0, tape := Tape.mk' L (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 0)) L) B0 } exact ⟨3, blank_step L⟩ All goals completed! 🐙
· nil.inr hds:∀ d ∈ [], d < 3L:ListBlank (Fin 2)hc:1 ≤ 1⊢ ∃ s,
nSteps erdosTernary15 s { state := st 1, tape := Tape.mk' L (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) L) B0 } refine ⟨2 + 3, nSteps_bind_eq (c₁ := ⟨1, Tape.mk' ((L.cons 1).cons 0) B0⟩) ?_ ?_⟩ nil.inr.refine_1 hds:∀ d ∈ [], d < 3L:ListBlank (Fin 2)hc:1 ≤ 1⊢ nSteps erdosTernary15 2 { state := st 1, tape := Tape.mk' L (ListBlank.append (encR []) B0) } =
some { state := 1, tape := Tape.mk' (ListBlank.cons 0 (ListBlank.cons 1 L)) B0 }nil.inr.refine_2 hds:∀ d ∈ [], d < 3L:ListBlank (Fin 2)hc:1 ≤ 1⊢ nSteps erdosTernary15 3 { state := 1, tape := Tape.mk' (ListBlank.cons 0 (ListBlank.cons 1 L)) B0 } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) L) B0 }
· nil.inr.refine_1 hds:∀ d ∈ [], d < 3L:ListBlank (Fin 2)hc:1 ≤ 1⊢ nSteps erdosTernary15 2 { state := st 1, tape := Tape.mk' L (ListBlank.append (encR []) B0) } =
some { state := 1, tape := Tape.mk' (ListBlank.cons 0 (ListBlank.cons 1 L)) B0 } simp only [st, encR, ListBlank.append] nil.inr.refine_1 hds:∀ d ∈ [], d < 3L:ListBlank (Fin 2)hc:1 ≤ 1⊢ nSteps erdosTernary15 2 { state := 0, tape := Tape.mk' L B0 } =
some { state := 1, tape := Tape.mk' (ListBlank.cons 0 (ListBlank.cons 1 L)) B0 }; tm_run All goals completed! 🐙
· nil.inr.refine_2 hds:∀ d ∈ [], d < 3L:ListBlank (Fin 2)hc:1 ≤ 1⊢ nSteps erdosTernary15 3 { state := 1, tape := Tape.mk' (ListBlank.cons 0 (ListBlank.cons 1 L)) B0 } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) L) B0 } exact blank_step _ All goals completed! 🐙
| cons d ds ih => cons d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR (d :: ds)) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl (d :: ds) c)) L) B0 }
have hd := hds d (by d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)⊢ d ∈ d :: ds simp All goals completed! 🐙) cons d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)hd:d < 3⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR (d :: ds)) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl (d :: ds) c)) L) B0 }
obtain ⟨s₁, hs₁⟩ := digit_step d c hd hc L (ListBlank.append (encR ds) B0) cons d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)hd:d < 3s₁:ℕhs₁:nSteps erdosTernary15 s₁
{ state := st c,
tape := { head := hi d, left := L, right := ListBlank.cons (lo d) (ListBlank.append (encR ds) B0) } } =
some
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) }⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR (d :: ds)) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl (d :: ds) c)) L) B0 }
obtain ⟨s₂, hs₂⟩ := ih (fun x hx => hds x (by d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)hd:d < 3s₁:ℕhs₁:nSteps erdosTernary15 s₁
{ state := st c,
tape := { head := hi d, left := L, right := ListBlank.cons (lo d) (ListBlank.append (encR ds) B0) } } =
some
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) }x:ℕhx:x ∈ ds⊢ x ∈ d :: ds simp [hx] All goals completed! 🐙)) ((2 * d + c) / 3) (by d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)hd:d < 3s₁:ℕhs₁:nSteps erdosTernary15 s₁
{ state := st c,
tape := { head := hi d, left := L, right := ListBlank.cons (lo d) (ListBlank.append (encR ds) B0) } } =
some
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) }⊢ (2 * d + c) / 3 ≤ 1 omega All goals completed! 🐙)
(ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) cons d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)hd:d < 3s₁:ℕhs₁:nSteps erdosTernary15 s₁
{ state := st c,
tape := { head := hi d, left := L, right := ListBlank.cons (lo d) (ListBlank.append (encR ds) B0) } } =
some
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) }s₂:ℕhs₂:nSteps erdosTernary15 s₂
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) } =
some
{ state := 4,
tape :=
Tape.mkL
(ListBlank.append (encL (dbl ds ((2 * d + c) / 3)))
(ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L))
B0 }⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR (d :: ds)) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl (d :: ds) c)) L) B0 }
have e : ListBlank.append (encL (dbl (d :: ds) c)) L =
ListBlank.append (encL (dbl ds ((2 * d + c) / 3)))
(ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) := by ds:List ℕhds:∀ d ∈ ds, d < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }
simp only [dbl, encL, ListBlank.append_assoc] cons d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)hd:d < 3s₁:ℕhs₁:nSteps erdosTernary15 s₁
{ state := st c,
tape := { head := hi d, left := L, right := ListBlank.cons (lo d) (ListBlank.append (encR ds) B0) } } =
some
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) }s₂:ℕhs₂:nSteps erdosTernary15 s₂
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) } =
some
{ state := 4,
tape :=
Tape.mkL
(ListBlank.append (encL (dbl ds ((2 * d + c) / 3)))
(ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L))
B0 }e:ListBlank.append (encL (dbl (d :: ds) c)) L =
ListBlank.append (encL (dbl ds ((2 * d + c) / 3))) (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L)⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR (d :: ds)) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl (d :: ds) c)) L) B0 }
rw [e cons d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)hd:d < 3s₁:ℕhs₁:nSteps erdosTernary15 s₁
{ state := st c,
tape := { head := hi d, left := L, right := ListBlank.cons (lo d) (ListBlank.append (encR ds) B0) } } =
some
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) }s₂:ℕhs₂:nSteps erdosTernary15 s₂
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) } =
some
{ state := 4,
tape :=
Tape.mkL
(ListBlank.append (encL (dbl ds ((2 * d + c) / 3)))
(ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L))
B0 }e:ListBlank.append (encL (dbl (d :: ds) c)) L =
ListBlank.append (encL (dbl ds ((2 * d + c) / 3))) (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L)⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR (d :: ds)) B0) } =
some
{ state := 4,
tape :=
Tape.mkL
(ListBlank.append (encL (dbl ds ((2 * d + c) / 3)))
(ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L))
B0 }] cons d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)hd:d < 3s₁:ℕhs₁:nSteps erdosTernary15 s₁
{ state := st c,
tape := { head := hi d, left := L, right := ListBlank.cons (lo d) (ListBlank.append (encR ds) B0) } } =
some
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) }s₂:ℕhs₂:nSteps erdosTernary15 s₂
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) } =
some
{ state := 4,
tape :=
Tape.mkL
(ListBlank.append (encL (dbl ds ((2 * d + c) / 3)))
(ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L))
B0 }e:ListBlank.append (encL (dbl (d :: ds) c)) L =
ListBlank.append (encL (dbl ds ((2 * d + c) / 3))) (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L)⊢ ∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR (d :: ds)) B0) } =
some
{ state := 4,
tape :=
Tape.mkL
(ListBlank.append (encL (dbl ds ((2 * d + c) / 3)))
(ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L))
B0 }
refine ⟨s₁ + s₂, nSteps_bind_eq ?_ hs₂⟩ cons d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ c ≤ 1,
∀ (L : ListBlank (Fin 2)),
∃ s,
nSteps erdosTernary15 s { state := st c, tape := Tape.mk' L (ListBlank.append (encR ds) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl ds c)) L) B0 }hds:∀ d_1 ∈ d :: ds, d_1 < 3c:ℕhc:c ≤ 1L:ListBlank (Fin 2)hd:d < 3s₁:ℕhs₁:nSteps erdosTernary15 s₁
{ state := st c,
tape := { head := hi d, left := L, right := ListBlank.cons (lo d) (ListBlank.append (encR ds) B0) } } =
some
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) }s₂:ℕhs₂:nSteps erdosTernary15 s₂
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) } =
some
{ state := 4,
tape :=
Tape.mkL
(ListBlank.append (encL (dbl ds ((2 * d + c) / 3)))
(ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L))
B0 }e:ListBlank.append (encL (dbl (d :: ds) c)) L =
ListBlank.append (encL (dbl ds ((2 * d + c) / 3))) (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L)⊢ nSteps erdosTernary15 s₁ { state := st c, tape := Tape.mk' L (ListBlank.append (encR (d :: ds)) B0) } =
some
{ state := st ((2 * d + c) / 3),
tape :=
Tape.mk' (ListBlank.append [lo ((2 * d + c) % 3), hi ((2 * d + c) % 3)] L) (ListBlank.append (encR ds) B0) }
simpa only [encR, ListBlank.append, Tape.mk'_cons] using hs₁ All goals completed! 🐙
Search for a 2 (States 4–6, 10–12)
theorem pair_scan (q : Fin 15) (hq : q = 4 ∨ q = 10) (d : ℕ) (hd : d < 3)
(L R : ListBlank (Fin 2)) :
nSteps erdosTernary15 2 ⟨q, ⟨lo d, L.cons (hi d), R⟩⟩ =
some ⟨if q = 10 ∨ d = 2 then 10 else 4, Tape.mkL L ((R.cons (lo d)).cons (hi d))⟩ := by q:Fin 15hq:q = 4 ∨ q = 10d:ℕhd:d < 3L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ nSteps erdosTernary15 2 { state := q, tape := { head := lo d, left := ListBlank.cons (hi d) L, right := R } } =
some
{ state := if q = 10 ∨ d = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi d) (ListBlank.cons (lo d) R)) }
rcases hq with rfl | rfl inl d:ℕhd:d < 3L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ nSteps erdosTernary15 2 { state := 4, tape := { head := lo d, left := ListBlank.cons (hi d) L, right := R } } =
some
{ state := if 4 = 10 ∨ d = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi d) (ListBlank.cons (lo d) R)) }inr d:ℕhd:d < 3L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ nSteps erdosTernary15 2 { state := 10, tape := { head := lo d, left := ListBlank.cons (hi d) L, right := R } } =
some
{ state := if 10 = 10 ∨ d = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi d) (ListBlank.cons (lo d) R)) } <;> inl d:ℕhd:d < 3L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ nSteps erdosTernary15 2 { state := 4, tape := { head := lo d, left := ListBlank.cons (hi d) L, right := R } } =
some
{ state := if 4 = 10 ∨ d = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi d) (ListBlank.cons (lo d) R)) }inr d:ℕhd:d < 3L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ nSteps erdosTernary15 2 { state := 10, tape := { head := lo d, left := ListBlank.cons (hi d) L, right := R } } =
some
{ state := if 10 = 10 ∨ d = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi d) (ListBlank.cons (lo d) R)) } rcases (by d:ℕhd:d < 3L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ d = 0 ∨ d = 1 ∨ d = 2 omega All goals completed! 🐙 : d = 0 ∨ d = 1 ∨ d = 2) with rfl | rfl | rfl <;> inl.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3⊢ nSteps erdosTernary15 2 { state := 4, tape := { head := lo 0, left := ListBlank.cons (hi 0) L, right := R } } =
some
{ state := if 4 = 10 ∨ 0 = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi 0) (ListBlank.cons (lo 0) R)) }inl.inr.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3⊢ nSteps erdosTernary15 2 { state := 4, tape := { head := lo 1, left := ListBlank.cons (hi 1) L, right := R } } =
some
{ state := if 4 = 10 ∨ 1 = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi 1) (ListBlank.cons (lo 1) R)) }inl.inr.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3⊢ nSteps erdosTernary15 2 { state := 4, tape := { head := lo 2, left := ListBlank.cons (hi 2) L, right := R } } =
some
{ state := if 4 = 10 ∨ 2 = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi 2) (ListBlank.cons (lo 2) R)) }inr.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3⊢ nSteps erdosTernary15 2 { state := 10, tape := { head := lo 0, left := ListBlank.cons (hi 0) L, right := R } } =
some
{ state := if 10 = 10 ∨ 0 = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi 0) (ListBlank.cons (lo 0) R)) }inr.inr.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3⊢ nSteps erdosTernary15 2 { state := 10, tape := { head := lo 1, left := ListBlank.cons (hi 1) L, right := R } } =
some
{ state := if 10 = 10 ∨ 1 = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi 1) (ListBlank.cons (lo 1) R)) }inr.inr.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3⊢ nSteps erdosTernary15 2 { state := 10, tape := { head := lo 2, left := ListBlank.cons (hi 2) L, right := R } } =
some
{ state := if 10 = 10 ∨ 2 = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons (hi 2) (ListBlank.cons (lo 2) R)) }
tm_run inr.inr.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3⊢ some { state := 10, tape := Tape.mkL L (ListBlank.cons 1 (ListBlank.cons 1 R)) } =
some { state := if True ∨ True then 10 else 4, tape := Tape.mkL L (ListBlank.cons 1 (ListBlank.cons 1 R)) } <;> inl.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3⊢ some { state := 4, tape := Tape.mkL L (ListBlank.cons 0 (ListBlank.cons 1 R)) } =
some { state := if 4 = 10 ∨ 0 = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons 0 (ListBlank.cons 1 R)) }inl.inr.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3⊢ some { state := 4, tape := Tape.mkL L (ListBlank.cons 1 (ListBlank.cons 0 R)) } =
some { state := if 4 = 10 ∨ 1 = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons 1 (ListBlank.cons 0 R)) }inl.inr.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3⊢ some { state := 10, tape := Tape.mkL L (ListBlank.cons 1 (ListBlank.cons 1 R)) } =
some { state := if 4 = 10 ∨ True then 10 else 4, tape := Tape.mkL L (ListBlank.cons 1 (ListBlank.cons 1 R)) }inr.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:0 < 3⊢ some { state := 10, tape := Tape.mkL L (ListBlank.cons 0 (ListBlank.cons 1 R)) } =
some { state := if True ∨ 0 = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons 0 (ListBlank.cons 1 R)) }inr.inr.inl L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:1 < 3⊢ some { state := 10, tape := Tape.mkL L (ListBlank.cons 1 (ListBlank.cons 0 R)) } =
some { state := if True ∨ 1 = 2 then 10 else 4, tape := Tape.mkL L (ListBlank.cons 1 (ListBlank.cons 0 R)) }inr.inr.inr L:ListBlank (Fin 2)R:ListBlank (Fin 2)hd:2 < 3⊢ some { state := 10, tape := Tape.mkL L (ListBlank.cons 1 (ListBlank.cons 1 R)) } =
some { state := if True ∨ True then 10 else 4, tape := Tape.mkL L (ListBlank.cons 1 (ListBlank.cons 1 R)) } simp All goals completed! 🐙
Scanning left over ds from its most significant digit finds a 2 iff 2 ∈ ds; after a
2 the machine keeps moving left in the rewind states.
theorem find2_scan (ds : List ℕ) (hds : ∀ d ∈ ds, d < 3) (L R : ListBlank (Fin 2)) :
nSteps erdosTernary15 (2 * ds.length) ⟨4, Tape.mkL (ListBlank.append (encL ds) L) R⟩ =
some ⟨if 2 ∈ ds then 10 else 4, Tape.mkL L (ListBlank.append (encR ds) R)⟩ := by ds:List ℕhds:∀ d ∈ ds, d < 3L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }
induction ds generalizing L with
| nil => nil R:ListBlank (Fin 2)hds:∀ d ∈ [], d < 3L:ListBlank (Fin 2)⊢ nSteps erdosTernary15 (2 * [].length) { state := 4, tape := Tape.mkL (ListBlank.append (encL []) L) R } =
some { state := if 2 ∈ [] then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR []) R) } simp [encL, encR] All goals completed! 🐙
| cons d ds ih => cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)⊢ nSteps erdosTernary15 (2 * (d :: ds).length) { state := 4, tape := Tape.mkL (ListBlank.append (encL (d :: ds)) L) R } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) }
have hd := hds d (by R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)⊢ d ∈ d :: ds simp All goals completed! 🐙) cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3⊢ nSteps erdosTernary15 (2 * (d :: ds).length) { state := 4, tape := Tape.mkL (ListBlank.append (encL (d :: ds)) L) R } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) }
have h₁ := ih (fun x hx => hds x (by R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3x:ℕhx:x ∈ ds⊢ x ∈ d :: ds simp [hx] All goals completed! 🐙))
(ListBlank.append [lo d, hi d] L) cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }⊢ nSteps erdosTernary15 (2 * (d :: ds).length) { state := 4, tape := Tape.mkL (ListBlank.append (encL (d :: ds)) L) R } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) }
rw [show 2 * (d :: ds).length = 2 * ds.length + 2 by ds:List ℕhds:∀ d ∈ ds, d < 3L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) } rw [List.length_cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }⊢ 2 * (ds.length + 1) = 2 * ds.length + 2] R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }⊢ 2 * (ds.length + 1) = 2 * ds.length + 2; omega All goals completed! 🐙, encL, cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }⊢ nSteps erdosTernary15 (2 * ds.length + 2)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds ++ [lo d, hi d]) L) R } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) }
ListBlank.append_assoc, cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }⊢ nSteps erdosTernary15 (2 * ds.length + 2)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) } nSteps_add, cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }⊢ (nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R }).bind
(nSteps erdosTernary15 2) =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) } h₁, cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }⊢ (some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }).bind
(nSteps erdosTernary15 2) =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) } Option.bind_some cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }⊢ nSteps erdosTernary15 2
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) }] cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }⊢ nSteps erdosTernary15 2
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) }
have hq : (if 2 ∈ ds then (10 : Fin 15) else 4) = 4 ∨
(if 2 ∈ ds then (10 : Fin 15) else 4) = 10 := by ds:List ℕhds:∀ d ∈ ds, d < 3L:ListBlank (Fin 2)R:ListBlank (Fin 2)⊢ nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }
by_cases h : 2 ∈ ds pos R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }h:2 ∈ ds⊢ (if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10neg R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }h:2 ∉ ds⊢ (if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10 <;> pos R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }h:2 ∈ ds⊢ (if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10neg R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }h:2 ∉ ds⊢ (if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10 simp [h] cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10⊢ nSteps erdosTernary15 2
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) }
simp only [ListBlank.append, Tape.mkL_cons] cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10⊢ nSteps erdosTernary15 2
{ state := if 2 ∈ ds then 10 else 4,
tape := { head := lo d, left := ListBlank.cons (hi d) L, right := ListBlank.append (encR ds) R } } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) }
rw [pair_scan _ hq d hd cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10⊢ some
{ state := if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4,
tape := Tape.mkL L (ListBlank.cons (hi d) (ListBlank.cons (lo d) (ListBlank.append (encR ds) R))) } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) }] cons R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10⊢ some
{ state := if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4,
tape := Tape.mkL L (ListBlank.cons (hi d) (ListBlank.cons (lo d) (ListBlank.append (encR ds) R))) } =
some { state := if 2 ∈ d :: ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR (d :: ds)) R) }
congr 2 cons.e_state R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4
by_cases h₂ : 2 ∈ ds pos R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10h₂:2 ∈ ds⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4neg R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10h₂:2 ∉ ds⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4 <;> pos R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10h₂:2 ∈ ds⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4neg R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10h₂:2 ∉ ds⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4 by_cases hd₂ : d = 2 pos R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10h₂:2 ∉ dshd₂:d = 2⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4neg R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10h₂:2 ∉ dshd₂:¬d = 2⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4 <;> pos R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10h₂:2 ∈ dshd₂:d = 2⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4neg R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10h₂:2 ∈ dshd₂:¬d = 2⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4pos R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10h₂:2 ∉ dshd₂:d = 2⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4neg R:ListBlank (Fin 2)d:ℕds:List ℕih:(∀ d ∈ ds, d < 3) →
∀ (L : ListBlank (Fin 2)),
nSteps erdosTernary15 (2 * ds.length) { state := 4, tape := Tape.mkL (ListBlank.append (encL ds) L) R } =
some { state := if 2 ∈ ds then 10 else 4, tape := Tape.mkL L (ListBlank.append (encR ds) R) }hds:∀ d_1 ∈ d :: ds, d_1 < 3L:ListBlank (Fin 2)hd:d < 3h₁:nSteps erdosTernary15 (2 * ds.length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL ds) (ListBlank.append [lo d, hi d] L)) R } =
some
{ state := if 2 ∈ ds then 10 else 4,
tape := Tape.mkL (ListBlank.append [lo d, hi d] L) (ListBlank.append (encR ds) R) }hq:(if 2 ∈ ds then 10 else 4) = 4 ∨ (if 2 ∈ ds then 10 else 4) = 10h₂:2 ∉ dshd₂:¬d = 2⊢ (if (if 2 ∈ ds then 10 else 4) = 10 ∨ d = 2 then 10 else 4) = if 2 ∈ d :: ds then 10 else 4 simp [h₂, hd₂, eq_comm] All goals completed! 🐙
The # Cell and the Counter
theorem hash_rewind (c : ℕ) (R : ListBlank (Fin 2)) :
nSteps erdosTernary15 3 ⟨10, Tape.mkL (LH c) R⟩ = some ⟨1, Tape.mk' (LH c) R⟩ := by c:ℕR:ListBlank (Fin 2)⊢ nSteps erdosTernary15 3 { state := 10, tape := Tape.mkL (LH c) R } = some { state := 1, tape := Tape.mk' (LH c) R }
simp only [LH, ListBlank.append, Tape.mkL_cons] c:ℕR:ListBlank (Fin 2)⊢ nSteps erdosTernary15 3
{ state := 10,
tape :=
{ head := 0, left := ListBlank.cons 0 (ListBlank.cons (clo c) (ListBlank.cons (chi c) B0)), right := R } } =
some
{ state := 1,
tape := Tape.mk' (ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.cons (clo c) (ListBlank.cons (chi c) B0)))) R }
tm_run All goals completed! 🐙theorem hash_find (c : ℕ) (R : ListBlank (Fin 2)) :
nSteps erdosTernary15 2 ⟨4, Tape.mkL (LH c) R⟩ =
some ⟨13, Tape.mkL (ListBlank.append [clo c, chi c] B0) ((R.cons 0).cons 0)⟩ := by c:ℕR:ListBlank (Fin 2)⊢ nSteps erdosTernary15 2 { state := 4, tape := Tape.mkL (LH c) R } =
some { state := 13, tape := Tape.mkL (ListBlank.append [clo c, chi c] B0) (ListBlank.cons 0 (ListBlank.cons 0 R)) }
simp only [LH, ListBlank.append, Tape.mkL_cons] c:ℕR:ListBlank (Fin 2)⊢ nSteps erdosTernary15 2
{ state := 4,
tape :=
{ head := 0, left := ListBlank.cons 0 (ListBlank.cons (clo c) (ListBlank.cons (chi c) B0)), right := R } } =
some
{ state := 13,
tape := { head := clo c, left := ListBlank.cons (chi c) B0, right := ListBlank.cons 0 (ListBlank.cons 0 R) } }
tm_run All goals completed! 🐙theorem counter_inc (c : ℕ) (hc : c < 3) (R : ListBlank (Fin 2)) :
∃ s, nSteps erdosTernary15 s
⟨13, Tape.mkL (ListBlank.append [clo c, chi c] B0) ((R.cons 0).cons 0)⟩ =
some ⟨1, Tape.mk' (LH (c + 1)) R⟩ := by c:ℕhc:c < 3R:ListBlank (Fin 2)⊢ ∃ s,
nSteps erdosTernary15 s
{ state := 13, tape := Tape.mkL (ListBlank.append [clo c, chi c] B0) (ListBlank.cons 0 (ListBlank.cons 0 R)) } =
some { state := 1, tape := Tape.mk' (LH (c + 1)) R }
rcases (by c:ℕhc:c < 3R:ListBlank (Fin 2)⊢ c = 0 ∨ c = 1 ∨ c = 2 omega All goals completed! 🐙 : c = 0 ∨ c = 1 ∨ c = 2) with rfl | rfl | rfl
· inl R:ListBlank (Fin 2)hc:0 < 3⊢ ∃ s,
nSteps erdosTernary15 s
{ state := 13, tape := Tape.mkL (ListBlank.append [clo 0, chi 0] B0) (ListBlank.cons 0 (ListBlank.cons 0 R)) } =
some { state := 1, tape := Tape.mk' (LH (0 + 1)) R } exact ⟨3, by R:ListBlank (Fin 2)hc:0 < 3⊢ nSteps erdosTernary15 3
{ state := 13, tape := Tape.mkL (ListBlank.append [clo 0, chi 0] B0) (ListBlank.cons 0 (ListBlank.cons 0 R)) } =
some { state := 1, tape := Tape.mk' (LH (0 + 1)) R } simp only [LH, clo, chi, ListBlank.append, Tape.mkL_cons] R:ListBlank (Fin 2)hc:0 < 3⊢ nSteps erdosTernary15 3
{ state := 13,
tape := { head := 0, left := ListBlank.cons 0 B0, right := ListBlank.cons 0 (ListBlank.cons 0 R) } } =
some { state := 1, tape := Tape.mk' (ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.cons 1 (ListBlank.cons 0 B0)))) R }; tm_run All goals completed! 🐙⟩
· inr.inl R:ListBlank (Fin 2)hc:1 < 3⊢ ∃ s,
nSteps erdosTernary15 s
{ state := 13, tape := Tape.mkL (ListBlank.append [clo 1, chi 1] B0) (ListBlank.cons 0 (ListBlank.cons 0 R)) } =
some { state := 1, tape := Tape.mk' (LH (1 + 1)) R } exact ⟨5, by R:ListBlank (Fin 2)hc:1 < 3⊢ nSteps erdosTernary15 5
{ state := 13, tape := Tape.mkL (ListBlank.append [clo 1, chi 1] B0) (ListBlank.cons 0 (ListBlank.cons 0 R)) } =
some { state := 1, tape := Tape.mk' (LH (1 + 1)) R } simp only [LH, clo, chi, ListBlank.append, Tape.mkL_cons] R:ListBlank (Fin 2)hc:1 < 3⊢ nSteps erdosTernary15 5
{ state := 13,
tape := { head := 1, left := ListBlank.cons 0 B0, right := ListBlank.cons 0 (ListBlank.cons 0 R) } } =
some { state := 1, tape := Tape.mk' (ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.cons 1 B0)))) R }; tm_run All goals completed! 🐙⟩
· inr.inr R:ListBlank (Fin 2)hc:2 < 3⊢ ∃ s,
nSteps erdosTernary15 s
{ state := 13, tape := Tape.mkL (ListBlank.append [clo 2, chi 2] B0) (ListBlank.cons 0 (ListBlank.cons 0 R)) } =
some { state := 1, tape := Tape.mk' (LH (2 + 1)) R } exact ⟨3, by R:ListBlank (Fin 2)hc:2 < 3⊢ nSteps erdosTernary15 3
{ state := 13, tape := Tape.mkL (ListBlank.append [clo 2, chi 2] B0) (ListBlank.cons 0 (ListBlank.cons 0 R)) } =
some { state := 1, tape := Tape.mk' (LH (2 + 1)) R } simp only [LH, clo, chi, ListBlank.append, Tape.mkL_cons] R:ListBlank (Fin 2)hc:2 < 3⊢ nSteps erdosTernary15 3
{ state := 13,
tape := { head := 0, left := ListBlank.cons 1 B0, right := ListBlank.cons 0 (ListBlank.cons 0 R) } } =
some { state := 1, tape := Tape.mk' (ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.cons 1 (ListBlank.cons 1 B0)))) R }; tm_run All goals completed! 🐙⟩theorem counter_halt (R : ListBlank (Fin 2)) :
∃ cfg, nSteps erdosTernary15 1
⟨13, Tape.mkL (ListBlank.append [clo 3, chi 3] B0) ((R.cons 0).cons 0)⟩ = some cfg ∧
step erdosTernary15 cfg = none := by R:ListBlank (Fin 2)⊢ ∃ cfg,
nSteps erdosTernary15 1
{ state := 13, tape := Tape.mkL (ListBlank.append [clo 3, chi 3] B0) (ListBlank.cons 0 (ListBlank.cons 0 R)) } =
some cfg ∧
step erdosTernary15 cfg = none
refine ⟨⟨14, ⟨1, B0, (((R.cons 0).cons 0).cons 0)⟩⟩, ?_, s14_1 _ _⟩ R:ListBlank (Fin 2)⊢ nSteps erdosTernary15 1
{ state := 13, tape := Tape.mkL (ListBlank.append [clo 3, chi 3] B0) (ListBlank.cons 0 (ListBlank.cons 0 R)) } =
some
{ state := 14,
tape := { head := 1, left := B0, right := ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.cons 0 R)) } }
simp only [clo, chi, ListBlank.append, Tape.mkL_cons] R:ListBlank (Fin 2)⊢ nSteps erdosTernary15 1
{ state := 13,
tape := { head := 1, left := ListBlank.cons 1 B0, right := ListBlank.cons 0 (ListBlank.cons 0 R) } } =
some
{ state := 14,
tape := { head := 1, left := B0, right := ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.cons 0 R)) } }
tm_run All goals completed! 🐙Stages
theorem stage_scan (c n : ℕ) :
∃ s, nSteps erdosTernary15 s (stageCfg c n) = some
⟨if 2 ∈ pw (n + 1) then 10 else 4,
Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0)⟩ := by c:ℕn:ℕ⊢ ∃ s,
nSteps erdosTernary15 s (stageCfg c n) =
some
{ state := if 2 ∈ pw (n + 1) then 10 else 4, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }
obtain ⟨s₁, hs₁⟩ := mul2_pass (pw n) (pw_lt n) 0 (by c:ℕn:ℕ⊢ 0 ≤ 1 omega All goals completed! 🐙) (LH c) c:ℕn:ℕs₁:ℕhs₁:nSteps erdosTernary15 s₁ { state := st 0, tape := Tape.mk' (LH c) (ListBlank.append (encR (pw n)) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl (pw n) 0)) (LH c)) B0 }⊢ ∃ s,
nSteps erdosTernary15 s (stageCfg c n) =
some
{ state := if 2 ∈ pw (n + 1) then 10 else 4, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }
have h₂ := find2_scan (pw (n + 1)) (pw_lt (n + 1)) (LH c) B0 c:ℕn:ℕs₁:ℕhs₁:nSteps erdosTernary15 s₁ { state := st 0, tape := Tape.mk' (LH c) (ListBlank.append (encR (pw n)) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl (pw n) 0)) (LH c)) B0 }h₂:nSteps erdosTernary15 (2 * (pw (n + 1)).length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL (pw (n + 1))) (LH c)) B0 } =
some { state := if 2 ∈ pw (n + 1) then 10 else 4, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }⊢ ∃ s,
nSteps erdosTernary15 s (stageCfg c n) =
some
{ state := if 2 ∈ pw (n + 1) then 10 else 4, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }
exact ⟨s₁ + 2 * (pw (n + 1)).length, nSteps_bind_eq hs₁ h₂⟩ All goals completed! 🐙theorem stage_keep (c n : ℕ) (h : 2 ∈ pw (n + 1)) :
∃ s, 1 ≤ s ∧ nSteps erdosTernary15 s (stageCfg c n) = some (stageCfg c (n + 1)) := by c:ℕn:ℕh:2 ∈ pw (n + 1)⊢ ∃ s, 1 ≤ s ∧ nSteps erdosTernary15 s (stageCfg c n) = some (stageCfg c (n + 1))
obtain ⟨s₁, hs₁⟩ := stage_scan c n c:ℕn:ℕh:2 ∈ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ (stageCfg c n) =
some { state := if 2 ∈ pw (n + 1) then 10 else 4, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }⊢ ∃ s, 1 ≤ s ∧ nSteps erdosTernary15 s (stageCfg c n) = some (stageCfg c (n + 1))
simp only [h, ↓reduceIte] at hs₁ c:ℕn:ℕh:2 ∈ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ (stageCfg c n) =
some { state := 10, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }⊢ ∃ s, 1 ≤ s ∧ nSteps erdosTernary15 s (stageCfg c n) = some (stageCfg c (n + 1))
exact ⟨s₁ + 3, by c:ℕn:ℕh:2 ∈ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ (stageCfg c n) =
some { state := 10, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }⊢ 1 ≤ s₁ + 3 omega All goals completed! 🐙, nSteps_bind_eq hs₁ (hash_rewind c _)⟩theorem stage_inc (c n : ℕ) (hc : c < 3) (h : 2 ∉ pw (n + 1)) :
∃ s, 1 ≤ s ∧ nSteps erdosTernary15 s (stageCfg c n) = some (stageCfg (c + 1) (n + 1)) := by c:ℕn:ℕhc:c < 3h:2 ∉ pw (n + 1)⊢ ∃ s, 1 ≤ s ∧ nSteps erdosTernary15 s (stageCfg c n) = some (stageCfg (c + 1) (n + 1))
obtain ⟨s₁, hs₁⟩ := stage_scan c n c:ℕn:ℕhc:c < 3h:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ (stageCfg c n) =
some { state := if 2 ∈ pw (n + 1) then 10 else 4, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }⊢ ∃ s, 1 ≤ s ∧ nSteps erdosTernary15 s (stageCfg c n) = some (stageCfg (c + 1) (n + 1))
simp only [h, ↓reduceIte] at hs₁ c:ℕn:ℕhc:c < 3h:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ (stageCfg c n) =
some { state := 4, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }⊢ ∃ s, 1 ≤ s ∧ nSteps erdosTernary15 s (stageCfg c n) = some (stageCfg (c + 1) (n + 1))
obtain ⟨s₃, hs₃⟩ := counter_inc c hc (ListBlank.append (encR (pw (n + 1))) B0) c:ℕn:ℕhc:c < 3h:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ (stageCfg c n) =
some { state := 4, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }s₃:ℕhs₃:nSteps erdosTernary15 s₃
{ state := 13,
tape :=
Tape.mkL (ListBlank.append [clo c, chi c] B0)
(ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.append (encR (pw (n + 1))) B0))) } =
some { state := 1, tape := Tape.mk' (LH (c + 1)) (ListBlank.append (encR (pw (n + 1))) B0) }⊢ ∃ s, 1 ≤ s ∧ nSteps erdosTernary15 s (stageCfg c n) = some (stageCfg (c + 1) (n + 1))
exact ⟨s₁ + 2 + s₃, by c:ℕn:ℕhc:c < 3h:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ (stageCfg c n) =
some { state := 4, tape := Tape.mkL (LH c) (ListBlank.append (encR (pw (n + 1))) B0) }s₃:ℕhs₃:nSteps erdosTernary15 s₃
{ state := 13,
tape :=
Tape.mkL (ListBlank.append [clo c, chi c] B0)
(ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.append (encR (pw (n + 1))) B0))) } =
some { state := 1, tape := Tape.mk' (LH (c + 1)) (ListBlank.append (encR (pw (n + 1))) B0) }⊢ 1 ≤ s₁ + 2 + s₃ omega All goals completed! 🐙,
nSteps_bind_eq (nSteps_bind_eq hs₁ (hash_find c _)) hs₃⟩theorem stage_halt (n : ℕ) (h : 2 ∉ pw (n + 1)) :
∃ s cfg, nSteps erdosTernary15 s (stageCfg 3 n) = some cfg ∧
step erdosTernary15 cfg = none := by n:ℕh:2 ∉ pw (n + 1)⊢ ∃ s cfg, nSteps erdosTernary15 s (stageCfg 3 n) = some cfg ∧ step erdosTernary15 cfg = none
obtain ⟨s₁, hs₁⟩ := stage_scan 3 n n:ℕh:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ (stageCfg 3 n) =
some { state := if 2 ∈ pw (n + 1) then 10 else 4, tape := Tape.mkL (LH 3) (ListBlank.append (encR (pw (n + 1))) B0) }⊢ ∃ s cfg, nSteps erdosTernary15 s (stageCfg 3 n) = some cfg ∧ step erdosTernary15 cfg = none
simp only [h, ↓reduceIte] at hs₁ n:ℕh:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ (stageCfg 3 n) =
some { state := 4, tape := Tape.mkL (LH 3) (ListBlank.append (encR (pw (n + 1))) B0) }⊢ ∃ s cfg, nSteps erdosTernary15 s (stageCfg 3 n) = some cfg ∧ step erdosTernary15 cfg = none
obtain ⟨cfg, hcfg, hnone⟩ := counter_halt (ListBlank.append (encR (pw (n + 1))) B0) n:ℕh:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ (stageCfg 3 n) =
some { state := 4, tape := Tape.mkL (LH 3) (ListBlank.append (encR (pw (n + 1))) B0) }cfg:Cfg 15 2hcfg:nSteps erdosTernary15 1
{ state := 13,
tape :=
Tape.mkL (ListBlank.append [clo 3, chi 3] B0)
(ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.append (encR (pw (n + 1))) B0))) } =
some cfghnone:step erdosTernary15 cfg = none⊢ ∃ s cfg, nSteps erdosTernary15 s (stageCfg 3 n) = some cfg ∧ step erdosTernary15 cfg = none
exact ⟨s₁ + 2 + 1, cfg, nSteps_bind_eq (nSteps_bind_eq hs₁ (hash_find 3 _)) hcfg, hnone⟩ All goals completed! 🐙theorem init_eq : (init : Cfg 15 2) = ⟨st 1, Tape.mk' (LH 0) (ListBlank.append (encR []) B0)⟩ := by ⊢ init = { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) }
have : LH 0 = B0 := by simp [LH, chi, clo, ListBlank.append, B0_cons_zero] this:LH 0 = B0⊢ init = { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) }
rw [this this:LH 0 = B0⊢ init = { state := st 1, tape := Tape.mk' B0 (ListBlank.append (encR []) B0) }] this:LH 0 = B0⊢ init = { state := st 1, tape := Tape.mk' B0 (ListBlank.append (encR []) B0) }
rfl All goals completed! 🐙theorem boot : ∃ s, nSteps erdosTernary15 s init = some (stageCfg 1 0) := by ⊢ ∃ s, nSteps erdosTernary15 s init = some (stageCfg 1 0)
obtain ⟨s₁, hs₁⟩ := mul2_pass [] (by ⊢ ∀ d ∈ [], d < 3 simp All goals completed! 🐙) 1 (by ⊢ 1 ≤ 1 omega All goals completed! 🐙) (LH 0) s₁:ℕhs₁:nSteps erdosTernary15 s₁ { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 }⊢ ∃ s, nSteps erdosTernary15 s init = some (stageCfg 1 0)
have h₂ := find2_scan (dbl [] 1) (by s₁:ℕhs₁:nSteps erdosTernary15 s₁ { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 }⊢ ∀ d ∈ dbl [] 1, d < 3 simp [dbl] All goals completed! 🐙) (LH 0) B0 s₁:ℕhs₁:nSteps erdosTernary15 s₁ { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 }h₂:nSteps erdosTernary15 (2 * (dbl [] 1).length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 } =
some { state := if 2 ∈ dbl [] 1 then 10 else 4, tape := Tape.mkL (LH 0) (ListBlank.append (encR (dbl [] 1)) B0) }⊢ ∃ s, nSteps erdosTernary15 s init = some (stageCfg 1 0)
simp only [show 2 ∉ dbl [] 1 by simp [dbl], ↓reduceIte] at h₂ s₁:ℕhs₁:nSteps erdosTernary15 s₁ { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 }h₂:nSteps erdosTernary15 (2 * (dbl [] 1).length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 } =
some { state := 4, tape := Tape.mkL (LH 0) (ListBlank.append (encR (dbl [] 1)) B0) }⊢ ∃ s, nSteps erdosTernary15 s init = some (stageCfg 1 0)
obtain ⟨s₃, hs₃⟩ := counter_inc 0 (by s₁:ℕhs₁:nSteps erdosTernary15 s₁ { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 }h₂:nSteps erdosTernary15 (2 * (dbl [] 1).length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 } =
some { state := 4, tape := Tape.mkL (LH 0) (ListBlank.append (encR (dbl [] 1)) B0) }⊢ 0 < 3 omega All goals completed! 🐙) (ListBlank.append (encR (dbl [] 1)) B0) s₁:ℕhs₁:nSteps erdosTernary15 s₁ { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 }h₂:nSteps erdosTernary15 (2 * (dbl [] 1).length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 } =
some { state := 4, tape := Tape.mkL (LH 0) (ListBlank.append (encR (dbl [] 1)) B0) }s₃:ℕhs₃:nSteps erdosTernary15 s₃
{ state := 13,
tape :=
Tape.mkL (ListBlank.append [clo 0, chi 0] B0)
(ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.append (encR (dbl [] 1)) B0))) } =
some { state := 1, tape := Tape.mk' (LH (0 + 1)) (ListBlank.append (encR (dbl [] 1)) B0) }⊢ ∃ s, nSteps erdosTernary15 s init = some (stageCfg 1 0)
rw [init_eq s₁:ℕhs₁:nSteps erdosTernary15 s₁ { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 }h₂:nSteps erdosTernary15 (2 * (dbl [] 1).length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 } =
some { state := 4, tape := Tape.mkL (LH 0) (ListBlank.append (encR (dbl [] 1)) B0) }s₃:ℕhs₃:nSteps erdosTernary15 s₃
{ state := 13,
tape :=
Tape.mkL (ListBlank.append [clo 0, chi 0] B0)
(ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.append (encR (dbl [] 1)) B0))) } =
some { state := 1, tape := Tape.mk' (LH (0 + 1)) (ListBlank.append (encR (dbl [] 1)) B0) }⊢ ∃ s,
nSteps erdosTernary15 s { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) } =
some (stageCfg 1 0)] s₁:ℕhs₁:nSteps erdosTernary15 s₁ { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) } =
some { state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 }h₂:nSteps erdosTernary15 (2 * (dbl [] 1).length)
{ state := 4, tape := Tape.mkL (ListBlank.append (encL (dbl [] 1)) (LH 0)) B0 } =
some { state := 4, tape := Tape.mkL (LH 0) (ListBlank.append (encR (dbl [] 1)) B0) }s₃:ℕhs₃:nSteps erdosTernary15 s₃
{ state := 13,
tape :=
Tape.mkL (ListBlank.append [clo 0, chi 0] B0)
(ListBlank.cons 0 (ListBlank.cons 0 (ListBlank.append (encR (dbl [] 1)) B0))) } =
some { state := 1, tape := Tape.mk' (LH (0 + 1)) (ListBlank.append (encR (dbl [] 1)) B0) }⊢ ∃ s,
nSteps erdosTernary15 s { state := st 1, tape := Tape.mk' (LH 0) (ListBlank.append (encR []) B0) } =
some (stageCfg 1 0)
exact ⟨s₁ + _ + 2 + s₃,
nSteps_bind_eq (nSteps_bind_eq (nSteps_bind_eq hs₁ h₂) (hash_find 0 _)) hs₃⟩ All goals completed! 🐙
Counting Powers Without a Digit 2
theorem reach (n : ℕ) (hn : cnt n ≤ 3) :
∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n) := by n:ℕhn:cnt n ≤ 3⊢ ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)
induction n with
| zero => zero hn:cnt 0 ≤ 3⊢ ∃ s, 0 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt 0) 0)
obtain ⟨s, hs⟩ := boot zero hn:cnt 0 ≤ 3s:ℕhs:nSteps erdosTernary15 s init = some (stageCfg 1 0)⊢ ∃ s, 0 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt 0) 0)
exact ⟨s, Nat.zero_le s, hs⟩ All goals completed! 🐙
| succ n ih => succ n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt (n + 1) ≤ 3⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt (n + 1)) (n + 1))
by_cases h : 2 ∈ pw (n + 1) pos n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt (n + 1) ≤ 3h:2 ∈ pw (n + 1)⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt (n + 1)) (n + 1))neg n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt (n + 1) ≤ 3h:2 ∉ pw (n + 1)⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt (n + 1)) (n + 1))
· pos n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt (n + 1) ≤ 3h:2 ∈ pw (n + 1)⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt (n + 1)) (n + 1)) rw [cnt_succ_of_mem h pos n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n ≤ 3h:2 ∈ pw (n + 1)⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) (n + 1))] at hn ⊢ pos n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n ≤ 3h:2 ∈ pw (n + 1)⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) (n + 1))
obtain ⟨s₁, hs₁n, hs₁⟩ := ih hn pos n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n ≤ 3h:2 ∈ pw (n + 1)s₁:ℕhs₁n:n ≤ s₁hs₁:nSteps erdosTernary15 s₁ init = some (stageCfg (cnt n) n)⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) (n + 1))
obtain ⟨s₂, hs₂1, hs₂⟩ := stage_keep (cnt n) n h pos n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n ≤ 3h:2 ∈ pw (n + 1)s₁:ℕhs₁n:n ≤ s₁hs₁:nSteps erdosTernary15 s₁ init = some (stageCfg (cnt n) n)s₂:ℕhs₂1:1 ≤ s₂hs₂:nSteps erdosTernary15 s₂ (stageCfg (cnt n) n) = some (stageCfg (cnt n) (n + 1))⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) (n + 1))
exact ⟨s₁ + s₂, by n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n ≤ 3h:2 ∈ pw (n + 1)s₁:ℕhs₁n:n ≤ s₁hs₁:nSteps erdosTernary15 s₁ init = some (stageCfg (cnt n) n)s₂:ℕhs₂1:1 ≤ s₂hs₂:nSteps erdosTernary15 s₂ (stageCfg (cnt n) n) = some (stageCfg (cnt n) (n + 1))⊢ n + 1 ≤ s₁ + s₂ omega All goals completed! 🐙, nSteps_bind_eq hs₁ hs₂⟩
· neg n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt (n + 1) ≤ 3h:2 ∉ pw (n + 1)⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt (n + 1)) (n + 1)) rw [cnt_succ_of_not_mem h neg n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n + 1 ≤ 3h:2 ∉ pw (n + 1)⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n + 1) (n + 1))] at hn ⊢ neg n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n + 1 ≤ 3h:2 ∉ pw (n + 1)⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n + 1) (n + 1))
obtain ⟨s₁, hs₁n, hs₁⟩ := ih (by n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n + 1 ≤ 3h:2 ∉ pw (n + 1)⊢ cnt n ≤ 3 omega All goals completed! 🐙) neg n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n + 1 ≤ 3h:2 ∉ pw (n + 1)s₁:ℕhs₁n:n ≤ s₁hs₁:nSteps erdosTernary15 s₁ init = some (stageCfg (cnt n) n)⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n + 1) (n + 1))
obtain ⟨s₂, hs₂1, hs₂⟩ := stage_inc (cnt n) n (by n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n + 1 ≤ 3h:2 ∉ pw (n + 1)s₁:ℕhs₁n:n ≤ s₁hs₁:nSteps erdosTernary15 s₁ init = some (stageCfg (cnt n) n)⊢ cnt n < 3 omega All goals completed! 🐙) h neg n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n + 1 ≤ 3h:2 ∉ pw (n + 1)s₁:ℕhs₁n:n ≤ s₁hs₁:nSteps erdosTernary15 s₁ init = some (stageCfg (cnt n) n)s₂:ℕhs₂1:1 ≤ s₂hs₂:nSteps erdosTernary15 s₂ (stageCfg (cnt n) n) = some (stageCfg (cnt n + 1) (n + 1))⊢ ∃ s, n + 1 ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n + 1) (n + 1))
exact ⟨s₁ + s₂, by n:ℕih:cnt n ≤ 3 → ∃ s, n ≤ s ∧ nSteps erdosTernary15 s init = some (stageCfg (cnt n) n)hn:cnt n + 1 ≤ 3h:2 ∉ pw (n + 1)s₁:ℕhs₁n:n ≤ s₁hs₁:nSteps erdosTernary15 s₁ init = some (stageCfg (cnt n) n)s₂:ℕhs₂1:1 ≤ s₂hs₂:nSteps erdosTernary15 s₂ (stageCfg (cnt n) n) = some (stageCfg (cnt n + 1) (n + 1))⊢ n + 1 ≤ s₁ + s₂ omega All goals completed! 🐙, nSteps_bind_eq hs₁ hs₂⟩theorem halt_of (n : ℕ) (h3 : cnt n = 3) (h : 2 ∉ pw (n + 1)) :
∃ s cfg, nSteps erdosTernary15 s init = some cfg ∧ step erdosTernary15 cfg = none := by n:ℕh3:cnt n = 3h:2 ∉ pw (n + 1)⊢ ∃ s cfg, nSteps erdosTernary15 s init = some cfg ∧ step erdosTernary15 cfg = none
obtain ⟨s₁, -, hs₁⟩ := reach n (by n:ℕh3:cnt n = 3h:2 ∉ pw (n + 1)⊢ cnt n ≤ 3 omega All goals completed! 🐙) n:ℕh3:cnt n = 3h:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ init = some (stageCfg (cnt n) n)⊢ ∃ s cfg, nSteps erdosTernary15 s init = some cfg ∧ step erdosTernary15 cfg = none
rw [h3 n:ℕh3:cnt n = 3h:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ init = some (stageCfg 3 n)⊢ ∃ s cfg, nSteps erdosTernary15 s init = some cfg ∧ step erdosTernary15 cfg = none] at hs₁ n:ℕh3:cnt n = 3h:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ init = some (stageCfg 3 n)⊢ ∃ s cfg, nSteps erdosTernary15 s init = some cfg ∧ step erdosTernary15 cfg = none
obtain ⟨s₂, cfg, hs₂, hnone⟩ := stage_halt n h n:ℕh3:cnt n = 3h:2 ∉ pw (n + 1)s₁:ℕhs₁:nSteps erdosTernary15 s₁ init = some (stageCfg 3 n)s₂:ℕcfg:Cfg 15 2hs₂:nSteps erdosTernary15 s₂ (stageCfg 3 n) = some cfghnone:step erdosTernary15 cfg = none⊢ ∃ s cfg, nSteps erdosTernary15 s init = some cfg ∧ step erdosTernary15 cfg = none
exact ⟨s₁ + s₂, cfg, nSteps_bind_eq hs₁ hs₂, hnone⟩ All goals completed! 🐙theorem cnt_stays (K : ℕ) (hK : 8 ≤ K) (hall : ∀ m, 8 < m → m ≤ K → 2 ∈ pw m) : cnt K = 3 := by K:ℕhK:8 ≤ Khall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw m⊢ cnt K = 3
induction K, hK using Nat.le_induction with
| base => base K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ 8 → 2 ∈ pw m⊢ cnt 8 = 3 exact cnt_eight All goals completed! 🐙
| succ K hK ih => succ K✝:ℕK:ℕhK:8 ≤ Kih:(∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw m) → cnt K = 3hall:∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m⊢ cnt (K + 1) = 3
rw [cnt_succ_of_mem (hall (K + 1) (by K✝:ℕK:ℕhK:8 ≤ Kih:(∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw m) → cnt K = 3hall:∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m⊢ 8 < K + 1 omega All goals completed! 🐙) le_rfl)] succ K✝:ℕK:ℕhK:8 ≤ Kih:(∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw m) → cnt K = 3hall:∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m⊢ cnt K = 3
exact ih fun m hm hmK => hall m hm (by K✝:ℕK:ℕhK:8 ≤ Kih:(∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw m) → cnt K = 3hall:∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw mm:ℕhm:8 < mhmK:m ≤ K⊢ m ≤ K + 1 omega All goals completed! 🐙)theorem first_free (n : ℕ) (h8 : 8 < n) (h : 2 ∉ pw n) :
∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1) := by n:ℕh8:8 < nh:2 ∉ pw n⊢ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)
have key : ∀ j, 8 ≤ j → cnt j = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1) := by
intro j hj n:ℕh8:8 < nh:2 ∉ pw nj:ℕhj:8 ≤ j⊢ cnt j = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)
induction j, hj using Nat.le_induction with
| base => base n:ℕh8:8 < nh:2 ∉ pw nj:ℕ⊢ cnt 8 = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1) exact Or.inl cnt_eight All goals completed! 🐙
| succ j _ ih => succ n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jih:cnt j = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)⊢ cnt (j + 1) = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)
rcases ih with h3 | hm succ.inl n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jh3:cnt j = 3⊢ cnt (j + 1) = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)succ.inr n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jhm:∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)⊢ cnt (j + 1) = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)
· succ.inl n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jh3:cnt j = 3⊢ cnt (j + 1) = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1) by_cases hj2 : 2 ∈ pw (j + 1) pos n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jh3:cnt j = 3hj2:2 ∈ pw (j + 1)⊢ cnt (j + 1) = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)neg n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jh3:cnt j = 3hj2:2 ∉ pw (j + 1)⊢ cnt (j + 1) = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)
· pos n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jh3:cnt j = 3hj2:2 ∈ pw (j + 1)⊢ cnt (j + 1) = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1) exact Or.inl (by n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jh3:cnt j = 3hj2:2 ∈ pw (j + 1)⊢ cnt (j + 1) = 3 rw [cnt_succ_of_mem hj2, n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jh3:cnt j = 3hj2:2 ∈ pw (j + 1)⊢ cnt j = 3 h3 n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jh3:cnt j = 3hj2:2 ∈ pw (j + 1)⊢ 3 = 3] All goals completed! 🐙)
· neg n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jh3:cnt j = 3hj2:2 ∉ pw (j + 1)⊢ cnt (j + 1) = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1) exact Or.inr ⟨j, h3, hj2⟩ All goals completed! 🐙
· succ.inr n:ℕh8:8 < nh:2 ∉ pw nj✝:ℕj:ℕhmn✝:8 ≤ jhm:∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)⊢ cnt (j + 1) = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1) exact Or.inr hm n:ℕh8:8 < nh:2 ∉ pw nkey:∀ (j : ℕ), 8 ≤ j → cnt j = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)⊢ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)
rcases key (n - 1) (by n:ℕh8:8 < nh:2 ∉ pw nkey:∀ (j : ℕ), 8 ≤ j → cnt j = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)⊢ 8 ≤ n - 1 omega All goals completed! 🐙) with h3 | hm
· inl n:ℕh8:8 < nh:2 ∉ pw nkey:∀ (j : ℕ), 8 ≤ j → cnt j = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)h3:cnt (n - 1) = 3⊢ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1) exact ⟨n - 1, h3, by n:ℕh8:8 < nh:2 ∉ pw nkey:∀ (j : ℕ), 8 ≤ j → cnt j = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)h3:cnt (n - 1) = 3⊢ 2 ∉ pw (n - 1 + 1) rwa [Nat.sub_add_cancel (by n:ℕh8:8 < nh:2 ∉ pw nkey:∀ (j : ℕ), 8 ≤ j → cnt j = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)h3:cnt (n - 1) = 3⊢ 1 ≤ n omega All goals completed! 🐙)]⟩
· inr n:ℕh8:8 < nh:2 ∉ pw nkey:∀ (j : ℕ), 8 ≤ j → cnt j = 3 ∨ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)hm:∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1)⊢ ∃ m, cnt m = 3 ∧ 2 ∉ pw (m + 1) exact hm All goals completed! 🐙theorem free_or_none (K : ℕ) :
(∃ m, 8 < m ∧ m ≤ K ∧ 2 ∉ pw m) ∨ (∀ m, 8 < m → m ≤ K → 2 ∈ pw m) := by K:ℕ⊢ (∃ m, 8 < m ∧ m ≤ K ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw m
induction K with
| zero => zero ⊢ (∃ m, 8 < m ∧ m ≤ 0 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ 0 → 2 ∈ pw m exact Or.inr fun m hm hmK => absurd hmK (by m:ℕhm:8 < mhmK:m ≤ 0⊢ ¬m ≤ 0 omega All goals completed! 🐙)
| succ K ih => succ K:ℕih:(∃ m, 8 < m ∧ m ≤ K ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw m⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m
rcases ih with ⟨m, hm, hmK, hfree⟩ | hall succ.inl K:ℕm:ℕhm:8 < mhmK:m ≤ Khfree:2 ∉ pw m⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw msucc.inr K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw m⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m
· succ.inl K:ℕm:ℕhm:8 < mhmK:m ≤ Khfree:2 ∉ pw m⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m exact Or.inl ⟨m, hm, by K:ℕm:ℕhm:8 < mhmK:m ≤ Khfree:2 ∉ pw m⊢ m ≤ K + 1 omega All goals completed! 🐙, hfree⟩
· succ.inr K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw m⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m by_cases h : 2 ∈ pw (K + 1) pos K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∈ pw (K + 1)⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw mneg K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∉ pw (K + 1)⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m
· pos K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∈ pw (K + 1)⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m refine Or.inr fun m hm hmK => ?_ pos K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∈ pw (K + 1)m:ℕhm:8 < mhmK:m ≤ K + 1⊢ 2 ∈ pw m
rcases (by K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∈ pw (K + 1)m:ℕhm:8 < mhmK:m ≤ K + 1⊢ m ≤ K ∨ m = K + 1 omega All goals completed! 🐙 : m ≤ K ∨ m = K + 1) with hmK' | rfl
· pos.inl K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∈ pw (K + 1)m:ℕhm:8 < mhmK:m ≤ K + 1hmK':m ≤ K⊢ 2 ∈ pw m exact hall m hm hmK' All goals completed! 🐙
· pos.inr K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∈ pw (K + 1)hm:8 < K + 1hmK:K + 1 ≤ K + 1⊢ 2 ∈ pw (K + 1) exact h All goals completed! 🐙
· neg K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∉ pw (K + 1)⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m by_cases hK : 8 < K + 1 pos K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∉ pw (K + 1)hK:8 < K + 1⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw mneg K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∉ pw (K + 1)hK:¬8 < K + 1⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m
· pos K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∉ pw (K + 1)hK:8 < K + 1⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m exact Or.inl ⟨K + 1, hK, le_rfl, h⟩ All goals completed! 🐙
· neg K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∉ pw (K + 1)hK:¬8 < K + 1⊢ (∃ m, 8 < m ∧ m ≤ K + 1 ∧ 2 ∉ pw m) ∨ ∀ (m : ℕ), 8 < m → m ≤ K + 1 → 2 ∈ pw m exact Or.inr fun m hm hmK => absurd hm (by K:ℕhall:∀ (m : ℕ), 8 < m → m ≤ K → 2 ∈ pw mh:2 ∉ pw (K + 1)hK:¬8 < K + 1m:ℕhm:8 < mhmK:m ≤ K + 1⊢ ¬8 < m omega All goals completed! 🐙)Halting Equivalence
The 15-state machine erdosTernary15 (erdos_ternary_15) halts on the blank tape if and only
if some power 2 ^ n with n > 8 has no digit 2 in base 3, with the digits computed by pw.
theorem halts_erdosTernary15_iff_exists_free :
ConjectureMachines.Halts erdosTernary15 ↔ ∃ n, 8 < n ∧ 2 ∉ pw n := by ⊢ ConjectureMachines.Halts erdosTernary15 ↔ ∃ n, 8 < n ∧ 2 ∉ pw n
unfold ConjectureMachines.Halts ⊢ (eval (step erdosTernary15) init).Dom ↔ ∃ n, 8 < n ∧ 2 ∉ pw n
constructor mp ⊢ (eval (step erdosTernary15) init).Dom → ∃ n, 8 < n ∧ 2 ∉ pw nmpr ⊢ (∃ n, 8 < n ∧ 2 ∉ pw n) → (eval (step erdosTernary15) init).Dom
· mp ⊢ (eval (step erdosTernary15) init).Dom → ∃ n, 8 < n ∧ 2 ∉ pw n intro hdom mp hdom:(eval (step erdosTernary15) init).Dom⊢ ∃ n, 8 < n ∧ 2 ∉ pw n
rw [Part.dom_iff_mem mp hdom:∃ y, y ∈ eval (step erdosTernary15) init⊢ ∃ n, 8 < n ∧ 2 ∉ pw n] at hdom mp hdom:∃ y, y ∈ eval (step erdosTernary15) init⊢ ∃ n, 8 < n ∧ 2 ∉ pw n
obtain ⟨b, hb⟩ := hdom mp b:Cfg 15 2hb:b ∈ eval (step erdosTernary15) init⊢ ∃ n, 8 < n ∧ 2 ∉ pw n
rw [mem_eval' mp b:Cfg 15 2hb:Reaches (step erdosTernary15) init b ∧ step erdosTernary15 b = none⊢ ∃ n, 8 < n ∧ 2 ∉ pw n] at hb mp b:Cfg 15 2hb:Reaches (step erdosTernary15) init b ∧ step erdosTernary15 b = none⊢ ∃ n, 8 < n ∧ 2 ∉ pw n
obtain ⟨hreach, hnone⟩ := hb mp b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = none⊢ ∃ n, 8 < n ∧ 2 ∉ pw n
obtain ⟨k, hk⟩ := reaches_imp_nSteps hreach mp b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some b⊢ ∃ n, 8 < n ∧ 2 ∉ pw n
rcases free_or_none (k + 9) with ⟨m, hm, -, hfree⟩ | hall mp.inl b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some bm:ℕhm:8 < mhfree:2 ∉ pw m⊢ ∃ n, 8 < n ∧ 2 ∉ pw nmp.inr b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some bhall:∀ (m : ℕ), 8 < m → m ≤ k + 9 → 2 ∈ pw m⊢ ∃ n, 8 < n ∧ 2 ∉ pw n
· mp.inl b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some bm:ℕhm:8 < mhfree:2 ∉ pw m⊢ ∃ n, 8 < n ∧ 2 ∉ pw n exact ⟨m, hm, hfree⟩ All goals completed! 🐙
· mp.inr b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some bhall:∀ (m : ℕ), 8 < m → m ≤ k + 9 → 2 ∈ pw m⊢ ∃ n, 8 < n ∧ 2 ∉ pw n have h3 := cnt_stays (k + 9) (by b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some bhall:∀ (m : ℕ), 8 < m → m ≤ k + 9 → 2 ∈ pw m⊢ 8 ≤ k + 9 omega All goals completed! 🐙) hall mp.inr b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some bhall:∀ (m : ℕ), 8 < m → m ≤ k + 9 → 2 ∈ pw mh3:cnt (k + 9) = 3⊢ ∃ n, 8 < n ∧ 2 ∉ pw n
obtain ⟨s, hks, hs⟩ := reach (k + 9) (by b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some bhall:∀ (m : ℕ), 8 < m → m ≤ k + 9 → 2 ∈ pw mh3:cnt (k + 9) = 3⊢ cnt (k + 9) ≤ 3 omega All goals completed! 🐙) mp.inr b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some bhall:∀ (m : ℕ), 8 < m → m ≤ k + 9 → 2 ∈ pw mh3:cnt (k + 9) = 3s:ℕhks:k + 9 ≤ shs:nSteps erdosTernary15 s init = some (stageCfg (cnt (k + 9)) (k + 9))⊢ ∃ n, 8 < n ∧ 2 ∉ pw n
rw [nSteps_eq_none_of_step_none s hk hnone (by b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some bhall:∀ (m : ℕ), 8 < m → m ≤ k + 9 → 2 ∈ pw mh3:cnt (k + 9) = 3s:ℕhks:k + 9 ≤ shs:nSteps erdosTernary15 s init = some (stageCfg (cnt (k + 9)) (k + 9))⊢ k < s omega All goals completed! 🐙)] at hs mp.inr b:Cfg 15 2hreach:Reaches (step erdosTernary15) init bhnone:step erdosTernary15 b = nonek:ℕhk:nSteps erdosTernary15 k init = some bhall:∀ (m : ℕ), 8 < m → m ≤ k + 9 → 2 ∈ pw mh3:cnt (k + 9) = 3s:ℕhks:k + 9 ≤ shs:none = some (stageCfg (cnt (k + 9)) (k + 9))⊢ ∃ n, 8 < n ∧ 2 ∉ pw n
cases hs All goals completed! 🐙
· mpr ⊢ (∃ n, 8 < n ∧ 2 ∉ pw n) → (eval (step erdosTernary15) init).Dom rintro ⟨n, h8, hfree⟩ mpr n:ℕh8:8 < nhfree:2 ∉ pw n⊢ (eval (step erdosTernary15) init).Dom
obtain ⟨m, h3, hm⟩ := first_free n h8 hfree mpr n:ℕh8:8 < nhfree:2 ∉ pw nm:ℕh3:cnt m = 3hm:2 ∉ pw (m + 1)⊢ (eval (step erdosTernary15) init).Dom
obtain ⟨s, cfg, hs, hnone⟩ := halt_of m h3 hm mpr n:ℕh8:8 < nhfree:2 ∉ pw nm:ℕh3:cnt m = 3hm:2 ∉ pw (m + 1)s:ℕcfg:Cfg 15 2hs:nSteps erdosTernary15 s init = some cfghnone:step erdosTernary15 cfg = none⊢ (eval (step erdosTernary15) init).Dom
rw [Part.dom_iff_mem mpr n:ℕh8:8 < nhfree:2 ∉ pw nm:ℕh3:cnt m = 3hm:2 ∉ pw (m + 1)s:ℕcfg:Cfg 15 2hs:nSteps erdosTernary15 s init = some cfghnone:step erdosTernary15 cfg = none⊢ ∃ y, y ∈ eval (step erdosTernary15) init] mpr n:ℕh8:8 < nhfree:2 ∉ pw nm:ℕh3:cnt m = 3hm:2 ∉ pw (m + 1)s:ℕcfg:Cfg 15 2hs:nSteps erdosTernary15 s init = some cfghnone:step erdosTernary15 cfg = none⊢ ∃ y, y ∈ eval (step erdosTernary15) init
exact ⟨cfg, mem_eval'.mpr ⟨nSteps_reaches hs, hnone⟩⟩ All goals completed! 🐙end ConjectureMachines.ErdosTernary15