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

Checking a result

You may not want to read the whole book. Perhaps you only want to know whether the library really proves that Tango trees are O(log⁡log⁡n)O(\log\log n)-competitive, or that arborally satisfied sets capture the cost of offline BST algorithms. This page is for that.

What there is to check

Lean checks every proof, so you never need to read one. What Lean cannot check is that a theorem says what you think it says. A statement can be technically true and still miss the point: the cost might be counted in the wrong place, or a definition might quietly assume what it should prove. To trust a result, you have to read its statement, every definition the statement mentions, every definition those mention, and so on down to standard Lean and Mathlib notions such as lists, natural numbers and log⁡2\log_2.

That set of definitions is usually small. The book computes it from the compiled library: it starts from the statement and follows definition types and bodies, but never proofs. For Tango trees, it is ten definitions: what a tree is, what a rotation, an access and an execution are, and what an online algorithm and its cost are. You do not need to know how Tango trees work.

Two refinements keep the list honest and short:

  • Skips. Sometimes a definition can be safely ignored. A decidability instance is an example: it only lets Lean compute a test, and any two instances for the same proposition agree, so it cannot change what a definition means. Each skip is listed on the reading list with its reason, so you can disagree.
  • Internal modules. If a statement used a definition from outside the reading interface, the book could not quote it, and the reading list would link it to the library source instead. No main result does at present.

The axioms behind each proof are listed in Appendix A. All of them are Lean’s three standard axioms.

How to use it

Every chapter or section that proves something opens with a box stating its main result, in English and in Lean. Results marked ★ are key results: the ones that the formalized papers announce in their abstracts or introductions. Select one or several results below, or tick the box in a chapter’s main-result box. To narrow the selection down to a single result, use its only this one button, or open the list of selected results in the bar at the bottom of the page. The selection then follows you through the book:

  • the sidebar shows, for each chapter or section, how many definitions you need from it;
  • on each page, those definitions are outlined and tagged needed;
  • a bar at the bottom of the page steps through them in reading order, and can dim everything else.

The reading list at the bottom of this page collects everything in one place.

The main results

  • Chapter 3 · 4 definitions in 2 chapters
    Statement

    Let ss and tt be binary trees with the same number nn of nodes. Then some sequence of at most 2n2n rotations turns ss into tt.

    In Lean, Geometry.reset concludes ∃ k ≤ 2 * s.size, Rotations s t k, where Rotations s t k says that exactly k rotations turn s into t.

  • Chapter 4 · 14 definitions in 4 chapters
    Statement

    Fix a list of nn keys.

    1. If the keys are strictly increasing (in any preordered type), then for every tree shape with nn nodes there is exactly one labelled tree with that shape whose inorder traversal is the list, and it satisfies the textbook search-tree invariant: at every node, all keys on the left are smaller and all keys on the right are larger.
    2. If the keys are distinct (no order needed), let ss and tt be labelled trees whose inorder traversals are the list, and let XX be a sequence of positions in the list. Then an execution serves the keys at positions XX from ss to tt with exactly kk rotations if and only if an execution serves the ranks XX from the shape of ss to the shape of tt with exactly kk rotations.

    In Lean, a labelled tree is a LabelledTree, its shape is erase, the invariant is LabelledTree.Ordered, and the two kinds of execution are Execution and LabelledTree.Execution.

  • Chapter 6 · 18 definitions in 5 chapters
    Statement

    Every execution of the rotation model that serves mm requests with RR rotations is also an execution of the dictionary model, serving the same requests as accesses and ending in the same tree, at main cost at most m+2Rm + 2R. In the other direction, searching a tree without changing it is a dictionary execution whose cost is the static search cost ∑j(1+depth(xj))\sum_j (1 + \mathrm{depth}(x_j)).

    In Lean, the executions are Execution and Dictionary.Execution, and trees without data become trees with unit data by Tree.unit.

  • Chapter 7 · 16 definitions in 4 chapters
    Statement

    Total cost means requests plus rotations (m+Rm + R) in the rotation model, and requests plus pointer instructions (KK) on the pointer machine. Let XX be a sequence of mm requests and ss a tree.

    1. Pointers to rotations. If the pointer machine serves XX from ss at total cost KK, ending in tree tt, then some root-access execution serves XX from ss with RR rotations and ends qq rotations away from tt, where m+R+q≤3Km + R + q \le 3K.
    2. Rotations to pointers. If a root-access execution serves XX from ss with RR rotations, ending in tree tt, then the pointer machine serves XX from ss at total cost KK, ending dd rotations away from tt, where K+32d≤32R+17mK + 32d \le 32R + 17m.

    The constants do not depend on the size of the tree. In both directions the final trees may differ, by a number of rotations that the bound pays for.

    In Lean, rotation-model executions are Execution, pointer executions are Pointer.Execution, and Rotations u t q says that q rotations turn u into t.

  • Chapter 12 · Demaine et al. 2009 · 13 definitions in 4 chapters
    Statement

    Fix nn keys and a sequence X=x0,…,xm−1X = x_0, \dots, x_{m-1} of requests. A geometric solution for XX is a finite set of points (key,time)(\text{key}, \text{time}), with keys below nn and times below mm, that contains every request point (xj,j)(x_j, j) and is arborally satisfied: any two of its points that share neither a key nor a time span a closed rectangle containing a third point of the set. Its cost is its number of points.

    1. Trees to points. If some tree on nn keys serves XX by root accesses with RR rotations in total, then XX has a geometric solution with at most 2R+m2R + m points.
    2. Points to trees. If XX has a geometric solution with ∣E∣|E| points, then from every initial tree on nn keys some sequence of root accesses serves XX with RR rotations, where m+R≤2n+99 ∣E∣m + R \le 2n + 99\,|E|.

    So, with OPTASS\mathrm{OPT}_{\mathrm{ASS}} the size of a smallest geometric solution and OPT\mathrm{OPT} the least total cost m+Rm + R of an execution from a given initial tree,

    12 OPTASS  ≤  OPT  ≤  99 OPTASS+2n.\tfrac12\,\mathrm{OPT}_{\mathrm{ASS}} \;\le\; \mathrm{OPT} \;\le\; 99\,\mathrm{OPT}_{\mathrm{ASS}} + 2n.

    In Lean, a root-access execution is an Execution (with its rotation count) and a geometric solution is a Geometric.Offline n xs, whose points field is the point set.

  • Chapter 13 · 25 definitions in 5 chapters
    Statement

    Fix a real-world machine pp. If pp runs from state ss to state tt in TT steps, with kk of them moves or rotations, then those kk instructions form a trace of the single-cursor machine of Chapter 7 from the tree and cursor of ss to those of tt, with the node data forgotten, and k≤Tk \le T. The machine receives one request at a time, and two executions of the same requests from the same state end in the same state with the same costs.

    In Lean, machines are RealWorld.Machine, their states RealWorld.State, runs RealWorld.Run, and traces Pointer.Trace.

  • Chapter 13 · 69 definitions in 5 chapters
    Statement

    Store the tree in records with three links (left, right, parent), the key and the node’s data words. Every move and rotation of the finger is then a fixed program of at most 19 pointer-machine instructions, which keeps the whole representation and allocates nothing. A real-world machine with ll instructions compiles to one pointer-machine program of 24l+424l + 4 instructions. Start the compiled program from a state that stores the source state, a relation that requires a nonempty tree, and let the word width be at least one bit. If the machine serves mm requests in TT steps in total, the compiled program responds to the same requests in at most 19T+3m19T + 3m instructions, ends in a state that stores the source’s final state, and keeps the number of records.

    In Lean, the pointer machine is Cslib.PointerMachine from CSLib Frontier, the representation is Linked.Realizes, the relation between the two machines is Compiler.Image, and the compiler is Compiler.compile.

  • Chapter 14 · Sleator and Tarjan 1985; Iacono 2001 · 18 definitions in 5 chapters
    Statement

    Let AA be any online BST algorithm. Suppose there are constants C,DC, D such that, from every initial tree on nn keys and for every sequence XX of mm valid requests, AA performs at most C∑j(1+⌊log⁡2wj⌋)+D n(1+⌊log⁡2n⌋)C \sum_j \bigl(1 + \lfloor\log_2 w_j\rfloor\bigr) + D\,n(1 + \lfloor\log_2 n\rfloor) rotations, where the working-set number wjw_j is one plus the number of distinct keys requested since the previous request for xjx_j, or nn if xjx_j has not been requested before (the working-set bound). Then, for new constants C′,D′C', D', the total cost of AA (rotations plus mm) is at most

    • C′(m+∑xqxlog⁡2(m/qx))+D′ n(1+⌊log⁡2n⌋)C' \bigl(m + \sum_x q_x \log_2(m/q_x)\bigr) + D'\,n(1 + \lfloor\log_2 n\rfloor), where qxq_x is the number of requests for xx (static optimality);
    • C′∑j(1+log⁡2(∣xj−f∣+1))+D′ n(1+⌊log⁡2n⌋)C' \sum_j \bigl(1 + \log_2(|x_j - f| + 1)\bigr) + D'\,n(1 + \lfloor\log_2 n\rfloor), for every finger ff at once (static finger);
    • C′⋅costu(X)+D′ n(1+⌊log⁡2n⌋)C' \cdot \mathrm{cost}_u(X) + D'\,n(1 + \lfloor\log_2 n\rfloor), where costu(X)\mathrm{cost}_u(X) is the cost of serving XX in any fixed BST uu on the same keys, one unit per request plus the depth of the requested key.

    In Lean, the three bounds are the properties HasWorkingSetBound, HasStaticOptimalityBound and HasStaticFingerBound of an Algorithm, and the fixed-tree cost is StaticTree.cost. Nothing about any specific algorithm is involved.

  • Chapter 14 · Mehlhorn 1975 · 5 definitions in 2 chapters
    Statement

    For every binary search tree tt on nn keys and every sequence XX of mm requests to its keys, let qxq_x be the number of requests for xx. Serving XX in tt without restructuring, at one unit per request plus the depth of the requested key, costs at least a third of the entropy bound:

    m+∑xqxlog⁡2mqx  ≤  3 (m+∑jdeptht(xj)).m + \sum_x q_x \log_2 \frac{m}{q_x} \;\le\; 3\,\Bigl(m + \sum_j \mathrm{depth}_t(x_j)\Bigr).

    In Lean, the left side is Bounds.staticCost and the right side is StaticTree.cost.

  • Chapter 15 · Bose et al. 2016 · 12 definitions in 2 chapters
    Statement

    Let X=x1,…,xmX = x_1, \dots, x_m be requests to the keys {0,…,n−1}\{0, \dots, n-1\}, and let p<np < n be a starting key. Write dT(x,y)d_T(x, y) for the number of edges between xx and yy in a tree TT, and W(x,y)=∑k=min⁡(x,y)max⁡(x,y)wkW(x,y) = \sum_{k=\min(x,y)}^{\max(x,y)} w_k. Define, with x0=px_0 = p,

    LFp(X)=min⁡T∑i=1m(1+dT(xi−1,xi)),WDFp(X)=inf⁡w>0∑i=1m(1+log⁡2W(xi−1,xi)min⁡(wxi−1,wxi)),\mathrm{LF}_p(X) = \min_{T} \sum_{i=1}^m \bigl(1 + d_T(x_{i-1}, x_i)\bigr), \qquad \mathrm{WDF}_p(X) = \inf_{w > 0} \sum_{i=1}^m \Bigl(1 + \log_2 \frac{W(x_{i-1}, x_i)}{\min(w_{x_{i-1}}, w_{x_i})}\Bigr),

    the minimum over all binary search trees on the nn keys, and the infimum over all weightings that are positive on the nn keys. Let LF(X)\mathrm{LF}(X) be defined like LFp(X)\mathrm{LF}_p(X), except that the first search starts at the root of TT. Then

    WDFp(X)≤3 LFp(X),LFp(X)≤4 WDFp(X),\mathrm{WDF}_p(X) \le 3\,\mathrm{LF}_p(X), \qquad \mathrm{LF}_p(X) \le 4\,\mathrm{WDF}_p(X),

    and, for the root start, with an additive nn for the initial position,

    LF(X)+n≤4 (WDFp(X)+n),WDFp(X)+n≤4 (LF(X)+n).\mathrm{LF}(X) + n \le 4\,\bigl(\mathrm{WDF}_p(X) + n\bigr), \qquad \mathrm{WDF}_p(X) + n \le 4\,\bigl(\mathrm{LF}(X) + n\bigr).

    If m≥nm \ge n, the additive term is not needed: WDFp(X)≤6 LF(X)\mathrm{WDF}_p(X) \le 6\,\mathrm{LF}(X) and LF(X)≤5 WDFp(X)\mathrm{LF}(X) \le 5\,\mathrm{WDF}_p(X).

    Both costs charge one unit per request, and the minimum over trees is attained. In Lean, LFp\mathrm{LF}_p is LazyFinger.optimalCostFrom, LF\mathrm{LF} is LazyFinger.optimalCost, and WDFp\mathrm{WDF}_p is WeightedFinger.optimalCostFrom.

  • Chapter 15 · Bose et al. 2016 · 8 definitions in 2 chapters
    Statement

    With the notation of the previous box, write LFp(T,X)=∑i(1+dT(xi−1,xi))\mathrm{LF}_p(T, X) = \sum_i (1 + d_T(x_{i-1}, x_i)) for the lazy-finger cost of one tree TT from x0=px_0 = p, cw(x,y)=1+log⁡2(W(x,y)/min⁡(wx,wy))c_w(x, y) = 1 + \log_2\bigl(W(x,y) / \min(w_x, w_y)\bigr) for the weighted charge, and WDFp(w,X)=∑icw(xi−1,xi)\mathrm{WDF}_p(w, X) = \sum_i c_w(x_{i-1}, x_i).

    • Weights give a tree (Corollary 2). For every weighting ww positive on {0,…,n−1}\{0, \dots, n-1\}, every p<np < n and every sequence XX of keys less than nn, there is a tree TT on the nn keys with LFp(T,X)≤4 WDFp(w,X)\mathrm{LF}_p(T, X) \le 4\,\mathrm{WDF}_p(w, X). The tree may depend on ww and on XX.
    • Trees give weights (Lemma 3). For every tree TT there is one weighting ww, positive everywhere, such that 1+dT(x,y)≤cw(x,y)≤3+2 dT(x,y)1 + d_T(x, y) \le c_w(x, y) \le 3 + 2\,d_T(x, y) for all keys x,yx, y of TT, and hence, for every valid start pp and sequence XX, LFp(T,X)≤WDFp(w,X)≤3 LFp(T,X)\mathrm{LF}_p(T, X) \le \mathrm{WDF}_p(w, X) \le 3\,\mathrm{LF}_p(T, X).
    • The reverse comparison (Corollary 4) is the upper half: cw(x,y)≤3+2 dT(x,y)c_w(x,y) \le 3 + 2\,d_T(x,y) and WDFp(w,X)≤3 LFp(T,X)\mathrm{WDF}_p(w, X) \le 3\,\mathrm{LF}_p(T, X).

    In Lean, LFp(T,X)\mathrm{LF}_p(T, X) is LazyFinger.costFrom, cwc_w is WeightedFinger.charge and WDFp(w,X)\mathrm{WDF}_p(w, X) is WeightedFinger.costFrom.

  • Chapter 15 · Bose et al. 2016 · 7 definitions in 3 chapters
    Statement

    Let ww be positive on {0,…,n−1}\{0, \dots, n-1\}. Draw a random order of the keys by repeatedly choosing one of the remaining keys with probability proportional to its weight. There is an assignment of a tree TσT_\sigma on the nn keys to every order σ\sigma such that, for all keys x,y<nx, y < n,

    Eσ[ 1+dTσ(x,y) ]  ≤  4 (1+log⁡2W(x,y)min⁡(wx,wy)).\mathbb E_\sigma\bigl[\,1 + d_{T_\sigma}(x, y)\,\bigr] \;\le\; 4\,\Bigl(1 + \log_2 \frac{W(x,y)}{\min(w_x, w_y)}\Bigr).

    The assignment depends on ww and nn only, so one random tree serves every pair at once. This is Theorem 1 of the paper, which attributes it to Seidel and Aragon (1996); in the proof, TσT_\sigma is the treap whose priority order is σ\sigma. In Lean, the expectation is Random.average and the right side is 44 times WeightedFinger.charge.

  • Chapter 16 · Bose et al. 2016 · 18 definitions in 4 chapters
    Statement

    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.

  • Chapter 16 · Bose et al. 2016 · 10 definitions in 3 chapters
    Statement

    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.

  • Chapter 17 · Wilber 1989 · 11 definitions in 4 chapters
    Statement

    Let PP be any binary search tree on nn keys, and let IBP(X)\mathrm{IB}_P(X) be the total number of left/right alternations of the sequence XX at the nodes of PP (defined in Section 17.1). Every execution that serves X=x1,…,xmX = x_1, \dots, x_m by rotations, starting from any initial tree on nn keys and using rr rotations in total, satisfies

    IBP(X)  ≤  4r+2m.\mathrm{IB}_P(X) \;\le\; 4r + 2m.

    So the offline optimum costs at least IBP(X)/4−m/2\mathrm{IB}_P(X)/4 - m/2 rotations, for every choice of PP.

    In Lean, the execution is an Execution from Part I and IBP\mathrm{IB}_P is Wilber.interleave. The reference tree only needs the right size; it is unrelated to the trees the execution passes through.

  • Chapter 18 · Bose et al. 2016 · 24 definitions in 4 chapters
    Statement

    For a sequence X=x1,…,xmX = x_1, \dots, x_m on nn keys and a predecessor x0=px_0 = p, let HH be the empirical conditional entropy of xjx_j given xj−1x_{j-1}, in bits, and let the conditional benchmark be m(1+H)m(1 + H), one unit per request plus the information of the transitions.

    Lemma 7, for dynamic BSTs. For every constant CC and every startup allowance a:N→Na : \mathbb N \to \mathbb N there are n≥1n \ge 1, a key p<np < n and a sequence XX of m≥nm \ge n valid requests such that H=0H = 0, also when only the transitions inside XX are counted, so that m(1+H)=mm(1 + H) = m, and such that every legal pointer-machine execution serving XX, from any initial tree on nn keys, costs more than

    C⋅m(1+H)+a(n).C \cdot m(1 + H) + a(n).

    For lazy finger. Theorem 6 (Chapter 16) gives an execution of cost at most 16n+464 LFn∗(X)16n + 464\,\mathrm{LF}^*_n(X). Applying the lemma with 464 C464\,C and 464 a(n)+16n464\,a(n) + 16n then gives LFn∗(X)>C⋅m(1+H)+a(n)\mathrm{LF}^*_n(X) > C \cdot m(1+H) + a(n). So no bound of the form LF∗≤C m(1+H)+a(n)\mathrm{LF}^* \le C\,m(1 + H) + a(n) holds. This two-line combination is arithmetic on the two listed theorems; the library does not state it as a separate theorem.

  • Chapter 19 · 5 definitions in 3 chapters
    Statement

    The balanced tree on nn keys serves every sequence of mm searches at cost at most m(1+⌊log⁡2n⌋)m(1 + \lfloor\log_2 n\rfloor), counting one unit per search plus the depth of the requested key. Conversely, every tree on n≥1n \ge 1 keys has a key xx such that searching xx mm times costs at least m(1+⌊log⁡2n⌋)m(1 + \lfloor\log_2 n\rfloor).

    In Lean, the balanced tree is Tree.balanced and the cost is StaticTree.cost. The repeated sequence is List.replicate m x.

  • Chapter 19 · Knuth 1971; Yao 1980 · 16 definitions in 3 chapters
    Statement

    For every sequence XX of requests to nn keys, the dynamic program builds a tree on the nn keys whose search cost for XX is at most that of every other tree on the same keys. Knuth’s algorithm computes this optimal cost while examining at most 2n22n^2 candidate roots; the library proves that it returns the cost, not that a tree built from its root table is optimal.

    In Lean, the weights are the request counts Static.counts, the optimal tree and cost are Static.optTree and Static.optCost, and Knuth’s algorithm is Optimal.knuth, which returns the cost and the number of roots it examined.

  • Chapter 20 · Adel'son-Vel'skiĭ and Landis 1962; Guibas and Sedgewick 1978; Haeupler et al. 2015 · 11 definitions in 2 chapters
    Statement

    Let tt be a tree on nn keys whose nodes carry integer ranks, and count its height in nodes. If the ranks satisfy the AVL rule, the height is at most log⁡φ(n+1)≈1.44log⁡2(n+1)\log_\varphi(n + 1) \approx 1.44 \log_2(n + 1), where φ\varphi is the golden ratio. If they satisfy the red-black rule, or the WAVL rule, the height is at most 2log⁡2(n+1)2\log_2(n + 1).

    In Lean, ranked trees are RankBalanced.RankedTree, the rules are RankBalanced.Rule, and Valid rule t says that every node of t satisfies the rule. Heights are Tree.height of the underlying shape t.erase.

  • Chapter 20 · Haeupler et al. 2015 · 25 definitions in 4 chapters
    Statement

    Bottom-up insertion into a WAVL tree keeps the WAVL rule, keeps the AVL rule when the tree is an AVL tree, and makes at most two rotations. It is a step of the dictionary model whose cost is one plus the depth of the new leaf plus the rotations. Any mm insertions into the empty tree change at most 7m7m ranks in total, and leave a tree of height at most log⁡φ(m+1)\log_\varphi(m + 1).

    In Lean, insertion is RankBalanced.insert, which returns the tree, its number of rotations and its number of rank changes. The dictionary step is Dictionary.Step of Chapter 6, with rank changes as its data edits.

  • Chapter 21 · Nievergelt and Reingold 1973; Day 1976; Stout and Warren 1986 · 10 definitions in 4 chapters
    Statement

    If every child’s weight is at most β\beta times its parent’s, for some 0<β<10 < \beta < 1, then the height, in nodes, is at most log⁡1/β(n+1)\log_{1/\beta}(n + 1). Every tree on nn keys can be turned into the balanced tree on the same keys by at most 2n2n rotations.

    In Lean, the invariant is WeightBalanced.Balanced and rebuilding is WeightBalanced.rebuild, which returns the balanced tree Tree.balanced with a number of rotations; rebuild_rotations proves that this many rotations reach it.

  • Chapter 21 · Andersson 1989; Galperin and Rivest 1993 · 31 definitions in 5 chapters
    Statement

    Fix a rational 12<α<1\frac12 < \alpha < 1. Start from the empty tree, and run any valid sequence of accesses, insertions and deletions with the scapegoat algorithm. The run is an execution of the dictionary model. At every point, every key lies at depth at most log⁡1/αn+1\log_{1/\alpha} n + 1. The total cost, rebuilding included, is at most ∑ib(ni)\sum_i b(n_i), where nin_i is the number of keys before the ii-th operation and b(n)=O(log⁡n)b(n) = O(\log n) is an explicit bound.

    In Lean, the algorithm is Scapegoat.run, the dictionary execution is Dictionary.Execution of Chapter 6, and the bound is Scapegoat.bound.

  • Chapter 22 · Hibbard 1962; Seidel and Aragon 1996 · 9 definitions in 3 chapters
    Statement

    Insert the keys 0,…,n−10, \dots, n - 1 into an empty binary search tree, without rebalancing, in a uniformly random order. Then key xx has expected depth exactly Hx+1+Hn−x−2H_{x+1} + H_{n-x} - 2, where Hk=1+12+⋯+1kH_k = 1 + \frac12 + \dots + \frac1k is the harmonic number, and this is at most 2ln⁡n2 \ln n. The tree built from an insertion order is the treap whose priorities are the positions in the order.

    In Lean, insertion is Random.insertKeys, the expectation over random orders is Random.average of Chapter 32 with uniform weights, and harmonic is Mathlib’s.

  • Chapter 23 · Allen and Munro 1978 · 6 definitions in 4 chapters
    Statement

    Let tt be any binary search tree on nn keys and xx any of its keys. Move-to-root returns a tree uu and a count kk such that kk rotations turn tt into uu, the key xx is the root of uu, and k<nk < n.

    In Lean, the algorithm is the function moveToRoot, which returns the pair (u,k)(u, k). The conclusion is Access from Chapter 3: a sequence of exactly kk rotations from tt to uu, with xx at the root of uu.

  • Section 24.1 · Sleator and Tarjan 1985 · 10 definitions in 5 chapters
    Statement

    For every binary search tree tt on nn keys and every key xx of tt, splaying xx is a root access: a sequence of legal rotations that ends with xx at the root. The number of rotations is exactly the count the algorithm reports, and it is less than nn.

    In Lean, the algorithm is Splay.run, which returns the new tree and its rotation count. correct concludes an Access, the certified notion of “bring xx to the root by rotations, at this cost” from Chapter 3.

  • Section 24.2 · Sleator and Tarjan 1985 · 15 definitions in 6 chapters
    Statement

    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.

  • Section 24.2 · Sleator and Tarjan 1985 · 19 definitions in 7 chapters
    Statement

    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.

  • Section 24.2 · Sleator and Tarjan 1985 · 17 definitions in 7 chapters
    Statement

    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.

  • Section 24.2 · Sleator and Tarjan 1985 · 16 definitions in 7 chapters
    Statement

    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.

  • Section 24.3 · Sleator and Tarjan 1985 · 15 definitions in 4 chapters
    Statement

    Consider any sequence of mm operations on a collection of splay trees (a forest). Each operation is an access, an insertion, a deletion, a split of one tree into two, or a join of two trees, and is charged one unit plus its rotations. Suppose the forest never holds more than NN keys, and initially holds ss keys. Then the total cost is at most

    m (5log⁡2(N+1)+3)+slog⁡2(s+1).m\,\bigl(5\log_2(N+1) + 3\bigr) + s\log_2(s+1).

    In Lean, the operations are Updates.split, Updates.join, Updates.insert and Updates.delete, built on Splay.run. A run of operations is an Updates.Execution made of Updates.Steps, and balance is the bound. Insertions and deletions name their position by rank; the search that finds that rank from a key is not modelled (Section 24.3.1).

  • Section 24.3 · Tarjan 1985 · 15 definitions in 6 chapters
    Statement

    For every initial tree on nn keys, accessing the keys 0,1,…,n−10, 1, \dots, n-1 in increasing order by splaying costs at most 14n14n in total, counting one unit per request plus one per rotation. The first access alone may take n−1n-1 rotations, so the bound is about the whole scan, not about each access.

    In Lean, the scan is List.range t.size, and scanning bounds totalCost of Splay.algorithm.

  • Section 25.1 · Demaine et al. 2009 · 9 definitions in 2 chapters
    Statement

    Let PP be an arborally satisfied set of points on keys {0,…,n−1}\{0,\dots,n-1\}, all at times before tt, and let r<nr < n be the request at time tt. Call a set of keys KK a legal row if r∈Kr \in K, every key of KK is less than nn, and PP together with the points K×{t}K \times \{t\} is still arborally satisfied. Then every legal row contains the sweep’s row, which is rr together with the keys of the old points visible from (r,t)(r, t). The sweep’s row is itself legal, so it is the unique legal row of minimum size.

    In Lean, greedy_required is the containment, and greedy_minimum says that a set of keys is a minimum-size legal row (Geometric.GreedyRow) exactly when it equals Geometric.greedySweep.

  • Section 25.2 · Demaine et al. 2009 · 16 definitions in 5 chapters
    Statement

    Fix an initial BST TT on nn keys and an online geometric algorithm AA on those keys: at each time, AA sees the request and the points added so far, and adds a row of points that contains the request and keeps the point set arborally satisfied. Then there is an online BST algorithm, chosen before any request is known, such that for every sequence XX of keys from {0,…,n−1}\{0,\dots,n-1\}, serving XX from TT takes at most

    6018 PA(X)+6016 n6018\,P_A(X) + 6016\,n

    rotations, where PA(X)P_A(X) is the number of points AA adds on XX. In particular, GreedyASS (Section 25.1) is an online BST algorithm whose cost is linear in its number of points.

    In Lean, AA is a Geometric.OnlineAlgorithm, its point count is Geometric.rowCost, and the BST algorithm is an Algorithm, whose cost counts rotations.

  • Section 25.3 · Iacono and Langerman 2016 · 24 definitions in 7 chapters
    Statement

    This is Theorem 4.1 of the paper. Let LF∗(X)\mathrm{LF}^*(X) be the least lazy-finger cost of XX over all BSTs on nn keys, where the first search starts at the root and each request costs one plus the number of edges walked from the previous request. Then

    PG(X)  ≤  120 LF∗(X)+15 n.P_G(X) \;\le\; 120\,\mathrm{LF}^*(X) + 15\,n .

    As a BST: there is a single online BST algorithm, depending only on nn, such that for every initial tree on nn keys and every XX, its total cost (rotations plus one per request) is at most

    722280 LF∗(X)+96303 n.722280\,\mathrm{LF}^*(X) + 96303\,n .

    In Lean, PG(X)P_G(X) is Geometric.rowCost greedySweep 0 ∅ X for the sweep Geometric.greedySweep, LF∗\mathrm{LF}^* is LazyFinger.optimalCost (a minimum, which is attained), and the BST algorithm is an Algorithm with cost Algorithm.totalCost. The second conjunct of bst also gives the weighted bound of the next box.

  • Section 25.3 · Iacono and Langerman 2016 · 19 definitions in 7 chapters
    Statement

    This is Theorem 4.2 of the paper. For positive weights w0,…,wn−1w_0, \dots, w_{n-1} and keys x,yx, y, let W[x,y]=∑min⁡(x,y)≤k≤max⁡(x,y)wkW[x, y] = \sum_{\min(x,y) \le k \le \max(x,y)} w_k, both endpoints included, and

    WFw(p,X)  =  ∑j=1m(1+log⁡2W[xj−1,xj]min⁡(wxj−1,wxj)),x0=p,\mathrm{WF}_w(p, X) \;=\; \sum_{j=1}^{m} \Bigl(1 + \log_2 \frac{W[x_{j-1}, x_j]}{\min(w_{x_{j-1}}, w_{x_j})}\Bigr), \qquad x_0 = p,

    where the start key p<np < n is arbitrary. Then for every such ww and pp,

    PG(X)  ≤  480 WFw(p,X)+15 n,P_G(X) \;\le\; 480\,\mathrm{WF}_w(p, X) + 15\,n,

    and the same holds with WFw(p,X)\mathrm{WF}_w(p, X) replaced by its infimum over all positive weightings. As a BST: there is a single online BST algorithm, depending only on nn, such that for every initial tree on nn keys, every p<np < n, every positive weighting ww and every XX, its total cost is at most

    2889120 WFw(p,X)+96303 n.2889120\,\mathrm{WF}_w(p, X) + 96303\,n .

    The weights appear only in the bound: neither GreedyASS nor the BST algorithm knows them. In Lean, WFw(p,X)\mathrm{WF}_w(p, X) is WeightedFinger.costFrom w p X and the infimum is WeightedFinger.optimalCostFrom, which need not be attained.

  • Section 25.3 · Iacono and Langerman 2016 · 16 definitions in 7 chapters
    Statement

    This is Corollary 1 of the paper, the case of unit weights. For every start key p<np < n, with x0=px_0 = p,

    PG(X)  ≤  480∑j=1m(1+log⁡2(∣xj−xj−1∣+1))+15 n.P_G(X) \;\le\; 480 \sum_{j=1}^{m} \Bigl(1 + \log_2\bigl(|x_j - x_{j-1}| + 1\bigr)\Bigr) + 15\,n .

    As a BST: there is a single online BST algorithm, depending only on nn, whose total cost from every initial tree on nn keys, for every p<np < n and every XX, is at most 28891202889120 times the same sum, plus 96303 n96303\,n.

    In Lean, the sum is Bounds.dynamicFingerCostFrom p X.

  • Section 25.5 · Iacono and Langerman 2016 · 25 definitions in 5 chapters, 4 more in internal modules
    Statement

    Let TT be a leaf-oriented reference tree whose ℓ\ell leaves are the keys lo,…,lo+ℓ−1lo, \dots, lo + \ell - 1, and run GreedyASS from the empty point set on a sequence of requests from that range. Before the row for the current request rr is added, call a component of the reference forest of rr old if, at some earlier time, GreedyASS touched one of its keys while it was a root, and it has remained a root at every search since then, up to and including rr. Call the other components virgin. Then the row GreedyASS adds for rr touches at most two old components.

    Give each virgin component 1212 units of potential. If the row touches kk components in all, at least k−2k - 2 of them are virgin, so the virgin potential drops from VV to some V′V' with

    V′+12 k  ≤  V+24.V' + 12\,k \;\le\; V + 24 .

    These are the paper’s Lemmas 3.7 and 3.8. The second is stated additively, so that it is meaningful when k<2k < 2.

  • Section 25.6 · Iacono and Langerman 2016 · 35 definitions in 9 chapters
    Statement

    Let TT be a leaf-oriented binary tree with LL leaves, labelled ℓ,ℓ+1,…,ℓ+L−1\ell, \ell+1, \dots, \ell+L-1 from left to right; its internal nodes carry no keys. For leaves x,yx, y let eT(x,y)e_T(x, y) be the number of edges on the path from xx to yy in TT. The reference cost of a sequence X=x1,…,xmX = x_1, \dots, x_m of leaves is

    RT(X)  =  m+∑i=2meT(xi−1,xi),R_T(X) \;=\; m + \sum_{i=2}^{m} e_T(x_{i-1}, x_i),

    one unit per request plus the edges a finger walks between consecutive requests. Equivalently, it is ∑i=2mdT(xi−1,xi)\sum_{i=2}^m d_T(x_{i-1},x_i) plus 11 for the first request, where dTd_T counts the nodes on the path, as in the paper. The finger starts at the first request for free, and no initial walk from the root is charged.

    Geometric form (Theorem 3.1). GreedyASS, run from the empty history on XX, adds at most

    24 RT(X)+15 L24\,R_T(X) + 15\,L

    points in total.

    BST form. For every nn there is one online BST algorithm, fixed before the initial tree, the reference tree and the requests are known, such that for every initial BST on nn keys, every leaf-oriented reference TT with leaves 0,…,n−10, \dots, n-1, and every sequence XX of keys less than nn, its total cost (rotations plus one per request) is at most

    144456 RT(X)+96303 n.144456\,R_T(X) + 96303\,n.

    Pointer form. For every nn there is one online BST algorithm whose run on the pointer machine of Chapter 7 is, under the same quantifiers, a legal pointer execution serving XX with at most 4622232 RT(X)+3081471 n4622232\,R_T(X) + 3081471\,n instructions.

    In Lean, RTR_T is Amortized.referenceCost and eTe_T is Transitions.edges. The reference tree is an ordinary Tree, read as leaf-oriented by Reference.leaves. The point count is Geometric.rowCost of Geometric.greedySweep, and the BST costs are Algorithm.totalCost and the cost of Online.run.

  • Section 26.1 · 12 definitions in 3 chapters
    Statement

    Fix a reference tree PP on nn keys and a sequence XX of requests. Serve XX one request at a time. After each request, every node on the search path to the requested key prefers the side of its subtree that holds that key: the left side if the key is the node itself or lies in its left subtree, the right side otherwise. Then:

    • if every request is a key of PP, the number of switches, where a node’s preference changes from one side to the other, is exactly Wilber’s interleave quantity IBP(X)\mathrm{IB}_P(X) of Chapter 17;
    • the number of settings, meaning switches plus the first time each node receives a preference, is at most IBP(X)+n\mathrm{IB}_P(X) + n.

    By Wilber’s bound, both are O(OPT+∣X∣)+nO(\mathrm{OPT} + |X|) + n, where OPT\mathrm{OPT} is the rotation count of the best offline execution.

  • Section 26.2 · Demaine et al. 2007 · 10 definitions in 4 chapters
    Statement

    For every nn there is an online BST algorithm, fixed before any request is known, with the following property. Start from any tree on nn keys and serve any sequence XX of keys from {0,…,n−1}\{0,\dots,n-1\}. Every request is a legal access by rotations, and the total cost (rotations plus one per request) is at most

    (56 L+16) (OPT+∣X∣)  +  (14 L+6) n,L=log⁡2(⌊log⁡2n⌋+1),\bigl(56\,L + 16\bigr)\,(\mathrm{OPT} + |X|) \;+\; \bigl(14\,L + 6\bigr)\,n, \qquad L = \log_2(\lfloor\log_2 n\rfloor + 1),

    where OPT\mathrm{OPT} is the number of rotations of any offline execution that serves XX from the same initial tree. So the algorithm is O(log⁡log⁡n)O(\log\log n)-competitive.

    In Lean, the algorithm is an Algorithm, the online algorithms of Chapter 5: a step function that sees only the past requests, the current tree and the new request, certified to perform a legal Access at the cost it reports. The cost is its totalCost, and the comparator is any Execution.

  • Section 26.3 · Demaine et al. 2007 · 90 definitions in 13 chapters, 35 more in internal modules
    Statement

    For every nn there is a Tango policy for the balanced reference tree on nn keys, fixed before any request is known, whose step applies each request’s preference updates bottom-up, with the following property. Let XX be any sequence of mm requests, and take any offline execution that serves XX with RR rotations from any tree on nn keys. Then the policy, run from its reference tree, serves XX with total cost (rotations plus one per request) at most

    42 n  +  (70 L+20) (R+m),L=log⁡2(⌊log⁡2n⌋+1).42\,n \;+\; \bigl(70\,L + 20\bigr)\,(R + m), \qquad L = \log_2(\lfloor\log_2 n\rfloor + 1).

    Compared with Section 26.2, the startup term (14L+4) n(14L+4)\,n of the policy becomes 42n42n, and the factor 56L+1656L+16 becomes 70L+2070L+20.

    A policy starts from its own reference tree. The second theorem turns any policy into an online algorithm in the sense of Chapter 5 that performs exactly the policy’s rotations when it starts from the reference tree. From any other tree of the same size it costs at most mm, plus the policy’s rotations, plus 2n2n. Combining the two gives an online BST, chosen before the initial tree and the requests, of total cost at most 44n+(70L+20)(R+m)44n + (70L+20)(R+m) from every initial tree on nn keys, against every offline execution from that tree. The library states this combination as one theorem, exists_competitive_linear.

    In Lean, the policy is a Tango.Policy whose step is BottomUp.serve, its cost is that of Policy.run, the comparator is any Execution, and the online algorithm is an Algorithm with cost Algorithm.totalCost.

  • Section 26.3 · 34 definitions in 8 chapters, 12 more in internal modules
    Statement

    Let PP be any reference tree of height hh, and serve a sequence XX of mm keys of PP with bottom-up preference updates, starting from the all-singleton marking. Each preference update gets an amortized charge from its actual position in the evolving auxiliary trees. The charges of all first settings together are at most

    ∑v∈P(8log⁡2h(v)+2)  +  m (14log⁡2h+4),\sum_{v \in P} \bigl(8\log_2 h(v) + 2\bigr) \;+\; m\,\bigl(14\log_2 h + 4\bigr),

    where h(v)h(v) is the height of vv’s subtree in PP. The first term is a one-time credit per node; the second is one ancestor-attachment charge per request. For the balanced reference tree on nn keys, the credit sum is at most 42n42n.

    In Lean, the first-setting charge is Initialization.firstLogCharge of the bottom-up log BottomUp.log, and the credit sum is Initialization.localAllowance.

  • Chapter 27 · Bose et al. 2016 · 36 definitions in 4 chapters
    Statement

    Let X=x1,…,xmX = x_1, \dots, x_m be a sequence of keys from {0,…,n−1}\{0, \dots, n-1\}. A static BST TT on these keys serves XX with a lazy finger at cost

    costT(X)  =  ∑j=1m(1+dT(xj−1,xj)),\mathrm{cost}_T(X) \;=\; \sum_{j=1}^{m} \bigl(1 + d_T(x_{j-1}, x_j)\bigr),

    where dT(x,y)d_T(x, y) is the number of edges on the path between xx and yy in TT, and x0x_0 is the root of TT: one unit per request, plus the edges the finger walks. There is an explicit algorithm that, given nn and XX, returns a tree T∗T^\ast with nn nodes such that

    costT∗(X)  =  min⁡T with n nodescostT(X),\mathrm{cost}_{T^\ast}(X) \;=\; \min_{T \text{ with } n \text{ nodes}} \mathrm{cost}_T(X),

    and whose work, counted in an explicit unit-cost RAM model, is at most 4m+64(n+1)34m + 64(n+1)^3. The bound holds for every nn, including n=0n = 0, with no hidden constants. The same holds when the first search starts from a specified key p<np < n instead of the root, that is, with x0=px_0 = p.

    In Lean, the algorithms are Work.tree n xs and Work.treeFrom n p xs, computations in the cost model Work.Computation: .ret is the returned tree and .time the counted work. The costs are LazyFinger.cost and LazyFinger.costFrom, and the optima LazyFinger.optimalCost and LazyFinger.optimalCostFrom, defined as infima over all shapes with nn nodes; the theorems show that the returned tree attains them. The work is the sum of the charges declared in the model’s program text, not a measurement of Lean’s own running time.

  • Chapter 28 · Bose et al. 2016 · 32 definitions in 6 chapters
    Statement

    Let n≥1n \ge 1 and 1≤c≤n1 \le c \le n. Let pp be a key and X=x1,…,xmX = x_1, \dots, x_m a sequence of keys, all in {0,…,n−1}\{0, \dots, n-1\}. Let FabF_{ab} be the number of indices jj with (xj−1,xj)=(a,b)(x_{j-1}, x_j) = (a, b), where x0=px_0 = p, let Ra=∑bFabR_a = \sum_b F_{ab}, and let

    I(X)  =  ∑a,b : Fab>0Fablog⁡2RaFabI(X) \;=\; \sum_{a,b \,:\, F_{ab} > 0} F_{ab} \log_2 \frac{R_a}{F_{ab}}

    be the empirical conditional information of XX, so that I=mHI = mH. The multiple-tree store built from FF with capacity cc uses at most 10nc10nc words, and serves XX, starting from pp, at total cost at most

    6 (m+I(X)) 1+log⁡2n1+log⁡2c.6\,\bigl(m + I(X)\bigr)\, \frac{1 + \log_2 n}{1 + \log_2 c}.

    Moreover, for every ε>0\varepsilon > 0 there is a capacity cc, depending only on nn and ε\varepsilon, such that for every pp and XX the store built from FF uses at most 20 n1+ε20\,n^{1+\varepsilon} words and serves XX at cost at most 6min⁡(ε,1) m (1+H)\frac{6}{\min(\varepsilon, 1)}\, m\,(1 + H).

    The cost is that of the linked-search model of Chapter 11: one unit per visited tree node and per pointer link followed. The store is built from the transition counts of the very sequence it serves, and the time to build it is not part of the bound; the counts themselves are not stored. In Lean, the execution is LinkedSearch.Execution, the space Store.words, the counts LazyFinger.frequency, m+Im + I is ConditionalEntropy.cost and HH is ConditionalEntropy.entropy.

  • Section 29.1 · Demaine et al. 2013 · 139 definitions in 12 chapters
    Statement

    This is the abstract BST-operation counterpart of Theorem 3 of the paper. Fix a nonempty initial tree SS with nn keys. Let A0A_0 and A1A_1 be two interruptible online algorithms starting from SS, each with a pointer-machine interpretation and a request-correctness contract, and let τ0\tau_0, τ1\tau_1 be nonnegative amortized charges, where τs(X,i)\tau_s(X, i) is the charge of the ii-th request of the whole sequence XX. Assume that both charges are well-behaved for their algorithms with a common overhead FF and constants C0,C1C_0, C_1, and that

    n≤F.n \le F.

    Then there is one online pointer policy, chosen before any request is known, such that for every sequence X=x0,…,xm−1X = x_0, \dots, x_{m-1} of keys in {0,…,n−1}\{0, \dots, n-1\} its run from SS is a legal pointer execution serving XX, and for every window 0≤lo≤hi≤m0 \le lo \le hi \le m the run splits exactly into the part before lolo, the window, and the part after hihi, with additive costs. The window part is a legal pointer execution of xlo,…,xhi−1x_{lo}, \dots, x_{hi-1} between the trees the run actually reaches, and its cost is at most

    8384 (C1+58)(2 C02min⁡(∑lo≤i<hiτ0(X,i), ∑lo≤i<hiτ1(X,i))+(2 C0C1+73) F).8384\,(C_1 + 58)\Bigl(2\,C_0^2 \min\Bigl(\sum_{lo \le i < hi} \tau_0(X, i),\ \sum_{lo \le i < hi} \tau_1(X, i)\Bigr) + (2\,C_0 C_1 + 73)\,F\Bigr).

    The charges in the bound are those of the original sequence, at the original indices, with its whole history: the window is not rerun from SS. Costs are pointer-machine costs, one per request plus one per instruction, so they include rotations and moves. Preparation of the saved snapshot is paid once, on the first request, and is absorbed in the overhead; the window lo=0lo = 0, hi=mhi = m is the whole run.

    In Lean, the algorithms are one Controller.Worker with a side bit, its interpretation is a Refinement.WorkerModel with Visits.Correct, well-behavedness is Analysis.WellBehaved, the window charge is Analysis.mass, the policy is an Online.Prepared run by Online.execute, and legality is Pointer.Execution.

  • Section 29.1 · Demaine et al. 2013 · 153 definitions in 12 chapters
    Statement

    The paper combines kk algorithms two at a time in a balanced binary tree (Section 1.2). Fix a nonempty initial tree SS with nn keys and a nonempty finite family A1,…,AkA_1, \dots, A_k of interruptible algorithms on SS, possibly with different state types, each with a pointer interpretation and request correctness, and each well-behaved for its own charge τj\tau_j, with common F≥nF \ge n, C0C_0 and C1C_1. Let d=⌈log⁡2k⌉d = \lceil \log_2 k \rceil. Then there is one online pointer policy such that for every valid sequence XX its run from SS is legal, its total cost is at most αmin⁡j∑iτj(X,i)+βF\alpha \min_j \sum_i \tau_j(X, i) + \beta F, and for every window [lo,hi)[lo, hi) the run splits additively as in the box above and the window costs at most

    α min⁡j∑lo≤i<hiτj(X,i)  +  β F,\alpha \, \min_{j} \sum_{lo \le i < hi} \tau_j(X, i) \;+\; \beta\, F,

    with α=8384 (C1+d+58)⋅2C02⋅Sd\alpha = 8384\,(C_1 + d + 58)\cdot 2C_0^2\cdot S_d and β=8384 (C1+d+58) (2C0(C1+d)+73)⋅Od\beta = 8384\,(C_1 + d + 58)\,(2C_0(C_1 + d) + 73)\cdot O_d. The scales start at S0=O0=1S_0 = O_0 = 1 and grow by one factor per level of the combination tree, Sj+1=33536 C0 (C1+j+58) SjS_{j+1} = 33536\,C_0\,(C_1 + j + 58)\,S_j and Oj+1=(33536 C0 (C1+j+58)+16768 (5(C1+j)+301)+1) OjO_{j+1} = \bigl(33536\,C_0\,(C_1 + j + 58) + 16768\,(5(C_1 + j) + 301) + 1\bigr)\,O_j. For fixed kk, C0C_0 and C1C_1 these are constants, as in the paper; they are not the paper’s sharper O(k)O(k).

    In Lean, the family is a function into Family.Algorithm, the scales are Family.chargeScale and Family.overheadScale, and the guarantee is Physical.Bounded.

  • Section 29.2 · Demaine et al. 2013 · 42 definitions in 11 chapters
    Statement

    Let A0,A1A_0, A_1 be two online algorithms of the rotation model (Chapter 5) and let TT be a tree on nn keys. There is one interruptible replay worker for the pair, fixed before any charges, overhead or constants are chosen, with the following property. Take any overhead f≥nf \ge n, any constants C0C_0 and C1≥20C_1 \ge 20, and any nonnegative charges τμ(X,i)\tau_\mu(X, i) (the charge of the ii-th request of XX on side μ\mu) such that, for every sequence XX of keys below nn,

    64⋅(∣X∣+rotAμ(T,X))  ≤  ∑i<∣X∣τμ(X,i)+f,64 \cdot \bigl(|X| + \mathrm{rot}_{A_\mu}(T, X)\bigr) \;\le\; \sum_{i<|X|} \tau_\mu(X, i) + f,

    and, for every contiguous segment X[lo,hi)X[lo, hi),

    ∑iτμ(X[lo,hi),i)+f  ≤  C0∑lo≤i<hiτμ(X,i)+C1f.\sum_{i} \tau_\mu\bigl(X[lo,hi), i\bigr) + f \;\le\; C_0 \sum_{lo \le i < hi} \tau_\mu(X, i) + C_1 f.

    Then the worker satisfies the operational well-behavedness contract Analysis.WellBehaved with these parameters. Every step of the worker is either one legal pointer instruction or local bookkeeping, and every valid request it completes from a reachable request boundary moves the cursor over the requested key (Visits.Correct for Replay.model).

    The cost on the left of the first inequality is Algorithm.totalCost: one unit per request plus rotations. The factor 6464 is the price of the translation to the pointer machine. The single-request bound of well-behavedness (C1fC_1 f per access from any reachable state) is not a hypothesis here: the worker caps every request at 20n20n units.

  • Section 29.4 · Demaine et al. 2013 · 139 definitions in 12 chapters
    Statement

    Let TT be a nonempty tree on nn keys, and let a worker present two source algorithms A0A_0 and A1A_1 on TT, with a causal pointer interpretation in which every access visits its key. Suppose both have well-behaved nonnegative amortized charges τ0,τ1\tau_0, \tau_1 with constants C0,C1C_0, C_1 and overhead F≥nF \ge n. Then there is one prepared online policy pp, fixed before any request is known, such that for every sequence XX of keys in {0,…,n−1}\{0,\dots,n-1\}, pp serves XX as a legal pointer-machine execution from TT, and its total cost, pointer instructions plus one unit per request, is at most

    524⋅1088 n  +  8384 (C1+58)(2C0min⁡(∑i<∣X∣τ0(X,i), ∑i<∣X∣τ1(X,i))+3F).524 \cdot 1088\, n \;+\; 8384\,(C_1 + 58)\Bigl(2C_0 \min\Bigl(\sum_{i<|X|} \tau_0(X,i),\ \sum_{i<|X|} \tau_1(X,i)\Bigr) + 3F\Bigr).

    In Lean, the worker is a Controller.Worker with a Refinement.WorkerModel satisfying Visits.Correct, the charges satisfy Analysis.WellBehaved, and the policy is a Online.Prepared run by Online.execute from the optional state none. The execution is a Pointer.Execution from T, in which every request starts at the root. The policy is chosen before the sequence (∃ p, ∀ xs), and the smaller of the two sums is chosen only in the proof.

  • Chapter 30 · Bose et al. 2012a · 30 definitions in 8 chapters
    Statement

    This is the abstract BST-operation counterpart of Theorem 6 of the paper. Let AA be any online BST algorithm in the rotation model, and TT any nonempty initial tree on nn keys. Then there is a single deamortized program, fixed from AA and TT before any request is known, made of two parts.

    1. Setup. A pointer-machine trace of at most 16n16n instructions turns TT, cursor at the root, into a tree T′′T'', cursor at the root.
    2. Responses. For every sequence X=x1,…,xmX = x_1, \dots, x_m of keys in {0,…,n−1}\{0, \dots, n-1\}, the program emits one stream of pointer instructions for a single persistent finger, starting at the root of T′′T''. The stream is cut into mm consecutive segments, one per request. During segment jj the finger stands on xjx_j at least once, and response jj costs cj=1+(length of segment j)c_j = 1 + (\text{length of segment } j). Every response is cheap, and the total is within a constant factor of AA:
    cj  <  251+195log⁡2nfor every j,∑j=1mcj  ≤  79360 (m+RA(X)),c_j \;<\; 251 + 195\log_2 n \quad\text{for every } j, \qquad \sum_{j=1}^m c_j \;\le\; 79360\,\bigl(m + R_A(X)\bigr),

    where RA(X)R_A(X) is the number of rotations AA performs on XX from TT. With the setup included, the total is at most 16n+79360 (m+RA(X))16n + 79360\,(m + R_A(X)), and any upper bound BB on m+RA(X)m + R_A(X) gives the total bound 16n+79360 B16n + 79360\,B.

    The program is online: if XX is a prefix of X′X', then the instruction stream and the list of response costs for XX are prefixes of those for X′X'.

    In Lean, AA is an Algorithm with cost Algorithm.totalCost, and the program is a Algorithm.Implementation. implementation_exists constructs one; its fields carry the setup, the correctness and cost guarantees, and causality. total_bound adds the setup, and transfer replaces m+RA(X)m + R_A(X) by any real upper bound.

  • Chapter 30 · Bose et al. 2012a · 40 definitions in 10 chapters
    Statement

    For every nonempty initial tree on nn keys there is a deamortized splay program as in the box above, with splaying as the source algorithm AA. Every response costs less than 251+195log⁡2n251 + 195\log_2 n. For every such program and every sequence XX of mm keys in {0,…,n−1}\{0, \dots, n-1\}, let T(X)T(X) be the setup cost plus the sum of the response costs. Then all of the following hold, for the same program and the same run:

    • Scanning. For X=0,1,…,n−1X = 0, 1, \dots, n-1: T(X)≤1111056 nT(X) \le 1111056\,n.
    • Balance. T(X)≤16n+79360 (m(2+3log⁡2n)+nlog⁡2n)T(X) \le 16n + 79360\,\bigl(m(2 + 3\log_2 n) + n\log_2 n\bigr).
    • Working set. T(X)≤16n+79360 (11∑j(1+⌊log⁡2wj⌋)+6n(1+⌊log⁡2n⌋))T(X) \le 16n + 79360\,\bigl(11\sum_j (1 + \lfloor\log_2 w_j\rfloor) + 6n(1 + \lfloor\log_2 n\rfloor)\bigr), where wjw_j is the working-set number of request jj.
    • Static optimality, if XX requests every key: T(X)≤16n+952320∑j(1+depthu(xj))T(X) \le 16n + 952320\sum_j \bigl(1 + \mathrm{depth}_u(x_j)\bigr) for every BST uu on the nn keys.
    • Static finger, if XX requests every key: T(X)≤16n+952320∑j(1+log⁡2(∣xj−f∣+1))T(X) \le 16n + 952320\sum_j \bigl(1 + \log_2(|x_j - f| + 1)\bigr) for every natural number ff.
    • Without the coverage hypothesis, there are constants CC and DD, the same for all nn, all programs and all sequences, such that T(X)≤16n+C(m+∑iqilog⁡2(m/qi))+D n(1+⌊log⁡2n⌋)T(X) \le 16n + C\bigl(m + \sum_i q_i\log_2(m/q_i)\bigr) + D\,n(1 + \lfloor\log_2 n\rfloor), where key ii is requested qiq_i times. Likewise, with constants of its own, T(X)≤16n+C∑j(1+log⁡2(∣xj−f∣+1))+D n(1+⌊log⁡2n⌋)T(X) \le 16n + C\sum_j \bigl(1 + \log_2(|x_j - f| + 1)\bigr) + D\,n(1 + \lfloor\log_2 n\rfloor) for every finger f<nf < n.

    In Lean, splaying is Splay.algorithm, T(X)T(X) is d.startup + out.costs.sum, and the bounds are workingSetSum, StaticTree.cost, Bounds.staticCost and Bounds.fingerCost of Chapter 14.

  • Chapter 31 · Iacono and Langerman 2016 · 32 definitions in 9 chapters
    Statement

    This is the abstract BST-operation counterpart of Theorem 4.3 of the paper, in a normalized form. Let saved be any nonempty initial tree on nn keys. There is one program, fixed before the requests, the start finger, the weights and the offline comparator are chosen, with the following properties.

    • Setup. Before the first request, a legal pointer trace of cost S≤16 nS \le 16\,n turns saved into the program’s prepared tree.
    • Serving. For every sequence X=x1,…,xmX = x_1, \dots, x_m of keys less than nn, the empty sequence included, the program’s instructions form a legal single-finger pointer execution from the prepared tree. They split into one contiguous segment per request, and the segment of xjx_j visits xjx_j. The response cost cjc_j is 11 plus the length of that segment, so ∑jcj=m+\sum_j c_j = m + {}(number of instructions).
    • Online. The instructions and response costs for x1,…,xjx_1, \dots, x_j do not depend on the later requests.
    • Worst case. Every response costs cj<251+195log⁡2nc_j < 251 + 195 \log_2 n.
    • Total. For every start key p<np < n, every initial tree on nn keys and every offline rotation-model execution that serves XX from it with RR rotations,
    S+∑j=1mcj  ≤  16 n+2480(1307904min⁡(184903680 WF∗(p,X),  8 ⌈64 (14 L+6)⌉ (m+R))+3839872⋅46225920 n),S + \sum_{j=1}^m c_j \;\le\; 16\,n + 2480\Bigl(1307904 \min\bigl(184903680\,\mathrm{WF}^*(p, X),\; 8\,\lceil 64\,(14\,L + 6)\rceil\,(m + R)\bigr) + 3839872 \cdot 46225920\, n\Bigr),

    where L=log⁡2(1+⌊log⁡2n⌋)L = \log_2(1 + \lfloor\log_2 n\rfloor). So the total cost is

    O(n+min⁡(WF∗(p,X),  (m+R)(1+log⁡2(1+⌊log⁡2n⌋)))).O\bigl(n + \min\bigl(\mathrm{WF}^*(p, X),\; (m + R)(1 + \log_2(1 + \lfloor\log_2 n\rfloor))\bigr)\bigr).

    Here WF∗(p,X)\mathrm{WF}^*(p, X) is WeightedFinger.optimalCostFrom, the infimum over all weightings positive on the keys of the weighted dynamic finger cost with x0=px_0 = p and one unit per request (Section 25.3). It is not assumed to be attained. The comparator is any Execution, so the bound holds in particular for the optimal one. The program is a Combination.Deamortized structure: its fields give the setup trace and the causality, and the theorem gives the rest.

  • Chapter 31 · Iacono and Langerman 2016 · 36 definitions in 10 chapters
    Statement

    The form of Theorem 4.3 for a single weighting. For every nonempty tree on nn keys there is a combined policy p and a deamortized program d for it. For every weighting ww positive on the keys, every p<np < n, and every rotation-model execution with RR rotations that serves XX from a tree on nn keys, if the program serves XX then its setup plus response costs is at most

    16 n+2480(1307904min⁡(184903680 WFw(p,X),  4 linearChargeFactor(balanced n) (m+R))+3839872⋅46225920 n).16\,n + 2480\Bigl(1307904 \min\bigl(184903680\,\mathrm{WF}_w(p, X),\; 4\,\mathtt{linearChargeFactor}(\mathtt{balanced}\ n)\,(m + R)\bigr) + 3839872 \cdot 46225920\, n\Bigr).

    The weights are chosen after the program, which never sees them.

  • Chapter 32 · Demaine et al. 2009 · 17 definitions in 4 chapters
    Statement

    For every nn, every request sequence X=x0,x1,…X = x_0, x_1, \dots and every number cc, the following are equivalent:

    • there is an arborally satisfied set of exactly cc points, with keys less than nn and times less than ∣X∣|X|, that contains the point (xi,i)(x_i, i) of every request;
    • some BST on nn keys can serve XX in the rooted-region model, touching exactly cc nodes in total.

    The initial tree is not fixed: the construction chooses it, and it needs the whole sequence in advance. In Lean, the point sets are Geometric.Offline solutions and the executions are RegionExecutions.

  • Chapter 33 · Demaine et al. 2009 · 21 definitions in 6 chapters
    Statement

    Let tt be a 2–3–4 tree of height hh with nn keys, stored as a BST in its standard binary representation.

    1. At most 3n3n rotations turn that BST into its finger view, a BST on the same nn keys whose right spine has at most 3h3h nodes.
    2. In the finger view, splaying the key of rank kk is a legal root access that uses at most 5⌊log⁡2(k+1)⌋+65\lfloor\log_2(k+1)\rfloor + 6 rotations.
    3. Separately: take any order of splits that eventually separates nn keys, and charge 1+⌊log⁡2(min⁡(a,b)+1)⌋1 + \lfloor\log_2(\min(a, b) + 1)\rfloor for splitting a group into sides of aa and bb keys. The total charge is at most 2n2n.

    In Lean, tt is a SplitTree.Multiway with Multiway.Balanced, its BST is Multiway.binary, the finger view is Finger.binaryView, and the order of splits is a binary tree read by SplitTree.totalCharge.

  • Chapter 34 · 9 definitions in 2 chapters
    Statement

    Let w0,…,wn−1w_0, \dots, w_{n-1} be natural-number weights with total WW. The tree built by recursive weighted-median splitting has the keys 0,…,n−10, \dots, n-1 in order, and every key xx satisfies 2depth(x) wx≤W2^{\mathrm{depth}(x)}\, w_x \le W, so depth(x)≤log⁡2(W/wx)\mathrm{depth}(x) \le \log_2(W / w_x) when wx>0w_x > 0. Building instead from the regularized weights n wx+W+1n\,w_x + W + 1 gives a tree in which every key with wx>0w_x > 0 satisfies both

    depth(x)  ≤  log⁡23Wwxanddepth(x)  ≤  log⁡2(2n).\mathrm{depth}(x) \;\le\; \log_2 \frac{3W}{w_x} \qquad\text{and}\qquad \mathrm{depth}(x) \;\le\; \log_2(2n).

    Depth counts edges from the root, as Tree.depth. The uniform bound 2depth(x)≤2n2^{\mathrm{depth}(x)} \le 2n holds for every key, including those of weight zero.

  • Section 37.1 · Bose et al. 2012a · 18 definitions in 3 chapters
    Statement

    A Vanilla pop-tart is a right spine whose left children are its weighted leaves, and whose last right child is the leaf of the initial empty stack. It is valid if the bottom leaf has nonnegative weight and every pushed leaf has weight at least the total weight of the leaves below it on the spine. Pushing a leaf of weight w≥Ww \ge W onto a valid stack of total weight WW gives a valid stack, and popping a valid stack gives a valid stack. Each push and pop is realized by a pointer trace of zero instructions, root to root, under any context. In a valid stack of total weight WW, a leaf of weight w>0w > 0 at depth dd satisfies

    d  ≤  1+log⁡2Ww.d \;\le\; 1 + \log_2 \frac{W}{w}.

    This is Lemma 1 of the paper, with its constant. Depth counts edges from the root, and the weights of internal nodes are not part of WW. A leaf may hold a whole subtree, frozen as one fringe slot of a PopTart.WeightedTree. The decreasing key order of pushes is built into the shape of the operations and is not a hypothesis.

  • Section 37.1 · Bose et al. 2012a · 36 definitions in 3 chapters
    Statement

    Start a Cherry pop-tart from the empty stack, and apply any sequence of nn pushes and pops of single leaves. Then every operation is realized by a pointer trace, root to root, and the total number of instructions is at most 10n10n. A stack with LL leaves has every leaf at depth at most 4log⁡2L4\log_2 L. Its next push costs at most 10log⁡2L10\log_2 L instructions, and its next pop at most 6log⁡2L6\log_2 L. In an ordinary pop-tart, whose leaves are empty, with nn nodes, every node has depth less than 4log⁡2(n+1)4\log_2(n+1). This is Lemma 2 of the paper, with explicit constants.

    Suppose in addition that the bottom leaf has nonnegative weight and that each pushed leaf weighs at least as much as every leaf currently in the stack. Then the leaves stay sorted by nonincreasing weight in inorder, the total cost is still at most 10n10n, and in the final stack of total weight WW every leaf of weight w>0w > 0 has depth

    d  ≤  3+4log⁡2Ww.d \;\le\; 3 + 4\log_2 \frac{W}{w}.

    This is Lemma 3 of the paper. The lemma is stated with O(⋅)O(\cdot); its proof ends with 4log⁡2(W/w)4\log_2(W/w), which drops an additive constant: the heaviest leaf is at depth 11, while log⁡2(W/w)\log_2(W/w) can be 00. The Lean bound adds 33 for the spine nodes. The costs are those of Program.cost, and empty_sequence and weighted_sequence write the cost bound as n+cost≤11nn + \text{cost} \le 11n, which is cost≤10n\text{cost} \le 10n.

  • Section 37.2 · Bose et al. 2012a · 43 definitions in 4 chapters
    Statement

    Start a Chocolate pop-tart from a single bottom slot of nonnegative weight. Run any sequence of nn operations, each either a push of one new fringe slot (an arbitrary payload subtree with an arbitrary nonnegative weight) or a pop, which is available whenever the stack holds at least two slots. Then:

    • Stack semantics. Every state is valid. A push prepends the new slot to the inorder sequence of weighted slots, and a pop exposes the first slot under a separator at the root and leaves the rest.
    • Local pointer operations. The rebalancing of each operation is a pointer-machine trace of exactly cost(op)\mathrm{cost}(op) moves and rotations, from the root of the stack back to its root, and it exists below any surrounding context: the stack may sit anywhere inside a larger tree.
    • Amortized cost. cost(op)+Φ′≤20+Φ\mathrm{cost}(op) + \Phi' \le 20 + \Phi for a potential Φ≥0\Phi \ge 0, and from the initial single slot, n+∑cost≤21 nn + \sum \mathrm{cost} \le 21\,n.
    • Worst-case cost. Each operation on a stack with NN fringe slots has 1+cost(op)≤7+14log⁡2N1 + \mathrm{cost}(op) \le 7 + 14\log_2 N.
    • Weighted depth. After the sequence, every slot of weight w>0w > 0 is at depth at most
    7+7log⁡2Ww,7 + 7\log_2 \frac{W}{w},

    where WW is the total weight of the slots.

    This is Lemma 4 of the paper. The paper’s depth bound is 6+7log⁡(W/w)6 + 7\log(W/w); the Lean constant is one larger. The cost of an operation counts only the rebalancing: placing the caller’s new separator on a push, and removing the exposed one on a pop, belong to the caller, which is why the bounds add 11 per operation. Weights live on the fringe slots only; separators weigh nothing. A slot of weight 00 is allowed but gets no depth bound.

  • Section 38.1 · Bose et al. 2012a · 57 definitions in 6 chapters, 2 more in internal modules
    Statement

    Let tt be a tree whose nodes carry weights, and let WW be its total weight. Each node has a solid edge to its heavier child (the left child on a tie); its other child edge is light.

    1. If all weights are nonnegative, every node xx with w(x)>0w(x) > 0 is reached from the root along a path with at most log⁡2(W/w(x))\log_2(W/w(x)) light edges.
    2. If all weights are positive and tt is nonempty, the solid path from the root ends at a leaf xx. Let ℓ\ell be its number of edges. Starting at the root, the pointer machine turns tt into a tree pp with xx at the root, a valid Chocolate pop-tart of the path’s nodes smaller than xx as its left subtree, and a mirrored one of the larger nodes as its right subtree. Each path node enters its pop-tart together with its off-path subtree, as one leaf of weight equal to the node’s weight plus the subtree’s. The cost of the trace plus the potential of the two pop-tarts is at most 24 ℓ24\,\ell, and w(x)+M=Ww(x) + M = W, where MM is the total leaf weight of pp. The rank at the root of pp is the rank of xx in tt.
    3. In every valid pair pp of leaf weight MM, a key inside a leaf of weight w>0w > 0 has depth at most
    8+7log⁡2(M/w)+d,8 + 7\log_2(M/w) + d,

    where dd is its depth inside the leaf’s subtree.

    Item 1 is path_exists with light_bound, item 2 is extract_build and item 3 is located_key_bound. Depths count edges, and ranks are inorder positions from 00.

  • Section 38.2 · Bose et al. 2012a · 61 definitions in 8 chapters, 2 more in internal modules
    Statement

    Let tt be a labelled tree with nn nodes and positive node weights ww, and let WW be its total weight. The canonical recursive representation rebuild w t is a tree shape with the same nn nodes. If tt is ordered, rebuild w t has exactly one ordered labelling with the inorder of tt, so it is a BST on the same keys. Whether or not tt is ordered, the node of inorder rank ii, whose label in tt is xix_i, lies at depth

    depth(i)  ≤  7+15log⁡2Ww(xi).\mathrm{depth}(i) \;\le\; 7 + 15\log_2\frac{W}{w(x_i)} .

    With unit weights this is 7+15log⁡2n7 + 15\log_2 n for every rank i<ni < n. The same bound holds in every history layout, that is, whatever valid stack shapes the pop-tarts of the representation have reached after pushes and pops. The pointer machine turns tt into rebuild w t in at most 16n16n instructions.

    This is the depth part of the paper’s Theorem 5, for a finger at the root, with explicit constants. Depth counts edges (Tree.depth), so the root has depth 00. In Lean, rebuild_labels gives the unique ordered labelling, rebuild_depth_at and rebuild_unit_depth are the two depth bounds, History.Results.layout_depth_at is the bound for an arbitrary history layout (History.Layout), and rebuild_initialization is the setup trace.

  • Section 38.3 · Bose et al. 2012a · 54 definitions in 9 chapters
    Statement

    Let tt be a labelled tree with nn nodes and a cursor at one of its nodes, the finger ff. The cursor’s path to the root is arbitrary; it need not be heavy. Give every node xx a weight w(x)>0w(x) > 0, and let WW be the total weight. Build the finger pair of this cursor with Finger.build. Then:

    1. Setup. Starting with the pointer at the root of tt, at most 16n16n pointer instructions turn tt into the pair’s tree, and end with the pointer at its root.
    2. Same keys. If tt is a BST, the pair’s tree carries exactly one labelling with the inorder of tt, and that labelling is a BST.
    3. Finger at the root. The root of the pair’s tree has the rank of ff in tt.
    4. Weighted depth. The node of tt at inorder rank ii, with weight wiw_i, has depth at most 15+15log⁡2(W/wi)15 + 15\log_2(W/w_i) in the pair’s tree.

    This is the depth claim of the paper’s Theorem 5 at a single moment, for a finger in general position, with explicit constants. The bound holds for the pair as built; that it survives the source’s operations is the subject of Section 38.4.

  • Section 38.4 · Bose et al. 2012a · 82 definitions in 10 chapters
    Statement

    Fix a weight w(a)w(a) for every label aa. There is a policy pp with the following properties. To answer one source instruction, pp sees only the current source cursor, the current physical representation and that instruction.

    Let the source finger point at a node of a labelled tree TT with nn nodes and positive weights. Let WW be the total weight, and let wiw_i be the weight of the ii-th label of TT in inorder. Then the physical tree, starting as TT itself with its cursor at the root, can be reshaped into a starting representation by a pointer-machine trace of cost s0s_0. The trace satisfies s0+Φ0≤39ns_0 + \Phi_0 \le 39n, where Φ0≥0\Phi_0 \ge 0 is the starting potential. Take any stream of mm source instructions that is legal from the source finger. Running pp instruction by instruction then succeeds and ends in a valid representation of the final source cursor, with the following guarantees:

    • the startup and the responses together form one pointer-machine trace from TT, of cost s0+Cs_0 + C with s0+C+Φ≤39n+62ms_0 + C + \Phi \le 39n + 62m, where Φ≥0\Phi \ge 0 is the final potential;
    • each source instruction is answered by at most 34+24log⁡2n34 + 24\log_2 n physical instructions, which start and end with the physical cursor at the root;
    • in every valid representation, between instructions, the physical root holds the source finger’s node, and the node of rank ii is at depth at most 15+15log⁡2(W/wi)15 + 15\log_2(W/w_i);
    • at every instruction boundary of the emitted physical program, even in the middle of a response, the node of rank ii is at depth at most
    336+240 log⁡2Wwi.336 + 240\,\log_2 \frac{W}{w_i}.

    In Lean, the per-instruction bound is part of Simulation.PolicyBounded, and Simulation.PolicyWithin extends it. Depths count edges (Tree.depth), and a rank is an inorder position. The policy is obtained by choice from the existence of a response for each step, so the theorem asserts that a function with these properties exists, not that it is computable. It depends on the weights, because the physical layout does.

  • Section 39.1 · Demaine et al. 2013 · 19 definitions in 5 chapters
    Statement

    Let TT be a tree with nn nodes, whose keys are the inorder ranks 0,…,n−10,\dots,n-1. A scan finger sits on any node, and the cells still to visit are either a suffix b,b+1,…,n−1b, b+1, \dots, n-1 in increasing order or a prefix b−1,…,1,0b-1, \dots, 1, 0 in decreasing order. A scan step either moves the finger one edge along a shortest path, in the current tree, toward the next pending cell, or visits that cell once the finger is on it. Both cost one unit. Arbitrary rotations of the tree, performed by someone else, may be interleaved between any two scan steps. If a trace contains rr such rotations, the scan’s work is

    moves+visits  ≤  4n+3r,\text{moves} + \text{visits} \;\le\; 4n + 3r,

    and the total including the rotations is at most 4n+4r4n + 4r. Any such partial trace can be completed, with no further rotations, so that every pending cell is visited and the whole scan still costs at most 4n+3r4n + 3r.

    This is the paper’s Lemma 9, with explicit constants. The bound holds for any start position of the finger and any boundary bb, in either direction.

  • Section 39.2 · Demaine et al. 2013 · 56 definitions in 8 chapters
    Statement

    Consider a tree with nn nodes and one data cell per node, indexed by inorder rank, as in the buffers of Section 39.1. Two fingers share the tree: a tree finger that moves and rotates, and a buffer finger that walks from cell to cell and reads or writes the cell under it.

    Save. Starting from a tree tt, with both fingers at the root and arbitrary initial cell contents, there is a save execution that ends with the same tree tt and the tree finger at its root, and that leaves in the cells the snapshot of tt: a fixed value below 2122^{12} in every cell, determined by tt (CellIO.Stored). It costs at most 72n72n. The cost counts every tree-finger instruction and every buffer-finger move, read and write.

    Load. Suppose the cells hold the snapshot of a tree ss, and the current tree has the same number nn of nodes, with both fingers at its root. Then there is a load execution that ends with the tree ss and the tree finger at its root, at cost at most 56n56n, counted in the same way. The load never writes a cell, and its steps depend only on the current tree and on the cell contents; ss appears only in the conclusion.

Select one or more results above to see what to read.