Correctness and amortized instruction cost of a RAM queue #
The mathematical client sees only a FIFO list. The realization hides how that list is split between the two arrays. A dequeue can move every rear element, but each enqueue deposits eight credits: six instructions move an element and two instructions control that loop iteration. Consequently every admissible history costs at most fourteen instructions per operation, plus the initial rear credit. The final unused credit is retained in the inequality.
These are actual RAM operation instructions, including each call's halt. The operation interface still uses externally delivered argument registers; arbitrary pure computation in a client's Lean continuation is not included in this bound. Initialization is a separate six-instruction program. The arrays reserve twice the queue capacity, while at most one capacity's worth of values are live. No allocator or dynamically growing capacity is assumed.
Main definitions #
QueueRep: the FIFO representation hiding the split into two stacks.certificate: a semantic realization of the bounded queue interface.amortized: the separate instruction-cost certificate with rear-stack potential.
Main results #
run_client: correct adaptive execution and the amortized native instruction bound.frame: every operation preserves any disjoint heap assertion.
References #
The fixed dispatcher implements the bounded FIFO specification.
Instances For
The expensive transfer consumes eight credits per rear element, including loop control. The final halt contributes the extra one in the left side.
Every native operation has the exact charged body cost plus its final halt.
Rear-stack credit is read from the concrete persistent length register.
Instances For
Amortized constant instruction cost is certified separately from FIFO correctness.
Every admissible adaptive client has a correct native execution with a telescoping bound. This sums operation calls; the externally supplied client controller is not machine code.
Starting with arbitrary bounded data, charge the six initialization instructions before
summing the actual queue calls. Empty regions need no zeroing; controller computation and
external argument delivery retain the boundary stated in run_client.
Actual queue calls modify only the two reserved array regions.
Disjoint heap representations survive every queue call, including a full rear transfer.