TorchLean API

NN.Proofs.RuntimeApprox.Reductions.IEEE32

Reductions #

Deployment-aware reduction semantics for ExecFloat.Binary 8 23.

In deployed environments, reductions (sums / dot-products / matmul accumulations) may be evaluated using different valid parenthesizations and, depending on the implementation, different leaf orders. Since floating-point addition is not associative, distinct reduction schedules can produce distinct results.

This module models a reduction as "any result produced by a valid reduction tree over the same leaves" and proves a standard forward-error enclosure that holds uniformly over all such trees.

What this file proves #

Assuming a local rounded-addition model with parameter u, we derive a global enclosure whose parameters depend only on:

The bound uses the geometric factor $(1+u)^{n-1}-1$, not the rational $\gamma_k$ bound. The generic rounding hypothesis quantifies over all real operands. Finiteness of one tree does not establish it, and binary32 underflow prevents choosing the usual unit roundoff globally over arbitrary real operands. The _binary32 corollaries instead reuse FloatLib's bounds for the tree's own representable operands. They admit u = 2⁻²⁴, including subnormal sums, under the finite-execution hypothesis alone. These are mathematical enclosures, not native-kernel checks.

For ExecFloat.Binary 8 23, we connect the executable add to the real model Model.roundAt FloatFormat.binary32 (a + b), but only on the finite branch. If Inf/NaN/ overflow is possible, the right semantics is the special-value semantics from FloatLib, so this file keeps those cases out of scope via FiniteEval*.

This is a direct formalization of standard numerical-analysis results for parallel sums:

Instead of bounding nondeterminism, another design direction is to eliminate it via reproducible accumulators/binned sums. That literature is a complement to this file:

ExecFloat.Binary 8 23: evaluation + nondeterminism (expression tree + permutation) #

FiniteEvalSumTree t means:

  • every leaf is finite, and
  • every internal add evaluates on the finite branch (no Inf/NaN result).

We need this hypothesis when relating the executable semantics to the real model Model.roundAt FloatFormat.binary32 (toReal a + toReal b): if an add can overflow to Inf or produce a NaN, the correct semantic layer is FloatLib's special-value semantics, not a small-error enclosure.

Instances For

    Real-valued “finite-branch model” of evalIEEE.

    Every internal node uses Model.roundAt FloatFormat.binary32 (a+b). This is the usual round-to-nearest floating-point model when the result stays finite; our bridge lemmas justify this model under FiniteEvalSumTree.

    Instances For

      Enclosure theorem for nondeterministic FP32 sums.

      sumTreeResult xs r means: r is the result of adding the elements of xs using executable ExecFloat.add, but with an evaluation order that is allowed to vary (a reduction tree plus a permutation of leaves).

      The conclusion produces a witness tree t and a bound on how far toReal r can deviate from the exact real sum of t’s leaves (measured against the leaf scale sumAbsIEEE t).

      A finite binary32 sum has the usual unit-roundoff enclosure, including subnormal sums.

      FloatLib bounds addition on this tree's own representable operands. Unlike the generic enclosure, this corollary needs no rounding assumption quantified over arbitrary real inputs.

      Dot-product accumulation (sum of products) #

      Leaves are operand pairs, evaluated by executable multiplication; internal nodes use executable addition. The enclosure bounds accumulation error relative to the exact sum of the already-rounded products. Bounding error against the original real dot product additionally needs multiplication error bounds. This schedule does not model fused multiply-add or establish which schedule a native matmul, convolution, or attention kernel uses.

      theorem TorchLean.Floats.IEEE754.IEEE32Exec.dotTreeResult_enclosure (xs : Array (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) evalIEEE._proof_1 evalIEEE._proof_2 evalIEEE._proof_3 evalIEEE._proof_4 × FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) evalIEEE._proof_1 evalIEEE._proof_2 evalIEEE._proof_3 evalIEEE._proof_4)) (r : FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) evalIEEE._proof_1 evalIEEE._proof_2 evalIEEE._proof_3 evalIEEE._proof_4) (hres : dotTreeResult xs r) (u : ℝ) (H : RelativeLocalAddBound (fun (a b : ℝ) => FloatLib.Floats.Formats.BinaryInterchange.Model.roundAt FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.binary32 (a + b)) u) (hu : 0 ≤ u) :

      Enclosure theorem for nondeterministic dot-product accumulation.

      dotTreeResult xs r means: the runtime computed r by taking the array of pairs xs, multiplying each pair, and then summing the products using some reduction tree whose leaves are a permutation of xs.

      The conclusion gives a witness tree t for that schedule and an order-independent enclosure: the accumulation result is close (in $\mathbb{R}$) to the exact sum of leaf products, with the same growth factor bound as in the plain-sum case.

      theorem TorchLean.Floats.IEEE754.IEEE32Exec.dotTreeResult_enclosure_binary32 (xs : Array (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) evalIEEE._proof_1 evalIEEE._proof_2 evalIEEE._proof_3 evalIEEE._proof_4 × FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) evalIEEE._proof_1 evalIEEE._proof_2 evalIEEE._proof_3 evalIEEE._proof_4)) (r : FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) evalIEEE._proof_1 evalIEEE._proof_2 evalIEEE._proof_3 evalIEEE._proof_4) (result : dotTreeResult xs r) :

      Binary32 dot-product accumulation needs only finite products and finite intermediate sums. The reference is the exact sum of the already-rounded products, not the original real dot product.