Documentation

CslibFrontier.Probability.DDGTree.Biased

Coin-reading trees on biased coins, and von Neumann's fair bit #

A Cslib.Probability.DDGTree is a possibly infinite absorbing prefix labelling: it reads coin flips one at a time and commits to an outcome when it reaches a leaf. DDGTree.run reads fair bits. This file runs the same trees on independent flips of a coin with an arbitrary law c : PMF Bool. runWith c n T is the outcome after n flips, or none if more are needed. The output law outputProbWith is its monotone limit, and expectedCostWith c w T = ∑ₙ w n P(T > n) is the expected total cost when reading flip number n + 1 (index n) costs w n. With unit weights it is the expected number of flips, expectedFlipsWith. For the fair coin all of these agree with the fair-bit API (run_eq_runWith, outputProb_eq_outputProbWith, expectedFlips_eq_expectedFlipsWith).

Such trees are the exact model of a sampler that loops until it stops. A program in Cslib.OracleComp is a finite tree of calls, so it can express only a truncation of such a loop (Cslib.OracleComp.retry), whose failure outcome is visible.

Von Neumann's extractor reads flips in pairs, outputs the first flip of the first unequal pair and discards equal pairs. On independent flips of a coin of bias 0 < ρ < 1 it outputs an exactly fair bit, with exactly 1 / (ρ (1 - ρ)) expected flips ([Arora and Barak, Lemma 7.15]). The hypothesis 0 < ρ < 1 is necessary: a coin of bias 0 or 1 is deterministic, so a tree reading it yields every outcome with probability 0 or 1, and no tree outputs a fair bit (exists_generatesWith_coin_iff).

Main definitions #

Main results #

References #

Running on a biased coin #

noncomputable def Cslib.Probability.DDGTree.runWith {α : Type u_1} (c : PMF Bool) :
ℕ → DDGTree α → PMF (Option α)

The result of running T on n independent flips of a coin with law c: some a if it has reached a leaf labelled a, and none if it needs more than n flips.

noncomputable def Cslib.Probability.DDGTree.outputProbWith {α : Type u_1} (c : PMF Bool) (T : DDGTree α) (a : α) :

Probability that T, run on flips of a coin with law c, eventually outputs a.

def Cslib.Probability.DDGTree.GeneratesWith {α : Type u_1} (c : PMF Bool) (T : DDGTree α) (p : PMF α) :

T generates p from flips of a coin with law c.

noncomputable def Cslib.Probability.DDGTree.expectedCostWith {α : Type u_1} (c : PMF Bool) (w : ℕ → ENNReal) (T : DDGTree α) :

Expected total cost ∑ₙ w n P(T > n) when reading flip number n + 1 costs w n: that flip is read exactly when the tree has not stopped after n flips.

noncomputable def Cslib.Probability.DDGTree.expectedFlipsWith {α : Type u_1} (c : PMF Bool) (T : DDGTree α) :

Expected number ∑ₙ P(T > n) of flips of a coin with law c read before a leaf.

@[simp]
theorem Cslib.Probability.DDGTree.runWith_zero {α : Type u_1} (c : PMF Bool) (T : DDGTree α) :
theorem Cslib.Probability.DDGTree.runWith_succ {α : Type u_1} (c : PMF Bool) (T : DDGTree α) (n : ℕ) :
runWith c (n + 1) T = c.bind fun (b : Bool) => runWith c n (T.child b)

Fair bits are flips of the fair coin.

theorem Cslib.Probability.DDGTree.runWith_eq_pure_of_output_nil {α : Type u_1} (c : PMF Bool) {T : DDGTree α} {a : α} (h : T.output [] = some a) (n : ℕ) :

A tree whose root is a leaf labelled a outputs a without reading any flip.

theorem Cslib.Probability.DDGTree.runWith_le_runWith_succ {α : Type u_1} (c : PMF Bool) (T : DDGTree α) (n : ℕ) (a : α) :
(runWith c n T) (some a) ≤ (runWith c (n + 1) T) (some a)

Probabilities of a fixed outcome increase with the number of flips.

theorem Cslib.Probability.DDGTree.monotone_runWith {α : Type u_1} (c : PMF Bool) (T : DDGTree α) (a : α) :
Monotone fun (n : ℕ) => (runWith c n T) (some a)
theorem Cslib.Probability.DDGTree.tendsto_runWith_outputProbWith {α : Type u_1} (c : PMF Bool) (T : DDGTree α) (a : α) :
Filter.Tendsto (fun (n : ℕ) => (runWith c n T) (some a)) Filter.atTop (nhds (outputProbWith c T a))

A finite expected number of flips forces the tree to halt almost surely.

Deterministic coins #

theorem Cslib.Probability.DDGTree.runWith_pure {α : Type u_1} (b : Bool) (T : DDGTree α) (n : ℕ) :

On a deterministic coin always showing b, the tree follows the single path b b b ⋯.

On a deterministic coin every outcome has probability 0 or 1.

A deterministic coin cannot produce a fair bit.

Von Neumann's extractor #

Von Neumann's labelling: read flips in pairs, skip equal pairs, and output the first flip of the first unequal pair.

Von Neumann's repeat-until-different extractor.

Two more flips: an unequal pair stops with its first flip, an equal pair restarts.

Both outcomes are equally likely after any number of flips.

The loop is still running after n flips exactly when the first ⌊n / 2⌋ pairs are equal.

The expected number of flips of the von Neumann loop is twice the expected number of pairs.

Von Neumann extraction, cost ([Arora and Barak, Lemma 7.15]): on a coin of bias 0 < ρ < 1 the loop reads exactly 1 / (ρ (1 - ρ)) flips in expectation.

Von Neumann extraction ([Arora and Barak, Lemma 7.15]): from independent flips of a coin of bias 0 < ρ < 1 the repeat-until-different loop outputs an exactly fair bit.

The hypothesis 0 < ρ < 1 of von Neumann extraction is necessary and sufficient: some coin-reading tree outputs an exactly fair bit from independent flips of a coin of bias ρ exactly when 0 < ρ < 1.