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, is uniform on , the bits of are uniform, and is uniform on , independently for all keys and all tries.
Theorem 1. For each key , .
Proof. Whether a try succeeds depends only on the hash values of the keys of in that try. So the final try is independent of the values at , and given the final try and all the values on , the array is fixed while , and are still independent and uniform. The value is a function of , and only, so it is independent of , and .
Theorem 2 (time and space). Each INSERT-ROW takes at most rounds of operations on -bit words, so one try of the build takes word operations, and in the row-major layout BACK-SUBSTITUTE takes operations on -bit values. A query takes steps in the row-major layout. The array has 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 xors for each of the rows. A query reads at most values.
A ribbon filter accepts every key of its set full
This proof shows: correctness, invariant, termination.
All arithmetic is over , on rows of length with an -bit right side. For a key let be its equation: the row with ones at the columns for the bits of , and right side . A stored row with stands for the row with ones at the columns for the bits of , and right side . Let be the set of stored rows.
Lemma 1 (shape). At all times during the build, each nonzero has bit 0 set and fewer than bits, and all its columns are in . The current row of INSERT-ROW has the same properties.
Proof. At the start of INSERT-ROW, has bit 0 set and bits, and . Line L4 stores a row with these properties. At line L5, both and are rows relative to with fewer than bits, so their xor has fewer than 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 .
Lemma 2 (equivalence). After INSERT-ROW has succeeded for the keys , the systems and have the same set of solutions .
Proof. By induction on , with both systems empty for . Consider INSERT-ROW for . Let be the current row with its right side, as an equation. Line L5 replaces by for a row ; line L7 does not change as an equation, it only renames its columns relative to the new . So at all times for a set .
If line L4 stores , the new system satisfies: a solution of satisfies , and a solution of and satisfies . So and have the same solutions, and by the induction hypothesis these are the solutions of . If line L6 succeeds, then is the zero row with right side 0, so holds for every solution of , and is unchanged.
Lemma 3 (failure means no solution). If line L6 fails, the equations of the keys inserted so far, with , have no common solution.
Proof. Then is the zero row with right side , which no satisfies, and ; a common solution of and would satisfy . By Lemma 2 the system of the keys is equivalent to .
Theorem 1 (invariant (R)). If every INSERT-ROW succeeds, then after BACK-SUBSTITUTE, satisfies for each , so QUERY returns true on .
Proof. By Lemma 2 it suffices that satisfies every stored row. Stored row has leading column (bit 0) and its other columns with , by Lemma 1. Line L9 runs for down to 0 and sets , using only values that are already final, since . So row holds, and it keeps holding, because later steps only write with , which row does not use.
Theorem 2 (termination). Each INSERT-ROW ends after at most rounds. If the hash functions of each try are independent and ideal, and a try succeeds with probability , then BUILD ends with probability 1 after a geometric number of tries. In particular whenever .
Proof. In each round that does not return, line L7 shifts right by , and has fewer than bits by Lemma 1, so after fewer than shifts it would be 0, and line L6 returns. For : if , 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.