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 #
- Everything here is spec-level and real-valued (
ℝ), so we can freely use Mathlib’s analysis and order theory. - The main
L2norm here is proof-oriented: it is defined fromSpec.tensorNormSquared, the same dot-product/sum-of-squares object used throughout tensor algebra proofs. NN.MLTheory.Robustness.Specalso has scalar-polymorphic norm definitions for runtime and verification statements. This file does not duplicate that API surface; it proves real-valued theorems and includes bridge lemmas where those polymorphic specs need theorem-level support.
PyTorch correspondence / citations #
- L2/L1/L∞ norms correspond to PyTorch’s
torch.linalg.*_norm/torch.linalg.normAPIs. https://pytorch.org/docs/stable/generated/torch.linalg.vector_norm.html https://pytorch.org/docs/stable/generated/torch.linalg.norm.html - ReLU corresponds to
torch.nn.functional.relu(andtorch.nn.ReLU). https://pytorch.org/docs/stable/generated/torch.nn.functional.relu.html
Typical downstream use #
These lemmas are intended to be imported by higher-level results that need quantitative smoothness statements, e.g.:
- proving that a composed network is Lipschitz (by composing layer-wise constants),
- justifying robustness bounds that depend on Lipschitz constants, or
- providing assumptions for convergence/step-size arguments.
References #
- The key analytic tool is the Mean Value Theorem / derivative bounds, as formalized in Mathlib:
Mathlib.Analysis.Calculus.MeanValue. - The mathematics is standard (functional analysis / optimization folklore); this file’s value is
aligning those facts with TorchLean’s
Tensorencoding.
L2 norm (Euclidean norm) for tensors. Fundamental for measuring tensor magnitudes and distances.
Instances For
L∞ norm (maximum norm) for tensors. Important for uniform convergence and pointwise bounds.
Instances For
L1 norm (Manhattan norm) for tensors. Useful for sparsity-inducing regularization.
Instances For
Distance function based on L2 norm.
Instances For
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.
Bilinearity of dot product over addition (distributive property).
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.
ReLU is 1-Lipschitz on scalar tensors.
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.
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.