skip to content

What is the subgradient set of the convex function f(x) = |x| at the point x = 0?

level: seniorimportance: should knowfreq 36%

answer

  1. supporting lines under the graph
  2. any slope that never rises above the curve
  3. test the inequality at x = 1 and x = -1
  4. a closed interval of allowed slopes
  5. zero being inside certifies the minimum

basics

~20 s

The subdifferential of |x| at 0 is the closed interval from -1 to 1: every slope of magnitude at most 1 gives a line supporting the V from below. Zero lies inside, which certifies 0 as the minimiser.

solid answer

~40 s

For a convex `f`, a number `g` is a **subgradient** at `x0` when `f(x) >= f(x0) + g*(x - x0)` for every `x` — the line through `(x0, f(x0))` with slope `g` never rises above the graph. The set of all such `g` is the subdifferential. For `f(x) = |x|` at `x0 = 0` the condition reads `|x| >= g*x` for all `x`. Taking `x = 1` gives `g <= 1` and `x = -1` gives `g >= -1`; conversely any `g` with `|g| <= 1` satisfies `g*x <= |g|*|x| <= |x|`. So the subdifferential is exactly `[-1, 1]`, collapsing to the single value `sign(x0)` wherever `x0` is not 0. The payoff: a convex function is minimised at `x*` precisely when `0` lies in the subdifferential there, and `0` is inside `[-1, 1]`.

go deeper

for a junior

Know that the derivative can be generalised to a set of slopes at a corner, and that for the absolute value at the origin that set spans from -1 to 1.

for a middle

Derive the interval from the supporting-line inequality by testing it at two points, and explain why the set shrinks to a single number wherever the function is smooth.

for a senior

Demonstrate the optimality condition in use: zero inside the subdifferential certifies a global minimum, and that is what makes exact zeros possible at a kink.

for a principal

Own the choice between a smooth surrogate and a genuinely non-smooth formulation, arguing the convergence cost of subgradient steps against the structural benefit the kink buys.

### Why a generalised derivative is needed For a smooth convex function, the test for a minimum is that the derivative vanishes. That test is useless at a kink, where no derivative exists — and kinks are exactly where interesting minima often sit. The subgradient generalises the derivative to convex functions in a way that keeps the optimality test working. ### The definition A function `f` is convex when `f(t*x + (1-t)*y) <= t*f(x) + (1-t)*f(y)` for all points `x`, `y` and all `t` in `[0, 1]`. For such a function, a number `g` is a **subgradient of f at x0** when ``` f(x) >= f(x0) + g*(x - x0) for every x ``` The right-hand side is the line through the point `(x0, f(x0))` with slope `g`. The condition says that line lies weakly below the graph everywhere — it is a **supporting line**. The set of all subgradients at `x0` is the **subdifferential**, written `df(x0)`. It is always a closed convex set; for a convex function that is finite near `x0` it is non-empty. Where `f` is differentiable, the tangent line is the only line that supports the graph from below, so the subdifferential is the single number `f'(x0)`. The set-valued definition therefore extends the derivative rather than replacing it. ### Computing the subdifferential of |x| at 0 With `f(x) = |x|`, `x0 = 0` and `f(0) = 0`, the defining inequality becomes ``` |x| >= g*x for every real x ``` **Necessity.** Put `x = 1`: the condition gives `1 >= g`. Put `x = -1`: it gives `1 >= -g`, i.e. `g >= -1`. So any subgradient must satisfy `-1 <= g <= 1`. **Sufficiency.** Suppose `|g| <= 1`. Then for every `x`, `g*x <= |g*x| = |g|*|x| <= |x|`. The inequality holds, so every such `g` is a subgradient. Therefore the subdifferential is exactly the **closed** interval `[-1, 1]`. The endpoints belong to it: the line of slope `1` coincides with the right branch of the V and stays below the left branch, and symmetrically for slope `-1`. Geometrically, the subdifferential at the vertex of a V is the whole fan of lines you can wedge under the crease without poking through. At a point `x0 > 0` the only supporting line is the tangent of slope `1`, so `df(x0) = {1}`; for `x0 < 0` it is `{-1}`. The subdifferential is a single point wherever the function is smooth and expands into an interval exactly at the kink. ### The optimality condition The reason this construction earns its place is one clean theorem: for a convex `f`, a point `x*` is a **global** minimiser if and only if ``` 0 belongs to df(x*) ``` The proof is immediate from the definition: `0` being a subgradient means `f(x) >= f(x*) + 0*(x - x*) = f(x*)` for every `x`, which is precisely the statement that `x*` is a global minimum. For `f(x) = |x|` we have `0` in `[-1, 1]`, so `x = 0` is the global minimiser — established without ever differentiating at the kink. When `f` is differentiable the condition reduces to `f'(x*) = 0`, recovering the familiar test. ### Why kinks create exact zeros Consider minimising `(1/2)*(x - z)^2 + L*|x|` over `x`, where `z` is a fixed number and `L > 0`. The optimality condition is `0` in `x - z + L*df(|x|)`. For a candidate `x = 0`, the subdifferential contributes the whole interval `[-L, L]`, so the condition becomes `|z| <= L`: whenever the target `z` is small relative to `L`, the exact solution is `x = 0`, not merely something close to it. Away from 0 the condition is `x - z + L*sign(x) = 0`, giving `x = sign(z)*(|z| - L)`. The combined solution is the soft-threshold `sign(z)*max(|z| - L, 0)`. Contrast a squared penalty `(1/2)*(x - z)^2 + L*x^2`, which is differentiable everywhere. Its derivative at `x = 0` is the single number `-z`, and that vanishes only when `z` is exactly 0. The interval-valued subdifferential of the absolute value is what creates a whole range of `z` values mapping to an exact zero. This is the mathematical reason an absolute-value penalty produces exact zeros while a squared one only shrinks. ### Operating with subgradients Three practical points distinguish a candidate who has used these rather than only read about them: 1. **Any element may be chosen.** An algorithm picks one subgradient from the set — often the convention of returning a one-sided value at the kink — and the choice affects the path taken. 2. **The negative subgradient is not guaranteed to be a descent direction.** Unlike the smooth case, stepping along it can increase the objective for every step size, so the usual descent reasoning does not carry over. 3. **Fixed step sizes do not converge to the exact optimum.** Subgradient methods need diminishing steps, and their worst-case convergence is markedly slower than gradient methods on smooth problems. Where the non-smooth part is simple, methods that handle the kink exactly rather than through a subgradient step do better. ### The boundary of validity The supporting-line definition and the optimality theorem rely on convexity. For non-convex functions the object is replaced by other generalised derivatives with weaker guarantees, and quoting the convex theory without that caveat is a genuine error.

  • What is the subdifferential of |x| at x = 3?
    The single value `{1}`. At a point where a convex function is differentiable, the tangent line is the only line supporting the graph from below, so the subdifferential collapses to the derivative alone — here `sign(3) = 1`. The set is interval-valued only at the kink.
  • What replaces the vanishing-derivative test as the optimality condition for a convex function with a kink?
    The condition `0` belongs to the subdifferential at `x*`. That is equivalent, straight from the definition, to `f(x) >= f(x*)` for every `x`, so it certifies a global minimum. For `|x|` at 0, `0` lies inside `[-1, 1]`, which proves the origin is optimal without differentiating there.
  • Why does an absolute-value penalty produce exact zeros while a squared penalty only shrinks?
    At 0 the absolute value contributes a whole interval of subgradients, so the optimality condition holds for a whole range of data values and the solution is exactly 0 on that range. A squared penalty is differentiable with derivative 0 at the origin, contributing nothing, so the solution is only pulled toward zero rather than pinned to it.
  • Does a subgradient step always reduce the objective?
    No. Unlike the smooth case, the negative of a subgradient need not be a descent direction, so an iterate can move uphill for every step size. Convergence is argued in terms of distance to the optimal set with diminishing step sizes, not by monotone decrease of the objective.

At the sharp crease of a V, many straight rulers can be laid touching the crease without cutting into the shape. Each ruler's slope is a subgradient, and the whole fan of allowed slopes is the subdifferential.

saying these in an interview costs you the question

  • Says a kinked function cannot be optimised because no derivative exists
  • Reports the subgradient at 0 as a single number, usually zero
  • Gives the open interval instead of the closed one
  • Assumes the negative subgradient is always a descent direction
  • Applies the convex definition to a non-convex function without qualification

context