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

Similar documents
Nondeterministic Finite Automata. Nondeterminism Subset Construction

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

Theory of Computation Regular Languages

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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

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

CMSC 330: Organization of Programming Languages

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

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

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

Non-deterministic Finite Automata

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

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

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

Non-deterministic Finite Automata

CS375: Logic and Theory of Computing

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

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

Worked out examples Finite Automata

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

Finite-State Automata: Recap

Fundamentals of Computer Science

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

Minimal DFA. minimal DFA for L starting from any other

Homework 3 Solutions

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

NFAs continued, Closure Properties of Regular Languages

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

Java II Finite Automata I

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

Deterministic Finite Automata

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

Nondeterminism and Nodeterministic Automata

Convert the NFA into DFA

Lecture 6 Regular Grammars

Lexical Analysis Finite Automate

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

Finite Automata-cont d

CHAPTER 1 Regular Languages. Contents

Non-Deterministic Finite Automata

State Minimization for DFAs

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

Formal Languages and Automata

Chapter 2 Finite Automata

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

CISC 4090 Theory of Computation

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

Deterministic Finite-State 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

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

Designing finite automata II

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

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

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

NFAs continued, Closure Properties of Regular Languages

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. Kleene s Theorem. Department of Computer Science

First Midterm Examination

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

CS 275 Automata and Formal Language Theory

Finite Automata Part Three

1 From NFA to regular expression

Lecture 08: Feb. 08, 2019

1.4 Nonregular Languages

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

Regular languages refresher

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

input tape head moves current state

Formal Language and Automata Theory (CS21004)

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

1.3 Regular Expressions

Some Theory of Computation Exercises Week 1

Automata and 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.

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

1 Nondeterministic Finite Automata

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

Nondeterminism and Epsilon Transitions

Lecture 09: Myhill-Nerode Theorem

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

Harvard University Computer Science 121 Midterm October 23, 2012

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

Today s Topics Automata and Languages

Automata and Languages

Let's start with an example:

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

Introduction to ω-autamata

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

Strong Bisimulation. Overview. References. Actions Labeled transition system Transition semantics Simulation Bisimulation

3 Regular expressions

Turing Machines Part One

Good-for-Games Automata versus 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.

CS 573 Automata Theory and Formal Languages

ɛ-closure, Kleene s Theorem,

GNFA GNFA GNFA GNFA GNFA

DFA Minimization and Applications

Transcription:

Nondeterminism Nondeterministic Finite Automt Nondeterminism Subset Construction A nondeterministic finite utomton hs the bility to be in severl sttes t once. Trnsitions from stte on n input symbol cn be to ny set of sttes. Modified from Jeff Ullmn s slides 2 Nondeterminism (2) Strt in one strt stte. Accept if ny sequence of choices leds to finl stte. Intuitively: the NFA lwys guesses right. Exmple: Moves on Chessbord Sttes = squres. Inputs = r (move to n djcent red squre) nd b (move to n djcent blck squre); digonl is djcent. Strt stte, finl stte re in opposite corners. 4 Exmple: Chessbord (2) 2 4 6 8 9 b 2 4 9 2,4 2 4,6,, 4 2,8,, 2,4,6,8,,,9 Forml NFA A finite set of sttes, typiclly Q. An input lphbet, typiclly Σ. A trnsition function, typiclly δ. A strt stte in Q, typiclly q. A set of finl sttes F Q. Accept, since finl stte reched 6

Trnsition Function of n NFA δ(q, ) is set of sttes. Extend to strings s follows: Bsis: δ(q, ) = {q} Induction: δ(q, w) = the union over ll sttes p in δ(q, w) of δ(p, ) Lnguge of n NFA A string w is ccepted by n NFA if δ(q, w) contins t lest one finl stte. The lnguge of the NFA is the set of strings it ccepts. Cn NFAs do more thn DFAs? 8 Exmple: Lnguge of n NFA 2 4 6 8 9 Equivlence of DFA s, NFA s For our chessbord NFA we sw tht rbb is ccepted. If the input consists of only b s, the set of ccessible sttes lterntes between {} nd {,,,9}, so only even-length, nonempty strings of b s re ccepted. Wht bout strings with t lest one r? 9 A DFA D cn be turned into n NFA N tht ccepts the sme lnguge. If δ D (q, ) = p, then let the NFA hve δ N (q, ) = {p}. Then the NFA is lwys in set contining exctly one stte the stte the DFA is in fter reding the sme input. Equivlence (2) Subset Construction Surprisingly, for ny NFA there is DFA tht ccepts the sme lnguge. Proof is the subset construction. The number of sttes of the DFA cn be exponentil in the number of sttes of the NFA. Thus, NFA s ccept exctly the regulr lnguges. Given n NFA with sttes Q, inputs Σ, trnsition function δ N, stte stte q, nd finl sttes F, construct equivlent DFA with: Stte set 2 Q (Set of subsets of Q). Inputs Σ. Strt stte {q }. Finl sttes = ll those with member of F. 2 2

Criticl Point The DFA sttes hve nmes tht re sets of NFA sttes. But s DFA stte, n expression like {p,q} must be red s single symbol, not s set. Anlogy: clss of objects whose vlues re sets of objects of nother clss, e.g. the stte of hsh tble Subset Construction (2) The trnsition function δ D is defined by: δ D ({q,,q k }, ) is the union over ll i =,,k of δ N (q i, ). Exmple: We ll construct the DFA equivlent of our chessbord NFA. 4 Exmple: Subset Construction 2,4 2 4,6,, 4 2,8,, 2,4,6,8,,,9 {} {2,4} {} {2,4} {} Alert: Wht we re doing here is the lzy form of DFA construction, where we only construct stte Exmple: Subset Construction 2,4 2 4,6,, 4 2,8,, 2,4,6,8,,,9 {} {2,4} {} {2,4} {2,4,6,8} {,,,} {} {2,4,6,8} {,,,} if we re forced to. (how mny?) 6 Exmple: Subset Construction Exmple: Subset Construction 2,4 2 4,6,, 4 2,8,, 2,4,6,8,,,9 {} {2,4} {} {2,4} {2,4,6,8} {,,,} {} {2,4,6,8} {,,,9} {2,4,6,8} {,,,} {,,,9} 2,4 2 4,6,, 4 2,8,, 2,4,6,8,,,9 {} {2,4} {} {2,4} {2,4,6,8} {,,,} {} {2,4,6,8} {,,,9} {2,4,6,8} {2,4,6,8} {,,,,9} {,,,} {,,,9} {,,,,9} 8

Exmple: Subset Construction Exmple: Subset Construction 2,4 2 4,6,, 4 2,8,, 2,4,6,8,,,9 {} {2,4} {} {2,4} {2,4,6,8} {,,,} {} {2,4,6,8} {,,,9} {2,4,6,8} {2,4,6,8} {,,,,9} {,,,} {2,4,6,8} {,,,,9} {,,,9} {,,,,9} 2,4 2 4,6,, 4 2,8,, 2,4,6,8,,,9 {} {2,4} {} {2,4} {2,4,6,8} {,,,} {} {2,4,6,8} {,,,9} {2,4,6,8} {2,4,6,8} {,,,,9} {,,,} {2,4,6,8} {,,,,9} {,,,9} {2,4,6,8} {} {,,,,9} 9 2 Exmple: Subset Construction 2,4 2 4,6,, 4 2,8,, 2,4,6,8,,,9 {} {2,4} {} {2,4} {2,4,6,8} {,,,} {} {2,4,6,8} {,,,9} {2,4,6,8} {2,4,6,8} {,,,,9} {,,,} {2,4,6,8} {,,,,9} {,,,9} {2,4,6,8} {} {,,,,9} {2,4,6,8} {,,,,9} 2 Proof of Equivlence: Subset Construction Show by induction on w tht δ N (q, w) = δ D ({q }, w) IH(n): for ll w of length n, δ N (q, w) = δ D ({q }, w) Bsis: Show IH(). Only string of length is, nd δ N (q, ) = {q } δ D ({q }, ) = {q } 22 Induction Step () Assume n nd IH (n) to show IH(n+) Let w be n rbitrry string of length n+ Need to show δ N (q, w) = δ D ({q }, w) Let w = x, so x =n, (use IH(n) on x) Let S = δ N (q, x); By IH(N), S = δ D ({q }, x) δ N (q, w) = δ N (q, x) = the union over ll sttes p in S of δ N (p, ) Induction Step (2) Assume n nd IH (n) to show IH(n+) w = x; x =n; δ N (q, x)=s=δ D ({q }, x) δ N (q, w) = union over ll sttes p in S of δ N (p, ) δ D ({q }, w) = δ D ({q }, x) = δ D ( δ D ({q }, x), ) def. ext. δ D = δ D ( S, ) by def. S = the union over ll sttes p in S of δ N (p, ) by def. δ D by def. extension of δ N So δ 2 N (q, w) = δ D ({q }, w) 24 4

NFA s With -Trnsitions Exmple: -NFA We cn llow stte-to-stte trnsitions on input. These trnsitions re done spontneously, without looking t the input string. A convenience t times, but still only regulr lnguges re ccepted. A B E C F D A {E} {B} B {C} {D} C {D} D E {F} {B, C} F {D} 2 26 Closure of Sttes CL(q) = set of sttes you cn rech from stte q following only rcs lbeled. Exmple: CL(A) = {A}; CL(E) = {B, C, D, E}. A B C D Closure of set of sttes = union of the closure of ech stte. E F 2 Extended Delt Bsis: δ (q, ) = CL(q). Induction: δ(q, x) is computed s follows:. Strt with (q, x) = S. δ 2. Tke the union of CL(δ(p, )) for ll p in S. Intuition: δ (q, w) is the set of sttes you cn rech from q following pth lbeled w. And notice tht δ(q, ) is not 28 tht set of sttes, for symbol. Exmple: Extended Delt δ (A, ) = CL(A) = {A}. A B C D (A, ) = CL({E}) = {B, C, D, E}. δ δ(a, ) = CL({C, D}) = {C, D}. Lnguge of n -NFA is the set of strings w such tht δ(q, w) contins finl stte. E F 29 Equivlence of NFA, -NFA Every NFA is n -NFA. It just hs no trnsitions on. Converse requires us to tke n -NFA nd construct n NFA tht ccepts the sme lnguge. We do so by combining trnsitions with the next trnsition on rel input. Wrning: This tretment is bit different from tht in the text.

Picture of -Trnsition Removl Picture of -Trnsition Removl Text goes from here To here, nd performs the subset construction Trnsitions on Trnsitions on Trnsitions on Trnsitions on 2 Picture of -Trnsition Removl We ll go from here Trnsitions on To here, with no subset construction Trnsitions on Equivlence (2) Strt with n -NFA with sttes Q, inputs Σ, strt stte q, finl sttes F, nd trnsition function δ E. Construct n ordinry NFA with sttes Q, inputs Σ, strt stte q, finl sttes F, nd trnsition function δ N. 4 Equivlence () Equivlence (4) Compute δ N (q, ) s follows:. Let S = CL(q). 2. δ N (q, ) is the union over ll p in S of δ E (p, ). F = the set of sttes q such tht CL(q) contins stte of F. Intuition: δ N incorportes trnsitions before using but not fter. Prove by induction on w tht CL(δ N (q, w)) = δ E (q, w). Thus, the -NFA ccepts w if nd only if the ordinry NFA does. 6 6

Interesting closures: CL(B) = {B,D}; CL(E) = {B,C,D,E} A {E} {B} B {C} {D} C {D} D E {F} {B, C} F {D} -NFA Exmple: -NFAto-NFA Since closures of B nd E include finl stte D. A {E} {B} B {C} C {D} D E {F} {C, D} F {D} Since closure of E includes B nd C; which hve trnsitions on to C nd D. Summry DFA s, NFA s, nd NFA s ll ccept exctly the sme set of lnguges: the regulr lnguges. The NFA types re esier to design nd my hve exponentilly fewer sttes thn DFA. But only DFA cn be implemented! 8