TorchLean API

NN.Floats.NeuralFloat.Conversion

NeuralFloat Conversion Helpers #

This module contains small utilities for moving values between:

Important scope note:

If you are doing proofs about rounding error, prefer theorems in:

Conversion result with error tracking.

  • value : α

    Converted value.

  • error_bound :

    Absolute error bound for the conversion step.

    For conversions that only repackage an already-rounded value, this may be a metadata field rather than a proved bound.

  • is_exact : Bool

    Whether the conversion was exact (error_bound = 0).

  • ulp_error : Option

    Optional ULP-scale metadata at the input point.

    This is not itself an error bound. For round-to-nearest, a typical one-step error bound is ulp(x)/2, proved separately (see neural_error_bound_ulp).

  • target_phase : TrainingPhase

    Training phase used when interpreting ULP scaling hooks.

Instances For

    Convert a NeuralFloat β payload to its real semantics, returning lightweight metadata.

    In words: the returned value is exactly neural_to_real f. The error_bound field is the metadata stored in the input record (it is not recomputed here).

    Instances For

      Round a real number x onto the (β,fexp,rnd) grid and package it as a NeuralFloat β.

      In words: The returned payload is the same one used by neural_round (it uses mantissa := rnd (scaled_mantissa x) and exponent := cexp x), and error_bound = |neural_to_real(value) - x| is the actual absolute error for this rounding step.

      If you additionally assume round-to-nearest (NeuralValidRndToNearest), the theorem neural_error_bound_ulp bounds this error by ulp(x)/2.

      Instances For

        Convert list of reals to neural floats

        Instances For

          Convert neural floats back to reals

          Instances For
            noncomputable def TorchLean.Floats.Conversion.testRoundTripAccuracy {β : NeuralRadix} {fexp : } [NeuralValidExp fexp] (original : ) (rnd : ) [NeuralValidRnd rnd] (phase : TrainingPhase := TrainingPhase.forward) :

            Test conversion round-trip accuracy

            Instances For
              noncomputable def TorchLean.Floats.Conversion.validateNeuralConversion (original : ) (converted : NeuralConversionResult ) (tolerance : ) :

              Validate conversion preserves essential properties

              Instances For