Documentation

VCVio.OracleComp.EvalDist

Output Distribution of Computations #

This file defines the MonadLiftT-based probability and support semantics for OracleComp.

class OracleSpec.IsProbabilitySpec {ι : Type u_1} (spec : OracleSpec ι) :
Type (max u_1 u_2)

A per-query distribution on an OracleSpec. Each query index t : ι is assigned a PMF (spec t) for its responses. This is the abstract data needed to lift OracleComp spec into PMF; uniformity is not assumed — see IsUniformSpec for the uniform-sampling specialization.

Specs that should opt into uniform sampling are best registered via IsUniformSpec, which extends this class and additionally carries Fintype / Inhabited on each range plus a propositional witness that toPMF is the canonical uniform distribution.

  • toPMF (t : ι) : PMF (spec t)

    The distribution of responses to query t.

Instances
    class OracleSpec.IsUniformSpec {ι : Type u_1} (spec : OracleSpec ι) extends spec.IsProbabilitySpec :
    Type (max u_1 u_2)

    An OracleSpec whose responses are uniformly sampled from finite, inhabited ranges. Bundles spec.Fintype, spec.Inhabited, and IsProbabilitySpec spec together with a Prop witness that the per-query distribution agrees with PMF.uniformOfFintype. Use this as the canonical input to lemmas that mention Fintype.card (spec.Range _) or PMF.uniformOfFintype in their statements.

    Instances
      @[reducible]
      noncomputable def OracleSpec.IsUniformSpec.ofFintypeInhabited {ι : Type u} (spec : OracleSpec ι) [hF : spec.Fintype] [hI : spec.Inhabited] :

      Bridge from [spec.Fintype] [spec.Inhabited] to IsUniformSpec spec. Deliberately not an instance — IsUniformSpec must be opted into per spec so that uniform-sampling semantics never attach silently to a spec whose author didn't intend a probabilistic interpretation. Use this helper when declaring IsUniformSpec for a concrete spec.

      Instances For
        @[implicit_reducible]
        @[implicit_reducible]
        @[implicit_reducible]
        noncomputable instance OracleSpec.instIsUniformSpecAdd {ι : Type u_1} {ι' : Type u_2} (spec : OracleSpec ι) (spec' : OracleSpec ι') [spec.IsUniformSpec] [spec'.IsUniformSpec] :
        (spec + spec').IsUniformSpec

        Propagate IsUniformSpec through +: each summand's uniformity is preserved on its branch. IsProbabilitySpec (spec + spec') is derived via the extends chain.

        @[deprecated OracleSpec.IsUniformSpec (since := "2026-05-20")]
        def OracleSpec.IsProbSpec {ι : Type u_1} (spec : OracleSpec ι) :
        Type (max u_1 u_2)

        Successor to the legacy empty marker OracleSpec.IsProbSpec. The replacement IsUniformSpec bundles Fintype, Inhabited, IsProbabilitySpec, and a uniformity witness.

        Instances For
          @[implicit_reducible]
          noncomputable instance OracleComp.instMonadLiftTPMF {ι : Type u_1} {spec : OracleSpec ι} [spec.IsProbabilitySpec] :

          Embed OracleComp into PMF by interpreting each query via the per-query distribution provided by IsProbabilitySpec.

          @[implicit_reducible]
          instance OracleComp.instMonadLiftTSetM {ι : Type u_1} {spec : OracleSpec ι} :

          Direct MonadLiftT (OracleComp spec) SetM: the syntactic / operational support of mx, computed by folding queries to Set.univ. Independent of any probability structure on spec — works for arbitrary specs without Fintype or Inhabited. The bridge to the probability side is EvalDistCompatible below, supplied only when [IsUniformSpec spec].

          Note: This is the only MonadLiftT (OracleComp spec) SetM instance Lean will find. The generic MonadLiftT SPMF SetM is declared as MonadLiftT (not MonadLift), so monadLiftTrans cannot chain OracleCompSPMFSetM.

          Abstract distribution of a single lifted query under IsProbabilitySpec: the per-query distribution toPMF is pushed forward through the query's continuation. Uniform-content sibling: evalDist_liftM.

          liftM (query t) : OracleComp spec _ evaluates to the per-query distribution IsProbabilitySpec.toPMF t, lifted to SPMF.

          @[simp]
          theorem OracleComp.support_liftM {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} (q : OracleQuery spec α) :
          theorem OracleComp.mem_support_liftM_iff {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} (q : OracleQuery spec α) (u : α) :
          u support (liftM q) ∃ (t : spec.Range q.input), q.cont t = u
          theorem OracleComp.mem_support_query {ι : Type u_1} {spec : OracleSpec ι} (t : spec.Domain) (u : spec.Range t) :
          theorem OracleComp.bind_congr_of_forall_mem_support {ι : Type u_1} {spec : OracleSpec ι} {α β : Type w} (mx : OracleComp spec α) {f g : αOracleComp spec β} (h : xsupport mx, f x = g x) :
          mx >>= f = mx >>= g

          Support-aware bind congruence: if two continuations agree on all elements in the support of mx, the resulting bind computations are equal.

          @[simp]
          theorem OracleComp.support_finite {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.Fintype] (mx : OracleComp spec α) :
          @[implicit_reducible]
          instance OracleComp.instHasEvalFinset {ι : Type u_1} {spec : OracleSpec ι} [spec.Fintype] :

          Finite version of support for when oracles have a finite set of possible outputs. NOTE: we can't use simulateQ because Finset lacks a Monad instance.

          @[simp]
          theorem OracleComp.finSupport_liftM {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.Fintype] [DecidableEq α] (q : OracleQuery spec α) :
          theorem OracleComp.mem_finSupport_liftM_iff {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.Fintype] [DecidableEq α] (q : OracleQuery spec α) (x : α) :
          x finSupport (liftM q) ∃ (t : spec.Range q.input), q.cont t = x
          theorem OracleComp.mem_finSupport_query {ι : Type u_1} {spec : OracleSpec ι} [spec.Fintype] [spec.DecidableEq] (t : spec.Domain) (u : spec.Range t) :
          @[simp]
          theorem OracleComp.evalDist_liftM {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (q : OracleQuery spec α) :
          @[simp]
          @[simp]
          theorem OracleComp.probOutput_liftM_eq_div {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (q : OracleQuery spec α) (x : α) :
          Pr[= x | liftM q] = (∑' (u : spec.Range q.input), Pr[= x | pure (q.cont u)]) / (Fintype.card (spec.Range q.input))
          @[simp]
          theorem OracleComp.probOutput_query {ι : Type u_1} {spec : OracleSpec ι} [spec.IsUniformSpec] (t : spec.Domain) (u : spec.Range t) :
          theorem OracleComp.probEvent_liftM_eq_div {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (q : OracleQuery spec α) (p : αProp) :
          probEvent (liftM q) p = (∑' (u : spec.Range q.input), probEvent (pure (q.cont u)) p) / (Fintype.card (spec.Range q.input))
          theorem OracleComp.probOutput_query_eq_div {ι : Type u_1} {spec : OracleSpec ι} [spec.IsUniformSpec] (t : spec.Domain) (u : spec.Range t) :
          @[simp]
          theorem OracleComp.probEvent_query {ι : Type u_1} {spec : OracleSpec ι} [spec.IsUniformSpec] (t : spec.Domain) (p : spec.Range tProp) [DecidablePred p] :
          probEvent (liftM (OracleSpec.query t)) p = {x : spec.Range t | p x}.card / (Fintype.card (spec.Range t))

          OracleComp spec admits the bridge between its direct support semantics and the SPMF.support of its evalDist.

          @[simp]
          theorem OracleComp.mem_support_evalDist_iff {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (oa : OracleComp spec α) (x : α) :

          An output has non-zero probability in evalDist iff it is in computation support.

          theorem OracleComp.mem_support_of_mem_support_evalDist {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (oa : OracleComp spec α) (x : α) :

          Alias of the forward direction of OracleComp.mem_support_evalDist_iff.


          An output has non-zero probability in evalDist iff it is in computation support.

          theorem OracleComp.mem_support_evalDist {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (oa : OracleComp spec α) (x : α) :

          Alias of the reverse direction of OracleComp.mem_support_evalDist_iff.


          An output has non-zero probability in evalDist iff it is in computation support.

          @[simp]
          theorem OracleComp.mem_support_evalDist_iff' {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (oa : OracleComp spec α) (x : α) [DecidableEq α] :

          Finite-support variant of mem_support_evalDist_iff.

          theorem OracleComp.mem_finSupport_of_mem_support_evalDist {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (oa : OracleComp spec α) (x : α) [DecidableEq α] :

          Alias of the forward direction of OracleComp.mem_support_evalDist_iff'.


          Finite-support variant of mem_support_evalDist_iff.

          theorem OracleComp.mem_support_evalDist' {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (oa : OracleComp spec α) (x : α) [DecidableEq α] :

          Alias of the reverse direction of OracleComp.mem_support_evalDist_iff'.


          Finite-support variant of mem_support_evalDist_iff.

          @[simp]
          theorem OracleComp.probFailure_eq_zero_iff {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsProbabilitySpec] (oa : OracleComp spec α) :
          @[simp]
          theorem OracleComp.probFailure_pos_iff {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsProbabilitySpec] (oa : OracleComp spec α) :
          theorem OracleComp.noFailure_of_probFailure_eq_zero {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsProbabilitySpec] {oa : OracleComp spec α} (h : Pr[⊥ | oa] = 0) :
          theorem OracleComp.not_noFailure_of_probFailure_pos {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsProbabilitySpec] {oa : OracleComp spec α} (h : 0 < Pr[⊥ | oa]) :
          theorem OracleComp.evalDist_query_bind {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (t : spec.Domain) (ou : spec.Range tOracleComp spec α) :
          theorem OracleComp.probOutput_congr {ι : Type u_1} {ι' : Type u_2} {spec : OracleSpec ι} {spec' : OracleSpec ι'} {α : Type w} [spec.IsUniformSpec] [spec'.IsProbabilitySpec] {x y : α} {oa : OracleComp spec α} {oa' : OracleComp spec' α} (h1 : x = y) (h2 : 𝒟[oa] = 𝒟[oa']) :
          Pr[= x | oa] = Pr[= y | oa']
          theorem OracleComp.probEvent_congr' {ι : Type u_1} {ι' : Type u_2} {spec : OracleSpec ι} {spec' : OracleSpec ι'} {α : Type w} [spec.IsUniformSpec] [spec'.IsProbabilitySpec] {p q : αProp} {oa : OracleComp spec α} {oa' : OracleComp spec' α} (h1 : xsupport oa, p x q x) (h2 : 𝒟[oa] = 𝒟[oa']) :
          probEvent oa p = probEvent oa' q
          theorem OracleComp.evalDist_ext_probEvent {ι : Type u_1} {ι' : Type u_2} {spec : OracleSpec ι} {spec' : OracleSpec ι'} {α : Type w} [spec.IsUniformSpec] [spec'.IsProbabilitySpec] {oa : OracleComp spec α} {oa' : OracleComp spec' α} (h : ∀ (x : α), Pr[= x | oa] = Pr[= x | oa']) :
          theorem OracleComp.probFailure_eq_sub_probEvent' {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} [spec.IsUniformSpec] (oa : OracleComp spec α) :
          Pr[⊥ | oa] = 1 - probEvent oa fun (x : α) => True
          @[simp]
          theorem OracleComp.probOutput_guard {ι : Type u_1} {spec : OracleSpec ι} [spec.IsProbabilitySpec] {p : Prop} [Decidable p] :
          @[simp]
          theorem OracleComp.probFailure_guard {ι : Type u_1} {spec : OracleSpec ι} [spec.IsProbabilitySpec] {p : Prop} [Decidable p] :
          theorem OracleComp.probOutput_guard_eq_sub_probOutput_guard_not {ι : Type u_1} {spec : OracleSpec ι} [spec.IsProbabilitySpec] {α : Type} {oa : OracleComp spec α} [NeverFail oa] {p : αProp} [DecidablePred p] :
          Pr[= () | do let aliftM oa guard (p a)] = 1 - Pr[= () | do let aliftM oa guard ¬p a]
          theorem OracleComp.evalDist_simulateQ_eq_evalDist {ι : Type u_1} {ι' : Type u_2} {spec : OracleSpec ι} {spec' : OracleSpec ι'} {α : Type w} [spec.IsProbabilitySpec] [spec'.IsProbabilitySpec] (so : QueryImpl spec' (OracleComp spec)) (h : ∀ (t : spec'.Domain), 𝒟[so t] = 𝒟[liftM (OracleSpec.query t)]) (oa : OracleComp spec' α) :

          If an oracle implementation preserves the distribution of each source query, then simulateQ preserves the distribution of every source computation.

          def OracleComp.supportWhen {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} (o : QueryImpl spec Set) (mx : OracleComp spec α) :
          Set α

          The possible outputs of mx when queries can output values in the specified sets. NOTE: currently proofs using this should reduce to simulateQ. A full API would be better

          Instances For
            @[simp]
            theorem OracleComp.supportWhen_pure {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} (o : QueryImpl spec Set) (x : α) :
            @[simp]
            theorem OracleComp.supportWhen_query_bind {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} (o : QueryImpl spec Set) (q : spec.Domain) (oa : spec.Range qOracleComp spec α) :
            supportWhen o (liftM (OracleSpec.query q) >>= oa) = xo q, supportWhen o (oa x)
            @[simp]
            theorem OracleComp.supportWhen_bind {ι : Type u_1} {spec : OracleSpec ι} {α β : Type w} (o : QueryImpl spec Set) (oa : OracleComp spec α) (ob : αOracleComp spec β) :
            supportWhen o (oa >>= ob) = xsupportWhen o oa, supportWhen o (ob x)

            Reachable outputs of a bind are the reachable outputs of the continuation over reachable outputs of the first computation.

            theorem OracleComp.mem_supportWhen_bind_iff {ι : Type u_1} {spec : OracleSpec ι} {α β : Type w} (o : QueryImpl spec Set) (oa : OracleComp spec α) (ob : αOracleComp spec β) (y : β) :
            y supportWhen o (oa >>= ob) xsupportWhen o oa, y supportWhen o (ob x)

            Membership form of [OracleComp.supportWhen_bind].

            theorem OracleComp.supportWhen_mono {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} {o₁ o₂ : QueryImpl spec Set} (h : ∀ (q : spec.Domain), o₁ q o₂ q) (oa : OracleComp spec α) :
            supportWhen o₁ oa supportWhen o₂ oa

            Enlarging the set of possible oracle outputs only enlarges the reachable output set.

            @[reducible]
            noncomputable def OracleComp.evalDistWhen {ι : Type u_1} {spec : OracleSpec ι} {α : Type w} (d : QueryImpl spec SPMF) (mx : OracleComp spec α) :
            SPMF α

            The output distribution of mx when queries follow the specified distribution.

            Instances For