The monadic second-order logic of graphs VII: Graphs as ... - CiteSeerX

2 downloads 4097 Views 2MB Size Report
Theoretical Computer Science 101 (1992) 3-33. Elsevier. 3. The monadic second-order logic of graphs VII: Graphs as relational structures *. Bruno Courcelle.
Theoretical Elsevier

Computer

Science

3

101 (1992) 3-33

The monadic second-order logic of graphs VII: Graphs as relational structures * Bruno Courcelle UniversitP Bordeau.y-1, Lahoratoirr d’hformoriyue Cedes. France

** , 3.51. Cow-s de la LihPration. 33405 Talence

Abstract Courcelle, B., The monadic second-order logic of graphs Theoretical Computer Science 101 (1992) 3-33.

VII: Graphs

as relational

structures,

Relational structures form a unique framework in which various types of graphs and hypergraphs can be formalized and studied. We define operations on structures that are compatible with monadic second-order logic, and that are powerful enough to represent context-free graph and hypergraph grammars of various types, namely, the so-called hyperedge replacement, C-edNCE, and separated handle rewriting grammars. Several results concerning monadic second-order properties of the generated sets are obtained in a uniform way. We also give a logical characterization of the equational sets of structures that generalizes the ones obtained by Engelfriet and Courcelle for hyperedge replacement and C-edNCE sets of graphs.

0. Introduction

There are many notions of graphs. A graph can be directed or not, colored (i.e., labeled) or not, with or without multiple edges. It may have distinguished vertices, called sources (or terminals). Hypergraphs are not essentially different from graphs, and graph grammars deal heavily with them. This variety of definitions is actually motivated by a variety of uses of the concept. Accordingly, many notions of graph grammars have been introduced. The field of graph grammars definitely needs some unification. This paper aims to contribute to it. Rather than choosing one type of *This work has been supported by ESPRIT-Basic Research Action 3299 (“Computing by Graph Transformation”), and by the “Programme de Recherches Coordonnees: Mathematiques et Informatique”. A preliminary version has been presented at the 4th International Workshop on Graph Grammars, Bremen, 1990. and has appeared in the proceedings, Lecture Notes in Computer Science Vol. 532, Springer, 1991. ** Laboratoire associe au CNRS. Email: courcell@ geocub.greco-prog.fr. 0304-3975/92/$05.00

cc; 1992-Elsevier

Science Publishers

B.V. All rights reserved

graph, and declaring dogmatically that this type is the “right” one, in terms of which everything should be defined, we prefer to consider that all definitions are useful and deserve consideration, preferably in a unified framework. In the present paper, we consider two unifying tools,

namely,

graph

operations

(forming

the basis of a theory of graph grammars based on Universal Algebra) and relationml structures (forming the basis of the definition of sets of graphs by means of

logical formulas.) By a graph operdon, we mean a mapping that constructs a graph from a fixed number, say li, of given graphs Gr, . . . . Gk, for example by gluing them together in some fixed way. (Series composition and parallel composition of graphs with distinguished entry and exit vertices are typical examples of graph operations.) These operations are necessarily cletermirzistic: adding a new edge “anywhere” in a graph is not a graph operation. They make possible the description of graphs by “graph expressions” of various types. Let us assume that we fix a class of graphs and a set PYp, 11 of graph operations. Every system of recursive set equations written with I!.Yp.I. and set union has a least solution for inclusion. Several types of context-free graph grammars, in particular hyperedge-replacement (HR) and C-edNCE ones, can be expressed as systems of equations over appropriate subsets of PY< 1’. and many of their properties can be described at the abstract level of systems of equations. All the existing notions of graphs we know can be formalized in the uniform framework of relariontll structures. Ehrig et al. [12] have already used relational structures in order to formalize graph rewritings for several types of graphs in a unified way. Here we are interested in the logical expression of graph properties. It is interesting to note that the same mathematical notion is appropriate. Logical formulas, to be evaluated in a relational structure 1G 1describing a graph G, define certain properties of this graph. Hierarchies of graph properties follow from hierarchies of logical languages. Examples of languages are first-order, first-order with transitive closure, monadic second-order, second-order, listed by order of increasing expressive power. Some of these languages have been introduced as a means to characterize complexity classes (see in particular the surveys by Immerman [19] and Kannellakis

cw I In this series of papers [6, 7, 81, we investigate monadic second-order logic as a language for expressing graph properties or, equivalently, for defining sets of finite (and sometimes infinite) graphs. This language is interesting because it is both expressive and manageable, as witnessed by the numerous existing decidability results. (See [16] for a survey.) It is closely connected to finite-state automata in the cases of finite and infinite words and trees. This connection entails decidability results, established in particular by Doner [ 1 l] and Rabin [22]. This connection has no direct counterpart in the case of graphs, because no general notion of finite-state graph automaton is known. However, the sets of graphs satisfying a monadic secondorder formula behave with respect to context-free graph grammars like regular languages with respect to context-free (string) grammars. Since a number of basic

graph properties like connectivity, planarity, k-colorability for fixed k can be expressed in monadic second-order logic, this language is an essential tool in the theory of graph grammars. The use of logic to express properties structure for representing these graphs. represent a graph G by a structure or by a structure I/G jl the domain quantified

variables

denote

of graphs depends on the choice of a logical There are at least two possibilities: one can

1G 1,the domain of which is the set of vertices of G, of which is the set of vertices and edges of G. The

vertices or sets of vertices in the first case. In the second

case, they can also denote edges and sets of edges. This gives two variants of monadic second-order logic as a language for expressing graph properties, respectively denoted by MS1 and MS2. Their expressive powers are compared in [8]. Let us recall two strikingly Result a C-edNCE Result hyperedge

similar 1 [lo,

results: 4]-One

can

(or a B-NLC; 2 [S, 6]-One replacement

decide

see [24]) can decide

grammar

whether graph

grammar

whether

satisfy

all graphs

of a set

satisfy

all graphs

L generated

by

a given MS,-formula.

of a set L generated

by a

a given MS&ormula.

We shall prove that these two results are two instances of a single general one, concerning sets of finite relational structures defined by systems of equations (i.e., by context-free grammars put in an algebraic setting). This general result involves some operations on structures that we now introduce. We define one binary operation on structures, that glues two structures S and S’ into a single one S//S’. (This operation generalizes the parallel composition of graphs). We also consider operations of the form S’=f(S), where S’ is defined in terms of S as follows: its domain is a subset of that of S; its relations are defined by quantifier-free logical formulas in terms of those of S. (We are using here the classical notion of semantic interpretation, used in particular in [21, 231.) Our first main result, the compatibility theorem (Theorem 3.4) states that monadic second-order logic is compatible with these operations. (This terminology is borrowed from 1171). It means that if G=f(G,, . . . . Gk) for some operationf, then the validity of a monadic second-order formula in G can be decided from those of finitely many auxiliary formulas in the composing graphs G1, . . . , Gk. This result would not hold without the restriction to quantifier-free formulas in the definition of the graph operations .f: With these operations, we can form systems of equations (like those canonically associated with context-free grammars) having least solutions. We obtain thus the notion of an equational set of structures, that we consider as an appropriate notion of context:freeness. A general result subsuming Results 1 and 2 follows immediately from the compatibility theorem. We also investigate graph transformations, aiming to build a theory akin to that of transformations of words and trees that is essential in formal languages theory. These transformations are usually called transductions, and are defined byjinite-state transducers, that do some computations while traversing an input word or tree, and produce as an output the result of these computations. A central issue is whether the

transductions of a certain type preserve classes of sets of words or trees, like the class of context-free sets or that of recognizable ones. Graph

transformations

are of common

use. Given a graph, one may wish to obtain

its spanning forests, or its connected components, or its maximal planar subgraphs by graph transformations, specified in some uniform way that fits well with graph grammars. We suggest

to consider

transformations

of graphs

specified

by monadic

second-

order formulas. We call them dclfinahle rrunsductions. (Graphs are, of course, represented by logical structures as explained above.) Our definition is an appropriate extension to monadic second-order logic of the technique of semantic interpretation that is commonly used as a tool for comparing various theories and proving certain decidability or undecidability results. (We refer the reader to [21-23, 161.) As a tool for transforming graphs, it has been introduced in [7, 81. Less powerful transformations have been introduced independently by Engelfriet [ 131 for purposes similar to ours, and by Arnborg et al. [l], for deciding graph properties with polynomial algorithms. Our second main result, the logical charucterization qf‘equational sets of structures (Theorem 4.6) states that the equational sets of structures are the images of the recognizable sets of finite trees under definable transductions. This result is a generalization of the result of [ 131 stating that a set of graphs L is C-edNCE iff 1L 1(namely, the set of structures 1G 1for all graphs G in L) is the image of a recognizable set of finite trees under a definable transduction. It generalizes also the result of [9] stating that a set L of hypergraphs is HR (i.e., it is generated by a hyperedge replacement grammar) iff I/L11(the set of structures 11G 11for all G in L) is the image of a recognizable set of finite trees under a definable transduction. This result also shows that the operations on structures, that may seem to be rather weak because of the restriction to quantifier-free formulas, are powerful enough to generate all sets of structures that are characterized in terms of transductions as are the C-edNCE of graphs and the HR sets of hypergraphs. Another consequence is that the class of equational sets of structures is closed under definable transductions, which confirms the robustness of our definitions. Some methodological consequences for the study of classes of graphs and graph grammars are developed in the conclusion.

1. Relational

structures

The logical structures we use in this paper are not strictly relational, since they also have distinguished elements denoted by constants (i.e., nullary function symbols). We call them, nevertheless, relutionul in order to emphasize that they have no functions of positive arity. 1.1. Definitions

(Relational

structures).

We let 55 be a countable

set of symbols

called

Graphs as relational

I

structures

constants. We let 3 be a set of relation symbols. Each symbol Yin .@ has an arity p(r) in N, and 9 has countably many symbols of each arity. We let R and C be finite subsets of 3 and %. An (R, C)-structure is an object of the (c~)~~~), where Ds is a set, called the domain of S, each form S=(DS,(rS)reR, cs belongs to D,, and each rs is a subset of D,P”’, i.e., is a p(r)-ary relation on D,. One may have cs = c$ with c # c’. We denote by Y(R, C) the set of (R, C)-structures having a finite domain. By a (relational) structure we shall mean in this paper an element of Y(R, C) for some finite sets R and C as above. We shall consider graphs

two isomorphic

and hypergraphs

defined

structures

below, without

as equal. The same will be done for any further

notice.

1.2. Example (Sourced hypergraphs). We recall [S, 61 how the sourced hypergraphs defined in [2, 51 can be represented by relational structures. Let A be a set of ranked hyperedge labels. The rank of a in A is a nonnegative integer t(a). An n-hypergraph over A is an object of the form G= (VG,EG, labG,vertC,srcG), where V, is the (finite) set of its vertices, E, is the (finite) set of its hyperedges (with EG n V, = 8), lab, : EG+ A is a mapping that defines IS a mapping that defines the sequence of the label of a hyperedge, vert,:EG-‘Vz vertices of a hyperedge, and we assume that the length of vertc(e) is 5( lab,(e)) for all eEEG. Finally, srcG is a sequence of n vertices of G. We denote by src,(i) the ith element of this sequence. The vertices of srcG are called the sources of G. The set of n-hypergraphs over A is denoted by HG(A),. With A and n as above, we associate the set of relation symbols R,:= and the set of constants {edg,laEAj, G = (VG, EG, lab,, vet-t,, src,), we associate

C,:= {sl, . . . . s,}. With a hypergraph the structure 11G 11in Y(R,, C,) such that

D ~IG~I :=V,uE,, edg,, G,l(x,yl, . . . . y,,):-=frue iff XEEG, y, . . . . . y,~v,, Si,iGi,:=srCG(i)

labc(x)=a

and vert&)=(yl

,..., y,),

for each i= 1, . . . . n.

(Hence, the arity of edg, is s(a)+ 1.) It is clear that two structures /(G 11and 11G’I/ are equal (i.e., isomorphic) iff the hypergraphs G and G’ are equal (i.e., isomorphic). In other words, we have a oneto-one mapping I(. /I : HG(A),+.!Y(RA,C,). We now describe a simpler, but less representative, relational structure associated with G. Here we assume that r(a) #O for all a in A, and we let R> := {edgb I aEA} with edgh of arity r(a) for each a. With G in HG(A),, we associate the structure ICI in Y(R>,C,):

where edg;,cl(.u,,

. . .._y,):o

of vertices

true iff (.Y,, . . . . x,,) is the sequence

of some hyperedge

and the other components

of G labeled

by a,

are as in 11G 11.

If G and G’ are simple, i.e., if they have no pair of hyperedges with the same sequence of vertices and the same label, then 1G/ = IG’l iff G= G’. On the other hand, since multiple hyperedges with the same label are not distinguished 1GI = IG’I without having G = G’.

in ICI, we may have

We refer the reader to [S] for some results comparing the expressive power of monadic second-order logic in the two cases where a simple graph G is represented by the two structures IGI and 11G /I.

2. Operations

on relational structures

We now define a few basic operations on relational structures. Our aim is to formalize graphs and hypergraphs as relational structures, and operations on them as derived operations expressed in terms of these basic operations. 2.1. Definition (The gluing operation). Let SE.V(R,C) and S’E.Y(R’,C’). We may assume that they are disjoint i.e., that Ds n D,, = 8. (If this is not the case, one replaces S’ by an isomorphic copy, disjoint with S.) We let S//S’ be the structure T defined as follows. We let D := D,u D,.; we let - be the least equivalence relation on D such that cs - cs. for every CE C n C’. We let DT := D/ - and we denote by [d] the equivalence class of an element (1 in D. We complete the definition of T as follows: cT := [cs]

if ~EC;

cT := [cs,]

if ~EC’ (we have [cs] = [cs,] if cECn . , [cl,,]) holds if rs(ll;. . . . , cl,:) holds or if

rT([dl],

r,.(d;,

. . . . db) holds for some d; E[LE,], . . . . dl~[d,,].

(It is clear that //’ is actually that S//S’EY’(RUR’,CUC’). disjoint union of S and S’. 2.2. Definition

C’);

(Quantijier+ee

well defined on isomorphism classes of structures.) Note If CnC’=@ then Ds ,s~=DsuDsz and S//S’ is the

dejinahle

operations).

We denote by QF(R, C, X) the set of quantifier-free (first-order) formulas written with R, C, and the variables of X, where X is a set of object variables (denoted by lowercase symbols). Our purpose is to formulas. We let A be specify total mappings: ,Y(R, C) + Y’(R’, C’) by quantifier-free a tuple of the form (~,(O,),..,,(~,),.c,) such that

9

~ $EQF(R,

C, {x1 )) and is of the form

for some formula II/’ in QF(R. C, {x1 )); (the formula all formulas x 1= K, for all c in C’); ~ B,.EQF(R, C, {x 1,..., x,)), where n=~(r), _ K,EC for each c~C’.

Vcsc, x1 = K, is the disjunction

of

The set of such tuples will be denoted by A((R, C),(R’, C’)). With every /i in A((R, C), (R’, C’)), we associate the total mapping defA : .Y(R, C) + Y(R’, C’) such that, for every S in Y’(R, C), def,,(S) is the structure

S’ in .Y’(R’, C’) defined as follows:

csc :=(h~,)~ for each (‘EC’, r,,(d,,

. . . . II,) holds

iff dr, . . . . C&ED,

and SI=~(d,)~...r\~(d,)~B,(d,,...,d,) (i.e., dI, . . . . &ED,.

and SI=8,(dI,

. . ..d.)).

(The notation S+$(d,)r\ ... A $(d,)r\B,(d,, . . ..d.) means that in the structure S, the formula 0, holds with d,, , d, as values of x1, . , x,, respectively, and the formula $ holds for d,, . , d, as values of x1 .) The domain of S’ is the set of elements of D, that satisfy $. This formula has been taken to be of such a form that the elements (K,)~, c~C’, that are needed as values of c in S’, are indeed in the domain of S’. Each formula 8, specifies rs, in terms of the constants and relations of S. A mapping: Y(R, C) -+ ,Y-‘(R’, C’) is quant$er$‘ree definable (&id) iff it is of the form def., for some /1 in A((R, C), (R’, C’)). We say that two formulas cp and cp’ are propositionally equivalent if they can be transformed into each other by the laws of propositional calculus. In such a case they are equivalent in every structure. Since we use no function symbols, there are only finitely many classes of quantifier-free formulas with respect to propositional equivalence. We shall assume that each formula is automatically replaced by some canonical representative of its class of propositional equivalence. It follows from this convention that each set QF(R, C, X) is finite if X is finite, and that A((R, C), (R’, C’)) is finite for each pair ((R, C), (R’, C’)). 2.3. Definition (A signature of operations on relational consisting of a finite subset R of .4? and of a finite subset let Y’P&‘Y be the (countable) set of all sorts. For every be an operation symbol of profile s x s’ + s”, where s” = s’ = (R’, C’). The associated operation is the restriction

structures).

Every pair (R, C) C of %?will be called a sort. We s and s’ in YO&?.Y-, we let //s,sI (R u R’, C u C’), s = (R, C), and of // to 9’(R, C) x Y(R’, C’).

For every s = (R, C) and s’ = (R’. C’) in .Y I’ ./AX, for every ,J in ,4 (s, s’), we introduce an operation symbol def,,,,,,’ of profile s + s’. The associated mapping is def,, : ,Y’(R, C) + .V(R’, C’). We let CcIip 1‘= jS/.:..,srdef.~.,.,~ 1s,.s’E,Y’~~.?A~~, AEA(s,s’) j. We obtain a many-sorted Q.4. I ‘-magma (i.e., P./p. I ‘-algebra): Y’=((:~(s)),,~,, In most concrete

~r,(iX.,~,) ,,.,,t.‘,P #.F.(def

cases, we shall consider

I.\,\ ) \,\ E’/C

restrictions

d.F..lt.l(\

, \’ ) >.

of .Y’to the domains

which belongs to some finite subset of .Y’C(.&‘.F and, operations, since the sets /1 (s. s’) are all finite.

whence,

in this way

the sort of

to finitely

many

We let Cf./P. 1‘+ denote the signature Q./p. 1 augmented with tzu//ury,function symbols denoting fixed structures. Any variable-free term r written with the symbols of P d. 1 ‘+ and well-formed w.r.t. arities, sorts and prohlcs denotes a structure val(t) in .V’(R, C), where (R, C) is the sort of t. An C’.Y. I ‘+-deriLvrl operrttion is a mapping: .‘~(R,,C,)x...x.Y(R,,C,) + .V(R’. C’) defined by a finite term written with the symbols of CV. I ‘+ and variables s ,. . . .._Y,, of respective sorts (R,, C,), . . . . (R,,, C,,): we shall also make the hxzrit~ us.sutnptiou that there is one and only one occurrence of each variable in these terms. We now give a few useful examples. 2.4. Definition (RetmJzitIy of’ umstunt.s). We define a fairly trivial but technically useful qfd operation: Y(R, C) + Y’(R, C’). Let [I: C’ + C be a total mapping. Let ren,) be the operation .‘/(R. C) + ,if(R, C’) that maps S = (D,, (I.~),.~~,(cS)ctC) to (Ds.(t-S)rsK,( /j’(~‘)~)~,.~,). It is the qfd operation associated with the tuple ); it makes the element of D, that is the value A=(true,(r(.~,, . . ..r.~(.,)),,,.(P(~‘))~,EC, in S of the constant /3(c’) into the value of c’, for each c’ in C’. 2.5. Example (0prrution.s on .sourd hyprtyraphs). We show that the operations on sourced hypergraphs introduced in [2, 5,6] can be described as derived operations on structures via the representation of a hypergraph G by the structure /I G/I. (If n is a nonnegative integer, we denote by [n] the set ( I. , tq); hence, [0] is the empty set.) The source dqfinition ucr: HG(A), + HG(A ),, is associated with every mapping g: [p] + [tl] and transforms G into G’ such that the ith source of G’ is the r(i)th source of G for all i~[p]. It is thus clear that IIo,(G) II = rqJ( IIG IIL where /~(s~)=s,,~, for all s,EC,. The second operation is source jilsion. Let i,,j~[n]. The operation ~~i,j: HG(A),, + HG(A), fuses the ith and the jth source of a hypergraph. It can be in