Define the finite-only contract

A checker can miss a violation and still accept the wrong thing. In a built-in Python float example, a NaN candidate makes both error > tolerance and error <= tolerance false. Negating the first condition turns that false into an acceptance.[5][1]

The contract matters. This original worksheet requires a finite reference and a finite candidate, then an absolute error no larger than 0.125. Relative tolerance is zero. NaN and either infinity are invalid candidates. A nonfinite reference is a fixture error and cannot count as an eligible candidate evaluation. This is a deliberate teaching contract, not a policy for every numerical API.[5]

Set the reference to 1.0 and the candidate to NaN. The absolute difference is NaN. The rejection-only predicate, not (abs(candidate-reference) > tolerance), returns true because the ordered comparison returns false. The positive error <= tolerance comparison also returns false. These expressions are not interchangeable when NaN is in the domain.[4][1]

  • Validate the reference: An invalid reference is a fixture problem, not an eligible failed candidate.

What the language promises

Python documents this behavior for built-in floats. Its language reference says ordered comparisons with NaN are false. The math module provides isfinite for the validity check; isclose says NaN is never close to any value. Infinities are close only to themselves, which is another reason an API closeness result should not silently define a finite-only reference policy. The worksheet records isclose with rel_tol=0 as a diagnostic, alongside the two predicates.[1][3][2]

Keep every authored row

The saved result retains every authored row. Seven use the valid reference 1.0: exact equality, both tolerance boundaries, one finite value outside the boundary, NaN and both infinities. The finite-only contract accepts the three intended finite cases. The rejection-only predicate accepts those three plus the NaN candidate. The two additional rows have invalid references and remain separate. Their role is to test fixture validation, not enlarge a model-failure denominator.[4]

One eighth and the finite fixture values are exactly representable in binary. That keeps the example focused on nonfinite values rather than decimal-rounding disputes. The result includes each input, absolute error, comparison boolean, acceptance and role. Special values are explicit string tags, so the saved output is strict JSON rather than a file containing non-standard bare NaN numbers.[5]

All nine authored rows. Absolute tolerance 0.125; relative tolerance zero. The raw predicate is shown even when the reference is invalid.

CaseReferenceCandidateRejection-only acceptsFinite-only status
Exact1.01.0Trueaccepted
Upper boundary1.01.125Trueaccepted
Outside1.01.25Falseoutside tolerance
Lower boundary1.00.875Trueaccepted
NaN candidate1.0NaNTruenonfinite candidate
+Infinity candidate1.0InfinityFalsenonfinite candidate
-Infinity candidate1.0-InfinityFalsenonfinite candidate
NaN referenceNaN1.0Trueinvalid reference
+Infinity referenceInfinity1.0Falseinvalid reference
  • Seven eligible candidate rows; two invalid-reference fixtures are ineligible.
  • Three intended finite acceptances and one designed NaN false acceptance by the rejection-only predicate. No prevalence estimate.

Apply the contract explicitly

The practical change is small for this contract: validate the reference, validate the candidate, then check the positive tolerance relation. Do not use equality to NaN as a validity test. For arrays, shape and dtype checks, reduction rules, broadcasting and the policy for nonfinite elements still need their own explicit treatment. This scalar worksheet does not validate those choices or general numerical equivalence.[3][5]

One reviewed standard-library invocation retained all nine rows and thirteen passing controls. The controls cover the designed counterexample, finite boundaries, both infinities, invalid references, strict JSON and malformed inputs. The source, fixture, protocol and full output are included in the MIT proof package. No model, GPU or existing grader was run.[5][4]

This establishes one designed logical counterexample. It does not show that a particular benchmark is vulnerable or estimate how often real models emit invalid outputs. If NaN or infinity is valid in your application, define that contract explicitly before choosing the comparison. Correctness starts with what the checker promises to accept.[5][6]

  • State the nonfinite policy: NaN-allowed and infinity-allowed APIs need their own contract. This example intentionally requires finite values.
  • Before trusting a tolerance score, state which values are valid and keep fixture errors separate from candidate failures.

Sources

  1. Python language reference: value comparisons docs.python.org
  2. Python math.isclose docs.python.org
  3. Python math.isfinite docs.python.org
  4. Full authored result data.nodus-compute.ai
  5. Original MIT source, fixture and complete proof data.nodus-compute.ai
  6. Source and saved-result provenance data.nodus-compute.ai
  7. Vector figure data.nodus-compute.ai