Algorithm Search⌘K

Proofs: Ribbon filter

These are the human proofs of Ribbon filter, at full length.

The false positive rate and the cost of a ribbon filter full

This proof shows: complexity.

Model. Assume ideal hashing: in each try, s(x)s(x) is uniform on {0,…,m−w}\{0, \ldots, m - w\}, the bits 1,…,w−11, \ldots, w - 1 of c(x)c(x) are uniform, and fp(x)\mathrm{fp}(x) is uniform on {0,…,2r−1}\{0, \ldots, 2^r - 1\}, independently for all keys and all tries.

Theorem 1. For each key x∉Sx \notin S, Pr⁡[QUERY(x)=true]=2−r\Pr[\text{QUERY}(x) = \text{true}] = 2^{-r}.

Proof. Whether a try succeeds depends only on the hash values of the keys of SS in that try. So the final try is independent of the values at xx, and given the final try and all the values on SS, the array ZZ is fixed while s(x)s(x), c(x)c(x) and fp(x)\mathrm{fp}(x) are still independent and uniform. The value v=⨁j:cj(x)=1Z[s(x)+j]v = \bigoplus_{j : c_j(x) = 1} Z[s(x) + j] is a function of ZZ, s(x)s(x) and c(x)c(x) only, so it is independent of fp(x)\mathrm{fp}(x), and Pr⁡[fp(x)=v]=2−r\Pr[\mathrm{fp}(x) = v] = 2^{-r}. □\square

Theorem 2 (time and space). Each INSERT-ROW takes at most ww rounds of O(1)O(1) operations on ww-bit words, so one try of the build takes O(nw)O(n w) word operations, and in the row-major layout BACK-SUBSTITUTE takes O(mw)O(m w) operations on rr-bit values. A query takes Θ(w)\Theta(w) steps in the row-major layout. The array has mrm r bits.

Proof. The bound on the rounds is Theorem 2 of the correctness proof. Each round does a xor of two rows and two right sides, a test, and a shift by the index of the lowest set bit. Line L9 does at most w−1w - 1 xors for each of the mm rows. A query reads at most ww values. ■\blacksquare

A ribbon filter accepts every key of its set full

This proof shows: correctness, invariant, termination.

All arithmetic is over GF(2)\mathrm{GF}(2), on rows of length mm with an rr-bit right side. For a key xx let E(x)E(x) be its equation: the row with ones at the columns s(x)+js(x) + j for the bits jj of c(x)c(x), and right side fp(x)\mathrm{fp}(x). A stored row (C[i],B[i])(C[i], B[i]) with C[i]≠0C[i] \ne 0 stands for the row with ones at the columns i+ji + j for the bits jj of C[i]C[i], and right side B[i]B[i]. Let RR be the set of stored rows.

Lemma 1 (shape). At all times during the build, each nonzero C[i]C[i] has bit 0 set and fewer than ww bits, and all its columns are in {0,…,m−1}\{0, \ldots, m - 1\}. The current row (s,c)(s, c) of INSERT-ROW has the same properties.

Proof. At the start of INSERT-ROW, c=c(x)c = c(x) has bit 0 set and ww bits, and s+w−1≤m−1s + w - 1 \le m - 1. Line L4 stores a row with these properties. At line L5, both cc and C[s]C[s] are rows relative to ss with fewer than ww bits, so their xor has fewer than ww bits, and it has bit 0 cleared. If it is not 0, line L7 shifts it to its lowest bit, which keeps the absolute columns and sets bit 0. The absolute columns of the xor are among those of the two rows, so they stay in {0,…,m−1}\{0, \ldots, m - 1\}. □\square

Lemma 2 (equivalence). After INSERT-ROW has succeeded for the keys x1,…,xtx_1, \ldots, x_t, the systems {E(x1),…,E(xt)}\{E(x_1), \ldots, E(x_t)\} and RR have the same set of solutions ZZ.

Proof. By induction on tt, with both systems empty for t=0t = 0. Consider INSERT-ROW for x=xt+1x = x_{t+1}. Let ee be the current row with its right side, as an equation. Line L5 replaces ee by e⊕ρe \oplus \rho for a row ρ∈R\rho \in R; line L7 does not change ee as an equation, it only renames its columns relative to the new ss. So at all times e=E(x)⊕∑ρ∈Pρe = E(x) \oplus \sum_{\rho \in P} \rho for a set P⊆RP \subseteq R.

If line L4 stores ee, the new system R′=R∪{e}R' = R \cup \{e\} satisfies: a solution of R′R' satisfies E(x)=e⊕∑PρE(x) = e \oplus \sum_P \rho, and a solution of RR and E(x)E(x) satisfies ee. So R′R' and R∪{E(x)}R \cup \{E(x)\} have the same solutions, and by the induction hypothesis these are the solutions of E(x1),…,E(xt+1)E(x_1), \ldots, E(x_{t+1}). If line L6 succeeds, then ee is the zero row with right side 0, so E(x)=∑PρE(x) = \sum_P \rho holds for every solution of RR, and RR is unchanged. □\square

Lemma 3 (failure means no solution). If line L6 fails, the equations of the keys inserted so far, with xx, have no common solution.

Proof. Then ee is the zero row with right side b≠0b \ne 0, which no ZZ satisfies, and e=E(x)⊕∑Pρe = E(x) \oplus \sum_P \rho; a common solution of RR and E(x)E(x) would satisfy ee. By Lemma 2 the system of the keys is equivalent to RR. □\square

Theorem 1 (invariant (R)). If every INSERT-ROW succeeds, then after BACK-SUBSTITUTE, ZZ satisfies E(x)E(x) for each x∈Sx \in S, so QUERY returns true on SS.

Proof. By Lemma 2 it suffices that ZZ satisfies every stored row. Stored row ii has leading column ii (bit 0) and its other columns i+ji + j with j≥1j \ge 1, by Lemma 1. Line L9 runs for i=m−1i = m - 1 down to 0 and sets Z[i]=B[i]⊕⨁j≥1, Cj[i]=1Z[i+j]Z[i] = B[i] \oplus \bigoplus_{j \ge 1,\, C_j[i] = 1} Z[i + j], using only values Z[i+j]Z[i + j] that are already final, since i+j>ii + j > i. So row ii holds, and it keeps holding, because later steps only write Z[i′]Z[i'] with i′<ii' < i, which row ii does not use. □\square

Theorem 2 (termination). Each INSERT-ROW ends after at most ww rounds. If the hash functions of each try are independent and ideal, and a try succeeds with probability p>0p > 0, then BUILD ends with probability 1 after a geometric number of tries. In particular p>0p > 0 whenever m−w+1≥nm - w + 1 \ge n.

Proof. In each round that does not return, line L7 shifts cc right by j≥1j \ge 1, and cc has fewer than ww bits by Lemma 1, so after fewer than ww shifts it would be 0, and line L6 returns. For p>0p > 0: if m−w+1≥nm - w + 1 \ge n, the keys can have distinct starts, and then each row finds its leading column free at line L4; this choice of starts has positive probability. ■\blacksquare

Back to Ribbon filter