TExcelTAD
Home › Calculus Essentials › Power, Sum and Constant Rules

Power, Sum and Constant Rules

Computing every derivative from the limit definition would be slow. A handful of rules do almost all the work: the power rule handles xnx^n, and the constant, constant-multiple and sum rules let you differentiate any polynomial term by term in a single line.

The rules

Rule Formula Example
Constant ddxc=0\frac{d}{dx} c = 0 ddx7=0\frac{d}{dx} 7 = 0
Power ddxxn=n⋅xn−1\frac{d}{dx} x^n = n \cdot x^{n-1} ddxx5=5x4\frac{d}{dx} x^5 = 5x^4
Constant multiple ddx[c⋅f]=c⋅f′\frac{d}{dx} [c \cdot f] = c \cdot f' ddx3x2=6x\frac{d}{dx} 3x^2 = 6x
Sum / difference ddx[f±g]=f′±g′\frac{d}{dx} [f \pm g] = f' \pm g' ddx(x3+x)=3x2+1\frac{d}{dx} (x^3 + x) = 3x^2 + 1

The power rule works for every real exponent nn, not only whole numbers, as long as xnx^n is defined near the point. Rewrite roots and reciprocals as powers first:

x=x1/2→12⋅x−1/2=12x1x3=x−3→−3⋅x−4=−3x4x23=x2/3→23⋅x−1/3\begin{aligned} \sqrt{x} &= x^{1/2} &&\to \tfrac{1}{2} \cdot x^{-1/2} = \frac{1}{2\sqrt{x}} \\ \frac{1}{x^3} &= x^{-3} &&\to -3 \cdot x^{-4} = -\frac{3}{x^4} \\ \sqrt[3]{x^2} &= x^{2/3} &&\to \tfrac{2}{3} \cdot x^{-1/3} \end{aligned}

Why the power rule holds

For a whole number nn, expand (x+h)n(x + h)^n with the binomial theorem:

(x+h)n=xn+n⋅xn−1⋅h+(terms with h2,h3,…)(x+h)n−xnh=n⋅xn−1+(terms with h,h2,…)→n⋅xn−1\begin{aligned} (x + h)^n &= x^n + n \cdot x^{n-1} \cdot h + (\text{terms with } h^2, h^3, \ldots) \\[1ex] \frac{(x + h)^n - x^n}{h} &= n \cdot x^{n-1} + (\text{terms with } h, h^2, \ldots) \to n \cdot x^{n-1} \end{aligned}

Every term except one still contains an hh and vanishes in the limit. The sum and constant-multiple rules follow directly from the matching limit laws.

Checking with SymPy and numbers

python · try it yourself
import sympy as sp

x = sp.symbols('x', positive=True)
for f in [x**7, 4 * x**3 - 5 * x + 9, sp.sqrt(x), 1 / x**3, x**sp.Rational(2, 3), x**sp.pi]:
    print(f"d/dx {str(f):<20} = {sp.diff(f, x)}")
d/dx x**7                 = 7*x**6
d/dx 4*x**3 - 5*x + 9     = 12*x**2 - 5
d/dx sqrt(x)              = 1/(2*sqrt(x))
d/dx x**(-3)              = -3/x**4
d/dx x**(2/3)             = 2/(3*x**(1/3))
d/dx x**pi                = pi*x**pi/x

SymPy writes sqrt(x) for x\sqrt{x}, moves negative exponents into the denominator (2/(3*x**(1/3)) is 23⋅x−1/3\frac{2}{3} \cdot x^{-1/3}), and writes π⋅xπ−1\pi \cdot x^{\pi - 1} as pi*x**pi/x.

Now the same rule from raw numbers: the central difference quotient for x2.5x^{2.5} at several points against the formula 2.5⋅x1.52.5 \cdot x^{1.5}.

python · try it yourself
def f(x):
    return x ** 2.5

h = 1e-5
print("  x    numeric slope    2.5*x**1.5")
for x0 in [0.5, 1, 2, 4, 9]:
    numeric = (f(x0 + h) - f(x0 - h)) / (2 * h)
    print(f"{x0:4}  {numeric:14.6f}  {2.5 * x0 ** 1.5:12.6f}")
  x    numeric slope    2.5*x**1.5
 0.5        0.883883      0.883883
   1        2.500000      2.500000
   2        7.071068      7.071068
   4       20.000000     20.000000
   9       67.500000     67.500000

Differentiating polynomials in one pass

Combine the rules term by term:

p(x)=2x4−5x3+x2−8x+11p′(x)=8x3−15x2+2x−8\begin{aligned} p(x) &= 2x^4 - 5x^3 + x^2 - 8x + 11 \\ p'(x) &= 8x^3 - 15x^2 + 2x - 8 \end{aligned}

Since a polynomial is stored as a list of coefficients, its derivative is a tiny loop: multiply each coefficient by its exponent and shift down by one. NumPy's Polynomial class does exactly that:

python · try it yourself
from numpy.polynomial import Polynomial

# coefficients from the constant term upwards: 11 - 8x + x^2 - 5x^3 + 2x^4
p = Polynomial([11, -8, 1, -5, 2])
dp = p.deriv()
print("p' coefficients:", dp.coef)

def deriv(coeffs):
    return [k * c for k, c in enumerate(coeffs)][1:]

print("by hand:        ", deriv([11, -8, 1, -5, 2]))
print("p'(2) =", dp(2))
p' coefficients: [ -8.   2. -15.   8.]
by hand:         [-8, 2, -15, 8]
p'(2) = 0.0

p′(2)=64−60+4−8=0p'(2) = 64 - 60 + 4 - 8 = 0, so the graph of pp is momentarily flat at x=2x = 2: a critical point, the starting place for finding maxima and minima.

Note: ddx(f⋅g)\frac{d}{dx} (f \cdot g) is not f′⋅g′f' \cdot g', and ddx(f/g)\frac{d}{dx} (f/g) is not f′/g′f'/g'. Products and quotients need the rules in the next lesson.

In software

  • Polynomial models: polynomial regression fits y=a0+a1x+a2x2+…y = a_0 + a_1 x + a_2 x^2 + \ldots; the slope of the fitted curve at any point is just the power rule applied to the learned coefficients.
  • Easing curves: a UI animation such as smoothstep⁡(t)=3t2−2t3\operatorname{smoothstep}(t) = 3t^2 - 2t^3 has velocity 6t−6t26t - 6t^2, which is 0 at t=0t = 0 and t=1t = 1. That is why it starts and stops gently (easing curves).
  • Cost of algorithms: if work is W(n)=n2/2W(n) = n^2/2, the marginal cost of one more item is about W′(n)=nW'(n) = n. Derivatives are a handy way to reason about "what does one more user cost?".
  • Loss functions: mean squared error uses (y^−y)2(\hat{y} - y)^2; its derivative 2(y^−y)2(\hat{y} - y) is the power rule, and it drives every step of gradient descent on regression.

Exercises

Exercise 1: Term by term

Differentiate f(x)=3x5−4x2+7x−2f(x) = 3x^5 - 4x^2 + 7x - 2.

Answer

f′(x)=15x4−8x+7f'(x) = 15x^4 - 8x + 7

Solution
3x5→3⋅5x4=15x4−4x2→−4⋅2x=−8x7x→7−2→0\begin{aligned} 3x^5 &\to 3 \cdot 5x^4 = 15x^4 \\ -4x^2 &\to -4 \cdot 2x = -8x \\ 7x &\to 7 \\ -2 &\to 0 \end{aligned}

Exercise 2: Rewrite as powers

Differentiate g(x)=6x−2/x2+x3g(x) = 6\sqrt{x} - 2/x^2 + \sqrt[3]{x}.

Answer

g′(x)=3x+4x3+13x23g'(x) = \dfrac{3}{\sqrt{x}} + \dfrac{4}{x^3} + \dfrac{1}{3\sqrt[3]{x^2}}

Solution
g(x)=6x1/2−2x−2+x1/3g′(x)=6⋅12x−1/2−2⋅(−2)x−3+13x−2/3=3x+4x3+13x23\begin{aligned} g(x) &= 6x^{1/2} - 2x^{-2} + x^{1/3} \\ g'(x) &= 6 \cdot \tfrac{1}{2} x^{-1/2} - 2 \cdot (-2) x^{-3} + \tfrac{1}{3} x^{-2/3} \\ &= \frac{3}{\sqrt{x}} + \frac{4}{x^3} + \frac{1}{3\sqrt[3]{x^2}} \end{aligned}

Exercise 3: Where is the slope 4?

At which points does y=x3−8xy = x^3 - 8x have slope 4?

Answer

x=2x = 2 and x=−2x = -2, i.e. the points (2,−8)(2, -8) and (−2,8)(-2, 8).

Solution
y′=3x2−8=4  ⟹  3x2=12  ⟹  x=±2y(2)=8−16=−8,y(−2)=−8+16=8\begin{aligned} &y' = 3x^2 - 8 = 4 \implies 3x^2 = 12 \implies x = \pm 2 \\ &y(2) = 8 - 16 = -8, \quad y(-2) = -8 + 16 = 8 \end{aligned}

Exercise 4: Derivative of a coefficient list

Write deriv(coeffs) for coefficients listed from the constant term upwards and use it on 1+2x+3x2+4x31 + 2x + 3x^2 + 4x^3. Check at x=1x = 1 against SymPy.

Answer

[2, 6, 12], i.e. 2+6x+12x22 + 6x + 12x^2, which is 20 at x=1x = 1.

Solution
python · try it yourself
import sympy as sp

def deriv(coeffs):
    return [k * c for k, c in enumerate(coeffs)][1:]

d = deriv([1, 2, 3, 4])
print(d, "value at 1:", sum(d))

x = sp.symbols('x')
print(sp.diff(1 + 2*x + 3*x**2 + 4*x**3, x).subs(x, 1))
[2, 6, 12] value at 1: 20
20

Test yourself

What is ddx\frac{d}{dx} of x−2x^{-2}?

  1. −2x−1-2x^{-1}
  2. −2x−3-2x^{-3}
  3. −x−3-x^{-3}
  4. 2x−32x^{-3}

What is the derivative of the constant π2\pi^2?

  1. 2π2\pi
  2. π2\pi^2
  3. 00
  4. 2π⋅x2\pi \cdot x

What is ddxx\frac{d}{dx} \sqrt{x}?

  1. 12x\frac{1}{2\sqrt{x}}
  2. 2x2\sqrt{x}
  3. x2\frac{\sqrt{x}}{2}
  4. 1x\frac{1}{\sqrt{x}}