The Expressive Power of Transformers with Chain of Thought

William Merrill, Ashish Sabharwal · DOI

Introduction

Standard transformer architectures are fundamentally "shallow" in a computational sense. Due to their lack of internal recurrent connections, they are restricted to the circuit complexity class TC⁰. This limitation prevents them from solving seemingly simple sequential tasks, such as simulating a finite-state machine or determining graph connectivity. In practice, researchers circumvent this by using "Chain of Thought" (CoT) or scratchpads, where the model generates intermediate tokens before producing a final answer. While empirically successful, a rigorous theoretical understanding of how CoT enhances expressivity has been lacking. This paper provides a formal characterization of CoT as a computational resource, mapping the boundaries of what transformers can "think" through as a function of their output length.

Theoretical Framework

The authors establish their results using a "log-precision" decoder-only transformer model. This model possesses sufficient precision to represent sequence positions and perform basic arithmetic but cannot store arbitrary real numbers. To bridge the gap between neural architectures and classical computation, two key mechanisms are introduced:

  1. The Layer-Norm Hash: A novel construction that enables exact-match retrieval of numerical values. By mapping values to specific unit vectors, the model uses attention to "look up" previous states, even when represented by noisy or scaled values.
  2. Turing Machine Simulation: The authors prove lower bounds by demonstrating how a transformer can simulate a multi-tape Turing Machine (TM). Each CoT step corresponds to a single TM step, with the attention mechanism acting as the read/write head over the sequence of previously generated tokens.

The Impact of Step Count

The primary insight of this work is that the "boost" in computational power provided by CoT is not binary but depends strictly on the number of intermediate steps ($t$).

Hierarchy of complexity classes and their relationship to CoT step counts.

As shown in the figure above, the expressivity scales with the length of the chain:

  • Logarithmic CoT ($O(\log n)$): Surprisingly, a logarithmic number of steps provides minimal benefit. The model remains within the class L (Log-space), still unable to solve many sequential reasoning problems.
  • Polynomial CoT ($O(\text{poly}(n))$): This is the "sweet spot" where the model becomes equivalent to the class P. This establishes the first "if and only if" equivalence between a specific transformer configuration and a standard complexity class.

Linear Chain of Thought and Formal Languages

When the number of CoT steps is linear ($O(n)$), the model undergoes a significant jump in capability. It can recognize any regular language and simulate real-time computation.

The relationship between linear CoT, regular languages (Reg), and context-sensitive languages (CSL).

The theoretical bounds for linear CoT are established as: $$\text{Reg} \subset \text{CoT}(n) \subseteq \text{CSL}$$ This indicates that while linear CoT is powerful enough for regular languages, it remains contained within the class of Context-Sensitive Languages (CSL).

Key Results and Complexity Mappings

The paper establishes a fundamental relationship between the number of CoT steps $t(n)$ and classical complexity classes: $$\text{TIME}(t(n)) \subseteq \text{CoT}(t(n)) \subseteq \text{SPACE}(t(n) + \log n)$$

These results rely on architectural assumptions common in transformer theory, such as "saturated attention" (where weights are pushed to extremes) and "projected pre-norm" configurations.

Conclusion and Limitations

This work provides a rigorous foundation for understanding why Chain of Thought works. By treating intermediate tokens as a recurrent state, transformers bypass their inherent shallowness. However, several caveats remain. The proofs focus on expressivity (what a model can represent) rather than learnability (what gradient descent will find). Additionally, the reliance on idealized saturated attention and fixed log-precision suggests that real-world "soft" attention models may have different practical boundaries. Future research is needed to explore the efficiency of these constructions and the impact of varying precision levels.

Summary updated

BibTeX
@inproceedings{merrill2024expressive,
  author = {William Merrill and Ashish Sabharwal},
  title = {{The Expressive Power of Transformers with Chain of Thought}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=NjNGlPh8Wh},
}
Figure