Seven Machines, One Computer

The notional machine, from bytes to a logic engine

CS 2010 — Computing Fundamentals

2026-10-26

One Computer, Seven Machines

A program runs on one computer. But the machine you imagine while you read it is a different machine at every layer — and that imagined machine is the one you actually program.

Notional machine (du Boulay, 1986): the computer you imagine while you read a program — what things exist, what they do, and what happens next.

It is not in the hardware. It is taught. And no error message will ever tell you that yours is wrong.

The Ladder

Each rung is implemented by the rung below it. Each rung up buys you expression and costs you visibility.

Part 0 — The Machine That Is Actually There

Rungs 1 and 2: the machine you can see all of.

The Computer Knows Three Moves

One instruction can do one of three things:

  • arithmetic on two numbers,
  • load or store a word of memory,
  • change which instruction runs next.

Then repeat, forever.

One Job, All the Way Up

The job: sum the squares of the even numbers in a list. For [1 2 3 4] the answer is 20.

what the job needs so every machine must provide
somewhere to keep a running total storage that survives a step
x * x, and + arithmetic
“only the even ones” a way to choose
“every element of the list” a way to repeat

Every rung has to be able to do this one job. That is what makes the rungs comparable — and what makes their differences interesting.

Rung 1: One Instruction at a Time

Rung 2: Names for the Numbers

Part I — Rung 3: The Stack

Rung 3: the first thing in the machine that the hardware has never heard of.

Variables Are Boxes in a Frame

The Frame Is Not in the Chip

The hardware has registers and memory. It has no idea what a function call is.

  • A frame is a range of stack memory that the compiler decided to use for one call’s locals.
  • Scope is a rule about which frame a name resolves to — it exists in the compiler, not in the machine.
  • A return is “put the result in a register, restore the stack pointer, jump”.

Everything you can see in the trace is real memory. Everything that makes it a frame is a convention someone maintains.

Part II — Rung 4: Rewriting the Text

Rung 4: the state stops being memory and becomes the program itself.

A Step Can Be a Rewrite

(define (sqs xs)
  (cond ((null? xs) 0)
        ((even? (car xs)) (+ (* (car xs) (car xs)) (sqs (cdr xs))))
        (else (sqs (cdr xs)))))

The rule: to evaluate a call, substitute the arguments into the body, then keep going.

(+ (* 2 2) (* 3 3)) → (+ 4 9) → 13

The syntax is the tree — you can see which subtree is being replaced.

The State Is the Program

This Is Not What the Computer Does

A real Scheme does not rewrite text. It keeps environments and a stack of pending operations, and it compiles to the same three machine moves as everything else.

The substitution trace is a model. And a model of the machine you should imagine while reading a program is exactly what a notional machine is.

Part III — Rung 5: Values That Don’t Change

Rung 5: the same machine as rung 4, with a different idea about data.

Stop Overwriting, Start Transforming

The Same Machine, Less Typing

rung 4 (Scheme) rung 5 (Clojure)
the machine rewrite the text rewrite the text
who does the recursion you write it filter / map / reduce
lines in the trace 10 4
anything overwritten no no

Same machine, one level of thinking moved into the library. That is what a library is: someone else’s notional machine, ready to use.

Part IV — Rung 6: The Machine With No Steps

Rung 6: the top of the ladder, and the end of steps.

Declare, Don’t Compute

(run* [x] (membero x [1 2 3 4]) (pred x even?))
;=> (2 4)
(run* [x] (membero x [1 2 3 4]) (pred x even?) (pred x #(> % 3)))
;=> (4)

There is no loop. You state what must be true of the answer, and the machine finds values that make it true.

Adding a condition is not editing a program. It is adding a fact.

One Relation, Four Questions

The Trace Is a Tree

What “Running” Means Here

There is no next instruction. The state is a substitution (what we have learned so far) plus a frontier (what is left to try).

  • unify — make two terms equal by binding variables
  • backtrack — when a goal fails, undo the last choice and try the next

The engine underneath is a search. That is the same machine as last week’s SAT solver — and it is what is running inside a package manager deciding whether your dependencies can be installed.

Part V — Above and Below

Where this leaves you, and what is above.

Every Abstraction Leaks

what you see what is really happening
0.1 + 0.2 gives 0.30000000000000004 rung 1: floats are not decimals
a stack overflow rung 3: the frame stack is finite and real
“this one line is slow” rung 1: it is still a loop, whatever it is called
a lazy sequence realising at a strange moment rung 5: the pipeline is not free

A leak is the layer below showing through. When something makes no sense, ask which rung you are actually standing on.

You Already Use Three Declarative Machines

machine you say it works out
SQL which rows you want how to find them
a spreadsheet a formula per cell what order to recompute
an LLM prompt what you want, in English the steps (sometimes)

None of these asks you for a loop. All three are the same move as rung 6: state the answer, let the machine search.

The Language You Will Actually Write

We are not going to write six languages. You will write one: JavaScript, or TypeScript.

It is a synthesis of the rungs you just climbed:

  • frames and locals — rung 3
  • objects on a heap, garbage collected — rung 4
  • map, filter, reduce on arrays — rung 5
  • and an event loop, which is a search you never see

The point of the ladder was never to learn six languages. It was to be able to see the parts of the one you use.

The Ladder Is a Loop

The bottom rung is last Wednesday: gates, which compute with no notion of a step.

The top rung is last Wednesday too: a search for an assignment, which is the SAT problem the boolean lecture ended on.

Seven machines, one computer. And the course you are in is the ladder: bits, then files, then gates, then instructions, then languages — and now you know what is above languages.

Five Things to Remember

  1. A program is one thing. The machine you imagine while reading it is another, and it changes with the layer.
  2. Each layer is implemented by the layer below it. That is the only reason the tower stands.
  3. Going up buys expression and costs visibility. Every rung pays that price.
  4. The state moves: memory → the program text → a search frontier.
  5. The trace changes shape: a line, then a tree.