Documentation

ConvexAnalysis.Gradient

The gradient inequality and subgradients of differentiable functions #

The gradient inequality f x + ⟪∇f x, y - x⟫ ≤ f y for a real valued convex function, from a derivative of f at x along the segment towards y, its form f x + ⟪∇f x, y - x⟫ + (m / 2) ‖y - x‖² ≤ f y for an m-strongly convex function, and the subdifferential of a convex function f : H → ℝ that is differentiable at x: the singleton {∇f x}. At a point of differentiability every subgradient of any function is the gradient.

Main statements #

Implementation notes #

The gradient inequality is proved on the line through x and y with Mathlib's one-dimensional ConvexOn.le_slope_of_hasDerivWithinAt. It needs only a directional derivative within s (Mathlib's HasLineDerivWithinAt, a derivative of t ↦ f (x + t • (y - x)) at 0 within the preimage of s), so f may be arbitrary outside s; a Fréchet derivative within s (HasGradientWithinAt) or a Gâteaux derivative at x gives one. The forms with a directional derivative need no inner product and hold on every real vector space.

The open Mathlib PR #41494 (first-order convexity inequalities, open on 2026-12-01) proves ConvexOn.add_hasLineDerivAt_le, ConvexOn.add_hasFDerivAt_le, ConvexOn.add_fderiv_le, ConvexOn.fderiv_sub_nonneg, ConvexOn.isMinOn_of_fderiv_eq_zero and convexOn_iff_add_fderiv_le on a real normed space. ConvexAnalysis.ConvexOn.add_hasLineDerivAt_le has the name and the statement of the PR's lemma (on a real vector space); the forms within a set and with a gradient follow the PR's pattern of names.

References #

Tags #

subgradient, gradient, gradient inequality, directional derivative, differentiable convex function, strongly convex function, Fréchet derivative

theorem ConvexAnalysis.ConvexOn.add_hasLineDerivWithinAt_le {E : Type u_1} [AddCommGroup E] [Module ℝ E] {f : E → ℝ} {s : Set E} {x y : E} {f' : ℝ} (hf : ConvexOn ℝ s f) (hx : x ∈ s) (hy : y ∈ s) (hf' : HasLineDerivWithinAt ℝ f f' s x (y - x)) :
f x + f' ≤ f y

The gradient inequality with a directional derivative: if f is convex on s, x, y ∈ s, and f' is the derivative of f at x in the direction y - x within s, then f x + f' ≤ f y. This contains BC, Proposition 17.6 (there with a Gâteaux gradient at x and f : H → ]-∞, +∞] convex, which is the case s = dom f here); only the derivative of t ↦ f (x + t • (y - x)) at 0 within the preimage of s is used.

theorem ConvexAnalysis.ConvexOn.add_hasLineDerivAt_le {E : Type u_1} [AddCommGroup E] [Module ℝ E] {f : E → ℝ} {s : Set E} {x y : E} {f' : ℝ} (hf : ConvexOn ℝ s f) (hx : x ∈ s) (hy : y ∈ s) (hf' : HasLineDerivAt ℝ f f' x (y - x)) :
f x + f' ≤ f y

The gradient inequality with a directional derivative at x: if f is convex on s, x, y ∈ s, and f' is the derivative of f at x in the direction y - x, then f x + f' ≤ f y. This is the statement of ConvexOn.add_hasLineDerivAt_le in the open Mathlib PR #41494.

theorem ConvexAnalysis.ConvexOn.add_hasGradientWithinAt_le {H : Type u_1} [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H] {f : H → ℝ} {s : Set H} {g x y : H} (hf : ConvexOn ℝ s f) (hx : x ∈ s) (hy : y ∈ s) (hg : HasGradientWithinAt f g s x) :
f x + inner ℝ g (y - x) ≤ f y

The gradient inequality BC, Proposition 17.6: if f is convex on s and has the gradient g within s at x ∈ s, then f x + ⟪g, y - x⟫ ≤ f y for every y ∈ s. [BC17] assumes a Gâteaux gradient at x; here the gradient is a Fréchet gradient, but only within s, so the two statements are incomparable. Both are cases of ConvexAnalysis.ConvexOn.add_hasLineDerivWithinAt_le.

theorem ConvexAnalysis.ConvexOn.add_hasGradientAt_le {H : Type u_1} [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H] {f : H → ℝ} {s : Set H} {g x y : H} (hf : ConvexOn ℝ s f) (hx : x ∈ s) (hy : y ∈ s) (hg : HasGradientAt f g x) :
f x + inner ℝ g (y - x) ≤ f y

The gradient inequality BC, Proposition 17.6 with the gradient at x (a Fréchet gradient, where [BC17] assumes a Gâteaux gradient): if f is convex on s and x, y ∈ s, then f x + ⟪g, y - x⟫ ≤ f y.

theorem ConvexAnalysis.HasGradientAt.sub_const_mul_norm_sq {H : Type u_1} [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H] {f : H → ℝ} {g x : H} (hg : HasGradientAt f g x) (m : ℝ) :
HasGradientAt (fun (w : H) => f w - m / 2 * ‖w‖ ^ 2) (g - m • x) x

A gradient g of f at x gives the gradient g - m • x of f - (m / 2) ‖·‖².

theorem ConvexAnalysis.HasGradientWithinAt.sub_const_mul_norm_sq {H : Type u_1} [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H] {f : H → ℝ} {s : Set H} {g x : H} (hg : HasGradientWithinAt f g s x) (m : ℝ) :
HasGradientWithinAt (fun (w : H) => f w - m / 2 * ‖w‖ ^ 2) (g - m • x) s x

A gradient g of f at x within s gives the gradient g - m • x of f - (m / 2) ‖·‖² within s.

theorem ConvexAnalysis.StrongConvexOn.add_hasGradientWithinAt_add_le {H : Type u_1} [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H] {f : H → ℝ} {s : Set H} {g x y : H} {m : ℝ} (hf : StrongConvexOn s m f) (hx : x ∈ s) (hy : y ∈ s) (hg : HasGradientWithinAt f g s x) :
f x + inner ℝ g (y - x) + m / 2 * ‖y - x‖ ^ 2 ≤ f y

The gradient inequality of a strongly convex function: if f is m-strongly convex on s and has the gradient g within s at x ∈ s, then f x + ⟪g, y - x⟫ + (m / 2) ‖y - x‖² ≤ f y for every y ∈ s. The proof applies the gradient inequality to the convex function f - (m / 2) ‖·‖² (Mathlib's strongConvexOn_iff_convex, BC, Proposition 10.8).

theorem ConvexAnalysis.hasSubgradientAt_coe_of_hasGradientAt {H : Type u_1} [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H] {f : H → ℝ} {g x : H} (hf : ConvexOn ℝ Set.univ f) (hg : HasGradientAt f g x) :
HasSubgradientAt (fun (y : H) => ↑(f y)) g x

The gradient of a differentiable convex function is a subgradient BC, Proposition 17.31 (i) (there with a Gâteaux gradient, for f : H → ]-∞, +∞]).

theorem ConvexAnalysis.HasSubgradientAt.eq_of_hasGradientAt {H : Type u_1} [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H] {f : H → ℝ} {x g u : H} (hu : HasSubgradientAt (fun (y : H) => ↑(f y)) u x) (hg : HasGradientAt f g x) :
u = g

At a point of differentiability, a subgradient is the gradient; no convexity is needed.

theorem ConvexAnalysis.subdifferential_coe_eq_singleton_of_hasGradientAt {H : Type u_1} [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H] {f : H → ℝ} (hf : ConvexOn ℝ Set.univ f) {x g : H} (hg : HasGradientAt f g x) :
subdifferential (fun (y : H) => ↑(f y)) x = {g}

∂f x = {∇f x} for a convex function differentiable at x BC, Proposition 17.31 (there for Gâteaux differentiable f with values in ]-∞, +∞]).