Professional Documents
Culture Documents
Chapter 7
Chapter 7
Method of proof
Theorem: Let A,B,C be sets such that AB, BC, CA.
Then A=B=C.
Proof: Let x be an element of B. xC (because BC). Also
xA (because CA). Thus BA, and we can conclude A=B.
By analogy, B=C and thus all the sets are equal.
Remark: Regular expressions, finite automata, and transition
graphs each define a set of languages.
Kleenes Theorem
Lemma 1: Every language that can be defined by a finite
automaton can also be defined by a transition
FTG
graph.
TGRE
Kleenes Theorem
Any language that can be defined by a regular expression, or
finite automaton, or transition graph can be defined by all
three methods.
Proof: By the lemmas above, and the theorem on
the previous page. (It remains to prove the lemmas.)
ab
3
1
3
aa
b
ab
2
4
aa
b
9+
aa
aba
12
+
aa
aba 12
b
Transform to a GTG
2. Combine edges that have the same starting and ending state.
r3
r1
r2
r1
3
r2
r1+ r2+ r3
r1 + r2
r1
r3
r1r3
r2
r1
r3
r1r2*r3
Bypass state 2
r2
r1
r3
2
r4
r5
r1r2*r3
r1r2*r4
r1r2*r5
ab
bbb
ba
bypass state 2,
paths through state 2: 1 24,
125,
324,
325
ab
bbb
ba
bypass state 2,
paths through state 2: 1 24,
125,
aba*ba
aba*b
324,
325
10
bbba*b
bbba*ba
11
r1
r3
r2
r4
r5 r6
11
4
5
r1r3*r4
r1r3*r6
r 234
r *r
9
r 236
r *r
r 135
r *r
11
4
r2r3*r5
5
11
Special cases
r2
r3
1
r4
r1
3 2 1,
121
r1 r2* r3
r4 r2* r3
12
r1
r2
1
r8
r5
r4
2
r3
r7
r6
r9
3 2 1,
323, 1 2 1,
1
123
3
r8+r2 r4*r5
r9+r6 r4*r3
r1+r2 r4*r3
13
r7+r6
r4*r5
14
r35
r1+r2+
+r
35
14
Example 1
a,b
aa
aa,bb
bb
Example 2: EVEN-EVEN
aa,bb
+
aa,bb
ab,ba
ab+ba
aa+bb
ab,ba
1
+
aa+bb
2
ab+ba
aa+bb
(ab+ba)(aa+bb)*(ab+ba)
Example 2: EVEN-EVEN
(aa+bb)+(ab+ba)(aa+bb)*(ab+ba)
[(aa+bb)+(ab+ba)(aa+bb)*(ab+ba)]*
Example 3
r4
r1
r2
r8
r9
r5
2
r3
3
r7
r6
r10
Kleenes Theorem
Lemma 3: Every language that can be defined by a regular
expression can also be defined by a finite automaton.
Proof: By constructive algorithm starting from the recursive
definition of regular expressions.
Remember: Given an alphabet , the set of regular expressions is
defined by the following rules.
1. For every letter in , the letter written in bold is a regular expression.
is a regular expression.
2. If r1 and r2 are regular expressions, so is r1+r2.
3. If r1 and r2 are regular expressions, so is r1 r2.
4. If r1 is a regular expression, so it r1*.
5. Nothing else is a regular expression.
Example: (a+b)*(aa+bb)(a+b)*
Build a finite automaton that accepts this language:
Rule:
1. The letter a
1
2. The letter b
1
3. The word aa (using 1)
3
4. The word bb (using 2)
3
5. The expression aa+bb (using 3 and 4)
2
6. The expression a+b (using 1 and 2)
2
7. The expression (a+b)* (using 6)
4
8. The expression (a+b)*(aa+bb) (using 7 and 5)
3
9. The expression (a+b)*(aa+bb)(a+b)* (using 8 and 7)
3
20
all
all
+
all
a,b
a
x1
+x3
x
2
x1
x2
+x3
a
x2
x3
x3
b
x1
x1
x3
b
+y1
y2
b
a
a
b
ab
y3 y2
+y1
y2 y3 y4 y4 y1
y1 y4
y2 y3
y4
Result: r1+r2
11+
a
9
b
1+
b
a
a
b
12
+
10
8+
Result: r1+r2
7+
a
a
4+
Example 2
b
x1
a
a
b
x2
+
ab
x1x2x1
+x2x2x1
(words ending in a)
a
y1
b
b
a
y2
+
ab
y1y1y2
+y2y1y2
(words ending in b)
Algorithm 1: r1+r2
Input:
FA 1: alphabet: states: x1, x2, x3, start state: x1
FA 2: alphabet: states: y1, y2, y3, start state: y1
plus final states and transitions
The new FA:
alphabet: states: z1, z2, z3, start state: x1 or y1
p
p
transitions: if zi= (xj or yk) and xj xnew and yk ynew
then znew= (xnew or ynew) for input p.
If xnew or ynew is a final state, then znew is a final state.
26
x1 or y2
+
x2 or y1
+
x2 or y2
+
x1 or y1
x1 or y1
x1 or y2
+
a
x2 or y2
+
b
a
x2 or y1
+
algorithm 1
+
xor
y2
1
+
xor
y1
2
27
algorithm 2
28
a,b
a,b
second letter is b
a,b
b
a
a
28
odd number of as
29
a,b
a,b
b
a
a
a
a,b
ab|abbaa
abab|bab
29
Example 2
b
x1
a
b
a,b
a
x2
x3
+
a
y1
b
b
a
y2
+
r1r2
b
z1
a
a
b
z2
b
a
z3
b
a
z4 +
31
Example 3
b
x1+
a
b
x2+
a,b
a
x3
r1: no double a
a,b
y1
y2
+
Example 3
a,b
x1 or y1
x2 or y2 or y1
z1
z2 +
a
b
b
a
b
z3+
x1 or y2 or y1
a,b
z4
+
x3 or y1 or y2
Example 4
a,b
x1
x3
+
a
x2
a
y1
a,b
b
b
a
y2
+
z1
r1r2
z3
a,b
z2
z4 +
b
z1
a
r2r1
z2
a
a
z3
z4
+
z6
+
b
z5
z7 +
b
36
37
x2
+
a,b
b
a,b
x3
+
x4
r: a* + aa*b
r*: words without double b, and that do not start with b.
r*
a
a
z1 +
z2
+
b
z4
+
a,b
b
z3
z 5+
Example 2
b
x1
a
b
Words ending in a
x2
+
b
a
b
x1
x1 or x2
+
b
b
x1
x1 or x2
+
40
Example 3
a
b
x1
x2
z1 +
z2
a,b
z3 +
a,b
a
a,b
b
(a+b)*aaa(a+b)*bbb(a+b)*
b
x1
x2
x3
x4
+
x1
x3 or x4
x2
a
a,b
bb+bbb
b
a,b
x4
+
50
Rule 2: r1+r2
x2
a
x1
b
a
b
a,b
a
b
y1
x3
y2
+
a
x4+
b
a,b
a
y1
y2
+
a
x1
b
b
x2
x3
a
x 4+
Rule 3: r1r2
a
a
w2
w1
b
x1
b
a
a,b
b
x3
+
b
w1
a
b
a
w2
b
b
x1
a
a
x2
a,b
b
x 3+