Emptiness problems of eNCE graph languages K. Skodinis
y
E. Wanke
z
Abstract
We consider the complexity of the emptiness problem for various classes of graph languages de ned by eNCE (edge label neighborhood controlled embedding) graph grammars. In particular, we show that the emptiness problem is undecidable for general eNCE graph grammars, DEXPTIME-complete for con uent and boundary eNCE graph grammars, PSPACE-complete for linear eNCE graph grammars, NLcomplete for deterministic con uent, deterministic boundary, and deterministic linear eNCE graph grammars. The exponential time algorithm for deciding emptiness of con uent eNCE graph grammars is based on an exponential time transformation of a con uent eNCE graph grammar into a nonblocking con uent eNCE graph grammar generating the same language.
1 Introduction The theory of graph grammars constitutes a well-motivated and well-developed area within theoretical computer science. The area of graph grammars has grown quite impressively in recent years. This growth was motivated by applications in pattern recognition, software speci cation and development, VLSI design, data bases, analysis of concurrent systems, and many other areas. See [CER79, EKR91, ENRR87, ENR83, Nag79] for an overview of dierent application areas and dierent types of graph grammars. In this paper, we analyze so-called edge label neighborhood controlled embedding (eNCE) graph grammars; see [Bra87, ELW90, Kau85, Kau87]. In such graph grammars all nodes and additionally all edges of the graphs are associated with labels, in contrast with ordinary NCE graph grammars [JR82] which do not use edge labels. There are terminal and nonterminal node labels as well as terminal and nonterminal edge labels. Thus, the graphs involved have terminal and nonterminal nodes and edges. In general, graph grammars are speci ed by a set of productions. A production is usually a tuple (H1; H2) of two special graphs. Such a production is applied to an occurrence H^1 of H1 in some graph G by replacing H^1 with a copy of H2 taking into account the embedding mechanism of the graph grammar. In eNCE graph grammars, all H1 are nonterminal singlenode graphs without edges and all H2 are labeled graphs associated with some embedding information C . The embedding mechanism of eNCE graph grammars allows the substitution to establish terminal as well as nonterminal edges between nodes of H2 and former neighbors of H^1. The embedding mechanism works as follows: An edge labeled by l2 is established
3/2
The work of the rst author was supported by the German Research Association (DFG) grant Br-835-
Department of Computer Science, University of Passau, D-94032 Passau, Germany, email:
[email protected] z Institute for Algorithms and Scienti c Computing, German National Research Center for Computer Science, D-53757 Sankt Augustin, Germany, email:
[email protected] y
1
between a node w from H2 and a former neighbor v of H^1 , which is labeled by a and was connected to H^1 by an edge labeled by l1 , if and only if the tuple (a; l1; l2; w) is a member of C . Here the nodes in H2 can be treated separately, whereas all nodes in the former neighborhood of H^1 with the same label are treated identically. The language of a graph grammar is the set of all terminal labeled graphs derivable from some axiom. We are interested in the question whether or not a given eNCE graph grammar generates at least one terminal graph. For many types of graph grammars studied in literature, the emptiness problem can be solved in linear time. This holds because in many graph grammars the left hand sides of all productions are atomic (single-node or single-edge graphs) and the embedding mechanism does not produce nonterminal objects. Such graph grammars are for example HR (hyper-edge replacement) systems [Hab92], NLC (node label controlled) graph grammars [JR80a, JR80b], or NCE (neighborhood controlled embedding) graph grammars [JR82]. For these types of graph grammars the emptiness problem is equivalent to the emptiness problem of context-free string grammars and thus P-complete. The property that makes eNCE graph grammars dicult to analyze is the existence of so-called blocking edges. These are nonterminal edges incident to two terminal nodes. Since only nonterminal nodes and their adjacent edges disappear during a substitution step, graphs containing a blocking edge and all graphs derivable from them have at least one nonterminal edge, and thus are not in the language of the grammar. We say, an eNCE graph grammar is nonblocking if it can not generate graphs having a blocking edge. The feature of blocking edges can, for example, be used to generate graph languages consisting of all complete graphs with 2n nodes for all n 1. On the other side, the emptiness problem for nonblocking eNCE graph grammars is P-complete as for context-free string grammars. A simple condition that ensures the nonblocking property for eNCE graph grammars is, for example, the condition that for each tuple (a; l1; l2; w) where a is a terminal node symbol and w a terminal node, the edge label l2 has to be terminal; see [ELR88, ELW90, Kau85]. However, if all tuples which violate the condition are simply removed then the grammar need not generate the same set of graphs. In this paper, we consider various classes of restricted eNCE graph grammars. The rst restriction is the con uence condition. In con uent eNCE graph grammars, the order in which the productions are applied is irrelevant for the resulting graph. A restriction that implies con uence is the boundary condition. In boundary eNCE graph grammars, nonterminal nodes are never adjacent. Boundary eNCE graph grammars are always con uent and analyzed in [ELW90]. From an algorithmic point of view, con uent and boundary eNCE graph grammars are the most interesting subclasses of eNCE graph grammars; see, for example, [RW86, Wan91]. More powerful restricted eNCE graph grammars are linear eNCE graph grammars. In such grammars all graphs have at most one nonterminal node. Linear eNCE graph grammars are analyzed in [EL89]. Another restriction is determinism. In deterministic eNCE graph grammars at most one production can be applied to each nonterminal node. Even deterministic eNCE graph grammars can de ne an exponential number of dierent terminal graphs, because the order in which substitutions are performed can in uence the labeling of edges and thus even their existence. Deterministic eNCE graph grammars can be considered as hierarchical descriptions of graphs; see also [LW88, Wan91]. The analysis of deterministic graph grammars is of primary interest within the context of analyzing succinct speci cations of graphs.
2
complexity of emptiness restriction
general eNCE
deterministic eNCE
unrestricted con uent boundary linear
undecidable DEXPTIME-complete DEXPTIME-complete PSPACE-complete
? NL-complete NL-complete NL-complete
The main results in this paper are summarized in the table above. We show that the emptiness problem is undecidable for general eNCE graph grammars, DEXPTIME-complete for con uent and boundary eNCE graph grammars, PSPACE-complete for linear eNCE graph grammars, NL-complete for deterministic con uent, deterministic boundary, and deterministic linear eNCE graph grammars. An upper bound for deciding the emptiness problem for general deterministic eNCE graph grammars is still open. A lower bound is, clearly, the NL-hardness of the emptiness for deterministic con uent eNCE graph grammars. The exponential time algorithm for deciding emptiness of con uent eNCE graph grammars is based on a transformation of a con uent eNCE graph grammar into a nonblocking con uent eNCE graph grammar generating the same language. This transformation only takes exponential time.
2 Preliminaries We de ne eNCE graph grammars in a sequence of de nitions; however, we try to be as informal and intuitive as possible. De nition 2.1 (Graphs) Let and ? be two nite sets of symbols (node and edge symbols, respectively). A node/edge labeled graph over ; ? is a system G = (V; E; ), where 1. V is a nite set of nodes, 2. : V ! is a node labeling that associates with each node u a node label (u), 3. E ffu; vg j u; v 2 V; u 6= vg ? is a nite set of labeled edges, i.e., each edge e = (fu; vg; l) consists of two distinct nodes u; v and an edge label l. A node or an edge labeled by a 2 or l 2 ? is called an a-node or l-edge, respectively. We deal with undirected node and edge labeled graphs over ; ? which we simply call graphs. Next we de ne the composition of two graphs G and H by replacing a node u from G by H . This composition mechanism is used in derivation steps of eNCE graph grammars. De nition 2.2 (Substitutions) An embedding relation for a graph H over ; ? is a set D ? ? VH ; i.e., each tuple (a; l1 ; l2 ; w) from an embedding relation consists of a node label a, two edge labels l1 ; l2 , and a node w of H . Let G and H be two graphs over ; ?. Let D an embedding relation for H , and let u be a node from G. The graph G[u=D H ] is obtained by replacing node u by H with respect to D as follows: 3
1. Let J be the disjoint union of G; H without node u and its incident edges. 2. For each edge (fv; ug; l1) from G, add an edge (fv; wg; l2) to J if and only if ((v); l1; l2 ; w) 2 D. The resulting graph is G[u=D H ].
Intuitively speaking, the substitution of a node u in G by a graph H is controlled by the embedding relation as follows: Let N (u) = fv j (fu; vg; l) 2 EG for some lg be the node neighborhood of u in G. If (a; l1 ; l2 ; w) is a tuple in the embedding relation then node w from H will be connected to an a-node v from N (u) by an l2-edge if and only if the a-node v was previously connected to u by an l1-edge. Figure 2.1 shows an example of such a substitution. a
b
a l2
v b
l1
l1
l1 l2
b
l1
a
G
l2
b
u
l1
l2
l1
b
l2
l1
b
w H
b v
a
w
G[u/ H] C
Figure 2.1: Three graphs G, H , and G[u=D H ], where D = f(a; l1; l2 ; v); (b; l2; l1; w)g. We continue with the de nition of eNCE graph grammars.
De nition 2.3 (eNCE graph grammars) An eNCE (edge label neighborhood controlled embedding) graph grammar is a system G = (; ; ?; ; S; P ), where 1. , , ? , ?, ?, and ? ? are nite sets of node labels, terminal node
labels, nonterminal node labels, edge labels, terminal edge labels, and nonterminal edge labels, respectively, 2. S is a graph over ; ?, the axiom of G , and 3. P is a nite set of productions. Each production is a triple (A; G; C ) where (a) A is a nonterminal node label from ? , (b) G is a graph over ; ?, (c) C is an embedding relation for G. A is called the left hand side and (G; C ) is called the right hand side of the production.
The de nition of eNCE graph grammars divides the node and edge labels into terminal and nonterminal labels. A node (edge) labeled by a terminal or nonterminal label is called a terminal or nonterminal node (edge), respectively. A graph is called terminal if all its nodes and edges are terminal. The next de nition shows how eNCE graph grammars de ne sets of graphs by derivations.
4
De nition 2.4 (Derivations and languages) Let G be an eNCE graph grammar and G; H be two graphs over ; ?. We say that G directly derives H in G , denoted by G =)G H if and only if G has some A-node u, G has a production (A; J; F ), and H = G[u=F J ]. We say that G derives H in G , if H; G =) G is the transitive and re exive closure of =) . where =) G G The language L(G ) of an eNCE graph grammar G is the set of all terminal graphs derivable from the axiom of G . We intend to analyze the complexity of problems using eNCE graph grammars as input. Thus, we have to de ne the size of an eNCE graph grammar. For our complexity analysis, the size of a grammar is just the size of the string that you get when writing down the grammar in the usual way. This implies that the size of a single node, edge, or label is logarithmic in the number of all nodes, all edges, and all labels, respectively.
3 General eNCE graph grammars The proof of the main theorem in this section is a transformation from the halting problem of Turing machines to the emptiness problem of eNCE graph grammars. Similar constructions have been used to show the undecidability of related problems for NLC graph grammars, see [JR80b, JR81]. A Turing machine is a system M = (Q; f0; 1g; ; qS ; qF ), where Q is the nite set of states, : Q f0; 1g ! Q f0; 1g fleft ; right g is the next move mapping, qS 2 Q is the start state, and qF 2 Q is the nal state. In general, there are more than two tape symbols and more than one nal state; however, the restriction to two tape symbols 0; 1 and one nal state qF has no in uence on the undecidability of the halting problem of Turing machines. A composite symbol is a pair (x; q), where x is a tape symbol from f0; 1g and q is either a state or the symbol \#". The set of all composite symbols is denoted by CS. An instantaneous description (ID) for M of length m is a sequence of m composite symbols. Each ID has exactly one composite symbol with a state on its right hand side. The position of this composite symbol indicates the head position of M . An ID is called initial or nal if it contains the state qS or qF , respectively. An ID 0 = (X10 ; : : : ; Xm0 0 ) is a successor ID of an ID = (X1; : : : ; Xm) if and only if either m0 = m and ; 0 dier in at most two positions j; j + 1 such that 1. (Xj ; Xj+1) = ((x; q); (y; #)), (Xj0 ; Xj0 +1) = ((z; #); (y; r)), and (q; x) = (r; z; right ), or 2. (Xj ; Xj+1) = ((y; #); (x; q)), (Xj0 ; Xj0 +1) = ((y; r); (z; #)), and (q; x) = (r; z; left ), or m0 = m + 1, Xi = Xi0 for i = 1; : : : ; m, and Xm0 +1 = (0; #). 5
The rst case represents a move to the right, the second case represents a move to the left, and the third case represents an extension of the ID. A Turing machine M accepts an ID if either is a nal ID or some successor ID of is accepted by M . M accepts an input I = I1 I2 In 2 f0; 1g, n 1, if and only if it accepts the initial ID I = ((I1; qS ); (I2; #); : : : ; (In; #)): In other words, M accepts I if and only if there is a sequence 1 ; : : : ; n of IDs such that 1 is the initial ID I de ned by input I , n is some nal ID, and each i is a successor ID of i?1 for i = 2; : : : ; n. It is well known that there are Turing machines M such that the question whether M accepts a given input I is undecidable. This question is called the halting problem for Turing machines. The problem whether or not a given Turing machine accepts the empty input is also undecidable and called the empty-tape halting problem.
Theorem 3.1 The emptiness problem for eNCE graph grammars is undecidable. Proof Our intention is to design an eNCE graph grammar G for an arbitrary Turing machine M and a given input I such that L(G ) is not empty if and only if M accepts I . G has the node labels L; A0; A1 ; A2; R, where only L is terminal. G has the edge labels
l and lX , where X is a composite symbol. The labels l(0;#) ; l(1;#); l(0;qF ); l(1;qF ) are terminal edge labels. The remaining edge labels l; l(0;q) ; l(1;q) for all q 2 Q; q 6= qF are nonterminal edge labels. A graph G represents an ID = (X1 ; : : : ; Xm ) if G has m + 1 nodes u1; : : : ; um+1 and m edges (fu1; u2g; lX1 ); (fu2; u3g; lX2 ); : : : ; (fum; um+1g; lXm ): The nodes are labeled as follows: Node u1 is labeled by L, node um+1 is labeled by R, and for i = 1; : : : ; m 1. if node ui is labeled by L then node ui+1 is labeled by L; A0; A1; A2 , or R 2. if node ui is labeled by A1 then node ui+1 is labeled by A2 or R, 3. if node ui is labeled by A2 then node ui+1 is labeled by A0 or R, 4. if node ui is labeled by A0 then node ui+1 is labeled by A1 or R. Node um+1 is the only node labeled by R. Such graphs G are called ID-graphs. The Lnodes specify the left hand side whereby the single R-node speci es the right hand side of G. The inner nodes in G are labeled by A0 ; A1, or A2 . Each inner node has exactly two neighbors. An inner Ai-node has a left neighbor labeled1 by Ai?1 mod 3 or by L, and a right neighbor labeled by Ai+1 mod 3 or by R. Thus, the labeling uniquely speci es the left and right neighbor. The labels of the edges represent from left to right the ID . For some ID = (X1 ; : : : ; Xm ), let H( ) be the ID-graph representing in which the m + 1 nodes are labeled by L; A0 ; A1; A2 ; A0; A1; A2; A0 ; A1; A2; : : : ; A(m?1) mod 3; R: Figure 3.2 shows an example of some H( ), where Figure 3.3 shows another ID-graph which represents the same ID. 1
i
mod 3 denotes the integer from 0 1 2 which is congruent to modulo 3. ;
;
i
6
(1,#) L
(0,#) A0
(1,q)
(0,#) A1
A2
(0,#) A0
(1,#) A1
R
G
Figure 3.2: The ID-graph H( ) for
= ((1; #); (0; #); (0; #); (1; q); (0; #); (1; #)): (1,#) L
(0,#) L
(0,#) L
(0,#)
(1,q) A2
A0
(1,#) A1
R
Figure 3.3: An ID-graph representing the ID
= ((1; #); (0; #); (0; #); (1; q); (0; #); (1; #)): The axiom S of G is the ID-graph
H((I1; qS ); (I2; #); : : : ; (In; #)); where I = I1I2 In, n 1, is the given input for M . Since the empty-tape halting problem for Turing machines is also undecidable and since we have considered an arbitrary Turing machine, we can assume that I consists of one symbol 0. G has three types of productions designed as follows: The productions of the rst type derive some H( 0) from some H( ) if and only if both IDs ; 0 have the same number of symbols and 0 is a successor ID of . The productions of the second type derive some H( 0) from some H( ) if and only if 0 has one additional symbol (0; #) on the right hand side. The productions of the third type derive a terminal graph from some H( ) if and only if is a nal ID. In particular, G has the following productions:
Type 1 productions for a move to the right
For each j = 0; 1; 2 and each (q; x) = (r; z; right ) there is a production (Aj ; G; C ), where G is the graph consisting of a single Aj -node u and C = f(B; l(x;q); l(z;#); u) j B 2 fAj?1 mod 3; Lgg [ f(B; lX ; l; u) j X 2 CS; X 6= (x; q); B 2 fAj?1 mod 3 ; Lgg [ f(B; l(y;#); l(y;r); u) j y 2 f0; 1g; B 2 fAj+1 mod 3; Rgg [ f(B; lX ; l; u) j X 2 f0; 1g Q; B 2 fAj+1 mod 3 ; Rgg [ f(B; l; l; u) j B 2 fL; A0 ; A1; A2; Rgg: A nonterminal l-edge is generated by applying one of these productions to some Aj node w if and only if the edge to the left neighbor of w is not labeled by (x; q), or the edge to the right neighbor of w is not labeled by (y; #) for some y 2 f0; 1g, or w is already connected to one of its neighbors by an l-edge. If one of these productions is applied to an ID-graph without generating an l-edge, then the result is a new ID-graph representing the previous ID changed with respect to the move (q; x) = (r; z; right ).
Type 1 productions for a move to the left 7
These productions are analogously de ned to the type 1 production for a move to the right. Here only the direction of the move is reversed. For each j = 0; 1; 2 and each (q; x) = (r; z; left ) there is a production (Aj ; G; C ), where G is the graph consisting of a single Aj -node u and C = f(B; l(x;q); l(z;#); u) j B 2 fAj+1 mod 3; Rgg [ f(B; lX ; l; u) j X 2 CS; X 6= (x; q); B 2 fAj+1 mod 3 ; Rgg [ f(B; l(y;#); l(y;r); u) j y 2 f0; 1g; B 2 fAj?1 mod 3; Lgg [ f(B; lX ; l; u) j X 2 f0; 1g Q; B 2 fAj?1 mod 3 ; Lgg [ f(B; l; l; u) j B 2 fL; A0 ; A1; A2; Rgg:
Type 2 productions for extending an ID-graph
For each j = 0; 1; 2 there is a production (R; G; C ), where G is a graph consisting of two nodes u; v labeled by Aj ; R, respectively, and an edge (fu; vg; l(0;#)), and C = f(B; lX ; lX ; u) j X 2 CS; B 2 fL; A0; A1 ; A2; Rgg [ f(B; l; l; u) j B 2 fL; A0 ; A1; A2; Rgg: If one of these productions is applied without generating a nonterminal l-edge, then the ID represented by the resulting graph is the previous ID extended by the composite symbol (0; #). Type 3 productions for eliminating nonterminal Aj -nodes next to L-nodes For each j = 0; 1; 2 there is a production (Aj ; G; C ), where G consists of a single L-node u and C = f(B; lX ; lX ; u) j X 2 CS; B 2 fL; Aj+1 mod 3; Rgg [ f(B; lX ; l; u) j X 2 CS; B 62 fL; Aj+1 mod 3; Rgg [ f(B; l; l; u) j B 2 fL; A0 ; A1; A2; Rgg: An l-edge is generated by applying one of these productions to some Aj -node w if and only if the left neighbor of w is not labeled by L or w is already connected to one of its neighbor by an l-edge. These productions generate ID-graphs that have more than one L-node; however, all these L-nodes are arranged side by side on the left hand side of the ID-graph. Type 3 production for eliminating the nonterminal R-node to the right There is a production (R; G; C ), where G consists of a single L-node u and C = f(L; lX ; lX ; u) j X 2 CSg [ f(B; lX ; l; u) j X 2 CS; B 6= Lg [ f(B; l; l; u) j B 2 fL; A0 ; A1; A2; Rgg: This production generates a nonterminal l-edge if and only if the substituted R-node is either not connected to an L-node or already incident to a nonterminal l-node. A terminal graph can only be derived if this is the last applied production. If the represented ID is nal, the R-node changes into a terminal L-node without changing the terminal label of its incident edge. A thorough inspection of the productions shows that any application of a production to an ID-graph G will generate a nonterminal l-edge if and only if G is not transformed into an ID-graph representing a successor ID. Since nonterminal edges will never disappear in any further derivation step, and since only nal ID-graphs can derive into terminal graphs, the language of G is not empty if and only if M accepts I . 2 8
4 Con uent eNCE graph grammars
An eNCE graph grammar G is called con uent (C-eNCE) if for each graph G derivable from the axiom of G , all distinct nonterminal nodes u; v in G, and all productions ((u); H; D); ((v); J; F ) in G :
G[u=D H ][v=F J ] = G[v=F J ][u=D H ]: In con uent eNCE graph grammars, the order in which the productions are applied is irrelevant for the resulting graph. Since only nonterminal nodes can be substituted, a nonterminal edge incident to two terminal nodes can never become terminal in any further derivation step. Thus, any further derivation can not produce a terminal graph. Such nonterminal edges that are incident to two terminal nodes are called blocking edges. An eNCE graph grammar is called nonblocking if all graphs derivable from its axiom have no blocking edges. In the following lines, we show that for each con uent eNCE graph grammar G it is possible to construct in time O(2poly (size (G)) ) a nonblocking con uent eNCE graph grammar G 0 such that L(G ) = L(G 0), where poly () is some polynomial function. Up to now, the existence of such a construction was only known for boundary eNCE graph grammars; see [ELW90]. The substitution mechanism used by eNCE graph grammars is unfortunately not associative; however, an associative substitution mechanism for eNCE graph grammars is obtained by a simple extension of the embedding mechanism as for example in [CER93, De nition 3.1] for directed eNCE graph grammars.
De nition 4.1 (Extended Substitutions) For a graph G and an embedding relation C for G, we call the pair G = (G; C ) an extended graph. Let G = (G; C ) and H = (H; D) be two extended graphs and let u be a node of G. The extended graph J = (J; F ), denoted by G[u=H], is de ned by the graph J := G[u=D H ] and the embedding relation
F :=
f(a; l1; l2; v) 2 C j v 6= ug [ f(a; l1; l3; v) j (a; l1; l2; u) 2 C and (a; l2 ; l3; v) 2 D for some l2 g:
Intuitively speaking, the embedding relation F is the embedding relation C in which each tuple (a; l1 ; l2; u) is replaced by all (a; l1; l3; v), where (a; l2; l3 ; v) is from D. For example, if (a; l3 ; l1; u); (b; l1; l2 ; u) are tuples in some embedding relation for graph G from Figure 2.1, then the embedding relation F for G[u=D H ] as de ned in Figure 2:1 contains the tuples (a; l3 ; l2; v); (b; l1; l1; w). The extended substitution is associative, see [CER93, Lemma 3.2]. That is, for all extended graphs G; H; J, all nodes u from G, and all nodes v from H:
G[u=H][v=J] = G[u=H[v=J]]: If only the underlying graphs are considered, then there is no fundamental dierence between the extended substitution and the usual substitution. If in an eNCE graph grammar G the axiom is changed into an extended graph (with empty embedding relation) and the derivation process is also extended to extended graphs, then the new eNCE graph grammar generates the same graphs (with empty embedding relations) using the extended substitution as the original eNCE graph grammar using the usual substitution. Furthermore, the 9
extended eNCE graph grammar is con uent if and only if the usual eNCE graph grammar is con uent. Using the extended substitution, one can simply show that the con uence property is not only restricted to those graphs derivable from the axiom, but carries over, for example, to all graphs on the right hand sides of the productions and also to all graph derivable from them. (Here and for the rest of this section we assume that for each production (A; G; C ) there is a graph derivable from the axiom which has a node labeled by A.) A more general statement is shown in the following lemma: Lemma 4.2 Let K, G, H, J be extended graphs, u; v be nodes of G, and w be a node of K. Then K[w=G][u=H][v=J] = K[w=G][v=J][u=H] if and only if G[u=H][v=J] = G[v=J][u=H]: Proof \)" The embedding relations of G[u=H][v=J] and G[v=J][u=H] are equal by the definition of the extended substitution. The graphs underlying G[u=H][v=J] and G[v=J][u=H] are equal, because they can be obtained by removing the nodes of K (except w) and their incident edges from K[w=G[u=H][v=J]] and K[w=G[v=J][u=H]], which are equal by the hypothesis and the associativity of the extended substitution. \(" G[u=H][v=J] = G[v=J][u=H] implies K[w=G[u=H][v=J]] = K[w=G[v=J][u=H]] and by the associativity K[w=G][u=H][v=J] = K[w=G][v=J][u=H]:
2
Lemma 4.2 shows the following. When using the extended substitution, there is no dierence between con uence de ned for all extended graphs derivable from the axiom, for all extended graphs at the right hand sides of the productions, or for all extended graphs derivable from the right hands sides of the productions, see also [Cou87, Lemma 2.14]. Note that this does not hold for the usual substitution. The idea of our intended transformation is based on the de nition of a nite congruence on extended graphs with respect to the extended substitution mechanism. Similar concepts are considered, for example, in [Cou90, LW93, Wan91] for the hyperedge replacement embedding and the NLC embedding. Here, we restrict the de nition of the congruence to extended graphs whose nodes are all terminal. In the following, we assume that each graph over ; ? is also associated with the sets ; of terminal labels. This allows us to talk about terminal nodes and edges, nonterminal nodes and edge, and blocking edges. We call a graph in which all nodes are terminal a node-terminal graph. De nition 4.3 (Replaceability) Two extended node-terminal graphs H = (H; D) and J = (J; F ) are called replaceable, denoted by H J, if and only if H has a blocking edge , J has a blocking edge and f(a; l1 ; l2; H (u)) j (a; l1; l2; u) 2 Dg = f(a; l1; l2; J (u)) j (a; l1 ; l2; u) 2 F g: 10
Replaceability is an equivalence relation by de nition. Clearly, there are O(2jjj?j2jj) equivalence classes for all node-terminal extended graphs. All these classes can easily be enumerated. Next we show that replaceability is a congruence with respect to a con uent extended substitution.
Lemma 4.4 Let G be an extended graph with k nonterminal nodes u1; : : : ; uk . Let H1; : : : ; Hk and J1; : : : ; Jk be node terminal extended graphs such that Hi Ji for i = 1; : : : ; k, then
G[u1=H1] : : : [uk =Hk ] G[u1=J1] : : : [uk =Jk ]: Proof Let (a; l1; l2; v) be a tuple in the embedding relation of G[u1=H1] : : : [uk =Hk ]. If node v is from G, then (a; l1 ; l2; v) is also in the embedding relation of G[u1=J1 ] : : : [uk =Jk ]. If node
v is from some Hi, then there is a tuple (a; l1 ; l0; ui) for some l0 in the embedding relation of G and a tuple (a; l0 ; l2; v) in the embedding relation of Hi. Since Hi Ji, there is some tuple (a; l0; l2; w) in the embedding relation of Ji such that v and w are equal labeled. This implies that tuple (a; l1; l2 ; w) is in G[u1=J1] : : : [uk =Jk ]. Thus, if CH , CJ are the embedding relations of G[u1=H1] : : : [uk =Hk ] and G[u1=J1] : : : [uk =Jk ], then f(a; l1; l2 ; H (u) j (a; l1; l2 ; u) 2 CH g = f(a; l1; l2; J (u) j (a; l1 ; l2; u) 2 CJ g: Assume that G[u1=H1] : : : [uk =Hk ] has a blocking edge. If the blocking edge connects two nodes from G then it is also in G[u1=J1] : : : [uk =Jk ]. If the blocking connects two nodes from Hi for some i then by Hi Ji the blocking edge is also in G[u1=J1] : : : [uk =Jk ]. Assume that one node v of the blocking edge if from G and the other node w is from some Hi. Since Hi Ji, there is also a node w0 in Ji labeled as node w such that for each tuple (a; l1 ; l2; v) in the embedding relation of Hi there is a tuple (a; l1; l2; w) in the embedding relation of Ji. This implies that there is a blocking edge in G[u1 =J1] : : : [uk =Jk ]. The reverse argumentation is equivalent. Finally assume that one node v of the blocking edge is from some Hi and the other from node w is from some Hj for i < j . Assume also that the blocking edge is labeled by l1 . Then ui and uj are connected in G by an edge labeled by some l2 . Now the extended graph G[u1=H1] : : : [ui=Hi] has an edge between v and uj labeled by some l3 such that the embedding relation of Hj contains the tuple ((v); l3 ; l1; w). Since Hi Ji it follows that G[u1=J1 ] : : : [ui=Ji] has an edge between some v0 and uj labeled by l2 , where v0 and v are equal labeled. Since Jj Hj there is a tuple ((v); l2; l1; w0) in the embedding relation of Jj , where w and w0 are equal labeled. This implies that G[u1=H1] : : : [uk =Hk ] has a blocking edge between v0 and w0 labeled by l1 . The reverse argumentation is equivalent. 2 If a substitution is con uent then the equivalence class of G[u1=J1] : : : [uk =Jk ] from Lemma 4.4 can be computed by substituting the node u1; : : : ; uk in any order by arbitrary replaceable extended graphs, as the next lemma shows.
Lemma 4.5 Let G be an extended graph with k nonterminal nodes u1; : : : ; uk . Let H1; : : : ; Hk and J1; : : : ; Jk be node terminal extended graphs such that Hi Ji for i = 1; : : : ; k. Let be any permutation over (1; : : : ; k), i.e., is a bijection from f1; : : : ; kg to f1; : : : ; kg. If
G[u1=H1] : : : [uk =Hk ] = G[u(1) =H(1)] : : : [u(k)=H(k)];
(the con uence hypothesis) then
G[u1=J1] : : : [uk =Jk ] G[u(1) =J(1)] : : : [u(k)=J(k)]: 11
Proof G[u1=J1 ] : : : [uk =Jk ] G[u1 =H1] : : : [uk =Hk ] = G[u(1) =H(1)] : : : [u(k)=H(k)] G[u(1) =J(1) ] : : : [u(k)=J(k)]
by Lemma 4.4, by the con uence hypothesis, by Lemma 4.4. 2
Now, we can show the main theorem of this section.
Theorem 4.6 For each con uent eNCE graph grammar G a nonblocking con uent eNCE graph grammar G 0 can be constructed in time O(2poly (size (G)) ) such that L(G ) = L(G 0). Proof We number the equivalence classes of by the integers 1; : : : ; N . This allows us to talk about the rth equivalence class of . Let A1 ; : : : ; An be the nonterminal node labels of G . Then A; A1;r ; : : : ; An;r for r = 1; : : : ; N are the nonterminal node labels of G 0. The terminal node labels and all edge labels of G 0 are those from G .
If G is a graph with k nonterminal nodes u1; : : : ; uk labeled by Ai1 ; : : : ; Aik , respectively, then G(u1=r1; : : : ; uk=rk ) denotes the graph G in which the k nonterminal nodes u1; : : : ; uk are relabeled by Ai1 ;r1 ; : : : ; Aik ;rk , respectively. All other nodes and edges remain unchanged. Let (Ai ; G; C ) be a production from G in which G has k nonterminal nodes u1; : : : ; uk labeled by Ai1 ; : : : ; Aik , respectively. Then G 0 contains all productions (Ai;r ; G0; C 0) such that
G0 := C 0 :=
G(u1=r1; : : : ; uk=rk ); f(a; l1; l2; v) 2 C j a 2 g [ f(Ai0;r0 ; l1; l2; v) j (Ai0 ; l1; l2; v) 2 C; 1 r0 N g; and (G; C )[u1=H1] : : : [uk =Hk ] is from the rth equivalence class if Hl for 1 l k is a graph from the rl th equivalence class. This construction is well-de ned because replaceability is a congruence, see Lemma 4.4, and thus the type of (G; C )[u1=H1] : : : [uk =Hk ] depends only on the types of the His. Here any extended graphs Hi of type ri can be used to determine the type of (G; C )[u1=H1] : : : [uk =Hk ], because G is con uent and thus Lemma 4.5 can be applied. Let H be any extended node-terminal graph. It follows that H is derivable in G from the right hand side of a production (Ai; G; C ) if and only if H is derivable in G 0 from the right hand side of some production (Ai;r ; G0; C 0) for some r. For the if case, consider any extended derivation H (G0 ; C 0) =)
in G 0. By the de nition of G 0 there is a production (Ai; G; C ) in G for each production (Ai;r ; G0; C 0) in G 0, where (G; C ) can be obtained from (G0; C 0) by changing all symbols Ai;r , 1 r N , into Ai . Thus, there is a derivation H (G; C ) =)
in G . The only if case can be shown by induction on the length of the derivation. For the induction step let H (G; C ) =) 12
be some derivation in G and (Aj1 ; G1; C1); : : : ; (Ajk ; Gk ; Ck ) be the productions applied to the nonterminal nodes u1; : : : ; uk of G. By the con uence of G , the associativity of the extended substitution, and by Lemma 4.2 we can express H by
H = (G; C )[u1=H1] : : : [uk =Hk ] where the His are extended graphs derivable from the right hand sides (Gi; Ci). The extended graphs Hi are derivable in G 0 by the inductive hypothesis, Let r be the equivalence class of H = (G; C )[u1=H1] : : : [uk =Hk ] and r1 ; : : : ; rk be the equivalence classes of H1; : : : ; Hk , respectively, then production (Ai;r ; G0; C 0) with
G0 := C 0 :=
G(u1=r1; : : : ; uk=rk );
f(a; l1; l2; v) 2 C j a 2 g [ f(Ai0;r0 ; l1; l2; v) j (Ai0 ; l1; l2; v) 2 C; 1 r0 N g; is in G 0 and thus H is derivable from (G0; C 0) in G 0. Let us continue with the de nition of G 0. Let S be the axiom of G with k nonterminal nodes u1; : : : ; uk labeled by Ai ; : : : ; Aik , respectively. Then G 0 contains all productions (A; S (u1=r1; : : : ; uk =rk ); ;) such that (S; ;)[u1=H1] : : : [uk =Hk] has no blocking edges if Hl for 1 l k is a graph from 1
the rl th equivalence class. These productions exactly select the derivation combinations which do not generate node-terminal graphs with blocking edges from the axiom. The axiom of G 0 consists of a single node labeled by A. The resulting eNCE graph grammar G 0 is con uent (by the con uence of G and the relabeling of nonterminals), nonblocking (by the selection of the productions generated from the axiom of G), and generates exactly all terminal2 graphs which are generated by G . The size of G 0 is in O(2poly (size (G)) ) because N 2 O(2jjj?j jj). 2
It follows the exponential time decidability of emptiness for con uent eNCE graph grammars.
Corollary 4.7 The emptiness problem for C-eNCE graph grammars can be solved in exponential time.
Proof Modify the con uent eNCE graph grammar G into a nonblocking con uent eNCE graph grammar G 0 and then check whether the language of G 0 is empty. The rst step can be done in exponential time; see Theorem 4.6. The emptiness investigation of G 0 can then be done in linear time with respect to the size of G 0 which is at most exponential in the size of G . 2 The construction in the proof of Theorem 4.6 yields a new graph grammar whose size is always exponential in the size of the original grammar. In general, many productions of the new graph grammar can not produce node-terminal graphs. That is, the size of the new graph grammar can be reduced by removing useless productions. In the next lines, we show how to compute only the used equivalence classes. Let us rst specify one representative extended graph from each equivalence class. 13
De nition 4.8 (Basic graphs) For a node-terminal extended graph H = (H; D) the basic graph H is the node-terminal extended graph (H 0; D0) de ned as follows: 1. Let X := f(u) j (a; l1 ; l2; u) 2 Dg. 2. H 0 has a node ua labeled by a for each label a in X . H 0 has two additional nodes w1 and w2 . If H has a blocking edge, then H 0 has a blocking edge between w1 and w2 . (The labels of w1 , w2 , and the blocking edge are arbitrary but xed.) 3. D0 has a tuple (a; l1 ; l2 ; u(v) ) for each tuple (a; l1 ; l2 ; v) 2 D.
The basic graph H of H can be constructed in linear time with respect to the size of H. Each basic graph has at most jj + 2 nodes, one edge, and an embedding relation with jj j?j2 jj tuples. H and H are always replaceable. Let G be a con uent eNCE graph grammar, p = (A; G; C ) be a production of G , and Lp be the set of all H, where H is some node-terminal extended graph derivable from (G; C ). The following bottom-up algorithm generates all sets Lp for all productions p. 1. For all productions p = (A; G; C ) do: (a) If G is node-terminal then initialize Lp by f(G; C )g. (b) Otherwise, initialize Lp by the empty set. 2. For all productions p = (A; G; C ), where G has nonterminal nodes u1; : : : ; uk do: (a) Generate all basic graphs (G; C )[u1=H1] : : : [uk =Hk ]; where Hi, 1 i k, is from a set Lp0 and p0 contains the label of ui on its left hand side. (b) Insert those of the generated basic graphs into Lp which do not yet belong to Lp. 3. Repeat step 2 until no set Lp is extended between two iterations of step 2. The correctness basically follows from Lemma 4.4 and Lemma 4.5. After the ith iteration of step 2, the set Lp for p = (A; G; C ) contains all basic graphs H where H is derivable from (G; C ) with a derivation depth of at most i, i.e., the node-terminal extended graph H has a parse tree of height at most i. If the sets Lp of basic graphs are not very large, which depends on the grammar, then it is possible to construct the nonblocking con uent eNCE graph grammar more eciently as with the general method in the proof of Theorem 4.6 which uses all possible equivalence classes.
5 Boundary eNCE graph grammars
An eNCE graph grammar G is called boundary (B-eNCE) if nonterminal nodes are never adjacent in the axiom of G and in all graphs of the productions of G . We show that the emptiness problem is DEXPTIME-hard2 even for boundary eNCE graph grammars. Boundary DEXPTIME is the class of problems solvable in exponential (= 2poly(n) ) time by deterministic Turing machines. 2
14
graph grammars are always con uent, because there is no interdependence between nonadjacent nodes. The class DEXPTIME is also characterized by alternating Turing machines using polynomially bounded space [CKS81]. An alternating Turing machine is a system
M = (QE ; QU ; f0; 1g; ; qS ; qF ) in which QE is the nite set of existential states, QU is the nite set of universal states (QE and QU are disjoint), Q := QE [ QU is the set of all states,
Q f0; 1g Q f0; 1g fleft ; rightg is the next move relation, qS 2 Q is the start state, and qF 2 Q is the nal state. An instantaneous description (ID) for M is de ned as for the Turing machine in Section 3. Since we consider only polynomially space bounded Turing machines, we can assume that each ID has length m. Then the IDs need not to be extended step by step from the input size n up to some maximal length m. An ID 0 = (X10 ; : : : ; Xm0 ) is a successor ID of some = (X1; : : : ; Xm) if and only if ; 0 dier in at most two positions j; j + 1, and 1. (Xj ; Xj+1) = ((x; q); (y; #)), (Xj0 ; Xj0 +1) = ((z; #); (y; r)), and (q; x; r; z; right ) 2 , or 2. (Xj ; Xj+1) = ((y; #); (x; q)), (Xj0 ; Xj0 +1) = ((y; r); (z; #)), and (q; x; r; z; left ) 2 . An alternating Turing machine M accepts an ID if and only if either is a nal ID, or contains an existential state and some successor ID of is accepted by M , or contains a universal state and all successor IDs of are accepted by M . M accepts an input I = I1 I2 In 2 f0; 1g if and only if M accepts the initial ID
I = ((I1; qS ); (I2; #); : : : ; (In; #); (0; #); : : : ; (0; #)) of length m. In other words, M accepts I if and only if there is a tree in which all nodes are labeled by IDs, the single root is labeled by the initial ID I , the children of any non-leaf node labeled by an ID containing a universal state represent all successor IDs of , the single child of any non-leaf node labeled by an ID containing an existential state represents one successor ID of , and all the leaves are labeled by nal IDs.
Theorem 5.1 The emptiness problem for B-eNCE graph grammars is DEXPTIME-hard.
15
Proof We design a B-eNCE graph grammar G for an arbitrary alternating polynomially space bounded Turing machine M and an input I = I1 I2 : : : In for M , such that M accepts I if and only if the language of G is not empty. Let m be the polynomial space bound of M . G has the node labels a1 ; : : : ; am; A; b, where a1 ; : : : ; am; b are terminal and A is nonterminal. The edge labels are l and lX , where X is a composite symbol. The labels l(0;#), l(1;#) , l(0;qF ), l(1;qF ) are terminal edge labels. The remaining labels l; l(0;q) ; l(1;q) for q 2 Q and q 6= qF are nonterminal edge labels. The axiom of G has m + 1 nodes u1; : : : ; um; v labeled by a1 ; : : : ; am; A, respectively, and edges (fui; vg; lXi ) for i = 1; : : : ; m, where I = (X1 ; : : : ; Xm) is the initial ID de ned by the input I for M . Let G = (V; E; ) be any graph without l-edges derivable from the axiom of G . The grammar G is designed such that each environment env (u) = f((v); l) j (fu; vg; l) 2 E g of a nonterminal A-node u of G represents some ID . That is, if (ai; lX ) is a pair from the environment, then in the composite symbol X is at position i. The environment of the nonterminal A-node in the axiom of G represents the initial ID I . We have three types of productions. Productions of the rst type change the environment of an A-node with respect to an existential computation step. Productions of the second type change the environment of an A-node with respect to a universal computation step. Productions of the third type change nonterminal A-nodes into terminal b-nodes if and only if they represent nal IDs. In particular, G has the following productions.
Type 1 productions for a move to the right For each j = 1; : : : ; m ? 1 and each (q; x; r; z; right ) 2 , where q is an existential state,
there is a production (A; G; C ), where G is the graph consisting of a single A-node u and C = f(aj ; l(x;q); l(z;#); u)g [ f(aj ; lX ; l; u) j X 2 CS; X 6= (x; q)g [ f(aj+1; l(y;#) ; l(y;r); u) j y 2 f0; 1gg [ f(aj+1; lX ; l; u) j X 2 f0; 1g Qg [ f(ai; lX ; lX ; u) j X 2 CS; 1 i m; i 6= j; i 6= j + 1g [ f(ai; l; l; u) j 1 i mg: As in the proof of Theorem 3.1, if one of these productions is applied without generating a nonterminal l-edge, then the environment of the new node u represents the previous ID changed with respect to the move (q; x; r; z; right ) 2 .
Type 1 productions for a move to the left
These productions are analogously de ned to the type 1 production for a move to the right. Here only the direction of the move is reversed. For each j = 2; : : : ; m and each (q; x; r; z; left ) 2 , where q is an existential state, there is a production (A; G; C ), where G is the graph consisting of a single A-node u and C = f(aj ; l(x;q); l(z;#); u)g [ f(aj ; lX ; l; u) j X 2 CS; 6= (x; q)g [ f(aj?1; l(y;#) ; l(y;r); u) j y 2 f0; 1gg [ f(aj?1; lX ; l; u) j X 2 f0; 1g Qg [ f(ai; lX ; lX ; u) j X 2 CS; 1 i m; i 6= j; i 6= j ? 1g [ f(ai; l; l; u) j 1 i mg: 16
Type 2 productions
For each j = 1; : : : ; m, each tape symbol x 2 f0; 1g, and each universal state q, there is a production (A; G; C ) de ned as follows: The graph G and the embedding relation C is the disjoint union of all graphs and embedding relations, respectively, of productions of type 1, which would exist for j , all (q; x; r; y; left ) 2 , and all (q; x; r; y; right ) 2 , if q would be considered as an existential state.
Type 3 production for the elimination of nonterminal nodes
There is a production (A; G; C ), where G is the graph consisting of a single b-node u and C = f(aj ; lX ; lX ; u) j X 2 CS; 1 j mg [ f(aj ; l; l; u) j 1 j mg: Again, a close inspection of the de ned productions shows that the language of G is not empty if and only if M accepts its input I . It is also straightforward that the construction of G can be done in logarithmic space with respect to the size of I . 2 We have shown by Corollary 4.7 and Theorem 5.1 the following result.
Corollary 5.2 The emptiness problem for C-eNCE and B-eNCE graph grammars is logspace complete for DEXPTIME.
6 Linear eNCE graph grammars
An eNCE graph grammar G is called linear (L-eNCE) if the axiom and all graphs of the productions have at most one nonterminal node. This implies that each graph derivable from the axiom also has at most one nonterminal node. We do not know whether or not for each linear eNCE graph grammar there always exists a nonblocking linear eNCE G 0 graph grammar whose size is polynomially bounded in the size of G . So we have to pursue another approach to show that emptiness of linear eNCE graph grammars is decidable in polynomial space.
Theorem 6.1 The emptiness problem for L-eNCE graph grammars is solvable in polynomial space.
Proof We can prove the existence of a derivation of some terminal graph by the following
nondeterministic method. Start with a production (Ai1 ; Gi1 ; Ci1 ) where G is node-terminal and compute H := (Gi1 ; Ci1 ). Then choose some production (Ai2 ; Gi2 ; Ci2 ) such that Gi2 has a nonterminal node ui2 labeled by Ai1 and recompute H := (Gi2 ; Ci2 )[ui2 =H]. Repeat this process some times by choosing some production (Aij ; Gij ; Cij ) such that Gij has a nonterminal node uij labeled by Aij?1 and recomputing H := (Gij ; Cij )[uij =H]. Then nally construct H := S[u=H], where S is the extended axiom of the grammar and u is its nonterminal node. The grammar G can generate a terminal graph if and only if the algorithm above can generate some extended graph H without blocking edge. The correctness follows from the associativity of the extended substitution and by Lemma 4.4. The algorithm obviously uses polynomial space. 2 The proof of the PSPACE-hardness is part of the proof of Theorem 5.1. 17
Theorem 6.2 The emptiness problem for L-eNCE graph grammars is log-space hard for PSPACE.
Proof A nondeterministic Turing machine is an alternating Turing machine without uni-
versal states. If in the construction from the proof of Theorem 5.1 the productions of type 2 are omitted, then the universal states are ignored and the resulting eNCE graph grammar is linear. 2 We have shown by Theorem 6.1 and 6.2 the following result.
Corollary 6.3 The emptiness problem for L-eNCE graph grammars is log-space complete for PSPACE.
7 Deterministic eNCE graph grammars
An eNCE graph grammar G is called deterministic (det-eNCE) if for each nonterminal node label A there is at most one production (A; G; C ) having A on its right hand side. There are con uent, boundary, and linear deterministic eNCE graph grammars. Con uent deterministic eNCE graph grammars de ne at most one terminal graph; but, in general, when the order in which nonterminal nodes are substituted is important for the resulting graph, eNCE graph grammars can de ne more than one terminal graph. However, all graphs in the language of a deterministic eNCE graph grammar have the same set of labeled nodes. Dierent derivation orders yield only dierent edges. Figure 7.4 shows an example of a deterministic eNCE graph grammar that de nes two dierent graphs. A
l1
c
B u
G
D
Derivation 1 A
l1
Derivation 2 A l1
B
c
l2
B
c
B
A
l1
c
c
c
l2
c
Figure 7.4: A deterministic eNCE graph grammar G = (fA; B; cg; fcg; fl1; l2g; fl2g; fp1; p2g; G) with two productions p1 = (A; D; f(u; l1; l2; B )g) and p2 = (B; D; f(u; l1; l1; A)g). The gure shows two derivations with dierent results. We do not know whether the emptiness problem for deterministic graph grammars can be solved in polynomial time. On the other side, we can not prove that emptiness for general deterministic eNCE graph grammars is harder than for con uent deterministic graph grammars.
Theorem 7.1 The emptiness problem for det-C-eNCE graph grammars is solvable nondeterministically in logarithmic space.
18
Proof A deterministic con uent eNCE graph grammar de nes a terminal graph if and only
if
1. for each graph G derivable from the axiom and each nonterminal node u in G, there is some production ((u); D; C ) in G such that all graphs derivable from D do not contain a node labeled by (u), and 2. all graphs derivable from the axiom do not contain a blocking edge. The equivalence above is obvious. Both properties are nondeterministically decidable in logarithmic space, because NL is closed under complementation; see [Imm87]. That is, for the rst property, we negate the answer of the following question: Is there a graph G derivable from the axiom that has a nonterminal node u which has either no production ((u); D; C ) or, if such a production exist, can D derive a graph with a nonterminal node labeled by (u)? For the second property we negate the answer of the question whether there is a graph derivable from the axiom that has a blocking edge. This can be done nondeterministically in logarithmic space as follows: Start with a subgraph of the axiom that has at most two nodes and one edge. If one of the nodes is nonterminal then apply some production to it and consider some subgraph of the resulting graph with at most two nodes and one edge. If this process ends with two terminal nodes connected by some nonterminal edge, then the grammar generates a blocking edge and its language is empty. On the other side, if the grammar generates a blocking edge then the derivation process can nd it. 2 The next theorem is proved by a log-space reduction from the graph accessibility problem. A directed graph is a graph G = (V; A) consisting of a nite set of vertices V and a set of arcs A V V . We say that vertex v is reachable from vertex u if there is sequence of arcs (ui1 ; ui2 ); (ui2 ; ui3 ); (ui3 ; ui4 ); : : : ; (uin?1 ; uin ) such that ui1 = u and v = uin . The graph accessibility problem (GAP) is the question whether for a given directed graph G some vertex v is reachable from some vertex u. It is well known that GAP is log-space complete for NL; see, for example, [HU79].
Theorem 7.2 The emptiness problem for det-L-eNCE graph grammars is log-space hard for NL.
Proof We prove the theorem by a simple reduction from GAP. Let G = (V; A) be a directed graph with vertex set V = fu1; : : : ; ung. We design a deterministic linear eNCE graph grammar G whose language is not empty if and only if in G vertex un is reachable from vertex u1. Since NL is closed under complementation, see [Imm87], the theorem will follow. G has the node labels A1 ; : : : ; An+1, where An+1 is terminal. The edge labels are l1 ; : : : ; ln, where l1; : : : ; ln?1 are terminal. The axiom of G consists of one node labeled by An+1, one node labeled by A1 , and one edge between the two nodes labeled by l1. Then for i = 1; : : : ; n there is a production (Ai ; H; D), where H consists of one single node u labeled by Ai+1, and D has a tuple (a; li; lj ; u) for each arc (ui; uj ) in G and a tuple (a; li; li; u) for each i = 1; : : : ; n. The grammar G derives exactly one graph J with two terminal nodes labeled by An+1. There is an li-edge between these two nodes if and only if vertex ui is reachable from vertex u1 (via at least n ? 1 vertices) in G. Since ln is nonterminal, J has a blocking edge if and only if vertex un is reachable from vertex v1 . The transformation can clearly be done in log-space. 2 Now we have shown the following corollary. 19
Corollary 7.3 The emptiness problem for det-C-eNCE, det-B-eNCE, and det-L-eNCE
graph grammars is log-space complete for NL.
If we do not allow more than one edge between two nodes, then the emptiness problem for deterministic linear eNCE graph grammars is only L-complete. This is because then the two properties from Theorem 7.2 can be answered deterministically in logarithmic space. The L hardness follows from the fact that GAP is L-complete for paths.
8 Conclusions The results presented in this paper can easily be extended to edNCE graph grammars. In such graph grammars all graphs have directed edges. Thus, the embedding has to take into account the directions of removed and generated edges. All hardness results for eNCE graph grammars hold also for edNCE graph grammar, because each undirected edge can be represented by two directed edges. The upper bounds can be shown by straight forward extensions of the proofs for the upper bounds for eNCE graph grammars. A simple modi cation of eNCE graph grammars shows that the problem whether an eNCE graph grammar G can generate a node-terminal graph without edges (a totally disconnected graph) is at least as dicult as the problem whether G can generate some terminal graph. Here we just have to remove all terminal edges incident to two terminal nodes in the axiom of G and in all graphs at the right hand sides of the productions; additionally, we have to remove all tuples (a; l1 ; l2; u) from all embedding relations for which a; l2 are terminal labels and u is a terminal node. This modi cation can be done in logarithmic space. The resulting eNCE graph grammar generates a totally disconnected graph if and only if the original eNCE graph grammar generates some terminal graph. It follows that the problem whether an eNCE, C/B-eNCE, L-eNCE graph grammar can generate a totally disconnected graph is undecidable, DEXPTIME-hard, and PSPACEhard, respectively. Furthermore, a simple additional modi cation shows that the question whether an eNCE, C/B-eNCE, L-eNCE graph grammar can generate a graph which satis es any node-monotone property is also undecidable DEXPTIME-hard, and PSPACE-hard, respectively. A property is node-monotone if each graph which satisfy does not loose its property if further nodes are included. To show this we just include to the axiom of the eNCE graph grammar above any graph that satis es . A simple modi cation shows that the question whether the language of an eNCE, C/BeNCE, L-eNCE is of bounded degree is also undecidable, DEXPTIME-hard, and PSPACEhard, respectively. A graph language L is of bounded degree if and only if there is an integer n such that the node degree of all nodes in all graph in L is less than n. Let us nally discuss the complexity of eliminating blocking edges. We have shown in Theorem 4.6 that each C-eNCE graph language can be generated by a nonblocking C-eNCE graph grammar. We have also shown that the emptiness problem for B-eNCE graph grammars is DEXPTIME-hard. This shows that generating a nonblocking C-eNCE or B-eNCE graph grammar from a usual C-eNCE or B-eNCE graph grammar takes at least exponential time for an in nite number of instances. Otherwise we could decide the emptiness problem in less than exponential time. This would contradict the de nition of exponential time Turing computability.
20
9 Acknowledgments We are grateful for many fruitful suggestions and comments of the anonymous referees of an earlier version of this paper.
References [Bra87]
[CER79] [CER93] [CKS81] [Cou87] [Cou90] [EKR91] [EL89] [ELR88] [ELW90] [ENR83] [ENRR87] [Hab92] [HU79]
F.J. Brandenburg. On partially ordered graph-grammars. In H. Ehrig, M. Nagl, A. Rosenfeld, and G. Rozenberg, editors, Proceedinds of Graph-Grammars and Their Application to Computer Science, volume 291 of LNCS, pages 99{111. Springer-Verlag, 1987. V. Claus, H. Ehrig, and G. Rozenberg. Proceedings of Graph-Grammars and Their Application to Computer Science '78, volume 73 of LNCS. Springer-Verlag, 1979. B. Courcelle, J. Engelfriet, and G. Rozenberg. Handle-rewriting hypergraph grammars. Journal of Computer and System Science, 46:218{270, 1993. A.K. Chandra, D.C. Kozen, and L.J. Stockmeyer. Alternation. Journal of the ACM, 28:114{133, 1981. B. Courcelle. An axiomatic de nition of context-free rewriting and its application to NLC graph grammars. Theoretical Computer Science, 55:141{181, 1987. B. Courcelle. The monadic second-order logic of graphs I: Recognizable sets of nite graphs. Information and Computation, 85:12{75, 1990. H. Ehrig, H.J. Kreowski, and G. Rozenberg. Proceedings of Graph-Grammars and Their Application to Computer Science '90, volume 532 of LNCS. SpringerVerlag, 1991. J. Engelfriet and G. Leih. Linear graph grammars: power and complexity. Information and Computation, 81:88{121, 1989. J. Engelfriet, G. Leih, and G. Rozenberg. Apex graph grammars and attribute grammars. Acta Informatica, 88:537{571, 1988. J. Engelfriet, G. Leih, and E. Welzl. Boundary graph grammars with dynamic edge relabeling. Journal of Computer and System Sciences, 40:307{345, 1990. H. Ehrig, M. Nagl, and G. Rozenberg. Proceedings of Graph-Grammars and Their Application to Computer Science '82, volume 153 of LNCS. SpringerVerlag, 1983. H. Ehrig, M. Nagl, A. Rosenfeld, and G. Rozenberg. Proceedings of GraphGrammars and Their Application to Computer Science '86, volume 291 of LNCS. Springer-Verlag, 1987. A. Habel. Hyperedge Replacement: Grammars and Languages, volume 643 of LNCS. Springer-Verlag, 1992. J.E. Hopcroft and J.D. Ullman. Introduction to Automata Theory, Languages, and Computation. Addison-Wesley Publishing Company, Massachusetts, 1979. 21
[Imm87] N. Immerman. Languages that capture complexity classes. SIAM Journal on Computing, 16(4):760{778, August 1987. [JR80a] D. Janssens and G. Rozenberg. On the structure of node label controlled graph languages. Information Science, 20:191{216, 1980. [JR80b] D. Janssens and G. Rozenberg. Restrictions, extensions, and variations of NLC grammars. Information Science, 20:217{244, 1980. [JR81] D. Janssens and G. Rozenberg. Decision problems for node label controlled graph grammars. Journal of Computer and System Science, 22:144{147, 1981. [JR82] D. Janssens and G. Rozenberg. Graph grammars with neighbourhood-controlled embedding. Theoretical Computer Science, 21:55{74, 1982. [Kau85] M. Kaul. Syntaxanalyse von Graphen bei Prazidenz-Graph-Grammatiken. PhD thesis, Universitat Osnabruck, Osnabruck, Germany, 1985. [Kau87] M. Kaul. Practical applications of precedence graph grammars. In H. Ehrig, M. Nagl, A. Rosenfeld, and G. Rozenberg, editors, Proceedinds of GraphGrammars and Their Application to Computer Science, volume 291 of LNCS, pages 326{342. Springer-Verlag, 1987. [LW88] T. Lengauer and E. Wanke. Ecient solution of connectivity problems on hierarchically de ned graphs. SIAM Journal on Computing, 17(6):1063{1080, December 1988. [LW93] T. Lengauer and E. Wanke. Ecient analysis of graph properties on context-free graph languages. Journal of the ACM, 40(2):368{393, 1993. [Nag79] M. Nagl. Graph-Grammatiken. Vieweg, Braunschweig, 1979. [RW86] G. Rozenberg and E. Welzl. Graph theoretic closure properties of the family of boundary NLC structured graphs. Acta Informatica, 23:289{309, 1986. [Wan91] E. Wanke. Algorithms for graph problems on BNLC structured graphs. Information and Computation, 94(1):93{122, 1991.
22