ma/csse 474 theory of computation minimizing dfsms

20
MA/CSSE 474 Theory of Computation Minimizing DFSMs

Upload: geraldine-theresa-henderson

Post on 17-Jan-2018

233 views

Category:

Documents


0 download

DESCRIPTION

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.

TRANSCRIPT

Page 1: MA/CSSE 474 Theory of Computation Minimizing DFSMs

MA/CSSE 474

Theory of Computation

Minimizing DFSMs

Page 2: MA/CSSE 474 Theory of Computation Minimizing DFSMs

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

Page 3: MA/CSSE 474 Theory of Computation Minimizing DFSMs

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.

Page 4: MA/CSSE 474 Theory of Computation Minimizing DFSMs

State MinimizationConsider:

Is this a minimal machine? It's not immediately obvious!We need tools!

Page 5: MA/CSSE 474 Theory of Computation Minimizing DFSMs

State MinimizationStep (1): Get rid of unreachable states.

State 3 is unreachable.

Step (2): Get rid of redundant states.

States 2 and 3 are redundant.

Page 6: MA/CSSE 474 Theory of Computation Minimizing DFSMs

Getting Rid of Unreachable StatesWe 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"

Page 7: MA/CSSE 474 Theory of Computation Minimizing DFSMs

Getting Rid of Redundant StatesIntuitively, 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.

Page 8: MA/CSSE 474 Theory of Computation Minimizing DFSMs

Getting Rid of Redundant States

The harder case:

The outcomes in states 2 and 3 are the same, even though the states aren’t.

Page 9: MA/CSSE 474 Theory of Computation Minimizing DFSMs

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.

Page 10: MA/CSSE 474 Theory of Computation Minimizing DFSMs

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) a b a b a b

(2) b a a b a b

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}.

Page 11: MA/CSSE 474 Theory of Computation Minimizing DFSMs

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:

Page 12: MA/CSSE 474 Theory of Computation Minimizing DFSMs

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:

Page 13: MA/CSSE 474 Theory of Computation Minimizing DFSMs

An Example

= {a, b}L = {w *: every a is immediately followed by b}

What are the equivalence classes of L?

Hint: Try:

aa bbba bb baab aba

aab

Page 14: MA/CSSE 474 Theory of Computation Minimizing DFSMs

Another Example of L

= {a, b}L = {w * : |w| is even}

bb aabba aba bbaab aab aabaaaa bbb

baa

The equivalence classes of L:

Page 15: MA/CSSE 474 Theory of Computation Minimizing DFSMs

Yet Another Example of L

= {a, b}L = aab*a

bb aabaaa aba aabbbab aab aabbaaaa baa

aabb

The equivalence classes of L:

Do this one for practice later

Page 16: MA/CSSE 474 Theory of Computation Minimizing DFSMs

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…]

Page 17: MA/CSSE 474 Theory of Computation Minimizing DFSMs

Today's final example of L

= {a, b}L = {anbn, n 0}

aa aaaaa aba aaaaab aaa

The equivalence classes of L:

Page 18: MA/CSSE 474 Theory of Computation Minimizing DFSMs

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.

Page 19: MA/CSSE 474 Theory of Computation Minimizing DFSMs

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.

Page 20: MA/CSSE 474 Theory of Computation Minimizing DFSMs

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!