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

Similar documents
First Midterm Examination

Harvard University Computer Science 121 Midterm October 23, 2012

Formal languages, automata, and theory of computation

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

Minimal DFA. minimal DFA for L starting from any other

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

Worked out examples Finite Automata

Nondeterminism and Nodeterministic Automata

First Midterm Examination

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

Homework 3 Solutions

Convert the NFA into DFA

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

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.

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

Formal Languages and Automata

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

Finite Automata-cont d

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Theory of Computation Regular Languages

Lecture 08: Feb. 08, 2019

Deterministic Finite Automata

Non-deterministic Finite Automata

1.4 Nonregular Languages

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

Section: Other Models of Turing Machines. Definition: Two automata are equivalent if they accept the same language.

Some Theory of Computation Exercises Week 1

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

Non-deterministic Finite Automata

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

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

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.

Revision Sheet. (a) Give a regular expression for each of the following languages:

CS375: Logic and Theory of Computing

CS 330 Formal Methods and Models

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

Finite-State Automata: Recap

The University of Nottingham

Designing finite automata II

Java II Finite Automata I

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

CHAPTER 1 Regular Languages. Contents

CSC 311 Theory of Computation

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

1 Nondeterministic Finite Automata

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

CS 275 Automata and Formal Language Theory

Languages & Automata

GNFA GNFA GNFA GNFA GNFA

CS 330 Formal Methods and Models

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

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

Lecture 09: Myhill-Nerode Theorem

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

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

CMSC 330: Organization of Programming Languages

CS S-12 Turing Machine Modifications 1. When we added a stack to NFA to get a PDA, we increased computational power

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

Let's start with an example:

FABER Formal Languages, Automata and Models of Computation

Thoery of Automata CS402

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

Name Ima Sample ASU ID

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

CS 275 Automata and Formal Language Theory

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

NFAs continued, Closure Properties of Regular Languages

3 Regular expressions

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

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

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

1.3 Regular Expressions

CS 330 Formal Methods and Models

Lexical Analysis Finite Automate

CS375: Logic and Theory of Computing

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

1 From NFA to regular expression

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

Chapter 2 Finite Automata

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

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

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

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

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.

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

Context-Free Grammars and Languages

Normal Forms for Context-free Grammars

Coalgebra, Lecture 15: Equations for Deterministic Automata

State Minimization for DFAs

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

Closure Properties of Regular Languages

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

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

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

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

Formal Language and Automata Theory (CS21004)

Myhill-Nerode Theorem

Transcription:

Deprtment of Computer Science, Austrlin Ntionl University COMP2600 Forml Methods for Softwre Engineering Semester 2, 206 Assignment Automt, Lnguges, nd Computility Smple Solutions Finite Stte Automt nd Regulr Lnguges Prolem. Consider the following NFA A over {, }: strt s 0, s s 2 s 3 A is intended to recognise the lnguge L = {zα z {, }, α {} } of strings over the lphet {, } tht strt with either or, end with nd hve n ritrry numer of s etween the first nd the lst letter. (i) The following trnsition tle shows DFA A D tht is otined from A y the method of lzy suset construction: {s 0 } {s, s 2 } {s 2 } {s, s 2 } {s, s 2 } {s 3 } {s 2 } {s, s 2 } {s 3 } {s 3 } Assignment Automt, Lnguges, nd Computility

For the ske of convenience, let s define DFA A D tht is exctly like A D ut sttes re renmed. The following tle shows A D : The trnsition digrm of A D is s follows: q 4 q 4 q 4 q 0 q q 2 q q q 3 q 2 q q 3 q 3 q 4 q 4 strt q 0 q q 2 q, 3 q 4, (ii) The initil split differentites non-finl nd finl sttes: [ [ q 0, q, q 2, q 4 ], [ q 3 ] ] splits [ q 0, q, q 2, q 4 ]: [ [ q 0, q 4 ], [ q, q 2 ], [ q 3 ] ] (s well s ) splits [ q 0, q 4 ]: [ [ q 0 ], [ q 4 ], [ q, q 2 ], [ q 3 ] ] Neither nor splits the only remining non-singleton group [ q, q 2 ]. Every other group is singleton. Therefore, the lgorithm termintes. Sttes q nd q 2 re equivlent. (iii) A m is s follows Assignment Automt, Lnguges, nd Computility 2

strt q 0, q q, 3 q 4, (iv) Prove tht A m recognises L. Proof: We need to prove the following two sttements () for ll w, if δ (q 0, w) = q 3 then w L () for ll w, if w L then δ (q 0, w) = q 3 Ech of these sttements cn e reformulted s follows () for ll w, if δ (q 0, w) = q 3 then either w = α or w = α, where α {} () for ll α, if α {} then δ (q 0, α) = q 3 nd δ (q 0, α) = q 3 Below we prove ech of these sttements () w = 0 Hence, w = ɛ. δ (q 0, ɛ) = q 0. Stte q 0 is stte distinct from q 3, therefore the ntecedent of the conditionl sttement is flse. Therefore, the whole sttement is true. w = Hence, either w = or w =. In oth cses δ (q 0, w) = q. Stte q is stte distinct from q 3, therefore the ntecedent of the conditionl sttement is flse. Therefore, the whole sttement is true. w > Hence, w is of the form xαy, where x, y {, } nd α {, }. Assume δ (q 0, xαy) = q 3. By definition of δ the following holds δ (q 0, xαy) = δ (δ(q 0, x), αy) δ(q 0, x) is defined for x {, } s follows: δ(q 0, ) = q δ(q 0, ) = q Therefore, regrdless whether x is or, δ(q 0, x) = q. Hence, δ (q 0, xαy) = δ (q, αy) Assignment Automt, Lnguges, nd Computility 3

δ (q, αy) = δ(δ (q, α), y) = q 3 There is only one one-step trnsition tht leds to q 3. It is lelled. Therefore y must e nd δ (q, α) must e q. Consequently, it is sufficient to prove the following sttement: for ll α {, }, if δ (q, α) = q then α {} Lemm proves this sttement. () Assume α {}. We need to prove tht δ (q 0, α) = q 3 nd δ (q 0, α) = q 3. We consider δ (q 0, α) nd δ (q 0, α) seprtely: δ (q 0, α) = δ (δ(q 0, ), α) = δ (q, α) = δ(δ (q, α), ). δ (q 0, α) = δ (δ(q 0, ), α) = δ (q, α) = δ(δ (q, α), ). In oth cses we reched δ(δ (q, α), ). By Lemm 2, δ (q, α) = q. Therefore, δ(δ (q, α), ) = δ(q, ) = q 3 Lemm For ll β {, }, if δ (q, β) = q then β {} Proof: β = 0. β = ɛ nd β {}. β > 0. This mens tht β = xα where x {, } nd α {, }. We need to prove the following: if δ (q, xα) = q then xα {} Assume δ (q, xα) = q () By the definition of δ the following holds: δ (q, xα) = δ (δ(q, x), α) (2) For the ske of contrdiction ssume tht x =, then δ(q, x) = δ(q, ) = q 3. Then δ (q, xα) = δ (q 3, α) = q This mens tht from stte q 3 we rech stte q 3 fter reding α. But ll trnsitions from q 3 led to the sink stte q 4. Therefore δ (q 3, α) = q is impossile. We reched contrdiction. Therefore, x nd x cn only e equl to, since is the only remining symol of the lphet. Hence we cn rewrite δ (δ(q, x), α) in (2) s follows: δ (δ(q, ), α) Since δ(q, ) = q nd y ssumption () the following holds: δ (δ(q, ), α) = δ (q, α) = q The only one possile wy to rech q from q is trnsition δ(q, ) or sequence of them. Therefore α {}. Hence, xα {}. Assignment Automt, Lnguges, nd Computility 4

Lemm 2 For ll α {}, δ (q, α) = q Proof: Induction on the length of α. Bse cse: α = 0. δ (q, ɛ) = q Induction: α > 0. Induction hypothesis: δ (q, n ) = q, where n is string consisting of sequence of n s. We need to prove δ (q, n+ ) = q. δ (q, n+ ) = δ(δ (q, n ), ) By induction hypothesis δ (q, n ) = q, hence Prolem 2. Let L e the lnguge δ (q, n+ ) = δ(q, ) = q L = {w {0, } w {0} or w {} } Construct deterministic finite utomton tht ccepts ll strings tht re in L, nd rejects ll strings tht re not in L. 0 strt q 0 0 q q 3 0, 0 q 2 Prolem 4. Let L e the lnguge L = {w {0, } w hs in the third position from the right} Construct non-deterministic finite utomton tht ccepts ll strings tht re in L, nd rejects ll strings tht re not in L. 0, strt q 0 q 0, q 0, 2 q 3 Assignment Automt, Lnguges, nd Computility 5

Prolem 3. Let L e the lnguge L = {w {0, } ech lock of 5 consecutive symols contins t lest two 0 s} Construct deterministic finite utomton tht ccepts ll strings tht re in L, nd rejects ll strings tht re not in L. Explin in plin English the intuition ehind the constructed utomton. We first define non-miniml DFA A n tht recognizes L. The nme of stte conveys the informtion out the sequence of 0s nd s of the lst 4-symols lock tht the utomton hs processed. Thus, if the sequence of the lst four processed symols ws 000, the utomton is in stte nmed 000. Then δ(000, 0) = 000 nd δ(000, ) = 00. We define the only non-ccepting stte sink. Whenever the utomton is in stte nmed with sequence of four symols nd t lest three of these symols re s, the utomton goes to the rejecting stte sink on input. The only exception is the string, s discussed elow. Since the utomton hs to ccept ll strings of length smller thn 5, there re sttes for these strings. The only string contining four consecutive s tht is ccepted is the string of length 4. Stte is the ccepting stte corresponding to strings. If the first four s of string re followed y symol, the utomton performs trnsition to sink. The initil stte is nmed ɛ. It is the stte for the empty string. Thus the utomton is s follows: Assignment Automt, Lnguges, nd Computility 6

0 *ɛ 0 *0 00 0 * 0 *00 000 00 *0 00 0 *0 00 0 * 0 *000 0000 000 *00 000 00 *00 000 00 *0 00 0 *00 000 00 *0 00 0 *0 00 0 * 0 *0000 0000 000 *000 000 00 *000 000 00 *00 00 0 *000 000 00 *00 00 0 *00 00 0 *0 0 sink *000 0000 000 *00 000 00 *00 000 00 *0 00 sink *00 000 00 *0 00 sink *0 00 sink * sink sink sink sink sink A n cn e minimized. The equivlence clsses of sttes re s follows: [ɛ] [] [sink] [] [0] [0] [] [0] [0] [] [00, 000, 00, 0] [0, 00] [0, 00] [0, 00] [0, 00, 000, 00] [0, 00, 000, 00, 0000, 000, 000, 00] Among equivlent sttes, we keep the sttes tht re emphsized in old ove. This gives us the following miniml utomton A m : Assignment Automt, Lnguges, nd Computility 7

0 *ɛ 0000 * 00 * 00 * 0 *0000 0000 000 *000 00 00 *00 00 0 *00 00 0 *00 0000 0 *0 0 sink *00 0000 00 *0 00 sink *0 00 sink *0 0000 sink * sink sink sink sink sink Here is A m s trnsition digrm: strt ɛ 0 0 0 0 0, 0 0000 000 00 0 sink 0, 0 0 0 0 0 0 00 00 0 0 0 00 0 0 0 Assignment Automt, Lnguges, nd Computility 8

2 Grmmr Prolem 5. From the NFA A given in Prolem, derive right-liner grmmr using the lgorithm given in the lectures. The grmmr is s follows G = ({, }, {S 0, S, S 2, S 3 }, S 0, P ) where the set P consists of the following production rules S 0 S S 0 S 2 S 0 S 2 S S 2 S S 3 S 2 S S 2 S 2 S 2 S 3 S 3 ɛ Prolem 2.6. Consider the grmmr G = ({S, T }, {0, }, S, P ), where P consists of the following productions S 0S T 0 T T Show tht no string in the lnguge L(G) contins the sustring 0. Proof: Let α e sententil form derived using G. We show y induction on the length n of the derivtion of α tht α does not contin ny of the sustrings 0, S, S0, SS, T 0 or T S. Bse cse: n=. The possile derivtions of length of sententil forms for G re S 0S, S T, nd S 0. Neither 0S, nor T, nor 0 contin 0, S, S0, SS, T 0 or T S s sustring. Inductive cse: Let S α β e derivtion of β of length n +. By inductive hypothesis, α does not contin 0, S, S0, SS, T 0 or T S s sustring. If the lst derivtion step uses S 0S, since α does not contin S, SS or T S, the derivtion step cnnot introduce 0, S0 or T 0 in β. If the lst derivtion step uses S T, since α does not contin S0 or SS, the derivtion step cnnot introduce T 0 or T S in β. If the lst derivtion step uses S 0, since α does not contin S, SS or T S, the derivtion step cnnot introduce 0, S0 or T 0 in β. If the lst derivtion step uses T T, since α does not contin T 0 or T S, the derivtion step cnnot introduce T 0 or T S in β. If the lst derivtion step uses T, since α does not contin T 0 or T S, the derivtion step cnnot introduce 0 or S in β. Assignment Automt, Lnguges, nd Computility 9

3 Context Free Lnguges nd Pushdown Automt Prolem 3.6. Show tht the lnguge {uw u, w {, }, with u = w } is context free y exhiiting context free grmmr tht genertes it. A CFG grmmr tht genertes this lnguge is G = ({, }, {S, T, X}, S, P ), where P consists of the following productions: S T T XT X X Prolem 7. Consider the context-free grmmr G = ({S, A, B}, {,, c}, P, S), where P consists of the following productions S A A BA B S cs Construct PDA M tht ccepts L(G) y empty stck. Drw the prse three of G for the string, nd show the corresponding execution trce for M. The prse tree for the string : A A A S S B M = ({q 0, q, q 2 }, q 0, {q 2 }, {,, c}, {,, c, S, A, B, Z}, Z, δ) with δ defined s follows: δ(q 0, ɛ, Z) = {(q, SZ)} δ(q, ɛ, S) = {(q, A)} δ(q, ɛ, A) = {(q, BA), (q, )} δ(q, ɛ, B) = {(q, S), (q, cs)} δ(q,, ) = {(q, ɛ)} δ(q,, ) = {(q, ɛ)} δ(q, c, c) = {(q, ɛ)} δ(q, ɛ, Z) = {(q 2, ɛ)} Assignment Automt, Lnguges, nd Computility 0

The execution trce of M for the string is s follows: (q 0,, Z) (q,, SZ) (q,, AZ) (q,, AZ) (q,, BAZ) (q,, SAZ) (q,, SAZ) (q,, AAZ) (q,, AAZ) (q,, AZ) (q,, AZ) (q,, Z) (q, ɛ, Z) (q 2, ɛ, ɛ) 4 OPTIONAL: Turing Mchine nd Computility Prolem 8. Design 2-tpe Turing mchine ccepting the lnguge of ll strings over {0, } tht hve n equl numer of 0 s nd s. The first tpe contins the input, nd is scnned from left to right. The second tpe is used to keep trck of the difference etween the numer of 0 s nd s in the prt of the input seen so fr. M = ({q 0, q, q 2 }, q 0, {q 2 }, {Λ, 0,, #}, {0, }, Λ, δ) The mchine strts in stte q 0. If the input string is empty, it goes directly to ccepting stte q 2. If the input string is non-empty, the mchine writes # on the second tpe nd goes to stte q. for ech 0 on tpe, the mchine moves left on tpe 2 for ech on tpe, the mchine moves right on tpe 2 If fter the whole word is scnned on tpe, the hed of tpe 2 is on symol #, the mchine ccepts y going to ccepting stte q 2 ; otherwise it rejects. δ(q 0, [Λ, Λ]) = (q 2, (Λ, R), (Λ, R)) δ(q 0, [0, Λ]) = (q, (0, R), (#, L)) δ(q 0, [, Λ]) = (q, (, R), (#, R)) δ(q, [0, Λ]) = (q, (0, R), (Λ, L)) δ(q, [, Λ]) = (q, (, R), (Λ, R)) δ(q, [0, #]) = (q, (0, R), (#, L)) δ(q, [, #]) = (q, (, R), (#, R)) δ(q, [Λ, #]) = (q 2, (Λ, R), (#, R)) Prolem 9. For TM M, let E(M) denote the encoding of M. Consider the lnguge L = {E(M) M, when strted on lnk tpe eventully writes somewhere on the tpe}. (i) Show tht L is recursively enumerle. Assignment Automt, Lnguges, nd Computility

(ii) Show tht L is not recursive. Let s use nottion M from the lectures for E(M). (i) We cn construct TM M L tht recognizes L s follows. M L first trnsforms its input M to M, ɛ. M L simultes universl TM U except the following cses: s soon s U writes on the tpe, M L moves to n ccepting stte if U hlts in n ccepting stte, M L hlts in non-ccepting stte (ii) L lnkhlt = { M lnkhlt M lnkhlt (ɛ) hlts} is hlting lnguge. It is the lnguge of encodings of TMs tht hlt on the lnk tpe. L lnkhlt is not recursive (s ws proven on lectures). We show how to reduce L lnkhlt to L. Assume there is decider D such tht D( M ) hlts in n ccepting stte if nd only if M L nd otherwise hlts in non-ccepting stte. We show tht using D we cn construct D lnkhlt such tht D lnkhlt ( M lnkhlt ) hlts in n ccepting stte if nd only if M lnkhlt L lnkhlt nd otherwise hlts in non-ccepting stte. We define converter R such tht for ll mchines M lnkhlt such tht M lnkhlt L lnkhlt, it returns mchine M such tht M L. R constructs M from M lnkhlt in the following wy: All occurences of symol in the trnsitions of M lnkhlt (red nd written) re replced in M with #, where # is new symol not occuring in the tpe lphet of M. The finl sttes of M lnkhlt re not finl in M. Insted, for ech finl stte q f of M lnkhlt, for every tpe symol x, R dds trnsition δ(q f, x) = (q f,, R) to M. For ech stte q nd tpe symol x for which δ(q, x) is undefined in M lnkhlt (i.e. M lnkhlt hlts on x), R dds trnsition δ(q, x) = (q f,, R) to M. M lnkhlt eventully hlts when strted on lnk tpe if nd only if M = R(M lnkhlt ) eventully writes somewhere on the tpe. Then we cn tke D lnkhlt = D( R(M lnkhlt ) ). We know such decider does not exists ecuse L lnkhlt is not recursive. Assignment Automt, Lnguges, nd Computility 2