Documentation

CslibFrontier.DataStructure.Dictionary.FeistelQuotient

One-round Feistel quotienting and universal succinct bit accounting #

This file formalizes the one-round Feistel permutation used for quotienting keys in succinct hash tables (Arbitman, Naor and Segev, FOCS 2010, Claim 5.7; Bender, Conway, Farach-Colton, Kuszmaul and Tagliavini, J. ACM 2023, Section 7, arXiv pp. 31–33) together with the universal bit-accounting inequality comparing quotient + value storage against the information-theoretic optimum Dynamic.optBits U V n = ⌈log₂ C(U, n)⌉ + n * ⌈log₂ V⌉ for every n.

Given a universe bound U, capacity n ≤ U, and bucket bit-width b = bucketBits n = ⌊log₂ n⌋ - 3 * logLogFactor n:

  1. Every key u < U has keyBits U = ⌈log₂ U⌉ bits and splits into a low b-bit part keyLow b u = u % 2^b and a high (keyBits U - b)-bit quotient keyQuotient b u = u / 2^b.
  2. Given a hash function h1 : ℕ → ℕ, key u maps to bucket feistelBucket b h1 u = (h1 (keyQuotient b u) % 2^b) ^^^ keyLow b u < 2^b and stores only keyQuotient b u < 2^(quotientBits U n).
  3. From (bucket, keyQuotient b u), feistelReconstruct b h1 bucket (keyQuotient b u) recovers u uniquely (feistelReconstruct_feistelBucket). Consequently, distinct keys sharing the same quotient always map to distinct Feistel buckets (feistelBucket_ne_of_keyQuotient_eq_of_ne).
  4. For every n, storing n quotients of quotientBits U n bits and n values of valBits V = ⌈log₂ V⌉ bits uses at most Dynamic.optBits U V n + 5 * n * Dynamic.logLogFactor n bits (quotient_val_bits_le_optBits).

Main definitions #

Main results #

References #

Section 1: Bit-width parameters and bucket/slab scales #

Number of bits ⌈log₂ U⌉ needed to represent keys in Fin U.

Number of bits ⌈log₂ V⌉ needed to represent values in Fin V.

Poly-logarithmic scale parameter L = 2^(logLogFactor n) ≥ 2, satisfying log₂ n ≤ L ≤ 2 * ⌈log₂ (max n 4)⌉.

Number of bucket index bits b = ⌊log₂ n⌋ - 3 * logLogFactor n.

Number of Feistel buckets M = 2^(bucketBits n).

Number of stored quotient bits per key q_bits = ⌈log₂ U⌉ - bucketBits n.

Whenever n ≤ U, the bucket bit-width bucketBits n is at most keyBits U.

If U ≤ 2 ^ w, then quotientBits U n ≤ w.

For every n, n ≤ 2 ^ (bucketBits n + 3 * Dynamic.logLogFactor n + 1).

Section 2: One-round Feistel quotienting and exact key reconstruction #

The low b bits u % 2^b of a key u.

The quotient u / 2^b obtained by dropping the low b bits of u.

One-round Feistel bucket index (h1 (keyQuotient b u) % 2^b) ^^^ keyLow b u < 2^b.

Inverse reconstruction of key u from its Feistel bucket index bucket and stored quotient q = keyQuotient b u.

keyLow b u is strictly less than 2 ^ b.

feistelBucket b h1 u is strictly less than 2 ^ b.

Whenever n ≤ U and u < U, the quotient keyQuotient (bucketBits n) u fits in quotientBits U n bits (< 2 ^ (quotientBits U n)).

@[simp]

Reconstructing from feistelBucket b h1 u and keyQuotient b u recovers u exactly.

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.feistelBucket_feistelReconstruct {b : ℕ} (h1 : ℕ → ℕ) {bucket : ℕ} (hb : bucket < 2 ^ b) (q : ℕ) :
feistelBucket b h1 (feistelReconstruct b h1 bucket q) = bucket ∧ keyQuotient b (feistelReconstruct b h1 bucket q) = q

Reconstructing any (bucket, q) with bucket < 2 ^ b produces a key whose Feistel bucket is bucket and whose quotient is q.

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.eq_of_feistelBucket_eq_of_keyQuotient_eq {b : ℕ} {h1 : ℕ → ℕ} {u₁ u₂ : ℕ} (hb : feistelBucket b h1 u₁ = feistelBucket b h1 u₂) (hq : keyQuotient b u₁ = keyQuotient b u₂) :
u₁ = u₂

Two keys landing in the same Feistel bucket with the same quotient are equal.

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.feistelBucket_ne_of_keyQuotient_eq_of_ne {b : ℕ} {h1 : ℕ → ℕ} {u₁ u₂ : ℕ} (hq : keyQuotient b u₁ = keyQuotient b u₂) (hne : u₁ ≠ u₂) :
feistelBucket b h1 u₁ ≠ feistelBucket b h1 u₂

Two distinct keys that share the same quotient keyQuotient b u₁ = keyQuotient b u₂ always map to distinct Feistel buckets for every hash function h1.

Section 3: Universal quotienting bit accounting against Dynamic.optBits #

For all n ≤ U, U ^ n ≤ n ^ n * U.choose n.

Universal quotient bit bound: for every n, storing n quotients of quotientBits U n bits uses at most ⌈log₂ C(U, n)⌉ + 5 * n * Dynamic.logLogFactor n bits. When U < n the binomial vanishes and quotientBits U n ≤ 3 * Dynamic.logLogFactor n + 1.

Universal quotient + value bit bound: for every n and V, storing n quotients of quotientBits U n bits and n values of valBits V = ⌈log₂ V⌉ bits uses at most Dynamic.optBits U V n + 5 * n * Dynamic.logLogFactor n bits.

Section 4: Pairwise and 3-wise independence bounds for Feistel buckets and micro-chains #

def Cslib.DataStructure.Dictionary.FeistelQuotient.feistelXor {ι : Type u_1} {Q : Type u_2} {U : ℕ} (b m : ℕ) (hbm : b ≤ m) (qOf : Fin U → Q) (H : ι → Q → Fin (2 ^ m)) (i : ι) (u : Fin U) :
Fin (2 ^ m)

Typed Feistel XOR map sending key u : Fin U to ⟨(H i (qOf u)).val ^^^ keyLow b u.val, ...⟩ : Fin (2 ^ m) whenever b ≤ m. When m = b, this is the Feistel bucket index in Fin (2 ^ b); when m = b + p, its low b bits give the Feistel bucket index and its high p bits give the per-bucket micro-chain index.

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.feistelXor_ne_of_qOf_eq_pt {ι : Type u_1} {Q : Type u_2} {U b m : ℕ} (hbm : b ≤ m) (qOf : Fin U → Q) (H : ι → Q → Fin (2 ^ m)) (i : ι) {u₁ u₂ : Fin U} (hquot : keyQuotient b ↑u₁ = keyQuotient b ↑u₂) (hne : u₁ ≠ u₂) (hqq : qOf u₁ = qOf u₂) :
feistelXor b m hbm qOf H i u₁ ≠ feistelXor b m hbm qOf H i u₂

Two distinct keys sharing the same qOf value and the same keyQuotient b value never collide under feistelXor, for any seed i.

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.feistelXor_eq_iff {ι : Type u_1} {Q : Type u_2} {U b m : ℕ} (hbm : b ≤ m) (qOf : Fin U → Q) (H : ι → Q → Fin (2 ^ m)) (i : ι) (u₁ u₂ : Fin U) :
feistelXor b m hbm qOf H i u₁ = feistelXor b m hbm qOf H i u₂ ↔ H i (qOf u₁) = (Equiv.xor ⟨keyLow b ↑u₂ ^^^ keyLow b ↑u₁, ⋯⟩) (H i (qOf u₂))

Two feistelXor values are equal iff H i (qOf u₁) equals Equiv.xor Δ (H i (qOf u₂)).

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.expect_boole_apply_eq_equiv {ι : Type u_1} {Q : Type u_2} [Fintype ι] {Y : Type u_3} {𝕜 : Type u_4} [Fintype Y] [DecidableEq Y] [Semifield 𝕜] [CharZero 𝕜] {H : ι → Q → Y} (hh : Probability.IsPairwiseIndependentHash H) {q₁ q₂ : Q} (hne : q₁ ≠ q₂) (e : Y ≃ Y) :
(Finset.univ.expect fun (i : ι) => if H i q₁ = e (H i q₂) then 1 else 0) = (↑(Fintype.card Y))⁻¹

For a pairwise independent hash family H and distinct quotients q₁ ≠ q₂, the probability that H i q₁ = e (H i q₂) is 1 / |Y|.

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.expect_card_feistelXor_eq_on {ι : Type u_1} {Q : Type u_2} [Fintype ι] [DecidableEq Q] {U b m : ℕ} {𝕜 : Type u_3} [Semifield 𝕜] [CharZero 𝕜] (hbm : b ≤ m) {qOf : Fin U → Q} {H : ι → Q → Fin (2 ^ m)} (hh : Probability.IsPairwiseIndependentHash H) (S : Finset (Fin U)) (u : Fin U) (hq : ∀ u₁ ∈ insert u (S.erase u), ∀ u₂ ∈ insert u (S.erase u), qOf u₁ = qOf u₂ → keyQuotient b ↑u₁ = keyQuotient b ↑u₂) :
(Finset.univ.expect fun (i : ι) => ↑{x ∈ S.erase u | feistelXor b m hbm qOf H i x = feistelXor b m hbm qOf H i u}.card) = ↑{x ∈ S.erase u | qOf x ≠ qOf u}.card / 2 ^ m

Under a pairwise independent hash H : ι → Q → Fin (2 ^ m), for any S : Finset (Fin U) and u : Fin U such that qOf is quotient-injective on insert u (S.erase u), the expected number of keys x ∈ S.erase u colliding with u under feistelXor is #({x ∈ S.erase u | qOf x ≠ qOf u}) / 2 ^ m.

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.dens_filter_apply_eq_three {ι : Type u_1} {Q : Type u_2} [Fintype ι] {Y : Type u_3} [Fintype Y] [DecidableEq Y] {H : ι → Q → Y} (hh : Probability.IsKWiseIndependentHash 3 H) {q q₁ q₂ : Q} (hq₁ : q₁ ≠ q) (hq₂ : q₂ ≠ q) (h12 : q₁ ≠ q₂) (y y₁ y₂ : Y) :
{i : ι | H i q = y ∧ H i q₁ = y₁ ∧ H i q₂ = y₂}.dens = (↑(Fintype.card Y) ^ 3)⁻¹

Under a 3-wise independent hash family H, the values at three pairwise distinct inputs q, q₁, q₂ are mutually independent and uniform.

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.expect_boole_apply_eq_equiv_two {ι : Type u_1} {Q : Type u_2} [Fintype ι] {Y : Type u_3} {𝕜 : Type u_4} [Fintype Y] [DecidableEq Y] [Semifield 𝕜] [CharZero 𝕜] {H : ι → Q → Y} (hh : Probability.IsKWiseIndependentHash 3 H) {q q₁ q₂ : Q} (hq₁ : q₁ ≠ q) (hq₂ : q₂ ≠ q) (h12 : q₁ ≠ q₂) (e₁ e₂ : Y ≃ Y) :
(Finset.univ.expect fun (i : ι) => if H i q₁ = e₁ (H i q) ∧ H i q₂ = e₂ (H i q) then 1 else 0) = (↑(Fintype.card Y) ^ 2)⁻¹

Under a 3-wise independent hash family H and pairwise distinct q, q₁, q₂, the probability that H i q₁ = e₁ (H i q) and H i q₂ = e₂ (H i q) is 1 / |Y|².

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.expect_feistelXor_mul_sub_one_le_on {ι : Type u_1} {Q : Type u_2} [Fintype ι] [DecidableEq Q] {U b m : ℕ} (hbm : b ≤ m) {qOf : Fin U → Q} {H : ι → Q → Fin (2 ^ m)} (hh : Probability.IsKWiseIndependentHash 3 H) (S : Finset (Fin U)) (u : Fin U) (hq : ∀ u₁ ∈ insert u (S.erase u), ∀ u₂ ∈ insert u (S.erase u), qOf u₁ = qOf u₂ → keyQuotient b ↑u₁ = keyQuotient b ↑u₂) :
(Finset.univ.expect fun (i : ι) => ↑{x ∈ S.erase u | feistelXor b m hbm qOf H i x = feistelXor b m hbm qOf H i u}.card * (↑{x ∈ S.erase u | feistelXor b m hbm qOf H i x = feistelXor b m hbm qOf H i u}.card - 1)) ≤ (↑{x ∈ S.erase u | qOf x ≠ qOf u}.card / 2 ^ m) ^ 2

Under a 3-wise independent hash H : ι → Q → Fin (2 ^ m), when qOf is quotient-injective on insert u (S.erase u), the second factorial moment of the number of keys in S.erase u colliding with u under feistelXor is at most (#({x ∈ S.erase u | qOf x ≠ qOf u}) / 2 ^ m) ^ 2.

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.nat_sub_two_mul_le_sq {N D : ℕ} {μ : ℚ} (hμ0 : 0 ≤ μ) (hμD : μ ≤ ↑D) :
↑(N - 2 * D) * ↑D ≤ (↑N - μ) ^ 2

Pointwise quadratic upper bound on truncated excess above 2 * D: for any N, D : ℕ and 0 ≤ μ ≤ D in ℚ, ((N - 2 * D : ℕ) : ℚ) * D ≤ ((N : ℚ) - μ) ^ 2.

theorem Cslib.DataStructure.Dictionary.FeistelQuotient.expect_feistelXor_overflow_le_on {ι : Type u_1} {Q : Type u_2} [Fintype ι] {U b m D : ℕ} (hbm : b ≤ m) (hD : 1 ≤ D) {qOf : Fin U → Q} {H : ι → Q → Fin (2 ^ m)} (hh : Probability.IsKWiseIndependentHash 3 H) (S : Finset (Fin U)) (u : Fin U) (hS : (S.erase u).card ≤ D * 2 ^ m) (hq : ∀ u₁ ∈ insert u (S.erase u), ∀ u₂ ∈ insert u (S.erase u), qOf u₁ = qOf u₂ → keyQuotient b ↑u₁ = keyQuotient b ↑u₂) :
(Finset.univ.expect fun (i : ι) => ↑({x ∈ S.erase u | feistelXor b m hbm qOf H i x = feistelXor b m hbm qOf H i u}.card - 2 * D)) ≤ 1

3-wise independent Feistel bucket overflow bound: under a 3-wise independent hash H : ι → Q → Fin (2 ^ m), for any D ≥ 1 and S : Finset (Fin U) with #(S.erase u) ≤ D * 2 ^ m such that qOf is quotient-injective on insert u (S.erase u), the expected overflow above 2 * D in u's Feistel bucket is at most 1.