Formal Languages and Automata Theory. D. Goswami and K. V. Krishna

Size: px
Start display at page:

Download "Formal Languages and Automata Theory. D. Goswami and K. V. Krishna"

Transcription

1 Forml Lnguges nd Automt Theory D. Goswmi nd K. V. Krishn Novemer 5, 2010

2 Contents 1 Mthemticl Preliminries 3 2 Forml Lnguges Strings Lnguges Properties Finite Representtion Regulr Expressions Grmmrs Context-Free Grmmrs Derivtion Trees Amiguity Regulr Grmmrs Digrph Representtion Finite Automt Deterministic Finite Automt Nondeterministic Finite Automt Equivlence of NFA nd DFA Heuristics to Convert NFA to DFA Minimiztion of DFA Myhill-Nerode Theorem Algorithmic Procedure for Minimiztion Regulr Lnguges Equivlence of Finite Automt nd Regulr Lnguges Equivlence of Finite Automt nd Regulr Grmmrs Vrints of Finite Automt Two-wy Finite Automton Mely Mchines

3 5 Properties of Regulr Lnguges Closure Properties Set Theoretic Properties Other Properties Pumping Lemm

4 Chpter 1 Mthemticl Preliminries 3

5 Chpter 2 Forml Lnguges A lnguge cn e seen s system suitle for expression of certin ides, fcts nd concepts. For formlizing the notion of lnguge one must cover ll the vrieties of lnguges such s nturl (humn) lnguges nd progrmming lnguges. Let us look t some common fetures cross the lnguges. One my rodly see tht lnguge is collection of sentences; sentence is sequence of words; nd word is comintion of syllles. If one considers lnguge tht hs script, then it cn e oserved tht word is sequence of symols of its underlying lphet. It is oserved tht forml lerning of lnguge hs the following three steps. 1. Lerning its lphet - the symols tht re used in the lnguge. 2. Its words - s vrious sequences of symols of its lphet. 3. Formtion of sentences - sequence of vrious words tht follow certin rules of the lnguge. In this lerning, step 3 is the most difficult prt. Let us postpone to discuss construction of sentences nd concentrte on steps 1 nd 2. For the time eing insted of completely ignoring out sentences one my look t the common fetures of word nd sentence to gree upon oth re just sequence of some symols of the underlying lphet. For exmple, the English sentence "The English rticles -, n nd the - re ctegorized into two types: indefinite nd definite." my e treted s sequence of symols from the Romn lphet long with enough punctution mrks such s comm, full-stop, colon nd further one more specil symol, nmely lnk-spce which is used to seprte two words. Thus, strctly, sentence or word my e interchngely used 4

6 for sequence of symols from n lphet. With this discussion we strt with the sic definitions of lphets nd strings nd then we introduce the notion of lnguge formlly. Further, in this chpter, we introduce some of the opertions on lnguges nd discuss lgeric properties of lnguges with respect to those opertions. We end the chpter with n introduction to finite representtion of lnguges vi regulr expressions. 2.1 Strings We formlly define n lphet s non-empty finite set. We normlly use the symols,, c,... with or without suscripts or 0, 1, 2,..., etc. for the elements of n lphet. A string over n lphet Σ is finite sequence of symols of Σ. Although one writes sequence s ( 1, 2,..., n ), in the present context, we prefer to write it s 1 2 n, i.e. y juxtposing the symols in tht order. Thus, string is lso known s word or sentence. Normlly, we use lower cse letters towrds the end of English lphet, nmely z, y, x, w, etc., to denote strings. Exmple Let Σ = {, } e n lphet; then,,,,... re some exmples of strings over Σ. Since the empty sequence is finite sequence, it is lso string. Which is ( ) in erlier nottion; ut with the nottion dpted for the present context we require specil symol. We use ε, to denote the empty string. The set of ll strings over n lphet Σ is denoted y Σ. For exmple, if Σ = {0, 1}, then Σ = {ε, 0, 1, 00, 01, 10, 11, 000, 001,...}. Although the set Σ is infinite, it is countle set. In fct, Σ is countly infinite for ny lphet Σ. In order to understnd some such fundmentl fcts we introduce some string opertions, which in turn re useful to mnipulte nd generte strings. One of the most fundmentl opertions used for string mnipultion is conctention. Let x = 1 2 n nd y = 1 2 m e two strings. The conctention of the pir x, y denoted y xy is the string 1 2 n 1 2 m. 5

7 Clerly, the inry opertion conctention on Σ is ssocitive, i.e., for ll x, y, z Σ, x(yz) = (xy)z. Thus, x(yz) my simply e written s xyz. Also, since ε is the empty string, it stisfies the property εx = xε = x for ny sting x Σ. Hence, Σ is monoid with respect to conctention. The opertion conctention is not commuttive on Σ. For string x nd n integer n 0, we write x n+1 = x n x with the se condition x 0 = ε. Tht is, x n is otined y conctenting n copies of x. Also, whenever n = 0, the string x 1 x n represents the empty string ε. Let x e string over n lphet Σ. For Σ, the numer of occurrences of in x shll e denoted y x. The length of string x denoted y x is defined s x = x. Σ Essentilly, the length of string is otined y counting the numer of symols in the string. For exmple, = 3, = 1. Note tht ε = 0. If we denote A n to e the set of ll strings of length n over Σ, then one cn esily scertin tht Σ = A n. n 0 And hence, eing A n finite set, Σ is countly infinite set. We sy tht x is sustring of y if x occurs in y, tht is y = uxv for some strings u nd v. The sustring x is sid to e prefix of y if u = ε. Similrly, x is suffix of y if v = ε. Generlizing the nottion used for numer of occurrences of symol in string x, we dopt the nottion y x s the numer of occurrences of string x in y. 2.2 Lnguges We hve got cquinted with the forml notion of strings tht re sic elements of lnguge. In order to define the notion of lnguge in rod spectrum, it is felt tht it cn e ny collection of strings over n lphet. Thus we define lnguge over n lphet Σ s suset of Σ. 6

8 Exmple The emptyset is lnguge over ny lphet. Similrly, {ε} is lso lnguge over ny lphet. 2. The set of ll strings over {0, 1} tht strt with The set of ll strings over {,, c} hving c s sustring. Remrk Note tht {ε}, ecuse the lnguge does not contin ny string ut {ε} contins string, nmely ε. Also it is evident tht = 0; wheres, {ε} = 1. Since lnguges re sets, we cn pply vrious well known set opertions such s union, intersection, complement, difference on lnguges. The notion of conctention of strings cn e extended to lnguges s follows. The conctention of pir of lnguges L 1, L 2 is Exmple L 1 L 2 = {xy x L 1 y L 2 }. 1. If L 1 = {0, 1, 01} nd L 2 = {1, 00}, then L 1 L 2 = {01, 11, 011, 000, 100, 0100}. 2. For L 1 = {,, } nd L 2 = {ε,,, }, we hve L 1 L 2 = {,,,,,,,, }. Remrk Since conctention of strings is ssocitive, so is the conctention of lnguges. Tht is, for ll lnguges L 1, L 2 nd L 3, (L 1 L 2 )L 3 = L 1 (L 2 L 3 ). Hence, (L 1 L 2 )L 3 my simply e written s L 1 L 2 L The numer of strings in L 1 L 2 is lwys less thn or equl to the product of individul numers, i.e. 3. L 1 L 1 L 2 if nd only if ε L 2. L 1 L 2 L 1 L 2. 7

9 Proof. The if prt is strightforwrd; for instnce, if ε L 2, then for ny x L 1, we hve x = xε L 1 L 2. On the other hnd, suppose ε / L 2. Now, note tht string x L 1 of shortest length in L 1 cnnot e in L 1 L 2. This is ecuse, if x = yz for some y L 1 nd nonempty string z L 2, then y < x. A contrdiction to our ssumption tht x is of shortest length in L 1. Hence L 1 L 1 L Similrly, ε L 1 if nd only if L 2 L 1 L 2. We write L n to denote the lnguge which is otined y conctenting n copies of L. More formlly, L 0 = {ε} nd L n = L n 1 L, for n 1. In the context of forml lnguges, nother importnt opertion is Kleene str. Kleene str or Kleene closure of lnguge L, denoted y L, is defined s L = n 0 L n. Exmple Kleene str of the lnguge {01} is {ε, 01, 0101, ,...} = {(01) n n 0}. 2. If L = {0, 10}, then L = {ε, 0, 10, 00, 010, 100, 1010, 000,...} Since n ritrry string in L n is of the form x 1 x 2 x n, for x i L nd L = n 0 L n, one cn esily oserve tht L = {x 1 x 2 x n n 0 nd x i L, for 1 i n} Thus, typicl string in L is conctention of finitely mny strings of L. Remrk Note tht, the Kleene str of the lnguge L = {0, 1} over the lphet Σ = {0, 1} is L = L 0 L L 2 = {ε} {0, 1} {00, 01, 10, 11} = {ε, 0, 1, 00, 01, 10, 11, } = the set of ll strings over Σ. Thus, the erlier introduced nottion Σ is consistent with the nottion of Kleene str y considering Σ s lnguge over Σ. 8

10 The positive closure of lnguge L is denoted y L + is defined s L + = n 1 L n. Thus, L = L + {ε}. We often cn esily descrie vrious forml lnguges in English y stting the property tht is to e stisfied y the strings in the respective lnguges. It is not only for elegnt representtion ut lso to understnd the properties of lnguges etter, descriing the lnguges in set uilder form is desired. Consider the set of ll strings over {0, 1} tht strt with 0. Note tht ech such string cn e seen s 0x for some x {0, 1}. Thus the lnguge cn e represented y {0x x {0, 1} }. Exmples 1. The set of ll strings over {,, c} tht hve c s sustring cn e written s {xcy x, y {,, c} }. This cn lso e written s {x {,, c} x c 1}, stting tht the set of ll strings over {,, c} in which the numer of occurrences of sustring c is t lest The set of ll strings over some lphet Σ with even numer of s is {x Σ x = 2n, for some n N}. Equivlently, {x Σ x 0 mod 2}. 3. The set of ll strings over some lphet Σ with equl numer of s nd s cn e written s {x Σ x = x }. 4. The set of ll plindromes over n lphet Σ cn e written s {x Σ x = x R }, where x R is the string otined y reversing x. 9

11 5. The set of ll strings over some lphet Σ tht hve n in the 5th position from the right cn e written s {xy x, y Σ nd y = 4}. 6. The set of ll strings over some lphet Σ with no consecutive s cn e written s {x Σ x = 0}. 7. The set of ll strings over {, } in which every occurrence of is not efore n occurrence of cn e written s { m n m, n 0}. Note tht, this is the set of ll strings over {, } which do not contin s sustring. 2.3 Properties The usul set theoretic properties with respect to union, intersection, complement, difference, etc. hold even in the context of lnguges. Now we oserve certin properties of lnguges with respect to the newly introduced opertions conctention, Kleene closure, nd positive closure. In wht follows, L, L 1, L 2, L 3 nd L 4 re lnguges. P1 Recll tht conctention of lnguges is ssocitive. P2 Since conctention of strings is not commuttive, we hve L 1 L 2 L 2 L 1, in generl. P3 L{ε} = {ε}l = L. P4 L = L =. Proof. Let x L ; then x = x 1 x 2 for some x 1 L nd x 2. But eing emptyset cnnot hold ny element. Hence there cnnot e ny element x L so tht L =. Similrly, L = s well. P5 Distriutive Properties: 1. (L 1 L 2 )L 3 = L 1 L 3 L 2 L 3. 10

12 Proof. Suppose x (L 1 L 2 )L 3 = x = x 1 x 2, for some x 1 L 1 L 2 ), nd some x 2 L 3 = x = x 1 x 2, for some x 1 L 1 or x 1 L 2, nd x 2 L 3 = x = x 1 x 2, for some x 1 L 1 nd x 2 L 3, = x L 1 L 3 or x L 2 L 3 = x L 1 L 3 L 2 L 3. or x 1 L 2 nd x 2 L 3 Conversely, suppose x L 1 L 3 L 2 L 3 = x L 1 L 3 or x L 2 L 3. Without loos of generlity, ssume x L 1 L 3. Then x L 2 L 3. = x = x 3 x 4, for some x 3 L 2 nd x 4 L 3 = x = x 3 x 4, for some x 3 L 1 L 2, nd some x 4 L 3 = x (L 1 L 2 )L 3. Hence, (L 1 L 2 )L 3 = L 1 L 3 L 2 L L 1 (L 2 L 3 ) = L 1 L 2 L 1 L 3. Proof. Similr to the ove. From these properties it is cler tht the conctention is distriutive over finite unions. Moreover, we cn oserve tht conctention is lso distriutive over countly infinite unions. Tht is, ( ) L L i = LL i nd i 1 i 1 ( ) L i L = L i L i 1 i 1 P6 If L 1 L 2 nd L 3 L 4, then L 1 L 3 L 2 L 4. P7 = {ε}. P8 {ε} = {ε}. P9 If ε L, then L = L +. P10 L L = LL = L +. 11

13 Proof. Suppose x L L. Then x = yz for some y L nd z L. But y L implies y = y 1 y n with y i L for ll i. Hence, x = yz = (y 1 y n )z = y 1 (y 2 y n z) LL. Converse is similr. Hence, L L = LL. Further, when x L L, s ove, we hve x = y 1 y n z is clerly in L +. On the other hnd, x L + implies x = x 1 x m with m 1 nd x i L for ll i. Now write x = x 1 x m 1 so tht x = x x m. Here, note tht x L ; prticulrly, when m = 1 then x = ε. Thus, x L L. Hence, L + = L L. P11 (L ) = L. P12 L L = L. P13 (L 1 L 2 ) L 1 = L 1 (L 2 L 1 ). Proof. Let x (L 1 L 2 ) L 1. Then x = yz, where z L 1 nd y = y 1 y n (L 1 L 2 ) with y i L 1 L 2. Now ech y i = u i v i, for u i L 1 nd v i L 2. Note tht v i u i+1 L 2 L 1, for ll i with 1 i n 1. Hence, x = yz = (y 1 y n )z = (u 1 v 1 u n v n )z = u 1 (v 1 u 2 v n 1 u n v n z) L 1 (L 2 L 1 ). Converse is similr. Hence, (L 1 L 2 ) L 1 = L 1 (L 2 L 1 ). P14 (L 1 L 2 ) = (L 1L 2). Proof. Oserve tht L 1 L 1 nd {ε} L 2. Hence, y properties P3 nd P6, we hve L 1 = L 1 {ε} L 1L 2. Similrly, L 2 L 1L 2. Hence, L 1 L 2 L 1L 2. Consequently, (L 1 L 2 ) (L 1L 2). For converse, oserve tht L 1 (L 1 L 2 ). Similrly, L 2 (L 1 L 2 ). Thus, L 1L 2 (L 1 L 2 ) (L 1 L 2 ). But, y property P12, we hve (L 1 L 2 ) (L 1 L 2 ) = (L 1 L 2 ) so tht L 1L 2 (L 1 L 2 ). Hence, (L 1L 2) ((L 1 L 2 ) ) = (L 1 L 2 ). 12

14 2.4 Finite Representtion Proficiency in lnguge does not expect one to know ll the sentences of the lnguge; rther with some limited informtion one should e le to come up with ll possile sentences of the lnguge. Even in cse of progrmming lnguges, compiler vlidtes progrm - sentence in the progrmming lnguge - with finite set of instructions incorported in it. Thus, we re interested in finite representtion of lnguge - tht is, y giving finite mount of informtion, ll the strings of lnguge shll e enumerted/vlidted. Now, we look t the lnguges for which finite representtion is possile. Given n lphet Σ, to strt with, the lnguges with single string {x} nd cn hve finite representtion, sy x nd, respectively. In this wy, finite lnguges cn lso e given finite representtion; sy, y enumerting ll the strings. Thus, giving finite representtion for infinite lnguges is nontrivil interesting prolem. In this context, the opertions on lnguges my e helpful. For exmple, the infinite lnguge {ε,,,,...} cn e considered s the Kleene str of the lnguge {}, tht is {}. Thus, using Kleene str opertion we cn hve finite representtion for some infinite lnguges. While opertions re under considertion, to give finite representtion for lnguges one my first look t the indivisile lnguges, nmely, {ε}, nd {}, for ll Σ, s sis elements. To construct {x}, for x Σ, we cn use the opertion conctention over the sis elements. For exmple, if x = then choose {} nd {}; nd conctente {}{}{} to get {}. Any finite lnguge over Σ, sy {x 1,..., x n } cn e otined y considering the union {x 1 } {x n }. In this section, we look t the spects of considering opertions over sis elements to represent lnguge. This is one spect of representing lnguge. There re mny other spects to give finite representtions; some such spects will e considered in the lter chpters Regulr Expressions We now consider the clss of lnguges otined y pplying union, conctention, nd Kleene str for finitely mny times on the sis elements. These lnguges re known s regulr lnguges nd the corresponding finite representtions re known s regulr expressions. Definition (Regulr Expression). We define regulr expression over n lphet Σ recursively s follows. 13

15 1., ε, nd, for ech Σ, re regulr expressions representing the lnguges, {ε}, nd {}, respectively. 2. If r nd s re regulr expressions representing the lnguges R nd S, respectively, then so re () (r + s) representing the lnguge R S, () (rs) representing the lnguge RS, nd (c) (r ) representing the lnguge R. In regulr expression we keep minimum numer of prenthesis which re required to void miguity in the expression. For exmple, we my simply write r + st in cse of (r + (st)). Similrly, r + s + t for ((r + s) + t). Definition If r is regulr expression, then the lnguge represented y r is denoted y L(r). Further, lnguge L is sid to e regulr if there is regulr expression r such tht L = L(r). Remrk A regulr lnguge over n lphet Σ is the one tht cn e otined from the emptyset, {ε}, nd {}, for Σ, y finitely mny pplictions of union, conctention nd Kleene str. 2. The smllest clss of lnguges over n lphet Σ which contins, {ε}, nd {} nd is closed with respect to union, conctention, nd Kleene str is the clss of ll regulr lnguges over Σ. Exmple As we oserved erlier tht the lnguges, {ε}, {}, nd ll finite sets re regulr. Exmple { n n 0} is regulr s it cn e represented y the expression. Exmple Σ, the set of ll strings over n lphet Σ, is regulr. For instnce, if Σ = { 1, 2,..., n }, then Σ cn e represented s ( n ). Exmple The set of ll strings over {, } which contin s sustring is regulr. For instnce, the set cn e written s {x {, } is sustring of x} = {yz y, z {, } } = {, } {}{, } Hence, the corresponding regulr expression is ( + ) ( + ). 14

16 Exmple The lnguge L over {0, 1} tht contins 01 or 10 s sustring is regulr. L = {x 01 is sustring of x} {x 10 is sustring of x} = {y01z y, z Σ } {u10v u, v Σ } = Σ {01}Σ Σ {10}Σ Since Σ, {01}, nd {10} re regulr we hve L to e regulr. In fct, t this point, one cn esily notice tht (0 + 1) 01(0 + 1) + (0 + 1) 10(0 + 1) is regulr expression representing L. Exmple The set of ll strings over {, } which do not contin s sustring. By nlyzing the lnguge one cn oserve tht precisely the lnguge is s follows. { n m m, n 0} Thus, regulr expression of the lnguge is nd hence the lnguge is regulr. Exmple The set of strings over {, } which contin odd numer of s is regulr. Although the set cn e represented in set uilder form s {x {, } x = 2n + 1, for some n}, writing regulr expression for the lnguge is little tricky jo. Hence, we postpone the rgument to Chpter 3 (see Exmple 3.3.6), where we construct regulr grmmr for the lnguge. Regulr grmmr is tool to generte regulr lnguges. Exmple The set of strings over {, } which contin odd numer of s nd even numer of s is regulr. As ove, set uilder form of the set is: {x {, } x = 2n + 1, for some n nd x = 2m, for some m}. Writing regulr expression for the lnguge is even more trickier thn the erlier exmple. This will e hndled in Chpter 4 using finite utomt, yet nother tool to represent regulr lnguges. Definition Two regulr expressions r 1 nd r 2 re sid to e equivlent if they represent the sme lnguge; in which cse, we write r 1 r 2. 15

17 Exmple The regulr expressions (10+1) nd ((10) 1 ) re equivlent. Since L((10) ) = {(10) n n 0} nd L(1 ) = {1 m m 0}, we hve L((10) 1 ) = {(10) n 1 m m, n 0}. This implies L(((10) 1 ) ) = {(10) n 1 1 m 1 (10) n 2 1 m2 (10) n l 1 m l m i, n i 0 nd 0 i l} l = {x 1 x 2 x k x i = 10 or 1}, where k = (m i + n i ) L((10 + 1) ). Conversely, suppose x L((10 + 1) ). Then, x = x 1 x 2 x p where x i = 10 or 1 i=0 = x = (10) p 1 1 q 1 (10) p 2 1 q2 (10) p r 1 q r for p i, q j 0 = x L(((10) 1 ) ). Hence, L((10+1) ) = L(((10) 1 ) ) nd consequently, (10+1) ((10) 1 ). From property P14, y choosing L 1 = {10} nd L 2 = {1}, one my notice tht ({10} {1}) = ({10} {1} ). Since 10 nd 1 represent the regulr lnguges {10} nd {1}, respectively, from the ove eqution we get (10 + 1) ((10) 1 ). Since those properties hold good for ll lnguges, y specilizing those properties to regulr lnguges nd in turn replcing y the corresponding regulr expressions we get the following identities for regulr expressions. Let r, r 1, r 2, nd r 3 e ny regulr expressions 1. rε εr r. 2. r 1 r 2 r 2 r 1, in generl. 3. r 1 (r 2 r 3 ) (r 1 r 2 )r r r. 5. ε. 6. ε ε. 16

18 7. If ε L(r), then r r rr r r r (r 1 + r 2 )r 3 r 1 r 3 + r 2 r r 1 (r 2 + r 3 ) r 1 r 2 + r 1 r (r ) r. 12. (r 1 r 2 ) r 1 r 1 (r 2 r 1 ). 13. (r 1 + r 2 ) (r1r 2). Exmple ( + ε) ( + ε) Proof. + ( + ε) ( ε) , since L( + ) L( + + ). Similrly, one cn oserve tht ( + ε) (0 + (01) (10) ) (0 + 10). Proof. (0 + (01) (10) ) (0 + 0(10) + 0 (10) ) (( )(10) ) (0 (10) ), since L(0 + 0) L(0 ) (0 + 10). Nottion If L is represented y regulr expression r, i.e. L(r) = L, then we my simply use r insted of L(r) to indicted the lnguge L. As consequence, for two regulr expressions r nd r, r r nd r = r re equivlent. 17

19 Chpter 3 Grmmrs In this chpter, we introduce the notion of grmmr clled context-free grmmr (CFG) s lnguge genertor. The notion of derivtion is instrumentl in understnding how the strings re generted in grmmr. We explin the vrious properties of derivtions using grphicl representtion clled derivtion trees. A specil cse of CFG, viz. regulr grmmr, is discussed s tool to generte to regulr lnguges. A more generl notion of grmmrs is presented in Chpter 7. In the context of nturl lnguges, the grmmr of lnguge is set of rules which re used to construct/vlidte sentences of the lnguge. It hs een pointed out, in the introduction of Chpter 2, tht this is the third step in forml lerning of lnguge. Now we drw the ttention of reder to look into the generl fetures of the grmmrs (of nturl lnguges) to formlize the notion in the present context which fcilitte for etter understnding of forml lnguges. Consider the English sentence The students study utomt theory. In order to oserve tht the sentence is grmmticlly correct, one my ttriute certin rules of the English grmmr to the sentence nd vlidte it. For instnce, the Article the followed y the Noun students form Noun-phrse nd similrly the Noun utomt theory form Noun-phrse. Further, study is Ver. Now, choose the Sententil form Suject Ver Oject of the English grmmr. As Suject or Oject cn e Noun-phrse y plugging in the ove words one my conclude tht the given sentence is grmmticlly correct English sentence. This verifiction/derivtion is depicted in Figure 3.1. The derivtion cn lso e represented y tree structure s shown in Figure

20 Sentence Suject Ver Oject Noun-phrse Ver Oject Article Noun Ver Oject The Noun Ver Oject The students Ver Oject The students study Oject The students study Noun-phrse The students study Noun The students study utomt theory Figure 3.1: Derivtion of n English Sentence In this process, we oserve tht two types of words re in the discussion. 1. The words like the, study, students. 2. The words like Article, Noun, Ver. The min difference is, if you rrive t stge where type (1) words re ppering, then you need not sy nything more out them. In cse you rrive t stge where you find word of type (2), then you re ssumed to sy some more out the word. For exmple, if the word Article comes, then one should sy which rticle need to e chosen mong, n nd the. Let us cll the type (1) nd type (2) words s terminls nd nonterminls, respectively, s per their fetures. Thus, grmmr should include terminls nd nonterminls long with set of rules which ttriute some informtion regrding nonterminl symols. 3.1 Context-Free Grmmrs We now understnd tht grmmr should hve the following components. A set of nonterminl symols. A set of terminl symols. A set of rules. As the grmmr is to construct/vlidte sentences of lnguge, we distinguish symol in the set of nonterminls to represent sentence from which vrious sentences of the lnguge cn e generted/vlidted. 19

21 Sentence Suject Ver Oject Noun phrse Noun phrse Article Noun Noun The students study utomt theory Figure 3.2: Derivtion Tree of n English Sentence With this, we formlly define the notion of grmmr s elow. Definition A grmmr is qudruple where G = (N, Σ, P, S) 1. N is finite set of nonterminls, 2. Σ is finite set of terminls, 3. S N is the strt symol, nd 4. P is finite suset of N V clled the set of production rules. Here, V = N Σ. It is convenient to write A α, for the production rule (A, α) P. To define forml notion of vlidting or deriving sentence using grmmr, we require the following concepts. Definition Let G = (N, Σ, P, S) e grmmr with V = N Σ. 1. We define inry reltion G on V y α G β if nd only if α = α 1 Aα 2, β = α 1 γα 2 nd A γ P, for ll α, β V. 20

22 2. The reltion G is clled one step reltion on G. If α G β, then we cll α yields β in one step in G. 3. The reflexive-trnsitive closure of G is denoted y G. Tht is, for α, β V, α G β if nd only if { n 0 nd α0, α 1,..., α n V such tht α = α 0 G α 1 G G α n 1 G α n = β. 4. For α, β V, if α β, then we sy β is derived from α or α derives G β. Further, α β is clled s derivtion in G. G 5. If α = α 0 G α 1 G G α n 1 G α n = β is derivtion, then the length of the derivtion is n nd it my e written s α n G β. 6. In given context, if we del with only one grmmr G, then we my simply write, in sted of G. 7. If α β is derivtion, then we sy β is the yield of the derivtion. 8. A string α V is sid to e sententil form in G, if α cn e derived from the strt symol S of G. Tht is, S α. 9. In prticulr, if α Σ, then the sententil form α is known s sentence. In which cse, we sy α is generted y G. 10. The lnguge generted y G, denoted y L(G), is the set of ll sentences generted y G. Tht is, L(G) = {x Σ S x}. Note tht production rule of grmmr is of the form A α, where A is nonterminl symol. If the nonterminl A ppers in sententil form X 1 X k AX k+1 X n, then the sententil form X 1 X k αx k+1 X n cn e otined in one step y replcing A with α. This replcement is independent of the neighoring symols of A in X 1 X k AX k+1 X n. Tht is, X is will not ply ny role in the replcement. One my cll A is within the context of X is nd hence the rules A α re sid to e of context-free type. Thus, the type of grmmr tht is defined here is known s contextfree grmmr, simply CFG. In the lter chpters, we relx the constrint nd discuss more generl types of grmmrs. 21

23 Exmple Let P = {S, S, S, S } with Σ = {, } nd N = {S}. Then G = (N, Σ, P, S) is context-free grmmr. Since left hnd side of ech production rule is the strt symol S nd their right hnd sides re terminl strings, every derivtion in G is of length one. In fct, we precisely hve the following derivtion in G. 1. S 2. S 3. S 4. S Hence, the lnguge generted y G, Nottion L(G) = {,,, }. 1. A α 1, A α 2 cn e written s A α 1 α Normlly we use S s the strt symol of grmmr, unless otherwise specified. 3. To give grmmr G = (N, Σ, P, S), it is sufficient to give the production rules only since one my esily find the other components N nd Σ of the grmmr G y looking t the rules. Exmple Suppose L is finite lnguge over n lphet Σ, sy L = {x 1, x 2,..., x n }. Then consider the finite set P = {S x 1 x 2 x n }. Now, s discussed in Exmple 3.1.3, one cn esily oserve tht the CFG ({S}, Σ, P, S) genertes the lnguge L. Exmple Let Σ = {0, 1} nd N = {S}. Consider the CFG G = (N, Σ, P, S), where P hs precisely the following production rules. 1. S 0S 2. S 1S 3. S ε 22

24 We now oserve tht the CFG G genertes Σ. As every string generted y G is sequence of 0 s nd 1 s, clerly we hve L(G) Σ. On the other hnd, let x Σ. If x = ε, then x cn e generted in one step using the rule S ε. Otherwise, let x = 1 2 n, where i = 0 or 1 for ll i. Now, s shown elow, x cn e derived in G. S 1 S (if 1 = 0, then y rule 1; else y rule 2) 1 2 S (s ove). 1 2 n S (s ove) 1 2 n ε (y rule 3) = x. Hence, x L(G). Thus, L(G) = Σ. Exmple The lnguge (over ny lphet Σ) cn e generted y CFG. Method-I. If the set of productions P is empty, then clerly the CFG G = ({S}, Σ, P, S) does not generte ny string nd hence L(G) =. Method-II. Consider CFG G in which ech production rule hs some nonterminl symol on its right hnd side. Clerly, no terminl string cn e generted in G so tht L(G) =. Exmple Consider G = ({S}, {}, P, S) where P hs the following rules 1. S S 2. S ε Let us look t the strings tht cn e generted y G. Clerly, ε cn e generted in one step y using the rule S ε. Further, if we choose rule (1) nd then rule (2) we get the string in two steps s follows: S S ε = If we use the rule (1), then one my notice tht there will lwys e the nonterminl S in the resulting sententil form. A derivtion cn only e terminted y using rule (2). Thus, for ny derivtion of length k, tht 23

25 derives some string x, we would hve used rule (1) for k 1 times nd rule (2) once t the end. Precisely, the derivtion will e of the form S S. S k 1 {}}{ S k 1 {}}{ ε = k 1 Hence, it is cler tht L(G) = { k k 0} In the following, we give some more exmples of typicl CFGs. Exmple Consider the grmmr hving the following production rules: S S ε One my notice tht the rule S S should e used to derive strings other thn ε, nd the derivtion shll lwys e terminted y S ε. Thus, typicl derivtion is of the form Hence, L(G) = { n n n 0}. S S. Exmple The grmmr S n S n n ε n = n n S S S ε genertes the set of ll plindromes over {, }. For instnce, the rules S S nd S S will produce sme terminls t the sme positions towrds left nd right sides. While terminting the derivtion the rules S or S ε will produce odd or even length plindromes, respectively. For exmple, the plindrome cn e derived s follows. S S S S 24

26 Exmple Consider the lnguge L = { m n c m+n m, n 0}. We now give production rules of CFG which genertes L. As given in Exmple 3.1.9, the production rule S Sc cn e used to produce equl numer of s nd c s, respectively, in left nd right extremes of string. In cse, there is no in the string, the production rule S ε cn e used to terminte the derivtion nd produce string of the form m c m. Note tht, s in string my hve leding s; ut, there will not e ny fter. Thus, nonterminl symol tht my e used to produce s must e different from S. Hence, we choose new nonterminl symol, sy A, nd define the rule S A to hndover the jo of producing s to A. Agin, since the numer of s nd c s re to e equl, choose the rule A Ac to produce s nd c s on either sides. Eventully, the rule A ε cn e introduced, which terminte the derivtion. Thus, we hve the following production rules of CFG, sy G. S Sc A ε A Ac ε Now, one cn esily oserve tht L(G) = L. Exmple For the lnguge { m m+n c n m, n 0}, one my think in the similr lines of Exmple nd produce CFG s given elow. S AB A A ε B Bc ε 25

27 S S S S S S S S + S S S + S S + S S + S + S S + S S + S + S + S (1) (2) (3) Figure 3.3: Derivtions for the string Derivtion Trees Let us consider the CFG whose production rules re: S S S S + S (S) Figure 3.3 gives three derivtions for the string +. Note tht the three derivtions re different, ecuse of ppliction of different sequences of rules. Nevertheless, the derivtions (1) nd (2) shre the following feture. A nonterminl tht ppers t prticulr common position in oth the derivtions derives the sme sustring of + in oth the derivtions. In contrst to tht, the derivtions (2) nd (3) re not shring such feture. For exmple, the second S in step 2 of derivtions (1) nd (2) derives the sustring ; wheres, the second S in step 2 of derivtion (3) derives the sustring. In order to distinguish this feture etween the derivtions of string, we introduce grphicl representtion of derivtion clled derivtion tree, which will e useful tool for severl other purposes lso. Definition Let G = (N, Σ, P, S) e CFG nd V = N Σ. For A N nd α V, suppose A α is derivtion in G. A derivtion tree or prse tree of the derivtion is itertively defined s follows. 1. A is the root of the tree. 2. If the rule B X 1 X 2 X k is pplied in the derivtion, then new nodes with lels X 1, X 2,..., X k re creted nd mde children to the node B from left to right in tht order. The construction of the derivtion tree of derivtion is illustrted with the following exmples. 26

28 Exmple Consider the following derivtion in the CFG given in Exmple S S S ε = The derivtion tree of the ove derivtion S is shown elow. S S S ε Exmple Consider the following derivtion in the CFG given in Exmple S AB AB AB AB ABc Aεc = Ac The derivtion tree of the ove derivtion S Ac is shown elow. S A B A B c A ε Note tht the yield α of the derivtion A α cn e identified in the derivtion tree y juxtposing the lels of the lef nodes from left to right. Exmple Recll the derivtions given in Figure 3.3. The derivtion trees corresponding to these derivtions re in Figure

29 S S S S S S S S + S S + S S + S S S (1) (2) (3) Figure 3.4: Derivtion Trees for Figure 3.3 Now we re in position to formlize the notion of equivlence etween derivtions, which precisely cptures the feture proposed in the eginning of the section. Two derivtions re sid to e equivlent if their derivtion trees re sme. Thus, equivlent derivtions re precisely differed y the order of ppliction of sme production rules. Tht is, the ppliction of production rules in derivtion cn e permuted to get n equivlent derivtion. For exmple, s derivtion trees (1) nd (2) of Figure 3.4 re sme, the derivtions (1) nd (2) of Figure 3.3 re equivlent. Thus, derivtion tree my represent severl equivlent derivtions. However, for given derivtion tree, whose yield is terminl string, there is unique specil type of derivtion, viz. leftmost derivtion (or rightmost derivtion). Definition For A N nd x Σ, the derivtion A x is sid to e leftmost derivtion if the production rule pplied t ech step is on the leftmost nonterminl symol of the sententil form. In which cse, the derivtion is denoted y A x. L Similrly, for A N nd x Σ, the derivtion A x is sid to e rightmost derivtion if the production rule pplied t ech step is on the rightmost nonterminl symol of the sententil form. In which cse, the derivtion is denoted y A x. R Becuse of the similrity etween leftmost derivtion nd rightmost derivtion, the properties of the leftmost derivtions cn e imitted to get similr properties for rightmost derivtions. Now, we estlish some properties of leftmost derivtions. Theorem For A N nd x Σ, A x if nd only if A L x. 28

30 Proof. Only if prt is strightforwrd, s every leftmost derivtion is, nywy, derivtion. For if prt, let A = α 0 α 1 α 2 α n 1 α n = x e derivtion. If α i L α i+1, for ll 0 i < n, then we re through. Otherwise, there is n i such tht α i L α i+1. Let k e the lest such tht α k L α k+1. Then, we hve α i L α i+1, for ll i < k, i.e. we hve leftmost sustitutions in the first k steps. We now demonstrte how to extend the leftmost sustitution to (k + 1)th step. Tht is, we show how to convert the derivtion A = α 0 L α 1 L L α k α k+1 α n 1 α n = x in to derivtion A = α 0 L α 1 L L α k L α k+1 α k+2 α n 1 α n = x in which there re leftmost sustitutions in the first (k + 1) steps nd the derivtion is of sme length of the originl. Hence, y induction one cn extend the given derivtion to leftmost derivtion A L x. Since α k α k+1 ut α k L α k+1, we hve α k = ya 1 β 1 A 2 β 2, for some y Σ, A 1, A 2 N nd β 1, β 2 V, nd A 2 γ 2 P such tht α k+1 = ya 1 β 1 γ 2 β 2. But, since the derivtion eventully yields the terminl string x, t lter step, sy pth step (for p > k), A 1 would hve een sustituted y some string γ 1 V using the rule A 1 γ 1 P. Thus the originl derivtion looks s follows. A = α 0 L α 1 L L α k = ya 1 β 1 A 2 β 2 α k+1 = ya 1 β 1 γ 2 β 2 = ya 1 ξ 1, with ξ 1 = β 1 γ 2 β 2 α k+2 = ya 1 ξ 2, ( here ξ 1 ξ 2 ). α p 1 = ya 1 ξ p k 1 α p = yγ 1 ξ p k 1 α p+1. α n = x 29

31 We now demonstrte mechnism of using the rule A 1 γ 1 in (k + 1)th step so tht we get desired derivtion. Set α k+1 = yγ 1β 1 A 2 β 2 α k+2 = yγ 1β 1 γ 2 β 2 = yγ 1 ξ 1 α k+3 = yγ 1ξ 2. α p 1 = yγ 1 ξ p k 2 α p = yγ 1 ξ p k 1 = α p α p+1 = α p+1. α n = α n Now we hve the following derivtion in which (k +1)th step hs leftmost sustitution, s desired. A = α 0 L α 1 L L α k = ya 1 β 1 A 2 β 2 L α k+1 = yγ 1 β 1 A 2 β 2 α k+2 = yγ 1 β 1 γ 2 β 2 = yγ 1 ξ 1 α k+3 = yγ 1 ξ 2. α p 1 = yγ 1 ξ p k 2 α p = yγ 1 ξ p k 1 = α p α p+1 = α p+1. α n = α n = x As stted erlier, we hve the theorem y induction. Proposition Two equivlent leftmost derivtions re identicl. Proof. Let T e the derivtion tree of two leftmost derivtions D 1 nd D 2. Note tht the production rules pplied t ech nonterminl symol is precisely represented y its children in the derivtion tree. Since the derivtion tree is sme for D 1 nd D 2, the production rules pplied in oth the derivtions re sme. Moreover, s D 1 nd D 2 re leftmost derivtions, the order of ppliction of production rules re lso sme; tht is, ech production is pplied to the leftmost nonterminl symol. Hence, the derivtions D 1 nd D 2 re identicl. Now we re redy to estlish the correspondence etween derivtion trees nd leftmost derivtions. 30

32 Theorem Every derivtion tree, whose yield is terminl string, represents unique leftmost derivtion. Proof. For A N nd x Σ, suppose T is the derivtion tree of derivtion A x. By Theorem 3.2.6, we cn find n equivlent leftmost derivtion A x. Hence, y Proposition 3.2.7, we hve unique leftmost derivtion L tht is represented y T. Theorem Let G = (N, Σ, P, S) e CFG nd κ = mx{ α A α P }. For x L(G), if T is derivtion tree for x, then where h is the height of the tree T. x κ h Proof. Since κ is the mximum length of righthnd side of ech production rule of G, ech internl node of T is prent of t most κ numer of children. Hence, T is κ-ry tree. Now, in the similr lines of Theorem tht is given for inry trees, one cn esily prove tht T hs t most κ h lef nodes. Hence, x κ h Amiguity Let G e context-free grmmr. It my e cse tht the CFG G gives two or more inequivlent derivtions for string x L(G). This cn e identified y their different derivtion trees. While deriving the string, if there re multiple possiilities of ppliction of production rules on the sme symol, one my hve difficulty in choosing correct rule. In the context of compiler which is constructed sed on grmmr, this difficulty will led to n miguity in prsing. Thus, grmmr with such property is sid to e miguous. Definition Formlly, CFG G is sid to e miguous, if G hs two different leftmost derivtions for some string in L(G). Otherwise, the grmmr is sid to e unmiguous. Remrk One cn equivlently sy tht CFG G is miguous, if G hs two different rightmost derivtions or derivtion trees for string in L(G). 31

33 Exmple Recll the CFG which genertes rithmetic expressions with the production rules S S S S + S (S) As shown in Figure 3.3, the rithmetic expression + hs two different leftmost derivtions, viz. (2) nd (3). Hence, the grmmr is miguous. Exmple An unmiguous grmmr which genertes the rithmetic expressions (the lnguge generted y the CFG given in Exmple ) is s follows. S S + T T T T R R R (S) In the context of constructing compiler or similr such pplictions, it is desirle tht the underlying grmmr e unmiguous. Unfortuntely, there re some CFLs for which there is no CFG which is unmiguous. Such CFL is known s inherently miguous lnguge. Exmple The context-free lnguge { m m c n d n m, n 1} { m n c n d m m, n 1} is inherently miguous. For proof, one my refer to the Hopcroft nd Ullmn [1979]. 3.3 Regulr Grmmrs Definition A CFG G = (N, Σ, P, S) is sid to e liner if every production rule of G hs t most one nonterminl symol in its righthnd side. Tht is, A α P = α Σ or α = xby, for some x, y Σ nd B N. Exmple The CFGs given in Exmples 3.1.8, nd re clerly liner. Wheres, the CFG given in Exmple is not liner. Remrk If G is liner grmmr, then every derivtion in G is leftmost derivtion s well s rightmost derivtion. This is ecuse there is exctly one nonterminl symol in the sententil form of ech internl step of the derivtion. 32

34 Definition A liner grmmr G = (N, Σ, P, S) is sid to e right liner if the nonterminl symol in the righthnd side of ech production rule, if ny, occurs t the right end. Tht is, righthnd side of ech production rule is of the form terminl string followed y t most one nonterminl symol s shown elow. A x or A xb for some x Σ nd B N. Similrly, left liner grmmr is defined y considering the production rules in the following form. for some x Σ nd B N. A x or A Bx Becuse of the similrity in the definitions of left liner grmmr nd right liner grmmr, every result which is true for one cn e imitted to otin prllel result for the other. In fct, the notion of left liner grmmr is equivlent right liner grmmr (see Exercise??). Here, y equivlence we men, if L is generted y right liner grmmr, then there exists left liner grmmr tht genertes L; nd vice-vers. Exmple The CFG given in Exmple is right liner grmmr. For the lnguge { k k 0}, n equivlent left liner grmmr is given y the following production rules. S S ε Exmple We give right liner grmmr for the lnguge L = {x {, } x = 2n + 1, for some n}. We understnd tht the nonterminl symols in grmmr mintin the properties of the strings tht they generte or whenever they pper in derivtion they determine the properties of the prtil string tht the derivtion so fr generted. Since we re looking for right liner grmmr for L, ech production rule will hve t most one nonterminl symol on its righthnd side nd hence t ech internl step of desired derivtion, we will hve exctly one nonterminl symol. While, we re generting sequence of s nd s for the lnguge, we need not keep trck of the numer of s tht re generted, so fr. Wheres, we need to keep trck the numer of s; here, it need not e 33

35 the ctul numer, rther the prity (even or odd) of the numer of s tht re generted so fr. So to keep trck of the prity informtion, we require two nonterminl symols, sy O nd E, respectively for odd nd even. In the eginning of ny derivtion, we would hve generted zero numer of symols in generl, even numer of s. Thus, it is expected tht the nonterminl symol E to e the strt symol of the desired grmmr. While E genertes the terminl symol, the derivtion cn continue to e with nonterminl symol E. Wheres, if one is generted then we chnge to the symol O, s the numer of s generted so fr will e odd from even. Similrly, we switch to E on generting n with the symol O nd continue to e with O on generting ny numer of s. Precisely, we hve otined the following production rules. E E O O O E Since, our criteri is to generte string with odd numer of s, we cn terminte derivtion while continuing in O. Tht is, we introduce the production rule O ε Hence, we hve the right liner grmmr G = ({E, O}, {, }, P, E), where P hs the ove defined three productions. Now, one cn esily oserve tht L(G) = L. Recll tht the lnguge under discussion is stted s regulr lnguge in Chpter 1 (refer Exmple ). Wheres, we did not supply ny proof in support. Here, we could identify right liner grmmr tht genertes the lnguge. In fct, we hve the following result. Theorem The lnguge generted y right liner grmmr is regulr. Moreover, for every regulr lnguge L, there exists right liner grmmr tht genertes L. An elegnt proof of this theorem would require some more concepts nd hence postponed to lter chpters. For proof of the theorem, one my refer to Chpter 4. In view of the theorem, we hve the following definition. Definition Right liner grmmrs re lso clled s regulr grmmrs. Remrk Since left liner grmmrs nd right liner grmmrs re equivlent, left liner grmmrs lso precisely generte regulr lnguges. Hence, left liner grmmrs re lso clled s regulr grmmrs. 34

36 Exmple The lnguge {x {, } is sustring of x} cn e generted y the following regulr grmmr. S S S A A A A ε Exmple Consider the regulr grmmr with the following production rules. S A S ε A S A Note tht the grmmr genertes the set of ll strings over {, } hving even numer of s. Exmple Consider the lnguge represented y the regulr expression + over {, }, i.e. { m n {, } m 0, n 1} It cn e esily oserve tht the following regulr grmmr genertes the lnguge. S S B B B Exmple The grmmr with the following production rules is clerly regulr. S S A A A B B B S ε It cn e oserved tht the lnguge {x {, } x 2 mod 3} is generted y the grmmr. Exmple Consider the lnguge { } L = x (0 + 1) x 0 is even x 1 is odd. It is little tedious to construct regulr grmmr to show tht L is regulr. However, using etter tool, we show tht L is regulr lter (See Exmple 5.1.3). 35

37 3.4 Digrph Representtion We could chieve in writing right liner grmmr for some lnguges. However, we fce difficulties in constructing right liner grmmr for some lnguges tht re known to e regulr. We re now going to represent right liner grmmr y digrph which shll give etter pproch in writing/constructing right liner grmmr for lnguges. In fct, this digrph representtion motivtes one to think out the notion of finite utomton which will e shown, in the next chpter, s n ultimte tool in understnding regulr lnguges. Definition Given right liner grmmr G = (N, T, P, S), define the digrph (V, E), where the vertex set V = N {$} with new symol $ nd the edge set E is formed s follows. 1. (A, B) E A xb P, for some x T 2. (A, $) E A x P, for some x T In which cse, the rc from A to B is leled y x. Exmple The digrph for the grmmr presented in Exmple is s follows. S, A, ε $ Remrk From digrph one cn esily give the corresponding right liner grmmr. Exmple The digrph for the grmmr presented in Exmple is s follows. S ε B $ Remrk A derivtion in right liner grmmr cn e represented, in its digrph, y pth from the strting node S to the specil node $; nd conversely. We illustrte this through the following. Consider the following derivtion for the string in the grmmr given in Exmple S S S B The derivtion cn e trced y pth from S to $ in the corresponding digrph (refer to Exmple 3.4.4) s shown elow. S S S ε B $ 36

38 One my notice tht the conctention of the lels on the pth, clled lel of the pth, gives the desired string. Conversely, it is esy to see tht the lel of ny pth from S to $ cn e derived in G. 37

39 Chpter 4 Finite Automt Regulr grmmrs, s lnguge generting devices, re intended to generte regulr lnguges - the clss of lnguges tht re represented y regulr expressions. Finite utomt, s lnguge ccepting devices, re importnt tools to understnd the regulr lnguges etter. Let us consider the regulr lnguge - the set of ll strings over {, } hving odd numer of s. Recll the grmmr for this lnguge s given in Exmple A digrph representtion of the grmmr is given elow: E O ε $ Let us trverse the digrph vi sequence of s nd s strting t the node E. We notice tht, t given point of time, if we re t the node E, then so fr we hve encountered even numer of s. Wheres, if we re t the node O, then so fr we hve trversed through odd numer of s. Of course, eing t the node $ hs the sme effect s tht of node O, regrding numer of s; rther once we rech to $, then we will not hve ny further move. Thus, in digrph tht models system which understnds lnguge, nodes holds some informtion out the trversl. As ech node is holding some informtion it cn e considered s stte of the system nd hence stte cn e considered s memory creting unit. As we re interested in the lnguges hving finite representtion, we restrict ourselves to those systems with finite numer of sttes only. In such system we hve trnsitions etween the sttes on symols of the lphet. Thus, we my cll them s finite stte trnsition systems. As the trnsitions re predefined in finite stte trnsition system, it utomticlly chnges sttes sed on the symols given s input. Thus finite stte trnsition system cn lso e clled s 38

40 finite stte utomton or simply finite utomton device tht works utomticlly. The plurl form of utomton is utomt. In this chpter, we introduce the notion of finite utomt nd show tht they model the clss of regulr lnguges. In fct, we oserve tht finite utomt, regulr grmmrs nd regulr expressions re equivlent; ech of them re to represent regulr lnguges. 4.1 Deterministic Finite Automt Deterministic finite utomton is type of finite utomton in which the trnsitions re deterministic, in the sense tht there will e exctly one trnsition from stte on n input symol. Formlly, deterministic finite utomton (DFA) is quintuple A = (Q, Σ, δ, q 0, F ), where Q is finite set clled the set of sttes, Σ is finite set clled the input lphet, q 0 Q, clled the initil/strt stte, F Q, clled the set of finl/ccept sttes, nd δ : Q Σ Q is function clled the trnsition function or next-stte function. Note tht, for every stte nd n input symol, the trnsition function δ ssigns unique next stte. Exmple Let Q = {p, q, r}, Σ = {, }, F = {r} nd δ is given y the following tle: δ p q p q r p r r r Clerly, A = (Q, Σ, δ, p, F ) is DFA. We normlly use symols p, q, r,... with or without suscripts to denote sttes of DFA. Trnsition Tle Insted of explicitly giving ll the components of the quintuple of DFA, we my simply point out the initil stte nd the finl sttes of the DFA in the tle of trnsition function, clled trnsition tle. For instnce, we use n rrow to point the initil stte nd we encircle ll the finl sttes. Thus, we cn hve n lterntive representtion of DFA, s ll the components of 39

41 the DFA now cn e interpreted from this representtion. For exmple, the DFA in Exmple cn e denoted y the following trnsition tle. Trnsition Digrm δ p q p q r p r r r Normlly, we ssocite some grphicl representtion to understnd strct concepts etter. In the present context lso we hve digrph representtion for DFA, (Q, Σ, δ, q 0, F ), clled stte trnsition digrm or simply trnsition digrm which cn e constructed s follows: 1. Every stte in Q is represented y node. 2. If δ(p, ) = q, then there is n rc from p to q leled. 3. If there re multiple rcs from leled 1,... k 1, nd k, one stte to nother stte, then we simply put only one rc leled 1,..., k 1, k. 4. There is n rrow with no source into the initil stte q Finl sttes re indicted y doule circle. The trnsition digrm for the DFA given in Exmple is s elow: p q r, Note tht there re two trnsitions from the stte r to itself on symols nd. As indicted in the point 3 ove, these re indicted y single rc from r to r leled,. Extended Trnsition Function Recll tht the trnsition function δ ssigns stte for ech stte nd n input symol. This nturlly cn e extended to ll strings in Σ, i.e. ssigning stte for ech stte nd n input string. 40

Parse trees, ambiguity, and Chomsky normal form

Parse trees, ambiguity, and Chomsky normal form Prse trees, miguity, nd Chomsky norml form In this lecture we will discuss few importnt notions connected with contextfree grmmrs, including prse trees, miguity, nd specil form for context-free grmmrs

More information

Closure Properties of Regular Languages

Closure Properties of Regular Languages Closure Properties of Regulr Lnguges Regulr lnguges re closed under mny set opertions. Let L 1 nd L 2 e regulr lnguges. (1) L 1 L 2 (the union) is regulr. (2) L 1 L 2 (the conctention) is regulr. (3) L

More information

Harvard University Computer Science 121 Midterm October 23, 2012

Harvard University Computer Science 121 Midterm October 23, 2012 Hrvrd University Computer Science 121 Midterm Octoer 23, 2012 This is closed-ook exmintion. You my use ny result from lecture, Sipser, prolem sets, or section, s long s you quote it clerly. The lphet is

More information

Coalgebra, Lecture 15: Equations for Deterministic Automata

Coalgebra, Lecture 15: Equations for Deterministic Automata Colger, Lecture 15: Equtions for Deterministic Automt Julin Slmnc (nd Jurrin Rot) Decemer 19, 2016 In this lecture, we will study the concept of equtions for deterministic utomt. The notes re self contined

More information

Formal Languages and Automata

Formal Languages and Automata Moile Computing nd Softwre Engineering p. 1/5 Forml Lnguges nd Automt Chpter 2 Finite Automt Chun-Ming Liu cmliu@csie.ntut.edu.tw Deprtment of Computer Science nd Informtion Engineering Ntionl Tipei University

More information

Context-Free Grammars and Languages

Context-Free Grammars and Languages Context-Free Grmmrs nd Lnguges (Bsed on Hopcroft, Motwni nd Ullmn (2007) & Cohen (1997)) Introduction Consider n exmple sentence: A smll ct ets the fish English grmmr hs rules for constructing sentences;

More information

Lecture 08: Feb. 08, 2019

Lecture 08: Feb. 08, 2019 4CS4-6:Theory of Computtion(Closure on Reg. Lngs., regex to NDFA, DFA to regex) Prof. K.R. Chowdhry Lecture 08: Fe. 08, 2019 : Professor of CS Disclimer: These notes hve not een sujected to the usul scrutiny

More information

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz University of Southern Cliforni Computer Science Deprtment Compiler Design Fll Lexicl Anlysis Smple Exercises nd Solutions Prof. Pedro C. Diniz USC / Informtion Sciences Institute 4676 Admirlty Wy, Suite

More information

Minimal DFA. minimal DFA for L starting from any other

Minimal DFA. minimal DFA for L starting from any other Miniml DFA Among the mny DFAs ccepting the sme regulr lnguge L, there is exctly one (up to renming of sttes) which hs the smllest possile numer of sttes. Moreover, it is possile to otin tht miniml DFA

More information

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014 CMPSCI 250: Introduction to Computtion Lecture #31: Wht DFA s Cn nd Cn t Do Dvid Mix Brrington 9 April 2014 Wht DFA s Cn nd Cn t Do Deterministic Finite Automt Forml Definition of DFA s Exmples of DFA

More information

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1 Chpter Five: Nondeterministic Finite Automt Forml Lnguge, chpter 5, slide 1 1 A DFA hs exctly one trnsition from every stte on every symol in the lphet. By relxing this requirement we get relted ut more

More information

Designing finite automata II

Designing finite automata II Designing finite utomt II Prolem: Design DFA A such tht L(A) consists of ll strings of nd which re of length 3n, for n = 0, 1, 2, (1) Determine wht to rememer out the input string Assign stte to ech of

More information

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton 25. Finite Automt AUTOMATA AND LANGUAGES A system of computtion tht only hs finite numer of possile sttes cn e modeled using finite utomton A finite utomton is often illustrted s stte digrm d d d. d q

More information

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages Deprtment of Computer Science, Austrlin Ntionl University COMP2600 Forml Methods for Softwre Engineering Semester 2, 206 Assignment Automt, Lnguges, nd Computility Smple Solutions Finite Stte Automt nd

More information

Let's start with an example:

Let's start with an example: Finite Automt Let's strt with n exmple: Here you see leled circles tht re sttes, nd leled rrows tht re trnsitions. One of the sttes is mrked "strt". One of the sttes hs doule circle; this is terminl stte

More information

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4 Intermedite Mth Circles Wednesdy, Novemer 14, 2018 Finite Automt II Nickols Rollick nrollick@uwterloo.c Regulr Lnguges Lst time, we were introduced to the ide of DFA (deterministic finite utomton), one

More information

Finite-State Automata: Recap

Finite-State Automata: Recap Finite-Stte Automt: Recp Deepk D Souz Deprtment of Computer Science nd Automtion Indin Institute of Science, Bnglore. 09 August 2016 Outline 1 Introduction 2 Forml Definitions nd Nottion 3 Closure under

More information

Finite Automata-cont d

Finite Automata-cont d Automt Theory nd Forml Lnguges Professor Leslie Lnder Lecture # 6 Finite Automt-cont d The Pumping Lemm WEB SITE: http://ingwe.inghmton.edu/ ~lnder/cs573.html Septemer 18, 2000 Exmple 1 Consider L = {ww

More information

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata CS103B ndout 18 Winter 2007 Ferury 28, 2007 Finite Automt Initil text y Mggie Johnson. Introduction Severl childrens gmes fit the following description: Pieces re set up on plying ord; dice re thrown or

More information

Formal languages, automata, and theory of computation

Formal languages, automata, and theory of computation Mälrdlen University TEN1 DVA337 2015 School of Innovtion, Design nd Engineering Forml lnguges, utomt, nd theory of computtion Thursdy, Novemer 5, 14:10-18:30 Techer: Dniel Hedin, phone 021-107052 The exm

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 utomt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Prolem (II) Chpter II.5.: Properties of Context Free Grmmrs (14) nton Setzer (Bsed on ook drft y J. V. Tucker nd K. Stephenson)

More information

Convert the NFA into DFA

Convert the NFA into DFA Convert the NF into F For ech NF we cn find F ccepting the sme lnguge. The numer of sttes of the F could e exponentil in the numer of sttes of the NF, ut in prctice this worst cse occurs rrely. lgorithm:

More information

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true. York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech

More information

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9. Regulr Expressions, Pumping Lemm, Right Liner Grmmrs Ling 106 Mrch 25, 2002 1 Regulr Expressions A regulr expression descries or genertes lnguge: it is kind of shorthnd for listing the memers of lnguge.

More information

Thoery of Automata CS402

Thoery of Automata CS402 Thoery of Automt C402 Theory of Automt Tle of contents: Lecture N0. 1... 4 ummry... 4 Wht does utomt men?... 4 Introduction to lnguges... 4 Alphets... 4 trings... 4 Defining Lnguges... 5 Lecture N0. 2...

More information

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages 5//6 Grmmr Automt nd Lnguges Regulr Grmmr Context-free Grmmr Context-sensitive Grmmr Prof. Mohmed Hmd Softwre Engineering L. The University of Aizu Jpn Regulr Lnguges Context Free Lnguges Context Sensitive

More information

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30 Tlen en Automten Test 1, Mon 7 th Dec, 2015 15h45 17h30 This test consists of four exercises over 5 pges. Explin your pproch, nd write your nswer to ech exercise on seprte pge. You cn score mximum of 100

More information

1.3 Regular Expressions

1.3 Regular Expressions 56 1.3 Regulr xpressions These hve n importnt role in describing ptterns in serching for strings in mny pplictions (e.g. wk, grep, Perl,...) All regulr expressions of lphbet re 1.Ønd re regulr expressions,

More information

Nondeterminism and Nodeterministic Automata

Nondeterminism and Nodeterministic Automata Nondeterminism nd Nodeterministic Automt 61 Nondeterminism nd Nondeterministic Automt The computtionl mchine models tht we lerned in the clss re deterministic in the sense tht the next move is uniquely

More information

CHAPTER 1 Regular Languages. Contents

CHAPTER 1 Regular Languages. Contents Finite Automt (FA or DFA) CHAPTE 1 egulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, euivlence of NFAs nd DFAs, closure under regulr

More information

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh Lnguges nd Automt Finite Automt Informtics 2A: Lecture 3 John Longley School of Informtics University of Edinburgh jrl@inf.ed.c.uk 22 September 2017 1 / 30 Lnguges nd Automt 1 Lnguges nd Automt Wht is

More information

1.4 Nonregular Languages

1.4 Nonregular Languages 74 1.4 Nonregulr Lnguges The number of forml lnguges over ny lphbet (= decision/recognition problems) is uncountble On the other hnd, the number of regulr expressions (= strings) is countble Hence, ll

More information

First Midterm Examination

First Midterm Examination Çnky University Deprtment of Computer Engineering 203-204 Fll Semester First Midterm Exmintion ) Design DFA for ll strings over the lphet Σ = {,, c} in which there is no, no nd no cc. 2) Wht lnguge does

More information

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings... Tle of contents: Lecture N0.... 3 ummry... 3 Wht does utomt men?... 3 Introduction to lnguges... 3 Alphets... 3 trings... 3 Defining Lnguges... 4 Lecture N0. 2... 7 ummry... 7 Kleene tr Closure... 7 Recursive

More information

Regular expressions, Finite Automata, transition graphs are all the same!!

Regular expressions, Finite Automata, transition graphs are all the same!! CSI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 7: Kleene s Theorem Chpter 7: Kleene s Theorem Regulr expressions, Finite Automt, trnsition grphs re ll the sme!! Dr. Neji Zgui CSI3104-W11 1

More information

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA) Finite Automt (FA or DFA) CHAPTER Regulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, equivlence of NFAs DFAs, closure under regulr

More information

Fundamentals of Computer Science

Fundamentals of Computer Science Fundmentls of Computer Science Chpter 3: NFA nd DFA equivlence Regulr expressions Henrik Björklund Umeå University Jnury 23, 2014 NFA nd DFA equivlence As we shll see, it turns out tht NFA nd DFA re equivlent,

More information

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018 CS 301 Lecture 04 Regulr Expressions Stephen Checkowy Jnury 29, 2018 1 / 35 Review from lst time NFA N = (Q, Σ, δ, q 0, F ) where δ Q Σ P (Q) mps stte nd n lphet symol (or ) to set of sttes We run n NFA

More information

First Midterm Examination

First Midterm Examination 24-25 Fll Semester First Midterm Exmintion ) Give the stte digrm of DFA tht recognizes the lnguge A over lphet Σ = {, } where A = {w w contins or } 2) The following DFA recognizes the lnguge B over lphet

More information

Homework 3 Solutions

Homework 3 Solutions CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 3 Solutions 1. Give NFAs with the specified numer of sttes recognizing ech of the following lnguges. In ll cses, the lphet is Σ = {,1}.

More information

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh Finite Automt Informtics 2A: Lecture 3 Mry Cryn School of Informtics University of Edinburgh mcryn@inf.ed.c.uk 21 September 2018 1 / 30 Lnguges nd Automt Wht is lnguge? Finite utomt: recp Some forml definitions

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automt Theory nd Forml Lnguges TMV027/DIT321 LP4 2018 Lecture 10 An Bove April 23rd 2018 Recp: Regulr Lnguges We cn convert between FA nd RE; Hence both FA nd RE ccept/generte regulr lnguges; More

More information

SWEN 224 Formal Foundations of Programming WITH ANSWERS

SWEN 224 Formal Foundations of Programming WITH ANSWERS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Time Allowed: 3 Hours EXAMINATIONS 2011 END-OF-YEAR SWEN 224 Forml Foundtions of Progrmming

More information

3 Regular expressions

3 Regular expressions 3 Regulr expressions Given n lphet Σ lnguge is set of words L Σ. So fr we were le to descrie lnguges either y using set theory (i.e. enumertion or comprehension) or y n utomton. In this section we shll

More information

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute Victor Admchik Dnny Sletor Gret Theoreticl Ides In Computer Science CS 5-25 Spring 2 Lecture 2 Mr 3, 2 Crnegie Mellon University Deterministic Finite Automt Finite Automt A mchine so simple tht you cn

More information

FABER Formal Languages, Automata and Models of Computation

FABER Formal Languages, Automata and Models of Computation DVA337 FABER Forml Lnguges, Automt nd Models of Computtion Lecture 5 chool of Innovtion, Design nd Engineering Mälrdlen University 2015 1 Recp of lecture 4 y definition suset construction DFA NFA stte

More information

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers 80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES 2.6 Finite Stte Automt With Output: Trnsducers So fr, we hve only considered utomt tht recognize lnguges, i.e., utomt tht do not produce ny output on ny input

More information

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-* Regulr Expressions (RE) Regulr Expressions (RE) Empty set F A RE denotes the empty set Opertion Nottion Lnguge UNIX Empty string A RE denotes the set {} Alterntion R +r L(r ) L(r ) r r Symol Alterntion

More information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS The University of Nottinghm SCHOOL OF COMPUTER SCIENCE LEVEL 2 MODULE, SPRING SEMESTER 2016 2017 LNGUGES ND COMPUTTION NSWERS Time llowed TWO hours Cndidtes my complete the front cover of their nswer ook

More information

Lecture 09: Myhill-Nerode Theorem

Lecture 09: Myhill-Nerode Theorem CS 373: Theory of Computtion Mdhusudn Prthsrthy Lecture 09: Myhill-Nerode Theorem 16 Ferury 2010 In this lecture, we will see tht every lnguge hs unique miniml DFA We will see this fct from two perspectives

More information

1 Nondeterministic Finite Automata

1 Nondeterministic Finite Automata 1 Nondeterministic Finite Automt Suppose in life, whenever you hd choice, you could try oth possiilities nd live your life. At the end, you would go ck nd choose the one tht worked out the est. Then you

More information

Tutorial Automata and formal Languages

Tutorial Automata and formal Languages Tutoril Automt nd forml Lnguges Notes for to the tutoril in the summer term 2017 Sestin Küpper, Christine Mik 8. August 2017 1 Introduction: Nottions nd sic Definitions At the eginning of the tutoril we

More information

CISC 4090 Theory of Computation

CISC 4090 Theory of Computation 9/6/28 Stereotypicl computer CISC 49 Theory of Computtion Finite stte mchines & Regulr lnguges Professor Dniel Leeds dleeds@fordhm.edu JMH 332 Centrl processing unit (CPU) performs ll the instructions

More information

1 From NFA to regular expression

1 From NFA to regular expression Note 1: How to convert DFA/NFA to regulr expression Version: 1.0 S/EE 374, Fll 2017 Septemer 11, 2017 In this note, we show tht ny DFA cn e converted into regulr expression. Our construction would work

More information

Name Ima Sample ASU ID

Name Ima Sample ASU ID Nme Im Smple ASU ID 2468024680 CSE 355 Test 1, Fll 2016 30 Septemer 2016, 8:35-9:25.m., LSA 191 Regrding of Midterms If you elieve tht your grde hs not een dded up correctly, return the entire pper to

More information

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010 CS 311 Homework 3 due 16:30, Thursdy, 14 th Octoer 2010 Homework must e sumitted on pper, in clss. Question 1. [15 pts.; 5 pts. ech] Drw stte digrms for NFAs recognizing the following lnguges:. L = {w

More information

Deterministic Finite Automata

Deterministic Finite Automata Finite Automt Deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion Sciences Version: fll 2016 J. Rot Version: fll 2016 Tlen en Automten 1 / 21 Outline Finite Automt Finite

More information

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch. Overview H9 Vertlerouw H 9: Prsing: op-down & LL(1) do 3 mei 2001 56 heo Ruys h. 8 - Prsing 8.1 ontext-free Grmmrs 8.2 op-down Prsing 8.3 LL(1) Grmmrs See lso [ho, Sethi & Ullmn 1986] for more thorough

More information

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science CSCI 340: Computtionl Models Kleene s Theorem Chpter 7 Deprtment of Computer Science Unifiction In 1954, Kleene presented (nd proved) theorem which (in our version) sttes tht if lnguge cn e defined y ny

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 CMSC 330 1 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All exmples so fr Nondeterministic

More information

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v. 1 Exercises Chpter 1 Exercise 1.1. Let Σ e n lphet. Prove wv = w + v for ll strings w nd v. Prove # (wv) = # (w)+# (v) for every symol Σ nd every string w,v Σ. Exercise 1.2. Let w 1,w 2,...,w k e k strings,

More information

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38 Theory of Computtion Regulr Lnguges (NTU EE) Regulr Lnguges Fll 2017 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of Finite Automt A finite utomton hs finite set of control

More information

Worked out examples Finite Automata

Worked out examples Finite Automata Worked out exmples Finite Automt Exmple Design Finite Stte Automton which reds inry string nd ccepts only those tht end with. Since we re in the topic of Non Deterministic Finite Automt (NFA), we will

More information

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck. Outline Automt Theory 101 Rlf Huuck Introduction Finite Automt Regulr Expressions ω-automt Session 1 2006 Rlf Huuck 1 Session 1 2006 Rlf Huuck 2 Acknowledgement Some slides re sed on Wolfgng Thoms excellent

More information

More on automata. Michael George. March 24 April 7, 2014

More on automata. Michael George. March 24 April 7, 2014 More on utomt Michel George Mrch 24 April 7, 2014 1 Automt constructions Now tht we hve forml model of mchine, it is useful to mke some generl constructions. 1.1 DFA Union / Product construction Suppose

More information

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun: CMPU 240 Lnguge Theory nd Computtion Spring 2019 NFAs nd Regulr Expressions Lst clss: Introduced nondeterministic finite utomt with -trnsitions Tody: Prove n NFA- is no more powerful thn n NFA Introduce

More information

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016 CS125 Lecture 12 Fll 2016 12.1 Nondeterminism The ide of nondeterministic computtions is to llow our lgorithms to mke guesses, nd only require tht they ccept when the guesses re correct. For exmple, simple

More information

DFA minimisation using the Myhill-Nerode theorem

DFA minimisation using the Myhill-Nerode theorem DFA minimistion using the Myhill-Nerode theorem Johnn Högerg Lrs Lrsson Astrct The Myhill-Nerode theorem is n importnt chrcteristion of regulr lnguges, nd it lso hs mny prcticl implictions. In this chpter,

More information

CM10196 Topic 4: Functions and Relations

CM10196 Topic 4: Functions and Relations CM096 Topic 4: Functions nd Reltions Guy McCusker W. Functions nd reltions Perhps the most widely used notion in ll of mthemtics is tht of function. Informlly, function is n opertion which tkes n input

More information

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science CSCI 340: Computtionl Models Trnsition Grphs Chpter 6 Deprtment of Computer Science Relxing Restrints on Inputs We cn uild n FA tht ccepts only the word! 5 sttes ecuse n FA cn only process one letter t

More information

Theory of Computation Regular Languages

Theory of Computation Regular Languages Theory of Computtion Regulr Lnguges Bow-Yw Wng Acdemi Sinic Spring 2012 Bow-Yw Wng (Acdemi Sinic) Regulr Lnguges Spring 2012 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of

More information

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS CS 310 (sec 20) - Winter 2003 - Finl Exm (solutions) SOLUTIONS 1. (Logic) Use truth tles to prove the following logicl equivlences: () p q (p p) (q q) () p q (p q) (p q) () p q p q p p q q (q q) (p p)

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 Automt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Problem (II) Chpter II.6.: Push Down Automt Remrk: This mteril is no longer tught nd not directly exm relevnt Anton Setzer (Bsed

More information

Model Reduction of Finite State Machines by Contraction

Model Reduction of Finite State Machines by Contraction Model Reduction of Finite Stte Mchines y Contrction Alessndro Giu Dip. di Ingegneri Elettric ed Elettronic, Università di Cgliri, Pizz d Armi, 09123 Cgliri, Itly Phone: +39-070-675-5892 Fx: +39-070-675-5900

More information

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1 Tle of Contents: Week 1: Preliminries (set lger, reltions, functions) (red Chpters 1-4) Weeks

More information

Java II Finite Automata I

Java II Finite Automata I Jv II Finite Automt I Bernd Kiefer Bernd.Kiefer@dfki.de Deutsches Forschungszentrum für künstliche Intelligenz Finite Automt I p.1/13 Processing Regulr Expressions We lredy lerned out Jv s regulr expression

More information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2 CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt

More information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb. CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt

More information

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers Speech Recognition Lecture 2: Finite Automt nd Finite-Stte Trnsducers Eugene Weinstein Google, NYU Cournt Institute eugenew@cs.nyu.edu Slide Credit: Mehryr Mohri Preliminries Finite lphet, empty string.

More information

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy: Scnner Specifying ptterns source code tokens scnner prser IR A scnner must recognize the units of syntx Some prts re esy: errors mps chrcters into tokens the sic unit of syntx x = x + y; ecomes

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 Automt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Problem (II) Chpter II.5.: Properties of Context Free Grmmrs (14) Anton Setzer (Bsed on book drft by J. V. Tucker nd K. Stephenson)

More information

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true. York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech

More information

Chapter 2 Finite Automata

Chapter 2 Finite Automata Chpter 2 Finite Automt 28 2.1 Introduction Finite utomt: first model of the notion of effective procedure. (They lso hve mny other pplictions). The concept of finite utomton cn e derived y exmining wht

More information

Bases for Vector Spaces

Bases for Vector Spaces Bses for Vector Spces 2-26-25 A set is independent if, roughly speking, there is no redundncy in the set: You cn t uild ny vector in the set s liner comintion of the others A set spns if you cn uild everything

More information

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Converting Regular Expressions to Discrete Finite Automata: A Tutorial Converting Regulr Expressions to Discrete Finite Automt: A Tutoril Dvid Christinsen 2013-01-03 This is tutoril on how to convert regulr expressions to nondeterministic finite utomt (NFA) nd how to convert

More information

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions CS 330 Forml Methods nd Models Dn Richrds, George Mson University, Spring 2016 Quiz Solutions Quiz 1, Propositionl Logic Dte: Ferury 9 1. (4pts) ((p q) (q r)) (p r), prove tutology using truth tles. p

More information

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1 CS4 45- Determinisitic Finite Automt -: Genertors vs. Checkers Regulr expressions re one wy to specify forml lnguge String Genertor Genertes strings in the lnguge Deterministic Finite Automt (DFA) re nother

More information

NFAs continued, Closure Properties of Regular Languages

NFAs continued, Closure Properties of Regular Languages Algorithms & Models of Computtion CS/ECE 374, Fll 2017 NFAs continued, Closure Properties of Regulr Lnguges Lecture 5 Tuesdy, Septemer 12, 2017 Sriel Hr-Peled (UIUC) CS374 1 Fll 2017 1 / 31 Regulr Lnguges,

More information

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research Speech Recognition Lecture 2: Finite Automt nd Finite-Stte Trnsducers Mehryr Mohri Cournt Institute nd Google Reserch mohri@cims.nyu.com Preliminries Finite lphet Σ, empty string. Set of ll strings over

More information

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA RIGHT LINEAR LANGUAGES. Right Liner Grmmr: Rules of the form: A α B, A α A,B V N, α V T + Left Liner Grmmr: Rules of the form: A Bα, A α A,B V N, α V T

More information

Homework Solution - Set 5 Due: Friday 10/03/08

Homework Solution - Set 5 Due: Friday 10/03/08 CE 96 Introduction to the Theory of Computtion ll 2008 Homework olution - et 5 Due: ridy 10/0/08 1. Textook, Pge 86, Exercise 1.21. () 1 2 Add new strt stte nd finl stte. Mke originl finl stte non-finl.

More information

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 4 1. UsetheproceduredescriedinLemm1.55toconverttheregulrexpression(((00) (11)) 01) into n NFA. Answer: 0 0 1 1 00 0 0 11 1 1 01 0 1 (00)

More information

CS 330 Formal Methods and Models

CS 330 Formal Methods and Models CS 330 Forml Methods nd Models Dn Richrds, George Mson University, Spring 2017 Quiz Solutions Quiz 1, Propositionl Logic Dte: Ferury 2 1. Prove ((( p q) q) p) is tutology () (3pts) y truth tle. p q p q

More information

Lecture 3: Equivalence Relations

Lecture 3: Equivalence Relations Mthcmp Crsh Course Instructor: Pdric Brtlett Lecture 3: Equivlence Reltions Week 1 Mthcmp 2014 In our lst three tlks of this clss, we shift the focus of our tlks from proof techniques to proof concepts

More information

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3 2 The Prllel Circuit Electric Circuits: Figure 2- elow show ttery nd multiple resistors rrnged in prllel. Ech resistor receives portion of the current from the ttery sed on its resistnce. The split is

More information

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.) CS 373, Spring 29. Solutions to Mock midterm (sed on first midterm in CS 273, Fll 28.) Prolem : Short nswer (8 points) The nswers to these prolems should e short nd not complicted. () If n NF M ccepts

More information

Myhill-Nerode Theorem

Myhill-Nerode Theorem Overview Myhill-Nerode Theorem Correspondence etween DA s nd MN reltions Cnonicl DA for L Computing cnonicl DFA Myhill-Nerode Theorem Deepk D Souz Deprtment of Computer Science nd Automtion Indin Institute

More information

ɛ-closure, Kleene s Theorem,

ɛ-closure, Kleene s Theorem, DEGefW5wiGH2XgYMEzUKjEmtCDUsRQ4d 1 A nice pper relevnt to this course is titled The Glory of the Pst 2 NICTA Resercher, Adjunct t the Austrlin Ntionl University nd Griffith University ɛ-closure, Kleene

More information

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes CSE 260-002: Exm 3-ANSWERS, Spring 20 ime: 50 minutes Nme: his exm hs 4 pges nd 0 prolems totling 00 points. his exm is closed ook nd closed notes.. Wrshll s lgorithm for trnsitive closure computtion is

More information

Revision Sheet. (a) Give a regular expression for each of the following languages:

Revision Sheet. (a) Give a regular expression for each of the following languages: Theoreticl Computer Science (Bridging Course) Dr. G. D. Tipldi F. Bonirdi Winter Semester 2014/2015 Revision Sheet University of Freiurg Deprtment of Computer Science Question 1 (Finite Automt, 8 + 6 points)

More information