Skip to main content

Powers, sums and constant multiples

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.
M04.3.1L1 Core25 minIn review

Before this lesson

M04.2 The derivative as slope and rate M04.1 Limits and continuity M01.8 Counting and combinatorics

After this lesson you can

  • 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\).

Two panels. Left, titled A square of side x grows by h: a blue square labelled x squared, with measuring lines x along its bottom and left side. A green strip of width h along its top and another along its right side are each labelled x h, and a small purple square in the top right corner is labelled h squared. Underneath: new area x squared plus 2 x h plus h squared, and in green: slope of x squared is 2x. Right, titled A cube of side x grows by h: a cube drawn in perspective whose three visible faces are covered by green slabs, each labelled x squared h, with thin purple rods along the edges where two slabs meet and a tiny purple corner, pointed to by the note thin rods and a tiny corner. Dashed blue lines show the hidden edges of the old cube. Underneath: new volume x cubed plus 3 x squared h plus more, and in green: slope of x cubed is 3 x squared.
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\):

\[ \begin{aligned} \frac{(x+h)^3 - x^3}{h} &= \frac{3x^2h + 3xh^2 + h^3}{h} \\ &= 3x^2 + 3xh + h^2 . \end{aligned} \]

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.

Two graphs. Left, titled Times 3: slopes triple: the sky-blue parabola x squared and the steeper blue parabola 3 x squared for x from 0 to 1.6. At x equals 1 each has a green tangent line: the one on x squared is labelled slope 2, the one on 3 x squared, through the point at height 3, is labelled slope 6 equals 3 times 2. Right, titled Add: slopes add: the sky-blue curve x cubed, the dashed sky-blue line minus 3 x, and their blue sum x cubed minus 3 x, for x from 0 to 2.5. At x equals 2 each has a green tangent: slope 12 on x cubed at height 8, slope minus 3 on the line at height minus 6, and slope 9 on the sum at height 2.
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:

\[ (x + h)^n = \sum_{k=0}^{n} \binom{n}{k}\, x^{n-k} h^{k} . \]

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:

\[ \begin{aligned} &\frac{(x+h)^n - x^n}{h} \\ &\quad= \sum_{k=1}^{n} \binom{n}{k}\, x^{n-k} h^{k-1} \\ &\quad= n\,x^{n-1} \\ &\qquad + \binom{n}{2} x^{n-2} h + \cdots + h^{n-1} . \end{aligned} \]

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:

\[ \begin{aligned} &\frac{c f(x+h) - c f(x)}{h} \\ &\quad= c \cdot \frac{f(x+h) - f(x)}{h} \\ &\quad\to c\, f'(x) . \end{aligned} \]

The sum rule. Regroup the four terms of the change into two changes:

\[ \begin{aligned} &\big(f(x+h) + g(x+h)\big) \\ &\qquad - \big(f(x) + g(x)\big) \\ &\quad= \big(f(x+h) - f(x)\big) \\ &\qquad + \big(g(x+h) - g(x)\big) . \end{aligned} \]

Divide by \(h\), and the sum law finishes the proof:

\[ \begin{aligned} &\frac{f(x+h) - f(x)}{h} + \frac{g(x+h) - g(x)}{h} \\ &\quad\to f'(x) + g'(x) . \end{aligned} \]

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:

\[ \begin{aligned} &\big(a_n x^n + \cdots + a_2 x^2 + a_1 x + a_0\big)' \\ &\quad= n\,a_n x^{n-1} + \cdots + 2a_2 x + a_1 . \end{aligned} \]

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

\[ \begin{aligned} v(t) = s'(t) &= 2 \cdot 2t - \tfrac{1}{3} \cdot 3t^2 \\ &= 4t - t^2 . \end{aligned} \]

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.

Two graphs one above the other, sharing a horizontal axis of time t from 0 to 4 seconds. Top, titled Position s of t equals 2 t squared minus t cubed over 3 metres: a blue S-shaped curve rising from 0 to about 10.7, with a blue dot at each whole second and a thin green tangent line through each dot, labelled slope 0, slope 3, slope 4, slope 3 and slope 0. Bottom, titled Velocity v of t equals s prime of t equals 4 t minus t squared metres per second: a green arch from 0 up to 4 at t equals 2 and back to 0 at t equals 4, with green dots at the whole seconds labelled 0, 3, 4, 3, 0.
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:

\[ \begin{aligned} L'(w) &= 7.5 \cdot 2w - 23.5 \cdot 1 + 0 \\ &= 15w - 23.5 . \end{aligned} \]

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.

Two graphs side by side with the weight w from 0.3 to 2.75 across. Left, titled The running loss L of w: a purple parabola with its lowest point marked by a black star near w equals 1.57. Green tangent lines touch it at three orange dots: at w equals 1, slope minus 8.5; at the star, a flat line labelled slope 0; at w equals 2, slope 6.5. Right, titled Its slope L prime of w equals 15 w minus 23.5: a straight green line rising from about minus 19 to about 18, crossing zero at w equals 47 over 30, with orange dots at w equals 1, the crossing and w equals 2 labelled minus 8.5, 0 at w equals 47 over 30, and 6.5.
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 comb

def secant(n, x, h):
    """The secant slope of x**n from x to x + h."""
    return ((x + h) ** n - x ** n) / h

def 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."""
    return sum(comb(n, k) * x ** (n - k) * h ** (k - 1) for k in range(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 in range(1, len(coefs))]

def evaluate(coefs, x):
    return sum(a * x ** k for k, a in enumerate(coefs))

cubic = [0, -3, 0, 1]           # x^3 - 3x
trip = [0, 0, 2, -1 / 3]        # 2t^2 - t^3/3
running_loss = [18.5, -23.5, 7.5]

print("cubic':", deriv(cubic))
print("trip': ", deriv(trip), "  speeds:", [round(evaluate(deriv(trip), t), 9) for t in range(5)])
print("loss': ", deriv(running_loss), "  at w = 1:", evaluate(deriv(running_loss), 1))
cubic': [-3, 0, 3]
trip':  [0, 4, -1.0]   speeds: [0.0, 3.0, 4.0, 3.0, 0.0]
loss':  [-23.5, 15.0]   at w = 1: -8.5

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 np
from numpy.polynomial import Polynomial

L = 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-5
central = (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

Two panels showing the blue parabola x squared plus 5 with a dot at x equals 1, height 6. Left, marked with a cross and titled The 5 kept: a vermillion line through the dot labelled slope 2x plus 5 equals 7, far steeper than the curve, cutting across it. Right, marked with a tick and titled The 5 dropped: a green tangent of slope 2 that just touches the curve at the dot. Below it the sky-blue parabola x squared has its own green tangent of slope 2 at height 1, and a grey arrow labelled plus 5 lifts the lower dot to the upper one: the two tangents are parallel.
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}\).

Exercises

1. ★ Differentiate \({f(x) = 4x^5 - 3x^2 + 7x - 2}\) and find \(f'(1)\).

Show solution

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

\[ \begin{aligned} &a^n - b^n \\ &\quad= (a - b)\,\big(a^{n-1} + a^{n-2}b \\ &\qquad + \cdots + b^{n-1}\big) \end{aligned} \]

with \({a = x + h}\) and \({b = x}\), and check the factorisation for \({n = 3}\) first.

Show solution

For \({n = 3}\), multiply out and watch the middle terms cancel in pairs:

\[ \begin{aligned} &(a - b)(a^2 + ab + b^2) \\ &\quad= a^3 + a^2b + ab^2 \\ &\qquad - a^2b - ab^2 - b^3 \\ &\quad= a^3 - b^3 . \end{aligned} \]

In general, with \({a = x + h}\) and \({b = x}\), we have \({a - b = h}\), so

\[ \begin{aligned} &\frac{(x+h)^n - x^n}{h} \\ &\quad= (x+h)^{n-1} + (x+h)^{n-2}x \\ &\qquad + \cdots + x^{n-1} . \end{aligned} \]

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.

The anchor figure again: a blue square grown by two green strips x h and a purple corner h squared, and a cube grown by three green slabs x squared h and thin purple rods and a corner.
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.
  • Matthew Boelkins, Active Calculus, Section 2.1, Elementary derivative rules. States the constant multiple and sum rules with their graphical reasons: a vertical stretch scales every slope, and the slopes of a sum add.
  • NumPy, numpy.polynomial.Polynomial (coefficients in order of increasing degree) and Polynomial.deriv, NumPy 2.5 manual.

Next. M04.3.2 Exponentials, sine and cosine takes the same route, from the definition to a rule, for \(e^x\), \(\sin x\) and \(\cos x\).

This lesson unlocks

M04.3.2 Exponentials, sine and cosine

Your progress is saved in this browser only. No account, no tracking.
Back to top