Documentation

Complexity.Algorithms.WordRAM.FusionTree.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. 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.

Instances For

    Fixed record header length, independent of branching capacity.

    Instances For

      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.

      Instances For

        Number of actual children (presence for a leaf).

        Instances For

          Cached minimum (the key for a leaf).

          Instances For

            Maximum compressed payload.

            Instances For

              Width-dependent global offset.

              Instances For

                Reserved preprocessing word.

                Instances For
                  @[irreducible]

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

                  Instances For

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

                    Instances For

                      The concrete internal header.

                      Instances For

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

                        Instances For

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

                          Instances For

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

                            Instances For

                              Every serialized tree occupies exactly its claimed span.

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

                              @[reducible, inline]
                              abbrev Cslib.Algorithms.WordRAM.FusionTree.Stores (xs : List ℕ) (base : ℕ) (mem : ℕ → ℕ) :

                              Actual RAM contents of a contiguous list, using the existing allocation API.

                              Instances For

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

                                Instances For

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

                                  Instances For
                                    theorem Cslib.Algorithms.WordRAM.FusionTree.arena_holds (p : Parameters) (t : Lean.FusionTree.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.Algorithms.WordRAM.FusionTree.arena_footprint (p : Parameters) (t : Lean.FusionTree.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.Algorithms.WordRAM.FusionTree.Rep.frame {p : Parameters} {t : Lean.FusionTree.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.

                                    Instances For

                                      The explicit list encoding has an actual RAM realization.

                                      theorem Cslib.Algorithms.WordRAM.FusionTree.Rep.node_parts {p : Parameters} {m base : ℕ} {cs : List Lean.FusionTree.Tree} {mem : ℕ → ℕ} (hr : Rep p (Lean.FusionTree.Tree.node m cs) base mem) :
                                      Stores (header p m cs) base mem ∧ Stores (childTable base cs) (base + headerWords) mem ∧ Stores (encodeForest p (base + headerWords + 2 * cs.length) cs) (base + headerWords + 2 * cs.length) mem

                                      A represented internal node exposes its header, minima, pointers and child-record interval.

                                      theorem Cslib.Algorithms.WordRAM.FusionTree.Rep.node_header {p : Parameters} {m base : ℕ} {cs : List Lean.FusionTree.Tree} {mem : ℕ → ℕ} (hr : Rep p (Lean.FusionTree.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 (Lean.FusionTree.Tree.node m cs) j

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

                                      theorem Cslib.Algorithms.WordRAM.FusionTree.Rep.leaf_fields {p : Parameters} {base : ℕ} {xs : List ℕ} {mem : ℕ → ℕ} (hr : Rep p (Lean.FusionTree.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.Algorithms.WordRAM.FusionTree.Rep.child {p : Parameters} {m base : ℕ} {cs : List Lean.FusionTree.Tree} {mem : ℕ → ℕ} (hr : Rep p (Lean.FusionTree.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.

                                      Every record is nonempty, including the empty leaf.

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

                                      theorem Cslib.Algorithms.WordRAM.FusionTree.access_owned (base : ℕ) (t : Lean.FusionTree.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.Algorithms.WordRAM.FusionTree.node_access_owned (base m : ℕ) (cs : List Lean.FusionTree.Tree) (a : ℕ) (ha : a < headerWords + 2 * cs.length) :
                                      { base := base, length := span (Lean.FusionTree.Tree.node m cs) }.Owns (base + a)

                                      Every direct header/table read is an owned parent word. Tables use their actual lengths.

                                      theorem Cslib.Algorithms.WordRAM.FusionTree.header_access_owned (base : ℕ) (t : Lean.FusionTree.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.Algorithms.WordRAM.FusionTree.child_entry_access_owned (base m : ℕ) (cs : List Lean.FusionTree.Tree) (i : Fin cs.length) :
                                      { base := base, length := span (Lean.FusionTree.Tree.node m cs) }.Owns (base + headerWords + 2 * ↑i) ∧ { base := base, length := span (Lean.FusionTree.Tree.node m cs) }.Owns (base + headerWords + (2 * ↑i + 1))

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

                                      theorem Cslib.Algorithms.WordRAM.FusionTree.child_access_owned (base m : ℕ) (cs : List Lean.FusionTree.Tree) (i : Fin cs.length) (a : ℕ) (ha : a < span cs[i]) :
                                      { base := base, length := span (Lean.FusionTree.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.

                                      The concrete allocation is at most nine times the structural scalar-slot count.

                                      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.

                                      Instances For
                                        theorem Cslib.Algorithms.WordRAM.FusionTree.decode_rep {B fuel base : ℕ} {p : Parameters} {t : Lean.FusionTree.Tree} {mem : ℕ → ℕ} (ht : Lean.FusionTree.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.Algorithms.WordRAM.FusionTree.decode_encode {B fuel : ℕ} {t : Lean.FusionTree.Tree} (ht : Lean.FusionTree.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.

                                        Instances For
                                          theorem Cslib.Algorithms.WordRAM.FusionTree.arenaFits_build_of_bound {B w base : ℕ} (hB : 2 ≤ B) (xs : List ℕ) (hw : WordRAM.Fits w (base + 126 * xs.length + 18)) :

                                          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.

                                          Instances For

                                            Cached child minima fit whenever all explicit tree contents fit.

                                            theorem Cslib.Algorithms.WordRAM.FusionTree.ArenaFits.address {w base a : ℕ} {t : Lean.FusionTree.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.

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

                                            theorem Cslib.Algorithms.WordRAM.FusionTree.encode_fits {w : ℕ} {p : Parameters} (t : Lean.FusionTree.Tree) (base : ℕ) :
                                            ArenaFits w base t → ContentFits w p t → ∀ v ∈ encode p base t, WordRAM.Fits w v

                                            Every serialized data word fits under explicit content and arena assumptions.

                                            theorem Cslib.Algorithms.WordRAM.FusionTree.memory_fits {w base : ℕ} {p : Parameters} {t : Lean.FusionTree.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.Algorithms.WordRAM.FusionTree.encoding_exists {B w base : ℕ} (hB : 2 ≤ B) (xs : List ℕ) (p : Parameters) (ha : ArenaFits w base (Lean.FusionTree.Tree.build B xs)) (ht : ContentFits w p (Lean.FusionTree.Tree.build B xs)) :
                                            ∃ (mem : ℕ → ℕ), Rep p (Lean.FusionTree.Tree.build B xs) base mem ∧ (∀ (a : ℕ), WordRAM.Fits w (mem a)) ∧ decode ((Lean.FusionTree.Tree.build B xs).height + 1) mem base = Lean.FusionTree.Tree.build B xs ∧ (encode p base (Lean.FusionTree.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.