Transparency No. 8-1 Formal Language and Automata Theory Chapter 8 DFA state minimization (lecture 13, 14)

Slides:



Advertisements
Similar presentations
Lecture 24 MAS 714 Hartmut Klauck
Advertisements

Finite Automata CPSC 388 Ellen Walker Hiram College.
Summary Showing regular Showing non-regular construct DFA, NFA
CSCI 2670 Introduction to Theory of Computing September 13, 2005.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state.
Transparency No. 2-1 Formal Language and Automata Theory Chapter 2 Deterministic Finite Automata (DFA) (include Lecture 3 and 4)
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Fall 2006Costas Busch - RPI1 Regular Expressions.
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
Transparency No Formal Language and Automata Theory Chapter 10 The Myhill-Nerode Theorem (lecture 15,16 and B)
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
Transparency No. 4-1 Formal Language and Automata Theory Chapter 4 Patterns, Regular Expressions and Finite Automata (include lecture 7,8,9) Transparency.
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
Regular Expression (EXTRA)
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Transparency No. 3-1 Formal Language and Automata Theory Chapter 3 Nondeterministic Finite Automata (NFA) (include lecture 5 and 6)
Transparency No Formal Language and Automata Theory Chapter 10 The Myhill-Nerode Theorem (lecture 15,16 and B)
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
1 CSCI 3130: Formal Languages and Automata Theory Tutorial 4 Hung Chun Ho Office: SHB 1026 Department of Computer Science & Engineering.
Transparency No. P2C1-1 Formal Language and Automata Theory Part II Pushdown Automata and Context-Free Languages.
Transparency No. ?-0 Formal Language and Automata Theory Chapter 6 Homomorphisms (lecture 10) Transparency No. 6-1.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Non-Deterministic Automata Regular Expressions.
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Costas Busch - LSU1 Non-Deterministic Finite Automata.
Lecture 4UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 4.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY For next time: Read 2.1 & 2.2.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Transparency No. 3-1 Formal Language and Automata Theory Chapter 3 Nondeterministic Finite Automata (NFA)
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Introduction to CS Theory
Decidable Questions About Regular languages 1)Membership problem: “Given a specification of known type and a string w, is w in the language specified?”
DFA Minimization 1 2 Equivalent States Consider the accept states c and g. They are both sinks meaning that any string which ever reaches them is guaranteed.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Lecture 5 Sept 06, 2012 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CSCI 2670 Introduction to Theory of Computing September 13.
Regular Expressions Costas Busch - LSU.
Transparency No. 4-1 Formal Language and Automata Theory Chapter 4 Patterns, Regular Expressions and Finite Automata (include lecture 7,8,9) Transparency.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA.
Algorithms for hard problems Automata and tree automata Juris Viksna, 2015.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
1 Language Recognition (11.4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1 Lexical Analysis Uses formalism of Regular Languages Uses formalism of Regular Languages Regular Expressions Regular Expressions Deterministic Finite.
Single Final State for NFA
Hierarchy of languages
CS 154, Lecture 4: Limitations on DFAs (I),
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 State Transition Graph (Non)deterministic FA: DFA, NFA
Instructor: Aaron Roth
Regular Language Equivalence and DFA Minimization
Presentation transcript:

Transparency No. 8-1 Formal Language and Automata Theory Chapter 8 DFA state minimization (lecture 13, 14)

DFA state minimization Transparency No. 8-2 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 ? 2. 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}. stuv ab a a,b

DFA state minimization Transparency No. 8-3 Inaccessible states A state p  Q is said to be inaccessible (or unreachable) [from the initial state] if there exists no string x in  * s.t.  (s,x) = p (I.e., p  {q | x   *,  (s,x) = q }. ) Theorem: Removing inaccessible states from a machine M does not affect the language it accepts. Pf: M = : a DFA; p : an inaccessible state let M’ = be the DFA M with p removed. Hence  ’:(Q\{p})x  --> Q\{p} with  ’(q,a) = r if  (q,a) =r and q,r in Q \{p}. For M and M’ it can be proved by induction on x that for all x in  *, for all q in Q\{p},  (q,x) =  ’(q,x). Hence for all x   *, x  L(M) iff  ’(s,x) = q  F\{p} iff  (s,x) = q  F iff x  L(M). qed

DFA state minimization Transparency No. 8-4 Inaccessible states are redundant M : any DFA with n inaccessible states p 1,p 2,…,p n. Let M 1,M 2,..,M n+1 are DFAs s.t. DFA M i+1 is constructed from M i by removing p i from M i. I.e., M -rm(p 1 )-> M 1 -rm(p 2 )-> M 2 - … M n -rm(p n )-> M n+1 By previous lemma: L(M) = L(M 1 ) = …=L(M n+1 ) and M n+1 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 ?

DFA state minimization Transparency No. 8-5 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  *, q   ( S,x) } and hence can be defined by induction. Let A k be the set of states accessible from initial states of M by at most k steps of transitions. I.e., A k = {q|  x  * with |x|  k and q   ( S,x) } What is the relationship b/t A(M) and A k s ? What is A 0 and the relationship b/t A k and A k+1 ? Formal definition: M= : any NFA. Basis: Every start state q  S is accessible.(A 0  A(M)) Induction: If q is accessible and p in  (q,a) for some a  , then p is accessible. (A k+1 =A k U {p | p   (q,a) for some q  A k and a  .)

DFA state minimization Transparency No. 8-6 An algorithm to find all accessible states: REACH(M) { // M = 1. A = S ; 2. B =  (A) - A ; 3. For k = 0 to |Q| do { // A = A k ; B = A K+1 - A k 4. A = A U B ; B =  (B) - A; if B = {} then break }; 5. Return(A) } Function  (S) { 1.  = {}; 2. For each q in Q do for each a in  do  =  U  (q,a); 3. Return(  }

DFA state minimization Transparency No. 8-7 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.t.  (p,x)  F iff  (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.

DFA state minimization Transparency No a a a,b a b bb ,23,4 a,b Example 13.2:

DFA state minimization Transparency No. 8-9 Quotient Construction M=(Q, , ,s,F): a DFA.  : a relation on Q defined by: p  q for all x   *  (p,x)  F iff  (q,x)  F Property:  is an equivalence relation. Hence it partitions Q into equivalence classes [p] = {q  Q | p  q} for p  Q. and the quotient set Q/  = {[p] | p  Q}. Every p  Q belongs to exactly one class [p] and p  q iff [p]=[q]. Define the quotient machine M/  = where Q’=Q/  ; s’=[s]; F’={[p] | p  F}; and  ’([p],a)=[  (p,a)] for all p  Q and a  . But well-defined ?

DFA state minimization Transparency No the function  ’ is well-defined. Lem if p  q  then  (p,a)   (q,a). Hence if [p]=[q] then [  (p,a)] = [  (q,a)] Pf: By def. [  (p,a)] = [  (q,a)] iff  (p,a)   (q,a) iff ∀ y ∈  *  (  (p,a),y ) ∈ F   (  (q,a),y) ∈ F iff ∀ y ∈  *  (p, ay) ∈ F   (q,ay) ∈ F if p  q. Lemma 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 =  (p,  ) ∈ F iff  (q,  ) = q ∈ F

DFA state minimization Transparency No Properties of the quotient machine. Lemma 13.7: ∀ x ∈  *,  ’([p],x) = [  (p,x)]. Pf: By induction on |x|. Basis x =  :  ’([p],  ] = [p] = [  (p,  )]. Ind. step: Assume  ’([p],x) = [  (p,x)] and let a ∈ .  ’([p],xa) =  ’(  ’(p,x),a) =  ’([  (p,x)],a) --- ind. hyp. =[  (  (p,x),a)] -- def. of  ’ = [  (p,xa)]. -- def. of . Theorem 13.8: L(M/  ) = L(M). Pf: ∀ x ∈  *, x ∈ L(M/  ) iff  ’(s’,x) ∈ F’ iff  ’([s],x) ∈ F’ iff [  (s,x)] ∈ F’ --- lem 13.7 iff  (s,x) ∈ F --- lem 13.6 iff x ∈ L(M).

DFA state minimization Transparency No M/  cannot be collapsed furtuer Theorem: ((M/  M/  Pf: denote the second  by . I.e. [p]  [q] iff ∀ x ∈  *,  ’([p],x) ∈ F’   ’([q],x) ∈ F’ Now [p]  [q] iff ∀ x ∈  *,  ’([p],x) ∈ F’   ’([q],x) ∈ F’ -- def.of  iff ∀ x ∈  *, [  (p,x)] ∈ F’  [  (q,x)] ∈ F’ -- lem 13.7 iff ∀ x ∈  *,  (p,x) ∈ F   (q,x) ∈ F -- lem 13.6 iff [p]  [q] -- def of 

DFA state minimization Transparency No 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 more change: 3.1 if ∃ unmarked pair {p,q} s.t. {  (p,q),  (q,a)} is marked for some a ∈ , 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 pass of step 3. [ and M 0 is the set of pairs before step 3.] Notes: 1. M = U k ≥0 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 pass of step 3 must marke at leat one pair.

DFA state minimization Transparency No An Example: The DFA: ab >012 1F34 2F F55

DFA state minimization Transparency No Initial Table

DFA state minimization Transparency No After step 2 1M 2M- 3-MM 4-MM- 5M--MM 01234

DFA state minimization Transparency No After first pass of step 3 1M 2M- 3-MM 4-MM- 5MMMMM 01234

DFA state minimization Transparency No nd pass of step 3. The result : 1  2 and 3  4. 1M 2M- 3M2MM 4 MM- 5MM1 MM 01234

DFA state minimization Transparency No Correctness of the collapsing algorithm Let M k ( k ≥ 0 ) be the set of pairs marked after the k-th pass of step 3. [ and M0 is the set of pairs befer step 3.] Lemma: {p,q} ∈ M k iff ∃ x ∈ S* of length ≤ k s.t.  (p,x) ∈ F and  (q,x) ∉ F or vice versa, Pf: By ind. on k. Basis k = 0. trivial. Ind. step: ∃ x ∈  * of length ≤ k+1 s.t.  (p,x) ∈ F   (q,x) ∉ F, iff ∃ x ∈  * of length ≤ k s.t.  (p,x) ∈ F   (q,x) ∉ F, or ∃ ax ∈  * of length ≤ k+1 s.t.  (  (p,a),x) ∈ F   (  (q,a),x) ∉ F, iff {p, q} ∈ M k or {  (p,a),  (q,a)} ∈ M  and a ∈ . iff {p,q} ∈ M k + 1. Theorem 14.3: The pair {p,q} is marked by the algorithm iff ∃ x ∈  * s.t.  (p,x) ∈ F   (q,x) ∉ F, (i.e., iff not(p  q) ) Pf: not(p  q) iff ∃ x ∈  * s.t.  (p,x) ∈ F   (q,x) ∉ F iff {p,q} ∈ M k for some k ≥ 0 iff {p,q} ∈ M = U k ≥ 0 M k.