Correctness of binary square root #
Lean's unpacked floating-point square root computes an integer square root and records whether the discarded real fraction is below or above one half. This module proves that certificate correct, connects the positive finite executable path to Lean's unpacked square-root model, proves that the square root of a finite nonnegative value never overflows, and concludes that the result for a conventional IEEE descriptor is one nearest-even rounding of the exact real square root.
The residual classification produced from an integer square root locates the exact real square
root in the unit interval beginning at Nat.sqrt n, with the correct half-way comparison.
Lean's positive finite model square root has the same real value as independent nearest-even rounding of the exact real square root whenever the packed result is finite.
Square root never overflows #
The largest finite value of every IEEE descriptor exceeds one, so its square root is below it and
the rounded result stays inside the finite range. We first show that packing a model value whose
biased exponent is in range yields a finite word, then that roundWithAccuracy of a certified real
below 2^maxNormal packs to such a value.
Packing a finite model value whose biased exponent stays below the all-ones pattern yields a
finite word. This is the converse of noOverflow_of_isFinite_ofModel_finite.
Rounding a positive certified real whose magnitude is below 2^maxNormal never overflows, so the
packed result is finite. The exponent premise is the documented precondition of
roundWithAccuracy: normalization may discard low bits but never shifts left.
Lean's positive finite model square root packs to a finite word whenever the radicand is below
2^(2 * maxNormal), which every finite IEEE value is.
The square root of a finite nonnegative value, including either signed zero, is finite for every conventional IEEE descriptor. The largest finite value exceeds one, so its square root lies below it and rounding cannot reach infinity.
Generic executable square root performs one nearest-even rounding of the exact real square root
on every finite, nonnegative conventional IEEE input. The domain condition includes both signed
zeros. Unlike the other arithmetic operations, no finiteness of the result is assumed:
isFinite_sqrt_of_isFinite shows that square root cannot overflow.