Resource contracts across stateful interfaces #
A client contract combines demonic admissibility, a postcondition and a bound on state-dependent operation charges across all permitted client runs. Semantic modules transport these contracts using separate method budgets; native implementations then interpret the charges as additive measures of execution evidence. This supports proofs at several interface levels without choosing a backend in the client proof.
These are operation-cost contracts. Pure results and host-language continuations incur no charge in this interpretation. A total machine-time theorem additionally needs certificates for the controller, argument preparation and result decoding.
Main definitions #
StateTransitionSpec.CostHoare: a demonic semantic client contract with an initial-state-dependent budget.Module.ChargeBound: lower method costs are bounded by upper operation charges.
Main results #
StateTransitionSpec.CostHoare.pure,StateTransitionSpec.CostHoare.call,StateTransitionSpec.CostHoare.call_ofFn,StateTransitionSpec.CostHoare.bind,StateTransitionSpec.CostHoare.consequence: compositional contract rules.StateTransitionSpec.costHoare_iff_ofFn: equivalence with the functionalrunClientformulation on deterministic specifications ([D.HasStepFn f]).Module.ChargeBound.demonic,Module.ChargeBound.client,Module.ChargeBound.comp,Module.ChargeBound.realize: transfer and compose method resource bounds across linked clients and implementations.StateTransitionSpec.CostHoare.link: transport a contract to a lower interface.StateTransitionSpec.CostHoare.realize,StateTransitionSpec.CostHoare.realize_amortized,StateTransitionSpec.CostHoare.exists_executes: native correctness, bounds and existence.
References #
Demonic CostHoare triple: strengthens D.Hoare with a worst-case abstract charge bound
D.totalCostTranscript charge s tr ≤ budget s across every valid ClientRun.
The budget is evaluated at the initial state; it does not charge pure Lean computation.
Instances For
On a deterministic specification ([D.HasStepFn f]), D.CostHoare is equivalent to
D.Hoare pre p post ∧ ∀ s, pre s → D.totalCost charge s (D.clientHistory s p) ≤ budget s.
Forget the resource bound while retaining semantic correctness.
Returning a value has zero operation cost.
Calling a single operation requires D.valid s o, establishes post a s' for every permitted
outcome D.step s o s' a, and charges charge s o at the pre-state s.
On a deterministic specification ([D.HasStepFn f]), calling an operation exposes
(D.stepFn s o) and charges charge s o.
Compose budgets at every intermediate abstract state satisfying mid.
Strengthen the precondition and weaken the postcondition or budget.
Transport a demonic CostHoare triple through an Amortized certificate to bound native
execution weight plus final potential by budget s + potential s c.
Every supplied native execution satisfies the contract and its interpreted resource bound.
A represented initial state has a native execution meeting the contract and budget.
Construct a ChargeBound on a deterministic lower specification ([E.HasStepFn fE]) from a
functional totalCost inequality along clientHistory.
Method budgets compose along any demonically admissible client execution.
Method budgets compose along the actual answer-dependent history of a client on deterministic specifications.
Resource refinements compose while keeping the intermediate representation hidden.
A method budget and a lower native certificate supply an upper native certificate.
Transport a client contract and its budget across an interface implementation.