Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Closure Properties of Regular Languages Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism.

Similar presentations


Presentation on theme: "1 Closure Properties of Regular Languages Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism."— Presentation transcript:

1 1 Closure Properties of Regular Languages Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

2 2 Review Closure Properties uRecall 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. uFor regular languages, we can use any of its representations to prove a closure property.

3 3 Closure Under Union uIf L and M are regular languages, so is L  M. uProof: Let L and M be the languages of regular expressions R and S, respectively. uThen R+S is a regular expression whose language is L  M. uIllustrates use of RE representation

4 4 Closure Under Concatenation and Kleene Closure uSame idea: wRS is a regular expression whose language is LM; therefor LM is regular. wR* is a regular expression whose language is L*; therefor L* is regular

5 5 Closure Under Intersection uIf L and M are regular languages, then L  M is regular. uProof: Let A and B be DFA’s whose languages are L and M, respectively. uConstruct C = p-DFA of A and B wStates of C are distinct pairs [q(A),r(B)]  Start state is pair [start(A), start(B)]  δ ([q(A),r(B)],a) = [ δ A (q,a), δ B (r,a)] uMake the accepting states of C be the pairs consisting of accepting states of both A and B.

6 6 Product DFA for Intersection AB 0 1 0, 1 1 CD 1 0 0 [A,C][A,D] 0 [B,C] 1 0 1 0 1 [B,D] 0 1 DFA(L) DFA(M) P-DFA(L  M ) String w accepted by p-DFA iff it is accepted by both DFA(L) and DFA(M). P-DFA defines (L  M ), which is regular

7 7 Closure Under Difference uIf L and M are regular languages, then so is L – M = strings in L but not M. uProof: Let A and B be DFA’s whose languages are L and M, respectively. uConstruct C = p-DFA of A and B. uMake the accepting states of C be the pairs where A-state is accepting but B-state is not.

8 8 Product DFA for Difference AB 0 1 0, 1 CD 1 1 0 0 [A,C][A,D] 0 [B,C] 1 0 1 0 1 [B,D] 0 1 DFA(L-M) is the empty language in this case. How do we know this? DFA(L) DFA(M) p-DFA(L-M)

9 9 Closure Under Complementation  The complement of a language L (with respect to an alphabet Σ such that Σ * contains L) is Σ * – L.  Since Σ * is regular, the complement of a regular language is regular because it is the difference of regular languaes.

10 10 Closure Under Reversal uGiven language L, L R is the set of strings whose reversal is in L. uExample: L = {0, 01, 100}; L R = {0, 10, 001}. uProof: Let E be a regular expression for L. uWe show how to reverse E, to provide a regular expression E R for L R.

11 11 Reversal of a Regular Expression  Basis: If E is a symbol a, ε, or ∅, then E R = E. uInduction: wIf E=F+G, then E R = F R + G R. wIf E=FG, then E R = G R F R wIf E=F*, then E R = (F R )*.

12 12 Example: Reversal of a RE Let E = 01* + 10*. E R = (01* + 10*) R = (01*) R + (10*) R = (1*) R 0 R + (0*) R 1 R = (1 R )*0 + (0 R )*1 = 1*0 + 0*1.

13 13 Homomorphisms uA homomorphism on an alphabet is a function that assigns a string to every symbol in that alphabet  Example on  ={0,1}  Define h(0) = ab h(1) = ε wExtend to strings by h(a 1 …a n ) = h(a 1 )…h(a n ) therefore: h(01010) = ababab uh(L)={h(w)|w is in L}=homomorphism of L wLanguage formed by applying h to every string in L

14 14 Closure Under Homomorphism uIf 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. uProof: Let E be a regular expression for L. uApply h to each symbol in E. uLanguage of resulting RE is h(L).

15 15  Let h(0) = ab; h(1) = ε. uLet L be the language of regular expression 01* + 10*.  Then h(L) is the language of regular expression ab ε * + ε (ab)*. Note: use parentheses to enforce the proper grouping. Exercise: find the RE of h(L)

16 16 Simply RE for h(L)  ab ε * + ε (ab)*  ε * = ε, so ab ε * = ab ε.  ε is the identity under concatenation.  ab ε *+ ε (ab)*=ab ε + ε (ab)*=ab+(ab)*. uab is contained in (ab)* uRE for h(L) is (ab)*

17 17 Inverse Homomorphism of a string uh -1 (w) is read “inverse homomorphism of w uw’=h -1 (w), iff h(w’)=w uTesting an inverse homomorphism candidate is easy. uJust apply homomorphism to the candidate

18 18 Inverse homomorphisms of a language  Let h be a homomorphism defined on   Let h(L) be a homomorphism of L defined on   Let h -1 (L) denote the inverse homomorphism of L defined by h(L) uh -1 (L) ={w’| such that h(w’) is in L}

19 19 Example: Inverse Homomorphism  Let h(0) = ab; h(1) = ε. uLet L = {abab, baba} uh -1 (L) = {w defined on {0,1} such that h(w) is either abab or baba} uNo w such that h(w)=baba uFor any w with two 0’s and any number of 1’s h(w)=abab

20 20 Closure of RLs under Inverse Homomorphism Proof by construction uStart with a DFA = A for L uConstruct the ih-DFA = B for h -1 (L) with: wThe same set of states. wThe same start state. wThe same final states. wInput alphabet = the symbols to which homomorphism h applies  Transition function δ B (q, a) = δ A (q, h(a))

21 21 Example of ih-DFA Construction A C B a a a b b b C B A 1 1 1Since h(1) = ε 0 0, 0 Since h(0) = ab DFA defined on {a,b} ih-DFA defined on {0,1} δ B (q,  ) = δ A (q, h(  )) h(0) = ab h(1) = ε

22 22 CptS 317 Fall 2014 Assignment 9, Due 11-7-14 Exercises 4.2.1 (a), (c) and (e) text p 147

23 23 Quotient of a language L/a uL/a = set of all strings w such that wa is in L ua is a symbol in the alphabet of L ua is the last symbol in the test string wa  Example: if L={a,aab,baa} then L/a ={ ,ba} uIf L is regular, so is L/a  Proof by construction: q-DFA(L/a) same as DFA(L) except that q is an accepting state of q-DFA iff  (q,a) is an accepting state of DFA uillustrate

24 24 Derivative of a language: a\L ua\L = set of all strings w such that aw is in L ua is the first symbol in the test string aw  Example: if L={a,aab,baa} then a\L={ ,ab} uCalled “derivative” because RE of L compared to RE a\L is similar to derivative of algebraic expression uExample: a\(R+S)=a\R+a\S remove a after union is the same as union of strings with a removed uConcatenation example on board

25 25 Exercise 4.2.5e What is the implication of 0\L = nil? Exercise 4.2.5f Find a language such that 0\L = L

26 26 Using Closure to prove non-regular uL 1 is language in question uL 2 is language known to be non-regular uO is an operation under which regular languages are closed. uL 2 = O L 1 uIf L 1 were regular, then L 2 would be regular, but it isn’t. uTherefore L 1 is not regular

27 27 Using Closure to prove non-regular uExample: 4.2.13 p149 uProve L1={0 i 1 j |i>0,j>0,i not = j} not reg. uAssume L1 is regular uThen L2=0*1*-L1 is regular by closure under difference uL2={0 n 1 n |n>0} why? uL2={0 n 1 n |n>0} is not regular uTherefor the assumption about L1 is false

28 28


Download ppt "1 Closure Properties of Regular Languages Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism."

Similar presentations


Ads by Google