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

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

Lecture 08: Feb. 08, 2019

Fundamentals of Computer Science

Minimal DFA. minimal DFA for L starting from any other

Finite Automata-cont d

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

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

Worked out examples Finite Automata

Convert the NFA into DFA

Designing finite automata II

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

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

1 Nondeterministic Finite Automata

CS375: Logic and Theory of Computing

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.

Thoery of Automata CS402

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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

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

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

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

Some Theory of Computation Exercises Week 1

Formal Languages and Automata

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

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.

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

Deterministic Finite Automata

Non-deterministic Finite Automata

CHAPTER 1 Regular Languages. Contents

Theory of Computation Regular Languages

1 From NFA to regular expression

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

CMSC 330: Organization of Programming Languages

Finite-State Automata: Recap

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

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

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Let's start with an example:

Chapter 2 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

Homework 3 Solutions

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

Languages & Automata

Non-deterministic Finite 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

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

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

Java II Finite Automata I

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

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

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

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

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

NFAs continued, Closure Properties of Regular Languages

Formal languages, automata, and theory of computation

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

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

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

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

Lecture 09: Myhill-Nerode Theorem

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

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

Lexical Analysis Finite Automate

Formal Language and Automata Theory (CS21004)

Chapter 7. Kleene s Theorem. 7.1 Kleene s Theorem. The following theorem is the most important and fundamental result in the theory of FA s:

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

Lecture 9: LTL and Büchi Automata

Regular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15

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

CS375: Logic and Theory of Computing

input tape head moves current state

Today s Topics Automata and Languages

Automata and Languages

State Minimization for DFAs

First Midterm Examination

Name Ima Sample ASU ID

First Midterm Examination

Coalgebra, Lecture 15: Equations for Deterministic Automata

CISC 4090 Theory of Computation

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

Closure Properties of Regular Languages

Non-Deterministic Finite Automata

Harvard University Computer Science 121 Midterm October 23, 2012

Lexical Analysis Part III

Nondeterminism and Nodeterministic Automata

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

GNFA GNFA GNFA GNFA GNFA

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.

1.3 Regular Expressions

1.4 Nonregular Languages

NFAs continued, Closure Properties of Regular Languages

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

CS 275 Automata and Formal Language Theory

FABER Formal Languages, Automata and Models of Computation

Context-Free Grammars and Languages

Transcription:

CSCI 340: Computtionl Models Kleene s Theorem Chpter 7 Deprtment of Computer Science

Unifiction In 1954, Kleene presented (nd proved) theorem which (in our version) sttes tht if lnguge cn e defined y ny one of the three wys, then it cn e defined y the other two. All three of these methods of defining lnguges re equivlent. Theorem Any lnguge tht cn e defined y: regulr expression, or finite utomton, or trnsition grph cn e defined y ll three methods. 1 / 26

How do we prove this theorem? This theorem is the most importnt nd fundmentl result in the theory of finite utomt We need to crefully prove tht it is correct We will do so y introducing four lgorithms tht enle us to construct the corresponding mchines nd expressions The generl logic of this proof is s follows: 1 Show tht the set of ll FAs cn e defined y set of TGs 2 Show tht the set of ll TGs cn e defined y set of REs 3 Show tht the set of ll REs cn e defined y set of FAs Mthemticlly: [FA TG RE FA] [FA = TG = RE] 2 / 26

Forml Proof of Kleene s Theorem Proof. The three sections of our proof will e: 1 Every lnguge tht cn e defined y finite utomton cn lso e defined y trnsition grph 2 Every lnguge tht cn e defined y trnsition grph cn lso e defined y regulr expression 3 Every lnguge tht cn e defined y regulr expression cn lso e defined y finite utomton When we hve proven these three prts, we hve finished our theorem Proof of Prt 1: FA TG. Every finite utomton is itself lredy trnsition grph. Therefore, ny lnguge tht hs een defined y finite utomton hs lredy een defined y trnsition grph. 3 / 26

Proof of Prt 2: TG RE We will prove prt 2 y constructive lgorithm Present procedure tht tkes TG nd yields n RE which defines the sme lnguge It must work for every conceivle TG It must gurntee to finish its jo in finite time It does not hve to e good lgorithm it just hs to work How We Wish It Could Work Look t the mchine, figure out its lnguge, nd write down n equivlent regulr expression people re not s relily cretive s they re relile drones we don t wnt to wit for DVinci to e in the suitle mood ll cleverness should e incorported into the lgorithm 4 / 26

Proof of Prt 2: TG RE Algorithm 1 Crete unique, un-enterle finl stte nd unique, un-levele initil stte 2 One-y-one, in ny order, ypss nd eliminte ll the non-initil or finl sttes in the TG. A stte is ypssed y connecting ech incoming edge with ech outgoing edge. The lel of ech resultnt edge is the conctention of the lel on the incoming edge with the lel on the loop edge (if there is one) nd the lel on the outgoing edge 3 When two sttes re joined y more thn one edge going in the sme direction, unify them y dding their lels 4 Finlly, when ll tht remins is one edge from initil to finl, the lel on tht edge is regulr expression tht genertes the sme lnguge s wht ws recognized y the originl mchine 5 / 26

Exmple for Prt 2: TG RE q 2 q λ 0 q 1 q 4 q 3 λ Eliminting sttes in the order: q 1, q 2, q 3 6 / 26

Exmple for Prt 2: TG RE q 2 q 0 q 4 q 3 λ After eliminting q 1 6 / 26

Exmple for Prt 2: TG RE q 0 q 3 q 4 + λ + + After eliminting q 2 6 / 26

Exmple for Prt 2: TG RE + [ + ][ + ] [λ + ] q 0 q 4 After eliminting q 3 Yielding: + [ + ][ + ] [λ + ] 6 / 26

Exmple for Prt 2: TG RE q 2 q λ 0 q 1 q 4 q 3 λ Eliminting sttes in the order: q 3, q 2, q 1 7 / 26

Exmple for Prt 2: TG RE + q λ 0 q + 1 q + 2 q 4 After eliminting q 3 7 / 26

Exmple for Prt 2: TG RE q λ [ + ][ + ] [ + ] 0 q 1 q 4 After eliminting q 2 7 / 26

Exmple for Prt 2: TG RE + [ + ][ + ] [ + ] q 0 q 4 After eliminting q 1 Yielding: + [ + ][ + ] [ + ] 7 / 26

Proof of Prt 3: RE FA Proof. 1 There is n FA tht ccepts ny prticulr letter of the lphet. There is n FA tht ccepts only the word λ. 2 If there is n FA clled FA 1 tht ccepts the lnguge defined y the regulr expression r 1, nd there is n FA clled FA 2 tht ccepts the lnguge defined y the regulr expression r 2, then there is n FA (clled FA 3 ) tht ccepts the lnguge defined y (r 1 + r 2 ), the sum lnguge. 3 If there is n FA 1 tht ccepts the lnguge defined y regulr expression r 1 nd n FA 2 tht ccepts the lnguge defined y regulr expression r 2, then there is n FA 3 tht ccepts the lnguge defined y the conctention r 1 r 2, the product lnguge. 4 If r is regulr expression nd FA 1 ccepts lnguge (r), then there exists FA 2 where it ccepts the lnguge (r ) [Kleene Str]. 8 / 26

Proof of Prt 3 Rule 1 Rule 1 There is n FA tht ccepts ny prticulr letter of the lphet. There is n FA tht ccepts only the word λ. x e Σ q 0 q 1 e Σ e x q 2 e Σ q ll Σ 0 q 1 ll Σ 9 / 26

Proof of Prt 3 Rule 2 Rule 2 If FA 1 ccepts lnguge(r 1 ) nd FA 2 ccepts lnguge(r 2 ) then n FA 3 exists nd ccepts lnguge(r 1 + r 2 ) The generl description is s follows: FA 1 hs sttes x 1, x 2, x 3,... FA 2 hs sttes y 1, y 2, y 3,... We will construct FA 3 with sttes z 1, z 2, z 3,... ech z k is of the form x i or y j x strt or y strt is the strt stte of FA 3 z k (= x i or y j ) is finl stte IFF x i is finl or y j is finl 10 / 26

Exmple for Prt 3 Rule 2 FA 1 x 1 x 2 x 3, FA 2 y 1 y 2 Reminder of Exercise on Chlkord (show (L 1 + L 2 )) 11 / 26

Proof of Prt 3 Rule 3 Rule 3 If FA 1 ccepts lnguge(r 1 ) nd FA 2 ccepts lnguge(r 2 ), then n FA 3 exists nd ccepts lnguge(r 1 r 2 ) Mke z-stte for every non-finl x-stte in FA 1, reched efore ever hitting finl stte on FA 1 For ech finl stte in FA 1, we estlish z-stte tht expresses either (1) we re continuing on FA 1 or eginning on FA 2. Initil sttes re the initil sttes from FA 1 Finl sttes re the z-sttes tht represent the disjunction of ny finl stte from FA 2 12 / 26

Exmple of Prt 3 Rule 3 FA 1 x 1 x 2 x 3, FA 2, y 1 y 2, Reminder of Exercise on Chlkord (show L 1 L 2 ) 13 / 26

Proof of Prt 3 Rule 4 Rule 4 If r is regulr expression nd FA 1 ccepts lnguge (r), then there exists FA 2 where it ccepts lnguge (r ) (.k.. the Kleene Str) Crete stte for every suset of x s. Cncel ny suset tht contins finl x-stte, ut does not contin the strt stte. For ll remining non-empty sttes, drw n -edge nd -edge to the collection of x-sttes rechle in the originl FA from the component x s y - nd -edges, respectively. Cll the null suset initil-nd-finl stte nd connect it to whtever sttes the originl strt stte is connect to y - nd -edges (even the strt stte) Finlly, mrk sttes s finl if the contin n x-component tht is finl stte of the originl FA 14 / 26

Exmple of Prt 3 Rule 4 FA 1 y 1 y 2 Reminder of Exercise on Chlkord (show L 1 ) 15 / 26

Prt 3 Recp 1 There is n FA tht ccepts ny letter or λ 2 If FA 1 ccepts r 1 nd FA 2 ccepts r 2, then there exists FA 3 ccepting r 1 r 2 3 If FA 1 ccepts r 1 nd FA 2 ccepts r 2, then there exists FA 3 ccepting r 1 + r 2 4 If FA 1 ccepts r 1 then there exists FA 2 ccepting r 1 We cn construct ny regulr expression through repplictions of the following four rules ove. Therefore, ny RE cn e converted into n FA. 16 / 26

Nondeterministic Finite Automt Finite Automt introduced up to this point hve ll een deterministic Trnsition Grphs re non-deterministic y defult ut cn lso e much more complicted. Mye there exists hppy medium etween the two? 17 / 26

Nondeterministic Finite Automt Finite Automt introduced up to this point hve ll een deterministic Trnsition Grphs re non-deterministic y defult ut cn lso e much more complicted. Mye there exists hppy medium etween the two? NFA is type of Trnsition Grph which hs unique strt stte where ech edge hs single lphet letter nd where mny - nd -edges could come out of ech stte Invented y Rin nd Scott in 1959 17 / 26

Exmples of NFAs,, x 1 y 0 y 1 y 1 x 0 x 2, x 3 x 4 z 0 z 1, z 3 z 2 18 / 26

Eliminte ll Loop Sttes r 1 r 2 α β γ χ s ω ψ t 1 t 2 r 3 t 3 Mye it would e cool if we could remove ll loops? 19 / 26

Eliminte ll Loop Sttes r 1 t 1 r 2 α β s χ ψ t 2 r 3 γ s ω t 3 duplicte the stte 19 / 26

Eliminte ll Loop Sttes r 1 t 1 α s χ r 2 β ψ t 2 r 3 γ s ω t 3 remove loop nd dd trnsitions 19 / 26

Eliminte ll Loop Sttes r 1 χ t 1 α s χ ψ r 2 β ψ t 2 r 3 γ s ω ω t 3 copy ll outgoing trnsitions to new stte 19 / 26

Exmple All strings with triple followed y triple. Should we ccept? 20 / 26

Theorems nd Proofs of NFAs Theorem For every NFA, there is some FA (DFA) tht ccepts exctly the sme lnguge Proof. 1 Using Prt 2 from efore, convert the NFA into n RE 2 Using the four rules from Prt 3 from efore, construct n FA tht ccepts the RE generted in (1) 3 Becuse we proved ech prt of the proof prior, we re done 21 / 26

Theorems nd Proofs of NFAs Theorem For every NFA, there is some FA (DFA) tht ccepts exctly the sme lnguge Proof. 1 Using Prt 2 from efore, convert the NFA into n RE 2 Using the four rules from Prt 3 from efore, construct n FA tht ccepts the RE generted in (1) 3 Becuse we proved ech prt of the proof prior, we re done Wit... isn t tht crzy complicted nd orderline cheting? 21 / 26

NFA to DFA Algorithm The Big Picture: Rememer Rule 4 from Prt 3 which tells us to represent new sttes s choice of x-sttes All sttes in the (D)FA we will produce will lso e the collections of sttes from the originl NFA. Every time we encounter trnsition, we must follow tht trnsition for ech stte in where we were Every time we try to tke n - or -trnsition which does not collectively exist cross ll NFA sttes in our current collection, we go to common hell stte of which there is never ny escpe 22 / 26

NFA to DFA Trp Stte q 1 q 0 q 3 q 2 At q0 we hve exctly one -trnsition nd one -trnsition. Next! 23 / 26

NFA to DFA Trp Stte q 1 q 0, q 3 q 2 At q1 we hve one -trnsition BUT no -trnsition. We must (1) crete trp stte nd (2) mke n -trnsition to it 23 / 26

NFA to DFA Trp Stte q 1 q 0, q 3 q 2 23 / 26

NFA to DFA Trp Stte q 1 q 0, q 3 q 2 At q2 we hve one -trnsition BUT no -trnsition. We must mke n -trnsition from q2 to the trp stte 23 / 26

NFA to DFA Trp Stte q 1 q 0,, q 3 q 2 At q3 we hve no trnsitions, so we must crete trnsition for nd to the trp stte 23 / 26

Adding NFAs to Kleene s Theorem Proof. 1 The following NFAs cn ccept {}, {} nd {λ} respectively 2 Becuse of our theorem For every NFA there is some FA tht ccepts exctly the sme lnguge, there is n equivlent TG nd RE for given NFA 24 / 26

Simplifying the cretion of FA 1 + FA 2 Algorithm 1 Introduce new nd unique stte stte with two outgoing -edges nd two outgoing -edges 2 Connect ech of the edges to the sttes tht follow the strt of oth FA 1 nd FA 2. 3 Remove the strt mrkers for the sttes which hd originlly strted FA 1 nd FA 2 4 Using the lgorithm provided erlier, convert the NFA into n FA 25 / 26

Exmple, y 1 x 0 x 1 y 0 y 2 y 3 26 / 26

Exmple, y 1 x 0 x 1 y 0 y 2 y 3 Introduce new nd unique strt stte 26 / 26

Exmple, y 1 x 0 x 1 y 0 y 2 y 3 Add outgoing -trnsitions to the follow sttes of ech FA 26 / 26

Exmple, y 1 x 0 x 1 y 0 y 3 y 2 Add outgoing -trnsitions to the follow sttes of ech FA 26 / 26

Exmple, y 1 x 0 x 1 y 0 y 3 y 2 Remove the two strt s which hd originlly strted the two FAs 26 / 26