Algebraic Decomposition Theory for Transformer Length Generalization
Andy Yang, Blerta Veseli, Corentin Barloy, Michaël Cadilhac, Andreas Krebs, Charles Paperman, Howard Straubing, Michael Hahn
University of Notre Dame · Saarland University · Ruhr University Bochum · DePaul University · University of Tübingen · university of lille · Boston College
cs.FL, cs.AI
Submitted: 2026-08-13
Updated: 2026-08-14
Comments: 54 pages, 12 figures
License: http://arxiv.org/licenses/nonexclusive-distrib/1.0/
Importance score: 95/100
The gist: This paper establishes the first complete characterization of which regular languages transformers can length-generalize on, and provides a polynomial-time decision algorithm for this membership
Terminology
Summary
This paper establishes the first complete characterization of which regular languages transformers can length-generalize on, and provides a polynomial-time decision algorithm for this membership problem. The characterization is based on C-RASP, a programming language formalism that expresses which languages transformers length-generalize on.
The paper's core contributions are:
-
An algebraic characterization of C-RASP in terms of iterated wreath products of the integers (Z), moving beyond classical Krohn-Rhodes decomposition theory.
-
A decision algorithm running in polynomial time in the size of the language's syntactic monoid to determine if a regular language is in C-RASP.
-
A simpler necessary (but not sufficient) criterion via a profinite equation Rω.
-
Empirical validation showing C-RASP membership predicts transformer length-generalization better than existing classifications.
The paper notes that classical tools like Krohn-Rhodes decomposition theory are insufficient for C-RASP because its basic building blocks (unbounded counting) are not expressible by finite semigroups, and the flip-flop unit U2 is not expressible in C-RASP. The authors generalize decomposition theory to the infinite additive group on the integers.
Key theoretical results include:
-
Theorem 11: L ∈ C-RASP ⇐⇒ M(L) ∈ wpc(Z)
-
Theorem 13: M ∈ Rω iff M is aperiodic and every R-class of M contains at most one idempotent
-
Theorem 14: C-RASP ∩ REG = wpc(Dy), giving the hierarchy R ⊊ C-RASP ∩ REG ⊊ Rω ⊊ A ⊊ REG
-
Theorem 15: Membership of M ∈ C-RASP ∩ REG is decidable in O(poly(M)) time
The decision procedure works by iterating over R-classes of the monoid, constructing relational morphisms into Z, and using derived categories to formalize division
by wreath product factors. The procedure terminates either with success (constructing a division into a wreath product of Z) or failure (proving no such division exists).
Experiments were conducted on 125 regular languages, training GPT-2 models on strings of lengths [lmin, 50] and evaluating on lengths up to 500. Results show languages in C-RASP maintain near-perfect accuracy well beyond training range, while languages outside C-RASP exhibit rapid degradation. The paper also includes experiments with increased training data (100K examples) and more complex languages with greater nesting depth, confirming the same trends.
Improvements for AI systems
Based on this paper, I can improve AI systems in the following specific ways:
1. Guaranteed Length-Generalization for Regular Language Tasks
-
Improvement: Integrate the C-RASP membership decision algorithm into the training pipeline. Before training a transformer on a regular language task (e.g., regex-based parsing, tokenization, or simple state machines), run the polynomial-time check to determine if the target language is in C-RASP.
-
What the improved system can do: If the language is in C-RASP, the system can be trained on short sequences only (e.g., length ≤ 50) and will provably generalize to arbitrary lengths (up to 500+ in tests) with near-perfect accuracy. If not in C-RASP, the system can be flagged for potential failure, prompting the use of alternative architectures (e.g., adding explicit counting modules or recurrent components) or data augmentation with longer sequences.
2. Automatic Architecture Selection Based on Algebraic Properties
-
Improvement: Use the hierarchy R ⊊ C-RASP ∩ REG ⊊ Rω ⊊ A ⊊ REG to classify a given task's complexity. The decision algorithm provides a certificate (a wreath product decomposition into Z-factors) that can be used to design a modular transformer.
-
What the improved system can do: For a language in C-RASP, the system can automatically insert a
counting head
or positional encoding that mimics the Z-wreath product structure, ensuring the model learns the exact counting behavior without memorization. For languages only in Rω (aperiodic with single-idempotent R-classes), the system can use a simpler feed-forward-only transformer without attention, reducing compute while maintaining generalization.
3. Proactive Failure Detection and Curriculum Learning
-
Improvement: Before training, compute the profinite equation Rω criterion (Theorem 13) as a cheap necessary condition. If a language fails Rω, the system can immediately reject it as a candidate for length-generalization and instead use a fallback strategy (e.g., train on exponentially increasing sequence lengths or use a different model family).
-
What the improved system can do: The AI system can automatically generate a curriculum: for languages in C-RASP, use minimal training lengths; for borderline languages (in Rω but not C-RASP), use a curriculum that gradually increases length to avoid catastrophic degradation. This reduces training time and improves robustness on real-world tasks like arithmetic or code parsing.
4. Explainable Failure Analysis via Algebraic Certificates
-
Improvement: When a transformer fails to generalize, use the decision algorithm's output (the specific R-class or relational morphism that failed) to generate a diagnostic report. The report identifies whether the failure is due to unbounded counting (missing Z-factor) or aperiodic complexity (missing flip-flop structure).
-
What the improved system can do: Instead of black-box debugging, the system can tell the user:
This language requires a counter that increments unboundedly; your transformer lacks a positional encoding that supports this. Add a learned counter or use a different attention mask.
This enables targeted architectural fixes rather than trial-and-error.
5. Data-Efficient Training for Known C-RASP Languages
-
Improvement: For any regular language verified as C-RASP, the system can use the wreath product decomposition to generate synthetic training data that covers all necessary counting states, rather than random sampling. The decomposition tells exactly which subsequences and state transitions are critical.
-
What the improved system can do: Train on a minimal, provably sufficient dataset (e.g., 10K examples instead of 100K) while achieving the same length-generalization guarantees. This reduces data collection costs and training time for industrial NLP tasks like named entity recognition or simple grammar parsing.
6. Hybrid Models for Non-C-RASP Languages
-
Improvement: For languages outside C-RASP but inside REG, the system can automatically augment the transformer with a finite-state machine (FSM) layer or a recurrent counter, guided by the algebraic characterization (e.g., adding a Z-counter for each failed wreath product factor).
-
What the improved system can do: The hybrid model will achieve length-generalization on a broader class of regular languages (e.g., those requiring nested counting or modulo operations) that pure transformers fail on, while still leveraging attention for context. This extends the system's applicability to more complex parsing and reasoning tasks.
7. Real-Time Complexity Estimation for New Tasks
-
Improvement: The polynomial-time decision algorithm can be used as a pre-processing step in an AutoML system. Given a new task (e.g., a regex from user input), the system computes its C-RASP membership and assigns a
generalization risk score.
-
What the improved system can do: The system can then automatically choose the model size, training length, and data augmentation strategy based on this score, optimizing for both accuracy and compute. For example, a low-risk language can use a tiny model with short training; a high-risk language triggers a larger model with explicit counting mechanisms.