Product Rule
The product rule tells you how to differentiate a product of two functions. It shows up whenever a model multiplies quantities that both change — for example a time-varying rate times a shrinking susceptible pool. The incidence term in an epidemic model is a product of the changing susceptible and infected counts, so differentiating it — say to build the Jacobian for a stability analysis — requires the product rule.
The rule
A common mistake is to guess ; the derivative of a product is not the product of derivatives.
Intuition
Think of a rectangle with width and height , so its area is . Nudge a little: the width grows by about and the height by about . The area gains two thin strips — one of size (from the wider width) and one of size (from the taller height). The tiny corner is negligible, leaving .
Worked example:
Let and , so and :
At this equals .
Computing it
R
# Symbolic
D(expression(x^2 * exp(x)), "x")
# 2 * x * exp(x) + x^2 * exp(x)
# Numeric check at x = 1
library(numDeriv)
grad(function(x) x^2 * exp(x), 1) # 8.15485 == 3*e
3 * exp(1) # 8.154845
Python
import sympy as sp
x = sp.symbols("x")
sp.diff(x**2 * sp.exp(x), x) # x**2*exp(x) + 2*x*exp(x)
# Numeric check at x = 1
import numpy as np
f = lambda x: x**2 * np.exp(x)
h = 1e-6
(f(1 + h) - f(1 - h)) / (2 * h) # ~8.1548 == 3*e
Julia
using Symbolics
@variables x
Symbolics.derivative(x^2 * exp(x), x) # 2x*exp(x) + (x^2)*exp(x)
using ForwardDiff
ForwardDiff.derivative(x -> x^2 * exp(x), 1.0) # 8.15485 == 3e
Why it matters for statistics
Likelihoods and moment calculations are full of products — a density times a weight, a rate times an exposure, or inside an expected value. The product rule (together with the chain rule) is what lets you differentiate these expressions to derive estimators and their variances.