Search papers, labs, and topics across Lattice.
This paper introduces source code algebra as a novel approach to modifying codebases through logical algebraic operations instead of traditional text editing. By applying these operations, which encapsulate the necessary semantic changes, the authors demonstrate that LLM-based coding agents can achieve non-local, cross-file code modifications with significantly higher success rates and reduced token usage compared to text-based methods. The findings suggest that algebraic manipulation could streamline the coding process, reducing the cognitive load on LLMs and enhancing their efficiency in code editing tasks.
LLM agents can achieve cross-file code changes with one to two orders of magnitude fewer tokens by leveraging algebraic operations instead of plain text edits.
Source code is almost universally edited as plain text. However, the mismatch between the syntactic and semantic requirements of valid and correct code, and the unconstrained text editing process trying to produce it, introduces friction that degrades the programming task. It is also increasingly costly in the era of LLM-based coding agents, which must materialize their high-level plan of intended changes as low-level text edits dispersed throughout the codebase, often requiring them to re-read large portions of code. We propose the novel alternative approach of source code algebra, where the codebase is modified by applying to it a sequence of logical algebraic operations. Each operation makes the full set of changes necessary for a single semantic change, analogous to mathematical equation rewriting. We sketch initial properties of such operations - including composition, nullipotency, and commutativity - that distinguish this approach from text editing, and make it well-suited as a substrate for agentic code editing. A feasibility probe with our proof-of-concept implementation (SCAS) suggests that LLM agents can use source code algebra to complete a non-local, cross-file code change with both higher success rates and one to two orders of magnitude fewer tokens, relative to text-based baselines. While preliminary, this is consistent with the hypothesis that having LLMs emit algebraic operations, rather than rewritten code, is a promising direction for code editing - and motivates broader future research into source code algebra, such as comprehensive operator libraries, formal properties, and human-facing tooling.