Introduction
Despite their massive success in natural language processing and beyond, Transformers are often treated as "black boxes." A fundamental question remains: What are the theoretical limits of what a Transformer can compute?
By characterizing neural networks in terms of well-understood formal systems, researchers can unlock new insights into their power and limitations. This paper provides a much tighter mathematical "sandwich" for the expressivity of Transformer encoders. By identifying a specific formal logic—FOC[+; MOD]—the authors prove it is simultaneously an upper bound for what fixed-precision Transformers can do and a lower bound for what arbitrary-precision Transformers can achieve, bringing us closer than ever to an exact characterization of these models.
The Expressivity Gap
To understand a model's limits, scientists link neural networks to formal systems like automata or logic. Previous research left a massive "no-man's-land" between two known bounds:
- The Lower Bound: Transformers were previously shown to be at least as powerful as "Simplified Stateless Counter Machines" (SSCMs), which are quite restricted and permutation-invariant (they ignore word order).
- The Upper Bound: Fixed-precision Transformers were shown to fall within the complexity class uniform $TC^0$, a very broad class of circuits capable of complex operations like multiplication and division.
This paper aims to fill that gap with a more precise logical language that matches the "flavor" of how Transformers actually process information.
The Logical Framework: FOC[+; MOD]
The authors introduce and utilize a variant of first-order logic called FOC[+; MOD]. This logic relies on three core components that closely mirror Transformer operations:
- Counting Quantifiers: The logic can ask, "Are there exactly $x$ positions where property $P$ is true?" This directly mirrors the way attention mechanisms aggregate information across a sequence.
- Modular Predicates: It can check if a position is, for example, even or odd (congruence). This mirrors the behavior of sinusoidal positional encodings, allowing the model to recognize patterns based on position (like "every third word") without needing a full "less-than" ($<$) operator.
- Linear Arithmetic: It allows the addition and comparison of these counts.
A key insight of the paper is the "Averaging" logic. The core of a Transformer is the attention mechanism, which is essentially a weighted average. By using a logic that focuses on counting and averaging rather than complex circuit connections, the authors found a much better fit for the architecture. Furthermore, they proved a "Normal Form" theorem for their logic, simplifying it into a standard structure (count things, then do math on the results) that maps neatly onto Transformer layers (Attention layers count; Feed-Forward layers do the math).
Closing the Gap: Key Results
The researchers prove two main directions to establish their tighter bounds:
- Tighter Upper Bound (Transformer $\to$ Logic): They show that any language recognized by a fixed-precision Transformer encoder can be described by an FOC[+; MOD] formula. They also prove that FOC[+; MOD] is strictly less powerful than uniform $TC^0$. For example, $TC^0$ can recognize the language $0^n 1^n$ (exactly $n$ zeros followed by exactly $n$ ones), but FOC[+; MOD] cannot. This confirms the previous upper bound was too loose.
- Tighter Lower Bound (Logic $\to$ Transformer): They show that for any FOC[+; MOD] formula, one can construct a Transformer encoder that recognizes the same language. They prove FOC[+; MOD] is strictly more powerful than SSCMs because it understands modular positions and can recognize languages like $(01)^*$, which SSCMs cannot.
By proving FOC[+; MOD] sits squarely between these two previous bounds, the authors have significantly narrowed the search for the exact "computational soul" of the Transformer encoder.
Limitations and Future Work
While this work provides a significant theoretical leap, a few gaps remain:
- Causal Masking: This paper focuses strictly on encoders (like BERT) where every token can attend to every other token. It does not cover decoders (like GPT) which use causal masking. Expressing "the past" would require a "less-than" ($p < q$) predicate, which would break the current upper bound.
- The Precision Gap: There is still a slight mismatch in the "sandwich": the upper bound assumes fixed-precision (mirroring real-world hardware), while the lower bound allows arbitrary precision. Bridging this gap is a primary goal for future research.
- Rational Weights: The authors speculate that a logic equivalent to Transformers with rational weights is possible, which would provide a final, exact characterization of their expressivity.
Summary updated