Professional Documents
Culture Documents
show that (i) L(G) has no strings of odd length, (ii) any string in L(G) is of
Solution
two terminals and at the most one variable. So, every step in any derivation
To prove (iii), consider any string 11' of length 2n. Then it is of the form
([1([2 ... al/a/1 ... ([1 involving n 'parameters' aj, a2, ..., ([11' Each ai can be
In the definition of a grammar (V.v, 2:, P, S), VV and 2: are the sets of symbols
the left context, ljf the right context and rpcxlfl the replacement string.
EXAMPLE 4.1 5
(a) In abdbed abABbed, ab is the left context, bed is the right context.
ex = AS-
production simply erases C when the left context is A and the right
context is A
(c) For C A. the left and right contexts are A. And CX = A. The
EXAMPLE 4.16
(a) adbeD ---7 ({beDbeD is a type 1 production where where a, beD are the
(b) All AbBe is a type 1 production. The left context is A, the right
context is A
(C) A abA is a type 1 production. Here both the left and right contexts
are A.
is also allowed in a type 1 grammar. but in this case S does not appear on the
in L(G). Apart from S -1 A, all the other productions do not decrease the
A type 1 production epA Iff dJalff does not increase the length of the
working string. In other words, i epA Iff I ::; ! ep alff I as a =;t: A. But if a f3
is a production such that I a I ::; I13 I, then it need not be a type 1 production.
L type 2 or type 3.
a and f3 we replace every terminal by a new variable Cu and get a' and f3'.
construct a' f3' and productions of the form Ca a for every terminal
a appearing in a or 13. The construction is performed for every such a 13. The
productions for G] are the new productions we have obtained through the above
construction. For G] the variables are the variables of G together with the new
variables (of the form C,,). The terminals and the start symbol of G] are those
L(G]). I
or 5 A. In the second case,S does not appear on the right-hand side of any
production in P.
type 1 (with left and right contexts being A). Suppose In ::::: 2. Conesponding
Aj A2 ... Am C] A2 ... Am
is not of type 1 as we replace more than one symbol on L.R.S. In the chain of
type 1. For the new grammar G'. the variables are the variables of Gl together
with the new variables. The productions of G' are the new type 1 productions
obtained through the above construction. The tenninals and the start symbol
where A E Vv and CI. E lVv U L)*. In other words. the L.R.S. has no left
type 2 productions.
grammar. but in this case S does not appear on the right-hand side of any
production.
EXAMPLE 4.1 7
Find the highest type number which can be applied to the following
productions:
(a)
(b)
(el
S Aa. A
S ASB Id,
S as Iab
elBa.
A aA
B abc
Solution
type number is 2.
number is 2.
In this section we discuss the relation between the classes of languages that we
Let xes), J cfl and denote the family of type 0 languages, context-
proves S
context- free but not regular. The gramm.ar given in Example 4.5 is regular. The
grammars given in Examples 4.10 and 4.11 are not context-sensitive as we have
productions of the form 2A) All, CB BC which are not type 1 rules. But
2. Two grammars of different types may generate the same language. For
{a. b}+. Let G/be given by S SSla5IbSla!b. Then L(G') =L(G) as the
The results given in this section will be used to prove £cs1 e" £0 in Section 9.7.
whether S A is in P or not.
{Wd of subsets of (Vv u I)*. Wi is simply the set of all sentential forms of
(i) Wo = is}.
(ii) Wi
(iii) Wi Wi
11. If IVv u I I = 111, then N = 1 + m + 111 2 + ... + mil since mi is the number
IWi I ::;; N. Therefore, Wk = Wk+1 for some k ::;; N. This proves the point (iv).
= W1 U W2 U U Wk
From the point (v) it follows that W E L(G) (i.e. S w) if and only if
W E W~. Also. Wi, W2, •.•, Wk can be constructed in a finite number of steps.
Algorithm to test whether w E L(G). 1. Construct Wi, W2• ... using the
points (i) and (ii). We terminate the construction when Wk+] = Wk for the first
time.
EXAMPlE 4.18
lA] 11. Test whether (a) 00112 E L(G) and (b) 001122 E L(G).
Solution
(a) To test whether w =00112 E L(G), we construct the sets Wo, WI, W2
etc. Iwl = 5.
Wo= {S}
W] = {012, S, OSA]2}
Wo = {012, S, OSA I2}
include 0012A]2 in W] as its length is> 5.) Then 00112 E WI' Hence,
00112 E LCG).
Wo= {S}
W] = {012. S, OSA]2}
exists a recursive set over {O, I} which is not a context-sensitive language. The
proof is by the diagonalization method which is used quite often in set theory.
Proof Let 2: = {O, I}. We write the elements of 2:* as a sequence (i.e. the
elements of 2:* are enumerated as the first element, second element, etc.) For
example, one such way of writing is A, 0, I, 00, 01, 10, 11, 000, .... In this
set of productions, we can also write all context-sensitive grammars over 2.: as
We define X ={>Vi E 2.:* IWi r;z: L(G;)}. We can show that X is recursive.
If W E 2.:*, then we can find i such that W = >Vi' This can be done in a finite
number of steps (depending on IW 1). For example, if >v = 0100, then W = W20'
As G20 is context-sensitive, we have an algorithm to test whether vI' =W20 E
is so, then X = L(G,,) for some n. Consider w" (the 11th element in 2.:*). By
W n r;z: X implies W n E L(Gn) and once again, this contradicts X = L(Gn). Thus,
We consider the effect of applying set operations on £0, £c51' ;[efl, elr!. Let
AT = {Ill U E A}
Theorem 4.5 Each of the classes ;[0, , £ef); elr] is closed under union.
Proof Let L I and L2 be two languages of the same type i. We can apply
and
a E 2.:.
We can further assume that V;v n V';; =0. (This is achieved by renaming
52 => w. Therefore, G,
Go
Gu Gu
Thus, L j U L2 L(G,).
5: is changed. As Vi.: (l V;": :f:- 0, these steps should involve only the variables
G,
first step is 5 52, then 5 => 52 w. Thus, L(G,,) =Ll U L2. Also, L(G,J
G, G,
N U V',~ U {5}, and (ii) P" = Pi U P2 U {5' -? 5, 5 -? 5\> 5 -? 52}' So, L(Gu ) is of type 1 or type 3
Theorem 4.6 Each of the classes ,10, L es \> L cf\> ;irl is closed under
concatenation.
get G j = CV:v, I\> Pl, 51) and G2 = (V':v , I:, P2, 52) of the same type i. We
Geon =(V'
where 5 e: V~v U V(
Peon = Pl U P2 U {5 -? 5i52}
* 51 => lVI'
G,
So,
Geoa