Computational Thinking Reasoning in Large Language Models

Kechi Zhang, Ge Li, Jia Li, Huangzhao Zhang, Jingjing Xu, Hao Zhu, Lecheng Wang, Yihong Dong, Jing Mai, Bin Gu, Zhi JinarXiv 2025 · DOI

Abstract

Modern Large Language Models (LLMs) often struggle with complex reasoning due to the linear nature of generative Chain-of-Thought (CoT) processes, where early errors propagate unchecked. We introduce the Computational Thinking Model (CTM), a framework designed to move LLMs from "thinking by talking" to "thinking by computing." By integrating a persistent Python execution environment into the reasoning loop and utilizing a novel reinforcement learning strategy (DAPO), CTM enables models to systematically decompose problems, simulate outcomes, and verify logic. Our results show that CTM-32B-RL significantly outperforms much larger models, including DeepSeek-R1-671B, on rigorous coding and mathematics benchmarks.

Introduction

While models like OpenAI’s o1 and DeepSeek-R1 have advanced the state of reasoning, they remain limited by a purely text-based generative approach. A single logical slip in a multi-step derivation often leads to an incorrect final answer because the model lacks a mechanism for formal verification. The authors argue that LLMs lack "Computational Thinking"—the fundamental toolkit used by computer scientists to manage complexity through decomposition, abstraction, and simulation.

Current models that use external tools often treat them as peripheral utilities. In contrast, CTM aims to bake these computational paradigms directly into the model's cognitive architecture, making code execution a core component of the "thought" process rather than an afterthought.

The Interactive Language-Code Reasoning Framework

The core of CTM is the Interactive Language-Code Reasoning Loop. Instead of generating a static text response, the model alternates between natural language reasoning and executable Python code blocks. These blocks are executed in a persistent sandbox environment (similar to a Jupyter notebook), and the resulting outputs—whether successful data or error messages—are immediately fed back into the model's context.

The Interactive Language-Code Reasoning Framework integrates natural language thoughts with executable code blocks.

This iterative process allows the model to treat every code block as a "self-edit checkpoint." If a code block fails or produces unexpected results, the model can backtrack and refine its strategy based on grounded feedback from the execution environment.

Training Methodology: SFT and RL with DAPO

To instill these computational habits, the researchers employed a two-phase training strategy:

  1. Cold Start Supervised Fine-Tuning (SFT): The model was first trained on a curated dataset of approximately 25,000 programming and math problems. These training traces were manually structured to follow a rigorous computational pattern: understand → plan → code → validate → refine → finalize.
  2. Reinforcement Learning (RL) with DAPO: The model was further optimized using Decouple Clip and Dynamic Sampling Policy Optimization (DAPO), a variant of Group Relative Policy Optimization (GRPO). DAPO rewards the model based on its ability to pass test cases and arrive at correct mathematical answers. This specifically encourages the model to utilize the execution environment for self-correction when it encounters errors.

Paradigms of Computational Thinking

The CTM framework enables several key cognitive shifts that distinguish it from standard reasoning models:

  • Thinking by Computing: Code execution is used to verify intermediate logic. This transforms the rare and unpredictable "Aha moment" of standard models into a systematic, programmable event triggered by execution feedback.
  • Symbolic Grounding: By utilizing libraries like sympy, CTM grounds symbolic manipulations in formal rules, preventing the "hallucinated math" common in purely generative models.
  • Decomposition and Backtracking: The RL process encourages the model to break monolithic problems into modular, testable subgoals. When a subgoal fails, the model can backtrack, a behavior rarely seen in linear CoT.
Comparison between standard natural language reasoning and the Computational Thinking Model, highlighting self-correction and symbolic grounding.

Experimental Results

CTM demonstrates that computational thinking allows smaller models to achieve performance levels typically reserved for massive parameter counts.

  • Coding Performance: On the LiveCodeBench benchmark, CTM-32B-RL achieved a score of 66.5, surpassing DeepSeek-R1-671B (65.9) and OpenAI o1-mini (53.8).
  • Mathematical Reasoning: On the AIME 2024 benchmark, CTM scored 76.6, nearly matching DeepSeek-R1 (70.0) and vastly outperforming GPT-4o (9.3).
  • Ablation Studies: The importance of the live execution environment was confirmed by ablation tests; removing code integration during inference caused performance on LiveCodeBench to drop from 66.5 to 58.5.

Conclusion and Future Work

The Computational Thinking Model represents a significant step toward more robust and verifiable AI reasoning. By grounding "thoughts" in executable code, CTM mitigates error propagation and enables systematic self-correction. Future research will focus on expanding this framework beyond Python to other programming languages and domain-specific languages, as well as optimizing the latency associated with real-time code execution. Ultimately, this paradigm could extend to multi-modal environments where models "compute" through physical or visual simulations.

Summary updated

BibTeX
@misc{zhang2025computational,
  author = {Kechi Zhang and Ge Li and Jia Li and Huangzhao Zhang and Jingjing Xu and Hao Zhu and Lecheng Wang and Jia Li and Yihong Dong and Jing Mai and Bin Gu and Zhi Jin},
  title = {{Computational Thinking Reasoning in Large Language Models}},
  year = {2025},
  eprint = {2506.02658},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.02658},
}
Figure