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

Chapter 38 · Heavy paths · Section 38.4Finger histories and simulation

Section 3 of Bose, Collette, Fagerberg and Langerman (2012a) shows that any BST algorithm can be run inside another BST that stays balanced at all times. The original algorithm, the source, keeps a persistent finger. Each of its instructions moves the finger to a child or to the parent, or rotates the finger over its parent. The simulating BST, the physical tree, keeps its own cursor at the root between instructions, and the source finger’s node sits at that root. The path from the root to the source finger is stored upside down as two weighted pop-tarts (Section 37.1, Section 37.2), and the subtrees hanging off that path are stored recursively as heavy-path representations (Section 38.1, Section 38.2). Every source instruction becomes a constant number of pop-tart operations. Every node of weight ww stays at physical depth O(log⁡(W/w))O(\log(W/w)), where WW is the total weight. This is the paper’s Theorem 5.

This section formalizes that simulation, as needed by the deamortization of Chapter 30. The representation of a source finger is a finger history: a state whose pop-tarts and payload layouts are whatever earlier instructions left behind, not a canonical rebuild of the current source tree. The section proves that each of the six source instructions maps one valid history to another at constant amortized cost and O(log⁡n)O(\log n) worst-case cost. It then packages the steps into one online policy, runs it on instruction streams and on request sequences, and bounds the depth of every key at every intermediate physical configuration, including those in the middle of the response to one source instruction.

Main result · Bose et al. 2012a
Any finger can be simulated by a BST of weight-balanced depth

Fix a weight w(a)w(a) for every label aa. There is a policy pp with the following properties. To answer one source instruction, pp sees only the current source cursor, the current physical representation and that instruction.

Let the source finger point at a node of a labelled tree TT with nn nodes and positive weights. Let WW be the total weight, and let wiw_i be the weight of the ii-th label of TT in inorder. Then the physical tree, starting as TT itself with its cursor at the root, can be reshaped into a starting representation by a pointer-machine trace of cost s0s_0. The trace satisfies s0+Φ0≤39ns_0 + \Phi_0 \le 39n, where Φ0≥0\Phi_0 \ge 0 is the starting potential. Take any stream of mm source instructions that is legal from the source finger. Running pp instruction by instruction then succeeds and ends in a valid representation of the final source cursor, with the following guarantees:

  • the startup and the responses together form one pointer-machine trace from TT, of cost s0+Cs_0 + C with s0+C+Φ≤39n+62ms_0 + C + \Phi \le 39n + 62m, where Φ≥0\Phi \ge 0 is the final potential;
  • each source instruction is answered by at most 34+24log⁡2n34 + 24\log_2 n physical instructions, which start and end with the physical cursor at the root;
  • in every valid representation, between instructions, the physical root holds the source finger’s node, and the node of rank ii is at depth at most 15+15log⁡2(W/wi)15 + 15\log_2(W/w_i);
  • at every instruction boundary of the emitted physical program, even in the middle of a response, the node of rank ii is at depth at most
336+240 log⁡2Wwi.336 + 240\,\log_2 \frac{W}{w_i}.

In Lean, the per-instruction bound is part of Simulation.PolicyBounded, and Simulation.PolicyWithin extends it. Depths count edges (Tree.depth), and a rank is an inorder position. The policy is obtained by choice from the existence of a response for each step, so the theorem asserts that a function with these properties exists, not that it is computable. It depends on the weights, because the physical layout does.

The Lean statements
theoremHeavyPath.Finger.History.Simulation.Results.policy_within_existspropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:125
theorem policy_within_exists {α : Type} (weight : α → ℝ) : ∃ p : Policy α, PolicyWithin weight p := …  RotationBST.HeavyPath.Finger.History.Simulation.policy_within_exists weight
theoremHeavyPath.Finger.History.Simulation.Results.initialized_runpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:50
theorem initialized_run {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) {cs : List (Frame α)}    {left right : LabelledTree α} {key : α}    (positive : Positive weight (plug cs (.node left key right))) :    ∃ (start : State α) (startupCost : Nat),      ConfigValid weight ⟨.node left key right, cs⟩ start ∧      Pointer.Trace ⟨(plug cs (.node left key right)).erase, []⟩ ⟨start.pair.tree, []⟩ startupCost ∧      startupCost + start.potential ≤ 39 * (plug cs (.node left key right)).erase.size ∧      ∀ (ops : List Multifinger.Opcode) (final : Config α),        sourceRun ⟨.node left key right, cs⟩ ops = some final →        ∃ out, run p ⟨.node left key right, cs⟩ start ops = some out ∧ out.source = final ∧          ConfigValid weight out.source out.state ∧          Pointer.Trace ⟨(plug cs (.node left key right)).erase, []⟩            ⟨out.state.pair.tree, []⟩ (startupCost + out.cost) ∧          startupCost + out.cost + out.state.potential ≤            39 * (plug cs (.node left key right)).erase.size + 62 * ops.length := …  RotationBST.HeavyPath.Finger.History.Simulation.initialized_run policyValid positive
theoremHeavyPath.Finger.History.Simulation.Interruption.Results.run_weighted_prefixpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Interruption/Abstract.lean:107
theorem run_weighted_prefix {α : Type} {weight : α → ℝ} {p : Policy α}    (certified : PolicyWithin weight p) {c : Config α} {s : State α}    (valid : ConfigValid weight c s) {ops : List Multifinger.Opcode} {out : Output α}    (completed : run p c s ops = some out) (cut : Nat) :    ∃ middle,      Multifinger.replay (out.instructions.take cut) ⟨s.pair.tree, []⟩ = some middle ∧      Multifinger.replay (out.instructions.drop cut) middle = some ⟨out.state.pair.tree, []⟩ ∧      ∀ rank : Fin c.tree.inorder.length,        (Tree.depth middle.tree rank.val : ℝ) ≤          336 + 240 * Real.logb 2 (HeavyPath.mass weight c.tree /            weight (c.tree.inorder[rank.val]'rank.isLt)) := …  RotationBST.HeavyPath.Finger.History.Simulation.Interruption.run_weighted_prefix certified valid completed cut
theoremHeavyPath.Finger.History.Simulation.Results.root_keypropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:68
theorem root_key {α : Type} {weight : α → ℝ} {c : Config α} {s : State α}    (valid : ConfigValid weight c s) :    (Pointer.Config.mk s.pair.tree []).key? = c.erase.key? := …  RotationBST.HeavyPath.Finger.History.Simulation.root_key valid
theoremHeavyPath.Finger.History.Simulation.Results.depthpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:73
theorem depth {α : Type} {weight : α → ℝ} {c : Config α} {s : State α}    (valid : ConfigValid weight c s) (rank : Fin c.tree.inorder.length) :    (Tree.depth s.pair.tree rank.val : ℝ) ≤      15 + 15 * Real.logb 2 (HeavyPath.mass weight c.tree /        weight (c.tree.inorder[rank.val]'rank.isLt)) := …  RotationBST.HeavyPath.Finger.History.Simulation.depth valid rank
82 definitions in 10 chapters · reading list
Do you need this section?

Only if you want to see how the deamortization works inside. The theorems that other chapters quote are Results.simulation and the scheduler results of Chapter 30, and the replay of source algorithms inside ComboBST workers (Section 29.1 and the sections after it) and in the combined finger BST (Chapter 31). Those statements mention the policy, the state and the request runs defined here. To check those results, you only need Section 38.4.6 and Section 38.4.10: what a policy promises, and how a source algorithm is described. The rest is the simulation itself: the invariant, the six instruction lemmas, and the depth analysis.

38.4.1 Overview

Three objects are involved.

  • The source cursor is a LabelledCursor.Config (a zipper): a focused labelled subtree node left key right together with its context frames cs, innermost first. The source finger is the node key. The source instructions are the six Multifinger.Opcodes, with the labelled semantics LabelledCursor.perform: move to the left or right child, move to the parent, or rotate the finger over its parent. A rotation keeps the finger on the same node. Labels travel with their nodes, and ww is a function of the labels.
  • The finger history is a History.State. It records one entry per source ancestor of the finger, a pair of Chocolate pop-tarts (Finger.Pair, Section 38.3), and the physical layouts of the finger’s two children.
  • The physical tree is s.pair.tree, an unlabelled Tree with the same number of nodes, operated on by the single-cursor pointer machine of Chapter 7.

The physical tree has this shape. It is Figure 5 of the paper with the lower side mirrored:

                       key                      ← physical root = source finger
                 ╱              ╲
     lower pop-tart, mirrored     upper pop-tart
     leaves, left to right:       leaves, left to right:
       payload of a₁                right subtree of key
       payload of a₂                payload of b_j
       …                            …
       left subtree of key          payload of b₁

  a₁ … a_i : ancestors smaller than key (the cursor went right at them), root first
  b₁ … b_j : ancestors larger than key (the cursor went left at them), root first

The internal nodes of each pop-tart are the ancestor keys of its side. The leaves are the payloads: the off-path subtree of each ancestor, and, innermost, the corresponding child subtree of the finger. Each payload is itself stored as a recursive heavy-path layout (History.Layout, Section 38.2). The stack top of each pop-tart is at the finger end. So the ancestors nearest the finger, and the finger’s children, are near the physical root. A source instruction changes only that end:

  • Down. The finger moves into one of its children. The old finger becomes an ancestor and is pushed onto one stack, its other child becomes that ancestor’s payload, and the new finger’s two children are exposed from the old child’s layout.
  • Up. The inverse: the innermost ancestor is popped and becomes the finger again.
  • Rotation. The finger and its parent exchange roles. The parent leaves its stack, and the two payloads it separated are joined with it into one.

Each instruction is a constant number of pushes, pops and top replacements on Chocolate pop-tarts, plus local surgery on the recursive layouts. A pop-tart operation has O(1)O(1) amortized and O(log⁡n)O(\log n) worst-case cost (Lemma 4 of the paper), so a source instruction costs at most 6262 physical instructions amortized against the state potential, and at most 34+24log⁡2n34 + 24\log_2 n in the worst case.

The depth bound is the paper’s telescoping argument. A pop-tart stores a leaf of weight ww at depth O(log⁡(W/w))O(\log(W/w)). A payload’s weight is its whole subtree mass, and inside the payload the recursive heavy-path layout again stores a node of weight ww at depth O(log⁡(mass/w))O(\log(\text{mass}/w)). The logarithms telescope to 15+15log⁡2(W/w)15 + 15\log_2(W/w).

Why “history”. After a few instructions the pop-tarts and payload layouts are no longer the canonical ones that Finger.build would produce from the current source tree. A payload that was split and later rejoined may have a different shape, and the potential records its imbalance. The invariant therefore accepts any layout that a valid sequence of stack operations can produce, as History.Layout does for heavy paths. Two equal source subtrees may be laid out differently at different places.

Why intermediate depths. Theorem 5 of the paper says that depths are “always” O(log⁡(W/w))O(\log(W/w)), and its proof bounds them in the representation, that is, between simulated source instructions. Theorem 6 interrupts the simulated program every clog⁡nc\log n physical operations to serve the next request. Such an interruption can fall in the middle of the O(log⁡n)O(\log n) instructions that answer one source instruction. The formalization therefore also bounds the depth of every key at every physical instruction boundary (Section 38.4.9).

The section proceeds as follows. Section 38.4.2 defines the state and its invariant. Section 38.4.3 lists what a valid state guarantees. Section 38.4.4 builds the first state. Section 38.4.5 gives the six instruction lemmas. Section 38.4.6 packages them as a policy and Section 38.4.7 runs it. Section 38.4.8 shows that starting from the cheapest representation removes the potential from the cost bound. Section 38.4.9 bounds depths inside responses, and Section 38.4.10 lifts everything to request sequences.

38.4.2 The representation

The definitions are in Structures/HeavyPath/Finger/History/Definitions/Abstract.lean.

38.4.2.1 Slots charged toward the finger

The leaves of a weighted pop-tart carry weights. The ancestor keys are internal nodes, which the pop-tarts of Section 37.1 do not weigh. So the weight of each ancestor key is moved onto the next leaf toward the finger:

defHeavyPath.Finger.History.sideSlotspropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:10
/-- Shift each ancestor's weight to the next payload toward the finger.Payload shapes belong to occurrences, independently of their source labels. -/def sideSlots {α : Type} (weight : α → ℝ) (boundary : LabelledTree α) (shape : Tree) :    ℝ → List (Entry α) → List (Tree × ℝ)  | carry, [] => [(shape, carry + HeavyPath.mass weight boundary)]  | carry, e :: es => (e.shape, carry + HeavyPath.mass weight (framePayload e.source)) ::      sideSlots weight boundary shape (weight (frameKey e.source)) es

sideSlots weight boundary shape carry es lists the leaves of one side, outermost first. Each ancestor entry e contributes its payload’s physical shape e.shape, with weight carry plus the payload’s mass. Then the ancestor’s own key weight becomes the carry of the next leaf. The last leaf is the finger’s child boundary, physically laid out as shape. It receives the key weight of the innermost ancestor on that side. The slot weights of both sides therefore add up to the total mass minus the finger’s own weight (Results.state_mass). This is the history version of Finger.sideSlots (Section 38.3). That function computes each payload’s shape with the canonical rebuild, while this one takes the recorded shape of each History.Entry.

38.4.2.2 States and potential

structureHeavyPath.Finger.History.Statepropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:18
/-- All physical payload occurrences of an inverted source cursor. -/structure State (α : Type) where  ancestors : List (Entry α)  leftShape : Tree  rightShape : Tree  leftCredit : Nat  rightCredit : Nat  pair : Pair
defHeavyPath.Finger.History.State.potentialpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:27
def State.potential {α : Type} (s : State α) : Nat :=  s.pair.potential + s.leftCredit + s.rightCredit + (s.ancestors.map Entry.credit).sum

A state has five components:

  • ancestors: one History.Entry per source ancestor, innermost first. An entry is the source frame (ancestor key, side, off-path subtree), the physical shape of that subtree, and its credit.
  • leftShape, rightShape: the physical layouts of the finger’s two children.
  • leftCredit, rightCredit: their credits.
  • pair: the two pop-tarts, a Finger.Pair. Its physical tree is the finger node with the mirrored lower pop-tart on the left and the upper pop-tart on the right. The leaves of the pop-tarts are the payload shapes.

The potential is the pop-tart potential of the pair (Pair.potential) plus the credits of the two children and of every ancestor payload. A credit is itself the potential of a recursive layout, so the potential counts every pop-tart nested anywhere in the physical tree. It is a natural number. The cost bounds below are amortized against it.

38.4.2.3 The invariant

structureHeavyPath.Finger.History.Validpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:30
/-- The whole inverted-cursor invariant. Depth is a consequence, not a field.Every ancestor payload and both finger children retain their recursive layouts. -/structure Valid {α : Type} (weight : α → ℝ) (cs : List (Frame α))    (left : LabelledTree α) (key : α) (right : LabelledTree α) (s : State α) : Prop where  positive : Positive weight (plug cs (.node left key right))  context : s.ancestors.map Entry.source = cs  pair : s.pair.Valid  leftLayout : Recursive.History.Layout weight left s.leftShape s.leftCredit  rightLayout : Recursive.History.Layout weight right s.rightShape s.rightCredit  children : ∀ e ∈ s.ancestors,    Recursive.History.Layout weight (framePayload e.source) e.shape e.credit  lower : s.pair.lower.decode.mirror.fringe =    sideSlots weight left s.leftShape 0 (Recursive.History.lower s.ancestors)  upper : s.pair.upper.decode.fringe =    (sideSlots weight right s.rightShape 0 (Recursive.History.upper s.ancestors).reverse).reverse

Valid weight cs left key right s says that s represents the source cursor with focus node left key right and context cs. Its eight fields are the whole invariant:

theoremHeavyPath.Finger.History.Valid.positivepropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:34
positive
Statement reads only Structures/HeavyPath/Finger/History/Definitions/Abstract.lean and its imports
theoremHeavyPath.Finger.History.Valid.contextpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:35
context
Statement reads only Structures/HeavyPath/Finger/History/Definitions/Abstract.lean and its imports
theoremHeavyPath.Finger.History.Valid.pairpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:36
pair
Statement reads only Structures/HeavyPath/Finger/History/Definitions/Abstract.lean and its imports
theoremHeavyPath.Finger.History.Valid.leftLayoutpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:37
leftLayout
Statement reads only Structures/HeavyPath/Finger/History/Definitions/Abstract.lean and its imports
theoremHeavyPath.Finger.History.Valid.rightLayoutpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:38
rightLayout
Statement reads only Structures/HeavyPath/Finger/History/Definitions/Abstract.lean and its imports
theoremHeavyPath.Finger.History.Valid.childrenpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:39
children
Statement reads only Structures/HeavyPath/Finger/History/Definitions/Abstract.lean and its imports
theoremHeavyPath.Finger.History.Valid.lowerpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:41
lower
Statement reads only Structures/HeavyPath/Finger/History/Definitions/Abstract.lean and its imports
theoremHeavyPath.Finger.History.Valid.upperpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Definitions/Abstract.lean:43
upper
Statement reads only Structures/HeavyPath/Finger/History/Definitions/Abstract.lean and its imports
  1. positive: every weight in the whole source tree is positive (HeavyPath.Positive). The depth bounds divide by weights.
  2. context: the sources of the ancestor entries are exactly the context frames. So the state records the actual source path from the root to the finger.
  3. pair: both Chocolate pop-tarts are valid (at level 00).
  4. leftLayout, rightLayout: the finger’s children are laid out as recursive heavy-path histories with the recorded shapes and credits.
  5. children: so is every ancestor’s off-path payload.
  6. lower, upper: the leaves of the two pop-tarts, read in inorder, are exactly the slots of the two sides. History.lower selects the ancestors smaller than the finger, root first, and History.upper those larger, innermost first. The latter list is reversed so that sideSlots again runs from the root toward the finger.

The path from the root to the finger is not required to be a heavy path. The whole path is held by one pair of pop-tarts, whatever its edges, and only the payloads use the heavy-path decomposition. Depth is not a field either: it is a consequence of the invariant (Results.state_depth), so the instruction lemmas never need to re-establish it.

38.4.3 What a valid state guarantees

These theorems are in Structures/HeavyPath/Finger/History/Abstract.lean. Each assumes Valid weight cs left key right s, and writes TT = plug cs (node left key right) for the whole source tree.

Theorem (same keys, finger at the root). The physical tree has as many nodes as TT. The physical root has the inorder rank of the source finger. If the labels are ordered by a preorder and TT is a search tree, there is exactly one labelling of the physical tree that has TT’s inorder and is a search tree. The finger’s weight plus the slot masses of the pair is the total mass of TT. Each side has the size of its blocks: the ancestors on that side with their payloads, plus the finger’s child on that side.

theoremHeavyPath.Finger.History.Results.state_sizepropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:23
theorem state_size {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α} {s : State α} (valid : Valid weight cs left key right s) :    s.pair.tree.size = (plug cs (.node left key right)).erase.size :=  RotationBST.HeavyPath.Finger.History.state_size valid
theoremHeavyPath.Finger.History.Results.state_root_keypropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:28
theorem state_root_key {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α} {s : State α} (valid : Valid weight cs left key right s) :    (Pointer.Config.mk s.pair.tree []).key? = (Config.mk (.node left key right) cs).erase.key? :=  RotationBST.HeavyPath.Finger.History.state_root_key valid
theoremHeavyPath.Finger.History.Results.state_labelspropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:33
theorem state_labels {α : Type} [Preorder α] {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α} {s : State α} (valid : Valid weight cs left key right s)    (ordered : (plug cs (.node left key right)).Ordered) :    ∃! u : LabelledTree α, u.erase = s.pair.tree ∧      u.inorder = (plug cs (.node left key right)).inorder ∧ u.Ordered :=  RotationBST.HeavyPath.Finger.History.state_labels valid ordered
theoremHeavyPath.Finger.History.Results.state_masspropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:10
theorem state_mass {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α} {s : State α} (valid : Valid weight cs left key right s) :    weight key + s.pair.mass = HeavyPath.mass weight (plug cs (.node left key right)) :=  RotationBST.HeavyPath.Finger.History.state_mass valid
theoremHeavyPath.Finger.History.Results.state_side_sizespropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:15
theorem state_side_sizes {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α} {s : State α} (valid : Valid weight cs left key right s) :    s.pair.lower.decode.tree.mirror.size =      ((Recursive.History.lower s.ancestors).flatMap Entry.lowerBlock).length + left.erase.size ∧    s.pair.upper.decode.tree.size =      right.erase.size + ((Recursive.History.upper s.ancestors).flatMap Entry.upperBlock).length :=  RotationBST.HeavyPath.Finger.History.state_side_sizes valid

state_root_key compares Config.key? at the physical root with the rank of the source cursor (Config.erase). So the pointer machine, whose searches start at the root, finds the source finger there at no cost. state_labels says that the physical tree is a BST on the same keys. The physical tree is unlabelled, and state_labels says how its nodes inherit the source labels.

Theorem (depth). The node of inorder rank ii in TT, with weight wiw_i, has physical depth at most 15+15log⁡2(W/wi)15 + 15\log_2(W/w_i), where WW is the total weight. Consequently, the pointer machine can walk from the root to that node and back, with the same cost kk each way, such that 1+2k≤31+30log⁡2(W/wi)1 + 2k \le 31 + 30\log_2(W/w_i).

theoremHeavyPath.Finger.History.Results.state_depthpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:40
theorem state_depth {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α}    {s : State α} (valid : Valid weight cs left key right s)    {before after : List α} {target : α}    (occurrence : (plug cs (.node left key right)).inorder = before ++ target :: after) :    (Tree.depth s.pair.tree before.length : ℝ) ≤      15 + 15 * Real.logb 2 (HeavyPath.mass weight (plug cs (.node left key right)) / weight target) :=  RotationBST.HeavyPath.Finger.History.state_depth valid occurrence
theoremHeavyPath.Finger.History.Results.state_depth_atpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:49
theorem state_depth_at {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α}    {s : State α} (valid : Valid weight cs left key right s)    (rank : Fin (plug cs (.node left key right)).inorder.length) :    (Tree.depth s.pair.tree rank.val : ℝ) ≤      15 + 15 * Real.logb 2 (HeavyPath.mass weight (plug cs (.node left key right)) /        weight ((plug cs (.node left key right)).inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Finger.History.state_depth_at valid rank
theoremHeavyPath.Finger.History.Results.state_search_walkpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:58
theorem state_search_walk {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α}    {s : State α} (valid : Valid weight cs left key right s)    (rank : Fin (plug cs (.node left key right)).inorder.length) :    ∃ (visited : Pointer.Config) (cost : Nat),      visited.tree = s.pair.tree ∧ visited.key? = some rank.val ∧      Pointer.Trace ⟨s.pair.tree, []⟩ visited cost ∧      Pointer.Trace visited ⟨s.pair.tree, []⟩ cost ∧      (1 + 2 * cost : ℝ) ≤ 31 + 30 * Real.logb 2        (HeavyPath.mass weight (plug cs (.node left key right)) /          weight ((plug cs (.node left key right)).inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Finger.History.state_search_walk valid rank

state_depth names the node by an occurrence in the inorder list (before ++ target :: after, of rank before.length), and state_depth_at by a rank in Fin. The walk in state_search_walk is navigation only: it never rotates, and it returns to the same tree with the cursor at the root. The 11 is the unit charge of the request.

Theorem (potential). The potential of a valid state is at most 20n−2020n - 20, where nn is the size of TT.

The bound holds for every valid history, not only for freshly built ones. Section 38.4.10 uses it to bound the work on any window of requests without assumptions about the starting potential.

38.4.4 The starting state

A valid state always exists, and the canonical one is reachable cheaply. Given positive weights, there is a valid state whose pair is the canonical Finger.build of Section 38.3. Its potential is at most 23n23n. Starting from the source tree itself, read as an unlabelled tree with the cursor at the root, the pointer machine reaches the physical tree of some valid state in at most 16n16n instructions, and that state can be chosen with potential at most 23n23n, so that startup cost plus potential is at most 39n39n.

theoremHeavyPath.Finger.History.Results.build_statepropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:71
theorem build_state {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α}    (positive : Positive weight (plug cs (.node left key right))) :    ∃ s : State α, Valid weight cs left key right s ∧ s.pair = build weight cs left right :=  RotationBST.HeavyPath.Finger.History.build_state positive
theoremHeavyPath.Finger.History.Results.build_state_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:85
theorem build_state_bounded {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α}    (positive : Positive weight (plug cs (.node left key right))) :    ∃ s : State α, Valid weight cs left key right s ∧ s.pair = build weight cs left right ∧      s.potential ≤ 23 * (plug cs (.node left key right)).erase.size :=  RotationBST.HeavyPath.Finger.History.build_state_bounded positive
theoremHeavyPath.Finger.History.Results.state_initializationpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:77
theorem state_initialization {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α}    (positive : Positive weight (plug cs (.node left key right))) :    ∃ (s : State α) (cost : Nat), Valid weight cs left key right s ∧      Pointer.Trace ⟨(plug cs (.node left key right)).erase, []⟩ ⟨s.pair.tree, []⟩ cost ∧      cost ≤ 16 * (plug cs (.node left key right)).erase.size :=  RotationBST.HeavyPath.Finger.History.state_initialization positive
theoremHeavyPath.Finger.History.Results.state_initialization_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Abstract.lean:92
theorem state_initialization_bounded {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {left right : LabelledTree α} {key : α}    (positive : Positive weight (plug cs (.node left key right))) :    ∃ (s : State α) (cost : Nat), Valid weight cs left key right s ∧      Pointer.Trace ⟨(plug cs (.node left key right)).erase, []⟩ ⟨s.pair.tree, []⟩ cost ∧      cost ≤ 16 * (plug cs (.node left key right)).erase.size ∧      s.potential ≤ 23 * (plug cs (.node left key right)).erase.size ∧      cost + s.potential ≤ 39 * (plug cs (.node left key right)).erase.size :=  RotationBST.HeavyPath.Finger.History.state_initialization_bounded positive

The source finger may be anywhere in TT. The startup trace begins from TT’s own shape, which is how the physical machine starts: before the simulation begins, the physical and source trees coincide. The constant 23n23n is the one the initialization proof produces, and Results.potential_bound improves it to 20n−2020n - 20 after the fact. The 39n39n is what enters every startup-inclusive bound below.

38.4.5 The six instructions

Each source instruction has a lemma in three strengths. The plain version gives a valid successor state, reached by a Pointer.Trace from the physical root to the physical root, and an amortized bound cost+Φ′≤K+Φ\text{cost} + \Phi' \le K + \Phi. The _bounded version adds a worst-case bound cost≤a+24log⁡2n\text{cost} \le a + 24\log_2 n, where nn is the physical size. The _within version replaces the trace by a Pointer.TraceWithin (Chapter 36). That trace keeps the size and satisfies, at every one of its instruction boundaries, depth(x)≤16⋅depth0(x)+b\mathrm{depth}(x) \le 16\cdot\mathrm{depth}_0(x) + b for every rank xx, where depth0\mathrm{depth}_0 is the depth in the starting physical tree. Each lemma also says exactly how the list of ancestor entries changes.

instruction amortized KK worst case intermediate depth
move down 5454 26+24log⁡2n26 + 24\log_2 n 16 d+6416\,d + 64
move up 6262 34+24log⁡2n34 + 24\log_2 n 16 d+9616\,d + 96
rotate 5050 22+24log⁡2n22 + 24\log_2 n 16 d+5616\,d + 56

The policy below uses the worst row of each column: 6262, 34+24log⁡2n34 + 24\log_2 n and 16d+9616d + 96.

38.4.5.1 Moving down

Theorem (move down). Suppose the finger key has a nonempty left child node l x r and right subtree sibling. Then there is a valid state for the finger x, whose new innermost ancestor is key with payload sibling. That payload keeps the old physical shape and credit of the right child. The cost satisfies the bounds of the table. The right move is the mirror image.

theoremHeavyPath.Finger.History.Down.Results.downLeftpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Down/Abstract.lean:10
theorem downLeft {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key x : α} {s : State α}    (valid : Valid weight cs (.node l x r) key sibling s) :    ∃ (next : State α) (cost : Nat), Valid weight (.left key sibling :: cs) l x r next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 54 + s.potential ∧      next.ancestors = ⟨.left key sibling, s.rightShape, s.rightCredit⟩ :: s.ancestors :=  RotationBST.HeavyPath.Finger.History.Down.downLeft valid
theoremHeavyPath.Finger.History.Down.Results.downRightpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Down/Abstract.lean:19
theorem downRight {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key x : α} {s : State α}    (valid : Valid weight cs sibling key (.node l x r) s) :    ∃ (next : State α) (cost : Nat), Valid weight (.right sibling key :: cs) l x r next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 54 + s.potential ∧      next.ancestors = ⟨.right sibling key, s.leftShape, s.leftCredit⟩ :: s.ancestors :=  RotationBST.HeavyPath.Finger.History.Down.downRight valid
theoremHeavyPath.Finger.History.Down.Results.downLeft_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Down/Abstract.lean:28
theorem downLeft_bounded {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key x : α} {s : State α}    (valid : Valid weight cs (.node l x r) key sibling s) :    ∃ (next : State α) (cost : Nat), Valid weight (.left key sibling :: cs) l x r next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 54 + s.potential ∧      next.ancestors = ⟨.left key sibling, s.rightShape, s.rightCredit⟩ :: s.ancestors ∧      (cost : ℝ) ≤ 26 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Down.downLeft_bounded valid
theoremHeavyPath.Finger.History.Down.Results.downRight_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Down/Abstract.lean:38
theorem downRight_bounded {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key x : α} {s : State α}    (valid : Valid weight cs sibling key (.node l x r) s) :    ∃ (next : State α) (cost : Nat), Valid weight (.right sibling key :: cs) l x r next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 54 + s.potential ∧      next.ancestors = ⟨.right sibling key, s.leftShape, s.leftCredit⟩ :: s.ancestors ∧      (cost : ℝ) ≤ 26 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Down.downRight_bounded valid
theoremHeavyPath.Finger.History.Down.Results.downLeft_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Down/Abstract.lean:48
theorem downLeft_within {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key x : α} {s : State α}    (valid : Valid weight cs (.node l x r) key sibling s) :    ∃ (next : State α) (cost : Nat), Valid weight (.left key sibling :: cs) l x r next ∧      Pointer.TraceWithin (fun t => t.size = s.pair.tree.size ∧        ∀ x, Tree.depth t x ≤ 16 * Tree.depth s.pair.tree x + 64) ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 54 + s.potential ∧      next.ancestors = ⟨.left key sibling, s.rightShape, s.rightCredit⟩ :: s.ancestors ∧      (cost : ℝ) ≤ 26 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Down.downLeft_within valid
theoremHeavyPath.Finger.History.Down.Results.downRight_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Down/Abstract.lean:59
theorem downRight_within {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key x : α} {s : State α}    (valid : Valid weight cs sibling key (.node l x r) s) :    ∃ (next : State α) (cost : Nat), Valid weight (.right sibling key :: cs) l x r next ∧      Pointer.TraceWithin (fun t => t.size = s.pair.tree.size ∧        ∀ x, Tree.depth t x ≤ 16 * Tree.depth s.pair.tree x + 64) ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 54 + s.potential ∧      next.ancestors = ⟨.right sibling key, s.leftShape, s.leftCredit⟩ :: s.ancestors ∧      (cost : ℝ) ≤ 26 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Down.downRight_within valid

The equation for next.ancestors shows the history at work. The old right child is not rebuilt. Its layout is reused as the payload of a new entry, so equal source subtrees can end up with different layouts. Physically, the top leaf of the lower pop-tart, the layout of the old left child, is opened at x. Its place is taken by x’s left child l. The old finger becomes an internal node of the upper pop-tart, its old right child stays there as a leaf, and x’s right child r is pushed as the new top leaf. On the pair this is the transfer Pair.downLeft of Section 38.3.

38.4.5.2 Moving up

Theorem (move up). Suppose the finger key, with children l and r, is the left child of parent, whose right subtree is sibling. Then there is a valid state for the finger parent, with left child node l key r and right child sibling. Its ancestors are the old ones without the innermost entry, and the cost satisfies the bounds of the table. The case of a right child is symmetric.

theoremHeavyPath.Finger.History.Up.Results.upLeftpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Up/Abstract.lean:10
theorem upLeft {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.left parent sibling :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs (.node l key r) parent sibling next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 62 + s.potential ∧ next.ancestors = s.ancestors.tail :=  RotationBST.HeavyPath.Finger.History.Up.upLeft valid
theoremHeavyPath.Finger.History.Up.Results.upRightpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Up/Abstract.lean:18
theorem upRight {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.right sibling parent :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs sibling parent (.node l key r) next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 62 + s.potential ∧ next.ancestors = s.ancestors.tail :=  RotationBST.HeavyPath.Finger.History.Up.upRight valid
theoremHeavyPath.Finger.History.Up.Results.upLeft_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Up/Abstract.lean:26
theorem upLeft_bounded {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.left parent sibling :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs (.node l key r) parent sibling next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 62 + s.potential ∧ next.ancestors = s.ancestors.tail ∧      (cost : ℝ) ≤ 34 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Up.upLeft_bounded valid
theoremHeavyPath.Finger.History.Up.Results.upRight_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Up/Abstract.lean:35
theorem upRight_bounded {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.right sibling parent :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs sibling parent (.node l key r) next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 62 + s.potential ∧ next.ancestors = s.ancestors.tail ∧      (cost : ℝ) ≤ 34 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Up.upRight_bounded valid
theoremHeavyPath.Finger.History.Up.Results.upLeft_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Up/Abstract.lean:44
theorem upLeft_within {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.left parent sibling :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs (.node l key r) parent sibling next ∧      Pointer.TraceWithin (fun t => t.size = s.pair.tree.size ∧        ∀ x, Tree.depth t x ≤ 16 * Tree.depth s.pair.tree x + 96) ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 62 + s.potential ∧ next.ancestors = s.ancestors.tail ∧      (cost : ℝ) ≤ 34 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Up.upLeft_within valid
theoremHeavyPath.Finger.History.Up.Results.upRight_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Up/Abstract.lean:54
theorem upRight_within {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.right sibling parent :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs sibling parent (.node l key r) next ∧      Pointer.TraceWithin (fun t => t.size = s.pair.tree.size ∧        ∀ x, Tree.depth t x ≤ 16 * Tree.depth s.pair.tree x + 96) ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 62 + s.potential ∧ next.ancestors = s.ancestors.tail ∧      (cost : ℝ) ≤ 34 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Up.upRight_within valid

Moving up is the most expensive instruction. The parent is popped from its stack, and the old finger with both its children must be merged back into one payload with a valid recursive layout.

38.4.5.3 Rotating at the finger

Theorem (rotation). Suppose the finger key, with children l and r, is the left child of parent, whose right subtree is sibling. Then there is a valid state for the rotated cursor: the finger is still key, now in the parent’s position, with left child l and right child node r parent sibling. Its ancestors are the old ones without the innermost entry, and the cost satisfies the bounds of the table. The case of a right child is symmetric.

theoremHeavyPath.Finger.History.Rotation.Results.rotateLeftChildpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Rotation/Abstract.lean:10
theorem rotateLeftChild {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.left parent sibling :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs l key (.node r parent sibling) next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 50 + s.potential ∧ next.ancestors = s.ancestors.tail :=  RotationBST.HeavyPath.Finger.History.Rotation.rotateLeftChild valid
theoremHeavyPath.Finger.History.Rotation.Results.rotateRightChildpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Rotation/Abstract.lean:18
theorem rotateRightChild {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.right sibling parent :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs (.node sibling parent l) key r next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 50 + s.potential ∧ next.ancestors = s.ancestors.tail :=  RotationBST.HeavyPath.Finger.History.Rotation.rotateRightChild valid
theoremHeavyPath.Finger.History.Rotation.Results.rotateLeftChild_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Rotation/Abstract.lean:26
theorem rotateLeftChild_bounded {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.left parent sibling :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs l key (.node r parent sibling) next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 50 + s.potential ∧ next.ancestors = s.ancestors.tail ∧      (cost : ℝ) ≤ 22 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Rotation.rotateLeftChild_bounded valid
theoremHeavyPath.Finger.History.Rotation.Results.rotateRightChild_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Rotation/Abstract.lean:35
theorem rotateRightChild_bounded {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.right sibling parent :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs (.node sibling parent l) key r next ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 50 + s.potential ∧ next.ancestors = s.ancestors.tail ∧      (cost : ℝ) ≤ 22 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Rotation.rotateRightChild_bounded valid
theoremHeavyPath.Finger.History.Rotation.Results.rotateLeftChild_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Rotation/Abstract.lean:44
theorem rotateLeftChild_within {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.left parent sibling :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs l key (.node r parent sibling) next ∧      Pointer.TraceWithin (fun t => t.size = s.pair.tree.size ∧        ∀ x, Tree.depth t x ≤ 16 * Tree.depth s.pair.tree x + 56) ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 50 + s.potential ∧ next.ancestors = s.ancestors.tail ∧      (cost : ℝ) ≤ 22 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Rotation.rotateLeftChild_within valid
theoremHeavyPath.Finger.History.Rotation.Results.rotateRightChild_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Rotation/Abstract.lean:54
theorem rotateRightChild_within {α : Type} {weight : α → ℝ} {cs : List (Frame α)}    {l r sibling : LabelledTree α} {key parent : α} {s : State α}    (valid : Valid weight (.right sibling parent :: cs) l key r s) :    ∃ (next : State α) (cost : Nat), Valid weight cs (.node sibling parent l) key r next ∧      Pointer.TraceWithin (fun t => t.size = s.pair.tree.size ∧        ∀ x, Tree.depth t x ≤ 16 * Tree.depth s.pair.tree x + 56) ⟨s.pair.tree, []⟩ ⟨next.pair.tree, []⟩ cost ∧      cost + next.potential ≤ 50 + s.potential ∧ next.ancestors = s.ancestors.tail ∧      (cost : ℝ) ≤ 22 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Rotation.rotateRightChild_within valid

Together with the moves, these are the six cases of LabelledCursor.perform. The physical tree is not rotated like the source. The physical root stays the finger, the parent leaves its stack, and the two payloads it separated, the finger’s old right child r and the parent’s payload sibling, are joined with it into the single payload node r parent sibling.

38.4.6 Policies

The definitions are in Structures/HeavyPath/Finger/History/Simulation/Definitions/Abstract.lean. A policy turns the instruction lemmas into a program: for each source instruction, it emits a concrete list of physical instructions.

defHeavyPath.Finger.History.Simulation.ConfigValidpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Definitions/Abstract.lean:11
/-- The complete history invariant at a source cursor. Empty focuses are notsource fingers and cannot execute any of the six labelled instructions. -/def ConfigValid {α : Type} (weight : α → ℝ) (c : Config α) (s : State α) : Prop :=  match c.focus with  | .nil => False  | .node l key r => Valid weight c.context l key r s
structureHeavyPath.Finger.History.Simulation.Outputpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Definitions/Abstract.lean:18
/-- One physical response, including its source cursor and exact trace cost. -/structure Output (α : Type) where  source : Config α  state : State α  instructions : List Multifinger.Opcode
defHeavyPath.Finger.History.Simulation.Output.costpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Definitions/Abstract.lean:24
def Output.cost {α : Type} (out : Output α) : Nat := out.instructions.length
defHeavyPath.Finger.History.Simulation.Policypropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Definitions/Abstract.lean:26
/-- A policy sees only the current source cursor, representation, and opcode. -/abbrev Policy (α : Type) := Config α → State α → Multifinger.Opcode → Option (Output α)

ConfigValid weight c s is History.Valid at a source cursor c. When the focus is empty it is False: an empty focus is not a finger, and no instruction can be performed at it. An Output is a response: the new source cursor, the new state, and the emitted physical instructions. Its cost is their number, one per pointer instruction. A Policy is a function of the current source cursor, the current state and the next opcode only. It cannot see later instructions or requests, so a run of a policy is online by construction. It may return none.

defHeavyPath.Finger.History.Simulation.PolicyValidpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Definitions/Abstract.lean:29
/-- Every legal instruction preserves the whole state; illegal instructionsare rejected. The potential includes all nested payload occurrences. -/def PolicyValid {α : Type} (weight : α → ℝ) (policy : Policy α) : Prop :=  ∀ c s op, ConfigValid weight c s →    match perform op c with    | none => policy c s op = none    | some next => ∃ out, policy c s op = some out ∧ out.source = next ∧        ConfigValid weight out.source out.state ∧        Multifinger.replay out.instructions ⟨s.pair.tree, []⟩ = some ⟨out.state.pair.tree, []⟩ ∧        out.cost + out.state.potential ≤ 62 + s.potential
defHeavyPath.Finger.History.Simulation.PolicyBoundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Definitions/Abstract.lean:40
/-- The same causal policy retains a logarithmic worst-case response boundin addition to its global potential inequality. -/def PolicyBounded {α : Type} (weight : α → ℝ) (policy : Policy α) : Prop :=  PolicyValid weight policy ∧ ∀ c s op out, ConfigValid weight c s →    policy c s op = some out → (out.cost : ℝ) ≤ 34 + 24 * Real.logb 2 s.pair.tree.size
defHeavyPath.Finger.History.Simulation.PolicyWithinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Definitions/Abstract.lean:46
/-- A bounded causal policy whose actual emitted program retains a structuralkey-depth certificate at every physical interruption. -/def PolicyWithin {α : Type} (weight : α → ℝ) (policy : Policy α) : Prop :=  PolicyBounded weight policy ∧ ∀ c s op out, ConfigValid weight c s →    policy c s op = some out → ∀ cut, ∃ middle,      Multifinger.replay (out.instructions.take cut) ⟨s.pair.tree, []⟩ = some middle ∧      Multifinger.replay (out.instructions.drop cut) middle = some ⟨out.state.pair.tree, []⟩ ∧      ∀ x, Tree.depth middle.tree x ≤ 16 * Tree.depth s.pair.tree x + 96

These are three levels of contract:

  • PolicyValid weight p: from any valid pair (c, s), an illegal instruction is rejected (none). A legal one is answered by an output whose source cursor is the true successor perform op c, whose state is valid for it, whose instructions replay (Multifinger.replay) from the physical root to the new physical root, and whose cost satisfies cost+Φ′≤62+Φ\text{cost} + \Phi' \le 62 + \Phi.
  • PolicyBounded: in addition, every response costs at most 34+24log⁡2n34 + 24\log_2 n.
  • PolicyWithin: in addition, for every cut point of a response there is an intermediate pointer configuration middle, possibly with the cursor away from the root. The first cut instructions lead to middle, the remaining ones lead from middle to the final configuration, and every rank xx has depth at most 16 depth0(x)+9616\,\mathrm{depth}_0(x) + 96 in middle. This is a certificate about the emitted program itself, not just about some trace with the same endpoints.

38.4.6.1 One step

Theorem (one step). From a valid pair (c,s)(c, s) and a legal source instruction, there is a valid state for the successor cursor, reached from the physical root by a trace back to the physical root, of amortized cost at most 6262 and worst-case cost at most 34+24log⁡2n34 + 24\log_2 n. Along the trace the size is constant, and every depth stays at most 1616 times its old value plus 9696. Recording such a trace gives a response with all three properties. Hence policies of all three strengths exist.

theoremHeavyPath.Finger.History.Simulation.Results.steppropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:10
theorem step {α : Type} {weight : α → ℝ} {c next : Config α} {s : State α}    {op : Multifinger.Opcode} (valid : ConfigValid weight c s)    (legal : perform op c = some next) :    ∃ (after : State α) (cost : Nat), ConfigValid weight next after ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨after.pair.tree, []⟩ cost ∧      cost + after.potential ≤ 62 + s.potential :=  RotationBST.HeavyPath.Finger.History.Simulation.step valid legal
theoremHeavyPath.Finger.History.Simulation.Results.step_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:90
theorem step_bounded {α : Type} {weight : α → ℝ} {c next : Config α} {s : State α}    {op : Multifinger.Opcode} (valid : ConfigValid weight c s)    (legal : perform op c = some next) :    ∃ (after : State α) (cost : Nat), ConfigValid weight next after ∧      Pointer.Trace ⟨s.pair.tree, []⟩ ⟨after.pair.tree, []⟩ cost ∧      cost + after.potential ≤ 62 + s.potential ∧      (cost : ℝ) ≤ 34 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Simulation.step_bounded valid legal
theoremHeavyPath.Finger.History.Simulation.Results.step_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:102
theorem step_within {α : Type} {weight : α → ℝ} {c next : Config α} {s : State α}    {op : Multifinger.Opcode} (valid : ConfigValid weight c s)    (legal : perform op c = some next) :    ∃ (after : State α) (cost : Nat), ConfigValid weight next after ∧      Pointer.TraceWithin (fun t => t.size = s.pair.tree.size ∧        ∀ x, Tree.depth t x ≤ 16 * Tree.depth s.pair.tree x + 96) ⟨s.pair.tree, []⟩ ⟨after.pair.tree, []⟩ cost ∧      cost + after.potential ≤ 62 + s.potential ∧      (cost : ℝ) ≤ 34 + 24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Simulation.step_within valid legal
theoremHeavyPath.Finger.History.Simulation.Results.response_exists_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:112
theorem response_exists_within {α : Type} {weight : α → ℝ} {c : Config α} {s : State α}    {op : Multifinger.Opcode} (valid : ConfigValid weight c s)    (legal : (perform op c).isSome = true) :    ∃ out : Output α, perform op c = some out.source ∧ ConfigValid weight out.source out.state ∧      Multifinger.replay out.instructions ⟨s.pair.tree, []⟩ = some ⟨out.state.pair.tree, []⟩ ∧      out.cost + out.state.potential ≤ 62 + s.potential ∧      (out.cost : ℝ) ≤ 34 + 24 * Real.logb 2 s.pair.tree.size ∧      ∀ cut, ∃ middle,        Multifinger.replay (out.instructions.take cut) ⟨s.pair.tree, []⟩ = some middle ∧        Multifinger.replay (out.instructions.drop cut) middle = some ⟨out.state.pair.tree, []⟩ ∧        ∀ x, Tree.depth middle.tree x ≤ 16 * Tree.depth s.pair.tree x + 96 :=  RotationBST.HeavyPath.Finger.History.Simulation.response_exists_within valid legal
theoremHeavyPath.Finger.History.Simulation.Results.policy_existspropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:18
theorem policy_exists {α : Type} (weight : α → ℝ) : ∃ p : Policy α, PolicyValid weight p :=  RotationBST.HeavyPath.Finger.History.Simulation.policy_exists weight
theoremHeavyPath.Finger.History.Simulation.Results.policy_bounded_existspropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:99
theorem policy_bounded_exists {α : Type} (weight : α → ℝ) : ∃ p : Policy α, PolicyBounded weight p :=  RotationBST.HeavyPath.Finger.History.Simulation.policy_bounded_exists weight
theoremHeavyPath.Finger.History.Simulation.Results.policy_within_existspropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:125
theorem policy_within_exists {α : Type} (weight : α → ℝ) : ∃ p : Policy α, PolicyWithin weight p :=  RotationBST.HeavyPath.Finger.History.Simulation.policy_within_exists weight

The step lemmas are a case analysis on the opcode, using the six lemmas of Section 38.4.5. response_exists_within turns the trace into an explicit instruction list with the prefix certificate. The policy behind policy_within_exists picks, by choice, one such response at each valid configuration and legal opcode, and returns none otherwise. Since PolicyWithin contains PolicyBounded, which contains PolicyValid, a single policy has all three properties. As elsewhere in the abstract online model, the policy’s internal computation is not charged. Only emitted pointer instructions count.

38.4.7 Running a policy

defHeavyPath.Finger.History.Simulation.sourceRunpropextStructures/HeavyPath/Finger/History/Simulation/Definitions/Abstract.lean:55
/-- Execute a finite source instruction stream, rejecting the first illegalinstruction. This is the reference semantics, independent of a policy. -/def sourceRun {α : Type} (c : Config α) : List Multifinger.Opcode → Option (Config α)  | [] => some c  | op :: ops => (perform op c).bind (fun next => sourceRun next ops)
defHeavyPath.Finger.History.Simulation.runpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Definitions/Abstract.lean:61
/-- Execute the same fixed policy at every instruction. Only accumulatedphysical trace cost is added; the final state carries its remaining credit. -/def run {α : Type} (p : Policy α) (c : Config α) (s : State α) :    List Multifinger.Opcode → Option (Output α)  | [] => some ⟨c, s, []⟩  | op :: ops => (p c s op).bind fun first =>      (run p first.source first.state ops).map fun last =>        ⟨last.source, last.state, first.instructions ++ last.instructions⟩

sourceRun c ops is the reference semantics of a source instruction stream: it applies LabelledCursor.perform in turn and fails at the first illegal instruction. run p c s ops answers the same stream with the policy, one instruction at a time. It concatenates the emitted programs, and it fails as soon as the policy does. The final state carries the remaining potential, and the output’s cost is only the emitted instructions.

Theorem (runs are online). Running on xs ++ ys is running on xs and then continuing from the output on ys. If the run on xs ++ ys succeeds, then so does the run on xs, and its program is a prefix of the whole program.

theoremHeavyPath.Finger.History.Simulation.Results.run_appendpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:21
theorem run_append {α : Type} (p : Policy α) (c : Config α) (s : State α)    (xs ys : List Multifinger.Opcode) :    run p c s (xs ++ ys) = (run p c s xs).bind fun first =>      (run p first.source first.state ys).map fun last =>        ⟨last.source, last.state, first.instructions ++ last.instructions⟩ :=  RotationBST.HeavyPath.Finger.History.Simulation.run_append p c s xs ys
theoremHeavyPath.Finger.History.Simulation.Results.run_prefixpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:28
theorem run_prefix {α : Type} (p : Policy α) (c : Config α) (s : State α)    (xs ys : List Multifinger.Opcode) {out : Output α}    (completed : run p c s (xs ++ ys) = some out) :    ∃ first, run p c s xs = some first ∧ first.instructions <+: out.instructions :=  RotationBST.HeavyPath.Finger.History.Simulation.run_prefix p c s xs ys completed

These two facts need no validity assumption. They hold for any policy, because a policy never sees the future.

Theorem (correct simulation). Let pp satisfy PolicyValid, and let (c,s)(c, s) be valid. If a stream of mm source instructions is legal from cc and ends at c′c', then the run succeeds and ends at c′c' in a valid state. Its program replays from the physical root to the final physical root, and cost+Φ′≤62m+Φ\text{cost} + \Phi' \le 62m + \Phi. The run fails exactly when the source stream is illegal.

theoremHeavyPath.Finger.History.Simulation.Results.run_specpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:34
theorem run_spec {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) {c final : Config α} {s : State α}    {ops : List Multifinger.Opcode} (valid : ConfigValid weight c s)    (legal : sourceRun c ops = some final) :    ∃ out, run p c s ops = some out ∧ out.source = final ∧      ConfigValid weight out.source out.state ∧      Multifinger.replay out.instructions ⟨s.pair.tree, []⟩ = some ⟨out.state.pair.tree, []⟩ ∧      out.cost + out.state.potential ≤ 62 * ops.length + s.potential :=  RotationBST.HeavyPath.Finger.History.Simulation.run_spec policyValid valid legal
theoremHeavyPath.Finger.History.Simulation.Results.run_none_iffpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:44
theorem run_none_iff {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) {c : Config α} {s : State α}    (valid : ConfigValid weight c s) (ops : List Multifinger.Opcode) :    run p c s ops = none ↔ sourceRun c ops = none :=  RotationBST.HeavyPath.Finger.History.Simulation.run_none_iff policyValid valid ops

Theorem (initialized run). For a valid policy and a source finger in a positively weighted tree TT with nn nodes, there is a starting state, reached from TT by a startup trace of cost s0s_0 with s0+Φ0≤39ns_0 + \Phi_0 \le 39n. For every legal stream of mm instructions, the run from it ends at the right source cursor in a valid state. The startup and the run form a single pointer trace from TT of cost s0+Cs_0 + C, and s0+C+Φ≤39n+62ms_0 + C + \Phi \le 39n + 62m.

theoremHeavyPath.Finger.History.Simulation.Results.initialized_runpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:50
theorem initialized_run {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) {cs : List (Frame α)}    {left right : LabelledTree α} {key : α}    (positive : Positive weight (plug cs (.node left key right))) :    ∃ (start : State α) (startupCost : Nat),      ConfigValid weight ⟨.node left key right, cs⟩ start ∧      Pointer.Trace ⟨(plug cs (.node left key right)).erase, []⟩ ⟨start.pair.tree, []⟩ startupCost ∧      startupCost + start.potential ≤ 39 * (plug cs (.node left key right)).erase.size ∧      ∀ (ops : List Multifinger.Opcode) (final : Config α),        sourceRun ⟨.node left key right, cs⟩ ops = some final →        ∃ out, run p ⟨.node left key right, cs⟩ start ops = some out ∧ out.source = final ∧          ConfigValid weight out.source out.state ∧          Pointer.Trace ⟨(plug cs (.node left key right)).erase, []⟩            ⟨out.state.pair.tree, []⟩ (startupCost + out.cost) ∧          startupCost + out.cost + out.state.potential ≤            39 * (plug cs (.node left key right)).erase.size + 62 * ops.length :=  RotationBST.HeavyPath.Finger.History.Simulation.initialized_run policyValid positive

The starting state is chosen before the instruction stream, in the same ∃ … ∀ order as the statement. So one physical start serves every future stream.

Theorem (between instructions). In any valid configuration, the physical root holds the source finger’s rank. The node of rank ii is at depth at most 15+15log⁡2(W/wi)15 + 15\log_2(W/w_i), and a round trip to it from the root costs 1+2k≤31+30log⁡2(W/wi)1 + 2k \le 31 + 30\log_2(W/w_i).

theoremHeavyPath.Finger.History.Simulation.Results.root_keypropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:68
theorem root_key {α : Type} {weight : α → ℝ} {c : Config α} {s : State α}    (valid : ConfigValid weight c s) :    (Pointer.Config.mk s.pair.tree []).key? = c.erase.key? :=  RotationBST.HeavyPath.Finger.History.Simulation.root_key valid
theoremHeavyPath.Finger.History.Simulation.Results.depthpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:73
theorem depth {α : Type} {weight : α → ℝ} {c : Config α} {s : State α}    (valid : ConfigValid weight c s) (rank : Fin c.tree.inorder.length) :    (Tree.depth s.pair.tree rank.val : ℝ) ≤      15 + 15 * Real.logb 2 (HeavyPath.mass weight c.tree /        weight (c.tree.inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Finger.History.Simulation.depth valid rank
theoremHeavyPath.Finger.History.Simulation.Results.search_walkpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Abstract.lean:80
theorem search_walk {α : Type} {weight : α → ℝ} {c : Config α} {s : State α}    (valid : ConfigValid weight c s) (rank : Fin c.tree.inorder.length) :    ∃ (visited : Pointer.Config) (cost : Nat),      visited.tree = s.pair.tree ∧ visited.key? = some rank.val ∧      Pointer.Trace ⟨s.pair.tree, []⟩ visited cost ∧      Pointer.Trace visited ⟨s.pair.tree, []⟩ cost ∧      (1 + 2 * cost : ℝ) ≤ 31 + 30 * Real.logb 2        (HeavyPath.mass weight c.tree / weight (c.tree.inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Finger.History.Simulation.search_walk valid rank

These restate Section 38.4.3 for a cursor c, with c.tree the whole source tree.

38.4.8 Cheapest representations

The bound cost+Φ′≤62m+Φ\text{cost} + \Phi' \le 62m + \Phi charges the starting potential to the simulation. Results.simulation instead bounds the cost by a multiple of mm alone, with no additive potential term. The tool is the cheapest representation of each source cursor. The definitions are in Simulation/Minimum/Definitions/Abstract.lean.

defHeavyPath.Finger.History.Simulation.Minimum.potentialpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Minimum/Definitions/Abstract.lean:9
/-- The least total potential among representations of the same labelledsource cursor. This depends on the fixed analysis weights, not on future input.For an unrepresentable cursor, the natural-number infimum is zero. -/noncomputable def potential {α : Type} (weight : α → ℝ) (c : LabelledCursor.Config α) : Nat :=  sInf {n | ∃ s : State α, ConfigValid weight c s ∧ s.potential = n}
defHeavyPath.Finger.History.Simulation.Minimum.excesspropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Minimum/Definitions/Abstract.lean:15
/-- Credit above the minimum for this source cursor. Minimum representationsstart with zero excess even when every representation has positive raw credit. -/noncomputable def excess {α : Type} (weight : α → ℝ) (c : LabelledCursor.Config α)    (s : State α) : Nat := s.potential - potential weight c

potential weight c is the least potential of any valid state for the source cursor c. It is an infimum over natural numbers, which is attained whenever some valid state exists. When none exists, for instance when the focus is empty, the infimum is 00: a totalized value that the theorems never use. It depends on c and the weights only, not on the history that led to c. excess weight c s is the credit of s above that minimum.

Theorem (minimum). For a valid pair (c,s)(c, s): the minimum is at most Φ(s)\Phi(s), it is attained by some valid state, and Φ(s)\Phi(s) is the excess plus the minimum.

theoremHeavyPath.Finger.History.Simulation.Minimum.Results.potential_lepropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Minimum/Abstract.lean:10
theorem potential_le {α : Type} {weight : α → ℝ} {c : Config α} {s : State α}    (valid : ConfigValid weight c s) : potential weight c ≤ s.potential :=  RotationBST.HeavyPath.Finger.History.Simulation.Minimum.potential_le valid
theoremHeavyPath.Finger.History.Simulation.Minimum.Results.attainedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Minimum/Abstract.lean:14
theorem attained {α : Type} {weight : α → ℝ} {c : Config α} {s : State α}    (valid : ConfigValid weight c s) :    ∃ best, ConfigValid weight c best ∧ best.potential = potential weight c :=  RotationBST.HeavyPath.Finger.History.Simulation.Minimum.attained valid
theoremHeavyPath.Finger.History.Simulation.Minimum.Results.excess_addpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Minimum/Abstract.lean:19
theorem excess_add {α : Type} {weight : α → ℝ} {c : Config α} {s : State α}    (valid : ConfigValid weight c s) : excess weight c s + potential weight c = s.potential :=  RotationBST.HeavyPath.Finger.History.Simulation.Minimum.excess_add valid

Theorem (the minimum moves slowly). Suppose a stream of mm source instructions leads from cc to c′c' and c′c' has a valid state. Then the minimum potential at cc is at most 186m186m plus the minimum at c′c'. Consequently, a run of a valid policy satisfies

cost+excess(c′,s′)  ≤  248m+excess(c,s).\text{cost} + \mathrm{excess}(c', s') \;\le\; 248m + \mathrm{excess}(c, s).
theoremHeavyPath.Finger.History.Simulation.Minimum.Results.potential_droppropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Minimum/Abstract.lean:23
theorem potential_drop {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) {c final : Config α} {s : State α}    {ops : List Multifinger.Opcode} (finalValid : ConfigValid weight final s)    (legal : sourceRun c ops = some final) :    potential weight c ≤ 186 * ops.length + potential weight final :=  RotationBST.HeavyPath.Finger.History.Simulation.Minimum.potential_drop policyValid finalValid legal
theoremHeavyPath.Finger.History.Simulation.Minimum.Results.run_excesspropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Minimum/Abstract.lean:30
theorem run_excess {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) {c final : Config α} {s : State α}    {ops : List Multifinger.Opcode} {out : Output α} (valid : ConfigValid weight c s)    (legal : sourceRun c ops = some final) (completed : run p c s ops = some out) :    out.cost + excess weight out.source out.state ≤ 248 * ops.length + excess weight c s :=  RotationBST.HeavyPath.Finger.History.Simulation.Minimum.run_excess policyValid valid legal completed

The first bound runs the simulation backwards. Every source instruction can be undone by at most three source instructions (Opcode.inverse), each of amortized cost 6262, and 3⋅62=1863 \cdot 62 = 186. Adding this to the forward bound of 6262 gives 248248. Starting from an attained minimum, the excess is 00, so the run costs at most 248m248m. This is the constant 248248 in Results.simulation.

38.4.9 Interrupting a response

The theorems of this section, in Simulation/Interruption/Abstract.lean, bound the physical tree at an arbitrary cut point of the emitted program, as Theorem 6 requires. A cut point is a natural number cut: the configuration middle is reached by the first cut instructions, and the remaining instructions lead from middle to the end. Cuts beyond the end give the final configuration.

Theorem (interrupted response, worst-case route). For a bounded policy and a valid pair (c,s)(c, s), every cut of one response reaches a configuration in which the node of rank ii has depth at most

49+15log⁡2Wwi+24log⁡2n.49 + 15\log_2 \frac{W}{w_i} + 24\log_2 n.

With unit weights this is 49+39log⁡2n49 + 39\log_2 n, at every cut of a single response and of a whole run.

theoremHeavyPath.Finger.History.Simulation.Interruption.Results.responsepropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Interruption/Abstract.lean:10
theorem response {α : Type} {weight : α → ℝ} {p : Policy α}    (bounded : PolicyBounded weight p) {c : Config α} {s : State α}    (valid : ConfigValid weight c s) {op : Multifinger.Opcode} {out : Output α}    (responded : p c s op = some out) :    ConfigValid weight out.source out.state ∧      Multifinger.replay out.instructions ⟨s.pair.tree, []⟩ = some ⟨out.state.pair.tree, []⟩ ∧      out.cost + out.state.potential ≤ 62 + s.potential ∧      (out.cost : ℝ) ≤ 34 + 24 * Real.logb 2 s.pair.tree.size ∧      ∀ cut, ∃ middle,        Multifinger.replay (out.instructions.take cut) ⟨s.pair.tree, []⟩ = some middle ∧        Multifinger.replay (out.instructions.drop cut) middle = some ⟨out.state.pair.tree, []⟩ ∧        ∀ rank : Fin c.tree.inorder.length,          (Tree.depth middle.tree rank.val : ℝ) ≤            49 + 15 * Real.logb 2 (HeavyPath.mass weight c.tree /              weight (c.tree.inorder[rank.val]'rank.isLt)) +                24 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Simulation.Interruption.response bounded valid responded
theoremHeavyPath.Finger.History.Simulation.Interruption.Results.response_uniformpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Interruption/Abstract.lean:28
theorem response_uniform {α : Type} {p : Policy α}    (bounded : PolicyBounded (fun _ => 1) p) {c : Config α} {s : State α}    (valid : ConfigValid (fun _ => 1) c s) {op : Multifinger.Opcode} {out : Output α}    (responded : p c s op = some out) (cut : Nat) :    ∃ middle,      Multifinger.replay (out.instructions.take cut) ⟨s.pair.tree, []⟩ = some middle ∧      Multifinger.replay (out.instructions.drop cut) middle = some ⟨out.state.pair.tree, []⟩ ∧      ∀ x < s.pair.tree.size,        (Tree.depth middle.tree x : ℝ) ≤ 49 + 39 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Simulation.Interruption.response_uniform bounded valid responded cut
theoremHeavyPath.Finger.History.Simulation.Interruption.Results.run_uniform_prefixpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Interruption/Abstract.lean:39
theorem run_uniform_prefix {α : Type} {p : Policy α}    (bounded : PolicyBounded (fun _ => 1) p) {c : Config α} {s : State α}    (valid : ConfigValid (fun _ => 1) c s) {ops : List Multifinger.Opcode} {out : Output α}    (completed : run p c s ops = some out) (cut : Nat) :    ∃ middle,      Multifinger.replay (out.instructions.take cut) ⟨s.pair.tree, []⟩ = some middle ∧      Multifinger.replay (out.instructions.drop cut) middle = some ⟨out.state.pair.tree, []⟩ ∧      ∀ x < s.pair.tree.size,        (Tree.depth middle.tree x : ℝ) ≤ 49 + 39 * Real.logb 2 s.pair.tree.size :=  RotationBST.HeavyPath.Finger.History.Simulation.Interruption.run_uniform_prefix bounded valid completed cut

The argument is elementary. One pointer instruction changes any depth by at most one, a response has at most 34+24log⁡2n34 + 24\log_2 n instructions, and the response starts from a valid state, where depths are at most 15+15log⁡2(W/wi)15 + 15\log_2(W/w_i). For a whole run, the cut falls inside one response, and that response starts from the valid state left by the previous ones. The bound is in terms of the starting tree c.tree: rotations change neither the total weight nor the inorder, so rank ii names the same label throughout. The deamortization with unit weights uses run_uniform_prefix (via Deamortization.Finger, Chapter 30).

Theorem (interrupted response, weighted). For a policy with the PolicyWithin certificate, every cut of a response, and every cut of a whole run, reaches a configuration in which the node of rank ii has depth at most

336+240log⁡2Wwi.336 + 240\log_2 \frac{W}{w_i}.
theoremHeavyPath.Finger.History.Simulation.Interruption.Results.response_weightedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Interruption/Abstract.lean:90
theorem response_weighted {α : Type} {weight : α → ℝ} {p : Policy α}    (certified : PolicyWithin weight p) {c : Config α} {s : State α}    (valid : ConfigValid weight c s) {op : Multifinger.Opcode} {out : Output α}    (responded : p c s op = some out) :    ConfigValid weight out.source out.state ∧      Multifinger.replay out.instructions ⟨s.pair.tree, []⟩ = some ⟨out.state.pair.tree, []⟩ ∧      out.cost + out.state.potential ≤ 62 + s.potential ∧      (out.cost : ℝ) ≤ 34 + 24 * Real.logb 2 s.pair.tree.size ∧      ∀ cut, ∃ middle,        Multifinger.replay (out.instructions.take cut) ⟨s.pair.tree, []⟩ = some middle ∧        Multifinger.replay (out.instructions.drop cut) middle = some ⟨out.state.pair.tree, []⟩ ∧        ∀ rank : Fin c.tree.inorder.length,          (Tree.depth middle.tree rank.val : ℝ) ≤            336 + 240 * Real.logb 2 (HeavyPath.mass weight c.tree /              weight (c.tree.inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Finger.History.Simulation.Interruption.response_weighted certified valid responded
theoremHeavyPath.Finger.History.Simulation.Interruption.Results.run_weighted_prefixpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Interruption/Abstract.lean:107
theorem run_weighted_prefix {α : Type} {weight : α → ℝ} {p : Policy α}    (certified : PolicyWithin weight p) {c : Config α} {s : State α}    (valid : ConfigValid weight c s) {ops : List Multifinger.Opcode} {out : Output α}    (completed : run p c s ops = some out) (cut : Nat) :    ∃ middle,      Multifinger.replay (out.instructions.take cut) ⟨s.pair.tree, []⟩ = some middle ∧      Multifinger.replay (out.instructions.drop cut) middle = some ⟨out.state.pair.tree, []⟩ ∧      ∀ rank : Fin c.tree.inorder.length,        (Tree.depth middle.tree rank.val : ℝ) ≤          336 + 240 * Real.logb 2 (HeavyPath.mass weight c.tree /            weight (c.tree.inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Finger.History.Simulation.Interruption.run_weighted_prefix certified valid completed cut

Here 336=16⋅15+96336 = 16 \cdot 15 + 96 and 240=16⋅15240 = 16 \cdot 15. The certificate’s multiplicative form avoids the log⁡2n\log_2 n term, which a weighted bound cannot afford: a heavy key must stay shallow even while a response deep in the tree is executed. This is the depth clause of Results.simulation.

Theorem (detours). With unit weights, at any cut of a run and for every key xx, there is a navigation-only detour from the interrupted configuration to xx and back, of total length (plus one for the request) at most 197+156log⁡2n197 + 156\log_2 n. The detour is empty if the cursor is already on xx. Inserting it at the cut leaves the program legal with the same final tree, and the tree does not change during the detour.

theoremHeavyPath.Finger.History.Simulation.Interruption.Results.run_detourpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Interruption/Abstract.lean:50
theorem run_detour {α : Type} {p : Policy α}    (bounded : PolicyBounded (fun _ => 1) p) {c : Config α} {s : State α}    (valid : ConfigValid (fun _ => 1) c s) {ops : List Multifinger.Opcode} {out : Output α}    (completed : run p c s ops = some out) (cut : Nat) :    ∃ middle,      Multifinger.replay (out.instructions.take cut) ⟨s.pair.tree, []⟩ = some middle ∧      Multifinger.replay (out.instructions.drop cut) middle = some ⟨out.state.pair.tree, []⟩ ∧      middle.focus ≠ .nil ∧      ∀ x < s.pair.tree.size, ∃ (visited : Pointer.Config) (before after : List Multifinger.Opcode),        Multifinger.replay before middle = some visited ∧ visited.key? = some x ∧        Multifinger.replay after visited = some middle ∧        (1 + before.length + after.length : ℝ) ≤ 197 + 156 * Real.logb 2 s.pair.tree.size ∧        (middle.key? = some x → before = [] ∧ after = []) ∧        Multifinger.replay (out.instructions.take cut ++ before ++ after ++ out.instructions.drop cut)          ⟨s.pair.tree, []⟩ = some ⟨out.state.pair.tree, []⟩ ∧        (∀ pause, ∃ cursor, Multifinger.replay (before.take pause) middle = some cursor ∧          cursor.tree = middle.tree) ∧        (∀ pause, ∃ cursor, Multifinger.replay (after.take pause) visited = some cursor ∧          cursor.tree = middle.tree) :=  RotationBST.HeavyPath.Finger.History.Simulation.Interruption.run_detour bounded valid completed cut

This is the paper’s “access this element by moving the finger to it and back”: go up to the root and down to xx, then return, each leg bounded by the interrupted depth 49+39log⁡2n49 + 39\log_2 n. The interrupted cursor may be anywhere in the tree. The conclusion middle.focus ≠ .nil says that it is on a node, not on an empty subtree, so a detour can start there.

Theorem (a search window). Use unit weights. Suppose a source stream serves a request for rank target (in the sense of Requests.Serves below), and let budget be at least 49+39log⁡2n49 + 39\log_2 n. Then the run of the stream succeeds with the usual amortized bound, and the physical machine has a window for the request: a number consumed ≤\le budget of the run’s instructions, and a walk from the physical root that visits target and ends exactly where those consumed instructions end. The walk has length at most 5⋅5 \cdot consumed, so at most 5⋅5 \cdot budget. Either the whole budget is consumed, or the cursor is on target after the consumed instructions.

theoremHeavyPath.Finger.History.Simulation.Interruption.Results.search_windowpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Interruption/Abstract.lean:71
theorem search_window {α : Type} {p : Policy α}    (bounded : PolicyBounded (fun _ => 1) p) {c final : Config α} {s : State α}    (valid : ConfigValid (fun _ => 1) c s) {ops : List Multifinger.Opcode} {target budget : Nat}    (targetValid : target < s.pair.tree.size) (search : Requests.Serves c ops target final)    (budgetBound : 49 + 39 * Real.logb 2 s.pair.tree.size ≤ budget) :    ∃ (out : Output α) (consumed : Nat) (middle visited : Pointer.Config)      (before after : List Multifinger.Opcode),      run p c s ops = some out ∧ out.source = final ∧      out.cost + out.state.potential ≤ 62 * ops.length + s.potential ∧      consumed ≤ budget ∧ consumed ≤ out.instructions.length ∧      Multifinger.replay (out.instructions.take consumed) ⟨s.pair.tree, []⟩ = some middle ∧      Multifinger.replay (out.instructions.drop consumed) middle = some ⟨out.state.pair.tree, []⟩ ∧      Multifinger.replay before ⟨s.pair.tree, []⟩ = some visited ∧ visited.key? = some target ∧      Multifinger.replay after visited = some middle ∧      before.length + after.length ≤ 5 * consumed ∧      1 + before.length + after.length ≤ 1 + 5 * budget ∧      (consumed = budget ∨ middle.key? = some target) :=  RotationBST.HeavyPath.Finger.History.Simulation.Interruption.search_window bounded valid targetValid search budgetBound

This is Results.serve (Chapter 30) specialized to this simulation, whose interruption depths satisfy that theorem’s height hypothesis. A scheduler can answer every request within 1+5⋅1 + 5\cdotbudget physical instructions while making progress on the pending simulated work.

38.4.10 Serving requests

So far the source has been a stream of instructions. A source BST algorithm turns requests into such streams. The definitions are in Simulation/Requests/Definitions/Abstract.lean.

defHeavyPath.Finger.History.Simulation.Requests.ServespropextStructures/HeavyPath/Finger/History/Simulation/Requests/Definitions/Abstract.lean:9
/-- A source search visits the requested rank at an instruction boundary.The cursor persists between searches; a visit may occur before any movement. -/def Serves {α : Type} (c : Config α) (ops : List Multifinger.Opcode)    (key : Nat) (final : Config α) : Prop :=  ∃ before after visited, ops = before ++ after ∧ sourceRun c before = some visited ∧    visited.erase.key? = some key ∧ sourceRun visited after = some final

Serves c ops key final says that the source stream ops from cursor c visits the node of rank key at some instruction boundary and ends at final. The stream splits as before ++ after, the cursor after before is on key, and after is arbitrary further work. The source finger persists between requests: a search starts wherever the previous one ended, as in the paper’s BST model, and before may be empty if the finger already is on the key.

structureHeavyPath.Finger.History.Simulation.Requests.AlgorithmpropextStructures/HeavyPath/Finger/History/Simulation/Requests/Definitions/Abstract.lean:16
/-- A source BST algorithm sees past requests, its current cursor and the nextrank. Correctness requires a legal search but permits arbitrary later work. -/structure Algorithm (α : Type) where  step : List Nat → Config α → Nat → List Multifinger.Opcode × Config α  correct : ∀ past c key, c.focus ≠ .nil → key < c.tree.erase.size →    Serves c (step past c key).1 key (step past c key).2
theoremHeavyPath.Finger.History.Simulation.Requests.Algorithm.correctpropextStructures/HeavyPath/Finger/History/Simulation/Requests/Definitions/Abstract.lean:20
correct
Statement reads only Structures/HeavyPath/Finger/History/Simulation/Requests/Definitions/Abstract.lean and its imports
defHeavyPath.Finger.History.Simulation.Requests.Algorithm.runFrompropextStructures/HeavyPath/Finger/History/Simulation/Requests/Definitions/Abstract.lean:23
def Algorithm.runFrom {α : Type} (a : Algorithm α) (past : List Nat) (c : Config α) :    List Nat → List Multifinger.Opcode × Config α  | [] => ([], c)  | key :: keys =>      let first := a.step past c key      let last := a.runFrom (past ++ [key]) first.2 keys      (first.1 ++ last.1, last.2)

An Algorithm has a step that sees the past requests, the current source cursor and the next requested rank. It returns a source instruction stream and the resulting cursor. Its correct field requires, for a nonempty focus and an in-range rank, that the stream serve the request and end at the returned cursor. Correctness constrains legality and the visit, not the cost, and an algorithm may do arbitrary work after the visit. runFrom past c keys concatenates the streams over a request list and returns the final cursor. The source cost of a request sequence is the length of this concatenated stream. This is a persistent-finger counterpart of the online algorithms of Chapter 5. Chapter 30 connects the two.

defHeavyPath.Finger.History.Simulation.Requests.runpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Definitions/Abstract.lean:31
/-- Lift the fixed physical instruction policy request by request. Emittedinstructions and source state are carried forward without seeing future keys. -/def run {α : Type} (p : Policy α) (a : Algorithm α) (past : List Nat)    (c : Config α) (s : State α) : List Nat → Option (Output α)  | [] => some ⟨c, s, []⟩  | key :: keys =>      (Simulation.run p c s (a.step past c key).1).bind fun first =>        (run p a (past ++ [key]) first.source first.state keys).map fun last =>          ⟨last.source, last.state, first.instructions ++ last.instructions⟩

Requests.run p a past c s keys lifts the policy request by request. For each key it runs the policy on the algorithm’s stream for that key. No step sees a future key.

Basic facts. Erasing labels commutes with running: a labelled source stream is a legal pointer program on the unlabelled tree with the same result, so source costs are pointer-model costs. Algorithms exist, so the correct obligation is satisfiable. Both the source algorithm and the lifted run are compositional and prefix-preserving. A request-by-request run equals the instruction-by-instruction run on the concatenated stream, which is legal. Every valid state has potential at most 20n−2020n - 20.

theoremHeavyPath.Finger.History.Simulation.Requests.Results.source_erasepropext · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:10
theorem source_erase {α : Type} (c : Config α) (ops : List Multifinger.Opcode) :    (sourceRun c ops).map Config.erase = Multifinger.replay ops c.erase :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.source_erase c ops
theoremHeavyPath.Finger.History.Simulation.Requests.Results.algorithm_existspropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:14
theorem algorithm_exists (α : Type) : Nonempty (Algorithm α) :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.algorithm_exists α
theoremHeavyPath.Finger.History.Simulation.Requests.Results.source_requests_appendpropextStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:28
theorem source_requests_append {α : Type} (a : Algorithm α) (past : List Nat) (c : Config α)    (xs ys : List Nat) :    a.runFrom past c (xs ++ ys) =      let first := a.runFrom past c xs      let last := a.runFrom (past ++ xs) first.2 ys      (first.1 ++ last.1, last.2) :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.source_requests_append a past c xs ys
theoremHeavyPath.Finger.History.Simulation.Requests.Results.run_appendpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:36
theorem run_append {α : Type} (p : Policy α) (a : Algorithm α) (past : List Nat)    (c : Config α) (s : State α) (xs ys : List Nat) :    run p a past c s (xs ++ ys) = (run p a past c s xs).bind fun first =>      (run p a (past ++ xs) first.source first.state ys).map fun last =>        ⟨last.source, last.state, first.instructions ++ last.instructions⟩ :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.run_append p a past c s xs ys
theoremHeavyPath.Finger.History.Simulation.Requests.Results.run_prefixpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:43
theorem run_prefix {α : Type} (p : Policy α) (a : Algorithm α) (past : List Nat)    (c : Config α) (s : State α) (xs ys : List Nat) {out : Output α}    (completed : run p a past c s (xs ++ ys) = some out) :    ∃ first, run p a past c s xs = some first ∧ first.instructions <+: out.instructions :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.run_prefix p a past c s xs ys completed
theoremHeavyPath.Finger.History.Simulation.Requests.Results.flattenpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:95
theorem flatten {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) (a : Algorithm α) (past : List Nat)    {c : Config α} {s : State α} (valid : ConfigValid weight c s)    (keys : List Nat) (validKeys : ∀ x ∈ keys, x < c.tree.erase.size) {out : Output α}    (completed : run p a past c s keys = some out) :    Simulation.run p c s (a.runFrom past c keys).1 = some out ∧      sourceRun c (a.runFrom past c keys).1 = some (a.runFrom past c keys).2 :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.flatten policyValid a past valid keys validKeys completed
theoremHeavyPath.Finger.History.Simulation.Requests.Results.config_potential_boundpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:104
theorem config_potential_bound {α : Type} {weight : α → ℝ} {c : Config α} {s : State α}    (valid : ConfigValid weight c s) : s.potential + 20 ≤ 20 * c.tree.erase.size :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.config_potential_bound valid

flatten is what lets the results for instruction runs apply to request runs: Results.run_excess and Results.run_weighted_prefix are both applied to the flattened run in the proof of Results.simulation.

Theorem (one request). For a valid policy and a valid pair (c,s)(c, s), if a source stream serves rank key, then the simulated run serves it on the pointer machine. In the sense of Pointer.Serves, the physical program starts at the physical root, visits key, and ends in the final physical tree, at cost 1+C1 + C, where CC is the number of emitted instructions. The amortized bound C+Φ′≤62m+ΦC + \Phi' \le 62m + \Phi holds, and the visit happens at a recorded cut of the emitted program.

theoremHeavyPath.Finger.History.Simulation.Requests.Results.servespropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:17
theorem serves {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) {c final : Config α} {s : State α}    {ops : List Multifinger.Opcode} {key : Nat} (valid : ConfigValid weight c s)    (search : Serves c ops key final) :    ∃ out, Simulation.run p c s ops = some out ∧ out.source = final ∧      ConfigValid weight out.source out.state ∧      Multifinger.replay out.instructions ⟨s.pair.tree, []⟩ = some ⟨out.state.pair.tree, []⟩ ∧      out.cost + out.state.potential ≤ 62 * ops.length + s.potential ∧      Pointer.Serves s.pair.tree out.state.pair.tree key (1 + out.cost) :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.serves policyValid valid search
theoremHeavyPath.Finger.History.Simulation.Requests.Results.serves_recordedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:81
theorem serves_recorded {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) {c final : Config α} {s : State α}    {ops : List Multifinger.Opcode} {key : Nat} (valid : ConfigValid weight c s)    (search : Serves c ops key final) :    ∃ out, Simulation.run p c s ops = some out ∧ out.source = final ∧      ConfigValid weight out.source out.state ∧      Multifinger.replay out.instructions ⟨s.pair.tree, []⟩ = some ⟨out.state.pair.tree, []⟩ ∧      out.cost + out.state.potential ≤ 62 * ops.length + s.potential ∧      Pointer.Serves s.pair.tree out.state.pair.tree key (1 + out.cost) ∧      ∃ cut visited, cut ≤ out.instructions.length ∧        Multifinger.replay (out.instructions.take cut) ⟨s.pair.tree, []⟩ = some visited ∧        visited.key? = some key :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.serves_recorded policyValid valid search

The physical visit happens between two responses. When the source finger is on key, the physical root is the node of rank key (Results.root_key), so the visit needs no extra instructions. The recorded cut in serves_recorded is the visit hypothesis of Results.serve.

Theorem (request sequences). For a valid policy, any source algorithm, a valid pair (c,s)(c, s) and in-range requests, the lifted run succeeds and ends at the algorithm’s final cursor in a valid state. It is a Pointer.Execution of the request list from the physical tree, of cost ∣keys∣+C|\text{keys}| + C (one unit per request plus the emitted instructions), and C+Φ′≤62m+ΦC + \Phi' \le 62m + \Phi, where mm is the algorithm’s total source cost. Without any assumption on Φ\Phi, the work on any window of requests is at most 62(∣keys∣+m)+20n62(|\text{keys}| + m) + 20n.

theoremHeavyPath.Finger.History.Simulation.Requests.Results.run_specpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:49
theorem run_spec {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) (a : Algorithm α) (past : List Nat)    {c : Config α} {s : State α} (valid : ConfigValid weight c s)    (keys : List Nat) (validKeys : ∀ x ∈ keys, x < c.tree.erase.size) :    ∃ out, run p a past c s keys = some out ∧ out.source = (a.runFrom past c keys).2 ∧      ConfigValid weight out.source out.state ∧      Multifinger.replay out.instructions ⟨s.pair.tree, []⟩ = some ⟨out.state.pair.tree, []⟩ ∧      Pointer.Execution s.pair.tree keys out.state.pair.tree (keys.length + out.cost) ∧      out.cost + out.state.potential ≤ 62 * (a.runFrom past c keys).1.length + s.potential :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.run_spec policyValid a past valid keys validKeys
theoremHeavyPath.Finger.History.Simulation.Requests.Results.interval_workpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:108
theorem interval_work {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) (a : Algorithm α) (past : List Nat)    {c : Config α} {s : State α} (valid : ConfigValid weight c s)    (keys : List Nat) (validKeys : ∀ x ∈ keys, x < c.tree.erase.size) :    ∃ out, run p a past c s keys = some out ∧ out.source = (a.runFrom past c keys).2 ∧      ConfigValid weight out.source out.state ∧      Multifinger.replay out.instructions ⟨s.pair.tree, []⟩ = some ⟨out.state.pair.tree, []⟩ ∧      Pointer.Execution s.pair.tree keys out.state.pair.tree (keys.length + out.cost) ∧      keys.length + out.cost ≤ 62 * (keys.length + (a.runFrom past c keys).1.length) +        20 * c.tree.erase.size :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.interval_work policyValid a past valid keys validKeys

interval_work combines run_spec with Results.config_potential_bound. It applies to any segment of a longer run, starting from whatever history the earlier requests left.

Theorem (initialized request sequences). For a valid policy and any source algorithm, starting from a source finger in a positively weighted tree TT with nn nodes, there is a starting state, reached from TT by a startup trace of cost s0s_0 with s0+Φ0≤39ns_0 + \Phi_0 \le 39n, such that for every request history past and every list of in-range requests:

  • the lifted run succeeds and ends at the algorithm’s final cursor in a valid state;
  • it is a pointer-machine execution of the requests from the starting physical tree at cost ∣keys∣+C|\text{keys}| + C, and, for a nonempty request list, an execution from TT itself at cost s0+∣keys∣+Cs_0 + |\text{keys}| + C;
  • s0+∣keys∣+C+Φ≤39n+62(∣keys∣+m)s_0 + |\text{keys}| + C + \Phi \le 39n + 62(|\text{keys}| + m), where mm is the algorithm’s source cost.
theoremHeavyPath.Finger.History.Simulation.Requests.Results.initialized_runpropext · Classical.choice · Quot.soundStructures/HeavyPath/Finger/History/Simulation/Requests/Abstract.lean:60
theorem initialized_run {α : Type} {weight : α → ℝ} {p : Policy α}    (policyValid : PolicyValid weight p) (a : Algorithm α) {cs : List (Frame α)}    {left right : LabelledTree α} {key : α}    (positive : Positive weight (plug cs (.node left key right))) :    ∃ (start : State α) (startupCost : Nat),      ConfigValid weight ⟨.node left key right, cs⟩ start ∧      Pointer.Trace ⟨(plug cs (.node left key right)).erase, []⟩ ⟨start.pair.tree, []⟩ startupCost ∧      startupCost + start.potential ≤ 39 * (plug cs (.node left key right)).erase.size ∧      ∀ (past keys : List Nat),        (∀ x ∈ keys, x < (plug cs (.node left key right)).erase.size) →        ∃ out, run p a past ⟨.node left key right, cs⟩ start keys = some out ∧          out.source = (a.runFrom past ⟨.node left key right, cs⟩ keys).2 ∧          ConfigValid weight out.source out.state ∧          Pointer.Execution start.pair.tree keys out.state.pair.tree (keys.length + out.cost) ∧          (keys ≠ [] → Pointer.Execution (plug cs (.node left key right)).erase keys            out.state.pair.tree (startupCost + (keys.length + out.cost))) ∧          startupCost + keys.length + out.cost + out.state.potential ≤            39 * (plug cs (.node left key right)).erase.size +              62 * (keys.length + (a.runFrom past ⟨.node left key right, cs⟩ keys).1.length) :=  RotationBST.HeavyPath.Finger.History.Simulation.Requests.initialized_run policyValid a positive

The empty request list is excluded from the second execution because a Pointer.Execution of no requests has cost 00 and cannot absorb a nonzero startup. Up to constants, this is Theorem 5’s ∣A′(S)∣=O(∣A(S)∣)|A'(S)| = O(|A(S)|) for every online source algorithm, with the startup made explicit. Results.simulation replaces the start by a cheapest representation, as in Section 38.4.8, to get the purely multiplicative bound C≤248mC \le 248m.