TExcelTAD
Home › Pre-Calculus, Geometry & Trigonometry › The Binomial Expansion

The Binomial Expansion

Multiplying out (a+b)5(a + b)^5 by hand is tedious, but the answer follows a beautiful pattern. The binomial theorem gives every term of (a+b)n(a + b)^n at once, using numbers from Pascal's triangle. This lesson builds the triangle, connects it to counting (choosing kk items from nn), and computes everything with Python's math.comb.

Expanding small powers

(a+b)0=1(a+b)1=a+b(a+b)2=a2+2ab+b2(a+b)3=a3+3a2b+3ab2+b3(a+b)4=a4+4a3b+6a2b2+4ab3+b4\begin{aligned} (a + b)^0 &= 1 \\ (a + b)^1 &= a + b \\ (a + b)^2 &= a^2 + 2ab + b^2 \\ (a + b)^3 &= a^3 + 3a^2b + 3ab^2 + b^3 \\ (a + b)^4 &= a^4 + 4a^3b + 6a^2b^2 + 4ab^3 + b^4 \end{aligned}

Three patterns stand out in (a+b)n(a + b)^n:

  • there are n+1n + 1 terms;
  • the power of aa falls from nn to 0 while the power of bb rises from 0 to nn, and in every term the two powers add up to nn;
  • the coefficients are symmetric: 1 4 6 4 1.

Pascal's triangle

Write the coefficients in rows. Each number is the sum of the two numbers above it, with 1s down the edges:

text
n = 0:            1
n = 1:          1   1
n = 2:        1   2   1
n = 3:      1   3   3   1
n = 4:    1   4   6   4   1
n = 5:  1   5  10  10   5   1

Why does adding work? (a+b)n+1=(a+b)n⋅(a+b)(a + b)^{n+1} = (a + b)^n \cdot (a + b). Each term of the new power comes from two old terms: one multiplied by aa, the other by bb. So each new coefficient is the sum of two neighbouring old ones.

python · try it yourself
def pascal(rows):
    row = [1]
    for n in range(rows):
        print(f"n = {n}: " + " ".join(str(c) for c in row).center(40).rstrip())
        row = [1] + [row[i] + row[i + 1] for i in range(len(row) - 1)] + [1]

pascal(8)
n = 0:                    1
n = 1:                   1 1
n = 2:                  1 2 1
n = 3:                 1 3 3 1
n = 4:                1 4 6 4 1
n = 5:              1 5 10 10 5 1
n = 6:             1 6 15 20 15 6 1
n = 7:           1 7 21 35 35 21 7 1

Binomial coefficients

The kk-th entry of row nn (counting from k=0k = 0) is the binomial coefficient "nn choose kk":

(nk)=n!k!⋅(n−k)!\binom{n}{k} = \frac{n!}{k! \cdot (n - k)!}

It counts the ways to choose kk items from nn when order does not matter. That is exactly what happens when you multiply out (a+b)n(a + b)^n: each term picks either aa or bb from each of the nn brackets, and the term an−kbka^{n-k} b^k appears once for every way of choosing which kk brackets supply bb.

The binomial theorem

(a+b)n=∑k=0n(nk)⋅an−k⋅bk=an+(n1)an−1b+(n2)an−2b2+⋯+bn\begin{aligned} (a + b)^n &= \sum_{k=0}^{n} \binom{n}{k} \cdot a^{n-k} \cdot b^k \\ &= a^n + \binom{n}{1} a^{n-1} b + \binom{n}{2} a^{n-2} b^2 + \cdots + b^n \end{aligned}

Python has math.comb(n, k) built in. Here it expands (2x−3)5(2x - 3)^5, with a=2xa = 2x and b=−3b = -3, and SymPy confirms:

python · try it yourself
import math
import sympy as sp

n, a, b = 5, 2, -3        # (a·x + b)^n = (2x - 3)^5
terms = []
for k in range(n + 1):
    coeff = math.comb(n, k) * a**(n - k) * b**k
    terms.append(f"{coeff:+d}x^{n - k}")
print(" ".join(terms))

x = sp.symbols("x")
print(sp.expand((2 * x - 3)**5))
+32x^5 -240x^4 +720x^3 -1080x^2 +810x^1 -243x^0
32*x**5 - 240*x**4 + 720*x**3 - 1080*x**2 + 810*x - 243

To find one particular term without expanding everything, use the general term (nk)⋅an−kbk\binom{n}{k} \cdot a^{n-k} b^k directly. For example the x3x^3 term of (x+2)10(x + 2)^{10} has n−k=3n - k = 3, so k=7k = 7: (107)⋅27⋅x3=120⋅128⋅x3=15360x3\binom{10}{7} \cdot 2^7 \cdot x^3 = 120 \cdot 128 \cdot x^3 = 15360x^3.

Tip: Setting a=b=1a = b = 1 gives ∑(nk)=2n\sum \binom{n}{k} = 2^n: the entries of row nn add up to 2n2^n, the number of subsets of an nn-element set. Setting a=1a = 1, b=−1b = -1 shows the alternating sum of a row is 0.

Approximations with the binomial

For small xx, (1+x)n≈1+nx(1 + x)^n \approx 1 + nx, since the later terms contain x2,x3,…x^2, x^3, \ldots This shortcut works for any power, even fractional ones like 1+x≈1+x/2\sqrt{1 + x} \approx 1 + x/2, via the binomial series.

python · try it yourself
import math

for x in [0.1, 0.01, 0.001]:
    exact = (1 + x)**8
    print(f"x = {x}: (1+x)^8 = {exact:.6f}   1 + 8x = {1 + 8 * x:.6f}   with x^2 term = {1 + 8 * x + math.comb(8, 2) * x**2:.6f}")
x = 0.1: (1+x)^8 = 2.143589   1 + 8x = 1.800000   with x^2 term = 2.080000
x = 0.01: (1+x)^8 = 1.082857   1 + 8x = 1.080000   with x^2 term = 1.082800
x = 0.001: (1+x)^8 = 1.008028   1 + 8x = 1.008000   with x^2 term = 1.008028

In software

  • Counting and probability. math.comb counts combinations: lottery tickets, poker hands, the number of test cases for kk features out of nn. The probability of exactly kk successes in nn coin-like trials is (nk)pk(1−p)n−k\binom{n}{k} p^k (1 - p)^{n-k} (the binomial distribution).
  • Bézier curves. The weights of a degree-nn Bézier curve are the terms (nk)(1−t)n−ktk\binom{n}{k} (1 - t)^{n-k} t^k of the expansion of ((1−t)+t)n=1((1 - t) + t)^n = 1, which is why they always add up to 1 (see Bézier Curves).
  • Dynamic programming. Pascal's rule (nk)=(n−1k−1)+(n−1k)\binom{n}{k} = \binom{n - 1}{k - 1} + \binom{n - 1}{k} is a classic table-filling recurrence (Tabulation).
  • Interest. (1+i)n≈1+ni(1 + i)^n \approx 1 + ni explains why simple and compound interest agree for small rates or short times.

Exercises

Exercise 1: Row 6

Use Pascal's triangle to expand (x+y)6(x + y)^6.

Answer

x6+6x5y+15x4y2+20x3y3+15x2y4+6xy5+y6x^6 + 6x^5y + 15x^4y^2 + 20x^3y^3 + 15x^2y^4 + 6xy^5 + y^6

Solution

Row 6 of the triangle is 1 6 15 20 15 6 1. The power of xx falls from 6 to 0 while the power of yy rises from 0 to 6.

Exercise 2: One term

Find the coefficient of x4x^4 in (3x−1)7(3x - 1)^7.

Answer

−2835

Solution
General term: (7k)⋅(3x)7−k⋅(−1)k. x4 needs 7−k=4, so k=3.(73)⋅34⋅(−1)3=35⋅81⋅(−1)=−2835\begin{aligned} &\text{General term: } \binom{7}{k} \cdot (3x)^{7-k} \cdot (-1)^k.\ x^4 \text{ needs } 7 - k = 4, \text{ so } k = 3. \\ &\binom{7}{3} \cdot 3^4 \cdot (-1)^3 = 35 \cdot 81 \cdot (-1) = -2835 \end{aligned}
python · try it yourself
import math

print(math.comb(7, 3) * 3**4 * (-1)**3)
-2835

Exercise 3: Middle term

Find the constant term (no xx) in (x+2/x)6(x + 2/x)^6.

Answer

160

Solution
Term: (6k)⋅x6−k⋅(2/x)k=(6k)⋅2k⋅x6−2kConstant when 6−2k=0, k=3:(63)⋅23=20⋅8=160\begin{aligned} &\text{Term: } \binom{6}{k} \cdot x^{6-k} \cdot (2/x)^k = \binom{6}{k} \cdot 2^k \cdot x^{6-2k} \\ &\text{Constant when } 6 - 2k = 0,\ k = 3{:}\quad \binom{6}{3} \cdot 2^3 = 20 \cdot 8 = 160 \end{aligned}

Exercise 4: Rows sum to powers of two

Write a loop that checks ∑k\sum_k math.comb(n, k) =2n= 2^n for n=0n = 0 to 20, and prints the sum for n=20n = 20.

Answer

It holds for every nn; for n=20n = 20 the sum is 1 048 576.

Solution
python · try it yourself
import math

ok = all(sum(math.comb(n, k) for k in range(n + 1)) == 2**n for n in range(21))
print(ok, sum(math.comb(20, k) for k in range(21)))
True 1048576

Test yourself

What is the coefficient of a2b3a^2b^3 in (a+b)5(a + b)^5?

  1. 5
  2. 10
  3. 15
  4. 20

How many terms does the expansion of (a+b)12(a + b)^{12} have?

  1. 13
  2. 12
  3. 24
  4. 6

What does math.comb(6, 2) return?

  1. 12
  2. 30
  3. 36
  4. 15