Summary
Float.ofBits and Float.toBits are declared as @[extern] opaque primitives in Init.Data.Float but have no accompanying lemmas establishing their inverse relationship:
@[extern "lean_float_of_bits"] opaque Float.ofBits : UInt64 → Float
@[extern "lean_float_to_bits"] opaque Float.toBits : Float → UInt64
There are currently zero theorems about these functions in the standard library.
Requested additions
axiom Float.ofBits_toBits (f : Float) : Float.ofBits f.toBits = f
axiom Float.toBits_ofBits (u : UInt64) : (Float.ofBits u).toBits = u
Both hold by the C implementation (lean_float_of_bits / lean_float_to_bits are memcpy-based reinterpret casts between double and uint64_t, which are exact inverses on all IEEE 754 platforms).
Motivating use case
I maintain a production Lean 4 codebase that uses a typed data model with a positional JSON codec. The codec serializes Float values via their exact IEEE-754 bit pattern (Float.toBits → UInt64 → Nat → Json.num) and decodes the reverse path. Proving the round-trip property (fromPositionalJson dm (toPositionalJson v) = .ok v) requires knowing that Float.ofBits f.toBits = f.
Without upstream support, I had to introduce a project-local axiom:
-- lean/Spec/Trusted/FloatBits.lean
axiom float_ofBits_toBits (f : Float) : Float.ofBits f.toBits = f
This is the only axiom in the project (714+ sorry-free theorems otherwise). Having this in the standard library would eliminate the need for downstream projects to each introduce their own trusted axiom for the same fact.
Implementation question
Would the Lean team prefer these as:
axiom declarations in Init.Data.Float (simplest, matches the opaque status of the functions), or
- Some other mechanism (e.g.
native_decide-backed, or @[implemented_by])?
Happy to open a PR once there's alignment on the approach.
Summary
Float.ofBitsandFloat.toBitsare declared as@[extern]opaque primitives inInit.Data.Floatbut have no accompanying lemmas establishing their inverse relationship:There are currently zero theorems about these functions in the standard library.
Requested additions
Both hold by the C implementation (
lean_float_of_bits/lean_float_to_bitsarememcpy-based reinterpret casts betweendoubleanduint64_t, which are exact inverses on all IEEE 754 platforms).Motivating use case
I maintain a production Lean 4 codebase that uses a typed data model with a positional JSON codec. The codec serializes
Floatvalues via their exact IEEE-754 bit pattern (Float.toBits→UInt64→Nat→Json.num) and decodes the reverse path. Proving the round-trip property (fromPositionalJson dm (toPositionalJson v) = .ok v) requires knowing thatFloat.ofBits f.toBits = f.Without upstream support, I had to introduce a project-local axiom:
This is the only axiom in the project (714+ sorry-free theorems otherwise). Having this in the standard library would eliminate the need for downstream projects to each introduce their own trusted axiom for the same fact.
Implementation question
Would the Lean team prefer these as:
axiomdeclarations inInit.Data.Float(simplest, matches theopaquestatus of the functions), ornative_decide-backed, or@[implemented_by])?Happy to open a PR once there's alignment on the approach.