Weakest preconditions with cost #
D.wp charge p Q s is the weakest precondition of the client p of a deterministic
specification D, under a postcondition Q that sees the answer, the final state and the total
charge of the run. It holds when every operation of the run from s is admissible and Q holds
of the outcome (StateTransitionSpec.wp_iff). It is computed operation by operation
(wp_pure, wp_lift_bind), so a program's effect and cost follow by simp, and it composes
(wp_bind, wp_mono).
A postcondition that bounds the charge expresses an amortized inequality directly: Q a s' t
may say t + potential s' ≤ budget + potential s. A CostHoare triple, whose budget is a
function of the initial state, does not.
With the charge fun _ _ => 1 the cost is the number of operations (wp_one_iff). Over
Memory.spec w with Memory.charge it is the memory cost.
Main definitions #
StateTransitionSpec.wp: the weakest precondition with cost.
Main results #
StateTransitionSpec.wp_pure,StateTransitionSpec.wp_lift_bind,StateTransitionSpec.wp_lift: evaluation, operation by operation.StateTransitionSpec.wp_bind,StateTransitionSpec.wp_mono: sequencing and consequence.StateTransitionSpec.wp_iff,StateTransitionSpec.wp_one_iff: the weakest precondition holds exactly when the run is admissible and the postcondition holds of its answer, final state and total charge, or number of operations.
The weakest precondition of the client p under Q, with charges charge: every operation
of the run from s is admissible, and Q holds of the answer, the final state and the total
charge.
An operation followed by a continuation: the operation is admissible, and the continuation runs from the next state with the operation's charge added.
Consequence: a weaker postcondition.
Sequencing: the charge of p >>= k is the charge of p plus the charge of k.
The weakest precondition holds exactly when the run is admissible and Q holds of its
answer, final state and total charge.
With a unit charge, the weakest precondition counts operations.