Documentation

Strata.Languages.Core.Logic.ContractToHoareTripleProps

Discharging a procedure's contract #

Ways to establish a Procedure.contractTriple, and the bridges that make a concrete procedure's contract decidable. The definitions being established live in Strata.Languages.Core.Logic.ContractToHoareTriple.

Key results #

A snapshot of a procedure's non-free contract clauses as assert events is assertion-valid whenever every such clause evaluates to true in that snapshot.

theorem Core.Logic.Hoare.Procedure.contractTriple_of (φ : Expression.Factory → Imperative.PureFunc Expression → Expression.Factory) (p : Program) (params : InitEnvWFParams) (procName : String) (proc : Procedure) (bss : Statements) (hproc : p.findProcByString? procName = some proc) (hbody : proc.body = Imperative.Body.structured bss) (h : Triple p.findProcByString? φ params (preAsPredicate proc) [Imperative.Stmt.block "" bss #[]] (postAsPredicate proc)) :
contractTriple φ p params procName

Build a contractTriple from the name lookup, body, and body judgement. The factory, old-inout, and input-typing clauses of contractTriple's precondition are discarded by weakening, so the body proof needs none of them.

Build a contractTriple whose body proof may assume the concrete factory and old-inout relation but does not need input-value typing.

Build a contractTriple while retaining every entry fact, including values matching the types of the procedure's input and inout formals.

theorem Core.Logic.Hoare.Procedure.contractTriple_nil (φ : Expression.Factory → Imperative.PureFunc Expression → Expression.Factory) (p : Program) (params : InitEnvWFParams) (procName : String) (proc : Procedure) (hproc : p.findProcByString? procName = some proc) (hbody : proc.body = Imperative.Body.structured []) (himp : ∀ (label : CoreLabel) (check : Procedure.Check), (label, check) ∈ proc.spec.postconditions.toList → check.attr = Procedure.CheckAttr.Default → ∃ (label' : CoreLabel), ∃ (check' : Procedure.Check), (label', check') ∈ proc.spec.preconditions.toList ∧ check'.expr = check.expr) :
contractTriple φ p params procName

A contract whose every non-free ensures is literally one of the requires is met by an empty body: nothing runs, so the precondition still holds at the end.

The workhorse is skip_block plus consequence; no reasoning about Expression.eval is involved, because the same check expression carries from the precondition to the postcondition.

The decidable check preHoldsAt discharges the proposition preAsPredicate.

The decidable check postRefutedAt refutes the proposition postAsPredicate: the clause it finds is a non-free ensures that does not hold.

An empty body meets a contract whose non-free ensures clauses are all among its requires, with the containment settled by the decidable ensuresAmongRequires.

A one-command body. The cmd rule reduces a contract over [.cmd c] to a single semantic obligation about c. hsem receives the precondition clauses, concrete factory, and old-inout relation; signature typing is weakened away because this constructor does not require it. hpost_proj ensures the postcondition names no variable declared by c, since the block drops those.