Presentation is loading. Please wait.

Presentation is loading. Please wait.

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA.

Similar presentations


Presentation on theme: "FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA."— Presentation transcript:

1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA

2 MINIMIZING DFAs THURSDAY Jan 24

3 IS THIS MINIMAL? 1 1 1 1 0 0 0 0 NO

4 IS THIS MINIMAL? 0 1 0 1

5 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)

6 NOT TRUE FOR NFAs 0 0 0 0

7 EXTENDING  Given DFA M = (Q, Σ, , q 0, F) extend  to  : Q  Σ* → Q as follows:  (q, ε) =  (q,  ) =  (q,  1 …  k+1 ) =  (  (q,  1 …  k ),  k+1 ) ^ ^ ^ ^ ^ String w  Σ* distinguishes states q 1 and q 2 iff  (q 1, w)  F   (q 2, w)  F ^ ^ q  (q,  ) ^ Note:  (q 0, w)  F  M accepts w

8 EXTENDING  Given DFA M = (Q, Σ, , q 0, F) extend  to  : Q  Σ* → Q as follows:  (q, ε) =  (q,  ) =  (q,  1 …  k+1 ) =  (  (q,  1 …  k ),  k+1 ) ^ ^ ^ ^ ^ String w  Σ* distinguishes states q 1 and q 2 iff q  (q,  ) ^ Note:  (q 0, w)  F  M accepts w exactly ONE of  (q 1, w),  (q 2, w) is a final state ^ ^

9 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 ^ ^

10 0 0,1 0 0 1 1 1 q0q0 q1q1 q2q2 q3q3 ε distinguishes accept from non-accept states

11 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 ^ ^ ^

12 Fix M = (Q, Σ, , q 0, F) and let p, q, r  Q Proposition: ~ is an equivalence relation so ~ partitions the set of states of M into disjoint equivalence classes q0q0 Q q [q] = { p | p ~ q }

13 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) so ~ partitions the set of states of M into disjoint equivalence classes q0q0 Q q [q] = { p | p ~ q }

14 1 1 1 1 0 0 0 0

15 Algorithm MINIMIZE Input: DFA M Output: DFA M MIN such that: M  M MIN (that is, L(M) = L(M MIN )) M MIN has no inaccessible states M MIN is irreducible all states of M MIN are pairwise distinguishable || Theorem: M MIN is the unique minimum DFA

16 Idea: States of M MIN will be blocks of equivalent states of M Theorem: M MIN is the unique minimum Must show: Suppose M’  M, then 1. # states in M’  # states in M MIN 2. If # states in M’ = # states in M MIN then M’ is isomorphic to M MIN (i.e. same up to re-labeling of states)

17 Intuition: States of M MIN will be blocks of equivalent states of M We’ll find these equivalent states with a “Table-Filling” Algorithm

18 TABLE-FILLING ALGORITHM Input: DFA M = (Q, Σ, , q 0, F) Output: (2) E M = { [q] | q  Q } (1) D M = { (p,q) | p,q  Q and p ~ q } / q0q0 q1q1 qiqi qnqn q0q0 q1q1 qiqi qnqn Base Case: p accepts and q rejects  p ~ q / Recursion: ddd d d p p q q ~/    p ~ q /

19 TABLE-FILLING ALGORITHM Input: DFA M = (Q, Σ, , q 0, F) (2) E M = { [q] | q  Q } (1) D M = { (p,q) | p,q  Q and p ~ q } / 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 IDEA: Output:

20 TABLE-FILLING ALGORITHM Input: DFA M = (Q, Σ, , q 0, F) Output: (2) E M = { [q] | q  Q } (1) D M = { (p,q) | p,q  Q and p ~ q } / q0q0 q1q1 qiqi qnqn q0q0 q1q1 qiqi qnqn Base Case: p accepts and q rejects  p ~ q /

21 TABLE-FILLING ALGORITHM Input: DFA M = (Q, Σ, , q 0, F) Output: (2) E M = { [q] | q  Q } (1) D M = { (p,q) | p,q  Q and p ~ q } / q0q0 q1q1 qiqi qnqn q0q0 q1q1 qiqi qnqn Recursion: if there is σ  Σ and states p, q satisfying DD D  (p,  ) = p  (q,  ) = q ~/  p ~ q / Base Case: p accepts and q rejects  p ~ q / Repeat until no more new D’s

22 1 0 1 0 1 0,1 0 q0q0 q0q0 q1q1 q1q1 q2q2 q2q2 q3q3 q3q3 q0q0 q1q1 q2q2 q3q3 DDD D D D

23 1 1 1 1 0 0 0 0 q0q0 q0q0 q1q1 q1q1 q2q2 q2q2 q3q3 q3q3 DD D D q0q0 q1q1 q2q2 q3q3

24 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 Then there are states p, q, and string w such that:  (p, w)  F and  (q, w)  F ^^ 2. p =  (p,  ) and q =  (q,  ), where   Σ The string  w distinguishes p and q! / Suppose (p, q) is marked D at a later point. 1. (p, q) are marked D  p ~ q (by induction)  /

25 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 ^^ Of all such bad pairs, let p, q be a pair with the shortest w So, w =  w, where   Σ Let p =  (p,  ) and q =  (q,  ) Then (p, q) is also a bad pair, but with a SHORTER w ! (Why is |w| >0 ?)

26 Algorithm MINIMIZE Input: DFA M Output: DFA M MIN (1) Remove all inaccessible states from M (2) Apply Table-Filling algorithm to get: E M = { [q] | q is an accessible state of M } Q MIN = E M, q 0 MIN = [q 0 ], F MIN = { [q] | q  F }  MIN ( [q],  ) = [  ( q,  ) ] Must show  MIN is well defined! Define: M MIN = (Q MIN, Σ,  MIN, q 0 MIN, F MIN )

27 Algorithm MINIMIZE Input: DFA M Output: DFA M MIN (1) Remove all inaccessible states from M (2) Apply Table-Filling algorithm to get: E M = { [q] | q is an accessible state of M } Define: M MIN = (Q MIN, Σ,  MIN, q 0 MIN, F MIN ) Q MIN = E M, q 0 MIN = [q 0 ], F MIN = { [q] | q  F }  MIN ( [q],  ) = [  ( q,  ) ] Claim: M MIN  M

28 1 0 1 0 1 0 1 0 1 0 q0q0 q1q1 q2q2 MINIMIZE

29 1 0 1 0 1 0,1 0 q0q0 q1q1 q3q3 q5q5 q4q4 0 1 q2q2 q0q0 q0q0 q1q1 q1q1 q3q3 q3q3 q4q4 q4q4 D DD D DD q5q5 q5q5 D D D

30 1 0 1 0 0 q0q0 q1q1 q3q3 q5q5 q4q4 0 1 q0q0 q0q0 q1q1 q1q1 q3q3 q3q3 q4q4 q4q4 D DD D DD q5q5 q5q5 D D D

31 *M MIN is the unique minimal DFA equivalent to M Suppose M  M MIN, and M has no inaccessible states and is irreducible Claim: There exists a 1-1 onto correspondence (preserving transitions) between M and M MIN Proof: We will construct a map recursively Base Case: q 0 MIN → q 0 Recursive Step: If p → p q  q Then q → q

32 *M MIN is the unique minimal DFA equivalent to M Claim: Suppose M  M MIN, and M has no inaccessible states and is irreducible. Then there is a bijection that preserves transitions between M and M MIN

33 *M MIN is the unique minimal DFA equivalent to M Claim: Suppose M  M MIN, and M has no inaccessible states and is irreducible. Then there is a bijection that preserves transitions between M and M MIN 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 M min  M be minimal. Then M min  M MIN So, by Claim, both M min and M are isomorphic to M MIN NOT TRUE for NFAs !

34 Proof: We construct a map from M MIN to M recursively Base Case: q 0 MIN → q 0 Recursive Step: If p → p q  q Then q → q *M MIN is the unique minimal DFA equivalent to M Claim: Suppose M  M MIN, and M has no inaccessible states and is irreducible. Then there is a bijection that preserves transitions between M and M MIN

35 Base Case: q 0 MIN → q 0 Recursive Step: If p → p q  q Then q → q We need to prove: The map is defined everywhere The map is well defined The map is a bijection That is, for all q  M MIN there is a q  M such that q → q If q  M MIN, there is a string w such that  MIN (q 0 MIN,w) = q ^ Let q =  (q 0,w). q will map to q ^

36 Base Case: q 0 MIN → q 0 Recursive Step: If p → p q  q Then 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 

37 M MIN M Suppose there exist q and q  such that q → q and q → q  q u q0q0 q  v q0q0 q u q 0 MIN q v Suppose q and q  are distinguishable w Accept w Reject w w Accept Contradiction!

38 Base Case: q 0 MIN → q 0 Recursive Step: If p → p q  q Then q → q The map is onto For all q  M there is a q  M MIN such that q → q If q  M, there is w such that  (q 0,w) = q ^ Let q =  MIN (q 0 MIN,w) ^

39 M MIN M Suppose there are distinct p and q such that p → q and q → q q u q0q0 q v q0q0 p u q 0 MIN q v Suppose p and q are distinguishable w Accept w Reject w w Accept The map is 1-1 Contradiction!

40 How can we prove that two regular expressions are equivalent?

41

42

43 WWW.FLAC.WS Finish reviewing Chapter 1 of the book and read 2.1 & 2.2 for next time


Download ppt "FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA."

Similar presentations


Ads by Google