Documentation

VCVio.OracleComp.Constructions.SampleableType

Uniform Selection Over a Type #

This file defines a typeclass SampleableType β for types β with a canonical uniform selection operation, using the ProbComp monad.

As compared to HasUniformSelect this provides much more structure on the behavior, enforcing that every possible output has the same output probability never fails.

class SampleableType (β : Type) :

A SampleableType β instance means that β is a finite inhabited type, with a computation selectElem that selects uniformly at random from the type. This generally requires choosing some "canonical" ordering for the type, so we include this to get a computable version of selection. We also require that each element has the same probability of being chosen from by selectElem, see SampleableType.probOutput_uniformSample for the reduction when α has a fintype instance involving the explicit cardinality of the type.

Instances
    def uniformSample (β : Type) [h : SampleableType β] :

    Select uniformly from the type β using a type-class provided definition. NOTE: naming is somewhat strange now that Fintype isn't explicitly required.

    Equations
      Instances For
        Equations
          Instances For
            @[simp]
            theorem probOutput_uniformSample (α : Type) [ : SampleableType α] [Fintype α] (x : α) :
            @[simp]
            theorem mem_support_uniformSample (α : Type) [ : SampleableType α] {x : α} :
            @[simp]
            theorem probEvent_uniformSample (α : Type) [ : SampleableType α] [Fintype α] (p : αProp) [DecidablePred p] :

            Select a uniform element from α × β by independently selecting from α and β.

            Equations

              Nonempty Fin types can be selected from, using implicit casting of Fin (n - 1 + 1).

              Equations

                Version of Fin selection using the NeZero typeclass, avoiding the need for n + 1.

                Equations

                  Select a uniform element from Vector α n by independently selecting α at each index.

                  Equations

                    Select a uniform element from Matrix α n by independently selecting α at each index.

                    Equations

                      A type equivalent to a SampleableType is also SampleableType.

                      Equations
                        Instances For
                          instance instSampleableTypeFinFunc {n : } {α : Type} [SampleableType α] [DecidableEq α] :
                          SampleableType (Fin nα)

                          A function from Fin n to a SampleableType is also SampleableType.

                          Equations
                            theorem probOutput_uniformBool_not_decide_eq_decide {ob : ProbComp Bool} :
                            Pr[=true | do let b$ᵗBool let b'ob pure !decide (b = b')] = Pr[=true | do let b$ᵗBool let b'ob pure (decide (b = b'))]

                            Given an independent probabilistic computation ob : ProbComp Bool, the probability that its output b' differs from a uniformly chosen boolean b is the same as the probability that they are equal. In other words, P(b ≠ b') = P(b = b') where b is uniform.