- What does a computer do?
- What are a computer's fundamental operations?
- Fundamental operations and imperative knowledge
- Algorithms
- How to use programming languages to implement algorithms
01.01 Basics of Computation
- Learn to program
- Learn to think computationally, algorithmically
- Performs calculations
- Built-in primitives
- User-defined methods
- Remembers results
Analogies with everyday examples
- Computing time (lamp 1 ft, ball 1m)
- Computing storage
Insufficiency of basic operations
- 5.2 days to search the Web
- 10123 different possible chess games
Moral: Computers are fast, but we still need efficient algorithms!
- Size of problem
- Fundamentally impossible to compute
- E.g., Turing's halting problem
Two types of knowledge:
- Declarative knowledge: facts; check truth
- Imperative knowledge: how to; find truth
Example: finding square root (Heron of Alexandria)
- Diagramming this imperative knowledge as flow of command
Algorithms are recipes
01.03 Basic Machine Architecture
Two general types of computers:
- Fixed-program computer: executes a specific set of commands
- Stored-program computer: machines that stores and manipulates instructions
- Program, i.e. sequence of instructions, stored in computer
- Interpreter executes instructions in program
Basic machine architecture
- Memory
- Control unit (houses program counter)
- Arithmetic logic unit (ALU)
Basic mechanics:
- Program counter in control unit advances through program in memory
- Memory sends input to ALU, stores output from ALU
- Tests within ALU can effect change on the program counter in control unit
Flow diagram
- Six primitives are sufficient to compute anything that is computable
- Computers with these six primitives are called Turing complete
"a serious pain in some parts of the anatomy"
01.04 Programming Language Characteristics
Each programming language provides
- a set of primitive operations
- mechanisms for combining these primitive operations
- mechanisms for assigning values to computation or expression
Aspects of a computer language
- Primitive constructs (analogous to words)
- Syntax -- how to put words together to form "well-formed" expression
- Semantics -- meaning
- Static semantics -- which syntactically valid strings have meaning
- Formal semantics -- the meaning associated with syntactically valid string free of static semantic errors
In computer science, there is always exactly one formal semantic meaning for any syntactically valid string free of static semantic errors
- Syntactic errors
- Static semantic errors
- Compiled versus interpreted languages
- No such thing as (formal) semantic error, but program may produce result programmer did not intend