Search

Search papers and lessons

Partial Derivative

Level 2 · 10 min read

A partial derivative is the rate of change of a multivariable function along one input axis, with every other input held fixed.

On this page

  • Colour = topic mix
  • Calculus
  • Sign in to see your progress

TL;DR

A function of several inputs has one slope for each input. The partial derivative with respect to one input is the slope you see when you move only that input and freeze all the others. You write it ∂f∂x\frac{\partial f}{\partial x}, with a curly ∂\partial in place of the plain dd of an ordinary derivative.

Stacking all the partial derivatives into a list gives the Gradient, which points in the direction the function grows fastest.

Where you'll see it: in the gradient descent step that trains a neural network, in the normal equations of linear regression, and in the rule for how a change in one input ripples through a computation.

Intuition

A hill with two directions

Stand on a hillside. The ground rises to the north and falls to the east. If you walk due north, the slope under your feet is one number. If you walk due east, it is a different number. Neither number alone describes the hill, but together they say how steep it is in every direction.

A function of two variables, f(x,y)f(x, y), is exactly a hill: xx and yy are your position on the map, and ff is the height. The partial derivative with respect to xx answers "how steep is it if I move east while my north-south position stays put?" The partial derivative with respect to yy answers the same question for moving north.

The reason we need the idea is that most real quantities depend on many things at once. A bill depends on the price of each item. A loss depends on every weight in a model. To learn how one of those things affects the result, we have to isolate it. Freezing everything else is how we do that, and it turns a many-input problem into a sequence of one-input problems we already know how to solve with the ordinary Derivative.

−2−1.5−1−0.500.511.52012345xf(x, y)
  • y = 0
  • y = 1
  • y = 2
Freezing y at 0, 1 and 2 cuts three slices through f(x, y) = x² + y². The partial derivative with respect to x is the slope of one of these curves. At x = 1 on the y = 0 slice, the slope is 2.

Freeze, then differentiate

The recipe is always the same. Pick the input you care about. Treat every other input as a constant. Differentiate the resulting one-variable expression as usual. The answer is a new function that still depends on the remaining inputs.

That last point matters. The partial derivative is not a single number in general. It is a function, evaluated at a point where all the inputs are known.

The math

Definition

Definition: Partial derivative

For a function f(x1,…,xn)f(x_1, \dots, x_n) of nn real variables, the partial derivative with respect to xix_i at a point a\mathbf{a} is

∂f∂xi(a)=lim⁡h→0f(a1,…,ai+h,…,an)−f(a1,…,an)h,\frac{\partial f}{\partial x_i}(\mathbf{a}) = \lim_{h \to 0} \frac{f(a_1, \dots, a_i + h, \dots, a_n) - f(a_1, \dots, a_n)}{h},

whenever this limit exists.

Here a=(a1,…,an)\mathbf{a} = (a_1, \dots, a_n) is the point where we measure the slope, and hh is a small step taken along the xix_i axis only. Every other coordinate stays at its value in a\mathbf{a}. The formula is the ordinary Derivative definition applied to the one-variable function that you get by freezing all the other inputs. The curly symbol ∂\partial is a reminder that the other inputs are being held still.

In practice you almost never use the limit directly. You use the rule: differentiate with respect to xix_i, pretend every other variable is a constant, and apply the usual rules of calculus.

Computing by hand

Take f(x,y)=x2y+3yf(x, y) = x^2 y + 3y.

  • To get ∂f∂x\frac{\partial f}{\partial x}, treat yy as a constant. The term x2yx^2 y is yy times x2x^2, so it differentiates to 2xy2xy. The term 3y3y has no xx in it, so it differentiates to 00. Therefore ∂f∂x=2xy\frac{\partial f}{\partial x} = 2xy.
  • To get ∂f∂y\frac{\partial f}{\partial y}, treat xx as a constant. The term x2yx^2 y is a constant x2x^2 times yy, so it differentiates to x2x^2. The term 3y3y differentiates to 33. Therefore ∂f∂y=x2+3\frac{\partial f}{\partial y} = x^2 + 3.

Nothing new happened beyond the ordinary rules. The only skill is remembering which letter is frozen.

Key results

Mixed partials commute. If the second partial derivatives are continuous, the order of differentiation does not matter:

∂∂y(∂f∂x)=∂∂x(∂f∂y).\frac{\partial}{\partial y}\left(\frac{\partial f}{\partial x}\right) = \frac{\partial}{\partial x}\left(\frac{\partial f}{\partial y}\right).

This is sometimes called Clairaut's theorem or Schwarz's theorem. It means a function's curvature in the xyxy direction is well defined, and it is why the second-order information in optimisation is a symmetric matrix.

Linearity. Partial differentiation respects sums and constant multiples, exactly like ordinary differentiation: ∂∂x(af+bg)=a∂f∂x+b∂g∂x\frac{\partial}{\partial x}(af + bg) = a\frac{\partial f}{\partial x} + b\frac{\partial g}{\partial x} for constants aa and bb.

Local linear approximation. Near a point a\mathbf{a}, if ff is differentiable there (for example, if its partial derivatives are continuous), the function is well approximated by a plane whose slopes are the partial derivatives:

f(a+Δx)≈f(a)+∑i=1n∂f∂xi(a) Δxi.f(\mathbf{a} + \Delta \mathbf{x}) \approx f(\mathbf{a}) + \sum_{i=1}^{n} \frac{\partial f}{\partial x_i}(\mathbf{a})\, \Delta x_i.

This is the multivariable version of the tangent line, and it is the reason a small step in the gradient direction lowers a smooth function.

Worked examples

Example
A tiny hand-computable case

Let f(x,y)=x2+y2f(x, y) = x^2 + y^2 and evaluate the partial derivative with respect to xx at the point (1,2)(1, 2).

  1. Freeze yy. The function becomes x2+(constant)x^2 + \text{(constant)}.
  2. Differentiate in xx: ∂f∂x=2x\frac{\partial f}{\partial x} = 2x.
  3. Evaluate at x=1x = 1: ∂f∂x(1,2)=2\frac{\partial f}{\partial x}(1, 2) = 2.

Interpretation: at the point (1,2)(1, 2), moving east by a tiny amount raises the height about twice as fast as the horizontal distance you moved. The value does not depend on yy here, because y2y^2 has no xx in it. Check the other direction too: ∂f∂y=2y\frac{\partial f}{\partial y} = 2y, so ∂f∂y(1,2)=4\frac{\partial f}{\partial y}(1, 2) = 4. Moving north is steeper at this spot.

Example
A realistic case: the gradient of a squared loss

Linear regression fits a line y^=wx+b\hat{y} = wx + b to data by minimising the mean squared error. For three points (xi,yi)(x_i, y_i) = (1,2)(1, 2), (2,3)(2, 3), (3,5)(3, 5), the loss is

L(w,b)=13∑i=13(yi−wxi−b)2.L(w, b) = \frac{1}{3}\sum_{i=1}^{3} \left(y_i - w x_i - b\right)^2.

Evaluate the partial derivatives at w=1w = 1, b=0b = 0.

  1. Compute the residuals ri=yi−wxi−br_i = y_i - w x_i - b: r1=2−1=1r_1 = 2 - 1 = 1, r2=3−2=1r_2 = 3 - 2 = 1, r3=5−3=2r_3 = 5 - 3 = 2.
  2. The loss is L=13(12+12+22)=63=2L = \frac{1}{3}(1^2 + 1^2 + 2^2) = \frac{6}{3} = 2.
  3. Differentiate with respect to ww, freezing bb. Each term contributes 2ri⋅(−xi)2 r_i \cdot (-x_i), so ∂L∂w=−23∑ixiri\frac{\partial L}{\partial w} = -\frac{2}{3}\sum_i x_i r_i.
  4. Substitute: ∑ixiri=1⋅1+2⋅1+3⋅2=9\sum_i x_i r_i = 1 \cdot 1 + 2 \cdot 1 + 3 \cdot 2 = 9, so ∂L∂w=−23⋅9=−6\frac{\partial L}{\partial w} = -\frac{2}{3} \cdot 9 = -6.
  5. Differentiate with respect to bb, freezing ww. Each term contributes 2ri⋅(−1)2 r_i \cdot (-1), so ∂L∂b=−23∑iri\frac{\partial L}{\partial b} = -\frac{2}{3}\sum_i r_i.
  6. Substitute: ∑iri=4\sum_i r_i = 4, so ∂L∂b=−83≈−2.67\frac{\partial L}{\partial b} = -\frac{8}{3} \approx -2.67.

Interpretation: both partials are negative, so increasing ww or bb a little lowers the loss. A gradient descent step moves each parameter in the opposite direction of its partial, so ww and bb both go up. The two partials tell you the steering for each knob separately, and the gradient bundles them together.

Tradeoffs and failure modes

Partial derivatives describe behaviour along coordinate axes only. They can mislead when the directions that matter are not aligned with the axes.

SituationWhat goes wrongBetter choice
Steepest direction is diagonalEach partial looks small, but the combined step is largeUse the gradient, which combines all partials into one direction
Function is not differentiable at the pointThe limit does not exist, so the partial is undefinedUse subgradients or smoothing, as in the absolute-value kink
Inputs are strongly correlatedChanging one input alone is not physically meaningfulUse directional derivatives along the real direction of change
Need the full curvatureSecond partials are many numbers to trackUse the Hessian matrix, or an approximation
Partials exist but the function is not smoothExistence of partials does not imply the function is locally linearCheck continuity of the partials, or use a different analysis

A common trap is assuming that existing partial derivatives means the function is well behaved. A function can have both partials at a point and still fail to be smooth there. The partials only check the axis directions.

History

Partial derivatives grew out of the calculus that Newton and Leibniz developed in the late 1600s. In the 1700s Leonhard Euler, Jean le Rond d'Alembert and Joseph-Louis Lagrange used them to study vibrating strings, fluids and mechanics. The curly ∂\partial was introduced by Adrien-Marie Legendre in the 1780s, fell out of use, and was revived by Carl Jacobi in the 1840s, after which it became standard.

They caught on because physics kept needing them. Heat flow, waves and fluid motion all depend on several variables at once, and the equations that govern them are written in partial derivatives. In the twentieth century the same tool became central to statistics and machine learning, where training a model means taking partial derivatives of a loss with respect to every parameter.

Check yourself

QuestionFor f(x,y)=3xy2f(x, y) = 3x y^2, what is ∂f∂x\frac{\partial f}{\partial x}?Show answer

Treat yy as a constant. The function is 3y23y^2 times xx, so the derivative with respect to xx is the constant 3y23y^2. The answer is ∂f∂x=3y2\frac{\partial f}{\partial x} = 3y^2. Note that it still depends on yy, as partial derivatives generally do.

QuestionFor f(x,y)=x2+3xyf(x, y) = x^2 + 3xy, compute ∂f∂y\frac{\partial f}{\partial y} at the point (2,5)(2, 5).Show answer

Differentiate in yy, treating xx as a constant. The term x2x^2 has no yy, so it contributes 00. The term 3xy3xy contributes 3x3x. So ∂f∂y=3x\frac{\partial f}{\partial y} = 3x. At x=2x = 2 this is 66. The answer is 66.

QuestionWhy do we freeze the other variables when taking a partial derivative, instead of letting them move too?Show answer

Freezing isolates the effect of one input. If every input moved at once, the observed change would mix together the effects of all of them, and you could not say how much of it came from a single input. The partial derivative answers the narrow question "what does this one input do, holding the rest fixed?" Moving all inputs at once is what the gradient and the total derivative describe.

QuestionA function has continuous second partial derivatives. Does it matter whether you differentiate first in xx and then in yy, or the other way round?Show answer

It does not matter. When the mixed second partials are continuous, the order of differentiation can be swapped without changing the result. This is the symmetry of mixed partials. It holds for the smooth functions that appear in most applications, which is why we can talk about the curvature in the xyxy direction without specifying an order.

QuestionIn a model with 10,000 parameters, roughly how many partial derivatives do you compute for one gradient, and what does training do with them?Show answer

One partial derivative per parameter, so about 10,000. Gradient descent collects them into a vector and takes a small step in the opposite direction, lowering the loss a little. Each partial tells you how that single parameter should move, given all the others stay where they are for that instant.

Sources