Skip to content

Support plain mixed-number extraction - #81

Open
dkajtoch wants to merge 3 commits into
huggingface:mainfrom
dkajtoch:fix/mixed-number-parsing
Open

Support plain mixed-number extraction#81
dkajtoch wants to merge 3 commits into
huggingface:mainfrom
dkajtoch:fix/mixed-number-parsing

Conversation

@dkajtoch

@dkajtoch dkajtoch commented Sep 1, 2026

Copy link
Copy Markdown

Problem

math_verify.parse() does not recognize plain mixed-number notation such as 11 5/6 as one value. The generic expression and number patterns can instead expose finite fragments of the answer as independent candidates.

This causes more than a missed equivalence with 71/6: it can produce false positives. For example, 2 2/3 can expose 2 and incorrectly match a gold answer of 2. Invalid mixed-looking syntax has the same problem: 4 10/3 can expose 10 and incorrectly match a gold answer of 10 instead of being rejected.

Solution

This PR adds a higher-priority mixed-number extraction path before the generic expression and number patterns.

  • Recognize an optional sign, an integer whole-number component, horizontal whitespace, and a fractional component.
  • Require the fractional component to be proper: the denominator must be positive and the numerator must be smaller than the denominator.
  • Normalize valid values to an explicit sum before parsing, with a leading negative sign applying to the complete value.
  • Preserve the original matched text as the fallback representation.
  • Return a non-finite result for invalid mixed-looking forms so extraction cannot fall through to a finite prefix or numerator.
  • Apply percentage suffixes to the complete mixed-number value.
  • Do not infer an operation when the left component is a fraction, decimal, parenthesized expression, or appears on another line. Existing explicit addition and subtraction remain unchanged.

Consequently, 11 5/6 is interpreted as 11 + 5/6, while 4 10/3 is rejected. The explicit expression 4 + 10/3 remains valid.

Checks run

  • .venv/bin/pytest -q tests/test_mixed_number_extraction.py: 42 passed
  • .venv/bin/pytest -q: 332 passed, 1 failed; the remaining LaTeX-percentage failure is unchanged on upstream/main
  • .venv/bin/ruff check tests/test_mixed_number_extraction.py: passed
  • .venv/bin/ruff format --check src/math_verify/parser.py tests/test_mixed_number_extraction.py: passed
  • uv build: source distribution and wheel built successfully

The existing parser.py import-order and unused-import Ruff findings are also present on upstream/main and are outside this change.

@dkajtoch

dkajtoch commented Sep 1, 2026

Copy link
Copy Markdown
Author

@hynky1999, would you mind reviewing this change? It adds plain mixed-number extraction and prevents finite-fragment false positives such as 2 2/3 matching gold 2. The focused suite has 42 passing tests; the only full-suite failure is the pre-existing LaTeX-percentage case documented in the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant