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 R and S be the REs that define L and M. Then R+S is a regular expression whose regular language is L M. Therefore, RLs are closed under union
Closure Under Concatenation and Kleene Closure Same idea: RS is a regular expression whose language is LM; therefore LM is regular. R* is a regular expression whose language is L*; therefore L* is regular
Closure Under Intersection If L and M are regular languages, then LM is regular. Proof: Let A and B be DFA’s whose languages are L and M, respectively. Construct C = p-DFA 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 B 1 0, 1 P-DFA(L M ) L [A,C] [A,D] 1 1 1 1 C D [B,C] [B,D] 1 M String w accepted by p-DFA iff it is accepted by both DFA(L) and DFA(M). P-DFA defines (LM ), which is regular
Closure Under Difference L– M = strings in L but not M. 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 = p-DFA of A and B. Make the accepting states of C be the pairs where A-state is accepting but B-state is not. p-DFA defines the RL of L-M.
Product DFA for Difference B 1 0, 1 p-DFA(L-M) L [A,C] [A,D] 1 1 1 C D 1 [B,C] [B,D] 1 M p-DFA(L-M) is the empty language in this case, why?
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 = 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 find ER of 1*0 + 0*1. Show all steps
Example: Reversal of a RE Let E = 01* + 10*. ER = (01* + 10*)R = (01*)R + (10*)R (union rule) = (1*)R0R + (0*)R1R (concat. rule) = (1R)*0 + (0R)*1 (closure rule) = 1*0 + 0*1.
Homomorphisms A homomorphism on an alphabet is a function that assigns a string to every symbol in that alphabet Example on S={0,1} Define h(0) = ab h(1) = ε Extend to strings by h(a1…an) = h(a1)…h(an) example: h(01010) = ababab h(L)={h(w)|w is in L}=homomorphism of L Language formed by applying h to every string in L
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).
Exercise: find the RE of h(L) and simplify h(0) = ab; h(1) = ε. L = the language of RE = 01* + 10* Find the RE of h(L) and simplify
Simplify the RE for h(L) 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 w’=h-1(w), iff h(w’)=w Testing a string for inverse homomorphism is easy. Just apply homomorphism to the string
Inverse homomorphisms of a language Let h be a homomorphism defined on S Let h(L) be a homomorphism of L defined on S Let h-1(L) denote the inverse homomorphism of L defined by h(L) h-1(L) ={w’| such that h(w’) is in L}
Example: Inverse Homomorphism Let h(0) = ab; h(1) = ε. Let L = {abab, baba} h-1(L) = {all w defined on {0,1} such that h(w) is either abab or baba} No w such that h(w)=baba h-1(L) = any w with two 0’s and any number of 1’s because h(w)=abab
Closure of RLs under Inverse Homomorphism Proof by construction Start with a DFA(L) = A 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))
Example of ih-DFA Construction ih-DFA defined on {0,1} DFA defined on {a,b} 1 Since h(1) = ε a B C B A , 0 Since h(0) = ab a A b b b C a δB(q, a) = δA(q, h(a)) h(0) = ab h(1) = ε
CptS 317 Fall 2016 Assignment 12, Due 10-28-16 Exercises 4.2.1 (a), (c) and (e) text p 147
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/a) 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 Concatenation example on board
Exercise 4.2.5e What is the implication of 0\L = nil? Exercise 4.2.5f Example of L such that 0\L = L
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. L2 = O L1 If L1 were regular, then L2 would be regular, but it isn’t. Therefore L1 is not regular
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 L2={0n1n|n>0} why? L2={0n1n|n>0} is not regular Therefor the assumption about L1 is false