Minimize # states in a DFSM

Slides:



Advertisements
Similar presentations
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Advertisements

CSE 311 Foundations of Computing I
CMPS 3223 Theory of Computation
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
1 COMP 382: Reasoning about algorithms Unit 9: Undecidability [Slides adapted from Amos Israeli’s]
Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by.
Regular Expression (EXTRA)
MA/CSSE 474 Theory of Computation
Finite State Machines Chapter 5. Languages and Machines.
CMPS 3223 Theory of Computation
MA/CSSE 474 Theory of Computation DFSM Canonical Form Proof of NDFSM  DFSM ALGORITHM (as much as we have time for) This version includes the "answers"
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
MA/CSSE 474 Theory of Computation Decision Problems DFSMs.
Computability Review homework. Regular Operations. Nondeterministic machines. NFSM = FSM Homework: By hand, build FSM version of specific NFSM. Try to.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Regular Expressions Chapter 6 1. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts 2.
Regular Expressions Chapter 6. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts.
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
MA/CSSE 474 Theory of Computation Minimizing DFSMs.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Nondeterministic Finite State Machines Chapter 5.
Finite State Machines Chapter 5. Languages and Machines.
Algorithms and Decision Procedures for Regular Languages Chapter 9.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
MA/CSSE 474 Theory of Computation How many regular/non-regular languages are there? Closure properties of Regular Languages (if there is time) Pumping.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Regular Expression (EXTRA)
The Acceptance Problem for TMs
Kleene’s Theorem and NFA
Modeling Arithmetic, Computation, and Languages
Languages, prefixes, sets, cardinality, functions
Pushdown Automata.
Pushdown Automata.
(Universal Turing Machine)
CSE 105 theory of computation
Theory of Computation Lecture 22: Turing Machines III
MA/CSSE 474 Decision Problems about Regular Languages
Handout 4 Functional Dependencies
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
Hierarchy of languages
Recap lecture 29 Example of prefixes of a language, Theorem: pref(Q in R) is regular, proof, example, Decidablity, deciding whether two languages are equivalent.
Minimal DFA Among the many DFAs accepting the same regular language L, there is exactly one (up to renaming of states) which has the smallest possible.
Finite Automata Reading: Chapter 2.
Chapter Five: Nondeterministic Finite Automata
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation Minimizing DFSMs.
MA/CSSE 474 Theory of Computation
Languages, prefixes, sets, cardinality, functions
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation Computation FSM Intro.
CS21 Decidability and Tractability
Instructor: Aaron Roth
MA/CSSE 474 Theory of Computation
Pushdown Automata (PDA) Part 2
MA/CSSE 474 Theory of Computation Nondeterminism NFSMs.
More on showing L non-regular
MA/CSSE 474 Theory of Computation
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
Regular Language Equivalence and DFA Minimization
Recap lecture 18 NFA corresponding to union of FAs,example, NFA corresponding to concatenation of FAs,examples, NFA corresponding to closure of an FA,examples.
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation
More About Nondeterminism
Turing Machines Everything is an Integer
Presentation transcript:

Minimize # states in a DFSM MA/CSSE 474 Theory of Computation Finish NDFSMDFSM Minimize # states in a DFSM

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

Nondeterministic and Deterministic FSMs Clearly: {Languages accepted by some DFSM}  {Languages accepted by some NDFSM} More interesting: Theorem: For each NDFSM, there is an equivalent DFSM. "equivalent" means "accepts the same language"

Nondeterministic and Deterministic FSMs Theorem: For each NDFSM, there is an equivalent DFSM. Proof: By construction: Given a NDFSM M = (K, , , s, A), we construct M' = (K', , ', s', A'), where K'  P(K) s' = eps(s) A' = {Q  K' : Q  A  } '(Q, a) = {eps(p): p  K and (q, a, p)   for some q  Q} More precisely, each state in K' is the string that encodes a subset of K, using the standard set notation. Example: "{q0, q2}" We omit the quotation marks. Think of the simulator as the "interpreted version" and this as the "compiled version".

An Algorithm for Constructing the Deterministic FSM 1. Compute the eps(q)’s. 2. Compute s' = eps(s). 3. Compute ‘. 4. Compute K' = a subset of P(K). 5. Compute A' = {Q  K' : Q  A  }.

The Algorithm ndfsmtodfsm ndfsmtodfsm(M: NDFSM) = 1. For each state q in KM do: 1.1 Compute eps(q). 2. s' = eps(s) 3. Compute ': 3.1 active-states = {s'}. 3.2 ' = . 3.3 While there exists some element Q of active-states for which ' has not yet been computed do: For each character c in M do: new-state = . For each state q in Q do: For each state p such that (q, c, p)   do: new-state = new-state  eps(p). Add the transition (q, c, new-state) to '. If new-state  active-states then insert it. 4. K' = active-states. 5. A' = {Q  K' : Q  A   }. Draw part of the transition diagram for the DFSM constructed from the NDFSM that appeared a few slides earlier. Do it for the8-state NDFSM, use the spreadsheet Later we may prove that this works for all NDFSMs M.

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

State Minimization Consider: Is this a minimal machine? It's not immediately obvious! We need tools! It's not at all obvious whether it is minimal. We need tools!

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.

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: reachable = {s} repeat new = {} for s in reachable: for a in : state = (s, a) if !(state in reachable  new) new.ppend(state) reachable.append (new) until new is empty // We can make this more efficient by having a separate variable that keeps track of the "fringe". Try it. Like many algorithms from this course, the structure is "add things until nothing new can be added"

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.

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

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.

Equivalent Strings (w.r.t. L) We say that two strings x and y are equivalent or indistinguishable with respect to a language L if, no matter what string z is appended to both, either both concatenated strings will be in L or neither will. Write it in first-order logic: x L y iff Example: x: a y: bab Suppose L1 = {w  {a, b}* : |w| is even}. Are x and y equivalent? Suppose L2 = {w  {a, b}* : every a is immediately followed by b}. Are x = a and y = aa equivalent with respect to L2? We are heading toward trying to find a minimal state DFSM that is equivalent to a given DFSM. We define an equivalence relation on a pair of strings, with respect to a language L. x L y iff z  * (xz  L iff yz  L). Why is this the right notion? We'll see that it corresponds naturally to what the states of a recognizing FSM have to remember.

L is an Equivalence Relation L is an equivalence relation because it is: 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)). The last thing boils down to propositional logic: A: xz  L B: yz  L C: wz  L This becomes ((A  B)  (B  C))  (A  C) Easy to see that this is a tautology.

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

An Example Recall that x L y iff z  * (xz  L ↔ yz  L).  = {a, b} L = {w  *: every a is immediately followed by b} What are the equivalence classes of L? Hint: Try:  aa bbb a bb baa b aba aab The equivalence classes of L: [1] [, b, abb, …] [all strings in L]. [2] [a, abbba, …] [all strings that end in a and have no prior a that is not followed by a b]. [3] [aa, abaa, …] [all strings that contain at least one instance of aa]. Recall that x L y iff z  * (xz  L ↔ yz  L).