Chapter 39
The oracles
Every implementation in this repository computes the same answers in its own way, and each is held to the others. The spine of the project is that they all agree.
What each one checks §
- Python, the original, is the source of
tests/golden/find_solutions.txtand of the step polynomials' strings,tests/golden/step_*.txt. - C prints that report byte for byte (
tests/test_golden.c), checks the stepper against the interpreter on all 4,096 × 4 runs, and proves the composition at all 2^14 points (tests/test_compose.c).shale build.shaleran its fast tier for this book: eleven test files and the golden check, all passing. - Roc prints the same report, the four step polynomials as the C's
bp_strprints them (roc/golden/step_polynomials.txt) and the composition's counts and proof (roc/golden/composition.txt).roc/check.shaleis its gate. - SAT reaches the 16 counts through
tests/test_sat.c's propagation and again through rocsat's blocked models, and each shortest length through an UNSAT, with a DRAT proof thatsrc/drat.cverifies, and a SAT. - JavaScript,
js/cook_levin.js, prints the report and then the composition, byte for byte the two goldens, under three runners. - Shale,
shale/cook_levin.shale, prints the same report and composition, held to the two goldens byte for byte byshale/check.shale. - Nibble's wasm is
src/vm.citself, andweb/page_check.mjsholds it to the C on all 4,096 × 4 runs and to the 16-puzzle table.
One program, three runners §
js/oracle.shale runs the JavaScript port three ways (c251895), each held to the goldens. The runners are node, and two of roc-js-interpreter's, both written in Roc: its bytecode VM and its compiler to x86-64. The port is written in the subset of JavaScript that roc-js-interpreter runs, which leaves out the bitwise operators, so the OR and AND of two masks come from tables of their 7-bit halves.
By README.md's timings on this box, 2026-11-25: node takes about 0.3 s, the VM about 80 s, in about 15 million of its steps, and the compiled executable, 111,698 bytes, 0.6 to 1.0 s, at a peak of 33 MB. The compiled program is slower than node here, and that is unprofiled. These runs were left unrepeated for this book.
Why so many §
Each pair shares only the machine's rule. The interpreter branches on opcodes, the stepper evaluates polynomials, the composition substitutes them, the SAT encoding propagates clauses, and rocsat searches. A bug would have to land the same way in all of them to pass.