The FIFO meaning of a two-stack representation #
The front stack lists the oldest values first; the rear stack lists the newest values first.
Thus the represented FIFO sequence is front ++ rear.reverse. Enqueue pushes onto the rear.
Dequeue pops the front when possible; otherwise it reverses the entire rear into the front
before popping. Reversal is only a mathematical description here: the machine implementation
executes a charged loop, moving one value at a time.
Main definitions #
spec: the existing FIFO specification restricted to fitting words and a fixed capacity.contents: the FIFO sequence represented by a pair of stacks.pairStep: the corresponding transition of the two stacks.
Main results #
pairStep_correct: both the returned answer and the new FIFO sequence matchspec.pairStep_length_le: admissible calls preserve the shared capacity bound.
References #
@[reducible, inline]
A queue admits an enqueue exactly when it has spare capacity and the value fits a word.