MathCoder: Seamless Code Integration in LLMs for Enhanced Mathematical Reasoning

Ke Wang, Houxing Ren, Aojun Zhou, Zimu Lu, Sichun Luo +5 more
2/12/2026

Official code: mathllm/MathCoder (340 stars, Apache-2.0, last commit 2025-10-18).

Abstract

The recently released GPT-4 Code Interpreter has demonstrated remarkable proficiency in solving challenging math problems, primarily attributed to its ability to seamlessly reason with natural language, generate code, execute code, and continue reasoning based on the execution output. In this paper, we present a method to fine-tune open-source language models, enabling them to use code for modeling and deriving math equations and, consequently, enhancing their mathematical reasoning abilities. We propose a method of generating novel and high-quality datasets with math problems and their code-based solutions, referred to as MathCodeInstruct. Each solution interleaves natural language, code, and execution results. We also introduce a customized supervised fine-tuning and inference approach. This approach yields the MathCoder models, a family of models capable of generating code-based solutions for solving challenging math problems. Impressively, the MathCoder models achieve state-of-the-art scores among open-source LLMs on the MATH (45.2%) and GSM8K (83.9%) datasets, substantially outperforming other open-source alternatives. Notably, the MathCoder model not only surpasses ChatGPT-3.5 and PaLM-2 on GSM8K and MATH but also outperforms GPT-4 on the competition-level MATH dataset. The dataset and models will be released at https://github.com/mathllm/MathCoder.

View on arXivView PDF

Code Implementations(1)

mathllm/MathCoderOfficial100%
Apache-2.0

[MathCoder, MathCoder-VL] Family of LLMs/LMMs for mathematical reasoning.

34026Shell, PythonSep 20, 20231 years agoApache-2.0

Similar Papers

Cite this paper

@article{wang2026mathcoder,
  title  = {MathCoder: Seamless Code Integration in LLMs for Enhanced Mathematical Reasoning},
  author = {Ke Wang and Houxing Ren and Aojun Zhou and Zimu Lu and Sichun Luo and Weikang Shi and Renrui Zhang and Linqi Song and Mingjie Zhan and Hongsheng Li},
  year   = {2026},
  eprint = {2310.03731},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/pdf/2310.03731},
  journal = {ICLR 2023 2023}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2310.03731.svg)](https://codeofpaper.com/paper/2310.03731)

Discussion