text:
# The First Order Definability of Graphs: Upper Bounds for Quantifier Rank

## 1 Introduction

From the logical point of view, a graph $`G`$ is a structure with a single anti-reflexive and symmetric binary predicate $`E`$ for the adjacency relation of $`G`$. Every closed first order formula $`\mathrm{\Phi }`$ with predicate symbols $`E`$ and $`=`$ is either true or false on $`G`$. Given two non-isomorphic graphs $`G`$ and $`G^{}`$, we say that $`\mathrm{\Phi }`$ distinguishes $`G`$ from $`G^{}`$ if $`\mathrm{\Phi }`$ is true on $`G`$ but false on $`G^{}`$. The quantifier rank of $`\mathrm{\Phi }`$ is the maximum number of nested quantifiers in this formula (see Section 2 for formal definitions). Let $`\text{D}(G,G^{})`$ denote the minimum quantifier rank of a formula distinguishing $`G`$ from $`G^{}`$. The number $`\text{D}(G,G^{})`$ is symmetric with respect to $`G`$ and $`G^{}`$ because, if $`\mathrm{\Phi }`$ distinguishes $`G`$ from $`G^{}`$, then $`\neg \mathrm{\Phi }`$ distinguishes $`G^{}`$ from $`G`$ and has the same quantifier rank.

The order of a graph is the number of its vertices. Throughout the paper the letter $`n`$ will denote the order of a graph $`G`$.

The first question we address is how large $`\text{D}(G,G^{})`$ can be over non-isomorphic graphs $`G`$ and $`G^{}`$ of the same order $`n`$. For any $`n`$ it is not hard to find a such pair with

$$\text{D}(G,G^{})(n+1)/2$$

(see Example 2.13). On the other hand, there is an obvious general upper bound

$$\text{D}(G,G^{})n.$$

Indeed, a graph $`G`$ with vertex set $`V(G)=\{1,\mathrm{},n\}`$ and edge set $`E(G)`$ is distinguished from any non-isomorphic $`G^{}`$ of order $`n`$ by the formula

$$x_1\mathrm{}x_n\left(\underset{ij}{}\neg (x_i=x_j)\underset{\{i,j\}E(G)}{}E(x_i,x_j)\underset{\{i,j\}E(G)}{}\neg E(x_i,x_j)\right).$$
(1)
It seems that no better upper bound has been reported in the literature so far. Here we prove a nearly best possible bound.

###### Theorem 1.1

If $`G`$ and $`G^{}`$ are non-isomorphic graphs both of order $`n`$, then

$$\text{D}(G,G^{})(n+3)/2.$$

It is worth noting that the distinguishing formulas resulting from our proof of Theorem 1.1 have a rather restricted logical structure. We say that a first order formula $`\mathrm{\Phi }`$ is in the negation normal form if the connective $`\neg `$ occurs in $`\mathrm{\Phi }`$ only in front of atomic subformulas. If $`\mathrm{\Phi }`$ is such a formula, its alternation number is the maximum number of alternations of $``$ and $``$ in a sequence of nested quantifiers of $`\mathrm{\Phi }`$. The proof of Theorem 1.1 produces distinguishing formulas in the negation normal form whose alternation number is at most 1. We are able to prove Theorem 1.1 even with alternation number 0 but with a little weaker bound $`\text{D}(G,G^{})(n+5)/2`$. The proof actually produces either an existential or a universal distinguishing formula. An existential or universal formula is a formula in the negation normal form whose all quantifiers are of only one sort, existential or universal respectively.

Our proof of these results is based on the well-known combinatorial characterization of $`\text{D}(G,G^{})`$ in terms of the Ehrenfeucht game on $`G`$ and $`G^{}`$  (Fraïssé  suggested an essentially equivalent characterization in terms of partial isomorphisms between $`G`$ and $`G^{}`$). In this setting, $`\text{D}(G,G^{})`$ is equal to the length of the game under the condition that the players play optimally. Thus Theorem 1.1 says that the Ehrenfeucht game on non-isomorphic graphs of the same order $`n`$ can be won within at most $`(n+3)/2`$ rounds.

Theorem 1.1 has consequences for the complexity analysis of the Weisfeiler-Lehman algorithm for graph isomorphism testing. This algorithm has been studied since the seventies (see e.g. ). An important combinatorial parameter of the algorithm, occurring in the known bounds on the running time, is its dimension. Denote the optimum dimension for input graphs $`G`$ and $`G^{}`$ by $`\text{WL}(G,G^{})`$ (see Section 7 for a detailed exposition).

Cai, Fürer, and Immerman  come up with a remarkable construction of non-isomorphic $`G`$ and $`G^{}`$ of the same order for which $`\text{WL}(G,G^{})=\mathrm{\Omega }(n)`$. Though they do not specify the constant hidden in the $`\mathrm{\Omega }`$-notation, a simple analysis of their proof, that we make in Section 7.5, gives at least

$$\text{WL}(G,G^{})>0.00465n.$$
(2)
In the same paper, the authors give a logical characterization of $`\text{WL}(G,G^{})`$ which readily implies the relation

$$\text{WL}(G,G^{})\text{D}(G,G^{})1.$$
(3)
Thus, our Theorem 1.1 establishes an upper bound

$$\text{WL}(G,G^{})0.5n+0.5.$$
(4)
We have to remark that this bound for the dimension does not imply any good bound for the worst case running time. In fact, the lower bound (2) shows that the Weisfeiler-Lehman algorithm hardly can be practical in the worst case. However, we believe that (4) shows an interesting combinatorial property of the algorithm previously never observed.

Providing upper bounds for the length of the Ehrenfeucht game and for the dimension of the Weisfeiler-Lehman algorithm, Theorem 1.1 is therefore rather meaningful from combinatorial and computer science point of view. Let us now focus on logical motivations in the scope of finite model theory.

We say that a formula $`\mathrm{\Phi }`$ identifies a graph $`G`$ (up to an isomorphism in the class of graphs of the same order) if $`\mathrm{\Phi }`$ distinguishes $`G`$ from any other non-isomorphic graph $`G^{}`$ of the same order. Let $`\text{}(G)`$ denote the minimum quantifier rank of a such formula. Note that, if $`G`$ is distinguished from $`G^{}`$ by formula $`\mathrm{\Phi }_G^{}`$, then $`G`$ is identified by the conjunction $`_G^{}\mathrm{\Phi }_G^{}`$ over all non-isomorphic $`G^{}`$ of the same order. It easily follows that $`\text{}(G)=\mathrm{max}\text{D}(G,G^{})`$ over all such $`G^{}`$. In these terms Theorem 1.1 reads $`\text{}(G)(n+3)/2`$.

However, from the point of view of finite model theory it is more natural to address defining rather than distinguishing formulas. A first order formula $`\mathrm{\Phi }`$ defines a graph $`G`$ if $`\mathrm{\Phi }`$ distinguishes $`G`$ from all non-isomorphic graphs, regardless of their order. Let $`\text{D}(G)`$ be the minimum quantifier rank of a formula defining $`G`$. As it is well known,

$$\text{D}(G)n+1$$

for every $`G`$ (we have to append $`x_{n+1}`$ to the quantifier prefix of (1) and say that any vertex $`x_{n+1}`$ is equal to one of $`x_1,\mathrm{},x_n`$). This bound cannot be generally improved because, for example, no formula of quantifier rank $`n`$ can distinguish between two complete graphs of orders $`n`$ and $`n+1`$. Nevertheless, our next aim is to suggest a bound for $`\text{D}(G)`$ similar to Theorem 1.1 and explicitly describe all the exceptions. We are able to prove a dichotomy result: Either $`\text{D}(G)n/2+O(1)`$ or else $`G`$ has a simple structure and, moreover, in the latter case $`\text{D}(G)`$ is efficiently computable.

###### Theorem 1.2

There is an efficiently recognizable class of graphs $`𝒞`$ such that

* $`\text{D}(G)(n+5)/2`$ with the exception of all graphs in $`𝒞`$;
* if $`G𝒞`$, then the exact value of $`\text{D}(G)`$ is efficiently computable.

Moreover, every graph $`G`$ admits a defining formula whose alternation number is 1 and whose quantifier rank is as small as possible if $`G𝒞`$ and does not exceed $`(n+5)/2`$ if $`G𝒞`$.

Referring to the efficiency here, we mean the time $`O(n^2\mathrm{log}n)`$ on a random access machine with input graphs given by their adjacency matrices. T. Łuczak  poses a question if $`\text{D}(G)`$ is computable. It seems plausible that it is not. The simulation of undecidable problems by finite structures, as in the Trakhtenbrot theorem  (cf.  and \[26, theorem 8.2.1\]), can be considered an evidence in favor of this hypothesis. In this respect, Theorem 1.2 provides us with a non-trivial computable upper bound for $`\text{D}(G)`$.

The bound of Theorem 1.2 can be improved for graphs with bounded vertex degree: For each $`d2`$ there is a constant $`c_d<1/2`$ such that $`\text{D}(G)c_dn+O(d^2)`$ for any graph $`G`$ with no isolated vertices and edges whose maximum degree is $`d`$. We do not try to find the best possible $`c_d`$ being content with a constant strictly less than $`1/2`$. Note that no sublinear bound is possible here. It is easy to show, for example, that $`\text{D}(G_n)n/(d+1)`$ for $`n=m(d+1)`$ and $`G_n`$ being the vertex disjoint union of $`m`$ copies of the complete graph on $`d+1`$ vertices. Moreover, no sublinear upper bound is possible even for connected graphs, as follows from the Cai-Fürer-Immerman bounds (2) and (3) and because $`G`$ and $`G^{}`$ in their construction are connected graphs of bounded degree (see Section 7.5).

With minor efforts, Theorems 1.1 and 1.2 carry over to directed graphs and, more generally, to arbitrary relational structures with maximum arity 2. In combinatorial terms, the latter are directed graphs endowed with colorings of the vertex set and the edge set.

Finally, we prove somewhat weaker analogs of Theorems 1.1 and 1.2 for $`k`$-uniform hypergraphs. The upper bound we obtain here is $`(11/k)n+2k1`$. It remains open if this bound is tight for $`k3`$ since the only lower bound we know for any $`k`$ is $`(n+1)/2`$.

#### Previous work

The graph identification is studied in  in aspects relevant to computer science. The main focus of this line of research is on the minimum number of variables used in an identifying formula, where formulas are in the first order language enriched by counting quantifiers. A counting quantifier $`^mx\mathrm{\Psi }`$ means that there are at least $`m`$ vertices $`x`$ for which the statement $`\mathrm{\Psi }`$ holds. Let $`\text{L}(G,G^{})`$ denote the minimum number of variables in a formula distinguishing non-isomorphic graphs $`G`$ and $`G^{}`$ (different occurrences of the same variable are not counted). Let $`\text{C}(G,G^{})`$ be the analog of this number for the logic with counting quantifiers. Since every formula of quantifier rank $`r`$ can be rewritten in equivalent form using only $`r`$ variables, we have

$$\text{C}(G,G^{})\text{L}(G,G^{})\text{D}(G,G^{}).$$

Asuming that $`G`$ and $`G^{}`$ are of the same order, our Theorem 1.1 establishes an upper bound of $`(n+3)/2`$ for the whole hierarchy. The aforementioned lower bound by Cai, Fürer, and Immerman  is actually $`\text{C}(G,G^{})=\mathrm{\Omega }(n)`$, for infinitely many non-isomorphic $`G`$ and $`G^{}`$. Their characterization of the optimum dimension of the Weisfeiler-Lehman algorithm is $`\text{WL}(G,G^{})=\text{C}(G,G^{})1`$.

Let $`\text{}(G)`$ (resp. $`\text{}(G)`$) be the minimum number of variables in a formula (resp. with counting quantifiers) identifying a graph $`G`$. By the aforementioned relationship between distinguishing and identifying formulas, we have $`\text{}(G)=\mathrm{max}\text{L}(G,G^{})`$ over all $`G^{}`$ of order $`n`$ non-isomorphic with $`G`$. Similarly, $`\text{}(G)=\mathrm{max}\text{C}(G,G^{})`$ over $`G^{}`$ non-isomorphic with $`G`$, where $`G^{}`$ may be of any order since graphs of different orders are easily distinguishable in the logic with counting quantifiers. Thus, $`\text{}(G)`$ is equal to the minimum number of variables in a formula with counting quantifiers that defines $`G`$.

Define $`\text{}(n)`$, $`\text{}(n)`$, and $`\text{}(n)`$ to be the maximum possible values of $`\text{}(G)`$, $`\text{}(G)`$, and $`\text{}(G)`$, respectively, over graphs of order $`n`$. We now know that

$$0.00465n<\text{}(n)\text{}(n)\text{}(n)0.5n+1.5,$$

where the upper bound is given by Theorem 1.1 and the lower bound is actually the Cai-Fürer-Immerman bound (2). The values of $`\text{}(n)`$ and $`\text{}(n)`$ are at most 1 apart from the upper bound. An interesting open question is where in this range $`\text{}(n)`$ is located.

It is known that $`\text{}(G)=2`$ for almost all graphs of a given order, $`\text{}(G)=3`$ for almost all regular graphs of a given order and degree, $`\text{}(G)=2`$ for all trees , $`\text{}(G)=O(g)`$ for graphs of genus $`g`$ , and $`\text{}(G)k+2`$ for graphs of tree-width $`k`$ . For strongly regular graphs it holds $`\text{}(G)=O(\sqrt{n}\mathrm{log}n)`$, where $`n`$ denotes the order of $`G`$ . If $`G`$ has separator of size $`O(n^\delta )`$, $`0<\delta <1`$, then $`\text{}(G)=O(n^\delta )`$ . This result applies, in particular, to classes of graphs with excluded minors, that have separators of size $`O(\sqrt{n})`$ .

Estimation of $`\text{D}(G,G^{})`$ is an interesting research problem not only for graphs but also for any class of structures. The case of words is considered in  in the context of Zero-One Laws of first order logic, where $`\text{D}(W,W^{})`$ is estimated for $`W`$ and $`W^{}`$ being independent random binary words of length $`n`$.

#### Subsequent work

In  it is shown that $`\text{D}(G)=O(\mathrm{log}n)`$ if $`G`$ is a tree of bounded degree or a Hamiltonian outerplanar graph. This upper bound complements the popular lower bounds $`\text{D}(P_n,P_{n+1})>\mathrm{log}_2n3`$ (e.g. \[26, Theorem 2.1.3\]) and $`\text{D}(C_n,C_{n+1})>\mathrm{log}_2n`$ (e.g. \[9, Example 2.3.8\]), where $`P_n`$ is the path and $`C_n`$ is the cycle on $`n`$ vertices.

As already mentioned, in the present paper we manage to extend Theorem 1.1 from graphs to arbitrary structures with maximum relation arity 2 and to $`k`$-uniform hypergraphs. Extension to arbitrary structures $`G`$ and $`G^{}`$ with maximum relation arity $`k`$ seems a much more subtle problem. It is done in  with bound $`(1\frac{1}{2k})n+k^2k+2`$, even if we restrict the alternation number of a distinguishing formula to 1. The same bound is established for $`\text{D}(G)`$ provided no transposition of two elements of $`G`$ is an automorphism of the structure.

Theorem 1.1 gives a worst case upper bound on $`\text{D}(G,G^{})`$ for graphs of the same order. In  the average case is analyzed and it is proved that, for random independent $`G`$ and $`G^{}`$ on $`n`$ vertices, with probability $`1o(1)`$ we have $`\text{D}(G,G^{})=\mathrm{log}_2n(1+o(1))`$. Moreover, $`\text{D}(G)`$ for a random graph $`G`$ is determined with high precision: With probability $`1o(1)`$,

$$\mathrm{log}_2n2\mathrm{log}_2\mathrm{log}_2n\text{D}(G)\mathrm{log}_2n\mathrm{log}_2\mathrm{log}_2n+\mathrm{log}_2\mathrm{log}_2\mathrm{log}_2n+O(1).$$

The upper bound here holds even if the alternation number of defining formulas is restricted to 1. A logarithmic upper bound is also proved with the alternation number restricted to 0. Together with Theorem 5.1 in the present paper, this shows that bounding the alternation number does not affect much the maximal and the average values of $`\text{D}(G,G^{})`$ for graphs of the same order.

In  the “best case” behavior of $`\text{D}(G)`$ is investigated. Namely, let $`g(n)=\mathrm{min}\text{D}(G)`$ over graphs of order $`n`$. It is not hard to see that $`g(n)\mathrm{}`$ as $`n\mathrm{}`$ but it is not so clear how fast or slowly $`g(n)`$ grows. In  it is proved that $`g(n)`$ can be so small if compared to $`n`$ that the gap between the two numbers cannot be estimated by any computable function, i.e., there is no recursive function $`f`$ such that $`nf(g(n))`$ for all $`n`$. However, if we “regularize” $`g(n)`$ by considering $`\overline{g}(n)=\mathrm{max}_{mn}g(m)`$, we have $`\overline{g}(n)=(1+o(1))\mathrm{log}^{}n`$, where $`\mathrm{log}^{}n`$ is the smallest number of iterations of the logarithm base 2 that suffices to decrease $`n`$ below 1. This result is proved even under the restriction of the alternation number of a defining formula to a constant. Under the strongest restriction of the alternation number to 0, an infinite family of graphs with $`\text{D}(G)2\mathrm{log}^{}n+O(1)`$ is constructed.

#### Organization of the paper

The paper is organized as follows. Section 2 contains the relevant definitions from graph theory and logic as well as the basic facts on the Ehrenfeucht games. In Sections 3 and 4 we prove Theorems 1.1 and 1.2, restated there as Theorems 3.15 and 4.6. In Section 5 we prove a variant of Theorem 1.1 for distinguishing formulas whose alternation number is restricted to 0. The case of graphs with bounded vertex degree is considered in Section 6. Section 7 gives an exposition of the Weisfeiler-Lehman algorithm and applies Theorem 1.1 for its analysis. This section is mostly expository and, in particular, includes computation of an explicit constant in the Cai-Fürer-Immerman bound (2). Section 8 discusses the extensions of Theorems 1.1 and 1.2 to directed graphs and relational structures of maximum arity 2. Section 9 is devoted to $`k`$-uniform hypergraphs. Section 10 lists open problems.

## 2 Preliminaries

### 2.1 Structures

#### 2.1.1 Graphs

Given a graph $`G`$, we denote its vertex set by $`V(G)`$ and its edge set by $`E(G)`$. The order of $`G`$ will be sometimes denoted by $`|G|`$, that is, $`|G|=|V(G)|`$. The neighborhood of a vertex $`v`$ consists of all vertices adjacent to $`v`$ and is denoted by $`\mathrm{\Gamma }(v)`$.

The complement of $`G`$, denoted by $`\overline{G}`$, is the graph on the same vertex set $`V(G)`$ with all those edges that are not in $`E(G)`$. Given $`G`$ and $`G^{}`$ with disjoint vertex sets, we define the sum (or disjoint union) $`GG^{}`$ to be the graph with vertex set $`V(G)V(G^{})`$ and edge set $`E(G)E(G^{})`$.

A set $`SV(G)`$ is called independent (or stable) if it contains no pair of adjacent vertices. $`S`$ is a clique if all vertices in $`S`$ are pairwise adjacent. The independence (or stability) number of $`G`$, denoted by $`\alpha (G)`$, is the largest number of vertices in an independent set of $`G`$. The clique number of $`G`$, denoted by $`\omega (G)`$, is the biggest number of vertices in a clique of $`G`$. The complete graph of order $`n`$, denoted by $`K_n`$, is a graph of order $`n`$ whose vertex set is a clique. The complement of $`K_n`$ is the empty graph of order $`n`$. The complete bipartite graph with vertex classes $`V_1`$ and $`V_2`$, where $`V_1V_2=\mathrm{}`$, is a graph with the vertex set $`V_1V_2`$ and the edge set consisting of all edges $`\{v_1,v_2\}`$ for $`v_1V_1`$ and $`v_2V_2`$.

If $`XV(G)`$, then $`G[X]`$ denotes the subgraph induced by $`G`$ on $`X`$ (or spanned by $`X`$ in $`G`$ If $`X,YV(G)`$ are disjoint, then $`G[X,Y]`$ denotes the bipartite graph induced by $`G`$ on vertex classes $`X`$ and $`Y`$, that is, $`V(G[X,Y])=XY`$ and there are those edges of $`G`$ connecting a vertex in $`X`$ with a vertex in $`Y`$.

We call $`XV(G)`$ homogeneous if it is a clique or an independent set. We call a pair of disjoint sets $`X,YV(G)`$ homogeneous if $`G[X,Y]`$ is a complete or an empty bipartite graph.

#### 2.1.2 General relational structures

A vocabulary is a finite sequence $`R_1,\mathrm{},R_m`$ of relation symbols along with a sequence $`k_1,\mathrm{},k_m`$ of positive integers, where each $`k_i`$ is the arity of the respective $`R_i`$. If $``$ is a vocabulary, a finite structure $`G`$ over $``$ (or $``$-structure $`G`$) is a finite set $`V(G)`$, called the universe, along with relations $`R_1^G,\mathrm{},R_m^G`$, where $`R_i^G`$ has arity $`k_i`$. The order of a structure $`G`$ is the number of elements in the universe $`V(G)`$. If $`UV(G)`$, then $`G`$ induces on $`U`$ the structure $`G[U]`$ with universe $`V(G[U])=U`$ and relations $`R_1^{G[U]},\mathrm{},R_m^{G[U]}`$ such that $`R_i^{G[U]}(\overline{v})=R_i^G(\overline{v})`$ for every $`\overline{v}U^{k_i}`$. Two $``$-structures $`G`$ and $`H`$ are isomorphic if there is a one-to-one map $`\varphi :V(G)V(H)`$, called an isomorphism from $`G`$ to $`H`$, such that $`R_i^G(\overline{v})=R_i^H(\varphi (\overline{v}))`$ for every $`im`$ and all $`\overline{v}V(G)^{k_i}`$. If $`G`$ and $`H`$ are isomorphic, we write $`GH`$. An automorphism of $`G`$ is an isomorphism from $`G`$ to itself. If $`UV(G)`$ and $`WV(H)`$, we call a one-to-one map $`\varphi :UW`$ a partial isomorphism from $`G`$ to $`H`$ if it is an isomorphism from $`G[U]`$ to $`H[W]`$.

All these notions coincide with their standard graph-theoretic counterparts if we consider graphs structures with a single symmetric and anti-reflexive binary relation.

### 2.2 Logic

First order formulas are assumed to be over the set of connectives $`\{\neg ,,\}`$.

###### Definition 2.1

A sequence of quantifiers is a finite word over the alphabet $`\{,\}`$. If $`S`$ is a set of such sequences, then $`S`$ (resp. $`S`$) means the set of concatenations $`s`$ (resp. $`s`$) for all $`sS`$. If $`s`$ is a sequence of quantifiers, then $`\overline{s}`$ denotes the result of replacement of all occurrences of $``$ to $``$ and vice versa in $`s`$. The set $`\overline{S}`$ consists of all $`\overline{s}`$ for $`sS`$.

Given a first order formula $`\mathrm{\Phi }`$, its set of sequences of nested quantifiers is denoted by $`Nest(\mathrm{\Phi })`$ and defined by induction as follows:

1. $`Nest(\mathrm{\Phi })=\{ϵ\}`$ if $`\mathrm{\Phi }`$ is atomic; here, $`ϵ`$ denotes the empty word.
2. $`Nest(\neg \mathrm{\Phi })=\overline{Nest(\mathrm{\Phi })}`$.
3. $`Nest(\mathrm{\Phi }\mathrm{\Psi })=Nest(\mathrm{\Phi }\mathrm{\Psi })=Nest(\mathrm{\Phi })Nest(\mathrm{\Psi })`$.
4. $`Nest(x\mathrm{\Phi })=Nest(\mathrm{\Phi })`$ and $`Nest(x\mathrm{\Phi })=Nest(\mathrm{\Phi })`$.

###### Definition 2.2

The quantifier rank of a formula $`\mathrm{\Phi }`$, denoted by $`qr(\mathrm{\Phi })`$ is the maximum length of a string in $`Nest(\mathrm{\Phi })`$.

###### Proposition 2.3

Let $`\mathrm{\Phi }`$ be a first order formula with $`qr(\mathrm{\Phi })=k`$ and suppose that none of variables $`x_1,\mathrm{},x_k`$ occurs in $`\mathrm{\Phi }`$. Then there is an equivalent formula $`\mathrm{\Psi }`$ whose bound variables are all in the set $`\{x_1,\mathrm{},x_k\}`$.

Proof.  Let $`m=conn(\mathrm{\Phi })`$, where $`conn(\mathrm{\Phi })`$ denotes the number of connectives in $`\mathrm{\Phi }`$. We proceed by induction on $`k`$ and $`m`$. The base cases of $`k=0`$, $`m`$ arbitrary and $`m=0`$, $`k`$ arbitrary are straightforward. Assume the claim is true for all formulas $`\mathrm{\Phi }^{}`$ with $`qr(\mathrm{\Phi }^{})<k`$, $`conn(\mathrm{\Phi }^{})m`$ and with $`qr(\mathrm{\Phi }^{})k`$, $`conn(\mathrm{\Phi }^{})<m`$. If $`\mathrm{\Phi }=\neg \mathrm{\Phi }^{}`$, or $`\mathrm{\Phi }=\mathrm{\Phi }^{}\mathrm{\Phi }^{\prime \prime }`$, or $`\mathrm{\Phi }=\mathrm{\Phi }^{}\mathrm{\Phi }^{\prime \prime }`$, we apply the induction assumption to $`\mathrm{\Phi }^{}`$ and $`\mathrm{\Phi }^{\prime \prime }`$, obtain equivalent formulas $`\mathrm{\Psi }^{}`$ and $`\mathrm{\Psi }^{\prime \prime }`$, and set $`\mathrm{\Psi }=\neg \mathrm{\Psi }^{}`$, or $`\mathrm{\Psi }=\mathrm{\Psi }^{}\mathrm{\Psi }^{\prime \prime }`$, or $`\mathrm{\Psi }=\mathrm{\Psi }^{}\mathrm{\Psi }^{\prime \prime }`$ respectively. If $`\mathrm{\Phi }=x\mathrm{\Phi }^{}`$ or $`\mathrm{\Phi }=x\mathrm{\Phi }^{}`$, we apply the induction assumption to $`\mathrm{\Phi }^{}`$ to obtain an equivalent formula $`\mathrm{\Psi }^{}`$ with bound variables in $`\{x_1,\mathrm{},x_{k1}\}`$ and rename $`x`$ to $`x_k`$.

We adopt the notion of the alternation number of a formula (cf. \[23, Definition 2.8\]).

###### Definition 2.4

Given a sequence of quantifiers $`s`$, let $`alt(s)`$ denote the number of occurrences of $``$ and $``$ in $`s`$. The alternation number of a first order formula $`\mathrm{\Phi }`$, denoted by $`alt(\mathrm{\Phi })`$, is the maximum $`alt(s)`$ over $`sNest(\mathrm{\Phi })`$.

###### Definition 2.5

Let $`G`$ and $`G^{}`$ be non-isomorphic structures over the same vocabulary $``$ and $`\mathrm{\Phi }`$ be a first order formula over vocabulary $`\{=\}`$. We say that $`\mathrm{\Phi }`$ distinguishes $`G`$ from $`G^{}`$ if $`\mathrm{\Phi }`$ is true on $`G`$ but false on $`G^{}`$. By $`\text{D}(G,G^{})`$ (resp. $`\text{D}_k(G,G^{})`$) we denote the minimum quantifier rank of a formula (with alternation number at most $`k`$ resp.) distinguishing $`G`$ from $`G^{}`$. By $`\text{L}(G,G^{})`$ we denote the minimum $`l`$ such that over the variable set $`\{x_1,\mathrm{},x_l\}`$ there is a formula distinguishing $`G`$ from $`G^{}`$.

Note that

$$\text{L}(G,G^{})\text{D}(G,G^{})\text{D}_k(G,G^{})\text{D}_{k1}(G,G^{})$$

for every $`k1`$, where the first inequality follows from Proposition 2.3.

###### Definition 2.6

We say that $`\mathrm{\Phi }`$ defines a structure $`G`$ (up to isomorphism) if $`\mathrm{\Phi }`$ distinguishes $`G`$ from any non-isomorphic structure $`G^{}`$ over the same vocabulary. By $`\text{D}(G)`$ (resp. $`\text{D}_k(G)`$) we denote the minimum quantifier rank of a formula defining $`G`$ (with alternation number at most $`k`$ resp.).

###### Definition 2.7

Let $`G`$ be an $``$-structure. We define

$$\text{L}(G)=\mathrm{max}\left\{\text{L}(G,G^{}):G^{}\cong ̸G\right\},$$

where $`G^{}`$ ranges over all $``$-structures non-isomorphic with $`G`$.<sup>1</sup><sup>1</sup>1In other terms, $`\text{L}(G)`$ is equal to the minimum $`l`$ such that $`G`$ is definable in the $`l`$-variable fragment of the infinitary logic $`FO_\mathrm{}\omega `$ (see ).

###### Proposition 2.8

Let $`G`$ be an $``$-structure.

$`\text{D}(G)`$ $`=`$ $`\mathrm{max}\left\{\text{D}(G,G^{}):G^{}\cong ̸G\right\},`$
$`\text{D}_k(G)`$ $`=`$ $`\mathrm{max}\left\{\text{D}_k(G,G^{}):G^{}\cong ̸G\right\},`$
where $`G^{}`$ ranges over all $``$-structures non-isomorphic with $`G`$. Moreover, if $`G`$ is a graph, one can suppose that $`G^{}`$ ranges in the class of graphs rather than in the class of structures with a single binary relation.

Proof.  We prove the first equality; The proof of the second equality is similar. Given $`G^{}`$ non-isomorphic with $`G`$, let $`\mathrm{\Phi }_G^{}`$ be a formula of minimum quantifier rank distinguishing $`G`$ from $`G^{}`$, that is, $`qr(\mathrm{\Phi }_G^{})=\text{D}(G,G^{})`$. Let $`R=\mathrm{max}_G^{}qr(\mathrm{\Phi }_G^{})`$. We have $`\text{D}(G)R`$ because $`\text{D}(G)\text{D}(G,G^{})`$ for every $`G^{}`$. To prove the reverse inequality $`\text{D}(G)R`$, notice that $`G`$ is defined by the formula $`\mathrm{\Phi }=_G^{}\mathrm{\Phi }_G^{}`$ whose quantifier rank is $`R`$. The only problem is that $`\mathrm{\Phi }`$ is an infinite conjunction (a $`FO_\mathrm{}\omega `$-formula). However, as it is well known, over a fixed finite vocabulary there are only finitely many inequivalent first order formulas of bounded quantifier rank (see e.g. ). We therefore can reduce $`\mathrm{\Phi }`$ to a finite conjunction.

If $`G`$ is a graph, we do not need to consider $`G^{}`$ which are not graphs because those are distinguished from $`G`$ by formula $`x_1E(x_1,x_1)x_1x_2(E(x_1,x_2)\neg E(x_2,x_1))`$. Notice that this formula has rank 2 while no formula of rank 1 can define $`G`$.

###### Proposition 2.9

Let $`G`$ and $`G^{}`$ be non-isomorphic graphs, ordinary or directed.

1. $`\text{D}(G,G^{})=\text{D}(\overline{G},\overline{G^{}})`$, $`\text{D}_k(G,G^{})=\text{D}_k(\overline{G},\overline{G^{}})`$, and $`\text{L}(G,G^{})=\text{L}(\overline{G},\overline{G^{}})`$.
2. $`\text{D}(G)=\text{D}(\overline{G})`$, $`\text{D}_k(G)=\text{D}_k(\overline{G})`$, and $`\text{L}(G)=\text{L}(\overline{G})`$.

Proof.  1) If $`\mathrm{\Phi }`$ is a first order formula, let $`\overline{\mathrm{\Phi }}`$ be the result of putting $`\neg `$ in front of every occurrence of the predicate symbol $`E`$ in $`\mathrm{\Phi }`$. As easily seen, $`G\mathrm{\Phi }`$ iff $`\overline{G}\overline{\mathrm{\Phi }}`$. It remains to note that $`\mathrm{\Phi }`$ and $`\overline{\mathrm{\Phi }}`$ have the same number of variables, the same sequences of nested quantifiers, and, consequently, equal quantifier ranks and alternation numbers.

2) The second item follows from the first one by Proposition 2.8.

### 2.3 Games

The Ehrenfeucht game is played on a pair of structures of the same vocabulary. In the case of graphs, if we want to translate the definition below into the language of graph theory, we just have to replace structures with graphs, elements with vertices, and universe with vertex set.

###### Definition 2.10

Let $`G`$ and $`G^{}`$ be structures with disjoint universes. The $`r`$-round $`l`$-pebble Ehrenfeucht game on $`G`$ and $`G^{}`$, denoted by $`\text{Ehr}_r^l(G,G^{})`$, is played by two players, Spoiler and Duplicator, with $`l`$ pairwise distinct pebbles $`p_1,\mathrm{},p_l`$, each given in duplicate. Spoiler starts the game. A round consists of a move of Spoiler followed by a move of Duplicator. At each move Spoiler takes a pebble, say $`p_i`$, selects one of the structures $`G`$ or $`G^{}`$, and places $`p_i`$ on an element of this structure. In response Duplicator should place the other copy of $`p_i`$ on an element of the other structure. It is allowed to remove previously placed pebbles to another element and place more than one pebble on the same element.

After each round of the game, for $`1il`$ let $`x_i`$ (resp. $`x_i^{}`$) denote the element of $`G`$ (resp. $`G^{}`$) occupied by $`p_i`$, irrespectively of who of the players placed the pebble on this element. If $`p_i`$ is off the board at this moment, $`x_i`$ and $`x_i^{}`$ are undefined. If after every of $`r`$ rounds it is true that

$$x_i=x_j\text{ iff }x_i^{}=x_j^{}\text{ for all }1i<jl,$$

and the component-wise correspondence $`(x_1,\mathrm{},x_l)`$ to $`(x_1^{},\mathrm{},x_l^{})`$ is a partial isomorphism from $`G`$ to $`G^{}`$, this is a win for Duplicator; Otherwise the winner is Spoiler.

The $`k`$-alternation Ehrenfeucht game on $`G`$ and $`G^{}`$ is a variant of the game in which Spoiler is allowed to switch from one structure to another at most $`k`$ times during the game, i.e., in at most $`k`$ rounds he can choose the structure other than that in the preceding round.

The main technical tool we will use is given by the following statement.

###### Proposition 2.11

1. $`\text{L}(G,G^{})`$ equals the minimum $`l`$ such that Spoiler has a winning strategy in $`\text{Ehr}_r^l(G,G^{})`$ for some $`r`$.
2. $`\text{D}(G,G^{})`$ equals the minimum $`r`$ such that Spoiler has a winning strategy in $`\text{Ehr}_r^r(G,G^{})`$.
3. $`\text{D}_k(G,G^{})`$ equals the minimum $`r`$ such that Spoiler has a winning strategy in the $`k`$-alternation $`\text{Ehr}_r^r(G,G^{})`$.

We refer the reader to \[15, Theorem 6.10\] for the proof of the first claim, to \[9, Theorem 1.2.8\], \[15, Theorem 6.10\], or \[26, Theorem 2.3.1\] for the second claim, and to  for the third claim.

Proposition 2.11 immediately implies Propositions 2.3 and 2.9 that we earlier proved syntactically. Note that, if we prohibit removing pebbles from one vertex to another in $`\text{Ehr}_r^r(G,G^{})`$, this will not affect the outcome of the game.

###### Definition 2.12

We denote the variant of $`\text{Ehr}_r^r(G,G^{})`$ with removing pebbles prohibited by $`\text{Ehr}_r(G,G^{})`$.

The examples below are obtained by simple application of Proposition 2.11.

###### Example 2.13

1. $`\text{L}(K_m\overline{K_m},K_{m+1}\overline{K_{m1}})=m`$, $`\text{D}(K_m\overline{K_m},K_{m+1}\overline{K_{m1}})=m+1`$.
2. $`\text{L}(K_{m+1}\overline{K_m},K_m\overline{K_{m+1}})=\text{D}(K_{m+1}\overline{K_m},K_m\overline{K_{m+1}})=m+1`$.

## 3 Distinguishing non-isomorphic graphs

We here prove Theorem 1.1, that will be restated as Theorem 3.15. The proof is based on the characterization of $`\text{D}(G,G^{})`$ as the length of the Ehrenfeucht game on $`G`$ and $`G^{}`$ given by Proposition 2.11. The most essential part of the proof is contained in Lemma 3.13 that gives a winning strategy for Spoiler. This lemma will also be used in the next section to prove Theorem 1.2. We first introduce a couple of useful relations between vertices of a graph that will be intensively exploited in the course of the proofs.

### 3.1 Spoiler’s preliminaries

###### Definition 3.1

We call vertices $`u`$ and $`v`$ of a graph $`G`$ similar and write $`uv`$ if the transposition $`(uv)`$ is an automorphism of $`G`$. Let $`[u]_G=\{vV(G):vu\}`$, $`\sigma _G(u)=|[u]_G|`$, and $`\sigma (G)=\mathrm{max}_{uV(G)}\sigma _G(u)`$. If the graph is clear from the context, the subscript $`G`$ may be omitted. We will call the numbers $`\sigma (v)`$ and $`\sigma (G)`$ the similarity indices of the vertex $`v`$ and the graph $`G`$ respectively.

In other words, $`uv`$ if every third vertex $`t`$ is simultaneously adjacent or not to $`u`$ and $`v`$. We will say that $`t`$ separates $`u`$ and $`v`$ if $`t`$ is adjacent to exactly one of the two vertices.

###### Lemma 3.2

1. $``$ is an equivalence relation on $`V(G)`$.
2. Every equivalence class $`[u]`$ is a homogeneous set.

Proof.  The lemma is straightforward. The only care should be taken to check the transitivity. Given pairwise distinct $`u`$, $`v`$, and $`w`$, let us deduce from $`uv`$ and $`vw`$ that $`uw`$. For every $`tu,w`$, we need to show that $`u`$ and $`t`$ are adjacent iff so are $`w`$ and $`t`$. If $`tv`$, this is true because both adjacencies are equivalent to the adjacency of $`v`$ and $`t`$. There remains the case that $`t=v`$. Then $`u`$ and $`v`$ are adjacent iff so are $`u`$ and $`w`$ (as $`vw`$), which in turn holds iff so are $`w`$ and $`v`$ (as $`uv`$).

###### Definition 3.3

Given $`XV(G)`$, we will denote its complement by $`\overline{X}=V(G)X`$. Let $`u,v\overline{X}`$. We write $`u_Xv`$ if the identity map of $`X`$ onto itself extends to an isomorphism from $`G[X\{u\}]`$ to $`G[X\{v\}]`$.

In other words, $`u_Xv`$ if these vertices have the same adjacency pattern to $`X`$, i.e., $`\mathrm{\Gamma }(u)X=\mathrm{\Gamma }(v)X`$. Clearly, $`_X`$ is an equivalence relation on $`\overline{X}`$.

###### Definition 3.4

$`𝒞(X)`$ is the partition of $`\overline{X}`$ into $`_X`$-equivalence classes.

Let us notice a few straightforward properties of this partition. If $`X_1X_2`$, then $`𝒞(X_2)`$ is a refinement of $`𝒞(X_1)`$ on $`\overline{X_2}`$. For any $`X`$, the $``$-equivalence classes restricted to $`\overline{X}`$ refine the partition $`𝒞(X)`$.

###### Definition 3.5

Let $`XV(G)`$. We say that $`X`$ is $`𝒞`$-maximal if $`|𝒞(X\{u\})||𝒞(X)|`$ for any $`u\overline{X}`$.

###### Lemma 3.6

Let $`XV(G)`$ be $`𝒞`$-maximal. Then the partition $`𝒞(X)`$ has the following properties.

1. Every $`C`$ in $`𝒞(X)`$ is a homogeneous set.
2. If $`C_1`$ and $`C_2`$ are distinct classes in $`𝒞(X)`$ and have at least two elements each, then the pair $`C_1,C_2`$ is homogeneous.

Proof.  1) Suppose, to the contrary, that $`C`$ is neither a clique nor an independent set. Then $`C`$ contains three vertices $`u`$, $`v`$, and $`w`$ such that $`u`$ and $`v`$ are adjacent but $`u`$ and $`w`$ are not. However, if we move $`u`$ to $`X`$, then $`C`$ splits into two classes, one containing $`u`$ and another containing $`w`$. Hence the number of equivalence classes increases at least by 1, a contradiction.

2) Suppose that this is not true, for example, $`uC_1`$ is adjacent to $`vC_2`$ but not to $`wC_2`$. If we move $`u`$ to $`X`$, then $`C_2`$ splits into two non-empty classes and $`C_1\{u\}`$ stays non-empty. Again the number of equivalence classes increases, a contradiction.

###### Lemma 3.7

In every graph $`G`$, there exists a $`𝒞`$-maximal set of vertices $`X`$ such that

$$|𝒞(X)||X|+1.$$
(5)
In particular,

$$|X|\frac{|G|1}{2}.$$
(6)
Proof.  Such an $`X`$ can be constructed, starting from $`X=\mathrm{}`$, by repeating the following procedure. As long as there exists $`u\overline{X}`$ such that $`𝒞(X\{u\})>𝒞(X)`$, we move $`u`$ to $`X`$. As soon as there is no such $`u`$, we arrive at $`X`$ which is $`𝒞`$-maximal. The relation (5) is true as it holds at the beginning and is preserved in each step. The bound (6) follows from the inequality $`|X|+|𝒞(X)||G|`$.

###### Definition 3.8

Let $`XV(G)`$.

$`Y(X)`$ is the union of all single-element classes in $`𝒞(X)`$.

$`Z(X)=V(G)(XY(X))`$.

$`𝒟(X)`$ is the partition of $`Z(X)`$ defined by $`𝒟(X)=𝒞(XY(X))`$.

Clearly, $`𝒟(X)`$ refines the partition induced on $`Z(X)`$ by $`𝒞(X)`$.

###### Lemma 3.9

If $`XV(G)`$ is $`𝒞`$-maximal, then every class $`D`$ in $`𝒟(X)`$ consists of pairwise similar vertices. Thus, $`𝒟(X)`$ coincides with the partition induced on $`Z(X)`$ by $``$-equivalence classes.

Proof.  Let $`u`$ and $`v`$ be distinct elements of the same class $`D𝒟(X)`$. These vertices cannot be separated by any vertex $`tXY(X)`$ by the definition of $`𝒟(X)`$. Assume that they are separated by a $`tZ(X)`$. Let $`C_1`$ be the class in $`𝒞(X)`$ including $`D`$ and $`C_2`$ be the class in $`𝒞(X)`$ containing $`t`$. Since $`tY(X)`$, the class $`C_2`$ has at least one more element except $`t`$. If $`C_1C_2`$, moving $`t`$ to $`X`$ splits up $`C_1`$ and does not eliminate $`C_2`$. If $`C_1=C_2`$, moving $`t`$ to $`X`$ splits up this class and splits up or does not affect the others. In either case, $`|𝒞(X)|`$ increases, giving a contradiction.

###### Definition 3.10

Let $`\varphi :XX^{}`$ be a partial isomorphism from $`G`$ to $`G^{}`$. Let $`v\overline{X}`$ and $`v^{}\overline{X^{}}`$. We call vertices $`v`$ and $`v^{}`$ $`\varphi `$-similar and write $`v_\varphi v^{}`$ if $`\varphi `$ extends to an isomorphism from $`G[X\{v\}]`$ to $`G^{}[X^{}\{v^{}\}]`$.

Note that, if $`u_Xv`$ and $`u^{}_X^{}v^{}`$, then $`u_\varphi u^{}`$ iff $`v_\varphi v^{}`$. This makes the following definition correct.

###### Definition 3.11

Let $`\varphi :XX^{}`$ be a partial isomorphism from $`G`$ to $`G^{}`$. Let $`C𝒞(X)`$ and $`C^{}𝒞(X^{})`$. We call $`C`$ and $`C^{}`$ $`\varphi `$-similar and write $`C_\varphi C^{}`$ if $`v_\varphi v^{}`$ for some (equivalently, for all) $`vC`$ and $`v^{}C^{}`$.

Notice that, if $`u_\varphi u^{}`$ and $`v_\varphi v^{}`$, then the relations $`u_Xv`$ and $`u^{}_X^{}v^{}`$ are true or false simultaneously. It follows that the $`\varphi `$-similarity is a matching between the classes in $`𝒞(X)`$ and the classes in $`𝒞(X^{})`$, i.e., no class can have more than one $`\varphi `$-similar counterpart in the other graph.

### 3.2 Spoiler’s strategy

###### Definition 3.12

If $`vV(G)`$, the notation $`H=Gv`$ means that

* $`\sigma _G(v)2`$ and
* $`H`$ is a graph obtained from $`G`$ by adding a new vertex $`v^{}`$ so that $`[v]_H=[v]_G\{v^{}\}`$.

In other words, $`v^{}`$ is similar to $`v`$ and adjacent to $`v`$ depending on if $`[v]_G`$ is a clique or an independent set. Furthermore, we define $`G0v=G`$ and $`Glv=(G(l1)v)v`$ for a positive integer $`l`$.

Convention. In the sequel, writing $`H=Glv`$ we will not require the inclusion $`V(G)V(H)`$ assuming that $`H`$ is an arbitrary isomorphic copy of $`Glv`$. When considering the Ehrenfeucht game on $`G`$ and $`H`$, we will in addition suppose that the vertex sets of these graphs are disjoint.

###### Lemma 3.13

If $`G`$ and $`G^{}`$ are non-isomorphic graphs of orders $`n`$ and $`n^{}`$ respectively and $`nn^{}`$, then

$$\text{D}_1(G,G^{})(n+5)/2$$
(7)
unless $`G^{}=G(n^{}n)v`$ for some $`vV(G)`$.

Proof.  We will describe a strategy of Spoiler winning $`\text{Ehr}_r(G,G^{})`$ for $`r=(n+5)/2`$ unless $`G^{}=G(n^{}n)v`$. The strategy splits the game in two phases.

Phase 1

Spoiler selects a $`𝒞`$-maximal set of vertices $`XV(G)`$ such that $`|𝒞(X)||X|+1`$, whose existence is guaranteed by Lemma 3.7. Denote $`s=|X|`$, the number of rounds in Phase 1, and $`t=|𝒞(X)|`$. The bounds (5) and (6) read

$$ts+1$$
(8)
and

$$s\frac{n1}{2}.$$
(9)
If Duplicator loses in Phase 1, by (9) this happens within the claimed bound.

Let $`X^{}V(G^{})`$ consist of the vertices selected in Phase 1 by Duplicator and $`\varphi :XX^{}`$ be the bijection defined by the condition that $`x`$ and $`\varphi (x)`$ are selected by the players in the same round. We assume that Phase 1 finishes without Duplicator losing and hence $`\varphi `$ is a partial isomorphism from $`G`$ to $`G^{}`$. The following useful observation is straightforward from Definition 3.10.

Claim 3.13.1.  Whenever after Phase 1 Spoiler selects a vertex $`vV(G)V(G^{})`$, Duplicator responds with a $`\varphi `$-similar vertex or otherwise immediately loses.$`\mathrm{}`$

Phase 2

Denote the classes of $`𝒞(X)`$ by $`C_1,\mathrm{},C_t`$ and the classes of $`𝒞(X^{})`$ by $`C_1^{},\mathrm{},C_t^{}^{}`$. If there is a class $`C_i`$ or $`C_j^{}`$ without any $`\varphi `$-similar counterpart, respectively, in $`𝒞(X^{})`$ or in $`𝒞(X)`$, then Spoiler selects a vertex in this class and wins according to Claim 3.13, making at total $`s+2(n+3)/2`$ moves and at most one alternation between the graphs. From now on, we therefore assume that the $`\varphi `$-similarity determines a perfect matching between $`C_1,\mathrm{},C_t`$ and $`C_1^{},\mathrm{},C_t^{}^{}`$, where actually $`t=t^{}`$. For the notational convenience, we assume that $`C_i_\varphi C_i^{}`$ for all $`it`$.

Furthermore, if there is a singleton $`C_i`$ or $`C_j^{}`$ whose $`\varphi `$-similar counterpart has at least two vertices, Spoiler selects such two vertices and again wins according to Claim 3.13. We will therefore assume that $`|C_i|=1`$ iff $`|C_i^{}|=1`$. Without loss of generality, assume that $`|C_i|=|C_i^{}|=1`$ iff $`iq`$.

Denote $`Y=Y(X)`$ and $`Y^{}=Y(X^{})`$. Let $`C_i=\{y_i\}`$ and $`C_i^{}=\{y_i^{}\}`$ for $`iq`$. Thus, $`Y=\{y_1,\mathrm{},y_q\}`$ and $`Y^{}=\{y_1^{},\mathrm{},y_q^{}\}`$. Define $`\varphi ^{}:XYX^{}Y^{}`$, an extension of $`\varphi `$, by $`\varphi ^{}(y_i)=y_i^{}`$.

Claim 3.13.2.  $`\varphi ^{}`$ is a partial isomorphism from $`G`$ to $`G^{}`$, unless Spoiler wins in the next 2 moves with no alternation, having made at total $`s+2(n+3)/2`$ moves.

Proof of Claim.  For every $`iq`$, the restriction $`\varphi ^{}:XC_iX^{}C_i^{}`$ is an isomorphism because $`C_i`$ and $`C_i^{}`$ are $`\varphi ^{}`$-similar. The restriction $`\varphi ^{}:YY^{}`$ should be an isomorphism as well by the following reason. If there are $`i,jq`$ such that $`y_i`$ and $`y_j`$ are adjacent but $`y_i^{}`$ and $`y_j^{}`$ are not or vice versa, then Spoiler wins on the account of Claim 3.13 by selecting $`y_i`$ and $`y_j`$. $`\mathrm{}`$

We will therefore assume that $`\varphi ^{}`$ is indeed a partial isomorphism from $`G`$ to $`G^{}`$. Let $`Z=Z(X)`$ and $`Z^{}=Z(X^{})`$. Denote the classes of $`𝒟(X)`$ by $`D_1,\mathrm{},D_p`$ and the classes of $`𝒟(X^{})`$ by $`D_1^{},\mathrm{},D_p^{}^{}`$. Note that

$$ptq$$
(10)
and

$$p=tq\text{ iff }𝒟(X)=\{C_{q+1},\mathrm{},C_t\}.$$

Claim 3.13.3.  Whenever in Phase 2 Spoiler selects a vertex $`vZZ^{}`$, Duplicator responds with a $`\varphi ^{}`$-similar vertex or otherwise Spoiler wins in the next round at latest, with no alternation between $`G`$ and $`G^{}`$ in this round.

Proof of Claim.  Let $`u`$ be the vertex selected by Duplicator in response to $`v`$ and assume that $`u_\varphi ^{}v`$. Suppose that $`vZ^{}`$ (the case of $`vZ`$ is completely similar). If $`uZ`$, Duplicator has already lost by Claim 3.13. If $`uZ`$, there exists a vertex $`wXY`$ such that $`u`$ and $`w`$ are adjacent but $`v`$ and $`\varphi ^{}(w)`$ are not or vice versa. If $`wX`$, again Duplicator has already lost. If $`wY`$, then in the next round Spoiler selects $`\varphi ^{}(w)`$ and wins. $`\mathrm{}`$

Claim 3.13 implies that every class in $`𝒟(X)`$ or $`𝒟(X^{})`$ has a $`\varphi ^{}`$-similar counterpart in, respectively, $`𝒟(X^{})`$ or $`𝒟(X)`$ unless Spoiler wins making in Phase 2 two moves and at most one alternation between the graphs. We will therefore assume that this is true, that is, the $`\varphi ^{}`$-similarity determines a perfect matching between the classes $`D_1,\mathrm{},D_p`$ and $`D_1^{},\mathrm{},D_p^{}^{}`$, where actually $`p=p^{}`$. For the notational convenience, we assume that $`D_i_\varphi ^{}D_i^{}`$ for all $`ip`$.

Claim 3.13.4.  Unless Spoiler is able to win making 2 moves and at most 1 alternation in Phase 2, the following conditions are met.

1. For every $`ip`$, $`D_i`$ and $`D_i^{}`$ are simultaneously cliques or independent sets.
2. For every pair of distinct $`i,jp`$, $`G[D_i,D_j]`$ and $`G^{}[D_i^{},D_j^{}]`$ are simultaneously complete or empty bipartite graphs.

Proof of Claim.  1) Since $`D_i`$ consists of $`XY`$-similar and hence $`X`$-similar vertices, by Item 1 of Lemma 3.6, $`D_i`$ is either a clique or an independent set. This is actually true for the class $`C𝒞(X)`$ including $`D_i`$. If $`D_i^{}`$ has at least 2 vertices and is not a clique or an independent set simultaneously with $`D_i`$, Spoiler wins in 2 moves with 1 alternation by selecting in $`D_i^{}`$ two vertices which are non-adjacent in the former case and adjacent in the latter case. Indeed, if Duplicator responds with two vertices in $`C`$, those are in the opposite adjacency relation. If at least one Duplicator’s response is not in $`C`$, he loses by Claim 3.13. Note that this argument applies, in particular, in the case that $`|D_i^{}|2`$ but $`|D_i|=1`$.

2) If $`D_i`$ and $`D_j`$ are included in the same class $`C𝒞(X)`$, then by Item 1 of Lemma 3.6, $`G[D_i,D_j]`$ is either complete or empty. Similarly to the above, complete or empty respectively must be $`G^{}[D_i^{},D_j^{}]`$ unless Spoiler wins in 2 moves with 1 alternation. If $`D_i`$ and $`D_j`$ are included in different classes of $`𝒞(X)`$, $`C^1`$ and $`C^2`$ respectively, then, since both $`C^1`$ and $`C^2`$ have at least 2 vertices, $`G[D_i,D_j]`$ is either complete or empty according to Item 2 of Lemma 3.6. If $`G^{}[D_i^{},D_j^{}]`$ is not, respectively, complete or empty, then Spoiler wins in 2 moves with 1 alternation by selecting, respectively, non-adjacent or adjacent vertices, one in $`D_i^{}`$ and another in $`D_j^{}`$. Indeed, if Duplicator responds with one vertex in $`C^1`$ and another in $`C^2`$, those are in the opposite adjacency relation. Otherwise Duplicator loses by Claim 3.13. $`\mathrm{}`$

Thus, in what follows we assume that the two conditions in Claim 3.13 are obeyed. Together with the fact that the $`D_i`$’s and the $`D_i^{}`$’s are classes of the partitions $`𝒞(XY)`$ and $`𝒞(X^{}Y^{})`$, this implies that each $`D_i`$ and each $`D_i^{}`$ consists of pairwise similar vertices (in the sense of Definition 3.1). Moreover, since $`D_i_\varphi ^{}D_i^{}`$ for every $`ip`$, where $`\varphi ^{}`$ is an isomorphism from $`G[XY]`$ to $`G^{}[X^{}Y^{}]`$ and $`D_i`$ and $`D_i^{}`$ are simultaneously cliques or independent sets, the graphs $`G`$ and $`G^{}`$ are isomorphic iff $`|D_i|=|D_i^{}|`$ for every $`ip`$. Since $`G`$ and $`G^{}`$ are supposed to be non-isomorphic, there is $`D_i`$ such that $`|D_i||D_i^{}|`$. We will call such a $`D_i`$ useful (for Spoiler).

Claim 3.13.5.  If $`D_i`$ is useful and $`p>tq`$, then Spoiler is able to win having made in Phase 2 at most $`\mathrm{min}\{|D_i|,|D_i^{}|\}+2`$ moves and at most 1 alternation between $`G`$ and $`G^{}`$. If $`p=tq`$, then $`\mathrm{min}\{|D_i|,|D_i^{}|\}+1`$ moves and 1 alternation suffice.

Proof of Claim.  Spoiler selects $`\mathrm{min}\{|D_i|,|D_i^{}|\}+1`$ vertices in the larger of the classes $`D_i`$ and $`D_i^{}`$. Duplicator is enforced to at least once reply with not a $`\varphi ^{}`$-similar vertex. Then, according to Claim 3.13, Spoiler wins in the next move at latest. If $`p=tq`$ and hence the $`D`$-classes coincide with the $`C`$-classes, this extra move is not needed. This follows from Claim 3.13 because in this case violation of the $`\varphi ^{}`$-similarity causes violation of the $`\varphi `$-similarity. $`\mathrm{}`$

Suppose that there are two useful classes, $`D_i`$ and $`D_j`$. Observe that

$`|D_i|+|D_j|=|Z|{\displaystyle \underset{li,j}{}}|D_l|(nsq)(p2)`$
$`\{\begin{array}{cc}(nsq)(tq1)n2s\hfill & \text{if }p>tq\text{,}\hfill \\ (nsq)(tq2)n2s+1\hfill & \text{if }p=tq\text{,}\hfill \end{array}`$ (11)
where we use (10) and (8). It follows that one of the useful classes has at most $`(n2s+1)/2`$ vertices if $`p=tq`$ and at most $`(n2s)/2`$ vertices if $`p>tq`$. Therefore, if $`p=tq`$, Spoiler wins the game in at most $`s+(n2s+1)/2+1=(n+3)/2`$ moves and, if $`p>tq`$, in at most $`s+(n2s)/2+2=(n+4)/2`$ moves, which is within the required bound (7).

Finally, suppose that there is a unique useful class $`D_m`$. According to Claim 3.13, Spoiler is able to win in at most $`|D_m|+2`$ moves, with the total number of moves $`s+|D_m|+2`$ that is within the required bound (7) provided $`|D_m|=1`$. Thus, we arrive at the conclusion that the bound (7) may not hold true in the only case that there is exactly one useful class $`D_m`$ and $`|D_m|2`$. Note that we then have $`n^{}>n`$ and $`|D_m^{}|=|D_m|+(n^{}n)`$. It remains to notice that, if we remove $`n^{}n`$ vertices from $`D_m^{}`$, we obtain a graph isomorphic to $`G`$. It follows that $`G^{}=G(n^{}n)v`$ with $`vD_m`$.

Note a direct consequence of Lemma 3.13 and Proposition 2.8, that will be significantly improved in the next section.

###### Corollary 3.14

If $`\sigma (G)=1`$, then $`\text{D}_1(G)(n+5)/2`$.

We now restate and prove Theorem 1.1 from the introduction.

###### Theorem 3.15

If $`G`$ and $`G^{}`$ are non-isomorphic and have the same order $`n`$, then

$$\text{D}_1(G,G^{})(n+3)/2.$$
(12)
Proof.  Lemma 3.13 immediately gives an upper bound of $`(n+5)/2`$, which is a bit worse than we now claim. To improve it, we go trough lines of the proof of Lemma 3.13 but make use of the equality $`n=n^{}`$. The latter causes the following changes. Since $`n^{}=n`$, there must be at least two useful classes, $`D_i`$ and $`D_j`$, such that $`|D_i|<|D_i^{}|`$ and $`|D_j|>|D_j^{}|`$. If $`p=tq`$, the bound of $`(n+3)/2`$ has been actually proved, and we only need to tackle the case that $`p>tq`$. Similarly to (11), we have

$$2|D_i|+2|D_j^{}|+2|D_i|+|D_j|+|D_i^{}|+|D_j^{}|2\left((nsq)(p2)\right)2(n2s).$$

It follows that at least one of $`|D_i|`$ and $`|D_j^{}|`$ does not exceed $`(n2s1)/2`$. By Claim 3.13, Spoiler wins in totally at most $`s+(n2s1)/2+2=(n+3)/2`$ moves.

In the conclusion of this section, we state a lemma for further use in Section 6. This lemma is actually a corollary from the proof of Lemma 3.13. More precisely, it is a variant of Claim 3.13, where we take into account Lemma 3.9.

###### Lemma 3.16

Let $`G`$ and $`G^{}`$ be arbitrary non-isomorphic graphs. Suppose that $`XV(G)`$ is $`𝒞`$-maximal. Then Spoiler wins the 1-alternation Ehrenfeucht game on $`G`$ and $`G^{}`$ in at most $`|X|+\mathrm{max}_{vX}\sigma _G(v)+2`$ rounds.

## 4 Defining a graph

Our next goal is to prove Theorem 1.2. Below this theorem is restated as Theorem 4.6 after precisely defining the class of graphs whose members have a larger but efficiently computable $`\text{D}(G)`$ (see Definition 4.5). The proof is based on the following four lemmas.

###### Lemma 4.1

Let $`x_i`$ (resp. $`x_i^{}`$) denote the vertex of $`G`$ (resp. $`G^{}`$) selected in the $`i`$-th round of $`\text{Ehr}_r(G,G^{})`$. Then, as soon as a move of Duplicator violates the condition that $`x_ix_j`$ iff $`x_i^{}x_j^{}`$, Spoiler wins either immediately or in the next move possibly with one alternation between the graphs.

Proof.  Suppose, for example, that Duplicator selects $`x_j^{}`$ so that $`x_i^{}\sim ̸x_j^{}`$ while $`x_ix_j`$ for some $`i<j`$. Suppose that the correspondence between the $`x_m`$’s and the $`x_m^{}`$’s, $`1mj`$, is still a partial isomorphism. Then there is $`yV(G^{})`$ adjacent to exactly one of $`x_i^{}`$ and $`x_j^{}`$. Note that such $`y`$ could not be selected by the players previously. In the next move Spoiler selects $`y`$ and wins, whatever the move of Duplicator is.

###### Lemma 4.2

Let $`|G|=n`$, $`vV(G)`$, $`\sigma _G(v)=s`$, and $`G^{}=Glv`$ with $`l1`$. Then

$$s+1\text{L}(G,G^{})\text{D}_1(G,G^{})s+1+\frac{n+1}{s+1}\{\begin{array}{cc}(n+5)/2\text{ for }1s(n1)/2,\hfill & \\ s+31/(n/2+1)\text{ for }sn/2.\hfill & \end{array}$$

Proof.  The lower bound is given by the following strategy for Duplicator in $`\text{Ehr}_r^s(G,G^{})`$. Whenever Spoiler selects a vertex outside $`[v]`$ in either graph, Duplicator selects its copy in the other graph. If Spoiler selects an unoccupied vertex similar to $`v`$, then Duplicator selects an arbitrary unoccupied vertex similar to $`v`$ in the other graph. Clearly, this strategy preserves the isomorphism arbitrarily long, that is, is winning for every $`r`$.

The upper bound for $`\text{D}_1(G,G^{})`$ is ensured by the following Spoiler’s strategy winning in the 1-alternation $`\text{Ehr}_r(G,G^{})`$ for $`r=s+1+\frac{n+1}{s+1}`$. In the first round Spoiler selects a vertex in $`[v]_G^{}`$. Suppose that Duplicator replies with a vertex in $`[u]_G`$.

Case 1: $`|[u]_G|s`$. Spoiler continues to select vertices in $`[v]_G^{}`$. In the $`(s+1)`$-th round at latest, Duplicator selects a vertex outside $`[u]_G`$. Spoiler wins in the next move by Lemma 4.1, having made at most $`s+2`$ moves and one alternation.

Case 2: $`|[u]_G|s+1`$. Spoiler selects one vertex in each similarity class of $`G^{}`$ containing at least $`s+1`$ vertices. Besides $`[v]_G^{}`$, there can be at most $`\frac{ns}{s+1}`$ such classes. At latest in the $`\frac{ns}{s+1}+1`$-th round Duplicator selects either another vertex in a class with an already selected vertex (then Spoiler wins in one extra move by Lemma 4.1) or a vertex in $`[w]_G`$ with $`|[w]_G|s`$. In the latter case Spoiler selects $`s`$ more vertices in the corresponding class of $`G^{}`$. Duplicator is forced to move outside $`[w]_G`$ and loses in the next move by Lemma 4.1. Altogether there are made at most $`\frac{ns}{s+1}+1+s+1s+1+\frac{n+1}{s+1}`$ moves.

If $`sn/2`$, the last inequality of the lemma is straightforward and, if $`2s(n1)/2`$, it follows from the fact that the function $`f(x)=x+\frac{n+1}{x}`$ on $`[2,(n+1)/2]`$ attains its maximum at the endpoints of this range.

Using Lemma 4.2, Lemma 3.13 can now be refined.

###### Lemma 4.3

If $`G`$ and $`G^{}`$ are graphs of orders $`nn^{}`$, then

$$\text{D}_1(G,G^{})(n+5)/2$$

unless

$$\sigma (G)n/2\text{ and }G^{}=G(n^{}n)v\text{ for some }vV(G)\text{ with }\sigma _G(v)=\sigma (G).$$
(13)
In the latter case we have

$$\sigma (G)+1\text{L}(G,G^{})\text{D}_1(G,G^{})\sigma (G)+2.$$
(14)
Note that the condition (13) determines $`G^{}`$ up to isomorphism with two exceptions if $`n`$ is even. Namely, for $`G=K_m\overline{K_m}`$ and $`G=\overline{K_m\overline{K_m}}`$ there are two ways to extend $`G`$ to $`G^{}`$.

The gap between the bounds (14) can be completely closed.

###### Lemma 4.4

Let $`G`$ and $`G^{}`$ be graphs of orders $`nn^{}`$. Assume the condition (13). Then $`\text{L}(G,G^{})=\sigma (G)+1`$ for all such $`G`$ and $`G^{}`$, $`\text{D}_0(G,G^{})=\sigma (G)+1`$ if $`[v]_G`$ is an inclusion maximal homogeneous set, and $`\text{D}(G,G^{})=\sigma (G)+2`$ if $`[v]_G`$ is not.

Using the inequality $`|[v]_G|n/2`$ and the mutual similarity of vertices in $`[v]_G`$, one can easily show that $`[v]_G`$ is a maximal (with respect to the inclusion) clique or independent set iff $`|[v]_G|=\alpha (G)`$ or $`|[v]_G|=\omega (G)`$ respectively. However, the former condition is more preferable because it is efficiently verifiable.

Proof.  For simplicity we assume that $`[v]_G`$ is an independent set. Otherwise we can switch to $`\overline{G}`$ and $`\overline{G^{}}`$ by Proposition 2.9. Denote $`s=\sigma (G)=|[v]_G|`$.

Case 1: $`[v]_G`$ is maximal independent. We show the bound $`\text{D}_0(G,G^{})s+1`$ by describing Spoiler’s strategy winning the 0-alternation $`\text{Ehr}_{s+1}(G,G^{})`$. Spoiler selects $`s+1`$ vertices in $`[v]_G^{}`$. Duplicator is forced to select at least one vertex $`u_1[v]_G`$ and at least one vertex $`u_2[v]_G`$. Since $`[v]_G`$ is a maximal independent set, $`u_1`$ and $`u_2`$ are adjacent and this is Spoiler’s win.

Case 2: $`[v]_G`$ is not maximal. We first show the bound $`\text{L}(G,G^{})s+1`$ by describing Spoiler’s strategy winning $`\text{Ehr}_{s+2}^{s+1}(G,G^{})`$. As in the preceding case, Spoiler selects $`s+1`$ vertices in $`[v]_G^{}`$ and there are $`u_1[v]_G`$ and $`u_2[v]_G`$ selected in response by Duplicator. Assume that $`u_1`$ and $`u_2`$ are not adjacent for otherwise Duplicator loses immediately. Since $`u_1`$ and $`u_2`$ are not similar, there is $`uV(G)\{u_1,u_2\}`$ adjacent to exactly one of $`u_1`$ and $`u_2`$. It follows that $`u[v]_G`$. Note that $`u`$ could not be selected by Duplicator in the first $`s+1`$ rounds without immediately losing. Therefore, Duplicator has selected in $`[v]_G`$ at least two vertices, say, $`u_0`$ and $`u_1`$. In the $`(s+2)`$-th round Spoiler removes the pebble from $`u_0`$ to $`u`$ and wins because the counterparts of $`u_1`$ and $`u_2`$ in $`G^{}`$ are similar and hence equally adjacent or non-adjacent to any counterpart of $`u`$.

We now show the bound $`\text{D}(G,G^{})>s+1`$ by describing Duplicator’s strategy winning $`\text{Ehr}_{s+1}(G,G^{})`$. Whenever Spoiler selects a vertex of either graph, Duplicator selects its copy in the other graph, with the convention that the copy of a vertex in $`[v]_G^{}`$ is an arbitrary unselected vertex in $`[v]_G`$. This is impossible in the only case when Spoiler selects $`s+1`$ vertices all in $`[v]_G^{}`$. Then Duplicator, in addition to $`s`$ vertices of $`[v]_G`$, selects one more vertex extending $`[v]_G`$ to a larger independent set.

###### Definition 4.5

$`𝒮`$ is the class of graphs $`G`$ with $`\sigma (G)>(|G|+3)/2`$. $`𝒮_1`$ is the class of graphs $`G`$ with $`\sigma (G)>(|G|+3)/2`$ such that the largest similarity class is an inclusion maximal homogeneous set. $`𝒮_2`$ is the class of graphs $`G`$ with $`\sigma (G)>(|G|+1)/2`$ such that the largest similarity class is not an inclusion maximal homogeneous set.

###### Theorem 4.6

$`\text{L}(G)(|G|+5)/2`$ with the exception of all graphs in $`𝒮`$. If $`G𝒮`$, then $`\text{L}(G)=\sigma (G)+1`$.

$`\text{D}_1(G)(|G|+5)/2`$ with the exception of all graphs in $`𝒮_1𝒮_2`$. If $`G𝒮_1`$, then $`\text{D}(G)=\sigma (G)+1`$; If $`G𝒮_2`$, then $`\text{D}(G)=\sigma (G)+2`$.

Proof.  We prove the theorem for $`\text{L}(G)`$; the proof for $`\text{D}(G)`$ is completely similar. Recall that $`\text{L}(G)=\mathrm{max}\left\{\text{L}(G,G^{}):G^{}\cong ̸G\right\}`$. We consider two cases.

Case 1: $`\sigma (G)<|G|/2`$. For every $`G^{}\cong ̸G`$ we have $`\text{L}(G,G^{})(|G|+5)/2`$ by Lemma 4.3. Since $`G𝒮`$, the theorem in Case 1 is true.

Case 2: $`\sigma (G)|G|/2`$. If $`G^{}=Glv`$ for some $`l1`$ and $`vV(G)`$ with $`\sigma _G(v)=\sigma (G)`$, then $`\text{L}(G,G^{})=\sigma (G)+1`$ by Lemma 4.4. By the definition of $`𝒮`$, we therefore have $`\text{L}(G,G^{})(|G|+5)/2`$ if $`G𝒮`$ and $`\text{L}(G,G^{})>(|G|+5)/2`$ if $`G𝒮`$.

If $`G=G^{}lv`$ for some $`l1`$, $`G^{}`$ with $`\sigma (G^{})|G^{}|/2`$, and $`vV(G^{})`$ with $`\sigma _G^{}(v)=\sigma (G^{})`$, then $`\text{L}(G,G^{})=\sigma (G^{})+1`$ by Lemma 4.4 and hence $`\text{L}(G,G^{})<\sigma (G)+1`$.

If $`G^{}`$ is any other graph non-isomorphic with $`G`$, then $`\text{L}(G,G^{})(|G|+5)/2`$ by Lemma 4.3.

Summarizing, if $`G𝒮`$, we have $`\mathrm{max}_G^{}\text{L}(G,G^{})(|G|+5)/2`$ and, if $`G𝒮`$, we have $`\mathrm{max}_G^{}\text{L}(G,G^{})=\sigma (G)+1>(|G|+5)/2`$. Thus, in Case 2 the theorem is also true.

A variant of Theorem 4.6 was stated in the introduction as Theorem 1.2. To link the two theorems, in the latter we should set $`𝒞=𝒮_1𝒮_2`$. The efficiency statements of Theorem 1.2 are due to the following lemma. Referring to efficient algorithms, we mean random access machines whose running time on graphs of order $`n`$, represented by adjacency matrices, is $`O(n^2\mathrm{log}n)`$.

###### Lemma 4.7

1. There is an efficient algorithm that, given $`G`$, finds the partition of $`V(G)`$ into classes of pairwise similar vertices.
2. Given $`G`$, the number $`\sigma (G)`$ is efficiently computable.
3. The classes $`𝒮`$, $`𝒮_1`$, and $`𝒮_2`$ defined in Definition 4.5 are efficiently recognizable.

Proof.  Notice that non-adjacent vertices are in the same similarity class iff the corresponding rows of the adjacency matrix are identical. Thus, in order to find similarity classes containing more than one element, it suffices, using the standard $`O(n\mathrm{log}n)`$-comparison sorting, to arrange rows of the adjacency matrices of $`G`$ and $`\overline{G}`$ in the lexicographic order. This proves Item 1. The other two are its direct consequences.

###### Remark 4.8

An analysis of the proofs shows that Theorem 4.6 is even more constructive: Given a graph $`G`$, one can efficiently construct its defining formula whose quantifier rank is as small as possible if $`G𝒮_1𝒮_2`$ and does not exceed $`(n+5)/2`$ if $`G𝒮_1𝒮_2`$.

###### Remark 4.9

Note that Definition 3.1 of the similarity relation makes sense for an arbitrary structure. Lemma 4.1 generalizes over any class of $``$-structures, for an arbitrary vocabulary $``$: If precisely one of the relations $`x_ix_j`$ and $`x_i^{}x_j^{}`$ holds, then Spoiler is able to win in at most $`k1`$ next moves, where $`k`$ is the maximum relation arity of $``$. If, say, $`x_i^{}\sim ̸x_j^{}`$ but $`x_ix_j`$, the only what Spoiler needs to do is to exhibit $`u_1,\mathrm{},u_{k1}V(G^{})`$ such that there is a sequence consisting of elements $`u_1,\mathrm{},u_{k1}`$ and a variable $`x`$ that satisfies some relation with $`x=x_i`$ and does not satisfy the same relation with $`x=x_j`$.

Lemma 4.2, whose proof uses only Lemma 4.1 and the definition of similarity classes, carries over to structures with maximum relation arity $`k`$ giving bounds

$$s+1\text{L}(G,G^{})\text{D}_1(G,G^{})s+k1+\frac{n+1}{s+1}.$$

## 5 Distinguishing graphs by zero-alternation formulas

Theorem 3.15 is proved in a stronger form: The class of distinguishing formulas is restricted to those with alternation number 1. We now further restrict the alternation number to the smallest possible value of 0. In terms of the Ehrenfeucht game, we restrict the ability of Spoiler to alternate between graphs during play (see Item 3 of Proposition 2.11). Moreover, let us call a formula existential (resp. universal) if it is in the negation normal form and all quantifiers in it are existential (resp. universal). It is easy to prove that, if a graph $`G`$ is distinguished from another graph $`G^{}`$ by a formula with alternation number 0, then $`G`$ is distinguished from $`G^{}`$ by either existential or universal formula of the same quantifier rank. Somewhat surprizingly, this restriction of the class of distinguishing formulas turns out not so essential in the worst case.

###### Theorem 5.1

If $`G`$ and $`G^{}`$ are non-isomorphic and have the same order $`n`$, then $`\text{D}_0(G,G^{})(n+5)/2`$.

Proof.  We will describe a strategy for Spoiler winning the 0-alternation game $`\text{Ehr}_{(n+5)/2}(G,G^{})`$. Given a set of vertices $`X`$ in a graph and a partial isomorphism $`\varphi :XX^{}`$ to another graph, we will use the notions introduces in Section 3.1: the partitions $`𝒞(X)`$ and $`𝒟(X)`$, the set $`Y(X)`$, and the $`\varphi `$-similarity relation $`_\varphi `$. We set the following notation:

$`s(X)`$ $`=`$ $`|X|,`$
$`t(X)`$ $`=`$ $`|𝒞(X)|,`$
$`c(X)`$ $`=`$ $`\mathrm{max}\left\{|C|:C𝒞(X)\right\},`$
$`d(X)`$ $`=`$ $`\mathrm{max}\left\{|D|:D𝒟(X)\right\}.`$
For brevity, we will not indicate the dependence on $`X`$, writing merely $`Y`$, $`s`$, $`t`$, $`c`$, and $`d`$.

At the start of the game Spoiler, over all choices of $`H=G`$ or $`H=G^{}`$, and of $`XV(H)`$ with $`ts+1`$ takes one which

first maximizes $`s`$;

then, if there is still some choice, minimizes $`c`$;

finally, minimizes $`d`$.

Let us assume $`H=G`$. As $`s+tn`$, we have $`s(n1)/2`$.

Spoiler selects all vertices in $`X`$ in any order. Denote the set of vertices of $`G^{}`$ selected in response by Duplicator by $`X^{}`$. Let $`t^{}=t(X^{})`$ and $`c^{}=c(X^{})`$. Assume that Duplicator has not lost up to now, that is, has managed to maintain the partial isomorphism $`\varphi :XX^{}`$. Let $`C_1,\mathrm{},C_t`$ (resp. $`C_1^{},\mathrm{},C_t^{}^{}`$) be all classes in $`𝒞(X)`$ (resp. $`𝒞(X^{})`$).

If there is a class $`C_i`$ without $`\varphi `$-similar counterpart in $`𝒞(X^{})`$, Spoiler wins in one move by selecting a vertex in $`C_i`$, having made $`s+1(n+1)/2`$ moves at total. We therefore suppose that $`t^{}t`$ and, for every $`it`$, the classes $`C_i`$ and $`C_i^{}`$ are $`\varphi `$-similar. Thus, $`t^{}s+1=s^{}+1`$ and, by Criterion 2 of the choice of $`(H,X)`$, we conclude that there is $`C_m^{}`$ such that $`|C_i||C_m^{}|`$ for all $`i`$.

If $`t^{}>t`$, define $`C_i=\mathrm{}`$ for all $`t<it^{}`$. Suppose first that for some $`it^{}`$ we have $`|C_i||C_i^{}|`$. As $`G`$ and $`G^{}`$ have the same order, there must be an $`it^{}`$ with $`|C_i|>|C_i^{}|`$. Spoiler wins by selecting $`|C_i^{}|+1`$ vertices inside $`C_i`$. Observe that $`|C_i^{}|<|C_i||C_m^{}|`$ and that

$$2|C_i^{}|+1|C_i^{}|+|C_m^{}|(ns^{})(t^{}2)n2s+1.$$

The total number of Spoiler’s moves is therefore at most $`s+|C_i^{}|+1n/2+1`$, within the required bound.

Suppose from now on, that $`t^{}=t`$ and for any $`it`$ we have $`|C_i|=|C_i^{}|`$. In particular,

$$c=c^{}.$$
(15)
Without loss of generality, assume that $`|C_i|=|C_i^{}|=1`$ precisely for $`iq`$. Note that $`Y=_{i=1}^qC_i`$ and $`Y^{}=_{i=1}^qC_i^{}`$, where $`Y^{}=Y(X^{})`$. Similarly to the proof of Lemma 3.13, we extend $`\varphi `$ to $`\varphi ^{}:XYX^{}Y^{}`$ by the condition that $`\varphi ^{}`$ maps each $`C_i`$ with $`iq`$ onto $`C_i^{}`$. Similarly to Claim 3.13, if $`\varphi ^{}`$ is not an isomorphism from $`G[XY]`$ to $`G^{}[X^{}Y^{}]`$, then Spoiler wins by selecting 2 vertices in $`Y`$, having made altogether $`s+2(n+3)/2`$ moves. In the sequel we therefore suppose that $`\varphi ^{}`$ is a partial isomorphism from $`G`$ to $`G^{}`$. We will make use of the following observation, provable similarly to Claim 3.13. Let $`Z=V(G)(XY)`$.

Claim 5.1.1.  From now on, whenever Spoiler selects a vertex $`vZ`$, Duplicator responds with a $`\varphi ^{}`$-similar vertex or otherwise loses in the next round at latest with no alternation.$`\mathrm{}`$

Let $`D_1,\mathrm{},D_p`$ (resp. $`D_1^{},\mathrm{},D_p^{}^{}`$) be all classes in $`𝒟(X)`$ (resp. $`𝒟(X^{})`$). We now claim that every class $`D_i`$ has a $`\varphi ^{}`$-similar counterpart in $`𝒟(X^{})`$ or otherwise Spoiler wins in at most 2 next moves with no alternation, having made altogether at most $`s+2(n+3)/2`$ moves. Indeed, if a $`D_i`$ has no $`\varphi ^{}`$-similar counterpart, Spoiler selects a vertex in the $`D_i`$ and wins either immediately or in the next move by Claim 5.1. We hence will assume that $`p^{}p`$ and, for all $`ip`$, the classes $`D_i`$ and $`D_i^{}`$ are $`\varphi ^{}`$-similar. If $`p^{}>p`$, define $`D_i=\mathrm{}`$ for all $`p<ip^{}`$.

We now show that each class in $`𝒟(X)`$ or $`𝒟(X^{})`$ consists of pairwise similar vertices as defined in Definition 3.1. Suppose, to the contrary, that vertices $`u`$ and $`v`$ lie in the same $`D_i`$ and some $`w`$ is connected to one of $`u,v`$ but not to the other. By the definition of $`D_i`$ such $`w`$ must lie in $`Z`$; but then moving $`w`$ to $`X`$ we increase $`t`$ at least by one. Indeed, if $`w`$ belongs to the same $`D_i`$, the class $`C^1𝒞(X)`$ including $`D_i`$ splits up into at least two subclasses, containing $`u`$ and $`v`$ respectively, while no class in $`𝒞(X)`$ disappears. If $`w`$ belongs to another $`D_j`$, the class $`C^1`$ splits up as well, while the class $`C^2𝒞(X)`$ including $`D_j`$ still stays because it has at least two elements. Since the relation $`ts+1`$ is preserved, we get a contradiction with Criterion 1 in the choice of $`(H,X)`$. The same argument applies for $`𝒟(X^{})`$.

It follows that, for any distinct $`i,jp`$, each of $`G[D_i]`$, $`G^{}[D_i^{}]`$, $`G[D_i,D_j]`$ and $`G^{}[D_i^{},D_j^{}]`$ is either complete or empty. The same is true about every $`G[D_i,\{v\}]`$ and $`G^{}[D_i^{},\{v^{}\}]`$ for $`vXY`$ and $`v^{}X^{}Y^{}`$. We now claim that, for every $`ip`$, $`jp`$ such that $`ji`$, and $`vXY`$,

1. $`G[D_i]`$ with at least 2 vertices is complete iff $`G^{}[D_i^{}]`$ is,
2. $`G[D_i,D_j]`$ is complete iff $`G^{}[D_i^{},D_j^{}]`$ is, and
3. $`G[D_i,\{v\}]`$ is complete iff $`G^{}[D_i^{},\{\varphi ^{}(v)\}]`$ is

or otherwise Spoiler wins in at most 3 next moves with no alternation, having made altogether $`s+3(n+5)/2`$ moves. For example, consider the case that $`G[D_i]`$ has at least 2 vertices and is complete but $`G^{}[D_i^{}]`$ is empty. Then Spoiler selects two vertices in $`D_i`$. If both Duplicator’s responses are in $`D_i^{}`$, he loses immediately. Otherwise Duplicator responds at least once with a vertex which is not $`\varphi ^{}`$-similar. Then Spoiler wins in the next move according to Claim 5.1.

We therefore suppose that the above three conditions are obeyed for all $`i,jp`$ and $`vXY`$. It follows that, if $`|D_i|=|D_i^{}|`$ for all $`ip^{}`$ and, in particular, $`p^{}=p`$, then $`G`$ and $`G^{}`$ should be isomorphic. Since this is not so, there is $`lp^{}`$ such that $`|D_l||D_l^{}|`$. As $`G`$ and $`G^{}`$ have the same order, we can assume that

$$|D_l|>|D_l^{}|.$$
(16)
Note that $`p^{}>tq`$ for else the $`D^{}`$-classes are identical to the $`C^{}`$-classes, which contradicts (16). Thus

$$p^{}s+2q.$$
(17)
It follows from (15) and Criterion 3 of the choice of $`(H,X)`$ that there exists $`kp^{}`$ such that $`|D_i||D_k^{}|`$ for all $`i`$. We have $`|D_l^{}|<|D_l||D_k^{}|`$, so

$$2|D_l^{}|+1|D_l^{}|+|D_k^{}|(nsq)(p^{}2)n2s,$$

where the latter inequality follows from (17).

Now, Spoiler selects $`|D_l^{}|+1`$ vertices inside $`D_l`$. Duplicator cannot reply to this with all moves in $`D_l^{}`$ and hence replies at least once with a vertex which is not $`\varphi ^{}`$-similar. According to Claim 5.1, Spoiler wins either immediately or in the next round. The total number of moves is at most

$$s+|D_l^{}|+1+1s+\frac{n2s1}{2}+2=\frac{n+3}{2},$$

as required.

## 6 Defining graphs of bounded degree

The degree of a vertex $`v`$ in a graph, denoted by $`\mathrm{deg}(v)`$, is the number of edges incident to $`v`$. The maximum degree of a graph $`G`$ is defined by $`\mathrm{\Delta }(G)=\mathrm{max}_{vV(G)}\mathrm{deg}(v)`$. The distance between vertices $`v`$ and $`u`$ in a graph, $`dist(v,u)`$, is the smallest number of edges in a path from $`v`$ to $`u`$. If $`UV(G)`$, then $`dist(v,U)=\mathrm{min}_{uU}dist(v,u)`$. Recall that the similarity index $`\sigma _G(v)`$ of a vertex $`v`$ is defined in Definition 3.1.

###### Lemma 6.1

If $`v`$ is a non-isolated vertex of a graph $`G`$, then

$$\sigma _G(v)\mathrm{\Delta }(G)+1.$$
(18)
Proof.  By Lemma 3.2, the similarity class $`[v]_G`$ is either a clique or an independent set. If it is a clique, then the bound (18) is clear. Otherwise there must exist a vertex $`u[v]_G`$ adjacent to $`v`$. As $`u`$ is adjacent to every vertex in $`[v]_G`$, we have $`\sigma _G(v)\mathrm{deg}(u)\mathrm{\Delta }(G)`$ in this case.

Recall that, while a formula defining a graph $`G`$ distinguishes $`G`$ from all non-isomorphic graphs, a formula identifying $`G`$ distinguishes $`G`$ from all non-isomorphic graphs of the same order. While the minimum quantifier rank of a defining formula with alternation number at most $`k`$ is denoted by $`\text{D}_k(G)`$, for an identifying formula it is denoted by $`\text{}_k(G)`$. By Proposition 2.8 we have

$$\text{D}_k(G)=\mathrm{max}\left\{\text{D}_k(G,G^{}):G^{}\cong ̸G\right\},$$

and likewise

$$\text{}_k(G)=\mathrm{max}\left\{\text{D}_k(G,G^{}):G^{}\cong ̸G,|G^{}|=|G|\right\}.$$

###### Theorem 6.2

Let $`d2`$. If $`G`$ is a graph of order $`n`$ with $`\mathrm{\Delta }(G)=d`$ that has no isolated vertex and no isolated edge, then

$$\text{D}_1(G)c_dn+d^2+d+7/2$$

for a constant $`c_d=\frac{1}{2}\frac{1}{10}d^{2d5}`$. If $`G`$ is an arbitrary graph of order $`n`$ with $`\mathrm{\Delta }(G)=d`$, then the same bound holds for $`\text{}_1(G)`$.

The constant $`c_d`$ as stated in the theorem is far from being best possible. We do not try to optimize it; Our goal is more moderate, just to show the existence of a $`c_d`$ strictly less than $`1/2`$. A tight, up to an additive constant, bound is easy to find for $`d=2`$. If $`\mathrm{\Delta }(G)=2`$ and $`G`$ has no isolated vertices and edges, the graph is a sum of paths and cycles. Using bounds $`\text{D}_0(C_n,C_m)\mathrm{log}_2n+O(1)`$ and $`\text{D}_0(P_n,P_m)\mathrm{log}_2n+O(1)`$ for $`mn`$ (e.g. \[26, Theorem 2.1.2\]), one can show that $`\text{D}_1(G)n/3+O(1)`$.

Proof of Theorem 6.2 We will prove the bounds for $`\text{D}_1(G)`$ and $`\text{}_1(G)`$ in parallel. We actually have to estimate $`\text{D}_1(G,G^{})`$ in two cases:

1. $`G`$ has no isolated vertices and edges; $`G^{}\cong ̸G`$ has arbitrary order.
2. $`G`$ is arbitrary; $`G^{}\cong ̸G`$ has order $`n`$.

In fact, almost all proof will go through for the most general case that $`G^{}\cong ̸G`$, with no other assumptions. Only once we will need the condition $`|G^{}|=|G|`$ for $`G`$ with isolated vertices or edges, and this will be explicitly stated.

Referring to Item 3 of Proposition 2.11, we design a strategy for Spoiler winning the 1-alternation Ehrenfeucht game on $`G`$ and $`G^{}`$ in at most $`c_dn+d^2+d+7/2`$ rounds. Clearly, we may assume that $`\mathrm{\Delta }(G^{})d`$ for otherwise Spoiler wins in at most $`d+2`$ moves by selecting a star $`K_{1,d+1}`$ in $`G^{}`$.

A component of a graph is a maximal connected induced subgraph. We call a component small if it has at most $`d^2+1`$ vertices. Throughout the proof we use the following notation.

$`AV(G)`$ consists of all vertices in small components.
$`B_1V(G)`$ consists of all isolated vertices.
$`B_2V(G)`$ consists of all vertices in isolated edges.
$`B=B_1B_2`$.
$`a=|A|`$.
$`b_1=|B_1|`$.
$`b_2=|B_2|/2`$.
$`A^{}`$, $`B_1^{}`$, $`B_2^{}`$, $`a^{}`$, $`b_1^{}`$, and $`b_2^{}`$ are similarly defined for $`G^{}`$.

We set $`\tau =\frac{1}{5}d^{2d5}`$. Spoiler will choose one of two strategies depending on how large or small $`a`$ is.

Strategy 1 (applicable if $`a\tau n`$)

Case 1: $`G[A]G^{}[A^{}]`$.

Spoiler plays outside $`A`$ and $`A^{}`$ using the strategy for the game on non-isomorphic graphs $`G[\overline{A}]`$ and $`G^{}[\overline{A^{}}]`$ described in the proof of Lemma 3.13. If Duplicator never moves in $`A`$ or $`A^{}`$, Spoiler wins, according to Lemmas 3.7, 3.16, and 6.1, in at most $`(na1)/2+(d+1)+2=(na)/2+d+5/2`$ moves. If Duplicator makes a move in $`A`$ or $`A^{}`$, Spoiler, who has selected in this round a vertex $`v`$ in a component with more than $`d^2+1`$ vertices, wins by selecting a set of $`d^2+2`$ vertices that includes $`v`$ and spans a connected subgraph. Thus, Spoiler needs at most $`\frac{na}{2}+d^2+d+\frac{7}{2}(\frac{1}{2}\frac{1}{2}\tau )n+d^2+d+\frac{7}{2}`$ moves to win.

Case 2: $`G[AB]\cong ̸G^{}[A^{}B^{}]`$.

Spoiler enforces play in $`AB`$ and $`A^{}B^{}`$. He starts in $`G`$ if $`G[AB]`$ has at least as many components as $`G^{}[A^{}B^{}]`$ has and in $`G^{}`$ otherwise. Without loss of generality assume the former.

Spoiler selects one vertex in each component of $`G[AB]`$. This takes at most $`n/3`$ moves as every component of $`G[AB]`$ has at least 3 vertices. Spoiler keeps doing so until one of the following happens.

1. Duplicator moves in $`B^{}`$. Then Spoiler wins in at most 2 extra moves.
2. Duplicator moves outside $`A^{}`$. Then Spoiler switches to $`G^{}`$ and wins in at most $`d^2+1`$ extra moves by selecting a connected subgraph spanned by $`d^2+2`$ vertices.
3. While Spoiler selects a vertex in a component $`C`$ of $`G[AB]`$, Duplicator responds with a vertex in a component $`C^{}`$ of $`G^{}[A^{}B^{}]`$ such that $`C^{}\cong ̸C`$. Then Spoiler wins in at most $`d^2`$ extra moves by selecting all vertices of $`C`$ if $`|C||C^{}|`$ or all vertices of $`C^{}`$ otherwise.

It is clear that one of the three situations must happen sooner or later. Thus, Spoiler wins in at most $`n/3+d^2+1`$ moves with at most 1 alternation between $`G`$ and $`G^{}`$.

If neither Case 1 nor Case 2 takes place, then

$$G[B]\cong ̸G^{}[B^{}].$$

Case 3: $`b_1b_1^{}`$ and $`b_2b_2^{}`$.

Since $`b_1+2b_2n`$, we have $`b_1n/3`$ or $`b_2n/3`$. If $`b_1n/3`$ , Spoiler selects $`\mathrm{min}\{b_1,b_1^{}\}+1`$ isolated vertices in the graph containing larger number of them and wins in the next move with alternation between the graphs. If $`b_2n/3`$, Spoiler selects one vertex in each of $`\mathrm{min}\{b_2,b_2^{}\}+1`$ isolated edges in one of the graphs, where this is possible, and then wins in at most 2 next moves with possibly 1 alternation. At total, at most $`n/3+3`$ moves are needed.

It remains to tackle the situation when exactly one of the inequalities $`b_1b_1^{}`$ and $`b_2b_2^{}`$ is true. Let $`j\{1,2\}`$ be the index for which $`|B_j||B_j^{}|`$ (then $`|B_{3j}|=|B_{3j}^{}|`$).

Case 4: $`\mathrm{min}\{|B_j|,|B_j^{}|\}n/3`$.

Spoiler wins in at most $`\mathrm{min}\{|B_j|,|B_j^{}|\}+3n/3+3`$ moves with at most 1 alternation similarly to Case 3.

Case 5: $`\mathrm{min}\{|B_j|,|B_j^{}|\}>n/3`$.

This is the only place in the proof where we need to assume that $`|G^{}|=|G|`$. We can do so because in Case 5 the graph $`G`$ must have isolated vertices or edges. It follows that $`G[\overline{B}]`$ and $`G^{}[\overline{B^{}}]`$ are non-isomorphic graphs of different orders. Denote the graph of the smaller order by $`H`$ and the other graph by $`H^{}`$. Spoiler enforces play on $`H`$ and $`H^{}`$ as follows: As soon as Duplicator moves in $`B`$ or $`B^{}`$, Spoiler, who has selected in this round a vertex $`u`$ in a component $`C`$ of $`G`$ or $`G^{}`$ with at least 3 vertices, wins in 2 extra moves by selecting two more vertices $`u_1`$ and $`u_2`$ in $`C`$ so that $`u`$, $`u_1`$, and $`u_2`$ span a connected subgraph. Note that

$$|H|nb<2n/3.$$

As long as Duplicator moves outside $`B`$ and $`B^{}`$, Spoiler uses the following strategy for the Ehrenfeucht game on $`H`$ and $`H^{}`$. We will now refer to Definition 3.12. If $`H^{}Hlv`$ for any $`vV(H)`$, then Spoiler follows the strategy from Lemma 3.13 and wins in at most $`|H|/2+2`$ moves with at most 1 alternation. If $`H^{}=Hlv`$ for some $`vV(H)`$, then Spoiler follows the strategy from Lemma 4.2 and wins in at most

$$\frac{|H|+1}{\sigma _H(v)+1}+\sigma _H(v)+1\frac{|H|}{2}+\sigma (H)+\frac{3}{2}$$

moves with at most 1 alternation between the graphs. As $`H`$ has no isolated vertices, by Lemma 6.1 we have $`\sigma (H)\mathrm{\Delta }(H)+1d+1`$. Thus, in Case 5 Spoiler needs at most $`|H|/2+d+9/2<n/3+d+9/2`$ moves to win.

In any of Cases 1–5 Spoiler makes at most 1 alternation and at most $`(\frac{1}{2}\frac{1}{2}\tau )n+d^2+d+\frac{7}{2}`$ moves, which is actually the claimed bound.

Strategy 2 (applicable if $`a\tau n`$)

We split our description of Spoiler’s strategy into four phases.

Phase 1.

Spoiler selects all vertices in the set $`A`$.

Phase 2.

Spoiler will make moves in pairs. Let $`i1`$. Denote the vertices selected by him in the $`(2i1)`$-th and $`2i`$-th rounds of Phase 2 by $`x_i`$ and $`y_i`$ respectively. Suppose that Spoiler has already made $`2(i1)`$ moves and selected a set $`X_{i1}=A\{x_1,y_1,\mathrm{},x_{i1},y_{i1}\}V(G)`$. Let us explain how $`x_i`$ and $`y_i`$ are now selected.

If there is a vertex $`xV(G)`$ such that

* $`dist(x,X_{i1})5`$ and
* for any $`y`$ with $`dist(x,y)2`$ we have $`\mathrm{deg}(y)\mathrm{deg}(x)`$,

then Spoiler selects this $`x`$ for $`x_i`$.

Claim 6.2.1.  Suppose that $`x_i=x`$ does exist. Then there are vertices $`u,y,v`$ such that $`\{x,u\},\{u,y\},\{y,v\}E(G)`$ while $`\{x,y\},\{x,v\}E(G)`$.

Proof of Claim.  Let $`C`$ be the component of $`G`$ containing $`x`$. It should contain a vertex $`v`$ with $`dist(x,v)=3`$ for else every vertex of $`C`$ would be at distance at most 2 from $`x`$ and hence $`C`$ would have at most $`1+d+d(d1)=d^2+1`$ vertices. Let $`(x,u,y,v)`$ be an arbitrary path from $`x`$ to $`v`$. The vertices $`u,y,v`$ are as desired. $`\mathrm{}`$

If $`x_i=x`$ is selected, Spoiler chooses some $`u,y,v`$ as in the claim and takes the $`y`$ for $`y_i`$.

If no such $`x`$ exists, Phase 2 ends. Suppose that Phase 2 lasts $`2r`$ rounds. Recall that the partition $`𝒞(X)`$, where $`XV(G)`$, is defined by Definition 3.4.

Claim 6.2.2.  $`|𝒞(X_i)||𝒞(X_{i1})|+3`$ if $`i<r`$ and $`|𝒞(X_r)||𝒞(X_{r1})|+2`$.

Proof of Claim.  We will show that, if we extend $`X_{i1}`$ to $`X_i`$, one of the classes in $`𝒞(X_{i1})`$ splits up into at least 4 parts if $`i<r`$ and into at least 3 parts if $`i=r`$.

By the choice of $`u`$, $`y=y_i`$, and $`v`$, we have $`dist(x_i,u)=1`$ and $`dist(x_i,v)=3`$. Since $`dist(x_i,X_{i1})5`$, neither $`u`$ and $`v`$ is in $`X_{i1}`$. Note that $`u`$ is adjacent to both $`x_i`$ and $`y_i`$, while $`v`$ is adjacent to $`y_i`$ but not to $`x_i`$.

Note also that $`\mathrm{\Gamma }(x_i)\mathrm{\Gamma }(y_i)\mathrm{}`$ because $`x_i`$ has no less neighbors than $`y_i`$ has and $`v`$ is a neighbor of $`y_i`$ but not of $`x_i`$. Thus, there is a vertex $`w`$ adjacent to $`x_i`$ but not to $`y_i`$. Like $`u`$ and $`v`$, we have $`wX_{i1}`$.

Thus, $`u`$, $`v`$, and $`w`$ belong to pairwise distinct classes of $`𝒞(X_i)`$. If we assume that $`i<r`$, we are able to find a vertex in a yet another class. Indeed, consider $`x=x_{i+1}`$. Since $`dist(x,X_i)5`$, this vertex is adjacent neither to $`x_i`$ nor to $`y_i`$.

On the other hand, every of $`u`$, $`v`$, $`w`$, and $`x`$ is at distance at least 2 from $`X_{i1}`$. Therefore all of them are in the same class of $`𝒞(X_{i1})`$. $`\mathrm{}`$

Phase 3.

As long as possible, Spoiler extends $`X=X_r`$ by one vertex so that $`|𝒞(X)|`$ increases at least by 1. Phase 3 ends as soon as Spoiler arrives at a $`𝒞`$-maximal set in the sense of Definition 3.5.

Suppose that Phase 3 lasts $`h`$ rounds. At the end of this phase we therefore have

$$|X|=a+2r+h$$

and

$$|𝒞(X)|1+3(r1)+2+h=3r+h.$$

It follows that $`|𝒞(X)||X|+ra`$ and hence $`n|X|+|𝒞(X)|2|X|+ra`$. We conclude that

$$|X|\frac{n+ar}{2}.$$

Phase 4.

Spoiler now plays precisely as in Phase 2 of the strategy designed in the proof of Lemma 3.13. By Lemma 3.16, with Lemma 6.1 taken into account, Spoiler wins making totally at most

$$|X|+d+3\frac{n+ar}{2}+d+3\frac{n+\tau nr}{2}+d+3$$
(19)
moves. It therefore remains to show that the duration of Phase 2, controlled by $`r`$, is linearly related to $`n`$ (the parameter $`\tau `$ is chosen small enough).

Claim 6.2.3.  Let $`V_k=\{xV(G):dist(x,X_r)2k+3\}`$. Then $`V_{d+1}=\mathrm{}`$.

Proof of Claim.  Assume, to the contrary, that $`V_{d+1}\mathrm{}`$. We will show that then there is $`x_{r+1}`$ such that $`dist(x_{r+1},X_r)5`$ and every $`y`$ at distance at most 2 from $`x_{r+1}`$ has smaller degree, contradicting the fact that Phase 2 lasts $`2r`$ rounds. Let $`d_i=\mathrm{max}\left\{\mathrm{deg}(x):xV_i\right\}`$. If no $`z_iV_i`$ with $`\mathrm{deg}(z_i)=d_i`$ can be taken for $`x_{r+1}`$, then $`d_{i+1}<d_i`$. Indeed, for any such $`z_i`$ there is $`y`$ such that $`dist(z_i,y)2`$ and $`\mathrm{deg}(y)>\mathrm{deg}(z_i)`$. The latter implies that $`yV_i`$, i.e., $`dist(y,X_r)2i+2`$. It follows that $`dist(z_i,X_r)2i+4`$, hence $`z_iV_{i+1}`$ and $`d_{i+1}<d_i`$. Since the chain $`d_1>d_2>d_3>\mathrm{}`$ can have length at most $`d`$, some $`z_i`$ with $`id+1`$ can be taken for $`x_{r+1}`$. This contradiction proves the claim. $`\mathrm{}`$

Thus, $`|\overline{V_{d+1}}|=n`$. By the definition of $`V_{d+1}`$ we have

$$|\overline{V_{d+1}}||X_r|(1+d+d(d1)+d(d1)^2+\mathrm{}+d(d1)^{2d+3})<|X_r|d^{2d+5}$$

(note that $`d2`$, which follows from the assumption that $`a<n`$). Putting it together, under the assumption that $`a\tau n`$, we obtain

$$\tau n+2ra+2r=|X_r|>n/d^{2d+5},$$

which implies that

$$r>n(d^{2d5}\tau )/2.$$

Substituted in (19), this shows that Spoiler wins in at most

$$\left(\frac{1}{2}+\frac{3}{4}\tau \frac{1}{4}d^{2d5}\right)n+d+3$$

moves, which is within the required bound.

## 7 The worst case dimension of the Weisfeiler-Lehman algorithm

The main purpose of this, mostly expository, section is to give a self-contained proof of an upper bound for the dimension of the Weisfeiler-Lehman algorithm for the graph isomorphism problem. The dimension is an important parameter of the algorithm. On the one hand, the higher dimension is chosen, the longer the algorithm runs. On the other hand, a small dimension may do not suffice to compute the right output. Our goal will be to show that, on input graphs of order $`n`$, the dimension $`(n+1)/2`$ suffices. Another job we do here is to compute an explicit constant in the Cai-Fürer-Immerman bound (2).

We begin with description of the algorithm.

### 7.1 Definitions and notation

Given an ordered $`k`$-tuple of vertices $`\overline{u}=(u_1,\mathrm{},u_k)V(G)^k`$, let $`s=s(\overline{u})`$ be the number of distinct components in $`\overline{u}`$ and define a function $`F_{\overline{u}}:\{1,\mathrm{},k\}\{1,\mathrm{},s\}`$ by $`F_{\overline{u}}(i)=|\{u_1,\mathrm{},u_i\}|`$. Furhtermore, let $`G_{\overline{u}}`$ be the graph on the vertex set $`\{1,\mathrm{},s\}`$ with vertices $`a`$ and $`b`$ adjacent iff, for the smallest $`i`$ and $`j`$ such that $`F_{\overline{u}}(i)=a`$ and $`F_{\overline{u}}(j)=b`$, $`u_i`$ and $`u_j`$ are adjacent in $`G`$. The pair $`(F_{\overline{u}},G_{\overline{u}})`$ is an isomorphism type of $`\overline{u}`$ and will be denoted by $`[\overline{u}]`$.

If $`wV(G)`$ and $`ik`$, we let $`\overline{u}^{i,w}`$ denote the result of substituting $`w`$ in place of $`u_i`$ in $`\overline{u}`$.

A (vertex) coloring of a graph $`G`$ is an arbitrary function $`\gamma :V(G)C`$. We will say that $`C`$ is the set of colors and that a vertex $`vV(G)`$ has color $`\gamma (v)`$. For a color $`cC`$, the set $`\gamma ^1(c)`$ is its monochromatic class. A coloring $`\gamma ^{}`$ refines a coloring $`\gamma `$ if $`\gamma ^{}(v)=\gamma ^{}(u)`$ implies $`\gamma (v)=\gamma (u)`$, that is, the partition of $`V(G)`$ into $`\gamma ^{}`$-monochromatic classes refines the partition into $`\gamma `$-monochromatic classes.

### 7.2 Description of the algorithm

We distinguish two modes of the algorithm. In the canonization mode the algorithm takes as an input a graph $`G`$ and is purported to output its canonic form $`W(G)`$. The canonic form of a graph $`W`$ is a graph function such that $`W(G)=W(G^{})`$ iff $`GG^{}`$. In the isomorphism testing mode the algorithm takes as an input two graphs $`G`$ and $`G^{}`$ and should decide if $`GG^{}`$.

We now describe the $`k`$-dimensional algorithm. The algorithm assigns an initial coloring to an input graph, then step by step refines it by iterating the color refinement procedure, and finally, when no color refinement is any more possible, terminates and computes an output.

Initial coloring

The algorithm assigns each $`\overline{u}V(G)^k`$ color $`W_G^{k,0}(\overline{u})=[\overline{u}]`$ (in a suitable encoding).

Color refinement step

In the $`r`$-th step each $`\overline{u}V(G)^k`$ is assigned color

$$W_G^{k,r}(\overline{u})=(W_G^{k,r1}(\overline{u}),\{(W_G^{k,r1}(\overline{u}^{1,w}),\mathrm{},W_G^{k,r1}(\overline{u}^{k,w})):wV(G)\}).$$

In the proper Weisfeiler-Lehman algorithm the second component of $`W_G^{k,r}(\overline{u})`$ is a multiset rather than a set. However, in what follows we assume that it is a set. It will be clear that the version of the algorithm we consider is weaker than the standard one, i.e., whenever our $`k`$-dimensional version gives the right output, so does the standard $`k`$-dimensional version (and it will be not hard to show that sometimes for the standard version a considerably smaller dimension is enough). This relaxation makes our result only stronger as any upper bound for the dimension of the weaker version is as well an upper bound for the dimension of the standard version.

###### Proposition 7.1

If $`\varphi `$ is an isomorphism from $`G`$ to $`G^{}`$, then for all $`k`$, $`r`$, and $`\overline{u}V(G)^k`$ we have $`W_G^{k,r}(\overline{u})=W_G^{}^{k,r}(\varphi ^k(\overline{u}))`$.

###### Proposition 7.2

For every pair of graphs $`G`$ and $`G^{}`$ there is a number $`R`$ such that for all $`\overline{u}V(G)^k`$, $`\overline{v}V(G^{})^k`$, and $`r>R`$

$$W_G^{k,r}(\overline{u})=W_G^{}^{k,r}(\overline{v})\text{ iff }W_G^{k,R}(\overline{u})=W_G^{}^{k,R}(\overline{v}).$$

Moreover, if $`R_k(G,G^{})`$ denotes the smallest such $`R`$, then $`R_k(G,G^{})<|G|^k+|G^{}|^k`$.

Proof.  By Proposition 7.1 it suffices to prove the claim for arbitrary isomorphic copies of $`G`$ and $`G^{}`$ and we therefore can suppose that $`V(G)`$ and $`V(G^{})`$ are disjoint. Colorings $`W_G^{k,r}`$ and $`W_G^{}^{k,r}`$ determine the partition of the union $`V(G)^kV(G^{})^k`$ into monochromatic classes. Denote this partition by $`\mathrm{\Pi }^r`$. Since the $`(r+1)`$-th color incorporates the $`r`$-th color, $`\mathrm{\Pi }^{r+1}`$ is a subpartition of $`\mathrm{\Pi }^r`$. It is clear that we eventally have $`\mathrm{\Pi }^{R+1}=\mathrm{\Pi }^R`$ and the smallest such $`R`$ is less than $`|V(G)|^k+|V(G^{})|^k`$.

Computing an output

Isomorphism testing mode. The algorithm terminates color refinement as soon as the partition $`\mathrm{\Pi }^r`$ of $`V(G)^kV(G^{})^k`$ coincides with $`\mathrm{\Pi }^{r1}`$, i.e., after performing $`r=R_k(G,G^{})+1`$ refinement steps. The algorithm decides that $`GG^{}`$ iff

$$\{W_G^{k,r}(u^k):uV(G)\}=\{W_G^{}^{k,r}(v^k):vV(G^{})\},$$
(20)
where $`w^k`$ denotes the diagonal vector $`(w_1,\mathrm{},w_k)`$ with all $`w_i=w`$.

Canonization mode. The algorithm performs $`r=2|G|^k1`$ refinement steps and outputs the set $`\{W_G^{k,r}(u^k):uV(G)\}`$.

##### Implementation details and complexity bounds.

Denote the minimum length of the code of $`W_G^{k,r}(\overline{u})`$ over all $`\overline{u}`$ by $`\lambda (r)`$. As easily seen, for any natural encoding we should expect that $`\lambda (r)(k+1)\lambda (r1)`$. To prevent increasing $`\lambda (r)`$ at the exponential rate, before every refinement step we arrange colors of all $`k`$-tuples in the lexicographic order and replace each color with its number. In the canonization mode we should keep the substitution tables of all steps. In the isomorphism testing mode this is unnecessary but it should be stressed that color renaming must be common for both input graphs. The straightforward implementation of the algorithm takes time $`O(k^2n^{2k}\mathrm{log}^2n)`$ and space $`O(kn^{2k}\mathrm{log}n)`$, where $`n=|G|`$. In the isomorphism testing mode, when we do not waste memory by keeping substitution tables, the space $`O(kn^k(k+\mathrm{log}n))`$ suffices. A better implementation with time bound $`O(k^2n^{k+1}\mathrm{log}n)`$ is suggested in .

### 7.3 Relation to the Ehrenfeucht game

Given numbers $`r`$, $`l`$, and $`kl`$, graphs $`G`$, $`G^{}`$, and $`k`$-tuples $`\overline{u}V(G)^k`$, $`\overline{v}V(G^{})^k`$, we use notation $`\text{Ehr}_r^l(G,\overline{u},G^{},\overline{v})`$ to denote the $`r`$-round $`l`$-pebble Ehrenfeucht game on $`G`$ and $`G^{}`$ with initial configuration $`(\overline{u},\overline{v})`$, i.e., the game starts with one copy of the pebble $`p_i`$, $`ik`$, placed on $`u_i`$ and the other copy of $`p_i`$ placed on $`v_i`$.

###### Proposition 7.3

(Cai, Fürer, and Immerman ) For all $`\overline{u}V(G)^k`$ and $`\overline{v}V(G^{})^k`$ the equality

$$W_G^{k,r}(\overline{u})=W_G^{}^{k,r}(\overline{v})$$
(21)
holds iff Duplicator has a winning strategy in $`\text{Ehr}_r^{k+1}(G,\overline{u},G^{},\overline{v})`$.

Proof.  We proceed by induction on $`r`$. The base case $`r=0`$ is straightforward by the definitions of the initial coloring and the game. Assume that the proposition is true for $`r1`$ rounds.

Assume (21) and consider the Ehrenfeucht game $`\text{Ehr}_r^{k+1}(G,\overline{u},G^{},\overline{v})`$. First of all, the initial configuration is non-losing for Duplicator since (21) implies that $`[\overline{u}]=[\overline{v}]`$. Further, Duplicator can survive in the first round. Indeed, assume that Spoiler in this round selects a vertex $`a`$ in one of the graphs, say in $`G`$. Then Duplicator selects a vertex $`b`$ in the other graph, respectively in $`G^{}`$, such that $`W_G^{k,r1}(\overline{u}^{i,a})=W_G^{}^{k,r1}(\overline{v}^{i,b})`$ for all $`ik`$. In particular, $`[\overline{u}^{i,a}]=[\overline{v}^{i,b}]`$ for all $`ik`$. Along with $`[\overline{u}]=[\overline{v}]`$, this implies that $`[\overline{u},a]=[\overline{v},b]`$. Assume now that in the second round Spoiler removes the $`j`$-th pebble, $`jk`$. Then Duplicator’s task in the rest of the game is essentially to win $`\text{Ehr}_{r1}^{k+1}(G,\overline{u}^{j,a},G^{},\overline{v}^{j,b})`$. Since $`W_G^{k,r1}(\overline{u}^{j,a})=W_G^{}^{k,r1}(\overline{v}^{j,a})`$, Duplicator succeeds by the induction assumption.

Assume now that (21) is false. It follows that $`W_G^{k,r1}(\overline{u})W_G^{}^{k,r1}(\overline{v})`$ (then Spoiler has a winning strategy by the induction assumption) or there is a vertex $`a`$ in one of the graphs, say in $`G`$, such that for every $`b`$ in the other graph, respectively in $`G^{}`$, $`W_G^{k,r1}(\overline{u}^{j_b,a})W_G^{}^{k,r1}(\overline{u}^{j_b,b})`$ for some $`j_bk`$. In the latter case Spoiler in his first move places the $`(k+1)`$-th pebble on $`a`$. Let $`b`$ be the vertex selected in response by Duplicator. In the second move Spoiler will remove the $`j_b`$-th pebble, which implies that since the second round the players essentially play $`\text{Ehr}_{r1}^{k+1}(G,\overline{u}^{j_b,a},G^{},\overline{v}^{j_b,b})`$. By the induction assumption, Spoiler wins.

If $`GG^{}`$, then the Weisfeiler-Lehman algorithm recognizes $`G`$ and $`G^{}`$ as isomorphic for every dimension $`k`$. This follows from Proposition 7.1. If $`G\cong ̸G^{}`$, then the algorithm may be wrong if $`k`$ is chosen too small.

###### Corollary 7.4

If $`G`$ and $`G^{}`$ are non-isomorphic graphs of the same order $`n`$, then the $`k`$-dimensional algorithm recognizes $`G`$ and $`G^{}`$ as non-isomorphic iff $`k\text{L}(G,G^{})1`$.

Proof.  Duplicator has a winning strategy in $`\text{Ehr}_r^{k+1}(G,G^{})`$ iff for every $`aV(G)`$ (resp. $`bV(G^{})`$) there is $`bV(G^{})`$ (resp. $`aV(G)`$) such that Duplicator has a winning strategy in $`\text{Ehr}_{r1}^{k+1}(G,a,G^{},b)`$ or, equivalently, in $`\text{Ehr}_{r1}^{k+1}(G,a^k,G^{},b^k)`$. It follows by Propositions 7.2 and 7.3 that the $`k`$-dimensional algorithm decides that $`GG^{}`$ iff Duplicator has a winning strategy in $`\text{Ehr}_r^{k+1}(G,G^{})`$ for all $`r`$. By Proposition 2.11, $`\text{L}(G,G^{})1`$ is equal to the maximum $`l`$ such that Duplicator has a winning strategy in $`\text{Ehr}_r^l(G,G^{})`$ for every $`r`$. Therefore the decision of the $`k`$-dimensional algorithm is correct iff $`k\text{L}(G,G^{})1`$.

### 7.4 An upper bound on the dimension of the algorithm

###### Definition 7.5

The smallest dimension of the Weisfeiler-Lehman algorithm giving the right output on graphs $`G`$ and $`G^{}`$ of order $`n`$ in the isomorphism testing mode will be referred to as the optimum dimension of the algorithm on $`G`$ and $`G^{}`$ and denoted by $`\text{WL}(G,G^{})`$. Furthermore, the optimum dimension of the algorithm on graphs of order $`n`$ is defined by

$$\text{WL}(n)=\mathrm{max}\left\{\text{WL}(G,G^{}):G^{}\cong ̸G,|G^{}|=|G|=n\right\}.$$

It is easy to see that the smallest dimension of the algorithm giving the right output on an input graph $`G`$ in the canonization mode is equal to

$$\mathrm{max}\left\{\text{WL}(G,G^{}):G^{}\cong ̸G,|G^{}|=|G|\right\}$$

and hence in the worst case is equal to $`\text{WL}(n)`$.

On the account of Corollary 7.4 and Theorem 3.15, we immediately obtain the following result.

###### Theorem 7.6

$`\text{WL}(n)(n+1)/2`$.

This bound is almost tight for the relaxed version of the algorithm that we have dealt with in this section. However, Theorem 7.6 leaves a considerable gap if compared with the Cai-Fürer-Immerman lower bound for $`\text{WL}(n)`$, that is discussed in the next subsection. Thus, what $`lim\; sup_n\mathrm{}\text{WL}(n)/n`$ is remains open.

### 7.5 The lower bound for the dimension — computing an explicit constant

Cai, Fürer, and Immerman  prove a striking linear lower bound $`\text{WL}(n)cn`$, without specification of a positive constant $`c`$. We are curious to draw from their proof an explicit value of $`c`$. We do not give a complete overview of the proof focusing only on a few most relevant points. The following notion will be fairly useful.

###### Definition 7.7

Let $`H`$ be a graph of order $`n`$. Given $`XV(H)`$, denote $`HX=H[V(H)X]`$. We call a set $`X`$ a separator of $`H`$ if every connected component of the graph $`HX`$ has at most $`n/2`$ vertices. The number of vertives in a separator is called its size. The minimum size of a separator of $`H`$ is denoted by $`s(H)`$.

Cai, Fürer, and Immerman present a construction of non-isomorphic graphs $`G`$ and $`G^{}`$ of the same order with large $`\text{WL}(G,G^{})`$. Both $`G`$ and $`G^{}`$ are constructed from a suitable connected graph $`H`$ with minimum vertex degree at least 2. We will assume that $`H`$ is $`d`$-regular, that is, every its vertex has degree $`d`$ (using $`H`$ not regular seems to give us no gain). Below we summarize the properties of the construction. Recall that $`\mathrm{\Delta }(G)`$ denotes the maximum vertex degree of a graph $`G`$.

###### Proposition 7.8

(Cai, Fürer, and Immerman ) Let $`d2`$ and $`H`$ be a connected $`d`$-redular graph. There are transformations of $`H`$ to two graphs $`G=G(H)`$ and $`G^{}=G^{}(H)`$ such that

* If $`d3`$, both $`G`$ and $`G^{}`$ are connected;
* $`|G|=|G^{}|=(d+2^{d1})|H|`$;
* $`\mathrm{\Delta }(G)=\mathrm{\Delta }(G^{})=2^{d1}`$;
* $`G\cong ̸G^{}`$;
* $`\text{WL}(G,G^{})s(H)`$.

Thus, we need a family of $`d`$-regular graphs $`H`$ with $`d`$ constant and $`s(H)`$ linearly related to the order of $`H`$. The authors of  suggest using graphs with good expansion properties.

###### Definition 7.9

Let $`H`$ be a graph of order $`n`$. The vertex-expansion of $`H`$ is denoted by $`i_v(H)`$ and defined by

$$i_v(H)=\mathrm{min}\left\{\frac{|N(A)|}{|A|}:AV(H),|A|\frac{n}{2}\right\},$$

where $`N(A)=_{vA}\mathrm{\Gamma }(v)A`$ is the neiborhood of a set $`A`$.

###### Lemma 7.10

For a graph $`H`$ of order $`n`$ we have

$$s(H)\frac{i_v(H)}{3+i_v(H)}n.$$

Proof.  Let $`X`$ be a separator of $`H`$ with the smallest size $`s=s(H)`$. Denote the largest size of a connected component of $`HX`$ by $`m`$ and recall that $`mn/2`$. There is a set $`A_1V(G)X`$ with $`|A_1|=m`$ such that $`H[A_1]`$ is a connected component of $`HX`$ and, as it is not hard to see, there is a set $`A_2V(G)X`$ with $`\frac{ns}{2}\frac{m}{2}|A_2|\frac{ns}{2}`$ such that $`H[A_2]`$ is a union of connected components of $`HX`$. Note that $`\mathrm{max}\{m,\frac{ns}{2}\frac{m}{2}\}\frac{ns}{3}`$ and therefore for $`A_i`$, one of the sets $`A_1`$ and $`A_2`$, we have

$$\frac{ns}{3}|A_i|\frac{n}{2}.$$

By the definition of the vertex expansion,

$$|N(A_i)|i_v(H)|A_i|i_v(H)\frac{ns}{3}.$$

Since $`A_i`$ is a union of connected components of $`HX`$, we have $`N(A_i)X`$ and hence $`|N(A_i)|s`$. Thus, we obtain the relation

$$si_v(H)\frac{ns}{3}.$$

Resolving it with respect to $`s`$, we arrive at the reqiured estimate.

Thus, we need $`d`$-regular graphs with large vertex-expansion. The best examples we could find in the literature come from the known edge-expansion results.

###### Definition 7.11

Let $`H`$ be a graph of order $`n`$. The edge-expansion (or the isoperimetric number) of $`H`$ is denoted by $`i_e(H)`$ and defined by

$$i_e(H)=\mathrm{min}\left\{\frac{e(A,N(A))}{|A|}:AV(H),|A|\frac{n}{2}\right\},$$

where $`e(A,B)`$ denotes the number of edges in $`H`$ with one end vertex in $`A`$ and the other in $`B`$.

For a $`d`$-regular graph $`H`$ it is straightforward that $`i_v(H)i_e(H)/d`$. We are able to improve this relation for 3-regular (or cubic) graphs.

###### Lemma 7.12

If $`H`$ is a cubic graph, then $`i_v(H)i_e(H)/2`$.

Proof.  If $`H`$ is disconnected, then one of its connected components occupies no more than a half of the vertices and hence $`i_v(H)=0`$. Suppose that $`H`$ is connected.

Of all $`AV(H)`$ with $`|A||H|/2`$ and $`|N(A)|/|A|=i_v(H)`$, take one minimizing $`e(A,N(A))`$. Let us show that every vertex $`xN(A)`$ sends at most 2 edges to $`A`$. This will give us the desired relation because in this case

$$i_e(H)\frac{e(A,N(A))}{|A|}\frac{2|N(A)|}{|A|}=2i_v(H).$$

Suppose, to the contrary, that some $`xN(A)`$ sends 3 edges to $`A`$.

Consider an arbitrary $`yA`$. Let $`A_y=(A\{y\})\{x\}`$. If $`y`$ sends 3 edges to $`N(A)\{x\}`$, then $`N(A_y)=N(A)\{x\}`$ has less vertices than $`N(A)`$ has while $`|A_y|=|A|`$. Therefore $`|N(A_y)|/|A_y|<i_v(H)`$, a contradiction. If $`y`$ sends 1 or 2 edges to $`N(A)\{x\}`$, then $`N(A_y)(N(A)\{x\})\{y\}`$. It follows that $`|N(A_y)||N(A)|`$ and it should be $`|N(A_y)|/|A_y|=i_v(H)`$. However, $`e(A_y,N(A_y))e(A,N(A))1`$, contradicting the choice of $`A`$.

We conclude that every $`yA`$ sends no edges to $`N(A)\{x\}`$. It follows that $`A\{x\}`$ spans a proper connected component of $`H`$, a contradiction to the connectivity of $`H`$.

Using Lemmas 7.10 and 7.12, from Proposition 7.8 we easily obtain the following consequence.

###### Proposition 7.13

Let $`i_e(3,m)`$ denote the maximum edge-expansion of a connected cubic graph of order $`m`$. Then there are non-isomorphic graphs $`G`$ and $`G^{}`$ both of order $`7m`$ with maximum degree 4 such that

$$\text{WL}(G,G^{})\frac{i_e(3,m)}{6+i_e(3,m)}m.\text{ }\text{ }$$

It seems that the best known lower bounds for $`i_e(3,m)`$ are obtained by examining random cubic graphs. The edge-expansion of a random cubic graph was studied by Buser , Bollobás , and others with the best lower bound as follows.

###### Proposition 7.14

(Kostochka and Melnikov ) Let $`H`$ be a random cubic graph of order $`m`$. If $`m`$ is sufficiently large, then with probability $`1o(1)`$ we have

$$i_e(H)\frac{1}{4.95}.\text{ }\text{ }$$

It follows that $`i_e(3,m)\frac{1}{4.95}`$, where $`m`$ is supposed to be large enough. For the graphs $`G`$ and $`G^{}`$ as in Proposition 7.13 we therefore have

$$\text{WL}(G,G^{})\frac{n}{7(1+64.95)}>0.00465n,$$

where $`n=7m`$ is the order of the graphs. Thus, the constant in question is evaluated.

###### Proposition 7.15

$`\text{WL}(n)>0.00465n`$ for infinitely many $`n`$.

Notice that, with high probability, a random cubic graph is connected. The construction of  together with the logical characterization of $`\text{WL}(G,G^{})`$ given in the same paper, has therefore the following consequence worthwhile to note.

###### Proposition 7.16

For infinitely many $`n`$, there are non-isomorphic connected graphs $`G`$ and $`G^{}`$ both of order $`n`$ with maximum degree 4 such that $`\text{D}(G,G^{})>0.00465n`$.

## 8 Digraphs and binary structures

We now extend the results of Sections 3 and 4 over directed graphs and, more generally, structures with relation arity at most 2.

### 8.1 Definitions

In logical terms, a directed graph (or digraph) $`G`$ is an arbitrary binary relation $`E`$ on a vertex set $`V(G)`$. The edge set of $`G`$ is $`E(G)=\{(u,v)V(G)^2:E(a,b)=1\}`$. Thus, between two distinct vertices $`u`$ and $`v`$ we allow two opposite edges $`(u,v)`$ and $`(v,u)`$, or only one of them, or none. We view an edge $`(u,v)`$ as an arrow from $`u`$ to $`v`$. An edge $`(v,v)`$, called a loop, is also allowed. From now on the stand-alone term graph means ordinary undirected graph. Recall that the undirected graphs are actually considered a subclass of the directed graphs wherein an undirected edge $`\{u,v\}`$ corresponds to two directed edges $`(u,v)`$ and $`(v,u)`$ and we have no loops and no two vertices with exactly one directed edge between them.

A (vertex) colored digraph is a structure that, in addition to the binary relation, has unary relations $`U_1,\mathrm{},U_m`$. The truth of $`U_i(v)`$ for a vertex $`v`$ is interpreted as coloration of $`v`$ in color $`i`$. Thus, a vertex can have several colors or no color. However, colored digraphs can be modelled as digraphs with each vertex having exactly one color by defining new colors as conjunctions of some of $`U_1,\mathrm{},U_m`$ and yet another new color for uncolored vertices.

Convention. Observe that digraphs can be modelled as colored loopless digraphs by assigning a special color to the vertices with loops. To facilitate the exposition, we will use this observation and assume throughout this section all digraphs loopless.

A complete digraph has two directed edges $`(u,v)`$ and $`(v,u)`$ for every pair of distinct vertices $`u`$ and $`v`$. An empty digraph has no edges at all. Let $`G`$ be a digraph and $`X,YV(G)`$ be disjoint. Similarly to graphs, $`G[X]`$ denotes the subdigraph induced by $`G`$ on $`X`$ and $`G[X,Y]`$ denotes the bipartite subdigraph induced on the vertex classes $`X`$ and $`Y`$. A set $`X`$ is called complete (resp. independent) if $`G[X]`$ is complete (resp. empty). $`X`$ is called homogeneous if it is complete or empty. A bipartite subdigraph $`G[X,Y]`$ is complete, independent, or $`(X,Y)`$-complete if for any $`uX`$ and $`vY`$ we have respectively $`(u,v),(v,u)E(G)`$; $`(u,v),(v,u)E(G)`$; $`(u,v)E(G)`$ but $`(v,u)E(G)`$. It is dicomplete if it is either $`(X,Y)`$-complete or $`(Y,X)`$-complete. A pair $`X,Y`$ is called homogeneous if $`G[X,Y]`$ is complete, independent, or dicomplete.

A binary vocabulary has relation arities at most 2. A binary structure is a structure over a binary vocabulary. Combinatorially, a binary structure $`(U_1,\mathrm{},U_s,E_1,\mathrm{},E_t)`$ with $`s`$ unary and $`t`$ binary relations can be viewed as a complete digraph that is vertex colored in colors $`1,\mathrm{},s`$ and edge colored in colors $`1,\mathrm{},t`$: A vertex $`v`$ has color $`is`$ iff $`U_i(v)=1`$ and an edge $`(u,v)`$ has color $`jt`$ iff $`E_j(u,v)=1`$. An isomorphism between such complete digraphs should preserve the sets of colors of each vertex and of each edge. Given a binary structure $`(U_1,\mathrm{},U_s,E_1,\mathrm{},E_t)`$, we will often call elements of its universe vertices and consider each $`E_i`$ a digraph.

Let $`G=(U_1,\mathrm{},U_s,E_1,\mathrm{},E_t)`$ be a binary structure with universe $`V(G)`$. A set $`XV(G)`$ is monochromatic if $`U_i(u)=U_i(v)`$ for all $`u,vX`$ and every $`is`$. We call $`X`$ homogeneous if it is monochromatic and homogeneous in every digraph $`E_j`$, $`jt`$. We call a pair $`X,YV(G)`$ of disjoint sets homogeneous if it is such in every digraph $`E_j`$, $`jt`$.

### 8.2 Distinguishing binary structures

We now generalize Theorem 3.15 from graphs to binary structures. The same proof in essence goes through with only a few substantiate modifications; We indicate these by tracing Section 3. By $`G`$ we will mean, unless stated otherwise, a binary structure $`(U_1,\mathrm{},U_s,E_1,\mathrm{},E_t)`$.

Definition 3.1, as well as the other definitions in Section 3.1, makes a perfect sense for an arbitrary structure. Let us look what the similarity of vertices $`u`$ and $`v`$ means in a digraph. We say that a vertex $`t`$ separates $`u`$ and $`v`$ if precisely one of $`(t,u)`$ and $`(t,v)`$ is in $`E(G)`$ or precisely one of $`(u,t)`$ and $`(v,t)`$ is in $`E(G)`$. Then $`u`$ and $`v`$ are similar if no third vertex separates them and if $`(u,v)`$ and $`(v,u)`$ both are in $`E(G)`$ or both are not<sup>2</sup><sup>2</sup>2and if $`u`$ and $`v`$ simultaneously make loops or do not (see Convention in Section 8.1).. In a general binary structure, $`u`$ and $`v`$ are similar if they have the same sets of colors (i.e., satisfy the same unary predicates) and are similar in each digraph $`E_i`$.

Claim 8.0.1.  Lemma 3.2 holds true for digraphs and, more generally, for binary structures.

Proof of Claim.  The only not completely obvious part of the proof is verification that $``$ is a transitive relation on the vertex set of a digraph. Suppose that $`uv`$ and $`vw`$ for pairwise distinct $`u`$, $`v`$, and $`w`$. Assume, for example, that $`(u,v)`$ and $`(v,u)`$ are both present in $`E(G)`$. As $`vw`$, we have $`(u,w),(w,u)E(G)`$. Now, as $`uv`$, we have $`(v,w),(w,v)E(G)`$. Also the sets of in- and out-neighbors of $`u`$ and $`w`$ in $`V(G)\{u,v,w\}`$ are identical (being equal to those of $`v`$). This implies that $`uw`$, proving the transitivity. $`\mathrm{}`$

Claim 8.0.2.  Lemma 3.6 holds true for digraphs and, more generally, for binary structures with one stipulation in Item 1. Specifically, let $`XV(G)`$ be $`𝒞`$-maximal. Then the partition $`𝒞(X)`$ has the following properties.

1. Every $`C`$ in $`𝒞(X)`$ is a homogeneous set provided $`|C|2`$.
2. If $`C_1`$ and $`C_2`$ are distinct classes in $`𝒞(X)`$ and have at least two elements each, then the pair $`C_1,C_2`$ is homogeneous.

Proof of Claim.  The claim easily reduces to its particular case that $`G`$ is a digraph. So we assume the latter.

1) Suppose, to the contrary, that $`C`$ is not homogeneous.

First, suppose there are $`u,vC`$ with $`(u,v)E(G)`$ and $`(v,u)E(G)`$. Let $`wC\{u,v\}`$. As moving $`v`$ to $`X`$ cannot separate $`u`$ and $`w`$ (for otherwise $`|𝒞(X)|`$ increases), we conclude that $`(w,v)E(G)`$ and $`(v,w)E(G)`$. Pondering $`w`$ as the next move we conclude that $`(w,u)E(G)`$ and $`(u,w)E(G)`$. But $`u`$ separates $`v`$ and $`w`$, a contradiction.

Thus we can assume that $`C`$ contains three vertices $`u`$, $`v`$, and $`w`$ such that $`(u,v),(v,u)E(G)`$ but $`(v,w),(w,v)E(G)`$. However, if we move $`v`$ to $`X`$, then $`C`$ splits into two classes, which are non-empty as they contain $`u`$ and $`w`$ respectively. Hence $`|𝒞(X)|`$ increases at least by 1, a contradiction.

2) Let $`u,vC_1`$ and $`w,xC_2`$. The contemplation of $`w`$ for the next move shows that $`(u,w)`$ and $`(v,w)`$ are both present or absent; considering $`v`$ we conclude the same about $`(v,x)`$ and $`(v,w)`$. Hence, $`(u,w)`$ is an edge if and only if $`(v,x)`$ is. Similarly, the same is true about $`(w,u)`$ and $`(x,v)`$. As $`u,v,w,x`$ are arbitrary, the claim follows. $`\mathrm{}`$

Lemma 3.7 carries over with literally the same proof.

Definition 3.12 makes a perfect sense for binary structures. We now state an analog of Lemma 3.13.

###### Lemma 8.1

Suppose that $`G`$ and $`G^{}`$ are non-isomorphic structures over the same vocabulary with maximum relation arity 2. If $`G`$ and $`G^{}`$ have orders $`n`$ and $`n^{}`$ respectively and $`nn^{}`$, then

$$\text{D}_1(G,G^{})(n+5)/2$$
(22)
unless $`G^{}=G(n^{}n)v`$ for some $`vV(G)`$.

Proof.  We go through the lines of the proof of Lemma 3.13. Phase 1 is played with no changes. The same strategy for Phase 2 ensures that, unless Spoiler wins in 2 extra moves, we have a partial isomorphism $`\varphi ^{}:XYX^{}Y^{}`$ from $`G`$ to $`G^{}`$. Exactly as in the case of graphs, in Phase 2 Duplicator should obey $`\varphi ^{}`$ if Spoiler moves in $`YY^{}`$ and the $`\varphi ^{}`$-similarity if Spoiler moves in $`ZZ^{}`$. In particular, Claim 3.13 carries over literally and we again have the $`\varphi ^{}`$-similarity of the classes $`D_i`$ and $`D_i^{}`$ for all $`ip`$. Claim 3.13 needs a careful revision, after which it is provable with minor changes.

Claim 8.1.1.  Unless Spoiler is able to win making 2 moves and at most 1 alternation in Phase 2, the following conditions are met for every $`ip`$, for every pair of distinct $`i,jp`$, and for each $`kt`$.

1. Both $`D_i`$ and $`D_i^{}`$ are monochromatic and, moreover, the sets of their colors coincide.
2. If $`|D_i|2`$, then the set $`D_i`$ is complete or independent in the digraph $`E_k`$. Moreover, irrespectively of $`|D_i|`$, the set $`D_i`$ is complete (resp. independent) in $`E_k`$ iff so is $`D_i^{}`$ in $`E_k^{}`$.
3. The pairs $`D_i,D_j`$ and $`D_i^{},D_j^{}`$ are simultaneously complete, independent, or dicomplete in $`E_k`$ and $`E_k^{}`$ respectively. Moreover, in case of dicompleteness we have the same direction of edges.$`\mathrm{}`$

Assume that the conditions in Claim 8.1 are obeyed. We now claim that $`G`$ and $`G^{}`$ are isomorphic iff $`|D_i|=|D_i^{}|`$ for all $`ip`$. We still cannot substantiate this, as it was done in the case of graphs, because of the stipulation that $`|D_i|2`$ made in Item 2 of Claim 8.1. The next claim gives the missing part of the argument.

Claim 8.1.2.  Unless Spoiler is able to win making 2 moves and at most 1 alternation in Phase 2, the following is true for every $`ip`$. Assume that $`|D_i|=2`$ and, for some $`kt`$, the digraph $`E_k[D_i]`$ has exactly one directed edge. Then $`|D_i^{}|=2`$ and $`\varphi ^{}`$ extends to an isomorphism from $`G[XYD_i]`$ to $`G^{}[X^{}Y^{}D_i^{}]`$.

Proof of Claim.  Let $`C`$ be the class in $`𝒞(X)`$ including $`D_i`$ and $`C^{}`$ be the class in $`𝒞(X^{})`$ including $`D_i^{}`$. Claim 8.2 implies that $`C=D_i`$.

Let us prove that $`|D_i^{}|=2`$. Note first that $`D_i^{}`$ cannot consists of a single element. Indeed, since $`|C^{}|2`$, this would mean that $`C^{}`$ is split up into at least two $`D^{}`$-classes. However, at most one of them can have $`\varphi ^{}`$-similar counterpart, contradicting the assumption that the $`\varphi ^{}`$-similarity is a perfect matching between $`𝒟(X)`$ and $`𝒟(X^{})`$.

Let us now show that $`D_i^{}`$ cannot have more than 2 elements. Suppose, to the contrary, that $`|D_i^{}|>2`$. Let $`D_i=\{u,v\}`$ with $`(u,v)E_k`$ and $`(v,u)E_k`$. If $`E_k^{}[C^{}]`$ contains two vertices with both or no directed edges between them, Spoiler selects these two and wins because Duplicator is enforced to reply with $`u`$ and $`v`$ by the analog of Claim 3.13. Assume that between any two vertices of $`E_k^{}[C^{}]`$ there is exactly one directed edge. It is easy to see that for some $`a,b,cC^{}`$ we have $`(a,b),(b,c)E_k^{}`$. Let Spoiler select $`b`$ first. By the analog of Claim 3.13, Duplicator must reply with $`u`$ or $`v`$. In the next move Spoiler wins with $`a`$ if Duplicator replies with $`u`$, and wins with $`c`$ otherwise.

To prove that $`\varphi ^{}`$ extends as desired, let Spoiler select the two vertices of $`D_i^{}C^{}`$. By the analog of Claim 3.13, Duplicator must reply with the vertices of $`D_i=C`$. It is clear that either Spoiler wins or $`\varphi ^{}`$ does extend. $`\mathrm{}`$

Since $`G`$ and $`G^{}`$ are supposed non-isomorphic, there is $`D_i`$ such that $`|D_i||D_i^{}|`$. As in the case of graphs, we call such a $`D_i`$ useful. Note that, by Item 2 of Claim 8.1 and Claim 8.1, every useful $`D_i`$ is homogeneous and, by Claim 8.1, $`D_i^{}`$ is also homogeneous coherently with $`D_i`$ over all unary and binary relations.

The rest of the proof carries over without any changes.

The main result of this section is provable similarly to Theorem 3.15 virtually with no change.

###### Theorem 8.2

Let $`G`$ and $`G^{}`$ be structures over the same vocabulary with maximum relation arity 2. If $`G`$ and $`G^{}`$ are non-isomorphic and have the same order $`n`$, then $`\text{D}_1(G,G^{})(n+3)/2`$.

### 8.3 Defining binary structures

Theorem 4.6 generalizes to binary structures with minor changes in the proof as follows. Lemmas 4.1 and 4.2 hold true for binary structures literally, see Remark 4.9 where $`k=2`$ makes no change. As a consequence, by Lemma 8.1, Lemma 4.3 literally holds as well. Lemma 4.4, where the homogeneousity is redefined in Section 8.1, also holds literally with the same in essence, easily adapted proof. Note that Definition 4.5 makes a perfect sense for the generalized homogeneousity. Finally, Theorem 4.6 holds true with literally the same proof.

## 9 Uniform hypergraphs

We here extend the results of Sections 3 and 4 to uniform hypergraphs.

### 9.1 Definitions

A $`k`$-uniform hypergraph (or $`k`$-graph) $`G`$ on vertex set $`V(G)`$ is a family of $`k`$-element subsets of $`V(G)`$ called (hyper)edges. As usually, the set of edges of $`G`$ is denoted by $`E(G)`$. The $`k`$-graphs generalize the notion of an ordinary graph, which is actually a $`2`$-graph. From the logical point of view, a $`k`$-graph is a structure with a single $`k`$-ary relation $`E`$ which is symmetric in the sense that $`E(x_1,\mathrm{},x_k)=E(x_{\pi (1)},\mathrm{},x_{\pi (k)})`$ for any permutation $`\pi `$ of the $`k`$-element index set and anti-reflexive in the sense that $`E(x_1,\mathrm{},x_k)=0`$ whenever at least two of the $`x_i`$’s coincide. Thus, we will sometimes write $`E(x_1,\mathrm{},x_k)=1`$ to say that $`\{x_1,\mathrm{},x_k\}E(G)`$ and $`E(x_1,\mathrm{},x_k)=0`$ to say that $`\{x_1,\mathrm{},x_k\}E(G)`$.

Most graph-theoretic notions and all notions introduced for general structures directly extend to $`k`$-graphs. For example, the complete $`k`$-graph of order $`n`$ has $`n`$ vertices and all possible $`\left(\genfrac{}{}{0pt}{}{n}{k}\right)`$ edges. The empty $`k`$-graph of order $`n`$ has $`n`$ vertices and no edges. If $`XV(G)`$, then $`G[X]`$ denotes the $`k`$-graph induced by $`G`$ on $`X`$, that is, the $`k`$-graph with the vertices in $`X`$ and with all those edges $`AE(G)`$ for which $`AX`$.

Let $`0bk1`$ and $`a=kb`$. Given a $`b`$-vertex set $`BV(G)`$, we define the link-graph $`G_B`$ of $`B`$ to be the $`a`$-graph on the vertex set $`V(G)B`$ with the edge set

$$E(G_B)=\{A:|A|=a,ABE(G)\}.$$

Clearly, $`G_{\mathrm{}}=G`$.

### 9.2 Distinguishing $`k`$-graphs

###### Theorem 9.1

Let $`k2`$. If $`G`$ and $`G^{}`$ are non-isomorphic $`k`$-graphs both of order $`n`$, then

$$\text{D}_1(G,G^{})\left(1\frac{1}{k}\right)n+2k1.$$

If $`k>2`$, we do not know if the bound of the theorem is tight since the only lower bound we know for any $`k`$ is $`(n+1)/2`$. The latter is given by the same Example 2.13 as for $`2`$-graphs, where $`K_m`$ now means the complete $`k`$-graph and $`\overline{K_m}`$ means the empty $`k`$-graph of order $`m`$.

The proof of Theorem 9.1 takes the rest of the subsection. It will be built on the framework worked out in Section 3. However, note that Spoiler’s strategy that will be designed in the proof of the key Lemma 9.7 will be somewhat different.

As it was already mentioned, Definition 3.1 of the similarity relation $``$ makes a perfect sense for an arbitrary class of structures, in particular, for $`k`$-graphs. Recall that $`uv`$ for vertices $`u`$ and $`v`$ of a $`k`$-graph $`G`$ if the transposition $`(uv)`$ is an automorphism of $`G`$. Both items of Lemma 3.2 hold true for $`k`$-graphs but Item 2 should be supplemented with more information specific for hypergraphs, see Item 4 of the following lemma.

###### Lemma 9.2

Let $`G`$ be a $`k`$-graph.

1. Given a $`k`$-element $`UV(G)`$ and $`v,wV(G)`$, let $`U^{(vw)}`$ denote the result of substituting $`v`$ in place of $`w`$ and vise versa in $`U`$. Assume that $`vw`$. Then $`UE(G)`$ iff $`U^{(vw)}E(G)`$.
2. $``$ is an equivalence relation on $`V(G)`$.
3. If $`v_iw_i`$ for all $`1ik`$, then $`E(v_1,\mathrm{},v_k)=E(w_1,\mathrm{},w_k)`$.
4. Let $`vV(G)`$ and $`[v]_G`$ denote the similarity class containing $`v`$. Let $`BV(G)`$ be disjoint with $`[v]_G`$ and have at most $`k1`$ vertices. Then the graph $`G_B\left[[v]_G\right]`$ is either complete or empty. In particular, $`G\left[[v]_G\right]`$ is either complete or empty.
5. Let $`H`$ be another $`k`$-graph, $`XV(H)`$, and $`G=H[X]`$. Then $`[v]_HX[v]_G`$ for any $`vX`$. In other words, the partition of $`X`$ into the $`H`$-similarity classes refines the partition into $`G`$-similarity classes.

Proof.  1) This item is straightforward from the definition of the $``$-relation.

2) The only not completely obvious task is, given pairwise distinct vertices $`u`$, $`v`$, and $`w`$, to infer from $`uv`$ and $`vw`$ that $`uw`$. For any $`(k1)`$-element set of vertices $`\{x_1,\mathrm{},x_{k1}\}`$ we have to check that

$$E(u,x_1,\mathrm{},x_{k1})=E(w,x_1,\mathrm{},x_{k1}).$$
(23)
If $`x_iv`$ for any $`i`$, this is easy. Assume that $`x_{k1}=v`$. Then the relations $`uv`$ and $`vw`$ imply by Item 1 that both the left hand side and the right hand side of (23) are equal to $`E(u,w,x_1,\mathrm{},x_{k2})`$.

3) Let $`t`$ denote the number of common elements in $`\{v_1,\mathrm{},v_k\}`$ and $`\{w_1,\mathrm{},w_k\}`$. We proceed by the reverse induction on $`t`$. If $`t=k`$, the claim is trivial. Otherwise assume that $`w_i\{v_1,\mathrm{},v_k\}`$. We have $`E(v_1,\mathrm{},v_i,\mathrm{},v_k)=E(v_1,\mathrm{},w_i,\mathrm{},v_k)`$ by Item 1 and $`E(v_1,\mathrm{},w_i,\mathrm{},v_k)=E(w_1,\mathrm{},w_i,\mathrm{},w_k)`$ by the induction hypothesis.

4) This item follows directly from Item 3.

5) Let $`v,wX`$ and assume that $`vw`$ in $`H`$. As easily follows from Item 1, $`vw`$ as well in $`G`$.

We will use all the definitions and notation introduced in Section 3.1. In particular, given $`XV(G)`$, we will deal with the relation $`_X`$ on $`\overline{X}`$, the partition $`𝒞(X)`$ of $`\overline{X}`$, the sets $`Y(X)`$ and $`Z(X)`$, and the partition $`𝒟(X)`$ of $`Z(X)`$. In addition, we need a new relation and a new important parameter.

###### Definition 9.3

The relation $`_X`$ coincides with the equality on $`XY(X)`$ and with the relation $`_{XY(X)}`$ on $`Z(X)`$.

###### Definition 9.4

$`\tau (X)=|Y(X)|+|𝒟(X)|`$.

We now generalize Definition 3.12 over $`k`$-graphs. This needs more care because the operation $``$ for $`k`$-graphs is somewhat more subtle than for graphs.

###### Definition 9.5

Let $`G`$ and $`H`$ be $`k`$-graphs, $`vV(G)`$, and $`l0`$. The notation $`HGlv`$ means that the following conditions are fulfilled.

$`\sigma _G(v)k`$;

$`|H|=|G|+l`$ and $`V(G)V(H)`$;

$`H[V(G)]=G`$;

$`[v]_H=[v]_G(V(H)V(G))`$.

Furthermore, we write $`H=Glv`$ if there is a $`k`$-graph $`K`$ such that $`HK`$ and $`KGlv`$.

Let us see carefully what the relation $`HGlv`$ means for $`k`$-graphs. As easily seen, $`H`$ is obtained from $`G`$ by adding a set $`A`$ of $`l`$ new vertices and some new edges involving at least one vertex from $`A`$. Given a $`k`$-vertex set $`UV(H)`$ having non-empty intersection with $`A`$, we have to decide whether or not $`U`$ is in $`E(H)`$. The criterion is given by Item 4 of Lemma 9.2. Specifically, assume that the intersection $`B=U(V(G)[v]_G)`$ contains $`b`$ vertices. Let $`W[v]_G`$ with $`|W|=kb`$. Then $`UE(H)`$ iff $`BWE(G)`$ (the latter is equally true or false for any choice of $`W`$). This provides us with the complete description of $`H`$. Thus, on the account of Item 4 of Lemma 9.2, we arrive at the conclusion that $`H=Glv`$, if exists, is unique up to an isomorphism. It remains to prove that, if $`H`$ is constructed as described above, then indeed $`HGlv`$. This immediately follows from the following lemma.

###### Lemma 9.6

Let $`G`$ and $`H`$ be $`k`$-graphs, $`vV(G)`$, and $`l0`$.

1) $`HGlv`$ iff the following two conditions are fulfilled.

$`|H|=|G|+l`$ and $`V(G)V(H)`$;

There is $`D[v]_G`$ with $`|D|k`$ such that the following is true: Every injection $`\psi :V(G)V(H)`$ whose restriction to $`V(G)D`$ is the identity map is a partial isomorphism from $`G`$ to $`H`$.

2) $`H=Glv`$ iff the following two conditions are fulfilled.

$`|H|=|G|+l`$;

There is $`D[v]_G`$ with $`|D|k`$ such that the following is true: There exists an injection $`\psi _0:V(G)DV(H)`$ whose every injective extension $`\psi :V(G)V(H)`$ is a partial isomorphism from $`G`$ to $`H`$.

Proof.  1) Let us show first that Conditions A1–A4 imply Conditions B1–B2. Since B1 coincides with A2, we focus on B2. Let $`D[v]_G`$ be an arbitrary set with $`|D|k`$, existing by A1. Assume that $`\psi :V(G)V(H)`$ is an injection whose restriction to $`V(G)D`$ is the identity map. Consider an arbitrary $`k`$-element set $`UV(G)`$ and suppose that $`U=\{u_1,\mathrm{},u_a,v_1,\mathrm{},v_b\}`$, where each $`u_jV(G)D`$ and each $`v_iD`$. Then $`\psi (U)=\{u_1,\mathrm{},u_a,w_1,\mathrm{},w_b\}`$, where $`w_i=\psi (v_i)`$. Note that each $`w_iD(V(H)V(G))`$. By A4 we have $`v_iw_i`$ in $`H`$ for all $`ib`$. By Item 3 of Lemma 9.2, $`\psi (U)E(H)`$ iff $`UE(H)`$. By A3, the latter is equivalent with $`UE(G)`$, proving that $`\psi `$ is indeed a partial isomorphism from $`G`$ to $`H`$.

We now show that Conditions B1–B2 imply Conditions A1–A4. For A1 and A2 this is trivial. Considering $`\psi `$ being the identity map of $`V(G)`$ onto itself, we immediately obtain A3. To obtain A4, it suffices to choose an arbitrary $`v_0[v]_G(V(H)V(G))`$ and prove that, for every $`v^{}[v]_G(V(H)V(G))`$, the vertices $`v_0`$ and $`v^{}`$ are similar in $`H`$. This will give $`[v]_G(V(H)V(G))[v]_H`$. The converse inclusion is given by Item 5 of Lemma 9.2.

Choose $`v_0D`$. According to Item 1 of Lemma 9.2, we have to show, for any $`k`$-vertex set $`UV(H)`$, that $`UE(H)`$ iff $`U^{(v_0v^{})}E(H)`$. If both $`v_0`$ and $`v^{}`$ or none of them are in $`U`$, this is obvious. Otherwise it is enough to consider the case that $`v_0`$ is in $`U`$ but $`v^{}`$ is not. Suppose that

$$U=\{u_1,\mathrm{},u_a,v_0,v_1,\mathrm{},v_b,w_1,\mathrm{},w_c\},$$

where all $`u_iV(G)D`$, all $`v_iD`$, and all $`w_iV(H)V(G)`$.

Since $`|D|k`$, we can choose in $`D\{v_0,v_1,\mathrm{},v_b\}`$ pairwise distinct vertices $`v_1^{},\mathrm{},v_c^{}`$. Define $`\psi _1:V(G)V(H)`$ so that $`\psi _1(v_i^{})=w_i`$ for each $`ic`$ and $`\psi _1(x)=x`$ for all other $`xV(G)`$. If $`v^{}[v]_G\{v_1^{},\mathrm{},v_c^{}\}`$, let $`\psi _2`$ be the same as $`\psi _1`$. Notice that in this case $`\psi _2^1(U^{(v_0v^{})})=(\psi _1^1(U))^{(v_0v^{})}`$ and $`v_0v^{}`$ in $`G`$. If $`v^{}\{v_1^{},\mathrm{},v_c^{}\}(V(H)V(G))`$, let $`\psi _2`$ coincide with $`\psi _1`$ everywhere but $`v_0`$, where we set $`\psi _2(v_0)=v^{}`$. Notice that now $`\psi _2^1(U^{(v_0v^{})})=\psi _1^1(U)`$. In both of the cases we have $`\psi _1^1(U)E(G)`$ iff $`\psi _2^1(U^{(v_0v^{})})E(G)`$. By B2, $`\psi _1`$ and $`\psi _2`$ are partial isomorphisms from $`G`$ to $`H`$. It follows that $`UE(H)`$ iff $`U^{(v_0v^{})}E(H)`$, completing derivation of A4.

2) Suppose that $`HK`$ and $`KGlv`$. Then Item 2 easily follows from Item 1 applied for $`k`$-graphs $`G`$ and $`K`$. In particular, if we have Condition B2 with a set $`D`$, then a map $`\psi _0`$ in Condition C2 can be taken the restriction of an isomorphism from $`K`$ to $`H`$ to the set $`V(G)D`$.

###### Lemma 9.7

Let $`k2`$. If $`G`$ and $`G^{}`$ are non-isomorphic $`k`$-graphs of orders $`n`$ and $`n^{}`$ respectively and $`nn^{}`$, then

$$\text{D}_1(G,G^{})\left(1\frac{1}{k}\right)n+2k1$$
(24)
unless $`G^{}=G(n^{}n)v`$ for some $`vV(G)`$.

Proof.  We will describe a strategy of Spoiler winning $`\text{Ehr}_r(G,G^{})`$ for $`r=(11/k)n+2k1`$ unless $`G^{}=G(n^{}n)v`$. The strategy splits the game in two phases.

Phase 1

Spoiler’s aim is to select in $`G`$ a set of vertices $`X`$ with some useful properties. He proceeds as follows. Initially, $`X=\mathrm{}`$. If there is $`B\overline{X}`$ with at most $`k1`$ element such that $`\tau (XB)>\tau (X)`$, Spoiler chooses a such $`B`$ arbitrarily, selects all vertices in $`B`$, and resets $`X`$ to $`XB`$. As soon as there is no such $`B`$, Phase 1 ends.

Suppose that Phase 1 has now ended, during which Spoiler made $`s`$ moves. The set $`X=\{x_1,\mathrm{},x_s\}`$ is from now on fixed and consists of the vertices selected by Spoiler during Phase 1, where $`x_i`$ is selected in the $`i`$-th round. It is easy to see that

$$\tau (X)1\frac{s}{k1}.$$
(25)
Since $`s+\tau (X)n`$, we have

$$s\left(1\frac{1}{k}\right)(n1).$$
(26)
We will refer to the sets $`Y(X)`$ and $`Z(X)`$, and to the relation $`_X`$ omitting the subscript $`X`$.

Claim 9.7.1.  Let $`U=\{u_1,\mathrm{},u_k\}`$ and $`W=\{w_1,\mathrm{},w_k\}`$ be $`k`$-element subsets of $`V(G)`$ and $`u_iw_i`$ for all $`1ik`$. Then $`UE(G)`$ iff $`WE(G)`$.

In particular, if $`uw`$, then $`uw`$ for any $`u,wV(G)`$, i.e., $`𝒟(X)`$ coincides with the partition of $`Z`$ into the similarity classes.

Proof of Claim.  Notice that the claim easily follows from its particular case that $`u_i=w_i`$ for $`ik1`$. We hence assume this.

Suppose on the contrary that $`UE(G)`$ but $`WE(G)`$. Let us modify $`X`$ in $`k1`$ steps as follows. We will denote the result of modification after the $`i`$-th step by $`X_i`$. Initially $`X_0=X`$. We set $`X_i=X_{i1}\{u_i\}`$ if $`u_iX_{i1}Y(X_{i1})`$ and $`X_i=X_{i1}`$ otherwise. We eventually enforce $`u_k_{X_{k1}Y(X_{k1})}w_k`$. Since in the $`i`$-th step no single-element $`_{X_{i1}}`$-class disappears, we have $`\tau (X_{k1})>\tau (X)`$ contradicting the assumption that Phase 1 has already ended. $`\mathrm{}`$

Let $`x_i^{}`$ denote the vertex of $`G^{}`$ selected by Duplicator in the $`i`$-th round of Phase 1 and $`X^{}=\{x_1^{},\mathrm{},x_s^{}\}`$. Assume that Duplicator has still not lost. Thus, the map $`\varphi :XX^{}`$ given by $`\varphi (x_i)=x_i^{}`$ for $`is`$ is a partial isomorphism from $`G`$ to $`G^{}`$. Similarly to Claim 3.13 we see that Duplicator now plays under the following constraint.

Claim 9.7.2.  Whenever after Phase 1 Spoiler selects a vertex $`vV(G)V(G^{})`$, Duplicator responds with a $`\varphi `$-similar vertex or otherwise immediately loses.$`\mathrm{}`$

Phase 2

Similarly to the proof of Lemma 3.13, we conclude from Claim 9.7 that the $`\varphi `$-similarity determines the perfect matching between the singletons in $`𝒞(X)`$ and the singletons in $`𝒞(X^{})`$ unless Spoiler wins making 2 moves and at most 1 alternation in Phase 2. Denote the classes of $`𝒞(X)`$ by $`C_1,\mathrm{},C_t`$ and the classes of $`𝒞(X^{})`$ by $`C_1^{},\mathrm{},C_t^{}^{}`$. We therefore will assume that, for some $`qt`$, $`|C_i|=1`$ iff $`iq`$, $`|C_i^{}|=1`$ iff $`iq`$, and $`C_i_\varphi C_i^{}`$ for all $`iq`$. Let $`Y^{}=Y(X^{})`$ and $`\varphi ^{}:YY^{}`$ be an extension of $`\varphi `$ that maps $`C_i`$ onto $`C_i^{}`$ for every $`iq`$.

Claim 9.7.3.  $`\varphi ^{}`$ is a partial isomorphism from $`G`$ to $`G^{}`$, unless Spoiler wins in the next $`k`$ moves with no alternation, having made at total $`s+k(11/k)n+k`$ moves.

Proof of Claim.  Assume that there is a $`k`$-vertex set $`UXY`$ such that exactly one of the sets $`U`$ and $`U^{}=\varphi ^{}(U)`$ is an edge of $`G`$ or $`G^{}`$ respectively. Let Spoiler select all vertices of $`U`$. If Duplicator responds with the vertices of $`U^{}`$, he obviously loses. If Duplicator moves at least once outside $`U^{}`$, he violates the $`\varphi `$-similarity and loses by Claim 9.7. $`\mathrm{}`$

Assume that Duplicator is lucky to ensure that $`\varphi ^{}`$ is a partial isomorphism from $`G`$ to $`G^{}`$. Let $`Z=Z(X)`$ and $`Z^{}=Z(X^{})`$.

Claim 9.7.4.  Whenever in Phase 2 Spoiler selects a vertex $`vZZ^{}`$, Duplicator responds with a $`\varphi ^{}`$-similar vertex or otherwise loses in at most $`k1`$ next rounds with no alternation between $`G`$ and $`G^{}`$ in these rounds.

Proof of Claim.  Let $`u`$ be the vertex selected by Duplicator in response to $`v`$ and assume that $`u_\varphi ^{}v`$. Suppose that $`vZ^{}`$ (the case of $`vZ`$ is completely similar). If $`uZ`$, Duplicator has already lost. If $`uZ^{}`$, there exists a $`(k1)`$-vertex set $`WXY`$ such that $`W\{u\}`$ is an edge but $`\varphi ^{}(W)\{v\}`$ is not or vice versa. Spoiler selects the so far unselected vertices of $`\varphi ^{}(W)`$. Duplicator, who either responds with vertices in $`W`$ or violates the $`\varphi `$-similarity, loses. $`\mathrm{}`$

Claim 9.7 readily implies that every class in $`𝒟(X)`$ or $`𝒟(X^{})`$ has a $`\varphi ^{}`$-similar counterpart in, respectively, $`𝒟(X^{})`$ or $`𝒟(X)`$ unless Spoiler wins making in Phase 2 at most $`k`$ moves and at most one alternation between the graphs (selecting a vertex in a $`𝒟`$-class without $`\varphi ^{}`$-similar counterpart and applying the strategy of Claim 9.7). We will therefore assume that $`𝒟(X)=\{D_1,\mathrm{},D_p\}`$, $`𝒟(X^{})=\{D_1^{},\mathrm{},D_p^{}\}`$, and $`D_i_\varphi ^{}D_i^{}`$ for all $`ip`$.

Claim 9.7.5.  Unless Spoiler is able to win making $`2k1`$ moves and at most 1 alternation in Phase 2, the following condition is met:

For any $`U=\{u_1,\mathrm{},u_k\}`$, a $`k`$-vertex subset of $`V(G)`$, and $`U^{}=\{u_1^{},\mathrm{},u_k^{}\}`$, a $`k`$-vertex subset of $`V(G^{})`$, such that $`u_i_\varphi ^{}u_i^{}`$ for all $`ik`$, we have $`UE(G)`$ iff $`U^{}E(G^{})`$.

Proof of Claim.  Suppose, to the contrary, that there are such $`U`$ and $`U^{}`$ but exactly one of $`U`$ and $`U^{}`$ is an edge. Spoiler selects the vertices in $`U^{}`$. Let $`U^{\prime \prime }=\{u_1^{\prime \prime },\mathrm{},u_k^{\prime \prime }\}`$ be the set of the respective responses of Duplicator. If $`u_i^{\prime \prime }_\varphi ^{}u_i^{}`$ for some $`ik`$, Spoiler wins in the next $`k1`$ moves according to Claim 9.7. Assume that $`u_i^{\prime \prime }_\varphi ^{}u_i^{}`$ for all $`ik`$. Together with $`u_i_\varphi ^{}u_i^{}`$ for all $`i`$, this implies $`u_iu_i^{\prime \prime }`$ for all $`i`$. Using Claim 9.7, we conclude that $`U^{\prime \prime }`$ is an edge iff $`U`$ is and iff $`U^{}`$ is not. Thus, Duplicator loses anyway. $`\mathrm{}`$

In the sequel we suppose that the condition $`()`$ in Claim 9.7 holds (for else Spoiler wins within the claimed bound (24) for the number of moves). Assume for a while that $`|D_i|=|D_i^{}|`$ for all $`ip`$. Consider an arbitrary bijection $`\overline{\varphi }:V(G)V(G^{})`$ that extends $`\varphi ^{}`$ and maps each $`D_i`$ onto $`D_i^{}`$. The condition $`()`$ immediately implies that $`\overline{\varphi }`$ is an isomorphism from $`G`$ to $`G^{}`$. Since $`G`$ and $`G^{}`$ are supposed non-isomorphic, there must exist a $`D_i`$ such that $`|D_i||D_i^{}|`$. We will call such a $`D_i`$ useful.

Similarly to Claim 3.13, we obtain, as a corollary from Claim 9.7, the following threat for Duplicator.

Claim 9.7.6.  If $`D_i`$ is useful, then Spoiler is able to win having made in Phase 2 at most $`\mathrm{min}\{|D_i|,|D_i^{}|\}+k`$ moves and at most 1 alternation between $`G`$ and $`G^{}`$.$`\mathrm{}`$

Suppose now that there are two useful classes, $`D_i`$ and $`D_j`$. Observe that

$$|D_i|+|D_j|=|Z|\underset{li,j}{}|D_l|(nsq)(\tau (X)q2)=ns\tau (X)+2.$$

It follows that one of the useful classes has at most $`(ns\tau (X)+2)/2`$ vertices. Thus, Spoiler is able to win totally in at most

$$s+\frac{ns\tau (X)+2}{2}+k=\frac{n+s\tau (X)+2}{2}+k$$
(27)
rounds. From (25) and (26), we infer that

$$s\tau (X)s\frac{s}{k1}1=s\frac{k2}{k1}1\left(1\frac{2}{k}\right)(n1)1.$$

The bound (27) therefore does not exceed

$$\left(1\frac{1}{k}\right)n+k+\frac{1}{k},$$

which is within the required bound (24).

Finally, suppose that there is a unique useful class $`D_m`$. According to Claim 9.7, Spoiler is able to win in at most $`|D_m|+k`$ moves, with the total number of moves $`s+|D_m|+k`$ within the required bound (24) provided $`|D_m|k1`$. Thus, we arrive at the conclusion that the bound (24) may not hold true in the only case that there is exactly one useful class $`D_m`$ and $`|D_m|k`$. Let $`\psi _0:V(G)D_mV(G^{})D_m^{}`$ be an extension of $`\varphi ^{}`$ that maps each $`D_i`$, $`im`$, onto $`D_i^{}`$. Let $`\psi :V(G)V(G^{})`$ be an arbitrary injective extension of $`\psi _0`$ (mapping $`D_m`$ into $`D_m^{}`$). By the condition $`()`$ in Claim 9.7, $`\psi `$ is a partial isomorphism from $`G`$ to $`G^{}`$. Take an arbitrary $`vD_m`$. By Claim 9.7, we have $`D_m[v]_G`$. On the account of Item 2 of Lemma 9.6 we conclude that $`G^{}=G(n^{}n)v`$, completing the proof of the lemma.

### 9.3 Defining $`k`$-graphs

Theorem 4.6 carries over $`k`$-graphs in a weaker form. The analogs of Lemmas 4.1 and 4.2 that we have for $`k`$-graphs (see Remark 4.9) together with Lemma 9.7, give the following analog of Lemma 4.3:

Let $`G`$ and $`G^{}`$ be non-isomorphic $`k`$-graphs. Let $`n`$ denote the order of $`G`$. Then we have

$$\text{D}_1(G,G^{})\left(1\frac{1}{k}\right)n+2k1$$

unless

$$\sigma (G)>\left(1\frac{1}{k}\right)n+k1.$$
(28)
In the latter case we have

$$\sigma (G)+1\text{D}_1(G,G^{})\sigma (G)+k.$$
(29)
Unfortunately, we cannot efficiently find the precise value of $`\text{D}_1(G,G^{})`$ in the range (29) for $`G`$ with (28), as it was done for 2-graphs in Lemma 4.4. Anyway, we have the following result, which is rather reasonable as $`\sigma (G)`$ is efficiently computable.

###### Theorem 9.8

If $`\sigma (G)\left(1\frac{1}{k}\right)n+k1`$, then

$$\text{D}_1(G,G^{})\left(1\frac{1}{k}\right)n+2k1.$$

Otherwise,

$$\text{D}_1(G)\sigma (G)+k$$

and this bound is at most $`k1`$ apart from the precise value of $`\text{D}(G)`$.

## 10 Open questions

1. In Section 1 we define

$$\text{}(n)=\mathrm{max}\left\{\text{D}(G,G^{}):G\cong ̸G^{},|G|=|G^{}|=n\right\}.$$

By Example 2.13 and Theorem 1.1,

$$\frac{n+1}{2}\text{}(n)\frac{n+3}{2}.$$

This determines $`\text{}(n)`$ if $`n`$ is even and leaves two possibilites for $`\text{}(n)`$ if $`n`$ is odd. Which is the right value?

2. Given a graph $`G`$, is the number $`\text{D}(G)`$ computable (T. Łuczak )? Can one, at least, improve the computable upper bound of Theorem 1.2, that is, can one lower the bound in Theorem 1.2 below $`n/2`$, of course, extending the class $`𝒞`$?

3. Theorem 5.1 is an improvement in the alternation number over Theorem 1.1. Can one as well improve on Theorem 1.2?

4. Prove analogs of Theorem 5.1 for digraphs and $`k`$-graphs.

5. Improve the constant $`c_d`$ in Theorem 6.2. Find connected bounded degree graphs $`G`$ and $`G^{}`$ of order $`n`$ with linear lower bound $`\text{D}(G,G^{})=\mathrm{\Omega }(n)`$ better than that given by Cai, Fürer, and Immerman  (cf. Proposition 7.16).

6. For the optimum dimension of the Weisfeiler-Lehman algorithm we know bounds $`0.00465n<\text{WL}(n)0.5n+0.5`$, where the lower bound is due to Cai, Fürer, and Immerman  and the upper bound is shown in Section 7. Make the gap between these bounds closer.

7. Generalize Theorem 8.2 over structures with maximum relation arity $`k`$ proving a tight upper bound $`\text{D}_1(G,G^{})c_kn(1+o(1))`$ for such structures $`G`$ and $`G^{}`$ of order $`n`$. We currently know  that $`1/2c_k11/(2k)`$. In the particular case of $`k`$-graphs, Theorem 9.1 gives us a better upper bound with $`c_k=11/k`$. How tight is it?

8. Find an analog of Lemma 4.4 for $`k`$-graphs. Namely, let $`G`$ and $`G^{}`$ be $`k`$-graphs of orders $`nn^{}`$, $`\sigma (G)n/2`$, and $`G^{}=G(n^{}n)v`$ for some $`vV(G)`$ with $`\sigma _G(v)=\sigma (G)`$. By an analog of Lemma 4.2 for $`k`$-graphs (see Remark 4.9), we have $`\sigma (G)+1\text{D}(G,G^{})\text{D}_1(G,G^{})\sigma (G)+k`$. How to efficiently compute the exact value of $`\text{D}(G,G^{})`$?

9. Let $`G`$ be a graph. Let $`L^{}(G)`$ denote the minimum $`l`$ such that over the variable set $`\{x_1,\mathrm{},x_l\}`$ there is a first order formula defining $`G`$. Is it true that $`L^{}(G)=\mathrm{max}\left\{\text{L}(G,G^{}):G^{}\cong ̸G\right\}`$? In other terms, are the definabilities in the $`l`$-variable first order logic and in the $`l`$-variable infinitary logic equivalent?

The affirmative answer would follow from this assumption: There is a function $`f`$ such that, if graphs $`G`$ and $`G^{}`$ are distinguished by a formula with $`l`$ variables, then they are distinguished by a formula with $`l`$ variables of quantifier rank at most $`f(n,l)`$, where $`n`$ is the order of $`G`$ (no dependence on the order of $`G^{}`$!). In combinatorial terms: If Spoiler can win the game on $`G`$ and $`G^{}`$ with $`l`$ pebbles in arbitrary number of rounds (reusing pebbles is allowed), then he can win with $`l`$ pebbles in $`f(n,l)`$ rounds, irrespective of the order of $`G^{}`$. Is it true?

### Acknowledgments

The third author is grateful to Georg Gottlob and members of his department at the Vienna University of Technology for their hospitality during this author’s visit in the summer 2002.