0% found this document useful (0 votes)
80 views11 pages

Flat Unit-Iii

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views11 pages

Flat Unit-Iii

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

FORMAL LANGUAGES & AUTOMATA THEORY UNIT III

UNIT – III
REGULAR LANGUAGES
Objective: To familiarize how to employ regular expressions.

Syllabus:
Regular sets, regular expressions, identity rules, construction of finite Automata for a given
regular expressions and its inter conversion, pumping lemma of regular sets, closure
properties of regular sets (proofs not required),applications of regular languages.

Regular Expression:
Regular expressions are useful for representing certain set of strings in an algebraic
fashion. Regular expression describes the language accepted by the finite state machine.
 Any terminal symbol or element of Σ is a regular expression.
Eg:- Ø, ε,a in Σ
o Ø is a regular expression and denotes the empty set.
o ε is a regular expression and denotes the set * ε+
o a is a regular expression which denotes the set {a}
 Union of two regular expressions R1, R2 is a regular expression R1+R2
Eg:- Let a be a regular expression R1, b be a regular expression R2
(a+b) is also a regular expression
 Concatenation of two regular expressions R1,R2 is a regular expression R1.R2
Eg:- Let a and b are two regular expressions then ab is also a regular expression
 Closure of a regular expression R written as R*. It is also a Regular expression.
Regular Set:
Any set represented by a regular expression is called a regular set.
o If a and b are the elements of Σ then regular expression a denotes the set *a+
o a+b denotes the set {a,b}
o ab denotes the set {ab}
o a* denotes the set * ε,a,aa,aaa,aaaa,aaaaaa,…………..+
o (a+b)* denotes the set * ε,a,b,aa,bb,ab,aab,abb,aabb,aaab,abbb,……….+

1. Write the regular expression for all strings of 0’s and 1’s.
The set represented by given language L={ε,0,1,00,11,01,10,010,100,………+
The required regular expression is (0+1)*.
2. Write the regular expression for all strings of 0’s and 1’s end in 00.
The set represented by given language L={ 00,000,100,0000,1100,0100,1000,....}
The required regular expression is (0+1)*00.
3. Write the regular expression for set of all strings 0’s and 1’s begins with 0 and ends
with 1
The set represented by given language L=*01,001,011,0011,00111,01111,……..}
The required regular expression is 0(0+1)*1.
4. Write the regular expression for set of all strings having even number of 1’s Σ={1}
The set represented by given language L={ ε,11,1111,111111,11111111,…….}
The required regular expression is (11)*.

DEPARTMENT OF INFORMATION TECHNOLOGY Page 1


FORMAL LANGUAGES & AUTOMATA THEORY UNIT III
5. Write the regular expression for set of all strings having odd number of 1’s Σ=*1+
The set represented by given language L={ 1,111,11111,1111111,…….}
The required regular expression is 1(11)* or (11)*1.
6. Write the regular expression for set of all strings of 0’s and 1’s with at least two
consecutive 0’s
The set represented by given language L={ 00,000,100,001,0000,0011,…….}
The required regular expression is (0+1)*00(0+1)*.
7. Write a regular expression for all strings 0’s and 1’s beginning with 1 or 0 and not
having two consecutive 0’s.
The set represented by given language L={0,1,10,01,11,101,110,….+
The required regular expression is (0+ ε)(1+10)*.
8. Write a regular expression for set of all strings with at least one 0,one 1 and one 2
respectively .
The set represented by given language L={012,001122,000111222,…….+
The required regular expression is 0+1+2+ or 00*11*22* .
9. Write a regular expression for set of all strings of 0’s and 1’s whose last two symbols
are the same.
The set represented by given language L={00,11,000,111,100,01011,0100,….+
The required regular expression is (0+1)*(00+11).
10. Write a regular expression for set of all strings in which every 0 is immediately
followed by at least two 1’s
The set represented by given language L={ ε,011,1,011011,111 ,….+
The required regular expression is (1+011)*.

Identity Rules for Regular Expression:


a. Ø+R= R+Ø=R
b. εR=Rε=R
c. R+R=R
d. RR*=R*R=R+
e. ε+RR*=R*
f. ØR=RØ=Ø
g. ε*=ε, Ø*=ε
h. (R*)*=R*
i. (PQ)*P=P(QP)*
j. (P+Q)R=PR+QR
k. R(P+Q)=RP+RQ
l. (P+Q)*=(P*Q*)*=(P*+Q*)*
m. (ε+R)*=R*
n. P+Q=Q+P

DEPARTMENT OF INFORMATION TECHNOLOGY Page 2


FORMAL LANGUAGES & AUTOMATA THEORY UNIT III

Equivalence of Finite Automata with Regular Expression


Non-Deterministic Finite
Automata

Deterministic Finite Non-Deterministic Finite


Automata Automata with ε transitions

Regular Expression

Every regular expression there exist a deterministic finite automata. So we can say that
regular languages, regular expression and finite automata are all different representation
of the same thing. Therefore we convert Finite Automata to Regular Expression, Regular
Expression to Finite Automata.
Let r be a regular expression. Then there exists an NFA with ε -transitions that accept L(r).
The expression r must be ε, Ø, or a for some a in Σ. The NFA’s are

a)r=ε b) r= Ø c)r=a

Construction of regular expression into Ɛ-NFA


 Ɛ-transitions provide a convenient way of modeling the system whose states sre not
precisely known
 Ɛ-transitions do not add any extra capacity of recognizing formal languages
 Ɛ-NFA and NFA recognize same class of languages namely regular languages.
 NFA with Ɛ-transitions are defined because certain properties can be move easily
proved on them as compared to NFA.
Let r have i operators. There are three cases depending on the form of r.
Case 1: Union (r = rl + r2.)
L(M) = L(M1) ∪ L(M2)

DEPARTMENT OF INFORMATION TECHNOLOGY Page 3


FORMAL LANGUAGES & AUTOMATA THEORY UNIT III
Case 2: Concatenation (r = r1 r2).
L(M) = L(M1)L(M2)

Case 3: Closure (r = r1*)

Examples:
1. Construct Ɛ-NFA for the regular expression 1+01*

Regular expression is of the form r1 + r2, where r1 =1 and r2 = 01*.


For 1 the regular expression is

For 0 the regular expression is

For 1* the regular expression is

DEPARTMENT OF INFORMATION TECHNOLOGY Page 4


FORMAL LANGUAGES & AUTOMATA THEORY UNIT III

For 01* the regular expression is

Finally, use the construction of union to find the NFA for r = r1 + r2

2. Consider regular expression 10*+01* and construct equivalent NFA.


The given regular expression is 10*+01* and Ɛ=*0,1+
The following is a NFA accepting 1

DEPARTMENT OF INFORMATION TECHNOLOGY Page 5


FORMAL LANGUAGES & AUTOMATA THEORY UNIT III

The following is a NFA accepting 0*

The following is a NFA accepting 10*

The following is a NFA accepting 0

The following is a NFA accepting 1*

The following is a NFA accepting 01*

DEPARTMENT OF INFORMATION TECHNOLOGY Page 6


FORMAL LANGUAGES & AUTOMATA THEORY UNIT III
The following is a NFA accepting 10*+01*

Construction of Regular Expression from Finite Automata:


To convert Finite Automata into regular expression we need to know about Arden’s
Theorem.
Arden’s Theorem:
Let P and Q be two regular expressions over alphabet Σ. If P does not contain ε(null
string) then R=Q+RP has unique solution that is R=QP*
Proof: Put the value of R in the R.H.S
R=Q+(Q+RP)P=Q+QP+QP2
When we put the value of R again and again we get the following equation.
R=Q+(Q+RP)P=Q+QP+QP2 +QP3+………..
R=Q+(Q+RP)P=Q(1+P+P2+P3+………………..
The second part of the product on the L.H.S can be replaced with the Kleene Closure.
So the equation becomes R=QP*

 Construct the regular expression for the following DFA.

A=A0+B0+ ε -----------1
B=B1+A1 -----------2
B=B1+A1 From Arden’s Theorem R=Q+RP then R=QP*
B=A11* -----------3
Substitute 3 in 1
A=A0+A11*0+ ε
A=A(0+11*0)+ ε
A=(0+11*0)* -----------4 From Arden’s Theorem
Substitute 4 in 3
B=(0+11*0)*11*

DEPARTMENT OF INFORMATION TECHNOLOGY Page 7


FORMAL LANGUAGES & AUTOMATA THEORY UNIT III
Required Regular expression is
(0+11*0)*11*

Regular Language:
Regular language is the set of all languages that can be represented by a regular
expression.
Pumping Lemma for Regular Languages:
Theorem: For any regular language L there exists an integer, such that for all x Є L with
|x|>=n there exist u,v,w Є Σ* such that
i) x=uvw
ii) |uv|<=n
iii) |v|>=1
iv) for all k>=0 : uvkw Є L
Proof:-
Let M be a DFA for L taken n be the number of states of M. Take any x Є L with |x|>=n
consider the path in M that corresponds to x. The length of this path is |x|>=n.
Since M has at most n-1 states some state must be visited twice or more in the first n steps of
the path.

Application of Pumping Lemma:


This theorem can be used to prove that certain sets are not regular
Step 1: Assume that L is regular. Let n be the number of states in corresponding finite
automaton.
Step 2: Choose a string w such that |w| >=n. Use pumping lemma to write w=xyz, with
|xy|<=n and |y|>0
Step 3: Find a suitable integer I such that xyz Є L. This contradicts our assumption. Hence L is
not regular.
Example:
Show that L={anbn|n>=0} is not regular.
Step 1: Assume L is regular.
Step 2: Let w=a2b2 Є L for n=2
by using pumping lemma
w=aabb Є L
x=a,y=a,z=bb
pump y
w=a aa bb
again pump y
w=a aaa bb
w=a4b2 Є L
Step 3: There is a contradiction. So our assumption is wrong
Hence L is not regular

DEPARTMENT OF INFORMATION TECHNOLOGY Page 8


FORMAL LANGUAGES & AUTOMATA THEORY UNIT III
Closure Properties of Regular Sets:
Theorem: Closure Properties of regular languages.
Statement: The class of languages accepted by Finite automata is closed under
1. Union
2. Concatenation
3. Kleene Closure
4. Complementation
5. Intersection
6. Difference
7. Reversal
8. Homomorphism
9. Inverse Homomorphism
Theorem 1:
If L1, L2 are two regular languages then so are L1 ∪ L2 , L1L2 and L1*
We can say that family of regular languages is closed under union, concatenation and
Kleene closure.

Proof: if L1, L2 are regular then there exist regular expression r1 and r2 such that L1 = L(r1)
and L2 = L(r2) .
By the definition of r1+r2, r1r2 and r* are regular expression denoting the language L1 ∪ L2
, L1L2 and L1* respectively. Thus closed under union, concatenation and Kleene closure is
immediate.

Theorem 2: If L is regular then complement of L that L’ is also regular. or Set of all regular
languages is closed under complementation.
Proof: To show closure under complementation let M=(Q, Σ, δ,q0,F) be a
DFA that accepts L, then DFA M’=(Q, Σ, δ,q0,Q-F) accepts L’
We can justify that it as if M accepts the language L then some of the states of this FA are
final states and must likely some are not. Let us reverse the final status of each state that is if it
was a final state, make it a non-final state, and if it was a non-final state, make it a final
state. If an input string formally ended in a non-final state, it now ends in a final state and
vice versa. This new machine we have built accepts all input strings that were not accepted
by the original FA and rejects all the input strings that the FA used to accept.
Therefore in machine accepts exactly the language L’. So L’ is also a regular language.

DEPARTMENT OF INFORMATION TECHNOLOGY Page 9


FORMAL LANGUAGES & AUTOMATA THEORY UNIT III
Example: An FA that accepts only the strings aba and abb is shown in below figure, find Fa
for the complement of L’ accepted by every string other than aba and abb

To find the complement of the given DFA make all non-final states as final and final as non-
final.

Theorem 3: If L1 and L2 are regular languages, then L1 ∩ L2 is also regular. or The set of
regular languages are closed under intersection.
Proof: By DeMorgon 's law for sets of any kind
L1 ∩ L2=(L1'+L2')'
L1 and L2 are regular so L1' and L2' are regular from theorem 2
So L1'+L2'is also regular from theorem 1
Therefore (L1'+L2')' is also regular from theorem 2
Which means L1 ∩ L2 is also regular

Theorem 4: If L1 and L2 are regular languages, then L1 - L2 is also regular.


Proof: L1 - L2= L1 ∩ L2'. Here L2' is also regular since L2 is regular.
and L1 ∩ L2' is also regular from theorem 3
Therefore L1 - L2 is regular
Reversal: The reversal of string a1a2a3a4.....an is the string written backwards, that is an an-1
an-2............ a3 a2 a1. We use Wr for the reversal of string W.
Example: 1010 is the reversal of 0101
Example: Let L be defined the regular expression (0+1)0* then find L R
L=(0+1)0*
Solution: L =(0*)R(0+1)R
R

DEPARTMENT OF INFORMATION TECHNOLOGY Page 10


FORMAL LANGUAGES & AUTOMATA THEORY UNIT III

Homomorphism: A String homomorphism is a function on strings that works by


substituting a particular string for each symbol.
Suppose Σ and Σ' are alphabets. Then function h: Σ--> Σ' is called a "homomorphism". In
other words, a homomorphism is a substitution in which a single letter is replaced with a
string. The domain of the function h is extended to string in an obvious fashion if
w=x1x2......xn then h(w)= h(x1) h(x2) h(x3)............. h(xn)
If L is a language on Σ, then its homomorphic image is defined as
h(L)={h(w):w ∈ L}

Example: Let Σ={0,1} and Σ'={0,1,2} and defined n by h(0)=01 ,h(1)=112 then find h(010)
and hommorphic image of {00,010}
Solution : Given Σ={0,1} , Σ'={0,1,2}
h is defined as h(0)=01,h(1)=112
So H(010)=0111201
The homomorphic image of L={00,010} is the language h(L)={0101,0111201}

DEPARTMENT OF INFORMATION TECHNOLOGY Page 11

You might also like