Flat Unit-Iii
Flat 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)*.
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
Examples:
1. Construct Ɛ-NFA for the regular expression 1+01*
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*
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.
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.
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
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}