370 likes | 798 Views
Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism. Review Closure Properties.
E N D
Closure Properties of Regular Languages Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism
Review Closure Properties • 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. • For regular languages, we can use any of its representations to prove a closure property.
Closure Under Union • If L and M are regular languages, so is L M. • Proof: Let L and M be the languages of regular expressions R and S, respectively. • Then R+S is a regular expression whose language is L M. • Illustrates use of RE representation
Closure Under Concatenation and Kleene Closure • Same idea: • RS is a regular expression whose language is LM; therefor LM is regular. • R* is a regular expression whose language is L*; therefor L* is regular
Closure Under Intersection • If L and M are regular languages, then so is L M. • Proof: Let A and B be DFA’s whose languages are L and M, respectively. • Construct C the product automaton of A and B • States 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)] • Make the accepting states of C be the pairs consisting of accepting states of both A and B.
Product DFA for Intersection DFA(L) P-DFA(L M ) 0 0 1 0 [A,C] [A,D] A B 1 0, 1 1 1 0 0 1 [B,C] [B,D] DFA(M) 0 1 0 C D String w accepted by p-DFA iff it is accepted by both DFA(L) and DFA(M) 1
Closure Under Difference • If L and M are regular languages, then so is L – M = strings in L but not M. • Proof: Let A and B be DFA’s whose languages are L and M, respectively. • Construct C, product automaton of A and B. • Make the accepting states of C be the pairs where A-state is accepting but B-state is not.
Product DFA for Difference p-DFA(L-M) DFA(L) 0 0 1 0 [A,C] [A,D] A B 1 0, 1 1 1 0 0 DFA(M) 1 [B,C] [B,D] 0 1 0 C D DFA(L-M) is the empty language in this case. How do we know this? 1
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.
Closure Under Reversal • Given language L, LR is the set of strings whose reversal is in L. • Example: L = {0, 01, 100}; LR = {0, 10, 001}. • Proof: Let E be a regular expression for L. • We show how to reverse E, to provide a regular expression ER for LR.
Reversal of a Regular Expression • Basis: If E is a symbol a, ε, or ∅, then ER = E. • Induction: • If E=F+G, then ER = FR + GR. • If E=FG, then ER = GRFR • If E=F*, then ER = (FR)*.
Example: Reversal of a RE Let E = 01* + 10*. ER = (01* + 10*)R = (01*)R + (10*)R = (1*)R0R + (0*)R1R = (1R)*0 + (0R)*1 = 1*0 + 0*1.
Homomorphisms • A homomorphism on an alphabet is a function that gives a string for each symbol in that alphabet • h(L)={h(w)|w is in L} is the homomorphism of language L • Example on S={0,1}: • Define h(0) = ab h(1) = ε • Extend to strings by h(a1…an) = h(a1)…h(an) • therefore: h(01010) = ababab
Closure Under Homomorphism • 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. • Proof: Let E be a regular expression for L. • Apply h to each symbol in E. • Language of resulting RE is h(L).
Note: use parentheses to enforce the proper grouping. Example: Closure under Homomorphism • Let h(0) = ab; h(1) = ε. • Let L be the language of regular expression 01* + 10*. • Then h(L) is the language of regular expression abε* + ε(ab)*.
Example – Continued • abε* + ε(ab)* can be simplified. • ε* = ε, so abε* = abε. • ε is the identity under concatenation. • abε*+ε(ab)*=abε+ε(ab)*=ab+(ab)*. • ab is contained in (ab)* • RE for h(L) is (ab)*
Inverse Homomorphism of a string • h-1(w) is read “inverse homomorphism of w • If w’=h-1(w), then h(w’)=w • Testing an inverse homomorphism candidate is easy. Just apply homomorphism to the candidate
Inverse homomorphisms of a language • Let h be a homomorphism defined on S • Let h(L) be a homomorphism of L defined on S (define h(L)) • Let h-1(L) be the inverse homomorphism of L • w’ is in h-1(L) iff h(w’)=w is in L
Example: Inverse Homomorphism • Let h(0) = ab; h(1) = ε. • Let L = {abab, baba} • h-1(L) = w defined on {0,1} such that h(w) is either abab or baba • No w such that h(w)=baba • h-1(L) is language of strings with two 0’s and any number of 1’s = L(1*01*01*).
Closure of RLs under Inverse HomomorphismProof by construction • Start with a DFA = A for L • Construct the ih-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 • Transition function δB(q, a) = δA(q, h(a))
1 Since h(1) = ε B 1 0 A 0 Since h(0) = ab C 1 , 0 Example of ih-DFA Construction ih-DFA defined on {0,1} DFA defined on {a,b} a B a A b b b C a δB(q, a) = δA(q, h(a)) h(0) = ab h(1) = ε
Given: δB(q, a) = δA(q, h(a))Prove:δB(q0, w) = δA(q0, h(w))by Induction on |w| • Basis: w = ε δB(q0, ε) = q0 (true for any DFA) δA(q0, h(ε)) = δB(q0, ε) = q0(given)
Proof continued • IH: δB(q0, x) = δA(q0, h(x)) • Induction: Let w = xa δB(q0, w) = δB(δB(q0, x), a) by delta-hat = δB(δA(q0, h(x)), a) by the IH. = δA(δA(q0, h(x)), h(a)) by construction of ih-DFA = δA(q0, h(x)h(a)) by delta-hat = δA(q0, h(w)) by homomorphism.
Quotient of a language L/a • L/a = set of all strings w such that wa is in L • a is a symbol in the alphabet of L • a is the last symbol in the test string wa • Example: if L={a,aab,baa} then L/a ={e,ba} • If L is regular, so is L/a • Proof by construction: Q-DFA(L) same as DFA(L) except that q is an accepting state of Q-DFA iff d(q,a) is an accepting state of DFA
Derivative of a language: a\L • a\L = set of all strings w such that aw is in L • a is the first symbol in the test string aw • Example: if L={a,aab,baa} then a\L={e,ab} • Called “derivative” because RE of L compared to RE a\L is similar to derivative of algebraic expression • Example: a\(R+S)=a\R+a\S remove a after union is the same as union of strings with a removed
Using Closure to prove non-regular • L1 is language in question • L2 is language known to be non-regular • O is an operation under which regular languages are closed. • If L1 were regular, then L2 = OL1 would be regular, but it isn’t. • Therefore L1 is not regular • Example: 4.2.13 p149
Using Closure to prove non-regular • Example: 4.2.13 p149 • Prove L1={0i1j|i>0,j>0,i not = j} not reg. • Assume L1 is regular • Then L2=0*1*-L1 is regular by closure under difference • But L2={0n1n|n>0} is not regular • Therefor the assumption about L1 is false
Homomorphism • Function defined on strings that substitutes a particular string for each symbol • Example: h(0)=ab, h(1)=e defined on strings of 0’s and 1’s • Regular languages are closed under homomorphism • If w=a1a2…an, then h(w)=h(a1)h(a2)…h(an) • h(L)={h(w)|w is in L} is the homomorphism of language L
Closure Under Reversal • Recall example of a DFA that accepted the binary strings that, as integers were divisible by 23. • We said that the language of binary strings whose reversal was divisible by 23 was also regular, but the DFA construction was very tricky. • Good application of reversal-closure.
Proof – (2) • 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). • Formally, δB(q, a) = δA(q, h(a)).
Using Closure to prove non-regular 2 • Example: exercise 4.2.13 p149 • L2={0n1n | n > 0} is not a regular language. • Prove L1={0i1j |i not equal j} not regular • S*-L1=L2 (i=j case) + set of all strings 0’s and 1’s that are not in 0*1* • L2=intersection S*-L1 and 0*1* • Regular languages are closed under complement and intersection • If L1 is regular then L2 would be regular • L2 is not regular; therefore L1 not regular