Imports
/-
Copyright (c) 2026 Terence Rokop. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Terence Rokop
-/
module
public import Geb.Prototypes.Computability.BitTree.BinaryMachine.Carry
public import Geb.Prototypes.Computability.BitTree.BinaryMachine.Return
public import Geb.Prototypes.Computability.BitTree.BinaryMachine.Representationset_option doc.verso trueComplete counter increments
A carry followed by the return is one counter increment. The marker and mismatch invariants connect its final state to equality of the represented counter values.
Main statements
-
configs_carry_invariantsmaintains marker and mismatch invariants. -
configs_incrementimplements one increment in twice its bit-change count plus one step. -
configs_increment_head_boundsbounds every visited work-tape position.
Tags
Turing machine, simulation, binary counter
@[expose] public sectionnamespace Geb.BitTree.BinaryMachineopen Turing MultiTapeTMThe marker and mismatch invariants survive every carry prefix, including its last step.
theorem configs_carry_invariants {input : List (Fin 4)}
(cfg : Cfg 3 (Fin 4) (Fin 10) input) (leaf : Bool) (p k width : ℕ)
(hq : cfg.state = some (if leaf then stCarryLeaf else stCarryFork))
(hp0 : cfg.workTapePos 0 = p) (hp1 : cfg.workTapePos 1 = p)
(hones : ∀ j < k, digits cfg (if leaf then 1 else 0) (p + j) = true)
(hw : p + k < width)
(hm : cfg.workTapePos 2 = (mismatchCount width (digits cfg 0) (digits cfg 1) : ℤ))
(t : ℕ) (ht : t ≤ k + 1) :
let now := machine.configs cfg t
(∀ z, origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧
now.workTapePos 2 = (mismatchCount width (digits now 0) (digits now 1) : ℤ) := input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕht:t ≤ k + 1⊢ let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))
input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕ⊢ t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))
input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕ⊢ Nat.zero ≤ k + 1 →
let now := configs cfg Nat.zero;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕ⊢ ∀ (n : ℕ),
(n ≤ k + 1 →
let now := configs cfg n;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))) →
n.succ ≤ k + 1 →
let now := configs cfg n.succ;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))
input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕ⊢ Nat.zero ≤ k + 1 →
let now := configs cfg Nat.zero;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1)) input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕa✝:Nat.zero ≤ k + 1⊢ let now := configs cfg Nat.zero;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))
All goals completed! 🐙
input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕ⊢ ∀ (n : ℕ),
(n ≤ k + 1 →
let now := configs cfg n;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))) →
n.succ ≤ k + 1 →
let now := configs cfg n.succ;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1)) input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1⊢ let now := configs cfg t.succ;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))
input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))⊢ let now := configs cfg t.succ;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))
obtain ⟨hstate, hpos0, hpos1, _⟩ :=
configs_carry_prefix cfg leaf p k hq hp0 hp1 hones t (by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))⊢ t ≤ k omega All goals completed! 🐙) input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ let now := configs cfg t.succ;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))
rw [configs_succ_eq_step' input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ let now := MultiTapeTM.step (configs cfg t);
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ let now := MultiTapeTM.step (configs cfg t);
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))
refine ⟨?_, ?_, ?_⟩ refine_1 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ ∀ (z : ℤ), origin ((MultiTapeTM.step (configs cfg t)).workTapes 0 z) = origin (cfg.workTapes 0 z)refine_2 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ (MultiTapeTM.step (configs cfg t)).workTapes 2 = cfg.workTapes 2refine_3 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ (MultiTapeTM.step (configs cfg t)).workTapePos 2 =
↑(mismatchCount width (digits (MultiTapeTM.step (configs cfg t)) 0) (digits (MultiTapeTM.step (configs cfg t)) 1))
· refine_1 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ ∀ (z : ℤ), origin ((MultiTapeTM.step (configs cfg t)).workTapes 0 z) = origin (cfg.workTapes 0 z) intro z refine_1 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)z:ℤ⊢ origin ((MultiTapeTM.step (configs cfg t)).workTapes 0 z) = origin (cfg.workTapes 0 z)
rw [step_carry_origin _ leaf z hstate, refine_1 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)z:ℤ⊢ origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z) ho refine_1 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)z:ℤ⊢ origin (cfg.workTapes 0 z) = origin (cfg.workTapes 0 z)] All goals completed! 🐙
· refine_2 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ (MultiTapeTM.step (configs cfg t)).workTapes 2 = cfg.workTapes 2 rw [step_carry_marker _ leaf hstate, refine_2 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ (configs cfg t).workTapes 2 = cfg.workTapes 2 hmark refine_2 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ cfg.workTapes 2 = cfg.workTapes 2] All goals completed! 🐙
· refine_3 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ (MultiTapeTM.step (configs cfg t)).workTapePos 2 =
↑(mismatchCount width (digits (MultiTapeTM.step (configs cfg t)) 0) (digits (MultiTapeTM.step (configs cfg t)) 1)) exact step_carry_mismatch _ leaf width (p + t) hstate hpos0 hpos1 (by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolp:ℕk:ℕwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = ↑php1:cfg.workTapePos 1 = ↑phones:∀ j < k, digits cfg (if leaf = true then 1 else 0) (p + j) = truehw:p + k < widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t✝:ℕt:ℕih:t ≤ k + 1 →
let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))ht:t.succ ≤ k + 1ho:∀ (z : ℤ), origin ((configs cfg t).workTapes 0 z) = origin (cfg.workTapes 0 z)hmark:(configs cfg t).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hstate:(configs cfg t).state = some (if leaf = true then stCarryLeaf else stCarryFork)hpos0:(configs cfg t).workTapePos 0 = ↑(p + t)hpos1:(configs cfg t).workTapePos 1 = ↑(p + t)right✝:(configs cfg t).inputPos = cfg.inputPos ∧
(digits (configs cfg t) (if leaf = true then 1 else 0) = fun j ↦
if p ≤ j ∧ j < p + t then false else digits cfg (if leaf = true then 1 else 0) j) ∧
digits (configs cfg t) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)⊢ p + t < width omega All goals completed! 🐙) hmismatchMarker and mismatch invariants throughout the carry of a represented bit list.
theorem configs_carry_bits_invariants {input : List (Fin 4)}
(cfg : Cfg 3 (Fin 4) (Fin 10) input) (leaf : Bool) (bs : List Bool) (width : ℕ)
(hq : cfg.state = some (if leaf then stCarryLeaf else stCarryFork))
(hp0 : cfg.workTapePos 0 = 0) (hp1 : cfg.workTapePos 1 = 0)
(hbits : ∀ j, digits cfg (if leaf then 1 else 0) j = bs[j]?.getD false)
(hw : Counter.flips bs ≤ width)
(hm : cfg.workTapePos 2 = (mismatchCount width (digits cfg 0) (digits cfg 1) : ℤ))
(t : ℕ) (ht : t ≤ Counter.flips bs) :
let now := machine.configs cfg t
(∀ z, origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧
now.workTapePos 2 = (mismatchCount width (digits now 0) (digits now 1) : ℤ) := by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolbs:List Boolwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = 0hp1:cfg.workTapePos 1 = 0hbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = bs[j]?.getD falsehw:Counter.flips bs ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕht:t ≤ Counter.flips bs⊢ let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))
have hpos := Counter.flips_pos bs input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolbs:List Boolwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = 0hp1:cfg.workTapePos 1 = 0hbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = bs[j]?.getD falsehw:Counter.flips bs ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕht:t ≤ Counter.flips bshpos:0 < Counter.flips bs⊢ let now := configs cfg t;
(∀ (z : ℤ), origin (now.workTapes 0 z) = origin (cfg.workTapes 0 z)) ∧
now.workTapes 2 = cfg.workTapes 2 ∧ now.workTapePos 2 = ↑(mismatchCount width (digits now 0) (digits now 1))
apply configs_carry_invariants cfg leaf 0 (Counter.flips bs - 1) width
hq hp0 hp1 ?_ (by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolbs:List Boolwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = 0hp1:cfg.workTapePos 1 = 0hbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = bs[j]?.getD falsehw:Counter.flips bs ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕht:t ≤ Counter.flips bshpos:0 < Counter.flips bs⊢ 0 + (Counter.flips bs - 1) < width omega All goals completed! 🐙) hm t (by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolbs:List Boolwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = 0hp1:cfg.workTapePos 1 = 0hbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = bs[j]?.getD falsehw:Counter.flips bs ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕht:t ≤ Counter.flips bshpos:0 < Counter.flips bs⊢ t ≤ Counter.flips bs - 1 + 1 omega All goals completed! 🐙)
intro j hj input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolbs:List Boolwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = 0hp1:cfg.workTapePos 1 = 0hbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = bs[j]?.getD falsehw:Counter.flips bs ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕht:t ≤ Counter.flips bshpos:0 < Counter.flips bsj:ℕhj:j < Counter.flips bs - 1⊢ digits cfg (if leaf = true then 1 else 0) (0 + j) = true
rw [Nat.zero_add, input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolbs:List Boolwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = 0hp1:cfg.workTapePos 1 = 0hbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = bs[j]?.getD falsehw:Counter.flips bs ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕht:t ≤ Counter.flips bshpos:0 < Counter.flips bsj:ℕhj:j < Counter.flips bs - 1⊢ digits cfg (if leaf = true then 1 else 0) j = true hbits input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolbs:List Boolwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = 0hp1:cfg.workTapePos 1 = 0hbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = bs[j]?.getD falsehw:Counter.flips bs ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕht:t ≤ Counter.flips bshpos:0 < Counter.flips bsj:ℕhj:j < Counter.flips bs - 1⊢ bs[j]?.getD false = true] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolbs:List Boolwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = 0hp1:cfg.workTapePos 1 = 0hbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = bs[j]?.getD falsehw:Counter.flips bs ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕht:t ≤ Counter.flips bshpos:0 < Counter.flips bsj:ℕhj:j < Counter.flips bs - 1⊢ bs[j]?.getD false = true
exact Counter.getD_eq_true_of_lt_flips bs j (by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolbs:List Boolwidth:ℕhq:cfg.state = some (if leaf = true then stCarryLeaf else stCarryFork)hp0:cfg.workTapePos 0 = 0hp1:cfg.workTapePos 1 = 0hbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = bs[j]?.getD falsehw:Counter.flips bs ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))t:ℕht:t ≤ Counter.flips bshpos:0 < Counter.flips bsj:ℕhj:j < Counter.flips bs - 1⊢ j + 1 < Counter.flips bs omega All goals completed! 🐙)A complete carry and return implements one increment and tests equality.
theorem configs_increment {input : List (Fin 4)}
(cfg : Cfg 3 (Fin 4) (Fin 10) input) (leaf : Bool) (width a b : ℕ)
(h : Represents width cfg (if leaf then stCarryLeaf else stCarryFork) a b)
(hnext : ((if leaf then b else a) + 1).size ≤ width) :
let f := Counter.flips (if leaf then b else a).bits
let a' := if leaf then a else a + 1
let b' := if leaf then b + 1 else b
let now := machine.configs cfg (2 * f + 1)
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = [] := by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ width⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
let n := if leaf then b else a input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else a⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
let f := Counter.flips n.bits input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bits⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
let a' := if leaf then a else a + 1 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
let b' := if leaf then b + 1 else b input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else b⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
let after := machine.configs cfg f input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg f⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have hbits : ∀ j, digits cfg (if leaf then 1 else 0) j = n.bits[j]?.getD false := by
intro j input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fj:ℕ⊢ digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD false
cases leaf false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕj:ℕh:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg f⊢ digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsetrue input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕj:ℕh:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg f⊢ digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD false
· false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕj:ℕh:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg f⊢ digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD false exact congrFun h.forkDigits j All goals completed! 🐙
· true input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕj:ℕh:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg f⊢ digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD false exact congrFun h.leafDigits j input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD false⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
obtain ⟨hstate, hpos0, hpos1, hin, hselected, hother, hout⟩ :=
configs_carry_bits cfg leaf n.bits h.state h.forkPos h.leafPos hbits input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have hw : f ≤ width := (Counter.flips_bits_le_succ_size n).trans hnext input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ width⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have hm : cfg.workTapePos 2 = (mismatchCount width (digits cfg 0) (digits cfg 1) : ℤ) := by
rw [h.forkDigits, input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ width⊢ cfg.workTapePos 2 = ↑(mismatchCount width (bitsAt a) (digits cfg 1)) h.leafDigits input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ width⊢ cfg.workTapePos 2 = ↑(mismatchCount width (bitsAt a) (bitsAt b))] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ width⊢ cfg.workTapePos 2 = ↑(mismatchCount width (bitsAt a) (bitsAt b))
exact h.mismatchPos input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
obtain ⟨horigin, hmarker, hmismatch⟩ := configs_carry_bits_invariants cfg leaf n.bits
width h.state h.forkPos h.leafPos hbits hw hm f (Nat.le_refl _) input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have hd0 : digits after 0 = bitsAt a' := by
cases leaf false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if false = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if false = true then 0 else 1) = digits cfg (if false = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))⊢ digits after 0 = bitsAt a'true input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if true = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if true = true then 0 else 1) = digits cfg (if true = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))⊢ digits after 0 = bitsAt a'
· false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if false = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if false = true then 0 else 1) = digits cfg (if false = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))⊢ digits after 0 = bitsAt a' funext j false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if false = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if false = true then 0 else 1) = digits cfg (if false = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))j:ℕ⊢ digits after 0 j = bitsAt a' j
simpa [Counter.increment_bits, n, a', after, f, bitsAt] using congrFun hselected j All goals completed! 🐙
· true input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if true = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if true = true then 0 else 1) = digits cfg (if true = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))⊢ digits after 0 = bitsAt a' exact hother.trans h.forkDigits input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have hd1 : digits after 1 = bitsAt b' := by
cases leaf false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if false = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if false = true then 0 else 1) = digits cfg (if false = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'⊢ digits after 1 = bitsAt b'true input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if true = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if true = true then 0 else 1) = digits cfg (if true = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'⊢ digits after 1 = bitsAt b'
· false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if false = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if false = true then 0 else 1) = digits cfg (if false = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'⊢ digits after 1 = bitsAt b' exact hother.trans h.leafDigits All goals completed! 🐙
· true input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if true = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if true = true then 0 else 1) = digits cfg (if true = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'⊢ digits after 1 = bitsAt b' funext j true input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if true = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if true = true then 0 else 1) = digits cfg (if true = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'j:ℕ⊢ digits after 1 j = bitsAt b' j
simpa [Counter.increment_bits, n, b', after, f, bitsAt] using congrFun hselected j input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have ho : ∀ z, origin (after.workTapes 0 z) = decide (z = 0) :=
fun z ↦ (horigin z).trans (h.originTag z) input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have hmark : ∀ z, after.workTapes 2 z = if z = 0 then some 0 else none := by
intro z input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)z:ℤ⊢ after.workTapes 2 z = if z = 0 then some 0 else none
rw [hmarker, input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)z:ℤ⊢ cfg.workTapes 2 z = if z = 0 then some 0 else none h.marker input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)z:ℤ⊢ (if z = 0 then some 0 else none) = if z = 0 then some 0 else none] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else none⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have hm' : after.workTapePos 2 = (mismatchCount width (bitsAt a') (bitsAt b') : ℤ) := by
rw [← hd0, input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else none⊢ after.workTapePos 2 = ↑(mismatchCount width (digits after 0) (bitsAt b')) ← hd1 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else none⊢ after.workTapePos 2 = ↑(mismatchCount width (digits after 0) (digits after 1))] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else none⊢ after.workTapePos 2 = ↑(mismatchCount width (digits after 0) (digits after 1))
exact hmismatch input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have ha' : a'.size ≤ width := by cases leaf false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if false = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if false = true then 0 else 1) = digits cfg (if false = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))⊢ a'.size ≤ widthtrue input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if true = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if true = true then 0 else 1) = digits cfg (if true = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))⊢ a'.size ≤ width <;> false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if false = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if false = true then 0 else 1) = digits cfg (if false = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))⊢ a'.size ≤ widthtrue input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if true = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if true = true then 0 else 1) = digits cfg (if true = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))⊢ a'.size ≤ width first | exact hnext true input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if true = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if true = true then 0 else 1) = digits cfg (if true = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))⊢ a'.size ≤ width | exact h.forkSize input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ width⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have hb' : b'.size ≤ width := by cases leaf false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if false = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if false = true then 0 else 1) = digits cfg (if false = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ width⊢ b'.size ≤ widthtrue input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if true = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if true = true then 0 else 1) = digits cfg (if true = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ width⊢ b'.size ≤ width <;> false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthn:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if false = true then a else a + 1b':ℕ := if false = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if false = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if false = true then 0 else 1) = digits cfg (if false = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ width⊢ b'.size ≤ widthtrue input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))h:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthn:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if true = true then a else a + 1b':ℕ := if true = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if true = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if true = true then 0 else 1) = digits cfg (if true = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhorigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ width⊢ b'.size ≤ width first | exact hnext All goals completed! 🐙 | exact h.leafSize input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ width⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have hr := returnedCfg_represents after width a' b' hd0 hd1 ho hmark hm' ha' hb' input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have he := returnCfg_self after f hstate hpos0 hpos1 input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = after⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
obtain ⟨hc, ho'⟩ := configs_return_done after ho f input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs (returnCfg after f) (f + 1) = returnedCfg afterho':machine.outputString (returnCfg after f) (f + 1) = []⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
rw [he input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []] at hc ho' input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
have hfinal : machine.configs cfg (2 * f + 1) = returnedCfg after := by
rw [show 2 * f + 1 = f + (f + 1) by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ width⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = [] omega All goals completed! 🐙, configs_add input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []⊢ configs (configs cfg f) (f + 1) = returnedCfg after] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []⊢ configs (configs cfg f) (f + 1) = returnedCfg after
exact hc input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []hfinal:configs cfg (2 * f + 1) = returnedCfg after⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = []
change Represents width _ _ a' b' ∧ _ ∧ _ input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []hfinal:configs cfg (2 * f + 1) = returnedCfg after⊢ Represents width (configs cfg (2 * Counter.flips (if leaf = true then b else a).bits + 1))
(if (if leaf = true then a else a + 1) = if leaf = true then b + 1 else b then stDone else stTree) a' b' ∧
(configs cfg (2 * Counter.flips (if leaf = true then b else a).bits + 1)).inputPos = cfg.inputPos ∧
machine.outputString cfg (2 * Counter.flips (if leaf = true then b else a).bits + 1) = []
rw [hfinal input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []hfinal:configs cfg (2 * f + 1) = returnedCfg after⊢ Represents width (returnedCfg after)
(if (if leaf = true then a else a + 1) = if leaf = true then b + 1 else b then stDone else stTree) a' b' ∧
(returnedCfg after).inputPos = cfg.inputPos ∧
machine.outputString cfg (2 * Counter.flips (if leaf = true then b else a).bits + 1) = []] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []hfinal:configs cfg (2 * f + 1) = returnedCfg after⊢ Represents width (returnedCfg after)
(if (if leaf = true then a else a + 1) = if leaf = true then b + 1 else b then stDone else stTree) a' b' ∧
(returnedCfg after).inputPos = cfg.inputPos ∧
machine.outputString cfg (2 * Counter.flips (if leaf = true then b else a).bits + 1) = []
refine ⟨hr, hin, ?_⟩ input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []hfinal:configs cfg (2 * f + 1) = returnedCfg after⊢ machine.outputString cfg (2 * Counter.flips (if leaf = true then b else a).bits + 1) = []
rw [show 2 * f + 1 = f + (f + 1) by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ width⊢ let f := Counter.flips (if leaf = true then b else a).bits;
let a' := if leaf = true then a else a + 1;
let b' := if leaf = true then b + 1 else b;
let now := configs cfg (2 * f + 1);
Represents width now (if a' = b' then stDone else stTree) a' b' ∧
now.inputPos = cfg.inputPos ∧ machine.outputString cfg (2 * f + 1) = [] omega All goals completed! 🐙, outputString_add_eq_append, input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []hfinal:configs cfg (2 * f + 1) = returnedCfg after⊢ machine.outputString cfg f ++ machine.outputString (configs cfg f) (f + 1) = [] hout, input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []hfinal:configs cfg (2 * f + 1) = returnedCfg after⊢ [] ++ machine.outputString (configs cfg f) (f + 1) = [] ho' input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []hfinal:configs cfg (2 * f + 1) = returnedCfg after⊢ [] ++ [] = []] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widthn:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitsa':ℕ := if leaf = true then a else a + 1b':ℕ := if leaf = true then b + 1 else bafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehstate:(configs cfg (Counter.flips n.bits)).state = some stReturnhpos0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hpos1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)hin:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPoshselected:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD falsehother:digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) = digits cfg (if leaf = true then 0 else 1)hout:machine.outputString cfg (Counter.flips n.bits) = []hw:f ≤ widthhm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)hmarker:(configs cfg f).workTapes 2 = cfg.workTapes 2hmismatch:(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))hd0:digits after 0 = bitsAt a'hd1:digits after 1 = bitsAt b'ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)hmark:∀ (z : ℤ), after.workTapes 2 z = if z = 0 then some 0 else nonehm':after.workTapePos 2 = ↑(mismatchCount width (bitsAt a') (bitsAt b'))ha':a'.size ≤ widthhb':b'.size ≤ widthhr:Represents width (returnedCfg after) (if a' = b' then stDone else stTree) a' b'he:returnCfg after f = afterhc:configs after (f + 1) = returnedCfg afterho':machine.outputString after (f + 1) = []hfinal:configs cfg (2 * f + 1) = returnedCfg after⊢ [] ++ [] = []
rfl All goals completed! 🐙Every work head stays within the fixed width during a complete increment.
theorem configs_increment_head_bounds {input : List (Fin 4)}
(cfg : Cfg 3 (Fin 4) (Fin 10) input) (leaf : Bool) (width a b : ℕ)
(h : Represents width cfg (if leaf then stCarryLeaf else stCarryFork) a b)
(hnext : ((if leaf then b else a) + 1).size ≤ width)
(t : ℕ) (ht : t ≤ 2 * Counter.flips (if leaf then b else a).bits + 1) (i : Fin 3) :
0 ≤ (machine.configs cfg t).workTapePos i ∧
(machine.configs cfg t).workTapePos i ≤ width := by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
let n := if leaf then b else a input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else a⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
let f := Counter.flips n.bits input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bits⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
have hw : f ≤ width := (Counter.flips_bits_le_succ_size n).trans hnext input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ width⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
have hbits : ∀ j, digits cfg (if leaf then 1 else 0) j = n.bits[j]?.getD false := by
intro j input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthj:ℕ⊢ digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD false
cases leaf false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕt:ℕi:Fin 3j:ℕh:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthht:t ≤ 2 * Counter.flips (if false = true then b else a).bits + 1n:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ width⊢ digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD falsetrue input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕt:ℕi:Fin 3j:ℕh:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthht:t ≤ 2 * Counter.flips (if true = true then b else a).bits + 1n:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ width⊢ digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD false
· false input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕt:ℕi:Fin 3j:ℕh:Represents width cfg (if false = true then stCarryLeaf else stCarryFork) a bhnext:((if false = true then b else a) + 1).size ≤ widthht:t ≤ 2 * Counter.flips (if false = true then b else a).bits + 1n:ℕ := if false = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ width⊢ digits cfg (if false = true then 1 else 0) j = n.bits[j]?.getD false exact congrFun h.forkDigits j All goals completed! 🐙
· true input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputwidth:ℕa:ℕb:ℕt:ℕi:Fin 3j:ℕh:Represents width cfg (if true = true then stCarryLeaf else stCarryFork) a bhnext:((if true = true then b else a) + 1).size ≤ widthht:t ≤ 2 * Counter.flips (if true = true then b else a).bits + 1n:ℕ := if true = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ width⊢ digits cfg (if true = true then 1 else 0) j = n.bits[j]?.getD false exact congrFun h.leafDigits j input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD false⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
have hm : cfg.workTapePos 2 = (mismatchCount width (digits cfg 0) (digits cfg 1) : ℤ) := by
rw [h.forkDigits, input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD false⊢ cfg.workTapePos 2 = ↑(mismatchCount width (bitsAt a) (digits cfg 1)) h.leafDigits input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD false⊢ cfg.workTapePos 2 = ↑(mismatchCount width (bitsAt a) (bitsAt b))] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD false⊢ cfg.workTapePos 2 = ↑(mismatchCount width (bitsAt a) (bitsAt b))
exact h.mismatchPos input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
by_cases htf : t ≤ f pos input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ f⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑widthneg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ f⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
· pos input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ f⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width obtain ⟨hp0, hp1⟩ :=
configs_carry_bits_pos cfg leaf n.bits h.state h.forkPos h.leafPos hbits t htf pos input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑t⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
have hm' := (configs_carry_bits_invariants cfg leaf n.bits width h.state
h.forkPos h.leafPos hbits hw hm t htf).2.2 pos input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
have hcount := mismatchCount_le width (digits (machine.configs cfg t) 0)
(digits (machine.configs cfg t) 1) pos input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
fin_cases i pos.«_@».4154754837._hygCtx._hyg.319.«0» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos ((fun i ↦ i) ⟨0, ⋯⟩) ∧ (configs cfg t).workTapePos ((fun i ↦ i) ⟨0, ⋯⟩) ≤ ↑widthpos.«_@».4154754837._hygCtx._hyg.319.«1» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos ((fun i ↦ i) ⟨1, ⋯⟩) ∧ (configs cfg t).workTapePos ((fun i ↦ i) ⟨1, ⋯⟩) ≤ ↑widthpos.«_@».4154754837._hygCtx._hyg.319.«2» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos ((fun i ↦ i) ⟨2, ⋯⟩) ∧ (configs cfg t).workTapePos ((fun i ↦ i) ⟨2, ⋯⟩) ≤ ↑width
· pos.«_@».4154754837._hygCtx._hyg.319.«0» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos ((fun i ↦ i) ⟨0, ⋯⟩) ∧ (configs cfg t).workTapePos ((fun i ↦ i) ⟨0, ⋯⟩) ≤ ↑width change 0 ≤ (machine.configs cfg t).workTapePos 0 ∧
(machine.configs cfg t).workTapePos 0 ≤ width pos.«_@».4154754837._hygCtx._hyg.319.«0» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos 0 ∧ (configs cfg t).workTapePos 0 ≤ ↑width
rw [hp0 pos.«_@».4154754837._hygCtx._hyg.319.«0» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ ↑t ∧ ↑t ≤ ↑width] pos.«_@».4154754837._hygCtx._hyg.319.«0» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ ↑t ∧ ↑t ≤ ↑width
omega All goals completed! 🐙
· pos.«_@».4154754837._hygCtx._hyg.319.«1» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos ((fun i ↦ i) ⟨1, ⋯⟩) ∧ (configs cfg t).workTapePos ((fun i ↦ i) ⟨1, ⋯⟩) ≤ ↑width change 0 ≤ (machine.configs cfg t).workTapePos 1 ∧
(machine.configs cfg t).workTapePos 1 ≤ width pos.«_@».4154754837._hygCtx._hyg.319.«1» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos 1 ∧ (configs cfg t).workTapePos 1 ≤ ↑width
rw [hp1 pos.«_@».4154754837._hygCtx._hyg.319.«1» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ ↑t ∧ ↑t ≤ ↑width] pos.«_@».4154754837._hygCtx._hyg.319.«1» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ ↑t ∧ ↑t ≤ ↑width
omega All goals completed! 🐙
· pos.«_@».4154754837._hygCtx._hyg.319.«2» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos ((fun i ↦ i) ⟨2, ⋯⟩) ∧ (configs cfg t).workTapePos ((fun i ↦ i) ⟨2, ⋯⟩) ≤ ↑width change 0 ≤ (machine.configs cfg t).workTapePos 2 ∧
(machine.configs cfg t).workTapePos 2 ≤ width pos.«_@».4154754837._hygCtx._hyg.319.«2» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos 2 ∧ (configs cfg t).workTapePos 2 ≤ ↑width
rw [hm' pos.«_@».4154754837._hygCtx._hyg.319.«2» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1)) ∧
↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1)) ≤ ↑width] pos.«_@».4154754837._hygCtx._hyg.319.«2» input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:t ≤ fhp0:(configs cfg t).workTapePos 0 = ↑thp1:(configs cfg t).workTapePos 1 = ↑thm':(configs cfg t).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1))hcount:mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1) ≤ width⊢ 0 ≤ ↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1)) ∧
↑(mismatchCount width (digits (configs cfg t) 0) (digits (configs cfg t) 1)) ≤ ↑width
omega All goals completed! 🐙
· neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ f⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width let after := machine.configs cfg f neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg f⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
obtain ⟨hq, hp0, hp1, _⟩ :=
configs_carry_bits cfg leaf n.bits h.state h.forkPos h.leafPos hbits neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
obtain ⟨horigin, _, hm'⟩ := configs_carry_bits_invariants cfg leaf n.bits width
h.state h.forkPos h.leafPos hbits hw hm f (Nat.le_refl _) neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
have ho : ∀ z, origin (after.workTapes 0 z) = decide (z = 0) :=
fun z ↦ (horigin z).trans (h.originTag z) neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
have he := returnCfg_self after f hq hp0 hp1 neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = after⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
have hcount := mismatchCount_le width (digits after 0) (digits after 1) neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits after 0) (digits after 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
dsimp only [after] at hcount neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ width⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
have hb := configs_return_head_bounds after ho f width hw
(by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ width⊢ 0 ≤ after.workTapePos 2 rw [hm' input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ width⊢ 0 ≤ ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ width⊢ 0 ≤ ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1)); omega All goals completed! 🐙) (by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ width⊢ after.workTapePos 2 ≤ ↑width rw [hm' input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ width⊢ ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1)) ≤ ↑width] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ width⊢ ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1)) ≤ ↑width; omega All goals completed! 🐙) (t - f) (by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ width⊢ t - f ≤ f + 1 dsimp [f, n] input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ width⊢ t - Counter.flips (if leaf = true then b else a).bits ≤ Counter.flips (if leaf = true then b else a).bits + 1; omega All goals completed! 🐙) i neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ widthhb:0 ≤ (configs (returnCfg after f) (t - f)).workTapePos i ∧ (configs (returnCfg after f) (t - f)).workTapePos i ≤ ↑width⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
rw [he neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ widthhb:0 ≤ (configs after (t - f)).workTapePos i ∧ (configs after (t - f)).workTapePos i ≤ ↑width⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width] at hb neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ widthhb:0 ≤ (configs after (t - f)).workTapePos i ∧ (configs after (t - f)).workTapePos i ≤ ↑width⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width
rw [show t = f + (t - f) by input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3⊢ 0 ≤ (configs cfg t).workTapePos i ∧ (configs cfg t).workTapePos i ≤ ↑width omega All goals completed! 🐙, configs_add neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ widthhb:0 ≤ (configs after (t - f)).workTapePos i ∧ (configs after (t - f)).workTapePos i ≤ ↑width⊢ 0 ≤ (configs (configs cfg f) (t - f)).workTapePos i ∧ (configs (configs cfg f) (t - f)).workTapePos i ≤ ↑width] neg input:List (Fin 4)cfg:Cfg 3 (Fin 4) (Fin 10) inputleaf:Boolwidth:ℕa:ℕb:ℕh:Represents width cfg (if leaf = true then stCarryLeaf else stCarryFork) a bhnext:((if leaf = true then b else a) + 1).size ≤ widtht:ℕht:t ≤ 2 * Counter.flips (if leaf = true then b else a).bits + 1i:Fin 3n:ℕ := if leaf = true then b else af:ℕ := Counter.flips n.bitshw:f ≤ widthhbits:∀ (j : ℕ), digits cfg (if leaf = true then 1 else 0) j = n.bits[j]?.getD falsehm:cfg.workTapePos 2 = ↑(mismatchCount width (digits cfg 0) (digits cfg 1))htf:¬t ≤ fafter:Cfg 3 (Fin 4) (Fin 10) input := configs cfg fhq:(configs cfg (Counter.flips n.bits)).state = some stReturnhp0:(configs cfg (Counter.flips n.bits)).workTapePos 0 = ↑(Counter.flips n.bits)hp1:(configs cfg (Counter.flips n.bits)).workTapePos 1 = ↑(Counter.flips n.bits)right✝:(configs cfg (Counter.flips n.bits)).inputPos = cfg.inputPos ∧
(digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 1 else 0) = fun j ↦
(Counter.increment n.bits)[j]?.getD false) ∧
digits (configs cfg (Counter.flips n.bits)) (if leaf = true then 0 else 1) =
digits cfg (if leaf = true then 0 else 1) ∧
machine.outputString cfg (Counter.flips n.bits) = []horigin:∀ (z : ℤ), origin ((configs cfg f).workTapes 0 z) = origin (cfg.workTapes 0 z)left✝:(configs cfg f).workTapes 2 = cfg.workTapes 2hm':(configs cfg f).workTapePos 2 = ↑(mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1))ho:∀ (z : ℤ), origin (after.workTapes 0 z) = decide (z = 0)he:returnCfg after f = afterhcount:mismatchCount width (digits (configs cfg f) 0) (digits (configs cfg f) 1) ≤ widthhb:0 ≤ (configs after (t - f)).workTapePos i ∧ (configs after (t - f)).workTapePos i ≤ ↑width⊢ 0 ≤ (configs (configs cfg f) (t - f)).workTapePos i ∧ (configs (configs cfg f) (t - f)).workTapePos i ≤ ↑width
exact hb All goals completed! 🐙end Geb.BitTree.BinaryMachine