Documentation

CslibFrontier.DataStructure.Queue.WordRAM.RegisterProgram

One fixed queue dispatcher over realized physical-array methods #

The finite method family chooses all code and register packing before any runtime count, base, capacity, width, memory or operation. Only the tag and payload are delivered by the external dynamic calling convention. The count words, base, capacity and frontier remain resident. A native branch selects a body, and two actual copies commit its returned counts.

The initializer is a literal-parameterized code family, as in the original queue: base and capacity are fixed before the arbitrary dirty entry data. It writes registers only, performs six instructions, and reserves exactly 2*capacity physical cells. It is not a memory-clearing initializer or an uncharged use of Backend.install.

Main definitions #

References #

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

@[reducible, inline]

One fixed family contains both method bodies. Runtime arguments select no new code. Certificate.ofRealizes takes each body, its scratch size and its exchange factor by classical choice from an existential Realizes proof, so registers and Backend.factor family are fixed natural numbers whose values this construction does not determine.

@[reducible, inline]

One finite register file for both bodies and the dispatcher.

The complete physical reservation, including unused array cells.

Persistent count, layout and payload bank. Both tags have the same five-word input.

The two counts occupy the first two words of this common result prefix.

@[reducible, inline]

Tag delivery reuses scratch word zero, which the selected body may overwrite.

@[reducible, inline]

A paid zero constant for the native tag test, also in the shared scratch bank.

Two paid copies update the resident count bank.

The same native program executes every operation. No host-selected body is substituted.

Only the tag and payload are external inputs. The result decoder observes Unit for enqueue and the faithful option tag/value for dequeue; enqueue need not echo its argument.

@[simp]
theorem Cslib.DataStructure.Queue.WordRAM.decode_dequeue (w capacity : ℕ) (regs : Fin registers → ℕ) :
(implementation w capacity).decode QueueOp.dequeue regs = if regs (result 2) = 0 then some none else if regs (result 2) = 1 then some (some (regs (result 3))) else none

A dequeue observes only a canonical zero/one option tag and its unmodified payload word.

structure Cslib.DataStructure.Queue.WordRAM.Rep (w base capacity : ℕ) (front back : List ℕ) (x : WordRAM.Data registers) :

The existing two-array representation, with counts and layout in the shared input bank. Unused cells and the delivered tag/payload impose no extra memory or register premise.

The same logical FIFO projection as the original queue.

theorem Cslib.DataStructure.Queue.WordRAM.Rep.input_eq {w base capacity : ℕ} {front back : List ℕ} {x : WordRAM.Data registers} (hr : Rep w base capacity front back x) :
x.regs ∘ src = ![front.length, back.length, base, capacity, x.regs (src 4)]

The actual resident input words, without installing the maintained metadata again.

Rear credit is scaled by the single native exchange factor. This definition does not assert the still separate dispatcher clock or the final per-call amortized inequality.

Exact initialized data: only the frontier, counts, layout and zero scratch word change.

A literal base/capacity initializer with the original uniform six-instruction cost.

theorem Cslib.DataStructure.Queue.WordRAM.initialize_exec {w base capacity : ℕ} {x : WordRAM.Data registers} (hx : WordRAM.Data.Bounded w x) (hc : WordRAM.Fits w (base + 2 * capacity)) :
WordRAM.Exec w (initializeCode base capacity) x (initialized base capacity x) 6 ∧ WordRAM.Data.Bounded w (initialized base capacity x) ∧ (initialized base capacity x).mem = x.mem

Initialization starts from arbitrary bounded dirty data and keeps every memory cell. The original Fits w 1 premise is needed by operation tag delivery, not these zero writes.