Binary Search Trees in Lean Check a result Declarations Bibliography Lean source

Chapter 16Where lazy finger stands

Chapter 15 introduced the lazy finger: a static BST in which each search starts where the previous one ended, instead of at the root. This chapter places that model between its two natural neighbours.

  • Below it is the classical root-finger static tree, the setting of static optimality (Chapter 14). The tree is fixed and every search starts at the root.
  • Above it is the dynamic BST of Part I. It also searches from the root each time, but may rotate.

Theorem 6 of Bose, Douïeb, Iacono and Langerman (2016) says that, up to constant factors, lazy finger is never worse than root finger and never better than a dynamic BST, and that both gaps can be arbitrarily large. The chapter also states the consequences listed in §1.4 of their paper: the optimal lazy-finger tree has static optimality, the static finger property and the dynamic finger property, all at once.

Throughout, X=x1,…,xmX = x_1, \dots, x_m is a sequence of keys in {0,…,n−1}\{0, \dots, n-1\} (valid requests), and all three costs charge one unit per request plus one per pointer move or rotation. We write

  • RFt(X)=∑j(1+deptht(xj))\mathrm{RF}_t(X) = \sum_j \bigl(1 + \mathrm{depth}_t(x_j)\bigr) for the root-finger cost in a tree tt (StaticTree.cost);
  • LFn∗(X)\mathrm{LF}^*_n(X) for the optimal lazy-finger cost over all trees on nn keys, with the finger initially at the root (LazyFinger.optimalCost; the minimum is attained);
  • OPT\mathrm{OPT} for the least cost of a Pointer.Execution, a legal execution of the pointer machine of Chapter 7 that starts each search at the root.
Key result · Bose et al. 2016
Lazy finger sits strictly between root-finger static trees and dynamic BSTs

This is Theorem 6 of the paper. Let XX be a sequence of mm valid requests on nn keys.

  1. Lazy finger beats root finger up to a factor 2. For every tree tt on nn keys, LFn∗(X)≤2 RFt(X)\mathrm{LF}^*_n(X) \le 2\,\mathrm{RF}_t(X).
  2. A dynamic BST follows lazy finger up to a constant factor. From every initial tree ss on nn keys there is a legal pointer-machine execution serving XX whose cost kk satisfies $k  ≤  16 n+464 LFn∗(X).k \;\le\; 16\,n + 464\,\mathrm{LF}^*_n(X).$
  3. The first gap is unbounded. For every startup allowance a:N→Na : \mathbb N \to \mathbb N there is a family of sequences XmX_m, of length mm on nm≥1n_m \ge 1 keys, such that for every constant CC, once mm is large enough, $C LFnm∗(Xm)+a(nm)  <  RFt(Xm)for every tree t on nm keys.C\,\mathrm{LF}^*_{n_m}(X_m) + a(n_m) \;<\; \mathrm{RF}_t(X_m) \quad\text{for every tree } t \text{ on } n_m \text{ keys}.$
  4. The second gap is unbounded. For every aa there is a family XmX_m on nm≥1n_m \ge 1 keys such that for every CC, once mm is large enough, every initial tree ss on nmn_m keys admits a legal execution serving XmX_m at a cost kk with $C k+a(nm)  <  LFnm∗(Xm).C\,k + a(n_m) \;<\; \mathrm{LF}^*_{n_m}(X_m).$

Item 2 is an existence statement about executions, so it compares lazy finger with the offline optimum. It does not give an online algorithm, and the execution may depend on the whole sequence. The families in items 3 and 4 are fixed before CC is chosen, so the ratios tend to infinity along one family: LF∗=o(RF)\mathrm{LF}^* = o(\mathrm{RF}) and OPT=o(LF∗)\mathrm{OPT} = o(\mathrm{LF}^*), even after any one-time startup allowance.

The Lean statements
theoremLazyFinger.Results.optimal_root_fingerpropext · Classical.choice · Quot.soundBounds/LazyFinger/Abstract.lean:42
/-- First inequality of the hierarchy, against every fixed root-finger tree. -/theorem optimal_root_finger (t : Tree) (xs : List Nat) :    optimalCost t.size xs ≤ 2 * StaticTree.cost t xs := … optimalCost_le_twice_static t xs
theoremLazyFinger.Dynamic.Results.optimalpropext · Classical.choice · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:55
/-- 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 valid
theoremLazyFinger.Sequential.Results.familypropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:65
/-- One family, fixed before the factor is chosen, has an unbounded separationratio as its sequence length grows. -/theorem family (allowance : Nat → Nat) :    ∃ sizes : Nat → Nat, ∃ requests : Nat → List Nat,      (∀ m, 0 < sizes m ∧ (requests m).length = m ∧        (∀ x ∈ requests m, x < sizes m)) ∧      ∀ C, ∃ threshold, ∀ m, threshold ≤ m →        ∀ root : Tree, root.size = sizes m →          C * optimalCost (sizes m) (requests m) + allowance (sizes m) <            StaticTree.cost root (requests m) := … optimal_root_lazy_family allowance
theoremLazyFinger.Separation.Results.familypropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:72
/-- One family, fixed before the factor and initial tree are chosen, witnessesan unbounded lazy-finger/dynamic separation ratio as length grows. -/theorem family (allowance : Nat → Nat) :    ∃ sizes : Nat → Nat, ∃ requests : Nat → List Nat,      (∀ m, 0 < sizes m ∧ (requests m).length = m ∧        (∀ x ∈ requests m, x < sizes m)) ∧      ∀ C, ∃ threshold, ∀ m, threshold ≤ m →        ∀ s : Tree, s.size = sizes m → ∃ t k, Pointer.Execution s (requests m) t k ∧          C * k + allowance (sizes m) < optimalCost (sizes m) (requests m) := …  lazy_dynamic_family allowance
18 definitions in 4 chapters · reading list
Main result · Bose et al. 2016
The optimal lazy-finger tree has static optimality, static finger and dynamic finger at once

This is the list of consequences in §1.4 of the paper. For every sequence XX of mm valid requests on nn keys there is a tree tt on nn keys whose lazy-finger cost, from the root, is the optimum LFn∗(X)\mathrm{LF}^*_n(X), and this cost is at most

  • 2(m+∑xqxlog⁡2(m/qx))2\bigl(m + \sum_x q_x \log_2 (m / q_x)\bigr), where qxq_x counts the requests for xx (static optimality);
  • 6∑j(1+log⁡2(∣xj−f∣+1))6 \sum_j \bigl(1 + \log_2(|x_j - f| + 1)\bigr), for every finger ff (static finger);
  • n+4∑j(1+log⁡2(∣xj−xj−1∣+1))n + 4 \sum_j \bigl(1 + \log_2(|x_j - x_{j-1}| + 1)\bigr) with x0=px_0 = p, for every key p<np < n (dynamic finger).

The tree may depend on the sequence; it is chosen before ff and pp. The term nn pays once for starting the finger at the root rather than at pp.

The Lean statement
theoremLazyFinger.Consequences.Results.simultaneouspropext · Classical.choice · Quot.soundBounds/LazyFinger/Consequences/Abstract.lean:42
/-- The three consequences in §1.4 of arXiv:1304.6897 hold for one optimalstatic tree. The choice can depend on the sequence, but precedes quantificationover the fixed finger and predecessor. This is not an online tree-selection rule. -/theorem simultaneous (n : Nat) (xs : List Nat) (valid : ∀ x ∈ xs, x < n) :    ∃ t : Tree, t.size = n ∧ cost t xs = optimalCost n xs ∧      (cost t xs : ℝ) ≤ 2 * Bounds.staticCost n xs ∧      (∀ f, (cost t xs : ℝ) ≤ 6 * Bounds.fingerCost f xs) ∧      ∀ p, p < n → (cost t xs : ℝ) ≤ n + 4 * Bounds.dynamicFingerCostFrom p xs := …  optimal_three_bounds n xs valid
10 definitions in 3 chapters · reading list

To confirm the results, the two boxes suffice. The rest of the chapter explains them in the order of the comparison chain. Section 16.1 gives an overview of the chain. Section 16.2 proves item 2, by simulating the lazy finger with a pointer machine. Section 16.3 proves item 3 with sequential scans. Section 16.4 counts nearby keys in a fixed tree, and Section 16.5 uses the count to prove item 4 with alternating pairs. Section 16.6 derives the consequences. Item 1 is proved in Chapter 15. The definitions are in Bounds/LazyFinger/{Sequential,Separation,Neighborhood}/Definitions/Abstract.lean, and the theorems in the Abstract.lean files of Bounds/LazyFinger/Dynamic, Sequential, Separation, Neighborhood and Consequences.

16.1 The chain at a glance

All three models use the same keys and charge one unit per request. They differ in where a search starts and whether the tree may change.

Model Tree A search starts at Cost of a request Lean
Root finger fixed the root 1+deptht(x)1 + \mathrm{depth}_t(x) StaticTree.cost
Lazy finger fixed the previous request 1+dt(xj−1,xj)1 + d_t(x_{j-1}, x_j) LazyFinger.cost
Dynamic BST rotates the root moves and rotations, plus one Pointer.Execution

Here dt(x,y)d_t(x, y) is the number of edges on the path between xx and yy in tt, which is LazyFinger.distance. The first search of a lazy finger starts at the root.

The chain reads

OPT  ≲  LF∗  ≤  2 min⁡tRFt,\mathrm{OPT} \;\lesssim\; \mathrm{LF}^* \;\le\; 2\,\min_t \mathrm{RF}_t,

where ≲\lesssim hides the factor 464464 and the additive 16n16n of item 2. In words:

  • Lazy finger is at least as good as root finger, up to a factor 2. Going from xx to yy through their lowest common ancestor is never longer than going from the root to xx and then from the root to yy. Charging each move to one of the two root-to-key paths gives the factor 2. This is Results.root_finger for a fixed tree and Results.optimal_root_finger for the optimum, both in Chapter 15.
  • A dynamic BST is at least as good as lazy finger, up to a constant factor. A dynamic BST could simply keep the tree fixed and walk from one request to the next, but the pointer machine restarts every search at the root. So the simulation has to carry a finger along inside the tree. Section 16.2 shows how.
  • Lazy finger can be much better than root finger. A sequential scan 0,1,…,n−10, 1, \dots, n-1 costs O(1)O(1) amortized per request with a lazy finger in every tree, while every root-finger tree pays about log⁡2n\log_2 n per request.
  • A dynamic BST can be much better than lazy finger. A sequence that alternates x,y,x,y,…x, y, x, y, \dots for a long time, for each pair (x,y)(x, y) in turn, is cheap for a BST that brings the current pair to the top. A fixed tree, however, must place most pairs far apart.

16.2 A dynamic BST can follow a lazy finger

The goal of this section is item 2 of the headline. Let tt be a tree and XX a sequence. The lazy finger walks along the edges of tt from one request to the next. A pointer machine can perform the same walk, but it must return to the root before each search. The library closes this gap in three steps.

  1. The lazy-finger distance is exactly the length of a shortest pointer walk (Section 16.2.1).
  2. A lazy finger is therefore a one-finger execution in the multi-finger model of Chapter 10, at exactly the lazy-finger cost (Section 16.2.2).
  3. A multi-finger execution with a constant number of fingers can be simulated by a conventional BST at a constant factor. This is the finger hand of Section 35.2. The method is due to Demaine, Iacono, Langerman and Özkan (2013). Optimizing over reference trees then gives the theorem (Section 16.2.3).

16.2.1 Walking the edge distance

The pointer machine’s configurations (Pointer.Config) are a cursor on a node of a tree. Its instructions (Pointer.Step) move the cursor to a parent or child, or rotate. The navigation-only instructions are Pointer.Move, and a sequence of them is a Pointer.Walk; a walk never changes the tree.

Theorem (the distance is walkable). For valid keys x,yx, y of a tree tt, there are cursors at xx and at yy in tt joined by exactly dt(x,y)d_t(x, y) pointer instructions, and in fact by a navigation-only walk of that length.

theoremLazyFinger.Dynamic.Results.walkpropext · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:9
/-- Realize the lazy-finger distance by exactly that many pointer instructions.The endpoints are cursors on the fixed reference tree. -/theorem walk (t : Tree) (x y : Nat) (hx : x < t.size) (hy : y < t.size) :    ∃ a b : Pointer.Config, a.tree = t ∧ b.tree = t ∧ a.key? = some x ∧ b.key? = some y ∧      Pointer.Trace a b (distance t x y) := pointer_walk t x y hx hy
theoremLazyFinger.Dynamic.Results.readonlypropext · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:15
/-- The realizing path uses only navigation, with no intervening rotations. -/theorem readonly (t : Tree) (x y : Nat) (hx : x < t.size) (hy : y < t.size) :    ∃ a b : Pointer.Config, a.tree = t ∧ b.tree = t ∧ a.key? = some x ∧ b.key? = some y ∧      Pointer.Walk a b (distance t x y) := readonly_walk t x y hx hy

The first statement uses Pointer.Trace, which allows any instruction, and the second uses a Pointer.Walk. Both fix the tree: a.tree = t and b.tree = t.

Theorem (the distance is shortest). Every navigation-only walk from a cursor at xx to a cursor at yy has at least d(x,y)d(x, y) steps. Conversely, from a cursor at x≠yx \ne y some single move reaches a key zz with d(z,y)+1=d(x,y)d(z, y) + 1 = d(x, y).

theoremLazyFinger.Dynamic.Results.shortestpropext · Classical.choice · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:20
/-- The edge metric is a lower bound for every navigation-only walk. -/theorem shortest {a b : Pointer.Config} {k : Nat} (walk : Pointer.Walk a b k)    (x y : Nat) (keyA : a.key? = some x) (keyB : b.key? = some y) : distance a.tree x y ≤ k :=  distance_le_walk walk x y keyA keyB
theoremLazyFinger.Dynamic.Results.towardpropext · Classical.choice · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:25
/-- A shortest route can be followed one legal parent/child instruction at a time. -/theorem toward (a : Pointer.Config) (x y : Nat) (key : a.key? = some x)    (valid : y < a.tree.size) (different : x ≠ y) :    ∃ b z, Pointer.Move a b ∧ b.key? = some z ∧ distance b.tree z y + 1 = distance a.tree x y :=  toward_exists a x y key valid different

So LazyFinger.distance, defined by recursion on the tree, is the graph metric of the tree as the pointer machine sees it, and it can be followed greedily, one legal move at a time.

16.2.2 One persistent finger

The multi-finger model of Chapter 10 keeps several cursors in one shared tree (Multifinger.State). A request is served by any finger reaching the requested key, and the fingers stay where they are between requests (Multifinger.Execution). With one finger this is exactly a lazy finger.

Theorem (lazy finger is a one-finger execution). Let tt be a tree, pp a valid key and XX a valid sequence. There is a one-finger execution from the state “tree tt, finger at pp” that serves XX and costs exactly the lazy-finger cost of XX from pp. Its final state has the same tree and the finger at some key qq.

theoremLazyFinger.Dynamic.Results.persistentpropext · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:31
/-- Retaining one finger between requests gives exactly the lazy-finger cost. -/theorem persistent (t : Tree) (p : Nat) (xs : List Nat) (hp : p < t.size)    (valid : ∀ x ∈ xs, x < t.size) :    ∃ q : Nat, Multifinger.Execution (⟨t, fun _ : Fin 1 => p⟩ : Multifinger.State 1) xs      ⟨t, fun _ => q⟩ (costFrom t p xs) := multifinger_execution t p xs hp valid

The cost is LazyFinger.costFrom t p xs, one unit per request plus the walked distance, with no rounding. The tree never changes.

16.2.3 From one finger to a conventional BST

The pointer machine restarts each search at the root. To serve the next request it must therefore reach the finger’s position again, cheaply. The finger hand of Section 35.2 does this. It maintains, inside the one physical tree, a compact representation of the paths that join the root to all fingers, the hand. With it, the root reaches any finger, and a finger takes a step, at amortized constant cost for a fixed number of fingers. In the library, a multi-finger execution with ff fingers and cost cc becomes a conventional execution of cost at most (344+60(f+1)) c(344 + 60(f + 1))\,c. For one finger this is 464 c464\,c, the constant below. When all fingers start at the root, the hand starts in the original tree with zero potential, so no startup term appears.

Theorem (same initial tree). For every tree tt and valid sequence XX there is a legal pointer-machine execution from tt serving XX at cost at most 464 LFt(X)464\,\mathrm{LF}_t(X), where LFt\mathrm{LF}_t is the lazy-finger cost in tt from the root.

theoremLazyFinger.Dynamic.Results.same_treepropext · Classical.choice · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:37
/-- A conventional dynamic execution from the same initial tree, with constantfactor overhead. Each request starts at the root in the target machine. -/theorem same_tree (t : Tree) (xs : List Nat) (valid : ∀ x ∈ xs, x < t.size) :    ∃ u k, Pointer.Execution t xs u k ∧ k ≤ 464 * cost t xs := dynamic_execution t xs valid

The comparison is between two executions that start in the same tree. If the dynamic BST may choose its initial tree, it starts in an optimal lazy-finger tree:

theoremLazyFinger.Dynamic.Results.optimal_treepropext · Classical.choice · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:42
/-- When the initial tree may be chosen, there is no startup term. The selectedinitial tree may depend on the whole sequence. -/theorem optimal_tree (n : Nat) (xs : List Nat) (valid : ∀ x ∈ xs, x < n) :    ∃ t u k, t.size = n ∧ Pointer.Execution t xs u k ∧ k ≤ 464 * optimalCost n xs :=  dynamic_optimal_tree n xs valid

Here the initial tree t is part of the witness, and depends on the whole sequence. Usually the initial tree is prescribed instead. The pointer machine can transform any tree on nn keys into any other with at most 16n16n instructions (Results.reshape, Chapter 7), and the library charges that reshaping to the first request:

theoremLazyFinger.Dynamic.Results.referencepropext · Classical.choice · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:48
/-- An arbitrary fixed initial tree, with explicit cost to reshape it to thereference tree. This also includes the empty sequence and empty universe. -/theorem reference (s t : Tree) (xs : List Nat) (same : s.size = t.size)    (valid : ∀ x ∈ xs, x < t.size) :    ∃ u k, Pointer.Execution s xs u k ∧ k ≤ 16 * s.size + 464 * cost t xs :=  dynamic_reference_tree s t xs same valid

The statement covers the empty sequence and the empty universe, where the execution is empty.

Theorem (dynamic BSTs follow optimal lazy finger, Theorem 6). Let ss be any tree on nn keys and XX a valid sequence. There is a legal pointer-machine execution from ss that serves XX at cost k≤16n+464 LFn∗(X)k \le 16n + 464\,\mathrm{LF}^*_n(X).

theoremLazyFinger.Dynamic.Results.optimalpropext · Classical.choice · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:55
/-- 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 valid

The initial tree is quantified before the optimal lazy-finger tree is chosen inside the proof. The execution reshapes ss into that tree and then simulates the finger. It therefore knows the whole sequence: the theorem bounds the offline optimum, and is not an online algorithm. When there are at least as many requests as keys, the unit request charges pay for the reshaping, since LFn∗(X)≥m≥n\mathrm{LF}^*_n(X) \ge m \ge n:

theoremLazyFinger.Dynamic.Results.long_sequencepropext · Classical.choice · Quot.soundBounds/LazyFinger/Dynamic/Abstract.lean:62
/-- For `m ≥ n`, normalized request charges absorb initialization. -/theorem long_sequence (s : Tree) (xs : List Nat)    (valid : ∀ x ∈ xs, x < s.size) (long : s.size ≤ xs.length) :    ∃ u k, Pointer.Execution s xs u k ∧ k ≤ 480 * optimalCost s.size xs :=  dynamic_optimal_long s xs valid long

16.3 Sequential scans separate lazy from root finger

The first separation uses the simplest possible sequence: scan the keys in order, and repeat.

defLazyFinger.scansno axiomsBounds/LazyFinger/Sequential/Definitions/Abstract.lean:8
/-- Full ordered scans of the key universe, repeated `rounds` times. -/def scans (n : Nat) : Nat → List Nat  | 0 => []  | rounds + 1 => List.range n ++ scans n rounds
defLazyFinger.scanPrefixno axiomsBounds/LazyFinger/Sequential/Definitions/Abstract.lean:13
/-- Ordered scans stopped at an exact request count, including a partial last scan. -/def scanPrefix (n length : Nat) : List Nat :=  scans n (length / n) ++ List.range (length % n)

scans n rounds is rounds copies of 0,1,…,n−10, 1, \dots, n-1. scanPrefix n length stops the repetition at exactly length requests: it takes ⌊length/n⌋\lfloor \mathit{length}/n \rfloor full scans and then the first length mod n\mathit{length} \bmod n keys of another. For n=0n = 0 the division gives 00, so the prefix is empty, and the validity statement below requires n>0n > 0.

Lazy finger scans in linear time. In any fixed tree, an inorder traversal crosses each edge twice, and the jump from the last key back to the first crosses each edge at most once more. With the unit per request, a scan costs at most 4n4n.

Theorem (scans with a lazy finger). For every tree tt on nn keys, rounds scans cost at most 4⋅rounds⋅n4 \cdot \mathit{rounds} \cdot n with a lazy finger starting at the root, and also from any valid starting key. A scan prefix of length m≥nm \ge n costs at most 8⌊m/n⌋n≤8m8\lfloor m/n\rfloor n \le 8m.

theoremLazyFinger.Sequential.Results.lazy_scanpropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:9
/-- Every fixed tree executes repeated ordered scans in linear lazy-finger cost. -/theorem lazy_scan (t : Tree) (rounds : Nat) :    cost t (scans t.size rounds) ≤ 4 * rounds * t.size := scans_cost t rounds
theoremLazyFinger.Sequential.Results.lazy_scan_frompropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:13
/-- The same bound from any valid initial key. -/theorem lazy_scan_from (t : Tree) (p rounds : Nat) (hp : p < t.size) :    costFrom t p (scans t.size rounds) ≤ 4 * rounds * t.size := scans_costFrom t p rounds hp
theoremLazyFinger.Sequential.Results.lazy_prefixpropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:47
theorem lazy_prefix (t : Tree) (m : Nat) (positive : 0 < t.size) (long : t.size ≤ m) :    cost t (scanPrefix t.size m) ≤ 8 * (m / t.size) * t.size :=  scanPrefix_cost t m positive long

The bounds hold for every tree shape, so they bound the optimum LFn∗\mathrm{LF}^*_n too.

Root finger pays the entropy. Each key is requested equally often in scans, so the entropy bound of Chapter 14 is m(1+log⁡2n)m(1 + \log_2 n), and every fixed tree pays at least a third of it (Results.entropy_lower_bound).

Theorem (scans with a root finger). For every tree tt on nn keys, rounds⋅n (1+log⁡2n)≤3 RFt(scans)\mathit{rounds} \cdot n\,(1 + \log_2 n) \le 3\,\mathrm{RF}_t(\text{scans}).

theoremLazyFinger.Sequential.Results.root_scanpropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:17
/-- Every root-finger tree pays a logarithmic charge per scan request. -/theorem root_scan (t : Tree) (rounds : Nat) :    (rounds * t.size : Nat) * (1 + Real.logb 2 (t.size : ℝ)) ≤      3 * (StaticTree.cost t (scans t.size rounds) : ℝ) := scans_root_lower t rounds

The gap. The ratio between the two bounds is about (1+log⁡2n)/12(1 + \log_2 n)/12, which is larger than any constant CC once n=212Cn = 2^{12C}.

Theorem (a strict gap for every factor). Let C≥0C \ge 0, rounds≥1\mathit{rounds} \ge 1 and n=212Cn = 2^{12C}. For any two trees on nn keys, a lazy finger in the first and a root finger in the second, CC times the lazy-finger cost of rounds scans is less than the root-finger cost.

theoremLazyFinger.Sequential.Results.strict_gappropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:22
/-- A concrete family with any prescribed strict gap, independent of the lazyand root-finger tree shapes, for any positive number of scans. -/theorem strict_gap (C rounds : Nat) (hr : 0 < rounds) (lazy root : Tree)    (hl : lazy.size = 2 ^ (12 * C)) (ht : root.size = 2 ^ (12 * C)) :    C * cost lazy (scans (2 ^ (12 * C)) rounds) <      StaticTree.cost root (scans (2 ^ (12 * C)) rounds) := scans_separate C rounds hr lazy root hl ht

The two trees are independent, so neither model gets to see the other’s choice. The next statements turn this into statements about the optimum LF∗\mathrm{LF}^*, with increasingly strong quantifiers.

Theorem (unbounded ratio). For every CC there is a universe n≥1n \ge 1 and a valid sequence of length nn (one scan) such that C LFn∗(X)<RFt(X)C\,\mathrm{LF}^*_n(X) < \mathrm{RF}_t(X) for every tree tt on nn keys. Moreover, for every startup allowance aa, there is such a sequence of length at least nn with C LFn∗(X)+a(n)<RFt(X)C\,\mathrm{LF}^*_n(X) + a(n) < \mathrm{RF}_t(X).

theoremLazyFinger.Sequential.Results.unbounded_ratiopropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:29
/-- No uniform constant bounds best root-finger cost by best lazy-finger cost. -/theorem unbounded_ratio (C : Nat) :    ∃ n xs, 0 < n ∧ xs.length = n ∧ (∀ x ∈ xs, x < n) ∧      ∀ t : Tree, t.size = n → C * optimalCost n xs < StaticTree.cost t xs := root_lazy_unbounded C
theoremLazyFinger.Sequential.Results.gap_beyond_startuppropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:34
/-- No universe-dependent startup allowance repairs the missing constant-factorcomparison: a sufficiently long repeated scan defeats it. -/theorem gap_beyond_startup (C : Nat) (allowance : Nat → Nat) :    ∃ n xs, 0 < n ∧ n ≤ xs.length ∧ (∀ x ∈ xs, x < n) ∧      ∀ t : Tree, t.size = n → C * optimalCost n xs + allowance n < StaticTree.cost t xs :=  root_lazy_unbounded_with_startup C allowance

A single sequence for each CC could be an artefact of a short length. The next two theorems fix a universe for each CC and then let the length be any large enough mm: the witness is scanPrefix n m with n=224Cn = 2^{24C}, and the threshold is about 3 a(n) n3\,a(n)\,n.

Theorem (every long length). For every CC and every allowance aa there are n≥1n \ge 1 and a threshold T≥nT \ge n such that every length m≥Tm \ge T has a valid sequence XX of length mm with C LFu(X)+a(n)<RFt(X)C\,\mathrm{LF}_u(X) + a(n) < \mathrm{RF}_t(X) for all trees u,tu, t on nn keys, and hence with C LFn∗(X)+a(n)<RFt(X)C\,\mathrm{LF}^*_n(X) + a(n) < \mathrm{RF}_t(X).

theoremLazyFinger.Sequential.Results.all_lengths_shapespropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:51
theorem all_lengths_shapes (C : Nat) (allowance : Nat → Nat) :    ∃ n threshold, 0 < n ∧ n ≤ threshold ∧ ∀ m, threshold ≤ m →      ∃ xs, xs.length = m ∧ (∀ x ∈ xs, x < n) ∧        ∀ lazy root : Tree, lazy.size = n → root.size = n →          C * cost lazy xs + allowance n < StaticTree.cost root xs :=  root_lazy_all_lengths C allowance
theoremLazyFinger.Sequential.Results.all_lengthspropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:58
theorem all_lengths (C : Nat) (allowance : Nat → Nat) :    ∃ n threshold, 0 < n ∧ n ≤ threshold ∧ ∀ m, threshold ≤ m →      ∃ xs, xs.length = m ∧ (∀ x ∈ xs, x < n) ∧        ∀ root : Tree, root.size = n →          C * optimalCost n xs + allowance n < StaticTree.cost root xs :=  optimal_root_lazy_all_lengths C allowance

Theorem (one family, Theorem 6). For every allowance aa there is a single family of sequences XmX_m, one of each length mm, on universes nm≥1n_m \ge 1, such that for every CC, eventually, C LFnm∗(Xm)+a(nm)<RFt(Xm)C\,\mathrm{LF}^*_{n_m}(X_m) + a(n_m) < \mathrm{RF}_t(X_m) for every tree tt on nmn_m keys.

theoremLazyFinger.Sequential.Results.familypropext · Classical.choice · Quot.soundBounds/LazyFinger/Sequential/Abstract.lean:65
/-- One family, fixed before the factor is chosen, has an unbounded separationratio as its sequence length grows. -/theorem family (allowance : Nat → Nat) :    ∃ sizes : Nat → Nat, ∃ requests : Nat → List Nat,      (∀ m, 0 < sizes m ∧ (requests m).length = m ∧        (∀ x ∈ requests m, x < sizes m)) ∧      ∀ C, ∃ threshold, ∀ m, threshold ≤ m →        ∀ root : Tree, root.size = sizes m →          C * optimalCost (sizes m) (requests m) + allowance (sizes m) <            StaticTree.cost root (requests m) := optimal_root_lazy_family allowance
Why the universe must grow

On a fixed universe the ratio is bounded: every root-finger tree has depth less than nn, so RFt(X)≤n m≤n LFn∗(X)\mathrm{RF}_t(X) \le n\,m \le n\,\mathrm{LF}^*_n(X). A family with an unbounded ratio therefore needs nm→∞n_m \to \infty. The library builds it by diagonalization, from the eventual witnesses of all_lengths. At length mm it takes the largest factor C≤mC \le m whose threshold is at most mm, and uses that factor’s universe and witness. Short lengths use a one-key fallback. Here nmn_m grows extremely slowly, roughly like 224C2^{24C} for the factor CC that mm can afford, but the theorem only asserts existence.

16.4 Neighbourhoods in a fixed tree

The second separation needs a lower bound on lazy-finger distances in every tree. The bound comes from counting: every node of a binary tree has at most three neighbours, so few keys are close to any given key.

defLazyFinger.ballpropext · Classical.choice · Quot.soundBounds/LazyFinger/Neighborhood/Definitions/Abstract.lean:9
/-- Existing ranks at lazy-finger distance at most `radius` from `x`. -/def ball (t : Tree) (x radius : Nat) : Finset Nat :=  (Finset.range t.size).filter fun y => distance t x y ≤ radius

ball t x r is the set of valid ranks y<ny < n with dt(x,y)≤rd_t(x, y) \le r.

Theorem (neighbourhoods are small). For every valid xx, the ball of radius rr around xx has at most 7r7^r keys.

theoremLazyFinger.Neighborhood.Results.cardinalitypropext · Classical.choice · Quot.soundBounds/LazyFinger/Neighborhood/Abstract.lean:9
/-- Uniform exponential bound on every fixed tree's lazy-finger neighborhood. -/theorem cardinality (t : Tree) (x r : Nat) (valid : x < t.size) :    (ball t x r).card ≤ 7 ^ r := ball_card t x r valid

The true bound for a graph of maximum degree three is 1+3(2r−1)1 + 3(2^r - 1). The base 77 is cruder, but any fixed base gives the logarithmic lower bounds below, and it changes only constants.

All keys outside the ball are at distance at least r+1r + 1. Summing gives the following bounds.

Theorem (distance sums). For valid xx,

(r+1) n  ≤  (r+1) 7r+∑y<ndt(x,y).(r + 1)\,n \;\le\; (r + 1)\,7^r + \sum_{y < n} d_t(x, y).

If n≥2⋅7rn \ge 2 \cdot 7^r, then (r+1) n≤2∑ydt(x,y)(r + 1)\,n \le 2 \sum_y d_t(x, y), so the average distance from xx is at least (r+1)/2(r+1)/2. Summing over xx as well, (r+1) n2≤2∑x∑ydt(x,y)(r + 1)\,n^2 \le 2 \sum_x \sum_y d_t(x, y).

theoremLazyFinger.Neighborhood.Results.distance_sumpropext · Classical.choice · Quot.soundBounds/LazyFinger/Neighborhood/Abstract.lean:13
/-- Counting the near ball gives a distance-sum lower bound without asymptotics. -/theorem distance_sum (t : Tree) (x r : Nat) (valid : x < t.size) :    (r + 1) * t.size ≤ (r + 1) * 7 ^ r + ∑ y ∈ Finset.range t.size, distance t x y :=  distance_sum_lower t x r valid
theoremLazyFinger.Neighborhood.Results.averagepropext · Classical.choice · Quot.soundBounds/LazyFinger/Neighborhood/Abstract.lean:18
/-- Every starting key has average distance at least `(r+1)/2` when the universehas at least `2 * 7^r` keys. -/theorem average (t : Tree) (x r : Nat) (valid : x < t.size) (large : 2 * 7 ^ r ≤ t.size) :    (r + 1) * t.size ≤ 2 * ∑ y ∈ Finset.range t.size, distance t x y :=  average_distance_lower t x r valid large
theoremLazyFinger.Neighborhood.Results.pairspropext · Classical.choice · Quot.soundBounds/LazyFinger/Neighborhood/Abstract.lean:24
/-- The all-pairs version used for the lazy-finger/dynamic separation. -/theorem pairs (t : Tree) (r : Nat) (large : 2 * 7 ^ r ≤ t.size) :    (r + 1) * t.size * t.size ≤      2 * ∑ x ∈ Finset.range t.size, ∑ y ∈ Finset.range t.size, distance t x y :=  pair_distance_lower t r large

Taking the largest rr with 2⋅7r≤n2 \cdot 7^r \le n, the average distance between two keys of any tree on nn keys is at least about 12log⁡7(n/2)\tfrac12 \log_7(n/2). Every statement is in exact natural-number arithmetic, without asymptotics.

16.5 Alternating pairs separate dynamic from lazy finger

The second separation uses a sequence with very little to remember at any moment, but too many different moments for one fixed tree.

defLazyFinger.pairBlockno axiomsBounds/LazyFinger/Separation/Definitions/Abstract.lean:8
/-- Repeat an alternating pair. A long block has a two-key working set. -/def pairBlock (x y : Nat) : Nat → List Nat  | 0 => []  | rounds + 1 => x :: y :: pairBlock x y rounds
defLazyFinger.pairBlocksno axiomsBounds/LazyFinger/Separation/Definitions/Abstract.lean:13
/-- Concatenate alternating blocks for an explicit list of ordered pairs. -/def pairBlocks (pairs : List (Nat × Nat)) (rounds : Nat) : List Nat :=  pairs.flatMap fun pair => pairBlock pair.1 pair.2 rounds
defLazyFinger.pairSequenceno axiomsBounds/LazyFinger/Separation/Definitions/Abstract.lean:17
/-- All ordered pairs, each occurring in one long alternating block. -/def pairSequence (n rounds : Nat) : List Nat :=  pairBlocks ((List.range n).flatMap fun x => (List.range n).map fun y => (x, y)) rounds
defLazyFinger.pairSequenceAtLengthno axiomsBounds/LazyFinger/Separation/Definitions/Abstract.lean:21
/-- All-pairs blocks followed by a repeated key, giving any prescribed length.The padding key is valid when the universe is nonempty. -/def pairSequenceAtLength (n m : Nat) : List Nat :=  pairSequence n (m / (2 * n * n)) ++ List.replicate (m % (2 * n * n)) 0
  • pairBlock x y rounds is x,y,x,y,…x, y, x, y, \dots, with rounds copies of the pair.
  • pairBlocks concatenates such blocks for a list of pairs.
  • pairSequence n rounds does this for all n2n^2 ordered pairs (x,y)(x, y) with x,y<nx, y < n, in lexicographic order. Pairs with x=yx = y are included and are harmless.
  • pairSequenceAtLength n m takes ⌊m/2n2⌋\lfloor m / 2n^2 \rfloor rounds and pads with copies of key 00 to reach length exactly mm. The padding key is valid when n>0n > 0.
theoremLazyFinger.Separation.Results.lengthpropext · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:9
/-- The witnesses enumerate all ordered pairs in long alternating blocks. -/theorem length (n rounds : Nat) : (pairSequence n rounds).length = 2 * rounds * n * n :=  pairSequence_length n rounds
theoremLazyFinger.Separation.Results.validpropext · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:13
theorem valid (n rounds : Nat) : ∀ x ∈ pairSequence n rounds, x < n :=  pairSequence_valid n rounds
theoremLazyFinger.Separation.Results.prescribed_lengthpropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:46
theorem prescribed_length (n m : Nat) : (pairSequenceAtLength n m).length = m :=  pairSequenceAtLength_length n m
theoremLazyFinger.Separation.Results.prescribed_validpropext · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:49
theorem prescribed_valid (n m : Nat) (positive : 0 < n) :    ∀ x ∈ pairSequenceAtLength n m, x < n := pairSequenceAtLength_valid n m positive

Lazy finger pays the average distance. In a fixed tree tt, each repetition in the block of (x,y)(x, y) contains the transition x→yx \to y, which costs dt(x,y)d_t(x, y). So the sequence costs at least rounds⋅∑x,ydt(x,y)\mathit{rounds} \cdot \sum_{x, y} d_t(x, y), whatever the starting finger and the transitions between blocks. The neighbourhood bound gives:

Theorem (lazy-finger lower bound). For every tree tt on n≥2⋅7rn \ge 2\cdot 7^r keys, rounds (r+1) n2≤2 LFt(pairSequence)\mathit{rounds}\,(r + 1)\,n^2 \le 2\,\mathrm{LF}_t(\text{pairSequence}). The padded sequence of length mm satisfies the same bound with ⌊m/2n2⌋\lfloor m/2n^2 \rfloor in place of rounds\mathit{rounds}.

theoremLazyFinger.Separation.Results.lazy_lowerpropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:16
/-- Uniform lower bound for every fixed lazy-finger reference tree. -/theorem lazy_lower (t : Tree) (rounds r : Nat) (large : 2 * 7 ^ r ≤ t.size) :    rounds * (r + 1) * t.size * t.size ≤ 2 * cost t (pairSequence t.size rounds) :=  pairSequence_lower t rounds r large
theoremLazyFinger.Separation.Results.prescribed_lowerpropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:52
/-- Padding preserves the all-pairs lower bound in every static tree. -/theorem prescribed_lower (t : Tree) (m r : Nat) (large : 2 * 7 ^ r ≤ t.size) :    (m / (2 * t.size * t.size)) * (r + 1) * t.size * t.size ≤      2 * cost t (pairSequenceAtLength t.size m) := pairSequenceAtLength_lower t m r large

Since the sequence has m=2 rounds n2m = 2\,\mathit{rounds}\,n^2 requests, this is about 14log⁡7(n/2)\tfrac14 \log_7(n/2) per request, in every tree.

A dynamic BST pays a constant. Before the block of (x,y)(x, y), a dynamic BST reshapes its tree so that xx and yy both lie at depth at most one. A reshape costs at most 16n16n instructions. Then every request of the block costs a constant.

Theorem (dynamic upper bound). From every initial tree ss on nn keys there is a legal pointer-machine execution of pairSequence n rounds at cost at most n2(16n+6 rounds)n^2(16n + 6\,\mathit{rounds}). If rounds≥16n\mathit{rounds} \ge 16n, the cost is at most 7 rounds n27\,\mathit{rounds}\,n^2, which is 3.53.5 per request.

theoremLazyFinger.Separation.Results.dynamic_upperpropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:21
/-- A legal dynamic execution of the same sequence, paying explicitly toreshape between blocks and retaining every key. -/theorem dynamic_upper (s : Tree) (rounds : Nat) :    ∃ t k, t.size = s.size ∧ Pointer.Execution s (pairSequence s.size rounds) t k ∧      k ≤ s.size * s.size * (16 * s.size + 6 * rounds) := pairSequence_dynamic s rounds
theoremLazyFinger.Separation.Results.dynamic_linearpropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:27
/-- Long blocks make the dynamic execution linear in the number of requests. -/theorem dynamic_linear (s : Tree) (rounds : Nat) (long : 16 * s.size ≤ rounds) :    ∃ t k, t.size = s.size ∧ Pointer.Execution s (pairSequence s.size rounds) t k ∧      k ≤ 7 * rounds * s.size * s.size := pairSequence_dynamic_long s rounds long

Every reshape is a real sequence of pointer instructions, charged in full; nothing switches trees for free. The final tree t keeps all nn keys. For the padded sequence, the repeated key is served after one more reshape, and is charged as well:

theoremLazyFinger.Separation.Results.prescribed_dynamicpropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:57
/-- Both the repeated-key padding and its physical preparation are charged. -/theorem prescribed_dynamic (s : Tree) (m : Nat) (positive : 0 < s.size)    (long : 16 * s.size ≤ m / (2 * s.size * s.size)) :    ∃ t k, t.size = s.size ∧ Pointer.Execution s (pairSequenceAtLength s.size m) t k ∧      k ≤ 14 * (m / (2 * s.size * s.size)) * s.size * s.size :=  pairSequenceAtLength_dynamic s m positive long

The gap. Taking nn large enough that log⁡7n\log_7 n exceeds a multiple of CC, and long blocks, gives the separation. The quantifiers are those of the previous section. The optimal lazy-finger tree is chosen after the sequence is known, and the dynamic BST may start from any tree.

Theorem (strict separation). For every CC there is a universe n≥1n \ge 1 and a valid sequence of length at least nn such that from every initial tree on nn keys there is a legal execution of cost kk with Ck<LFn∗(X)C k < \mathrm{LF}^*_n(X). The same holds with Ck+a(n)<LFn∗(X)C k + a(n) < \mathrm{LF}^*_n(X) for any startup allowance aa.

theoremLazyFinger.Separation.Results.strictpropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:32
/-- Strict lazy-finger/dynamic separation (Theorem 6 of arXiv:1304.6897).The quantifiers allow the static optimum to choose its tree after seeing thesequence, and allow any prescribed dynamic initial tree. -/theorem strict (C : Nat) :    ∃ n xs, 0 < n ∧ n ≤ xs.length ∧ (∀ x ∈ xs, x < n) ∧      ∀ s : Tree, s.size = n → ∃ t k, Pointer.Execution s xs t k ∧ C * k < optimalCost n xs :=  lazy_dynamic_unbounded C
theoremLazyFinger.Separation.Results.with_startuppropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:40
/-- The gap survives every universe-dependent one-time initialization allowance. -/theorem with_startup (C : Nat) (allowance : Nat → Nat) :    ∃ n xs, 0 < n ∧ n ≤ xs.length ∧ (∀ x ∈ xs, x < n) ∧      ∀ s : Tree, s.size = n → ∃ t k, Pointer.Execution s xs t k ∧        C * k + allowance n < optimalCost n xs := lazy_dynamic_unbounded_with_startup C allowance

Theorem (every long length). For every CC and aa there are n≥1n \ge 1 and a threshold T≥nT \ge n such that every length m≥Tm \ge T has such a sequence of length exactly mm.

theoremLazyFinger.Separation.Results.all_lengthspropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:64
/-- The strict separation holds at every sufficiently large prescribed length,uniformly over dynamic initial trees and beyond any universe-dependent startup. -/theorem all_lengths (C : Nat) (allowance : Nat → Nat) :    ∃ n threshold, 0 < n ∧ n ≤ threshold ∧ ∀ m, threshold ≤ m →      ∃ xs, xs.length = m ∧ (∀ x ∈ xs, x < n) ∧        ∀ s : Tree, s.size = n → ∃ t k, Pointer.Execution s xs t k ∧          C * k + allowance n < optimalCost n xs := lazy_dynamic_all_lengths C allowance

Theorem (one family, Theorem 6). For every allowance aa there is a single family XmX_m of sequences, one of each length mm, on universes nm≥1n_m \ge 1, such that for every CC, eventually, every initial tree on nmn_m keys admits a legal execution of cost kk with Ck+a(nm)<LFnm∗(Xm)C k + a(n_m) < \mathrm{LF}^*_{n_m}(X_m).

theoremLazyFinger.Separation.Results.familypropext · Classical.choice · Quot.soundBounds/LazyFinger/Separation/Abstract.lean:72
/-- One family, fixed before the factor and initial tree are chosen, witnessesan unbounded lazy-finger/dynamic separation ratio as length grows. -/theorem family (allowance : Nat → Nat) :    ∃ sizes : Nat → Nat, ∃ requests : Nat → List Nat,      (∀ m, 0 < sizes m ∧ (requests m).length = m ∧        (∀ x ∈ requests m, x < sizes m)) ∧      ∀ C, ∃ threshold, ∀ m, threshold ≤ m →        ∀ s : Tree, s.size = sizes m → ∃ t k, Pointer.Execution s (requests m) t k ∧          C * k + allowance (sizes m) < optimalCost (sizes m) (requests m) :=  lazy_dynamic_family allowance

The family is built by the same diagonalization as in Section 16.3, from the witnesses pairSequenceAtLength n m of all_lengths.

What the sequence shows

Inside a block only two keys are in use, so almost every request has working-set number at most two. A dynamic BST exploits this. A static tree cannot, because over the whole sequence every pair is used and most pairs are far apart. Once the blocks are long (rounds≥16n\mathit{rounds} \ge 16n), the working-set bound of the sequence is O(m)O(m) while LF∗\mathrm{LF}^* is Ω(mlog⁡n)\Omega(m \log n). So, informally, the optimal lazy-finger tree does not have the working-set property, although it has the three properties of the next section. The library does not state this corollary.

16.6 Consequences for the optimal tree

The characterization of Chapter 15 compares LF∗\mathrm{LF}^* with the weighted dynamic-finger benchmark WeightedFinger.costFrom: one positive weight per key, and a charge of 1+log⁡2(w[xj−1,xj]/min⁡(wxj−1,wxj))1 + \log_2\bigl(w[x_{j-1}, x_j] / \min(w_{x_{j-1}}, w_{x_j})\bigr) per request, where w[x,y]w[x, y] is the total weight of the keys between xx and yy inclusive. Particular weightings give the classical bounds.

Unit weights give dynamic finger. With every weight equal to 11, the interval mass is ∣x−y∣+1|x - y| + 1 and the minimum weight is 11, so the charge is 1+log⁡2(∣xj−1−xj∣+1)1 + \log_2(|x_{j-1} - x_j| + 1). That is the dynamic-finger benchmark Bounds.dynamicFingerCostFrom, with the predecessor x0=px_0 = p of the first request given explicitly.

theoremLazyFinger.Consequences.Results.unit_weightspropext · Classical.choice · Quot.soundBounds/LazyFinger/Consequences/Abstract.lean:9
/-- The unit-weight benchmark is exactly the normalized dynamic-finger sum. -/theorem unit_weights (p : Nat) (xs : List Nat) :    WeightedFinger.costFrom (fun _ => 1) p xs = Bounds.dynamicFingerCostFrom p xs :=  unit_weight_cost p xs

Theorem (dynamic finger). Let p<np < n and let XX be valid. The optimal lazy-finger cost with the finger starting at pp is at most 44 times the dynamic-finger cost from pp. With the finger starting at the root, LFn∗(X)≤n+4 DFp(X)\mathrm{LF}^*_n(X) \le n + 4\,\mathrm{DF}_p(X), and if m≥nm \ge n then LFn∗(X)≤5 DFp(X)\mathrm{LF}^*_n(X) \le 5\,\mathrm{DF}_p(X).

theoremLazyFinger.Consequences.Results.dynamic_finger_frompropext · Classical.choice · Quot.soundBounds/LazyFinger/Consequences/Abstract.lean:14
/-- Dynamic finger with the same specified predecessor in both benchmarks. -/theorem dynamic_finger_from (n p : Nat) (xs : List Nat)    (hp : p < n) (valid : ∀ x ∈ xs, x < n) :    (optimalCostFrom n p xs : ℝ) ≤ 4 * Bounds.dynamicFingerCostFrom p xs :=  optimal_dynamic_finger_from n p xs hp valid
theoremLazyFinger.Consequences.Results.dynamic_fingerpropext · Classical.choice · Quot.soundBounds/LazyFinger/Consequences/Abstract.lean:20
/-- The selected static tree starts at its root; the dynamic-finger benchmarkstarts at `p`. The difference costs at most `n` once. -/theorem dynamic_finger (n p : Nat) (xs : List Nat)    (hp : p < n) (valid : ∀ x ∈ xs, x < n) :    (optimalCost n xs : ℝ) ≤ n + 4 * Bounds.dynamicFingerCostFrom p xs :=  optimal_dynamic_finger n p xs hp valid
theoremLazyFinger.Consequences.Results.dynamic_finger_longpropext · Classical.choice · Quot.soundBounds/LazyFinger/Consequences/Abstract.lean:27
theorem dynamic_finger_long (n p : Nat) (xs : List Nat)    (hp : p < n) (valid : ∀ x ∈ xs, x < n) (long : n ≤ xs.length) :    (optimalCost n xs : ℝ) ≤ 5 * Bounds.dynamicFingerCostFrom p xs :=  optimal_dynamic_finger_long n p xs hp valid long

The first bound uses the optimum with a specified start, LazyFinger.optimalCostFrom. The additive nn in the second pays once for moving the finger from the root to pp (Results.initialization). The factor 55 in the third absorbs it, since the dynamic-finger cost is at least m≥nm \ge n.

Theorem (static optimality). LFn∗(X)≤2(m+∑xqxlog⁡2(m/qx))\mathrm{LF}^*_n(X) \le 2\bigl(m + \sum_x q_x \log_2(m/q_x)\bigr).

theoremLazyFinger.Consequences.Results.static_optimalitypropext · Classical.choice · Quot.soundBounds/LazyFinger/Consequences/Abstract.lean:32
/-- The best lazy-finger tree satisfies the static-optimality entropy bound. -/theorem static_optimality (n : Nat) (xs : List Nat) (valid : ∀ x ∈ xs, x < n) :    (optimalCost n xs : ℝ) ≤ 2 * Bounds.staticCost n xs :=  optimal_static_entropy n xs valid

The proof takes a root-finger tree whose cost is at most the entropy bound Bounds.staticCost (Results.entropy_upper_bound), and applies the factor 2 of the hierarchy.

Theorem (static finger). For every ff, LFn∗(X)≤6∑j(1+log⁡2(∣xj−f∣+1))\mathrm{LF}^*_n(X) \le 6 \sum_j \bigl(1 + \log_2(|x_j - f| + 1)\bigr).

theoremLazyFinger.Consequences.Results.static_fingerpropext · Classical.choice · Quot.soundBounds/LazyFinger/Consequences/Abstract.lean:37
/-- Uniform static-finger bound, including fingers outside the key universe. -/theorem static_finger (n f : Nat) (xs : List Nat) (valid : ∀ x ∈ xs, x < n) :    (optimalCost n xs : ℝ) ≤ 6 * Bounds.fingerCost f xs :=  optimal_static_finger n f xs valid

The finger ff is any natural number, even one outside the key universe. The bound follows from static optimality, because the entropy bound is at most three times the static-finger bound Bounds.fingerCost (Chapter 14). Neither of these two bounds needs an additive term.

Theorem (all three at once, §1.4). For every valid XX there is a tree on nn keys that attains LFn∗(X)\mathrm{LF}^*_n(X) and satisfies the three bounds, the static-finger bound for every ff and the dynamic-finger bound for every p<np < n.

theoremLazyFinger.Consequences.Results.simultaneouspropext · Classical.choice · Quot.soundBounds/LazyFinger/Consequences/Abstract.lean:42
/-- The three consequences in §1.4 of arXiv:1304.6897 hold for one optimalstatic tree. The choice can depend on the sequence, but precedes quantificationover the fixed finger and predecessor. This is not an online tree-selection rule. -/theorem simultaneous (n : Nat) (xs : List Nat) (valid : ∀ x ∈ xs, x < n) :    ∃ t : Tree, t.size = n ∧ cost t xs = optimalCost n xs ∧      (cost t xs : ℝ) ≤ 2 * Bounds.staticCost n xs ∧      (∀ f, (cost t xs : ℝ) ≤ 6 * Bounds.fingerCost f xs) ∧      ∀ p, p < n → (cost t xs : ℝ) ≤ n + 4 * Bounds.dynamicFingerCostFrom p xs :=  optimal_three_bounds n xs valid
Reading the Lean

simultaneous adds nothing beyond the three separate bounds and the attainment of the optimum (Results.optimal_attained). Each bound is about the optimal value LFn∗(X)\mathrm{LF}^*_n(X), so any optimal tree satisfies all three. What the theorem makes explicit is the quantifier order: one tree, chosen from the sequence, serves every ff and every pp. It is not an online rule for choosing the tree.