Documentation

CslibFrontier.Probability.KWiseIndependent.DoubleTabulation

Double Tabulation and High Independence ([Thorup2013]) #

This module formalizes the double tabulation hash family and its universal k-uniqueness analysis following Mikkel Thorup, "Simple Tabulation, Fast Expanders, Double Tabulation, and High Independence", Proc. 54th IEEE Symposium on Foundations of Computer Science (FOCS 2013), pp. 90–99, 2013 (arXiv:1311.3121v2, 16 October 2018) [Tho13].

Given keys split into c characters from Φ = Fin (2 ^ b), a first-level simple tabulation table T₁ : Fin c → Fin d → Fin (2 ^ b) → Fin (2 ^ b) maps each key x : Fin c → Fin (2 ^ b) to an intermediate d-tuple simpleTabTuple T₁ x : Fin d → Fin (2 ^ b) by XORing the c character table lookups in each output coordinate j : Fin d. Composing simpleTabTuple T₁ with an independent second-level simple tabulation table T₂ : Fin d → Fin (2 ^ b) → Fin (2 ^ M) yields the double tabulation hash doubleTabHash c d b U M T₁ T₂ : Fin U → Fin (2 ^ M).

Source statements and notation mapping #

In Thorup [Tho13] (arXiv:1311.3121v2):

Main definitions #

Main results #

References #

Section 1: k-uniqueness and Siegel's peeling lemma #

def Cslib.Probability.IsKUnique {α : Type u_1} {β : Type u_2} {d : ℕ} (k : ℕ) (f : α → Fin d → β) :

k-uniqueness ([Tho13], Section 1.1, p. 4): a tuple map f : α → Fin d → β is k-unique if every non-empty subset X ⊆ α of size #X ≤ k contains a key x₀ ∈ X and output coordinate j₀ : Fin d whose value f x₀ j₀ differs from f x j₀ for all other x ∈ X.

Instances For
    @[instance_reducible]
    instance Cslib.Probability.instDecidableIsKUniqueOfFintypeOfDecidableEq {α : Type u_1} {β : Type u_2} [Fintype α] [DecidableEq α] [DecidableEq β] {d : ℕ} (k : ℕ) (f : α → Fin d → β) :
    theorem Cslib.Probability.IsKUnique.mono {α : Type u_1} {β : Type u_2} {d k k' : ℕ} {f : α → Fin d → β} (hf : IsKUnique k f) (hk : k' ≤ k) :

    Monotonicity of IsKUnique in k: if f is k-unique and k' ≤ k, then f is k'-unique.

    theorem Cslib.Probability.IsKUnique.comp_injective {α' : Type u_1} {α : Type u_2} {β : Type u_3} {d k : ℕ} {f : α → Fin d → β} (hf : IsKUnique k f) {g : α' → α} (hg : Function.Injective g) :
    IsKUnique k fun (x : α') => f (g x)

    Precomposing a k-unique function f : α → Fin d → β with an injective map g : α' → α preserves k-uniqueness.

    def Cslib.Probability.simpleTabAddHom {α : Type u_1} {β : Type u_2} {γ : Type u_3} [AddCommGroup γ] {d : ℕ} (f : α → Fin d → β) :
    (Fin d → β → γ) →+ α → γ

    Simple tabulation evaluation over an additive commutative group γ as an additive homomorphism (Fin d → β → γ) →+ (α → γ).

    def Cslib.Probability.simpleTabEval {β : Type u_1} {d M : ℕ} (r : Fin d → β → Fin (2 ^ M)) (y : Fin d → β) :
    Fin (2 ^ M)

    Simple tabulation evaluation over Fin (2 ^ M), XORing (r j (y j)).val across j : Fin d via BitString.equivFin M.

    theorem Cslib.Probability.isKWiseIndependentHash_of_isKUnique {α : Type u_1} {β : Type u_2} [Fintype β] [DecidableEq β] {d M k : ℕ} {f : α → Fin d → β} (hf : IsKUnique k f) :
    IsKWiseIndependentHash k fun (r : Fin d → β → Fin (2 ^ M)) (x : α) => simpleTabEval r (f x)

    Siegel's Peeling Lemma ([Tho13], Section 1.1, Lemma 2, p. 5 & Appendix A, p. 19): If f : α → Fin d → β is k-unique (IsKUnique k f), then composing f with a uniformly random simple tabulation table r : Fin d → β → Fin (2 ^ M) yields a k-wise independent hash family α → Fin (2 ^ M).

    Section 2: Base-2 ^ b character extraction and double tabulation #

    def Cslib.Probability.charDigits (c b : ℕ) {U : ℕ} (u : Fin U) (i : Fin c) :
    Fin (2 ^ b)

    Base-2 ^ b character extraction: splits u : Fin U into c characters in Fin (2 ^ b) via (u.val >>> (i.val * b)) &&& (2 ^ b - 1).

    Injectivity of charDigits: when U ≤ 2 ^ (c * b), distinct keys in Fin U have distinct c-tuples of b-bit characters.

    @[reducible, inline]

    Top-level simple tabulation seed space Fin c → Fin d → Fin (2 ^ b) → Fin (2 ^ b).

    @[reducible, inline]

    Bottom-level simple tabulation seed space Fin d → Fin (2 ^ b) → Fin (2 ^ M).

    def Cslib.Probability.simpleTabTuple {c d b : ℕ} (T₁ : DoubleTabTopSeed c d b) (x : Fin c → Fin (2 ^ b)) (j : Fin d) :
    Fin (2 ^ b)

    First-level simple tabulation ([Thorup2013], Eq. (2), p. 3 & Theorem 1, p. 4): maps each character tuple x : Fin c → Fin (2 ^ b) to an intermediate d-tuple Fin d → Fin (2 ^ b) by XORing T₁ i j (x i) across i : Fin c in each output coordinate j : Fin d.

    def Cslib.Probability.doubleTabHash (c d b U M : ℕ) (T₁ : DoubleTabTopSeed c d b) (T₂ : DoubleTabBotSeed d b M) (u : Fin U) :
    Fin (2 ^ M)

    Mikkel Thorup's Double Tabulation hash function ([Tho13], Section 1.1, p. 5): extracts c base-2 ^ b characters from u : Fin U, applies simpleTabTuple T₁ to obtain d intermediate b-bit characters, and applies simpleTabEval T₂ to produce an M-bit hash in Fin (2 ^ M).

    theorem Cslib.Probability.isKWiseIndependentHash_doubleTabHash_of_isKUnique {c d b U M k : ℕ} {T₁ : DoubleTabTopSeed c d b} (hU : U ≤ 2 ^ (c * b)) (huniq : IsKUnique k (simpleTabTuple T₁)) :
    IsKWiseIndependentHash k fun (T₂ : DoubleTabBotSeed d b M) => doubleTabHash c d b U M T₁ T₂

    When the top-level table T₁ is k-unique (IsKUnique k (simpleTabTuple T₁)) and U ≤ 2 ^ (c * b), the bottom-level family fun T₂ => doubleTabHash c d b U M T₁ T₂ is k-wise independent ([Tho13], Section 1.1, Lemma 2, p. 5).

    Section 3: Position-character sets, symmetric differences, and BitString XOR laws #

    Section 4: Derivable output characters and Theorem 7(a) ([Thorup2013], §3) #

    Section 5: Efficient-code seed counting ([Thorup2013], §2, Eqs. (6)–(7)) #

    Per-step efficient-code counting factor c * ((c * k) ^ (2 * c) * d) ^ q from [Tho13], Section 2, Eqs. (6)–(7), p. 11.

    theorem Cslib.Probability.card_not_isKUnique_le {c d b q k : ℕ} (hc : 1 ≤ c) (hq : 1 ≤ q) (hd : d = 2 * q * c) (hbound : 2 * doubleTabCodeBound c d q k ≤ 2 ^ ((q - 1) * b)) :
    (2 ^ ((q - 1) * b)) ^ 2 * {T₁ : DoubleTabTopSeed c d b | ¬IsKUnique k (simpleTabTuple T₁)}.card ≤ 2 * doubleTabCodeBound c d q k ^ 2 * Fintype.card (DoubleTabTopSeed c d b)

    Thorup's Universal k-Uniqueness Bound ([Tho13], Theorem 1(a), Section 2 Eqs. (6)–(7), and Section 3 Theorem 7(a), pp. 4, 11–13): For c ≥ 1, q ≥ 1, d = 2 * q * c, and 2 * doubleTabCodeBound c d q k ≤ 2 ^ ((q - 1) * b), the number of top-level tables T₁ : DoubleTabTopSeed c d b for which simpleTabTuple T₁ fails to be k-unique satisfies (2 ^ ((q - 1) * b)) ^ 2 * #{T₁ | ¬ IsKUnique k (simpleTabTuple T₁)} ≤ 2 * (doubleTabCodeBound c d q k) ^ 2 * Fintype.card (DoubleTabTopSeed c d b).

    theorem Cslib.Probability.card_not_isKUnique_eight_mul_le {c b k : ℕ} (hc : 1 ≤ c) (hbound : 2 * doubleTabCodeBound c (8 * c) 4 k ≤ 2 ^ (3 * b)) :
    2 ^ (6 * b) * {T₁ : DoubleTabTopSeed c (8 * c) b | ¬IsKUnique k (simpleTabTuple T₁)}.card ≤ 2 * doubleTabCodeBound c (8 * c) 4 k ^ 2 * Fintype.card (DoubleTabTopSeed c (8 * c) b)

    Specialization of card_not_isKUnique_le to q = 4 (d = 8 * c, [Thorup2013], Theorem 1(a), p. 4): when 2 * doubleTabCodeBound c (8 * c) 4 k ≤ 2 ^ (3 * b), at most a 2 * (doubleTabCodeBound c (8 * c) 4 k) ^ 2 / 2 ^ (6 * b) fraction of top-level tables fail to be k-unique.

    Minimum character bit-width doubleTabMinB c_exp for polynomial universe exponent c_exp : ℕ, bounding the character bit-width b = (1 + Nat.clog 2 (max n_max 4)) / 2 from below when doubleTabThreshold c_exp ≤ n_max (n_max = capacity bound) so doubleTabHash satisfies the high-probability logarithmic k-uniqueness bound via Nat.pow_le_two_pow.

    theorem Cslib.Probability.doubleTabMinB_eq (c_exp : ℕ) :
    doubleTabMinB c_exp = 4 * (24 * (2 * max c_exp 1) + 8) ^ 2

    Capacity threshold 2 ^ (2 * doubleTabMinB c_exp) for polynomial universe exponent c_exp : ℕ above which Double Tabulation with c = 2 * max c_exp 1 characters of bit-width b = (1 + Nat.clog 2 (max n_max 4)) / 2 achieves logarithmic k-wise independence with inverse-polynomial failure probability.