Early-exit transfer for the memory queue #
The remaining number of rear elements is explicit loop state. A rear pop returning none
sets it to zero, so the shared bounded while loop stops immediately. The source equalities
preserve the original linked queue program, including its operation history.
Main definitions #
transferBody: one rear pop and, when successful, one front push.
Main results #
transfer_eq_boundedWhile: the existing transfer program is the shared early-exit loop.run_eq_allocPair_bind: allocation followed by the original linked queue client.transfer_invariant: the existing framed product preserves both stacks and moves the rear.
References #
The queue and its algorithmic references are in Cslib.DataStructure.Queue.Spec.
Pop one rear element. An empty rear stops the loop; a successful move decreases the explicit remaining count. The loop guard excludes a zero count from this body.
Forgetting the loop's remaining count leaves exactly one step of the original transfer.
The bounded while has exactly the original source program, with no inactive tail queries or extra memory operations after an early empty pop. The cutoff bounds the remaining count.
The current allocator allocates its two stack handles and then links the unchanged queue methods through their product. This is equality of programs, before selecting a memory state.
The source transfer preserves the two existing storage invariants and reverses the rear into the front. The generic framed product supplies noninterference; no replacement invariant or instruction-level proof is needed.