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

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

Theory of Computation Regular Languages

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Finite Automata Part Three

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

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

1.3 Regular Expressions

Fundamentals of Computer Science

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

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

Lecture 08: Feb. 08, 2019

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

NFAs continued, Closure Properties of Regular Languages

Non-deterministic Finite Automata

Harvard University Computer Science 121 Midterm October 23, 2012

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

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

Finite Automata-cont d

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

1.4 Nonregular Languages

Deterministic Finite-State Automata

CHAPTER 1 Regular Languages. Contents

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

Finite-State Automata: Recap

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

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

Minimal DFA. minimal DFA for L starting from any other

CS375: Logic and Theory of Computing

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

Chapter 2 Finite Automata

Convert the NFA into DFA

CMSC 330: Organization of Programming Languages

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

NFAs continued, Closure Properties of Regular Languages

3 Regular expressions

CISC 4090 Theory of Computation

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

Homework 3 Solutions

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

Lecture 6 Regular Grammars

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

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

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

Java II Finite Automata I

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

Non-Deterministic Finite Automata

Nondeterminism and Nodeterministic Automata

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

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.

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

ɛ-closure, Kleene s Theorem,

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

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.

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

1 Nondeterministic Finite Automata

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

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

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

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

Let's start with an example:

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

Closure Properties of Regular Languages

Some Theory of Computation Exercises Week 1

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

Formal Language and Automata Theory (CS21004)

Deterministic Finite Automata

Lecture 09: Myhill-Nerode Theorem

Designing finite automata II

Formal languages, automata, and theory of computation

Lexical Analysis Finite Automate

State Minimization for DFAs

CS 275 Automata and Formal Language Theory

Closure Properties of Regular Languages

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

Thoery of Automata CS402

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

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

Coalgebra, Lecture 15: Equations for Deterministic Automata

Worked out examples Finite Automata

Formal Languages and Automata

Turing Machines Part One

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

FABER Formal Languages, Automata and Models of Computation

Introduction to ω-autamata

Context-Free Grammars and Languages

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

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

This lecture covers Chapter 8 of HMU: Properties of CFLs

Today s Topics Automata and Languages

Automata and Languages

Lecture 9: LTL and Büchi Automata

Name Ima Sample ASU ID

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

a b b a pop push read unread

GNFA GNFA GNFA GNFA GNFA

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Transcription:

CMPU 240 Lnguge Theory nd Computtion Spring 2019 NFAs nd Regulr Expressions Lst clss: Introduced nondeterministic finite utomt with -trnsitions Tody: Prove n NFA- is no more powerful thn n NFA Introduce regulr expressions Fun: Assignment 1 is due Lte dedline is next clss Assignment 2 out Exm 1 in pprox. two weeks Recll NFA-, continued A lnguge L is clled regulr lnguge if there exists DFA D such tht L(D) = L. A nondeterministic finite utomton (NFA) is like DFA but cn hve missing trnsitions or multiple trnsitions defined on the sme input symbol. An NFA ccepts if ny possible series of choices leds to n ccepting stte. An NFA- my follow ny number of -trnsitions t ny point without consuming ny input.

Forml definition of NFA- A nondeterministic finite utomton with - trnsitions is five-tuple (Q, Σ, q 0, δ, F) where Q is finite set of sttes Σ is finite lphbet of symbols q 0 Q is the strt stte F Q is the set of ccepting sttes δ is the trnsition function from Q x (Σ {}) to P(Q) DFAs nd NFA-s -trnsitions re convenience, but they don t increse the power of FAs For ny NFA-, there is n equivlent DFA, i.e., one tht ccepts the sme lnguge. The construction is similr to the NFA-to-DFA construction Creting DFA from n NFA- 1. Compute the -closure for ech stte, i.e., the set of sttes rechble from tht stte following only - trnsitions. 2. The strt stte of the DFA is now the -closure of q 0, E({q 0 }) 3. Define δ for ech Σ nd ech -closed set S: If stte p S cn rech stte q on input (not!), then dd trnsition on input from S to E(q) 4. The set of finl sttes for the DFA now includes those sets tht contin t lest one ccepting stte of the NFA-. -closure exmple q 0 Find the set T = E({s}) T = {s} initil step T = {s, w} dd δ(s, ) T = {s, w, q 0 } dd δ(w, ) b b p r s w b t u v T = {s, w, q 0, p, t} dd δ(q 0, ) δ(p, ) = δ(t, ) =, so we re done: E({s}) = T = {s, w, q 0, p, t}

Exmple 1. Compute -closure for ll sttes: E({q}) = {q} E({r}) = {r, s} E({s}) = {r, s} 2. Strt stte = E({q}) = {q} 3. Compute δ for input nd set of sttes from step 1. δ({q}, 0) = E({s}) = {r, s} δ({q}, 1) = E({r}) = {r, s} δ({r, s}, 0) = E({q}) = {q} δ({r, s}, 1) = E({q}) = {q} 4. Finl sttes F D = {{r, s}} 0 q 1 r s 0 1 RESULTING DFA {q} 0, 1 0, 1 {r,s} Problem Convert this NFA- to DFA q 0 q 1 q 2 q 3 q 4 q 6 q 7 q 5 q 1 q 2 q 3 q 4 q 0 q 5 q 6 q 7 Step 1 E({q 0 }) = {q 0, q 1, q 6 } E({q 1 }) = {q 1 } E({q 2 }) = {q 2, q 3 } E({q 3 }) = {q 3 } E({q 4 }) = {q 4, q 5 } E({q 5 }) = {q 5 } E({q 6 }) = {q 6 } E({q 7 }) = {q 7, q 5 } Step 2 Strt = E({q 0 }) = {q 0, q 1, q 6 } Step 3 δ({q 0, q 1, q 6 }, ) = E({q 2, q 7 }) = {q 2, q 3, q 7, q 5 } δ({q 2, q 3, q 7, q 5 }, ) = E({q 4 }) = {q 4, q 5 } δ({q 4, q 5 }, ) = Step 4 Finl = { {q 2, q 3, q 7, q 5 }, {q 4, q 5 } } {q 0, q 1, q 6} {q 2, q 3, q 7, q 5} {q 4, q 5}

DFAs, NFAs, nd NFAs with -trnsitions ll describe sme clss of lnguges. Thus to show lnguge is regulr lnguge, you cn just build NFA- tht recognizes it, rther thn DFA. Mny times it is more convenient to build NFA- rther thn DFA, especilly if you wnt to keep trck of multiple possibilities. Regulr expressions We ve seen we cn show lnguge is regulr by constructing DFA for it constructing n NFA for it (with or without trnsitions) We cn lso show lnguge is regulr by constructing it out of other regulr lnguges using closure properties. Regulr expressions re concise nottion for describing how to ssemble lrger lnguge out of smller pieces.

A bottom-up pproch to the regulr lnguges: Strt with smll set of simple lnguges we know to be regulr Use closure properties to combine these to form more elborte lnguges Photogrph by Benjmin D. Eshm Opertors nd opernds Regulr expressions re built by combining three kinds of simple opernds: For ny symbol Σ, the regulr expression represents the lnguge {} The symbol is regulr expression representing the lnguge {} The symbol is regulr expression for the empty lnguge Opertion: Union If R 1 nd R 2 re regulr expressions, (R 1 R 2 ) is regulr expression for the union of the lnguges of R 1 nd R 2 : L((R 1 R 2 )) = L(R 1 ) L(R 2 ). These re combined using symbols for the regulr opertions union, conctention, nd Kleene str.

Opertion: Conctention When we conctente strings w nd x, we write wx or w x nd the result is ll the symbols from w followed by ll the symbols from x, e.g., w = wonder x = womn wx = wonderwomn This is like the + opertor in some progrmming lnguges, e.g., in Python, > w = 'wonder' > x = 'womn' > w+x 'wonderwomn' Opertion: Conctention, continued The conctention of two lnguges L 1 nd L 2 is the lnguge L 1 L 2 = {wx w L 1 nd x L 2 } E.g., consider the lnguges Noun = {Puppy, Rinbow, Whle, } Verb = {Hugs, Juggles, Loves, } Det = {A, The} The lnguge DetNounVerbDetNoun is {APuppyHugsTheWhle, TheRinbowJugglesTheRinbow, TheWhleLovesAPuppy, } Opertion: Conctention, continued Two views of L 1 L 2 : The set of ll strings tht cn be mde by conctenting string in L 1 with string in L 2. Opertion: Conctention, continued If R 1 nd R 2 nd regulr expressions, (R 1 R 2 ) is regulr expression for the conctention of the lnguges of R 1 nd R 2. The set of strings tht cn be split into two pieces: piece from L 1 followed by piece from L 2. Conceptully it s similr to the Crtesin product of two sets, only with strings.

Opertion: Kleene str We cn conctente lnguge with itself. Consider L = {, b} LL is the lnguge of strings formed by conctenting pirs of strings in L: {, b, b, bb} LLL is the set of strings formed by conctenting triples of strings in L: Etc. {, b, b, bb, b, bb, bb, bbb} Opertion: Kleene str, continued We cn define wht it mens to exponentite lnguge s follows: L 0 = {} Bse cse: Any string formed by conctenting zero strings together is the empty string. L n+1 = LL n Recursive cse: Conctenting n+1 strings together works by conctenting n strings, then conctenting one more. Opertion: Kleene str, continued An importnt opertion on lnguges is the Kleene closure, defined s L * = L 0 L 1 L 2 L 3 Intuitively, it gives ll possible wys of conctenting ny number of copies of strings in L together. Opertion: Kleene str, continued If R is regulr expression, (R * ) is regulr expression for the Kleene closure of the lnguge of R.

Forml definition of regulr expressions DEFINITION. R is regulr expression if R is 1 for some Σ 2 3 4 (R 1 R 2), where R 1 nd R 2 re regulr expressions 5 (R 1 R 2), where R 1 nd R 2 re regulr expressions 6 (R 1 *), where R 1 is regulr expression Bsis Recursive cses Every regulr expression rises by finite number of pplictions of these six rules. Order of opertions We cn omit prentheses (nd the conctention opertor) to mke regulr expressions more compct, but this mkes them mbiguous without defining precedence. 0 Prentheses (R) 1 Kleene str R * 2 Conctention R 1 R 2 or R 1 R 2 3 Union R 1 R 2 Empty strings, empty sets Do not confuse the regulr expressions: the lnguge contining only the empty string the lnguge contining no strings Identities: R = R R = R R is regulr expression if R is 1 for some Σ 2 3 4 (R 1 R 2 ), where R 1 nd R 2 re regulr expressions 5 (R 1 R 2 ), where R 1 nd R 2 re regulr expressions 6 (R 1 *), where R 1 is regulr expression Exmple: To prove (((b * )) ) is regulr expression over Σ = {, b}, show it cn be constructed ccording to the rules: 1 b is regulr by Rule 1 2 (b * ) is regulr by Rule 6 3 is regulr by Rule 1 4 ((b * )) is regulr by Rule 5 5 (((b * )) ) is regulr by Rule 4 pplied to expressions (4) nd (3)

Exmples L(001) = {001} L(0 10 * ) = {0, 1, 10, 100, 1000, } L( ((0(0 1)) * ) = the set of strings of 0s nd 1s, of even length, such tht every odd position hs 0 A few more exmples b * * b * (b) * Is this the sme s * b *? * b * * Is b in this? L = {x odd } = x(xx) * or (xx) * x but not x * xx * All strings of s nd bs of exctly length 3 L = {, b, b, bb, b, bb, bb, bbb} or ( b) ( b) ( b) or ( b) 3 RE for strings with n in them somewhere? ( b) * ( b) * RE for strings with t lest two s? b * b * ( b) * RE for strings with exctly two s? b * b * b * RE for strings with t lest one nd one b? Convenient shorthnds R + = RR * tht is, one or more strings from lnguge R conctented together. R k = conctention of k Rs. ( b) * ( b) * b( b) * ( b) * b( b) * ( b) * RE for strings tht end in b but do not contin? (b b) * (b b) = (b b) + RE for ll strings over {, b, c} hving no substring c? c * ( bc * ) *

Equlity of REs Two regulr expressions s nd t re equl if nd only if L(s) = L(t) Two regulr expressions cn look quite different yet describe the sme lnguge Exmple: Acknowledgments This lecture incorportes mteril from: Nncy Ide Keith Schwrz Michel Sipser Jeffrey Ullmn s = ( b) * nd t = (b * b) * *