TorchLean API

FloatLib.Floats.ExecFloat.Backends.Generic.Sqrt.Proof

Correctness of compact finite square root #

The executable descriptor-aware square-root kernels live in Sqrt.Runtime. This module proves their agreement with the exact dyadic and unpacked-model specifications and installs the verified compiler substitution.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.FiniteSqrt.sqrtGeneral_eq_unscaled (fmt : FloatFormat) (mantissa : ℕ) (exponent : ℤ) :
sqrtGeneral fmt mantissa exponent = if (mantissa == 0) = true then posZero fmt else have finalExponent := targetExponent fmt mantissa exponent; have rootExponent := min (exponent.ediv 2) finalExponent; have scaledMantissa := mantissa <<< (exponent - 2 * rootExponent).toNat; have root := scaledMantissa.sqrt; have remainder := scaledMantissa - root * root; Internal.roundDyadic fmt { negative := false, significand := roundRoot root remainder (finalExponent - rootExponent).toNat, exponent := finalExponent }

The scaled kernel sqrtGeneral equals the full-radicand algorithm.

For a conventional IEEE descriptor, exact-dyadic square root agrees with the unpacked model UnpackedFloat.sqrt applied to the encoded value.

Compact positive square root agrees with the exact-dyadic specification.

Scalar-field square root sqrtPositiveRuntime? agrees with sqrtPositive?.

On a positive finite nonzero input, the optional scalar decoder returns sqrtPositiveRuntime.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.FiniteSqrt.sqrtPositiveRuntime_eq_finiteDyadic {fmt : FloatFormat} (x : Model fmt) (hfinite : x.isFinite = true) (hnonzero : x.isZero = false) (hpositive : x.signBit = false) :
sqrtPositiveRuntime x hfinite hnonzero hpositive = have value := x.finiteDyadic hfinite; sqrtPositiveDyadic fmt value.significand value.exponent

sqrtPositiveRuntime takes the square root of the exact dyadic that its finite input represents.