One-work-tape installer for a framed packet stream
DefinitionBarePacketFrameWritercomplexity-theory
A finite local tape program reads tagged four-bit packets and consumes a one-bit sentinel. It writes the decoded payload to a frame track at the same absolute origin and clears the source bit plane.
Definition code
import Definitions.Def_OnlineScratchWindow
set_option autoImplicit false
set_option maxHeartbeats 4200000
namespace PvsNP.BareFrameWriter
open WorkBoundarySplice OnlineWindowShift
variable {Q Γ : Type} in
/-- An ordinary clocked finite run, allowing an arbitrary final configuration., allowing an arbitrary final configuration. -/
inductive Steps (M : Machine Q Γ) : Config Q Γ → Config Q Γ → ℕ → Prop
| refl (a : Config Q Γ) : Steps M a a 0
| next {a b c : Config Q Γ} {n : ℕ} :
step M a = some b → Steps M b c n → Steps M a c (n+1)
variable {C P : Type}
abbrev Packet := Bool × Bool × Bool
abbrev Square (C P : Type) := C × Cell P
def Packet.bits (p : Packet) : List Bool := [true,p.1,p.2.1,p.2.2]
def packetBits (packets : List Packet) : List Bool :=
packets.flatMap Packet.bits ++ [false]
inductive Phase (P : Type)
| start | round | seek | read0 | read1 (b0 : Bool) | read2 (b0 b1 : Bool)
| leftRead (symbol : Cell P) | deposit (symbol : Cell P)
| leftWritten (finish : Bool) | done
deriving Fintype
def machine (readBit : C → Option Bool) (clearBit : C → C) (decode : Packet → P) :
Machine (Phase P) (Square C P)
| .start, (cell,.blank) => some (.round,(cell,.near),.stay)
| .round, square => some (.seek,square,.right)
| .seek, square =>
match readBit square.1 with
| none => some (.seek,square,.right)
| some true => some (.read0,(clearBit square.1,square.2),.right)
| some false => some (.leftRead .far,(clearBit square.1,square.2),.left)
| .read0, square =>
(readBit square.1).map fun b => (.read1 b,(clearBit square.1,square.2),.right)
| .read1 a, square =>
(readBit square.1).map fun b => (.read2 a b,(clearBit square.1,square.2),.right)
| .read2 a b, square =>
(readBit square.1).map fun c =>
(.leftRead (.data (decode (a,b,c))),(clearBit square.1,square.2),.left)
| .leftRead symbol, (cell,.near) => some (.deposit symbol,(cell,.near),.right)
| .leftRead symbol, square => some (.leftRead symbol,square,.left)
| .deposit symbol, (cell,.blank) =>
some (.leftWritten (match symbol with | .far => true | _ => false),(cell,symbol),.left)
| .deposit symbol, square => some (.deposit symbol,square,.right)
| .leftWritten finish, (cell,.near) => some ((if finish then .done else .round),(cell,.near),.stay)
| .leftWritten finish, square => some (.leftWritten finish,square,.left)
| _, _ => none
def bitsFrom (origin : ℤ) (bits : List Bool) (i : ℤ) : Option Bool :=
if origin < i then bits[(i-origin-1).toNat]? else none
def stampLine (stamp : ℤ → Option Bool → C) (origin : ℤ) (bits : List Bool) : ℤ → C :=
fun i => stamp i (bitsFrom origin bits i)
def partialFrame (p : ℤ) (done : List P) (i : ℤ) : Cell P :=
if i = p then .near
else if p < i then
match done[(i-p-1).toNat]? with
| some value => .data value
| none => .blank
else .blank
def tape (stamp : ℤ → Option Bool → C) (origin : ℤ) (bits : List Bool) (p : ℤ)
(done : List P) : ℤ → Square C P :=
tracks (stampLine stamp origin bits) (partialFrame p done)
def clock (width : ℕ) : ℕ := 5*width*width+16*width+6
end PvsNP.BareFrameWriter
Source
Single-work-tape preparation for a bounded-window replay.