TorchLean API

NN.Floats.IEEEExec.BridgeFP32Expr

BridgeFP32Expr #

Compositional refinement lemmas on top of NN/Floats/IEEEExec/BridgeFP32.lean.

In BridgeFP32.lean we prove refinement theorems one op at a time (add/mul/div/sqrt, etc.). In practice, though, we often want to talk about a whole scalar expression and not re-run the same “op-level” proof script at every node.

This file provides:

so we can state and prove a single theorem that looks like:

toReal (evalRuntime env e) = evalSpec (toReal ∘ env) e

where:

This mirrors the standard mathematical model of float32 evaluation: compute the real operation, then round-to-float32 at each node, provided we stay on the finite path (no NaNs/Infs, no division by zero, no overflow).

References / background (for the rounding model itself, not this AST wrapper):

A small scalar expression language #

Expr is a small, scalar-only AST. TorchLean's main IRs live elsewhere; this wrapper exists to state expression-level refinement theorems for straight-line float32 computations.

A compact AST for scalar float32 expressions evaluated using IEEE32Exec.

Instances For

    Evaluate an Expr using the executable float32 kernel (IEEE32Exec).

    Instances For

      Real semantics for the compact scalar expression language.

      Instances For

        "Finite evaluation" witnesses (finite at every intermediate node) #

        BridgeFP32.lean is explicit about the trust boundary: it bridges only the finite behavior of IEEE32Exec to FP32. For expression-level statements, we therefore need an assumption that every intermediate evaluation remains finite.

        FiniteEval env e d is a proof object that says:

        We store the dyadic because it gives us a convenient “finiteness certificate”: toDyadic? x = some d immediately rules out NaN/Inf and unlocks the op-level bridge lemmas.

        Finite-evaluation witness for the compact scalar expression language.

        Instances For

          Extract the decoded dyadic of the runtime evaluation from a FiniteEval witness.

          Whole-expression refinement #

          This is the main result of the file: a compositional refinement theorem that follows the AST AST shape and invokes the corresponding op-level bridge theorem at each node.

          If you are thinking in PyTorch terms: Expr is a compact “forward graph”, and the result says that the executable float32 evaluation agrees with the standard float32 mathematical model (real arithmetic + rounding) on the finite path.

          Main expression-level refinement theorem for IEEEExec.