Intuition What this page is
The parent note gave you the tests . This page runs those tests through every kind of function you'll meet : nice bowls, deceptive cubes, flat regions, functions defined only on part of the line, non-differentiable kinks, multi-variable surfaces, saddles, and a real ML loss. If you finish this page, no exam case can surprise you — because we already walked it.
Before anything: recall the three questions we ask of any function.
1D curvature test: is f ′′ ( x ) ≥ 0 for every x in the domain? (f ′′ = second derivative = "how fast the slope changes" = curvature.)
Multi-D curvature test: is the Hessian ∇ 2 f positive semidefinite (PSD) everywhere? (Hessian = the matrix of all second partial derivatives; PSD = v ⊤ H v ≥ 0 for every direction vector v .)
The word everywhere is the whole game. One bad point breaks convexity.
Definition Concave and strictly concave (the mirror image)
Concave: f is concave if − f is convex — equivalently f ′′ ≤ 0 everywhere (multi-D: Hessian negative semidefinite). The curve stays on-or-above every chord (a dome, holds nothing / spills).
Strictly concave: curve lies strictly above every chord for x = y (sufficient: f ′′ < 0 everywhere).
The chord inequality just flips: f ( λ x + ( 1 − λ ) y ) ≥ λ f ( x ) + ( 1 − λ ) f ( y ) .
Neither is the common case (a function whose f ′′ changes sign, like x 3 − 3 x ). Both happens only for affine functions (Ex 5).
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, f ′′ > 0 everywhere
none — the "yes" baseline
Ex 1
B
Sign of f ′′ flips
fails only on part of the line
Ex 2
C
f ′′ = 0 somewhere (degenerate/flat)
is "= 0 " still convex?
Ex 3
D
Restricted domain (x > 0 )
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 x
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 (∣ x ∣ , norms)
no f ′′ at the kink — new tool needed
Ex 11
Worked example Ex 1 (Cell A) —
f ( x ) = 3 x 2 − 12 x + 7
Forecast: guess now — convex, concave, or neither? Where's its lowest point?
Differentiate once: f ′ ( x ) = 6 x − 12 .
Why this step? The first derivative tells us where the slope is zero (a candidate minimum).
Differentiate again: f ′′ ( x ) = 6 .
Why this step? f ′′ is the curvature; a constant positive number means the curve cups upward identically everywhere — the definition of a bowl.
Read the test: f ′′ = 6 . Since 6 > 0 for all x , curvature is strictly positive everywhere, so f is strictly convex . (If we only knew f ′′ ≥ 0 we could claim convex ; here the stronger f ′′ > 0 upgrades us to strictly convex — see the definition box above.)
Why this step? We separate the two tiers cleanly: ≥ 0 ⇒ convex; the strict > 0 we actually have ⇒ strictly convex.
Find the min: set f ′ ( x ) = 0 ⇒ 6 x − 12 = 0 ⇒ x = 2 . Then f ( 2 ) = 3 ( 4 ) − 24 + 7 = − 5 .
Why this step? For a convex function a stationary point is automatically the global minimum — no other valley can exist.
Verify: f ( 1 ) = 3 − 12 + 7 = − 2 and f ( 3 ) = 27 − 36 + 7 = − 2 ; both are above − 5 , and they sit symmetrically around x = 2 . A single lowest point flanked by higher values — a true bowl. ✔
Read the figure (Fig s01 — convex parabola, flat tangent, chord): the blue parabola is the curve f = 3 x 2 − 12 x + 7 ; the dashed yellow line is the flat tangent at the minimum ( 2 , − 5 ) — the whole curve floats above it (the first-order convexity picture). The green segment is a chord joining ( 1 , − 2 ) and ( 3 , − 2 ) ; the curve dips below this chord, which is the chord-test signature of convexity.
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).
Worked example Ex 2 (Cell B) —
f ( x ) = x 3 − 3 x
Forecast: a cubic. Convex? On part of the line? Nowhere?
First derivative: f ′ ( x ) = 3 x 2 − 3 .
Why this step? Not needed for convexity but shows the two turning points at x = ± 1 , hinting the shape wiggles.
Second derivative: f ′′ ( x ) = 6 x .
Why this step? This is the curvature we test. Notice it depends on x — a red flag.
Check the sign region by region:
x > 0 : f ′′ = 6 x > 0 ⇒ cups up (locally convex).
x < 0 : f ′′ = 6 x < 0 ⇒ cups down (locally concave).
x = 0 : f ′′ = 0 ⇒ inflection point (curvature switches).
Why this step? Convexity demands f ′′ ≥ 0 everywhere ; the region x < 0 violates it.
Verdict: not convex (and not concave either — it's neither).
Why this step? Convexity requires f ′′ ≥ 0 on the whole domain and concavity requires f ′′ ≤ 0 on the whole domain; since f ′′ = 6 x is positive on one side and negative on the other, neither condition can hold everywhere, so the function belongs to the "neither" category from the concave definition box.
Verify (chord test at x = − 2 , y = 0 ): midpoint = − 1 , f ( − 1 ) = ( − 1 ) 3 − 3 ( − 1 ) = − 1 + 3 = 2 . Chord midpoint value = 2 f ( − 2 ) + f ( 0 ) = 2 ( − 2 ) + 0 = − 1 . The curve at − 1 sits at 2 , which is above the chord value − 1 — the curve pokes above the chord, exactly the concave violation. ✔ Not convex.
Read the figure (Fig s02 — cubic sign flip): the green segment is the chord from x = − 2 to x = 0 ; the red dot at x = − 1 marks the curve poking above that chord (convexity would forbid this). The yellow dot at x = 0 is the inflection point where f ′′ changes sign.
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.
Worked example Ex 3 (Cell C) —
f ( x ) = x 4
Forecast: its second derivative is 0 at the origin. Does one flat point break convexity?
Curvature: f ′′ ( x ) = 12 x 2 .
Why this step? We need its sign on the whole line.
Sign check: 12 x 2 ≥ 0 for every real x (a square is never negative), and = 0 only at x = 0 .
Why this step? The test is "≥ ", not "> ". Touching zero at isolated points is allowed .
Verdict: convex (in fact strictly convex, because the curve still lies strictly below every chord even though the curvature vanishes for an instant at the bottom).
Why this step? Distinguish "f ′′ ≥ 0 everywhere" (convex) from "f ′′ > 0 everywhere" (a sufficient but not necessary condition). x 4 shows a function can be strictly convex with f ′′ ( 0 ) = 0 .
Verify (chord test x = − 1 , y = 1 ): midpoint 0 , f ( 0 ) = 0 ; chord value 2 f ( − 1 ) + f ( 1 ) = 2 1 + 1 = 1 . Curve 0 < 1 chord ✔ (strict). The flat instant did not break the bowl.
f ′′ ( x 0 ) = 0 means not strictly convex."
Why it feels right: strict convexity is often defined via f ′′ > 0 .
The fix: f ′′ > 0 is only sufficient . x 4 is strictly convex with f ′′ ( 0 ) = 0 . Judge strictness by the chord, not by a single derivative value.
Worked example Ex 4 (Cell D) —
f ( x ) = − log x and g ( x ) = 1/ x , on x > 0
Forecast: logs and reciprocals — surely wild? Watch what the restricted domain does.
− log x , curvature: d x d ( − log x ) = − x 1 , then d x 2 d 2 ( − log x ) = x 2 1 .
Why this step? − log x only exists for x > 0 , so the domain is already the ray x > 0 .
Sign: x 2 1 > 0 for all x > 0 ⇒ convex on its whole domain.
Why this step? There is no x ≤ 0 to worry about — the domain excludes the trouble. Convexity is stated relative to the domain .
1/ x , curvature: d x d x − 1 = − x − 2 , then d x 2 d 2 x − 1 = 2 x − 3 .
Why this step? Same idea, but now the sign of 2/ x 3 tracks the sign of x .
Sign of 2/ x 3 : on x > 0 it is > 0 ⇒ convex there. On x < 0 it is < 0 ⇒ concave there. So 1/ x is convex only on x > 0 , not on its full natural domain x = 0 .
Why this step? This is the classic "state the domain or the answer is meaningless" trap.
Verify: at x = 2 , − log : f ′′ = 1/4 > 0 ✔ convex. 1/ x : f ′′ = 2/8 = 0.25 > 0 ✔ convex on positive side. At x = − 2 , 1/ x : f ′′ = 2/ ( − 8 ) = − 0.25 < 0 ✔ concave on negative side — confirms domain-dependence.
Worked example Ex 5 (Cell E) —
f ( x ) = 5 x − 2
Forecast: a straight line. One of the categories, or two at once?
Curvature: f ′ ( x ) = 5 , f ′′ ( x ) = 0 everywhere.
Why this step? Zero curvature means the chord and the curve coincide — no bending at all.
Convex? 0 ≥ 0 ✔. Concave? 0 ≤ 0 ✔.
Why this step? The convex test needs f ′′ ≥ 0 and the concave test (from the concave definition box) needs f ′′ ≤ 0 ; the value 0 satisfies both inequalities simultaneously, which is only possible when f ′′ is exactly 0 .
Verdict: the only functions that are both convex and concave are affine ones (a x + b ).
Verify (chord = curve): x = 0 , y = 4 , midpoint 2 : curve f ( 2 ) = 8 ; chord 2 f ( 0 ) + f ( 4 ) = 2 − 2 + 18 = 8 . Equal — line lies on its own chord. ✔
Worked example Ex 6 (Cell F) —
f ( x , y ) = 2 x 2 + 3 y 2
Forecast: two positive squared terms. Convex bowl? Prove it via the Hessian.
Gradient: ∇ f = ( 4 x , 6 y ) .
Why this step? First partials; setting them to 0 locates the candidate min at the origin.
Hessian: ∇ 2 f = [ 4 0 0 6 ] .
Why this step? The Hessian collects all second partials; for a quadratic it's constant (same everywhere), so one check settles the whole plane.
Check PSD via eigenvalues: a diagonal matrix has its diagonal as eigenvalues: 4 and 6 , both > 0 ⇒ positive definite ⇒ certainly PSD.
Why this step? PSD everywhere is exactly the multivariate convexity test; positive-definite is the strict "every direction curves up" case.
Verdict: strictly convex ; global min at ( 0 , 0 ) with f = 0 .
Why this step? Both eigenvalues are strictly positive at every point (they're constants), so v ⊤ H v > 0 for every nonzero direction — that's positive definiteness, which certifies strict convexity and guarantees the single stationary point at the origin is the unique global minimum.
Verify (test direction v = ( 1 , 1 ) ): v ⊤ H v = 4 ( 1 ) 2 + 6 ( 1 ) 2 = 10 > 0 ✔ — bends up along the diagonal too, not just along axes.
Read the figure (Fig s03 — bowl contours): these are contour lines (level sets) of the surface — each ring is where f 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 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.
Worked example Ex 7 (Cell G) —
f ( x , y ) = x 2 − 4 y 2
Forecast: one plus, one minus. Bowl, dome, or something with a pass through it?
Hessian: ∇ 2 f = [ 2 0 0 − 8 ] .
Why this step? Constant again (quadratic), so one look decides everything.
Eigenvalues: 2 and − 8 — mixed signs ⇒ indefinite .
Why this step? A single negative eigenvalue means there's a direction where the surface curves down , so PSD fails.
Interpret the directions: along x (v = ( 1 , 0 ) ): v ⊤ H v = 2 > 0 (valley). Along y (v = ( 0 , 1 ) ): v ⊤ H v = − 8 < 0 (ridge). The origin is a saddle point — a min one way, a max the other.
Why this step? This is why Gradient Descent can stall here: the gradient is zero but it's not a minimum.
Verdict: not convex .
Why this step? Convexity demands PSD (all eigenvalues ≥ 0 ) everywhere; the − 8 eigenvalue means one direction bends downward, so the multivariate test fails and the "curve below every chord" property is broken along the y -axis.
Verify: f ( 1 , 0 ) = 1 > 0 = f ( 0 , 0 ) (up along x ) and f ( 0 , 1 ) = − 4 < 0 = f ( 0 , 0 ) (down along y ). Origin is higher than some neighbours and lower than others — a saddle, confirmed. ✔
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 (x , curving up); the red arrow is the ridge direction (y , curving down). One up, one down = indefinite Hessian = not convex.
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.
Worked example Ex 8 (Cell H) —
f ( x , y ) = x 4 + y 2
Forecast: the x 4 made a flat spot in 1D. Does the 2D version stay convex everywhere?
Gradient: ∇ f = ( 4 x 3 , 2 y ) .
Why this step? First partials; note the x -part is nonlinear, so the Hessian won't be constant.
Hessian: ∇ 2 f = [ 12 x 2 0 0 2 ] .
Why this step? Because entries depend on x , we must check PSD at every point, not just one.
PSD at a general point: eigenvalues are 12 x 2 and 2 . Now 12 x 2 ≥ 0 (a square) for every x , and 2 > 0 always. Both eigenvalues ≥ 0 everywhere ⇒ PSD everywhere ⇒ convex.
Why this step? At x = 0 one eigenvalue is 0 (touching PSD's boundary), still allowed — this is the multi-D echo of Ex 3.
Verdict: convex; global min at origin, f = 0 .
Why this step? PSD held at every point (worst case x = 0 still gave both eigenvalues ≥ 0 ), so the "everywhere" requirement is met and convexity — hence the local=global guarantee — is secured.
Verify (worst case x = 0 , direction v = ( 1 , 1 ) ): H ( 0 , y ) = diag ( 0 , 2 ) , v ⊤ H v = 0 ⋅ 1 + 2 ⋅ 1 = 2 ≥ 0 ✔. Even at the flattest point no direction bends down.
Worked example Ex 9 (Cell I) — squared-error loss
L ( w ) = 2 1 ∑ i ( w x i − y i ) 2 (single weight)
Forecast: this is what linear regression minimizes. Convex in the weight w ?
With data x = ( 1 , 2 ) , y = ( 2 , 2 ) so L ( w ) = 2 1 [ ( w − 2 ) 2 + ( 2 w − 2 ) 2 ] .
Expand: L ( w ) = 2 1 [ ( w 2 − 4 w + 4 ) + ( 4 w 2 − 8 w + 4 ) ] = 2 1 ( 5 w 2 − 12 w + 8 ) = 2.5 w 2 − 6 w + 4 .
Why this step? Turning a sum of squares into a single quadratic makes the curvature obvious.
Curvature: L ′′ ( w ) = 5 .
Why this step? A sum of squared linear terms is always a quadratic with nonnegative leading coefficient — that's the structural reason least-squares is convex.
Test and verdict: L ′′ = 5 . Since 5 ≥ 0 (indeed > 0 ) for every w , the 1D curvature test is satisfied everywhere, so L is convex — in fact strictly convex.
Why this step? Convexity is a claim about the whole domain; here L ′′ is a positive constant, so there is no region where it could dip negative, which is exactly why least-squares has a single basin and convex methods (or plain gradient descent) reach the global best fit — local = global .
Min: L ′ ( w ) = 5 w − 6 = 0 ⇒ w = 1.2 , and L ( 1.2 ) = 2.5 ( 1.44 ) − 7.2 + 4 = 3.6 − 7.2 + 4 = 0.4 .
Why this step? Convexity guarantees this stationary point is the global best-fit weight, so we can stop the moment the gradient hits zero.
Verify: L ( 1 ) = 2.5 − 6 + 4 = 0.5 and L ( 1.4 ) = 2.5 ( 1.96 ) − 8.4 + 4 = 4.9 − 8.4 + 4 = 0.5 ; both exceed 0.4 and straddle w = 1.2 symmetrically. A single true minimum. ✔
Worked example Ex 10 (Cell J) — is
h ( x ) = e x + max ( 0 , x ) 2 convex? (a ReLU-squared style term)
Forecast: a sum of two pieces, one non-smooth. Trap or fine?
Piece 1 — e x , derived here (not on faith): d x d e x = e x , so d x 2 d 2 e x = e x . Since e x > 0 for every real x , we have f ′′ > 0 everywhere ⇒ e x is (strictly) convex.
Why this step? We must earn e x 's convexity from its own second derivative, not borrow it from an unrelated example.
Piece 2 — g ( x ) = max ( 0 , x ) 2 , curvature by pieces: for x ≤ 0 , g ( x ) = 0 (curvature 0 ); for x ≥ 0 , g ( x ) = x 2 (curvature 2 ). Both pieces have curvature ≥ 0 .
Why this step? Convexity is checked region by region wherever g is smooth.
Handle the kink at x = 0 rigorously (subgradient/epigraph): at x = 0 the left slope is g ′ ( 0 − ) = 0 and the right slope is g ′ ( 0 + ) = 0 ; the slope is non-decreasing as we pass through 0 (0 → 0 , then rising). A one-variable function is convex iff its slope (subgradient) is non-decreasing across its whole domain — equivalently, its epigraph (the region on-or-above the graph) is a convex set. Here the slope never drops, and the epigraph has no dents, so g is convex including at the join. (No downward corner is created because both one-sided slopes agree at 0 .)
Why this step? At a non-differentiable point we cannot use f ′′ ; the correct tool is "slopes never decrease" (or "epigraph is convex"), which certifies the kink honestly.
Sum rule: a sum of convex functions is convex . Because if f 1 , f 2 each stay on-or-below their chords, adding the two chord inequalities shows f 1 + f 2 does too.
Why this step? This reusable theorem certifies built-up ML losses (data term + regularizer) without recomputing a Hessian.
Verdict: e x convex + g convex ⇒ h is convex .
Why this step? Both summands passed their own convexity checks, and the sum rule from step 4 transfers that property to h with no extra work — the whole point of learning operation-preserving rules.
Verify (chord test x = − 1 , y = 2 for g ): midpoint 0.5 , g ( 0.5 ) = 0.25 ; chord 2 g ( − 1 ) + g ( 2 ) = 2 0 + 4 = 2 . Curve 0.25 ≤ 2 ✔ convex piece. Adding convex e x keeps it convex.
Recall Which operations preserve convexity? (memorize these)
Sum of convex is convex ::: yes (add chord inequalities)
Nonnegative scaling c ⋅ f , c ≥ 0 ::: convex
Max of convex functions ::: convex (pointwise max keeps the bowl)
Composition g ( f ( x )) with g convex AND nondecreasing, f convex ::: convex (the full rule — both conditions on g required)
Product of two convex functions ::: NOT guaranteed convex
Worked example Ex 11 (Cell K) —
f ( x ) = ∣ x ∣ (and the 2D norm ∥( x , y ) ∥ 2 )
Forecast: ∣ x ∣ has a sharp corner at 0 where f ′′ does not exist . Can something with no second derivative still be convex?
Spot the problem: f ( x ) = ∣ x ∣ equals − x for x < 0 and + x for x > 0 . The slope is − 1 then + 1 — it jumps at x = 0 , so f ′ ( 0 ) and hence f ′′ ( 0 ) do not exist .
Why this step? We must admit the curvature test is unusable here; pretending f ′′ = 0 would be wrong because f ′ is discontinuous.
Switch tools — use the chord definition directly (it never mentions derivatives): check f ( λ x + ( 1 − λ ) y ) ≤ λ f ( x ) + ( 1 − λ ) f ( y ) . The triangle inequality gives ∣ λ x + ( 1 − λ ) y ∣ ≤ ∣ λ x ∣ + ∣( 1 − λ ) y ∣ = λ ∣ x ∣ + ( 1 − λ ) ∣ y ∣ (using λ , 1 − λ ≥ 0 ).
Why this step? The master chord definition is more fundamental than f ′′ ; it works for any function, differentiable or not, so it is the right instrument at a kink.
Slope (subgradient) view for a picture: the slope is − 1 on the left and + 1 on the right — it only ever increases as we move rightward through 0 . A 1D function is convex iff its slope is non-decreasing, and a jump upward (− 1 → + 1 ) qualifies. The corner points up into a V, never down into a peak.
Why this step? It shows the kink is a convex corner (a valley), giving the same verdict geometrically without needing f ′′ .
Verdict: convex (but not strictly convex — the two straight arms each lie on their chords, so equality can occur; and not differentiable at 0 ). The same triangle-inequality argument makes every norm ∥ v ∥ convex, which is why L 1 /L 2 regularizers keep ML objectives convex.
Why this step? We record all edge attributes at once — convex yet non-strict and non-smooth — so no scenario is left unstated.
Verify (chord test x = − 3 , y = 1 ): midpoint − 1 , f ( − 1 ) = 1 ; chord 2 f ( − 3 ) + f ( 1 ) = 2 3 + 1 = 2 . Curve 1 ≤ 2 ✔. A degenerate direction: x = − 2 , y = 2 midpoint 0 , f ( 0 ) = 0 , chord 2 2 + 2 = 2 , 0 ≤ 2 ✔ — the corner sits below its chord.
Read the figure (Fig s05 — the V and its chord): the blue V is ∣ x ∣ ; the sharp red corner at the origin is where f ′′ fails to exist. The green chord joining ( − 3 , 3 ) and ( 1 , 1 ) lies entirely above the curve — convexity confirmed by the chord test, not by curvature.
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.
Common mistake "No second derivative at a point ⇒ can't be convex there."
Why it feels right: we lean on f ′′ ≥ 0 as the convexity test.
The fix: f ′′ is just one sufficient lens for smooth functions. The chord definition (and the "slope non-decreasing" / "epigraph convex" views) are the real definition and handle kinks like ∣ x ∣ and norms perfectly. Convex = smooth.
The word that makes or breaks every convexity test everywhere — one bad point kills it.
f ′′ ( x 0 ) = 0 at an isolated point meansstill possibly convex (test is ≥ , e.g. x 4 ).
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 − f is convex, equivalently f ′′ ≤ 0 everywhere (curve above every chord).
Is ∣ x ∣ convex? Yes (by chord / triangle inequality) — but not strictly convex and not differentiable at 0 .