Manuscript Offprint
arXiv:2611.09759A Tight Hierarchy for Chain of Thought
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
Chain-of-thought (CoT) reasoning has emerged as a powerful paradigm for extending the computational capabilities of transformer-based models. A growing body of recent work has begun to uncover the fine-grained computational power of transformers augmented with CoT, as well as their connections to classical complexity theory.
In this work, we advance this line of research by establishing the first hierarchy theorem for CoT-based computation. Our main result shows that for any reasonable resource bound and any ,
where denotes the class of decision problems solvable by transformers using CoT reasoning steps on inputs of length . Our result shows that increasing the number of CoT reasoning steps provably yields strictly greater computational power, establishing CoT steps as a fundamental resource in transformer-based computation.
Unlike classical hierarchy theorems, which are typically proved via diagonalization, our approach leverages known coarse-grained simulations between CoT-augmented transformers and Turing machines in both directions. Building on these connections, we adapt the classical padding technique from complexity theory to this setting to obtain a tight hierarchy. A key technical contribution of our work is the implementation of padding within the transformer-based CoT model.
1 Introduction
A central objective in computing foundations is to understand how computational power scales with access to additional resources. The classical hierarchy theorems from computational complexity theory establish that increased time or space yields strictly greater computational capability. The two most fundamental results in this regard are the Time Hierarchy Theorem and the Space Hierarchy Theorem. Intuitively, the Time Hierarchy Theorem states that if is a sufficiently nice complexity-bounding function (i.e., time-constructible function), then there are problems solvable in time slightly more than that cannot be solved in time . In particular, the most well-known version of this principle states that if [HS65]. Here is the class of languages that are decidable in time on inputs of length using a multi-tape Turing machine. Hierarchy theorems formalize a basic structural principle: bounded resources induce strict stratifications of computational
A version of this paper will appear at NeurIPS 2026.
power. Even though hierarchy theorems are intuitive, it is far from trivial to establish such quantitative results. Without such results, we cannot rule out the possibility of universal thresholds on resources that are required to solve any decidable problem.
Modern AI architectures, particularly transformer architectures, have introduced new models of computation that are both practically powerful and theoretically intriguing. Transformers, built on mechanisms such as self-attention and layered representations, have achieved remarkable success across domains including natural language processing, vision, and scientific computing. The success of transformer architectures led to a new line of research to understand their computational power. Recent research formulated this question by modeling transformers as a computation device, thus enabling rigorous study of the power and limitations of this new model.
A growing body of work has identified fundamental limitations of standard transformer architectures [Hah20; CCP23; Liu+23; HAF22; MSS22; MS23a; MS23b]. In particular, under realistic assumptions, constant-depth transformers are less powerful than finite state machines, arguably the simplest computational model. A recent survey [Str+24] gives an excellent account of the expressive power of transformers as a computational device. The intuitive reason is that constant-depth transformers operate in a largely feedforward manner and lack the ability to perform the iterative computation required for multi-step reasoning. As a result, even tasks that are conceptually simple but require sequential composition of intermediate steps fall outside their effective computational capabilities [PNP24; Dzi+23; Zha+24].
Modern AI systems are augmented with interactive reasoning steps where the output of a step can be used to further the computation. This is known as chain-of-thought (CoT) reasoning. Chain of thought (CoT) refers to a mode of computation in which a model produces explicit intermediate steps before arriving at a final answer. Instead of mapping an input directly to an output in one pass, the model generates a sequence of reasoning states that progressively transform the input into the solution.
From a computational perspective, this modification significantly alters the computational landscape. A growing body of work shows that the number of such intermediate reasoning steps plays a crucial role in determining expressivity. Thus, chain of thought emerges not merely as a heuristic for improving empirical performance, but as a fundamental computational resource in transformer-based models. In particular, Perez et al. show that this model is Turing complete in the sense that anything that is computable using a Turing machine is computable by transformers with enough CoT steps [PBM21]. This connection is made more explicit by Merrill and Sabharwal [MS23a]. In particular, they showed that any language recognized by -time bounded Turing machine can also be recognized via a transformer with CoT steps and any transformer with CoT steps can be simulated by a Turing machine in time .
In this work, we propose to view the number of CoT steps as a resource (such as time and space in TM model) and ask the fundamental question:
Is there a strict hierarchy for CoT reasoning?
Let be the class of problems that can be decided by transformers with chain-of-thought steps. Our main result is that for any reasonable function , and for any ,
Our result shows that chain-of-thought reasoning admits a fine-grained hierarchy: a small increase in the number of reasoning steps strictly increases computational power. This establishes CoT as a meaningful computational resource similar to time and space.
A classical technique underlying hierarchy theorems is diagonalization. In the setting of Turing machines, diagonalization constructs a language that disagrees with every Turing machine running within a given resource bound, by simulating each such machine on carefully chosen inputs and flipping its output. This approach relies on two key properties: (i) machines can be effectively enumerated, and (ii) there exists a universal machine that can take the description of another machine as input and simulate its execution with controlled overhead. These properties make it possible in the Turing machine model to carry out self-referential constructions in a clean and uniform way.
For transformers with chain of thought, the situation appears to be different. While one can, in principle, encode a transformer as a finite object (e.g., via its architecture and parameters), there is no conceptually clean notion of what it means for a transformer to take another transformer as input and simulate its computation. Transformer computation is specified by a fixed architecture, layers, attention heads, and learned weights—rather than a discrete, easily interpretable transition function. As a result, even defining a “universal transformer” that can parse such an encoding and simulate another transformer’s behavior in a step-by-step manner is conceptually unclear. This lack of a natural encoding-and-simulation approach makes it difficult to carry out the kind of self-referential constructions that diagonalization relies on.
This chain of containments implies that : if not, , contradicting the Time Hierarchy Theorem. However, this approach only gives us a very coarse hierarchy theorem. In particular, it will not separate from , let alone separate from . A way to obtain such separation is via a very efficient simulation of transformers by a Turing machine, such as . However, each decoding step of a transformer attends to all preceding tokens. This incurs a quadratic cost to simulate via Turing machines.
To obtain sharper results, we use the padding technique from complexity theory. The padding technique enables the transformation of coarse separations into finer-grained separations. By adapting padding to the transformer model, we are able to derive a tighter separation: . The main technical challenge lies in adapting the padding technique to the transformer setting, where inputs and intermediate representations must be encoded within the constraints of the model. This is our primary technical contribution.
1.2 Related Work
In addition to the works discussed in the introduction on the expressive power of transformers with chain-of-thought reasoning, we briefly review classical hierarchy theorems from complexity theory. The time hierarchy theorem was established in the seminal work of Hartmanis and Stearns [HS65]. This was followed by the space hierarchy theorem in [SHI65]. These results were subsequently extended to nondeterministic computation. The nondeterministic time hierarchy theorem [Coo73; SFM78] shows that , for suitably larger , while a corresponding nondeterministic space hierarchy theorem was established by Ibarra [Iba67]. Establishing hierarchy theorems is still an active area of research in complexity theory, for example for randomized computations there has been only partial progress [Bar02; FS04; FST05].
Recent works have studied transformers as formal computational models, relating their expressive power to automata, circuit complexity, and classical complexity classes. The work of [PBM21] showed that transformers with hard attention and arbitrary precision are Turing complete. Subsequent work focused on understanding the power of transformer variants under bounded precision and architectural restrictions. The work of [Hah20] showed that constant-depth transformers cannot recognize several basic formal languages, including PARITY and Dyck languages. The work of [HAF22] proved hard-attention transformers can be simulated by constant depth circuits (belonging to the complexity class ). In [MSS22], this result has been extended to saturated attention transformers by providing an upper bound of . Other works further explored limitations arising from bounded depth, restricted attention, and finite precision [CCP23; Liu+23; MS23b; MS23a; PNP24]. More recently, the role of intermediate decoding and chain-of-thought reasoning has received attention [MS23a; CPW25]. We refer the reader to [Str+24] for a comprehensive survey of this rapidly growing area.
¹They prove a slightly stronger containment, but the stated bound suffices for our purposes.
2 Preliminaries
We consider decoder-only transformers with chain of thought that can generate intermediate tokens between reading the input and generating an answer. Our model mostly follows definitions as in [MS23a]. In the main body of the paper, we describe the main points about the model. We start here with notation that we use throughout the paper.
Let . A function is time-constructible if there is a Turing machine that on every input length of runs for exactly steps and stops. All standard time functions, such as polynomials and exponentials, have this property. We (most of the time) use lowercase letters for tokens in an alphabet ; uppercase letters for strings in . We use lowercase bold letters for vectors; uppercase bold letters for matrices. We work with vectors which can be either a row matrix or a column matrix. Sometimes, we do not specify row or column for conciseness – whether a vector is a row or a column should be clear from context. We write “identity” to be the identity map, i.e. for any vector , identity() = . In terms of matrix, we write for the identity matrix. We write for the zero matrix. We write “_” to mean “some number in ,” and likewise we write to mean “some vector in ”.
We use indicator-notation: if is a proposition, we write
Definition 2.1. Let be a finite alphabet containing a designated accept symbol . For a function , a transformer decides a language in chain-of-thought steps if the following holds.
On input , define a sequence of strings by , where denotes concatenation. Each is called a decoding step. After decoding steps, the output of is the final token of . We say that accepts if this output equals 1. The language decided by is
We define to be the class of all languages that are decided by some transformer using at most decoding steps.
Let denote the class of decision problems decidable in time steps using a multi-tape Turing machine. Let denote . [MS23a] shows the following relations between TIME and CoT.
Theorem 2.2 ([MS23a]). With the definition above, we have that
In particular, [MS23a] assumes the following: log-precision (i.e. for input of length and intermediate decoding steps, precision is ); saturated attention; and multi-layernorm. We make the same assumptions for our constructions, together with a few reasonable additional assumptions. More details on model assumptions are explained in Appendix A, in particular Remark A.6.
A technical note is that we use in our constructions throughout this paper. In fact, we take to be the max possible value (with precision ). More specifically, we can take the precision to be for suitably large , so that the max possible value is much bigger than all other values needed to encode matrix and vector values.
3 A Hierarchy Theorem for CoT
In this section, we state and prove the main results. Proofs in this section require a few primitives for manipulating transformers, which are provided in Appendix B. We start with the following lemma. Note that for padding to work (in general), is a technical requirement. Padding as a technique is not translatable to the sub-linear regime.

Figure 1: Padding argument for Lemma 3.1. Write and , with chosen as in the proof. The transformer simulates on a padded input with essentially the same absolute CoT budget. The assumed class equality yields a transformer with budget . Finally, generates the padding using CoT and simulates . Dashed vertical lines separate supplied input from generated tokens; gray blocks denote padding. Bar lengths are schematic.
Lemma 3.1. Let . Let such that is time-constructible, nondecreasing, unbounded, and . If , then .
Proof of Lemma 3.1. First, we give an outline of how padding works (see Figure 1 for an illustration). Let be a language in . We will show that under the assumption that . Define a “padded” language (for an appropriately chosen function ), where means a string padded with many *'s. Note that and are essentially the same except the input is padded with *'s. Thus, using the transformer for as a black box, we design a transformer for using the same absolute number of CoT steps, i.e. the number of CoT steps of on input is essentially the same as the number of CoT steps of on input . However, as a function of input length, will recognize in CoT steps. Now, by the assumption that , we obtain that is indeed in via a transformer . Since and are essentially the same languages, we can design a new transformer for by padding an input appropriately and simulate on the padded input. This ensures that the new transformer for runs in CoT steps.
While this is the high-level approach, there are several technical challenges to adapt this to the transformer setting. First, to simulate , one technical challenge is that expects an unpadded input over . If we just run as it is on , then since attention of CoT steps are over * tokens as well, this would change the output for in ways that we can't control. Another challenge is to copy the output of a position to a position far apart (where position means the token in the input string) – so that desired calculations can be carried out. To simulate , a technical challenge is when we receive as input, we need to include layers and heads that pads * tokens using CoT steps. The difficulty is to make sure that these layers/heads take effect only in certain steps.
We now give details of the construction. In this proof, we will focus on a polynomial . We will explain how this can be extended to other classes of functions after the proof.
Assume . Let , and let be a transformer that recognizes in CoT steps. Let be the alphabet for .
Define the padded language , where and is a new character (just used for padding). So, the alphabet for is .
As mentioned above, the proof consists of the constructions of the following two transformers.
Transformer : Using transformer , we can construct transformer that recognizes in CoT steps. Then, by our assumption, . Let be the transformer that recognizes in CoT steps.
Transformer : Using transformer , we construct a transformer that recognizes in CoT steps.
3.1 Construction of
Note that for any , we say , , or to refer to position , i.e. step number , that a transformer takes.
We first give a high-level description of our construction: We take as input strings that look like , where . Let and . Let denote the embedding of token , denote the intermediate value after layer , and denote the output at token . Our goal is to design a transformer to check if , i.e. check if and . To check if , we use a mask function to “ignore” tokens in , and run CoT steps as in by attending over tokens in and CoT-generated tokens . Note that the mask function is not necessary in our construction, it just helps with making our proof concise – see Remark 3.2. The challenge is to make equal to so that the first CoT step of is exactly the same as the first CoT step of . To check if , we just need a single decoding step.
Let the parameters of be: alphabet: ; embedding dimension: ; number of layers: ; number of heads per layer: ; output function: affine linear transformation .
We construct with parameters: alphabet: ; input string: , where , ; embedding dimension: . The embedding dimensions are (note that more details will be provided later in the proof):
-
All WE and PE used for remain the same. Say they occupy dimension numbers 1 to of our vectors. When simulating , acts on these dimensions only.
-
1 dimension for saving is , WLOG, say dimension number .
-
5 dimensions for additional PE: , .
-
Dimensions that serve as placeholders. They are:
-
1 dimension for saving if , say dimension .
-
1 dimension for saving , say dimension .
-
dimensions for saving the copied .
-
Other placeholder dimensions.
Word embedding (WE): We define WE for by using the exact same WE as for , except for adding a new dimension (dimension number ) which is 1 iff character is * (and 0 otherwise). That is, WE(*) is 1 at dimension , and 0 elsewhere.
Positional encoding (PE): In addition to PE of , we also use a supplementary PE (so that in case changes the values of its original PE via calculations, we still have additional PE values to use). For input length , we define the supplement PE to be . Note that . We just write the 5 dimensions that matter (the rest are understood to be all 0's). We save supplement PE in 5 unique dimensions in embedding vectors (i.e. 's).
Heads and layers: has layers, each layer has H heads.
- Layers 1 to L: exactly the same as the layers of T. Note that each head in these layers acts on dimensions 1 to d (i.e. the dimensions that shares with T) only.
• Layers to : additional layers, to be described.
Multi-layernorms: put multi-layernorms only where T has.
Attention mask function: we use causal mask; the only difference is that
Note again that this tailored attention mask is avoidable (see Remark 3.2). That is, causal mask suffices; the use of the tailored mask is just for conciseness.
Output function: , where are affine linear transformations . Since composition of affine linear transformations is an affine linear transformation, we have that is an affine linear transformation.
How runs:
• For to : Run exactly as T would run.
Now, we denote the vector at position after layer (i.e. the last layer) of be . Note that we have (since runs exactly as for its first layers).
Note that has dimension , while has dimension . When we write , it actually means that “at the dimensions that shares with , we have .”
• For to : It does not matter what does here.
• For : Copy the first dimensions of to this position. Also check if .
First, we add a layer (layer L+1) with no head, so as to use its feedforward network to calculate and (as in Lemma B.1). Note that layer needs to share the number of heads with other layers, but we can just make all heads “silent.”
Note that for each 1 function, we need 3 placeholder dimensions and 1 dimension. In total, we need 8 dimensions.
To copy to position , we do the following.
– We add a layer (layer ). This layer has a head (head 1). For query i and key j, choose and such that
where and are calculated from layer ; 1 can be easily obtained by adding a 1 in a designated dimension in any layer before .
We just use 2 additional dimensions, one to line up 1 for and for , and the other to line up for and for .
Note that when average hardmax is applied:
We design such that copies dimensions 1 to of to some placeholder dimensions of .
We need d placeholder dimensions here.
- Then, at output function , before applying , we perform a linear transformation to switch the placeholder dimensions above to dimension 1 to using the linear transformation . Note that only at do changes appear: is now “copied” to position of , and we obtain . This makes in equal to in , as desired.
To check if , we need 3 additional layers (layers , , ). Say we want to save this in dimension number .
– Design the following head (head 1 of layer ). Attend to all positions where character is *. Make query to be just m (or any positive constant available), and make keys to be
(by simply taking the value at the dimension ). Make values to be all . We have the following cases:
-
If , then attention weights are exactly at positions and 0 elsewhere. Therefore, attention (Att) is (as values are 0 except for being 1 at position ).
-
If among , some are and the others are not, then Att is either 0 or (where ).
-
If among , none are , then we have uniform attention over all positions . So, Att is .
- Now, we just need to check if , where is given from PE. By Lemma B.5, we use the feedforward network of layer and layer to get , as desired. Say the result is saved in dimension .
Note that we need 3 additional dimensions to use the construction in Lemma B.5.
-
Last, we use a layer (layer ) to implement the feedforward network as in Lemma B.7, whose effect is to copy the results in dimension to dimension iff . Note that we need 3 additional dimensions for this.
-
CoT steps: Run exactly as if would run (on the dimensions that acts on, ignoring other dimensions). Attention mask makes each CoT step attend to only to and other CoT steps (i.e. , , ..., which are equivalent to , , ..., of , respectively). Let the transformer run CoT steps (as does).
-
Last, we output True (i.e. is indeed in ) if the following are correct:
-
The result of (equivalently ) on says that is in .
This concludes our construction for .
We obtain that can be recognized in CoT steps by the transformer . As is of polynomial order and , we have
As we consider the input of is of length , we obtain that , as desired.
Remark 3.2. We can simulate the effects of the attention mask for , as detailed below.
• Prepend five first layers of the transformer to do the following:
-
Layers 1, 2: Calculate by Corollary B.3.
-
Layers 3, 4: Calculate by Corollary B.3.
-
Layer 5: Use feedforward network to multiply to to get .
• Next, for every layer of that does not involve multi-layernorm, use the exact same heads as for the original with the only difference that for every head, for any query i and key j, embed the query and key such that:
where is the value in the original .
So, when and , we have , meaning query will not attend to key . Otherwise, , so attention is calculated as normal.
- On the other hand, for every layer of that involves multi-layernorm, multi-layernorm will alter the values and , which is not what we want.
To solve this, say is the current vector, and wants to perform multi-layernorm on the vector only. Denote . We can add a layer just to perform multi-layernorm on (by making a head such that value at is , key at is , and query is - this head gives as attention). We save into placeholder dimensions. So, after this layer, we yield .
Next we add a layer on what would have performed on . The difference is that now we already have , so no need to do multi-layernorm anymore (therefore, the numbers and are intact). We just need to use the numbers and to reproduce the mask and perform calculations just on (like in the bullet point above).
Thus, we have obtained the desired mask effect.
3.2 Construction of
We have shown that . By the assumption that , we obtain . Let be the transformer that recognizes in CoT steps. We will use to construct a transformer that recognizes in CoT steps.
On a high level, we design as follows. gets as input. On , we want to simulate . To do that, for (i.e. at positions ), we generate letters * (i.e. we are trying to reconstruct ). Then, on , we simulate (as if we are in the on ).
Let the parameters of be: embedding dimension: ; number of layers: ; number of heads per layer: ; output function: .
We now describe the parameters of :
Input (after embedding as for ): , where .
Positional encoding: as noted in Remark A.6:
-
For , save to encode position. Also, use fixed numbers in PE. So,
-
For CoT steps: at where , PE is updated to .
Embedding dimension: , namely
- for (matching with ). WLOG, suppose:
-
acts on dimension 1 to .
-
Dimension is to save .
-
Some 3 dimensions for positional encoding.
-
additional dimensions (WLOG, dimensions to ). In particular:
- Dimensions to is for saving (this will be explained below).
Number of layers and heads: layers, heads in each layer.
- The first layers of match with (these layers act only on dimensions that has effects on (i.e. dimensions 1 to )).
Attention masks: standard causal mask.
Output function: , where is an affine linear transformation.
Descriptions and justifications of :
-
For : Run exactly as .
-
For (i.e CoT steps 1 to ):
-
Run calculations exactly as for .
-
Also, we need to simulate paddings here: for (), we want the output of position to be * (i.e. has WE for *: 0 from dimensions 1 to , and 1 at dimension ).
-
First, we use 2 layers (layers and ) to compute as in Corollary B.3. We save in a designated dimension. Also, we save at the dimension to indicate * (i.e. dimension ).
-
Let represent the vector that we obtain for query after layer , restricted on dimensions 1 through . The idea is that we would want to make if , and intact otherwise. We proceed as follows.
Use a previous feedforward network (say, of layer ) to save v in some separate d-1 placeholder dimensions, say, WLOG, dimensions to 2d-1.
Next, use a layer to calculate (on dimensions to ) - this can be done by Lemma B.9.
Last, in the output function, calculate (on dimensions 1 to ). Note that this returns if , and if , as desired.
- Thus, the effect is that , for all .
Note that in total, we need additional dimensions.
• For later steps: for (and after): just run . For instance, at , it is exactly as if runs on the input . Subsequently, step of is exactly the same as CoT step number of .
Therefore, R will be able to accept or reject correctly in
CoT steps. The construction of R is completed.
Now, with , we obtain that . In particular, we obtain .
Thus, we can conclude that .
This completes the proof of Lemma 3.1.
Remark 3.3 (Extending to time-constructible functions). Fix , and suppose that is nondecreasing and unbounded, with and
The proof above will go through if we pad the input to for some function , such that .
Write
and choose a rational constant satisfying . Such a choice exists because
Define
Unboundedness of ensures that exists, and is a nonnegative integer. For all sufficiently large , we have , so , and minimality gives
Furthermore, the assumed growth condition and imply that
for all sufficiently large k. Applying this with , we obtain
Thus padding to satisfies the required growth inequalities for all sufficiently large input lengths.
3.3 Proof of Main Theorem
Equipped with Lemma 3.1, we are ready to prove our main theorem.
Theorem 3.4. For and such that is time-constructible, nondecreasing, unbounded, and , we have .
Proof. Let be arbitrary. Suppose, for the sake of contradiction, that .
By Theorem 2.2, we have
By Time Hierarchy Theorem, . Thus, from the chain of containment, .
Now, note that by assumption. Then, by Lemma 3.1, we obtain that . Now, applying the lemma again, we get that . After applications, we get . By choosing , we get that , contradiction.
Thus, we can conclude now that .
4 Conclusions and Open Problems
We established a hierarchy theorem for chain-of-thought reasoning, identifying the number of decoding steps as a fundamental computational resource. Our results raise an important open question of obtaining a hierarchy theorem that is as tight as classical time and space hierarchies in the Turing machine model. In particular, can we show that
Our proof relies on simulations of transformers with Turing machines combined with padding. The known simulations incur quadratic blow-up, and it is unclear whether near-linear time simulations of are possible. In particular, can we show
Moreover, due to the use of the padding technique, we only get Theorem 3.4 for . The case is an open question for saturated-attention transformers. We expect a positive answer.
Finally, the full computational power of chain-of-thought reasoning is not yet well understood and is a promising research theme.
Acknowledgments and Disclosure of Funding
N. V. Vinodchandran and Thanh Le were supported in part by NSF awards 2342244, 2413848, and a UNL Grand Challenges Grant. A. Pavan was supported in part by NSF awards 2342245 and 2413849.
References
[Bar02] Boaz Barak. "A Probabilistic-Time Hierarchy Theorem for "Slightly Non-uniform" Algorithms". In: Randomization and Approximation Techniques, 6th International Workshop, RANDOM 2002, Cambridge, MA, USA, September 13-15, 2002, Proceedings. Ed. by José D. P. Rolim and Salil P. Vadhan. Lecture Notes in Computer Science. Springer, 2002, pp. 194–208. DOI: 10.1007/3-540-45726-7\16. URL: https://doi.org/10.1007/3-540-45726-7%5C_16.
[CC22] David Chiang and Peter Cholak. "Overcoming a theoretical limitation of self-attention". In: Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers). 2022, pp. 7654–7664.
[CCP23] David Chiang, Peter Cholak, and Anand Pillay. "Tighter Bounds on the Expressivity of Transformer Encoders". In: Proceedings of the 40th International Conference on Machine Learning (ICML). Vol. 202. Proceedings of Machine Learning Research. PMLR, 2023, pp. 5544–5560. URL: https://proceedings.mlr.press/v202/chiang23a.html.
[Coo73] Stephen A. Cook. "A Hierarchy for Nondeterministic Time Complexity". In: Journal of Computer and System Sciences 7.4 (1973), pp. 343–353.
[CPW25] Lijie Chen, Binghui Peng, and Hongxun Wu. "Theoretical limitations of multi-layer Transformer". In: 66th IEEE Annual Symposium on Foundations of Computer Science, FOCS 2025, Sydney, Australia, December 14-17, 2025. IEEE, 2025, pp. 2631–2653. DOI: 10.1109/FOCS63196.2025.00136. URL: https://doi.org/10.1109/FOCS63196.2025.00136.
[Dzi+23] Nouha Dziri et al. "Faith and Fate: Limits of Transformers on Compositionality". In: Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023. Ed. by Alice Oh et al. 2023. URL: http://papers.nips.cc/paper%5C_files/paper/2023/hash/deb3c28192f979302c157cb653c15e90-Abstract-Conference.html.
[FS04] Lance Fortnow and Rahul Santhanam. "Hierarchy Theorems for Probabilistic Polynomial Time". In: 45th Symposium on Foundations of Computer Science, FOCS 2004, Rome, Italy, October 17-19, 2004, Proceedings. IEEE Computer Society, 2004, pp. 316–324. DOI: 10.1109/FOCS.2004.33. URL: https://doi.org/10.1109/FOCS.2004.33.
[FST05] Lance Fortnow, Rahul Santhanam, and Luca Trevisan. "Hierarchies for semantic classes". In: Proceedings of the 37th Annual ACM Symposium on Theory of Computing, Baltimore, MD, USA, May 22-24, 2005. Ed. by Harold N. Gabow and Ronald Fagin. ACM, 2005, pp. 348–355.
[HAF22] Sophie Hao, Dana Angluin, and Roberta Frank. "Formal Language Recognition by Hard Attention Transformers: Perspectives from Circuit Complexity". In: Transactions of the Association for Computational Linguistics 10 (2022), pp. 800–810.
[Hah20] Michael Hahn. "Theoretical Limitations of Self-Attention in Neural Sequence Models". In: Transactions of the Association for Computational Linguistics 8 (2020), pp. 156–171.
[HS65] Juris Hartmanis and Richard E. Stearns. "On the Computational Complexity of Algorithms". In: Transactions of the American Mathematical Society 117 (1965), pp. 285–306.
[Iba67] Oscar H. Ibarra. "A Note on Nondeterministic Tape Complexities". In: Journal of the ACM 14.2 (1967), pp. 341–343.
[Liu+23] Bingbin Liu et al. "Transformers Learn Shortcuts to Automata". In: International Conference on Learning Representations (ICLR). 2023. URL: https://openreview.net/forum?id=De4FYqjFueZ.
[MS23a] William Merrill and Ashish Sabharwal. "The expressive power of transformers with chain of thought". In: arXiv preprint arXiv:2310.07923 (2023).
[MS23b] William Merrill and Ashish Sabharwal. "The Parallelism Tradeoff: Limitations of Log-Precision Transformers". In: Transactions of the Association for Computational Linguistics 11 (2023), pp. 531–545.
[MSS22] William Merrill, Ashish Sabharwal, and Noah A. Smith. "Saturated Transformers are Constant-Depth Threshold Circuits". In: Transactions of the Association for Computational Linguistics 10 (2022), pp. 843–856.
[PBM21] Jorge Pérez, Pablo Barceló, and Javier Marinkovic. "Attention is turing-complete". In: Journal of Machine Learning Research 22.75 (2021), pp. 1–35.
[PNP24] Binghui Peng, Srini Narayanan, and Christos H. Papadimitriou. "On Limitations of the Transformer Architecture". In: Proceedings of the 1st Conference on Language Modeling (COLM). 2024. URL: https://openreview.net/forum?id=KidynPuLW.
[SFM78] Joel I. Seiferas, Michael J. Fischer, and Albert R. Meyer. "Separating Nondeterministic Time Complexity Classes". In: J. ACM 25.1 (Jan. 1978), pp. 146–167. ISSN: 0004-5411. DOI: 10.1145/322047.322061. URL: https://doi.org/10.1145/322047.322061.
[SHI65] Richard E. Stearns, Juris Hartmanis, and Philip M. Lewis II. "Hierarchies of Memory-Limited Computations". In: Proceedings of the Sixth Annual IEEE Symposium on Switching Circuit Theory and Logical Design (SWCT) (1965), pp. 179–190.
[Str+24] Lena Strobl et al. "What Formal Languages Can Transformers Express? A Survey". In: Transactions of the Association for Computational Linguistics 12 (2024), pp. 543–561. ISSN: 2307-387X. DOI: 10.1162/tac1_a_00663. URL: http://dx.doi.org/10.1162/tac1_a_00663.
[Swi+23] Pawel Swietojanski et al. "Variable Attention Masking for Configurable Transformer Transducer Speech Recognition". In: ICASSP 2023 - 2023 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP). 2023, pp. 1–5. DOI: 10.1109/ICASSP49357.2023.10094588.
[Zha+24] Muru Zhang et al. "How Language Model Hallucinations Can Snowball". In: Forty-first International Conference on Machine Learning, ICML 2024, Vienna, Austria, July 21-27, 2024. Ed. by Ruslan Salakhutdinov et al. Proceedings of Machine Learning Research. PMLR / OpenReview.net, 2024, pp. 59670–59684. URL: https://proceedings.mlr.press/v235/zhang24ay.html.
A Transformer Definition
A transformer is a neural network and a function . In this paper, we work with decoder-only transformer. We define the model and its components below. We then explain assumptions for our constructions.
Definition A.1. A decoder-only transformer with heads, layers, model dimension consists of the following components:
- Embedding function:
where for , , input length , we define:
WE, are a word embedding function and a positional encoding function, respectively, where
In particular, positional encoding is dependent on the length of the input string (see [Str+24] for remarks on this).
- Attention heads: For each layer and head :
- Activation block (feedforward + skip-connection): For each layer ,
- Output function:
Definition A.2. Given an input sequence . We define one decoding step of a decoder-only transformer as follows.
- Embeddings:
- Multihead Self-attention: For each layer and each position , we compute attention heads. For head , we compute:
where is i for causal attention.
We define and as follows (note that we drop for conciseness). has two affine linear transformations parametrized by (for queries) and (for keys) as parameters. Likewise, has one affine linear transformation (for values) as parameter.
where , where is either a multi-layernorm (defined below) or an identity function,
and mask is the attention masking function (defined below).
Attention mask function, denoted mask : , decides whether keys get attended to or not. mask takes a query and a key as inputs and returns if the key is forbidden from the query. mask returns 0 otherwise. For instance, attention mask function for (standard) causal masking is:
Different mask functions are studied (for example, see [Swi+23]).
3. Activation block:
The activation function first aggregates attention heads' outputs, and then feeds the results through a feedforward network (with skip-connection).
For each position , takes as input attention heads' outputs and the previous layer value .
First f sums up outputs for heads, yielding
is then passed through a linear transformation, and then a two layer feedforward (FFW) network (with a multi-layernorm (or identity), a non-linearity, and skip-connections in between) as follows
Then, we get that .
- Output: The final output at position i is
where is an affine linear transformation from , parametrized by .
Remark A.3. With the definition above, parameters for a decoder-only transformer, denoted , include:
• Embedding dimension (d), number of heads (H), number of layers (L).
• Word embedding function WE and positional encoding functions (for ).
• Attention mask function. Default to be causal mask.
• For each attention head: 3 affine linear transformations , where denotes the linear transformation, and denotes the affine part.
• For each layer: 2 multi-layernorms and (which can be identity); an affine linear transformation ; a 2-layer FFW network (parametrized by and ).
• For output function: an affine linear transformation .
Remark A.4. For saturated attention (also known as average-hard attention), we modify multihead self-attention as follows
where . We define hardmax to take as input a vector of real numbers, and return a probability distribution (of the same dimension) whose weights are equally distributed between the maximum positions, and 0 elsewhere.
Based on current theoretical results, saturated attention appears to be computationally equivalent to softmax attention, in the sense that no separation between them is known (see Table 1 of [Str+24]). From a practical point of view, trained softmax systems usually exhibit attention concentrated almost equally on a few dominant positions. Thus, the work of [MSS22] argues that average hardmax is a realistic approximation of how Transformers behave in practice. This motivates average hardmax as a reasonable and mathematically simple abstraction of softmax attention.
Definition A.5 (Multi-layernorm, [MS23a]). Layernorm is defined as
where , where computes the mean of vector .
Then, let be a parameter matrix that projects vectors from to . Then projected pre-norm is defined as
If context is clear, we write proj_layer_norm(v).
Next, let be divisible by . For , let be a parameter projection matrix. let denote iterated concatenation. The multi-pre-norm of is defined as
There is a result that says (compositions of) projected pre-norm can simulate multi-pre-norm. We use multi_layer_norm in our transformer model (we denote it by ).
Remark A.6. Our constructions of decoder-only transformers assume the following:
• Positional encoding (PE):
– PE uses the number i to encode position i. In addition, PE may contain other fixed numbers independent of i (such as those dependent on the input length).
– Without loss of generality (WLOG), we assume that our transformers have PE for generated tokens. That is, (for any where is the input length) has as PE. (This can be implemented easily by just using the output function to add 1 to PE (for ). If , then this does not change anything, as the output is not taken to be the next token. If , then that makes the PE for exactly .)
– By Lemma B.11, WLOG, we can use as a positional encoding value for .
• Attention: We use saturated attention.
• Precision: We assume precision as in [MS23a]. That is, for input of length n and intermediate decoding steps, precision is .
• Attention mask: We allow slightly tailored attention mask. That is, we forbid some CoT steps from attending to a certain portion of past CoT steps.
Note that this is to help with writing concise proofs rather than a necessary condition.
• Attention head's dimension: We don't follow the exact definition of attentions in [MS23a], as they consider dimension d/H for each head. But, their model and ours can simulate each other easily.
• Layernorm: We allow the possibility of applying or not applying multi-layernorm.
In particular, Theorem 2.2 still holds under our assumptions.
Remark A.7. Attention mask is not required for our constructions. Yet, we use attention mask to simplify our construction. We explain how to “simulate” attention mask in Remark 3.2.
B Primitives for Manipulating Transformers
In this subsection we list and prove computations that we will perform with transformers in our main proofs. The following lemma is implicit in [CC22]. We write it in a form that we will use. It essentially says that transformers can check equality between integers and a given integer.
Lemma B.1. Let current prefix be , where each , , for . Then, there exists a decoder-only transformer with 1 layer (which has 1 head) that, for any , computes and saves into dimension 6. That is, there exists a decoder-only transformer that returns .
Proof. We design a transformer T as follows:
• Dimension: 6; number of layers: 1; number of heads per layer: 1.
• WE, PE: not applied, since inputs are already given to vector form.
• For layer 1: put ; put and . We specify and below.
• For the head in layer 1: put and . The effect of this is to make head output for all . That means, we do not want this head to have any effects.
• Output function: we put and .
Now, fix a position , with input .
Consider layer 1. The head produces . Since there is only one head . Since we know we talk about layer 1, we can drop the superscript 1, and just write . Then, since and , we yield that . Next, since , we have that .
Now, let
We yield
Now, observe that since , we have
Therefore, we let
We obtain that , as desired.
Remark B.2. Some notes on how we use different components of transformers to build desired properties:
• Placeholder dimensions: we call dimensions 3 to 5 (informally) as placeholder dimensions. Their purpose is to save results of auxiliary calculations.
• Dimensions to save results: dimension 6 is a dimension to save results.
• Effects of 2-layer FFW network: multiply by constants, add constants, perform ReLU, move numbers between dimensions.
• Effects of skip-connection: keep original values. That is, values and t in dimensions 1 and 2 are kept intact in thanks to skip connections.
• For dimensions that we do not want to change, we can make our heads and linear transformations ignore them by ignoring respective rows/columns. Or, we can make values of the dimensions be 0 during calculations, and then recover their original values using skip-connections.
We obtain the following corollary for checking if an integer x is between 2 integers and .
Corollary B.3. Say where and . There exists two nested 2-layer feedforward networks (with ReLU) that compute .
Proof. First, use an affine linear transformation and a ReLU (of the first feedforward network) to compute . Note that iff . Next, use a second feedforward network to compute if .
Remark B.4. We can implement the nested feedforward networks of the above corollary using a transformer with 2 layers and 3 additional dimensions (2 as placeholder dimensions, and 1 as result-saving dimension).
Next, we have the following lemma for checking if , where is given, and . Note that we state our result for feedforward networks, but similar to Lemma B.1, we can transfer feedforward networks to transformers by making attention heads silent and using additional dimensions (to avoid effects of skip-connections).
Lemma B.5. Consider where . Then, there exists two nested 2-layer feedforward networks (with ReLU) that return .
Proof. First, use an affine linear transformation to get and (saved in dimensions 3 and 4). Then, use ReLU to get ReLU and ReLU. Then use an affine linear transformation to get ReLU (saved in dimension 4). Next, the second 2-layer feedforward network, compute ReLU (saved in dimension 5), where is a scalar. We get 1 if , and 0 otherwise.
Remark B.6. We can implement the two nested feedforward networks as in Lemma B.5 by using 2 layers of a transformer, with 2 placeholder dimensions and 1 result-saving dimension.
Next, we have the following lemma from [PBM21]. We generalize so that it works for our case. The lemma essentially says that transformer can do “if” clauses (under some assumptions). We make an assumption that .
Lemma B.7. Let and , and let . There exists a two-layer feedforward network such that
Proof. (Sketch) Let be the vector of dimension whose entries are all 's.
We utilize the 2-layer feedforward network to compute the following:
which equals if and if .
Remark B.8. We can implement the feedforward network in the lemma using additional dimensions (say we use dimensions to save , dimensions to save , and 1 to save ). There can be more optimal usage of dimensions, but we don't need that.
Next, we have a lemma that essentially says transformer can multiply a vector with a number .
Lemma B.9. Let and together in a vector, denoted . Then, there exists a 2-layer feedforward network (with ReLU) that returns .
Proof. First, use the first affine linear transformation to get
Next, after ReLU, we get
Then, we use the second linear transformation to get
Thus, we yield , as desired.
Remark B.10. We have some remarks on the previous lemma:
-
Above, we could have done calculation on the first dimensions, but we will leave them equal to zero, and do calculations in some placeholder dimensions. The reason is that when we use feedforward network in a transformer, after all calculations, the transformer performs a skip-connection to add the original vector into the resulting vector. In our case, the first dimensions will be added by in the end, and that may alter the results we want. Thus, we perform calculations in placeholder dimensions, which are unaltered by skip-connections.
-
So, to multiply by , we have used 2d-placeholder dimensions ( of which are used to save the results, too).
Next, we have a lemma that says if each has as positional encoding, then for , we can calculate number (using a transformer).
Lemma B.11. Let such that . Then, there exists a transformer with 2 layers that returns .
Proof. Let us just write in terms of 3 dimensions for conciseness. Let's be understood we may need to use more than 3 dimensions for the purpose of place-holding. Say we are considering query .
First, by Lemma B.1, we use a layer (layer 1) to get . Next, use a head in layer 2 to attend uniformly over all tokens (with causal mask) with value . From this, we get as the result, hence obtaining .
Remark B.12. By Lemma B.11, if we have as a positional encoding for , we can easily obtain for . Thus, WLOG, we can assume as a number given from positional encoding, too.