Chapter 25 · GreedyASS · Section 25.6Paying for each row
This section completes the proof of Theorem 3.1 of Iacono and Langerman (2016). The theorem says that GreedyASS (Section 25.1) serves every request sequence about as fast as a fixed leaf-oriented reference tree whose search starts where the previous search ended. Section 25.4 built the reference forest, and Section 25.5 built the potential: item potentials of four colors, plus a virgin potential on the roots of the forest. What remains is the accounting. For each row that GreedyASS adds, the number of points plus the change in potential is at most times the reference distance between the two searches, plus , plus a one-time charge for keys never accessed before. Adding these bounds over the rows gives the theorem.
The theorem is the base of Section 25.3. Its consequences there, the ordinary lazy-finger bound, the weighted dynamic finger bound and the dynamic finger bound (Theorems 4.1 and 4.2 and Corollary 1), all follow from it.
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.referenceCost and 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.
The Lean statements
/-- Theorem 3.1 for the actual geometric sweep: twenty-four times thenode-counted leaf-reference benchmark, plus fifteen per reference leaf. -/theorem cost (t : Tree) (lo : Nat) (xs : List Nat) (valid : ∀ x ∈ xs, lo ≤ x ∧ x < lo + leaves t) : rowCost greedySweep 0 ∅ xs ≤ 24 * referenceCost t lo xs + 15 * leaves t := … Amortized.cost t lo xs validModels.Rotation, Models.Online, Models.Pointer.Machine, Models.Pointer.Lazy.Online.Definitions, Models.Pointer.Lazy.Online.Algorithm, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions, Algorithms.GreedyASS.Potential.Amortized.Definitions/-- One BST policy works simultaneously for all leaf-oriented references.Its normalized cost includes requests, rotations, and initialization. -/theorem bst (n : Nat) : ∃ algorithm : Algorithm, ∀ initial : Tree, initial.size = n → ∀ reference : Tree, leaves reference = n → ∀ xs : List Nat, (∀ x ∈ xs, x < n) → algorithm.totalCost initial xs ≤ 144456 * referenceCost reference 0 xs + 96303 * n := … Amortized.bst nModels.Rotation, Models.Online, Models.Pointer.Machine, Models.Pointer.Lazy.Online.Definitions, Models.Pointer.Lazy.Online.Algorithm, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions, Algorithms.GreedyASS.Potential.Amortized.Definitions/-- Actual pointer execution with the same quantifier order and a singlelinear initialization allowance. The simulation constants are not sharp. -/theorem pointer (n : Nat) : ∃ algorithm : Algorithm, ∀ initial : Tree, initial.size = n → ∀ reference : Tree, leaves reference = n → ∀ xs : List Nat, (∀ x ∈ xs, x < n) → Pointer.Execution initial xs (Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial initial) xs).1.current (Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial initial) xs).2 ∧ (Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial initial) xs).2 ≤ 4622232 * referenceCost reference 0 xs + 3081471 * n := … Amortized.pointer nModels.Rotation, Models.Online, Models.Pointer.Machine, Models.Pointer.Lazy.Online.Definitions, Models.Pointer.Lazy.Online.Algorithm, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions, Algorithms.GreedyASS.Potential.Amortized.DefinitionsThe paper states the bound as . The Lean statements hold for every reference tree at once, with explicit constants. In the BST and pointer forms the algorithm is chosen before , so the minimum over follows. None of the constants is meant to be sharp. The startup term is twelve units for each initial virgin root and three for the first access to each key; the paper leaves both of these implicit, and the Lean proof pays them explicitly (Section 25.6.9).
A reader who only wants the result can stop here. The rest of the section is the proof, in the order of the paper’s Sections 3.4 to 3.6. Section 25.6.1 gives the plan of the proof and a map from the paper’s lemmas to the Lean theorems. Section 25.6.2 defines the benchmark and the potential. Then come Phase I (Section 25.6.3), the two halves of Phase II (Section 25.6.4 and Section 25.6.5), the color counting they rely on (Section 25.6.6), the assembly of Phase II (Section 25.6.7), and the final summation (Section 25.6.8). The statements live in Algorithms/GreedyASS/Potential/{PhaseOne,Accessed,Unaccessed,Counting,PhaseTwo,Amortized}/Abstract.lean and their Definitions/Abstract.lean files.
25.6.1 The plan of the proof
Fix the reference tree and write for the requests. At time , the reference forest is with the proper ancestors of the leaf removed (Reference.forest, Section 25.4). Its roots are the siblings of the nodes on the path from the root of down to , together with the leaf itself.
The potential after row has two parts (Section 25.5):
- Item potential. Each key that has been accessed carries a natural number determined by its color. Red and green measure distances in to the lowest common ancestor of the key’s neighbors, in its row or among the external keys. Blue is one plus the node distance from the key to its root in the current forest. Purple is the largest blue value since the key’s last access. Never-accessed keys carry .
- Virgin potential. Each root of the current forest carries if no key in its interval has been accessed since it became a root, and otherwise.
The amortized cost of row is the number of points it adds, , plus . The proof bounds it in two phases, separated by an intermediate potential . This is the potential computed with the new forest but the old point set .
- Phase I (): the forest changes from to while the points stay fixed. The change is a sequence of merges up from to the lowest common ancestor of and , followed by splits down to : one event per edge of the path. Each event raises the potential by at most . So .
- Phase II (): the row is added while the forest stays . Every accessed key that ends red pays for its own point, because its potential drops by at least one. Keys accessed for the first time cost at most each. The remaining accessed keys end blue or purple, and there are at most of them in each root touched by the row. Every touched root except at most two loses its units of virgin potential. Untouched keys never gain. So , where is the number of keys accessed for the first time.
- Summation. The two phases give for each row after the first. The first row has no Phase I; it starts from the virgin potential of , at most . The sum telescopes. The count distinct keys, so they add up to at most . Since , the total number of points is at most .
The table maps the steps to the paper and to the Lean theorems.
| Step | Paper | Lean |
|---|---|---|
| Blue and purple counts per root | Lemma 3.1 | Results.counts |
| A split or merge costs at most | Lemma 3.2 | Results.local_change, Results.charges |
| Phase I | Lemma 3.3 | Results.step |
| Virgin roots lost in Phase II | Lemmas 3.7, 3.8 | Results.count, Results.decrease |
| Accessed items, by color after Phase I | Lemmas 3.9–3.12 | Results.green_exact_change, Results.purple_change, Results.blue_change, Results.red_change |
| Unaccessed items | Lemmas 3.13–3.17 | Results.external_point, Results.red_unchanged, Results.internal_cover, Results.nonexternal_change |
| Phase II | Lemma 3.18 | Results.step |
| One row | Lemma 3.19 | Results.step |
| The whole sequence | Theorem 3.1 | Results.stream, Results.cost |
25.6.2 The benchmark and the potential
The benchmark charges a lazy finger on the leaves of . Between two consecutive requests, the finger walks the path between their leaves.
/-- Reference edges traversed between consecutive requests. The firstrequest has no predecessor and contributes no edges. -/def edgeCost (t : Tree) (lo : Nat) : List Nat → Nat | [] => 0 | [_] => 0 | x :: y :: xs => Transitions.edges t lo x y + edgeCost t lo (y :: xs)/-- Node-counted lazy-finger benchmark on a leaf-oriented reference tree,with one unit for the first request and no initial root traversal. -/def referenceCost (t : Tree) (lo : Nat) (xs : List Nat) : Nat := xs.length + edgeCost t lo xsedgeCost t lo xs sums Transitions.edges t lo x y over consecutive pairs x, y of xs. That function descends from the root of t while both leaves are on the same side, and at their lowest common ancestor returns the sum of the two leaf depths in that subtree, counted in edges. So it is the number of edges on the leaf-to-leaf path, and when . The offset lo is the label of the leftmost leaf, so the leaves of t are lo, …, lo + leaves t - 1.
referenceCost adds one unit per request. Since the paper’s distance counts nodes, , and
A repeated request costs one unit, the cheapest possible charge for a search. The first request also costs one unit: the finger is assumed to start on it, rather than at the root. An initial walk from the root would add at most the height of , which is less than , so the convention changes nothing up to the startup term.
The potential after a history xs is the potential of Section 25.5, evaluated on the actual GreedyASS points:
/-- Potential after all rows of the history have been completed. Virginlifetimes are evaluated in the last searched forest after its access. -/noncomputable def potential (t : Tree) (lo : Nat) (xs : List Nat) : Nat := totalAmount t lo xs (Virgin.points xs) (Finset.range (lo + leaves t)) + match xs.getLast? with | none => 0 | some last => Virgin.before t lo xs lastThe first term is the item potential Potential.totalAmount, summed over the keys 0, …, lo + leaves t - 1. The point set is Virgin.points xs, the set GreedyASS produces from the empty history, and the search list is xs itself, so blue values are measured in the forest of the last request. Keys below lo are never accessed and contribute , so the range is just a convenient finite domain containing every column. The second term is Virgin.before at the last request last, with the completed history xs (which already contains last). It is times the number of roots of the last search’s forest that have not been accessed since they became roots. The empty history has potential .
All quantities are natural numbers, so the potential is never negative. This is what lets the summation drop the final potential at the end.
25.6.3 Phase I: moving the reference forest
Phase I keeps the point set P of the completed history prior ++ [old] fixed and replaces the forest of old by the forest of next. The resulting intermediate item potential is Potential.totalAmount with the search list prior ++ [old] ++ [next] and the old points. Appending next without a new row changes exactly two things: blue is now measured in the forest of next, and every purple maximum now includes that new blue value.
25.6.3.1 Values on any cut
The forest of old is turned into the forest of next one split or merge at a time, and the forests in between are not search forests. To follow the potential through them, the library evaluates every item on an arbitrary ordered cut of into subtrees (Transitions.Cut).
/-- Current blue candidate for an arbitrary ordered cut, including theintermediate cuts of an LCA-routed split/merge plan. -/def rootBlue : List Component → Nat → Nat | [], _ => 0 | c :: cs, x => if c.Contains x then Distance.toRoot c x + 1 else rootBlue cs xrootBlue roots x finds the component of the cut containing x and returns one plus the node distance from x to that component’s root (Distance.toRoot). This is the paper’s for that cut. On a search forest it is the existing blue value:
Theorem (cut blue agrees with blue). For every leaf of and every search , rootBlue on the forest of equals Potential.blue t lo s x.
/-- The cut query agrees with the existing blue potential at a search forest. -/theorem forest_blue (t : Tree) (lo searched x : Nat) (valid : lo ≤ x ∧ x < lo + leaves t) : rootBlue (forest t lo searched) x = blue t lo searched x := rootBlue_forest t lo searched x validModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.PhaseOne.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsGiven a blue candidate b, the value of a point is selected as follows. The color rule of Section 25.5 is rewritten with minima and maxima, which makes the dependence on b explicit:
/-- During Phase I the geometry and old historical maximum stay fixed.Only the current forest's blue candidate changes. -/def select (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (q : Point) (b : Nat) : WithTop Nat := if ¬ Active P q then WithTop.some 0 else if External P q then if LatestRow P q.2 then b else min (green t lo P q.1) (WithTop.some b) else if Glancing P q then min (red t lo P q) (WithTop.some (max (purple t lo searches q.2 q.1) b)) else red t lo P qAn inactive point has value . A top corner, an external point in the latest row, has value b. Another external point has : green when green is at most blue, as the color rule says, and blue otherwise. A glancing point has , where purple is the historical maximum over the old search list and b adds the current forest’s contribution. An internal point has its red value. The location classes, red and green depend only on P, so they are fixed throughout Phase I. Only b moves, and select is monotone in b.
def valueAt (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (roots : List Component) (q : Point) : WithTop Nat := select t lo searches P q (rootBlue roots q.1)def itemAt (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (roots : List Component) (x : Nat) : WithTop Nat := match latest P x with | none => WithTop.some 0 | some stamp => valueAt t lo searches P roots (x, stamp)def amountAt (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (roots : List Component) (x : Nat) : Nat := (itemAt t lo searches P roots x).untopD 0def totalAt (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (roots : List Component) (domain : Finset Nat) : Nat := ∑ x ∈ domain, amountAt t lo searches P roots xvalueAt applies select with the candidate rootBlue roots q.1. itemAt applies it to a key’s most recent access, or gives for a key never accessed. amountAt converts the result to a natural number, and totalAt sums over a finite domain. As with Potential.itemAmount, the conversion untopD 0 would turn into . It loses nothing, because the selected value is always finite:
Theorem (cut values are finite). For every cut and every key, itemAt is the finite number amountAt.
/-- Intermediate selected values are exactly their finite natural-valued amounts. -/theorem amount (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (roots : List Component) (x : Nat) : itemAt t lo searches P roots x = WithTop.some (amountAt t lo searches P roots x) := amount_exact t lo searches P roots xModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.PhaseOne.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsThe two ends of Phase I are the two potentials it connects.
Theorem (initial cut). If P is a history before time with all keys in the leaf range, then on the forest of old, with the search list prior ++ [old], totalAt equals the item potential Potential.totalAmount for prior ++ [old].
/-- The initial cut has exactly the old total item potential. -/theorem initial (t : Tree) (lo : Nat) (prior : List Nat) (old : Nat) {n : Nat} {P : Finset Point} (history : History n (prior.length + 1) P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) (domain : Finset Nat) : totalAt t lo (prior ++ [old]) P (forest t lo old) domain = totalAmount t lo (prior ++ [old]) P domain := total_initial t lo prior old history valid domainModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.PhaseOne.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsTheorem (final cut). If P is a history before time with all keys in the leaf range, then on the forest of searched, with the search list searches, totalAt equals the item potential for searches ++ [searched], the intermediate potential.
/-- The final cut has exactly the next intermediate total item potential. -/theorem final (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (history : History n searches.length P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) (domain : Finset Nat) : totalAt t lo searches P (forest t lo searched) domain = totalAmount t lo (searches ++ [searched]) P domain := total_final t lo searches searched history valid domainModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.PhaseOne.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsIn the initial theorem, the purple maximum over prior ++ [old] already includes the blue value at old, so taking the maximum with b changes nothing. In the final theorem, the maximum with b is exactly what appending searched to the search list adds. Throughout Phase I the search list in totalAt stays prior ++ [old]; only the cut moves.
25.6.3.2 Which items can gain
A split replaces a root by its two children. Every key below it gets one node closer to its root, so b decreases and, by monotonicity, no value increases. A merge is the reverse. Every key of the two merged components gets one node farther from its root, so b grows by exactly one, and each value grows by at most one. Only some keys can actually gain:
/-- Only an external point not capped by green, or a glancing point notcapped by red, can gain when its blue candidate rises. -/def Sensitive (t : Tree) (lo : Nat) (P : Finset Point) (q : Point) (b : Nat) : Prop := (External P q ∧ (LatestRow P q.2 ∨ WithTop.some b < green t lo P q.1)) ∨ (Glancing P q ∧ WithTop.some b < red t lo P q)instance (t : Tree) (lo : Nat) (P : Finset Point) (q : Point) (b : Nat) : Decidable (Sensitive t lo P q b) := inferInstanceAs (Decidable ((_ ∧ (_ ∨ _)) ∨ (_ ∧ _)))A point is sensitive to the candidate b if raising b can raise its selected value. This holds for an external point that is a top corner or whose green value exceeds b, and for a glancing point whose red value exceeds b. Internal points never depend on b, and the other external and glancing points are capped by green or red. The instance only makes the predicate decidable, so that it can be used in a filter.
/-- Actual active columns whose selected potential can increase in a mergefrom this component. Historical maxima can only reduce this charged set. -/def chargedKeys (t : Tree) (lo : Nat) (P : Finset Point) (c : Component) : Finset Nat := (P.filter fun q => Active P q ∧ c.Contains q.1 ∧ Sensitive t lo P q (Distance.toRoot c q.1 + 1)).image Prod.fstchargedKeys t lo P c collects the columns of the active points inside the component c that are sensitive to the blue candidate of c, one plus their distance to its root. Historical purple maxima can only cap values further, so every key whose value can grow when c is merged into its parent lies in this set. The set is small:
Theorem (six charged keys per subtree). For every subtree occurrence of and every arborally satisfied P, at most columns are charged.
/-- At most six active columns per actual reference subtree can gain on a merge. -/theorem charges {t : Tree} {lo k : Nat} {c : Component} (occurrence : Distance.Occurs t lo c k) {P : Finset Point} (satisfied : ASS P) : (chargedKeys t lo P c).card ≤ 6 := charged_count occurrence satisfiedModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.PhaseOne.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsThe count is the argument of Lemma 3.1, run with the candidate of c instead of the current colors: at most two sensitive glancing points, two sensitive left-external points and two sensitive right-external points. Among three glancing points of one subtree, the middle one has its row neighbors between the outer two. By the nesting of lowest common ancestors (the paper’s Fact 3.1), its red value is then below the subtree’s blue candidate, so it is not sensitive. External points work the same way, with green in place of red. Section 25.6.6 gives the same argument for the actual colors.
25.6.3.3 Splits, merges and the plan
Theorem (one event). Let P be arborally satisfied with keys in the leaf range. A split or merge of an ordered cut of , whose parent component is a subtree of , increases totalAt by nothing if it is a split, and by at most if it is a merge.
/-- Splits add no item potential; merges add at most twelve. -/theorem local_change (t : Tree) (lo : Nat) (searches : List Nat) {P : Finset Point} (satisfied : ASS P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) {roots next : List Component} {event : Transitions.Event} (cut : Transitions.Cut t lo roots) (step : Transitions.Step roots event next) (admissible : Transitions.Admissible t lo event) (domain : Finset Nat) : totalAt t lo searches P next domain ≤ totalAt t lo searches P roots domain + (if event.isMerge then 12 else 0) := step_total t lo searches satisfied valid cut step admissible domainModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.PhaseOne.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsA merge joins two components, each with at most charged keys gaining at most one unit each. The hypotheses come from Section 25.4. cut says the current components are an ordered partition of the leaves into actual subtrees of . step is the local rewrite, and admissible says the parent of the event occurs in . Two adjacent intervals are not enough for a merge: they must be siblings in .
Theorem (any trace). Along a certified trace of splits and merges from a cut, totalAt increases by at most per merge.
/-- Only merge events consume item-potential credit along a certified trace. -/theorem trace_change (t : Tree) (lo : Nat) (searches : List Nat) {P : Finset Point} (satisfied : ASS P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) {roots next : List Component} {events : List Transitions.Event} (trace : Transitions.Trace roots events next) (cut : Transitions.Cut t lo roots) (admissible : ∀ e ∈ events, Transitions.Admissible t lo e) (domain : Finset Nat) : totalAt t lo searches P next domain ≤ totalAt t lo searches P roots domain + 12 * Transitions.merges events := trace_total t lo searches satisfied valid trace cut admissible domainModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.PhaseOne.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsTheorem (the plan). If P is arborally satisfied, is a history before time , and has keys in the leaf range, then the intermediate item potential exceeds the item potential of prior ++ [old] by at most times the number of merges in Transitions.plan t lo old next.
/-- The actual LCA plan bounds the old-to-intermediate item-potential change. -/theorem items_change (t : Tree) (lo : Nat) (prior : List Nat) (old next : Nat) {n : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n (prior.length + 1) P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) (domain : Finset Nat) : totalAmount t lo ((prior ++ [old]) ++ [next]) P domain ≤ totalAmount t lo (prior ++ [old]) P domain + 12 * Transitions.merges (Transitions.plan t lo old next) := plan_items t lo prior old next satisfied history valid domainModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.PhaseOne.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsThe plan is the LCA-routed sequence of Section 25.4: merges from the leaf old up to the lowest common ancestor, then splits down to next. Its events correspond to the edges of the path, so there are exactly of them. The virgin side of the budget is Results.phase_one_budget from Section 25.5. A split creates two new roots, which may be virgins worth each, and a merge creates one. So the virgin potential grows by at most per split and per merge, and the remaining per merge pays for the items. Together:
Theorem (Phase I, Lemma 3.3). Let prior ++ [old] ++ [next] be requests in the leaf range, and let P be the GreedyASS points of prior ++ [old]. On any domain, the intermediate item potential plus the virgin potential of the forest of next is at most the item potential after old plus the virgin potential left after old’s row, plus .
/-- Lemma 3.3: all item and virgin potential increases fit the 24-per-reference-edge bound. -/theorem step (t : Tree) (lo : Nat) (prior : List Nat) (old next : Nat) (valid : ∀ x ∈ (prior ++ [old]) ++ [next], lo ≤ x ∧ x < lo + leaves t) (domain : Finset Nat) : totalAmount t lo ((prior ++ [old]) ++ [next]) (Virgin.points (prior ++ [old])) domain + Virgin.before t lo (prior ++ [old]) next ≤ totalAmount t lo (prior ++ [old]) (Virgin.points (prior ++ [old])) domain + Virgin.after t lo prior old + 24 * Transitions.edges t lo old next := PhaseOne.step t lo prior old next valid domainModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.PhaseOne.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsThe left side is and the right side is . Here Virgin.after t lo prior old is the virgin potential once old’s row has been added, and Virgin.before t lo (prior ++ [old]) next is the virgin potential of the forest of next before the next row. The paper bounds Phase I by , counting nodes. The Lean bound, , counts the events, which is one per edge.
25.6.4 Phase II: the accessed items
Phase II keeps the forest of the current search searched and adds GreedyASS’s row, keys = greedySweep |searches| searched P, to the old points P. Colors before the row are the intermediate ones: search list searches ++ [searched], points P. Colors after it use the same search list and P ∪ row |searches| keys. Most statements below assume that P is a history before time (so the new row is the latest), and some also that it is arborally satisfied with keys in the leaf range.
After the row, an accessed key is never green. Its point is in the latest row. If it is external, it is a top corner, which is blue by the color rule. Otherwise no point lies above it, so it is glancing, and it is red or purple. Every new value is also bounded by the current blue value:
Theorem (new accesses are capped by blue). For any finite set keys placed on the new row, and any x ∈ keys, the new value of x is at most Potential.blue t lo searched x. It is strictly smaller if x ends red.
/-- Every new access is bounded by blue; a new red value is strictly smaller. -/theorem new_access (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (keys : Finset Nat) (history : History n searches.length P) {x : Nat} (member : x ∈ keys) : itemValue t lo (searches ++ [searched]) (P ∪ row searches.length keys) x ≤ WithTop.some (blue t lo searched x) ∧ (itemColor t lo (searches ++ [searched]) (P ∪ row searches.length keys) x = some .red → itemValue t lo (searches ++ [searched]) (P ∪ row searches.length keys) x < WithTop.some (blue t lo searched x)) := top_bound t lo searches searched keys history memberModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.DefinitionsFor a top corner the value is blue itself. For a glancing point, purple is a maximum over the searches since its last access, which is now only searched, so it is blue, and red is selected only when it is strictly smaller.
The remaining lemmas split the accessed keys by their color after Phase I, as the paper does. Each says that the potential does not increase, and decreases by at least one if the key ends red.
Theorem (Lemma 3.10, old purple). If an accessed key was purple, its new value is at most its old one, and strictly smaller if it ends red.
/-- Lemma 3.10: resetting the old purple maximum cannot increase potential. -/theorem purple_change (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (keys : Finset Nat) (history : History n searches.length P) {x : Nat} (member : x ∈ keys) (old : itemColor t lo (searches ++ [searched]) P x = some .purple) : itemValue t lo (searches ++ [searched]) (P ∪ row searches.length keys) x ≤ itemValue t lo (searches ++ [searched]) P x ∧ (itemColor t lo (searches ++ [searched]) (P ∪ row searches.length keys) x = some .red → itemValue t lo (searches ++ [searched]) (P ∪ row searches.length keys) x < itemValue t lo (searches ++ [searched]) P x) := purple_access t lo searches searched keys history member oldModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.DefinitionsThe old purple value is a maximum that includes the current blue value, and the new value is at most that blue value.
Theorem (Lemma 3.11, old blue). If an accessed key was blue, its new value is at most its old one, and strictly smaller if it ends red.
/-- Lemma 3.11: an old blue access cannot gain potential. -/theorem blue_change (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (keys : Finset Nat) (history : History n searches.length P) {x : Nat} (member : x ∈ keys) (old : itemColor t lo (searches ++ [searched]) P x = some .blue) : itemValue t lo (searches ++ [searched]) (P ∪ row searches.length keys) x ≤ itemValue t lo (searches ++ [searched]) P x ∧ (itemColor t lo (searches ++ [searched]) (P ∪ row searches.length keys) x = some .red → itemValue t lo (searches ++ [searched]) (P ∪ row searches.length keys) x < itemValue t lo (searches ++ [searched]) P x) := blue_access t lo searches searched keys history member oldModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.DefinitionsThe old blue value is the current blue value, since Phase I already moved to the current forest.
Theorem (the search separates the neighbors). Let P be a history before time time, and let an active point q of P have row neighbors . If GreedyASS accesses q.1 at time for the request searched, then .
/-- The executable sweep puts the search strictly between an accessed item’s old row neighbors. -/theorem search_interval {n time searched : Nat} {P : Finset Point} (history : History n time P) {q : Point} (active : Active P q) (accessed : q.1 ∈ greedySweep time searched P) {a b : Nat} (left : leftNeighbor P q = some a) (right : rightNeighbor P q = some b) : a < searched ∧ searched < b := search_between history active accessed left rightModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.DefinitionsOtherwise the neighbor’s point, which is in q’s row, would lie in the rectangle between q and the request, and q would not be visible. This is the first observation in the paper’s proof of Lemma 3.12.
Theorem (Lemma 3.12, old red). Let P be a history with keys in the leaf range. If a key accessed by GreedyASS was red, its new value is at most its old one, and strictly smaller if it ends red.
/-- Lemma 3.12, including the searched key and a unit loss for new red accesses. -/theorem red_change (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (history : History n searches.length P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) {x : Nat} (member : x ∈ greedySweep searches.length searched P) (old : itemColor t lo (searches ++ [searched]) P x = some .red) : itemValue t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) x ≤ itemValue t lo (searches ++ [searched]) P x ∧ (itemColor t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) x = some .red → itemValue t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) x < itemValue t lo (searches ++ [searched]) P x) := red_access t lo searches searched history valid member oldModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.DefinitionsBy the previous theorem, the lowest common ancestor of the old row neighbors lies above the subtree containing both x and the search, so the old red value is at least the current blue value. The new value is at most blue, and strictly smaller when red.
Theorem (Lemma 3.9, old green). Let P be arborally satisfied, a history, with keys in the leaf range. If a key accessed by GreedyASS was green, it becomes red and its value decreases by exactly one.
/-- Lemma 3.9 exactly: an accessed green item becomes red and loses one unit. -/theorem green_exact_change (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n searches.length P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) {x : Nat} (member : x ∈ greedySweep searches.length searched P) (old : itemColor t lo (searches ++ [searched]) P x = some .green) : itemColor t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) x = some .red ∧ itemAmount t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) x + 1 = itemAmount t lo (searches ++ [searched]) P x := green_exact t lo searches searched satisfied history valid member oldModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions/-- Lemma 3.9 in its amortized inequality form: an accessed green item loses at least one unit. -/theorem green_change (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n searches.length P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) {x : Nat} (member : x ∈ greedySweep searches.length searched P) (old : itemColor t lo (searches ++ [searched]) P x = some .green) : itemAmount t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) x + 1 ≤ itemAmount t lo (searches ++ [searched]) P x := green_access t lo searches searched satisfied history valid member oldModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.DefinitionsA green key shares its forest root with its two external neighbors, so the search lies outside that root, on one side of all three. The sweep then accesses all three and nothing between them. The new row neighbors of are its old external neighbors, and the new red value is the old green value minus one. Since the search is outside, is not a top corner. The paper also allows the result to be purple. The Lean proof shows it is always red, and green_change is the inequality form used in the accounting.
A key with no earlier access, a first access, has old value . Old points lie in old columns, so a column without points can enter the row only as the request itself. The request’s leaf is a singleton root, and its blue value is .
Theorem (first accesses). If a key accessed by GreedyASS had no earlier access, its old amount is and its new amount at most . Summed over all first-accessed keys of the row, the new amounts plus one unit of actual cost per key are at most per key.
/-- A first access has zero old potential and at most two units of new potential. -/theorem first_access (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (history : History n searches.length P) {x : Nat} (member : x ∈ greedySweep searches.length searched P) (unseen : latest P x = none) : itemAmount t lo (searches ++ [searched]) P x = 0 ∧ itemAmount t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) x ≤ 2 := unseen_amount t lo searches searched history member unseenModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions/-- First-access potential and actual cost are at most three per unseen item. -/theorem first_access_total (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (history : History n searches.length P) : totalAmount t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) (unseenKeys P (greedySweep searches.length searched P)) + (unseenKeys P (greedySweep searches.length searched P)).card ≤ 3 * (unseenKeys P (greedySweep searches.length searched P)).card := unseen_total t lo searches searched historyModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.DefinitionsThe values live in WithTop Nat, because red and green are when a neighbor is missing. The selected value is always finite, so the natural-valued amount is exact:
/-- The natural-valued potential is exactly the finite selected potential. -/theorem amount (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (x : Nat) : itemValue t lo searches P x = WithTop.some (itemAmount t lo searches P x) := amount_exact t lo searches P xModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.DefinitionsThe per-color lemmas combine into a unit credit. The bracket if … then 1 else 0 is one if the key ends red:
Theorem (unit credit). Under the hypotheses of the red lemma, for a key accessed by GreedyASS that was red, blue or purple, the new amount, plus one if it ends red, is at most the old amount. Summed over any such set of keys, the new total plus the number of keys ending red is at most the old total.
/-- Every new red access among old red, blue, and purple items pays one unit. -/theorem charge (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (history : History n searches.length P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) {x : Nat} (member : x ∈ greedySweep searches.length searched P) (old : itemColor t lo (searches ++ [searched]) P x = some .red ∨ itemColor t lo (searches ++ [searched]) P x = some .blue ∨ itemColor t lo (searches ++ [searched]) P x = some .purple) : itemAmount t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) x + (if itemColor t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) x = some .red then 1 else 0) ≤ itemAmount t lo (searches ++ [searched]) P x := unit_credit t lo searches searched history valid member oldModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions/-- Sum the actual item potentials and pay for the resulting red accesses. -/theorem total (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (history : History n searches.length P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) (keys : Finset Nat) (accessed : keys ⊆ greedySweep searches.length searched P) (old : ∀ x ∈ keys, itemColor t lo (searches ++ [searched]) P x = some .red ∨ itemColor t lo (searches ++ [searched]) P x = some .blue ∨ itemColor t lo (searches ++ [searched]) P x = some .purple) : totalAmount t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) keys + (coloredKeys t lo (searches ++ [searched]) (P ∪ row searches.length (greedySweep searches.length searched P)) keys .red).card ≤ totalAmount t lo (searches ++ [searched]) P keys := total_credit t lo searches searched history valid keys accessed oldModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.DefinitionsAdding the green and first-access cases accounts for every point of the row:
Theorem (the whole row). Let P be arborally satisfied, a history before time , with keys in the leaf range, and let keys be the GreedyASS row. Then the number of points of the row plus the new item potential of keys is at most the intermediate item potential of keys, plus the number of keys ending blue, plus the number ending purple, plus per first access.
/-- All accessed items, including first accesses, are included. Only the new blue/purple counts and explicit startup allowance remain. -/theorem whole_row (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n searches.length P) (valid : ∀ q ∈ P, lo ≤ q.1 ∧ q.1 < lo + leaves t) : let keys := greedySweep searches.length searched P let Q := P ∪ row searches.length keys keys.card + totalAmount t lo (searches ++ [searched]) Q keys ≤ totalAmount t lo (searches ++ [searched]) P keys + (coloredKeys t lo (searches ++ [searched]) Q keys .blue).card + (coloredKeys t lo (searches ++ [searched]) Q keys .purple).card + 3 * (unseenKeys P keys).card := row_bound t lo searches searched satisfied history validModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.DefinitionsIn the paper, accessed keys that were blue or purple after Phase I are charged to Lemma 3.1 in Lemma 3.19, even when they end red. The Lean statement pays for those that end red by the strict decrease in the lemmas for old blue and old purple keys, so it charges only the colors after the row.
25.6.5 Phase II: the unaccessed items
Keys not on the new row must not gain potential. Their colors can still change, because the new row changes which points are external or glancing, and which external keys are neighbors.
External keys come first.
Theorem (the row is on one side). Let P be arborally satisfied, a history before time. If an external point q of P is not accessed, every key of the new row lies on the same side of q.1.
/-- Every new access lies on one side of an untouched external item. -/theorem sweep_side {n time searched : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n time P) {q : Point} (external : External P q) (untouched : q.1 ∉ greedySweep time searched P) : (∀ y ∈ greedySweep time searched P, y < q.1) ∨ (∀ y ∈ greedySweep time searched P, q.1 < y) := one_side satisfied history external untouchedModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsTheorem (external neighbors move inward). If x has external neighbors in P, and a new row lies on one side of x, then x still has external neighbors after the row, with .
/-- External neighbors can only move inward when the new row lies on one side. -/theorem neighbor_interval {n time : Nat} {P : Finset Point} (keys : Finset Nat) (history : History n time P) {x a b : Nat} (left : leftExternal P x = some a) (right : rightExternal P x = some b) (side : (∀ y ∈ keys, y < x) ∨ (∀ y ∈ keys, x < y)) : ∃ u v, leftExternal (P ∪ row time keys) x = some u ∧ rightExternal (P ∪ row time keys) x = some v ∧ a ≤ u ∧ u < x ∧ x < v ∧ v ≤ b := neighbors_nested keys history left right sideModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsTheorem (green does not increase). Under a new row on one side of x, the green value of x does not increase.
/-- The green candidate cannot increase under a one-sided later row. -/theorem green_change (t : Tree) (lo : Nat) {n time : Nat} {P : Finset Point} (keys : Finset Nat) (history : History n time P) (x : Nat) (side : (∀ y ∈ keys, y < x) ∨ (∀ y ∈ keys, x < y)) : green t lo (P ∪ row time keys) x ≤ green t lo P x := green_mono t lo keys history x sideModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsCloser neighbors have a lower common ancestor, so the distance from x to it does not grow (the paper’s Fact 3.1).
Theorem (Lemma 3.13). Let P be arborally satisfied, a history before time. The value of an unaccessed external point does not increase when the GreedyASS row is added. This includes former top corners, which change from blue to the minimum of green and blue. The same holds for the natural-valued amount of its key, and for the sum over any set of unaccessed external keys.
/-- Lemma 3.13, including old top corners: an untouched external point cannot gain potential. -/theorem external_point (t : Tree) (lo : Nat) (searches : List Nat) {n time searched : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n time P) {q : Point} (external : External P q) (untouched : q.1 ∉ greedySweep time searched P) : value t lo searches (P ∪ row time (greedySweep time searched P)) q ≤ value t lo searches P q := external_value t lo searches satisfied history external untouchedModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions/-- Lemma 3.13 for the natural-valued latest-item query. -/theorem external_change (t : Tree) (lo : Nat) (searches : List Nat) {n time searched : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n time P) {q : Point} (external : External P q) (untouched : q.1 ∉ greedySweep time searched P) : itemAmount t lo searches (P ∪ row time (greedySweep time searched P)) q.1 ≤ itemAmount t lo searches P q.1 := external_amount t lo searches satisfied history external untouchedModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions/-- Sum the external-item nonincrease over any untouched subset. -/theorem external_sum (t : Tree) (lo : Nat) (searches : List Nat) {n time searched : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n time P) (keys : Finset Nat) (external : keys ⊆ externalKeys P) (untouched : ∀ x ∈ keys, x ∉ greedySweep time searched P) : totalAmount t lo searches (P ∪ row time (greedySweep time searched P)) keys ≤ totalAmount t lo searches P keys := external_total t lo searches satisfied history keys external untouchedModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsThese three statements use one search list on both sides, so the forest, and therefore blue, is fixed. Only the geometry changes.
The other unaccessed keys are glancing or internal, and their row neighbors do not change. A red key stays red:
Theorem (Lemmas 3.14 and 3.17, red). If an unaccessed key is red, it is still red after any new row, with the same amount. This includes a glancing key that becomes internal.
/-- An untouched red item keeps its color and amount, including glancing-to-internal changes. -/theorem red_unchanged (t : Tree) (lo : Nat) (searches : List Nat) {n time : Nat} {P : Finset Point} (keys : Finset Nat) (history : History n time P) {x : Nat} (colored : itemColor t lo searches P x = some .red) (untouched : x ∉ keys) : itemColor t lo searches (P ∪ row time keys) x = some .red ∧ itemAmount t lo searches (P ∪ row time keys) x = itemAmount t lo searches P x := red_amount t lo searches keys history colored untouchedModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsA purple glancing key can become internal, and internal keys are always red. The paper’s Lemma 3.16 shows that this cannot raise its value: the red value is at most the purple value. The library proves this for every internal point of a GreedyASS history:
Theorem (Lemma 3.16, purple covers red). Let searches be any request list and P its GreedyASS points. For every internal point q of P, its red value is at most its purple value: the largest blue value over the searches since q’s row.
/-- Historical purple covers red for every internal point of an actual greedy history; this supplies Lemma 3.16. -/theorem internal_cover (t : Tree) (lo : Nat) (searches : List Nat) {n : Nat} (valid : ∀ y ∈ searches, y < n) {q : Point} (internal : Internal (Virgin.points searches) q) : red t lo (Virgin.points searches) q ≤ WithTop.some (purple t lo searches q.2 q.1) := internal_purple t lo searches valid internalModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsFor an internal point, there have been searches on both sides since its last access, and the closest ones are at least as far out as its row neighbors. Let be the lowest common ancestor of the two closest searches, and the child of containing the key. At the time of the later of the two searches, was a root of the forest. The blue value at that time is the distance to , which is at least the red value. The hypothesis valid only asks that the requests are bounded by some n, and n is arbitrary, so it holds for every list.
Theorem (Lemma 3.17). Let searches ++ [searched] be bounded requests. Every active, non-external point of the GreedyASS points of searches whose key is not in the next row has a value that does not increase when the row is added, with the search list searches ++ [searched] on both sides.
/-- Lemma 3.17, including glancing-to-internal changes. -/theorem nonexternal_change (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} (valid : ∀ y ∈ searches ++ [searched], y < n) {q : Point} (active : Active (Virgin.points searches) q) (nonexternal : ¬ External (Virgin.points searches) q) (untouched : q.1 ∉ Virgin.keys searches searched) : value t lo (searches ++ [searched]) (Virgin.points (searches ++ [searched])) q ≤ value t lo (searches ++ [searched]) (Virgin.points searches) q := nonexternal_value t lo searches searched valid active nonexternal untouchedModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsCombining the cases, and adding the keys never accessed, which stay at :
Theorem (every unaccessed key). For bounded requests, every key not on the next GreedyASS row has a natural-valued amount that does not increase when the row is added. The same holds for the sum over any set of such keys.
/-- Every untouched item has nonincreasing natural-valued potential, including unseen columns. -/theorem untouched_change (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} (valid : ∀ y ∈ searches ++ [searched], y < n) {x : Nat} (untouched : x ∉ Virgin.keys searches searched) : itemAmount t lo (searches ++ [searched]) (Virgin.points (searches ++ [searched])) x ≤ itemAmount t lo (searches ++ [searched]) (Virgin.points searches) x := all_amount t lo searches searched valid untouchedModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions/-- Sum the complete unaccessed contribution to Phase II. -/theorem untouched_sum (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} (valid : ∀ y ∈ searches ++ [searched], y < n) (keys : Finset Nat) (untouched : ∀ x ∈ keys, x ∉ Virgin.keys searches searched) : totalAmount t lo (searches ++ [searched]) (Virgin.points (searches ++ [searched])) keys ≤ totalAmount t lo (searches ++ [searched]) (Virgin.points searches) keys := all_total t lo searches searched valid keys untouchedModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions25.6.6 At most six blue or purple items per root
The accessed keys that end blue or purple are not paid for by their own potential. They are paid for by virgin potential, and that works because there are few of them in each root of the forest. This is the paper’s Lemma 3.1. The library counts per component:
/-- Actual purple items contained in one reference component. -/def purpleKeys (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (c : Reference.Component) : Finset Nat := (P.image Prod.fst).filter fun x => c.Contains x ∧ itemColor t lo searches P x = some .purpledef blueKeys (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (c : Reference.Component) : Finset Nat := (P.image Prod.fst).filter fun x => c.Contains x ∧ itemColor t lo searches P x = some .bluedef leftBlueKeys (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (c : Reference.Component) : Finset Nat := (P.filter fun q => c.Contains q.1 ∧ Items.LeftExternal P q ∧ color t lo searches P q = some .blue).image Prod.fstdef rightBlueKeys (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (c : Reference.Component) : Finset Nat := (P.filter fun q => c.Contains q.1 ∧ Items.RightExternal P q ∧ color t lo searches P q = some .blue).image Prod.fstpurpleKeys and blueKeys are the columns of P inside the component c whose item color is purple or blue. leftBlueKeys and rightBlueKeys keep only the blue points that are left or right external. A blue item is always external, and a purple one is always glancing:
Theorem (where blue and purple items are). If a key is purple, its most recent point is active, glancing and purple. If it is blue, its most recent point is active, external and blue.
theorem locations (t : Tree) (lo : Nat) (searches : List Nat) (P : Finset Point) (x : Nat) : (itemColor t lo searches P x = some .purple → ∃ stamp, Active P (x, stamp) ∧ Glancing P (x, stamp) ∧ color t lo searches P (x, stamp) = some .purple) ∧ (itemColor t lo searches P x = some .blue → ∃ stamp, Active P (x, stamp) ∧ External P (x, stamp) ∧ color t lo searches P (x, stamp) = some .blue) := ⟨purple_point t lo searches P x, blue_point t lo searches P x⟩Models.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.Counting.DefinitionsThe counting rests on two bracketing facts and two “middle” lemmas.
Theorem (brackets). In an arborally satisfied P, if three glancing points have keys , then the row neighbors of exist and lie in . If and are external, then the external neighbors of any key strictly between them exist and lie in .
theorem glancing_neighbors {P : Finset Point} (satisfied : ASS P) {p q r : Point} (left : Glancing P p) (middle : Glancing P q) (right : Glancing P r) (pq : p.1 < q.1) (qr : q.1 < r.1) : ∃ a b, leftNeighbor P q = some a ∧ rightNeighbor P q = some b ∧ p.1 ≤ a ∧ a < q.1 ∧ q.1 < b ∧ b ≤ r.1 := bracket satisfied left middle right pq qrModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.Counting.Definitionstheorem external_neighbors {P : Finset Point} {p q r : Point} (left : External P p) (right : External P r) (pq : p.1 < q.1) (qr : q.1 < r.1) : ∃ a b, leftExternal P q.1 = some a ∧ rightExternal P q.1 = some b ∧ p.1 ≤ a ∧ a < q.1 ∧ q.1 < b ∧ b ≤ r.1 := external_bracket left right pq qrModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.Counting.DefinitionsTheorem (the middle one is red, or green). Let be a root of the forest of searched, and color with the search list searches ++ [searched]. If P is arborally satisfied and a history before time , then among three glancing points with keys in , the middle one is red. Among three external points with keys in , the middle one is green, provided it is not in the latest row.
theorem red_middle (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n (searches.length + 1) P) {c : Component} (component : c ∈ forest t lo searched) {p q r : Point} (left : Glancing P p) (middle : Glancing P q) (right : Glancing P r) (insideP : c.Contains p.1) (insideQ : c.Contains q.1) (insideR : c.Contains r.1) (pq : p.1 < q.1) (qr : q.1 < r.1) : color t lo (searches ++ [searched]) P q = some .red := middle_red t lo searches searched satisfied history component left middle right insideP insideQ insideR pq qrModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.Counting.Definitionstheorem green_middle (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {P : Finset Point} {c : Component} (component : c ∈ forest t lo searched) {p q r : Point} (left : External P p) (middle : External P q) (right : External P r) (insideP : c.Contains p.1) (insideQ : c.Contains q.1) (insideR : c.Contains r.1) (pq : p.1 < q.1) (qr : q.1 < r.1) (notTop : ¬ LatestRow P q.2) : color t lo (searches ++ [searched]) P q = some .green := middle_green t lo searches searched component left middle right insideP insideQ insideR pq qr notTopModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.Counting.DefinitionsThe bracket puts the lowest common ancestor of the middle point’s neighbors at or below the lowest common ancestor of the outer two, by the nesting of lowest common ancestors (the paper’s Fact 3.1). The outer two are in , so that ancestor is inside , and red is strictly less than blue, which is at most purple; for external points, green is at most blue. The color rule then picks red, or green. The green half needs neither satisfaction nor the history hypothesis. Its exclusion of the latest row is necessary, since top corners are blue by definition.
Theorem (two per direction). If P is arborally satisfied and a history before time , then each root of the forest of searched contains at most two left-external and at most two right-external blue items.
theorem directional (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n (searches.length + 1) P) {c : Component} (component : c ∈ forest t lo searched) : (leftBlueKeys t lo (searches ++ [searched]) P c).card ≤ 2 ∧ (rightBlueKeys t lo (searches ++ [searched]) P c).card ≤ 2 := ⟨left_blue_count t lo searches searched satisfied history component, right_blue_count t lo searches searched satisfied history component⟩Models.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.Counting.DefinitionsAmong three left-external blue points in one root, the middle one has a left-external point to its right. Arboral satisfaction then keeps it out of the latest row, so it is not a top corner, and by the previous theorem it is green, a contradiction. Right-external points are symmetric. Since every blue item is external, this gives at most four blue items per root.
Theorem (Lemma 3.1). Let P be arborally satisfied, a history before time . Every root of the forest of searched contains at most blue and purple items, colored with the search list searches ++ [searched]. The same holds for the intermediate colors, with P a history before time .
/-- Lemma 3.1, including top corners and the actual historical purple values. -/theorem counts (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n (searches.length + 1) P) {c : Component} (component : c ∈ forest t lo searched) : (blueKeys t lo (searches ++ [searched]) P c).card ≤ 4 ∧ (purpleKeys t lo (searches ++ [searched]) P c).card ≤ 2 := ⟨blue_count t lo searches searched satisfied history component, purple_count t lo searches searched satisfied history component⟩Models.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.Counting.Definitions/-- The same bounds hold after changing forests but before adding the row. -/theorem intermediate (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) {n : Nat} {P : Finset Point} (satisfied : ASS P) (history : History n searches.length P) {c : Component} (component : c ∈ forest t lo searched) : (blueKeys t lo (searches ++ [searched]) P c).card ≤ 4 ∧ (purpleKeys t lo (searches ++ [searched]) P c).card ≤ 2 := counts t lo searches searched satisfied (fun p hp => ⟨(history p hp).1, Nat.lt_succ_of_lt (history p hp).2⟩) componentModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Potential.Counting.DefinitionsThe paper’s statement does not mention top corners. The Lean statement covers them, since they are blue items and are included in blueKeys, and it uses the actual historical purple values.
25.6.7 Phase II assembled
Phase II has three parts: the accessed keys, the unaccessed keys, and the virgin roots. The statements now use the actual GreedyASS histories: Virgin.points searches before the row, Virgin.points (searches ++ [searched]) after it, and the row Virgin.keys searches searched.
Theorem (all items). Let searches ++ [searched] be requests in the leaf range, and let the domain contain the new row. Then the number of points of the row plus the new item potential is at most the intermediate item potential, plus the number of row keys ending blue or purple, plus per first access.
/-- The total item potential includes both accessed and untouched keys. -/theorem items (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) (valid : ∀ x ∈ searches ++ [searched], lo ≤ x ∧ x < lo + leaves t) (domain : Finset Nat) (covers : Virgin.keys searches searched ⊆ domain) : let keys := Virgin.keys searches searched let Q := Virgin.points (searches ++ [searched]) keys.card + totalAmount t lo (searches ++ [searched]) Q domain ≤ totalAmount t lo (searches ++ [searched]) (Virgin.points searches) domain + (coloredKeys t lo (searches ++ [searched]) Q keys .blue).card + (coloredKeys t lo (searches ++ [searched]) Q keys .purple).card + 3 * (unseenKeys (Virgin.points searches) keys).card := PhaseTwo.items t lo searches searched valid domain coversModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsTheorem (six per touched root). The number of row keys ending blue or purple is at most times the number of roots of the forest of searched whose interval contains a key of the row (Virgin.touched).
/-- At most six blue or purple new accesses per touched reference root. -/theorem colors (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) (valid : ∀ x ∈ searches ++ [searched], lo ≤ x ∧ x < lo + leaves t) : (coloredKeys t lo (searches ++ [searched]) (Virgin.points (searches ++ [searched])) (Virgin.keys searches searched) .blue).card + (coloredKeys t lo (searches ++ [searched]) (Virgin.points (searches ++ [searched])) (Virgin.keys searches searched) .purple).card ≤ 6 * (Virgin.touched t lo searches searched).card := PhaseTwo.color_counts t lo searches searched validModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsThe virgin side is Results.decrease from Section 25.5, the paper’s Lemmas 3.7 and 3.8. At most two touched roots are not virgins, and every other touched root loses its units. So the virgin potential after the row plus per touched root is at most the virgin potential before it plus . Since per touched root suffices for the colors, the bound has slack. The Lean accounting charges only the colors after the row, while the paper’s Lemma 3.19 also charges the colors before it, which needs the full .
Theorem (Phase II, Lemma 3.18). Let searches ++ [searched] be requests in the leaf range. On any domain containing the row, and in particular on all keys below lo + leaves t: the number of points of the row, plus the new item potential, plus the remaining virgin potential, is at most the intermediate item potential plus the virgin potential of the forest of searched, plus , plus per first access.
/-- The Phase-II bound on any finite domain containing the accessed row. -/theorem domain_bound (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) (valid : ∀ x ∈ searches ++ [searched], lo ≤ x ∧ x < lo + leaves t) (domain : Finset Nat) (covers : Virgin.keys searches searched ⊆ domain) : (Virgin.keys searches searched).card + totalAmount t lo (searches ++ [searched]) (Virgin.points (searches ++ [searched])) domain + Virgin.after t lo searches searched ≤ totalAmount t lo (searches ++ [searched]) (Virgin.points searches) domain + Virgin.before t lo searches searched + 24 + 3 * (unseenKeys (Virgin.points searches) (Virgin.keys searches searched)).card := PhaseTwo.bound t lo searches searched valid domain coversModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions/-- Complete Phase-II amortization on the full key universe; first accesses retain their explicit allowance. -/theorem step (t : Tree) (lo : Nat) (searches : List Nat) (searched : Nat) (valid : ∀ x ∈ searches ++ [searched], lo ≤ x ∧ x < lo + leaves t) : (Virgin.keys searches searched).card + totalAmount t lo (searches ++ [searched]) (Virgin.points (searches ++ [searched])) (Finset.range (lo + leaves t)) + Virgin.after t lo searches searched ≤ totalAmount t lo (searches ++ [searched]) (Virgin.points searches) (Finset.range (lo + leaves t)) + Virgin.before t lo searches searched + 24 + 3 * (unseenKeys (Virgin.points searches) (Virgin.keys searches searched)).card := PhaseTwo.step t lo searches searched validModels.Rotation, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.DefinitionsOn the full domain, the left side is and the right side is .
25.6.8 One row, a whole stream, and the theorem
The two phases combine into the amortized cost of one row.
Theorem (Lemma 3.19). Let prior ++ [old] ++ [next] be requests in the leaf range, and let row be GreedyASS’s row for next. Writing for potential t lo h,
where is the number of keys of the row that have never been accessed.
/-- Lemma 3.19 with explicit charges for previously unseen columns. -/theorem step (t : Tree) (lo : Nat) (prior : List Nat) (old next : Nat) (valid : ∀ x ∈ (prior ++ [old]) ++ [next], lo ≤ x ∧ x < lo + leaves t) : (Virgin.keys (prior ++ [old]) next).card + potential t lo ((prior ++ [old]) ++ [next]) ≤ potential t lo (prior ++ [old]) + 24 * Transitions.edges t lo old next + 24 + 3 * (unseenKeys (Virgin.points (prior ++ [old])) (Virgin.keys (prior ++ [old]) next)).card := Amortized.step t lo prior old next validModels.Rotation, Models.Online, Models.Pointer.Machine, Models.Pointer.Lazy.Online.Definitions, Models.Pointer.Lazy.Online.Algorithm, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions, Algorithms.GreedyASS.Potential.Amortized.DefinitionsThis is the paper’s , with replaced by , and with first accesses charged explicitly. The is exactly times the contribution of the request next to referenceCost.
The first row is different: there is no previous search and no Phase I. Its forest is new, and each of its at most roots may carry units of virgin potential, so the first row is charged at most (internally Amortized.startup). Summing over the rows:
Theorem (whole stream). For every sequence xs of requests in the leaf range, the number of GreedyASS points plus the final potential is at most
/-- The exact whole-stream accounting retains final potential and chargesonly distinct encountered columns, with startup paid once. -/theorem stream (t : Tree) (lo : Nat) (xs : List Nat) (valid : ∀ x ∈ xs, lo ≤ x ∧ x < lo + leaves t) : (Virgin.points xs).card + potential t lo xs ≤ 12 * leaves t + 24 * referenceCost t lo xs + 3 * ((Virgin.points xs).image Prod.fst).card := Amortized.stream t lo xs validModels.Rotation, Models.Online, Models.Pointer.Machine, Models.Pointer.Lazy.Online.Definitions, Models.Pointer.Lazy.Online.Algorithm, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions, Algorithms.GreedyASS.Potential.Amortized.DefinitionsThe statement keeps the final potential on the left and charges first accesses by the number of distinct columns, (Virgin.points xs).image Prod.fst. Every column with a point was accessed for the first time exactly once, so the per-row charges add up to three per column. The startup is paid once.
Since the final potential is a natural number and every column is a leaf of , the stream bound gives the headline:
Theorem (Theorem 3.1, geometric form). For every leaf-oriented reference tree with leaves lo, …, lo + leaves t - 1 and every sequence xs of such leaves, the number of points GreedyASS adds from the empty history is at most .
/-- Theorem 3.1 for the actual geometric sweep: twenty-four times thenode-counted leaf-reference benchmark, plus fifteen per reference leaf. -/theorem cost (t : Tree) (lo : Nat) (xs : List Nat) (valid : ∀ x ∈ xs, lo ≤ x ∧ x < lo + leaves t) : rowCost greedySweep 0 ∅ xs ≤ 24 * referenceCost t lo xs + 15 * leaves t := Amortized.cost t lo xs validModels.Rotation, Models.Online, Models.Pointer.Machine, Models.Pointer.Lazy.Online.Definitions, Models.Pointer.Lazy.Online.Algorithm, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions, Algorithms.GreedyASS.Potential.Amortized.DefinitionsrowCost greedySweep 0 ∅ xs is the actual sweep of Section 25.1, run from time on an empty history, counting every point added, requests included. The bound holds for every , so it holds for the minimizing one.
The simulation of Section 25.2 turns the bound into one on binary search trees. Its normalized form, Results.normalized_simulation, gives one online BST algorithm with total cost at most points from every initial tree on keys. With and offset , the constants are and .
Theorem (Theorem 3.1, BST form). For every there is an online BST algorithm such that for every initial tree on keys, every reference tree with leaves, and every sequence of keys less than , the total cost (rotations plus one per request) is at most .
/-- One BST policy works simultaneously for all leaf-oriented references.Its normalized cost includes requests, rotations, and initialization. -/theorem bst (n : Nat) : ∃ algorithm : Algorithm, ∀ initial : Tree, initial.size = n → ∀ reference : Tree, leaves reference = n → ∀ xs : List Nat, (∀ x ∈ xs, x < n) → algorithm.totalCost initial xs ≤ 144456 * referenceCost reference 0 xs + 96303 * n := Amortized.bst nModels.Rotation, Models.Online, Models.Pointer.Machine, Models.Pointer.Lazy.Online.Definitions, Models.Pointer.Lazy.Online.Algorithm, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions, Algorithms.GreedyASS.Potential.Amortized.Definitions- One algorithm for all references.
∃ algorithmcomes before∀ initialand∀ reference. The algorithm is the simulation of GreedyASS, which never looks at a reference tree. A single algorithm therefore meets the bound for every simultaneously, which is what the paper’s requires. - Two different trees.
initialis an ordinary BST with nodes (initial.size = n), where the algorithm runs.referenceis read as leaf-oriented, with leaves (leaves reference = n) and internal nodes, and it only enters the bound. - Cost model.
Algorithm.totalCostis rotations plus one per request (Chapter 5). The term includes the simulation’s startup and the of the geometric bound.
The pointer-machine version composes the geometric bound with Results.pointer_simulation, whose constants are per point and per key: and .
Theorem (Theorem 3.1, pointer form). For every there is an online BST algorithm such that for every initial tree on keys, every reference tree with leaves, and every sequence of keys less than , its pointer-machine run is a legal pointer execution serving the sequence, at a cost of at most instructions.
/-- Actual pointer execution with the same quantifier order and a singlelinear initialization allowance. The simulation constants are not sharp. -/theorem pointer (n : Nat) : ∃ algorithm : Algorithm, ∀ initial : Tree, initial.size = n → ∀ reference : Tree, leaves reference = n → ∀ xs : List Nat, (∀ x ∈ xs, x < n) → Pointer.Execution initial xs (Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial initial) xs).1.current (Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial initial) xs).2 ∧ (Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial initial) xs).2 ≤ 4622232 * referenceCost reference 0 xs + 3081471 * n := Amortized.pointer nModels.Rotation, Models.Online, Models.Pointer.Machine, Models.Pointer.Lazy.Online.Definitions, Models.Pointer.Lazy.Online.Algorithm, Models.Geometric.Definitions, Models.Geometric.Online, Models.Geometric.Offline, Algorithms.GreedyASS.Algorithm, Algorithms.GreedyASS.Items.Definitions, Algorithms.GreedyASS.Reference.Definitions, Algorithms.GreedyASS.Reference.Distance.Definitions, Algorithms.GreedyASS.Reference.Transitions.Definitions, Algorithms.GreedyASS.Potential.Definitions, Algorithms.GreedyASS.Virgin.Definitions, Algorithms.GreedyASS.Potential.Amortized.DefinitionsAs in Section 25.2, the three occurrences of Pointer.Lazy.Online.run algorithm [] (Pointer.Lazy.Online.initial initial) xs are one term: the final pointer state and its accumulated cost. The first conjunct says that the instructions form a Pointer.Execution serving xs from initial, and the second bounds their number.
25.6.9 What the formalization adds
The Lean proof follows the paper’s structure closely. It differs in a few places where the paper is informal or slightly loose.
The paper’s proof of Theorem 3.1 says that the initial potential is zero and that the potential is always nonnegative. Two charges are left implicit there. First, the forest of the first search has up to roots, all virgin, with units each, and nothing pays for them in Lemma 3.19 at . Second, Lemmas 3.9–3.12 classify accessed keys by their color after Phase I, but a key accessed for the first time has no color. The Lean proof charges per leaf for the first forest and per key for first accesses: one unit for the point, at most two for the new potential. Together these give the term. Both are , which the paper’s bound allows.
The paper’s counts nodes. Phase I really performs one split or merge per edge of the path, so the Lean bound has where the paper has . With the of Phase II, the amortized cost of a row is , which is times the row’s contribution to referenceCost.
An accessed green item always becomes red (Results.green_exact_change), where the paper also allows purple. Lemma 3.16 is proved for every internal point of a GreedyASS history, not only for keys that were glancing just before (Results.internal_cover). The Phase II accounting charges blue and purple colors only after the row, so of the virgin units per touched root suffice there.
Where the proofs are
Phase I is in Algorithms/GreedyASS/Potential/PhaseOne/ (values on cuts, the six-key count, single events, traces, and the plan). The accessed-item lemmas are in Accessed/ (one file per color, plus the row accounting and the first accesses), and the unaccessed ones are in the proof files behind Unaccessed/Abstract.lean. The counting is in Counting/{Blue,Purple,External,Geometry}.lean. Phase II is in PhaseTwo/, and the summation, the startup and the composition with the simulation are in Amortized/{Step,Startup,Stream,Simulation}.lean. None of these proof files is part of the reading interface.