Documentation

Complexity.Algorithms.WordRAM.Queue.Model

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 #

Main results #

References #

@[reducible, inline]

A queue admits an enqueue exactly when it has spare capacity and the value fits a word.

Instances For

    Front is in FIFO order; rear is in reverse FIFO order.

    Instances For

      Mathematical description of the machine's two-stack transition, including an empty pop.

      Instances For

        Projecting the concrete stack transition gives exactly the specified FIFO step.

        The sum of live stack lengths is the FIFO length, not the size of the reserved regions.

        theorem Cslib.WordRAM.Queue.pairStep_length_le {w capacity : ℕ} {s : List ℕ × List ℕ} (hs : (contents s).length ≤ capacity) (o : Algorithms.Lean.Queue.QueueOp ℕ) (hv : (spec w capacity).valid (contents s) o) :
        (contents (pairStep s o).1).length ≤ capacity

        Enqueues require one spare slot; dequeues cannot increase the number of live values.