Now let V be a nite alphabet and A an n-dimensional array over V; A 6= n. Then A is said ...... F of lines of thickness one over the one-letter alphabet fag with the ...
ACCEPTING ARRAY GRAMMARS WITH CONTROL MECHANISMS Henning FERNAU
Wilhelm-Schickard-Institut fur Informatik, Universitat Tubingen, Sand13, D-72076 Tubingen, Germany
Rudolf FREUND
Institut fur Computersprachen, Technische Universitat Wien, Resselgasse3, A-1040 Wien, Austria
Abstract. We consider (n-dimensional) array grammars in the accept-
ing mode with various control mechanisms and compare these families of array grammars with the corresponding families obtained by array grammars in the generating mode.
1 Introduction Accepting grammars together with various control mechanisms were introduced in [1] for the string case. Recent ideas concerning these grammars were exposed in [2]. The main results of the paper concern the relations between the families of array languages obtained by accepting array grammars in this way and array languages described by the corresponding types of generating array grammars. Compared with the string case, we nd many similarities, e.g., accepting programmed array grammars without appearance checking are just as powerful as their generating counterparts, and accepting ordered grammars can describe every recursively enumerable array language. On the other hand, the family of accepting regular programmed two-dimensional array languages with unconditional transfer is incomparable with the corresponding family of generating regular programmed array languages, while the respective string language classes coincide. Moreover, such incomparability results have not been observed in the string case except for pure grammars [3].
2 De nitions and examples In the main part of this section, we will introduce the de nitions and notations for arrays and sequential array grammars [5,11,14,17,19] and give some explanatory examples, but rst we recall some basic notions from the theory of formal languages (for more details, the reader is referred to [18]). De nition 2.1. For an alphabet V , by V we denote the free monoid generated by V under the operation of concatenation; the empty string is denoted by , and V n fg is denoted by V + . Any subset of V + is called a -free (string) language. A (string) grammar is a quadruple G = (VN ; VT ; P; S) ; where VN and VT are nite sets of non-terminal and terminal symbols, respectively, with VN \ VT = ;; P is a nite set of productions ! with 2 V + and 2 V ; where V =
VN [ VT ; and S 2 VN is the start symbol. For x; y 2 V we say that y is directly derivable from x in G, denoted by x `G y, if and only if for some ! in P and u; v 2 V we get x = uv and y = u v. Denoting the re exive and transitive closure of the derivation relation `G by `G , the (string) language generated by G is L(G) = fw 2 VT j S `G wg : The families of -free (string) languages generated by arbitrary, monotonic, context-free, respectively regular grammars are denoted by L (enum) ; L (mon) ; L (cf) ; respectively L (reg) : The following relations are known as the Chomskyhierarchy [18]: L (reg) $ L (cf) $ L (mon) $ L (enum) : De nition 2.2. Let Z denote the set of integers, let N denote the set of positive integers, N = f1; 2; :::g, and let n 2 N: Then an n-dimensional array A over an alphabet V is a function A : Z n ! V [ f#g ; where shape(A) = fv 2 Z n j A (v) 6= #g is nite and # 2= V is called the background or blank symbol. We usually shall write A = f(v; A(v)) j v 2 shape(A)g : The set of all n-dimensional arrays over V shall be denoted by V n : The empty array in V n with empty shape shall be denoted by n. Moreover, we de ne V +n = V n n fn g : Any subset of V +n is called a -free n-dimensional array language. De nition 2.3. Let v 2 Z n. Then the translation v : Z n ! Z n is de ned by v (w) = w + v for all w 2 Z n , and for any array A 2 V n we de ne v (A), the corresponding n-dimensional array translated by v, by (v (A)) (w) = A (w ? v) for all w 2 Z n : The vector (0; : : :; 0) 2 Z n is denoted by n , while (1; : : :; 1) is denoted by En . Usually [5,17,19,20], arrays are regarded as equivalence classes of arrays with respect to linear translations, i.e. only the relative positions of the symbols 6= # in the plane are taken into account: The equivalence class [A] of an array A 2 V n is de ned by [A] = fB 2 V n j B = v (A) for some v 2 Z n g : The set of all equivalence classes of n-dimensional arrays over V with respect to linear translations shall be denoted by [V n ] etc. Most of the results elaborated in this paper immediately carry over from the families of array languages we consider to the corresponding families of array languages with respect to linear translations, therefore, in general we shall not consider these families of array languages with respect to linear translations explicitely in the following any more. In order to be able to de ne the notion of connectedness of n-dimensional arrays, we need the following de nitions: De nition 2.4. An (undirected) graph g is an ordered pair (K; E), where K is a nite set of nodes and E is a set of undirected edges fx; yg with x; y 2 K: A sequence of dierent nodes x0; x1; : : :; xm; m 2 N, is called a path of length m in g with the starting-point x0 and the ending-point xm , if for all i with 1 i m an edge fxi?1; xig in E exists. A graph g is said to be connected, if for any two nodes x; y 2 K; x 6= y, a path in g with starting point x and ending point y
exists. Observe that a graph (fxg ; ;) with only one node and an empty set of edges is connected, too. Let W be a non-empty nite subset of Z n . For any k 2 N [ f0g ; a graph gk (W) = (W; Ek) can be assigned to W such that Ek for v; w 2 W contains the edge fv; wg if and only if 0 < kv ? wk k; where the norm kuk of a vector u 2 Z n ; u = (u (1) ; : : :; u (n)) ; is de ned by kuk = max fju (i)j j 1 i ng : Then, W is said to be k-connected if gk (W) is a connected graph. Observe that W is 0-connected if and only if card (W) = 1; where card (W) denotes the number of elements in the set W: Now let V be a nite alphabet and A an n-dimensional array over V; A = 6 n. Then A is said to be k-connected if gk (shape (A)) is a connected graph. Obviously, if A is k-connected then A is m-connected for all m > k; too. The norm of A is the smallest number k 2 N [ f0g such that A is k-connected, and is denoted by kAk : Observe that kAk = 0 if and only if card (shape (A)) = 1: Example 2.1. The n-dimensional array E (n; k) = f( n; a); (kEn; a)g 2 fagn is m-connected only for every m k, and therefore kE (n; k)k = k: 2 De nition 2.5. An n-dimensional generating array production p over V is a triple (W; A1 ; A2) ; where W Z n is a nite set and A1 and A2 are mappings from W to V [ f#g ; p is called -free if shape (A2 ) 6= ;; where we de ne shape (Ai ) = fv 2 W j Ai (v) 6= #g ; 1 i 2: The norm of the n-dimensional array production (W; A1; A2 ) is de ned by k(W; A1; A2)k = max fkvk j v 2 W g : We say that the array C2 2 V n is directly derivable from the array C1 2 V n by the n-dimensional array production (W; A1 ; A2) if and only if there exists a vector v 2 Z n such that C1 (w) = C2 (w) for all w 2 Z n n v (W) as well as C1 (w) = A1 (?v (w)) and C2 (w) = A2 (?v (w)) for all w 2 v (W) ; i.e. the subarray of C1 corresponding to A1 is replaced by A2 , thus yielding C2; we also write C1 `p C2: As can already be seen from the de nitions of an n-dimensional array production, the conditions for an application to an n-dimensional array B and the result of an application to B, an n-dimensional array production (W; A1; A2 ) is a representative for the in nite set of equivalent n-dimensional array productions of the form (v (W) ; v (A1 ) ; v (A2 )) with v 2 Z n : Hence, without loss of generality, in the sequel we shall assume n 2 W as well as A1 ( n ) 6= #: Moreover, we often will omit the set W; because it is uniquely reconstructible from the description of the two mappings A1 and A2 by Ai = f(v; Ai (v)) j v 2 W g ; 1 i 2: Thus in the sequel we will represent the n-dimensional array production (W; A1; A2) also by writing A1 ! A2 ; i.e. f(v; A1 (v)) j v 2 W g ! f(v; A2 (v)) j v 2 W g : De nition 2.6. An n-dimensional (generating) array grammar is a quintuple G = (n; VN ; VT ; #; P; f(v0 ; S)g) ; where VN is the alphabet of non-terminal symbols, VT is the alphabet of terminal symbols, VN \ VT = ;; # 2= VN [ VT ; P is a nite non-empty set of n-dimensional array productions over VN [ VT and f(v0; S)g is the start array (axiom), v0 is
the start vector, and S is the start symbol. G is called -free if every production in P is -free. We say that the array B2 2 V n is directly derivable from the array B1 2 V n in G, denoted B1 `G B2 , if and only if there exists an n-dimensional array production p = (W; A1; A2) in P such that B1 `p B2 : Let `G be the re exive transitive closure of `G . Then the (n-dimensional) array language generated by G, Lgen (G) ; is de ned by Lgen (G) = fA j A 2 VTn; f(v0; S)g `G Ag : The norm of the n-dimensional array grammar G is de ned by kGk = max fkpk j p 2 P g : An n-dimensional generating array production p = (W; A1; A2) in P is called
{ { { {
monotonic, if shape (A1 ) shape (A2 ) ; strictly monotonic, if shape (A2 ) = W and kpk = 1; #-context-free, if card (shape (A1 )) = 1; context-free, if p is monotonic, card (shape (A1 )) = 1, and A1 ( n ) 2 VN ;
the condition A1 ( n) 2 VN allows the representation of a context-free array production as (A; f(v; A2 (v)) j v 2 W g) or A ! f(v; A2 (v)) j v 2 W g instead of (W; f( n ; A)g [ f(v; #) j v 2 W n f n gg ; f(v; A2 (v)) j v 2 W g) ; if card (W) = 1; we only write A ! A2 ( n ) ; { strictly context-free, if p is strictly monotonic as well as context-free; { regular, if either 1. W = f n; vg for some v 2P Un ; where Un = f(i1 ; : : :; in) j nk=1 jik j = 1g ; and A1 = f( n ; B) ; (v; #)g ; A2 = f( n; a) ; (v; C)g ; with B; C 2 VN and a 2 VT ; (we also write Bv# ! avC), or 2. W = f ng ; A1 = f( n ; B)g ; A2 = f( n ; a)g ; with B 2 VN and a 2 VT (we also write B ! a).
G is called an n-dimensional array grammar of type (gen; X) ; X 2 fenum; # ? cf; mon; smon; cf; scf; regg ; if every array production in P is
of the corresponding type, i.e. a generating arbitrary (gen; enum), #-context-free (gen; # ? cf), monotonic (gen; mon), strictly monotonic (gen; smon), contextfree (gen; cf), strictly context-free (gen; scf), respectively regular (gen; reg) ndimensional (generating) array production; the corresponding families of -free n-dimensional array languages are denoted by L (n; (gen; X)) : If for two types (gen; X), (gen; Y ) with X; Y 2 fenum; # ? cf; mon; smon; cf; scf; regg every array production of type (gen; X) is also an array production of type (gen; Y ) ; we write (gen; X) (gen; Y ) or even X Y: Remark 2.1. Let G = (n; VN ; VT ; #; P; f(v0 ; S)g) be an n-dimensional (generating) array grammar. If G is regular, strictly context-free, respectively strictly monotonic, then according to the previous de nition of regular, strictly contextfree, and strictly monotonic n-dimensional generating array productions we immediately see that every array in Lgen (G) must be 1-connected. If G is contextfree or monotonic, then kAk kGk for all A 2 Lgen (G) : In the case of arbitrary n-dimensional array grammars, additional restrictive conditions on the n-dimensional array productions in P are required in order to guarantee every
n-dimensional array in Lgen (G) to be kGk-connected or even to be 1-connected as it is often required in the literature [5,17,19,20]. In the following, we also consider the case of monotonic n-dimensional generating array grammars with norm 1 and denote the corresponding family of array languages generated by such array grammars by L (n; (gen; mon1 )) : Like in the string case, some of the families of array languages de ned above form a strict hierarchy (compare with the results stated in [11,12,14]). Proposition 2.1. (Chomsky-Hierarchy of array languages) For all n 2 N, L (n; (gen; reg)) $ L (n; (gen; scf)) $ L (n; (gen; mon)) $ L (n; (gen; enum)) : Obviously, the inclusions L (n; (gen; scf)) $ L (n; (gen; smon)) and L (n; (gen; cf)) $ L (n; (gen; mon)) are true, too, whereas the families L (n; (gen; cf)) and L (n; (gen; smon)) are incomparable. Furthermore, we have the inclusions L (n; (gen; cf)) $ L (n; (gen; # ? cf)) $ L (n; (gen; enum)) ; whereas L (n; (gen; # ? cf)) and L (n; (gen; mon)) are incomparable. An interesting feature of n-dimensional (generating) array grammars is the fact that even regular and context-free array productions make use of some special context, namely the context of blank symbols #. This #-sensing ability (which is reduced to a minimum in the case of strictly context-free respectively strictly monotonic array grammars in contrast to context-free respectively monotonic array grammars) induces a relatively high generating power even of only regular two-dimensional-dimenensional array grammars and yields some rather astonishing results, e.g. the set of all solid squares can be generated by a regular two-dimensional array grammar [20]. As many results for n-dimensional arrays for a special n can be taken over immediately for higher dimensions, we introduce the following notion: De nition 2.7. Let n; m 2 N with n m: For n < m; the natural embedding in;m : Z n ! Z m is de ned by in;m (v) = (v; m?n ) for all v 2 Z n ; for n = m we de ne in;n : Z n ! Z n by in;n(v) = v for all v 2 Z n : To an n-dimensional array A 2 V +n with A = f(v; A (v)) j v 2 shape (A)g we assign the m-dimensional array in;m (A) = f(in;m (v) ; A (v)) j v 2 shape (A)g :
3 Accepting array grammars: de nitions and examples First we introduce the concept of accepting array productions and grammars: De nition 3.1. An n-dimensional accepting array production p over V is a triple (W; A2 ; A1) ; where W Z n is a nite set and A1 and A2 are mappings from W to V [ f#g ; p is called -free if shape (A2) 6= ;. We say that the array C1 2 V n is directly derivable (reducible) from the array C2 2 V n by
the n-dimensional accepting array production (W; A2; A1 ) if and only if there exists a vector v 2 Z n such that C1 (w) = C2 (w) for all w 2 Z n n v (W) as well as C2 (w) = A2 (?v (w)) and C1 (w) = A1 (?v (w)) for all w 2 v (W) ; i.e. the subarray of C2 corresponding to A2 is replaced by A1 , thus yielding C1 ; we also write C2 `p C1: For short, if (W; A1; A2 ) is a generating array production, then (W; A2 ; A1) is the corresponding (dual) accepting array production; for the accepting array production (W; A2; A1 ) the dual generating array production is (W; A1; A2). An n-dimensional accepting array grammar is a construct G = (n; VN ; VT ; #; P; f(v0 ; S)g) ; where VN is the alphabet of non-terminal symbols, VT is the alphabet of terminal symbols, VN \ VT = ;; # 2= VN [ VT ; P is a nite non-empty set of n-dimensional accepting array productions over VN [ VT ; and f(v0; S)g is the nal array (goal). G is called -free if every production in P is -free. We say that the array B1 2 V n is directly derivable from the array B2 2 V n
in G, denoted B2 `G B1 , if and only if there exists an n-dimensional accepting array production p = (W; A2; A1) in P such that B2 `p B1 : Let `G be the re exive transitive closure of `G . Then the (n-dimensional) array language accepted by G, Lacc (G) ; is de ned by Lacc (G) = fA j A 2 VTn; A `G f(v0 ; S)gg : For any X 2 fenum; # ? cf; mon; smon; cf; scf; regg the accepting array production (W; A2; A1) is said to be of type (acc; X) ; if the dual generating array production (W; A1; A2) is of type (gen; X) : G is called to be of type (acc; X) ; if every accepting array production in P is of the corresponding type. The corresponding families of -free n-dimensional array languages are denoted by L (n; (acc; X)) : For any n-dimensional (generating respectively accepting) array grammar G = (n; VN ; VT ; #; P; f(v0 ; S)g) ; the corresponding ?dual n-dimensional (accept- ing respectively generating) array grammar Gd = n; VN ; VT ; #; P d; f(v0 ; S)g is de ned by P d = f(W; A2; A1) j (W; A1; A2 ) 2 P g : The following result is obvious from our de nitions: Lemma 3.1. If G is a generating (accepting, respectively) array grammar and Gd is its dual (generating, respectively) array grammar, then ? ? accepting Lgen (G) = Lacc Gd (and Lacc (G) = Lgen Gd , respectively). Hence, for every n 2 N and for every X 2 fenum; # ? cf; mon; smon; cf; scf; regg we obtain L (n; (acc; X)) = L (n; (gen; X)) : Therefore, as in the string case we can also use the notation L (n; X) for both L (n; (acc; X)) and L (n; (gen; X)) : We shall also omit the subscripts gen and acc, respectively, in Lgen (G) and Lacc (G); respectively, if the derivation mode is clear from the context.
4 Control mechanisms on array grammars In the following, we give the necessary de nitions of ordered and programmed (graph controlled) array grammars and languages in the generating as well as in the accepting case. For detailed informations concerning these control mechanisms as well as many other interesting results about regulated rewriting in the theory of string languages, the reader is referred to [6]. De nition 4.1. An ordered (string) grammar is a construct GO = (VN ; VT ; (P; p is applicable to v: With `GO denoting the re exive and transitive closure of the derivation relation `GO the string language generated by GO is Lgen(GO ) = w 2 VT j S `GO w : A programmed (string) grammar (or graph controlled (string) grammar) with appearance checking is a construct GP = (VN ; VT ; (R; Li ; Lf ) ; S) ; VN and VT are disjoint alphabets of non-terminal and terminal symbols, respectively; S 2 VN is the start symbol; R is a nite set of rules r of the form (l (r) : p (l (r)) ; (l (r)) ; ' (l (r))) ; where l (r) 2 Lab (GP ) ; Lab (GP ) being a set of labels associated (in a one-to-one manner) to the rules r in R; p (l (r)) is a string production over VN [ VT ; (l (r)) Lab (GP ) is the success eld of the rule r; and ' (l (r)) is the failure eld of the rule r; Li Lab (GP ) is the set of initial labels, and Lf Lab (GP ) is the set of nal labels. For r = (l(r) : p (l (r)) ; (l (r)) ; ' (l (r))) and v; w 2 (VN [ VT ) we de ne (v; l (r)) `GP (w; k) if and only if { either p (l (r)) is applicable to v; the result of the application of the production p(l(r)) to v is w; and k 2 (l (r)) ; { or p (l (r)) is not applicable to v; w = v; and k 2 ' (l (r)) : The (string) language generated by GP is L (GP ) = fw 2 VT j (S; l0 ) `GP (w1;l1) `GP : : :(wk ; lk ) ; k 1; wj 2 (VN [ VT ) and lj 2 Lab (GP ) for 0 j k; wk = w; l0 2 Li ; lk 2 Lf g : If the failure elds ' (l (r)) are empty for all r 2 R; then GP is called a programmed grammar without appearance checking. If ' (l (r)) = (l (r)) for all r 2 R; then GP is called a programmed grammar with unconditional transfer. An ordered (string) grammar, or a programmed (string) grammar, respectively, is said to be of type enum; mon; cf; cf ? ; or reg; respectively, if every production appearing in this grammar is of the corresponding type, i.e.
an arbitrary, monotonic, context-free, -free context-free, respectively regular production. For the types X 2 fenum, mon, cf, cf ? , regg ; by L (gen; X) ; O (gen; X) ; Pac (gen; X) ; Put (gen; X) ; P (gen; X) ; we denote the -free (string) languages generated by grammars of type X and ordered grammars, programmed grammars with appearance checking, programmed grammars with unconditional transfer, and programmed grammars without appearance checking, respectively, of type X: In the following we list some of the most important results known [6,8,9,15] for the control mechanisms de ned above (for the sake of conciseness, we use U (X) instead of U (gen; X)):
{ { { { { {
L (X) = Y (X) for X 2 freg, mon, enumg and Y 2 fO; Pac; Put; P g ; L (cf ? ) $ P (cf ? ) $ Pac (cf ? ) $ L (mon) ; L (cf ? ) $ Put (cf ? ) Pac (cf ? ) $ L (mon) ; P (cf ? ) P (cf) $ Pac (cf) = L (enum) ; O (cf ? ) $ Put (cf ? ) $ Put (cf) Pac (cf) = L (enum) ; L (cf ? ) = L (cf) $ O (cf ? ) O (cf) $ Put (cf) L (enum) :
The de nitions of ordered grammars and graph controlled grammars can immediately be taken over for accepting (string) grammars as well as for generating and accepting array grammars by taking accepting string productions or generating and accepting array productions, respectively, instead of generating string productions in the de nitions given above, e.g. an ordered array grammar is a construct G = (n; VN ; VT ; #; (P;