Documentation

CslibFrontier.DataStructure.SearchTree.PointerMachine.Representation

Linked representations of binary search trees #

The left/right/parent record layout and recursive heap representation adapt Stefan Langerman's earlier lean-bst development. This is an adaptation of that design, not a verbatim port of a pinned source module. Mathematical trees use Frontier's existing BinaryTree. Addresses are ghost labels, inaccessible to scalar instructions. Extra data fields hold values and balancing metadata. Unrelated heap records are permitted.

Represents describes the contents of a subtree, independently of ordering and of a cursor. Mutation routines must additionally establish separation of the records they modify. The companion search module proves charged machine execution against SearchTree.contains.

@[reducible, inline]

Cursor, root, parent, grandparent, middle, null and comparison pointer registers; query and temporary data registers followed by client registers. Records contain left, right and parent links, then a key and client data fields.

A ghost address and all scalar fields of a tree node. Only data is available through scalar loads; address records its heap location for the proof.

  • address : ℕ

    Heap location, used only in the representation proof.

  • data : Fin (extra + 1) → M.Value

    Key in field zero, followed by client data.

Different positions in the represented tree have different heap addresses.

The finite set of ghost node addresses. This is a proof footprint, not scalar data available to the machine.

theorem Cslib.DataStructure.SearchTree.PointerMachine.mem_addresses_iff {M : PointerMachine.Model} {extra : ℕ} (t : BinaryTree (Label M extra)) (a : ℕ) :
a ∈ addresses t ↔ ∃ (p : PosNum) (label : Label M extra), BinaryTree.get p t = some label ∧ label.address = a

The address footprint consists exactly of labels at existing tree positions.

Address separation at a node consists of separation within each child and disjoint child footprints, neither containing the root.

Root address of a ghost-labelled tree; the empty tree has a null root.

Concrete left/right/parent record for a ghost label.

Every node has its labelled address, scalar fields and prescribed child/parent links. The first pointer is the external parent of the represented subtree.

theorem Cslib.DataStructure.SearchTree.PointerMachine.Represents.congr {M : PointerMachine.Model} {extra regs : ℕ} {h k : List (PointerMachine.Record M (layout extra regs))} {t : BinaryTree (Label M extra)} {parent : PointerMachine.Pointer} (rep : Represents h parent t) (agree : ∀ (p : PosNum) (a : Label M extra), BinaryTree.get p t = some a → k[a.address]? = h[a.address]?) :
Represents k parent t

Agreement on the represented tree's records transports its heap representation. Unrelated records may change arbitrarily.

theorem Cslib.DataStructure.SearchTree.PointerMachine.Represents.address_lt {M : PointerMachine.Model} {extra regs : ℕ} {heap : List (PointerMachine.Record M (layout extra regs))} {parent : PointerMachine.Pointer} {tree : BinaryTree (Label M extra)} (rep : Represents heap parent tree) {a : ℕ} (mem : a ∈ addresses tree) :
a < heap.length

Every address in a represented subtree lies within the allocated heap.

theorem Cslib.DataStructure.SearchTree.PointerMachine.Represents.append {M : PointerMachine.Model} {extra regs : ℕ} {heap : List (PointerMachine.Record M (layout extra regs))} {parent : PointerMachine.Pointer} {tree : BinaryTree (Label M extra)} (h : Represents heap parent tree) (suffix : List (PointerMachine.Record M (layout extra regs))) :
Represents (heap ++ suffix) parent tree

Appending fresh records preserves every existing linked-tree representation.

Forget addresses and metadata, retaining the keys in Frontier's existing tree type.