Math Answer Verification with Equivalence Checking
Text Generation & NLP Evaluation DS practice problem on Onlearn.
Difficulty: medium.
Topics: Math Answer Verification with Equivalence Checking, Canonical Form Normalization, Expression Tree Isomorphism, LaTeX Parsing, Numerical Precision Thresholding, Equivalence Class Partitioning, Natural Language Processing, Symbolic Mathematics, Information Retrieval, Formal Verification, Machine Learning Evaluation, Semantic Textual Similarity, Computer Algebra Systems, Abstract Syntax Tree Parsing, Automated Theorem Proving, Metric-based Model Assessment.
Implement a function that verifies if two mathematical answer strings are equivalent. This is a crucial task in evaluating LLM outputs on math benchmarks where the model's answer might be expressed differently from the ground truth but still be mathematically correct. The function should handle: Direct string equality Numeric equivalence (integers and floats) Fraction expressions (e.g., '1/2' should match '0.5') Square root expressions (e.g., 'sqrt(4)' should match '2') Pi expressions (e.g., 'pi' should match '3.14159...') Combinations with basic arithmetic operations The function should return True if the predicted answer is mathematically equivalent to the ground truth within the specified tolerance, and False otherwise. Non numeric or unparseable expressions that don't match exactly should return False.