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 at depth , where 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:
Let be a labelled tree with nodes and positive node weights , and let be its total weight. The canonical recursive representation rebuild w t is a tree shape with the same nodes. If is ordered, rebuild w t has exactly one ordered labelling with the inorder of , so it is a BST on the same keys. Whether or not is ordered, the node of inorder rank , whose label in is , lies at depth
With unit weights this is for every rank . 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 into rebuild w t in at most 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 . 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
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 orderedModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 rankModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 rankModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 positiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.DefinitionsThis 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 , 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 : 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 , 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 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 , 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 , in the same inorder. This section has four layers:
- 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. - Exposure (
Recursive.Exposure). The finger of the source algorithm starts at the root of . 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. - 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 amortized and worst case. - 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 to , pop-tarts , (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 is a telescoping sum | depth_telescope, rebuild_depth |
| moves down the path (finger moves down from the root) | expose_view, layout_expose |
| 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 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 .
/-- 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]def upperFrames {α : Type} : List (Frame α) → List (Frame α) | [] => [] | f@(.left _ _) :: cs => f :: upperFrames cs | .right _ _ :: cs => upperFrames csdef lowerBlock {α : Type} (frame : Frame α) : List α := (framePayload frame).inorder ++ [frameKey frame]def upperBlock {α : Type} (frame : Frame α) : List α := frameKey frame :: (framePayload frame).inorderlowerFrames 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:
theorem context_inorder {α : Type} (cs : List (Frame α)) (t : LabelledTree α) : (plug cs t).inorder = (lowerFrames cs).flatMap lowerBlock ++ t.inorder ++ (upperFrames cs).flatMap upperBlock := RotationBST.HeavyPath.Recursive.context_inorder cs tModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.DefinitionsHere LabelledCursor.plug cs t rebuilds the tree from the context. The statement holds for every context, heavy or not.
/-- 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) xRanksSatisfy 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
/-- 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.erasenoncomputable def rebuild {α : Type} (weight : α → ℝ) (t : LabelledTree α) : Tree := rebuildFuel weight t.erase.size t/-- 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.emptyrebuildFuel 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 , where 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:
/-- 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).treeLayout 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:
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 memModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 memModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionsrebuild produces a layout, the layout is unique, and the fuel has no effect once it is large enough:
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 enoughModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem rebuild_layout {α : Type} {weight : α → ℝ} {t : LabelledTree α} (positive : Positive weight t) : Layout weight t (rebuild weight t) := RotationBST.HeavyPath.Recursive.rebuild_layout positiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 rightModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 enoughModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionslayout_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:
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 nonemptyModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 nonemptyModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 nonemptyModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 nonemptyModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.DefinitionsIn 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 : the frame charges partition the weights of . 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:
theorem layout_size {α : Type} {weight : α → ℝ} {t : LabelledTree α} {shape : Tree} (layout : Layout weight t shape) : shape.size = t.erase.size := RotationBST.HeavyPath.Recursive.layout_size layoutModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem rebuild_size {α : Type} {weight : α → ℝ} {t : LabelledTree α} (positive : Positive weight t) : (rebuild weight t).size = t.erase.size := RotationBST.HeavyPath.Recursive.rebuild_size positiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 orderedModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 nonemptyModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.DefinitionsTree 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:
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 positiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitions- The bound 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 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, asPointer.Tracedoes.
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 at depth at most inside a pop-tart of mass (Section 37.2). One more edge, from the endpoint to the pop-tart, gives .
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 memModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 memModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionsextract_payload_half is the halving: every payload of the heavy path has at most half the mass of . 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:
theorem depth_telescope {whole child key d : ℝ} (keyPositive : 0 < key) (keyMass : key ≤ child) (half : 2 * child ≤ whole) (bound : d ≤ 8 + 7 * Real.logb 2 (whole / child) + (7 + 15 * Real.logb 2 (child / key))) : d ≤ 7 + 15 * Real.logb 2 (whole / key) := RotationBST.HeavyPath.Recursive.depth_telescope keyPositive keyMass half boundModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.DefinitionsLet the whole tree have mass , a payload have mass with , and a key in it have weight . If the key’s depth is at most the depth of the payload in the outer pair, , plus the inductive bound inside the payload, , then . Since , the additive is absorbed into , and . This is how a constant per light edge disappears into the logarithm. It is also why the coefficient is roughly twice the pop-tart’s .
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.
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 childBoundModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 existsKeyModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 existsKeyModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.DefinitionsThe 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 .
Strong induction on the size of then covers every rank:
Theorem (depth of the canonical layout). Let have positive weights and total weight . Every occurrence of a label in the inorder of , at position , is at depth at most in rebuild w t. With unit weights, every rank is at depth at most .
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 occurrenceModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 rankModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.Definitionstheorem 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 validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.DefinitionsThe 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 and . It needs no positivity hypothesis, since unit weights are positive.
A depth bound gives a search walk. Visiting rank and returning to the root costs one unit for the request plus two walks of moves:
theorem rebuild_search_walk {α : Type} {weight : α → ℝ} {t : LabelledTree α} (positive : Positive weight t) (rank : Fin t.inorder.length) : ∃ (visited : Pointer.Config) (cost : Nat), visited.tree = rebuild weight t ∧ visited.key? = some rank.val ∧ Pointer.Trace ⟨rebuild weight t, []⟩ visited cost ∧ Pointer.Trace visited ⟨rebuild weight t, []⟩ cost ∧ (1 + 2 * cost : ℝ) ≤ 15 + 30 * Real.logb 2 (HeavyPath.mass weight t / weight (t.inorder[rank.val]'rank.isLt)) := RotationBST.HeavyPath.Recursive.rebuild_search_walk positive rankModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.PopTart.Located.Definitions, Bounds.StaticTree.DefinitionsThe constants are doubled, , 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 . 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.
/-- 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)noncomputable def leftTree {α : Type} (weight : α → ℝ) (l : LabelledTree α) : View → Tree | .leaf => .nil | .left rest => rest.tree | .right _ => rebuild weight lnoncomputable def rightTree {α : Type} (weight : α → ℝ) (r : LabelledTree α) : View → Tree | .leaf => .nil | .left _ => rebuild weight r | .right rest => rest.treedef potential : View → Nat | .leaf => 0 | .left rest | .right rest => rest.potentialdef 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).contextA 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 has the size of :
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 positiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.Exposure.Definitionstheorem 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 representedModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.Exposure.DefinitionsTheorem (root exposure). Let node l x r have positive weights, with canonical representation of potential . There is a pointer trace, from root to root, that turns into node a b with a and b representing l and r. Its cost satisfies , where is the potential of the residual pair, and the new root has the rank of .
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 nonemptyModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.Exposure.Definitionstheorem 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 nonemptyModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.Exposure.Definitionstheorem 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 positiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.Exposure.Definitionstheorem 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 representedModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.Exposure.Definitionstheorem 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 positiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.Exposure.Definitionsexpose_left and expose_right are the two cases. The cost is Stacks.exposeCost: one pop from the stack that holds , 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 . 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 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.
/-- 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 : Natdef slot {α : Type} (weight : α → ℝ) (e : Entry α) : Tree × ℝ := (e.shape, frameMass weight e.source)def lowerBlock {α : Type} (e : Entry α) : List α := Recursive.lowerBlock e.sourcedef upperBlock {α : Type} (e : Entry α) : List α := Recursive.upperBlock e.source/-- 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 childAn 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.
def lower {α : Type} : List (Entry α) → List (Entry α) | [] => [] | e :: es => match e.source with | .left _ _ => lower es | .right _ _ => lower es ++ [e]def upper {α : Type} : List (Entry α) → List (Entry α) | [] => [] | e :: es => match e.source with | .left _ _ => e :: upper es | .right _ _ => upper eslower and upper select the entries of each pop-tart in physical key order, exactly as lowerFrames and upperFrames do for frames.
/-- 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)pairStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean and its importslowerStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean and its importsupperStructures/HeavyPath/Recursive/History/Definitions/Abstract.lean and its importsPathValid 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:
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 validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 focusModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitions38.2.5.2 History layouts
/-- 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 . 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:
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 layoutModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 layoutModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 orderedModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.DefinitionsThe canonical layout is a history layout, with credit at most , and every history layout has credit at most :
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 layoutModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem rebuild_history {α : Type} {weight : α → ℝ} {t : LabelledTree α} (positive : Positive weight t) : ∃ credit, Layout weight t (rebuild weight t) credit := RotationBST.HeavyPath.Recursive.History.rebuild_history positiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 layoutModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 positiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 layoutModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionspath_potential_bound bounds one pair by per entry. layout_potential_bound adds this over the recursion. A source tree with nodes has fewer than entries in total, so its credit is at most . The of the two _bounded theorems is therefore not the best constant: layout_potential_bound applied to rebuild_history gives . 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:
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 occurrenceModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 rankModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 rankModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.DefinitionsThe 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:
theorem pop_path {α : Type} {weight : α → ℝ} {es : List (Entry α)} {e : Entry α} {p : Stacks} (valid : PathValid weight (es ++ [e]) p) : ∃ rest : Stacks, PathValid weight es rest ∧ Pointer.Trace ⟨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 validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.DefinitionsExposing 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 . A root-to-root trace of cost turns it into node a b, where a and b are history layouts of l and r with credits and , with and . Conversely, from layouts a, b of l, r, a trace of cost produces a layout of node l x r with credit and .
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 layoutModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 keyPositiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 layoutModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 keyPositiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.DefinitionsThe amortized bound is the Chocolate pop-tart’s. The worst-case bounds come from the depth of the stack being popped or pushed into. Here 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.
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 nonnegativeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 layoutModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitionstheorem 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 keyPositiveModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.DefinitionsIn every intermediate tree of a pop or an exposure, the size is unchanged and every rank is at depth at most . For a push or a join, the constant is , 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 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 node_depth_at {α : 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) (rank : Fin (LabelledTree.node l key r).inorder.length) : (Tree.depth (.node a b) rank.val : ℝ) ≤ 8 + 15 * 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.node_depth_at left right positive rankModels.Rotation, Models.Multifinger.Program.Definitions, Models.Multifinger.Program.Replay.Definitions, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.DefinitionsTheorem (interruptible exposure and join). Let be the mass of node l key r and 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 , with label , has depth at most
Purely weighted versions give for exposure and for join. With unit weights, the bounds are and .
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 layoutModels.Rotation, Models.Multifinger.Program.Definitions, Models.Multifinger.Program.Replay.Definitions, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitionstheorem 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 positiveModels.Rotation, Models.Multifinger.Program.Definitions, Models.Multifinger.Program.Replay.Definitions, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.DefinitionsThe 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.
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 layoutModels.Rotation, Models.Multifinger.Program.Definitions, Models.Multifinger.Program.Replay.Definitions, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitionstheorem 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 rightModels.Rotation, Models.Multifinger.Program.Definitions, Models.Multifinger.Program.Replay.Definitions, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitionstheorem 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 layoutModels.Rotation, Models.Multifinger.Program.Definitions, Models.Multifinger.Program.Replay.Definitions, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.Definitionstheorem 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 positiveModels.Rotation, Models.Multifinger.Program.Definitions, Models.Multifinger.Program.Replay.Definitions, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Models.Labelled.Ordering.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Mirror.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Recursive.History.Definitions, Bounds.StaticTree.DefinitionsThe weighted versions instead use the multiplicative bounds of the _within theorems: for exposure, and, from node_depth_at, for join, where . Only these have no dependence on .
- 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 treemiddle.treeof 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, , from the
_withintheorems of this section.