Derivative

Level FundamentalDifficulty ★★★★★Concept⌖ Open in the map

What is it?

f′(a)f'(a) is the instantaneous rate of change of ff at aa: the slope of the tangent line to the graph, defined as the limit of slopes of secant lines.

Why does it exist?

Average rates are easy: distance over time. But "how fast is the car going now?" asks for a rate over an interval of length zero — 0/00/0. Newton needed it for mechanics, Leibniz for tangents; the derivative is their common answer, made rigorous by the limit. It solves the problem of quantifying local change.

Intuition

Geometrically: zoom in on a smooth curve and it looks like a straight line; the derivative is that line's slope. Physically: if s(t)s(t) is position, s′(t)s'(t) is velocity and s′′(t)s''(t) acceleration. As sensitivity: f(a+h)≈f(a)+f′(a) hf(a + h) \approx f(a) + f'(a)\,h — the output moves f′(a)f'(a) times as much as the input, for small nudges. That last reading is the one machine learning uses: the derivative of the loss with respect to a weight says which way to move the weight.

Formal definition

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

when the limit exists (then ff is differentiable at aa). The function f′:x↦f′(x)f' : x \mapsto f'(x) is the derivative of ff; Leibniz writes it dfdx\frac{\dd f}{\dd x}.

Formulas

f′(a)=lim⁡h→0f(a+h)−f(a)hf'(a) = \lim_{h\to 0}\frac{f(a + h) - f(a)}{h}
definition
y=f(a)+f′(a) (x−a)y = f(a) + f'(a)\,(x - a)
tangent line
(xn)′=nxn−1,(ex)′=ex,(ln⁡x)′=1x,(sin⁡x)′=cos⁡x(x^n)' = n x^{n-1}, \quad (e^x)' = e^x, \quad (\ln x)' = \tfrac1x, \quad (\sin x)' = \cos x
the basic table

How is it computed?

Three ways, and all three are used by software:

  1. Symbolically, applying rules (power, product, quotient, chain) to a formula — what a CAS does.
  2. Numerically, with a finite difference f(a+h)−f(a−h)2h\frac{f(a+h) - f(a - h)}{2h} — easy but inexact (truncation error for large hh, rounding error for tiny hh).
  3. Automatically: propagate exact derivatives through each elementary operation of a program — automatic differentiation, the engine of PyTorch and JAX.

Example

f(x)=x2f(x) = x^2 at a=3a = 3: (3+h)2−9h=6h+h2h=6+h→6\frac{(3 + h)^2 - 9}{h} = \frac{6h + h^2}{h} = 6 + h \to 6. So f′(3)=6f'(3) = 6 and the tangent is y=9+6(x−3)y = 9 + 6(x - 3). In code, the central difference with h=10−5h = 10^{-5} gives 6.000000000039…6.000000000039…, while h=10−15h = 10^{-15} gives garbage — the subtraction cancels all the digits.

Interactive visualization

f tangent, slope f′(a) secant through a and a + h— Drag the point. As h → 0 the secant becomes the tangent: that limit is the derivative.

Why does it matter?

Optimization is following derivatives downhill; simulation is integrating them forward in time; rendering needs them to orient surfaces; control uses them to anticipate. Modern deep learning is, at its computational core, an extremely efficient machine for computing derivatives of one number (the loss) with respect to billions of inputs (the weights).

Where it shows up in computing

  • Kinematics: position, velocity, acceleration★★★★★fundamentalRobotics and control

    Velocity is the derivative of position, acceleration the derivative of velocity.

  • Physics engines★★★★★fundamentalPhysics and simulation

    Engines store positions and their derivatives (velocities) and advance them frame by frame.

  • PID control★★★★★frequentRobotics and control

    The D term reacts to the derivative of the error, anticipating where the system is going.

  • Image processing and computer vision★★★★★frequentSignals, media and vision

    Edges are where intensity changes fast: detectors (Sobel, Canny) estimate derivatives of the image.

  • Symbolic computation (CAS)★★★★★frequentScientific computing and algorithms

    Symbolic differentiation is the textbook example of term rewriting on expression trees.

Where it shows up in AI

  • Gradient descent★★★★★fundamentalAI and machine learning

    Each step moves the parameter against the derivative of the loss: w←w−η L′(w)w \leftarrow w - \eta\,L'(w).

  • Automatic differentiation★★★★★fundamentalAI and machine learning

    AD computes exact derivatives of programs by propagating them through each operation.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

Exercises

1Computation

Using the definition, compute f′(x)f'(x) for f(x)=1xf(x) = \frac1x.

Solution

1h(1x+h−1x)=−hh x(x+h)=−1x(x+h)→−1x2\frac{1}{h}\left(\frac{1}{x+h} - \frac1x\right) = \frac{-h}{h\,x(x+h)} = \frac{-1}{x(x+h)} \to -\frac{1}{x^2}.

2Graphical

Sketch f(x)=x3−3xf(x) = x^3 - 3x and, below it, f′f'. Where is f′f' zero, positive, negative?

Solution

f′(x)=3x2−3f'(x) = 3x^2 - 3: zero at x=±1x = \pm1 (a local max at −1-1, a local min at 11), negative on (−1,1)(-1,1) where ff decreases, positive outside.

3AI

A one-parameter model has loss L(w)=(w−3)2+1L(w) = (w - 3)^2 + 1. Starting at w0=0w_0 = 0 with learning rate η=0.1\eta = 0.1, compute two steps of gradient descent.

Solution

L′(w)=2(w−3)L'(w) = 2(w - 3). w1=0−0.1⋅(−6)=0.6w_1 = 0 - 0.1\cdot(-6) = 0.6; w2=0.6−0.1⋅(−4.8)=1.08w_2 = 0.6 - 0.1\cdot(-4.8) = 1.08. Each step closes 20% of the gap to the minimum w=3w = 3.

↑ ↓ to navigate · ↵ · Esc