CSCI 2400 Models of Computtion, Section 3 Solutions to Homework 4 Problem 1. ll the solutions below refer to the Pumping Lemm of Theorem 4.8, pge 119. () L = f n b l k : k n + lg Let's ssume for contrdiction tht L is regulr lnguge. We pply the pumping lemm to L. Let m be the prmeter of the pumping lemm. We choose to pump the string m b m 2m which is in the lnguge L, since 2m m+m (we hve n = m, l = m, nd k =2m). Since xyz = m b m 2m nd jxyj»m we hve tht the string y is substring of the first m of m b m 2m. Therefore, the string y hs the form y = p, for some integer p, 1» p» m (since jyj 1). Now, we pump up y once nd we obtin the string m+p b m 2m which is string identicl to m b m 2m with the only difference tht we replce y with y 2. By the pumping lemm, we hve tht m+p b m 2m is in the lnguge L. However, m+p b m 2m is not in the lnguge L since 2m <m+ p + m (violting the condition k n + l, where n = m+p, l = m, nd k = 2m). Therefore, we hve contrdiction. Subsequently, our originl ssumption tht the lnguge L is regulr must be wrong. Therefore, the lnguge L is not regulr. (b) L = fww : w 2 ± Λ g Let's ssume for contrdiction tht L is regulr lnguge. We pply the pumping lemm to L. Let m be the prmeter of the pumping lemm. We choose to pump the string m b m m b m which is in the lnguge L, since m b m m b m = ww with w = m b m. Since xyz = m b m m b m nd jxyj» m, we hve tht the string y is substring of the first m of m b m m b m. Therefore, the string y hs the form y = p, for some integer p, 1» p» m (since jyj 1). Now, we pump up y once nd we obtin the string m+p b m m b m which is string identicl to m b m m b m with the only difference tht we replce y with y 2. By the pumping lemm, wehve tht m+p b m m b m is in the lnguge L. However, m+p b m m b m is not in the lnguge L since there is no string w such tht m+p b m m b m = ww. Therefore, we hve contrdiction. Subsequently, our originl ssumption tht the lnguge L is regulr must be wrong. Therefore, the lnguge L is not regulr. (c) L = f k2 g Let's ssume for contrdiction tht L is regulr lnguge. We pply the pumping lemm to L. Let m be the prmeter of the pumping lemm. We choose to pump the string m2 which obviously is in the lnguge L. 1
For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the first m of m m m. Therefore, the string y hs the form y = p, for some integer p, 1» p» m (since jyj 1). Now, we pump up y once nd we obtin the string m+p m m which is string identicl to m m m with the only difference tht we replce y with y 2. By the pumping lemm, we hve tht m+p m m is in the lnguge L. On the other hnd, we cn rewrite m+p m m s m+p m m = p m m m = p m2 = m2 +p : m2 +p The string would be in the lnguge L if there would exist n integer k such tht m2 +p = k2. But there is no such k. To prove this, observe the following: since p» m. This implies tht m 2 <m 2 + p<m 2 +2m +1=(m +1) 2 ; Tking the squre roots we obtin, m 2 <k 2 < (m +1) 2 : m<k<m+1; which is impossible, since m nd k re positive integers. Therefore, there in no k such tht m2 +p = k2. Subsequently, the string m2 +p is not in the lnguge L. Therefore, we hve contrdiction. Subsequently, our originl ssumption tht the lnguge L is regulr must be wrong. Therefore, the lnguge L is not regulr. (d) L = fuww R v : u; v; w 2 ± + ; juj jvjg Let's ssume for contrdiction tht L is regulr lnguge. We pply the pumping lemm to L. Let m be the prmeter of the pumping lemm. We choose to pump the string (b) m (b) m which is in the lnguge L, by tking u = (b) m, ww R =, nd v = (b) m (notice tht juj = jvj, nd thus the condition juj jvj holds). We note tht in the string (b) m (b) m the rightmost loction of the middle of ny substring of the form ww R must pper within the middle substring. Since xyz = (b) m (b) m nd jxyj»m, wehve tht the string y is substring of the 2
first u =(b) m. Now let's pump down the string y, by removing it from the string (b) m (b) m. The resulting string hs the form u 0 (b) m, where u 0 is idecticl with the substring u =(b) m with the difference tht y is removed. By the pumping lemm we hve tht the string u 0 (b) m is in the lnguge L. On the other hnd, we hve tht ju 0 j < juj (since we pumped down y, nd jyj 1). Notice now tht in the string u 0 (b) m the rightmost loction of the middle of ny substring of the form ww R must pper in the substring, right fter u 0. For ww R =, the string u 0 (b) m cn be written in the form u 0 ww R v, with ju 0 j < juj = jvj. Therefore, the condition ju 0 j jvj of lnguge L is violted. The sme violtion occurs even when we identify the string ww R s ny other possible substring of u 0 (b) m (which could possibly spn u 0 nd v), since the middle of tht substring ppers in or t the left from. Therefore, the string u 0 (b) m is not in the lnguge L. Therefore, we hve contrdiction. Subsequently, our originl ssumption tht the lnguge L is regulr must be wrong. Therefore, the lnguge L is not regulr. Problem 2. () L = fw : n (w) 6= n b (w)g Not regulr. Intuitive explntion: For ny string in this lnguge we need to keep count of the numbers of 's nd b's so tht we compre them. finite utomton cnnot count the numbers of 's nd b's in n rbitrry input string, since the number of sttes is finite nd the input string length cn be rbitrrily lrge. Forml Explntion: Consider the complement lnguge L = fw : n (w) = n b (w)g. By the pumping lemm, the lnguge L is not regulr (you cnnot pump the string m b m ). Since regulr lnguges re closed under complement, it follows tht the lnguge L is not regulr either (if L ws regulr then L would be regulr too). (b) L = f n b l : n 100;l» 100g Regulr. Explntion: You cn construct finitite utomton tht ccepts this lnguge. The utomton hs two prts connected in series. The first prt recognizes strings of the form n with n 100 (this prt consists from sequence of 100 sttes, ech stte for single, then followed by loop stte for the 's fter the 100th ). The second prt recognizes strings of the form b l, where l» 100 (this prt consists from sequence of 100 sttes, ech stte for single b, nd ech stte is finl stte). 3
(c) L = fuww R v : u; v; w 2 ± + g Regulr. Explntion: The regulr expression tht describes this lnguge is ( + b) + ( + bb)( + b) + where the superscript +" mens 1 or more repetitions (the superscript Λ" mens 0 or more repetitions). (d) L = fb n l b k : n>5;l >3;l kg Not Regulr. Intuitive explntion: For ny string in this lnguge we need to keep count of the numbers of 's nd b's so tht we compre them. finite utomton cnnot count the numbers of 's nd b's in n rbitrry input string, since the number of sttes is finite nd the input string length cn be rbitrrily lrge. Forml Explntion: Consider the reverse lnguge L R = fb k l b n : n> 5;l > 3;l kg. By the pumping lemm, the lnguge L R is not regulr (you cnnot pump the string b m m 4 b 6 ). Since regulr lnguges re closed under reversl, it follows tht the lnguge L is not regulr either (if L ws regulr then L R would be regulr too). Problem 3. () L = fw : w strts nd ends with the sme symbol, nd w 2f; bg Λ g The following grmmr genertes lnguge L, where S is the strt vrible. S! T j bt b T! T j bt j The vribles S generte ny string tht strts nd ends with the sme symbol. The vrible T genertes ny string mde from 's nd b's. (b) The complement of the lnguge L = f n b n g. The following grmmr genertes lnguge L, where S is the strt vrible. S! 1 j 2 j 3 j B 1! 1 j 2! 1 X j 1 XT 3! XbT j XT 4
B! bt X! Xb j b T! T j bt j The vribles of the grmmr correspond to cse nlysis of the possible strings. The vribles 1, 2 nd 3 generte ll the strings tht strt with n, nd the vrible B genertes ll the strings tht strt with b. Therefore, the strt vrible S covers ll the cses. In order to generte the desired strings we use the helping vribles X nd T s follows. The vrible X genertes ll the strings of the form n b n, which wewnt tovoid (since these re excluded from the desired lnguge). The vrible T genertes ny string mde from symbols nd b (nmely, the lnguge ( + b) Λ ). The three cses of strings strting with re the following: Vrible 1 : genertes ny string of the form Λ. Vrible 2 : genertes ny string of the form + n b n nd + n b n (+ b) Λ. Vrible 3 : genertes ny string of the form n b n ( + b) +. (The + superscript mens one or more occurence.) These re ll the cses of strings strting with n. Notice tht vribles 2 nd 3 del with the cse where n b n is substring. The wy we remove n b n is by conctenting other strings to the left nd right of n b n. (c) L = fw : n (w) =2n b (w); where w 2f; bg Λ g The following grmmr genertes lnguge L, where S is the strt vrible. S! SS j S! Sb j Sb j Sb S! bs j bs j bs This is modifiction of the grmmr of Exmple 1.12 in pge 23 which hndles the cse n (w) =n b (w). The min difference here is tht we dd n extr symbol to ech possible position of the righthnd side of ech production tht hs terminl. (d) L = fw#x : w R is substring of x, where w; x 2f; bg Λ g The following grmmr genertes lnguge L, where S is the strt vrible. S! T! j bb j #T T! T j bt j 5
The strings in the lnguge hve the form w#uw R v, where u nd v re strings of the form ( + b) Λ (ny string mde from symbols nd b). The vrible T genertes the strings u nd v, while vrible genertes the string w#uw R nd the vrible S genertes the desired string w#uw R v. Problem 4. () The string s = b hs the following two leftmost derivtions: S ) B ) b S ) B ) B ) B ) b (b) The two derivtion trees of string b re shown in Figure 1. S ) B ) b S B b S ) B ) B ) B ) b S B b Figure 1: The two derivtion trees of string b 6
(c) The equivlent unmbiguous grmmr is the following: S! b! j This grmmr is not mbiguous becuse t ny derivrion step there is only one choice to mke. This grmmr is equivlent to the previous grmmr becse both grmmrs generte the sme lnguge: ll the stings tht strt with one or more 's nd end with single b. (d) With the new grmmr the unique leftmost derivtion nd derivtion tree of the string b re shown in Figure 2. S ) b ) b ) b S b Figure 2: The derivtion of string b with the unmbiguous grmmr 7