Documentation

CslibFrontier.DataStructure.ApproximateMembership.WordRAM.QuotientFilter

Word-RAM Implementation of the Two-Stage Quotient Filter #

This module packages the bit-packed two-stage quotient filter into a reusable Cslib.DataStructure.WordRAM.Randomized.ObliviousSequenceImpl certificate realizing Cslib.DataStructure.ApproximateMembership.spec U n ε on the Word-RAM without any universe-to-table restriction log₂ U ≤ c · log₂ n. Keys fit in half a word: every certificate assumes U ≤ 2 ^ w₀ with 0 < w₀ and 2 * w₀ ≤ w.

Architecture #

  1. Deterministic branch-wise transcript (simResult, simTranscript): Because runs are maintained in canonical sorted order, on each fixed random seed p : FilterSeed w₀ n the active slot configuration depends only on the current active set S : Finset (Fin U). Every query on seed p deterministically returns decide (remHash U w₀ k p.2 u ∈ bucketRun S (quotHash U w₀ n p.1) (remHash U w₀ k p.2) _). Hence zero false negatives hold on every random branch, and the false-positive event at query index idx is bounded by (1 / 2 : ℝ≥0∞) ^ k ≤ ε.
  2. Expected O(1) time per operation (charge = opStepBound 290): Evaluating the two-stage quotient hash and the independent remainder hash takes at most 236841 + 45 = 236886 instructions, and the Memory.Prog cluster operation lowered via the realize tactic (realizes_clusterOp.code) executes in at most 19 + clusterFactor * (11 * ℓ + 14) instructions for a cluster of length ℓ. By tsum_seedClusterBound_le (𝔼[ℓ] ≤ 290), the expected instruction count of every operation is at most charge = opStepBound 290.
  3. Compact space (space_le, implOfEps_space_le): The single contiguous memory block of space w w₀ n k words stores the two-stage quotient seed, the o(n)-bit Four-Russians carryless multiplication table, the remainder seed, and the four bit-packed slot arrays (isFull, isOcc, isRunStart, remAt), totaling at most 640 * ((n * k + w - 1) / w + 1) words.

Main definitions #

Main results #

References #

Section 1: Derived word-width bounds and representation invariant Rep #

Whenever 0 < w₀, 2 * w₀ ≤ w, and Fits w (base + space w w₀ n k), the Four-Russians double limb width 2 * reducedChunkBits is strictly less than w.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.tableRep_congr {base w w₀ b b' k : ℕ} {mem₁ mem₂ : ℕ → ℕ} (h : ∀ a < base + HashFamily.WordRAM.ReducedKWise.space w w₀ b b' k, mem₁ a = mem₂ a) :

ReducedKWise.TableRep depends only on memory below base + ReducedKWise.space.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.seedRep_congr {base w w₀ b b' k : ℕ} (θ : Probability.ReducedPolySeed w₀ b b' k) {mem₁ mem₂ : ℕ → ℕ} (h : ∀ a < base + HashFamily.WordRAM.ReducedKWise.space w w₀ b b' k, mem₁ a = mem₂ a) :
HashFamily.WordRAM.ReducedKWise.SeedRep base w₀ b b' k θ mem₁ ↔ HashFamily.WordRAM.ReducedKWise.SeedRep base w₀ b b' k θ mem₂

ReducedKWise.SeedRep depends only on memory below base + ReducedKWise.space.

Seed-coupled Word-RAM representation invariant linking seed p : FilterSeed w₀ n, active key set S : Finset (Fin U), and machine state x : Data rQF.

Section 2: Deterministic branch-wise transcript (simResult, simTranscript) #

noncomputable def Cslib.DataStructure.ApproximateMembership.QuotientFilter.simResult (U w₀ n k : ℕ) (p : FilterSeed w₀ n) (S : Finset (Fin U)) (o : Op U) :

Deterministic branch-wise result of operation o : Op U on seed p : FilterSeed w₀ n from active key set S : Finset (Fin U).

noncomputable def Cslib.DataStructure.ApproximateMembership.QuotientFilter.simTranscript (U w₀ n k : ℕ) (p : FilterSeed w₀ n) :
Finset (Fin U) → List (Op U) → List (Label U)

Deterministic branch-wise transcript produced across ops : List (Op U) on seed p : FilterSeed w₀ n starting from active key set S : Finset (Fin U).

@[simp]
theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.simTranscript_cons (U w₀ n k : ℕ) (p : FilterSeed w₀ n) (S : Finset (Fin U)) (o : Op U) (rest : List (Op U)) :
simTranscript U w₀ n k p S (o :: rest) = ⟨o, simResult U w₀ n k p S o⟩ :: simTranscript U w₀ n k p (stepSet S o) rest
theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.simTranscript_append (U w₀ n k : ℕ) (p : FilterSeed w₀ n) (S : Finset (Fin U)) (ops₁ ops₂ : List (Op U)) :
simTranscript U w₀ n k p S (ops₁ ++ ops₂) = simTranscript U w₀ n k p S ops₁ ++ simTranscript U w₀ n k p (activeSetFrom S ops₁) ops₂
theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.getElem?_simTranscript (U w₀ n k : ℕ) (p : FilterSeed w₀ n) (S : Finset (Fin U)) (ops : List (Op U)) (idx : ℕ) :
(simTranscript U w₀ n k p S ops)[idx]? = Option.map (fun (o : Op U) => ⟨o, simResult U w₀ n k p (activeSetFrom S (List.take idx ops)) o⟩) ops[idx]?
theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.falsePositiveAt_simTranscript_iff (U w₀ n k : ℕ) (p : FilterSeed w₀ n) (ops : List (Op U)) {idx : ℕ} {u : Fin U} (hq : ops[idx]? = some (Op.query u)) :
FalsePositiveAt (simTranscript U w₀ n k p ∅ ops) idx u ↔ ∃ x ∈ activeSetBefore ops idx, 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
theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.contract_map_simTranscript {U w₀ n k : ℕ} (hw₀ : 0 < w₀) (hU : U ≤ 2 ^ w₀) {ops : List (Op U)} (hv : ValidOpSeq n ops) :
(spec U n ((1 / 2) ^ k)).Contract ops (PMF.map (fun (p : FilterSeed w₀ n) => simTranscript U w₀ n k p ∅ ops) (filterSeedLaw w₀ n))

The transcript distribution induced by simTranscript under filterSeedLaw w₀ n satisfies (spec U n ((1 / 2 : ℝ≥0∞) ^ k)).Contract ops.

Section 3: Initialization (allocSpan, initSetup, initSetup_exec) #

Allocate [base, base + space w w₀ n k) by setting qfReg 0 ← qfReg 240 and advancing qfReg 240 ← qfReg 0 + space w w₀ n k in 3 instructions.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.allocSpan_execWithin {base w w₀ n k : ℕ} (hfit_space : WordRAM.Fits w (base + space w w₀ n k)) {x : WordRAM.Data rQF} (hfr : x.regs (qfReg 240) = base) :
∃ (x₁ : WordRAM.Data rQF), WordRAM.ExecWithin w (allocSpan w w₀ n k) x x₁ 3 ∧ x₁.mem = x.mem ∧ x₁.regs (qfReg 0) = base ∧ x₁.regs (qfReg 240) = base + space w w₀ n k

Initialize the Four-Russians carryless multiplication table, sample the two-stage quotient seed, and sample the multiply-shift remainder seed.

Combined ProbComp semantics for sampling the quotient seed and the remainder seed.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.initSetup_exec {U base w w₀ n k : ℕ} (hw₀_pos : 0 < w₀) (hw : 2 * w₀ ≤ w) (hfit_space : WordRAM.Fits w (base + space w w₀ n k)) {x₁ : WordRAM.Data rQF} (hx₁ : WordRAM.Data.Bounded w x₁) (hb : x₁.regs (qfReg 0) = base) (hfr : x₁.regs (qfReg 240) = base + space w w₀ n k) (hzero : ∀ a ∈ { base := base, length := space w w₀ n k }.footprint, x₁.mem a = 0) :
∃ (ν₀ : PMF (WordRAM.Randomized.LatentState (FilterSeed w₀ n) rQF)), WordRAM.ExecCodeDist w (initSetup w w₀ n) x₁ (PMF.map WordRAM.Randomized.LatentState.data ν₀) ↑(setupSteps w₀ n) ∧ (PMF.map WordRAM.Randomized.LatentState.latent ν₀ = filterSeedLaw w₀ n ∧ ∀ t ∈ ν₀.support, Rep U w base w₀ n k t.latent ∅ t.data) ∧ ∀ t ∈ ν₀.support, WordRAM.Data.Bounded w t.data ∧ t.data.regs (qfReg 240) = base + space w w₀ n k ∧ WordRAM.Modifies { base := base, length := space w w₀ n k }.footprint x₁.mem t.data.mem

Section 4: Operation dispatcher opCode and single-step execution #

Underlying key Fin U of a filter operation o : Op U.

Numeric operation tag (0 = insert, 1 = delete, 2 = query).

Input-register mask (qfReg 1 = key, qfReg 247 = operation tag).

Standalone register encoding for argument delivery.

Output decoder reading typed operation observations from final registers.

Unified Word-RAM operation body: evaluates the two-stage quotient hash into qfReg 2 and the remainder hash into qfReg 3, then runs the realized clusterCode (clusterOpProg).

Upper bound clusterFactor * (11 * ℓ + 14) + 236909 on the instruction count of opCode when the cluster around quot u has length ℓ.

Per-operation expected instruction charge opStepBound 290.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.opCode_execWithin {U base w w₀ n k : ℕ} (hw₀_pos : 0 < w₀) (hw : 2 * w₀ ≤ w) (hU : U ≤ 2 ^ w₀) (hfit_space : WordRAM.Fits w (base + space w w₀ n k)) {S : Finset (Fin U)} (hS : S.card ≤ n) {p : FilterSeed w₀ n} {o : Op U} (ho : ValidOp n S o) {x : WordRAM.Data rQF} (hrep : Rep U w base w₀ n k p S x) (h1 : x.regs (qfReg 1) = ↑(opKey o)) (h247 : x.regs (qfReg 247) = opTag o) :
∃ (y : WordRAM.Data rQF), WordRAM.ExecWithin w (opCode w w₀ n k) x y (opStepBound (seedClusterBound U w₀ n S (opKey o) p.1)) ∧ Rep U w base w₀ n k p (stepSet S o) y ∧ decode o y.regs = some (simResult U w₀ n k p S o) ∧ WordRAM.Modifies { base := base, length := space w w₀ n k }.footprint x.mem y.mem

Section 5: Packaging as SubroutineCode and ObliviousSequenceImpl #

Relocatable Word-RAM SubroutineCode for the two-stage quotient filter over Basis.exact.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.prepare_rep {U base w w₀ n k : ℕ} (hw₀_pos : 0 < w₀) (hw : 2 * w₀ ≤ w) (hU : U ≤ 2 ^ w₀) {p : FilterSeed w₀ n} {S : Finset (Fin U)} (o : Op U) {x : WordRAM.Data rQF} (hrep : Rep U w base w₀ n k p S x) :
have x_prep := (subroutineCode w w₀ n k).prepare encode o x; Rep U w base w₀ n k p S x_prep ∧ x_prep.regs (qfReg 1) = ↑(opKey o) ∧ x_prep.regs (qfReg 247) = opTag o ∧ ∀ (i : Fin rQF), (subroutineCode w w₀ n k).input i = true → WordRAM.Fits w (encode o i)
theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.tsum_opStepBound_le {U w₀ n : ℕ} (hw₀_pos : 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 * ↑(opStepBound (seedClusterBound U w₀ n S u p.1)) ≤ ↑charge
noncomputable def Cslib.DataStructure.ApproximateMembership.QuotientFilter.implOfLe {U base w w₀ n k : ℕ} {ε : ENNReal} (hε : (1 / 2) ^ k ≤ ε) (hw₀_pos : 0 < w₀) (hw : 2 * w₀ ≤ w) (hU : U ≤ 2 ^ w₀) (hfit_space : WordRAM.Fits w (base + space w w₀ n k)) :

Parametric ObliviousSequenceImpl certificate for spec U n ε whenever (1 / 2 : ℝ≥0∞) ^ k ≤ ε.

noncomputable def Cslib.DataStructure.ApproximateMembership.QuotientFilter.impl {U base w w₀ n k : ℕ} (hw₀_pos : 0 < w₀) (hw : 2 * w₀ ≤ w) (hU : U ≤ 2 ^ w₀) (hfit_space : WordRAM.Fits w (base + space w w₀ n k)) :
WordRAM.Randomized.ObliviousSequenceImpl (subroutineCode w w₀ n k) (spec U n ((1 / 2) ^ k)) w base ![]

Exact-basis ObliviousSequenceImpl certificate for the two-stage quotient filter realizing spec U n ((1 / 2 : ℝ≥0∞) ^ k).

noncomputable def Cslib.DataStructure.ApproximateMembership.QuotientFilter.implStandard {U base w w₀ n k : ℕ} (hw₀_pos : 0 < w₀) (hw : 2 * w₀ ≤ w) (hU : U ≤ 2 ^ w₀) (hfit_space : WordRAM.Fits w (base + space w w₀ n k)) :

Standard-basis ObliviousSequenceImpl certificate for spec U n ((1 / 2 : ℝ≥0∞) ^ k).

noncomputable def Cslib.DataStructure.ApproximateMembership.QuotientFilter.implOfEps {U base w w₀ n : ℕ} {ε : ENNReal} (hε0 : ε ≠ 0) (hw₀_pos : 0 < w₀) (hw : 2 * w₀ ≤ w) (hU : U ≤ 2 ^ w₀) (hfit_space : WordRAM.Fits w (base + space w w₀ n (epsLog ε))) :

Exact-basis ObliviousSequenceImpl certificate realizing spec U n ε for any ε ≠ 0 by choosing k = epsLog ε = max 1 ⌈log₂(1 / ε)⌉.

noncomputable def Cslib.DataStructure.ApproximateMembership.QuotientFilter.implOfEpsStandard {U base w w₀ n : ℕ} {ε : ENNReal} (hε0 : ε ≠ 0) (hw₀_pos : 0 < w₀) (hw : 2 * w₀ ≤ w) (hU : U ≤ 2 ^ w₀) (hfit_space : WordRAM.Fits w (base + space w w₀ n (epsLog ε))) :

Standard-basis ObliviousSequenceImpl certificate realizing spec U n ε for any ε ≠ 0.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.impl_space_le {U base w w₀ n k : ℕ} (hw₀_pos : 0 < w₀) (hw : 2 * w₀ ≤ w) (hU : U ≤ 2 ^ w₀) (hfit_space : WordRAM.Fits w (base + space w w₀ n k)) (hn : 1 ≤ n) (hk : 1 ≤ k) :
(impl hw₀_pos hw hU hfit_space).space ≤ 640 * ((n * k + w - 1) / w + 1)

Space bound for impl without requiring quotBits w₀ n ≤ w as a separate hypothesis.

theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.implOfEps_space_le {U base w w₀ n : ℕ} {ε : ENNReal} (hε0 : ε ≠ 0) (hw₀_pos : 0 < w₀) (hw : 2 * w₀ ≤ w) (hU : U ≤ 2 ^ w₀) (hfit_space : WordRAM.Fits w (base + space w w₀ n (epsLog ε))) (hn : 1 ≤ n) :
(implOfEps hε0 hw₀_pos hw hU hfit_space).space ≤ 640 * ((n * epsLog ε + w - 1) / w + 1)

Space bound for implOfEps: at most 640 * ((n * epsLog ε + w - 1) / w + 1) words for all 1 ≤ n, 0 < w₀, 2 * w₀ ≤ w.