Lecture 08: Feb. 08, 2019

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

CHAPTER 1 Regular Languages. Contents

Fundamentals of Computer Science

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

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

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Theory of Computation Regular Languages

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

1 From NFA to regular expression

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

Deterministic Finite Automata

Non-deterministic Finite Automata

Harvard University Computer Science 121 Midterm October 23, 2012

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.

Finite Automata-cont d

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.

Non-deterministic Finite Automata

1 Nondeterministic Finite Automata

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

Worked out examples Finite Automata

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

CISC 4090 Theory of Computation

Let's start with an example:

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

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

Formal Languages and Automata

Closure Properties of Regular Languages

Finite-State Automata: Recap

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

Coalgebra, Lecture 15: Equations for Deterministic Automata

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

3 Regular expressions

NFAs continued, Closure Properties of Regular Languages

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Name Ima Sample ASU ID

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

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

Some Theory of Computation Exercises Week 1

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

First Midterm Examination

Homework 3 Solutions

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 2 Finite Automata

Lecture 09: Myhill-Nerode Theorem

Thoery of Automata CS402

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

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

Convert the NFA into DFA

Lexical Analysis Finite Automate

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

1.3 Regular Expressions

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

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

First Midterm Examination

Today s Topics Automata and Languages

Automata and Languages

Formal languages, automata, and theory of computation

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

ɛ-closure, Kleene s Theorem,

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

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

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

Lecture 9: LTL and Büchi Automata

Languages & Automata

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

Designing finite automata II

Java II Finite Automata I

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

CMSC 330: Organization of Programming Languages

State Minimization for DFAs

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

NFAs continued, Closure Properties of Regular Languages

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

CS375: Logic and Theory of Computing

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

Nondeterminism and Nodeterministic Automata

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

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

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

Closure Properties of Regular Languages

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

Formal Language and Automata Theory (CS21004)

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

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

CS375: Logic and Theory of Computing

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

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

Lecture 6 Regular Grammars

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.

Non-Deterministic Finite Automata

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

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

Hybrid Control and Switched Systems. Lecture #2 How to describe a hybrid system? Formal models for hybrid system

GNFA GNFA GNFA GNFA GNFA

CS 330 Formal Methods and Models

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7

Transcription:

4CS4-6:Theory of Computtion(Closure on Reg. Lngs., regex to NDFA, DFA to regex) Prof. K.R. Chowdhry Lecture 08: Fe. 08, 2019 : Professor of CS Disclimer: These notes hve not een sujected to the usul scrutiny reserved for forml pulictions. They my e distriuted outside this clss only with the permission of the Instructor. 8.1 Closure properties of Regulr lnguges We know tht regulr lnguges re expressile s Sets. The set opertions of union nd conctention correspond to lnguge opertions. Hence regulr lnguges hve closure properties under these opertions. However, there is no opertion on sets corresponding to Kleene Str opertion on Regulr Sets. In fct, this cn e considered s repeted conctention opertion. This section explores the closure properties of regulr lnguges corresponding to other opertions in sets, like intersections, complementtion, difference, nd symmetric difference. Theorem 8.1 The clss of lnguges ccepted y Finite Automt re closed under the opertion of (i) Complementtion, nd (ii) Intersection. Proof: I. Complementtion: Let the M = (Q,Σ,δ,s 0,F) e the finite utomton nd L = L(M) e the lnguge ccepted y it. The complement of M is M. Let M e the FA tht ccepts the lnguge L. Oviously M would ccept lnguges tht re not ccepted y M nd vice-vers. Therefore, the finl sttes in M re those tht re non-finl sttes in M nd, wht re non-finl sttes in M re finl sttes in M. In other words, the finl sttes nd non-finl sttes re interchnged in M nd M. However, the totl sttes remin the sme in oth the utomt. Thus, L = L(M) = Σ L(M), nd M = (Q,Σ,δ,s 0,Q F). Since M is finite utomton, the L lnguge ccepted y this is regulr. This shows tht complement of regulr lnguge is lso regulr, hence the regulr lnguges re closed under the opertion of complementtion. II. Intersection: LetusssumethtintersectionofregulrlngugesL 1 ndl 2 islnguge L = L 1 L 2. We wnt to determine whether L is regulr. Using De Morgn s theorem we rewrite the expression for intersection of L 1 nd L 2 s, L 1 L 2 = (L 1 L 2 ) (8.1) This mens tht, the lnguge L = L 1 L 2 consists ll words tht re in (L 1 L 2 ). In other words L consists those words tht re not in (L 1 L 2 ), tht is they re neither in L 1 8-1

8-2 Lecture 08: Fe. 08, 2019 nor in L 2. Since L 1 nd L 2 re regulr, hence L 1 nd L 2 re lso regulr. In ddition, their union (L 2 L 2 ) is regulr nd its complement (L 1 L 2 ) too. Hence, the intersection of two regulr lnguges results to regulr lnguge. Therefore, the regulr lnguges re closed under the opertion of intersection. Regrding the sttes of utomtion recognizing the lnguge (L 1 L 2 ), the following proof clrifies it: Let L 1 = L(M 1 ), nd L 2 = L(M 2 ), where M 1 = (Q 1,Σ 1,δ 1,s 1,F 1 ), nd M 2 = (Q 2,Σ 2,δ 2,s 2,F 2 ). A comined utomtion out of M 1 nd M 2 cn e constructed s M = (Q,Σ,δ,(s 1,s 2 ),F), where Q = Q 1 Q 2 = {(,q j ) Q 1,q j Q 2 }. The trnsition function δ is defined in such wy tht M is in stte (,q j ) whenever the M 1 is in stte nd M 2 is in stte q j. Thus, the stte trnsitions in M re defined s, δ((,qj ),) = (q k,q l ) If nd only if, δ 1 (,) = q k, nd, δ 2 (q j,) = q l. Similrly F is defined s the set of ll the pirs (,q j ), such tht F 1, nd q j F 2. Exmple 8.2 Consider regulr expression r = ( + ), nd construct finite utomtion which ccepts the lnguge L(r). Let us first consider only prt of the regulr expression, +, nd let = nd =. Therefore, =. Applying the rule of conctention from Theorem??, the FA which cn recognize L( ) is given s shown in Figure 8.1(). q 1 () q 7 q 8 q 9 0 () 1 q 1 2 q 7 q 8 q 9 0 (c) Figure 8.1: () FA for =, () FA for =, (c) FA for r 3 = + Similrly, the FA which cn recognize L( ) is shown in figure 8.1(). Let r 3 = +. By pplying the union opertion on the set of lnguges L( ) nd L( ), the new lnguge otined is L(r 3 ) = L( )L( ). The finite utomt for L(r 3 ) is s shown in figure 8.1(c).

Lecture 08: Fe. 08, 2019 8-3 Finlly, pplying the opertion of Kleene Str on the lnguge L(r 3 ) we get (L(r 3 )) = L(r3 ). The finite utomton for this is shown in figure 8.2. The strt stte for the NFA M is nd finl stte is 2. 1 1 q 7 q 8 q 9 0 2 Figure 8.2: FA for regulr expression (+) We hve noted tht, the min prt in deriving FA for given regulr expression is to find suexpressions in the regulr expressions, in the form of r+s, r q nd r. Therefore, prentheses re essentil for complex expression to mke precedence explicit. In this wy, we cn construct n NFA for ny given regulr expression. This NFA cn e converted into DFA s discussed in the previous clsses. 8.1.1 Generlized NFA Unlike the NFA, which reds one symol t time, generlized NFA (GNFA) reds lock of symols from the input, nd moves long the trnsition rrows connecting two sttes when lock of symols is red. This lock of symols is nothing ut regulr expression. The GNFA ccepts the input string corresponding to the lel if it leds to the finl stte when the string is completely red. A GNFA is formlly defined s, where, G = (Q,Σ,ρ,,q f ), (8.2) Q is finite set of sttes, Σ is lphet set, Q is initil stte, q f F is single finl stte, ρ : (Q {q f }) (Q { }) R Σ. In the ove R Σ is set of ll regulr expressions over the lphet set Σ. An input string is ccepted if there is wy to red the input string such tht the GNFA is in the ccepting (finl) stte fter processing of the entire string. A GNFA hs one strt stte (q strt ) with no incoming rrows, nd one ccepting stte (q finl ) with no outgoing rrows.

8-4 Lecture 08: Fe. 08, 2019 We rek this procedure into two prts, using GNFA. First we show how to convert DFAs into GNFAs, nd then GNFAs into regulr expressions. The method is clled stte removl method (see figure 8.3). DFA GNFA REG. EXP. Figure 8.3: Conversion of DFA to Regulr Expression The process of constructing regulr expression requires the finite utomton with only one initil nd one finl stte. To chieve this, we eliminte one stte t time from the initil trnsition-digrm. The resulting successive trnsition grphs re with r rrows, where r is regulr expression. Converting DFA into GNFA: 1. Add new strt stte (q strt ), with -trnsition from this to ). 2. Add new ccept stte (q ccept ), with -trnsition from ech of the finl stte to q ccept. 3. If n edge in originl DFA hs multiple lels, replce the lels with regulr expression formed y the union of these lels. 4. If originlly there is no rrow etween two sttes, dd new edge with lel φ. Converting GNFA into Regulr Expression: 1. We interctively remove sttes one y one in GNFA such tht, fter ech stte is removed, the new GNFA otined will recognize the sme lnguge s the previous one. 2. When sttes in the GNFA re two, we hve chieved the regulr expression for the given DFA, represented y the lel of the edge connecting these sttes. Removing stte q (not q strt or q ccept ) in the process of construction of GNFA is demonstrted in Figure 8.3. The new lel on the rrow from to q j ecomes Regulr Expression tht descries ll strings tht tke GNFA from to q j either directly or vi q (the removed stte). The Figure 8.4 shows n exmple of conversion of DFA to n equivlent GNFA. r q j r 3 r+(r1 r 2 r 3) f () () q j Figure 8.4: Conversion of DFA to GNFA: () DFA, () Equivlent GNFA.

Lecture 08: Fe. 08, 2019 8-5 Exmple 8.3 Otin Regulr expressions for given finite Automt using the pproch of GNFA construction. Vrious possile cses re shown for otining regulr expressions for given finite utomt. Ech cse shows n equivlent utomton for given regulr expression. Cse-I. A finite utomton ccepts the expression + + +r n (figure 8.5()). Replce it y the one shown in figure 8.5(). + +...+r n f f r n () () Figure 8.5: FA to Regulr expression(cse-i) Cse-II). If the trnsition digrm is like the one shown in figure 8.6(), replce it y tht in figure 8.6().,,...,r n r1 + +...+r n () () Figure 8.6: FA to Regulr expression(cse-ii) Cse-III. If there re more thn one finl sttes, sy, f 1, f 2, f 3 (figure 8.7(), then replce them with single finl stte (figure 8.7()). f 1 f 1 f 2 f 2 f f 3 f 3 () () Figure 8.7: FA to Regulr expression(cse-iii) Cse-IV. Simplify the trnsition digrm of three sttes s in figure 8.8() nd replce it y figure 8.8().

8-6 Lecture 08: Fe. 08, 2019 ( ) r3 r 3 q j q k qi q k () () Figure 8.8: FA to Regulr expression(cse-iv) Cse-V. Replce the old trnsition digrm in figure 8.9() y shown in figure 8.9(). ( ) r3 r 3 q j q k q k () () Figure 8.9: FA to Regulr expression(cse-v). Cse VI. Replce the old trnsition digrm in figure 8.10() y tht in figure 8.10(). q k q k r 3 q j r 3 r 3 q l q l () () Figure 8.10: FA to Regulr expression(cse-vi) In the similr wy, using these primitives, ny complex utomton cn e reduced to GNFA, which ultimtely produce the regulr expression. Exmple 8.4 Find the regulr expression for the utomton shown in the Figure 8.11. Figure 8.11: Finite utomton The reduction steps discussed ove mke use of rules discussed in Lemm??. The resultnt regulr expression is (+ ).

Lecture 08: Fe. 08, 2019 8-7 () () (c) (d), (e) q0 (+ ) Figure 8.12: Steps()-(e) re for construction of regulr expression from Finite utomton. The reduction steps for the finite utomtion, to otin the regulr expression, fter conversion of FA into GNFA, re shown in Figure 8.12. Using the primitives discussed ove in most cses, DFA cn e converted into GNFA, nd then to regulr expression. However, some times the ove method is too cumersome, nd even my not e universl solution some times.