Calculus I · A Toolkit for Slopes

Sums, differences, and constant multiples

In Chapter 3 you found ddx(3x2−4x+1)=6x−4\tfrac{d}{dx}(3x^2 - 4x + 1) = 6x - 4 — you differentiated term by term, and you predicted the rule in the Looking-ahead problems. Here it is, and it’s immediate from the definition (the difference quotient of a sum is the sum of the difference quotients):

Sum / Constant-Multiple Rules. ddx[f(x)+g(x)]=f′(x)+g′(x),ddx[cf(x)]=cf′(x).\displaystyle \frac{d}{dx}\big[f(x) + g(x)\big] = f'(x) + g'(x), \qquad \frac{d}{dx}\big[c\,f(x)\big] = c\,f'(x).

Together with the power rule, these differentiate any polynomial instantly. For example, ddx(5x4−2x3+7x−9)=20x3−6x2+7\tfrac{d}{dx}(5x^4 - 2x^3 + 7x - 9) = 20x^3 - 6x^2 + 7 — bring each exponent down, subtract one, drop the constant. What took a page in Chapter 3 now takes a glance.


The product rule (and why it is not what you’d guess)

Here intuition fails, so we derive carefully. You might guess that the derivative of a product is the product of the derivatives — that (fg)′=f′g′(fg)' = f'g'. It is not, and the derivation shows why. Start from the definition and use one clever move: add and subtract the same term, f(a+h)g(a)f(a+h)g(a), to split the quotient into two recognizable pieces.

Figure 4.2
Figure 4.2

f(a+h)g(a+h)−f(a)g(a)h=f(a+h)g(a+h)−f(a+h)g(a)h+f(a+h)g(a)−f(a)g(a)h\frac{f(a+h)g(a+h) - f(a)g(a)}{h} = \frac{f(a+h)g(a+h) - f(a+h)g(a)}{h} + \frac{f(a+h)g(a) - f(a)g(a)}{h} =f(a+h)⋅g(a+h)−g(a)h+g(a)⋅f(a+h)−f(a)h.= f(a+h)\cdot\frac{g(a+h)-g(a)}{h} + g(a)\cdot\frac{f(a+h)-f(a)}{h}.

Now let h→0h \to 0. The two difference quotients become g′(a)g'(a) and f′(a)f'(a); and f(a+h)→f(a)f(a+h) \to f(a) because ff is continuous (which, by Chapter 3, follows from ff being differentiable). So:

The Product Rule. ddx[f(x)g(x)]=f′(x)g(x)+f(x)g′(x).\displaystyle \frac{d}{dx}\big[f(x)\,g(x)\big] = f'(x)\,g(x) + f(x)\,g'(x).

In words: derivative of the first times the second, plus the first times the derivative of the second. The extra term — the one the naive guess misses — is exactly the cross-term that the add-and-subtract trick exposed. Example: ddx[x2(x3+1)]=(2x)(x3+1)+(x2)(3x2)=2x4+2x+3x4=5x4+2x\tfrac{d}{dx}\big[x^2(x^3+1)\big] = (2x)(x^3+1) + (x^2)(3x^2) = 2x^4 + 2x + 3x^4 = 5x^4 + 2x. (Check: expanding first gives x5+x2x^5 + x^2, whose derivative is 5x4+2x5x^4 + 2x. They agree.)


The chain rule: differentiating a function inside a function

This is the one that matters most, because most real functions are compositions — a function applied to the output of another function, like (x2+1)5(x^2+1)^5 (raise-to-the-fifth applied to x2+1x^2+1) or x2+1\sqrt{x^2+1} or ex2e^{x^2}. The chain rule tells you how to differentiate them, and Leibniz’s notation makes it almost think for you. Write y=f(u)y = f(u) where u=g(x)u = g(x) — an outer function ff and an inner function gg. Then:

Figure 4.3
Figure 4.3

The Chain Rule. dydx=dydu⋅dudx,orddxf(g(x))=f′(g(x))⋅g′(x).\displaystyle \frac{dy}{dx} = \frac{dy}{du}\cdot\frac{du}{dx}, \qquad\text{or}\qquad \frac{d}{dx}\,f(g(x)) = f'(g(x))\cdot g'(x).

The idea behind it is beautifully simple: rates of change multiply through a chain. If yy changes dydu\tfrac{dy}{du} times as fast as uu, and uu changes dudx\tfrac{du}{dx} times as fast as xx, then yy changes dydu⋅dudx\tfrac{dy}{du}\cdot\tfrac{du}{dx} times as fast as xx — the same way gear ratios multiply. (The honest derivation writes ΔyΔx=ΔyΔu⋅ΔuΔx\tfrac{\Delta y}{\Delta x} = \tfrac{\Delta y}{\Delta u}\cdot\tfrac{\Delta u}{\Delta x} and takes limits; a careful proof handles the case Δu=0\Delta u = 0 separately, which is the Diamond problem.) In practice: differentiate the outer function, leaving the inside alone, then multiply by the derivative of the inside.

  • ddx(x2+1)5=5(x2+1)4⋅2x⏟inside′=10x(x2+1)4.\dfrac{d}{dx}(x^2+1)^5 = 5(x^2+1)^4 \cdot \underbrace{2x}_{\text{inside}'} = 10x(x^2+1)^4.
  • ddxx2+1=12x2+1⋅2x=xx2+1.\dfrac{d}{dx}\sqrt{x^2+1} = \dfrac{1}{2\sqrt{x^2+1}}\cdot 2x = \dfrac{x}{\sqrt{x^2+1}}.
  • ddxex2=ex2⋅2x\dfrac{d}{dx}e^{x^2} = e^{x^2}\cdot 2x (using the exponential’s derivative, below).

A glimpse of why machine learning runs on this rule

A neural network is a tower of functions — the input passes through layer after layer, each one a function of the layer below: f(g(h(⋯)))f\big(g\big(h(\cdots)\big)\big), sometimes hundreds deep. To train it, you need the derivative of the final error with respect to every knob in every layer — and you get it by the chain rule, multiplying the rates of change layer by layer, working from the output back toward the input. That backward sweep has a name — backpropagation — and it is nothing more exotic than the chain rule, applied across an enormous composition, a few billion times per second. The rule you’re learning on (x2+1)5(x^2+1)^5 is the literal engine of modern AI.


All 12 chapters of Calculus I · Foundations · All courses