Documentation

CslibFrontier.DataStructure.Queue.WordRAM.RegisterExecution

Paid initialization and execution of the resident queue #

The proof uses the shared Backend's public packing and live-execution facts. In particular, the maintained count words are already present in native source registers, rather than being reinstalled by the external controller. Operation code and packing are the globally fixed family from RegisterProgram; the initializer remains parameterized by literal base and capacity.

Main results #

References #

The queue and its algorithmic references are in Cslib.DataStructure.Queue.Spec.

theorem Cslib.DataStructure.Queue.WordRAM.initialized_rep {w base capacity : ℕ} {x : WordRAM.Data registers} (hx : WordRAM.Data.Bounded w x) (hc : WordRAM.Fits w (base + 2 * capacity)) :
Rep w base capacity [] [] (initialized base capacity x)

The actual six writes establish the empty representation under precisely the original end-fit condition, with no assumption on initial registers or dirty memory.

theorem Cslib.DataStructure.Queue.WordRAM.initialize_queue {w base capacity : ℕ} {x : WordRAM.Data registers} (hx : WordRAM.Data.Bounded w x) (hc : WordRAM.Fits w (base + 2 * capacity)) :
∃ (ready : WordRAM.Data registers), WordRAM.Exec w (initializeCode base capacity) x ready 6 ∧ QueueRep w base capacity [] ready ∧ ready.mem = x.mem

Paid raw initialization establishes the existing FIFO meaning and preserves all memory. The original small-width and capacity-zero cases are included; tag delivery later retains its separate Fits w 1 requirement.

theorem Cslib.DataStructure.Queue.WordRAM.execute_enqueue {w base capacity v : ℕ} {front back : List ℕ} {x : WordRAM.Data registers} (h1 : WordRAM.Fits w 1) (hr : Rep w base capacity front back x) (hs : front.length + back.length < capacity) (hv : WordRAM.Fits w v) :
∃ (y : WordRAM.Data registers) (n : ℕ), WordRAM.Exec w program ((implementation w capacity).prepare (QueueOp.enqueue v) x) y n ∧ n + 1 ≤ 2 * WordRAM.Realization.Backend.factor family + 5 ∧ Rep w base capacity front (v :: back) y ∧ WordRAM.Modifies (footprint base capacity) x.mem y.mem

The fixed dispatcher executes enqueue from resident metadata, pays the zero test and two count copies, and includes the final call halt in its bound. The original two arrays are the complete memory footprint.

theorem Cslib.DataStructure.Queue.WordRAM.execute_dequeue {w base capacity : ℕ} {front back : List ℕ} {x : WordRAM.Data registers} (h1 : WordRAM.Fits w 1) (hr : Rep w base capacity front back x) :

The negative native branch performs the source transfer/pop, commits both returned counts, and decodes its faithful option result. The bound includes the negative branch's two instructions and the call halt, without charging any hidden metadata installation.

theorem Cslib.DataStructure.Queue.WordRAM.execute {w base capacity : ℕ} {front back : List ℕ} {x : WordRAM.Data registers} (h1 : WordRAM.Fits w 1) (hr : Rep w base capacity front back x) (o : QueueOp ℕ) (hv : (spec w capacity).valid { front := front, rear := back }.contents o) :
have p := pairStep { front := front, rear := back } o; ∃ (y : WordRAM.Data registers) (n : ℕ), WordRAM.Exec w program ((implementation w capacity).prepare o x) y n ∧ (implementation w capacity).decode o y.regs = some p.2 ∧ Rep w base capacity p.1.front p.1.rear y ∧ WordRAM.Modifies (footprint base capacity) x.mem y.mem ∧ n + 1 + potential y ≤ 4 * WordRAM.Realization.Backend.factor family + 6 + potential x

One admissible call of the fixed native queue. The terminal rear potential is retained; the globally chosen exchange factor, control, metadata copies and halt are all charged. The external controller and tag/payload delivery remain the original dynamic-call boundary.

noncomputable def Cslib.DataStructure.Queue.WordRAM.certificate {w base capacity : ℕ} (h1 : WordRAM.Fits w 1) :

The fixed realized dispatcher implements the original bounded FIFO specification via the existing dynamic certificate. Its representation retains resident count words; no memory-only Backend implementation is asserted. The bounded resident frontier equals the physical end, so its fit already follows from Rep; raw initialization keeps its explicit end-fit premise.