January 25, 2000
Most important part of today's lecture: http://courses.cs.cornell.edu/cs212/2000sp
Lots of interesting stuff, including problem set #1 and the software you'll need to do it.
Every week, 2 lectures and 2 sections. Lectures are Tuesday & Thursday, sections are Monday & Wednesday (sections start next week). Right now there are 2 sections, 2:30-3:20 & 3:35-4:25. We would like to move one of these to 1:25-2:15. Locations on the web.
Course staff (email addresses on the web page):
Instructor: Dexter Kozen
TAs: Ralph
Benzinger, Brandon Bray
Consultants: Walter Chang, Hubert
Chao, Dion Kane Harmon, Nadine Latief, Jeff Vinocur
Administrative assistant: Karla Consroe
Swindle demo session will be in Upson B7 on Wednesday 1/26 and Thursday 1/27 at 7:00pm or 7:30pm. We emphatically recommend waiting to install the software until after attending the demo. Attendance is mandatory!
Exams are closed-book, closed-notes. Makeup exams are oral (let's try and avoid them!)
Grading: last year about 1/3 A's, 1/2 B, 1/6 C or less. "Past performance is no guarantee of future results." The final exam is particularly important.
WARNINGS:
Problem sets count for a lot. Do them!
Note that because early problem sets are much easier than later ones, you should consider your prelim and homework scores carefully around the drop deadline.
Working together: For problem sets 2-6, up to two people may work together but if you do so you MUST hand in ONE joint assignment. You may not share code with anyone else. Cheating is the best way to get an F (or worse). Please read the CS Department code of academic integrity on the CS Dept Undergrad web site. If you are unsure, ask.
Prof. Kozen's office hours: after class on Tuesday/Thursday or by appointment. Contact Karla Consroe (karla@cs.cornell.edu) for an appointment.
Read the announcements on the web page daily. Corrections to assignments, updates, etc. will be posted there. All course materials and software are on the web. There is no textbook. We'll put notes up on the web. There are some textbooks listed on the web page that are on reserve in the Engineering library.
Note: we are posting the lecture notes to help you, but keep in mind they are just notes prepared for the lecturer, not a book. They may be ready in advance and maybe not. They will all eventually be on the Web, but they are not a substitute for attending lecture.
The software is a modern development environment for Scheme called DrScheme. We've added our own extensions (Dr Swindle) to do advanced object oriented programming. The environment provides a syntax-highlighting editor (very important for Scheme), online help, good libraries, good debugging support, etc. Also, it's designed for teaching.
The software should be installed on the CIT Windows machines (e.g., in the Upson B7 lab). You can also download the software and install it on your own machine; instructions on the web. DrScheme also runs on Macs and Unix boxes. See the Web page for more information.
CS 212 will be more work than CS 211 and also more credit hours.
CS 212 is recommended for CS majors.
Major pre-requisite is willingness to work and to think clearly and to go beyond programming to learn more about the fundamentals of computer science. You don't need to know how to program particularly (and, in fact, being a great programmer isn't a big advantage.) We will assume a certain degree of mathematical sophistication -- not calculus per se, although we assume you know what a derivative/integral is. Best preparation is high school geometry!
We cover:
Style of the course:
This course could be called an introduction to COMPUTER SCIENCE.
That's a terrible name, actually. It's not about either one. It's not really about computers per se; They're our tools. You wouldn't call surgery ``Scalpel Science'' or math ``Arithmetic Science''
It's more like some combination of
Names of disciplines are mostly misleading (economic science, military intelligence?). Geometry comes from ``Ghia Metra'', ``Geo Metry'', meaning ``Earth measure''
In Egypt, the priesthood was charged with restoring boundaries of fields after the annual flood when all the boundary markers got swept away. They invented geometry, more or less, to handle distances and angles and areas.
Geometers are not still measuring the earth -- not mostly anyways. The main contribution was FORMALIZING NOTIONS OF SPACE.
Similarly, we are using tools (computers, occasionally RNA and other gadgets) to do computation. Our most lasting work is probably FORMALIZING NOTIONS OF COMPUTATION. Understanding what it means to compute.
Most of 212 is Building your skills in REASONING ABOUT COMPUTATION.
1. Writing programs: Bag of Tricks
2. Understanding programs
3. Better Problem Solving:
Single most important mantra: a little bit of thinking is worth a lot of coding (or: don't hack - think!)
Almost all exam questions, problem set questions have very short solutions. But that doesn't mean they're easy...
There are two classes of high-power programmers:
Wizards do all kinds of amazing things,
Experts do other kinds of amazing things:
Never program behind a wizard. (You can't understand their code, or fix it.)
You can be both:
We can't quite train you to be a wizard.
We can, and will, train you to be an expert.
Later courses (and what computer scientists do) are not programming courses, mostly
Computational Processes aren't quite mathematics, though:
Our goal is to help you develop some computational rigor: precise descriptions of how to compute something.
Declarative vs. Imperative:
DECLARATIVE: sqrt(x) is the unique y such that y*y = x and y >= 0.
Well, to compute sqrt(x) we could try all possible y's, compute y*y, and check if it's x. But that would take a long time.
Observation:
Proof: g > sqrt(x) -> 1/g < 1/sqrt(x) -> x/g < x/sqrt(x)
ALGORITHMIC or COMPUTATIONAL knowledge: To find sqrt(x) -- or rather, a good enough approximation to it --
This is one of the first ALGORITHMS (= METHODS OF COMPUTATION)
Heron of Alexandria, about 100 AD (Newton generalized it to cover almost everything, so it's called Newton's Method)
It works quite well:
* Take x = 2,
* guess g=1, why not?
* x/g = 2, so g := 3/2 = 1.5
* x/g = 4/3, so g := 17/12 = 1.4166666
* x/g = 24/17, so g := 557/408 = 1.4142156
which is off by 6e-6.
A key idea of the course:
ABSTRACTION:
** e.g., define sqrt(x) to be the result of doing Newton's method.
Stereo connectors
We'll use the programming language Scheme.
First lie of many! (This course is successively lies, each a bit closer to the truth) (Ptolemy, Copernicus, Kepler, Newton, Einstein). Kind of like the sqrt algorithm...
Rules of Scheme: - Grammar (aka Syntax) * It's described as ``Prefix-order, fully parenthesized''
1. The operation to perform comes first (prefix-order)
2. Every part of the program has parentheses around it,
This has two effects:
1. The grammar is very simple
2. It's kind of alien at first. It isn't "just like Pascal or C". Mantra: "Scheme is not C++/Pascal/C/Java".
For example, the Pascal 4+5*2 [AMBIGUOUS] is the Scheme (+ 4 (* 5 2)) [NOT]
Another example: in Pascal,
IF false THEN
IF true THEN x:=1
ELSE x:=2
does nothing. Pascal's ambiguous, and there's a special rule which makes it read
IF false THEN
(IF true THEN x:=1
ELSE x:=2)
In Scheme, the analogous code is never ambiguous. That doesn't mean it's always easy for humans to read it!
Everything in Scheme is an EXPRESSION, which means that it has a value.
The value of (+ 4 (* 5 2)) is 14.
Mantra: Everything in Scheme is an expression, and has a value.
An expression is either
PRIMITIVES are variables and constants:
sequence of characters not containing parentheses, spaces
(There's a little more to it than that)
1 -31 "a string" x a-long-variable-name +
(note the last one! the name of a function is a variable just like any other)
COMBINATION: is one or more expressions enclosed in parentheses, separated by spaces:
(+ 3 5)
(gcd (+ 51 8) 6)
The order of expressions in a combination is always (operator operand1 ... operandn)
Note that the definition of an EXPRESSION is recursive (really, inductive, it is a PRIMITIVE or COMBINATION, the latter of which is one or more EXPRESSIONs). First of many...
We can abbreviate the definition of the syntax of Scheme using the following notation:
<prim> ::= 1 | -31 | "a string" | x | a-long-variable-name | + | ...
<exp> ::= <prim> | ( <combination> )
<combination> ::= <exp> | <combination> <exp>
where we interpret "|" as meaning "or".
Everything in Scheme is an expression. Computation is performed by evaluating an expression, which yields a value. How do we evaluate an expression? We apply rules that depend on the form of the expression.
For every expression, there is exactly one rule that applies.
The value of a constant is itself.
The value of a variable is the value that it is bound to. There are different ways of binding variables to values. The concept is a little different from assigning a variable a value in Java or C.
For almost all operators, the value of a combination is determined by the following rule:
E. Evaluate the subexpressions. [[ THIS RULE IS RECURSIVE: ``to evaluate, evaluate''! ]]
A. Do the specified operation (value of the first expression) to the operands (remaining expressions)
Example: (* (+ 3 4) 2)
E. Evaluate *. It comes out as `multiply.'
E. Evaluate (+ 3 4)
E. Evaluate +. It's `add'
E. Evaluate 3. It's 3
E. Evaluate 4. It's 4
A. Add 3 and 4. It's 7
E. Evaluate 2. It's 2
A. Multiply 7 by 2. It's 14
Note that we're doing it inside-out.
So far we have a fully-parenthesized 4-function calculator. Big deal. They're free in cereal boxes.
The same basic mechanism holds for all Scheme expressions
One of the most powerful abstraction techniques is to give things names.
This sounds kind of trivial, but it's very hard to get the right parts of a problem and give them the right names. Much of system DESIGN is thinking clearly about what the PARTS of something are, not just hacking, and naming things descriptively can help.
The way to name a global variable in Scheme is using the special form define:
(define data (+ 9 4))
data is now 13
(define add-up +)
add-up is now the same function that + is
(define luke (add-up data 2))
luke is now 15
In general (define name expr) defines the NAME to be the VALUE that we get when we evaluate EXPR.
The general evaluation rule given above wouldn't work for define:
So that doesn't work.
MAIN POINTS:
* Studying computational processes in a language (Scheme) Two parts:
* The language has simple, uniform evaluation rules
* One of the most important aspects of good program design is good abstraction, and a lot of that involves thinking clearly about complex things. This course is about techniques for doing that.