IBM Research Proves Why Transformers Fail Hard Math Beyond Quadratic Complexity
New theoretical work shows transformers have an inductive bias toward low-complexity algorithms, explaining why they nail sorting but fail at shortest-path.
ProTakeaways
- New paper formally defines algorithmic capture as generalization to arbitrary sizes with only logarithmic fine-tuning samples.
- Introduces EPTHS complexity class to measure how hard a task is under its natural input distribution.
- Proves infinite-width transformers cannot capture tasks above O(T^{3+ε}) complexity, tightened to O(T^{2+ε}) under NTK convergence assumptions.
- Empirically confirms capture on induction heads, sorting, and string matching tasks.
- Shortest path, max-flow / min-cut, and context-free grammar parsing all fail to capture, even with 40-layer models.
- Feature learning helps sample complexity but does not raise the inference-complexity ceiling.
A common frustration with large language models is that they can ace a math problem one day and stumble on a rephrased version the next. New theoretical work from IBM Research and the Hebrew University tries to explain why, with a framework that separates transformers that have actually internalized an algorithm from transformers that are just doing sophisticated pattern matching. The paper derives hard upper bounds on the computational complexity of algorithms a transformer can learn, and backs them up with experiments across seven combinatorial tasks.
The problem with saying a model understands something
Debates about whether LLMs reason or memorize tend to bog down in philosophy. The GSM-symbolic benchmark shows that performance on mathematical reasoning tasks can degrade significantly when symbolic templates are altered, suggesting a reliance on pattern matching rather than robust algorithmic execution. But there is no crisp definition of what genuine algorithmic understanding would even look like.
The authors argue that combinatorial tasks are the right laboratory for this question. Extrapolation to arbitrarily large task instance sizes is an inherent requirement, and such strong out-of-distribution settings make statistical correlation and simple interpolation far less effective. Existing algorithms provide a reliable ground truth regarding worst-case, average-case, and heuristic complexity. These theoretical bounds can be contrasted with the computation required for network inference, allowing us to refute the possibility that a network grokked a task without needing to interpret its inner workings.
A sharp definition of grokking
The core new concept is algorithmic capture. A transformer captures a task if, after training on instances up to some base size, it can handle arbitrarily larger instances using only a logarithmically small number of extra fine-tuning samples. That logarithmic budget is the key criterion.
Why logarithmic rather than zero? In principle, one might regard O(1) additional samples as the cleanest signature of genuine capture. Empirically, however, this standard appears too strict. In combinatorial optimization problems, performance typically deteriorates as one moves away from the training size distribution. A natural architectural reason is attention dilution: for fixed learned key-query geometry, attention becomes increasingly diffuse as the context length grows, so even a correctly learned heuristic may require mild recalibration when transported to larger T. Allowing polynomial re-adaptation, on the other hand, blurs the line between calibration and relearning the task.
Alongside capture, the authors introduce a complexity class called EPTHS (Efficient Polynomial-Time Heuristic Scheme). Loosely, a task is in EPTHS with complexity O(T^k) if there is an algorithm that runs in polynomial time in the instance size T and produces the correct output on most inputs drawn from the natural task distribution. This gives a principled scale against which transformer inference cost can be compared.
The main theoretical result
By analyzing transformers in the infinite-width limit, where the network behaves like a kernel predictor built from the Neural Network Gaussian Process (NNGP) or Neural Tangent Kernel (NTK), the authors bound how much compute is needed to evaluate the model on a new input of context length T. The punchline appears in a single table:
| Regime | Evaluation | Inference Complexity | Max EPTHS complexity capturable |
|---|---|---|---|
| NNGP/NTK | Kernel Monte Carlo | O(P N_MC T^3) | O(T^{3+ε}) |
| NNGP/NTK | Forward-pass | O(N T^2) | O(T^{2+ε}) |
| Rich mean-field | Forward-pass | O(N T^2) | O(T^{2+ε}) |
The interpretation is blunt: despite their universal expressivity, transformers possess an inductive bias that disfavors higher-complexity algorithmic procedures within the efficient polynomial-time heuristic scheme class. A transformer is universal in principle, but its learning dynamics push it toward algorithms whose inference cost scales no worse than cubic, and probably closer to quadratic, in the sequence length. Anything that requires genuinely more compute per token is out of reach.
One subtle consequence: while feature learning can have drastic sample complexity effects, it does not have similar inference complexity effects. Rich, feature-learning regimes get you the same complexity ceiling as lazy kernel regimes.
Which tasks get captured and which do not
The empirical section is where the theory earns its keep. The authors identify transformers that capture the induction head, sorting, and string matching tasks. Conversely, several transformers, including very deep ones, fail to capture the source-target shortest path problem, the Max Flow / Minimal Cut problem, and the context-free grammar parsing problem.
- Captured (low complexity): induction heads, sorting a vocabulary of integers, and matching a 3-token string. These have simple RASP-style solutions well within the O(T^2) budget.
- Not captured, even at depth 40: shortest path and min-cut on random geometric graphs, and recognizing strings from a context-free grammar.
Interestingly, shortest path has average-case complexity around O(T log T) and min-cut around O(T^2), both technically within the theoretical bound. The bound is a ceiling, not a floor, so failure below it is allowed. The context-free grammar task, however, sits above the bound, and the theory flatly predicts capture is impossible at fixed depth regardless of model capacity.
Why this matters
The methodology is worth understanding on its own. The proof works by:
- Replacing the infinite-width transformer with its equivalent kernel predictor, so the network is a weighted sum of kernel evaluations over training points.
- Showing that each kernel evaluation can be computed by Monte Carlo sampling of attention scores, at cost O(N_MC T^3) per pair of inputs.
- Proving that Monte Carlo errors do not blow up with T as covariance propagates through blocks, thanks to Lipschitz bounds on softmax and LayerNorm.
- Concluding that any task the network captures admits a heuristic algorithm at that same complexity.
The framework has some real limitations. The theory covers next-token prediction only and purposely sets aside the potential yet not at all obvious benefits of scaling depth and scratchpads to focus on the complexity of next-token predictions. Chain-of-thought reasoning and reinforcement learning with verifiable rewards are left for future work, though the capture definition applies verbatim to them. The upper bounds are also conservative, and the authors conjecture the true bound is tighter, which would explain why shortest path fails even though the bound formally permits it. No code repository is released with the paper; the contribution is definitional and theoretical, with experiments serving as illustrations.
The practical takeaway for anyone building or evaluating models on algorithmic tasks: if the ground-truth algorithm needs more than roughly quadratic work per input token, do not expect a vanilla transformer to internalize it, no matter how big you make the model. Either give it more inference-time compute through scratchpads and chain of thought, or accept that the model is doing interpolation on the size range you trained on and will drift as instances grow.