Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transparency No. 8-1 Formal Language and Automata Theory Chapter 8 DFA state minimization (lecture 13, 14)

Similar presentations


Presentation on theme: "Transparency No. 8-1 Formal Language and Automata Theory Chapter 8 DFA state minimization (lecture 13, 14)"— Presentation transcript:

1 Transparency No. 8-1 Formal Language and Automata Theory Chapter 8 DFA state minimization (lecture 13, 14)

2 DFA state minimization Transparency No. 8-2 Motivations Problems: 1. Given a DFA M with k states, is it possible to find an equivalent DFA M’ (I.e., L(M) = L(M’)) with state number fewer than k ? 2. Given a regular language A, how to find a machine with minimum number of states ? Ex: A = L((a+b)*aba(a+b)*) can be accepted by the following NFA: By applying the subset construction, we can construct a DFA M2 with 2 4 =16 states, of which only 6 are accessible from the initial state {s}. stuv ab a a,b

3 DFA state minimization Transparency No. 8-3 Inaccessible states A state p  Q is said to be inaccessible (or unreachable) [from the initial state] if there exists no string x in  * s.t.  (s,x) = p (I.e., p  {q | x   *,  (s,x) = q }. ) Theorem: Removing inaccessible states from a machine M does not affect the language it accepts. Pf: M = : a DFA; p : an inaccessible state let M’ = be the DFA M with p removed. Hence  ’:(Q\{p})x  --> Q\{p} with  ’(q,a) = r if  (q,a) =r and q,r in Q \{p}. For M and M’ it can be proved by induction on x that for all x in  *, for all q in Q\{p},  (q,x) =  ’(q,x). Hence for all x   *, x  L(M) iff  ’(s,x) = q  F\{p} iff  (s,x) = q  F iff x  L(M). qed

4 DFA state minimization Transparency No. 8-4 Inaccessible states are redundant M : any DFA with n inaccessible states p 1,p 2,…,p n. Let M 1,M 2,..,M n+1 are DFAs s.t. DFA M i+1 is constructed from M i by removing p i from M i. I.e., M -rm(p 1 )-> M 1 -rm(p 2 )-> M 2 - … M n -rm(p n )-> M n+1 By previous lemma: L(M) = L(M 1 ) = …=L(M n+1 ) and M n+1 has no inaccessible states. Conclusion: Removing all inaccessible sates simultaneously from a DFA will not affect the language it accepts. In fact the conclusion holds for all NFAs we well. Pf: left as an exercise. Problem: Given a DFA (or NFA), how to find all inaccessible states ?

5 DFA state minimization Transparency No. 8-5 How to find all accessible states A state is said to be accessible if it is not inaccessible. Note: the set of accessible states A(M) of a NFA M is {q|  x  *, q   ( S,x) } and hence can be defined by induction. Let A k be the set of states accessible from initial states of M by at most k steps of transitions. I.e., A k = {q|  x  * with |x|  k and q   ( S,x) } What is the relationship b/t A(M) and A k s ? What is A 0 and the relationship b/t A k and A k+1 ? Formal definition: M= : any NFA. Basis: Every start state q  S is accessible.(A 0  A(M)) Induction: If q is accessible and p in  (q,a) for some a  , then p is accessible. (A k+1 =A k U {p | p   (q,a) for some q  A k and a  .)

6 DFA state minimization Transparency No. 8-6 An algorithm to find all accessible states: REACH(M) { // M = 1. A = S ; 2. B =  (A) - A ; 3. For k = 0 to |Q| do { // A = A k ; B = A K+1 - A k 4. A = A U B ; B =  (B) - A; if B = {} then break }; 5. Return(A) } Function  (S) { 1.  = {}; 2. For each q in Q do for each a in  do  =  U  (q,a); 3. Return(  }

7 DFA state minimization Transparency No. 8-7 Minimization process Minimization process for a DFA: 1. Remove all inaccessible states 2. Collapse all equivalent states What does it mean that two states are equivalent? both states have the same observable behaviors.i.e., there is no way to distinguish their difference, or more formally, we say p and q are equivalent iff there is no string x  * s.t.  (p,x)  F iff  (q,x)  F. Example[13.2]: (next slide) state 3 and 4 are equivalent. States 1 and 2 are equivalent. Equivalents sates can be merged to form a simpler machine.

8 DFA state minimization Transparency No. 8-8 0 1 24 3 a a a,b a b bb 5 0 5 1,23,4 a,b Example 13.2:

9 DFA state minimization Transparency No. 8-9 Quotient Construction M=(Q, , ,s,F): a DFA.  : a relation on Q defined by: p  q for all x   *  (p,x)  F iff  (q,x)  F Property:  is an equivalence relation. Hence it partitions Q into equivalence classes [p] = {q  Q | p  q} for p  Q. and the quotient set Q/  = {[p] | p  Q}. Every p  Q belongs to exactly one class [p] and p  q iff [p]=[q]. Define the quotient machine M/  = where Q’=Q/  ; s’=[s]; F’={[p] | p  F}; and  ’([p],a)=[  (p,a)] for all p  Q and a  . But well-defined ?

10 DFA state minimization Transparency No. 8-10 the function  ’ is well-defined. Lem 13.5. if p  q  then  (p,a)   (q,a). Hence if [p]=[q] then [  (p,a)] = [  (q,a)] Pf: By def. [  (p,a)] = [  (q,a)] iff  (p,a)   (q,a) iff ∀ y ∈  *  (  (p,a),y ) ∈ F   (  (q,a),y) ∈ F iff ∀ y ∈  *  (p, ay) ∈ F   (q,ay) ∈ F if p  q. Lemma 13.6. p ∈ F iff [p] ∈ F’. pf: => : trival. <=: need to show that if q  p and p ∈ F, then q ∈ F. But this is trival since p =  (p,  ) ∈ F iff  (q,  ) = q ∈ F

11 DFA state minimization Transparency No. 8-11 Properties of the quotient machine. Lemma 13.7: ∀ x ∈  *,  ’([p],x) = [  (p,x)]. Pf: By induction on |x|. Basis x =  :  ’([p],  ] = [p] = [  (p,  )]. Ind. step: Assume  ’([p],x) = [  (p,x)] and let a ∈ .  ’([p],xa) =  ’(  ’(p,x),a) =  ’([  (p,x)],a) --- ind. hyp. =[  (  (p,x),a)] -- def. of  ’ = [  (p,xa)]. -- def. of . Theorem 13.8: L(M/  ) = L(M). Pf: ∀ x ∈  *, x ∈ L(M/  ) iff  ’(s’,x) ∈ F’ iff  ’([s],x) ∈ F’ iff [  (s,x)] ∈ F’ --- lem 13.7 iff  (s,x) ∈ F --- lem 13.6 iff x ∈ L(M).

12 DFA state minimization Transparency No. 8-12 M/  cannot be collapsed furtuer Theorem: ((M/  M/  Pf: denote the second  by . I.e. [p]  [q] iff ∀ x ∈  *,  ’([p],x) ∈ F’   ’([q],x) ∈ F’ Now [p]  [q] iff ∀ x ∈  *,  ’([p],x) ∈ F’   ’([q],x) ∈ F’ -- def.of  iff ∀ x ∈  *, [  (p,x)] ∈ F’  [  (q,x)] ∈ F’ -- lem 13.7 iff ∀ x ∈  *,  (p,x) ∈ F   (q,x) ∈ F -- lem 13.6 iff [p]  [q] -- def of 

13 DFA state minimization Transparency No. 8-13 A minimization algorithm The algorithm: 1. Write down a table of all pairs {p,q}, initially unmarked. 2. mark {p,q} if p ∈ F and q ∉ F or vice versa. 3. Repeat until no more change: 3.1 if ∃ unmarked pair {p,q} s.t. {  (p,q),  (q,a)} is marked for some a ∈ , then mark {p,q}. 4. When done, p  q iff {p,q} is not marked. Let M k ( k ≥ 0 ) be the set of pairs marked after the k-th pass of step 3. [ and M 0 is the set of pairs before step 3.] Notes: 1. M = U k ≥0 M k is the final set of pairs marked by the alg. 2. The algorithm must terminate since there are totally only C(n,2) pairs and each pass of step 3 must marke at leat one pair.

14 DFA state minimization Transparency No. 8-14 An Example: The DFA: ab >012 1F34 2F43 355 455 5F55

15 DFA state minimization Transparency No. 8-15 Initial Table 1- 2-- 3--- 4---- 5----- 01234

16 DFA state minimization Transparency No. 8-16 After step 2 1M 2M- 3-MM 4-MM- 5M--MM 01234

17 DFA state minimization Transparency No. 8-17 After first pass of step 3 1M 2M- 3-MM 4-MM- 5MMMMM 01234

18 DFA state minimization Transparency No. 8-18 2nd pass of step 3. The result : 1  2 and 3  4. 1M 2M- 3M2MM 4 MM- 5MM1 MM 01234

19 DFA state minimization Transparency No. 8-19 Correctness of the collapsing algorithm Let M k ( k ≥ 0 ) be the set of pairs marked after the k-th pass of step 3. [ and M0 is the set of pairs befer step 3.] Lemma: {p,q} ∈ M k iff ∃ x ∈ S* of length ≤ k s.t.  (p,x) ∈ F and  (q,x) ∉ F or vice versa, Pf: By ind. on k. Basis k = 0. trivial. Ind. step: ∃ x ∈  * of length ≤ k+1 s.t.  (p,x) ∈ F   (q,x) ∉ F, iff ∃ x ∈  * of length ≤ k s.t.  (p,x) ∈ F   (q,x) ∉ F, or ∃ ax ∈  * of length ≤ k+1 s.t.  (  (p,a),x) ∈ F   (  (q,a),x) ∉ F, iff {p, q} ∈ M k or {  (p,a),  (q,a)} ∈ M  and a ∈ . iff {p,q} ∈ M k + 1. Theorem 14.3: The pair {p,q} is marked by the algorithm iff ∃ x ∈  * s.t.  (p,x) ∈ F   (q,x) ∉ F, (i.e., iff not(p  q) ) Pf: not(p  q) iff ∃ x ∈  * s.t.  (p,x) ∈ F   (q,x) ∉ F iff {p,q} ∈ M k for some k ≥ 0 iff {p,q} ∈ M = U k ≥ 0 M k.


Download ppt "Transparency No. 8-1 Formal Language and Automata Theory Chapter 8 DFA state minimization (lecture 13, 14)"

Similar presentations


Ads by Google