Proofs: PPJoin
These are the human proofs of PPJoin, at full length.
PPJoin reports exactly the pairs above the Jaccard threshold full
This proof shows: correctness.
We use the names of the pseudocode on the page. Fix , a threshold , and the global order . Every set is a sorted list , and the sets are processed in a fixed order in which whenever comes before . Write
for the probing prefix length, the indexing prefix length and the required overlap.
Lemma 1 (overlap form). For nonempty and , if and only if .
Proof. Let , so . Then if and only if , that is . Since is an integer, this holds if and only if .
Lemma 2 (the index). When the probe of starts in line L3, the list holds exactly the pairs such that was processed before , and , in the order in which those sets were processed.
Proof. Line L2 starts with an empty index. During the probe of , line L11 appends to exactly for the . Since for , , so these are the . Nothing else changes . The appends during the probe of itself come after all reads of the same list in that iteration of line L5, and has no repeated element, so never meets itself.
Lemma 3 (the counter). During the probe of , at the moment line L9 examines the pair found under , if is not pruned for , then equals the number of elements with .
Proof. Let with , at position of and of . Then , and since is in at position and , . So is in the probing prefix of , and by Lemma 2, is in . When the loop of line L5 reached , line L7 met . The size test gave the same answer as now, since it depends only on and , and it passes now. The pair was not pruned then, since pruning is permanent for the probe of and is not pruned now. So line L9 ran on it, and its test passed, or would be pruned. So grew by one for . Conversely grows only in line L9, once per element of met in a list entry of , and such an element is common to and and earlier than . Each common element gives one entry, since has no repeated element.
Lemma 4 (the positional bound). In the situation of Lemma 3, .
Proof. Split by the element , which is common. The elements before number by Lemma 3. The element counts one. An element after is among and among , so there are at most of them.
Lemma 5 (the prefixes). Let and be nonempty with and , and let be the -least element of , with . Then , and .
Proof. We have . Let ; by Lemma 1, . All common elements are at or after in , so , that is ; in the same way . Now gives , so and . And gives , so and .
Theorem. PPJOIN outputs a pair if and only if and are distinct nonempty sets of with , and it outputs each such pair once.
Proof. (Soundness.) Line L13 outputs only if , that is, by Lemma 1, only if . An empty set has no prefix, so it never enters and never probes.
(Uniqueness.) A pair is considered only during the probe of the later of its two sets, by Lemma 2, and line L12 visits each once in that probe.
(Completeness.) Let , with processed before , so . Take , and as in Lemma 5. By Lemma 5 and Lemma 2, , so the loop of line L5 reaches , and is in , and the size filter of line L7 passes. We claim that is never pruned during the probe of . Suppose line L10 prunes for the first time, at an element with . Before that was not pruned, so Lemma 4 applies and gives , by Lemma 1. So the test of line L9 passes, a contradiction. At the test passes as well, so after it, and line L12 visits . Line L13 checks , which holds, and outputs the pair.