0% found this document useful (0 votes)
68 views10 pages

ACD UNIT 2 RegularExpression

Uploaded by

Vamshi Laggani
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)
68 views10 pages

ACD UNIT 2 RegularExpression

Uploaded by

Vamshi Laggani
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/ 10

Formal Languages and Automata Theory

UNIT-III

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.
Learning Outcomes:
Students will be able to:
understand the regular sets and how to represent the regular
expressions.
construct finite Automata for a given regular expression and viceversa.
list closure properties of regular languages.
understand the different applications of regular languages.

Learning Material
Regular set:
A language is a regular set (or just regular) if it is the set accepted by some
finite automaton.
Example:
L= {0, 1, 10, 00, 01, 11, 000, 101, .................} is a regular set representing
any no of 0’s and any no of 1’s.
Regular expression:
The languages accepted by finite automata are easily described by simple
expressions called regular expressions.
an alphabet and the sets that they
denote are defined recursively as follows.
1) Ø is a regular expression and denotes the empty set.
is a regular e }.

II Year –II-Semester 2018-19 CSE


Formal Languages and Automata Theory

3) For eac is a regular expression and denotes the set {a}.


4) If r and s are regular expressions denoting the languages R and S,
respectively, then
(r + s), (rs), and (r*) are regular expressions that denote the sets R U S, RS,
and R*, respectively.

Some Examples on Regular expressions


1.Write regular expressions for each of the following languages over
{0, 1}.

a) The set representing {00}.


00
b) The set representing all strings of 0's and 1's.
(0+1)*
c) The set of all strings representing with at least two consecutive 0’s.
(0 + 1)*00(0 + 1)*
d) The set of all strings ending in 011.
(0 + 1)*011
e) The set of all strings representing any number of 0's followed by any
number of 1’s followed by any number of 2's.
0*1*2*
f) The set of all strings starting with 011.
011 (0 + 1)*
2.Write regular expressions for each of the following languages over
{a, b}.

a) The set of all strings ending with either a or bb.


(a+b)* (a + bb)
b) The set of strings consisting of even no. of a’s followed by odd no. of
b’s.
(aa)*(bb)*b
c) The set of strings representing even number of a’s.
(b* a b* a b*) * + b*

II Year –II-Semester 2018-19 CSE


Formal Languages and Automata Theory

Identity Rules Related to Regular Expressions


Given r, s and t are regular expressions, the following identities hold:
*

r+ = rr* = r*r

r*r* = r*

(r*)* = r*

r+s=s+r

(r + s) + t = r + (s + t)

(rs)t = r(st)

r(s + t) = rs + rt

(r + s)t = rt + st

(r + s)* = (r*s*)* = (r* + s*)* =(r+s*)*

r+ = +r=r

L=L =

r+r=r
* *

Construction of Finite automata for a given regular expression

II Year –II-Semester 2018-19 CSE


Formal Languages and Automata Theory

Equivalence of Finite Automata and Regular Expressions


The languages accepted by finite automata are precisely the
languages denoted by regular expressions.
For every regular expression there is an equivalent NFA with -
transitions.
For every DFA there is a regular expression denoting its language.

Let r be a regular expression. Then there exists an NFA with -


transitions that accept L(r).
Zero operators:
The expression r must be Ø, or a for some a in
operators are

One or more operators:


Let r have i operators. There are three cases depending on the form of r.
Case 1: Union (r = rl + r2.)
There are NFA’s M1 = (Q1, 1, q1, {f1}) and M2=(Q2, 2, q2, {f2})
with L(M1) = L(r1) and L(M2) = L(r2).

Construct
M = (Q1 Q2 {q0, f0}, , , q0, {f0}) where is defined by

i) (q0,

ii) (q, a) = 1(q ,a) for q in Q1-{f1} and a in

iii) (q, a) = 2(q ,a) for q in Q2-{f2} and a in

iv) (f1, { f0 }

II Year –II-Semester 2018-19 CSE


Formal Languages and Automata Theory

L(M) = L(M1) L(M2)

Case 2: Concatenation (r = r1 r2).

Let M1 and M2 be as in Case 1 and construct M = (Q1 Q2, , ,


q1, {f2})

where is defined by

i) (q, a) = 1(q ,a) for q in Q1-{f1} and a in

ii) (f1,

iii) (q, a) = 2(q ,a) for q in Q2 and a in

L(M) ={xy| x is in L(M1) and y is in L(M2)} and L(M) = L(M1)L(M2)

Case 3: Closure (r = r1*)

Let M1 = (Q1, 1, q1, {f1}) and L(M1) = r1.

Construct M = (Q1 {q0,f0}, , , q0, {f0}), where is defined by

i) (q0, (f1,

ii) (q, a) = 1(q ,a) for q in Q1-{f1} and a in

II Year –II-Semester 2018-19 CSE


Formal Languages and Automata Theory

Example:
1. Construct an NFA for the regular expression 01*+1

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


The automaton for r2 is

Express r1 as r3 and r4, where r3=0 and r4= 1*

The automaton for r3 is

r4 is r5* where r5=1

The NFA for r5 is

To construct an NFA for r4 = r5* use the construction of closure. The


resulting NFA for r4 is

II Year –II-Semester 2018-19 CSE


Formal Languages and Automata Theory

Then, for r1 = r3 r4 use the construction of concatenation.

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

Construction of regular expressions for the given finite Automata:


Arden’s Theorem

epsilon, then R=Q+RP has a unique solution R=QP*.


Procedure:
Assume the given finite automata should not contain any epsilons.
Step 1: Find the reachability for each and every state in given Finite
automata.
Reachability of a state is the set of states whose edges enter into that state.
Step 2: For the initial state of finite automata ,add epsilon to the
reachability equation.
Step 3: Solve the equations by using Arden’s Theorem.
Step 4: Substitute the results of each state equation into the final state
equation,to get the regular expression for the given DFA.

II Year –II-Semester 2018-19 CSE


Formal Languages and Automata Theory

Example:
1. Construct regular expression for the given finite automaton.

The given Finite Automata is not having any ’s( epsilons).

Step 1: Find the reachability for each and every state in given Finite
automata.
Reachability of a state is the set of states whose edges enter into that state.
q0=q0 0 1
q1= q0 1 + q10 + q2 1 2
q2= q1 1 + q20 3
Step 2: For the initial state of finite automata, add epsilon to the
reachability equation.
q0=q0 0 +
Step 3: Solve the equations by using Arden’s Theorem.
After applying arden’s theorem for equation 3
q2=q1 10* 4
Substitute equation 4 in equation 2
q1= q0 1 + q10+q1 10*
q1= q0 1 + q1(0+10*) 5
Apply arden’s theorem on equation 5
q1= q01 (0+10*)* 6
Apply arden’s theorem on equation 1
q0=q0 0 +
q0= 0* 7
Substitute equation 7 in equation 6
q1= 0* 1 (0+10*)* 8
Step 4: Substitute the results of each state equation into the final state
equation, to get the regular expression for the given DFA.

II Year –II-Semester 2018-19 CSE


Formal Languages and Automata Theory

q2= 0* 1 (0+10*)* 10*


Therefore, the regular expression for the given DFA is 0* 1 (0+10*)* 10*.

Pumping Lemma for Regular Sets:


Pumping lemma, which is a powerful tool for proving certain
languages non-regular.
It is also useful in the development of algorithms to answer certain
questions concerning finite automata, such as whether the language
accepted by a given FA is finite or infinite.
Lemma
Let L be a regular set. Then there is a constant n such that if z is any word
in L, and |z| > n, we may write z=uvw in such a way that |uv|
and for all i> 0, uviw is in L. Furthermore, n is no greater than the number
of states of the smallest FA accepting L.
Example:
The set L = {0i2 | i is an integer, i ich consists of all strings of
0’s whose length is a perfect square, is not regular.
Assume L is regular and let n be the integer in the pumping lemma.
Let z = 0n2.
By the pumping lemma, 0n2may be written as uvw, where 1
uviw is in L for all i. Let i = 2, n2 < |uv2w| < n2 + n < (n+1)2.
That is, the length of uv2w lies properly between n2 and (n +1)2, and is thus
not a perfect square.
Thus uv2w is not in L, a contradiction.
We conclude that L is not regular.
Closure Properties of Regular Sets:
The regular sets are closed under union, concatenation, and Kleene
closure.
The class of regular sets is closed under complementation. That is, if L
is a regular set and L - L is a regular set.
The regular sets are closed under intersection.
The class of regular sets is closed under substitution.

II Year –II-Semester 2018-19 CSE


Formal Languages and Automata Theory

The class of regular sets is closed under homomorphism and inverse


homomorphism.
The class of regular sets is closed under quotient with arbitrary sets.

II Year –II-Semester 2018-19 CSE

You might also like