Despite their world-dominating success across natural language processing and beyond, the fundamental "computational DNA" of Transformers remains an active area of theoretical research. In computer science, a system's power is often measured by comparing it to formal languages or logic—just as simple Recurrent Neural Networks (RNNs) are known to be roughly equivalent to finite automata.
Previous research established broad goalposts for the expressivity of Transformer encoders. On the lower end, they are at least as powerful as "simplified stateless counter machines" (which merely count occurrences of symbols). On the upper end, when limited to fixed-precision arithmetic (like the 16-bit or 32-bit floats used in actual hardware), they are no more powerful than uniform $TC^0$ circuits—a class of shallow but wide Boolean circuits. However, the gap between these two bounds was substantial. This paper aims to "tighten the sandwich" by identifying a precise logical language that describes exactly what a Transformer encoder can and cannot compute.
The Logical Sandwich: Introducing FOC[+; MOD]
To bridge this gap, the researchers identify a specific variant of first-order logic called FOC[+; MOD]. This logic serves as a tighter upper bound for what fixed-precision Transformers can compute, and a tighter lower bound for what arbitrary-precision Transformers can express.
The components of FOC[+; MOD] break down as follows:
- FO (First-Order): The logic can reference individual positions within a string.
- C (Counting): It includes "counting quantifiers" (e.g., "There are exactly $x$ positions where the symbol is 'A'").
- [+; MOD]: It can perform addition and modular arithmetic on these counts and positions.
The core insight here is the power of counting. Unlike RNNs, which process data linearly, Transformers are naturally permutation-invariant (prior to positional encodings). Their core strength lies in their ability to count and compare quantities across the entire input simultaneously, making them behave much like counting-based logic.
Methodology: A Two-Pronged Proof
As a purely theoretical work, the paper relies on mathematical proofs rather than empirical dataset training. The authors utilize a two-pronged approach to establish their bounds:
- Logic to Transformer (Lower Bound): The authors demonstrate that any sentence written in FOC[+; MOD] can be "compiled" into a Transformer encoder. They provide clever constructions using ReLU units to simulate logical gates (AND, OR, NOT) and leverage self-attention mechanisms to perform the counting.
- Transformer to Logic (Upper Bound): Conversely, they prove that for any fixed-precision Transformer, there exists a corresponding formula in FOC[+; MOD] that describes exactly which strings the model will accept. This involves translating floating-point arithmetic into logical operations.
To make these proofs manageable, the authors developed a "Normal Form Theorem," demonstrating that any complex FOC[+; MOD] formula can be simplified into a standard structure that maps cleanly onto the discrete layers of a Transformer.
Key Findings
The paper successfully tightens the known computational bounds of Transformer encoders through several key theorems and propositions:
- A Tighter Upper Bound: Every language recognizable by a fixed-precision Transformer encoder is definable in FOC[+; MOD] (Theorem 2). Crucially, the authors prove that FOC[+; MOD] is strictly less expressive than uniform $TC^0$. Because $TC^0$ can recognize certain languages (like $0^n 1^n$) that FOC[+; MOD] cannot, the previous $TC^0$ bound was "loose." In practical terms, fixed-precision Transformers are actually less powerful than previously thought.
- A Tighter Lower Bound: Every language definable in FOC[+; MOD] is recognizable by a Transformer encoder (Theorem 5). FOC[+; MOD] is a tighter lower bound than Simplified Stateless Counter Machines (SSCMs). For instance, FOC[+; MOD] can recognize the language $(01)^*$, which SSCMs cannot.
- The Role of Precision: The upper bound strictly holds for fixed-precision models, highlighting how real-world hardware limitations constrain the theoretical expressivity of the architecture.
Limitations and Future Directions
While this work brings us closer to a complete mathematical characterization of Transformers, it notes several boundaries and areas for future exploration:
- Infinite Precision: The upper bound relies on the assumption of fixed-precision arithmetic. If a Transformer could utilize infinite-precision real numbers, it might theoretically store an unbounded amount of information in decimal values, potentially breaking these bounds.
- Causal Masking: The study focuses exclusively on standard encoders. It does not account for the "causal masking" used in decoders (like GPT models), which prevents positions from attending to future tokens. Expressing this masking might require adding a "less-than" ($<$) predicate to the logic, fundamentally altering the results.
- Positional Encodings: While the paper successfully handles sinusoidal positional encodings, the authors note that different encoding schemes—such as learned or relative positional embeddings—might shift the boundaries of what the model can compute.
Summary updated