Documentation

CatCryptCore.Unary.Lossless

Losslessness for Stateful Probabilistic Computations #

This file defines the isLossless predicate for SPComp computations and proves that basic operations (pure, get, set, sample) are lossless, while fail is not.

A computation is lossless if it has total mass 1 from any initial heap, meaning it never fails (never produces the none outcome in the underlying sub-distribution).

Main definitions #

Main results #

References #

Losslessness predicates #

A computation is lossless if it has total mass 1 from any initial heap. This means the computation never fails.

Equations
Instances For
    def CatCrypt.Unary.isLosslessIf {α : Type u_1} (P : UPre) (c : Core.SPComp α) :

    Lossless with precondition: only requires mass 1 from heaps satisfying P.

    Equations
    Instances For

      Relationship between isLossless and isLosslessIf #

      theorem CatCrypt.Unary.isLossless_implies_if {α : Type u_1} (P : UPre) {c : Core.SPComp α} (h : isLossless c) :

      Unconditional losslessness implies conditional losslessness for any P.

      Conditional losslessness with truePre is equivalent to unconditional.

      Losslessness of basic operations #

      pure a is lossless: returning a value never fails.

      get l is lossless: reading from a location never fails.

      set l v is lossless: writing to a location never fails.

      fail is not lossless: it always fails (mass 0).

      The mass of fail is 0, as an explicit lemma for use in proofs.

      Helper lemmas for mass reasoning #

      Losslessness of sample #

      sample α is lossless: sampling from a finite nonempty type never fails.

      Losslessness of bind #

      theorem CatCrypt.Unary.lossless_bind {α : Type u_1} {β : Type u_2} {c : Core.SPComp α} {f : αCore.SPComp β} (hc : isLossless c) (hf : ∀ (a : α), isLossless (f a)) :

      Bind preserves losslessness: if c is lossless and f a is lossless for all a, then c.bind f is lossless.

      Proof idea: We need to show (c h).bind (fun (a, h') => f a h') none = 0. Since c is lossless, (c h) none = 0, so the none-to-none path contributes 0. For each (a, h') in the support of c h, f a h' is lossless, so (f a h') none = 0, meaning the some-to-none path also contributes 0.

      theorem CatCrypt.Unary.lossless_bind_of_support {α : Type u_1} {β : Type u_2} {c : Core.SPComp α} {f : αCore.SPComp β} (hc : isLossless c) (hf : ∀ (h : Core.Heap) (a : α) (h' : Core.Heap), (c h) (some (a, h')) 0isLossless (f a)) :

      Variant of lossless_bind with conditional losslessness for the continuation. The continuation only needs to be lossless for outcomes actually produced by c.

      Derived losslessness lemmas #

      Assert is lossless when the condition holds.

      Assert is not lossless when the condition fails.

      theorem CatCrypt.Unary.lossless_seq {α : Type u_1} {β : Type u_2} {c₁ : Core.SPComp α} {c₂ : Core.SPComp β} (h₁ : isLossless c₁) (h₂ : isLossless c₂) :
      isLossless (c₁.seq c₂)

      Sequential composition preserves losslessness.