When sets overlap, you can't just add their sizes β you'd double-count the overlap. The principle of inclusion-exclusion (PIE) fixes this: add the singles, subtract the pairs, add back the triples, and so on. It's the generalization of complementary counting to multiple forbidden conditions.
For two sets A and B:
\[ |A \cup B| = |A| + |B| - |A \cap B| \]
Add both sets, then subtract the overlap that was counted twice.
Example: 30 students take math, 25 take physics, 10 take both. Total taking at least one = 30 + 25 - 10 = 45.
For three sets A, B, C:
\[ |A \cup B \cup C| = |A| + |B| + |C| - |A \cap B| - |A \cap C| - |B \cap C| + |A \cap B \cap C| \]
Pattern: add single sets, subtract pairwise intersections, add back triple intersection.
The triple intersection was subtracted too many times, so we add it back once.
For n sets $A_1, A_2, ..., A_n$:
\[ \left| \bigcup_{i=1}^{n} A_i \right| = \sum |A_i| - \sum |A_i \cap A_j| + \sum |A_i \cap A_j \cap A_k| - ... + (-1)^{n+1} |A_1 \cap ... \cap A_n| \]
Alternating sum over all non-empty subsets. Odd-sized intersections added, even-sized subtracted.
Total of \(2^{n}\) - 1 terms.
Most competition problems ask "how many have NONE of the bad properties?"
If U is the total and $A_i$ are the sets of items with property i:
\[ |U - \bigcup A_i| = |U| - \sum |A_i| + \sum |A_i \cap A_j| - \sum |A_i \cap A_j \cap A_k| + ... + (-1)^n |A_1 \cap ... \cap A_n| \]
Items with none of the properties = Total - at least one property.
This is the form you'll use 90% of the time. "None of the bad things" is the complement of "at least one bad thing."
A derangement is a permutation where no element appears in its original position.
Number of derangements of n elements, denoted !n:
\[ !n = n! \left(1 - \frac{1}{1!} + \frac{1}{2!} - \frac{1}{3!} + ... + (-1)^n \frac{1}{n!}\right) \]
Classic PIE application: let A_{i} = permutations where element i is fixed. Count permutations with none fixed.
Examples: !3 = 2, !4 = 9, !5 = 44
"How many numbers from 1 to 100 are divisible by 2 or 3 or 5?"
Classic PIE problem. Count multiples of each, subtract multiples of pairwise products, add back multiples of lcm of all three.
β100/2β + β100/3β + β100/5β - β100/6β - β100/10β - β100/15β + β100/30β
Number of onto functions from an n-element set to a k-element set:
\[ \sum_{i=0}^{k} (-1)^i \binom{k}{i} (k-i)^n \]
PIE: total functions \(k^{n},\) minus those missing at least one element, add back those missing two, etc.
Often all single-set sizes are equal, all pairwise intersections equal, etc. Then PIE simplifies:
$ |\bigcup A_i| = \binom{n}{1}|A_1| - \binom{n}{2}|A_1 \cap A_2| + \binom{n}{3}|A_1 \cap A_2 \cap A_3| - ... $
Use binomial coefficients to count how many terms of each size there are. This saves a lot of computation.
\(Inclusion-Exclusion for two sets: |A \\cup B| = |A| + |B| - |A \\cap B|\)
Step 1: Identify the sets.
A = basketball players, |A| = 18
B = soccer players, |B| = 15
\(A \\cap B = both sports, |A \\cap B| = 7\)
Step 2: Apply formula.
\[ |A \cup B| = 18 + 15 - 7 = 26 \]
Why subtract 7? The 7 students who play both were counted twice β once in basketball, once in soccer. We subtract them once to correct the overcount.
Venn diagram check: Basketball only = 18 - 7 = 11, Soccer only = 15 - 7 = 8, Both = 7. Total = 11 + 8 + 7 = 26 β
Answer: 26
Use inclusion-exclusion (complement form).
\(Let A_{i} = permutations where element i is fixed (in position i).\)
\(We want permutations with NONE fixed: total - |A_{1} \\cup A_{2} \\cup A_{3} \\cup A_{4}|\)
Step 1: Total permutations = 4! = 24
Step 2: \(\(Single fixed positions. |A_{i}\(| = 3! = 6 for each i. There are \binom{4}{1} = 4 such sets.\)\)\)
\(Sum = 4 \\times 6 = 24\)
Step 3: \(Two fixed positions. |A_{i} \(\\cap A\)_{j}\(| = 2! = 2. \binom{4}{2} = 6 pairs.\)\)
\(Sum = 6 \\times 2 = 12\)
Step 4: \(Three fixed positions. |A_{i} \(\\cap A\)_{j} \(\\cap A\)_{k}\(| = 1! = 1. \binom{4}{3} = 4 triples.\)\)
\(Sum = 4 \\times 1 = 4\)
Step 5: \(All four fixed. |A_{1} \\cap A_{2} \\cap A_{3} \\cap A_{4}| = 0! = 1. \binom{4}{4} = 1.\)
Step 6: PIE (complement form).
\[ !4 = 24 - 24 + 12 - 4 + 1 = 9 \]
List them for n=4: 2143, 2341, 2413, 3142, 3412, 3421, 4123, 4312, 4321 = 9 derangements β
Answer: 9
Two-set PIE: divisible by 2 OR 3 = divisible by 2 + divisible by 3 - divisible by both (i.e., by lcm(2,3)=6)
Step 1: Count multiples of 2 in [1, 100].
β100/2β = 50 numbers (2, 4, 6, ..., 100)
Step 2: Count multiples of 3 in [1, 100].
β100/3β = 33 numbers (3, 6, 9, ..., 99)
Step 3: Count multiples of both 2 and 3 = multiples of 6.
β100/6β = 16 numbers (6, 12, ..., 96)
Step 4: Apply PIE.
\[ |A \cup B| = |A| + |B| - |A \cap B| = 50 + 33 - 16 = 67 \]
Check: Multiples of 2 only: 50 - 16 = 34. Multiples of 3 only: 33 - 16 = 17. Both: 16. Total = 34 + 17 + 16 = 67 β
Answer: 67