Documentation

CatCryptCore.Core.SPTree

SPTree: Syntactic Computation Trees for SPComp #

This file defines SPTree α, a syntactic (free-monad-like) representation of stateful probabilistic computations. Unlike SPComp α = Heap → SDistr (α × Heap) (which is denotational), SPTree preserves syntactic structure, enabling cost analysis by structural recursion.

Main definitions #

Main results #

SPTree Definition #

inductive CatCrypt.Core.SPTree :
TypeType 1

Syntactic computation tree for stateful probabilistic programs.

Lives in Type 1 because sample quantifies over β : Type.

Instances For

    Compilation to SPComp #

    Query Cost #

    Worst-case operation count: counts sample + get + set operations. Uses Finset.univ.sup for branching to take the maximum cost across all possible continuations. Structurally recursive.

    Equations
    Instances For

      Monadic Bind (Substitution at Leaves) #

      def CatCrypt.Core.SPTree.bind {α β : Type} :
      SPTree α(αSPTree β)SPTree β

      Monadic bind: substitute f at every ret leaf of s.

      Equations
      Instances For

        Simp Lemmas #

        @[simp]
        @[simp]
        theorem CatCrypt.Core.SPTree.queryCost_ret {α : Type} (a : α) :
        @[simp]
        theorem CatCrypt.Core.SPTree.bind_ret_val {α β : Type} (a : α) (f : αSPTree β) :
        (ret a).bind f = f a
        @[simp]
        theorem CatCrypt.Core.SPTree.bind_fail {α β : Type} (f : αSPTree β) :

        Compile-Bind Correctness #

        theorem CatCrypt.Core.SPTree.compile_bind {α β : Type} (s : SPTree α) (f : αSPTree β) :
        (s.bind f).compile = s.compile.bind fun (a : α) => (f a).compile

        Compilation commutes with monadic bind.

        Query Cost Bound for Bind #

        theorem CatCrypt.Core.SPTree.queryCost_bind {α β : Type} (s : SPTree α) (f : αSPTree β) (bound : ) (hf : ∀ (a : α), (f a).queryCost bound) :
        (s.bind f).queryCost s.queryCost + bound

        Cost of bind ≤ cost of tree + uniform bound on continuation.

        Monad Laws #

        theorem CatCrypt.Core.SPTree.ret_bind {α β : Type} (a : α) (f : αSPTree β) :
        (ret a).bind f = f a
        theorem CatCrypt.Core.SPTree.bind_assoc {α β γ : Type} (s : SPTree α) (f : αSPTree β) (g : βSPTree γ) :
        (s.bind f).bind g = s.bind fun (a : α) => (f a).bind g