Manuscript Offprint

arXiv:2610.19238

LLMs program using Reusable and Composable Abstract Representations

Casper L. Christensen, Kyle J. Ray, Dmitry Manning-Coe, Adam Shai, Paul Riechers

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

Casper L. Christensen ∗^{*}

Simplex

Astera Institute

Kyle J. Ray

Simplex

Astera Institute

Dmitry Manning-Coe

MATS

University of Illinois at Urbana-Champaign

Adam Shai

Simplex

Astera Institute

Paul Riechers

Simplex

Astera Institute

ABSTRACT

When writing code, the same computation can be expressed in different programming languages and through different implementation strategies. We show that the activations of LLMs capture this shared structure in reusable and composable abstract representations when they generate code. These representations emerge in the middle layers, are reusable across programming languages, and afford the model an impressive amount of generalization ability when generating code under various interventions. Using activation steering, we show that function, programming language, and implementation strategy can be independently manipulated. The independent interventions on language and function can be flexibly composed to control code generation, even in cases when the prompt contains no information about language and function. We additionally find that finetuning on examples of arbitrarily defined functions in one programming language transfers to other languages, consistent with the models reusing abstract features of code generation that are shared across different examples. Finally, to study how such abstract representations come to be, we implement a minimal model of shared, reusable, and composable structure in a synthetic setting, and show that transformers trained on such data learn representations that reuse these parts flexibly across contexts.

1 INTRODUCTION

Programming repeatedly combines familiar computations with different languages and implementation choices. A graph search, for example, can recur across programs with different syntax, control flow, and data structures. A competent programmer can recognize what these implementations share, and reason about the abstract computation, separately from the details of its realization. This allows knowledge acquired in one setting to support programming in another; understanding a graph-search algorithm in Python can help a programmer implement it in Java, even when the implementation requires different language constructs and data structures. Rather than learning every realization independently, programmers can reuse their understanding of the computation while adapting its implementation to the setting. In this work, we show that coding models also learn such abstractions from the shared computational structure of program data. These representations are built from reusable contributions that decompose into (i) what a program computes, (ii) the language in which it is expressed, and (iii) its implementation strategy.

Our work builds on the Factored World Hypothesis (FWH), which proposes that predictive models can represent independent parts of a data-generating process in separable latent state spaces (Shai et al., 2026). Here, we extend the theoretical framework to training data from multiple sources (Ray et al., 2026) that share computational parts. When training data from different sources contain shared mechanisms, we anticipate and find the emergence of reusable factored representations. That is, representations that track information about the shared mechanism abstractly and

*Correspondence: casper.lutzhoft@gmail.com a Additive, reusable factors

Figure

b Estimate an edit

c Compose edits

Figure

Figure 1: Abstract representations enable control and generalization in programming. (a): The factored world hypothesis motivates additive activation states; when multiple factored sources reuse the same mechanism, a reusable representation avoids redundancy. (b,c): Testing composability and reusability of coding representations. In (b), we find a steering vector for a fixed function without ever asking the model to output Haskell code (separately, we also find a steering vector for Haskell, without ever asking the model to implement the target function.) In (c) we use both steers at once to implement the target function in Haskell.

separately from information about the source-specific components. Representations that leverage such abstractions are more dimensionally efficient at no predictive cost, because the joint representation can be fully recovered from the two marginals: one over the shared mechanism and one over the remaining mixture.

In the following, we ask whether a model's activation state Z (i.e., the residual stream in a transformer (Vaswani et al., 2017), or the hidden state in a recurrent neural network) learns to exploit this kind of shared structure. We test reuse directly in open-source coding models' internal representations. To begin, we find that when a programming instruction is put into context, the most performant models retain an internal state that supports code generation, even after direct access to the specification is removed. This compiler-like representation gives us an internal target of study.

Through this compiled state, we ask whether the model represents a function it's been asked to implement separately from the programming language in which it's been asked to write. Our contributions are as follows:

  1. Coding LLMs create a compiled program state representation. Across 26 instruction-tuned models, the strongest coders keep enough task information at a shared suffix to write correct code after the specification is masked (Section 3.1).

  2. LLMs represent function, language, and strategy as reusable, composable components. Interventions estimated only from other languages (a) transport, (b) install, and (c) compose (i) function, (ii) language, and (iii) strategy in three LLMs and a modern RNN (Section 4.1).

  3. Training on data with shared mechanisms produces reusable representations. In a controlled synthetic setting, next-token prediction on data whose sources share a mechanism suffices to produce reusable, composable structure (Section 4.2).

  4. Reusable abstractions let models generalize across languages. State from a single in-context example transfers across languages, and Python-only fine-tuning on invented algorithms transfers to held-out languages (Section 5).

Code to reproduce all experiments is available at https://github.com/Astera-org/code-abstractions.

References (34)