Doubling arrays on the word RAM #
A fixed twelve-register append routine uses the charged zeroing allocator and a charged
copy loop. Old blocks are retained: the space theorem concerns total allocated words over
append-only histories, rather than reclamation. The abstract state exposes only the list.
A companion two-instruction indexed read routine and a fixed operation dispatcher connect
the doubling array to Cslib.Stateful and Cslib.Stateful.Amortized.
Main definitions #
Cslib.Algorithms.WordRAM.DynamicArray.program: the fixed twelve-register append procedure.Cslib.Algorithms.WordRAM.DynamicArray.getProgram: the two-instruction indexed read procedure.Cslib.Algorithms.WordRAM.DynamicArray.initProgram: charged fifteen-instruction initializer.Cslib.Algorithms.WordRAM.DynamicArray.dispatch: fixed append/get operation dispatcher.Cslib.Algorithms.WordRAM.DynamicArray.Rep: the live array and allocator frontier invariant.Cslib.Algorithms.WordRAM.DynamicArray.potential: natural-valued credit15 * (2 * |vs| - cap).
Main results #
Cslib.Algorithms.WordRAM.DynamicArray.Rep.space: total allocated words< 4 * vs.lengthfor nonempty arrays.Cslib.Algorithms.WordRAM.DynamicArray.grow_exec: capacity doubling within15 * cap + 14instructions.Cslib.Algorithms.WordRAM.DynamicArray.append_exec: append correctness, memory preservation, and the49-instruction potential inequality.Cslib.Algorithms.WordRAM.DynamicArray.get_exec: two-instruction indexed read correctness.Cslib.Algorithms.WordRAM.DynamicArray.init_exec: charged initialization of the empty array.Cslib.Algorithms.WordRAM.DynamicArray.amortized:Stateful.Amortizedcertificate for adaptive histories.Cslib.Algorithms.WordRAM.DynamicArray.run_initialized: end-to-end adaptive execution from charged initialization with linear total instruction bound and< 4 * mspace.Cslib.Algorithms.WordRAM.DynamicArray.run_appendAll: appendingmwords from an initialized empty array in at most15 + 52 * mtotal instructions and< 4 * mtotal allocated words.
References #
Pointer to the live block.
Instances For
New block pointer and operation dispatch tag.
Instances For
Logical length.
Instances For
Copy/allocation loop cursor.
Instances For
Temporary address.
Instances For
Temporary copied value and read output register.
Instances For
Constant one.
Instances For
Current capacity.
Instances For
Bump allocator frontier.
Instances For
Caller-supplied value to append or index to read.
Instances For
Requested allocation size.
Instances For
Constant zero.
Instances For
The copy routine embedded in the first seven registers.
Instances For
Allocate twice the capacity, copy the live prefix, and switch the pointer.
Instances For
Append a word, growing precisely when the array is full.
Instances For
Allocate the initial one-word block at address zero and install the empty representation.
Instances For
The live prefix, capacity and total allocation. The equalities express the geometric allocation series starting with a single cell at address zero.
Instances For
The doubled frontier bound x.regs frontier + 2 * x.regs cap is bounded by 8 * vs.length + 3
for every represented state.
The natural-valued credit used to pay for allocation and copying.
Instances For
The exact copy contract lifts to a larger register file without charging a meta-level call.
A growth phase preserves the live values and sets aside a zeroed block, charging both allocation and copying. The resulting capacity, frontier, and frame are explicit.
Four-instruction suffix of program: set one ← #1, write arg at ptr + len, and
increment len.
Appending a word preserves the doubling-array invariant, modifies only cells in
[x.regs ptr, y.regs frontier) (hence only within [0, y.regs frontier)), and satisfies the
potential-method amortized bound with constant 49.
Indexed read returns vs[x.regs arg] in temp in two instructions without changing the
representation, memory, or potential.
Charged initialization allocates the initial one-word block at address zero in fifteen
instructions, establishing Rep [] with zero potential and frontier 1.
Connection to Cslib.Stateful and Cslib.Stateful.Amortized #
Instances For
Mathematical specification of a bounded-word dynamic array.
Appending requires the value and the worst-case doubled frontier bound 8 * vs.length + 4
to fit in a machine word; indexed reads require a valid index fitting a machine word.
Instances For
Fixed operation dispatcher: dest = 0 runs program (append), dest = 1 runs getProgram.
Instances For
Register calling convention for dispatch.
Instances For
Bounded-word doubling-array representation for DynamicCertificate.
- bounded : WordRAM.Data.Bounded w x
- rep : Rep vs x
Instances For
Amortized instruction charge per operation, including dispatch and final halt.
Instances For
Encoded arguments fit the word width whenever 1 fits and the operation is valid.
Argument delivery preserves Rep because dest and arg are not persistent representation
registers.
Every admissible operation executes dispatch, preserves BoundedRep, modifies only
cells below y.regs frontier, and satisfies the potential inequality with charge o
(counting the final halt).
Semantic realization certificate for the bounded-word dynamic array.
Instances For
Amortized instruction-cost certificate for the dynamic array (52 per append, 6 per get,
including dispatch and final halt).
Uniform amortized instruction-cost certificate (52 instructions per operation).
Every concrete call modifies only cells below y.regs frontier.
Disjoint heap assertions above y.regs frontier survive every dynamic-array call.
Every admissible adaptive client executes with total instructions bounded by 52 per
operation plus initial credit, retaining final credit and the < 4 * m space invariant.
Starting from arbitrary bounded machine data, run initProgram (15 instructions) followed
by any admissible adaptive client p. Total instructions across initialization and m operations
are at most 15 + 52 * m, and the allocator frontier is < 4 * n whenever the final list of
length n is nonempty.
appendAll us is admissible from vs whenever every element of us fits w and
8 * (vs.length + us.length) + 4 fits w.
Any sequence of m = vs.length appends starting from the charged initializer executes in at
most 15 + 52 * m total charged instructions and uses fewer than 4 * m total allocated words
whenever vs ≠ [].