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 -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 .
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
Statement
Let and be binary trees with the same number of nodes. Then some sequence of at most rotations turns into .
In Lean,
Geometry.resetconcludes∃ k ≤ 2 * s.size, Rotations s t k, whereRotationss t ksays that exactlykrotations turnsintot.Statement
Fix a list of keys.
- If the keys are strictly increasing (in any preordered type), then for every tree shape with 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.
- If the keys are distinct (no order needed), let and be labelled trees whose inorder traversals are the list, and let be a sequence of positions in the list. Then an execution serves the keys at positions from to with exactly rotations if and only if an execution serves the ranks from the shape of to the shape of with exactly rotations.
In Lean, a labelled tree is a
LabelledTree, its shape iserase, the invariant isLabelledTree.Ordered, and the two kinds of execution areExecutionandLabelledTree.Execution.Statement
Every execution of the rotation model that serves requests with 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 . In the other direction, searching a tree without changing it is a dictionary execution whose cost is the static search cost .
In Lean, the executions are
ExecutionandDictionary.Execution, and trees without data become trees with unit data byTree.unit.Statement
Total cost means requests plus rotations () in the rotation model, and requests plus pointer instructions () on the pointer machine. Let be a sequence of requests and a tree.
- Pointers to rotations. If the pointer machine serves from at total cost , ending in tree , then some root-access execution serves from with rotations and ends rotations away from , where .
- Rotations to pointers. If a root-access execution serves from with rotations, ending in tree , then the pointer machine serves from at total cost , ending rotations away from , where .
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 arePointer.Execution, andRotationsu t qsays thatqrotations turnuintot.Statement
Fix keys and a sequence of requests. A geometric solution for is a finite set of points , with keys below and times below , that contains every request point 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.
- Trees to points. If some tree on keys serves by root accesses with rotations in total, then has a geometric solution with at most points.
- Points to trees. If has a geometric solution with points, then from every initial tree on keys some sequence of root accesses serves with rotations, where .
So, with the size of a smallest geometric solution and the least total cost of an execution from a given initial tree,
In Lean, a root-access execution is an
Execution(with its rotation count) and a geometric solution is aGeometric.Offlinen xs, whosepointsfield is the point set.Statement
Fix a real-world machine . If runs from state to state in steps, with of them moves or rotations, then those instructions form a trace of the single-cursor machine of Chapter 7 from the tree and cursor of to those of , with the node data forgotten, and . 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 statesRealWorld.State, runsRealWorld.Run, and tracesPointer.Trace.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 instructions compiles to one pointer-machine program of 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 requests in steps in total, the compiled program responds to the same requests in at most 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.PointerMachinefrom CSLib Frontier, the representation isLinked.Realizes, the relation between the two machines isCompiler.Image, and the compiler isCompiler.compile.Statement
Let be any online BST algorithm. Suppose there are constants such that, from every initial tree on keys and for every sequence of valid requests, performs at most rotations, where the working-set number is one plus the number of distinct keys requested since the previous request for , or if has not been requested before (the working-set bound). Then, for new constants , the total cost of (rotations plus ) is at most
- , where is the number of requests for (static optimality);
- , for every finger at once (static finger);
- , where is the cost of serving in any fixed BST on the same keys, one unit per request plus the depth of the requested key.
In Lean, the three bounds are the properties
HasWorkingSetBound,HasStaticOptimalityBoundandHasStaticFingerBoundof anAlgorithm, and the fixed-tree cost isStaticTree.cost. Nothing about any specific algorithm is involved.Statement
For every binary search tree on keys and every sequence of requests to its keys, let be the number of requests for . Serving in without restructuring, at one unit per request plus the depth of the requested key, costs at least a third of the entropy bound:
In Lean, the left side is
Bounds.staticCostand the right side isStaticTree.cost.Statement
Let be requests to the keys , and let be a starting key. Write for the number of edges between and in a tree , and . Define, with ,
the minimum over all binary search trees on the keys, and the infimum over all weightings that are positive on the keys. Let be defined like , except that the first search starts at the root of . Then
and, for the root start, with an additive for the initial position,
If , the additive term is not needed: and .
Both costs charge one unit per request, and the minimum over trees is attained. In Lean, is
LazyFinger.optimalCostFrom, isLazyFinger.optimalCost, and isWeightedFinger.optimalCostFrom.Statement
With the notation of the previous box, write for the lazy-finger cost of one tree from , for the weighted charge, and .
- Weights give a tree (Corollary 2). For every weighting positive on , every and every sequence of keys less than , there is a tree on the keys with . The tree may depend on and on .
- Trees give weights (Lemma 3). For every tree there is one weighting , positive everywhere, such that for all keys of , and hence, for every valid start and sequence , .
- The reverse comparison (Corollary 4) is the upper half: and .
In Lean, is
LazyFinger.costFrom, isWeightedFinger.chargeand isWeightedFinger.costFrom.Statement
Let be positive on . 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 on the keys to every order such that, for all keys ,
The assignment depends on and 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, is the treap whose priority order is . In Lean, the expectation is
Random.averageand the right side is timesWeightedFinger.charge.Statement
This is Theorem 6 of the paper. Let be a sequence of valid requests on keys.
- Lazy finger beats root finger up to a factor 2. For every tree on keys, .
- A dynamic BST follows lazy finger up to a constant factor. From every initial tree on keys there is a legal pointer-machine execution serving whose cost satisfies $$
- The first gap is unbounded. For every startup allowance there is a family of sequences , of length on keys, such that for every constant , once is large enough, $$
- The second gap is unbounded. For every there is a family on keys such that for every , once is large enough, every initial tree on keys admits a legal execution serving at a cost with $$
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 is chosen, so the ratios tend to infinity along one family: and , even after any one-time startup allowance.
Statement
This is the list of consequences in §1.4 of the paper. For every sequence of valid requests on keys there is a tree on keys whose lazy-finger cost, from the root, is the optimum , and this cost is at most
- , where counts the requests for (static optimality);
- , for every finger (static finger);
- with , for every key (dynamic finger).
The tree may depend on the sequence; it is chosen before and . The term pays once for starting the finger at the root rather than at .
Statement
Let be any binary search tree on keys, and let be the total number of left/right alternations of the sequence at the nodes of (defined in Section 17.1). Every execution that serves by rotations, starting from any initial tree on keys and using rotations in total, satisfies
So the offline optimum costs at least rotations, for every choice of .
In Lean, the execution is an
Executionfrom Part I and isWilber.interleave. The reference tree only needs the right size; it is unrelated to the trees the execution passes through.Statement
For a sequence on keys and a predecessor , let be the empirical conditional entropy of given , in bits, and let the conditional benchmark be , one unit per request plus the information of the transitions.
Lemma 7, for dynamic BSTs. For every constant and every startup allowance there are , a key and a sequence of valid requests such that , also when only the transitions inside are counted, so that , and such that every legal pointer-machine execution serving , from any initial tree on keys, costs more than
For lazy finger. Theorem 6 (Chapter 16) gives an execution of cost at most . Applying the lemma with and then gives . So no bound of the form holds. This two-line combination is arithmetic on the two listed theorems; the library does not state it as a separate theorem.
Statement
The balanced tree on keys serves every sequence of searches at cost at most , counting one unit per search plus the depth of the requested key. Conversely, every tree on keys has a key such that searching times costs at least .
In Lean, the balanced tree is
Tree.balancedand the cost isStaticTree.cost. The repeated sequence isList.replicate m x.Statement
For every sequence of requests to keys, the dynamic program builds a tree on the keys whose search cost for is at most that of every other tree on the same keys. Knuth’s algorithm computes this optimal cost while examining at most 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 areStatic.optTreeandStatic.optCost, and Knuth’s algorithm isOptimal.knuth, which returns the cost and the number of roots it examined.Statement
Let be a tree on keys whose nodes carry integer ranks, and count its height in nodes. If the ranks satisfy the AVL rule, the height is at most , where is the golden ratio. If they satisfy the red-black rule, or the WAVL rule, the height is at most .
In Lean, ranked trees are
RankBalanced.RankedTree, the rules areRankBalanced.Rule, andValid rule tsays that every node oftsatisfies the rule. Heights areTree.heightof the underlying shapet.erase.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 insertions into the empty tree change at most ranks in total, and leave a tree of height at most .
In Lean, insertion is
RankBalanced.insert, which returns the tree, its number of rotations and its number of rank changes. The dictionary step isDictionary.Stepof Chapter 6, with rank changes as its data edits.Statement
If every child’s weight is at most times its parent’s, for some , then the height, in nodes, is at most . Every tree on keys can be turned into the balanced tree on the same keys by at most rotations.
In Lean, the invariant is
WeightBalanced.Balancedand rebuilding isWeightBalanced.rebuild, which returns the balanced treeTree.balancedwith a number of rotations;rebuild_rotationsproves that this many rotations reach it.Statement
Fix a rational . 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 . The total cost, rebuilding included, is at most , where is the number of keys before the -th operation and is an explicit bound.
In Lean, the algorithm is
Scapegoat.run, the dictionary execution isDictionary.Executionof Chapter 6, and the bound isScapegoat.bound.Statement
Insert the keys into an empty binary search tree, without rebalancing, in a uniformly random order. Then key has expected depth exactly , where is the harmonic number, and this is at most . 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 isRandom.averageof Chapter 32 with uniform weights, andharmonicis Mathlib’s.Statement
Let be any binary search tree on keys and any of its keys. Move-to-root returns a tree and a count such that rotations turn into , the key is the root of , and .
In Lean, the algorithm is the function
moveToRoot, which returns the pair . The conclusion isAccessfrom Chapter 3: a sequence of exactly rotations from to , with at the root of .Statement
For every binary search tree on keys and every key of , splaying is a root access: a sequence of legal rotations that ends with at the root. The number of rotations is exactly the count the algorithm reports, and it is less than .
In Lean, the algorithm is
Splay.run, which returns the new tree and its rotation count.correctconcludes anAccess, the certified notion of “bring to the root by rotations, at this cost” from Chapter 3.Statement
Every splay is a legal root access by rotations, fewer than of them. Serving any sequence of requests by splaying, from any initial tree on keys, has total cost
In Lean,
correctcertifies one splay as anAccess, andbalanceboundstotalCostofSplay.algorithm, the online algorithm that splays each request in turn.Statement
Let key be requested times. There are constants and such that for every initial tree on keys and every sequence of requests,
The sum is times the entropy of the access frequencies. The bracket is a lower bound for static trees: for every BST on the same keys, serving the sequence by plain searches in costs , which is at least a third of the bracket. So splaying, which never learns the frequencies, costs at most times as much as the best static tree for the sequence, plus a startup term.
In Lean,
staticOptimalityis the propertyHasStaticOptimalityBoundofSplay.algorithm, andentropy_lower_boundis the comparison with every static tree, whose search cost isStaticTree.cost.Statement
There are constants and such that for every initial tree on keys, every fixed key (the finger) and every sequence of requests,
Keys are ranks, so 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,
staticFingeris the propertyHasStaticFingerBoundofSplay.algorithm; the sum isBounds.fingerCost.Statement
For each request , let be one plus the number of distinct keys requested since the previous request to , or if was not requested before. For every initial tree on keys and every sequence of requests, the number of rotations is at most
A key that was used recently is cheap to access again, however large the tree. The sum charges at least per request, so adding the requests changes only the constant.
In Lean, is
workingSetNumberand the sum isworkingSetSum;Splay.algorithm.costcounts rotations only.Statement
Consider any sequence of 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 keys, and initially holds keys. Then the total cost is at most
In Lean, the operations are
Updates.split,Updates.join,Updates.insertandUpdates.delete, built onSplay.run. A run of operations is anUpdates.Executionmade ofUpdates.Steps, andbalanceis 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).Statement
For every initial tree on keys, accessing the keys in increasing order by splaying costs at most in total, counting one unit per request plus one per rotation. The first access alone may take rotations, so the bound is about the whole scan, not about each access.
In Lean, the scan is
List.range t.size, andscanningboundstotalCostofSplay.algorithm.Statement
Let be an arborally satisfied set of points on keys , all at times before , and let be the request at time . Call a set of keys a legal row if , every key of is less than , and together with the points is still arborally satisfied. Then every legal row contains the sweep’s row, which is together with the keys of the old points visible from . The sweep’s row is itself legal, so it is the unique legal row of minimum size.
In Lean,
greedy_requiredis the containment, andgreedy_minimumsays that a set of keys is a minimum-size legal row (Geometric.GreedyRow) exactly when it equalsGeometric.greedySweep.Statement
Fix an initial BST on keys and an online geometric algorithm on those keys: at each time, 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 of keys from , serving from takes at most
rotations, where is the number of points adds on . In particular, GreedyASS (Section 25.1) is an online BST algorithm whose cost is linear in its number of points.
In Lean, is a
Geometric.OnlineAlgorithm, its point count isGeometric.rowCost, and the BST algorithm is anAlgorithm, whosecostcounts rotations.Statement
This is Theorem 4.1 of the paper. Let be the least lazy-finger cost of over all BSTs on 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
As a BST: there is a single online BST algorithm, depending only on , such that for every initial tree on keys and every , its total cost (rotations plus one per request) is at most
In Lean, is
Geometric.rowCostgreedySweep 0 ∅ Xfor the sweepGeometric.greedySweep, isLazyFinger.optimalCost(a minimum, which is attained), and the BST algorithm is anAlgorithmwith costAlgorithm.totalCost. The second conjunct ofbstalso gives the weighted bound of the next box.Statement
This is Theorem 4.2 of the paper. For positive weights and keys , let , both endpoints included, and
where the start key is arbitrary. Then for every such and ,
and the same holds with replaced by its infimum over all positive weightings. As a BST: there is a single online BST algorithm, depending only on , such that for every initial tree on keys, every , every positive weighting and every , its total cost is at most
The weights appear only in the bound: neither GreedyASS nor the BST algorithm knows them. In Lean, is
WeightedFinger.costFromw p Xand the infimum isWeightedFinger.optimalCostFrom, which need not be attained.Statement
This is Corollary 1 of the paper, the case of unit weights. For every start key , with ,
As a BST: there is a single online BST algorithm, depending only on , whose total cost from every initial tree on keys, for every and every , is at most times the same sum, plus .
In Lean, the sum is
Bounds.dynamicFingerCostFromp X.Statement
Let be a leaf-oriented reference tree whose leaves are the keys , and run GreedyASS from the empty point set on a sequence of requests from that range. Before the row for the current request is added, call a component of the reference forest of 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 . Call the other components virgin. Then the row GreedyASS adds for touches at most two old components.
Give each virgin component units of potential. If the row touches components in all, at least of them are virgin, so the virgin potential drops from to some with
These are the paper’s Lemmas 3.7 and 3.8. The second is stated additively, so that it is meaningful when .
Statement
Let be a leaf-oriented binary tree with leaves, labelled from left to right; its internal nodes carry no keys. For leaves let be the number of edges on the path from to in . The reference cost of a sequence of leaves is
one unit per request plus the edges a finger walks between consecutive requests. Equivalently, it is plus for the first request, where 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 , adds at most
points in total.
BST form. For every 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 keys, every leaf-oriented reference with leaves , and every sequence of keys less than , its total cost (rotations plus one per request) is at most
Pointer form. For every 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 with at most instructions.
In Lean, is
Amortized.referenceCostand isTransitions.edges. The reference tree is an ordinaryTree, read as leaf-oriented byReference.leaves. The point count isGeometric.rowCostofGeometric.greedySweep, and the BST costs areAlgorithm.totalCostand the cost ofOnline.run.Statement
Fix a reference tree on keys and a sequence of requests. Serve 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 , the number of switches, where a node’s preference changes from one side to the other, is exactly Wilber’s interleave quantity of Chapter 17;
- the number of settings, meaning switches plus the first time each node receives a preference, is at most .
By Wilber’s bound, both are , where is the rotation count of the best offline execution.
Statement
For every there is an online BST algorithm, fixed before any request is known, with the following property. Start from any tree on keys and serve any sequence of keys from . Every request is a legal access by rotations, and the total cost (rotations plus one per request) is at most
where is the number of rotations of any offline execution that serves from the same initial tree. So the algorithm is -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 legalAccessat the cost it reports. The cost is itstotalCost, and the comparator is anyExecution.Statement
For every there is a Tango policy for the balanced reference tree on keys, fixed before any request is known, whose step applies each request’s preference updates bottom-up, with the following property. Let be any sequence of requests, and take any offline execution that serves with rotations from any tree on keys. Then the policy, run from its reference tree, serves with total cost (rotations plus one per request) at most
Compared with Section 26.2, the startup term of the policy becomes , and the factor becomes .
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 , plus the policy’s rotations, plus . Combining the two gives an online BST, chosen before the initial tree and the requests, of total cost at most from every initial tree on 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.Policywhose step isBottomUp.serve, its cost is that ofPolicy.run, the comparator is anyExecution, and the online algorithm is anAlgorithmwith costAlgorithm.totalCost.Statement
Let be any reference tree of height , and serve a sequence of keys of 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
where is the height of ’s subtree in . 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 keys, the credit sum is at most .
In Lean, the first-setting charge is
Initialization.firstLogChargeof the bottom-up logBottomUp.log, and the credit sum isInitialization.localAllowance.Statement
Let be a sequence of keys from . A static BST on these keys serves with a lazy finger at cost
where is the number of edges on the path between and in , and is the root of : one unit per request, plus the edges the finger walks. There is an explicit algorithm that, given and , returns a tree with nodes such that
and whose work, counted in an explicit unit-cost RAM model, is at most . The bound holds for every , including , with no hidden constants. The same holds when the first search starts from a specified key instead of the root, that is, with .
In Lean, the algorithms are
Work.tree n xsandWork.treeFrom n p xs, computations in the cost modelWork.Computation:.retis the returned tree and.timethe counted work. The costs areLazyFinger.costandLazyFinger.costFrom, and the optimaLazyFinger.optimalCostandLazyFinger.optimalCostFrom, defined as infima over all shapes with 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.Statement
Let and . Let be a key and a sequence of keys, all in . Let be the number of indices with , where , let , and let
be the empirical conditional information of , so that . The multiple-tree store built from with capacity uses at most words, and serves , starting from , at total cost at most
Moreover, for every there is a capacity , depending only on and , such that for every and the store built from uses at most words and serves at cost at most .
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 spaceStore.words, the countsLazyFinger.frequency, isConditionalEntropy.costand isConditionalEntropy.entropy.Statement
This is the abstract BST-operation counterpart of Theorem 3 of the paper. Fix a nonempty initial tree with keys. Let and be two interruptible online algorithms starting from , each with a pointer-machine interpretation and a request-correctness contract, and let , be nonnegative amortized charges, where is the charge of the -th request of the whole sequence . Assume that both charges are well-behaved for their algorithms with a common overhead and constants , and that
Then there is one online pointer policy, chosen before any request is known, such that for every sequence of keys in its run from is a legal pointer execution serving , and for every window the run splits exactly into the part before , the window, and the part after , with additive costs. The window part is a legal pointer execution of between the trees the run actually reaches, and its cost is at most
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 . 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 , is the whole run.
In Lean, the algorithms are one
Controller.Workerwith a side bit, its interpretation is aRefinement.WorkerModelwithVisits.Correct, well-behavedness isAnalysis.WellBehaved, the window charge isAnalysis.mass, the policy is anOnline.Preparedrun byOnline.execute, and legality isPointer.Execution.Statement
The paper combines algorithms two at a time in a balanced binary tree (Section 1.2). Fix a nonempty initial tree with keys and a nonempty finite family of interruptible algorithms on , possibly with different state types, each with a pointer interpretation and request correctness, and each well-behaved for its own charge , with common , and . Let . Then there is one online pointer policy such that for every valid sequence its run from is legal, its total cost is at most , and for every window the run splits additively as in the box above and the window costs at most
with and . The scales start at and grow by one factor per level of the combination tree, and . For fixed , and these are constants, as in the paper; they are not the paper’s sharper .
In Lean, the family is a function into
Family.Algorithm, the scales areFamily.chargeScaleandFamily.overheadScale, and the guarantee isPhysical.Bounded.Statement
Let be two online algorithms of the rotation model (Chapter 5) and let be a tree on 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 , any constants and , and any nonnegative charges (the charge of the -th request of on side ) such that, for every sequence of keys below ,
and, for every contiguous segment ,
Then the worker satisfies the operational well-behavedness contract
Analysis.WellBehavedwith 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.CorrectforReplay.model).The cost on the left of the first inequality is
Algorithm.totalCost: one unit per request plus rotations. The factor is the price of the translation to the pointer machine. The single-request bound of well-behavedness ( per access from any reachable state) is not a hypothesis here: the worker caps every request at units.Statement
Let be a nonempty tree on keys, and let a worker present two source algorithms and on , with a causal pointer interpretation in which every access visits its key. Suppose both have well-behaved nonnegative amortized charges with constants and overhead . Then there is one prepared online policy , fixed before any request is known, such that for every sequence of keys in , serves as a legal pointer-machine execution from , and its total cost, pointer instructions plus one unit per request, is at most
In Lean, the worker is a
Controller.Workerwith aRefinement.WorkerModelsatisfyingVisits.Correct, the charges satisfyAnalysis.WellBehaved, and the policy is aOnline.Preparedrun byOnline.executefrom the optional statenone. The execution is aPointer.ExecutionfromT, 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.Statement
This is the abstract BST-operation counterpart of Theorem 6 of the paper. Let be any online BST algorithm in the rotation model, and any nonempty initial tree on keys. Then there is a single deamortized program, fixed from and before any request is known, made of two parts.
- Setup. A pointer-machine trace of at most instructions turns , cursor at the root, into a tree , cursor at the root.
- Responses. For every sequence of keys in , the program emits one stream of pointer instructions for a single persistent finger, starting at the root of . The stream is cut into consecutive segments, one per request. During segment the finger stands on at least once, and response costs . Every response is cheap, and the total is within a constant factor of :
where is the number of rotations performs on from . With the setup included, the total is at most , and any upper bound on gives the total bound .
The program is online: if is a prefix of , then the instruction stream and the list of response costs for are prefixes of those for .
In Lean, is an
Algorithmwith costAlgorithm.totalCost, and the program is aAlgorithm.Implementation.implementation_existsconstructs one; its fields carry the setup, the correctness and cost guarantees, and causality.total_boundadds the setup, andtransferreplaces by any real upper bound.Statement
For every nonempty initial tree on keys there is a deamortized splay program as in the box above, with splaying as the source algorithm . Every response costs less than . For every such program and every sequence of keys in , let 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 : .
- Balance. .
- Working set. , where is the working-set number of request .
- Static optimality, if requests every key: for every BST on the keys.
- Static finger, if requests every key: for every natural number .
- Without the coverage hypothesis, there are constants and , the same for all , all programs and all sequences, such that , where key is requested times. Likewise, with constants of its own, for every finger .
In Lean, splaying is
Splay.algorithm, isd.startup + out.costs.sum, and the bounds areworkingSetSum,StaticTree.cost,Bounds.staticCostandBounds.fingerCostof Chapter 14.Statement
This is the abstract BST-operation counterpart of Theorem 4.3 of the paper, in a normalized form. Let
savedbe any nonempty initial tree on 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 turns
savedinto the program’s prepared tree. - Serving. For every sequence of keys less than , 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 visits . The response cost is plus the length of that segment, so (number of instructions).
- Online. The instructions and response costs for do not depend on the later requests.
- Worst case. Every response costs .
- Total. For every start key , every initial tree on keys and every offline rotation-model execution that serves from it with rotations,
where . So the total cost is
Here is
WeightedFinger.optimalCostFrom, the infimum over all weightings positive on the keys of the weighted dynamic finger cost with and one unit per request (Section 25.3). It is not assumed to be attained. The comparator is anyExecution, so the bound holds in particular for the optimal one. The program is aCombination.Deamortizedstructure: its fields give the setup trace and the causality, and the theorem gives the rest.- Setup. Before the first request, a legal pointer trace of cost turns
Statement
The form of Theorem 4.3 for a single weighting. For every nonempty tree on keys there is a combined policy
pand a deamortized programdfor it. For every weighting positive on the keys, every , and every rotation-model execution with rotations that serves from a tree on keys, if the program serves then its setup plus response costs is at mostThe weights are chosen after the program, which never sees them.
Statement
For every , every request sequence and every number , the following are equivalent:
- there is an arborally satisfied set of exactly points, with keys less than and times less than , that contains the point of every request;
- some BST on keys can serve in the rooted-region model, touching exactly 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.Offlinesolutions and the executions areRegionExecutions.Statement
Let be a 2–3–4 tree of height with keys, stored as a BST in its standard binary representation.
- At most rotations turn that BST into its finger view, a BST on the same keys whose right spine has at most nodes.
- In the finger view, splaying the key of rank is a legal root access that uses at most rotations.
- Separately: take any order of splits that eventually separates keys, and charge for splitting a group into sides of and keys. The total charge is at most .
In Lean, is a
SplitTree.MultiwaywithMultiway.Balanced, its BST isMultiway.binary, the finger view isFinger.binaryView, and the order of splits is a binary tree read bySplitTree.totalCharge.Statement
Let be natural-number weights with total . The tree built by recursive weighted-median splitting has the keys in order, and every key satisfies , so when . Building instead from the regularized weights gives a tree in which every key with satisfies both
Depth counts edges from the root, as
Tree.depth. The uniform bound holds for every key, including those of weight zero.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 onto a valid stack of total weight 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 , a leaf of weight at depth satisfies
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 . 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.Statement
Start a Cherry pop-tart from the empty stack, and apply any sequence of 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 . A stack with leaves has every leaf at depth at most . Its next push costs at most instructions, and its next pop at most . In an ordinary pop-tart, whose leaves are empty, with nodes, every node has depth less than . 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 , and in the final stack of total weight every leaf of weight has depth
This is Lemma 3 of the paper. The lemma is stated with ; its proof ends with , which drops an additive constant: the heaviest leaf is at depth , while can be . The Lean bound adds for the spine nodes. The costs are those of
Program.cost, andempty_sequenceandweighted_sequencewrite the cost bound as , which is .Statement
Start a Chocolate pop-tart from a single bottom slot of nonnegative weight. Run any sequence of 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 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. for a potential , and from the initial single slot, .
- Worst-case cost. Each operation on a stack with fringe slots has .
- Weighted depth. After the sequence, every slot of weight is at depth at most
where is the total weight of the slots.
This is Lemma 4 of the paper. The paper’s depth bound is ; 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 per operation. Weights live on the fringe slots only; separators weigh nothing. A slot of weight is allowed but gets no depth bound.
Statement
Let be a tree whose nodes carry weights, and let 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.
- If all weights are nonnegative, every node with is reached from the root along a path with at most light edges.
- If all weights are positive and is nonempty, the solid path from the root ends at a leaf . Let be its number of edges. Starting at the root, the pointer machine turns into a tree with at the root, a valid Chocolate pop-tart of the path’s nodes smaller than 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 , and , where is the total leaf weight of . The rank at the root of is the rank of in .
- In every valid pair of leaf weight , a key inside a leaf of weight has depth at most
where is its depth inside the leaf’s subtree.
Item 1 is
path_existswithlight_bound, item 2 isextract_buildand item 3 islocated_key_bound. Depths count edges, and ranks are inorder positions from .Statement
Let be a labelled tree with nodes and positive node weights , and let be its total weight. The canonical recursive representation
rebuild w tis a tree shape with the same nodes. If is ordered,rebuild w thas exactly one ordered labelling with the inorder of , so it is a BST on the same keys. Whether or not is ordered, the node of inorder rank , whose label in is , lies at depthWith unit weights this is for every rank . 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 into
rebuild w tin at most 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 . In Lean,rebuild_labelsgives the unique ordered labelling,rebuild_depth_atandrebuild_unit_depthare the two depth bounds,History.Results.layout_depth_atis the bound for an arbitrary history layout (History.Layout), andrebuild_initializationis the setup trace.Statement
Let be a labelled tree with nodes and a cursor at one of its nodes, the finger . The cursor’s path to the root is arbitrary; it need not be heavy. Give every node a weight , and let be the total weight. Build the finger pair of this cursor with
Finger.build. Then:- Setup. Starting with the pointer at the root of , at most pointer instructions turn into the pair’s tree, and end with the pointer at its root.
- Same keys. If is a BST, the pair’s tree carries exactly one labelling with the inorder of , and that labelling is a BST.
- Finger at the root. The root of the pair’s tree has the rank of in .
- Weighted depth. The node of at inorder rank , with weight , has depth at most 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.
Statement
Fix a weight for every label . There is a policy with the following properties. To answer one source instruction, 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 with nodes and positive weights. Let be the total weight, and let be the weight of the -th label of in inorder. Then the physical tree, starting as itself with its cursor at the root, can be reshaped into a starting representation by a pointer-machine trace of cost . The trace satisfies , where is the starting potential. Take any stream of source instructions that is legal from the source finger. Running 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 , of cost with , where is the final potential;
- each source instruction is answered by at most 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 is at depth at most ;
- at every instruction boundary of the emitted physical program, even in the middle of a response, the node of rank is at depth at most
In Lean, the per-instruction bound is part of
Simulation.PolicyBounded, andSimulation.PolicyWithinextends 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.Statement
Let be a tree with nodes, whose keys are the inorder ranks . A scan finger sits on any node, and the cells still to visit are either a suffix in increasing order or a prefix 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 such rotations, the scan’s work is
and the total including the rotations is at most . 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 .
This is the paper’s Lemma 9, with explicit constants. The bound holds for any start position of the finger and any boundary , in either direction.
Statement
Consider a tree with 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 , with both fingers at the root and arbitrary initial cell contents, there is a save execution that ends with the same tree and the tree finger at its root, and that leaves in the cells the snapshot of : a fixed value below in every cell, determined by (
CellIO.Stored). It costs at most . 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 , and the current tree has the same number of nodes, with both fingers at its root. Then there is a load execution that ends with the tree and the tree finger at its root, at cost at most , 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; appears only in the conclusion.
Select one or more results above to see what to read.