CS 3100 Models of Computation Fall 2011 This assignment is worth 8% of the total points for assignments 100 points total.

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

CS 3100 Models of Computation Fall 2011 Notes for L5. September 15, 2011

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

Chapter 4: Regular Expressions

CHAPTER TWO LANGUAGES. Dr Zalmiyah Zakaria

ITEC2620 Introduction to Data Structures

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

Welcome! CSC445 Models Of Computation Dr. Lutz Hamel Tyler 251

Lesson 18: Counting Problems

CS 314 Principles of Programming Languages. Lecture 3

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

Multiple Choice Questions

CMPSCI 250: Introduction to Computation. Lecture #28: Regular Expressions and Languages David Mix Barrington 2 April 2014

JNTUWORLD. Code No: R

Regexs with DFA and Parse Trees. CS230 Tutorial 11

Glynda, the good witch of the North

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory

Notes for Comp 454 Week 2

CS 314 Principles of Programming Languages

Compiler Construction

Assignment No.4 solution. Pumping Lemma Version I and II. Where m = n! (n-factorial) and n = 1, 2, 3

Problem Set 3 Due: 11:59 pm on Thursday, September 25

Lec-5-HW-1, TM basics

Data Compression Fundamentals

Chapter Seven: Regular Expressions

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

UNIT I PART A PART B

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

1. Which of the following regular expressions over {0, 1} denotes the set of all strings not containing 100 as a sub-string?

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

Program Construction and Data Structures Course 1DL201 at Uppsala University Autumn 2010 / Spring 2011 Homework 6: Data Compression

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

Finite Automata Part Three

CS52 - Assignment 10

Dr. D.M. Akbar Hussain

Tilings of the Sphere by Edge Congruent Pentagons

Strings, Languages, and Regular Expressions

Finite Automata Part Three

LING/C SC/PSYC 438/538. Lecture 20 Sandiway Fong

Automata Theory CS S-FR Final Review

Concepts Introduced in Chapter 3. Lexical Analysis. Lexical Analysis Terms. Attributes for Tokens

AUBER (Models of Computation, Languages and Automata) EXERCISES

XVIII Open Cup named after E.V. Pankratiev Stage 10, Grand Prix of Korea, Sunday, February 4, 2018

CMPSCI 250: Introduction to Computation. Lecture #36: State Elimination David Mix Barrington 23 April 2014

DVA337 HT17 - LECTURE 4. Languages and regular expressions

(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

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 2: Lexical Analysis 23 Jan 08

CS402 - Theory of Automata FAQs By

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES

Regular Expressions 1

Formal Languages. Grammar. Ryan Stansifer. Department of Computer Sciences Florida Institute of Technology Melbourne, Florida USA 32901

THE INTERNATIONAL JOURNAL OF SCIENCE & TECHNOLEDGE

CS195H Homework 1 Grid homotopies and free groups. Due: February 5, 2015, before class

Regular Expressions & Automata

KHALID PERVEZ (MBA+MCS) CHICHAWATNI

CMSC 330: Organization of Programming Languages. Context-Free Grammars Ambiguity

On the Parikh-de-Bruijn grid

Python Iterators. Stéphane Vialette. LIGM, Université Paris-Est Marne-la-Vallée. October 19, 2011

Bayesian Networks and Decision Graphs

Graph Theory. 1 Graphs and Subgraphs

1 On the role of DFA and NFA, IMPORTANT TERMINOLOGY

A language is a subset of the set of all strings over some alphabet. string: a sequence of symbols alphabet: a set of symbols

QUESTION BANK. Unit 1. Introduction to Finite Automata

Languages and Strings. Chapter 2

CMSC 132: Object-Oriented Programming II

Talen en Compilers. Johan Jeuring , period 2. January 17, Department of Information and Computing Sciences Utrecht University

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

I BSc(Computer Science)[ ] Semester - II Allied:DISCRETE MATHEMATICS - 207D Multiple Choice Questions.

CS308 Compiler Principles Lexical Analyzer Li Jiang

QTL Analysis with QGene Tutorial

Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

Zhizheng Zhang. Southeast University

Lexical Analysis. Lecture 2-4

The total symbol code budget

Solutions to Homework 10

Models of Computation II: Grammars and Pushdown Automata

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)

More Scripting and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

Multiple Choice Questions (20 questions * 6 points per question = 120 points)

Midterm 1 Review Fall 2017 September 8, Functions. Instructions

Weighted Finite Automatas using Spectral Methods for Computer Vision

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

Basic Syntax - First Program 1

CpSc 421 Final Solutions

Supplemental Materials: Grammars, Parsing, and Expressions. Topics. Grammars 10/11/2017. CS2: Data Structures and Algorithms Colorado State University

CS103 Handout 16 Winter February 15, 2013 Problem Set 6

Formal Languages and Compilers Lecture VI: Lexical Analysis

Florida State University Libraries

CS 341 Homework 1 Basic Techniques

Finite Automata Part Three

CS375: Logic and Theory of Computing

Parsing. Top-Down Parsing. Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 19

Syntax and Parsing COMS W4115. Prof. Stephen A. Edwards Fall 2004 Columbia University Department of Computer Science

Variable and Data Type I

Study on LZW algorithm for Embedded Instruction Memory.

MA/CSSE 474. Today's Agenda

Actually talking about Turing machines this time

CS2 Practical 2 CS2Ah

CMSC330 Fall 2017 Final Exam

Turing Machine Languages

Transcription:

CS 3100 Models of Computation Fall 2011 This assignment is worth 8% of the total points for assignments 100 points total September 7, 2011 Assignment 3, Posted on: 9/6 Due: 9/15 Thursday 11:59pm 1. (20 points) Write a Python function recognizes(d, N) that returns all strings of length 0 i N recognized by the given DFA D. Assume that N 0. Test it out on the the DFA that recognizes all strings ending in 0101 that you constructed in Assignment 2 for N = 5. Submit the function in a file recognizes.py as well as an ASCII record of your testing session as file recognizes_tests.out. # The solution is below. from math import * from lang import * from dfa import * def nthnumeric(n): """Assume that Sigma is {a,b}. Produce the Nth string in numeric order, where N >= 0. Idea : Given N, get b = floor(log_2(n+1)) - need that many places; what to fill in the places is the binary code for N - (2^b - 1) with 0 as a and 1 as b. """ if(n==0): return else: width = floor(log(n+1, 2)) tofill = int(n - pow(2, width) + 1) relevant_binstr = bin(tofill)[2::] # strip the 0b leading string len_to_makeup = width - len(relevant_binstr) return "a"*len_to_makeup + homos(relevant_binstr, lambda x: b if x== 1 else a ) def listall(d, frm, S): """Search in the nthnumeric order from frm back through 0, exiting at -1. frm guaranteed to be >= 0. S guaranteed to be called

with set({}). """ if (frm == -1): return S else: nth_str = nthnumeric(frm) if accepts(d, D["q0"], nth_str): return listall(d, frm-1, S { nth_str }) else: return listall(d, frm-1, S) def lang_lt_n(d, N): """Given a DFA D, find all strings of length <= N accepted by D. Strings listed in numeric order are: "", a, b, aa, ab, ba, bb, aaa, aab,..., bba, bbb, aaaa,... In this listing, note that the ordinal position of "" is 0, of a is 1, etc. Now all strings of length <= N are obtained by searching for strings in the nthnumeric enumeration from 2^(N+1) - 2. For instance, all strings of length 3 or less are obtained by looking from 14 downwards in the nthnumeric listing. """ ordinal_from = pow(2, N+1) - 2 return listall(d, ordinal_from, set({})) >>> DFA1 { Q : { S1, S0 }, q0 : S0, F : { S1 }, Sigma : { a, b }, Delta : {( S0, a ): S0, ( S1 >>> lang_lt_n(dfa1,4) lang_lt_n(dfa1,3) { abb, ab, bab, bb, aab, b, bbb } >>> DFA1.update( { F : { S0, S1 }}) >>> DFA1 DFA1 { Q : { S1, S0 }, q0 : S0, F : { S1, S0 }, Delta : {( S0, a ): S0, ( S1, a ): S0, >>> lang_lt_n(dfa1, 4) lang_lt_n(dfa1, 4) { baba, abab, aa, babb, abbb, abba, bbab, aaba, aabb,, abb, aaaa, abaa, >>> 2

2. (40 points) Define a DFA that accepts all strings over {0,1} such that every block of four consecutive positions contains at least two 0s. (This means: If there are four consecutive positions, Then in those four positions, there must be at least two 0s.) Call this language L 00. Build this DFA using the mk_dfa call (we will supply you a working mk_dfa for this assignment). Next, use dot_dfa and print this DFA out. Submit the PDF drawing of this DFA, as file L00.pdf. Test this DFA on 12 strings including two (2) strings of length < 5, five (5) strings that are accepted and of length 6 and five (5) strings that are rejected and of length 6. Submit an ASCII record of your testing session as file L00_tests.out. Here is how you do your work! S -0-> S0 S -1-> S1 S0-0-> S00 S0-1-> S01 S1-0-> S10 S1-1-> S11 S00-0-> S000 S00-1-> S001 S01-0-> S010 S01-1-> S011 S10-0-> S100 S10-1-> S101 S11-0-> S110 S11-1-> S111 S000-0-> S0000 S000-1-> S0001 S001-0-> S0010 S001-1-> S0011 S010-0-> S0100 S010-1-> S0101 S011-0-> S0110 S011-1-> BH 3

S100-0-> S1000 S100-1-> S1001 S101-0-> S1010 S101-1-> BH S110-0-> S1100 S110-1-> BH S0000-0-> S0000 S0001-1-> S0011 S0010 S0011 S0100 S0101 S0110 S1000 S1001 S1010 S1100 Once they get this trick, they fan finish up! 3. (20 points) Draw a DFA for Question 3 of notes5.pdf. Next, enter this DFA and generate a PDF drawing for it. Argue why this DFA works (in about 3-4 sentences), and also use function accepts to demonstrate that indeed it works on five (5) strings in the language and five (5) strings not in the language. Submit your PDF as notes5_qn3_dfa.pdf and your writeup as notes5_qn3_dfa.out. This question asks: Define a DFA that accepts all strings over {0,1} fed LSB-first such that these strings when interpreted according to standard binary conventions defines numbers which are evenly divisible by 4

3. This is built by solving a recurrence. N, 2^n 0> N, 2^(n+1) N, 2^n 1> N + 2^n, 2^(n+1) N%3, 2^n 1> (N + 2^n)%3, 2^(n+1) We need to remember only (2^n)%3 N%3, (2^n)%3 1> (N%3 + (2^n)%3)%3, (2 * (2^n)%3)%3 (0, 1) 0> (0, 2) (0, 1) 1> (1, 2) (0, 2) 0> (0, 1) (0, 2) 1> (2, 1) (1, 2) 0> (1, 1) (1, 2) 1> (0, 1) (2, 1) 0> (2, 2) (2, 1) 1> (0, 2) etc. If we did MSB-first, the recurrence is easier N -> 2*N + b N%3 -> ((2 * N%3)%3 + b)%3 4. (20 points) Draw a DFA for Question 5 of notes5.pdf. Next, enter this DFA and generate a PDF drawing for it, and submit it. Argue why this DFA works (in about 3-4 sentences), and also use function 5

accepts to demonstrate that indeed it works on five (5) strings in the language and five (5) strings not in the language. Submit your PDF as notes5_qn5_dfa.pdf and your writeup as notes5_qn5_dfa.out. This question asks: Define a DFA for the language defined by the concatenation of the languages denoted by DFA of the two figures in those notes. Basically it is the concatenation of all strings ending in 1 and all equal 0-1 changes. This is all strings containing a 1. Why? Because if there is no 1, then we can t be a concat. If there is a 1, then there is a last 1. Pick that: the rest of the strings have equal changes. Now draw the DFA and solve easily! 6