Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

§B.9 — the softmax loss has gradient p(v) − e_y, Lipschitz constant √2 and smoothness constant 1

Proved
CertDRO.NNSmooth.softmax_constants

by mikedeng1 · Oct 8, 2026 · Mathlib 0df444a (Lean v4.33.1)

lipschitzp2o-batch-pfp2bp2o-gran-per-chapterp2o-plan-paperp2o-v1smoothnesssoftmax

Let K≥1K\ge1K≥1, y∈{1,…,K}y\in\{1,\dots,K\}y∈{1,…,K}, and let σy(v)=−log⁡py(v)\sigma_y(v)=-\log p_y(v)σy​(v)=−logpy​(v) be the softmax loss on RK\mathbb R^KRK, with p(v)p(v)p(v) the vector of softmax probabilities. Then:

  1. σy\sigma_yσy​ is differentiable with gradient
∇σy(v)=p(v)−ey;\nabla\sigma_y(v)=p(v)-e_y ;∇σy​(v)=p(v)−ey​;
  1. σy\sigma_yσy​ is 2\sqrt22​-Lipschitz: for all u,v∈RKu,v\in\mathbb R^Ku,v∈RK,
∣σy(u)−σy(v)∣≤2 ∥u−v∥2;|\sigma_y(u)-\sigma_y(v)|\le\sqrt2\,\|u-v\|_2 ;∣σy​(u)−σy​(v)∣≤2​∥u−v∥2​;
  1. if K≥2K\ge2K≥2, this constant is the supremum of the gradient norm:
sup⁡v∈RK∥p(v)−ey∥2=2;\sup_{v\in\mathbb R^K}\|p(v)-e_y\|_2=\sqrt2 ;v∈RKsup​∥p(v)−ey​∥2​=2​;
  1. the derivative of σy\sigma_yσy​ is 111-Lipschitz: for all u,v∈RKu,v\in\mathbb R^Ku,v∈RK,
∥Dσy(u)−Dσy(v)∥op≤∥u−v∥2.\|D\sigma_y(u)-D\sigma_y(v)\|_{\mathrm{op}}\le\|u-v\|_2 .∥Dσy​(u)−Dσy​(v)∥op​≤∥u−v∥2​.

In the terminology of Assumption E, the softmax loss is a layer with L0=2L^0=\sqrt2L0=2​ and L1=1L^1=1L1=1; these are the constants that enter Corollary 4.

Formalization Note The paper states L0=sup⁡x∥p(x)−ey∥2=2L^0=\sup_x\|p(x)-e_y\|_2=\sqrt2L0=supx​∥p(x)−ey​∥2​=2​; part 3 states this value of the supremum (a real supremum over a nonempty set bounded by 2\sqrt22​), which is not attained, under K≥2K\ge2K≥2 (for K=1K=1K=1, p≡eyp\equiv e_yp≡ey​ and the supremum is 000; the paper's "any corner other than eye_yey​" presumes a second class). The paper's "L1=1L^1=1L1=1" is a bound, not the value of a supremum, and is stated as a bound. The paper's eigenvalue argument for L1L^1L1 (via ∇2σy=diag⁡p−ppT\nabla^2\sigma_y=\operatorname{diag}p-pp^{T}∇2σy​=diagp−ppT and Weyl's inequality) is not formalized; only its conclusion, the bound with constant 111, is. The derivative in part 4 is the Fréchet derivative, a linear functional whose operator norm equals the Euclidean norm of the gradient. Classes are Fin K (0-based) and eye_yey​ is EuclideanSpace.single y 1.

Preamble
import Mathlib
import Definitions.Def_CertDRO_NNSmooth_Softmax
Formal statement
namespace CertDRO.NNSmooth

/-- §B.9 (p. 46), the constants of the softmax loss `σ_y(v) = −log p_y(v)` on `ℝ^K`:
its gradient is `∇σ_y(v) = p(v) − e_y`; `σ_y` is `√2`-Lipschitz for the ℓ²-norm (`L⁰ = √2`);
for `K ≥ 2`, `sup_v ‖p(v) − e_y‖₂ = √2` (the supremum, not attained); and its derivative is
`1`-Lipschitz from the ℓ²-norm to the operator norm (`L¹ = 1`). -/
theorem softmax_constants {K : ℕ} (y : Fin K) :
    (∀ v : EuclideanSpace ℝ (Fin K),
      HasGradientAt (softmaxLoss y) (softmaxProb v - EuclideanSpace.single y 1) v) ∧
    (∀ u v : EuclideanSpace ℝ (Fin K),
      |softmaxLoss y u - softmaxLoss y v| ≤ Real.sqrt 2 * ‖u - v‖) ∧
    (2 ≤ K → (⨆ v : EuclideanSpace ℝ (Fin K),
      ‖softmaxProb v - EuclideanSpace.single y 1‖) = Real.sqrt 2) ∧
    (∀ u v : EuclideanSpace ℝ (Fin K),
      ‖fderiv ℝ (softmaxLoss y) u - fderiv ℝ (softmaxLoss y) v‖ ≤ 1 * ‖u - v‖) := by sorry

end CertDRO.NNSmooth
Source
Sinha, Namkoong, Volpi, Duchi, Certifying Some Distributional Robustness with Principled Adversarial Training, arXiv:1710.10571v5, p. 46, §B.9 (L0 = √2, L1 = 1)
Human review
  • Endorsed by Shuze Chen · Oct 9, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 9, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me