TorchLean API

NN.Proofs.Analysis.Lipschitz.Network

Lipschitz bounds for neural-network operations #

This module owns Lipschitz estimates for ReLU, matrix-vector multiplication, linear layers, and composition. The underlying real-valued tensor norm API lives in NN.Proofs.Analysis.Lipschitz.Norm.

Import NN.Proofs.Analysis.Lipschitz for the complete norm and network-bound API.

Bridges between tensorL2Dist bounds and Mathlib's LipschitzWith #

theorem Proofs.lipschitzWith_of_tensorL2Dist_le {s t : Spec.Shape} {f : TorchLean.Tensor ℝ s → TorchLean.Tensor ℝ t} {L : ℝ} (hL : 0 ≤ L) (h : ∀ (x y : TorchLean.Tensor ℝ s), tensorL2Dist (f x) (f y) ≤ L * tensorL2Dist x y) :

A tensorL2Dist bound with a nonnegative constant is a Mathlib Lipschitz bound.

A Mathlib Lipschitz bound on real tensors is a tensorL2Dist bound.

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.

ReLU is 1-Lipschitz in the L2 norm for tensors of every shape.

ReLU is 1-Lipschitz for the Euclidean metric on real tensors.

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.

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.

noncomputable def Proofs.matrixFrobeniusNorm {m n : ℕ} (W : TorchLean.Tensor ℝ [m, n]) :

Frobenius norm of a matrix tensor.

We use the Frobenius-norm-style bound:

$$ \lVert W\rVert_F =\sqrt{\sum_i\lVert\operatorname{row}_i(W)\rVert_2^2}, $$

This is an upper bound for the induced Euclidean operator norm; it is not the spectral norm.

Instances For

    The Frobenius norm bounds matrix-vector multiplication in the Euclidean norm.

    Matrix-vector multiplication is Lipschitz with its matrix's Frobenius norm as a bound.

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

    Composing the two distance bounds multiplies their constants.

    The nonnegative Lg preserves the inequality when multiplying the bound for f. No sign assumption on Lf is needed.

    ReLU after matrix-vector multiplication retains the matrix's Frobenius Lipschitz bound.