AnyLearn
All lessons
Mathintermediate

Convexity: the property that decides what is solvable

Convexity is what separates optimization problems you can solve with a guarantee from ones you can only hope about. This lesson defines convex sets and functions, proves why every local minimum is global, and gives you the operations that let you recognise convexity without touching a Hessian.

Updated · AI-authored, review-gated · how lessons are made

Not signed in: your progress and quiz score won't be saved.
Progress1 / 11

Where the real dividing line runs

Most people sort optimization problems into linear and nonlinear. That is the wrong cut. R. Tyrrell Rockafellar put the correct one in SIAM Review in 1993:

Key idea: "The great watershed in optimization isn't between linearity and nonlinearity, but convexity and nonconvexity."

On the convex side you can compute a solution and prove it is the best one, with algorithms whose running time you can bound in advance. On the nonconvex side you get a point that is better than its neighbours, with no way to know whether something far better sits elsewhere in the space.

A linear problem in a million variables is routine. A nonconvex problem in twenty can be hopeless. Dimension is not the obstacle; shape is.

Full lesson text

All 11 steps on one page, for reading, reference, and search.

Show

1. Where the real dividing line runs

Most people sort optimization problems into linear and nonlinear. That is the wrong cut. R. Tyrrell Rockafellar put the correct one in SIAM Review in 1993:

Key idea: "The great watershed in optimization isn't between linearity and nonlinearity, but convexity and nonconvexity."

On the convex side you can compute a solution and prove it is the best one, with algorithms whose running time you can bound in advance. On the nonconvex side you get a point that is better than its neighbours, with no way to know whether something far better sits elsewhere in the space.

A linear problem in a million variables is routine. A nonconvex problem in twenty can be hopeless. Dimension is not the obstacle; shape is.

2. Convex sets

A set CC is convex when the straight line between any two of its points stays inside it:

x,yC,θ[0,1]θx+(1θ)yCx, y \in C, \quad \theta \in [0,1] \quad \Longrightarrow \quad \theta x + (1-\theta) y \in C

No dents, no holes, no disconnected pieces.

ConvexNot convex
a ball, a cube, a half-spacea sphere's surface, an annulus
the set of PSD matricesthe set of rank-1 matrices
a linear subspacea union of two disjoint balls
the solution set of AxbAx \le bthe solution set of x1x21x_1 x_2 \ge 1 over all signs

Intersections of convex sets are convex, and this is what makes linear constraints so well behaved: each inequality axba^\top x \le b carves out a half-space, and stacking any number of them keeps the feasible region convex.

3. Convex functions

A function is convex when the chord between two points on its graph never dips below the graph:

f(θx+(1θ)y)θf(x)+(1θ)f(y)f(\theta x + (1-\theta) y) \le \theta f(x) + (1-\theta) f(y)

for all x,yx, y in the domain and θ[0,1]\theta \in [0,1]. Replace \le with << for strict convexity.

There is a cleaner way to hold this. The epigraph of ff is the set of points lying on or above its graph, and ff is convex exactly when its epigraph is a convex set. Every fact about convex functions is a fact about convex sets wearing different notation.

Definition: A function is concave when f-f is convex. Maximising a concave function and minimising a convex one are the same problem, which is why the literature moves between them without comment.

4. The theorem everything rests on

Here is why convexity is worth this much attention.

Claim. If ff is convex, every local minimum is a global minimum.

Proof. Let xx be a local minimum and suppose some yy has f(y)<f(x)f(y) < f(x). Take a point on the segment between them, z=θx+(1θ)yz = \theta x + (1-\theta) y, with θ\theta close to 1 so that zz sits inside the neighbourhood where xx is optimal. Convexity gives

f(z)θf(x)+(1θ)f(y)<θf(x)+(1θ)f(x)=f(x)f(z) \le \theta f(x) + (1-\theta) f(y) < \theta f(x) + (1-\theta) f(x) = f(x)

So zz beats xx while lying in the very neighbourhood where nothing was supposed to beat it. Contradiction.

That is the whole guarantee. A local search cannot get stuck in the wrong place, because on a convex function there is no wrong place to get stuck.

5. Testing convexity with derivatives

For differentiable functions there are two mechanical tests.

First order. ff is convex exactly when its tangent plane is a global underestimator everywhere:

f(y)f(x)+f(x)(yx)f(y) \ge f(x) + \nabla f(x)^\top (y - x)

This is the useful one conceptually: it says the linear model at any point never overpromises.

Second order. For twice-differentiable ff on an open convex domain, ff is convex exactly when its Hessian is positive semidefinite everywhere:

2f(x)0\nabla^2 f(x) \succeq 0

Gotcha: The Hessian test is a trap in practice. For a function of 500 variables the Hessian is a 500 by 500 symbolic matrix whose eigenvalues you would need to sign everywhere on the domain. Almost nobody establishes convexity this way.

6. How convexity is actually established

You build convex functions out of convex pieces, using operations that provably preserve the property. Learn this list and you can classify most problems on sight.

  • Nonnegative weighted sum. If f1,f2f_1, f_2 are convex and w1,w20w_1, w_2 \ge 0, then w1f1+w2f2w_1 f_1 + w_2 f_2 is convex.
  • Composition with an affine map. If ff is convex, so is f(Ax+b)f(Ax + b).
  • Pointwise maximum. The max of any number of convex functions is convex, even infinitely many.
  • Composition rule. h(g(x))h(g(x)) is convex when hh is convex and nondecreasing and gg is convex.
  • Partial minimisation. If f(x,y)f(x,y) is jointly convex, then infyf(x,y)\inf_y f(x,y) is convex in xx.

The pointwise maximum rule is why maxi(aix+bi)\max_i (a_i^\top x + b_i) is convex, and therefore why any piecewise-linear upper envelope, the hinge loss included, is convex.

7. A case people get wrong

Recognition by rules beats intuition, and here is a function that shows why.

Predict first

Is f(x,y)=x2/yf(x,y) = x^2 / y convex on the domain y>0y > 0? Jointly, in both variables at once.

8. Is my problem convex?

All three conditions must hold. Note the asymmetry in the middle: inequality constraints may be convex functions, but equality constraints must be affine, because a curved equality traces a surface rather than bounding a solid region.

flowchart LR
  A["Is the objective convex?"] --> B["Are all inequality constraints convex?"]
  B --> C["Are all equality constraints affine?"]
  C --> D["Convex problem, global optimum certified"]
  A --> E["Not convex as written"]
  B --> E
  C --> E
  E --> F["Reformulate, or accept a local solution"]

9. Letting a solver check for you

Modelling tools mechanise the rules from two steps back. CVXPY implements disciplined convex programming: you assemble the objective from atoms with known curvature, and the library refuses anything it cannot certify.

import cvxpy as cp

x = cp.Variable(2)
objective = cp.Minimize(cp.sum_squares(x - [1.0, 2.0]))
constraints = [x >= 0, cp.sum(x) <= 1]

problem = cp.Problem(objective, constraints)
problem.solve()          # DCP rules verify convexity before any solving starts
print(problem.status, x.value)
# optimal [0. 1.]

The unconstrained minimum sits at (1,2)(1,2), whose coordinates sum to 3, so the budget constraint binds and the solution slides to (0,1)(0,1).

In practice: A DCP rejection almost always means the model is genuinely nonconvex, not that the tool is being fussy. Treat it as a free proof.

10. The two constants that set the speed

Convexity says a solution exists and can be certified. It says nothing about how long finding it takes. Two extra constants decide that, and both appear throughout the next lesson.

ConstantConditionMeaning
LL, smoothness2fLI\nabla^2 f \preceq L Icurvature is bounded above, so the gradient cannot change arbitrarily fast
μ\mu, strong convexity2fμI\nabla^2 f \succeq \mu Icurvature is bounded below, so the function is at least as curved as a quadratic bowl

Their ratio κ=L/μ\kappa = L/\mu is the condition number of the problem. Geometrically it is how elongated the level sets are: κ=1\kappa = 1 is a perfectly round bowl, and large κ\kappa is a long narrow valley. Every convergence rate in the next lesson is written in terms of κ\kappa.

11. Where convexity stops, and why that is fine

Convexity is a guarantee, not a requirement. Neural network training is thoroughly nonconvex and works anyway, and pretending otherwise would misrepresent the field.

What you lose without it is precise: no certificate that the point you found is best, no bound on how far from optimal you might be, no guarantee that a different initialisation lands in the same place. What practitioners do instead is accept local solutions and rely on empirical evidence that they are good enough.

What convexity still gives you in that world is a toolkit. Convex subproblems appear inside nonconvex methods constantly: the trust region step, the projection, the linearised update. Knowing which pieces are convex tells you which pieces come with guarantees, and that is worth knowing even when the whole problem does not.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. Why does convexity guarantee that a local minimum is global?
    • Convex functions have exactly one stationary point by definition
    • A better point would make the chord dip below the graph near the local minimum
    • The gradient of a convex function is zero only at the global minimum
    • Convex functions are always strictly increasing away from the origin
  2. Which of these sets is NOT convex?
    • The set of positive semidefinite matrices
    • The solution set of a system of linear inequalities
    • The surface of a sphere in three dimensions
    • A closed half-space
  3. A model is built as the pointwise maximum of 40 affine functions. What can you say about it?
    • It is convex, since pointwise maxima of convex functions are convex
    • It is concave, since each affine piece is concave
    • Convexity depends on the sign of the coefficients
    • It is neither, because maxima introduce kinks
  4. In a convex optimization problem, why must equality constraints be affine rather than merely convex?
    • Because convex equalities are computationally expensive to evaluate
    • Because a curved equality traces a surface, which is not a convex set
    • Because solvers cannot differentiate nonlinear equalities
    • Because affine equalities always have a unique solution
  5. A problem has condition number kappa = 1. What does that say about its level sets?
    • They are long narrow valleys, and gradient methods will zigzag
    • They are perfectly round, since the smoothness and strong convexity constants match
    • They are unbounded, since the curvature is not constrained
    • Nothing, since kappa measures problem size rather than shape

Related lessons

Math
advanced

Newton's method and the interior point revolution

Second derivatives buy something gradients cannot: a step shaped by curvature, immune to conditioning, converging quadratically. This lesson builds Newton's method, then layers it on a log barrier to get interior point methods, the machinery that made large constrained problems solvable with a certificate rather than a hope.

13 steps·~20 min
Math
intermediate

Gradient descent: choosing the step and knowing the rate

Gradient descent is three lines of code and a hundred years of theory. This lesson derives why a safe step size is one over the smoothness constant, why the condition number governs everything, and why acceleration reaching order one over k squared is provably the best any first-order method can do.

11 steps·~17 min
Math
intermediate

What a Group Is, and Why the Axioms Are So Bare

A group is a set with one operation obeying four rules, and that deliberate poverty is the point: anything proved about groups holds for rotations, permutations, integers, XOR and Rubik's cube at once. This lesson builds the definition from symmetry, works through the symmetries of a square, and shows where groups already sit in code.

10 steps·~15 min
Math
intermediate

Gradients, Jacobians, and Hessians: Calculus in Many Dimensions

One derivative becomes three objects once a function has many inputs and many outputs. This lesson builds the gradient, the Jacobian and the Hessian, shows what each one actually tells you, and explains why curvature decides how many steps an optimiser needs and why nobody ever writes the Hessian down.

10 steps·~15 min