A riff on Cook-Levin Chapters

Chapter 23

Two theorems about Nibble++

With zero and decr alone, a short proof gives every formal language's shortest length and the count of formal languages at each length. The census of “Nibble++” checks both, and tests/test_census.c holds them.

Theorem 10. With zero and decr alone, the shortest program for a nonempty set S of inputs has exactly max(S) + |S| lines, and the empty set's has 0.

Proof. The inputs move in lockstep: after d decrs, an input x still running has AX = x − d. The decr numbered x + 1 finds input x at 0 and rejects it. A zero accepts the inputs whose AX is 0 when it runs, so a zero after exactly d decrs accepts input d, and every other input passes it: those above d hold AX above 0, and those below d have halted. Inputs above the last such d run to the end and are rejected. So a program decides the set of counts d at which some zero runs. For S it needs a zero at each member's count, |S| lines, and max(S) decrs before the last of them, max(S) lines more. The program that walks d from 0 to max(S), with a zero at each member and a decr between counts, has exactly max(S) + |S| lines. The empty program decides the empty set.

Theorem 11. With zero and decr alone, the number of formal languages whose shortest program has L lines is F(L), the Fibonacci number with F(1) = F(2) = 1, for L from 1 to 16, and F(17) − 1 at L = 17.

Proof. By Theorem 10, the count at length L is the number of sets S with max(S) + |S| = L. A set with largest member m and k members picks its other k − 1 members from {0, ..., m − 1}, so there are C(m, k − 1) of them, with m = L − k. The count is the sum over k ≥ 1 of C(L − k, k − 1). With j = k − 1 it is the sum over j of C(L − 1 − j, j), the sum along a shallow diagonal of Pascal's triangle, which is F(L). The inputs end at 15, so m is at most 15. For L up to 16 every term has m = L − k ≤ 15. At L = 17 the term k = 1 is the set {16}, past the machine's inputs, and the count is F(17) − 1.

The census agrees. The last column is {zero, decr, mod2}, for contrast:

Length L {zero, decr} F(L) {zero, decr, mod2}
1 1 1 1
2 1 1 2
3 2 2 3
4 3 3 6
5 5 5 8
6 8 8 13
7 13 13 21
8 21 21 34
9 34 34 55
10 55 55 89
11 89 89 144
12 144 144 233
13 233 233 377
14 377 377 610
15 610 610 987
16 987 987 1595
17 1596 1597 2556

With mod2 the counts follow the Fibonacci numbers one place on, F(L + 1), from length 1 to 15, apart from length 4, which has 6 where F(5) is 5. At 16 the count is 1,595, two below F(17). mod2 breaks the lockstep that Theorem 10 rests on, since it merges inputs, and a formula for these counts is open here.