Chapter 1
Introduction
Steve Howell devised a virtual machine with a single two-bit register, AX, and four instructions: nada, zero, decr and mod2. Every program is exactly six of those instructions. A run starts with AX holding the input, a number from 0 to 3, and ends in one of three ways:
zeroaccepts the input, the moment it findsAXat 00;decrrejects it, the moment it findsAXat 00 (otherwise it takes 1 fromAX);- the run rejects implicitly when it gets past the sixth instruction with neither of them having seen 00.
nada leaves AX as it is, and mod2 takes 2 from AX when it is 2 or 3. So each program sorts the four inputs into accepted and rejected, and the accepted ones are the set the program decides. Complexity theory calls such a set a formal language or a decision problem; this book calls each of the 16 subsets of {0, 1, 2, 3} a problem. The machine is small enough that every program, every input and every step can be listed, 4,096 programs, so every claim about it can be checked by running all of them.
Once the plain machine worked, Steve used techniques inspired by the Cook-Levin proof to answer the same questions with polynomials. Each step of the machine becomes four polynomials in the state's bits and the instruction's bits, so that evaluating them at 0s and 1s gives the next state. Chained through all six steps, they become polynomials that answer "does this program accept this input?" for every program and every input at once.
Then Steve proved that the Cook-Levin machinery matches the toy. His Python's search runs each problem's example program twice, once on the interpreter and once through the step polynomials, and checks that the two give the same verdicts. Three pieces of his Python, quoted as they stand in virtual-machine at commit 94c3d31, carry the whole idea. First, logic becomes arithmetic (stepper.py, lines 8 to 17):
def NOT(x):
return 1 - x
def AND(x, y):
return x * y
def OR(x, y):
return (x + y) - (x * y)
Second, a program runs through the step polynomials instead of the interpreter, each step evaluating them at the state's 0s and 1s (stepper.py, lines 147 to 158):
def test_with_stepper(program, ax):
AX = ax
halted = False
accepted = False
for cmd in program:
(AX, halted, accepted) = step(
AX=AX,
halted=halted,
accepted=accepted,
op=OPS[cmd],
)
return accepted
Third, the assertions, in find_solutions (virtual_machine.py, lines 159 to 160 and 178 to 180). After running all 4,096 programs on the interpreter, every one of the 16 problems must have a program, and each problem's example program, run through the polynomials on each input, must accept exactly the problem's inputs:
for y in range(16):
assert len(solutions[y]) > 0
for i in range(4):
accepted = stepper.test_with_stepper(example_program, i)
assert accepted == (i in lang)
That agreement is the thesis of this book: the machine and its Cook-Levin translation answer every question the same way. Everything after it widens the check. The C runs both on all 4,096 programs and all four inputs; the six steps are chained into four polynomials that agree with the machine on all 2^14 points; a SAT solver, given the same machine as a formula, finds exactly the machine's programs; and seven implementations in five programming languages compute the same answers. His Python stopped short of chaining all six steps, and this repository finishes the chain (“How it got here”).
Steve wrote the first version by hand in Python, in virtual-machine: the machine (virtual_machine.py), a general polynomial library (poly.py) and a stepper that writes one step of the machine as polynomials (stepper.py). The machine is Steve's invention; the code in this repository, written by AI coding agents (Claude) with human supervision, departs from the 2023 Python wherever a cleaner choice turned up, and its choices are this book's own.
What the book covers §
The first part is the toy for its own sake: a finite machine, completely understood, every question settled by running everything, even in Python. It runs from “The machine” and the theory of formal languages through plain Python, the search of all 4,096 programs, the puzzle page, and the machine as Boolean functions and as hardware, to “Some history of the approach”, the order in which Steve built it.
The second part is Cook-Levin: “How it got here”, “P and NP”, “Nibble, sized”, “Nibble++”, “Two theorems about Nibble++”, “Nibble++ meets rocsat”, “Guided search”, “P, NP and Cook-Levin”, “Six expressions, composed”, then the step as polynomials, from “Arithmetization” to “The polynomials, in full”, and the circuit as tableau and formula, from “The Cook-Levin machine” to “The solver's work, in full”.
The third part is the cross-checks: “The oracles”, “The Roc port”, “What is Shale?” and “The VM in Shale”, then “What comes next”. The theorems are numbered through the book, each checked by a run that its proof names.
Why the name fits §
The Cook-Levin theorem says that satisfiability of Boolean formulas is NP-complete: any problem whose answers a machine can check in polynomial time reduces to it. The proof unrolls the checking machine, step by step, into one formula. This repository does that unrolling on a toy instrument. It makes no claim about NP, and it reduces one machine's questions, never an arbitrary verifier's. It also goes one step past the formula, into arithmetic: the whole program becomes four polynomials with integer coefficients. "A riff" is the honest word for that.
Where the numbers come from §
Each number here comes from the repository, a commit, a golden file or a program run, named where it is used. Code is quoted as it stands when the book is built.