1 closure properties of regular languages l 1 and l 2 are regular. how about l 1 l 2, l 1 l 2, l 1...

36
1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1 L 2 , L 1 L 2 , L 1 L 2 , L 1 , L 1 * ?

Upload: beverley-young

Post on 21-Jan-2016

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

1

Closure Properties of Regular Languages

L1 and L2 are regular.

How about L1L2, L1L2 , L1L2 , L1, L1* ?

Page 2: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

2

Theorem 1

If L1 and L2 are regular, then so are L1L2, L1L2 , L1L2 ,

L1, L1*.

(The family of regular languages is closed under intersection, union, concatenation, complement, and star-closure.)

Page 3: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

3

Proof

• L1 = L(r1) L2 = L(r2)

L(r1 + r2) = L(r1)L(r2)

L(r1 . r2) = L(r1)L(r2)

L(r1*) = (L(r1))*

Page 4: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

4

Proof

• M = (Q, , , q0, F) accepts L1.

M = (Q, , , q0, Q – F) accepts L1.

Page 5: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

5

Proof

• M1 = (Q, , 1, q0, F1) accepts L1.

M2 = (P, , 2, p0, F2) accepts L2.

q0 qf

a1 an

p0 pf

a1 an

2(pj, a) = pl

1(qi, a) = qk

1((qi, pj), a) = (qk, pl)

Page 6: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

6

Proof

• Example:

L1 = {abn | n 0}

L2 = {anb | n 0}

L1L2 = {ab}

Page 7: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

7

Theorem 2

The family of regular languages is closed under reversal:

If L is regular, then so is LR.

Page 8: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

8

Proof

?

Page 9: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

9

Homomorphism

Suppose and are alphabets.

h: *

is called a homomorphism

Page 10: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

10

Homomorphism

Extended definition:

w = a1a2 ... an

h(w) = h(a1)h(a2) ... h(an)

Page 11: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

11

Homomorphism

If L is a language on , then its homomorphic image is defined as:

h(L) = {h(w): w L}

Page 12: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

12

Example

= {a, b}

= {a, b, c}

h(a) = ab h(b) = bbc

h(aba) = abbbcab

L = {aa, aba} h(L) = {abab, abbbcab}

Page 13: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

13

Homomorphism

If L is the language on of a regular expression r,

then the regular expression for h(L) is obtained by

applying the homomorphism to each symbol of r.

Page 14: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

14

Example

= {a, b}

= {b, c, d}

h(a) = dbcc h(b) = bdc

r = (a + b*)(aa)* L = L(r)

h(r) = (dbcc + (bdc)*)(dbccdbcc)*

Page 15: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

15

Theorem 3

The family of regular languages is closed under homomorphism:

If L is regular, then so is h(L).

Page 16: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

16

Proof

Let L(r) = L for some regular expression r.

Prove: h(L(r)) = L(h(r)).

Page 17: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

17

Homework

• Exercises: 2, 4, 6, 8, 9, 11, 18, 22 of Section 4.1 - Linz’s book.

• Presentation: Section 4.3 - Linz’s book (pigeonhole principle & pumping lemma and examples).

Page 18: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

18

Right Quotient

Let L1 and L2 be languages on the same alphabet.

Then the right quotient of L1 with L2 is defined as:

L1/L2 = {x | xy L1 and y L2}

Page 19: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

19

Example

L1 = {anbm | n 1, m 0}{ba}

L2 = {bm | m 1}

L1/L2 = ?

Page 20: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

20

Example

L1 = {anbm | n 1, m 0}{ba}

L2 = {bm | m 1}

L1/L2 = {anbm | n 1, m 0}

Page 21: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

21

Example

q0 q1 q2

b

b

b

a

q3

a

a, b

a

q4

q5

a, b

a

L1 = {anbm | n 1, m 0}{ba}

Page 22: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

22

Example

q0 q1 q2

b

b

b

a

q3

a

a, b

a

q4

q5

a, b

a

L1 = {anbm | n 1, m 0}{ba}

L2 = {bm | m 1}

*(q0, x) = qi

*(qi, y) F and y L2

Page 23: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

23

Example

q0 q1 q2

b

b

b

a

q3

a

a, b

a

q4

q5

a, b

a

L1 = {anbm | n 1, m 0}{ba}

L2 = {bm | m 1}

*(q0, x) = qi

*(qi, y) F and y L2

Page 24: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

24

Theorem

The family of regular languages is closed under right quotient:

If L1 and L2 are regular, then so is L1/L2.

Page 25: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

25

Proof

• M = (Q, , , q0, F) accepts L1.

M^ = (P, , , q0, F^) accepts L1/L2.

If y L2 and *(qi, y) F add qi to F^

Page 26: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

26

Proof

• M = (Q, , , q0, F) accepts L1.

M^ = (P, , , q0, F^) accepts L1/L2.

If y L2 and *(qi, y) F add qi to F^

Mi = (P, , , qi, F) and L(Mi) L2 .

Page 27: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

27

Example

L1 = L(a*baa*)

L2 = L(ab*)

L1/L2 = ?

Page 28: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

28

Example

q0 q1 q2

a

a

b

b

b

a, b

q3

a

L1 = L(a*baa*)

L(M0) L2 =

L(M1) L2 = {a}

L(M2) L2 = {a}

L(M3) L2 =

L1 = L(ab*)

Page 29: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

29

Example

q0 q1 q2

a

a

b

b

b

a, b

q3

a

L1 = L(a*baa*)

L(M0) L2 =

L(M1) L2 = {a}

L(M2) L2 = {a}

L(M3) L2 =

L1 = L(ab*)

Page 30: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

30

Questions about RLs

1. Given a regular language L on and any w *, is there an algorithm to determine whether or not w L?.

Page 31: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

31

Questions about RLs

1. Given a regular language L on and any w *, is there an algorithm to determine whether or not w L?.

Yes.

Page 32: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

32

Questions about RLs

1. Is there an algorithm to determine whether or nota regular language is empty, finite, or infinite?.

Page 33: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

33

Questions about RLs

1. Is there an algorithm to determine whether or nota regular language is empty, finite, or infinite?.

Yes.

Page 34: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

34

Questions about RLs

1. Given two regular languages L1 and L2, is there an algorithm to determine whether or not L1 = L2?.

Page 35: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

35

Questions about RLs

1. Given two regular languages L1 and L2, is there an algorithm to determine whether or not L1 = L2?.

Yes.

Page 36: 1 Closure Properties of Regular Languages L 1 and L 2 are regular. How about L 1  L 2, L 1  L 2, L 1 L 2, L 1, L 1 * ?

36

Homework

• Exercises: 1, 2, 3, 5, 9 of Section 4.2 - Linz’s book.

• Exercises: 3, 4, 5, 6, 8, 10, 12 of Section 4.3 - Linz’s book.