Tagged binary countdown on one work tape
DefinitionPhysicalBinaryCountdownClockcomplexity-theoryformal-verification
A finite-control countdown model has an outward search state, a return state carrying a marker flag, and an exhausted state. The tape contains binary digits and one highest-one marker. Each outward or return step also advances a separate one-way input head.
Definition code
import Mathlib.Logic.Function.Basic
set_option autoImplicit false
namespace PvsNP.PhysicalCountdown
inductive Phase where
| seek
| back (mark : Bool)
| done
structure Frame where
head : Nat
input : Nat
tape : Nat → Bool × Bool
phase : Phase
/-- The origin is a permanent marker. The second bit of a data cell is the
highest-one marker. A return flag transfers a cleared highest-one marker. -/
def markCell (tape : Nat → Bool × Bool) (head : Nat) (mark : Bool) : Nat → Bool × Bool :=
if mark then Function.update tape head ((tape head).1, true) else tape
def tick (cfg : Frame) : Frame :=
match cfg.phase with
| .done => cfg
| .seek =>
let digit := cfg.tape cfg.head
if digit.1 then
let tape := Function.update cfg.tape cfg.head (false, false)
if cfg.head = 0 then
⟨0, cfg.input + 1, tape, if digit.2 then .done else .seek⟩
else
⟨cfg.head - 1, cfg.input + 1, tape, .back digit.2⟩
else
⟨cfg.head + 1, cfg.input + 1, Function.update cfg.tape cfg.head (true, false), .seek⟩
| .back mark =>
let tape := markCell cfg.tape cfg.head mark
if cfg.head = 0 then ⟨0, cfg.input + 1, tape, .seek⟩
else ⟨cfg.head - 1, cfg.input + 1, tape, .back false⟩
def raised (tape : Nat → Bool × Bool) (width : Nat) : Nat → Bool × Bool :=
fun i => if i < width then (true, false) else tape i
end PvsNP.PhysicalCountdown
Source
Tagged decrement routine for simultaneous input scan.