Formal Languages and
Automata Theory
Nonregular Languages
Modified and presented by Asst. Prof. Dr.
Mohamed Kurdi
1.3 Properties of Regular
Languages
Pumping Lemma
Closure properties
Decision properties
Minimization of DFAs
Limits on the Power of FA
Is every language describable by a
sufficiently complex regular
expression?
If someone asks you to design an FA
for a language that seems hard, how
do you know when to give up?
An FA is limited on finite memory, i.e.
finite set of states
Non-Regular Languages
Is this language regular?
▪ B = {0 1 | n 0}
n n
Non-Regular Languages
B = {0 n1n | n 0}
Non-Regular Languages
Doesn't the argument already given prove non-
regularity because the number of 0s is unlimited?
It does not. Just because the language appears to
require unbounded memory doesn't mean that it is
necessarily so.
It does happen to be true for the language B, but
other languages seem to require an unlimited
number of possibilities, yet actually they are regular.
Non-Regular Languages
Is this language regular?
◼ L = {w | w has equal numbers of occurrences of ‘01’ and ‘10’}
◼ Thus 101 ∈ L because 101 contains a single 01 and a single 10,
but 1010 ∈ L because1010 contains two 10s and only one 01.
◼ L=1 + 0 + ε + 0(0+1)*0 + 1(0+1)*1
◼ Claim:
◼ A string w has equal occurrences of 01 and 10 is a string that starts
and ends with the same symbol.
Non-Regular Languages
Is this language regular?
L = {w | w has equal numbers of ‘0’ and ‘1’}
?
How to prove that there is no Finite
Automaton recognizing a given language?
Every regular language satisfies the pumping
lemma
Pumping Lemma
If L is a regular language, then there exists a
constant n (pumping length) such that every string
w in L with |w| >= n, can be written as w = xyz,
where:
◼ |y| > 0 (y is not ε, i.e. y can not be empty. But yi can be ε )
◼ |xy| <= n (the first two pieces occur at the start of the string)
◼ For all i >= 0, xyiz is also in L (the middle piece y can be
replicated (“pumped”) zero or more times)
Note: both of or one of x and z may be ε
That means each such string contains a section that
can be repeated any number of times with the
resulting string remaining in the language.
Proof of Pumping Lemma
L is regular, then
◼ Let M be a FA that recognizes L.
◼ Set n = number of states of M.
◼ Consider wL, say w = a1a2…am (m>=n).
◼ Let q0q1…qm be the sequence of states of M when
processing W.
◼ Since there are only n different states, two of q0q1…qm
(m>=n) must be the same (pigeon hole principle); say
qi=qj where 0<=i<j<=n (among the first n+1 states).
◼ Pigeonhole principle: if p pigeons are placed into fewer
than p holes, some hole has to have more than one
pigeon in it.
Proof of Pumping Lemma
(cont’d)
◼ Let x=a1…ai; y=ai+1…aj; z =aj+1…am.
◼ Then xyz=a1…am and |y| > 0.
◼ Then by repeating the loop from qi to qi
with label ai+1…aj zero or more times, we
can show that xyiz is accepted by A.
y
q0 qm
x qi
z M
Use Pumping Lemma
Use pumping lemma to prove that L is not
regular.
◼ Assume L is regular;
◼ Then there exists a pumping length n.
We may not know what n is, but we can work
the rest of the “game" with n as a parameter.
◼ Select a string wL such that |w|>=n.
◼ Applying the PL, we know w can be broken into
xyz, satisfying the PL properties.
◼ We derive a contradiction by picking i>=0 such
that xyiz is not in L (whatever x, y, z are)
Example 1.38:
B = {0n1n | n>=0}
Assume B is regular, let p be the pumping length
Choose w = 0p1p because it is in B and (|w|=2p > p)
Applying PL, w = xyz, where |y|>0, such that xyiz in B for
all i >= 0
Three possible cases for y:
◼ y = 0k, (k>0), then xyyz = 0p+k1p, not in B
◼ y = 1k, (k>0), then xyyz = 0p1k+p, not in B
◼ y = 0k1k, (k+l>0), then xyyz = 0p1k0k1p, not in B
Contradiction, B is not regular
Example 1.38:
B = {0n1n | n>=0}
Assume B is regular, let p be the pumping length
Choose w = 0p1p because it is in B and (|w|=2p > p)
Applying PL, w = xyz, where |y|>0, such that xyiz in B for
all i >= 0 Recall that
1.|y| > 0
We consider only the first case: 2.|xy| <= p
3.i >= 0, xyiz is also in L
◼ y = 0k, (k>0), then xyyz = 0p+k1p, not in B
◼ y = 1k, (k>0), then xyyz = 0p1k+p, not in B
◼ y = 0k1k, (k+l>0), then xyyz = 0p1k0k1p, not in B
Contradiction, B is not regular
Example 1.39:
C = {w | w has equal number of 0s and 1s}
Assume C is regular, let p be the pumping length
Choose w = 0p1p which is in C and (|w|=2p > p)
◼ We did not choose w = (01)p, why?
Applying PL, w = xyz, where |y|>0, |xy|<=p, such that
xyiz in C for all i >= 0
Since |xy|<=p, then y = 0k, (k>0) Then xyyz = 0p+k1p,
not in C
Contradiction, C is not regular
Example 1.39:
C = {w | w has equal number of 0s and 1s}
Assume C is regular, let p be the pumping length
If we had chosen w= (01)p which is also in C and (|w|=2p>p)
◼ We have run into trouble.
◼ Because we need a string that can be pumped. But that sting
actually can be pumped.
One way to do so sets x = ε, y = 01, and z = (01) p-1. Then xyiz ∈ C
for every value of i.
If you fail on your first attempt to find a string that cannot be
pumped, don't despair. Try another one!
Example 1.40:
F = {ww | w{0, 1}*}
Assume F is regular, let p be the pumping length
Choose w = 0p10p1 in F (|w| > p)
◼ We did not choose w = 0p0p
Applying PL, w = xyz, where |y|>0, |xy|<=p, such that
xyiz in F for all i >= 0
Since |xy|<=p, then y = 0k, (k>0)
Then xyyz = 0p+k10p1, not in F
Contradiction, F is not regular
Example 1.42:
E = {0i1j | i > j}
Assume E is regular, let p be the pumping length
Choose w = 0p+11p because w in E and (|w| > p)
Applying PL, w = xyz, where |y|>0, |xy|<=p, such that
xyiz in D for all i >= 0
Since |xy|<=p, then y=0k, (k>0)
Then xyyz = 0p+1+k1p, in E…
But when k=0, xy0z = xz = 0p+1-k1p, not in E
Contradiction, E is not regular