Docsity

AUTOMATA - DFA state minimization - KUMAR 6, Study notes of Theory of Automata

Partial preview of the text

Download AUTOMATA - DFA state minimization - KUMAR 6 and more Study notes Theory of Automata in PDF only on Docsity!

Formal Language and Automata Theory

Chapter 8

DFA state minimization

(lecture 13, 14)

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?

  1. 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}. s t u v a b (^) a a,b a,b

Inaccessible states are redundantM : any DFA with n inaccessible states p 1 ,p 2 ,…,p n

Let M 1

,M

2

,..,M

n+ are DFAs s.t. DFA M i+ is constructed from M i by removing pi from Mi. I.e., M - rm(p 1

)-> M

1

- rm(p 2

)-> M

2

- … M

n

- rm(p n

)-> M

n By previous lemma: L(M) = L(M 1

) = …=L(M

n ) and M n 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?

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 S *, q  D ( S ,x) } and hence can be defined by induction.  Let Ak be the set of states accessible from initial states of M by at most k steps of transitions. I.e., A k = {q| $ x S * with |x| k and q  D ( S ,x) }  What is the relationship b/t A(M) and A k s? sol: A(M) = U k≥

A

k

. Moreover A k

 A

k+  What is A 0 and the relationship b/t A k and A k+

Formal definition: M=<Q, S , d , S ,F> : any NFA. Basis: Every start state q  S is accessible.(A 0

 A(M))

Induction: If q is accessible and p in d (q,a) for some a  S , then p is accessible. (A k+

=A

k U {p | p  d (q,a) for some q A k and a  S .)

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 * s.t. D (p,x) F iff D (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.

a a a,b a a,b b b b

a,b (^0 ) a,b 1,2 3, a,b a,b a,b Example 13.2:

the function d’ is well-defined. Lem 13.5. if p q then d (p,a)  d (q,a). Hence if [p]=[q] then [ d (p,a)] = [ d (q,a)] Pf: By def. [ d (p,a)] = [ d (q,a)] iff d (p,a)  d (q,a) iff ∀ y ∈ S * D ( d (p,a),y ) ∈ F  D ( d (q,a),y) ∈ F iff ∀ y ∈ S * D (p, ay) ∈ F  D (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 = D (p, e ) ∈ F iff D (q, e ) = q ∈ F

Properties of the quotient machine. Lemma 13.7: ∀ x ∈ S *, D ’([p],x) = [ D (p,x)]. Pf: By induction on |x|. Basis x = e : D ’([p], e ] = [p] = [ D (p, e )]. Ind. step: Assume D ’([p],x) = [ D (p,x)] and let a ∈ S. D ’([p],xa) = d ’( D ’(p,x),a) = d ’([ D (p,x)],a) --- ind. hyp. =[ d ( D (p,x),a)] -- def. of d ’ = [ D (p,xa)]. -- def. of D. Theorem 13.8: L(M/ ) = L(M). Pf: ∀ x ∈ S *, x ∈ L(M/ ) iff D ’(s’,x) ∈ F’ iff D ’([s],x) ∈ F’ iff [ D (s,x)] ∈ F’ --- lem 13. iff D (s,x) ∈ F --- lem 13. iff x ∈ L(M).

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 additional pairs marked: 3.1 if ∃ unmarked pair {p,q} s.t. { d (p,q), d (q,a)} is marked for some a ∈ S , 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

iteration of step 3. [ and M

0

is the set of pairs before

step 3.]

Notes: (1) M = U

k ≥

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 iteration of step 3

must mark at least one pair for it to not terminate ..

An Example:  The DFA: a b

0 1 2 1F 3 4 2F 4 3 3 5 5 4 5 5 5F 5 5

After step 2 (M0) 1 M 2 M - 3 - M M 4 - M M - 5 M - - M M 0 1 2 3 4

After first pass of step 3 (M 1 ) 1 M 2 M - 3 - M M 4 - M M - 5 M M M M M 0 1 2 3 4

Correctness of the collapsing algorithm Let Mk ( k ≥ 0 ) be the set of pairs marked after the k - th itration of step 3. [ and M 0 is the set of pairs befer step 3.] Lemma: {p,q} ∈ Mk iff ∃ x ∈ S of length ≤ k s.t. D* (p,x) ∈ F and D (q,x) ∉ F or vice versa, Pf: By ind. on k. Basis k = 0. trivial. Ind. step: ∃ x ∈ S of length ≤ k+1 s.t. D* (p,x) ∈ F D (q,x) ∉ F, iff ∃ y ∈ S of length ≤ k s.t. D* (p,y) ∈ F D (q,y) ∉ F, or ∃ ay ∈ S of length ≤ k+1 s.t. D* ( d (p,a),y) ∈ F D ( d (q,a),y) ∉ F, iff {p , q} ∈ Mk or { d (p,a), d (q,a)} ∈ M k for some a ∈ S. iff {p,q} ∈ M k + 1 . Theorem 14.3: The pair {p,q} is marked by the algorithm iff ∃ x ∈ S * s.t. D (p,x) ∈ F  D (q,x) ∉ F, (i.e., iff not(p q) ) Pf: not(p q) iff ∃ x ∈ S * s.t. D (p,x) ∈ F D (q,x) ∉ F iff {p,q} ∈ Mk for some k ≥ 0 iff {p,q} ∈ M = U (^) k ≥ 0 Mk.