arXiv:2609.08851cs.LGSep 2026

Manuscript Offprint

arXiv:2609.08851

Length Generalization for Transformers via Compression

Georg Zetzsche, Hongjian Jiang, Andy Yang, Pascal Bergsträßer, Marco Sälzer, David Chiang, Anthony W. Lin

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Georg Zetzsche

Max Planck Institute for Software Systems (MPI-SWS) georg@mpi-sws.org

Hongjian Jiang

RPTU Kaiserslautern-Landau lus70ger@rptu.de

Andy Yang

University of Notre Dame ayang4nd.edu

Pascal Bergsträßer

RPTU Kaiserslautern-Landau bergstraesser@cs.uni-kl.de

Marco Sälzer

RPTU Kaiserslautern-Landau marco.saelzer@rptu.de

David Chiang

University of Notre Dame dchiang@nd.edu

Anthony W. Lin

RPTU Kaiserslautern-Landau Max Planck Institute for Software Systems (MPI-SWS) awlin@mpi-sws.org

Abstract

Recent advancements in transformer length generalization theory enable us to reliably predict when a transformer can learn to solve a task. In particular, the C-RASP hypothesis (a formalized version of the so-called RASP-1 conjecture) posits that transformers length-generalize on a task if and only if a solution is expressible in the C-RASP language. While this hypothesis has strong empirical validation, theoretical problems arise from the fact that no computable length generalization bounds exist for C-RASP, alongside the discovery of seemingly contradictory experiments. To address these problems, we refine the C-RASP hypothesis utilizing the recently-proposed fragments C-RASP+_{+} and C-RASP1_{1}. These fragments have computable length generalization bounds, though in the worst case requiring an extremely large (double exponential) sample size. It is an open question whether these sample size bounds are tight. In this paper, we resolve this open question by providing an exponentially tighter bound. In doing so, we show a polynomial length generalization bound for transformers if we adopt compressed strings, via a novel connection to power words. As an application, we show how this yields a fine-grained analysis of the C-RASP conjecture that resolves contradicting experimental evidence against it.

1 Introduction

Length generalization (Anil et al., 2022; Varre, Yüce, and Flammarion, 2025; Wang et al., 2025; Huang, Yang, et al., 2025; Y. Zhou et al., 2024; Chen, Ma, and Z. Li, 2025a; J. Li and Cotterell, 2026; Yang, Bergsträßer, et al., 2026; H. Zhou et al., 2024) has recently been demonstrated to be a powerful theory for understanding when transformers could generalize beyond a given set of training data. Loosely speaking, a given task could be solved in a length-generalizable manner if, after training on strings up to a certain N>0N > 0, the trained transformer would be able to correctly output the right label for longer input strings (i.e., not seen in the training data). One key component in the theory of length generalization for transformers lies in the so-called RASP-1 conjecture (H. Zhou et al., 2024), which hypothesizes a criterion for length generalizability for transformers in terms of definability in a RASP language (Weiss, Goldberg, and Yahav, 2021). In particular, a more formal version of the hypothesis

Preprint.

— which we will henceforth refer to as the C-RASP hypothesis — was given by Huang, Yang, et al. (2025) that length generalizability for transformers is equivalent to definability by a limit transformer, which particularly includes the the C-RASP specification language (Yang and Chiang, 2024). This theory has enabled practical advancements in training efficiency (Hu et al., 2025) and interpretability (Huang, Bakalova, et al., 2026).

The current framework based on C-RASP is the most predictive notion of transformer length-generalization that we know of. By reformulating different reasoning tasks in terms of formal language recognition, we can prove whether or not the task is expressible in C-RASP, and this closely characterizes when length generalization occurs (Huang, Yang, et al., 2025; Yang, Cadilhac, and Chiang, 2026). However, there remain several problems behind the C-RASP framework.

One problem, as pinpointed by (Chen, Ma, and Z. Li, 2025a), is that the current theory provides no bounds on the input lengths nor number of samples required to guarantee length generalization. Beyond an exponential length bound for C-RASP1_{1} (the fragment of C-RASP in which counting operators are nested to depth at most 1) and a fragment of C-RASP2_{2}, Chen, Ma, and Z. Li (2025a) did not find any bounds for C-RASP. Indeed, Yang, Bergsträßer, et al. (2026) later showed that length generalization bounds are not computable for C-RASP in full generality. This seems to conflict with the experimental observations (e.g. Huang, Yang, et al., 2025) that transformers rather quickly length generalize. To overcome this theoretical issue, Yang, Bergsträßer, et al. (2026) proposed to study the finite-precision fragment of C-RASP, called C-RASP+_{+}, proving (tight) exponential length generalization bounds. Unfortunately, these exponential bounds for C-RASP1_{1} and C-RASP+_{+}yield only an extremely large upper bound on the sample size: doubly exponential in the size of the minimal representation as a C-RASP1_{1} or C-RASP+_{+} formula. It is an open question whether these upper bounds are tight.

The lack of a computable length generalization bound in fact leads to some strange paradoxes on the C-RASP hypothesis. For instance, consider the notorious PARITY language (strings of a's and b's with an even number of a's), whose inability to length generalize on transformers is backed up by numerous experimental results, e.g., see Huang, Yang, et al., 2025; Chiang and Cholak, 2022; Bhattamishra, Ahuja, and Goyal, 2020; Butoi et al., 2025. Consider now the restriction PARITYk_{k}, which consists of all strings in PARITY with at most kk occurrences of the symbol a. Now, for any kk, the language PARITYk_{k} is definable in C-RASP, and thus the theory predicts that transformers should length-generalize on this language. However, the same aforementioned experiments in fact show that PARITYk_{k} does not length generalize even on small values of kk (e.g. k=50k = 50). An explanation to this “contradiction” is that transformers could length generalize after an astronomically large sample has been seen. As we shall show in this paper, by providing a precise computable bound for sample size required for length generalization, we can more accurately predict when transformers will (or will not) length generalize in a reasonable amount of time.

Contributions. In this paper, we address both of the above problems by conducting a more precise theoretical analysis of transformer length generalization using C-RASP+_{+} and C-RASP1_{1}. First, we resolve the aforementioned open question on the sample size bound to achieve length generalization for C-RASP+_{+} and C-RASP1_{1} definable tasks by showing an exponential improvement upon the prior bound. This exploits a novel connection to compression via the so-called power words. Then, we show how our result provides a fine-grained analysis that resolves contradicting experimental evidence against the C-RASP hypothesis. We detail our contribution below.

Firstly, we exploit compression using the so-called power words and obtain a polynomial length generalization for transformers in terms of compressed strings. Until now, power words have mostly been studied in connection with computational group theory (Lohrey, Stober, and Weiß, 2024; Ganardi, Lohrey, and Zetzsche, 2023; Lohrey and Weiß, 2019), and we show for the first time in this paper that this is applicable to the theory of length generalization for transformers. In particular, our result implies a new tight sample size bound for length generalization: exponential in the size of the smallest C-RASP+_{+}/C-RASP1_{1} expression. Note that an exponential sample lower bound size is already needed for simpler concepts (e.g. boolean formulas (Blumer et al., 1989)).

Theorem 1 (Informal Version). Every C-RASP+_{+}/C-RASP1_{1} expression φ\varphi has a small (polynomial) length generalization bound in terms of compressed strings (as power words). Therefore, we obtain a sample size bound for length generalization that is exponential in the size of φ\varphi.

Secondly, to resolve the aforementioned “counterexample” of the C-RASP hypothesis, we propose to consider a fine-grained analysis at the sample size bound that is required to length generalize on a language. In the case of PARITYk\text{PARITY}_k, our result implies an upper bound that exponentially (in kk) many strings might be needed in the training data to achieve length generalization. As we show later, this is because PARITYk\text{PARITY}_k is definable in C-RASP+\text{C-RASP}_+ by a formula with size polynomial in kk. Similarly, our result also separates tasks like PARITYk\text{PARITY}_k from tasks like COUNTk\text{COUNT}_k (ensuring the number of aa's in the input is >k> k, without checking its parity), and MAJk\text{MAJ}_k (ensuring the input string is in COUNTk\text{COUNT}_k, and there are more aa's than bb's in the input), for which our result entails a polynomial bound in kk for the required sample size for length generalization. This is because COUNTk\text{COUNT}_k (resp. MAJk\text{MAJ}_k) is definable by a C-RASP+\text{C-RASP}_+ (resp. C-RASP1\text{C-RASP}_1) specification, whose size is polynomial in log⁡k\log k. We experimentally validate such languages achieve a much better length generalization in comparison to PARITYk\text{PARITY}_k.

References (62)