Documentation

CslibFrontier.DataStructure.VanEmdeBoas.Predecessor

Strict van Emde Boas predecessor #

This module defines and verifies strict predecessor lookup on recursive minimum-excluded van Emde Boas trees ([CLRS09], Section 20.3, p. 552). [Dem15] gives only Successor (p. 4), which this mirrors. The algorithm returns the greatest represented key strictly less than its query, or none when every represented key is at least the query. Queries need not lie inside [0, universeSize d).

Because each internal node stores its minimum m outside its clusters, predecessor is slightly asymmetric with successor: when m < x ≤ M and neither x's cluster nor any earlier nonempty cluster recorded in summary contains a key below x, predecessor falls back to returning some m in O(1). These are mathematical correctness statements, without a machine cost claim.

Main definitions #

Main results #

References #

The greatest stored key strictly less than the query, or none if it does not exist. The cached cluster minimum chooses between one cluster recursion and one summary recursion; when no cluster entry precedes x > m, the excluded node minimum m is returned ([CLRS09], Section 20.3, p. 552; it mirrors Successor in [Dem15], p. 4).

@[simp]

Predecessor lookup on the empty tree at depth d always returns none.

theorem Cslib.DataStructure.VanEmdeBoas.Tree.predecessor_spec {d : ℕ} {t : Tree d} (ht : t.Valid) (x : ℕ) :
match t.predecessor x with | some y => t.Contains y ∧ y < x ∧ ∀ (z : ℕ), t.Contains z → z < x → z ≤ y | none => ∀ (z : ℕ), t.Contains z → x ≤ z

A returned key is the greatest represented key strictly below the query; failure certifies that every represented key is at least the query. No bound on the query is required.

theorem Cslib.DataStructure.VanEmdeBoas.Tree.predecessor_eq_some_iff {d : ℕ} {t : Tree d} (ht : t.Valid) (x y : ℕ) :
t.predecessor x = some y ↔ t.Contains y ∧ y < x ∧ ∀ (z : ℕ), t.Contains z → z < x → z ≤ y

A successful result is exactly the greatest represented key strictly less than the query.

theorem Cslib.DataStructure.VanEmdeBoas.Tree.predecessor_eq_none_iff {d : ℕ} {t : Tree d} (ht : t.Valid) (x : ℕ) :
t.predecessor x = none ↔ ∀ (z : ℕ), t.Contains z → x ≤ z

Failure is exactly the absence of a represented key strictly below the query.

theorem Cslib.DataStructure.VanEmdeBoas.Tree.predecessor_isSome_of_gt_min {d m M query : ℕ} {tree : Tree d} (ht : tree.Valid) (hb : tree.bounds = some (m, M)) (hq : m < query) :
∃ ans < universeSize d, tree.predecessor query = some ans

A valid node with a query strictly above its cached minimum always has a strict predecessor in [0, universeSize d).