Lecture 1: What is Computation? What is Programming? Processing Numbers

###
Lecture 1: What is Computation? What is Programming? Processing Numbers

1. Why should anyone take a course with this title?

       required for degree    to learn to THINK	to study the nature
       earns money	       (computationally)	 of human thought

       "I take one course                              brain activity and
       and earn some money"				esp consciousness
       -- a criminal					is _computation_
       illusion                                        (humanities/social sciences)

2. The two strange words in the title are "computation" and "programming". What is computation?

   Let's calculate the wage of someone working at minimum wage (5.65). What do we need to know? The number of hours. Here we go:

       if it is  2 hours, then 5.65 * 2  = 11.30
       if it is 10 hours, then 5.65 * 10 = 56.50
       if it is 12 hours, then 5.65 * 12 = 67.80

   Let's calculate the area of a disk. What do we need to know? The radius. Here we go:

       if it is  1 [cm], then pi * (1  *  1) ~   3.14
       if it is 10 [cm], then pi * (10 * 10) ~ 314
       if it is 11 [cm], then pi * (11 * 11) ~ 317.14

   Computing is the process of determining the result of an algebraic expression. The difference between high school and computing science is that the former teaches an algebra of numbers and the latter generalizes this to an algebra of information (numbers, truth, names, positions in space, streams of measurements, etc).

3. What is programming? Let's formulate a rule that explains how we can determine the wage, area of disk, in general.

   Let h stand for the number of hours. Then 5.65 * h is the wage.

   Let r stand for the radius. Then pi * (r * r) is the area of a disk.

   Exercise: Let f stand for a temperature measured in Fahrenheit. What is the temperature in Celsius? Answer: 5/9 * (f - 32).

   Here is one of many mathematical short-hands for rules:

       wage: h |--> 5.65 * h

       area-of-disk: r |--> pi * (r * r)

   It names the rule, then the unknown quantity, and the algebraic expression behind the arrow says how to determine the result.
4. Okay, let's communicate this to a computer. We use Scheme because it is so unbelievably close to what we just discusssed. Here we go:

       (define (wage h) (* 5.65 h))

       (define (area-of-disk r) (* pi (* r r)))

   What's this about? Expressions are prefix. They all start with "(" and a word that says what comes next. For example, define says that we are defining a rule. Explain (wage h). Similarly, * says that we are mulitplying two quantities.

   Of course, for basic expressions like numbers and names, we don't need parentheses.

   Let's compute in Scheme:

         (wage 2)
       = (* 5.65 2)
       ~ 11.30

         (area-of-disk 10)
       = (* pi (* 10 10))
       = (* pi 100)
       ~ 314

   Of course, we don't have to do any of that. DrScheme (a computer program) knows about Scheme and does all that for us:

       > (wage 2)
       11.30

       > (area-of-disk 10)
       ~ 314

   In Lab, we learn how to do this in conjunction with the computer.

   Why this funny Scheme notation?

5. READINGS: Sections 1 through 6 in HtDP by Monday

Matthias Felleisen | This page was generated on Fri Mar 5 09:04:41 CST 1999.