Every learning machine, from a two-line regression to a trillion-parameter transformer, spends its whole life asking one question over and over: which way is down? This unit builds the instrument that answers it — the derivative — from a single sliding secant line all the way up to the Jacobian matrices that make backpropagation work.
≈ 60 min read + play10 interactive widgets · 2 in 3D12 inline checks✍ 10 solved practice problems
1
You are standing in fog, and you want to get down
Here is the entire story of machine learning in one image, and it is worth spending a minute on because everything else in this unit is a tool for surviving it.
You are somewhere in a vast valley. The fog is so thick you can see nothing — not the horizon, not the bottom, not even your own boots. Your altitude is your model's error: how badly it is currently getting things wrong. Your position is the setting of every knob in your model — every weight, every bias. Moving one step in some direction means nudging those numbers a little.
You want to reach the lowest point in the valley. That is training.
You cannot see. But you can do one thing: feel the ground under your feet. You can sense which way it tilts and how steeply. That local tilt is all you get — and remarkably, it turns out to be enough.
Scenario
That feeling underfoot has a name. In one dimension it is the derivative. In many dimensions it is the gradient. Everything in this unit — limits, rules, Taylor, partials, Jacobians — exists to compute that tilt for functions of increasing complexity, and to keep the bookkeeping straight when "position" stops being a number and becomes a vector, a matrix, or a whole neural network's worth of parameters.
The foggy valleyDrag the hiker. You only ever learn the slope where you stand — is that enough?
—
Slide the fog away and the whole landscape appears — but a real model never gets that view. Its loss surface lives in millions of dimensions and can only ever be probed one point at a time. The slope at your feet is the entire information channel.
Pause & predict
You are at a point where the slope is +3. Which way do you step to reduce your altitude?
2
The derivative, built from a shrinking triangle
"Slope at a point" is a slightly strange idea when you first meet it. Slope is a ratio of two changes — rise over run — but at a single point nothing changes. So the definition sneaks up on it: take a second point a distance h away, measure the honest slope between the two, then let h shrink toward zero and see what number the answer approaches.
dxdf=h→0limhf(x+h)−f(x)
That fraction is the difference quotient: the slope of the straight line through two points on the curve, called a secant. As h shrinks the second point slides toward the first, the secant pivots, and in the limit it settles onto the tangent — the line that best imitates the curve right there.
The lecture states the payoff in one line: the derivative of f points in the direction of steepest ascent of f. In one dimension there are only two directions, so this amounts to a sign; in Section 6, when the input becomes a vector, that same sentence becomes a genuine compass needle.
Secant → tangentShrink h and watch a two-point slope become a one-point slope
—
Push h all the way to the left. The two points merge, the secant stops moving, and the number in the readout stops changing — that settled number is the derivative. Notice it never divides by zero: it only ever asks what the ratio approaches.
The lecture's proof that dxdxn=nxn−1 — every step
Put f(x)=xn into the definition and expand the binomial:
The i=0 term of the sum is exactly xn, so it cancels the −xn, leaving a sum that starts at i=1 — and every surviving term carries at least one factor of h, so the division by h is legal:
dxdf=h→0limi=1∑n(in)xn−ihi−1=i=1,no h left(1n)xn−1+h→0limevery term still has an h→0i=2∑n(in)xn−ihi−1=nxn−1
The whole trick is that exactly one term survives the shrinking: the one where the single factor of h in the numerator was consumed by the h in the denominator. Everything else still has an h attached and vanishes.
Pause & predict
In the widget, why does the readout for f(x)=x2 at x=1 approach exactly 2?
3
Four rules, and the only one that really matters
Nobody computes limits by hand for a living. Once a handful of basic derivatives are known, four rules let you differentiate anything built out of them:
Three of those are conveniences. The fourth — the chain rule — is the reason deep learning is possible at all, so it deserves a picture rather than a formula.
Think of f and g as two machines bolted together. x goes into the first, its output u=f(x) is fed straight into the second, and g(u) comes out the far end. Now nudge x by a tiny amount. The first machine amplifies that nudge by its own sensitivity f′(x). The second machine takes the already-amplified nudge and amplifies it again by g′(u). Two amplifiers in series multiply.
Intuition
Gears. If a small gear turns 3× for every turn of the crank, and a large gear turns 5× for every turn of the small one, the large gear turns 15× per crank. The chain rule is gear ratios — and a 50-layer network is just 50 gears in a row. This is also the whole reason deep networks are delicate: multiply 50 numbers that are each slightly less than 1 and the signal reaching the first layer is essentially zero. That is the vanishing gradient problem, and you have just seen its cause.
The chain rule machineA nudge enters on the left and gets amplified twice — watch the ratios multiply
—
Shrink the nudge and the measured amplification converges on the predicted product g′(f(x))⋅f′(x). The gap you see at large nudges is exactly the curvature the derivative ignores — Section 4 measures that gap precisely.
The lecture's worked example — h(x)=(2x+1)4
Name the two machines. Inner: f(x)=2x+1. Outer: g(u)=u4. Their separate derivatives are easy: f′(x)=2 and g′(u)=4u3.
The chain rule says evaluate the outer derivative at the inner value, then multiply by the inner derivative:
h′(x)=g′(f(x))⋅f′(x)=4(2x+1)3⋅2=8(2x+1)3
The classic slip is writing 4(2x+1)3 and stopping — forgetting to multiply by the inner derivative. The gear picture is the cure: you cannot report the final gear's speed without accounting for every gear it passed through.
Pause & predict
Using the chain rule, what is dxdsin(x2)?
4
Taylor — rebuilding a whole function out of its derivatives
The derivative is the best straight line imitation of a curve at a point. A natural greed sets in: if one derivative buys a line, what does a second derivative buy? A parabola. A third? A cubic. Keep going and you get the Taylor polynomial:
Tn(x)=k=0∑nk!f(k)(x0)(x−x0)k
Read it as a recipe rather than a formula. Term k does one job: it matches the k-th derivative of f at the anchor point x0, without disturbing any of the lower ones. The k! is the bookkeeping that makes that possible — differentiating (x−x0)k exactly k times produces k!, and dividing by it cancels the mess.
Let n run to infinity and you get the Taylor series; anchor it at x0=0 and it earns the name Maclaurin series. This is not a side-quest: it is why your computer can evaluate sin, exp and log at all, and in Unit 8 the second-order term becomes the whole basis of Newton-style optimisation.
The Taylor builderAdd one derivative at a time and watch the imitation tighten
—
Two things to hunt for. First, on x⁴ the approximation stops improving at degree 4 — it has become exact, and every higher derivative is zero. Second, on ln(1+x) the fit is excellent near the anchor and then falls off a cliff past x=1: Taylor series are local promises, not global ones.
The lecture's two examples, worked in full
Example 1 — a polynomial is reproduced exactly. Take f(x)=x4 and anchor at x0=1. The derivatives at 1 are
Expanding really does collapse back to x4 — a Taylor polynomial of degree n reproduces any polynomial of degree k≤n exactly, because all higher derivatives are identically zero. The approximation has nothing left to approximate.
Careful with the lecture's line here. The slide writes the coefficients as 1+4(x−1)+12(x−1)2+24(x−1)3+24(x−1)4, which is the list of derivativesf(k)(1) — the division by k! hasn't been carried out yet. With the k! applied (12/2!=6, 24/3!=4, 24/4!=1) you get the line above, and only that version expands back to x4. Worth checking yourself: expand both and see which one is really x4.
Example 2 — a Maclaurin series that folds into two famous ones. For f(x)=sinx+cosx at x0=0, the derivatives cycle with period 4: f(0)=1,f′(0)=1,f′′(0)=−1,f′′′(0)=−1, then repeat. So
T∞(x)=1+x−2!1x2−3!1x3+4!1x4+5!1x5−⋯
Sort the terms by parity and the two halves are recognisable on sight:
The series reassembles the function it came from — a satisfying closed loop, and a good sanity check on the machinery.
Pause & predict
In the widget, switch to x4 and raise the degree past 4. Why does nothing change?
Pause & predict
The sigmoid σ(z)=1+e−z1 has Maclaurin expansion 21+4z−48z3+⋯. What does the missing z2 term tell you?
5
Many knobs at once — partial derivatives
Real models do not have one knob. They have millions. So we need the derivative of a function whose input is a whole vector, f:Rn→R — many numbers in, one score out.
The generalisation is almost insultingly simple: vary one variable at a time and hold every other one still. That is a partial derivative, written with a curly ∂ instead of a straight d as a reminder that other variables exist and are being deliberately frozen:
Notice that only the first slot changes. Every other argument sits untouched on both sides of the subtraction. In practice this means something very concrete: when differentiating with respect to x, treat y as if it were the number 7. All your one-variable rules come along unchanged.
Geometrically you are slicing. The surface z=f(x,y) is a landscape; freezing y cuts a vertical slice through it, and that slice is an ordinary one-variable curve with an ordinary slope. The partial derivative is the slope of that slice.
The slicerFreeze one variable, cut the surface, read the slope of the slice — drag to orbit
—
The surface is f(x,y)=x2−y2+21xy — a saddle, which is the interesting case: at the centre one slice curves up while the other curves down. Drag to orbit and look along each slice edge-on; the tangent line you see is exactly what the partial derivative reports.
The lecture's two examples — and the chain rule hiding inside them
Example 1:f(x,y)=(x+2y3)2. This is a composition, so the chain rule applies inside each partial. Outer: square. Inner: x+2y3.
Same outer derivative both times; the two answers differ only in the inner derivative — the fingerprint of the chain rule.
Example 2:f(x1,x2)=x12x2+x1x23. No composition, just the freeze-the-other rule applied term by term. Treating x2 as a constant, x12x2 differentiates to 2x1x2 and x1x23 to x23:
∂x1∂f=2x1x2+x23,∂x2∂f=x12+3x1x22
Collecting both into one row gives the gradient of the next section:
dxdf=[2x1x2+x23,x12+3x1x22]∈R1×2
Pause & predict
For f(x,y)=x2y+3xy2−y3, what is ∂x∂f?
6
The gradient — a compass that always points uphill
One partial derivative answers "how does the output respond to this knob?". Collect them all and something more than a list appears:
∇xf=gradf=dxdf=[∂x1∂f,∂x2∂f,…,∂xn∂f]
The gradient is a vector, and it has two properties that make it the most important object in this entire course.
Its direction is steepest ascent. Of all the directions you could step, the gradient points the one that increases f fastest. Not merely uphill — maximally uphill. Its length is the steepness in that best direction: a long gradient means a cliff, a near-zero gradient means flat ground, which is either a summit, a valley floor, or a saddle.
That is why the fog of Section 1 turns out to be survivable. You cannot see the valley, but you can compute one vector, and it tells you both the best direction and how urgent the situation is. Flip its sign and you have the single most-run line of code in machine learning:
wnew=wold−η∇L(w)
The aha
Why does the gradient point steepest ascent, rather than merely uphill? Because the rate of change in some unit direction u is the dot product ∇f⋅u — and Unit 3 already told you that a dot product with a fixed vector is maximised when u aligns with it. The compass property is Cauchy–Schwarz wearing a hat. Two units ago you proved this; today you get to use it.
The gradient compassDrag anywhere on the map. Red points uphill, green is the direction training would take
—
Watch the arrow against the contour lines: it always crosses them at a right angle. Contours are curves of constant height, so moving along one changes nothing — all the change is packed into the perpendicular direction, and that is where the gradient points. On the stretched valley, notice the arrow mostly ignores the long flat axis; that mismatch is what momentum and Adam exist to fix.
Pause & predict
At some point the gradient of a loss is ∇L=[0,0]. What can you conclude?
7
The five shapes a derivative can take
Here is where most people's intuition quietly breaks, and where a small amount of organisation pays off enormously. "The derivative" is not one kind of object. Its shape is decided entirely by two questions: what shape goes in, and what shape comes out.
The rule underneath every case is the same. The derivative must hold one number for every (output component, input component) pair — because each of those pairs needs its own sensitivity. Count the pairs and you know the shape. That single sentence generates all five rows below, so you never have to memorise them.
The shape calculatorPick what goes in and what comes out — the derivative's shape follows
input
output
—
Input
Output
Derivative is a…
Shape
Where you meet it
scalar
scalar
scalar
1
a single learning-rate schedule
vector Rn
scalar
gradient
n
loss w.r.t. weights — the big one
matrix Rm×n
scalar
gradient matrix
m×n
loss w.r.t. a CNN kernel
vector Rn
vector Rm
Jacobian
m×n
one layer of a network
matrix
matrix
rank-4 tensor
p×q×m×n
lurking inside every autodiff library
Remember
The two rows in bold carry almost all of practical machine learning. Gradient: the loss is a single number and the weights are a vector, so the derivative is a vector the same shape as the weights — which is exactly why you can subtract it from them. Jacobian: a layer maps a vector to a vector, so its derivative is a matrix, and stacking layers means multiplying those matrices. That is backpropagation in one sentence, and Section 10 makes it explicit.
Pause & predict
A network layer maps R100→R50. What shape is its derivative?
8
The Jacobian — a local rulebook for a curved map
Now let both ends be vectors: f:Rn→Rm. This is the shape of a neural-network layer, of a coordinate change, of any transformation that takes a bundle of numbers and returns another bundle.
Each output component fi is itself a scalar-valued function of all n inputs, so each has a gradient — a row of n partials. Stack the m rows and you have the Jacobian:
Read it twice, in two directions. Row i is the gradient of output i — how that one output feels every input. Column j is ∂f/∂xj — how the entire output vector twitches when input j alone is nudged.
And here is the meaning that makes it worth the notation. A curved map, zoomed in far enough, is linear. The Jacobian is that linear map: the matrix that best imitates your complicated function in a small neighbourhood. Stretching, rotating, shearing — whatever the function does locally, J does exactly.
Intuition
A video game. Your joystick position is the input vector; your character's velocity is the output vector; the game's physics engine is f. The Jacobian is the rulebook at this instant: nudge the stick slightly forward and it tells you the exact resulting change in velocity — "+5 forward, +1 right". Move to a different game state and the rulebook changes, which is precisely what it means for J to depend on x.
Zoom until it's linearA curved map bends the whole grid — but shrink the window and it becomes a plain matrix
—
Drag window to the left. The warped patch on the right straightens into a parallelogram — the one the Jacobian matrix draws. That convergence is differentiability: a function is differentiable exactly when zooming in makes it look linear.
The lecture's example — the derivative of a linear map is the map itself
Take f(x)=Ax with A∈RM×N. Component i is the plain sum fi(x)=∑j=1NAijxj. Differentiate it with respect to one particular xj: every term of that sum is a constant except the j-th, which contributes its coefficient. So
∂xj∂fi=Aij⟹dxdf=A11⋮AM1⋯⋯A1N⋮AMN=A
The Jacobian of a linear map is that map's own matrix — the exact analogue of dxd(ax)=a. It also explains why the "linear layer" of a network is the easy case in backpropagation: its local rulebook never changes, no matter where you evaluate it.
Pause & predict
For f(x,y)=(x2−y2,xey,ln(1+x2+y2)), what is J at (1,0)?
9
What the Jacobian determinant knows — area, invertibility, and one honest warning
When the Jacobian is square, Unit 4's volume dial comes back to work. detJ at a point is the factor by which the map stretches area (or volume) right there. Feed in a tiny square of area ε; out comes a tiny parallelogram of area ∣detJ∣ε. A negative determinant means the map also flipped orientation, turning the neighbourhood inside out like a mirror.
This buys a genuine theorem. The inverse function theorem says that wherever detJ=0, the map is locally invertible: near that point, distinct inputs give distinct outputs and you can run the map backwards. Where detJ=0, a whole direction has been crushed flat and information is destroyed — you cannot undo it.
And now the warning, because this is a place careful people still trip. Locally invertible everywhere does not mean globally one-to-one.
Watch out
Take the exponential map T(x,y)=(excosy,exsiny) — the third preset in the widget above. Its Jacobian determinant works out to detJ=e2x, which is strictly positive for every real x. So T is locally invertible at every single point of the plane, with no exceptions.
Yet T(x,y)=T(x,y+2π), because sine and cosine repeat. Infinitely many different inputs land on exactly the same output. Every local statement can be true while the global one fails — the map wraps the plane around the origin over and over, like a spiral staircase whose steps all sit above one another.
Set the widget to the exponential preset and slide y through more than 2π: the patch on the right returns to where it started while the input point keeps travelling. That is the failure, made visible.
Pause & predict
A map R2→R2 has detJ=0 along a whole curve. What happens there?
10
The chain rule becomes matrix multiplication — and that is backpropagation
Everything so far converges here. In Section 3 the chain rule multiplied two numbers. With vectors it multiplies two matrices, and the order matters because matrix multiplication does not commute:
xFyGz⟹dxdz=dydz⋅dxdy=JGJF
This is not element-wise multiplication. It is honest matrix multiplication, and the shapes police themselves: if F:Rn→Rp and G:Rp→Rm, then JG is m×p, JF is p×n, and the product is m×n — exactly the shape the composed map demands. When your dimensions line up, you have almost certainly written it in the right order.
A network is a long composition: input → layer → layer → … → one loss number. Applying the rule end to end gives a product of Jacobians. Because the final loss is a single scalar, its derivative is a row, and multiplying that row through the chain from the left keeps every intermediate a row rather than a full matrix. That choice — right to left instead of left to right — is the entire efficiency trick of backpropagation, and it is why training a network costs about the same as two forward passes rather than one pass per parameter.
Backprop, one Jacobian at a timePush numbers forward, then send the gradient back through the same layers
—
Step through and watch the shapes: the backward pass starts as a 1×2 row and stays a row the whole way, because each multiplication is (row)·(matrix). Nothing bigger than a row is ever built — that is the saving.
The lecture's composite example — h(t)=f(g(t)) with a vector in the middle
Let f(x)=exp(x1x22) with x=g(t)=(tcost,tsint). Here g:R→R2 and f:R2→R, so the shapes are ∂x∂f∈R1×2 and ∂t∂x∈R2×1 — their product is 1×1, a single number, as it must be.
That sum of products is the row-times-column multiplication written out longhand. Every "sum over paths" you meet in calculus is a matrix product waiting to be recognised.
Pause & predict
Layers F:R4→R3 then G:R3→R2. Which product is the Jacobian of G∘F?
11
Walking down the valley
You now have everything needed to make the fog survivable. Compute the gradient, step against it, repeat:
w←w−η∇L(w)
The gradient chooses the direction. The learning rateη chooses how far to trust it — and that is the whole difficulty, because the gradient is only honest infinitesimally close to where it was measured. Step a little and the promise holds. Step too far and you overshoot the valley floor and land higher up the opposite wall, where the new gradient points back, and you oscillate outwards forever.
Learning rate rouletteSame landscape, same start, one number changed
—
Drag the start point too. Three regimes live in this one slider: too small and you crawl, about right and you glide in, too large and the path explodes outward. The valley here is stretched 8:1 — notice that even a well-tuned run zig-zags across the narrow direction instead of running straight down the long one. Unit 11 is devoted to fixing exactly that.
Pause & predict
Training loss oscillates and grows instead of settling. Reaching for one knob first, which is it?
12
Fine print worth knowing
Row or column? The layout convention. Is a gradient a row vector or a column? Both conventions are in use. This unit follows the lecture and writes gradients as rows(∇f∈R1×n), which makes the Jacobian chain rule read left to right without transposes. Many textbooks and most code write gradients as columns. Neither is wrong; mixing them silently is. When a formula from elsewhere seems transposed, suspect the convention before suspecting the algebra.
Order matters now. With scalars, f′g=gf′. With matrices it does not. The lecture flags this explicitly for the product and chain rules — once your derivatives are matrices, you must preserve the order in which the factors appear.
Not everything is differentiable.∣x∣ has no derivative at 0: the slope from the left is −1, from the right +1, and no single number splits the difference. ReLU has exactly this kink, and every framework simply picks a value there and moves on. It works fine in practice, but it is a convention rather than a theorem.
The tensor nobody builds. Matrix in, matrix out gives a rank-4 tensor — for a modest 100×100 layer that is 108 numbers for a single derivative. PyTorch and TensorFlow never materialise it. Instead each operation ships a backward() that maps an incoming gradient straight to an outgoing one, applying the tensor's action without ever storing the tensor. The mathematics is the honest description; the implementation is the same map, evaluated lazily.
Errata — check this against your slides
On the Taylor-polynomial example (f(x)=x4 at x0=1), the lecture slide lists the polynomial as 1+4(x−1)+12(x−1)2+24(x−1)3+24(x−1)4. Those are the raw derivatives f(k)(1) — the division by k! hasn't been applied. Expanding that expression gives 24x4−72x3+84x2−44x+9, which is not x4; at x=2 it returns 65 instead of 16.
With the factorials divided out — 12/2!=6, 24/3!=4, 24/4!=1 — the polynomial becomes 1+4(x−1)+6(x−1)2+4(x−1)3+(x−1)4, whose coefficients are the binomial numbers 1,4,6,4,1. That really does collapse to ((x−1)+1)4=x4, which is the point the slide is making.
13
What to carry forward
One idea generated this entire unit: nudge the input a little, see how much the output moves, and take the ratio as the nudge shrinks to nothing. Everything else was bookkeeping for richer shapes.
Idea
The one-line version
Where it returns
Derivative
Limit of a shrinking secant slope; points along steepest ascent
everywhere below
Chain rule
Amplifiers in series multiply
Unit 7 · backpropagation
Taylor
Match derivatives one at a time; k! keeps the books
Unit 8 · approximation & error
Partial derivative
Freeze every other variable and use ordinary rules
every gradient you ever compute
Gradient
All partials in one vector; direction = steepest ascent, length = steepness
Unit 9 · gradient descent
Jacobian
One row per output; the best local linear map
Unit 7 · layers; Unit 12 · PCA
detJ
Local area factor; nonzero ⇒ locally invertible only
change of variables, normalising flows
Vector chain rule
Matrix multiplication, later layer on the left
Unit 7 · the training loop
Remember
If you keep one habit from this unit, make it counting shapes before computing anything. Outputs give rows, inputs give columns; a gradient matches the shape of the thing you are differentiating with respect to; a chain rule product must have matching inner dimensions. Most matrix-calculus errors are shape errors wearing a disguise, and they announce themselves before you do any algebra.
14
Practice arena — the unit's problem set, solved in full
Eight problems from Prof. Saurabh's practice set for this unit, plus two extra written to cover the two corners the set leaves open — Taylor polynomials, and the vector chain rule as matrix multiplication. Every solution below was checked symbolically before publication; the set itself came through clean, with no errata.
One rule does almost all the work: to compute ∂f/∂x, treat every other variable as a constant. The gradient collects those partials into a row; the Jacobian stacks the gradients of each output component as rows. Attempt each problem on paper first — the fold-outs give every step, entry by entry.
Problem 1easy
Let f(x,y)=x2y+3xy2−y3. (a) Compute ∂f/∂x and ∂f/∂y and write ∇f as a row vector. (b) Evaluate ∇f at (2,−1). (c) Verify ∂f/∂x at (2,−1) directly from the limit definition.
What this tests. The freeze-the-others rule, and the fact that the rules you use are not a separate system from the limit definition — they are shortcuts for it.
Show the full solution
(a) Step 1 — ∂f/∂x, holding y fixed. Take the three terms one at a time, treating y as a number:
∂x∂(x2y)=y⋅2x=2xy,∂x∂(3xy2)=3y2,∂x∂(−y3)=0
The last term dies completely because it contains no x. Adding: ∂f/∂x=2xy+3y2.
Step 2 — ∂f/∂y, holding x fixed.∂y∂(x2y)=x2,∂y∂(3xy2)=3x⋅2y=6xy,∂y∂(−y3)=−3y2
Adding: ∂f/∂y=x2+6xy−3y2.
(c) Step 1 — collapse to one variable. Fix y=−1: f(x,−1)=x2(−1)+3x(1)−(−1)=−x2+3x+1.
Step 2 — form f(2+h,−1).−(2+h)2+3(2+h)+1=−(4+4h+h2)+6+3h+1=3−h−h2
and f(2,−1)=−4+6+1=3.
Step 3 — difference quotient and limit.h(3−h−h2)−3=h−h−h2=−1−hh→0−1
matching part (b) exactly.
∇f=[2xy+3y2,x2+6xy−3y2], and ∇f(2,−1)=[−1,−11].
Remember
Notice the cancellation in step 3: the h in the denominator is consumed before the limit is taken. That is the whole reason the definition never divides by zero.
Problem 2medium
Let f(x,y)=x+2yx2y with x+2y=0. Without using the quotient rule — rewrite it as f=x2y(x+2y)−1 and use the product rule together with dtdt−1=−t−2. (a) Compute ∂f/∂x. (b) Compute ∂f/∂y. (c) Write ∇f and evaluate at (1,1).
What this tests. Product plus chain rule in combination, and the discipline of putting a fractional answer over a common denominator so it can be checked.
Show the full solution
(a) Step 1 — name the factors and their x-derivatives. With y held fixed, write f=g⋅w where
g=x2y⇒gx=2xy,w=(x+2y)−1⇒wx=−(x+2y)−2⋅∂(x+2y)/∂x1
Step 3 — common denominator (x+2y)2.∂x∂f=(x+2y)22xy(x+2y)−x2y=(x+2y)22x2y+4xy2−x2y=(x+2y)2x2y+4xy2=(x+2y)2xy(x+4y)
(b) Step 1 — now hold x fixed.gy=x2, and wy=−(x+2y)−2⋅2=−2(x+2y)−2 (the inner derivative is now 2, not 1 — this is where the two parts differ).
Step 2 — product rule, then combine.∂y∂f=x+2yx2−(x+2y)22x2y=(x+2y)2x2(x+2y)−2x2y=(x+2y)2x3+2x2y−2x2y=(x+2y)2x3
The 2x2y terms cancel exactly — a good sign the algebra is right.
(c) Evaluate at (1,1), where x+2y=3 so (x+2y)2=9:
∇f=[(x+2y)2xy(x+4y),(x+2y)2x3],∇f(1,1)=[91⋅1⋅5,91]=[95,91]
Independent check of ∂f/∂y(1,1) from the definition. Fix x=1: f(1,y)=1+2yy, so f(1,1)=31 and
h1(3+2h1+h−31)=3h(3+2h)3(1+h)−(3+2h)=3h(3+2h)h=3(3+2h)1h→091✓
∇f=[(x+2y)2xy(x+4y),(x+2y)2x3], and ∇f(1,1)=[95,91].
Watch out
The two parts share the same product-rule skeleton and differ only in one number — the inner derivative of x+2y, which is 1 for x and 2 for y. Dropping that 2 is the most common slip here.
Problem 3easy
Let f(x,y,z)=x2ey+ycosz. (a) Compute the three partials. (b) Write ∇f and evaluate at (1,0,0).
What this tests. Three variables instead of two, with exponential and trigonometric pieces — and the habit of noticing which whole terms vanish.
Show the full solution
Step 1 — ∂f/∂x. Here ey is a constant multiplier and ycosz contains no x at all, so it dies:
∂x∂f=ey⋅2x+0=2xey
Step 2 — ∂f/∂y. Now x2 and cosz are constants; use dydey=ey on the first term and dydy=1 on the second:
∂y∂f=x2ey+cosz
Step 3 — ∂f/∂z. The first term has no z; in the second, y is a constant multiplier on cosz:
∂z∂f=0+y(−sinz)=−ysinz
Evaluate at (1,0,0), using e0=1, cos0=1, sin0=0:
∇f=[2xey,x2ey+cosz,−ysinz],∇f(1,0,0)=[2,1+1,0]=[2,2,0]
∇f=[2xey,x2ey+cosz,−ysinz], and ∇f(1,0,0)=[2,2,0].
Aha
The third component is zero not because z is irrelevant to f, but because y=0 at this particular point switches off the only term containing z. Move to y=0 and z matters again — gradients are local statements.
Problem 4medium
(a) For f(x,y,z)=ln(x2+y2+z2), compute ∇f and evaluate at (1,2,2). (b) For g(x)=∥x∥=x2+y2+z2, compute ∇g and evaluate at (1,2,2). (c) What is special about the direction and length of ∇g at any nonzero point?
What this tests. The chain rule on radially symmetric functions, and a geometric fact used constantly in ML: the gradient of the norm is the unit radial direction.
Show the full solution
(a) Step 1 — set the inner function. Let u=x2+y2+z2, so f=lnu and ∂x∂lnu=u1∂x∂u. The inner partials are ux=2x,uy=2y,uz=2z.
Step 2 — apply the chain rule to each variable.∂x∂f=x2+y2+z22x,∂y∂f=u2y,∂z∂f=u2z
Step 3 — assemble and evaluate.∇f=x2+y2+z22[x,y,z]. At (1,2,2), u=1+4+4=9, so
∇f(1,2,2)=92[1,2,2]=[92,94,94]
(b) Step 1 — same inner function, outer is a square root.g=u1/2, and ∂x∂u1/2=21u−1/2⋅2x=ux, similarly for y and z.
Step 2 — assemble and evaluate.∇g=u1[x,y,z]=∥x∥x⊤. At (1,2,2), u=3:
∇g(1,2,2)=31[1,2,2]=[31,32,32]
(c)∇g=x/∥x∥ is the unit vector pointing radially outward. Its length is 1 everywhere:
91+94+94=99=1
So distance-from-the-origin grows fastest straight away from the origin, at unit rate — exactly what you would expect, now derived rather than assumed.
∇f(1,2,2)=92[1,2,2]; ∇g=x⊤/∥x∥ with ∇g(1,2,2)=31[1,2,2], a unit vector.
Aha
Both gradients point along [1,2,2] — the same direction, different lengths. Any radially symmetric function has a gradient along the radius; only the magnitude carries information about which function it was.
Problem 5easy
Let f(x,y)=(2x2−y)3. (a) Compute ∂f/∂x and ∂f/∂y. (b) Write ∇f and evaluate at (1,1).
What this tests. The chain rule in its purest multivariable form: one outer power, two different inner derivatives.
Show the full solution
Step 1 — spot the structure. The function is (inner)3 with inner=2x2−y, so ∂∙∂(inner)3=3(inner)2⋅∂∙∂(inner).
Step 2 — ∂f/∂x. Hold y fixed; the inner derivative is 4x:
∂x∂f=3(2x2−y)2⋅4x=12x(2x2−y)2
Step 3 — ∂f/∂y. Hold x fixed; the inner derivative is −1:
∂y∂f=3(2x2−y)2⋅(−1)=−3(2x2−y)2
(b) Evaluate at (1,1), where the inner is 2(1)2−1=1 so (2x2−y)2=1:
∇f(1,1)=[12(1)(1),−3(1)]=[12,−3]
∇f=[12x(2x2−y)2,−3(2x2−y)2], and ∇f(1,1)=[12,−3].
Aha
Factor out the shared piece and the structure appears: ∇f=3(2x2−y)2[4x,−1]=3(inner)2∇(inner). The chain rule in vector form — outer derivative times the gradient of the inner. No cube ever has to be expanded.
Problem 6medium
Consider f:R2→R3, f(x,y)=(x2−y2,xey,ln(1+x2+y2)). (a) Compute the Jacobian and state its dimensions. (b) Evaluate at (1,0). (c) Say in words what the rows and columns represent.
What this tests. Assembling a non-square Jacobian, and reading it in both directions — per output and per input.
Show the full solution
Step 1 — fix the shape before differentiating. Three outputs, two inputs, and Jij=∂fi/∂xj, so the answer is 3×2. Six partials to compute.
(b) Substitute x=1,y=0, so e0=1 and 1+x2+y2=2:
Jf(1,0)=212/2010/2=211010
(c)Row i is the gradient ∇fi — a 1×2 row saying how output i responds to each input. Column j is ∂f/∂xj — how the whole output vector moves when input j alone changes. Here column 1 is ∂f/∂x and column 2 is ∂f/∂y.
J∈R3×2 as above, with J(1,0)=211010.
Remember
Building the matrix as a stack of gradients — compute ∇f1,∇f2,∇f3 separately, then stack — gives the same answer and is much harder to get wrong than filling in six entries by position.
Problem 7hard
Consider T:R2→R2, T(x,y)=(excosy,exsiny). (a) Compute JT. (b) Evaluate detJT. (c) Where is T not locally invertible? Is T globally one-to-one?
What this tests. The determinant as a local area factor, the inverse function theorem, and the gap between local and global statements.
Show the full solution
(a) Step 1 — partials of u=excosy. With respect to x, cosy is a constant: ux=excosy. With respect to y, ex is a constant: uy=−exsiny.
Step 2 — partials of v=exsiny.vx=exsiny, vy=excosy.
(b) Determinant via ad−bc:
detJT=(excosy)(excosy)−(−exsiny)(exsiny)=e2x(cos2y+sin2y)=e2x
(c) Step 1 — local invertibility. The inverse function theorem guarantees local invertibility wherever detJ=0. Since e2x>0 for every real x, the determinant is never zero: T is locally invertible everywhere.
Step 2 — global injectivity fails anyway. Because cos and sin have period 2π,
T(x,y+2π)=(excos(y+2π),exsin(y+2π))=(excosy,exsiny)=T(x,y)
Infinitely many distinct inputs share an output, so T is not globally one-to-one. "Locally invertible everywhere" and "globally invertible" are genuinely different claims.
JT=[excosyexsiny−exsinyexcosy], detJT=e2x>0 always — locally invertible everywhere, but not globally one-to-one.
Aha
Write z=x+iy and the map is simply w=ez. For a holomorphic map the real Jacobian determinant equals ∣dw/dz∣2=∣ez∣2=e2x — the same answer, arrived at with no partial derivatives at all.
Problem 8hard
Three identities are worth memorising: ∇(b⊤x)=b⊤, ∇(x⊤x)=2x⊤, ∇(x⊤Ax)=x⊤(A+A⊤). Let f(x)=x⊤Ax−b⊤x with A=[1023] (not symmetric) and b=[11]. (a) Write f in components. (b) Apply the identities to get ∇f — why does A+A⊤ appear rather than 2A? (c) Evaluate at (1,1).
What this tests. Matrix-calculus identities, and the specific trap of assuming symmetry when none was given.
(b) Step 1 — form A+A⊤.A⊤=[1203], so A+A⊤=[2226].
Step 2 — apply the identities.∇f=x⊤(A+A⊤)−b⊤=[x1,x2][2226]−[1,1]=[2x1+2x2−1,2x1+6x2−1]
Step 3 — why A+A⊤? Write x⊤Ax=∑i,jAijxixj and differentiate with respect to xk. The variable xk appears twice in that double sum: once as the i=k factor (contributing ∑jAkjxj) and once as the j=k factor (contributing ∑iAikxi). Adding the two contributions gives the k-th entry of x⊤(A+A⊤). Only when A is symmetric does A+A⊤ collapse to 2A.
Had you used 2A instead, you would get ∇f(1,1)=[1,9] — visibly different, so this is a trap with teeth. The safest check is part (a): differentiate the component form directly, ∂f/∂x1=2x1+2x2−1, and confirm. Expanding the cross term 2x1x2 by hand automatically produces the symmetric off-diagonal 2s.
Problem 9mediumadded — covers Taylor
The practice set above never touches Taylor polynomials, so here they are. (a) Find the degree-4 Maclaurin polynomial of ln(1+x) and use it to estimate ln1.5. (b) The sigmoid is σ(z)=1+e−z1, with the useful identity σ′=σ(1−σ). Find its degree-3 Maclaurin polynomial. (c) What does the result in (b) say about logistic regression near z=0?
What this tests. Building a Taylor polynomial from repeated differentiation, keeping the k! straight, and reading a vanishing coefficient as a statement about shape.
Show the full solution
(a) Step 1 — differentiate repeatedly at x0=0. With f=ln(1+x):
f′=1+x1,f′′=(1+x)2−1,f′′′=(1+x)32,f(4)=(1+x)4−6
At x=0: f(0)=0,f′(0)=1,f′′(0)=−1,f′′′(0)=2,f(4)(0)=−6.
Step 2 — divide each by k!. The coefficients are 1/1!=1, −1/2!=−21, 2/3!=31, −6/4!=−41:
T4(x)=x−2x2+3x3−4x4
The pattern ∑(−1)k+1xk/k is worth recognising on sight.
Step 3 — estimate ln1.5 by setting x=0.5.T4(0.5)=21−81+241−641=19277≈0.401042
The true value is ln1.5≈0.405465, so the error is about 0.0044 — roughly the size of the first omitted term, x5/5=1/160≈0.00625, as Taylor's remainder predicts.
(b) Step 1 — use the identity to avoid quotient-rule misery. From σ′=σ(1−σ), differentiate again with the product rule:
σ′′=σ′(1−σ)+σ(−σ′)=σ′(1−2σ)σ′′′=σ′′(1−2σ)+σ′(−2σ′)=σ′′(1−2σ)−2(σ′)2
Step 2 — evaluate at z=0, where σ(0)=21:
σ′(0)=21⋅21=41,σ′′(0)=41⋅=0(1−2⋅21)=0,σ′′′(0)=0−2(41)2=−81
Step 3 — divide by k! and assemble. Coefficients: 21, 41, 0/2!=0, −81/3!=−481:
T3(z)=21+4z−48z3
(c) The quadratic term is exactly zero, so near z=0 the sigmoid is 21+4z up to a cubic correction — it is locally a straight line with slope 41. That is why a logistic model behaves almost linearly for small activations, why 41 is the largest gradient the sigmoid can ever pass backwards (the source of vanishing gradients in deep sigmoid networks), and why keeping activations near zero — through normalisation — keeps a network in its responsive band.
(a) T4(x)=x−2x2+3x3−4x4, giving ln1.5≈19277≈0.4010. (b) T3(z)=21+4z−48z3. (c) The sigmoid is locally linear at the origin, with maximum slope 41.
Aha
The missing z2 is not an accident of arithmetic — it is symmetry. The sigmoid has rotational symmetry about the point (0,21), and odd symmetry kills every even-order term beyond the constant.
Problem 10hardadded — covers the vector chain rule
The set above computes Jacobians but never multiplies them, so here is the backpropagation step itself. (a) Let g(x)=(x12x2,x1+x22) and f(u)=u1u2. Compute ∇(f∘g) as a product of Jacobians, and verify by substituting first. Evaluate at (1,2). (b) A linear layer computes z=Wx and the loss is L=21∥z−y∥2. Show ∂x∂L=(z−y)⊤W, then evaluate for W=[21−13], y=[12], x=[11].
What this tests. That the vector chain rule really is matrix multiplication, that the shapes police the order, and the exact gradient a linear layer sends backwards.
Show the full solution
(a) Step 1 — the two Jacobians, with shapes first.g:R2→R2 gives a 2×2; f:R2→R gives a 1×2. The product must be (1×2)(2×2)=1×2 — a gradient, as expected.
Jg=[2x1x21x122x2],Jf=[u2,u1]=[x1+x22,x12x2]
Note Jf must be evaluated atu=g(x) — that substitution is the step people forget.
Step 2 — multiply, later stage on the left.∇(f∘g)=JfJg=[x1+x22,x12x2][2x1x21x122x2]
First entry: (x1+x22)(2x1x2)+(x12x2)(1)=3x12x2+2x1x23.
Second entry: (x1+x22)(x12)+(x12x2)(2x2)=x13+3x12x22.
Step 3 — verify by composing first.f(g(x))=(x12x2)(x1+x22)=x13x2+x12x23. Differentiating directly:
∂x1∂=3x12x2+2x1x23,∂x2∂=x13+3x12x22
Identical to step 2 — the matrix product was not a shortcut with a catch, it is the same derivative.
Step 4 — evaluate at (1,2).3(1)(2)+2(1)(8)=6+16=22; 1+3(1)(4)=13. So ∇(f∘g)(1,2)=[22,13].
(b) Step 1 — split into two stages and take each Jacobian. Write r=z−y and L=21r⊤r. Then
∂z∂L=r⊤=(z−y)⊤(1×n),∂x∂z=W(n×n)
using ∇(r⊤r)=2r⊤ from Problem 8 (the 21 is chosen precisely to cancel that 2), and the fact that the Jacobian of a linear map is the map's own matrix.
Step 2 — chain them, later stage on the left.∂x∂L=∂z∂L⋅∂x∂z=(z−y)⊤W
Shapes: (1×n)(n×n)=1×n ✓. This is the backward pass of a linear layer: the incoming gradient row gets multiplied by W on its way back.
Step 3 — forward pass with the numbers.z=Wx=[21−13][11]=[14],z−y=[14]−[12]=[02]
so L=21(02+22)=2.
(a) ∇(f∘g)=[3x12x2+2x1x23,x13+3x12x22], equal to [22,13] at (1,2). (b) ∂x∂L=(z−y)⊤W=[2,6], with L=2.
Remember
In part (b) the first output was already perfect (z1−y1=0) yet ∂L/∂x1=2 is not zero. The error in output 2 still reaches input 1, because W couples them. Gradients flow along every path the weights create — which is exactly what makes a network trainable and its behaviour hard to reason about locally.
Next up
Unit 7 · Backpropagation & Automatic Differentiation— coming soon
You now hold every piece: the chain rule, Jacobians, and the insight that composing layers means multiplying matrices. Unit 7 turns that into an algorithm — how a network computes a million derivatives for roughly the price of two forward passes, and why it must run backwards to do it.