Chapter 38 · Heavy paths · Section 38.3Fingers on heavy paths
The deamortization of Chapter 30 runs a source algorithm inside a tree of logarithmic depth. The source works in the BST model of Bose, Collette, Fagerberg and Langerman (2012a): it has one persistent finger, which it moves to a parent or a child, or rotates over its parent, at unit cost per operation. In the library the source finger is a labelled cursor (LabelledCursor.Config, operated by LabelledCursor.perform; see Chapter 36). The simulating structure is a pointer machine in the sense of Chapter 7. Its cursor returns to the root, and every operation of the source must become a short pointer trace from the root back to the root.
Section 3 of the paper does this with heavy paths stored in pop-tarts. When the source finger is at the root of its tree, every heavy path is a pair of pop-tarts hung below the path’s endpoint. That is the representation of Section 38.1, applied recursively in Section 38.2. When the finger is elsewhere, the paper stores the path from the root down to upside down, as a second kind of pair of pop-tarts, with at the physical root (Figure 5 of the paper). This section formalizes that inverted pair. It covers three things:
- Building. A finger pair can be built from any source cursor. The setup costs a linear number of pointer instructions, and every node lies at logarithmic weighted depth.
- Population. Stack operations inside the pair cost in the worst case, where is the number of nodes.
- Transfer. Moving the source finger down to a child moves one node from one stack to the other, at constant amortized cost and worst-case cost.
Section 38.4 completes the picture. It wraps the pair in a state that also records the recursive layouts of all off-path subtrees, adds the upward moves and the rotations, and assembles the simulation that Chapter 30 schedules.
Let be a labelled tree with nodes and a cursor at one of its nodes, the finger . The cursor’s path to the root is arbitrary; it need not be heavy. Give every node a weight , and let be the total weight. Build the finger pair of this cursor with Finger.build. Then:
- Setup. Starting with the pointer at the root of , at most pointer instructions turn into the pair’s tree, and end with the pointer at its root.
- Same keys. If is a BST, the pair’s tree carries exactly one labelling with the inorder of , and that labelling is a BST.
- Finger at the root. The root of the pair’s tree has the rank of in .
- Weighted depth. The node of at inorder rank , with weight , has depth at most in the pair’s tree.
This is the depth claim of the paper’s Theorem 5 at a single moment, for a finger in general position, with explicit constants. The bound holds for the pair as built; that it survives the source’s operations is the subject of Section 38.4.
The Lean statements
theorem build_initialization {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) : ∃ cost, cost ≤ 16 * (plug cs (.node left key right)).erase.size ∧ Pointer.Trace ⟨(plug cs (.node left key right)).erase, []⟩ ⟨(build weight cs left right).tree, []⟩ cost := … RotationBST.HeavyPath.Finger.build_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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem build_labels {α : Type} [Preorder α] {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) (ordered : (plug cs (.node left key right)).Ordered) : ∃! u : LabelledTree α, u.erase = (build weight cs left right).tree ∧ u.inorder = (plug cs (.node left key right)).inorder ∧ u.Ordered := … RotationBST.HeavyPath.Finger.build_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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem build_root_key {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) : (Pointer.Config.mk (build weight cs left right).tree []).key? = (Config.mk (.node left key right) cs).erase.key? := … RotationBST.HeavyPath.Finger.build_root_key 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem build_depth {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) {before after : List α} {target : α} (occurrence : (plug cs (.node left key right)).inorder = before ++ target :: after) : (Tree.depth (build weight cs left right).tree before.length : ℝ) ≤ 15 + 15 * Real.logb 2 (HeavyPath.mass weight (plug cs (.node left key right)) / weight target) := … RotationBST.HeavyPath.Finger.build_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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.DefinitionsNo headline result of the deamortization mentions a finger pair. The definitions here lie on the proof path of the transformation in Chapter 30: the bounded-depth simulation Results.simulation runs on the finger states of Section 38.4, and those states consist of one finger pair plus recursive payloads. Read this section to see how the source finger is kept at the physical root, where the setup cost and the depth constants come from, and why a downward move has constant amortized cost. A reader who only wants to check Theorem 6 can skip it.
38.3.1 Overview
38.3.1.1 The inverted path
Let the finger be at depth in the source tree. Its ancestors split into two monotone sequences. The lower ancestors are smaller than , and they increase on the way down. The upper ancestors are larger than , and they decrease on the way down. Each ancestor contributes its key, a separator, and the subtree that hangs off the path at that ancestor, a payload. The two children of are payloads too. In inorder the source tree reads
where are the lower ancestors from the root down, their left subtrees, the upper ancestors from the root down, their right subtrees, and and the subtrees of .
A finger pair stores the left half in one Chocolate pop-tart and the right half in another, and puts between them:
f (physical root)
/ \
mirrored lower pop-tart upper pop-tart
slots l1 l2 ... lj L slots R ri ... r2 r1
separators x1 ... xj separators yi ... y1
top slot: L (next to f) top slot: R (next to f)
The payloads are the pop-tarts’ fringe slots (Section 37.1), and the ancestors are their internal nodes. The top of each stack, the slot most recently pushed, is the payload next to in inorder: on the lower side and on the upper side. The bottom slots, and , belong to the ancestors nearest the source root. A Chocolate pop-tart pushes new nodes on the smaller side of its stack, which suits the upper ancestors directly. The lower stack is stored in mirrored coordinates and reflected when it is decoded. The heavy-path pair of Section 38.1 uses the opposite orientations. There the endpoint of a downward path is the physical root and the stacks grow at their outer ends, where the top of the path is. Here they grow next to the finger.
Inside each payload, the source subtree is represented recursively by the heavy-path pairs of Section 38.2. The finger pair is the one place where a path is stored upside down. The structure is weighted: a slot of weight in a pop-tart of total weight sits at depth . This is the paper’s Lemma 4, Results.weighted_depth in Section 37.2. Telescoping it through the nested payloads gives the depth bound of the headline.
38.3.1.2 Charges
A pop-tart weighs only its fringe slots; its internal nodes have no weight. (The paper’s pop-tarts give internal nodes unit weight by convention, and its weighted simulation does not spell out where the weights of path nodes go.) The library charges each ancestor’s weight to the adjacent payload on the side of the finger. With weights and the total weight of a subtree, the lower slots carry
and symmetrically on the upper side. The two stacks together therefore weigh . Only the finger’s own weight is outside them. A separator sits next to the slot that carries its weight, so the depth bound for slots also bounds separators.
38.3.1.3 Moves and costs
A move of the source finger to a child transfers one node. When the finger moves to its left child , the payload must first have at its physical root. Then two or four instructions rotate above , and becomes a separator of the upper stack, with the right subtree of as its new top slot. That is one Chocolate push. The lower stack keeps its shape, and its top slot shrinks from to the left subtree of . The paper describes a move as “one push and one pop”. In the library a downward move is a push and a replacement of the top payload. Upward moves pop, and they are in Section 38.4.
All costs are counted as pointer instructions (Pointer.Trace) from the root configuration to the root configuration of the result, and below is the number of nodes in the pair’s tree (equal to ).
| operation | bound | lemma |
|---|---|---|
| build from the source tree | at most instructions | build_initialization |
| depth of a node of weight in a fresh pair | at most | build_depth |
| push onto either stack | at most | lower_push, upper_push |
| pop from either stack | at most | lower_pop, upper_pop |
| move down, child already exposed | amortized at most | downLeft_amortized |
| move down, given an exposure of cost | amortized at most ; actual at most | downLeft_exposed_bounded |
| move down into a recursive payload | amortized at most , the payload’s potential included | downLeft_pair, downLeft_recursive, downLeft_source |
| same, arbitrary layout histories | amortized at most ; actual at most ; intermediate depths at most | Transfer.History.Results.downLeft_within |
Each downLeft lemma has a downRight mirror image with the same constants.
38.3.2 The finger pair
/-- The inverted path has the opposite stack orientations from a downwardheavy path. Its physical root is the original finger node. -/structure Pair where lower : Layer upper : Layerdef Pair.tree (p : Pair) : Tree := .node p.lower.decode.tree.mirror p.upper.decode.treedef Pair.mass (p : Pair) : ℝ := p.lower.decode.mass + p.upper.decode.massdef Pair.Valid (p : Pair) : Prop := p.lower.Valid 0 ∧ p.upper.Valid 0A Pair is two Chocolate stacks (Chocolate.Layer, Section 37.2). Its physical tree is a root node, the finger, whose left subtree is the decoded lower stack mirrored (Tree.mirror) and whose right subtree is the decoded upper stack. The finger node carries no data of its own. Its key is determined by its position, as for every node of an unlabelled Tree. The mass is the total weight of the fringe slots of both stacks, excluding the finger. Valid asks only that both stacks satisfy the Chocolate invariant at level . It says nothing about which source cursor the pair represents. That correspondence is stated by the fringe equations of the build theorems below, and maintained by the state invariant History.Valid of Section 38.4.
38.3.3 Building a pair from a cursor
A source cursor is a context cs of labelled frames (LabelledCursor.Frame), innermost first, and a focus node left key right. The whole source tree is plug cs (.node left key right). The lower frames, in inorder, are Recursive.lowerFrames cs, and the upper ones are Recursive.upperFrames cs, from the finger outward.
38.3.3.1 Slots and their charges
/-- Ancestors are charged to the next payload toward the finger. The firstouter payload has no preceding separator; the last payload is a finger child. -/def sideSlots {α : Type} (weight : α → ℝ) (payload : LabelledTree α → Tree) (boundary : LabelledTree α) : ℝ → List (Frame α) → List (Tree × ℝ) | carry, [] => [(payload boundary, carry + HeavyPath.mass weight boundary)] | carry, f :: fs => (payload (framePayload f), carry + HeavyPath.mass weight (framePayload f)) :: sideSlots weight payload boundary (weight (frameKey f)) fssideSlots weight payload boundary carry fs lists one side’s slots, outermost first, as pairs of a physical payload and its charge. Each frame f of fs contributes the slot payload (framePayload f) (Paired.framePayload), charged with its subtree’s mass plus carry. The carry is the weight of the previous frame’s separator, HeavyPath.frameKey. The last slot is the finger’s child boundary, which carries the weight of the innermost separator. The first slot has no preceding separator, so the build starts with carry = 0. The physical payloads are given by a function, so the same list can describe raw subtrees or recursively rebuilt ones. The build uses Recursive.rebuild, the canonical recursive layout of Section 38.2.
theorem sideSlots_nonempty {α : Type} (weight : α → ℝ) (payload : LabelledTree α → Tree) (boundary : LabelledTree α) (carry : ℝ) (fs : List (Frame α)) : sideSlots weight payload boundary carry fs ≠ [] := RotationBST.HeavyPath.Finger.sideSlots_nonempty weight payload boundary carry fsModels.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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem sideSlots_nonnegative {α : Type} {weight : α → ℝ} (payload : LabelledTree α → Tree) {boundary : LabelledTree α} (boundaryPositive : Positive weight boundary) {carry : ℝ} (carryNonnegative : 0 ≤ carry) {fs : List (Frame α)} (framesPositive : ∀ f ∈ fs, Positive weight (framePayload f) ∧ 0 < weight (frameKey f)) : ∀ entry ∈ sideSlots weight payload boundary carry fs, 0 ≤ entry.2 := RotationBST.HeavyPath.Finger.sideSlots_nonnegative payload boundaryPositive carryNonnegative framesPositiveModels.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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem sideSlots_mass {α : Type} (weight : α → ℝ) (payload : LabelledTree α → Tree) (boundary : LabelledTree α) (carry : ℝ) (fs : List (Frame α)) : ((sideSlots weight payload boundary carry fs).map Prod.snd).sum = carry + HeavyPath.mass weight boundary + (fs.map (frameMass weight)).sum := RotationBST.HeavyPath.Finger.sideSlots_mass weight payload boundary carry fsModels.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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem sideSlots_span {α : Type} (weight : α → ℝ) (payload : LabelledTree α → Tree) (boundary : LabelledTree α) (carry : ℝ) (fs : List (Frame α)) : fringeSpan (sideSlots weight payload boundary carry fs) = (fs.map (fun f => (payload (framePayload f)).size + 1)).sum + (payload boundary).size + 1 := RotationBST.HeavyPath.Finger.sideSlots_span weight payload boundary carry fsModels.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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem frame_mass_partition {α : Type} (weight : α → ℝ) (cs : List (Frame α)) : ((lowerFrames cs).map (frameMass weight)).sum + ((upperFrames cs).map (frameMass weight)).sum = (cs.map (frameMass weight)).sum := RotationBST.HeavyPath.Finger.frame_mass_partition weight csModels.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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.DefinitionsThese five facts are the bookkeeping. A side always has at least one slot, the finger’s child. With positive weights and a nonnegative carry, every charge is nonnegative. The charges add up to the carry plus the mass of the boundary plus the masses HeavyPath.frameMass of the frames, each frame’s mass being its separator’s weight plus its payload’s mass. The fringeSpan (WeightedTree.fringeSpan) of the slots, one plus the size of each payload, counts the keys of the payloads together with the separators that follow them. The lower and upper frames partition the frames of the context, so their masses add up to the total.
38.3.3.2 Assembly by pushes
/-- Assemble a nonempty fringe by actual Chocolate pushes, starting at itslast leaf. The empty case is only a totalization of this auxiliary function. -/noncomputable def assemble : List (Tree × ℝ) → Layer | [] => .last .zero (.base (.leaf .nil 0)) | [entry] => .last .zero (.base (.leaf entry.1 entry.2)) | entry :: next :: rest => (assemble (next :: rest)).push (.leaf entry.1 entry.2)assemble slots builds a Chocolate stack whose fringe is slots, read top first. It starts from the last slot as the stack’s only leaf and pushes the others in turn with the real Chocolate push (Layer.push), so the result is an actual stack history, not a stack written down directly. The value on the empty list is only a totalization.
theorem assemble_valid_fringe (slots : List (Tree × ℝ)) (nonempty : slots ≠ []) (nonnegative : ∀ entry ∈ slots, 0 ≤ entry.2) : (assemble slots).Valid 0 ∧ (assemble slots).decode.fringe = slots := RotationBST.HeavyPath.Finger.assemble_valid_fringe slots nonempty 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem assemble_mass (slots : List (Tree × ℝ)) (nonempty : slots ≠ []) (nonnegative : ∀ entry ∈ slots, 0 ≤ entry.2) : (assemble slots).decode.mass = (slots.map Prod.snd).sum := RotationBST.HeavyPath.Finger.assemble_mass slots nonempty 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.DefinitionsOn a nonempty list of nonnegative charges, the assembled stack is valid, its fringe (WeightedTree.fringe) is exactly the list, and its mass is the sum of the charges.
38.3.3.3 The build
def reflectSlot (entry : Tree × ℝ) : Tree × ℝ := (entry.1.mirror, entry.2)noncomputable def build {α : Type} (weight : α → ℝ) (cs : List (Frame α)) (left right : LabelledTree α) : Pair := ⟨assemble ((sideSlots weight (rebuild weight) left 0 (lowerFrames cs)).map reflectSlot).reverse, assemble (sideSlots weight (rebuild weight) right 0 (upperFrames cs).reverse).reverse⟩build weight cs left right assembles both stacks. The lower slots are mirrored with reflectSlot, which mirrors the payload and keeps its charge, and are reversed so that the finger’s child left is on top. The upper frames are reversed so that the slots are computed from the root inward, as the charging rule needs, and the slot list is reversed back so that right is on top. The key of the focus is not an argument: the finger is the pair’s root node, and its key is implicit in the position.
theorem build_valid_fringe {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) : (build weight cs left right).Valid ∧ (build weight cs left right).lower.decode.mirror.fringe = sideSlots weight (rebuild weight) left 0 (lowerFrames cs) ∧ (build weight cs left right).upper.decode.fringe = (sideSlots weight (rebuild weight) right 0 (upperFrames cs).reverse).reverse := RotationBST.HeavyPath.Finger.build_valid_fringe 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem build_mass {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) : weight key + (build weight cs left right).mass = HeavyPath.mass weight (plug cs (.node left key right)) := RotationBST.HeavyPath.Finger.build_mass 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem build_side_sizes {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) : (build weight cs left right).lower.decode.tree.mirror.size = ((lowerFrames cs).flatMap lowerBlock).length + left.erase.size ∧ (build weight cs left right).upper.decode.tree.size = right.erase.size + ((upperFrames cs).flatMap upperBlock).length := RotationBST.HeavyPath.Finger.build_side_sizes 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem build_size {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) : (build weight cs left right).tree.size = (plug cs (.node left key right)).erase.size := RotationBST.HeavyPath.Finger.build_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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem lower_blocks_offset {α : Type} (cs : List (Frame α)) : ((lowerFrames cs).flatMap lowerBlock).length = Pointer.offset (cs.map Frame.erase) := RotationBST.HeavyPath.Finger.lower_blocks_offset csModels.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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem build_root_key {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) : (Pointer.Config.mk (build weight cs left right).tree []).key? = (Config.mk (.node left key right) cs).erase.key? := RotationBST.HeavyPath.Finger.build_root_key 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.DefinitionsWith positive weights on the whole source tree:
- the pair is valid, and its two fringes, in physical inorder, are the slot lists of the two sides (
build_valid_fringe); - the finger’s weight plus the pair’s mass is the total weight of the source tree (
build_mass); - the lower side has as many nodes as the lower blocks (
Recursive.lowerBlock: each lower payload with its separator) plusleft, the upper side likewise, and the whole pair has as many nodes as the source tree (build_side_sizes,build_size); - the lower blocks contain exactly
Pointer.offsetof the erased context keys, the number of keys before the focus (lower_blocks_offset), so the root of the pair has the rank of the finger in the source (build_root_key, stated withConfig.key?).
theorem build_labels {α : Type} [Preorder α] {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) (ordered : (plug cs (.node left key right)).Ordered) : ∃! u : LabelledTree α, u.erase = (build weight cs left right).tree ∧ u.inorder = (plug cs (.node left key right)).inorder ∧ u.Ordered := RotationBST.HeavyPath.Finger.build_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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.DefinitionsIf the source tree is a BST (LabelledTree.Ordered), the pair’s tree has exactly one labelling with the same inorder, and that labelling is a BST. The physical tree therefore stores the same keys in the same order. Only the shape differs.
38.3.3.4 Setup cost
Theorem (setup). For positive weights, the pointer machine turns the source tree into the finger pair, from root configuration to root configuration, with at most instructions, where is the number of nodes.
theorem build_initialization {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) : ∃ cost, cost ≤ 16 * (plug cs (.node left key right)).erase.size ∧ Pointer.Trace ⟨(plug cs (.node left key right)).erase, []⟩ ⟨(build weight cs left right).tree, []⟩ cost := RotationBST.HeavyPath.Finger.build_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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.DefinitionsThe proof does not follow the construction. Any two trees with the same number of nodes are at most pointer instructions apart, by the generic reshaping theorem Results.reshape of Chapter 7, and build_size says the sizes agree. The constant is therefore that of reshaping, and the same argument gives the setup of a heavy-path layout, Results.rebuild_initialization. This is the setup term that the deamortization charges once, before any request.
38.3.4 Depth
The depth bound has two levels. The first bounds the depth of a slot or separator within the pair, in terms of the pair’s mass. The second adds the depth inside the slot’s payload, which Section 38.2 bounds by the payload’s mass. The two logarithms telescope.
38.3.4.1 Inside the pair
The theorems below locate a slot in the pair’s outer weighted tree, node lower.mirror upper, whose physical tree is the pair’s tree. A WeightedTree.LocatedSlot records the slot’s payload, its charge, the inorder offset of its first key, and its edge depth (Section 37.1).
theorem located_mass {p : Pair} (valid : p.Valid) {subtree : Tree} {weight : ℝ} {offset depth : Nat} (slot : LocatedSlot (.node p.lower.decode.mirror p.upper.decode) subtree weight offset depth) : 0 ≤ weight ∧ weight ≤ p.mass := RotationBST.HeavyPath.Finger.located_mass valid slotModels.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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem located_depth {p : Pair} (valid : p.Valid) {subtree : Tree} {weight : ℝ} {offset depth : Nat} (slot : LocatedSlot (.node p.lower.decode.mirror p.upper.decode) subtree weight offset depth) (positive : 0 < weight) : (depth : ℝ) ≤ 8 + 7 * Real.logb 2 (p.mass / weight) := RotationBST.HeavyPath.Finger.located_depth valid slot 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem located_key_bound {p : Pair} (valid : p.Valid) {subtree : Tree} {weight : ℝ} {offset depth : Nat} (slot : LocatedSlot (.node p.lower.decode.mirror p.upper.decode) subtree weight offset depth) (positive : 0 < weight) (rank : Nat) (inside : rank < subtree.size) : (Tree.depth p.tree (offset + rank) : ℝ) ≤ 8 + 7 * Real.logb 2 (p.mass / weight) + Tree.depth subtree rank := RotationBST.HeavyPath.Finger.located_key_bound valid slot positive rank insideModels.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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem located_predecessor_bound {p : Pair} (valid : p.Valid) {subtree : Tree} {weight : ℝ} {offset depth : Nat} (slot : LocatedSlot (.node p.lower.decode.mirror p.upper.decode) subtree weight offset depth) (positive : 0 < weight) (existsKey : 0 < offset) : (Tree.depth p.tree (offset - 1) : ℝ) ≤ 7 + 7 * Real.logb 2 (p.mass / weight) := RotationBST.HeavyPath.Finger.located_predecessor_bound valid slot positive 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem located_successor_bound {p : Pair} (valid : p.Valid) {subtree : Tree} {weight : ℝ} {offset depth : Nat} (slot : LocatedSlot (.node p.lower.decode.mirror p.upper.decode) subtree weight offset depth) (positive : 0 < weight) (existsKey : offset + subtree.size < p.tree.size) : (Tree.depth p.tree (offset + subtree.size) : ℝ) ≤ 7 + 7 * Real.logb 2 (p.mass / weight) := RotationBST.HeavyPath.Finger.located_successor_bound valid slot positive 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.DefinitionsIn a valid pair of mass , a slot of charge :
- has (
located_mass); - sits at depth at most , which is one edge below the finger plus the Chocolate bound (
located_depth); - puts the key of rank of its payload at depth at most plus that key’s depth inside the payload (
located_key_bound); - has its two neighbouring separators, the keys just before and just after it in inorder, at depth at most , when they exist (
located_predecessor_bound,located_successor_bound).
Neighbouring separators are the reason for the charging rule. Every ancestor is the immediate predecessor or successor of the slot that carries its weight, so its depth is at most . The finger itself is at depth .
38.3.4.2 Telescoping
theorem payload_estimate {whole pair charge child key d : ℝ} (keyPositive : 0 < key) (keyMass : key ≤ child) (childCharge : child ≤ charge) (chargeMass : charge ≤ pair) (sourceMass : pair ≤ whole) (bound : d ≤ 8 + 7 * Real.logb 2 (pair / charge) + (7 + 15 * Real.logb 2 (child / key))) : d ≤ 15 + 15 * Real.logb 2 (whole / key) := RotationBST.HeavyPath.Finger.payload_estimate keyPositive keyMass childCharge chargeMass sourceMass 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionspayload_estimate is pure arithmetic. Consider masses : a key’s weight , the mass of the payload containing it, that payload’s charge , the pair’s mass and the whole weight . Suppose a depth is at most , for the slot, plus , the recursive bound of Results.rebuild_depth inside the payload. Then . The constant absorbs the outer constant , and the coefficient absorbs the outer logarithm. This is the telescoping sum at the end of the paper’s Section 3. The heavy-path pairs of Section 38.2 telescope in the same way (Results.depth_telescope), and the finger pair costs more in the constant.
38.3.4.3 Depth of a fresh pair
Theorem (weighted depth). With positive weights and total weight , every node occurrence of weight in the source tree has depth at most in the built pair. With unit weights, the bound is .
theorem build_depth {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) {before after : List α} {target : α} (occurrence : (plug cs (.node left key right)).inorder = before ++ target :: after) : (Tree.depth (build weight cs left right).tree before.length : ℝ) ≤ 15 + 15 * Real.logb 2 (HeavyPath.mass weight (plug cs (.node left key right)) / weight target) := RotationBST.HeavyPath.Finger.build_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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem build_depth_at {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) (rank : Fin (plug cs (.node left key right)).inorder.length) : (Tree.depth (build weight cs left right).tree rank.val : ℝ) ≤ 15 + 15 * Real.logb 2 (HeavyPath.mass weight (plug cs (.node left key right)) / weight ((plug cs (.node left key right)).inorder[rank.val]'rank.isLt)) := RotationBST.HeavyPath.Finger.build_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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionstheorem build_unit_depth {α : Type} (cs : List (Frame α)) (left right : LabelledTree α) (key : α) (rank : Nat) (valid : rank < (plug cs (.node left key right)).erase.size) : (Tree.depth (build (fun _ => 1) cs left right).tree rank : ℝ) ≤ 15 + 15 * Real.logb 2 ((plug cs (.node left key right)).erase.size : ℝ) := RotationBST.HeavyPath.Finger.build_unit_depth cs left right key 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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.Definitionsbuild_depth names an occurrence by splitting the source inorder as before ++ target :: after; its rank is before.length. Labels may repeat, so this form refers to one occurrence and not to a key. build_depth_at is the same statement indexed by a rank. build_unit_depth takes all weights equal to , so , and needs no positivity hypothesis. None of the three assumes that the ancestor path of the finger is heavy: the bound holds for every cursor.
theorem build_search_walk {α : Type} {weight : α → ℝ} {cs : List (Frame α)} {left right : LabelledTree α} {key : α} (positive : Positive weight (plug cs (.node left key right))) (rank : Fin (plug cs (.node left key right)).inorder.length) : ∃ (visited : Pointer.Config) (cost : Nat), visited.tree = (build weight cs left right).tree ∧ visited.key? = some rank.val ∧ Pointer.Trace ⟨(build weight cs left right).tree, []⟩ visited cost ∧ Pointer.Trace visited ⟨(build weight cs left right).tree, []⟩ cost ∧ (1 + 2 * cost : ℝ) ≤ 31 + 30 * Real.logb 2 (HeavyPath.mass weight (plug cs (.node left key right)) / weight ((plug cs (.node left key right)).inorder[rank.val]'rank.isLt)) := RotationBST.HeavyPath.Finger.build_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.PopTart.Located.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Recursive.Definitions, Structures.HeavyPath.Finger.Definitions, Bounds.StaticTree.DefinitionsThe search walk turns depth into cost. For every rank there is a configuration with the cursor on that rank and the tree unchanged, reached from the root and left back to the root by traces of the same length cost. One unit for the request plus the walk down and back costs at most . This is the form in which the deamortization uses the depth bound: it serves a pending request by walking to the key and back.
38.3.5 Population
The Chocolate worst-case bounds of Section 37.2, Results.push_worst_case and Results.pop_worst_case, are stated in terms of a stack’s number of slots, its WeightedTree.leafCount. The simulation needs them in terms of , the number of nodes of the pair’s tree, which does not change as the finger moves.
theorem pair_population (p : Pair) : 1 ≤ p.lower.decode.leafCount ∧ p.lower.decode.leafCount ≤ p.tree.size ∧ 1 ≤ p.upper.decode.leafCount ∧ p.upper.decode.leafCount ≤ p.tree.size := RotationBST.HeavyPath.Finger.Population.pair_population pModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitions, Structures.PopTart.Chocolate.Top.DefinitionsEach stack of any pair has between and slots. A stack with slots has separators, and the finger is outside both stacks, so this holds with no validity hypothesis.
theorem lower_push {p : Pair} (valid : p.Valid) : (p.lower.pushCost : ℝ) ≤ 6 + 14 * Real.logb 2 p.tree.size := RotationBST.HeavyPath.Finger.Population.lower_push validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitions, Structures.PopTart.Chocolate.Top.Definitionstheorem upper_push {p : Pair} (valid : p.Valid) : (p.upper.pushCost : ℝ) ≤ 6 + 14 * Real.logb 2 p.tree.size := RotationBST.HeavyPath.Finger.Population.upper_push validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitions, Structures.PopTart.Chocolate.Top.Definitionstheorem lower_pop {p : Pair} (valid : p.Valid) : (p.lower.popCost : ℝ) ≤ 6 + 10 * Real.logb 2 p.tree.size := RotationBST.HeavyPath.Finger.Population.lower_pop validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitions, Structures.PopTart.Chocolate.Top.Definitionstheorem upper_pop {p : Pair} (valid : p.Valid) : (p.upper.popCost : ℝ) ≤ 6 + 10 * Real.logb 2 p.tree.size := RotationBST.HeavyPath.Finger.Population.upper_pop validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitions, Structures.PopTart.Chocolate.Top.DefinitionsIn a valid pair, the rebalancing cost of a push onto either stack (Layer.pushCost) is at most , and that of a pop (Layer.popCost) at most . These are the bounds of Section 37.2 with the slot count replaced by .
theorem lower_payload_size {p : Pair} {shape : Tree} {charge : ℝ} (stored : p.lower.top = .leaf shape.mirror charge) : shape.size ≤ p.tree.size := RotationBST.HeavyPath.Finger.Population.lower_payload_size storedModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitions, Structures.PopTart.Chocolate.Top.Definitionstheorem upper_payload_size {p : Pair} {shape : Tree} {charge : ℝ} (stored : p.upper.top = .leaf shape charge) : shape.size ≤ p.tree.size := RotationBST.HeavyPath.Finger.Population.upper_payload_size storedModels.Rotation, Models.Pointer.Machine, Models.Pointer.Mirror.Definitions, Models.Pointer.Lazy.Skeleton, Models.Labelled.Cursor.Definitions, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Definitions, Structures.HeavyPath.Paired.Definitions, Structures.HeavyPath.Paired.Substitution.Definitions, Structures.HeavyPath.Paired.Exposure.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitions, Structures.PopTart.Chocolate.Top.DefinitionsThe top payload of either stack (Layer.top), a single slot holding a subtree shape, has at most nodes. Exposures inside that payload are bounded in terms of its size, so these lemmas express their worst-case costs in terms of too.
38.3.6 Moving the finger down
38.3.6.1 The transfer
def potential (p : Pair) : Nat := p.lower.potential + p.upper.potential/-- The left source child is already exposed as the root of the innermostpayload. Its left child stays below; its right child enters the other stack. -/noncomputable def downLeft (p : Pair) (a b : Tree) (lowerCharge upperCharge : ℝ) : Pair := ⟨p.lower.replaceTop (.leaf a.mirror lowerCharge), p.upper.push (.leaf b upperCharge)⟩def leftExposeCost (p : Pair) : Nat := match p.lower.topTail with | none => 2 | some _ => 4noncomputable def downLeftCost (p : Pair) : Nat := p.leftExposeCost + p.upper.pushCost + 2The potential of a pair is the sum of the Chocolate potentials of its stacks (Layer.potential). p.downLeft a b lowerCharge upperCharge is the pair after the finger moves to its left child, assuming that child is the root of the top lower payload, with subtrees a and b. The lower stack keeps its structure. Layer.replaceTop swaps its top payload for a, mirrored, with a new charge. The upper stack receives b by a real push, and the old finger becomes the separator of that push. The new charges are parameters, so the caller decides how the two moving weights are booked. The _source and history lemmas below fix them.
The cost has three parts. Reaching the new finger and rotating it to the root costs instructions if the lower stack’s top layer has no separator above the top payload (Layer.topTail is none), and if one separator stands between: two descents and two rotations. Then the upper push costs its Chocolate rebalancing cost plus for entering the stack and returning.
def flip (p : Pair) : Pair := ⟨p.upper, p.lower⟩/-- The reflected transfer uses the same physical operation in the oppositeorientation. The old finger node supplies the pushed separator. -/noncomputable def downRight (p : Pair) (a b : Tree) (lowerCharge upperCharge : ℝ) : Pair := (p.flip.downLeft b.mirror a.mirror upperCharge lowerCharge).flipnoncomputable def downRightCost (p : Pair) : Nat := p.flip.downLeftCostflip swaps the stacks, which mirrors the whole tree. The move to the right child is defined as the move to the left child in the flipped pair, with the subtrees mirrored and the charges swapped, flipped back. Its cost is defined in the same way. Every downRight lemma is the corresponding downLeft lemma transported through flip, using the three facts below.
theorem flip_tree (p : Pair) : p.flip.tree = p.tree.mirror := RotationBST.HeavyPath.Finger.flip_tree pModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem flip_mass (p : Pair) : p.flip.mass = p.mass := RotationBST.HeavyPath.Finger.flip_mass pModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem flip_potential (p : Pair) : p.flip.potential = p.potential := RotationBST.HeavyPath.Finger.flip_potential pModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitions38.3.6.2 Local guarantees
Theorem (transfer). Suppose the top payload of the lower stack is the subtree node a b, mirrored, with some charge. Then the move costs exactly downLeftCost pointer instructions, root to root. Validity is preserved for nonnegative new charges. The amortized cost, actual cost plus potential change, is at most . The mass changes by exactly the new charges minus the old one. The new root has the rank of the old top payload’s root. The right-hand move is symmetric.
theorem downLeft_trace {p : Pair} {a b : Tree} {oldCharge : ℝ} (exposed : p.lower.top = .leaf (Tree.node a b).mirror oldCharge) (lowerCharge upperCharge : ℝ) : Pointer.Trace ⟨p.tree, []⟩ ⟨(p.downLeft a b lowerCharge upperCharge).tree, []⟩ p.downLeftCost := RotationBST.HeavyPath.Finger.downLeft_trace exposed lowerCharge upperChargeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downLeft_valid {p : Pair} (valid : p.Valid) (a b : Tree) {lowerCharge upperCharge : ℝ} (lowerNonnegative : 0 ≤ lowerCharge) (upperNonnegative : 0 ≤ upperCharge) : (p.downLeft a b lowerCharge upperCharge).Valid := RotationBST.HeavyPath.Finger.downLeft_valid valid a b lowerNonnegative upperNonnegativeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downLeft_amortized {p : Pair} (valid : p.Valid) (a b : Tree) (lowerCharge : ℝ) {upperCharge : ℝ} (upperNonnegative : 0 ≤ upperCharge) : p.downLeftCost + (p.downLeft a b lowerCharge upperCharge).potential ≤ 26 + p.potential := RotationBST.HeavyPath.Finger.downLeft_amortized valid a b lowerCharge upperNonnegativeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downLeft_mass {p : Pair} (valid : p.Valid) {a b : Tree} {oldCharge : ℝ} (exposed : p.lower.top = .leaf (Tree.node a b).mirror oldCharge) (lowerCharge : ℝ) {upperCharge : ℝ} (upperNonnegative : 0 ≤ upperCharge) : (p.downLeft a b lowerCharge upperCharge).mass + oldCharge = p.mass + lowerCharge + upperCharge := RotationBST.HeavyPath.Finger.downLeft_mass valid exposed lowerCharge upperNonnegativeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downLeft_root_key {p : Pair} {a b : Tree} {oldCharge : ℝ} (exposed : p.lower.top = .leaf (Tree.node a b).mirror oldCharge) (lowerCharge upperCharge : ℝ) : (Pointer.Config.mk (p.downLeft a b lowerCharge upperCharge).tree []).key? = some (p.lower.decode.tree.mirror.size - b.size - 1) := RotationBST.HeavyPath.Finger.downLeft_root_key exposed lowerCharge upperChargeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downLeft_fringe {p : Pair} (valid : p.Valid) {a b : Tree} {oldCharge : ℝ} (exposed : p.lower.top = .leaf (Tree.node a b).mirror oldCharge) (lowerCharge : ℝ) {upperCharge : ℝ} (upperNonnegative : 0 ≤ upperCharge) : ∃ before, p.lower.decode.mirror.fringe = before ++ [(.node a b, oldCharge)] ∧ (p.downLeft a b lowerCharge upperCharge).lower.decode.mirror.fringe = before ++ [(a, lowerCharge)] ∧ (p.downLeft a b lowerCharge upperCharge).upper.decode.fringe = (b, upperCharge) :: p.upper.decode.fringe := RotationBST.HeavyPath.Finger.downLeft_fringe valid exposed lowerCharge upperNonnegativeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.DefinitionsThe trace, the mass equation, the root key and the fringe need the exposure hypothesis exposed. Validity and the amortized inequality are about the defined result and its defined cost, so they hold without it. downLeft_fringe describes the move on the fringes. The last lower slot (node a b, oldCharge) becomes (a, lowerCharge), and (b, upperCharge) becomes the first upper slot. All other slots are unchanged.
theorem downRight_trace {p : Pair} {a b : Tree} {oldCharge : ℝ} (exposed : p.upper.top = .leaf (.node a b) oldCharge) (lowerCharge upperCharge : ℝ) : Pointer.Trace ⟨p.tree, []⟩ ⟨(p.downRight a b lowerCharge upperCharge).tree, []⟩ p.downRightCost := RotationBST.HeavyPath.Finger.downRight_trace exposed lowerCharge upperChargeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_valid {p : Pair} (valid : p.Valid) (a b : Tree) {lowerCharge upperCharge : ℝ} (lowerNonnegative : 0 ≤ lowerCharge) (upperNonnegative : 0 ≤ upperCharge) : (p.downRight a b lowerCharge upperCharge).Valid := RotationBST.HeavyPath.Finger.downRight_valid valid a b lowerNonnegative upperNonnegativeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_amortized {p : Pair} (valid : p.Valid) (a b : Tree) {lowerCharge : ℝ} (upperCharge : ℝ) (lowerNonnegative : 0 ≤ lowerCharge) : p.downRightCost + (p.downRight a b lowerCharge upperCharge).potential ≤ 26 + p.potential := RotationBST.HeavyPath.Finger.downRight_amortized valid a b upperCharge lowerNonnegativeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_mass {p : Pair} (valid : p.Valid) {a b : Tree} {oldCharge : ℝ} (exposed : p.upper.top = .leaf (.node a b) oldCharge) {lowerCharge : ℝ} (upperCharge : ℝ) (lowerNonnegative : 0 ≤ lowerCharge) : (p.downRight a b lowerCharge upperCharge).mass + oldCharge = p.mass + lowerCharge + upperCharge := RotationBST.HeavyPath.Finger.downRight_mass valid exposed upperCharge lowerNonnegativeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_root_key (p : Pair) (a b : Tree) (lowerCharge upperCharge : ℝ) : (Pointer.Config.mk (p.downRight a b lowerCharge upperCharge).tree []).key? = some (p.lower.decode.tree.mirror.size + a.size + 1) := RotationBST.HeavyPath.Finger.downRight_root_key p a b lowerCharge upperChargeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_fringe {p : Pair} (valid : p.Valid) {a b : Tree} {oldCharge : ℝ} (exposed : p.upper.top = .leaf (.node a b) oldCharge) {lowerCharge : ℝ} (upperCharge : ℝ) (lowerNonnegative : 0 ≤ lowerCharge) : ∃ after, p.upper.decode.fringe = (.node a b, oldCharge) :: after ∧ (p.downRight a b lowerCharge upperCharge).upper.decode.fringe = (b, upperCharge) :: after ∧ (p.downRight a b lowerCharge upperCharge).lower.decode.mirror.fringe = p.lower.decode.mirror.fringe ++ [(a, lowerCharge)] := RotationBST.HeavyPath.Finger.downRight_fringe valid exposed upperCharge lowerNonnegativeModels.Rotation, Models.Pointer.Machine, Models.Pointer.Lazy.Skeleton, Structures.PopTart.Definitions, Structures.PopTart.Chocolate.Definitions, Structures.PopTart.Chocolate.Top.Definitions, Models.Pointer.Mirror.Definitions, Structures.PopTart.Mirror.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.DefinitionsThe mirror images. Here a is pushed onto the lower stack, so the new root’s rank is the old lower size plus a.size + 1 whatever the top payload was. downRight_root_key has no exposure hypothesis, unlike its left counterpart, whose rank depends on the size of the replaced payload.
38.3.6.3 Exposing the new finger
In a real pair the new finger is usually not at the physical root of its payload. A payload holds a recursive heavy-path representation, whose physical root is the endpoint of the subtree’s heavy path, while the subtree’s source root is near the top of one of its stacks. Before the transfer, the payload must be restructured to bring its source root to the top. That is an exposure, Exposure.View of Section 38.2. The lemmas below compose an exposure with the transfer. The cost counted includes every descent into the payload and every return, through the separator that may stand between the finger and its top slot.
theorem downLeft_exposed {p : Pair} (valid : p.Valid) {old a b : Tree} {oldCharge : ℝ} (stored : p.lower.top = .leaf old.mirror oldCharge) {exposureCost : Nat} (exposure : Pointer.Trace ⟨old, []⟩ ⟨.node a b, []⟩ exposureCost) {lowerCharge upperCharge : ℝ} (lowerNonnegative : 0 ≤ lowerCharge) (upperNonnegative : 0 ≤ upperCharge) : ∃ cost, Pointer.Trace ⟨p.tree, []⟩ ⟨(p.downLeft a b lowerCharge upperCharge).tree, []⟩ cost ∧ cost + (p.downLeft a b lowerCharge upperCharge).potential ≤ exposureCost + 30 + p.potential ∧ (p.downLeft a b lowerCharge upperCharge).Valid ∧ (p.downLeft a b lowerCharge upperCharge).mass + oldCharge = p.mass + lowerCharge + upperCharge ∧ (Pointer.Config.mk (p.downLeft a b lowerCharge upperCharge).tree []).key? = some (p.lower.decode.tree.mirror.size - b.size - 1) := RotationBST.HeavyPath.Finger.Transfer.Exposure.downLeft_exposed valid stored exposure lowerNonnegative upperNonnegativeModels.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.PopTart.Chocolate.Top.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.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_exposed {p : Pair} (valid : p.Valid) {old a b : Tree} {oldCharge : ℝ} (stored : p.upper.top = .leaf old oldCharge) {exposureCost : Nat} (exposure : Pointer.Trace ⟨old, []⟩ ⟨.node a b, []⟩ exposureCost) {lowerCharge upperCharge : ℝ} (lowerNonnegative : 0 ≤ lowerCharge) (upperNonnegative : 0 ≤ upperCharge) : ∃ cost, Pointer.Trace ⟨p.tree, []⟩ ⟨(p.downRight a b lowerCharge upperCharge).tree, []⟩ cost ∧ cost + (p.downRight a b lowerCharge upperCharge).potential ≤ exposureCost + 30 + p.potential ∧ (p.downRight a b lowerCharge upperCharge).Valid ∧ (p.downRight a b lowerCharge upperCharge).mass + oldCharge = p.mass + lowerCharge + upperCharge ∧ (Pointer.Config.mk (p.downRight a b lowerCharge upperCharge).tree []).key? = some (p.lower.decode.tree.mirror.size + a.size + 1) := RotationBST.HeavyPath.Finger.Transfer.Exposure.downRight_exposed valid stored exposure lowerNonnegative upperNonnegativeModels.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.PopTart.Chocolate.Top.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.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downLeft_exposed_bounded {p : Pair} (valid : p.Valid) {old a b : Tree} {oldCharge : ℝ} (stored : p.lower.top = .leaf old.mirror oldCharge) {exposureCost : Nat} (exposure : Pointer.Trace ⟨old, []⟩ ⟨.node a b, []⟩ exposureCost) {lowerCharge upperCharge : ℝ} (lowerNonnegative : 0 ≤ lowerCharge) (upperNonnegative : 0 ≤ upperCharge) : ∃ cost, Pointer.Trace ⟨p.tree, []⟩ ⟨(p.downLeft a b lowerCharge upperCharge).tree, []⟩ cost ∧ cost + (p.downLeft a b lowerCharge upperCharge).potential ≤ exposureCost + 30 + p.potential ∧ (p.downLeft a b lowerCharge upperCharge).Valid ∧ (p.downLeft a b lowerCharge upperCharge).mass + oldCharge = p.mass + lowerCharge + upperCharge ∧ (Pointer.Config.mk (p.downLeft a b lowerCharge upperCharge).tree []).key? = some (p.lower.decode.tree.mirror.size - b.size - 1) ∧ cost ≤ exposureCost + p.upper.pushCost + 10 := RotationBST.HeavyPath.Finger.Transfer.Exposure.downLeft_exposed_bounded valid stored exposure lowerNonnegative upperNonnegativeModels.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.PopTart.Chocolate.Top.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.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_exposed_bounded {p : Pair} (valid : p.Valid) {old a b : Tree} {oldCharge : ℝ} (stored : p.upper.top = .leaf old oldCharge) {exposureCost : Nat} (exposure : Pointer.Trace ⟨old, []⟩ ⟨.node a b, []⟩ exposureCost) {lowerCharge upperCharge : ℝ} (lowerNonnegative : 0 ≤ lowerCharge) (upperNonnegative : 0 ≤ upperCharge) : ∃ cost, Pointer.Trace ⟨p.tree, []⟩ ⟨(p.downRight a b lowerCharge upperCharge).tree, []⟩ cost ∧ cost + (p.downRight a b lowerCharge upperCharge).potential ≤ exposureCost + 30 + p.potential ∧ (p.downRight a b lowerCharge upperCharge).Valid ∧ (p.downRight a b lowerCharge upperCharge).mass + oldCharge = p.mass + lowerCharge + upperCharge ∧ (Pointer.Config.mk (p.downRight a b lowerCharge upperCharge).tree []).key? = some (p.lower.decode.tree.mirror.size + a.size + 1) ∧ cost ≤ exposureCost + p.lower.pushCost + 10 := RotationBST.HeavyPath.Finger.Transfer.Exposure.downRight_exposed_bounded valid stored exposure lowerNonnegative upperNonnegativeModels.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.PopTart.Chocolate.Top.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.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.DefinitionsThese are generic. If some pointer trace of cost turns the top payload old into node a b, root to root, then some trace performs the whole move, with amortized cost at most , the validity, mass and root-key conclusions as before, and, in the _bounded forms, actual cost at most plus the receiving stack’s push cost plus .
theorem downLeft_pair {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} {child : Paired.Stacks} (valid : p.Valid) (positive : Positive weight (.node l x r)) (represented : child.Represents weight (rebuild weight) (extract weight (.node l x r)).context) {oldCharge : ℝ} (stored : p.lower.top = .leaf child.tree.mirror oldCharge) {lowerCharge upperCharge : ℝ} (lowerNonnegative : 0 ≤ lowerCharge) (upperNonnegative : 0 ≤ upperCharge) : ∃ (view : Recursive.Exposure.View) (cost : Nat), view.Valid weight l r ∧ let next := p.downLeft (view.leftTree weight l) (view.rightTree weight r) lowerCharge upperCharge Pointer.Trace ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + view.potential ≤ 54 + p.potential + child.potential ∧ next.mass + oldCharge = p.mass + lowerCharge + upperCharge ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size - r.erase.size - 1) := RotationBST.HeavyPath.Finger.Transfer.Exposure.downLeft_pair valid positive represented stored lowerNonnegative upperNonnegativeModels.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.PopTart.Chocolate.Top.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.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_pair {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} {child : Paired.Stacks} (valid : p.Valid) (positive : Positive weight (.node l x r)) (represented : child.Represents weight (rebuild weight) (extract weight (.node l x r)).context) {oldCharge : ℝ} (stored : p.upper.top = .leaf child.tree oldCharge) {lowerCharge upperCharge : ℝ} (lowerNonnegative : 0 ≤ lowerCharge) (upperNonnegative : 0 ≤ upperCharge) : ∃ (view : Recursive.Exposure.View) (cost : Nat), view.Valid weight l r ∧ let next := p.downRight (view.leftTree weight l) (view.rightTree weight r) lowerCharge upperCharge Pointer.Trace ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + view.potential ≤ 54 + p.potential + child.potential ∧ next.mass + oldCharge = p.mass + lowerCharge + upperCharge ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size + l.erase.size + 1) := RotationBST.HeavyPath.Finger.Transfer.Exposure.downRight_pair valid positive represented stored lowerNonnegative upperNonnegativeModels.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.PopTart.Chocolate.Top.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.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downLeft_recursive {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} (valid : p.Valid) (positive : Positive weight (.node l x r)) {oldCharge : ℝ} (stored : p.lower.top = .leaf (rebuild weight (.node l x r)).mirror oldCharge) {lowerCharge upperCharge : ℝ} (lowerNonnegative : 0 ≤ lowerCharge) (upperNonnegative : 0 ≤ upperCharge) : ∃ (view : Recursive.Exposure.View) (cost : Nat), view.Valid weight l r ∧ let next := p.downLeft (view.leftTree weight l) (view.rightTree weight r) lowerCharge upperCharge Pointer.Trace ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + view.potential ≤ 54 + p.potential + (rootPair weight (.node l x r)).potential ∧ next.mass + oldCharge = p.mass + lowerCharge + upperCharge ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size - r.erase.size - 1) := RotationBST.HeavyPath.Finger.Transfer.Exposure.downLeft_recursive valid positive stored lowerNonnegative upperNonnegativeModels.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.PopTart.Chocolate.Top.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.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_recursive {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} (valid : p.Valid) (positive : Positive weight (.node l x r)) {oldCharge : ℝ} (stored : p.upper.top = .leaf (rebuild weight (.node l x r)) oldCharge) {lowerCharge upperCharge : ℝ} (lowerNonnegative : 0 ≤ lowerCharge) (upperNonnegative : 0 ≤ upperCharge) : ∃ (view : Recursive.Exposure.View) (cost : Nat), view.Valid weight l r ∧ let next := p.downRight (view.leftTree weight l) (view.rightTree weight r) lowerCharge upperCharge Pointer.Trace ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + view.potential ≤ 54 + p.potential + (rootPair weight (.node l x r)).potential ∧ next.mass + oldCharge = p.mass + lowerCharge + upperCharge ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size + l.erase.size + 1) := RotationBST.HeavyPath.Finger.Transfer.Exposure.downRight_recursive valid positive stored lowerNonnegative upperNonnegativeModels.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.PopTart.Chocolate.Top.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.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.DefinitionsThese specialize the exposure to recursive payloads. Let the top payload be the tree of a heavy-path pair child (Paired.Stacks) that represents the heavy path of the source subtree node l x r, in the sense of Stacks.Represents. Then there is an exposure view, valid for l and r (View.Valid). The view keeps the residual heavy path of the heavy child as an actual pair, with its own potential, and the light child in its rebuilt layout. The move to x with a and b taken from the view (View.leftTree and rightTree) satisfies
The child pair’s potential pays for its exposure, and the residual pair’s potential is handed on to the view. The _pair forms allow child to be any valid representation, including one left behind by earlier exposures. The _recursive forms take the canonical rebuilt payload, whose pair is Recursive.rootPair.
theorem downLeft_source {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} (valid : p.Valid) (positive : Positive weight (.node l x r)) {carry fingerWeight : ℝ} (carryNonnegative : 0 ≤ carry) (fingerNonnegative : 0 ≤ fingerWeight) (stored : p.lower.top = .leaf (rebuild weight (.node l x r)).mirror (carry + mass weight (.node l x r))) : ∃ (view : Recursive.Exposure.View) (cost : Nat), view.Valid weight l r ∧ let next := p.downLeft (view.leftTree weight l) (view.rightTree weight r) (carry + mass weight l) (fingerWeight + mass weight r) Pointer.Trace ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + view.potential ≤ 54 + p.potential + (rootPair weight (.node l x r)).potential ∧ next.mass + weight x = p.mass + fingerWeight ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size - r.erase.size - 1) := RotationBST.HeavyPath.Finger.Transfer.Exposure.downLeft_source valid positive carryNonnegative fingerNonnegative storedModels.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.PopTart.Chocolate.Top.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.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_source {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} (valid : p.Valid) (positive : Positive weight (.node l x r)) {carry fingerWeight : ℝ} (carryNonnegative : 0 ≤ carry) (fingerNonnegative : 0 ≤ fingerWeight) (stored : p.upper.top = .leaf (rebuild weight (.node l x r)) (carry + mass weight (.node l x r))) : ∃ (view : Recursive.Exposure.View) (cost : Nat), view.Valid weight l r ∧ let next := p.downRight (view.leftTree weight l) (view.rightTree weight r) (fingerWeight + mass weight l) (carry + mass weight r) Pointer.Trace ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + view.potential ≤ 54 + p.potential + (rootPair weight (.node l x r)).potential ∧ next.mass + weight x = p.mass + fingerWeight ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size + l.erase.size + 1) := RotationBST.HeavyPath.Finger.Transfer.Exposure.downRight_source valid positive carryNonnegative fingerNonnegative storedModels.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.PopTart.Chocolate.Top.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.Definitions, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.DefinitionsThe _source forms fix the charges to keep the charging rule. Suppose the top payload of node l x r is charged carry plus its mass, where carry is the weight of the separator before it. After the move, the slot of l, which stays on the same side, is charged carry plus the mass of l. The slot of r, now on the other side behind the old finger, is charged the old finger’s weight plus the mass of r. Then the new finger’s weight plus the new mass equals the old mass plus the old finger’s weight. So the invariant of build_mass, finger weight plus pair mass equals , is preserved.
38.3.6.4 With arbitrary histories
After a few moves, the payloads are no longer canonical. A payload may hold a residual path, a pair rebuilt by pops, or a subtree whose stacks have any valid history. History.Layout of Section 38.2 describes all of these, together with a repair credit, the potential of the pairs it contains. The final transfer lemmas are stated for such layouts, and these are the ones that Section 38.4 uses.
theorem downLeft {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} (valid : p.Valid) {shape : Tree} {childCredit : Nat} (child : Recursive.History.Layout weight (.node l x r) shape childCredit) {carry fingerWeight : ℝ} (carryNonnegative : 0 ≤ carry) (fingerNonnegative : 0 ≤ fingerWeight) (stored : p.lower.top = .leaf shape.mirror (carry + mass weight (.node l x r))) : ∃ (a b : Tree) (leftCredit rightCredit cost : Nat), Recursive.History.Layout weight l a leftCredit ∧ Recursive.History.Layout weight r b rightCredit ∧ let next := p.downLeft a b (carry + mass weight l) (fingerWeight + mass weight r) Pointer.Trace ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + leftCredit + rightCredit ≤ 54 + p.potential + childCredit ∧ next.mass + weight x = p.mass + fingerWeight ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size - r.erase.size - 1) := RotationBST.HeavyPath.Finger.Transfer.History.downLeft valid child carryNonnegative fingerNonnegative storedModels.Rotation, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitions, 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.PopTart.Chocolate.Top.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, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} (valid : p.Valid) {shape : Tree} {childCredit : Nat} (child : Recursive.History.Layout weight (.node l x r) shape childCredit) {carry fingerWeight : ℝ} (carryNonnegative : 0 ≤ carry) (fingerNonnegative : 0 ≤ fingerWeight) (stored : p.upper.top = .leaf shape (carry + mass weight (.node l x r))) : ∃ (a b : Tree) (leftCredit rightCredit cost : Nat), Recursive.History.Layout weight l a leftCredit ∧ Recursive.History.Layout weight r b rightCredit ∧ let next := p.downRight a b (fingerWeight + mass weight l) (carry + mass weight r) Pointer.Trace ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + leftCredit + rightCredit ≤ 54 + p.potential + childCredit ∧ next.mass + weight x = p.mass + fingerWeight ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size + l.erase.size + 1) := RotationBST.HeavyPath.Finger.Transfer.History.downRight valid child carryNonnegative fingerNonnegative storedModels.Rotation, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitions, 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.PopTart.Chocolate.Top.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, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.DefinitionsTheorem (downward move). Suppose the top lower payload is a layout of the source subtree node l x r with credit , charged carry plus its mass. Then there are layouts of l and r, with credits and , such that the move with the charges of the _source forms is a root-to-root trace of some cost, keeps the pair valid, preserves the mass invariant, puts the right rank at the root, and satisfies
The symmetric statement holds for the right child.
theorem downLeft_bounded {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} (valid : p.Valid) {shape : Tree} {childCredit : Nat} (child : Recursive.History.Layout weight (.node l x r) shape childCredit) {carry fingerWeight : ℝ} (carryNonnegative : 0 ≤ carry) (fingerNonnegative : 0 ≤ fingerWeight) (stored : p.lower.top = .leaf shape.mirror (carry + mass weight (.node l x r))) : ∃ (a b : Tree) (leftCredit rightCredit cost : Nat), Recursive.History.Layout weight l a leftCredit ∧ Recursive.History.Layout weight r b rightCredit ∧ let next := p.downLeft a b (carry + mass weight l) (fingerWeight + mass weight r) Pointer.Trace ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + leftCredit + rightCredit ≤ 54 + p.potential + childCredit ∧ next.mass + weight x = p.mass + fingerWeight ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size - r.erase.size - 1) ∧ (cost : ℝ) ≤ 26 + 24 * Real.logb 2 p.tree.size := RotationBST.HeavyPath.Finger.Transfer.History.downLeft_bounded valid child carryNonnegative fingerNonnegative storedModels.Rotation, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitions, 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.PopTart.Chocolate.Top.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, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_bounded {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} (valid : p.Valid) {shape : Tree} {childCredit : Nat} (child : Recursive.History.Layout weight (.node l x r) shape childCredit) {carry fingerWeight : ℝ} (carryNonnegative : 0 ≤ carry) (fingerNonnegative : 0 ≤ fingerWeight) (stored : p.upper.top = .leaf shape (carry + mass weight (.node l x r))) : ∃ (a b : Tree) (leftCredit rightCredit cost : Nat), Recursive.History.Layout weight l a leftCredit ∧ Recursive.History.Layout weight r b rightCredit ∧ let next := p.downRight a b (fingerWeight + mass weight l) (carry + mass weight r) Pointer.Trace ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + leftCredit + rightCredit ≤ 54 + p.potential + childCredit ∧ next.mass + weight x = p.mass + fingerWeight ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size + l.erase.size + 1) ∧ (cost : ℝ) ≤ 26 + 24 * Real.logb 2 p.tree.size := RotationBST.HeavyPath.Finger.Transfer.History.downRight_bounded valid child carryNonnegative fingerNonnegative storedModels.Rotation, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitions, 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.PopTart.Chocolate.Top.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, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.DefinitionsThe _bounded forms add the worst case: the actual cost is at most . It combines the worst-case cost of the exposure inside the payload, which Section 38.2 bounds by the logarithm of the payload’s size, the push onto the receiving stack, and a constant number of moves. The population bounds above turn both logarithms into .
theorem downLeft_within {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} (valid : p.Valid) {shape : Tree} {childCredit : Nat} (child : Recursive.History.Layout weight (.node l x r) shape childCredit) {carry fingerWeight : ℝ} (carryNonnegative : 0 ≤ carry) (fingerNonnegative : 0 ≤ fingerWeight) (stored : p.lower.top = .leaf shape.mirror (carry + mass weight (.node l x r))) : ∃ (a b : Tree) (leftCredit rightCredit cost : Nat), Recursive.History.Layout weight l a leftCredit ∧ Recursive.History.Layout weight r b rightCredit ∧ let next := p.downLeft a b (carry + mass weight l) (fingerWeight + mass weight r) Pointer.TraceWithin (fun t => t.size = p.tree.size ∧ ∀ x, Tree.depth t x ≤ 16 * Tree.depth p.tree x + 64) ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + leftCredit + rightCredit ≤ 54 + p.potential + childCredit ∧ next.mass + weight x = p.mass + fingerWeight ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size - r.erase.size - 1) ∧ (cost : ℝ) ≤ 26 + 24 * Real.logb 2 p.tree.size := RotationBST.HeavyPath.Finger.Transfer.History.downLeft_within valid child carryNonnegative fingerNonnegative storedModels.Rotation, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitions, 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.PopTart.Chocolate.Top.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, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.Definitionstheorem downRight_within {α : Type} {weight : α → ℝ} {l r : LabelledTree α} {x : α} {p : Pair} (valid : p.Valid) {shape : Tree} {childCredit : Nat} (child : Recursive.History.Layout weight (.node l x r) shape childCredit) {carry fingerWeight : ℝ} (carryNonnegative : 0 ≤ carry) (fingerNonnegative : 0 ≤ fingerWeight) (stored : p.upper.top = .leaf shape (carry + mass weight (.node l x r))) : ∃ (a b : Tree) (leftCredit rightCredit cost : Nat), Recursive.History.Layout weight l a leftCredit ∧ Recursive.History.Layout weight r b rightCredit ∧ let next := p.downRight a b (fingerWeight + mass weight l) (carry + mass weight r) Pointer.TraceWithin (fun t => t.size = p.tree.size ∧ ∀ x, Tree.depth t x ≤ 16 * Tree.depth p.tree x + 64) ⟨p.tree, []⟩ ⟨next.tree, []⟩ cost ∧ next.Valid ∧ cost + next.potential + leftCredit + rightCredit ≤ 54 + p.potential + childCredit ∧ next.mass + weight x = p.mass + fingerWeight ∧ (Pointer.Config.mk next.tree []).key? = some (p.lower.decode.tree.mirror.size + l.erase.size + 1) ∧ (cost : ℝ) ≤ 26 + 24 * Real.logb 2 p.tree.size := RotationBST.HeavyPath.Finger.Transfer.History.downRight_within valid child carryNonnegative fingerNonnegative storedModels.Rotation, Bounds.StaticTree.Definitions, Models.Pointer.Invariant.Definitions, 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.PopTart.Chocolate.Top.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, Structures.HeavyPath.Finger.Definitions, Structures.HeavyPath.Finger.Transfer.DefinitionsThe _within forms strengthen the trace to a Pointer.TraceWithin: at every instruction boundary of the move, the intermediate tree has nodes, and every rank’s depth is at most times its depth in the starting tree plus . The deamortization may interrupt the simulation in the middle of a source operation to serve a request. It then needs a depth bound for the tree as it stands, and this invariant provides it. The bound is relative: it combines with the logarithmic depth of the starting pair, which Section 38.4 maintains, to give a logarithmic bound for every intermediate tree.
38.3.7 What is not here
The upward moves and the two rotations of the source finger are proved in Section 38.4, on the full finger state. An upward move pops the separator next to the finger from one stack and joins it, with the finger’s child, into a payload on the other side. A rotation exchanges a constant number of slots. The local pair-level lemmas behind them live in the proof files Transfer/Up, Transfer/Rotation and Transfer/Interruption and are not part of the reading interface. The paper’s remark that bits per node suffice to store the roles of the nodes belongs to Theorem 7’s storage clauses. The library does not formalize it.