Chapter 39 · Saving trees in their nodes · Section 39.1Tree buffers
ComboBST (Section 29.1) runs two online BST algorithms on one physical tree, in alternating rounds. Every round starts from the same initial tree , so at the end of a round the structure must turn whatever tree the interrupted worker left behind back into . It has no memory outside the tree beyond a constant number of registers. Where does it keep the description of ? Demaine, Iacono, Langerman and Özkan (2013, Section 3) answer: in the nodes themselves. Each node may carry bits of augmented data, so the nodes together form a buffer of cells. Their Definition 8 stores the -th cell in the -th node in inorder, and a buffer finger walks from cell to cell by inorder traversal.
The difficulty is that the tree changes shape while the buffer is in use. When the tree state is loaded, a second finger rotates the tree while the buffer finger reads the saved instructions, and every rotation can lengthen the buffer finger’s route. Their Lemma 9 says this costs little: an inorder traversal interleaved with rotations by other fingers takes time. Lemma 10 then makes saving and loading the tree state cost , because a linear-time normalization performs only rotations.
This section formalizes the buffer: the scan and its cost, the cells and their reads and writes, the node records that hold keys, routing bounds and cells, and a shared tree in which several persistent fingers act on the same nodes. The snapshot, the saved instruction log packed into the cells, is the subject of Section 39.2.
Let be a tree with nodes, whose keys are the inorder ranks . A scan finger sits on any node, and the cells still to visit are either a suffix in increasing order or a prefix in decreasing order. A scan step either moves the finger one edge along a shortest path, in the current tree, toward the next pending cell, or visits that cell once the finger is on it. Both cost one unit. Arbitrary rotations of the tree, performed by someone else, may be interleaved between any two scan steps. If a trace contains such rotations, the scan’s work is
and the total including the rotations is at most . Any such partial trace can be completed, with no further rotations, so that every pending cell is visited and the whole scan still costs at most .
This is the paper’s Lemma 9, with explicit constants. The bound holds for any start position of the finger and any boundary , in either direction.
The Lean statements
/-- Linear traversal accounting from Lemma 9 of arXiv:1304.7604. Rotations caninterrupt the route between two cells. Counts include the scan's node visits.The operational rule follows a shortest route toward each pending cell. -/theorem cost {s t : State} {work rotations : Nat} (trace : Trace s t work rotations) (valid : s.Valid) : work ≤ 4 * s.tree.size + 3 * rotations := … trace.cost validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.Definitions/-- Include the cost of the external rotations themselves. -/theorem total {s t : State} {work rotations : Nat} (trace : Trace s t work rotations) (valid : s.Valid) : work + rotations ≤ 4 * s.tree.size + 4 * rotations := … trace.total_cost validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.Definitions/-- Every finite interleaved prefix can be completed within the same bound. -/theorem completion {s t : State} {work rotations : Nat} (trace : Trace s t work rotations) (valid : s.Valid) : ∃ u extra, Trace s u (work + extra) rotations ∧ u.requests = [] ∧ work + extra ≤ 4 * s.tree.size + 3 * rotations := … complete_after trace validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.Definitions39.1.1 Overview
39.1.1.1 Do you need this section?
The statements of the ComboBST results, Section 29.1 to Section 29.4, and of the combined finger theorem in Chapter 31 are about pointer-machine executions of the hand tree (Section 35.2). They do not mention cells or scans. The prepared policy (Online.Prepared) does carry a proof that its startup is a legal shared-node execution (Startup.Execution), and its state (Online.State) carries a shared tree. So the definitions of the node and shared layers, in Section 39.1.4 and Section 39.1.5, are on the reading paths of those headline results, together with the event type Cells.Event. A reader who only wants to confirm those results needs just one fact from here: a shared-node trace is made of legal pointer moves, cell reads and writes, and rotations maintained by a fixed local program, each with a fixed charge. The scan and cell layers are proof machinery. Read them to see why restoring the initial tree costs .
39.1.1.2 Four layers
The library builds the buffer in four layers, from the most abstract to the most concrete. All live in Structures/TreeBuffer.
| Layer | State | What a step costs | Main theorem |
|---|---|---|---|
Scan (Scan) |
tree, finger key, boundary, direction | move or visit: 1; rotation: counted apart | cost: |
Cells (Cells) |
scan state and one payload per key | navigate, read or write: 1 | write_completed, read_completed |
Nodes (Nodes) |
one labelled node: key, interval bounds, cell | route: 4; cell read or write: 1; maintained rotation: 15 | used by the shared layer |
Shared (Shared) |
one labelled tree and persistent fingers | as for nodes, plus a bare move: 1 | used by Results.worker_step and the snapshot |
The scan is a model of Lemma 9 and nothing else: it only knows which key the finger is on and which cells remain. The cell layer adds the data. The node layer says how that data, together with the routing information the finger needs to find its way, is laid out in actual node records. The shared layer puts several fingers on the same records: ComboBST uses two fingers, finger 0 for the worker or the replay and finger 1 for the buffer scan (Refinement.Represents, Refinement.Represents).
Cells are attached to keys, which are inorder ranks. A rotation preserves the inorder, so it moves every cell along with its node and never changes which cell is the -th. This is the paper’s design, and it is what makes rotations by other fingers harmless to the data. They only lengthen the routes.
39.1.1.3 Where it is used
- Section 39.2 saves a tree by normalizing it to a right path, writing the opcode log into the cells with a forward scan, and undoing the normalization (
Results.save, at most ). It loads a saved tree by normalizing the current tree and replaying the inverse log while a reverse scan reads the cells. The replay’s rotations interrupt the scan, and the scan bound pays for them (Streaming.Step,Results.load, at most ). - Section 29.4 runs the ComboBST controller on a shared tree with two fingers. Each worker step costs at most shared units (
Results.worker_step) and a restart costs at most (Results.restart).
39.1.2 The scan
39.1.2.1 State
/-- A buffer finger and a scan boundary. For forward scans, `next` is the firstunvisited cell; for reverse scans, it is one past the first unvisited cell.Only a key, boundary counter, and direction bit are part of the scan state. -/structure State where tree : Tree position : Nat next : Nat descending : Bool deriving DecidableEqdef State.Valid (s : State) : Prop := s.position < s.tree.size ∧ s.next ≤ s.tree.sizeA scan state is the current tree, the key position of the buffer finger, a boundary next, and a direction bit descending. The finger is a key, that is an inorder rank, as for the fingers of Chapter 10. The tree is part of the state because other fingers may rotate it. In a real structure it is the shared tree, not a copy. A state is valid when the finger is on an existing node and the boundary is at most .
/-- The remaining list is a specification quantity, not additional scan storage. -/def State.requests (s : State) : List Nat := if s.descending then (List.range s.next).reverse else List.range' s.next (s.tree.size - s.next)def State.target (s : State) : Nat := if s.descending then s.next - 1 else s.nextdef State.afterVisit (s : State) : State := { s with next := if s.descending then s.next - 1 else s.next + 1 }The boundary determines the pending cells:
- forward ():
nextis the first unvisited cell, and the pending list is ; - reverse ():
nextis one past the first unvisited cell, and the pending list is .
target is the head of that list, and afterVisit advances the boundary by one in the scan’s direction. requests is a specification quantity: the machine only stores the key, the counter and the bit. Note that target is totalized. A reverse scan with has no pending cell, and its target is in natural numbers, but no step uses it, because both scan steps require a nonempty pending list.
39.1.2.2 Steps
/-- Other fingers may rotate after every primitive move. Cell visits cost one;the two counters separate the scan's work from externally performed rotations. -/inductive Step : State → State → Nat → Nat → Prop where | move {s : State} {a b : Pointer.Config} {y : Nat} : a.tree = s.tree → Pointer.Move a b → a.key? = some s.position → b.key? = some y → s.requests ≠ [] → LazyFinger.distance b.tree y s.target + 1 = LazyFinger.distance s.tree s.position s.target → Step s { s with tree := b.tree, position := y } 1 0 | visit {s : State} : s.requests ≠ [] → s.position = s.target → Step s s.afterVisit 1 0 | rotate {s : State} {t : Tree} : Rotate s.tree t → Step s { s with tree := t } 0 1inductive Trace : State → State → Nat → Nat → Prop where | refl {s : State} : Trace s s 0 0 | step {s t u : State} {k r h q : Nat} : Step s t k r → Trace t u h q → Trace s u (k + h) (r + q)A step carries two counters, the scan’s own work and the number of external rotations.
movefollows one pointer, a parent or child edge of the current tree (Pointer.Move), from the finger’s node to a node . It is allowed only if it brings the finger strictly closer to the target: the edge distance (LazyFinger.distance) from to the target is one less than from the current key. So the finger always moves along a shortest path in the current tree. It costs one unit of work.visitis allowed when the finger is on the target. It consumes the target and costs one unit of work. This is where the cell layer will read or write.rotateis any rotation of the tree (Rotate). It leaves the finger on the same key and costs no scan work, only one in the rotation counter. Nothing restricts where the rotation happens. The paper’s rotations “by other fingers” are a special case, and a rotation at the scan finger’s own node is allowed too.
A trace concatenates steps and adds both counters. The paper describes the traversal as moving to the inorder successor. The shortest-path rule is the same thing when the tree is fixed, and it stays meaningful when the tree changes in between: after a rotation, the finger simply continues along a shortest path in the new tree.
39.1.2.3 The potential
/-- Remaining navigation and cell-visit work without further rotations. -/def potential (s : State) : Nat := LazyFinger.costFrom s.tree s.position s.requestsThe potential of a scan state is the lazy-finger cost (LazyFinger.costFrom, Chapter 15) of its pending cells, starting from the current finger: one unit per pending cell, plus the distance from each cell to the next. If no more rotations happen, it is the work that remains: each move or visit lowers it by one.
The proof of the bound works with the interval decomposition of the lazy-finger cost. Each node of the tree has a key interval, the keys of its subtree, and the edge above is crossed exactly when consecutive positions of the route lie on different sides of that interval’s boundary. So the potential is the number of pending cells plus, for each node, the number of times the sequence (position, pending cells) enters or leaves its interval (LazyFinger.crossings, LazyFinger.intervalCost). A monotone sequence of cells, started from an arbitrary position, crosses the boundary of any interval at most three times. For example, it may leave the interval, enter it again, and leave it for good. This gives the two facts the proof needs:
- the potential is at most ;
- a rotation of over its parent gives the old interval of and gives a new one, so the set of subtree intervals loses one interval and gains one. The potential therefore increases by at most .
Each move or visit decreases the potential by one. Summing over a trace gives work .
The paper’s proof of Lemma 9 counts at most for an inorder traversal and at most one extra step per rotation. The library’s constants are larger for three reasons: visits are charged too, the finger may start anywhere rather than at the first cell, and the rotation bound is proved for the whole potential at once rather than for a single path.
39.1.2.4 Results
/-- The pending scan is a linear-size potential in either direction. -/theorem initial (s : State) (valid : s.Valid) : potential s ≤ 4 * s.tree.size := potential_le s validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.DefinitionsThe pending scan of any valid state, forward or reverse, has potential at most .
/-- Linear traversal accounting from Lemma 9 of arXiv:1304.7604. Rotations caninterrupt the route between two cells. Counts include the scan's node visits.The operational rule follows a shortest route toward each pending cell. -/theorem cost {s t : State} {work rotations : Nat} (trace : Trace s t work rotations) (valid : s.Valid) : work ≤ 4 * s.tree.size + 3 * rotations := trace.cost validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.Definitions/-- Include the cost of the external rotations themselves. -/theorem total {s t : State} {work rotations : Nat} (trace : Trace s t work rotations) (valid : s.Valid) : work + rotations ≤ 4 * s.tree.size + 4 * rotations := trace.total_cost validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.DefinitionsThese are the headline bounds. For every trace from a valid state with rotations, the scan’s work is at most , and the work plus the rotations is at most . Here is the size of the starting tree; rotations do not change it. Both theorems hold for every prefix of a scan, finished or not.
/-- Routing is always possible using a real parent/child pointer primitive. -/theorem progress (s : State) (valid : s.Valid) (pending : s.requests ≠ []) : ∃ t, Step s t 1 0 := next_exists s valid pendingModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.Definitionstheorem finish (s : State) (valid : s.Valid) : ∃ t work, Trace s t work 0 ∧ t.requests = [] ∧ work ≤ potential s := Scan.finish s validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.Definitions/-- Every finite interleaved prefix can be completed within the same bound. -/theorem completion {s t : State} {work rotations : Nat} (trace : Trace s t work rotations) (valid : s.Valid) : ∃ u extra, Trace s u (work + extra) rotations ∧ u.requests = [] ∧ work + extra ≤ 4 * s.tree.size + 3 * rotations := complete_after trace validModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.DefinitionsThe bounds would be empty if the scan could get stuck. progress says it never does: from a valid state with a pending cell, some step of work one exists, a move or a visit. finish runs a whole scan without rotations, within the potential. completion extends any interleaved partial trace to a finished one, with no further rotations, and the extended trace still satisfies the bound.
/-- Completed scans pay for every pending cell, including repeated-key-freesingleton scans. Navigation and rotations cannot silently skip visits. -/theorem visits {s t : State} {work rotations : Nat} (trace : Trace s t work rotations) : s.requests.length ≤ work + t.requests.length := trace.visits_leModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.DefinitionsConversely, work cannot be avoided: a trace that consumes pending cells has done at least units of work. Rotations and moves never consume a cell, so a scan cannot skip cells for free.
39.1.2.5 Choosing a move locally
The move rule is stated with the global distance function, which a real finger cannot compute. The next three theorems show that the move can be chosen by looking only at fields stored at the finger’s node: its key and the bounds of its subtree’s key interval. Routing.choose goes to the parent if the target is outside the interval, and otherwise left or right according to the key.
/-- Scan movement can be selected from the interval fields at the cursor. -/theorem route (s : State) (valid : s.Valid) (pending : s.requests ≠ []) (cursor : Pointer.Config) (tree : cursor.tree = s.tree) (key : cursor.key? = some s.position) (view : Pointer.Routing.View) (fields : view.Valid cursor) (different : s.position ≠ s.target) : ∃ next position, Pointer.Routing.next view cursor s.target = some next ∧ Step s { s with tree := next.tree, position := position } 1 0 := local_route s valid pending cursor tree key view fields differentModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.Definitions/-- Read initialized interval fields at the cursor to choose the next scan move. -/theorem fields_route (s : State) (valid : s.Valid) (pending : s.requests ≠ []) (cursor : Pointer.Config) (tree : cursor.tree = s.tree) (key : cursor.key? = some s.position) (fields : Nat → IntervalMetadata.Bounds) (initialized : Metadata.label fields s.tree 0 = IntervalMetadata.label s.tree 0) (different : s.position ≠ s.target) : ∃ next position, Pointer.Routing.next ⟨(fields s.position).low, s.position, (fields s.position).high⟩ cursor s.target = some next ∧ Step s { s with tree := next.tree, position := position } 1 0 := stored_route s valid pending cursor tree key fields initialized differentModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.Definitions/-- Charged routing with explicit stored keys and fields. -/theorem labelled_route (s : State) (valid : s.Valid) (pending : s.requests ≠ []) (cursor : LabelledCursor.Config (Nat × IntervalMetadata.Bounds)) (canonical : IntervalMetadata.Access.Canonical cursor) (tree : cursor.erase.tree = s.tree) (bounds : IntervalMetadata.Bounds) (read : cursor.read = some (s.position, bounds)) (different : s.position ≠ s.target) : ∃ next position, IntervalMetadata.Access.route s.target cursor = some (4, next) ∧ Step s { s with tree := next.erase.tree, position := position } 1 0 ∧ IntervalMetadata.Access.Canonical next := Scan.labelled_route s valid pending cursor canonical tree bounds read differentModels.Rotation, Models.Pointer.Machine, Models.Pointer.Walk.Definitions, Bounds.StaticTree.Definitions, Bounds.LazyFinger.Definitions, Structures.TreeBuffer.Scan.Definitions, Models.Pointer.Routing.Definitions, Models.Labelled.Metadata.Definitions, Models.Labelled.Intervals.Definitions, Models.Multifinger.Program.Definitions, Models.Labelled.Cursor.Definitions, Models.Labelled.Intervals.Access.DefinitionsWhen the finger is not yet on the target:
route: for any correct view of the interval at the cursor (View.Valid), the pointer chosen byRouting.nextis a legal scan move.fields_route: the same, with the view read from a field array that is correctly initialized (IntervalMetadata.label).labelled_route: the same, for a labelled cursor that stores keys and bounds in its nodes. The routing stepAccess.routecharges (three word reads and one pointer move), and the cursor stays canonical afterwards.
These theorems hold for any tree shape, so they apply after any number of rotations, as long as the bounds were maintained. The maintenance is the node layer’s job.
39.1.3 Cells
The cell layer adds the payloads. It is still a specification: the payloads are a function of the key, and the tree is the scan’s tree.
/-- One payload per existing node, rendered by `Metadata.label`. Values outsidethe current finite key universe are unobservable through the cell operations. -/structure State (α : Type) where scan : Scan.State data : Nat → αdata x is the cell of the node with key . Rendered on the tree by Metadata.label, it is the paper’s layout: the -th cell in the -th node in inorder. Values at keys outside exist because data is a total function, but no operation can read them.
/-- An observable cell access. Events form a specification trace, not additionalruntime storage; reads return a value and writes receive a value from their caller. -/inductive Event (α : Type) where | read (key : Nat) (value : α) | write (key : Nat) (value : α) deriving DecidableEqdef Event.key {α : Type} : Event α → Nat | .read key _ => key | .write key _ => keydef Event.value {α : Type} : Event α → α | .read _ value => value | .write _ value => valueAn event records an observable cell access, a read or a write, with its key and value. The event list of a trace is a specification of what was read and written, not storage of the machine.
/-- Payload I/O is permitted only at the finger's existing node. Navigation ischarged per primitive and follows the scan rule; rotations by other fingerspreserve every payload. Each cell read or write costs one visit unit. -/inductive Step {α : Type} : State α → State α → Option (Event α) → Nat → Nat → Prop where | navigate {s : State α} {a b : Pointer.Config} {y : Nat} : a.tree = s.scan.tree → Pointer.Move a b → a.key? = some s.scan.position → b.key? = some y → s.scan.requests ≠ [] → LazyFinger.distance b.tree y s.scan.target + 1 = LazyFinger.distance s.scan.tree s.scan.position s.scan.target → Step s ⟨{ s.scan with tree := b.tree, position := y }, s.data⟩ none 1 0 | read {s : State α} : s.scan.position < s.scan.tree.size → s.scan.requests ≠ [] → s.scan.position = s.scan.target → Step s ⟨s.scan.afterVisit, s.data⟩ (some (.read s.scan.position (s.data s.scan.position))) 1 0 | write {s : State α} (value : α) : s.scan.position < s.scan.tree.size → s.scan.requests ≠ [] → s.scan.position = s.scan.target → Step s ⟨s.scan.afterVisit, Function.update s.data s.scan.position value⟩ (some (.write s.scan.position value)) 1 0 | rotate {s : State α} {t : Tree} : Rotate s.scan.tree t → Step s ⟨{ s.scan with tree := t }, s.data⟩ none 0 1inductive Trace {α : Type} : State α → State α → List (Event α) → Nat → Nat → Prop where | refl {s : State α} : Trace s s [] 0 0 | step {s t u : State α} {event : Option (Event α)} {events : List (Event α)} {k r h q : Nat} : Step s t event k r → Trace t u events h q → Trace s u (event.toList ++ events) (k + h) (r + q)The steps are the scan’s steps, with the visit split in two:
navigateis a scan move. It costs one and emits no event.readvisits the target and emits the target’s current value. It costs one.write valuevisits the target, replaces its cell byvalue, and emits the write. It costs one.rotateis an external rotation. The payloads are unchanged, since they are indexed by keys.
So the cell layer can only read or write the cell under the finger, and only in scan order. A trace adds up the work and the rotations, as before, and collects the events.
/-- The mathematical effect of a stream of writes supplied in key order. Theactual machine writes only at its cursor; it does not evaluate this recursionas a sequence of free random-access memory operations. -/def writeMany {α : Type} (target : Nat → α) : List Nat → (Nat → α) → (Nat → α) | [], data => data | x :: xs, data => writeMany target xs (Function.update data x (target x))/-- Specification of the data effect of an observable I/O stream. -/def effect {α : Type} (data : Nat → α) : List (Event α) → (Nat → α) | [] => data | .read _ _ :: events => effect data events | .write key value :: events => effect (Function.update data key value) eventsTwo specification functions describe the data after a stream of accesses. writeMany target keys data sets each key in keys to its target value, in order. effect data events applies a list of events: reads change nothing, and writes update one key. No theorem of the reading interface mentions them; the writes theorem below states their content directly.
39.1.3.1 Local access
/-- Reads return the payload of the cursor node. -/theorem read_local {α : Type} {s t : State α} {x : Nat} {value : α} {k r : Nat} (step : Step s t (some (.read x value)) k r) : x = s.scan.position ∧ value = s.data x ∧ Metadata.At (Metadata.label s.data s.scan.tree 0) x value := read_at step/-- Writes change only the cursor node payload. -/theorem write_local {α : Type} {s t : State α} {x : Nat} {value : α} {k r : Nat} (step : Step s t (some (.write x value)) k r) : x = s.scan.position ∧ Metadata.Write (Metadata.label s.data s.scan.tree 0) x value (Metadata.label t.data t.scan.tree 0) ∧ (∀ y, y ≠ x → t.data y = s.data y) := write_at stepA read returns the cell of the finger’s node, $x = $ position and value data x. The read is also located in the labelled tree (Metadata.At). A write changes only the finger’s cell: the labelled tree changes by one payload update (Metadata.Write) and every other key keeps its value.
39.1.3.2 Order and cost
/-- The event stream visits exactly a prefix of the pending keys. -/theorem order {α : Type} {s t : State α} {events : List (Event α)} {k r : Nat} (trace : Trace s t events k r) : s.scan.requests = events.map Event.key ++ t.scan.requests := trace.requests/-- Scan accounting includes every read and write. -/theorem cost {α : Type} {s t : State α} {events : List (Event α)} {k r : Nat} (trace : Trace s t events k r) (valid : s.scan.Valid) : k ≤ 4 * s.scan.tree.size + 3 * r := trace.cost validThe keys of the events of a trace are exactly the pending cells consumed, in scan order: the pending list before the trace is the event keys followed by the pending list after it. And a cell trace obeys the scan bound: work at most , reads and writes included.
39.1.3.3 Complete passes
/-- Completed interleaved scans read the full pending stream. -/theorem read_completed {α : Type} {s t : Scan.State} {work rotations : Nat} (trace : Scan.Trace s t work rotations) (valid : s.Valid) (done : t.requests = []) (data : Nat → α) : Trace ⟨s, data⟩ ⟨t, data⟩ (s.requests.map fun x => Event.read x (data x)) work rotations := read_complete trace valid done data/-- Completed interleaved scans set exactly the pending fields. -/theorem write_completed {α : Type} {s t : Scan.State} {work rotations : Nat} (trace : Scan.Trace s t work rotations) (valid : s.Valid) (done : t.requests = []) (target data : Nat → α) : ∃ final, Trace ⟨s, data⟩ ⟨t, final⟩ (s.requests.map fun x => Event.write x (target x)) work rotations ∧ ∀ x, final x = if x ∈ s.requests then target x else data x := write_complete trace valid done target data/-- The observed write stream determines the final node fields. -/theorem writes {α : Type} {s t : State α} {target : Nat → α} {keys : List Nat} {w r : Nat} (trace : Trace s t (keys.map fun x => Event.write x (target x)) w r) (x : Nat) : t.data x = if x ∈ keys then target x else s.data x := trace.writes xThese lift a finished scan trace, rotations included, to a cell trace with the same work and the same rotations.
read_completed: reading at every visit produces one read event per pending cell, in order, with the stored values, and leaves the data unchanged.write_completed: writing a target function at every visit produces one write per pending cell, in order. The final data agree with the target on the pending cells and with the old data elsewhere.writes: for any trace whose events are writes oftargetat a list of keys, the final cell of istarget xif is in the list and the old value otherwise.
The snapshot load of Section 39.2 uses the read direction with rotations interleaved. The save uses the write direction.
/-- Whole-buffer forward read with linear charged work. -/theorem read_all {α : Type} (tree : Tree) (position : Nat) (present : position < tree.size) (data : Nat → α) : ∃ t work, Trace ⟨⟨tree, position, 0, false⟩, data⟩ ⟨t, data⟩ ((List.range tree.size).map fun x => Event.read x (data x)) work 0 ∧ t.requests = [] ∧ work ≤ 4 * tree.size := Cells.read_all tree position present data/-- Whole-buffer write with linear charged work. -/theorem write_all {α : Type} (tree : Tree) (position : Nat) (present : position < tree.size) (target data : Nat → α) : ∃ t final work, Trace ⟨⟨tree, position, 0, false⟩, data⟩ ⟨t, final⟩ ((List.range tree.size).map fun x => Event.write x (target x)) work 0 ∧ t.requests = [] ∧ work ≤ 4 * tree.size ∧ ∀ x, final x = if x < tree.size then target x else data x := Cells.write_all tree position present target data/-- Whole-buffer reverse read with linear charged work. -/theorem read_reverse {α : Type} (tree : Tree) (position : Nat) (present : position < tree.size) (data : Nat → α) : ∃ t work, Trace ⟨⟨tree, position, tree.size, true⟩, data⟩ ⟨t, data⟩ ((List.range tree.size).reverse.map fun x => Event.read x (data x)) work 0 ∧ t.requests = [] ∧ work ≤ 4 * tree.size := read_all_reverse tree position present dataWhole-buffer passes without interleaved rotations. From a finger anywhere in the tree, a forward read of all cells, a forward write of all cells, or a reverse read of all cells costs at most work. The write sets the cells of the keys below to the target values and leaves the rest unchanged.
/-- Advance to and write exactly one pending cell. -/theorem write_next {α : Type} (s : Scan.State) (valid : s.Valid) (pending : s.requests ≠ []) (data : Nat → α) (value : α) : ∃ t work, Trace ⟨s, data⟩ ⟨t, Function.update data s.target value⟩ [.write s.target value] work 0 ∧ s.requests = s.target :: t.requests := Cells.write_next s valid pending data valueOne cell at a time: from a valid state with a pending cell, the scan can navigate to the next pending cell and write it, with exactly that one write event and no rotation. The theorem does not bound the work of this single step: the finger may have to travel far. Its work is bounded by cost when it is part of a longer trace from a valid state.
39.1.4 Physical nodes
The two layers above speak of keys and of a function data. The node layer says what a node actually stores, and how a finger moves, reads, writes and rotates using only the fields of the nodes it touches. A node is a record in a labelled tree (LabelledTree), addressed by a zipper cursor (LabelledCursor.Config), as in Chapter 36.
/-- One physical node stores its key, routing bounds, and independent buffer cell. -/structure Entry (α : Type) where key : Nat bounds : IntervalMetadata.Bounds cell : α deriving DecidableEqdef Entry.routing {α : Type} (e : Entry α) : Nat × IntervalMetadata.Bounds := (e.key, e.bounds)def Entry.payload {α : Type} (e : Entry α) : Nat × α := (e.key, e.cell)A node entry stores three things: its key, the bounds of its subtree’s key interval (IntervalMetadata.Bounds), and its buffer cell. The projection routing forgets the cell and gives the routing annotation of Chapter 36. The projection payload forgets the bounds and gives the key and cell, the layout of Metadata.label. In ComboBST the cell type is Nat: a cell holds a packet of opcodes (Section 39.2). The Lean model does not bound the size of the words; the storage clauses of the paper are not formalized.
/-- Finite representation of the shared routing annotation and saved cells.This recursive layout is a specification, not a runtime rebuilding operation. -/def label {α : Type} (data : Nat → α) : Tree → Nat → LabelledTree (Entry α) | .nil, _ => .nil | .node l r, lo => let key := lo + l.size .node (label data l lo) ⟨key, ⟨lo, lo + (Tree.node l r).size⟩, data key⟩ (label data r (key + 1))/-- Separate projections are specifications; neither is evaluated as a treetraversal by the node operations. -/def Routing {α : Type} (c : LabelledCursor.Config (Entry α)) : Prop := IntervalMetadata.Access.Canonical (c.map Entry.routing)def Stored {α : Type} (data : Nat → α) (c : LabelledCursor.Config (Entry α)) : Prop := (c.map Entry.payload).tree = Metadata.label data c.erase.tree 0label data t lo is the canonical layout of a tree whose keys start at lo: every node stores its rank, the exact interval of its subtree, and its cell. Routing c says that the routing projection of a cursor’s tree is canonical, and Stored data c says that its payload projection is the layout of data. These are representation invariants used in the proofs, not operations.
39.1.4.1 Maintained rotations
A rotation changes the subtree intervals of the two nodes involved. If the bounds are not updated, routing breaks. The update is local: the new bounds of both nodes can be computed from their old keys and bounds.
structure State (α : Type) where cursor : LabelledCursor.Config (Entry α) child : Nat × IntervalMetadata.Bounds parent : Nat × IntervalMetadata.Bounds deriving DecidableEqdef State.routing {α : Type} (s : State α) : IntervalMetadata.Maintenance.State := ⟨s.cursor.map Entry.routing, s.child, s.parent⟩/-- Update only the two bound words; the cell stays in its existing node. -/def writeBounds {α : Type} (c : LabelledCursor.Config (Entry α)) (bounds : IntervalMetadata.Bounds) : Option (LabelledCursor.Config (Entry α)) := match c.focus with | .nil => none | .node l e r => some ⟨.node l { e with bounds := bounds } r, c.context⟩/-- The same charged instruction set as interval maintenance, with independentcell fields carried through each pointer operation and left alone by writes. -/def tick {α : Type} (op : IntervalMetadata.Maintenance.Op) (s : State α) : Option (State α) := do match op with | .pointer opcode => return { s with cursor := ← LabelledCursor.perform opcode s.cursor } | .readChild => return { s with child := (← s.cursor.read).routing } | .readParent => return { s with parent := (← s.cursor.read).routing } | .writeChild side => return { s with cursor := ← writeBounds s.cursor (IntervalMetadata.Maintenance.childBounds side s.routing) } | .writeParent side => return { s with cursor := ← writeBounds s.cursor (IntervalMetadata.Maintenance.parentBounds side s.routing) }def run {α : Type} : List IntervalMetadata.Maintenance.Op → State α → Option (State α) | [], s => some s | op :: ops, s => (tick op s).bind (run ops)def maintain {α : Type} (side : IntervalMetadata.Maintenance.Side) (s : State α) : Option (State α) := run (IntervalMetadata.Maintenance.program side) sA node-machine state is a cursor and two scratch registers, child and parent, each holding a key and its bounds. State.routing forgets the cells and gives the state of the routing-only maintenance machine (Maintenance.State). tick executes one instruction of that machine (Maintenance.Op): a pointer opcode, a read of the current node’s key and bounds into a register, or a write of new bounds into the current node with writeBounds. The cell is carried along by every pointer operation and never touched by a bounds write. run executes a list of instructions, and maintain side runs the fixed program Maintenance.program for a left or right rotation. Starting at the child, it reads the child, goes up, reads the parent, comes back down, rotates, rewrites the bounds of the promoted and the demoted node, and returns to the promoted node.
The program performs six word reads, four word writes, four moves and one rotation. Its charge is , the cost of a maintained rotation in the shared layer below. The proof files show that maintain agrees with the routing-only program on the routing projection, performs exactly a rotation on the payload projection, keeps both invariants, and starts from any scratch values (maintain_routing, maintain_payload, maintain_preserves, maintain_scratch in Nodes/Maintenance.lean).
39.1.4.2 Routing and cell access
/-- Navigation reads only key and interval fields, with the same four-unitcharge as the routing-only machine. -/def route {α : Type} (target : Nat) (c : LabelledCursor.Config (Entry α)) : Option (Nat × LabelledCursor.Config (Entry α)) := do let e ← c.read let direction ← Pointer.Routing.choose ⟨e.bounds.low, e.key, e.bounds.high⟩ target let next ← match direction with | .left => LabelledCursor.perform .downLeft c | .right => LabelledCursor.perform .downRight c | .parent => match c.context with | .left _ _ :: _ => LabelledCursor.perform .upLeft c | .right _ _ :: _ => LabelledCursor.perform .upRight c | [] => none return (4, next)/-- A cell read returns one stored word without reading the routing fields. -/def readCell {α : Type} (c : LabelledCursor.Config (Entry α)) : Option (Nat × α) := c.read.map fun e => (1, e.cell)/-- A cell write charges one word and preserves the key and routing bounds. -/def writeCell {α : Type} (c : LabelledCursor.Config (Entry α)) (value : α) : Option (Nat × LabelledCursor.Config (Entry α)) := match c.focus with | .nil => none | .node l e r => some (1, ⟨.node l { e with cell := value } r, c.context⟩)route target c reads the current node’s key and bounds, chooses a direction with Routing.choose, and follows one pointer: down to a child, or up through the zipper’s top frame. It charges , like the routing-only Access.route, and fails at the target itself or at the root when the target is outside. readCell returns the current node’s cell for one unit and reads no routing field. writeCell replaces the current cell for one unit and keeps the key and bounds. The proof files show that these three operations realize the navigate, read and write steps of the cell layer on a correctly labelled tree (navigate_step, read_step, write_step in Nodes/Bridge.lean), and that maintain realizes its rotate step, with the scan finger’s key unchanged (rotation_step).
39.1.4.3 Initializing the bounds
When ComboBST starts, the nodes of the initial tree hold their keys and some cells, but their bound words may contain anything. A traversal writes the correct bounds before the first save.
/-- Initial finite layout with arbitrary routing words and existing keys/cells.This is a representation specification, not an initializing traversal. -/def raw {α : Type} (fields : Nat → IntervalMetadata.Bounds) (data : Nat → α) : Tree → Nat → LabelledTree (Entry α) | .nil, _ => .nil | .node l r, lo => let key := lo + l.size .node (raw fields data l lo) ⟨key, fields key, data key⟩ (raw fields data r (key + 1))raw fields data t lo is the starting layout: each node stores its correct key and its cell, and arbitrary bounds fields key.
structure State (α : Type) where cursor : Config (Entry α) pending : IntervalMetadata.Bounds mode : IntervalMetadata.Initialization.Mode/-- Stackless initialization on actual combined nodes. Reads use the currentnode's stored key and bounds; writes leave its key and snapshot cell intact.Child dispatch costs four, bounds writes two, null checks and returns one. -/def tick {α : Type} (s : State α) : Option (Nat × State α) := match s.mode, s.cursor.focus, s.cursor.context with | .write, .node l e r, cs => some (2, ⟨⟨.node l { e with bounds := s.pending } r, cs⟩, s.pending, .left⟩) | .left, .node .nil _ _, _ => some (1, { s with mode := .right }) | .left, .node (.node a e b) parent r, cs => some (4, ⟨⟨.node a e b, .left parent r :: cs⟩, ⟨parent.bounds.low, parent.key⟩, .write⟩) | .right, .node _ _ .nil, _ => some (1, { s with mode := .up }) | .right, .node l parent (.node a e b), cs => some (4, ⟨⟨.node a e b, .right l parent :: cs⟩, ⟨parent.key + 1, parent.bounds.high⟩, .write⟩) | .up, .node a e b, .left parent r :: cs => some (1, { s with cursor := ⟨.node (.node a e b) parent r, cs⟩, mode := .right }) | .up, .node a e b, .right l parent :: cs => some (1, { s with cursor := ⟨.node l parent (.node a e b), cs⟩ }) | _, _, _ => noneinductive Run {α : Type} : State α → State α → Nat → Prop where | refl {s : State α} : Run s s 0 | step {s t u : State α} {cost rest : Nat} : tick s = some (cost, t) → Run t u rest → Run s u (cost + rest)The initializer is the stackless traversal of the routing-only initializer (Initialization.tick), run on the actual combined nodes. Its state is a cursor, one pending pair of bounds, and a mode (Initialization.Mode):
writestores the pending bounds into the current node (charge ) and switches toleft;leftdescends into a nonempty left child (charge ), with pending bounds computed from the parent’s stored fields, or switches torightif there is none (charge );rightdoes the same on the right, with , or switches toup;upreturns to the parent (charge ) and resumes inrightmode if it came from the left.
It keeps no stack: the ancestors’ information is in the parent links and in the bounds already written. Each step keeps every key and cell. Run is a finite run, with its total charge.
def initial {α : Type} (tree : LabelledTree (Entry α)) (n : Nat) : State α := ⟨⟨tree, []⟩, ⟨0, n⟩, .write⟩/-- Bounded tail loop; fuel and the accumulated work are scalar registers. -/def runLoop {α : Type} : Nat → Nat → State α → Option (Nat × State α) | 0, spent, s => match tick s with | none => some (spent, s) | some _ => none | fuel + 1, spent, s => match tick s with | none => some (spent, s) | some (cost, next) => runLoop fuel (spent + cost) nextdef runFuel {α : Type} (fuel : Nat) (s : State α) : Option (Nat × State α) := runLoop fuel 0 sinitial tree n starts at the root in write mode with pending bounds . The universe size is a scalar input, not computed from the tree. runFuel fuel is the executable loop: it runs until no step applies, and fails if more than fuel steps would be needed. Every step charges at least one, so a fuel equal to a bound on the charge is enough. The proof file Nodes/Initialization/Execution.lean shows that, when is the size of the tree, the loop with fuel ends at the root with the canonical layout label data tree 0 and total charge at most (complete). The startup of ComboBST, Startup.Execution, requires exactly this run and then a shared-node trace from its result.
39.1.5 Shared nodes
The last layer puts several fingers on one labelled tree. This is the physical counterpart of the multi-finger model of Chapter 10, with node records instead of bare nodes.
/-- Persistent node identities into a single shared labelled tree. As in themultifinger model, keys denote existing nodes; zipper views below are semanticwitnesses rather than independent copies or runtime searches. -/structure State (α : Type) (fingers : Nat) where tree : LabelledTree (Nodes.Entry α) position : Fin fingers → Natdef State.Valid {α : Type} {fingers : Nat} (s : State α fingers) (data : Nat → α) : Prop := s.tree.map Nodes.Entry.routing = IntervalMetadata.label s.tree.erase 0 ∧ s.tree.map Nodes.Entry.payload = Metadata.label data s.tree.erase 0 ∧ ∀ i, s.position i < s.tree.erase.size/-- The selected finger's local view of the one shared tree. -/def View {α : Type} {fingers : Nat} (s : State α fingers) (i : Fin fingers) (c : LabelledCursor.Config (Nodes.Entry α)) (entry : Nodes.Entry α) : Prop := c.tree = s.tree ∧ c.read = some entry ∧ entry.key = s.position iA shared state is one labelled tree of node entries and a key for each of its fingers persistent fingers. As in the multi-finger model, a finger is the key of an existing node, so a rotation, which preserves keys, keeps every finger on its node. Valid s data says that the routing projection is the canonical interval annotation, that the payload projection is the layout of data, and that every finger is on a node. The data are a parameter of validity, not stored separately: the cells are the payload projection. View s i c entry says that the cursor c is finger i’s position in the shared tree, reading entry. The cursor is a proof witness of where the finger is, not a separate copy of the tree.
/-- Navigation changes only the selected node identity. Reads keep all fingersfixed; writes and maintained rotations update the shared tree in place. -/inductive Step {α : Type} {fingers : Nat} : State α fingers → Fin fingers → State α fingers → Option (Cells.Event α) → Nat → Prop where | move {s : State α fingers} {i : Fin fingers} {c next : LabelledCursor.Config (Nodes.Entry α)} {entry nextEntry : Nodes.Entry α} (op : Multifinger.Opcode) : View s i c entry → LabelledCursor.perform op c = some next → Pointer.Move c.erase next.erase → next.read = some nextEntry → Step s i ⟨next.tree, Function.update s.position i nextEntry.key⟩ none 1 | navigate {s : State α fingers} {i : Fin fingers} {c next : LabelledCursor.Config (Nodes.Entry α)} {entry nextEntry : Nodes.Entry α} (target : Nat) : View s i c entry → Nodes.route target c = some (4, next) → next.read = some nextEntry → Step s i ⟨next.tree, Function.update s.position i nextEntry.key⟩ none 4 | read {s : State α fingers} {i : Fin fingers} {c : LabelledCursor.Config (Nodes.Entry α)} {entry : Nodes.Entry α} {value : α} : View s i c entry → Nodes.readCell c = some (1, value) → Step s i s (some (.read (s.position i) value)) 1 | write {s : State α fingers} {i : Fin fingers} {c next : LabelledCursor.Config (Nodes.Entry α)} {entry : Nodes.Entry α} (value : α) : View s i c entry → Nodes.writeCell c value = some (1, next) → Step s i ⟨next.tree, s.position⟩ (some (.write (s.position i) value)) 1 | rotate {s : State α fingers} {i : Fin fingers} {before after : Nodes.State α} {entry : Nodes.Entry α} (side : IntervalMetadata.Maintenance.Side) : View s i before.cursor entry → Nodes.maintain side before = some after → Step s i ⟨after.cursor.tree, s.position⟩ none 15/-- Event lists are specifications. The runtime state keeps only the fixednumber of fingers, the node fields, and the local operation's scratch words. -/inductive Trace {α : Type} {fingers : Nat} : State α fingers → State α fingers → List (Cells.Event α) → Nat → Prop where | refl {s : State α fingers} : Trace s s [] 0 | step {s t u : State α fingers} {i : Fin fingers} {event : Option (Cells.Event α)} {events : List (Cells.Event α)} {cost rest : Nat} : Step s i t event cost → Trace t u events rest → Trace s u (event.toList ++ events) (cost + rest)A step acts at one finger i, emits at most one event, and has a charge:
| Step | Effect | Charge |
|---|---|---|
move op |
follow one parent or child pointer (Pointer.Move on the erased cursors), without reading fields |
1 |
navigate target |
one Nodes.route step toward target |
4 |
read |
read finger i’s cell; nothing changes |
1 |
write value |
write finger i’s cell in place |
1 |
rotate side |
run Nodes.maintain side at finger i |
15 |
Moves and navigation update only finger i. Writes and rotations change the shared tree, and every finger keeps its key. A trace collects the events and adds the charges. Its event list is a specification. The runtime state is the tree, the fixed number of fingers, and the scratch words of the current local operation.
The two kinds of movement serve the two kinds of fingers. A worker finger follows the opcodes of its algorithm with move, and the buffer finger routes itself with navigate.
/-- Forget cell and routing fields while retaining the one tree and everypersistent finger. Erasure is a specification, not a runtime traversal. -/def State.erase {α : Type} {fingers : Nat} (s : State α fingers) : Multifinger.State fingers := ⟨s.tree.erase, s.position⟩Erasing forgets the routing and cell fields and keeps the tree shape and every finger, giving a Multifinger.State. The proof files show that a shared trace erases to a multi-finger trace (Multifinger.Trace) with no more instructions than its charge (Trace.erase in Shared/Erasure/Traces.lean). This is how ComboBST’s physical execution, which is described on shared nodes, becomes a multi-finger execution and then, through the hand of Section 35.2, a pointer-machine execution.
def Represents {α : Type} {fingers : Nat} (actual : Shared.State α fingers) (model : Cells.State α) (i : Fin fingers) : Prop := actual.Valid model.data ∧ actual.tree.erase = model.scan.tree ∧ actual.position i = model.scan.positionRepresents actual model i relates a shared state to a cell-layer state: the shared state is valid for the model’s data, its shape is the scan’s tree, and finger i is the scan finger. The proof files lift every rotation-free cell trace to a shared trace with the same events, at most four times the work, and with all other fingers unmoved (CellRefinement.trace in Shared/CellRefinement/Traces.lean). The factor four is the cost of navigate. No theorem of the reading interface mentions this relation; the snapshot section uses the lifting in its proofs.
/-- A requested key occurs at a real persistent finger between two parts ofthe same shared-node trace. Work after the visit is retained and charged. -/def Visit {α : Type} {fingers : Nat} (s t : State α fingers) (x : Nat) (events : List (Cells.Event α)) (cost : Nat) : Prop := ∃ visited before after first last i, Trace s visited before first ∧ visited.position i = x ∧ Trace visited t after last ∧ events = before ++ after ∧ cost = first + last/-- A shared-node request sequence includes one explicit request charge aswell as all pointer, cell, routing, and maintenance work. -/inductive Execution {α : Type} {fingers : Nat} : State α fingers → List Nat → State α fingers → List (Cells.Event α) → Nat → Prop where | nil {s : State α fingers} : Execution s [] s [] 0 | cons {s t u : State α fingers} {x cost rest : Nat} {xs : List Nat} {first last : List (Cells.Event α)} : Visit s t x first cost → Execution t xs u last rest → Execution s (x :: xs) u (first ++ last) (1 + cost + rest)Requests on shared nodes. A Visit s t x events cost is a shared trace from s to t that passes through a state in which some finger is on key . The work after that moment is part of the visit and is charged. An Execution serves a list of requests by consecutive visits, and charges one unit per request plus all pointer, cell, routing and maintenance work. This is the convention of Multifinger.Execution and of the rest of the library. The proof files show that an execution erases to a multi-finger execution of the same requests, with no larger cost (Requests.Execution.erase). ComboBST’s per-request transition (Online.Transition) records such a visit, whose events are all correct reads of the saved cells.