Register-top k-word stacks on the word RAM #
Stack.Memory and MemoryStack store one-word items alongside a count cell in memory.
Iterative depth-first and worklist controllers on the word RAM instead keep the live record
count in a register top and store k-word records directly at [base, base + cap * k) with
no header cell, starting from possibly dirty memory.
This module provides:
WordStack.Holds R base items mem, the top-first LIFO representation ofitems : List αin[base, base + items.length * k), requiring no initialization of unused capacity above the live prefix;WordStack.pushandWordStack.pop, inlineCode .standard rroutines executing in exact2 * k + 2instructions;WordStack.pushWords_exec,WordStack.popWords_exec,WordStack.push_exec, andWordStack.pop_exec, proving exact instruction counts, typed LIFO stack transitions, and both single-slot and capacity-boundedModifiesframes.
Main definitions #
Cslib.WordRAM.WordStack.Holds: top-firstk-word stack representation atbase.Cslib.WordRAM.WordStack.push,Cslib.WordRAM.WordStack.pop: inline2 * k + 2-instruction push and pop programs.Cslib.WordRAM.WordStack.PushLocal,Cslib.WordRAM.WordStack.PopLocal: modified-register predicates forpushandpop.
Main results #
Cslib.WordRAM.WordStack.Holds.unique,Cslib.WordRAM.WordStack.Holds.keep,Cslib.WordRAM.WordStack.holds_iff_getElem_reverse: uniqueness at a known register top, equality-frame preservation, and reverse-indexed characterization ofWordStack.Holds.Cslib.WordRAM.WordStack.pushWords_exec,Cslib.WordRAM.WordStack.push_exec: exact2 * k + 2-instruction push at the single-slot and typed-stack levels.Cslib.WordRAM.WordStack.popWords_exec,Cslib.WordRAM.WordStack.pop_exec: exact2 * k + 2-instruction pop at the single-slot and typed-stack levels.
Top-first k-word stack invariant #
Top-first LIFO stack of k-word records at base: items = v :: rest places v at
base + rest.length * k above rest in [base, base + rest.length * k). Cells at or above
base + items.length * k are unconstrained.
An equality frame covering [base, base + items.length * k) preserves Holds.
Agreement on [base, base + items.length * k) transports Holds.
Writing v immediately above a represented stack items represents v :: items.
At a fixed stack height, injective record encoding uniquely determines the logical stack list from memory.
Holds R base items mem is equivalent to each slot idx < items.length holding the
idx-th element from the bottom (items.reverse[idx]).
Registers written by WordStack.push: cursor and top.
Instances For
Registers written by WordStack.pop: top, cursor, and the loaded fields.
Instances For
WordStack.push preserves every register outside PushLocal top cursor.
WordStack.pop preserves every register outside PopLocal top cursor fields.
WordStack.push never inspects the physical word width.
WordStack.pop never inspects the physical word width.
Single-slot execution of WordStack.push in exact 2 * k + 2 instructions.
Push a typed k-word record v onto a stack of capacity cap in exact 2 * k + 2
instructions.
Single-slot execution of WordStack.pop in exact 2 * k + 2 instructions.
Pop the top typed k-word record v from v :: items into fields in exact 2 * k + 2
instructions.