Grammars Working on Layered Strings Paolo Bottoni
Department of Computer Science University of Rome \La Sapienza" Via Salaria 113, 00198 Roma, Italy
Giancarlo Mauri
Department of Computer Science University of Milano Via Comelico 39, 20135 Milano, Italy
Piero Mussio
Department of Electronics for Automation University of Brescia Via Branze 38, 25123 Brescia, Italy
Gheorghe Paun
Institute of Mathematics of the Romanian Academy PO Box 1 { 764, 70700 Bucuresti, Romania
Turku Centre for Computer Science TUCS Technical Report No 135 October 1997 ISBN 952-12-0087-1 ISSN 1239-1891
Abstract We consider rst an operation with strings and languages suggested by superposed windows on the computer screen (as well as by cryptographic systems of Richelieu type): we assume that the strings contain usual symbols as well as a transparent symbol. Superposing two strings (justi ed to left), we produce a new string consisting of the symbols visible from above. This operation is investigated as an abstract operation on strings, then it is used in building a variant of grammar systems with the component grammars working on the layers of an array of strings. Each grammar can rewrite only symbols in its layer which are visible from above. The language generated in this way consists of strings of the visible symbols, produced at the end of a derivation. The power of several variants of these generative mechanisms is investigated for the case of two layered strings. When a matrix-like control on the work of the component grammars is considered, then a characterization of recursively enumerable languages is obtained.
Keywords: regulated rewriting, grammar systems, visual languages, Chomsky hierarchy
TUCS Research Group
Mathematical Structures of Computer Science
1 Introduction Recent work in the study of algebraic features of pictorial languages has shown how a natural operation between pictures is that of superposition. This operation is informally understood as the placing of one image (which can contain some transparent symbols) above another, so that only pixels in the second image which appear immediately below transparent pixels in the rst image are observable and can contribute to the resulting image [2]. Actually, superposition of structures on the screen is continuously used in visual interactive systems. Consider for example windowing systems in which windows are allowed to overlap, as in the MacOsTM and WindowsTM operating systems. In these cases what is actually visible by a user results from the spatial relations among the windows currently on the screen. If one considers that each window contains a sentence in a language, the screen de nes a sentence which results from the superposition of several such partial sentences. The study of the characteristics of such languages, and hence of the properties of the superposition operation becomes interesting if one wants to avoid situations which may generate disorientation in the user [3]. The idea of employing transparency as a language-de ning tool predates the appearance of computers of a long time. It can be traced back to the Richelieu code, an elementary form of cryptography in which a message is embedded in a random text, and can be recovered by superposing the whole text by an opaque sheet with holes in it. The letters reading through the holes form the original message [1]. On the other hand, non transparent pixels are those on which the user can interact, hence are those from which the transformations of the current sentence may originate. This suggests a notion of control in which the activation of symbols in a rewriting process is possible only if such symbols are visible. Such a form of control appears to be very frequent in natural and arti cial systems, in all cases in which layers may be de ned and the development of a phenomenon depends on the characteristics both of the layer at which it occurs and of the above layers (e.g., rain permeability of a terrain, the growth of lms in VLSI chips; competition for light in chlorophylliac plants, radiology methods based on dierences in tissue absorbing properties, etc.). The notion of layer is also useful in de ning systems in which dierent agents may cooperate to de ne the evolution of a substrate. Dierent systems may have dierent roles and be allowed to operate only on parts left unde ned by prominent agents. A similar model was also at the basis of the proposal of Parallel Communicating Grammar Systems, where query symbols are used by a master agent to mark the places where other, speci ed, agents may contribute strings of unknown length [10]. In the notion of layered grammar proposed in this paper, instead, agents 1
can operate autonomously and independently, but their contribution to the nal result is limited to ll transparent \holes" left by an agent in an upper position. Which agent will contribute in which zones of the substrate to the nal result cannot be established a priori, depending on the ability of an agent to synchronize its activity with that of agents at an upper layer. Hence, two problems appear worth studying related to the notion of layer. First, what are the properties of the superposition operation and which properties and families of languages it preserves. Second, which is the expressive power of layers as a modelling tool. We start this study by considering closure properties of the operation and by exploring the generative power of context-free grammars with only two layers. It results that by such simple tools, more precisely by using layered right-linear grammars with a speci c form of synchronization, we can provide a characterization of recursively enumerable languages. Further study can be performed on the characteristics of systems with more than two layers and on an extension of the notion of transparency (for instance by considering symbols with dierent levels of opacity).
2 Formal language theory prerequisites In this section we recall only a few notions, notations, and results needed below. Further details can be found in [13] and in references therein. For an alphabet V , we denote by V the free monoid generated by V ; is the empty string, jxj is the length of x 2 V . The language of the non-empty strings over V , that is V ?fg, is denoted by V + . A morphism h : V ?! U such that h(a) 2 U [ fg for all a 2 V is called a weak coding; it is called a coding when h(a) 2 U for all a 2 V and a projection when h(a) 2 fa; g for all a 2 V . A string x 2 V can be seen as a mapping x : f1; 2; : : :; 1g ?! V [ f#g, where # is the blank symbol, with the following properties: there is i 1 such that x(i) = #; moreover, if x(j ) = #, then x(j + 1) = #; j 1 (this means that x(j ) 2 V for 1 j jxj and x(j ) = # otherwise). Sometimes, we shall use below such an interpretation of a string. A Chomsky grammar is a construct G = (N; T; S; P ), where N; T are disjoint alphabets, S 2 N , and P is a nite subset of (N [ T ) N (N [ T ) (N [ T ).The elements of N are called nonterminal symbols, those of T are called terminal symbols, S is the axiom, and the elements (u; v ) 2 P , written in the form u ! v , are called rewriting rules (for short, rules). The language generated by G is denoted L(G): When all rules in P are of the form A ! x; A 2 N; x 2 (N [ T ), then the grammar is said to be context-free; it is linear if x above contains at most one nonterminal symbol. A context-free grammar whose rules are of the forms A ! xB; A ! x, for A; B 2 N; x 2 T , is said to be right-linear; when x above is a 2
single symbol in T , then the grammar is said to be regular. We denote by FIN; REG; LIN; CF; CS; RE the families of nite, regular, linear, contextfree, context-sensitive, and recursively enumerable languages, respectively. For x; y 2 V , we de ne the shue of x; y by
x ?t y = fx1 y1 x2y2 : : :xn yn j n 1; x = x1x2 : : :xn; y = y1 y2 : : :yn ; xi; yi 2 V ; 1 i ng:
Convention. Two language generating mechanisms are considered equivalent if they generate languages which dier at most by the empty string.
3 The operation of superposition In what follows, t is always a special symbol, which is considered transparent. Let V be an alphabet. Two strings x; y 2 (V [ ftg) can be superposed, producing a third string z which is constructed as follows: 1. the shortest of x; y is completed to the right with occurrences of t such that two strings of the same length are obtained; let us denote by x0 ; y 0 the strings obtained in this way (at least one of them is not modi ed); 2. then, for i 1, we set 0 x0(i) 6= t, z(i) = yx0 ((ii));; ifotherwise. (Clearly, jz j = maxfjxj; jy jg.) We denote the string z by x y and we say that it is obtained bysuperposition of x and y . We can imagine that x y is obtained by writing the strings x; y one over the other, with x above, aligned to left, and looking from above to the \layered string" obtained in this way. Through transparent symbols we observe the corresponding symbols of y (maybe also the transparent symbol), otherwise we observe the symbols of x. For example, for
x = abttabt; ytabttbbabt; we obtain
x y = abbtabbabt; where the underlined symbols are taken from y . Obviously, the operation is associative, but not commutative. For L1 ; L2 (V [ ftg) we put L1 L2 = fx y j x 2 L1 ; y 2 L2g: 3
Note that every string from L1 is superposed with every string in L2 , irrespective of their length, because of the completion with occurrences of t of the shortest string in each pair. We now investigate the operation of superposition as an abstract operation on languages, relating it to other operations on languages. In this way, the closure properties of families in the Chomsky hierarchy under this new operation will be settled. Lemma 1. If F is a family of languages which is closed under superposition, shue with regular languages, weak codings, and intersection with regular languages,then it is closed under intersection. Proof. Consider two languages L1 ; L2 V : Denote V 0 = fa0 j a 2 V g and de ne the coding h2 : (V [ ftg) ?! (V 0 [ ftg) byh2 (a) = a0 ; a 2 V , and h2(t) = t, and the weak coding h1 : (V [ V 0) ?! V by h1(a0) = ; a0 2 V 0, and h1 (a) = a; a 2 V . Consider also the regular languages
R1 = fat j a 2 V g ; R2 = fta j a 2 V g ; R3 = faa0 j a 2 V g : Then the following equality holds
L1 \ L2 = h1((((L1 ?t t ) \ R1) h2 ((L2 ?t t ) \ R2)) \ R3): (The intersection with R1; R2 forces the shuing with t to pair symbols of strings in L1; L2 with symbols t, then the intersection with R3 selects only those strings coresponding to equal strings from L1; L2. Finally, the weak coding h1 discards symbols in V 0.) In view of the closure properties of the family F , it follows that F is
closed under intersection. Corollary 1. The families LIN, CF are not closed under superposition. Lemma 2. If F is a family of languages which is closed under intersection with regular languages, shue, codings, and inverse morphisms, then F is closed under superposition. Proof. Consider two languages L1 ; L2 (V [ ftg), denote as above V 0 = fa0 j a 2 V g, consider the new symbols c; c0; t0 and the new alphabet
U = f[ab0]; [at0]; [ac0]; [ca0]; [ta0] j a; b 2 V g [ f[tt0]; [cc0]; [ct0]; [tc0]g; and de ne the following morphisms:
h1 : U ?! V ; by h1 ([ab0]) = h1([at0 ]) = h1 ([ta0]) = h1 ([ca0]) = h1 ([ac0]) = a; 4
for a; b 2 V; and h1 ([tt0 ]) = h1([ct0]) = h1 (tc0 ]) = t; h2 : U ?! (V [ V 0 [ ft; t0; c; c0g); by h2 ([ ]) = ; for [ ] 2 U; h3 : (V [ ftg) ?! (V 0 [ ft0 g); by h3 (a) = a0 ; a 2 V; and h3 (t) = t0 : With the regular language
R = ((V [ ftg)(V 0 [ ft0 g))(((V [ ftg)fc0g) [ (fcg(V 0 [ ft0 g))) we obtain
L1 L2 = h1 (h?2 1 (((L1fcg) ?t (h3(L2 )fc0g )) \ R)): The intersection with R selects from the strings produced by shuing those strings which are obtained by interleaving the symbols of strings in L1; L2, maybe prolonged with occurrences of c; c0, but not containing super uous occurrences of c; c0; then, h?2 1 replaces blocks by symbols [ ] which are \interpreted" by h1 in the same way as when constructing the superposition of the two strings in L1 ; L2. The use of symbols c; c0 prevents the addition of super uous symbols t in the right end of strings. From the closure properties of F , we get L1 L2 2 F . Corollary 2. The families REG, CS, RE are closed under the superposition. Corollary 3. If F is a family of languages which is closed under intersection with regular languages, shue with regular languages, codings, and inverse morphisms, then F is closed under superposition with regular languages, in the following sense: if L1 2 F; L2 2 REG, then L1 L2 2 F and L2 L1 2 F . Proof. If one of the languages L1; L2 is regular, then in the proof above we use a shue with regular languages. The families LIN; CF are closed under shue with regular languages, hence they are closed under superposition with regular languages.
4 Grammars working on layered strings For two strings x; y 2 (V [ ftg) we denote by [x; y ] the two level sequence obtained by placing x over y , justi ed to left and completing the shortest string with occurrences of t; [x; y ] is called a layered string. Given a layered string [x; y ], any symbol x(i) 2 V is said to be visible. A symbol y (i) 2 V [ ftg is visible if and only if x(i) = t. Therefore, the visible symbols in [x; y ] correspond to the symbols appearing in the string x y de ned as in the previous section. We can now de ne the main notion investigated in this paper. 5
A layered grammar is a construct
= (N; T; t; (S1; P1); (S2; P2)); where N; T are disjoint alphabets, t is a special symbol not in N [ T ,S1; S2 2 N , and P1 ; P2 are nite sets of context-free rules over N [ T [ ftg (t is considered a terminal symbol); N is the nonterminal alphabet, T is the terminal alphabet, t is the transparent symbol, (Si; Pi ) are the components of the grammar; Si is the axiom and Pi is the set of rules of component i; i = 1; 2. We also say that (S1; P1) is the upper component and (S2 ; P2) is the lower component of . For x1; x2; y1; y2 2 (N [ T [ ftg) we write [x1 ; x2] =)s [y1 ; y2]if and only if both the following conditions hold: (1) x1 = x01 Ax001 ; y1 = x01 u1 x001 ; A ! u1 2 P1 ; or x1 = y1 2 (T [ ftg); (2) x2 = x02 Ax002 ; y2 = x02 u2 x002 ; A ! u2 2 P2 ; A is visible, or x2 = y2 and no nonterminal symbol is visible in x2: The relation =)s is called a synchronized derivation in : each component has to use a rule, except the case when the corresponding string is terminal, or, in the case of the lower component, no nonterminal is visible. Therefore, only the visible symbols of the lower level are active and can be rewriten. A variant of the relation =)s is =)ns , the nonsynchronized derivation step: for x1 ; x2; y1; y2 2 (N [ T [ ftg) we write [x1; x2] =)ns [y1; y2 ] if and only if one of the following cases holds: (1) x1 = x01 Ax001 ; y1 = x01 u1x001 ; A ! u1 2 P1 ; and x2 = y2 ; (2) x1 = y1 and either x2 = x02 Ax002 ; y2 = x02u2 x002 ; A ! u2 2 P2 ; A is visible, or x2 = y2 and no nonterminal symbol is visible in x2: Only one of the two components works, rewriting any symbol in the upper level andan visible symbol in the lower level. By rewriting rst in the lower level and then in the upper level we can simulate in this way a synchronized derivation. Thus, =)s is indeed a restricted version of =)ns . For any =) ; 2 fs; nsg we denote by =) its re exive and transitive closure. For each relation =) we can consider two languages associated to
, by considering two stop conditions for a derivation: when no nonterminal is allowed in the last layered string, we get
Lt;( ) = fz1 z2 2 (T [ ftg) j [S1; S2] =) [z1; z2]; z1; z2 2 (T [ ftg)g: 6
When we allow nishing the derivation with non-visible nonterminal symbols in the lower level, then we get
Lnt;( ) = fz1 z2 2 (T [ ftg) j [S1; S2] =) [z1; z2]; z1 2 (T [ ftg); z2 2 (N [ T [ ftg); but no nonterminal in z2 is visibleg: In both cases, 2 fs; nsg. In this way, we associate with four languages, Lt;s ( ); Lt;ns( ); Lnt;s( ); Lnt;ns( ). We denote by TSL(X ); TNSL(X ); NTSL(X ); NTNSL(X ) the families of languages of these types generated by layered grammars with rules of type X ; for X we consider here REG; RL; LIN; CF (regular, right-linear, linear, context-free, respectively); we do not distinguish between grammars allowed to contain -rules and -free grammars (that is, we allow erasing rules). In the proofs in the following section we shall present several speci c layered grammars, hence we do not give here examples.
5 Preliminary results Directly from the de nitions, we obtain Lemma 3. Y L(REG) Y L(RL) Y L(LIN ) Y L(CF ); for all Y 2 fTS, TNS, NTS, NTNSg. By adding to each set P1 ; P2 rules A ! A for each A 2 N , we can simulate a non-synchronized derivation by a synchronized one, hence we get Lemma 4. TNSL(X ) TSL(X ); NTNSL(X ) NTSL(X ), for each X 2 fRL, LIN, CFg. (The use of chain rules is important here. We shall see below that layered grammars with regular rules generate only regular languages, both in the synchronized and the non-synchronized modes, hence the result above holds in this indirect way also for the regular case.) Lemma 5. X Y L(X ), for all X 2 fREG, RL, LIN, CFg,Y 2 fTS, TNS, NTS, NTNSg. Proof. For a usual grammar G = (N; T; S; P ) we construct the layered grammar
= (N [ fS1g; T; t; (S1; fS1 ! tg); (S; P )): Because the upper component generates only one transparent symbol and then stops, we obviously obtain Lt; ( ) = Lnt;( ) = L(G); 2 fs; nsg. Lemma 6. For all context-free languages L1; L2 (T [ ftg) there are a weak coding h, a regular language R, and a layered context-free grammar such that L1 L2 = h(Lt;ns ( ) \ R): 7
Proof. Let Gi = (Ni ; T [ftg; Si; Pi) be two context-free grammars such that Li = L(Gi); i = 1; 2. We construct the layered grammar
= (N 0; T 0; t; (S10 ; P10 ); (S20 ; P20 )); with
N 0 = N1 [ N2 [ fS10 ; S20 ; Ag; T 0 = T [ fc1; c2; t0g; P10 = fS10 ! tS10 ; S10 ! c1S1g [ P1 ; P20 = fS20 ! AS2; A ! t0 A; A ! c2 tg [ P2 : Consider also the weak coding h : T 0 ?! (T [ ftg) de ned by h(a) = a; a 2 T ,h(t0 ) = h(c1) = h(c2) = , as well as the regular language
R = ft0 g fc2c1g(T [ ftg): We obtain the equality L1 L2 = h(Lt;ns ( ) \ R): Indeed, the derivations in leading to strings in R are equivalent (modulo the orders of some steps) to a derivation of the following form: [S10 ; S20 ] =)ns =)ns =)ns =)ns
[tn S10 ; S20 ] =)ns [tn c1 S1; S20 ]; for n 1; [tn c1 w1; S20 ]; for w1 2 L1 ; [tn c1 w1; AS2] =)ns [tn c1 w1; Aw2]; for w2 2 L2 ; jw2j n; [tn c1 w1; t0n?1 c2tw2 ]:
Clearly, (tn c1 w1) (t0n?1 c2 w2) = t0n?1 c2c1 (w1 w2).With the weak coding h, we obtain the string w1 w2. Corollary 4. TNSL(CF ) ? CF 6= ;, TSL(CF ) ? CF 6= ;: Proof. The family CF is not closed under the operation , but it is closed under intersection with regular languages and arbitrary morphisms. Moreover, TNSL(CF ) TSL(CF ) (Lemma 4). We shall strenghten this result in the following section.
6 The power of layered grammars First, we show that all families of languages generated by layered grammars with linear rules can generate non-context-free languages. (Note that this does not follow from the proof of Lemma 6, because we use the non-linear rule S20 ! AS2 in P20 .) Theorem 1. Y L(LIN ) ? CF 6= ;; Y 2 fTS; TNS; NTS; NTNS g: 8
Proof. Let us consider the following layered grammar
= (fS1; S10 ; S100; S2; S20 g; fa; b; c; d; eg; t; (S1; P1); (S2; P2)); P1 = fS1 ! tS10 ; S10 ! S100d; S100 ! aS100t; S100 ! etg; P2 = fS2 ! ttS2 ; S2 ! tS2 ; S2 ! dS20 ; S20 ! bS20 c; S20 ! teg: A non-synchronized derivation in is equivalent (modulo the order of some steps) to a derivation of the following form. After using the rule S1 ! tS10 in the upper layer, the rule S2 ! ttS2 must be used in the lower one in order to \get free" this component: [S1; S2] =)ns [tS10 ; S2] =)ns [tS10 ; ttS2 ]: In the second component we can derive freely: [tS10 ; ttS2 ] =)ns [tS10 ; tmS2 ]; for m 2; =)ns [tS10 ; tm dS20 ] =)ns [tS10 ; tm dbnS20 cn ]; for n 0; =)ns [tS10 ; tm dbn tecn ]: At any time, we can also start deriving in the upper component, where a stringtar ettr d; r 0, can be produced. If we consider also the regular language R = ta+ edb+dec+ ; and we look only for strings in Lt;ns ( )\R, then we have to stop by producing a layered string [tar ettr d; tmdbn tecn ]; such that r + 2 = m; r = n. Therefore, the obtained string is (tar ettr d) (tm dbn tecn ) = tan edbn decn : Consequently,
Lt;ns ( ) \ R = ftanedbndecn j n 0g;
which is not a context-free language. Because the intersection with R asks for having the terminal rule S20 ! te used, we have Lt;ns ( ) \ R = Lnt;ns ( ) \ R. Therefore, TNSL(LIN ) ? CF 6= ;; NTNSL(LIN ) ? CF 6= ;. With Lemma 4, also TSL(LIN ) ? CF 6= ;; NTSL(LIN ) ? CF 6= ;: We consider now the case of right-linear layered grammars. When they work in the synchronized mode, they can generate non-regular languages. (However, we do not know whether or not also non-context-free languages can be generated in this way.) Theorem 2. NTSL(RL) ? REG 6= ;: 9
Proof. Let us consider the layered grammar
= (fS1; S10 ; S2g; fa; bg; t; (S1; P1); (S2; P2)); P1 = fS1 ! tS1; S1 ! b4S10 ; S10 ! b4 S10 ; S10 ! b4g; P2 = fS2 ! a3 S2 g: The idea behind this construction is the following. For a while, the upper component, using the rule S1 ! tS1 , runs slowly, then it \accelerates" by using rules which introduce four occurrences of the symbol b. When the upper component catches up the lower one, this latter component will stop, because its nonterminal is no longer visible. Therefore, the derivations in proceed as follows: [S1; S2] =)s [tS1 ; S2] =)s [ttS1 ; a3S2 ] =)s [ttn S1 ; a3nS2 ]; for n 0; =)s [ttn b4 S10 ; a3na3 S2 ] =)s [ttn b4m S10 ; a3n a3m S2]; for m 0: () If S2 is covered by a symbol b or by S10 , then from that moment on only the upper component can work, an arbitrary number of steps: =)s [ttn b4mb4s ; a3na3m S2 ]; for s 1: The fact that S2 is not visible in () means n + 1 + 4m + 1 3(n + m) + 1; which implies m 2n ? 1: Therefore, Lnt;s ( ) = fan+1 b4(m+s) j n 0; s 0; m 2n ? 1g: This is not a regular language (by pumping symbols a we can get a string of the form ap bq with p > q , which are not in L). The case of terminal derivations is more dicult, because by removing the nonterminal of a right-linear grammar working in the lower layer of a layered grammar, the work of the lower component can stop, a fact which can remove the eect of the synchronization. Theorem 3. TSL(RL) ? REG 6= ;: Proof. Consider the layered grammar
= (fS1; S10 ; S2g; fa; b; c; dg; t; (S1; P1); (S2; P2)); P1 = fS1 ! tS1 ; S1 ! b2tb2 S10 ; S10 ! b2tb2 S10 ; S10 ! b2 tcg; P2 = fS2 ! a3 S2; S2 ! a3 dg;
10
as well as the regular language
R = a+(bbabb)+bbdc: In order that a terminal synchronized derivation in will produce a string in R, it has to proceed as follows. After the rst step, S2 is visible; it runs faster than S1 as long as the upper component uses the rule S1 ! tS1 ;after starting to use another rule, the upper component runs faster and eventually it catches up the lower one. This must indeed happen when looking for strings in R, because we must obtain a string containing both the symbol c (introduced by the upper component) and the symbol d (introduced by the lower component), in neighboring positions. Thus, we have to follow derivations of the form [S1; S2] =)s [tS1 ; S2] =)s [ttn S1; a3n S2] for n 0; =)s [ttn bbtbbS10 ; a3n a3S2 ] =)s [ttn (bbtbb)mS10 ; a3na3m S2 ]; for m 0: The second component can stop in any moment, but the upper one must derive until catching up (in order to produce the substring dc). Therefore, we have to produce a layered string of the form =)s [ttn (bbtbb)pbbtc; a3kd]; such that
n + 1 + 5p + 3 = 3k + 1 (in order to have d adjacent to c) and k n + p:
(1) (2)
These relations easily imply 2p + 3 2n:
(3)
Consequently, we get
Lt;s( ) \ R = fan+1 (bbabb)pbbdc j n 0; 2n 2p + 3g: The intersection Lts ( ) \ R is in nite. More precisely, this intersection contains strings an+1 (bbabb)pbbdc with arbitrarily large p: considerthe values
n = 3s + 3; p = 3s; k = 6s + 2; for any integer s 1. All conditions (1), (2), and (3) are ful lled, hence the stringsa3s+3+1 (bbabb)3sbbdc are in Lt;s ( ) \ R for all s 1. This means 11
that Lt;s ( ) \ R (hence Lt;s ( ), too) is not a regular language: by pumping a substring of the sux (bbabb)3sbbdc we get strings no tin Lt;s ( ) \ R. The synchronization is essential in the result above: Theorem 4. TNSL(RL) REG; NTNSL(RL) REG. Proof. Consider the layered grammar = (N; T; t; (S1; P1); (S2; P2)) and examine the derivations performed in the terminal non-synchronized mode. In each layer there is one nonterminal only, which moves from left to right. If the lower nonterminal is behind the upper one, then the derivation in the lower level depends on the transparent symbols in the upper layer (the lower level is blocked if its nonterminal is placed under a terminal symbol in the upper level). If the lower nonterminal goes ahead the upper one, then no restriction on the derivation is imposed. The two nonterminals can work freely, but the result is obtained by superposition. Because of the nonsynchronization, we can apply a rule in any of the two layers. Therefore, (1) only the relative position of the two nonterminals is important, and (2) as long as both nonterminals are present we can keep them at a bounded distance, just applying rules to that nonterminal which is behind, such that the relative position is not changed. The distance between the two nonterminals can be bounded by 2m, where
m = maxfjuj j A ! u 2 P1 [ P2 g: Therefore, the work of can be controlled by a \window" of length at most 2m. Initially, this is [S1; S2], it possibly grows to some [w1; w2] with jw1j = jw2j = 2m, and continues in this way until ending the derivation in one component; after that, only one nonterminal is enough to control the derivation. Formally, we construct the right-linear grammar
G = (N 0; T; S; P ) with
N 0 = f(w1; w2) j w1 2 T (N [ fg); w2 2 T (N [ fg); 1 jw1j; jw2j 2m; at least one of w1; w2 contains a nonterminalg [ fS g [ f(A; #); (#; A) j A 2 N g; and the following rules: 1. S ! (S1 ; S2); 2. (u1 tu2 A1 ; u3A2) ! (u1tu2 v1 B1 ; u3A2 ), for u1 ; u2; u3; v1 2 (T [ ftg); ju1j = ju3j; A1 ! v1B1 2 P1; ju1tu2v1B1j 2m; 3. (u1 tu2 A1 ; u3A2) ! (u1tu02 tu002 A1 ; u3v2 B2 ), for u1 ; u2; u3; v2 2 (T [ ftg); 12
u2 = u02 tu002 ; ju1 j = ju3j; ju1tu02 j = ju3v2 j; A2 ! v2 B2 2 P2 ; ju1tu2A1j 2m;
(We derive in one layer, without growing the strings over the threshold 2m.)
4. (u1tu2 A1; u3A2 ) ! x(u001 tu2 v1B1 ; u003 A2 ), for u1; u2; u3; v1 2 (T [ ftg); ju1j = ju3j; A1 ! v1B1 2 P1; ju001tu2v1B1j = 2m; u1 = u01u001 ; u3 = u03u003 ; ju01j = ju03j; x = u01 u03; (We change the window when deriving in the upper layer. After that, using rules in group 3, we can keep close in the second layer.) 5. (u1tu2 A1; u3A2 ) ! (u1 tu2 A1 ; u3v2 ); for u1; u2; u3; v2 2 (T [ ftg); ju1j = ju3j; A2 ! v2 2 P2; ju3v2j ju1tu2A1j 2m; (We nish the derivation in the second layer.) 6. (u1A; u2) ! x(A; #), for u1; u2 2 (T [ ftg); ju1Aj 2m; x = u1 u2 ; 7. (A; #) ! x(B; #), for A ! xB 2 P1 ; x 2 (T [ ftg) ; 8. (A; #) ! x, for A ! x 2 P1 ; x 2 (T [ ftg); (We derive freely in the upper layer.) 9. (u1tu2 A1; u3A2 ) ! (u1 tu2 v1 ; u3A2 ); for u1; u2; u3; v1 2 (T [ ftg); ju1j = ju3j; A1 ! v1 2 P1; ju1tu2v1j 2m; 10. (u1tu2 A1; u3A2 ) ! x(u001 tu2 v1; u003 A2 ); for u1; u2; u3; v1 2 (T [ ftg); ju1j = ju3j; u1 = u01u001 ; u3 = u03u003 ; ju01j = ju03j; x = u01 u03; ju001 tu2v1j = 2m; A1 ! v1 2 P1; (We end the derivation in the upper layer.) 11. (u1tu2 ; u3A2 ) ! (u1tu02 tu002 ; u3v2 B2 ); for u1 ; u2; u3; v2 2 (T [ ftg); ju1j = ju3j; u2 = u02tu002 ; ju1tu02j = ju3v2j; ju1tu2j 2m; A2 ! v2B2 2 P2; 12. (u1tu2 ; u3A2 ) ! x(#; B2); for u1 ; u2; u3 2 (T [ ftg) ; ju1j = ju3j; ju1tu2j ju3v2j; x = u1tu2 u3v2; A2 ! v2B2 2 P2; (We continue deriving in the lower layer.) 13. (#; A2) ! x(#; B2); for A2 ! xB2 2 P2 ; x 2 (T [ ftg); 14. (#; A2) ! x, for A2 ! x 2 P2 ; x 2 (T [ ftg); (We derive freely in the lower layer.) 15. (u1tu2 A1; u3A2 ) ! (u1 tu2 A1 ; u3v2 B2 ); for u1 ; u2; u3; v2 2 (T [ ftg); ju1j = ju3j; ju1tu2A1j ju3v2j < 2m; A2 ! v2B2 2 P2; (The nonterminal in the lower level goes ahead the nonterminal in the upper layer.) 13
16. (u1 tu2 A1 ; u3A2) ! x(u001 tu2 A1 ; u003 v2 B2 ); for u1 ; u2; u3; v2 2 (T [ ftg); ju1j = ju3j; u1 = u01u001 ; u3 = u03u003 ; ju01j = ju03j; x = u01 u03; A2 ! v2B2 2 P2 ; ju001tu2A1 j < ju003 v2 B2j = 2m; (Idem, but the lower string is of length greater than 2m.) 17. (u1 A1; u2A2 ) ! (u1v1 B1 ; u2A2 ); for u1; u2; v1 2 (T [ ftg); ju1v1 B1 j < ju2A2j 2m; A1 ! v1B1 2 P1; 18. (u1 A1; u2A2 ) ! (u1A1 ; u2v2 B2 ); for u1 ; u2; v2 2 (T [ ftg); ju1A1 j < ju2v2B2 j 2m; A2 ! v2B2 2 P2; 19. (u1 A1; u2A2 ) ! x(u001 A1 ; u002 v2B2 ), for u1 ; u2; v2 2 (T [ ftg) ; u1 = u01 u001 ; u2 = u02u002 ; ju01 j = ju02j; x = u01 u02; ju001A1 j < ju002 v2B2 j = 2m; A2 ! v 2 B2 2 P 2 ; (We derive freely in the two layers.) 20. (u1 A1; u2A2 ) ! (u1 A1; u2v2 ); for u1 ; u2; v2 2 (T [ ftg) ; ju1A1 j < ju2v2j 2m; A2 ! v2 2 P2; 21. (u1 A1; u2A2 ) ! x(u001 A1 ; u002 v2), for u1 ; u2; v2 2 (T [ ftg); u1 = u01u001 ; u2 = u02u002 ; ju01 j = ju02j; x = u01 u02; ju001 A1 j < ju002 v2 j = 2m; A2 ! v 2 2 P2 ; (We stop in the lower layer.) 22. (u1 A1; u2) ! (u1v1 B1 ; u2); for u1 ; u2; v1 2 (T [ftg); ju1v1 B1 j < ju2j 2m; A1 ! v1 B1 2 P1 ; 23. (u1 A1; u2) ! x(B1 ; #), for u1; u2; v1 2 (T [ ftg); x = (u1v1 ) u2 ; A1 ! v 1 B1 2 P 1 ; 24. (u1 A1; u2) ! x; for u1 ; u2; v1 2 (T [ ftg) ; x = (u1 v1 ) u2 ; A1 ! v 1 2 P1 ; (The rst layer continues, possibly also nishes working.) 25. (u1 A1; u2A2 ) ! (u1v1 ; u2A2); for u1; u2; v1 2 (T [ ftg); ju1v1j < ju2A2j 2m; A1 ! v1 2 P1; (We stop in the upper layer.) 26. (u1 ; u2A2) ! x(#; B2), for u1; u2; v2 2 (T [ ftg); x = u1 (u2v2 );
A2 ! v 2 B2 2 P 2 :
We obviously obtain L(G) = Lt;ns ( ). This proves the inclusion TNSL(RL) REG. For the non-terminal case we can nish the derivation with the lower nonterminal placed under a symbol dierent from t. The
necessary modi cations are left to the reader. Theorems 2, 3 cannot be improved by replacing RL by REG: even synchronized, layered grammars with regular components can generate only regular 14
languages.
Theorem 5. TSL(REG) REG; NTSL(REG) REG:
Proof. Let us consider a layered grammar = (N; T; t; (S1; P1); (S2; P2)) with the sets P1 ; P2 containing regular rules. Because the work of is synchronized, whenever the nonterminal in the lower level is visible, it has to be rewritten. At the rst step, when the upper level uses a rule dierent from A ! tB ,A ! t (that is a terminal in T is introduced), this will cover the nonterminal in the lower level, hence it is no longer rewritten. Thus, the derivation of starts by a number of steps of using rules of the form A ! tB (this number may be zero). Synchronously, the lower level nonterminal advances, one step behind the nonterminal in the upper level, at any step it can be replaced by a terminal, and this ends the derivation in the lower level. When the upper level introduced asymbol in T , the lower one should use a terminal rule in the case of terminal derivation, or any rule in the case of non-terminal derivation and it stops. The upper level can continue without any restriction. To sum up, a window of length two suces in order to control the work of in a way similar to that in the proof of Theorem 4. Consequently, Lt;s ( ) 2 REG; Lnt;s( ) 2 REG. Corollary 5. Y L(REG) = REG for all Y 2 fTS; TNS; NTS; NTNS g. Proof. Combine Lemma 5 (it gives the inclusion ) with Theorem 4 (the converse inclusion for the non-synchronized case) and Theorem 5 (the converse inclusion for the synchronized case). Thus, the regular layered grammars need no further investigation (in what concerns the generative capacity). The results above deserve to be emphasized: in the synchronized case, the regular rules are strictly less powerful than right-linear rules. This does not happen in many situations in formal language theory (for instance, in regulated rewriting area, [6]). However, a similar result has been recently proved for parallel communication grammar systems: in the centralized returning case, the regular rules are strictly weaker than the right-linear rules [7].
7 A characterization of RE languages We increase now the degree of synchronization in a layered grammar, by specifying the pair of rules to be used by the two components, at steps when both of them have visible nonterminals. A matrix layered grammar is a construct
= (N; T; t; S1; S2; M ); where N; T; t; S1; S2 are as in a usual layered grammar (the nonterminal and the terminal alphabet, the transparent symbol, the axioms of the two layers, 15
respectively), and M is a nite set of pairs (we call them matrices) of the forms (A1 ! u1; A2 ! u2 ); (A1 ! u1 ; #); (#; A2 ! u2 ); where A1 ! u1 ; A2 ! u2 are context-free rules over N [ T [ ftg. In a derivation step [x1; x2] ! [y1; y2 ] we have to use a pair (A1 ! u1 ; A2 ! u2) if both x1 and x2 contain visible nonterminals (hence x1 = x01 A1 x001 ; y1 = x01u1 x001 ; x2 = x02A2 x002 ; y2 = x02 u2x002 ), a pair (A1 ! u1; #) if x2 contains no visible nonterminal and A1 appears in x1 (hence x1 = x01 A1 x001 ; y1 = x01u1 x001 ; x2 = y2 ), and a pair (#; A2 ! u2 ) if x1 is a terminal string and A2 is an visible nonterminal in x2 (hence x1 = y1 ; x2 = x02A2 x002 ; y2 = x02 u2x002 ). We denote by Lt( ) the language generated by in the terminal mode and by Lnt ( ) the language generated by in the non-terminal mode. The corresponding families of languages are denoted by TML(X ); NTML(X ); X 2
fREG; RL; LIN; CF g:
Rather surprisingly, the following characterization of recursively enumerable languages can be obtained. Theorem 6. For every language L 2 RE there are a weak coding h, a regular language R, and a language L0 2 TML(RL) \ NTML(RL) such that L = h(L0 \ R): Proof. We use the following variant (proved in [9]) of the characterization of recursively enumerable languages by means of equality sets of morphisms (see [5], [14], [15]). For two morphisms h1 ; h2 : V ?! U we denote
EQ(h1; h2) = fw 2 V j h1(w) = h2(w)g: For every language L 2 RE; L V , there are two alphabets V1; V2 such that V V2 ,two -free morphisms h1 ; h2 : V1 ?! V2, a regular set R V2, and a projection h3 : V2 ?! V , such that L = h3 (h1(EQ(h1; h2)) \ R). Consider also the alphabet V20 = fa0 j a 2 V2 g. We now construct the matrix layered grammar
= (fS1; S10 ; S2g; V2 [ V20 [ fc; dg; t; S1; S2; M );
with the following matrices of rules: (1) (S1 ! tS10 ; #); (2) (S10 ! tbi1 tbi2 : : :tbik tS10 ; S2 ! b0j1 tb0j2 t : : :tb0jl tS2 ); (3) (S10 ! tbi1 tbi2 : : :tbik td; S2 ! b0j1 tb0j2 t : : :tb0jl tc); for h1 (a) = bi1 bi2 : : :bik ; k 1; bis 2 V2; 1 s k; and h2 (a) = b0j1 b0j2 : : :b0jl ; l 1; b0js 2 V20 ; 1 s l: Consider also the regular language
R0 = fb0b j b 2 V2gfcdg 16
and the weak coding g : (V2 [ V20 ) ! V2 de ned by g (b) = b; b 2 V2, and g(b0) = ; b0 2 V20. It is easy to see that we have
g(Lt( ) \ R0) = g(Lnt( ) \ R0) = h1 (EQ(h1; h2)): Indeed, because the upper component introduces the symbol t in each odd
position and the nonterminal of the lower component appears always in an odd position, the non-terminal derivations should be terminal. Moreover, the intersection with R0 ensures the fact that we end in the two layers with two identical strings modulo the primes appearing in the lower layer, namely the two strings correspond to some h1 (w1) = h2 (w2); the matrices in M ensure the fact that w1 = w2: after using the matrix of type 1, always S2 is visible, and the two components should stop at the same time, by using a matrix of type (3). Now, let us consider the morphism h : V2 ?! (V2 [ V20 ) de ned by h(b) = b0b; b 2 V2 , the regular language R0 = h(R)cd, and extend the weak coding h3 to h03 : (V2 [ V20 ) ! V by h03 (b) = h3 (b); b 2 V2 , and h03(b0) = ; b0 2 V20 , h03(c) = h03(d) = . Then we have
L = h03(Lt( ) \ h(R)) = h03(Lnt ( ) \ h(R)): Indeed, R0 plays at the same time the roles of both R and R0, while h03 plays at the same time the roles of h3 and g . Corollary 6. For every family of languages F RE which is closed under intersection with regular languages and weak codings we have TML(RL) ? F= 6 ;; NTML(RL) ? F = 6 ;: Proof. An inclusion TML(RL) F; NTML(RL) F would imply that the closure of TML(RL); NTML(RL) under intersection with regular languages and weak codings is included into the closure of F under these operations. This implies the inclusion RE F , contradicting the strict inclusion F RE . Important families F as above are MAT , of languages generated by matrix grammars with arbitrary context-free rules but without appearance checking, and ET 0L, the family of languages generated by extended tabled interactionless Lindenmayer systems, [12]. The proof of Theorem 5 remains valid also for matrix layered grammars, that is the next result holds: Theorem 7. TML(REG) = NTML(REG) = REG:
8 Final remarks; variants Several variants of layered grammars can be naturally de ned. We only mention some of them as a proof of the richness of this notion. First, as it is the case with the icons visible in windows superposed on the computer 17
screen, we can assume that some nonterminals are \more active" than others. When several nonterminals are visible, the \most active" of them is rewritten. This idea can be implemented, for instance, under the form of a partial order relation on the nonterminal alphabet of the grammar, or under the form of a leftmost restriction on the derivation (the rst visible nonterminal from the left of the layer should be rewritten). Note that in the case of linear grammars (hence also of right-linear and regular grammars) these variants coincide with the one investigated here, hence all Theorems 1 { 7 from the previous sections remain true also for these variants. Second, we can consider a variant which removes the apparent contrast between the parallel character of activating symbols by visibility and the sequential mode of rewriting. That is, it is quite natural to derive all visible symbols at the same time. This leads to considering parallel derivations, either in a context-free grammar as here (this reminds the so-called Indian and Russian parallel grammars in regulated rewriting area, see [6]), or in a pure grammar, where there is no distinction between terminal and nonterminal symbols (this corresponds to Lindenmayer systems; in particular, layered 0L or D0L systems look attractive). Third, we can consider layered grammars of any order, not only with two levels as we have done here. The de nition of visibility can be obviously extended to n-layered strings; similarly the de nition of a layered grammar of degree n; n 1, is an obvious extension of the de nition here. Such systems will probably have a rather intricate behavior. They correspond in a better way to a parallel grammar system, with a particular type of cooperation among components: they work synchronously, on their separate sentential forms (this is similar to a parallel communication grammar system, [10], [4]), but they do not communicate by sending messages, rather they just in uence each other through visible symbols; however, the result is highly integrated: it is the superposition (in the sense of the operation , extended ton-layered strings) of the strings generated by the component grammars. Then, usual derivation, leftmost, parallel derivations can be considered also in this case. Of course, such a system with n layers can be simulated by a system with n + 1 layers (just add a component which contains only the rule S ! t).Whether or not the systems of degree n + 1 are strictly more powerful than those of degree n becomes a fundamental problem (in general, not solved in grammar systems area, [4]). By the various motivations of the model, by the results given here (especially the possibility of generating non-regular languages by layered grammars with right-linear rules and the characterization of recursively enumerable languages by matrix layered grammars with rules of the same type|right-linear), and by the wealth of problem raised by the variants mentioned above, the layered grammars prove to be a research area of de nite interest. 18
References [1] M. Andrasiu, J. Dassow, Gh. Paun, A. Salomaa, Language-theoretic problems arising from Richelieu cryptosystems, Theor. Comput. Sci., 116 (1993), 339 { 357. [2] P. Bottoni, M. F. Costabile, S. Levialdi, P. Mussio, De ning visual languages for interactive computing, IEEE Transactions on Systems, Man, and Cybernetics, 1997 (to appear). [3] P. Bottoni, M. F. Costabile, S. Levialdi, P. Mussio, Speci cation of Visual Languages as Means for Interaction, Theory of Visual Languages, K. Marriott, B. Meyer eds., Springer-Verlag, 1997, to appear. [4] E. Csuhaj-Varju, J. Dassow, J. Kelemen, Gh. Paun, Grammar Systems. A Grammatical Approach to Distribution and Cooperation,Gordon and Breach, London, 1994. [5] K. Culik II, A purely homomorphic characterization of recursively enumerable sets,Journal of the ACM, 26 (1979), 345 { 350. [6] J. Dassow, Gh. Paun, Regulated Rewriting in Formal Language Theory, Springer-Verlag, Berlin, Heidelberg, 1989. [7] S. Dumitrescu, Gh. Paun, On the power of parallel communicating grammar systems with right-linear components, Rev. Fr. Aut. Inform. Theor., RAIRO,in press. [8] D. Hauschild, M. Jantzen, Petri nets algorithms in the theory of matrix grammars, Acta Inform., 31 (1994), 719 { 728. [9] L. Kari, Gh. Paun, G. Rozenberg, A. Salomaa, S. Yu, DNA computing, sticker systems, and universality, Acta Informatica, to appear. [10] Gh. Paun, L. S^antean, Parallel communicating grammar systems: the regular case, Ann. Univ. Buc., Matem.-Inform. Series, 38, 2(1989), 55 { 63. [11] D. J. Rosenkrantz, Programmed grammars and classes of formal languages, Journal of the ACM, 16 (1969), 107 { 131. [12] G. Rozenberg, A. Salomaa, The Mathematical Theory of L Systems, Academic Press, 1980. [13] G. Rozenberg, A. Salomaa, Eds., Handbook of Formal Languages, 3 volumes, Springer-Verlag, Heidelberg, 1997. [14] A. Salomaa, Equality sets for homomorphisms of free monoids,Acta Cybernetica, 4 (1978) 127-139. 19
[15] A. Salomaa, Jewels of Formal Language Theory, Computer Science Press, Rockville, Maryland, 1981.
20
Turku Centre for Computer Science Lemminkaisenkatu 14 FIN-20520 Turku Finland http://www.tucs.abo.
University of Turku Department of Mathematical Sciences
Abo Akademi University Department of Computer Science Institute for Advanced Management Systems Research
Turku School of Economics and Business Administration Institute of Information Systems Science