Choosing LLMs for Mathematical Problems: A Practical Framework for Cost and Capability
Selecting the right LLM for mathematical tasks requires balancing cost against reasoning capabilities. This article provides a practical framework covering API cost structures, model evaluation methodologies, a specific LaTeX proof generation use case, task-based routing strategies, and ongoing cost monitoring. By utilizing custom evaluation sets and tracking both token consumption and manual review times, you can optimize model selection and avoid common pitfalls.
Unifying Metrics Before Model Selection
Before evaluating LLMs, unify three key metrics: billing, testing, and cost. This article does not cite specific public model accuracy numbers, as public leaderboards vary significantly in datasets, prompts, and parameters, making direct comparisons misleading. The methods introduced here can be reproduced on your own datasets. Pricing should be based on official provider pricing pages, and reports should clearly state the testing date and model versions used.
1. The Three Components of API Costs
Mainstream API billing is typically divided into three parts: standard input tokens, output tokens, and cached input tokens.
Output tokens are generally more expensive than input tokens, though the exact gap depends on the provider and model. When estimating costs, you cannot look at unit price alone; output length matters equally. Mathematical reasoning often involves long chains of thought. If the reasoning process is counted towards the output, the number of output tokens per task may far exceed expectations.
Cache hits reduce the cost of repeated prefixes. In mathematical tasks, axiomatic definitions, preconditions, and system prompts are often identical across requests. Placing these stable contents at the beginning of the request and keeping the prefix consistent at the byte level ensures a high hit rate. Inserting timestamps or random IDs at the beginning will cause cache misses.
Package-based billing needs to align with actual usage. Track your real token consumption over a month before selecting a package. If your usage consistently falls below the quota, a smaller package is usually more cost-effective. If you frequently exceed limits, set up usage alerts to prevent service interruptions.
2. Evaluating a Model’s Mathematical Reasoning Capability
Instead of relying on “which model is the strongest” leaderboards, test using your own datasets. A viable test set must meet the following conditions:
- Quantity: Include at least several dozen questions per task category. Too few samples lead to high volatility in conclusions.
- Source: Use self-compiled or rewritten propositions where possible. Public questions may already be in the model’s training data, leading to inflated results.
- Scoring Criteria: Separately evaluate whether the conclusion is correct, whether the proof is complete, and whether each step can be independently verified.
- Sampling: Run the same question multiple times and record the success rate rather than just running it once.
- Logging: Record model name and version, call date, temperature parameter, and maximum output tokens.
Post-testing, you can derive four metrics: accuracy, average output tokens, cost per question, and manual review time. Manual review time is often overlooked but directly determines whether a model truly saves time. A seemingly coherent proof that requires a person with a mathematical background two hours to verify represents a hidden cost that must be factored into selection.
Based on test results, categorize models into tiers. For example: high accuracy with short output; high accuracy with long output; and lower accuracy. Note that these tier classifications only apply to your specific dataset and cannot be directly extrapolated to other domains.
3. Use Case: Academic Lecture Notes Generation
A typical task: Given a mathematical proposition with only a statement and no proof, require the model to provide a proof and output compilable English LaTeX lecture notes.
This task can be broken down into three checkpoints:
- Mathematical Correctness: Is every step of the proof verifiable? Are there circular arguments or skipped steps?
- Format Correctness: Can the LaTeX compile in the specified environment? Are theorem and proof environments complete?
- Expression Consistency: Is the terminology unified? Are symbols consistently defined throughout the text?
A basic prompt example is as follows:
Role: You are a researcher familiar with algebraic geometry.Task: Prove the following proposition and provide complete derivations.Requirements: Use English, output LaTeX, include theorem and proof environments. Provide the basis for each step. If unable to complete, explicitly state the missing steps and do not fabricate conclusions.Proposition: [Insert proposition here]
The final requirement is critical. Models may output structurally complete, fluently written proofs that contain mathematical errors. For research purposes, output must be reviewed by someone with the appropriate background. Model output should always be treated as a draft awaiting verification.
When logging tasks, save the compiler version, list of packages, model version, and parameter settings. Without this information, results cannot be reproduced. For costs, record input tokens, output tokens, and cache hits for each task, converting them using the official unit price at the time. Do not substitute actual data with estimated percentages.
4. Model Selection via Task-Based Routing
There is no need to use the same model for all requests. A common practice is to classify tasks by type first, then set routing rules. The table below is a template; specific values need to be filled based on your test results.
| Task Type | Candidate Model Tier | Input/Output Unit Price | Cache Support | Accuracy Metric | Single Cost Limit | Routing Threshold |
|---|---|---|---|---|---|---|
| Intent recognition, format conversion | Low-cost base model | Refer to official pricing | To be confirmed | Custom dataset, to be tested | TBD | Default use |
| Routine math verification | Mid-tier model | Refer to official pricing | To be confirmed | Custom dataset, to be tested | TBD | Escalate if below confidence threshold |
| Open-ended reasoning, key proofs | High-tier model | Refer to official pricing | To be confirmed | Custom dataset, to be tested | TBD | Use when task contains complex logical structures |
Routing rules can be designed as follows:
- A low-tier model first determines the task type and assigns a complexity label.
- If the label is simple, the low-tier model completes it directly.
- If the label is complex, or if the low-tier model’s self-check fails, route it to the high-tier model.
- If the high-tier model’s core conclusion conflicts with the low-tier model, route it to a manual review queue.
Escalation thresholds need to be determined through experimentation. For instance, you can use a batch of questions with known answers to observe error rates under different complexity labels, then select an acceptable error margin as the escalation line.
5. Cost Monitoring Checklist
After deployment, check the following weekly:
- Log input tokens, output tokens, and cache hit rates by task type.
- Set a single cost limit for each task category. If exceeded, interrupt the task or downgrade to a lower-tier model.
- Set monthly budget alert lines to notify the responsible person when a preset proportion is reached.
- Monitor whether the average output token count grows abnormally. Longer outputs usually indicate prompt changes, model upgrades, or expanded task scopes.
- Compare actual usage against package quotas to determine if the current package is appropriate.
- Sample and review high-tier model outputs to confirm that increased costs actually brought about accuracy improvements.
6. Common Mistakes
- Looking only at unit price, not output length: Two models may have similar unit prices, but if their output lengths differ several-fold, total costs will differ by the same magnitude.
- Drawing conclusions from one or two questions: With a small sample size, randomness is high.
- Adopting fluent proofs directly: Mathematical proofs require step-by-step verification; fluent expression is not a substitute for verification.
- Changing the cache prefix every time: This drives the cache hit rate close to zero, rendering cost optimization ineffective.
- Not recording model versions: After a model updates, previous test results may no longer apply.
