CS 573 Automata Theory and Formal Languages

Similar documents
Regular languages refresher

NON-DETERMINISTIC FSA

Nondeterministic Finite Automata

Nondeterministic Automata vs Deterministic Automata

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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

Finite Automata-cont d

Running an NFA & the subset algorithm (NFA->DFA) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

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

Let's start with an example:

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

Finite State Automata and Determinisation

CSE 401 Compilers. Today s Agenda

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

CMSC 330: Organization of Programming Languages

Lecture 08: Feb. 08, 2019

2.4 Theoretical Foundations

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

Non-deterministic Finite Automata

= state, a = reading and q j

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

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

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

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

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

Fundamentals of Computer Science

Minimal DFA. minimal DFA for L starting from any other

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

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

CHAPTER 1 Regular Languages. Contents

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

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

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

Theory of Computation Regular Languages

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

Deterministic Finite Automata

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

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

Non-deterministic Finite Automata

Designing finite automata II

Nondeterminism and Nodeterministic Automata

1 Nondeterministic Finite Automata

Section 1.3 Triangles

Finite-State Automata: Recap

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

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

Chapter 2 Finite Automata

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

Formal Language and Automata Theory (CS21004)

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

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.

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

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

CS241 Week 6 Tutorial Solutions

Worked out examples Finite Automata

CS375: Logic and Theory of Computing

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

Convert the NFA into DFA

Java II Finite Automata I

1 From NFA to regular expression

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

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

Descriptional Complexity of Non-Unary Self-Verifying Symmetric Difference Automata

Petri Nets. Rebecca Albrecht. Seminar: Automata Theory Chair of Software Engeneering

Formal Languages and Automata

@#? Text Search ] { "!" Nondeterministic Finite Automata. Transformation NFA to DFA and Simulation of NFA. Text Search Using Automata

Prefix-Free Regular-Expression Matching

CISC 4090 Theory of Computation

Today s Topics Automata and Languages

Automata and Languages

Harvard University Computer Science 121 Midterm October 23, 2012

System Validation (IN4387) November 2, 2012, 14:00-17:00

Homework 3 Solutions

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

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

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.

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

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

where the box contains a finite number of gates from the given collection. Examples of gates that are commonly used are the following: a b

Lecture 6 Regular Grammars

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

Lexical Analysis Finite Automate

More Properties of the Riemann Integral

Non-Deterministic Finite Automata

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

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

Closure Properties of Regular Languages

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

Chapter 4 State-Space Planning

NFAs continued, Closure Properties of Regular Languages

State Complexity of Union and Intersection of Binary Suffix-Free Languages

Compression of Palindromes and Regularity.

input tape head moves current state

Bisimulation, Games & Hennessy Milner logic

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

Name Ima Sample ASU ID

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

Some Theory of Computation Exercises Week 1

Transcription:

Non-determinism Automt Theory nd Forml Lnguges Professor Leslie Lnder Leture # 3 Septemer 6, 2 To hieve our gol, we need the onept of Non-deterministi Finite Automton with -moves (NFA) An NFA is tuple M = (Q, Σ,, δ, F), where δ is modified to e funtion δ : Q (Σ { }) P(Q) There re two spets to non-determinism: one-to-mny trnsitions spontneous trnsitions CLASS 3-7 one-to-mny trnsitions where do we go from stte? For n NFA, δ(, ) is n element of P(Q ), i.e. suset of Q, for exmple δ(, ) = {,, 3, 4 } If we re in stte nd the input is, we n hoose to move to ny one of,, 3 or 4 4 3 Of ourse, if there is no input, we n lso hoose to sty t stte Thus, if we reh stte while proessing n input string, then the next trnsition ould e from ny of the sttes,, or 3 3 CLASS 3-8 CLASS 3-9

-losure of stte First we define the -losure of stte: (i) is in -los() (ii) if -los() nd δ (, ) then -los() Thus -los() hs nd ll the sttes tht n e rehed from y seuenes of -trnsitions Exmple The sttes olored gry re ll in the set -los() CLASS 3- CLASS 3- -losure of set of sttes We n extend the definition of -los() to -los(s) for set of sttes S. -los(s) onsists of S nd ll sttes rehle from stte in S y -trnsitions -los(s) = U -los() S Extending δ We n modify δ to δ* in three steps s follows: Define δ*:q Σ P(Q) y δ*(, ) = -los(δ(, )) Next we extend s follows: δ*:p(q) Σ P(Q) y defining δ*(s, ) = U δ*(, ) S Finlly we extend to strings in Σ* CLASS 3-2 CLASS 3-3

The lnguge of n NFA Define δ*:p(q) Σ* P(Q) y δ*(s, ) = -los(s) δ*(s, w ) = δ*(δ*(s, w ), ) Rememer tht every pplition of δ*lwys dds the -losure to the set of points rehed y trnsition For n NFA lled M, the lnguge of M is denoted L(M ). L(M ) = {w Σ * : δ*(-los( ),w) F Ø} Definition of the lnguge of n NFA L(M ) = {w Σ * : δ*(-los( ),w) F Ø} Exmple: -los( ) = {, }, -los( 3 ) = {, 3 }, 3, CLASS 3-4 CLASS 3-5 Exmple-I Exmple-II δ*(-los( ), ) = δ*({, }, ) = -los(δ(, )) -los(δ(, )) = -los(ø) -los({, })={,, }, 3 δ*(-los( ), ) = δ*(δ*(-los( ),), ) = δ*({,, }, ) = -los({, 3 }) = {,, 3 }, so is epted, 3,, CLASS 3-6 CLASS 3-7

CLASS 3-8 Exmple-III δ*(-los( ), )= δ*(δ*(-los( ), ),) = δ*({,, 3 }, ) = -los({,, 3 }) = {,,, 3 }, so is epted, 3, CLASS 3-9 Wht is going on? The definition of eptne y n NFA is sutle nd hidden y ll the forml definitions Given string w = 2... n, it is epted if you n strt t nd finish t finl stte, possily using -trnsitions long the wy So we my relly e using trnsitions leled something like,,, 2,,,,, n, one pth to finl stte mens eptne Further, there my e lternte rnhes with the sme lels tht led to non-finl stte or tht go nowhere (with or without -trnsitions) The point is: n you mke the right hoie of edges nd intermedite uses of to get from to finl stte? Why non-determinism? We will see in our exmples tht n NFA n e more ompt nd intuitive thn DFA for the sme lnguge However, we hve to show tht they reognize the sme lss of lnguges, i.e. ll n NFA n do is reognize regulr lnguge ONE suh pth mens eptne of w CLASS 3-2 CLASS 3-2

CLASS 3-22 Exmple The following is one of mny NFA s tht reognize ** + ** 5 3 4 6 Converting n NFA to n euivlent DFA Given lnguge L, espeilly one desried y regulr expression, it is usully esiest to onstrut n NFA M tht reognizes the lnguge However, DFA M 2 would e esier to write progrm for, for exmple Hene we re interested in onverting M to M 2 ut ensuring L = L(M ) = L(M 2 ) CLASS 3-23 CLASS 3-24 The trik The trik is simply to onsider susets of Q, i.e. the elements of P(Q) to e sttes of new utomton Given n NFA M = (Q, Σ,, δ, F ), onsider the utomton: M 2 = (P(Q), Σ, -los( ), δ 2, F 2 ), where δ 2 = δ*: P(Q) Σ P(Q) nd F 2 is the olletion of ll susets of Q tht ontin n element of F M 2 IS DFA susets re elements of nother universe Rell tht δ*:p(q) Σ* P(Q) nd so we n restrit the funtion to words of length to otin funtion δ*:p(q) Σ P(Q) This lst δ* is deterministi euse it tkes n element of P(Q) nd symol in Σ to nother element of P(Q) Now, P(Q) is ig: if Q hs 8 elements, P(Q) hs 2 8 = 256 elements, whih is lot of sttes CLASS 3-25

Get resonle We will give onstrutive method tht only puts the rehle sttes into M 2, whih is often more mngele However, we wnt L(M ) = L(M 2 ) First, it is tedious symol-dense exerise to hek tht δ 2 * = δ*:p(q) Σ + P(Q) so eptne of w y M 2 reuires Symol-dense verifition By definition δ 2 = δ*:p(q) Σ P(Q), so onsider S in P(Q) (i.e. S Q), so δ 2 * = δ* gree on string of length We proeed y indution, suppose δ 2 * = δ* gree on ll strings of length up to n Pik string w = w, where w =n + nd so w =n δ*(-los( ), w) F 2 CLASS 3-26 CLASS 3-27 CLASS 3-28 Symol-dense verifition - 2 From slide 2-34 δ 2 *(S, w) = δ 2 *(S, w ) = δ 2 (δ 2 *(S, w ), ) = δ*(δ 2 *(S, w ), ), sine δ 2 (..., ) = δ*(..., ) y definition By the indutive hypothesis δ 2 *(S, w ) = δ*(s, w ) Therefore δ 2 *(S, w) = δ*(δ*(s, w ), ) = δ*(s, w ) = δ*(s, w) CLASS 3-29 Symol-dense verifition - 3 Also, look t the definition of δ 2 * (for deterministi trnsition funtion) δ 2 *(S, ) = S (see slide 2-34) while δ*(s, ) = -los(s) (from 3-4) These two expressions oinide if S = -los( ) sine -los(-los( )) Altogether, δ 2 *(-los( ), w) = δ*(-los( ), w)

Euivlene is esy Look t the definition of F 2 ; it tells us tht δ*(-los( ), w) is n element of F 2 preisely when δ*(-los( ), w) ontins n element of F, i.e. δ*(-los( ),w) F Ø This seond riterion defines the eptne of w y M The lnguge of the NFA is the lnguge of the DFA Prtil onversion NFA to DFA Suppose we hve n NFA trnsition tle Ø { 4 } { } { 5 } { } Ø { 3 } Ø { 5 } 3 Ø {, 4 } { } 4 Ø { 6 } { } 5 6 Ø { 6 } Ø Ø { } { } CLASS 3-3 CLASS 3-3 Trnsition grph DFA: initil stte Trnsition grph 5, 3 4 6 CLASS 3-32 The initil stte is -los{ } = {, } We fill in the δ*-trnsitions from this initil stte (so we lwys dd the -losure) {, } {,, 5 } {,,, 4, 5 } This is unwieldy, so we revite s follows:.,..5,..2.4.5, et. CLASS 3-33

CLASS 3-34 Keep dding rehle sttes Every stte we reh gets dded to the left-hnd olumn:...5..2.4.5..5..5..2.4.5..2.4.5 *..2.3.5..2.4.5.6..2.3.5 *..2.3.5..2.4.5..2.4.5.6 *..2.3.5.6..2.4.5.6..2.3.5.6 *..2.3.5.6..2.4.5 * finl sttes The DFA is smller (unusul)! The onverted DFA The finl DFA:...2.4.5.6..5..2.4.5..2.3.5 CLASS 3-35..2.3.5.6 CLASS 3-36 Notes DFA finl sttes re those ontining one of the finl sttes of the NFA A seond exmple is provided on the ourse we pges In tht exmple, there is stte Ø, whih is ded stte: one you enter ded stte you n never reh finl stte ny string tht tkes to ded stte in DFA n never e epted getting n NFA from regulr expression-i If we hve regulr expression r, we need to onstrut n NFA M so tht L(M ) = L(r ) A regulr expression whih represents lnguge with only one element denotes the lnguge epted y n NFA with liner seuene of sttes: Regulr expression NFA (in ft DFA): CLASS 3-37

getting n NFA from regulr expression-ii Finite lnguges, whih re not singletons, re lso esy: + Kleene losure - I The Kleene losure is often simple: onsider r *r 2, where r nd r 2 re regulr expressions grph for r grph for r 2 CLASS 3-38 CLASS 3-39 Kleene losure - II Kleene losure - III Next onsider r ()*r 2, where r nd r 2 re regulr expressions The following is n NFA for (++)* grph for r CLASS 3-4 grph for r 2 It is not uniue The next slide hs n lterntive CLASS 3-4

Kleene losure - IV Euivlent full-dfa (++)* The following slides hve full-dfa nd DFA with the ded stte removed. 3,,,,,,,, CLASS 3-42 CLASS 3-43 Euivlent DFA A simple sum This seond DFA should demonstrte tht the grphi is lerer without the ded sttes showing. 3 The NFA for + ould e either of the following, mong others CLASS 3-44 CLASS 3-45

A simple ontention The NFA for * ould e the following, mong others Euivlent DFA The following is the DFA derived from the previous NFA CLASS 3-46 CLASS 3-47 The stndrd onstrution NFA s for the si regulr expressions We wnt to show tht ny regulr expression hs n NFA We do this y lwys reting NFA s tht hve SINGLE FINAL STATE tht is different from We show how to omine them to uild lrger regulr expressions The si regulr expressions re,, nd nd the simplest NFA s with single initil nd finl stte re: NOTE: the following is simpler for ut does not fit the seprte initil/finl sttes property: CLASS 3-48 CLASS 3-49

The NFA for sum of regulr expressions Grph for the sum If we hve onstruted the NFA s (eh with single finl stte) for two regulr expressions r nd r 2 then the NFA for r +r 2 is shown next grph for r The two finl sttes from r nd r 2 re no longer finl. A new single finl stte is dded with -trnsitions from the old finl stte grph for r 2 CLASS 3-5 CLASS 3-5 The NFA for sum of regulr expressions - II Wht were finl sttes in the grphs of r nd r 2 re no longer finl sttes (they re shown with dotted lines round them There is only one finl stte The NFA for ontention of reg. expr. If we hve onstruted the NFA s (eh with single finl stte) for two regulr expressions r nd r 2 then the NFA for r r 2 is shown next CLASS 3-52 CLASS 3-53

Grph for the ontention The NFA for the Kleene losure of reg. expr. grph for r If we hve onstruted the NFA (eh with single finl stte) for the regulr expression r then the NFA for r * is shown next grph for r 2 grph for r CLASS 3-54 CLASS 3-55