7.01k–7.01m - Inclusion-exclusion and derangements
Count a union without counting overlaps twice, extending inclusion-exclusion from two sets to three or more. Then count small derangements directly: arrangements in which every object is away from its own position, including questions that prescribe an exact number of correctly placed objects.
Inclusion-exclusion for two sets
Four labelled letters are put into four correspondingly labelled envelopes, one letter per envelope. How many arrangements put every letter in a wrong envelope? “All arrangements minus the ones with a correct letter” sounds promising, but an arrangement with two correct letters belongs to two forbidden groups. We first need a reliable way to correct overlapping counts.
If pupils study a language and study music, with doing both, adding counts those three pupils twice. The union therefore has pupils. Subtract the overlap once, leaving each person counted once.
You already know
means membership of either set, including both; means membership of both. is the size of a finite set. A complement is taken within a stated universal set.
The same correction works whether the elements are people, integers, or arrangements satisfying different conditions.
Two-set inclusion-exclusion
For finite sets and :
This is the two-set case of the three-set formula supplied in the booklet, obtained by taking the third set to be empty.
Not in the formula booklet: learn it.
For divisibility conditions, the intersection consists of multiples of the least common multiple. For example, multiples of both and are multiples of , rather than of . The number of multiples of from to is , where the floor means rounding down; this counting result is not separately printed in the booklet.
Worked example 1: multiples of either divisor
Question. Determine how many integers in are divisible by or . Hence find how many are divisible by neither.
Plan. Count the two sets and their intersection, then subtract the union from the universal set.
Why this step? A multiple of has been included in both initial counts; subtracting its second occurrence leaves it in the union once.
Answer. integers are divisible by or , and are divisible by neither.
Check. The disjoint regions have sizes , , and , totalling .
The next example changes only the upper limit. Keep the same divisors and overlap rule, but recalculate every count.
Worked example 2: a different upper limit
Question. Determine how many integers in are divisible by or , and how many are divisible by neither.
Plan. Use the same sets within the new universe.
Why this step? is not itself a count of integers: only the completed multiples fit below or at .
Answer. are divisible by at least one of the divisors; by neither.
Check. , and the union is at least as large as either individual set.
The words “or” and “neither” lead to different final operations.
Watch out
“Divisible by neither nor ” means outside the union. Subtracting the intersection from the total instead would leave integers divisible by exactly one of the two divisors, which are forbidden by “neither”.
Write counts of actual elements, not probabilities, when the question asks “how many”.
Three or more overlapping sets
With three sets, subtracting all pairwise intersections removes elements in all three sets too often; they must be added back.
An element in is counted three times in . It then occurs in each of the three pairwise intersections, so subtracting those leaves it counted zero times. Adding the triple intersection restores its one required occurrence. An element in exactly two sets is counted twice and subtracted once; an element in exactly one set is counted once throughout.
Three-set inclusion-exclusion
For finite sets , and :
In the formula booklet.
Pairwise intersections include the triple intersection. If you are given , do not silently treat it as “in and only”.
[DIAGRAM: asset_name: Three-set overlaps counted once; asset_slug: h245_7_01_three_sets; caption: Among the integers from 1 to 120, the three divisibility sets have seven disjoint regions totalling 88, leaving 32 outside; description: Three overlapping circles labelled A multiples of 2, B multiples of 3 and C multiples of 5. The A-only region is labelled 32, B-only 16, C-only 8; pairwise-only regions AB, AC, BC are labelled 16, 8, 4 respectively; the central triple region is labelled 4. The rectangle outside the circles is labelled 32. A lower counting line reads 60 + 40 + 24 - 20 - 12 - 8 + 4 = 88]

The numbers in the picture are region counts; the pairwise intersection sizes used in the formula also include the centre.
Worked example 3: three divisibility conditions
Question. Use inclusion-exclusion to determine how many integers in are divisible by , or .
Plan. Count each divisor, each pair's least common multiple and the triple's least common multiple.
Why this step? The four multiples of were included in all three initial sets and all three subtracted intersections; the final addition is essential.
Answer. integers.
Check. In each consecutive block of integers, are divisible by at least one of . Four such blocks give .
The next example changes only the upper limit, so every set and intersection has the same definition.
Worked example 4: a second three-set count
Question. Use inclusion-exclusion to determine how many integers in are divisible by , or .
Plan. Recalculate all seven terms using the upper limit .
Why this step? A three-set formula needs all three pairwise terms, not just the intersection of the first two sets followed by an extra single-set count.
Answer. integers.
Check. Five complete blocks of give , consistent with the first example.
For four sets, the same correction continues: add singles, subtract all six pairwise intersections, add all four triple intersections, and subtract the intersection of all four. For more sets, continue alternating signs. An element belonging to exactly sets must end with total coefficient ; this explains the repeated corrections. The general extension is not printed in the booklet; reconstruct it from this alternating pattern.
Watch out
Do not omit the final triple intersection. For an element in all three sets, , so the element would vanish from a union to which it certainly belongs. The correct coefficient is .
A direct substitution into the supplied formula gives a cleaner final method than a collection of unlabelled partial sums.
Continue this lesson.
You’re previewing NovaLearn without an account. Create a free account to read the rest.
Create free account