Evaluating Mathematical Reasoning in Large Language Models: A Reproducible Methodology
Evaluating mathematical reasoning in large language models is harder than exact-match scoring suggests. This article presents a reproducible methodology: define the target capability, build and decontaminate a tiered item bank, normalize answers and check equivalence, score derivations when needed, run repeated evaluations, and analyze confidence intervals, consistency, error types, and difficulty distribution. It also includes an illustrative evaluation script and practical guidance for integrating regression testing into model and prompt iteration.
1. Why Mathematical Reasoning Evaluation Is Difficult
Mathematical answers are usually deterministic, which makes them appear well suited to automated evaluation. In practice, there are three main difficulties.
First, the same problem may have multiple correct solutions. The final answer can be the same while intermediate steps differ greatly, so simple string comparison can produce false judgments.
Second, model outputs are affected by sampling parameters, prompt format, and context length. The same model may produce different results across two runs.
Third, public problem sets may already be present in training data. A high score does not necessarily indicate reasoning ability; it may simply reflect memorization of the problems.
A trustworthy evaluation methodology therefore needs to answer three questions at the same time: what capability is being measured, whether the items are clean, and whether scoring is reliable.
2. Define the Evaluation Goal First
Before evaluation, the goal should be stated clearly; otherwise, the results cannot be interpreted. Common goals fall into four categories:
- Calculation ability: accuracy on multi-digit arithmetic, algebraic simplification, and numerical computation.
- Proof and derivation ability: producing a complete chain of argument and checking whether each step holds.
- Problem modeling ability: converting word problems into equations or constraints.
- Tool collaboration ability: when calculation tools are allowed, whether the model can correctly decompose subtasks and integrate the results.
Each goal corresponds to different item types and scoring methods. If they are mixed into a single total score, the conclusions are often difficult to explain.
3. Item Construction and Decontamination
Item sources fall roughly into three categories: self-authored items, adapted items, and public competition problems. Self-authored items are the most controllable and are suitable for regression testing. Adapted items modify numbers, conditions, or question phrasing in existing problems, which can reduce interference from memorization. Public competition problems are difficult and discriminative, but they must be checked for whether they have already appeared in training data.
A recommended process for building an item bank is as follows:
- Stratify by difficulty, for example basic, medium, and hard. Aim for at least 100 items per tier so that reliable confidence intervals can be calculated.
- Record the source, gold answer, and knowledge point for each item to support later attribution.
- Perform decontamination checks on public items. Rewrite the item, retest, and compare the accuracy gap between the original and rewritten versions. A clear gap suggests a memorization effect.
- Keep a portion of the item bank private, not publicly released, for periodic validation only.
4. Answer Judging Methods
Answer judging can be divided into three layers.
The first layer is final-answer checking. Normalize the answer into a standard form, such as reducing fractions, simplifying radicals, and unifying units, then perform exact comparison. For numeric items, an error threshold can be set, but the threshold must be stated in the item instructions.
The second layer is equivalence checking. For algebraic expressions, subtract the candidate answer from the gold answer and use a symbolic simplification tool to determine whether the difference is zero. For sets or intervals, compare endpoints and whether they are open or closed.
The third layer is process scoring. For proof problems or long derivations, assign step scores and check whether key conclusions hold and whether steps are skipped or reasoning is circular. Process scoring is costly, so it is advisable to sample items and have two independent raters score them, using an agreement coefficient to measure inter-rater consistency.
5. Illustrative Evaluation Script
The following code demonstrates the overall workflow: read the item bank, call the interface under test, extract the final answer, check equivalence, and output statistical results. The interface part is a placeholder implementation and must be replaced with the actual call method.
import jsonfrom fractions import Fractiondef call_model(prompt: str, seed: int) -> str:"""Placeholder: replace with the actual model call logic and record sampling parameters."""raise NotImplementedErrordef extract_answer(text: str) -> str:# Convention: the model provides the final answer at the end in the format "ANSWER: xxx"for line in reversed(text.strip().splitlines()):if line.startswith("ANSWER:"):return line.split(":", 1)[1].strip()return ""def is_equal(pred: str, gold: str) -> bool:try:return Fraction(pred) == Fraction(gold)except (ValueError, ZeroDivisionError):return pred.replace(" ", "") == gold.replace(" ", "")def evaluate(path: str, runs: int = 3) -> dict:with open(path, encoding="utf-8") as f:items = [json.loads(line) for line in f]results = {"total": 0, "correct": 0}for item in items:for seed in range(runs):raw = call_model(item["question"], seed)pred = extract_answer(raw)results["total"] += 1results["correct"] += int(is_equal(pred, item["answer"]))results["accuracy"] = results["correct"] / results["total"]return results
Two cautions apply when using this code. First, a fixed random seed is effective only if the interface supports it; otherwise, record the sampling parameters for each call. Second, the format convention must be explicitly stated in the prompt; otherwise, answer extraction failures will be counted as errors and distort the results.
6. Result Analysis
Accuracy is only a number and needs to be interpreted together with the following analyses.
- Confidence intervals: for a binomial proportion, the Wilson interval can be used to estimate uncertainty. When the sample is small, a difference of a few percentage points between two models may be only random fluctuation.
- Repeated consistency: for the same item across multiple runs, calculate the proportion of identical answers. Items with consistent answers that are still wrong should be flagged separately, because this may indicate a systematic misunderstanding in the model.
- Error attribution: classify errors into calculation errors, concept errors, problem-reading errors, skipped steps, and format errors, and count each category separately. Format errors can often be resolved by adjusting the prompt, while concept errors better reflect the model’s capability boundary.
- Difficulty distribution: plot accuracy curves by difficulty tier. If the model performs well only on easy items and drops clearly on hard items, this conclusion should be stated explicitly in the report.
7. Common Pitfalls
- Looking only at the total score. A total score can hide differences across tiers; results for each difficulty tier should also be reported.
- Drawing conclusions from a single run. Sampling introduces randomness, so run each evaluation at least three times.
- Treating a high score on public items directly as reasoning ability. Decontamination checks must be performed first.
- Ignoring the impact of prompts and output format. Inconsistent formats can cause scoring failures; standardize the format before comparing capabilities.
- Replacing records with subjective impressions. Evaluation conclusions should include item version, parameters, date, and scoring rules so that others can reproduce them.
8. Practical Implementation Advice
When a team builds an evaluation system, it can proceed in the following order.
First, run the pipeline with a few dozen items to check whether the scoring rules are reasonable, especially answer extraction and equivalence checking. Then expand the item bank into difficulty tiers and add repeated runs and confidence interval calculations. Finally, integrate evaluation into the version iteration process: automatically run regression tests whenever the model version changes or the prompt is adjusted, and save historical results for trend comparison.
The value of evaluation is that it makes conclusions testable. A transparent, stable, and reproducible methodology supports technical selection and risk assessment better than a one-off subjective impression.
