Kleene Closure

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

1

Kleene Theorem II
Logistics
Homework
Homework #2 change
Exercise 3.1.1 (b and c) pg 89
Exercise 3.1.4 (b and c) pg 90
Exercise 3.2.2 (a d) pg 106
Exercise 3.2.4 (b and c) pg 106
Exercise 3.2.5 (just c) pg 107
Questions
Any questions before we start?
Regular Languages
Today we continue looking at our first class
of languages: Regular languages
Means of defining: Regular Expressions
Machine for accepting: Finite Automata
Kleene Theorem
A language L over is regular iff there
exists an FA that accepts L.
1. If L is regular there exists an FA M such that
L = L(M)
2. For any FA, M, L(M) is regular
L(M), the language accepted by the FA can be
expressed as a regular expression.
Kleene Theorem
Last time we proved Part I
RE -> DFA
Today we tackle Part II
DFA -> RE
2
DFA -> RE
Given a DFA, A, there is a regular
expression R that described the language
accepted by A.
DFA -> RE
Basic idea
This proof is surprisingly much trickier than the first
We will consider a path of states taken by the machine
on a given input:
Will develop a recursive definition for a path from one state to
another using the operations +, concatenation, Kleene Star
This will be sufficient, since the language accepted by the DFA
is merely the union of paths starting from the start state leading
to accepting states, and that Regular Languages are closed
under union (by definition).
DFA -> RE
Some definitions:
A = (Q, , q
o
, , F)
Rij
Regular expression describing the set of all strings
that, on input, takes you from state i to state j.
DFA -> RE
More definitions:
In creating the RE, we will actually consider
paths that start at one state, ends at another, and
goes through even another.
i
k j
a
b
DFA -> RE
More definitions:
For a string x: we say that x represents a path
from i to j going through k if:
There are non-null strings y,z such that
x = yz
(i, y) = k
(k, z) = j
i
k j
y
z
^

DFA -> RE
Even more definitions
We will re-label each of the states of M to
correspond with the integers 1n, where n is
the number of states
R
ij
k
RE describing the set of strings representing paths
starting from i, ending at j, and going through no
state numbered higher than k.
3
DFA -> RE
Finally
R
ij
n
RE describing the set of strings represented by paths
starting at i, ending at j, going through no state
higher than n
Rij
We will construct R
ij
n
via induction on n
Questions?
DFA -> RE
Base step, n=0
Construct Rij
0
Rij
0
Regular expression describing set of all strings
represented by paths from i to j going through no
state number higher than 0.
Recall that states are numbered 1-n
I.e. Path must have no intermediate states
DFA -> RE
Base step, n=0
Construct Rij
0
3 cases
No direct transitions from i to j
Rij
0
=
Single transition from i to j (on a symbol a)
Rij
0
= a
Multiple transitions from i to j (on symbols a
1
, a
2,
, a
k
)
Rij
0
= a
1
+ a
2
, ++ a
k
DFA -> RE
Base step, n=0
Construct Rij
0
If i = j
Can get from i to j by not reading a symbol
Must add to Rij
0
Questions so far?
DFA -> RE
Induction
Assume that Rij
k-1
exists
Rij
k-1
=
RE describing the set of all strings represented by
paths starting at i, ending at j, going through no state
numbered higher than k-1.
Must construct Rij
k
DFA -> RE
Lets consider the set described by Rij
k
Set of all strings represented by paths starting at
i, ending at j, going through no state numbered
higher than k.
There are two ways this can occur for a string
x:
The path bypasses state kaltogether. In this case x is
in the language described by Rij
k-1
The path can start at i, get to state k, loop from k
back to k (0 or more times), then finally get to j
4
DFA -> RE
Rewrite x as yzw where
y is a string represented by the path from i to k
z is a string represented by the looping from k
to itself
w is a string represented by the path from k to j
i
k
j
y
w
z
DFA -> RE
Take special note
y does not go through any state higher than k-1,
so y is in the language described by R
ik
k-1
w does not go through any state higher than k-
1, so w is in the language described by R
kj
k-1
A single loop of z does not go through any state
higher than k-1, so z is in the language
described by R
kk
k-1
DFA -> RE
Putting it all together
Rij
k
= Rij
k-1
+ (R
ik
k-1
)(R
kk
k-1
)
*
(R
kj
k-1
)
Each of these exist by the inductive hypothesis
We have constructed a RE for Rij
k
DFA -> RE
Recall:
Rij
Regular expression describing the set of all strings
that, on input, takes you from state i to state j.
R
ij
n
= R
ij
L (A) = set of all strings that takes you from a start state
to a final state.
If we let the start state be state 1, then
L(A) can be described by the sum of R
1j
such that j is a
final state.
DFA -> RE
Lets look at an example
DFA -> RE
The set of all x accepted by this FA is:
Set of all strings starting at state 1, ending in
states 1 or 2, going through no state higher than
state 3.
Can be described by R
11
3
+ R
12
3
We will construct these starting from base case.
5
DFA -> RE
R
ij
0
3
2
1
R
i3
0
R
i2
0
R
i1
0
i
a +
b
a

b
a b

DFA -> RE
Recursion
Rij
k
= Rij
k-1
+ (R
ik
k-1
)(R
kk
k-1
)
*
(R
kj
k-1
)
Lets try a few
R
11
1
=
R
11
0
+ R
11
0
(R
11
0
)
*
R
11
0
(a + ) + (a + ) (a + )
*
(a + )
a
*
DFA -> RE
Lets try a few
R
12
1
=
R
12
0
+ R
11
0
(R
11
0
)
*
R
12
0
b + (a + ) (a + )
*
b
a
*
b
R
32
1
=
R
32
0
+ R
31
0
(R
11
0
)
*
R
12
0
b + a (a + )
*
b
a
*
b
DFA -> RE
R
ij
1
=
Rij
0
+ (R
i1
0
)(R
11
0
)
*
(R
1j
0
)

a
*
b aa
*
3
b
+ aa
*
b
aa
*
2

a
*
b a
*
1
R
i3
1
R
i2
1
R
i1
1
DFA -> RE
R
ij
2
=
Rij
1
+ (R
i2
1
)(R
22
1
)
*
(R
2j
1
)
+ a
*
b (aa
*
b)
*
b
a
*
b(aa
*
b)
* aa
*
+ a
*
(baa
*
)
(baa
*
)
*
3
(aa
*
b)
*
b (aa
*
b)
*
aa
*
(baa
*
)
*
2
a
*
(baa
*
)
*
bb a
*
(baa
*
)
*
b a
*
(baa
*
)
*
1
R
i3
2
R
i2
2
R
i1
2
DFA -> RE
R
ij
3
=
Rij
2
+ (R
i3
2
)(R
33
2
)
*
(R
3j
2
)
We only need R
11
3
and R
12
3
R
11
3
=
R
11
2
+ R
13
2
(R
33
2
)
*
R
31
2
a
*
(baa
*
)
*
+ a
*
(baa
*
)
*
bb( + a
*
b (aa
*
b)
*
b)
*
(aa
*
+ a
*
(baa
*
) (baa
*
)
*
)
You get the idea?
6
DFA -> RE
What have we found?
Given a DFA, we can find express the language
accepted by the DFA as a regular expression
I never claimed that this regular expression
would be pretty!
Questions
DFA -> RE
Note, for the truly interested:
The text does describe an alternate method of
getting from DFA -> RE via reducing states
We wont be covering this.
Summary
Pt 1
Given a regular language we built an -NFA
that accepts the language
Pt 2
Given a DFA, we constructed a regular
expression that describes the language accepted
by the DFA
Summary
The proof of Kleene Theorem is complete!
Questions?
Lets take a break

You might also like