Correctness-and-cost triples for memory programs #
Memory.Triple w s p c Q says that the memory program p, run from the state s at word size
w, issues only admissible operations, costs at most c memory units (Memory.charge), and
ends with an answer and a state satisfying Q. It is StateTransitionSpec.CostHoare at the
single initial state s; Memory.triple_iff unfolds it along the run of p.
The rules evaluate a program from its first operation on. Triple.read_bind and
Triple.write_bind discharge one operation's admissibility and charge, and leave the
continuation at the next state; Triple.bind splits a program at a subprogram with its own
triple; Triple.pure ends the run. Each rule peels one unit off a cost written c + 1, so a
straight-line program is checked by applying the rules in order. A recursive program is checked
by induction on its recursion measure, with the induction hypothesis applied at the recursive
call.
The word RAM's initial memory is zero past the input (zeroAbove_init), so a structure that
needs zeroed storage can take it there with a dirty allocation, at the cost of one unit, instead
of a zeroed one, whose charge grows with its size.
Main definitions #
Cslib.DataStructure.Memory.Triple: admissibility, cost and postcondition of one run.Cslib.DataStructure.Memory.ZeroAbove: every cell at or above the frontier holds0.
Main results #
Cslib.DataStructure.Memory.triple_iff: the triple along the run of the program.Cslib.DataStructure.Memory.Triple.pure,Cslib.DataStructure.Memory.Triple.read_bind,Cslib.DataStructure.Memory.Triple.read,Cslib.DataStructure.Memory.Triple.write_bind,Cslib.DataStructure.Memory.Triple.write,Cslib.DataStructure.Memory.Triple.alloc_bind,Cslib.DataStructure.Memory.Triple.alloc,Cslib.DataStructure.Memory.Triple.allocDirty_bind,Cslib.DataStructure.Memory.Triple.allocDirty,Cslib.DataStructure.Memory.Triple.allocBlock_bind,Cslib.DataStructure.Memory.Triple.allocBlock,Cslib.DataStructure.Memory.Triple.allocBlockDirty_bind,Cslib.DataStructure.Memory.Triple.allocBlockDirty,Cslib.DataStructure.Memory.Triple.get_bind,Cslib.DataStructure.Memory.Triple.get,Cslib.DataStructure.Memory.Triple.set_bind,Cslib.DataStructure.Memory.Triple.set: primitive step and block rules.Cslib.DataStructure.Memory.Triple.bind,Cslib.DataStructure.Memory.Triple.ite,Cslib.DataStructure.Memory.Triple.dite,Cslib.DataStructure.Memory.Triple.map: sequential composition, branching, and functorial mapping.Cslib.DataStructure.Memory.Triple.mono,Cslib.DataStructure.Memory.Triple.wellFormed,Cslib.DataStructure.Memory.Triple.zeroAbove: cost/postcondition weakening and invariant preservation.Cslib.DataStructure.Memory.zeroAbove_init,Cslib.DataStructure.Memory.ZeroAbove.write,Cslib.DataStructure.Memory.ZeroAbove.alloc,Cslib.DataStructure.Memory.ZeroAbove.allocDirty,Cslib.DataStructure.Memory.ZeroAbove.step,Cslib.DataStructure.Memory.ZeroAbove.run:ZeroAboveinitialization and preservation.
A triple is a statement about the one run of the program.
Write a word to an allocated cell, then continue.
Write a word to an allocated cell as a standalone program.
Allocate k zeroed cells at the frontier, then continue with the base address.
Allocate k dirty cells at the frontier, then continue with the base address.
Allocate a zeroed block of k cells, then continue with the block handle.
Allocate a zeroed block of k cells as a standalone program.
Allocate a field of k cells without clearing it, then continue with the field at the
frontier.
Allocate a dirty block of k cells as a standalone program.
Read entry i of an allocated block, then continue with its contents.
Write v to entry i of an allocated block, then continue.
Write v to entry i of an allocated block as a standalone program.
Sequential composition. Run p within c₁, and from each of its outcomes run the
continuation within c₂.
Dependent branching rule for if h : cond then p₁ h else p₂ h.
Memory that is zero above the frontier #
Every cell at or above the frontier holds 0, as in the word RAM's initial memory past the
input. A dirty allocation from such a state hands out a zeroed block at the cost of one unit.
The input convention is zero above the frontier.
Every admissible single operation preserves ZeroAbove.