Measuring Change: Derivatives

Derivatives in differential calculus, explained for people who survived mathematics.

Fundamentals 13 min Intermediate May 11, 2026

When a neural network trains, it adjusts millions of weights — but how does it know WHICH direction to adjust them? The answer: It computes the derivative of the loss function. The derivative measures how much the error changes when a weight changes by a tiny amount.

Positive derivative: error increases — decrease the weight. Negative derivative: error decreases — increase the weight. This simple sign-check, repeated billions of times, is how AI learns.

Slope: From Average to Instantaneous

Derivative

AnalogyDefinition
Your car drives through mountains. The average speed over 100 km (100 km / 2 h = 50 km/h) is the average slope of the distance-time curve — the secant. The speedometer shows the speed RIGHT NOW — the tangent slope, the derivative.

Example

A real speedometer measures over a small but finite time window (milliseconds). The mathematical derivative idealizes this: h goes to exactly zero — physically impossible, but mathematically precise.

Let us see how the limit works. For f(x) = x\u00B2 at x = 3: the exact derivative is f'(3) = 6. Watch how the approximation converges:

1
h = 1 [f(4) - f(3)] / 1 = [16 - 9] / 1 = 7.0
2
h = 0.1 [f(3.1) - f(3)] / 0.1 = [9.61 - 9] / 0.1 = 6.1
3
h = 0.01 [f(3.01) - f(3)] / 0.01 = [9.0601 - 9] / 0.01 = 6.01
4
h \u2192 0 Limit = 6.0 — the exact derivative f'(3) = 2\u00B73 = 6
def f(x):
    return x ** 2

x = 3
for h in [1, 0.1, 0.01, 0.001, 0.0001]:
    slope = (f(x + h) - f(x)) / h
    print(f"h = {h:8.4f}  ->  slope = {slope:.4f}")

# h =   1.0000  ->  slope = 7.0000
# h =   0.1000  ->  slope = 6.1000
# h =   0.0100  ->  slope = 6.0100
# h =   0.0010  ->  slope = 6.0010
# h =   0.0001  ->  slope = 6.0001  (converges to 6)

Misconception: The Derivative IS the Slope

Almost: The derivative is a FUNCTION f'(x) that gives the slope at every point. At a specific point x = 3, f'(3) = 6 is the slope there. The derivative maps every input to its corresponding slope.

The loss function L depends on weights w. The derivative dL/dw tells you: "If I increase this weight by a tiny amount, does the error go up or down — and by how much?" This is exactly the information gradient descent uses.

Differentiation Rules: The Toolkit

Instead of computing the limit by hand every time, four rules cover almost all AI-relevant derivatives. Like recipes: you grab ready-made flour instead of grinding grain.

Power Rule
(xⁿ)' = n · xⁿ⁻¹
Constant Rule
c' = 0
Sum Rule
(f + g)' = f' + g'
Scaling Rule
(c · f)' = c · f'

Example: Loss Function L(w) = (w-3)\u00B2 + 1

Expanded: L(w) = w\u00B2 - 6w + 10. Apply rules: (w\u00B2)' = 2w (power), (-6w)' = -6 (scaling), (10)' = 0 (constant). Sum rule: L'(w) = 2w - 6.

def L(w):
    return (w - 3) ** 2 + 1

def L_prime(w):
    return 2 * w - 6

for w in [0, 1, 2, 3, 4, 5]:
    print(f"w={w}  L(w)={L(w):5.1f}  L'(w)={L_prime(w):+.1f}")

# w=0  L(w)= 10.0  L'(w)=-6.0   (falling -> increase w)
# w=1  L(w)=  5.0  L'(w)=-4.0   (falling -> increase w)
# w=2  L(w)=  2.0  L'(w)=-2.0   (falling -> increase w)
# w=3  L(w)=  1.0  L'(w)=+0.0   (flat -> minimum!)
# w=4  L(w)=  2.0  L'(w)=+2.0   (rising -> decrease w)
# w=5  L(w)=  5.0  L'(w)=+4.0   (rising -> decrease w)
L'(w) > 0

Loss increases with larger w

L'(w) < 0

Loss decreases with larger w

+4
L'(5) = +4: Loss rises steeply
0
L'(3) = 0: Minimum reached
-4
L'(1) = -4: Loss falls steeply

Deep Dive: The Notation Zoo

The derivative has many notations: f'(x) (Lagrange), dy/dx (Leibniz), df/dx (explicit), \u2202f/\u2202x (partial derivative). All mean the same thing for functions of one variable. You will need the \u2202 notation starting with the next article (Partial Derivatives), when functions depend on multiple variables.

Deep Dive: Autograd — Why You Don't Compute Derivatives by Hand

PyTorch and TensorFlow compute all derivatives automatically via Autograd. You define a function, call .backward(), and the framework delivers the gradients. Yet understanding the concept is essential: when training does not converge, you need to know WHY the gradient is too large, too small, or zero.

import torch

# Weight with gradient tracking
w = torch.tensor([5.0], requires_grad=True)

# Compute loss
loss = (w - 3) ** 2 + 1  # L(5) = 5

# Compute gradient automatically
loss.backward()
print(w.grad)  # tensor([4.]) -> L'(5) = 4

Interactive: Compare Function Growth

The power rule reveals: the higher the exponent, the faster the function grows. Move the slider and observe how f(x) = x² and f(x) = x³ pull away from f(x) = x as x increases. The derivative measures exactly this difference in growth — f'(x) = 2x for x² grows twice as fast as f'(x) = 1 for x.

150
f(x) = 11
f(x) = x100
f(x) = x²10.000
f(x) = x³1.000.000
Moderate Input

At n=100, the difference becomes visible: O(n²) requires 10.000 operations, while O(n) needs only 100. O(log n) needs just 6.6 — that's 15x less than O(n).

Ratio to O(n)

ComplexityOperationsFactor vs. O(n)
f(x) = 11100x faster
f(x) = x1001x (Reference)
f(x) = x²10.000100x slower
f(x) = x³1.000.00010000x slower

Finding Minima: Why Derivatives Power AI

You now know how to compute derivatives and what their sign means. The decisive question: where is the error smallest?

Function Minimum

AnalogyDefinition
You stand on a hill in dense fog and want to reach the valley (minimum). You cannot see the valley, but you can feel which direction the ground slopes downward under your feet (= derivative). You walk in the direction of steepest descent. Step by step, you approach the valley.

Example

A real hill has maybe 3 valleys. A neural network's loss landscape has millions of dimensions with countless valleys of varying depth — unimaginably complex.

Misconception: f'(x) = 0 Always Means Minimum

Not necessarily. f'(x) = 0 only means the tangent is horizontal — the terrain is flat here. It could be a valley (minimum), a hilltop (maximum), or a saddle point. In deep neural networks, saddle points are more common than true local minima — they can slow down or stall training.

Preview: Gradient Descent

The simplest form of training: start at a random weight, compute the derivative, take a small step in the opposite direction. Repeat.

Gradient Descent Rule
w_new = w_old - learning_rate × L'(w_old)
# Simplest Gradient Descent
def L(w):
    return (w - 3) ** 2 + 1

def L_prime(w):
    return 2 * w - 6

w = 0.0
lr = 0.1  # learning rate

for step in range(20):
    grad = L_prime(w)
    w = w - lr * grad
    if step % 5 == 0:
        print(f"Step {step:2d}: w={w:.4f}  L={L(w):.4f}  L'={grad:+.4f}")

# Step  0: w=0.6000  L=6.7600  L'=-6.0000
# Step  5: w=2.8024  L=1.0390  L'=-0.3277
# Step 10: w=2.9893  L=1.0001  L'=-0.0178
# Step 15: w=2.9994  L=1.0000  L'=-0.0010
# -> w converges to 3.0 (the true minimum)

Training a neural network means: minimizing the loss function by adjusting weights. The derivative of loss with respect to each weight points toward the minimum. Gradient descent formalizes this: w_new = w_old - learning_rate \u00D7 gradient. The next articles (Gradient, Chain Rule) complete the picture for real networks.

Key Takeaways

  • The derivative f'(x) gives the instantaneous rate of change — how steeply the function rises or falls at one specific point. The limit definition (h \u2192 0) turns average slope into exact slope.
  • Four simple rules (power, constant, sum, scaling) are enough to differentiate any polynomial. In AI, the derivative of the loss function tells you whether to increase or decrease a weight.
  • Setting f'(x) = 0 finds candidates for extrema — but not every zero is a minimum. It could also be a maximum or a saddle point. Real neural network loss landscapes have many local minima and saddle points — not just one clean valley.

Learning Goals

  • Given f(x) = 3x\u00B2 + 2, what is f'(4)?
  • For L(w) = w\u00B2 - 4w + 5, where is the minimum?
  • Why doesn't f'(x) = 0 guarantee a minimum?

Quiz: Derivatives

Question 1 / 4
Not completed

What does the sign of the derivative L'(w) tell you about the loss function?

Select one answer
Answer Key: 1) B · 2) C · 3) B · 4) B