C-RASP / VERSION 2
Version 2 · Experimental · Separate from main tutorial

C-RASP and length generalization

An interactive introduction to length generalization and C-RASP: length-independent programs that transformers can implement, and why that is not the same as learning to generalize.

Version 2 — drag-and-drop program editing · Does not replace the main tutorial

01 / The question Length generalization and C-RASP

A model can look accurate on short strings and fail when inputs get longer. Length generalization means: fit on lengths up to N, then stay correct on lengths beyond N.

A C-RASP program is a fixed list of assignments. Each assignment builds a vector with one entry per input position—either a yes/no (Boolean) or an integer (count). The number of lines does not depend on the input length: longer inputs only make those vectors longer. Yang and Chiang (2024) show such programs can be implemented by transformers; that is about what can be represented, not what training will find.

Keep three questions separate: representability, learning, and length generalization. Writing a C-RASP program answers only the first.

02 / What is C-RASP Programs, commands, and what “in C-RASP” means

C-RASP is a tiny programming language. A program is a fixed list of assignments. Each assignment builds a vector with one value per input position—either a yes/no (Boolean) or an integer (count). Longer inputs make those vectors longer; they do not add new lines to the program.

What “in C-RASP” means

Saying a task is in C-RASP (or C-RASP-expressible) means: there exists a C-RASP program that solves it, using only the commands below. That is a statement about representability—a transformer can implement that program. It is not a claim that training will find the program, or that a trained model will length-generalize.

The commands

Every line of a program is one of these operations (Yang & Chiang). In the tool, an input marker looks like "("; a prefix count looks like # "(".

Boolean vectors

  • Input marker — is this position token a?
  • Negation — not
  • Conjunction — and
  • Count comparison — e.g. ≤ between two counts
  • Constant — always true

Count vectors

  • Prefix count — # how often a Boolean holds so far
  • Conditional — if–then–else on counts
  • Add / subtract
  • Min / max
  • Constant — the integer 1

Shorthand such as ==, <, and 0 is derived from these primitives (e.g. equality via two ≤ checks).

How a program decides

Assignments run in order. Each line may use earlier vectors. For recognition, the program ends with a Boolean vector; the input is accepted exactly when that vector’s last position is true.

Example: Dyck-1

Correctly nested ( ) needs two conditions: (1) no prefix has more closes than opens, and (2) the string ends balanced. Both matter—())( has equal totals but already closed too many in the middle. The program below writes those conditions with prefix counts, comparisons, and &&. Step through it on ( ).

The C-RASP program · running on ( ) Guided example

This box is the program. The highlighted line is the one introduced in the current step.



              

Each row is the vector produced by one program line

03 / Try it yourself Run the interpreter

Pick an example, set the input, then Run. The program view highlights the active line and names the C-RASP command it uses. Edit only if you want—use the pencil.

C-RASP notebook Executable program · Python interpreter
Input tokens

Whitespace-separated tokens (parentheses may be typed without spaces). 1–128 tokens.

Program

                  
                

Pinned coli-saar/c-rasp interpreter · positions start at 0

Nothing has run yet. Press play to fill this area with the execution trace.