CIT3130: Theory of Computation. Regular languages

Similar documents
CSE 105 THEORY OF COMPUTATION

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

To illustrate what is intended the following are three write ups by students. Diagonalization

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Ambiguous Grammars and Compactification

CSE 105 THEORY OF COMPUTATION

(Refer Slide Time: 0:19)

Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages

6 NFA and Regular Expressions

Finite automata. We have looked at using Lex to build a scanner on the basis of regular expressions.

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

Chapter Seven: Regular Expressions

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

Computer Science 236 Fall Nov. 11, 2010

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

THEORY OF COMPUTATION

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

Formal languages and computation models

Source of Slides: Introduction to Automata Theory, Languages, and Computation By John E. Hopcroft, Rajeev Motwani and Jeffrey D.

ECS 120 Lesson 7 Regular Expressions, Pt. 1

Learn Smart and Grow with world

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA

Formal Languages and Automata

Languages and Compilers

Regular Languages and Regular Expressions

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

CS402 - Theory of Automata Glossary By

Theory Bridge Exam Example Questions Version of June 6, 2008

Theory of Computation, Homework 3 Sample Solution

Theory of Computation

Lecture 2 Finite Automata

ECS 20 Lecture 9 Fall Oct 2013 Phil Rogaway

Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1

Name: Finite Automata

Slides for Faculty Oxford University Press All rights reserved.

1. [5 points each] True or False. If the question is currently open, write O or Open.

Lexical Analysis. Prof. James L. Frankel Harvard University

LECTURE NOTES THEORY OF COMPUTATION

Converting a DFA to a Regular Expression JP

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

FAdo: Interactive Tools for Learning Formal Computational Models

2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS

Decidable Problems. We examine the problems for which there is an algorithm.

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

LECTURE NOTES THEORY OF COMPUTATION

Final Course Review. Reading: Chapters 1-9

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

Computer Sciences Department

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Lecture 15: The subspace topology, Closed sets

MATH 139 W12 Review 1 Checklist 1. Exam Checklist. 1. Introduction to Predicates and Quantified Statements (chapters ).

AUBER (Models of Computation, Languages and Automata) EXERCISES

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

PS3 - Comments. Describe precisely the language accepted by this nondeterministic PDA.

Midterm I review. Reading: Chapters 1-4

Automata & languages. A primer on the Theory of Computation. The imitation game (2014) Benedict Cumberbatch Alan Turing ( ) Laurent Vanbever

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006.

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81%

1 Finite Representations of Languages

DVA337 HT17 - LECTURE 4. Languages and regular expressions

Decision Properties of RLs & Automaton Minimization

Decision, Computation and Language

JNTUWORLD. Code No: R

CHAPTER 8. Copyright Cengage Learning. All rights reserved.

Lexical Analysis. Chapter 2

Multiple Choice Questions

CS 432 Fall Mike Lam, Professor. Finite Automata Conversions and Lexing

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal.

lec3:nondeterministic finite state automata

2 Review of Set Theory

8 ε. Figure 1: An NFA-ǫ

CS525 Winter 2012 \ Class Assignment #2 Preparation

A Formal Study of Practical Regular Expressions

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

CS/B.Tech/CSE/IT/EVEN/SEM-4/CS-402/ ItIauIafIaAblll~AladUnrtel1ity

Quiz 1: Solutions J/18.400J: Automata, Computability and Complexity. Nati Srebro, Susan Hohenberger

Languages and Finite Automata

CS2 Language Processing note 3

QUESTION BANK. Unit 1. Introduction to Finite Automata

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007.

Problems, Languages, Machines, Computability, Complexity

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

Notes for Comp 454 Week 2

Front End: Lexical Analysis. The Structure of a Compiler

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

CT32 COMPUTER NETWORKS DEC 2015

CS402 - Theory of Automata FAQs By

Automata Theory CS S-FR Final Review

Pushdown Automata. A PDA is an FA together with a stack.

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

Chapter 1 AUTOMATA & LANGUAGES. Roger Wattenhofer. ETH Zurich Distributed Computing

Transcription:

ƒ CIT3130: Theory of Computation Regular languages ( M refers to the first edition of Martin and H to IALC by Hopcroft et al.) Definitions of regular expressions and regular languages: A regular expression of an alphabet is composed from the expressions,, ( ), ( ) using union ( ), concatenation ( ) and iteration (, where = ). A language is regular if it is the language defined by some regular expression. Examples of regular languages: strings of even length (M, Ex. 3.1); strings of odd length; strings in "!$# %& containing at least one 1 (M, Ex. 3.2); strings in "!'#%& of length at most 6 (M, Ex. 3.4); strings in "!'# %( that end in 1 and do not contain the substring 00 (M, Ex. 3.5); Java floating point constants (M, Ex. 3.6); strings in "!'# %( denoting integers divisible by 3 (best postponed until finite automata have been introduced). A regular language may be defined by different regular expressions, e.g.,!$ %*)+!,-%(./, )+!, %&.0 %*)+!1%&./ and )2!1%&./ %!* (M, Ex. 3.3). Regular languages are closed under union, concatenation and iteration (trivial). Regular languages are also closed under complement (35476 98:3 ), intersection, difference, symmetric difference (3;=<>356?)@3AA8B3CD.CE)/35F8G3A. ). If 3 is regular, then H*IJK)/3;. is regular, where H*IJK)/3;.C6 C ML" L&NOQP P P= RTS( O= 'UPP P L V3W. Every finite language is regular. Informal proof and proof by induction. Examples of nonregular languages: CX(X&YZS[X Q, where X\Y]6^H_IJ`)2X*. ; the set of all palindromes in "!'#%&* (M, Thm 4.3); C L*aL S_bEc!; ; legal arithmetic expressions using the identifier, the operator, and left and right parentheses. Applications of regular expressions (H, 3.3). Algebraic laws can be used to simplify regular expressions (H, 3.4): 3d6e3EG f6e3, 3Z6 3A E6 3, '3Z6 3C g6, 3hdi 6 i -3, )/3jdi.dk 6 3jl)@i -km., )@3Ai.=k 6n3F)/i km., 39)/i gko.m6n3ai 3Ak, )@3pi.k 6 3;i 3Ak,3j3q6n3, )@3Cr.06s35, M96, 96, 3Ctu6 3A3Cv6w3Cr3, 356 3Ctxh, yz37{ 6 3mh. Finite-state automaton for the regular expression )=%9p!'%(.=t, where tm6. Definition of (deterministic) finite-state automata (DFA). A DFA has a set of states }, an jƒ alphabet, an initial state ~[ V}, a transition function '} }, and a set of accepting states }. Often a DFA is drawn as a transition diagram, with each state having a transition for each element of. (In programs, the transition function of a DFA is represented by a state transition matrix.) Examples of DFAs: Initial and simplified DFA for the regular expression "!$# %&&%! (M, Ex. 4.4); DFA for the binary numbers divisible by 3. Definition of the extended transition function v O}d }. 1

A string Xf is accepted by a DFA if _r)+~ #X*.> l. The language 3F)@is. accepted, or recognised, by a DFA i is the set of strings in that are accepted by i. Consider the DFA with }q6]" #!$# #%*#, 6]"!$# %&, ~ 6, 6]$)+ #!'#!M., )2 #%*# %(., )2!$#!'#., )+!'# %"#., ) #!'#., ) # %*#., )=%*#!$#., )%*#%*#., ) W#!$#., ) W# %"# %&.=, B6 " # (M, Ex. 4.5). What languages does this DFA recognise? Another example of a DFA: Strings in "!'# %(_ with an even number of 0s and an even number of 1s (H, Ex. 2.4). Programs to recognise languages accepted by DFAs. Kleene s theorem: A language is regular (has a regular expression) if and only if it is recognised by some DFA. (See below.) DFAs may have unnecessary states and transitions. Consider the DFA for )=% w!$%&. t (M, Ex. 5.1). We could omit one state, and say that if the machine has no transition it can quit immediately and not accept the string. DFAs may be unnecessarily complex. Consider the DFA for )2! w%&. )+!*!"! w%*%"%&.)+! w% and the nondeterministic finite-state automaton that corresponds directly to the regular expression (M, Ex. 5.2). We say the machine accepts a string if there is some sequence of transitions that leads to an accepting state. Definition of a nondeterministic finite-state automaton (NFA). An NFA has a set of states }, qƒ an alphabet, an initial state ~ }, a transition function E v}], and a set of accepting states g B}. Example of an NFA for CX j"!$# %&*>S7S XOSUcdk and the k th symbol from the right is %5, for k c% (M, Ex. 5.3; N, Ex. 2.13). ƒ Definition of the extended transition function v O}d for NFAs: 1. "r)2~$#r.56 "~ 2. "r)2~$#x( R.C6 * $) # R. That is, *r)+~'#x*. is the set of states that the machine can reach from the initial state ~ with input string X. A string X is accepted by an NFA if _ )2~ #X*.o 6G. The language 3F)@i. accepted, or recognised, by an NFA i is the set of strings in that are accepted by i. NFAs may have many fewer states than the corresponding DFA. Consider the above NFA for CX V"!$# %&"SKS XOSc k and the k th symbol from the right is %7. Equivalence of DFAs and NFAs by subset construction (H, 2.3.5 6). To construct a DFA equivalent to an NFA k, let = )@} # # F#r"~ $#!9., where 1. }"E6 $#, i.e., }% is the set of subsets of }'&. 2

2. For each set in }' and symbol in, 9)/ # R.A6 &[) U# O.P I.e., )/ # O. is the union of all the states that k can go to from states in with input. 3.! is the set of states in }' (equivalently, subsets of states in } & ) such that!& 6w. Example of subset construction (H, Exx. 2.6 and 2.9): Construction of DFA equivalent to 3- state NFA (H, FIg. 2.9) accepting all strings in "!'# %( that end with!'%. Example of subset construction for (k "!'#%&" such that the k th symbol from the right is % (H, Ex. 2.13). Application of DFAs and NFAs to text search (H, 2.4). % )-state NFA (H, Fig. 2.15) accepting all strings in The use of -transitions moves that change state without reading input symbols further simplify NFAs (M, Ex. 5.4) and the proof of Kleene s theorem. NFAs with -transitions are called -NFAs. Example: -NFA for decimal numbers (H, Ex. 2.16). Definition of the extended transition function to incorporate -transitions by using -closures, (H, 2.5.4). Equivalence of -NFAs and DFAs by a modified subset construction using -closures (H, 2.5.5). Example: Construction of a DFA equivalent to the -NFA above for decimal numbers (H, Ex. 2.21). Example: Construction of a DFA equivalent to the four-state -NFA with :6 $)2~\ # #~., )2~ #r #~D., )2~&#!'#~&., )2~& # %*# ~, ~ r#!$#~., )2~ # %*#~D. and B6 "~ r (M, Ex. 5.6). Kleene s theorem: A language is regular (has a regular expression) if and only if it is recognised by some DFA. See Fig. 3.1 (H., p.91). Proof: Every NFA is equivalent to a DFA by the subset construction (H, 2.3.5). Every DFA is equivalent to a regular expression by the state elimination construction (H, 3.2.2). Every regular expression is equivalent to an -NFA by a simple inductive construction (H, 3.2.3). Finally, every -NFA is equivalent to an NFA by a modified subset construction (H, 2.5.5). (This last modification involves use of -closures.) Example: Construct a regular expression from the following DFA that accepts all strings in "!'#%&" containing at least one 0 (H, Ex. 3.5, but using a different construction): 3

ƒ ƒ L % L 0 1 p q p *q q q Example: Construct a regular expression from the following DFA that accepts all strings in "!'#%& containing the substring 00: 0 1 p q p q r p *r r r Example: Construct a regular expression from the 3-state DFA from Tutorial 1 that accepts all strings in "!'# %(* representing (binary) numbers evenly divisible by 3. Example: Construct an -NFA equivalent to the language )2!:%(. %")2! :%&. (H, Ex. 3.8). Example: Construct a DFA (by the modified subset construction) equivalent to the resulting -NFA. Recognising that languages are not regular (H, 4.1). The pumping lemma for regular languages (H, 4.1.1): Let 3 be a regular language. Then there exists a constant b c% such that, for every string in 3 with S S c:b, we can write 6 in such a way that: 1. S S 1b (the initial section is not too long). 2. 6 (the string to pump is not empty). 3. For all cb!, the string is in 3 (the string may be pumped any number of times, including 0, and the resulting string is still in 3 ). Proof outline: Every string in 3 with more symbols than states in the DFA for 3 must cause some state to repeat in being recongised, which allows any number of cycles through that state. Applications. The following languages are not regular: 1. All strings in "!$# %& with an equal number of 0s and 1s (H, Ex. 4.2). If this language 3 is regular, there exists b satisfying the above condition. Let 6G!. Clearly S S'cwb. We can then write as with S S db, where 6d! for c %. By the lemma, V3 (x61! ). But has b 8 0s and b 1s, which is a contradiction. 2. C! L % L S(b c%7. 3. The set of balanced parenthesis strings. 4. C! L % S(b. 5. C! L S"b is a perfect square 4

Closure properties of regular languages. Regular languages are closed under union, concatenation and iteration, complement, intersection, and difference. The first three are immediate from regular expression construction (H, Thm 4.3). Complement follows from reversing final and nonfinal states in a DFA (H, Thm 4.5). Intersection (and union) follow from a product construction on DFAs (H, Thm 4.8). Example: Construct the DFA that accepts the language with an even number of 0s and an even number of 1s as the intersection of two simpler languages. Regular languages are also closed under reversal if L is regular, then 3 YV6 YjS 3W is regular either by DFA construction or induction on regular expression definition (H, Thm 4.11). Example: The set of strings in "!'# %(_ with different numbers of 0s and 1s is not regular. This is harder (not possible?) to prove using the pumping lemma. Decision problems for regular languages (H, 4.3). The following problems are decidable: 1. (Emptiness) Is the language empty? (Is there a path from the initial state to a final state? Use induction on the regular expression.) 2. (Finiteness) Is the language finite? (Let b be the pumping-lemma constant. Test all strings of length between b and bm8w% for membership in 3. If we find even one such string, then 3 is infinite. The reason is that the pumping lemma applies to such a string, and it can be pumped to show an infinite sequence of strings are in 3.) 3. (Membership) Does a given string belong to the language? (Apply the DFA for the language to the string.) 4. (Equality) Do two language descriptions define the same language? (A more complex problem, see H, 4.4) Each DFA has a unique (up-to-renaming) equivalent minimal-state DFA (H, 4.4). 5