For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir

Similar documents
Automata and Languages

1.3 Regular Expressions

1.4 Nonregular Languages

Lecture 6 Regular Grammars

CS 275 Automata and Formal Language Theory

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

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.

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

CS 275 Automata and Formal Language Theory

First Midterm Examination

Formal languages, automata, and theory of computation

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

First Midterm Examination

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

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

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

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

Closure Properties of Regular Languages

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

Harvard University Computer Science 121 Midterm October 23, 2012

Theory of Computation Regular Languages

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

a b b a pop push read unread

Lecture 08: Feb. 08, 2019

CSC 473 Automata, Grammars & Languages 11/9/10

Recursively Enumerable and Recursive. Languages

CS 275 Automata and Formal Language Theory

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

Finite Automata-cont d

CSCI FOUNDATIONS OF COMPUTER SCIENCE

1 Structural induction

Let's start with an example:

CHAPTER 1 Regular Languages. Contents

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

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

CS 330 Formal Methods and Models

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

CS 314 Principles of Programming Languages

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

THEOTY OF COMPUTATION

Convert the NFA into DFA

Minimal DFA. minimal DFA for L starting from any other

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.

Lecture 09: Myhill-Nerode Theorem

State Minimization for DFAs

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

Non-Deterministic Finite Automata

1 Structural induction, finite automata, regular expressions

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

Name Ima Sample ASU ID

CS 330 Formal Methods and Models

Normal Forms for Context-free Grammars

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

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

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

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

p-adic Egyptian Fractions

ɛ-closure, Kleene s Theorem,

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

Parse trees, ambiguity, and Chomsky normal form

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

Euler-Maclaurin Summation Formula 1

1 From NFA to regular expression

FABER Formal Languages, Automata and Models of Computation

Turing Machines Part One

CS375: Logic and Theory of Computing

Note 16. Stokes theorem Differential Geometry, 2005

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

Formal Languages Simplifications of CFGs

Handout: Natural deduction for first order logic

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

CS375: Logic and Theory of Computing

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

CMSC 330: Organization of Programming Languages

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

Non-deterministic Finite Automata

UniversitaireWiskundeCompetitie. Problem 2005/4-A We have k=1. Show that for every q Q satisfying 0 < q < 1, there exists a finite subset K N so that

and that at t = 0 the object is at position 5. Find the position of the object at t = 2.

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

Non-deterministic Finite Automata

MAA 4212 Improper Integrals

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Decidability. Models of Computation 1

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

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

Worked out examples Finite Automata

Homework 3 Solutions

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

USA Mathematical Talent Search Round 1 Solutions Year 21 Academic Year

CS5371 Theory of Computation. Lecture 20: Complexity V (Polynomial-Time Reducibility)

E 1 (n) = E 0 (n-1) E 0 (n) = E 0 (n-1)+e 0 (n-2) T(n -1)=2E 0 (n-2) + E 0 (n-3)

Chapter 5. , r = r 1 r 2 (1) µ = m 1 m 2. r, r 2 = R µ m 2. R(m 1 + m 2 ) + m 2 r = r 1. m 2. r = r 1. R + µ m 1

Bases for Vector Spaces

This lecture covers Chapter 8 of HMU: Properties of CFLs

CS 330 Formal Methods and Models

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

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

Transcription:

CSCI 2400 Models of Computtion, Section 3 Solutions to Homework 4 Problem 1. ll the solutions below refer to the Pumping Lemm of Theorem 4.8, pge 119. () L = f n b l k : k n + lg Let's ssume for contrdiction tht L is regulr lnguge. We pply the pumping lemm to L. Let m be the prmeter of the pumping lemm. We choose to pump the string m b m 2m which is in the lnguge L, since 2m m+m (we hve n = m, l = m, nd k =2m). Since xyz = m b m 2m nd jxyj»m we hve tht the string y is substring of the first m of m b m 2m. Therefore, the string y hs the form y = p, for some integer p, 1» p» m (since jyj 1). Now, we pump up y once nd we obtin the string m+p b m 2m which is string identicl to m b m 2m with the only difference tht we replce y with y 2. By the pumping lemm, we hve tht m+p b m 2m is in the lnguge L. However, m+p b m 2m is not in the lnguge L since 2m <m+ p + m (violting the condition k n + l, where n = m+p, l = m, nd k = 2m). Therefore, we hve contrdiction. Subsequently, our originl ssumption tht the lnguge L is regulr must be wrong. Therefore, the lnguge L is not regulr. (b) L = fww : w 2 ± Λ g Let's ssume for contrdiction tht L is regulr lnguge. We pply the pumping lemm to L. Let m be the prmeter of the pumping lemm. We choose to pump the string m b m m b m which is in the lnguge L, since m b m m b m = ww with w = m b m. Since xyz = m b m m b m nd jxyj» m, we hve tht the string y is substring of the first m of m b m m b m. Therefore, the string y hs the form y = p, for some integer p, 1» p» m (since jyj 1). Now, we pump up y once nd we obtin the string m+p b m m b m which is string identicl to m b m m b m with the only difference tht we replce y with y 2. By the pumping lemm, wehve tht m+p b m m b m is in the lnguge L. However, m+p b m m b m is not in the lnguge L since there is no string w such tht m+p b m m b m = ww. Therefore, we hve contrdiction. Subsequently, our originl ssumption tht the lnguge L is regulr must be wrong. Therefore, the lnguge L is not regulr. (c) L = f k2 g Let's ssume for contrdiction tht L is regulr lnguge. We pply the pumping lemm to L. Let m be the prmeter of the pumping lemm. We choose to pump the string m2 which obviously is in the lnguge L. 1

For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the first m of m m m. Therefore, the string y hs the form y = p, for some integer p, 1» p» m (since jyj 1). Now, we pump up y once nd we obtin the string m+p m m which is string identicl to m m m with the only difference tht we replce y with y 2. By the pumping lemm, we hve tht m+p m m is in the lnguge L. On the other hnd, we cn rewrite m+p m m s m+p m m = p m m m = p m2 = m2 +p : m2 +p The string would be in the lnguge L if there would exist n integer k such tht m2 +p = k2. But there is no such k. To prove this, observe the following: since p» m. This implies tht m 2 <m 2 + p<m 2 +2m +1=(m +1) 2 ; Tking the squre roots we obtin, m 2 <k 2 < (m +1) 2 : m<k<m+1; which is impossible, since m nd k re positive integers. Therefore, there in no k such tht m2 +p = k2. Subsequently, the string m2 +p is not in the lnguge L. Therefore, we hve contrdiction. Subsequently, our originl ssumption tht the lnguge L is regulr must be wrong. Therefore, the lnguge L is not regulr. (d) L = fuww R v : u; v; w 2 ± + ; juj jvjg Let's ssume for contrdiction tht L is regulr lnguge. We pply the pumping lemm to L. Let m be the prmeter of the pumping lemm. We choose to pump the string (b) m (b) m which is in the lnguge L, by tking u = (b) m, ww R =, nd v = (b) m (notice tht juj = jvj, nd thus the condition juj jvj holds). We note tht in the string (b) m (b) m the rightmost loction of the middle of ny substring of the form ww R must pper within the middle substring. Since xyz = (b) m (b) m nd jxyj»m, wehve tht the string y is substring of the 2

first u =(b) m. Now let's pump down the string y, by removing it from the string (b) m (b) m. The resulting string hs the form u 0 (b) m, where u 0 is idecticl with the substring u =(b) m with the difference tht y is removed. By the pumping lemm we hve tht the string u 0 (b) m is in the lnguge L. On the other hnd, we hve tht ju 0 j < juj (since we pumped down y, nd jyj 1). Notice now tht in the string u 0 (b) m the rightmost loction of the middle of ny substring of the form ww R must pper in the substring, right fter u 0. For ww R =, the string u 0 (b) m cn be written in the form u 0 ww R v, with ju 0 j < juj = jvj. Therefore, the condition ju 0 j jvj of lnguge L is violted. The sme violtion occurs even when we identify the string ww R s ny other possible substring of u 0 (b) m (which could possibly spn u 0 nd v), since the middle of tht substring ppers in or t the left from. Therefore, the string u 0 (b) m is not in the lnguge L. Therefore, we hve contrdiction. Subsequently, our originl ssumption tht the lnguge L is regulr must be wrong. Therefore, the lnguge L is not regulr. Problem 2. () L = fw : n (w) 6= n b (w)g Not regulr. Intuitive explntion: For ny string in this lnguge we need to keep count of the numbers of 's nd b's so tht we compre them. finite utomton cnnot count the numbers of 's nd b's in n rbitrry input string, since the number of sttes is finite nd the input string length cn be rbitrrily lrge. Forml Explntion: Consider the complement lnguge L = fw : n (w) = n b (w)g. By the pumping lemm, the lnguge L is not regulr (you cnnot pump the string m b m ). Since regulr lnguges re closed under complement, it follows tht the lnguge L is not regulr either (if L ws regulr then L would be regulr too). (b) L = f n b l : n 100;l» 100g Regulr. Explntion: You cn construct finitite utomton tht ccepts this lnguge. The utomton hs two prts connected in series. The first prt recognizes strings of the form n with n 100 (this prt consists from sequence of 100 sttes, ech stte for single, then followed by loop stte for the 's fter the 100th ). The second prt recognizes strings of the form b l, where l» 100 (this prt consists from sequence of 100 sttes, ech stte for single b, nd ech stte is finl stte). 3

(c) L = fuww R v : u; v; w 2 ± + g Regulr. Explntion: The regulr expression tht describes this lnguge is ( + b) + ( + bb)( + b) + where the superscript +" mens 1 or more repetitions (the superscript Λ" mens 0 or more repetitions). (d) L = fb n l b k : n>5;l >3;l kg Not Regulr. Intuitive explntion: For ny string in this lnguge we need to keep count of the numbers of 's nd b's so tht we compre them. finite utomton cnnot count the numbers of 's nd b's in n rbitrry input string, since the number of sttes is finite nd the input string length cn be rbitrrily lrge. Forml Explntion: Consider the reverse lnguge L R = fb k l b n : n> 5;l > 3;l kg. By the pumping lemm, the lnguge L R is not regulr (you cnnot pump the string b m m 4 b 6 ). Since regulr lnguges re closed under reversl, it follows tht the lnguge L is not regulr either (if L ws regulr then L R would be regulr too). Problem 3. () L = fw : w strts nd ends with the sme symbol, nd w 2f; bg Λ g The following grmmr genertes lnguge L, where S is the strt vrible. S! T j bt b T! T j bt j The vribles S generte ny string tht strts nd ends with the sme symbol. The vrible T genertes ny string mde from 's nd b's. (b) The complement of the lnguge L = f n b n g. The following grmmr genertes lnguge L, where S is the strt vrible. S! 1 j 2 j 3 j B 1! 1 j 2! 1 X j 1 XT 3! XbT j XT 4

B! bt X! Xb j b T! T j bt j The vribles of the grmmr correspond to cse nlysis of the possible strings. The vribles 1, 2 nd 3 generte ll the strings tht strt with n, nd the vrible B genertes ll the strings tht strt with b. Therefore, the strt vrible S covers ll the cses. In order to generte the desired strings we use the helping vribles X nd T s follows. The vrible X genertes ll the strings of the form n b n, which wewnt tovoid (since these re excluded from the desired lnguge). The vrible T genertes ny string mde from symbols nd b (nmely, the lnguge ( + b) Λ ). The three cses of strings strting with re the following: Vrible 1 : genertes ny string of the form Λ. Vrible 2 : genertes ny string of the form + n b n nd + n b n (+ b) Λ. Vrible 3 : genertes ny string of the form n b n ( + b) +. (The + superscript mens one or more occurence.) These re ll the cses of strings strting with n. Notice tht vribles 2 nd 3 del with the cse where n b n is substring. The wy we remove n b n is by conctenting other strings to the left nd right of n b n. (c) L = fw : n (w) =2n b (w); where w 2f; bg Λ g The following grmmr genertes lnguge L, where S is the strt vrible. S! SS j S! Sb j Sb j Sb S! bs j bs j bs This is modifiction of the grmmr of Exmple 1.12 in pge 23 which hndles the cse n (w) =n b (w). The min difference here is tht we dd n extr symbol to ech possible position of the righthnd side of ech production tht hs terminl. (d) L = fw#x : w R is substring of x, where w; x 2f; bg Λ g The following grmmr genertes lnguge L, where S is the strt vrible. S! T! j bb j #T T! T j bt j 5

The strings in the lnguge hve the form w#uw R v, where u nd v re strings of the form ( + b) Λ (ny string mde from symbols nd b). The vrible T genertes the strings u nd v, while vrible genertes the string w#uw R nd the vrible S genertes the desired string w#uw R v. Problem 4. () The string s = b hs the following two leftmost derivtions: S ) B ) b S ) B ) B ) B ) b (b) The two derivtion trees of string b re shown in Figure 1. S ) B ) b S B b S ) B ) B ) B ) b S B b Figure 1: The two derivtion trees of string b 6

(c) The equivlent unmbiguous grmmr is the following: S! b! j This grmmr is not mbiguous becuse t ny derivrion step there is only one choice to mke. This grmmr is equivlent to the previous grmmr becse both grmmrs generte the sme lnguge: ll the stings tht strt with one or more 's nd end with single b. (d) With the new grmmr the unique leftmost derivtion nd derivtion tree of the string b re shown in Figure 2. S ) b ) b ) b S b Figure 2: The derivtion of string b with the unmbiguous grmmr 7