Properties of Regular Languages Wen-Guey Tzeng Department of Computer Science National Chiao Tung University
Closure Properties Question: L is a regular language and op is an operator on strings. Is op(l) still a regular language? Example L={a n b : n 1} is regular. Is reverse(l) = L R = {ba n : n 1} regular? 2
General: L is regular. Assume an r.e., dfa, nfa, or linear grammar for L. Can you design an r.e., dfa, nfa, or linear grammar for op(l)? If the answer to the above is yes, we say that the regular languages are closed under operator op. 3
Over simple operations L 1 and L 2 are regular. So are comp(l 1 ), L 1 L 2, L 1 * Comp(L 1 ) L 1 L 2 L 1 * 4
Closure under right quotient Right quotient: L 1 /L 2 ={x : xy L 1 for some y L 2 } Example, L 1 ={a n b m : n 1, m 0} {ba} L 2 ={b m : m 1} L 1 /L 2 = {a n b m : n 1, m 0} 5
Regular languages are closed under right quotient. Let M 1 = (Q,,, q 0, F) for L 1. Idea: A string x in L 1 /L 2 : there is a string y in L 2 such that xy is in L 1. If such y exists, make state q as a final state. So, we check every q in Q to see whether it should be a final for L 1 /L 2 M 1 x q y 6
Example Find L 1 /L 2 for L 1 =L(a*baa*) and L 2 =L(ab*) L 1 /L 2 is r=a*ba* L 1 /L 2 : M=(Q,,, q 0, F ), where F ={q Q : exist y L 2, *(q, y) F} M 1 for L 1 M for L 1 /L 2 7
Closure under AND, OR, XOR L 1 is accepted by dfa M 1 and L 2 is accepted by dfa M 2. Find a dfa for L=L 1 L 2 ={w : w L 1, w L 2 } Method 1: Find dfa for L= comp(comp(l 1 ) comp(l 2 )) 8
Method 2: direct construction from M 1 =(Q 1,, 1, q 0, F 1 ) and M 2 =(Q 2,, 2, p 0, F 2 ) run M 1 and M 2 simultaneously M 2 M 1 a p 0 p 1 a b M 1 M 2 9
Question: Find a dfa for L 1 or L 2 L 1 xor L 2 10
Elementary questions Standard representation for regular languages Finite automata Regular expressions Regular grammars Membership question Given a regular language L (standard representation) and a string w, determine whether w L Emptiness Given a regular language L, determine whether L=? Finiteness, Equality, 11
For given dfa M, determine whether L(M)=? Minimize M as M? Determine whether M is a, b 12
For given dfa M 1 and M 2, determine whether L(M 1 )=L(M 2 )? Find a dfa M for L=L(M 1 ) xor L(M 2 ) Determine whether L(M)= 13
Identifying non-regular languages Prove that L is regular. Design an r.e., dfa, nfa, linear grammar Show the designed is indeed L. Prove that L is not regular By the pigeon hole principle By the Pumping Lemma By closure properties 14
Pigeonhole principle L is accepted by dfa M of m states. Type 1: For m+1 strings w 1, w 2,, w m+1, there are i, j, i j, * (q 0, w i ) = * (q 0, w j ) 15
L={a n b n : n 0} is not regular. Assume that M=(Q, {a,b},, q 0, F) accepts L and Q =m. Consider * (q 0, a), * (q 0, a 2 ),, * (q 0, a m+1 ), and there must be r and s, r s, * (q 0, a r )= q = * (q 0, a s ). But, consider reading b r further * (q 0, a r b r ) = * (q 0, a s b r ) = p. Is p in F? Contradiction!! Thus, L is not regular. q 0 a s a r q p Final or not? 16
Type 2: If a string w=a 1 a 2 a n, of length n m, is accepted by M, the accepting configuration must at least pass a state (q i =q j ) twice. a 1 a 2 a i a i+1 a j a j+1 a n q 0 q 1 q i q j q mn 17
18
Pumping Lemma If L is a regular language, there exists some positive integer m such that for any w L, w m, there exist x, y, z, such that w=xyz, xy m, y 1, so that for any i=0, 1, 2,, xy i z is also in L. 19
Use Pumping Lemma To prove that L is not regular 1. Assume L is regular and m is the constant for the pumping lemma. 2. Find a string w L, w m, consider all possible (x, y, z) with w=xyz xy m, y 1 For each possible (x, y, z), find one i, w i =x y i z L. 3. Conclusion: L is no regular. 20
Game view To prove that L is not regular YOU Pick m m w Find w L, w m Find x, y, z w=xyz xy m y 1 x, y, z You can win the game L is not regular Win, if found i 0 such that w i = x yy y z L i 21
Game tree m w L, w m x 1,y 1, z 1 x 2,y 2, z 2 x k,y k, z k... i=2 i=0 i=4... x 1 y 1 y 1 z 1 L x 2 z 2 L x k y k y k y k y k z k L 22
Example Show that L = {a n b n : n>0} is not regular Assume that m is the constant in the pumping lemma. We consider the following string w For the following possible x, y, z Case: Case: 23
Show that L = {uu R : u {a,b}*} is not regular Assume that m is the constant in the pumping lemma. We consider the following string w For the following possible x, y, z Case: Case: 24
Show that L={a n b k c n+k : n,k 0} is non-regular 25
Show that L = {a n : n is a perfect square} is not regular. 26
Show that L = {a n b l : n l} is not regular. Method 1: use pumping lemma pick w=a m! b (m+1)!, m 2. 27
Method 2: by closure properties consider L = comp(l) L(a*b*) = {a n b n : n 0} If L is regular, L must be regular. (think over!!!) Thus, L is not regular. 28
Use closure and pumping lemma To show that L is not regular Regular languages are closed under op Find another regular language L Compute L = L op L Show that L is not regular Note: it is easier to prove L non-regular 29
Proof of pumping lemma 30
Proof of pumping lemma (cont.) 31
Comments The pumping lemma CANNOT be used to prove that L is regular. Some mistakes in using the pumping lemma 1. Fix m=20, etc, some constant. 2. Choose w L, or w <m. 3. Not consider ALL possible decompositions w=xyz, xy m, y 1. 4. Every possible w=xyz, xy 2 z L for an integer i=2 (e.g.) is enough 32