Skip to content
AriadneTechnology

The Outer Ring · Chamber 2 of 9

Derivatives: The Best Local Line

The derivative as the best linear approximation: prove the rules, then differentiate every activation in the zoo.

40 min 60 XP + 9 questions + 1 challengeMathVideoPapersProofsCodeLab

In this chamber you will

  • Read a derivative as the best linear approximation to a function
  • Prove the product rule and use the rules of differentiation fluently
  • Differentiate sigmoid, tanh, softplus and GELU, and handle ReLU's kink
  • Estimate derivatives numerically with central differences
DiscoverLearnRead beyondPapers & lecturesYour turn

An activation function changes both the values moving forward through a network and the slopes moving backward. GELU makes a useful example: its formula is short, but understanding its slope takes the product rule.

Spotted in the wild

GELU⁡(x)=xΦ(x)\operatorname{GELU}(x)=x\Phi(x)
Gaussian Error Linear Units (GELUs)
DiscoverLearnRead beyondPapers & lecturesYour turn
Symbols for this chamber
  • f′(a)f'(a)“f prime at a”
    Instantaneous slope at aa.
  • dfdx\frac{df}{dx}“d f by d x”
    The derivative of a scalar function.
  • o(h)o(h)“little o of h”
    An error negligible compared with ∣h∣|h| as h→0h\to0.
  • σ(x)\sigma(x)“sigmoid of x”
    The logistic activation.
  • ϕ(x)\phi(x)“phi of x”
    Standard normal density.
  • Φ(x)\Phi(x)“capital phi of x”
    Standard normal cumulative distribution.

The best local line

A derivative is the limit

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

Equivalently, f(a+h)=f(a)+f′(a)h+o(h)f(a+h)=f(a)+f'(a)h+o(h): after subtracting the proposed line, the remaining error divided by ∣h∣|h| tends to zero. This is why the tangent predicts the effect of a small parameter change.

For f(x)=x2f(x)=x^2, the difference quotient at aa is 2a+h2a+h, so f′(a)=2af'(a)=2a. Near a=3a=3, the prediction for f(3.01)f(3.01) is 9+6(0.01)=9.069+6(0.01)=9.06. The exact value is 9.06019.0601; the error is the omitted h2h^2.

Quick check +20 XP

What is the derivative of x2x^2 at x=3x=3?

Rules that save work

Linearity gives (af+bg)′=af′+bg′(af+bg)'=af'+bg'. The product rule is (fg)′=f′g+fg′(fg)'=f'g+fg'. To prove it, add and subtract f(a+h)g(a)f(a+h)g(a) in the numerator:

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.\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.

Differentiability implies continuity, so taking the limit gives the rule. A product's derivative is generally not the product of the derivatives. The quotient rule, when g≠0g\ne0, is (f/g)′=(f′g−fg′)/g2(f/g)'=(f'g-fg')/g^2.

Useful building blocks are (xn)′=nxn−1(x^n)'=nx^{n-1}, (ex)′=ex(e^x)'=e^x, (ln⁡x)′=1/x(\ln x)'=1/x for x>0x>0, and (sin⁡x)′=cos⁡x(\sin x)'=\cos x. Differentiating a composition will be the next chamber's main task.

Quick check +20 XP

What is (xex)′(x e^x)'?

The activation toolbox

Let s=σ(x)=1/(1+e−x)s=\sigma(x)=1/(1+e^{-x}). Differentiating the quotient gives σ′(x)=s(1−s)\sigma'(x)=s(1-s). Since s(1−s)=1/4−(s−1/2)2s(1-s)=1/4-(s-1/2)^2, its maximum is 1/41/4 at x=0x=0.

ActivationDerivativeWhat to watch
tanh⁡x\tanh x1−tanh⁡2x1-\tanh^2xMaximum 1 at zero; saturated tails have small slopes
ln⁡(1+ex)\ln(1+e^x), softplusσ(x)\sigma(x)Positive slope tending to 1
max⁡(0,x)\max(0,x), ReLU0 for x<0x<0, 1 for x>0x>0No ordinary derivative at zero
xΦ(x)x\Phi(x), GELUΦ(x)+xϕ(x)\Phi(x)+x\phi(x)ϕ(x)=e−x2/2/2π\phi(x)=e^{-x^2/2}/\sqrt{2\pi}

ReLU implementations choose a backward value at the kink, often zero. That convention does not turn the corner into a differentiable point. GELU's derivative can exceed one and can be negative: smoothness does not imply monotonicity.

The lab also includes arctan⁡x\arctan x, a bounded smooth function with derivative 1/(1+x2)1/(1+x^2). Its maximum slope is 1 at zero.

Check a derivative numerically

The central difference is

Dhf(x)=f(x+h)−f(x−h)2h.D_hf(x)=\frac{f(x+h)-f(x-h)}{2h}.

For a sufficiently smooth function its truncation error is O(h2)O(h^2). Forward differences usually have O(h)O(h) error. Floating-point subtraction eventually dominates when hh becomes very small; compare several step sizes. At a kink, central differences can average two incompatible one-sided slopes. For ∣x∣|x| at zero they always give zero, although the derivative does not exist.

Quick check +20 XP

A central difference for ∣x∣|x| at zero is zero. What does that prove?

DiscoverLearnRead beyondPapers & lecturesYour turn

Read beyond

Book · free online · ~20 min

Calculus, Volume 1

OpenStax · Sections 3.1–3.3: derivatives and rules

Derive the slope of a polynomial from the difference quotient.

Book · free online · ~20 min

Mathematics for Machine Learning

Deisenroth, Faisal & Ong · Section 5.1: univariate differentiation

Compare derivatives, finite differences and local linear approximation.

Book · free online · ~20 min

The Matrix Calculus You Need For Deep Learning

Parr & Howard · Scalar derivative rules

Check which expressions are sums, products or compositions before differentiating.

DiscoverLearnRead beyondPapers & lecturesYour turn

Read the equation in context

Gaussian Error Linear Units (GELUs)Dan Hendrycks & Kevin Gimpel · 2016

The paper defines GELU by weighting an input by a Gaussian cumulative probability. Differentiate this exact formula before considering its common approximations. The derivative we obtain below follows from the product rule and the fact that the derivative of a CDF is its density.

Decode the paper · Section 2: GELU definition

Gaussian Error Linear Units (GELUs)

Dan Hendrycks & Kevin Gimpel · 2016

+25 XP
GELU⁡(x)=xΦ(x)\operatorname{GELU}(x)=x\Phi(x)

The paper defines GELU by weighting an input by a Gaussian cumulative probability. Differentiate this exact formula before considering its common approximations. The derivative we obtain below follows from the product rule and the fact that the derivative of a CDF is its density.

xx
Φ(x)\Phi(x)
GELU⁡(x)\operatorname{GELU}(x)

Options

Derivative formulas through geometry3Blue1Brown
DiscoverLearnRead beyondPapers & lecturesYour turn

Your turn

Move along each activation and compare its output with its derivative. Find a point where the derivative reaches its maximum, then submit the slope.

Interactive lab

Tangent tracer

Compare a function with its derivative. For each function, locate the maximum derivative and submit its value.
Sigmoid, its derivative, and the selected tangent-4-2-2-1002142xy
● Activation● Derivative● Tangent● Selected slope

Value

0.8808

Slope

0.1050

Challenge: Slope sleuthFind where three activation functions are steepest, and read off the slope there.+30 XP

Match · Expression ↔ Meaning

Activation slopes

+20 XP
σ′(x)\sigma'(x)
tanh⁡′(x)\tanh'(x)
softplus⁡′(x)\operatorname{softplus}'(x)

Options

Match · Expression ↔ Meaning

Numerical checks

+20 XP
[f(x+h)−f(x)]/h[f(x+h)-f(x)]/h
[f(x+h)−f(x−h)]/(2h)[f(x+h)-f(x-h)]/(2h)
f(x)+hf′(x)f(x)+hf'(x)

Options

Proof puzzle

The product rule

+25 XP

Claim

Prove (fg)′=f′g+fg′(fg)'=f' g+fg' at a point of differentiability.

Tap lines in the order they should appear. Tap a line in your proof to send it back.

Your proof

  1. Pick the first line below.

Available lines

Prove it yourself

A derivative forces continuity

+35 XP

Claim

Prove that differentiability at aa implies continuity at aa.

Preview

Your typeset proof appears here.

Coding problems

Problem 4·Warm-up

Sum the slopes

+20 XP

For f(x)=x3−2xf(x)=x^3-2x, compute ∑k=1100f′(k)\sum_{k=1}^{100}f'(k).

An exact integer (or a fraction like 7/12)

Problem 5·Standard

Central difference accuracy

+35 XP

Estimate the derivative of f(x)=x3f(x)=x^3 at x=2x=2 by central differences with h=2−kh=2^{-k}. Find the smallest integer k≥0k\ge0 for which the exact-arithmetic absolute error is below 10−610^{-6}.

An exact integer (or a fraction like 7/12)

Problem 6·Challenge

Where GELU is steepest

+50 XP

The derivative of GELU is g(x)=Φ(x)+xϕ(x)g(x)=\Phi(x)+x\phi(x). Find the positive xx maximising g(x)g(x), and give 6 decimal places. Use calculus or numerical search.

A number, rounded to 6 decimal places

Key takeaways

  • The derivative is the slope of the best local line.
  • The product rule differentiates one factor at a time.
  • ReLU needs a convention at its kink; smooth activations have different saturation behaviour.
  • Finite differences check a formula, with both truncation and rounding error to consider.

Checkpoint

Prove it to the labyrinth

Answer every question to clear this chamber. First-try answers earn the most XP.

0/6
Question 1 of 6 +20 XP

What is the largest sigmoid derivative?

Question 2 of 6 +20 XP

What is tanh⁡′(0)\tanh'(0)?

Question 3 of 6 +20 XP

What is the derivative of softplus at zero?

Question 4 of 6 +20 XP

What is the derivative of exact GELU at zero?

Question 5 of 6 +20 XP

As a finite-difference step becomes extremely small, what can happen?

Question 6 of 6 +20 XP

Which statement is true?

End of the chamber

Clear this chamber

+60 XPDerivativeLocal Linear ApproximationProduct RuleActivation Derivatives