Documentation

CslibFrontier.Probability.DDGTree

Discrete distribution generating trees #

A discrete distribution generating (DDG) tree reads independent fair bits and eventually commits to an outcome. Following [KY76] and [CT06], Section 5.11, it is a possibly infinite complete binary tree whose leaves carry outcomes. Here such a tree is presented by its prefix labelling output : List Bool → Option α: output w = some a means that the walk along w has reached a leaf labelled a, and none means it is still at an internal node. Leaves are absorbing.

Running on n fair bits gives run T n : PMF (Option α). run T n none is the probability P(T > n) that more than n flips are needed. The output law is the monotone limit outputProb T a = ⨆ n, run T n (some a). The expected number of flips is the tail sum expectedFlips T = ∑ₙ P(T > n). expectedFlips_eq_tsum_mul identifies it with ∑ₖ (k + 1) P(T = k + 1) whenever the tree halts almost surely, as every tree generating a PMF distribution does (tendsto_run_none_of_generates). expectedFlips_eq_top covers trees that fail to halt with positive probability.

Main definitions #

Main results #

References #

structure Cslib.Probability.DDGTree (α : Type u_1) :
Type u_1

A discrete distribution generating tree, given by its prefix labelling. output w = some a when reading the bits w reaches a leaf labelled a, and output w = none while the walk is at an internal node. Leaves are absorbing: further bits do not change the outcome. The tree may be infinite.

  • output : List Bool → Option α

    The outcome reached after reading a finite bit string, if any.

  • output_append_singleton (w : List Bool) (a : α) (b : Bool) : self.output w = some a → self.output (w ++ [b]) = some a

    Once a leaf is reached, later bits are ignored.

theorem Cslib.Probability.DDGTree.ext {α : Type u_1} {x y : DDGTree α} (output : x.output = y.output) :
x = y
theorem Cslib.Probability.DDGTree.ext_iff {α : Type u_1} {x y : DDGTree α} :
x = y ↔ x.output = y.output
noncomputable def Cslib.Probability.DDGTree.run {α : Type u_1} (T : DDGTree α) (n : ℕ) :
PMF (Option α)

The result of running the tree on n independent fair bits: some a if it has reached a leaf labelled a, and none if it needs more than n bits.

noncomputable def Cslib.Probability.DDGTree.outputProb {α : Type u_1} (T : DDGTree α) (a : α) :

Probability that the tree eventually outputs a.

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

The tree generates p when its eventual output has law p.

noncomputable def Cslib.Probability.DDGTree.expectedFlips {α : Type u_1} (T : DDGTree α) :

Expected number of fair bits read before a leaf is reached: the tail sum ∑ₙ P(T > n) of the stopping time T. It is ⊤ when the tree fails to halt with positive probability.

theorem Cslib.Probability.DDGTree.output_append {α : Type u_1} {T : DDGTree α} {w : List Bool} {a : α} (h : T.output w = some a) (v : List Bool) :
T.output (w ++ v) = some a

A leaf is never left.

theorem Cslib.Probability.DDGTree.output_eq_of_output_nil {α : Type u_1} {T : DDGTree α} {a : α} (h : T.output [] = some a) (w : List Bool) :
T.output w = some a

If the root is a leaf, every bit string reaches it.

def Cslib.Probability.DDGTree.child {α : Type u_1} (T : DDGTree α) (b : Bool) :

The subtree reached after reading b first.

@[simp]
theorem Cslib.Probability.DDGTree.child_output {α : Type u_1} (T : DDGTree α) (b : Bool) (w : List Bool) :
(T.child b).output w = T.output (b :: w)
@[simp]
theorem Cslib.Probability.DDGTree.run_zero {α : Type u_1} (T : DDGTree α) :

With no bits, the tree reports its root.

theorem Cslib.Probability.DDGTree.run_succ {α : Type u_1} (T : DDGTree α) (n : ℕ) :
T.run (n + 1) = (PMF.uniformOfFintype Bool).bind fun (b : Bool) => (T.child b).run n

One more bit: flip a fair coin, then run the chosen subtree.

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

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

theorem Cslib.Probability.DDGTree.run_le_run_succ {α : Type u_1} (T : DDGTree α) (n : ℕ) (a : α) :
(T.run n) (some a) ≤ (T.run (n + 1)) (some a)

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

theorem Cslib.Probability.DDGTree.monotone_run {α : Type u_1} (T : DDGTree α) (a : α) :
Monotone fun (n : ℕ) => (T.run n) (some a)
theorem Cslib.Probability.DDGTree.run_le_outputProb {α : Type u_1} (T : DDGTree α) (n : ℕ) (a : α) :
(T.run n) (some a) ≤ T.outputProb a
theorem Cslib.Probability.DDGTree.tendsto_run_outputProb {α : Type u_1} (T : DDGTree α) (a : α) :
Filter.Tendsto (fun (n : ℕ) => (T.run n) (some a)) Filter.atTop (nhds (T.outputProb a))
theorem Cslib.Probability.DDGTree.exists_run_eq_div {α : Type u_1} (T : DDGTree α) (n : ℕ) (o : Option α) :
∃ (c : ℕ), (T.run n) o = ↑c / 2 ^ n

After n fair bits every event has dyadic probability c / 2 ^ n.

theorem Cslib.Probability.DDGTree.run_none_add_sum {α : Type u_1} [Fintype α] (T : DDGTree α) (n : ℕ) :
(T.run n) none + ∑ a : α, (T.run n) (some a) = 1
theorem Cslib.Probability.DDGTree.run_succ_none_le {α : Type u_1} (T : DDGTree α) (n : ℕ) :
(T.run (n + 1)) none ≤ (T.run n) none

The probability P(T > n) of needing more than n bits is nonincreasing in n.

theorem Cslib.Probability.DDGTree.antitone_run_none {α : Type u_1} (T : DDGTree α) :
Antitone fun (n : ℕ) => (T.run n) none
theorem Cslib.Probability.DDGTree.tendsto_run_none_of_generates {α : Type u_1} {T : DDGTree α} {p : PMF α} (hT : T.Generates p) :
Filter.Tendsto (fun (n : ℕ) => (T.run n) none) Filter.atTop (nhds 0)

A tree generating a PMF distribution halts almost surely.

The tail-sum formula #

theorem Cslib.Probability.DDGTree.expectedFlips_eq_tsum_mul {α : Type u_1} (T : DDGTree α) (h : Filter.Tendsto (fun (n : ℕ) => (T.run n) none) Filter.atTop (nhds 0)) :
T.expectedFlips = ∑' (k : ℕ), (↑k + 1) * ((T.run k) none - (T.run (k + 1)) none)

For a tree that halts almost surely, expectedFlips is the expectation ∑ₖ (k + 1) P(T = k + 1) of the stopping time, where P(T = k + 1) = P(T > k) - P(T > k + 1).

theorem Cslib.Probability.DDGTree.expectedFlips_eq_top {α : Type u_1} (T : DDGTree α) (h : ⨅ (n : ℕ), (T.run n) none ≠ 0) :

A tree that fails to halt with positive probability reads infinitely many bits in expectation.

Realizing a depth profile #

noncomputable def Cslib.Probability.DDGTree.ofCounts {α : Type u_1} [Fintype α] (t : ℕ → α → ℕ) :

A tree in which t k a of the 2 ^ k depth-k positions lie at or below a leaf labelled a, provided t is inherited (2 * t k a ≤ t (k + 1) a) and fits the Kraft-type budget ∑ₐ t k a ≤ 2 ^ k (see run_ofCounts). A leaf at depth j ≤ k accounts for 2 ^ (k - j) of them, so t k a / 2 ^ k is the probability of having output a within k flips. The depth-k positions are ordered so that positions below leaves of depth < k come first, then the new leaves of depth k, then the internal nodes.

theorem Cslib.Probability.DDGTree.run_ofCounts {α : Type u_1} [Fintype α] {t : ℕ → α → ℕ} (hmono : ∀ (k : ℕ) (a : α), 2 * t k a ≤ t (k + 1) a) (hkraft : ∀ (k : ℕ), ∑ a : α, t k a ≤ 2 ^ k) (n : ℕ) (a : α) :
((ofCounts t).run n) (some a) = ↑(t n a) / 2 ^ n

If the counts are inherited along each level (2 * t k a ≤ t (k + 1) a: both children of a position at or below an a-leaf are again such positions) and fit at every depth (∑ₐ t k a ≤ 2 ^ k, a Kraft-type budget), then ofCounts t reaches a leaf labelled a within n flips with probability exactly t n a / 2 ^ n.