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.
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.
- selectElem : ProbComp β
Instances
Select uniformly from the type β using a type-class provided definition.
NOTE: naming is somewhat strange now that Fintype isn't explicitly required.
Instances For
Pushing forward uniform sampling along a bijection preserves output probabilities.
Binding after pushing forward uniform sampling along a bijection preserves output probabilities.
Right-translation analogue of probOutput_add_left_uniform: right-adding a constant to a
uniform sample in AddGroup α preserves the output distribution, since (· + m) is a bijection
on α with inverse (· + (-m)).
Right-translation analogue of evalDist_add_left_uniform: right-adding a constant to a
uniform sample in AddGroup α preserves the full evaluation distribution.
Pushing forward uniform sampling via a bijection preserves the full evaluation distribution.
Bijective uniform + right-translation gives uniform. Sampling x ← $ᵗ α, transporting
through a bijection f : α → β, and right-adding any fixed m : β yields the same distribution
as sampling y ← $ᵗ β directly, as observed by any continuation cont : β → ProbComp γ.
This is the "one-time pad" fact underlying many cryptographic reductions: bijective transport
makes f x uniform on β, and in any AddGroup β right-translation (· + m) is a bijection
on the uniform measure, so the sum is again uniform.
Constant-irrelevance form of evalDist_bind_bijective_add_right_uniform: sampling through a
bijection and right-adding a constant has a distribution independent of the constant. Any two
offsets produce the same evaluation distribution.
A sum of oracle specs with sampleable ranges again has sampleable ranges.
Select a uniform element from α × β by independently selecting from α and β.
Any finitely enumerable type can be sampled uniformly using the underlying equivalence.
Select a uniform element from Vector α n by independently selecting α at each index.
A function from Fin n to a SampleableType is also SampleableType.
Select a uniform element from Matrix α n by selecting each row independently.
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.
Guessing a uniformly random bit after branching between real and rand decomposes into
the difference of the branch success probabilities.
If the distribution of f b is independent of b, then guessing a uniformly random
bit by running f has success probability exactly 1/2.
This is the core lemma behind "all-random hybrid has probability 1/2" arguments.