NeuralFloat Conversion Helpers #
This module contains small utilities for moving values between:
- real semantics (
ℝ), and - the Flocq-style mantissa/exponent payload
NeuralFloat β.
Important scope note:
- The canonical rounding semantics in this folder is
neural_round(seeRounding.lean), which models one “compute inℝ, then round” step and comes with the key half-ULP theoremneural_error_bound_ulp(under round-to-nearest assumptions). - The helpers in this file are conversion utilities and examples: packaging the rounded result into a
NeuralFloatrecord and attaching a small amount of error/ULP metadata.
If you are doing proofs about rounding error, prefer theorems in:
NN/Floats/NeuralFloat/Rounding.lean(core half-ULP bound), andNN/Floats/NeuralFloat/ErrorBounds.lean(small derived bounds).
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). 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 (seeneural_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
Test conversion round-trip accuracy
Instances For
Validate conversion preserves essential properties