Documentation

Complexity.Algorithms.Lean.FusionTree.Tree

Static multiway predecessor trees #

This is an outer multiway tree for fusion-tree search, independently of node search. Keys occur in leaves; each internal node caches the first key in its subtree. A node search may scan its children linearly. No word-RAM running-time bound is asserted here. Singleton branches are collapsed, so leaves need not all have the same depth.

Main definitions #

Main results #

References #

See [FW93] for fusion trees and their multiway outer search tree.

A multiway tree representation. Well-formed leaves contain at most one key. The empty tree is represented by an empty leaf. Internal nodes store one cached minimum and their child pointers.

Instances For
    @[irreducible]

    Stored leaf keys in left-to-right order, without the cached internal minima.

    Instances For

      Cached subtree minimum, with zero used for an empty leaf.

      Instances For
        @[irreducible]

        Height counts edges, so a leaf has height zero.

        Instances For

          Every child has strictly smaller height than its parent node.

          An indexed child has strictly smaller height than its parent node.

          @[irreducible]

          Structural storage in scalar slots, including the list representation: a leaf has a tag and a list reference; an internal node has a tag, minimum and child-list reference. Each list cell has a tag, an entry and a next link. A key is counted as one scalar, not by its bit length. There is no allocation of B slots at every node.

          Instances For
            @[irreducible]

            Occupancy and cached-minimum invariants. Every non-root child is nonempty.

            Instances For

              Form a node, collapsing groups of zero or one child.

              Instances For

                Split into at most B consecutive nonempty blocks of at most k elements, using Mathlib's List.splitLengths. The caller must ensure that B * k covers the input.

                Instances For

                  Construct a tree of height at most h, for inputs of length at most B ^ h. Singleton child groups are collapsed, including on incomplete rightmost branches.

                  Instances For

                    Construct a static tree. For 2 ≤ B, no input keys are lost, and the height is at most Nat.clog B xs.length. Sorting and distinctness are requirements for ordered search, not for construction or its shape bounds.

                    Instances For
                      theorem Cslib.Algorithms.Lean.FusionTree.Tree.keys_build {B : ℕ} (hB : 2 ≤ B) (xs : List ℕ) :
                      (build B xs).keys = xs

                      Construction preserves the complete input list, including its order.

                      theorem Cslib.Algorithms.Lean.FusionTree.Tree.valid_build {B : ℕ} (hB : 2 ≤ B) (xs : List ℕ) :
                      Valid B (build B xs)

                      Construction supplies the occupancy and cached-minimum invariants.

                      The explicit height bound, uniform in the branching parameter.

                      A logarithmic height bound with a constant independent of the branching parameter.

                      theorem Cslib.Algorithms.Lean.FusionTree.Tree.slots_build_le {B : ℕ} (hB : 2 ≤ B) (xs : List ℕ) :
                      (build B xs).slots ≤ 14 * xs.length + 2

                      Total keys, child pointers, cached minima, node headers and list links use at most 14n+2 scalar slots. The numerical constant is independent of B. This is a structural bound, not a word-RAM heap encoding or a bit-space bound for unbounded natural numbers.

                      Linear semantic node search: select the last child whose cached minimum is at most q. Only the selected subtree is searched recursively.

                      Instances For

                        Any child selected by selectChild belongs to the input child list.

                        Rightmost qualifying key in an input list. For sorted input this is inclusive predecessor.

                        Instances For
                          @[irreducible]

                          Inclusive predecessor by cached-minimum routing, descending into at most one child per node. The linear node scan is explicit and is not charged as a constant-time operation.

                          Instances For

                            In a valid tree, minimum equals the first stored key (or 0 when empty).

                            listPredecessor returns none iff every element of the list exceeds q.

                            theorem Cslib.Algorithms.Lean.FusionTree.Tree.listPredecessor_ne_none_iff {q : ℕ} {xs : List ℕ} (hn : xs ≠ []) (hs : List.Pairwise (fun (x1 x2 : ℕ) => x1 ≤ x2) xs) :
                            theorem Cslib.Algorithms.Lean.FusionTree.Tree.predecessor_eq_listPredecessor {B : ℕ} {t : Tree} (ht : Valid B t) (hs : List.Pairwise (fun (x1 x2 : ℕ) => x1 ≤ x2) t.keys) (q : ℕ) :

                            Cached-minimum routing agrees with rightmost list search on every valid ordered tree.

                            theorem Cslib.Algorithms.Lean.FusionTree.Tree.listPredecessor_some_spec {q p : ℕ} {xs : List ℕ} (hs : List.Pairwise (fun (x1 x2 : ℕ) => x1 ≤ x2) xs) (hp : listPredecessor q xs = some p) :
                            p ∈ xs ∧ p ≤ q ∧ ∀ (x : ℕ), x ∈ xs → x ≤ q → x ≤ p
                            theorem Cslib.Algorithms.Lean.FusionTree.Tree.listPredecessor_eq_some_iff {q p : ℕ} {xs : List ℕ} (hs : List.Pairwise (fun (x1 x2 : ℕ) => x1 ≤ x2) xs) :
                            listPredecessor q xs = some p ↔ p ∈ xs ∧ p ≤ q ∧ ∀ (x : ℕ), x ∈ xs → x ≤ q → x ≤ p

                            The list search returns exactly the greatest stored key not exceeding the query.

                            theorem Cslib.Algorithms.Lean.FusionTree.Tree.predecessor_build_eq_some_iff {B q p : ℕ} (hB : 2 ≤ B) {xs : List ℕ} (hs : List.Pairwise (fun (x1 x2 : ℕ) => x1 < x2) xs) :
                            predecessor q (build B xs) = some p ↔ p ∈ xs ∧ p ≤ q ∧ ∀ (x : ℕ), x ∈ xs → x ≤ q → x ≤ p

                            Inclusive predecessor correctness for every sorted distinct input and every natural query.

                            theorem Cslib.Algorithms.Lean.FusionTree.Tree.predecessor_build_eq_none_iff {B q : ℕ} (hB : 2 ≤ B) {xs : List ℕ} (hs : List.Pairwise (fun (x1 x2 : ℕ) => x1 < x2) xs) :
                            predecessor q (build B xs) = none ↔ ∀ (x : ℕ), x ∈ xs → q < x

                            Empty output is equivalent to having no stored key at or below the query.