Skip to content

fix(parser): extract scientific notation exponents in ExprExtractionConfig - #89

Open
Virtuoso461 wants to merge 1 commit into
huggingface:mainfrom
Virtuoso461:fix/scientific-notation
Open

Virtuoso461 wants to merge 1 commit into
huggingface:mainfrom
Virtuoso461:fix/scientific-notation

Conversation

@Virtuoso461

Copy link
Copy Markdown

What does this PR do?

ExprExtractionConfig parsing dropped scientific-notation exponents: the number regex stopped right after the mantissa, so "1.5e3" was extracted as 1.5 and "6.02e23" as 6.02. Answers written in scientific notation were compared against the mantissa alone:

from math_verify import parse, verify
from math_verify.parser import ExprExtractionConfig

cfg = (ExprExtractionConfig(),)
parse("The answer is 1.5e3.", cfg)   # -> [1.5, '1.5']  (before this PR)
verify(parse("The answer is 1.5e3.", cfg), parse("The answer is 1500.", cfg))  # -> False

Fix

Adds an optional (?P<exponent>[eE][-+]?\d+) group after the integer/decimal alternation in number_re, and appends it when building the number string in extract_expr. Sympy's Number("1.5e3") then evaluates to 1500.

A trailing e without digits still does not count as an exponent — word1e extracts nothing, as before.

Tests

New tests/test_scientific_notation.py:

  • positive / large / negative / uppercase exponents extract the full value
  • 1.5e3 verifies equal to 1500
  • no-false-positive control for trailing e

Full suite (excluding large corpus files): 241 passed, no regressions. On the unpatched tree the new tests fail 5/6.

…onfig

The expr number regex stopped right after the mantissa, so "1.5e3" was
extracted as 1.5 and "6.02e23" as 6.02. Answers written in scientific
notation were then compared against the mantissa alone, e.g.
verify('The answer is 1.5e3.', 'The answer is 1500.') returned False.

Adds an optional (?P<exponent>[eE][-+]?\d+) group to number_re and
appends it when building the number string. A trailing e without digits
still does not count as an exponent ('word1e' extracts nothing).
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