Documentation

CslibFrontier.DataStructure.SearchTree.PointerMachine.Context

Ancestors of a linked subtree #

These ghost frames describe ancestors and siblings, not an additional machine stack. They adapt the ancestor contexts and labelled cursors of Stefan Langerman's earlier lean-bst development to Frontier's BinaryTree. represents_plug_iff decomposes a whole-tree heap representation into the focused subtree and its surrounding context, and conversely reconstructs it. Parent pointers implement the corresponding machine navigation.

One ghost ancestor, retaining its label and the sibling outside the focus.

Reconstruct the tree, with the immediate parent first in the context.

The immediate parent's address, or null at the overall root.

A plugged tree consists of the focus addresses and the addresses in its context.

Heap representation of the ancestors and siblings around a supplied focus link. The list and labels are proof data; no unbounded register or stack is added to the machine.

theorem Cslib.DataStructure.SearchTree.PointerMachine.represents_plug_iff {M : PointerMachine.Model} {extra regs : ℕ} (heap : List (PointerMachine.Record M (layout extra regs))) (cs : List (Frame M extra)) (t : BinaryTree (Label M extra)) :
Represents heap none (plug cs t) ↔ Represents heap (contextParent cs) t ∧ ContextRep heap (root t) cs

A whole-tree representation is exactly the focused subtree plus its ancestor/sibling context. This permits local mutation proofs to reconstruct the complete tree.

A complete tree is separated exactly when its focus and context are individually separated and their address footprints are disjoint.

A focused subtree inherits distinct addresses from its complete tree.

Replacing a focus by a separated tree with the same address footprint preserves separation from every ancestor and sibling.

theorem Cslib.DataStructure.SearchTree.PointerMachine.root_plug_congr {M : PointerMachine.Model} {extra : ℕ} (cs : List (Frame M extra)) {a b : BinaryTree (Label M extra)} (eq : root a = root b) :
root (plug cs a) = root (plug cs b)

Equal focus roots give equal complete-tree roots, independently of interior shape.

The focused addresses are among the complete tree's addresses.

A focus's height plus its ancestor count is bounded by the complete tree's height.

theorem Cslib.DataStructure.SearchTree.PointerMachine.Represents.plug_of_frame {M : PointerMachine.Model} {extra regs : ℕ} {h k : List (PointerMachine.Record M (layout extra regs))} {cs : List (Frame M extra)} {before after : BinaryTree (Label M extra)} (rep : Represents h none (plug cs before)) (distinct : AddressesDistinct (plug cs before)) (newRep : Represents k (contextParent cs) after) (sameRoot : root after = root before) (frame : ∀ a ∉ addresses before, k[a]? = h[a]?) :
Represents k none (plug cs after)

A local replacement with the same root reconstructs the whole tree when the heap outside the original focus is unchanged. Separation is derived from the original tree.

theorem Cslib.DataStructure.SearchTree.PointerMachine.ascend_correct {M : PointerMachine.Model} {extra regs : ℕ} (s : PointerMachine.State M (layout extra regs)) (cs : List (Frame M extra)) (label : Label M extra) (l r : BinaryTree (Label M extra)) (rep : Represents s.heap (contextParent cs) (BinaryTree.node label l r)) (cursor : s.ptr 0 = some label.address) (pc : s.pc = 0) :

Following a represented nonempty focus's parent takes one load and halt. The heap, scalars and every other pointer register survive; at the root the resulting cursor is null.