Products and quotients
Calculate slopes, use the chain rule and distinguish derivatives from partial derivatives.
THE IDEA
Both factors move
Suppose a rectangle has width u(x) and height v(x), and both depend on x. Its area is p = u·v. When x grows by h the width grows by about u′·h and the height by about v′·h. Does the area grow by (u′h)·(v′h)? That is the tempting guess "derivative of a product is the product of derivatives". The picture shows why it is wrong.
The new area splits into the old rectangle, a strip on the right (u′h by v), a strip on top (u by v′h) and a tiny corner (u′h by v′h). Divide the change by h. The strips give v·u′ and u·v′. The corner gives u′v′·h, which melts to 0. So (u·v)′ = u′v + u·v′.
| u = x + 1, v = x/2 + 2 | 2, 2.5 |
|---|---|
| blue strip u′·h·v | 1.2500 |
| orange strip u·v′·h | 0.5000 |
| corner u′h · v′h | 0.1250 |
| change in area | 1.8750 |
| change / h | 3.7500 |
| product rule u v′ + v u′ | 3.5000 |
| wrong rule u′ · v′ | 0.5000 |
Divide the change by h and let h shrink: the two strips give u·v′ + v·u′, and the corner (which carries h² in it) disappears.
Predict first. For p(x) = x·x, the product rule gives x + x = 2x. At x = 3, which number is p′(3)?
f = lambda x: x * x
h = 1e-6
print((f(3 + h) - f(3 - h)) / (2 * h))
print(1 * 1)
# output:
6.000000000838668
1
Quotients: the denominator moves too
For u / v both parts change, and a growing denominator shrinks the whole fraction. The rule is (u / v)′ = (u′v − u·v′) / v². Memorise the order: derivative of the top times the bottom, minus the top times derivative of the bottom, over the bottom squared. Test it with real numbers: q(x) = x / (x² + 1), so u = x and v = x² + 1.
| q(x) = x / (x² + 1) at x = 2 | value |
|---|---|
| q(x) | 0.40000 |
| central difference, h = 1e-5 | -0.12000 |
| quotient rule (u′v − uv′) / v² | -0.12000 |
| wrong rule u′ / v′ = 1 / 2x | 0.25000 |
The first two agree at every x. The wrong rule does not, except by accident.
At x = 1: (1·2 − 1·2) / 2² = 0, the top of the bump. At x = 2: (1·5 − 2·4) / 5² = -0.12, a gently falling curve. The wrong rule would claim 1 / (2·2) = 0.25 at x = 2, a slope with the wrong sign.
Common mistakes
- Multiplying the derivatives: (u·v)′ ≠ u′·v′. At the single point x = −2 in the picture above both happen to equal 0.5, which is an accident of that particular pair of functions.
- Swapping the subtraction in the quotient rule: u′v − uv′ is not the same as uv′ − u′v. The sign flips.
- Dividing where v = 0: the quotient is undefined there, and so is its derivative.
Chapter context
A derivative measures a local rate of change. It describes what a function does under a very small input change, rather than its average behavior over an arbitrary interval. This local sensitivity is what training algorithms use.
TRY IT YOURSELF
Part 1. Do it on the graph
Move the controls. Each task ticks from the real numbers on the screen and stays ticked once earned.
The rectangle has sides u = x + 1 and v = x/2 + 2. Move x and h.
| u = x + 1, v = x/2 + 2 | 2, 2.5 |
|---|---|
| blue strip u′·h·v | 2.5000 |
| orange strip u·v′·h | 1.0000 |
| corner u′h · v′h | 0.5000 |
| change in area | 4.0000 |
| change / h | 4.0000 |
| product rule u v′ + v u′ | 3.5000 |
| wrong rule u′ · v′ | 0.5000 |
Divide the change by h and let h shrink: the two strips give u·v′ + v·u′, and the corner (which carries h² in it) disappears.
- To do: Move x to the point where the slope of p = u·v is exactly 0
- To do: At x = 2, shrink h until the tiny corner piece is under 1% of the whole area change
- To do: Find the x where the tempting wrong answer u′·v′ happens to equal the true slope p′(x)
Part 2. Do it in code
- Write product_rule(u, du, v, dv, x) returning (u v)′ at x, where du and dv are the derivative functions of u and v.
- Write quotient_rule(u, du, v, dv, x) returning (u / v)′ at x. If v(x) is 0, raise ValueError.
- Write numeric_check(u, du, v, dv, x) returning the pair (product rule value, central-difference value with h = 1e-5) so you can compare them.
Stuck, or something not working? You can come back to it any time.
CHECK YOUR UNDERSTANDING
Is the derivative of x*x equal to 1*1?
Chapter reference: math, worked example & code
This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.
Math and notation
For numerical checking, use and report a tolerance.
Worked example
Let f(x)=(3x+1)^2. At x=2, the inner value is 7, its derivative is 3, and the outer derivative is 14. Multiplying gives 42. A central difference with h=0.00001 gives approximately the same answer, within numerical error.
Reference code
The following example uses the Python standard library and does not call a remote service.
from math import isclose
f = lambda x: (3*x + 1)**2
x, h = 2, 1e-5
analytic = 6*(3*x + 1)
numeric = (f(x+h)-f(x-h))/(2*h)
assert analytic == 42
assert isclose(numeric, analytic, rel_tol=1e-7)
Python examples are provided for study and local execution; this page does not execute Python.
Common mistakes
A function value is not its derivative. The chain rule multiplies sensitivities, not intermediate values. At a corner such as abs(x) at zero, a two-sided derivative does not exist.