Computability by Monadic Second-Order Logic
aa r X i v : . [ c s . F L ] A ug Computability byMonadic Second-Order Logic
Joost Engelfriet
LIACS, Leiden University, the Netherlands ∗ Abstract
A binary relation on graphs is recursively enumerable if and only if itcan be computed by a formula in monadic second-order logic. The lattermeans that the formula defines a set of graphs, in the usual way, such thateach “computation graph” in that set determines a pair consisting of aninput graph and an output graph.
There are many characterizations of computability, but the one presented heredoes not seem to appear explicitly in the literature. Nevertheless, it is a naturaland simple characterization, based on the intuitive idea that a computation of amachine, or a derivation of a grammar, can be represented by a graph satisfyinga formula of monadic second-order (MSO) logic. Assuming the reader to befamiliar with MSO logic on graphs (see, e.g., [CE12, Chapter 5]), the MSO-computability of a binary relation on graphs can be given in half a page, seebelow. One advantage of the definition is that there is no need to code thegraphs 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 oflabeled 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 Γ. Wedefine a computation graph over Γ to be a graph h over Γ ∪ { ν } with at leastone ν -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 nodesthat have an outgoing ν -edge, and the output graph out( h ) is the subgraphof h induced by all nodes that have an incoming ν -edge. By (2) above, the ∗ email: [email protected] ; address: P.O. Box 9512, 2300 RA Leiden. This first sentence and the first part of the next sentence are taken over from [Eng07]. -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 tospecify an ordered pair of disjoint subsets of V h , in a simple way. This notionof computation graph generalizes the “pair graph” of [EV20], which on its turngeneralizes the “origin graph” of [BDGP17].For a set H of computation graphs over Γ we define the graph relationcomputed 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 analphabet ∆ and an MSO-definable set H of computation graphs over Γ ∪ ∆ suchthat rel( H ) = R . As observed before, we assume the reader to be familiar withMSO logic on graphs. The closed MSO formula ϕ that defines the set H canbe viewed as a “machine” of which the computations are represented by thegraphs 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 graphthat are not part of its input or output graph, to carry arbitrary informationin their label; it is similar to the “working alphabet” of a machine. This notionof MSO-computability generalizes the “MSO-expressibility” of graph relationsof [EV20], 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 inducedsubgraph of g . The graph relation R is MSO-computable because it can becomputed 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 beexpressed 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 forman isomorphism from out( h ) to an induced subgraph of in( h ). The last conditionmeans, in detail, that for every u, v, u ′ , v ′ ∈ V h ,(1) if ( u, d, v ) is an edge of h , then u ∈ V out( h ) and v ∈ V in( h ) ,(2) if u ∈ V out( h ) , then u has an outgoing d -edge,(3) if ( u, d, v ) and ( u ′ , d, v ′ ) are edges of h , then(a) u = u ′ if and only if v = v ′ , and(b) for every γ ∈ Γ, ( u, γ, u ′ ) ∈ E h if and only if ( v, γ, v ′ ) ∈ E h .There may be γ -edges in h between in( h ) and out( h ), with γ ∈ Γ; though theyare harmless, we could additionally forbid them. Obviously the above conditionscan 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”, inthe sense of [EV20].As another (similar) example, if R consists of all ( g, g ′ ) such that g has The atomic formulas of MSO logic are x = y , x ∈ X , and edge γ ( x, y ), where x and y arenodes, X is a set of nodes, and edge γ ( x, y ) expresses that there is a γ -edge from x to y . The relation R is MSO-expressible, in the sense of [EV20, Section 3.1], if it is MSO-computable by a set H of pair graphs, where a pair graph is a computation graph h such that V h = V in( h ) ∪ V out( h ) .
2t least two, disjoint, induced subgraphs isomorphic to g ′ , then we take ∆ = { d , d } , we require that the d i -edges satisfy the same conditions as the d -edgesabove (for each i ∈ { , } ), and we require that no node of in( h ) has both anincoming d -edge and an incoming d -edge.Our aim is now to prove the following theorem. Theorem.
A graph relation is MSO-computable if and only if it is recursivelyenumerable.Recursive enumerability of a graph relation R means that there is a (singletape) 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 theoremis obvious: every MSO-computable graph relation is recursively enumerable. Infact, on input g ∈ G Γ (coded as a string in an appropriate way) M guesses acomputation graph h over Γ ∪ ∆ such that in( h ) = g , checks whether h satisfiesthe MSO formula ϕ (cf. [CE12, Chapter 6]), and if so, outputs the (coded) graphout( 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 = γ γ · · · γ k over Γ with the graph gr( g ) ∈ G Γ such that V gr( g ) = { , , . . . , k + 1 } and E gr( g ) = { ( j, γ j , j + 1) | ≤ j ≤ k } . The proof is similar to the one of [CE12,Theorem 5.6]. Let M be a nondeterministic Turing machine that computes therecursively enumerable string relation R ⊆ Γ ∗ × Γ ∗ . Consider a computationof M that, for an input string w , outputs the string w ′ . Suppose that it usesspace m and time n . Thus, it can be viewed as a sequence of strings w , . . . , w n ,each of length m , such that w i is the content of M ’s tape at time i (including thestate of M ), w 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 gridof dimension n × ( m +1). The rows of the grid are the graphs gr( w ) , . . . , 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 − ≤ j ≤ m + 1. It is easy to turnthat 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 graphover Γ ∪ ∆ 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 theblank), and the states of M . Since the set of grids is MSO-definable (as shownin [CE12, Section 5.2]), it is a straightforward exercise in MSO logic to show thatthe computation graphs h , obtained from the (successful) computations of M ,can be defined by an MSO formula ϕ M . In particular, ϕ M should express thatthe consecutive rows of the grid (corresponding to strings w i and w i +1 ) satisfythe (local) changes determined by the instructions of M . This shows that thegraph relation computed by ϕ M is gr( R ) = { (gr( w ) , gr( w ′ )) | ( w, w ′ ) ∈ R } , andso, 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 Γ is3ecursively enumerable if there is a recursively enumerable string relation R ′ such that R is the composition of enc Γ , gr( R ′ ), and enc − . Hence, to obtain ourtheorem for graph relations it now suffices to prove the following two lemmas. Lemma 1.
The class of MSO-computable graph relations is closed under inverseand composition.
Lemma 2.
For every Γ, the graph encoding relation enc Γ is MSO-computable. Proof of Lemma 1.
Closure under inverse is obvious: just reverse the di-rection of all ν -edges. To prove closure under composition, let R and R begraph relations computed by MSO formulas ϕ and ϕ . We may assume that ϕ and ϕ use the same auxiliary alphabet ∆. Moreover, we may assume thatevery computation graph h defined by ϕ or ϕ is connected: if not, then adda 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 ϕ uses thelabel ν instead of ν , and ϕ uses ν instead of ν , with ν = ν . The MSOformula ϕ that computes the composition of R and R , uses the auxiliary al-phabet ∆ ∪ { ν , ν , d } and defines computation graphs h that are obtained asthe disjoint union of a computation graph h of ϕ and a computation graph h of ϕ , enriched by d -edges that establish an isomorphism between out( h ) andin( h ), and by ν -edges from in( h ) to out( h ). It should be clear that this canbe realized by ϕ ; for instance, it expresses that the connected components of h minus its enriching edges satisfy ϕ or ϕ , depending on whether they containa ν -edge or a ν -edge. Proof of Lemma 2.
We first specify the relation enc Γ . Let g ∈ G Γ . We mayassume that V g is the set of strings { a, a , . . . , a n } over the alphabet { a } , forsome n ≥
1, where a / ∈ Γ. Let E g = { ( u , γ , v ) , . . . , ( u m , γ m , v m ) } for some m ≥
0. We encode g as the string w = a a · · · a n $ u γ v $ · · · $ u m γ 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 onlinear orderings of V g and E g , a graph g has in general more than one encoding.On the other hand, the relation enc − 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¨uc60, 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-definableset of graphs. For a string w as displayed above we define gr + ( w ) to be thegraph gr( w ) to which α -edges and δ -edges are added as follows. The α -edgesallow an MSO formula to express the fact that the first half of w is of the form a a · · · a n $. For each substring a i a i of w (1 ≤ i ≤ n −
1) thereare α -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 form4n 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, usingthe outgoing α -edges of gr( a i a i a i +1 a i +1 $. The δ -edges in gr + ( w ) witness the fact that foreach substring $ u j γ j v j $ of w (1 ≤ j ≤ m ) both u j and v j are in { a, a , . . . , a n } ,i.e., u j and v j are “declared” in the first half of w . Thus, there are δ -edges fromthe nodes of gr( u j ) to the nodes of some gr( a i a i $) in the first halfof gr( w ) that establish an isomorphism between gr( u j ) and gr( a i ), and similarlyfor 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 tothe same node (and similarly for v j = v k ). We now define enc +Γ to consist ofall pairs ( g, gr + ( w )) where w encodes g . It follows that the set enc +Γ ( G Γ ) isMSO-definable. Finally, we show that enc Γ is MSO-computable by describing the computa-tion 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 arenot 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 requirethat there are d -edges from out( h ) to mid( h ) that establish an isomorphismbetween 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 thatin( h ) is isomorphic to g . To realize this, we require that in( h ) ∈ G Γ and thatthere 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 V in( h ) and V g = { a, a , . . . , a n } ). Since we wish this bijec-tion 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 thereexist 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 consecutiveedge 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) meanthat w has a substring $ a i γa j $, i.e., that ( a i , γ, a j ) is an edge of g . It should beclear that all these requirements can be expressed in MSO logic, and that thegraph relation computed by H is enc Γ .Lemma 2 is trivial from the point of view of Turing computability: if w We recall that the set of graphs gr( w ), where w is an arbitrary string over Ω, is MSO-definable, see for instance [CE12, Corollary 5.12] or [EV20, Example 2.1]. g , then both g and gr( w ) can be represented by w on the tape ofa Turing machine. This is however based on the intuition that our encodingof graphs as strings is computable. Since the notion of MSO-computabilitydiscussed here uses graphs as datatype rather than strings, we were able togive a formal proof of that intuition. The reader may object that that proofis based on the intuition that the encoding of a string w as the graph gr( w ) iscomputable. One might then argue that the latter encoding is simpler than theformer.Traditionally, it has been shown that MSO logic is related to regularity,e.g., to regular string languages [B¨uc60, Elg61, Tra62] and regular tree lan-guages [Don70, TW68]. If one identifies regularity with computability by afinite-state machine, then this approach fails for MSO logic on graphs, because“no notion of finite graph automaton has been defined that would generalizeconveniently finite automata on words and terms” ([CE12, Section 1.7]). Forthis reason, the MSO transducers of [CE12, Chapter 7] were proposed to playthe role of finite-state transducers of graphs, and in the case of strings theyindeed turned out to be equivalent to two-way finite-state transducers [EH01].We have shown above how, dropping the finite-state condition, MSO logic isrelated to computability by any machine.If, on the other hand, one identifies regularity with rationality, i.e., with asmallest class containing all finite sets of objects and closed under a numberof natural operations on sets of objects (union, concatenation, and Kleene starin the case of string languages), then the class of all MSO-definable sets ofgraphs has a rational characterization [Eng91]. Since the recursively enumerablestring relations also have a rational characterization (as discussed in [Eng07]),the question remains whether there is a natural rational characterization of theMSO-computable graph relations. Such a characterization would at least involvethe operations of union, composition, and transitive closure of graph relations.The above quote from [CE12, Section 1.7] refers to the non-existence of afinite-state graph automaton that accepts exactly the MSO-definable sets ofgraphs. In [Tho91] a finite-state graph acceptor is introduced of which thecomputations are “tilings” of the input graphs (which have to be graphs ofbounded degree). All “tiling-recognizable” sets of graphs accepted by thesemachines are MSO-definable, and the reverse is true for strings and trees. If wewould allow the nodes of our graphs to have labels, then we could model theinput graph in( h ) and the output graph out( h ) of a computation graph h by twospecial 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 everyrecursively enumerable graph relation tiling-computable? Note that, as shownin [Tho91, Example 3.2(b)], the set of grids is tiling-recognizable.Descriptive complexity theory investigates logics that characterize complex-ity classes. By Fagin’s theorem (see, e.g., [Fag93, Theorem 5.1]), the complexity6lass NP equals the set of problems that can be specified by existential second-order formulas. In terms of graphs, such a formula requires the existence of anextension of the input graph by additional labeled hyperedges (where a hyper-edge is a sequence of nodes), such that the resulting (hyper)graph satisfies afirst-order formula. In our notion of MSO-computability we require that the in-put graph is an induced subgraph of a graph that satifies a monadic second-orderformula, and we obtain all recursively enumerable problems.We finally note that the notion of MSO-computability can easily be gener-alized to deal with arbitrary relational structures (cf. [CE12, Section 5.1]). That’s all folks!
This was my last paper. Thank you, dear reader, andfarewell.
References [BDGP17] M. Boja´nczyk, L. Daviaud, B. Guillon, and V. Penelle. Which classesof origin graphs are generated by transducers? In I. Chatzigian-nakis, P. Indyk, F. Kuhn, and A. Muscholl, editors,
Proc. 44th In-ternational Colloquium on Automata, Languages, and Programming(ICALP 2017) , volume 80 of
Leibniz International Proceedings in In-formatics (LIPIcs) , pages 114:1–114:13. Schloss Dagstuhl–Leibniz-Zentrum f¨ur Informatik, 2017.[B¨uc60] J.R. B¨uchi. Weak second-order arithmetic and finite automata.
Zeitschrift f¨ur mathematische Logik und Grundlagen der Mathematik
Graph Structure and MonadicSecond-Order Logic - A Language-Theoretic Approach , volume 138of
Encyclopedia of mathematics and its applications . Cambridge Uni-versity Press, 2012.[Don70] J. Doner. Tree acceptors and some of their applications.
Journal ofComputer and System Sciences
ACM Transactions onComputational Logic
Transactions of the American Mathematical Society
Theoretical Computer Science
Informa-tion Processing Letters
101 (2007), 139–140.[EV20] J. Engelfriet and H. Vogler. A B¨uchi-Elgot-Trakhtenbrot theoremfor automata with MSO graph storage.
Discrete Mathematics andTheoretical Computer Science
TheoreticalComputer Science
116 (1993), 3-31.[Tho91] W. Thomas. On logics, tilings, and automata. In J. Leach Al-bert, B. Monien, and M. Rodr´ıguez Artalejo, editors,
Proc. 18stInternational Colloquium on Automata, Languages, and Program-ming (ICALP 1991) , volume 510 of
LNCS , pages 441–454. Springer,Berlin, Heidelberg, 1991.[Tra62] B.A. Trakhtenbrot. Finite automata and the logic of one-place predi-cates.
Siberian Mathematical Journal
American Mathematical Society Translations ,Series 2, 59 (1966), 23–55.[TW68] J.W. Thatcher and J.B. Wright. Generalized finite automata the-ory with an application to a decision problem of second-order logic.