Word-addressed memory as a state-transition specification #
Memory.spec w is a memory oracle: the interface through which a data-structure implementation
reaches storage. Its state is the contents of every cell together with an allocation frontier.
Every address below the frontier is allocated, and allocation hands out the block that starts at
the frontier. The operations read a cell, write a cell, and allocate a block, either zeroed
(alloc, charged per cell) or with its old contents (allocDirty, charged one unit).
Admissibility carries the preconditions a word RAM needs. Accessed addresses must be allocated,
written values must fit a w-bit word, and the frontier after an allocation must fit. Under
these preconditions the frontier and every cell keep fitting a word (WellFormed.step), so an
allocated address fits too (WellFormed.fits_of_lt_frontier).
An implementation over this interface is an ordinary Memory.Prog program. Its correctness and
its operation charges are proved against step and charge, without registers or instruction
counts. charge is the memory-level currency; executing such a program on the word RAM is a
separate step that exchanges it into instructions. Allocation never reuses addresses, as in
Cslib.WordRAM.alloc, so blocks allocated at different times are disjoint
(Cslib.WordRAM.Block.disjoint_of_le). A program reuses memory by keeping a block it allocated.
Main definitions #
Memory.State,Memory.Op,Memory.step,Memory.valid: cells and frontier, operations with their answers, the transition function and the admissibility preconditions.Memory.spec: the deterministic specification at word sizew.Memory.charge: one unit per read, write and dirty allocation;k + 1for a zeroed block ofkcells.Memory.Prog,Memory.read,Memory.write,Memory.alloc,Memory.allocDirty: programs over the oracle and its four one-call programs.Memory.WellFormed: the frontier and all cell contents fit aw-bit word.Memory.State.init: the word RAM's input convention as a memory state.
Main results #
Memory.WellFormed.step,Memory.WellFormed.run: admissible operations preserve well-formedness.Memory.WellFormed.fits_of_lt_frontier: allocated addresses fit a word.Memory.one_le_charge: every operation costs at least one unit.Memory.frontier_le_step,Memory.frontier_le_run: the frontier never decreases.Memory.mem_step_of_lt_frontier: an operation changes an allocated cell only by writing it.Memory.wellFormed_init: the input convention is well formed.
Operations on memory. Addresses are words computed by the caller.
- read (addr : ℕ) : Op
Read the cell at an address.
- write (addr value : ℕ) : Op
Write a value to the cell at an address.
- alloc (count : ℕ) : Op
Allocate
countzeroed cells at the frontier and return their base address. - allocDirty (count : ℕ) : Op
Allocate
countcells at the frontier without clearing them and return their base address.
Instances For
Instances For
The answer type of each operation: a read and an allocation return a word.
Instances For
Word-addressed memory at word size w.
Instances For
The memory-level currency: one unit per read, write and dirty allocation, and k + 1 units
for a zeroed block of k cells.
Instances For
Programs over the memory oracle. They are the clients of Memory.spec w at every word size.
Instances For
Read the cell at address a.
Instances For
Write v to the cell at address a.
Instances For
Allocate k zeroed cells and return their base address.
Instances For
Allocate k cells without clearing them and return their base address.
Instances For
Admissibility of a concrete history is decidable.
Frontier and frame #
Word fit #
The frontier and every cell fit a w-bit word. Admissible operations preserve this.
- frontier_fits : WordRAM.Fits w s.frontier
The frontier fits a word, hence so does every allocated address.
- mem_fits (a : ℕ) : WordRAM.Fits w (s.mem a)
Every cell holds a word.
Instances For
Allocated addresses fit a word.
Admissible operations preserve well-formedness.
Admissible histories preserve well-formedness.
The input convention #
The word RAM's input convention (Cslib.WordRAM.Data.init) as a memory state: the input
length at address 0, the input words at addresses 1, …, n, and everything up to the input
allocated.
Instances For
The input convention is well formed when the input and its frontier fit a word.