DOC PREVIEW
MIT 6 01 - Assignment for Week 2

This preview shows page 1-2-3-4-5 out of 15 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

6 01 Spring Semester 2008 Assignment for Week 2 Issued Tuesday Feb 12 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6 01 Introduction to EECS I Spring Semester 2008 Assignment for Week 2 Issued Tuesday Feb 12 This week s work gives you practice with higher order procedures i e procedures that manipulate other procedures Tuesday s lecture the software lab and the on line tutor problems all explore Python s support for functional programming as a means of capturing commons patterns The design lab extends your work from last week by applying higher order procedures to the design of robot behaviors Overview of this week s work to do in software lab You ve seen in homework how to represent sets as lists In software lab you ll look at a different representation of sets that uses higher order procedures and also practice the material on higher order procedures that was presented in lecture homework to do before the start of your design lab on Feb 14 or 15 Read the class notes and review the lecture handout Do the first half of the on line tutor problems for week 1 the part that is due before design lab Read the entire description of the design lab so that you will be ready to work on it when you get to lab to do in design lab Just as last week the design lab will begin with a nanoquiz The quiz may include material from the class notes from the on line tutor problems due that day or from the design lab description The quiz will be given in the first 15 minutes of lab and if you miss it we will not give you time to make it up before starting the lab so please don t be late After the quiz you should work with your same partner from last week We ll change partners in about two weeks This week s lab will extend the work on behaviors that you did last week to cover non deterministic behaviors and using the PCAP framework to design behaviors homework due at the beginning of your next design lab on Feb 21 or 22 Additional problems to do using the on line tutor Lab writeup to hand in In general written homework should be handed in at the beginning of the following week s software lab But next Tuesday February 19 is an MIT virtual Monday so there will be no lecture So for next week homework should be handed in at the beginning of the design lab 6 01 Spring Semester 2008 Assignment for Week 2 Issued Tuesday Feb 12 2 Software Lab for Week 2 Reminder On lab laptops or Athena terminals you should start by executing athrun 6 01 update in a Unix terminal window This creates the Desktop 6 01 lab2 directory that will contain the code files mentioned in this handout If you are running from an Athena terminal you should also execute add f 6 01 to get the appropriate versions of Idle and Python If you are using your own laptop you should download the lab code files from the course Web site linked from the Calendar page Today s code file is ps2 software lab py Lecture review on higher order procedures The code file for today s lab contains several of the higher order procedures shown in lecture including summation deriv and newtonsMethod Here s what s in the file so you can have it in front of you as you work on these exercises today def summation low high f next s 0 x low while x high s s f x x next x return s def fixedPoint f firstGuess def close g1 g2 return abs g1 g2 0001 guess firstGuess next f guess while not close guess next guess next next f guess return next def deriv f dx 0 0001 def df x return f x dx f x dx return df def newtonTransform f def g x return x f x deriv f x return g def newtonTransform f return lambda x x f x deriv f x 6 01 Spring Semester 2008 Assignment for Week 2 Issued Tuesday Feb 12 3 def newtonsMethod f firstGuess return fixedPoint newtonTransform f firstGuess computing square roots by Newton s method def newtonSqrt x return newtonsMethod lambda y y 2 x 1 0 Question 1 Define a simple procedure called inc that takes a number as input and returns that number plus 1 and a simple procedure square that takes a numeric input and returns the square What will Python print at each step when you evaluate the following sequence inc 7 How about if you evaluate inc What if you evaluate def compose f g return lambda x f g x compose inc inc Then compose inc inc 3 And finally a compose inc inc a 4 b compose inc square b 5 c compose square inc c 5 Predict what the result will be at the end of each line and then try it and see if you were correct Check with a staff member if the results are puzzling Question 2 Show how to use the summation procedure from lecture to compute 13 23 33 1003 14 34 54 994 Question 3 Show how to use the newtonsMethod procedure from lecture to solve the equation y4 2y2 x for y with x 1 Try it for other positive values of x Hint Compare the use of newtonsMethod in lecture for computing square roots 6 01 Spring Semester 2008 Assignment for Week 2 Issued Tuesday Feb 12 4 Representing sets as procedures In homework last week you explored representing sets using Python lists Another way to represent a set is as a procedure that takes a value as input and returns True if the value is in the set and False otherwise For example def s1 x return x in this is my set of strings would represent the set of six strings That may seem hardly different from the list representation you worked with for homework but notice that we could also have something like def s2 x return x 99 and this would represent the set of all numbers greater than 99 an infinite set Question 4 Define some sets both finite and infinite How can you test your definitions Question 5 For homework last week you implemented the setUnion and setIntersection operations in terms of lists In terms of the PCAP framework these are means of combination for sets Define setUnion and setIntersection for sets represented as procedures and create some tests to show that they work They take two sets as input and return a set Hint 1 caveat Remember that the results of these operations must be sets in the same representation as the input sets That is the results produced by the means of combination should be things that themselves can be combined For example if s1 s2 and s3 are sets then you ought to be able to compute setUnion s1 setIntersection s3 s4 Hint 2 You can use Python s and and or …


View Full Document

MIT 6 01 - Assignment for Week 2

Documents in this Course
Week 1

Week 1

3 pages

Op-Amps

Op-Amps

8 pages

Op-Amps

Op-Amps

6 pages

Syllabus

Syllabus

14 pages

Planning

Planning

14 pages

Load more
Download Assignment for Week 2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Assignment for Week 2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Assignment for Week 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?