TorchLean API

NN.Proofs.Analysis.Lipschitz

Lipschitz continuity library for Tensor-level ops #

This file proves basic norm and distance facts for TorchLean tensors over , and uses them to derive Lipschitz-style bounds for common neural-network building blocks.

Scope and conventions #

PyTorch correspondence / citations #

Typical downstream use #

These lemmas are intended to be imported by higher-level results that need quantitative smoothness statements, e.g.:

References #

noncomputable def Proofs.tensorL2Norm {s : Spec.Shape} (t : Spec.Tensor s) :

L2 norm (Euclidean norm) for tensors. Fundamental for measuring tensor magnitudes and distances.

Instances For
    noncomputable def Proofs.tensorLInftyNorm {s : Spec.Shape} (t : Spec.Tensor s) :

    L∞ norm (maximum norm) for tensors. Important for uniform convergence and pointwise bounds.

    Instances For
      noncomputable def Proofs.tensorL1Norm {s : Spec.Shape} (t : Spec.Tensor s) :

      L1 norm (Manhattan norm) for tensors. Useful for sparsity-inducing regularization.

      Instances For
        noncomputable def Proofs.tensorL2Dist {s : Spec.Shape} (x y : Spec.Tensor s) :

        Distance function based on L2 norm.

        Instances For
          noncomputable def Proofs.tensorLInftyDist {s : Spec.Shape} (x y : Spec.Tensor s) :

          Distance function based on L∞ norm.

          Instances For

            Cross-library norm facts #

            NN.MLTheory.Robustness.Spec defines a scalar-polymorphic tensor_linf_norm. In this file we work over and often use tensor_l2_norm. The key inequality ‖v‖∞ ≤ ‖v‖₂ is what lets L2-based Lipschitz proofs feed directly into the L∞-robustness lemmas.

            For a real vector-valued tensor, the L∞ norm from NN.MLTheory.Robustness.Spec is bounded by the L2 norm from this file:

            ‖v‖∞ ≤ ‖v‖₂.

            L2 norm is non-negative.

            L2 norm is zero iff tensor is zero.

            Basic lemma: dot product with zero tensor is zero.

            theorem Proofs.dot_add_add {s : Spec.Shape} (x y : Spec.Tensor s) :
            Spec.dot (x.addSpec y) (x.addSpec y) = Spec.dot x x + 2 * Spec.dot x y + Spec.dot y y

            Bilinearity of dot product over addition (distributive property).

            theorem Proofs.dot_quadratic_expand {s : Spec.Shape} (x y : Spec.Tensor s) (t : ) :
            Spec.dot (x.addSpec (y.scaleSpec t)) (x.addSpec (y.scaleSpec t)) = Spec.dot x x + 2 * t * Spec.dot x y + t ^ 2 * Spec.dot y y

            Bilinearity of dot product: dot (x + ty) (x + ty) = ||x||² + 2t⟨x,y⟩ + t²||y||²

            Cauchy-Schwarz inequality for tensors. For any tensors x, y: |⟨x,y⟩| ≤ ||x|| * ||y|| This is a fundamental inequality in inner product spaces.

            Triangle inequality for L2 norm.

            Homogeneity of L2 norm.

            theorem Proofs.relu_scalar_lipschitz (x y : ) :
            |max 0 x - max 0 y| |x - y|

            Pointwise ReLU is 1-Lipschitz for scalars. Foundation for tensor-level Lipschitz bounds.

            General ReLU Lipschitz theorem for arbitrary tensor shapes. Main result: ReLU is 1-Lipschitz in L2 norm for any tensor shape.

            Vector-shaped ReLU is 1-Lipschitz in L2.

            This theorem is just the vector specialization of relu_lipschitz_general, but it is convenient for callers working with ordinary .dim n .scalar activations.

            Tensor subtraction can be rewritten as addition of a -1 scale.

            This is a small algebraic normal form used by linear-operator proofs, where it is often easier to reuse additive and scaling lemmas than reason about subSpec directly.

            Subtracting the zero tensor on the right leaves the tensor unchanged.

            Matrix-vector multiplication sends the zero vector to the zero vector.

            The proof follows the spec definition: each output coordinate is a fold over scalar products, and every scalar product contains a zero input coordinate.

            Upper bound on a matrix operator norm.

            We use the Frobenius-norm-style bound: matrix_op_norm W = √(∑ i, ‖row_i‖₂²), which satisfies ‖W x‖₂ ≤ matrix_op_norm W * ‖x‖₂.

            Instances For

              Frobenius-based operator norm bound: ‖W x‖₂ ≤ matrix_op_norm W * ‖x‖₂.

              Linear transformation preserves L2 norm bounds. Fundamental theorem for neural network stability analysis.

              theorem Proofs.lipschitz_composition {s t u : Spec.Shape} (f : Spec.Tensor sSpec.Tensor t) (g : Spec.Tensor tSpec.Tensor u) (Lf Lg : ) (hf : ∀ (x y : Spec.Tensor s), tensorL2Dist (f x) (f y) Lf * tensorL2Dist x y) (hg : ∀ (x y : Spec.Tensor t), tensorL2Dist (g x) (g y) Lg * tensorL2Dist x y) (hLg : 0 Lg) (x y : Spec.Tensor s) :
              tensorL2Dist (g (f x)) (g (f y)) Lg * Lf * tensorL2Dist x y

              Composition of Lipschitz functions preserves Lipschitz property. Essential for analyzing deep neural networks.

              ReLU + Linear composition Lipschitz bound. Practical theorem for single neural network layer analysis.