Generalized Stream X-machines and Cooperating Distributed ...

2 downloads 0 Views 229KB Size Report
Thus for
Generalized Stream X- machines and Cooperating Distributed Grammar Systems Marian Gheorghe

Faculty of Sciences, Pitesti University Str. Targu din Vale Pitesti, Romania, email: [email protected]

Abstract. Stream X- machines are a general and powerful computational model.

By coupling the control structure of a stream X- machine with a set of formal grammars a new machine called generalized stream X- machine with underlying distributed grammars, acting as a translator, is obtained. By introducing this new mechanism a hierarchy of computational models is provided. If the grammars are of a particular class, say regular or context-free, then nite sets are translated into nite sets, when k = k derivation strategies are used, and regular or context-free sets, respectively, are obtained for  k  and terminal derivation strategies. In both cases, regular or context-free grammars, the regular sets are translated into non context-free languages. Moreover, any language accepted by a Turing machine may be written as a translation of a regular set performed by a generalized stream X- machine with underlying distributed grammars based on context-free rules, under = k derivation strategy. On the other hand the languages generated by some classes of cooperating distributed grammar systems may be obtained as images of regular sets through some X- machines with underlying distributed grammars. Other relations of the families of languages computed by generalized stream X- machines with the families of languages generated by cooperating distributed grammar systems are established. At the end, an example dealing with the specication of a scanner system illustrates the use of the introduced mechanism as a formal specication model. Keywords: generalized stream X- machines, formal grammars, cooperating distributed grammar systems, Turing machines, computational models

1 Introduction Introduced by Eilenberg in 1974, 6], X- machines have received little further study. Holcombe,

7], proposed the model as a basis for a possible specication language and since then a number of further investigations have demonstrated that this idea is of great potential value for software engineers. In its essence an X- machine is like a nite state machine but with one important di erence. A basic data set X , is identied together with a set of basic processing functions , which operate on X . Each arrow in the nite state machine diagram is then labelled by a function from . These functions are applied on an input data from X in order to obtain an output data from the same set X and they are chosen according to the state transition given by the nite automaton. This method allows the control state of the system to be easily separated from the data set. Usually, the data set X contains information about the internal memory of a system, often an array consisting of elds that dene internal structures such as registers, stacks, database lestores, input information from various devices, models of screen displays and other output mechanisms. 1

A special case of an X- machine is a stream X- machine which is like a pushdown machine with output except that the stack structure can be arbitrary with a variety of functions that can be dened to access it. This has proved to be a powerful vehicle for exploring issues of computability (see 11]). It contains a nite set of states Q, an input set  and an output set A as with a nite state machine. There is also an internal memory set M which can take any convenient form. Given a start state and an initial value for the memory, the machine processes as follows:  reads an input symbol from the input tape  moves to a new state  updates the memory  outputs some suitable value. The machine has an initial state and an initial memory value. It works on an input stream until this one is entirely scanned. A nite state machine may be recovered by making the memory a trivial one and excluding the outputs. The strength of the X- machine approach is that the basic functions that label (and are triggered by) the transitions, can be very general. In 11] the case where the components of the set of basic functions  are push and pop operations is considered. The conclusion being that they are not powerful enough and consequently more complex ones are required to be used 11]. As an example, the case is considered where the set  contains functions computed by machines which are already known. Finite state machines are used instead of simple push and pop operations 11]. It is a natural step to consider the situation whereby these transitions activate sets of regular production rules (regular grammars) 3], the generative counterpart of the nite state machine models 10]. Hence, instead of the arc function carrying out a computation when triggered, the corresponding set of rules is applied in order to generate a sentential form, under a suitable derivation strategy. From this sentential form both an output value and a memory value are extracted. We can then ask what sorts of languages can be accepted by these systems called generalized stream X- machines with underlying distributed grammars, when rules of a certain type are used. Thus for k and = k derivation strategies (the number of derivation steps, in each component, is at most k or it is equal to k, respectively), a generalized stream X machine with underlying distributed grammars translates a nite set of strings into another nite set 3]. For  (an arbitrary number of derivation steps in each component),  k (at least k derivation steps in each component) and for terminal (in every component the derivation ends when no more steps are possible) derivation strategies, nite sets are translated into a family of languages strictly included in the family of regular languages 3]. When these mechanisms based on regular rules, process regular sets, then non-context free languages are obtained 3]. In this paper we consider the case of using context-free rules rather than regular ones. In these conditions it is proved that for k and = k derivation modes and when context-free rules are used, a nite set is always translated into a nite set. When   k or terminal derivation mode is used, then nite sets are translated into a family of languages strictly included in the family of context-free languages. On the other hand any language accepted by a Turing machine may be written as a translation of a regular set performed by such a mechanism based on context-free rules, under = k derivation strategy. So, a hierarchy of computational models may be introduced by considering various rule types and di erent derivation strategies applied to nite or regular sets as input sequences. It is also shown that the languages generated by some classes of cooperating distributed grammar 2

systems (see 4]) may be obtained as images of regular sets through some translations performed by generalized stream X- machines with underlying distributed grammars using context-free rules. The approach is also of practical interest when some specications may naturally lead to some simple grammars that dene the set of all legal input strings that should be processed 8]. In the last part of this paper is provided an example showing how the set of legal input strings submitted to a scanner system 7] may be specied by some suitable grammars which gives the production rule components of a generalized stream X- machine with underlying distributed grammars.

2 Basic denitions and examples For a set Q we denote by 2Q the family containing all subsets of Q: Let  be a nite alphabet  is the set of all nite strings having symbols from . By  we denote the empty string. The length of a string s is denoted by j s j : We have j  j= 0: For two strings s t 2  st represents the string obtained by concatenation. Let P be a set of context-free productions over a set N of nonterminal symbols and a set A of terminal symbols, 10]. The domain of P is given by the set

dom(P ) = fA j A 2 N and there exists A ;!  2 P g: By =)P we denote the usual derivation in P: As in 4] are dened the following derivations =)=P r =)P =)P r =)Pt =)P r where r  1: Let   2 (N  A) then we write  =)=r  if and only if there are some words x0 : : : xr such that  = x0  = xr and xj =)P xj +1 for all 0 j r ; 1: Moreover, we write  =)  when  =  or  =)=r  for some r: We write also  =)r  when  =)=k  for some k  r: By  =)tP  we understand  =)P  and there is no derivation step  =)P : Note that if x 2 A then x =)tP x: We have also that  =)P r  , if and only if  =)=P k  for some 1 k r: Note that 1 means = 1: We denote by DM the set of all derivation modes, i.e.

DM = ft g  f r = r  r j r  1g: In 4] besides the usual reexive transitive closure of =)P denoted by =)P they are also dened some other derivation strategies saying that in P a specied number of derivation steps (= r), at most a number of derivation steps ( r), or at least a number of derivation steps ( r), may be developed. A terminal derivation strategy says that a derivation ends when no more steps may be made in P: The regular rules have the forms B ;! a or B ;! aC where a 2 A and B C 2 N: The context free rules have the form B ;!  where  2 (N  A)+ : The rules of the form B ;!  are called erasing rules. The cooperating/distributed (CD for short) grammar systems have been introduced rst in 13] with motivations related to two level grammars. An intensive study of CD grammar systems has been started after relating them with articial intelligence concepts 4], 5] such as the blackboard models in problem solving. A CD grammar system is a construct consisting of several usual grammars, working together on the same sentential form to generate words. Informally, such systems and their work can be described as follows (see 4]): initially, the axiom is the common sentential form. At each moment, one grammar is active, that means it rewrites the common string, while the others are not active. The conditions under which a component can become active or it is disabled and leaves the sentential form to other component 3

are specied by the cooperation protocol. The language of terminal strings generated in this way is the language generated by the system. As basic stop conditions usually considered, we mention: each component, when active, has to work for exactly r, at least r, at most r, or the maximal number of steps (a step means the application of a rewriting rule). Many other stopping conditions have been considered or added to the above mentioned one (see 4], 1], 2]).

Denition 1. A cooperating/distributed grammar system with n components P1 : : : Pn is

a system

; = (N A S P1 : : : Pn ) where N is the set of nonterminal symbols, A is the set of terminal symbols, S is the nonterminal start symbol, and P1 : : : Pn are sets of production rules. Note 1. For d 2 DM the language generated by ; using the d derivation mode, is Ld(;): By CDLn(CF d) are denoted the families of languages generated by CD grammar systems with n components in the d derivation mode and using only context-free rules. The union of all the families CDLn(CF d) for all n is denoted by CDL1(CF d): The new generative models are more powerful than the corresponding generative devices provided by Chomsky hierarchy 10]. For example let us consider a system with three components ; = (fS A C A1 C1 g fa b cg S P1 P2 P3 ) where P1 = fS ;! AC1 C1 ;! C g P2 = fA ;! aA1 b A ;! ab C ;! cC1 C ;! cg P3 = fA1 ;! aAb A1 ;! ab C1 ;! cC C1 ;! cg A derivation in ; using = 2  2 or t derivation modes develops as follows: S =)P1 AC =)P2 aA1 bcC1 =)P3 aaAbbccC =)P2 : : : =) an bncn : It may be observed that in = 2  2 or t derivation modes, the language generated is not context-free 10] and the rules used by the components are linear or regular excepting the rule

S ;! AC1 2 P1 :

Denition 2. Let ; be a CD grammar system and d 2 DM: Let also U = (W E ) be a directed graph which nodes are labelled by the components of ;. The language LUd (;) generated by ; and controlled by U in the d mode is dened as the set of all words z 2 A such that S =)dPi1 z1 =) : : : =)dPim zm = z with (Pij Pij+1 ) 2 E 1 j m ; 1: Note 2. We denote by CDLn(CF c d) d 2 DM the family of all languages LUd (;) generated by some grammar systems with n components, controlled by a directed graph U in the d derivation mode. The above introduced denition considers a new control mechanism for selecting at a given moment a component to continue the derivation process. Denition 3. A cooperating distributed grammar system with appearance checking is a system ; = (N A S P1 : : : Pn v) where 4

 (N A S P1 : : : Pn) is a usual CD grammar system and  v = (v1 : : : vn) 2 f0 1gn :

A component Pi can be applied in the appearance checking mode only if vi = 1: For x y 2 (N  A) we write x ac =)Pi y if  either x =)Pi y  or x = y and no rule of Pi can be applied to x and vi = 1:

Note 3. The language generated by ; (controlled by U ) in the d mode is denoted by L(d ac)(;) (LU(d ac) (;)). We denote by CDLn(CF d ac) (CDLn(CF c d ac)), d 2 DM the family of languages L(d ac) (;)(LU(d ac) (;)) generated by some grammar systems with n components, (controlled by a directed graph U ) in the d derivation mode. When the union of these families of languages, for all n are considered, n is replaced by 1:

The appearance checking feature allows for a component, which is selected to develop the current sentential form, to be skipped when the rules of the component may not be applied and the component has the corresponding element of v equal to 1. Normally if this feature is absent the derivation is blocked in the above mentioned conditions. Note 4. When erasing rules are allowed for the context-free case, CF is replaced by CF  in the corresponding notations. We introduce the concept of generalized stream X- machine with underlying distributed grammars where, for each basic function (relation) of  we have an associated set of (regular or context-free) production rules. The involved derivation process is dened according to the above mentioned derivation strategies. The memory and the ways in which this one is combined with the input symbol or the output sequence of symbols will take a specic form. Denition 4. Let us consider the following elements:

 A, a nite alphabet of terminal symbols  N , a nite set of nonterminal symbols with A \ N =   P = fP1 : : : Png contains sets of rules with symbols from A  N: A (generalized) stream X- machine with underlying distributed grammars - (g)Xmdg, for short - is a system X = ( A Q M P F I T m0 N ) where:   N  A is the input alphabet  A, the alphabet introduced above, is the output alphabet  Q is the nite set of states  M = (N  A) is the memory  m0 2 N  A is the initial memory value  F is the next state function F : Q P ;! 2Q  I and T are the sets of initial and nal states respectively 5

Denition 5. If q q0 2 Q R 2 P and q0 2 F (q R) we say that R : q ! q0 is an arc from q to q0: If q q0 2 Q are such that there exists q0 : : : qm 2 Q m  0 with q = q0 q0 = qm and Ri : qi;1 ! qi are arcs for all 1 i m then we say that R1 : : : Rm : q ! q0 is a path from q to q0 : Note that  : q ! q is a path. Denition 6. Let X = ( A Q M P F I T m0 N ) be a (g)Xmdg. For a given derivation mode d 2 DM we can dene an associated (generalized) stream X- machine Xd = ( A Q M d F I T m0 ), where d = f1 : : : n g and i : M  ;! 2A M : Each i is associated to Pi and it is dened by (x m0 ) 2 i (m ) if and only if m =)dPi xm0 and  2  x 2 A m m0 2 M but m0 does not begin with a symbol of A: Note 5. There are some new elements in the denition of Xd compared with those occurring in the usual denition of stream X- machines 9], 12]:  i are relations with the range A M   the memory values are taken from the set (N  A)   the ways for combining the input symbol  or the output sequences of symbols x with the current memory values m m0 follow from the strings submitted to or obtained from the derivation process in a given component Pi respectively: m =)dPi xm0 :

So, the input symbol is always considered at the right end part of the current memory element, when the derivation starts. At the end of the derivation process, the output sequence of symbols is considered as being the sequence of terminal symbols occurring to the left end part of the resulted sentential form the rest of that sequence is considered as being the memory element produced. The rst observation mentioned above is a compulsory feature of any generalized stream Xmachine 9]. The others are specic for the mechanism introduced here. Now a state to state transition is introduced by addressing the states, the memory elements, the input symbol and the output sequence of symbols involved in each processing step. Denition 7. A conguration of Xd is a system (q o m ) where q is the current state, o is the content of output tape, m is the current memory value,  is the unscanned part of the input tape. A state to state transition Pi : (q o m ) ` (r ox m0 ) is done in Xd if and only if r 2 F (q Pi )  2  and (x m0 ) 2 i (m ): For a given path R1 : : : Rk : q1 ! qk+1 we have a state to state transition closure R1 : : : Rk : (q1 o1 m1 1 : : : k ) ` (qk+1 ok+1 mk+1 ) if and only if k = 0 or k  1 and R1 : (q1 o1 m1 1 : : : k ) ` (q2 o2 m2 2 : : : k ) is a state to state transition and R2 : : : Rk : (q2 o2 m2 2 : : : k ) ` (qk+1 ok+1 mk+1 ) is a state to state transition closure. Note 6. Let us suppose that (q o m ) is a current conguration of Xd where  2  is the current input symbol. At a state to state transition the machine acts as follows: 6

 the current input symbol is added to the right end of the sequence representing the current     

memory value and then it is discarded the new obtained sequence m is used as a sentential form if there exists a set of rules Pi such that F (q Pi ) 6= , the rules of Pi are used in order to produce in the d derivation mode a new sentential form   let us suppose that  = xm0 , where x is the longest prex containing only output symbols x is moved out and it is added to the right end of the current output string o ox becomes the new current output string m0 becomes the new current memory value the new current state is arbitrarily chosen from the set F (q Pi ).

Note 7. The relation computed by the stream X- machine Xd under the assumption that the nal memory value is empty is denoted by fd (see 12]). It follows that fd (s) is the set of all x 2 A such that there exist R1 : : : Rk with: R1 : : : Rk : (q  m0 s) ` (r x  ) q 2 I r 2 T k  1: That is, for an input sequence s 2  the set fd (s) contains all the output strings produced by the machine Xd starting from an initial state, an empty output string and the initial memory value m0 and leading to a terminal state, an empty input and an empty memory value. For a language L we dene fd (L) = fd (s): s2L

Note 8. A regular (or context free) gXmdg is a generalized stream X- machine with underlying distributed grammars such that all the sets Pi 2 P contain only regular (or context-free) rules. For a derivation mode d 2 DM we consider the families DSd nREG and DSd nCF containing all the generalized stream X- machines Xd obtained from regular gXmdg or context-free gXmdg with n sets of rules, respectively. Moreover, if the context-free gXmdg has erasing rules in a component Pi then Xd is a member of the family DSd nCF  : Example. In order to show how powerful is such a generalized stream X- machine with underlying distributed grammars, let us consider the system Xd = (fcg fa b cg f1g M fg F f1g f1g S ) where

   

M = fa b c S g F (1 ) = 1  corresponding to the set P = fS ;! aSb S ;! abg the derivation mode = 1:

7

The following state to state transitions may be dened: (1  S cn ) ` (1 a Sbc cn;1 ) ` (1 aa Sbbcc cn;2 ) ` : : : (1 an;1 Sbn;1 cn;1 c) ` (1 an bn cn  ):

It follows that

f=1(fcn j n  1g) = fan bncn j n  1g:

It may be observed that using only one basic function associated to some linear rules, a regular language is translated into a language known as being a non context-free language 10]. Denition 8. A (generalized) stream X- machine with underlying distributed grammars using appearance checking - (g)Xmdgac, for short - is a pair Y = (X v) where

X = ( A Q M P F I T m0 N ) is a (g)Xmdg as in denition 4, and v has the meaning given in denition 3. Note 9. For a given d 2 DM by DSd nCFac and DSd nCFac are denoted the classes containing the generalized stream X-machines Xd obtained from some gXmdgac with n contextfree components, without or with erasing rules, respectively. For X 2 fREG CF g we denote by DSd X the union of all the families DSd nX for all n: A similar notation is used when the appearance checking concept is allowed, namely DSd CFac or DSd CFac : The appearance checking feature considered for cooperating distributed grammar systems is normally addressed in the context of generalized stream X- machines with underlying distributed grammars. Note 10. By FIN REG CF PR PR RE are denoted the families of nite, regular, context-free, programmed, programmed with erasing rules, and recursively enumerable languages respectively. By REG2 we denote also the family of regular languages containing only words of length greater than or equal to 2: For a given derivation mode d 2 DM and a family Y of languages over the input alphabet  we dene

DSd nREG(Y ) = ffd (L) j L 2 Y and Xd 2 DSd nREGg: We also work with DSd nCF (Y ) and DSd nCF  (Y ) appropriately dened. DSd nCFac(Y ) and DSd nCFac (Y ) are also considered. In every case the union of the corresponding families, for all n is taken. The notation is obtained by replacing the index d n by

d:

3 Main results The case of the regular rules used by the components of the Xmdg is studied in 3]. Here they are briey presented the main relations obtained among various families of languages. Theorem 1. The following relations hold: 1. DSd REG(FIN )  FIN d 2 f k = k j k  1g 2. DSd REG(FIN ; f fgg) = REG2 for d 2 f tg 3. DSk REG(FIN )  REG k  1: 8

Theorem 2. For d 2 DM the family DSdREG(REG) contains non context free languages. Corollary 1. REG2  DStREG(REG) \ DS REG(REG)

These results show that the generalized stream X- machines obtained from gXmdg devices having regular rules, transform nite sets into nite or regular languages depending on the derivation strategy used (see theorem 1) when regular sets are considered as input sets then non context-free languages are obtained for all the derivation strategies dened (see theorem 2). This last result shows that the power of these mechanisms is greater than that of cooperating distributed grammar systems which in the case of regular rules produce only regular languages

4]. Now the case of context-free rules used by the components of the gXmdg is studied. This case is also considered for cooperating distributed grammar systems (see 4]) and it is a natural extension of the above considered regular case 3].

Theorem 3.

1. DSd CF (FIN )  FIN d 2 f k = k j k  1g 2. DSd CF (FIN )  CF d 2 f tg: Proof. For the rst point, lemmas 1 and 2 in 3] prove the relations. For the second point, the proof of lemma 3 in 3] may be used by appropriately changing regular with context-free. As it may be observed the above result is a direct consequence of the theorem 1 and of the proofs of lemma 1, lemma 2 and lemma 3, developed in 3]. The next result will show that for  k derivation mode the generalized stream X- machines obtained from gXmdg mechanisms using context-free rules translate nite sets into context-free ones. Theorem 4. DSk CF (FIN )  CF k  1: Proof. For any n  1 and L 2 DSk nCF (FIN ) it will be shown that L is a context-free language. Indeed let us consider a gXmdg

X = ( A Q M P F I T m0 N ) with P = fP1 : : : Pn g n  1 and let Xk be the associated generalized stream X- machine for the derivation mode  k: Let us also consider a nite language L0 such that

fk (L0 ) 2 DSk nCF (FIN ): For any x 2 L0 x = a1 : : : ar ai 2  1 i r denote by zx the string m0 x: Let us consider R1 : : : Rr 2 P the rule sets acting on zx i.e. there exist q0 q1 : : : qr 2 Q q0 2 I qr 2 T and qi 2 F (qi;1 Ri ) 1 i r: For each zx the following context-free grammar is considered

G x = (N 0 A S P 0 ) where

N 0 = fS g  f B p1 : : : pr c] j B 2 N 0 pi k 1 i r 1 c rg

and P 0 contains the rules dened in the following two steps: 1. S ;! x0 x1 : : : xr 2 P 0 where 9

x0 x0 xi xi

= = = =

m0 if m0 2 A or

m0 p0 1 : : : p0 r c0 ] c0 = 1 if m0 2 N ai if ai 2 A 1 i r or

ai pi 1 : : : pi r ci ] pi 1 = : : : = pi ci;1 = 0 i ci r if ai 2 N 1 i r:

If we denote by B the set

f0 j m0 2 N g  fi j ai 2 N 1 i rg then the following relation holds j 2B pj h = k 1 h r The gXmdg X processes the input sequence x by applying the rule sets R1 : : : Rr in this order, each one at least k times, such that R1 is applied to m0 a1 at least k times yielding y1 z1 y1 2 A z1 2 (A  N ) and the rst letter of z1 is not from A: R2 is applied to z1 a2 at least k times and yields y2 z2 a.s.o. The above conditions say that pi ci is the minimum number of applications of the set Rci to ai (note that Rci may be also applied to previous symbols aj 1 j < i in their derivation process). The values pi j are 0 because Rj were already applied, for 1 j ci ; 1 and the values pi j show the minimum derivations required to be applied by Rj ci < j r to ai : The last relation point out that each set of rules is applied at least k times. 2. a) For each rule E ;! x1 D1 x2 : : : Dt xt+1 2 Rc 1 c r xi 2 A 1 i t + 1 Di 2 N 1 i t t  1 and any 0 pi k 1 i r with p1 = : : : = pc;1 = 0 the following rules are built:

E p1 : : : pr c] ;! y 2 P 0 y 2 sp1 ::: pr c (x1 D1 : : : Dt xt+1 ) where the set sp1 ::: pr c(x1 D1 : : : Dt xt+1 ) contains elements of the form x1 D1 q1 1 : : : q1 r c1 ]x2 : : : xt Dt qt 1 : : : qt r ct ]xt+1 where

c ci r qi 1 = : : : = qi ci;1 = 0 1 i t th=1 qh j = pj 1 j r j 6= c and if pc = 0 then th=1 qh c = pc or if pc > 0 then th=1 qh c = pc ; 1 According to this denition each pi 1 i r is "distributed" in (sum of) values qh i 1 h t associated to the t nonterminals and the value corresponding to the current derivation, applying the set Rc is decreased by one (if it is possible). b) In the case of terminal rules E ;! x 2 Rc 1 c r x 2 A the following rules are built:

E p1 : : : pr c] ;! x 2 P 0 if pi = 0 i 6= c and pc = 0 or pc = 1: A terminal rule is used only when all the required derivations were performed. With this set of rules, the context-free grammar Gx has the following property

L(Gx ) = fk (x) 10

As L0 is a nite set of strings it follows that fk (L0 ) can be obtained as a nite union of some context free languages. So, we get that fk (L0 ) 2 CF (see 10]). The proper inclusion follows from Lemma 4 in 3]. The following three lemmas state various relations among languages generated by cooperating distributed grammar systems and languages produced by generalized stream X-machines obtained from gXmdg mechanisms having context-free rules and using regular languages as input sets. Lemma 1. For any language L 2 DSd nCF (REG) n  1 and c a symbol which does not occur in the alphabet of L it follows that Lc 2 CDL1(CF c d) d 2 ftg  f k = k  k j k  1g: Proof. Let X = ( A Q M P F I T m0 N ) be a gXmdg with P = fP1 : : : Pn g n  1 and let Xd be the associated generalized stream X- machine for the derivation mode d being = 1 or 1: Let us also consider L0 a regular language generated by the grammar G = (N 0  S 0 P 0 ) with L(G) = L0 and fd(L0 ) = L: We show that Lc 2 CDL1(CF c d): We may assume that N \ N 0 = : Now, let us construct a grammar system with the derivation controlled by a directed graph. So, we have the grammar system ; where:  the set of nonterminal symbols is N " = N  N 0  fS X g and S X are new symbols  the set of terminal symbols is A  fcg  the axiom symbol is S   the components are { (Pi s s0 p)1ips s02Qp2f0 g { (Pn+1 s)s2Q (Pn+2 s)s2Q

{ Pn+3 Pn+4 :

The components are dened in the following way: Pi s s0 p = Pi 1 i n s s0 2 Q p = 0 or p =  where Pi are the components of P 

Pn+l s = Pn+l  1 l 2 s 2 Q with

Pn+1 = fB ;! aX j B ;! a 2 P 0 g Pn+2 = P 0 n fB ;! a j B ;! a 2 P 0 g and

Pn+3 = fS ;! m0 S 0 g Pn+4 = fX ;! cg: The directed graph U = (W E ) has W= fPn+3 Pn+4g  fPn+l s j 1 l 2 s 2 Qg  fPi s s0 p j 1 i n s s0 2 Q p 2 f0 gg 11

and

E=

f(Pn+3 Pn+l s) j 1 l 2 s 2 I g  f(Pi s s0 Pn+l s0 ) j 1 i n 1 l 2 s s0 2 Q s0 2 F (s Pi )g  f(Pn+2 s Pi s s0 ) j 1 i n s s0 2 Q s0 2 F (s Pi )g  f(Pn+1 s Pi s s0 0) j 1 i n s s0 2 Q s0 2 F (s Pi ) \ T g  f(Pi s s0 0 Pn+4 ) j 1 i n s s0 2 Q s0 2 F (s Pi ) \ T g: A derivation starts with Pn+3 by applying a rule S ;! m0 S 0 : Before applying the rules of a production set Pi s s0 1 i n s s0 2 Q a rule belonging to Pn+l s 1 l 2 s 2 Q is

applied getting a new input symbol to the right end of the sentential form, due to an edge (Pn+l s Pi s s0 ) 2 E: An edge (Pn+2 s Pi s s0 ) exists in E so it allows the application of only nonterminal rules inherited from P 0 . After Pi s s0 is chosen, the derivation may continue if and edge (Pi s s0 Pn+l s0 ) 1 l 2 occurs in E: At the end before entering from the current state s in a nal one, s0 2 T by applying rules of a set Pi s s0 0 it is used a set Pn+1 s in order to apply a rule B ;! aX: This derivation step is allowed by the edge (Pn+1 s Pi s s0 0 ) occurring in E: Finally a rule X ;! c 2 Pn+4 is used according to (Pi s s0 0 Pn+4 ) 2 E: The sets Pn+2 s s 2 Q contain only nonterminal rules and then no terminal rules of P 0 are used before reaching a nal state. If the machine is in a state s 2 Q the rules of Pi 1 i n have been applied, and it will enter in a nal state s0 2 F (s Pi ) \ T then in the CD grammar system, ; we use the sets Pn+1 s and Pi s s0 0 allowing a terminal derivation only in a nal state s0 2 T after 'reading' the last input symbol. In this case the derivation process ends even in the case when F (s0 Pj ) is not empty, for some Pj 2 P: For this reason a special distinct instance of Pi s s0 is used, namely Pi s s0 0 : So, LUd (;) = Lc: In the cases = k and k k  2 we should modify the sets Pn+1 s Pn+2 s Pn+3 Pn+4 s 2 Q in the following way:  each rule C ;! aB 2 Pn+2 s(C ;! aX 2 Pn+1 s) is replaced by

C ;! B1 Bi ;! Bi+1 1 i < k ; 1 Bk;1 ;! aB (Bk;1 ;! aX )

with B1 : : : Bk;1 being new symbols  the rule S ;! m0 S 0 2 Pn+3 is replaced by

S ;! S1 Si ;! Si+1 1 i < k ; 1 Sk;1 ;! m0 S 0  where S1 : : : Sk;1 are new symbols  each rule X ;! c 2 Pn+4 is replaced by

X ;! X1 Xi ;! Xi+1 1 i < k ; 1 Xk;1 ;! c with Xi 1 i k ; 1 being new symbols. In the cases  k k  1 and t the sets Pn+i 1 i 2 are replaced by Pn+i j 1 where for each rule C ;! aB 2 Pn+i 1 i 2 we add to Pn+i 1 the rules

C ;! A1 1 Ai 1 ;! Ai+1 1 1 i < k ; 1 Ak;1 1 ;! A0 12

ij 2

and to Pn+i 2 the rules

A0 ;! A1 2 Ai 2 ;! Ai+1 2 1 i < k ; 1 Ak;1 2 ;! aB where Ai j 1 i k ; 1 1 j 2 are new symbols. For each set Pn+i s are introduced two sets in order to avoid the application of a rule C ;! aB for more than one time, when B = C: Additionally any occurrence in E of the form (X Pn+i s ) 1 i 2 is replaced by (X Pn+i 1 s ) and any occurrence of the form (Pn+i s X ) is replaced by (Pn+i 2 s X ): A new edge (Pn+i 1 s Pn+i 2 s ) is added to E: Accordingly are modied the denitions for the set of nonterminal symbols (N "): With these

changes we get the results stated by this lemma. Let us denote by DM1 = ftg  f k = k  k j k  1g: Lemma 2. DSd nCF (REG) CDL1(CF  c d) n  1 d 2 DM1 Proof. The set Pn+4 occurring in the proof of lemma 1 is replaced by Pn+4 = fX ;! g: The same arguments as those given in the proof of that lemma show the results stated by this lemma. Let us denote by DM2 = DM1 n f= 1 1g: Lemma 3. CDLn(CF  c d) DSdCF (REG) n  1 d 2 DM2 : Proof. Let us consider a CD grammar system ; = (N A S P1 : : : Pn ) and the directed graph U = (W E ). The following gXmdg is constructed

X = ( A Q M P F I T m0 N ) with  = fZ g Q = f1 2 : : : n n + 1g P = fP1 : : : Pn Pn+1 g where P1 : : : Pn are the sets dened by ; and Pn+1 contains only the rule Z ;!  I = Q n fn + 1g T = fn + 1g m0 = S: For all (Pi Pj ) 2 E it follows j 2 F (i Pi ): For all k 2 Q we have n + 1 2 F (k Pk ): Let Xd be the associated generalized stream X- machine for the derivation mode d 2 DM1 : Now we can show that fd(fZ n j n  1g) = LUd (;): Indeed, a derivation in ; is a sequence of derivation steps in di erent components being selected according to the graph U: In the same time Xd will start in any state s 2 I with the sentential form SZ and will enter in a component. As the transition function F is constructed according to U it follows that the same sets Pi 1 i n are selected. At the end we get a string xZ p for some p  1 if a derivation S =) x holds in ;: In order to erase Z p the rules of Pn+1 are used as long as it is necessary. The derivation modes d 2 ftg  f k j k  2g allow to get x from xZ p: The cases = 1 and 1 are removed from the set DM1 because at any derivation step in Pn+1 at least one Z is erased and exactly one is added to the right end of the sentential form, 13

when Pn+1 is selected to be applied. For = k k  2 and  k k  1 the rule Z ;! Z is added to Pn+1 : So it results x 2 fd (fZ n j n  1g): As a conclusion the next result may be stated: Theorem 5. DSdCF (REG) = CDL1(CF  c d) d 2 DM2 Proof. The result is a consequence of the previous lemmas. Corollary 2. DSdCF (REG) = PR d 2 f= k k j k  2g DSk CF  (REG) PR k  1 Proof. This is a consequence of theorem 5 and theorem 4.2 (see 4]). If the appearance checking restriction is considered for the components dening any gXmdg, then theorem 5 is again true and by using theorem 4.7 (see 4])we get Theorem 6. DS=k CFac (REG) = RE k  2 Again we get the power of Turing devices for some of the generalized stream X- machines obtained from gXmdgac devices using context-free rules in the = k derivation mode. In 11] it has been shown that any function computed by a Turing machine is obtained as a computation of a 2- stack straight move X- machine, a model based on push and pop operations considered as basic functions. Here these basic functions are elementary rewriting production rules applied in various ways according to the considered derivation strategies.

4 An example: Formal specication of a scanner system A scanner system has been presented in 7] for illustrating the use of the X- machine model as a language specication. Here it is further rened this example by using a gXmdg as a model for getting formal specications. Let C , be the set of printable characters, and L D C letters and decimal digits, respectively. The elements n 2 L are called names, and the elements y 2 D are called numbers. Two special symbols CR (carriage return) and LF (line feed), where CR LF 62 C are considered. The sequence CR LF is referred to as end of line. By C it is denoted the set of highlighted characters and by C the set of ignored characters. Next, s stands for the highlighted string s and s stands for the ignored string s: The scanner system processes input strings from the set C fCR LF g: An input of the form

n y CR LF is an accepted input and contains a name and a number separated by a single semicolon. A given correct input n y CR LF is translated to the output string

accepted : n y CR LF containing an acceptance prex and the highlighted input string. Some inputs may be rejected due to a wrong name or a wrong number. In this case the output string contains the prex 14

rejected: and the scanned input will be highlighted. The remaining part of the string will be ignored by replacing each character c with c and CR LF is replaced by CRLF . The gXmdg specifying the problem has the components:

 N  A ; the set of the input symbols where

N = L  D  fCRg  f$g  f g A = L  D  L  D  fCR CR LF g ; the set of the output symbols Q = fenter ; name enter ; number reject ; name reject ; number eol accept rejectg ; the set of the states I = fenter ; nameg ; the initial set of the states T = faccept rejectg ; the nal set of the states m0 = S ; the initial memory value

and the rule sets:

fl ;! l j l 2 Lg f ;! g fd ;! d j d 2 Dg fc ;! c j c 62 L c 6=00 g fc ;! c j c 62 D c =6 CRg fc ;! c j c 2 C or c = CRg  f$ ;! rejected :g CARRIAGE ; RETURN = fCR ;! CRg ACCEPT = fS ;! accepted :g NAME SEPARATOR NUMBER WRONG ; NAME WRONG ; NUMBER SKIP

= = = = = =

the function F given by:

F (enter ; name NAME ) F (enter ; name SEPARATOR) F (enter ; number NUMBER) F (enter ; number CARRIAGE ; RETURN ) F (eol ACCEPT ) F (enter ; name WRONG ; NAME ) F (reject ; name SKIP ) F (reject ; name SKIP ) F (enter ; number WRONG ; NUMBER) F (reject ; number SKIP ) F (reject ; number SKIP )

15

= = = = = = = = = = =

enter ; name enter ; number enter ; number eol accept reject ; name reject ; name reject reject ; number reject ; number reject:

The generalized stream X- machine X=1 obtained from the above introduced gXmdg for = 1 derivation mode, provides the following set of basic functions (by R it is denoted the function associated to the rule set R): ( $n1 l) where l 2 L ( $n) ( $n y1 d) where d 2 D ( $n yCR) (accepted : n yCRLF ) ( $n1 c) where c 62 L c 6=0 0 WRONG;NUMBER($n y1 c) = ( $n y1 c) where c 62 D c 6= CR SKIP (xay b) = f(xay b) (x ayb)g where x y 2 A  a b 2 N:

NAME ($n1 l) SEPARATOR($n  ) NUMBER ($n y1 d) CARRIAGE;RETURN ($n y CR) ACCEPT ($n yCR LF ) WRONG;NAME ($n1 c)

= = = = = =

Please note that when x =  a = $ then a is rejected:. The obtained generalized stream X- machine X=1 has the following properties: 1. SKIP is a relation, because having two nonterminal symbols in the sequence being the memory value, distinct output sequences may be generated from it 2. the memory play an important role in getting output strings with suitable prexes (accepted: or rejected: this kind of result may not be obtained by using a simple scanner based on nite state models.

5 Conclusions A mechanism for accepting classes of languages by using a generalized state machine to control a family of distributed grammars has been described. The results demonstrate that powerful devices can be constructed from simple basic components in an elementary way. Starting from the suggestions made in 11] - to consider as basic functions nite state machines - a hierarchy of computational models is pointed out, depending on various rule types and di erent derivation strategies used in processing nite or regular input sets. If the grammars are of a particular class, say regular or context-free, then nite sets are translated into nite sets when k = k derivation strategies are used, and regular or context-free sets, respectively, are obtained for  k  and terminal derivation strategies. In both cases, regular or context-free rules used, the regular sets are translated into non-context free languages. In 11] a way for computing a function accepted by a Turing machine through a specic X- machine, 2-stack straight move stream X- machine, is presented. In this paper a similar result says that any language accepted by a Turing machine may be written as a translation of a regular set performed by a generalized stream X- machine , obtained from a gXmdgac, based on context-free rules, under = k derivation strategy. Some relations between the families of languages computed by generalized stream X- machines, obtained from various gXmdg devices, and the families of languages generated by cooperating distributed grammar systems are investigated. 16

Other new problems may be further addressed in the framework of the considered model in this paper:  other ways of combining memory elements and the input/output symbols  other derivation strategies, for example the derivation process in a component ends when a specied sequence occurs or vanishes in the current sentential form  at any derivation step a new input symbol occurs rather than only one considered when the derivation starts (see denition 6). The theoretical interest of this approach consists in establishing a number of hierarchies of computational models of generalized stream X- machines based on di erent types of distributed grammar systems and using various derivation strategies. The approach is also useful in many situations when software engineers are trying to rene a high level model, in this case a stream X- machine the process often translates, naturally into the denition of a simple grammar to represent the set of legal input strings that are appropriate for that context 8]. Following an work on the use of stream X- machines to specify systems 7], it is presented here an example for specifying a scanner system. For example, the transition functions having the e ect of receiving strings representing a name or a number, are associated to some rules that precisely generate the set of legal names or numbers. So, it is obtained a generalized stream Xmachine based on a gXmdg. Dening grammars is a natural activity and thus this approach presents us with a promising way of organising system design in a formal manner. The author is indebted to the anonymous referee who made a number of useful comments on the rst version of this paper that allow us to improve the quality of the presentation.

References

1] T. Balanescu, H. Georgescu, M. Gheorghe: Grammar Systems with Counting Derivation and Dynamical Priorities, in New Trends in Formal Languages (Gh. Paun and A. Salomaa Eds), Lectures Notes in Computer Science 1218, 1997, 150-166.

2] T. Balanescu, H. Georgescu, M. Gheorghe: A New Type of Counting Derivation for CD Grammar Systems, in Grammatical Models of Multi-Agent Systems, OPA Overseas Publishing Associates (UK) Ltd , Gordon and Breach, 1999, 1-17.

3] T. Balanescu, H. Georgescu, M. Gheorghe: Stream X- machines with Underlying Distributed Grammars, Informatica, (submitted).

4] E. Csuhaj-Varju, J. Dassow, J. Kelemen, Gh. Paun, Grammar Systems. A Grammatical Approach to Distribution and Cooperation. Gordon & Breach, London, 1994.

5] J. Dassow, J. Kelemen, Cooperating distributed grammar systems: a link between formal languages and articial intelligence. Bulletin of EATCS 45, 1991, 131-145.

6] S. Eilenberg, Automata, languages and machines, Vol. A, Academic Press, 1974.

7] M. Holcombe, X- machines as a basis for dynamic system specication, Software Engineering Journal 3, 1988, 69-76. 17

8] M. Holcombe, T. Balanescu, M. Gheorghe, P. Radovici-Marculescu: On testing generalized stream X-machines, to appear in Recent Topics in Mathematical and Computational Linguistics (G. Paun ed.), Romanian Academy Publishing House.

9] M, Holcombe and F. Ipate, Correct Systems: Building a Business Process Solution, Springer Verlag, Berlin, 1998.

10] J. E. Hopcroft and J. D. Ullman, Introduction to Automata Theory, Language, and Computation, Addison-Wesley, 1979.

11] F. Ipate and M. Holcombe, Another look at computability, Informatica, Vol. 20, 1996, 359-372.

12] F. Ipate and M. Holcombe, An Integration Testing Method That is Proved to Find all Faults, Intern. J. Computer Math, Vol. 69, 1997, 159-178.

13] R. Meersman, G. Rozenberg, Cooperating grammar systems. In: Proc. MFCS 78, LNCS 64, Springer-Verlag, Berlin, 1978, 364{374.

18

Suggest Documents