The right prompt can theoretically turn a transformer into any computer program — but does training actually produce that, or just clever mimicry?
How does program synthesis relate to transformers computing general algorithms?
This explores the two-way relationship between program synthesis and transformers-as-computers: transformers can be programmed (prompts as code, heads as extractable programs), yet whether they actually run general algorithms — versus memorized shortcuts — is contested.
This explores the two-way relationship between program synthesis and transformers-as-computers. In one direction, the transformer is the thing being programmed; in the other, its internal computation is what gets synthesized back into explicit programs. The corpus puts both directions in tension with a harder question: do transformers actually compute general algorithms, or only appear to?
Start with the strongest claim that they can. A single finite-size transformer is provably Turing complete — there exists one fixed network that, given the right prompt, computes any computable function, with the prompt itself acting as the program Can a single transformer become universally programmable through prompts?. So in principle the transformer is a universal machine and the prompt is program synthesis by another name. The catch, stated in that same result, is that ordinary training almost never produces a model that has actually learned to run arbitrary programs this way. Existence is not learnability.
Program synthesis also runs the other direction: instead of writing programs for the transformer, you recover programs out of it. One line of work synthesizes executable code that matches 99% of an attention head's behavior, then swaps 30–40% of heads for their synthesized programs while preserving question-answering ability Can executable programs replace transformer attention heads?. That is a concrete bridge — it says a large chunk of what a transformer computes really is program-like enough to be extracted as testable code, which doubles as a formal interpretability method rather than a hand-wavy natural-language summary.
But when you ask whether transformers compute *general* algorithms, the corpus gets skeptical. Compositional reasoning often reduces to linearized subgraph matching — the model memorizes computation subgraphs from training and fails on novel compositions, with errors compounding Do transformers actually learn systematic compositional reasoning?. And chain-of-thought, which looks like an algorithm being executed step by step, may be an architectural workaround: feedforward transformers have no native recurrent state, so they externalize evolving state into tokens because depth runs out Why do transformers need explicit chain-of-thought reasoning?. There is even evidence the real computation hides in early layers and gets overwritten by filler tokens Do transformers hide reasoning before producing filler tokens?. So the surface program isn't always the actual computation.
What closes the gap is giving the architecture the machinery a general algorithm needs. Looped, recurrent-depth transformers with shared weights achieve compositional generalization and depth extrapolation vanilla ones cannot, emerging through a sharp memorize→in-distribution→out-of-distribution grokking transition Can looped transformers generalize to unseen knowledge combinations?. Hierarchical dual-recurrence escapes the fixed-depth AC0/TC0 ceiling to solve Sudoku and mazes where chain-of-thought fails outright Can recurrent hierarchies achieve reasoning that transformers cannot?. Adding an explicit stack tape buys 3–5x more sample-efficient recursive-syntax learning Can explicit stack tracking improve how transformers learn recursive syntax?. And transformers can even bootstrap themselves into true algorithmic generalization — self-training on their own filtered-correct solutions carries 10-digit addition to 100 digits Can transformers improve exponentially by learning from their own correct solutions?. The through-line: program synthesis is where transformers-as-general-computers stops being a proof-of-existence and becomes something you can either extract, engineer, or train into being.
Sources 9 notes
Research proves a single finite-size transformer exists that can compute any computable function given the right prompt, achieving complexity bounds nearly matching unbounded models. However, standard training rarely produces models that learn to implement arbitrary programs this way.
Program synthesis recovers executable code matching 99% of attention head behavior. Substituting the best-fit 30–40% of heads with their synthesized programs preserves QA ability, offering formal, testable interpretability instead of natural-language summaries.
Research shows transformers succeed on in-distribution tasks by memorizing computation subgraphs from training data, not by learning systematic rules. They fail drastically on novel compositions, with errors compounding across reasoning steps.
Feedforward transformers lack native recurrent state-tracking and must push evolving state deeper into layers, eventually exhausting depth. Explicit chain-of-thought externalizes this state into tokens as a costly patch for a structural deficiency.
Logit lens analysis shows models trained with hidden CoT tokens compute correct answers in layers 1-3, then actively suppress these representations in final layers to produce format-compliant filler output. The reasoning is fully recoverable from lower-ranked token predictions.
Show all 9 sources
Recurrent-depth transformers with shared parameters across iterations enable systematic generalization and depth extrapolation that vanilla transformers cannot achieve. This emerges through a sharp three-phase process: memorization, in-distribution, then out-of-distribution generalization.
The Hierarchical Reasoning Model couples slow abstract planning with fast detailed computation across two timescales, achieving near-perfect performance on Sudoku and mazes where chain-of-thought methods fail completely. With only 27M parameters and 1,000 samples, HRM escapes the AC0/TC0 complexity ceiling that constrains fixed-depth transformers.
Pushdown Layers—a drop-in self-attention replacement with explicit stack tracking—achieve 3-5x more sample-efficient syntactic generalization while maintaining perplexity. The improvement shows that recursive structure specifically benefits from architectural inductive bias despite general compositional generalization emerging from scale.
Standard transformers generalize from 10-digit to 100-digit addition by repeatedly generating solutions, filtering for correctness, and retraining—showing exponential (not linear) out-of-distribution improvement across rounds without saturation.
Papers this line draws on 8
The research behind the notes this line reads — ranked by how closely each paper relates.
- Grokked Transformers are Implicit Reasoners: A Mechanistic Journey to the Edge of Generalization
- Loop, Think, & Generalize: Implicit Reasoning in Recurrent-Depth Transformers
- A Mechanistic Analysis of Looped Reasoning Language Models
- Faith and Fate: Limits of Transformers on Compositionality
- The Topological Trouble With Transformers
- Beyond Semantics: The Unreasonable Effectiveness of Reasonless Intermediate Tokens
- Performative Thinking? The Brittle Correlation Between CoT Length and Problem Complexity
- How do Transformers Learn Implicit Reasoning?