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

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 2424 times the reference distance between the two searches, plus 2424, 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.

GreedyASS is within a constant factor of every leaf-oriented lazy finger

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

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

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

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

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

points in total.

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

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

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

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

The Lean statements
theoremGeometric.GreedyASS.Potential.Amortized.Results.costpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Amortized/Abstract.lean:26
/-- 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 valid
theoremGeometric.GreedyASS.Potential.Amortized.Results.bstpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Amortized/Abstract.lean:33
/-- 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 n
theoremGeometric.GreedyASS.Potential.Amortized.Results.pointerpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Amortized/Abstract.lean:43
/-- 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 n
35 definitions in 9 chapters · reading list

The paper states the bound as O(min⁡T∑idT(si−1,si)+n)O\bigl(\min_T \sum_i d_T(s_{i-1}, s_i) + n\bigr). The Lean statements hold for every reference tree TT at once, with explicit constants. In the BST and pointer forms the algorithm is chosen before TT, so the minimum over TT follows. None of the constants is meant to be sharp. The 15L15L 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 TT and write s1,…,sms_1, \dots, s_m for the requests. At time ii, the reference forest FiF_i is TT with the proper ancestors of the leaf sis_i removed (Reference.forest, Section 25.4). Its roots are the siblings of the nodes on the path from the root of TT down to sis_i, together with the leaf sis_i itself.

The potential Φi\Phi_i after row ii 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 TT 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 00.
  • Virgin potential. Each root of the current forest carries 1212 if no key in its interval has been accessed since it became a root, and 00 otherwise.

The amortized cost of row ii is the number of points it adds, ∣Rowi∣|\mathrm{Row}_i|, plus Φi−Φi−1\Phi_i - \Phi_{i-1}. The proof bounds it in two phases, separated by an intermediate potential Φi′\Phi'_i. This is the potential computed with the new forest FiF_i but the old point set Pi−1P_{i-1}.

  1. Phase I (Φi−1→Φi′\Phi_{i-1} \to \Phi'_i): the forest changes from Fi−1F_{i-1} to FiF_i while the points stay fixed. The change is a sequence of merges up from si−1s_{i-1} to the lowest common ancestor of si−1s_{i-1} and sis_i, followed by splits down to sis_i: one event per edge of the path. Each event raises the potential by at most 2424. So Φi′≤Φi−1+24 eT(si−1,si)\Phi'_i \le \Phi_{i-1} + 24\,e_T(s_{i-1}, s_i).
  2. Phase II (Φi′→Φi\Phi'_i \to \Phi_i): the row is added while the forest stays FiF_i. 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 33 each. The remaining accessed keys end blue or purple, and there are at most 66 of them in each root touched by the row. Every touched root except at most two loses its 1212 units of virgin potential. Untouched keys never gain. So ∣Rowi∣+Φi≤Φi′+24+3ui|\mathrm{Row}_i| + \Phi_i \le \Phi'_i + 24 + 3u_i, where uiu_i is the number of keys accessed for the first time.
  3. Summation. The two phases give ∣Rowi∣+Φi≤Φi−1+24 (eT(si−1,si)+1)+3ui|\mathrm{Row}_i| + \Phi_i \le \Phi_{i-1} + 24\,(e_T(s_{i-1},s_i) + 1) + 3u_i for each row after the first. The first row has no Phase I; it starts from the virgin potential of F1F_1, at most 12L12L. The sum telescopes. The uiu_i count distinct keys, so they add up to at most LL. Since Φm≥0\Phi_m \ge 0, the total number of points is at most 24 RT(X)+15L24\,R_T(X) + 15L.

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 2424 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 TT. Between two consecutive requests, the finger walks the path between their leaves.

defGeometric.GreedyASS.Potential.Amortized.edgeCostno axiomsAlgorithms/GreedyASS/Potential/Amortized/Definitions/Abstract.lean:11
/-- 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)
defGeometric.GreedyASS.Potential.Amortized.referenceCostno axiomsAlgorithms/GreedyASS/Potential/Amortized/Definitions/Abstract.lean:18
/-- 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 xs

edgeCost 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 00 when x=yx = y. 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 dTd_T counts nodes, dT=eT+1d_T = e_T + 1, and

referenceCost  t  ℓ  X  =  m+∑i=2meT(xi−1,xi)  =  1+∑i=2mdT(xi−1,xi)(m≥1).\texttt{referenceCost}\;t\;\ell\;X \;=\; m + \sum_{i=2}^m e_T(x_{i-1},x_i) \;=\; 1 + \sum_{i=2}^m d_T(x_{i-1},x_i) \qquad (m \ge 1).

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 TT, which is less than LL, 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:

defGeometric.GreedyASS.Potential.Amortized.potentialpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Amortized/Definitions/Abstract.lean:23
/-- 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 last

The 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 00, 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 1212 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 00.

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 TT into subtrees (Transitions.Cut).

defGeometric.GreedyASS.Potential.PhaseOne.rootBlueno axiomsAlgorithms/GreedyASS/Potential/PhaseOne/Definitions/Abstract.lean:10
/-- 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 x

rootBlue 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 Blue(x)=d(x,r(x))+1\mathrm{Blue}(x) = d(x, r(x)) + 1 for that cut. On a search forest it is the existing blue value:

Theorem (cut blue agrees with blue). For every leaf xx of TT and every search ss, rootBlue on the forest of ss equals Potential.blue t lo s x.

Given 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:

defGeometric.GreedyASS.Potential.PhaseOne.selectpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Definitions/Abstract.lean:16
/-- 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 q

An inactive point has value 00. A top corner, an external point in the latest row, has value b. Another external point has min⁡(green,b)\min(\mathrm{green}, b): green when green is at most blue, as the color rule says, and blue otherwise. A glancing point has min⁡(red,max⁡(purple,b))\min(\mathrm{red}, \max(\mathrm{purple}, b)), 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.

defGeometric.GreedyASS.Potential.PhaseOne.valueAtpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Definitions/Abstract.lean:26
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)
defGeometric.GreedyASS.Potential.PhaseOne.itemAtpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Definitions/Abstract.lean:30
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)
defGeometric.GreedyASS.Potential.PhaseOne.amountAtpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Definitions/Abstract.lean:36
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 0
defGeometric.GreedyASS.Potential.PhaseOne.totalAtpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Definitions/Abstract.lean:39
def 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 x

valueAt applies select with the candidate rootBlue roots q.1. itemAt applies it to a key’s most recent access, or gives 00 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 ∞\infty into 00. 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.

The two ends of Phase I are the two potentials it connects.

Theorem (initial cut). If P is a history before time ∣prior∣+1|prior| + 1 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].

Theorem (final cut). If P is a history before time ∣searches∣|searches| 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.

theoremGeometric.GreedyASS.Potential.PhaseOne.Results.finalpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Abstract.lean:27
/-- 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 domain

In 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:

defGeometric.GreedyASS.Potential.PhaseOne.Sensitivepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Definitions/Abstract.lean:43
/-- 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)
instanceGeometric.GreedyASS.Potential.PhaseOne.instDecidableSensitivepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Definitions/Abstract.lean:49
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.

defGeometric.GreedyASS.Potential.PhaseOne.chargedKeyspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Definitions/Abstract.lean:53
/-- 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.fst

chargedKeys 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 cc of TT and every arborally satisfied P, at most 66 columns are charged.

The 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 TT, whose parent component is a subtree of TT, increases totalAt by nothing if it is a split, and by at most 1212 if it is a merge.

theoremGeometric.GreedyASS.Potential.PhaseOne.Results.local_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Abstract.lean:40
/-- 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 domain

A merge joins two components, each with at most 66 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 TT. step is the local rewrite, and admissible says the parent of the event occurs in TT. Two adjacent intervals are not enough for a merge: they must be siblings in TT.

Theorem (any trace). Along a certified trace of splits and merges from a cut, totalAt increases by at most 1212 per merge.

theoremGeometric.GreedyASS.Potential.PhaseOne.Results.trace_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Abstract.lean:50
/-- 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 domain

Theorem (the plan). If P is arborally satisfied, is a history before time ∣prior∣+1|prior| + 1, and has keys in the leaf range, then the intermediate item potential exceeds the item potential of prior ++ [old] by at most 1212 times the number of merges in Transitions.plan t lo old next.

theoremGeometric.GreedyASS.Potential.PhaseOne.Results.items_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Abstract.lean:59
/-- 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 domain

The 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 eT(old,next)e_T(old, next) 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 1212 each, and a merge creates one. So the virgin potential grows by at most 2424 per split and 1212 per merge, and the remaining 1212 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 24 eT(old,next)24\,e_T(old, next).

theoremGeometric.GreedyASS.Potential.PhaseOne.Results.steppropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseOne/Abstract.lean:67
/-- 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 domain

The left side is Φi′\Phi'_i and the right side is Φi−1+24 eT(si−1,si)\Phi_{i-1} + 24\,e_T(s_{i-1}, s_i). 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 24 dT24\,d_T, counting nodes. The Lean bound, 24 eT24\,e_T, 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 ∣searches∣|searches| (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.

theoremGeometric.GreedyASS.Potential.Accessed.Results.new_accesspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:10
/-- 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 member

For 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.

theoremGeometric.GreedyASS.Potential.Accessed.Results.purple_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:33
/-- 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 old

The 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.

theoremGeometric.GreedyASS.Potential.Accessed.Results.blue_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:21
/-- 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 old

The 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 a<q.1<ba < q.1 < b. If GreedyASS accesses q.1 at time for the request searched, then a<searched<ba < \texttt{searched} < b.

theoremGeometric.GreedyASS.Potential.Accessed.Results.search_intervalpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:58
/-- 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 right

Otherwise 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.

theoremGeometric.GreedyASS.Potential.Accessed.Results.red_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:45
/-- 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 old

By 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.

theoremGeometric.GreedyASS.Potential.Accessed.Results.green_exact_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:144
/-- 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 old
theoremGeometric.GreedyASS.Potential.Accessed.Results.green_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:120
/-- 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 old

A green key xx 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 xx are its old external neighbors, and the new red value is the old green value minus one. Since the search is outside, xx 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 00. 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 22.

Theorem (first accesses). If a key accessed by GreedyASS had no earlier access, its old amount is 00 and its new amount at most 22. Summed over all first-accessed keys of the row, the new amounts plus one unit of actual cost per key are at most 33 per key.

theoremGeometric.GreedyASS.Potential.Accessed.Results.first_accesspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:101
/-- 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 unseen
theoremGeometric.GreedyASS.Potential.Accessed.Results.first_access_totalpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:110
/-- 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 history

The values live in WithTop Nat, because red and green are ∞\infty when a neighbor is missing. The selected value is always finite, so the natural-valued amount is exact:

The 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.

theoremGeometric.GreedyASS.Potential.Accessed.Results.chargepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:71
/-- 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 old
theoremGeometric.GreedyASS.Potential.Accessed.Results.totalpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:86
/-- 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 old

Adding 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 ∣searches∣|searches|, 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 33 per first access.

theoremGeometric.GreedyASS.Potential.Accessed.Results.whole_rowpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Accessed/Abstract.lean:131
/-- 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 valid

In 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.

theoremGeometric.GreedyASS.Potential.Unaccessed.Results.sweep_sidepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:10
/-- 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 untouched

Theorem (external neighbors move inward). If x has external neighbors a<x<ba < x < b in P, and a new row lies on one side of x, then x still has external neighbors u,vu, v after the row, with a≤u<x<v≤ba \le u < x < v \le b.

theoremGeometric.GreedyASS.Potential.Unaccessed.Results.neighbor_intervalpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:18
/-- 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 side

Theorem (green does not increase). Under a new row on one side of x, the green value of x does not increase.

theoremGeometric.GreedyASS.Potential.Unaccessed.Results.green_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:27
/-- 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 side

Closer 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.

theoremGeometric.GreedyASS.Potential.Unaccessed.Results.external_pointpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:34
/-- 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 untouched
theoremGeometric.GreedyASS.Potential.Unaccessed.Results.external_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:42
/-- 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 untouched
theoremGeometric.GreedyASS.Potential.Unaccessed.Results.external_sumpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:50
/-- 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 untouched

These 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.

theoremGeometric.GreedyASS.Potential.Unaccessed.Results.red_unchangedpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:59
/-- 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 untouched

A 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.

theoremGeometric.GreedyASS.Potential.Unaccessed.Results.internal_coverpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:68
/-- 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 internal

For 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 rr be the lowest common ancestor of the two closest searches, and r′r' the child of rr containing the key. At the time of the later of the two searches, r′r' was a root of the forest. The blue value at that time is the distance to rr, 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.

theoremGeometric.GreedyASS.Potential.Unaccessed.Results.nonexternal_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:74
/-- 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 untouched

Combining the cases, and adding the keys never accessed, which stay at 00:

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.

theoremGeometric.GreedyASS.Potential.Unaccessed.Results.untouched_changepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:83
/-- 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 untouched
theoremGeometric.GreedyASS.Potential.Unaccessed.Results.untouched_sumpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Unaccessed/Abstract.lean:91
/-- 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 untouched

25.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:

defGeometric.GreedyASS.Potential.Counting.purpleKeyspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Definitions/Abstract.lean:8
/-- 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 .purple
defGeometric.GreedyASS.Potential.Counting.blueKeyspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Definitions/Abstract.lean:13
def 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 .blue
defGeometric.GreedyASS.Potential.Counting.leftBlueKeyspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Definitions/Abstract.lean:17
def 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.fst
defGeometric.GreedyASS.Potential.Counting.rightBlueKeyspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Definitions/Abstract.lean:22
def 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.fst

purpleKeys 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.

theoremGeometric.GreedyASS.Potential.Counting.Results.locationspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Abstract.lean:39
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⟩

The counting rests on two bracketing facts and two “middle” lemmas.

Theorem (brackets). In an arborally satisfied P, if three glancing points have keys p<q<rp < q < r, then the row neighbors of qq exist and lie in [p,r][p, r]. If pp and rr are external, then the external neighbors of any key strictly between them exist and lie in [p,r][p, r].

theoremGeometric.GreedyASS.Potential.Counting.Results.glancing_neighborspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Abstract.lean:10
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 qr
theoremGeometric.GreedyASS.Potential.Counting.Results.external_neighborspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Abstract.lean:26
theorem 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 qr

Theorem (the middle one is red, or green). Let cc 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 ∣searches∣+1|searches| + 1, then among three glancing points with keys in cc, the middle one is red. Among three external points with keys in cc, the middle one is green, provided it is not in the latest row.

theoremGeometric.GreedyASS.Potential.Counting.Results.red_middlepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Abstract.lean:16
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 qr
theoremGeometric.GreedyASS.Potential.Counting.Results.green_middlepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Abstract.lean:31
theorem 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 notTop

The 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 cc, so that ancestor is inside cc, 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 ∣searches∣+1|searches| + 1, then each root of the forest of searched contains at most two left-external and at most two right-external blue items.

theoremGeometric.GreedyASS.Potential.Counting.Results.directionalpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Abstract.lean:48
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⟩

Among 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 ∣searches∣+1|searches| + 1. Every root of the forest of searched contains at most 44 blue and 22 purple items, colored with the search list searches ++ [searched]. The same holds for the intermediate colors, with P a history before time ∣searches∣|searches|.

theoremGeometric.GreedyASS.Potential.Counting.Results.countspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Abstract.lean:57
/-- 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⟩
theoremGeometric.GreedyASS.Potential.Counting.Results.intermediatepropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/Counting/Abstract.lean:67
/-- 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⟩) component

The 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 33 per first access.

theoremGeometric.GreedyASS.Potential.PhaseTwo.Results.itemspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseTwo/Abstract.lean:10
/-- 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 covers

Theorem (six per touched root). The number of row keys ending blue or purple is at most 66 times the number of roots of the forest of searched whose interval contains a key of the row (Virgin.touched).

theoremGeometric.GreedyASS.Potential.PhaseTwo.Results.colorspropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseTwo/Abstract.lean:23
/-- 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 valid

The 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 1212 units. So the virgin potential after the row plus 1212 per touched root is at most the virgin potential before it plus 2424. Since 66 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 1212.

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 2424, plus 33 per first access.

theoremGeometric.GreedyASS.Potential.PhaseTwo.Results.domain_boundpropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseTwo/Abstract.lean:32
/-- 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 covers
theoremGeometric.GreedyASS.Potential.PhaseTwo.Results.steppropext · Classical.choice · Quot.soundAlgorithms/GreedyASS/Potential/PhaseTwo/Abstract.lean:44
/-- 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 valid

On the full domain, the left side is ∣Rowi∣+Φi|\mathrm{Row}_i| + \Phi_i and the right side is Φi′+24+3ui\Phi'_i + 24 + 3u_i.

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 Φ(h)\Phi(h) for potential t lo h,

∣row∣+Φ(prior,old,next)  ≤  Φ(prior,old)+24 eT(old,next)+24+3 u,|\mathrm{row}| + \Phi(\textit{prior}, \textit{old}, \textit{next}) \;\le\; \Phi(\textit{prior}, \textit{old}) + 24\,e_T(\textit{old}, \textit{next}) + 24 + 3\,u,

where uu is the number of keys of the row that have never been accessed.

This is the paper’s 24 dT(si−1,si)+2424\,d_T(s_{i-1}, s_i) + 24, with dTd_T replaced by eT=dT−1e_T = d_T - 1, and with first accesses charged explicitly. The 24+24 eT24 + 24\,e_T is exactly 2424 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 LL roots may carry 1212 units of virgin potential, so the first row is charged at most 12L+24+3u12L + 24 + 3u (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

12L+24 RT(X)+3⋅#{columns with at least one point}.12L + 24\,R_T(X) + 3\cdot\#\{\text{columns with at least one point}\}.

The 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 3ui3u_i add up to three per column. The startup 12L12L is paid once.

Since the final potential is a natural number and every column is a leaf of TT, the stream bound gives the headline:

Theorem (Theorem 3.1, geometric form). For every leaf-oriented reference tree TT 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 24 RT(X)+15 L24\,R_T(X) + 15\,L.

rowCost greedySweep 0 ∅ xs is the actual sweep of Section 25.1, run from time 00 on an empty history, counting every point added, requests included. The bound holds for every TT, 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 60196019 points + 6018 n+\,6018\,n from every initial tree on nn keys. With L=nL = n and offset 00, the constants are 6019⋅24=1444566019 \cdot 24 = 144456 and 6019⋅15+6018=963036019 \cdot 15 + 6018 = 96303.

Theorem (Theorem 3.1, BST form). For every nn there is an online BST algorithm such that for every initial tree on nn keys, every reference tree with nn leaves, and every sequence of keys less than nn, the total cost (rotations plus one per request) is at most 144456 RT(X)+96303 n144456\,R_T(X) + 96303\,n.

Reading the Lean
  • One algorithm for all references. ∃ algorithm comes before ∀ initial and ∀ reference. The algorithm is the simulation of GreedyASS, which never looks at a reference tree. A single algorithm therefore meets the bound for every TT simultaneously, which is what the paper’s min⁡T\min_T requires.
  • Two different trees. initial is an ordinary BST with nn nodes (initial.size = n), where the algorithm runs. reference is read as leaf-oriented, with nn leaves (leaves reference = n) and n−1n - 1 internal nodes, and it only enters the bound.
  • Cost model. Algorithm.totalCost is rotations plus one per request (Chapter 5). The 96303 n96303\,n term includes the simulation’s startup and the 15n15n of the geometric bound.

The pointer-machine version composes the geometric bound with Results.pointer_simulation, whose constants are 192593192593 per point and 192576192576 per key: 192593⋅24=4622232192593 \cdot 24 = 4622232 and 192593⋅15+192576=3081471192593 \cdot 15 + 192576 = 3081471.

Theorem (Theorem 3.1, pointer form). For every nn there is an online BST algorithm such that for every initial tree on nn keys, every reference tree with nn leaves, and every sequence of keys less than nn, its pointer-machine run is a legal pointer execution serving the sequence, at a cost of at most 4622232 RT(X)+3081471 n4622232\,R_T(X) + 3081471\,n instructions.

As 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.

Startup and first accesses

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 LL roots, all virgin, with 1212 units each, and nothing pays for them in Lemma 3.19 at i=1i = 1. 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 1212 per leaf for the first forest and 33 per key for first accesses: one unit for the point, at most two for the new potential. Together these give the 15L15L term. Both are O(n)O(n), which the paper’s bound allows.

Distances

The paper’s dTd_T counts nodes. Phase I really performs one split or merge per edge of the path, so the Lean bound has 24 eT24\,e_T where the paper has 24 dT24\,d_T. With the +24+24 of Phase II, the amortized cost of a row is 24 dT(si−1,si)24\,d_T(s_{i-1}, s_i), which is 2424 times the row’s contribution to referenceCost.

Slightly stronger lemmas

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 66 of the 1212 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.