Algorithm Search⌘K

Proofs: Weisfeiler-Leman algorithm

These are the human proofs of Weisfeiler-Leman algorithm, at full length.

Color refinement terminates, is isomorphism-invariant, and returns the coarsest equitable refinement full

This proof shows: correctness, termination.

Setting. Let X=(V,E)X = (V, E) be a finite simple undirected graph with NN vertices and an initial coloring c0c_0. In WL-TEST, XX is the disjoint union G⊎HG \uplus H and N=2nN = 2n. Write N(v)N(v) for the set of neighbors of vv, and for a coloring cc write { ⁣{c(w):w∈N(v)} ⁣}\{\!\{ c(w) : w \in N(v) \}\!\} for the multiset of neighbor colors. A coloring dd refines cc when d(u)=d(v)d(u) = d(v) implies c(u)=c(v)c(u) = c(v). Let cic_i be the coloring held after ii executions of L6, with c0c_0 the ranked coloring of L1.

Lemma 1 (refinement). For every ii, ci+1c_{i+1} refines cic_i.

Proof. By L3 and L4, ci+1(u)=ci+1(v)c_{i+1}(u) = c_{i+1}(v) holds exactly when sig(u)=sig(v)\mathrm{sig}(u) = \mathrm{sig}(v). The first component of sig(v)\mathrm{sig}(v) is ci(v)c_i(v), so equal signatures give ci(u)=ci(v)c_i(u) = c_i(v). □\square

Lemma 2 (termination). The loop runs at most NN times, and on return the coloring cc satisfies: for all u,vu, v, c(u)=c(v)c(u) = c(v) implies { ⁣{c(w):w∈N(u)} ⁣}={ ⁣{c(w):w∈N(v)} ⁣}\{\!\{ c(w) : w \in N(u) \}\!\} = \{\!\{ c(w) : w \in N(v) \}\!\}.

Proof. By Lemma 1 the partition of ci+1c_{i+1} refines that of cic_i, so it has at least as many classes, and it has exactly as many only when the two partitions are equal. L5 returns as soon as the number of classes does not grow. The number of classes is between 1 and NN, so after at most NN iterations it stops growing. When L5 returns c=cic = c_i, the partitions of cic_i and c′=ci+1c' = c_{i+1} are equal. If ci(u)=ci(v)c_i(u) = c_i(v) then ci+1(u)=ci+1(v)c_{i+1}(u) = c_{i+1}(v), so sig(u)=sig(v)\mathrm{sig}(u) = \mathrm{sig}(v), and the second components give equal multisets of neighbor colors under cic_i. The sorted list in L3 represents the multiset exactly. □\square

A coloring with the property of Lemma 2 is equitable: two vertices of the same color have, for each color xx, the same number of neighbors of color xx.

Lemma 3 (invariance). Let φ:V→V\varphi : V \to V be a bijection with {u,v}∈E  ⟺  {φ(u),φ(v)}∈E\{u, v\} \in E \iff \{\varphi(u), \varphi(v)\} \in E and c0(φ(v))=c0(v)c_0(\varphi(v)) = c_0(v) for all vv. Then ci(φ(v))=ci(v)c_i(\varphi(v)) = c_i(v) for all ii and all vv.

Proof. By induction on ii. The case i=0i = 0 is the hypothesis, since L1 applies the same rank map to equal values. Assume the claim for ii. The map φ\varphi sends N(v)N(v) bijectively onto N(φ(v))N(\varphi(v)), so

{ ⁣{ci(w):w∈N(φ(v))} ⁣}={ ⁣{ci(φ(w)):w∈N(v)} ⁣}={ ⁣{ci(w):w∈N(v)} ⁣}.\{\!\{ c_i(w) : w \in N(\varphi(v)) \}\!\} = \{\!\{ c_i(\varphi(w)) : w \in N(v) \}\!\} = \{\!\{ c_i(w) : w \in N(v) \}\!\}.

With ci(φ(v))=ci(v)c_i(\varphi(v)) = c_i(v), this gives sig(φ(v))=sig(v)\mathrm{sig}(\varphi(v)) = \mathrm{sig}(v) in round i+1i + 1, and L4 gives both the same rank. □\square

Theorem 1 (soundness of WL-TEST). If WL-TEST returns "not isomorphic", then there is no isomorphism from GG to HH that keeps the initial colors.

Proof. Assume ψ:V(G)→V(H)\psi : V(G) \to V(H) is such an isomorphism. Define φ\varphi on V=V(G)⊎V(H)V = V(G) \uplus V(H) by φ(v)=ψ(v)\varphi(v) = \psi(v) for v∈V(G)v \in V(G) and φ(w)=ψ−1(w)\varphi(w) = \psi^{-1}(w) for w∈V(H)w \in V(H). Then φ\varphi is a bijection of VV, it maps edges of XX to edges and non-edges to non-edges (edges of GG go to edges of HH and back, and there are no edges between the two parts), and it keeps c0c_0. By Lemma 3 the returned coloring cc satisfies c(ψ(v))=c(v)c(\psi(v)) = c(v) for v∈V(G)v \in V(G). Since ψ\psi is a bijection from V(G)V(G) onto V(H)V(H), the multisets { ⁣{c(v):v∈V(G)} ⁣}\{\!\{ c(v) : v \in V(G) \}\!\} and { ⁣{c(w):w∈V(H)} ⁣}\{\!\{ c(w) : w \in V(H) \}\!\} are equal, so L8 does not report "not isomorphic". □\square

Theorem 2 (coarsest equitable refinement). The returned coloring cc is equitable, refines c0c_0, and is refined by every equitable coloring dd that refines c0c_0. Hence its partition is the unique coarsest equitable partition that refines c0c_0.

Proof. Equitability is Lemma 2, and cc refines c0c_0 by Lemma 1 and transitivity. Let dd be equitable and refine c0c_0. We show by induction on ii that dd refines cic_i. For i=0i = 0 this is the hypothesis. Assume dd refines cic_i, and let d(u)=d(v)d(u) = d(v). Then ci(u)=ci(v)c_i(u) = c_i(v). Since dd is equitable, for each dd-color yy the vertices uu and vv have the same number of neighbors of color yy. Each cic_i-class is a union of dd-classes, because dd refines cic_i. Summing over the dd-classes inside a cic_i-class xx, uu and vv have the same number of neighbors of cic_i-color xx, for every xx. So their multisets of neighbor colors under cic_i are equal, sig(u)=sig(v)\mathrm{sig}(u) = \mathrm{sig}(v) in round i+1i + 1, and ci+1(u)=ci+1(v)c_{i+1}(u) = c_{i+1}(v). So dd refines ci+1c_{i+1}, and in particular dd refines the returned cc. If two equitable partitions both refine c0c_0 and are both refined by every such partition, each refines the other, so they are equal. □\square

Lemma 2 gives termination, Theorem 1 gives the correctness of every "not isomorphic" answer, and Theorem 2 shows that the result does not depend on the order in which an implementation splits cells, so any correct partition refinement computes the same stable partition. ■\blacksquare

Back to Weisfeiler-Leman algorithm