4.10.18 · D2Advanced Topics (Elite Level)

Visual walkthrough — First-order optimality conditions — gradient = 0

2,667 words12 min readBack to topic

Step 1 — What does "slope" even mean?

WHAT. Before any calculus, picture a smooth hill drawn as a curve. Pick a point on it. Zoom in. As you zoom, the curve looks more and more like a straight line — its tangent line. The slope of that line is a single number: how many steps up you go for one step to the right.

WHY. Optimisation is the question "can I get lower?" — and "can I get lower" is answered entirely by the slope under your feet. If the ground tilts, one direction goes down. So slope is the whole game; we must pin it down first.

PICTURE. In the figure below, the black curve is the hill. The magenta line is the tangent at the marked point. Its slope is the ratio (rise)/(run) shown by the orange triangle.

Figure — First-order optimality conditions — gradient = 0

Step 2 — Turning slope into a number we can compute

WHAT. To measure the slope at a point , take a tiny horizontal step of size and see how much height changes. Height at the new point is ; height at the old point is . Their difference over the step is the difference quotient:

WHY. We want the exact slope, but "exact" needs the step to shrink to nothing. The difference quotient is the honest rise-over-run for a step of real width ; shrinking hands us the tangent's slope — that limit is the derivative , which exists precisely because we assumed differentiable at . We use a limit (and not just plugging ) because plugging gives , which is meaningless — the limit is the tool built exactly to rescue that.

PICTURE. Two dots on the curve joined by a violet secant line; as the right dot slides toward the left dot the secant tips over into the magenta tangent.

Figure — First-order optimality conditions — gradient = 0

Step 3 — The setup: what "local minimum" promises us

WHAT. Say is a local minimum: no nearby point is lower. Formally, there is a small radius so that for every step with ,

The bar means " is smaller than in size, whether is positive or negative" — steps to the right and to the left are both allowed.

WHY. This single inequality is the only fact we have about a minimum. Everything below is squeezed out of it. Notice the crucial word interior: because sits inside the domain, both and stay legal. Hold that thought — Step 6 is where it bites.

PICTURE. A valley with a flat floor; a shaded band of width around ; every point of the curve in that band sits at or above the dashed floor line.

Figure — First-order optimality conditions — gradient = 0

Step 4 — Poke to the RIGHT (a one-sided limit, )

WHAT — first, what does mean? A one-sided limit from the right, written , asks: as shrinks toward but stays strictly positive (approaching only from the right, ), what value does the quantity home in on? It is the ordinary idea of a limit, but restricted to one side of . We split into sides precisely because "step right" () and "step left" () will tell us different things.

Now take steps to the right, so , and read the difference quotient piece by piece:

Top is because a minimum means every neighbour is at least as high. Bottom is because we stepped right. A non-negative number over a positive number is non-negative. Letting :

(Differentiability lets us call this one-sided limit — both one-sided limits equal the single derivative.)

WHY. A limit of numbers that are all cannot suddenly turn negative — it lands . So from the right side alone, the slope is non-negative: the tangent can't dip down as we look rightward.

PICTURE. The right-hand track of dots creeping toward from the right; the secant slopes are all , shown in orange.

Figure — First-order optimality conditions — gradient = 0

Step 5 — Poke to the LEFT (the mirror one-sided limit, )

WHAT. The one-sided limit from the left, , is the mirror of Step 4: shrinks toward but stays strictly negative (), approaching only from the left. Step left, so :

Top is still (a minimum is a minimum in both directions). But now the bottom is negative. A non-negative number divided by a negative number is . So

WHY. Only the sign of flipped, which flips the whole quotient's sign. From the left, the same derivative is forced to be non-positive.

PICTURE. Left-side secants, mirror image of Step 4, all tilting downward or flat in violet as the left dot slides toward .

Figure — First-order optimality conditions — gradient = 0

Step 6 — The squeeze: two inequalities crush into equality

WHAT. Because is differentiable at , the left-side and right-side one-sided limits are the same number . Step 4 said it is ; Step 5 said it is . A number that is both cannot budge:

WHY. This is why we needed both directions, and why the point must be interior. On a boundary you can only poke one way — you'd get just Step 4 or just Step 5, never both, and the slope could stay nonzero (pointing outward). The two-sided poke is the entire engine.

PICTURE. A number line for the value : an orange arrow from the right pins it , a violet arrow from the left pins it ; they collide at a single magenta dot on .

Figure — First-order optimality conditions — gradient = 0

Step 7 — Climbing to many variables, one axis at a time

WHAT. Now eats several inputs, e.g. — a landscape, not a curve. Freeze every coordinate except one. Sliding only along the -axis carves out a 1-D slice — call its height , where is the unit step along axis and is how far you've slid.

If is the lowest point of the whole landscape, it is certainly the lowest point along that single slice, so minimises . By Step 6, . And is exactly the partial derivative — the slope of if you only wiggle the -th input.

WHY. A many-variable minimum is a minimum along every one-dimensional line through it, so each slice hands us one flat-slope equation. Do this for every axis and all partials vanish. We now bundle those partial slopes into a single arrow, the gradient — the vector whose -th entry is (see Gradient and directional derivatives). Then "all partials zero" is exactly "the gradient arrow has zero length":

PICTURE. A bowl-shaped surface; two perpendicular slice-curves cut through the bottom, each showing a flat tangent at the base — one along , one along .

Figure — First-order optimality conditions — gradient = 0

Step 8 — The deepest reason: no downhill direction survives

WHAT — first, two tools we must define.

Tool A — the length (norm) of a vector. The gradient (built in Step 7) is an arrow with a direction and a length. Its length is written with double bars, , and computed by Pythagoras on its components:

Two facts we use: the norm is never negative, and it is zero only for the zero vector (a zero-length arrow is the arrow that points nowhere). So "" is just shorthand for " is a genuine, nonzero arrow."

Tool B — the directional derivative. The gradient points in the direction of steepest increase. The directional derivative answers: if I walk in a chosen unit direction (an arrow of length ), how fast does change? The formula is a dot product:

The dot product multiplies the two vectors' lengths by the cosine of the angle between them: it is largest when points with the gradient, zero when is perpendicular, and most negative when points against the gradient.

Now the argument. Suppose, for contradiction, , i.e. . Deliberately walk straight downhill, choosing the unit direction

Plug into the formula — dotting a vector with a scaled copy of itself gives its length squared over its length:

A negative slope means decreases as you walk — so was not a minimum. Contradiction. The only escape: .

WHY. This says why zero gradient is unavoidable: a nonzero gradient is literally an arrow labelled "improvement lives this way." A genuine optimum can't leave such an arrow lying around.

PICTURE. At a non-optimal point, the magenta gradient arrow points uphill; the orange arrow points downhill along the surface, tracing a path that visibly drops — proving the point was beatable.

Figure — First-order optimality conditions — gradient = 0

Step 9 — The traps: flat is not the same as bottom

WHAT. Flatness () is necessary, never sufficient. Three different shapes all pass the test:

  • Minimum: flat, and rising in every direction (a bowl).
  • Maximum: flat, and falling in every direction (a dome). Same proof — just swap for .
  • Saddle: flat, yet rising along one axis and falling along another. Example : along it climbs, along it drops, but all the same. See Saddle points.

Even in 1-D, has yet is an inflection, neither peak nor valley.

WHY. Our proof only ruled out "a direction that improves things immediately." A saddle has directions that improve — just not right at the flat point along the tested axis. That is exactly why the Hessian second-order test exists: to sort these three apart.

PICTURE. Three mini-landscapes side by side — bowl, dome, saddle — each with a flat magenta tangent plane at the centre dot, showing identical flatness but wildly different shapes.

Figure — First-order optimality conditions — gradient = 0

The one-picture summary

Everything at once: the two-sided poke traps the slope at zero (1-D), stacking that over all axes gives (many-D), and the flat point is only a finalist — bowl, dome, or saddle still to be decided.

Figure — First-order optimality conditions — gradient = 0
Recall Feynman: the whole walkthrough in plain words

You're standing somewhere on a smooth landscape and you want to know if you're at the lowest spot. You do one simple experiment: nudge your foot right — if you're at a min, the ground can't drop, so the right-slope is at least zero (). Nudge left — by the very same reasoning the ground can't drop that way either, but "not dropping to the left" means the slope read leftward is at most zero (). Here's the punchline: the ground has one slope (that's what "smooth / differentiable" guarantees), and the only number that is simultaneously "not below zero" and "not above zero" is exactly zero. So the ground is flat. In a full landscape you just repeat this nudge along every compass axis, and every one comes back flat — that bundle of flat slopes is what packs into a single arrow of zero length. The deepest way to see it: if the ground weren't flat, the gradient would be a real arrow shouting "downhill is that way," and you'd follow it to somewhere lower — so you couldn't have been at the bottom. The catch, drawn in the last figure: flat ground shows up at the top of a hill and in the middle of a horse-saddle too. Flat is a clue, not a verdict. To read the verdict you bend down and check the curvature — and that is the Hessian's job.


Connections

Concept Map

shrink step

poke right

poke left

squeeze

squeeze

one axis at a time

walk downhill

contradiction

only a finalist

judge

Slope = rise over run

Derivative f prime

f prime >= 0

f prime <= 0

f prime = 0 in 1D

grad f = 0

Directional derivative

f decreases if grad not 0

Bowl or Dome or Saddle

Hessian test