Chapter 12How the models agree
Part I has now described binary search tree executions in five ways: rotation traces on shapes (Chapter 3), the same traces on labelled trees (Chapter 4), a single-pointer machine (Chapter 7), rooted regions rearranged at each request (Chapter 8), and arborally satisfied point sets (Chapter 9). The two models since then, many fingers and linked searches, serve particular results and are related to the others in their own chapters. This chapter proves that the geometric view measures the same thing as the other four. Demaine, Harmon, Iacono, Kane and Pătraşcu (2009) showed that the cheapest arborally satisfied superset of the request points has, up to constant factors, the cost of the best BST execution. Every BST question about a fixed sequence thereby becomes a question about points in the plane: no trees, no rotations, only rectangles.
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 a Geometric.Offline n xs, whose points field is the point set.
The Lean statements
/-- A rotation execution has a geometric solution of comparable total cost. -/theorem rotations_to_ass {s t : Tree} {xs : List Nat} {r : Nat} (execution : RotationBST.Execution s xs t r) : ∃ E : Offline s.size xs, E.points.card ≤ 2 * r + xs.length := … rotations_to_offline execution/-- Every ASS solution gives a rotation algorithm from any prescribed initialshape. The additive term pays for initialization; no final shape is prescribed. -/theorem ass_to_rotations (s : Tree) (xs : List Nat) (E : Offline s.size xs) : ∃ t r, RotationBST.Execution s xs t r ∧ xs.length + r ≤ 2 * s.size + 99 * E.points.card := … offline_from_initial s xs EThe chapter proves this in both directions, first exactly for the region model of Chapter 8, then with constants for the rotation model and the pointer machine. It ends with an online version, which turns an online geometric algorithm into an online BST algorithm. The introduction to Part I tabulates every correspondence of the part.
All six theorems are in Models/Equivalence/Abstract.lean, under Geometric.Equivalence.Results. Their statements use the geometric definitions of Chapter 9, the region model of Chapter 8, and the BST models of Chapter 3, Chapter 5 and Chapter 7.
12.1 What has to be compared
A geometric solution has no initial tree. Geometric.Offline n xs is an arborally satisfied set containing the request points , with every point on a key below and a time below = xs.length, and its cost is its number of points. A BST execution starts from a given tree of size . So each direction of the correspondence must decide what happens to the initial tree:
- From a BST execution to points, the initial tree is simply forgotten.
- From points to a BST execution, the conversion may choose a convenient initial tree, or it may be given one and pay to reach a convenient tree first. Rotations connect any two shapes of size in at most steps (
Geometry.reset), so the price of a prescribed initial tree is an additive .
All conversions in this chapter except the last are offline: they read a whole execution or a whole point set. The last section turns an online geometric algorithm into an online BST algorithm.
12.2 Regions are points
The rooted-region model of Chapter 8 is the BST model of the 2009 paper. At each request the algorithm touches a connected region containing the root and the requested key, rearranges it, and pays one unit per touched node. Its executions and point sets are the same objects, with the same cost.
Theorem (regions are points). For every number of keys , sequence xs and number cost, there is an offline geometric solution with exactly cost points if and only if some initial tree of size has a RegionExecution serving xs with charge exactly cost.
/-- Exact point-count equivalence with rooted-subtree BST executions.The initial tree is free; the conversion is offline. -/theorem ass_iff_region_execution (n : Nat) (xs : List Nat) (cost : Nat) : (∃ E : Offline n xs, E.points.card = cost) ↔ ∃ s t, s.size = n ∧ RegionExecution s xs t cost := offline_iff_regions n xs costThe equivalence is exact: one touched node per point, in both directions, with no constant.
- From regions to points, record row as the keys touched by the -th step. Each row contains the request, since a
RegionStepmust visit it, and the rows together are arborally satisfied. The proof keeps the current tree a max-heap of last-touch times, and finds the third point of every rectangle as a common ancestor in that heap (Section 32.4). - From points to regions, build a treap whose priorities are next-touch times. Before each row, the keys of that row are exactly the top region of the treap, and rearranging that region alone restores the treap for the next time (Section 32.2). This is the offline step: priorities come from the future of the point set.
- The initial tree
sis existential on the right-hand side. The treap construction needs its own initial tree, the treap for the first touches. The final treetis unconstrained. - Region charges count
step.before.size, the nodes of the touched region and not the untouched subtrees hanging from it. Point counts and region charges therefore agree exactly. costis the same variable on both sides, so the equivalence also says that the minimum costs coincide. A minimum offline solution exists (Results.optimal_exists).
12.3 From trees to points
An execution in the rotation model of Chapter 3, or on the pointer machine of Chapter 7, yields a geometric solution that is at most a constant factor larger.
Theorem (rotations to points). If a root-access execution from a tree s serves the requests xs with rotations, then xs has an offline geometric solution on s.size keys with at most points.
/-- A rotation execution has a geometric solution of comparable total cost. -/theorem rotations_to_ass {s t : Tree} {xs : List Nat} {r : Nat} (execution : RotationBST.Execution s xs t r) : ∃ E : Offline s.size xs, E.points.card ≤ 2 * r + xs.length := rotations_to_offline executionThe touched nodes of an access are not determined by its rotations: the rotation model allows rotations anywhere, and those far from the request touch nodes the access never needed. The proof reuses the lazy normal form of Chapter 7. The rotations of an access that are connected to the root in the rotation graph form an access on their own, and they rearrange a region of at most nodes, where is their number. That region is a region step. The other rotations are postponed to later accesses. Summing over the execution, the region charge plus twice the rotations still pending at the end is at most , and Results.ass_iff_region_execution turns the region execution into points.
Theorem (pointers to points). If a pointer execution from s serves xs at total cost (requests plus instructions), then xs has an offline geometric solution with at most points.
/-- The conventional pointer model also maps to geometry at constant cost. -/theorem pointers_to_ass {s t : Tree} {xs : List Nat} {cost : Nat} (execution : Pointer.Execution s xs t cost) : ∃ E : Offline s.size xs, E.points.card ≤ 6 * cost := pointer_to_offline executionThis composes two earlier bounds. Results.to_rotations turns the pointer execution into a rotation execution with , and the previous theorem gives at most points.
These two theorems carry geometric lower bounds back to the tree models. Wilber’s interleave bound (Chapter 17) is proved once for point sets, , and stated for rotation executions as and for pointer executions as , through exactly these conversions.
12.4 From points to trees
Conversely, every geometric solution can be executed by a tree at constant cost per point. Here the initial tree matters, and the two theorems treat it differently.
Theorem (points to pointers). For every offline geometric solution of xs on keys, there is an initial tree of size from which a pointer execution serves xs at total cost at most .
/-- Without fixing the initial tree, the geometric solution has a pointerrealization with no additive initialization term. This construction is offline. -/theorem ass_to_pointers {n : Nat} {xs : List Nat} (E : Offline n xs) : ∃ s t cost, s.size = n ∧ Pointer.Execution s xs t cost ∧ cost ≤ 33 * E.points.card := offline_to_pointer EThe construction chooses the initial tree. It runs the treap construction of Chapter 32 on the pointer machine. Each row is a region of nodes that must be rearranged, with the request visited along the way. The reshaping lemma Results.reshape transforms a region into any other with the same fringe in at most instructions. Reshaping once to bring the request to the root, where the cursor is, and once more into the target arrangement costs , including the request unit. Summed over the rows, this is per point.
Theorem (points to rotations). For every tree s with nodes and every offline geometric solution of the requests xs on keys, some root-access execution from s serves xs with rotations, where .
/-- Every ASS solution gives a rotation algorithm from any prescribed initialshape. The additive term pays for initialization; no final shape is prescribed. -/theorem ass_to_rotations (s : Tree) (xs : List Nat) (E : Offline s.size xs) : ∃ t r, RotationBST.Execution s xs t r ∧ xs.length + r ≤ 2 * s.size + 99 * E.points.card := offline_from_initial s xs EThe initial shape is prescribed here, not chosen. Two steps produce the constants. First, the pointer execution of ass_to_pointers becomes a rotation execution by Results.to_rotations, which multiplies by : . That execution starts from the treap chosen by the construction, so the theorem first rotates s into it, using at most rotations (Geometry.reset), merged into the first access. The suffix of postponed rotations that to_rotations leaves at the end is dropped, since no final shape is prescribed.
Theorem (points to pointers, prescribed start). For every tree s with nodes and every offline geometric solution of xs on keys, some pointer execution from s serves xs at total cost at most .
/-- The pointer machine from a prescribed initial tree: a linear initializationterm, as for rotations. No final shape is prescribed. -/theorem ass_to_pointers_from (s : Tree) (xs : List Nat) (E : Offline s.size xs) : ∃ t cost, Pointer.Execution s xs t cost ∧ cost ≤ 64 * s.size + 3168 * E.points.card := pointer_from_initial s xs EIt composes the two conversions already shown: the rotation execution of ass_to_rotations from s, then the lazy pointer simulation of Results.to_pointer_lazy (Chapter 7). The lazy simulation costs at most . Its pending rotations at the end are dropped, since no final shape is prescribed.
Together, these theorems pin down the offline optimum. Writing for the size of a smallest geometric solution, every rotation execution from s satisfies , and the best one satisfies . Up to constant factors and the for the initial tree, the offline cost of a sequence is a property of a point set.
12.5 Online: from geometric algorithms to BST algorithms
The conversions above see the whole future. The treap construction in particular orders keys by their next touch, which no online algorithm knows. An online geometric algorithm (Geometric.OnlineAlgorithm, Chapter 9) instead adds the points of each row knowing only the past rows and the current request, and Geometric.rowCost counts the points it adds. Demaine et al. (2009) showed that such an algorithm can be simulated online by a BST with a constant-factor overhead. The library proves this in the following form.
Theorem (online simulation). For every online geometric algorithm A on keys there is a single BST Algorithm of Chapter 5 such that, from every initial tree of size and on every sequence of keys below , its rotation count is at most times the number of points A adds, plus .
/-- Online: every online geometric algorithm has one causal BST policy, validfrom all initial shapes, with constant rotation cost per added point and alinear initialization allowance. The policy is fixed before the request sequence. -/theorem online_bst (n : Nat) (A : OnlineAlgorithm n) : ∃ algorithm : Algorithm, ∀ tree : Tree, tree.size = n → ∀ xs : List Nat, (∀ x ∈ xs, x < n) → algorithm.cost tree xs ≤ 6018 * rowCost A.step 0 ∅ xs + 6018 * n := Online.Supernode.uniform_online_policy n A- Online in the strong sense. The algorithm is chosen before the tree and the sequence. Like every
Algorithm, its step receives only the past requests, the current tree and the current request. It may simulateAon the past, sinceAsees no future either. - Uniform in the initial tree. One algorithm works for every initial shape of size , and the additive pays for adapting to it.
- The constants are not sharp. The proof is an existence argument through last-touch supernodes stored in split trees, and its constants are the product of several lemmas. They are explicit only so that the statement is closed.
This theorem is the headline of Section 25.2, which proves it and states variants for one fixed initial tree, with total cost, and on the pointer machine. Its main use is GreedyASS (Section 25.1): the greedy geometric rule becomes an online BST algorithm whose cost is within a constant factor of its point count.
Only this direction is stated online. The other direction, from an online BST algorithm to an online geometric algorithm, is immediate in the region model (record the touched nodes), but the library states the tree-to-points conversions offline only, as in the previous sections.
12.6 A map of the models
The introduction to Part I collects the theorems of this chapter, together with the correspondences of Chapter 4 and Chapter 7, in one figure and one table.