Partial Derivatives and the Multivariable Chain Rule

Published on 2026-11-04·v1.0

Learning Objectives

  • Define the partial derivatives fxf_x and fyf_y as limits, compute them by freezing the other variable, and read each as the slope of a slice of the graph.
  • State the equality of mixed partials with its hypothesis, and recognize a function where it fails.
  • Build the tangent plane as the linear approximation of ff, and explain why differentiability asks for more than the existence of partial derivatives.
  • Apply the multivariable chain rule for one and two parameters, including the implicit slope of a level curve.
  • Use the chain rule to differentiate a small computation graph, the idea behind backpropagation.

Context & Motivation

A function of several variables has no single slope at a point: the slope depends on which way you walk. The simplest way to tame this is to walk along one coordinate axis at a time, holding every other variable fixed. The result is a partial derivative, which is an ordinary single-variable derivative applied to a slice of the surface from functions-of-several-variables-and-level-curves. The existing lesson gradients-extending-derivatives-to-several-variables uses partial derivatives informally, as "how fast ff changes if you nudge one variable". Here the limit definition comes back, together with the question that informal treatment skips: when does the list of partial derivatives actually describe how ff behaves in every direction?

The second half of the lesson is the chain rule. Real computations are compositions: a loss depends on a prediction, which depends on a score, which depends on weights. Every derivative needed to train such a model comes from the chain rule applied through intermediate variables. The single-variable version is in differentiation-rules-and-the-chain-rule, and the new difficulty is that an intermediate quantity can depend on the input through several routes at once.

Core Theory

Partial derivatives

For f(x,y)f(x, y) at (a,b)(a, b),

fx(a,b)=lim⁡h→0f(a+h,b)−f(a,b)h,fy(a,b)=lim⁡h→0f(a,b+h)−f(a,b)h,f_x(a, b) = \lim_{h \to 0} \frac{f(a + h, b) - f(a, b)}{h}, \qquad f_y(a, b) = \lim_{h \to 0} \frac{f(a, b + h) - f(a, b)}{h},

when the limits exist. Geometrically, fx(a,b)f_x(a, b) is the slope at x=ax = a of the curve where the vertical plane y=by = b cuts the graph. In practice, differentiate with respect to one variable and treat the other as a constant. Other notations are ∂f/∂x\partial f/\partial x and ∂xf\partial_x f. Notice what the definition uses: ff along two lines through the point and nothing else. On a contour map, fxf_x can be estimated by stepping east from the point to the next level curve: the change in height divided by the distance walked. Contours packed closely along the east-west direction mean a large ∣fx∣\lvert f_x \rvert, and the sign says whether the surface rises or falls as you go east.

Mixed partials

Differentiating twice gives fxxf_{xx}, fyyf_{yy} and the mixed partials fxy=(fx)yf_{xy} = (f_x)_y and fyx=(fy)xf_{yx} = (f_y)_x. Clairaut's theorem: if ff is defined on a disk around (a,b)(a, b) and both fxyf_{xy} and fyxf_{yx} are continuous on that disk, then fxy(a,b)=fyx(a,b)f_{xy}(a, b) = f_{yx}(a, b). Polynomials, exponentials, sines and their compositions meet the hypothesis everywhere. Also keep the notation straight: fxyf_{xy} means differentiate in xx first, then in yy, and some books write the opposite order. Example 3 shows what happens when it fails.

Differentiability and the tangent plane

The right generalization of "differentiable" is linear approximability. ff is differentiable at (a,b)(a, b) if there are numbers AA and BB with

lim⁡(x,y)→(a,b)f(x,y)−f(a,b)−A(x−a)−B(y−b)(x−a)2+(y−b)2=0.\lim_{(x,y) \to (a,b)} \frac{f(x, y) - f(a, b) - A(x - a) - B(y - b)}{\sqrt{(x-a)^2 + (y-b)^2}} = 0.

If this holds, then A=fx(a,b)A = f_x(a, b) and B=fy(a,b)B = f_y(a, b), and the plane

L(x,y)=f(a,b)+fx(a,b)(x−a)+fy(a,b)(y−b)L(x, y) = f(a, b) + f_x(a, b)(x - a) + f_y(a, b)(y - b)

is the tangent plane, the best linear approximation: the error shrinks faster than the distance to the point. A differentiable function is continuous. The existence of fxf_x and fyf_y is not enough, since they only see two directions. A usable sufficient condition: if fxf_x and fyf_y exist in a neighborhood of (a,b)(a, b) and are continuous at (a,b)(a, b), then ff is differentiable there. Functions with continuous first partials are called C1C^1. In terms of the approximation, the change of a differentiable function is Δf≈fxΔx+fyΔy\Delta f \approx f_x \Delta x + f_y \Delta y for small steps, and the right-hand side is the differential dfdf. It is what turns a measurement error in xx and yy into an error in ff.

The chain rule

Let z=f(x,y)z = f(x, y) be differentiable at (x(t0),y(t0))(x(t_0), y(t_0)), with x(t)x(t) and y(t)y(t) differentiable at t0t_0. Then z(t)=f(x(t),y(t))z(t) = f(x(t), y(t)) is differentiable at t0t_0 and

dzdt=fxdxdt+fydydt.\frac{dz}{dt} = f_x \frac{dx}{dt} + f_y \frac{dy}{dt}.

With two parameters, x=x(s,t)x = x(s, t) and y=y(s,t)y = y(s, t), each parameter gets its own sum:

∂z∂s=fx∂x∂s+fy∂y∂s.\frac{\partial z}{\partial s} = f_x \frac{\partial x}{\partial s} + f_y \frac{\partial y}{\partial s}.

Here is why differentiability is the right hypothesis. For a small step hh in tt, the linear approximation gives z(t0+h)−z(t0)≈fx Δx+fy Δyz(t_0 + h) - z(t_0) \approx f_x\,\Delta x + f_y\,\Delta y with Δx≈x′(t0) h\Delta x \approx x'(t_0)\,h and Δy≈y′(t0) h\Delta y \approx y'(t_0)\,h. Dividing by hh and letting h→0h \to 0 gives the formula. If ff only has partials, the first approximation is not available. The rule is: add one product for every route from zz to the parameter, multiplying the derivatives along the route.

Implicit slope. Suppose F(x,y)=cF(x, y) = c defines yy as a differentiable function of xx near a point where FF is C1C^1 and Fy≠0F_y \ne 0. Differentiating F(x,y(x))=cF(x, y(x)) = c with the chain rule gives Fx+Fy y′=0F_x + F_y\, y' = 0, so y′=−Fx/Fyy' = -F_x/F_y. This is the slope of the level curve from the previous lesson. Where Fy=0F_y = 0 the formula breaks, and the level curve may have a vertical tangent.

Worked Examples

Example 1: linear approximation of a distance

Let f(x,y)=x2+y2f(x, y) = \sqrt{x^2 + y^2}, the distance from the origin, at (3,4)(3, 4) where f=5f = 5. Then fx=x/x2+y2=3/5f_x = x/\sqrt{x^2+y^2} = 3/5 and fy=4/5f_y = 4/5 there, so

L(x,y)=5+35(x−3)+45(y−4).L(x, y) = 5 + \tfrac35 (x - 3) + \tfrac45 (y - 4).

At (3.1,3.9)(3.1, 3.9): L=5+0.06−0.08=4.98L = 5 + 0.06 - 0.08 = 4.98, and the true value is 24.82≈4.98197\sqrt{24.82} \approx 4.98197, an error of about 0.00200.0020. The numbers also have a meaning: stepping east raises the distance by 0.60.6 per unit, less than 11 because east is not straight away from the origin. Stepping straight away, in the direction (3,4)/5(3, 4)/5, changes it at rate 35⋅35+45⋅45=1\tfrac35\cdot\tfrac35 + \tfrac45\cdot\tfrac45 = 1, as it must for a distance. The next lesson explains this combination. Halving the displacement should quarter the error, and it does:

text
displacement (d, -d) true f L error d = 0.1 4.981967 4.980000 0.001967 d = 0.05 4.990491 4.990000 0.000491 d = 0.025 4.995123 4.995000 0.000123

Example 2: mixed partials

Let g(x,y)=x3y2+exyg(x, y) = x^3 y^2 + e^{xy}. Then gx=3x2y2+yexyg_x = 3x^2y^2 + y e^{xy} and gy=2x3y+xexyg_y = 2x^3 y + x e^{xy}. Differentiating again,

gxy=6x2y+exy+xy exy=gyx.g_{xy} = 6x^2 y + e^{xy} + xy\, e^{xy} = g_{yx}.

Both are continuous everywhere, so Clairaut applies and the equality is guaranteed, not a coincidence.

Example 3: a function where mixed partials differ

Let u(x,y)=xy(x2−y2)x2+y2u(x, y) = \dfrac{xy(x^2 - y^2)}{x^2 + y^2} for (x,y)≠(0,0)(x, y) \ne (0, 0) and u(0,0)=0u(0, 0) = 0. For y≠0y \ne 0, u(h,y)/hu(h, y)/h tends to −y-y as h→0h \to 0, and u(0,y)=0u(0, y) = 0, so ux(0,y)=−yu_x(0, y) = -y for all yy. Symmetrically uy(x,0)=xu_y(x, 0) = x for all xx. Therefore

uxy(0,0)=ddy(−y)=−1,uyx(0,0)=ddx(x)=1.u_{xy}(0, 0) = \frac{d}{dy}(-y) = -1, \qquad u_{yx}(0, 0) = \frac{d}{dx}(x) = 1.

A numerical check with an inner step of 10−510^{-5} and an outer step of 10−310^{-3} gives −0.9998-0.9998 and 0.99980.9998 (the value is ±(h2−k2)/(h2+k2)\pm(h^2 - k^2)/(h^2 + k^2) for inner step hh and outer step kk, so equal steps would give exactly 00). Both mixed partials exist but are not continuous at the origin, which is exactly the hypothesis that Clairaut needs.

Example 4: the chain rule with two parameters

Let z=x2yz = x^2 y with x=stx = st and y=s+ty = s + t, at (s,t)=(1,2)(s, t) = (1, 2), where x=2x = 2 and y=3y = 3.

zs=2xy⋅t+x2⋅1=2(2)(3)(2)+4=28,zt=2xy⋅s+x2⋅1=12+4=16.z_s = 2xy \cdot t + x^2 \cdot 1 = 2(2)(3)(2) + 4 = 28, \qquad z_t = 2xy \cdot s + x^2 \cdot 1 = 12 + 4 = 16.

Substituting first gives z=s3t2+s2t3z = s^3 t^2 + s^2 t^3, so zs=3s2t2+2st3=12+16=28z_s = 3s^2t^2 + 2st^3 = 12 + 16 = 28 and zt=2s3t+3s2t2=4+12=16z_t = 2s^3 t + 3s^2 t^2 = 4 + 12 = 16. A centered finite difference agrees.

Example 5: the chain rule through a neuron

A single sigmoid neuron has score z=wx+bz = wx + b, output p=σ(z)=1/(1+e−z)p = \sigma(z) = 1/(1 + e^{-z}) and loss L=(p−y)2L = (p - y)^2. The route from LL to ww passes through pp and zz, so

∂L∂w=2(p−y)⏟∂L/∂p  p(1−p)⏟∂p/∂z  x⏟∂z/∂w,∂L∂b=2(p−y) p(1−p).\frac{\partial L}{\partial w} = \underbrace{2(p - y)}_{\partial L/\partial p}\; \underbrace{p(1 - p)}_{\partial p/\partial z}\; \underbrace{x}_{\partial z/\partial w}, \qquad \frac{\partial L}{\partial b} = 2(p - y)\,p(1 - p).

Take x=2x = 2, w=0.5w = 0.5, b=−1b = -1, y=1y = 1. Then z=0z = 0, p=0.5p = 0.5, L=0.25L = 0.25, and

∂L∂w=2(−0.5)(0.25)(2)=−0.5,∂L∂b=−0.25.\frac{\partial L}{\partial w} = 2(-0.5)(0.25)(2) = -0.5, \qquad \frac{\partial L}{\partial b} = -0.25.

Centered finite differences give −0.5000-0.5000 and −0.2500-0.2500. Both are negative: increasing ww or bb lowers the loss here. Backpropagation is this same product of local derivatives, computed from the loss backward and reused across all the routes.

The finite-difference check is also a standard debugging tool: compare the analytic derivative with (L(w+ε)−L(w−ε))/(2ε)(L(w + \varepsilon) - L(w - \varepsilon))/(2\varepsilon). The centered form has error of order ε2\varepsilon^2, but it costs two evaluations of the loss per parameter, which is why it is used to test a gradient and not to compute one for a model with millions of parameters.

Example 6: the implicit slope, and a broken chain rule

For x2+4y2=8x^2 + 4y^2 = 8 at (2,1)(2, 1): Fx=2x=4F_x = 2x = 4 and Fy=8y=8F_y = 8y = 8, so y′=−4/8=−1/2y' = -4/8 = -1/2 and the tangent line is x+2y=4x + 2y = 4.

Now the hypothesis. Take q(x,y)=xy/(x2+y2)q(x, y) = xy/(x^2 + y^2) with q(0,0)=0q(0, 0) = 0. Its partials at the origin are both 00, because q(h,0)=q(0,h)=0q(h, 0) = q(0, h) = 0. Along x=tx = t, y=ty = t the composite is g(t)=1/2g(t) = 1/2 for t≠0t \ne 0 and g(0)=0g(0) = 0, which is not even continuous at t=0t = 0, yet the formula qx⋅1+qy⋅1q_x \cdot 1 + q_y \cdot 1 would produce 00. The chain rule failed because qq is not differentiable at the origin.

Common Misconceptions & Pitfalls

  • "If both partials exist, ff is differentiable (or at least continuous)." The function qq of Example 6 has both partials at the origin and is not continuous there.
  • "Mixed partials are always equal." Only under the continuity hypothesis. Example 3 gives −1-1 and 11.
  • "The ∂\partial symbols cancel like fractions." Writing ∂z∂x∂x∂s\frac{\partial z}{\partial x}\frac{\partial x}{\partial s} and cancelling ∂x\partial x drops the route through yy. The chain rule is a sum over routes, not a single product.
  • "The tangent plane approximates well everywhere." It is a local statement. The error is small near the point and grows away from it.
  • "The chain rule only needs the partial derivatives to exist." It needs ff to be differentiable at the point, which is what fails in Example 6. Continuous first partials are the usual way to guarantee it.
  • "dz/dtdz/dt and ∂z/∂x\partial z/\partial x are interchangeable." Use dd when the quantity depends on a single variable, and ∂\partial when the other variables are held fixed.

Summary

A partial derivative is a single-variable derivative along one coordinate axis, the slope of a slice. Mixed partials agree when both are continuous near the point, and can differ otherwise. Differentiability, meaning a linear approximation whose error vanishes faster than the distance, defines the tangent plane and is guaranteed by continuous first partials, but not by the mere existence of partials. For a differentiable ff composed with differentiable inner functions, the chain rule sums one product per route, which gives the implicit slope −Fx/Fy-F_x/F_y of a level curve and the derivatives of a neuron's loss. The next lesson, directional-derivatives-and-the-direction-of-steepest-ascent, assembles the partials into the gradient and uses the chain rule to read off slopes in every direction.

Documentation Links