properties of regular languageswgtzeng/courses... · closure properties •question: l is a regular...

31
Properties of Regular Languages Wen-Guey Tzeng Department of Computer Science National Chiao Tung University 1

Upload: others

Post on 16-May-2020

2 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

Properties of Regular Languages

Wen-Guey Tzeng

Department of Computer Science

National Chiao Tung University

1

Page 2: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 3: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• 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

Page 4: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

Over simple operations

• L1 and L2 are regular. So are L1L2, L1L2, L1L2, L1*, comp(L1).

• Example: Comp(L1)

• Example: L1L2

• Example: L1L2

4

Page 5: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 6: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• 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

Page 7: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 8: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• 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

Page 9: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• Find L1/L2 for L1=L(a*baa*) and L2=L(ab*)

• L1/L2 is denoted by r=a*ba*

9

Page 10: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 11: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• Method 2: direct construction from M1 and M2.

11

Page 12: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• Question: Find a dfa for L=L1 xor L2 ={w : wL1, wL2 or w L1, w L2}

12

Page 13: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

Closure under shift

• Shift(L)={a2a3…ana1 : a1a2…anL}

• Assume that regular language L is accepted by dfa M=(Q, , , q0, F)

13

Page 14: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 15: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 16: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 17: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 18: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

18

Page 19: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 20: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 21: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

21

Page 22: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

Example

• Show that L = {wwR : w{a,b}*} is not regular

22

Page 23: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• Show that L={w{a,b}* : na(w) < nb(w)}

23

Page 24: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• Show that L={anbkcn+k : n,k 0}

24

Page 25: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• Show that L = {an : n is a perfect square}

25

Page 26: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• Show that L = {anbl : nl} is not regular.

• Method 1: use pumping lemma

– pick w=ambm!, n2.

26

Page 27: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

• 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

Page 28: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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

Page 29: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

Proof of pumping lemma

29

Page 30: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

Proof of pumping lemma (cont.)

30

Page 31: Properties of Regular Languageswgtzeng/courses... · Closure Properties •Question: L is a regular language and op is an operator on strings. Is op(L) still a regular language? •Example

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