Documentation

CslibFrontier.DataStructure.Queue.WordRAM.RegisterCorrectness

FIFO correctness of the physical-array memory programs #

The count inputs and results are ordinary values; the physical memory assertions reuse Block.HoldsList. The conclusions identify the existing pairStep on the front and rear lists, including empty dequeue and a returned zero. No count cell or stronger room premise is introduced. The native register representation and paid dispatcher are separate consumers.

Main results #

References #

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

theorem Cslib.DataStructure.Queue.WordRAM.RegisterMetadata.enqueue_contents {d : Input} (front back : List ℕ) (s : Memory.State) (hF : d 0 = front.length) (hB : d 1 = back.length) (hc : front.length + back.length < d 3) (hfront : WordRAM.Block.HoldsList (d 2) front.reverse s.mem) (hback : WordRAM.Block.HoldsList (d 2 + d 3) back.reverse s.mem) :
have t := (Memory.spec 0).clientState s (enqueue d); (Memory.spec 0).clientResult s (enqueue d) = { front := front.length, rear := (d 4 :: back).length } ∧ WordRAM.Block.HoldsList (d 2) front.reverse t.mem ∧ WordRAM.Block.HoldsList (d 2 + d 3) (d 4 :: back).reverse t.mem

Enqueue appends one physical rear word while retaining the entire represented front.

theorem Cslib.DataStructure.Queue.WordRAM.RegisterMetadata.popFront_contents {d : Input} (front back : List ℕ) (s : Memory.State) (hF : d 0 = front.length) (hB : d 1 = back.length) (hfront : WordRAM.Block.HoldsList (d 2) front.reverse s.mem) (hback : WordRAM.Block.HoldsList (d 2 + d 3) back.reverse s.mem) :
(Memory.spec 0).clientResult s (popFront d) = ({ front := front.tail.length, rear := back.length }, front.head?) ∧ WordRAM.Block.HoldsList (d 2) front.tail.reverse s.mem ∧ WordRAM.Block.HoldsList (d 2 + d 3) back.reverse s.mem

Pop observes the top represented value and retains the unused dirty cell. No memory clearing, capacity fit or nonzero-value hypothesis is needed for this source equation.

theorem Cslib.DataStructure.Queue.WordRAM.RegisterMetadata.dequeue_contents {w : ℕ} {d : Input} (front back : List ℕ) (s : Memory.State) (hw : Memory.WellFormed w s) (hF : d 0 = front.length) (hB : d 1 = back.length) (hc : front.length + back.length ≤ d 3) (hf : d 2 + 2 * d 3 ≤ s.frontier) (hfront : WordRAM.Block.HoldsList (d 2) front.reverse s.mem) (hback : WordRAM.Block.HoldsList (d 2 + d 3) back.reverse s.mem) :
have p := pairStep { front := front, rear := back } QueueOp.dequeue; have t := (Memory.spec 0).clientState s (dequeue d); (Memory.spec 0).clientResult s (dequeue d) = ({ front := p.1.front.length, rear := p.1.rear.length }, p.2) ∧ WordRAM.Block.HoldsList (d 2) p.1.front.reverse t.mem ∧ WordRAM.Block.HoldsList (d 2 + d 3) p.1.rear.reverse t.mem

The interpreter's actual counts, option answer and physical arrays implement the existing two-stack transition. The only capacity premise is the original sum bound.