Closure Properties of Regular Language Lecture-2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Closure Properties of Regular

Language
Regular Language
A language that can be defined by regular
expression.
L1 = { bb abb aabb aaabb …..}
RE = a*bb

q0 q1 q2

q0 q1
Closure Properties of Regular Language

Closure refers to some operation on a


language, resulting in a new language that
is of same “type” as originally operated on
i.e., regular.
For example, the positive integers are
closed under addition and multiplication,
S = {-∞ .. -5 .. 1,2,3,4,5 .. +∞}
A plus operation on any two integer from
the set S produce the same type of result.
Therefore plus operation is closed in set S.
Closure Properties of Regular Language

Set of Regular Language


L1
L2
.
.
L10

LI U L2 = L10

If result of union operation between L1 and L2 exist in similar set of RL,


then it is called closure (closed) property of regular language else
operation is not closed.
Closure Properties
Regular languages are closed under a wide
variety of operations.
 Union
 Intersection
 Difference
 Concatenation
 Kleene Closure
 Complementation
 Reversal
 Homomorphism
 Reverse homomorphism
UNION
Closure Under Union
 If L1 and L2 are two Regular Language. Then, if we
combine both the language, the result we will get is a
regular Language.
 If L1 & L2 are two RL. Then their union is defined by
L1UL2 = { W: W∈L1 & W∈L2}
Example:
L1 = {aa, bb, aaa, bbb}
L2 = {xx, yy, xxx, yyy}
L3 = L1UL2 = {aa, bb, aaa, bbb, xx, yy, xxx, yyy}
“Union of two regular language is regular”
Closure Under Union
If L1 and L2 are regular languages, there are regular
expressions r1 and r2 that define these languages.
Then (r1+r2) is a regular expression that define the
language L1 + L2.
Hence L1+L2 (L1UL2) is a regular language.

Example: if L1 = (a+b)(a+b) and L2 = (a+b)


Then
L1 + L2 = (a+b)(a+b)+(a+b)
= aa+bb+bc+bb+a+b
Union of FA

New States
State a b
(P,1) +-A (Q,2) D (P,1) A
(P,2) +B (Q,1) C (P,2) B
(Q,1) +C (R,2) F (P,1) A
(Q,2) +D (R,1) E (P,2) B
(R,1) E (R,2) F (R,1) E
(R,2) +F (R,1) E (R,2) F
Union of FAs
Closure Properties of Regular
Language(Complement)
 If L is a language over the alphabet ∑, then
its complement denoted by L’ is a language
consisting of all string from ∑(ab)* that are
not words in L
 L’ = {x ∈ ∑* | x ∉ L}
 L1 = { a, ab, aa, abb, aaa, aba, … }
 L1’ = ∑* - L1 = {^, b, ba, bb, bab, baa …}
 If L is a regular Language, then L’ is also a
regular language. i.e. the set of regular
language is closed under complementation.
Closure Properties of Regular
Language(Complement)
 If L is a regular language then Kleen’s theorem states that
there is some FA that accepts the language L.
 This FA contains some final states. Reverse the final status
of each state, means convert final to no-nfinal state and
no-final to final state.
 This new FA will now accept all the string that were
previously being rejected and reject all the previously
accepted strings i.e it accepts the words of L’.
 Thus this new FA defines L’ which by Kleen’s theorem
indicates that L’ can also be defined by a Regular
Expression and hence is a Regular Language.
Closure Properties of Regular
Language(Complement)
Example L = {abb, aba}
L’ = {^, a, b, ab, ba, bb, aa … aaa, baa .. }

- + -
+ +
+

+
Closure Properties of Regular
Language(Intersection)
If L and M be languages over alphabet ∑. Then
L ∩ M is the language that contains all string
that are in both L and M.

 Intersection of Regular Languages


If L1 and L2 are regular languages then L1 ∩
L2 is also regular language. i.e. Set of regular
languages is closed under intersection.
Closure Properties of Regular
Language(Intersection)
By Demorgan’s Law
L1 ∩ L2 = (L1’ U L2’)’

This implies that L1 ∩ L2 consists of all


words that are not is either L1’ or L2’.
As L1 and L2 are regular languages so are
L1’ and L2’. There Union L1’+L2’ is also a
regular language.
Closure Properties of Regular
Language(Intersection)
L1 = All strings with a double a
R1 = (a+b)*aa(a+b)*
L2 = All strings with an even number of a’s
R2 = b*(ab*ab*)*
Now the FAs of Both Language L1 and L2
Closure Properties of Regular
Language(Intersection)
Step-1: Complement of FAs
(FA1 U FA2)’ = FA1’ + FA2’
Closure Properties of Regular
Language(Intersection)
Step-2
Join the machines to get FA3 = FA1’ + FA2’

To get FA3 machine, we first create a


transition table of both FA1’ and FA2’
New States
State a b
(x1,y1) = - +A (x2,y2) D (x1,y1) A
(x1,y2) = +B (x2,y1) C (x1,y2)B
(x2,y1) = +C (x3,y2) F (x1,y1) A
(x2,y2) = +D (x3,y1) E (x1,y2) B
(x3,y1) =- E (x3,y2) F (x3,y1) E
(x3,y2) = +F (x3,y1) E (x3,y2) F
Closure Properties of Regular
Language(Intersection)
State Diagram

You might also like