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

Similar documents
Homework 3 Solutions

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

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

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

Minimal DFA. minimal DFA for L starting from any other

Lecture 09: Myhill-Nerode Theorem

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.

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

Lecture 08: Feb. 08, 2019

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

Harvard University Computer Science 121 Midterm October 23, 2012

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Parse trees, ambiguity, and Chomsky normal form

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

Deterministic Finite Automata

1 Nondeterministic Finite Automata

1.4 Nonregular Languages

Finite Automata-cont d

Lecture 3: Equivalence Relations

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

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

CHAPTER 1 Regular Languages. Contents

First Midterm Examination

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

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

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

1 From NFA to regular expression

Theory of Computation Regular Languages

State Minimization for DFAs

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

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

Chapter 2 Finite Automata

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

Coalgebra, Lecture 15: Equations for Deterministic Automata

Lexical Analysis Finite Automate

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Name Ima Sample ASU ID

NFAs continued, Closure Properties of Regular Languages

Closure Properties of Regular Languages

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Let's start with an example:

Designing finite automata II

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.

First Midterm Examination

CMSC 330: Organization of Programming Languages

Convert the NFA into DFA

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

Non-deterministic Finite Automata

Homework Solution - Set 5 Due: Friday 10/03/08

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

CSE396 Prelim I Answer Key Spring 2017

p-adic Egyptian Fractions

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

1.3 Regular Expressions

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

set is not closed under matrix [ multiplication, ] and does not form a group.

3 Regular expressions

Infinite Geometric Series

Review of Gaussian Quadrature method

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

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.

Fundamentals of Computer Science

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

Some Theory of Computation Exercises Week 1

Non-deterministic Finite Automata

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

Formal Languages and Automata

CS 275 Automata and Formal Language Theory

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

Surface maps into free groups

Nondeterminism and Nodeterministic Automata

Tutorial Automata and formal Languages

Finite-State Automata: Recap

Lecture 3 ( ) (translated and slightly adapted from lecture notes by Martin Klazar)

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

GNFA GNFA GNFA GNFA GNFA

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

Improper Integrals. The First Fundamental Theorem of Calculus, as we ve discussed in class, goes as follows:

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

NFAs continued, Closure Properties of Regular Languages

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

CS 330 Formal Methods and Models

Bases for Vector Spaces

Turing Machines Part One

Automata and Languages

Lecture 2e Orthogonal Complement (pages )

Worked out examples Finite Automata

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

Farey Fractions. Rickard Fernström. U.U.D.M. Project Report 2017:24. Department of Mathematics Uppsala University

Lecture 2: January 27

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

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

1 Structural induction, finite automata, regular expressions

Formal languages, automata, and theory of computation

Linear Inequalities. Work Sheet 1

CS 330 Formal Methods and Models

Transcription:

CS103 Hndout 32 Fll 2016 Novemer 11, 2016 Prolem Set 7 Wht cn you do with regulr expressions? Wht re the limits of regulr lnguges? On this prolem set, you'll find out! As lwys, plese feel free to drop y office hours, sk on Pizz, or send us emils if you hve ny questions. We'd e hppy to help out. Good luck, nd hve fun! Due Fridy, Novemer 18 t the strt of clss. Skills developed in this prolem set: Designing nd testing regulr expressions. Switching etween different representtions of regulr lnguge to prove results out those lnguges. Using the stte-elimintion lgorithm to convert finite utomt into regulr expressions. Understnding the definition of distinguishility t conceptul level. Using the Myhill-Nerode theorem to prove tht lnguges re or re not regulr. Building n intuition for wht mkes lnguge regulr or nonregulr. Developing nunced understnding of the proof of the Myhill-Nerode theorem nd using it to generlize the proof of tht result. Exploring the nunces of closure properties nd their limits.

Prolem One: Designing Regulr Expressions (14 Points) Below re list of lphets nd lnguges over those lphets. For ech lnguge, write regulr expression for tht lnguge. Plese use our online tool to design, test, nd sumit your regulr expressions. Typed or hndwritten solutions will not e ccepted. To use it, visit the CS103 wesite nd click the Regex Editor link under the Resources heder. As efore, mke note in your GrdeScope sumission of which tem memer sumitted your nswers to this question so tht we know where to look. Also, s reminder, plese test your sumissions thoroughly, since we'll e grding them with n utogrder. i. Let Σ = {, } nd let L = { w Σ* w does not contin s sustring }. Write regulr expression for L. ii. Let Σ = {, } nd let L = { w Σ* w does not contin s sustring }. Write regulr expression for L. iii. Suppose you re tking wlk with your dog on lesh of length two. Let Σ = {y, d} nd let L = { w Σ* w represents wlk with your dog on lesh where you nd your dog oth end up t the sme loction }. For exmple, the string yyddddyy is in L ecuse you nd your dog re never more thn two steps prt nd oth of you end up four steps hed of where you strted; similrly, ddydyy L. However, yyyyddd L, since hlfwy through your wlk you re three steps hed of your dog; ddyd L, ecuse your dog ends up two steps hed of you; nd ddyddyyy L, ecuse t one point in your wlk your dog is three steps hed of you. Write regulr expression for L. iv. Let Σ = {, } nd let L = { w Σ* w }. Write regulr expression for L. v. Let Σ = {M, D, C, L, X, V, I} nd let L = { w Σ* w is numer less thn 1,000 represented in Romn numerls }. For exmple, CMXCIX L, since it represents the numer 999, s re the strings L (50), VIII (8), DCLXVI (666), CXXXVII (137), nd CDXII (412). However, we hve VIIII L (you'll never hve four I's in row; use IX or IV insted), tht MI L (it's Romn numerl, ut it's for numer tht's too lrge), tht VX L (this isn't vlid Romn numerl), nd tht IM L (the nottion of using smller digit to sutrct from lrger one only lets you use I to prefix V nd X, or X to prefix L nd C, or C to prefix D nd M). The Romns didn't hve wy of expressing the numer 0, so to mke your life esier we'll sy tht ε L nd tht the empty string represents 0. (Oh, those silly Romns.) Write regulr expression for L. Prolem Two: Finite nd Cofinite Lnguges (6 Points) A lnguge L is clled finite if L contins finitely mny strings. More precisely, lnguge L is finite lnguge if L is nturl numer. A lnguge L is clled cofinite if its complement is finite lnguge; tht is, L is cofinite if L is nturl numer. i. Prove tht ny finite lnguge is regulr. ii. Prove tht ny cofinite lnguge is regulr.

Prolem Three: Stte Elimintion (6 Points) The stte elimintion lgorithm gives wy to trnsform finite utomton (DFA or NFA) into regulr expression. It's relly eutiful lgorithm once you get the hng of it, so we thought tht we'd let you try it out on prticulr exmple. Let Σ = {, } nd let L = { w Σ* w hs n even numer of 's nd n even numer of 's}. Below is finite utomton for L tht we've prepred for the stte elimintion lgorithm y dding in new strt stte q strt nd new ccept stte q cc : q cc strt q strt ε ε q 0 q 1 q 2 q 3 We'd like you to use the stte elimintion lgorithm to produce regulr expression for L. i. Run two steps of the stte elimintion lgorithm on the ove utomton. Specificlly, first remove stte q₁, then remove stte q₂. Show your result t this point. ii. Finish the stte elimintion lgorithm y removing q₃, then q₀. Wht regulr expression do you get for L? Prolem Four: Distinguishle Strings (6 Points) The Myhill-Nerode theorem is one of the trickier nd more nunced theorems we've covered this qurter. This question explores wht the theorem mens nd, importntly, wht it doesn't men. Let Σ = {, } nd let L = { w Σ* w is even }. i. Show tht L is regulr lnguge. ii. Prove tht there is infinite set S Σ* where there re infinitely mny pirs of distinct strings x, y S such tht x L y. iii. Prove tht there is no infinite set S Σ* where ll pirs of distinct strings x, y S stisfy x L y. The distinction etween prts (ii) nd (iii) is importnt for understnding the Myhill-Nerode theorem. A lnguge is nonregulr not if you cn find infinitely mny pirs of distinguishle strings, ut rther if you cn find infinitely mny strings tht re ll pirwise distinguishle. This is sutle distinction, ut it's n importnt one!

Prolem Five: Blnced Prentheses (12 Points) Let Σ = {(, )} nd consider the lnguge L₁ = { w Σ* w is string of lnced prentheses }. For exmple, we hve () L₁, (()) L₁, (()())() L₁, ε L₁, nd (())((()())) L₁, ut )( L₁, (() L₁, nd ((()))) L₁. This question explores properties of this lnguge. i. Prove tht L₁ is not regulr lnguge. One consequence of this result which you don't need to prove is tht most lnguges tht support some sort of nested prentheses, such s most progrmming lnguges nd HTML, ren't regulr nd so cn't e prsed using regulr expressions. Let's sy tht the nesting depth of string of lnced prentheses is the mximum numer of unmtched open prentheses t ny point inside the string. For exmple, the string ((())) hs nesting depth three, the string (()())() hs nesting depth two, nd the string ε hs nesting depth zero. Consider the lnguge L₂ = { w Σ* w is string of lnced prentheses nd w's nesting depth is t most four }. For exmple, ((())) L₂, (()()) L₂, nd (((())))(()) L₂, ut ((((())))) L₂ ecuse lthough it's string of lnced prentheses, the nesting goes five levels deep. ii. Design DFA for L₂, showing tht L₂ is regulr. A consequence of this result which, gin, you don't need to prove is tht while you cn't prse generl progrms or HTML with regulr expressions, you cn (in principle) prse progrms with low nesting depth or HTML documents without deeply-nested tgs using regulr expressions. Plese sumit this DFA using the DFA editor on the course wesite. iii. Look ck t your proof from prt (i) of this prolem. Imgine tht you were to tke tht exct proof nd lindly replce every instnce of L₁ with L₂. This would give you (incorrect) proof tht L₂ is nonregulr (we know is hs to e wrong ecuse L₂ is indeed regulr.) Where would the error e in tht proof? Be s specific s possile. iv. Without mking reference to DFAs, NFAs, regulr expressions, or the Myhill-Nerode theorem, explin, intuitively, why L₁ is nonregulr while L₂ is regulr. Prolem Six: Tutonyms (8 Points) A tutonym is word tht consists of the sme string repeted twice. For exmple, the words ulul, crcr, nd dikdik re ll tutoynms (the first two re species of irds, nd the lst is the cutest niml you'll ever see), s is the word hotshots (people who ren't very fun to e round). Let Σ = {, } nd consider the following lnguge: L = { ww w Σ* } This is the lnguge of ll tutonyms over Σ. Below is n incorrect proof tht L is not regulr: Proof: Let S = { n n N }. This set is infinite ecuse it contins one string for ech nturl numer. We clim tht ny two strings in S re distinguishle reltive to L. To see this, consider ny two distinct strings n nd m in the set S. Then n n L ut m n L, so n L m. This mens tht S is n infinite set of strings tht re pirwise distinguishle to L. Therefore, y the Myhill-Nerode theorem, L is not regulr. Although this lnguge is indeed nonregulr, this proof is incorrect. i. Wht's wrong with this proof? Be specific. ii. Although the ove proof is incorrect, the lnguge L isn't regulr. Prove this.

Prolem Seven: Stte Lower Bounds (6 Points) The Myhill-Nerode theorem we proved in lecture is ctully specil cse of more generl theorem out regulr lnguges tht cn e used to prove lower ounds on the numer of sttes necessry to construct DFA for given lnguge. i. Let L e lnguge over Σ. Suppose there's finite set S such tht ny two distinct strings x, y S re distinguishle reltive to L (tht is, x L y). Prove tht ny DFA for L must hve t lest S sttes. (You sometimes her this referred to s lower-ounding the size of ny DFA for L.) Consider this lnguge from Prolem Two, prt (iii) from Prolem Set Six: L₁ = { w {, }* w contins t lest two 's with exctly five chrcters etween them } It's possile to uild seven-stte NFA for this prticulr lnguge, ut ny DFA for this lnguge will hve to hve huge numer of sttes. ii. Let S = {, } 6. Prove tht ny pir of distinct strings in S re distinguishle reltive to L₁. This shows tht ny DFA for L₁ must hve t lest 64 sttes, since there re 64 strings in S. Prolem Eight: Closure Properties Revisited (9 Points) When uilding up the regulr expressions, we explored severl closure properties of the regulr lnguges. This prolem explores some of their nunces. The regulr lnguges re closed under complementtion: If L is regulr, so is L. i. Prove or disprove: the nonregulr lnguges re closed under complementtion. The regulr lnguges re closed under union: If L₁ nd L₂ re regulr, so is L₁ L₂. ii. Prove or disprove: the nonregulr lnguges re closed under union. We know tht the union of ny two regulr lnguges is regulr. Using induction, we cn show tht the union of ny finite numer of regulr lnguges is lso regulr. As result, we sy tht the regulr lnguges re closed under finite union. An infinite union is the union of infinitely mny sets. For exmple, the rtionl numers cn e expressed s the infinite union { x / 1 x Z } { x / 2 x Z } { x / 3 x Z } out to infinity. iii. Prove or disprove: the regulr lnguges re closed under infinite union.

Extr Credit Prolem: Fooling Sets (1 Point Extr Credit) In Prolem Seven, you sw how to use distinguishility to lower-ound the size of DFAs for prticulr lnguge. Unfortuntely, distinguishility is not powerful enough technique to lower-ound the sizes of NFAs. In fct, it's in generl quite hrd to ound NFA sizes; there's $1,000,000 prize for nyone who finds polynomil-time lgorithm tht, given n ritrry NFA, converts it to the smllest possile equivlent NFA! Although it's generlly difficult to lower-ound the sizes of NFAs is in gener, there re some techniques we cn use to find lower ounds on the sizes of NFAs. Let L e lnguge over Σ. A generlized fooling set for L is set F Σ* Σ* is set with the following properties: For ny (x, y) F, we hve xy L. For ny distinct pirs (x₁, y₁), (x₂, y₂) F, we hve x₁y₂ L or x₂y₁ L (this is n inclusive OR.) As n exmple, consider this lnguge L₁: L₁ = { w {, }* w contins t lest two 's with exctly five chrcters etween them } The following set is generlized fooling set for L₁: F₁ = { (, ), (, ), (, ), (, ), (, ), (, ), (, ε) } It's worth investigting why, exctly, this is generlized fooling set for L₁. Prove tht if there is generlized fooling set F for some lnguge L tht contins n pirs of strings, then ny NFA for L must hve t lest n sttes.