You are on page 1of 55

6.

00: Introduction to Computer Science & Programming


Frdo Durand and Armando Solar-Lezama MIT EECS

Tuesday, February 5, 13

Stu I do with computers

Tuesday, February 5, 13

Show of hands

Who has programmed before? Who knows Python? Who wants to be a CS major? Who thinks theyre going to be bad at programming? Who thinks they will need to program in their life? Whos here because its a requirement?

Tuesday, February 5, 13

Introductions

Armando Solar-Lezama - Programming tools/languages - Program synthesis

Frdo Durand - Computer graphics - Computational photography

Tuesday, February 5, 13

Course objectives
Tuesday, February 5, 13

Course objectives

Prepare students without programming experience for course VI Help non-course VI students write programs Map scientic problems into computational framework Provide students with competence in computational problem solving (useful for urops & summer jobs)

Tuesday, February 5, 13

Is programming hard?

Programming is not hard But you often dont get it right at rst - like most things - Persevere, edit, debug, divide and conquer

Everyone can be a programmers - Not necessarily a software architect who handles millions of lines of code - But everyone can use programming to solve practical problems

Dont get scared by keywords and details

Tuesday, February 5, 13

Administrivia

Tuesday, February 5, 13

Administrivia

Mostly web-based: stellar, piazza Signup on website for recitations Weekly programming problem sets 2 evening quizzes. First one around March 7 Final exam, closed book, 2 sheets of notes Textbook MITx material - lectures, nger exercises, low-grade version of book

Tuesday, February 5, 13

Collaboration policy

Collaborate, dont plagiarize - Talk about psets, but write your own code - Good idea not to look at other peoples code

We will use plagiarism detection software - MOSS: http://theory.stanford.edu/~aiken/moss/

Tuesday, February 5, 13

Slightly dierent from past 6.00

Mostly same material, slightly different presentation and order Dont freak out too much if you cant answer all questions on old quizzes - But freak out a little bit

Tuesday, February 5, 13

Problems Computer Science can solve


Tuesday, February 5, 13

Path planning

Well cover a simple version


Tuesday, February 5, 13

Airfare optimization

Tuesday, February 5, 13

Biology

Slide by Manolis Kellis


Tuesday, February 5, 13

Pandora, Spotify

Tuesday, February 5, 13

Organize data, communicate

Tuesday, February 5, 13

Simulation

Fluids, weather, structure, n-body, virus spread

Well cover a simple version


Tuesday, February 5, 13

Search

http://en.wikipedia.org/wiki/File:PageRanks-Example.svg https://dhs.stanford.edu/algorithmic-literacy/accessing-data/
Tuesday, February 5, 13

Natural language processing, speech

Tuesday, February 5, 13

Robots

Tuesday, February 5, 13

Play chess, play jeopardy

Tuesday, February 5, 13

3D reconstruction, face detection

Tuesday, February 5, 13

Medical imaging

Tuesday, February 5, 13

Computational thinking

Cognition as algorithms Human vision & computer vision Genetics as information processing

Tuesday, February 5, 13

Problems one Programmer can solve


Tuesday, February 5, 13

Psets from last year


Scrabble/Words With Friends inspired game Encryption/decryption RSS ltering Simple robot simulation Virus spread simulation Election prediction using randomized simulation Course load optimization Clustering census data

Tuesday, February 5, 13

Keep track of workout


For the MIT frisbee team By Patricia Li, Physics major

Tuesday, February 5, 13

Yearbook

Small team and too many photos/names/index to handle. Were about to miss the print deadline. After an hour of code: Script to automatically generate layout from pictures+names Unfortunately no duck-face correction script

Tuesday, February 5, 13

Monty Hall probability paradox

You choose among three doors - one of them allows you to win a car
A B

Then the host tells you, for one of the doors you didnt choose, that it doesnt have a car You get a chance to change your mind: what should you do? Simulation was 20 lines of code

Tuesday, February 5, 13

Simple problems

Tennis game probabilities - 60 lines of code Is 2048 the last power of two with only even digits? - 20 lines of code Web site ltering with chicken feet - 10 lines of easy code Designating TA volunteers - 3 lines of Pyhton~

Tuesday, February 5, 13

Photo collages

N photos=> auto correspondence and layout About 3 months of 25%-time coding

Tuesday, February 5, 13

Photo collages

N photos=> auto correspondence and layout About 3 months of 25%-time coding

Tuesday, February 5, 13

Pentimento

I wanted to create a handwritten video lecture Online Sub No good tool

Non-Sequential Authoring I wrote my own software, Pentimento of


About 6 months at 25% of coding

Handw

Tuesday, February 5, 13

(a) User records temporal lecture,

(b) retroactively edits layout,

From 6.815 (also in Python!)


HDR Panorama stitching Painterly lter Seamless pasting Morphing ...


A

Be

Tuesday, February 5, 13

What problems would you solve?


Part of pset 0 Anything from frivolous to big challenges Well try to give you feedback: - A Harvard student could do it - You can do it at the end of 6.00 - You can do it at the end of course VI - Youll need a big team of programmers - So hard theyll create a Nobel prize in computer science just for this - This is the next Microsoft/Google/Facebook. Weve already stolen and patented your idea

Tuesday, February 5, 13

What is Computation?
Tuesday, February 5, 13

What you should remember

Programming is empowering and cool Imperative knowledge Computers are dumb and just follow steps Variables & assignment

Tuesday, February 5, 13

Youre the computer! n=10 while n1: if isEven(n): n=n/2 else: n=n*3+1
Tuesday, February 5, 13

Python tutor

http://www.pythontutor.com/

Tuesday, February 5, 13

For your culture: Syracuse problem


Conjecture: always converges to 1 http://en.wikipedia.org/wiki/Collatz_conjecture

Tuesday, February 5, 13

Elements of a program
Variable

n=10 assignment

while n 1: control

test

if even(n): control
assignment

test

n=n/2

arithmetic

else: n=n*3+1
Tuesday, February 5, 13

Dont forget

The computer has no purpose The computer doesnt understand the task The computer just does what you tell it to do

Tuesday, February 5, 13

Declarative vs. imperative knowledge

Declarative: - statement of fact Imperative: - how-to recipe - also known as procedural

Tuesday, February 5, 13

Declarative denition of

is the number so that the area of a circle or radius r is r2

Tuesday, February 5, 13

Imperative version of pi

Area of circle of radius 1 Generate lots of points inside [-1 1] square Count point inside circle - they satisfy x*x+y*y<1

Tuesday, February 5, 13

Computing pi
N=1000.0 numberInCircle=0.0 x=-1.0 while x<1.0: y=-1.0 while y<1.0: if x*x+y*y<1: numberInCircle=numberInCircle+1 y=y+1/N x=x+1/N print numberInCircle/(N*N)

Tuesday, February 5, 13

Other example: Square root

Declarative: - square root of N is the number x such that 2 x =N

Imperative (Heron algorithm) - start with rough guess, e.g. x=N - While x2 too different from N - x=0.5*(x+N/x)

See 6.00x or the book for more

Tuesday, February 5, 13

Recap: What computers do


Compute *, +, -, /, etc. including tests: >, ==, etc. Control: while, if Store in variable, described by names the = operator changes the stored value
Tuesday, February 5, 13

Python & Idle

Tuesday, February 5, 13

Why Python?

Easy syntax, concise Supports all styles of programming Widely used in science and engineering - lots of useful library Easy to transfer knowledge to other languages Cons: can be slow - but you can speed it up with Pypi

Tuesday, February 5, 13

IDLE

Shell - where results are printed - where user-input is entered - can be used for on-the-y pogramming and experiments

Editor - to edit and rene longer pieces of code

Tuesday, February 5, 13

Basic elements

Expressions Variables - Name - Value - Very different from math unknowns!

Assignment using = - Change the v

Tuesday, February 5, 13

The = challenge

= in computer science is very different from = in math the left hand side of = is always a variable name = means that the result of the right expression gets stored in the variable some languages use <- instead of = to be clearer to make matters worse, there is a test to see if two expressions are equal, and in Python its

Tuesday, February 5, 13

What you should remember

Computer science is cool and useful Imperative knowledge Computers are dumb and just follow steps Variables & assignment = means that the variable on the left stores a new value

Tuesday, February 5, 13

You might also like