TorchLean API

NN.Floats.IEEEExec.BridgeInitFloat32

BridgeInitFloat32 #

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 intended connection as a typeclass interface. If you (or your trusted runtime) can discharge the assumptions that the 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 the internal refinement theorems (BridgeFP32.lean / BridgeFP32Expr.lean) to connect execution to the FP32 rounding-on- model on finite/no-overflow inputs.

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

Background:

@[reducible, inline]

Local alias for Lean's runtime Float32 type.

Instances For
    @[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:

        We keep this separation because it makes the trust boundary explicit: the only “axioms” are the bit-level runtime correctness assumptions below.

        External correctness assumptions #

        Assumption package relating Lean's runtime Float32 primitives to IEEE32Exec.

        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).

          Rewrite runtime float32 square root into executable IEEE32Exec.sqrt (value-level form).