Академический Документы
Профессиональный Документы
Культура Документы
Kleene’s Theorem
• regular expression, or
• finite automata, or
• transition graph
Part 1: (FA ⇒ TG) Every language that can be defined by an FA can also
be defined by a transition graph.
7-1
CHAPTER 7. KLEENE’S THEOREM 7-2
Algorithm:
1. If T has more than one start state, add a new state and add arcs labeled
Λ going to each of the original start states.
b b
a a
1- 3 1 3
b b
a a
+
/\
a, b a a, b
... b => b a +
...
+ /\
a, b a, b
CHAPTER 7. KLEENE’S THEOREM 7-4
(a) If T has some state with n > 1 loops circling back to itself, where the
loops are labeled with regular expressions r1 , r2 , . . . , rn , then replace
the n loops with a single loop labeled with the regular expression
r1 + r2 + · · · + rn .
r1
=> r 1+ r2 + 3r
r2
r3
(b) If two states are connected by n > 1 direct arcs in the same di-
rection, where the arcs are labelled with the regular expressions
r1 , r2 , . . . , rn , then replace the n arcs with a single arc labeled with
the regular expression r1 + r2 + · · · + rn .
r1
=>
r +r
1 2
r2
CHAPTER 7. KLEENE’S THEOREM 7-5
r r
1 r1 r2
2
x y z => x z
r3
r r
1 r1 r *r
32
2
x y z => x z
CHAPTER 7. KLEENE’S THEOREM 7-6
z1 z1
r r* r
r1 0 n+1 1
r0 r2
x y z => x z2
2 r0 r*
. n+1 r2
.
rn . .
rn+1 . .
r0 r*
n+1 rn
zn zn
iii. If any other arcs led directly to y, divert them directly to the
zi ’s.
CHAPTER 7. KLEENE’S THEOREM 7-7
iv. Need to make sure that all paths possible in the original TG
are still possible after the bypass operation.
• Example
x r4
r1
w r2 r3 z
y r5
r1 (r2 r3 )* r4
=> w z
r1 r2 (r3 r2 )* r5
=> w z
r1 (r2 r3 )* r4 + r1 r2 (r3 r2 )* r5
CHAPTER 7. KLEENE’S THEOREM 7-8
• Example:
Example:
a ab ba
1- 2 3
bb abb /\
4 5+
/\ a, b
a
abba
1-
=> abb
a+b
bb 5+
=> 1-
a*(abba+abb+bb)(a+b)*
5+
CHAPTER 7. KLEENE’S THEOREM 7-10
Example:
-
/\ /\
b b b b b b
1- 2- 3+ 1 2 3
a => a /\
a b a a b a
4 5+ 4 5 +
a a /\
a, b a+b
=> - => -
/\ /\+b
b bb*
a 2 bb* a 2
a bb*a a bb*a(a+b)*
b b
4 5 + 4 +
a /\ a(a+b)*
a+b
CHAPTER 7. KLEENE’S THEOREM 7-11
=> - => -
/\+b /\+b
a 2 bb*(/\+a(a+b)*) 2 bb*(/\+a(a+b)*)
a a
b b
4 + 4 +
a(a+b)* a(a+b)*
a(ba)*a(a+b)* + ab(ab)*bb*(/\+a(a+b)*)
(/\+b)((ab)*bb*(/\+a(a+b)*) + a(ba)*a(a+b)*)
=> -
+
a(ba)*a(a+b)* + ab(ab)*bb*(/\+a(a+b)*)
• every regular expression can be built up from the letters of the alphabet
and Λ and ∅.
• Also, given some existing regular expressions, we can build new regular
expressions by applying the following operations:
1. union (+)
2. concatenation
3. closure (Kleene star)
• We will not include r+ in our discussion here, but this will not be a
problem since r+ = rr∗ .
CHAPTER 7. KLEENE’S THEOREM 7-13
Recall that we had the following recursive definition for regular expressions:
Based on the above recursive definition for regular expressions, we have the
following recursive definition for FA’s associated with regular expressions:
Rule 1:
x
- +
- {x}
+
_
-
CHAPTER 7. KLEENE’S THEOREM 7-15
F3 = {(x, y) ∈ K1 × K2 : x ∈ F1 or y ∈ F2 }.
x4
a, b
b a a, b
x3+
a
CHAPTER 7. KLEENE’S THEOREM 7-19
2S = {∅, {a}, {bb}, {ab}, {a, bb}, {a, ab}, {bb, ab}, {a, bb, ab}}.
Fact: If |S| < ∞, then |2S | = 2|S| ; i.e., there are 2|S| different
subsets of S.
π3 ({x, y1 , . . . , yn }, `)
(
{π1 (x, `), π2 (y1 , `), . . . , πn (y2 , `)} if π1 (x, `) 6∈ F1 ,
=
{π1 (x, `), π2 (y1 , `), . . . , πn (y2 , `), s2 } if π1 (x, `) ∈ F1 ,
b a a, b
x3+
a
a a b
x2,y2+ x3,y1 x3,y2,y1+ x1,y1,y2+
b a b b a
b a a
b
x1,y1 x1,y2+ x2,y1 x2,y2,y1+
b a
CHAPTER 7. KLEENE’S THEOREM 7-22
π2 ({x1 , . . . , xn }, `)
(
{π1 (x1 , `), . . . , π1 (xn , `)} if π1 (xk , `) 6∈ F1 for all k = 1, . . . , n,
=
{π1 (x1 , `), . . . , π1 (xn , `), s1 } if π1 (xk , `) ∈ F1 for some k = 1, . . . , n,
FA for L:
b
x2+
a
a a
x1- x3 b
b x4 a
FA for L*: a
x1+ a x4,x2,x1+ a
b -
b a a
x4 x2,x1+ b x2,x1,x3+ x1,x2,x3,x4+
a a
b b
a x3,x4 b
x3
b b
CHAPTER 7. KLEENE’S THEOREM 7-25
(a + b)∗ b
FA for L:
a x1- x2+ b
a
If we blindly applied previous method for constructing F A for L∗ , we
get the following:
a x1+ x2,x1+ b
-
a
Problem:
Solution:
• Given original FA F A1 having arcs going into the initial state, cre-
ate an equivalent FA Fg A1 having no arcs going into the initial state
by splitting the original start state x1 of F A1 into two states x1.1
and x1.2
x1.1 is the new start state of Fg A1 and is never visited again
after the first letter of the input string is read.
x1.2 in FgA1 corresponds to x1 after the first letter of the input
string is read.
• Then run algorithm to create FA for L∗ from the new FA Fg A1 .
new FA for L:
x1.1-
b
a a x2+ b
x1.2
b
a
FA for L*:
x1.1+
- b
a a x2, x1.1+ b
x1.2
b
a
CHAPTER 7. KLEENE’S THEOREM 7-27
Example:
a, b
a
a
b - b b a
a +
b
Note that
a FA must have from each state an arc labeled with each letter of
alphabet, while NFA does not.
a FA is deterministic, while a NFA may be nondetermisic.
An NFA can have repeated labels from any single state.
• Can transform any NFA with repeated labels from any single state to an
equivalent TG with no repeated labels from any single state.
2 ...
b
2 4
3 ... b b
a
^ ^
1 => 1
b
b
4 ... a
3 5
b
5 ...
• given two FA’s for two languages with regular expressions r1 and r2 , it
is easy to construct an NFA to accept language corresponding to regular
expression r1 + r2 .
CHAPTER 7. KLEENE’S THEOREM 7-31
Example:
FA1: FA2:
a, b a a
b
a, b a
b
a b - - +
b
b a
+ + a, b
a, b
NFA1+2
a, b a a
b
a, b a
a b
b b - +
b a
+ + a, b
a, b
• This works when neither of the original FA’s has any arcs going into
their original initial states.
• If one or both of the original FA’s has an arc going into its original
initial state, the newly constructed FA for the language corresponding
CHAPTER 7. KLEENE’S THEOREM 7-32