ΒΆPaper Feed

Issue 45 Β· Pick 08 AI / ML βœ“ read

Sketchpad: certified exact arithmetic with a small vision-language model

Mostafa 'Neo' Mohsenvand

TL;DR: Take a 0.8B vision-language model, force every "step" of a long computation to be a pure function of a tiny rendered image β€” three cells of a worksheet β€” and suddenly exactness becomes a finite property: there are only 2,446 possible views, so checking all of them (which takes 3.5 minutes in a browser) certifies correct arithmetic on inputs of any length. The paper proves this equivalence in Lean, proves that no finite test can do the same for chain-of-thought, and backs it with a logit-margin argument that makes the certificate survive 16-bit WebGPU inference. The result: a laptop model that adds 1,000-digit numbers with a proof-backed guarantee, while GPT-6.1 Sol silently drops a few.

The problem: accuracy is a sample statistic, not a guarantee

Frontier LLMs are very good at long arithmetic now. In this paper's pre-registered comparison, the best of ten other models got 217 of 220 problems right. But the three errors are the interesting part: on 300- and 1,000-digit sums, GPT-6.1 Sol produced completed, well-formatted, wrong answers β€” indistinguishable in form from the correct ones. Measured accuracy is an estimate over a test distribution; it says nothing about the next input, and the failure mode is silent.

The standard escape is tool use: hand the arithmetic to Python. Exact, but the computation no longer happens in the network β€” you've certified the interpreter, not the model. The research question here is whether a neural network's own forward passes can carry a universal guarantee: correct on every input of every length, not just the tested ones.

The obstacle is obvious once stated: there are unboundedly many inputs, so a guarantee needs the behaviour on infinitely many cases to be pinned down by finitely many facts.

The key move: make the step a function of a bounded view

There is a classical situation in which infinitely many behaviours are pinned down by finitely many facts: a finite-state machine. A Turing machine runs forever on an unbounded tape, but its transition table is finite β€” verify the table and you've verified every run.

Sketchpad imposes exactly this structure on a pretrained VLM. The architecture of the computation is:

  • The sheet holds all state: a grid of 32-pixel cells, each blank or a digit from a fixed glyph set, laid out like pencil-and-paper arithmetic.
  • The model (Qwen3.5-0.8B plus a rank-16 LoRA adapter, 10.2M trained parameters, 1.2% of the model) sees one view per step: three cells, rendered as a 32Γ—96 strip, entering the vision encoder as three image tokens. The prompt is just an operation token, the image, =, and two placeholders. One forward pass emits one step's outputs at those positions: a digit, a carry/borrow, and the next operation.
  • The runtime (a few hundred lines of conventional code per procedure) writes the outputs back to the sheet, moves the view, and sequences the outer loops. Crucially, it never writes a digit of a result β€” every number comes from the model.

The paper calls this the pinned-sheet policy: nothing passes between steps except through the sheet, and each step reads only its bounded view. Under it, the model's behaviour is a function f from views to outputs β€” and the set of views any procedure can ever encounter is enumerable in advance. For column addition it's 242 views (carry Γ— top digit Γ— bottom digit); long multiplication's five sub-operations total 1,553; subtraction, quotient estimation, and estimate-decrement add 651. Total: 2,446 views, listed exhaustively in tables with their correct outputs T(v).

Rendered sheet (all state) 1 748 61 4 view = 3 cells (32Γ—96 px) 3 image tokens Qwen3.5-0.8B + LoRA one forward pass f : view β†’ step digit: 2 carry: 1 next op: A runtime paints outputs, moves view β€” writes no result digit itself only 2,446 possible views exist β†’ check them all
One step of long multiplication. No hidden state survives between steps; the sheet is the only memory, and each step reads only a bounded window of it. The model becomes a learned transition table of a finite-state machine.

The theorems: why finite checking suffices β€” and why it can't for chain-of-thought

Theorem 1 (exactness on views). If the runtime's reference runs only ever present views in the table set V, and the model's output f(v) matches the table T(v) on every v \in V, then every run from every initial configuration is exact at every step, for inputs of any length. The proof is a straightforward induction (formalized in Lean 4 with Mathlib, no sorry, no extra axioms): as long as the model's run agrees with the reference run, the next view is a certified one, so the next step agrees too. The converse also holds under a mild injectivity condition β€” so the finite check is not just sufficient but equivalent to universal exactness.

Theorem 2 (necessity). Here's the sharpest conceptual contribution. Suppose instead that each step's context retains all earlier steps β€” i.e., ordinary chain-of-thought. Then no finite test suite can certify the model, however long the tested inputs. The construction is concrete: take a correct two-state lookup plus a single attention head that attends to a sink token with score c and writes mass 4Rk/(e^c + n) onto the wrong state's logit, where n is context length, k counts event tokens, and R is the lookup's margin. For any finite test set with max context length M, set e^c = 3M+5: the interference stays below R on every test β€” all tests pass with positive margins β€” but grows past R on longer runs and flips the state. The same decoder, run under the pinned-sheet policy, is exact forever, because the interference term is pinned to a constant. This is Moore's 1956 result about identifying finite automata, resurrected as a statement about transformer verification.

run length interference on wrong token margin R: above this, output flips pinned view: constant, certified once chain of thought: grows with context every finite test lives here βœ“ silent failure βœ—
Theorem 2 in a picture. When steps read the full history, a single attention head's interference can be tuned to clear any finite test suite and still cross the decision margin on longer runs. Pinning each step to a bounded view caps the interference, so one finite check covers all lengths.

Theorem 3 (robustness). Exact-arithmetic theorems are useless if deployment is 16-bit WebGPU. The fix is to certify margins, not just argmaxes: m(v) is the smallest lead of a correct token's logit over any competitor across the step's output positions. If every margin exceeds 2\tau and the deployment path's logits stay within \tau of the certified ones, the argmax β€” and hence the entire run β€” is unchanged. They certify directly on the deployment path (ONNX Runtime Web, WebGPU, fp16, Apple M4 laptop): all 2,446 views pass, smallest margin 3.02 logits, tolerating any perturbation below 1.51. Batched inference shifts logits by at most 1.09 in their sampled checks β€” under the bound. The cautionary tale motivating all this: a 4-bit quantized decoder of a preliminary adapter flipped a margin from +9.4 to βˆ’8.9. Margins are not a formality.

Training is refreshingly literal: cross-entropy plus a hinge loss on the margin over the 2,446 table rows, with low-margin rows replayed, plus a KL distillation term toward the base model on plain text to limit forgetting. Training stops when every row's margin β‰₯ 3. Twenty minutes on one H100. And the capability is genuinely learned, not latent: the base model passes only 12 of 2,446 views zero-shot, 158 few-shot.

The evidence

The headline comparison: 220 pre-registered problems (sums of 10–1,000 digits, products of 2–20-digit numbers), same prompt, 32,768-token budget.

Pre-registered comparison: exact answers out of 220problems exact050100150200220Sketchpad (0.8B)217GPT-6.1 Sol216Claude Opus 5.5207Gemini 4 Argon199DeepSeek-V4-Pro121Qwen3.5-27B CoT23Qwen3.5-0.8B baseExtended Data Table 5. All frontier-model errors were on 300- and 1,000-digit sums; GPT-6.1 Sol and Claude's errors were completed, silently wrong answers. The base model Sketchpad is built on scores 23/220.

A separate 200-problem browser test (division to 10 decimal places, square roots to 6 places, GCDs, signed 20-digit sums, all pre-registered) came back 200/200 on the laptop, median 2–10 s per problem. Division uses Knuth's Algorithm D, with the operands pre-scaled on the sheet so the quotient-estimation table needs only 400 entries and the estimate \hat q provably satisfies q \le \hat q \le q+2; square roots get an analogous scaling trick so one estimation table serves every digit. These classical normalizations are what keep the view set finite β€” the paper is as much careful algorithm engineering as ML.

Composition (Theorem 4) extends the guarantee upward: a derivation is a sequence of certified calls, so a wrong final answer requires a wrong table (excluded by the certificate), a wrong transcription, or a wrong combining program β€” both of which are conventional runtime code, guarded by exact answer checks (Vieta's relations, substitution, evaluation at points). On this base, a symbolic runtime expands (x+2)^5, factors cubics, and solves small linear systems with every number computed by the model, in 3–22 s.

One more engineering touch worth stealing: the LoRA adapter is multiplied by a scalar graph input g. At g=0 the adapter branch contributes exact floating-point zero, so the gated model is bit-for-bit the base model β€” verified on logits, hidden states, and KV caches. Arithmetic specialization with zero collateral damage outside the sheet, as a hard switch rather than a hope.

Where it cracks, and where the authors admit it

The paper is unusually honest about its boundary, and you should hold it to that boundary:

  • The guarantee covers the model's steps only. The runtime β€” layouts, outer loops, the claim that reference runs present only table views (R_T(I) \subseteq V) β€” is conventional code, not formalized in Lean. It's asserted at each step and fuzz-tested on 1,000 random problems per procedure. A runtime bug voids everything. The trusted computing base moved; it didn't vanish. This is still very different from tool use (the model computes every digit), but "certified" refers to a specific, bounded claim.
  • The certificate is device- and path-specific. Margins were measured on one M4 laptop; a new GPU by default rechecks only the lowest-margin tenth of each table. The batching robustness check samples batch compositions rather than bounding all of them (\tau = 1.09 observed, not proven).
  • Generality is narrow. This works because arithmetic has rigid, local, classical procedures. The finite-view trick requires that every reachable step-input be enumerable β€” fine for schoolbook algorithms, unclear for anything requiring unbounded or content-dependent context. The algebra layer tops out at low-degree univariate polynomials and 3Γ—3 linear systems.
  • The reasoning tax is real. The dialogue adapter, trained to invoke the sheet from natural language, hit its pre-registered criteria on development items β€” then, rescored on fresh items (it was the fifth candidate scored on the dev set, and they say so), lost 5.8 points on GSM8K versus the base model. Certified arithmetic, slightly degraded multi-step reasoning. The precision/recall of invoking the sheet is excellent (0.994/0.989), but ~7% of word problems get mistranslated into the wrong computation β€” which no certificate touches.
  • It's slow. ~0.1 s per step; (x+1)^{10} takes 22 seconds. Nobody will use this as a calculator. Its value is as an existence proof.

Why it matters anyway

The lasting idea is the pairing of Theorems 1 and 2: bounded per-step context is not just sufficient for finite certification β€” it is necessary. Any scheme where steps read their own history (chain-of-thought, most length-generalization setups) is in principle uncertifiable by finite testing, no matter how long the tested inputs. That reframes the context-discipline line of work (inductive scratchpads, PENCIL) as points on a spectrum whose verifiable limit is the pinned view, and it gives a crisp theoretical reason to externalize working memory if you want guarantees rather than estimates. The margin-based Theorem 3 is the practical glue β€” it's what lets a Lean theorem about an idealized function say something about fp16 kernels in a browser, and it's reusable anywhere a neural component has a finite certified input set.

If you read one section, read Section 3 (Certification) together with the Theorem 2 construction in Appendix A β€” the counterexample is three lines of math and worth internalizing. The Methods subsection on division and square-root normalization is a close second: it shows how much classical numerical craft is needed to make the view set finite in the first place, which is also the clearest signal of how hard this recipe will be to extend.