1 / 14

CS355 - Theory of Computation

CS355 - Theory of Computation. Regular Expressions. Regular Expressions. In maths one can use operations + and × to build up expressions like: (12 + 5) × 2 (= 34) Similarly, can build regular operations to build expressions describing languages. An example is: (0 1)1* = a language!!

branhamd
Download Presentation

CS355 - Theory of Computation

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. CS355 - Theory of Computation Regular Expressions

  2. Regular Expressions • In maths one can use operations + and × to build up expressions like: (12 + 5) × 2 (= 34) • Similarly, can build regular operations to build expressions describing languages. • An example is: (0 1)1* = a language!! • In this case it is the language consisting of all strings starting with a 0 or 1 followed by zero or more 1’s (1 *). Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  3. Regular Expressions • We let R+ represent RR* • In other words, R+ has all strings that are one or more concatenation of strings from R i.e. RR* • (01+)* = {w | every 0 in w is followed by at least one 1} Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  4. Regular Expressions • Which of these are value languages for the regular expression: (00)*1(0 1)*? • 0, 1, 010, 0010, 000011, 0011010, 0000101010 • 0 No - must be at least one 1 • 1 Yes • 010 No – must be two 0’s • 0010 Yes • 000011 Yes • 0011010 Yes • 0000101010 Yes Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  5. Regular Expressions • In regular expression shorthand is used and concatenation symbol ( )is not used • (0 1)0* is shorthand for (0 1) 0* • The precedence order in regular expressions is: star operation, concatenation and then union, unless parentheses are used to change the order. Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  6. Regular Expressions • The expression (0 1)* is the language consisting of all possible strings of 0’s and 1’s. • If the alphabet Σ = {0,1}, we can write Σ as shorthand for (0 1) . • If Σ is any alphabet, the regular expression Σ describes the language of all strings of length 1. • Σ* is the language of all strings over the alphabet. • Σ*0 is the language that contains all strings ending in a 0. • The language (0Σ*) (Σ*1) consists of all strings that either start with a 0 or end with a 1. Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  7. Regular Expression • A language is regular if some regular expression describes it. Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  8. Nonregular Languages • Finite automaton are powerful machines but they do have limitations. • There are some languages that can not be recognised by any finite automaton. • At first glance some languages may seem regular but are in fact nonregular and vice versa!!! Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  9. Pumping Lemma • Pumping Lemma is a technique used to show that if a language does not have a special property then it is not regular. • The property states that all strings in the language can be “pumped” and still belong to that class • A language can be pumped if any sufficiently long string, having length at least the pumping length, in the language can be broken into pieces that can be repeated to produce an even longer string in the language. Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  10. Pumping Lemma • Thus, if there is a pumping lemma for a given language class, any language in the class will contain an infinite set of finite strings all produced by a simple rule given by the lemma. Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  11. Pumping Lemma - Theorem • 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 at least p, then s may be divided into three pieces, s = xyz, satisfying the following conditions: • For each i≥ 0, xyiz A, • |y| > 0, and • |xy| ≤ p. • x or z may be ε, but condition 2 does not allow y to be ε. Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  12. Pumping Lemma to prove a language is not regular • Assume language B is regular in order to obtain a contradiction. • Use pumping lemma to guarantee existence of a pumping length p such that all strings of length p or greater in B can be pumped. • Find a string in B that has length p or greater but that cannot be pumped. • Finally, demonstrate that s cant be pumped by considering all ways of dividing s into x, y and z and for each such division, finding a value i where xyiz B. • Let us look at examples of this. Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  13. Limitations of the Pumping Lemma • The Pumping Lemma can be used to prove that a language is not regular, however, it can’t be used to prove that a language is regular. • Just because you can’t think up the right string does not mean that someone else cant. Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

  14. Examples • Examples. • Think about: • Is L = {0ix | i ≥ 0, x {0,1}* and |x| ≤ i} regular? • Is L = {0i | i is prime} regular? Dr. A. Mooney, Dept. of Computer Science, NUI Maynooth

More Related