Proofs: Bloom filter
These are the human proofs of Bloom filter, at full length.
The false positive rate of a Bloom filter full
This proof shows: false-positive-rate.
Model. Ideal hashing: the values , over all keys and all , are independent and uniform on . Insert distinct keys , and let . Let be the number of positions with , and let .
Claim 1 (the exact rate). .
Proof. By the correctness proof, is a function of the values for , and QUERY returns true exactly when for each . The values are independent of the values for , because , and independent of each other. Given , each hits a 1 bit with probability , so the conditional probability that all hit a 1 bit is . Taking the expectation over gives the claim.
Claim 2 (the mean of ). .
Proof. Position stays 0 exactly when none of the independent values , , equals . Each misses with probability , so position is 0 with probability . By linearity of expectation over the positions, .
Claim 3 (the classical formula is a lower bound).
Proof. The function is convex on for , so by Jensen's inequality . Claim 2 gives the first inequality. The second follows from , which makes , and from the fact that is increasing on .
Claim 4 (concentration). For each , . Hence, with ,
Proof. is a function of the independent values . Changing one of them moves at most one 1 bit, so it changes by at most 1. The bounded differences inequality (McDiarmid's form of the Azuma inequality) then gives the tail bound. For the second part, split on the event . On , . Off , , and is at most the tail bound. Claim 1 adds the two parts.
Consequence. Take . Then the second term is , and when . So , and for fixed and a fixed ratio the rate tends to as , since .
Probes of a query. For , given , the rounds of line L6 look at independent uniform positions, and each one is 0 with probability . The loop stops at the first 0 or after rounds, so the number of rounds is at most a geometric random variable with mean when .
A Bloom filter has no false negatives full
This proof shows: correctness, invariant, termination.
Write for the bit array after the first operations, and for the set of keys inserted by them. The hash functions are fixed by line L2 and do not change. Let be the set of positions of a key .
Lemma 1 (bits only rise). For each and each position , if then .
Proof. A QUERY writes nothing. An INSERT writes only in line L4, and it writes the value 1. So no operation changes a 1 to a 0.
Lemma 2 (invariant (B)). For each , each and each , .
Proof. By induction on . For , line L1 makes all bits 0, and , so the claim holds with nothing to check. Assume the claim for . If operation is a QUERY, then and , so the claim holds. If it is INSERT, then . For and we have by the hypothesis, so by Lemma 1. For , the loop of lines L3 and L4 runs for and sets for each , so each is 1 after the loop. A later round of the same loop writes only the value 1, so it does not undo an earlier round.
Theorem. After any sequence of operations, QUERY returns true for each inserted key . If QUERY returns false, then was never inserted. QUERY returns true exactly when for each .
Proof. The loop of lines L5 and L6 reads for and returns false at the first with . If there is no such , it ends after rounds and line L7 returns true. So QUERY returns true exactly when each position of holds a 1. If , Lemma 2 says that each position of holds a 1, so the query returns true. The second claim is the contrapositive of the first.
Union. Let and be the arrays for the sets and , built with the same and the same hash functions from an all-zero array. By Lemma 1 and line L4, position is 1 in exactly when , because no other position is ever written. So exactly when , which is the array that inserting gives.
Termination. Each loop of lines L3 and L5 has at most rounds, and each round does one hash evaluation and one access to the array.