Documentation

CslibFrontier.Tactic.PMFSwap

Reordering independent samples #

Two probabilistic experiments that draw the same independent samples in different orders have the same law, by PMF.bind_comm. Proving such an equation by rewriting means navigating to each swap (conv_lhs => enter [2, a, 2, b]) and stripping the common samples one at a time (congr 1 with x : 1), and simp [PMF.bind_comm] loops on two samples of the same distribution. The tactics here match samples by their distributions instead of their positions.

pmf_swap proves an equation lhs = rhs of distributions whose sides are sampling chains. It normalizes visible monadic notation, nested binds, maps, and ProbComp.eval as it matches draws. An unpeeled continuation keeps its original form. It brings a sample of the right side that the left side draws independently of its earlier samples to the front of both sides, by PMF.bind_comm, strips it, and continues with the continuations. Samples of the same distribution may be matched in any order: the tactic searches for an order in which the two sides become equal up to reducible unfolding, and then closes the goal. The search has a budget, renewed after stripping each sample with a single possible partner, and the tactic fails when it runs out. If no order works, it strips common samples and leaves the equation of the remaining continuations, with the stripped samples as variables, unless rfl proves it. It first strips samples whose distribution occurs once on each side, which have only one possible partner, and then the first matches of the others. pmf_swap with x y skips the search and strips exactly two samples, naming them in the order they occur in the right side; plain pmf_swap strips every sample it can. It fails when it can strip no sample, listing the samples of both sides and marking those that depend on earlier ones, which cannot move. pmf_swap [h] also moves samples past a sampler F, a function of a continuation, given a commutation lemma h : μ.bind (fun b => F (k b)) = F (fun a => μ.bind fun b => k b a).

pmf_hoist q moves every sample of the distribution q in the goal, or in a hypothesis with at h, as far toward the front of its chain as its independence allows. It works anywhere in the goal, for instance inside a probability or an inequality, where pmf_swap does not apply. pmf_hoist (occ := n) q moves only the nth sample of q, for chains that draw q more than once. pmf_hoist [h] F also moves a custom sampler F using the same commutation rule as pmf_swap [h].

Distributions are compared up to reducible unfolding. A sample of a distribution that depends on an earlier sample never moves past that sample.

Main definitions #

pmf_swap proves an equation lhs = rhs of distributions whose sides draw the same independent samples in different orders. Visible monadic notation, nested binds, maps, and ProbComp.eval are normalized automatically, without unfolding named programs. The tactic brings a sample that both sides draw independently of their earlier samples to the front of both, by PMF.bind_comm, strips it, and continues. Samples are matched by their distributions, up to reducible unfolding, not by position.

If the samples can be matched so that the two sides become equal, up to reducible unfolding, the goal is closed; samples of the same distribution are tried in every order. The search has a budget of 256 steps, renewed after stripping each sample whose distribution occurs once on each side, and the tactic fails when the budget runs out with no such sample left. If no order makes the sides equal, pmf_swap strips common samples and leaves the equation of what remains, with the stripped samples as variables: first the samples whose distribution occurs once on each side, then the first match of each remaining sample of the right side, and fails when it can strip none. It closes the remaining equation when rfl proves it.

pmf_swap with x y skips the search and strips exactly two samples in the same way, and fails if it cannot. The names follow the order of the samples in the right side, whatever order they are stripped in: on (p.bind fun a => q.bind fun b => f a b) = q.bind fun b => p.bind fun a => g a b, pmf_swap with y x leaves f x y = g x y. The remaining equation is left as it is.

pmf_swap [h₁, h₂] also moves samples past a sampler F, a function of a continuation such as Game.runStatelessOracle o prog, given commutation lemmas of the form h : μ.bind (fun b => F (k b)) = F (fun a => μ.bind fun b => k b a) for every distribution μ. An application F k is then a sample of F with continuation k. Two samplers do not move past each other.

An occurrence (occ := n) of a distribution, counted from 1.

pmf_hoist q moves every sample of the distribution q, in every chain of PMF.bind in the goal, as far toward the front of its chain as possible, by PMF.bind_comm: past every earlier sample, which q cannot depend on. q may contain holes _, which are filled by its first match. Like rw, it then closes a goal that has become reflexive. pmf_hoist q at h works on the hypothesis h instead. It fails when no sample of q moves.

pmf_hoist (occ := n) q moves only the nth independent sample of q, counting from the front of each chain and through the chains in the order they occur, the left side of an equation before the right. When a chain draws q twice, it chooses which of the two pmf_swap or congr 1 with x : 1 then pairs with the first sample of the other side. It fails when that sample is already at the front of its chain or there are fewer than n independent samples of q.

pmf_hoist [h] F also moves a custom sampler F, such as Game.runStatelessOracle o prog, given a commutation rule of the form accepted by pmf_swap [h]. The same rule lets a distribution move past F; two custom samplers do not move past each other. Visible monadic notation is normalized along the path to the moved sample; the rest of each chain keeps its form.