A Measure-Theoretic Analysis of Reasoning in Transformers: Structural Generalization and Approximation Limits

Yuyang Zhang, Yifu Zhang, Xuehai Zhou, Xiaoyin ChenNeurIPS 2026

TL;DR

When a Transformer learns to reason via step-by-step search, can a model trained on shallow, breadth-first traces generalize to deep, backtracking-heavy problems? By mapping discrete reasoning traces into a continuous geometric space, the authors prove—and empirically verify—that generalization hinges on two architectural choices: relative positional encodings (like RoPE) to survive shifting token positions, and physical layer depth (not width) to handle recursive backtracking.

What Problem Does This Paper Address?

Chain-of-thought prompting lets Large Language Models (LLMs) solve complex math and planning problems by writing out explicit search traces—exploring branches, hitting dead ends, and backtracking. Effectively, the LLM is flattening a search tree into a sequence of text tokens.

While we know empirically that bigger models generally reason better, a glaring theoretical blind spot remains: what happens when the shape of the search tree changes at test time? Standard metrics like token-level perplexity cannot tell the difference between a shallow breadth-first search and a deep depth-first search—two traces can have identical token likelihoods while executing completely different algorithms. Prior work studied circuit limits, positional encodings, and data shifts in isolation. This paper unifies them to predict exactly when an architecture will generalize out-of-distribution (OOD) and when it will hit a hard failure wall.

Methods

The authors build a bridge between discrete text generation and continuous measure theory:

  • Structural Projection ($\Phi$): Instead of looking at raw words, they map every reasoning trace into a 12-dimensional vector of structural summary statistics (e.g., max tree depth, search volume, deepening rate, backtracking rate, and pruning rate).
  • Wasserstein-1 ($W_1$) Task Shift: Projected into this 12D space, an entire dataset becomes a probability distribution. The structural shift between a training task and a test task is measured as the $W_1$ optimal transport distance—intuitively, the "work" required to morph one distribution of search shapes into another.
  • Unified Risk Bound: Using Kantorovich duality, they bound OOD failure rates by combining three potential bottlenecks: the $W_1$ shift multiplied by the architecture's positional sensitivity (its Lipschitz constant), a representation-width limit (via Barron spaces), and a circuit-depth limit (mapping last-in-first-out backtracking onto parenthetical $\text{Dyck-}k$ languages within $\mathsf{TC}^0$ circuit complexity).

Datasets

  • Countdown (Stream of Search format): Models combine input numbers using basic arithmetic to hit a target number, with the full search tree serialized into tokens. Using a simulator, the authors generate three distinct 500,000-trajectory training distributions over the exact same problem population: BFS (lateral priority-queue expansion), DFS (recursive stack expansion with ~4x the backtracking rate of BFS), and MIXED (a randomized 50/50 blend of BFS and DFS).
  • Extended Benchmarks (Appendix): Public software-engineering agent trajectories (SWE-bench Verified under mini-SWE-agent and OpenHands), embodied/robotic trajectories, and nested tool-call tasks evaluated across 33 open-weight LLMs.

Key Insights and Ideas

  • Absolute Positional Encoding (APE) breaks modular search: In tree search, the exact same sub-problem might appear at token 20 or token 220 depending on how many dead ends preceded it. Shifting a reasoning sub-trace forward in the sequence almost surely alters APE's internal attention scores, which can misroute greedy search down a wrong branch. RoPE, by parameterizing attention via relative token offsets, preserves local attention scores under translation, acting as a structural regularizer.
  • Width cannot buy you recursive depth: Resolving recursive backtracking requires matching nested states (like closing parentheses). Fixed-depth Transformers face a hard $\mathsf{TC}^0$ ceiling: a single forward pass of $L$ layers can only resolve tree depths up to a linear multiple of $L$. Making the network wider shrinks approximation error on shallow features, but does nothing to raise this depth ceiling.
  • Your weakest link sets the error floor: Target error is lower-bounded by the maximum of the width, depth, and transport bottlenecks. Fixing positional encodings won't save a shallow model on deep trees, and adding layers won't save an APE model from severe position shifts.

Key Results

The authors trained 54 Transformers from scratch across 3 scales (Small, Medium, Large), 3 shapes (Deep, Wide, Balanced—holding core parameters $12Ld^2$ constant per scale), and 2 encodings (APE vs. RoPE):

Countdown accuracy across model shapes and search strategies
  • RoPE Dominates Across Scales: RoPE beat APE in 25 of 27 matched model pairs ($p < 10^{-5}$) and all 27 comparisons at the Large scale (Figure 1D). Under the variable token positions of MIXED, scaling Wide APE models to Large caused accuracy to collapse to 42.15%, while Large Wide RoPE remained rock-solid at 54.25% (Figure 1C).
  • The $\mathsf{TC}^0$ Depth Ceiling is Real: On backtracking-heavy DFS evaluations, all 54 models fell beneath the theoretical depth ceiling (Figure 1A). Holding depth fixed at $L=12$ or $L=24$ and doubling hidden width (quadrupling parameters from 84.9M to 339.7M at $L=12$) budged peak accuracy by less than 1 percentage point.
  • Direct Position-Shift Interventions: Artificially shifting position indices by +16 or +64 on Countdown left RoPE's resumed search success completely unchanged (59.4%), whereas APE success plummeted from 52.7% down to 12.2%–13.4%. Similarly, across 33 open-weight LLMs, a +256 index shift (common in prefix caching or left-padding) degraded APE accuracy by up to 52 percentage points, while leaving fp32 RoPE and ALiBi virtually untouched.
  • Splitting Deep Tasks Works: Decomposing depth-8 nested tool calls into single-level sub-calls across separate forward passes bypassed the single-pass depth limit, jumping accuracy across eight open-weight LLMs from 1.5%–15.5% up to 43.5%–99%.

Limitations and Future Work

  • Formal vs. Natural Language: The theoretical guarantees rely on an $\epsilon$-relaxed structural sufficiency assumption—that the 12 structural coordinates capture task difficulty up to a small residual $\epsilon$. While verified on formal Countdown planning, extending this to messy, open-ended natural language reasoning remains an open problem.
  • Fixed Problem Difficulty: Because all three Countdown datasets share the same underlying problem difficulty, future benchmarks that simultaneously shift problem difficulty and search strategy are needed to more directly stress-test the $W_1$ transport penalty.
  • External Search Wrappers: The $\mathsf{TC}^0$ depth bound applies to single-pass autoregressive generation; formalizing how external inference-time search (like Monte Carlo Tree Search or Tree-of-Thoughts) reshapes the target distribution is left for future work.

Summary updated

Abstract

While empirical scaling laws for reasoning in large language models (LLMs) are well established, it remains unclear when a model trained on one class of search traces can generalize to structurally different out-of-distribution (OOD) problems. We study this question by projecting each discrete search trajectory into a twelve-dimensional space of structural coordinates—such as tree depth and backtracking rate—and quantifying task shifts via the Wasserstein-1 ($W_1$) distance. Using Kantorovich duality, we bound OOD generalization risk in terms of this transport distance, the architecture's structural Lipschitz constant, and capacity lower bounds from network depth and width. This analysis yields two main architectural conclusions. First, under absolute positional encoding (APE), translating a reasoning sub-trajectory to later token positions almost surely alters its internal attention scores. When these perturbations misroute greedy exact-match search, the structural Lipschitz constant is $\Omega(1)$, and target risk has an order-one lower bound whenever misrouted structures carry enough target mass to exceed the approximation error by a fixed margin. By contrast, rotary position embedding (RoPE) preserves local attention scores under translation for fixed content vectors; under our baseline smoothness assumption, its transport penalty scales as $\mathcal{O}(W_1/T_{\max})$, where $T_{\max}$ is the maximum sequence length. Second, by reducing sequential backtracking to a Dyck-$k$ language under an implicit-depth assumption, we prove that fixed-depth Transformers face an irreducible risk floor when sufficiently many target searches exceed a multiple of their layer count. Adding layers removes this bottleneck, whereas widening the network only reduces a separate Barron-space term in the risk lower bound. Experiments on 54 Transformers trained from scratch on Countdown support these predictions. Further evaluations in the appendix extend our framework to broader settings: we quantify structural shifts across public agent, embodied, and robotic trajectories; evaluate 33 open-weight LLMs under global position-index shifts; and test when splitting nested tasks across model calls improves final-answer accuracy.
BibTeX
@inproceedings{zhang2026measure,
  author = {Yuyang Zhang and Yifu Zhang and Xuehai Zhou and Xiaoyin Chen},
  title = {{A Measure-Theoretic Analysis of Reasoning in Transformers: Structural Generalization and Approximation Limits}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=4s7rR55ePz},
}
Figure