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 , 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 | ||
| Power | ||
| Constant multiple | ||
| Sum / difference |
The power rule works for every real exponent , not only whole numbers, as long as is defined near the point. Rewrite roots and reciprocals as powers first:
Why the power rule holds
For a whole number , expand with the binomial theorem:
Every term except one still contains an and vanishes in the limit. The sum and constant-multiple rules follow directly from the matching limit laws.
Checking with SymPy and numbers
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 , moves negative exponents into the denominator (2/(3*x**(1/3)) is ), and writes as pi*x**pi/x.
Now the same rule from raw numbers: the central difference quotient for at several points against the formula .
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:
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:
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
, so the graph of is momentarily flat at : a critical point, the starting place for finding maxima and minima.
Note: is not , and is not . Products and quotients need the rules in the next lesson.
In software
- Polynomial models: polynomial regression fits ; 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 has velocity , which is 0 at and . That is why it starts and stops gently (easing curves).
- Cost of algorithms: if work is , the marginal cost of one more item is about . Derivatives are a handy way to reason about "what does one more user cost?".
- Loss functions: mean squared error uses ; its derivative is the power rule, and it drives every step of gradient descent on regression.
Exercises
Exercise 1: Term by term
Differentiate .
Answer
Solution
Exercise 2: Rewrite as powers
Differentiate .
Answer
Solution
Exercise 3: Where is the slope 4?
At which points does have slope 4?
Answer
and , i.e. the points and .
Solution
Exercise 4: Derivative of a coefficient list
Write deriv(coeffs) for coefficients listed from the constant term upwards and use it on . Check at against SymPy.
Answer
[2, 6, 12], i.e. , which is 20 at .
Solution
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 of ?
What is the derivative of the constant ?
What is ?