TorchLean API

FloatLib.Floats.ExecFloat.Backends.Word.Full.Sqrt.Proof

Correctness of the native binary64 square-root kernel #

The restoring two-limb kernel reconstructs its scaled radicand one base-four digit at a time. Its state invariant proves that the final native root is Nat.sqrt with the exact remainder. The format-level theorem then refines the native field packing to Lean's unpacked binary64 model.

Restoring-root invariant #

Two-word radicand digits #

Restoring-loop refinement #

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.NativeBinary64.rootAndRemainder_spec (mantissa : UInt64) (shift : ) (hpositive : 0 < shift) (hshift : shift < 128) (hfit : mantissa.toNat <<< shift < 2 ^ 106) :
have state := rootAndRemainder mantissa shift; state.root.toNat = (mantissa.toNat <<< shift).sqrt state.remainder.toNat = mantissa.toNat <<< shift - (mantissa.toNat <<< shift).sqrt * (mantissa.toNat <<< shift).sqrt

When the shifted significand fits in 106 bits, the restoring root returns the integer square root and its remainder.

Binary64 scaling and rounding specification #

Native-core refinement #

Unpacked binary64 semantic refinement #

On every positive finite binary64 value, including subnormals, the native square root agrees with the unpacked model after packing.