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.chunks_mem {B k : ℕ} {xs ys : List ℕ} (h : ys ∈ chunks B k xs) :
                      ys ≠ [] ∧ ys.length ≤ k
                      theorem Cslib.Algorithms.Lean.FusionTree.Tree.valid_join {B : ℕ} {cs : List Tree} (hl : cs.length ≤ B) (hc : ∀ (t : Tree), t ∈ cs → Valid B t ∧ t.keys ≠ []) :
                      Valid B (join cs)
                      theorem Cslib.Algorithms.Lean.FusionTree.Tree.height_join_le {cs : List Tree} {h : ℕ} (hc : ∀ (t : Tree), t ∈ cs → t.height ≤ h) :
                      (join cs).height ≤ h + 1
                      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.

                      Nonempty valid trees have storage bounded uniformly in their maximum node capacity.

                      Empty valid trees are empty leaves, with a tag and a reference to the empty list.

                      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

                        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
                            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.