Foundations to Frontier
Tests
A. Mathematical Foundations › A6 Optimization › Convex optimization

Convex Sets and Convex Functions

Convexity is the dividing line between optimization problems we can solve reliably and those we can't. You will define convex sets and functions, learn the zeroth-, first- and second-order tests, the operations that preserve convexity (intersections, sums, max, affine maps, composition rules), a catalogue of convex functions used in ML and control, projections onto convex sets, and compute the nearest safe point for a drone geofence with Dykstra's algorithm.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

No dents, no holes

A shape is convex if you can stretch a rubber band between any two points inside it and the band never leaves the shape. A disk or a triangle is convex. A ring or a star is not, because the band crosses the empty middle or cuts across a gap between points.

A function is convex if its graph is shaped like a bowl. Draw a straight line between any two points on the graph, and the line always sits on or above the curve.

Why care? In a bowl there’s only one bottom. Walk downhill from anywhere and you’ll find it.

Is it convex? The segment test and the chord test
segment leaves the set at 51% of its points → this set is NOT convex
A set is convex if the straight segment between any two of its points stays in the set. Disks, polygons and intersections of convex sets pass; rings and stars fail. A function is convex if every chord lies above its graph: f(tx + (1−t)y) ≤ t f(x) + (1−t) f(y). Equivalently, its epigraph (the region above the graph) is a convex set. For convex problems every local minimum is global, which is why we care.
Why engineers care

Powered-descent landing guidance, model predictive control, portfolio-style resource allocation, sparse regression and support vector machines are all convex problems, solved to global optimality in milliseconds with certificates. Recognizing (or creating) convexity is one of the most valuable skills in engineering optimization.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Which shape is convex?
  2. 2. For a convex function, a chord between two points on the graph lies…
  3. 3. A convex function has how many separate valley bottoms?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Convex sets

C⊆RnC\subseteq\mathbb R^n is convex if x,y∈Cx, y\in C and t∈[0,1]t\in[0, 1] imply tx+(1−t)y∈Ctx + (1 - t)y\in C. Examples:

  • Hyperplanes {a⊤x=b}\{a^\top x = b\} and halfspaces {a⊤x≤b}\{a^\top x\le b\}.
  • Polyhedra {Ax≤b}\{Ax\le b\}.
  • Norm balls {∥x−c∥≤r}\{\|x - c\|\le r\} for any norm.
  • Ellipsoids, the PSD cone {X⪰0}\{X\succeq0\}, and the probability simplex.

Intersections of convex sets are convex. Unions generally aren’t.

Convex functions

ff is convex if its domain is convex and

f(tx+(1−t)y)≤t f(x)+(1−t) f(y)∀x,y, t∈[0,1]f(tx + (1 - t)y)\le t\,f(x) + (1 - t)\,f(y)\qquad\forall x, y,\ t\in[0, 1]

Equivalently, its epigraph {(x,s):f(x)≤s}\{(x, s) : f(x)\le s\} is a convex set. It’s concave if −f-f is convex. Examples: x2x^2, ∣x∣|x|, eaxe^{ax}, −log⁡x-\log x, any norm, max⁡ixi\max_ix_i, and log-sum-exp log⁡∑iexi\log\sum_ie^{x_i}.

📝 Quick check (Level 1)
0/3 answered
  1. 1. The intersection of two convex sets is…
  2. 2. Is the union of two disjoint disks convex?
  3. 3. f is convex iff its epigraph is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

Tests for convexity

  • First-order (differentiable ff): f(y)≥f(x)+∇f(x)⊤(y−x)f(y)\ge f(x) + \nabla f(x)^\top(y - x) for all x,yx, y. The tangent plane is a global under-estimator. Consequence: ∇f(x⋆)=0\nabla f(x^\star) = 0 implies a global minimum.
  • Second-order (twice differentiable): ∇2f(x)⪰0\nabla^2f(x)\succeq0 everywhere. Example: log-sum-exp has ∇2=diag⁡(p)−pp⊤⪰0\nabla^2 = \operatorname{diag}(p) - pp^\top\succeq0, where pp is the softmax.
  • Restriction to a line: ff is convex iff g(t)=f(x+tv)g(t) = f(x + tv) is convex for every x,vx, v.

Operations that preserve convexity

  • Non-negative weighted sums: ∑wifi\sum w_if_i with wi≥0w_i\ge0.
  • Affine pre-composition: f(Ax+b)f(Ax + b). So ∥Ax−b∥\|Ax - b\| and the logistic loss log⁡(1+e−y w⊤x)\log(1 + e^{-y\,w^\top x}) are convex in ww.
  • Pointwise maximum: max⁡ifi(x)\max_if_i(x) and sup⁡yf(x,y)\sup_yf(x, y). Hinge loss and the largest eigenvalue are examples.
  • Composition: h(g(x))h(g(x)) is convex if hh is convex and non-decreasing and gg is convex. Example: eg(x)e^{g(x)}.
  • Partial minimization: inf⁡yf(x,y)\inf_yf(x, y) over a convex set is convex in xx.

This calculus is the basis of disciplined convex programming (CVX, CVXPY): build problems from atoms using these rules, and convexity is certified automatically.

Projections

For a closed convex CC, every point xx has a unique nearest point PC(x)P_C(x), characterized by (x−PC(x))⊤(z−PC(x))≤0(x - P_C(x))^\top(z - P_C(x))\le0 for all z∈Cz\in C. Projections are non-expansive: ∥PC(x)−PC(y)∥≤∥x−y∥\|P_C(x) - P_C(y)\|\le\|x - y\|.

🐍 Exercise 1: testing convexity numerically
Search for Jensen violations over random point pairs and compute numerical Hessians. Confirm that log-sum-exp and the L1 norm pass, that an indefinite quadratic fails, and that ∇² log-sum-exp = diag(p) − ppᵀ.
📝 Quick check (Level 2)
0/3 answered
  1. 1. For differentiable convex f, ∇f(x*) = 0 implies x* is…
  2. 2. The pointwise maximum of convex functions is…
  3. 3. ‖Ax − b‖₂ is convex in x because…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Proof: the first-order condition implies convexity

Suppose f(y)≥f(x)+∇f(x)⊤(y−x)f(y)\ge f(x) + \nabla f(x)^\top(y - x) for all x,yx, y. Let z=tx+(1−t)yz = tx + (1 - t)y. Apply the inequality at zz toward xx and toward yy, multiply by tt and 1−t1 - t, and add. The gradient terms cancel because t(x−z)+(1−t)(y−z)=0t(x - z) + (1 - t)(y - z) = 0, leaving tf(x)+(1−t)f(y)≥f(z)tf(x) + (1 - t)f(y)\ge f(z). ∎ The converse follows by taking t→0t\to0 in the definition.

Proof: projections onto convex sets are unique

If p1≠p2p_1\ne p_2 were both nearest points at distance dd, their midpoint mm would be in CC (by convexity). By the parallelogram law, ∥x−m∥2=d2−14∥p1−p2∥2<d2\|x - m\|^2 = d^2 - \tfrac14\|p_1 - p_2\|^2 < d^2, a contradiction. ∎ For a circle (non-convex), the centre has infinitely many nearest points, and nearby points get torn apart.

Hessian of log-sum-exp

With p=softmax⁡(x)p = \operatorname{softmax}(x): ∇2=diag⁡(p)−pp⊤\nabla^2 = \operatorname{diag}(p) - pp^\top. For any vv, v⊤(diag⁡p−pp⊤)v=∑pivi2−(∑pivi)2=Var⁡p(v)≥0v^\top(\operatorname{diag}p - pp^\top)v = \sum p_iv_i^2 - (\sum p_iv_i)^2 = \operatorname{Var}_p(v)\ge0. ∎ This is why softmax cross-entropy is convex in the logits.

Exercise 3.1: Is f(x, y) = x²/y convex for positive y?

Yes. ∇2f=2y3[y2−xy−xyx2]=2y3(y,−x)⊤(y,−x)⪰0\nabla^2f = \frac2{y^3}\begin{bmatrix}y^2 & -xy\\ -xy & x^2\end{bmatrix} = \frac2{y^3}(y, -x)^\top(y, -x)\succeq0. It’s the perspective of x2x^2.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The quadratic form of ∇² log-sum-exp equals…
  2. 2. Projection onto a closed convex set is…
  3. 3. x²/y on y > 0 is…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

The nearest safe point for a drone

A drone must stay inside a 5 m circular geofence, above a no-fly line and to the right of a building. Each constraint is convex, so the safe region is their intersection: convex, and every outside point has a unique nearest safe point. Alternating projections (POCS) find a safe point. Dykstra’s algorithm finds the nearest one, here the corner (0.5, 1), which matches a brute-force grid search. A safety filter that snaps commands to the nearest safe command uses exactly this projection (Ames et al., 2019, control barrier functions).

🐍 Exercise 2 (research): projecting onto a safe set
Implement projections onto halfspaces and balls, alternating projections and Dykstra's algorithm. Find the nearest safe point for a geofenced drone and check non-expansiveness for a convex vs a non-convex set.

Convexity in AI, robotics and aerospace

  • Powered-descent guidance: lossless convexification turns a non-convex landing problem into a second-order cone program, flown on board for Mars landing studies and reusable rockets (Açıkmeşe and Ploen, 2007; Blackmore, 2016).
  • Safety filters: control barrier function QPs project desired inputs onto a convex safe set at kilohertz rates (Ames et al., 2019).
  • Convex losses in ML: least squares, logistic regression, SVMs and lasso all have global optima and strong theory (A6.2-6, A6.2-7).
  • Convex relaxations give certificates for non-convex problems, as in SDP relaxations for SLAM and pose estimation (Rosen et al., 2019).

References

  1. S. Boyd, L. Vandenberghe (2004). Convex Optimization. Cambridge University Press. Ch. 2–3.
  2. R. T. Rockafellar (1970). Convex Analysis. Princeton University Press.
  3. M. Grant, S. Boyd, Y. Ye (2006). “Disciplined convex programming.” In Global Optimization, Springer.
  4. S. Diamond, S. Boyd (2016). “CVXPY: a Python-embedded modeling language for convex optimization.” JMLR, 17.
  5. R. Dykstra (1983). “An algorithm for restricted least squares regression.” JASA, 78(384).
  6. H. Bauschke, P. Combettes (2017). Convex Analysis and Monotone Operator Theory in Hilbert Spaces, 2nd ed. Springer.
  7. B. Açıkmeşe, S. Ploen (2007). “Convex programming approach to powered descent guidance for Mars landing.” Journal of Guidance, Control, and Dynamics, 30(5).
  8. L. Blackmore (2016). “Autonomous precision landing of space rockets.” The Bridge (NAE), 46(4).
  9. A. Ames et al. (2019). “Control barrier functions: theory and applications.” European Control Conference.
  10. D. Rosen, L. Carlone, A. Bandeira, J. Leonard (2019). “SE-Sync: a certifiably correct algorithm for synchronization over the special Euclidean group.” IJRR, 38(2–3).