TorchLean API

NN.MLTheory.Proofs.Approximation.Universal.UniversalApproximation

Universal approximation (1D, constructive) #

On a compact interval $I=[a,b]$, any Lipschitz function $f:\mathbb{R}\to\mathbb{R}$ can be uniformly approximated by a single-hidden-layer ReLU network (a 2-layer MLP).

This file formalizes the classic constructive proof strategy:

Main result #

References #

@[reducible, inline]

Shorthand for relu in this development, using TorchLean’s spec semantics.

Instances For

    If the knot $t$ is to the left of $x$, then $\operatorname{ReLU}(x-t)=x-t$.

    If $x$ is to the left of the knot $t$, then $\operatorname{ReLU}(x-t)=0$.

    noncomputable def NN.MLTheory.Proofs.UniversalApproximation.mlpEval1d (hidDim : ) (l1 : Spec.LinearSpec 1 hidDim) (l2 : Spec.LinearSpec hidDim 1) (x : ) :

    Evaluate a 2-layer ReLU MLP on a scalar input.

    Instances For

      TorchLean's MLP forward pass is exactly $\operatorname{linear}\circ\operatorname{ReLU}\circ\operatorname{linear}$.

      theorem NN.MLTheory.Proofs.UniversalApproximation.foldl_add_init {α : Type} (l : List α) (f : α) (a : ) :
      List.foldl (fun (acc : ) (x : α) => acc + f x) a l = a + List.foldl (fun (acc : ) (x : α) => acc + f x) 0 l

      Move a scalar initial accumulator out of a left fold that only adds terms.

      This is bookkeeping for converting TorchLean's list-fold tensor semantics into Mathlib finite sums.

      theorem NN.MLTheory.Proofs.UniversalApproximation.finRange_foldl_add (n : ) (f : Fin n) :
      List.foldl (fun (acc : ) (i : Fin n) => acc + f i) 0 (List.finRange n) = i : Fin n, f i

      Convert the List.finRange fold used in matVecMulSpec into a Finset.univ sum.

      vectorN is the dependent-tensor vector constructor expanded pointwise.

      First real hinge layer: hidden unit $i$ computes $x-t_i$ before ReLU.

      Instances For

        Second real hinge layer: sum hidden activations with coefficients $c_i$ and bias $b$.

        Instances For
          noncomputable def NN.MLTheory.Proofs.UniversalApproximation.hingeFun (n : ) (t c : Fin n) (b x : ) :

          Real hinge network $b+\sum_i c_i\operatorname{ReLU}(x-t_i)$.

          Instances For

            Fold lemma matching the scalar tensor accumulator used in matVecMulSpec.

            theorem NN.MLTheory.Proofs.UniversalApproximation.mat_vec_mul_spec_matrixMN_vector (n : ) (c v : Fin n) :
            Spec.matVecMulSpec (Spec.matrixMN 1 n fun (x : Fin 1) (j : Fin n) => c j) (Spec.Tensor.dim fun (j : Fin n) => Spec.Tensor.scalar (v j)) = Spec.Tensor.dim fun (x : Fin 1) => Spec.Tensor.scalar (∑ j : Fin n, c j * v j)

            Matrix-vector multiply for a one-row matrix is the expected finite dot product.

            Matrix-vector multiply by the all-ones column extracts the scalar input into every hidden unit.

            theorem NN.MLTheory.Proofs.UniversalApproximation.mlp_eval_1d_hinge (n : ) (t c : Fin n) (b x : ) :
            mlpEval1d n (hingeLayer1 n t) (hingeLayer2 n c b) x = hingeFun n t c b x

            The explicit two-layer network built from hingeLayer1 and hingeLayer2 computes hingeFun.

            This is the main semantic bridge from the approximation-theory hinge representation to TorchLean's spec-level MLP model.

            theorem NN.MLTheory.Proofs.UniversalApproximation.relu_universal_approximation_Icc_hinge {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 hidDim) (c : Fin hidDim), xSet.Icc a b, |f x - hingeFun hidDim t c (f a) x| < ε

            1D Universal Approximation (ReLU, one hidden layer).

            This is the classic constructive proof: Lipschitz continuity on $[a,b]$, a uniform partition, and piecewise-linear interpolation, then represent the interpolant as a finite linear combination of hinges $\operatorname{ReLU}(x-t_i)$.

            theorem NN.MLTheory.Proofs.UniversalApproximation.relu_universal_approximation_Icc {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 : ) (l1 : Spec.LinearSpec 1 hidDim) (l2 : Spec.LinearSpec hidDim 1), xSet.Icc a b, |f x - mlpEval1d hidDim l1 l2 x| < ε

            1D Universal Approximation (ReLU, one hidden layer), stated as an existence theorem for a 2-layer MLP.

            This is a wrapper around relu_universal_approximation_Icc_hinge that instantiates the linear layers as the explicit hinge construction.