KTU S1

Composition and the Chain Rule

By the end you should be able to: Apply the chain rule to compositions of functions and extend it to multivariable functions whose inputs depend on a common parameter.

Composition

Given f(x)=x2f(x) = x^2 and g(x)=sin⁡xg(x) = \sin x, feeding one into the other gives

(f∘g)(x)=f(g(x))=sin⁡2x(g∘f)(x)=g(f(x))=sin⁡(x2)(f \circ g)(x) = f(g(x)) = \sin^2 x \qquad (g \circ f)(x) = g(f(x)) = \sin(x^2)

Order matters. These are different functions; try x=1x = 1 and compare.

The chain rule, one variable

ddxf(g(x))=f′(g(x))⋅g′(x)\frac{d}{dx}f(g(x)) = f'(g(x)) \cdot g'(x)

Or in Leibniz form, which is easier to remember and to generalise:

dydx=dydu⋅dudx\frac{dy}{dx} = \frac{dy}{du}\cdot\frac{du}{dx}

What it says. A small nudge in xx changes uu by g′(x)g'(x) times as much; that change in uu changes yy by f′(u)f'(u) times as much. Multiply the two amplification factors.

For y=sin⁡(x2)y = \sin(x^2): put u=x2u = x^2, so y=sin⁡uy = \sin u.

dydx=cos⁡(u)⋅2x=2xcos⁡(x2)\frac{dy}{dx} = \cos(u) \cdot 2x = 2x\cos(x^2)

The multivariable chain rule

Now let z=f(x,y)z = f(x,y) where both xx and yy depend on a parameter tt. As tt moves, both inputs move, and each drags zz with it:

dzdt=∂z∂xdxdt+∂z∂ydydt\frac{dz}{dt} = \frac{\partial z}{\partial x}\frac{dx}{dt} + \frac{\partial z}{\partial y}\frac{dy}{dt}

Sum the contributions, one per input. Each term is "how much zz responds to that input" times "how fast that input is moving".

Note the mixture of ∂\partial and dd: partial for zz against its own inputs, ordinary for anything depending on tt alone.

A worked instance with a check

z=x2+y2z = x^2 + y^2, with x=cos⁡tx = \cos t and y=sin⁡ty = \sin t.

∂z∂x=2x,∂z∂y=2y,dxdt=−sin⁡t,dydt=cos⁡t\frac{\partial z}{\partial x} = 2x, \quad \frac{\partial z}{\partial y} = 2y, \quad \frac{dx}{dt} = -\sin t, \quad \frac{dy}{dt} = \cos t dzdt=2x(−sin⁡t)+2y(cos⁡t)=−2cos⁡tsin⁡t+2sin⁡tcos⁡t=0\frac{dz}{dt} = 2x(-\sin t) + 2y(\cos t) = -2\cos t\sin t + 2\sin t\cos t = 0

Check it directly. Substituting first, z=cos⁡2t+sin⁡2t=1z = \cos^2 t + \sin^2 t = 1, a constant — so dz/dt=0dz/dt = 0. The two routes agree.

The geometry: the point (cos⁡t,sin⁡t)(\cos t, \sin t) travels around the unit circle, which is itself a level curve of x2+y2x^2+y^2. Moving along a contour, height never changes. The chain rule and the picture say the same thing.

More inputs

The pattern extends. For w=f(x,y,z)w = f(x,y,z) with all three depending on tt:

dwdt=∂w∂xdxdt+∂w∂ydydt+∂w∂zdzdt\frac{dw}{dt} = \frac{\partial w}{\partial x}\frac{dx}{dt} + \frac{\partial w}{\partial y}\frac{dy}{dt} + \frac{\partial w}{\partial z}\frac{dz}{dt}

One term per input, always.

Why it matters later

Backpropagation in a neural network is the chain rule applied through many layers. The gradient of a loss with respect to an early weight is a product of the sensitivities at every layer in between — exactly this rule, at scale.