GNFA GNFA GNFA GNFA GNFA

Similar documents
Today s Topics Automata and Languages

Automata and Languages

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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

Minimal DFA. minimal DFA for L starting from any other

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

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

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

CMSC 330: Organization of Programming Languages

Finite Automata-cont d

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

State Minimization for DFAs

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

Designing finite automata II

Theory of Computation Regular Languages

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

Convert the NFA into DFA

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Formal Languages and Automata

Harvard University Computer Science 121 Midterm October 23, 2012

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.

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

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

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

Worked out examples Finite Automata

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

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

Let's start with an example:

Lexical Analysis Finite Automate

CHAPTER 1 Regular Languages. Contents

Finite-State Automata: Recap

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

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

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

Lecture 08: Feb. 08, 2019

Fundamentals of Computer Science

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

Homework 3 Solutions

Lecture 09: Myhill-Nerode Theorem

1 Nondeterministic Finite Automata

CISC 4090 Theory of Computation

Deterministic Finite Automata

Principles of Programming Languages

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

Chapter 2 Finite Automata

Nondeterminism and Nodeterministic Automata

Formal Language and Automata Theory (CS21004)

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

DFA minimisation using the Myhill-Nerode theorem

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

NFAs continued, Closure Properties of Regular Languages

1 From NFA to regular expression

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

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

FABER Formal Languages, Automata and Models of Computation

Myhill-Nerode Theorem

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

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

Formal languages, automata, and theory of computation

Coalgebra, Lecture 15: Equations for Deterministic Automata

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

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

Java II Finite Automata I

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

First Midterm Examination

DFA Minimization and Applications

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

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

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

1.3 Regular Expressions

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

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

Some Theory of Computation Exercises Week 1

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Closure Properties of Regular Languages

NFAs continued, Closure Properties of Regular Languages

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

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

Thoery of Automata CS402

Name Ima Sample ASU ID

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

CS375: Logic and Theory of Computing

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

CS 330 Formal Methods and Models

Closure Properties of Regular Languages

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Nondeterministic Automata vs Deterministic Automata

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

Tutorial Automata and formal Languages

CSE396 Prelim I Answer Key Spring 2017

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

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

Languages & Automata

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

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

3 Regular expressions

Transcription:

DFA RE NFA DFA -NFA REX GNFA Definition GNFA A generlize noneterministic finite utomton (GNFA) is grph whose eges re lele y regulr expressions, with unique strt stte with in-egree, n unique finl stte with out-egree. A string u is si to lel pth in GNFA, if it is n element of the lnguge generte y the regulr expression which is gotten y conctenting ll lels of eges trverse in the pth. The lnguge ccepte y GNFA consists of ll the ccepte strings of the GNFA. GNFA GNFA 2 ( )* q S q f c * * This is GNFA ecuse eges re lele y REX s, strt stte hs no in-eges, n the unique finl stte hs no out-eges. Q: Is ccepte 2 GNFA A: is ccepte. The pth given y c λ proves this fct. (The lst lel results from ( )* ) ( )* c Definition GNFA A Generlize noneterministic finite utomton (GNFA) is efine y M=(Q, S,, q strt, q finl ) with Q finite set of sttes S the input lphet q strt the strt stte with in-egree q finl the ccept stte with out-egree :(Q\{q finl }) (Q\{q strt }) Ρ the trnsition function (Ρ is the set of regulr expressions over S)

Theorem DFA GNFA For every DFA M, there exist n equivlent GNFA M DFA GNFA Remove Internl stte of GNFA If the GNFA M hs more thn 2 sttes, rip internl q rip to get equivlent GNFA M y: - Removing stte q rip : Q =Q\{q rip } - Chnging the trnsition function y (q i,q j ) = (q i,q j ) ((q i,q rip )((q rip,q rip ))*(q rip,q j )) for every q i Q \{q finlt } n q j Q \{q strt } R q rip R 2 q i R 3 = q i R 4 (R R 2 *R 3 ) q j R 4 q j GNFA RE R Ripping out GNFA RE Ripping out is one s follows. If you wnt to rip the mile stte v out of: u r r 2 v r 3 w q s * * e q f then you ll nee to recrete ll the lost possiilities from u to w. I.e., to the current REX lel r 4 of the ege (u,w) you shoul the conctention of the (u,v ) lel r followe y the (v,v )-loop lel r 2 repete ritrrily, followe y the (v,w ) lel r 3.. The new (u,w ) sustitute woul therefore e: r 4 u r 4 r (r 2 )*r 3 w Theorem For every (NFA) DFA M, there exist n equivlent RE R, with L(M)=L(R) Proof ie:. Trnsform n NFA into n equivlent GNFA 2. Trnsform the GNFA into regulr expression y removing sttes n releling the rrows with regulr expressions Proof ie:. NFA GNFA NFA A unique n istinct strt stte with in-egree n finl stte with out-egree, then connect them to the NFA with 2. GNFA RE While mchine hs more thn 2 sttes: Pick n internl stte, rip it out n re-lel the rrowswith regulr expressions to ccount for the missing stte For : * 2 2

2, *(*)( )* q q q R(q, ) = (*)( )* 3 4 2 2 ( )* = R(q,q ) q q ( )* 5 6 GNFA RE GNFA RE Strt with: This is not GNFA ecuse finl stte, though unique, hs nonzero out-egree. First we nee to convert this into GNFA. Strt stte hs zero in-egree, so is oky. 7 Just e n ccept stte y connecting vi from the ol ccept stte. Since the lels re single letters, they re utomticlly regulr expressions so this is GNFA An we re rey to strt ripping out interior sttes. 8 3

3 3 Now, let s rip out. A: (,c ): CD*A A2: (c,c ): CD*A Q: Wht will e the lel of (,c ) Next, rip out c. Q2: Wht will e the lel of (c,c ) Q: Wht will e the lel of (, ) 9 2 3 3 A: B (CD*A)(CD*A)*B which simplifies to B (CD*A) + B Next, rip out. Finlly, rip out : 2 22 3 Exercise Convert the following NFA into regulr expression The resulting REX Is the unique lel (A D(B (CD*A) + B)) + q, ( )*(*)* ( )* ( )*(*)* * 23 24 4

Answer (( )*(*)*)* (( )*(*)*)*( )*(*)* Algorithm Next we stuy the Algorithm 25 26 Algorithm: A q strt n q finl to crete G Run CONVERT(G): If #sttes = 2 If #sttes return the > 2 expression on the rrow going from q strt to q finl Algorithm: Run CONVERT(G): A q strt n q finl to crete G If #sttes > 2 select q rip Q ifferent from q strt n q finl efine Q = Q {q rip } efine R s: R (q i,q j ) = R(q i,q rip )R(q rip,q rip )*R(q rip,q j ) R(q i,q j ) return CONVERT(G ) 27 28 Algorithm: CONVERT(G) is equivlent to G Proof y inuction on k (numer of sttes in G) Bse Cse: k = 2 Inuctive Step: Assume clim is true for k- sttes We first note tht G n G re equivlent But, y the inuction hypothesis, G is equivlent to CONVERT(G ) 29 3 5

Strings over {,} with even numer of s Σ* Strings over {,} with even numer of s Σ* E O E O E O E O [E,E] [O,E] [E,O] [O,O] [E] [O] 3 32 Oservtion The sttes mong the stte sets {[E,E], [E,O]} n {[O,E], [O,O]} iffer on spect immteril for the prolem t hn. Why not collpse these stte sets into one stte ech, to get smller DFA Definition Equivlent or Inistinguishle Sttes Recll tht DFA stte summrizes the sustring consume so fr (tht is, the pst history). Two sttes q i n q j re equivlent or (inistinguishle), if, when strte in these sttes, every string cuses the mchine to either en up in finl stte for oth or en up in non-ccepting stte for oth. Two sttes q i n q k re equivlent (or inistinguishle), if for ll strings w S* (q i, w) F (q k, w) F Two sttes q i n q k re istinguishle, if for some string w S* (q i, w) F (q k, w) ˇ F 33 34 Min Ie q i q j q m q n q q4 DFA q q2,, q5 q7 q3 If q m n q n re istinguishle, then so re q i n q j ( u )( u *) q6, 35 36 6

Refinement of Stte Prtitions { {q,q7}, {q,q2,q3,q4,q5,q6} } { {q},{q7}, {q,q2,q3,q4,q5,q6} } On ny trnsition { {q},{q7}, {q,q2,q3,q4,q5,q6} } { {q},{q7}, {q,q4}, {q2,q3,q5,q6} } On trnsition { {q},{q7}, {q,q4}, {q2,q5},{q3,q6} } On trnsition Showing equivlent sttes in DFA q q q2,, q4 q5 q7 q6 ( u )( u *), q3 37 38 Minimum DFA q,, q,q4 q2,q5 q7 Equivlent Sttes Consier the ccept sttes c n g. They re oth sinks mening tht ny string which ever reches them is gurntee to e ccepte lter. Q: Do we nee oth sttes,, c ( u )( u *) q3,q6, 39 f e, g 4 A: No, they cn e unifie s illustrte elow. Q: Cn ny other sttes e unifie ecuse ny susequent string suffixes prouce ienticl results Joining Equivlent Sttes e,, cg A: Yes, n f. Notice tht if you re in or f then:. if string ens, reject in oth cses 2. if next chrcter is, forever ccept in oth cses 3. if next chrcter is, forever reject in oth cses So unify with f. Equivlent Sttes e,, cg f 4 f 42 7

Intuitively two sttes re equivlent if ll susequent ehvior from those sttes is the sme. Q: Come up with forml chrcteriztion of stte equivlence. Joining Equivlent Sttes e,, cg Finishing the Q: Any other wys to simplify the utomton e,, cg, f 43, f 44 Useless Sttes A: Get ri of. Getting ri of unrechle useless sttes oesn t ffect the ccepte lnguge. Definition An utomton is irreucile if it contins no useless sttes, n no two istinct sttes re equivlent. e,, cg Gols of the Minimiztion Algorithm The gol of minimiztion lgorithm is to crete irreucile utomt from ritrry ones., f 45 The lgorithm ctully prouces smllest possile DFA for the given lnguge, hence the nme minimiztion. 46 Minimiztion Algorithm First Prt: Prtition DFA minimize(dfa (Q, Σ, δ, q, F ) ) remove ny stte q unrechle from q Prtition P = {F, Q - F } oolen Consistent = flse while( Consistent == flse ) Consistent = true for(every Set S P, symol Σ, Set T P ) Set temp = {q T δ(q,) S } if (temp!= Ø && temp!= T ) Consistent = flse P = (P T ) {temp,t temp} return efineminimizor( (Q, Σ, δ, q, F ), P ) 47 Minimiztion Algorithm DFA efineminimizor (DFA (Q, Σ, δ, q, F ), Prtition P ) Set Q =P Stte q = the set in P which contins q F = { S P S F } for (ech S P, Σ) efine δ (S,) = the set T P which contins the sttes δ (S,) return (Q, Σ, δ, q, F ) Secon Prt: Minimiztion 48 8

Minimiztion Minimiztion Miniture version à Strt with DFA 49 5 Minimiztion Minimiztion Split into two prts. ACCEPT vs. REJECT -lel oesn t split 5 52 Minimiztion -lel splits up REJECT's Minimiztion No further splits. HALT! 53 54 9

En Result Sttes of the miniml utomt re remining. Minimiztion. Compre 55 56 Minimiztion. Compre Minimiztion. Compre 57 58 Minimiztion. Compre Minimiztion. Compre 59 6

Minimiztion. Compre Minimiztion. Compre 6 62 Minimiztion. Compre Minimiztion. Compre 63 64 Minimiztion. Compre Minimiztion. Compre ACCEPTED. 65 66

Minimiztion. Compre Minimiztion. Compre 67 68 Minimiztion. Compre Minimiztion. Compre 69 7 Minimiztion. Compre Miniml Automton Previous lgorithm gurntee to prouce n irreucile FA. Why shoul tht FA e the smllest possile FA for its ccepte lnguge REJECT. 7 72 2

Theorem Proof Miniml Automton (Myhill-Neroe): The minimiztion lgorithm prouces the smllest possile utomton for its ccepte lnguge. Show tht ny irreucile utomton is the smllest for its ccepte lnguge L: We sy tht two strings u,v Σ* re inistinguishle if for ll suffixes x, ux is in L exctly when vx is. Notice tht if u n v re istinguishle, the pth from their pths from the strt stte must hve ifferent enpoints. 73 Proof (cont.) Consequently, the numer of sttes in ny DFA for L must e s gret s the numer of mutully istinguishle strings for L. But n irreucile DFA hs the property tht every stte gives rise to nother mutully istinguishle string! Therefore, ny other DFA must hve t lest s mny sttes s the irreucile DFA 74 Quiz IS ITS THIS MINIMAL DFA MINIMAL DFA NO IS Quiz IS THIS DFA MINIMAL q, q 75 76 Definition For DFA M = (Q, S,, q, F), let p, q, r Q Definition: p ~ q iff p is inistinguishle (equivlent) from q p ~ / q iff p is istinguishle from q Proposition: ~ is n equivlence reltion p ~ p (reflexive) p ~ q p ~ q n q ~ r q ~ p (symmetric) p ~ r (trnsitive) Definition: so p ~ ~ prtitions q iff p is the inistinguishle set of sttes of from M into q isjoint equivlence clsses p ~ / q iff p is istinguishle from q [q] = { p p ~ q } Proposition: ~ is n equivlence reltion p ~ p (reflexive) Q q p ~ q q ~ p (symmetric) q Definition For DFA M = (Q, S,, q, F), let p, q, r Q p ~ q n q ~ r p ~ r (trnsitive) 77 78 3

Algorithm Algorithm MINIMIZE Input: DFA M Output: DFA M MIN such tht: M M MIN M MIN hs no inccessile sttes M MIN is irreucile sttes of M MIN re pirwise istinguishle Theorem: M MIN is the unique minimum 79 Ie: Sttes of M MIN will e locks of equivlent sttes of M 8 Algorithm TABLE-FILLING ALGORITHM Input: DFA M = (Q, S,, q, F) Output: () D M = { (p,q) p,q Q n p ~ / q } (2) E M = { [q] q Q } q q q q Bse Cse: p ccepts n q rejects p ~ / q q i Recursion: p p q n ~/ q q q q q i q n p ~ / q 8 q q, q q 82 q q q q Algorithm Algorithm MINIMIZE Input: DFA M Output: DFA M MIN () Remove ll inccessile sttes from M (2) Apply Tle-Filling lgorithm to get E M = { [q] q is n ccessile stte of M } M MIN = (Q MIN, S, MIN, q MIN, F MIN ) Q MIN = E M, q MIN = [q ], F MIN = { [q] q F } q q 83 MIN ( [q],s ) = [ ( q,s ) ] 84 4

MINIMIZE q q Exercise Minimize the following DFA q q, q 4, q 5 85 86 q q q 4, q q, q 5 q 4 q 5 q q q 4 q 5 87 5