Documentation

CslibFrontier.DataStructure.VanEmdeBoas.Impl

Stateful ordered-set realization by recursive van Emde Boas trees #

This module realizes the shared Cslib.DataStructure.OrderedSet.spec (Fin (universeSize d)) interface (contains, insert, delete, minimum, successor) using recursive minimum-excluded van Emde Boas trees Tree d over the bounded universe Fin (universeSize d) of size universeSize d = 2 ^ (2 ^ d), and supplies an active-recursive-call depth certificate callDepthBound of d + 1 per operation ([Dem15], pp. 4–5; [CLRS09], Section 20.3).

Alongside Cslib.DataStructure.SearchTree (linear worst-case bound s.card), this provides a bounded-universe realization of Cslib.DataStructure.OrderedSet.spec with doubly-logarithmic recursion depth d + 1 on bounded integer keys.

Cost model and limitations #

Native operation traces count active recursive van Emde Boas calls (1 at the root plus the active calls of the single recursive subcall, if any, at each internal level; at most d + 1 per operation). In particular:

Main definitions #

Main results #

References #

Every van Emde Boas universe size is nonzero, enabling OfNat (Fin (universeSize d)) numerals for bounded-key clients.

Active recursive calls performed by Tree.minimum (1 root header read).

Active recursive calls performed by Tree.member.

Active recursive calls performed by Tree.insert.

Active recursive calls performed by Tree.erase.

Active recursive calls performed by Tree.successor.

Active recursive calls performed by Tree.predecessor.

minimum performs 1 ≤ d + 1 active calls.

member performs at most d + 1 active recursive calls.

Inserting into an empty node performs only 1 active call at any depth.

insert performs at most d + 1 active recursive calls.

Deleting from a singleton node (bounds = some (m, m)) performs only 1 active call at any depth.

erase performs at most d + 1 active recursive calls.

successor performs at most d + 1 active recursive calls.

predecessor performs at most d + 1 active recursive calls.

Mathematical finite-set observation in Fin (universeSize d).

Membership in finElements agrees with Tree.Contains on valid trees.

Membership in finElements agrees with Tree.elements on x.val.

@[simp]

The empty tree represents the empty finite set of bounded keys.

Bounded insertion commutes with finElements.

Deletion commutes with finElements.

Typed Fin (universeSize d) minimum read from the cached root bounds.

Typed Fin (universeSize d) strict successor query.

Typed Fin (universeSize d) strict predecessor query.

finMinimum satisfies the optional-minimum contract for t.finElements.

finSuccessor satisfies the optional-minimum contract for keys strictly above x.

theorem Cslib.DataStructure.VanEmdeBoas.Tree.finPredecessor_eq_some_iff {d : ℕ} {t : Tree d} (ht : t.Valid) (x y : Fin (universeSize d)) :
t.finPredecessor x = some y ↔ y ∈ t.finElements ∧ y < x ∧ ∀ z ∈ t.finElements, z < x → z ≤ y

A successful finPredecessor returns the greatest element of t.finElements strictly below x.

finPredecessor returns none iff every element of t.finElements is at least x.

Execute a single OrderedSet.Op (Fin (universeSize d)) on t : Tree d, returning the updated tree, result, and active recursive-call count.

@[reducible, inline]

Native execution relation for OrderedSet.spec (Fin (universeSize d)) over Tree d.

Representation relation coupling a finite set s : Finset (Fin (universeSize d)) with a valid van Emde Boas tree t : Tree d.

theorem Cslib.DataStructure.VanEmdeBoas.Rep.valid {d : ℕ} {s : Finset (Fin (universeSize d))} {t : Tree d} (hr : Rep s t) :

Extract Tree.Valid from Rep.

Extract the finElements equality from Rep.

Tree.empty d represents the empty Finset (Fin (universeSize d)).

Semantic realization of OrderedSet.spec (Fin (universeSize d)) by Tree d.

@[simp]

(impl d).rep is definitionally Rep.

theorem Cslib.DataStructure.VanEmdeBoas.exec_visits_le {d : ℕ} {t t' : Tree d} {o : OrderedSet.Op (Fin (universeSize d))} {a : (OrderedSet.spec (Fin (universeSize d))).Result o} {n : ℕ} (he : Exec d t o a t' n) :
n ≤ d + 1

Every native OrderedSet operation on Tree d performs at most d + 1 active recursive calls.

Uniform d + 1 active-call depth bound (O(log log U) since universeSize d = 2 ^ (2 ^ d)) for VanEmdeBoas.impl d.

theorem Cslib.DataStructure.VanEmdeBoas.realized_client {d : ℕ} {β : Type} (p : (OrderedSet.spec (Fin (universeSize d))).Client β) {s : Finset (Fin (universeSize d))} {t : Tree d} (hr : Rep s t) :
match (OrderedSet.spec (Fin (universeSize d))).runClient s p with | (value, finalState, history) => ∃ (t' : Tree d) (ns : List ℕ), Executes (Exec d) p t value t' ns ∧ Rep finalState t' ∧ total id ns ≤ history.length * (d + 1)

Every adaptive OrderedSet client over Fin (universeSize d) executes on Tree d with finite-set correctness and total active recursive calls at most history.length * (d + 1).

@[reducible, inline]

Execute an OrderedSet client concretely on Tree d, recording active recursive-call counts per operation.

theorem Cslib.DataStructure.VanEmdeBoas.run_correct {d : ℕ} {β : Type} (p : (OrderedSet.spec (Fin (universeSize d))).Client β) {s : Finset (Fin (universeSize d))} {t : Tree d} (hr : Rep s t) :
match (OrderedSet.spec (Fin (universeSize d))).runClient s p with | (value, finalState, history) => (run t p).value = value ∧ Rep finalState (run t p).state ∧ total id (run t p).traces ≤ history.length * (d + 1)

Running the concrete vEB interpreter agrees with abstract Finset (Fin (universeSize d)) semantics, preserves Rep, and satisfies the history.length * (d + 1) active-call bound.