NF: a rounded scalar type #
FloatRep (the record with a mantissa/exponent) is useful for talking about the grid and for
stating format predicates like FLTFormat. Higher-level specifications are easier to state with
a scalar carrier that already performs the rounding step.
NF β fexp rnd is that scalar carrier:
- it stores a semantic value
val : ℝ, - and every primitive arithmetic operation rounds back to the format using
round.
The public constructor remains available because proof developments sometimes embed an arbitrary
real as a comparison value. Such a value need not be representable. NF.IsRepresentable records the
grid invariant when a theorem needs it; NF.ofReal and arithmetic results establish that invariant.
Addition, for example, satisfies:
val(a + b) = round( val(a) + val(b) )
This is the standard textbook model used for floating-point error analysis: compute in reals, then incur a rounding error at each step (Higham/Goldberg style).
Trust boundary:
NFandFloatRepmodel real values and rounding in Lean.- Instantiating
NFwith IEEE single parameters + round-to-nearest-even models domain-valid, finite, no-overflow arithmetic with binary32's precision and gradual-underflow grid. The format has no upper exponent bound, and Mathlib's real division, square root, and logarithm are totalized; exceptional IEEE behavior belongs toExecFloat.Binary (exponentBits := 8) (fractionBits := 23)and its binary-interchange model. - Correspondence to hardware float32 / Lean's builtin
Floatis not proved in this file; that connection is an external assumption/interface boundary (or requires a separate verified kernel).
Rounded scalar value at a given radix/format/rounding mode.
β is the radix (typically 2), fexp selects the exponent grid, and rnd rounds the scaled
mantissa to an integer.
- val : ℝ
Exact real value represented by this rounded-real model value.
Instances For
Forgetful projection (semantic view): treat an NF as a real number.
Instances For
A default inhabitant (rounded zero).
Negate the real value and round onto the grid. For a representable input, negation is exact.
Checked division rejects exactly the zero-divisor case.
Linear order on NF induced by val, with semantic minimum and maximum.
Positive-base real exponentiation, evaluated as exp (b * log a) and rounded once.
The positivity proof is part of the API so negative bases and 0^0 cannot silently acquire an
arbitrary totalized value.
Instances For
Checked real exponentiation.
Positive bases accept every real exponent. Negative bases accept integer exponents, including
negative integer exponents. Zero uses the usual natural-power convention for nonnegative integer
exponents, maps positive noninteger exponents to zero, and rejects negative exponents. Thus the
remaining rejected case is a negative base with a noninteger exponent. Natural powers can also use
powNat directly.
Instances For
On a positive base, checked exponentiation is the ordinary positive real-power formula.
A positive noninteger exponent of zero uses the unambiguous real value zero.
Evaluate each mathematical function in ℝ and round once. These noncomputable specifications use
Mathlib's totalized real functions; checkedSqrt and checkedLog enforce their usual real domains.