CS154. Non-Regular Languages, Minimizing DFAs

Similar documents
CS 154, Lecture 4: Limitations on DFAs (I), Pumping Lemma, Minimizing DFAs

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Lecture 5: Minimizing DFAs

Minimization of DFAs

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Proving languages to be nonregular

Lecture 4: More on Regexps, Non-Regular Languages

More on Regular Languages and Non-Regular Languages

Before we show how languages can be proven not regular, first, how would we show a language is regular?

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Incorrect reasoning about RL. Equivalence of NFA, DFA. Epsilon Closure. Proving equivalence. One direction is easy:

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

What we have done so far

CS 455/555: Finite automata

3515ICT: Theory of Computation. Regular languages

CS 154 NOTES CONTENTS

Properties of Regular Languages. BBM Automata Theory and Formal Languages 1

Chapter 2: Finite Automata

CS5371 Theory of Computation. Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)

Computational Models - Lecture 3 1

Computational Theory

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

CSCE 551 Final Exam, Spring 2004 Answer Key

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

CPSC 421: Tutorial #1

Uses of finite automata

Formal Language and Automata Theory (CS21004)

Theory of Computation (II) Yijia Chen Fudan University

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

We define the multi-step transition function T : S Σ S as follows. 1. For any s S, T (s,λ) = s. 2. For any s S, x Σ and a Σ,

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Chapter 2 The Pumping Lemma

Finite Automata and Regular languages

Lecture 4 Nondeterministic Finite Accepters

CSE 105 THEORY OF COMPUTATION

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

CpSc 421 Final Exam December 6, 2008

Equivalence of DFAs and NFAs

CS 154 Introduction to Automata and Complexity Theory

Fooling Sets and. Lecture 5

Applied Computer Science II Chapter 1 : Regular Languages

Outline. CS21 Decidability and Tractability. Regular expressions and FA. Regular expressions and FA. Regular expressions and FA

TDDD65 Introduction to the Theory of Computation

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 9 : Myhill-Nerode Theorem and applications

More on Finite Automata and Regular Languages. (NTU EE) Regular Languages Fall / 41

Nondeterministic Finite Automata

DFA to Regular Expressions

The Pumping Lemma and Closure Properties

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

Nondeterministic Finite Automata

Computational Models - Lecture 3

Computational Models: Class 3

acs-04: Regular Languages Regular Languages Andreas Karwath & Malte Helmert Informatik Theorie II (A) WS2009/10

CS21 Decidability and Tractability

Computability and Complexity

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Chapter Five: Nondeterministic Finite Automata

Finite Automata and Regular Languages

Nondeterministic finite automata

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

CSE 105 Theory of Computation Professor Jeanne Ferrante

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

Name: Student ID: Instructions:

Chapter 6: NFA Applications

Notes on State Minimization

COMP4141 Theory of Computation

V Honors Theory of Computation

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Theory of Computation 4 Non-Deterministic Finite Automata

Chapter 2: Finite Automata

Languages, regular languages, finite automata

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Finite Automata and Formal Languages TMV026/DIT321 LP Testing Equivalence of Regular Languages

CSE 135: Introduction to Theory of Computation Optimal DFA

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

11-711: Algorithms for NLP Homework Assignment #1: Formal Language Theory Solutions

Sample Midterm. Understanding the questions is part of the exam; you are not allowed to ask questions during the exam.

Outline. Summary. DFA -> Regex. Finish off Regex -> e-nfa -> NFA -> DFA -> Regex Minimization/equivalence (Myhill-Nerode theorem)

Answers to the CSCE 551 Final Exam, April 30, 2008

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

Regular Languages and Finite Automata

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) September,

CSE 105 Theory of Computation

Computational Models - Lecture 3 1

CSE 105 THEORY OF COMPUTATION

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

CSC173 Workshop: 13 Sept. Notes

Büchi Automata and their closure properties. - Ajith S and Ankit Kumar

CS 154 NOTES MOOR XU NOTES FROM A COURSE BY LUCA TREVISAN AND RYAN WILLIAMS

CS154 Final Examination

Decidability (What, stuff is unsolvable?)

CS 154 Formal Languages and Computability Assignment #2 Solutions

Please give details of your calculation. A direct answer without explanation is not counted.

Intro to Theory of Computation

CpSc 421 Homework 1 Solutions

Further discussion of Turing machines

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Transcription:

CS54 Non-Regular Languages, Minimizing FAs

CS54 Homework is due! Homework 2 will appear this afternoon 2

The Pumping Lemma: Structure in Regular Languages Let L be a regular language Then there is a positive integer P s.t. for all strings w L with w P there is a way to write w = xyz, where:. y > (that is, y ε) 2. xy P 3. For all i, xy i z L Why is it called the pumping lemma? The word w gets pumped into longer and longer strings 3

Proof: Let M be a FA that recognizes L Let P be the number of states in M Let w be a string where w L and w P We show: w = xyz y. y > 2. xy P 3. xy i z L for all i x z q q j q k q w Claim: There must exist j and k such that j < k P, and q j = q k 4

Applying the Pumping Lemma Let s prove that EQ = { w w has equal number of s and s} is not regular. By contradiction. Assume EQ is regular. Let P be as in pumping lemma. Let w = P P ; note w EQ. If EQ is regular, then there is a way to write w as w = xyz, y >, xy P, and for all i, xy i z is also in EQ Claim: The string y must be all zeroes. Why? Because xy P and w = xyz = P P But then xyyz has more s than s Contradiction!

Applying the Pumping Lemma Let s prove that SQ = { n2 n } is not regular Assume SQ is regular. Let w = P2 If SQ is regular, then we can write w = xyz, y >, xy P, and for any i, xy i z is also in SQ So xyyz SQ. Note that xyyz = P2 + y Note that < y P So xyyz = P 2 + y P 2 + P < P 2 + 2P + = (P+) 2 and P 2 < xyyz < (P+) 2 Therefore xyyz is not a perfect square! Hence P2 + y = xyyz SQ, so our assumption must be false. That is, SQ is not regular!

oes this FA have a minimal number of states? NO 8

9

Is this minimal? How can we tell in general?

Theorem: For every regular language L, there is a unique (up to re-labeling of the states) minimal-state FA M* such that L = L(M*). Furthermore, there is an efficient algorithm which, given any FA M, will output this unique M*. If this were true for more general models of computation, that would be an engineering breakthrough!!

Note: There isn t a uniquely minimal NFA 2

Extending transition function δ to strings Given FA M = (Q, Σ, δ, q, F), we extend δ to a function : Q Σ* Q as follows: (q, ε) = (q, σ) = q δ(q, σ) (q, σ σ k+ ) = δ( (q, σ σ k ), σ k+ ) (q, w) = the state of M reached after reading in w, starting from state q Note: (q, w) F M accepts w ef. w Σ* distinguishes states q and q 2 iff (q, w) F (q 2, w) F 3

Extending transition function δ to strings Given FA M = (Q, Σ, δ, q, F), we extend δ to a function : Q Σ* Q as follows: (q, ε) = (q, σ) = q δ(q, σ) (q, σ σ k+ ) = δ( (q, σ σ k ), σ k+ ) (q, w) = the state of M reached after reading in w, starting from state q Note: (q, w) F M accepts w ef. w Σ* Σ* distinguishes states q and q 22 iff iff exactly oneof of (q,, w), (q 22,, w) is is a final state 4

istinguishing two states ef. w Σ* distinguishes states q and q 2 iff exactly one of (q, w), (q 2, w) is a final state I m in q or q 2, but which? How can I tell? 5

istinguishing two states ef. w Σ* distinguishes states q and q 2 iff exactly one of (q, w), (q 2, w) is a final state Here read this I m in q or q 2, but which? How can Ok, I I m tell? accepting! Must have been q W 6

Fix M = (Q, Σ, δ, q, F) and let p, q Q efinition: State p is distinguishable from state q iff there is w Σ* that distinguishes p and q iff there is w Σ* so that exactly one of (p, w), (q, w) is a final state State p is indistinguishable from state q iff p is not distinguishable from q iff for all w Σ*, (p, w) F (q, w) F Pairs of indistinguishable states are redundant 7

q, q Which pairs of states are distinguishable here? q 3 q 2 ε distinguishes all final states from non-final states 8

q, q q 2 Which pairs of states are distinguishable here? q 3 The string distinguishes q and q 3 9

q, q q 2 Which pairs of states are distinguishable here? q 3 The string distinguishes q and q 2 2

Fix M = (Q, Σ, δ, q, F) and let p, q, r Q efine a binary relation on the states of M: 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? 2

Fix M = (Q, Σ, δ, q, F) and let p, q, r Q Proposition: is an equivalence relation Therefore, the relation partitions Q into disjoint equivalence classes Q q [q] := { p p q } q 22

23

Algorithm: MINIMIZE-FA Input: FA M Output: FA M MIN such that: L(M) = L(M MIN ) M MIN has no inaccessible states M MIN is irreducible For all states p q of M MIN, p and q are distinguishable Theorem: M MIN is the unique minimal FA that is equivalent to M 24

Intuition: The states of M MIN will be the equivalence classes of states of M We ll uncover these equivalent states with a dynamic programming algorithm 25

The Table-Filling Algorithm Input: FA M = (Q, Σ, δ, q, F) Output: () M = { (p, q) p, q Q and p q} (2) EQUIV M = { [q] q Q } High-Level Idea: We know how to find those pairs of states that the string ε distinguishes Use this and iteration to find those pairs distinguishable with longer strings The pairs of states left over will be indistinguishable 26

The Table-Filling Algorithm Input: FA M = (Q, Σ, δ, q, F) Output: () M = { (p, q) p, q Q and p q} (2) EQUIV M = { [q] q Q } q q Base Case: For all (p, q) such that p accepts and q rejects p q q i q n q q q i q n 27

q q q i q n q q q i q n The Table-Filling Algorithm Input: FA M = (Q, Σ, δ, q, F) Output: () M = { (p, q) p, q Q and p q} (2) EQUIV M = { [q] q Q } Base Case: For all (p, q) such that p accepts and q rejects p q Iterate: If there are states p, q and symbol σ Σ satisfying: δ (p, σ) = p mark p q δ (q, σ) = q Repeat until no more s can be added 28

q q q 2 q 3 q q q 2 q 3, q q q 2 q 3 29

q q q q q 3 q 2 q 2 q 3 q q q 2 q 3 3

Claim: If (p, q) is marked by the Table-Filling algorithm, then p q Proof: By induction on the number of steps in the algorithm before (p,q) is marked If (p, q) is marked at the start, then one state s in F and the other isn t, so ε distinguishes p and q Suppose (p, q) is marked at a later point. Then there are states p, q such that:. (p, q ) are marked p q (by induction) So there s a string w s.t. (p, w) F (q, w) F 2. p = δ(p,σ) and q = δ(q,σ), where σ Σ The string σw distinguishes p and q! 3

Claim: If (p, q) is not marked by the Table-Filling algorithm, then p q Proof (by contradiction): Suppose the pair (p, q) is not marked by the algorithm, yet p q (call this a bad pair ) Then there is a string w such that w > and: (p, w) F and (q, w) F (Why is w >?) Of all such bad pairs, let p, q be a pair with the shortest distinguishing string w 32

Claim: If (p, q) is not marked by the Table-Filling algorithm, then p q Proof (by contradiction): Suppose the pair (p, q) is not marked by the algorithm, yet p q (call this a bad pair ) Of all such bad pairs, let p, q be a pair with the shortest distinguishing string w (p, w) F and (q, w) F We have w = σw, for some string w and some σ Σ Let p = δ(p,σ) and q = δ(q,σ) (Why is w >?) Then (p, q ) is also a bad pair, but with a SHORTER distinguishing string, w! 33

Algorithm MINIMIZE Input: FA M Output: Equivalent minimal-state FA M MIN. Remove all inaccessible states from M 2. Run Table-Filling algorithm on M to get: EQUIV M = { [q] q is an accessible state of M } 3. efine: M MIN = (Q MIN, Σ, δ MIN, q MIN, F MIN ) Q MIN = EQUIV M, q MIN = [q ], F MIN = { [q] q F } δ MIN ( [q], σ ) = [ δ( q, σ ) ] Claim: L(M MIN ) = L(M) 34

q q q 4, q, q 5 q q 2 q 3 q 3 q 4 q 5 q q q 3 q 4 q 5 36

q q q 4, q q 5 q q 3 q 3 q 4 q 5 q q q 3 q 4 q 5 37

Thm: M MIN is the unique minimal FA equivalent to M Claim: Suppose for a FA M, L(M )=L(M MIN ) and M has no inaccessible states and M is irreducible. Then there is an isomorphism between M and M MIN If M is a minimal FA, then M has no inaccessible states and is irreducible. So the Claim implies: If M is a minimal FA for M, then there is an isomorphism between M and M MIN. So the Thmholds! Corollary: If M has no inaccessible states and is irreducible, then M is minimal. Proof: Let M min be minimal for M. Then L(M) = L(M min ), no inaccessible states in M, and M is irreducible. By Claim, both M min and M are isomorphic to M MIN! 38