The ANF sketches are the Flajolet-Martin sketches of the balls full
This proof shows: correctness, termination.
Let G=(V,E) be a directed graph; an undirected graph has both arcs for each edge, and Adj[v] lists the heads of the arcs out of v. Fix the random positions ρj(u) for each vertex u and copy j=1,…,r. For a set S⊆V, let Mj(S)=⋁u∈S2ρj(u), the bitwise OR, with Mj(∅)=0. Let Bh(v) be the set of vertices reachable from v by a path of at most h arcs.
Termination. Line L1 and each of the hmax rounds of line L3 are loops over finite sets of vertices, arcs and copies. So the algorithm stops.
Lemma 1 (union). Mj(S∪T)=Mj(S)∨Mj(T) for all S,T⊆V.
Proof. Bit i of Mj(S∪T) is 1 if and only if some u∈S∪T has ρj(u)=i, that is, if and only if some u∈S or some u∈T has it, which is the condition for bit i of Mj(S)∨Mj(T). The overlap S∩T plays no role, since 1∨1=1. □
Lemma 2 (balls). B0(v)={v}, and for h≥1,
Bh(v)={v}∪u∈Adj[v]⋃Bh−1(u). Proof. A path of length 0 from v ends at v. For h≥1, take w∈Bh(v). If w=v, it is in the right side. Else a shortest path from v to w has between 1 and h arcs; its first arc goes to some u∈Adj[v], and the rest is a path from u to w of at most h−1 arcs, so w∈Bh−1(u). Conversely, v∈Bh(v), and a path of at most h−1 arcs from an out-neighbour u of v to w, after the arc (v,u), is a walk of at most h arcs from v to w, which contains a path of at most h arcs. □
Theorem. After line L1, and after the round h of lines L4 to L6 for each h=1,…,hmax, M[v][j]=Mj(Bh(v)) for all v and j. Hence line L7 (and line L2 for h=0) sets N^(h)=∑vESTIMATE(M1(Bh(v)),…,Mr(Bh(v))).
Proof. By induction on h. Line L1 sets M[v][j]=2ρj(v)=Mj({v})=Mj(B0(v)).
Assume M[v][j]=Mj(Bh−1(v)) for all v,j at the start of round h. Line L4 sets M′[v][j]=Mj(Bh−1(v)). Line L5 reads only M, which does not change during the round, and ORs into M′[v][j] the value M[u][j]=Mj(Bh−1(u)) for each u∈Adj[v]. Since OR is associative, commutative and idempotent, the order of these steps and repeated arcs do not matter, and after line L5,
M′[v][j]=Mj(Bh−1(v))∨u∈Adj[v]⋁Mj(Bh−1(u))=Mj(Bh−1(v)∪u∈Adj[v]⋃Bh−1(u)) by Lemma 1. For h≥1, Bh−1(v)⊆Bh(v) and v∈Bh−1(v), so by Lemma 2 the set in the brackets equals Bh(v). Line L6 makes M=M′, which gives the claim for h. Line L7 applies ESTIMATE to these values. ■
The theorem makes N^(h) a sum of Flajolet-Martin estimates of the true sizes ∣Bh(v)∣, with the same random positions for every v; the statistical accuracy of each term is the one proved by Flajolet and Martin for their estimator.