Skip to main content

10. Differentiation Rules and Techniques — Differentiating the World through Composition

Calculus 2/5. Every complex function is built from arithmetic operations and compositions of basic functions. A table of basic derivatives plus four combination rules is therefore enough to differentiate any function mechanically. This "mechanical" property is the seed that later becomes automatic differentiation.

Table of basic derivatives

f(x)f(x)f(x)f'(x)Note
cc00Constant
xnx^nnxn1n x^{n-1}Holds for every real nn
exe^xexe^xThe unique fixed-point function
axa^xaxlnaa^x \ln aReduce via ax=exlnaa^x = e^{x \ln a}
lnx\ln x1/x1/xDerived with the inverse-function rule
sinx\sin xcosx\cos x
cosx\cos xsinx-\sin x
tanx\tan xsec2x\sec^2 xDerived with the quotient rule
arcsinx\arcsin x1/1x21/\sqrt{1-x^2}Inverse-function rule
arctanx\arctan x1/(1+x2)1/(1+x^2)Inverse-function rule

The four combination rules

1. Linearity

(af+bg)=af+bg(af + bg)' = a f' + b g'

Differentiation is a linear operator. Together with the linearity of expectation, it illustrates the general mathematical principle that "linear things are easy to handle."

2. Product rule

(fg)=fg+fg(fg)' = f'g + fg'

Intuition: when the two sides of a rectangle with area f×gf \times g each grow slightly, the increase in area is "the sum of each side's contribution + a negligible corner piece (fgh2f'g' h^2)." For the proof, insert f(x+h)g(x)f(x+h)g(x)=0f(x+h)g(x) - f(x+h)g(x) = 0 into f(x+h)g(x+h)f(x)g(x)f(x+h)g(x+h) - f(x)g(x) and separate the terms.

3. Quotient rule

(fg)=fgfgg2(g0)\left( \frac{f}{g} \right)' = \frac{f'g - fg'}{g^2} \qquad (g \neq 0)

It does not need to be memorized separately; applying the product rule and chain rule to fg1f \cdot g^{-1} gives the same result.

4. Chain rule — the most important

(gf)(x)=g(f(x))f(x)or in Leibniz formdzdx=dzdydydx(g \circ f)'(x) = g'\big(f(x)\big) \cdot f'(x) \qquad\text{or in Leibniz form}\qquad \frac{dz}{dx} = \frac{dz}{dy} \cdot \frac{dy}{dx}

Proof sketch (linear-approximation perspective): using Definition 2 from Part 1, it takes two lines.

f(x+h)=f(x)+f(x)h+o(h),g(y+k)=g(y)+g(y)k+o(k)f(x+h) = f(x) + f'(x)h + o(h), \qquad g(y+k) = g(y) + g'(y)k + o(k)

Substituting k=f(x)h+o(h)k = f'(x)h + o(h) gives

g(f(x+h))=g(f(x))+g(f(x))f(x)h+o(h)g\big(f(x+h)\big) = g\big(f(x)\big) + g'\big(f(x)\big) f'(x)\, h + o(h)

That is, "the composition of linear approximations is the product of slopes." This one line is the entire chain rule. In multiple variables it extends to "the product of Jacobian matrices," and in computational graphs it becomes backpropagation. Training a deep neural network ultimately applies this rule millions of times.

Example: ddxex2/2=ex2/2(x)\dfrac{d}{dx} e^{-x^2/2} = e^{-x^2/2} \cdot (-x)—the fact that the derivative of a Gaussian density has the form "itself × (x)(-x)" reappears in many places, including Stein's identity for the Gaussian distribution and the Ornstein–Uhlenbeck process.

Differentiating inverse functions

If ff has an inverse f1f^{-1}, then

(f1)(y)=1f(f1(y))\big(f^{-1}\big)'(y) = \frac{1}{f'\big(f^{-1}(y)\big)}

Derivation: differentiate both sides of f(f1(y))=yf(f^{-1}(y)) = y with respect to yy (chain rule) to get f(f1(y))(f1)(y)=1f'(f^{-1}(y)) \cdot (f^{-1})'(y) = 1.

Example — derivative of ln\ln: since y=lnx    x=eyy = \ln x \iff x = e^y,

(lnx)=1elnx=1x(\ln x)' = \frac{1}{e^{\ln x}} = \frac{1}{x}

In probability, inverse-function differentiation is the heart of the change-of-variables formula. If Y=g(X)Y = g(X) and gg is monotonic,

fY(y)=fX(g1(y))ddyg1(y)f_Y(y) = f_X\big(g^{-1}(y)\big) \left| \frac{d}{dy} g^{-1}(y) \right|

Normalizing flows stand on this formula.

Implicit differentiation

Even when yy cannot be explicitly solved as a function of xx, differentiating both sides of the relation yields yy'.

Example — a circle: differentiating both sides of x2+y2=1x^2 + y^2 = 1 with respect to xx gives 2x+2yy=02x + 2y\,y' = 0, so y=x/yy' = -x/y. The tangent slope is obtained without solving for yy in terms of xx.

This technique is used directly in implicit layers, where a layer is defined as the solution of an equation, and in hyperparameter differentiation (bilevel optimization based on the implicit function theorem).

Logarithmic differentiation

For a function with layers of products and powers, taking the logarithm first to turn them into sums makes differentiation overwhelmingly easier.

(lnf)=fff=f(lnf)(\ln f)' = \frac{f'}{f} \quad\Longrightarrow\quad f' = f \cdot (\ln f)'

Example — f(x)=xxf(x) = x^x: because lnf=xlnx\ln f = x \ln x, (lnf)=lnx+1(\ln f)' = \ln x + 1, and therefore

(xx)=xx(lnx+1)(x^x)' = x^x (\ln x + 1)

Connection to statistics: differentiating the log-likelihood (θ)=ilnp(xiθ)\ell(\theta) = \sum_i \ln p(x_i \mid \theta) instead of the likelihood L(θ)=ip(xiθ)L(\theta) = \prod_i p(x_i \mid \theta) directly is exactly logarithmic differentiation. The score function θlnp\nabla_\theta \ln p, cross-entropy loss, and REINFORCE's log-derivative trick p=plnp\nabla p = p \nabla \ln p—half the reason logarithms appear everywhere in ML is "to turn products into sums and make differentiation easy."

Higher-order derivatives

Differentiating a derivative again gives the second derivative ff''; repeating gives f(n)f^{(n)}.

  • ff' — slope (first-order information): increasing/decreasing
  • ff'' — curvature (second-order information): convex/concave, above/below the tangent
  • On an interval where f>0f'' > 0, ff is convex—the condition leads to a "guaranteed minimum" in Optimization Part 5.

Example: (ex2/2)=(x21)ex2/2(e^{-x^2/2})'' = (x^2 - 1)e^{-x^2/2}—the inflection points of the Gaussian bell are exactly x=±1x = \pm 1 (the standard-deviation points).

Summary

  • A table of basic derivatives plus four rules (linearity, product, quotient, and chain) mechanically differentiates every elementary function.
  • Chain rule = "the composition of linear approximations is the product of slopes." It is the mathematical core of deep-learning backpropagation.
  • Inverse-function differentiation leads to the change-of-variables formula for random variables, while logarithmic differentiation leads to log-likelihoods and score functions.
  • The second derivative determines convexity and connects to second-order conditions in optimization.

Next: Mean Value Theorem and Taylor Expansion