Shared normalization and reordering of probabilistic bind chains #
The proof-producing core of pmf_swap, pmf_hoist, and peel_binds. It normalizes monadic
notation and nested binds at the heads it visits, without unfolding named programs or rewriting the
rest of a chain, matches independent samples by their distributions, and constructs the equality
moving a selected sample to the front. Custom samplers
supply their commutation lemmas; relation-specific peeling and support witnesses stay in the
calling tactic.
Cast a proof h : a' = b' to a = b when a ≡ a' and b ≡ b' definitionally.
Compose optional equality proofs e₀ = e₁ and e₁ = e₂.
Normalize only the outer head of a PMF expression into PMF.bind
without unfolding named user definitions or traversing continuation bodies. Keep a source map
intact with preserveMap so its enclosing bind can apply PMF.bind_map directly.
The head of an application, for a cheap test that an expression may be a sampler.
- const (n : Lean.Name) : HeadKey
A constant.
- fvar (x : Lean.FVarId) : HeadKey
A local variable.
Instances For
A commutation lemma μ.bind (fun b => F (k b)) = F (fun a => μ.bind fun b => k b a), which
lets an independent sample of any μ move past the sampler F.
The lemma, with its metavariables abstracted.
- stx : Lean.Syntax
The lemma as written, for messages.
- key : HeadKey
The head of the sampler
F. - arity : ℕ
The number of arguments of the sampler
F.
The sampler rules shared by matching and proof-producing reordering.
Rules commuting independent distributions with custom samplers.
Optional rule for commuting two custom samplers
F,G, with continuationk. Its result provesF (fun a => G (k a)) = G (fun b => F (fun a => k a b)).
Check the shape of a sampler commutation lemma, retaining its syntax for diagnostics.
Elaborate a commutation lemma supplied by a tactic caller.
Recognize a custom sampler by a supplied commutation rule.
The first sample of a chain, including a map or a bind exposed by head normalization.
Run k x b with a new variable x for the argument of the function f, where b is f x
reduced.
The type of outcomes α of a distribution p : PMF α.
p.front f = p.front g from h : f = g.
The depths at which the chain e samples q, up to reducible unfolding. A sample whose
distribution mentions an earlier sample is not equal to q, which is closed. The search for a
custom sampler stops at the first custom sampler unless the context supplies their commutation
rule. Heads are normalized as the search descends into the chain.
The first depth at which the chain e samples q, assigning the metavariables of q.
The same sampler boundaries as findDepths apply.
Move the sample at depth k of the chain e, which samples q independently of the earlier
samples, to the front. Normalize only the path to that sample, preserving the remaining
continuation. Returns q.front g and a proof of e = q.front g.