TorchLean API

FloatLib.Floats.Formats.IEEE754.Native

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:

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 #

Exact encoded-word transport #

@[simp]

Extracting the word just used to construct binary32 returns that word.

@[simp]

Extracting the word just used to construct binary64 returns that word.

Lean runtime types #

@[inline]

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
    @[inline]

    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
      @[simp]

      Native binary32 conversion exposes exactly Lean's public interchange word.

      @[inline]

      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
        @[simp]

        Native binary64 conversion exposes exactly Lean's public interchange word.

        Exact source integration #

        @[instance_reducible]

        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.

        @[instance_reducible]

        Lean's native binary64 participates as an exact signed-rational conversion source.

        @[simp]

        The native binary32 source capability uses exact interchange decoding.

        @[simp]

        The native binary64 source capability uses exact interchange decoding.