← back to lean navigator

Hoare/Bridge.lean

ghView source on GitHub

Connects the contract infrastructure to Hoare triples: ContractPreserving is a triple with precondition True, and handshakes compose via the COMP rule. This bridge is one of several translations catalogued in the jkframework lexicon.

contract_is_triple

Contract preservation is exactly a Hoare triple with trivial precondition. ContractPreserving f Q is the same as {True} f {Q}. Both unfold to: for all inputs, all reachable outputs satisfy Q.

theorem contract_is_triple [Monad M] [Support M]
    {f : Kernel M α β} {Q : Contract β}
    : ContractPreserving f Q ↔ Triple (fun _ => True) f Q
Python

handshake_enables_comp

Handshake-compatible stages compose. If f establishes the handshake's postcondition and g requires the handshake's precondition, sequential composition carries P to R. The handshake's compatibility lemma (post implies pre) bridges the gap via the rule of consequence.

theorem handshake_enables_comp [Monad M] [LawfulMonad M] [Support M]
    {P : α → Prop} {R : γ → Prop}
    {f : Kernel M α β} {k : Kernel M β γ}
    (h : Handshake β)
    (hf : Triple P f h.post) (hk : Triple h.pre k R)
    : Triple P (Kernel.comp f k) R

triple_counterexample

Nontriviality: not every kernel satisfies every triple. A specific bad kernel (mapping unit to false) fails the triple {True} badKernel {b = true}. This demonstrates the proof system has teeth — it can reject kernels.

theorem triple_counterexample :
    ¬ Triple (fun (_ : Unit) => True) badKernel (· = true)

Connections

Neighbors