TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/TangibleResearch/Halgorithem/llms.txt
Use this file to discover all available pages before exploring further.
Halgorithem.math_utils module provides symbolic math evaluation using sympy, used internally when Halgorithem classifies a claim as type MATH and needs to verify arithmetic correctness.
These functions are internal utilities. Most users will not call them directly — the
Halgorithm class handles MATH claims automatically through compare_to_docs(). Refer to this page if you need to understand the verification logic or reuse the functions in your own pipeline.Functions
safe_eval
implicit_multiplication_application transformation.
A string containing a mathematical expression, such as
"2 + 2", "100 * 1.05", or "2x" (implicit multiplication).The evaluated result as a Python
float, produced by calling .evalf() on the sympy expression.ValueError if the expression cannot be parsed.
numbers_close
max(..., 1) floor prevents the tolerance from collapsing to zero when both values are very small.
The first number to compare.
The second number to compare.
Relative tolerance. The default
1e-6 is appropriate for most floating-point rounding differences. Increase this value if you need a looser match (e.g. for rounded figures).True if the two values are within the relative tolerance of each other, False otherwise.How MATH claim verification works
WhenHalgorithm.compare_to_docs() encounters a claim classified as type MATH, it calls verify_math_claim() in core.py, which uses both functions above:
- The claim string is split on
=— for example"2 + 2 = 4"becomes["2 + 2", "4"]. - Both sides are passed to
safe_eval()to produce float values. numbers_close()checks whether the two values agree within the default1e-6relative tolerance.- The result is returned as a structured dict:
| Outcome | Status |
|---|---|
| Values match within tolerance | SUPPORTED |
| Values do not match | CONTRADICTION |
No = found in claim | UNKNOWN |
safe_eval() raises | ERROR |