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 #
Tree: a fully allocated recursive shape, with a two-key base universe.Tree.bounds,Tree.minimum,Tree.maximum,Tree.withBounds: cached local extrema and header update.Tree.empty,Tree.insert,Tree.member,Tree.successor: set operations.Tree.Contains: mathematical interpretation of the stored keys.Tree.Extrema,Tree.Valid: local extrema specification and recursive tree invariant.
References #
The extrema use one shared presence bit. A present pair stores minimum and maximum.
The fully allocated empty tree. Allocation cost is not measured in this Lean definition.
The local extrema correctly describe a bounded set of keys.
Recursive invariant: bounded extrema, valid children and summary, exact summary occupancy, and strict exclusion of the local minimum from every cluster.
The representation invariant has a concrete instance at every depth.
Stored keys lie in the advertised bounded universe.
Conversely, comparing two keys compares their clusters first, then their low parts: if
i * u + a < j * u + b with b < u, then cluster i precedes cluster j, or they coincide and
a < b. Predecessor and successor queries use this to locate the answer's cluster.