Discrete MathCounting

The Sum and Product Rules

Add the counts of cases that cannot happen together; multiply the counts of choices made one after another.

Not started Jump to practice

In probability you counted permutations by multiplying choices. That multiplication is one of two basic rules of counting. Both rules are facts about sets you have seen: the size of a union of separate sets, and the size of a Cartesian product.

Key idea

Sum rule: if a choice can be made in one of several ways that cannot happen together, with $a$, $b$, … options in each, the total is $a + b + \cdots$. Product rule: if a choice is made in steps, with $a$ options for the first step and $b$ for the second (whatever the first was), and so on, the total is $a \cdot b \cdots$.

Why it works

The sum rule is $|A \cup B| = |A| + |B|$ for disjoint sets: nothing is counted twice because nothing is in both. The product rule is $|A \times B| = |A| \cdot |B|$: a two-step choice is an ordered pair, and each first step pairs with every second step. The words to listen for: "either … or" (alternatives, add) versus "first … then" (a sequence, multiply). Big problems often need both: split into cases with the sum rule, count each case with the product rule.

Worked examples

Worked example: A license plate

A plate has $3$ letters (A–Z) followed by $3$ digits (0–9), repeats allowed. How many plates are there?
  1. Six steps in a row: $26$ choices for each letter and $10$ for each digit.
  2. Product rule: $26^{3} \cdot 10^{3} = 17{,}576 \cdot 1{,}000 = 17{,}576{,}000$.

Answer: $17{,}576{,}000$

Worked example: Two possible lengths

A code uses digits 0–9 and has length $3$ or $4$. How many codes are there?
  1. A code has one length or the other, never both, so split into cases and add.
  2. Length $3$: $10^{3} = 1{,}000$. Length $4$: $10^{4} = 10{,}000$.
  3. Sum rule: $1{,}000 + 10{,}000 = 11{,}000$.

Answer: $11{,}000$

Worked example: Cases, then products

How many three-digit numbers are even and have three different digits?
  1. The last digit must be even, and $0$ behaves differently because the first digit cannot be $0$. So split by the last digit.
  2. Last digit $0$: first digit $1$–$9$ ($9$ ways), middle digit anything else ($8$ ways): $9 \cdot 8 = 72$.
  3. Last digit $2$, $4$, $6$ or $8$ ($4$ ways): first digit not $0$ and not the last digit ($8$ ways), middle digit not either of those ($8$ ways): $4 \cdot 8 \cdot 8 = 256$.
  4. Sum rule: $72 + 256 = 328$.

Answer: $328$

Common mistake

Multiplying alternatives or adding a sequence. "Choose a dessert: one of $4$ pies or one of $3$ cakes" is $4 + 3 = 7$, not $12$; there is no second step. "Choose a pie and a cake" is $4 \cdot 3 = 12$, not $7$. Check: ask whether one outcome involves both choices (multiply) or just one of them (add).

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 1 XP.

Loading practice…

Builds on

Leads to

Sources and further reading

  • Oscar Levin, Discrete Mathematics: An Open Introduction (3rd ed.), section "Additive and Multiplicative Principles"
  • MIT OpenCourseWare 6.042J Mathematics for Computer Science (Lehman, Leighton and Meyer), chapter "Cardinality Rules" (sum and product rules)
@teddyrookbook GitHub