k-Petri Net Controlled Grammars J¨ urgen Dassow1 and Sherzod Turaev2 1
Otto-von-Guericke-Universit¨ at Magdeburg PSF 4120, D-39016 Magdeburg, Germany
[email protected] 2 GRLMC, Universitat Rovira i Virgili Pl. Imperial T` arraco 1, 43005 Tarragona, Spain
[email protected]
Abstract. We introduce a new type of regulated grammars using Petri nets as a control of the derivations of a context-free grammar. We investigate the generative power and give closure properties of the families of languages generated by such Petri net controlled grammars.
1
Introduction
A context-free grammar and its derivation process can be described by a Petri net, where places correspond to nonterminals and terminals, transitions are the counterpart of the productions, and the tokens reflect the occurrences of symbols in the sentential form, and there is a one-to-one correspondence between the application of (sequences of) rules and the firing of a (sequence of) transitions. Therefore it is a very natural and very easy idea to control the derivations in a context-free grammar by adding some features to the associated Petri net. In [2] and [9] it has been shown that by adding some places and arcs which satisfy some structural requirements one can generate well-known families of languages as random context languages, vector languages and matrix languages. Thus the control by Petri nets can be considered as a unifying approach to different types of control (note that random context is a control by occurrence/nonoccurrence of letters whereas matrices give a prescribed set of sequences in which the productions have to be applied). In this paper we add additional places, called counters, and additional arcs associated with the new places. Adding k places leads to a control by k-Petri nets. The aim of this paper is the study of properties of the family of languages which can be generated by context-free grammars with a control by k-Petri nets. We present results on the generative power and we give some closure properties. The paper is organized as follows. In Section 2 we give some notions and definitions from the theories of formal languages and Petri nets needed in the sequel. Moreover we introduce the Petri net associated with a context-free grammar. In Section 3 we construct the new Petri net control mechanism and define the corresponding grammars. Furthermore, we give some examples. In Section 4 we show that context-free grammars with the simple control by one additional place can generate non-context-free languages. We also give relations to valence C. Mart´ın-Vide, F. Otto, and H. Fernau (Eds.): LATA 2008, LNCS 5196, pp. 209–220, 2008. c Springer-Verlag Berlin Heidelberg 2008
210
J. Dassow and S. Turaev
grammars and vector grammars. Furthermore, we show that we get an infinite hierarchy with respect to the numbers of additional places. In Section 5 we investigate the fundamental closure properties of the families of languages generated by k-Petri net controlled grammars.
2
Preliminaries
The reader is assumed to be familiar with basic notions of formal language theory and Petri net theory as, e.g. contained in [4,5,7,8]. 2.1
Grammars
Let Σ = {a1 , a2 , . . ., ak } be an alphabet. A string over Σ is a sequence of symbols from the alphabet. The length of a string w is denoted by |w|, and the number of a symbol a in a string w by |w|a . The empty string is denoted by λ which is of length 0. The number of the occurrences of all symbols of U ⊆ Σ in a string w is denoted by |w|U . The set of all strings over the alphabet Σ is denoted by Σ ∗ . A subset L of Σ ∗ is called a language. For languages L, L ⊆ Σ ∗ , the operation shuffle is defined by Shuf(L, L ) = {x1 y1 · · · xn yn | x1 · · · xn ∈ L, y1 · · · yn ∈ L , xi , yi ∈ Σ ∗ , 1 ≤ i ≤ n} and for L ⊆ Σ ∗ : Shuf 1 (L) = L; Shuf i (L) = Shuf(Shuf i−1 (L), L) for i ≥ 2; Shuf ∗ (L) = ∪i≥1 Shuf i (L). A context-free grammar is a quadruple G = (V, Σ, S, R) where V and Σ are the finite sets of nonterminal and terminal symbols, respectively, S ∈ V is the start symbol and R ∈ V × (V ∪ Σ)∗ is the set of (production) rules. Usually, a rule (A, x) is written as A → x. A rule of the form A → λ is called an erasing rule. x ∈ (V ∪ Σ)+ directly derives y ∈ (V ∪ Σ)∗ , written as x ⇒ y, iff there is a rule r = A → α ∈ R such that x = x1 Ax2 and y = x1 αx2 . The reflexive and transitive closure of ⇒ is denoted by ⇒∗ . A derivation using the sequence r1 r2 ···rn π ⇒ or == ===⇒. The language generated by of rules π = r1 r2 · · · rn is denoted by = G is defined by L(G) = {w ∈ Σ ∗ | S ⇒∗ w}. A vector grammar is a quadruple G = (V, Σ, S, M ) where V, Σ, S are defined as for context-free grammars, and M is a finite set of strings over a set R of context-free rules called matrices. The language generated by G is L(G) = {w ∈ π ⇒ w and π ∈ Shuf ∗ (M )}. Σ∗ | S = An additive valence grammar is a quintuple G = (V, Σ, S, R, v) where V , Σ, S, R are defined as for context-free grammars and v is a mapping from R into the set Z of integers. The language generated by G consists of all strings w ∈ Σ ∗ r1 r2 ···rk such that there is a derivation S == ===⇒ w such that ki=1 v(ri ) = 0. A positive valence grammar is a quintuple G = (V, Σ, S, R, v) whose components are defined as for additive valence grammars. The language generated by r1 r2 ···rk ∗ G consists j is a derivation S =====⇒ w such k of all strings w ∈ Σ such that there that i=1 v(ri ) = 0 and for any 1 ≤ j < k, i=1 v(ri ) ≥ 0. The families of languages generated by context-free, vector, additive valence and positive valence grammars (with erasing rules) are denoted by CF, V, aV and pV (CFλ , Vλ , aVλ and pVλ ), respectively.
k-Petri Net Controlled Grammars
2.2
211
Petri Nets
A Petri net is a construct N = (P, T, F, ϕ) where P and T are disjoint finite sets of places and transitions, respectively, F ⊆ (P × T ) ∪ (T × P ) is the set of directed arcs, ϕ : F → {1, 2, . . . } is a weight function. A Petri net can be represented by a bipartite directed graph with the node set P ∪ T where places are drawn as circles, transitions as boxes and arcs as arrows with labels ϕ(p, t) or ϕ(t, p). If ϕ(p, t) = 1 or ϕ(t, p) = 1, the label is omitted. A mapping μ : P → {0, 1, 2, . . .} is called a marking. For each place p ∈ P , μ(p) gives the number of tokens in p. Graphically, tokens are drawn as small solid dots inside circles. • x = {y | (y, x) ∈ F } and x• = {y | (x, y) ∈ F } are called pre- and post-sets of x ∈ P ∪ T , respectively. A transition t ∈ T is enabled by marking μ iff μ(p) ≥ ϕ(p, t) for all p ∈ P . In this case t can occur (fire). Its occurrence transforms the marking μ into the marking μ defined for each place p ∈ P by μ (p) = μ(p)−ϕ(p, t)+ϕ(t, p). A finite sequence t1 , t2 , . . . , tk of transitions is called an occurrence sequence enabled at tk t1 t2 μ1 −→ . . . −→ a marking μ if there are markings μ1 , μ2 , . . . , μk such that μ −→ t1 t2 ···tk ν −−−→ μk or μ − → μk where μk . In short this sequence can be written as μ −− ν = t1 t 2 · · · t k . A marked Petri net is a system N = (P, T, F, ϕ, ι) where (P, T, F, ϕ) is a Petri net, ι is the initial marking. We also define the final marking τ at which we stop the execution of N under some conditions. An occurrence sequence ν of transitions is called successful if it is enabled at the initial marking ι and finished at a final marking τ . 2.3
cf Petri Nets
The construction of the following type of Petri nets is based on the idea of using similarity between the firing of a transition and the application of a production rule in a derivation in which places are terminal and nonterminal symbols and tokens are separate occurrences of symbols. Definition 1. Let G = (V, Σ, S, R) be a context-free grammar. Let β : P → (V ∪ Σ) and γ : T → R be bijections. The cf Petri net corresponding to the grammar G is a marked Petri net N = (P, T, F, ϕ, ι) where – each place p ∈ P is labeled by the corresponding symbol x = β(p) ∈ V ∪ Σ and each transition t ∈ T is labeled by the corresponding rule r = γ(t) ∈ R; – (p, t) ∈ F iff γ(t) = r, r : A → w ∈ R where β(p) = A and ϕ(p, t) = 1; – (t, p) ∈ F iff γ(t) = r, r : A → w ∈ R where β(p) = x, |w|x > 0 and ϕ(t, p) = |w|x ; – ι(β −1 (S)) = 1 and ι(β −1 (x)) = 0 for all x ∈ (V ∪ Σ) \ {S}. Example 2. Let G1 be a context-free grammar with the following rules: r0 : S → AB, r1 : A → aAb, r2 : A → ab, r3 : B → cB, r4 : B → c (the other components of the grammar can be seen from these rules). Figure 1 illustrates the corresponding cf Petri net N . Obviously, L(G1 ) = {an bn cm | n ≥ 1, m ≥ 1}.
212
J. Dassow and S. Turaev
• S A
r2
r0
B
r4
a r1
b
c
r3
Fig. 1. A cf Petri net N
The following proposition, which directly follows from the definition, shows the similarity between terminal derivations in a context-free grammar and successful occurrences in the corresponding cf Petri net. Proposition 3. Let N = (P, T, F, ϕ, ι) be the cf Petri net corresponding to a r1 r2 ···rn context-free grammar G = (V, Σ, S, R). Then S == ===⇒ w ∈ Σ ∗ is a derivation t1 t2 ···tn in G iff ι −−−−−→ τ is an occurrence sequence of transitions in N such that ti = γ −1 (ri ), 1 ≤ i ≤ n, and τ (β −1 (x)) = 0 for all x ∈ V .
3
Petri Net Controlled Grammars
Now we consider cf Petri nets with k ≥ 1 additional places, pre-sets and post-sets of which are disjoint, respectively. Let N = (P, T, F, ϕ, ι) be the corresponding cf Petri net corresponding to a context-free grammar G = (V, Σ, S, R). For k ≥ 1 we set T1k = {tk11 , tk12 , . . . , tk1m(1) } ⊂ T and T2k = {tk21 , tk22 , . . . , tk2m(2) } ⊂ T where Tik1 ∩ Tjk2 = ∅ for 1 ≤ i < j ≤ 2 or 1 ≤ k1 < k2 ≤ k and T1i = ∅ iff T2i = ∅ for any 1 ≤ i ≤ k. Let Q = {q1 , q2 , . . . , qk } be the set of new places called counters. Let F1 = {(t, qi ) | t ∈ T1i , 1 ≤ i ≤ k} and F2 = {(qi , t) | t ∈ T2i , 1 ≤ i ≤ k}.
Definition 4. A k-Petri net (in short k-PN) with respect to the grammar G is a system Nk = (P , T , F , ϕ , ι , M ) where – – – –
P = P ∪ Q, T = T and F = F ∪ F1 ∪ F2 , ϕ (x, y) = ϕ(x, y) if (x, y) ∈ F and ϕ (x, y) = 1 if (x, y) ∈ F1 ∪ F2 , ι (β −1 (S)) = 1 and ι (p) = 0 for all p ∈ P \ {β −1 (S)}, M is the set of final markings and for any τ ∈ M , τ (p) = 0 for all p ∈ P \ {β −1 (x) | x ∈ Σ}.
Definition 5. Let k ≥ 1. A k-PN controlled grammar is a quintuple G = (V , Σ, S, R, Nk ) where V, Σ, S, R are defined as for a context-free grammar and Nk is the k-PN with respect to the context-free grammar (V, Σ, S, R).
k-Petri Net Controlled Grammars
213
Definition 6. The language generated by a k-PN controlled grammar G, denoted by L(G), consists of all strings w ∈ Σ ∗ such that there is a derivation π S= ⇒ w, π = r1 r2 · · · rn where ν = t1 t2 · · · tn , ti = γ −1 (ri ) ∈ T, 1 ≤ i ≤ n is an occurrence sequence of the transitions of Nk enabled at the initial marking ι and finished at a final marking τ . We denote the family of languages generated by k-PN controlled grammars (without erasing rules) by PNλk (PNk ), k ≥ 1. We give two examples which will be used in the sequel. Example 7. Figure 2 illustrates a 1-PN N1 which is constructed from the cf Petri net N in Figure 1 adding a single counter place q. Let G2 = (V, Σ, S, R, N1 ) be the 1-PN controlled grammar where V, Σ, S, R are defined as for the grammar G1 in Example 2. It is easy to see that L(G2 ) = {an bn cn | n ≥ 1}.
• S A
r2 a
r1
r0
r4
B
c
b q
r3
Fig. 2. A 1-PN N1
Example 8. Let G3 be a 2-PN controlled grammar with the production rules: r0 : S → A1 B1 A2 B2 , r1 : A1 → a1 A1 b1 , r2 : A1 → a1 b1 , r3 : B1 → c1 B1 , r4 : B1 → c1 , r5 : A2 → a2 A2 b2 , r6 : A2 → a2 b2 , r7 : B2 → c2 B2 , r8 : B2 → c2 . and the corresponding 2-PN N2 is given in Figure 3. Then it is easy to see that m m G3 generates the language L(G3 ) = {an1 bn1 cn1 am 2 b2 c2 | n, m ≥ 1}. m m Lemma 9. The language L = {an1 bn1 cn1 am 2 b2 c2 | n, m ≥ 1} cannot be generated by a 1-PN controlled grammar.
Proof. Suppose the contrary: there is a 1-PN controlled grammar G = (V , Σ, S, R, N1 ) where Σ = {a1 , b1 , c1 , a2 , b2 , c2 } such that L(G) = L . Since the set V is finite, for large n and m each derivation S ⇒∗ w ∈ L contains a subderivation of the form D: A ⇒∗ xAy where A ∈ V and x, y ∈ Σ ∗ . As L is infinite, there are words with large enough length obtained by iterating such a derivation D arbitrarily many times. Suppose S ⇒∗ uAv ⇒∗ uxAyv ⇒∗ · · · ⇒∗ uxn Ay n v ⇒∗ w ∈ Σ ∗
(1)
is also a derivation in G. Then xn and y n are subwords of w . It follows that x and y can be only powers of two symbols from Σ ∪ {λ}. Therefore, in order to
214
J. Dassow and S. Turaev
r3
S •
c1
r4
q1
c2
r8
q2
r0 r2
b1
r6
a1 r1
r7
B1 B2
b2 a2
A1 A2
r5
Fig. 3. A 2-PN N2 m m generate a word w = an1 bn1 cn1 am 2 b2 c2 ∈ L for large n and m, we need at least three subderivations of the form
D1 : A1 ⇒∗ x1 A1 y1 , ∗
D2 : A2 ⇒ x2 A2 y2 , ∗
D3 : A3 ⇒ x3 A3 y3
(2) (3) (4)
where x1 , x2 , x3 , y1 , y2 , y3 are powers of the symbols from Σ, i.e. xi = αki i and yi = βili where αi , βi ∈ Σ and ki + li ≥ 1, i = 1, 2, 3. Obviously, any of the subderivations (2)–(4) produces additional tokens at the counter or consumes tokens from the counter or does not change the number of tokens at the counter. According to the production and consumption of tokens by the subderivations (2)–(4) we distinguish some cases and show a contradiction in all cases. By reasons of space we discuss here only two cases (the other ones can be handled analogously). Case I. One of the derivations (2)–(4) does not produce and consume any token at the counter. Without loss of generality we can assume that this derivation is (2). If S ⇒∗ uA1 v ⇒∗ uwv ∈ L then for any k > 1 we apply (2) k times and get a word which is not in L , i.e., S ⇒∗ uA1 v ⇒∗ ux1 A1 y1 v ⇒∗ ux21 A1 y12 v ⇒∗ uxk1 A1 y1k v ⇒∗ uxk1 wy1k v ∈ L since (2) increases only the powers of at most two symbols. Case II. The subderivation (2) produces p ≥ 1 tokens, the subderivation (3) consumes q ≥ 1 tokens, {α1 , β1 , α2 , β2 } ∩ {ai , bi , ci } = ∅ for 1 ≤ i ≤ 2, and there is a derivation S ⇒∗ u1 A1 u2 A2 u3 ⇒∗ u1 w1 u2 w2 u3 ∈ L . Then the derivation S ⇒∗ u1 A1 u2 A2 u3 ⇒∗ u1 x1 A1 y1 u2 A2 u3 ⇒∗ u1 xk1 A1 y1k u2 A2 u3 ⇒∗ u1 xk1 A1 y1k u2 x2 A2 y2 u3 ⇒∗ u1 xk1 A1 y1k u2 xl2 A2 y2l u3 ⇒∗ u1 xk1 w1 y1k u2 xl2 w2 y2l u3
k-Petri Net Controlled Grammars
215
where k, l ≥ 1, should be in G. It can be done by choosing the numbers k, l and the symbols α1 , β1 , α2 , β2 ∈ Σ ∪ {λ}. If we choose k = q and l = p, then we also come to the final marking (kp−lq = 0). By the supposition 1 ≤ |{α1 , β1 , α2 , β2 } ∩ {ai , bi , ci }| ≤ 2 for at least one i, 1 ≤ i ≤ 2. Thus at most two letters from {ai , bi , ci } are changed in there power.
4
Hierarchy Results
We start with a simple fact. Lemma 10. CF PN1 . Proof. It is clear that CF ⊆ PN1 if we take T1 = T2 = ∅. From Example 7 it follows that CF PN1 .
Now we present some relations to (positive) additive valence languages. Lemma 11. PN1 ⊆ pV and PNλ1 ⊆ pVλ . Proof. Let G = (V, Σ, S, R, N1 ) where N1 = (P, T, F, ϕ, ι, M ) is the corresponding 1-PN with the counter q (with the notions of Definition 4) be a 1-PN controlled grammar (with or without erasing rules). We define a positive valence grammar G = (V, Σ, S, R, v) where V, Σ, S, R are defined as for the grammar G and for each r ∈ R, the mapping v is defined by v(r) = 1 if γ −1 (r) ∈ • q, v(r) = −1 if γ −1 (r) ∈ q • and v(r) = 0 otherwise. π Let S = ⇒ w ∈ Σ ∗ , π = r1 r2 · · · rk be a derivation in G. Then ν = t1 t2 · · · tk , ti = γ −1 (ri ), 1 ≤ i ≤ k is an occurrence sequence of transitions in N1 enabled at the initial marking ι and finished at a final marking τ . By definition if |ν|t > 0 for some t ∈ • q then there is a transition t ∈ q • such that |ν|t > 0. Let U1 = {t11 , t12 , . . . , t1k(1) } ⊆ • q where |ν|t1j > 0, 1 ≤ j ≤ k(1) and U2 = {t21 , t22 , . . . , t2k(2) } ⊆ q • where |ν|t2j > 0, 1 ≤ j ≤ k(2). As μi (q) ≥ 0 for any occurrence step 1 ≤ i ≤ k we have |ν|U1 ≥ |ν|U2 , consequently, v(r1 ) + v(r2 ) + . . . + v(rj ) ≥ 0 for any 1 ≤ j < k and from ι(q) = def n τ (q) = 0, τ ∈ M , it follows that t∈U1 |ν|t − t∈U2 |ν|t = i=1 v(ri ) = 0. Hence, L(G) ⊆ L(G ). π Let D : S = ⇒ w ∈ Σ ∗ , π = r1 r2 · · · rk be a derivation in G where v(r1 ) + v(r2 ) + . . . + v(rk ) = 0 and v(r1 ) + v(r2 ) + . . . + v(rj ) ≥ 0 for any 1 ≤ j < k. By construction of G D is a derivation in (V, Σ, S, R). According to the bijection γ : T → R, there is an occurrence sequence in N1 : ν μ0 − → μk , ν = t1 t2 · · · tk such that ti = γ −1 (ri ), 1 ≤ i ≤ k. μ0 = ι as D starts from S, i.e. μ0 (β −1 (S)) = 1 and μ0 (β −1 (x)) = 0 for all x ∈ (V ∪ Σ) \ {S} as well as μ0 (q) = 0. Since w ∈ Σ ∗ for the last marking, we have μk (β −1 (x)) = 0 for all x ∈ j V . From i=1 v(ri ) ≥ 0, it follows that μi (q) ≥ 0 for any 1 ≤ j < k. Also k def γ −1 (r)∈ • q v(r) + γ −1 (r)∈q• v(r) = 0 shows that in k steps the i=1 v(ri ) = counter place q has received and given the same number of tokens, i.e. μk (q) = 0. Hence μk ∈ M . Consequently, L(G ) ⊆ L(G).
216
J. Dassow and S. Turaev
Lemma 12. aV PN2 and aVλ PN2 λ . Proof. Let G = (V, Σ, S, R, v) be an additive valence grammar (with or without erasing rules). Without loss of generality we can assume that v(r) ∈ {1, 0, −1} for each r ∈ R (theorem 2.1.10 in [4]). For each rule r : A → α ∈ R, v(r) = 0 we add a nonterminal symbol Ar and a pair of rules r : A → Ar , r : Ar → α and set V = V ∪ {Ar | r : A → α ∈ R, v(r) = 0}, R = R ∪ {r : A → Ar , r : Ar → α | r : A → α ∈ R, v(r) = 0}. Let N = (P, T, F, ϕ, ι) be the cf Petri net corresponding to (V , Σ, S, R ). We construct 2-PN N2 = (P , T , F , ϕ , ι, M ) by adding the counter places q, q and the arcs: (t, q), t = γ −1 (r) for each r ∈ R, v(r) = 1 and (q, t), t = γ −1 (r) for each r ∈ R, v(r) = −1, (t , q ), t = γ −1 (r ) for each r ∈ R, v(r) = −1, (q , t ), t = γ −1 (r ) for each r ∈ R, v(r) = 1. The value of the weight function ϕ for each new arc is 1. Consider 2-PN controlled grammar G = (V , Σ, S, R , N2 ). L(G ) ⊆ L(G) is obvious: according to the definitions of the initial and final markings for the counter places q and q , i.e. ι(q) = ι(q ) = 0 and for any τ ∈ M , n r1 r2 ···rn τ (q) = τ (q ) = 0, we have i=1 v(ri ) = 0, for any derivation S == ===⇒ w ∈ Σ ∗ . r1 r2 ···rn =====⇒ w ∈ Σ ∗ be a derivation in G. For any 1 ≤ k ≤ n Let S (1) if ki=1 v(ri ) > 0 then for the rule rk+1 , v(rk+1 ) ∈ {1, 0, −1} in G, we also choose the rule rk+1 in G ; k (2) if i=1 v(ri ) ≤ 0 then (a) for the rule rk+1 , v(rk+1 ) = 0 in G, we choose and rk+1 in G ; (b) for the rule rk+1 , v(rk+1 ) = 0 in G then we the rules rk+1 also choose rk+1 . Hence, w ∈ L(G ). m m The strict inclusion follows from the fact that {an1 bn1 cn1 am 2 b2 c2 | n, m ≥ 1} ∈ PN2 cannot be generated by an additive valence grammar (Example 2.1.7 in [4]).
The following lemma shows that, for any n ≥ 1, an n-PN controlled grammar generates a vector language. Lemma 13. For any n ≥ 1, PNn ⊆ V and PNλn ⊆ Vλ . Theorem 14. For k ≥ 1, PNk PNk+1 and PNλk PNλk+1 . Proof. We first prove that PN1 ⊆ PN2 . Let G = (V, Σ, S, R, N1 ) be a 1-PN controlled grammar (with or without erasing rules) where N1 = (P, T, F, ϕ, ι, M ) 1-PN with the counter place q. Let • q = {t11 , t12 , . . . , t1k(1) }, k(1) ≥ 1 and q • = {t21 , t22 , . . . , t2k(2) }, k(2) ≥ 1 where tij = γ −1 (rij ), rij : Aij → wij , 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i) and by definition • q ∩ q • = ∅. We set V = V ∪ {Aij | 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i)} where Aij , 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i) are new nonterminal symbols. For each rule rij : Aij → wij , 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i) we add the new rules rij : Aij → Aij , rij : Aij → wij and we consider the 2-PN controlled grammar G = (V , Σ, S, R , N2 ) where R consists of all rules of R and all rules constructed above. Let pij = β −1 (Aij ) where Aij → wij , 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i). We add the new places and transitions: pij , tij , tij , 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i) and
k-Petri Net Controlled Grammars
217
define extended bijections β and γ by β(p) = β(p) if p ∈ P and β(p) = Aij if p = pij , 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i), and γ (t) = γ(t) if t ∈ T , γ (t) = rij if t = tij and γ (t) = rij if t = tij , 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i). Let q be a new counter place. We construct 2-PN N2 = (P , T , F , ϕ , ι , M ) corresponding to the grammar (V , Σ, S, R ) where P = P ∪ {pij | 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i)} ∪ {q }, T = T ∪ {tij | 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i)} ∪ {tij | 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i)}, F = F ∪ {(pij , tij ) | 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i)} ∪ {(tij , pij ) | 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i)} ∪ {(pi,j , ti,j ) | 1 ≤ i ≤ 2, 1 ≤ j ≤ s(i)} ∪ {(tij , p) | p = β −1 (x), |wij |x > 0, 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i)} ∪ {(tij , q ) | 1 ≤ j ≤ k(1)} ∪ {(q , t2j ) | 1 ≤ j ≤ k(2)}. For the weight function we set ϕ (x, y) = ϕ(x, y) if (x, y) ∈ F and ϕ (x, y) = 1, otherwise. The initial and final markings are defined by ι (β−1 (S)) = 1, ι (p) = 0 for all p ∈ P \{β−1 (S)} and for any τ ∈ M , τ (p) = 0 for all p ∈ P \{β−1 (x) | x ∈ Σ}. The inclusion L(G) ⊆ L(G ) is obvious, it follows from the construction of G . π Let S = ⇒ w, π = r1 r2 · · · rn be a derivation in G with the occurrence sequence ν = t1 t2 · · · tn of transitions N2 where ti = γ −1 (ri ), 1 ≤ i ≤ n enabled at ι and finished at τ ∈ M . It is obvious that if for some 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i) a production rule > 0, > 0, = |π|r . rij : Aij → Aij then |π|rij rij : Aij → wij , and |π|rij |π|rij ij Without loss of generality we can assume that a rule rij is the next to a rule rij in π (as to the nonterminal Aij only the rule rij is applicable and we can change the order in which the derivation π is used). Then we can replace any derivation x1 A x2 ⇒r x1 wij x2 by x1 Aij x2 ⇒r steps of the form x1 Aij x2 ⇒rij ij x1 wij x2 . ij ij tij
t ij
tij
Accordingly, the occurrence sequence μ −−→ μ −−→ μ is replaced by μ −−→ μ where tij = γ −1 (rij ), tij = γ −1 (rij ) and tij = γ −1 (rij ), 1 ≤ i ≤ 2, 1 ≤ j ≤ k(i). Clearly, L(G ) ⊆ L(G). Let us consider the general case k ≥ 1. Let G = (V, Σ, S, R, Nk ) be a k-PN controlled grammar (with or without erasing rules) where Nk = (P, T, F, ϕ, ι, M ) is a k-PN with the counters q1 , q2 , . . . , qk . We can repeat the arguments of the proof for k = 1 considering qk instead of q and adding the new counter place qk+1 . For k ≥ 1, let the language Lk be defined by Lk = {
k i=1
ani i bni i cni i | ni ≥ 1, 1 ≤ i ≤ k}.
218
J. Dassow and S. Turaev
Then we can show analogously to Example 8 and Lemma 9 that, for k ≥ 1, Lk+1 ∈ PNk+1 and Lk+1 ∈ PNk . Thus the inclusions are strict.
5
Closure Properties
We define the following binary form for k-PN controlled grammars, which will be used in some of the next proofs. Definition 15. A k-PN controlled grammar G = (V, Σ, S, R, Nk ) is said to be in a binary form if for each rule A → α the length of the α is not greater than 2, i.e. |α| ≤ 2. Lemma 16 (Binary Form). For each k-PN controlled grammar there exists an equivalent k-PN controlled grammar in the binary normal form. Lemma 17 (Union). The family of languages PNk , k ≥ 1 is closed under union. Proof. Let G1 = (V1 , Σ1 , S1 , R1 , Nk1 ) and G2 = (V2 , Σ2 , S2 , R2 , Nk2 ) be k-PN controlled grammars. We assume (without loss of generality) that V1 ∩V2 = ∅. Let (Pi , Ti , Fi , ϕi , ιi ) be the cf Petri net corresponding to the context-free grammar (Vi , Σi , Si , Ri ), i = 1, 2 and let Qi = {qij | i = 1, 2, 1 ≤ j ≤ k}, i = 1, 2 be the set of the counters. Then k-PN is defined by Nki = (Pi ∪ Qi , Ti , Fi ∪ Fi1 ∪ Fi2 , ϕi , ιi , Mi ), i = 1, 2 (with the notions of Definition 4). We construct the k-PN controlled grammar G = (V1 ∪ V2 ∪ {S}, Σ1 ∪ Σ2 , S, R1 ∪ R2 ∪ {S → S1 , S → S2 }, Nk ) where Nk = (P, T, F, ϕ, ι, M ) is defined by – P = P1 ∪ P2 ∪ Q1 ∪ {q} where q is labeled by S; – T = T1 ∪ T2 ∪ {t01 , t02 } where t01 and t02 are labeled by the rules S → S1 and S → S2 , respectively; – F = F1 ∪ F2 ∪ F11 ∪ F12 ∪ {(q, t0i ), (t0i , q0i ) | i = 1, 2} ∪ {(t, q1i ) | (t, q2i ) ∈ F21 , 1 ≤ i ≤ k} ∪ {(q1i , t) | (q2i , t) ∈ F22 , 1 ≤ i ≤ k} where q0i is labeled by Si , i = 1, 2; – ϕ(x, y) = ϕi (x, y) if (x, y) ∈ Fi , i = 1, 2 and ϕ(x, y) = 1 otherwise; – ι(q) = 1, ι(q01 ) = ι(q02 ) = 0 and τ (q) = τ (q01 ) = τ (q02 ) = 0 for any τ ∈ M ι(p) = ιi (p) and for any τ ∈ M , τ (p) = τi (p) if p ∈ Pi \ {q0i }, i = 1, 2; ι(p) = 0 and for any τ ∈ M , τ (p) = 0 if p ∈ Q1 . By the construction of Nk any occurrence of its transitions can start by firing of t01 or t02 then transitions of T1 or transitions of T2 can occur, correspondingly we start a derivation with the rule S → S1 or S → S2 then we can use rules of R1 or R2 . A string w is in L(G) iff there is a derivation S ⇒ Si ⇒∗ w ∈ L(Gi ), i = 1, 2. On the other hand, we can initialize any derivation Si ⇒∗ w ∈ L(Gi ) with the rule S → Si , i = 1, 2, i.e. w ∈ L(G).
k-Petri Net Controlled Grammars
219
Lemma 18 (Concatenation). The family of languages PNk , k ≥ 1 is not closed under concatenation. Proof. Let Lk be the language given at the end of the proof of Theorem 14. / PNk . Then Lk ∈ PNk and L2k = Lk · Lk ∈ Using the standard proof we can show that Lemma 19. For L1 ∈ PNk , k ≥ 1 and L2 ∈ PNm , m ≥ 1, L1 · L2 ∈ PNk+m . Lemma 20 (Substitution). The family of languages PNk , k ≥ 1 is closed under substitution by context-free languages. Proof. Let G = (V, Σ, S, R, Nk ) be a k-PN controlled grammar with k-Petri net Nk = (P, T, F, ϕ, ι, M ). Let P = PV ∪ PΣ where PV = {p | p = β −1 (A), A ∈ V } ∗ and PΣ = {p | p = β −1 (a), a ∈ Σ}. We consider a substitution s : Σ ∗ → 2U with s(a) ∈ CF for each a ∈ Σ. Let Ga = (Va , Σa , Sa , Ra ) be a context-free grammar for s(a), a ∈ Σ. We can assume that V ∩ Va = ∅ for any a ∈ Σ and Va ∩ Vb = ∅ for any a, b ∈ Σ, a = b. Let Na = (Pa , Ta , Fa , ϕa , ιa ) be the corresponding cf Petri net to Ga , a ∈ Σ with the bijections βa and γa . For each place p ∈ PΣ we replace its label and we define the k-PN controlled grammar G = a = β(p) by Sa in Nk (V ∪ a∈Σ Va , U, S, R ∪ a∈Σ Ra , Nk ) where R is the set of rules obtained by replacing of a ∈ Σ by Sa in R and Nk is defined by each occurrence Nk = (P ∪ a∈Σ Pa , T ∪ a∈Σ Ta , F ∪ a∈Σ Fa , ϕ , ι , M ) where – ϕ (x, y) = ϕ(x, y) if (x, y) ∈ F and ϕ (x, y) = ϕa (x, y) if (x, y) ∈ Fa , a ∈ Σ; – ι (p) = ι(p) if p ∈ P and ι (p) = 0 if p ∈ Pa , a ∈ Σ; – for any τ ∈ M , τ (p) = 0 if p ∈ P or p ∈ Pa \ {βa−1 (b) | b ∈ Σa }, a ∈ Σ. Obviously, L(G ) ∈ PNk .
Lemma 21 (Mirror Image). The family of languages PNk , k ≥ 1 is closed under mirror image. Proof. Let G = (V, Σ, S, R, Nk ) be a k-PN controlled grammar. The context-free grammar (V, Σ, S, R) and its reversal (V, Σ, S, RR ) have the same corresponding cf Petri net N = (P, T, F, ϕ, ι) as N does not preserve the order of the positions of the output places for each transition. Thus we can also use the k-Petri net Nk as a control mechanism for the grammar (V, Σ, S, RR ), i.e. we define GR = (V, Σ, S, RR , Nk ). Clearly, L(GR ) ∈ PNk .
Lemma 22 (Intersection with Regular Languages). The family of languages PNk , k ≥ 1 is closed under intersection with regular languages. The results of the previous lemmas are summarized in the following theorem Theorem 23. The family of languages PNk , k ≥ 1 is closed under union, substitution, mirror image, intersection with regular languages and it is not closed under concatenation.
220
J. Dassow and S. Turaev
References 1. ter Beek, M.H., Kleijn, H.C.M.: Petri net control for grammar systems. In: Brauer, W., Ehrig, H., Karhum¨ aki, J., Salomaa, A. (eds.) Formal and Natural Computing. LNCS, vol. 2300, pp. 220–243. Springer, Heidelberg (2002) 2. Ceska, M., Marek, V.: Petri nets and random-context grammars. In: Proc. 35th Spring Conference: Modeling and Simulation of Systems (MOSIS 2001), MARQ Ostrava Hardec nad Moravici, pp. 145–152 (2001) 3. Crespi-Reghizzi, S., Mandrioli, D.: Petri nets and commutative grammars. Internal Report No. 74-5, Laboratorio di Calcolatori, Instituto de Elettrotecnica ed Elettronica del Politecnico di Milano, Italy (1974) 4. Dassow, J., Pˇ aun, G.: Regulated rewriting in formal language theory. Springer, Berlin (1989) 5. Hack, M.: Petri net languages. Computation Structures Group Memo 124, p. 128. MIT, Cambridge (1975) 6. Hauschildt, D., Jantzen, M.: Petri nets algorithms in the theory of matrix grammars. Acta Informatica 31, 719–728 (1994) 7. Hopcroft, J.E., Ullman, J.D.: Introduction to automata theory, languages, and computation. Addison-Wesley Longman Publishing Co., Inc, Amsterdam (1990) 8. Reisig, W., Rozenberg, G. (eds.): Lectures on Petri nets I: Basic models. LNCS, vol. 1491. Springer, Heidelberg (1998) 9. Turaev, S.: Petri Net Controlled Grammars. In: Proc. 3rd Doctoral Workshop on MEMICS-2007, Znojmo, Czech Republic, pp. 233–240 (2007)