0% found this document useful (0 votes)
3 views97 pages

Pumping Lema

The document discusses non-regular languages and the Pumping Lemma, which is a method to prove that certain languages are not regular. It explains the relationship between finite automata (DFA) and the Pigeonhole Principle, illustrating how repeated states in a DFA can lead to contradictions when applying the Pumping Lemma. Several examples are provided to demonstrate the application of the Pumping Lemma in proving the non-regularity of specific languages.

Uploaded by

rehmanateequr501
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)
3 views97 pages

Pumping Lema

The document discusses non-regular languages and the Pumping Lemma, which is a method to prove that certain languages are not regular. It explains the relationship between finite automata (DFA) and the Pigeonhole Principle, illustrating how repeated states in a DFA can lead to contradictions when applying the Pumping Lemma. Several examples are provided to demonstrate the application of the Pumping Lemma in proving the non-regularity of specific languages.

Uploaded by

rehmanateequr501
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/ 97

Theory of Automata

Non Regular Languages


Exercise
Build an FA that accepts the following
language:
L = {L, ab, aabb, aaabbb, aaaabbbb, ……}

We cannot…!!!

2
Nonregular Languages.
Examples:
L = {L, ab, aabb, aaabbb, aaaabbbb, …}
L = {anbn | n=0,1,2,3,4,…}
L = {anbn}
L  language(a*b*)

Palindrome is another non regular language.

3
How can we prove that a language L
is not regular?

Prove that there is no DFA that accepts L

Problem: this is not easy to prove

Solution: the Pumping Lemma !!!

4
The Pigeonhole Principle
n pigeons
m pigeonholes
There is a pigeonhole
nm with at least 2 pigeons

...........

5
How does pigeonhole principle relate to
DFAs?

DFA with 4 states

b
b b

q1 a b b
q2 q3 q4
a a
6
In walks of strings a, aa, aab, no state is
repeated

In walks of strings aabb, bbaa, abbaba, a


state is repeated
b
b b

q1 a a b
q2 q3 q4
a a
7
In general, for any DFA:

String w has length  number of states

A state q must be repeated in the walk of w

walk of w
...... q ......
Repeated state 8
In other words for a string w:

a transitions are pigeons

q states are pigeonholes

walk of w
...... q ......
Repeated state
9
The Pumping Lemma

10
Take an infinite regular language L
There exists a DFA that accepts L
Take a string w from the language.

m
states

11
If string w has length | w |  m (number
of states
of DFA)
then, from the pigeonhole principle:

a state is repeated in the walk w

...... q ......
walk w
12
Let q be the first state repeated in the
walk of w

...... q ......
walk w
13
Write w= x y z

...... q ......

x z 14
Observations: length |x y|  m number
of states
length | y | 1 of DFA

...... q ......

x z 15
Additional string: The string xz
is accepted

Do not follow loop


y
...

j  i +1
1 ... i
q  j+1... ... k

x z
Prof. Busch - LSU 16
Additional string: The string xyyz
is accepted

Follow loop y
2 times
...

j  i +1
1 ... i
q  j+1... ... k

x z
Prof. Busch - LSU 17
Additional string: The string xyyyz
is accepted

Follow loop y
3 times
...

j  i +1
1 ... i
q  j+1... ... k

x z
Prof. Busch - LSU 18
i
In General: The string xy z
is accepted i = 0, 1, 2, ...

Follow loop y
i times
...

j  i +1
1 ... i
q  j+1... ... k

x z
Prof. Busch - LSU 19
Therefore: x y z L
i
i = 0, 1, 2, ...

Language accepted by the DFA


y
...

j  i +1
1 ... i
q  j+1... ... k

x z
Prof. Busch - LSU 20
Observation: The string xz
is accepted

...... q ......

x z 21
Observation: The string xyyz
is accepted

...... q ......

x z 22
Observation: The string xyyyz
is accepted

...... q ......

x z 23
Chapter 10: Nonregular Languages.

y
x z

y
x z

first state that is visited more than once


xz L, xyz L, xyyz L, xyyyz L, …, xynz L.

24
In other words, we described:
The Pumping Lemma !!!

25
The Pumping Lemma:
• Given a infinite regular language L
• there exists an integer m
• for any string w L with length | w| m

• we can write w= x y z

• with | x y |  m and | y |  1

• such that: xy z  L
i i = 0, 1, 2, ...
26
Example
a
b 2+
b 3
1–

a b
a a b
a,b
4
b
5 6+
a
w=bbbababa
b b b a b a b a
1 2 3 5 2 3 6 3 6
x y z
27
w=bbbababa

bbbabbababa

xy z  L
i i = 0, 1, 2, ...
28
What does the pumping lemma suggest…???

◼ Since this lemma must be true for any regular language L, we can
logically state it as follows:

◼ L regular  Pumping Lemma true

◼ But the contrapositive implies that:

◼ Pumping Lemma not true  L is not regular

◼ We can show a language is not regular by showing that it violates some


condition of the Pumping Lemma.
◼ We do that by first assuming the language is regular, and deriving a
contradiction.
29
Outline of a pumping lemma proof to show
the non-regularity of some language L:

1. Assume L is regular. Therefore (by the Pumping Lemma) there


exists some number m, which is the number of states in DFA that
accepts L.
2. Choose a specific string ‘w’ such that wL and |w|m. Both of these
conditions must be explicitly stated/verified for ‘w’.
3. Consider an arbitrary factorization of w into xyz such that |y|1 and
|xy|  m. Any possible factorization of w that satisfies these
conditions must be considered.
4. Create the string w' from w by choosing some value for i0. That is,
w' = xyiz for some i0. Show that w'L, no matter how the portions
x, y, and z are determined.
5. Conclude that L is not regular if it contradicts the Pumping Lemma.

30
Applications

of

the Pumping Lemma

Prof. Busch - LSU 31


Observation:
Every language of finite size has to be regular
(we can easily construct an NFA
that accepts every string in the language)

Therefore, every non-regular language


has to be of infinite size
(contains an infinite number of strings)

Prof. Busch - LSU 32


Suppose you want to prove that
αn infinite language L is not regular

1. Assume the opposite: L is regular

2. The pumping lemma should hold for L


3. Use the pumping lemma to obtain a
contradiction

4. Therefore, L is not regular

Prof. Busch - LSU 33


Explanation of Step 3: How to get a contradiction
1. Let m be the critical length for L

2. Choose a particular string w L which satisfies


the length condition | w | m

3. Write w = xyz
4. Show that w = xy z  L
i
for some i 1

5. This gives a contradiction, since from


pumping lemma w = xy z  L i

Prof. Busch - LSU 34


Note: It suffices to show that
only one string w L
gives a contradiction

You don’t need to obtain


contradiction for every w L

Prof. Busch - LSU 35


L = {a b : n  0}
n n

36
Example of Pumping Lemma application

Theorem: The language L = {a nb n : n  0}


is not regular

Proof: Use the Pumping Lemma

Prof. Busch - LSU 37


L = {a b : n  0}
n n

Assume for contradiction


that L is a regular language

Since L is infinite
we can apply the Pumping Lemma

Prof. Busch - LSU 40


L = {a b : n  0}
n n

Let m be the critical length for L

Pick a string w such that: w  L


and length | w| m

We pick w=a b m m

Prof. Busch - LSU 41


From the Pumping Lemma:

we can write w = a b m m
=x y z

with lengths | x y |  m, | y | 1
m m
w = xyz =a b
m m
= a...aa...aa...ab...b
x y z

Thus: y = a k
, 1k m
Prof. Busch - LSU 42
x y z=a b
m m y =a , 1k m
k

From the Pumping Lemma: xy z  L


i

i = 0, 1, 2, ...

Thus: xy z  L
2

Prof. Busch - LSU 43


x y z=a b m m y =a , 1k m
k

From the Pumping Lemma: xy z  L


2

m+k m
xy z = a...aa...aa...aa...ab...b  L
2

x y y z

m+ k m
Thus: a b L
Prof. Busch - LSU 44
m+ k m
a b L k≥ 1

BUT: L = {a b : n  0}
n n

m+ k m
a b L

CONTRADICTION!!!
Prof. Busch - LSU 45
Therefore: Our assumption that L
is a regular language is not true

Conclusion: L is not a regular language

END OF PROOF
Prof. Busch - LSU 46
Non-regular language {a b : n  0}
n n

Regular languages

* *
L( a b )

Prof. Busch - LSU 47


n l n +l
L = {a b c : n, l  0}

48
Non-regular languages
n l n +l
L = {a b c : n, l  0}

Regular languages

Prof. Busch - LSU 49


Theorem: The language
n l n +l
L = {a b c : n, l  0}
is not regular

Proof: Use the Pumping Lemma

Prof. Busch - LSU 50


n l n +l
L = {a b c : n, l  0}

Assume for contradiction


that L is a regular language

Since L is infinite
we can apply the Pumping Lemma

Prof. Busch - LSU 51


n l n +l
L = {a b c : n, l  0}
Let m be the critical length of L

Pick a string w such that: w  L and

length | w| m

We pick w=a b c m m 2m

Prof. Busch - LSU 52


From the Pumping Lemma:

We can write w =a b c m m 2m
=x y z
With lengths | x y |  m, | y | 1

m m 2m
w = xyz = a...aa...aa...ab...bc...cc...c
x y z

Thus: y =a , 1k m
k

Prof. Busch - LSU 53


x y z=a b c
m m 2m
y =a , 1k m
k

From the Pumping Lemma: xy z  L


i

i = 0, 1, 2, ...

0
Thus: x y z = xz ∈ L

Prof. Busch - LSU 54


x y z=a b c
m m 2m
y =a , 1k m
k

From the Pumping Lemma: xz  L


m−k m 2m
xz = a...aa...ab...bc...cc...c  L
x z

m−k m 2m
Thus: a b c L
Prof. Busch - LSU 55
m−k m 2m
a b c L k 1

BUT: n l n +l
L = {a b c : n, l  0}

m−k m 2m
a b c L

CONTRADICTION!!!
Prof. Busch - LSU 56
Therefore: Our assumption that L
is a regular language is not true

Conclusion: L is not a regular language

END OF PROOF
Prof. Busch - LSU 57
L = {a : n  0}
n!

58
Non-regular languages L = {a : n  0}
n!

Regular languages

Prof. Busch - LSU 59


Theorem: The language L = {a : n  0}
n!

is not regular

n! = 1 2  (n − 1)  n

Proof: Use the Pumping Lemma

Prof. Busch - LSU 60


L = {a : n  0}
n!

Assume for contradiction


that L is a regular language

Since L is infinite
we can apply the Pumping Lemma

Prof. Busch - LSU 61


L = {a : n  0}
n!

Let m be the critical length of L

Pick a string w such that: w  L


length | w| m

We pick w=a m!

Prof. Busch - LSU 62


From the Pumping Lemma:

We can write w = a =x y z
m!

With lengths | x y |  m, | y | 1
m m!−m
w = xyz = a = a...aa...aa...aa...aa...a
m!

x y z

Thus: y = a , 1 k  m
k
Prof. Busch - LSU 63
x y z=a m!
y = a , 1 k  m
k

From the Pumping Lemma: xy z  L


i

i = 0, 1, 2, ...

Thus: xy z  L
2

Prof. Busch - LSU 64


x y z=a m!
y = a , 1 k  m
k

From the Pumping Lemma: xy z  L


2

m+k m!−m
xy z = a...aa...aa...aa...aa...aa...a  L
2

x y y z

m!+ k
Thus: a L
Prof. Busch - LSU 65
m!+ k
a L 1 k  m

Since: L = {a : n  0}
n!

There must exist p such that:

m!+ k = p!

Prof. Busch - LSU 66


However: m!+ k  m!+ m for m 1
 m!+ m!
 m!m + m!
= m!(m + 1)
= (m + 1)!

m!+ k  (m + 1)!

m!+ k  p! for any p


Prof. Busch - LSU 67
m!+ k 1 k  m
a L

BUT: L = {a : n  0}
n!

m!+ k
a L

CONTRADICTION!!!
Prof. Busch - LSU 68
Therefore: Our assumption that L
is a regular language is not true

Conclusion: L is not a regular language

END OF PROOF
Prof. Busch - LSU 69
Palindrome

71
Theorem: The language

L = {vv : v  *}
R
 = {a, b}
is not regular

Proof: Use the Pumping Lemma

Prof. Busch - LSU 72


L = {vv : v  *}
R

Assume for contradiction


that L is a regular language

Since L is infinite
we can apply the Pumping Lemma

Prof. Busch - LSU 73


L = {vv : v  *}
R

Let m be the critical length for L

Pick a string w such that: w  L


and length | w| m

We pick w=a b b a m m m m

Prof. Busch - LSU 74


From the Pumping Lemma:

we can write: w = a b b a =x y z
m m m m

with lengths: | x y |  m, | y | 1
m m m m
w = xyz = a...aa...a...ab...bb...ba...a
x y z

Thus: y =a , 1k m
k
Prof. Busch - LSU 75
x y z=a b b a
m m m m
y =a , 1k mk

From the Pumping Lemma: xy z  L


i

i = 0, 1, 2, ...

Thus: xy z  L
2

Prof. Busch - LSU 76


Example: Palindrome is non regular

Theorem: Palindrome L = {anban | n=0,1,2,3,4,…}


= {b, aba, aabaa, …} is not regular.
Proof (incomplete).
The left an will be pumped to aq while the right an
remains fixed, imbalance.

Note: Solve this yourself with all steps as required.

77
PRIME = {ap | p is a prime number}

78
Example: PRIME is non regular

Theorem: PRIME = {ap | p is a prime number}


= {aa, aaa, aaaaa, aaaaaaa, …}
is not regular.
Proof: p>N (N= # of states in assumed FA), ap=xyz from
pumping lemma. ap accepted →
xyp+1z = xyzyp (why?) = apyp = ap(am)p = a(m+1)p accepted
But (m+1)p is not a prime number … contradiction.

79
Example: anbanb is nonregular
◼ Assume L is regular and let m be the integer from the pumping
lemma.
◼ Choose w = ambamb. Clearly, w ε L so by the pumping lemma, w =
xyz such that |xy|  m. |y| > 0 and xyiz ε L for all i ≥ 0.
◼ Let p = |y|.
◼ Consider what happens when i = 0.
◼ The resulting string, xz = am-pbamb.
◼ Since p ≥ 1, the number of a’s in the two runs are not the same,
and thus this string is not in L.
◼ Therefore L is not regular.

80
Example: How to attempt the Regular pumping
Lemma Problems in Exams
Prove that language L={a3bncn-3 | n>3} is non
regular
1. Suppose for contradiction that the language is regular, hence, a DFA with ‘m’
states will accept this language.
2. We choose w=a3bmcm-3 such that |w|≥m
3. We can decompose w into xyz such that |y| ≥ 1 and |xy|≤m and xyiz is in L for
all i≥0.
4. Since |xy|≤m, these are the possible factorizations of xy
a) y consists of all a’s
Pumping y will lead to more than 3 a’s, contradiction as w’ not in L
a) y consists of a’s and b’s
Pumping y will lead to a string with b’s before a’s, contradiction.
a) y consists of all b’s
Pumping y will lead to more b’s and the c’s are untouched, difference
becomes more than 3, contradiction
5. The given language is non-regular as it violates the conditions of the pumping
lemma.
81
Theory of Automata
Fall 2018

Chapter - 11
Decidability
Chapter 11: Decidability

A problem is called a decision problem if its solution is


either YES or NO.

Definition: a decision problem is decidable, or


effectively solvable, if there is an algorithm that can
find the answer for any input in a finite number of
steps.

84
Decision Problems…
◼ Membership: Does w  L
◼ Do two regular expressions define the same
language?
◼ Do two finite automata accept the same language?
◼ Is L Empty?
◼ Is L finite or infinite?

85
Membership Question
Question: Given regular language L and string w
how can we check if w  L ?

Answer: Take the DFA that accepts L


and check if w is accepted

DFA
w
w L

86
Question: Given regular language L
how can we check
if L is empty: ( L = ) ?

Answer: Take the DFA that accepts L

Check if there is any path from


the initial state to a final state
87
DFA

L

DFA

L=

88
Chapter 11: Decidability

Method: Answer the question: is there any path from – to +?


The Blue Paint Algorithm:
1. Mark the start state. (Paint it blue.)
2. From every blue state, follow every arrow that goes out
of the state, and paint the destination state blue. Delete
each arrow that was followed.
3. Repeat step 2 until there are no new blue states.
4. If there is any final state that is blue, then there are
words in the language accepted by the finite automaton.
If not, the language is empty.

89
Chapter 11: Decidability

a a a b
b b a
– b a,b +
b a
a a b
b b a
– a,b +
b a
a b
b a
– +
b a
90
Chapter 11: Decidability

a b
b a
– +
b a
b
b a
– +
a

The language is empty.

91
Question: Given regular language L
how can we check
if L is finite?

Answer: Take the DFA that accepts L

Check if there is a walk with cycle


from the initial state to a final state
92
DFA

L is infinite

DFA

L is finite

93
Question: Given regular languages L1 and L2
how can we check if L1 = L2 ?

Answer: Find if ( L1  L2 )  ( L1  L2 ) = 

94
( L1  L2 )  ( L1  L2 ) = 

L1  L2 =  and L1  L2 = 

L1 L2 L L2 L1 L1
2
L1  L2 L2  L1

L1 = L2
95
( L1  L2 )  ( L1  L2 )  

L1  L2   or L1  L2  

L1 L2 L2 L1

L1  L2 L2  L1

L1  L2
96
Chapter 11: Decidability

Theorem: Let F be a finite automaton with N states. If the


language accepted by F is not empty, then it contains at
least one word with N or fewer letters.

Method 3. Try all words with N and fewer letters.


If the finite automaton accepts none of them, then the
language accepted by this automaton is empty.

97
Chapter 11: Decidability

Problem 3. Does the language defined by a finite


automaton has a finite number of words? Infinite?
None?
None? Done previously.
Finite or Infinite language?
Solution 1: Does corresponding RE contain * ?
Solution 2: Use the following theorem.

98
Infinite language…???

Theorem. Let F be a finite automaton with N states.


F accepts a word w such that N  length(w) < 2N if and only if
the language accepted by F is infinite.

Proof: Apply Pumping lemma.


 If w, N  length(w) is accepted, then w created loop while
following N states
 pumping lemma creates infinite number of accepted words

99
SUMMARY
◼ Membership: Does w  L
◼ Do two regular expressions define the same
language?
◼ Do two finite automata accept the same language?
◼ Is L Empty?
◼ Is L finite or infinite?

100
◼ This lecture concludes the course for
the mid term exam

101

You might also like