State Minimization for DFAs

Similar documents
Minimal DFA. minimal DFA for L starting from any other

Formal Languages and Automata

Myhill-Nerode Theorem

More on automata. Michael George. March 24 April 7, 2014

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Lecture 09: Myhill-Nerode Theorem

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Theory of Computation Regular Languages

CMSC 330: Organization of Programming Languages

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Finite Automata-cont d

11.1 Finite Automata. CS125 Lecture 11 Fall Motivation: TMs without a tape: maybe we can at least fully understand such a simple model?

Non-deterministic Finite Automata

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Harvard University Computer Science 121 Midterm October 23, 2012

1 Nondeterministic Finite Automata

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

Non-deterministic Finite Automata

Chapter 2 Finite Automata

Convert the NFA into DFA

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Formal languages, automata, and theory of computation

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

DFA minimisation using the Myhill-Nerode theorem

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

Lecture 08: Feb. 08, 2019

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

GNFA GNFA GNFA GNFA GNFA

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

Homework 3 Solutions

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Regular expressions, Finite Automata, transition graphs are all the same!!

Model Reduction of Finite State Machines by Contraction

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Fundamentals of Computer Science

Let's start with an example:

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

Worked out examples Finite Automata

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Designing finite automata II

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

NFAs continued, Closure Properties of Regular Languages

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

Some Theory of Computation Exercises Week 1

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)

Coalgebra, Lecture 15: Equations for Deterministic Automata

FABER Formal Languages, Automata and Models of Computation

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

Deterministic Finite Automata

NON-DETERMINISTIC FSA

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Finite-State Automata: Recap

CS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

First Midterm Examination

Regular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15

NFAs continued, Closure Properties of Regular Languages

Nondeterminism and Nodeterministic Automata

Lexical Analysis Finite Automate

DFA Minimization and Applications

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

1.4 Nonregular Languages

p-adic Egyptian Fractions

Formal Language and Automata Theory (CS21004)

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

CISC 4090 Theory of Computation

CS375: Logic and Theory of Computing

Midterm 1 Practice. CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

This lecture covers Chapter 8 of HMU: Properties of CFLs

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7

CS 330 Formal Methods and Models

Lecture 6 Regular Grammars

CS 275 Automata and Formal Language Theory

Java II Finite Automata I

Chapter 1, Part 1. Regular Languages. CSC527, Chapter 1, Part 1 c 2012 Mitsunori Ogihara 1

1 Structural induction

Tutorial Automata and formal Languages

First Midterm Examination

1.3 Regular Expressions

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. FLAC (15-453) - Spring L. Blum

input tape head moves current state

E 1 (n) = E 0 (n-1) E 0 (n) = E 0 (n-1)+e 0 (n-2) T(n -1)=2E 0 (n-2) + E 0 (n-3)

CSE396 Prelim I Answer Key Spring 2017

Transcription:

Stte Minimiztion for DFAs Red K & S 2.7 Do Homework 10. Consider: Stte Minimiztion 4 5 Is this miniml mchine? Step (1): Get rid of unrechle sttes. Stte Minimiztion 6, Stte is unrechle. Step (2): Get rid of redundnt sttes. Sttes 2 nd re redundnt. Getting Rid of Unrechle Sttes We cn't esily find the unrechle sttes directly. But we cn find the rechle ones nd determine the unrechle ones from there. An lgorithm for finding the rechle sttes:, Lecture Notes 10 Stte Minimiztion 1

Getting Rid of Redundnt Sttes Intuitively, two sttes re equivlent to ech other (nd thus one is redundnt) if ll strings in Σ* hve the sme fte, regrdless of which of the two sttes the mchine is in. But how cn we tell this? The simple cse:,, Two sttes hve identicl sets of trnsitions out. The hrder cse: Getting Rid of Redundnt Sttes The outcomes re the sme, even though the sttes ren't. Finding n Algorithm for Minimiztion Cpture the notion of equivlence clsses of strings with respect to lnguge. Cpture the (weker) notion of equivlence clsses of strings with respect to lnguge nd prticulr FSA. Prove tht we cn lwys find deterministic FSA with numer of sttes equl to the numer of equivlence clsses of strings. Descrie n lgorithm for finding tht deterministic FSA. Defining Equivlence for Strings We wnt to cpture the notion tht two strings re equivlent with respect to lnguge L if, no mtter wht is tcked on to them on the right, either they will oth e in L or neither will. Why is this the right notion? Becuse it corresponds nturlly to wht the sttes of recognizing FSM hve to rememer. Exmple: (1) (2) Suppose L = {w {,}* : w is even}. Are (1) nd (2) equivlent? Suppose L = {w {,}* : every is immeditely followed y }. Are (1) nd (2) equivlent? Lecture Notes 10 Stte Minimiztion 2

Defining Equivlence for Strings If two strings re equivlent with respect to L, we write x L y. Formlly, x L y if, z Σ*, xz L iff yz L. Notice tht L is n equivlence reltion. Exmple: Σ = {, } L = {w Σ* : every is immeditely followed y } The equivlence clsses of L : L is the numer of equivlence clsses of L. Σ = {, } Another Exmple of L The equivlence clsses of L : Σ = {, } L = * The equivlence clsses of L : Yet Another Exmple of L An Exmple of L Where All Elements of L Are Not in the Sme Equivlence Clss Σ = {, } L = {w {, }* : no two djcent chrcters re the sme} The equivlence clsses of L : Lecture Notes 10 Stte Minimiztion

Σ = {, } L = n n The equivlence clsses of L : Is L Alwys Finite? L is n idel reltion. Bringing FSMs into the Picture Wht if we now consider wht hppens to strings when they re eing processed y rel FSM? Σ = {, },, Define ~ M to relte pirs of strings tht drive M from s to the sme stte. Formlly, if M is deterministic FSM, then x ~ M y if there is some stte q in M such tht (s, x) - * M (q, ) nd (s, y) - * M (q, ). Notice tht M is n equivlence reltion. An Exmple of ~M Σ = {, },, The equivlence clsses of ~ M : ~ M = Lecture Notes 10 Stte Minimiztion 4

Another Exmple of ~M Σ = {, },, The equivlence clsses of ~ M : ~ M = L: [,,,, ] w is even [,,,,,, ] w is odd ~ M, stte mchine: q1: [,,,, ] w is even q2: [,,, ] ( )* q: [,, ] ( )* ~ M, 2 stte mchine: q1: [,,,, ] w is even q2: [,,,,,, ] w is odd The Reltionship Between L nd ~ M ~ M is refinement of L. The Refinement L [even length] [odd length] (S) ~ M [even length] odd ending odd ending (R) ( stte) in in An equivlence reltion R is refinement of nother one S iff xry xsy In other words, R mkes ll the sme distinctions S does, plus possily more. R S Lecture Notes 10 Stte Minimiztion 5

~ M is Refinement of L. Theorem: For ny deterministic finite utomton M nd ny strings x, y Σ*, if x ~ M y, then x L y. Proof: If x ~ M y, then x nd y drive m to the sme stte q. From q, ny continution string w will drive M to some stte r. Thus xw nd yw oth drive M to r. Either r is finl stte, in which cse they oth ccept, or it is not, in which cse they oth reject. But this is exctly the definition of L. Corollry: ~ M L. When is this true? Going the Other Wy If x L(M) y then x ~ M y. Finding the Miniml FSM for L Wht's the smllest numer of sttes we cn get wy with in mchine to ccept L? Exmple: The equivlence clsses of L : Miniml numer of sttes for M(L) = This follows directly from the theorem tht sys tht, for ny mchine M tht ccepts L, ~ M must e t lest s lrge s L. Cn we lwys find mchine with this miniml numer of sttes? The Myhill-Nerode Theorem Theorem: Let L e regulr lnguge. Then there is deterministic FSA tht ccepts L nd tht hs precisely L sttes. Proof: (y construction) M = K sttes, corresponding to the equivlence clsses of L. s = [], the equivlence clss of under L. F = {[x] : x L} δ([x], ) = [x] For this construction to prove the theorem, we must show: 1. K is finite. 2. δ is well defined, i.e., δ([x], ) = [x] is independent of x.. L = L(M) Lecture Notes 10 Stte Minimiztion 6

The Proof (1) K is finite. Since L is regulr, there must exist mchine M, with ~ M finite. We know tht ~ M L Thus L is finite. (2) δ is well defined. This is ssured y the definition of L, which groups together precisely those strings tht hve the sme fte with respect to L. The Proof, Continued () L = L(M) Suppose we knew tht ([x], y) - M * ([xy], ). Now let [x] e [] nd let s e string in Σ*. Then ([], s) - M * ([s], ) M will ccept s if [s] F. By the definition of F, [s] F iff ll strings in [s] re in L. So M ccepts precisely the strings in L. The Proof, Continued Lemm: ([x], y) - M * ([xy], ) By induction on y : Trivil if y = 0. Suppose true for y = n. Show true for y = n+1 Let y = y', for some chrcter. Then, y' = n ([x], y') - M * ([xy'], ) (induction hypothesis) ([xy',] ) - M * ([xy'], ) (definition of δ) ([x], y') - M * ([xy'], ) (trns. of - M *) ([x], y) - M * ([xy], ) (definition of y) Theorem: A lnguge is regulr iff L is finite. Exmple: Consider: L = n n,,,, Equivlence clsses: Another Version of the Myhill-Nerode Theorem Proof: Regulr L is finite: If L is regulr, then there exists n ccepting mchine M with finite numer of sttes N. We know tht N L. Thus L is finite. L is finite regulr: If L is finite, then the stndrd DFSA M L ccepts L. Since L is ccepted y FSA, it is regulr. Lecture Notes 10 Stte Minimiztion 7

Σ = {, } L = {w {, }* : no two djcent chrcters re the sme} Constructing the Miniml DFA from L The equivlence clsses of L : 1: [] 2: [,,,,,...] ( )()* : [,,,,...] ( )()* 4: [,,,,...] the rest Equivlence clsses ecome sttes Strt stte is [] Finl sttes re ll equivlence clsses in L δ([x], ) = [x] 2 1 4, L = { n : n is prime} Using Myhill-Nerode to Prove tht L is not Regulr Consider: Equivlence clsses: So Where Do We Stnd? 1. We know tht for ny regulr lnguge L there exists miniml ccepting mchine M L. 2. We know tht K of M L equls L.. We know how to construct M L from L. But is this good enough? Consider: 4 5 6 Lecture Notes 10 Stte Minimiztion 8

Constructing Miniml FSA Without Knowing L We wnt to tke s input ny DFSA M' tht ccepts L, nd output miniml, equivlent DFSA M. Wht we need is definition for "equivlent", i.e., mergele sttes. Define q p iff for ll strings w Σ*, either w drives M to n ccepting stte from oth q nd p or it drives M to rejecting stte from oth q nd p. Exmple: Σ = {, },, Constructing s the Limit of Sequence of Approximting Equivlence Reltions n (Where n is the length of the input strings tht hve een considered so fr) We'll consider input strings, strting with, nd incresing in length y 1 t ech itertion. We'll strt y wy overgrouping sttes. Then we'll split them prt s it ecomes pprent (with longer nd longer strings) tht their ehvior is not identicl. Initilly, 0 hs only two equivlence clsses: [F] nd [K - F], since on input, there re only two possile outcomes, ccept or reject. Next consider strings of length 1, i.e., ech element of Σ. Split ny equivlence clsses of 0 tht don't ehve identiclly on ll inputs. Note tht in ll cses, n is refinement of n-1. Continue, until no splitting occurs, computing n from n-1. Constructing, Continued More precisely, for ny two sttes p nd q K nd ny n 1, q n p iff: 1. q n-1 p, AND 2. for ll Σ, δ(p, ) n-1 δ(q, ) Lecture Notes 10 Stte Minimiztion 9

The Construction Algorithm The equivlence clsses of 0 re F nd K-F. Repet for n = 1, 2, For ech equivlence clss C of n-1 do For ech pir of elements p nd q in C do For ech in Σ do See if δ(p, ) n-1 δ(q, ) If there re ny differences in the ehvior of p nd q, then split them nd crete new equivlence clss. Until n = n-1. is this nswer. Then use these equivlence clsses to colesce sttes. Σ = {, } An Exmple 1 2 4 5 6 0 =, 1 = 2 = (**)* 0 = 1 = Another Exmple Miniml mchine: Lecture Notes 10 Stte Minimiztion 10

Exmple: L={w {, }* : w is even} Another Exmple (() () () ())* S S T S T, T T T S T S S T #, Convert to deterministic: S = {s} δ = Minimize: Another Exmple, Continued S(1), T(2),, #S() 0 = 1 = Miniml mchine: Lecture Notes 10 Stte Minimiztion 11