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 sTorchLean.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.

Rank-one ReLU is 1-Lipschitz in $\ell_2$.

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

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.

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.

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.

    Linear transformations preserve $\ell_2$-norm bounds. Fundamental theorem for neural network stability analysis.

    theorem Proofs.lipschitz_composition {s t u : Spec.Shape} (f : TorchLean.Tensor sTorchLean.Tensor t) (g : TorchLean.Tensor tTorchLean.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

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

    This is LipschitzWith.comp read through tensorL2Dist_eq_dist. A negative Lf is degenerate: the hypothesis on f then forces x = y, and both sides vanish.

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