Overview
Step-by-Step Coding (SBSC) is a multi-turn reasoning framework designed to enable Large Language Models (LLMs) to solve elite-level mathematical problems by decomposing them into a sequence of executable programs. By iteratively generating sub-tasks and leveraging code execution outputs to inform subsequent steps, SBSC achieves state-of-the-art performance on rigorous benchmarks like AIME and AMC, significantly outperforming traditional "single-block" code generation methods.
The Challenge of Olympiad Mathematics
While LLMs have become proficient at high-school level mathematics, Mathematical Olympiad problems (such as those in the AIME or AMC) remain a significant hurdle. Current state-of-the-art strategies generally fall into two categories: Chain-of-Thought (CoT), which utilizes natural language steps, and Program-Aided/Tool-Integrated Reasoning (PAL/ToRA), which generates a single Python script to solve the entire problem.
The authors argue that these "one-shot" coding approaches are too rigid for complex problems. A single large code block is prone to overlooking constraints, failing on edge cases, or becoming impossible for the model to debug if a logic error occurs mid-script. Humans do not solve Olympiad problems in one giant leap; they explore intermediate concepts, verify results, and adjust their strategy dynamically. SBSC aims to bring this granular, iterative approach to LLMs.
Methodology: The SBSC Framework
SBSC introduces a multi-turn, code-generation-based prompting strategy. Instead of asking the model for the final answer in one go, the process follows an iterative loop:
- Sub-task Generation: The model identifies a logical intermediate sub-task or concept to explore.
- Program Generation: The model writes a specific Python snippet to solve only that sub-task.
- Execution & Feedback: A code interpreter executes the snippet.
- State Update: The output (variables, values, or errors) is appended to the conversation history.
- Iteration: The model uses the accumulated knowledge to define and solve the next sub-task.
This continues until the model generates a specific stop-word (###END OF CODE). Crucially, SBSC encourages code rectification: if a snippet returns an error, the model is instructed to fix that specific step rather than restarting the entire problem.
Evaluation and Key Results
The authors evaluated SBSC across several prestigious mathematical benchmarks, including AIME & AMC12, MathOdyssey, OlympiadBench, JEE-Bench, and OmniMATH. SBSC demonstrated substantial improvements over existing SOTA methods:
- Claude-3.5-Sonnet: Using greedy decoding, SBSC outperformed ToRA by an absolute 10.7% on AMC12, 8% on AIME, and 12.6% on MathOdyssey.
- JEE-Bench: SBSC achieved 62.24% accuracy with Claude-3.5-Sonnet, compared to ToRA’s 45.92%.
- Open Source Success: The framework also worked well with open-source models like DeepSeekCoder V2.5, showing a 3.94% gain on AIME over ToRA.
Remarkably, SBSC using simple greedy decoding (taking the first answer) often outperformed the self-consistency (majority vote @ 7) results of other methods.
Insights and Discussion
- Dynamic Discovery: Unlike "Least-to-Most" prompting, which plans all sub-problems upfront, SBSC allows the model to discover the next step after seeing the results of the previous one. This is vital for problems where the path forward depends on a calculated value.
- Granular Debugging: SBSC is much better at recovering from errors. Because the code blocks are small, the "error surface" is reduced, making it easier for the model to identify and fix a specific bug without losing the logic of the entire solution.
- Coding Capability Correlation: There is a strong positive correlation between an LLM’s general coding ability (measured by LiveCodeBench) and its performance gains using SBSC.
Limitations and Future Work
- Token Cost: SBSC is more expensive than single-turn methods, using roughly 3x to 6x more tokens due to multi-turn overhead and repeated context.
- Geometry Struggles: While SBSC dominates in Algebra and Number Theory, it still struggles with Geometry, likely due to the inherent difficulty LLMs have with spatial reasoning.
- Future Directions: SBSC trajectories could be used as high-quality data for Supervised Fine-Tuning (SFT) or to train Outcome-Supervised Value Models to further improve mathematical reasoning.
Summary updated