TorchLean API

NN.Floats.IEEEExec.Bridge.RuntimeFloat32

Runtime Float32 Bridge #

External (assumption-based) bridge: Lean's Init.Float32IEEE32Exec.

Why assumptions are necessary: Init.Float32 arithmetic in Lean is implemented by external runtime calls. Those calls are opaque to the Lean kernel, so (inside Lean) we cannot prove that the runtime implementation coincides bit-for-bit with any particular float32 specification.

We package the finite-result connection as a typeclass interface. If you (or your trusted runtime) can discharge the assumptions that finite runtime Float32 primitives match the executable kernel IEEE32Exec bit-for-bit, then you can:

  1. execute with Float32 (runtime),
  2. rewrite the result to IEEE32Exec,
  3. reuse NN/Floats/IEEEExec/Bridge/FP32.lean and NN/Floats/IEEEExec/Bridge/Expressions.lean to connect execution to the FP32 rounding-on- model on finite/no-overflow inputs.

The trust boundary is explicit: the only unproved part is the external/runtime correctness assumption, which is unavoidable in a pure Lean development.

Background:

@[inline]

Reinterpret a runtime Float32 as the executable bit-level float32 (IEEE32Exec).

Instances For
    @[inline]

    Reinterpret an executable float32 bit-pattern as a runtime Float32.

    Instances For

      What this bridge gives us #

      This file does not prove anything about the runtime semantics of Float32. Instead, it gives a clean interface that you can assume/provide:

      NaN payloads are deliberately outside the exact-bit contract: Lean runtimes may canonicalize them, whereas IEEE32Exec preserves a deterministic payload. Classification fields below still relate NaN, infinity, and finiteness for every runtime value.

      External correctness assumptions #

      Assumption package relating the finite-result part of Lean's runtime Float32 primitives to IEEE32Exec. Exact NaN payload agreement is intentionally not required.

      Instances

        Derived bit-level refinement lemmas #

        Derived lemmas (rewriting runtime to executable) #

        The assumptions above are phrased as bit equalities. In practice we almost always want the more convenient value-level rewriting lemmas below:

        toIEEE32Exec (a + b) = IEEE32Exec.add (toIEEE32Exec a) (toIEEE32Exec b), etc.

        These are the lemmas you use to “turn a runtime evaluation into an IEEE32Exec evaluation”.

        Rewrite runtime float32 subtraction into executable IEEE32Exec.sub (value-level form).

        Rewrite runtime float32 multiplication into executable IEEE32Exec.mul (value-level form).

        Rewrite runtime float32 division into executable IEEE32Exec.div (value-level form).

        Rewrite runtime float32 negation into executable IEEE32Exec.neg (value-level form).