NFAs continued, Closure Properties of Regular Languages

Similar documents
NFAs continued, Closure Properties of Regular Languages

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

Theory of Computation Regular Languages

Finite-State Automata: Recap

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Non-deterministic Finite Automata

Non-deterministic Finite Automata

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

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

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

Homework 3 Solutions

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

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

Convert the NFA into DFA

Deterministic Finite Automata

Fundamentals of Computer Science

Lecture 08: Feb. 08, 2019

CMSC 330: Organization of Programming Languages

CHAPTER 1 Regular Languages. Contents

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

Finite Automata-cont d

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

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

Formal Languages and Automata

Lecture 09: Myhill-Nerode Theorem

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.

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

CISC 4090 Theory of Computation

Harvard University Computer Science 121 Midterm October 23, 2012

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

Nondeterminism and Nodeterministic Automata

3 Regular expressions

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

1 Nondeterministic Finite Automata

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

1 From NFA to regular expression

Lexical Analysis Finite Automate

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

Minimal DFA. minimal DFA for L starting from any other

Chapter 2 Finite Automata

Some Theory of Computation Exercises Week 1

Designing finite automata II

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

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

State Minimization for DFAs

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.

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

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

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

NON-DETERMINISTIC FSA

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

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

Java II Finite Automata I

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Coalgebra, Lecture 15: Equations for Deterministic Automata

Languages & Automata

Thoery of Automata CS402

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

Let's start with an example:

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

FABER Formal Languages, Automata and Models of Computation

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

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

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

Closure Properties of Regular Languages

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

Formal Language and Automata Theory (CS21004)

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

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

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

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

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

Lecture 9: LTL and Büchi Automata

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

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 Languages and Applications

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

GNFA GNFA GNFA GNFA GNFA

Lexical Analysis Part III

Tutorial Automata and formal Languages

Formal languages, automata, and theory of computation

1.4 Nonregular Languages

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

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

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

Worked out examples Finite Automata

First Midterm Examination

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

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

Deterministic Finite-State Automata

Closure Properties of Regular Languages

CS375: Logic and Theory of Computing

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

CS 330 Formal Methods and Models

Formal Methods in Software Engineering

This lecture covers Chapter 8 of HMU: Properties of CFLs

Nondeterministic Finite Automata

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

Transcription:

lgorithms & Models of omputtion S/EE 374, Spring 209 NFs continued, losure Properties of Regulr Lnguges Lecture 5 Tuesdy, Jnury 29, 209 Regulr Lnguges, DFs, NFs Lnguges ccepted y DFs, NFs, nd regulr expressions re the sme. DFs re specil cses of NFs (trivil) NFs ccept regulr expressions (we sw lredy) DFs ccept lnguges ccepted y NFs (tody) Regulr expressions for lnguges ccepted y DFs (lter in the course) L TEXed: Decemer 26, 208 07:00 hn, Hr-Peled, Hssnieh (UIU) S374 Spring 209 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 2 Spring 209 2 / 3 Equivlence of NFs nd DFs Prt I For every NF N there is DF M such tht L(M) = L(N). Equivlence of NFs nd DFs hn, Hr-Peled, Hssnieh (UIU) S374 3 Spring 209 3 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 4 Spring 209 4 / 3

Forml Tuple Nottion for NF non-deterministic fe utomt (NF) N = (Q, Σ, δ, s, ) is five tuple where Q is fe set whose elements re clled sttes, Σ is fe set clled the input lphet, δ : Q Σ {ɛ} P(Q) is the trnsition function (here P(Q) is the power set of Q), s Q is the strt stte, Q is the set of ccepting/finl sttes. δ(q, ) for Σ {ɛ} is suset of Q set of sttes. Extending the trnsition function to strings For NF N = (Q, Σ, δ, s, ) nd q Q the ɛrech(q) is the set of ll sttes tht q cn rech using only ɛ-trnsitions. Inductive defion of δ : Q Σ P(Q): if w = ɛ, δ (q, w) = ɛrech(q) if w = where Σ δ (q, ) = p ɛrech(q) ( r δ(p,) ɛrech(r)) if w = x, δ (q, w) = p δ (q,x)( r δ(p,) ɛrech(r)) hn, Hr-Peled, Hssnieh (UIU) S374 5 Spring 209 5 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 6 Spring 209 6 / 3 Forml defion of lnguge ccepted y N string w is ccepted y NF N if δ N (s, w). The lnguge L(N) ccepted y NF N = (Q, Σ, δ, s, ) is {w Σ δ (s, w) }. Simulting n NF y DF Think of progrm with fixed memory tht needs to simulte NF N on input w. Wht does it need to store fter seeing prefix x of w? It needs to know t lest δ (s, x), the set of sttes tht N could e in fter reding x Is it sufficient? Yes, if it cn compute δ (s, x) fter seeing nother symol in the input. When should the progrm ccept string w? If δ (s, w). Key Oservtion: DF M tht simultes N should keep in its memory/stte the set of sttes of N Thus the stte spce of the DF should e P(Q). hn, Hr-Peled, Hssnieh (UIU) S374 7 Spring 209 7 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 8 Spring 209 8 / 3

Simulting NF Exmple the first revisited Previous lecture.. Rn NF (N) on input. t = 0: D E t = 2: t = 3: t = 4: t = 5: D E D E D E t = : hn, Hr-Peled, Hssnieh (UIU) S374 9 Spring 209 9 / 3 Suset onstruction NF N = (Q, Σ, s, δ, ). We crete DF M = (Q, Σ, δ, s, ) s follows: Q = P(Q) s = ɛrech(s) = δ (s, ɛ) = {X Q X } δ (X, ) = q X δ (q, ) for ech X Q, Σ. hn, Hr-Peled, Hssnieh (UIU) S374 Spring 209 / 3 Exmple: DF from NF NF: (N) DF: ctive thred in prticulr stte. Thus, to simulte the NF, the DF only needs to mintin the current set of sttes of the NF. The forml construction sed on the ove ide is s follows. onsider n NF N =(Q,,,s,). Define the DF det(n) =(Q 0,, 0,s 0, 0 ) s follows. D E Q 0 = P(Q) s 0 = N (s, ) 0 = {X Q X \ 6= ;} 0 ({q,q 2,...q k },)= N (q,) [ N (q 2,) [ [ N (q k,) or more concisely, 0 (X, ) = [ N (q, ) q2x hn, Hr-Peled, Hssnieh (UIU) S374 0 Spring 209 0 / 3 n exmple NF is shown in Figure 4 long with the DF det(n) in Figure 5. Exmple No ɛ-trnsitions q 0 q Figure 4: NF N We will now prove tht the DF defined ove is correct. Tht is Lemm 4. L(N) =L(det(N)) Proof. Need to show 8w 2. det(n) ccepts w i N ccepts w 8w 2. det(n) (s 0,w) 2 0 i N (s, w) \ 6= ; 8w 2. det(n) (s 0,w) \ 6= ; i N (s, w) \ 6= ; {q } {} 0 {q 0 } {q 0,q } Figure 5: DF det(n) equivlent to N gin for the induction proof to go through we need to strengthen the clim s follows. 8w 2. det(n) (s0,w)= N (s, w) In other words, this sys tht the stte of the DF fter reding some string is exctly the set of sttes the NF could e in fter reding the sme string. The proof of the strengthened sttement is y induction on w. se se If w =0thenw =. Now hn, Hr-Peled, Hssnieh (UIU) S374 2 Spring 209 2 / 3 det(n) (s0, ) =s 0 = N (s, ) y the defn. of det(n) nd defn. of s 0

Exmple s 0 = N (s, ) 0 = {X Q X \ 6= ;} 0 ({q,q2,...qk},)= N (q,) [ N (q2,) [ [ N (qk,) or more concisely, 0 (X, ) = [ N (q, ) No ɛ-trnsitions n exmple NF is shown in Figure 4 long with the DF det(n) in Figure 5. q2x Incrementl construction Only uild sttes rechle from s = ɛrech(s) the strt stte of M {q} {} ε q 0 q 0 ε q 3 {q 0, q } 0 {q 2,q 3} {} q0 q 0 {q0} {q0,q} q 2 δ (X, ) = q X δ (q, ) {q 3} Figure 4: NF N Figure 5: DF det(n) equivlent to N We will now prove tht the DF defined ove is correct. Tht is Lemm 4. L(N) =L(det(N)) Proof. Need to show 8w 2. det(n) ccepts w i N ccepts w 8w 2. det(n) (s 0,w) 2 0 i N (s, w) \ 6= ; 8w 2. det(n) (s 0,w) \ 6= ; i N (s, w) \ 6= ; gin for the induction proof to go through we need to strengthen the clim s follows. 8w 2. det(n) (s0,w)= N (s, w) In other words, this sys tht the stte of the DF fter reding some string is exctly the set of sttes the hn, Hr-Peled, NF could Hssnieh e in fter (UIU) reding the sme string. S374 3 The proof of the strengthened sttement is y induction on w. se se If w =0thenw =. Now Spring 209 3 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 4 Spring 209 4 / 3 det(n) (s0, ) =s 0 = N (s, ) y the defn. of det(n) nd defn. of s 0 Incrementl lgorithm 7 Proof of orrectness uild M eginning with strt stte s == ɛrech(s) For ech existing stte X Q consider ech Σ nd clculte the stte Y = δ (X, ) = q X δ (q, ) nd dd trnsition. If Y is new stte dd it to rechle sttes tht need to explored. To compute δ (q, ) - set of ll sttes reched from q on string ompute X = ɛrech(q) ompute Y = p X δ(p, ) ompute Z = ɛrech(y ) = r Y ɛrech(r) Let N = (Q, Σ, s, δ, ) e NF nd let M = (Q, Σ, δ, s, ) e DF constructed from N vi the suset construction. Then L(N) = L(M). Stronger clim: Lemm For every string w, δ N (s, w) = δ M (s, w). Proof y induction on w. se cse: w = ɛ. δ N (s, ɛ) = ɛrech(s). δ M (s, ɛ) = s = ɛrech(s) y defion of s. hn, Hr-Peled, Hssnieh (UIU) S374 5 Spring 209 5 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 6 Spring 209 6 / 3

Proof continued Lemm For every string w, δ N (s, w) = δ M (s, w). Inductive step: w = x (Note: suffix defion of strings) δ N (s, x) = p δn (s,x) δ N (p, ) y inductive defion of δ N δ M (s, x) = δ M (δ M (s, x), ) y inductive defion of δ M y inductive hypothesis: Y = δ N (s, x) = δ M (s, x) Prt II losure Properties of Regulr Lnguges Thus δ N (s, x) = p Y δ N (p, ) = δ M(Y, ) y defion of δ M. Therefore, δ N (s, x) = δ M(Y, ) = δ M (δ M (s, x), ) = δ M (s, x) which is wht we need. hn, Hr-Peled, Hssnieh (UIU) S374 7 Spring 209 7 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 8 Spring 209 8 / 3 Regulr Lnguges Regulr lnguges hve three different chrcteriztions Inductive defion vi se cses nd closure under union, conctention nd Kleene str Lnguges ccepted y DFs Lnguges ccepted y NFs Regulr lnguge closed under mny opertions: union, conctention, Kleene str vi inductive defion or NFs complement, union, intersection vi DFs homomorphism, inverse homomorphism, reverse,... Different representtions llow for flexiility in proofs Exmple: PREFIX Let L e lnguge over Σ. PREFIX(L) = {w wx L, x Σ } If L is regulr then PREFIX(L) is regulr. Let M = (Q, Σ, δ, s, ) e DF tht recognizes L X = {q Q s cn rech q in M} Y = {q Q q cn rech some stte in } Z = X Y rete new DF M = (Q, Σ, δ, s, Z) lim: L(M ) = PREFIX(L). hn, Hr-Peled, Hssnieh (UIU) S374 9 Spring 209 9 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 20 Spring 209 20 / 3

Exercise: SUFFIX Let L e lnguge over Σ. SUFFIX(L) = {w xw L, x Σ } Prove the following: If L is regulr then PREFIX(L) is regulr. Prt III Regex to NF hn, Hr-Peled, Hssnieh (UIU) S374 2 Spring 209 2 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 22 Spring 209 22 / 3 Stge 0: Input Stge : Normlizing,, 2: Normlizing it. + hn, Hr-Peled, Hssnieh (UIU) S374 23 Spring 209 23 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 24 Spring 209 24 / 3

Stge 2: Remove stte + + Stge 4: Redrwn without old edges + hn, Hr-Peled, Hssnieh (UIU) S374 25 Spring 209 25 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 26 Spring 209 26 / 3 Stge 4: Removing Stge 5: Redrw + + + + hn, Hr-Peled, Hssnieh (UIU) S374 27 Spring 209 27 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 28 Spring 209 28 / 3

Stge 6: Removing Stge 7: Redrw + ( + )( + ) + ( + )( + ) + + hn, Hr-Peled, Hssnieh (UIU) S374 29 Spring 209 29 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 30 Spring 209 30 / 3 Stge 8: Extrct regulr expression ( + )( + ) Thus, this utomt is equivlent to the regulr expression ( + )( + ). hn, Hr-Peled, Hssnieh (UIU) S374 3 Spring 209 3 / 3