WELCOME!
(download slides and .py files from
the class site to follow along)
6.100L Lecture 1
Ana Bell1 TODAY
Course info
What is computation
Python basics
Mathematical operations
Python variables and types
NOTE: slides and code files up before each lecture
Highly encourage you to download them before class
Take notes and run code files when I do
Do the in-class “You try it” breaks
Class will not be recorded
Class will be live-Zoomed for those sick/quarantine6.100L Lecture 12 WHY COME TO CLASS?
You get out of this course what you put into it
Lectures
Intuition for concept
Teach you the concept
Ask me questions!
Examples of concept
Opportunity to
practice practice practice
Repeat6.100L Lecture 13 PRACTICE
February 3, 2016 6.0001 LECTURE 1
PROBLEM
SOLVING
PROGRAMMING
SKILL
PSETS
EXAMS
MANDATORY
FINGER
EXERCISES
OPTIONAL
(practice)
OFFICE
HOURS
PIAZZA
LECTURES
RECITATION
KNOWLEDGE
OF CONCEPTS6.100L Lecture 14 TOPICS
Solving problems using computation
Python programming language
Organizing modular programs
Some simple but important algorithms
Algorithmic complexity6.100L Lecture 15 TYPES of KNOWLEDGE
Declarative knowledge is statements of fact
Imperative knowledge is a recipe or “how-to”
Programming is about writing recipes to generate facts6.100L Lecture 17 NUMERICAL EXAMPLE
Square root of a number x is y such that y*y = x
Start with a guess, g
1) If g*g is close enough to x, stop and say g is the answer
2) Otherwise make a new guess by averaging g and x/g
3) Using the new guess, repeat process until close enough
Let’s try it for x = 16 and an initial guess of 3
g g*g x/g (g+x/g)/2
3 9 16/3 4.176.100L Lecture 18 NUMERICAL EXAMPLE
Square root of a number x is y such that y*y = x
Start with a guess, g
1) If g*g is close enough to x, stop and say g is the answer
2) Otherwise make a new guess by averaging g and x/g
3) Using the new guess, repeat process until close enough
Let’s try it for x = 16 and an initial guess of 3
g g*g x/g (g+x/g)/2
3 9 16/3 4.17
4.17 17.36 3.837 4.00356.100L Lecture 19 NUMERICAL EXAMPLE
Square root of a number x is y such that y*y = x
Start with a guess, g
1) If g*g is close enough to x, stop and say g is the answer
2) Otherwise make a new guess by averaging g and x/g
3) Using the new guess, repeat process until close enough
Let’s try it for x = 16 and an initial guess of 3
g g*g x/g (g+x/g)/2
3 9 16/3 4.17
4.17 17.36 3.837 4.0035
4.0035 16.0277 3.997 4.0000026.100L Lecture 110 WE HAVE an ALGORITHM
1) Sequence of simple steps
2) Flow of control process that specifies when each step is
executed
3) A means of determining when to stop6.100L Lecture 111 ALGORITHMS are RECIPES /
RECIPES are ALGORITHMS
Bake cake from a box
1) Mix dry ingredients
2) Add eggs and milk
3) Pour mixture in a pan
4) Bake at 350F for 5 minutes
5) Stick a toothpick in the cake
6a) If toothpick does not come out clean, repeat step 4 and 5
6b) Otherwise, take pan out of the oven
7) Eat6.100L Lecture 112 COMPUTERS are MACHINES that
EXECUTE ALGORITHMS
Two things computers do:
Performs simple operations
100s of billions per second!
Remembers results
100s of gigabytes of storage!
What kinds of calculations?
Built-in to the machine, e.g., +
Ones that you define as the programmer
The BIG IDEA here?6.100L Lecture 113 A COMPUTER WILL ONLY DO
WHAT YOU TELL IT TO DO6.100L Lecture 114 COMPUTERS are MACHINES that
EXECUTE ALGORITHMS
Fixed program computer
Fixed set of algorithms
What we had until 1940’s
Stored program computer
Machine stores and executes instructions
Key insight: Programs are no different from other kinds of data6.100L Lecture 115 STORED PROGRAM COMPUTER
Sequence of instructions stored inside computer
Built from predefined set of primitive instructions
1) Arithmetic and logical
2) Simple tests
3) Moving data
Special program (interpreter) executes each instruction in
order
Use tests to change flow of control through sequence
Stops when it runs out of instructions or executes a halt instruction6.100L Lecture 116 6.100L Lecture 1
MEMORY
CONTROL
UNIT
ARITHMETIC
LOGIC UNIT
INPUT OUTPUT
program counter do primitive ops17 6.100L Lecture 1
MEMORY
CONTROL
UNIT
ARITHMETIC
LOGIC UNIT
INPUT OUTPUT
3456 3
3457 4
3458
3459 True
3460
3461 False
7889 5
7890 2
7891
7892
7893
7894
Add 3456 3457
Add 7889 7890
Store 3458
Store 7891
Compare 3458 7891
Print18 6.100L Lecture 1
MEMORY
CONTROL
UNIT
ARITHMETIC
LOGIC UNIT
INPUT OUTPUT
3456 3
3457 4
3458
3459 True
3460
3461 False
7889 5
7890 2
7891
7892
7893
7894
Add 3456 3457
Add 7889 7890
Store 3458
Store 7891
Compare 3458 7891
Print19 6.100L Lecture 1
MEMORY
CONTROL
UNIT
ARITHMETIC
LOGIC UNIT
INPUT OUTPUT
3456 3
3457 4
3458 7
3459 True
3460
3461 False
7889 5
7890 2
7891
7892
7893
7894
Add 3456 3457
Add 7889 7890
Store 3458
Store 7891
Compare 3458 7891
Print20 6.100L Lecture 1
MEMORY
CONTROL
UNIT
ARITHMETIC
LOGIC UNIT
INPUT OUTPUT
3456 3
3457 4
3458 7
3459 True
3460
3461 False
7889 5
7890 2
7891
7892
7893
7894
Add 3456 3457
Add 7889 7890
Store 3458
Store 7891
Compare 3458 7891
Print21 6.100L Lecture 1
MEMORY
CONTROL
UNIT
ARITHMETIC
LOGIC UNIT
INPUT OUTPUT
3456 3
3457 4
3458 7
3459 True
3460
3461 False
7889 5
7890 2
7891 7
7892
7893
7894
Add 3456 3457
Add 7889 7890
Store 3458
Store 7891
Compare 3458 7891
Print22 6.100L Lecture 1
MEMORY
CONTROL
UNIT
ARITHMETIC
LOGIC UNIT
INPUT OUTPUT
3456 3
3457 4
3458 7
3459 True
3460
3461 False
7889 5
7890 2
7891 7
7892
7893
7894
Add 3456 3457
Add 7889 7890
Store 3458
Store 7891
Compare 3458 7891
Print23 6.100L Lecture 1
MEMORY
CONTROL
UNIT
ARITHMETIC
LOGIC UNIT
INPUT OUTPUT
3456 3
3457 4
3458 7
3459 True
3460
3461 False
7889 5
7890 2
7891 7
7892
7893
7894
Add 3456 3457
Add 7889 7890
Store 3458
Store 7891
Compare 3458 7891
Print
True24 BASIC PRIMITIVES
Turing showed that you can compute anything with a very
simple machine with only 6 primitives: left, right, print, scan,
erase, no op
Real programming languages have
More convenient set of primitives
Ways to combine primitives to create new primitives
Anything computable in one language is computable in any
other programming language6.100L Lecture 1© source unknown. All rights reserved. Thiscontent is excluded from our Creative Commonslicense. For more information, seehttps://ocw.mit.edu/help/faq-fair-use/25 ASPECTS of LANGUAGES
Primitive constructs
English: words
Programming language: numbers, strings, simple operators6.100L Lecture 126 ASPECTS of LANGUAGES
Syntax
English: "cat dog boy" not syntactically valid
"cat hugs boy" syntactically valid
Programming language: "hi"5 not syntactically valid
"hi"*5 syntactically valid6.100L Lecture 127 ASPECTS of LANGUAGES
Static semantics: which syntactically valid strings have meaning
English: "I are hungry" syntactically valid
but static semantic error
PL: "hi"+5 syntactically valid
but static semantic error6.100L Lecture 128 ASPECTS of LANGUAGES
Semantics: the meaning associated with a syntactically correct
string of symbols with no static semantic errors
English: can have many meanings "The chicken is
ready to eat."
Programs have only one meaning
But the meaning may not be what programmer intended6.100L Lecture 129 WHERE THINGS GO WRONG
Syntactic errors
Common and easily caught
Static semantic errors
Some languages check for these before running
program
Can cause unpredictable behavior
No linguistic errors, but different meaning
than what programmer intended
Program crashes, stops running
Program runs forever
Program gives an answer, but it’s wrong!6.100L Lecture 130