Chapter 18Conditional entropy
The cost of the optimal root-finger tree has a classical closed form. Up to constant factors it is the entropy bound , where counts the requests for (Chapter 14). A lazy finger profits from a different kind of regularity: a request is cheap when it is close, in the tree, to the previous request. So the natural candidate for a closed form of the optimal lazy-finger cost is the conditional entropy of each request given its predecessor, the information content of the transitions.
Bose, Douïeb, Iacono and Langerman (2016) show that this candidate fails (Lemma 7 of their paper). Some sequences have conditional entropy zero, since each key is always followed by the same key, and still cost per request with a lazy finger in any tree. The library proves a stronger form: the sequence costs that much in every dynamic BST. The proof is Wilber’s interleave bound (Chapter 17) applied to a repeated bit-reversal sequence. The paper therefore characterizes the optimal lazy finger differently, by the weighted benchmark of Chapter 15.
For a sequence on keys and a predecessor , let be the empirical conditional entropy of given , in bits, and let the conditional benchmark be , one unit per request plus the information of the transitions.
Lemma 7, for dynamic BSTs. For every constant and every startup allowance there are , a key and a sequence of valid requests such that , also when only the transitions inside are counted, so that , and such that every legal pointer-machine execution serving , from any initial tree on keys, costs more than
For lazy finger. Theorem 6 (Chapter 16) gives an execution of cost at most . Applying the lemma with and then gives . So no bound of the form holds. This two-line combination is arithmetic on the two listed theorems; the library does not state it as a separate theorem.
The Lean statements
/-- Lemma 7 of arXiv:1304.6897, strengthened to normalized request cost andarbitrary universe-dependent startup allowances. Every initial shape and everylegal dynamic execution are quantified, including offline executions. -/theorem obstruction (C : Nat) (allowance : Nat → Nat) : ∃ n p xs, 0 < n ∧ p < n ∧ n ≤ xs.length ∧ (∀ x ∈ xs, x < n) ∧ entropy n p xs = 0 ∧ adjacentInformation n xs = 0 ∧ cost n p xs = (xs.length : ℝ) ∧ ∀ s t k, s.size = n → Pointer.Execution s xs t k → (C : ℝ) * cost n p xs + allowance n < k := … normalized_unbounded C allowance/-- The dynamic/lazy inequality of Theorem 6 of arXiv:1304.6897, stated as alegal offline execution witness from any prescribed initial tree. This doesnot assert an online choice of the optimal reference tree. -/theorem optimal (s : Tree) (xs : List Nat) (valid : ∀ x ∈ xs, x < s.size) : ∃ u k, Pointer.Execution s xs u k ∧ k ≤ 16 * s.size + 464 * optimalCost s.size xs := … dynamic_optimal s xs validThe definitions are in Bounds/ConditionalEntropy/Definitions/Abstract.lean and Bounds/Interleave/BitReversal/Definitions/Abstract.lean, and the theorems in the Abstract.lean files next to them. Section 18.1 defines the conditional information and explains the normalization . Section 18.2 shows that deterministic and periodic sequences have zero information. Section 18.3 builds the bit-reversal sequence and bounds its cost with Wilber’s theorem. Section 18.4 assembles the obstruction. Section 18.5 explains why the conditional-entropy bound is still achievable outside the BST model, with more space.
18.1 Empirical conditional information
Everything is empirical: computed from the counts of the sequence itself, with no probabilistic source. The counts are the directed transition frequencies LazyFinger.frequency of Chapter 15: frequency p xs a b is the number of with , where . There are exactly transitions, one into each request.
/-- Total outgoing transition frequency on the finite key universe. -/def rowTotal (n : Nat) (f : Nat → Nat → Nat) (a : Nat) : Nat := ∑ b ∈ Finset.range n, f a b/-- Empirical conditional information, multiplied by the sequence length.Zero-frequency terms contribute zero. Outgoing row totals are used so that thefinite sequence's endpoint convention is explicit. -/noncomputable def information (n : Nat) (f : Nat → Nat → Nat) : ℝ := ∑ a ∈ Finset.range n, ∑ b ∈ Finset.range n, (f a b : ℝ) * Real.logb 2 ((rowTotal n f a : ℝ) / (f a b : ℝ))rowTotal n f a is , the number of transitions leaving . The information of a frequency matrix is
A zero entry contributes , since Lean’s 0 * _ is , whatever the totalized value of the logarithm. Row by row, is times the entropy of the empirical distribution of successors of . So is the conditional entropy of the empirical transition distribution. The row totals are the outgoing counts. Among every key appears as a predecessor exactly times, so the last request , which has no successor, is not counted. The docstring calls this the endpoint convention.
/-- Conditional information of the directed transitions, including the suppliedpredecessor of the first request. It is not implicitly taken to be a tree root. -/noncomputable def sequenceInformation (n p : Nat) (xs : List Nat) : ℝ := information n (LazyFinger.frequency p xs)/-- Conditional information using only adjacent requests, without an externalpredecessor. Empty and singleton request sequences have no transitions. -/noncomputable def adjacentInformation (n : Nat) : List Nat → ℝ | [] => 0 | p :: xs => sequenceInformation n p xsThere are two ways to treat the first request.
sequenceInformation n p xsuses an explicit predecessor for . It is not the root of any tree, just a key. This matches the lazy-finger benchmarks with a specified starting finger, and the multiple-tree structure of Section 18.5.adjacentInformation n xsuses only the transitions inside the sequence. Empty and one-element sequences have no transitions, hence zero information.
The obstruction holds with both conventions.
/-- The average empirical conditional entropy; empty sequences are totalized. -/noncomputable def entropy (n p : Nat) (xs : List Nat) : ℝ := sequenceInformation n p xs / xs.length/-- Request-normalized conditional benchmark, so deterministic transitions donot imply a zero service cost. -/noncomputable def cost (n p : Nat) (xs : List Nat) : ℝ := xs.length + sequenceInformation n p xsentropy n p xs is the average . For , Lean’s real division by zero returns , so the empty sequence has entropy . cost n p xs is the conditional benchmark .
Theorem (basic properties). The information of every frequency matrix is nonnegative. The benchmark is at least , and it equals , also when .
/-- Conditional information is nonnegative, including empty rows. -/theorem nonnegative (n : Nat) (f : Nat → Nat → Nat) : 0 ≤ information n f := information_nonneg n ftheorem request_charge (n p : Nat) (xs : List Nat) : (xs.length : ℝ) ≤ cost n p xs := length_le_cost n p xs/-- The normalized benchmark is exactly `m(1+H)`, also when `m = 0`. -/theorem normalization (n p : Nat) (xs : List Nat) : cost n p xs = (xs.length : ℝ) * (1 + entropy n p xs) := cost_eq_length_mul_entropy n p xs18.1.1 The normalization
The paper writes the conditional bound as , and the library defines it as , which is the same thing. The normalization is chosen for three reasons.
- Empty sequences. The average is undefined for . The total needs no division, and
normalizationshows that it agrees with under Lean’s convention , so nothing is lost by stating results with either form. - Deterministic transitions. If every key is always followed by the same key, then , as Section 18.2 shows. A bound would then claim that serving the sequence is free. Every model in this book charges at least one per request, so such a bound is false for trivial reasons, and its failure says nothing. With the unit per request, the benchmark is , and the obstruction says something real: no constant per request suffices.
- Capacity one. The positive result of Section 18.5 trades space for time with a factor , where is the capacity of each local tree. For this divides by . The library uses instead, together with , so every case is a finite and meaningful bound.
The information is also a sum over the actual transitions of the sequence. Each transition is charged , minus the logarithm of the empirical probability that is followed by :
/-- Sum any fixed charge over the actual directed transitions of a sequence. -/noncomputable def transitionSum (charge : Nat → Nat → ℝ) : Nat → List Nat → ℝ | _, [] => 0 | p, x :: xs => charge p x + transitionSum charge x xsTheorem (information as a transition sum). For a valid predecessor and valid requests, charging every transition the amount and summing over gives exactly the information .
/-- The sequence's empirical information is the sum of the actual transitioncharges; no independent or stationary source assumption is required. -/theorem transitions (n p : Nat) (xs : List Nat) (initial : p < n) (valid : ∀ x ∈ xs, x < n) : transitionSum (fun a b => Real.logb 2 ((rowTotal n (LazyFinger.frequency p xs) a : ℝ) / LazyFinger.frequency p xs a b)) p xs = sequenceInformation n p xs := sequenceInformation_transitions n p xs initial validThis is the form a data structure can aim for: if request costs given its predecessor, the total is . Nothing about independence or stationarity is assumed.
18.2 Deterministic sequences
A sequence is deterministic if one successor function explains all its transitions:
/-- Every next request is determined by the previous key. -/def Follows (next : Nat → Nat) : Nat → List Nat → Prop | _, [] => True | p, x :: xs => next p = x ∧ Follows next x xsFollows next p xs says that and . The theorem below is stated directly on frequency matrices instead, which is more general: each row has at most one nonzero entry.
Theorem (deterministic rows carry no information). If whenever , then .
/-- A deterministic successor gives zero information, even with unequal counts. -/theorem deterministic (n : Nat) (f : Nat → Nat → Nat) (next : Nat → Nat) (unique : ∀ a b, b ≠ next a → f a b = 0) : information n f = 0 := information_deterministic n f next uniqueThe row totals may differ arbitrarily: a key that occurs often and a key that occurs once both contribute , since in each row the only nonzero term is . Unlike the entropy bound of Chapter 14, conditional information ignores how often keys occur. It only measures how predictable each step is.
The sequences used below repeat a fixed period:
/-- Repeat a finite period, preserving all transitions at period boundaries. -/def repeatPeriod (period : List Nat) : Nat → List Nat | 0 => [] | rounds + 1 => period ++ repeatPeriod period roundsrepeatPeriod period rounds is rounds copies of period, concatenated. The transitions at the period boundaries are kept: the last key of one copy is followed by the first key of the next.
Theorem (repeated periods). Let the period consist of distinct keys. Then every repetition has zero adjacent-request information. With the last key of the period as the explicit predecessor, which is one choice of in the period for all repetition counts, the information is zero as well.
/-- Every repeated distinct-key period has zero adjacent-request information.No external predecessor is part of this convention. -/theorem adjacent_cycle (n : Nat) (period : List Nat) (distinct : period.Nodup) (rounds : Nat) : adjacentInformation n (repeatPeriod period rounds) = 0 := distinct_period_adjacent_zero n period distinct rounds/-- With an explicit predecessor, one choice works for every repetition count. -/theorem cycle (n : Nat) (period : List Nat) (distinct : period.Nodup) (nonempty : period ≠ []) : ∃ p ∈ period, ∀ rounds, sequenceInformation n p (repeatPeriod period rounds) = 0 := distinct_period_zero n period distinct nonemptyDistinctness makes the successor of each key unique: in the cyclic order of the period, each key is followed by the same key every time, including across the boundary. The period need not contain every key of the universe; keys that never occur have empty rows.
18.3 The bit-reversal sequence
Chapter 17 introduced the bit-reversal permutation as Wilber’s standard hard example: on a perfect reference tree, nearly every node alternates sides on nearly every request it sees, so the interleave bound is about per request. The obstruction needs a version of this example with an exact recursive structure, so the library builds it on the leaves of a perfect tree.
/-- A perfect reference BST with `2^height` leaves. Internal keys separate theleaves; requests below visit only leaves. -/def reference : Nat → Tree | 0 => .node .nil .nil | height + 1 => .node (reference height) (reference height)/-- Bit-reversal order on the leaves: alternate the two child copies of eachsmaller request. Values are full-tree inorder ranks, not leaf indices. -/def requests : Nat → List Nat | 0 => [0] | height + 1 => (requests height).flatMap fun x => [x, x + (reference height).size + 1]reference his the perfect tree of height : one node for , and two copies ofreference hbelow a root for . It has keys, of them leaves.requests hlists the leaves in bit-reversal order, as inorder ranks of the whole tree. For , every request ofrequests his replaced by , a leaf of the left copy, followed by , the same leaf in the right copy.
For the tree has keys and the requests are : the leaves in the order of their reversed binary indices . The internal keys separate the leaves and are never requested. Consecutive requests always lie in different halves of the root, and inside each half the requests again alternate between its two halves, and so on down.
theorem size (h : Nat) : (reference h).size + 1 = 2 ^ (h + 1) := reference_size htheorem length (h : Nat) : (requests h).length = 2 ^ h := requests_length htheorem valid (h : Nat) : ∀ x ∈ requests h, x < (reference h).size := requests_valid htheorem distinct (h : Nat) : (requests h).Nodup := requests_distinct hThese are the facts the obstruction needs: the size , the length , validity, and distinctness, which makes the repeated sequence deterministic.
Theorem (interleave of bit reversal). On its own reference tree, the bit-reversal sequence has interleave quantity at least , that is, at least half an alternation per request at each of levels.
/-- Bit reversal forces a logarithmic interleave count per requested leaf. -/theorem lower (h : Nat) : h * 2 ^ h ≤ 2 * interleave (reference h) (requests h) := interleave_lower hHere interleave is Wilber’s quantity Wilber.interleave of Chapter 17. The node at the root of each subtree of height sees requests that alternate on every step, so alternations. Summing over the subtrees of each height gives the bound.
The repeated sequence is then served by a single execution, which never resets its tree between periods. Wilber’s bounds of Chapter 17, for a pointer-machine execution of cost (Results.pointer_lower_bound) and for a rotation execution with rotations (Results.rotation_lower_bound), give lower bounds that are linear in the length.
Theorem (every BST pays per request). Let be rounds repetitions of requests h, of length . Every pointer-machine execution serving from any tree with keys has cost with . Every rotation execution with rotations has .
/-- Every conventional dynamic BST pays for these interleaves, across repeatedperiods without resetting its physical state. -/theorem pointer (h rounds : Nat) {s t : Tree} {k : Nat} (same : s.size = (reference h).size) (run : Pointer.Execution s (ConditionalEntropy.repeatPeriod (requests h) rounds) t k) : h * (ConditionalEntropy.repeatPeriod (requests h) rounds).length ≤ 24 * k := repeated_pointer_lower h rounds same run/-- Lower bound in the simplified arbitrary-rotation model, with request costskept explicit. -/theorem rotations (h rounds : Nat) {s t : Tree} {k : Nat} (same : s.size = (reference h).size) (run : RotationBST.Execution s (ConditionalEntropy.repeatPeriod (requests h) rounds) t k) : h * (ConditionalEntropy.repeatPeriod (requests h) rounds).length ≤ 8 * k + 4 * (ConditionalEntropy.repeatPeriod (requests h) rounds).length := repeated_rotation_lower h rounds same runSince , this is per request. The initial tree is arbitrary; only its size is fixed. The factor combines the factor 2 of the interleave count with the factor 12 of Wilber’s pointer bound.
18.4 The obstruction
The repeated bit-reversal sequence is the witness. It has a distinct period, so its conditional information is zero, and every BST pays per request on it.
Theorem (bit-reversal obstruction). For every height there is a predecessor in the universe of reference h such that, for every number of rounds, the repeated bit-reversal sequence has zero conditional information from , and every pointer-machine execution of it costs .
/-- Quantitative bit-reversal obstruction: logarithmic cost per request remainsnecessary despite zero empirical conditional information. -/theorem bit_reversal (h : Nat) : ∃ p < (Wilber.BitReversal.reference h).size, ∀ rounds, sequenceInformation (Wilber.BitReversal.reference h).size p (repeatPeriod (Wilber.BitReversal.requests h) rounds) = 0 ∧ ∀ s t k, s.size = (Wilber.BitReversal.reference h).size → Pointer.Execution s (repeatPeriod (Wilber.BitReversal.requests h) rounds) t k → h * (repeatPeriod (Wilber.BitReversal.requests h) rounds).length ≤ 24 * k := bit_reversal_obstruction hTo defeat a given constant and allowance , take , so that , and enough rounds that . Concretely, the proof takes rounds, which also gives .
Theorem (Lemma 7, normalized). For every and every allowance there are , and a sequence of valid requests whose conditional entropy from is , whose adjacent-request information is , and whose conditional benchmark is exactly , such that every legal pointer-machine execution of from every initial tree on keys costs more than .
/-- Lemma 7 of arXiv:1304.6897, strengthened to normalized request cost andarbitrary universe-dependent startup allowances. Every initial shape and everylegal dynamic execution are quantified, including offline executions. -/theorem obstruction (C : Nat) (allowance : Nat → Nat) : ∃ n p xs, 0 < n ∧ p < n ∧ n ≤ xs.length ∧ (∀ x ∈ xs, x < n) ∧ entropy n p xs = 0 ∧ adjacentInformation n xs = 0 ∧ cost n p xs = (xs.length : ℝ) ∧ ∀ s t k, s.size = n → Pointer.Execution s xs t k → (C : ℝ) * cost n p xs + allowance n < k := normalized_unbounded C allowance- All executions. The lower bound quantifies over every
Pointer.Execution, including offline ones that know the whole sequence, and over every initial tree of the right size. So it bounds the offline optimum, not just one algorithm. - Both conventions. The witness has zero information with the explicit predecessor
pand with adjacent requests only, so the result does not depend on how the first request is treated. - No escape through startup. The allowance
amay be any function of , chosen before the sequence. The condition rules out the degenerate escape of sequences shorter than the universe. - Lazy finger. The statement is about dynamic BSTs. The lazy-finger form follows from
Results.optimal, as explained in the headline box, but it is not a separate Lean theorem.
18.5 More space beats the obstruction
The obstruction is a statement about binary search trees. It does not say that is out of reach for every pointer structure. Theorem 9 of the same paper achieves it with a structure of multiple trees. For each key there is a small local search tree on the most frequent successors of , shaped according to their transition frequencies, together with one shared balanced fallback tree on all keys. A search starts from the local tree of the previous request. Chapter 28 formalizes this in the linked-search model of Chapter 11.
With local trees of capacity , the structure uses at most words and serves from the predecessor at cost at most
(Results.sequence). With about , this is with words (Results.polynomial_space). The two results fit together.
- The multiple-tree structure is not a BST. It follows stored links between different trees, so neither Wilber’s bound nor the obstruction applies to it.
- It is built from the transition matrix of the sequence it serves, so it is an offline, static structure. Preprocessing time is not part of the bound.
- Its cost uses the same benchmark
ConditionalEntropy.costas the obstruction, including the unit per request and the explicit predecessor .