Documentation

VCVio.OracleComp.Constructions.UniformSelect

Selecting Uniformly From a Collection #

This file defines some computations for selecting uniformly at random from a number of different collections, using unifSpec to make the random choices.

TODO: A lot of lemmas here could exist at the PMF level instead. Probably even a lot of the uniform constructions themselves (like uniformOfList)

class OracleComp.HasUniformSelect (cont : Type u) (β : outParam Type) :
Type (max 1 u)

Typeclass to implement the notation $ xs for selecting an object uniformly from a collection. The container type is given by cont with the resulting type given by β. NOTE: This current implementation doesn't impose any "correctness" conditions, it purely exists to provide the notation, could revisit that in the future.

Instances
    def OracleComp.uniformSelect {cont : Type} (β : Type) [h : HasUniformSelect cont β] (xs : cont) :

    Given a selectable object, we can get a random element by indexing into the element vector.

    Equations
    Instances For

      Select a random element from a list by indexing into it with a uniform value. If the list is empty we instead just fail rather than choose a default value. This means selecting from a vector is often preferable, as we can prove at the type level that there is an element in the list, avoiding the defualt case of empty lists.

      Equations
      • One or more equations did not get rendered due to their size.
      theorem OracleComp.uniformSelectList_cons {α : Type} (x : α) (xs : List α) :
      uniformSelect α (x :: xs) = (fun (x_1 : Fin (xs.length + 1)) => (x :: xs)[x_1]) <$> $[0..xs.length]
      @[simp]
      theorem OracleComp.evalDist_uniformSelectList {α : Type} (xs : List α) :
      evalDist (uniformSelect α xs) = match xs with | [] => PMF.pure none | x :: xs => PMF.map (fun (x_1 : Fin xs.length.succ) => some (x :: xs)[x_1]) (PMF.uniformOfFintype (Fin xs.length.succ))
      @[simp]
      @[simp]
      theorem OracleComp.probOutput_uniformSelectList {α : Type} [DecidableEq α] (xs : List α) (x : α) :
      [=x|uniformSelect α xs] = if xs.isEmpty = true then 0 else (List.count x xs) / xs.length
      @[simp]
      theorem OracleComp.probEvent_uniformSelectList {α : Type} (xs : List α) (p : αProp) [DecidablePred p] :
      [p|uniformSelect α xs] = if xs.isEmpty = true then 0 else (List.countP (fun (b : α) => decide (p b)) xs) / xs.length
      instance OracleComp.hasUniformSelectVector (α : Type) (n : ) :
      HasUniformSelect (Vector α (n + 1)) α

      Select a random element from a vector by indexing into it with a uniform value. TODO: different types of vectors in mathlib now

      Equations
      theorem OracleComp.uniformSelectVector_def {α : Type} {n : } (xs : Vector α (n + 1)) :
      noncomputable instance OracleComp.hasUniformSelectFinset (α : Type) [DecidableEq α] :

      Choose a random element from a finite set, by converting to a list and choosing from that. This is noncomputable as we don't have a canoncial ordering for the resulting list, so generally this should be avoided when possible.

      Equations
      @[simp]
      theorem OracleComp.probOutput_uniformSelectFinset {α : Type} [DecidableEq α] (s : Finset α) (x : α) :

      A SelectableType β 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 SelectableType.probOutput_selectElem for the reduction when α has a fintype instance. NOTE: universe polymorphism of β is hard.

      Instances

        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
          @[simp]
          theorem OracleComp.probOutput_uniformOfFintype (α : Type) [ : SelectableType α] [Fintype α] (x : α) :
          Equations
          Equations
          • One or more equations did not get rendered due to their size.

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

          Equations
          • One or more equations did not get rendered due to their size.

          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