1.2.8 · D3Calculus & Optimization Basics

Worked examples — Convex vs non-convex functions

4,171 words19 min readBack to topic

Before anything: recall the three questions we ask of any function.

  • 1D curvature test: is for every in the domain? ( = second derivative = "how fast the slope changes" = curvature.)
  • Multi-D curvature test: is the Hessian positive semidefinite (PSD) everywhere? (Hessian = the matrix of all second partial derivatives; PSD = for every direction vector .)
  • The word everywhere is the whole game. One bad point breaks convexity.

The scenario matrix

Every convexity question you can be asked falls into one of these cells. The examples below are labelled with the cell they cover.

Cell Case class What makes it tricky Example
A Clean bowl, everywhere none — the "yes" baseline Ex 1
B Sign of flips fails only on part of the line Ex 2
C somewhere (degenerate/flat) is "" still convex? Ex 3
D Restricted domain () convex only because domain is cut Ex 4
E Affine / linear both convex AND concave Ex 5
F Multi-D positive-definite bowl Hessian PSD in every direction Ex 6
G Multi-D indefinite → saddle one direction bends down Ex 7
H Multi-D but Hessian depends on must hold at all points Ex 8
I Real-world ML loss convex in parameters? Ex 9
J Exam twist: sum / composition rule convexity survives certain operations Ex 10
K Non-differentiable convex (, norms) no at the kink — new tool needed Ex 11

Cell A — the clean bowl

Read the figure (Fig s01 — convex parabola, flat tangent, chord): the blue parabola is the curve ; the dashed yellow line is the flat tangent at the minimum — the whole curve floats above it (the first-order convexity picture). The green segment is a chord joining and ; the curve dips below this chord, which is the chord-test signature of convexity.

Figure — Convex vs non-convex functions
Figure s01: Cell A — a convex bowl. Curve stays below its chord (green) and above its flat tangent (yellow dashed); red dot marks the single global minimum at (2, −5).


Cell B — the sign flip

Read the figure (Fig s02 — cubic sign flip): the green segment is the chord from to ; the red dot at marks the curve poking above that chord (convexity would forbid this). The yellow dot at is the inflection point where changes sign.

Figure — Convex vs non-convex functions
Figure s02: Cell B — the cubic x^3−3x. The curve (blue) rises above its chord (green) in the left region, and the yellow dot at x=0 is the inflection point where curvature flips sign: not convex, not concave.


Cell C — the flat spot ()


Cell D — convex only because we cut the domain


Cell E — affine: convex AND concave


Cell F — a genuine multi-D bowl

Read the figure (Fig s03 — bowl contours): these are contour lines (level sets) of the surface — each ring is where equals a fixed height. Nested closed loops shrinking to the red dot at the origin is the visual fingerprint of a convex bowl: no matter which way you leave the centre, you climb.

Figure — Convex vs non-convex functions
Figure s03: Cell F — contour map of 2x^2+3y^2. Concentric closed loops nesting toward the red central dot (global min at the origin) are the signature of a convex bowl.


Cell G — the saddle

Read the figure (Fig s04 — saddle contours): the contours here cross through the origin instead of nesting — the tell-tale saddle pattern. The green arrow is the valley direction (, curving up); the red arrow is the ridge direction (, curving down). One up, one down = indefinite Hessian = not convex.

Figure — Convex vs non-convex functions
Figure s04: Cell G — contour map of x^2−4y^2. Contours cross (not nest) at the origin; the green arrow marks the upward valley direction and the red arrow the downward ridge direction — an indefinite Hessian saddle.


Cell H — Hessian that varies with position


Cell I — a real ML loss


Cell J — exam twist: does convexity survive operations?

Recall Which operations preserve convexity? (memorize these)

Sum of convex is convex ::: yes (add chord inequalities) Nonnegative scaling , ::: convex Max of convex functions ::: convex (pointwise max keeps the bowl) Composition with convex AND nondecreasing, convex ::: convex (the full rule — both conditions on required) Product of two convex functions ::: NOT guaranteed convex


Cell K — non-differentiable convex functions

Read the figure (Fig s05 — the V and its chord): the blue V is ; the sharp red corner at the origin is where fails to exist. The green chord joining and lies entirely above the curve — convexity confirmed by the chord test, not by curvature.

Figure — Convex vs non-convex functions
Figure s05: Cell K — the non-differentiable convex function |x|. The curve is a V with a sharp corner (red) at the origin where no second derivative exists; the green chord still lies on-or-above the curve, so the chord definition certifies convexity where the curvature test cannot.


Recap cloze

The word that makes or breaks every convexity test
everywhere — one bad point kills it.
at an isolated point means
still possibly convex (test is , e.g. ).
Multi-D convexity requires the Hessian to be
PSD at every point, not just one.
A saddle has a Hessian that is
indefinite (mixed-sign eigenvalues).
Least-squares loss is convex because
it's a sum of squared linear terms ⇒ constant nonnegative curvature.
Convexity at a non-differentiable kink is certified by
slope (subgradient) non-decreasing / epigraph is a convex set / chord definition.
Definition of concave
is convex, equivalently everywhere (curve above every chord).
Is convex?
Yes (by chord / triangle inequality) — but not strictly convex and not differentiable at .

Connections