CS212 Notes for Lecture 1

August 26, 1999

Outline for the day:

Most important part of today's lecture: http://www.cs.cornell.edu/cs212-fa99

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.  There will be a 3rd section MW 11:15-12:05, and a 4th section MW 1:25-2:15, both in locations TBA on the web.

Course staff: Ramin Zabih (prof), Ozan Hafizogullari (TA), Walter Bell (ugrad TA). Consultants: Carson Bloomberg, 
Aleksey Kliger, Kate Oliver, Samuel Tan, Jeff Vinocur, Grant Wang, Maverick Woo. Email addresses on the web page.

Monday/Tuesday evening in Upson B7, demo of DrSwindle. Details TBA in section on Monday.

Grading

Exams are closed-book, closed-notes (not that they would help).  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. Zabih's office hours:  after class on Tuesday/Thursday or by email appointment

Read the announcements on the web page carefully. Corrections to assignments, updates, etc. will be posted there and on the newsgroup.  All course materials and software are on the Web.  There is no textbook -- we'll put notes up on the web and distribute them in class. There are some text books listed on the web page, but I don't personally recommend reading them (they will mostly just confuse you). Note: the lecture notes are to help you, but they are just notes prepared for the lecturer, not a book. Perhaps they will be ready in advance or perhaps not. They will (eventually) be on the Web.

The software is a modern development environment for Scheme called DrScheme. We've added our own extensions (called Swindle) to do very 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 if you have one. (DrScheme also runs on Macs and Unix boxes.) See the Web page for more information.


CS 211 or CS 212

CS 212 is more work (we cover more) and also more credit hours.  (I've had people that think that got a B in 212 that thought they could get an A in 211. Keep that in mind when deciding on the course.)

CS 212 is recommended for CS majors.

You will get an opportunity to learn Java (take CS 112: transition to Java)

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 CSists 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 --

  1. Make a guess g, which should be nonnegative.
  2. Improve the guess, by averaging g and x/g
  3. Stop when the guess is good enough. How? When |g*g-x| is very small.

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

* a PRIMITIVE

or

* a COMBINATION

 

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

(+ 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".


For *almost* all operators, the value of a combination is determined by the following rule:

 

To evaluate a combination:

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.