0% found this document useful (0 votes)
61 views53 pages

Unit 2

unit 1

Uploaded by

ashokkumar.aa361
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)
61 views53 pages

Unit 2

unit 1

Uploaded by

ashokkumar.aa361
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/ 53

Unit 2

Regular Expression

o The language accepted by finite automata can be easily described by simple expressions called Regular
Expressions. It is the most effective way to represent any language.
o The languages accepted by some regular expression are referred to as Regular languages.
o A regular expression can also be described as a sequence of pattern that defines a string.
o Regular expressions are used to match character combinations in strings. String searching algorithm used this
pattern to find the operations on a string.

For instance:

In a regular expression, x* means zero or more occurrence of x. It can generate {e, x, xx, xxx, xxxx, .....}

In a regular expression, x+ means one or more occurrence of x. It can generate {x, xx, xxx, xxxx, .....}

Operations on Regular Language

The various operations on regular language are:

Union: If L and M are two regular languages then their union L U M is also a regular language.

1. 1. L U M = {s | s is in L or s is in M}

Intersection: If L and M are two regular languages then their intersection is also a regular language.

1. 1. L ∩ M = {st | s is in L and t is in M}

Kleen closure: If L is a regular language then its Kleen closure L1* will also be a regular language.

1. 1. L* = Zero or more occurrence of language L.

Example 1:

Write the regular expression for the language accepting all combinations of a's, over the set ∑ = {a}

Solution:

All combinations of a's means a may be zero, single, double and so on. If a is appearing zero times, that means a
null string. That is we expect the set of {ε, a, aa, aaa, ....}. So we give a regular expression for this as:

1. R = a*

That is Kleen closure of a.


Example 2:

Write the regular expression for the language accepting all combinations of a's except the null string, over the set
∑ = {a}

Solution:

The regular expression has to be built for the language

1. L = {a, aa, aaa, ....}

This set indicates that there is no null string. So we can denote regular expression as:

R = a+

Example 3:

Write the regular expression for the language accepting all the string containing any number of a's and b's.

Solution:

The regular expression will be:

1. r.e. = (a + b)*

This will give the set as L = {ε, a, aa, b, bb, ab, ba, aba, bab, .....}, any combination of a and b.

The (a + b)* shows any combination with a and b even a null string.

Examples of Regular Expression


Example 1:

Write the regular expression for the language accepting all the string which are starting with 1 and ending with 0,
over ∑ = {0, 1}.

Solution:

In a regular expression, the first symbol should be 1, and the last symbol should be 0. The r.e. is as follows:

1. R = 1 (0+1)* 0
Example 2:
Write the regular expression for the language starting and ending with a and having any having any
combination of b's in between.

Solution:

The regular expression will be:

1. R = a b* a

Example 3:

Write the regular expression for the language starting with a but not having consecutive b's.

Solution: The regular expression has to be built for the language:

1. L = {a, aba, aab, aba, aaa, abab, .....}

The regular expression for the above language is:

1. R = {a + ab}*

Example 4:

Write the regular expression for the language accepting all the string in which any number of a's is followed
by any number of b's is followed by any number of c's.

Solution: As we know, any number of a's means a* any number of b's means b*, any number of c's means c*.
Since as given in problem statement, b's appear after a's and c's appear after b's. So the regular expression
could be:

1. R = a* b* c*

Example 5:

Write the regular expression for the language over ∑ = {0} having even length of the string.

Solution:

The regular expression has to be built for the language:

1. L = {ε, 00, 0000, 000000, ......}

The regular expression for the above language is:

1. R = (00)*
Example 6:

Write the regular expression for the language having a string which should have atleast one 0 and alteast one 1.

Solution:

The regular expression will be:

1. R = [(0 + 1)* 0 (0 + 1)* 1 (0 + 1)*]

Example 7:

Describe the language denoted by following regular expression

1. r.e. = (b* (aaa)* b*)*

Solution:

The language can be predicted from the regular expression by finding the meaning of it. We will first split the regular
expression as:

r.e. = (any combination of b's) (aaa)* (any combination of b's)

L = {The language consists of the string in which a's appear triples, there is no restriction on the number of b's}

Example 8:

Write the regular expression for the language L over ∑ = {0, 1} such that all the string do not contain the substring
01.

Solution:

The Language is as follows:

1. L = {ε, 0, 1, 00, 11, 10, 100, .....}

The regular expression for the above language is as follows:

1. R = (1* 0*)

Example 9:

Write the regular expression for the language containing the string over {0, 1} in which there are at least two
occurrences of 1's between any two occurrences of 1's between any two occurrences of 0's.

Solution: At least two 1's between two occurrences of 0's can be denoted by (0111*0)*.

Similarly, if there is no occurrence of 0's, then any number of 1's are also allowed. Hence the r.e. for required
language is:

1. R = (1 + (0111*0))*
Example 10:

Write the regular expression for the language containing the string in which every 0 is immediately followed by 11.

Solution:

The regular expectation will be:

1. R = (011 + 1)*

Transition Diagram
A transition diagram or state transition diagram is a directed graph which can be constructed as follows:

o There is a node for each state in Q, which is represented by the circle.


o There is a directed edge from node q to node p labeled a if δ(q, a) = p.
o In the start state, there is an arrow with no source.
o Accepting states or final states are indicating by a double circle.

Some Notations that are used in the transition diagram:


There is a description of how a DFA operates:

1. In DFA, the input to the automata can be any string. Now, put a pointer to the start state q and read the input
string w from left to right and move the pointer according to the transition function, δ. We can read one
symbol at a time. If the next symbol of string w is a and the pointer is on state p, move the pointer to δ(p, a).
When the end of the input string w is encountered, then the pointer is on some state F.

2. The string w is said to be accepted by the DFA if r ∈ F that means the input string w is processed successfully
and the automata reached its final state. The string is said to be rejected by DFA if r ∉ F.

Kleen’s Theorem

A language is said to be regular if it can be represented by using a Finite Automata or if a Regular Expression can
be generated for it. This definition leads us to the general definition that; For every Regular Expression
corresponding to the language, a Finite Automata can be generated. For certain expressions like :- (a+b), ab, (a+b)*
; It’s fairly easier to make the Finite Automata by just intuition as shown below. The problem arises when we are
provided with a longer Regular Expression. This brings about the need for a systematic approach towards FA
generation, which has been put forward by Kleene in Kleene’s Theorem – I Kleene’s Theorem-I :

For any Regular Expression r that represents Language L(r), there is a Finite Automata that accepts same
language.
Arden's Theorem

Arden’s theorem state that: “If P and Q are two regular expressions over “∑”, and if P does not contain “∈ ” , then
the following equation in R given by R = Q + RP has a unique solution i.e., R = QP*.” That means, whenever we get
any equation in the form of R = Q + RP, then we can directly replace it with R = QP*. So, here we will first prove
that R = QP* is the solution of this equation and then prove that it is the unique solution of this equation.
1. proof R = QP* is the solution of R = Q + RP

R = Q + RP ......(i)

Now, replacing R by R = QP*, we get,

R = Q + QP*P

Taking Q as common,

R = Q( ∈ + P*P) = QP*
(As we know that ∈ + R*R = R*). Hence proved. Thus, R = QP* is the solution of the equation R = Q
+ RP. Now, we have to prove that this is the only solution to this equation.

2. proof R = QP* is the unique solution of R = Q + RP

Let me take this equation again:

R = Q + RP

Now, replace R by R = Q + RP,

R = Q + (Q + RP)P

= Q + QP + RP2

Again, replace R by R = Q + RP :-

R = Q + QP + (Q + RP) P2

= Q + QP + QP2 + RP3

. ……

= Q + QP + QP2 + .. + QPn + RP(n+1)

Now, replace R by R = QP*, we get,

R = Q + QP + QP2 + .. + QPn+ QP*P(n+1)

Taking Q as common,

R = Q( ∈ + P + P2 + .. + Pn + P*P(n+1) = QP* [As ∈ + P + P2 + .. + Pn + P*P(n+1) represent the closure of P]

Hence proved. Thus, R = QP* is the unique solution of the equation R = Q + RP.
Note : Arden’s theorem is used to convert given finite automata to a regular expression.
Principal Closure Properties
of Regular Languages
1. The union of two regular languages is regular.

2. The concatenation of regular languages is regular.

3. The closure (star) of a regular language is regular.

4. The complement of a regular language is regular.

5. The intersection of two regular languages is regular.

6. The difference of two regular languages is regular.

7. The reversal of a regular language is regular.

8. A homomorphism (substitution of strings for symbols) of a regular language is


regular.

9. The inverse homomorphism of a regular language is regular.

BBM401 Automata Theory and Formal Languages 28


Union of Two Regular Languages is Regular
Theorem: (closure under union)
If L and M are regular languages, then L∪M is regular.

Proof:
• Since L and M are regular, they have regular expressions; say L = L(R) and M = L(S).
• Then L∪M = L(R+S) by the definition of the + operator for regular expressions.
• Thus, L∪M is regular.

BBM401 Automata Theory and Formal Languages 29


Concatenation of Regular Languages is Regular
Theorem: (closure under concetanation)
If L and M are regular languages, then LM is regular.

Proof:
• Since L and M are regular, they have regular expressions; say L=L(R) and M=L(S).
• Then LM=L(RS) by the definition of the concatenation operator for regular
expressions.
• Thus, LM is regular

BBM401 Automata Theory and Formal Languages 30


Closure of a Regular Language is Regular
Theorem: (closure under star)
If L is a regular language, then L* is regular.

Proof:
• Since L is regular, it has a regular expression; say L=L(R).
• Then L*=L(R*) by the definition of the closure operator for regular expressions.
• Thus, L* is regular.

BBM401 Automata Theory and Formal Languages 31


Complement of a Regular Language is Regular
Theorem: (closure under complement)
If L is a regular language over alphabet , then its complement 𝐋=
ҧ *-L is also a
regular language.

Proof:
• Let L=L(A) for some DFA A = (Q, , , q0, F).
• Then Lത =L(B), where B is the DFA = (Q, , , q0, Q-F).
• That is, B is exactly like A, but the accepting states of A have become non-accepting
states of B, and vice versa.
෠ 0,w) in Q-F, which occurs if and only if w is not
• Then, w is in L(B) if and only if δ(q
in L(A).
• Thus, Lത is regular.

BBM401 Automata Theory and Formal Languages 32


Closure Under Complement - Example

L=L(A) : strings of 0's and l’s


that end in 01;
In regular-expression terms,
L(A) = L((0+l)*01).

L=L(A) : strings of 0's and l’s


that do not end in 01;

BBM401 Automata Theory and Formal Languages 33


Intersection of Two Regular Languages is Regular
Theorem: (closure under intersection)
If L and M are regular languages, then L∩M is regular.

Proof: (Simple Proof)


• By DeMorgan’s law L∩M = Lത ∪ M.

• We already know that regular languages are closed under complement and union.
• So, L∩M is regular when L and M are regular.

BBM401 Automata Theory and Formal Languages 34


Closure Under Intersection
DFA Construction Proof
Theorem: (closure under intersection)
If L and M are regular languages, then L∩M is regular.

Proof: (DFA Construction Proof)


• Let L be the language of DFA AL = (QL, , L, qL, FL) and M be the language of
DFA AM = (QM, , M, qM, FM).
• We will construct an automaton that simulates AL and AM in parallel, and accepts if
and only if both AL and AM accept.
• If AL goes from state p to state s on reading a, and AM goes from state q to state t on
reading a, then ALM will go from state (p,q) to state (s,t) on reading a.
• Formally, ALM = (QLxQM, , LM, (qL,qM), FLxFM) where
LM((p,q),a) = (L(p,a),M(q,a))

BBM401 Automata Theory and Formal Languages 35


Closure Under Intersection
DFA Construction Proof (cont.)
• By induction |w|, it can be shown that
δ෠ LM((qL,qM),w) = (δ෠ L(qL,w), δ෠ M(qM,w))

• To see why L(ALM) = L(AL)∩L(AM), first we can observe that an induction on |w|
proves that δ෠ LM((qL,qM),w) = (δ෠ L(qL,w), δ෠ M(qM,w)).

• But ALM accepts w if and only if δ෠ LM((qL,qM),w) is a pair of accepting states.

• That is, δ෠ L(qL,w) must be in FL and δ෠ M(qM,w) must be in FM.

• w is accepted by ALM if and only if both AL and AM accept w.

• Thus, ALM accepts the intersection of L(AL) and L(AM).

BBM401 Automata Theory and Formal Languages 36


Closure Under Intersection
Product Construction -- Example

DFA AL

DFA AM

• DFA ALM is the cross product of AL and AM. DFA ALM

• L(ALM) = L(AL)∩L(AM).
• L(AL) is the set of strings containing at least one 0.
• L(AM) is the set of strings containing at least one 1.
• L(ALM) is the set of strings containing at least one 0 and one 1.

BBM401 Automata Theory and Formal Languages 37


Difference of Two Regular Languages is Regular
Theorem: (closure under difference)
If L and M are regular languages, then L-M is regular.

Proof:

• We can observe that L - M = L ∩ M.
ഥ is regular.
• By closure under complement, M
ഥ is regular.
• By closure under intersection, L ∩ M
• Thus, L-M is regular.

BBM401 Automata Theory and Formal Languages 38


Reversal of a Regular Language is Regular
• The reversal of a string a1a2 ... an is the string written backwards, that is, anan-1 ... a1.

• We use wR for the reversal of string w.


– Thus, 0010R is 0100, and
– R = .

• The reversal of a language L, written LR is the language consisting of the reversals of


all its strings.
– For instance, if L={001,10,111}, then LR ={100,01,111}.

• Reversal is another operation that preserves regular languages; that is, if L is a regular
language, so is LR.

BBM401 Automata Theory and Formal Languages 39


Reversal of a Regular Language is Regular
Theorem: (closure under reversal)
If L is a regular language, then its reversal LR is regular.

Proof: (proof by automaton creation)


• Let L be recognized by a Finite Automaton A.
• Turn A into a FA for LR, by
1. Reverse all the arcs in the transition diagram for A,
2. Make the start state of A be the only accepting state for the new automaton.
3. Create a new start state p0 with transitions on  to all the accepting states of A.
• The result is an automaton that, simulates A "in reverse" and therefore accepts a string
w if and only if A accepts wR.

BBM401 Automata Theory and Formal Languages 40


Closure Under Reversal
Induction Proof on Regular Expressions
Theorem: (closure under reversal)
If L is a regular language, then its reversal LR is regular.

Proof: (induction proof on regular expressions)


• Assume L is defined by regular expression E.
• The proof is a structural induction on the size of E.
• We can show that there is another regular expression ER such that L(ER) = (L(E))R;
that is, the language of ER is the reversal of the language of E.

BBM401 Automata Theory and Formal Languages 41


Closure Under Reversal
Induction Proof on Regular Expressions (cont.)
BASIS:
• If E is , , or a, for some symbol a, then ER is the same as E.
• We know {}R = {}, R = , and {a}R = {a}.

INDUCTION:
• There are three cases, depending on the form of E.

Case 1. E = F + G  ER = FR + GR
• The reversal of the union of two languages is obtained by computing the reversals of
the two languages and taking the union of those languages.
• So, L(FR+GR ) = (L(F+G))R

BBM401 Automata Theory and Formal Languages 42


Closure Under Reversal
Induction Proof on Regular Expressions (cont.)
Case 2. E = F G  ER = GR FR
• We reverse the order of the two languages, as well as reversing the languages
themselves.
– For instance, if L(F)={01,111} and L(G)={00,10}, then L(FG) =
{0100,0110,11100,111100}.
– Its reversal is {0010,0110,00111,01111}
– If we concatenate the reversals of L(G) and L(F) in that order, we get
{00,01}{10,111} = {0010,00111,0110,01111} which is the same language as
(L(FG))R .
• In general, if a word w in L(E) is the concatenation of x from L(F) and y from L(G),
then wR = yR xR
• So, L(GRFR ) = (L(FG))R

BBM401 Automata Theory and Formal Languages 43


Closure Under Reversal
Induction Proof on Regular Expressions (cont.)
Case 3. E = F*  ER = (FR )*
• Let w be a string in L(F*) that can be written as w1w2 … wn, where each wi is in L(F).
• Then, wR = wnR wn-1R … w1R
• Since each wiR is in L(FR), wR is in L((FR )*)
• This means that “if w is in L(F*), then wR is L((FR)*)”
• Conversly, let w be a string in L((FR)*) that can be written as w1w2 ... wn, where each
wi is the reversal of a string L(F).
• Since each wiR is in L(F), wR is in L(F*)
• This means that “if w is in L((FR)*), then wR is L(F*)”
• Thus, w is in L(F*) if and only if wR is L((FR)*)
• L((FR)*) = (L(F*))R

BBM401 Automata Theory and Formal Languages 44


Closure Under Reversal -- Example
• Let M be L((0+1)0*)

• Then MR (ie (L((0+1)0*)) R ) can be found as follows:

MR = ( L((0+1)0*) ) R
= L( ((0+1)0*)) R )
= L( (0*)R(0+1)R )
= L( (0R)* (0R+1R) )
= L( 0*(0+1) )

BBM401 Automata Theory and Formal Languages 45


Homomorphism of a Regular Language is Regular
• A homomorphism on an alphabet is a function h that gives a string for each symbol
in that alphabet.
– Suppose  and  are alphabets, the function h: →* is called a
homomorphism.

• Extend to strings by h(a1…an) = h(a1)…h(an).


• Extend to languages h(L) = { h(w) | w∈L }

Example:
• h(0) = ab; h(1) = ε.
• h(01010) = ababab.
• h({010110, 11, 1001}) = {ababab, ε, abab}

BBM401 Automata Theory and Formal Languages 46


Homomorphism of a Regular Language is Regular
Theorem: (closure under homomorphism )
If L is a regular language and h is a homomorphism on its alphabet,
then h(L)={ h(w) | win L } is regular.

Proof:
• Let E be a regular expression for L.
• Apply h to each symbol in E.
• Language of the resulting regular expression is h(L).
• Thus, h(L) is regular.

BBM401 Automata Theory and Formal Languages 47


Closure Under Homomorphism -- Example
• Let h(0) = ab; h(1) = ε.
• Let L be the language of regular expression 01* + 10*.
• Then h(L) is the language of regular expression ab(ε)* + ε(ab)*.
ab(ε)* + ε(ab)* = ab + (ab)* = (ab)*

BBM401 Automata Theory and Formal Languages 48


Decision Properties of Regular Languages

BBM401 Automata Theory and Formal Languages 49


Decision Properties of Regular Languages
• A decision property for a class of languages is an algorithm that takes a formal
description of a language (e.g., a DFA) and tells whether or not some property holds.

• Some Decision Properties:


– Is language L empty?
– Is language L finite?

BBM401 Automata Theory and Formal Languages 50


Decision Properties of Regular Languages
language is empty or not

Theorem: There exist algorithms for determining whether a regular language is


empty or not.

Proof:
• Represent the language with a DFA.
• If there is a path from the start state to some final state, the language is not empty.

BBM401 Automata Theory and Formal Languages 51


Decision Properties of Regular Languages
language is finite or infinite
Theorem: There exist algorithms for determining whether a regular language is
finite or infinite.
Proof:
• Represent the language with a DFA.
• Find all states that form a cycle.
• If any of these cycle states are on path from the start state to a final state, then the
language is infinite.

Key idea:
• If the DFA has n states, and the language contains any string of length n or more,
then the language is infinite.
• Otherwise, the language is surely finite. Limited to strings of length n or less.

BBM401 Automata Theory and Formal Languages 52


More Decision Problems
• To decide if L1  L2, check if L1 - L2 = ϕ

• To decide if  ∊ L, check if q0 ∊ F

• To decide if L contains a string w such that w = wR


– Let M be the DFA for L.
– Construct MR.
– Construct M ∩ MR using the cross-product construction
– Check if L(M ∩ MR ) ≠ ϕ.

BBM401 Automata Theory and Formal Languages 53


The Pumping Lemma for Regular Languages

BBM401 Automata Theory and Formal Languages 54


The Pumping Lemma
for Regular Languages
• There are languages which are NOT regular.

• Every regular language satisfies the pumping lemma.

• A non-regular language can be shown that it is NOT regular using the pumping
lemma.

• L01 = {0n1n | n ≥ 1 } is not regular.


– We can use the pumping lemma to show that this language is not regular.

BBM401 Automata Theory and Formal Languages 55


The Pumping Lemma
for Regular Languages
• Let L be a regular language.
• Then there exists a constant n such that for every string w in L such
that |w| > n, we can break w into three strings, w = xyz, such that:
1. y  , ie. |y|>0 Number of states of
DFA for L
2. |xy| ≤ n
3. For all k ≥ 0, the string xykz is also in L.
• That is, we can always find a nonempty string y not too far from the
beginning of w that can be "pumped"; that is, repeating y any
number of times, or deleting it (the case k= 0), keeps the resulting
string in the language L.

BBM401 Automata Theory and Formal Languages 56


The Pumping Lemma - Proof
Proof:
• Suppose L is regular
• Then L is recognized by some DFA A with n states, and L= L(A).
• Let a string w=a1a2...am  L, where m>n
෠ 0, a1a2...ai)
• Let pi = δ(q
• Then, there exists j such that i<j and pi = pj
• Now we have w=xyz where
1. x = a1a2...ai
2. y = ai+1ai+2...aj
3. z = aj+1aj+2...am

BBM401 Automata Theory and Formal Languages 57


The Pumping Lemma – Proof (cont.)
• That is, x takes us to pi, once; y takes us from pi back to pi. (since pi is also pj),
and z is the balance of w.
• So we have the following figure, and every string longer than the number of states
must cause a state to repeat.

• Since y can repeat 0 or more times


 xykz  L for any k0. Q.E.D.

BBM401 Automata Theory and Formal Languages 58


Applications of The Pumping Lemma
• Every regular language satisfies the pumping lemma.

• A non-regular language can be shown that it is NOT regular using the pumping
lemma.

• L01 = {0n1n | n ≥ 1 } is not regular.


– We can use the pumping lemma to show that this language is not regular.

BBM401 Automata Theory and Formal Languages 59


Using the Pumping Lemma
• In order to show that a language L is NOT a regular language using the Pumping
Lemma (Proof by Contradiction):
1. Suppose L were a regular language.
2. Then there is an integer n given us by the pumping lemma, which we do not
know, we must plan for any possible n.
3. Pick a string w which must be in L, it must be defined using n and |w|>n.
• Tricky Part 1: You should find a string w so that you can create a contradiction
in step 5. YOU CANNOT SELECT A SPECIFIC STRING.
4. Break w into xyz, subject only to the constraints that |xy|n and y.
5. Pick i and show that xyiz is NOT in L in order to create a contradiction.
• Tricky Part 2: You have to show that xyiz is NOT in L using only the constraints
that |xy|n and y. You may need to look at more than one cases. YOU
CANNOT GIVE A SPECIFIC EXAMPLE.
6. Conclude that L is NOT a regular language (proof by contradiction).

BBM401 Automata Theory and Formal Languages 60


Applications of The Pumping Lemma – Example 1
Example 1: Let us show that the language L01 = {0n1n | n ≥ 1 } is NOT regular.
Proof: (proof by contradiction)
• Suppose L01 were a regular language (our assumption)
• Then, w = 0n1n  L01 for any n
• By the pumping lemma, w=xyz, |xy|≤n, y and xykz  L01.

• Since y and |xy| ≤n, y must contain only one or more 0s.
• If y repeats 0 times, xy0z=xz must be in L01 by the pumping lemma.
• xz has fewer 0’s than 1’s because y can only contain one or more 0s
• So, there is a contradiction with our assumption (L01 is regular)
• Proof by contradiction, we prove that L01 is NOT regular

BBM401 Automata Theory and Formal Languages 61


Applications of The Pumping Lemma – Example 2
Example 2: Let us show that the language Leq is the set of all strings with an equal
number of 0's and l's is NOT a regular language.

Proof: (proof by contradiction)


• The proof is exactly same as the proof of L01.

BBM401 Automata Theory and Formal Languages 62


Applications of The Pumping Lemma – Example 3
Example 3: Let us show that the language Lpr is the set of all strings of l's whose length
is a prime is NOT a regular language.
Proof: (proof by contradiction)
• Suppose Lpr were a regular language (our assumption)
• Choose a prime p≥n+2 (this is possible since there are infinite number of primes.)

• Now, xyp-mz  Lpr by the pumping lemma.


• |xyp-mz| = |xz| + (p-m)|y| = (p-m)+(p-m)m = (1+m)(p-m)
• But, (1+m)(p-m) is not prime unless one of the factors is 1.
– y  (1+m) > 1
– m=|y| ≤ |xy| ≤ n and p≥n+2  (p-m) ≥ (n+2)-n ≥ 2
• So, there is a contradiction with our assumption
 Proof by contradiction, Lpr is NOT regular.
BBM401 Automata Theory and Formal Languages 63
Applications of The Pumping Lemma – Example 4
Example 4: Let us show that the language L is the set of all strings with the number of 0's
is more the number of l's is NOT a regular language.
Proof: (proof by contradiction)
• Suppose L were a regular language (our assumption)
• Then, w=0n+11n  L for any n since n+1>n
• By the pumping lemma, w=xyz, |xy|≤n, y and xykz  L.
w = 000 … 00111…11
x y z
• Since 0≤|xy|≤n, y must contain only 0’s.
• By the pumping lemma, xy0z  L. But the number of 0’s cannot be more than the
number 1’s because 0<|y|≤n and y must contain only 0’s.
• So, there is a contradiction with our assumption (L is regular)
• Proof by contradiction, we prove that L is NOT regular

BBM401 Automata Theory and Formal Languages 64


Applications of The Pumping Lemma – Example 5
Example 5: Show that the language L is the set of all strings of 0’s and 1’s that have an
unequal number of 0’s and 1’s is NOT regular.

Proof: (proof by contradiction)


• It would be hard to use the pumping lemma directly to show that L is not regular. We
can use closure properties of regular languages in addition to the pumping lemma in
order to prove.
• Suppose that L were regular (our assumption)
• The complement of this language Lത is the set of all strings of 0’s and 1’s that have
equal number of 0’s and 1’s.
• By the closure under complement theorem, Lത must be regular.
• But, we showed that Lത is NOT regular previously using the pumping lemma.
• So, there is a contradiction with our assumption (L is regular)
• Proof by contradiction, we prove that L is NOT regular

BBM401 Automata Theory and Formal Languages 65


Properties of Regular Languages – Summary
Minimizing Deterministic Finite Automata:
• We can partition states of any DFA into groups of mutually indistinguishable states.
• Members of two different groups are always distinguishable.
• If we replace each group by a single state we get an equivalent DFA that has as few
states as any DFA for the same language.

Testing Distinguishability of States:


• Two states of a DFA are distinguishable if there is an input string that takes exactly
one of the two states to an accepting state.
• By starting with only the fact that pairs consisting of one accepting and one non-
accepting state are distinguishable and trying to discover additional pairs of
distinguishable states by finding pairs whose successors on one input symbol are
distinguishable we can discover all pairs of distinguishable states.

BBM401 Automata Theory and Formal Languages 66


Properties of Regular Languages – Summary
Closure Properties of Regular Languages:
• There are many operations that preserve the property of being a regular language.
• Among these are union, concatenation, closure, intersection, complement, difference,
reversal, homomorphism.

Decision Properties of Regular Languages:


• Testing emptiness of regular languages
• Testing whether a regular language is finite or not.

The Pumping Lemma for Regular Languages:


• If a language is regular then every sufficiently long string in the language has a
nonempty substring that can be pumped that is repeated any number of times while
the resulting strings are also in the language.
• This fact can be used to prove that many different languages are not regular.

BBM401 Automata Theory and Formal Languages 67


The Pigeonhole Principle
If n pigeonholes are occupied by n+1 or more pigeons, then at least one pigeonhole is occupied by greater than one
pigeon. Generalized pigeonhole principle is: - If n pigeonholes are occupied by kn+1 or more pigeons, where k is a
positive integer, then at least one pigeonhole is occupied by k+1 or more pigeons.

Example1: Find the minimum number of students in a class to be sure that three of them are born in the same month.

Solution: Here n = 12 months are the Pigeonholes

And k + 1 = 3

K=2

Example2: Show that at least two people must have their birthday in the same month if 13 people are assembled in a
room.

Solution: We assigned each person the month of the year on which he was born. Since there are 12 months in a year.

So, according to the pigeonhole principle, there must be at least two people assigned to the same month.

Regular Expression Regular Languages

set of vovels (a∪ e∪ i∪ o∪ u) {a, e, i, o, u}

a followed by 0 or more b (a.b*) {a, ab, abb, abbb, abbbb,….}

any no. of vowels followed by v*.c* ( where v – vowels { ε , a ,aou, aiou, b, abcd…..} where ε represent
any no. of consonants and c – consonants) empty string (in case 0 vowels and o consonants )

Transition Table in Automata


Transition Table :
Transition function(∂) is a function which maps Q * ∑ into Q . Here ‘Q’ is set of states and ‘∑’ is input of
alphabets. To show this transition function we use table called transition table. The table takes two values a
state and a symbol and returns next state.
A transition table gives the information about –
1. Rows represent different states.
2. Columns represent input symbols.
3. Entries represent the different next state.
4. The final state is represented by a star or double circle.
5. The start state is always denoted by an small arrow.
Example 1 –
This example shows transition table for NFA(non-deterministic finite automata) .
Explanation of above table –
1. First column indicates all the present states ,Next for input 0 and 1 respectively.
2. When the present state is q0, for input 0 the next state will become q0. For input 1 the next state is q1.
3. When the present state is q1, for input 0 the next state is q1 or q2, and for 1 input the next state is q2.
4. When the current state is q2 for input 0, the next state will become q1, and for 1 input the next state will
become Nil.
5. The small straight arrow on q0 indicates that it is a start state and circle on to q3 indicates that it is a final
state.
Example 2 –
This example shows transition table of DFA(deterministic finite automata).

Explanation of above table –


1. First column indicates all the present states, Next for input 0 and 1 respectively.
2. When the current state is q0, for input 0 the next state will become q1 and for input as 1 the next state is
q1.
3. When the current state is q1, for input 0, the next state will become q1, and on 1 input the next state is q1.
4. The small straight arrow on q0 indicates that it is a start state and circle on to q3 indicates that it is a final
state.
Example 3 –
This example shows transition table of DFA(deterministic finite automata)
Explanation of above table –
1. First column indicates all the present states, Next for input 0 and 1 respectively.
2. When the current/present state is q0, for input 0 the next state will become q0 and for input 1 the next
state is q1.
3. When the current state is q1, on input 0, the next state will become q2, and for 1 input the next state is q1.
4. When the current state is q2 for input 0, the next state will become q0, and for 1 input the next state is q1.
5. The small straight arrow on q0 indicates that it is a start state and circle on to q3 indicates that it is a final
state.
Example 4 –
This example shows transition table for NFA(non-deterministic finite automata).

Explanation of above table –


1. First column indicates all present states, next for input 0 and 1 respectively.
2. When the current state is q0, for input 0 next state will become q0 or q1 and for input 1 the next state is q0
or q2.
3. When the current state is q1, for input 0 next state will become q3, and for input 1 the next state is Nil as
there is no state for input 1.
4. When the current state is q2 for input 0, next state will become nil as there is no state for input 0, and for 1
input the next state will become q3.
5. When the current state is q3 for input 0, next state will become nil as there is no state for input 0, and for 1
input the next state will also become nil as there is no state for input 1.
6. The small straight arrow on q0 indicates that it is a start state and circle on to q3 indicates that it is a final
state.

Finite Automata

o Finite automata are used to recognize patterns.


o It takes the string of symbol as input and changes its state accordingly. When the desired symbol is found,
then the transition occurs.
o At the time of transition, the automata can either move to the next state or stay in the same state.
o Finite automata have two states, Accept state or Reject state. When the input string is processed
successfully, and the automata reached its final state, then it will accept.

Formal definition of Finite Automata


Finite automata is defined as a 5-tuples
M=(Q, Σ, δ,q0,F)
Where,

 Q: Finite set called states.


 Σ: Finite set called alphabets.
 δ: Q × Σ → Q is the transition function.
 q0 ∈ Q is the start or initial state.
 F: Final or accept state.
Now that we have learnt about these terminologies, let us understand the relation between them.

Types of Automata:
There are two types of finite automata:

1. DFA(deterministic finite automata)


2. NFA(non-deterministic finite automata)

1. DFA

DFA refers to deterministic finite automata. Deterministic refers to the uniqueness of the computation. In the DFA,
the machine goes to one state only for a particular input character. DFA does not accept the null move.

2. NFA

NFA stands for non-deterministic finite automata. It is used to transmit any number of states for a particular input. It
can accept the null move.
Some important points about DFA and NFA:

1. Every DFA is NFA, but NFA is not DFA.


2. There can be multiple final states in both NFA and DFA.
3. DFA is used in Lexical Analysis in Compiler.
4. NFA is more of a theoretical concept.

Relationship
The relationship between FA and RE is as follows

The above figure explains that it is easy to convert

 RE to Non-deterministic finite automata (NFA) with epsilon moves.


 NFA with epsilon moves to without epsilon moves.
 NFA without epsilon moves to Deterministic Finite Automata (DFA).
 DFA can be converted easily to RE.

Regular Languages and Computers


There are many ways regular languages are used in computer science and related fields. A few examples include:

 Pattern matching: They are often used in text editors, word processors, and programming languages for
searching and manipulating strings that match a given pattern
 Lexical analysis: Regular languages are used in the lexical analysis phase of compiler design to identify
and tokenize keywords, identifiers, and other elements of a programming language
 Input validation: Regular languages are used in programming to validate user input by checking if it
matches a given pattern
 Network protocols: Regular languages are used to define the syntax of messages in network protocols
such as HTTP, FTP, and SMTP
 DNA sequence analysis: Regular languages are used to analyze DNA sequences in bioinformatics

Limitations of Regular Languages

 Less powerful formal language: Regular languages are a limited class of formal languages and are less
powerful than other classes of languages, such as CFLs and context-sensitive languages
 Unboundedness: Regular languages are limited to patterns that have a fixed length or can be described by
a fixed number of repeating units
 Expressiveness: Regular languages are not powerful enough to describe all computable functions or to
model all kinds of data structures

Regular languages are a fundamental class of formal languages, but they are not powerful enough to describe many
of the languages that arise in practice. They are useful for simple pattern matching and lexical analysis, but more
complex languages require more powerful models

You might also like