SlowGuess/NeurIPS_2023_OCR huggingface dataset:
(f)  $CC_{1}(u)$
(j)  $TR_{1}(u)$
Figure 4: Illustrations of certain substructure counts.
(g)  $CC_2(u)$
(k)  $TR_{2}(u)$
(h)  $TR_{1}(u,v)$
(1)  $TR_{3}(u)$
There are relations between the above-defined counts. For chordal cycle counts we have
$$
C C _ {1} (u) = \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} C C _ {1} (v, u), \quad C C _ {2} (u) = \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} C C _ {1} (u, v). \tag {32}
$$
$$
C C _ {2} (u) = \sum_ {v \in \mathcal {N} _ {1} (u)} C C _ {2} (u, v). \tag {33}
$$
For triangle-rectangle counts we have
$$
T R _ {1} (u) = \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} T R _ {1} (u, v), \quad T R _ {2} (u) = \sum_ {v \in \mathcal {N} _ {1} (u)} T R _ {1} (v, u), \tag {34}
$$
$$
T R _ {2} (u) = \sum_ {v \in \mathcal {N} _ {1} (u) \cup \mathcal {N} _ {2} (u)} T R _ {2} (u, v), \quad T R _ {3} (u) = \sum_ {v \in \mathcal {N} _ {1} (u) \cup \mathcal {N} _ {2} (u)} T R _ {2} (v, u). \tag {35}
$$
We also denote  $P_{k}(u,v)$  as the number of  $k$ -paths starting at node  $u$  and ending at node  $v$ ,  $W_{k}(u,v)$  as the number of  $k$ -walks from  $u$  to  $v$ , and  $C_k(u)$  as the number of  $k$ -cycles that pass a node  $u$ .
The following lemma will be used throughout this section.
Lemma C.5. Let  $S$  be a graph substructure. If there exists a  $d$ -DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$ ,
$$
W ^ {(T)} (u, u) = C (S, u, G), \quad \forall u \in \mathcal {V} _ {G} \tag {36}
$$
after running  $q$  for  $T$  iterations on  $G$ , then  $d$ -DRFWL(2) GNNs can node-level count  $S$ .
Proof. Let  $(G_{1},u_{1}),(G_{2},u_{2})\in \mathcal{G}\times \mathcal{V}$ , and  $C(S,u_1,G_1)\neq C(S,u_2,G_2)$ . Then by assumption,
$$
W ^ {(T)} \left(u _ {1}, u _ {1}\right) \neq W ^ {(T)} \left(u _ {2}, u _ {2}\right) \tag {37}
$$
after running  $q$  for  $T$  iterations on  $G_{1}$  and  $G_{2}$ . From the proof of Proposition B.3 (which is in Appendix B.3), we see that there exists a  $d$ -DRFWL(2) GNN  $f$  with  $T$ $d$ -DRFWL(2) GNN layers such that a tuple  $(u, v)$  with  $0 \leqslant d(u, v) \leqslant d$  gets its representation  $h_{uv}^{(T)} = \nu(W^{(T)}(u, v))$ , where  $\nu$  is an injective mapping from the color space of  $q$  to  $\mathbb{N}$ . Therefore, (37) implies  $h_{u_1 u_1}^{(T)} \neq h_{u_2 u_2}^{(T)}$ , or  $f(G_{1}, u_{1}) \neq f(G_{2}, u_{2})$ . This means that  $d$ -DRFWL(2) GNNs can node-level count  $S$ .
We restate Theorem 4.3 as following,
Theorem C.6. 1-DRFWL(2) GNNs can node-level count 3-cycles, but cannot graph-level count any longer cycles.
Proof. To prove that 1-DRFWL(2) GNNs can node-level count 3-cycles, it suffices to find a 1-DRFWL(2) test  $q$  such that after running  $q$  for  $T$  iterations on a graph  $G$ ,
$$
W ^ {(T)} (u, u) = C _ {3} (u), \quad \forall u \in \mathcal {V} _ {G}.
$$
Below we explicitly construct  $q$ . Notice that if  $d(u,v) = 1$ ,  $M_{11}^{1(1)}(u,v)$  can know the count  $C(u,v) = |\mathcal{N}_1(u)\cap \mathcal{N}_1(v)|$  in the first 1-DRFWL(2) iteration. This is essentially the number of triangles in which  $\{u,v\} \in \mathcal{E}_G$  is included as an edge. In the second iteration, we can ask
$$
W ^ {(2)} (u, u) = \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} C (u, v), \tag {38}
$$
and we have  $W^{(2)}(u,u) = C_3(u)$ . Therefore, the positive result is proved.
To prove that 1-DRFWL(2) GNNs cannot graph-level count  $k$ -cycles with  $k \geqslant 4$ , we make use of the fact mentioned at the end of Appendix B.2, that 1-DRFWL(2) tests (and thus GNNs) cannot distinguish between two  $k$ -cycles and one  $2k$ -cycle, as long as  $k \geqslant 4$ . This set of counterexamples leads to the negative result.
C.2 Proofs of Theorems 4.4-4.7
Before proving the theorems, we state and prove a series of lemmas.
Lemma C.7. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any 2-tuple  $(u, v) \in \mathcal{V}_G^2$  with  $d(u, v) = 1$  or  $d(u, v) = 2$ ,  $q$  assigns
$$
W ^ {(T)} (u, v) = P _ {2} (u, v), \tag {39}
$$
for some integer  $T \geqslant 1$ .
Proof. Let  $q$  be a 2-DRFWL(2) test that satisfies: at the first iteration,  $M_{11}^{1(1)}(u,v)$  and  $M_{11}^{2(1)}(u,v)$  both count the number of nodes in  $\mathcal{N}_1(u)\cap \mathcal{N}_1(v)$ , and  $\mathrm{HASH}_k^{(1)}$  of  $q$  simply selects the  $M_{11}^{k(1)}$  component, for  $k = 1,2$ ;  $q$  stops updating colors for any tuple from the second iteration. It is easy to see that  $q$  satisfies the condition stated in the lemma.
Lemma C.8. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any node  $u \in \mathcal{V}_G$ ,  $q$  assigns
$$
W ^ {(T)} (u, u) = \deg (u), \tag {40}
$$
for some integer  $T \geqslant 1$ . Here  $\deg(u)$  is the degree of node  $u \in \mathcal{V}_G$ .
Proof. Let  $q$  be a 2-DRFWL(2) test that satisfies: at the first iteration,  $M_{11}^{0(1)}(u,u)$  counts  $|\mathcal{N}_1(u)| = \deg (u)$ , and  $\mathrm{HASH}_0^{(1)}$  of  $q$  selects the  $M_{11}^{0(1)}$  component, then  $W^{(1)}(u,u) = \deg (u)$ .  $q$  then stops updating colors for any tuple from the second iteration. It is obvious that  $q$  satisfies the condition stated in the lemma.
Lemma C.9. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any 2-tuple  $(u, v) \in \mathcal{V}_G^2$  with  $d(u, v) = 1$  or  $d(u, v) = 2$ ,  $q$  assigns
$$
W ^ {(T)} (u, v) = \deg (u) + \deg (v), \tag {41}
$$
for some integer  $T \geqslant 2$ .
Proof. By Lemma C.8, there exists a 2-DRFWL(2) test  $q$  that assigns  $W^{(T)}(u,u) = \deg (u)$  for distance-0 tuples  $(u,u)$  with  $u\in \mathcal{V}_G$ , where  $T\geqslant 1$ . Now, for the  $(T + 1)$ -th iteration of  $q$ , we ask
$$
M _ {0 k} ^ {k (T + 1)} (u, v) = W ^ {(T)} (u, u), \tag {42}
$$
$$
M _ {k 0} ^ {k (T + 1)} (u, v) = W ^ {(T)} (v, v), \tag {43}
$$
where  $k = 1$  or 2;  $q$  then assigns
$$
W ^ {(T + 1)} (u, v) = M _ {0 k} ^ {k (T + 1)} (u, v) + M _ {k 0} ^ {k (T + 1)} (u, v), \tag {44}
$$
for  $d(u,v) = k$  and  $k = 1,2$ . Now  $W^{(T + 1)}(u,v) = \deg (u) + \deg (v)$  for  $T + 1\geqslant 2$
Lemma C.10. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any 2-tuple  $(u, v) \in \mathcal{V}_G^2$  with  $d(u, v) = 1$  or  $d(u, v) = 2$ ,  $q$  assigns
$$
W ^ {(T)} (u, v) = P _ {3} (u, v), \tag {45}
$$
Proof. A 3-path starting at  $u$  and ending at  $v$  is a 3-walk  $u \to x \to y \to v$  with  $u \neq y$  and  $x \neq v$ . Therefore,
$$
P _ {3} (u, v) = W _ {3} (u, v) - \# (u \rightarrow x \rightarrow u \rightarrow v) - \# (u \rightarrow v \rightarrow y \rightarrow v) + 1 _ {(u, v) \in \mathcal {E} _ {G}}. \tag {46}
$$
Here  $\# (u\to x\to u\to v)$  is the number of different ways to walk from  $u$  to a neighboring node  $x$ , then back to  $u$ , and finally to  $v$ , which is also a neighbor of  $u$  ( $x$  can coincide with  $v$ ). The term  $\# (u\to v\to y\to v)$  can be interpreted analogously. The  $1_{(u,v)\in \mathcal{E}_G}$  takes value 1 if  $(u,v)\in \mathcal{E}_G$ , and 0 otherwise. This term accounts for the count  $\# (u\to v\to u\to v)$  which is subtracted twice.
$$
\# (u \rightarrow x \rightarrow u \rightarrow v) = 1 _ {(u, v) \in \mathcal {E} _ {G}} \deg (u), \tag {47}
$$
$$
\# (u \rightarrow v \rightarrow y \rightarrow v) = 1 _ {(u, v) \in \mathcal {E} _ {G}} \deg (v). \tag {48}
$$
Now we construct  $q$  as following: at the first iteration,  $q$  chooses proper  $\mathrm{POOL}_{ij}^{k(1)}$  and  $\mathrm{HASH}_k^{(1)}$  functions  $(0 \leqslant i,j,k \leqslant 2)$  such that
$$
W ^ {(1)} (u, v) = \left\{ \begin{array}{l l} \text {a r b i t r a r y}, & \text {i f} d (u, v) = 0, \\ \left(P _ {2} (u, v), \deg (u) + \deg (v)\right), & \text {i f} d (u, v) = 1, \\ P _ {2} (u, v), & \text {i f} d (u, v) = 2. \end{array} \right. \tag {49}
$$
(a) Setting  $u = z$
(b) Setting  $x = v$
Figure 5: The four types of redundant 4-walks requiring subtraction in the proof of Lemma C.12. Each of the 4 situations is obtained by coalescing one or more node pairs from  $(u, z)$ ,  $(x, z)$  and  $(x, v)$  in a 4-walk  $u \to x \to y \to z \to v$ , while subject to constraints  $u \neq y$  and  $y \neq v$ .
(c) Setting  $x = z$
(d) Setting  $u = z$  and  $x = v$
From Lemmas C.7 and C.9, this is possible. At the second iteration, we ask  $M_{11}^{k(2)}$ ,  $M_{12}^{k(2)}$  and  $M_{21}^{k(2)}$  to be
$$
M _ {1 1} ^ {k (2)} (u, v) = \sum_ {w \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} \left(P _ {2} (u, w) + P _ {2} (w, v)\right), \tag {50}
$$
$$
M _ {1 2} ^ {k (2)} (u, v) = \sum_ {w \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {2} (v)} P _ {2} (w, v), \tag {51}
$$
$$
M _ {2 1} ^ {k (2)} (u, v) = \sum_ {w \in \mathcal {N} _ {2} (u) \cap \mathcal {N} _ {1} (v)} P _ {2} (u, w), \tag {52}
$$
respectively. Here  $k$  takes 1 or 2. We notice that if  $d(u,v) = k$  with  $k = 1,2$ ,
$$
W _ {3} (u, v) = \frac {1}{2} \left(M _ {1 1} ^ {k (2)} (u, v) + M _ {1 2} ^ {k (2)} (u, v) + M _ {2 1} ^ {k (2)} (u, v) + 1 _ {d (u, v) = 1} (\deg (u) + \deg (v))\right) \tag {53}
$$
because the RHS of (53) is exactly  $\frac{1}{2}\left(\sum_{w\in \mathcal{N}_1(v)}W_2(u,w) + \sum_{w\in \mathcal{N}_1(u)}W_2(w,v)\right)$ . Therefore, for a distance- $k$  tuple  $(u,v)$  where  $k = 1$  or 2,
$$
P _ {3} (u, v) = W _ {3} (u, v) - 1 _ {d (u, v) = 1} (\deg (u) + \deg (v) - 1) \tag {54}
$$
is a function of  $M_{11}^{k(2)}, M_{12}^{k(2)}, M_{21}^{k(2)}$  and  $W^{(1)}(u,v)$ , and thus can be assigned to  $W^{(2)}(u,v)$  by choosing proper  $\mathrm{HASH}_k^{(2)}$  functions. After  $q$  assigns  $W^{(2)}(u,v) = P_3(u,v)$  for those  $(u,v)$  with  $d(u,v) = 1$  or  $d(u,v) = 2$ , it then stops updating colors for any tuple from the third iteration. It is now clear that  $q$  satisfies the condition stated in the lemma.
Lemma C.11. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any node  $u \in \mathcal{V}_G$ ,  $q$  assigns
$$
W ^ {(T)} (u, u) = C _ {3} (u), \tag {55}
$$
Proof. This lemma follows from Theorem 4.3 and the fact that the update rule of 2-DRFWL(2) tests encompasses that of 1-DRFWL(2) tests.  $\square$
Lemma C.12. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any 2-tuple  $(u, v) \in \mathcal{V}_G^2$  with  $d(u, v) = 1$  or  $d(u, v) = 2$ ,  $q$  assigns
$$
W ^ {(T)} (u, v) = P _ {4} (u, v), \tag {56}
$$
for some integer  $T \geqslant 3$ .
Proof. A 4-path starting at  $u$  and ending at  $v$  is a 4-walk  $u \to x \to y \to z \to v$  with  $u \neq y, u \neq z, x \neq z, x \neq v$  and  $y \neq v$ . We will calculate  $P_{4}(u, v)$  as following: first define
$$
P _ {2, 2} (u, v) = \sum_ {y \neq u, y \neq v} P _ {2} (u, y) P _ {2} (y, v). \tag {57}
$$
It is easy to see that  $P_{2,2}(u,v)$  gives the number of 4-walks  $u \to x \to y \to z \to v$  with only constraints  $u \neq y$  and  $y \neq v$ . Therefore,
$$
P _ {4} (u, v) = P _ {2, 2} (u, v) - \# (\mathrm {a}) - \# (\mathrm {b}) - \# (\mathrm {c}) + \# (\mathrm {d}), \tag {58}
$$
where  $\# (\mathrm{a}),\# (\mathrm{b}),\# (\mathrm{c})$  and  $\# (\mathrm{d})$  are the numbers of four types of 4-walks illustrated in Figure 5a, 5b, 5c and 5d, respectively. They correspond to setting  $u = z$ ,  $x = v$ ,  $x = z$  and both setting  $u = z$  and  $x = v$  in the 4-walk  $u\rightarrow x\rightarrow y\rightarrow z\rightarrow v$ , respectively, while keeping  $u\neq y$  and  $y\neq v$ .
Now, it is not hard to get the following results,
$$
\# (\mathrm {a}) = 1 _ {(u, v) \in \mathcal {E} _ {G}} \left(2 C _ {3} (u) - P _ {2} (u, v)\right), \tag {59}
$$
$$
\# (\mathbf {b}) = 1 _ {(u, v) \in \mathcal {E} _ {G}} (2 C _ {3} (v) - P _ {2} (u, v)), \tag {60}
$$
$$
\# (\mathbf {c}) = \sum_ {x \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} (\deg (x) - 2), \tag {61}
$$
$$
\# (\mathrm {d}) = 1 _ {(u, v) \in \mathcal {E} _ {G}} P _ {2} (u, v). \tag {62}
$$
We will briefly explain (59)-(62) in the following. The contribution from (59), (60) and (62) only exists when  $u$  and  $v$  are neighbors, which accounts for the  $1_{(u,v)\in \mathcal{E}_G}$  factor. For  $\# (\mathrm{a})$ , if we allow  $v = y$ , then the count is simply  $C_3(u)$  times 2 (because two directions of a 3-cycle that passes  $u$  are counted as two different walks); the contribution of counts from the additional  $v = y$  case is exactly  $\# (\mathrm{d})$ , and is  $P_{2}(u,v)$ , as long as  $(u,v)\in \mathcal{E}_G$ . A similar argument applies to  $\# (\mathrm{b})$ . Determining  $\# (\mathrm{c})$  and  $\# (\mathrm{d})$  is easier and the calculation will not be elaborated here.
Combining the above results, we can give a formula for  $P_4(u,v)$ ,
$$
P _ {4} (u, v) = P _ {2, 2} (u, v) - \sum_ {x \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} (\deg (x) - 2) - 1 _ {(u, v) \in \mathcal {E} _ {G}} \left(2 C _ {3} (u) + 2 C _ {3} (v) - 3 P _ {2} (u, v)\right). \tag {63}
$$
Given the explicit formula (63), we now construct  $q$  as follows: at the first iteration,  $q$  chooses proper POOL $_{ij}^{k(1)}$  and HASH $_{k}^{(1)}$  functions  $(0 \leqslant i,j,k \leqslant 2)$  such that
$$
W ^ {(1)} (u, v) = \left\{ \begin{array}{l l} \text {a r b i t r a r y}, & \text {i f} d (u, v) = 0, \\ \left(1, P _ {2} (u, v), \deg (u) + \deg (v)\right), & \text {i f} d (u, v) = 1, \\ \left(2, P _ {2} (u, v), \deg (u) + \deg (v)\right), & \text {i f} d (u, v) = 2. \end{array} \right. \tag {64}
$$
From Lemmas C.7 and C.9, this is possible. At the second iteration, we let
$$
P _ {2, 2} ^ {i j} (u, v) = \sum_ {w \in \mathcal {N} _ {i} (u) \cap \mathcal {N} _ {j} (v)} P _ {2} (u, w) P _ {2} (w, v), \tag {65}
$$
where  $1\leqslant i,j\leqslant 2$  , and
$$
D _ {1 1} (u, v) = \sum_ {w \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} \left[ \left(\deg (u) + \deg (w)\right) + \left(\deg (w) + \deg (v)\right) \right], \tag {66}
$$
$$
N _ {1 1} (u, v) = \left| \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v) \right|, \tag {67}
$$
for every  $(u,v)$  with  $d(u,v) = 1$  or  $d(u,v) = 2$ . Notice that (65), (66) and (67) can be calculated by an iteration of 2-DRFWL(2) with proper  $\mathrm{POOL}_{ij}^{k(2)}$  functions, where  $1 \leqslant i,j,k \leqslant 2$ . Therefore, we assert that
$$
\sum_ {x \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} (\deg (x) - 2) = \frac {1}{2} D _ {1 1} (u, v) - \left(2 + \frac {\deg (u) + \deg (v)}{2}\right) N _ {1 1} (u, v) \tag {68}
$$
can be calculated by an iteration of 2-DRFWL(2), with proper  $\mathrm{POOL}_{ij}^{k(2)}$  and  $\mathrm{HASH}_k^{(2)}$  functions,  $1\leqslant i,j,k\leqslant 2$ . We now ask  $q$  to assign
$$
W ^ {(2)} (u, v) = \left\{ \begin{array}{l l} C _ {3} (u), & \text {i f} d (u, v) = 0, \\ \left(P _ {2} (u, v), \sum_ {x \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} (\deg (x) - 2), \sum_ {1 \leqslant i, j \leqslant 2} P _ {2, 2} ^ {i j} (u, v)\right), & \text {i f} d (u, v) = 1, \\ \left(\sum_ {x \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} (\deg (x) - 2), \sum_ {1 \leqslant i, j \leqslant 2} P _ {2, 2} ^ {i j} (u, v)\right), & \text {i f} d (u, v) = 2, \end{array} \right. \tag {69}
$$
at the second iteration. From the above discussion and Lemma C.11, this is possible. At the third iteration,  $q$  gathers information from (69) and assigns  $W^{(3)}(u,v) = P_4(u,v)$  for those  $(u,v)$  with  $d(u,v) = 1$  or  $d(u,v) = 2$ , using formula (63); since we already have all the terms of (63) prepared in (69) (notice that  $\sum_{1\leqslant i,j\leqslant 2}P_{2,2}^{ij}(u,v) = P_{2,2}(u,v)$ ), it is easy to see that  $P_4(u,v)$  can be calculated by an iteration of 2-DRFWL(2) with proper  $\mathrm{POOL}_{ij}^{k(3)}$  and  $\mathrm{HASH}_k^{(3)}$  functions,  $1\leqslant i,j,k\leqslant 2$ . We then ask  $q$  to stop updating colors for any tuple from the fourth iteration. Now  $q$  satisfies the condition stated in the lemma.
Lemma C.13. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any 2-tuple  $(u, v) \in \mathcal{V}_G^2$  with  $d(u, v) = 1$  or  $d(u, v) = 2$ ,  $q$  assigns
$$
W ^ {(T)} (u, v) = W _ {4} (u, v), \tag {70}
$$
Proof. Following the notations in the proof of Lemma C.12, we have
$$
W _ {4} (u, v) = W _ {2, 2} (u, v) + \# (u \rightarrow x \rightarrow u \rightarrow z \rightarrow v) + \# (u \rightarrow x \rightarrow v \rightarrow z \rightarrow v), \tag {71}
$$
where  $\# (u\to x\to u\to z\to v)$  is the number of different ways to walk from  $u$  to a neighboring node  $x$ , then back to  $u$ , and, through another neighboring node  $z$ , finally to  $v$  ( $x,z,v$  can coincide with each other). The number  $\# (u\to x\to v\to z\to v)$  can be interpreted analogously. It is easy to see that
$$
\# (u \rightarrow x \rightarrow u \rightarrow z \rightarrow v) = \deg (u) P _ {2} (u, v), \tag {72}
$$
$$
\# (u \rightarrow x \rightarrow v \rightarrow z \rightarrow v) = \deg (v) P _ {2} (u, v), \tag {73}
$$
for  $d(u,v) = 1$  or  $d(u,v) = 2$ . Therefore,
$$
W _ {4} (u, v) = W _ {2, 2} (u, v) + (\deg (u) + \deg (v)) P _ {2} (u, v). \tag {74}
$$
From Lemma C.12, there exists a 2-DRFWL(2) test  $q$  such that  $q$  assigns  $W^{(2)}(u,v) = P_{2,2}(u,v)$  for  $(u,v)$  with  $d(u,v) = 1$  or  $d(u,v) = 2$ . Moreover, from Lemmas C.7 and C.9, there exists another 2-DRFWL(2) test  $q'$  such that  $q'$  assigns  $W^{(2)}(u,v) = (\deg(u) + \deg(v))P_2(u,v)$ , for  $d(u,v) = 1$  or  $d(u,v) = 2$ . Synthesizing the colors that  $q$  and  $q'$  assign to  $(u,v)$  respectively, it is easy to construct a 2-DRFWL(2) test that assigns  $W^{(3)}(u,v) = W_4(u,v)$ , where  $d(u,v) = 1$  or  $d(u,v) = 2$ . We then let it stop updating colors for any tuple from the fourth iteration to make it satisfy the condition stated in the lemma.
In the following, we denote  $P_{k}(u)$  as the number of  $k$ -paths that starts at a node  $u$ , and  $W_{k}(u)$  as the number of  $k$ -walks that starts at a node  $u$ .
Lemma C.14. There exists a 2-DRFWL(2) test  $q$  for any  $k \geqslant 1$  such that for any graph  $G \in \mathcal{G}$  and for any node  $u \in \mathcal{V}_G$ ,  $q$  assigns
$$
W ^ {(T)} (u, u) = W _ {k} (u), \tag {75}
$$
for some integer  $T$ .
Proof. We prove by induction. When  $k = 1$ ,  $W_{1}(u) = \deg (u)$ , and by Lemma C.8, the conclusion is obvious. Now we assume that for  $k = \ell$ , there exists a 2-DRFWL(2) test  $q$  such that  $q$  assigns
$$
W ^ {(T)} (u, u) = W _ {\ell} (u), \quad \forall u \in \mathcal {V} _ {G}, \tag {76}
$$
for some integer  $T$ . Then, at the  $(T + 1)$ -th iteration, we ask
$$
W ^ {(T + 1)} (u, v) = \left\{ \begin{array}{l l} \left(\deg (u), W ^ {(T)} (u, u)\right), & \text {i f} d (u, v) = 0, \\ W ^ {(T)} (u, u) + W ^ {(T)} (v, v), & \text {i f} d (u, v) = 1, \\ \text {a r b i t r a r y}, & \text {i f} d (u, v) = 2. \end{array} \right. \tag {77}
$$
At the  $(T + 2)$ -th iteration, we ask
$$
W ^ {(T + 2)} (u, u) = \sum_ {v \in \mathcal {N} _ {1} (u)} W ^ {(T + 1)} (u, v) - \deg (u) W ^ {(T)} (u, u), \tag {78}
$$
for every distance-0 tuple  $(u, u) \in \mathcal{V}_G^2$ . It is easy to see that
$$
W ^ {(T + 2)} (u, u) = \sum_ {v \in \mathcal {N} _ {1} (u)} W _ {\ell} (v). \tag {79}
$$
Therefore,  $W^{(T + 2)}(u,u) = W_{\ell +1}(u)$ , and the induction step is finished. We then assert that the lemma is true.
Lemma C.15. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any node  $u \in \mathcal{V}_G$ ,  $q$  assigns
$$
W ^ {(T)} (u, u) = C _ {4} (u), \tag {80}
$$
Proof. From Lemma C.10, there exists a 2-DRFWL(2) test  $q$  such that  $q$  assigns  $W^{(T)}(u,v) = C_{1,3}(u,v)$  for some integer  $T \geqslant 2$ , for any graph  $G \in \mathcal{G}$  and any 2-tuple  $(u,v) \in \mathcal{V}_G^2$  with  $d(u,v) = 1$ .  $C_4(u)$  can be calculated from  $C_{1,3}(u,v)$  in another iteration.
Lemma C.16. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any node  $u \in \mathcal{V}_G$ ,  $q$  assigns
$$
W ^ {(T)} (u, u) = C _ {5} (u), \tag {81}
$$
for some integer  $T \geqslant 4$ .
Proof. From Lemma C.12, there exists a 2-DRFWL(2) test  $q$  such that  $q$  assigns  $W^{(T)}(u,v) = C_{1,4}(u,v)$  for some integer  $T \geqslant 3$ , for any graph  $G \in \mathcal{G}$  and any 2-tuple  $(u,v) \in \mathcal{V}_G^2$  with  $d(u,v) = 1$ .  $C_5(u)$  can be calculated from  $C_{1,4}(u,v)$  in another iteration.
Lemma C.17. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any node  $u \in \mathcal{V}_G$ ,  $q$  assigns
$$
W ^ {(T)} (u, u) = C C _ {1} (u), \tag {82}
$$
Proof. By the first equation of (32),
$$
\begin{array}{l} C C _ {1} (u) = \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} C C _ {1} (v, u) \\ = \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} \sum_ {x \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} \left(P _ {2} (x, v) - 1\right) \\ = \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} \sum_ {x \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} \left(P _ {2} (x, v) + P _ {2} (u, x) - 1\right) \\ - \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} \sum_ {x \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} P _ {2} (u, x) \\ = \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} \sum_ {x \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} \left(P _ {2} (x, v) + P _ {2} (u, x) - 1\right) \\ - \frac {1}{2} \sum_ {x \in \mathcal {N} _ {1} (u)} P _ {2} (u, x) \left(\sum_ {v \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (x)} 1\right). \tag {83} \\ \end{array}
$$
Now, using Lemma C.7,  $CC_1(u)$  can be assigned by a 2-DRFWL(2) test to  $W^{(T)}(u,u)$ , for some integer  $T \geqslant 3$  and for all nodes  $u \in \mathcal{V}_G$ .
(a) A 6-cycle with  $u$  and  $v$  on meta-positions. The number of such 6-cycles is exactly  $C_{2,4}(u,v)$ . We require  $t \neq x, t \neq y, t \neq z$
(b) Setting  $t = x$  , the count of the substructure is  $\# (\mathrm{b})$
(c) Setting  $t = y$  , the count of the substructure is  $\# (\mathfrak{c})$
(d) Setting  $t = z$  , the count of the substructure is  $\# (\mathrm{d})$
Figure 6: Illustrations accompanying the proof of Lemma C.19. In all subfigures, it is assumed that  $u \to x \to y \to z \to v$  is a 4-path and  $u \to t \to v$  is a 2-path.
Lemma C.18. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any node  $u \in \mathcal{V}_G$ ,  $q$  assigns
$$
W ^ {(T)} (u, u) = T R _ {1} (u), \tag {84}
$$
Proof. We first calculate  $TR_{1}(u,v)$  as following,
$$
T R _ {1} (u, v) = \sum_ {z \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} P _ {3} (z, v) - \sum_ {z \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} \left(P _ {2} (u, z) - 1\right) - P _ {2} (u, v) \left(P _ {2} (u, v) - 1\right). \tag {85}
$$
Therefore, by the first equation of (34),
$$
\begin{array}{l} T R _ {1} (u) = \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} T R _ {1} (u, v) \\ = \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} \sum_ {z \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (v)} \left(P _ {3} (u, z) + P _ {3} (z, v)\right) \\ - \frac {1}{2} \sum_ {z \in \mathcal {N} _ {1} (u)} P _ {3} (u, z) \left(\sum_ {v \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (z)} 1\right) \\ - \frac {1}{2} \sum_ {z \in \mathcal {N} _ {1} (u)} \left(P _ {2} (u, z) - 1\right) \left(\sum_ {v \in \mathcal {N} _ {1} (u) \cap \mathcal {N} _ {1} (z)} 1\right) \\ - \frac {1}{2} \sum_ {v \in \mathcal {N} _ {1} (u)} P _ {2} (u, v) \left(P _ {2} (u, v) - 1\right). \tag {86} \\ \end{array}
$$
By Lemmas C.7 and C.10,  $TR_{1}(u)$  can be assigned by a 2-DRFWL(2) test to  $W^{(T)}(u,u)$ , for some integer  $T\geqslant 4$  and for all nodes  $u\in \mathcal{V}_G$ .
Lemma C.19. There exists a 2-DRFWL(2) test  $q$  such that for any graph  $G \in \mathcal{G}$  and for any node  $u \in \mathcal{V}_G$ ,  $q$  assigns
$$
W ^ {(T)} (u, u) = C _ {6} (u), \tag {87}
$$
for some integer  $T \geqslant 5$ .
Proof. We first try to calculate  $C_{2,4}(u,v)$ , which is shown in Figure 6a. (If the 6-cycle is thought to be a benzene ring in organic chemistry, then  $u$  and  $v$  are on meta-positions.) It is easy to see that
$$
C _ {6} (u) = \frac {1}{2} \left(\sum_ {v \in \mathcal {N} _ {1} (u)} C _ {2, 4} (u, v) + \sum_ {v \in \mathcal {N} _ {2} (u)} C _ {2, 4} (u, v)\right). \tag {88}
$$