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

Chapter 38 · Heavy paths · Section 38.2Recursive heavy paths

Section 38.1 stores one heavy path of a weighted tree as a pair of Chocolate pop-tarts. The endpoint of the path is the root, the path nodes smaller than the endpoint are in the left pop-tart, the larger ones in the right pop-tart, and every subtree hanging off the path is an opaque leaf of one of the two pop-tarts. This section applies the construction recursively: each of those opaque subtrees is itself stored by its own heavy path and its own pair of pop-tarts, and so on down to the leaves. This is the representation of Section 3 of Bose, Collette, Fagerberg and Langerman (2012a), drawn in their Figure 4, and it is what gives the deamortized BSTs of Chapter 30 their logarithmic depth.

A Chocolate pop-tart keeps a leaf of weight ww at depth O(log⁡(M/w))O(\log(M/w)), where MM is the total weight of the pop-tart (Section 37.2). A key is reached by descending into one pop-tart per heavy path on its source path. Each light edge at least halves the weight, and the depths telescope into a single logarithm:

Main result · Bose et al. 2012a
Every key of a recursive heavy-path representation has logarithmic weighted depth

Let tt be a labelled tree with nn nodes and positive node weights ww, and let WW be its total weight. The canonical recursive representation rebuild w t is a tree shape with the same nn nodes. If tt is ordered, rebuild w t has exactly one ordered labelling with the inorder of tt, so it is a BST on the same keys. Whether or not tt is ordered, the node of inorder rank ii, whose label in tt is xix_i, lies at depth

depth(i)  ≤  7+15log⁡2Ww(xi).\mathrm{depth}(i) \;\le\; 7 + 15\log_2\frac{W}{w(x_i)} .

With unit weights this is 7+15log⁡2n7 + 15\log_2 n for every rank i<ni < n. The same bound holds in every history layout, that is, whatever valid stack shapes the pop-tarts of the representation have reached after pushes and pops. The pointer machine turns tt into rebuild w t in at most 16n16n instructions.

This is the depth part of the paper’s Theorem 5, for a finger at the root, with explicit constants. Depth counts edges (Tree.depth), so the root has depth 00. In Lean, rebuild_labels gives the unique ordered labelling, rebuild_depth_at and rebuild_unit_depth are the two depth bounds, History.Results.layout_depth_at is the bound for an arbitrary history layout (History.Layout), and rebuild_initialization is the setup trace.

The Lean statements
theoremHeavyPath.Recursive.Results.rebuild_labelspropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:50
theorem rebuild_labels {α : Type} [Preorder α] {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (ordered : t.Ordered) :    ∃! u : LabelledTree α, u.erase = rebuild weight t ∧ u.inorder = t.inorder ∧ u.Ordered := …  RotationBST.HeavyPath.Recursive.rebuild_labels positive ordered
theoremHeavyPath.Recursive.Results.rebuild_depth_atpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:158
theorem rebuild_depth_at {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (rank : Fin t.inorder.length) :    (Tree.depth (rebuild weight t) rank.val : ℝ) ≤      7 + 15 * Real.logb 2 (HeavyPath.mass weight t / weight (t.inorder[rank.val]'rank.isLt)) := …  RotationBST.HeavyPath.Recursive.rebuild_depth_at positive rank
theoremHeavyPath.Recursive.Results.rebuild_unit_depthpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:164
theorem rebuild_unit_depth {α : Type} (t : LabelledTree α) (rank : Nat)    (valid : rank < t.erase.size) :    (Tree.depth (rebuild (fun _ => 1) t) rank : ℝ) ≤      7 + 15 * Real.logb 2 (t.erase.size : ℝ) := …  RotationBST.HeavyPath.Recursive.rebuild_unit_depth t rank valid
theoremHeavyPath.Recursive.History.Results.layout_depth_atpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:48
theorem layout_depth_at {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree} {credit : Nat}    (layout : Layout weight t shape credit) (rank : Fin t.inorder.length) :    (Tree.depth shape rank.val : ℝ) ≤      7 + 15 * Real.logb 2 (mass weight t / weight (t.inorder[rank.val]'rank.isLt)) := …  RotationBST.HeavyPath.Recursive.History.layout_depth_at layout rank
theoremHeavyPath.Recursive.Results.rebuild_initializationpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:55
theorem rebuild_initialization {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) :    ∃ cost, cost ≤ 16 * t.erase.size ∧ Pointer.Trace ⟨t.erase, []⟩ ⟨rebuild weight t, []⟩ cost := …  RotationBST.HeavyPath.Recursive.rebuild_initialization positive
61 definitions in 8 chapters, 2 more in internal modules · reading list
Do you need this section?

This section is proof machinery for the deamortization theorem of Chapter 30 and for the combined finger bound of Chapter 31. No headline result of those chapters mentions a recursive layout in its statement. What they use is the depth bound above, and the cost of moving the source tree’s root in and out of the representation. If you only want to know why the deamortized trees have depth O(log⁡n)O(\log n), the headline and the overview below are enough. Section 38.3 and Section 38.4 build the simulation of a moving finger on top of the history layouts of this section.

The definitions are in Structures/HeavyPath/Recursive/Definitions/Abstract.lean and its Exposure, History and History/Interruption subdirectories, and the theorems in the Abstract.lean files next to them.

38.2.1 Overview

Fix a source tree tt: a labelled tree with positive node weights. Its heavy-path decomposition (Section 38.1) starts at the root and follows the heavier child at every node, with ties going left, until it reaches a leaf xx, the endpoint. Every node of that path has a second child, possibly empty, the root of an off-path subtree, called a payload. The physical tree represents tt as follows:

                 x                 the endpoint is the physical root
               /   \
       pop-tart     pop-tart       path nodes < x on the left, > x on the right;
      L(root, x)    R(root, x)     each pop-tart leaf is one payload, stored as
       /  |  \        /  |  \      a recursive representation of that payload
     [P1][P2]...    ...[P5][P6]

The separators of the left pop-tart are the path nodes smaller than xx, and its leaves are the payloads between them, in key order. The right pop-tart is the mirror image. Each payload leaf is charged the weight of its subtree plus the weight of the separator next to it. The physical tree has exactly the nodes of tt, in the same inorder. This section has four layers:

  1. The canonical layout (Recursive.Layout, rebuild). Every pop-tart has the shape produced by pushing the path nodes in order, from the endpoint up. The layout is unique, and its depth bound is the telescoping argument of the paper.
  2. Exposure (Recursive.Exposure). The finger of the source algorithm starts at the root of tt. Moving it down to a child of the root removes that root from its heavy path. Physically, the root is popped from its pop-tart and becomes the physical root, with the two children of the source root as its physical children. The heavy child comes back as a residual pair of pop-tarts, and the light child as its canonical payload.
  3. Histories (Recursive.History). After a few pops and pushes, the pop-tarts no longer have the canonical shapes, and the payloads inside them have their own histories. A history layout records, for every off-path occurrence, its actual physical shape and a credit, the potential stored in it. The depth bound survives, and exposing or joining a source root costs O(1)O(1) amortized and O(log⁡n)O(\log n) worst case.
  4. Interruption (Recursive.History.Interruption). The deamortization interrupts the simulation between any two physical instructions. The last layer bounds the depth of every key in every intermediate tree of an exposure or a join.
Paper (Section 3) Here
heavy path from yy to xx, pop-tarts L(y,x)L(y,x), R(y,x)R(y,x) (Figure 4) Paired.Stacks built by Stacks.buildWith, rootPair
“the subtrees contained in those leaves will be structured in the same manner, recursively” Layout, rebuild
depth of xx is a telescoping sum O(log⁡(W/w))O(\log(W/w)) depth_telescope, rebuild_depth
yy moves down the path (finger moves down from the root) expose_view, layout_expose
yy moves up the path layout_join
pop-tarts in arbitrary reachable states, amortized by their potential History.Layout

The finger in general position, Figure 5 of the paper, with the path from the root to the finger stored upside down, is the subject of Section 38.3 and Section 38.4. They reuse the history layouts of this section for every subtree that the finger is not in.

38.2.2 The canonical layout

38.2.2.1 Inorder bookkeeping

The heavy path of tt is described by the cursor HeavyPath.extract w t: its focus is the endpoint, and its context is a list of LabelledCursor.Frames from the endpoint up to the root. A frame .left x r says that the path went left at x and that r is the payload; .right l x is the mirror case. The first four definitions say where each frame’s nodes appear in the inorder of tt.

defHeavyPath.Recursive.lowerFramesno axiomsStructures/HeavyPath/Recursive/Definitions/Abstract.lean:9
/-- Off-path frames in physical inorder order on each side of the endpoint. -/def lowerFrames {α : Type} : List (Frame α) → List (Frame α)  | [] => []  | .left _ _ :: cs => lowerFrames cs  | f@(.right _ _) :: cs => lowerFrames cs ++ [f]
defHeavyPath.Recursive.upperFramesno axiomsStructures/HeavyPath/Recursive/Definitions/Abstract.lean:15
def upperFrames {α : Type} : List (Frame α) → List (Frame α)  | [] => []  | f@(.left _ _) :: cs => f :: upperFrames cs  | .right _ _ :: cs => upperFrames cs
defHeavyPath.Recursive.lowerBlockno axiomsStructures/HeavyPath/Recursive/Definitions/Abstract.lean:20
def lowerBlock {α : Type} (frame : Frame α) : List α :=  (framePayload frame).inorder ++ [frameKey frame]
defHeavyPath.Recursive.upperBlockno axiomsStructures/HeavyPath/Recursive/Definitions/Abstract.lean:23
def upperBlock {α : Type} (frame : Frame α) : List α :=  frameKey frame :: (framePayload frame).inorder

lowerFrames cs keeps the .right frames, whose separators are smaller than the endpoint, and reverses them so that they appear root first, in increasing key order. upperFrames cs keeps the .left frames in endpoint-first order, which is again increasing key order. A lower frame contributes its payload followed by its separator (lowerBlock), and an upper frame its separator followed by its payload (upperBlock). The cursor’s inorder is the concatenation of these blocks around the focus:

Here LabelledCursor.plug cs t rebuilds the tree from the context. The statement holds for every context, heavy or not.

defHeavyPath.Recursive.RanksSatisfyno axiomsStructures/HeavyPath/Recursive/Definitions/Abstract.lean:26
/-- A property of every occurrence, retaining its rank even when labels repeat. -/def RanksSatisfy {α : Type} (P : Nat → α → Prop) (offset : Nat) (xs : List α) : Prop :=  ∀ before x after, xs = before ++ x :: after → P (offset + before.length) x

RanksSatisfy P offset xs says that P (offset + i) x holds for every occurrence x at position i of xs. It speaks of occurrences, not of values, so it remains meaningful when labels repeat. It is used in the proofs of the depth bounds below, which never assume distinct or ordered labels.

38.2.2.2 Building the representation

defHeavyPath.Recursive.rebuildFuelpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Definitions/Abstract.lean:30
/-- Fuel bounds the number of recursively nested heavy paths. The zero caseretains the original subtree. With at least one unit per original node andpositive weights, every nonempty recursive call takes the paired branch. -/noncomputable def rebuildFuel {α : Type} (weight : α → ℝ) : Nat → LabelledTree α → Tree  | 0, t => t.erase  | _ + 1, .nil => .nil  | n + 1, t@(.node _ _ _) =>      match (extract weight t).focus with      | .node .nil _ .nil => (Stacks.buildWith weight (rebuildFuel weight n)          (extract weight t).context Stacks.empty).tree      | _ => t.erase
defHeavyPath.Recursive.rebuildpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Definitions/Abstract.lean:42
noncomputable def rebuild {α : Type} (weight : α → ℝ) (t : LabelledTree α) : Tree :=  rebuildFuel weight t.erase.size t
defHeavyPath.Recursive.rootPairpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Definitions/Abstract.lean:45
/-- The outermost pair, with all off-path payloads recursively rebuilt. -/noncomputable def rootPair {α : Type} (weight : α → ℝ) (t : LabelledTree α) : Stacks :=  Stacks.buildWith weight (rebuild weight) (extract weight t).context Stacks.empty

rebuildFuel w n t extracts the heavy path of t and builds its pair of pop-tarts with Stacks.buildWith, which pushes the frames of the context one after the other, starting from the frame next to the endpoint. The payload of each frame is replaced by its own recursive representation rebuildFuel w n' before being pushed as an opaque leaf. The pop-tart charges, though, are computed from the original labelled payloads: the leaf of frame .left x r is charged w(x)+W(r)w(x) + W(r), where WW is HeavyPath.mass. The fuel n only makes the recursion structural. With fuel at least the number of nodes, every recursive call on a nonempty tree takes the paired branch (rebuildFuel_eq). The fallback t.erase, which leaves a subtree unchanged, is reached only when fuel runs out, or when the endpoint is not a leaf, which positive weights rule out. rebuild w t uses fuel t.erase.size. rootPair w t is the outermost pair, the one whose tree is rebuild w t when t is nonempty (rootPair_source).

The pop-tart pair Paired.Stacks has a lower and an upper Chocolate layer. Its physical tree is .node lower upper.mirror: the endpoint is the root, and the upper stack is stored in mirrored coordinates. The pairs and their pushes are defined in Section 38.1, and the Chocolate layers in Section 37.2.

The canonical layout is also given as an inductive relation, which is the form the proofs use:

inductiveHeavyPath.Recursive.Layoutpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Definitions/Abstract.lean:49
/-- A full recursive paired layout: every nonempty source path is representedby its Chocolate pair, and each off-path source subtree has another fulllayout in its corresponding opaque payload. No depth estimate is assumed. -/inductive Layout {α : Type} (weight : α → ℝ) : LabelledTree α → Tree → Prop where  | nil : Layout weight .nil .nil  | path {t : LabelledTree α} {payload : LabelledTree α → Tree}      (positive : Positive weight t) (nonempty : t ≠ .nil)      (terminal : ∃ x, (extract weight t).focus = .node .nil x .nil)      (children : ∀ frame ∈ (extract weight t).context,        Layout weight (framePayload frame) (payload (framePayload frame))) :      Layout weight t (Stacks.buildWith weight payload (extract weight t).context Stacks.empty).tree

Layout w t shape holds when t is empty and shape is empty, or when t is nonempty with positive weights, its heavy path ends at a leaf, shape is the tree of the pair built by buildWith w payload from its context, and every payload occurrence framePayload frame has a full layout payload (framePayload frame). The function payload matters only at the payload occurrences of the path. No depth estimate is part of the definition: depth is a theorem.

38.2.2.3 Basic facts

The recursion is well founded because every payload is strictly smaller than the tree, and positivity is inherited by the payloads:

theoremHeavyPath.Recursive.Results.extract_payload_sizepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:11
theorem extract_payload_size {α : Type} (weight : α → ℝ) (t : LabelledTree α)    {frame : Frame α} (mem : frame ∈ (extract weight t).context) :    (framePayload frame).erase.size < t.erase.size :=  RotationBST.HeavyPath.Recursive.extract_payload_size weight t mem
theoremHeavyPath.Recursive.Results.extract_payload_positivepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:16
theorem extract_payload_positive {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) {frame : Frame α} (mem : frame ∈ (extract weight t).context) :    Positive weight (framePayload frame) :=  RotationBST.HeavyPath.Recursive.extract_payload_positive positive mem

rebuild produces a layout, the layout is unique, and the fuel has no effect once it is large enough:

theoremHeavyPath.Recursive.Results.rebuildFuel_layoutpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:21
theorem rebuildFuel_layout {α : Type} {weight : α → ℝ} (fuel : Nat) {t : LabelledTree α}    (positive : Positive weight t) (enough : t.erase.size ≤ fuel) :    Layout weight t (rebuildFuel weight fuel t) :=  RotationBST.HeavyPath.Recursive.rebuildFuel_layout fuel positive enough
theoremHeavyPath.Recursive.Results.rebuild_layoutpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:26
theorem rebuild_layout {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) : Layout weight t (rebuild weight t) :=  RotationBST.HeavyPath.Recursive.rebuild_layout positive
theoremHeavyPath.Recursive.Results.layout_uniquepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:60
theorem layout_unique {α : Type} {weight : α → ℝ} {t : LabelledTree α} {first second : Tree}    (left : Layout weight t first) (right : Layout weight t second) : first = second :=  RotationBST.HeavyPath.Recursive.layout_unique left right
theoremHeavyPath.Recursive.Results.rebuildFuel_eqpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:64
theorem rebuildFuel_eq {α : Type} {weight : α → ℝ} (fuel : Nat) {t : LabelledTree α}    (positive : Positive weight t) (enough : t.erase.size ≤ fuel) :    rebuildFuel weight fuel t = rebuild weight t :=  RotationBST.HeavyPath.Recursive.rebuildFuel_eq fuel positive enough

layout_unique says that two layouts of the same labelled tree are the same shape. Together with rebuild_layout, every Layout w t shape has shape = rebuild w t. The recursion can be unfolded one level, either for an arbitrary layout or for rebuild itself:

theoremHeavyPath.Recursive.Results.layout_unfoldpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:30
theorem layout_unfold {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree}    (layout : Layout weight t shape) (nonempty : t ≠ .nil) :    ∃ endpoint payload,      (extract weight t).focus = .node .nil endpoint .nil ∧      shape = (Stacks.buildWith weight payload (extract weight t).context Stacks.empty).tree ∧      (Stacks.buildWith weight payload (extract weight t).context Stacks.empty).Valid ∧      weight endpoint + (Stacks.buildWith weight payload (extract weight t).context Stacks.empty).mass =        HeavyPath.mass weight t ∧      ∀ frame ∈ (extract weight t).context,        Layout weight (framePayload frame) (payload (framePayload frame)) :=  RotationBST.HeavyPath.Recursive.layout_unfold layout nonempty
theoremHeavyPath.Recursive.Results.rebuild_eqpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:69
theorem rebuild_eq {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (nonempty : t ≠ .nil) :    rebuild weight t =      (Stacks.buildWith weight (rebuild weight) (extract weight t).context Stacks.empty).tree :=  RotationBST.HeavyPath.Recursive.rebuild_eq positive nonempty
theoremHeavyPath.Recursive.Results.rebuild_pairpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:75
theorem rebuild_pair {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (nonempty : t ≠ .nil) :    let q := extract weight t    let p := Stacks.buildWith weight (rebuild weight) q.context Stacks.empty    ∃ endpoint, q.focus = .node .nil endpoint .nil ∧ rebuild weight t = p.tree ∧      p.Valid ∧ weight endpoint + p.mass = HeavyPath.mass weight t ∧      p.lower.decode.fringe = (lowerSlotsWith weight (rebuild weight) q.context).reverse ++ [(.nil, 0)] ∧      p.upper.decode.mirror.fringe = [(.nil, 0)] ++ upperSlotsWith weight (rebuild weight) q.context :=  RotationBST.HeavyPath.Recursive.rebuild_pair positive nonempty
theoremHeavyPath.Recursive.Results.rootPair_sourcepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:101
theorem rootPair_source {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (nonempty : t ≠ .nil) :    (rootPair weight t).Valid ∧ (rootPair weight t).mass ≤ HeavyPath.mass weight t ∧      rebuild weight t = (rootPair weight t).tree :=  RotationBST.HeavyPath.Recursive.rootPair_source positive nonempty

In both cases the outer pair is valid in the sense of Chocolate pop-tarts, and the endpoint’s weight plus the pair’s mass is the mass of tt: the frame charges partition the weights of tt. rebuild_pair also gives the two fringes, that is, the leaves of each pop-tart from left to right with their charges. The lower fringe lists the lower payloads root first, and ends with an empty slot (.nil, 0) next to the endpoint, which stands for the endpoint’s empty left child. The upper fringe, read in physical orientation, starts with the endpoint’s empty right child and lists the upper payloads. rootPair_source says the same with the weaker ≤ on the mass.

The representation keeps the nodes, the inorder and the root key:

theoremHeavyPath.Recursive.Results.layout_sizepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:42
theorem layout_size {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree}    (layout : Layout weight t shape) : shape.size = t.erase.size :=  RotationBST.HeavyPath.Recursive.layout_size layout
theoremHeavyPath.Recursive.Results.rebuild_sizepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:46
theorem rebuild_size {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) : (rebuild weight t).size = t.erase.size :=  RotationBST.HeavyPath.Recursive.rebuild_size positive
theoremHeavyPath.Recursive.Results.rebuild_labelspropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:50
theorem rebuild_labels {α : Type} [Preorder α] {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (ordered : t.Ordered) :    ∃! u : LabelledTree α, u.erase = rebuild weight t ∧ u.inorder = t.inorder ∧ u.Ordered :=  RotationBST.HeavyPath.Recursive.rebuild_labels positive ordered
theoremHeavyPath.Recursive.Results.rebuild_root_keypropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:85
theorem rebuild_root_key {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (nonempty : t ≠ .nil) :    (Pointer.Config.mk (rebuild weight t) []).key? = (extract weight t).erase.key? :=  RotationBST.HeavyPath.Recursive.rebuild_root_key positive nonempty

Tree shapes carry no labels, so rebuild_labels states the inorder property by relabelling. If t is ordered (LabelledTree.Ordered), there is exactly one ordered labelled tree whose shape is rebuild w t and whose inorder is that of t. rebuild_root_key says that the physical root has the inorder rank of the endpoint of the outer heavy path.

Building the representation from scratch is cheap:

Reading the Lean
  • The bound 16n16n does not come from the pushes. It is the library’s generic reshaping theorem, Pointer.reshape, which transforms any tree into any other tree of the same size with at most 16n16n pointer instructions. Any target shape on the same nodes would have the same bound.
  • The trace starts and ends with the cursor at the root (context []), and it counts every move and every rotation, as Pointer.Trace does.

38.2.3 The depth bound

The paper’s argument has two ingredients. A light edge at least halves the weight, and a Chocolate pop-tart puts a leaf of charge cc at depth at most 7+7log⁡2(M/c)7 + 7\log_2(M/c) inside a pop-tart of mass MM (Section 37.2). One more edge, from the endpoint to the pop-tart, gives 8+7log⁡2(M/c)8 + 7\log_2(M/c).

theoremHeavyPath.Recursive.Results.extract_payload_halfpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:90
theorem extract_payload_half {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) {frame : Frame α} (mem : frame ∈ (extract weight t).context) :    2 * mass weight (framePayload frame) ≤ mass weight t :=  RotationBST.HeavyPath.Recursive.extract_payload_half positive mem
theoremHeavyPath.Recursive.Results.extract_charge_boundspropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:95
theorem extract_charge_bounds {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) {frame : Frame α} (mem : frame ∈ (extract weight t).context) :    0 < weight (frameKey frame) ∧ weight (frameKey frame) ≤ frameMass weight frame ∧      mass weight (framePayload frame) ≤ frameMass weight frame :=  RotationBST.HeavyPath.Recursive.extract_charge_bounds positive mem

extract_payload_half is the halving: every payload of the heavy path has at most half the mass of tt. This holds even far down the path, since the payload’s sibling, the next path node, is at least as heavy. extract_charge_bounds relates a frame’s charge HeavyPath.frameMass to the two things it pays for: the separator HeavyPath.frameKey has positive weight at most the charge, and so does the payload’s mass. These bridge the pop-tart weights, which are charges, with the node weights, which appear in the final bound.

The telescoping step is a statement about real numbers:

Let the whole tree have mass WW, a payload have mass CC with 2C≤W2C \le W, and a key in it have weight k≤Ck \le C. If the key’s depth dd is at most the depth of the payload in the outer pair, 8+7log⁡2(W/C)8 + 7\log_2(W/C), plus the inductive bound inside the payload, 7+15log⁡2(C/k)7 + 15\log_2(C/k), then d≤7+15log⁡2(W/k)d \le 7 + 15\log_2(W/k). Since log⁡2(W/C)≥1\log_2(W/C) \ge 1, the additive 88 is absorbed into 8log⁡2(W/C)8\log_2(W/C), and 7+8=157 + 8 = 15. This is how a constant per light edge disappears into the logarithm. It is also why the coefficient 1515 is roughly twice the pop-tart’s 77.

The three induction steps apply this to the three kinds of nodes found below the endpoint: a key inside a payload, the separator following a lower payload, and the separator preceding an upper payload.

theoremHeavyPath.Recursive.Results.payload_depth_steppropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:113
theorem payload_depth_step {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (nonempty : t ≠ .nil)    {frame : Frame α} (member : frame ∈ (extract weight t).context) {offset depth x : Nat} {keyWeight : ℝ}    (slot : LocatedSlot (.node (rootPair weight t).lower.decode (rootPair weight t).upper.decode.mirror)      (rebuild weight (framePayload frame)) (frameMass weight frame) offset depth)    (inside : x < (rebuild weight (framePayload frame)).size)    (keyPositive : 0 < keyWeight) (keyMass : keyWeight ≤ HeavyPath.mass weight (framePayload frame))    (childBound : (Tree.depth (rebuild weight (framePayload frame)) x : ℝ) ≤      7 + 15 * Real.logb 2 (HeavyPath.mass weight (framePayload frame) / keyWeight)) :    (Tree.depth (rebuild weight t) (offset + x) : ℝ) ≤      7 + 15 * Real.logb 2 (HeavyPath.mass weight t / keyWeight) :=  RotationBST.HeavyPath.Recursive.payload_depth_step positive nonempty member slot inside keyPositive keyMass childBound
theoremHeavyPath.Recursive.Results.successor_depth_steppropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:126
theorem successor_depth_step {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (nonempty : t ≠ .nil)    {frame : Frame α} (member : frame ∈ (extract weight t).context) {offset depth : Nat}    (slot : LocatedSlot (.node (rootPair weight t).lower.decode (rootPair weight t).upper.decode.mirror)      (rebuild weight (framePayload frame)) (frameMass weight frame) offset depth)    (existsKey : offset + (rebuild weight (framePayload frame)).size < (rebuild weight t).size) :    (Tree.depth (rebuild weight t) (offset + (rebuild weight (framePayload frame)).size) : ℝ) ≤      7 + 15 * Real.logb 2 (HeavyPath.mass weight t / weight (frameKey frame)) :=  RotationBST.HeavyPath.Recursive.successor_depth_step positive nonempty member slot existsKey
theoremHeavyPath.Recursive.Results.predecessor_depth_steppropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:136
theorem predecessor_depth_step {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (nonempty : t ≠ .nil)    {frame : Frame α} (member : frame ∈ (extract weight t).context) {offset depth : Nat}    (slot : LocatedSlot (.node (rootPair weight t).lower.decode (rootPair weight t).upper.decode.mirror)      (rebuild weight (framePayload frame)) (frameMass weight frame) offset depth)    (existsKey : 0 < offset) :    (Tree.depth (rebuild weight t) (offset - 1) : ℝ) ≤      7 + 15 * Real.logb 2 (HeavyPath.mass weight t / weight (frameKey frame)) :=  RotationBST.HeavyPath.Recursive.predecessor_depth_step positive nonempty member slot existsKey

The hypothesis slot locates the payload’s physical occurrence inside the outer pair: WeightedTree.LocatedSlot records its inorder offset and its edge depth. payload_depth_step lifts a bound for rank x inside the payload to rank offset + x in the whole representation. successor_depth_step bounds the rank right after a lower payload, which is the frame’s separator (lowerBlock is the payload followed by its key). predecessor_depth_step bounds the rank right before an upper payload. The separators get the bound for their own weight, without induction. The endpoint is the root, at depth 00.

Strong induction on the size of tt then covers every rank:

Theorem (depth of the canonical layout). Let tt have positive weights and total weight WW. Every occurrence of a label xx in the inorder of tt, at position ii, is at depth at most 7+15log⁡2(W/w(x))7 + 15\log_2(W/w(x)) in rebuild w t. With unit weights, every rank i<ni < n is at depth at most 7+15log⁡2n7 + 15\log_2 n.

theoremHeavyPath.Recursive.Results.rebuild_depthpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:151
theorem rebuild_depth {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) {before after : List α} {key : α}    (occurrence : t.inorder = before ++ key :: after) :    (Tree.depth (rebuild weight t) before.length : ℝ) ≤      7 + 15 * Real.logb 2 (HeavyPath.mass weight t / weight key) :=  RotationBST.HeavyPath.Recursive.rebuild_depth positive occurrence
theoremHeavyPath.Recursive.Results.rebuild_depth_atpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:158
theorem rebuild_depth_at {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) (rank : Fin t.inorder.length) :    (Tree.depth (rebuild weight t) rank.val : ℝ) ≤      7 + 15 * Real.logb 2 (HeavyPath.mass weight t / weight (t.inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Recursive.rebuild_depth_at positive rank
theoremHeavyPath.Recursive.Results.rebuild_unit_depthpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Abstract.lean:164
theorem rebuild_unit_depth {α : Type} (t : LabelledTree α) (rank : Nat)    (valid : rank < t.erase.size) :    (Tree.depth (rebuild (fun _ => 1) t) rank : ℝ) ≤      7 + 15 * Real.logb 2 (t.erase.size : ℝ) :=  RotationBST.HeavyPath.Recursive.rebuild_unit_depth t rank valid

The three forms say the same thing. rebuild_depth names the occurrence by a split t.inorder = before ++ key :: after, so its rank is before.length. rebuild_depth_at indexes by a rank in Fin t.inorder.length. rebuild_unit_depth specializes to unit weights, where W=nW = n and w(x)=1w(x) = 1. It needs no positivity hypothesis, since unit weights are positive.

A depth bound gives a search walk. Visiting rank ii and returning to the root costs one unit for the request plus two walks of depth(i)\mathrm{depth}(i) moves:

The constants are doubled, 15+30log⁡2(W/w)15 + 30\log_2(W/w), because both walks are counted. The walk does not change the tree, and it does not simulate any work of the source algorithm. It is only a sanity check that the depth bound is reachable with pointer moves.

38.2.4 Exposing the root of the source tree

The source algorithm’s finger starts every request at the root of tt. When it moves down to a child, the source root leaves the heavy path it was the top of. Physically, it is popped from its pop-tart. One rotation sequence then makes it the physical root, with a representation of each child of the source root as its physical children. The heavy child keeps a residual pair, the old pair with one fewer path node. The light child is a payload, already a separate subtree in canonical form.

inductiveHeavyPath.Recursive.Exposure.Viewpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Definitions/Abstract.lean:10
/-- The residual heavy path is retained explicitly after exposing its sourceroot. Its potential belongs to this actual residual pair. -/inductive View where  | leaf  | left (rest : Stacks)  | right (rest : Stacks)
defHeavyPath.Recursive.Exposure.View.leftTreepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Definitions/Abstract.lean:19
noncomputable def leftTree {α : Type} (weight : α → ℝ) (l : LabelledTree α) : View → Tree  | .leaf => .nil  | .left rest => rest.tree  | .right _ => rebuild weight l
defHeavyPath.Recursive.Exposure.View.rightTreepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Definitions/Abstract.lean:24
noncomputable def rightTree {α : Type} (weight : α → ℝ) (r : LabelledTree α) : View → Tree  | .leaf => .nil  | .left _ => rebuild weight r  | .right rest => rest.tree
defHeavyPath.Recursive.Exposure.View.potentialpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Definitions/Abstract.lean:29
def potential : View → Nat  | .leaf => 0  | .left rest | .right rest => rest.potential
defHeavyPath.Recursive.Exposure.View.Validpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Definitions/Abstract.lean:33
def Valid {α : Type} (weight : α → ℝ) (l r : LabelledTree α) : View → Prop  | .leaf => l = .nil ∧ r = .nil  | .left rest => LeftHeavy weight l r ∧ l ≠ .nil ∧      rest.Represents weight (rebuild weight) (extract weight l).context  | .right rest => ¬ LeftHeavy weight l r ∧ r ≠ .nil ∧      rest.Represents weight (rebuild weight) (extract weight r).context

A View is what one finds below the source root node l x r after exposure. In .leaf both children are empty. In .left rest the heavy child is l, it is represented by the residual pair rest, and the right child is the canonical rebuild w r. .right rest is the mirror case. leftTree and rightTree are the two physical subtrees, and potential is the potential of the residual pair, which is all the potential that remains. Valid says that the case matches the heavy choice of HeavyPath.LeftHeavy, that the heavy child is nonempty, and that rest Stacks.Represents the heavy child’s own path with canonical payloads.

Representation is weaker than equality with a canonical pair. Represents asks only for valid Chocolate stacks with the correct fringes: popping need not recover the shape that the pushes would have built. The canonical pair represents its path, and any pair that represents the path of tt has the size of tt:

theoremHeavyPath.Recursive.Exposure.Results.rootPair_representspropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Abstract.lean:10
theorem rootPair_represents {α : Type} {weight : α → ℝ} {t : LabelledTree α}    (positive : Positive weight t) :    (rootPair weight t).Represents weight (rebuild weight) (extract weight t).context :=  RotationBST.HeavyPath.Recursive.Exposure.rootPair_represents positive
theoremHeavyPath.Recursive.Exposure.Results.represented_sizepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Abstract.lean:15
theorem represented_size {α : Type} {weight : α → ℝ} {t : LabelledTree α} {p : Stacks}    (positive : Positive weight t) (nonempty : t ≠ .nil)    (represented : p.Represents weight (rebuild weight) (extract weight t).context) :    p.tree.size = t.erase.size :=  RotationBST.HeavyPath.Recursive.Exposure.represented_size positive nonempty represented

Theorem (root exposure). Let node l x r have positive weights, with canonical representation PP of potential Φ(P)\Phi(P). There is a pointer trace, from root to root, that turns PP into node a b with a and b representing l and r. Its cost cc satisfies c+Φ′≤24+Φ(P)c + \Phi' \le 24 + \Phi(P), where Φ′\Phi' is the potential of the residual pair, and the new root has the rank of xx.

theoremHeavyPath.Recursive.Exposure.Results.expose_leftpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Abstract.lean:21
theorem expose_left {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α}    (positive : Positive weight (.node l x r)) (heavy : LeftHeavy weight l r) (nonempty : l ≠ .nil) :    ∃ rest : Stacks,      rest.Represents weight (rebuild weight) (extract weight l).context ∧      Pointer.Trace ⟨rebuild weight (.node l x r), []⟩        ⟨.node rest.tree (rebuild weight r), []⟩ ((rootPair weight (.node l x r)).exposeCost (.left x r)) ∧      (rootPair weight (.node l x r)).exposeCost (.left x r) + rest.potential ≤        24 + (rootPair weight (.node l x r)).potential ∧      rest.tree.size = l.erase.size ∧      (rootPair weight (.node l x r)).mass = rest.mass + (weight x + mass weight r) :=  RotationBST.HeavyPath.Recursive.Exposure.expose_left positive heavy nonempty
theoremHeavyPath.Recursive.Exposure.Results.expose_rightpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Abstract.lean:33
theorem expose_right {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α}    (positive : Positive weight (.node l x r)) (heavy : ¬ LeftHeavy weight l r) (nonempty : r ≠ .nil) :    ∃ rest : Stacks,      rest.Represents weight (rebuild weight) (extract weight r).context ∧      Pointer.Trace ⟨rebuild weight (.node l x r), []⟩        ⟨.node (rebuild weight l) rest.tree, []⟩ ((rootPair weight (.node l x r)).exposeCost (.right l x)) ∧      (rootPair weight (.node l x r)).exposeCost (.right l x) + rest.potential ≤        24 + (rootPair weight (.node l x r)).potential ∧      rest.tree.size = r.erase.size ∧      (rootPair weight (.node l x r)).mass = rest.mass + (mass weight l + weight x) :=  RotationBST.HeavyPath.Recursive.Exposure.expose_right positive heavy nonempty
theoremHeavyPath.Recursive.Exposure.Results.expose_viewpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Abstract.lean:65
theorem expose_view {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α}    (positive : Positive weight (.node l x r)) :    ∃ (view : View) (cost : Nat), view.Valid weight l r ∧      Pointer.Trace ⟨rebuild weight (.node l x r), []⟩        ⟨.node (view.leftTree weight l) (view.rightTree weight r), []⟩ cost ∧      (view.leftTree weight l).size = l.erase.size ∧      (view.rightTree weight r).size = r.erase.size ∧      cost + view.potential ≤ 24 + (rootPair weight (.node l x r)).potential :=  RotationBST.HeavyPath.Recursive.Exposure.expose_view positive
theoremHeavyPath.Recursive.Exposure.Results.expose_pair_viewpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Abstract.lean:54
theorem expose_pair_view {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Stacks}    (positive : Positive weight (.node l x r))    (represented : p.Represents weight (rebuild weight) (extract weight (.node l x r)).context) :    ∃ (view : View) (cost : Nat), view.Valid weight l r ∧      Pointer.Trace ⟨p.tree, []⟩        ⟨.node (view.leftTree weight l) (view.rightTree weight r), []⟩ cost ∧      (view.leftTree weight l).size = l.erase.size ∧      (view.rightTree weight r).size = r.erase.size ∧      cost + view.potential ≤ 24 + p.potential :=  RotationBST.HeavyPath.Recursive.Exposure.expose_pair_view positive represented
theoremHeavyPath.Recursive.Exposure.Results.root_exposurepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/Exposure/Abstract.lean:45
theorem root_exposure {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α}    (positive : Positive weight (.node l x r)) :    ∃ (a b : Tree) (cost remainingPotential : Nat),      Pointer.Trace ⟨rebuild weight (.node l x r), []⟩ ⟨.node a b, []⟩ cost ∧      a.size = l.erase.size ∧ b.size = r.erase.size ∧      (Pointer.Config.mk (.node a b) []).key? = some l.erase.size ∧      cost + remainingPotential ≤ 24 + (rootPair weight (.node l x r)).potential :=  RotationBST.HeavyPath.Recursive.Exposure.root_exposure positive

expose_left and expose_right are the two cases. The cost is Stacks.exposeCost: one pop from the stack that holds xx, plus four instructions to enter the stack, return and rotate. The mass identity says that the charge removed from the pair is exactly the frame charge of xx. expose_view packages both cases, and the leaf case, as a View. expose_pair_view starts from any pair that represents the path, not only the canonical one. It is the form used by the finger simulation of Section 38.3. root_exposure forgets the structure, keeping the sizes, the root rank and the amortized cost.

The constant 2424 is an amortized bound: the cost is paid by a drop of the Chocolate potential (Layer.potential). The heavy child’s residual pair is a represented pair, not a canonical one, so a second exposure cannot simply apply expose_view again. This is why histories are needed.

38.2.5 Histories

38.2.5.1 Entries and paths

A history layout drops the requirement that payloads are canonical. Each off-path occurrence is recorded with its actual physical shape and its own stored potential.

structureHeavyPath.Recursive.History.Entryno axiomsStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:10
/-- One off-path occurrence. Equal source subtrees may retain differentphysical layouts and repair credits at different occurrences. -/structure Entry (α : Type) where  source : Frame α  shape : Tree  credit : Nat
defHeavyPath.Recursive.History.Entry.slotpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:19
def slot {α : Type} (weight : α → ℝ) (e : Entry α) : Tree × ℝ :=  (e.shape, frameMass weight e.source)
defHeavyPath.Recursive.History.Entry.lowerBlockno axiomsStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:21
def lowerBlock {α : Type} (e : Entry α) : List α := Recursive.lowerBlock e.source
defHeavyPath.Recursive.History.Entry.upperBlockno axiomsStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:22
def upperBlock {α : Type} (e : Entry α) : List α := Recursive.upperBlock e.source
defHeavyPath.Recursive.History.Entry.wrapno axiomsStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:24
/-- Restore this source separator around the remaining heavy path. -/def wrap {α : Type} (e : Entry α) (child : Tree) : Tree :=  match e.source with  | .left _ _ => .node child e.shape  | .right _ _ => .node e.shape child

An Entry has the source frame, the physical shape of its payload, and the credit of that payload. Two equal source subtrees at different positions may have different shapes and credits, since they have had different histories. slot is the pop-tart leaf it occupies: the shape with the frame’s charge. lowerBlock and upperBlock are the inorder blocks of the source frame. wrap e child puts the separator back above the rest of the path: for a .left frame it is node child e.shape, the separator node with the path below it on the left and the payload on the right.

defHeavyPath.Recursive.History.lowerno axiomsStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:32
def lower {α : Type} : List (Entry α) → List (Entry α)  | [] => []  | e :: es => match e.source with    | .left _ _ => lower es    | .right _ _ => lower es ++ [e]
defHeavyPath.Recursive.History.upperno axiomsStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:38
def upper {α : Type} : List (Entry α) → List (Entry α)  | [] => []  | e :: es => match e.source with    | .left _ _ => e :: upper es    | .right _ _ => upper es

lower and upper select the entries of each pop-tart in physical key order, exactly as lowerFrames and upperFrames do for frames.

structureHeavyPath.Recursive.History.PathValidpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:44
/-- Physical fringes describe occurrences, without imposing constructionhistory or assuming a height bound. -/structure PathValid {α : Type} (weight : α → ℝ) (es : List (Entry α)) (p : Stacks) : Prop where  pair : p.Valid  lower : p.lower.decode.fringe = (History.lower es).map (Entry.slot weight) ++ [(.nil, 0)]  upper : p.upper.decode.mirror.fringe = [(.nil, 0)] ++ (History.upper es).map (Entry.slot weight)
theoremHeavyPath.Recursive.History.PathValid.pairpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:47
pair
Statement reads only Structures/HeavyPath/Recursive/History/Definitions/Abstract.lean and its imports
theoremHeavyPath.Recursive.History.PathValid.lowerpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:48
lower
Statement reads only Structures/HeavyPath/Recursive/History/Definitions/Abstract.lean and its imports
theoremHeavyPath.Recursive.History.PathValid.upperpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:49
upper
Statement reads only Structures/HeavyPath/Recursive/History/Definitions/Abstract.lean and its imports

PathValid w es p says that the pair p is valid and that its two fringes, read in physical orientation, are the slots of the entries, with the endpoint’s empty slot at the inner end. This is a condition on the current state only. It does not say how the pair was built, and it does not assume a height bound. The pair’s mass is the sum of the frame charges, and with the endpoint’s weight it is the mass of the source tree:

theoremHeavyPath.Recursive.History.Results.path_masspropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:10
theorem path_mass {α : Type} {weight : α → ℝ} {es : List (Entry α)} {p : Stacks}    (valid : PathValid weight es p) : p.mass = (es.map (fun e => frameMass weight e.source)).sum :=  RotationBST.HeavyPath.Recursive.History.path_mass valid
theoremHeavyPath.Recursive.History.Results.path_partitionpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:14
theorem path_partition {α : Type} {weight : α → ℝ} {es : List (Entry α)} {p : Stacks}    {t : LabelledTree α} {endpoint : α}    (context : es.map Entry.source = (extract weight t).context)    (valid : PathValid weight es p) (focus : (extract weight t).focus = .node .nil endpoint .nil) :    weight endpoint + p.mass = mass weight t :=  RotationBST.HeavyPath.Recursive.History.path_partition context valid focus

38.2.5.2 History layouts

inductiveHeavyPath.Recursive.History.Layoutpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean:51
/-- A recursive representation with arbitrary valid stack histories. Thepotential is the sum over actual path and payload occurrences. -/inductive Layout {α : Type} (weight : α → ℝ) : LabelledTree α → Tree → Nat → Prop where  | nil : Layout weight .nil .nil 0  | path {t : LabelledTree α} {es : List (Entry α)} {p : Stacks}      (positive : Positive weight t) (nonempty : t ≠ .nil)      (context : es.map Entry.source = (extract weight t).context)      (valid : PathValid weight es p)      (children : ∀ e ∈ es, Layout weight (framePayload e.source) e.shape e.credit) :      Layout weight t p.tree (p.potential + (es.map Entry.credit).sum)

Layout w t shape credit is the recursive invariant. The empty tree has the empty shape and credit 00. A nonempty tree with positive weights is represented by any pair p with entries es whose sources are the context of its heavy path, such that PathValid w es p holds and every entry’s shape is itself a layout of its payload with the entry’s credit. The credit of the whole is the potential of p plus the credits of all entries. Summed over the recursion, it is the total Chocolate potential of all the pop-tarts of the representation, and it is the potential function of the amortized analysis.

A history layout has the expected size, positivity and labels:

theoremHeavyPath.Recursive.History.Results.layout_positivepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:21
theorem layout_positive {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree} {credit : Nat}    (layout : Layout weight t shape credit) : Positive weight t :=  RotationBST.HeavyPath.Recursive.History.layout_positive layout
theoremHeavyPath.Recursive.History.Results.layout_sizepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:25
theorem layout_size {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree} {credit : Nat}    (layout : Layout weight t shape credit) : shape.size = t.erase.size :=  RotationBST.HeavyPath.Recursive.History.layout_size layout
theoremHeavyPath.Recursive.History.Results.layout_labelspropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:29
theorem layout_labels {α : Type} [Preorder α] {weight : α → ℝ} {t : LabelledTree α}    {shape : Tree} {credit : Nat} (layout : Layout weight t shape credit) (ordered : t.Ordered) :    ∃! u : LabelledTree α, u.erase = shape ∧ u.inorder = t.inorder ∧ u.Ordered :=  RotationBST.HeavyPath.Recursive.History.layout_labels layout ordered

The canonical layout is a history layout, with credit at most 23n23n, and every history layout has credit at most 20n20n:

theoremHeavyPath.Recursive.History.Results.of_canonicalpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:34
theorem of_canonical {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree}    (layout : Recursive.Layout weight t shape) : ∃ credit, Layout weight t shape credit :=  RotationBST.HeavyPath.Recursive.History.of_canonical layout
theoremHeavyPath.Recursive.History.Results.rebuild_historypropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:38
theorem rebuild_history {α : Type} {weight : α → ℝ} {t : LabelledTree α} (positive : Positive weight t) :    ∃ credit, Layout weight t (rebuild weight t) credit :=  RotationBST.HeavyPath.Recursive.History.rebuild_history positive
theoremHeavyPath.Recursive.History.Results.of_canonical_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:85
theorem of_canonical_bounded {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree}    (layout : Recursive.Layout weight t shape) :    ∃ credit, Layout weight t shape credit ∧ credit ≤ 23 * t.erase.size :=  RotationBST.HeavyPath.Recursive.History.of_canonical_bounded layout
theoremHeavyPath.Recursive.History.Results.rebuild_history_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:90
theorem rebuild_history_bounded {α : Type} {weight : α → ℝ} {t : LabelledTree α} (positive : Positive weight t) :    ∃ credit, Layout weight t (rebuild weight t) credit ∧ credit ≤ 23 * t.erase.size :=  RotationBST.HeavyPath.Recursive.History.rebuild_history_bounded positive
theoremHeavyPath.Recursive.History.Results.path_potential_boundpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:151
theorem path_potential_bound {α : Type} {weight : α → ℝ} {es : List (Entry α)} {p : Stacks}    (valid : PathValid weight es p) : p.potential ≤ 20 * es.length :=  RotationBST.HeavyPath.Recursive.History.path_potential_bound valid
theoremHeavyPath.Recursive.History.Results.layout_potential_boundpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:155
theorem layout_potential_bound {α : Type} {weight : α → ℝ} {t : LabelledTree α}    {shape : Tree} {credit : Nat} (layout : Layout weight t shape credit) :    credit ≤ 20 * t.erase.size :=  RotationBST.HeavyPath.Recursive.History.layout_potential_bound layout

path_potential_bound bounds one pair by 2020 per entry. layout_potential_bound adds this over the recursion. A source tree with nn nodes has fewer than nn entries in total, so its credit is at most 20n20n. The 23n23n of the two _bounded theorems is therefore not the best constant: layout_potential_bound applied to rebuild_history gives 20n20n. Either bound means that starting from a fresh canonical layout costs at most a linear amount of potential.

The depth bound and the search walk carry over unchanged, with the same constants:

theoremHeavyPath.Recursive.History.Results.layout_depthpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:42
theorem layout_depth {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree} {credit : Nat}    (layout : Layout weight t shape credit) {before after : List α} {key : α}    (occurrence : t.inorder = before ++ key :: after) :    (Tree.depth shape before.length : ℝ) ≤ 7 + 15 * Real.logb 2 (mass weight t / weight key) :=  RotationBST.HeavyPath.Recursive.History.layout_depth layout occurrence
theoremHeavyPath.Recursive.History.Results.layout_depth_atpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:48
theorem layout_depth_at {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree} {credit : Nat}    (layout : Layout weight t shape credit) (rank : Fin t.inorder.length) :    (Tree.depth shape rank.val : ℝ) ≤      7 + 15 * Real.logb 2 (mass weight t / weight (t.inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Recursive.History.layout_depth_at layout rank
theoremHeavyPath.Recursive.History.Results.layout_search_walkpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:54
theorem layout_search_walk {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree} {credit : Nat}    (layout : Layout weight t shape credit) (rank : Fin t.inorder.length) :    ∃ (visited : Pointer.Config) (cost : Nat), visited.tree = shape ∧ visited.key? = some rank.val ∧      Pointer.Trace ⟨shape, []⟩ visited cost ∧ Pointer.Trace visited ⟨shape, []⟩ cost ∧      (1 + 2 * cost : ℝ) ≤ 15 + 30 * Real.logb 2 (mass weight t / weight (t.inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Recursive.History.layout_search_walk layout rank

The reason is that the depth argument only used two facts about each pair: valid Chocolate stacks, and the payload charges in the fringe. Both are part of PathValid. The shapes the stacks happen to have, and the history of the payloads, do not matter.

38.2.5.3 Popping, exposing and joining

One pop removes the topmost source ancestor of a path, the last entry of es, and makes it the physical root above the rest of the path:

Exposing a source root for an arbitrary history layout is the same operation, followed by the observation that the residual pair and the light payload are again history layouts. Joining is the converse: given layouts of l and r and a positive weight for x, it builds a layout of node l x r, pushing the light child into the heavy child’s pair.

Theorem (exposing and joining). Let shape be a history layout of node l x r with credit Φ\Phi. A root-to-root trace of cost cc turns it into node a b, where a and b are history layouts of l and r with credits Φl\Phi_l and Φr\Phi_r, with c+Φl+Φr≤24+Φc + \Phi_l + \Phi_r \le 24 + \Phi and c≤10+10log⁡2nc \le 10 + 10\log_2 n. Conversely, from layouts a, b of l, r, a trace of cost c≤10+14log⁡2nc \le 10 + 14\log_2 n produces a layout of node l x r with credit Φ\Phi and c+Φ≤24+Φl+Φrc + \Phi \le 24 + \Phi_l + \Phi_r.

theoremHeavyPath.Recursive.History.Results.layout_exposepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:68
theorem layout_expose {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α}    {shape : Tree} {credit : Nat} (layout : Layout weight (.node l x r) shape credit) :    ∃ (a b : Tree) (leftCredit rightCredit cost : Nat),      Layout weight l a leftCredit ∧ Layout weight r b rightCredit ∧      Pointer.Trace ⟨shape, []⟩ ⟨.node a b, []⟩ cost ∧      cost + leftCredit + rightCredit ≤ 24 + credit :=  RotationBST.HeavyPath.Recursive.History.layout_expose layout
theoremHeavyPath.Recursive.History.Results.layout_joinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:76
theorem layout_join {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α}    {a b : Tree} {leftCredit rightCredit : Nat}    (left : Layout weight l a leftCredit) (right : Layout weight r b rightCredit)    (keyPositive : 0 < weight x) :    ∃ (shape : Tree) (credit cost : Nat), Layout weight (.node l x r) shape credit ∧      Pointer.Trace ⟨.node a b, []⟩ ⟨shape, []⟩ cost ∧      cost + credit ≤ 24 + leftCredit + rightCredit :=  RotationBST.HeavyPath.Recursive.History.layout_join left right keyPositive
theoremHeavyPath.Recursive.History.Results.layout_expose_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:94
theorem layout_expose_bounded {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α}    {shape : Tree} {credit : Nat} (layout : Layout weight (.node l x r) shape credit) :    ∃ (a b : Tree) (leftCredit rightCredit cost : Nat),      Layout weight l a leftCredit ∧ Layout weight r b rightCredit ∧      Pointer.Trace ⟨shape, []⟩ ⟨.node a b, []⟩ cost ∧      cost + leftCredit + rightCredit ≤ 24 + credit ∧      (cost : ℝ) ≤ 10 + 10 * Real.logb 2 shape.size :=  RotationBST.HeavyPath.Recursive.History.layout_expose_bounded layout
theoremHeavyPath.Recursive.History.Results.layout_join_boundedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:103
theorem layout_join_bounded {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α}    {a b : Tree} {leftCredit rightCredit : Nat}    (left : Layout weight l a leftCredit) (right : Layout weight r b rightCredit)    (keyPositive : 0 < weight x) :    ∃ (shape : Tree) (credit cost : Nat), Layout weight (.node l x r) shape credit ∧      Pointer.Trace ⟨.node a b, []⟩ ⟨shape, []⟩ cost ∧      cost + credit ≤ 24 + leftCredit + rightCredit ∧      (cost : ℝ) ≤ 10 + 14 * Real.logb 2 (Tree.node a b).size :=  RotationBST.HeavyPath.Recursive.History.layout_join_bounded left right keyPositive

The amortized bound 2424 is the Chocolate pop-tart’s. The worst-case bounds come from the depth of the stack being popped or pushed into. Here nn is the size of the physical tree, shape.size or (node a b).size. Only the outer pair changes: every payload keeps its shape and its credit.

The deamortization also needs to know that no intermediate tree is deep. Pointer.TraceWithin holds is a trace whose tree satisfies holds at every instruction boundary.

theoremHeavyPath.Recursive.History.Results.push_path_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:113
theorem push_path_within {α : Type} {weight : α → ℝ} {es : List (Entry α)} {p : Stacks}    (valid : PathValid weight es p) (e : Entry α) (nonnegative : 0 ≤ frameMass weight e.source) :    PathValid weight (es ++ [e]) (p.pushWith weight (fun _ => e.shape) e.source) ∧      Pointer.TraceWithin (fun t => t.size = (e.wrap p.tree).size ∧        ∀ x, Tree.depth t x ≤ 4 * Tree.depth (e.wrap p.tree) x + 16) ⟨e.wrap p.tree, []⟩ ⟨(p.pushWith weight (fun _ => e.shape) e.source).tree, []⟩        (p.pushCost e.source + 1) ∧      p.pushCost e.source + 1 + (p.pushWith weight (fun _ => e.shape) e.source).potential ≤ 24 + p.potential :=  RotationBST.HeavyPath.Recursive.History.push_path_within valid e nonnegative
theoremHeavyPath.Recursive.History.Results.pop_path_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:122
theorem pop_path_within {α : Type} {weight : α → ℝ} {es : List (Entry α)} {e : Entry α} {p : Stacks}    (valid : PathValid weight (es ++ [e]) p) :    ∃ rest : Stacks, PathValid weight es rest ∧      Pointer.TraceWithin (fun t => t.size = p.tree.size ∧        ∀ x, Tree.depth t x ≤ 4 * Tree.depth p.tree x + 10) ⟨p.tree, []⟩ ⟨e.wrap rest.tree, []⟩ (p.exposeCost e.source) ∧      p.exposeCost e.source + rest.potential ≤ 24 + p.potential :=  RotationBST.HeavyPath.Recursive.History.pop_path_within valid
theoremHeavyPath.Recursive.History.Results.layout_expose_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:130
theorem layout_expose_within {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α}    {shape : Tree} {credit : Nat} (layout : Layout weight (.node l x r) shape credit) :    ∃ (a b : Tree) (leftCredit rightCredit cost : Nat),      Layout weight l a leftCredit ∧ Layout weight r b rightCredit ∧      Pointer.TraceWithin (fun t => t.size = shape.size ∧        ∀ x, Tree.depth t x ≤ 4 * Tree.depth shape x + 10) ⟨shape, []⟩ ⟨.node a b, []⟩ cost ∧      cost + leftCredit + rightCredit ≤ 24 + credit ∧      (cost : ℝ) ≤ 10 + 10 * Real.logb 2 shape.size :=  RotationBST.HeavyPath.Recursive.History.layout_expose_within layout
theoremHeavyPath.Recursive.History.Results.layout_join_withinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Abstract.lean:140
theorem layout_join_within {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α}    {a b : Tree} {leftCredit rightCredit : Nat}    (left : Layout weight l a leftCredit) (right : Layout weight r b rightCredit)    (keyPositive : 0 < weight x) :    ∃ (shape : Tree) (credit cost : Nat), Layout weight (.node l x r) shape credit ∧      Pointer.TraceWithin (fun t => t.size = (Tree.node a b).size ∧        ∀ x, Tree.depth t x ≤ 4 * Tree.depth (.node a b) x + 16) ⟨.node a b, []⟩ ⟨shape, []⟩ cost ∧      cost + credit ≤ 24 + leftCredit + rightCredit ∧      (cost : ℝ) ≤ 10 + 14 * Real.logb 2 (Tree.node a b).size :=  RotationBST.HeavyPath.Recursive.History.layout_join_within left right keyPositive

In every intermediate tree of a pop or an exposure, the size is unchanged and every rank yy is at depth at most 4 depthstart(y)+104\,\mathrm{depth}_{\text{start}}(y) + 10. For a push or a join, the constant is 1616, measured against the tree before the push. A pop-tart push or pop restructures only a few nodes on the stack’s spine, so it can at most multiply depths by a constant. The _within versions imply the plain ones, which are kept as projections. Section 38.4 uses layout_join_within for the finger’s moves and rotations.

38.2.6 Interruption

The deamortization of Chapter 30 runs the simulation as a stream of single-finger instructions and may cut that stream between any two instructions to serve the next request with a fresh search; in the proof of the paper’s Theorem 6 this happens every clog⁡nc\log n instructions. That search runs in the intermediate tree, possibly in the middle of an exposure or a join. The last module states the exposure and the join as explicit instruction lists, a list of Multifinger.Opcodes replayed by Multifinger.replay on the pointer configuration, and bounds the depth of every key in every intermediate configuration.

The starting tree of a join, a source root above two layouts, already has a weighted depth bound with respect to the whole source subtree:

Theorem (interruptible exposure and join). Let WW be the mass of node l key r and nn the size of the physical tree before the operation. Exposure and join can be written as instruction lists with the amortized and worst-case costs above, such that, for every cut point, the instructions before the cut replay to an intermediate configuration, the remaining ones replay from there to the result, and in that intermediate tree every rank ii, with label xix_i, has depth at most

17+15log⁡2Ww(xi)+10log⁡2n(exposure),17+15log⁡2Ww(xi)+14log⁡2n(join).17 + 15\log_2\frac{W}{w(x_i)} + 10\log_2 n \quad\text{(exposure)}, \qquad 17 + 15\log_2\frac{W}{w(x_i)} + 14\log_2 n \quad\text{(join)}.

Purely weighted versions give 38+60log⁡2(W/w(xi))38 + 60\log_2(W/w(x_i)) for exposure and 48+60log⁡2(W/w(xi))48 + 60\log_2(W/w(x_i)) for join. With unit weights, the bounds are 17+25log⁡2n17 + 25\log_2 n and 17+29log⁡2n17 + 29\log_2 n.

theoremHeavyPath.Recursive.History.Interruption.Results.exposepropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Interruption/Abstract.lean:9
theorem expose {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {key : α}    {shape : Tree} {credit : Nat} (layout : Layout weight (.node l key r) shape credit) :    ∃ (a b : Tree) (lc rc : Nat) (ops : List Multifinger.Opcode),      Layout weight l a lc ∧ Layout weight r b rc ∧      Multifinger.replay ops ⟨shape, []⟩ = some ⟨.node a b, []⟩ ∧      ops.length + lc + rc ≤ 24 + credit ∧      (ops.length : ℝ) ≤ 10 + 10 * Real.logb 2 shape.size ∧      ∀ cut, ∃ middle,        Multifinger.replay (ops.take cut) ⟨shape, []⟩ = some middle ∧        Multifinger.replay (ops.drop cut) middle = some ⟨.node a b, []⟩ ∧        ∀ rank : Fin (LabelledTree.node l key r).inorder.length,          (Tree.depth middle.tree rank.val : ℝ) ≤            17 + 15 * Real.logb 2 (mass weight (.node l key r) /              weight ((LabelledTree.node l key r).inorder[rank.val]'rank.isLt)) +                10 * Real.logb 2 shape.size :=  RotationBST.HeavyPath.Recursive.History.Interruption.expose layout
theoremHeavyPath.Recursive.History.Interruption.Results.joinpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Interruption/Abstract.lean:26
theorem join {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {key : α}    {a b : Tree} {lc rc : Nat} (left : Layout weight l a lc) (right : Layout weight r b rc)    (positive : 0 < weight key) :    ∃ (shape : Tree) (credit : Nat) (ops : List Multifinger.Opcode),      Layout weight (.node l key r) shape credit ∧      Multifinger.replay ops ⟨.node a b, []⟩ = some ⟨shape, []⟩ ∧      ops.length + credit ≤ 24 + lc + rc ∧      (ops.length : ℝ) ≤ 10 + 14 * Real.logb 2 (Tree.node a b).size ∧      ∀ cut, ∃ middle,        Multifinger.replay (ops.take cut) ⟨.node a b, []⟩ = some middle ∧        Multifinger.replay (ops.drop cut) middle = some ⟨shape, []⟩ ∧        ∀ rank : Fin (LabelledTree.node l key r).inorder.length,          (Tree.depth middle.tree rank.val : ℝ) ≤            17 + 15 * Real.logb 2 (mass weight (.node l key r) /              weight ((LabelledTree.node l key r).inorder[rank.val]'rank.isLt)) +                14 * Real.logb 2 (Tree.node a b).size :=  RotationBST.HeavyPath.Recursive.History.Interruption.join left right positive

The mixed bounds of expose and join combine the depth of a complete layout with the length of the operation. During an exposure, a key’s depth is at most its depth in the starting layout plus the number of instructions performed so far. A join is bounded backwards from its final layout across the remaining suffix.

theoremHeavyPath.Recursive.History.Interruption.Results.expose_uniformpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Interruption/Abstract.lean:44
theorem expose_uniform {α : Type} {l r : LabelledTree α} {key : α}    {shape : Tree} {credit : Nat} (layout : Layout (fun _ => 1) (.node l key r) shape credit) :    ∃ (a b : Tree) (lc rc : Nat) (ops : List Multifinger.Opcode),      Layout (fun _ => 1) l a lc ∧ Layout (fun _ => 1) r b rc ∧      Multifinger.replay ops ⟨shape, []⟩ = some ⟨.node a b, []⟩ ∧      ops.length + lc + rc ≤ 24 + credit ∧      (ops.length : ℝ) ≤ 10 + 10 * Real.logb 2 shape.size ∧      ∀ cut, ∃ middle,        Multifinger.replay (ops.take cut) ⟨shape, []⟩ = some middle ∧        Multifinger.replay (ops.drop cut) middle = some ⟨.node a b, []⟩ ∧        ∀ rank : Fin (LabelledTree.node l key r).inorder.length,          (Tree.depth middle.tree rank.val : ℝ) ≤ 17 + 25 * Real.logb 2 shape.size :=  RotationBST.HeavyPath.Recursive.History.Interruption.expose_uniform layout
theoremHeavyPath.Recursive.History.Interruption.Results.join_uniformpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Interruption/Abstract.lean:58
theorem join_uniform {α : Type} {l r : LabelledTree α} {key : α}    {a b : Tree} {lc rc : Nat} (left : Layout (fun _ => 1) l a lc) (right : Layout (fun _ => 1) r b rc) :    ∃ (shape : Tree) (credit : Nat) (ops : List Multifinger.Opcode),      Layout (fun _ => 1) (.node l key r) shape credit ∧      Multifinger.replay ops ⟨.node a b, []⟩ = some ⟨shape, []⟩ ∧      ops.length + credit ≤ 24 + lc + rc ∧      (ops.length : ℝ) ≤ 10 + 14 * Real.logb 2 (Tree.node a b).size ∧      ∀ cut, ∃ middle,        Multifinger.replay (ops.take cut) ⟨.node a b, []⟩ = some middle ∧        Multifinger.replay (ops.drop cut) middle = some ⟨shape, []⟩ ∧        ∀ rank : Fin (LabelledTree.node l key r).inorder.length,          (Tree.depth middle.tree rank.val : ℝ) ≤ 17 + 29 * Real.logb 2 (Tree.node a b).size :=  RotationBST.HeavyPath.Recursive.History.Interruption.join_uniform left right
theoremHeavyPath.Recursive.History.Interruption.Results.expose_weightedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Interruption/Abstract.lean:80
theorem expose_weighted {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {key : α}    {shape : Tree} {credit : Nat} (layout : Layout weight (.node l key r) shape credit) :    ∃ (a b : Tree) (lc rc : Nat) (ops : List Multifinger.Opcode),      Layout weight l a lc ∧ Layout weight r b rc ∧      Multifinger.replay ops ⟨shape, []⟩ = some ⟨.node a b, []⟩ ∧      ops.length + lc + rc ≤ 24 + credit ∧      (ops.length : ℝ) ≤ 10 + 10 * Real.logb 2 shape.size ∧      ∀ cut, ∃ middle,        Multifinger.replay (ops.take cut) ⟨shape, []⟩ = some middle ∧        Multifinger.replay (ops.drop cut) middle = some ⟨.node a b, []⟩ ∧        ∀ rank : Fin (LabelledTree.node l key r).inorder.length,          (Tree.depth middle.tree rank.val : ℝ) ≤            38 + 60 * Real.logb 2 (mass weight (.node l key r) /              weight ((LabelledTree.node l key r).inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Recursive.History.Interruption.expose_weighted layout
theoremHeavyPath.Recursive.History.Interruption.Results.join_weightedpropext · Classical.choice · Quot.soundStructures/HeavyPath/Recursive/History/Interruption/Abstract.lean:96
theorem join_weighted {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {key : α}    {a b : Tree} {lc rc : Nat} (left : Layout weight l a lc) (right : Layout weight r b rc)    (positive : 0 < weight key) :    ∃ (shape : Tree) (credit : Nat) (ops : List Multifinger.Opcode),      Layout weight (.node l key r) shape credit ∧      Multifinger.replay ops ⟨.node a b, []⟩ = some ⟨shape, []⟩ ∧      ops.length + credit ≤ 24 + lc + rc ∧      (ops.length : ℝ) ≤ 10 + 14 * Real.logb 2 (Tree.node a b).size ∧      ∀ cut, ∃ middle,        Multifinger.replay (ops.take cut) ⟨.node a b, []⟩ = some middle ∧        Multifinger.replay (ops.drop cut) middle = some ⟨shape, []⟩ ∧        ∀ rank : Fin (LabelledTree.node l key r).inorder.length,          (Tree.depth middle.tree rank.val : ℝ) ≤            48 + 60 * Real.logb 2 (mass weight (.node l key r) /              weight ((LabelledTree.node l key r).inorder[rank.val]'rank.isLt)) :=  RotationBST.HeavyPath.Recursive.History.Interruption.join_weighted left right positive

The weighted versions instead use the multiplicative bounds of the _within theorems: 4(7+15L)+10=38+60L4(7 + 15L) + 10 = 38 + 60L for exposure, and, from node_depth_at, 4(8+15L)+16=48+60L4(8 + 15L) + 16 = 48 + 60L for join, where L=log⁡2(W/w(xi))L = \log_2(W/w(x_i)). Only these have no dependence on nn.

Reading the Lean
  • In all four theorems the cut is an arbitrary natural number. A cut beyond the end of the list gives the final configuration.
  • The depth bound covers every rank of the source subtree node l key r, in the physical tree middle.tree of the intermediate configuration, wherever its cursor is.
  • These theorems are a self-contained statement about one exposure or join of a source root. The deamortized simulation of Chapter 30 does not cite them directly: it goes through the finger simulation of Section 38.4, which proves its own interruption bound, 336+240log⁡2(W/w)336 + 240\log_2(W/w), from the _within theorems of this section.