Chapter 4
Properties of
Regular Languages
1
4.1: Closure Properties of RLs (1)
A language L over an alphabet S is regular
if it
has a regular set (expression) over S
is accepted y DFA, NFA, or NFA-e
is generated by regular grammar
2
4.1: Closure Properties of RLs (2)
3
4.1: Closure Properties of RLs (3)
If L1 and L2 are regular languages, then
L1 L2
Union
= {w * : w L1 or w L2}
L1 L2
Intersection
L1 L2
Concatenation
L*
Kleene Star
L1
Complement
= {w * : w L1 and w L2}
n languages: L1L2 …Ln = {w1w2…wn : wi Li}
one languages: Ln = {w1w2…wn : wi L}
L*= L0 L1 L2 …
L = * - L = {w : w * and w L}
are also regular languages
4
4.1: Closure Properties of RLs (4)
Prove that RLs are closed under complementation.
If L is a regular language over S, then L = S* - L is
regular language.
Proof:
If L is regular, there exists a DFA M
recognizing L.
We can construct a DFA M’ for L by copying
M to M’ except that all final states in M are
changed to non-final, and all non-final states to
final.
See next slide for a formal proof
5
4.1: Closure Properties of RLs (5)
Let M1=(Q, S, , q0, F) a DFA that accepts L(M1)
Let M2=(Q, S, , q0, Q-F) a DFA that accepts L(M2)
Obviously both languages are regular languages
Per definition 2.2: L(M) = {w * : (q0, w) F}
The following are both true
w * : (q0, w) F
(q0, w) Q – F
w * : (q0, w) Q - F
(q0, w) F
Thus L(M2) = L(M1)
L(M1) is an arbitrary regular language and its
complement is also a regular language, therefore the
regular languages are closed under complementation
6
4.1: Closure Properties of RLs (6)
Are regular languages closed under intersection?
If L1 and L2 are RLs, then L1 L2 is RL.
Proof:
Since RLs are closed under union and
complementation, they are also closed under
intersection
L1, L2 are RLs, so L1, L2 are RLs, and L1 L2
is RL, so L1 L2 is RL.
Thus L1 L2 = L1 L2 is RL.
7
4.1: Closure Properties of RLs (7)
Are regular languages closed under difference?
If L1 and L2 are RLs, is L1 - L2 RL? Why?
L1 - L2 = L1 L2
Since RLs are closed under intersection and
complementation, they are also closed under
difference.
8
4.1: Closure Properties of RLs (8)
Let L, M and N are regular expressions, which of
the followings are correct?
Commutative Rules:
LM=ML
LM = ML
Associative Rules:
(L M) N = L (M N)
(LM)N = L(MN)
9
4.1: Closure Properties of RLs (9)
Which of the followings are correct?
Left Distributive Rules:
L(M N) = LM LN
L (MN) = (L M)(L N)
Right Distributive Rules:
(M N)L = ML NL
(MN) L = (M L)(N L)
10
4.1: Closure Properties of RLs (10)
Identities:
is the identity for union:
L=L=L
e is the identity for concatenation:
eL = Le = L
11
4.1: Closure Properties of RLs (11)
Other Rules for Kleene Closure
(L*)* = L*
L+ = LL* = L*L
L* = L+ | e
*=e
e* = e
12
4.2: Elementary Questions about RLs
Membership question:
If L is a RL over S, then for any string w S*
there exists an algorithm for determining
whether or not w is in L.
DFA
Empty, finite, or infinite question:
There exists an algorithm for determining
whether a RL is empty, finite, or infinite.
DFA (path from start to final, cycle)
Equality question:
If L1 and L2 are RLs, then there exists an
algorithm to determine whether or not L1 = L2.
L3 = (L1 L2) (L1 L2) = iff L1 = L2
13
4.3: Non-regular Languages (1)
The language
L = {an bn | n 0} is not regular
There is NO DFA/NFA that accepts L
Theorem:
If L1 is RL and L2 is not-regular, then
The language L = L1 L2 is not necessarily
regular
Proof:
L1 = a*b* is regular
L2 = {an bn | n 0} is not regular
L1 L2 = L2 which is not regular
14
4.3: Non-regular Languages (2)
The language
L = {an bm | n, m 0 and n m} is not regular.
Proof:
L is regular iff L a*b* is regular.
But L a*b* = {an bn | n 0}, which we know
is not regular.
Then L is not regular.
15
4.3: Non-regular Languages (3)
Many languages are non-regular:
{anbn | n 0}
{wwR} | w * }
2
{an | n 0}
{ap | p is prime}
set of well-formed parentheses
set of palindromes: {w = wR}
…...
16
4.3: Non-regular Languages (4)
We want to prove that L = {akbk | k 0} is nonregular. Prove by contradiction:
Assume that there is a DFA M which
recognizes L. Let n be the no. of states in M
Consider the acceptance of the input arbr where
r n:
q0 a q1 a q2 a
…...
a qr b qr+1 b
ar
…... b q2r
br
path for accepting arbr
17
4.3: Non-regular Languages (5)
Since r n and M has only n states, there must
be at least one state visited twice in the first r
transitions. Let this state be visited at the ith and
the jth steps, where j i.
qi = qj
qf F
q0
a path in M
By skipping the loop, ar-(j-i)br should also be
accepted by M,
but this is contradictory since ar-(j-i)br L
18
4.3: Non-regular Languages (6)
2
k
{a
We want to prove that L =
| k 0} is nonregular. Prove by contradiction:
Assume that there is a DFA M which
recognizes L. Let n be the no. of states in M
M should also accept the string an2
q0 a q1 a q2 a
…...
a q2
n
path for accepting an2
19
4.3: Non-regular Languages (7)
Since n2 n and M has only n states, there must
be at least two equal states from q0 to qn2. Let
them be qi and qj where j - i = m n.
A loop of
length m
qi = qj
a path in M
qn2 F
q0
By repeating the loop one more time, a(n2+m) is
also accepted by M, which is a contradiction,
since (n2+m) cannot be a square (the next
square after n2 is (n+1)2 but n2+m (n+1)2)
20
4.3: Non-regular Languages (8)
We want to prove that L = {ap | p is a prime} is
non-regular. Prove by contradiction:
Assume that there is a DFA M which
recognizes L. Let n be the no. of states in M
From Number Theory, we know that the no. of
primes are infinite, so there exists a prime p n
q0 a q1 a q2 a
…...
a qp
path for accepting ap
21
4.3: Non-regular Languages (9)
Since p n and M has only n states, there must
be at least two equal states from q0 to qp. Let
them be qi and qj where j - i = m 0
qi = qj
A loop of
length m
a path in M
q0
qp F
By repeating the loop (p-m) times, a(p-m)m + (p-m)
= a(p-m)(m+1) is also accepted by M, which is a
contradiction since (p-m)(m+1) is not a prime,
since it can be divided by (p-m) and (m+1) 1
22
4.3: Pumping Lemma (1)
If L is a regular language, there is a DFA which
recognizes L.
All finite languages are regular
, {a}, {abaabb, b, baabbbbb, bb}
So, only infinite languages are interesting for
this discussion.
What are non-regular languages?
Pumping Lemma
A technique for proving a language L is NOT
regular
23
4.3: Pumping Lemma (2)
Any given DFA has a finite number of states
Let k = |Q|
Consider any accepted input w = a1…an, such that
|w| = n k
DFA follows a path of states q0…qn:
q0
a1
q1
a2
…
an-1
qn-1
an
qn
This state numbering has nothing to do with
state names in Q
May repeat states in this path
24
4.3: Pumping Lemma (3)
Since |w| k, path must contain at least one loop
Consider any one such loop (cycle)
Break string & path into three parts: before,
during, & after loop
…
aj
q0
a1
…
ai
ai+1
qi=qj
aj+1
…
an
qn
Given other inputs, could loop an arbitrary number
of times
(a1…ai)(ai+1…aj)*(aj+1…an) also accepted
25
4.3: Pumping Lemma (4)
If language L is regular, then for any w L that is
longer than |Q|, there is a substring of w that can be
repeated (pumped) any number of times with
resulting string remaining in the language
Lemma:
Let G be the state diagram of a DFA with k states.
Any path of length k in G contains a cycle.
Proof:
A path of length k contains k+1 nodes. Since there
are only k nodes (states) in G, there must be a
node, call it qi, that occurs in at least two positions
in the path. The subpath from the first occurrence
of qi to the second produces the desired cycle.
26
4.3: Pumping Lemma (5)
Let G be the state diagram of a DFA with k
states and let p be a path of length k.
The path p can be subdivided into
subpaths u, v, and z where p = uvz
The length of uv is |uv| k, and v is a
cycle
27
4.3: Pumping Lemma (6)
Pumping Lemma
Let L be a regular language is accepted by a DFA
M with k states. Let for ALL w L and |w| k.
Then w can be divided into three parts, w = uvz,
satisfying the following conditions:
|uv| k,
|v| 1, and
for all i 0, uviz L
28
4.3: Pumping Lemma (7)
Proof:
Let w L with |w| = n k
where w(i) is the ith symbol of the string w.
q0 w(1) q1 w(2) q2 w(3) …... w(n) qn
Since n k and M has only k states, there must be
at least one repeated state from q0 to qn
Let qi be the first such repeated state
qi
q0
a path in M
29
qn F
4.3: Pumping Lemma (8)
qi
q0
a path in M
qn F
Let u be the string obtained by traversing from
q0 to qi, v be the string obtained by traversing
the loop once (so |v| 1)
In the traversal from q0 to qi and then through
the loop once back to qi, nothing except qi
repeats, thus |uv| k
By traversing the loop 0 or more times, we
obtain uviz for all i 0 and they should all be
accepted by the DFA, i.e., in L.
30
4.3: Pumping Lemma (9)
How to use pumping lemma to prove some L isn’t
regular?
Lemma describes a property of regular
languages.
Use proof by contradiction: If L doesn't have
this property, it is NOT regular
We cannot use the pumping lemma to prove a
language is regular
Since we have to check every string in L
31
4.3: Pumping Lemma (10)
We assume the given language L is regular
Let n be the constant of pumping lemma
Find a string w L where |w| n
Divide w into 3 parts, w = uvz, where
|uv| n
|v| 1
Claim that uviz are also in L for all i
Find one i such that uviz L
Contradiction
Only one string w is needed
do not need to consider all general cases
choose w that can led to contradiction easily
32
4.3: Pumping Lemma (11)
Example 1:
L = {am bm | m 0}
Assume L is regular, n is the # of DFA states
Let w = anbn
where |w| = 2n n
where p + j n and j 1
w = ap aj an-p-j bn
w=u v z
u & v contain only a’s, since |uv| n
Pick i = 2:
uv2z = ap aj aj an-p-j bn = an aj bn
uv2z contains more a’s than b’s, since |v| 1
uv2z L
Contradiction and hence L is not regular
33
4.3: Pumping Lemma (12)
Example 2:
L = {w | w {a, b}*, w has equal number of a’s
and b’s}
w = an bn
Same argument as previous example
Choice of w is important
Different w’s may lead to different proofs, or
none being possible
Choice of i is important.
Different i’s may lead to different proofs, or
none being possible
34
4.3: Pumping Lemma (13)
Example 3:
L = {(ab)i | i 0}
L is regular: L = (ab)*
i.e., for any w, there is some split u, v, z that allows
pumping
35
4.3: Pumping Lemma (14)
Example 4:
Prove that the language L of well-formed
parentheses is non-regular
Assume L is regular and let n be the constant of
pumping lemma
Let w = (n)n L, |w| = 2n n
we do not need to consider other possible cases
like ()()
we only need to ensure |w| n
Then w = (m (j (n-m-j )n where j 1 and m + j n
u
v
z
36
4.3: Pumping Lemma (15)
By pumping lemma,
(m(ji(n-m-j )n = (n+j(i-1) )n L for all i
When i = 0
(n-j )n L
since j 1 n-j n
Contradiction
We can choose i = 2, i = 3, ...
but cannot choose i = 1
L is not regular
37
4.3: Pumping Lemma (16)
To prove L is regular
1. Constructing a FSA (NFA or DFA), RE, or RG for L
2. Using closure property of regular sets
Let ⊕ be a binary operation (such as union,
concatenation and intersection)
L3 = L1 ⊕ L2 is regular, if both L1 and L2 are regular
Let ⊡ be an unary operation (such as complementation
and Kleene star)
L1 = ⊡ L2 is regular, if L2 is regular
38
4.3: Pumping Lemma (17)
Example
Prove that L is regular, where L is the set of all
strings with three consecutive 0's and S = {0,1}
Let
L1 = (0 | 1)*, which is regular and
L2 = 000, which is also regular
then L = L1.L2.L1
Hence L is regular due to the closure property
of regular sets under concatenation.
39
4.3: Pumping Lemma (18)
Prove L is not regular
1. Using Pumping Lemma
2. Using closure property of regular sets
Let ⊕ be a binary operation (such as union,
concatenation and intersection)
if L3 = L1 ⊕ L2 and L1 is regular and L3 is not regular,
then L2 must be non-regular
⊡ be an unary operation (such as
complementation and Kleene star)
Let
if L1 = ⊡ L2 and L2 is not regular, then L1 is nonregular
40
4.3: Pumping Lemma (19)
L = {w {a, b}*, w has equal number of a’s and
b’s}
Consider
By
L’ = L a*b* = {an bn | n 0}
closure properties of RLs:
if L is regular, then L’ is also regular
But since L’ not regular, so L can’t be regular
41
4.3: Pumping Lemma (20)
Example
Prove that L is not regular, where L is the set of all
strings over {a, b} such that the number of b is the
double of the number of a. Let
L1 = (anb2n) ,
which is non-regular, and
L2 = a*b*,
which is regular
then L1 = L L2
By
closure properties of RLs:
if L is regular, then L1 is also regular
But since L1 not regular, so L can’t be regular
42
4.3: Pumping Lemma (21)
Common Mistakes
Let L1 regular language, L3 and L4 are not regular.
Is L regular?
L = L1 ⊕ L3
0n1n = 0*1* 0n1n
0*1* = 0*1* 0n1n
L
= L3 ⊕ L4
0*1* = 0p1q 0q1p , where p q
L3
= L ⊕ L4
0n1n = 0*1* 0n1n
43
Class Discussion
Prove that L = {ww : w (0|1)*} is non-regular
Is L = {(01)6n : n 0} regular?
Is L = {(ab)n : n 0} regular?
44
Summary
We use the Pumping Lemma to prove a language is
not regular
Note, does not work for all non-regular
languages, though
Choosing a good string w is first key step
Choosing a good integer i is second key step
Must apply argument to all legal u, v, z
45
© Copyright 2026 Paperzz