Computations with Uniform Selection Oracles #
This file defines a type ProbComp α for the case of OracleComp with access to a
uniform selection oracle, specified by unifSpec, as well as common operations for this type.
We define $[0..n] as uniform selection starting from zero for any n : ℕ (uniformFin)
as well as a version $[n⋯m] that tries to synthesize an instance of n < m (uniformRange).
This allows us to avoid needing an OptionT wrapper to handle empty ranges.
We also define typeclasses HasUniformSelect β cont and HasUniformSelect! β cont to allow for
$ xs and $! xs notation for uniform sampling from a container.
These don't really enforce any semantics, so any new definition will need to prove
lemmas about the behavior of the operation.
TODO: we could introduce a mixin typeclass at least to handle this?
SampleableType α on the other hand allows for $ᵗ α notation for uniform type sampleing,
and does enforce the uniformity of outputs.
Encapsulating the thing you want to select in a SampleableType can therefore give more
useful lemmas out of the box, in particular when using subtypes.
Simplified notation for computations with no oracles besides random inputs.
This specific case can be used with #eval to run a random program, see OracleComp.runIO.
NOTE: Need to decide if this should be more opaque than abbrev, seems like no as of now..
Equations
Instances For
Tactic to attempt to prove uniformRange decreasing bound, similar to array indexing.
Equations
Instances For
Select uniformly from a range of numbers. Attempts to use `get
Equations
Instances For
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 β.
β is marked as an outParam so that Lean will first pick the output type before synthesizing.
NOTE: This current implementation doesn't impose any "correctness" conditions,
it purely exists to provide the notation, could revisit that in the future.
Instances
Version of HasUniformSelect that doesn't allow for failure.
Useful for things like Vector that can be shown nonempty at the type level.
- uniformSelect! : cont → ProbComp β
Instances
Given a non-failing uniform selection operation we also have a potentially failing one,
using OptionT.lift
Equations
Compatibility of the $! xs operation with $ xs given the inferred instance.
TODO: I think we probably want to simp in the other direction when possible?
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
Select a random element from a vector by indexing into it with a uniform value. TODO: different types of vectors in mathlib now
Equations
Equations
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.