lect7-ClosurePropertiesOfRL

lect7-ClosurePropertiesOfRL - Closure Properties of Regular...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Closure Properties of Regular Languages Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism 1 Closure Properties x Recall a closure property is a statement that a certain operation on languages, when applied to languages in a class (e.g., the regular languages), produces a result that is also in that class. x For regular languages, we can use any of its representations to prove a closure property. 2 Closure Under Union x If L and M are regular languages, so is L ∪ M. x Proof: Let L and M be the languages of regular expressions R and S, respectively. x Then R+S is a regular expression whose language is L ∪ M. 3 Closure Under Concatenation and Kleene Closure x Same idea:  RS is a regular expression whose language is LM.  R* is a regular expression whose language is L*. 4 Closure Under Intersection x If L and M are regular languages, then so is L ∩ M. x Proof: Let A and B be DFA’s whose languages are L and M, respectively. x Construct C, the product automaton of A and B. x Make the final states of C be the pairs consisting of final states of both A and B. 5 Example: Product DFA for Intersection 0 0 A 1 B [A,C] 0, 1 1 1 C 0 0 D 1 1 0 [A,D] 1 0 [B,C] 0 [B,D] 1 6 Closure Under Difference x If L and M are regular languages, then so is L – M = strings in L but not M. x Proof: Let A and B be DFA’s whose languages are L and M, respectively. x Construct C, the product automaton of A and B. x Make the final states of C be the pairs where A­state is final but B­state is not. 7 Example: Product DFA for Difference 0 0 A 1 B [A,C] 0, 1 1 1 C 0 1 0 D 1 1 0 [A,D] 1 0 [B,C] 0 [B,D] Notice: difference is the empty language 8 Closure Under Complementation x The complement of a language L (with respect to an alphabet Σ such that Σ* contains L) is Σ* – L. x Since Σ* is surely regular, the complement of a regular language is always regular. 9 Closure Under Reversal x Recall example of a DFA that accepted the binary strings that, as integers were divisible by 23. x We said that the language of binary strings whose reversal was divisible by 23 was also regular, but the DFA construction was very tricky. x Good application of reversal­closure. 10 Closure Under Reversal – (2) x Given language L, LR is the set of strings whose reversal is in L. x Example: L = {0, 01, 100}; LR = {0, 10, 001}. x Proof: Let E be a regular expression for L. x We show how to reverse E, to provide a regular expression ER for LR. 11 Reversal of a Regular Expression x Basis: If E is a symbol a, ε, or ∅, then ER = E. x Induction: If E is  F+G, then ER = FR + GR.  FG, then ER = GRFR  F*, then ER = (FR)*. 12 Example: Reversal of a RE x Let E = 01* + 10*. x ER = (01* + 10*)R = (01*)R + (10*)R x = (1*)R0R + (0*)R1R x = (1R)*0 + (0R)*1 x = 1*0 + 0*1. 13 Homomorphisms x A homomorphism on an alphabet is a function that gives a string for each symbol in that alphabet. x Example: h(0) = ab; h(1) = ε. x Extend to strings by h(a1…an) = h(a1)… h(an). x Example: h(01010) = ababab. 14 Closure Under Homomorphism x If L is a regular language, and h is a homomorphism on its alphabet, then h(L) = {h(w) | w is in L} is also a regular language. x Proof: Let E be a regular expression for L. x Apply h to each symbol in E. x Language of resulting RE is h(L). 15 Example: Closure under Homomorphism x Let h(0) = ab; h(1) = ε. x Let L be the language of regular expression 01* + 10*. x Then h(L) is the language of regular expression abε* + ε(ab)*. Note: use parentheses to enforce the proper grouping. 16 Example – Continued x abε* + ε(ab)* can be simplified. x ε* = ε, so abε* = abε. x ε is the identity under concatenation.  That is, εE = Eε = E for any RE E. x Thus, abε* + ε(ab)* = abε + ε(ab)* = ab + (ab)*. x Finally, L(ab) is contained in L((ab)*), so a RE for h(L) is (ab)*. 17 Inverse Homomorphisms x Let h be a homomorphism and L a language whose alphabet is the output language of h. x h­1(L) = {w | h(w) is in L}. 18 Example: Inverse Homomorphism x Let h(0) = ab; h(1) = ε. x Let L = {abab, baba}. x h­1(L) = the language with two 0’s and any number of 1’s = L(1*01*01*). Notice: no string maps to baba; any string with exactly two 0’s maps to abab. 19 Closure Proof for Inverse Homomorphism x Start with a DFA A for L. x Construct a DFA B for h­1(L) with:     The same set of states. The same start state. The same final states. Input alphabet = the symbols to which homomorphism h applies. 20 Proof – (2) x The transitions for B are computed by applying h to an input symbol a and seeing where A would go on sequence of input symbols h(a). x Formally, δB(q, a) = δA(q, h(a)). 21 Example: Inverse Homomorphism Construction 1 a B a A b a b C B 1 b Since h(1) = ε 0 A 0 Since h(0) = ab C 1 , 0 h(0) = ab h(1) = ε 22 Proof – (3) x Induction on |w| shows that δB(q0, w) = δA(q0, h(w)). x Basis: w = ε. x δB(q0, ε) = q0, and δA(q0, h(ε)) = δA(q0, ε) = q0. 23 Proof – (4) x Induction: Let w = xa; assume IH for x. x δB(q0, w) = δB(δB(q0, x), a). x = δB(δA(q0, h(x)), a) by the IH. x = δA(δA(q0, h(x)), h(a)) by definition of the DFA B. x = δA(q0, h(x)h(a)) by definition of the extended delta. x = δA(q0, h(w)) by def. of homomorphism. 24 ...
View Full Document

Ask a homework question - tutors are online