Compositional Hardness of Code in Large Language Models - A Probabilistic Perspective

Yotam Wolf, Binyamin Rothberg, Dorin Shteyman, Amnon Shashua · DOI

Introduction

While Large Language Models (LLMs) have demonstrated remarkable capabilities in solving complex problems through Chain-of-Thought (CoT) prompting, their performance often degrades significantly as the complexity of coding tasks increases. Traditional explanations frequently point to technical "context window" limitations. However, this paper identifies a more fundamental architectural bottleneck: Screening.

We introduce the concept of Compositional Hardness, a theoretical framework demonstrating that LLMs face an exponential "tax" when attempting to solve multiple sub-tasks within a single context window. By modeling LLM generation as a noisy probabilistic process, we show that the latent representations of previous sub-tasks act as interference, making it mathematically more efficient to distribute tasks across a multi-agent system than to rely on a single long context.

Theoretical Framework: Generation Complexity and Noise

The authors define a new metric, Generation Complexity ($N$), representing the expected number of samples required to obtain at least one correct solution. To understand why $N$ increases disproportionately in composite tasks, the paper models the LLM as an autoregressive generator where "irrelevant" context—tokens from previous, completed sub-tasks—injects symmetric noise into the logits before the final softmax layer.

The Screening Assumption

This model relies on the "Screening" assumption: when multiple semantically distinct but grammatically similar problems (e.g., two different Python functions) coexist in the same context, the model's internal representations become cluttered. This noise reduces the probability of selecting the correct next token, even if the model technically "knows" the solution to each individual part.

The Compositional Hardness Theorem

The core contribution is a mathematical proof (Theorem 1) showing that the generation complexity of a composite problem ($A \circ B$) is not merely the sum of its parts. Instead, it is at least the product of the sub-tasks' individual complexities, multiplied by an exponential factor related to the length of the solution:

$$N(A \circ B) \geq N(A) \cdot N(B) \cdot e^{\lambda L}$$

where $L$ is the length of the generated code and $\lambda$ represents the noise coefficient. This suggests that the difficulty of composing solutions grows exponentially with the number of tokens required.

Experimental Methodology

To validate this theory, the researchers utilized two primary benchmarks:

  1. HumanEval: Standard basic Python coding tasks.
  2. Code Contests: Advanced competitive programming problems.

To measure composition specifically, the authors created synthetic composite problems. For instance, a model might be tasked with solving two independent HumanEval problems and then performing a simple operation on their outputs. This setup allowed for a direct comparison between solving "A and B together" in a single context versus solving "A" and "B" independently in parallel.

Key Insights and Results

The Composition Gap

Empirical testing with Llama-3-8B revealed a stark "Composition Gap." Solving two problems within a single context often required 10 to 20 times more samples to find a correct solution compared to independent solving. Even the more capable Llama-3-70B exhibited this exponential hardness as task complexity scaled (e.g., moving from two to four composed tasks).

Effective vs. Technical Context Length

The research suggests a distinction between a model's technical context length (e.g., 128k tokens) and its effective context length. While a model can technically process a massive amount of data, the "noise" from those tokens significantly degrades the quality of complex code generation long before the technical limit is reached.

Validation of Exponential Decay

Experimental data confirmed the theoretical predictions: the log-ratio of success versus code length showed a clear linear trend. This confirms that the probability of success drops exponentially as the length of the composed code increases, validating the screening model.

Discussion: Why Multi-Agent Systems Win

The findings provide a mathematical justification for the success of multi-agent architectures. By distributing sub-tasks to different LLM instances, the system effectively "resets" the noise. Each agent begins with a clean context, avoiding the exponential penalty of composition. While multi-agent systems introduce their own challenges—such as ensuring coherence between agents—they bypass the fundamental probabilistic bottleneck of single-context screening.

Conclusion

Compositional Hardness represents a significant hurdle for scaling LLM performance on complex, multi-step engineering tasks. The realization that context acts as a source of interference rather than just a memory buffer suggests that future improvements in LLM utility may come not from larger context windows, but from better noise-mitigation strategies or more sophisticated multi-agent orchestration.

Summary updated

BibTeX
@misc{wolf2024compositional,
  author = {Yotam Wolf and Binyamin Rothberg and Dorin Shteyman and Amnon Shashua},
  title = {{Compositional Hardness of Code in Large Language Models - A Probabilistic Perspective}},
  year = {2024},
  eprint = {2409.18028},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2409.18028},
}
Figure