Code-driven Number Sequence Calculation: Enhancing the inductive Reasoning Abilities of Large Language Models

Kedi Chen, Zhikai Lei, Xu Guo, Xuecheng Wu, Siyuan Zeng, Jianghao Yin, Yinqi Zhang, Qin Chen, Jie Zhou, Liang He, Qipeng Guo, Kai Chen, Wei Zhang · OpenReview

Abstract

Large language models (LLMs) make remarkable progress in reasoning tasks. Among different reasoning modes, inductive reasoning, due to its better alignment with human learning, attracts increasing interest. However, research on inductive reasoning faces certain challenges. First, existing inductive data mostly focuses on superficial regularities while lacking more complex internal patterns. Second, current works merely prompt LLMs or finetune on simple prompt-response pairs, but do not provide precise thinking processes nor implement difficulty control. Unlike previous work, we address these challenges by introducing CodeSeq, a synthetic post-training dataset built from number sequences. We package number sequences into algorithmic problems to discover their general terms, defining a general term generation (GTG) task correspondingly. Our pipeline generates supervised finetuning data by reflecting on failed test cases and incorporating iterative corrections, thereby teaching LLMs to learn autonomous case generation and self-checking. Additionally, it leverages reinforcement learning with a novel Case-Synergy Solvability Scaling Reward based on both solvability, estimated from the problem pass rate, and the success rate of self-directed case generation, enabling models to learn more effectively from both successes and failures. Experimental results show that the models trained with CodeSeq improve on various reasoning tasks and can preserve the models' OOD performance.

Introduction

While LLMs have achieved significant success in deductive reasoning—applying general rules to specific instances—they often struggle with inductive reasoning, the process of discovering general rules from specific observations. Current research in inductive reasoning is hampered by simplistic datasets that focus on visual or structural patterns rather than deep logical structures. Furthermore, training often lacks a structured "thinking process" or rigorous difficulty control.

To address this, we propose using number sequences (e.g., from the OEIS) as a foundation for inductive reasoning. These sequences contain deep mathematical logic that is difficult to express in natural language but can be precisely captured through code. By framing the search for a sequence's general term as an algorithmic problem, we provide a verifiable and executable framework for inductive reasoning.

Figure 1: The process of converting a number sequence into an algorithmic problem and a verifiable code solution.

The CodeSeq Pipeline

The CodeSeq dataset is constructed through a three-stage pipeline designed to teach models how to induce rules and verify their own hypotheses.

1. Sequence Algorithmization

We scrape thousands of sequences from sources like the OEIS and Project Euler. A "working agent" (LLM) transforms these sequences into algorithmic problems with story-based descriptions. A "guiding agent" then validates the logic to ensure the problem description accurately reflects the sequence's mathematical properties.

2. Case-based Reflection Injection (SFT)

To move beyond simple input-output pairs, we generate Supervised Fine-Tuning (SFT) data that includes a "reflection-correction" loop. In this process, the model attempts a solution, identifies failures against test cases, reflects on the error, and iteratively corrects its code. This embeds a self-correcting Chain-of-Thought (CoT) directly into the model's reasoning process.

3. Solvability-Estimated Selection (RL)

For Reinforcement Learning, we employ Group Relative Policy Optimization (GRPO) with a unique reward function: the Case-Synergy Solvability Scaling Reward (CSSR). This reward scales based on problem difficulty (estimated via pass rates) and the model's success in generating its own autonomous test cases. This encourages the model to find the "Goldilocks" zone of difficulty—moderately hard problems where the most learning occurs.

Figure 5: The complete CodeSeq pipeline, illustrating sequence algorithmization, reflection-based SFT, and solvability-estimated RL.

Experimental Results

Our experiments demonstrate that training on CodeSeq significantly boosts performance across several benchmarks, particularly for smaller models:

  • General Term Generation (GTG): LLaMA3-8B’s performance on this in-domain task jumped from 9.27% to 44.22%, while Qwen2.5-7B rose from 26.89% to 69.55%. These models outperformed much larger counterparts, such as InternLM2.5-20B and DeepSeek-R1-32B.
  • Cross-Domain Transfer: Training on inductive sequence tasks improved performance on standard deductive coding benchmarks like HumanEval and MBPP.
  • Robustness: CodeSeq maintains or slightly improves performance on out-of-domain (OOD) tasks like MMLU and Big Bench Hard (BBH), avoiding the "catastrophic forgetting" often seen with synthetic fine-tuning.

Conclusion

CodeSeq demonstrates that code is a powerful language for inductive reasoning. By leveraging the precision of programming and a structured reflection-correction training loop, we can significantly enhance the ability of LLMs to discover complex logical patterns. Future work will explore expanding this code-driven approach to multimodal data and other scientific domains.

Summary updated

BibTeX
@misc{chen2025code,
  author = {Kedi Chen and Zhikai Lei and Xu Guo and Xuecheng Wu and Siyuan Zeng and Jianghao Yin and Yinqi Zhang and Qin Chen and Jie Zhou and Liang He and Qipeng Guo and Kai Chen and Wei Zhang},
  title = {{Code-driven Number Sequence Calculation: Enhancing the inductive Reasoning Abilities of Large Language Models}},
  year = {2025},
  eprint = {2510.14620},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.14620},
}
Figure