TExcelTAD
Home › Calculus Essentials › Product and Quotient Rules

Product and Quotient Rules

When two changing quantities are multiplied or divided, the result changes for two reasons at once. The product and quotient rules account for both. They are the tools for derivatives like x2⋅sin⁡xx^2 \cdot \sin x, x+1x−1\frac{x + 1}{x - 1}, or revenue=price×quantity\text{revenue} = \text{price} \times \text{quantity} when both move.

The product rule

(f⋅g)′=f′⋅g+f⋅g′(f \cdot g)' = f' \cdot g + f \cdot g'

"Derivative of the first times the second, plus the first times the derivative of the second." A picture explains it: f⋅gf \cdot g is the area of a rectangle with sides ff and gg. If ff grows by Δf\Delta f and gg by Δg\Delta g, the area grows by Δf⋅g+f⋅Δg+Δf⋅Δg\Delta f \cdot g + f \cdot \Delta g + \Delta f \cdot \Delta g. Divide by Δx\Delta x and let it go to 0: the tiny corner Δf⋅Δg/Δx\Delta f \cdot \Delta g / \Delta x vanishes, and the two strips remain.

ddx[x3⋅(2x+1)]=3x2⋅(2x+1)+x3⋅2=6x3+3x2+2x3=8x3+3x2\frac{d}{dx}\left[x^3 \cdot (2x + 1)\right] = 3x^2 \cdot (2x + 1) + x^3 \cdot 2 = 6x^3 + 3x^2 + 2x^3 = 8x^3 + 3x^2

Check by expanding first: x3(2x+1)=2x4+x3x^3(2x + 1) = 2x^4 + x^3, derivative 8x3+3x28x^3 + 3x^2. Same answer.

The quotient rule

(fg)′=f′⋅g−f⋅g′g2(where g≠0)\left(\frac{f}{g}\right)' = \frac{f' \cdot g - f \cdot g'}{g^2} \qquad (\text{where } g \ne 0)

A memory aid: "low d-high minus high d-low, over low squared". The order matters because of the minus sign.

ddx[x+1x−1]=1⋅(x−1)−(x+1)⋅1(x−1)2=−2(x−1)2\begin{aligned} \frac{d}{dx}\left[\frac{x + 1}{x - 1}\right] &= \frac{1 \cdot (x - 1) - (x + 1) \cdot 1}{(x - 1)^2} \\ &= \frac{-2}{(x - 1)^2} \end{aligned}

The result is always negative, so this function decreases on each side of its asymptote at x=1x = 1.

Checking with SymPy

python · try it yourself
import sympy as sp

x = sp.symbols('x')
f, g = x**2 + 3, sp.sin(x)

by_rule = sp.diff(f, x) * g + f * sp.diff(g, x)
print("product rule:", by_rule)
print("sp.diff     :", sp.diff(f * g, x))
print("equal?      :", sp.simplify(by_rule - sp.diff(f * g, x)) == 0)

q = (x + 1) / (x - 1)
print("quotient    :", sp.simplify(sp.diff(q, x)))
product rule: 2*x*sin(x) + (x**2 + 3)*cos(x)
sp.diff     : 2*x*sin(x) + (x**2 + 3)*cos(x)
equal?      : True
quotient    : -2/(x - 1)**2

sp.simplify(a - b) == 0 is a reliable way to test whether two formulas are the same function.

Numeric evidence

The product rule against central differences for F(x)=x2⋅exF(x) = x^2 \cdot e^x at a few points (F′=2x⋅ex+x2⋅exF' = 2x \cdot e^x + x^2 \cdot e^x):

python · try it yourself
import math

def F(x):
    return x**2 * math.exp(x)

def F_prime(x):                      # product rule
    return 2 * x * math.exp(x) + x**2 * math.exp(x)

h = 1e-5
for x0 in [-2.0, 0.0, 0.5, 1.0, 3.0]:
    numeric = (F(x0 + h) - F(x0 - h)) / (2 * h)
    print(f"x = {x0:4}   numeric {numeric:12.6f}   rule {F_prime(x0):12.6f}")
x = -2.0   numeric    -0.000000   rule     0.000000
x =  0.0   numeric     0.000000   rule     0.000000
x =  0.5   numeric     2.060902   rule     2.060902
x =  1.0   numeric     8.154845   rule     8.154845
x =  3.0   numeric   301.283054   rule   301.283054

At x=−2x = -2 the slope is exactly 0: there FF has a local maximum, a fact we will use in Maxima, Minima and Curve Shape.

Quotient rule examples

Function Derivative
1x\frac{1}{x} −1x2-\frac{1}{x^2}
xx2+1\frac{x}{x^2 + 1} 1−x2(x2+1)2\frac{1 - x^2}{(x^2 + 1)^2}
tan⁡x=sin⁡xcos⁡x\tan x = \frac{\sin x}{\cos x} 1cos⁡2x=sec⁡2x\frac{1}{\cos^2 x} = \sec^2 x
3x−2x+4\frac{3x - 2}{x + 4} 14(x+4)2\frac{14}{(x + 4)^2}

Tip: If the numerator or denominator is a constant, skip the quotient rule. 5/x3=5x−35/x^3 = 5x^{-3} differentiates instantly with the power rule to −15x−4-15x^{-4}.

In software

  • Revenue and pricing: revenue R=p⋅q(p)R = p \cdot q(p). Its derivative R′=q+p⋅q′R' = q + p \cdot q' says raising the price earns more per unit (qq) but loses some sales (p⋅q′p \cdot q', negative). Setting R′=0R' = 0 finds the best price.
  • Normalisation in ML: softmax, layer norm and cosine similarity all divide one expression by another. Their gradients in a framework's backward pass are quotient-rule derivatives, written out once and reused.
  • Perspective projection: screen coordinates are x/zx/z and y/zy/z. How fast a point moves on screen when the camera moves is a quotient-rule derivative, which is why nearby objects seem to move faster (projection).

Exercises

Exercise 1: Product rule

Differentiate f(x)=(x2−1)(x3+2x)f(x) = (x^2 - 1)(x^3 + 2x) with the product rule.

Answer

f′(x)=5x4+3x2−2f'(x) = 5x^4 + 3x^2 - 2

Solution
f′=2x⋅(x3+2x)+(x2−1)⋅(3x2+2)=2x4+4x2+3x4+2x2−3x2−2=5x4+3x2−2\begin{aligned} f' &= 2x \cdot (x^3 + 2x) + (x^2 - 1) \cdot (3x^2 + 2) \\ &= 2x^4 + 4x^2 + 3x^4 + 2x^2 - 3x^2 - 2 \\ &= 5x^4 + 3x^2 - 2 \end{aligned}

Check: expanded f=x5+x3−2xf = x^5 + x^3 - 2x, so f′=5x4+3x2−2f' = 5x^4 + 3x^2 - 2.

Exercise 2: Quotient rule

Differentiate g(x)=x2x+3g(x) = \dfrac{x^2}{x + 3}.

Answer

g′(x)=x2+6x(x+3)2g'(x) = \dfrac{x^2 + 6x}{(x + 3)^2}

Solution
g′=2x⋅(x+3)−x2⋅1(x+3)2=2x2+6x−x2(x+3)2=x2+6x(x+3)2\begin{aligned} g' &= \frac{2x \cdot (x + 3) - x^2 \cdot 1}{(x + 3)^2} \\ &= \frac{2x^2 + 6x - x^2}{(x + 3)^2} \\ &= \frac{x^2 + 6x}{(x + 3)^2} \end{aligned}

Exercise 3: Horizontal tangents

Where does y=xx2+4y = \dfrac{x}{x^2 + 4} have a horizontal tangent?

Answer

At x=2x = 2 and x=−2x = -2.

Solution
y′=1⋅(x2+4)−x⋅2x(x2+4)2=4−x2(x2+4)2y′=0  ⟺  4−x2=0  ⟺  x=±2\begin{aligned} &y' = \frac{1 \cdot (x^2 + 4) - x \cdot 2x}{(x^2 + 4)^2} = \frac{4 - x^2}{(x^2 + 4)^2} \\ &y' = 0 \iff 4 - x^2 = 0 \iff x = \pm 2 \end{aligned}

Exercise 4: Best price

Weekly sales of an app subscription at price pp are q(p)=1000−40pq(p) = 1000 - 40p. Use R′(p)=q+p⋅q′R'(p) = q + p \cdot q' to find the price that maximises revenue, and confirm with SymPy.

Answer

p=12.5p = 12.5, revenue 6250.

Solution
R(p)=p(1000−40p)R′(p)=(1000−40p)+p⋅(−40)=1000−80p=0  ⟹  p=12.5R(12.5)=12.5⋅500=6250\begin{aligned} R(p) &= p(1000 - 40p) \\ R'(p) &= (1000 - 40p) + p \cdot (-40) = 1000 - 80p = 0 \implies p = 12.5 \\ R(12.5) &= 12.5 \cdot 500 = 6250 \end{aligned}
python · try it yourself
import sympy as sp

p = sp.symbols('p')
R = p * (1000 - 40 * p)
best = sp.solve(sp.diff(R, p), p)[0]
print(best, R.subs(p, best))
25/2 6250

Test yourself

What is the product rule?

  1. (fg)′=f′g′(fg)' = f'g'
  2. (fg)′=f′g−fg′(fg)' = f'g - fg'
  3. (fg)′=f′g+fg′(fg)' = f'g + fg'
  4. (fg)′=(f′g+fg′)/g2(fg)' = (f'g + fg')/g^2

What is ddx[1x2+1]\frac{d}{dx}\left[\frac{1}{x^2 + 1}\right]?

  1. −2x(x2+1)2\frac{-2x}{(x^2 + 1)^2}
  2. 12x\frac{1}{2x}
  3. 2x(x2+1)2\frac{2x}{(x^2 + 1)^2}
  4. −1(x2+1)2\frac{-1}{(x^2 + 1)^2}

In the quotient rule f′g−fg′g2\frac{f'g - fg'}{g^2}, what happens if you swap the order of the terms in the numerator?

  1. The answer gets the wrong sign
  2. Nothing changes
  3. The answer doubles
  4. It becomes the product rule