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

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

TL;DR

This paper provides a theoretical foundation for why Chain-of-Thought (CoT) prompting works, proving that it fundamentally expands the computational power of Transformers. By generating intermediate steps, a constant-size Transformer can solve complex mathematical and decision-making problems that are mathematically impossible for even much larger models to solve in a single "direct" step.

What Problem Does This Paper Address?

While Chain-of-Thought (CoT) prompting—asking a model to "think step-by-step"—has become a standard way to boost LLM performance, we haven't fully understood why it works. Is it just a quirk of how they were trained, or is there a deeper structural reason?

From a computational perspective, a standard Transformer has a fixed number of layers (depth). This makes it equivalent to a "shallow" parallel circuit. However, many reasoning tasks, like solving equations or dynamic programming, are inherently sequential and difficult to parallelize. The authors set out to prove that CoT isn't just a trick; it is a mechanism that allows a shallow model to act like a very deep one by using the output tokens as a "scratchpad" for recursive computation.

Methods

The authors use circuit complexity theory to map the architecture of Transformers to known classes of computational difficulty.

  1. Impossibility Results: They prove that bounded-depth Transformers (which fall into the complexity class $TC^0$) cannot solve basic arithmetic or linear equations directly unless the model size grows at an impossible, super-polynomial rate.
  2. Constructive Proofs: Conversely, they prove by construction that a constant-size autoregressive Transformer can solve these same problems if it is allowed to generate intermediate CoT steps.
  3. Dynamic Programming (DP) Emulation: They extend this to a general framework for Dynamic Programming, showing that CoT allows LLMs to tackle a massive class of real-world decision-making problems (like finding the longest increasing subsequence or calculating edit distance) that are otherwise too complex for their fixed depth.

Datasets

The authors validated their theory using synthetic datasets for four key tasks:

  • Arithmetic Expressions: Evaluating nested math problems (e.g., (7+5) / (6+4*3-2*7)).
  • Linear Equations: Solving systems of $m$ equations with $m$ variables.
  • Longest Increasing Subsequence (LIS): A classic DP problem.
  • Edit Distance (ED): Measuring the similarity between two strings.

For each task, they created "Direct" datasets (input $\rightarrow$ answer) and "CoT" datasets (input $\rightarrow$ intermediate steps $\rightarrow$ answer).

Figure 1: Illustrations of CoT on two math tasks.

Key Insights and Ideas

  • Effective Depth: The "aha moment" is that CoT turns the Transformer's depth from a constant ($L$) into a variable proportional to the number of generated tokens. Each new token generated is a new "layer" of computation that can attend to all previous steps.
  • Parallel vs. Serial Complexity: The reason LLMs fail at direct math isn't necessarily because the math is "hard" in terms of total operations, but because it has high parallel complexity. You can't solve a deep math expression all at once; you must resolve the inner brackets first. CoT provides the serial structure needed to match the problem's nature.
  • Expressivity vs. Size: A tiny model with CoT is computationally more expressive than a massive model without it.
  • Algorithmic Learning: Experiments showed that models trained with CoT don't just memorize; they learn the underlying algorithm. This was proven by length extrapolation: a model trained on short math problems could still solve significantly longer ones it had never seen before.

Key Results

  • Performance Gap: On all four tasks, 3-layer Transformers using CoT achieved near-perfect accuracy. In contrast, models trained for direct prediction failed miserably as the problem difficulty increased, even when the researchers increased the model's depth.
  • Robustness: CoT models are surprisingly resilient. Even when 30% of the intermediate steps were missing or contained random token corruptions during training, the 3-layer models still achieved over 95% accuracy.
  • DP Power: The paper formalizes how CoT allows Transformers to solve $P$-complete problems (the hardest problems that can be solved in polynomial time), which are generally considered unreachable for standard parallel architectures.
Comparison of DP formulations for LIS and Edit Distance

Limitations and Future Work

  • The "Trigger" Mystery: While this paper explains why CoT is powerful once it happens, it doesn't explain how specific prompts (like "let's think step by step") actually trigger this behavior in pre-trained models.
  • Generalization Theory: The theoretical proofs focus on expressivity (what a model is capable of representing). Future work is needed to provide a formal theory of generalization—why the models actually choose to learn the correct reasoning algorithm rather than just finding statistical shortcuts.
  • Model Size and CoT: Empirical evidence suggests that CoT only "emerges" at certain model scales. The authors note that theoretically understanding the role of model size in unlocking CoT remains an open research problem.

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