Documentation

Complexity.Language.Session.Refinement

Mathematical refinement of persistent source sessions #

A single-step refinement relates ordinary mathematical state to an actual source value and heap. Replies use the existing heap-indexed Representation, at their own return-time heaps. The state relation may retain ghost invariants and does not choose, encode or reload a runtime state.

Finite mathematical histories reuse Lean's List.mapM in StateM. They are proof models, not source callbacks or a second implementation. The fixed request encoding describes the arguments already supplied at each call; it is not a runtime loader. Reference-bearing external inputs still need a loading protocol. Admissibility may depend on the mathematical state, so a completed protocol need not accept another request. ValidInputs checks only the legal history in a proof.

The total refinement constructs successful source traces, and also describes any actual trace of the same entries, including the source projection of a RAM run. Neither statement requires a machine width or a time budget.

def Complexity.Language.Session.modelRun {σ ι β : Type u} (step : σ → ι → β × σ) (inputs : List ι) (state : σ) :
List β × σ

Ordinary left-to-right stateful list traversal, used only as a proof model.

Equations
Instances For
    @[simp]
    theorem Complexity.Language.Session.modelRun_nil {σ ι β : Type u} (step : σ → ι → β × σ) (state : σ) :
    modelRun step [] state = ([], state)
    @[simp]
    theorem Complexity.Language.Session.modelRun_cons {σ ι β : Type u} (step : σ → ι → β × σ) (input : ι) (inputs : List ι) (state : σ) :
    modelRun step (input :: inputs) state = ((step state input).1 :: (modelRun step inputs (step state input).2).1, (modelRun step inputs (step state input).2).2)
    def Complexity.Language.Session.ValidInputs {σ ι β : Type u} (admissible : σ → ι → Prop) (step : σ → ι → β × σ) :
    σ → List ι → Prop

    Each request is admissible at its own mathematical state. This proof-side history condition does not pass a future sequence to either source entry.

    Equations
    Instances For
      def Complexity.Language.Session.StepRefines {configuration request : List Ty} {response : Ty} {σ ι β : Type u} (session : Session configuration request response) (encode : ι → Env request) (output : Representation β response) (relation : σ → Value session.stateTy → Heap → Prop) (admissible : σ → ι → Prop) (step : σ → ι → β × σ) :

      Total correspondence of one actual source step to an ordinary mathematical transition. The state relation observes the actual heap, without a chosen encoder, unique runtime representation or disjoint-ownership assumption.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Complexity.Language.Session.StepRefines.run {configuration request : List Ty} {response : Ty} {session : Session configuration request response} {σ ι β : Type u} {encode : ι → Env request} {output : Representation β response} {relation : σ → Value session.stateTy → Heap → Prop} {admissible : σ → ι → Prop} {step : σ → ι → β × σ} (refinement : session.StepRefines encode output relation admissible step) {abstract : σ} {state : Value session.stateTy} {heap : Heap} (represented : relation abstract state heap) (inputs : List ι) (legal : ValidInputs admissible step abstract inputs) :
        ∃ (replies : List (Value response × Heap)) (finish : Value session.stateTy) (finalHeap : Heap), session.Run state heap (List.map encode inputs) replies finish finalHeap ∧ List.Forall₂ (fun (expected : β) (observed : Value response × Heap) => output.Rel expected observed.1 observed.2) (modelRun step inputs abstract).1 replies ∧ relation (modelRun step inputs abstract).2 finish finalHeap

        A total single-step refinement constructs a finite trace with exactly the model's replies and final state observation. Requests remain environment data.

        theorem Complexity.Language.Session.StepRefines.post_of_run {configuration request : List Ty} {response : Ty} {session : Session configuration request response} {σ ι β : Type u} {encode : ι → Env request} {output : Representation β response} {relation : σ → Value session.stateTy → Heap → Prop} {admissible : σ → ι → Prop} {step : σ → ι → β × σ} (refinement : session.StepRefines encode output relation admissible step) {abstract : σ} {state finish : Value session.stateTy} {heap finalHeap : Heap} (represented : relation abstract state heap) (inputs : List ι) (legal : ValidInputs admissible step abstract inputs) {replies : List (Value response × Heap)} (run : session.Run state heap (List.map encode inputs) replies finish finalHeap) :
        List.Forall₂ (fun (expected : β) (observed : Value response × Heap) => output.Rel expected observed.1 observed.2) (modelRun step inputs abstract).1 replies ∧ relation (modelRun step inputs abstract).2 finish finalHeap

        The same refinement describes an already supplied actual trace, not only a separately selected successful witness. This is the entry for RAM source erasure.

        theorem Complexity.Language.Session.Starts.deterministic {configuration request : List Ty} {response : Ty} {session : Session configuration request response} {args : Env configuration} {heap : Heap} {state₁ state₂ : Value session.stateTy} {finish₁ finish₂ : Heap} (first : session.Starts args heap state₁ finish₁) (second : session.Starts args heap state₂ finish₂) :
        state₁ = state₂ ∧ finish₁ = finish₂

        A successful initializer has one actual state and heap.

        theorem Complexity.Language.Session.Run.deterministic {configuration request : List Ty} {response : Ty} {session : Session configuration request response} {state finish₁ finish₂ : Value session.stateTy} {heap finalHeap₁ finalHeap₂ : Heap} {inputs : List (Env request)} {replies₁ replies₂ : List (Value response × Heap)} (first : session.Run state heap inputs replies₁ finish₁ finalHeap₁) (second : session.Run state heap inputs replies₂ finish₂ finalHeap₂) :
        replies₁ = replies₂ ∧ finish₁ = finish₂ ∧ finalHeap₁ = finalHeap₂

        Any two successful traces from the same actual state and heap have the same replies, including their return-time heaps, and the same final observation.

        theorem Complexity.Language.Session.Runs.deterministic {configuration request : List Ty} {response : Ty} {session : Session configuration request response} {args : Env configuration} {heap finalHeap₁ finalHeap₂ : Heap} {finish₁ finish₂ : Value session.stateTy} {inputs : List (Env request)} {replies₁ replies₂ : List (Value response × Heap)} (first : session.Runs args heap inputs replies₁ finish₁ finalHeap₁) (second : session.Runs args heap inputs replies₂ finish₂ finalHeap₂) :
        replies₁ = replies₂ ∧ finish₁ = finish₂ ∧ finalHeap₁ = finalHeap₂

        Initialization and all subsequent actual steps have unique observations. This aligns an independently proved source postcondition with a costed run.

        theorem Complexity.Language.Session.StepRefines.runs {configuration request : List Ty} {response : Ty} {session : Session configuration request response} {σ ι β : Type u} {encode : ι → Env request} {output : Representation β response} {relation : σ → Value session.stateTy → Heap → Prop} {admissible : σ → ι → Prop} {step : σ → ι → β × σ} (refinement : session.StepRefines encode output relation admissible step) {args : Env configuration} {heap : Heap} {abstract : σ} (initialized : ∃ (state : Value session.stateTy) (initialHeap : Heap), session.Starts args heap state initialHeap ∧ relation abstract state initialHeap) (inputs : List ι) (legal : ValidInputs admissible step abstract inputs) :
        ∃ (replies : List (Value response × Heap)) (finish : Value session.stateTy) (finalHeap : Heap), session.Runs args heap (List.map encode inputs) replies finish finalHeap ∧ List.Forall₂ (fun (expected : β) (observed : Value response × Heap) => output.Rel expected observed.1 observed.2) (modelRun step inputs abstract).1 replies ∧ relation (modelRun step inputs abstract).2 finish finalHeap

        Attach a proved initialization to the same finite source refinement. The supplied start includes its actual heap, not a reconstructed model state.

        theorem Complexity.Language.Session.StepRefines.post_of_runs {configuration request : List Ty} {response : Ty} {session : Session configuration request response} {σ ι β : Type u} {encode : ι → Env request} {output : Representation β response} {relation : σ → Value session.stateTy → Heap → Prop} {admissible : σ → ι → Prop} {step : σ → ι → β × σ} (refinement : session.StepRefines encode output relation admissible step) {args : Env configuration} {heap : Heap} {abstract : σ} (initialized : ∃ (state : Value session.stateTy) (initialHeap : Heap), session.Starts args heap state initialHeap ∧ relation abstract state initialHeap) (inputs : List ι) (legal : ValidInputs admissible step abstract inputs) {replies : List (Value response × Heap)} {finish : Value session.stateTy} {finalHeap : Heap} (run : session.Runs args heap (List.map encode inputs) replies finish finalHeap) :
        List.Forall₂ (fun (expected : β) (observed : Value response × Heap) => output.Rel expected observed.1 observed.2) (modelRun step inputs abstract).1 replies ∧ relation (modelRun step inputs abstract).2 finish finalHeap

        Transfer ordinary mathematical observations to any initialized actual source trace, so a separate cost proof cannot silently choose a different computation.