Documentation

Complexity.Algorithms.Lean.VanEmdeBoas.Basic

Recursive van Emde Boas sets #

The universe at depth d is [0, 2 ^ (2 ^ d)). Each internal node stores its minimum outside its clusters, caches its maximum, and records nonempty clusters in a recursive summary. This is the recursive variant presented in Demaine's lecture notes, not the stratified-tree implementation of van Emde Boas, Kaas and Zijlstra. The lecture notes credit Michael Bender for a 2001 personal communication.

The functions here are Lean algorithms. Immutable function updates, pattern matching and recursive calls have no certified machine cost. The separate word-RAM realization must charge instructions, initialization and memory before any machine running-time claim is made.

Main definitions #

References #

The extrema use one shared presence bit. A present pair stores minimum and maximum.

Instances For

    Cached extrema; none denotes an empty node.

    Instances For

      Cached minimum, without a search through clusters.

      Instances For

        Cached maximum, without a search through clusters.

        Instances For

          Change only the local extrema. A caller must justify the children and summary invariant.

          Instances For

            The fully allocated empty tree. Allocation cost is not measured in this Lean definition.

            Instances For

              Set membership. On valid trees, arguments outside the universe are rejected.

              Instances For

                Insert a bounded key. Repeated insertion of the local minimum does no recursive work. For an empty cluster, its first element is installed directly and only the summary recurses.

                Instances For

                  The least stored key strictly greater than the query, or none if it does not exist. The cached maximum chooses between one cluster recursion and one summary recursion.

                  Instances For

                    Mathematical interpretation. The minimum is absent from the cluster interpretation.

                    Instances For

                      The local extrema correctly describe a bounded set of keys.

                      Instances For

                        Recursive invariant: bounded extrema, valid children and summary, exact summary occupancy, and strict exclusion of the local minimum from every cluster.

                        Instances For

                          The representation invariant has a concrete instance at every depth.

                          Every valid tree has correctly bounded extrema.

                          Stored keys lie in the advertised bounded universe.

                          An empty local header has no represented elements.

                          An occupied valid node has a represented cached minimum.

                          An occupied valid node has a represented cached maximum.

                          theorem Cslib.Algorithms.Lean.VanEmdeBoas.Tree.cluster_coordinates {u i y : ℕ} (hu : 0 < u) (hy : y < u) :
                          (i * u + y) / u = i ∧ (i * u + y) % u = y

                          Division and remainder recover a cluster's coordinates for bounded low parts.

                          Boolean lookup agrees with the mathematical interpretation of every valid tree.