AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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

Theory of Computation Regular Languages

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

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

Deterministic Finite Automata

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

Minimal DFA. minimal DFA for L starting from any other

Java II Finite Automata I

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

CISC 4090 Theory of Computation

Lecture 08: Feb. 08, 2019

Worked out examples Finite Automata

CHAPTER 1 Regular Languages. Contents

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

Formal Languages and Automata

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

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

Non-deterministic Finite Automata

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

Fundamentals of Computer Science

NFAs continued, Closure Properties of Regular Languages

GNFA GNFA GNFA GNFA GNFA

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

Lexical Analysis Finite Automate

Convert the NFA into DFA

Finite-State Automata: Recap

Non-deterministic Finite Automata

Finite Automata-cont d

1 Nondeterministic Finite Automata

State Minimization for DFAs

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

Homework 3 Solutions

Designing finite automata II

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

3 Regular expressions

Let's start with an example:

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

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

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

Chapter 2 Finite Automata

Languages & Automata

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

CMSC 330: Organization of Programming Languages

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

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

Nondeterminism and Nodeterministic Automata

CS375: Logic and Theory of Computing

Today s Topics Automata and Languages

Automata and Languages

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

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

1.3 Regular Expressions

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

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

Non-Deterministic Finite Automata

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

First Midterm Examination

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

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

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

NFAs continued, Closure Properties of Regular Languages

Coalgebra, Lecture 15: Equations for Deterministic Automata

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.

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

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

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

1.4 Nonregular Languages

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

1 From NFA to regular expression

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Formal Language and Automata Theory (CS21004)

Non Deterministic Automata. Formal Languages and Automata - Yonsei CS 1

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.

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

CS375: Logic and Theory of Computing

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

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

Some Theory of Computation Exercises Week 1

Harvard University Computer Science 121 Midterm October 23, 2012

Closure Properties of Regular Languages

Section: Other Models of Turing Machines. Definition: Two automata are equivalent if they accept the same language.

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

ɛ-closure, Kleene s Theorem,

In-depth introduction to main models, concepts of theory of computation:

Lecture 09: Myhill-Nerode Theorem

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

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

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

FABER Formal Languages, Automata and Models of Computation

Name Ima Sample ASU ID

Thoery of Automata CS402

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

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

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

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

Formal languages, automata, and theory of computation

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

Closure Properties of Regular Languages

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

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

Transcription:

25. Finite Automt AUTOMATA AND LANGUAGES A system of computtion tht only hs finite numer of possile sttes cn e modeled using finite utomton A finite utomton is often illustrted s stte digrm d d d. d q q q 2 q 3 E E d q 4 q 6 d +, - d q 5 26 Definition.5: Finite Automton A finite utomton is 5-tuple M = (Q,,, q, F), where Q is finite set clled the sttes, is finite set clled the lphet, : Q Q is the trnsition function, q Q is the strt stte, nd F Q is the set of (ccepting) finl sttes. A mchine M ccepts the string w = w w 2...w n n if sequence of sttes r, r,, r n in Q exists s.t. r = q, (r i, w i+ ) = r i+, i =,, n, r n F.

27 The lnguge recognized y M is L(M)={w* M ccepts w } A lnguge is clled regulr lnguge, if some finite utomton recognizes it Bsic opertions on lnguges A nd B re Union A B = { x x A x B }, Conctention AB = { xy x A y B } nd (Kleene) Str (closure) A* = { x x 2 x k k x i A i } 28 Properties of Regulr Lnguges Theorem.25 The clss of regulr lnguges is closed under the union opertion. In other words, if A nd A 2 re regulr lnguges, so is A A 2. Theorem.26 The clss of regulr lnguges is closed under the conctention opertion. DFA = Deterministic Finite Automton 2

29.. Minimiztion of DFAs Two utomt tht recognize exctly the sme lnguge re equivlent with ech other A finite utomton is miniml if it hs the smllest numer of sttes mong equivlent utomt An utomton tht hs more sttes thn in n equivlent miniml utomton is clled redundnt Algorithms producing utomt do not lwys generte miniml utomton Hndling miniml utomton is more efficient thn tht of redundnt utomton 3 Algorithm MINIMIZE Input: DFA M = (Q,,, q, F).. Remove ll sttes of M tht re unrechle from the strt stte. 2. Construct the following undirected grph G whose nodes re the sttes of M. 3. Plce n edge in G connecting every ccept stte with every nonccept stte. Add dditionl edges s follows. 4. Repet until no new edges re dded to G:. For every pir q, r Q, q r, nd every : dd the edge (q, r) to G if ((q, ), (r, )) is n edge of G. 2. For ech stte q Q let [q] e the collection of sttes 2. [q]= { q} {rq no edge joins q nd r in G }. 5. Form new DFA M = (Q,,, q, F ), where Q' = { [q] q Q }, (removing doules) '([q], ) = [(q, )], for every q Q nd, q = [q ] nd F' = { [q] q F }. 6. Output M. 3

3 2 4 6 3 5 32 [2] 2 4 [4, 5] [, 3] 3 [, 3] 5 [4, 5] 2 3 4 5 4

33 The End Result An utomton M tht is equivlent with the input utomton M', such tht it hs the minimum numer of sttes Automton M' is unique (up to the nming of the sttes)., 3 2 4, 5 34.2 Nondeterministic Finite Automt (NFAs) In n NFA stte cn hve mny possile lterntive trnsitions with the sme symol of the lphet Also -trnsitions re llowed Implementing nondeterministic ehvior is not strightforwrd (though possile), ut s modeling tool it is quite useful Vi NFAs we cn connect DFAs nd regulr expressions 5

35,,, q q q 2 q 3 36 The definition of n utomton requires the trnsition function to e function On the other hnd, in n NFA the trnsition function should get mpped to set of vlues An NFA ccepts string if sequence of possile sttes leds to finl stte. Only if no such sequence exists will the NFA reject the input string E.g. the previous NFA ccepts the string ecuse it cn e processed s follows (q, ) (q, ) (q, ) (q 2, ) (q 3,) (q 3, ) (q 3, ) 6

37,,, q q q 2 q 3 On the other hnd, we cn end up in rejecting stte: (q, ) (q, ) (q, ) (q, ) (q, ) (q, ) (q 2, ) 38 Definition of n NFA Let P(A) = { B B A } denote the power set of the set A nd for n lphet = { } A nondeterministic finite utomton is 5-tuple N = (Q,,, q, F) Q is finite set of sttes, is finite lphet, : Q P(Q) is the (set-vlued) trnsition function, tht lso llows -trnsitions q Q is the strt stte, nd F Q is the set of (ccepting) finl sttes 7

39 The trnsition function of the previous utomton is q {q } {q q } Ø q {q 2 } Ø {q 2 } q 2 Ø {q 3 } Ø q 3 {q 3 } {q 3 } Ø Now we cn esily express the error stte s n empty set of possile next sttes 4 An NFA N = (Q,,q, F) ccepts the string w, If we cn write it s w = y y 2 y m m nd sequence of sttes r, r,, r m exists in Q s.t. r = q, r i+ (r i, y i+ ), i =,, m, nd r m F. DFAs re specil cse of NFAs ll lnguges tht cn e recognized using the former cn lso e recognized using the ltter Also the other wy round: DFAs nd NFAs recognize the sme set of lnguges 8

4 Theorem.39 Let A = L(N) e the lnguge recognized y some NFA N. There exists DFA M such tht L(M) = A Proof. Let N = (Q,,q, F). We construct DFA M =(Q,,q, F ) tht simultes the computtion of N in prllel in ll its possile sttes t ll times. Let us first consider the esier sitution where N hs no rrows. Every stte of M is set of sttes of N Q' = P(Q) q ' = { q } F' ={RQ R contins n ccept stte r F } '(R, ) = r R (r, ) 42 Without rrows,,, q q q 2 q 3 {q } {q, q } {q,q 2 } {q, q, q 3 } {q, q 2, q 3 } {q, q 3 } 9

43 After Minimiztion R R R 2 R 3, 44 Let us check tht L(M) = L(N). The equivlence of the lnguges follows when we prove for ll x * nd r Q tht (q, x) N (r, ) ({q }, x) M (R, ) nd r R, where the nottion (q, x) N (r, ) mens tht in utomton N we cn process the string x strting from stte q so tht we end up in stte r nd there re no more symols to process (). We prove it using induction over the length of the string x :. Bsis: x = : (q, ) N (r, ) r = q. Similrly ({q }, ) M (R, ) R = {q }

45 2. Induction hypothesis: the clim holds when x k 3. x = k+: Then x = y for some y, y = k, for which the clim holds y the induction hypothesis. Now, (q, x) = (q, y) N (r, ) r' Q s.t. (q, y) N (r', ) nd (r', ) N (r, ) = in one trnsition r' Q s.t. (q, y) N (r', ) nd (r', ) N (r, ) By induction hypothesis we get r Q s.t. ({q }, y) M (R', ) nd r' R nd r (r', ) Rerrnging yields ({q }, y) M (R', ) nd r' R' s.t. r (r', ) By the definition of the trnsition function ' 46 ({q }, y) M (R', ) nd r r' R' (r', ) = '(R', ) Let us return nd nme '(R', ) ({q }, y) M (R', ) nd r '(R', ) = R ({q }, y) M (R', ) nd (R', ) M (R, ) nd r R Concluding ({q }, x) = ({q }, y) M (R, ) nd r R Which completes the proof of the clim

47 In order to tke the rrows into ccount, we compute for ech stte R Q of M the collection of sttes tht cn e reched from R y going only long rrows: E(R)={q q cn e reched from R y trveling long or more rrows } It is enough to modify the trnsition function of M nd strt stte to tke the rrows into ccount: '(R, ) = rr E(r, )) q ' = E({q }) 48 With rrows,,, q q q 2 q 3 {q } {q, q,q 2 } {q q 3 } {q,q 2, q 3 } {q,q 2 } {q, q 3 } 2

49 After Minimiztion R R R 2 R 3, 5 Theorem.45 The clss of regulr lnguges is closed under the union opertion. Proof. Let the lnguges A nd A 2 e regulr. Then, there exists (nondeterministic) finite utomt N = (Q,,q, F ) nd N 2 = (Q 2, 2,q 2, F 2 ), which recognize these two lnguges. Let us construct n utomton N = (Q,,q, F) for recognizing the lnguge A A 2. Q = { q } Q Q 2, The strt stte of N is q, ( q,), q Q F = F F 2 nd 2( q,), q Q2 ( q,) { q, q2}, q q nd Ø, q q nd 3

5 q N q q 2 N 2 52 Theorem.47 The clss of regulr lnguges is closed under the conctention opertion. Proof. Let the lnguges A nd A 2 e regulr. Then, there exists (nondeterministic) finite utomt N = (Q,,q,F )nd N 2 = (Q 2, 2,q 2,F 2 ),which recognize these two lnguges. Let us construct n utomton N = (Q,,q,F 2 )for recognizing A A 2. Q = Q Q 2, The strt stte of N is q, The finl sttes of N re those in F 2 nd ( q, ), ( q, ), ( q, ) ( q, ) { q2}, 2( q, ), qq nd q F q F nd q F nd qq 2 4

53 q q 2 N N 2 54 Theorem.49. The clss of regulr lnguges is closed under the str opertion. Proof. Let the lnguge A e regulr. Then, there exists (nondeterministic) finite utomton N = (Q,,, q, F ), which recognizes the lnguge. Let us construct n utomton N = (Q,,, q, F) for recognizing A*. Q = { q } Q, The new strt stte of N is q, F = { q } F nd ( q, ), ( q, ), ( q, ) ( q, ) { q}, { } Ø, q q Q nd q F q F nd q F nd q q q q nd nd 5

55 q q N 6