1.2.8 · D2Calculus & Optimization Basics

Visual walkthrough — Convex vs non-convex functions

2,040 words9 min readBack to topic

We will earn every symbol before using it. By the last figure you will see why non-convex landscapes have "fake bottoms" and convex ones don't.


Step 0 — What is a "graph", a "chord", and a "tangent"?

Before any formula, three plain-English pictures.

  • A graph of a function is just the set of dots you get by sweeping an input left-to-right and stacking its output upward as height. Think of a landscape seen from the side: horizontal = where you stand, vertical = how high the ground is.
  • A chord is a straight ruler laid across the graph touching it at exactly two points. It is the shortcut between two spots on the curve.
  • A tangent is a straight ruler that just kisses the graph at one point without crossing it — the direction you'd slide if you were a marble sitting right there.
Figure — Convex vs non-convex functions

Step 1 — The convex inequality, symbol by symbol

WHAT. We write down what "curve stays below the chord" means as a formula.

WHY. A picture is convincing but not checkable. We need something a machine — or a proof — can test. So we translate the picture into arithmetic.

First we need to name the "in-between point." Slide a knob (Greek lambda) from to . It is a mixing dial:

  • When : (all weight on ).
  • When : (all weight on ).
  • When : , the exact midpoint.

So walks us smoothly along the horizontal axis from to .

Figure — Convex vs non-convex functions

Now the definition:

  • Left side: go to the mixed input , then read the curve's height — the black dot.
  • Right side: the same mixing dial applied to the two heights and — that is exactly where the red ruler sits above .
  • : curve height is at most ruler height. Curve below chord. That is convex.

Step 2 — The tangent test (the "instant chord")

WHAT. We replace the two-point chord with a one-point tangent line.

WHY. Chords compare two far-apart points. Optimization asks a local question: "from where I stand, where is down?" That is a tangent question. So we shrink one end of the chord toward the other.

To talk about a tangent we need the word slope: the slope of at is how fast height changes per step sideways — steepness. In one dimension we write it (read "f-prime of x"). The tangent line through the point is:

  • : where the tangent is pinned.
  • : rise = slope run, the straight-line prediction of height at .

The tangent version of convex says the curve sits above every tangent:

Figure — Convex vs non-convex functions

Step 3 — The flat-spot punchline (why convex ⇒ global min)

WHAT. We plug a flat tangent into Step 2.

WHY. Gradient Descent stops where the slope is zero — a stationary point. We want to know what a zero slope guarantees for a convex function.

Suppose at some point the slope is zero: . Put that into the boxed tangent inequality:

  • The whole slope term vanishes because .
  • What remains: for every .

Read that last line out loud: no point anywhere is lower than . A flat spot on a convex curve is the global minimum — not merely local. There is no "over the hill" that could be deeper, because the flat tangent is a floor the whole graph rests on.

Figure — Convex vs non-convex functions

Step 4 — Where does convexity come from? Curvature

WHAT. We show a curve guarantees the tangent test if it never bends downward.

WHY. Steps 2–3 assumed convexity. But how do we check it on a real function? We need a computable handle. That handle is the second derivative — the slope of the slope, i.e. how fast the steepness itself changes. If , the steepness only ever increases: the curve keeps turning upward, cupping like a bowl.

We use one tool — Taylor's theorem with exact remainder — because it is the only device that writes a curve's value exactly in terms of a tangent line plus a leftover curvature term:

  • The first bracket is exactly the tangent height from Step 2.
  • The second bracket is everything the tangent missed, packed into a single curvature term evaluated at some hidden point sitting between and .

Now bound the leftover. Two of its pieces are always :

Multiply three non-negative things → the leftover is . Drop it, and the equation becomes an inequality:

That is the boxed tangent test of Step 2. So everywhere forces convexity. Chain the steps: tangent test flat spot is global min.

Figure — Convex vs non-convex functions

See Taylor Series Expansion for the machinery, and Hessian Matrix for the multi-dimensional twin of .


Step 5 — The degenerate case: (a flat straight line)

WHAT. We test the boundary where curvature is exactly zero.

WHY. The rule was , allowing equality. A good walkthrough must show the edge, not just the strict interior. What happens when the curve doesn't cup at all?

If everywhere, the leftover term is exactly , so Step 4 gives with equality. The "curve" is a straight line — an affine function. It sits on every chord and on every tangent simultaneously.

  • Curve chord? Yes (equal counts as ). So it is convex.
  • Curve chord? Also yes. So it is concave too.

A straight line is the one shape that is convex and concave at once. This is the razor's edge: nudge up a hair and you get a bowl; nudge it down and you get a dome.

Figure — Convex vs non-convex functions

Step 6 — The failure case: changes sign (non-convex, fake bottoms)

WHAT. We break the rule on purpose and watch the guarantee die.

WHY. The parent's whole warning — Gradient Descent can get trapped — lives here. We must see the trap.

Take . Its curvature is , which is negative for and positive for . Where the curve bends downward (domes), where it cups. The curve threads below some chords and above others — the convex inequality fails.

The damage: there is a flat spot (a local minimum) that is not the global bottom. A marble released nearby settles there, "thinks" it is done, while a deeper valley waits over the ridge. The tangent floor of Step 3 no longer supports the whole graph because there is no single tangent everything sits above. This is exactly a saddle-like / multi-basin landscape, the reason Local vs Global Minima stop agreeing.

Figure — Convex vs non-convex functions

The one-picture summary

Everything above compressed into a single frame: a convex bowl (left) whose only flat spot is the true bottom, versus a non-convex ridge (right) with a fake bottom trapping the marble. The red marble tells the whole story — one honest valley vs. many deceptive dips.

Figure — Convex vs non-convex functions
Recall Feynman retelling — the whole walkthrough in plain words

Picture a skate ramp seen from the side. Lay a ruler across any two points on it. If the ramp always ducks under the ruler, it's a convex bowl. Now shrink the ruler until it just kisses one spot — that's a tangent, the way a marble would roll from there. Convex means the ramp never dips under any such kiss-line either; every tangent is a floor the ramp rests on. So if you find a spot where the tangent is perfectly flat, that flat floor lies under the entire ramp — nothing anywhere is lower. That flat spot is the deepest point, period. Why is a ramp convex in the first place? Because its steepness only ever increases as you walk right — it keeps curling upward (). A perfectly straight ramp () is the borderline: bowl and dome at once. But bend a piece downward somewhere () and you've built a skate park with little dips; a marble parks in the nearest one and swears it's done, while a deeper valley hides over the hill. Convex = one honest bowl. Non-convex = fake bottoms.


Connections