TorchLean API

FloatLib.Floats.ExecFloat.Backends.FixedLimb.Pair.Core.Proof

Two-word pair-kernel storage #

The field helpers in Core.Runtime agree with the width-generic carrier under NativePair.Eligible. The eligibility bounds ensure that field extraction and packing do not lose bits to native-word overflow.

packNormal_eq_ofFields relates native packing to the canonical field constructor for an in-range exponent field and a normalized significand. decode_of_normalExponent gives the finite components when the exponent is nonzero and not all ones. These contracts apply to binary128 and every other eligible descriptor.

Layout bounds #

An eligible descriptor uses the conventional IEEE encoding and bias.

An eligible fraction is wider than one word.

An eligible descriptor fits in two words.

The exponent and fraction of an eligible descriptor share at most 127 bits.

An eligible fraction has at most 125 bits, since the exponent field has at least two.

An eligible exponent field has at most 62 bits.

An eligible descriptor uses the IEEE exceptional-value encoding.

An eligible descriptor uses the conventional bias.

The bias of an eligible descriptor is below 2^61.

Layout constants #

The high word holds fracWidth - 64 fraction bits.

The high fraction mask is 2^(fracWidth - 64) - 1.

The native all-ones exponent field is the descriptor's all-ones exponent.

The implicit bit sits at high-word position fracWidth - 64.

The carry bit sits at high-word position fracWidth - 63.

The sign bit sits at high-word position expWidth + fracWidth - 64.

Splitting and joining words #

The low storage word is the low 64 bits of the encoding.

The high storage word is the encoding shifted down by 64 bits.

The two native storage words reconstruct the exact encoding.

Joining two native words reconstructs their value whenever it fits the storage width.

Field extraction #

Native sign extraction agrees with the public carrier.

Native exponent extraction agrees with the public carrier.

The two fraction limbs reconstruct the public fraction field.

The high fraction limb occupies at most fracWidth - 64 bits.

The native exponent field fits the exponent width.

A nonzero, nonexceptional native exponent lies in the normal range.

Normal significands #

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.NativePair.normalMantissa_toNat {fmt : FloatFormat} (h : Eligible fmt) (high low : UInt64) (hhigh : high.toNat < 2 ^ (fmt.fracWidth - 64)) :
(normalMantissa fmt high low).toNat = 2 ^ fmt.fracWidth + high.toNat * 2 ^ 64 + low.toNat

The normal significand is 2^fracWidth plus the two fraction limbs in place.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.NativePair.normalMantissa_bounds {fmt : FloatFormat} (h : Eligible fmt) (high low : UInt64) (hhigh : high.toNat < 2 ^ (fmt.fracWidth - 64)) :
2 ^ fmt.fracWidth (normalMantissa fmt high low).toNat (normalMantissa fmt high low).toNat < 2 ^ (fmt.fracWidth + 1)

A normal significand occupies exactly fracWidth + 1 bits, including its implicit bit.

The carried-out significand 2^(fracWidth + 1) as two limbs.

The two-limb carry test is exactly the carry produced by fracWidth + 1-bit rounding.

Carry normalization of a rounded significand is either that significand or 2^fracWidth.

Packing #

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.NativePair.packNormal_eq_ofFields {fmt : FloatFormat} (h : Eligible fmt) (sign : Bool) (exponent : UInt64) (mantissa : Numerics.FixedWord.UInt128) (hexponent : exponent.toNat < 2 ^ fmt.expWidth) (hmantissaLower : 2 ^ fmt.fracWidth mantissa.toNat) (hmantissaUpper : mantissa.toNat < 2 ^ (fmt.fracWidth + 1)) :
packNormal fmt sign exponent mantissa = ofFields fmt sign exponent.toNat (mantissa.toNat - pow2 fmt.fracWidth)

Native packing agrees with the field constructor for a normalized significand and an in-range exponent field.

Finite decoding #

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.NativePair.decode_of_normalExponent {fmt : FloatFormat} (h : Eligible fmt) (x : Model fmt) (hexponentZero : expField fmt (toWords x).hi 0) (hexponentFinite : expField fmt (toWords x).hi expAllOnes fmt) :
FiniteKernel.decode? x = some { sign := signBit fmt (toWords x).hi, exponent := (expField fmt (toWords x).hi).toNat, mantissa := (normalMantissa fmt (fracHigh fmt (toWords x).hi) (toWords x).lo).toNat }

Decode a normal finite value directly from its two native storage words.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.NativePair.normalComponents_toDyadic {fmt : FloatFormat} (h : Eligible fmt) (sign : Bool) (exponent mantissa : ) (hexponent : exponent 0) (hmantissa : mantissa 0) :
FiniteKernel.Components.toDyadic fmt { sign := sign, exponent := exponent, mantissa := mantissa } = { negative := sign, significand := mantissa, exponent := Int.ofNat exponent - Int.ofNat (fmt.bias + fmt.fracWidth) }

Interpret normal finite-kernel components as their exact dyadic value.

Normalize the scale used by the product-round kernels.