Convex Analysis & Duality
The Subdifferential: Subgradients of Convex Functions
The absolute value function |x| has no derivative at 0 — but it has a whole interval of slopes, [−1, 1], each of which describes a line that touches the graph at the origin and stays below it everywhere. That interval is the subdifferential ∂f(0), and it is the object that rescues calculus for the non-smooth convex functions that dominate optimization, economics, and machine learning.
Precisely: for a convex function f: ℝⁿ → ℝ ∪ {+∞}, a vector g ∈ ℝⁿ is a subgradient of f at x if f(y) ≥ f(x) + ⟨g, y − x⟩ for all y. The subdifferential ∂f(x) is the set of all such g. Where f is differentiable, ∂f(x) = {∇f(x)} collapses to a single vector; where f has a kink, it fattens into a convex set — and 0 ∈ ∂f(x) is exactly the condition for a global minimum.
- FieldConvex analysis / nonsmooth optimization
- Named afterGeneralizes the gradient; theory by Moreau (1963) & Rockafellar (1970)
- Definition∂f(x) = {g : f(y) ≥ f(x) + ⟨g, y−x⟩ ∀y}
- Key hypothesisf convex; nonempty for x in relative interior of dom f
- Fermat's rulex minimizes f ⟺ 0 ∈ ∂f(x)
- GeneralizesThe gradient: ∂f(x) = {∇f(x)} when f is differentiable at x
Interactive visualization
Press play, or step through manually. The visualization is yours to drive — try it before reading on.
Watch the 60-second explainer
A condensed visual walkthrough — narrated, captioned, under a minute.
The precise definition and what it claims
Let f: ℝⁿ → ℝ ∪ {+∞} be a convex function (a proper one — not identically +∞ and never −∞), and let x be a point where f(x) is finite. A vector g ∈ ℝⁿ is a subgradient of f at x if the affine minorant it defines lies below the graph:
- f(y) ≥ f(x) + ⟨g, y − x⟩ for all y ∈ ℝⁿ.
The subdifferential ∂f(x) is the collection of all such g. The inequality says: the hyperplane through (x, f(x)) with slope g is a global affine lower bound touching the graph at x — a supporting hyperplane of the epigraph.
Three structural facts follow immediately. First, ∂f(x) is always a closed convex set (an intersection of closed half-spaces, one per y). Second, it may be empty, a singleton, or a fat set. Third — the punchline — g = 0 satisfies the inequality precisely when f(y) ≥ f(x) for all y, so 0 ∈ ∂f(x) if and only if x is a global minimizer. This is Fermat's rule for the nonsmooth world.
The geometric picture: supporting lines at a kink
Picture the graph of a convex function as a bowl. At a smooth point there is exactly one tangent line, and it lies below the whole curve — that unique slope is ∇f(x), so ∂f(x) is a single point. But at a corner, like the vertex of |x|, no single tangent exists. Instead a whole fan of lines pivots through the kink, each staying below the graph.
For |x| at 0, every line y = gx with slope g ∈ [−1, 1] satisfies |y| ≥ g·y, so ∂f(0) = [−1, 1]. As you slide the slope from −1 up to +1 you sweep out all the supporting lines that touch the vertex. The endpoints are the one-sided derivatives: the left slope f′₋(0) = −1 and the right slope f′₊(0) = +1.
This is general in one dimension: for a finite convex f, ∂f(x) = [f′₋(x), f′₊(x)], the closed interval between the left and right derivatives. The gradient fails to exist exactly when this interval has positive length — when the two one-sided slopes disagree.
The mechanism: existence via a supporting hyperplane
Why does ∂f(x) ever contain anything? The engine is the Hahn–Banach / supporting hyperplane theorem applied to the epigraph epi f = {(y, t) : t ≥ f(y)}, which is a convex set in ℝⁿ⁺¹.
The construction: fix a point x in the relative interior of dom f. The point (x, f(x)) sits on the boundary of epi f, since you cannot go any lower. Because epi f is convex, the supporting hyperplane theorem provides a nonzero (a, β) ∈ ℝⁿ × ℝ with ⟨a, y⟩ + βt ≥ ⟨a, x⟩ + β f(x) for all (y, t) ∈ epi f. Pushing t → +∞ forces β ≥ 0; a short argument using x ∈ ri(dom f) rules out β = 0 (a vertical hyperplane would separate an interior point, contradiction). Normalizing so β = 1 and setting g = −a yields exactly the subgradient inequality.
The conclusion is the nonemptiness theorem: if x ∈ ri(dom f), then ∂f(x) ≠ ∅. The relative-interior hypothesis is doing real work — it is what guarantees the separating hyperplane is not vertical.
Worked example: the max of finitely many affine functions
Take f(x) = max{ ⟨a₁, x⟩ + b₁, …, ⟨aₘ, x⟩ + bₘ }, a piecewise-linear convex function — the building block of linear programming and of hinge losses. Let I(x) = { i : the i-th term achieves the max at x } be the active index set.
The Danskin / max-rule gives the subdifferential exactly as a convex hull:
- ∂f(x) = conv{ aᵢ : i ∈ I(x) }.
Where a single affine piece is strictly on top, I(x) is a singleton and ∂f(x) = {aᵢ}: f is differentiable there. On the ridge where two pieces tie, ∂f(x) = [aᵢ, aⱼ] is the segment between their gradients — a fat set, and the graph has a crease.
Concretely, f(x) = max(x, −x) = |x| has a₁ = 1, a₂ = −1; at 0 both are active, so ∂f(0) = conv{1, −1} = [−1, 1], recovering the interval. This example is why the subdifferential is central to subgradient descent: at a kink you simply pick any g ∈ ∂f(x) and step opposite to it.
Why the hypotheses matter — and where it breaks
Convexity is essential. The defining inequality demands a global affine minorant; only convex functions have one at every interior point. For f(x) = −|x|, no line through the vertex stays below the graph, so ∂f(0) = ∅ — the subdifferential machinery simply does not apply to nonconvex f (the Clarke subdifferential is the correct generalization there).
The relative interior matters. At the boundary of the domain the subdifferential can be empty even for a nice convex function: extend f(x) = −√(1 − x²) by +∞ outside [−1, 1]; at x = 1 the tangent is vertical, no finite-slope line supports the graph, and ∂f(1) = ∅.
The sum rule needs a qualification. Always ∂f(x) + ∂g(x) ⊆ ∂(f + g)(x). The reverse inclusion — the Moreau–Rockafellar theorem — requires a constraint qualification such as ri(dom f) ∩ ri(dom g) ≠ ∅. Without it, equality can fail: two functions whose domains meet only at a single boundary point can have ∂f + ∂g strictly smaller than ∂(f+g).
Why it matters: optimality, duality, and algorithms
The subdifferential is the load-bearing concept of modern nonsmooth optimization.
- Fermat's rule. The clean statement 0 ∈ ∂f(x) ⟺ global minimum turns optimality into an inclusion. Adding constraints, ∂(f + δ_C)(x) ∋ 0 recovers the KKT conditions via the normal cone N_C.
- Duality. The subdifferential is the inverse of the gradient of the convex conjugate: g ∈ ∂f(x) ⟺ x ∈ ∂f*(g) ⟺ f(x) + f*(g) = ⟨g, x⟩ (the Fenchel–Young equality). This bijection is the backbone of Fenchel and Lagrangian duality.
- Algorithms. Subgradient methods, the proximal operator prox_f (defined via (I + ∂f)⁻¹, a genuine single-valued map because ∂f is a maximal monotone operator), ADMM, and mirror descent all run on subgradients. The proximal step is exactly resolvent of the subdifferential.
In machine learning this is why you can 'differentiate' the ℓ₁ penalty, the hinge loss (SVMs), and ReLU networks: each has a well-defined subdifferential, and optimizers select an element of it. The concept, developed by Jean-Jacques Moreau and R. Tyrrell Rockafellar around 1963–1970, made non-smooth convexity as computable as the smooth case.
| Function f(x) | Point x | ∂f(x) | Interpretation |
|---|---|---|---|
| |x| | 0 | [−1, 1] | Kink: an interval of slopes; 0 ∈ [−1,1] certifies 0 is a global minimizer of |x| (strictness is a separate fact not implied by 0 ∈ ∂f(0)) |
| |x| | x > 0 | {1} | Smooth region: subdifferential is the single derivative |
| max(x, 0) (ReLU) | 0 | [0, 1] | Convex combinations of the left slope 0 and right slope 1 |
| Indicator δ_C(x) of convex set C | x ∈ C | Normal cone N_C(x) | Subdifferential of a set-membership penalty is its normal cone |
| x² | any x | {2x} | Differentiable everywhere: gradient recovered exactly |
| −√(1 − x²) extended by +∞ off [−1,1] | x = 1 | ∅ | Boundary of domain with vertical tangent: subdifferential can be empty |
Frequently asked questions
Why is 0 ∈ ∂f(x) equivalent to x being a global minimum?
Set g = 0 in the subgradient inequality f(y) ≥ f(x) + ⟨g, y − x⟩. It becomes f(y) ≥ f(x) for all y, which is exactly the statement that x is a global minimizer. Conversely, if x is a global minimizer, then f(y) ≥ f(x) = f(x) + ⟨0, y − x⟩, so 0 is a subgradient. This 'Fermat's rule for convex functions' is remarkable because for convex f, stationarity in this generalized sense is automatically global, not merely local.
When is the subdifferential guaranteed to be nonempty?
If f is a proper convex function and x lies in the relative interior of its effective domain, then ∂f(x) is nonempty, closed, and convex — this is the classic nonemptiness theorem proved by supporting the epigraph with a hyperplane. It is bounded (hence compact) precisely when x ∈ int(dom f), equivalently when f is finite in a full neighborhood of x; at a merely relative-interior point of a lower-dimensional domain ∂f(x) contains the orthogonal complement of aff(dom f) and is unbounded. On the boundary of the domain it can be empty (e.g. a vertical tangent), and outside the domain it is empty by convention.
How does the subdifferential relate to the ordinary gradient?
They coincide precisely when f is differentiable at x: then ∂f(x) = {∇f(x)}, a single point. More sharply, a finite convex function is differentiable at x if and only if its subdifferential there is a singleton, and in that case the unique subgradient is the gradient. So the subdifferential is a strict generalization of the gradient that also captures corners and kinks where the gradient fails to exist.
What's a concrete counterexample where the sum rule fails?
The inclusion ∂f(x) + ∂g(x) ⊆ ∂(f+g)(x) always holds, but equality (Moreau–Rockafellar) can fail without a constraint qualification. Let f(x) = −√x on [0,∞) (and +∞ elsewhere) and g = δ_{(−∞,0]}, whose domains meet only at 0. Then f has a vertical tangent at 0, so ∂f(0) = ∅, giving ∂f(0) + ∂g(0) = ∅. But f + g = δ_{{0}}, so ∂(f+g)(0) = ℝ. Thus ∅ ⊊ ℝ and the sum rule strictly fails. The qualification ri(dom f) ∩ ri(dom g) ≠ ∅ prevents this.
Does the subdifferential theory extend to infinite dimensions?
Yes. For a proper convex lower-semicontinuous f on a Banach or locally convex space, subgradients g live in the dual space and the inequality reads f(y) ≥ f(x) + ⟨g, y − x⟩ with the duality pairing. Nonemptiness at continuity points follows from the Hahn–Banach separation theorem, which needs no finite dimension. The main new subtlety is that ∂f(x) is weak*-compact rather than just compact, and continuity (not just relative-interior membership) is the clean sufficient condition for nonemptiness.
How is the subdifferential used in algorithms if it's set-valued?
You do not need the whole set — you pick any single element g ∈ ∂f(x) and use it as a descent-like direction. Subgradient descent xₖ₊₁ = xₖ − tₖ gₖ converges (with diminishing step sizes) even though −gₖ need not be a descent direction at every step. More powerfully, the proximal operator prox_{λf} = (I + λ∂f)⁻¹ is single-valued and firmly nonexpansive because ∂f is maximal monotone, which is what makes proximal-gradient, ADMM, and mirror descent well-defined and convergent on nonsmooth convex problems.