Documentation

CslibFrontier.Probability.KWiseIndependent.Reduced

Universe-reduced k-wise independent hashing via multiply-shift and trinomial polynomials #

To hash a w₀-bit universe Fin U (U ≤ 2 ^ w₀) into Fin (2 ^ b') in $O(1)$ Word-RAM instructions without any polynomial universe restriction $U \le n^c$, we compose two stages:

  1. Dietzfelbinger multiply-shift universe reduction (multiplyShiftReduced U w₀ (3 * b)), which maps keys in Fin U into Fin (2 ^ min w₀ (3 * b)) using a single (w₀ - 1)-bit odd-multiplier seed α ∈ Fin (2 ^ (w₀ - 1)) Dietzfelbinger et al..
  2. Degree-< k trinomial binary-field polynomial evaluation (trinomialPolyHash), which maps the reduced key in Fin (2 ^ min w₀ (3 * b)) into Fin (2 ^ b') using k field coefficients in TrinomialField (reducedTrinomialStep w₀ b b') Vadhan, Section 3.5.5; Wegman and Carter.

Whenever the reduction stage is injective on a key set S : Finset (Fin U), the two-stage hash family is exact k-wise independent on S (isKWiseIndependentHash_reducedPolyHash_of_injOn). By 2-universality of multiply-shift (isUniversalHash_multiplyShift) when 3 * b ≤ w₀ and exact bijectivity of odd multiplication modulo 2 ^ w₀ when w₀ < 3 * b, the probability that a uniform reduction seed α fails to be injective on S is at most (#S * (#S - 1) : ℝ≥0∞) / 2 ^ (3 * b) ≤ (#S ^ 2 : ℝ≥0∞) / 2 ^ (3 * b) (toOuterMeasure_not_injOn_multiplyShiftReduced_le).

Main definitions #

Main results #

References #

Multiply-shift universe reduction to min w₀ R bits #

theorem Cslib.Probability.mod_two_pow_div_lt_min (w₀ R a : ℕ) :
a % 2 ^ w₀ / 2 ^ (w₀ - R) < 2 ^ min w₀ R

For any w₀ R a : ℕ, (a % 2 ^ w₀) / 2 ^ (w₀ - R) < 2 ^ min w₀ R.

def Cslib.Probability.multiplyShiftReduced (U w₀ R : ℕ) (α : Fin (2 ^ (w₀ - 1))) (u : Fin U) :
Fin (2 ^ min w₀ R)

Dietzfelbinger multiply-shift hash mapping u : Fin U into Fin (2 ^ min w₀ R) for a seed α : Fin (2 ^ (w₀ - 1)).

@[simp]
theorem Cslib.Probability.val_multiplyShiftReduced (U w₀ R : ℕ) (α : Fin (2 ^ (w₀ - 1))) (u : Fin U) :
↑(multiplyShiftReduced U w₀ R α u) = (2 * ↑α + 1) * ↑u % 2 ^ w₀ / 2 ^ (w₀ - R)
theorem Cslib.Probability.injective_multiplyShiftReduced_of_le {U w₀ R : ℕ} (hU : U ≤ 2 ^ w₀) (hle : w₀ ≤ R) (α : Fin (2 ^ (w₀ - 1))) :

When w₀ ≤ R and U ≤ 2 ^ w₀, multiplyShiftReduced U w₀ R α is (2 * α + 1) * u % 2 ^ w₀, which is injective on Fin U for every seed α.

theorem Cslib.Probability.card_multiplyShiftReduced_eq_le {U w₀ R : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {x y : Fin U} (hxy : x ≠ y) :
{α : Fin (2 ^ (w₀ - 1)) | multiplyShiftReduced U w₀ R α x = multiplyShiftReduced U w₀ R α y}.card * 2 ^ R ≤ 2 ^ w₀

For any distinct x, y : Fin U (U ≤ 2 ^ w₀, 0 < w₀), the number of seeds α : Fin (2 ^ (w₀ - 1)) for which multiplyShiftReduced U w₀ R α x = multiplyShiftReduced U w₀ R α y is at most 2 ^ (w₀ - R) when R ≤ w₀, and 0 when w₀ < R.

noncomputable def Cslib.Probability.reducedGoodTop (U w₀ R : ℕ) (S : Finset (Fin U)) :
Finset (Fin (2 ^ (w₀ - 1)))

Finset of top-level multiply-shift seeds α : Fin (2 ^ (w₀ - 1)) that are injective on S : Finset (Fin U).

theorem Cslib.Probability.mem_reducedGoodTop {U w₀ R : ℕ} {S : Finset (Fin U)} {α : Fin (2 ^ (w₀ - 1))} :
α ∈ reducedGoodTop U w₀ R S ↔ Set.InjOn (multiplyShiftReduced U w₀ R α) ↑S
theorem Cslib.Probability.card_not_injOn_multiplyShiftReduced_le {U w₀ R : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) (S : Finset (Fin U)) :
(Finset.univ \ reducedGoodTop U w₀ R S).card * 2 ^ R ≤ S.card * (S.card - 1) * 2 ^ (w₀ - 1)

Counting union bound on non-injective multiply-shift seeds: for any S : Finset (Fin U) (U ≤ 2 ^ w₀, 0 < w₀), the number of seeds α : Fin (2 ^ (w₀ - 1)) on which multiplyShiftReduced U w₀ R α fails to be injective on S satisfies #(univ \ reducedGoodTop U w₀ R S) * 2 ^ R ≤ (#S * (#S - 1)) * 2 ^ (w₀ - 1).

theorem Cslib.Probability.toOuterMeasure_not_injOn_multiplyShiftReduced_le {U w₀ R : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) (S : Finset (Fin U)) :
(PMF.uniformOfFintype (Fin (2 ^ (w₀ - 1)))).toOuterMeasure {α : Fin (2 ^ (w₀ - 1)) | ¬Set.InjOn (multiplyShiftReduced U w₀ R α) ↑S} ≤ ↑(S.card * (S.card - 1)) / 2 ^ R

Probability bound on non-injective multiply-shift seeds: under a uniform seed α ← PMF.uniformOfFintype (Fin (2 ^ (w₀ - 1))), the probability that multiplyShiftReduced U w₀ R α fails to be injective on S : Finset (Fin U) is at most (#S * (#S - 1) : ℝ≥0∞) / 2 ^ R.

Two-stage reduced trinomial polynomial hash family #

Target bit-width max (min w₀ (3 * b)) (max b' 1) for the trinomial field stage.

Trinomial step parameter t = trinomialStepAux (reducedTargetBits w₀ b b') for the second-stage polynomial hash over reduced min w₀ (3 * b)-bit keys and b'-bit outputs.

@[reducible, inline]

Trinomial field degree q = 2 * 3 ^ reducedTrinomialStep w₀ b b'.

theorem Cslib.Probability.min_le_reducedTrinomialDeg (w₀ b b' : ℕ) :
min w₀ (3 * b) ≤ 2 * 3 ^ reducedTrinomialStep w₀ b b'

The reduced key bit-width min w₀ (3 * b) is at most reducedTrinomialDeg w₀ b b'.

theorem Cslib.Probability.two_pow_min_le_two_pow_reducedTrinomialDeg (w₀ b b' : ℕ) :
2 ^ min w₀ (3 * b) ≤ 2 ^ (2 * 3 ^ reducedTrinomialStep w₀ b b')

The reduced key universe 2 ^ min w₀ (3 * b) fits in 2 ^ reducedTrinomialDeg w₀ b b'.

The output bit-width b' is at most reducedTrinomialDeg w₀ b b'.

@[reducible, inline]

Top-level seed type Fin (2 ^ (w₀ - 1)) for the multiply-shift reduction stage.

@[reducible, inline]
abbrev Cslib.Probability.ReducedBotSeed (w₀ b b' k : ℕ) :

Bottom-level seed type Fin k → Fin (2 ^ reducedTrinomialDeg w₀ b b') for the k-wise independent trinomial polynomial stage.

@[reducible, inline]

Combined seed type ReducedTopSeed w₀ × ReducedBotSeed w₀ b b' k for the two-stage reduced polynomial hash family.

noncomputable def Cslib.Probability.reducedPolyHash (U w₀ b b' k : ℕ) (θ : ReducedPolySeed w₀ b b' k) (u : Fin U) :
Fin (2 ^ b')

Two-stage hash family reducedPolyHash U w₀ b b' k mapping u : Fin U to Fin (2 ^ b'): first reduces u to min w₀ (3 * b) bits via multiplyShiftReduced U w₀ (3 * b) θ.1, then evaluates the degree-< k trinomial polynomial hash with coefficients θ.2.

theorem Cslib.Probability.isKWiseIndependentHash_reducedPolyHash_of_injOn {U w₀ b b' k : ℕ} {S : Finset (Fin U)} {α : ReducedTopSeed w₀} (hinj : Set.InjOn (multiplyShiftReduced U w₀ (3 * b) α) ↑S) :
IsKWiseIndependentHash k fun (β : ReducedBotSeed w₀ b b' k) (u : ↥S) => reducedPolyHash U w₀ b b' k (α, β) ↑u

Conditional k-wise independence on any key set where the reduction is injective: for any S : Finset (Fin U) and any reduction seed α : ReducedTopSeed w₀ that is injective on S (Set.InjOn (multiplyShiftReduced U w₀ (3 * b) α) S), the restricted bottom-seed family fun (β : ReducedBotSeed w₀ b b' k) (u : S) => reducedPolyHash U w₀ b b' k (α, β) u.val is exact k-wise independent (IsKWiseIndependentHash k).

theorem Cslib.Probability.map_restrict_reducedPolyHash_eq_uniform_of_injOn {U w₀ b b' k : ℕ} {T : Finset (Fin U)} (hT : T.card ≤ k) {α : ReducedTopSeed w₀} (hinj : Set.InjOn (multiplyShiftReduced U w₀ (3 * b) α) ↑T) :
PMF.map (fun (β : ReducedBotSeed w₀ b b' k) => T.restrict (reducedPolyHash U w₀ b b' k (α, β))) (PMF.uniformOfFintype (ReducedBotSeed w₀ b b' k)) = PMF.uniformOfFintype (↥T → Fin (2 ^ b'))

For any α ∈ reducedGoodTop U w₀ (3 * b) T, the restriction of reducedPolyHash to T (#T ≤ k) under a uniform bottom seed is PMF.uniformOfFintype (T → Fin (2 ^ b')).

theorem Cslib.Probability.coupledWithin_reducedPolyHash_restrict {U w₀ b b' k : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {T : Finset (Fin U)} (hT : T.card ≤ k) :
PMF.CoupledWithin (PMF.map (fun (θ : ReducedPolySeed w₀ b b' k) => T.restrict (reducedPolyHash U w₀ b b' k θ)) (PMF.uniformOfFintype (ReducedPolySeed w₀ b b' k))) (PMF.uniformOfFintype (↥T → Fin (2 ^ b'))) (↑(T.card * (T.card - 1)) / 2 ^ (3 * b))

High-probability k-wise independence coupling (coupledWithin_reducedPolyHash_restrict): for any T : Finset (Fin U) with #T ≤ k (0 < w₀, U ≤ 2 ^ w₀), the restriction of reducedPolyHash U w₀ b b' k θ to T under a uniform seed θ ← PMF.uniformOfFintype (ReducedPolySeed w₀ b b' k) is coupled within (#T * (#T - 1) : ℝ≥0∞) / 2 ^ (3 * b) of PMF.uniformOfFintype (T → Fin (2 ^ b')).