Documentation

Complexity.Computability.Ram.Verification.StateM.Frame

Framing native stateful models inside a larger state #

An implementation of an ordinary StateM model also implements the native modifyGet operation that runs that model on the left side of a product state. The returned value is unchanged and the right-hand model is retained through the existing heap frame rule. The resulting native stateful computation can be composed using Refines.stateM_bind and specified with Std's usual triples.

Only the ordinary model runs inside modifyGet; this is not an extra RAM instruction or a new evaluator. The source statement stays fixed. The same safe execution and proved endpoint frame justify the enlarged representation; disjointness, heap bounds and any original register conditions remain explicit.

theorem Ram.Source.Refines.stateM_frame_heap {w : ℕ} {α σ γ : Type u} {program : Program} {heapLimit depth : ℕ} {stmt : Stmt} {inputRep : σ → State w → Prop} {outputRep : α × σ → State w → Prop} {model : StateM σ α} (h : Refines program heapLimit depth stmt inputRep outputRep (StateT.run model)) (observed : γ → Set (Word w)) (writes : σ → Set (Word w)) (heapModel : γ → (Word w → Word w) → Prop) (depends : ∀ (z : γ) (before after : Word w → Word w), Set.EqOn after before (observed z) → heapModel z before → heapModel z after) (unchanged : ∀ (state : σ) (entry finish : State w), inputRep state entry → SafeExec program heapLimit depth stmt entry finish → outputRep (StateT.run model state) finish → Set.EqOn finish.mem entry.mem (writes state)ᶜ) :
Refines program heapLimit depth stmt (fun (x : σ × γ) (s : State w) => match x with | (state, z) => inputRep state s ∧ heapModel z s.mem ∧ Disjoint (observed z) (writes state)) (fun (result : Id (α × σ × γ)) (t : State w) => outputRep (result.1, result.2.1) t ∧ heapModel result.2.2 t.mem) (StateT.run (modifyGet fun (x : σ × γ) => match x with | (state, z) => have result := StateT.run model state; (result.1, result.2, z)))

Lift a native stateful implementation to a product state while retaining an unrelated represented heap object. The standard returned-value/final-state pair is reassociated internally, so subsequent native binds need no adapter.