Presentation is loading. Please wait.

Presentation is loading. Please wait.

MA/CSSE 474 Theory of Computation Minimizing DFSMs.

Similar presentations


Presentation on theme: "MA/CSSE 474 Theory of Computation Minimizing DFSMs."— Presentation transcript:

1 MA/CSSE 474 Theory of Computation Minimizing DFSMs

2 Your Questions? Previous class days' material Reading Assignments HW2 solutions HW3 or HW4 Tuesday's Exam Anything else Another example of why we often need formal specifications instead of natural language

3 Finite State Machines Intro to State Minimization Among all DSFMs that are equivalent to a given DFSM, can we find one whose number of states is minimal? Note that this is a different question form "Is there an equivalent machine with a minimal number of states?", which has an obvious answer.

4 State Minimization Consider: Is this a minimal machine? It's not immediately obvious! We need tools!

5 State Minimization Step (1): Get rid of unreachable states. State 3 is unreachable. Step (2): Get rid of redundant states. States 2 and 3 are redundant.

6 Getting Rid of Unreachable States We can’t easily find the unreachable states directly. But we can find the reachable ones and determine the unreachable ones from there. An algorithm for finding the reachable states: Like many algorithms from this course, the structure is "add things until nothing new can be added"

7 Getting Rid of Redundant States Intuitively, two states are equivalent to each other (and thus one is redundant) if, starting in those states, all strings in  * have the same fate, regardless of which of the two states the machine is currently in. But how can we tell this? The simple case: Two states have identical sets of transitions out.

8 Getting Rid of Redundant States The harder case: The outcomes in states 2 and 3 are the same, even though the states aren’t.

9 Finding an Algorithm for Minimization Capture the notion of equivalence classes of strings with respect to a language. Prove that we can always find a (unique up to state naming) a deterministic FSM with a number of states equal to the number of equivalence classes of strings. Describe an algorithm for finding that deterministic FSM.

10 Equivalence for Strings (w.r.t. L) We want to capture the notion that two strings are equivalent or indistinguishable with respect to a language L if, no matter what string w tacked on to them on the right, either both concatenated strings will be in L or neither will. Write it in first-order logic: x  L y iff Example: (1) ababab (2) baabab Suppose L = {w  { a, b }* : |w| is even}. Are (1) and (2) equivalent? Suppose L = {w  { a, b }* : every a is immediately followed by b }.

11  L is an Equivalence Relation Reflexive:  x   * (x  L x), because:  x, z   * (xz  L  xz  L). Symmetric:  x, y   * (x  L y  y  L x), because:  x, y, z   * ((xz  L  yz  L)  (yz  L  xz  L)). Transitive:  x, y, z   * (((x  L y)  (y  L w))  (x  L w)), because:  x, y, z   * (((xz  L  yz  L)  (yz  L  wz  L))  (xz  L  wz  L)).  L is an equivalence relation because it is:

12 Because  L is an Equivalence Relation No equivalence class of  L is empty. Each string in  * is in exactly one equivalence class of  L. An equivalence relation on a set partitions the set. Thus:

13 An Example  = { a, b } L = {w   *: every a is immediately followed by b } What are the equivalence classes of  L ? Hint: Try:  aabbb abbbaa baba aab

14 Another Example of  L  = { a, b } L = {w   * : |w| is even}  bbaabb aababbaa baabaabaa aabbb baa The equivalence classes of  L :

15 Yet Another Example of  L  = { a, b } L = aab * a  bbaabaa aabaaabbba baabaabbaa aabaa aabb The equivalence classes of  L : Do this one for practice later

16 More Than One Class Can Contain Strings in L  = { a, b } L = {w   * : no two adjacent characters are the same} The equivalence classes of  L : [1][  ] [2][a, aba, ababa, …] [3][b, ab, bab, abab, …] [4][aa, abaa, ababb…]

17 Today's final example of  L  = { a, b } L = { a n b n, n  0}  aaaaaa aabaaaaaa baaa The equivalence classes of  L :

18 The Best We Can Do Theorem: Let L be a regular language and let M be a DFSM that accepts L. The number of states in M is greater than or equal to the number of equivalence classes of  L. Proof: 1.Suppose that the number of states in M were less than the number of equivalence classes of  L. 2.Then, by the pigeonhole principle, there must be at least one state q that contains strings from at least two equivalence classes of  L. 3.But then M’s future behavior on those strings will be identical, which is not consistent with the fact that they are in different equivalence classes of  L.

19 The Best Is Unique Theorem: Let L be a regular language over some alphabet . Then there is a DFSM M with L(M)=L and that has precisely n states where n is the number of equivalence classes of  L. Any other FSM that accepts L must either have more states than M or it must be equivalent to M except for state names. Proof: (by construction) M = (K, , , s, A), where: ● K contains n states, one for each equivalence class of  L. ● s = [  ], the equivalence class of  under  L. ● A = {[x] : x  L}. ●  ([x], a) = [xa]. In other words, if M is in the state that contains some string x, then, after reading the next symbol, a, it will be in the state that contains xa.

20 Proof, Continued K is finite. Since L is regular, it is accepted by some DFSM M. M has some finite number of states m. By Theorem 5.4, n  m. So K is finite.  is a function. In other words, it is defined for all (state, input) pairs and it produces, for each of them, a unique value. L = L(M). To prove this, we first show that  s,t ∊ Σ*( ([  ], st) ⊦ M * ([s], t)). We do this by induction on |s|. We must show that: Not much to do for the base case!


Download ppt "MA/CSSE 474 Theory of Computation Minimizing DFSMs."

Similar presentations


Ads by Google