Chapter 6
Which instructions are needed
“Programs as formal languages” counted what the four opcodes decide together. This chapter takes them apart: which of the four are needed, and what instructions of other designs could do.
The four opcodes §
Theorem 6. The six-line programs over zero, decr and mod2 decide all 16 problems, and each of the three is needed: dropping zero leaves only { } decided, dropping decr leaves 3 problems, and dropping mod2 leaves 15 (Theorem 2). nada is redundant: the programs over the other three decide all 16. And every shortest program is made of zero, decr and mod2 alone.
Proof. tests/test_theorems.c runs the 4,096 programs, keeps those whose every instruction is in a given set, and counts the problems they decide, for all four opcodes and for each set of three. Only zero accepts, so dropping it leaves every input rejected. Dropping decr leaves { }, {0} and {0, 2}: mod2 brings 2 to 0, and 1 and 3 to 1, where they stay. For the last part, take a nada out of a program and close the gap: every input meets the same lines in the same order, so the shorter program decides the same problem. So every line of a shortest program is zero, decr or mod2, and the same test checks each one.
What it means for a player §
The last part of Theorem 6 is a lemma a player can use. A puzzle with three open lines offers 4^3 = 64 programs to try, but once nada is set aside it offers 3^3 = 27. A player who clicks through those 27, knowing only the buttons, will find the answer. That is the toy's version of the question “P, NP and Cook-Levin” asks: whether finding an answer can ever be easier than trying the possibilities.
Instructions of any kind §
The four opcodes are one choice among many. An instruction of any kind says, for each value of AX, what happens there: a new value, or accept, or reject. That makes 6^4 = 1,296 instructions, and the toy's four are among them.
Theorem 7. Two instructions of that kind decide all 16 problems in four lines: decr, and its twin that accepts at 0 and otherwise takes 1 from AX. One instruction, repeated, decides at most 5 problems at any length.
Proof. For a problem L, line i + 1 is the twin when i is in L and decr otherwise, for i from 0 to 3. Input n reaches 0 on line n + 1, and that line's verdict is L's. tests/test_theorems.c builds the 16 programs and runs them. For one instruction it runs all 1,296, each repeated from 0 to 1,296 times on all four inputs, and finds at most 5 problems for each, and 5 for some. Five is also the bound by argument: an accept is for good, so each length's problem contains the one before it, and a chain of subsets of four inputs has at most five members.