Skip to main content
Fanout
Derivation Rules & Examples
Curriculum overview

Math Fundamentals · lesson 06/15

Derivation Rules & Examples

Differentiation is an algorithm, not a bag of tricks. A handful of rules covers every elementary function, and they compose: autograd and hand-written backprop code are both just these rules applied in order. Knowing them cold is what lets you read a gradient formula instead of trusting it.

The idea

f(x)f(x)f(x)f'(x)Rule
cc00constant
xnx^nnxn1n x^{n-1}power
u+vu + vu+vu' + v'sum
uvu vuv+uvu'v + uv'product
u/vu / v(uvuv)/v2(u'v - uv') / v^2quotient
u(v(x))u(v(x))u(v(x))v(x)u'(v(x))\, v'(x)chain
exe^xexe^xexponential
lnx\ln x1/x1/xlogarithm
sinx\sin xcosx\cos xtrig
cosx\cos xsinx-\sin xtrig

Two facts make the table go further. First, lnx\ln x and exe^x are inverses, and 1/x1/x versus exe^x reflects that. Second, generic bases reduce to the natural ones: ax=exlnaa^x = e^{x \ln a}, so (ax)=axlna(a^x)' = a^x \ln a, and logax=lnx/lna\log_a x = \ln x / \ln a.

Worked example

Differentiate f(x)=x2exf(x) = x^2 e^x with the product rule, taking u=x2u = x^2 and v=exv = e^x:

f(x)=2xex+x2ex=xex(x+2)f'(x) = 2x\, e^x + x^2 e^x = x e^x (x + 2)

At x=1x = 1 this gives 1e13=3e8.1551 \cdot e^1 \cdot 3 = 3e \approx 8.155. Direct substitution into the unfactored form gives the same: 2e+e=3e2e + e = 3e.

Now g(x)=(x+1)/(x1)g(x) = (x + 1)/(x - 1) with the quotient rule:

g(x)=(1)(x1)(x+1)(1)(x1)2=2(x1)2g'(x) = \frac{(1)(x - 1) - (x + 1)(1)}{(x - 1)^2} = \frac{-2}{(x - 1)^2}

At x=3x = 3, g(3)=2/4=0.5g'(3) = -2/4 = -0.5. The derivative is negative everywhere it is defined: the function decreases on each side of its pole.

In code

import torch

x = torch.tensor(1.0, requires_grad=True)
y = x**2 * torch.exp(x)
y.backward()
print(x.grad)  # tensor(8.1548) == 3e

The chain rule, covered next, is what makes the table composable. Its job is to connect the derivative you know locally to the variable you actually care about.

Check yourself

  1. Differentiate x3lnxx^3 \ln x using the product rule.
  2. Rewrite 1/v1/v as v1v^{-1} and derive the quotient rule from the product and chain rules.
  3. Differentiate e2xe^{2x} and ln(x2)\ln(x^2) from the table plus the chain rule.

Key takeaways

  • A small table of rules covers all elementary derivatives.
  • Product and quotient rules are mechanical; the chain rule makes them composable.
  • Reduce non-natural bases and logs to ee and ln\ln before differentiating.