390 likes | 744 Views
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 * ?. Theorem 1. If L 1 and L 2 are regular, then so are L 1 L 2 , L 1 L 2 , L 1 L 2 , L 1 , L 1 * .
E N D
Closure Properties of Regular Languages L1 and L2 are regular. How about L1L2, L1L2, L1L2,L1,L1*?
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.)
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))*
Proof • M = (Q, , , q0, F) accepts L1. M = (Q, , , q0, Q – F) accepts L1.
Proof • M1 = (Q, , 1, q0, F1) accepts L1. M2 = (P, , 2, p0, F2) accepts L2. a1 an q0 qf 1(qi, a) = qk a1 an p0 pf 2(pj, a) = pl 1((qi, pj), a) = (qk, pl)
Proof • Example: L1 = {abn | n 0} L2 = {anb | n 0} L1L2 = {ab}
Theorem 2 The family of regular languages is closed under reversal: If L is regular, then so is LR.
Proof ?
Homomorphism Suppose and are alphabets. h: * is called a homomorphism
Homomorphism Extended definition: w = a1a2 ... an h(w) = h(a1)h(a2) ... h(an)
Homomorphism If L is a language on , then its homomorphic image is defined as: h(L) = {h(w): w L}
Example = {a, b} = {a, b, c} h(a) = ab h(b) = bbc h(aba) = abbbcab L = {aa, aba} h(L) = {abab, abbbcab}
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.
Example = {a, b} = {b, c, d} h(a) = dbcc h(b) = bdc r = (a + b*)(aa)* L = L(r) h(r) = (dbcc + (bdc)*)(dbccdbcc)*
Theorem 3 The family of regular languages is closed under homomorphism: If L is regular, then so is h(L).
Proof Let L(r) = L for some regular expression r. Prove: h(L(r)) = L(h(r)).
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).
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 andy L2}
Example L1 = {anbm | n 1, m 0}{ba} L2 = {bm | m 1} L1/L2 = ?
Example L1 = {anbm | n 1, m 0}{ba} L2 = {bm | m 1} L1/L2 = {anbm | n 1, m 0}
Example L1 = {anbm | n 1, m 0}{ba} a b a b q0 q1 q2 b a q3 q5 a a, b a, b q4
Example L1 = {anbm | n 1, m 0}{ba} L2 = {bm | m 1} a b a b q0 q1 q2 *(q0, x) = qi *(qi, y) F and y L2 b a q3 q5 a a, b a, b q4
Example L1 = {anbm | n 1, m 0}{ba} L2 = {bm | m 1} a b a b q0 q1 q2 *(q0, x) = qi *(qi, y) F and y L2 b a q3 q5 a a, b a, b q4
Theorem The family of regular languages is closed under right quotient: If L1 and L2 are regular, then so is L1/L2.
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^
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 .
Example L1 = L(a*baa*) L2 = L(ab*) L1/L2 = ?
Example L1 = L(a*baa*) L1 = L(ab*) a a b a L(M0) L2 = L(M1) L2 = {a} L(M2) L2 = {a} L(M3) L2 = q0 q1 q2 b b q3 a, b
Example L1 = L(a*baa*) L1 = L(ab*) a a b a L(M0) L2 = L(M1) L2 = {a} L(M2) L2 = {a} L(M3) L2 = q0 q1 q2 b b q3 a, b
Questions about RLs • Given a regular language L on and any w *, is there an algorithm to determine whether or not w L?.
Questions about RLs • Given a regular language L on and any w *, is there an algorithm to determine whether or not w L?. Yes.
Questions about RLs • Is there an algorithm to determine whether or not a regular language is empty, finite, or infinite?.
Questions about RLs • Is there an algorithm to determine whether or not a regular language is empty, finite, or infinite?. Yes.
Questions about RLs • Given two regular languages L1 and L2, is there an algorithm to determine whether or not L1 = L2?.
Questions about RLs • Given two regular languages L1 and L2, is there an algorithm to determine whether or not L1 = L2?. Yes.
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.