Beyond Text Editing: Algebraic Manipulation of Source Code

📅 2026-07-21
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Traditional text-based code editing struggles to satisfy syntactic and semantic constraints, leading to inefficient performance by large language model (LLM) agents when performing cross-file or non-local modifications. This work proposes Source Code Algebra (SCA), a novel framework that introduces compositional, idempotent, and commutative algebraic operations into code editing, replacing character-level edits with semantically complete atomic operations. Built upon abstract syntax trees, SCA defines semantics-aware edit primitives and formally models their algebraic properties, integrating them into an LLM interface. Experimental evaluation of the prototype system SCAS demonstrates that this paradigm significantly improves modification success rates while reducing communication token overhead by one to two orders of magnitude, highlighting its potential as an efficient and accurate new approach to code editing.
📝 Abstract
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.
Problem

Research questions and friction points this paper is trying to address.

source code editing
text editing
semantic mismatch
LLM-based coding agents
code manipulation
Innovation

Methods, ideas, or system contributions that make the work stand out.

source code algebra
algebraic operations
LLM-based coding agents
semantic code editing
non-local code changes
🔎 Similar Papers
No similar papers found.