Lean native floating-point interoperability #
Explicit conversions connect ExecFloat.Binary (exponentBits := 8) (fractionBits := 23) and
ExecFloat.Binary (exponentBits := 11) (fractionBits := 52) to Lean's runtime Float32 and
Float types. Lean names its IEEE binary64 runtime type Float; there is no separate core type
named Float64.
The conversion boundary is explicit:
ofBits32,toBits32,ofBits64, andtoBits64transport every interchange word exactly inside FloatLib;- the native conversions use Lean's public
Float32.ofBits,Float32.toBits,Float.ofBits, andFloat.toBitsoperations; - Lean's logical model of
Float32.ofBitsandFloat.ofBitscanonicalizes NaN payloads, and the compiled runtime primitives do the same (a compiled(Float32.ofBits 0x7f800001).toBitsis0x7fc00000); exact payload-preserving transport therefore stays in theofBits32/toBits32andofBits64/toBits64APIs.
The conversions themselves do not choose an arithmetic backend. Configured binary32 and binary64
arithmetic uses proved software kernels by default. Applications may call
Configured.NativeFPU.Unchecked explicitly for guarded host arithmetic, but those functions are
outside the proof-carrying planner and depend on the compiler and host runtime.
Lean 4.34 exposes more definitions in its logical float model. The companion Native.Integer
module connects integer conversion to FloatLib's rounding specifications. Native.AddSub proves
agreement for finite operands, and Native.Sqrt covers every input after NaN canonicalization.
Import FloatLib.Floats.Formats.IEEE754 or FloatLib to include these proofs alongside the
conversions.
References #
- IEEE 754-2019, Sections 3.4 and 3.6, defines binary interchange encodings.
- Lean's
Init.Data.Float.Float32andInit.Data.Float.Floatmodules define the runtime types, their logical models, and the model-based conversion boundary used here.
Exact encoded-word transport #
Construct configured IEEE binary32 from an exact 32-bit interchange word.
Instances For
Extract the exact 32-bit interchange word from configured IEEE binary32.
Instances For
Reconstructing binary32 from its exact interchange word returns the original value.
Construct configured IEEE binary64 from an exact 64-bit interchange word.
Instances For
Extract the exact 64-bit interchange word from configured IEEE binary64.
Instances For
Reconstructing binary64 from its exact interchange word returns the original value.
Lean runtime types #
Convert Lean's native binary32 value to configured ExecFloat binary32.
The definition uses Lean's public interchange conversion Float32.toBits. Its logical model and
the compiled primitive agree on every finite value and infinity; a NaN reaches this function
already canonicalized by whichever operation produced it.
Instances For
Convert configured ExecFloat binary32 to Lean's native Float32.
Both the logical model of Float32.ofBits and its compiled primitive canonicalize a
noncanonical NaN payload, so a configured NaN with a payload does not round-trip through this
function. Use toBits32 for payload-preserving serialization inside FloatLib.
Instances For
The logical model of a converted binary32 value is constructed from the same word.
Converting configured binary32 through Lean's native model performs exactly the canonical-NaN normalization already defined by the generic Lean-model bridge.
Convert Lean's native binary64 Float to configured ExecFloat binary64.
Lean calls its 64-bit IEEE runtime type Float.
Instances For
Convert configured ExecFloat binary64 to Lean's native binary64 Float.
Both the logical model of Float.ofBits and its compiled primitive canonicalize a noncanonical
NaN payload, so a configured NaN with a payload does not round-trip through this function. Use
toBits64 for payload-preserving serialization inside FloatLib.
Instances For
The logical model of a converted binary64 value is constructed from the same word.
Converting configured binary64 through Lean's native model performs exactly the canonical-NaN normalization already defined by the generic Lean-model bridge.
Exact source integration #
Lean's native binary32 participates as an exact signed-rational conversion source.
The decoder crosses the already documented native bit boundary and then uses the configured
binary32 decoder, so -0.0 decodes to SignedRat.negZero. Destination selection remains explicit
through ExecFloat.convert; native types are not placed in an implicit promotion lattice.
Lean's native binary64 participates as an exact signed-rational conversion source.
The native binary32 source capability uses exact interchange decoding.
The native binary64 source capability uses exact interchange decoding.