In one sentence
When several sets are pairwise disjoint, the size of their union is the sum of their sizes (the addition principle). When they overlap, the overlaps are counted too often and must be subtracted; if you subtract too much, add it back:
This is the inclusion–exclusion principle. The workbench above marks how many times each region has been counted: the formula is right exactly when every region is counted time.
Why every region is counted exactly once
Step 1 / 4- Add everything first
: regions inside one circle are counted time, regions inside two circles times, and the middle times.
Stop 1 · Integers: counting “none of them”
How many numbers in are coprime to ? Being coprime to means being a multiple of neither , nor , nor : the region outside all the circles. Above, the circles hold numbers, so the outside has .
Predict first
How many numbers in are multiples of neither , nor , nor ?
Three circles: , , ; (multiples of ), , ; (multiples of ).
, so lie outside.
Stop 2 · Permutations: derangements
letters go into addressed envelopes, every letter in a wrong envelope. In how many ways can this happen?
Counting derangements by inclusion–exclusion
Step 1 / 4- Set up the sets
There are ways to fill the envelopes. Let be the ways in which letter is in the right envelope. We want the ways that lie in none of the .
Stop 3 · Mappings: no empty box
In how many ways can different balls go into different boxes with no box empty? Two ways of thinking, and the answers must agree:
One problem, several solutions
different balls go into different boxes with no box empty. Count the ways.
Inclusion–exclusion: remove the ways with an empty box
Without restrictions there are ways. Let be “box is empty”: , , and all three empty is impossible.
The ways with an empty box number , so the ways with no empty box number .
CostMechanical, and works just as well for balls and boxes.
Partitions: group first, then assign
First split the balls into non-empty groups: ways (an exercise in station 4). Then hand the groups to the boxes: ways.
In all, ways.
CostYou need to count partitions first (station 4), but the structure is clearer.
Practice
How many numbers in are multiples of or multiples of ?
A class has students. are in the math club, are in the physics club, and are in neither. How many are in both?
people each write a greeting card. The cards are collected and handed back at random, one per person. In how many ways can this be done so that nobody gets their own card?
In how many ways can different balls go into different boxes with no box empty?