Lecture 6: Quotient Construction

advertisement
CS 172: Computability and Complexity
Fall 2003
Lecture 6: Quotient Construction
c Tom Henzinger
°
6.1 Example. Consider the following DFA A:
0
B
D
0
0,1
1
A
F
0,1
0
1
0,1
C
E
1
This automaton accepts all 2-letter words; that is, L(A) = {00, 01, 10, 11}. There are other DFAs which
define the same language. For example, L(A) = L(B) for the following automaton B:
R
0,1
S
0,1
T
0,1
U
0,1
Indeed, B is the smallest DFA that accepts L(A), because every DFA C with L(C) = L(A) must have at
least four states (it must remember if it has seen 0, 1, 2, or more input letters).
6.2 State equivalence. Given a finite automaton M and a state p of M , we write M p for the finite
automaton which results from M by changing the initial state to p; that is, if M = (Q, Σ, δ, q 0 , F ), then
Mp = (Q, Σ, δ, p, F ). Two states p and q of M are equivalent, written p ≈M q, iff L(Mp ) = L(Mq ). If started
from equivalent states, the automaton accepts and rejects the same words. For Example 6.1:
L(AA ) = L(BR ) = {00, 01, 10, 11}.
L(AB ) = L(AC ) = L(BS ) = {0, 1}.
L(AD ) = L(AE ) = L(BT ) = {ε}.
L(AF ) = L(BU ) = ∅.
It follows that B and C are equivalent states of automaton A, and so are D and E. No two states of automaton
B are equivalent. Automaton B can be viewed as resulting from A by collapsing equivalent states into a
single state:
State
State
State
State
corresponds to state A.
results from collapsing states B and C.
T results from collapsing states D and E.
U corresponds to state F.
R
S
In the following, we shall see that we can always arrive at the smallest DFA for a regular language L by
starting from any DFA for L and collapsing equivalent states. This is called the quotient construction.
6.3 Quotient automaton. Given a finite automaton M = (Q, Σ, δ, q0 , F ), the quotient automaton M/≈ =
(Q0 , Σ, δ 0 , q00 , F 0 ) is defined as follows:
Q0 = Q/≈M , the set of ≈M -equivalence classes.
R ∈ δ 0 (P, a) iff there exist two states r ∈ R and p ∈ P such that r ∈ δ(p, a).
q00 = [q0 ]≈M , the ≈M -equivalence class of q0 .
R ∈ F 0 iff there exists a state r ∈ R such that r ∈ F .
1
Each state of M/≈ corresponds to a set of equivalent states in M . Since these sets (the ≈M equivalence
classes) are nonempty and pairwise disjoint, the quotient automaton M/ ≈ has no more states than M . In
Example 6.1, the ≈A -equivalence classes are
{A}, {B, C}, {D, E}, {F}
and A≈ = B.
6.4 Language of the quotient automaton. The quotient construction does not change the language of
a finite automaton: L(M ) = L(M/≈ ) for all finite automata M . We prove a stronger statement.
Given a
S
language L, let Li be the set of words in L which contain at most i letters; that is, L = i≥0 Li . We prove:
For every finite automaton M , every state p of M , and every i ≥ 0,
Li (Mp ) = Li ((M/≈ )[p]≈M ). (†)
First, we show that for every accepting run of Mp , there is a run of (M/≈ )[p]≈M that accepts the same word.
Consider an accepting run
p = p0
a
a
p1
→1
···
a
[p1 ]≈M
→1
→0
a
n
→
pn+1 ∈ F
of Mp . Then
[p0 ]≈M
→0
a
···
a
n
→
[pn+1 ]≈M ∈ F 0
is an accepting run of (M/≈ )[p]≈M . Second, we show that for every accepting run of (M/≈ )[p]≈M , there is
run of Mp that accepts the same word. This must be argued by induction on the length i of the accepted
word. Base case:
If there is a run of (M/≈ )[p]≈M which accepts ε, then [p]≈M ∈ F 0 ; that is, there is a state q ∈ F
such that p ≈M q. Since q ∈ F , we have ε ∈ L(Mq ). Since p ≈M q, we have ε ∈ L(Mp ); that is,
there is a run of Mp which accepts ε.
Inductive step:
We assume that the statement (†) holds for i, and prove that it holds also for i + 1. If there
is a run of (M/≈ )[p]≈M which accepts ax, then there is an equivalence class R ∈ δ 0 ([p]≈M , a)
such that x ∈ L((M/≈ )R ); that is, there are two states q and q 0 of M such that p ≈M q and
q 0 ∈ δ(q, a) and x ∈ L((M/≈ )[q0 ]≈M ). Since |x| ≤ i, from the induction hypothesis it follows that
x ∈ L(Mq0 ). Since q 0 ∈ δ(q, a), we have ax ∈ L(Mq ). Since p ≈M q, we have ax ∈ L(Mp ); that
is, there is a run of Mp which accepts ax.
6.5 Determinism of the quotient automaton. The quotient construction and the result of Section 6.4
apply to both DFAs and NFAs. It is important to observe that if M is deterministic, then also M/ ≈ is
deterministic. To see this, consider two states p and q of a DFA M such that p ≈ M q. We need to show that
δ(p, a) ≈M δ(q, a). Consider x ∈ L(Mδ(p,a) ). Then ax ∈ L(Mp ). Since p ≈M q, we have ax ∈ L(Mq ). Since
M is deterministic, x ∈ L(Mδ(q,a) ).
6.6 Approximating state equivalence. To compute the quotient automaton M/ ≈ , we need to check
whether L(Mp ) = L(Mq ) for every pair p, q of states. This is a quadratic number of equivalence checks,
each requiring quadratic time for DFAs (and exponential time for NFAs). However, we can do better to
compute M/≈ . Define p ≈iM q iff Li (Mp ) = Li (Mq ). Note:
p ≈M q iff p ≈iM q for all i ≥ 0.
i+1
i
Each ≈iM -relation defines a partition on the state space Q. Since p ≈i+1
M q implies p ≈M q, the ≈M -partition
of Q refines the ≈iM -partition. For Example 6.1:
2
≈0A -partition:
≈1A -partition:
≈2A -partition:
≈3A -partition:
{A, B, C, F}, {D, E}
{A, F}, {B, C}, {D, E}
{A}, {B, C}, {D, E}, {A}
{A}, {B, C}, {D, E}, {A}
In general, we can compute ≈M by first computing ≈0M , then ≈1M , then ≈2M , etc.:
(1) p ≈0M q iff either p, q ∈ F or p, q 6∈ F .
i
i
(2) p ≈i+1
M q iff p ≈M q and for all a ∈ Σ, we have δ(p, a) ≈M δ(q, a).
i
Note that (2) holds only for deterministic automata. By (2), once ≈i+1
M = ≈M for some i ≥ 0, it follows that
j
i
i
≈M = ≈M for all j ≥ i, and therefore, ≈M = ≈M . Since the finest possible partition of Q is the one where
each state forms an equivalence class by itself, if |Q| = n, then there must be some i ≤ n such that ≈ i+1
M =
≈iM (for automaton A of Example 6.1, we have i = 2). Hence we can compute ≈ M by computing at most n
so-called approximations: ≈0M , ≈1M , . . . , ≈nM . Using (2), each approximation ≈i+1
M can be computed from the
previous approximation ≈iM in time n2 · |Σ|. The overall running time for computing ≈M is therefore n3 · |Σ|.
6.6 Minimization algorithm. The minimization algorithm organizes the computation of ≈ 0M , ≈1M , . . . ,
≈nM by filling in the entries below the diagonal of an n × n matrix D whose entries are initially all blank, so
that when the algorithm is completed:
D[p, q] = i iff p 6≈iM q, but p ≈jM q for all j < i;
D[p, q] remains blank iff p ≈M q.
First, we fill in the 0 entries according to the negation of (1):
p 6≈0M q iff either p ∈ F and q 6∈ F , or p 6∈ F and q ∈ F .
For automaton A of Example 6.1:
A
B
C
D
E
0
0
0
0
0
0
A
B
C
F
0
0
D
E
F
Next, we fill in the 1 entries according to the negation of (2):
p 6≈1M q iff either p 6≈0M q or there exists a ∈ Σ such that δ(p, a) 6≈0M δ(q, a).
For automaton A of Example 6.1:
A
B
C
D
E
1
1
0
0
F
A
0
0
1
0
0
1
0
0
B
C
D
E
F
Then, we fill in the 2 entries according to the negation of (2):
p 6≈2M q iff either p 6≈1M q or there exists a ∈ Σ such that δ(p, a) 6≈1M δ(q, a).
For automaton A of Example 6.1:
3
A
B
C
D
E
F
1
1
0
0
2
0
0
1
0
0
1
0
0
A
B
C
D
E
F
When we try to fill in the 3 entries, we notice that there are no 3 entries in this example. Hence ≈ 2A = ≈3A
= ≈A . Since D[C, B] and D[E, D] remain blank, we conclude that B ≈A C and D ≈A E. No other states are
equivalent.
4
Download