liveBook · Manning

Equality_check

As explained in Build a Reasoning Model (From Scratch)

A function that decides whether two mathematical expressions are equivalent after normalization.

Compare a predicted mathematical expression with a ground-truth expression after normalization, rather than relying only on Python's == operator. Parse both expressions with SymPy, then test whether their difference simplifies to zero. section 3.6

The implementation follows a defensive comparison workflow:

  • Return True immediately when the raw expressions already match. section 3.6

Equivalent expressions

The checker accepts 13/4 and (13)/(4), 0.5 and (1)/(2), and tuple components such as 2/3 and 4/6 when used through answer grading; it rejects 14/3 versus 15/3.

How Build a Reasoning Model (From Scratch) covers it

How deep it goes
Implements parsing, implicit multiplication, simplification, length limits, and failure handling, but delegates expression semantics to SymPy.
Examples
Demonstrates equivalent fractions, decimals, LaTeX, radicals, percentages, degrees, powers, and ordered tuple comparisons.
What it assumes
Assumes extracted and normalized answer strings plus a reference answer, while handling malformed or empty expressions defensively.
What you can do after
Build a defensive mathematical equivalence checker and reuse it for componentwise grading of tuple-like answers.
How it connects
Connects normalization, symbolic mathematics, ground truth, answer extraction, and answer grading.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Reasoning Model (From Scratch). The section links point to the parts of the book it draws on.