15 453 FORMAL LANGUAGES AUTOMATA AND COMPUTABILITY MINIMIZING
15 -453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
MINIMIZING DFAs THURSDAY Jan 24
IS THIS MINIMAL? NO 0 1 1 0 0 0
IS THIS MINIMAL? 0 1 1 0
THEOREM For every regular language L, there exists a UNIQUE (up to re-labeling of the states) minimal DFA M such that L = L(M)
NOT TRUE FOR NFAs 0 0
EXTENDING Given DFA M = (Q, Σ, , q 0, F) extend to ^ : Q Σ* → Q as follows: ^ (q, ε) = q ^ (q, ) = (q, ) ^ ^ (q, 1 … k+1 ) = ( (q, 1 … k ), k+1 ) Note: ^ (q 0, w) F M accepts w String w Σ* distinguishes states q 1 and q 2 iff ^ ^ (q 1, w) F (q 2, w) F
EXTENDING Given DFA M = (Q, Σ, , q 0, F) extend to ^ : Q Σ* → Q as follows: ^ (q, ε) = q ^ (q, ) = (q, ) ^ ^ (q, 1 … k+1 ) = ( (q, 1 … k ), k+1 ) Note: ^ (q 0, w) F M accepts w String w Σ* distinguishes states q 1 and q 2 iff ^ ^ exactly ONE of (q 1, w), (q 2, w) is a final state
Fix M = (Q, Σ, , q 0, F) and let p, q Q DEFINITION: p is distinguishable from q iff there is a w Σ* that distinguishes p and q p is indistinguishable from q iff p is not distinguishable from q iff for all w Σ*, ^ (p, w) F ^ (q, w) F
q 1 0, 1 1 q 0 q 2 0 0 q 3 1 ε distinguishes accept from non-accept states
Fix M = (Q, Σ, , q 0, F) and let p, q, r Q Define relation ~ : p ~ q iff p is indistinguishable from q p ~/ q iff p is distinguishable from q Proposition: ~ is an equivalence relation p ~ p (reflexive) p ~ q q ~ p (symmetric) p ~ q and q ~ r p ~ r (transitive) Proof (of transitivity): for all w, we have: ^ (p, w) F ^ (q, w) F ^ (r, w) F
Fix M = (Q, Σ, , q 0, F) and let p, q, r Q so ~ partitions the set of states of M into disjoint equivalence classes Proposition: ~ is an equivalence relation [q] = { p | p ~ q } Q q q 0
0 1 1 0 0 0
Algorithm MINIMIZE Input: DFA M Output: DFA MMIN such that: M MMIN (that is, L(M) = L(MMIN)) MMIN has no inaccessible states MMIN is irreducible || all states of MMIN are pairwise distinguishable Theorem: MMIN is the unique minimum DFA
Intuition: States of MMIN will be blocks of equivalent states of M We’ll find these equivalent states with a “Table-Filling” Algorithm
TABLE-FILLING ALGORITHM Input: DFA M = (Q, Σ, , q 0, F) Output: (1) DM = { (p, q) | p, q Q and p ~/ q } (2) EM = { [q] | q Q } IDEA: • We know how to find those pairs of states that ε distinguishes… • Use this and recursion to find those pairs distinguishable with longer strings • Pairs left over will be indistinguishable
TABLE-FILLING ALGORITHM Input: DFA M = (Q, Σ, , q 0, F) Output: (1) DM = { (p, q) | p, q Q and p ~/ q } (2) EM = { [q] | q Q } q 0 q 1 Base Case: p accepts and q rejects p ~/ q qi qn q 0 q 1 qi qn
TABLE-FILLING ALGORITHM Input: DFA M = (Q, Σ, , q 0, F) Output: (1) DM = { (p, q) | p, q Q and p ~/ q } (2) EM = { [q] | q Q } q 0 q 1 Base Case: p accepts and q rejects p ~/ q Recursion: if there is σ Σ and states p , q satisfying qi D D qn D q 0 q 1 qi qn (p, ) = p ~/ q (q, ) = q Repeat until no more new D’s
q 0 q 1 D q 2 D D q 3 D D D q 0 q 1 q 2 q 3 1 q 0 0 1 q 1 0 0, 1 0 q 2 1 q 3
0 q 1 1 1 q 0 q 1 D q 2 D q 3 q 0 q 3 D D q 1 q 2 q 3 0 0 0 q 2
Claim: If p, q are distinguished by Table. Filling algorithm, then p ~/ q Proof: By induction on the length of the string distinguishing them. If (p, q) is marked D at the start, then one’s in F and one isn’t, so ε distinguishes p and q Suppose (p, q) is marked D at a later point. Then there are states p , q , and string w such that: 1. (p , q ) are marked D p ~ / q (by induction) ^ (p , w) F and ^ (q , w) F 2. p = (p, ) and q = (q, ), where Σ The string w distinguishes p and q!
Claim: If p, q are not distinguished by Table. Filling algorithm, then p ~ q Proof (by contradiction): Suppose the pair (p, q) is not marked D by the algorithm, yet p ~ / q (a “bad pair”) Then there is a string w such that: ^ (p, w) F and ^ (q, w) F (Why is |w| >0 ? ) So, w = w , where Of all such bad pairs, let p, q beΣa pair with the p shortest Let = (p, )wand q = (q, ) Then (p , q ) is also a bad pair, but with a SHORTER w !
Algorithm MINIMIZE Input: DFA M Output: DFA MMIN (1) Remove all inaccessible states from M (2) Apply Table-Filling algorithm to get: EM = { [q] | q is an accessible state of M } Define: MMIN = (QMIN, Σ, MIN, q 0 MIN, FMIN) QMIN = EM, q 0 MIN = [q 0], FMIN = { [q] | q F } MIN( [q], ) = [ ( q, ) ] Must show MIN is well defined!
Algorithm MINIMIZE Input: DFA M Output: DFA MMIN (1) Remove all inaccessible states from M (2) Apply Table-Filling algorithm to get: EM = { [q] | q is an accessible state of M } Define: MMIN = (QMIN, Σ, MIN, q 0 MIN, FMIN) QMIN = EM, q 0 MIN = [q 0], FMIN = { [q] | q F } MIN( [q], ) = [ ( q, ) ] Claim: MMIN M
MINIMIZE 0 q 0 1 0 q 2 q 1 0 1 0 1 1
1 0 0 q 0 0 0, 1 q 0 q 4 q 1 1 q 2 q 1 D q 3 D D q 4 D D q 5 D D q 0 q 1 q 3 q 4 0, 1 q 5 0 q 3 q 5 1 1
1 0 0 q 4 q 1 1 0 q 0 0, 1 q 1 D 0 q 3 D D q 4 D D q 5 D D q 0 q 1 q 3 q 4 q 5 1 q 5
*MMIN is the unique minimal DFA equivalent to M Claim: Suppose M MMIN, and M has no inaccessible states and is irreducible. Then there is a bijection that preserves transitions between M and MMIN
*MMIN is the unique minimal DFA equivalent to M Claim: Suppose M MMIN, and M has no inaccessible states and is irreducible. Then there is a bijection that preserves transitions between M and MMIN Note: If M is minimal, then M has no inaccessible states and is irreducible. (So the Claim implies *) Corollary to the Claim: If M has no inaccessible states and is irreducible, then M is minimal. Proof: Let Mmin M be minimal. Then Mmin MMIN So, by Claim, both Mmin and M are isomorphic to MMIN NOT TRUE for NFAs !
*MMIN is the unique minimal DFA equivalent to M Claim: Suppose M MMIN, and M has no inaccessible states and is irreducible. Then there is a bijection that preserves transitions between M and MMIN Proof: We construct a map from MMIN to M recursively Base Case: q 0 MIN → q 0 Recursive Step: If p → p q Then q → q q
We need to prove: That is, for q Meverywhere MIN The map is all defined there is. Case: a q q M such that q → q Base → q The map is well defined 0 MIN 0 If q map MMINis, there is. Ifapstring w such that The a bijection Recursive Step: → p ^ MIN(q 0 MIN, w) = q Then q → q Let q = ^ (q 0 , w). q will q map q to q
Base Case: q 0 MIN → q 0 Recursive Step: If p → p q Then q → q q The map is well defined Suppose there exist q and q such that q → q and q → q We show that q and q are indistinguishable, so it must be that q = q
Suppose there exist q and q such that q → q and q → q Suppose q and q are distinguishable MMIN q Reject q 0 MIN v q 0 w q q 0 Contradiction! v w w Reject q u Accept q 0 MIN w Accept u M q
Base Case: q 0 MIN → q 0 Recursive Step: If p → p q Then q → q q The map is onto For all q M there is a q MMIN such that q → q If q M , there is w such that ^ (q 0 , w) = q Let q = ^ MIN(q 0 MIN, w)
The map is 1 -1 Suppose there are distinct p and q such that p → q and q → q Suppose p and q are distinguishable MMIN p q 0 MIN q q 0 w q Contradiction! v w q 0 q Reject q 0 MIN w Reject v u Accept w Accept u M
How can we prove that two regular expressions are equivalent?
WWW. FLAC. WS Finish reviewing Chapter 1 of the book and read 2. 1 & 2. 2 for next time
- Slides: 39