Sub topic 9
The three-set inclusion-exclusion formula
This chapter assumes you can draw a two-set Venn diagram and use n(A∪B) = n(A) + n(B) − n(A∩B). It also assumes you can solve simple linear equations. Here the same idea extends to three overlapping groups. This is the standard tool for CAT problems that give three subjects, three brands or three newspapers.
Why adding the sets overcounts
Suppose you add n(A) + n(B) + n(C). An element that belongs to only one set is counted once, which is correct. An element in exactly two sets is counted twice. An element in all three sets is counted three times.
To fix this, subtract the pairwise overlaps n(A∩B), n(B∩C) and n(A∩C). That fixes the double counts, but it over-corrects for the triple-overlap elements. Such an element sits in all three pairwise overlaps, so it is subtracted three times. It started with three counts and now has zero. The last step adds n(A∩B∩C) back once.
The formula
n(A∪B∪C) = n(A) + n(B) + n(C) − n(A∩B) − n(B∩C) − n(A∩C) + n(A∩B∩C)
The signs alternate: add the singles, subtract the pairs, add the triple. The following table tracks how many times each region is counted at each step.
| Region | Singles added | Pairs subtracted | Triple added | Net count |
|---|---|---|---|---|
| Exactly one set | 1 | 0 | 0 | 1 |
| Exactly two sets | 2 | 1 | 0 | 1 |
| All three sets | 3 | 3 | 1 | 1 |
Every element ends up counted exactly once. That is the whole proof.
Worked example: the union and the regions
A survey records three groups. 30 people are in A, 25 in B and 20 in C. Also, 10 are in both A and B, 8 in both B and C, and 6 in both A and C. Finally, 4 people are in all three.
n_a, n_b, n_c = 30, 25, 20
n_ab, n_bc, n_ac = 10, 8, 6
n_abc = 4
union = n_a + n_b + n_c - (n_ab + n_bc + n_ac) + n_abc # 55
exactly_three = n_abc # 4
exactly_two = (n_ab + n_bc + n_ac) - 3 * n_abc # 12
exactly_one = union - exactly_two - exactly_three # 39
print(union, exactly_one, exactly_two, exactly_three) # 55 39 12 4The union is 75 − 24 + 4 = 55. Subtracting 3 × n(A∩B∩C) from the pairwise total gives the "exactly two" count. Each triple-overlap element was counted in all three pairwise overlaps, so removing it three times leaves only the people in exactly two sets.
Filling the eight regions
Work from the innermost region outward.
- Put 4 in the centre (A∩B∩C).
- "A and B only" is 10 − 4 = 6. "B and C only" is 8 − 4 = 4. "A and C only" is 6 − 4 = 2.
- "A only" is 30 − 6 − 2 − 4 = 18. "B only" is 25 − 6 − 4 − 4 = 11. "C only" is 20 − 4 − 2 − 4 = 10.
- Check: 18 + 11 + 10 + 6 + 4 + 2 + 4 = 55, which matches the union.
The eighth region is "none of the three", which lies outside all circles. It is not part of the union, so it does not appear in the chart.
Working with a universal set
CAT problems usually give a total and ask about people in none of the groups. A class has 120 students. Of them, 70 like tea, 60 like coffee and 50 like juice. Also, 30 like tea and coffee, 25 like coffee and juice, 20 like tea and juice, and 10 like all three.
- Union = 70 + 60 + 50 − (30 + 25 + 20) + 10 = 180 − 75 + 10 = 115.
- None of the three = 120 − 115 = 5.
- Exactly two = 75 − 3 × 10 = 45.
- Exactly one = 115 − 45 − 10 = 60.
You can confirm the "exactly one" figure region by region. Tea only is 70 − 20 − 10 − 10 = 30. Coffee only is 60 − 20 − 15 − 10 = 15. Juice only is 50 − 15 − 10 − 10 = 15. These sum to 60.
Two shortcut identities
Let x, y and z be the counts of people in exactly one, exactly two and exactly three sets. Then two relations hold.
- Union: n(A∪B∪C) = x + y + z.
- Membership total: n(A) + n(B) + n(C) = x + 2y + 3z. Each person is counted once for every set they belong to.
Subtracting the first from the second gives n(A) + n(B) + n(C) − n(A∪B∪C) = y + 2z. In the first example, 75 − 55 = 20 = 12 + 2 × 4. This relation is useful when the problem gives the "exactly" counts instead of the pairwise overlaps. For example, if the total number of people in the union, the number in exactly two sets and the number in all three sets are known, you can find the sum of the individual set sizes without ever computing a pairwise overlap.
Solving for an unknown
The formula is one equation, so it can solve for one missing quantity. Suppose 60 people are in at least one set. The three set sizes total 80, and the three pairwise overlaps total 30. Find n(A∩B∩C).
60 = 80 − 30 + n(A∩B∩C), so n(A∩B∩C) = 10.
Most CAT problems have one unknown, but it is not always the triple overlap. If the unknown is a single pairwise overlap, the other two pairwise values and the triple must be known. If two quantities are missing, look for a second relation, such as a total or an "exactly two" figure.
Checking a solution in code
A solver should reject inputs that give a negative region. This function builds all eight regions and raises an error if any region is impossible.
def regions(total, a, b, c, ab, bc, ac, abc):
only_ab = ab - abc
only_bc = bc - abc
only_ac = ac - abc
only_a = a - only_ab - only_ac - abc
only_b = b - only_ab - only_bc - abc
only_c = c - only_bc - only_ac - abc
union = a + b + c - ab - bc - ac + abc
result = {
"A only": only_a, "B only": only_b, "C only": only_c,
"AB only": only_ab, "BC only": only_bc, "AC only": only_ac,
"ABC": abc, "none": total - union,
}
for name, value in result.items():
if value < 0:
raise ValueError(f"inconsistent data: {name} = {value}")
return result
print(regions(120, 70, 60, 50, 30, 25, 20, 10))
# {'A only': 30, 'B only': 15, 'C only': 15, 'AB only': 20,
# 'BC only': 15, 'AC only': 10, 'ABC': 10, 'none': 5}If you change the data to regions(120, 70, 60, 50, 30, 25, 20, 40), the call fails because "AB only" becomes negative. The overlap data cannot be satisfied by any real group of people.
Common errors
- Using "only" counts as pairwise totals. Substituting "only A and B" for n(A∩B) removes the triple overlap twice. Convert first, so n(A∩B) = (A and B only) + n(A∩B∩C).
- Forgetting the triple term. Without + n(A∩B∩C), the answer is too small by that amount.
- Subtracting the triple instead of 3 × the triple for "exactly two". The sum of pairwise overlaps includes the triple three times.
- Treating "at least two" as "exactly two". At least two equals exactly two plus exactly three.
- Forgetting the outside region. The union is not the universal set unless the problem says everyone belongs to at least one group.
- Skipping the final check. Add all eight regions and compare the sum with the total.
Exercises
Exercise
In a college of 200 students, 90 play cricket, 80 play football and 70 play tennis. 30 play cricket and football, 25 play football and tennis, 20 play cricket and tennis, and 10 play all three. How many play none of the three, and how many play exactly one sport?
Show answer
Union = 90 + 80 + 70 − (30 + 25 + 20) + 10 = 240 − 75 + 10 = 175. None = 200 − 175 = 25. Exactly two = 75 − 3 × 10 = 45. Exactly one = 175 − 45 − 10 = 120.
Exercise
Every one of 100 people reads at least one of newspapers P, Q and R. n(P) = 50, n(Q) = 45, n(R) = 40. Exactly 30 people read exactly two papers, and 10 people read all three. Find the number who read exactly one paper, and then check that the sum of the pairwise overlaps n(P∩Q) + n(Q∩R) + n(P∩R) is consistent.
Show answer
Exactly one = 100 − 30 − 10 = 60. The membership total gives 50 + 45 + 40 = 135 = 60 + 2 × 30 + 3 × 10 = 150? That gives 150, not 135, so the data are inconsistent. Equivalently, the pairwise overlaps would sum to 30 + 3 × 10 = 60, and the formula would give 135 − 60 + 10 = 85, not 100. No such group of readers exists. This is the kind of check to run before trusting a CAT-style answer.