Title: CS1 Introduction to Computation
1CS1Introduction to Computation
http//www.cs.caltech.edu/courses/cs1
- Day 1 October 1, 2007
- Automated Processing of Information
Add cards signed at end of class.
2Outline
- 15 Administrative details
- 10 Pep talk
- 10 What class is about / philosophy
- 15 Review mathematical notation
- translate to Scheme
3Course Admin
4People
Mike Vanier (mvanier_at_cs) Donnie Pinkston
(donnie_at_cs)
(lectures)
Joseph Schaeffer Donnie Pinkston
(recitations)
David Dicato Nick Fortino Brent
Goldman Alexander Hudson Ilya Loksha Keegan
McAllister
Catherine Chou Cheng William Hong Radhika
Marathe Hamik Mukelyan Kim Scott Tamas Szalay
(lab)
5Website
- http//www.cs.caltech.edu/courses/cs1
- (also http//www.cs.caltech.edu/cs1)
- ? Administrative Handout
- CS1man
- Other Good LinksTM
6Organization
- Lectures 2x50min/week
- Introduce new material
- Tie ideas to mathematics
- Big Idea page
- Punctuate with interludes (midpoint)
- Attendance reqd ? Daily Quiz
- Recitations 1x50min/week
- Ask questions and work examples
- Smaller groups (target 25)
- Staffed lab 4d x 8 hrs
- TAs, assigned times
- Comprehensive Text
- SICP
- (Abelson/Sussman)
- Required Reading
- Weekly assignments
- Allow rework (1 wk)
- Online, assignment 1 posted
- Exams
- midterm, final
- Point system
7Your Part
- Read the text
- Go to lectures and sections
- Ask your TA for help
- Learn from your mistakes
- (rework gives you a chance to do so)
- Tell us what makes things hard
- Fill out feedback, talk to ombuds, TAs,
instructors
8Point System
- Daily Quiz (0.0 - 0.5) x 20 10
- Homework (0 - 3) x 9 27
- Midterm
6 - Final
18 - Possible
61 - Pass
40
9Grading homework
- Set has multiple parts (A through F, e.g.)
- Score for entire set is minimum of the section
scores - Each part receives integer in 0, 3
10Time on Assignments
- Taking excessive time on a problem is a symptom
that you missed an important concept - Its possible to do things the wrong way (missing
what were teaching you) - but it probably will take you a lot more time
- Time hint on assignments
- suggested upper bound
- feedback to you ? you should see a TA
- Dont spend hours alone on a problem!
11Rework Philosophy
- Programs that are 1 wrong are wrong
- as far as the computer is concerned
- Good match ? pass/fail nature
- Emphasizes mastery
12Optional Seminar
- Everything You Need to Know About Linux, the CS
Cluster, and CS 1 Software In 60 Minutes or Less - Useful if youre new to Linux or need/want a
refresher - 1000pm Thursday Jorgensen 074
- (basement)
- South-side basement door will be unlocked
13Lab
- No formal lab sections first week
- TAs in lab T/W/Th/F for week 1
- 2 PM to midnight
- not 6 PM 8 PM, T/Th 2-4, F 8-midnight
- Lab is in Jorgensen 154
- combo 3-5-2
14Your Action Items
- Hand in (today)
- daily quiz, section time prefs, feedback
- Sign up for CS account (via the web)
- also results in card key access
- Get text book (and/or read on web)
- read thru section 1.1.5
- Visit web site
- read admin handout
- find lab 1
- start getting familiar with CS system
15Pep Talk
16Before I begin...
- I'd like to read a quote from Kip Thorne
- R.P.Feynman Professor of Theoretical Physics
17Kip Thorne's advice to you
- "To undergraduates I would say, youre living in
an artificial environment where the pressure is
intense, your peers are brilliant, and you see
yourselves competing with them. You should try to
put that competition away make it not affect
you, and focus instead on simply learning and
enjoying science."
18Kip Thorne's advice to you
- "This is a totally artificial environment. Youll
never be in this situation again. When you leave
Caltech, you will find yourself surrounded by
more ordinary mortals. Now, thats a weird kind
of advice, but I have seen too many talented
undergraduates get discouraged and drop out,
either actually or spiritually."
19Kip Thorne's advice to you
- "My main advice, then, is to focus on enjoying
science. Make your learning of science something
that reaches out beyond your studies and into the
world more broadly. "
20Kip Thorne's advice to you
- "Keep up with whats going on outside of your own
areas of study. Maintain your intellectual
curiosity and learn thereby how to function like
a real scientist rather than just focusing on the
narrow, particular areas that are involved in
your coursework."
21Alrighty then...
22I'm sure you're all asking...
- What is this course really all about?
- Learning to program?
- Learning computer science?
- Learning an employable skill?
- Learning an enjoyable skill?
- YES!
23Setting the mood...
- I etch a pattern of geometric shapes onto a
stone. To the uninitiated, the shapes look
mysterious and complex, but I know that when
arranged correctly they will give the stone a
special power, enabling it to respond to
incantations in a language no human being has
ever spoken. I will ask the stone questions in
this language, and it will answer by showing me a
vision a world created by my spell, a world
imagined within the pattern on the stone.
24- A few hundred years ago in my native New
England, an accurate description of my occupation
would have gotten me burned at the stake. Yet my
work involves no witchcraft I design and program
computers. The stone is a wafer of silicon, and
the incantations are software. The patterns
etched on the chip and the programs that instruct
the computer may look complicated and mysterious,
but they are generated according to a few basic
principles that are easily explained.
Danny Hillis The Pattern On the Stone
25Programming fun
- Frederick P. Brooks, Jr.The Mythical Man-Month
- joy of making things
- things that are useful to other people
- things that are complex and intricate
- joy of always learning
- delight of working in such a tractable medium
- purely abstract "thought stuff"
- yet its effects are real
26Programming fun
- Frederick P. Brooks, Jr.The Mythical Man-Month
- "Programming then is fun because it gratifies
creative longings built deep within us and
delights sensibilities we have in common with all
men and women."
27Alan Perlis
- From the introduction to our textbook
- "We're responsible for stretching computers,
setting them off in new directions, and keeping
fun in the house."
28Alan Perlis
- From the introduction to our textbook
- "What's in your hands, I think and hope, is
intelligence the ability to see the machine as
more than when you were first led up to it, that
you can make it more."
29"Double happiness"
- "People who program have double happiness.
First of all they experience the sheer beauty of
elegant mathematical patterns that surround
elegant computational procedures. Then they
receive a practical payoff when their theories
make it possible to get other jobs done more
quickly and more economically.'' - Donald Knuth
30Why learn computer science?
- Computer science/programming has
- great theory
- tons of practical applications
- financial rewards
- and it's fun
- And if that isn't enough...
- Computer programming is an essential tool in
every branch of science
31Fantasia (1940)
32Is it magic?
- What computers can do may seem almost magical
e.g. - simulate global climate
- play chess better than humans
- prove mathematical theorems
- connect people to the internet
33Clarkes Third Law
- Any sufficiently advanced technology is
indistinguishable from magic. - Profiles of the Future
- Arthur C. Clarke
34Goal Magic ? Technology
- We want to fundamentally understand computers and
information processing - so it doesnt appear as unfathomable magic
- but as a technology we have control over
35Information Processing
- is an important component of our physical world
- has very interesting laws, characteristics, and
behaviors - of its own
- and in close relation to matter
- something we can and must understand to master
our world
36CS 1 is...
- an introduction to computer programming
- big ideas and concepts
- much unfamiliar material
- emphasis on deep understand of behavior of
programs - preparation for future
- an introduction to computer science
- CS is more than programming
37...a class for everyone
- Computers impact lives
- Essential tool in all science and engineering
endeavors - control expts, run simulations, process results,
optimize designs - We'll start from the beginning
- more fundamental/foundational than taught in high
school
38The basic idea behind computing
- We can write a precise, mechanical specification
of a process - We can build machines to follow the specification
- We can reason rigorously about the behavior of
these machines
39Model
big idea!
- A good conceptual model allows us to predict the
effects of our actions. Without a good model we
operate by rote, blindly, we do operations as we
were told to do them we can't fully appreciate
why, what effects to expect, or what to do if
things go wrong. As long as things work
properly, we can manage. When things go wrong,
however, or when we come upon novel situations,
then we need a deeper understanding, a good
model.
Donald Norman
40Programming
Job 1
- Build a strong conceptual model of computation
- using the Scheme programming language
- Understand the meaning of programs
- Reason rigorously about their behavior
- Appreciate complexity
- and learn how to manage it
- emphasize managing complexity and understanding
the model over micro-optimization - human time is (usually) the limiting factor
41Poll
- Who has not programmed before?
42For those that have
- keep active mind on the course
- watch for differences
- unlearn what you have learned
- expose you to new ways of thinking
- valuable even if you never program in Scheme
again - paradigms, techniques, idioms carry over to
(almost) any language
43Computer Language(s)
- Fundamental ideas behind all languages
- enable to pick up new ones easily
- Beyond syntax
- Use Scheme as programming language
- start functional
- extend from math functions
- introduce objects
- introduce assignment (imperative)
44Why not C/C/Java?
- Scheme is not a practical language
- but
- very simple, consistent syntax
- very powerful
- other languages keep reinventing Scheme ideas
- very consistent
- easy to precisely understand computational model
- can incorporate most programming paradigms
- great textbook!
45NOT!
46http//mitpress.mit.edu/sicp
47OR
(exact same book, different cover, cheaper!)
http//mitpress.mit.edu/sicp
48Another reason we use Scheme
- "Because it lets us do things we can't do in
other languages." - -- Paul Graham
49Two examples
- Example 1 sum all the numbers from 1 to n
- for some number n you specify
- easy to do in Scheme or (say) C
- or any other language
50Two examples
- Example 2
- Write a function that takes a number n and
returns a function which adds n to its argument - In Scheme
- (define (addn n) (lambda (x) ( x n)))
- you don't need to understand this yet
- In C
- "You just can't write it."
51Two examples
- "Programming languages teach you not to want what
they don't provide." - We want you to know what features programming
languages can provide - even if the language you're using doesn't
provide them - Want you to be educated consumers of languages
- or maybe even producers...
52Yet Another Reason
- Many new computer languages are very closely
related to Scheme - Erlang (massively concurrent programming)
- Ocaml (typed functional programming)
- Haskell (lazy functional programming)
- More conventional languages have borrowed
features from Scheme - Python, Ruby, C
- Therefore, Scheme is a good foundation for
learning new languages
53Notations and Model
54Infix notation
- infix operator between operands
- 3 4
operator
operands
55Infix notation
- Examples
- 3 4
- 3 4 5
- 3 4 5 22
- sometimes use parentheses to specify order of
evaluation - (3 4) 5
- (3 ((4 - 5) 2))2
56Assignment
- Assignment gives a symbol a particular value
- x 3
symbol
value
57Assignment
58Evaluation
- x 3
- y 4
- z x y
- How to evaluate to get z?
- Substitute symbol's value for symbol in RHS
- ? z 3 4 7
- w z 2
- w 7 2 9
59Functions
- Function definition
- f(x) x2 - 2x 4
- f(x,y) 3x - 4y 2
- a(r) pi r2
60Function evaluation
- Substitute numbers for arguments, simplify
- f(x) x2 - 2x 4
- f(3) 32 - 23 4 9 - 6 4 7
- f(x,y) 3x - 4y 2
- f(3,2) 33 - 42 2 3
- a(r) pi r2
- a(1) pi 12 3.1415926.
61Prefix notation
- Prefix operator precedes the operands
- Familiar from function usage
- f(3, 2)
operands
operator
62Prefix notation
- Examples
- f(x) operator f operand x
- f(3) operator f operand 3
- f(x,y) operator f operands x, y
- f(3,2) etc.
- a(r)
- a(1)
63Alternative prefix notation
- (f 3 2)
- means the same thing
- parentheses on the outside
- separate with spaces, not commas
- space is significant!
operands
operator
64Scheme
- abandons infix only uses (2nd) prefix notation
- math Scheme
- 3 4 ( 3 4)
- 3 45 ( 3 ( 4 5))
- 3 4 - 522 ( 3 (- 4 ( 5 (expt 2 2))))
- f(3) (f 3)
- f(x,y) (f x y)
- f(3,2) (f 3 2)
65Yes, it's weird
- This notation takes getting used to
- Lots of parentheses
- DrScheme editor will help you with these
- but completely consistent
- no special rules to remember
- all operators are prefix
- no "operator precedence"
- Usually takes 2-3 weeks before comfortable
66Scheme combinations
- look like this
- (operator operand1 operand2 )
- Delimited by parentheses
- First element is the operator
- Rest are operands
- In general, arbitrary number of operands
- but will depend on operator
67Scheme combinations
- Examples
- ( 2 3)
- ( 2 3 4)
- (abs -7)
- May be nested
- (abs ( (- x1 x2) (- y1 y2)))
68Parentheses
- NOTE Parentheses are not optional
- Everything has parentheses
- They have a very specific meaning
- first item in parenthesized set is the operator.
- rest are operands
- Cant just wrap more parentheses around things
- why not?
- This is different from
- mathematical use
- use in most other programming languages
69Parentheses
- Scheme is a dialect of the programming language
Lisp - Lisp means either
- LISt Processing
- Lots of Irritating Stupid Parentheses
- depending on who you ask
70Assignment in Scheme
- Assignment is also a prefix operation
- math Scheme
- x 3 (define x 3)
- y 4 (define y 4)
- z x y (define z ( x y))
- w z 2 (define w ( z 2))
71Scheme function definition
- Translate a(r) pi r2
- (define a (lambda (r) ( pi (expt r 2))))
72lambda???
- (lambda (r) ( pi (expt r 2)))
- lambda means this combination represents a
procedure (function) - from the Greek letter lambda (l)
- we'll see why later
- Somewhat cumbersome well see a shortcut next
lecture
73More function definitions
- f(x) x2 - 2x 4
- (define f (lambda (x)
- ( (expt x 2) ( -2 x) 4)))
- f(x,y) 3x - 4y 2
- (define f (lambda (x y)
- ( ( 3 x) ( -4 y) 2)))
- N.B. some operators (like ) can have a variable
number of operands
74Comments
- Often useful to leave notes for
- your future self
- others who may read/modify your code
- Can do this by using comments
- words and symbols you tell the machine to ignore
- In Scheme
- comments start with a semicolon (usually two)
- and go to the end of the line
- this is a comment
75Scheme as a calculator
- Now know enough to use Scheme interpreter as a
(programmable) calculator - Assignment 1 will walk you through how to invoke
the Scheme interpreter (DrScheme) - More importantly
- Now you know (almost) all the syntax in Scheme!
76Big Ideas
- Automated processing of information
- Precise specification
- Computational Model
- Rigorous thinking about model
- Complexity and its management
77Finally...
- Some more words of motivation from an illustrious
speaker
78Saturday Night Live (1993)
79Note
- Any resemblence between Matt Foley and the CS 1
lecturers is purely accidental -)