Documentation

Complexity.Computability.Ram.Verification.Specification

Mathematical postconditions retained by compositional refinements #

Refines.with_postcondition attaches a proved property of the ordinary model result without leaving the refinement interface. The same pure function and RAM statement remain available to Refines.seq; the strengthened output representation supplies the mathematical fact to the next implementation.

Refines.stateM_spec_refines does the same for native Std.Do.Triple proofs, so a postcondition proved using mvcgen can be carried into stateM_bind. Unlike stateM_spec, this interface does not fix one initial state or hide the model result behind an existential contract postcondition.

These properties describe the chosen mathematical result, not every value that could represent the same machine state. Representation relations may be noninjective, including word encodings. No runtime assertion is inserted, and the existing safe terminating execution and separately proved costs are not changed. A property depending on the initial mathematical input can capture a fixed ghost in its closure or retain that input in the result's ghost model.

theorem Ram.Source.Refines.with_postcondition {w : Nat} {α : Type u_1} {β : Type u_2} {program : Program} {heapLimit depth : Nat} {stmt : Stmt} {inputRep : α → State w → Prop} {outputRep : β → State w → Prop} {f : α → β} (h : Refines program heapLimit depth stmt inputRep outputRep f) {P : α → Prop} {Q : β → Prop} (property : ∀ (x : α), P x → Q (f x)) :
Refines program heapLimit depth stmt (fun (x : α) (s : State w) => inputRep x s ∧ P x) (fun (y : β) (t : State w) => outputRep y t ∧ Q y) f

Retain a pure mathematical postcondition in the representation used by subsequent refinements. The input's mathematical precondition is explicit; no injectivity or converse interpretation of the output representation is assumed.

theorem Ram.Source.Refines.stateM_spec_refines {w : Nat} {program : Program} {heapLimit depth : Nat} {stmt : Stmt} {α σ : Type u} {model : StateM σ α} {inputRep : σ → State w → Prop} {outputRep : α × σ → State w → Prop} (h : Refines program heapLimit depth stmt inputRep outputRep (StateT.run model)) {P : σ → Prop} {Q : α → σ → Prop} (specification : ⦃fun (state : σ) => { down := P state }⦄ model ⦃(fun (result : α) (state : σ) => { down := Q result state }, PUnit.unit)⦄) :
Refines program heapLimit depth stmt (fun (state : σ) (s : State w) => inputRep state s ∧ P state) (fun (result : α × σ) (t : State w) => outputRep result t ∧ Q result.fst result.snd) (StateT.run model)

Carry a native stateful Hoare postcondition into later refinement composition. Both the returned value and final abstract state remain the ordinary pair produced by StateM.run, ready for Refines.stateM_bind.