Not All Votes Count! Programs as Verifiers Improve Self-Consistency of Language Models for Math Reasoning

Vernon Y. H. Toh, Deepanway Ghosal, Soujanya Poria

TL;DR

The authors introduce PROVE, a simple, training-free framework that improves the mathematical accuracy of Large Language Models (LLMs) by using Python code as a verification mechanism. By translating an LLM's natural language reasoning path into an executable program, PROVE filters out flawed solutions before performing majority voting, yielding accuracy boosts of up to 18% on standard benchmarks—with the most dramatic gains seen in smaller, open-source models.

What Problem Does This Paper Address?

Multi-step mathematical reasoning is notoriously difficult for autoregressive LLMs, particularly smaller open-source variants (under 13B parameters). Because these models generate text token-by-token, a single arithmetic slip or semantic misunderstanding early in a response propagates downstream, dooming the final answer.

A popular remedy is Self-Consistency (majority voting), where the model samples multiple distinct reasoning paths, and the most common final answer is selected. However, if a model frequently succumbs to the same logical or calculation trap, vanilla majority voting will confidently select that common, incorrect answer. Existing alternatives to fix this—such as training separate verifier models or formalizing problems into complex logic languages—require heavy computational overhead, extensive fine-tuning, or advanced few-shot prompting.

Methods

The authors propose PROVE (PROgrams for VErification), a model-agnostic, zero-shot framework that introduces an automated code-execution check to filter out bad reasoning paths before answers are aggregated.

The pipeline operates in three distinct steps:

  1. Generate Plan and Solution: The LLM uses a zero-shot "Plan-and-Solve" prompt to generate a natural language plan followed by a step-by-step solution. The framework samples multiple candidate paths (typically 16).
  2. Translate to Python: Each generated natural language plan and solution is passed individually to a translation LLM (by default, the lightweight Phi-3-mini-4k-instruct), which converts the textual logic into an executable Python program.
  3. Verify and Select: The Python program is executed. If the program's output matches the final answer extracted from the natural language text, the solution is deemed valid. If they mismatch, it is filtered out. Finally, majority voting is performed only on the valid reasoning paths. If no paths pass verification, the system falls back to a standard majority vote across all sampled answers.
Figure 1: Comparison of self-consistency and PROVE.

Datasets

The framework was evaluated across eight diverse mathematical reasoning benchmarks:

  • GSM8K: Grade-school math word problems.
  • MATH-500: A 500-problem subset of the highly challenging MATH dataset, used to accelerate evaluation.
  • SVAMP, ASDIV, MultiArith, SingleEQ, SingleOP, AddSub: Standard arithmetic and math word problem datasets focusing on varying operational complexities.

Key Insights and Ideas

  • Code as a Strict Sanity Check: Natural language text can easily mask subtle arithmetic inconsistencies or logical leaps. Forcing an LLM to formalize its own text into Python code acts as a strict mathematical constraint; deterministic code execution does not suffer from the calculation "hallucinations" common to autoregressive text generation.
  • Smaller Models Benefit Most: The performance gains are inversely proportional to model size. Smaller models (1B–3B parameters) are highly prone to calculation slips but possess surprisingly robust code-generation capabilities. PROVE effectively patches their arithmetic weaknesses by offloading the math to a Python interpreter.
  • Zero-Shot & Training-Free: Unlike other verification methods that require training a separate reward model or engineering complex few-shot exemplars, PROVE works entirely out of the box with zero-shot prompting on commodity open-source models.

Key Results

The authors evaluated PROVE across 13 open-source LLMs from various model families (including Qwen-2, Gemma-2, Llama-3, and Mistral), ranging from 0.5B to 13B parameters.

  • Universal Improvements: PROVE consistently outperformed vanilla majority voting across all 13 models and all 8 datasets.
  • Substantial Accuracy Jumps: On the GSM8K dataset, the smaller Llama-2-7B-chat model achieved an absolute accuracy improvement of 18.19%. On the more rigorous MATH-500 dataset, Llama-2-13B-chat improved by 9.4%, while the tiny Qwen2-0.5B-Instruct saw an 8.20% boost.
  • Eliminating Calculation Blunders: Manual error analysis revealed that PROVE reduced calculation errors to 0% among the remaining failed cases, successfully shifting the failure modes entirely to missing steps or fundamental semantic misunderstandings.

Limitations and Future Work

  • Dependency on Translation Quality: PROVE relies heavily on the LLM's ability to accurately translate textual solutions into code. While lightweight models like Phi-3 excel at translating simpler arithmetic problems (GSM8K, SVAMP), complex datasets like MATH require a frontier model (such as GPT-4o) to handle the translation reliably.
  • Inference Overhead: Generating code and executing it for every sampled reasoning path increases computational latency and API costs compared to standard greedy decoding, though it remains competitive with other multi-sample verification techniques.

Summary updated

BibTeX
@inproceedings{toh2025not,
  author = {Vernon Y. H. Toh and Deepanway Ghosal and Soujanya Poria},
  title = {{Not All Votes Count! Programs as Verifiers Improve Self-Consistency of Language Models for Math Reasoning}},
  booktitle = {AI4MATH @ ICML},
  year = {2025},
  url = {https://openreview.net/forum?id=uw2FhekYtc},
}
Figure