Flocq-style formats (FIX / FLX / FLT) #
We are not defining the executable IEEE-754 layer here.
What we do here is the same separation used by Flocq:
Core.leangives us mantissa/exponent arithmetic on $\mathbb{R}$ plusbpow,mag, andcexp;- this file defines format families via exponent-selection functions
fexp : ℤ → ℤ.
Those fexps let us talk about “a fixed-point grid”, “an unbounded float grid”, or “a float grid
with a lower exponent bound and gradual underflow” without committing to a concrete bit encoding.
In particular:
FIX_*models a fixed exponent (useful for quantization / fixed-point reasoning),FLX_*models an unbounded exponent float (a convenient intermediate model),FLT_*has a lower exponent bound and gradual underflow, but no upper bound or overflow.
If you want NaN/Inf/signed-zero and an executable kernel, that is NN/Floats/IEEEExec/.
For TorchLean-specific “which precision do we use in each phase?” configuration helpers, see
NN/Floats/NeuralFloat/Metadata.lean.
References:
- Flocq project: https://flocq.gitlabpages.inria.fr/flocq/
- S. Boldo, G. Melquiond, “Flocq: a unified Coq library for proving floating-point algorithms correct” (ARITH 2011), DOI: 10.1109/ARITH.2011.40
- IEEE Standard for Floating-Point Arithmetic (IEEE 754-2019)
A positive number of radix digits for FLX, FLT, and FTZ formats.
Raw exponent functions remain available for algebraic proofs, but callers accepting an integer
configuration should first use NeuralFormatPrecision.ofInt?. This prevents a zero or negative
precision from being silently reinterpreted through an absolute-value conversion.
- digits : ℕ
Number of radix digits retained by the format.
A floating-point precision has at least one radix digit.
Instances For
Instances For
Instances For
Convert a proof-carrying format precision to the integer parameter used by exponent formulas.
Instances For
Check a natural-number precision at a configuration boundary.
Instances For
Check an integer precision, rejecting zero and every negative value.
Instances For
A checked precision remains positive after conversion to the integer exponent parameter.
FIX_exp emin is the simplest exponent-selection function: it always returns the same exponent.
This is the Flocq “FIX” family. It is useful when you want to reason about values living on a single, fixed grid $\beta^{\mathtt{emin}}\mathbb{Z}$ (think: fixed-point arithmetic or quantization).
Instances For
FIX_exp satisfies the standard Flocq-style Valid_exp axioms (here: NeuralValidExp).
Even though the proof is trivial, having the instance is what lets later theorems reuse the same generic lemmas for FIX/FLX/FLT.
The ULP at zero for a fixed-point grid is its fixed grid step.
FIX_format emin x says “x is exactly representable on the fixed grid”.
This is phrased via an existential NeuralFloat β so that it composes smoothly with the rest of
the rounding model (neural_to_real, ULP bounds, etc.).
Instances For
FLX_exp prec is the unbounded-exponent family.
This is Flocq’s “FLX” family: it models a floating-point format with no exponent bounds but with
a mantissa precision parameter prec. It is a convenient intermediate model for proofs because it
removes underflow/overflow corner cases while still tracking mantissa rounding.
Instances For
FLX_exp satisfies NeuralValidExp.
The side-condition 0 < prec matches the standard assumption that “precision is positive”.
Instances For
FLXExp prec satisfies the generic exponent axioms exactly when prec is positive.
The unbounded exponent selector associated with a checked precision.
Instances For
A checked precision automatically discharges the FLX exponent-validity obligation.
Instances For
Instances For
Exact representability predicate for FLX.
Heuristically, there exists a mantissa/exponent pair with mantissa bounded by the precision, and $x=m\beta^e$.
Instances For
Nonpositive precision is rejected by the explicit FLX format predicate.
The unbounded FLX exponent function has no negligible exponent.
Consequently, the generic ULP of zero is zero for FLX.
FLT_exp emin prec is the lower-exponent-bounded family with gradual underflow.
This is Flocq’s “FLT” family. The exponent is bounded below by emin, but it has no upper bound, so
this rounded-real format models gradual underflow but not overflow, infinities, or NaNs. Gradual
underflow is captured by taking max (e - prec) emin.
Instances For
FLT_exp satisfies NeuralValidExp.
This is where most format-bridge lemmas live when connecting proofs to float32-style bounds
(e.g. via NN/Floats/FP32).
Instances For
FLTExp emin prec satisfies the exponent axioms exactly for positive precision.
The gradual-underflow exponent selector associated with a checked precision.
Instances For
A checked precision automatically discharges the gradual-underflow validity obligation.
Instances For
Instances For
Exact representability predicate for FLT.
This version includes:
- a mantissa size bound (precision),
- and the lower exponent bound $\mathtt{emin}\le\mathtt{exponent}$ (no values smaller than the
minimum normal/subnormal
scale, depending on the choice of
eminand rounding).
Instances For
Nonpositive precision is rejected by the explicit FLT format predicate.
FLT has a negligible-exponent witness at emin.
The ULP at zero for FLT is the smallest grid step $\beta^{\mathtt{emin}}$.