(a, b, tolerance, timeout=10.0)
| 315 | |
| 316 | |
| 317 | def 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 | |
| 346 | def extract_answer(string): |
no test coverage detected