Unit 2 - Theory of Computation - WWW - Rgpvnotes.in

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

Program : B.

Tech
Subject Name: Theory of Computation
Subject Code: IT-503
Semester: 5th
Downloaded from www.rgpvnotes.in

Department of Information Technology


Subject Notes
IT503 (A) - Theory of Computation
B.Tech, IT-5th Semester

Unit II
Syllabus : Regular grammars, regular expressions, regular sets, closure properties of regular grammars,
Arden’s theorem, Myhill-Nerode theorem, pumping lemma for regular languages, Application of
pumping lemma, applications of finite automata, minimization of FSA.

Unit Objective: Obtain minimized DFA and Application of regular expression and conversion from RE to
Finite Automata and Finite Automata to Regular Expression and Proving language are not regular.

Regular Grammar

Grammar:
A grammar G can be formally written as a 4-tuple (N, T, S, P) where
 N or VN is a set of variables or non-terminal symbols
 T or ∑ is a set of Terminal symbols
 S is a special variable called the Start symbol, S ∈ N
 P is Production rules for Terminals and Non-terminals. A production rule has the form 𝛼 → 𝛽,
where 𝛼 and 𝛽 are strings on 𝑉𝑁∪Σ and least one symbol of 𝛼 belongs to VN.

Derivations from a Grammar:


Strings may be derived from other strings using the productions in a grammar. If a grammar G has a
production α  β, we can say that x α y derives x β y in G. This derivation is written as:
G
𝒙𝜶𝒚⇒𝒙𝜷𝒚
Example:
Let us consider the grammar:
G2 = ({S, A}, {a, b}, S, {S → aAb, aA →aaAb, A→ε})
Some of the strings that can be derived are:
S  aAb using production S  aAb
 aaAbb using production aA  aAb
 aaaAbbb using production aA  aAb
 aaabbb using production A  ε

Language generated by a Grammar:


The set of all strings that can be derived from a grammar is said to be the language generated from
that grammar. A language generated by a grammar G is a subset formally defined by
G
𝐿(𝐺) = { 𝑊 | 𝑊∈Σ∗ , 𝑆⇒𝑊 }
If L(G1) = L(G2), the Grammar G1 is equivalent to the Grammar G2.

Example:
If there is a grammar
G: N = {S, A, B} T = {a, b} P = {S →AB, A →a, B →b}
Here S produces AB, and we can replace A by a, and B by b. Here, the only accepted string is ab, i.e.,

Page no: 1 Get real-time updates from RGPV


Downloaded from www.rgpvnotes.in

L(G) = {ab}

Regular Expression (RE):


Regular expressions are useful for representing certain sets of strings in an algebraic fashion. These
describe the languages accepted by finite state automata.

A Regular Expression can be recursively defined as follows:


1. ε is a Regular Expression indicates the language containing an empty string.(L (ε)= {ε})
2. φ is a Regular Expression denoting an empty language. (L (φ) = { })
3. x is a Regular Expression where L={x}
4. If X is a Regular Expression denoting the language L(X) and Y is a Regular Expression denoting
the language L(Y), then
 X+Y is a Regular Expression corresponding to the language L(X) U L(Y) where L(X+Y) = L(X)
U L(Y).
 X.Y is a Regular Expression corresponding to the language L(X).L(Y) where L(X.Y)= L(X) .
L(Y)
 R* is a Regular Expression corresponding to the language L(R*) where L(R*) = (L(R))*
5. If we apply any of the rules several times from 1 to 5, they are Regular Expressions.

Example:
Regular Expressions Regular Set

(0 + 10*) L = { 0, 1, 10, 100, 1000, 10000, … }

(0*10*) L = {1, 01, 10, 010, 0010, …}

(0 + ε)(1 + ε) L = {ε, 0, 1, 01}

(a+b)* Set of strings of a’s and b’s of any length including the null string. So L = { ε,
a, b, aa , ab , bb , ba, aaa…….}

(a+b)*abb Set of strings of a’s and b’s ending with the string abb. So L = {abb, aabb,
babb, aaabb, ababb, …………..}

Regular Set:
Any set that represents the value of the Regular Expression is called a Regular Set.

Properties of Regular Set:

Page no: 2 Get real-time updates from RGPV


Downloaded from www.rgpvnotes.in

Figure 2.1: Properties of Regular Set

Identities related to Regular Expression:

1. Ø* = ε
2. ε* = ε
3. RR* = R*R
4. R*R* = R*
5. (R*)* = R*
6. RR* = R*R
7. (PQ)*P =P(QP)*
8. (a+b)* = (a*b*)* = (a*+b*)* = (a+b*)* = a*(ba*)*
9. R + Ø = Ø + R = R (The identity for union)
10. Rε = εR = R (The identity for concatenation)
11. ØL = LØ = Ø (The annihilator for concatenation)
12. R + R = R (Idempotent law)
13. L (M + N) = LM + LN (Left distributive law)
14. (M + N) L = LM + LN (Right distributive law)
15. ε + RR* = ε + R*R = R*

Closure properties of Regular Language (RL):


If certain languages are regular then language formed by certain operations is also regular. These is

Page no: 3 Get real-time updates from RGPV


Downloaded from www.rgpvnotes.in

called Closure properties of Regular Language(RL).


 The set of regular languages is closed under the union operation, i.e., if A1 and A2 are regular
languages over the same alphabet Σ, then A1 ∪ A2 is also a regular language.
 The set of regular languages is closed under the concatenation operation, i.e., if A1 and A2 are
regular languages over the same alphabet Σ, then A1 A2 is also a regular language.
 The set of regular languages is closed under the star operation, i.e., if A is a regular language, then
A* is also a regular language.
 The set of regular languages is closed under the complement operation. i.e.,Complement of RL
is regular.
 The set of regular languages is closed under the difference operation i.e., Difference of two RL is
regular.
 The set of regular languages is closed under the reversal operation i.e., Reversal of a RL is
regular.

Arden’s Theorem:
In order to find out a regular expression of a Finite Automaton, we use Arden’s Theorem along with the
properties of regular expressions.
Statement:
Let P and Q be two regular expressions.
If P does not contain null string, then R = Q + RP has a unique solution that is R = QP*
Proof:
R = Q + (Q + RP)P [After putting the value R = Q + RP]
R= Q + QP + RPP
When we put the value of R recursively again and again, we get the following equation:
R = Q + QP + QP2 + QP3…..
R = Q (є + P + P2 + P3 + ….)
R = QP* [As P* represents (є + P + P2 + P3 + ….)]
Hence, proved.

Assumptions for Applying Arden’s Theorem:


1. The transition diagram must not have NULL transitions
2. It must have only one initial state

Myhill-Nerode Theorem:
A language L is regular if and only if RL has a finite number of equivalence classes. Moreover, the
number of states is the smallest DFA recognizing L is equal to the number of equivalence classes of RL.

The following three statements are equivalent


1. The set L є ∑* is accepted by a FSA
2. L is the union of some of the equivalence classes of a right invariant equivalence relation of
finite index.
3. Let equivalence relation RL be defined by :
xRLy if for all z in ∑* xz is in L exactly when yz is in L.
Then RL is of finite index.
Example:-To show L = {anbn |n>=1} is not regular

Page no: 4 Get real-time updates from RGPV


Downloaded from www.rgpvnotes.in

 Assume that L is Regular


 Then by Myhill Nerode theorem we can say that L is the union of sum of the Equivalence classes
and etc
a, aa,aaa,aaaa,……..
 Each of this cannot be in different equivalence classes.
an ~ am for m ≠ n
 By Right invariance
anbn ~ am bn for m ≠ n
 Hence contradiction: The L cannot be regular.

Pumping lemma:
Pumping lemma is tool that can be used to prove that certain languages are not regular. Observe that
for a regular language,
1. The amount of memory that is needed to determine whether or not a given string is the
language is finite and independent of the length of the string, and
2. If the language consists of an infinite number of strings, then this language should contain
infinite subsets having a fairly repetitive structure.
Intuitively, languages that do not follow both point should be non-regular.

Example: Consider the language


{0n 1n: n ≥ 0}.
This language should be non-regular; because it seems unlikely that a DFA can remember how many 0s
it has seen when it has reached the border between the 0s and the 1s. Similarly the language
{0n: n is a prime number}
should be non-regular, because the prime numbers do not seem to have any repetitive structure that
can be used by a DFA.

This property is called the pumping lemma. If a language does not have this property, then it must be
non-regular. The pumping lemma states that any sufficiently long string in a regular language can be
pumped, i.e., there is a section in that string that can be repeated any number of times, so that the
resulting strings are all in the language.

Theorem:
Let L be a regular language. Then there exists a constant ‘c’ such that for every string w in L:
|w| ≥ c
We can break w into three strings, w = xyz, such that:
1. |y| > 0
2. |xy| ≤ c
3. For all k ≥ 0, the string xykz is also in L.

Applications of Pumping Lemma:


Pumping Lemma is to be applied to show that certain languages are not regular. It should never be
used to show a language is regular.
 If L is regular, it satisfies Pumping Lemma.

Page no: 5 Get real-time updates from RGPV


Downloaded from www.rgpvnotes.in

 If L does not satisfy Pumping Lemma, it is non-regular.


Method to prove that a language L is not regular
 At first, we have to assume that L is regular.

 So, the pumping lemma should hold for L.


 Use the pumping lemma to obtain a contradiction −
a) Select w such that |w| ≥ c
b) Select y such that |y| ≥ 1

c) Select x such that |xy| ≤ c


d) Assign the remaining string to z.

e) Select k such that the resulting string is not in L.

Hence L is not regular.


Example: Prove that L = {aibi | i ≥ 0} is not regular.
 At first, we assume that L is regular and n is the number of states.
 Let w = anbn. Thus |w| = 2n ≥ n.
 By pumping lemma, let w = xyz, where |xy| ≤ n.
 Let x = ap, y = aq, and z = arbn, where p + q + r = n, p ≠ 0, q ≠ 0, r ≠ 0. Thus |y| ≠ 0.
 Let k = 2. Then xy2z = apa2qarbn.
 Number of as = (p + 2q + r) = (p + q + r) + q = n + q
 Hence, xy2z = an+q bn. Since q ≠ 0, xy2z is not of the form a nbn.
 Thus, xy2z is not in L. Hence L is not regular.

Application of Finite Automata:

Some of the major applications of finite automata are:

Compiler Design: Lexical Analysis

Special purpose hardware design

Protocol specification

String matching algorithm

Minimization of DFA:

DFA minimization stands for converting a given DFA to its equivalent DFA with minimum number of
states.

If X and Y are two states in a DFA, we can combine these two states into {X, Y} if they are not
distinguishable. Two states are distinguishable, if there is at least one string S, such that one of δ (X, S)

Page no: 6 Get real-time updates from RGPV


Downloaded from www.rgpvnotes.in

and δ (Y, S) is accepting and another is not accepting. Hence, a DFA is minimal if and only if all the
states are distinguishable.

Suppose there is a DFA D < Q, Σ, q0, δ, F > which recognizes a language L. Then the minimized DFA D <
Q’, Σ, q0, δ’, F’ > can be constructed for language L as:
Step 1: We will divide Q (set of states) into two sets. One set will contain all final states and other set
will contain non-final states. This partition is called P0.
Step 2: Initialize k = 1
Step 3: Find Pk by partitioning the different sets of Pk-1. In each set of Pk-1, we will take all possible
pair of states. If two states of a set are distinguishable, we will split the sets into different sets in Pk.
Step 4: Stop when Pk = Pk-1 (No change in partition)
Step 5: All states of one set are merged into one. No. of states in minimized DFA will be equal to no. of
sets in Pk.
Example:
Consider the following DFA

Step 1. P0 will have two sets of states. One set will contain q1, q2, q4 which are final states of DFA and
another set will contain remaining states. So P0 = {{q1, q2, q4}, { q0, q3, q5 } }.
Step 2. To calculate P1, we will check whether sets of partition P0 can be partitioned or not:
i) For set {q1, q2, q4}:
δ ( q1, 0 ) = δ ( q2, 0 ) = q2 and δ ( q1, 1 ) = δ ( q2, 1 ) = q5, So q1 and q2 are not distinguishable.
Similarly, δ (q1, 0) = δ (q4, 0) = q2 and δ ( q1, 1 ) = δ ( q4, 1 ) = q5, So q1 and q4 are not distinguishable.
Since, q1 and q2 are not distinguishable and q1 and q4 are also not distinguishable, So q2 and q4 are
not distinguishable. So, { q1, q2, q4 } set will not be partitioned in P1.
ii) For set { q0, q3, q5 } :
δ ( q0, 0 ) = q3 and δ ( q3, 0 ) = q0
δ ( q0, 1) = q1 and δ( q3, 1 ) = q4
Moves of q0 and q3 on input symbol 0 are q3 and q0 respectively which are in same set in partition P0.
Similarly, Moves of q0 and q3 on input symbol 1 are q3 and q0 which are in same set in partition P0.
So, q0 and q3 are not distinguishable.

Page no: 7 Get real-time updates from RGPV


Downloaded from www.rgpvnotes.in

δ ( q0, 0 ) = q3 and δ ( q5, 0 ) = q5 and δ ( q0, 1 ) = q1 and δ ( q5, 1 ) = q5


Moves of q0 and q5 on input symbol 0 are q3 and q5 respectively which are in different set in partition
P0. So, q0 and q5 are distinguishable. So, set { q0, q3, q5 } will be partitioned into { q0, q3 } and { q5 }.
So,
P1 = { { q1, q2, q4 }, { q0, q3}, { q5 } }
To calculate P2, we will check whether sets of partition P1 can be partitioned or not:
iii) For set { q1, q2, q4 } :
δ ( q1, 0 ) = δ ( q2, 0 ) = q2 and δ ( q1, 1 ) = δ ( q2, 1 ) = q5, So q1 and q2 are not distinguishable.
Similarly, δ ( q1, 0 ) = δ ( q4, 0 ) = q2 and δ ( q1, 1 ) = δ ( q4, 1 ) = q5, So q1 and q4 are not
distinguishable.
Since, q1 and q2 are not distinguishable and q1 and q4 are also not distinguishable, So q2 and q4 are
not distinguishable. So, { q1, q2, q4 } set will not be partitioned in P2.
iv) For set { q0, q3 } :
δ ( q0, 0 ) = q3 and δ ( q3, 0 ) = q0
δ ( q0, 1 ) = q1 and δ ( q3, 1 ) = q4
Moves of q0 and q3 on input symbol 0 are q3 and q0 respectively which are in same set in partition P1.
Similarly, Moves of q0 and q3 on input symbol 1 are q3 and q0 which are in same set in partition P1.
So, q0 and q3 are not distinguishable.
v) For set { q5 }:
Since we have only one state in this set, it can’t be further partitioned. So,
P2 = { { q1, q2, q4 }, { q0, q3 }, { q5 } }
Since, P1=P2. So, this is the final partition. Partition P2 means that q1, q2 and q4 states are merged
into one. Similarly, q0 and q3 are merged into one.
Minimized DFA corresponding to DFA is as below:

Page no: 8 Get real-time updates from RGPV


We hope you find these notes useful.
You can get previous year question papers at
https://qp.rgpvnotes.in .

If you have any queries or you want to submit your


study notes please write us at
[email protected]

You might also like