Machine certificates for stateful controllers #
Refines relates a mathematical free-monad client to a fixed structured RAM program. Unlike
an operation-count contract, its budget bounds an actual execution, including controller
instructions and argument preparation. The final halt is added by Refines.executes_demonic
(and Refines.executes for deterministic specifications).
The intermediate assertions record how answers are represented in registers or memory. The
bind rule uses one continuation code fragment for every intermediate answer: Lean's semantic
continuation is not an uncharged machine computation. Likewise returning a pure answer requires
an execution certificate. Initialization is supplied as code using Refines.prepend.
Main definitions #
Refines: demonic caller admissibility, angelic client run semantics, and bounded RAM execution with a relational postcondition.
Main results #
refines_iff_ofFn: equivalence with the functionalrunClientformulation on deterministic specifications ([D.HasStepFn f]).Refines.bind,Refines.bind_ofFn,Refines.branch: sequential and conditional controller certificates.Refines.call: inlining a dynamic operation after charged register preparation.Refines.executes_demonic,Refines.executes: a complete flat-program run, including its final halt.
References #
The clients reuse Quang Dao's upstream PFunctor.FreeM. Machine execution and assembly reuse
the word-RAM calculus based on the lean-trominoes formalization; see WordRAM.Defs.
A fixed machine fragment certifies that the client p is demonically admissible
(D.DemonicValid) and implements a permitted D.ClientRun and its result/state representation,
within a bound depending on the initial abstract and concrete states.
As for ExecWithin, word boundedness is an entry assertion obligation: include Data.Bounded
in pre when reasoning about arbitrary machine data. Standard Data.init inputs are bounded
whenever InputFits holds.
Instances For
On a deterministic specification ([D.HasStepFn f]), Refines is equivalent to
D.ValidHistory s (D.clientHistory s p) and post (D.clientResult s p) (D.clientState s p) y.
Construct a Refines proof on a deterministic specification ([D.HasStepFn f]) from
D.ValidHistory and D.clientResult / D.clientState / D.clientHistory.
Unpack a Refines proof on a deterministic specification ([D.HasStepFn f]) into
D.ValidHistory and D.clientResult / D.clientState / D.clientHistory.
Strengthen an entry assertion, weaken the exit assertion, or increase the instruction bound.
Even a pure semantic computation needs actual code realizing its output assertion.
Compose with one fixed continuation fragment valid for every represented intermediate answer.
The continuation budget is evaluated at the state actually reached by the first fragment, while
hvalid ensures demonic continuation admissibility across all permitted specification outcomes of
p.
On a deterministic specification ([D.HasStepFn f]), sequential composition automatically
discharges demonic continuation admissibility from hk at the unique reached outcome.
A machine branch must test the same proposition as the semantic client. Both paths include all their control instructions; the common bound allows the larger two-instruction overhead.
Charge initialization or argument computation preceding a certified client. The prefix preserves the abstract initial state, while establishing its concrete entry representation.
Discharge a client's abstract postcondition using an independently proved semantic contract.
A certificate produces a real halting machine execution realizing a valid D.ClientRun.
On a deterministic specification ([D.HasStepFn f]), a certificate produces a real halting
machine execution returning encode (D.clientResult s p).
Inline a dynamic operation after a machine-certified preparation fragment. The body bound excludes a halt because execution continues in the caller; only the complete program halts.