properties of regular languageswgtzeng/courses... · closure properties •question: l is a regular...
TRANSCRIPT
Properties of Regular Languages
Wen-Guey Tzeng
Department of Computer Science
National Chiao Tung University
1
Closure Properties
• Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language?
• Example
– L={anb : n1} is regular.
– Is LR = {ban : n1} 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
• L1 and L2 are regular. So are L1L2, L1L2, L1L2, L1*, comp(L1).
• Example: Comp(L1)
• Example: L1L2
• Example: L1L2
4
Closure under homomorphism
• Homomorphism: h: *
• h(a1a2…an) = h(a1)h(a2)…h(an)
• h(L) = {h(w) : wL}
• Example,
– h(a)=ab, h(b)=bbc
– h(aba)=abbbcab
– L={aba, bbaa}
– h(L) = {abbbcab, bbcbbcabab}
5
• Regular languages are closed under any homomorphism.
• Example
– Assume r = (a+ab*)(a+bb)*
– Then, r1 = (ab+ab(bbc)*)(ab+bbcbbc)*
– L(r1)=h(L(r)).
6
Closure under right quotient
• Right quotient: L1/L2={x : xyL1 for some yL2}
• Example,
– L1={anbm : n1, m0} {ba}
– L2={bm : m1}
– L1/L2 = {anbm : n1, m0}
• Regular languages are closed under right quotient.
7
• Let M1 = (Q, , , q0, F)
• Idea: If *(q0, xy) = *(q, y) = qfF and yL2, then q should be a final state in new M2=(Q, , , q0, F2)
• We examine every qQ. If there is y L2, put q in F2.
8
• Find L1/L2 for L1=L(a*baa*) and L2=L(ab*)
• L1/L2 is denoted by r=a*ba*
9
Closure under AND, OR, XOR, NOR
• Find a dfa for L=L1 L2 ={w : wL1, wL2}
– Assume that L1 is accepted by dfa M1 and L2 is accepted by dfa M2.
• Method 1: L= comp(comp(L1) comp(L2))
10
• Method 2: direct construction from M1 and M2.
11
• Question: Find a dfa for L=L1 xor L2 ={w : wL1, wL2 or w L1, w L2}
12
Closure under shift
• Shift(L)={a2a3…ana1 : a1a2…anL}
• Assume that regular language L is accepted by dfa M=(Q, , , q0, F)
13
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 wL
• Emptiness – Given a regular language L, determine whether L=?
• Finiteness, Equality, …
14
Identifying nonregular 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
15
Pigeonhole principle
• L is accepted by dfa M of m states.
1. For m+1 strings w1, w2, …, wm+1, there are i, j, ij, *(q0, wi) = *(q0, wj)
2. If a string w=a1a2…an, of length nm, is accepted by M, the accepting configuration must at least pass a state twice.
16
Use pigeonhole principle
• L={anbn : n0} is not regular.
• Assume that M=(Q, {a,b}, , q0, F) accepts L.
• Consider *(q0, a), *(q0, a2), …, *(q0, am+1),
• There must be r and s, rs, *(q0, ar)= q = *(q0, as), but
– *(q0, arbr) = *(q0, asbr) = p.
– Is p in F ? Contradiction !!
• Thus, L is not regular.
17
18
Pumping Lemma
• If L is a regular language, there exists some positive integer m such that any wL, |w|m, can be decomposed into w=xyz with
– |xy|m,
– |y|1,
– For any i=0, 1, 2,…, xyiz 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.
2. Find a string wL, |w|m, consider all possible (x, y, z) with
• w=xyz
• |xy|m,
• |y|1
3. For each possible (x, y, z), find one i, xyizL.
4. Conclusion: L is no regular.
20
21
Example
• Show that L = {wwR : w{a,b}*} is not regular
22
• Show that L={w{a,b}* : na(w) < nb(w)}
23
• Show that L={anbkcn+k : n,k 0}
24
• Show that L = {an : n is a perfect square}
25
• Show that L = {anbl : nl} is not regular.
• Method 1: use pumping lemma
– pick w=ambm!, n2.
26
• Method 2: by closure properties
– consider L’ = comp(L) L(a*b*) = {anbn : n0}
– If L is regular, L’ must be regular. ???
– Thus, L is not regular.
27
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 by pumping lemma
28
Proof of pumping lemma
29
Proof of pumping lemma (cont.)
30
Comments
• The pumping lemma CANNOT be used to prove that L is regular.
• Some mistakes in using the pumping lemma – Fix m=20, etc, some constant.
– Choose wL, or |w|<m.
– Not consider ALL possible decompositions w=xyz, |xy|m, |y|1.
– Every possible w=xyz, xy2zL for an integer i=2 (e.g.) is enough
31