TorchLean API

FloatLib.Floats.Formats.DecimalInterchange.Sqrt.Proof

Decimal square-root value, range, and error #

Carry normalization preserves the rounded root, and preferred-cohort selection preserves its value. The numerical bound compares the returned rational datum with the mathematical real square root. Inexactness is tested by an exact squaring equality.

theorem FloatLib.Floats.Formats.DecimalInterchange.sqrtPair_value (f : Format) (mode : RoundingMode) (x : ) :
(sqrtPair f mode x).1 * 10 ^ (sqrtPair f mode x).2 = (mode.sqrtRound (x / 10 ^ (2 * sqrtQuantum f x))) * 10 ^ sqrtQuantum f x

Decimal carry normalization does not change the rounded numerical root.

theorem FloatLib.Floats.Formats.DecimalInterchange.sqrtMagnitude_valid (f : Format) (mode : RoundingMode) {x : } (hx : 0 x) (preferred : ) :
Datum.Valid f (sqrtMagnitude f mode x preferred).value
theorem FloatLib.Floats.Formats.DecimalInterchange.sqrtMagnitude_value (f : Format) (mode : RoundingMode) (x : ) (preferred : ) (hq : (sqrtPair f mode x).2 f.maxQuantum) :
(sqrtMagnitude f mode x preferred).value.toRat? = some ((mode.sqrtRound (x / 10 ^ (2 * sqrtQuantum f x))) * 10 ^ sqrtQuantum f x)
theorem FloatLib.Floats.Formats.DecimalInterchange.sqrt_scaled (x : ) (q : ) :
↑(x / 10 ^ (2 * q)) * 10 ^ q = x

Scaling by a decimal quantum commutes with the nonnegative mathematical square root.

theorem FloatLib.Floats.Formats.DecimalInterchange.sqrtMagnitude_error_le_half (f : Format) (mode : RoundingMode) (hm : mode = RoundingMode.nearestEven mode = RoundingMode.nearestAway) {x : } (hx : 0 x) (preferred : ) (hfinite : (sqrtMagnitude f mode x preferred).status.overflow = false) :
∃ (value : ), (sqrtMagnitude f mode x preferred).value.toRat? = some value |value - x| 10 ^ sqrtQuantum f x / 2

The actual returned datum is within half a grid unit of the mathematical root.

theorem FloatLib.Floats.Formats.DecimalInterchange.sqrtMagnitude_inexact_iff (f : Format) (mode : RoundingMode) {x : } (hx : 0 x) (value : ) (preferred : ) (hq : (sqrtPair f mode x).2 f.maxQuantum) (hv : (sqrtMagnitude f mode x preferred).value.toRat? = some value) :
(sqrtMagnitude f mode x preferred).status.inexact = true value x

Squared equality tests real numerical exactness, including irrational roots.