Upcoming SlideShare
×

# 0227 regularlanguages

1,161 views

Published on

1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
1,161
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
69
0
Likes
1
Embeds 0
No embeds

No notes for slide

### 0227 regularlanguages

1. 1. Regular Languages <ul><li>Finite Automata </li></ul><ul><ul><li>eg. Supermarket automatic door: </li></ul></ul>exit or entrance
2. 2. Finite Automata Door state Input signal State transition table State diagram OPEN OPEN OPEN CLOSED OPEN CLOSED CLOSED OPEN CLOSED CLOSED BOTH REAR FRONT NEITHER
3. 3. Definition <ul><li>A finite automaton is a 5-tuple (Q,  ,  , q 0 , F) </li></ul><ul><ul><li>Q : a finite set called the states </li></ul></ul><ul><ul><li> : a finite set called the alphabet </li></ul></ul><ul><ul><li> : Qx   Q is the transition function </li></ul></ul><ul><ul><li>q 0  Q is the start state </li></ul></ul><ul><ul><li>F  Q is the set of accept states </li></ul></ul>final states
4. 4. <ul><li>M 1 = (Q,  ,  , q 0 , F) </li></ul><ul><ul><li>Q = {q 1 , q 2 , q 3 } </li></ul></ul><ul><ul><li> = {0, 1} </li></ul></ul><ul><ul><li> : 0 1 </li></ul></ul><ul><ul><li> q 1 q 1 q 2 </li></ul></ul><ul><ul><li> q 2 q 3 q 2 </li></ul></ul><ul><ul><li> q 3 q 2 q 2 </li></ul></ul><ul><ul><li>q 1 : the start state </li></ul></ul><ul><ul><li>F = {q 2 } </li></ul></ul>L(M) = A M recognizes A or M accepts A the set of all strings that M accepts L(M 1 ) = ?
5. 5. q 2 q 3 q 2 q 3 q 2 q 3 100000 101011 M 2 =({q 1 ,q 2 }, {0,1},  , q 1 , {q 2 }) Eg:  : 0 1 q 1 q 1 q 2 q 2 q 1 q 2 L(M 2 ) =? M 2 : L(M 2 ) = {w | w ends in a 1}
6. 6. M 3 : L(M 3 )=? L(M 3 )={  or ends in 0}
7. 7. M 4 : Starts and ends with the same symbol
8. 8. What is the language accepted by the above automata? 1 0 <RESET> 2 2 <RESET> 0 1 2 M 5 :  ={<RESET>, 0, 1, 2}
9. 9. L(M 5 ) = {w | the sum of the symbols in w is 0 modulo 3 except the <RESET> resets to 0} M 5 :  ={<RESET>, 0, 1, 2}
10. 10. Formal definition of computation <ul><li>M = (Q,  ,  , q 0 , F) </li></ul><ul><li>w : a string over  , w i   , w = w 1 w 2 … w n </li></ul><ul><li>M accepts w if a sequence of states r 0 , r 1 , …, r n exists in Q and satisfies the following 3 conditions: </li></ul><ul><ul><li>r 0 = q 0 </li></ul></ul><ul><ul><li> ( r i , w i+1 ) = r i+1 , for i = 0, …, n-1 </li></ul></ul><ul><ul><li>r n  F </li></ul></ul>
11. 11. <ul><li>We say that M recognizes language A if A = { w | M accepts w } </li></ul><ul><li>Def: A language is called a regular language if some finite automata recognizes it. </li></ul>
12. 12. Designing finite automata <ul><li>Let A = { w | w is 0-1 string and w has odd number of 1} </li></ul><ul><li>Is A a regular language ? </li></ul><ul><li>What is the automata accepting A ? </li></ul>
13. 13. Designing finite automata <ul><li>eg: Design a finite automaton to recognize all strings that contains 001 as a substring </li></ul>
14. 14. Regular operations <ul><li>A, B : languages </li></ul><ul><li>Regular operations : union, concatenation, star </li></ul><ul><ul><li>Union : </li></ul></ul><ul><ul><li>A  B = { x | x  A or x  B} </li></ul></ul><ul><ul><li>Concatenation : </li></ul></ul><ul><ul><li>A 。 B = { x y | x  A and y  B} </li></ul></ul><ul><ul><li>Star : </li></ul></ul><ul><ul><li>A* = { x 1 x 2 … x k | k  0 and each x i  A } </li></ul></ul>
15. 15. Regular operations <ul><li>eg:  = { a, b, c, …, z} (26 letters) A = { good, bad} B = { boy, girl} </li></ul><ul><li>A  B = { good, bad, boy, girl} A 。 B = {goodboy, goodgirl, badboy,badgirl} A* = {  , good, bad, goodbad, badgood, goodgood, badbad, goodgoodgood, goodgoodbad, ………} </li></ul>
16. 16. <ul><li>eg. A 1 ={ w | w has odd number of 1} </li></ul><ul><ul><li>Q 1 = {q even , q odd } </li></ul></ul><ul><ul><li> = {0,1} </li></ul></ul><ul><ul><li> 1 : 0 1 q even q even q odd q odd q odd q even </li></ul></ul><ul><ul><li>q even : start state </li></ul></ul><ul><ul><li>q odd : accept state </li></ul></ul>
17. 17. <ul><li>eg. A 2 ={ w | w has a 1} </li></ul><ul><ul><li>Q 2 = {q 1 , q 2 } </li></ul></ul><ul><ul><li> = {0,1} </li></ul></ul><ul><ul><li> 2 : 0 1 q 1 q 1 q 2 q 2 q 2 q 2 </li></ul></ul><ul><ul><li>q 1 : start state </li></ul></ul><ul><ul><li>q 2 : accept state </li></ul></ul>
18. 18. <ul><li>A 1  A 2 ={ w | w has odd number of 1 or w has a 1} </li></ul><ul><ul><li>Q= {(q even ,q 1 ), (q even ,q 2 ), (q odd ,q 1 ), (q odd ,q 2 )} </li></ul></ul><ul><ul><li> = {0, 1} </li></ul></ul><ul><ul><li> : 0 1 (q even , q 1 ) (q even , q 1 ) (q odd , q 2 ) (q even , q 2 ) (q even , q 2 ) (q odd , q 2 ) (q odd , q 1 ) (q odd , q 1 ) (q even , q 2 ) (q odd , q 2 ) (q odd , q 2 ) (q even , q 2 ) </li></ul></ul><ul><ul><li>(q even , q 1 ): start state </li></ul></ul><ul><ul><li>(q odd , q 1 )(q odd , q 2 )(q even , q 2 ): accept state </li></ul></ul>
19. 19. <ul><li>Theorem: The class of regular languages is closed under the union operation (in other words, if A 1 and A 2 are regular languages, so is A 1  A 2 ) </li></ul>
20. 20. <ul><li>Pf : Let M 1 recognize A 1 , where M 1 = (Q 1 ,  ,  1 , q 1 , F 1 ) M 2 recognize A 2 , where M 2 = (Q 2 ,  ,  2 , q 2 , F 2 ) Goal: Construct M=(Q,  ,  , q 0 , F) to recognize A 1  A 2 </li></ul><ul><ul><li>Q={(r 1 ,r 2 )|r 1  Q 1 and r 2  Q 2 } </li></ul></ul><ul><ul><li> is the same in M 1 , M 2 </li></ul></ul><ul><ul><li>For each (r 1 , r 2 )  Q and each a   , let  ((r 1 ,r 2 ), a)=(  1 (r 1 ,a),  2 (r 2 ,a)) </li></ul></ul><ul><ul><li>q 0 =(q 1 , q 2 ), (q 0 is a new state  Q 1  Q 2 ) </li></ul></ul><ul><ul><li>F={(r 1 , r 2 )|r 1  F 1 or r 2  F 2 } </li></ul></ul>
21. 21. <ul><li>Theorem: The class of regular languages is close under the concatenation (in other words, if A 1 and A 2 are regular languages, so is A 1 。 A 2 ) </li></ul>
22. 22. Nondeterminism: <ul><li>eg. </li></ul>Deterministic Computation Non Deterministic Computation
23. 23. Input : 0 1 0 1 1 0
24. 24. <ul><li>eg: </li></ul><ul><li>A : the language consisting of all strings over {0, 1} containing a 1 in the 3rd position from the end </li></ul>
25. 25. 0 1 1 0 0 1
26. 26. <ul><li>eg: What does the following automaton accept? </li></ul>1. 2.   
27. 27. Formal definition of a nondeterministic finite automaton <ul><li>  =  {  }, P (Q) : the collection of all subset of Q </li></ul><ul><li>A nondeterministic finite automaton is a 5-tuple ( Q,  ,  , q 0 , F), where </li></ul><ul><ul><li>Q : a finite set of states </li></ul></ul><ul><ul><li> : a finite set of alphabet </li></ul></ul><ul><ul><li> : Qx    P (Q) transition function </li></ul></ul><ul><ul><li>q 0  Q : start state </li></ul></ul><ul><ul><li>F  Q : the set of accept states </li></ul></ul>
28. 28. <ul><li>eg. </li></ul><ul><ul><li>Q = {q 1 , q 2 , q 3 , q 4 } </li></ul></ul><ul><ul><li> = {0, 1} </li></ul></ul><ul><ul><li> : 0 1  q 1 {q 1 } {q 1 , q 2 }  q 2 {q 3 }  {q 3 } q 3  {q 4 }  q 4 {q 4 } {q 4 }  </li></ul></ul><ul><ul><li>q 1 : start state </li></ul></ul><ul><ul><li>q 4 : accept state </li></ul></ul>
29. 29. <ul><li>N=(Q,  ,  , q 0 , F ) ~NFA w : string over  , w= y 1 y 2 y 3 … y m , y i   r 0 ,r 1 ,r 2 ,…,r m  Q </li></ul><ul><li>N accepts w if exists r 0 ,r 1 ,r 2 ,…,r m such that </li></ul><ul><ul><li>r 0 =q 0 </li></ul></ul><ul><ul><li>r i+1   (r i , y i+1 ), for i =0,…m-1 </li></ul></ul><ul><ul><li>r m  F </li></ul></ul>
30. 30. Equivalence of NFA and DFA <ul><li>Theorem : Every nondeterministic finite automaton has an equivalent deterministic finite automaton </li></ul><ul><li>Pf: Let N=(Q,  ,  , q 0 , F) be the NFA recognizing A. </li></ul><ul><li>Goal: Construct a DFA recognizing A </li></ul><ul><li>1. First we don’t consider  . </li></ul><ul><li> Construct M= ( Q’,  ,  ’, q 0 ’, F’) </li></ul><ul><li> 1. Q’= P (Q) </li></ul><ul><li> 2. For R  Q’ and a  let </li></ul><ul><li> 3. q 0 ’= {q 0 } </li></ul><ul><li> 4. F’ = {R  Q’ | R contains an accept state of N} </li></ul>
31. 31. Equivalence of NFA and DFA <ul><li>2. Consider  : </li></ul><ul><li> For any R  M, define E(R)={q | q can be reached from R by traveling along 0 or more  } </li></ul><ul><li> Replace  (r,a) by E(  (r,a)) </li></ul><ul><li> Thus,  ’(R, a)={q  Q : q  E(  (r,a)) for some r  R} </li></ul><ul><li> Change q 0 ’ to be E({q 0 }) </li></ul>
32. 32. <ul><li>Corollary: A language is regular if and only if some NFA recognizes it eq. D’s state : </li></ul><ul><li>{  , {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}} </li></ul><ul><li>N 4 = ({1,2,3}, {a,b},  , 1, {1}) </li></ul>
33. 33. <ul><li>Construct a DFA D equivalent to N 4 </li></ul>
34. 34. <ul><li>eg. Convert the following NFA to an equivalent DFA </li></ul><ul><li>E({q 0 }) = {q 0 } </li></ul><ul><li>E(  ({q 0 },a)) = {q 1 ,q 2 } </li></ul><ul><li>E(  ({q 0 },b)) =  </li></ul><ul><li>E(  ({q 1 ,q 2 },a) = {q 1 ,q 2 } </li></ul><ul><li>E(  ({q 1 ,q 2 },b) = {q 0 } </li></ul>
35. 35. Closure under the regular operations <ul><li>Theorem : The class of regular language is closed under the union operation </li></ul><ul><li>Pf: A 1 : N 1 : A 2 : N 2 : </li></ul><ul><ul><li>N 1 =(Q 1 ,  ,  1 , q 1 , F 1 ) for A 1 </li></ul></ul><ul><ul><li>N 2 =(Q 2 ,  ,  2 , q 2 , F 2 ) for A 2 </li></ul></ul>A1  A2
36. 36. <ul><li>Construct N=(Q,  ,  , q 0 , F) to recognize A1  A2 </li></ul><ul><ul><li>Q : {q 0 }  Q 1  Q 2 </li></ul></ul><ul><ul><li>q 0 : start state </li></ul></ul><ul><ul><li>F : F 1  F 2 </li></ul></ul><ul><ul><li>For q  Q and a    (q, a)=  1 (q, a), q  Q 1  2 (q, a), q  Q 2 {q 1 , q 2 }, q=q 0 and a=   , q=q 0 and a  </li></ul></ul>
37. 37. <ul><li>Theorem : The class of regular language is closed under the concatenation operation </li></ul><ul><li>Pf: N 1 : N 2 : </li></ul><ul><ul><li>N 1 =(Q 1 ,  ,  1 , q 1 , F 1 ) recognize A 1 </li></ul></ul><ul><ul><li>N 2 =(Q 2 ,  ,  2 , q 2 , F 2 ) recognize A 2 </li></ul></ul>A1 。 A2
38. 38. <ul><li>Construct N=(Q,  ,  , q 1 , F 2 ) to recognize A1 。 A2 </li></ul><ul><ul><li>Q : Q 1  Q 2 </li></ul></ul><ul><ul><li>q 1 : start state </li></ul></ul><ul><ul><li>F 2 : accept state </li></ul></ul><ul><ul><li> (q, a) =  1 (q, a), q  Q 1 and q  F 1  1 (q, a), q  F 1 and a   1 (q, a)  {q 2 }, q  F 1 and a=   2 (q, a), q  Q 2 </li></ul></ul>q  Q, a 
39. 39. <ul><li>Theorem : The class of regular language is closed under the star operation </li></ul><ul><li>Pf: A: A*: </li></ul><ul><ul><li>N 1 =(Q 1 ,  ,  1 , q 1 , F 1 ) recognize A </li></ul></ul>A = {a, b} A* = {  , a, b, …}  , A A 。 A = {aa, ab, ba, bb} A 。 A 。 A …
40. 40. <ul><li>Construct N=(Q,  ,  , q 0 , F) to recognize A* </li></ul><ul><ul><li>Q : { q 0 }  Q </li></ul></ul><ul><ul><li>q 0 : start state </li></ul></ul><ul><ul><li>F : { q 0 }  F </li></ul></ul><ul><ul><li> (q, a) =  1 (q, a), q  Q 1 and q  F 1  1 (q, a), q  F 1 and a   1 (q, a)  {q 1 }, q  F 1 and a=  {q 1 }, q=q 0 and a=   q=q 0 and a  </li></ul></ul>
41. 41. Regular Expressions <ul><li>AWK, GREP in UNIX PERL, text editors. </li></ul><ul><li>eg. (0  1)0* = ({0}  {1}) 。 {0}* </li></ul><ul><li>eg. (0  1)* = {0, 1}* </li></ul>
42. 42. Formal definition of a regular expression <ul><li>Definition: R is a regular expression if R is </li></ul><ul><ul><li>a   </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li>(R 1  R 2 ), R 1 and R 2 are regular </li></ul></ul><ul><ul><li>(R 1 。 R 2 ), R 1 and R 2 are regular </li></ul></ul><ul><ul><li>(R 1 * ), R 1 is regular expression </li></ul></ul>Inductive definition
43. 43. <ul><li>eg.  = {0, 1} </li></ul><ul><ul><li>0*10* = { w : w has exactly a single 1} </li></ul></ul><ul><ul><li> *1  * </li></ul></ul><ul><ul><li> *001  * </li></ul></ul><ul><ul><li>(  )* </li></ul></ul><ul><ul><li>01  10 </li></ul></ul><ul><ul><li>0  *0  1  *1  0  1 </li></ul></ul><ul><ul><li>(0  )1*=01*  1* </li></ul></ul><ul><ul><li>(0  )(1  ) = {  , 0, 1, 01} </li></ul></ul><ul><ul><li>1*  =  </li></ul></ul><ul><ul><li> * = {  } </li></ul></ul>
44. 44. <ul><li>eg. R : regular expression R  = R R 。  = R </li></ul><ul><li>R   ?=R R 。  ?= R R = {0} R 。  =  </li></ul>
45. 45. Equivalence with finite automata <ul><li>Theorem: A language is regular if and only if some regular expression describes it </li></ul><ul><li>Lemma: (  ) If a language is described by a regular expression then it is regular </li></ul>
46. 46. <ul><li>Pf: Let R be a regular expression describing some language A Goal: Convert R into an NFA N. </li></ul><ul><ul><li>R=a   , L(R)={a} </li></ul></ul><ul><ul><li>R=  , L(R)={  } </li></ul></ul><ul><ul><li>R=  , L(R)=  </li></ul></ul><ul><ul><li>R = R 1  R 2 </li></ul></ul><ul><ul><li>R = R 1 。 R 2 </li></ul></ul><ul><ul><li>R = R 1 * </li></ul></ul>
47. 47. <ul><li>eg. (ab  a)* </li></ul><ul><ul><li>a </li></ul></ul><ul><ul><li>b </li></ul></ul><ul><ul><li>ab </li></ul></ul><ul><ul><li>ab  a </li></ul></ul><ul><ul><li>(ab  a)* </li></ul></ul>
48. 48. <ul><li>eg. (a  b)*aba </li></ul><ul><ul><li>a </li></ul></ul><ul><ul><li>b </li></ul></ul><ul><ul><li>a  b </li></ul></ul><ul><ul><li>(a  b)* </li></ul></ul><ul><ul><li>aba </li></ul></ul>
49. 49. <ul><ul><li>(a  b)*aba </li></ul></ul>
50. 50. Generalized nondeterministic finite automaton (GNFA) <ul><li>( Q,  ,  , q start , q accept )  : (Q - {q accept }) x (Q - {q start })  R </li></ul>Set of all regular expressions over   (q i , q j ) = R
51. 51. <ul><li>Lemma: (  ) If a language is regular, then it is described by a regular expression </li></ul><ul><li>Pf: a language A is regular  There is a DFA M accepting A </li></ul><ul><ul><li>Goal: Convert DFAs into equivalent regular expressions </li></ul></ul>
52. 52. <ul><ul><li>A GNFA accepts a string w in  * if w = w 1 w 2 …w k , where each w i is in  * and a sequence of states q 0 q 1 q 2 …q k exists s.t. </li></ul></ul><ul><ul><ul><li>q 0 = q start is the start state </li></ul></ul></ul><ul><ul><ul><li>q k = q accept is the accept state </li></ul></ul></ul><ul><ul><ul><li>for each i , we have w i  L(R i ), where R i =  (q i-1 , q i ) </li></ul></ul></ul><ul><ul><li>DFA M --------------------  GNFA G </li></ul></ul><ul><ul><li>Convert (G) : takes a GNFA and return an equivalent regular expression </li></ul></ul>start state adding accept state transition arrows
53. 53. Convert(G) <ul><li>Convert(G) </li></ul><ul><ul><li>Let k be the number of states of G </li></ul></ul><ul><ul><li>If k=2, return R </li></ul></ul><ul><ul><li>If k>2, select any q rip  Q (  q start ,q accept ), Let G’ = GNFA(Q’,  ,  ’, q start , q accept ), where Q’=Q-{q rip } , and for any q i  Q’-{q accept } and any q j  Q’-{q start }, let  ’(q i , q j ) = (R 1 )(R 2 )*(R 3 )  (R 4 ) </li></ul></ul><ul><ul><li>Compute CONVERT(G’) and return this value </li></ul></ul>
54. 54. <ul><li>Claim: For any GNFA G, CONVERT(G) is equivalent to G. </li></ul><ul><li>Pf: By induction on k, the number of states of the GNFA </li></ul><ul><ul><li>Basis: It is clear for k=2 </li></ul></ul>
55. 55. Induction step <ul><li>Assume that the claim is true for k-1 states </li></ul><ul><ul><li>Suppose G accepts an input w , Then in an accepting branch of the computation G enters a sequence of states: q start , q 1 , q 2 , …, q accept </li></ul></ul><ul><ul><ul><li>If none of them is q rip , G’ accepts w . </li></ul></ul></ul><ul><ul><ul><li>If q rip does appear in the above states, removing each run of consecutive q rip states forms an accepting computation for G’ </li></ul></ul></ul><ul><ul><li>Suppose G’ accepts an input w G’: G: or </li></ul></ul><ul><ul><li>⇒ G accepts w </li></ul></ul><ul><ul><li>G ≅ G’, by induction hypothesis, the claim is true </li></ul></ul>
56. 56. example <ul><li>eg: </li></ul>
57. 57. example
58. 58. Pumping lemma for regular languages <ul><li>Is {0 n 1 n : n ≥ 0} regular? How can we prove a language non-regular? </li></ul><ul><li>Theorem: (Pumping Lemma) If A is a regular language, then there is a number P (the pumping length) where, if s is any string in A of length ≥ P , then s may be divided into 3 pieces, s = x yz , satisfying the following conditions: </li></ul><ul><ul><li>for each i ≥ 0, x y i z ∈ A </li></ul></ul><ul><ul><li>| y | > 0 </li></ul></ul><ul><ul><li>| x y | ≤ P </li></ul></ul>
59. 59. <ul><li>proof </li></ul><ul><ul><li>M=(Q, Σ , δ ,q 1 , F) : a DFA recognizing A </li></ul></ul><ul><ul><li>P =|Q|: number of state of M </li></ul></ul><ul><ul><li>s = s 1 s 2 … s n ∈ A, n ≥ P </li></ul></ul><ul><ul><li>r 1 , r 2 , …, r n+1 : the seq. of states M enters while processing </li></ul></ul><ul><ul><li>r i+1 = δ (r i , s i ) for 1 ≤ i ≤ n. By pigeonhole principle , there must be 2 identical states, say r j =r l , x = s 1 … s j-1 , y = s j …s l-1 , z = s l …s n </li></ul></ul><ul><ul><li>x takes M from r 1 to r j , y takes M from r j to r j , and z takes M from r j to r n+1 M must accept x y i z for i ≥ 0 ∵ j ≠ l , | y |=| s j …s l-1 |>0, l ≤ P +1, so | x y | ≤ P </li></ul></ul>
60. 60. <ul><li>B={0 n 1 n : n ≥0 } is not regular </li></ul><ul><li>proof: </li></ul><ul><ul><li>Suppose B is regular </li></ul></ul><ul><ul><li>Let P be the pumping length </li></ul></ul><ul><ul><li>Choose s = 0 P 1 P = 0…01…1 ∈ B </li></ul></ul><ul><ul><li>Let s = x yz , By pumping lemma, for any i ≥0 x y i z ∈ B. But </li></ul></ul><ul><ul><ul><li>0…001…1 : y has 0 only ⇒ ->← </li></ul></ul></ul><ul><ul><ul><li>0…01…1 : y has 1 only ⇒ ->← </li></ul></ul></ul><ul><ul><ul><li>0…01…1 : y has both 0 and 1 ⇒ x yyz ∉ B </li></ul></ul></ul>
61. 61. <ul><li>C={ w | w has an equal number of 0s and 1s} is not regular </li></ul><ul><li>proof: (By pumping lemma) </li></ul><ul><ul><li>Let P be the pumping length, Suppose C is regualr </li></ul></ul><ul><ul><li>Let s = 0 P 1 P ∈ C, By pumping lemma, s can be split into 3 pieces, s = x yz , and x y i z ∈ C for any i ≥0 </li></ul></ul><ul><ul><li>By condition 3 in the lemma: | x y | ≤ P Thus y must have only 0s. Then x yyz ∉ C </li></ul></ul>
62. 62. <ul><li>proof: (Not by pumping lemma) </li></ul><ul><ul><li>Suppose C is regular </li></ul></ul><ul><ul><li>It is clear that 0*1* is regualr </li></ul></ul><ul><ul><li>Then C ∩ 0*1*={0 n 1 n : n ≥0 } is regular ->← </li></ul></ul>
63. 63. <ul><li>F={ ww | w ∈{0,1}* } is nonregular </li></ul><ul><li>proof: </li></ul><ul><ul><li>Suppose F is regular </li></ul></ul><ul><ul><li>Let P be the pumping length given by the pumping lemma </li></ul></ul><ul><ul><li>Let s = 0 P 10 P 1 ∈ F </li></ul></ul><ul><ul><li>Split s into 3 pieces, s = x yz </li></ul></ul><ul><ul><li>By condition 3 in the lemma: | x y | ≤ P Thus y must have 0 only. ⇒ x yyz ∉ F 0…010…01 ->← </li></ul></ul>w y
64. 64. <ul><li>E={0 i 1 j : i > j } is nonregular </li></ul><ul><li>proof: </li></ul><ul><ul><li>Assume E is regular </li></ul></ul><ul><ul><li>Let P be the pumping length </li></ul></ul><ul><ul><li>Let s = 0 P+1 1 P ∈ E </li></ul></ul><ul><ul><li>Split s into 3 pieces, s = x yz </li></ul></ul><ul><ul><li>By pumping lemma: x y i z ∈ E for any i ≥ 0 | y |>0, y have 0 only. x z ∈ E. But x z has #(0) ≤ #(1) </li></ul></ul>
65. 65. <ul><li>D={1 n 2 : n ≥ 0 } is not regular </li></ul><ul><li>proof: </li></ul><ul><ul><li>Assume D is regular </li></ul></ul><ul><ul><li>Let P be the pumping length </li></ul></ul><ul><ul><li>Let s = 1 P 2 ∈ D </li></ul></ul><ul><ul><li>Split s into 3 pieces, s = x yz ⇒ x y i z ∈ D, i ≥ 0 </li></ul></ul><ul><ul><li>Consider x y i z ∈ D and x y i+1 z ∈ D ⇒ | x y i z | and | x y i+1 z | are perfect squre for any i ≥ 0 </li></ul></ul><ul><ul><li>If m=n 2 , (n+1) 2 - n 2 =2n+1 = 2 +1 </li></ul></ul>
66. 66. <ul><ul><li>Let m =| x y i z | </li></ul></ul><ul><ul><li>| y | ≤ | s |= P 2 </li></ul></ul><ul><ul><li>Let i = P 4 | y |= | x y i+1 z |-| x y i z | ≤ P 2 = ( P 4 ) 1/2 </li></ul></ul><ul><ul><li> < 2( P 4 ) 1/2 +1 </li></ul></ul><ul><ul><li> ≤ 2(| x y i z |) 1/2 +1 </li></ul></ul><ul><ul><li> = 2 +1 </li></ul></ul><ul><ul><li>-> ← </li></ul></ul>