Every way to establish convexity (and why it's worth checking)
The definition, the first-order tangent test, the second-order Hessian test, and the operations that build complex convex functions from simple ones — because convexity is what turns "a minimum" into "the minimum."
The definition (every chord lies on or above the graph) works everywhere but is often the hardest to check directly. The first-order tangent-line test needs one gradient evaluation and a single inequality. The second-order Hessian test is usually fastest when second derivatives are cheap — positive semidefinite everywhere means convex. Rather than re-deriving convexity from scratch for a complicated function, check whether it was built from simpler known-convex pieces using an operation that preserves convexity. Once convexity is established, FONC (a zero gradient) stops being merely necessary for a local minimum and becomes sufficient for a GLOBAL one — the payoff that makes checking worth the effort.
The definition
Term
convex set
Term
epigraph
A function is convex exactly when the region on or above its graph is a convex set.
The two derivative tests
Let f be differentiable on a convex open set S\subseteq\mathbb{R}^n. Then f is convex on S if and only if, for every x,y\in S, f(y) \ge f(x) + \nabla f(x)^\top (y-x). In words: f is convex exactly when its graph never lies below any of its own tangent (hyper)planes.
Sanity check: take f(x)=x^2, known to be convex. At x=1, the tangent-line inequality claims f(y) \ge f(1) + f'(1)(y-1) = 1+2(y-1) = 2y-1 for every y. Check at y=0: f(0)=0 \ge 2(0)-1=-1. True. At y=3: f(3)=9 \ge 2(3)-1=5. True — the parabola sits above every one of its tangent lines, as the theorem predicts. Now check a nonconvex function, f(x)=x^3, at x=0: the tangent line is y=0 (since f'(0)=0), but at y=-1, f(-1)=-1 < 0 — the graph dips below its own tangent line, and indeed x^3 is not convex on all of \mathbb R.
The graph lies on or above every one of its own tangent lines.
Show proof
(\Rightarrow) Suppose f is convex. Fix x,y\in S and t\in(0,1]. Convexity applied to the two points x and y gives f\big(x+t(y-x)\big) = f\big((1-t)x+ty\big) \le (1-t)f(x)+tf(y). Rearrange: \frac{f(x+t(y-x)) - f(x)}{t} \le f(y)-f(x). As t\to 0^+, the left side is exactly the directional derivative of f at x in the direction y-x, which for a differentiable f equals \nabla f(x)^\top(y-x). Taking the limit (the inequality is preserved since it holds for every t\in(0,1]) gives \nabla f(x)^\top(y-x) \le f(y)-f(x), i.e. f(y) \ge f(x) + \nabla f(x)^\top(y-x), as claimed.
(\Leftarrow) Suppose the tangent-plane inequality holds at every pair of points in S. Fix x,y\in S and t\in[0,1], and let z=(1-t)x+ty\in S (convex S guarantees z\in S). Apply the hypothesis twice, once with the pair (z,x) and once with (z,y): f(x) \ge f(z) + \nabla f(z)^\top(x-z), \qquad f(y) \ge f(z) + \nabla f(z)^\top(y-z). Multiply the first by (1-t), the second by t, and add: (1-t)f(x)+tf(y) \ge f(z) + \nabla f(z)^\top\Big[(1-t)(x-z)+t(y-z)\Big]. The bracketed term is (1-t)x+ty - z = z-z = \mathbf 0 by the definition of z, so the gradient term vanishes and (1-t)f(x)+tf(y) \ge f(z) = f\big((1-t)x+ty\big), which is exactly the definition of convexity.
Let f be twice continuously differentiable on a convex open set S\subseteq\mathbb{R}^n. Then f is convex on S if and only if the Hessian H(x) is positive semidefinite for every x\in S: d^\top H(x)\, d \ge 0 \quad\text{for every } x\in S,\ d\in\mathbb{R}^n.
Sanity check: take f(x,y)=x^2+y^2. Its Hessian is H=\begin{pmatrix}2&0\\0&2\end{pmatrix}, positive definite (hence PSD) everywhere — matching the known fact that x^2+y^2 is convex (a bowl). Now take f(x,y)=x^2-y^2: H=\begin{pmatrix}2&0\\0&-2\end{pmatrix} has eigenvalues 2 and -2, so d=(0,1) gives d^\top H d = -2 < 0 — H is not PSD, correctly flagging that the saddle-shaped x^2-y^2 is not convex.
The Hessian is positive semidefinite everywhere on the domain.
Show proof
This proof builds on the first-order convexity condition (see
first-order-convexity-condition): f convex \iff
f(y)\ge f(x)+\nabla f(x)^\top(y-x) for all x,y\in S.
(\Rightarrow) Suppose f is convex, fix x\in S and any direction d, and let y=x+td for small t>0 (small enough that y\in S, possible since S is open). Taylor's theorem gives f(x+td) = f(x) + t\,\nabla f(x)^\top d + \tfrac12 t^2\, d^\top H(x)\, d + o(t^2). The first-order convexity condition applied to this same pair states f(x+td) \ge f(x) + \nabla f(x)^\top(td) = f(x) + t\,\nabla f(x)^\top d. Substituting the Taylor expansion's left side: f(x) + t\,\nabla f(x)^\top d + \tfrac12 t^2\, d^\top H(x)\, d + o(t^2) \ge f(x) + t\,\nabla f(x)^\top d, which simplifies to \tfrac12 t^2\, d^\top H(x)\, d + o(t^2) \ge 0. Dividing by t^2>0 and letting t\to0^+ (so o(t^2)/t^2\to0) gives d^\top H(x)\,d \ge 0. Since x\in S and direction d were arbitrary, H(x)\succeq 0 throughout S.
(\Leftarrow) Suppose H(z)\succeq 0 for every z\in S. Fix x,y\in S; since S is convex the segment z(t) = x+t(y-x), t\in[0,1], stays in S. Define \varphi(t) = f(z(t)). By the chain rule, \varphi'(t) = \nabla f(z(t))^\top(y-x) and \varphi''(t) = (y-x)^\top H(z(t)) (y-x) \ge 0 for every t, since H(z(t))\succeq 0 on S. A single-variable function with \varphi''\ge0 everywhere on [0,1] is convex on that interval (a standard single- variable fact: \varphi' is nondecreasing, so the tangent-line-below-graph argument for one variable applies to \varphi term by term). In particular, at t=0,1 convexity of \varphi gives, for x,y\in S, \varphi(1) \ge \varphi(0) + \varphi'(0)(1-0) \;\Longrightarrow\; f(y) \ge f(x) + \nabla f(x)^\top(y-x). This is exactly the first-order convexity condition for f, which is equivalent to f being convex on S.
Let g be a convex function and X a random variable. Then E[g(X)] \geq g(E[X]). If g is concave instead, the inequality reverses: E[g(X)] \leq g(E[X]).
The function's value at an average is at most the average of its values — the definition's inequality, generalized to any weighted mix of points.
Show proof
Direct, for the convex case. Let m = E[X]. Because g is convex, its graph lies on or above every one of its tangent lines — in particular the tangent line at the single point x=m: g(x) \geq g(m) + g'(m)(x-m) \quad \text{for all } x (if g isn't differentiable at m, any supporting line at that point works the same way). Take the expectation of both sides over X: E[g(X)] \geq E\big[g(m) + g'(m)(X-m)\big] = g(m) + g'(m)\big(E[X]-m\big). Since m = E[X], the term E[X]-m is exactly 0, so the right side collapses to g(m) = g(E[X]): E[g(X)] \geq g(E[X]). The concave case follows by applying this result to -g, which is convex whenever g is concave, and flipping the sign back.