Languages and Finite Automata

Let’s Recapitulate
1
Regular Languages
DFAs
NFAs
Regular
Grammars
Regular
Expressions
2
A standard representation
of a regular language L :
A DFA M that accepts L
A NFA M that accepts L
A regular expression R
that generates L
A regular grammar G
that generates L
3
When we say:
“We are given a Regular Language L “
We mean:
Language in a standard representation
4
Elementary Questions
about
Regular Languages
5
Question:
Given regular language L
how can we check
if a string w  L ?
6
Question:
Answer:
Given regular language L
how can we check
if a string w  L ?
Take the DFA that accepts L
and check if w is accepted
7
Question:
Answer:
Given regular language L
how can we check
if L is empty, ( L  )
finite,
infinite ?
Take the DFA that accepts L
Then check the DFA
8
If there is a walk from the start state
to a final state then:
L is not empty
Otherwise empty
If the walk contains a cycle then:
L
is infinite
Otherwise finite
9
Question:
Given regular languages L1 and L2
how can we check if L1  L2 ?
10
Question:
Given regular languages L1 and L2
how can we check if L1  L2 ?
Answer:
take
L  ( L1  L2 )  ( L1  L2 )
And find if
L
11
Question:
Given language L
how can we check
if L is not a regular language ?
12
Question:
Given language L
how can we check
if L is not a regular language ?
Answer:
The answer is not obvious
We need the Pumping Lemma
13
The Pigeonhole Principle
14
4 pigeons
3 pigeonholes
15
A pigeonhole must
have two pigeons
16
nm
n pigeons
...........
m pigeonholes
...........
17
The Pigeonhole Principle
n pigeons
m pigeonholes
nm
There is a pigeonhole
with at least 2 pigeons
...........
18
The Pigeonhole Principle
and
DFAs
19
DFA with 4 states
b
q1
b
b
a
q2
b
a
q3
b
q2
a
20
In walks of strings:
a
no state
is repeated
aa
aab
b
q1
b
b
a
q2
a
a
q3
b
q2
a
21
In walks of strings: aabb
a state
is repeated
bbaa
abbabb
abbbabbabb...
b
q1
b
b
a
q2
a
a
q3
b
q2
a
22
If the walk of string w has length | w |  4
Then a state is repeated
b
q1
b
b
a
q2
a
a
q3
b
q2
a
23
The pigeonhole principle:
If in a walk:
Then:
A state is repeated
b
q1
transitions  states
b
b
a
q2
a
a
q3
b
a
q2
24
In other words:
a
transitions are pigeons
q
states are pigeonholes
b
q1
b
b
a
q2
a
a
q3
b
a
q2
25
In general:
A string w has length  number of states
A state q
must be repeated in the walk w
......
q
......
26
The Pumping Lemma
27
Take an infinite regular language L
DFA that accepts L
m
states
28
Take string w
with
w L
There is a walk with label w :
.........
29
| w |  m number
If string w has length
of states
Then, from the pigeonhole principle:
A state q is repeated in the walk w
......
q
......
30
Write
w x y z
y
......
x
q
......
z
31
Observations :
length | x y |  m
number
of states
length | y |  1
y
......
x
q
......
z
32
Observation:
The string x z is accepted
y
......
x
q
......
z
33
Observation:
The string x y y z
is accepted
y
......
x
q
......
z
34
Observation:
The string x y y y z
is accepted
y
......
x
q
......
z
35
In General:
The string
is accepted
i
xy z
i  0, 1, 2, ...
y
......
x
q
......
z
36
In other words, we described:
The Pumping Lemma
37
The Pumping Lemma:
1. Given a infinite regular language L
2. There exists an integer m
3. For any string w L with length | w |  m
4. We can write w  x y z
5. With
|x y|  m
6. Such that: string
|
y
|

1
and
i
xy z  L
i  0, 1, 2, ...
38
Applications of
the Pumping Lemma
39
Claim:
The language
n n
L  {a b : n  0}
is not regular
Proof:
Use the Pumping Lemma
40
Proof:
Assume for contradiction
that L is a regular language
Since L is infinite
we can apply the Pumping Lemma
41
Let m be the integer
in the Pumping Lemma
Pick a string w such that:
w L
length | w |  m
Example:
pick
m m
wa b
42
Write
m m
a b xyz
From the Pumping Lemma
| x y| m
it must be that length
m
Therefore:
m
a...aa...a...ab...b
x
y
z
ya
k
43
m m
ya
x y za b
From the Pumping Lemma:
k
i
xy z  L
i  0, 1, 2, ...
Thus:
2
xy z  L
2
x y zx y y za
m k m
b
 L
44
Therefore,
BUT:
a
m k m
b L
n n
L  {a b : n  0}
and
a
m k m
b L
CONTRADICTION!!!
45
Therefore:
Our assumption that L
is a regular language
cannot be true
CONCLUSION:
L is not a regular language
46
Claim:
R
The language L  {ww : w  *}
is not regular
Proof:
Use the Pumping Lemma
47
Proof:
Assume for contradiction
that L is a regular language
Since L is infinite
we can apply the Pumping Lemma
48
Let m be the integer
in the Pumping Lemma
Pick a string w such that:
w L
length | w |  m
Example:
pick w  a b b a
m m m m
49
Write
m m m m
a b b a xyz
From the Pumping Lemma
| x y| m
it must be that length
m
Therefore:
m m m
a...aa...a...ab...bb...ba...a
x
y
z
ya
k
50
m m m m
x y za b b a
From the Pumping Lemma:
ya
k
i
xy z  L
i  0, 1, 2, ...
2
xy z  L
Thus:
2
x y zx y y za
m k m m m
b b a
 L
51
Therefore,
BUT:
a
m k m m m
b b a
L
R
L  {ww : w  *}
and
a
m k m m m
b b a
L
CONTRADICTION!!!
52
Therefore:
Our assumption that L
is a regular language
cannot be true
CONCLUSION:
L is not a regular language
53