CS200: Computer Science, Spring 2002

Notes: Friday 25 January 2002
Schedule
 Now: Problem Set 1
 28 January: Read SICP, 1.2
 30 January: Read GEB, Little Harmonic Labyrinth and Chapter 5
 1 February: Read SICP, 1.3
 4 February: Problem Set 2
Reading Guide As you read GEB chapter 5, here are some things to think about:
 How do the Recursive Transition Networks he uses to describe languages compare to the Backus Naur Form we saw in class? Can any Recursive Transition Network be rewritten as in Backus Naur Form? Which notation is more compact? Which notation is easier to understand?
 Can you translate his definition of FIBO (p. 136) into a Scheme procedure that calculates Fibonacci numbers?
 Are Feynman diagrams a formal system? Are they a language? Richard Feynman won the Nobel Prize in Physics in 1965 and was important in the Manhattan Project and in the Space Shuttle Challenger investigation. He also made important contributions to Computer Science (a few of which we will see later in this class). In 1984, Richard Feynman and Gerry Sussman cotaught a course at Caltech using an early version of the Wizard Book. Here's a story about that from Feynman Online:
In the beginning part of 1984, Feynman was teaching a course on computing at Caltech. The course was also cojointly taught by Gerald Sussman from MIT. On one occasion Feynman was lecturing at the blackboard, but this time Sussman kept coming up and correcting him. Later that week Feynman was supposed to come over for dinner. On the night in question, Feynman's wife Gweneth called to say that Feynman was in the hospital and that they would not be able to come over. She told me not to tell anyone, as she didn't want the word to get around. Apparently Feynman in his excitement to purchase a new computer tripped on the sidewalk curb and hit his head. This caused some internal complications and bleeding. In a week or so, Feynman was back on his feet and returned to class. At lunch Feynman related what had happened. After bumping his head, he paid little or no attention to it. He was bleeding when he entered the computer store. What was interesting is that he gradually began to loose his sense of what was happening around him without internally realizing it. First, he couldn't locate his car. Then he had a very strange session with one of his artistic models. And on another day, he told his secretary Helen Tuck that he was going home, and proceeded to undress and lie down in his office. He forgot that he was to give a lecture at Hughs aircraft, and so on... Everything was just rationalized away. But you know, he said, NO ONE told me I was going crazy. Now why not? I said, Come on. You are always doing weird stuff. Besides there such a fine line between genius and madness that it sometimes difficult to tell! Listen, ape, the next time I go crazy around here, you be sure to tell me!
For more stories about Feynman, "Surely You're Joking, Mr. Feynman!": Adventures of a Curious Character is highly recommended summer reading.
Notes
Scheme Rules of Evaluation
(Repeated from 22 Jan notes, except expanded Rule 4.)
Evaluation Rule 1: Primitives. If the expression is a primitive, it is selfevaluating.
Evaluation Rule 2: Names. If the expression is a name, it evaluates to the value associated with that name.
Evaluation Rule 3: Application. If the expression is an application:
(a) Evaluate all the subexpressions of the combination (in any order)
(b) Apply the value of the first subexpression to the values of all the other subexpressions.Evaluation Rule 4: Special Forms. If the expression is a special form, do something special.
Eval 4if. If the expression is (if Expression_{0} Expression_{1} Expression_{2}) evaluate Expression_{0}. If it evaluates to #f, the value of the if expression is the value of Expression_{1}. Otherwise, the value of the if expression is the value of Expression_{2}.Eval 4lambda. Lambda expressions selfevaluate. (Do not do anything until it is applied.)
Eval 4define. If the expression is (define Name Expression) associate the Expression with Name (for Evaluation Rule 2).
Eval 4begin. If the expression is (begin Expression_{0} Expression_{1} ... Expression_{k} ) evaluate all the subexpressions Expression_{0}, Expression_{1}, ... ,Expression_{k} in order. The value of the begin expression is the value of Expression_{k}.
Application Rule 1: Primitives. If the procedure to apply is a primitive, just do it.
Application Rule 2: Compound Procedures. If the procedure is a compound procedure, evaluate the body of the procedure with each formal parameter replaced by the corresponding actual argument expression value.
Syntactic Sugar (define (square x) (* x x)) is actually syntactic sugar (and easier way to write something that means exactly the same thing) for:
(define square (lambda (x) (begin (* x x))))Defining Recursive Procedures
 Be optimistic.
 Assume you can solve it.
 If you could, how would you solve a bigger problem.
 Think of the simplest version of the problem, something you can already solve.
 This is called the base case.
 Usually something like solve for 0 or the empty list
 Combine them to solve the problem.
(define (findclosestnumberextra goal newnumber numbers) (if (empty? numbers) newnumber ;;; No others, newnumber is best (if (< (abs ( newnumber goal)) (abs ( (findclosestnumber goal numbers) goal))) newnumber (findclosestnumber goal numbers)))) (define (findclosestnumber goal numbers) (findclosestnumberextra goal (first numbers) (rest numbers)))This isn't the best way of doing this — think about ways to improve the code."Somehow it seems to fill my head with ideas  only I don't exactly know what they are!"
Alice, in Alice and Wonderland by Lewis Carroll after hearing The Jaberwocky.The best book on programming for the layman is Alice in Wonderland; but that's because it's the best book on anything for the layman.
Alan Perlis, author of SICP Forward and First Turing Award (biggest prize for Computer Science) Winner
University of Virginia Department of Computer Science CS 200: Computer Science 
David Evans evans@virginia.edu Using these Materials 