Counting Overlapping Sets
Section titled “Counting Overlapping Sets”Adding two set sizes counts their intersection twice. The principle of inclusion–exclusion corrects this:
For three sets,
An object in all three sets is counted three times, subtracted three times, then added once. Its final contribution is one, as required.
Example. How many integers from through are divisible by at least one of ?
A number divisible by both and is a multiple of . Use the corresponding least common multiples for the other intersections:
Thus integers satisfy at least one condition. Their complement contains integers.
General Inclusion–Exclusion
Section titled “General Inclusion–Exclusion”For a finite universe and forbidden sets , the number avoiding every forbidden condition is
To justify the alternating signs, take an object that belongs to exactly forbidden sets. Its contribution to the count of allowed objects is
An object belonging to no forbidden sets contributes one. This also explains why every intersection must be counted, even when it looks like it has already been removed.
If all -fold intersections have the same size , group them into . Otherwise, calculate their sizes separately.
Example. How many length-five strings over contain all three letters?
There are strings in total. Define a forbidden event for each missing letter. A specified missing letter leaves strings, and two specified missing letters leave one string. No length-five string can miss all three letters. The result is
Onto Functions
Section titled “Onto Functions”A function from an -element set to a labeled -element set is onto if every target is used. There are unrestricted functions. Declare “target is missed” to be the th bad event. Missing a specified collection of targets leaves functions, so for ,
This also counts assignments of distinct objects to distinct boxes with no empty box. It does not count distributions of identical objects.
Example. Four distinct tasks are assigned to three named workers, with every worker receiving a task. Find the number of assignments.
Using the onto-function count,
We can check by observing that the task counts must be : choose the worker receiving two tasks in ways, choose their tasks in ways, then assign the other two tasks in ways. This also gives .
Derangements and Fixed Positions
Section titled “Derangements and Fixed Positions”A derangement is a permutation with no fixed points. Let be the permutations that leave object in its original position. Fixing a specified set of positions leaves permutations, so
Example. Five letters are placed into five addressed envelopes, one per envelope. In how many assignments does no letter reach its own envelope?
Every assignment is a permutation, and the restriction is exactly a derangement. Thus
For exactly fixed points, first choose the fixed positions, then derange every remaining position. The count is . Merely arranging the remaining objects arbitrarily would allow additional fixed points and violate “exactly.”
Restricted Arrangements
Section titled “Restricted Arrangements”Some restrictions are easier to combine with blocks than with fixed positions. For example, in permutations of distinct objects, a specified adjacent pair can be treated as a block; intersections require checking whether several block conditions are compatible.
Example. Six distinct people stand in a row. Two specified people, Alice and Bob, must not be adjacent, and two other specified people, Carol and Dan, must not be adjacent. Find the number of valid orders.
There are unrestricted orders. Treating Alice and Bob as a block gives orders violating their restriction; Carol and Dan give the same count. When both pairs are adjacent, there are four units to arrange and two internal orders for each pair, giving . Hence
orders satisfy both restrictions. The pairwise intersection must be added back because it was subtracted twice.
Counting Exactly a Given Number of Conditions
Section titled “Counting Exactly a Given Number of Conditions”The ordinary union formula counts objects satisfying at least one condition. To count exactly one, exactly two, or another fixed number, the intersection sizes need different weights.
Let be the sum of all -fold intersection sizes, and let . An object lying in exactly sets contributes to . The number lying in exactly sets is
To justify the formula, consider one object in sets. Its contribution is
This is one when and zero otherwise. The calculation explains why merely subtracting pairwise overlaps once does not count objects satisfying exactly one condition.
Example. Among integers from one through one hundred, count those divisible by exactly one of two, three, and five.
The single-set total is . The pairwise total is , and the triple intersection has size .
Therefore
For comparison, exactly two conditions occur for integers, and all three occur for three integers. These counts sum to seventy-four, the union count.
The coefficients two and three are not arbitrary corrections. An object in two bad sets was counted twice in , while an object in three was counted three times and appears in three pairwise intersections. Track one hypothetical object to reconstruct the weights if you forget them.
Forbidden Positions and Compatible Intersections
Section titled “Forbidden Positions and Compatible Intersections”A restricted permutation can be represented by a board: rows are objects, columns are positions, and a forbidden cell records one disallowed assignment. A permutation selects exactly one cell in every row and every column.
When inclusion–exclusion chooses several forbidden cells, the corresponding events can occur together only if the cells lie in different rows and different columns. Compatible selections resemble nonattacking rooks on a chessboard.
Let count compatible selections of forbidden cells. Fixing those assignments leaves ways to place the remaining objects. Hence the number of allowed permutations is
This is the rook-number form of inclusion–exclusion. It generalizes derangements, whose forbidden cells are exactly the diagonal and have .
Example. Four distinct tasks are assigned one each to four distinct students A, B, C, D. A cannot receive task one or two, and B cannot receive task one. Find the number of valid assignments.
There are three forbidden cells: . Thus . Only together with is a compatible pair; the other pairs share a row or column. Hence , and no larger compatible selection exists.
The count is
As a direct check, A has two choices, then B has two allowed remaining choices, and the other students can be assigned in two ways. This also gives eight.
The board is useful because empty intersections become visible. Assuming all two-event intersections have the same size would fail here, even though the single-event sizes agree.
Onto Functions and Unlabeled Set Partitions
Section titled “Onto Functions and Unlabeled Set Partitions”Onto functions assign distinct objects to labeled nonempty boxes. An unlabeled set partition divides the objects into nonempty groups with no names on the groups. Each unlabeled partition into groups gives exactly onto assignments after the groups are labeled, so
for positive . The numbers are Stirling numbers of the second kind. They are different from integer partitions, which distribute identical objects.
Example. In how many ways can six distinct students be split into three nonempty, unlabeled study groups?
First count assignments to three named groups:
Each unlabeled grouping appears exactly times, because all three groups are nonempty and can be named in six ways. The answer is .
These numbers also satisfy . The last object either joins one of existing groups or forms a singleton group. The recurrence gives a useful independent check on an inclusion–exclusion computation.
The division by works here because the objects are distinct and the groups are nonempty. If empty groups were allowed, changing the labels of empty boxes would not create all distinct assignments, and the uniform overcount argument would fail.
Overlapping Word Patterns
Section titled “Overlapping Word Patterns”Inclusion–exclusion applies to forbidden adjacent patterns, but intersections may merge into larger blocks. When patterns overlap, determine the resulting arrangement explicitly before counting its permutations.
Example. How many permutations of the letters A, B, C, D, E contain neither the consecutive ordered pattern AB nor the consecutive ordered pattern BC?
There are permutations. Those containing AB are counted by treating AB as one block, giving . The same holds for BC.
If both patterns occur, their shared B forces the single ordered block ABC. The remaining three units, ABC, D, E, can be ordered in ways. Therefore the valid count is
Treating AB and BC as disjoint blocks would use B twice and give an invalid intersection count.
For a repeated-letter string, an occurrence can be indexed by its starting position. Several starting positions may force some of the same letters. Check consistency of those forced letters; incompatible overlaps contribute zero. This is often the point where a recurrence becomes simpler than a large inclusion–exclusion expansion.
Partial Inclusion–Exclusion and Bounds
Section titled “Partial Inclusion–Exclusion and Bounds”A full formula may have too many terms to calculate, while the first few terms already prove the required bound. For a union of sets,
The upper bound is the union bound. The lower bound subtracts pairwise overlaps but ignores higher corrections. More generally, an odd-length truncation of the alternating union sum is an upper bound, and an even-length truncation is a lower bound. These are Bonferroni bounds.
They can be understood one object at a time. An object appearing in sets has a partial contribution determined by alternating binomial coefficients. Its error has a predictable sign, so summing over objects preserves the bound.
Suppose one hundred objects belong to three properties, each property holding for thirty objects, with every pairwise overlap containing at most five. The union has at least objects. The full triple intersection is unnecessary for this lower bound because its omitted contribution is nonnegative.
Derangement Probability and Approximation
Section titled “Derangement Probability and Approximation”Dividing the derangement formula by gives the probability that a random permutation has no fixed points:
The infinite alternating series is . Its omitted terms decrease in magnitude, so the finite-sum error has magnitude less than . Multiplying back by yields
For , this identifies as the nearest integer to . The approximation comes with an error bound; it is not a substitute for an exact integer calculation when rounding could be uncertain.
It also shows that the no-fixed-point probability approaches approximately 0.368, even as the number of positions grows. The individual bad events become rarer, but their number grows at the same time. This is why multiplying independent-looking probabilities is tempting here and also why it needs care: fixed-point events are not independent.
An Exact Fixed-Point Probability
Section titled “An Exact Fixed-Point Probability”The derangement formula can be used inside a larger selection, but the remaining positions must have no extra fixed points.
Example. A uniformly random permutation of seven objects is chosen. Find the probability that exactly two objects remain in their original positions.
Choose the two fixed positions in ways. The other five objects must form a derangement, of which there are . Thus the number of successful permutations is , and the probability is
Using instead of would allow more fixed positions and would count permutations outside the requested event.
The selection and derangement steps describe one outcome uniquely: its actual fixed positions determine the chosen pair, and its restriction to the other positions determines the derangement. This is why no additional overcount correction is needed.