Documentation

CslibFrontier.DataStructure.ApproximateMembership.QuotientFilter.Probability

Probabilistic Analysis of the Two-Stage Quotient Filter #

This file establishes the probabilistic guarantees of the canonical quotient filter when instantiated with:

  1. a two-stage $5$-wise independent reduced polynomial hash quotHash U w₀ n mapping keys in Fin U (U ≤ 2 ^ w₀) to b = tableLog (min n (2 ^ w₀))-bit quotients (2 ^ b ≥ 8 * n_eff, where n_eff = min n (2 ^ w₀)), and
  2. an independent multiply-shift hash remHash U w₀ k mapping keys in Fin U to remBits w₀ k = min w₀ (k + 1)-bit remainders.

Main results #

References #

Section 1: Two-stage quotient and remainder hash parameters #

Effective capacity min n (2 ^ w₀): since #S ≤ U ≤ 2 ^ w₀ for every S : Finset (Fin U), any valid state of capacity n has #S ≤ effCap w₀ n.

Quotient bit-width b = tableLog (effCap w₀ n) = ⌈log₂ max(8 · effCap w₀ n, 8)⌉.

Remainder bit-width f = min w₀ (k + 1).

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.card_le_effCap {U w₀ n : ℕ} (hU : U ≤ 2 ^ w₀) {S : Finset (Fin U)} (hS : S.card ≤ n) :
S.card ≤ effCap w₀ n
@[reducible, inline]

Seed type for the two-stage $5$-wise independent quotient hash.

@[reducible, inline]

Seed type for the independent multiply-shift remainder hash.

@[reducible, inline]

Combined seed type QuotSeed w₀ n × RemSeed w₀ for the quotient filter.

Uniform distribution over FilterSeed w₀ n.

noncomputable def Cslib.DataStructure.ApproximateMembership.QuotientFilter.quotHash (U w₀ n : ℕ) (θ : QuotSeed w₀ n) (u : Fin U) :
Fin (2 ^ quotBits w₀ n)

Two-stage $5$-wise independent quotient hash mapping Fin U to Fin (2 ^ quotBits w₀ n).

Multiply-shift remainder hash mapping Fin U to Fin (2 ^ remBits w₀ k).

Section 2: Pairwise collision and false-positive probability bounds #

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.card_remHash_eq_le {U w₀ k : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {x y : Fin U} (hxy : x ≠ y) :
{γ : RemSeed w₀ | remHash U w₀ k γ x = remHash U w₀ k γ y}.card * 2 ^ k ≤ Fintype.card (RemSeed w₀)

For any distinct x, y : Fin U (0 < w₀, U ≤ 2 ^ w₀), the number of remainder seeds γ : RemSeed w₀ on which remHash U w₀ k γ x = remHash U w₀ k γ y satisfies #{γ | remHash U w₀ k γ x = remHash U w₀ k γ y} * 2 ^ k ≤ Fintype.card (RemSeed w₀).

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.card_quotHash_eq_le {U w₀ n : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {x y : Fin U} (hxy : x ≠ y) :
{θ : QuotSeed w₀ n | quotHash U w₀ n θ x = quotHash U w₀ n θ y}.card * 2 ^ quotBits w₀ n ≤ 2 * Fintype.card (QuotSeed w₀ n)

For any distinct x, y : Fin U (0 < w₀, U ≤ 2 ^ w₀), the number of quotient seeds θ : QuotSeed w₀ n on which quotHash U w₀ n θ x = quotHash U w₀ n θ y satisfies #{θ | quotHash U w₀ n θ x = quotHash U w₀ n θ y} * 2 ^ quotBits w₀ n ≤ 2 * Fintype.card (QuotSeed w₀ n).

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.card_falsePositive_mul_le {U w₀ n k : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {S : Finset (Fin U)} (hS : S.card ≤ n) {u : Fin U} (hu : u ∉ S) :
{p : FilterSeed w₀ n | ∃ x ∈ S, quotHash U w₀ n p.1 x = quotHash U w₀ n p.1 u ∧ remHash U w₀ k p.2 x = remHash U w₀ k p.2 u}.card * 2 ^ k ≤ Fintype.card (FilterSeed w₀ n)

Counting false-positive bound over FilterSeed w₀ n: for any S : Finset (Fin U) with #S ≤ n and any u ∉ S (0 < w₀, U ≤ 2 ^ w₀), the number of seeds p : FilterSeed w₀ n for which ∃ x ∈ S, quotHash U w₀ n p.1 x = quotHash U w₀ n p.1 u ∧ remHash U w₀ k p.2 x = remHash U w₀ k p.2 u satisfies #{p | ...} * 2 ^ k ≤ Fintype.card (FilterSeed w₀ n).

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.toOuterMeasure_falsePositive_le {U w₀ n k : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {S : Finset (Fin U)} (hS : S.card ≤ n) {u : Fin U} (hu : u ∉ S) :
(filterSeedLaw w₀ n).toOuterMeasure {p : FilterSeed w₀ n | ∃ x ∈ S, quotHash U w₀ n p.1 x = quotHash U w₀ n p.1 u ∧ remHash U w₀ k p.2 x = remHash U w₀ k p.2 u} ≤ (1 / 2) ^ k

Per-query false-positive probability bound: for any S : Finset (Fin U) with #S ≤ n and any absent key u ∉ S (0 < w₀, U ≤ 2 ^ w₀), the probability under filterSeedLaw w₀ n that u collides in both quotient and remainder with some key in S is at most (1 / 2 : ℝ≥0∞) ^ k.

Minimum exponent k = max 1 ⌈log₂(1 / ε)⌉ such that (1 / 2 : ℝ≥0∞) ^ k ≤ ε for any ε : ℝ≥0∞ with ε ≠ 0.

Section 3: Expected cluster length bound across the two-stage seed distribution #

noncomputable def Cslib.DataStructure.ApproximateMembership.QuotientFilter.seedClusterBound (U w₀ n : ℕ) (S : Finset (Fin U)) (u : Fin U) (θ : QuotSeed w₀ n) :

Seed-only upper bound on the cluster length around quotHash U w₀ n θ u for any state representing S (#S ≤ n).

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.FilterInv.clusterLen_le_seedClusterBound {U w₀ n f : ℕ} {S : Finset (Fin U)} {θ : QuotSeed w₀ n} {rem : Fin U → Fin (2 ^ f)} {st : FilterState (quotBits w₀ n) f} (hinv : FilterInv n S (quotHash U w₀ n θ) rem st) (hS_lt : S.card < 2 ^ quotBits w₀ n) (u : Fin U) :
hinv.clusterLen hS_lt (quotHash U w₀ n θ u) ≤ seedClusterBound U w₀ n S u θ

Pointwise bound of hinv.clusterLen hS_lt (quotHash U w₀ n θ u) by the state-independent quantity seedClusterBound U w₀ n S u θ.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.sum_seedClusterBound_sub_one_goodTop_le {U w₀ n : ℕ} (hU : U ≤ 2 ^ w₀) {S : Finset (Fin U)} (hS : S.card ≤ n) (u : Fin U) {α : Probability.ReducedTopSeed w₀} (hα : α ∈ Probability.reducedGoodTop U w₀ (3 * quotBits w₀ n) (insert u (S.erase u))) :
∑ β : Probability.ReducedBotSeed w₀ (quotBits w₀ n) (quotBits w₀ n) 5, (seedClusterBound U w₀ n S u (α, β) - 1) ≤ 288 * Fintype.card (Probability.ReducedBotSeed w₀ (quotBits w₀ n) (quotBits w₀ n) 5)

For any top-level seed α ∈ reducedGoodTop U w₀ (3 * quotBits w₀ n) (insert u (S.erase u)) that is injective on insert u (S.erase u), summing seedClusterBound - 1 over all bottom polynomial seeds β : ReducedBotSeed w₀ (quotBits w₀ n) (quotBits w₀ n) 5 is bounded by 288 * Fintype.card Bot.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.sum_seedClusterBound_le {U w₀ n : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {S : Finset (Fin U)} (hS : S.card ≤ n) (u : Fin U) :
∑ θ : QuotSeed w₀ n, seedClusterBound U w₀ n S u θ ≤ 290 * Fintype.card (QuotSeed w₀ n)

Unconditional sum bound on seedClusterBound over QuotSeed w₀ n: for any S : Finset (Fin U) with #S ≤ n and any u : Fin U (0 < w₀, U ≤ 2 ^ w₀), the sum of seedClusterBound over all quotient seeds θ : QuotSeed w₀ n is at most 290 * Fintype.card (QuotSeed w₀ n).

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.tsum_seedClusterBound_le {U w₀ n : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {S : Finset (Fin U)} (hS : S.card ≤ n) (u : Fin U) :
∑' (p : FilterSeed w₀ n), (filterSeedLaw w₀ n) p * ↑(seedClusterBound U w₀ n S u p.1) ≤ 290

ℝ≥0∞ expectation bound on seedClusterBound under filterSeedLaw w₀ n: ∑' p : FilterSeed w₀ n, filterSeedLaw w₀ n p * (seedClusterBound U w₀ n S u p.1 : ℝ≥0∞) ≤ 290.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.sum_clusterLen_le {U w₀ n f : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {S : Finset (Fin U)} (hS : S.card ≤ n) (hS_lt : S.card < 2 ^ quotBits w₀ n) (u : Fin U) {rem : Fin U → Fin (2 ^ f)} {st : QuotSeed w₀ n → FilterState (quotBits w₀ n) f} (hinv : ∀ (θ : QuotSeed w₀ n), FilterInv n S (quotHash U w₀ n θ) rem (st θ)) :
∑ θ : QuotSeed w₀ n, ⋯.clusterLen hS_lt (quotHash U w₀ n θ u) ≤ 290 * Fintype.card (QuotSeed w₀ n)

Unconditional sum bound on clusterLen over QuotSeed w₀ n: for any S : Finset (Fin U) with #S ≤ n and any u : Fin U (0 < w₀, U ≤ 2 ^ w₀), the sum of clusterLen over all quotient seeds θ : QuotSeed w₀ n is at most 290 * Fintype.card (QuotSeed w₀ n).

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.tsum_clusterLen_le {U w₀ n f : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {S : Finset (Fin U)} (hS : S.card ≤ n) (hS_lt : S.card < 2 ^ quotBits w₀ n) (u : Fin U) {rem : RemSeed w₀ → Fin U → Fin (2 ^ f)} {st : FilterSeed w₀ n → FilterState (quotBits w₀ n) f} (hinv : ∀ (p : FilterSeed w₀ n), FilterInv n S (quotHash U w₀ n p.1) (rem p.2) (st p)) :
∑' (p : FilterSeed w₀ n), (filterSeedLaw w₀ n) p * ↑(⋯.clusterLen hS_lt (quotHash U w₀ n p.1 u)) ≤ 290

ℝ≥0∞ expectation bound on clusterLen under filterSeedLaw w₀ n: ∑' p : FilterSeed w₀ n, filterSeedLaw w₀ n p * (clusterLen p.1 : ℝ≥0∞) ≤ 290.