TorchLean API

NN.Floats.FP32.Sterbenz

Exact Binary32 Subtraction #

Sterbenz's lemma specialized to the rounded-real binary32 configuration fexp32 = fltExp (-149) 24. Two positive representable values within a factor of two have an exactly representable difference, so rounding that difference does nothing.

Reference #

If two positive binary32-representable reals are within a factor of two, rounding their exact difference is the identity.

theorem TorchLean.Floats.FP32.sub_exact_of_sterbenz {a b : FP32} (ha : FloatLib.Floats.Formats.Flocq.NF.IsRepresentable a) (hb : FloatLib.Floats.Formats.Flocq.NF.IsRepresentable b) (hapos : 0 < a.val) (hbpos : 0 < b.val) (hab : a.val 2 * b.val) (hba : b.val 2 * a.val) :
(a - b).val = a.val - b.val

Subtraction of positive representable FP32 values within a factor of two has no rounding error.