Coding Triangle: How Does Large Language Model Understand Code?

Taolin Zhang, Zihan Ma, Maosong Cao, Junnan Liu, Songyang Zhang, Kai Chen · DOI

Introduction

As Large Language Models (LLMs) like DeepSeek-V3 and OpenAI’s o3 achieve state-of-the-art performance on coding benchmarks, researchers are increasingly questioning whether these models possess true logical understanding or are merely sophisticated pattern matchers. Traditional evaluation metrics, such as "Pass@1" accuracy, focus narrowly on whether a model can produce executable code that passes hidden tests. However, human programming is a multi-faceted cognitive process involving problem analysis, implementation, and rigorous validation. To address this gap, we introduce the Coding Triangle, a holistic framework designed to evaluate LLMs across three interconnected dimensions: natural language analysis (Editorial), implementation (Code), and validation (Cases).

The Coding Triangle Framework

The Coding Triangle framework decomposes programming ability into three distinct vertices to observe how logic flows—or fails—between them.

  1. Editorial: The model generates a natural language explanation of the problem and the intended algorithmic strategy.
  2. Code: The model produces the actual implementation, typically in a high-level language like C++.
  3. Cases: The model generates diverse test inputs and outputs to validate the correctness of solutions.
The Coding Triangle framework evaluates models across Editorial, Code, and Case generation, bridging the gap between natural language reasoning and executable logic.

By systematically "bridging the edges" of this triangle—for instance, testing if a model can use its own editorial to debug its code—researchers can identify where the chain of reasoning breaks down. This approach reveals whether a model's internal logic is consistent across different modes of expression.

Methodology and Evaluation

The study utilized a curated dataset of 200 problems from the AtCoder Beginner Contest (ABC), spanning problems A (easiest) through F (hardest). The evaluation included leading models such as DeepSeek-V3, Qwen2.5-72B-Instruct, and the reasoning-focused QwQ-32B.

To assess the quality of non-executable outputs, the researchers employed LLM-as-a-Judge (using OpenAI’s o3-mini) to score model editorials against human-written ground truths. Furthermore, the study compared AI error patterns against a vast database of human submissions to identify "distribution shifts" in how different agents fail.

Key Insights: The Cognitive Gap and Self-Consistency

The "Self-Consistency Trap"

A primary finding is that LLMs are remarkably self-consistent, but often to their own detriment. If a model develops a flawed understanding of a problem, that error propagates through its editorial, its code, and its test cases. This leads to a phenomenon known as "reward hacking," where a model’s code passes its own self-generated test cases even when the implementation is objectively incorrect. Unlike humans, whose mistakes are diverse and creative, LLM errors tend to cluster together, suggesting shared biases in training data.

The Performance Gap

There is a persistent "cognitive gap" (often 0–20%) between a model's ability to explain a problem in natural language and its ability to implement it in code. Models frequently "know" the correct approach in English but fail the translation into executable logic.

Performance of QwQ-32B across problem difficulties (A-F). While Editorial and Code scores decline with difficulty, Case generation accuracy shows a unique "rebound" on the hardest algorithmic problems.

As shown in the performance analysis of QwQ-32B, the accuracy for Editorial and Code generation declines as problem difficulty increases. Interestingly, case generation accuracy often "rebounds" on the hardest problems (E and F). On these problems, the challenge is purely algorithmic; the logic becomes binary—either the model understands the complex algorithm required, or it does not—reducing the ambiguity often found in "medium" difficulty edge cases.

Results and Discussion

  • Human Knowledge as a Catalyst: Providing models with human-written editorials significantly boosted coding performance. Conversely, providing models with their own self-generated editorials offered negligible improvement, suggesting models are already operating at the limit of their internal reasoning.
  • Model Mixtures: Combining outputs (cases or code) from different model families (e.g., DeepSeek and Qwen) improved robustness. The diversity of a "model mixture" helps cover the specific cognitive blind spots inherent to any single architecture.
  • The Judging Paradox: Reasoning models like QwQ-32B are often better at judging the correctness of a solution than they are at writing one. This "self-inconsistency" presents a unique opportunity for training: if a model can recognize its own mistakes, it can potentially be fine-tuned to self-correct.

Conclusion

The Coding Triangle reveals that while LLMs are powerful, their understanding is often brittle and prone to logical loops. The gap between judging and implementation suggests that future research should focus on iterative alignment between these three dimensions. By developing models that can truly "self-reflect" and cross-reference their code against their own logical editorials, we move closer to AI that understands programming as a holistic discipline rather than a sequence of patterns.

Summary updated

BibTeX
@misc{zhang2025coding,
  author = {Taolin Zhang and Zihan Ma and Maosong Cao and Junnan Liu and Songyang Zhang and Kai Chen},
  title = {{Coding Triangle: How Does Large Language Model Understand Code?}},
  year = {2025},
  eprint = {2507.06138},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.06138},
}
Figure