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

Derivatives of Common Functions (exp, log, trig, sigmoid, tanh, softplus)

The derivatives every engineer and ML researcher uses daily. Why eˣ is its own slope, how log turns products into sums, and how the shapes of activation derivatives decide whether a deep network can learn at all.

Level 0: Foundation

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

A function that grows at its own size

Some quantities grow faster the bigger they get: a bacteria colony, a snowball rolling downhill, money earning interest on interest. The special function exe^x grows at a rate exactly equal to its current size. That one fact makes it the star of calculus.

The squashing function

Neural networks use an S-shaped activation function like the sigmoid. It squashes any number into the range between 0 and 1, like a dimmer switch. Its slope tells the network how much a small nudge to the input changes the output. If the slope is tiny, learning stalls.

Activation functions and their derivatives
f(x) = 0.5000 · f′(x) = 0.2500 · largest |f′| on [−4, 4] = 0.250
gradient factor through 10 layers at this x, |f′(x)|^L = 9.54e-7 → vanishing gradient
Blue = f, dashed orange = f′. The sigmoid's derivative never exceeds ¼, so 10 layers give at most ¼¹⁰ ≈ 10⁻⁶. ReLU's derivative is exactly 1 for x > 0. (Real networks also multiply by weights; see Exercise 2.)
Why engineers care

Exponentials describe radioactive decay in a spacecraft’s power source, a battery discharging, and a robot joint’s motion settling to rest. Sines and cosines describe every vibration and orbit. Knowing their slopes lets engineers predict and control all of these.

📝 Quick check (Level 0)
0/3 answered
  1. 1. If eˣ is 5 at some point, how fast is it growing there?
  2. 2. What is the sigmoid's output at 0?
  3. 3. Can the sigmoid ever output more than 1?

Level 1: Beginner

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

The essential table

f(x)f(x) f′(x)f'(x)
exe^x exe^x
axa^x axln⁡aa^x\ln a
ln⁡x\ln x 1/x1/x
sin⁡x\sin x cos⁡x\cos x
cos⁡x\cos x −sin⁡x-\sin x
tan⁡x\tan x 1/cos⁡2x1/\cos^2x
arctan⁡x\arctan x 1/(1+x2)1/(1+x^2)

Combine these with the chain rule (A3.1-2): (e3x)′=3e3x(e^{3x})' = 3e^{3x}, (sin⁡ωt)′=ωcos⁡ωt(\sin\omega t)' = \omega\cos\omega t, and (ln⁡(x2+1))′=2xx2+1(\ln(x^2+1))' = \frac{2x}{x^2+1}.

📝 Quick check (Level 1)
0/3 answered
  1. 1. (ln x)′ at x = 4?
  2. 2. (sin x)′ at 0?
  3. 3. (e^(3x))′ = ?

Level 2: Intermediate

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

Activation functions and their derivatives

Activation f(x)f(x) f′(x)f'(x) max ∣f′∣\lvert f'\rvert
sigmoid σ(x)=11+e−x\sigma(x) = \frac1{1+e^{-x}} σ(1−σ)\sigma(1-\sigma) 14\tfrac14
tanh tanh⁡x\tanh x 1−tanh⁡2x1 - \tanh^2x 1
ReLU max⁡(0,x)\max(0,x) 1[x>0]\mathbf 1[x>0] 1
softplus ln⁡(1+ex)\ln(1 + e^x) σ(x)\sigma(x) 1
SiLU / swish xσ(x)x\sigma(x) σ+xσ(1−σ)\sigma + x\sigma(1-\sigma) ≈ 1.1
GELU xΦ(x)x\Phi(x) Φ(x)+xφ(x)\Phi(x) + x\varphi(x) ≈ 1.13

The derivatives are written in terms of the function itself (σ′=σ(1−σ)\sigma' = \sigma(1-\sigma)). Backprop can therefore reuse the value saved in the forward pass, which costs no extra exponentials.

Vanishing gradients

Backprop multiplies one activation derivative per layer (A3.1-2). With the sigmoid, each factor is at most 14\frac14, so 10 layers give at most 4−10≈10−64^{-10}\approx10^{-6}. This vanishing gradient problem (Hochreiter, 1991; Bengio, Simard and Frasconi, 1994) is why modern deep networks use ReLU-family activations, careful initialization and residual connections.

🐍 Exercise 1: activation derivatives
Implement sigmoid, tanh, softplus, SiLU, exp and sin with their derivatives. Verify them against central differences, and confirm σ′ peaks at ¼.

The logarithmic derivative

(ln⁡f)′=f′f(\ln f)' = \frac{f'}{f}

It turns products into sums, which is how we differentiate xxx^x (giving xx(ln⁡x+1)x^x(\ln x + 1)). In statistics, it is the score function ∇θln⁡p(x;θ)\nabla_\theta\ln p(x;\theta), central to maximum likelihood and policy gradients.

📝 Quick check (Level 2)
0/3 answered
  1. 1. σ′(0) = ?
  2. 2. softplus′(x) equals…
  3. 3. If tanh x = 0.6, then tanh′(x) = ?

Level 3: Advanced

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

Where the formulas come from

Exponential. ex+h−exh=ex⋅eh−1h→ex\frac{e^{x+h} - e^x}h = e^x\cdot\frac{e^h - 1}h\to e^x, because lim⁡h→0eh−1h=1\lim_{h\to0}\frac{e^h-1}h = 1. That limit is one way to define ee.

Sine. sin⁡(x+h)−sin⁡xh=sin⁡xcos⁡h−1h+cos⁡xsin⁡hh→cos⁡x\frac{\sin(x+h) - \sin x}h = \sin x\frac{\cos h - 1}h + \cos x\frac{\sin h}h\to\cos x, using the two limits from A3.1-1.

Logarithm. ln⁡\ln is the inverse of exp⁡\exp. By the inverse-function rule, (ln⁡)′(y)=1/exp⁡′(ln⁡y)=1/y(\ln)'(y) = 1/\exp'(\ln y) = 1/y.

Sigmoid. σ=(1+e−x)−1\sigma = (1 + e^{-x})^{-1}, so σ′=e−x(1+e−x)−2=σ⋅e−x1+e−x=σ(1−σ)\sigma' = e^{-x}(1+e^{-x})^{-2} = \sigma\cdot\frac{e^{-x}}{1+e^{-x}} = \sigma(1 - \sigma).

tanh. tanh⁡x=2σ(2x)−1\tanh x = 2\sigma(2x) - 1, so tanh⁡′=4σ(2x)(1−σ(2x))=1−tanh⁡2x\tanh' = 4\sigma(2x)(1 - \sigma(2x)) = 1 - \tanh^2x.

Uniqueness of the exponential

Theorem

The only differentiable ff with f′=ff' = f and f(0)=1f(0) = 1 is exe^x.

Proof. Let g=fe−xg = fe^{-x}. Then g′=f′e−x−fe−x=0g' = f'e^{-x} - fe^{-x} = 0, so gg is constant (by the mean value theorem, A3.1-4), and g(0)=1g(0) = 1. ∎ This is why eλte^{\lambda t} solves every linear ODE y˙=λy\dot y = \lambda y, the scalar case of A2.4-3.

Exercise 3.1: Differentiate xˣ

Let y=xxy = x^x, so ln⁡y=xln⁡x\ln y = x\ln x. Differentiating gives y′/y=ln⁡x+1y'/y = \ln x + 1, so y′=xx(ln⁡x+1)y' = x^x(\ln x + 1). At x=2x = 2, this is 4(ln⁡2+1)≈6.77264(\ln2 + 1)\approx6.7726.

📝 Quick check (Level 3)
0/3 answered
  1. 1. (eˣ)′ = eˣ follows from which limit?
  2. 2. (xˣ)′ at x = 1?
  3. 3. (arctan x)′ at x = 1?

Level 4: Expert

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

Depth, derivatives and trainability

🐍 Exercise 2 (research): vanishing gradients through depth
Backpropagate through random width-64 networks of depth 5, 20 and 50, with sigmoid (Xavier), tanh (Xavier) and ReLU (He init). Measure the input-gradient norm: sigmoid's collapses to about 10⁻³¹.
  • Activation design. ReLU fixed the vanishing derivative for positive inputs (Nair and Hinton, 2010; Glorot, Bordes and Bengio, 2011), but has “dead” units with derivative 0. Smooth variants (softplus, SiLU/swish, GELU; Hendrycks and Gimpel, 2016; Ramachandran, Zoph and Le, 2017) keep nonzero gradients, and GELU/SiLU are standard in transformers.
  • Initialization. Xavier/Glorot (2010) and He et al. (2015) choose weight scales so that, combined with the activation derivative, signal and gradient norms stay roughly constant through depth. Exercise 2 shows this with He-initialized ReLU.
  • Numerical stability. ln⁡(1+ex)\ln(1 + e^x) overflows for large xx, and e−xe^{-x} overflows in the sigmoid for very negative xx. Libraries use log1p, exp(-|x|) and the log-sum-exp trick (Practice Code 4). Softmax followed by cross-entropy has the beautifully simple gradient p−y\mathbf p - \mathbf y (Practice Code 3).
  • The log-derivative trick in robot learning. ∇θEx∼pθ[f(x)]=E[f(x)∇θln⁡pθ(x)]\nabla_\theta\mathbb E_{x\sim p_\theta}[f(x)] = \mathbb E[f(x)\nabla_\theta\ln p_\theta(x)] (REINFORCE; Williams, 1992). It lets a robot improve a policy from rewards alone, even when the reward (task success) can’t be differentiated. The price is high variance (Practice Code 5), which motivates baselines, actor-critic methods and PPO.

References

  1. L. Euler (1748). Introductio in analysin infinitorum. (The exponential and its series.)
  2. S. Hochreiter (1991). Untersuchungen zu dynamischen neuronalen Netzen. Diploma thesis, TU München.
  3. Y. Bengio, P. Simard, P. Frasconi (1994). “Learning long-term dependencies with gradient descent is difficult.” IEEE Transactions on Neural Networks, 5(2).
  4. R. Williams (1992). “Simple statistical gradient-following algorithms for connectionist reinforcement learning.” Machine Learning, 8.
  5. X. Glorot, Y. Bengio (2010). “Understanding the difficulty of training deep feedforward neural networks.” AISTATS.
  6. V. Nair, G. Hinton (2010). “Rectified linear units improve restricted Boltzmann machines.” ICML.
  7. K. He, X. Zhang, S. Ren, J. Sun (2015). “Delving deep into rectifiers: surpassing human-level performance on ImageNet classification.” ICCV.
  8. D. Hendrycks, K. Gimpel (2016). “Gaussian error linear units (GELUs).” arXiv:1606.08415.
  9. P. Ramachandran, B. Zoph, Q. Le (2017). “Searching for activation functions.” arXiv:1710.05941.