Canonical uniform samplers: the $ᵗ notation class #
SampleableType β gives the notation $ᵗ β its meaning: an executable ProbComp β together
with the one law that makes it a uniform sampler, 𝒟[$ᵗ β] = uniformOn Set.univ for every
measurable structure with measurable singletons. The law is part of the contract because no
consumer wants a canonical sampler that is not uniform; it is the only field besides the
program, and every construction below discharges it once.
Nonemptiness of β follows from having a sampler at all (SampleableType.nonempty), and
finiteness and full operational support follow from the law (SampleableType.finite,
support_uniformSample). The two Prop-valued facts are instances so that a hypothesis
[SampleableType β] supplies them wherever Mathlib asks, but at low priority: ordinary
instances such as Finite.of_fintype and instNonemptyOfInhabited are tried first, so a fact
about Fin 3 never routes through sampler code and the sampler instances only answer for types
whose finiteness is known through nothing else (typically spec.Range t under
[∀ t, SampleableType (spec.Range t)]). Since the classes are propositions, which instance
answers is invisible to definitional equality (docs/agents/gotchas.md §8b).
Products, vectors, and equivalences transport the sampler together with its law.
A canonical uniform sampler for β, written $ᵗ β: an executable program whose output
measure is uniform for every measurable structure with measurable singletons.
- selectElem : ProbComp β
The canonical sampler of
β, written$ᵗ β. - evalDist_selectElem_eq_uniform [MeasurableSpace β] [MeasurableSingletonClass β] : 𝒟[selectElem] = ProbabilityTheory.uniformOn Set.univ
The canonical sampler denotes the uniform measure on
β.
Instances
Select uniformly from the type β using a type-class provided definition.
Instances For
The canonical sample has uniform output measure under native oracle semantics.
A sampler yields an element of its type: run it on default oracle answers. Low priority so that ordinary nonemptiness instances answer first.
A uniform sampler denotes a probability measure only on a finite type. Low priority so that ordinary finiteness instances answer first.
A uniform sampler can output every element: positive uniform mass on each singleton is operational reachability.
The canonical sampler has a possible output.
A sum of oracle specs with sampleable ranges again has sampleable ranges.
Select a uniform element from α × β by independently selecting from α and β.
Transport a uniform sampler along an equivalence.
Instances For
Any finitely enumerable type can be sampled uniformly using the underlying equivalence.
Noncomputable bridge from a nonempty Fintype with decidable equality to SampleableType,
via Fintype.equivFin. Used by downstream instances (e.g. Sym α n, Equiv.Perm α, β ↪ α)
whose Mathlib Fintype instances are not paired with a FinEnum. Provided as a def rather
than an instance to avoid overlap with FinEnum.SampleableType.
Instances For
Explicit noncomputable uniform sampler for a dependent finite product. This constructor is a definition rather than an instance so it cannot compete with executable samplers for particular dependent function types.
Instances For
Uniform sampling of a nonempty subtype of a finite type, by enumeration. Provided as a definition so that it never competes with executable enumeration-based instances.
Instances For
Uniform sampling from a nonempty finite set, by enumeration.
Instances For
Sample a Vector α n by independently sampling α at each index.
Instances For
Independent uniform samples at each index give the uniform measure on Vector α n.
A function from Fin n to a SampleableType is also SampleableType. This is the base
case used by the general FinEnum-indexed instSampleableTypeFunc below.
A function β → α for β finitely enumerable and α sampleable is itself sampleable.
This generalizes the Fin n → α instance above: the FinEnum.fin instance recovers it.
Select a uniform element from List.Vector α n by independently selecting α at each
index. The construction goes through the equivalence with Fin n → α.
Select a uniform element from Matrix ι κ α by independently selecting an entry for each
(i, j). Both index types only need to be FinEnum.
Discoverability wrapper: SampleableType (α ⊕ β) follows from FinEnum on each side
plus nonemptiness of the sum, via Mathlib's FinEnum.sum instance and
FinEnum.SampleableType. Listed explicitly so users can see it in the instance set rather
than relying on a multi-step search.
Discoverability wrapper: SampleableType (Finset α) for FinEnum α. Uniform sampling
draws every subset of α with the same probability (2^|α| outcomes). Finset α is always
inhabited by ∅, so no Nonempty hypothesis is needed.
Uniform sampling of size-n multisets over a FinEnum type. Sym α n is the correct finite
analogue of Multiset α: a plain Multiset α is unbounded in multiplicity and thus not finite,
while Sym α n is finite whenever α is. We obtain a computable uniform sampler from the
canonical enumeration Sym.finEnum; for a base type with only a Fintype instance use
SampleableType.ofFintype instead.
Note this is genuinely uniform on multisets: mapping a uniform List.Vector α n through
Sym.ofVector is not (it weights each multiset by its number of orderings), so we enumerate
Sym α n canonically rather than pushing forward from vectors.
Uniform sampling of permutations of a FinEnum type. Equiv.Perm α has n! elements when
Fintype.card α = n. We obtain a computable uniform sampler from the canonical enumeration
Equiv.Perm.finEnum. Useful for shuffle-based protocols and oblivious-permutation games.
Uniform sampling of injections β ↪ α for FinEnum types. The number of such embeddings is
α.card! / (α.card - β.card)! when β.card ≤ α.card, else 0; the Nonempty (β ↪ α)
hypothesis rules out the latter case. We obtain a computable uniform sampler from the canonical
enumeration Function.Embedding.finEnum (itself computable, unlike Mathlib's Fintype (β ↪ α)).
A function from a finite type D with Fintype + DecidableEq (not necessarily FinEnum)
to a SampleableType is itself SampleableType, transporting the Fin (Fintype.card D) → α
sampler across the canonical equivalence (D → α) ≃ (Fin (Fintype.card D) → α).
This is the noncomputable counterpart to the computable FinEnum-domain instance
instSampleableTypeFunc, and is given lower priority so that for a FinEnum domain the
computable instance is preferred; it is the fallback for Fintype + DecidableEq-only domains.
Given that the output type of all oracles has a SampleableType instance, replace all queries
with uniformly random responses by calling the corresponding uniformSample at each query.
Instances For
A uniformly sampled implementation answers each query with the uniform sampler for that query's response type.
Interpreting queries by full-support samplers preserves operational reachability.
Full-support query sampling also preserves the finite support when answers are enumerable.