TorchLean API

FloatLib.Kernels.FixedWord.Core.Proof.Rounding

Verified native-word rounding #

The one-word nearest-even shift and quotient kernels agree with the shared arbitrary-precision definitions. The compiler substitutions therefore change only the representation used for bounded inputs, not the numerical result.

@[simp]
theorem FloatLib.Numerics.FixedWord.finiteScale_toNat (exponent : UInt64) :
(finiteScale exponent).toNat = if exponent = 0 then 0 else exponent.toNat - 1

Natural-number view of the shared nonnegative finite-scale encoding.

@[simp]

Native word rounding agrees exactly with the generic natural-number rounder.

Capacity-selected nearest-even shifting agrees with arbitrary-precision rounding.

@[csimp]

The compiler uses native nearest-even shifting for one-word inputs and the arbitrary-precision definition otherwise.

theorem FloatLib.Numerics.FixedWord.roundQuotientEven_toNat (num den : UInt64) (hden : den 0) (hquotientFit : num.toNat / den.toNat + 1 < 2 ^ 64) :

Native quotient rounding agrees with natural-number quotient rounding whenever the denominator is nonzero and the incremented quotient fits in one word.

No bound on den is needed: the kernel compares the remainder with den - remainder instead of doubling it, so its intermediates never wrap.

The native and arbitrary-precision branches compute the same nearest-even natural-number quotient.

@[csimp]

The compiler uses native quotient rounding for bounded inputs and the arbitrary-precision definition otherwise.