homework for intro comp sci, part 1 home page
submit homework

hw33:  ifelse; forever; patches
due at your first class after Wednesday, 2021-01-20 8:00 a.m.

expected to take 0.3?? – 0.?? hours. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 3 min.) Compare your answers on hw32#2 ("turtle race") with answers that will be contributed on Piazza after period 3 on Tuesday.

For people in periods 6 and 7 who start their homework promptly, postponing this review is fine, since the current homework has little dependency on the previous homework. But remember to do the review, since it typically provides good value: lots of learning in little time.


1.  Understand (estimated time: 4 min.)  …this code's arithmetic to implement the maxSwerve button. Questions? Ask on Piazza!


2.  asymmetric meandering (optional extra education; estimated time: 8 min.)  Especially if the sample code in the previous task improved your grasp of the cooperation between the maxSwerve slider and the arithmetic of using random, you might want to exercise your new understanding, so you own it. Students suggested creating two sliders, so that the maxRightSwerve could differ from the maxLeftSwerve.

Program the easy way: answer the structuring questions for programming with random.


Concepts to use: (estimated time to read: 2 min.)


3.  conditional appearance (estimated time: 11 min.) 

  1. Record the syntax of ifelse in the page in your notebook where you are accumulating NetLogo commands (the page you were asked to start in the early NetLogo homework). Understand the examples.

  2. Pick an interesting pair of color and shape, to be adopted by all turtles when they are in the swath. (Wondering "What swath?" Read the "Concepts to use".)

  3. Pick a different color/shape pair, for turtles outside the swath.

  4. Augment the meander procedure to set a turtle's color and shape…

    If you are flummoxed on where to start, right-click on a turtle and ask to "inspect" it. Which property determines the desired color/shape?

    It may also help to review the operators from the table of precedences that you bookmarked. Which operators will help?

  5. Test your work.

  6. optional extra education: Generalize your procedure to work for worlds of arbitrary configurations. That is, use the global variables that NetLogo automatically sets to represent the world's dimensions. You can see their names via the Interface tab's "Settings…" button.

    It is easier to notice errors in computing "the middle third of the world" when the world is very small.


4.  less clicking, more meandering (estimated time: 6 min.) 

  1. Record the actions of a forever button in the page in your notebook where you are accumulating NetLogo commands.

  2. Automate the model to obviate the user's having to click the meander button repeatedly to keep it running.


5.  patches (estimated time: 5 min.)  Watch Mr. Brooks's video 16, on patches.


6.  Submit the file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. If you did the optional programming, add that information to the comments, to aid my understanding of the times reported. (estimated time: 1 min.)


hw32:  random
due at your first class after Friday, 2021-01-15 8:00 a.m.

expected to take 0.6 – 0.8 hours for the required parts Record the time at which you start this assignment.


0.  period 6: Watch the rest of the lesson. (estimated time: ?? min.)  …here, starting where period 6's discussion ended, around 35:40 into the recording. Scroll simultaneously through the chat, starting at the corresponding post, which is marked as10:57 am. At that point in the lesson, we were aiming to program turtles to meander, but the
     rt random 20
command was unsatisfactory, since the turtles meandered only to their right sides.


1.  review previous hw (estimated time: 5 min.) Compare your answers on hw31 ("independent agents & precedence") with answers that have been posted in Piazza@380, Piazza@381, and your period's thread on "hw31#5 problems".


2.  turtle race (estimated time: 12 min.) 

  1. Download the turtle-racing skeletal program that we played with in class.

  2. Understand all the in the skeleton's Code tab, with the help of the NetLogo Dictionary. Add new commands to the reference sheet in your notebook.

    Understanding the setup routine requires understanding the resize-world command.

    Pay particular attention to the difference between
         cro / create-ordered-turtles
    versus
         crt / create-turtles
    This distinction will contribute to future programming.

    Mr. Brooks's videos mentioned the list of commands that can be part of a turtle-creating command like cro, but the official word is in the NetLogo Dictionary.

  3. Race fans demand turtles with panache. Pick some nice shape from
         Tools → Turtle Shapes Editor

  4. Add a procedure to make each turtle move forward by a number of steps that is randomly chosen from the set {0,1,2}.

  5. Make a button run your procedure.


3.  add excitement (optional extra education; estimated time: 10 min.)  Make a different procedure to make each turtle move a randomly-chosen number of half-steps, from ½ step backwards, up to 1½ steps forward.

How are you going to test this?! Checking results is a serious challenge in a program that includes randomness.

have each turtle show its xcor after its move

Although incremental development probably requires starting there, this approach requires mental arithmetic, with fractions. <shudder> The let command can help, at the cost of some independent learning. Teachers are overrated.


4.  turtles meander (estimated time: 12 min.)  The sessions talked about three structuring questions for writing programs that use random. This task asks you to take those questions out for a spin on a variation of the problem we did in class. Subsequent programming requires more complicated versions, so thinking carefully about this relatively simple version should aid using the questions for more complicated problems.

  1. Download the code that we started with.

  2. The aim of the next steps is to modify the code so that each turtle turns through an angle whose measurement is randomly selected from the range [–15°, +15°], and then steps forward.

  3. For the aim given above, answer the structuring questions for programming with random. Write the questions and your answers in your notebook, so that the thinking winds up in your notes and your head.

  4. Put the questions and your answers into comments in your code.

    Text is more perspicuous when lines fit in the window, rather than requiring a reader to use the horizontal scroll bar. But for lots of writers, the semicolons that the mark the beginning of the comments interfere with the revising that is necessary to communicate clearly. So I enter the text without semicolons, revise it, and have NetLogo put the semicolon in at the end, using
         control+;
    on a selected block of text.

  5. Use your answers to the questions to modify the code. As always in NetLogo programming, use the minimum number of parentheses, by recalling where primitives like random fit in NetLogo's list of precedences.

  6. Test your code. In general, checking computer programs is easier with less data. So I recommend reducing the number of turtles in initial runs.


5.  Vary the swerves. (estimated time: 10 min.)  I picked the range [–15°, +15°] arbitrarily, and the results look a tad tame. Allow the user to control the magnitude of the range from which the turns are chosen, to make it easy find a swerve size that they find aesthetically appealing.

This task is intentionally specified loosely. Most of the work in this task is likely to be in deciding on a reasonable approach, rather than in programming it. So don't skimp on your design thinking and/or consulting with others. As programmers say, "Hours of debugging can save minutes of planning."


6.  Submit the files for this assignment to the homework server, each in the appropriate one of the two slots for this assignment. In "Comments to teacher" for the "meander" program, tell me how long this assignment took, total, in decimal hours rounded to the nearest tenth. If you did the optional programming, add that information to the comments, to aid my understanding of the times reported. (estimated time: 1 min.)


hw31:  independent agents & precedence
due at your first class after Monday, 2021-01-11 8:00 a.m.

expected to take 0.5 – 0.7 hours for the required parts. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 4 min.) Compare your answers on hw30 ("sliders & models") with my answers in Piazza@371.


1.  coding style for buttons (estimated time: 4 min. to read several times)  Buttons should contain only a single procedure call, and only in observer context. Although Mr. Brooks puts multiple NetLogo commands in his initial examples, in this class we adhere to two stricter conventions:


2.  period 3, period 6: watch the recording of the rest of the class. The recording is here.

3.  square dance (estimated time: 9 min.)  We have been writing programs to govern a single turtle, but that is not emergence-style thinking. We aim to create simulations, by writing rules for a large number of independent agents to follow. Take a step in that direction by incrementally developing a program in which four turtles draw this:
square dance

Start by having your program create 4 turtles. Is that too little to test? Really? Ok, which way are they facing? That is, do you already know what cro does, or are you willing to learn? Learning takes effort and time, but it is easier and faster than programming in ignorance.

Additional requirements follow, but these are not steps in incremental development. That thinking is up to you. Keep asking yourself "What is the least I can do that I can test?" And then "Wait. Can I do less?"

Wait. That is NOT the sound of keys clicking, is it? Do you remember the pain of programming the saltshaker while trying to visualize it in your head? It helped me to move a physical turtle, drawing the result on paper, and writing down the steps in English shorthand, without involving the complication of NetLogo. The result in one class looked like this:
saltshaker sketch
Mr. Myloklyk calls scrap paper "Keys to Success", and he is not kidding.

I found four helpful "turtles" on my desk:
ducks and KtS
Where are yours?


4.  bookmark the precedence documentation (estimated time: 2 min.)  In your browser, bookmark the "Commands and reporters" section of NetLogo's Programming Guide. As you do the problems below, refer to the table in this section to justify your answers. Doing so will help you learn these rules.


5.  Exercise the precedence rules. (estimated time: 5 min.)  Copy the minimize-parens procedure below into the code tab. Then remove as many parentheses as possible from the second, repeated line in each pair, while leaving NetLogo to do the same operations, in the same order, arriving at the same answer.

to minimize-parens
  ;part A 
  show (abs( 20 -(4 - 3) mod (10 / 2) - (7 * 2)))
  show (abs( 20 -(4 - 3) mod (10 / 2) - (7 * 2)))  ;simplify this line

  ;part B
  show ((3 ^ 4) ^ 1) / 2 - ((3 - (- min-pycor)) - 5)
  show ((3 ^ 4) ^ 1) / 2 - ((3 - (- min-pycor)) - 5)  ;simplify this line
end


6.  DIY (estimated time: 5 min.)  Create an expression like the ones in the previous problem to serve as practice for classmates. Don't be boring; use operators besides the five that would occur to an eighth-grader. Post your problem on the Piazza thread for this homework assignment that is dedicated to your class: period 1 period 2 period 3 period 6 period 7


7.  Do someone else's. (estimated time: 5 min.)  From your class's set of student-generated problems, add someone else's problem to your minimize-parens procedure and solve it. Post your answer as a response to the original statement of the problem.


8.  isosceles saltshaker (optional extra education; estimated time: 15–30 min.)  Want a real use for arithmetic? Think the equilateral triangles in the saltshaker are a bit tame?

Add a slider so that the user can specify the apex angle, to be used for both the top and bottom of the shaker. Use the two already-programmed sliders to specify the congruent sides of the top and bottom triangles, respectively. Write code to calculate the length of the base.

Did you reach for a few Keys to Success immediately? I did, and it took me four versions. But maybe you would prefer to carefully program something that is wrong, first?

optional hints and spoilers:


9.  Submit the file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. If you did the optional programming, add that information to the comments, to aid my understanding of the times reported. (estimated time: 1 min.)


Lists of data (optional extra education)  NetLogo uses brackets to make lists. Aparna N.-K. and Rui L. used two-element lists in NetLogo to make…
fractal.


hw30:  sliders & models
due at your first class after Thursday, 2021-01-07 8:00 a.m.

expected to take 0.7 – 0.9 hours for the required parts. Record the time at which you start this assignment.


0.  slider widgets (estimated time: 8 min. to watch; 7 min. for exercises)  Watch Mr. Brooks's videos 6 and 7, on NetLogo slider widgets. As usual, do the exercises (for video 6A), and compare your answers to his (in video 6B).


1.  adjustable saltshaker (estimated time: 11 min.)  The following steps guide you through incrementally modifying the code from class, adding sliders that will allow the user to vary the sizes of the top and bottom triangles.

  1. Download this solution to hw28's saltshaker..

  2. Find the places in the code that specify the sizes of the top and bottom triangles. You were going to change one a time, even without this suggestion, right?

  3. Create a slider called topSize that will allow a user to specify the size of the top triangle within reasonable limits.

    The slider creates a global variable that can be used in any place in your code that a number is required. Read that sentence again. In past semesters, many people erroneously thought they had to pass the value of the slider as an argument. But that is awkward and unnecessary. Rather, the value of the variable can be retrieved "in any place in your code", which explains the name global variable.

    NetLogo's semantics for retrieving a value for a variable mimic Racket's steps.

  4. Modify the code to use the value from the slider to govern the size of the top triangle.

  5. Test that before proceeding, in the spirit of incremental development.

  6. Follow similar steps to allow a user to control the size of the bottom triangle.


2.  optional disco shaker (optional extra education; estimated time: 10 min.)  Picky clients request a slider called tilt that will allow them to tilt the shaker to any angle in the range [-180, 180), in increments of 5°, so that the shaker can appear in any orientation.


3.  Learn from the Models Library. (estimated time: 20 min.)  Take an in-depth look at a model from the NetLogo Models Library. Choose one that implements a simulation for which you can write a falsifiable hypothesis. This precludes the entries I have seen from the Art, Games, and Mathematics libraries.

It will help to choose a model in an area that interests you, but spend no more than 3 minutes choosing one for this assignment.

  1. Read the model's Info tab.

  2. Play with the model a little, in its Interface tab.

  3. Spend a few minutes skimming the code — especially its comments — aiming to gain insight into how much code is required for a model of this level of complexity.

    If you are curious about any of the NetLogo statements, the NetLogo Dictionary can probably help. But do not get too sucked into learning the NetLogo. This assignment asks you to learn about a model more than about NetLogo.

  4. Start a word-processed document in accordance with the standard instructions. After the heading, name the model you worked with, and provide a citation for the model that would be appropriate for a paper based on the model.

  5. In your document, write a falsifiable hypothesis that the simulation could inform you about. That is, the simulation should provide a tentative conclusion about the real world that a researcher could check.


4.  Submit the two files for this assignment (.nlogo and .pdf) to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. If you did the optional programming, add that information to the comments, to aid my understanding of the times reported. (estimated time: 1 min.)


hw29:  checking simulations v1
due at your first class after Wednesday, 2020-12-23 8:00 a.m.

expected to take 0.8 – 1.0 hours. Record the time at which you start this assignment.


Concepts to use:


0.  pd6: watch the remainder of the lesson (estimated time: 13 min.)  from this recording starting at 46:21, which is about where period 6 ended.


1.  Start a new word-processing document (estimated time: 1 min.)  …in accordance with the standard instructions.


2.  Get used to disappointment. (estimated time: 7 min.)  List two elements of the traffic simulation that are unrealistic. Then reconcile these shortcomings with George Box's assertion that "All models are wrong, but some are useful." Write two to four sentences on how the traffic simulation could be considered useful even by a person who is aware of the shortcomings.

optional education: "Get used to disappointment" is a classic line from a staged sword fight in a movie that nearly everyone likes. It is quoted here for the reason that one often uses quotations: it communicates better than I can. Or, as another of my betters put it, "he wrapped himself in quotations — as a beggar would enfold himself in the purple of emperors".


3.  Define sensitivity analysis (estimated time: 12 min.)  …in preparation for using that understanding in the next task. Cite your sources, preferably by including a link.

The class notes now hold the best explanation I know of, thanks to YuLin.

Crowdsourcing helps in Piazza@332. If you find a source that is clear enough to recommend to others, contribute it there. If you are having trouble finding a good source, check there.

The Wikipedia article disappointed me, at least for the amount I could stand to read. It lacks the introduction that helps in so many articles, and instead dives too deep into detail too fast. If you want to give back to Wikipedia, you could improve the introduction to this article. perhaps based on the introduction by Iman, Campbell, and Helton.


4.  What constitutes a check? (estimated time: 10 min.)  Read the paragraphs recommended by Derek in Piazza@326_f1.


5.  Apply this learning (estimated time: 10 min.)  …by describing a two to four checks that would be practical to perform for the traffic simulation if checking it were your full-time job for about a week. Include examples for both of the "two broad types" discussed in the reading.


6.  Why are zombies apocalypses bad (estimated time: 3 min.)  …for final projects in this course, given that you will be asked to describe how to check the simulation you write? One or two sentences should suffice to answer this.


7.  Submit a .pdf of your writing to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


hw28:  checking simulations & buttons
due at your first class after Monday, 2020-12-21 8:00 a.m.

expected to take 0.7 – 0.9 hours. Record the time at which you start this assignment.


0.  If you have questions about grades from marking period 2 (estimated time: 4 min.)  …read these notes. The reading is optional for people who can simply accept that grading. But students have a legitimate interest in grading, which is why I spent the time to write the notes.

To align The Points with productive practices, this homework assignment is graded. I have recorded a 100% initial grade for everyone. If a student's subsequent communication indicates that they failed to do the reading, their grade on this homework will be reassessed.


Concepts to use:


1.  Your turn to check. (estimated time: 15 min.)  Hw26#3 asked you to read about checking a simulation of peat fires. In preparation for similar thinking on the final project…

  1. Start a new word-processing document in accordance with the standard instructions.

  2. In the article, re-read the paragraph that starts by quoting George Box: "All models are wrong, but some are useful." For a particular simulation model, a researcher must ask "Is this model correct enough to be useful?"

  3. Write two or three sentences on how one might check the traffic simulation we discussed. It will help to load it from NetLogo's File | Models Library | Sample Models | Social Science | Traffic Basic. For a legitmate check, you are required to provide an expected outcome. This can take serious thought, as it did when we where check the "sphere" hypothesis for the shape of the NetLogo world.

  4. For the final project, people routinely want to simulate a Zombie Apocalypse. Write another two or three sentences on checking one of those.

  5. Create a .pdf from your word-processed document. Of course.


2.  buttons (estimated time: 5 min. to watch; 7 min. for exercises) Watch Mr. Brooks's video 5A, on using NetLogo button widgets. Do his exercises 1–4, and compare your answers to his, in video 5B.


3.  Download (estimated time: 2 min.)  this saltshaker model from period 7. Unlike most download links on this page, this one lacks the download attribute that causes most browsers to download the file on a left-click. So users of most browsers will right-click on the link and select some "Save As" command from the resulting context menu.

It does NOT suffice to copy code to NetLogo from a web page. See Piazza@329 for a helpful discussion of this issue.

Firefox FTW! It does what I want on a single left-click. Plus, Mozilla claims they are not selling your data.

If you seek help with this operation — say, on Piazza — be sure to tell would-be helpers…


4.  Resolve questions (estimated time: 4 min.)  …about this code that remain from class.

If you violated NTTSTT by writing separate routines for the different sizes of triangles and/or sides, understand how to avoid that. That is a common error, but a noxious one nonetheless.


5.  Add two buttons (estimated time: 6 min.)  …to the model you downloaded, to make it easy for a user to run the and procedures.


6.  Submit the two files for this assignment (.pdf and .nlogo) to the corresponding slots on the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


seasonal refrigerator art (optional extra education)  People in period 7 found the salt shaker to be "pathetic". ("This you call a salt shaker?" —Monk Ariel)

These critics assert that the assignment should have requested making the turtle draw a secular holiday tree, like…
      secular holiday tree

Actual education: revising the salt shaker program caused me to re-evaluate the distribution of actions among the modules. For example, I now doubt that
     set color green
belongs in setup.

Colors in Netlogo include gray, which looks kinda silver-y

Geometers know that the points of a star inscribed in a regular pentagon have a measure of 36°. For some of us, the pain of writing draw-side has burned the words "external angle" into our consciousness.

Furthermore, in the circumscribing pentagon, the ratio of the lengths of a diagonal to a side is an irrational number so cool that it has its own name ("the golden ratio") and its own Greek letter, phi:
     \( \phi = \dfrac{1 + \sqrt{5}}{2} \)
as shown in this diagram. So one can use phi to calculate the length of a side from the length of a diagonal.

Winter Recess will be soon.

estimated time: 20 min. if you develop incrementally and stop when it is close enough, accepting reasonable compromises, unlike me


hw27:  parameters
due at your first class after Thursday, 2020-12-17 8:00 a.m.

expected to take 0.4 – 0.6 hours. Record the time at which you start this assignment.


Concepts to use:


0.  Read about to (estimated time: 2 min.)  …in the NetLogo Dictionary. One easy way: type
     to
in the Command Center or Code tab, select it, and then press F1.


1.  Pass an argument to a parameter. (estimated time: 4 min.)  The manual uses the language
     [input1]
where the normal language among programmers might be
     a sequence of parameters surrounded by square brackets.
Sigh. But it is still a great, relatively-easy-to-read manual.

Copy the manual's circle procedure to your Code tab. Invoke circle from the Command Center.

You know how to pass an argument to the radius parameter, since…

Make some circles.


2.  Download starter code (estimated time: 7 min.)  via this link. Then start NetLogo and use
     File → Open
to see…

Run this model and understand how it works. That is always the first step on modifying code that someone gives you and that they claim works.


3.  searching for a shaker of salt (estimated time:15 min.)  The following steps guide you through incremental development of a procedure to draw a salt shaker, whose top is smaller than its base, like…
      salt shaker

  1. Parameterize the draw-side, procedure by adding a [sideSize] parameter, so draw-side can draw sides of various sizes.

  2. Test that, as part of incremental development.

  3. Create the ability to make triangles of varying size.

  4. Test that, of course. To do so, use NetLogo's speed slider (at the top of the Interface window) to reduce the speed to 1/8. That is a powerful debugging technique: spend a few seconds watching, save tens of minutes debugging.

  5. Write a procedure to draw an upright salt shaker using your helper functions. Pick a reasonable size for the top triangle and the bottom triangle.


4.  Submit the file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


hw26:  moving & procedures / checking
due at your first class after Tuesday, 2020-12-15 8:00 a.m.

expected to take 0.8 – 1 hours. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 7 min.) Compare your answers on hw25 ("Scientific thinking, v1") with answers that will be contributed on Piazza after that assignment is due for period 3. That is the class after that homework is due for periods 6 and 7.

For people in periods 6 and 7 who start their homework promptly, postponing this review is fine, since the current homework has little dependency on the previous homework. But remember to do the review, since it typically provides good value: lots of learning in little time.


Concepts to use: (estimated time to read: 2 min.)


1.  Watch Mr. Brooks's videos on NetLogo …from where you left off through video 4B. Add new commands to the reference page in your notebook (the page you were asked to start in hw24#5). Do the exercises. (estimated time: 21 minutes to watch + 12 minutes to do exercises)


2.  Save your work. (estimated time: 2 min.)  Use NetLogo's File → Save As… command to save your triangle-leg and make-a-triangle procedures to a file whose name ends in .nlogo


3.  Simulations require checking. (estimated time: 10 min.)  This article from Wired echoes the discussion of NetLogo's "Fire" simulation, and adds an important bit on checking simulations. Focus on the paragraph that says "they compared their simulated model fires to what they and other scientists have already observed".

If you did this reading as the optional part of hw23, you need not repeat it.

Thanks for the contribution are due to a poster in Piazza@273.


4.  Submit the .nlogo file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


hw25:  Scientific thinking, v1
due at your first class after Friday, 2020-12-11 8:00 a.m.

expected to take 0.8 – 1.0 hours. Record the time at which you start this assignment.


Concepts to use:


0.  review previous hw (estimated time: 7 min.) Compare your answers on hw23 ("simulations for scientific thinking") with answers in Piazza's "hw23" folder. Piazza will show you the threads if you enter
     folder:hw23
in the box labeled "Search or add a post…"

These answers are expected to contain errors, as always. Help improve them.


1.  Dialog on meaning (estimated time: 9 min.)  The falsifiability of a statement concerns whether that statement has meaning, not whether the statement is true. For a scientific statement I make to have meaning, I must be open to having the statement be shown to be false. That is, it must be falsifiable, whether or not it is later shown to be false.

In a scientific context, some falsifiable statements can be shown to be are false, and others can be considered potentially true. But a statement that fails falsifiability lacks meaning in a scientific context, so one might say there is no way to decide that it is false and therefore no way to decide that it could be true.

A scientific statement can only potentially be considered true. It cannot be proven true. It is always open to refutation by a careful, skeptical experimenter.

Yes, people sometimes sloppily speak of a scientific statement as being "true" or "proven". Unfortunately, this sloppy language misleads people.

This task ask you to write a dialog between two friends arguing about an assertion that I think fails falsifiability: "Almost nobody at Stuy is smart."

Imagine that you have a friend who likes to argue, and they assert that "Almost nobody at Stuy is smart."

Another friend seeks to argue them out of their position.

Make up some names, since this task asks you to think about falsifiability, not about which of your friends to offend so they never talk to you again.

Word-process your results into a new document in accordance with the standard instructions.

Write enough lines of the friends' dialog that any reasonable person would want to start shouting "THIS ARGUMENT IS FUTILE! No evidence would convince this person that they are wrong!"


2.  What is Strogatz's hypothesis? (estimated time: 6 min.)  Write a hypothesis that that could be usefully investigated by the simulation shown in the video from hw22#1. This takes serious thinking, but the result should be a single, clear sentence.

As a convenient abbreviation, use the phrase "the Strogatz rules" to refer to the four rules that Strogatz lists, concerning alignment, proximity, awareness, and scattering. (Strogatz does not claim authorship of those rules; this phrase is just an abbreviation.)


3.  Define falsifiability. (estimated time: 4 min.) 

Falsifiability is not "when" anything. Since falsifiability is not an event, your definition must not begin "Falsifiability is when…" Watch your language.


4.  Is the hypothesis falsifiable? (estimated time: 4 min.)  Do you consider the hypothesis that you ascribed to Strogatz and his collaborators to be falsifiable, or is it meaningless? Justify your position. That justification requires reference to the definition of falsifiability, to say that the hypothesis is or is not consistent with that definition.


5.  Watch Mr. Brooks's videos on using NetLogo …from the beginning through 1B. Record new commands on your notebook's NetLogo reference page. Do the exercises. (11 minutes to watch + 10 minutes to do exercises).

You can speed up the video using YouTube's HTML5 viewer. The gear-shaped button at the bottom of the player presents a "Playback speed" setting that can be used to multiply Mr. Brooks's delivery speed.


6.  Submit a .pdf of your work on tasks 1–4 of this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)

A few people continue to fail to convert their word processed documents to .pdf format. Starting with this assignment, such submissions will earn a grade of zero.


hw24:  NetLogo!
due at your first class after Wednesday, 2020-12-09 8:00 a.m.

expected to take 0.4 – 0.6 hours. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 7 min.) Compare your answers on hw23 ("simulations for scientific thinking") with answers that have been posted in Piazza@278–275.


Concepts to use:


1.  install NetLogo (estimated time: 7 min.)  …from here. If you have trouble, posting your error message on Piazza is likely to be the best source of help.

The current macOS 11 Big Sur increases security with a penalty in convenience. If you are using that operating system, definitely look at Piazza@279, helpfully posted by Alika. There is older advice by a Dojo staffer who provided advice plus screen shots, but this advice failed the people who commented in the Piazza thread. This sort of pain is apparently unavoidable in using computers well.


2.  start the 2D version (estimated time: 1 min.)  We use
     NetLogo 6.1.1
not
     NetLogo 3D 6.1.1


3.  Try these commands (estimated time: 10 min.)  The task will be easier if you read its entirety before typing. Then try these commands, in this order, in the Command Center.

  1. cro 3, which tells the observer to create three turtles
  2. Use the drop-down list in the lower left to change from observer context to turtles context, so that the following commands will be addressed to the turtles.
  3. set size 4
  4. set color magenta or blue etc.
  5. fd 5
  6. pen-down
  7. fd 5
  8. lt 90 and rt 90

It will help to try these features:


4.  Bookmark NetLogo's main manual (estimated time: 3 min.)  in your browser. One of the pleasures of NetLogo stems from the convenience of getting help from its great manual.

That web page is large enough that you will need to know how to tell your browser to search for text on the current web page. But you need to know that anyway, just to qualify as a citizen of the internet.


5.  Start a reference page in your notebook (estimated time: 6 min.)  …and record each new command you learn in NetLogo, starting with the commands from this assignment. The size will be manageable, but it might be 60 commands. If you have questions on any of the commands, well, it is convenient that you just bookmarked the manual, eh?


6.  over the edge (estimated time: 2 min.)  Observe what happens when you advance a turtle off the edge of the world using repetitions of the
     fd 2
command.


7.  Submit your time for this assignment in "Comments to teacher" on the homework server, in decimal hours rounded to the nearest tenth.


play (optional extra education)  If you're enjoying NetLogo, try some stuff, some of which is likely to wind up in the next homework:


hw23:  simulations for scientific thinking
due at your first class after Monday, 2020-12-07 8:00 a.m.

expected to take 0.7 – 0.9 hours. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 4 min.) Compare your answers on hw22 ("Towers v1") with answers that have been posted in Piazza@271.


Concepts to use:


0.  Playing with traffic (estimated time: 13 min.)  Since periods 6 and 1 went too slowly, people in those classes should watch this recording, starting at 41:59, about simulating traffic, courtesy of the ace contributors in period 7. It will be more fun and educational if you simultaneously scroll through the chat starting at 2020-12-03 10:58.

Props to the pd7 crew who recalled that Cavendish weighed the world. If you might need their help with your science homework, check out their savvy at 23:19 into the video with the accompanying chat. Picture Cavendish's set-up via this diagram from this article.

If you missed the whole class, watch from the beginning of the recording. The chat starts at 2020-12-03 10:08, shortly before the recording starts.


1.  What is science? (estimated time: 5 min.) 

Middle school courses on the topic called "science" often focus on the results of scientific inquiry, providing no justification for their assertions.

For example, a chemistry textbook might tell you to believe that "Bonds between Na and Cl differ from bonds between carbon atoms." Assertions like that leave open philosophical questions like "How do you know?", "How should I know?", and "What do you mean when you say that assertion is 'true'?"

Understand the philosophy better by reading the introduction to Wikipedia's article on the scientific method, which precedes the table of contents. The point is to be able to identify assertions that are justified — and unjustified — based on the results of an experiment or simulation.


2.  What is falsifiability? (estimated time: 12 min.)  Statements are meaningless unless they are falsifiable. Understand what this means.

Today's class notes have a couple attempts to explain this concept. But let's crowdsource the task of finding better explanations. If the class notes don't work for you, see and contribute to Piazza@265.

Word-process a document in accordance with the standard instructions.

State an idea from the public discourse that others will recognize, and that you regard as failing falsifiability. Explain why you make that finding in a few sentences. There are a couple examples in the class notes, that might prompt your thinking.


3.  What do simulations prove? (estimated time: 6 min.)  In your already-started document, answer the following in cogent English, edited so that each is less than 60 words:

  1. What is incorrect in asserting that "The simulation Strogatz displayed shows the rules that schooling fish follow"?

  2. Write a correct sentence that starts the same way: "The simulation Strogatz displayed shows…"

A serious thinker in the period 7 chat asked a related question:
"if you are making a simulation to test your hypothesis how can you tell … if the result will be valid because you selectively made that program to test your hypothesis"?


4.  What is a simulation? (estimated time: 12 min.)  Read these 5 paragraphs on "Computer simulation". You can ignore the paragraphs that follow the first five, even though they are invitingly titled "Computer science". Find a decent article from a mainstream news source that describes the use for a simulation, link to it in your document, and write 2–4 sentences (less than 80 words) describing the knowledge people hoped to gain from the simulation. Does the investigation meet the requirement for falsifiability? Why or why not?


5.  Submit a .pdf of your document to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


"Want to Fight the Zombie Fire Apocalypse? Weaponize Math" (strongly recommended reading, but optional; estimated time: 10 min.)  This article from Wired echoes the discussion of NetLogo's "Fire" simulation, and adds an important bit on checking simulations. Thanks for the contribution are due to a poster in Piazza@273.


Wonko the Sane on the scientific method (optional extra education; estimated time: 2 min.)  Douglas Adams describes science well, via a character who is the world's leading scientist concerning dolphins, and who calls himself "Wonko the Sane" :

When Wonko returned he was carrying… sandals.

"I just thought you'd like to see," he said, "what angels wear on their feet. Just out of curiosity. I'm not trying to prove anything, by the way. I'm a scientist and I know what constitutes proof. But the reason I call myself by my childhood name [Wonko] is to remind myself that a scientist must also be absolutely like a child. If he sees a thing, he must say that he sees it, whether it was what he thought he was going to see or not. See first, think later, then test. But always see first. Otherwise you will only see what you were expecting. Most scientists forget that… So, the other reason I call myself Wonko the Sane is so people will think I'm a fool. That allows me to say what I see when I see it. You can't possibly be a scientist if you mind people thinking you're a fool."

Douglas Adams, So Long, and Thanks for All the Fish


hw22:  Towers v1
due at your first class after Thursday, 2020-12-03 8:00 a.m.

expected to take 0.3 – 0.6 hours for the required parts. Record the time at which you start this assignment.


0.  Re-do the previous hw (estimated time: 5–20 min.)  …using what you learned in class on Tuesday or Wednesday, or from the many insightful posts on Piazza, or from your people, or from the Dojo, or from reflection. Cite your sources in the header comment in your code.

If your answer to the previous homework worked, this task amounts to the few additional steps below.

Otherwise (that is, if you are one of the many people who reported partial success), I strongly recommend starting over with step 1C, since that workflow is likely to generate more learning for less work. A solid student in period 7 stated the reason well: "i think my hw got less right the more work I did". Typing the right stuff is likely to be easier than un-typing the wrong stuff.

Follow the instructions slowly and methodically. Maybe the reason I think the instructions are ok and other people think they are hard to follow is that I write them for people like me. I am a slow, methodical, rule-following geek. Even if you are a wild, creative, free spirit, can you pretend to be a SMRFG for long enough to finish the homework faster than your inner WCFS has any hope of doing it?

A SMRFG would keep…

Develop incrementally. The means making the smallest change you can test, and then testing it. Only then make the next change. That way, when a test fails, there will be a tiny region of the code where the error was introduced. Your inner SMRFG will find the error there while your inner WCFS is rending their garments and howling in frustration.

Add comments identify the three major parts of a recursive solution, namely,

Have DrRacket indent your code. Yes, you could leave this to the last step, just to accommodate the whacky demands of a teacher, lest you lose some of the Almighty Points. Or you could indent early and often, so that you eventually assimilate the the way DrR shows the ends of expressions, and thereby speed your programming. If you put any stock in which of these choices the pros make, with no Points on the line, search the intertubes for something like
     indent Java
and notice the number of pros who have almost-fanatical opinions on the subject. No joke.


1.  Why should I care about NetLogo? (estimated time: 5 min.)  Watch 3.3 minutes of a TED talk on synchronized behavior that occurs without leadership, starting here, through at least 6 minutes 15 seconds into the video, after Professor Strogatz says "Even though it looks they are thinking as a group, they are not."

Background:
NetLogo's strength is its power for writing computer simulations. (It is a truly terrible language for writing games.) You will be asked to learn enough NetLogo to create a simulation as a final project. Since every student is always entitled to ask "Why should I care?", we will start with the example above and discuss it in the next sessions.


2.  Submit the improved program to the homework server slot for this assignment. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


NTTSTT (optional extra education) (estimated time: 15 min.)  Did you type the same "Move the disk" code into your processing for recursive cases as in your processing for the base case? I committed that solecism in class and in the Manual for a Monastery. Fixing that raises a bunch of questions, and trying to answer them has improved my recursive programming, so I recommend this exercise to anyone interested in the topic.

The error crept early in the original video when I misleadingly asked "Who knows one?" That is an ok base case, since a base case is a version of the problem everyone can solve without turning to any smaller version of this problem. But smaller is easier, in this case, and in all others in my experience.

So this tasks asks you to consider a base case of zero disks:

  1. Archive a copy of your working program, with a name like
         hw21_ToH_A_baseCase1.rkt
    in case you decide to abandon this improvement.

  2. Construct tests first, as always in programming, so you will know what your program is trying to produce. Start with the the instructions to be generated for 3 and 2 disks, and extend these backwards to write the invocations and expected instructions that would cause Michael the Bot to move 1 and 0 disks. This is the most crucial step, so you might want to check your answers with your people. Maybe someone will have posted a SPOILER on Piazza.

  3. Stop and think: which of the "three major parts of a recursive solution" do you expect to have to modify? Which do you expect to leave untouched, in their current, working condition?

  4. Inhale slowly. Hold that breath for five seconds. Exhale slowly. Do that again. Go, both calmly and methodically.

If your program works, reflect on it to achieve the learning you can use next time you create a recursive solution. Which version do you prefer? Why? Write the answers, in good English, in a comment at the beginning of your .rkt file.

Submit this new program in the slot for this assignment, overwriting the version you submitted previously. Update your comment to tell me that you did the optional work and the total time you spent on this assignment


hw21:  Towers of Hanoi!
due at your first class after Tuesday, 2020-12-01 8:00 a.m.

expected to take 0.5 – 0.8 hours. Record the time at which you start this assignment.


Concepts to use:


0.  Recall (estimated time: 6 min.)  …the material you need at the front of your brain to do this assignment efficiently. Reviewing these documents now is likely to make this homework easier.

Your mission is to assemble these translations into the right order for a procedure that returns a single string of text, giving instructions for Michael the Bot.


1.  if (estimated time: 10 min.) 

  1. On your notebook's page for the Friday or Monday lesson, record the structure and meaning of Racket's if form:

    Structure:
         (if   true-or-false-value   value-if-true   value-otherwise )
    Order matters. That is, Racket treats the first expression after the keyword if as the true-or-false-value, and the next expression as the value-if-true.

    The importance of order is nothing new. For example, order matters in writing divisions in Racket: in
         (/ 12 3)
    the first expression after the slash (12 in this example) is always the dividend, never the divisor.

    Meaning: To interpret the if Racket will…

    1. Evaluate the true-or-false-value.

    2. When the value is true, Racket evaluates the value-if-true, uses that value as the value of the entire if form, and skips over the value-otherwise.

    3. Otherwise (that is, when the true-or-false-value is false), Racket skips over the value-if-true, and evaluates the value-otherwise as the value of the entire if form.

  2. If you have doubts about your level of understanding, play with the sample from class, predicting its results as you change the number of disks:

    (define numberOfDisks 1)  ; in the procedure, use a parameter
    
    (display
     (if                                ; Choose, based on...
          (= numberOfDisks 1)           ; true-or-false value
          "the base case"               ; value-if-true
          "one of the recursive cases"  ; value-otherwise
          ) ; end of IF
     )

  3. Download the program from class. Run it and understand it.

  4. Modify the program in the steps below. These steps provide a sequence for incremental development.

  5. Replace the placeholder invocation of string-append with an if that will cause instructionsForBot to return
         instructions for processing the base case
    when invoked for one disk, and
         instructions for processing any recursive case
    otherwise.

  6. Test your work for several values. Of course. The "expecting" text in the existing tests show the eventual results, but this task creates another stub, whose result is closer to the desired result, but not yet there.


2.  base case (estimated time: 3 min.)  Improve instructionsForBot to produce the correct results when invoked for one disk. Test.


3.  recursive case (estimated time: 9 min.)  Improve instructionsForBot to produce the correct results when invoked for multiple disks. Test it on 2 disks. If that works, uncomment the code at the bottom of the file to test it on 3 disks.


4.  If you get this far… (estimated time: 5 min.)  …administer a massive self-high-five. Try other numbers of disks. Admire your work. This would take me much longer than 5 minutes, but maybe you're less surprised than I am by writing a tough program that works. Or maybe you're exhausted. In any case, please accept my congratulations.


5.  Submit the file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth, and what stopped your progress, if anything. (estimated time: 2 min.)


hw20:  end-the-universe instructions
due at your first class after Wednesday, 2020-11-23 8:00 a.m.

expected to take 0.4 – 0.7 hours. Record the time at which you start this assignment.


Concepts to use:


0.  Start with this program. (estimated time: 4 min.)  It is a modified version of my answer to hw18, modified to show "expected" output that is one step closer to the eventual goal of calculating instructions for moving the disks. That goal still requires one more piece of Racket, to be covered in the next class.

Run the program to see the interim results mandated by this assignment. Following these instructions would violate the rules of the Towers of Hanoi puzzle. But merely programming this output violates no rules and exercises string-append.

Notice that the expected output is a single string of text that is built up from some literal strings, like
     Pick up all the disks from
concatenated with the values from parameters like source.


1.  Understand the motivation (estimated time: 8 min.)  …for this assignment by re-visiting the aims from your class on Monday 2020-11-23 or Tuesday 11-24. In a comment at the top of the file, write comments in good English, edited down to 2 to 4 sentences each, answering…

  1. What advantage derives from having a procedure like the one you are writing return the result of its calculations, rather than just displaying it.

    In programming jargon, to return a result from a procedure means to have that result replace the invocation of the procedure in the last step of how Racket invokes a procedure, as discussed a few paragraphs below the green section.

    It may help to recall why it is useful that expt returns its result, rather than displaying it. Recall the use of expt in calculating the area of a circle given its radius. For sample code, search for
         circleArea_fromRadius
    on this web page.

  2. Why is invoking string-append necessary for your routine to return the results shown in the program downloaded in the previous task?


2.  Build the specified output (estimated time: 9 min.)  …by starting with the program downloaded in this assignment and replacing the
     "under construction"
literal with an appropriate invocation of string-append, so that program displays the instruction that the skeleton says we are expecting:
     Pick up all the disksMWAHAHA!

Leave the code that displays the announcement
     I will moveManual says to.
Displaying this announcement is not violating the practice of "having a procedure… return the result of its calculations". Rather, the announcement tells the programmer what the procedure will do, before the procedure does it. That is, after displaying the announcement, the procedure should return the directions
     Pick up all the disksMWAHAHA!

Leave the
     (define steps
forms unmodified. They can help you understand the necessity to return the string of text instructions, rather than displaying it in the procedure.

The
     Don't worry
part of the instruction begins a new line.


3.  Factor out the displays that produce the announcement. (estimated time: 6 min.)  To make your eventual routine easier to read, create a well-named helper procedure to display the announcement
     I will moveManual says to.
Invoke that helper procedure from instructionsForBot, so that the output is unchanged.

Do you remember what programmers mean by "factoring out" code? It means to…

Recall the factoring you were asked to do in calculating the solutions to quadratic equations. See my results here.

This task requests factoring, only. It does not request converting the multiple invocations of display to a single invocation of display combined with an invocation of string-append. Even if you think that conversion merits learning about, as an incremental developer you will do the factoring first, test that, and then consider the conversion, right? Right?

Later note: enough people were interested in that conversion that some advice appears in the following task, which is optional.


4.  string-append goes pro (optional extra education; estimated time: 15 min.)  Some people, on hearing about string-append, noticed that it could be used to build the announcement
     I will moveManual says to.
Perhaps these people are aesthetically offended by the nine invocations of display that create the announcement in the program downloaded in this assignment. They might have (correctly) noticed that they could replace the nine with a single invocation of display, by passing that single invocation a single string of text built with string-append.

If your aesthetics match, you can learn some worthwhile programming by incrementally developing a new version of your helper procedure.

First, save a copy of your working code. Always. Working code is rare and valuable, at least in my life. Throwing it away brings out a rash. For example, you might run out of time to work on this change, or you might decide after seeing the change that you prefer the nine-display version. Saving versions makes it easy to submit your previous version.

Build your incremental development chops. What is the smallest change you can make to the helper procedure that you can test, and that is in the direction of reducing the nine invocations to one? Smaller steps mean faster programming. Faster programmers have more time for other stuff in their lives. In the professional world, faster programmers are paid more.

You are likely to trip across the error that lots of us make on our first attempt. This is good. Having seen the error and fought your way past it, it will be much faster to program through this issue the next time.

If your attempt ran afoul of the same contract violation that mine did, you are likely to benefit from reading a bit of the documentation on converting numbers to strings of text.

Piazza@235 discusses this issue helpfully. Even if you find the answer yourself, you are likely to benefit from seeing others' questions and approaches.


5.  Submit the file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. If you did the optional programming, add that information to the comments, to aid my understanding of the times reported. (estimated time: 1 min.)


hw19:  step 0, corrected
due at your first class after Monday, 2020-11-23 8:00 a.m.

expected to take 0.3 – 0.7 hours. Record the time at which you start this assignment.


Concepts to use:


0.  Do hw18 better. (estimated time: 30 min.)  Re-read the assignment, since many, many errors in submissions showed failures to understand the directions. So you can expect at least two benefits from re-reading:

Re-load your browser's view of the page each time you start a new task. Although I think the instructions are clear, I will watch Piazza after posting this; if questions there suggest improvements here, I will make them.


1.  Submit the file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


hw18:  recursion in Racket, step 0
due at your first class after Thursday, 2020-11-19 8:00 a.m.

expected to take 0.8 – 1 hours, but less for people in periods 1–3 who have done about 0.2 hours of the thinking already. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 6 min.) Compare your answers on hw17 ("Be the Monks") with answers in Piazza@212.

The current homework depends on the previous homework, so do the review before the rest of this assignment.


Concepts to use: (estimated time to read: 2 min.)


1.  Understand program development in the real world (estimated time: 3 min.)  …at least as illustrated by this assignment.

School assignments usually rob you of a serious challenge. The author of a homework assignment spoon-feeds students what to do, so the only thinking required of the students is how to do it. Deciding what to do is crucial and requires thought.

Spoon-fed students start writing code before understanding the problem they want to solve, a.k.a. "Ready, fire, aim." Or, as programmers say, "Hours of debugging can sometimes save minutes of planning."

You can do better.

When writing a program in the real world, first decide what the program is to do:

Those decisions require serious thinking. Some of the answers have been given away in class, so you are not starting with a blank slate. When you are lucky, that happens in real-world programming, too.


2.  For the inputs (estimated time: 2 min.)  …you can re-use previous thinking by answering "What information does the Abbot supply to test the Manual for a Monastery?"

Monday's classes in periods 1–3 settled on four pieces of information:


3.  For the outputs (estimated time: 12 min.)  …it would be nice to generate commands for a robot that could move disks between towers. Since we lack such a robot, imagine one. In honor of Michael the TA, I'm naming this robot after his kid brother, Michael the Bot.

Michael the Bot understands only commands like
     Move the top disk from Da Nang to HCMC.
That is, he can't make choices, nor copy values into parameters, nor subtract, nor make requests, so that he resembles a traditional robot.

Instead, all the logic for choosing, subtracting, meditating, requesting, etc. will be in a Racket procedure you write, so that your procedure will do the Racket equivalent of the a monk's actions, except for actually moving the disks. Instead of making the moves, your program should issue a list of commands that Michael the Bot could follow to move the disks legally.

List the commands your procedure should generate for two requests from the Abbot. As is common in program development, generating this output helps a programmer decide exactly what their program should do and generates answers for testing the program once it is written. Recall a meaningful test requires that "you know what to expect the result to be after the procedure is evaluated".

Re-use previous thinking! In hw17's trace of the Monks following the directions in the Manual you generated exactly the desired "Move" commands for to possible requests from an Abbot:…

For even more certainty, or if you skipped hw17, see answers to hw17 that a lot of eyes have scanned for errors.

Record your answers in a comment in a new .rkt file. That will facilitate turning them into tests of your procedure eventually.

My answers are in the class notes from Monday's sessions.


4.  Understand this sample (estimated time: 7 min.)  …illustrating the approach I'd take to developing bumpUp incrementally. Yes, bumpUp might be simple enough to write in "Ready, fire, aim" mode, but…

What caused
     under construction
to appear in the interactions window, even though the procedure has no invocation of display? You will need to understand the answer for the next task, and it is easier to understand in this tiny example.

Between today's lesson and all this analysis, I hope you can appreciate the difficulty of starting a program when no one has done the hard parts for you, so you do not despair when you, too, find it difficult.


5.  Create a stub. for the Towers of Hanoi program. (estimated time: 16 min.)  …that you will be asked to complete in future assignment.

Programmers use the word stub to mean a program that runs without errors, but which produces results that fall short of the eventual goal for the project. Stubs are crucial for incremental development, since any competent programmer tests their work long before it can produce the desired answers.

The eventual goal, in a future assignment:
a Manual for a Monastery procedure that produces the outputs you defined in the previous task when given the inputs that you identified in the task before that, representing a request from the abbot.

This task stops well short of that goal. For this task, you are asked to write only…

Develop incrementally, which means making the smallest change you can test, testing that change, and only then making a second change. Some guidance follows.

Start by running the bumpUp code that you downloaded in the previous task. Did you assume I never make errors? Have you seen me type?

Write the Abbot's part, by writing invocations of your procedure, passing as arguments the four pieces of information it will need, namely, the number of disks to be moved, and city names like
     "Hanoi" "HCMC" "Da Nang"
and
     "Kingman" "Barstow" "San Bernardino"

When the stub has been fully upgraded to produce the eventual goal, the last value computed by the procedure will be the text of the desired instructions to Michael the Bot. But since we need to discuss two more bits of Racket before you can write that computation, temporarily use
     "under construction"
as a placeholder last expression in the procedure. Keep that simple expression as the last value computed in the procedure for the rest of this assignment.

Almost certainly the last expression in your procedure is
     (display something)
rather than an unadorned
     "under construction"
Don't do that.

When your procedure is invoked, it is to display the "I will move…" announcement that the Manual requires of each monk.

When writing the stub of a procedure, programmers commonly make the stub display its parameters' values. The feedback is helpful for understanding whether the flow through the program is correct, even before the stub is upgraded to actually do what the announcement says it will do.

You used to know how to display a mixture of strings of text with other values, since we did that in displaying solutions of quadratic equations.

In my solution to this assignment, when my stub procedure is invoked to provide Michael the Bot with instructions to move 2 disks from Hanoi to Da Nang using HCMC if required, the stub procedure just echoes the request and adds an advisory that the procedure is under construction. The interactions window shows…

I will move the top 2 disks from Hanoi to Da Nang using HCMC if the Manual says to.
under construction

When the same stub procedure is invoked to provide Michael the Bot with instructions to move 3 disks from Hanoi to HCMC using Da Nang if required, it produces the following announcement in the interactions window:

I will move the top 3 disks from Hanoi to HCMC using Da Nang if the Manual says to.
under construction

The stub version of the procedure that is requested in this assignment issues no instructions for Michael the Bot, as shown in the sample results above.


6.  Submit the file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


hw17:  Be the Monks
due at your first class after
Friday, 2020-11-13 8:00 a.m. for pds1–3 and
Monday, 2020-11-16 8:00 a.m. for pds6 and 7

expected to take 0.6 – 0.8 hours. Record the time at which you start this assignment.


0.  review my instructions for the Monks. (estimated time: 7 min.)

Students in the past have found this assignment long but helpful, because the upcoming Racket programming will have the same form as the English programming in the "Manual for a Monastery". So understanding the English recursion will take you a long way towards understanding recursion in another language.

You are likely to find many differences between your language and mine, and many of them matter. I have been improving these directions for years, with no end in sight. The current version benefited from suggestions by several students in teh current classes. So you can expect to find places where you wonder "Would this 'Manual' be better with phrasing like…"

The current homework depends on the this step, so do the review before the rest of this assignment.


1.  review how order matters (estimated time: 3 min.)  using answers on that will be contributed in Piazza@201.


2.  Move 3 (estimated time: 25 min.)  This task asks you to record the moves of all 3 monks, to accomplish the "3 disk" task requested by the Abbot, in the form used in the Tuesday / Thursday lesson.

That is, create boxes of instructions that belong at the end of the "3 disks" table at the end of this document. As in the lesson, moving a platter when ever the instructions start with "Move" should result in moving all three disks.

Make your own towers! Your thinking, learning, and writing are all likely to benefit from moving actual objects. Watching an animation from the intertubes would waste your time. So build your own out of whatever golden platters you have at hand. Here's a budget-conscious version:
 towers, for 31 cents

Keep your word-processing simple; this is not a course in word processing. You can start with this document.


3.  Submit a .pdf of your work to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


hw16:  MonkN,  v1
due at your first class after Tuesday, 2020-11-10 8:00 a.m.

expected to take 0.4 – 0.6 hours. Record the time at which you start this assignment.


0.  Improve your instructions for MonkN. (estimated time: 20 min.)  Produce a new version of your work on the previous homework, based on the issues discussed in Monday's classes. Word-process your results in accordance with the standard instructions.

Cover all the improvements discussed in the classes on 2020-11-06/ 11-09. We can crowd-source assembling a list of improvements, in the Yesterday's Knews entries for those classes. You were asked to take notes in class on the improvements that your first draft requires, so make sure all your items are represented in the list, and augment your list with any ideas that you missed in the tumult of the class.

Include the following elaborations on the class discussions:


1.  How does order matter? (estimated time: 7 min.)  We will shortly write recursive instructions in Racket, as well as English. Doing so requires understanding the interaction between building a procedure (using lambda) versus invoking it. This task asks you to solve two relevant questions from this test from a previous semester.

Figure this out by following Racket's rules, as described in Piazza@163 and @128. There is nothing new here. Shut off the thinking and predict Racket's results from following the rules.

DrRacket can check your predictions. There is a helpful discussion of this in Piazza@191. But if all you're going to do is thoughtlessly edit in DrRacket, skip the problem, since you won't learn anything anyway.

Type your answers into your word-processed document.


2.  Submit a .pdf of your document to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


hw15:  recurse in English
due at your first class after Friday, 2020-11-06 8:00 a.m.

expected to take 0.6 – 0.8 hours, including about 0.3 hours allocated during the class period. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 2–7 min.) Compare your answers on hw14 ("gonna try with a little help from my friends") with answers in Piazza@179. This thread is great work, mostly because people were willing to contribute alternative solutions and others were willing to spend time writing constructive criticism. You can learn a lot in little time.


Concepts to use:


1.  Think about the rest of the video and the chat (estimated time: 25 min.)  started during class.

Fun fact: "Michael the TA" in the video is our Michael the TA. He travels through time.


2.  Start a new word-processed document (estimated time: 2 min.)  in accordance with the standard instructions. A line for citations has been added to the header, so pay attention to that new request.


3.  manual for MonkN (estimated time: 15 min.)  In the video, we developed instructions for Monk4, which relied on Monk3. The results were something like…

When you are asked to move the top 4 disks from Hanoi to HCMC (Ho Chi Minh City) using Da Nang for storage…

  1. Ask Monk3 to move the top 3 disks from Hanoi to Da Nang using HCMC for storage.

  2. Wait for Monk3 to report "done".

  3. Move the top disk from Hanoi to HCMC.

  4. Ask Monk3 top move the top 3 disks from Da Nang to HCMC using Hanoi for storage.

  5. Wait for Monk3 to report "done".

  6. Report "done".

Your mission:
Imagine that you are the abbot of this monastery, and that new monks periodically replace vacationing monks. Write instructions in English that would work for a replacement MonkN who steps into any role, no matter which numbered monk they replaced.

That is, MonkN may not be the highest-numbered monk. For example, the monastery might be working on a 17-disk tower, while MonkN is subbing for Monk9, or for Monk1, or for Monk17.

So the sub arrives at the monastery gate, you hand them the manual, tell them which monk number they are, and they follow the instructions — carefully, but without any insight or judgment — resulting in flawless participation in this crucial task.

For example, if the new monk is to become Monk3, they will read your instructions, replacing all mentions of n with 3.

Start your instructions like this:

When you are asked to move n disks…

Make your instructions usable by Monk1, too.

To test your instructions, it is helpful to find 3 or 4 objects of decreasing size that you can stack.


4.  Submit .pdf of your document to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


hw14:  "gonna try with a little help from my friends"
due at your first class after Wednesday, 2020-11-04 8:00 a.m.

expected to take 0.6 hours, plus any extra time you spend on the revision to hw13 in the optional task 1. Record the time at which you start this assignment.


0.  review hw13's two new "rules to Racket by" (estimated time: 3 min.) Compare your answers with answers that will be contributed on Piazza after hw13 is due for periods 6 and 7.


Concepts to use:


1.  optional improvement to hw13's trace Several solid students in this course sought more time so that they could revise the tracing they did for hw13. That learning seems worthwhile to me, because understanding those steps is likely benefit all your future programming.

Cut and paste your rules. The point of all this work is to own the rules that Racket follows. So don't paraphrase, don't abbreviate, don't synopsize. Using a word processor allows you to present each of the rules you use, pasting the rules quickly. Do the pasting to learn the rules, or skip this optional improvement.

As will all homework so far, you are welcome to work with someone else on this revision as long as you cite that help and understand everything you submit.

If I grade hw13, there will be no points penalty for this second submission. There will be an additional slot on the homework server for anyone who wants to submit a revised version of hw13.


2.  solutions to quadratic equations, improved more (estimated time: 5 min.)  To wrap up the work started in the breakout rooms, review the "before" and "after" versions of factoring out the calculation of the discriminant's square root:
     before
     after, with the calculation factored out into the discriminant_sqrt procedure

Understanding this example is likely to speed your work on the rest of this assignment.


3.  annulusArea (estimated time: 10 min.)  Write a procedure called annulusArea that calculates the area of an annulus, given the radii of the inner and outer circles. Create unambiguous names for all parameters, so that another programmer could use your procedure. Test the results.

Can circleArea_fromRadius serve as a helper procedure?


4.  targetArea (estimated time: 15 min.)  Write a procedure called targetArea that calculates the total area of the three red rings in the old Target logo, given the radius of the innermost, white circle. Each of the surrounding rings has a width that is the same as the radius of the innermost, white circle, so targetArea needs only one parameter, namely, the length of that radius.

old Target logo concept by Mr. Mykolyk

How will you test your routine? A test requires knowing the answer by some external means.

One idea: estimate the fraction of the logo that is red.

Another idea: on Piazza@150, people could post some pairs of radius and the associated area. Yes, lots of us could be wrong together. But when I'm programing, I gain a little confidence when I see answers from others that resemble mine.

optional extra education: Mr. Kats, ace math teacher, showed a cool way to decide that the answer is a constant times a triangular number. This makes a good way to check your work, but don't use this insight for programming this task, since you won't learn anything about helper procedures by programming a couple multiplications.


5.  Submit the .rkt file for this assignment to the appropriate slot on the homework server. In "Comments to teacher", tell me how long you spent on this assignment, in decimal hours rounded to the nearest tenth. If you did the optional revision to hw13, submit that work to the appropriate slot on the homework server. (estimated time: 2 min.)


functional programming, FTW (optional extra education; estimated time: 13 min.)  Does the remaining duplication in my after version of the quadratic formula program have you grumbling? "NTTSTT my foot! There's still duplication, mostly because oneSolution and otherSolution match, except that one adds where the other subtracts." Several students have wanted to fix this.

Racket makes this easy, once you start thinking that procedures are values, just as much as integers are. In fact, Racket is called a functional programming language because of that similarity. (Other languages use the word "function" the way "procedure" is used in Racket.)

So replace those two procedures with a single procedure, called aSolution perhaps, and invoke that procedure twice, with an argument that specifies whether to add or subtract. Finally, the code passes the NTTSTT test.


hw13:  rules & trace
due at your first class after Monday, 2020-11-02 8:00 a.m.

expected to take 0.8 – 1.0 hours. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 20 min.) Improve your answers on hw12 ("rules to Racket by, v0") based on the breakout room discussions in class and the answers that will be posted on Piazza after hw12 is due for periods 6 and 7.

A common shortcoming in hw12 answers: for the "evaluate an expression" row, many people considered too few kinds of expressions. There are at least three:

For the first two, your text can simply refer to other rows in your table.


Concepts to use:


1.  two more capabilities (estimated time: 10 min.)  Tracing requires two more capabilities, so augment your "rules to Racket by" document with two more rows, describing…


2.  Apply your rules (estimated time: 20 min.)  …to this program, adding a new page at the end of your "rules to Racket by" document.

Start by copying the content of this page into your word processor. I cannot be sure this will work in all word processors, but the results are helpful in Microsoft Word, at least. This kind of structure-to-be-filled-with-thinking is called a skeleton even at other times of the year.

For each separately-numbered line in the sample program, show the steps that Racket follows. Copy these steps from your "rules to Racket by".

Proceed through the program's lines in the order that Racket reads and processes them, starting with line 1, and reading top-to-bottom, left-to-right,

Remember that a left-parenthesis has two effects:

  1. Put the current processing on hold
  2. Start something new, such as a lambda or the invocation of a procedure.

A sample might help, so here is a possible answer for line 2: (You will have your own version of the steps for lambda; I'm only taking a guess at them here.)

(lambda (tooSmall) (+ tooSmall 1))   ; line 2
  1. Put the define on hold.
  2. Build a procedure, recording tooSmall as the procedure's list of parameters and packaging the instructions
         (+ tooSmall 1)
    as the expression to be evaluated if and when this procedure is invoked.


3.  Submit a .pdf of your document to the homework server slot for this assignment. Leave the preliminary version from the previous homework in the slot for that assignment. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


Stop here if you have already done the previous assignments in this class. That is, the remaining task is assigned only to Mykolykites. It was published late, after 3:30, so it is due at your second class after Monday, 2020-11-02 8:00 a.m., meaning Wednesday or Thursday. But it is both small and important, so I hope many people will do it sooner.


4.  Introduce yourself (estimated time: 2 min.) by filling out this form.


hw12:  rules to Racket by,v0
due at your first class after Thursday, 2020-10-29 8:00 a.m.

expected to take 0.6 – 1 hours. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 7 min.) Compare your answers on hw11 ("terms in how Racket invokes a procedure ") with answers contributed in Piazza after Wednesday's classes have posted them.


Concepts to use:


1.  Start (estimated time: 1–5 min.)  …a word-processed document called rulesToRacketBy in accordance with the standard instructions, plus one of the following formatting aids:


2.  Fill in the table. (estimated time: 30 min.) 

For the form of the language: Show what a programmer types to use the capability. Equivalently, tell how Racket recognizes that a programmer wants to employ the capability. Write your answer using normal and italic letters the way we use black and red in class. That is…

The "format painter" tool in your word processor can help.

Use entries from the class notes whenever possible.


3.  Continue memorizing (estimated time: 5 min.)  how Racket invokes a procedure.


4.  Test your access to the new Zoom meeting (estimated time:  min.)  …for November, via the instructions for joining Holmes's Intro Comp Sci meeting. Remember to join the new meeting on Monday. Remind people who forget (or who blow off this homework).


5.  Submit a .pdf of your work for the rules to the homework server slot labeled "rules to Racket by". In "Comments to teacher" for that slot, tell me how long it took you to write the rules, in decimal hours rounded to the nearest tenth. (estimated time: 2 min.)


6.  optional self-assessment (estimated time: 20 min.)  …for students who submitted Holmes's hw05. Hw05's exercise showed a wide range in understandings of Racket's symbol table processing or, perhaps, of willingness to learn through homework. Your education is likely to benefit from comparing your work with my answers. Watch for errors on my part, as always. Questions are best addressed on Piazza.

Since hw05 is the major assessment in marking period 1, you can gain insight into your grade by applying my rubric to the work you submitted. You are unlikely to be able to match my judgment exactly. Rather, the rubric aims to communicate the parts of the assignment I judge as important.

The homework server for Holmes's classes will have an additional slot. If you submit your version of scores on my rubric, I may be able to use them to give a more accurate assessment of hw05 for marking period 1. As discussed in class, wildly inflated assessments of your work will be taken as evidence that you still lack understanding of the material, and decrease your score on the final grade for this assessment.

Comparing your work to mine will be educational. But do not spend too much effort on applying and submitting the rubric, since that is an experimental idea for this remote-learning, and may be too much work for too little learning. Also, it unclear whether I have time to incorporate your work into my submissions on Friday.

The grade on hw05 affects your semester's grade. So it is important to me that the grading be done well by semester's end, even if I can provide only a rough estimate for marking period 1, and even if families take advantage of the DOE's policy to throw away that grading. It has taken me a lot of time this semester to adapt to the many changes in grading policies so far. Perhaps the pace of change is slowing, to permit more even-paced grading. But Wednesday's DOE memo shows policy in flux, as perhaps we should expect in these turbulent times.


7.  optional: submit your scoring in an Excel-style workbook built from the rubric template I provided, to the homework server slot labeled "hw05 score". To have any chance of being useful, I'll need a day to process your submission, so the due dates are earlier for periods 6 and 7 than due dates for mandatory work. (estimated time: 2 min.)


hw11:  terms in how Racket invokes a procedure
due at your first class after Tuesday, 2020-10-27 8:00 a.m.

This assignment is expected to take 0.5 – 0.7 hours for tasks tasks requested of everyone (that is, tasks 0 – 4).

An additional 0.3 hours is assigned to people from Mr. Mykolyk's classes, who will benefit from catching up on the class culture, and benefit others by participating in it.

Record the time at which you start this assignment.


0.  review previous hw (estimated time: 4 min.) Compare your answers on hw10 ("bind a procedure to symbol") with answers contributed in Piazza after Monday 2020-10-26 10:15am (when it is due for the last period).


Concepts to use:


1.  Understand the terms (estimated time: 7 min.)  …in how Racket invokes a procedure by generating examples, in the following steps:

  1. Copy lines a–g below into a word-processing document in accordance with the standard instructions.
    1. the invocation of circleArea_fromRadius
    2. the invocation of the built-in display procedure
    3. the value(s) of the argument(s) in the invocation of circleArea_fromRadius
    4. the value(s) of the argument(s) in the invocation of display
    5. the parameter(s) of circleArea_fromRadius
    6. the expression in circleArea_fromRadius
    7. the value of the expression in circleArea_fromRadius that will replace the invocation in step 2 of how Racket invokes a procedure
  2. Run the following code in DrRacket:

    (define circleArea_fromRadius 
      (lambda (radius)
        (* 3.14 (expt radius 2))
        ))
    ; test it
    (display (circleArea_fromRadius 10))
  3. For each line you pasted into the word-processing document, paste the appropriate snippet of the code (above) or its output from DrRacket's interactions window.


2.  Familiarize yourself (estimated time: 7 min.)  …with how Racket invokes a procedure. In your document for this assignment, write down any questions you have, especially about the meaning of terms. Previous semesters' students have taught me that understanding this text takes discussion.


3.  Submit a .pdf version of your document to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 2 min.)


4.  memorize (estimated time: 15 min. spread over 2 days) how Racket invokes a procedure so that you can write it perfectly. To help your self-discipline, visualize an upcoming quiz, on any day starting with Tuesday's class, as we had in previous semesters. There will be only one question: "Write how Racket invokes a procedure, according to the class notes."


Stop here if you have already done the previous assignments in this class. That is, the remaining tasks are assigned only to the people from Mr. Mykolyk's classes.


5.  Email better (estimated time: 3 min.)  …by understanding how email helps communication. Failing to follow that advice in email to me will reduce your grade on this assignment


6.  Piazza party (estimated time: 20 min.) Completing this task might push your time for this assignment over one hour, which is unreasonable. So feel free to postpone finishing this task until after the next class.

This course makes extensive use of an online forum called "Piazza". This task asks you to activate your account and make a first contribution.

Activate your Piazza account after you receive email from Piazza with an invitation.

Set your profile to use the first and last names that you are known by in class, to aid communication and promote collegiality.

Read these notes on how Piazza is to be used in this course. As an incentive to students who are motivated by grades, part of the homework grade covers following the advice on that page.

Use good wiki etiquette to contribute 7 minutes of thought and writing to one of the discussions TNPG or trade-offs in switching teachers. Alternatively, you can contribute to the threads populated by your predecessors in this course, on

…although it may be tough to establish your individuality among the existing solid contributions. You are also welcome to start a new thread. The work aims to ensure that you are familiar with Piazza, before you have a need for it.

optional extra education: Piazza founder Pooja Sankar writes about studying comp sci in college as a woman in India, and how Piazza can help. (estimated time: 2 minutes).


hw10:  bind a procedure to symbol
due at your first class after Friday, 2020-10-23 8:00 a.m.

expected to take 0.6 – 0.8 hours. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 10 min.) Compare your answers on hw09 ("build procedures") with my answers by downloading this file and using DrRacket's File > Open command to edit it. Lots of people have shared that they are struggling to understand Racket's parentheses. So do serious thinking to understand each pair in this program, which is about as complicated as this gets. Time spent now will make future homework faster. Experiment with each of these techniques:


Concepts to use:


1.  display a procedure, 2 ways estimated time: 4 min.)  Paste a copy of the following procedure-building-and-displaying code, which I wrote for hw27:

(display

 ; Build a procedure to calculate
 ; the area of a circle, given its radius
 (lambda (radius)
   (* 3.1 radius radius)
   )   ; end of building

 )  ; end of display

Paste a second copy of the procedure-building code, but this time, instead of displaying the procedure, bind it to the symbol circleArea_fromRadius.

Then display the value of the symbol circleArea_fromRadius.

Write a Racket comment explaining the difference between the outputs.


2.  invoke a procedure, via a symbol (estimated time: 4 min.)  Recall the language for invoking a procedure:
     ( procedure argument argument… )
Having bound a procedure to the symbol circleArea_fromRadius, we seek to use that symbol to refer to that procedure in the language for invocation.

So try it. That is, use the symbol circleArea_fromRadius in an invocation where Racket expects a procedure. Supply one of the arguments you used in hw09. Display the result.


3.  Get paid (estimated time: 3 min.)  …for storing the procedure in the symbol table. Download this ugly code from class, paste it into your .rkt file, and improve it by eliminating the copies of the lambda forms, which are violating NTTSTT. Use the symbol circleArea_fromRadius in place of those copies.


4.  Got it? (estimated time: 7 min.)  After the steps above make sense — and only if they make sense — re-use your thinking from hw09 ("build procedures") by scrubbing the NTTSTT violations out of calculating averages:

  1. Invoke lambda to build a Racket procedure that takes two parameters and calculates their average.

  2. Bind the resulting procedure to a symbol called averageOf2

  3. Re-write your two demonstrations of averaging, this time without violating NTTSTT.


5.  Own it. (estimated time: 6 min.)  Do one more, starting from the math function from hw08#2c that calculates trapezoid areas:

  1. Invoke lambda to build a Racket procedure that calculates the area of a trapezoid, given the lengths of its two bases and the altitude between them.

  2. Bind the resulting procedure to a symbol called trapezoidArea

  3. Write two separate invocations of the procedure and display the results of each.


6.  Submit the file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


Fun with parentheses (optional extra education; estimated time: 1 min.)  Lisp is the second-oldest programming language and a direct, close ancestor of Racket. Xkcd weighs in.


hw09:  build procedures
due at your first class after Wednesday, 2020-10-21 8:00 a.m.

expected to take 0.6 – 0.8 hours. Record the time at which you start this assignment.


Concepts to use: (estimated time to read: 11 min.)


0.  Build and display (estimated time: 8 min.)  …a procedure that will compute the area of a circle, given its radius. Save your .rkt file with some fileName before running it.

This task asks you to "build and display" the procedure, NOT invoke it. Understand the distinction. Your output for this task should look like
     #<procedure:...fileNameSuffix:number:number>

Approximate π. As we have discussed, irrational numbers are approximated anyway. A value like 3.1 is fine. Even if you have made the life error of memorizing too many digits of π (as we geeks are prone to doing), be aware of the comp sci learning: Racket will use only the first 15 digits.


1.  Invoke (estimated time: 5 min.)  your procedure to calculate the area of a circle with a radius of 10, and display the results.


2.  Invoke 2 copies (estimated time: 5 min.)  …of your procedure, and display the results. That is, copy the code twice and modify the copies to compute results for 2 additional radii.

The code you write will be complicated enough that it is likely to be difficult to program without error, and difficult to read afterward. So program it well:


3.  Build and display another (estimated time: 8 min.)  …procedure, which accepts two parameters and calculates their average, like the averaging function in hw08#2b. As in task 0, your output should show that a procedure has been built, rather than showing results from invoking that procedure.


4.  Invoke (estimated time: 5 min.)  …2 copies of your averaging procedure, and display the results. Pass different pairs of values. Have the last invocation compute the average of \( \sqrt{2} \) and \( \sin( \pi/4) \). Write code to make Racket compute those numbers, rather than using a separate calculator or your knowledge of trigonometry.

Racket has a built-in procedure named sin that computes sines. It expects an argument that is an angle measure, in radians.


5.  Submit the file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


hw08:  steal from math
due at your first class after Monday, 2020-10-19 8:00 a.m.

expected to take 0.5 – 0.7 hours. Record the time at which you start this assignment.


Concepts to use:


0.  Hand-write (estimated time: 2 min.)  your results onto a separate piece of paper in accordance with the standard instructions. Read the last task in this assignment and understand what you will be asked to submit.


1.  Recall the terms from math (estimated time: 6 min.)  …discussed on Thursday and Friday by creating a sample function definition and invocation. Leave space around these on your paper, so you have room to neatly label the function's…


2.  Define (estimated time: 3 min.)  …functions, using math notation, to compute…

  1. the area of a circle, given its radius

  2. the average of two numbers

  3. the area of a trapezoid, given the lengths of its two bases and the altitude between them


3.  Write two invocations (estimated time: 6 min.)  …of each function. Make half the arguments expressions with operators, like \( 5 \times 2 \) or \( \sqrt{9} \), rather than simple constants, like 10 or 3. Evaluate each invocation.


4.  Write instructions (estimated time: 12 min.)  …in English for invoking a function. You performed six example invocations in the previous task, so use that experience as the basis for your instructions. Your single list of instructions must work for all of your examples. Expect writing the instructions to require 3–5 sentences and serious thought.

The only purpose to learning vocabulary is to facilitate communication. So use the terms related to functions.

Think of the target audience for your instructions as a middle-school student whose knowledge of functions is limited to the terms related to functions. The kid is willing to read your directions carefully and repeatedly. Imagine that they will be given a function definition and the right number of arguments for invoking the function. Following your instructions should result in their evaluating the function.

Students have taught me the similarities between programming a fifth-grader by writing instructions in English and programming DrRacket by writing instructions in Racket.

Do not write a separate list of instructions for each evaluation. Rather, write a single list of instructions that generalizes your actions. Those instructions must work for any of the invocations.

To appreciate the need for generalization, notice that you used multiplication to calculate the area of circles, but used addition to calculate averages. So your generalized instructions cannot specify either. Instead, you will probably write language language directing the fifth-grader to perform the "specified operations" for the function at hand.

Drafting your answer in a word processor helps. I require several drafts to write clear instructions, and a word processor facilitates revision.


5.  Submit a legible image of your work for this assignment to the homework server. Files in .pdf format are best, but files in .jpg or .png format are acceptable. Display your files on your own computer before submitting them, to make sure they will be legible when I display them on mine. I cannot award points for work I cannot read.

Piazza@58–57 should accumulate advice on producing .pdf files from various smartphones. Serious smartphone users will have future use for this capability.

In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 4 min.)


hw07:  grades
due at your first class after Thursday, 2020-10-15 8:00 a.m.

expected to take 0.3 – 1.3 hours. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 3 min.) Compare your answers on hw06 ("realistic use of symbols") with my answers in Piazza@50.


Concepts to use:


1.  People in pd1: watch… (estimated time: 55 min.)  …this recording of pd3. The link to the recording apparently attracted a bot. Since the recording has served its purpose, it was deleted on 2020-10-17.


2.  Read new advice (estimated time: 15 min.)  …in preparation for being graded on it, as discussed in the classes and the recording of pd3. The important parts:


3.  Submit your time for this assignment in "Comments to teacher" on the homework server, in decimal hours rounded to the nearest tenth.


\(\sqrt{2}\) never quits. (optional extra education; estimated time: 9 min.) We discussed that a number's square root cannot be represented exactly in any number of digits, except for a number that is the ratio of perfect squares. The great Vi Hart dishes the dirt on Pythagoras and proves that there is no fraction that is the square root of 2.


hw06:  realistic use of symbols
due at your first class after Tuesday, 2020-10-13 8:00 a.m.

expected to take 0.6 – 0.8 hours. Record the time at which you start this assignment.


Concepts to use: (estimated time to read: 3 min.)


0.  NTTSTT, version 0 (estimated time: 12 min.)  Download and modify the program from class.

Add a standard header to the top of your file.

Eliminate violations of the rule that one should Never Type The Same Thing Twice. That is, deploy symbols, so that each coefficient is typed only once.

Develop incrementally. That is, start by replacing only one coefficient with a symbol. The answers should remain unchanged. When one replacement works, proceed to the next.

Eliminate the duplication of computing
        \( \sqrt{b^2 - 4ac} \)
as part of this work.


1.  Add text. (estimated time: 4 min.)  Augment your program with a call to display that produces
     One solution is approximately
in front of the first solution's value and
     The other solution is approximately
in front of the other.


2.  solutions to another equation (estimated time: 10 min.) 

Leaving previous code untouched, add code below that work, to bind new values to ab, and c. For the new values, use the coefficients of
      2.71828x2 + 7.64x + 1.616 = 0

Copy the solution-displaying Racket commands that you wrote for task 0 to the bottom of your file, below the define lines from that you just wrote for this task.

Do not modify the insides of the commands. Since you used symbols, there should be no numbers in those commands that need modifying anyway! That's the benefit of the work you did to use symbols.


3.  Is that right? (estimated time: 4 min.)  Check your answers for the second equation. Wolfram Alpha can help.


4.  Submit the file for this assignment to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 1 min.)


hw05:  symbol processing
due at your first class after Thursday, 2020-10-08 8:00 a.m.

expected to take 0.6 – 1 hours. Record the time at which you start this assignment.


Concepts to use:


0.  See the steps (estimated time: 5 min.)  in my version of Racket's processing of symbols, from hw04 and the following class, in the class notes.


1.  Start a word-processed document (estimated time: 1 min.)  in accordance with the standard instructions.


2.  instructions (estimated time: 3 min.)  …that aim to echo the steps we took in class. The "sample answer" below illustates following these instructions.

In your document, create three sub-sections for each of the numbered tasks that follow this one…

  1. Symbol-processing steps
    State the steps DrRacket follows to process the symbols, by quoting from the steps in the class notes.

    Retain the wording of "Racket's steps for processing symbols" whenever possible. You should augment that wording by…

    But eschew unnecessary re-wording.

    A student kindly contributed a solid example:

    language from Racket's steps for processing symbols:
    If a slot named for symbol is found, re-use that slot in the next steps.

    helpful re-wording:
    Since a slot named for penny is found, re-use that slot in the next steps.

    unnecessary re-wording:
    Since there is an entry in the symbol table with penny stored as the symbol, prepare that slot for use in the following steps.

  2. resulting symbol table
    Each define affects the symbol table, building on the effects from previous steps. So the contents of this section after the last numbered step will show the final form of the symbol table after all the entire program runs.

  3. output
    List output that results from the display functions. The output sections will grow, just like the other sections.

    The code snippets include
         (display "\n")
    to separate the pieces of output. Here's the classy way to show that you know the effect of these: paste a hooked arrow like this one
        
    into your word-processing document at the end of each line that DrR would produce, as shown in section C of the sample answer, below.

sample answer: understand the classes' answers for 3 lines of code


3.  define the symbol penny (estimated time: 6 min.)  In class we started applying Racket's steps for processing symbols to the following code snippet:

(define penny 27)       ; line 00
(display penny)         ; line 01
(display "\n")          ; line 02

Make sense of the following answer as you copy it into your document. The A, B, and C sections correspond to the instructions above.

3. define the symbol penny

A. Symbol-processing steps

for (define penny 27):

Look for penny in the symbol table.

Since no slot named for penny exists, reserve a new slot named for penny, and use the new slot in the next steps.

Evaluate the expression 27, resulting in the value twenty-seven

Store twenty-seven in the symbol table slot for penny.

for (display penny):

Look for penny in the symbol table.

Since a slot named for penny is found, replace penny with its value, 27, resulting in…
     (display 27)
Put dots of light in the interactions window that that look like 27

for (display "\n"):

Add a newline at the end of the output.

B. resulting symbol table
symbol value
penny 27

C. output

27

benefit from your experience in class

estimated time to read: 3 min.

Each of the following tasks adds another code snippet to the end of the program constructed by previous steps. So you can efficiently start your answer to each task by copying the answer to the previous task. Then you can add to each of the A, B, and C sections of the new answer. That is, each numbered task will have single A, B, and C section.

Since your answers will all start the same way, identify each with a big, red task number in its header, like the 3 in the sample answer.

Each line in the A sections ("Symbol-processing steps") should be a quotation from Racket's steps, with substitutions to tailor the quotation to the particular Racket code you are analyzing. For examples of these "tailored quotations", compare the A answers for the "sample answer", above, to the generic form of Racket's steps.

Workflow: In constructing answers, it helps to have three windows open simultaneously:

DrRacket offers a little help. You are welcome to run the code in DrR, but it will show you only the results. This assignment, in contrast, asks you to identify the steps that produce those results. DrRacket's output can help by serving as a check on your conclusions.

your turn

For each task, previously-analyzed code is shown in silver. Copy your answers for silver code from the numbered tasks before the current task!

4.  re-define a symbol (estimated time: 6 min.) 

(define penny 27)       ; line 00
(display penny)         ; line 01
(display "\n")          ; line 02

(define penny 1)        ; line 04
(display penny)         ; line 05
(display "\n")          ; line 06


5.  nickel computed from penny (estimated time: 4 min.) 

(define penny 27)       ; line 00
(display penny)         ; line 01
(display "\n")          ; line 02

(define penny 1)        ; line 04
(display penny)         ; line 05
(display "\n")          ; line 06

(define nickel          ; line 08
  (* penny 5)           ; line 09
  )                     ; line 10
(display nickel)        ; line 11
(display "\n")          ; line 12


6.  Define penny using penny? (estimated time: 4 min.) 

(define penny 27)       ; line 00
(display penny)         ; line 01
(display "\n")          ; line 02

(define penny 1)        ; line 04
(display penny)         ; line 05
(display "\n")          ; line 06

(define nickel          ; line 08
  (* penny 5)           ; line 09
  )                     ; line 10
(display nickel)        ; line 11
(display "\n")          ; line 12

(define penny           ; line 14
  (+ penny 7)           ; line 15
  )                     ; line 16
(display penny)         ; line 17


7.  effect on nickel (estimated time: 3 min.)  This last task is subtle and crucial. Apply the steps. Sweat the details.

(define penny 27)       ; line 00
(display penny)         ; line 01
(display "\n")          ; line 02

(define penny 1)        ; line 04
(display penny)         ; line 05
(display "\n")          ; line 06

(define nickel          ; line 08
  (* penny 5)           ; line 09
  )                     ; line 10
(display nickel)        ; line 11
(display "\n")          ; line 12

(define penny           ; line 14
  (+ penny 7)           ; line 15
  )                     ; line 16
(display penny)         ; line 17

(display "  nickel: ")  ; line 19
(display nickel)        ; line 20


8.  Submit a .pdf version of your document to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 2 min.)


hw04:  steps in symbol processing
due at your first class after Tuesday, 2020-10-06 8:00 a.m.

expected to take 0.8 – 1 hours. Record the time at which you start this assignment.


0.  review previous hw (estimated time: 7 min.) Compare your answers on hw03 ("expressions with comments") with my answers in Piazza@21–@19.


Concepts to use:


1.  Understand a demo program. (estimated time: 7 min.)  Download the program from class, run it, and finish it, all with the aim of understanding what Racket does to…

Questions? Piazza!


2.  Start a word-processed document (estimated time: 3 min.)  in accordance with the standard instructions.


3.  steps for binding (estimated time: 7 min.)  List the steps Racket follows when it binds a value to a symbol. Start your answer with…
     When Racket processes a define

Here and in the future, write steps in a numbered or lettered list. A list is easier to read and edit than a paragraph.

For items in a numbered list, programmers start numbering at zero. Welcome to the club! Any decent word processor will allow you to specify a list's starting value.

To visualize "the steps Racket follows" it may help to think about writing instructions that could be followed by an eight-year-old who read instructions extremely carefully, interpreted them extremely literally, but had no common sense and was too uncooperative to exercise it if they had any. Think Amelia Bedelia on steroids, but without the good intentions.


4.  steps for retrieving (estimated time: 7 min.)  List the steps Racket follows when it processes a symbol in an expression.

When a symbol appears in an expression, the program is requesting that Racket retrieve a value that was bound to a symbol in a previous step. Every appearance of a symbol is such a request, except the appearance of a symbol as the first argument in a define.

Start your answer with…
     When Racket processes a symbol that appears in an expression…


5.  Find and fix the errors in your steps (estimated time: 20 min.)  …by following those steps for the program below. Keep track of the symbol table and the displayed values on two separate pieces of paper.

Recall that a symbol table is the table in a computer's main memory that stores pairs, each one of which comprises…

To understand Racket's processing you must turn off your intuition of what could happen. Instead you must understand Racket's steps and apply them as if you were as mindless as a computer. This routinely surprises new programmers. Following rules is harder than it sounds.

(define penny 27)       ; line 00
(display penny)         ; line 01
(display "\n")          ; line 02

(define penny 1)        ; line 04
(display penny)         ; line 05
(display "\n")          ; line 06

(define nickel          ; line 08
  (* penny 5)           ; line 09
  )                     ; line 10
(display nickel)        ; line 11
(display "\n")          ; line 12

(define penny           ; line 14
  (+ penny 7)           ; line 15
  )                     ; line 16
(display penny)         ; line 17

(display "  nickel: ")  ; line 19
(display nickel)        ; line 20

Run the program. Fix your steps until you generate output that matches DrRacket's.


6.  Submit a .pdf of your word-processed document to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 3 min.)


If you joined your current class after its first session read these notes to get yourself and me on track.


hw03:  expressions with comments
due at your first class after Friday, 2020-10-02 8:00 a.m.

expected to take 0.7 – 0.9 hours. Record the time at which you start this assignment.


Concepts to use:


0.  review previous hw (estimated time: 7 min.) Recall the aim of reviewing homework. Compare your answers on hw02 ("expressions") with my answers, available via the class notes for the most-recent class.


1.  Racket → infix (estimated time: 5 min.)  Hand-write your results for this task on a piece of paper, preferably in your notebook. The last task in this assignment asks you to submit a .pdf of your work.

Use a pencil and eraser. Cross-outs are unacceptable on this work. As we have discussed in class recently, students must strive to make grading easy for teachers, just as teachers must strive to make learning easy for students.

Express the following Racket code…

(/ (* (abs -7)
      (sqrt (+ 12 4))
      )
   5 4 3 2 1
   )

…in standard infix notation, using the arithmetic operators
   () + – × ÷   |absolute value|   √  
Use the normal, seventh-grade rules of precedence and associativity to eliminate redundant parentheses. Make no algebraic simplifications. Do no arithmetic.


2.  new .rkt file, with header comments (estimated time: 6 min.)  In DrRacket, start a new file named hw03_commentedExpressions.rkt

Begin the file with comments giving our standard header, by tailoring the following template appropriately.
Type the text shown in this font.
Substitute your information for text shown in this font.

NameYouWantToBeCalled   FamilyName   <account@stuy.edu>
hwnumber
worked with Names of classmate(s)
advised by Names of advisor(s)

For example:

Bill Withers <WWithers@stuy.edu>
hw03
worked with Ace Studentinintro
advised by Grace Cantarella, Michael "The TA" Borczuk

Are you raising your incremental development game? Good.
So what do you expect when you run the program written so far?
What does DrRacket produce?


3.  more infix → Racket (estimated time: 6 min.)  In the definitions pane of a new .rkt file, do the two problems from a previous semester's test.

Make no algebraic simplifications. Do no arithmetic. Instead, program Racket to evaluate the entirety of each expression.

Precede each solution with a comment giving its task identifier, like
     task 3a
     task 3b

  1. \( \sqrt{ 13^2 - 12^2} \)

  2. \( \dfrac{ 11 \div 22}{ 5^{2.5} - 123} \)


4.  Piazza party (estimated time: 20 min.) This course makes extensive use of an online forum called "Piazza". This task asks you to activate your account and make a first contribution.

Activate your Piazza account using the email sent to you from Piazza.

Set your profile to use the first and last names that you are known by in class, to aid communication and promote collegiality.

Read these notes on how Piazza is to be used in this course. As an incentive to students who are motivated by grades, part of the homework grade covers following the advice on this page.

Use good wiki etiquette to contribute 7 minutes of thought and writing on one of the existing discussions, or start a new one. This work should ensure that you are familiar with Piazza, before you have a need for it.

optional extra education: Piazza founder Pooja Sankar writes about studying comp sci in college as a woman in India, and how Piazza can help. (estimated time: 2 minutes).


5.  Submit your work (estimated time: 6 min.) …for this assignment to the homework server. There are two slots for this assignment; you are asked to submit a file to each of them:

Since having two slots increases the complexity of the submission a little, check your work, by visiting the "View homework" menu on the homework server. I aim to check also, but I charge Points for errors I find.


If you joined your current class after its first session read these notes to get yourself and me on track.


hw02:  expressions
due at your first class after Wednesday, 2020-09-30 8:00 a.m.

expected to take 0.5 – 0.7 hours. Record the time at which you start this assignment.


Concepts to use:


0.  definitions window → file → definitions window (estimated time: 3 min.) 

  1. In DrRacket, in the upper pane — which is called the definitions window — paste this classic, one-line program:
         (display "hello, world")
    Use the Racket → Run command to see what it does.

  2. Save your nascent definitions in a file called expressions.rkt

  3. Close DrRacket, re-open your expressions.rkt file and verify that it still runs.
    Problems you can't solve? Post on the chat!

There is no need to save the results that you see in the interactions window (that is, the lower pane) since you can always reproduce them by re-running the code that is in the definitions window.


1.  Learn a few arithmetic procedures (estimated time: 11 min.)  Understand each of the following arithmetic procedures by creating one or more examples of each in the definitions window of your expressions.rkt

Pro tip:
To speed your work, create an example for just one procedure, and run the resulting program. Repeat that process, adding examples one at a time, alternating with running the enhanced program. This process — taking tiny steps and testing each — is so beneficial that programmers have a name for it: incremental development.

One could write all the code at once. I understand the temptation, since I used to make that mistake myself. But if you have other things to do in your life — sleeping, for example — you can program more efficiently using incremental development.

The first 4 procedures are n-ary, so make examples that demonstrate that feature.
    *
    /
    +
    -
  sqrt  
for square-root
  abs    for absolute value
  expt   for exponentiation


2.  infix → Racket (estimated time: 15 min.)  Still working in the definitions window, add to your expressions.rkt file. Write code to compute and display each of the following expressions. Do none of the arithmetic in your head. Rather, tell Racket to do it all.

  1. \(\dfrac{4}{3.2+0.8}\)   Check your work, of course.

  2. \(5^2 - \frac{4}{3.2+0.8}\)

  3. \( 16 + 8 \times -\sqrt9 \)      

    Demonstrate your negation skillz.

  4. \( \dfrac{5^2 - \frac{4}{3.2+0.8}}{16 + 8 \times -\sqrt9} \)


3.  Submit expressions.rkt to the homework server. In "Comments to teacher", tell me how long this assignment took, in decimal hours rounded to the nearest tenth. (estimated time: 2 min.)


If you joined your current class after its first session read these notes to get yourself and me on track.


hw01:  starting with DrRacket
due at your first class after Friday, 2020-09-25 8:00 a.m.

expected to take 0.6 – 0.8 hours. Record the time at which you start this assignment.


Concepts to use:


0.  Understand a rule for processing prefix notation (estimated time: 15 min.)  This is a big deal. We went over it in class, But unless I already knew that rule, I still wouldn't. (I remember when Professor Acton explained it in my first year of college, and the pain persists. But you can be a better student than I was, by reviewing the topic before using it in the rest of this assignment and the remainder of your programming career.)

Read my notes from that lesson. I expect this reading to take you about 15  minutes. If you spend much less on it, you're wasting your time.


1.  Download and install DrRacket (estimated time: 8 min.)  from from here.


2.  Start DrRacket (estimated time: 3 min.)  Then use the LanguageChoose language menu to select "other languages", and then the legacy language R5RS. Then select RacketRun. This should leave the bottom pane showing…

DrRacket window

You don't want to see a mostly-black window without the two horizontal panes, without the menu, the language, etc., like…

wrong command: racket, not DrRacket

Windows like that result from the wrong start-up command:
     Racket  (without the "Dr"),
instead of the correct command:
    DrRacket
Here's a screen shot of the Windows Start menu, with the right and wrong selections identified:
Windows Start menu selections


3.  Use parentheses (estimated time to read: 2 min.)  To do calculations in Racket, you need one more fact, beyond those we discussed in class on Wednesday/Thursday:
     Type parentheses around expressions.

Background:
We discussed that Racket requires prefix notation, and that the asterisk ("*") means "the product of…". So prefix notation for 13×5 is
     * 13 5

The new fact:
Surround that expression with parentheses:
     (* 13 5)
This rule applies to expressions that are within expressions, too, as you can see in the examples below.


4.  Try it! (estimated time: 7 min.) In the bottom pane, type

(- 2 10)

The spaces matter. Press enter. Expect to see…
2 - 10 calculation

Try two more, after predicting their results.

(* 13 5)
(- 2 (* 13 5))

Make up an expression of your own, predict its result, and see its result.


5.  Submit the result (estimated time: 2 min.) 

  1. Use a mouse to highlight, and copy the text from DrRacket's bottom pane. Start with…

    Welcome to DrRacket, version something [3m].
    Language: R5RS; memory limit: 128 MB.
    > (- 2 10)
    -8

    Include the rest of your work, including the "expression of your own" and its result. Paste your copy into the hw server's "Comments to teacher".

  2. At the end of that comment, post how long this assignment took, in decimal hours rounded to the nearest tenth.


If you joined your current class after its first session read these notes to get yourself and me on track.


optional entertainment Xkcd humor often requires education to appreciate. (I've learned plenty by working on understanding it.) But now that you know that reverse polish notation is another name for postfix notation, you might enjoy this classic and an explanation of it.


hw00:  get organized
due at your first class after Wednesday, 2020-09-23 8:00 a.m.

expected to take 1 hour.


0.  introduce yourself (estimated time: 2 min.) by filling out this form.


1.  change your password on the homework server (estimated time: 2 min.) Your password is initially your 9-digit OSIS.

Only the password fields need changing.
      profile page


The rest of the assignment is one more click away.

There is nothing to submit for this assignment.