Chapter 25 · GreedyASS · Section 25.2From points back to trees
An online geometric algorithm (Chapter 9) answers each request by naming a set of keys: the row of points it adds at the current time. It never says how a binary search tree would touch those keys, or what shape the tree would be in. Chapter 12 shows that, offline, a point set can always be turned back into a BST execution of comparable cost, but that conversion builds a treap ordered by the next time each key is touched (Chapter 32), which requires knowing the future.
Demaine, Harmon, Iacono, Kane and Pătraşcu (2009) showed that the future is not needed. Every online geometric algorithm can be simulated by an online BST algorithm whose cost is a constant times the number of points, plus a startup term. Their construction keeps the tree heap-ordered by the last time each key was touched. Keys touched at the same time are grouped into a “supernode”, stored as a split tree (Chapter 33) so that it can be broken apart cheaply when later rows touch some of its keys. Applied to GreedyASS (Section 25.1), this makes the geometric greedy algorithm an online BST algorithm, so its conjectured dynamic optimality is a statement about binary search trees.
The library formalizes this simulation as a single fixed algorithm, in the sense of Algorithm, whose cost is linear in the geometric point count. Here is the theorem in its basic form.
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 is Geometric.rowCost, and the BST algorithm is an Algorithm, whose cost counts rotations.
The Lean statement
/-- Fix the initial BST and an online geometric algorithm. A single BSTalgorithm, chosen before the sequence, simulates every valid request sequencewith constant cost per geometric point and linear initialization cost. -/theorem online_simulation (tree : Tree) (A : OnlineAlgorithm tree.size) : ∃ algorithm : Algorithm, ∀ xs : List Nat, (∀ x ∈ xs, x < tree.size) → algorithm.cost tree xs ≤ 6018 * rowCost A.step 0 ∅ xs + 6016 * tree.size := … Online.Supernode.online_policy tree AThis section states the four versions of the theorem and outlines the proof. The statements are in Algorithms/Simulation/Abstract.lean. They mention only the models: rotation executions, online algorithms, the geometric definitions and the pointer machine. Nothing about supernodes or split trees appears in them.
25.2.1 The simulation theorem
Fix a key universe of size and an online geometric algorithm A (Geometric.OnlineAlgorithm). For a request sequence xs, Geometric.rowCostA.step 0 ∅ xs is the number of points A adds when it runs from an empty history at time : the geometric cost of A on xs. The first theorem fixes the initial tree.
Theorem (online simulation). Let tree be a BST on keys and an online geometric algorithm on keys. There is a BST algorithm such that, for every sequence of keys less than , it serves from tree with at most rotations, where is rowCost A.step 0 ∅ X.
/-- Fix the initial BST and an online geometric algorithm. A single BSTalgorithm, chosen before the sequence, simulates every valid request sequencewith constant cost per geometric point and linear initialization cost. -/theorem online_simulation (tree : Tree) (A : OnlineAlgorithm tree.size) : ∃ algorithm : Algorithm, ∀ xs : List Nat, (∀ x ∈ xs, x < tree.size) → algorithm.cost tree xs ≤ 6018 * rowCost A.step 0 ∅ xs + 6016 * tree.size := Online.Supernode.online_policy tree A- One algorithm for all sequences. The existential
∃ algorithmcomes before∀ xs. The algorithm is chosen knowingtreeandA, but not the requests. Since it is anAlgorithm, each step receives only the past requests, the current tree and the current request (Chapter 5). This is what makes the simulation online. - Rotations only.
algorithm.costcounts rotations (Algorithm.cost). Request charges are added innormalized_simulationbelow. - Geometric cost includes the requests. Every legal row contains its request (
Geometric.Completion), sorowCostis at leastxs.length. A sequence of repeated requests for the current root costs one point per request and zero rotations. - The algorithm is not executable. The proof chooses it with
Classical.choosefrom existence statements, soalgorithm.stepis a mathematical function. Costs count rotations only, and the planning behind each step is not charged, as everywhere in the rotation model.
The algorithm above is built for one initial tree. A single algorithm can serve every initial tree of the given size, at the price of a slightly larger startup term.
Theorem (uniform simulation). For every and every online geometric algorithm on keys, there is a BST algorithm such that, for every initial tree on keys and every sequence of keys less than , it uses at most rotations.
This is the online equivalence of the geometric and BST models, stated in Chapter 12 as Results.online_bst, next to the offline equivalences. The proof fixes one reference shape. On the first request, the algorithm rotates whatever tree it is given into that shape, using at most rotations (Geometry.reset, Chapter 3), and from then on it behaves like the algorithm of online_simulation for the reference shape. The startup term grows from to . The same reset wrapper, which works for any online algorithm, also turns Tango into an algorithm for every initial tree (Section 26.2).
The conventional cost of a BST algorithm also charges one unit per request (Chapter 5). Since the geometric cost already pays one point per request, the conversion costs one more unit per point.
Theorem (conventional cost). Under the same hypotheses, there is a BST algorithm whose total cost, rotations plus one unit per request, is at most from every initial tree on keys.
/-- Conventional normalized cost includes one charge for every request. -/theorem normalized_simulation (n : Nat) (A : OnlineAlgorithm n) : ∃ algorithm : Algorithm, ∀ tree : Tree, tree.size = n → ∀ xs : List Nat, (∀ x ∈ xs, x < n) → algorithm.totalCost tree xs ≤ 6019 * rowCost A.step 0 ∅ xs + 6018 * n := Online.Supernode.uniform_online_total n AFinally, the simulation also runs on the pointer machine of Chapter 7. The causal transformer Online.run takes any rotation-model algorithm and runs it on the pointer machine, starting from Online.initial, postponing rotations that the current request does not need. Applying it to the simulated algorithm gives a pointer strategy.
Theorem (pointer simulation). Under the same hypotheses, there is a BST algorithm whose pointer-machine run, from every initial tree on keys and on every sequence of keys less than , is a legal pointer execution serving , with at most pointer instructions.
/-- The fixed causal pointer strategy serves every request and has linearcost in the geometric point count, including initialization. -/theorem pointer_simulation (n : Nat) (A : OnlineAlgorithm n) : ∃ algorithm : Algorithm, ∀ tree : Tree, tree.size = n → ∀ xs : List Nat, (∀ x ∈ xs, x < n) → Pointer.Execution tree xs (Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial tree) xs).1.current (Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial tree) xs).2 ∧ (Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial tree) xs).2 ≤ 192593 * rowCost A.step 0 ∅ xs + 192576 * n := Online.Supernode.uniform_online_pointer n AThe first conjunct says that the transformer’s instructions form a pointer execution (Pointer.Execution) that serves xs from tree, ending at the transformer’s current tree with the transformer’s cost. The second bounds that cost. The constants are those of the transformer, Results.simulation: pointer cost is at most , where is the algorithm’s rotation count and the number of requests. With and , where is the point count, this gives
$$
- The four occurrences of
Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial tree) xsare the same term: the final simulation state and its accumulated cost..1.currentis the tree actually present in the pointer machine, and.2is the cost. - As in Chapter 7, the final pointer tree need not equal the final tree of the rotation-model algorithm. The difference consists of postponed rotations that no request needed. They are not executed, and the bound does not have to pay for them.
None of the constants is meant to be sharp. They come out of a straightforward accounting. Creating a supernode costs, per key, the rotations that build it plus a stored credit large enough for every split it will ever undergo. Together these are at most per key. Two more units per point pay for rotating the request to the root inside the extracted region and for undoing those rotations afterwards. The initial tree is treated as a single supernode containing all untouched keys, which accounts for the .
25.2.2 GreedyASS as a binary search tree
The point of the theorem is that geometry can be used to design BST algorithms. GreedyASS adds, for each request, the minimal legal row (Results.greedy_minimum), and it is an online geometric algorithm (Geometric.greedyASS). Instantiating A with it in normalized_simulation gives an online BST algorithm whose total cost on every sequence is at most times the number of points GreedyASS adds, plus .
In the other direction, every BST execution with rotations on requests yields an arborally satisfied set of at most points (Results.rotations_to_ass). Together with the simulation, this means that GreedyASS is dynamically optimal as a BST algorithm, up to the additive term, if and only if its point count is within a constant factor of the minimum arborally satisfied superset of the requests. Whether this holds is the geometric form of the dynamic optimality conjecture for Greedy (Lucas 1988; Munro 2000; Demaine et al. 2009). It is open, and the library does not claim it.
The library proves no upper bound on the number of points GreedyASS adds, beyond what follows from the definitions. Known results about Greedy, such as its access lemma and the working-set bound (Fox 2011), are not formalized. The simulation transfers whatever bound one proves for a geometric algorithm, with a constant factor, but the bound itself must come from elsewhere.
25.2.3 Why the past suffices
The offline conversion of Chapter 12 keeps the tree as a treap ordered by next-touch times: the key that will be needed soonest is at the root. An online algorithm cannot know these priorities, but it knows the last touch of every key, Geometric.lastTouch. The simulation maintains the tree as a max-heap on last-touch times (Geometric.HistoryHeap), so that the most recently touched keys are near the root.
The first observation is that this is the right order for the next row. Suppose the new row touches a key , and is a key that was touched more recently than every key strictly between and . In a last-touch heap, such a is an ancestor of . Then the rectangle spanned by the new point and the last touch of contains no other old point. Looking at the row’s touched key closest to in that rectangle shows that arboral satisfaction forces the row to touch itself. Hence the keys of a legal row form a connected region containing the root, apart from one complication.
That complication is ties. All keys touched in the same row share their last-touch time, and a heap says nothing about their arrangement among themselves. The geometric argument above applies only to strictly more recent keys, so a new row may touch some keys of an old row and not others. The simulation therefore treats each maximal group of keys with the same last-touch time, within the interval delimited by more recent keys, as one supernode. The tree is a heap of supernodes, each supernode is a BST on its keys, and the gaps between a supernode’s keys hold the recursively represented subtrees of less recently touched keys.
25.2.4 How the simulation works
Serving a request has four phases. Each is a rotation sequence on the actual tree, and the proof tracks a state consisting of the geometric history, the nested supernode structure, and a canonical tree for that structure.
- Ask the geometric algorithm. The algorithm computes
A.step time x Pfrom the historyPand the requestx. This is the row that the BST must touch, and only the past is consulted. - Extract the row. Starting from the root supernode, the simulation splits each supernode that the row touches so that the touched keys rise to the top and the untouched parts remain as intact subtrees. It recurses into the gaps the row reaches. The touched keys of a supernode are carved out by splits whose cost is logarithmic in the smaller side (
Results.nearer_endpoint). After extraction, the touched keys form a rooted region whose fringe consists of untouched subtrees, the same picture as the rooted regions of Chapter 8. - Access. The request belongs to the row, so it lies in this region, which has one node per row point. Rotating it to the root inside the region takes fewer rotations than the region has nodes, and completes the
Accessthat the algorithm must perform. - Rebuild, later. The touched keys now share the latest touch time, so in the canonical tree they form one new supernode at the top, stored as a fresh split tree (
Results.finger_construction). Reaching that canonical tree from the accessed one means undoing the access rotations and then rebuilding. These rotations are not needed to serve the current request, so they are recorded as a debt, and the next request starts by performing them.
The amortization uses two kinds of stored potential. The debt is the number of rotations separating the actual tree from the canonical one. The credit of a supernode with keys is a constant times its number of multiway nodes, plus . The second term is the reserve from the proof of Results.linear_accounting, scaled by a constant number of rotations per unit of split charge. Splits draw on the credit of the supernode being split. Creating a supernode deposits its whole lifetime credit at once, and that deposit is paid by the keys of the new row, one row point each. This is how the constant per point, and per key for the initial supernode, arises.
The online algorithm itself is a replay. Given the past requests, the algorithm recomputes the simulation state that the past has produced, checks that the tree it is handed is the tree that state predicts, and performs the next certified step. If the tree differs, which never happens along a run from the intended initial tree, it falls back to moveToRoot, so that the Algorithm interface is satisfied on every input. Because each step consults only the history and the current request, the algorithm is fixed before the request sequence, which is what the order of the quantifiers in the theorems states.
Where the pieces are
The proof is about seventy modules under Algorithms/Simulation and uses the internal two-ended split trees of Structures/SplitTree. The geometric lemma about rows touching their more recent boundary keys is in Algorithms/Simulation/LastTouch. Extraction, rebuilding and supernode creation are in Algorithms/Simulation/Supernode/{Extraction,Rebuild,Create}, and the policy and its bounds are in Supernode/Policy. None of these modules is part of the reading interface. The four theorems above are the only statements a reader has to trust, and their statements reach only the model definitions listed under each of them.