1 / 18

CS 448 Foundation of Computing

CS 448 Foundation of Computing. Soundararajan Ezekiel Department of Computer Science Ohio Northern University ADA, Ohio 45810 e-mail: s-ezekiel@onu.edu http://www.onu.edu/user/FS/sezekiel. Chapter 10. Non-Regular Language. In this chapter we will see some languages that are not regular.

laurie
Download Presentation

CS 448 Foundation of Computing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 448 Foundation of Computing Soundararajan Ezekiel Department of Computer Science Ohio Northern University ADA, Ohio 45810 e-mail: s-ezekiel@onu.edu http://www.onu.edu/user/FS/sezekiel

  2. Chapter 10. Non-Regular Language • In this chapter we will see some languages that are not regular. • We say a language is non-regular if it cannot be defined by a regular expression. • With Kleene's Theorem behind us, we know that a nonregular language cannot be accepted by any finite automaton or transition graph either.

  3. Example • Our first example of a non-regular language is the language • L={anbn | n  0} = {, ab, aabb, aaabbb, ...}. • Note that anbn | n  0 is not a regular expression. • Also notice that the language consists of strings in which all the a's come before the b's and the counts are the same

  4. Why is this language non-regular? • If we knew a maximum value for n, then we could build a machine to accept the language and that machine would contain a finite number of states. • Here is a machine that accepts {anbn | 0 n4}

  5. a a a -0 a 1 2 3 4      5 9 8 + 7 6 b b b b

  6. But there is only one way to count in a machine and that is by changing states. • Clearly, if there are cycles in a machine then we have no way to keep track of how many times we go around the cycle during the processing of a string. • If n is allowed to go arbitrarily high, then we cannot build a machine with a finite number of states that will accept only the strings in the language {anbn | n  0}

  7. Suppose someone claims that there is a finite state machine that accepts the language {anbn | n  0} and they draw us such a machine. • Consider a string in the language that contains more a's than there are states in the machine. Somewhere in the processing of the a's in the string, the machine must go around a cycle since there are more a's than states. • What's to keep the machine from accepting a string with the same number of b's as the original string, but enough additional a's to go around that cycle twice? Clearly, the machine would accept such a string. Thus the machine does not accept just the language {anbn | n  0} as claimed.

  8. Theorem 13 in our text is one version of a well-known theorem called the Pumping Lemma. • It describes a characteristic that every infinite regular language has. • Thus it can be used to prove that some specific infinite language is not regular by showing that the language cannot possibly have that characteristic. • Here is a different version of the Pumping Lemma that I like better.

  9. Theorem 13 • Statement:Let L be any regular language with infinitely many words and • let M be a DFA that accepts L. • Then any string in L that is longer than the number of states in M can be subdivided into three parts x, y, and z, where y is not empty, such that all strings of the form xynz for n  0 are in L.

  10. Proof • The machine M has a finite number of states. The language L is infinite so it has strings of every length in it. • Let w be a word in L with length greater than the number of states in M. The path through M for string w must contain a cycle. • We can break w into 3 parts: • x: letters that lead up to the first state in the cycle, i.e., the first state that is revisited during the processing of w. • Note that x may be  if the start state is the first state revisited.

  11. y: letters in one loop of the cycle • z: rest of the string • Strings xyyz, xyyyz, and so forth can all be accepted by M by taking more than one trip around the cycle. • String xz can also be accepted by not going around the cycle at all. Thus all these strings are in L.

  12. Example • We can pump up this middle part of the string, y, as much as we like. • Here is a finite automaton with 6 states. Any string of length 6 or more must revisit a state. • Consider the string bbbababa. • In the processing of this string state 2 is the first state revisited. So the part of the string called x is just the first letter b. We come back to state 2 after processing bba, so y is bba and z is the rest of the string, baba. By pumping we can get bbba bbababa, which is also in L. Note that spaces were included in the string just shown in order to better see the parts xyyz.

  13. Example • How can we use the Pumping Lemma to prove that {anbn | n  0} is non-regular? • If the language is regular then we should be able to take any string of sufficient length and break it into three parts like the Pumping Lemma says. • Consider where the part y might be. It would either be made of only a's, a mixture of a's and b's, or only b's. • If y is made of only a's or only b's and we duplicate y to pump up the string, then we will produce a string that is not of the proper composition. • The count of a's will no longer match the count of b's. So y must be made of both a's and b's.

  14. However, in that case if we duplicate y's we will produce a string in which all the a's do not come first, a string such as aaaa aabb aabb bbbb. • No matter how we subdivide the string into x, y, and z, we cannot pump up the string and get only valid longer strings. • Thus this language cannot be regular because the Pumping Lemma says that if the language is regular we will always be able to find a way to pump up a string.

  15. Example • We can use our knowledge of {anbn | n  0} to prove that the language • EQUAL = set of all strings that contain the same number of a's as b's (in any order) is not regular. • We can use the closure properties of regular languages to do this. • Note that EQUAL  a*b* ={anbn | n  0}

  16. We know that the set of regular languages is closed under intersection. • Therefore, if EQUAL is regular then {anbn | n  0}is regular. Since we just proved that {anbn | n  0}is not regular, we know that EQUAL is not regular. • Read the author's proofs that anban (p. 193) and anbnabn+1 (p. 194) are not regular.

More Related