Skip to main content

Overview

MathRubric extends Rubric to provide mathematical equivalence checking using the math_verify library. It evaluates whether model-generated mathematical answers are equivalent to ground truth, handling symbolic expressions, algebraic equivalence, and numerical precision.

Constructor

list[RewardFunc] | None
default:"None"
Additional reward functions beyond the built-in correct_answer function.
list[float] | None
default:"None"
Weights for additional reward functions. The built-in correct_answer gets weight 1.0.
Parser | None
default:"None"
Parser for extracting answers. Defaults to MaybeThinkParser(extract_fn=extract_boxed_answer).
int
default:"50"
Maximum number of thread pool workers for parallel verification.
float
default:"5"
Per-verification timeout in seconds. Returns 0.0 reward if exceeded.

Built-in Reward Function

correct_answer

Verifies mathematical equivalence between the parsed completion and ground truth answer.
Parser
Parser instance (automatically provided by the rubric).
Messages
Model’s completion to verify.
str
Ground truth answer in LaTeX format (will be wrapped in \boxed{}).
Returns: float - 1.0 if mathematically equivalent, 0.0 otherwise.
The function automatically wraps answers in \boxed{} format before verification.

Timeouts

MathRubric implements two-level timeout protection:
float
default:"5"
Soft timeout: Returns 0.0 if verification takes longer than this, but logs it as debug.
float
default:"120"
Hard timeout: Absolute maximum time for verification. Logs a warning if exceeded.

Attributes

ThreadPoolExecutor
Thread pool for running blocking math_verify operations asynchronously.
All attributes from Rubric are also available.

Example Usage

Basic Math Verification

Custom Parser for Boxed Answers

Adding Additional Metrics

Custom Timeout Settings

Combining with Other Reward Functions

Handling Edge Cases

Mathematical Equivalence

The math_verify library checks various forms of equivalence:
  • Symbolic: 2x + 62(x + 3)
  • Numerical: 0.333...1/3
  • Algebraic: (x+1)^2x^2 + 2x + 1
  • Trigonometric: sin^2(x) + cos^2(x)1

Performance Considerations

Mathematical verification can be computationally expensive:
  • Set appropriate timeout_seconds to avoid hanging on complex expressions
  • Use max_workers to control parallelism and memory usage
  • The thread pool is automatically cleaned up when the rubric is garbage collected
Verification runs in a thread pool executor to avoid blocking the async event loop.

Notes

  • Empty or unparseable responses always receive 0.0 reward
  • Timeout violations are logged at debug level for soft timeouts, warning for hard timeouts
  • The rubric suppresses math_verify library timeout warnings (handled internally)
  • All parsing exceptions return 0.0 rather than raising errors

See Also