1. Equivalence with FA
* Any Regex can be converted to FA and vice versa,
because:
* Regex and FA are equivalent in their descriptive
power
** Regular language is one that is recognized by
some FA, remember?
Hence: (Lemma) if a language is described by a
RegEx, then it is a regular language.
See Proof: P.67, example 1.56
11/25/13
2. Lemma: If a language is regular, then it is
descried by a RegEx.
Because A is regular, it is accepted by a DFA. We
describe a procedure for converting DFAs into
equivalent RegEx.
Breaking the procedure into 2 parts, using a new
type of FA called Generalized Nondeterministic
Finite Automaton (GNFA)
Hence, 1st convert DFA to GNFA, then GNFA to
RegEx
11/25/13
3. GNFA is NFA, but Regex could be used as labels
on arrows. Figure 1.61 P.70 shows an example of
GNFA, which is on the special form that it should
ALWAYS have.
11/25/13
4. To convert a NFA to GNFA (and
keep the special form)
Add a new start state with ε arrow to the old start
Add a new accept state with ε arrow coming from
the old accept state.
If any arrow has more than one label, or there
are more than one arrow between two states on
the same direction, replace with one arrow and
“union” the labels
If two states have no arrows between them, add
an arrow with Φ label
11/25/13
5. Convert the GNFA to RegEx
In GNFA, the start and accept states are must,
and they're different, hence no. of states (k) of
any GNFA is always >=2.
If k>2, then GNFA is constructed by reducing the
number to k=2 (an arrow form start to accept
states) whose label is the RegEx.
Example, converting a 3 state DFA to RegEx.
3k DFA > 5k GNFA > 4k GNFA > 3k GNFA > 2k
GNFA > RegEx
11/25/13
6. Convert the GNFA to RegEx
The Challenge in reducing the states if greater than
2, by Ripping the a state out of the machine
(other than the start, accept states), we call it q rip ,
we repair the machine by altering the removed
qrip with labeled arrow. The label should cover the
absence of qrip .The new label form start to accept
states is the RegEx.
Figure 1.63 P. 72
11/25/13
7. Formal definition of GNFA
Just like the DFA, it's a 5-tuple with same parameters
except for δ, which can be given as:
δ: (Q - {qaccept }) X (Q – {qstart}) → R
R is the collection of all RegEx over the alphabet ∑,
The domain of the transition function is (Q - {qaccept })
X (Q – {qstart}) simply because in GNFA, an arrow
connects every state to every other state, except no
arrows are coming from qaccept or going to qstart.
Read: P.73 - 76
11/25/13
8. Nonregular Languages
Some languages cannot be recognized by any
FA (a limitation of FA)
Assume the language B = {0n1n | n>=0}. No DFA
can recognize it because the resulting number of
0s is unlimited, and therefore no DFA can
remember this number of possibilities.
But just because the language appears to require
unbounded memory doesn't mean it's nonregular.
So we need a method to prove the nonregularity
11/25/13
9. Nonregular Languages
Assume we have 2 languages C and D, over the
alphabet ∑ = {0,1}, where:
C = { w | w has an equal no. of 0s and 1s}, and
D = { w | w has an equal number of occurrences of
01 and 10 as substrings}
Which one is nonregular?
See problem 1.48
>> Difficult? We need a mathematical proof for
certainty.
11/25/13
10. The pumping lemma for regular
languages
Theorem (Pumping Lemma): “All regular
languages have a special property, if a language
doesn't have that property, it is not regular”.
The property states that all strings in the
language can be “pumped” if they are at least as
long as a certain special value called the
“pumping length”. In other words:
Such string contains a section that can be repeated
any number of times with the resulting string
remaining in the language
11/25/13
11. Pumping lemma: if A is a regular language, then
there is a number p (the pumping length) where,
if s is any string in A of length at least p, then s
may be divided into three pieces, s=xyz,
satisfying the conditions:
1- for each i>=0, xyiz ∈ A
2- |y| >0, and
3- |xy| <= p.
Figure 1.71 P.78
11/25/13
12. Nonregular languages
n
{a b : n≥ 0}
vv
R
:
Regular languages
a∗b
b∗c + a
b + c ( a + b )∗¿
¿
etc . ..
11/25/13
n
v ∈ {a , b }
∗¿
¿
¿
¿
20. Consider a DFA with 4
b
q1
b
b
a
q2
a
a
11/25/13
states
b
q3
a
q4
21. aaaab
Consider the walk of a “long’’ string:
(length at least 4)
A state is repeated in the walk of aaaab
a
q1
q2
b
q1
a
q3
a
a
q3
b
a
q2
b
q4
b
a
a
11/25/13
q2
q3
b
a
q4
23. aabb
Consider the walk of a “long’’ string:
(length at least 4)
Due to the pigeonhole principle:
A state is repeated in the walk of aabb
a
q1
q2
b
a
q3
b
q4
b
q4
b
b
q1
a
q2
a
a
11/25/13
q3
b
a
q4
24. The state is repeated as a result of
the pigeonhole principle
aabb
Walk of
Pigeons:
q1
a
a
q2
q3
b
q4
b
q4
(walk states)
Are more than
Nests:
(Automaton states)
11/25/13
q1
q2
q3
Automaton States
q4
Repeated
state
25. In General:
If ∣w∣ ≥ #states of DFA,
by the pigeonhole principle,
a state is repeated in the walk
Walk of
q1
σ1
σ2
....
σi
w = σ 1 σ 2 ⋯σ k
qi
σ i +1
σj
....
qi
σ j+1
....
σk
Arbitrary DFA
q1
11/25/13
σ1
σ2
w
......
qi
......
Repeated state
σk
qz
qz
26. ∣w∣ ≥ #states of DFA =m
Pigeons: (walk states)
....
q1
Walk of
qi
....
w
qi
....
qz
Are
more
than
Nests:
q1
q2
(Automaton states)
11/25/13
....
qi
....
A state is
repeated
q m−1
qm
28. Take an infinite regular language
L
(contains an infinite number of strings)
There exists a DFA that accepts
L
m
states
11/25/13
29. Take string
w ∈L
∣w∣ ≥ m
with
(number of
states of DFA)
then, at least one state is repeated
in the walk of w
Walk in DFA of
w = σ 1 σ 2 ⋯σ k
σ1
σ2
......
q
......
σk
Repeated state in DFA
11/25/13
30. There could be many states repeated
Take q to be the first state repeated
One dimensional projection of walk
w
:
First
occurrence
σ1
σ2
....
σi
Second
occurrence
q
σ i +1
Unique states
11/25/13
....
σj
q
σ j+1
....
σk
31. We can write
w = xyz
One dimensional projection of walk
w
:
First
occurrence
σ1
σ2
....
x=σ 1 ⋯σ i
11/25/13
σi
Second
occurrence
q
σ i +1
....
y =σ i +1 ⋯σ j
σj
q
σ j+1
....
σk
z=σ j +1 ⋯σ k
32. In DFA:
w=x y z
contains only
first occurrence of
y
...
σj
...
σ1
11/25/13
x
σi
σ i +1
q
σ j+1
...
...
z
σk
q
33. Observation:
length
∣x y∣ ≤ m
number
of states
of DFA
y
...
Unique States
σj
...
σ1
11/25/13
x
σi
σ i +1
q
Since, in xy no
state is repeated
(except q)
42. The Pumping Lemma:
• Given a infinite regular language
• there exists an integer
• for any string w ∈ L
• we can write
(critical length)
with length ∣w∣ ≥ m
w=x y z
• with ∣x y∣ ≤ m
• such that:
11/25/13
m
L
i
and
x y z ∈L
∣ y∣ ≥ 1
i=0, 1, 2, . ..
45. 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)
11/25/13
46. Suppose you want to prove that
An infinite language L is not regular
1. Assume the opposite: L
is regular
2. The pumping lemma should hold forL
3. Use the pumping lemma to obtain a
contradiction
4. Therefore, L is not regular
11/25/13
47. Explanation of Step 3: How to get a contradiction
1. Let m
be the critical length for
2. Choose a particular stringw ∈ L
∣w∣≥m
the length condition
3. Write
L
which satisfies
w=xyz
4. Show that
'
i
w =xy z∉L
for some
5. This gives a contradiction, since from
'
i
pumping lemma
w =xy z∈L
11/25/13
i≠1
48. Note:
It suffices to show that
only one string w ∈ L
gives a contradiction
You don’t need to obtain
contradiction for everyw ∈ L
11/25/13
49. Example
Theorem: L = { 0 n 1 n | n ∈ N } is not regular.
Proof: By contradiction; assume L is regular. Let n
be the pumping length guaranteed by the
pumping lemma.
Consider the string w = 0 n 1 n . Then |w| = 2n ≥ n
and w ∈ L, so we can write
w = xyz such that y ≠ ε and for any natural
number i, xyiz ∈ L. We
consider three cases:
50. Case 1: y consists solely of 0s. Then xyiz = xz = 0 n - |y| 1 n ,
and since
|y| > 0, xz ∉ L.
Case 2: y consists solely of 1s. Then xy i z = xz = 0 n 1 n - |y| , and
since
|y| > 0, xz ∉ L.
Case 3: y consists of k 0s followed by m 1s. Then xy i z has
the
form 0 n 1 m 0 k 1 n + m , so xy i z ∉ L.
In all three cases we reach a contradiction, so our
assumption was
wrong and L is not regular. ■
51. Example of Pumping Lemma application
Theorem:
The language
n
n
L={a b : n≥0}
is not regular
Proof:
11/25/13
Use the Pumping Lemma
52. n
n
L={a b : n≥0}
Assume for contradiction
thatL
is a regular language
SinceL
is infinite
we can apply the Pumping Lemma
11/25/13
53. n
n
L={a b : n≥0}
Let
m
be the critical length for L
Pick a string
w
such that: w ∈ L
and length ∣w∣ ≥m
We pick
11/25/13
m
w=a b
m
54. From the Pumping Lemma:
m m
we can write
w=a b =x y z
with lengths
∣x y∣ ≤m , ∣ y∣≥1
m
w=
m
m m
xyz=a b = a ...aa ... aa .. . ab.. . b
x
11/25/13
Thus:
k
y
z
y =a , 1≤k ≤m
55. m m
k
y =a , 1≤k ≤m
x y z=a b
From the Pumping Lemma:
i
x y z ∈L
i=0, 1, 2, . ..
Thus:
11/25/13
2
x y z ∈L
56. m m
k
y =a , 1≤k ≤m
x y z=a b
2
x y z ∈L
From the Pumping Lemma:
m+k
m
2
xy z= a...aa...aa ...aa...ab...b ∈L
x
Thus:
11/25/13
y
a
y
m+k
z
m
b ∈L