NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

On Code-Induced Reasoning in LLMs

Abdul Waheed, Zhen Wu, Carolyn Rose, Daphne Ippolito

TL;DR

While it is well-known that training on code boosts a Large Language Model's (LLM) reasoning skills, the exact reasons for this improvement have remained elusive. This paper systematically deconstructs code data through 3,331 experiments, revealing that the structural scaffolding of code is far more important for reasoning than its semantic content or specific syntax.

What Problem Does This Paper Address?

Researchers have frequently observed a "transfer" effect where models trained on programming languages become better at unrelated tasks, such as solving math word problems or logic puzzles. The common hypothesis is that code’s logical consistency and compositional structure provide a superior "thinking" signal.

However, "code" is a complex bundle of many features: strict syntax, meaningful variable names, helpful comments, and specific indentation. Until now, we lacked a causal understanding of which of these specific properties drive reasoning improvements. Is it the "if-then" logic, or just the fact that code is less ambiguous than English? This paper aims to isolate these variables to inform better training data design.

Methods

The authors developed a systematic, data-centric framework consisting of three main stages:

Framework Overview
  1. Parallel Dataset Construction: They created a massive dataset of 120,000 instruction-response pairs. Using GPT-4o-mini, they generated parallel responses for the same instructions across ten different programming languages (from Python to Rust) and natural language.
  2. Controlled Perturbations: To isolate what matters, they "broke" the code in specific ways:
  3. Rule-based: Stripping whitespace, renaming variables to generic placeholders (var_1), replacing keywords with nonsense, or shuffling comments.
  4. Generative: Using a model to rewrite code into pseudocode, Mermaid flowcharts, "imaginary" languages, or step-by-step prose.
  5. Large-Scale Fine-Tuning: They fine-tuned 14 different model bases (from families like Qwen, LLaMA, and Gemma) across eight scales (0.6B to 8B parameters) on these variants to see how each "flavor" of data affected downstream performance in math, code, and general knowledge.

Datasets

  • Code Instructions: Aggregated from high-quality sources including Codeforces-CoT, Evol-Instruct-Code-80k, and Code-Instruct-Alpaca.
  • Natural Language Instructions: Sampled from OpenHermes 2.5 (filtering out coding-specific tasks to ensure a "pure" NL baseline).
  • Evaluation Suite: Included PIQA (commonsense), ARC (science), GSM8K/MATH (math), and HumanEvalX (code).

Key Insights and Ideas

  • Structure Trumps Semantics: Models are much more sensitive to "structural" changes (like removing whitespace or changing control flow) than "semantic" ones (like renaming variables or deleting comments). This suggests LLMs learn the pattern of logic rather than the meaning of the words used in the code.
  • Abstractions are Sufficient: You don't actually need "runnable" code to teach reasoning. High-level abstractions like pseudocode and flowcharts were often just as effective as actual code. They provide the same logical skeleton with fewer "noisy" tokens.
  • The "Efficiency" of Code: The benefit of code doesn't come from its verbosity. In fact, variants that encoded the same information with fewer tokens (higher information density) often maintained or even improved reasoning performance.
  • Robustness to Corruption: Surprisingly, models could still learn to reason from "corrupted" code (e.g., code with misleading comments or nonsense keywords) as long as the underlying structural regularities remained intact.
  • Language Matters for Specific Tasks: Not all programming languages are equal. Python training favored natural language reasoning (likely due to its proximity to English), while lower-level languages like Java and Rust provided stronger signals for mathematical tasks.

Key Results

Across 14 model bases, fine-tuning on code (code-ft) or a mix of code and NL achieved the best performance on the vast majority of math and code understanding tasks.

Performance across domains
  • Performance Gains: Code fine-tuning consistently outperformed natural language fine-tuning (nl-ft) and zero-shot baselines, particularly in Math and Code Generation.
  • Structural Vulnerability: In math tasks, structural perturbations caused significantly steeper performance drops compared to semantic perturbations. For example, in Qwen-4B, structural changes dropped math scores by nearly 10% more than semantic changes.
  • Human Interpretability vs. Model Learning: There is a disconnect between what humans find readable and what models find useful. "Low-interpretability" code (with nonsense keywords) often performed as well as "medium-interpretability" code, suggesting models exploit surface-level patterns that humans find confusing.

Limitations and Future Work

  • Model Scale: The study focused on small-to-mid-size models (up to 8B parameters). It remains to be seen if the same structural dependencies hold for "frontier" models (100B+ parameters).
  • Benchmark Breadth: While the task suite was diverse, it only captures a portion of the "reasoning" spectrum. Future work could explore more complex multi-step reasoning like Chain-of-Thought optimization.
  • Data Diversity: The perturbations, while systematic, do not cover every possible way code can be modified (e.g., varying algorithmic complexity).

The authors suggest that future training data shouldn't just focus on "more code," but on structurally rich data—even if that data takes the form of flowcharts or dense pseudocode rather than executable scripts.

Summary updated

BibTeX
@inproceedings{waheed2026code,
  author = {Abdul Waheed and Zhen Wu and Carolyn Rose and Daphne Ippolito},
  title = {{On Code-Induced Reasoning in LLMs}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=LIv0bfJZIi},
}
Figure