Documentation

CslibFrontier.DataStructure.ApproximateMembership.WordRAM.QuotientFilter.Cluster

Memory-Program Realization of Quotient-Filter Cluster Operations #

This module implements and certifies the deterministic cluster-level operations (queryCluster, insertCluster, deleteCluster) of the Word-RAM quotient filter as a unified Memory.Prog program clusterOpProg, certified for width-independent compilation via the realize tactic (realizes_clusterOp). Word-RAM register assignment and machine-code assembly live in CslibFrontier/DataStructure/ApproximateMembership/WordRAM/QuotientFilter/Code.lean.

Main definitions #

Main results #

Section 1: Cluster operation input record (ClusterInput) #

The 15-word runtime input record passed to the quotient-filter cluster program clusterOpProg. The fields appear in register order 0..14 matching ClusterInput.words.

  • qVal : ℕ

    Target quotient slot q.val.

  • rVal : ℕ

    Target remainder r.val.

  • opTag : ℕ

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

  • slotCap : ℕ

    Slot capacity 2 ^ b (b = quotBits w₀ n).

  • slotMask : ℕ

    Cyclic slot bitmask 2 ^ b - 1.

  • fullBase : ℕ

    Base word address of the isFull bitmap.

  • occBase : ℕ

    Base word address of the isOcc bitmap.

  • runBase : ℕ

    Base word address of the isRunStart bitmap.

  • remBase : ℕ

    Base word address of the remAt packed array.

  • pBit : ℕ

    Log₂ packing factor slotPackShift b 1 w for 1-bit bitmaps.

  • pBitMask : ℕ

    Intra-word bit-index mask 2 ^ pBit - 1 for 1-bit bitmaps.

  • pRem : ℕ

    Log₂ packing factor slotPackShift b f w for f-bit remainders.

  • pRemMask : ℕ

    Intra-word entry-index mask 2 ^ pRem - 1 for f-bit remainders.

  • f : ℕ

    Remainder bit-width remBits w₀ k.

  • fMask : ℕ

    Remainder value mask 2 ^ f - 1.

Instances For
    theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.ClusterInput.ext {x y : ClusterInput} (qVal : x.qVal = y.qVal) (rVal : x.rVal = y.rVal) (opTag : x.opTag = y.opTag) (slotCap : x.slotCap = y.slotCap) (slotMask : x.slotMask = y.slotMask) (fullBase : x.fullBase = y.fullBase) (occBase : x.occBase = y.occBase) (runBase : x.runBase = y.runBase) (remBase : x.remBase = y.remBase) (pBit : x.pBit = y.pBit) (pBitMask : x.pBitMask = y.pBitMask) (pRem : x.pRem = y.pRem) (pRemMask : x.pRemMask = y.pRemMask) (f : x.f = y.f) (fMask : x.fMask = y.fMask) :
    x = y

    Faithful 15-word vector encoding of a ClusterInput in declaration order 0..14.

    def Cslib.DataStructure.ApproximateMembership.QuotientFilter.mkClusterInput (base w w₀ n k : ℕ) (q : Fin (2 ^ quotBits w₀ n)) (r : Fin (2 ^ remBits w₀ k)) (opTag : ℕ) :

    Construct the ClusterInput parameter record for (base, w, w₀, n, k) and (q, r, opTag).

    Word-level safety envelope for ClusterInput at word width w.

    theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.quotBits_lt_w_of_fits_space {base w w₀ n k : ℕ} (hw₀ : 0 < w₀) (hw : 2 * w₀ ≤ w) (hfit : WordRAM.Fits w (base + space w w₀ n k)) :
    quotBits w₀ n < w

    Whenever 0 < w₀, 2 * w₀ ≤ w, and Fits w (base + space w w₀ n k), the quotient bit-width quotBits w₀ n is strictly less than w.

    theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.clusterSafe_mkClusterInput {base w w₀ n k : ℕ} (hw₀ : 0 < w₀) (hw : 2 * w₀ ≤ w) (hfit : WordRAM.Fits w (base + space w w₀ n k)) (q : Fin (2 ^ quotBits w₀ n)) (r : Fin (2 ^ remBits w₀ k)) {opTag : ℕ} (hop : opTag < 4) :
    ClusterSafe w (mkClusterInput base w w₀ n k q r opTag)

    Every mkClusterInput record satisfies ClusterSafe w once 0 < w₀, 2 * w₀ ≤ w, Fits w (base + space w w₀ n k), and opTag < 4.

    Section 2: Bit-packed accessor programs #

    Section 3: Backward and forward cluster-extent discovery (findClusterProg) #

    Section 4: Prefix occBefore and full cluster scan (scanClusterProg) #

    Environment of the cluster scan scanLoopProg. The words are listed in the order ((d, (o, (a, ℓ))), (occA, occA1)).

    • Cluster operation input.

    • o : ℕ

      Cluster start slot.

    • a : ℕ

      Offset of the target quotient within the cluster.

    • ℓ : ℕ

      Cluster length.

    • occA : ℕ

      Occupied quotients before the target, occBefore st o a.

    • occA1 : ℕ

      Occupied quotients up to and including the target, occBefore st o (a + 1).

    Instances For
      theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.ScanEnv.ext {x y : ScanEnv} (d : x.d = y.d) (o : x.o = y.o) (a : x.a = y.a) (ℓ : x.ℓ = y.ℓ) (occA : x.occA = y.occA) (occA1 : x.occA1 = y.occA1) :
      x = y

      Loop state of the cluster scan after i slots. The words are listed in the order ((i, (runs, occI)), ((s₀, s), (e, qFound))).

      • i : ℕ

        Slots scanned so far.

      • runs : ℕ

        Run starts among the scanned slots.

      • occI : ℕ

        Occupied quotients among the scanned slots.

      • s₀ : ℕ

        Start of the target run, calcRunStart.

      • s : ℕ

        Insertion target slot, calcTargetSlot.

      • e : ℕ

        End of the shift for a delete, calcDeleteStop.

      • qFound : ℕ

        Whether the target remainder was found (0 or 1), queryAnyPrefix.

      Instances For
        theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.ScanState.ext {x y : ScanState} (i : x.i = y.i) (runs : x.runs = y.runs) (occI : x.occI = y.occI) (s₀ : x.s₀ = y.s₀) (s : x.s = y.s) (e : x.e = y.e) (qFound : x.qFound = y.qFound) :
        x = y

        Input of the target, stop and query updates in one step of scanLoopProg: the environment, the state before the step, the run count including the current slot, and the current slot's remainder. The words are listed in the order ((env, st), (runs, rem)).

        • env : ScanEnv

          Scan environment.

        • State before the step.

        • runs : ℕ

          Run starts up to and including the current slot.

        • rem : ℕ

          Remainder stored at the current slot.

        Instances For

          Section 5: Right-Shift Loop and insertAfterScanProg #

          Section 6: Left-Shift Loop and deleteAfterScanProg #

          Section 7: Unified Cluster Operation clusterOpProg #

          Unified deterministic cluster operation (0 = insert, 1 = delete, 2 = query).

          Section 8A: Memory Admissibility (ValidHistory) and memoryCost Bound #

          Section 8B: Semantic Correctness of clusterOpProg on mkClusterInput #

          SlotFrame base w w₀ n k s₁ s₂ states that s₂ preserves s₁.frontier and modifies mem only within the four packed slot arrays [fullBase base w w₀ n, base + space w w₀ n k).

          theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.SlotFrame.trans {base w w₀ n k : ℕ} {s₁ s₂ s₃ : Memory.State} (h₁₂ : SlotFrame base w w₀ n k s₁ s₂) (h₂₃ : SlotFrame base w w₀ n k s₂ s₃) :
          SlotFrame base w w₀ n k s₁ s₃
          theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.clusterOpProg_mk_insert {U : ℕ} {S : Finset (Fin U)} (base w w₀ n k : ℕ) {quot : Fin U → Fin (2 ^ quotBits w₀ n)} {rem : Fin U → Fin (2 ^ remBits w₀ k)} (u : Fin U) (s : Memory.State) (hinv : FilterInv n S quot rem (extractFilterState base w w₀ n k s.mem)) (hS_lt : S.card < 2 ^ quotBits w₀ n) :
          have d := mkClusterInput base w w₀ n k (quot u) (rem u) 0; (Memory.spec 0).clientResult s (clusterOpProg d) = 0 ∧ extractFilterState base w w₀ n k ((Memory.spec 0).clientState s (clusterOpProg d)).mem = hinv.insertState hS_lt u ∧ SlotFrame base w w₀ n k s ((Memory.spec 0).clientState s (clusterOpProg d))
          theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.clusterOpProg_mk_delete {U : ℕ} {S : Finset (Fin U)} (base w w₀ n k : ℕ) {quot : Fin U → Fin (2 ^ quotBits w₀ n)} {rem : Fin U → Fin (2 ^ remBits w₀ k)} {u : Fin U} (hu : u ∈ S) (s : Memory.State) (hinv : FilterInv n S quot rem (extractFilterState base w w₀ n k s.mem)) (hS_lt : S.card < 2 ^ quotBits w₀ n) :
          have d := mkClusterInput base w w₀ n k (quot u) (rem u) 1; (Memory.spec 0).clientResult s (clusterOpProg d) = 0 ∧ extractFilterState base w w₀ n k ((Memory.spec 0).clientState s (clusterOpProg d)).mem = hinv.deleteState hS_lt u ∧ SlotFrame base w w₀ n k s ((Memory.spec 0).clientState s (clusterOpProg d))
          theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.clusterOpProg_mk_query {U : ℕ} {S : Finset (Fin U)} (base w w₀ n k : ℕ) {quot : Fin U → Fin (2 ^ quotBits w₀ n)} {rem : Fin U → Fin (2 ^ remBits w₀ k)} (u : Fin U) (s : Memory.State) (hinv : FilterInv n S quot rem (extractFilterState base w w₀ n k s.mem)) (hS_lt : S.card < 2 ^ quotBits w₀ n) :
          have d := mkClusterInput base w w₀ n k (quot u) (rem u) 2; (Memory.spec 0).clientResult s (clusterOpProg d) = (decide (rem u ∈ bucketRun S quot rem (quot u))).toNat ∧ (Memory.spec 0).clientState s (clusterOpProg d) = s
          theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.validHistory_clusterOp_mk {base w w₀ n k : ℕ} {s : Memory.State} (hwf : Memory.WellFormed w s) (hfront : base + space w w₀ n k ≤ s.frontier) (q : Fin (2 ^ quotBits w₀ n)) (r : Fin (2 ^ remBits w₀ k)) {opTag : ℕ} (hcs : ClusterSafe w (mkClusterInput base w w₀ n k q r opTag)) :

          Memory admissibility (ValidHistory) of clusterOpProg on mkClusterInput.

          theorem Cslib.DataStructure.ApproximateMembership.QuotientFilter.memoryCost_clusterOp_mk_le {U : ℕ} {S : Finset (Fin U)} (base w w₀ n k : ℕ) {quot : Fin U → Fin (2 ^ quotBits w₀ n)} {rem : Fin U → Fin (2 ^ remBits w₀ k)} (q : Fin (2 ^ quotBits w₀ n)) (r : Fin (2 ^ remBits w₀ k)) (opTag : ℕ) (s : Memory.State) (hinv : FilterInv n S quot rem (extractFilterState base w w₀ n k s.mem)) (hS_lt : S.card < 2 ^ quotBits w₀ n) :
          WordRAM.Realization.memoryCost (clusterOpProg (mkClusterInput base w w₀ n k q r opTag)) s ≤ 11 * hinv.clusterLen hS_lt q + 13

          On any FilterInv-valid state, clusterOpProg performs at most 11 * ℓ + 13 memory operations on a cluster of length ℓ = hinv.clusterLen hS_lt q.