Lecture 7 Properties of regular languages COT 4420 Theory of Computation Section 4.1
Closure properties of regular languages If L 1 and L 2 are regular languages, then we prove that: Union: L 1 L 2 Concatenation: L 1 L 2 Star: L 1 * Reversal: L 1 R Complement: L1 Are regular Languages Intersection: L 1 L 2
Closure properties of regular languages If L 1 and L 2 are regular languages, then we prove that: Substitution Homomorphism Inverse homomorphism Are regular Languages Right Quotient: L 1 /L 2
Suppose this is the representation of an NFA accepting L 1. M(r)
Union L 1 L 2 M 1 M 2 w L 1 L 2 w L1 or w L2
L1 L2 = { a b} { ba} n Union - Example L1 = { a b} a n b L 2 = { ba} b a
Concatenation L 1 L 2 M 1 M 2 w L 1 L 2 w = w1w 2 : w1 L1 and w2 L2
Concatenation - Example n L1 L2 = { a b}{ ba} = { a bba} n n L1 = { a b} a L 2 = { ba} b b a
Star Operation L 1 * M 1 * w L w = w1w 2 wk : or w = w i L
Star Operation - Example L * = { a n b} * 1 a L1 = { a b} b n
Reverse L 1 R Make sure your NFA has single final state. Reverse all transitions Make the initial state accept state and make the accept state initial state. M M L ( M ) = L L ( M ) = R L
Reverse - Example L n 1 b = { a } a M 1 b L = R 1 { ba n } a M 1 b
Complement The the DFA that accepts L. Make final states non-final states and vice versa M M L ( M ) = L L ( M ) = L
Complement - Example a a,b n L1 = { a b} b a, b n L1 = { a, b}* { a b} a b a, b a,b
Intersection L 1 L 2 De Morgan s Law: L1 L2 = L1 L2 L 1 and L 2 are regular L 1 and L 2 are regular L 1 L 2 L 1 L 2 is regular is regular
Substitution A substitution f is a mapping f: Σ 2 Δ* (for some alphabet Δ). Thus f associates a language with each symbol of Σ. The mapping f is extended to strings as follows: f()= f(xa) = f(x)f(a) x Σ*, a Σ The mapping f is also extended to languages by defining:
Substitution - Example Σ={0,1} Δ={a,b} Let f(0) = ab* and f(1) = ac f(011) = ab*acac f(011*) = ab*ac(ac)* o If f(a) is a regular language for a Σ, we call the substitution a regular substitution.
Closure under substitution Theorem: Regular sets are closed under (regular) substitutions. Let R Σ * be a regular language. We need to show that f(r) is a regular language. For each a Σ, let R a Δ* be a regular set such that f(a) = R a. Select regular expressions denoting R and each R a. Replace each occurrence of a in the regular expression for R by the regular expression for R a.
Closure under substitution The resulting regular expression is denoting f(r). And it can be shown that: f(l 1 L 2 ) = f(l 1 ) f(l 2 ) f(l 1 L 2 ) = f(l 1 )f(l 2 ) f(l 1 *) = (f(l 1 ))*
Homomorphism A homomorphism h is a substitution in which a single letter is replaced with a string. for a Σ, h(a) is a single string in Δ h: Σ Δ* If w = a 1 a 2 a n then h(w) = h(a 1 )h(a 2 ) h(a n ) If L is a language on Σ, h(l) = { h(w) : w L} and is called its homomorphic image.
Homomorphism - Example Σ={0,1,2} Δ={a,b} h(0) = ab h(1) = b h(2) = a Then h(0110) = abbbab h(122) = baa The homomorphic image of L = {0110,122} is the language h(l) = {abbbab, baa}
Homomorphism Homomorphism is a substitution hence regular languages are closed under homomorphism. Inverse homomorphism: Let h: Σ Δ* be a homomorphism, then h -1 (w) = { x h(x) = w} for w Δ*. h -1 (L) = { x h(x) L} for L Δ*
Inverse Homomorphism Theorem: The class of regular sets is closed under inverse homomorphism. Let h: Σ Δ* be a homomorphism and consider L a regular language in Δ*. There must exists a dfa M=(Q, Δ, δ, q 0, F) that accepts L. We construct M Σ = (Q, Σ, δ, q 0, F) that accepts h -1 (L) by defining δ (q, a) = δ(q, h(a)) for a Σ. By induction on x we can show that x L Σ if and only if h(x) L.
Example Prove that L = { a n ba n : n 1} is not regular. Suppose we know hat {0 n 1 n : n 1} is not regular. h 1 (a) = a, h 1 (b) = ba h 1 (c)=a h 2 (a) = 0 h 2 (b) = 1 h 2 (c) = 1 h 1-1 ({a n ba n n 1}) = (a+c) n b(a+c) n-1 h 1-1 ({a n ba n n 1}) a*bc* = {a n bc n-1 : n 1} h 2 (h 1-1 ({a n ba n n 1}) a*bc* ) = {0 n 1 n : n 1} If { a n ba n : n 1} were regular since regular languages are closed under h and h -1 and intersection, {0 n 1 n : n 1} must have been regular, a contradiction.
Right Quotient Let L 1 and L 2 be languages on the same alphabet. Then the right quotient of L 1 with L 2 is defined as: L 1 /L 2 = { x: xy L 1 for some y L 2 } Example: L 1 = 0*10* L 2 =10*1 L 3 =0*1 L 1 /L 3 = 0* L 2 /L 3 =10*
Right Quotient Theorem: If L 1 and L 2 are regular languages, then L 1 /L 2 is regular. Suppose there is a dfa M=(Q, Σ, δ, q 0, F) such that L 1 = L(M). We construct M =(Q, Σ, δ, q 0, F ) that accepts L 1 /L 2. For all states q i Q determine if there exists a y L 2 such that δ*(q i, y) = q f F. In that case we add q i to F.
Right Quotient - Example L 1 = L(a*baa*) L 2 = L(ab*) L(M) = L 1
Right Quotient - Example L 1 = L(a*baa*) L 2 = L(ab*) For every state q i determine if there is a y L 2 that δ*(q i, y) F L(M) = L 1
Right Quotient - Example L 1 = L(a*baa*) L 2 = L(ab*) For every state q i determine if there is a y L 2 that δ*(q i, y) F L(M) = L 1 From q 0? No
Right Quotient - Example L 1 = L(a*baa*) L 2 = L(ab*) For every state q i determine if there is a y L 2 that δ*(q i, y) F L(M) = L 1 From q 0? No From q 1? y = a
Right Quotient - Example L 1 = L(a*baa*) L 2 = L(ab*) For every state q i determine if there is a y L 2 that δ*(q i, y) F L(M) = L 1 From q 0? No From q 1? y = a From q 2? y = a
Right Quotient - Example L 1 = L(a*baa*) L 2 = L(ab*) For every state q i determine if there is a y L 2 that δ*(q i, y) F L(M) = L 1 From q 0? No From q 1? y = a From q 2? y = a From q 3? No
Right Quotient - Example L 1 /L 2 = L(a*ba*)