TorchLean API

FloatLib.Floats.Formats.OCP.MX.Standard.DotProduct.Proof

Numerical correctness of exact MX dot products #

The executable list reductions are related to finite sums of decoded rational products and to the factored shared-scale formula of OCP MX 1.0 §6.1. For finite input lanes and a finite binary32 result, the result is one nearest-even rounding of the exact real dot across any number of blocks. Its error is at most half an ULP, including gradual underflow; there is no accumulation error.

Exact finite reduction agrees with the algebraic sum, independently of cancellation.

An indexed finite reduction agrees with the mathematical finite sum.

An infinity survives a reduction whose other terms are finite or infinities of the same sign. The hypothesis excludes both invalid products and opposite-infinity cancellation.

The existing binary rational packer realizes the independent nearest-even real projection. Finiteness excludes overflow, where a real-valued error is not defined.

theorem FloatLib.Floats.Formats.OCP.MX.Standard.dotExact_eq_nan_of_left_lane {leftProfile rightProfile : Profile} (left : Block leftProfile) (right : Block rightProfile) (lane : Fin 32) (exceptional : Numerics.ExceptionalValue) (h : left.decodeLane lane = Numerics.NumericalValue.exceptional exceptional) :

A lane-local NaN on the left propagates through multiplication and the full block sum.

theorem FloatLib.Floats.Formats.OCP.MX.Standard.dotExact_eq_nan_of_right_lane {leftProfile rightProfile : Profile} (left : Block leftProfile) (right : Block rightProfile) (lane : Fin 32) (exceptional : Numerics.ExceptionalValue) (h : right.decodeLane lane = Numerics.NumericalValue.exceptional exceptional) :

A lane-local NaN on the right also poisons the full dot.

A NaN shared scale on either operand poisons the dot independently of element bits.

theorem FloatLib.Floats.Formats.OCP.MX.Standard.dotExact_eq_nan_of_zero_infinity {leftProfile rightProfile : Profile} (left : Block leftProfile) (right : Block rightProfile) (lane : Fin 32) (zero : Numerics.SignedRat) (sign : Bool) (hzero : zero.value = 0) (hleft : left.decodeLane lane = Numerics.NumericalValue.finite zero) (hright : right.decodeLane lane = Numerics.NumericalValue.infinity sign) :

A zero lane multiplied by infinity is invalid even when every other product is finite.

An invalid block dot propagates to the final binary32 NaN across any number of blocks.

@[simp]
theorem FloatLib.Floats.Formats.OCP.MX.Standard.dotGeneral_empty {leftProfile rightProfile : Profile} (left : Vector (Block leftProfile) 0) (right : Vector (Block rightProfile) 0) :

With no blocks there are no exceptional operands, and the result is positive zero.

theorem FloatLib.Floats.Formats.OCP.MX.Standard.dotExact_finite {leftProfile rightProfile : Profile} (left : Block leftProfile) (right : Block rightProfile) (a b : Fin 32Numerics.SignedRat) (ha : ∀ (i : Fin 32), left.decodeLane i = Numerics.NumericalValue.finite (a i)) (hb : ∀ (i : Fin 32), right.decodeLane i = Numerics.NumericalValue.finite (b i)) :
dotExact left right = Numerics.NumericalValue.finite (∑ i : Fin 32, (a i).value * (b i).value)

Finite decoded lanes are multiplied and accumulated exactly, even when they cancel.

theorem FloatLib.Floats.Formats.OCP.MX.Standard.toReal_dot_eq_roundAt {leftProfile rightProfile : Profile} (left : Block leftProfile) (right : Block rightProfile) (a b : Fin 32Numerics.SignedRat) (ha : ∀ (i : Fin 32), left.decodeLane i = Numerics.NumericalValue.finite (a i)) (hb : ∀ (i : Fin 32), right.decodeLane i = Numerics.NumericalValue.finite (b i)) (hfinite : (dot left right).isFinite = true) :

A finite one-block result is one nearest-even rounding of its exact real dot.

theorem FloatLib.Floats.Formats.OCP.MX.Standard.abs_toReal_dot_sub_le {leftProfile rightProfile : Profile} (left : Block leftProfile) (right : Block rightProfile) (a b : Fin 32Numerics.SignedRat) (ha : ∀ (i : Fin 32), left.decodeLane i = Numerics.NumericalValue.finite (a i)) (hb : ∀ (i : Fin 32), right.decodeLane i = Numerics.NumericalValue.finite (b i)) (hfinite : (dot left right).isFinite = true) :
|(dot left right).toReal - i : Fin 32, (a i).value * (b i).value| BinaryInterchange.Model.epsilonAt BinaryInterchange.FloatFormat.binary32 (∑ i : Fin 32, (a i).value * (b i).value)

The one-block dot also incurs only the final half-ULP rounding error.

theorem FloatLib.Floats.Formats.OCP.MX.Standard.dotExact_eq_scaled_sum {leftProfile rightProfile : Profile} (left : Block leftProfile) (right : Block rightProfile) (a b : Fin 32Numerics.SignedRat) (leftExponent rightExponent : ) (hleft : left.scale.exponent? = some leftExponent) (hright : right.scale.exponent? = some rightExponent) (ha : ∀ (i : Fin 32), left.values[i].decode = Numerics.NumericalValue.finite (a i)) (hb : ∀ (i : Fin 32), right.values[i].decode = Numerics.NumericalValue.finite (b i)) :
dotExact left right = Numerics.NumericalValue.finite (2 ^ leftExponent * 2 ^ rightExponent * i : Fin 32, (a i).value * (b i).value)

The exact block reduction equals the specification's factored shared-scale expression.

theorem FloatLib.Floats.Formats.OCP.MX.Standard.dotGeneralExact_finite {leftProfile rightProfile : Profile} {n : } (left : Vector (Block leftProfile) n) (right : Vector (Block rightProfile) n) (a b : Fin nFin 32Numerics.SignedRat) (ha : ∀ (j : Fin n) (i : Fin 32), left[j].decodeLane i = Numerics.NumericalValue.finite (a j i)) (hb : ∀ (j : Fin n) (i : Fin 32), right[j].decodeLane i = Numerics.NumericalValue.finite (b j i)) :
dotGeneralExact left right = Numerics.NumericalValue.finite (∑ j : Fin n, i : Fin 32, (a j i).value * (b j i).value)

General accumulation sums every exact lane product without intermediate rounding.

Real exact dot of decoded lanes, without an intermediate representability restriction.

Instances For
    theorem FloatLib.Floats.Formats.OCP.MX.Standard.toReal_dotGeneral_eq_roundAt {leftProfile rightProfile : Profile} {n : } (left : Vector (Block leftProfile) n) (right : Vector (Block rightProfile) n) (a b : Fin nFin 32Numerics.SignedRat) (ha : ∀ (j : Fin n) (i : Fin 32), left[j].decodeLane i = Numerics.NumericalValue.finite (a j i)) (hb : ∀ (j : Fin n) (i : Fin 32), right[j].decodeLane i = Numerics.NumericalValue.finite (b j i)) (hfinite : (dotGeneral left right).isFinite = true) :

    The final finite binary32 result is one nearest-even rounding of the exact real dot.

    theorem FloatLib.Floats.Formats.OCP.MX.Standard.abs_toReal_dotGeneral_sub_le {leftProfile rightProfile : Profile} {n : } (left : Vector (Block leftProfile) n) (right : Vector (Block rightProfile) n) (a b : Fin nFin 32Numerics.SignedRat) (ha : ∀ (j : Fin n) (i : Fin 32), left[j].decodeLane i = Numerics.NumericalValue.finite (a j i)) (hb : ∀ (j : Fin n) (i : Fin 32), right[j].decodeLane i = Numerics.NumericalValue.finite (b j i)) (hfinite : (dotGeneral left right).isFinite = true) :

    Finite-result absolute error is at most half an ULP of the exact dot. This includes subnormal results and cancellation; there is no error from the number or order of finite summands.