MCPcopy Create free account
hub / github.com/PRIME-RL/PRIME / symbolic_equal

Function symbolic_equal

data_preprocessing/math_util/grader.py:317–343  ·  view source on GitHub ↗
(a, b, tolerance, timeout=10.0)

Source from the content-addressed store, hash-verified

315
316
317def symbolic_equal(a, b, tolerance, timeout=10.0):
318 def _parse(s):
319 for f in [parse_expr, parse_latex]:
320 try:
321 with time_limit(timeout):
322 return f(s)
323 except Exception:
324 pass
325 return s
326
327 a = _parse(a)
328 b = _parse(b)
329
330 try:
331 with time_limit(timeout):
332 if simplify(a - b) == 0:
333 return True
334 except Exception:
335 pass
336
337 try:
338 with time_limit(timeout):
339 if isclose(N(a), N(b), rel_tol=tolerance):
340 return True
341 except Exception:
342 pass
343 return False
344
345
346def extract_answer(string):

Callers 1

math_equalFunction · 0.70

Calls 2

_parseFunction · 0.70
time_limitFunction · 0.70

Tested by

no test coverage detected