TorchLean API

FloatLib.Kernels.FixedWord.CheckedSqrt.Proof

Correctness of checked square roots #

An accepted candidate is the floor square root with its exact remainder (checkRoot?_spec, acceptRootWide?_spec), and rootAndRemainder and Internal.rootAndRemainder equal the restoring loop on every input.

theorem FloatLib.Numerics.FixedWord.CheckedSquareRoot.checkRoot?_spec {radicand : UInt128} {guess : UInt64} {state : RestoringRootState UInt64} (h : checkRoot? radicand guess = some state) :
state.root.toNat = radicand.toNat.sqrt ∧ state.remainder.toNat = radicand.toNat - radicand.toNat.sqrt * radicand.toNat.sqrt

An accepted candidate is the floor square root, with the exact remainder.

rootAndRemainder equals the restoring loop on every input.

theorem FloatLib.Numerics.FixedWord.CheckedSquareRoot.acceptRootWide?_spec {radicand : UInt256} {guess : UInt128} {state : RestoringRootState UInt128} (h : acceptRootWide? radicand guess = some state) :
state.root.toNat = radicand.toNat.sqrt ∧ state.remainder.toNat = radicand.toNat - radicand.toNat.sqrt * radicand.toNat.sqrt

An accepted four-word candidate is the floor square root, with the exact remainder.

Internal.rootAndRemainder equals the two-word checked path, hence the loop, on every input.