Towards Revealing the Mystery behind Chain of Thought: A Theoretical Perspective

Guhao Feng, Bohang Zhang, Yuntian Gu, Haotian Ye, Di He, Liwei Wang

Introduction

The emergence of "Chain of Thought" (CoT) prompting—where Large Language Models (LLMs) are encouraged to "think step by step"—has significantly enhanced their reasoning capabilities. Despite its empirical success, a fundamental question remains: Why does generating intermediate steps help a model solve problems that it cannot solve directly? This paper provides a theoretical foundation for CoT, arguing that it effectively increases the computational depth of a Transformer architecture.

The Computational Limits of Direct Prediction

The researchers frame the problem through the lens of circuit complexity theory. They investigate the gap between "direct prediction" (mapping input to answer in a single forward pass) and "autoregressive CoT" (generating a sequence of intermediate derivations).

In computational terms, a bounded-depth Transformer with log-precision belongs to the complexity class $TC^0$. Many fundamental reasoning tasks, such as multi-step arithmetic or solving linear equations, belong to the class $NC^1$ or higher. Theoretically, problems in $NC^1$ cannot be solved by $TC^0$ circuits unless the circuit size grows super-polynomially. In practical terms, this means a standard Transformer of fixed depth is mathematically incapable of solving complex logic problems in one shot, regardless of its parameter count, as the problem scale increases.

CoT as "Effective Depth"

The core insight of the paper is that autoregressive generation allows a shallow Transformer to emulate a much deeper one. Each time a model generates a token and appends it to the context for the next step, it essentially adds another "layer" of computation. A 3-layer model generating 100 intermediate tokens functions, in some sense, like a 300-layer model.

By serializing computation, CoT allows the model to break down $NC^1$ problems into a series of $TC^0$ steps. The authors prove this by construction, mathematically designing a constant-size Transformer capable of solving arithmetic and dynamic programming (DP) problems by iterating through logical steps. This demonstrates that the architecture is inherently capable of complex logic, provided it is allowed to iterate.

Experimental Evidence

To validate their theory, the authors tested Transformers on four synthetic reasoning tasks designed to challenge specific computational boundaries:

  • Arithmetic: Evaluating expressions with nested operations (e.g., (7+5) / (6+4*3-2*7)).
  • Linear Equations: Solving systems of $m$ equations with $m$ variables using Gaussian elimination.
  • Longest Increasing Subsequence (LIS): A classic DP problem finding the longest ordered sequence within an array.
  • Edit Distance (ED): Measuring the minimum operations to transform one string into another.

For each task, they compared a Direct dataset (input $\rightarrow$ answer) against a CoT dataset (input $\rightarrow$ intermediate steps $\rightarrow$ answer).

Key Results

  • Performance Gap: 3-layer Transformers trained with CoT achieved near-perfect accuracy (~100%) across all tasks. In contrast, models trained for direct prediction failed as complexity increased, often dropping below 60% accuracy even when the number of layers was increased.
  • Generalization: Models trained on CoT for arithmetic expressions with up to 15 operators successfully generalized to 18 operators. This suggests that the models learned the underlying algorithmic rules rather than simple pattern memorization.
  • Transformers as Programmable Units: The study demonstrates that attention heads and Feed-Forward Networks (FFNs) can be configured to perform basic operations like COPY, MEAN, and lookup. CoT allows the model to loop these "instructions," effectively acting as a programmable computer.

Conclusion and Future Directions

This research moves beyond the intuition that CoT simply "gives the model more time to think." It provides a rigorous proof that CoT is a mathematical necessity for solving certain classes of problems within the Transformer architecture. While this explains the expressive power of CoT, it leaves open the question of optimization: how do specific prompts like "Let's think step by step" actually trigger these latent capabilities? Future work is needed to bridge the gap between this theoretical potential and the practical training dynamics of LLMs.

Summary updated

BibTeX
@inproceedings{feng2023towards,
  author = {Guhao Feng and Bohang Zhang and Yuntian Gu and Haotian Ye and Di He and Liwei Wang},
  title = {{Towards Revealing the Mystery behind Chain of Thought: A Theoretical Perspective}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=qHrADgAdYu},
}
Figure