Why length generalization?
Why should a rule learned on short sequences keep working on longer ones? Distinguish representability, learning, and generalization.
We want models to apply what they learn to problems larger than those encountered during training. A model trained on short sequences might later need to copy a longer passage, count events across a longer record, or check the structure of a larger program. When the underlying task stays the same, can the model carry out the same computation on inputs longer than the training examples? This is the problem of length generalization.
One motivation is to make better use of training data and computation. Long examples can be costly to collect, annotate, and process, and training cannot cover every input length a model may encounter. If shorter examples are sufficient to learn a reusable rule, we may reduce the need for long training examples while still handling longer inputs at test time. This does not necessarily mean that fewer training examples are needed overall: generalizing across lengths and learning from fewer samples are distinct goals.
Length generalization also asks whether the learned computation continues to work as the task grows. Counting, copying, and checking nested structure provide simple settings in which the same rule applies across lengths. A larger context window allows a model to receive longer inputs, but does not ensure that it processes them correctly. Throughout this tutorial, we therefore distinguish the lengths seen during training from the maximum length the model can process.
To understand what a transformer can learn from shorter inputs, we separate three questions:
- Representability: Does there exist a transformer that computes the desired function across input lengths?
- Learnability: Can a training procedure find a model that computes the function on the training distribution?
- Length-generalizable learnability: Does training on bounded lengths yield a model that also computes the function on longer inputs?
A positive answer to one question does not settle the next. Constructing suitable weights establishes that a computation is possible, but does not show that training will find them. Likewise, perfect accuracy on shorter inputs does not establish length generalization. For example, a rule that checks whether parentheses are correctly nested only up to the maximum training length can agree with the desired recognizer on every training input and fail on every longer valid string. The observations alone do not distinguish that rule from a recognizer that works at all lengths. We therefore need to understand which computations the architecture can represent and which solutions the learning procedure favors.
Our main tool is C-RASP, a small programming language for computations over sequences. Its programs combine predicates on positions with counts over prefixes. A fixed program describes the same computation at every input length, making it possible to state an algorithm without choosing a maximum sequence length. C-RASP also connects these algorithms to transformers: prefix counts can be represented using attention, while feedforward layers implement comparisons and Boolean operations. This connection gives constructive expressivity results; it does not by itself establish a learning guarantee.
We first develop C-RASP through a worked parentheses recognizer and examples of what the language can and cannot express. We then explain its compilation into transformers and the role of positional information. This leads to the length-generalization framework of Huang et al. (2025), which connects suitable representations to eventual generalization under an idealized inference procedure. We keep this guarantee separate from ordinary gradient-based training and discuss what it does, and does not, tell us about the training lengths required. The final sections outline how additional computation through chain of thought changes the question and which limitations remain open.
Foundations
The complexity classes, sequence tasks, and causal transformer model used throughout the tutorial.
Computational complexity
Complexity classes describe which problems can be solved with specified computational resources. For transformers, circuit complexity is useful because it separates the amount of computation performed in parallel from the number of sequential stages.
A Boolean circuit is a directed acyclic graph whose gates compute Boolean operations. Its size is the number of gates; its depth is the longest path from an input to the output. Gates at the same depth can be evaluated in parallel. To recognize inputs of arbitrary length, we use a family of circuits , with one circuit for each input length . Polynomial size means at most gates, while constant depth means a bound independent of . We use logspace-uniform families: one algorithm constructs from using working space, rather than choosing unrelated circuits separately at every length (Immerman, 1999, Chapter 5).
Three circuit classes. The following classes all require polynomial size but differ in their gates and depth:
- : Constant-depth circuits with AND, OR, and NOT gates. AND and OR have unbounded fan-in: a single gate may combine arbitrarily many inputs. For example, testing whether a string contains an needs only an OR over the input indicators. Parity cannot be computed in this class.
- : Constant-depth circuits that additionally allow unbounded-fan-in majority gates. A majority gate tests whether more than half its inputs are true; this gives the same class as allowing unweighted threshold gates. This class contains both majority and parity.
- : Circuits of depth with AND and OR gates of fan-in at most two, and NOT gates. The additional depth allows information to be combined through a tree. For example, a balanced tree of constant-size XOR circuits computes parity in logarithmic depth.
The classes satisfy
The first inclusion is strict; whether the second is strict remains open. Thus, constant depth alone does not determine expressive power: the permitted gates matter as well (Viola, 2023, Chapter 10).
Turing-computable functions. A total function is Turing-computable if a single Turing machine halts and returns its value on every finite input. Unlike the circuit classes above, this imposes no polynomial time or small-depth bound. For a language, the corresponding notion is decidability: the machine must halt with the correct acceptance decision on every input. Computability asks whether an algorithm exists; complexity asks which resources it needs.
Why these classes matter for transformers. A fixed number of transformer layers suggests a bounded number of parallel stages, but a circuit simulation must also account for arithmetic precision and the operations within each layer. With -bit arithmetic and feedforward maps computable in space linear in their input representation, a fixed transformer forward pass can be simulated in (Merrill and Sabharwal, 2023). Claims of Turing completeness concern a different resource regime and must specify how computation can grow, for example through additional generated tokens or iterations. Neither a circuit upper bound nor Turing completeness establishes that training will learn a solution that generalizes to longer inputs.
Formal languages and sequence tasks
We use a small set of tasks to study which computations transformers can represent and learn across input lengths. Their rules are easy to state, but involve different operations: counting, tracking order, checking nested structure, and reproducing a sequence. They will serve as running examples throughout the tutorial.
Language recognition. A formal language is a set of finite strings over an alphabet . A recognizer decides whether an input string belongs to that set. We consider:
- Parity: Accept a string over exactly when it contains an even number of symbols. Encoding as 1 and as 0 gives the usual bit-parity problem. For example,
abais accepted andabbis rejected. - Dyck-1: Accept correctly nested parentheses of a single type. Every prefix must have at least as many opening as closing parentheses, and the final counts must agree. For example,
()(())is accepted, while())(is rejected despite having equal final counts. - Dyck with multiple bracket types: Require both correct nesting and matching bracket types. For example,
([])is accepted, while([)]is rejected. Unlike Dyck-1, counting opening and closing brackets alone cannot check that their types match. - Flip-flop: For a string over , accept exactly when the last non- symbol is . The symbol is neutral: appending it leaves the decision unchanged. For example,
abeeis accepted andbaeeis rejected. Strings with no or , including the empty string, are rejected.
Sequence generation. Copying asks the model to produce an output sequence rather than an acceptance decision. After reading an input and a separator, it must reproduce the input in the same order. Following Huang et al. (2025, Appendix E.2.1), an example is SOS b a b SEP b a b EOS. The paper distinguishes Copy (repeat), with inputs over a binary alphabet that may contain repeated symbols, from Copy (unique), in which all input tokens are distinct. Training loss is applied to the copied sequence and the final EOS token.
Transformer models
We follow the causal transformer model of Huang et al. (2025, Section 2). Its main design choices are:
| Choice | Setting |
|---|---|
| Positions | NoPE or learned APE. |
| Attention | Causal softmax, with logits scaled by . |
| Blocks | Residual attention and feedforward layers; fixed depth, width, and head count. |
| Activations | ReLU or Heaviside. |
| Normalization | LayerNorm omitted from the formal model. |
| Precision | Rounded attention logits and exponentials; other activations may have unbounded precision. |
| Readout | Final-position logits for recognition. |
Here includes the beginning-of-sequence token. The details below specify the computation and distinguish the formal model from the experiments.
Transformer equations and numerical assumptions
Inputs and positions. Let be a word over a finite alphabet . We prepend a special beginning-of-sequence token, , and write for the total sequence length. At each position , the model maintains a vector after layer . The initial vector is
where maps token identities to learned vectors. The optional vector supplies explicit positional information:
- With no positional encodings (NoPE), at every position. Positions can nevertheless have different representations because causal attention gives them access to different prefixes.
- With absolute positional encodings (APE), each supported position has a learned vector . The positional table is finite, so a fixed model supports only a finite context window. We discuss how offsets and increasing context lengths enter the generalization framework below.
Causal attention. A model has layers and attention heads per layer. Within layer , head applies learned linear maps to the previous layerβs vectors:
The query describes what position uses to score other positions; the key supplies the features against which it is scored. The value is the information that the head aggregates. Suppressing the layer and head indices, the computation is
The causal mask excludes positions : a position can attend to BOS, itself, and earlier tokens, but not to future tokens. All queries, keys, and values in a layer come from the previous layer; the prefix restriction does not turn a layer into a left-to-right recurrent computation. The weights are nonnegative and sum to 1 over the visible prefix, so a head returns a weighted average of its values.
Logit scaling and uniform attention. Ordinary softmax attention uses . Huang et al. instead use , making the scale depend explicitly on sequence length. For positive , the ratio between two attention weights is
Thus scaling changes how strongly the head distinguishes unequal scores. If all visible scores are equal, however, every visible position receives weight . This is the uniform attention used later to represent prefix counts. The usual fixed factor , where is the query/key dimension, can be absorbed into the learned query or key matrices. These equations display the algebraic operations; the rounding convention is stated below.
Residual and feedforward updates. Each head contributes a vector in the modelβs width- space; its value map incorporates the required output projection. The head outputs are summed and added to the current representation:
The feedforward update is
Here maps into the feedforward hidden space, is a bias vector, and maps back to width . The activation acts coordinatewise. Each coordinate may use ReLU,
or Heaviside,
The feedforward map uses the same parameters at every position within a layer. It does not itself combine different positions; that communication occurs through attention. The residual additions retain the preceding representation while adding the attention and feedforward contributions.
LayerNorm. The equations above omit normalization, as does Huang et al.βs main formal model. Their experiments include LayerNorm. Appendix D.3 sketches how to incorporate normalization into the limit-transformer simulation by retaining additional information from which activation norms can be recovered. We therefore distinguish the stated formal model from its proposed extension with normalization. Yang and Chiangβs original C-RASP compilation uses LayerNorm explicitly; we return to its role alongside that construction.
Numerical precision. Huang et al. round attention logits and the outputs of the exponential function to a fixed number of fractional bits before further processing. Rounding to fractional bits restricts these quantities to multiples of ; it does not impose a fixed total bit budget on every number in the computation. Other activations may retain unbounded precision. In particular, this model differs from one that rounds every stored activation and arithmetic result to a fixed number of bits. The circuit upper bound discussed next has its own precision assumptions and should not be transferred to this model without checking them.
Output and computation budget. After layers, a learned linear map produces the output logits
For recognition, the output at the final input position determines acceptance; for example, a binary readout can compare acceptance and rejection logits. A single forward pass applies the layers once. For a fixed transformer, its parameters, depth, width, and head count do not grow when the input gets longer. Autoregressive generation instead uses the output to append a token and runs another forward pass, introducing additional computation that we consider separately in the chain-of-thought section.
Forward-pass Expressivity
We first ask which languages a fixed transformer can recognize in a single forward pass. Its depth , width , and number of heads are independent of the input length. Increasing the input length adds positions to the computation, while the number of layers remains fixed.
The circuit classes introduced in the complexity background make this parallel structure precise. Merrill and Sabharwal (2023) show that transformers using bits of arithmetic precision, with feedforward maps computable in space linear in their input representation, can be simulated by logspace-uniform circuits. This is an upper bound on their forward-pass expressivity, not a claim that every such circuit can be represented by a transformer.
The precision assumption matters: Huang et al.βs model permits unbounded-precision activations, so this circuit bound does not apply to it directly. Nor does the bound characterize C-RASP: for example, contains parity, whereas C-RASP does not. We consider autoregressive generation, which runs further forward passes to generate additional tokens, in the chain-of-thought section.
Programming in C-RASP
Define token predicates and prefix counts, then study a parentheses recognizer and other language examples.
Motivation
- Why introduce C-RASP?
- What does it abstract away / capture?
Definition
A C-RASP program is a fixed finite sequence of assignments defining vectors indexed by input positions. Boolean-valued vectors represent predicates on positions; count-valued vectors assign an integer to each position. Assignments are evaluated in sequence, each defining a whole vector from the input and previously defined vectors. Both the number of assignments and the permitted operations are independent of the input length.
Our running example is Dyck-1, the language of correctly nested parentheses over the alphabet . We will trace the program on the input ()(()).
Input representation. We assume that inputs are words over a finite alphabet , corresponding to tokens in a transformer. For each character , we create an initial Boolean vector , where is the input length. Its entry is 1 if the input character at position is , and 0 otherwise. In other words, each marks all the positions containing the character .
The two input-marker vectors for our example are:
Both kinds of vectors have one entry per input position, but their entries mean different things. A Boolean-valued vector answers a yes-or-no question at each position: for example, says whether position contains an opening parenthesis. A count-valued vector instead stores a number at each position: tells us how many opening parentheses have appeared from the start through position . Thus, marks individual tokens, while summarizes prefixes. Prefix counting turns a Boolean predicate into counts; comparing counts, as in below, produces a Boolean predicate again.
We now combine these markers into a recognizer.
Prefix counts. First, count how many opening and closing parentheses have appeared up to each position. The notation counts the positions up to where the predicate is true:
For , these vectors are and . Each entry records the count at the corresponding prefix.
Prefix violations. A valid string must never close more parentheses than it has opened. Mark each position where this condition fails:
For , no prefix has more closing than opening parentheses, so .
Then count the positions marked as violations and check whether that count is zero:
For this input, and . In general, is true exactly when no prefix ending at or before has violated the nesting condition.
Balanced prefixes. The final condition is that the prefix has equally many opening and closing parentheses:
For this input, and . The prefix () is balanced at position 2, and the entire string is balanced at position 6. Following Yang and Chiang (2024, Definition 3.1), a recognition program must end with a Boolean-valued operation and accepts a word exactly when is true. Here, is the output vector, and , so is in Dyck-1.
The two conditions are both necessary. The string ())( has equal total numbers of opening and closing parentheses, but it has already closed one too many at position 3. It therefore fails the prefix condition and is rejected.
Reference: all allowed C-RASP operations
The full set of allowed operations is:
Boolean-valued vectors
| Input marker | for |
| Negation | |
| Conjunction | |
| Count comparison | |
| Constant |
Count-valued vectors
| Prefix count | |
| Conditional | |
| Addition | |
| Subtraction | |
| Minimum | |
| Maximum | |
| Constant |
Examples
Below we provide some more examples of C-RASP programms for some formal languages. In contrast we also discuss languages that are not expressible by C-RASP and hence are not expected to length-generalize.
Expressible in C-RASP
The goal is to accept strings in which every precedes every . Thse key idea is to mark an as a violation once a has appeared, then check that there are no violation.
C-RASP Program for
Reading the program. records whether a has appeared; marks an after a ; and checks that no such position exists.
Check. aaabbb and bbb are accepted; ba is rejected. The empty word also belongs to .
Add equal counts:
Now require equally many and symbols, with at least one of each. The following program over checks block order, equal counts, and nonzero counts:
C-RASP Program for
Reading the program. records whether a has appeared, and marks any that appears after a . The condition requires that there are no such violations, requires equal counts, and requires at least one . The final output combines these three checks. Together they recognize for ; the empty word is excluded.
Check. aabb is accepted. aab fails the count check, while abab has equal counts but fails the order check.
TODO: other programms
Not expressible in C-RASP
Parity. Strings over containing an even number of symbols. Parity is theoretically expressible by transformers, but both theoreticaly and experimentally it is not learnable. C-RASP can count symbols, but expressing modula properties is not possible. TODO be more precise why Parity not in Crasp
Flip-flop. The language over . Membership depends on the last non- symbol being . TODO C-RASP can not recover the last occurence of the non-e symbols.
Exercise: three equal blocks
Write a recognizer for strings of the form over , with . Extend the two-block construction in three steps:
- Compute the three symbol counts.
- Mark and count positions that violate the block order.
- Combine the order check with equal, nonzero counts in the final Boolean output.
You can use the drag-and-drop C-RASP editor (source and launch instructions) to check your solution on concrete inputs and inspect the intermediate vectors. Test your solution on abc and aabbcc (accept), and on aabcc, acb, and abccba (reject). The last input has equal counts but the wrong order. These tests help catch mistakes; justify separately why your program works for every input length. Use the hint before consulting the solution.
Hint
Start by computing prefix counts for each symbol. Use them to mark positions where the order is broken: an after any or , or a after any . Count these violations, then combine the no-violation check with a final comparison of the three counts and a check that they are nonzero.
Solution
Use to mark positions at or after the first or , and to mark positions at or after the first . The disjunction below is shorthand for negation and conjunction: .
flags an after a or , while flags a after a . Thus enforces the block order. The conditions and require equal, nonzero counts, so the program accepts exactly for .
From programs to transformers
How attention and feedforward computations implement C-RASP operations, including the numerical assumptions used by the construction.
C-RASP provides a constructive lower bound on transformer expressivity: any C-RASP program can be simulated by a suitable transformer. Boolean operations are encoded by the transformerβs feedforward layers, while prefix counting is implemented through attention.
The central idea is that uniform causal attention averages a predicate over the visible prefix. The resulting normalized counts share a positive denominator at each position, so comparing them gives the same answer as comparing the integer counts.
Derivation: prefix counting with uniform attention
For an input over a finite alphabet , represent the token at position by a one-hot vector , where exactly when the token is . These coordinates are precisely the C-RASP indicators . A standard transformerβs token-embedding matrix maps this one-hot representation (or its equivalent token ID) to a learned vector.
Counting with attention. Following Counting Like Transformers (Yang and Chiang, 2024), the key idea is that attention can aggregate a predicate over a prefix. At position , a causally masked attention head assigns position the weight
Set for every visible position (for example, set all keys to zero). Each softmax score is then , so its normalized weight is . With values encoding , attention returns
Thus attention can encode the C-RASP prefix count as the normalized count
At each position , count values share the positive normalization factor , so comparisons between them are unchanged. Counts can also be combined using arithmetic and conditional selection, as described below. Constants must use the same encoding: the integer constant 1 is represented by , and more generally a constant by .
For Dyck-1, for example, becomes . Both opening- and closing-counts share divisor , so their comparisons-and hence the prefix-balance testβare unchanged.
Arithmetic and numerical precision
Sums, differences, minima, maxima, and conditional selection also preserve this shared divisor, allowing normalized counts to flow through the program. Distinguishing adjacent normalized counts requires resolution on the order of , so a fixed number of fractional bits cannot suffice at arbitrary lengths. This motivates allowing logarithmic precision for these attention results: for inputs of length at most , fractional bits give resolution finer than the smallest adjacent-count gap . This observation concerns the resolution of the normalized counts, rather than a guarantee that rounding every intermediate computation to this precision preserves the full simulation.
Constants and the BOS token
The simplified calculation above omits the beginning-of-sequence (BOS) token used in the full construction. With BOS preceding the ordinary input tokens, uniform attention averages over positions. Assigning value 1 at BOS and 0 elsewhere therefore yields , the normalized encoding of the integer constant 1. Ordinary predicates are false at BOS, so their counts are encoded as . Counts and constants thus share the same denominator (Yang and Chiang, 2024, Appendix B.2).
How LayerNorm is handled
For clarity, this explanation omits LayerNorm, but it can be accounted for in the compilation. Yang and Chiang (2024, Section 5.2 and Appendix B.3) use paired coordinates with opposite signs, ensuring zero mean so that LayerNorm applies a shared scaling factor at each position. Their construction handles this scaling when implementing Boolean values and count comparisons.
Putting these constructions together, any fixed C-RASP program can be compiled into a transformer whose depth and width are independent of the input length.
This compilation establishes representability, but does not imply that training will find the constructed solution. Empirical studies nevertheless find that C-RASP expressibility predicts length generalization on a range of algorithmic and formal-language tasks (Huang et al., 2025).
Positional information
How positions enter the model, from finite positional tables to limit transformers and positional predicates.
So far, we have not used explicit positional embeddings. Positions are distinguished only by their tokens and the information available from their prefixes through causal attention. Positional embeddings provide an additional, explicit representation of where each token occurs. Here we consider absolute positional embeddings: each position has its own learned vector , which is added to the token embedding :
Finite positional tables and offsets
The position vectors are stored in a finite table, so the model is defined only up to its maximum context length . To train the embeddings across this table using shorter examples, the offset trick assigns an example of length the positional vectors for a valid offset . Varying the offset allows training examples to occur throughout the context window, but does not guarantee that every position is observed in a finite training run or teach the model to generalize to longer examples. Since the table is still finite, the C-RASP simulation cannot be realized by one such fixed transformer for inputs of arbitrary length. Instead, consider a sequence of transformers with increasing context lengths and corresponding positional tables. To describe the underlying computations across these context lengths, the framework introduces a mathematical object called a limit transformer.
Limit transformers
A limit transformer is an idealized model that captures the positional information provided by positional embeddings while remaining defined on inputs of arbitrary length. It has fixed width and finite-precision parameters. Besides positional vectors , it can use an additional positional function in each attention head. Writing for the query position and for the key position, the attention logit has the form
The term directly expresses a relation between positions, such as whether immediately precedes . This allows the model to describe positional interactions at every input length without storing a separate learned vector for every position in a growing table.
For the length-generalization result, the positional vectors must be periodic, and the additional positional functions must be translation-invariant and local. Below, denotes the positional function of one attention head, with query position and key position .
Periodicity. The positional vectors repeat with a fixed positive integer period :
For example, period 2 allows alternating vectors for odd and even positions. The sequence is infinite, but only vectors need to be specified, independently of the input length.
Translation invariance. Shifting both positions equally leaves the interaction unchanged:
For example, assigning score 1 to the preceding position and 0 elsewhere treats and identically. Singling out absolute position would violate translation invariance.
Locality. The additional positional interaction vanishes beyond a fixed nonnegative integer distance :
The preceding-position example is local with . Assigning score 1 at every even distance is translation-invariant but not local. This restriction applies only to ; content-based attention can still aggregate over the entire prefix.
Positional information in C-RASP
We can express the same kinds of information at the program level by extending C-RASP to . Here, is a collection of Boolean predicates on individual positions, and is a collection of Boolean relations between pairs of positions. We add positional predicates
and allow counting to be restricted by a positional relation:
This counts positions for which both and hold. Ordinary prefix counting remains a separate allowed primitive, represented here by the always-true relation . The locality restriction applies to relations in , not to this unrestricted prefix-counting operation.
For example, a unary predicate can mark the even positions. A binary relation can hold exactly when . Counting with this relation gives 1 if the preceding position satisfies , and 0 otherwise, including when no preceding position exists. Comparing this count with 0 therefore lets a program test the preceding token.
When the predicates in are periodic and the relations in are translation-invariant and local, we obtain the variant we denote by throughout this tutorial. This abbreviates the notation used by Huang et al. (2025). The position-free language introduced earlier is the special case with no added positional predicates or relations.
Length generalization guarantees
What the idealized learning framework guarantees, and what it leaves unresolved about practical training and required input lengths.
A C-RASP program specifies one computation that works at every input length. Compiling it into a transformer establishes that the computation is representable. Length generalization asks a further question: can a learner identify such a computation from its behavior on shorter inputs?
Training length and context length
To formalize this question, we must separate the lengths seen during training from the lengths the model can process. A model with context length can be tested on longer examples than it has seen, but only up to length . Success within one fixed window therefore cannot establish generalization to arbitrarily long inputs. Huang et al. (2025) address this by considering a sequence of transformers with increasing context length . For each , an idealized learner observes the target function on all inputs of length at most and selects . We ask whether, for every sufficiently large , this model also computes correctly on all unseen lengths between and .
This definition captures the idea that, once the learner has seen sufficiently long examples, its solution continues to work at greater lengths. Increasing the context window prevents the modelβs finite positional table from setting an arbitrary ceiling on the analysis, while leaving the longer inputs unseen makes extrapolation necessary. The factor of two is a convenient choice, rather than an essential assumption of the framework. Observing all inputs through the training length also isolates generalization across lengths from the separate problem of learning from a finite sample. The resulting guarantee concerns this idealized inference procedure; it does not say that one trained finite-context model can process inputs of every length.
The idealized learner
The learner must fit every input through the training length and approximately minimize a complexity regularizer. Its positional contributions must also satisfy an offset-independence restriction. This is an idealized inference procedure; ordinary gradient-based training need not satisfy these assumptions.
Formal selection rule and positional restrictions
The selection rule requires to match exactly on all inputs through the training length and to approximately minimize a particular complexity regularizer among the models that do so. This regularizer controls quantities such as depth, precision, parameter norms, and positional interactions. The width is not explicitly bounded by the hypothesis class. More precisely, let be the set of admissible models that match on all inputs of length at most , at every valid offset. The procedure selects satisfying
Why approximate minimization? An exact minimizer need not exist: the infimum may not be attained by any model in . The allowance makes approximate minimization sufficient, with an error that vanishes as grows (Huang et al., 2025, Definition 6).
A separate restriction concerns how the model uses positional information. Although the embeddings may vary across positions, the parameter products through which they contribute to the computation must be unchanged when all positions are shifted equally. This is stronger than requiring the same final prediction at every offset: the underlying computation must use positional information in the same way. For example, an interaction based on the distance between two positions survives such a shift, whereas one tied to a particular absolute position generally does not.
The main equivalence
Under the frameworkβs assumptions, Huang et al. (2025, Theorem 7) establish that the following statements are equivalent:
- Representation: The target function is representable by a limit transformer with periodic positional vectors and translation-invariant, local additional positional interactions.
- Identification with bounded complexity: Any sequence selected by the idealized inference procedure has uniformly bounded regularizer values and eventually generalizes. That is, there are constants and such that for every , and for every , matches on all inputs of length at most , despite having fitted it only through length .
The forward direction shows that such a representation guarantees eventual generalization with bounded complexity under the inference procedure. The reverse direction shows that a sequence selected by this procedure with both properties implies the existence of such a representation. Bounded regularization is part of this equivalence: eventual generalization alone is not the condition being characterized.
The procedure itself requires approximate minimization of the regularizer, rather than a prescribed uniform bound . When the representation in the first statement exists, the theorem guarantees that the selected sequence remains uniformly bounded.
Intuition: eliminating incorrect candidate algorithms
Why is this possible? Under the theoremβs assumptions, bounded complexity leaves only finitely many candidate underlying algorithms. Any incorrect candidate disagrees with on some finite input. As the training length increases, that input eventually becomes visible and rules out the candidate. Once every incorrect candidate has been eliminated, the remaining algorithms agree with at every length. This is a statement about the computations identified by the learner; it does not require the parameter vectors to converge to a unique set of weights.
What follows for C-RASP?
The compilation introduced above connects directly to the main equivalence: every such program supplies a limit-transformer representation satisfying the theoremβs restrictions. Expressing a target function in therefore guarantees eventual generalization with bounded regularization under the idealized inference procedure. This is a sufficient condition; the converse claim that every such limit transformer has an equivalent C-RASP[Pos] program is not established.
How much training length is enough?
Eventual identification does not provide a practical stopping rule. Yang et al. (2026), in Length Generalization Bounds for Transformers, show that no computable bound in terms of program description size exists for general C-RASP, even at counting depth two, with a corresponding result for the transformer model considered there. This concerns the maximum input length needed to distinguish candidate programs, rather than simply the number of training examples. The same work also identifies a restricted positive fragment, , for which a computable bound does exist: the required training length is exponential in program description size, and this bound is optimal in the worst case. This fragment restricts count comparisons to nonnegative linear combinations of counts against constants. It is expressively equivalent to the paperβs fully fixed-precision transformer model, for which the authors also obtain exponential bounds.
Limitations and open questions
Directions for further exploration, including chain of thought, richer formalisms, and limitations of the transformer model.
Chain of thought
- Can CoT increase expressivity? (and how to fix this)
- C-RASP CoT
Further directions
- Open C-RASP conjecture
- Incomputable bound
- Extensions of C-RASP
- how the model differs from real transformers (e.g., precision, attention, etc.)
- Other formalisms of length generalization (RASP-L etc.)
References
The papers and other sources cited throughout the tutorial.