Three rules, each proved once from the definition of the derivative, replace a fresh limit for every function: the power rule from the binomial expansion, and the rules for constant multiples and sums from the limit laws. Together they differentiate every polynomial, the running loss included.
Prove the power rule for a positive whole exponent from the definition of the derivative, using the binomial expansion of (x + h) to the power n.
Prove the constant multiple rule and the sum rule from the limit laws, and explain each with a picture of slopes.
Differentiate any polynomial term by term, and use the result to find a velocity from a position and the slope of a loss.
Differentiate a polynomial stored as a list of coefficients, from scratch and with numpy.polynomial.Polynomial.deriv.
In review. The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.
The question
Gradient descent on the running loss \({L(w) = 7.5w^2 - 23.5w + 18.5}\) needs the slope of the loss at a new weight on every step. From the definition, each slope costs a limit. Is there a way to find the slope at every weight at once, in one line, and to trust the answer without redoing the limit each time?
Intuition
In module M04.2 the slope of \({f(x) = x^2}\) came out of a limit: the secant from \(x\) to \({x + h}\) has slope \({2x + h}\), which settles on \(2x\) as \(h\) shrinks. There is a picture behind that algebra. Read \(x^2\) as the area of a square of side \(x\), and let the side grow by a small amount \(h\).
M04.3.1-F1
Grow the side of a square by \(h\) and the area gains two strips of area \(xh\) and a corner of area \(h^2\). Grow the side of a cube by \(h\) and the volume gains three slabs of volume \(x^2h\), plus thin rods and a tiny corner whose volumes contain \(h^2\) or \(h^3\).
The square’s new area is \({x^2 + 2xh + h^2}\), so it grew by \({2xh + h^2}\). Per unit of \(h\) that is \({2x + h}\), the secant slope from M04.2. As \(h\) shrinks, the corner’s share \(h\) fades away and only the two strips are left: the slope of \(x^2\) is \(2x\).
The cube works the same way. Its growth per unit of \(h\) is \(3x^2\) from the three slabs, plus pieces that still carry a factor \(h\) and fade away. So the slope of \(x^3\) is \(3x^2\).
The pattern: the slope of \(x^n\) counts the pieces of size \({x^{n-1}h}\) that the growth adds, and there are \(n\) of them. That is the power rule. Two simpler rules complete the toolkit. Stretching a graph upwards stretches its slopes by the same factor, and adding two graphs adds their slopes. With these three rules and nothing else, every polynomial can be differentiated at sight.
Build it up
Step 1. The power rule for \({n = 3}\), from the definition. The binomial theorem of lesson M01.8.4 multiplies out the cube, with the coefficients 1, 3, 3, 1 from row 3 of Pascal’s triangle: \({(x + h)^3 = x^3 + 3x^2h + 3xh^2 + h^3}\). Take away \(x^3\) and divide by \(h\):
At \({x = 2}\) this secant slope is \({12 + 6h + h^2}\): 12.61 for \({h = 0.1}\), 12.0601 for \({h = 0.01}\), 12.006001 for \({h = 0.001}\). The two terms that carry \(h\) fade, and the limit is \({3 \cdot 2^2 = 12}\).
Step 2. A constant multiple stretches every slope. Multiply a function by 3 and its graph is stretched upwards by 3. Over any run, every rise is 3 times as large while the run stays the same, so every slope is 3 times as large.
Step 3. A sum adds slopes. Over a run from \(x\) to \({x + h}\), the rise of \({f + g}\) is the rise of \(f\) plus the rise of \(g\). Divide by the run, and the secant slopes add; let \(h\) shrink, and the slopes add.
M04.3.1-F2
Left: at \({x = 1}\) the tangent to \(3x^2\) is 3 times as steep as the tangent to \(x^2\). Right: at \({x = 2}\) the slopes of \(x^3\) and \(-3x\) are 12 and \(-3\), and the slope of their sum, the running cubic, is \({12 + (-3) = 9}\).
Step 4. A constant has slope 0. The graph of \({f(x) = c}\) is a flat line: every rise is 0.
Step 5. Put them together. A polynomial is a sum of constant multiples of powers. Split it at the plus signs, differentiate each power, and keep each coefficient in front.
The formal statement
NoteThe first rules of differentiation
For functions \(f\) and \(g\) that have derivatives at \(x\), and any constant \(c\):
Constant rule: the derivative of the constant function \(c\) is \(0\).
Power rule:\({(x^n)' = n\,x^{n-1}}\) for \({n = 1, 2, 3, \dots}\)
Constant multiple rule:\({(c\,f)' = c\,f'}\).
Sum rule:\({(f + g)' = f' + g'}\).
Each rule is proved once, from the definition of the derivative as the limit of the difference quotient (M04.2.1) and the limit laws of lesson M04.1.2.
The constant rule. For every \({h \neq 0}\), the quotient is \({(c - c)/h = 0}\). A quantity that is 0 for every \(h\) has limit 0.
The power rule. The binomial theorem, written with the numbers \(\binom{n}{k}\), expands the power:
The term with \({k = 0}\) is \({\binom{n}{0} x^n h^0 = x^n}\), which the subtraction removes. Every other term has at least one factor \(h\) to divide by:
The first term does not depend on \(h\), since \({\binom{n}{1} = n}\) and \({h^0 = 1}\). Each later term is a fixed number times a positive power of \(h\), so by the product law it tends to 0, and by the sum law so does their sum. The limit is \({n\,x^{n-1}}\). For \({n = 1}\) the rule gives \({(x)' = 1 \cdot x^0 = 1}\): the line \({y = x}\) has slope 1, as it should.
The constant multiple rule. The constant comes out of the quotient, and the limit law for a constant times a function (the product law with a constant factor) finishes the proof:
Two consequences. With \({c = -1}\) the last two rules give the difference rule, \({(f - g)' = f' - g'}\). And used together, they give the derivative of any polynomial, one term at a time:
Go deeper: why the rules ask for f and g to have derivatives
The sum rule says: if\(f'(x)\) and \(g'(x)\) exist, then so does \({(f + g)'(x)}\), and it equals their sum. It says nothing when one of them is missing. Take \({f(x) = \abs{x}}\) and \({g(x) = -\abs{x}}\). Neither has a derivative at 0, because of the corner (M04.2.3), yet their sum is the constant 0, whose derivative is 0. The rule is not wrong there; it simply does not apply. The same caution holds for every rule in this module: each one assumes that the pieces have derivatives at the point in question.
Worked example
The running cubic. Split \({g(x) = x^3 - 3x}\) at the minus sign. The power rule gives \(3x^2\) for the first term. The constant multiple rule with the power rule for \({n = 1}\) gives \({-3 \cdot 1 = -3}\) for the second. So \({g'(x) = 3x^2 - 3}\). At \({x = -1}\) and \({x = 1}\) the slope is \({3 - 3 = 0}\): the graph is flat at the local maximum 2 and the local minimum \(-2\) that M04.4 studies. At \({x = 0}\) the slope is \(-3\), and at \({x = 2}\) it is \({12 - 3 = 9}\), as in the figure above.
The running trip. The cart’s position is \({s(t) = 2t^2 - t^3/3}\) metres after \(t\) seconds (an invented example). Its velocity is the rate of change of position, so
At \({t = 0, 1, 2, 3, 4}\) this gives 0, 3, 4, 3 and 0 metres per second: the course’s table of speeds, now from a formula. The units follow the quotient: metres over seconds.
M04.3.1-F3
The slope of the position curve at each whole second (top) is the height of the velocity curve at that second (bottom). The rules turned the position formula into the velocity formula in one line.
The running loss. Term by term, with the power rule for \({n = 2}\) and \({n = 1}\) and the constant rule:
At \({w = 1}\) the slope is \({15 - 23.5 = -8.5}\): the loss falls as \(w\) grows, so a gradient step moves \(w\) up. At \({w = 2}\) it is \({30 - 23.5 = 6.5}\), so a step moves \(w\) down. The slope is 0 where \({15w = 23.5}\), at \({w = 47/30 \approx 1.567}\), the lowest point of the loss, where \({L \approx 0.092}\). M04.4 proves that a zero slope marks the minimum here.
M04.3.1-F4
The slope of a parabola is a straight line. Where the line crosses zero, the parabola is flat.
Code
First from scratch. The secant slope of \(x^3\) at \({x = 2}\), computed directly and from the binomial expansion, for shrinking \(h\):
from math import combdef secant(n, x, h):"""The secant slope of x**n from x to x + h."""return ((x + h) ** n - x ** n) / hdef expanded(n, x, h):"""The same slope from the binomial expansion: C(n, k) x^(n-k) h^(k-1), summed for k = 1..n."""returnsum(comb(n, k) * x ** (n - k) * h ** (k -1) for k inrange(1, n +1))for h in (0.1, 0.01, 0.001):print(f"h = {h:<6} direct {secant(3, 2, h):.6f} expanded {expanded(3, 2, h):.6f}")print("expanded at h = 0:", expanded(3, 2, 0), "which is 3 * 2**2")
h = 0.1 direct 12.610000 expanded 12.610000
h = 0.01 direct 12.060100 expanded 12.060100
h = 0.001 direct 12.006001 expanded 12.006001
expanded at h = 0: 12 which is 3 * 2**2
A polynomial can be stored as its list of coefficients, lowest power first, so \({x^3 - 3x}\) is [0, -3, 0, 1]. The power rule moves each coefficient one place down and multiplies it by its old power:
def deriv(coefs):"""Derivative of the polynomial with these coefficients, lowest power first."""return [k * coefs[k] for k inrange(1, len(coefs))]def evaluate(coefs, x):returnsum(a * x ** k for k, a inenumerate(coefs))cubic = [0, -3, 0, 1] # x^3 - 3xtrip = [0, 0, 2, -1/3] # 2t^2 - t^3/3running_loss = [18.5, -23.5, 7.5]print("cubic':", deriv(cubic))print("trip': ", deriv(trip), " speeds:", [round(evaluate(deriv(trip), t), 9) for t inrange(5)])print("loss': ", deriv(running_loss), " at w = 1:", evaluate(deriv(running_loss), 1))
NumPy stores a polynomial the same way, lowest power first, and its deriv method applies the same rule. A central difference (M04.2.4) checks the result at seven weights:
import numpy as npfrom numpy.polynomial import PolynomialL = Polynomial(running_loss)dL = L.deriv()print("coefficients of L':", dL.coef, " L'(1) =", dL(1.0), " zero at w =", dL.roots())w = np.linspace(0, 3, 7)h =1e-5central = (L(w + h) - L(w - h)) / (2* h)print("largest gap to a central difference:", float(np.max(np.abs(central - dL(w)))))
coefficients of L': [-23.5 15. ] L'(1) = -8.5 zero at w = [1.56666667]
largest gap to a central difference: 3.6985170481784735e-10
The gap is tiny: a parabola’s central difference is exact apart from rounding, a fact M04.2.4 derives.
Explore
This module’s interactive, the chain-rule gears, lives in lesson M04.3.4, once the chain rule is in hand. You can use it already for one thing: choose the inner function \({u = 2x + 1}\) and turn \(x\). Its gear ratio stays at 2 wherever you are, because \({2x + 1}\) is a constant multiple of \(x\) plus a constant, and the rules of this lesson give \({2 \cdot 1 + 0 = 2}\) at every point.
Pitfalls
M04.3.1-F5
Wrong beside right. Adding 5 lifts the whole graph by 5, and a lifted graph has the same slope at every point. The slope of \({x^2 + 5}\) at \({x = 1}\) is 2, not 7.
“The derivative of \({x^2 + 5}\) is \({2x + 5}\).”
The constant has slope 0, so it disappears: the derivative is \(2x\). In machine learning this is why the constant term of a loss, such as the \(18.5\) in the running loss, has no effect on where gradient descent goes. Only the parts that change with \(w\) have a slope.
“The power rule works for \(2^x\) too, so its derivative is \({x\,2^{x-1}}\).”
In \(x^n\) the base moves and the exponent is fixed. In \(2^x\) the exponent moves, which is a different kind of function. At \({x = 3}\) the false rule gives \({3 \cdot 2^2 = 12}\), but the true slope, which the next lesson finds, is about 5.55.
“The proof covered every exponent, so \({(\sqrt{x})' = \tfrac12 x^{-1/2}}\) is proved.”
The formula is true, but not yet proved. The binomial expansion used here has finitely many terms only when \(n\) is a whole number. Lesson M04.3.4 proves the power rule for every real exponent with the chain rule; until then, use it only for \({n = 1, 2, 3, \dots}\)
Check yourself
Recall
1. State the power rule, and say for which exponents this lesson proves it.
Show answer
\({(x^n)' = n\,x^{n-1}}\), proved here for \({n = 1, 2, 3, \dots}\) from the binomial expansion.
2. In the proof of the power rule, why does only the term \({n\,x^{n-1}}\) survive the limit?
Show answer
After dividing by \(h\), every other term still has a factor \(h\) to a positive power, and so tends to 0 as \(h\) does.
3. In the growing square, which piece vanishes in the limit, and why?
Show answer
The corner \(h^2\). Per unit of \(h\) it contributes \(h\), which tends to 0; the two strips contribute \(2x\), which does not.
4. Multiply a function by 3. What happens to its slopes, and which rule says so?
Show answer
Every slope is multiplied by 3, by the constant multiple rule: each rise triples while the run stays the same.
5. What is the derivative of the running loss, and where is it zero?
Show answer
\({L'(w) = 15w - 23.5}\), which is zero at \({w = 47/30 \approx 1.567}\).
Term by term: the power rule with \({n = 5, 2, 1}\), each coefficient kept in front, and 0 for the constant. So \({f'(x) = 20x^4 - 6x + 7}\), and \({f'(1) = 20 - 6 + 7 = 21}\).
2.★★ For the running trip, find the acceleration \({a(t) = v'(t)}\). When is it zero, and what is the speed then? What is \(s'(4)\), and what does it say about the cart?
Show solution
From \({v(t) = 4t - t^2}\), the rules give \({a(t) = 4 - 2t}\) metres per second per second. It is zero at \({t = 2}\), where the speed is \({v(2) = 8 - 4 = 4}\) metres per second, the largest value in the table: the cart stops speeding up and starts slowing down. Finally \({s'(4) = v(4) = 16 - 16 = 0}\): after 4 seconds the cart is at rest.
3.★★★ Prove the power rule without the binomial theorem. Use the factorisation
There are \(n\) terms. As \(h\) tends to 0, each tends to \(x^{n-1}\), by the product law for limits, since \({x + h}\) tends to \(x\). By the sum law the whole sum tends to \({n\,x^{n-1}}\).
Summary card
Three rules, each proved once, differentiate every polynomial.
M04.3.1-F1
Count the pieces of size \(x^{n-1}h\).
Power:\({(x^n)' = n\,x^{n-1}}\) for whole \({n \ge 1}\); a constant has slope 0.
Constant multiple:\({(c\,f)' = c\,f'}\).
Sum:\({(f + g)' = f' + g'}\), and so \({(f - g)' = f' - g'}\).
Running loss:\({L'(w) = 15w - 23.5}\), zero at \({w = 47/30}\).
Sources and next steps
Sources. Each was opened and checked against this lesson on 12 November 2026.
Gilbert Strang and Edwin Herman, Calculus Volume 1, Section 3.3, Differentiation Rules, OpenStax. Theorem 3.3, the power rule, is proved by expanding \({(x + h)^n}\) with binomial coefficients; Theorem 3.4 gives the sum, difference and constant multiple rules, with the sum rule proved from the sum law for limits.
Marc Peter Deisenroth, A. Aldo Faisal and Cheng Soon Ong, Mathematics for Machine Learning, Section 5.1. Definition 5.2 defines the derivative as the limit of the difference quotient (equation 5.4), Example 5.2 derives the derivative of \(x^n\) through the binomial expansion (equations 5.5 and 5.6), and Section 5.1.2 lists the sum rule (5.31) beside the product, quotient and chain rules of the next lessons.