Ref:
-
“Introduction to Computation and Programming using Python” by Guttag.
ROUGH NOTES (!)
Updated: 27/4/26
INTRO TO CS AND PROGRAMMING WITH PYTHON
Lec-1
Link to the lecture: Link.
[Types of Knowledge]
- Declarative knowledge is statements of fact.
- Imperative knowledge is a recipe or “how-to”.
Programming is about writing recipes to generate facts.
[Numerical Example]
Square root of a number x is y such that y * y = x.
- Start with a guess
g. - If
g * gis close enough tox, stop and saygis the answer. - Otherwise make a new guess by averaging
gandx/g. - Using the new guess, repeat the process until close enough.
Why does it work?
Here is a pic:
[We have an ALGORITHM]
Checklist for an algorithm:
- Sequence of simple steps.
- Flow of control process that specifies when each step is executed.
- A means of determining when to stop.
Algorithms = Recipes.
[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, eg, +
- Ones that you define as the programmer
A computer will only do what you tell it to do.
[Computers are machines that execute algorithms]
Fixed program computer
- Fixed set of algorithms
- What we had until 1940s
Stored program computer
- Machine stores and executes instructions
Programs are no different from other kinds of data.
[Stored program computer]
The Stored program computer has:
- Sequence of instructions stored inside computer
- Built from predefined set of primitive instructions: Arithmetic and logical, Simple tests, 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 instruction
Look at slides 17 to 24 here. Link to the slides: Link.
[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 language.
[Aspects of Languages]
Primitive constructs: (Analogy)
- English: words
- Programming language: numbers, strings, simple operators
Syntax: (Analogy)
- English:
"cat dog boy"is not syntactically valid."cat hugs boy"is syntactically valid. - Programming language:
"hi"5is not syntactically valid."hi"*5is syntactically valid. (We haveobject operator object)
Static semantics: which syntactically valid strings have meaning
- English:
"I are hungry"is syntactically valid but has static semantic error. - PL:
"hi"+5is syntactically valid but has static semantic error. (Not valid even though we haveobject operator object.)
(To do: Syntax and Static Semantics)
[Aspects of Languages]
Semantics: the meaning associated with a syntactically correct string of symbols with no static semantic errors
English: can have many meanings. For eg, "The chicken is ready to eat."
Programs have only one meaning. (But the meaning may not be what programmer intended).