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

Chapter 24 · Splay trees · Section 24.2The amortized analysis

A single splay can be slow: an access at depth n−1n-1 costs n−1n-1 rotations. Sleator and Tarjan’s insight is that such an access also roughly halves the depth of every node on its path, so expensive accesses pay for later cheap ones. They make this precise with a potential function and one lemma, the Access Lemma. A whole family of bounds then follows by choosing weights:

  • O(log⁡n)O(\log n) amortized cost per access (balance);
  • within a constant factor of the best static tree for the sequence (static optimality);
  • cheap accesses near any fixed key (static finger);
  • cheap accesses to recently used keys (working set).

These are the headline results of the 1985 paper, and all four hold for the same algorithm, which never sees the weights. This section proves them with explicit constants. In all four, tt is an arbitrary initial tree on nn keys, X=x1,…,xmX = x_1, \dots, x_m is a sequence of keys of tt, and RR is the number of rotations splaying performs while serving XX. The total cost m+Rm + R counts one unit per request plus one per rotation (Chapter 5).

Key result · Sleator and Tarjan 1985
Splaying costs O(log⁡n)O(\log n) amortized per access

Every splay is a legal root access by rotations, fewer than nn of them. Serving any sequence of mm requests by splaying, from any initial tree on nn keys, has total cost

m+R  ≤  m (2+3log⁡2n)+nlog⁡2n.m + R \;\le\; m\,(2 + 3\log_2 n) + n\log_2 n .

In Lean, correct certifies one splay as an Access, and balance bounds totalCost of Splay.algorithm, the online algorithm that splays each request in turn.

The Lean statements
theoremSplay.Results.correctpropext · Quot.soundAlgorithms/Splay/Abstract.lean:23
/-- Splay exposes exactly the requested rank using a legal rotation trace.Its rotation count is the depth of that rank, hence less than the number of nodes. -/theorem correct (t : Tree) (x : Nat) (valid : x < t.size) :    Access t (run t x).1 x (run t x).2 ∧ (run t x).2 < t.size := …  run_correct t x valid
theoremSplay.Results.balancepropext · Classical.choice · Quot.soundAlgorithms/Splay/Balance/Abstract.lean:10
/-- Balance theorem, including requests and the arbitrary initial shape. -/theorem balance (t : Tree) (xs : List Nat) (valid : ∀ x ∈ xs, x < t.size) :    (algorithm.totalCost t xs : ℝ) ≤      (xs.length : ℝ) * (2 + 3 * Real.logb 2 t.size) +      (t.size : ℝ) * Real.logb 2 t.size := …  Splay.balance t xs valid
15 definitions in 6 chapters · reading list
Key result · Sleator and Tarjan 1985
Splaying is statically optimal

Let key ii be requested qiq_i times. There are constants CC and DD such that for every initial tree on nn keys and every sequence of mm requests,

m+R  ≤  C(m+∑iqilog⁡2mqi)+D n (1+⌊log⁡2n⌋).m + R \;\le\; C\Bigl(m + \sum_i q_i \log_2 \frac{m}{q_i}\Bigr) + D\,n\,\bigl(1 + \lfloor\log_2 n\rfloor\bigr).

The sum ∑iqilog⁡2(m/qi)\sum_i q_i \log_2(m/q_i) is mm times the entropy of the access frequencies. The bracket is a lower bound for static trees: for every BST uu on the same nn keys, serving the sequence by plain searches in uu costs ∑j(1+depthu(xj))\sum_j \bigl(1 + \mathrm{depth}_u(x_j)\bigr), which is at least a third of the bracket. So splaying, which never learns the frequencies, costs at most 3C3C times as much as the best static tree for the sequence, plus a startup term.

In Lean, staticOptimality is the property HasStaticOptimalityBound of Splay.algorithm, and entropy_lower_bound is the comparison with every static tree, whose search cost is StaticTree.cost.

The Lean statements
19 definitions in 7 chapters · reading list
Key result · Sleator and Tarjan 1985
Splaying has the static finger property

There are constants CC and DD such that for every initial tree on nn keys, every fixed key f<nf < n (the finger) and every sequence of mm requests,

m+R  ≤  C∑j=1m(1+log⁡2(∣xj−f∣+1))+D n (1+⌊log⁡2n⌋).m + R \;\le\; C\sum_{j=1}^{m} \Bigl(1 + \log_2\bigl(|x_j - f| + 1\bigr)\Bigr) + D\,n\,\bigl(1 + \lfloor\log_2 n\rfloor\bigr).

Keys are ranks, so ∣xj−f∣|x_j - f| is the number of keys between the request and the finger. The finger is used only in the analysis: the algorithm is plain splaying.

In Lean, staticFinger is the property HasStaticFingerBound of Splay.algorithm; the sum is Bounds.fingerCost.

The Lean statement
17 definitions in 7 chapters · reading list
Key result · Sleator and Tarjan 1985
Splaying has the working-set property

For each request xjx_j, let wjw_j be one plus the number of distinct keys requested since the previous request to xjx_j, or nn if xjx_j was not requested before. For every initial tree on nn keys and every sequence of requests, the number of rotations is at most

R  ≤  10∑j(1+⌊log⁡2wj⌋)+6 n (1+⌊log⁡2n⌋).R \;\le\; 10\sum_{j} \bigl(1 + \lfloor\log_2 w_j\rfloor\bigr) + 6\,n\,\bigl(1 + \lfloor\log_2 n\rfloor\bigr).

A key that was used recently is cheap to access again, however large the tree. The sum charges at least 11 per request, so adding the mm requests changes only the constant.

In Lean, wjw_j is workingSetNumber and the sum is workingSetSum; Splay.algorithm.cost counts rotations only.

The Lean statement
theoremSplay.Results.workingSetpropext · Classical.choice · Quot.soundAlgorithms/Splay/WorkingSet/Abstract.lean:13
theorem workingSet (t : Tree) (xs : List Nat) (valid : ∀ x ∈ xs, x < t.size) :    algorithm.cost t xs ≤ 10 * workingSetSum t.size [] xs +      6 * t.size * (1 + t.size.log2) := …  Splay.workingSet_bound t xs valid
16 definitions in 7 chapters · reading list

24.2.1 Weights and potential

Sleator and Tarjan (1985) analyse splaying with a potential function. Each item ii gets a fixed positive weight w(i)w(i). The size s(x)s(x) of a node is the total weight of its subtree, its rank is r(x)=log⁡2s(x)r(x) = \log_2 s(x), and the potential of a tree is the sum of the ranks of its nodes. The Access Lemma bounds the amortized cost of one splay. Their Theorems 1–5 then follow by choosing the weights. The rest of this section shows the formal versions of the potential, the lemma and the five theorems. The bounds themselves (working set, entropy, finger) are defined in Chapter 14.

defSplay.masspropext · Classical.choice · Quot.soundAlgorithms/Splay/Potential/Abstract.lean:10
/-- Positive analysis weights are indexed by implicit inorder rank. -/def mass (w : Nat → ℝ) : Tree → Nat → ℝ  | .nil, _ => 0  | .node l r, lo => mass w l lo + w (lo + l.size) + mass w r (lo + l.size + 1)
defSplay.potentialpropext · Classical.choice · Quot.soundAlgorithms/Splay/Potential/Abstract.lean:15
/-- Sum of the binary logarithms of all nonempty subtree masses. -/noncomputable def potential (w : Nat → ℝ) : Tree → Nat → ℝ  | .nil, _ => 0  | .node l r, lo => potential w l lo + potential w r (lo + l.size + 1) +      Real.logb 2 (mass w (.node l r) lo)

The weights are a function w : Nat → ℝ on ranks. Because a subtree does not know its own keys, both functions carry the offset lo of the subtree’s smallest key and update it exactly as labelFrom does (Chapter 1). The root of node l r is rank lo + l.size, so mass adds w (lo + l.size) between the masses of the two subtrees. mass w t 0 is the total weight WW of the tree. mass is the paper’s ss, and potential is Φ=∑xlog⁡2s(x)\Phi = \sum_x \log_2 s(x), summed over nonempty subtrees only, so nil contributes neither weight nor a log⁡0\log 0 term.

Reading the Lean
  • potential is noncomputable only because of Real.logb. Nothing in it is chosen classically.
  • The weights are ghost data. Splay.run takes no weight argument, and every theorem below quantifies over weights only in its analysis, so the same algorithm satisfies all of them simultaneously.
  • The mass of a subtree depends only on the interval of keys it holds, not on its shape. Rotations therefore preserve the total weight WW and change only the masses of the rotated nodes. The library proves this as mass_eq_sum.
  • With unit weights fun _ => 1, mass is Tree.size and Φ\Phi is ∑log⁡2(subtree size)\sum \log_2(\text{subtree size}).

24.2.2 The access lemma

Theorem (access lemma). Fix positive weights ww. Let tt be a tree of total weight WW, and let splaying the rank x<∣t∣x < |t| take kk rotations and produce t′t'. Then the amortized cost is bounded:

k+Φ(t′)−Φ(t)  ≤  3(log⁡2W−log⁡2s(x))+1, k + \Phi(t') - \Phi(t) \;\le\; 3\bigl(\log_2 W - \log_2 s(x)\bigr) + 1 ,

where s(x)s(x) is the initial weight of xx’s subtree. Since s(x)≥w(x)s(x) \ge w(x), the same holds with s(x)s(x) replaced by w(x)w(x).

theoremSplay.Results.access_lemmapropext · Classical.choice · Quot.soundAlgorithms/Splay/AccessLemma/Abstract.lean:12
/-- Weighted access lemma, using the accessed node's own weight. -/theorem access_lemma (w : Nat → ℝ) (positive : ∀ i, 0 < w i)    (t : Tree) (x : Nat) (valid : x < t.size) :    ((run t x).2 : ℝ) + potential w (run t x).1 0 - potential w t 0 ≤      3 * (Real.logb 2 (mass w t 0) - Real.logb 2 (w x)) + 1 :=  Splay.access_lemma w positive t x valid
theoremSplay.Results.access_lemma_subtreepropext · Classical.choice · Quot.soundAlgorithms/Splay/AccessLemma/Abstract.lean:19
/-- Stronger original form: the denominator is the initial subtree mass of the accessed node, not merely its own weight. -/theorem access_lemma_subtree (w : Nat → ℝ) (positive : ∀ i, 0 < w i)    (t : Tree) (x : Nat) (valid : x < t.size) :    ((run t x).2 : ℝ) + potential w (run t x).1 0 - potential w t 0 ≤      3 * (Real.logb 2 (mass w t 0) -        Real.logb 2 (mass w (locate t x).focus (Pointer.offset (locate t x).context))) + 1 :=  Splay.access_lemma_subtree w positive t x valid

In Lean, WW is mass w t 0. access_lemma_subtree takes s(x)s(x) to be the initial mass of xx’s subtree. It writes that as mass w (locate t x).focus (offset (locate t x).context): the focus is the subtree rooted at xx, and the offset is the rank of its smallest key. This is exactly Lemma 1 of the paper, 3(r(t)−r(x))+13(r(t) - r(x)) + 1. access_lemma weakens s(x)s(x) to the weight w(x)w(x) of xx itself, which is the only form the theorems below need.

Reading the Lean
  • The hypothesis positive : ∀ i, 0 < w i asks for positive weights at every natural number, though only ranks below t.size affect the statement. This costs nothing, since any positive weights on the keys extend to all of Nat. Positivity is needed because Real.logb 2 0 = 0 in Mathlib: with a zero weight, −log⁡2w(x)-\log_2 w(x) would silently become 00.
  • The paper counts the time of a splay as its number of rotations, or 11 if there are none. Here kk is exactly the number of rotations, possibly 00. The additive 11 pays for a final zig.
  • Both Φ\Phi terms are evaluated with the same weights. Changing weights between accesses, as in the working-set proof, is a separate argument.

The proof is the paper’s. Three lemmas bound the amortized cost of the local steps: a zig costs at most 3(r′(x)−r(x))+13(r'(x) - r(x)) + 1, and a zig-zig or zig-zag at most 3(r′(x)−r(x))3(r'(x) - r(x)) (zig_left, zigzig_left, zigzag_left and their mirror images). A rotation inside the context leaves the mass of every strict ancestor unchanged, so it changes no other term of Φ\Phi. The induction follows splayAt, and the bounds telescope.

The figure below runs the same transcription of run as in Section 24.1 with unit weights. It tracks Φ\Phi, and at the end checks both inequalities on the actual run.

24.2.3 Balance (Theorem 1)

Theorem (balance). For every initial tree on nn keys and every sequence of mm valid requests, splaying has total cost m+R≤m (2+3log⁡2n)+nlog⁡2nm + R \le m\,(2 + 3\log_2 n) + n\log_2 n.

theoremSplay.Results.balancepropext · Classical.choice · Quot.soundAlgorithms/Splay/Balance/Abstract.lean:10
/-- Balance theorem, including requests and the arbitrary initial shape. -/theorem balance (t : Tree) (xs : List Nat) (valid : ∀ x ∈ xs, x < t.size) :    (algorithm.totalCost t xs : ℝ) ≤      (xs.length : ℝ) * (2 + 3 * Real.logb 2 t.size) +      (t.size : ℝ) * Real.logb 2 t.size :=  Splay.balance t xs valid

The paper’s Theorem 1 states O((m+n)log⁡n+m)O((m+n)\log n + m). The left side is totalCost, so the request count is included (Chapter 5). The logarithms are real, Real.logb 2 t.size, not floors. When n=0n = 0 both sides are 00, since a valid request sequence on the empty tree is empty.

The proof uses unit weights. Then W=nW = n and w(x)=1w(x) = 1, so each access has amortized rotation cost at most 1+3log⁡2n1 + 3\log_2 n. Every subtree has mass at least 11, so Φ≥0\Phi \ge 0, and initially Φ≤nlog⁡2n\Phi \le n \log_2 n. Summing over the sequence and adding mm gives the bound.

24.2.4 Static optimality (Theorem 2)

Theorem 2 of the paper states that if every item is accessed at least once, the total access time is O(m+∑iqilog⁡(m/qi))O(m + \sum_i q_i \log(m/q_i)), where qiq_i is the number of accesses to ii. The library has three versions.

Theorem (static optimality, every key requested). If every key of the initial tree is requested at least once, then m+R≤4(m+∑iqilog⁡2(m/qi))m + R \le 4\bigl(m + \sum_i q_i \log_2(m/q_i)\bigr).

This is the paper’s statement with explicit constants: T≤4⋅T \le 4 \cdot staticCost, which is 4 (m+∑iqilog⁡2(m/qi))4\,(m + \sum_i q_i \log_2(m/q_i)), with no startup term. The hypothesis covers : ∀ x < t.size, x ∈ xs is exactly “every item is accessed”. The proof takes w(i)=qiw(i) = q_i, so W=mW = m. The access lemma gives amortized cost 1+3log⁡2(m/qx)1 + 3\log_2(m/q_x). The potential drop over the whole sequence is at most ∑ilog⁡2(W/w(i))=∑ilog⁡2(m/qi)\sum_i \log_2(W/w(i)) = \sum_i \log_2(m/q_i), which is at most ∑iqilog⁡2(m/qi)\sum_i q_i\log_2(m/q_i) because every qi≥1q_i \ge 1. Adding mm for the requests gives T≤2m+4∑iqilog⁡2(m/qi)≤4⋅T \le 2m + 4\sum_i q_i\log_2(m/q_i) \le 4\cdotstaticCost.

Theorem (static optimality). There are constants CC and DD such that for every initial tree on nn keys and every valid sequence, m+R≤C(m+∑iqilog⁡2(m/qi))+D n (1+⌊log⁡2n⌋)m + R \le C\bigl(m + \sum_i q_i \log_2(m/q_i)\bigr) + D\,n\,(1 + \lfloor\log_2 n\rfloor).

Without covers, unused keys still sit in the tree, and some startup allowance is needed. HasStaticOptimalityBound (Chapter 14) has uniform but unspecified constants and an n(1+⌊log⁡2n⌋)n(1+\lfloor\log_2 n\rfloor) allowance. This theorem is not proved from the access lemma directly: it is the algorithm-independent implication “working set ⇒ static optimality” of Chapter 14, applied to splay's working-set bound.

Theorem (static optimality against a fixed tree). If every key is requested, then for every tree uu on the same nn keys, splaying from any initial tree has total cost m+R≤12∑j(1+depthu(xj))m + R \le 12 \sum_j \bigl(1 + \mathrm{depth}_u(x_j)\bigr).

theoremSplay.Results.staticOptimality_fixedTreepropext · Classical.choice · Quot.soundAlgorithms/Splay/StaticOptimality/Abstract.lean:21
/-- The paper's comparison-tree formulation, with no startup when every key occurs. -/theorem staticOptimality_fixedTree (t u : Tree) (xs : List Nat) (same : t.size = u.size)    (valid : ∀ x ∈ xs, x < t.size) (covers : ∀ x < t.size, x ∈ xs) :    (algorithm.totalCost t xs : ℝ) ≤ 12 * (StaticTree.cost u xs : ℝ) :=  Bridge.staticOptimality_fixedTree t u xs same valid covers

This is the comparison-tree reading of static optimality: splay, starting from any tree t, costs at most 1212 times what the best fixed BST u on the same keys would cost to serve xs by plain searches. StaticTree.cost counts one unit per request plus the depth of each requested key (Chapter 14). The constant is 12=4⋅312 = 4 \cdot 3: staticOptimality_all_accessed contributes the 44, and the prefix-code bound entropy_lower_bound, which says staticCost ≤ 3 · StaticTree.cost u xs for every tree u, contributes the 33.

Caveat

Both _all_accessed forms need covers. If some key is never requested, they say nothing. The general staticOptimality still applies, with an additive startup term and unspecified constants.

24.2.5 Static finger (Theorem 3)

Theorem (static finger). There are constants CC and DD such that for every initial tree on nn keys, every finger f<nf < n and every valid sequence, m+R≤C∑j(1+log⁡2(∣xj−f∣+1))+D n (1+⌊log⁡2n⌋)m + R \le C \sum_j \bigl(1 + \log_2(|x_j - f| + 1)\bigr) + D\,n\,(1 + \lfloor\log_2 n\rfloor). If every key is requested, then m+R≤12∑j(1+log⁡2(∣xj−f∣+1))m + R \le 12 \sum_j \bigl(1 + \log_2(|x_j - f| + 1)\bigr) for every natural number ff, with no startup term.

theoremSplay.Results.staticFingerpropext · Classical.choice · Quot.soundAlgorithms/Splay/StaticFinger/Abstract.lean:12
theorem staticFinger : HasStaticFingerBound algorithm :=  Splay.hasWorkingSetBound.staticFinger algorithm
theoremSplay.Results.staticFinger_all_accessedpropext · Classical.choice · Quot.soundAlgorithms/Splay/StaticFinger/Abstract.lean:15
/-- When every key occurs, the startup allowance can be omitted. -/theorem staticFinger_all_accessed (t : Tree) (xs : List Nat) (f : Nat)    (valid : ∀ x ∈ xs, x < t.size) (covers : ∀ x < t.size, x ∈ xs) :    (algorithm.totalCost t xs : ℝ) ≤ 12 * Bounds.fingerCost f xs :=  Bridge.staticFinger_all_accessed t xs f valid covers

Theorem 3 of the paper bounds the total time by O(nlog⁡n+m+∑jlog⁡(∣ij−f∣+1))O(n\log n + m + \sum_j \log(|i_j - f| + 1)) for any fixed item ff. fingerCost f xs is ∑j(1+log⁡2(∣xj−f∣+1))\sum_j \bigl(1 + \log_2(|x_j - f| + 1)\bigr). The distance is Nat.dist, the absolute difference of ranks, which matches the paper because its items are numbered in symmetric order. staticFinger is again the generic implication from working set (through static optimality). staticFinger_all_accessed removes the startup term when every key is accessed. Its constant 12=4⋅312 = 4 \cdot 3 comes from staticCost n xs ≤ 3 · fingerCost f xs (Bounds.static_le_finger), proved with the weights 1/(∣i−f∣+1)21/(|i-f|+1)^2, whose total is at most 44.

Reading the Lean

In staticFinger_all_accessed the finger f is an arbitrary natural number. There is no hypothesis f < t.size, so the statement is slightly stronger than the paper’s. HasStaticFingerBound quantifies only over f < t.size.

24.2.6 Working set (Theorem 4)

Theorem (working set). For every initial tree on nn keys and every valid sequence, R≤10∑j(1+⌊log⁡2wj⌋)+6 n (1+⌊log⁡2n⌋)R \le 10 \sum_j \bigl(1 + \lfloor\log_2 w_j\rfloor\bigr) + 6\,n\,(1 + \lfloor\log_2 n\rfloor), where wjw_j is the working-set number of request jj. In particular, splaying has the working-set property HasWorkingSetBound.

Theorem 4 of the paper bounds the total time by O(nlog⁡n+m+∑jlog⁡(t(j)+1))O(n\log n + m + \sum_j \log(t(j)+1)), where t(j)t(j) counts the distinct items accessed since the previous access to iji_j. The formal version bounds rotations: $R  ≤  10⋅workingSetSum+6 n (1+⌊log⁡2n⌋),R \;\le\; 10\cdot\texttt{workingSetSum} + 6\,n\,(1 + \lfloor\log_2 n\rfloor),$ where workingSetSum charges 1+⌊log⁡2workingSetNumber⌋1 + \lfloor\log_2 \texttt{workingSetNumber}\rfloor per request. The working-set number of a repeated access is the paper’s t(j)+1t(j) + 1. A first access is charged nn, which is at least the paper’s value; the total extra charge is O(nlog⁡n)O(n \log n), within the startup term (Chapter 14 gives the exact conventions). Because workingSetSum charges at least 11 per request, adding the mm requests costs at most one more unit per term. workingSet_totalCost_iff (Chapter 14) makes this precise for the property HasWorkingSetBound.

The proof follows the paper and changes the weights after every access. Before request jj, list the keys by recency: most recently accessed first, never-accessed keys after them in increasing order (Recency.recent). A key at 1-based position ρ\rho gets weight 1/ρ21/\rho^2 (Recency.weight). The total weight is at most 22 for every order, so the access lemma bounds the amortized cost of accessing the key at position ρ\rho by 3(1+2log⁡2ρ)+1≤10(1+⌊log⁡2ρ⌋)3(1 + 2\log_2\rho) + 1 \le 10(1 + \lfloor\log_2\rho\rfloor) (Recency.access_bound). After the access, xx moves to the front of the list. Its weight rises to 11, every other weight weakly falls, and the total is unchanged. Since xx is now the root, this cannot increase Φ\Phi (Recency.touch_potential). Finally ρ≤\rho \le workingSetNumber: they are equal on a repeated access, and ρ≤n\rho \le n on a first access. For any order, Φ\Phi lies between −2nlog⁡2(n+1)-2n\log_2(n+1) and nn, and this width is the 6n(1+⌊log⁡2n⌋)6n(1 + \lfloor\log_2 n\rfloor) term.

Theorem (working set on the pointer machine). For every initial tree and every valid sequence, there is a pointer-machine execution that ends in exactly the splayed tree and costs at most 31∑j(1+⌊log⁡2wj⌋)+18 n (1+⌊log⁡2n⌋)31 \sum_j \bigl(1 + \lfloor\log_2 w_j\rfloor\bigr) + 18\,n\,(1 + \lfloor\log_2 n\rfloor).

theoremSplay.Results.pointer_workingSetpropext · Classical.choice · Quot.soundAlgorithms/Splay/Abstract.lean:36
/-- Working set in the conventional pointer-and-rotation cost model. -/theorem pointer_workingSet (t : Tree) (xs : List Nat) (valid : ∀ x ∈ xs, x < t.size) :    ∃ k, k ≤ 31 * workingSetSum t.size [] xs + 18 * t.size * (1 + t.size.log2) ∧      Pointer.Execution t xs (algorithm.runFrom [] t xs).1 k :=  Bridge.pointer_workingSet t xs valid

The same bound in the conventional pointer model: the pointer implementation costs at most m+3Rm + 3R, and m≤m \le workingSetSum, so 31=3⋅10+131 = 3 \cdot 10 + 1 and 18=3⋅618 = 3 \cdot 6.

24.2.7 The unified theorem (Theorem 5)

Theorem 5 of the paper charges each access the smallest of its three logarithmic costs: frequency, finger distance and working set. The charge unifiedCharge and its sum unifiedSum are sequence functions, defined with the other benchmarks in Section 14.7. The frequencies there come from the whole sequence, but only the analysis sees them; the algorithm is still Splay.run.

Theorem (unified bound, fixed finger). For every initial tree on nn keys, every natural number ff and every valid sequence, m+R≤11∑jcj+8 n (1+⌊log⁡2n⌋)m + R \le 11 \sum_j c_j + 8\,n\,(1 + \lfloor\log_2 n\rfloor), where cjc_j is the smallest of the frequency, finger and working-set charges of request jj.

theoremSplay.Results.unifiedpropext · Classical.choice · Quot.soundAlgorithms/Splay/Unified/Abstract.lean:14
theorem unified (t : Tree) (xs : List Nat) (f : Nat)    (valid : ∀ x ∈ xs, x < t.size) :    (algorithm.totalCost t xs : ℝ) ≤ 11 * unifiedSum t.size f xs [] xs +      8 * (t.size : ℝ) * (1 + (t.size.log2 : ℝ)) :=  Splay.unified_bound t xs f valid

As for the static finger theorem, there is no f < t.size hypothesis. The minimum is taken per access, so this is not merely the minimum of the three earlier theorems. The proof uses the sum of three weights: the recency weight 1/ρ21/\rho^2, which changes after each access as in the working-set proof, plus two fixed weights, qi/mq_i/m and 1/(∣i−f∣+1)21/(|i - f| + 1)^2. The total weight is at most 7<237 < 2^3, so log⁡2W≤3\log_2 W \le 3. Each of the three weights is at most the combined weight, so the amortized cost of an access is at most 10⋅10\cdotunifiedCharge. Every charge is at least 11, which absorbs the mm requests into the constant 1111.

Not the dynamic unified bound

This is the 1985 fixed-finger unified theorem. It is not the later unified bound of Iacono (2001), in which the finger distance is measured to recently accessed keys. Whether splay trees satisfy that bound is open, and the library makes no claim about it.

24.2.8 Measured cost against the bounds

The figure runs the transcription of splay on a request sequence and plots its cumulative cost against the bound of a chosen theorem. Each point jj applies the theorem to the first jj requests from the same initial tree. For the static-optimality bound, the panel checks the covers hypothesis and says when it fails.

Constants versus behaviour

Switch to Balance with sequential scans. The measured cost stays far below m(2+3log⁡2n)m(2 + 3\log_2 n), because sequential access is linear (Section 24.3). Then try one key repeated under Working set: after the first access the key stays at the root, each request costs 00 rotations, and the bound grows by 1010 per request. The theorems give worst-case guarantees with generous constants, not estimates of typical cost.

Worst-case time per access

All the bounds of this section are amortized: a single access can cost Θ(n)\Theta(n) rotations. Chapter 30 builds one deamortized splay program that keeps the scanning, balance, working-set, static-optimality and static-finger bounds up to constant factors, and serves every access in O(log⁡n)O(\log n) time in the worst case.