Foundations to Frontier
Tests
A. Mathematical Foundations › A3 Calculus and Analysis › Single-variable calculus

Derivatives: Definition and Rules (Product, Quotient, Chain)

The derivative is the instantaneous rate of change, the slope of the tangent and the best linear approximation, all at once. The chain rule, applied backwards, is backpropagation, the engine of deep learning.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

How fast, right now?

A car’s speedometer doesn’t show your average speed for the whole trip. It shows how fast you’re going at this instant. That instant rate of change is the derivative.

On a hill, the derivative is the steepness right where you stand. It’s positive going uphill, negative going downhill, and zero at the very top.

From secant to tangent: the derivative as a limit
secant slope (f(a+h) − f(a))/h = 3.000000 · derivative f′(a) = 2.000000 · error 1.0e+0
Orange = secant through a and a + h; dashed green = tangent. Shrink h and the error shrinks roughly in proportion to h (first-order). Try |x| at a = 0.
Why engineers care

A rocket’s guidance computer constantly asks “how fast is my altitude changing?” and “how fast is that speed changing?”. Those are the first and second derivatives. Every control loop on a robot or spacecraft is built on them.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A car covers 100 km in 2 hours at a steady speed. Its speed?
  2. 2. At the very top of a thrown ball's path, its vertical speed is…
  3. 3. The slope of a flat road is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

The definition

f′(a)=lim⁡h→0f(a+h)−f(a)hf'(a) = \lim_{h\to0}\frac{f(a+h) - f(a)}{h}

This is the limit (A3.1-1) of secant slopes, and it gives the slope of the tangent line. Other notations are dfdx\frac{df}{dx}, x˙\dot x (a time derivative, in physics and robotics) and DfDf.

Example. For f(x)=x2f(x) = x^2: (a+h)2−a2h=2a+h→2a\frac{(a+h)^2 - a^2}{h} = 2a + h\to2a. So (x2)′=2x(x^2)' = 2x.

The power rule

ddxxn=nxn−1,ddxc=0,(cf)′=cf′,(f+g)′=f′+g′\frac{d}{dx}x^n = nx^{n-1}, \qquad \frac{d}{dx}c = 0, \qquad (cf)' = cf', \qquad (f+g)' = f' + g'

So (5x2+3x)′=10x+3(5x^2 + 3x)' = 10x + 3, which is 13 at x=1x = 1.

📝 Quick check (Level 1)
0/3 answered
  1. 1. (x³)′ at x = 2?
  2. 2. The slope of the tangent to x² at x = −1?
  3. 3. d/dx 7 = ?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

The rules

Rule Formula Example
product (fg)′=f′g+fg′(fg)' = f'g + fg' (x2ex)′=(2x+x2)ex(x^2e^x)' = (2x + x^2)e^x
quotient (fg)′=f′g−fg′g2\big(\tfrac fg\big)' = \frac{f'g - fg'}{g^2} (xx+1)′=1(x+1)2\big(\tfrac x{x+1}\big)' = \frac1{(x+1)^2}
chain (f∘g)′(x)=f′(g(x)) g′(x)(f\circ g)'(x) = f'(g(x))\,g'(x) (sin⁡x2)′=2xcos⁡x2(\sin x^2)' = 2x\cos x^2, ((3x+1)4)′=12(3x+1)3((3x+1)^4)' = 12(3x+1)^3

The chain rule says rates multiply through a composition. If yy changes 5× as fast as uu, and uu changes 3× as fast as xx, then yy changes 15× as fast as xx.

The derivative as the best linear approximation

f(a+h)=f(a)+f′(a) h+o(h)f(a + h) = f(a) + f'(a)\,h + o(h)

The tangent line is the unique line whose error vanishes faster than hh. This view generalizes to many variables, where it becomes the Jacobian and gradient (A3.2). It also explains when the derivative fails to exist: ∣x∣\lvert x\rvert at 0 has a kink, so no single line fits from both sides.

Derivatives on a computer: finite differences

Formula Truncation error Best hh (float64) Best accuracy
forward f(x+h)−f(x)h\frac{f(x+h) - f(x)}h O(h)O(h) ∼ε≈10−8\sim\sqrt{\varepsilon}\approx10^{-8} ~8 digits
central f(x+h)−f(x−h)2h\frac{f(x+h) - f(x-h)}{2h} O(h2)O(h^2) ∼ε1/3≈10−5\sim\varepsilon^{1/3}\approx10^{-5} ~11 digits

Making hh smaller is not always better. The rounding error grows like ε/h\varepsilon/h, so the total error has a V shape.

🐍 Exercise 1: the V-shaped error of finite differences
Implement forward and central differences, sweep h from 10⁻¹ to 10⁻¹⁴ for sin at x = 1, and locate the best h for each.
📝 Quick check (Level 2)
0/3 answered
  1. 1. ((3x + 1)⁴)′ at x = 0?
  2. 2. (x/(x + 1))′ at x = 1?
  3. 3. The central difference is exact for which functions?

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Proofs of the rules

Differentiable ⇒ continuous. f(a+h)−f(a)=h⋅f(a+h)−f(a)h→0⋅f′(a)=0f(a+h) - f(a) = h\cdot\frac{f(a+h) - f(a)}h\to0\cdot f'(a) = 0. ∎ The converse is false: ∣x∣\lvert x\rvert, and even functions that are continuous everywhere but differentiable nowhere (Weierstrass, 1872).

Product rule. Add and subtract f(a+h)g(a)f(a+h)g(a):

f(a+h)g(a+h)−f(a)g(a)h=f(a+h)g(a+h)−g(a)h+g(a)f(a+h)−f(a)h→fg′+f′g\frac{f(a+h)g(a+h) - f(a)g(a)}h = f(a+h)\frac{g(a+h) - g(a)}h + g(a)\frac{f(a+h) - f(a)}h\to fg' + f'g

This uses the continuity of ff at aa. ∎

Chain rule (careful version). Write g(a+h)=g(a)+kg(a+h) = g(a) + k with k=g′(a)h+o(h)k = g'(a)h + o(h). Define ϕ(k)=f(g(a)+k)−f(g(a))k\phi(k) = \frac{f(g(a)+k) - f(g(a))}k for k≠0k\ne0 and ϕ(0)=f′(g(a))\phi(0) = f'(g(a)), which is continuous at 0. Then f(g(a+h))−f(g(a))=ϕ(k) kf(g(a+h)) - f(g(a)) = \phi(k)\,k always holds (even when k=0k = 0), so dividing by hh gives ϕ(k)kh→f′(g(a))g′(a)\phi(k)\frac kh\to f'(g(a))g'(a). ∎ The naive proof, “multiply and divide by kk”, fails when k=0k = 0 for small hh.

Strange but true

f(x)=x2sin⁡(1/x)f(x) = x^2\sin(1/x) with f(0)=0f(0) = 0 is differentiable everywhere, with f′(0)=lim⁡hsin⁡(1/h)=0f'(0) = \lim h\sin(1/h) = 0. But f′(x)=2xsin⁡(1/x)−cos⁡(1/x)f'(x) = 2x\sin(1/x) - \cos(1/x) has no limit at 0. A derivative can exist without being continuous. Even so, derivatives always have the intermediate-value property (Darboux’s theorem).

Exercise 3.1: Derive the quotient rule from the product and chain rules

Write f/g=f⋅g−1f/g = f\cdot g^{-1}. The chain rule gives (g−1)′=−g−2g′(g^{-1})' = -g^{-2}g'. The product rule then gives f′g−1−fg−2g′=f′g−fg′g2f'g^{-1} - fg^{-2}g' = \frac{f'g - fg'}{g^2}.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Is |x| differentiable at 0?
  2. 2. f(g(x)) with g(1) = 2, g′(1) = 3, f′(2) = 5. Then (f∘g)′(1) = ?
  3. 3. Differentiable at a implies…

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Automatic differentiation: exact derivatives by program

Forward mode (dual numbers). Compute with a+bεa + b\varepsilon, where ε2=0\varepsilon^2 = 0. Then f(x+ε)=f(x)+f′(x)εf(x + \varepsilon) = f(x) + f'(x)\varepsilon, because the arithmetic rules are the product, quotient and chain rules. The result is exact to machine precision, with no step size. The cost is one pass per input direction.

Reverse mode (backpropagation). Record the computation graph, then apply the chain rule from the output backwards. One backward pass gives the derivative of a scalar loss with respect to all inputs, at a small constant multiple of the forward cost (Linnainmaa, 1970; Rumelhart, Hinton and Williams, 1986; Griewank and Walther, 2008). This is why we can train networks with billions of parameters.

🐍 Exercise 2 (research): forward-mode autodiff with dual numbers
Implement a Dual class (+, −, ×, ÷, powers) and dual-aware sin and exp. Differentiate sin(x²)/(1 + x²) exactly, and compare with a central difference.

Derivatives in science and engineering

  • Complex-step differentiation computes f′(x)≈Im⁡f(x+ih)/hf'(x)\approx\operatorname{Im}f(x + ih)/h. It has no subtraction, so h=10−20h = 10^{-20} works and gives machine precision (Squire and Trapp, 1998). It became a standard tool in aerospace design sensitivity analysis (Martins, Sturdza and Alonso, 2003).
  • Robotics and control: velocities are derivatives of poses, accelerations of velocities. PID controllers use the derivative term to anticipate error. Numerically differentiating noisy encoder data needs filtering, because differentiation amplifies high-frequency noise.
  • Differentiable programming: physics simulators (Brax, MuJoCo MJX), renderers and ODE solvers are made differentiable so robot policies and designs can be optimized by gradient (Degrave et al., 2019).
  • Gradient checking: comparing autodiff with central differences is the standard unit test for new layers. Practice Code 5 does exactly this.

References

  1. I. Newton (1671/1736). Method of Fluxions; G. W. Leibniz (1684). “Nova methodus pro maximis et minimis.” Acta Eruditorum.
  2. K. Weierstrass (1872). Lecture on a continuous, nowhere-differentiable function (published by du Bois-Reymond, 1875).
  3. S. Linnainmaa (1970). The representation of the cumulative rounding error of an algorithm as a Taylor expansion of the local rounding errors. MSc thesis, University of Helsinki. (Reverse-mode AD.)
  4. D. Rumelhart, G. Hinton, R. Williams (1986). “Learning representations by back-propagating errors.” Nature, 323.
  5. W. Squire, G. Trapp (1998). “Using complex variables to estimate derivatives of real functions.” SIAM Review, 40(1).
  6. J. Martins, P. Sturdza, J. Alonso (2003). “The complex-step derivative approximation.” ACM Transactions on Mathematical Software, 29(3).
  7. A. Griewank, A. Walther (2008). Evaluating Derivatives: Principles and Techniques of Algorithmic Differentiation, 2nd ed. SIAM.
  8. A. G. Baydin, B. Pearlmutter, A. Radul, J. Siskind (2018). “Automatic differentiation in machine learning: a survey.” JMLR, 18.
  9. J. Degrave, M. Hermans, J. Dambre, F. wyffels (2019). “A differentiable physics engine for deep learning in robotics.” Frontiers in Neurorobotics, 13.