# iteration and conditionals Friday, 2021-01-15

## semantics of forever buttons

A forever button causes NetLogo to…
execute the button’s commands
over and over
as fast as permitted by the "speed" slider
until the button is un-pressed.

## ifelse

### semantics

example from Social Sciences | Segregation model

### syntax

ifelse true-or-false-value
[ actions-if-true ]
[ actions-otherwise ]

### examples

Paste the following line into NetLogo's Command center:
ifelse 0 < 1 [show "arithmetic works"] [show "We're in trouble, Spock"]

When you understand the result, play with the code to execute the actions-otherwise.

The true-or-false-value expression can be powerful. Predict and check the results of…
ifelse 555 < 1 or 15 mod 5 = 0 [show "so true"] [show "nope"]

# structuring questions for programming with random Wednesday, 2021-01-13

Programmers use random to produce an integer chosen at random from a specific desired range, like the range [-4,7] that we discussed in class.

Writing the correct expression used to bother students, apparently because they had trouble breaking down the task in to its parts. The following three questions lead you through the relevant steps:

1. How many possibilities are there?

That number is the argument to random.

2. What is the result of a call to random with that value?

Answer in a full sentence of the form…
"Random ?? produces one of the ?? integers from the range [??,??]"

3. What operation(s) will convert that range to the desired range?

Write the NetLogo code that performs that operation.

# sensitivity analysis Wednesday, 2020-12-23

At least 13 people have contributed to the Piazza thread on "sensitivity analysis": crowdsourcing hw29#3. I am grateful for their help to my understanding and others'.

One paper describes the motivation and benefits of sensitivity analysis particularly helpfully:

To study a process, it is often necessary to develop a mathematical model to represent the process and to use a computer program to implement this model… Due to the possibly significant expense of running such models and the often much greater expense of collecting appropriate data for use as model input, it is important to have efficient techniques to examine and assess the influence of model input on model output. That is, it is important to be able to perform sensitivity analyses on the relationship between information supplied to a model and predictions made by the model. The benefits of such analyses include the following:

1. an indication whether the model operates as intended,
2. identification of unimportant variables or unnecessary model complexity, and
3. an assessment of relative input variable importance for guidance in data collection.

The expression sensitivity analysis is widely understood to mean the study of variation in model output with respect to input… to answer the following questions.

1. What variables have a significant effect on model output and what is their relative importance?
2. What relationship exists between the distributions of model input and output?

— Iman, Ronald & Campbell, J. & Helton, J.. (1981). An approach to sensitivity analysis of computer models. I-Introduction, input, variable selection and preliminary variable assessment. J. Qual. Technol. 13. 174-183.

Emphasis has been added to the technical term sensitivity analysis

A tutorial on sensitivity analyses in clinical trials helpfully provides more motivation and many examples in a 7-minute reading of its sections on…

• Background
• What is a sensitivity analysis in clinical research?
• Why is sensitivity analysis necessary?

The explanations concern checking results of clinical trials, rather than models. But the two overlap significantly, in my understanding.

# grades in marking period 2 Wednesday, 2020-12-16

## What is the primary component of these grades?

The most heavily-weighted assessment of a student's work in marking period 2 was the fraction of the required homework assignments that a student submitted. Counting the optional revision to hw13, grades on this assessment range from 0% to 110%. The assessment appears in JupiterEd under the name "hw12-21", since it covers homework assignments 12 through 21, inclusive.

Inaccuracy is inevitable when a grader tries to assess the knowledge in a student's head. Counting submissions has the advantages that it fit in the time I allocated to the grading, and historically a count has been a reasonable proxy for students' learning, correlating well with test scores. This grade can be expected to have overstated some students' learning, since it ignored the content of submissions, but it seems accurate at the low end of the scale: students who do little homework can expect to learn little.

I intend to grade more of the work from marking period 2, which is likely to provide two benefits:

• Some students' learning is under-represented by their work on hw05. The additional grading on homework they did better will dilute the grade on hw05.

• Sadly, some students dishonestly submit files that reflect no work and, therefore, no learning. Others deceptively submit copied files, without learning. I aim to spend my time working for the benefit of honest students who are making the large efforts that learning requires, so we must tolerate the cheaters. But when further review of homework from marking period 2 shows bad practices by a student, the student's hw12-21 grade will be assessed accurately, lowering the student's average significantly.

Grades don't matter to the DOE administration. They communicate this message implicitly but clearly, not just once, but via many of their choices. Some students, caregivers, and teachers disagree with those priorities. But my responsibility is to work within this system. Struggling against it would be foolish, frustrating, and ineffective, so I seek to avoid making that error. I commend a similar approach to you.

On the positive side, students who are more interested in education than in grades benefit from diminished emphasis on grades. For every teacher, time is the scarcest resource. So time saved by de-emphasizing grades can be directed toward aiding learning.

## To what extent can a student raise their average?

Raising an average therefore requires…

• good work from the student and
• time from me to grade everyone's work.

In fairness, I will grade an assignment for everyone or no one. Grading individual extra credit work would violate that fairness. I plan to spend no more time re-grading already-graded work.

## Piazza is the best forum…

…for seeking clarification of this post. Anonymity will be respected.

There is already a list of students and caregivers who want time spent on discussing individual grades. Those requests are reasonable only for issues that apply only to that individual. Efficiency requires using Piazza to ask questions that could apply to others.

Caregivers can benefit students' education by adopting the same approach. Some caregivers will choose otherwise. It is part of my job to communicate with caregivers, and I will fulfill that responsibility, even at the cost to the education and grades of interested students. But there are grounds for optimism that many caregivers will cooperate with these priorities, as many have in the past.

For example, caregivers have asked students to post questions on Piazza and communicate answers, as part of the communication between them. (Caregivers lack direct access to Piazza, in keeping with privacy considerations for minors.)

# What is falsifiability? Wednesday, 2020-12-02

## Holmes's understanding

To make a statement that is considered meaningful in a scientific context, you must be able to imagine some evidence that you would regard as showing the statement to be false.

For example, the statement "All swans are white" is meaningful because it is falsifiable, that is, because we can imagine finding a black swan, and, if we did find a black swan, we would regard that evidence as showing the statement to be false.

The statement is falsifiable whether or not…

• you have found a black swan; or even
• there are any black swans.

Rather the statement is falsifiable (and therefore considered meaningful) merely because we can imagine some evidence (seeing a black swan) that would show the statement to be false.

In contrast, if I make a statement and cannot imagine any evidence that I would regard as falsifying the statement, you might regard my statement as meaningless.

For example, the statement "The earth is only 4,000 years old" fails falsifiability. Adherents to that young-earth idea reject the evidence of much-older fossils, saying that the earth was constructed 4,000 years ago with those fossils constructed to look as if they were much older. The same rejection applies to all other evidence of an older earth. The rejection is logically consistent — a tricky, powerful deity could have created the earth to fool us — but the same approach would justify saying that the earth is only four seconds old, or that the earth is just a trick being played on your mind, and that yours is the only mind that exists. A statement that no evidence can refute can be fun or valuable to think about, but it has no meaning in a scientific context, where we assess truth by looking for contrary evidence.

## more, from Martyn Shuttleworth, Lyndsay T Wilson, writing for Explorable

Falsifiability is the assertion that for any hypothesis to have credence, it must be inherently disprovable before it can become accepted as a scientific hypothesis or theory.

Importantly, falsifiability doesn’t mean that there are currently arguments against a theory, only that it is possible to imagine some kind of argument which would invalidate it. Falsifiability says nothing about an argument's inherent validity or correctness. It is only the minimum trait required of a claim that allows it to be engaged with in a scientific manner — a dividing line between what is considered science and what isn’t. …

The idea is that no theory is completely correct, but if it can be shown both to be falsifiable and supported with evidence that shows it's true, it can be accepted as truth.

For example, Newton's Theory of Gravity was accepted as truth for centuries, because objects do not randomly float away from the earth. It appeared to fit the data obtained by experimentation and research, but was always subject to testing.

However, Einstein's theory makes falsifiable predictions that are different from predictions made by Newton's theory, for example concerning the precession of the orbit of Mercury, and gravitational lensing of light. In non-extreme situations Einstein's and Newton's theories make the same predictions, so they are both correct. But Einstein's theory holds true in a superset of the conditions in which Newton's theory holds, so according to the principle of Occam's Razor, Einstein's theory is preferred. On the other hand, Newtonian calculations are simpler, so Newton's theory is useful for almost any engineering project, including some space projects. But for GPS we need Einstein's theory. Scientists would not have arrived at either of these theories, or a compromise between both of them, without the use of testable, falsifiable experiments.

# What instructions would direct a disk-moving robot? Monday, 2020-11-16

To move 2 disks from Hanoi to Da Nang using HCMC if required:

Move the top disk from Hanoi to HCMC.
Move the top disk from Hanoi to Da Nang.
Move the top disk from HCMC  to Da Nang.

To move 3 disks from Hanoi to HCMC using Da Nang if required:

Move the top disk from Hanoi   to HCMC.
Move the top disk from Hanoi   to Da Nang.
Move the top disk from HCMC    to Da Nang.
Move the top disk from Hanoi   to HCMC.
Move the top disk from Da Nang to Hanoi.
Move the top disk from Da Nang to HCMC.
Move the top disk from Hanoi   to HCMC.

The extra spaces that align the text have been added only to help human readers. A robot would not care about them. So the procedure you write need not produce them (and there is not much interesting to learn by doing so).

# understanding grades for hw05 Wednesday, 2020-11-04

Low grades on hw05 resulted mostly from either…

• not doing the assignment, or…
• failing to read its directions.

Students already know when they spent sub-standard effort on hw05, and they can understand the failure to follow the directions by comparing their work with the answers in hw12#6. Yet many students are requesting a breakdown of their grade on hw05 without making that effort to understand. Here is a plan for addressing these requests at a tolerable cost to students who are focused on new learning:

1. My next step in this process is to finish the detailed grading of all submissions. To meet the deadline for report cards in marking period 1, I calculated approximate grades for some submissions, based on a seven-element rubric. The affected students are due a grade based on the full 35-element rubric.

2. People who want to understand the breakdown of the grade before I am finished can achieve that understanding by some combination of…

• doing the thinking associated with hw12#6
• consulting with classmates, perhaps by posting their answers to hw05 and hw12#6 on Piazza.
3. Students whose self-assessment diverges significantly from mine can dispute my judgment in the standard way, with the standard caveat: "Your grade may go up or down."

4. If a substantial number of people dispute my judgment, I can develop technology to disseminate the breakdown of the hw05 grades to all students. That development seems a low-value way to spend time that could be directed to helping students learn. So we all benefit if students and caregivers can be satisfied with their self-assessment and my judgment.

On the other hand, I love programming, and colleagues Peter Brooks and JonAlf Dyrland-Weaver have provided facilities and ideas that I can build on. In this remote learning environment, we must all accept diminished education for students anyway, so the inefficiency of writing these notes and dissemination technology is presumably acceptable to the people who make it necessary.

The good news mixed into this dubious allocation of time is that students can learn through self-assessment, whether they are interested in computer science knowledge or only the Points. This learning was explained well by a student who submitted a self-assessment:

I found this self-assessment of hw05 to be really helpful. I can see a lot of places that I missed or did wrong in my homework by comparing them to the answers. Even though the grade didn't come out as I… expected, now I know what are the spots that I need to improve and put down extra effort on.

# how Racket invokes a procedure Friday, 2020-10-23; Monday, 2020-10-26

0. Copy
the value of each argument from the invocation
into
the corresponding parameter of the procedure.

1. Evaluate the expressions in the procedure, using the copied values.

2. Replace the invocation with the last value computed by the procedure.

Understand the meaning of all these terms. Notice the strong parallel in the structure to what you already know about invoking a mathematical function from hw08#5. If there are any gaps in your knowledge, write questions in good English in your notebook page for the next class. One semester a surprisingly large number of people tried to memorize the text without understanding it. As you can imagine, that half-effort helped little in understanding computer science.

In step 0, "corresponding" implies…
copying the value of the 1st  argument into the 1st  parameter;
copying the value of the 2nd argument into the 2nd parameter;
…and so forth.

In comp sci jargon, the "Replace the invocation" in that last step is called returning  the value. It's a fairly descriptive term, since the value is sent back to the place where the procedure was invoked, and processing continues from there.

Pay attention to your English when you use "replace" and "substitute", since this is a common stumbling block.

We use the word "for" with "substitute", as in the example in this dictionary. Other examples:

Similarly, if someone says "The argument value 5 has been substituted for the parameter x in the expression x+2", you evaluate 5+2.

The verb "replace" conveys a direction similarly. So all of the following suggest the same substitution of an argument value for a parameter:

• Replace the parameter x with the argument value 5.
• The parameter x is replaced by the argument value 5.
• The argument value 5 replaces the parameter x.

The key point: both "replace" and "substitute" convey a direction, a sense of which entity is in place after the action. Students and sports fans can remember that direction by thinking of human replacements.

Students ask why they should memorize this description, rather than writing their own. Here's why: it is hard to create your own description that is at least as correct as this one. It requires acquiring the knowledge and conveying it correctly, which is much more work than memorizing my description. I think the complainers actually mean "I would prefer to skip the work and just wing it," which is unlikely to result in developing a correct understanding.

You can handle the memorizing; it's only 40 words. Macbeth has 5,296. As the prince told the actors, "Speak the speech, I pray you, as I pronounced it to you".

Human brains seem to be hardwired for music. One student who is wired better than most of us created this, with some help from Taylor Swift's "You Belong With Me". Bring up the lyrics and sing along.

# build and invoke a procedure Monday, 2020-10-19; Tuesday 10-20

Today's lesson provided two related examples:

1. build a procedure
2. invoke a procedure after building it

Read the comments. Paste the code into DrRacket's definitions window. Observe the correspondence between
the Racket procedure built here
and
the math function, f, in the note below.
Play with the code, for example to create a list of three parameters and compute their average.

The code below shows its results by invoking display, in compliance a simplifying rule in this course: Always invoke display when you want DrRacket to produce output. Yes, DrRacket will produce output for some code that omits display, but understanding when and why is much more complicated than wrapping an invocation of display around a value you want displayed.

## 0. build a procedure

(display   ; means "Display the following value"

; Build a procedure
(lambda  ; the procedure that builds procedures
(start)    ; ...to accept 1 parameter, named "start"
(+ start 2)   ; ...and calculates a value 2 larger.
)         ; end of the building

)  ; end of display

## 1. invoke a procedure after building it

Recall the parts of an invocation like
(sqrt 36)

• code that refers to the procedure, sqrt in this case
• followed by argument(s), 36 in this case
• all surrounded by parentheses.

That pattern is repeated below:

• code that builds a procedure,
(lambda (start)
(+ start 2)
)
in this case
• followed by argument(s), 7 in this case
• all surrounded by parentheses.
(display   ; means "Display the following value"

(   ;means "invoke a procedure"

; Build the procedure that will be invoked
(lambda (start)
(+ start 2)
)         ; end of the building

7  ; Supply 7 as an argument to the invocation
)  ; end of invocation

)  ; end of display

# functions: notation and terms Thursday, 2020-10-15; Friday, 10-16

…and subsequently co-opted for computer languages.

The symbols on the left are just mathematicians' shorthand for an English statement like…

Define a function named f
that requires a single argument
and maps the value of that argument
to the value that is 2 larger than that argument.

What is meant by $$f(11-3)$$? This indicates an invocation of function f, but with an argument that comprises a subtraction operation, rather than a constant. Does it mean that the subtraction happens first, and f is invoked on the result, like
$$f(11-3) = f(8) = 8+2 = 10$$    [choice A]?
Or does it mean that the subtraction operation is passed to f and evaluated with the addition that is part of the definition of f, like
$$f(11-3) = (11-3)+2 = 10$$    [choice B]?
Answer: for all the computer languages I'm familiar with, the answer is "choice A": put the invocation on hold, do the nested operation, and pass the resulting value to the function.

Which of these does a mathematician mean, if either? I was ignorant, but ignorance is remediable since we have a Mathematician on Speed-Dial for this course! I offered her choice A, choice B, plus bonus choices…

1. Who cares? When we say that an expression "equals" a value, we mean that the expression and the value are the same thing. There is no distinction to be drawn here.

2. What are you even talking about with this "before" and "after" stuff? Math is eternal; there is no time dimension. Yes, in the lesser world of computer programs, calculations happen in some order, but such considerations are beneath my contempt.

3. other

and asked "when you write an expression as the argument to a function, what do you aim to communicate to the reader?"

Check out the precision in her answer:

I guess I think the answer to be [choice] A but with an amendment. I think $$11-3$$ can be passed to f without being evaluated. But, even if $$11-3$$ is an unexamined expression that is passed into f to obtain $$(11-3) + 2,$$ in order for this expression to be evaluated $$11-3$$ has to be evaluated first. The parenthesis that gets added in, when we say
$$f(11-3) = (11-3)+2 = 10$$    [choice B]
is just a way to communicate that $$11-3$$ has to be evaluated first.

As to: "when you write an expression as the argument to a function, what do you aim to communicate to the reader?" I'm not sure that writing an expression as an argument is a good way to write math. Not that it's wrong just not wise. I think :)

# rubric for hw00 Wednesday, 2020-10-14

JupiterEd has been updated to reflect each student's grade for hw00, assessing one point for each of the following five items:

• name / pronoun data in the "introduce yourself" form
• submit caregiver's receipt

The last of those points reflects an assumption that the student did the reading. If a student's subsequent actions demonstrate ignorance of the content, the grade on hw00 will decrease. For example, the class home page has instructions for writing email.

The average of the grades across all classes is 89%. Ninety-nine people scored 100%.

# Racket's steps for processing symbols Tuesday, 2020-10-06

Symbol processing has two purposes:

• to store values for later use, by associating them with symbols
• to retrieve values when a program requires that.

## steps for binding

The steps in this section describe Racket's processing of
(define symbol   expression )
Here is an example define that binds the value 27 (a very simple expression!) to the symbol penny:
(define penny 27)

Racket's steps:

1. Look for symbol in the symbol table.

1. If a slot named for symbol is found, re-use that slot in the next steps.

2. Otherwise (that is, if no slot named for symbol exists), reserve a new slot named for symbol, and use the new slot in the next steps.

2. Evaluate expression.

3. Store the resulting value in the symbol table slot for symbol.

## steps for retrieving

Programmers type a symbol name in an expression when they want to retrieve the value that was previously bound to that symbol. For example, the following invocation displays the value of a minimal expression, comprising only the symbol penny:
(display penny) # see the value that was bound to penny

Racket's steps:

1. Look for symbol in the symbol table.

1. If a slot named for symbol is found, replace the symbol with its value.

2. Otherwise (that is, if no slot named for symbol exists), tell the programmer
symbol: undefined;
cannot reference an identifier before its definition

## thinking that can aid learning

In both binding and retrieving, Racket starts its processing with "Look for symbol in the symbol table." Notice how subsequent processing diverges.

In each entry, make sense of the differing consequences when an entry is found versus when no entry is found. Why is the difference reasonable?

# syntax for define Friday, 2020-10-02

(define symbol   expression )
Type the text shown in this font.
Substitute appropriate Racket language for text shown in this font.

Here is an example that binds the value 5 (a very simple expression!) to the symbol nickel:
(define nickel 5)

# expressions, continued Wednesday, 2020-09-30 & Thursday, 10-01

## expression vs. equation

### expression

"combination of symbols [that] designate numbers (constants), variables, operations, functions,… grouping…"

Wikipedia, of course

### evaluate an expression

interpret the expression using a particular value for each variable. (An expression can include more than one variable.)
The interpretation results in another value.

— based on WP

### equation

a statement asserting equality between 2 expressions
To be interesting or useful, an equation contains variable(s).

— based on WP

### solve an equation

Find the values for the variables that make the equality true.
Those values are called solutions to the equation.

WP

# evaluating prefix notation Wednesday, 2020-09-23

## Why should I care?

The following rules are simple, but must be followed carefully. That makes them well-suited to computers, but requires humans to slow down and be more careful than most people are used to. You can do this.

That care is worth the effort required. The put-on-hold idea below lies at the heart of how computers process every program that is large enough to be interesting. So learn the idea here, on arithmetic that you understand well.

## the rule

Read the expression left-to-right, just once.

1. Recognize the procedure (+, /, etc.)

2. Process each of the for that procedure.

Argument has the same meaning here as it does in a math class when you're talking about functions. An argument is an input to the function, one of the values that the function operates on.

For example, when a second grader says they will "add 3 and 4", a person thinking in function terms says they are sending the addition procedure the values 3 and 4 as arguments.

Why learn the new language? Answer: because we can extend it beyond arithmetic operations without the challenge of learning a new concept. Understand it here! Then stay tuned for the extension.

(Click on the button again to hide this explanation, so it's easier to understand the rule.)

Each argument can be one of only two types:

1. If the argument is a single value, like –2 or 6.02e23, just use it.

2. Otherwise, the argument will be another procedure (+, /, etc.). In this case, put the outer procedure on hold, evaluate the new procedure by applying these same rules, and use the resulting single value as an argument to the outer procedure.

3. Having processed all the arguments' values, apply the procedure to them, resulting in a single value.

## examples of applying the rule

Slowly and carefully work through how the rule achieves the desired result in these two examples. This takes serious thinking, but sadly, learning requires thinking.

### + 4 007

Recognize "+" as the name of the addition procedure.

Process 4 as the first argument, having the value four.

Process 007 as the second argument, having the value seven.

Having processed all the arguments' values, you (or the computer) can apply the additon procedure to them, resulting in the value eleven.

### + 4 / 10 2.0

The parts in silver are copies from the previous example. Nothing new here.

Recognize "+" as the name of the addition procedure.

Process 4 as the first argument, having the value four.

Recognize "/" as the name of the division procedure, rather than a single value. So apply the rule to this sub-expression.

Process 10 as the first argument, having the value ten.

Process 2.0 as the second argument, having the value two.

Having processed all the arguments' values, you can apply the division procedure to them, resulting in the value five.

Use five as the an argument to the outer addition procedure.

Having processed all the arguments' values, you can apply the addition procedure to them, resulting in the value nine.

## Notice…

The first example,
+ 4 007
might seem more detailed than you are use to, but any competent second-grader could do it.

The second example,
+ 4 / 10 2.0
is longer, but the parts are just as simple to process! This is where you get paid for understanding the rule: it works on an arbitrarily complicated expressions…

• without hairy rules about operator precedence (like these from the Perl language),
• without mentioning the ugly word,
• without scanning back and forth for parentheses, as in 3 / (4 – (5 + 6)) + 7, and
• without grouping left-to-right sometimes (4–5–2) and right-to-left other times ($$2^{2^3}$$).

Computer programmers like simple rules. Their simplicity makes them easy to write instructions for, which a computer can follow. The lengthy processing is fine with us, because the computer does the processing. All hail Jan Łukasiewicz!

# course outline Monday, 2020-09-21

Intro: how to succeed in courses like this one

Programming in Racket

an elegantly simple programming language

relatively small number of rules for writing valid instructions

focuses concentration on the elements of programming

Programming in NetLogo

a powerful, graphics-oriented language

simulations

with great power goes great complexity

## define computer science

Computer science is the study of
solving problems
by writing a sequence of unambiguous instructions
to perform calculations and choices based on the results of those calculations

The above is the result of my coalescing the definitions that emerged from five periods. Improvements are welcome.