Chapter 4 Properties of Regular Languages

Slides:



Advertisements
Similar presentations
Properties of Regular Languages
Advertisements

Lecture 9,10 Theory of AUTOMATA
Fall 2006Costas Busch - RPI1 Non-regular languages (Pumping Lemma)
1 More Properties of Regular Languages. 2 We have proven Regular languages are closed under: Union Concatenation Star operation Reverse.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Costas Busch - RPI1 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
Courtesy Costas Busch - RPI1 Non-regular languages.
Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
Prof. Busch - LSU1 Non-regular languages (Pumping Lemma)
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
Chapter 4 Pumping Lemma Properties of Regular Languages Decidable questions on Regular Languages.
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
Class Discussion Can you draw a DFA that accepts the language {a k b k | k = 0,1,2,…} over the alphabet  ={a,b}?
Chapter 6 Properties of Regular Languages. 2 Regular Sets and Languages  Claim(1). The family of languages accepted by FSAs consists of precisely the.
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
CS 203: Introduction to Formal Languages and Automata
Regular Languages ภาษาปกติ. Jaruloj Chongstitvatana Outline Regular expressions Regular languages Equivalence between languages accepted by.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Equivalence with FA * Any Regex can be converted to FA and vice versa, because: * Regex and FA are equivalent in their descriptive power ** Regular language.
MA/CSSE 474 Theory of Computation How many regular/non-regular languages are there? Closure properties of Regular Languages (if there is time) Pumping.
1 Use the pumping theorem for context-free languages to prove that L= { a n b a n b a p : n, p ≥ 0, p ≥ n } is not context-free. Hint: For the pumping.
CSE 105 theory of computation
Pumping Lemma.
Foundations of Computing Science
Non-regular languages
Standard Representations of Regular Languages
CSE322 PUMPING LEMMA FOR REGULAR SETS AND ITS APPLICATIONS
CSE 105 theory of computation
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
PROPERTIES OF REGULAR LANGUAGES
FORMAL LANGUAGES AND AUTOMATA THEORY
CSE 105 theory of computation
CSE 3813 Introduction to Formal Languages and Automata
PDAs Accept Context-Free Languages
CSE 105 theory of computation
Nonregular Languages Section 2.4 Wed, Oct 5, 2005.
CSE 105 theory of computation
Properties of Regular Languages
Regular Expression We shall build expressions from the symbols using simple operations include concatenation, union and kleen closure. Several intuitive.
CS 154, Lecture 3: DFANFA, Regular Expressions.
CSE 105 theory of computation
Deterministic PDAs - DPDAs
Properties of Regular Languages
Elementary Questions about Regular Languages
Non-regular languages
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Pumping Lemma.
CS21 Decidability and Tractability
Non-Regular Languages
Regular Languages ภาษาปกติ.
CS21 Decidability and Tractability
Instructor: Aaron Roth
CSE 105 theory of computation
Chapter 1 Regular Language
Recap lecture 25 Intersection of two regular languages is regular, examples, non regular languages, example.
CSE 105 theory of computation
CSE 105 theory of computation
CHAPTER 1 Regular Languages
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

Chapter 4 Properties of Regular Languages

4.1: Closure Properties of RLs (1) A language L over an alphabet S is regular if it has a regular set (expression) over S is accepted y DFA, NFA, or NFA-e is generated by regular grammar

4.1: Closure Properties of RLs (2)

4.1: Closure Properties of RLs (3) If L1 and L2 are regular languages, then L1  L2 Union = {w * : w  L1 or w  L2} L1  L2 Intersection = {w * : w  L1 and w  L2} L1 L2 Concatenation n languages: L1L2 …Ln = {w1w2…wn : wi  Li} one languages: Ln = {w1w2…wn : wi  L} L* Kleene Star L*= L0  L1  L2  … L1 Complement L = * - L = {w : w * and w  L} are also regular languages

4.1: Closure Properties of RLs (4) Prove that RLs are closed under complementation. If L is a regular language over , then L = * - L is regular language. Proof: If L is regular, there exists a DFA M recognizing L. We can construct a DFA M’ for L by copying M to M’ except that all final states in M are changed to non-final, and all non-final states to final. See next slide for a formal proof

4.1: Closure Properties of RLs (5) Let M1=(Q, , , q0, F) a DFA that accepts L(M1) Let M2=(Q, , , q0, Q-F) a DFA that accepts L(M2) Obviously both languages are regular languages Per definition 2.2: L(M) = {w * : (q0, w)  F} The following are both true w * : (q0, w)  F  (q0, w)  Q – F w * : (q0, w)  Q - F  (q0, w)  F Thus L(M2) = L(M1) L(M1) is an arbitrary regular language and its complement is also a regular language, therefore the regular languages are closed under complementation

4.1: Closure Properties of RLs (6) Are regular languages closed under intersection? If L1 and L2 are RLs, then L1  L2 is RL. Proof: Since RLs are closed under union and complementation, they are also closed under intersection L1, L2 are RLs, so L1, L2 are RLs, and L1  L2 is RL, so L1  L2 is RL. Thus L1  L2 = L1  L2 is RL.

4.1: Closure Properties of RLs (7) Are regular languages closed under difference? If L1 and L2 are RLs, is L1 - L2 RL? Why? L1 - L2 = L1  L2 Since RLs are closed under intersection and complementation, they are also closed under difference.

4.1: Closure Properties of RLs (8) Let L, M and N are regular expressions, which of the followings are correct? Commutative Rules: L  M = M  L LM = ML Associative Rules: (L  M)  N = L  (M  N) (LM)N = L(MN)

4.1: Closure Properties of RLs (9) Which of the followings are correct? Left Distributive Rules: L(M  N) = LM  LN L  (MN) = (L  M)(L  N) Right Distributive Rules: (M  N)L = ML  NL (MN)  L = (M  L)(N  L)

4.1: Closure Properties of RLs (10) Identities:  is the identity for union:   L = L   = L  is the identity for concatenation: L = L = L

4.1: Closure Properties of RLs (11) Other Rules for Kleene Closure (L*)* = L* L+ = LL* = L*L L* = L+ |   * =  * = 

4.2: Elementary Questions about RLs Membership question: If L is a RL over , then for any string w  * there exists an algorithm for determining whether or not w is in L. DFA Empty, finite, or infinite question: There exists an algorithm for determining whether a RL is empty, finite, or infinite. DFA (path from start to final, cycle) Equality question: If L1 and L2 are RLs, then there exists an algorithm to determine whether or not L1 = L2. L3 = (L1  L2)  (L1  L2) =  iff L1 = L2

4.3: Non-regular Languages (1) The language L = {an bn | n  0} is not regular There is NO DFA/NFA that accepts L Theorem: If L1 is RL and L2 is not-regular, then The language L = L1  L2 is not necessarily regular Proof: L1 = a*b* is regular L2 = {an bn | n  0} is not regular L1  L2 = L2 which is not regular

4.3: Non-regular Languages (2) The language L = {an bm | n, m  0 and n  m} is not regular. Proof: L is regular iff L  a*b* is regular. But L  a*b* = {an bn | n  0}, which we know is not regular. Then L is not regular.

4.3: Non-regular Languages (3) Many languages are non-regular: {anbn | n  0} {wwR} | w  * } {an2 | n  0} {ap | p is prime} set of well-formed parentheses set of palindromes: {w = wR} …...

4.3: Non-regular Languages (4) We want to prove that L = {akbk | k  0} is non-regular. Prove by contradiction: Assume that there is a DFA M which recognizes L. Let n be the no. of states in M Consider the acceptance of the input arbr where r  n: q0 a a a a b b b q1 q2 qr qr+1 …... q2r …... ar br path for accepting arbr

4.3: Non-regular Languages (5) Since r  n and M has only n states, there must be at least one state visited twice in the first r transitions. Let this state be visited at the ith and the jth steps, where j  i. By skipping the loop, ar-(j-i)br should also be accepted by M, but this is contradictory since ar-(j-i)br  L qi = qj qf  F a path in M q0

4.3: Non-regular Languages (6) We want to prove that L = {ak2 | k  0} is non-regular. Prove by contradiction: Assume that there is a DFA M which recognizes L. Let n be the no. of states in M M should also accept the string an2 q0 a a a a q1 q2 qn2 …... path for accepting an2

4.3: Non-regular Languages (7) Since n2  n and M has only n states, there must be at least two equal states from q0 to qn2. Let them be qi and qj where j - i = m  n. By repeating the loop one more time, a(n2+m) is also accepted by M, which is a contradiction, since (n2+m) cannot be a square (the next square after n2 is (n+1)2 but n2+m  (n+1)2) q0 qi = qj qn2  F a path in M A loop of length m

4.3: Non-regular Languages (8) We want to prove that L = {ap | p is a prime} is non-regular. Prove by contradiction: Assume that there is a DFA M which recognizes L. Let n be the no. of states in M From Number Theory, we know that the no. of primes are infinite, so there exists a prime p  n q0 a a a a q1 q2 qp …... path for accepting ap

4.3: Non-regular Languages (9) Since p  n and M has only n states, there must be at least two equal states from q0 to qp. Let them be qi and qj where j - i = m  0 By repeating the loop (p-m) times, a(p-m)m + (p-m) = a(p-m)(m+1) is also accepted by M, which is a contradiction since (p-m)(m+1) is not a prime, since it can be divided by (p-m) and (m+1)  1 q0 qi = qj qp  F a path in M A loop of length m

4.3: Pumping Lemma (1) If L is a regular language, there is a DFA which recognizes L. All finite languages are regular , {a}, {abaabb, b, baabbbbb, bb} So, only infinite languages are interesting for this discussion. What are non-regular languages? Pumping Lemma A technique for proving a language L is NOT regular

4.3: Pumping Lemma (2) Any given DFA has a finite number of states Let k = |Q| Consider any accepted input w = a1…an, such that |w| = n  k DFA follows a path of states q0…qn: This state numbering has nothing to do with state names in Q May repeat states in this path q0 a1 q1 … qn-1 qn a2 an an-1

4.3: Pumping Lemma (3) Since |w|  k, path must contain at least one loop Consider any one such loop (cycle) Break string & path into three parts: before, during, & after loop Given other inputs, could loop an arbitrary number of times (a1…ai)(ai+1…aj)*(aj+1…an) also accepted q0 a1 qi=qj … qn ai an ai+1 aj+1 aj

4.3: Pumping Lemma (4) If language L is regular, then for any w  L that is longer than |Q|, there is a substring of w that can be repeated (pumped) any number of times with resulting string remaining in the language Lemma: Let G be the state diagram of a DFA with k states. Any path of length k in G contains a cycle. Proof: A path of length k contains k+1 nodes. Since there are only k nodes (states) in G, there must be a node, call it qi, that occurs in at least two positions in the path. The subpath from the first occurrence of qi to the second produces the desired cycle.

4.3: Pumping Lemma (5) Let G be the state diagram of a DFA with k states and let p be a path of length  k. The path p can be subdivided into subpaths u, v, and z where p = uvz The length of uv is |uv|  k, and v is a cycle

4.3: Pumping Lemma (6) Pumping Lemma Let L be a regular language is accepted by a DFA M with k states. Let for ALL w  L and |w|  k. Then w can be divided into three parts, w = uvz, satisfying the following conditions: |uv|  k, |v|  1, and for all i  0, uviz  L

4.3: Pumping Lemma (7) Proof: Let w  L with |w| = n  k where w(i) is the ith symbol of the string w. Since n  k and M has only k states, there must be at least one repeated state from q0 to qn Let qi be the first such repeated state q0 q1 q2 qn w(2) w(3) …... w(1) w(n) q0 qi qn  F a path in M

4.3: Pumping Lemma (8) Let u be the string obtained by traversing from q0 to qi, v be the string obtained by traversing the loop once (so |v|  1) In the traversal from q0 to qi and then through the loop once back to qi, nothing except qi repeats, thus |uv|  k By traversing the loop 0 or more times, we obtain uviz for all i  0 and they should all be accepted by the DFA, i.e., in L. q0 qi qn  F a path in M

4.3: Pumping Lemma (9) How to use pumping lemma to prove some L isn’t regular? Lemma describes a property of regular languages. Use proof by contradiction: If L doesn't have this property, it is NOT regular We cannot use the pumping lemma to prove a language is regular Since we have to check every string in L

4.3: Pumping Lemma (10) We assume the given language L is regular Let n be the constant of pumping lemma Find a string w  L where |w|  n Divide w into 3 parts, w = uvz, where |uv|  n |v|  1 Claim that uviz are also in L for all i Find one i such that uviz  L Contradiction Only one string w is needed do not need to consider all general cases choose w that can led to contradiction easily

4.3: Pumping Lemma (11) Example 1: L = {am bm | m  0} Assume L is regular, n is the # of DFA states Let w = anbn where |w| = 2n  n w = ap aj an-p-j bn where p + j  n and j  1 w = u v z u & v contain only a’s, since |uv|  n Pick i = 2: uv2z = ap aj aj an-p-j bn = an aj bn uv2z contains more a’s than b’s, since |v|  1 uv2z  L Contradiction and hence L is not regular

4.3: Pumping Lemma (12) Example 2: L = {w | w  {a, b}*, w has equal number of a’s and b’s} w = an bn Same argument as previous example Choice of w is important Different w’s may lead to different proofs, or none being possible Choice of i is important. Different i’s may lead to different proofs, or none being possible

4.3: Pumping Lemma (13) Example 3: L = {(ab)i | i  0} L is regular: L = (ab)* i.e., for any w, there is some split u, v, z that allows pumping

4.3: Pumping Lemma (14) Example 4: Prove that the language L of well-formed parentheses is non-regular Assume L is regular and let n be the constant of pumping lemma Let w = (n)n  L, |w| = 2n  n we do not need to consider other possible cases like ()() we only need to ensure |w|  n Then w = (m (j (n-m-j )n where j  1 and m + j  n u v z

4.3: Pumping Lemma (15) By pumping lemma, (m(ji(n-m-j )n = (n+j(i-1) )n  L for all i When i = 0  (n-j )n  L since j  1  n-j  n Contradiction  L is not regular We can choose i = 2, i = 3, ... but cannot choose i = 1

4.3: Pumping Lemma (16) To prove L is regular 1. Constructing a FSA (NFA or DFA), RE, or RG for L 2. Using closure property of regular sets Let ⊕ be a binary operation (such as union, concatenation and intersection) L3 = L1 ⊕ L2 is regular, if both L1 and L2 are regular Let ⊡ be an unary operation (such as complementation and Kleene star) L1 = ⊡ L2 is regular, if L2 is regular

4.3: Pumping Lemma (17) Example Prove that L is regular, where L is the set of all strings with three consecutive 0's and  = {0,1} Let L1 = (0 | 1)*, which is regular and L2 = 000, which is also regular then L = L1.L2.L1 Hence L is regular due to the closure property of regular sets under concatenation.

4.3: Pumping Lemma (18) Prove L is not regular 1. Using Pumping Lemma 2. Using closure property of regular sets Let ⊕ be a binary operation (such as union, concatenation and intersection) if L3 = L1 ⊕ L2 and L1 is regular and L3 is not regular, then L2 must be non-regular Let ⊡ be an unary operation (such as complementation and Kleene star) if L1 = ⊡ L2 and L2 is not regular, then L1 is non-regular

4.3: Pumping Lemma (19) L = {w  {a, b}*, w has equal number of a’s and b’s} Consider L’ = L  a*b* = {an bn | n  0} By closure properties of RLs: if L is regular, then L’ is also regular But since L’ not regular, so L can’t be regular

4.3: Pumping Lemma (20) Example Prove that L is not regular, where L is the set of all strings over {a, b} such that the number of b is the double of the number of a. Let L1 = (anb2n) , which is non-regular, and L2 = a*b*, which is regular then L1 = L  L2 By closure properties of RLs: if L is regular, then L1 is also regular But since L1 not regular, so L can’t be regular

4.3: Pumping Lemma (21) Common Mistakes Let L1 regular language, L3 and L4 are not regular. Is L regular? L = L1 ⊕ L3 0n1n = 0*1*  0n1n 0*1* = 0*1*  0n1n L = L3 ⊕ L4 0*1* = 0p1q  0q1p , where p  q L3 = L ⊕ L4

Class Discussion Prove that L = {ww : w  (0|1)*} is non-regular Is L = {(01)6n : n  0} regular? Is L = {(ab)n : n  0} regular?

Summary We use the Pumping Lemma to prove a language is not regular Note, does not work for all non-regular languages, though Choosing a good string w is first key step Choosing a good integer i is second key step Must apply argument to all legal u, v, z