Documentation

CslibFrontier.DataStructure.FusionTree.WordRAM.Model

Contiguous static fusion-tree records #

Every record has an 18-word header. Leaves store tag 0, presence, and key (zero when absent), followed by fifteen zero words. Internal nodes have tag 1, followed by exactly n interleaved pairs of full child minima and absolute child pointers, and the recursively encoded children in order. No capacity-sized arrays are allocated. The header indices are: tag 0, child count 1, minimum 2, compression mask C 3, multiplier digits 4--6, D 7, copies 8, packed complements 9, packed normal 10, guards 11, bits 12, middle 13, radix 14, maximum 15, width-dependent global offset 16, and reserved 17, where NodeParameters.words stores the selected-bit count. Parameters supplies indices 3--17; it asserts no node-search oracle.

This is a static representation, with explicit arena/address and stored-word fit contracts. It asserts neither preprocessing time nor a query running time.

Main definitions #

Main results #

References #

@[reducible, inline]

The fifteen preprocessing words in header slots 3 through 17, for each internal node. The final two slots accommodate a width-dependent global offset and one reserved word.

Fixed record header length, independent of branching capacity.

Stable offsets within internal headers. The fifteen parameter words are named here so node-search implementations can use the layout without duplicating numerical indices.

Record tag: 0 for leaves, 1 for internal nodes.

Number of actual children (presence for a leaf).

Reserved preprocessing word; NodeParameters.words stores the selected-bit count here.

@[irreducible]

Actual allocated words, without any padding to the maximum branching capacity.

Starting address of child i, after the parent's actual tables and earlier children.

The concrete internal header.

Stride-two child table: a full minimum followed by its absolute pointer.

Serialize a tree at its absolute address. Invalid nonsingleton leaves are truncated; decode_encode requires Tree.Valid, which excludes them.

Serialize consecutive child records; the next record starts at the previous one's end.

Every serialized tree occupies exactly its claimed span.

The concrete child-record list has the sum of the child spans as its length.

Memory represents the concrete serialized tree, with arbitrary memory outside its block.

The existing heap assertion for the serialized arena, including exactly its allocated cells.

theorem Cslib.DataStructure.FusionTree.WordRAM.arena_holds (p : Parameters) (t : Tree) (base : ℕ) (mem : ℕ → ℕ) :
(arena p t base).holds mem ↔ Rep p t base mem

The heap assertion's contents are exactly the representation predicate.

theorem Cslib.DataStructure.FusionTree.WordRAM.arena_footprint (p : Parameters) (t : Tree) (base : ℕ) :
(arena p t base).footprint = { base := base, length := span t }.footprint

The heap footprint counts actual allocated words, including each fixed header.

theorem Cslib.DataStructure.FusionTree.WordRAM.Rep.frame {p : Parameters} {t : Tree} {base : ℕ} {mem mem' : ℕ → ℕ} {writes : Finset ℕ} (hr : Rep p t base mem) (hd : Disjoint { base := base, length := span t }.footprint writes) (hm : WordRAM.Modifies writes mem mem') :
Rep p t base mem'

Writes disjoint from the contiguous arena preserve the complete tree representation.

A concrete total memory obtained by placing the serialized words into an otherwise zero RAM.

theorem Cslib.DataStructure.FusionTree.WordRAM.rep_memory (p : Parameters) (t : Tree) (base : ℕ) :
Rep p t base (memory p t base)

The explicit list encoding has an actual RAM realization.

theorem Cslib.DataStructure.FusionTree.WordRAM.Rep.node_header {p : Parameters} {m base : ℕ} {cs : List Tree} {mem : ℕ → ℕ} (hr : Rep p (Tree.node m cs) base mem) :
mem base = 1 ∧ mem (base + 1) = cs.length ∧ mem (base + 2) = m ∧ ∀ (j : Fin 15), mem (base + 3 + ↑j) = p (Tree.node m cs) j

The first three internal header words and all fifteen preprocessing words decode literally.

theorem Cslib.DataStructure.FusionTree.WordRAM.Rep.leaf_fields {p : Parameters} {base : ℕ} {xs : List ℕ} {mem : ℕ → ℕ} (hr : Rep p (Tree.leaf xs) base mem) :
mem base = 0 ∧ (mem (base + 1) = if xs.isEmpty = true then 0 else 1) ∧ mem (base + 2) = xs.headD 0

The three leaf words decode as tag, presence and key.

theorem Cslib.DataStructure.FusionTree.WordRAM.Rep.child {p : Parameters} {m base : ℕ} {cs : List Tree} {mem : ℕ → ℕ} (hr : Rep p (Tree.node m cs) base mem) (i : Fin cs.length) :
mem (base + headerWords + 2 * ↑i) = cs[i].minimum ∧ mem (base + headerWords + (2 * ↑i + 1)) = childAddress base cs ↑i ∧ Rep p cs[i] (childAddress base cs ↑i) mem

Following a stored child pointer gives the representation of precisely that child.

theorem Cslib.DataStructure.FusionTree.WordRAM.child_span_le (base m : ℕ) (cs : List Tree) (i : Fin cs.length) :
base + headerWords + 2 * cs.length ≤ childAddress base cs ↑i ∧ childAddress base cs ↑i + span cs[i] ≤ base + span (Tree.node m cs)

A whole child allocation lies inside its parent's allocation.

theorem Cslib.DataStructure.FusionTree.WordRAM.access_owned (base : ℕ) (t : Tree) (a : ℕ) (ha : a < span t) :
{ base := base, length := span t }.Owns (base + a)

Every valid offset denotes an allocated cell, including the full leaf header.

theorem Cslib.DataStructure.FusionTree.WordRAM.header_access_owned (base : ℕ) (t : Tree) (j : Fin 18) :
{ base := base, length := span t }.Owns (base + ↑j)

Each of the eighteen header loads lies inside the record, including for empty leaves.

theorem Cslib.DataStructure.FusionTree.WordRAM.child_entry_access_owned (base m : ℕ) (cs : List Tree) (i : Fin cs.length) :
{ base := base, length := span (Tree.node m cs) }.Owns (base + headerWords + 2 * ↑i) ∧ { base := base, length := span (Tree.node m cs) }.Owns (base + headerWords + (2 * ↑i + 1))

Both stride-two table loads are inside the parent's allocation.

theorem Cslib.DataStructure.FusionTree.WordRAM.child_access_owned (base m : ℕ) (cs : List Tree) (i : Fin cs.length) (a : ℕ) (ha : a < span cs[i]) :
{ base := base, length := span (Tree.node m cs) }.Owns (childAddress base cs ↑i + a)

Every word read inside a child record is owned by the parent allocation. Repeated use provides the same guarantee at arbitrary descendant depth.

theorem Cslib.DataStructure.FusionTree.WordRAM.span_build_le {B : ℕ} (hB : 2 ≤ B) (xs : List ℕ) :
span (Tree.build B xs) ≤ 126 * xs.length + 18

Uniform linear allocated RAM words, with constants independent of branching capacity and word width. This counts the actual serialized words, including all preprocessing headers.

A single absolute constant works for both terms in the usual C * n + C bound.

Recover the functional tree by loads of tags, fields and absolute child pointers. Fuel bounds recursive depth, not the number of machine instructions. The zero-fuel result is a default; correctness requires fuel strictly larger than the tree height.

theorem Cslib.DataStructure.FusionTree.WordRAM.decode_rep {B fuel base : ℕ} {p : Parameters} {t : Tree} {mem : ℕ → ℕ} (ht : Tree.Valid B t) (hr : Rep p t base mem) (hf : t.height < fuel) :
decode fuel mem base = t

Concrete RAM decoding recovers every valid tree. In particular, empty and singleton leaves remain distinct even when the stored key is zero.

theorem Cslib.DataStructure.FusionTree.WordRAM.decode_encode {B fuel : ℕ} {t : Tree} (ht : Tree.Valid B t) (hf : t.height < fuel) (p : Parameters) (base : ℕ) :
decode fuel (memory p t base) base = t

The explicit serializer and total RAM realization round-trip through the load-based decoder.

Every owned address and the one-past-end allocation frontier fit a word. This strict frontier condition also suffices for the existing WordRAM.alloc execution contract.

theorem Cslib.DataStructure.FusionTree.WordRAM.arenaFits_build_of_bound {B w base : ℕ} (hB : 2 ≤ B) (xs : List ℕ) (hw : WordRAM.Fits w (base + 126 * xs.length + 18)) :
ArenaFits w base (Tree.build B xs)

A numerical sufficient arena contract, using only input length and the allocation base. It bounds the entire one-past-end frontier, rather than only the input key values.

Allocation size, base address and tag one all fit under the arena contract. Together with the fitting frontier, these are the numerical inputs to WordRAM.alloc_exec.

@[irreducible]

Explicit key and preprocessing-word assumptions. Child counts and addresses are instead bounded by ArenaFits; fitting input keys alone does not imply either contract.

Cached child minima fit whenever all explicit tree contents fit.

theorem Cslib.DataStructure.FusionTree.WordRAM.ArenaFits.address {w base a : ℕ} {t : Tree} (ha : ArenaFits w base t) (ho : { base := base, length := span t }.Owns a) :

The fit assumption for the arena bounds every owned access address.

theorem Cslib.DataStructure.FusionTree.WordRAM.ArenaFits.child {w base m : ℕ} {cs : List Tree} (ha : ArenaFits w base (Tree.node m cs)) (i : Fin cs.length) :
ArenaFits w (childAddress base cs ↑i) cs[i]

The child's whole allocation also fits; in particular following its pointer cannot wrap.

theorem Cslib.DataStructure.FusionTree.WordRAM.memory_fits {w base : ℕ} {p : Parameters} {t : Tree} (ha : ArenaFits w base t) (ht : ContentFits w p t) (a : ℕ) :
WordRAM.Fits w (memory p t base a)

The concrete memory consists entirely of fitting words, including its zero exterior.

theorem Cslib.DataStructure.FusionTree.WordRAM.encoding_exists {B w base : ℕ} (hB : 2 ≤ B) (xs : List ℕ) (p : Parameters) (ha : ArenaFits w base (Tree.build B xs)) (ht : ContentFits w p (Tree.build B xs)) :
∃ (mem : ℕ → ℕ), Rep p (Tree.build B xs) base mem ∧ (∀ (a : ℕ), WordRAM.Fits w (mem a)) ∧ decode ((Tree.build B xs).height + 1) mem base = Tree.build B xs ∧ (encode p base (Tree.build B xs)).length ≤ 126 * xs.length + 18

A fitting contiguous encoding exists for every built tree whose explicit address and content assumptions hold. The decoder uses depth fuel; no preprocessing-time claim is made.