MIT6_042JS10_lec08_sol

MIT6_042JS10_lec08_sol - Massachusetts Institute of...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Massachusetts Institute of Technology 6.042J/18.062J, Spring ’10 : Mathematics for Computer Science February 19 Prof. Albert R. Meyer revised February 19, 2010, 1400 minutes Solutions to In-Class Problems Week 3, Fri. Problem 1. Let’s refer to a programming procedure (written in your favorite programming language —C++, or Java, or Python, . . . ) as a string procedure when it is applicable to data of type string and only returns values of type boolean . When a string procedure, P , applied to a string , s , returns True , we’ll say that P recognizes s . If R is the set of strings that P recognizes, we’ll call P a recognizer for R . (a) Describe how a recognizer would work for the set of strings containing only lower case Ro- man letter — a,b,...,z —such that each letter occurs twice in a row. For example, aaccaabbzz , is such a string, but abb , 00bb , AAbb , and a are not. (Even better, actually write a recognizer pro- cedure in your favorite programming language). Solution. All the standard programming languages have built-in operations for scanning the characters in a string. So simply write a procedure that checks an input string left to right, verify- ing that successive pairs of characters in the string are duplicated, lowercase roman characters. ACTUAL PROGRAM TBA A set of string s is called recognizable if there is a recognizer procedure for it. When you actually program a procedure, you have to type the program text into a computer system. This means that every procedure is described by some string of typed characters. If a string , s , is actually the typed description of some string procedure, let’s refer to that procedure as P s . You can think of P s as the result of compiling s . 1 In fact, it will be helpful to associate every string, s , with a procedure, P s ; we can do this by defining P s to be some fixed string procedure —it doesn’t matter which one —whenever s is not the typed description of an actual procedure that can be applied to string s. The result of this is that we have now defined a total function, f , mapping every string , s , to the set, f ( s ) , of string s recognized by P s . That is we have a total function, f : string → P ( string ) . (1) (b) Explain why the actual range of f is the set of all recognizable sets of strings. Creative Commons 2010, Prof. Albert R. Meyer . 1 The string, s , and the procedure, P s , have to be distinguished to avoid a type error: you can’t apply a string to string. For example, let s be the string that you wrote as your program to answer part ( a ). Applying s to a string argument, say oorrmm
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern