Documentation

CslibFrontier.DataStructure.StateTransition.StepFunction

Backends given by a step function #

Many concrete backends are a total function taking a concrete state and an operation to the next state, the answer and a native trace (a cost count, say). This module states the execution relation, the client runner and the semantic implementation of such a backend once, so that each data structure supplies only its step function and its correctness proof.

Main definitions #

Main results #

structure Cslib.DataStructure.StepResult (C τ : Type x) (β : Type w) :
Type (max w x)

The outcome of one step of a concrete backend: the next state, the answer and a native trace.

  • state : C

    The concrete state after the step.

  • answer : β

    The answer returned to the client.

  • trace : τ

    The native trace of the step, such as its cost.

structure Cslib.DataStructure.RunResult (C τ : Type x) (α : Type u) :
Type (max u x)

The outcome of running an adaptive client on a concrete backend: the client's value, the final state and the native trace of each operation, in call order.

  • value : α

    The value returned by the client.

  • state : C

    The concrete state after the last operation.

  • traces : List τ

    The native traces of the operations, in call order.

@[reducible, inline]
abbrev Cslib.DataStructure.Execution.ofStep {S : PFunctor.{v, w}} {C τ : Type x} (step : C → (o : S.A) → StepResult C τ (S.B o)) :
Execution S C τ

The execution relation of a step function: c steps under o to c' with answer a and trace t exactly when step c o = ⟨c', a, t⟩.

def Cslib.DataStructure.Execution.run {S : PFunctor.{v, w}} {C τ : Type x} (step : C → (o : S.A) → StepResult C τ (S.B o)) {α : Type u} (c : C) :
S.FreeM α → RunResult C τ α

Run an adaptive client with a step function, recording the trace of each operation.

theorem Cslib.DataStructure.Execution.executes_run {S : PFunctor.{v, w}} {C τ : Type x} (step : C → (o : S.A) → StepResult C τ (S.B o)) {α : Type u} (p : S.FreeM α) (c : C) :
Executes (ofStep step) p c (run step c p).value (run step c p).state (run step c p).traces

The runner of a step function produces a derivation of its execution relation.

@[reducible, inline]
abbrev Cslib.DataStructure.StateTransitionImpl.ofStep {C τ : Type x} {D : StateTransitionSpec} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (rep : D.State → C → Prop) (step : C → (o : D.Op) → StepResult C τ (D.Result o)) (correct : ∀ {s : D.State} {c : C} (o : D.Op), rep s c → D.valid s o → (step c o).answer = (D.stepFn s o).2 ∧ rep (D.stepFn s o).1 (step c o).state) :

A semantic implementation of a deterministic specification by a step function. Totality holds because the step function is total, so only step correctness is required: from a represented state, every admissible operation answers as D.stepFn and reaches a represented state.