Admissibility and loop-invariant combinators for Memory.Prog #
This module provides width-independent reasoning principles for Memory.Prog clients over
Memory.spec:
- Primitive
clientState,clientResult, andmemoryCostequations: closed-form reductions forMemory.read,Memory.write,Memory.alloc,Memory.allocDirty, and conditional branches (memoryCost_ite). - Monotone state invariants and
ValidHistoryrules:MonotoneMemInv(synthesized forMemory.WellFormed, frontier lower boundsF ≤ s.frontierandF < s.frontier, and conjunctions),wellFormed_clientState, and structuralValidHistorydecomposition rules. - Loop-invariant and
memoryCostcombinators: step-invariant transport acrossiterateandboundedWhile, read-only loop state preservation, and constant per-stepmemoryCostbounds.
Main definitions #
MonotoneMemInv: memory-state invariant preserved by any admissibleMemory.Progstep.PreservesAt: a program leaves one memory address unchanged.
Main results #
clientState_read,clientResult_read,clientState_write,clientResult_write,clientState_allocDirty,clientResult_allocDirty,runClient_allocDirty,runClient_ite,prog_clientState_ite,prog_clientResult_ite,state_frontier_ite,state_mem_ite,memoryCost_read,memoryCost_write,memoryCost_alloc,memoryCost_allocDirty,memoryCost_ite: primitive state, result, and cost equations.wellFormed_clientState,validHistory_pure,validHistory_read,validHistory_write,validHistory_alloc,validHistory_allocDirty,validHistory_allocDirty_bind,validHistory_bind_step,validHistory_read_bind,validHistory_write_bind,validHistory_ite,validHistory_dite,validHistory_iterate_inv,validHistory_boundedWhile_inv: monadic admissibility combinators.boundedWhile_invariant_of,iterate_invariant_of,iterationSafe_of_stepInv,clientState_iterate_eq_of,clientState_boundedWhile_eq_of,memoryCost_iterate_le_of,memoryCost_iterate_le_potential: generic loop invariant and cost lemmas, including an amortized bound with a potential.clientResult_bind_read,clientState_bind_write,runClient_read,runClient_write,memoryCost_bind_le,memoryCost_read_bind_le,memoryCost_write_bind_le,memoryCost_ite_le,validHistory_iterate_nat,validHistory_iterate_fst: reductions through primitive steps and cost and admissibility combinators for counting loops.PreservesAt,preservesAt_bind,preservesAt_iterate,preservesAt_iterate_nat: single-address frames.
Primitive client state, result, and cost equations #
Running Memory.allocDirty advances the frontier by k and returns the old frontier.
Split ValidHistory across Memory.allocDirty k >>= q directly in closed form.
Push memoryCost inside a conditional Memory.Prog branch.
Monotone memory invariants and ValidHistory combinators #
Admissible Memory.Prog execution preserves Memory.WellFormed w.
A predicate on Memory.State preserved across every admissible Memory.Prog step at width
w. Synthesized automatically for Memory.WellFormed w, frontier lower bounds F ≤ s.frontier
and F < s.frontier, and conjunctions.
- pres {α : Type} {s : DataStructure.Memory.State} {p : DataStructure.Memory.Prog α} : Inv s → (DataStructure.Memory.spec w).ValidHistory s ((DataStructure.Memory.spec w).clientHistory s p) → Inv ((DataStructure.Memory.spec 0).clientState s p)
Instances
Admissibility of pure a is trivial.
Admissibility of a single Memory.read a.
Admissibility of a single Memory.write a v.
Admissibility of a single Memory.alloc k.
Admissibility of a single Memory.allocDirty k.
Split ValidHistory across p >>= q at width-0 intermediate state and result.
Split ValidHistory across Memory.read a >>= q directly in closed form.
Split ValidHistory across Memory.write a v >>= q directly in closed form.
Split ValidHistory across if c then p₁ else p₂.
Split ValidHistory across dependent if h : c then p₁ h else p₂ h.
ValidHistory of iterate given a MonotoneMemInv body certificate.
ValidHistory of boundedWhile given a MonotoneMemInv body certificate.
Generic loop-invariant, read-only, and cost lemmas #
An invariant I a s preserved by each guarded step of boundedWhile holds on exit.
A step-indexed invariant I j a s preserved by body establishes iterationSafe.
A step-indexed invariant I j a s preserved by body reaches I 0 after n steps of
iterate.
A read-only iterate loop leaves clientState unchanged.
A read-only boundedWhile loop leaves clientState unchanged.
Constant upper bound on memoryCost of an iterate loop with fixed environment d.
Amortized memoryCost bound for iterate: if every step from a state satisfying the
step-indexed invariant I costs at most c plus the drop of the potential Φ, and preserves I,
then m steps cost at most c * m plus the initial potential.
Reductions through read, write, map, and cost combinators #
Running Memory.read returns the stored word, leaves memory unchanged, and logs the read.
Add this and runClient_write with attribute [local client_simps] when simplifying runClient
projections directly.
Running Memory.write updates the cell at a, preserves the frontier, and logs the write.
A read followed by a continuation of cost at most k costs at most k + 1.
A write followed by a continuation of cost at most k costs at most k + 1.
ValidHistory of a counting iterate loop whose step returns its index plus one.
ValidHistory of an iterate loop whose state carries a counter in its first component.
Single-address frames #
p leaves memory address a unchanged from every starting state.
Frame of a counting iterate loop whose step returns its index plus one: only the steps
i < m that actually run need to preserve a.