Compositional Reasoning with Transformers, RNNs, and Chain of Thought

Gilad Yehudai, Noah Amsel, Joan Bruna

Abstract

As Large Language Models (LLMs) are increasingly deployed for complex algorithmic tasks, understanding the fundamental computational limits of different architectures is essential. This paper introduces Compositional Reasoning Questions (CRQs), a formal framework of tree-structured tasks, to analyze the trade-offs between Transformers, Recurrent Neural Networks (RNNs), and Chain of Thought (CoT) prompting. Through circuit complexity theory and constructive proofs, we demonstrate that no single architecture serves as a universal solution. Instead, each architecture optimizes for a different resource: Transformers for parallel runtime, RNNs for parameter efficiency (given optimal input ordering), and CoT for model depth at the cost of sequential token generation.

Introduction

The rapid advancement of LLMs has sparked a debate regarding the inherent strengths and weaknesses of various neural architectures. While Transformers have become the industry standard due to their parallelizability, RNNs remain relevant for their sequential efficiency, and CoT prompting has emerged as a powerful technique for enhancing reasoning. However, a rigorous theoretical comparison of these paradigms has been lacking.

This research addresses this gap by defining Compositional Reasoning Questions (CRQs). A CRQ can be visualized as a hierarchical "to-do list" or a complex mathematical expression, such as $5 \cdot (8 - (9 \div (2 - 1)))$. Solving these problems requires evaluating sub-problems in a specific recursive order. By analyzing CRQs, we can determine the specific resources—depth for Transformers, memory for RNNs, or tokens for CoT—required by each architecture to solve inherently hierarchical problems.

The CRQ Framework and Complexity

CRQs are defined as rooted trees where each node represents a vector. The value of a parent node is computed recursively based on its children, typically using an argmax of inner products. This framework is robust enough to encompass Boolean formula evaluation (logic gates like AND, OR, and NOT) as a special case.

The authors prove that CRQs are $NC^1$-hard, a complexity class that includes Boolean formula evaluation. This classification implies that CRQs are "inherently deep" and cannot be solved by shallow, purely parallel circuits. This theoretical foundation allows for a precise mapping of architectural requirements to task complexity.

Architectural Trade-offs in Reasoning

1. Transformers: The Depth-Parallelism Constraint

Transformers excel at parallel processing, but this parallelism is a limitation when faced with hierarchical reasoning. The study demonstrates that for a tree of depth $L$, a Transformer must possess at least $O(L)$ layers to solve the problem. Specifically, a Transformer with $O(\log n)$ depth and $O(\log n)$ precision is sufficient to solve CRQs on $n$ nodes. Under standard complexity assumptions (such as $TC^0 \neq NC^1$), constant-depth Transformers are fundamentally incapable of solving CRQs, regardless of their width.

2. RNNs: The Critical Role of Input Order

RNNs are sequential models that maintain a hidden state, making them potentially memory-efficient. However, their performance is hypersensitive to the order in which data is presented. The authors introduce Memory-Rank Sort (Algorithm 1), a specific method for ordering tree nodes.

Without optimal ordering, an RNN may require a massive hidden state of $O(n)$ to retain necessary information. Conversely, if the inputs are ordered via Memory-Rank Sort, an RNN with only 5 layers and a logarithmic hidden dimension ($O(\log n)$) can solve any binary-tree CRQ. This highlights that for RNNs, architectural efficiency is inextricably linked to data preprocessing.

3. Chain of Thought: Trading Time for Depth

Chain of Thought (CoT) prompting functions as a form of "test-time scaling." It allows a shallow model to simulate the reasoning process of a much deeper one by generating intermediate "scratchpad" tokens. The paper proves that a 2-layer Transformer can solve any CRQ by generating $n$ CoT tokens. This is significantly more efficient than previous theoretical bounds, which suggested $O(n^2)$ tokens were necessary for similar logic tasks. CoT effectively trades sequential runtime (more tokens) for a reduction in model depth.

Comparative Summary

Each model minimizes a different computational resource, as summarized below:

  • Transformers: Minimize parallel runtime but require significant depth for hierarchical tasks.
  • RNNs: Minimize total parameters and memory, provided the input sequence is optimized via Memory-Rank Sort.
  • CoT: Minimizes model size (allowing for very shallow models) at the expense of the longest sequential runtime.

Conclusion and Future Work

This research provides a rigorous theoretical framework for understanding how different AI architectures approach logic. While it proves the expressivity of these models—showing they can represent solutions—it does not address whether standard training techniques like Gradient Descent will successfully find these solutions.

Furthermore, the current study focuses on tree-structured reasoning. Future research is needed to determine if these trade-offs persist in more complex scenarios, such as graph-based reasoning or "loopy" logic, and to bridge the gap between theoretical "hardmax" constructions and the "softmax" attention used in practical, noisy environments.

Summary updated

BibTeX
@inproceedings{yehudai2025compositional,
  author = {Gilad Yehudai and Noah Amsel and Joan Bruna},
  title = {{Compositional Reasoning with Transformers, RNNs, and Chain of Thought}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=nUZaI7aRb2},
}
Figure