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 ( ).
( )
Guided example
This box is the program. The highlighted line is the one introduced in the current step.
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.
Whitespace-separated tokens (parentheses may be typed without spaces). 1–128 tokens.
Three columns: pick a command, build your program, watch the view update as text. Drag left → middle (or click a command to append). Use ← → to undo/redo, restore for the initial program, then Commit to check it is well-formed and leave the builder.
Drag into Your program →
Also in C-RASP (Advanced text): + - min/max, if–then–else.
Commit checks syntax and that the interpreter can evaluate the program on the current input (last line must be Boolean).
Advanced: edit as text
Pinned coli-saar/c-rasp interpreter · positions start at 0