Lecture 1 (Spring 2023)
#

Required readings
#

  • Chapter 1
  • Sections 2.1 – 2.3

What is computation?
#

There are (at least) two kinds of knowledge: (1) declarative knowledge, which are statements of fact; and (2) imperative knowledge, which are recipes or “how-to”s.

Programming is about writing recipes to generate statements of fact.

Example: Finding square roots
  • What is the square root of 16? (declarative knowledge)

  • Babylonian square root finding algorithm (imperative knowledge)

    1. Start with a guess gg
    2. If g×gg \times g is close enough to xx, stop and say gg is the answer.
    3. Otherwise, make a new guess by averaging x/gx/g and gg. Repeat from step 2.

An algorithm is a (1) sequence of steps with (2) clearly defined control flow specifying when each step is executed and (3) a means of determining when to stop.

Computers, then, are machines that execute algorithms. Computers can perform billions of simple operations per section and store those results in memory.

At one point, computers were fixed-program computers; they had a fixed set of algorithms they could perform. However, there was a key insight: programs are no different from other kinds of data. That means we can store programs in memory, and operate on them (i.e. execute them) like another other piece of data. This insight led to the formation of stored-program computers.

Stored-program computers have a predefined set of primitive instructions. The set of primitive instructions include:

  1. Arithmetic and logical operators
  2. Simple tests that can alter control flow
  3. Moving data

If these primitive instructions can execute any program a Turing machine can execute, that set of instructions is called Turing-complete.

What is a programming language?
#

First and foremost, a programming language is a language. Thus, we should examine aspects of languages.

Languages have primitive constructs. Languages also have syntax. When someone does not obey the syntax rules, they commit a syntax error, and these are common but easily caught.

Beyond syntax, however, languages have semantics: the meaning associated with a syntactically correct string of symbols.

Python basics
#

A program is a sequence of definitions and commands. Definitions are evaluated while commands are executed.

Python is an interpreted language: a special program called an interpreter executes your programs.

In Python, everything is an object
#

Converting between types: type casting
#

Mathematical operators
#

Objects are representations of the world, but to build meaningful programs, we need to be able to manipulate these objects. That is the function of operators. In programming, we combine objects and operators to form expressions.

Variables
#

Binding
#

Strings
#

Logical operators and booleans
#