Documentation

VCVio.Interaction.Basic.Chain

Continuation-style chains (Spec.Chain) #

A Chain n is a self-contained recipe for an n-round protocol: at each level it carries the current round's Spec and a transcript-indexed continuation to the next level. There is no external state type, no Stage : Nat → Type, and no round index family.

Converting to a Spec via Chain.toSpec uses only Spec.append. State-machine constructions are derived: Chain.ofStateMachine builds a chain from (σ, step, next, s₀) and then forgets σ.

Main definitions #

Three composition mechanisms #

MechanismState?Transcript-dependent?Use when
Spec.replicateNoNoUniform rounds (same spec, independent)
Spec.stateChainYes (Stage i)YesState machine with explicit state type
Spec.ChainNo (baked in)YesContinuation-style, no external state

Chain is the most fundamental: it requires no external state type, yet supports full transcript dependence. stateChain is a specialization (recovered by Chain.ofStateMachine), and replicate is a further specialization (recovered by Chain.replicate).

Toy examples #

The GrowingMessages section builds a protocol whose message type grows at each step (Fin 1, Fin 2, …) without mentioning any state type.

A self-contained recipe for an n-round protocol. At each level, carries the current round's Spec and, for each possible transcript, the recipe for the remaining rounds. No external state type.

Instances For

    Convert a chain into a concrete Spec via iterated append.

    Instances For
      theorem Interaction.Spec.Chain.toSpec_succ {n : } (spec : Spec) (cont : spec.TranscriptChain n) :
      toSpec (n + 1) spec, cont = spec.append fun (tr : spec.Transcript) => toSpec n (cont tr)

      Constructors #

      Constant rounds: same spec every round, continuation ignores the transcript.

      Instances For
        def Interaction.Spec.Chain.ofStateMachine {σ : Type u} (step : σSpec) (next : (s : σ) → (step s).Transcriptσ) (n : ) :
        σChain n

        Build a chain from a state machine. The state σ is consumed during construction and does not appear in the resulting Chain.

        Instances For

          Bridge to existing API #

          theorem Interaction.Spec.Chain.toSpec_replicate (spec : Spec) (n : ) :
          toSpec n (replicate spec n) = spec.replicate n

          Converting a replicate chain recovers Spec.replicate.

          theorem Interaction.Spec.Chain.toSpec_ofStateMachine {σ : Type u} (step : σSpec) (next : (s : σ) → (step s).Transcriptσ) (n i : ) (s : σ) :
          toSpec n (ofStateMachine step next n s) = stateChain (fun (x : ) => σ) (fun (x : ) => step) (fun (x : ) => next) n i s

          Converting a state-machine chain recovers Spec.stateChain with constant stage family and round index erased.

          Transcript operations #

          def Interaction.Spec.Chain.splitTranscript (n : ) (c : Chain (n + 1)) :
          (toSpec (n + 1) c).Transcript(tr₁ : c.fst.Transcript) × (toSpec n (c.snd tr₁)).Transcript

          Split a transcript of an (n+1)-round chain into the first round's transcript and the remainder.

          Instances For
            def Interaction.Spec.Chain.appendTranscript (n : ) (c : Chain (n + 1)) (tr₁ : c.fst.Transcript) (tr₂ : (toSpec n (c.snd tr₁)).Transcript) :
            (toSpec (n + 1) c).Transcript

            Combine a first-round transcript with a remainder.

            Instances For
              @[simp]
              theorem Interaction.Spec.Chain.splitTranscript_appendTranscript (n : ) (c : Chain (n + 1)) (tr₁ : c.fst.Transcript) (tr₂ : (toSpec n (c.snd tr₁)).Transcript) :
              splitTranscript n c (appendTranscript n c tr₁ tr₂) = tr₁, tr₂

              Strategy composition #

              def Interaction.Spec.Chain.outputFamily (Family : {n : } → Chain nType u) (n : ) (c : Chain n) :
              (toSpec n c).TranscriptType u

              Output family for strategy composition along a chain. This is the intrinsic analog of Transcript.stateChainFamily: a family on the remaining chain is lifted to a family on transcripts of the flattened Spec.

              Instances For
                def Interaction.Spec.Chain.strategyComp {m : Type u → Type u} [Monad m] {Family : {n : } → Chain nType u} (step : {n : } → (c : Chain (n + 1)) → Family cm (Strategy m c.fst fun (tr : c.fst.Transcript) => Family (c.snd tr))) (n : ) (c : Chain n) :
                Family cm (Strategy m (toSpec n c) (outputFamily (fun {n : } => Family) n c))

                Compose strategies along a chain with a transcript-dependent output family. The step function sees the current round spec packaged as the remaining chain, and returns the next family member indexed by the transcript of that round.

                Instances For

                  Toy example: growing message types #

                  Toy example: genuine transcript-prefix dependence #

                  Dependent strategy composition over the prefix-dependent example #