Slides
Slides
Peter Cappello
Department of Computer Science
University of California, Santa Barbara
Santa Barbara, CA 93106
[email protected]
1
Unification
Theorem: Any language that can be defined by
• a regular expression, or
• a finite automaton, or
• a transition graph
can be defined by all 3 methods.
2
Proof Architecture
Part 1 Every language that can be defined by an FA can be defined by
a TG.
Part 2 Every language that can be defined by a TG can be defined by a
regular expression.
Part 3 Every language that can be defined by a regular expression can
be defined by an FA.
Proof of Part 1
3
Turning TGs into Regular Expressions
Proof of Part 2
4
Transform the TG into T G0 with a unique start state
• Illustrate.
• T G0 has only 1 start state.
• If word w is accepted by the original TG, it is accepted by T G0.
• If word w is accepted by T G0, it is accepted by the original TG; every
start state of the original TG is reachable from s0 without consuming
any input.
5
Transform the T G0 into T G00 with a unique final state
• Illustrate.
• T G00 has only 1 final state.
• If word w is accepted by T G0, it is accepted by T G00.
• If word w is accepted by T G00, it is accepted by T G0; if there is a
successful path for w in T G00, it must go through a final state in T G0,
and transits without consuming any more input to f 00.
6
Some Transformation Methods
eliminateMultipleSelfLoops() {
replace multiple self-loops with 1 self-loop labelled with th
sum of the labels.
}
Illustrate.
eliminateMultipleTransitions() {
if there are multiple transitions between states $p$ and $q$,
replace them with 1 transition, labelled with the sum of the
}
Illustrate.
7
bypassAState(p, q, t) {
if (p, e1, q) and (q, e2, t) are transitions,
where e1 and e2 are strings or regular expressions,
replace them with transition (p, e1 e2, t).
}
Illustrate.
bypassASelfLoopState(p, q, t) {
if (p, e1, q) and (q, e2, t) are transitions,
where e1 and e2 are strings or regular expressions,
and q has a self-loop labelled e3,
replace them with transition (p, e1 e3* e2, t).
}
Illustrate.
8
omitAState() {
if a state has transitions neither into nor out of it,
omit it.
}
Illustrate.
eliminateMultipleTransitions(s, f) {
if the GTG has only a start and a final state with multiple t
replace the transitions with their sum.
}
Illustrate.
9
Algorithm
1. Transform the TG so that it has a unique source start state, and a
unique sink final state.
2. while ( |Q| > 2 ) eliminate any internal state:
If state q’s inDegree = i and its outDegree = o, perform i ∗ o
bypass operations. Delete q.
Eliminate multiple transitions between 2 states, in favor of a single
transition, labelled with the sum of the labels.
3. When only the start and final state remain, output the sum of the
regular expressions on the arcs connecting them.
Illustrate.
10
Where we are in the proof
Part 1 Every language that can be defined by an FA can be defined by
a TG.
Part 2 Every language that can be defined by a TG can be defined by a
regular expression.
Part 3 Every language that can be defined by a regular expression can
be defined by an FA.
11
Proof of Part 3
• The proof exploits the recursive nature of regular expressions.
• For each of the 3 rules for building a regular expression, we give a
construction of an FA.
• Thus, as we build up the regular expression, we build up an FA that
accepts the language denoted by the regular expression.
12
Proof of Part 3, Rule 1
Rule 1
• There is an FA that accepts the empty language.
• There is an FA that accepts only the word Λ.
• For each letter of the alphabet, there is an FA that accepts the 1
word consisting of only that letter.
Illustrate.
13
Proof of Part 3, Rule 2
Rule 2 Given:
• FA E that accepts the language denoted by regular expression e
• FA F that accepts the language denoted by regular expression f
There exists an FA that accepts L(e + f ).
Illustrate with:
• (a + b)∗aa(a + b)∗, all strings with a double a
• (a + b)∗b, all strings that end in b.
14
Proof of Part 3, Rule 2: Construction
Construct FA Z = (QZ , Σ, z0, FZ , δZ ), given
• FA X = (QX , Σ, x0, FX , δX )
• FA Y = (QY , Σ, y0, FY , δY ).
1. QZ = QX × QY .
2. z0 = (x0, y0).
3. (x, y) ∈ FZ if x ∈ FX or y ∈ FY .
4. δZ ((x, y), a) = (x0, y 0), where
• δX (x, a) = x0, for x, x0 ∈ QX and a ∈ Σ.
• δY (y, a) = y 0, for y, y 0 ∈ QY and a ∈ Σ.
15
Part 3, Rule 2: Another illustration
Illustrate with:
• (b + ab∗a)∗, all strings with an even number of a’s
• (a + ba∗b)∗, all strings with an even number of b’s.
16
Proof of Part 3, Rule 3
Rule 3 Given:
• FA E that accepts the language denoted by regular expression e
• FA F that accepts the language denoted by regular expression f
There exists an FA that accepts L(ef ).
Illustrate with:
• (a + b)∗aa(a + b)∗, all strings with a double a
• (a + b)∗b, all strings that end in b.
17
Proof of Part 3, Rule 3: Construction
Construct FA Z = (QZ , Σ, z0, FZ , δZ ), given
• FA X = (QX , Σ, x0, FX , δX )
• FA Y = (QY , Σ, y0, FY , δY ).
1. QZ = QX × 2QY .
2. Start state:
(x0, {}), x0 ∈ / QX ;
z0 =
(x0, {y0}), otherwise.
3. Final states: (x, {yi1 , yi2 , . . . , yij }) ∈ FZ if any yi ∈ FY .
18
4. δ function. Let
• (x, {yi1 , yi2 , . . . , yij }) ∈ QZ
• δX (x, a) = x0, for x, x0 ∈ QX and a ∈ Σ.
• δY (yik , a) = yi0k , for yik , yi0k ∈ QY and a ∈ Σ.
Then,
(x0, {yi01 , yi02 , . . . , yi0j }), x0 ∈
/ FX ;
δZ ((x, {yi1 , yi2 , . . . , yij }), a) = 0 0 0 0
(x , {yi , yi , . . . , yi } ∪ {y0 }), otherwise
1 2 j
Illustrate with:
• All strings without a double a.
• All strings of odd length.
19
Proof of Part 3, Rule 4
• Rule 4: Let FA X accept the language denoted by regular expression
e.
• There exists an FA Z that accepts L(e∗).
• The ideas:
20
Why is this a potential problem?
21
Proof of Part 3, Rule 4: Construction
Construct FA Z = (QZ , Σ, z0, FZ , δZ ), given
• FA X = (QX , Σ, x0, FX , δX ).
1. QZ = 2QX − any subset that contains a final state, but not the start
state.
2. Start state: z0 = {}.
• δZ (z0, a) = δ(x0, a);
• δZ (z0, b) = δ(x0, b);
3. Final states: {z0} ∪ { Every z ∈ QZ that contains an x ∈ FX }.
4. δ function. Let
22
• {xi1 , xi2 , . . . , xij } ∈ QZ
• δX (xik , a) = x0ik , for xik , x0ik ∈ QX and a ∈ Σ.
Then,
{x0i1 , x0i2 , . . . , x0ij }), no x0 ∈ FX ;
δZ ({xi1 , xi2 , . . . , xij }), a) = 0 0 0
{xi , xi , . . . , xi } ∪ {x0 }), otherwise
1 2 j
Illustrate with an FA that accepts all strings with an odd number of b’s.
23
Nondeterministic Finite Automata
Definition
24
NFA: Theorem
Theorem
Proof
25
NFA: Theorem
Theorem
Alternate Proof
26
•
– Let qa = {q1, q2, . . . , qj } ∈ QN .
– Define δA({q1, q2, . . . , qj }, a) = {q10 , q20 , . . . , qj0 }, where δN (qi, a) =
qi0 .
– δA({}, a) = {}.
27