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 () 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 IEEE-754 binary32 (gradual underflow), 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-ℝ” model.
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- 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

          Convenience constant: the largest finite magnitude representable by the binary32 parameters used by this model (i.e. roughly (2 - 2^-23) * 2^127).

          We keep this in FP32 because it is a useful proof-level guard when you want to state “no overflow” side-conditions in a readable way.

          Instances For

            Convenience constant: the smallest positive normal binary32 number (roughly 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