Non-deterministic Finite Automata

Similar documents
Non-deterministic Finite Automata

Deterministic Finite Automata

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

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

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Theory of Computation Regular Languages

Lecture 08: Feb. 08, 2019

NFAs continued, Closure Properties of Regular Languages

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

Finite Automata-cont d

Minimal DFA. minimal DFA for L starting from any other

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.

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

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

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

Finite-State Automata: Recap

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

Fundamentals of Computer Science

CHAPTER 1 Regular Languages. Contents

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

Formal Languages and Automata

Java II Finite Automata I

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

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

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

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

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

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

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

CMSC 330: Organization of Programming Languages

Chapter 2 Finite Automata

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

NFAs continued, Closure Properties of Regular Languages

Worked out examples Finite Automata

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

Nondeterminism and Nodeterministic Automata

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

Languages & Automata

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.

Some Theory of Computation Exercises Week 1

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

Non-Deterministic Finite Automata

State Minimization for DFAs

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

CS375: Logic and Theory of Computing

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

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

Regular languages refresher

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

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

Convert the NFA into DFA

CS 275 Automata and Formal Language Theory

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

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.

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

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

3 Regular expressions

Lecture 6 Regular Grammars

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

CISC 4090 Theory of Computation

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

ɛ-closure, Kleene s Theorem,

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

Designing finite automata II

Formal Language and Automata Theory (CS21004)

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

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Harvard University Computer Science 121 Midterm October 23, 2012

Let's start with an example:

CS375: Logic and Theory of Computing

Lexical Analysis Finite Automate

Homework 3 Solutions

1 Nondeterministic Finite Automata

1.3 Regular Expressions

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

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

FABER Formal Languages, Automata and Models of Computation

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

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

1.4 Nonregular Languages

Today s Topics Automata and Languages

Automata and Languages

Closure Properties of Regular Languages

First Midterm Examination

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 311 Homework 3 due 16:30, Thursday, 14 th October 2010

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

a b b a pop push read unread

Deterministic Finite-State Automata

Myhill-Nerode Theorem

Thoery of Automata CS402

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

Formal languages, automata, and theory of computation

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

1 From NFA to regular expression

CS 573 Automata Theory and Formal Languages

Transcription:

Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd T. vn Lrhoven Institute for Computing nd Informtion Sciences Intelligent Systems Rdoud University Nijmegen Version: fll 2014 H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 1 / 18

Outline Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt Eliminting non-determinism H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 2 / 18

Previous Weeks Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Regulr Expressions nd Regulr Lnguges rexp Σ ::= s rexp Σ rexp Σ rexp Σ +rexp Σ rexp Σ with s Σ L Σ is regulr if L = L(e) for some regulr expression e. Deterministic Finite Automt, DFA Proposition Closure under complement, union, intersection If L 1, L 2 re ccepted y some DFA, then so re L 1 = Σ L 1 L 1 L 2 L 1 L 2. H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 3 / 18

Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Kleene s Theorem (nnounced lst lecture) Theorem The lnguges ccepted y DFAs re exctly the regulr lnguges We prove this y 1 If L = L(M) for some DFA M, then there is regulr expression e such tht L = L(e) (Previous lecture) 2 If L = L(e), for some regulr expression e, then there is non-deterministic finite utomton with -steps (NFA ) M such tht L = L(M). (This lecture) 3 For every NFA, M, there is DFA M such tht L(M) = L(M ) (This lecture) H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 4 / 18

Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic finite utomton (NFA), q strt 0 q 1 q 2 δ(q, ) is not one stte, ut set of sttes. δ q 0 {q 0 } {q 0, q 1 } q 1 {q 2 } q 2 in shorthnd δ q 0 q 0 q 0, q 1 q 1 q 2 q 2 H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 6 / 18

Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt: NFA (formlly) M is NFA over Σ if M = (Q, q 0, δ, F ) with Q is finite set of sttes q 0 Q is the initil stte F Q is finite set of finl sttes δ : Q Σ PQ is the trnsition function [PQ denotes the collection of susets of Q] Reding function δ : Q Σ PQ (multi-step trnsition) δ (q, ) = {q} δ (q, w) = {q q δ (p, w) for some p δ(q, )} = δ (p, w) p δ(q,) [ X i denotes the union of ll the X i ] The lnguge ccepted y M, nottion L(M), is: L(M) = {w Σ q f F (q f δ (q 0, w))} H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 7 / 18

Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen For the union of lnguges we cn put NFAs in prllel Exmple. Suppose we wnt to hve n NFA for L 1 L 2 = {w w is even or w 1} First ide: put the two mchines non-deterministiclly in prllel strt ev od, strt 0 1 strt, ev0 od 1 But this is wrong: The NFA ccepts. H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 8 / 18

Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt with silent steps: NFA We dd -trnsitions or silent steps to NFAs The correct union of M 1 nd M 2 is: ev od strt U, 0 1 In n NFA we llow δ(q, ) = q for q q. Tht mens δ : Q (Σ {}) PQ H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 9 / 18

NFA formlly Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen M is n NFA over Σ if M = (Q, q 0, δ, F ) with Q is finite set of sttes q 0 Q is the initil stte F Q is finite set of finl sttes δ : Q (Σ {}) PQ is the trnsition function The -closure of stte q, -closure(q), is the set of sttes rechle with only -steps. Reding function δ : Q Σ PQ (multi-step trnsition) δ (q, ) = -closure(q) δ (q, w) = {q p -closure(q) r δ(p, ) (q δ (r, w))} = δ (r, w) p -closure(q) r δ(p,) The lnguge ccepted y M, nottion L(M), is: L(M) = {w Σ q f F (q f δ (q 0, w))} H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 10 / 18

Non-deterministic Finite Automt Eliminting non-determinism Insulted mchines Rdoud University Nijmegen A finite utomton M is clled insulted if q 0 hs no in-going rrows there is only one finl stte which hs no out-going rrows Proposition. For ny mchine M one cn find n insulted NFA M such tht M ccepts the sme lnguge Proof. By dding sttes nd silent steps, for exmple strt 0 1 gives q strt 0 0 1 q f H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 11 / 18

Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Toolkit for uilding n NFA from regulr expression For ech regulr expression, we construct n insulted NFA. e M such tht L(M) = L(e) strt q 0 strt q 0 (for Σ) strt S F M 1 e = e 1 + e 2 with L(M 1 ) = L(e 1 ) L(M 2 ) = L(e 2 ) strt S S1 M 2 F1 F S2 F2 H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 12 / 18

Non-deterministic Finite Automt Eliminting non-determinism Toolkit (continued) Rdoud University Nijmegen e M such tht L(M) = L(e) e = e 1 e 2 with L(M 1 ) = L(e 1 ) L(M 2 ) = L(e 2 ) M 1 M 2 strt S1 F1 S2 F2 e = (e 1 ) with L(M 1 ) = L(e 1 ) M1 strt S S1 F1 F H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 13 / 18

Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Regulr lnguges ccepted y NFA Proposition. For every regulr expression e there is n NFA M e such tht L(M e ) = L(e). Proof. Apply the toolkit. M e cn e found y induction on the structure of e: First do this for the simplest regulr expressions. For composed regulr expression compose the utomt. Corollry. For every regulr lnguge L there is n NFA M tht ccepts L (so L(M) = L). H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 14 / 18

Non-deterministic Finite Automt Eliminting non-determinism Avoiding non-determinism Rdoud University Nijmegen We cn trnsform ny NFA (nd NFA ) into DFA tht ccepts the sme lnguge. Ide: Keep trck of ll the sttes you cn go to! A comintion of sttes is finl if one of the memers is finl. Exmple:L = {w w is even or w 1} strt U ev od, strt U od,0 od,1 ev,0 0 1 ev,1 H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 16 / 18

Non-deterministic Finite Automt Eliminting non-determinism Eliminting non-determinism nd -steps Let M e NFA given y (Q, q 0, δ, F ) Define the DFA M + s (Q +, q + 0, δ+, F + ) where Q + = PQ Rdoud University Nijmegen q 0 = {q 0 } δ + (H, ) = δ(q, ), for H Q, q H F + = {H Q H F } Then M + is DFA ccepting the sme lnguge s M If M is n NFA, we tke δ + (H, ) = q H p -closure(q) -closure(δ(p, )) F + = {H Q -closure(h) F } H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 17 / 18

Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Equivlence of DFA, NFA nd NFA Conclusion. Every NFA (or NFA) M cn e turned into DFA M ccepting the sme lnguge. Corollry. For every regulr lnguge L there is DFA M tht ccepts L (so L(M) = L). Proof. Given regulr expression e, first construct n NFA M such tht L(M) = L(e). Then chnge it into DFA preserving the lnguge tht is ccepted. Rephrsing of Kleene s Theorem: The clss of regulr lnguges is (equivlently) chrcterized s 1 The lnguges descried y regulr expression 2 The lnguges ccepted y DFA 3 The lnguges ccepted y n NFA 4 The lnguges ccepted y NFA H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 18 / 18