TorchLean API

NN.MLTheory.Proofs.Approximation.Universal.UniversalApproximationFP32

Exact ReLU interpolation and FP32 error lifting #

This file has two jobs.

First, it proves an exact interpolation lemma on a uniform grid: given arbitrary target values at the grid points, we construct a two-layer ReLU MLP that matches those values exactly under the ideal semantics. This is the familiar hinge-basis construction behind one-dimensional piecewise-linear approximation; see Pinkus for the approximation-theory background and Yarotsky for quantitative ReLU-network rates.

Second, it states the FP32 lifting layer: once a real construction is fixed, explicit rounding-error bounds turn it into an FP32 approximation theorem. This keeps the architecture clean: real approximation, parameter rounding, and executable IEEE semantics are proved in separate modules, matching the numerical-analysis separation used in Goldberg and Higham.

theorem NN.MLTheory.Proofs.UniversalApproximation.relu_mlp_exact_on_uniform_grid {a b : } (h_ab : a < b) {N : } :
0 < N∀ (y : Fin (N + 1)), ∃ (l1 : Spec.LinearSpec 1 N) (l2 : Spec.LinearSpec N 1), ∀ (k : Fin (N + 1)), mlpEval1d N l1 l2 (a + k * ((b - a) / N)) = y k

Exact interpolation on a uniform grid by a 2-layer ReLU MLP (over semantics).

Given arbitrary target values y₀,…,y_N at the uniform grid points grid k = a + k * ((b-a)/N), this constructs a width-N hinge network that matches them at the grid points.

FP32 (rounding-on-ℝ) error propagation for the hinge construction #

This section does not claim that FP32 is equivalent to hardware float32. It proves a pointwise bound for evaluating the same hinge network with rounded operations (TorchLean.Floats.FP32) versus exact real arithmetic on the rounded inputs/weights.

@[reducible, inline]

Alias for the “round-after-each-primitive” real-valued FP32 model (TorchLean.Floats.FP32).

Instances For
    noncomputable def NN.MLTheory.Proofs.UniversalApproximation.mlpEval1dFp32 (hidDim : ) (l1 : Spec.LinearSpec FP32 1 hidDim) (l2 : Spec.LinearSpec FP32 hidDim 1) (x : FP32) :

    Evaluate a 2-layer ReLU MLP on a scalar FP32 input (returns an FP32 scalar).

    Instances For
      @[inline]

      Scalar ReLU on FP32. (No rounding: it is max x 0 at the FP32 level.)

      Instances For

        Real ReLU is 1-Lipschitz.

        This elementary analytic fact is what lets the FP32 error analysis pass a subtraction-rounding error through the ReLU nonlinearity without amplifying it.

        FP32 hinge layers and a pointwise error bound #

        First FP32 hinge layer: hidden unit i computes x - tᵢ before ReLU.

        Instances For

          Second FP32 hinge layer: sum hidden activations with coefficients cᵢ and bias b.

          Instances For
            noncomputable def NN.MLTheory.Proofs.UniversalApproximation.hingeTermFp32 {n : } (c t : Fin nFP32) (x : FP32) (i : Fin n) :

            One rounded hinge term cᵢ * reluFp32 (x - tᵢ) in the FP32 model.

            Instances For
              noncomputable def NN.MLTheory.Proofs.UniversalApproximation.hingeTermReal {n : } (c t : Fin nFP32) (x : FP32) (i : Fin n) :

              Real reference for the same hinge term, using the .val denotation of FP32 parameters.

              Instances For

                Per-neuron FP32 hinge-term error bound.

                The bound has two pieces: one half-ulp term for the final multiplication and one subtraction rounding term propagated through the 1-Lipschitz ReLU and scaled by |cᵢ|.

                noncomputable def NN.MLTheory.Proofs.UniversalApproximation.hingeTermErrorBound {n : } (c t : Fin nFP32) (x : FP32) (i : Fin n) :

                The per-hinge error bound used by hinge_term_abs_error.

                Instances For

                  Summation error propagation (FP32 hinge network) #

                  @[reducible, inline]

                  Fold state for summing hinge terms in FP32, while tracking:

                  • a real reference sum (computed from .val),
                  • and a provable error bound on the difference between them.
                  Instances For

                    One summation step: add a hinge term, and accumulate rounding+term error bounds.

                    Instances For

                      Compute the hinge-term sum state over all Fin n in a fixed order (List.finRange).

                      Instances For
                        noncomputable def NN.MLTheory.Proofs.UniversalApproximation.hingeSumFp32 {n : } (c t : Fin nFP32) (x : FP32) :

                        FP32 value produced by folding all hinge terms in the fixed List.finRange order.

                        Instances For
                          noncomputable def NN.MLTheory.Proofs.UniversalApproximation.hingeSumReal {n : } (c t : Fin nFP32) (x : FP32) :

                          Real reference sum accumulated alongside hingeSumFp32.

                          Instances For

                            Accumulated certified absolute-error budget for hingeSumFp32.

                            Instances For
                              theorem NN.MLTheory.Proofs.UniversalApproximation.hinge_sum_state_invariant_aux {n : } (c t : Fin nFP32) (x : FP32) (xs : List (Fin n)) (acc32 : FP32) (accR err : ) :
                              |acc32.val - accR| errhave st := List.foldl (hingeSumStateStep c t x) (acc32, accR, err) xs; |st.1.val - st.2.1| st.2.2

                              Fold invariant for FP32 hinge summation.

                              At every prefix of the fold, the rounded accumulator is within the tracked error budget of the real accumulator. The proof is deliberately order-sensitive because floating-point addition is not associative.

                              Certified absolute-error bound for the whole FP32 hinge-term sum.

                              noncomputable def NN.MLTheory.Proofs.UniversalApproximation.hingeFunFp32 {n : } (t c : Fin nFP32) (b x : FP32) :

                              FP32 hinge-network output: sum of hinge terms, then add the bias.

                              Instances For
                                noncomputable def NN.MLTheory.Proofs.UniversalApproximation.hingeFunReal {n : } (t c : Fin nFP32) (b x : FP32) :

                                Real reference for hinge_fun_fp32: evaluate over on the .val parameters/inputs.

                                Instances For
                                  noncomputable def NN.MLTheory.Proofs.UniversalApproximation.hingeFunErrorBound {n : } (t c : Fin nFP32) (b x : FP32) :

                                  Total FP32 hinge-network error budget, including the final rounded bias addition.

                                  Instances For

                                    Certified absolute-error bound for the complete FP32 hinge network.

                                    This composes the fold invariant with the final rounded + b, giving the main FP32 rounding term used by the executable approximation theorems.

                                    Real approximation + rounding combination (pointwise) #

                                    Triangle bound combining real approximation error with FP32 rounding error.

                                    The theorem is pointwise: it does not construct the approximating hinge parameters, it simply says that once a real hinge network is close to f, the rounded FP32 network is close up to the certified rounding budget.

                                    theorem NN.MLTheory.Proofs.UniversalApproximation.hinge_fun_total_abs_error_lt {n : } (f : ) (t c : Fin nFP32) (b x : FP32) {ε : } ( : |f x.val - hingeFunReal t c b x| < ε) :
                                    |f x.val - (hingeFunFp32 t c b x).val| < ε + hingeFunErrorBound t c b x

                                    Strict version of hinge_fun_total_abs_error_le for use with < ε approximation statements.

                                    The real reference accumulator is the ordinary finite sum of real hinge terms.

                                    theorem NN.MLTheory.Proofs.UniversalApproximation.relu_universal_approximation_Icc_fp32 {f : } {a b L : } (h_ab : a < b) (hL : 0 < L) (h_lip : xSet.Icc a b, ySet.Icc a b, |f x - f y| L * |x - y|) (ε : ) :
                                    ε > 0∃ (hidDim : ) (t : Fin hidDimFP32) (c : Fin hidDimFP32) (b0 : FP32), xSet.Icc a b, |f x - (hingeFunFp32 t c b0 { val := x }).val| < ε + hingeFunErrorBound t c b0 { val := x }

                                    1D ReLU approximation with a pointwise FP32 rounding bound.

                                    This combines:

                                    • the constructive real-valued hinge-network approximation theorem (relu_universal_approximation_Icc_hinge), and
                                    • the FP32 hinge-network rounding bound (hinge_fun_total_abs_error_lt).

                                    The output network is evaluated on the FP32 model (NF rounding-on-); the additional rounding error is given by hinge_fun_error_bound.