TorchLean API

NN.Proofs.RuntimeApprox.Reductions.Tree

Reduction-tree error enclosure #

A binary tree records the parenthesization of a rounded sum. Under the explicit local RelativeLocalAddBound hypothesis, every such tree satisfies the same leaf-count and absolute-leaf-scale error enclosure. The argument is independent of a floating-point format. We retain the array-facing schedule API and use FloatLib's generic reduction-tree error bound.

Binary32 does not satisfy the relative bound globally over arbitrary real operands. The separate IEEE32 module also provides tree-local corollaries: addition of representable operands inherits FloatLib's usual unit-roundoff bound whenever every intermediate sum is finite.

Generic reduction trees over $\mathbb{R}$ #

A binary reduction schedule.

Leaves contain inputs of type α; internal nodes indicate “evaluate left and right subtrees, then combine”. Different trees represent different valid parenthesizations for a parallel reduction.

Instances For
    Instances For
      @[instance_reducible]
      instance TorchLean.Floats.IEEE754.instReprSumTree {α✝ : Type u_1} [Repr α✝] :
      Repr (SumTree α✝)

      The leaves of the reduction tree, read left-to-right.

      The numerical collection is an Array. The schedule relation below converts arrays to lists only inside List.Perm, reusing mathlib's established permutation theory without exposing list-backed numerical data in the API.

      Instances For

        Number of leaves in the tree (the “reduction length”).

        Instances For

          A reduction tree always has at least one leaf.

          Growth factor (1+u)^(n-1) for a reduction with n leaves.

          Instances For
            def TorchLean.Floats.IEEE754.evalRound {α : Type u} (roundAdd : ℝ → ℝ → ℝ) (leafVal : α → ℝ) :
            SumTree α → ℝ

            Evaluate a reduction tree using a given “rounded add” at internal nodes.

            evalRound roundAdd leafVal t maps leaves via leafVal, and combines subresults using roundAdd. This abstracts the idea of evaluating a parallel sum with a fixed local rounding model.

            Instances For
              def TorchLean.Floats.IEEE754.exactSum {α : Type u} (leafVal : α → ℝ) :
              SumTree α → ℝ

              Exact real evaluation of the tree (just + at internal nodes).

              Instances For
                def TorchLean.Floats.IEEE754.sumAbs {α : Type u} (leafVal : α → ℝ) :
                SumTree α → ℝ

                Sum of absolute values of leaf contributions.

                This is the standard “scale” that appears in forward-error bounds for floating-point reductions.

                Instances For

                  Relative local rounded-addition assumption for reductions.

                  This is the usual normal-range unit-roundoff envelope: $$ \operatorname{roundAdd}(a,b)=(a+b)+e, \qquad |e|\le u(|a|+|b|). $$ Binary32 does not satisfy it globally with $u=2^{-24}$: subnormal results require an absolute-error term. The executable theorems below take this global predicate as an explicit hypothesis. Normal-range evidence for one evaluation tree cannot establish a bound quantified over all real operands. Applying a normal-range analysis to a particular tree requires a tree-local hypothesis; handling underflow requires an absolute/mixed analysis.

                  Instances For

                    Preserve the schedule when reusing FloatLib's reduction theorems.

                    Instances For
                      theorem TorchLean.Floats.IEEE754.evalRound_enclosure_of_relativeLocalAddBound {α : Type u} (roundAdd : ℝ → ℝ → ℝ) (leafVal : α → ℝ) (u : ℝ) (H : RelativeLocalAddBound roundAdd u) (hu : 0 ≤ u) (t : SumTree α) :
                      |evalRound roundAdd leafVal t - exactSum leafVal t| ≤ (ReductionBound.growth u t.leafCount - 1) * sumAbs leafVal t

                      Order-independent enclosure for any reduction tree evaluated with roundAdd.

                      Let $A=\sum_i|\mathtt{leaf}_i|$ be the sum of absolute values of leaves. For $n$ leaves, the rounded evaluation is within $(\operatorname{growth}(u,n)-1)A$ of the exact real sum.