Fundamentals of Computer Science

Similar documents
Lecture 08: Feb. 08, 2019

CHAPTER 1 Regular Languages. Contents

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

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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

Theory of Computation Regular Languages

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

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

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

Harvard University Computer Science 121 Midterm October 23, 2012

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

Non-deterministic Finite Automata

Designing finite automata II

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

Chapter 2 Finite Automata

Non-deterministic Finite Automata

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

Finite-State Automata: Recap

Let's start with an example:

NFAs continued, Closure Properties of Regular Languages

Deterministic Finite Automata

Finite Automata-cont d

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

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

Minimal DFA. minimal DFA for L starting from any other

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

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

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

3 Regular expressions

1 From NFA to regular expression

Formal Languages and Automata

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

CISC 4090 Theory of Computation

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

Today s Topics Automata and Languages

Automata and Languages

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

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

Formal Language and Automata Theory (CS21004)

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.

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

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

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

CMSC 330: Organization of Programming Languages

Worked out examples Finite Automata

Introduction to ω-autamata

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

Myhill-Nerode Theorem

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

NFAs continued, Closure Properties of Regular Languages

ɛ-closure, Kleene s Theorem,

Closure Properties of Regular Languages

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

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.

Homework 3 Solutions

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

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Lecture 09: Myhill-Nerode Theorem

CS375: Logic and Theory of Computing

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

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

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

Languages & Automata

State Minimization for DFAs

Regular languages refresher

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

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

Name Ima Sample ASU ID

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

GNFA GNFA GNFA GNFA GNFA

CS375: Logic and Theory of Computing

Formal languages, automata, and theory of computation

1.3 Regular Expressions

Some Theory of Computation Exercises Week 1

Java II Finite Automata I

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

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

1 Nondeterministic Finite Automata

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

Non-Deterministic Finite Automata

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

input tape head moves current state

Thoery of Automata CS402

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

Convert the NFA into DFA

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

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

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

DFA minimisation using the Myhill-Nerode theorem

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

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

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

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

Tutorial Automata and formal Languages

First Midterm Examination

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

1.4 Nonregular Languages

Transcription:

Fundmentls of Computer Science Chpter 3: NFA nd DFA equivlence Regulr expressions Henrik Björklund Umeå University Jnury 23, 2014

NFA nd DFA equivlence As we shll see, it turns out tht NFA nd DFA re equivlent, i.e., they hve the sme expressive power. This cn lso e sid s follows: For every NFA A there is DFA B such tht L(A) = L(B). In yet other words, the clss of NFAs nd the clss of DFAs define the sme fmily of lnguges.

NFA nd DFA equivlence As we shll see, it turns out tht NFA nd DFA re equivlent, i.e., they hve the sme expressive power. This cn lso e sid s follows: For every NFA A there is DFA B such tht L(A) = L(B). In yet other words, the clss of NFAs nd the clss of DFAs define the sme fmily of lnguges. This lso gives us n lterntive defintion of the regulr lnguges: A forml lnguge L is regulr if nd only if there is n NFA A such tht L = L(A).

DFA NFA This direction is trivil: Given DFA A = (Q, Σ, δ, q 0, F), define n NFA A = (Q, Σ, δ, q 0, F), where, for ll q Q nd Σ, we define δ (q, ) = {δ(q, )}. This mens tht if δ(q, ) = p, then δ (q, ) = {p}.

DFA NFA This direction is trivil: Given DFA A = (Q, Σ, δ, q 0, F), define n NFA A = (Q, Σ, δ, q 0, F), where, for ll q Q nd Σ, we define δ (q, ) = {δ(q, )}. This mens tht if δ(q, ) = p, then δ (q, ) = {p}. Slogn: Every DFA is n NFA.

NFA DFA It is less ovious tht for every NFA there is lnguge-equivlent DFA.

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 0

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 0

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 0

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0 p 02

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 013 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 013 p 03 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 013 p 03 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 013 p 03 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 013 p 03 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 013 p 03 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 013 p 03 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 013 p 03 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 013 p 03 p 023

NFA DFA: Exmple,,, q 0 q 1 q 2 q 3 p 01 p 012 p 0123 p 0 p 02 p 013 p 03 p 023

NFA DFA: Generl procedure Given: n NFA A = (Q, Σ, δ, q 0, F). 1. Crete n initil stte q 0. 2. Repet the follwoing until no trnsitions re missing: Tke ny stte {q i, q j,..., q k } tht does not hve trnsition for some Σ. Compute p = δ (q i, ) δ (q j, ) δ (q k, ). If there is no stte with lel p yet, crete such stte. Add trnsition from the stte with lel {qi, q j,..., q k } to the stte with lel p for the symol. 3. Mrk every stte whose lel contins ny q F s ccepting. 4. If the NFA ccepts ε, mrk the stte {q 0 } s ccepting.

Regulr expressions Perhps the most widely known wy of defining regulr lnguges re through the regulr expressions.

Regulr expressions Perhps the most widely known wy of defining regulr lnguges re through the regulr expressions. While finite utomt emphsizes the computtionl spects of regulr lnguges, regulr expressions re more purely descriptive.

Regulr expressions Perhps the most widely known wy of defining regulr lnguges re through the regulr expressions. While finite utomt emphsizes the computtionl spects of regulr lnguges, regulr expressions re more purely descriptive. Regulr expressions descrie lnguges y repeted use of union, conctention, nd Kleene closure.

RE definition Let Σ e n lphet. 1. ε nd re regulr expressions over Σ.

RE definition Let Σ e n lphet. 1. ε nd re regulr expressions over Σ. 2. If Σ, then is regulr expression over Σ.

RE definition Let Σ e n lphet. 1. ε nd re regulr expressions over Σ. 2. If Σ, then is regulr expression over Σ. 3. If r 1 nd r 2 re regulr expressions over Σ, then so re r1 + r 2,

RE definition Let Σ e n lphet. 1. ε nd re regulr expressions over Σ. 2. If Σ, then is regulr expression over Σ. 3. If r 1 nd r 2 re regulr expressions over Σ, then so re r1 + r 2, r1 r 2,

RE definition Let Σ e n lphet. 1. ε nd re regulr expressions over Σ. 2. If Σ, then is regulr expression over Σ. 3. If r 1 nd r 2 re regulr expressions over Σ, then so re r1 + r 2, r1 r 2, (r1 ), nd

RE definition Let Σ e n lphet. 1. ε nd re regulr expressions over Σ. 2. If Σ, then is regulr expression over Σ. 3. If r 1 nd r 2 re regulr expressions over Σ, then so re r1 + r 2, r1 r 2, (r1 ), nd r1.

RE definition Let Σ e n lphet. 1. ε nd re regulr expressions over Σ. 2. If Σ, then is regulr expression over Σ. 3. If r 1 nd r 2 re regulr expressions over Σ, then so re r1 + r 2, r1 r 2, (r1 ), nd r1. Exmple: ( + c) ( + ε) is regulr expression over {,, c}.

RE lnguges If r is regulr expression, we write L(r) for the lnguge ssocited with r. We define L(r) y the following rules: If r =, then L(r) =

RE lnguges If r is regulr expression, we write L(r) for the lnguge ssocited with r. We define L(r) y the following rules: If r =, then L(r) = If r = ε, then L(r) = {ε}

RE lnguges If r is regulr expression, we write L(r) for the lnguge ssocited with r. We define L(r) y the following rules: If r =, then L(r) = If r = ε, then L(r) = {ε} If r =, then L(r) = {}

RE lnguges If r is regulr expression, we write L(r) for the lnguge ssocited with r. We define L(r) y the following rules: If r =, then L(r) = If r = ε, then L(r) = {ε} If r =, then L(r) = {} If r = r 1 + r 2, then L(r) = L(r 1 ) L(r 2 )

RE lnguges If r is regulr expression, we write L(r) for the lnguge ssocited with r. We define L(r) y the following rules: If r =, then L(r) = If r = ε, then L(r) = {ε} If r =, then L(r) = {} If r = r 1 + r 2, then L(r) = L(r 1 ) L(r 2 ) If r = r 1 r 2, then L(r) = L(r 1 ) L(r 2 )

RE lnguges If r is regulr expression, we write L(r) for the lnguge ssocited with r. We define L(r) y the following rules: If r =, then L(r) = If r = ε, then L(r) = {ε} If r =, then L(r) = {} If r = r 1 + r 2, then L(r) = L(r 1 ) L(r 2 ) If r = r 1 r 2, then L(r) = L(r 1 ) L(r 2 ) If r = (r 1 ), then L(r) = L(r 1 )

RE lnguges If r is regulr expression, we write L(r) for the lnguge ssocited with r. We define L(r) y the following rules: If r =, then L(r) = If r = ε, then L(r) = {ε} If r =, then L(r) = {} If r = r 1 + r 2, then L(r) = L(r 1 ) L(r 2 ) If r = r 1 r 2, then L(r) = L(r 1 ) L(r 2 ) If r = (r 1 ), then L(r) = L(r 1 ) If r = (r 1 ), then L(r) = L(r 1 )

Exmple Rememer the regulr expression ( + c) ( + ε). Wht lnguge does it define? L(( + c) ( + ε)) = L(( + c) ) L(( + ε))

Exmple Rememer the regulr expression ( + c) ( + ε). Wht lnguge does it define? L(( + c) ( + ε)) = L(( + c) ) L(( + ε)) = L(( + c)) L( + ε)

Exmple Rememer the regulr expression ( + c) ( + ε). Wht lnguge does it define? L(( + c) ( + ε)) = L(( + c) ) L(( + ε)) = L(( + c)) L( + ε) = L( + c) (L( ) L(ε))

Exmple Rememer the regulr expression ( + c) ( + ε). Wht lnguge does it define? L(( + c) ( + ε)) = L(( + c) ) L(( + ε)) = L(( + c)) L( + ε) = L( + c) (L( ) L(ε)) = ({} {c}) (L() L( ) {ε})

Exmple Rememer the regulr expression ( + c) ( + ε). Wht lnguge does it define? L(( + c) ( + ε)) = L(( + c) ) L(( + ε)) = L(( + c)) L( + ε) = L( + c) (L( ) L(ε)) = ({} {c}) (L() L( ) {ε}) = {, c} (L() L() {ε})

Exmple Rememer the regulr expression ( + c) ( + ε). Wht lnguge does it define? L(( + c) ( + ε)) = L(( + c) ) L(( + ε)) = L(( + c)) L( + ε) = L( + c) (L( ) L(ε)) = ({} {c}) (L() L( ) {ε}) = {, c} (L() L() {ε}) = {, c} ({} {ε,,,... } {ε})

Exmple Rememer the regulr expression ( + c) ( + ε). Wht lnguge does it define? L(( + c) ( + ε)) = L(( + c) ) L(( + ε)) = L(( + c)) L( + ε) = L( + c) (L( ) L(ε)) = ({} {c}) (L() L( ) {ε}) = {, c} (L() L() {ε}) = {, c} ({} {ε,,,... } {ε}) = {, c} {ε,,,... }

Exmple Rememer the regulr expression ( + c) ( + ε). Wht lnguge does it define? L(( + c) ( + ε)) = L(( + c) ) L(( + ε)) = L(( + c)) L( + ε) = L( + c) (L( ) L(ε)) = ({} {c}) (L() L( ) {ε}) = {, c} (L() L() {ε}) = {, c} ({} {ε,,,... } {ε}) = {, c} {ε,,,... } = {ε,, c,, c, c,... } {ε,,,... }

Precedence Kleene str inds hrder thn conctention nd union Conctention inds hrder thn union

Exmple Construct regulr expression over Σ = {,, c} tht defines the lnguge of ll words over Σ tht do not hve two consecutive :s.

Exmple Construct regulr expression over Σ = {,, c} tht defines the lnguge of ll words over Σ tht do not hve two consecutive :s. ( + ε)( )

REs nd regulr lnguges Regulr expressions re expressively equivlent to DFA nd NFA. In other words, every lnguge tht cn e defined y finite utomton cn e defined y regulr expression nd vice vers. This mens tht the regulr expressions, just like the DFA nd the NFA, define exctly the regulr lnguges. We will prove one direction of this clim y showing tht for every regulr expression r, there is n NFA A such tht L(r) = L(A).

q 0 An NFA for L( )

q 0 An NFA for L(ε)

q 0 q 1 An NFA for L()

An NFA for L(r 1 + r 2 ) A(r 1 ) ε ε q 0 q 1 ε A(r 2 ) ε

An NFA for L(r 1 r 2 ) A(r 1 ) A(r 2 ) ε ε ε q 0 q 1

An NFA for L(r 1 ) A(r 1 ) ε ε q 0 q 1