TorchLean API

NN.Floats.FP32.Core

FP32: TorchLean's proof-oriented float32 semantics #

FP32 is a proof-oriented float32 semantics: it models float computations as real-number operations over $\mathbb{R}$ followed by rounding to a fixed binary32 grid after each primitive operation. This abstraction is designed to support compositional rounding-error bounds over long computations.

What this model does cover:

What this model does not cover:

Special-value semantics live in the executable IEEE32Exec model. Bridge lemmas relate IEEE32Exec back to FP32 on the finite/no-overflow fragment.

Canonical IEEE-754 binary32 configuration #

Exponent function for the gradual-underflow part of IEEE-754 binary32, expressed in Flocq style.

Two numbers here matter:

  • prec = 24: binary32 has 23 stored fraction bits, but 24 bits of precision for normal numbers once you include the implicit leading $1$.
  • emin = -149: the smallest positive subnormal is $2^{-149}$. Using emin = -149 is the usual way to encode gradual underflow in this “rounding on $\mathbb{R}$” model.

FLTExp has no upper exponent bound. Overflow and the transition to infinity belong to IEEE32Exec, not this exponent function.

Instances For

    fexp32 is the binary32-compatible exponent function used by FP32.

    noncomputable def TorchLean.Floats.rnd32 :

    Round-to-nearest, ties-to-even (binary32-style default rounding).

    This is the rounding mode people typically assume when they say “IEEE float32 rounding”.

    Instances For

      rnd32 is a valid monotone rounding mode in the generic neural-float sense.

      rnd32 is round-to-nearest in the NeuralValidRndToNearest sense.

      @[reducible, inline]

      FP32: finite float32 rounding model, as a rounded real value.

      This is the type you want if you are proving numerical stability/error bounds without dealing with NaN/Inf behavior.

      Instances For
        @[reducible, inline]

        Forgetful projection: treat an FP32 value as a real number.

        Instances For

          Canonical effective mantissa/exponent representation of binary32 rounded-real rounding.

          The result of FP32 addition has the canonical mantissa/exponent representation computed by the effective nearest-even rounding layer.

          Effective representation of FP32 subtraction.

          Effective representation of FP32 multiplication.

          Effective representation of FP32 division.

          The largest finite IEEE-754 binary32 magnitude, $(2-2^{-23})2^{127}$.

          This is a bridge guard, not a maximum of FP32: the proof-oriented FLTExp (-149) 24 model has gradual underflow but no upper exponent bound. Executable IEEE binary32 operations must establish this bound before transferring a finite result into the rounded-real model.

          Instances For

            Mantissa/exponent form of the largest finite binary32 magnitude.

            The largest finite binary32 value lies strictly below 2^128.

            Convenience constant: the smallest positive normal binary32 number (approximately $2^{-126}$).

            Subnormals exist below this; this constant is mainly useful when you want to distinguish “normal-range” arguments from “subnormal-range” arguments in proofs.

            Instances For
              @[simp]

              The binary32 minimum normal value is $2^{-126}$.