The Knuth–Yao entropy bounds for sampling from fair coins #
Every DDG tree generating a distribution p on a finite type reads at least H(p) fair bits in
expectation, and the Knuth–Yao tree knuthYao p reads fewer than H(p) + 2
([KY76]; [CT06], Theorems 5.11.1 and 5.11.3).
knuthYao p places a leaf labelled a at depth k exactly when the k-th binary digit
⌊2ᵏ p a⌋ mod 2 of p a is 1. Equivalently, it outputs a within k flips with probability
⌊2ᵏ p a⌋ / 2ᵏ. Its stopping time is stochastically smallest. For every generating tree T and
every n, P(T_KY > n) ≤ P(T > n), because after n fair bits T can only have produced a
with dyadic probability c / 2ⁿ ≤ p a, so c ≤ ⌊2ⁿ p a⌋. Hence knuthYao p minimizes the
expected number of flips. Its expected cost is ∑ₐ ν(p a), where
ν(x) = ∑ₙ (x - ⌊2ⁿ x⌋ / 2ⁿ) is the sum of the binary-truncation errors of x. The bounds
x log₂ (1 / x) ≤ ν(x) < x log₂ (1 / x) + 2x for 0 < x ≤ 1 then give both entropy bounds.
Equality ν(x) = x log₂ (1 / x) holds exactly when x is 0 or a power of 1/2, which
characterizes the dyadic case.
The entropy bounds are stated for distributions on a Fintype. The countable-support and
infinite-entropy cases of [CT06], Section 5.11 are not formalized.
Main definitions #
Cslib.Probability.DDGTree.truncErr,.knuthYaoCost: binary-truncation error and its sum.Cslib.Probability.DDGTree.knuthYao: the Knuth–Yao tree of a finite distribution.
Main results #
Cslib.Probability.DDGTree.knuthYao_generates: the Knuth–Yao tree generatesp.Cslib.Probability.DDGTree.isLeast_expectedFlips_knuthYao: it minimizes the expected number of flips among all trees generatingp.Cslib.Probability.DDGTree.entropy_le_expectedFlips:H(p) ≤ E[T]for every generating tree.Cslib.Probability.DDGTree.expectedFlips_knuthYao_lt:E[T_KY] < H(p) + 2.Cslib.Probability.DDGTree.exists_generates_expectedFlips_eq_entropy_iff: some tree attainsE[T] = H(p)exactly when every positivep ais a power of1/2.
References #
- D. E. Knuth, A. C. Yao, The complexity of nonuniform random number generation.
- T. M. Cover, J. A. Thomas, Elements of Information Theory, Section 5.11, Theorems 5.11.1–5.11.3.
Binary-truncation errors #
Error of the n-digit binary truncation of x: x - ⌊2ⁿ x⌋ / 2ⁿ.
The Knuth–Yao cost ∑ₙ (x - ⌊2ⁿ x⌋ / 2ⁿ) of a probability x. It is the contribution of
an outcome of probability x to the expected number of flips of the Knuth–Yao tree.
Lower bound: an outcome of probability x costs at least its surprisal contribution.
The Knuth–Yao tree #
The number ⌊2ᵏ p a⌋ of depth-k positions of the Knuth–Yao tree lying at or below a leaf
labelled a (a leaf at depth j ≤ k counts 2 ^ (k - j) times). Equivalently, ⌊2ᵏ p a⌋ / 2ᵏ
is the probability that the tree outputs a within k flips.
The expected number of flips of the Knuth–Yao tree is ∑ₐ ν(p a).
Knuth–Yao upper bound ([CT06], Theorem 5.11.3): the Knuth–Yao tree reads fewer
than H(p) + 2 fair bits in expectation.
The Knuth–Yao tree attains the entropy exactly for dyadic distributions.
Dyadic case ([CT06], Theorem 5.11.2 and its converse): some tree generating p
reads exactly H(p) fair bits in expectation if and only if every positive probability p a is a
power of 1/2.