Tutorial Automata and formal Languages

Size: px
Start display at page:

Download "Tutorial Automata and formal Languages"

Transcription

1 Tutoril Automt nd forml Lnguges Notes for to the tutoril in the summer term 2017 Sestin Küpper, Christine Mik 8. August 2017

2 1 Introduction: Nottions nd sic Definitions At the eginning of the tutoril we repet some concepts nd nottions, which cn e helpful for the understnding of the lecture. Nottion 1.1. In the following, we lwys use the following symols with certin mening Σ lphet (finite set) Z set of sttes of n utomton(finite set) G grmmr V set of vriles of grmmr (finite set) S the strting vrile of grmmr P production rules of grmmr (pirs (V Σ) + (V Σ) ) Σ the set of ll sequences over Σ, so Σ = { 1 2,... n n N 0, 1 i n : i Σ} L Lnguge (suset of Σ ) ε the empty word (n empty sequence over n ritrry Σ) Σ + the set of ll non-empty sequences over Σ, Σ + = Σ \ {ε} One of the most importnt concepts in the theory of forml lnguges is, of course, the concept of lnguge itself. Definition 1.2 (Lnguge). Let e Σ finite set, clled the lphet. Then we cll Σ the set of ll Words (sequences) over Σ, forml: Σ = { n n N 0, 1 i n : i Σ} Σ contins lso the empty sequence ε, which we lso cll the empty word. To see this, let e n = 0 is set in the ove definition. A lnguge L over n lphet Σ is n ritrry suset of Σ, forml: L Σ. Let us consider some exmples for lnguges: Exmple 1.3., the empty lnguge. Σ, the lnguge of ll words. {ε}, the lnguge including only the empty word. {w w {, } } the set of ll words over the lphet {, }, which strts with n. { n n n N 0 } over the lphet {, }. {w {(, )} # ( (w) = # ) (w) w w : # ( (w ) # ) (w )}, the lnguge of correctly rcketed expressions. denotes the prefix reltion. w w holds if nd only if w could e written s w = w w with w {, }. N 0 = {n 1 n 2...n m m N, 1 i m : n i {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, m 1 n 1 0}. Primes = {n N 0 n interpreted s nturl numer is prime.}. Remrk 1.4. In the exercises, we will often identify the set N 0 with the numer set N 0. Lnguges cn e chrcterized in vrious wys; in the context of this lecture, we re prticulrly interested in two types of models: 1. Genertive models (grmmrs) 2

3 2. Acceptors (utomt / mchines) Both models provide hierrchy of lnguges. The more generl the model, the lower the index of the lnguge clss, ut the more difficult it is to nswer questions out the respective lnguge clss. In the following, we will refer to the Chomsky hierrchy of lnguges defined y clsses of grmmrs. We will first define wht grmmr is nd then define the grmmr clsses. Definition 1.5. A grmmr is four-tuple (V, Σ, P, S), such tht V is finite set, clled the set of vriles. We usully use for elements A V uppercse letters nd denote the elements of V s vriles. Σ is finite set, clled lphet. We usully use for elements Σ lowercse letters nd denote the elements of Σ s lphet symols or letters. P is set of production rules, which mens pirs (l, r) (V Σ) + (V Σ). For set M, the nottion M + := M \ {ε} denotes the set of ll non-empty sequences over M. We use for P the nottion l r. S V is clled the strting symol. A grmmr cn perform derivtion step on word w (V Σ) + s follows: If rule l r exists, such tht w could e written s w 1 lw 2, w 1, w 2 (V Σ), then w could e derived to w 1 rw 2. Thus the occurrence of l is removed from the word nd r is inserted in its plce. We write w G w 1 rw 2 (or w w 1 rw 2, if the grmmr is cler from the context). The lnguge produced y G is defined s L(G) = {w Σ S G w}. Where G is the repeted ppliction of G, the lnguge L(G) is the set of ll words tht do not contin vriles nd cn e derived from S y G. Nottion 1.6. We write revited, if n rules with the sme left side l exist, insted off l r 1, l r 2,..., l r n usully l r 1 r 2... r n. If we formlly restrict the grmmrs, we otin hierrchy of grmmrs nmed fter the linguist Nom Chomsky, who originlly set them up. Definition 1.7 (Chomsky-Hierrchy of grmmrs). Let e G = (V, Σ, P, S) grmmr, the we denote with G grmmr of type 0 without imposing restrictions on the grmmr. 1 if for ll l r it holds, tht l r, or l = S nd for ll rules l r it holds tht S / r. Therefore, rule pplictions re never llowed to shorten the word unless they direct S directly to the empty word. Grmmrs tht stisfy this condition re lso clled context-sensitive. 2 if G is context-sensitive, nd for ll rules l r holds tht l V, so every rule on the left contins only single vrile. We cll G context-free in this cse. 3 if G is context-free nd in ddition to ll rules l r it holds tht r = A or r =, Σ, A V. We cll G regulr in this cse. 3

4 In this wy, grmmrs cn e clssified into strict hierrchy. Ech grmmr clss contins ll clsses with higher index, which mens, for exmple, tht ech type 3 grmmr is lso type 2, type 1, nd type 0. Furthermore, it is ovious tht for i = 1, 2, 3 there re grmmrs of type i 1, which re not of type i. We illustrte this vi four different grmmrs for the lnguge L = {w w {, } }: Exmple 1.8. The following grmmrs re grmmrs for the lnguge L = {w w {, } } over the lphet {, }. Hence we hve G i = ({A, S}, {, }, P i, S} for i = 0, 1, 2, 3. i = 0 P 0 is defined s: S A A A A. The grmmr is of type 0, since every grmmr is of type 0. However, the grmmr is not of type 1 ecuse A = 2, = 1 nd 2 1. So the l r condition is not stisfied for ll l r rules. i = 1 P 1 is defined ccording to: S A A A A. The grmmr is of type 1, s one cn esily verify: S = 1 2 = A, S = 1 =, A = 2 3 = A = A nd A = 2 = =. So l r is stisfied for ll rules l r. As grmmr of type 1, this grmmr is utomticlly lso of type 0. However, the grmmr is not of type 2 ecuse there re rules where the left-hnd side is not from V, i.e. ll those rules with the left-hnd side A. i = 2 P 2 is defined s: S A A A A. The grmmr is of the type 1, s cn e verified in the sme wy s in the previous cse, nd thus lso of the type 0. Moreover, the grmmr is of the type 2, since only A nd S pper s left-hnd side, oth of which re vriles. However, the grmmr is not of type 3 ecuse there is, for exmple, the rule A A, which is not llowed in regulr grmmrs. i = 3 P 3 is defined ccording to: S A A A A. The grmmr is of the type 2 (nd thus lso of the type 1, s well s of the type 0), s cn e verified in the sme wy s in the previous cse. Oviously, the grmmr is lso of type 3, since there re only rules in which on the right side there is either n lphet letter, or one of the expressions A or A ech hving the form tht the first chrcter is n lphet letter nd the second chrcter is vrile. However, nother suject of exmintion in the lecture re lnguges. The Chomsky hierrchy of grmmrs cn e nturlly extended to hierrchy of lnguges s follows: Definition 1.9. A lnguge L Σ is of Chomsky-Type i, i = 0, 1, 2, 3, if grmmr G exists, which includes the Chomsky-Type i nd produces L, therefore L(G) = L holds. Note tht the hierrchy of lnguges, similr to the hierrchy of grmmrs, is sed on ech other, which mens tht ech lnguge of type i, i > 0 is lso of type i 1. This is cler y simple oservtion: If lnguge L is of type i, then there is grmmr G of the type i tht genertes L y definition of the lnguge clsses. Since grmmr of the i type is lwys of type i 1, there is lso grmmr just G tht is of type i 1 nd which genertes the lnguge. To show tht lnguge is of prticulr Chomsky type, it is sufficient to specify corresponding grmmr. However, to show tht lnguge is not of certin type, further efforts re needed. In the simplest cse, the type 3 lnguges, one cn use suitle utomt model. In contrst to grmmrs, which function s producer systems tht is, they re le to generte words of lnguge mchines re cceptors. This mens tht they do not generte words, ut 4

5 expect n input from w Σ, similr to computer progrm, nd then check tht the word w is in the lnguge tht the mchines generte. Exmple We now consider some exercises: Exercise 1: Given the following grmmr G = ({S, A, B}, {, }, P, S) with P : S A B A A A B B B Wht lnguge is generted y this grmmr? Possile solution steps: First we derive some words: S A A or S A A A etc. You should try s mny different derivtions-steps s possile in order to recognize pttern. This mens tht you should look t which words cn not e derived. Let us try to derive the word : S A A or only A A, ut we could not generte. On closer inspection, it cn e seen tht there is no wy to end with using S A. Consider the derivtion pths to recognize the constrints of the produced words. Exercise 2: Adventure Specify grmmr tht llows only pths, so tht fter drgon there lwys follows jump into river in the cse no swords re ville. First consider wht this mens: Cn it e tht occurs in pth? If you strt S you hve to jump directly into the wter, s soon s you meet, S... S ε. But on the other hnd it cn lso e tht you find or you hve to cross. Therefore we hve S XS S ε nd X should exctly produce the symols or sequences of symols tht do not violte the Drgon rule: X. Exercise 3: Comintion of the simple door rule with the drgon rule. Rememer the simple door rule: Pssing door is only llowed if you hve key. You cn use key for every door. Strting from S we cn pss every symol possile y X. If we meet drgon we hve to jump into river. After hving found key, we use K for deriving the pths, in which we re now lso le to open every door: S XS S K ε K XK K K K ε X Exercise 4: Given lnguge L, we serch for grmmr G generting exctly the words of the lnguge. How do we determine grmmr, which is lso of the mximl type? 5

6 1. Consider the lnguge L 1 = { m c t m, t N \ {0}}. First property of every produced word is, tht you hve to strt with t lest one. So S S... should e the first ide for constructing grmmr, which llows you s mny s you wnt t the eginning of word. Now you should e le to switch to the prt of the word: S S B, ut still ensure tht there is t lest one t the eginning. A sequence of two is not tht difficult: A B nd B C, cuse you only wnt exctly two s. Now we only need to enle s mny c s s we wnt, ut t lest one: C Cc c. Of course you cn displce A C, ut tht would not e grmmr of type 3. Just try to void using rules of lower types, if you hve the feeling, tht it is higher Chomsky-type. 2. Consider L 2 = { m c t m, t N \ {0} nd m > t}. Agin every word should strt with t lest one, ut here we cn not produce s mny c s s we wnt. There must e more s thn c s in every word. So this time S BX could e one ide nd B B llows to produce ritrry mny s you. The vrile X should ensure, tht you cn not produce more c s thn s: X Xc... But now we somehow need to terminte with etween the two sequences: X Xc c. For tht lnguge we could not restrict to rules of type 3, ecuse we hve reltion etween the length of the eginning nd finl sequence of every word. 3. Consider L 3 = { m c 2m d m m, n 1} lnguge. Agin we hve reltion etween the eginning nd end of every word. But in ddition we re only llowed to produce twice s mny c s s s. So we only consider the type 1 rules here: S SCd ccd seems to e nice strt for our production rules. Tht wy we ensure tht only s mny d s s s re produced. But wht we get is something like tht: S SCd SCdCd ccdcdcd. To shift ll the d to the right side of the word nd ensure tht ll C occur in one sequence efore the sequence of d s we need to work with some context: dc Cd nd finlly cc ccc, just to ensure, tht we get two c s for every. Finlly, remrk on the specil rule for Typ 1 grmmrs: S ε: This rule is llowed if S does not pper on the right side of ny rule. This lso holds for Typ 2 nd Type 3. Through pproprite trnsformtions you cn crete grmmr tht is up to ε derivtions regulre (context-free), into regulre (Context-free) grmmr, which fulfill the specific ε rule. Such construction generlly does not exist for ll type 1 grmmrs. 2 Automt models nd concepts As lredy mentioned grmmrs generte words, ut there re lso concepts for modeling cceptors, which exctly ccept the words of lnguge L Σ for some given lphet Σ. 2.1 Automt models I (Regulr lnguges) We strt with n cceptnce model for lnguges, which cn e generted y Typ 3 grmmrs. Definition 2.1. A deterministic finite utomton is five-tuple M = (Z, Σ, z 0, δ, E) where Z nd Σ re finite sets, Z Σ = nd z 0 Z is the initil stte, E Z is the set of ccepting sttes. δ : Z Σ Z is the trnsfer function, which ssigns unique successor stte to ech pir of stte nd lphet symol. The set of ll words ccepted y DF A M is defined s the lnguge L(M). The set of ll lnguges ccepted y DFA is the clss of regulr lnguges. Non-deterministic finite utomt 6

7 (NFA), DFA, nd type-3 grmmrs (in the Chomsky hierrchy) descrie the sme lnguge clss. NFAs cn e converted into equivlent DFAs y mens of the power set construction. Definition 2.2. A non-deterministic finite utomton is five-tuple M = (Z, Σ, δ, S, E) where Z is finite set of sttes, Σ is finite set clled lphet, S is set of initil sttes, E is the set of finl sttes nd δ : Z Σ P(Z) is the trnsition function. Both concepts of modelling cceptors cpture ll regulr lnguges. By the power set construction NFA cn e trnsformed into DFA. Imgine n deterministic utomton simultes ll possile ehviours of NFA nd rememers ll sttes he is visiting. So the sttes of this utomton corresponds to set of sttes. Here is one exmple to demonstrte tht fct: Exmple 2.3. Powerset construction: NFA into DFA: c S1 S2 S3 Reding eing in stte S1 could end in stte S2 or S3 where reding n cn only led to stte S2 nd for c no trnsition is defined. This is cptured in the set {S2, S3}, {S2} nd : c {S1} {S2, S3} {S2} Here you see the whole DFA generted y the powerset construction: 7

8 c {S1},, c, c c {S2, S3} {S2} {S3} {S1, S2} c, c Another concept to descrie lnguges, which cn e modelled y DF A or NF A re regulr expressions. Definition 2.4. Regulr expression A regulr expression α is of the following structure: ε with Σ. The single symols of n lphet serves s the sic uilding locks for non trivil expressions. αβ Mens you just conctente two regulr expressions, for exmple α =, β = cc so αβ = cc. (α β) Choice the sme exmple (α β) = ( cc ). (α) nd (α) =, so this is the opertor tht enles the representtion of infinite lnguges. Or (β) = (cc ), such tht you cn construct ccccccccccccc. nd α, β re regulr expressions. In the next exmple we will summrise the reltion etween different grmmr types, finite utomt nd regulr expressions: Exmple 2.5. Consider the following grmmr G: S ε A B AXB AX XB X A A B B X X 8

9 1. Which type of grmmr do we hve? This grmmr is of type 2 ecuse the specil ε rule is stisfied nd l r for ll l r. 2. Descrie the lnguge using set nottion nd regulr expressions: L = { n () l m n, m, l N 0 } nd L(G) = ( () ) 3. Plese define grmmr of type 3 for the lnguge L from ove: S ε S 1 S 4 S 2 S 4 S 1 S 1 S 2 S4 S 3 S 2 S 4 S 2 S 3 S 4 S 4 4. Define n utomton, which exctly ccepts the lnguge L of G: strt S1 S2 S3 strt S4 Next we will discuss trnsformtions from NFA to regulr expressions considering n exmple: Exmple 2.6. The single steps re sed on the rules in the lecture. We strt with the regulr expression ((c )) to NFA: 1. Construct n utomton for the different sic locks: c, nd : c S1 S2 S3 S1 S1 S2 S3 2. First comine the utomton for (c ), just drwing oth utomt: c S1 S2 S3 S4 3. Next uild the utomton for (c ) connecting the ccepting sttes of (c ) with the initil sttes of nd mrk the initil stte of lso s initil stte ecuse ε (c ). 9

10 S1 S2 c S4 S3 S5 S6 4. Next, we need to connect the sttes connected with n ccepting stte of the utomton of step 4 with the initil sttes, such tht the str opertion is cptured y the NFA: S1 S2 c S4 S3 S5 S6 5. Lst, we need to dd n initil nd ccepting dditionl stte, to enle the empty word.( no illustrtion) Often the questions rises if lnguge is regulr or not. This question could e nswered y two different pproches. One pproch, the Pumping Lemm, cn e used to check if lnguge is not regulr, ut not to nswer the question if it is regulr. The other method is sed on equivlence reltions. Let us first concentrte on the Pumping Lemm: Pumping Lemm The ide ehind the Pumping Lemm is to use the property, tht regulr lnguges hs to e ccepted y n utomton consisting of finitely mny sttes. This mens for word x = uvw L which is t lest s long s the numer of sttes the utomton hs, one of the sttes z of the utomton must e visited t lest twice. v u z w The loop creted this wy, cn thn e repeted severl times (or not t ll), therey the word x = uvw is pumped up nd we find tht uv 2 w, uv 3 w,..., nd uw re lso in L. To chieve, tht z is visited t lest two times nd does not contin the empty word we demnd the following properties for x = uvw L: 1. v 1: The loop is not trivil nd ws tken t lest once. 2. uv n: After t most n lphet symols the stte z will e visited second time. How to use the pumping lemm to show tht lnguge is not regulr? Sttement of the pumping lemm with logicl opertors: L regulr n x L, x n u, v, w, x = uvw i (uv i w L) 10

11 n x L, x n u, v, w, x = uvw i (uv i w L) L is not regulr. This logicl sttements just men, tht if you find word x = uvw L for this lnguge, tht for some n nd ll uvw stisfying the conditions 1 nd 2 the pumping produces word uv i w / L then L is not regulr. Of course sometimes it could e hrd to find the right word x = uvw or there is mye none (see exmple lecture: L = { k m c m k, m 0} { i c j i, j 0}). In the ltter cse, no conclusion cn e drwn out the non regulrity of the lnguge. For such difficult cses we recommend to use the Myhill Nerode Theorem. Before we switch to the Myhill Nerode Theorem we first consider some exmples for the Pumping Lemm: Exmple 2.7. The following lnguges re not regulr: 1. L 1 = { n n n N 0 } Let n N 0 e given, we chosse x = n n, oviously the numer of symols in n n is 2n > n. Possile decomposition for x = n n : u = k v = l w = n l k n with l 1, k 0 nd l + k n. For i = 2 we get k 2l n l k n = n+l n / L. Note tht there re no further decompositions with the required properties tht re not lredy contined in this one. Only decompositions which re not lredy covered must e considered (u = ε is covered y 0 ). 2. L 2 = { n! n N 0 }. Let n N 0 e given, we chosse x = n!, oviously the numer of symols in n! is n! n. Possile decomposition for x = n! : u = k v = l w = n! l k with l 1, k 0 nd l + k n. For i = 2 we get k 2l n! l k = n!+l / L, since n! + l < (n + 1)! with l n for n > 1, i.e. n! + l m! for ll m N 0. But here the cse n = 0 nd n = 1 re not cptured. To cpture lso n 0 we choose x = (n+2)! : u = k v = l w = (n+2)! l k. For i = 2 we get (n+2)!+l since l n : (n + 2)! + l m! for ll m N 0, so (n+2)!+l / L L 3 = { k l c m 1 k < l, m 1, k, l, m N}. Let n N 0 e given, we chosse x = k n c, oviously the numer of symols in k n c is n + k + 1 > n. Possile decomposition for x = k n c with k < n: 1. u = j v = t w = n c with j + t < n. So for i = n it holds tht n t > n. hence uv n w / L 3 hence t u = j v = t s w = n s c with j + t + s < n. For i = 2 we get j t s t s n s c / L 3. Alterntiv word x = n n+1 c. Only one decomposition possile. Like mentioned efore the Pumping Lemm cn e used to show tht lnguge is not regulr, ut cnnot e used s decision-mking. Also in some cses it fils to show, tht lnguge is not regulr. However, in order to e le to mke sttements out the (non) regulrity of lnguge, we now focus on the Myhill Nerode Theorem. Remrk 2.8. In the next section we spek out equivlence reltions, plese hve look t the forml definition in the lecture slides, if you re not fmilir with it Myhill Nerode The ide ehind the next theorem is gin to use the finite set of sttes. Consider the following deterministic utomton M over the lphet Σ = {, }: 11

12 S1 S3 S2, From stte S 1 n yields n ccepting word. Also word tht hs the form yields word contined in L(M) from stte S 1. Now hve look t the stte S 2, from this reding n does not end up in word included in L(M). So oth sttes llow to mke different trnsitions or sequences of trnsitions to end up in n ccepting stte. This concept of llowing the sme sequences of trnsitions, which represents words in Σ is cptured y the Myhill Nerode Theorem. Definition 2.9. Myhill-Nerode-Equivlence Let e L lnguge nd words x, y Σ. We define n equivlence reltion R L with x R L y if nd only if for ll z Σ it holds tht (xz L yz L). For our exmple utomton consider x = nd y =. For oth words the set of words z Σ which produces xz L nd yz L is the sme set. This mens tht oth words elongs to the sme equivlence clss. For word like Σ every word z Σ does not generte word z L. So every word, where the set of suffixes, which cn continue the word such tht the resulting word is in L, is empty elongs to tht equivlence clss. This does not men tht you hve in generl the empty set for words w / Σ nd no z with wz L. In our exmple ε / L ut ε L. In our exmple we hve exctly three equivlence clsses: [ε] = {ε}: In this clss every z L with z = L yields word in L. This clss corresponds to stte S 1 nd [] = {w Σ z L( ) nd wz L.} is represented y stte S 2. For ll other words we hve third clss [] ecuse for them the set of vlid suffixes is the empty set, corresponding in our exmple to stte S 3. So looking t the miniml deterministic utomton of regulr lnguge you hve s mny equivlence clsses s sttes. So to check if lnguge is regulr, just check if you hve finitely mny equivlence clsses. Exmple To etter understnd this concept, let us tke look t some exmples, two for regulr lnguges nd one for non regulr lnguges. (We ssume tht we only consider the miniml utomt for given lnguge nd set of vlid suffixes mens: the set of words z Σ such tht for ll words w of n equivlence clss sed on lnguge L wz L) : 1. L 1 = { n m n + m 2; n, m N 0 } is regulr, hence we show tht we hve finitly mny equivlence clsses: 12

13 S1 S2 S3 S4 S5 F, [ε] = {ε} nd the set of suffixes is { n m n + m 2} [] = {} nd the set of suffixes is { n m n + m 1} [] = {,,,...} nd the set of suffixes is { n m n, m N 0 } [] = {} nd the set of suffixes is { m m N 1 } [] = { n m m 1, n + m 2} nd the set of suffixes is { m m N 0 } [] = {w w / L( )} nd the set of suffixes is {} 2. L 2 = {w Σ w 2} with Σ = {, } is regulr, hence we show tht we hve finitly mny equivlence clsses: S1 S2 S3, [ε] = {ε} nd the set of suffixes is {w Σ w 2} [] = {, } nd the set of suffixes is {w Σ w 1} [] = Σ \ {ε,, } nd the set of suffixes is Σ. 3. L 2 = { n n n N 0 } is not regulr, hence we show tht we hve infinitly mny equivlence clsses: Consider the words,,,..., i,... with i N 0. It holds tht ( i R L j ) for i j, since i i L nd j i L. So we hve for exmple different clss for every i N 0 with { k+i k k N 0 } nd the corresponding set of vlid suffixes is { i }. 4. L 3 = { n m c n+m n, m N} is not regulr, hence we show tht we hve infinitly mny equivlence clsses: It holds tht ( i R L j ) for i j, since i m c i+m L nd j m c i+m L. In the next section we will hve look t the context-free lnguges nd ccepting models. 2.2 Automt models II (Context free lnguges) Both models (finite utomt or regulr grmmrs) for regulr lnguges do not llow to rememer how often n lphet symol occurs within word. As lredy seen in context-free grmmrs, it is possile to generte words tht contin s mny s s s. We will now consider n cceptnce model tht exctly covers the context-free lnguges: 13

14 Definition A (non deterministic) pushdown utomt M is 6-tuple M = (Z, Σ, Γ, δ, z 0, #), wher Z set of sttes, Σ the input lphet (with Z Σ = ), Γ the cellr lphet, z 0 Z the initil stte, δ : Z (Σ {ε}) Γ P e (Z Γ ) the trnsfer function nd # Γ the lowest cellr symol. Before looking more closely t the reltion etween context-free grmmrs nd pushdown utomt, we first look t more efficient lgorithm for the word prolem Word prolem nd context-free grmmrs We repet the definition of the word prolem: Definition Word prolem Given grmmr G (ritrry grmmr type) nd word w Σ. Is w L(G)? In the lecture nd exercise we hve lredy discussed n lgorithm for the word prolem which pplies for grmmrs from type 1. Here we ssume tht context-free grmmr is given in Chomsky Normlform (plese hve look into the lecture slides for Chomsky Normlform nd trnsformtion of type 2 grmmr into grmmr in Chomsky Normlform). Definition Chomsky Normlform Given context-free grmmr G = (V, Σ, P, S) ll rules in P re of the following two forms: A BC or A Given n ritrry word x Σ we wnt to know how this word could e generted y the given grmmr in Chomsky Normlform. One cse could e, tht the word only consists of one single terminl symol, so it is esy to check, if ny rule in P enles derivtion form S A i with A i V. In the other cse the word x = 1... n consists of severl terminl symols. In this cse first production of the form A BC must e pplied nd prt 1... k should e derived from B nd k+1... n from C. However, it is not cler where the word x must e divided, tht is, how ig the index k is. To solve this prolem the following concept is used: Given word x = 1... n. Check for ll k with 1 k < n: Determine ll vriles V 1 from which 1... k is derivle. Determine ll vriles V 2 from which k+1... n is derivle. Determine whether there re vriles A, B, C with A BC P nd B V 1, C V 2. In this cse x could e generted y A. This concept is optimized y the following CYK-Algorithm: First determine ll vriles from which ll suwords of x of the length 1 could e derived. Then determine ll vriles from which ll suwords of x of the length 2 could e derived. 14

15 ... Then determine ll vriles from which x could e derived nd if S is n element of this set the word x cn e generted y the grmmr G. We lso illustrte this concept y n exmple. The generl work flow of this lgorithm is demonstrted in the slides ( ). Exmple Let the grmmr G = ({S, U, B, V, X, A, A }, {, }, P, S) e given nd P is defined s follows: S UB A UB X V B A B U BX A V A A B Given the word x = L(G) we demonstrte how this lgorithm works: We construct the following tle with some intermedite steps strting with the suwords of length 1: 1 B A B A B B B B Next we consider ll suwords of length 2, due to this no entry for the suword cuse no rule of the form V BA with V V exists, ut X A B P for : 1 B A B A B B B B 2 X X Next we consider ll suwords of length 3, due to this no entry for the suword cuse no rule of the form V XA with V V exists, ut U BX P for : 1 B A B A B B B B 2 X X 3 U U After steps 4,5,6 nd 7 we finlly get for the word x of length 8: 1 B A B A B B B B 2 X X 3 U U 4 S, A 5 V 6 X 7 U 8 S, A In the next section we discuss the concept of trnsforming pusdown utomt into grmmrs nd vice vers. 15

16 2.2.2 Context free Grmmr Pushdown utomton In tht section we wnt to consider how to trnsform pushdown utomton into contextfree grmmr nd vice vers. Let e non deterministic pushdown utomton given where δ is defined s follows: K = ({z 0, z 1 }, {, }, {#, A}, δ, z 0, #) δ(z 0,, #) = {(z 0, A#)} δ(z 0,, A) = {(z 0, AA)} δ(z 0,, A) = {(z1, ε)} δ(z 0, ε, #) = {(z 0, ε)} δ(z 1,, A) = {(z1, ε)} δ(z 1, ε, #) = {(z 1, ε)} All other δ(z, t, V ) with z {z 0, z 1 }, t {, } nd V {A, #} re mpped to the emptyset. Before we extrct the production rules for the grmmr, we first need to estlish the vrile set V. The lphet is the sme s for the pushdown utomton nd the initil Vrile is S. And V = {S, (z 0, #, z 0 ), (z 0, #, z 1 ), (z 1, #, z 0 ), (z 1, #, z 1 ), (z 0, A, z 0 ), (z 0, A, z 1 ), (z 1, A, z 0 ), (z 1, A, z 1 )} First we provide production rule for removing the ottom element of the stck # with S (z 0, #, z 0 ) (z 0, #, z 1 ). Next we cpture deleting of A from top of the stck if the utomton is in stte z 0 reding on the input tpe with (z 0, A, z 1 ) nd (z 1, A, z 1 ) for eing in stte z 1. If the complete word is red nd the lst symol on the stck is # the stck is emptied, This ehviour of the pushdown utomton is trnsformed into the rule (z 1, #, z 1 ) ε. Now we consider the remining two prts of δ. Here we will descrie the trnsformtion sed on δ(z 0,, #) = {(z 0, A#)}, which mens tht the symol # is replced y A# if the utomton is in the stte z 0 nd reds n (for the second prt it is similr). This implies tht this two symols on the stck, hs to e removed somehow. It is not cler which sttes simulte the deleting, so we construct the production in the following wy: (z 0, #,?) (z0, A,?)(?, #,?) We construct ll possile comintions sed on the sttespce: (z 0, #, z 0 ) (z 0, A, z 0 )(z 0, #, z 0 ) (z 0, #, z 0 ) (z 0, A, z 1 )(z 1, #, z 0 ) (z 0, #, z 1 ) (z 0, A, z 0 )(z 0, #, z 1 ) (z 0, #, z 1 ) (z 0, A, z 1 )(z 1, #, z 1 ) It cn e, tht some production rules do not produce sequences of terminl symols, like for exmple (z 0, #, z 0 ) (z 0, A, z 1 )(z 1, #, z 0 ), ut tht hs no impct on the lnguge L = { n n n N 0 }. And finlly the rest of the production rules sed on δ(z 0,, A) = {(z 0, AA)}: (z 0, A, z 0 ) (z 0, A, z 0 )(z 0, A, z 0 ) (z 0, A, z 0 ) (z 0, A, z 1 )(z 1, A, z 0 ) (z 0, A, z 1 ) (z 0, A, z 0 )(z 0, A, z 1 ) (z 0, A, z 1 ) (z 0, A, z 1 )(z 1, A, z 1 ) 16

17 Now we consider the opposite direction, where we trnsform grmmr into n pushdown utomton. Agin we consider the lnguge L = { n n n N 0 }, ut this time descried y the grmmr G = ({S, X}, {, }, P, S) with P defined s follows: S X ε X X For tht trnsformtion we use the stck to derive word (somehow the word is guessed). After prts of the word re compred with the input they re removed if they mtch the input. So we construct the pushdown utomton K = ({z}, {, }, {S, X} {, }, δ, z, S) nd δ is defined s follows: δ(z, ε, S) {(z, X), (z, ε), (z, )} nd δ(z, ε, X) {(z, X), (z, )} for rting word on the stck sed on P. δ(z,, ) {(z, ε)} nd δ(z,, ) {(z, ε)} for compring the rted word with the input word w. Exmple Let e the word e given nd the write-red hed is positioned t the eginning of the word from the left. First we rte S X nd updte the stck. After tht we compre the symol on the input tpe with the top of the stck nd remove the. Since comprison of X nd leds to mismtch, we gin guess derivtion on the stck X. After tht we compre the content of the input tpe with the top of the stck nd remove the mtching prts. Input tpe: Stck: X X S Just s with the regulr lnguges, sometimes the question rises whether lnguge is context-free. This cn e the cse, for exmple, if one hs determined tht lnguge is not regulr, ut one nevertheless wnts to use n efficient method for the word prolem. For this we will look t the pumping lemm for context-free lnguges in the next section Context-free lnguges: Pumping Lemm For context-free lnguges similr concept is used s for regulr lnguges is used. But here it is not considered, how often stte is visited in run of n utomton, ut whether vrile is used twice when deriving the word from grmmr. For word of sufficient length vrile is used inside the syntx tree t lest twice. Thinking of the fct, tht every context-free lnguge could e represented y type 2 grmmr in Chomsky norml form we cn infer long enough mens, tht word z L stisfies z 2 k where k is the numer of vriles of the grmmr in Chomsky norml form. Then it is ovious tht pth in the syntx tree exists with k + 1 nodes. In order to cpture the effect of visiting vrile twice, we consider decomposition of z into five prts z = uvwxy. To reduce the numer of decompositions we demnd the following properties for z = uvwxy L nd n = 2 k : 1. vx 1: 2. vwx n: nd 3. for ll i = 0, 1, 2,... it holds: uv i wx i y L. To show tht lnguge is not context-free we need to consider ll possile decompositions of z stisfying vx 1 nd vwx n nd prove tht some i N exists such tht uv i wx i y / L. 17

18 Exmple Consider the lnguge L = { n m n n > m}. We choose z = n+1 n n+1. Becuse of vwx n there re only four different cses how the symols cn e distriuted: vwx only consists of: s s followed y s only s s followed y s Now let us discuss wht hppens for every cse, no mtter how the decomposition looks in detil if we choose n i 1: s: For i = 2 we get more s efore the s thn fter them. This genertes word, which is not in L. (Or more s fter the s thn efore the s.) s followed y s: Agin for i = 2 we get more s efore the s thn fter the s. This genertes word, which is not in L. only s: We get for i = (n + 1) 2 more s thn s t ll. s followed y s: We get more s fter the s thn efore the s. 18

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

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

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

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

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 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

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

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

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

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

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

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 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014 CS125 Lecture 12 Fll 2014 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

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

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

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

Lecture 9: LTL and Büchi Automata

Lecture 9: LTL and Büchi Automata Lecture 9: LTL nd Büchi Automt 1 LTL Property Ptterns Quite often the requirements of system follow some simple ptterns. Sometimes we wnt to specify tht property should only hold in certin context, clled

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

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

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

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

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

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

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

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

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

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

State Minimization for DFAs

State Minimization for DFAs Stte Minimiztion for DFAs Red K & S 2.7 Do Homework 10. Consider: Stte Minimiztion 4 5 Is this miniml mchine? Step (1): Get rid of unrechle sttes. Stte Minimiztion 6, Stte is unrechle. Step (2): Get rid

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

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Lexicl Anlysis nd These slides re sed on slides copyrighted y Keith Cooper, Ken Kennedy & Lind Torczon t Rice University First Progrmming Project Instruction Scheduling Project hs een posted

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

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

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

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

NFAs continued, Closure Properties of Regular Languages

NFAs continued, Closure Properties of Regular Languages lgorithms & Models of omputtion S/EE 374, Spring 209 NFs continued, losure Properties of Regulr Lnguges Lecture 5 Tuesdy, Jnury 29, 209 Regulr Lnguges, DFs, NFs Lnguges ccepted y DFs, NFs, nd regulr expressions

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

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

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

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

Normal Forms for Context-free Grammars

Normal Forms for Context-free Grammars Norml Forms for Context-free Grmmrs 1 Linz 6th, Section 6.2 wo Importnt Norml Forms, pges 171--178 2 Chomsky Norml Form All productions hve form: A BC nd A vrile vrile terminl 3 Exmples: S AS S AS S S

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

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 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

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

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

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

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

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

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

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

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

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

Some Theory of Computation Exercises Week 1

Some Theory of Computation Exercises Week 1 Some Theory of Computtion Exercises Week 1 Section 1 Deterministic Finite Automt Question 1.3 d d d d u q 1 q 2 q 3 q 4 q 5 d u u u u Question 1.4 Prt c - {w w hs even s nd one or two s} First we sk whether

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

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

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

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

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

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

Automata and Languages

Automata and Languages Automt nd Lnguges Prof. Mohmed Hmd Softwre Engineering Lb. The University of Aizu Jpn Grmmr Regulr Grmmr Context-free Grmmr Context-sensitive Grmmr Regulr Lnguges Context Free Lnguges Context Sensitive

More information

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6 CS311 Computtionl Strutures Regulr Lnguges nd Regulr Grmmrs Leture 6 1 Wht we know so fr: RLs re losed under produt, union nd * Every RL n e written s RE, nd every RE represents RL Every RL n e reognized

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

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7 CS103 Hndout 32 Fll 2016 Novemer 11, 2016 Prolem Set 7 Wht cn you do with regulr expressions? Wht re the limits of regulr lnguges? On this prolem set, you'll find out! As lwys, plese feel free to drop

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

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

p-adic Egyptian Fractions

p-adic Egyptian Fractions p-adic Egyptin Frctions Contents 1 Introduction 1 2 Trditionl Egyptin Frctions nd Greedy Algorithm 2 3 Set-up 3 4 p-greedy Algorithm 5 5 p-egyptin Trditionl 10 6 Conclusion 1 Introduction An Egyptin frction

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

Non-deterministic Finite Automata

Non-deterministic Finite Automata Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd T. vn Lrhoven Institute for Computing nd Informtion Sciences Intelligent

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

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

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

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

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

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

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1 Non-Deterministic Finite Automt Fll 2018 Costs Busch - RPI 1 Nondeterministic Finite Automton (NFA) Alphbet ={} q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 2 Nondeterministic Finite Automton (NFA) Alphbet

More information

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51 Non Deterministic Automt Linz: Nondeterministic Finite Accepters, pge 51 1 Nondeterministic Finite Accepter (NFA) Alphbet ={} q 1 q2 q 0 q 3 2 Nondeterministic Finite Accepter (NFA) Alphbet ={} Two choices

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

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

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

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