Abstract: The transformer architecture is almost a decade old. Despite that, we still have a limited understanding of what this architecture can or cannot compute. For instance, can a 1-layer transformer solve PARITY -- or more generally -- which kinds of transformers can do it? Known constructions for PARITY have at least 2 layers and employ impractical features: either a length-dependent positional encoding, or hardmax, or layernorm without the regularization parameter, or they are not implementable with causal masking. We give a new construction of a transformer for PARITY with softmax, length-independent and polynomially bounded positional encoding, no layernorm, working both with and without causal masking. We also give the first lower bound for transformers solving PARITY -- by showing that it cannot be done with only one layer and one head.
Introduction
Despite the ubiquity of transformers in modern artificial intelligence, our theoretical understanding of their computational boundaries remains incomplete. We lack a definitive "instruction manual" that outlines the specific functions these architectures can and cannot represent. To probe these limits, researchers often turn to the PARITY function—a classic benchmark in Boolean circuit complexity that determines if a bitstring contains an even or odd number of ones.
PARITY is a particularly challenging task because it is highly "sensitive": flipping a single input bit always flips the output. While previous research demonstrated that transformers could solve PARITY, these proofs often relied on architectural "cheats" that do not reflect practical implementations. These included length-dependent positional encodings (where the model knows the sequence length $n$ in advance), non-differentiable hardmax attention, or modified LayerNorm implementations. This paper seeks to establish both a more rigorous lower bound and a more realistic upper bound for transformer expressivity.
The Lower Bound: A "No-Go" Theorem
The authors first address the simplest possible transformer configuration: a single-layer model with a single attention head. To prove that this architecture is incapable of solving PARITY, they utilize the concept of average sensitivity.
In computational theory, the sensitivity of a function measures how much the output changes in response to small changes in the input. The authors demonstrate that any function computed by a 1-layer, 1-head transformer has an average sensitivity of only $O(\sqrt{n})$. In contrast, the PARITY function has a sensitivity of $n$, which grows linearly with the input length. Because $n$ grows significantly faster than $\sqrt{n}$, the transformer's logic eventually fails to capture the high-frequency fluctuations of the PARITY function as the sequence length increases. This proof is formalized by representing the transformer's operations as a quantifier-free formula within the theory of reals.
The Upper Bound: A Realistic Construction
Moving beyond the limitations of single-layer models, the paper introduces a new 4-layer transformer construction capable of solving PARITY without relying on the aforementioned "cheats." This construction is designed to be "site-ready" and faithful to standard practices:
- Softmax Attention: Uses the standard, differentiable softmax function rather than hardmax.
- Length-Independent Positional Encoding: The encoding for the $i$-th position remains constant regardless of the total sequence length $n$.
- Polynomial Bounds: Positional encodings do not grow to impractical, infinite values.
- Causal Masking: The model functions correctly in decoder-only modes where tokens can only attend to preceding tokens.
To achieve this in four layers, the authors employ a mathematical technique involving a generalization of Faulhaber’s formulas. By using attention layers to compute sums of powers of positions, the model can effectively "count" the bits in the sequence and determine their parity.
Key Results and Theorems
The paper formalizes its findings through two primary theorems:
- Theorem 1 (The Sensitivity Bound): A 1-layer, 1-head transformer has an average sensitivity of $O(\sqrt{n})$. This leads to Corollary 1, which states it is mathematically impossible for such a model to compute PARITY for arbitrary input lengths.
- Theorem 2 (The Feasibility Result): A 4-layer transformer can compute PARITY using standard softmax attention and length-independent, polynomially bounded positional encodings.
Discussion and Future Work
While this work provides a significant step forward in understanding transformer expressivity, several questions remain open.
First, the lower bound currently applies only to the single-head case. It remains to be seen if a 1-layer transformer with multiple heads could potentially solve PARITY. This suggests that multi-head attention may be a fundamental requirement for certain types of logical reasoning rather than just a tool for parallelization.
Second, while 4 layers are proven to be sufficient, the absolute minimum number of layers required under realistic constraints is still unknown. Finally, the authors emphasize the distinction between expressivity and learnability. While they have proven that a weight assignment exists for a 4-layer transformer to solve PARITY, it is not guaranteed that standard optimization techniques like Stochastic Gradient Descent (SGD) would successfully find those weights during training. Bridging this gap remains a vital frontier for machine learning theory.
Summary updated