Convex sets and functions
凸集与凸函数
Use line segments to define convexity, connect it to supporting planes and curvature, and separate global guarantees from numerical spot checks.
convexityMix two choices without leaving the allowed region
Suppose a recipe permits nonnegative fractions of three ingredients summing to one. Averaging two valid recipes gives another valid recipe. The feasible region is convex. By contrast, two points on a circle can have a midpoint inside the circle, outside the circumference itself: the circumference is not a convex set, though the filled disk is.
Now put a cost on each recipe. A convex cost says that mixing two feasible choices costs no more than mixing their costs. It is a precise inequality, not just the visual impression of a bowl. This geometry is what allows certain local optimization conditions to imply global conclusions. Convex Optimization, Sections 2.1 and 3.1
The domain is part of the definition
A set C is convex when every segment between points of C remains inside C. A real function f on C is convex when C is convex and
Strict convexity requires strict inequality for distinct x and y and interior weights . An affine function gives equality everywhere and is both convex and concave. A convex function need not be differentiable: absolute value is a simple example.
For a differentiable function on an open convex domain, convexity is equivalent to the global supporting-plane condition
To obtain this from the segment inequality, apply it at , subtract f(x), divide by positive t, and let t decrease to zero. Conversely, apply supporting inequalities from an intermediate point to x and y; multiply by the mixing weights and add. The gradient terms cancel, giving the original definition.
For a twice continuously differentiable function on an open convex domain, convexity is equivalent to at every x. Along each line, the second derivative is ; its nonnegativity makes the first derivative nondecreasing and gives the supporting inequality. Checking H at only one point does not establish global convexity. Convex Optimization, Sections 3.1.3–3.1.4
For symmetric S and , direct expansion gives a useful identity:
This proves q is convex exactly when S is positive semidefinite. A single negative direction gives an explicit violating pair. It connects the line-segment definition to quadratic forms without requiring an optimization algorithm.
Search for a counterexample with exact fractions
The program computes the gap between the two sides of the convexity inequality. It uses rational inputs to avoid rounding obscuring a negative gap. The helper assumes f is defined at all queried points and returns exact rational values; callers must separately verify the domain is convex.
from fractions import Fraction as F
def jensen_gap(f, x, y, weight):
if not x or len(x)!=len(y) or not F(0)<=weight<=F(1):
raise ValueError("matching nonempty vectors and a weight in [0,1] required")
z = [weight*a+(1-weight)*b for a,b in zip(x,y)]
return weight*f(x)+(1-weight)*f(y)-f(z)
def bowl(x):
a,b = x
return (a+b)**2+2*b*b
def saddle(x):
a,b = x
return a*a-b*b
for weight in [F(0),F(1,4),F(1,2),F(1)]:
x,y = [F(2),F(-1)],[F(-1),F(3)]
gap = jensen_gap(bowl,x,y,weight)
difference = [a-b for a,b in zip(x,y)]
assert gap == weight*(1-weight)*bowl(difference)
assert gap >= 0
assert jensen_gap(saddle,[F(0),F(1)],[F(0),F(-1)],F(1,2)) == -1
# A positive observed gap does not certify every untested pair.
assert jensen_gap(saddle,[F(1),F(0)],[F(-1),F(0)],F(1,2)) == 1
For d-dimensional vectors, forming a mixture costs operations and storage, plus three evaluations of f. Arithmetic on fractions also has a bit-length cost. Testing N chosen pairs costs N such evaluations. Finding a negative gap disproves convexity. Finding no violation in a finite set of tests does not prove the inequality for all pairs.
Global optimality is not automatic existence
If a differentiable convex function has zero gradient at an interior point, its supporting inequality proves that point is globally minimizing. A local minimum of a convex function over a convex feasible set is also global: if a better point existed, points arbitrarily close along the connecting segment would improve the value, contradicting local minimality.
Strict convexity guarantees at most one minimizer over a convex set, not existence. The strictly convex function on the real line has infimum zero but never attains it. The strictly convex function has zero second derivative at zero, so a positive-definite Hessian everywhere is sufficient for strict convexity but not necessary.
A positive Hessian on a disconnected domain cannot repair the missing convex-domain condition. For on nonzero real numbers, the second derivative is positive at every allowed point, yet the segment from −1 to 1 passes through an excluded point. This is not a convex function on that entire domain. It is convex on each separate positive or negative half-line.
Neural networks can have convex losses as functions of their predictions while remaining nonconvex as functions of all their weights. Convexity does survive affine composition and nonnegative weighted sums; an arbitrary nonlinear composition needs additional conditions. MML, Section 7.3
Find the missing assumption
- Is a probability simplex convex? Answer: yes. Mixtures preserve nonnegativity and total mass one.
- Does positive second derivative everywhere on the domain prove convexity? Answer: only with the required convex-domain conditions; the disconnected example shows the gap.
- Does strict convexity guarantee a solution exists? Answer: no; on the real line has no minimizer.
- The saddle passes a hundred tests along the first axis. What should you try next? Answer: the opposite points and ; their midpoint yields a negative Jensen gap of −1.
Guarantees worth preserving
Convex formulations provide useful baselines and optimization certificates, even when a later model is nonconvex. A convex relaxation changes a problem to gain tractable structure; it must still be checked for how its solution relates to the original constraints. Strong convexity adds a uniform quadratic lower bound and can support quantitative convergence rates. The definitions here explain why those extra assumptions matter; they are not interchangeable labels for a surface that merely looks smooth.
Make a prediction, then check
Must a strictly convex function have a minimizer?
Learning objectives
- Analyze convexity using segment inequalities, supporting planes, and Hessians.
- Use counterexamples to separate strict convexity, uniqueness, and existence.
Prerequisites & connections
Explore related knowledge →References
- Convex Optimization
Stephen Boyd; Lieven Vandenberghe · 2004 - Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: specified-source comparison, derivation checks, independent numerical checks, and paragraph-level bilingual comparison; no independent human peer review.
- Verified the exact quadratic Jensen-gap identity for 100 rational pairs and checked a negative-direction counterexample; finite checks are not treated as a proof.
- Checked both support-plane implications, the local-to-global proof, unattained exp infimum, and x⁴ without everywhere-positive curvature; retained the convex-domain condition.
- Compared bilingual assumptions, claims, numbers, exercise answers and citations; structural checks additionally compare formulas, code, main anchors and source IDs.
Source locations checked:
- Convex Optimization · §§2.1 and 3.1.3–3.1.4, convex domains, support inequality, Hessian and strict-convexity counterexample
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft) · §7.3, printed pp.237–239 / PDF243–245, convexity and nonnegative weighted sums
Related topics