Computability by Monadic Second-Order Logic

A binary relation on graphs is recursively enumerable if and only if it can be computed by a formula in monadic second-order logic. The latter means that the formula defines a set of graphs, in the usual way, such that each"computation graph"in that set determines a pair consisting of an input graph and an output graph.

There are many characterizations of computability, but the one presented here does not seem to appear explicitly in the literature. 1 Nevertheless, it is a natural and simple characterization, based on the intuitive idea that a computation of a machine, or a derivation of a grammar, can be represented by a graph satisfying a formula of monadic second-order (MSO) logic. Assuming the reader to be familiar with MSO logic on graphs (see, e.g., [CE12,Chapter 5]), the MSOcomputability of a binary relation on graphs can be given in half a page, see below. One advantage of the definition is that there is no need to code the graphs as strings or numbers.
For an alphabet Γ, we consider directed edge-labeled graphs g = (V, E) over Γ where V is a nonempty finite set of nodes and E ⊆ V × Γ × V is a set of labeled edges. We also denote V by V g , and E by E g . An edge (u, γ, v) ∈ E g is called a γ-edge. Isomorphic graphs are considered to be equal. The set of all (abstract) graphs over Γ is denoted by G Γ .
To model computations we use a special edge label ν that is not in Γ. We define a computation graph over Γ to be a graph h over Γ ∪ {ν} with at least one ν-edge such that for every u, v, u ′ , v ′ ∈ V h , (1) (u, ν, u) / ∈ E h , and (2) if (u, ν, v), (u ′ , ν, v ′ ) ∈ E h , then (u, ν, v ′ ) ∈ E h . The input graph in(h) is defined to be the subgraph of h induced by all nodes that have an outgoing ν-edge, and the output graph out(h) is the subgraph of h induced by all nodes that have an incoming ν-edge. By (2) above, the ν-edges of h connect every node of in(h) to every node of out(h), and so by (1) above, V in(h) and V out(h) are disjoint. In fact, the role of the ν-edges is just to specify an ordered pair of disjoint subsets of V h , in a simple way. This notion of computation graph generalizes the "pair graph" of [EV20], which on its turn generalizes the "origin graph" of [BDGP17].
For a set H of computation graphs over Γ we define the graph relation computed by H to be rel(H) = {(in(h), out(h)) | h ∈ H} ⊆ G Γ × G Γ . Finally, we say that a graph relation R ⊆ G Γ × G Γ is MSO-computable if there are an alphabet ∆ and an MSO-definable set H of computation graphs over Γ ∪ ∆ such that rel(H) = R. As observed before, we assume the reader to be familiar with MSO logic on graphs. 2 The closed MSO formula ϕ that defines the set H can be viewed as a "machine" of which the computations are represented by the graphs in H. We will also say that rel(H) is the graph relation computed by ϕ. The auxiliary alphabet ∆ is needed to allow the edges of a computation graph that are not part of its input or output graph, to carry arbitrary information in their label; it is similar to the "working alphabet" of a machine. This notion of MSO-computability generalizes the "MSO-expressibility" of graph relations of [EV20], 3 which on its turn generalizes the MSO graph transductions of [CE12, Chapter 7] (as shown in [EV20, Section 7.1]).
Example. Let R ⊆ G Γ × G Γ be the set of all (g, g ′ ) such that g ′ is an induced subgraph of g. The graph relation R is MSO-computable because it can be computed by an MSO-definable set H of computation graphs over Γ ∪ ∆, with ∆ = {d}. We note that, by definition, the set of all computation graphs h over Γ ∪ ∆ is MSO-definable, and the sets of nodes V in(h) and V out(h) can be expressed in MSO logic. The set H consists of computation graphs h such that V h = V in(h) ∪ V out(h) , in(h) and out(h) are graphs over Γ, and the d-edges form an isomorphism from out(h) to an induced subgraph of in(h). The last condition means, in detail, that for every u, v, if u ∈ V out(h) , then u has an outgoing d-edge, There may be γ-edges in h between in(h) and out(h), with γ ∈ Γ; though they are harmless, we could additionally forbid them. Obviously the above conditions can be expressed by an MSO formula ϕ, which defines H. Moreover rel(H) = R, and hence R is MSO-computable. Note that R is even "MSO-expressible", in the sense of [EV20].
As another (similar) example, if R consists of all (g, g ′ ) such that g has at least two, disjoint, induced subgraphs isomorphic to g ′ , then we take ∆ = {d 1 , d 2 }, we require that the d i -edges satisfy the same conditions as the d-edges above (for each i ∈ {1, 2}), and we require that no node of in(h) has both an incoming d 1 -edge and an incoming d 2 -edge.
Our aim is now to prove the following theorem.

Theorem. A graph relation is MSO-computable if and only if it is recursively enumerable.
Recursive enumerability of a graph relation R means that there is a (single tape) nondeterministic Turing machine M such that (g, g ′ ) ∈ R if and only if, on input g, M has a computation that outputs g ′ . In one direction this theorem is obvious: every MSO-computable graph relation is recursively enumerable. In fact, on input g ∈ G Γ (coded as a string in an appropriate way) M guesses a computation graph h over Γ ∪ ∆ such that in(h) = g, checks whether h satisfies the MSO formula ϕ (cf. [CE12, Chapter 6]), and if so, outputs the (coded) graph out(h). To show the other direction we first consider the case of string relations. For the notion of MSO-computability we represent a string w = γ 1 γ 2 · · · γ k over Γ with the graph gr(g) ∈ G Γ such that V gr(g) = {1, 2, . . . , k + 1} and The proof is similar to the one of [CE12, Theorem 5.6]. Let M be a nondeterministic Turing machine that computes the recursively enumerable string relation R ⊆ Γ * × Γ * . Consider a computation of M that, for an input string w, outputs the string w ′ . Suppose that it uses space m and time n. Thus, it can be viewed as a sequence of strings w 1 , . . . , w n , each of length m, such that w i is the content of M 's tape at time i (including the state of M ), w 1 contains w (plus the initial state and blanks), and w n contains w ′ (and a final state and blanks). Clearly, this sequence can be represented by a grid of dimension n×(m+1). The rows of the grid are the graphs gr(w 1 ), . . . , gr(w n ), which are connected by * -labeled column edges from the j-th node of w i to the j-th node of w i+1 for every 1 ≤ i ≤ n − 1 and 1 ≤ j ≤ m + 1. It is easy to turn that grid into a computation graph h by adding ν-edges from the nodes of gr(w) in the first row to those of gr(w ′ ) in the last row. Thus, h is a computation graph over Γ ∪ ∆ such that in(h) = gr(w) and out(h) = gr(w ′ ), where the alphabet ∆ consists of the column symbol * , the working symbols of M (including the blank), and the states of M . Since the set of grids is MSO-definable (as shown in [CE12, Section 5.2]), it is a straightforward exercise in MSO logic to show that the computation graphs h, obtained from the (successful) computations of M , can be defined by an MSO formula ϕ M . In particular, ϕ M should express that the consecutive rows of the grid (corresponding to strings w i and w i+1 ) satisfy the (local) changes determined by the instructions of M . This shows that the graph relation computed by ϕ M is gr(R) = {(gr(w), gr(w ′ )) | (w, w ′ ) ∈ R}, and so, gr(R) is MSO-computable.
For an alphabet Γ, let the graph encoding relation enc Γ consist of all pairs (g, gr(w)) such that g ∈ G Γ and w is an appropriate encoding of g as a string (which we will specify later). By definition, a graph relation R ⊆ G Γ × G Γ is recursively enumerable if there is a recursively enumerable string relation R ′ such that R is the composition of enc Γ , gr(R ′ ), and enc −1 Γ . Hence, to obtain our theorem for graph relations it now suffices to prove the following two lemmas.
Lemma 1. The class of MSO-computable graph relations is closed under inverse and composition.
Proof of Lemma 1. Closure under inverse is obvious: just reverse the direction of all ν-edges. To prove closure under composition, let R 1 and R 2 be graph relations computed by MSO formulas ϕ 1 and ϕ 2 . We may assume that ϕ 1 and ϕ 2 use the same auxiliary alphabet ∆. Moreover, we may assume that every computation graph h defined by ϕ 1 or ϕ 2 is connected: if not, then add a special symbol µ to ∆ and require that every node u of h that is not in in(h) or out(h), has a µ-edge to in(h) or out(h). Finally, we assume that ϕ 1 uses the label ν 1 instead of ν, and ϕ 2 uses ν 2 instead of ν, with ν 1 = ν 2 . The MSO formula ϕ that computes the composition of R 1 and R 2 , uses the auxiliary alphabet ∆ ∪ {ν 1 , ν 2 , d} and defines computation graphs h that are obtained as the disjoint union of a computation graph h 1 of ϕ 1 and a computation graph h 2 of ϕ 2 , enriched by d-edges that establish an isomorphism between out(h 1 ) and in(h 2 ), and by ν-edges from in(h 1 ) to out(h 2 ). It should be clear that this can be realized by ϕ; for instance, it expresses that the connected components of h minus its enriching edges satisfy ϕ 1 or ϕ 2 , depending on whether they contain a ν 1 -edge or a ν 2 -edge.
Proof of Lemma 2. We first specify the relation enc Γ . Let g ∈ G Γ . We may assume that V g is the set of strings {a, a 2 , . . . , a n } over the alphabet {a}, for some n ≥ 1, where a / ∈ Γ. Let E g = {(u 1 , γ 1 , v 1 ), . . . , (u m , γ m , v m )} for some m ≥ 0. We encode g as the string w = #a#a 2 # · · · #a n $u 1 γ 1 v 1 $ · · · $u m γ 1 v m $ over the alphabet Ω = Γ ∪ {a, #, $}, and we define the graph encoding relation enc Γ ⊆ G Γ × G Ω to consist of all pairs (g, gr(w)). Note that since w depends on linear orderings of V g and E g , a graph g has in general more than one encoding. On the other hand, the relation enc −1 Γ is a function. The set of strings over Ω that encode graphs over Γ is not a regular language, and hence the set enc Γ (G Γ ) of graphs over Ω is not MSO-definable [Büc60,Elg61,Tra62]. However, by enriching each gr(w) with α-edges and δ-edges (where α and δ are special symbols not in Ω), we can turn enc Γ (G Γ ) into an MSO-definable set of graphs. For a string w as displayed above we define gr + (w) to be the graph gr(w) to which α-edges and δ-edges are added as follows. The α-edges allow an MSO formula to express the fact that the first half of w is of the form #a#a 2 # · · · #a n $. For each substring #a i #a i of w (1 ≤ i ≤ n − 1) there are α-edges in gr + (w) from the nodes of the first occurrence of gr(a i ) in gr(w) to the nodes of the second occurrence of gr(a i ) in gr(w), such that they form an isomorphism between these two subgraphs. An MSO formula on gr + (w) can express that w is in the regular language #a(#a * ) * ($a * Γa * ) * $, and, using the outgoing α-edges of gr(#a i #), it can enforce that each substring #a i # is followed by a i+1 # or a i+1 $. The δ-edges in gr + (w) witness the fact that for each substring $u j γ j v j $ of w (1 ≤ j ≤ m) both u j and v j are in {a, a 2 , . . . , a n }, i.e., u j and v j are "declared" in the first half of w. Thus, there are δ-edges from the nodes of gr(u j ) to the nodes of some gr(#a i #) or gr(#a i $) in the first half of gr(w) that establish an isomorphism between gr(u j ) and gr(a i ), and similarly for gr(v j ). This can also easily be expressed by an MSO formula. Moreover, the δ-edges can be used to express that an edge is not encoded twice in w, i.e., if j = k then $u j γ j v j $ = $u k γ k v k $; in fact, u j = u k if and only if the two δ-edges that start from the first nodes of gr(u j ) and gr(u k ) in gr + (w), lead to the same node (and similarly for v j = v k ). We now define enc + Γ to consist of all pairs (g, gr + (w)) where w encodes g. It follows that the set enc + Γ (G Γ ) is MSO-definable. 4 Finally, we show that enc Γ is MSO-computable by describing the computation graphs h over Ω ∪ ∆ in an MSO-definable set H such that rel(H) = enc Γ . The auxiliary alphabet is ∆ = {α, δ, d, e}. Let mid(h) be the subgraph of h induced by the nodes of h that are not incident with a ν-edge, i.e., that are not in V in(h) or V out(h) . First, we require that mid(h) is in enc + Γ (G Γ ), i.e., mid(h) = gr + (w) where w encodes some graph g in G Γ . Second, we require that there are d-edges from out(h) to mid(h) that establish an isomorphism between out(h) and the graph obtained from mid(h) by removing all α-and δ-edges. This means that out(h) = gr(w). Third, it remains to require that in(h) is isomorphic to g. To realize this, we require that in(h) ∈ G Γ and that there are e-edges from in(h) to mid(h) that establish a bijection between V in(h) and the nodes of mid(h) that have an incoming #-edge (thus representing a bijection between V in(h) and V g = {a, a 2 , . . . , a n }). Since we wish this bijection to represent an isomorphism between in(h) and g, we require for every (x, γ, y) ∈ V in(h) × Γ × V in(h) that (x, γ, y) is an edge of in(h) if and only if there exist nodes x ′ , x ′′ , y ′ , y ′′ of mid(h) such that (1) (x, e, x ′ ) and (y, e, y ′ ) are edges of h, (2) (x ′′ , δ, x ′ ) and (y ′′ , δ, y ′ ) are edges of mid(h), (3) x ′′ has an incoming $-edge in mid(h), and (4) there is a directed path from x ′′ to y ′′ in mid(h), of which the consecutive edge labels form a string in a * γ. Condition (1) means that x and y correspond to substrings #a i * and #a j * of w (with * ∈ {#, $}), i.e., to nodes a i and a j of g, and conditions (2)-(4) mean that w has a substring $a i γa j $, i.e., that (a i , γ, a j ) is an edge of g. It should be clear that all these requirements can be expressed in MSO logic, and that the graph relation computed by H is enc Γ .
Lemma 2 is trivial from the point of view of Turing computability: if w encodes g, then both g and gr(w) can be represented by w on the tape of a Turing machine. This is however based on the intuition that our encoding of graphs as strings is computable. Since the notion of MSO-computability discussed here uses graphs as datatype rather than strings, we were able to give a formal proof of that intuition. The reader may object that that proof is based on the intuition that the encoding of a string w as the graph gr(w) is computable. One might then argue that the latter encoding is simpler than the former.
Traditionally, it has been shown that MSO logic is related to regularity, e.g., to regular string languages [Büc60,Elg61,Tra62] and regular tree languages [Don70,TW68]. If one identifies regularity with computability by a finite-state machine, then this approach fails for MSO logic on graphs, because "no notion of finite graph automaton has been defined that would generalize conveniently finite automata on words and terms" ([CE12, Section 1.7]). For this reason, the MSO transducers of [CE12,Chapter 7] were proposed to play the role of finite-state transducers of graphs, and in the case of strings they indeed turned out to be equivalent to two-way finite-state transducers [EH01]. We have shown above how, dropping the finite-state condition, MSO logic is related to computability by any machine.
If, on the other hand, one identifies regularity with rationality, i.e., with a smallest class containing all finite sets of objects and closed under a number of natural operations on sets of objects (union, concatenation, and Kleene star in the case of string languages), then the class of all MSO-definable sets of graphs has a rational characterization [Eng91]. Since the recursively enumerable string relations also have a rational characterization (as discussed in [Eng07]), the question remains whether there is a natural rational characterization of the MSO-computable graph relations. Such a characterization would at least involve the operations of union, composition, and transitive closure of graph relations.
The above quote from [CE12, Section 1.7] refers to the non-existence of a finite-state graph automaton that accepts exactly the MSO-definable sets of graphs. In [Tho91] a finite-state graph acceptor is introduced of which the computations are "tilings" of the input graphs (which have to be graphs of bounded degree). All "tiling-recognizable" sets of graphs accepted by these machines are MSO-definable, and the reverse is true for strings and trees. If we would allow the nodes of our graphs to have labels, then we could model the input graph in(h) and the output graph out(h) of a computation graph h by two special node labels rather than by ν-edges. Then, similar to MSO-computability, we could define a graph relation to be "tiling-computable" by requiring the set H of computation graphs to be tiling-recognizable rather than MSO-definable. This leads to the following question for graphs of bounded degree: is every recursively enumerable graph relation tiling-computable? Note that, as shown in [Tho91, Example 3.2(b)], the set of grids is tiling-recognizable.
Descriptive complexity theory investigates logics that characterize complexity classes. By Fagin's theorem (see, e.g., [Fag93,Theorem 5.1]), the complexity class NP equals the set of problems that can be specified by existential secondorder formulas. In terms of graphs, such a formula requires the existence of an extension of the input graph by additional labeled hyperedges (where a hyperedge is a sequence of nodes), such that the resulting (hyper)graph satisfies a first-order formula. In our notion of MSO-computability we require that the input graph is an induced subgraph of a graph that satifies a monadic second-order formula, and we obtain all recursively enumerable problems.
We finally note that the notion of MSO-computability can easily be generalized to deal with arbitrary relational structures (cf. [CE12, Section 5.1]).
That's all folks! This was my last paper. Thank you, dear reader, and farewell.