You are on page 1of 12

Closure properties of regular languages

All regular languages are closed under the mentioned operations. These operations are as
follows:

1. Union
2. Star Closure
3. concatenation
4. Complement
5. Reverse
6. Intersection
7. Difference
8. Homomorphism
9. Inverse Homomorphism

Let L and M be regular languages. Then the following languages are all regular
1. Union : LUM
Let L1 and L2 be the two languages, then
L1 U L2 = { x , y | x ϵ L1 and y ϵ L2 }
Ex: Let L1 = { 00,01} L2 = { 00,110,11}
L1 U L2 = {00,01,110,11}
2. Star closure : L*
Let L be the languages, then

L* = ⋃𝑖=0 𝐿𝑖

Ex: Let L = {ab}


L0 = {Ɛ}
L1 = {ab}
L2 = {abab}
L3 = {ababab}
L4 = {abababab}

L* = ⋃𝑖=0 𝐿𝑖 = L0 U L1 U L2 U L3 . . . . . . . . .

= { Ɛ, ab, abab, ababab, abababab………..}


3. Concatenation : L.M
Let L1 and L2 be the two languages, then
L1 . L2 = { x . y | x ϵ L1 and y ϵ L2 }
Ex: Let L1 = { 00,01} L2 = { 00,110,11}

14
L1 . L2 = { 0000, 00110, 0011, 0100, 01110, 0111 }
4. Complement :
If L(G) is a regular language, its complement L'(G) will also be regular. Complement
of a language can be found by subtracting strings which are in L(G) from all possible
strings.
Example
L(G) = {an | n > 3}
L'(G) = {an | n <= 3}

5. Reverse : LR = wR : w ϵ L
R
Given language L, L is the set of strings whose reversal is in L.
Example:
L = {0, 01, 100};
LR = {0, 10, 001}

6. Intersection : LՈM
If L1 and If L2 are two regular languages, their intersection L1 ∩ L2 will also be
regular.
Example
So, L1 = { a,aa, aaa, aaaa, ....} (Strings of all possible lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even length excluding Null)

7. Difference : L–M
If L and M are regular languages, then so is L – M = strings in L but not M.
If L1 and L2 are regular languages, then L1-L2 is as well, which implies all the strings
in L1 but not in L2.
So, L1 = {a, aa, aaa, aaaa, ....} (Strings of all possible lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....}
(Strings of all odd lengths excluding Null)

8. Homomorphism : h(L) = { h(w) | w ∈ L, h is a homomorphism }


A homomorphism on an alphabet is a function that gives a string for each symbol in
that alphabet.
Example: h(0) = ab; h(1) = ε
Extend to strings by h(a1…an) = h(a1)…h(an).
Example: h(01010) = ababab
9. Inverse Homomorphism –
Let h be a homomorphism and L a language whose alphabet is the output language
of h. h-1 (L) = {w | h(w) is in L}.
Example:

15
If L = {aabb} and H(0) = “aa” and H(1) = “bb” then after substitution H-1(L) is given
below
H-1(L) = {01}
Pumping Lemma for Regular sets
Pumping Lemma: If L is a regular language, then there exists a constant p such that every
string w ∈ L, of length p or more can be written as w = xyz, where

1. |y| > 0
2. |xy| ≤ p
3. xyiz ∈ L for all i

if a string y is ‘pumped’ or insert any number of times, the resultant string still remains in
A.
Steps to prove that a language is not regular by using Pumping Lemma are as follows−

• step 1 − We have to assume that L is regular


• step 2 − So, the pumping lemma should hold for L.
• step 3 − It has to have a pumping length (say P).
• step 4 − All strings longer that P can be pumped |w|>=p.
• step 5 − Now find a string 'w' in L such that |w|>=P
• step 6 − Divide w into xyz.
• step 7 − Show that xyiz ∉ L for some i.
• step 8 − Then consider all ways that w can be divided into xyz.
• step 9 − Show that none of these can satisfy all the 3 pumping conditions at
same time.
• step 10 − w cannot be pumped = CONTRADICTION.

Implementation of Pumping lemma for regular languages


1. The language L = { anbn : n ≠ 0 } is not regular.
(or)
1.Using Pumping Lemma, prove that the language A = {anbn | n≥0} is Not Regular.
Solution:
Assume that A is Regular and has a Pumping length = P.
Let a string S = apbp.
Now divide the S into the parts, x y z.
To divide the S, let’s take the value of P = 7.
Therefore, S = aaaaaaabbbbbbb (by putting P=7 in S = apbp).
Case 1: Y consists of a string having the letter only ‘a’.

16
Case 2: Y consists of a string having the letter only ‘b’.

Case 3: Y consists of a string with the letters ‘a’ and ‘b’.


aaaa aaabb bbbbb
x y z
For all the above cases, we need to show xyiz ∉ A for some i.
Let the value of i = 2. xyiz => xy2z
In Case 1. xy2z = aa aaaa aaaa abbbbbbb
No of ‘a’ = 11, No. of ‘b’ = 7.

Since the No of ‘a’ != No. of ‘b’, but the original language has an equal number of ‘a’ and ‘b’;
therefore, this string will not lie in our language.
In Case 2. xy2z = aaaaaaabb bbbb bbbb b
No of ‘a’ = 7, No. of ‘b’ = 11.
Since the No of ‘a’ != No. of ‘b’, but the original language has an equal number of ‘a’ and ‘b’;
therefore, this string will not lie in our language.
In Case 3. xy2z = aaaa aaabb aaabb bbbbb
No of ‘a’ = 10, No. of ‘b’ = 9.
Since the No of ‘a’ != No. of ‘b’, but the original language has an equal number of ‘a’ and ‘b’,
and also, this string did not follow the anbn pattern; therefore, this string will not lie in our
language.
We can see at i = 2 all the above three strings do not lie in the language A = {anbn | n≥0}.
Therefore, the language A = {anbn | n≥0} is not Regular.

17
Practice Problems:
2. The language L = { uuR : u ∈ {a,b}*} is not regular.
3. The language L = { an : n is prime } is not regular.
4. L = { anbm : n ≠ m }
5. L = { anbm : n > m }
6. L = { w : na(w) = nb(w) }
7. L = { ww : w ∈ {a,b}* }
8. L = { an2 : n > 0 }

Introduction to Grammar
Grammar in theory of computation is a finite set of formal rules that are generating syntactically
correct sentences.
The formal definition of grammar is that it is defined as four tuples −
G=(V,T,P,S)
G is a grammar, which consists of a set of production rules. It is used to generate the strings of
a language.
V is the final set of non-terminal symbols or Variables. It is denoted by capital letters.
T is the final set of terminal symbols. It is denoted by lower case letters.
P is a set of production rules, which is used for replacing non-terminal symbols (on the
left side of production) in a string with other terminals (on the right side of production).
S is the start symbol used to derive the string.

1. Terminal Symbols –
Terminal symbols are those which are the components of the sentences
generated using a grammar and are represented using small case letter like a, b, c
etc.
2. Non-Terminal Symbols –
Non-Terminal Symbols are those symbols which take part in the generation of
the sentence but are not the component of the sentence. Non-Terminal Symbols
are also called Auxiliary Symbols and Variables. These symbols are represented
using a capital letter like A, B, C, etc.
18
Example 1:
Consider a grammar G = (V , T , P , S) where-
•V = { S } // Set of Non-Terminal symbols
• T = { a , b } // Set of Terminal symbols
• P = { S → aSbS , S → bSaS , S → ∈ } // Set of production rules
• S = { S } // Start symbol

Types of grammar

Context Free Grammar (CFG)

Parse Tree-
Parse tree is a hierarchical structure that defines the derivation of the grammar to yield input
strings.
The process of deriving a string is called as derivation.
The geometrical representation of a derivation is called as a parse tree or derivation tree.

1. Leftmost Derivation-
The process of deriving a string by expanding the leftmost non-terminal at each step is called
as leftmost derivation.
The geometrical representation of leftmost derivation is called as a leftmost derivation tree.

19
Example-
Consider the following grammar-
S → aB / bA
S → aS / bAA / a
B → bS / aBB / b
A→ a
Let us consider a string w = aaabbabbba
Now, let us derive the string w using leftmost derivation.

Leftmost Derivation-
S → aB
→ aaBB (Using B → aBB)
→ aaaBBB (Using B → aBB)
→ aaabBB (Using B → b)
→ aaabbB (Using B → b)
→ aaabbaBB (Using B → aBB)
→ aaabbabB (Using B → b)
→ aaabbabbS (Using B → bS)
→ aaabbabbbA (Using S → bA)
→ aaabbabbba (Using A → a)

20
2. Rightmost Derivation-
The process of deriving a string by expanding the rightmost non-terminal at each step is called
as rightmost derivation.
The geometrical representation of rightmost derivation is called as a rightmost derivation
tree.
Example-
Consider the following grammar-
S → aB / bA
S → aS / bAA / a
B → bS / aBB / b
Let us consider a string w = aaabbabbba
Now, let us derive the string w using rightmost derivation.
Rightmost Derivation-

S → aB
→ aaBB (Using B → aBB)
→ aaBaBB (Using B → aBB)
→ aaBaBbS (Using B → bS)
→ aaBaBbbA (Using S → bA)
→ aaBaBbba (Using A → a)
→ aaBabbba (Using B → b)
→ aaaBBabbba (Using B → aBB)
→ aaaBbabbba (Using B → b)
→ aaabbabbba (Using B → b)

21
Problem-01:
Consider the grammar-
S → bB / aA
A → b / bS / aAA
B → a / aS / bBB
For the string w = bbaababa, find-
1. Leftmost derivation
2. Rightmost derivation
3. Parse Tree

Solution-

1. Leftmost Derivation-

S → bB
→ bbBB (Using B → bBB)
→ bbaB (Using B → a)
→ bbaaS (Using B → aS)
→ bbaabB (Using S → bB)
→ bbaabaS (Using B → aS)
→ bbaababB (Using S → bB)
→ bbaababa (Using B → a)

2. Rightmost Derivation-

S → bB
→ bbBB (Using B → bBB)
→ bbBaS (Using B → aS)
→ bbBabB (Using S → bB)
→ bbBabaS (Using B → aS)
→ bbBababB (Using S → bB)
→ bbBababa (Using B → a)

22
→ bbaababa (Using B → a)

3. Parse Tree-

• Whether we consider the leftmost derivation or rightmost derivation, we get the above
parse tree.

Example

Let any set of production rules in a CFG be

X → X+X | X*X |X| a

over an alphabet {a}.

The leftmost derivation for the string "a+a*a" may be −

X → X+X

→ a+X

→ a + X*X

→ a+a*X

→ a+a*a

23
Generation of Derivation Tree
A derivation tree or parse tree is an ordered rooted tree that graphically represents the
semantic information a string derived from a context-free grammar.

Representation Technique

• Root vertex − Must be labeled by the start symbol.


• Vertex − Labeled by a non-terminal symbol.
• Leaves − Labeled by a terminal symbol or ε.

The stepwise derivation of the string "a+a*a" in form of the parse tree / derivation tree will
be as follows −

The rightmost derivation for the above string "a+a*a" may be −

X → X*X

→ X*a

24
→ X+X*a

→ X+a*a

→ a+a*a

25

You might also like