Documentation

CslibFrontier.DataStructure.Dictionary.UniformProbing

Uniform Probing in Open-Addressed Hash Tables #

This file formalizes the classical uniform-probing model of open-addressed hashing from Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms, third edition (MIT Press, 2009), Section 11.4 ("Open addressing", pp. 269–277), realizing the bounded-capacity insert-only dictionary specification Cslib.DataStructure.Dictionary.spec over m table slots (2 * n_max ≤ m).

In the textbook uniform-probing ("uniform hashing") model, each key u : Fin U is assigned an independent uniform random permutation π u : Equiv.Perm (Fin m) (PMF.uniformOfFintype (Fin U → Equiv.Perm (Fin m))), which may equivalently be sampled lazily on demand via Cslib.RandomOracle.uniform_interpret_eq_lazy (CslibFrontier/Languages/Probabilistic/RandomOracle.lean).

Source statements and notation mapping #

In [CLRS09], third edition, Section 11.4:

Main definitions #

Main results #

Representation space note #

Storing an explicit table of independent permutations in (Equiv.Perm (Fin m)) ^ U requires U * log₂ (m!) bits (Ω(U) machine words when U = poly(n_max) ≫ n_max). To achieve an O(n_max)-word self-contained Word-RAM dictionary, CslibFrontier/DataStructure/Dictionary/WordRAM/UniformProbing.lean pairs a Double Tabulation primary hash h₁(u) ∈ Fin (2 ^ M) with a Double Tabulation stride index h₂(u) ∈ Fin (2 ^ (M - 1)), probing with the odd stride 2 * h₂(u) + 1 ([CLRS09], third edition, Section 11.4, "Double hashing", pp. 272–274), reusing the open-addressed table invariants proved here.

References #

Section 1: Permutation probe counts and stopping indices #

Event that the first k slots σ ⟨0, _⟩, ..., σ ⟨k - 1, _⟩ of permutation σ all belong to the occupied slot set O.

Instances For
    theorem Cslib.DataStructure.Dictionary.UniformProbing.allOccupied_succ_iff {m : ℕ} {O : Finset (Fin m)} {k : ℕ} (hk : k < m) (σ : Equiv.Perm (Fin m)) :
    allOccupied O (k + 1) σ ↔ allOccupied O k σ ∧ σ ⟨k, hk⟩ ∈ O
    theorem Cslib.DataStructure.Dictionary.UniformProbing.allOccupied_mono {m : ℕ} {O : Finset (Fin m)} {j k : ℕ} (hjk : j ≤ k) {σ : Equiv.Perm (Fin m)} (h : allOccupied O k σ) :

    Count how many consecutive slots σ ⟨idx, _⟩, σ ⟨idx + 1, _⟩, ... belong to O, for up to rem steps starting at idx.

    Number of consecutive probes σ 0, σ 1, ... that hit O before the first slot outside O.

    Total number of slot probes 1 + missedProbes O σ made by an unsuccessful search (or fresh-key insertion) against occupied slot set O along permutation σ.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.mem_of_lt_missedProbesFrom {m : ℕ} {O : Finset (Fin m)} {σ : Equiv.Perm (Fin m)} {rem idx t : ℕ} (hrem : idx + rem ≤ m) (ht : t < missedProbesFrom O σ rem idx) :
    ∃ (h : idx + t < m), σ ⟨idx + t, h⟩ ∈ O
    theorem Cslib.DataStructure.Dictionary.UniformProbing.notMem_at_missedProbesFrom {m : ℕ} {O : Finset (Fin m)} {σ : Equiv.Perm (Fin m)} {rem idx : ℕ} (hrem : idx + rem ≤ m) (hlt : missedProbesFrom O σ rem idx < rem) :
    ∃ (h : idx + missedProbesFrom O σ rem idx < m), σ ⟨idx + missedProbesFrom O σ rem idx, h⟩ ∉ O

    For any k ≤ m, at least k probes miss (k ≤ missedProbes O σ) if and only if the first k slots of σ all belong to O.

    For any k ≤ m, an unsuccessful search inspects more than k slots (k < unsuccessfulProbes O σ) if and only if the first k slots of σ all belong to O.

    When O.card < m, not all m slots of σ can belong to O.

    When O.card < m, missedProbes O σ < m for every permutation σ.

    The probe index ⟨missedProbes O σ, _⟩ : Fin m of the first slot along σ outside O when O.card < m.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.mem_of_lt_probeSlotIndex {m : ℕ} {O : Finset (Fin m)} {σ : Equiv.Perm (Fin m)} (hO : O.card < m) {i : Fin m} (hi : ↑i < ↑(probeSlotIndex O σ hO)) :
    σ i ∈ O
    theorem Cslib.DataStructure.Dictionary.UniformProbing.missedProbes_eq_iff {m : ℕ} {O : Finset (Fin m)} {σ : Equiv.Perm (Fin m)} (i₀ : Fin m) :
    missedProbes O σ = ↑i₀ ↔ allOccupied O (↑i₀) σ ∧ σ i₀ ∉ O

    Exact characterization of missedProbes O σ: for any i₀ : Fin m, missedProbes O σ = i₀.val if and only if all earlier probes i < i₀ lie in O and σ i₀ ∉ O.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.probeSlotIndex_eq_iff {m : ℕ} {O : Finset (Fin m)} {σ : Equiv.Perm (Fin m)} (hO : O.card < m) (i₀ : Fin m) :
    probeSlotIndex O σ hO = i₀ ↔ allOccupied O (↑i₀) σ ∧ σ i₀ ∉ O

    Tail-sum identity on Fin m: when O.card < m, the total number of probes unsuccessfulProbes O σ equals the number of k ∈ Finset.range m for which allOccupied O k σ holds.

    Section 2: Textbook Uniform-Probing Expected-Probe Bounds ([CLRS09], Theorem 11.6) #

    Set of permutations σ : Equiv.Perm (Fin m) whose first k probes all belong to O.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.mul_card_occPermSet_succ {m : ℕ} (O : Finset (Fin m)) {k : ℕ} (hk : k < m) :
    (m - k) * (occPermSet O (k + 1)).card = (O.card - k) * (occPermSet O k).card

    Exact step recurrence for occPermSet: for any k < m, (m - k) * (occPermSet O (k + 1)).card = (O.card - k) * (occPermSet O k).card.

    Exact textbook product formula ([CLRS09], Proof of Theorem 11.6): for any occupied slot set O : Finset (Fin m) and k ≤ m, the probability over a uniform random permutation σ ← PMF.uniformOfFintype (Equiv.Perm (Fin m)) that the first k probes all hit O (k < unsuccessfulProbes O σ) is ∏ i ∈ Finset.range k, ((O.card - i : ℝ≥0∞) / (m - i : ℝ≥0∞)).

    theorem Cslib.DataStructure.Dictionary.UniformProbing.sub_div_sub_le_div {n m i : ℕ} (hnm : n ≤ m) (hi : i < m) :
    ↑(n - i) / ↑(m - i) ≤ ↑n / ↑m

    Each factor (n - i) / (m - i) for i < m and n ≤ m is at most n / m.

    Upper bound (n / m) ^ k on the k-probe tail probability ([CLRS09], Proof of Theorem 11.6): for any occupied slot set O : Finset (Fin m) and k ≤ m, the probability over a uniform random permutation σ that the first k probes all hit O is at most ((O.card : ℝ≥0∞) / (m : ℝ≥0∞)) ^ k.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.sum_div_pow_add_tail {n m : ℕ} (hnm : n < m) (j : ℕ) :
    ∑ k ∈ Finset.range j, (↑n / ↑m) ^ k + ↑m / ↑(m - n) * (↑n / ↑m) ^ j = ↑m / ↑(m - n)

    Finite geometric sum identity in ℝ≥0∞ without subtraction: for n < m, ∑ k ∈ Finset.range j, (n / m) ^ k + (m / (m - n)) * (n / m) ^ j = m / (m - n).

    theorem Cslib.DataStructure.Dictionary.UniformProbing.sum_div_pow_le {n m : ℕ} (hnm : n < m) (j : ℕ) :
    ∑ k ∈ Finset.range j, (↑n / ↑m) ^ k ≤ ↑m / ↑(m - n)

    For n < m, any partial geometric sum ∑ k ∈ Finset.range j, (n / m) ^ k is at most m / (m - n).

    theorem Cslib.DataStructure.Dictionary.UniformProbing.div_sub_le_two {n m : ℕ} (hm : 0 < m) (h2n : 2 * n ≤ m) :
    ↑m / ↑(m - n) ≤ 2

    When 2 * n ≤ m and 0 < m, m / (m - n) ≤ 2 (1 / (1 - α) ≤ 2 for load factor α ≤ 1 / 2).

    Theorem 11.6 of [CLRS09] (Expected probes in an unsuccessful search): for any occupied slot set O : Finset (Fin m) with O.card < m, the expected number of probes unsuccessfulProbes O σ over a uniform random permutation σ ← PMF.uniformOfFintype (Equiv.Perm (Fin m)) is at most m / (m - O.card).

    Half-load corollary of Theorem 11.6 ([CLRS09], Section 11.4): when 0 < m and 2 * O.card ≤ m (load factor α = O.card / m ≤ 1 / 2), the expected number of probes in an unsuccessful search is at most 2.

    Section 3: Open-Addressed Table Model ([CLRS09], Section 11.4, pp. 269–276) #

    @[reducible, inline]

    Pure open-addressed hash table of m slots over key universe Fin U, where each slot holds none (empty) or some (u, v) (occupied by key u with value v).

    The initially empty table of m slots.

    The finite set of currently occupied slot indices in table T.

    The finite set of slot indices in T occupied by keys distinct from u.

    Total number of slot probes 1 + missedProbes (otherOccupiedSlots T u) σ made when probing table T for key u along permutation σ.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.mem_otherOccupiedSlots_iff {U m : ℕ} {T : Table U m} {u : Fin U} {j : Fin m} :
    j ∈ otherOccupiedSlots T u ↔ ∃ (u' : Fin U) (v' : ℕ), T j = some (u', v') ∧ u' ≠ u
    structure Cslib.DataStructure.Dictionary.UniformProbing.TableRep {U m : ℕ} (π : Fin U → Equiv.Perm (Fin m)) (s : State U) (T : Table U m) :

    Open-addressed table representation invariant linking concrete slot array T : Table U m to abstract dictionary state s : Dictionary.State U under permutation family π : Fin U → Equiv.Perm (Fin m).

    The empty table represents Dictionary.empty U under any permutation family π.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.TableRep.slot_eq_of_same_key {U m : ℕ} {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) {j₁ j₂ : Fin m} {u : Fin U} {v₁ v₂ : ℕ} (h₁ : T j₁ = some (u, v₁)) (h₂ : T j₂ = some (u, v₂)) :
    j₁ = j₂

    Under TableRep π s T, each key u occupies at most one slot in T.

    Under TableRep π s T, the number of occupied slots in T equals (Dictionary.dom s).card.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.TableRep.card_otherOccupiedSlots {U m : ℕ} {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (u : Fin U) :

    Under TableRep π s T, (otherOccupiedSlots T u).card = ((Dictionary.dom s).erase u).card.

    Under TableRep π s T, (otherOccupiedSlots T u).card ≤ (Dictionary.dom s).card.

    When s u = none, no slot in T holds key u, so otherOccupiedSlots T u = occupiedSlots T.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.TableRep.missedProbes_lt {U m : ℕ} {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (hcard : (dom s).card < m) (u : Fin U) :

    When TableRep π s T and (Dictionary.dom s).card < m, the stopping index for any key u satisfies missedProbes (otherOccupiedSlots T u) (π u) < m.

    def Cslib.DataStructure.Dictionary.UniformProbing.targetSlot {U m : ℕ} (π : Fin U → Equiv.Perm (Fin m)) (T : Table U m) (u : Fin U) (hO : (otherOccupiedSlots T u).card < m) :
    Fin m

    Target slot π u ⟨missedProbes (otherOccupiedSlots T u) (π u), _⟩ where key u is found or inserted when (otherOccupiedSlots T u).card < m.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.TableRep.apply_targetSlot {U m : ℕ} {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (u : Fin U) (hO : (otherOccupiedSlots T u).card < m) :
    T (targetSlot π T u hO) = Option.map (fun (v : ℕ) => (u, v)) (s u)

    Under TableRep π s T and hO : (otherOccupiedSlots T u).card < m, T (targetSlot π T u hO) equals (s u).map (fun v => (u, v)).

    def Cslib.DataStructure.Dictionary.UniformProbing.tableQuery {U m : ℕ} (hm : 0 < m) (π : Fin U → Equiv.Perm (Fin m)) (T : Table U m) (u : Fin U) :

    Pure open-addressed lookup tableQuery hm π T u when 0 < m: inspects slot π u ⟨min (missedProbes (otherOccupiedSlots T u) (π u)) (m - 1), _⟩ and returns some v if it contains (u, v), else none.

    def Cslib.DataStructure.Dictionary.UniformProbing.tableInsert {U m : ℕ} (hm : 0 < m) (π : Fin U → Equiv.Perm (Fin m)) (T : Table U m) (u : Fin U) (v : ℕ) :
    Table U m

    Pure open-addressed insertion tableInsert hm π T u v: writes some (u, v) at slot π u ⟨min (missedProbes (otherOccupiedSlots T u) (π u)) (m - 1), _⟩.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.tableInsert_eq_update_targetSlot {U m : ℕ} (hm : 0 < m) (π : Fin U → Equiv.Perm (Fin m)) (T : Table U m) (u : Fin U) (v : ℕ) (hO : (otherOccupiedSlots T u).card < m) :
    tableInsert hm π T u v = Function.update T (targetSlot π T u hO) (some (u, v))
    theorem Cslib.DataStructure.Dictionary.UniformProbing.TableRep.tableQuery_eq {U m : ℕ} (hm : 0 < m) {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (u : Fin U) (hO : (otherOccupiedSlots T u).card < m) :
    tableQuery hm π T u = s u

    Under TableRep π s T and (otherOccupiedSlots T u).card < m, tableQuery hm π T u = s u.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.otherOccupiedSlots_tableInsert_self {U m : ℕ} (hm : 0 < m) {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (_hrep : TableRep π s T) (u : Fin U) (v : ℕ) (hO : (otherOccupiedSlots T u).card < m) :

    Inserting (u, v) leaves otherOccupiedSlots for u itself unchanged.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.TableRep.missedProbes_tableInsert_of_isSome {U m : ℕ} (hm : 0 < m) {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (u : Fin U) (v : ℕ) (hO : (otherOccupiedSlots T u).card < m) {w : Fin U} (hw : (s w).isSome = true) :

    Inserting (u, v) preserves the stopping index missedProbes (otherOccupiedSlots · w) (π w) for every key w already present in s ((s w).isSome).

    theorem Cslib.DataStructure.Dictionary.UniformProbing.TableRep.tableInsert {U m : ℕ} (hm : 0 < m) {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (u : Fin U) (v : ℕ) (hO : (otherOccupiedSlots T u).card < m) :

    Preservation of TableRep under tableInsert: if TableRep π s T and (otherOccupiedSlots T u).card < m, then tableInsert hm π T u v satisfies TableRep π (Function.update s u (some v)).

    theorem Cslib.DataStructure.Dictionary.UniformProbing.TableRep.probeCount_tableInsert_self {U m : ℕ} (hm : 0 < m) {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (u : Fin U) (v : ℕ) (hO : (otherOccupiedSlots T u).card < m) :
    probeCount (UniformProbing.tableInsert hm π T u v) u (π u) = probeCount T u (π u)

    Inserting (u, v) leaves probeCount · u (π u) unchanged.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.TableRep.probeCount_tableInsert_of_isSome {U m : ℕ} (hm : 0 < m) {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (u : Fin U) (v : ℕ) (hO : (otherOccupiedSlots T u).card < m) {w : Fin U} (hw : (s w).isSome = true) :
    probeCount (UniformProbing.tableInsert hm π T u v) w (π w) = probeCount T w (π w)

    Probe invariance for present keys ([CLRS09], proof of Theorem 11.8, p. 276): once a key w is present in s ((s w).isSome), inserting or updating any key (u, v) leaves the number of probes probeCount · w (π w) made when searching for w unchanged.

    def Cslib.DataStructure.Dictionary.UniformProbing.tableStep {U m : ℕ} (hm : 0 < m) (π : Fin U → Equiv.Perm (Fin m)) (T : Table U m) (o : Op U) :
    Table U m × (spec U 0 0).Result o

    Execute a single Dictionary.Op U on open-addressed table T.

    def Cslib.DataStructure.Dictionary.UniformProbing.runTableFrom {U m : ℕ} (hm : 0 < m) (π : Fin U → Equiv.Perm (Fin m)) :
    Table U m → List (Op U) → Table U m

    Execute a sequence of Dictionary.Op U operations on T under permutation family π.

    def Cslib.DataStructure.Dictionary.UniformProbing.runTable {U m : ℕ} (hm : 0 < m) (π : Fin U → Equiv.Perm (Fin m)) (ops : List (Op U)) :
    Table U m

    Table produced by running ops starting from emptyTable U m.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.TableRep.card_otherOccupiedSlots_lt_of_valid {U V n_max m : ℕ} (_hm : 0 < m) (hcap : n_max ≤ m) {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (hs : (dom s).card ≤ n_max) {u : Fin U} {v : ℕ} (hval : (spec U V n_max).valid s (Op.insert u v)) :

    Under an admissible insertion (Dictionary.spec U V n_max).valid s (.insert u v) with n_max ≤ m, TableRep π s T and (Dictionary.dom s).card ≤ n_max, (otherOccupiedSlots T u).card < m holds for the inserted key u.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.tableRep_runTableFrom {U V n_max m : ℕ} (hm : 0 < m) (hcap : n_max ≤ m) (π : Fin U → Equiv.Perm (Fin m)) {s : State U} {T : Table U m} (hrep : TableRep π s T) (hs : (dom s).card ≤ n_max) {ops : List (Op U)} (hvh : (spec U V n_max).ValidHistory s ops) :
    TableRep π ((spec U V n_max).run s ops).1 (runTableFrom hm π T ops)

    Any valid operation history preserves TableRep.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.tableRep_runTable {U V n_max m : ℕ} (hm : 0 < m) (hcap : n_max ≤ m) (π : Fin U → Equiv.Perm (Fin m)) {ops : List (Op U)} (hvh : (spec U V n_max).ValidHistory (empty U) ops) :
    TableRep π ((spec U V n_max).run (empty U) ops).1 (runTable hm π ops)

    Running any valid operation history from emptyTable U m produces a table satisfying TableRep.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.probeCount_runTableFrom_of_isSome {U V n_max m : ℕ} (hm : 0 < m) (hcap : n_max ≤ m) (π : Fin U → Equiv.Perm (Fin m)) {s : State U} {T : Table U m} (hrep : TableRep π s T) (hs : (dom s).card ≤ n_max) {w : Fin U} (hw : (s w).isSome = true) {ops : List (Op U)} (hvh : (spec U V n_max).ValidHistory s ops) :
    probeCount (runTableFrom hm π T ops) w (π w) = probeCount T w (π w)

    If key w is already present in s, then running any valid continuation ops from (s, T) preserves probeCount · w (π w).

    theorem Cslib.DataStructure.Dictionary.UniformProbing.validHistory_and_runTableFrom_append {U V n_max m : ℕ} (hm : 0 < m) (π : Fin U → Equiv.Perm (Fin m)) {l₁ l₂ : List (Op U)} {s : State U} (T : Table U m) :
    (spec U V n_max).ValidHistory s (l₁ ++ l₂) → (spec U V n_max).ValidHistory s l₁ ∧ (spec U V n_max).ValidHistory ((spec U V n_max).run s l₁).1 l₂ ∧ runTableFrom hm π T (l₁ ++ l₂) = runTableFrom hm π (runTableFrom hm π T l₁) l₂

    Prefix + suffix decomposition for ValidHistory and runTableFrom.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.probeCount_runTable_eq_firstInsert {U V n_max m : ℕ} (hm : 0 < m) (hcap : n_max ≤ m) (π : Fin U → Equiv.Perm (Fin m)) {ops₁ ops₂ : List (Op U)} {u : Fin U} {v₀ : ℕ} (hvh : (spec U V n_max).ValidHistory (empty U) (ops₁ ++ Op.insert u v₀ :: ops₂)) :
    probeCount (runTable hm π (ops₁ ++ Op.insert u v₀ :: ops₂)) u (π u) = probeCount (runTable hm π ops₁) u (π u)

    Pathwise insertion-cost identity from the proof of Theorem 11.8 of [CLRS09], third edition, p. 276 (probeCount_runTable_eq_firstInsert): if ops = ops₁ ++ (.insert u v₀ :: ops₂) is a valid operation history where ops₁ is the prefix before u is inserted (((Dictionary.spec U V n_max).run (Dictionary.empty U) ops₁).1 u = none), then the number of probes made when searching for u after the entire history ops equals the number of probes made when u was first inserted after ops₁.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.runTableFrom_update_eq {U m : ℕ} (hm : 0 < m) (π : Fin U → Equiv.Perm (Fin m)) (u : Fin U) (σ : Equiv.Perm (Fin m)) (T : Table U m) {ops : List (Op U)} :
    (∀ (v : ℕ), Op.insert u v ∉ ops) → runTableFrom hm (Function.update π u σ) T ops = runTableFrom hm π T ops

    If key u is never inserted during ops (∀ v, .insert u v ∉ ops), then runTableFrom is independent of π u: updating π at u leaves the resulting table unchanged.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.not_mem_insert_of_run_eq_none {U V n_max : ℕ} {u : Fin U} {ops : List (Op U)} {s : State U} :
    ((spec U V n_max).run s ops).1 u = none → ∀ (v : ℕ), Op.insert u v ∉ ops

    If ((Dictionary.spec U V n_max).run s ops).1 u = none, then no .insert u v appears in ops.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.expect_probeCount_of_eq_none_le {U V n_max m : ℕ} (hm : 0 < m) (hcap : n_max ≤ m) {ops : List (Op U)} (hvh : (spec U V n_max).ValidHistory (empty U) ops) {u : Fin U} (hu : ((spec U V n_max).run (empty U) ops).1 u = none) (hcard : (dom ((spec U V n_max).run (empty U) ops).1).card < m) :
    have s := ((spec U V n_max).run (empty U) ops).1; ∑' (π : Fin U → Equiv.Perm (Fin m)), (Probability.PMF.uniformOfFintype (Fin U → Equiv.Perm (Fin m))) π * ↑(probeCount (runTable hm π ops) u (π u)) ≤ ↑m / ↑(m - (dom s).card)

    Theorem 11.6 (pp. 274–275) & Corollary 11.7 (p. 275) of [CLRS09], third edition, over PMF.uniformOfFintype: for any valid operation history ops reaching state s with (Dictionary.dom s).card < m and any absent key u (s u = none), the expected number of probes made by an unsuccessful lookup query u or fresh-key insertion insert u v on runTable hm π ops over π ← PMF.uniformOfFintype (Fin U → Equiv.Perm (Fin m)) is at most m / (m - (Dictionary.dom s).card) (≤ 2 when 2 * (Dictionary.dom s).card ≤ m).

    theorem Cslib.DataStructure.Dictionary.UniformProbing.expect_probeCount_of_eq_none_le_two {U V n_max m : ℕ} (hm : 0 < m) (h2cap : 2 * n_max ≤ m) {ops : List (Op U)} (hvh : (spec U V n_max).ValidHistory (empty U) ops) {u : Fin U} (hu : ((spec U V n_max).run (empty U) ops).1 u = none) :
    ∑' (π : Fin U → Equiv.Perm (Fin m)), (Probability.PMF.uniformOfFintype (Fin U → Equiv.Perm (Fin m))) π * ↑(probeCount (runTable hm π ops) u (π u)) ≤ 2

    Half-load corollary of Theorem 11.6 & Corollary 11.7 ([CLRS09], third edition, Section 11.4, pp. 274–276): when 2 * n_max ≤ m, any unsuccessful lookup or fresh-key insertion after a valid history ops makes at most 2 probes in expectation over π ← PMF.uniformOfFintype (Fin U → Equiv.Perm (Fin m)).

    theorem Cslib.DataStructure.Dictionary.UniformProbing.expect_probeCount_of_mem_dom_le {U V n_max m : ℕ} (hm : 0 < m) (hcap : n_max ≤ m) {ops₁ ops₂ : List (Op U)} {u : Fin U} {v₀ : ℕ} (hvh : (spec U V n_max).ValidHistory (empty U) (ops₁ ++ Op.insert u v₀ :: ops₂)) (hu₁ : ((spec U V n_max).run (empty U) ops₁).1 u = none) (hcard₁ : (dom ((spec U V n_max).run (empty U) ops₁).1).card < m) :
    have s₁ := ((spec U V n_max).run (empty U) ops₁).1; ∑' (π : Fin U → Equiv.Perm (Fin m)), (Probability.PMF.uniformOfFintype (Fin U → Equiv.Perm (Fin m))) π * ↑(probeCount (runTable hm π (ops₁ ++ Op.insert u v₀ :: ops₂)) u (π u)) ≤ ↑m / ↑(m - (dom s₁).card)

    Per-key successful-search bound from the proof of Theorem 11.8 of [CLRS09], third edition, p. 276: if ops = ops₁ ++ (.insert u v₀ :: ops₂) is a valid operation history where ops₁ is the prefix before u is first inserted (s₁ u = none), then the expected number of probes made when searching for the fixed key u after ops equals the expected number of probes when u was first inserted after ops₁, and is at most m / (m - (Dictionary.dom s₁).card) (this formalizes the per-key intermediate bound 1 / (1 - i / m) = m / (m - i) for i = (Dictionary.dom s₁).card from the proof of Theorem 11.8; the uniform-key-averaged (1 / α) ln(1 / (1 - α)) endpoint of Theorem 11.8 is not formalized here).

    theorem Cslib.DataStructure.Dictionary.UniformProbing.expect_probeCount_of_mem_dom_le_two {U V n_max m : ℕ} (hm : 0 < m) (h2cap : 2 * n_max ≤ m) {ops₁ ops₂ : List (Op U)} {u : Fin U} {v₀ : ℕ} (hvh : (spec U V n_max).ValidHistory (empty U) (ops₁ ++ Op.insert u v₀ :: ops₂)) (hu₁ : ((spec U V n_max).run (empty U) ops₁).1 u = none) :
    ∑' (π : Fin U → Equiv.Perm (Fin m)), (Probability.PMF.uniformOfFintype (Fin U → Equiv.Perm (Fin m))) π * ↑(probeCount (runTable hm π (ops₁ ++ Op.insert u v₀ :: ops₂)) u (π u)) ≤ 2

    Half-load per-key successful-search bound from the proof of Theorem 11.8 ([CLRS09], third edition, Section 11.4, p. 276): when 2 * n_max ≤ m, any successful lookup of a fixed present key u (first inserted after prefix ops₁) makes at most 2 probes in expectation over π ← PMF.uniformOfFintype (Fin U → Equiv.Perm (Fin m)).

    Section 4: Lazy Random-Oracle Equivalence (RandomOracle.uniform_interpret_eq_lazy) #

    Any adaptive oracle program querying per-key permutations u ↦ π u : Equiv.Perm (Fin m) has the exact same output distribution whether the permutation table π ← PMF.uniformOfFintype (Fin U → Equiv.Perm (Fin m)) is sampled eagerly upfront or lazily on first query via Cslib.RandomOracle.answer.

    Section 5: Deterministic Pigeonhole Probe-Count Bounds #

    For any occupied slot set O : Finset (Fin m) and permutation σ : Equiv.Perm (Fin m), the number of consecutive missed probes missedProbes O σ is at most O.card by injectivity of σ.

    Deterministic Pigeonhole Probe Bound: for any table T : Table U m, key u : Fin U, and probe permutation σ : Equiv.Perm (Fin m), probeCount T u σ ≤ (otherOccupiedSlots T u).card + 1.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.probeCount_le_dom_card_add_one {U m : ℕ} {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (u : Fin U) :
    probeCount T u (π u) ≤ (dom s).card + 1

    Under TableRep π s T, probeCount T u (π u) ≤ (Dictionary.dom s).card + 1 holds deterministically for every key u : Fin U.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.probeCount_le_add_one {U m n_max : ℕ} {π : Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Table U m} (hrep : TableRep π s T) (hdom : (dom s).card ≤ n_max) (u : Fin U) :
    probeCount T u (π u) ≤ n_max + 1

    Under TableRep π s T and (Dictionary.dom s).card ≤ n_max, probeCount T u (π u) ≤ n_max + 1 holds deterministically for every key u : Fin U.

    theorem Cslib.DataStructure.Dictionary.UniformProbing.expect_probeCount_le_add_one {Θ : Type u_1} [Fintype Θ] [Nonempty Θ] {U m n_max : ℕ} {π : Θ → Fin U → Equiv.Perm (Fin m)} {s : State U} {T : Θ → Table U m} (hrep : ∀ (θ : Θ), TableRep (π θ) s (T θ)) (hdom : (dom s).card ≤ n_max) (u : Fin U) :
    ∑' (θ : Θ), (Probability.PMF.uniformOfFintype Θ) θ * ↑(probeCount (T θ) u (π θ u)) ≤ ↑n_max + 1

    Deterministic Expected Probe-Count Bound (≤ n_max + 1) for Any Full-Cycle Permutation Family: for any nonempty finite seed space Θ and any permutation family π : Θ → Fin U → Equiv.Perm (Fin m) representing s in T θ with (Dictionary.dom s).card ≤ n_max, the expected probe count of u under PMF.uniformOfFintype Θ is at most n_max + 1.