Algorithm Search⌘K

Proofs: ANF algorithm

These are the human proofs of ANF algorithm, at full length.

The ANF sketches are the Flajolet-Martin sketches of the balls full

This proof shows: correctness, termination.

Let G=(V,E)G = (V, E) be a directed graph; an undirected graph has both arcs for each edge, and Adj[v]\mathrm{Adj}[v] lists the heads of the arcs out of vv. Fix the random positions ρj(u)\rho_j(u) for each vertex uu and copy j=1,…,rj = 1, \ldots, r. For a set S⊆VS \subseteq V, let Mj(S)=⋁u∈S2ρj(u)M_j(S) = \bigvee_{u \in S} 2^{\rho_j(u)}, the bitwise OR, with Mj(∅)=0M_j(\emptyset) = 0. Let Bh(v)B_h(v) be the set of vertices reachable from vv by a path of at most hh arcs.

Termination. Line L1 and each of the hmax⁡h_{\max} 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)M_j(S \cup T) = M_j(S) \vee M_j(T) for all S,T⊆VS, T \subseteq V.

Proof. Bit ii of Mj(S∪T)M_j(S \cup T) is 1 if and only if some u∈S∪Tu \in S \cup T has ρj(u)=i\rho_j(u) = i, that is, if and only if some u∈Su \in S or some u∈Tu \in T has it, which is the condition for bit ii of Mj(S)∨Mj(T)M_j(S) \vee M_j(T). The overlap S∩TS \cap T plays no role, since 1∨1=11 \vee 1 = 1. □\square

Lemma 2 (balls). B0(v)={v}B_0(v) = \{v\}, and for h≥1h \ge 1,

Bh(v)={v}∪⋃u∈Adj[v]Bh−1(u).B_h(v) = \{v\} \cup \bigcup_{u \in \mathrm{Adj}[v]} B_{h-1}(u).

Proof. A path of length 0 from vv ends at vv. For h≥1h \ge 1, take w∈Bh(v)w \in B_h(v). If w=vw = v, it is in the right side. Else a shortest path from vv to ww has between 1 and hh arcs; its first arc goes to some u∈Adj[v]u \in \mathrm{Adj}[v], and the rest is a path from uu to ww of at most h−1h - 1 arcs, so w∈Bh−1(u)w \in B_{h-1}(u). Conversely, v∈Bh(v)v \in B_h(v), and a path of at most h−1h - 1 arcs from an out-neighbour uu of vv to ww, after the arc (v,u)(v, u), is a walk of at most hh arcs from vv to ww, which contains a path of at most hh arcs. □\square

Theorem. After line L1, and after the round hh of lines L4 to L6 for each h=1,…,hmax⁡h = 1, \ldots, h_{\max}, M[v][j]=Mj(Bh(v))M[v][j] = M_j(B_h(v)) for all vv and jj. Hence line L7 (and line L2 for h=0h = 0) sets N^(h)=∑vESTIMATE(M1(Bh(v)),…,Mr(Bh(v)))\hat N(h) = \sum_v \mathrm{ESTIMATE}(M_1(B_h(v)), \ldots, M_r(B_h(v))).

Proof. By induction on hh. Line L1 sets M[v][j]=2ρj(v)=Mj({v})=Mj(B0(v))M[v][j] = 2^{\rho_j(v)} = M_j(\{v\}) = M_j(B_0(v)).

Assume M[v][j]=Mj(Bh−1(v))M[v][j] = M_j(B_{h-1}(v)) for all v,jv, j at the start of round hh. Line L4 sets M′[v][j]=Mj(Bh−1(v))M'[v][j] = M_j(B_{h-1}(v)). Line L5 reads only MM, which does not change during the round, and ORs into M′[v][j]M'[v][j] the value M[u][j]=Mj(Bh−1(u))M[u][j] = M_j(B_{h-1}(u)) for each u∈Adj[v]u \in \mathrm{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))M'[v][j] = M_j(B_{h-1}(v)) \vee \bigvee_{u \in \mathrm{Adj}[v]} M_j(B_{h-1}(u)) = M_j\Bigl(B_{h-1}(v) \cup \bigcup_{u \in \mathrm{Adj}[v]} B_{h-1}(u)\Bigr)

by Lemma 1. For h≥1h \ge 1, Bh−1(v)⊆Bh(v)B_{h-1}(v) \subseteq B_h(v) and v∈Bh−1(v)v \in B_{h-1}(v), so by Lemma 2 the set in the brackets equals Bh(v)B_h(v). Line L6 makes M=M′M = M', which gives the claim for hh. Line L7 applies ESTIMATE to these values. ■\blacksquare

The theorem makes N^(h)\hat N(h) a sum of Flajolet-Martin estimates of the true sizes ∣Bh(v)∣|B_h(v)|, with the same random positions for every vv; the statistical accuracy of each term is the one proved by Flajolet and Martin for their estimator.

Back to ANF algorithm