In the tutorials, it was argued that for any two finite sets and , and equality holds if the sets are disjoint. Can I say something stronger in the general case?

All sets are assumed to be finite in the section.

Proposition.

If , then .

Proof:

Obviously and are disjoint sets, so by the result from the tutorials, . Using that , I get and so the result follows.

The inclusion-exclusion principle

Corollary.

For any sets and ,

Proof:

By the proposition,

Inclusion-exclusion principle.

For any finite family of finite sets ,

You will need this technical lemma to complete the proof:

Lemma.

For ,

Proof of lemma:

By associativity and commutativity of the intersection,

Proof of the inclusion-exclusion principle:

By induction on . The case when is trivial. The case when is the corollary at the beginning of this section.

I will assume the inclusion-exclusion principle holds for any family of finite sets of size . Now let be an arbitrary family of finite sets.

On the one hand, expanding the left-hand side and using the inductive hypothesis twice:

On the other hand, expanding the right-hand side by ordering the sum by the size of , I apply the lemma above and simplify:

The first double sum is just

and the latter double sum, the indexing goes from to . When , the intersection is just ; therefore the second double sum may be rewritten as

Combining both, I see that they are equal, hence the theorem is proved.

For example, for three sets, we have , so the right-hand sum iterates over three singletons, three complements of singletons and (there are seven nonempty subsets of in this case). Therefore,

Just as a sanity check, I write the following “obvious” fact, which can be of course proved using much simpler methods.

Corollary.

Assume, in addition to the hypotheses of the inclusion-exclusion principle, that the sets are pairwise disjoint. Then,

Proof:

If the sets are pairwise disjoint, all intersections of two or more are empty. Therefore, only the cases when are singleton sets contribute to the sum, which simplifies to the above.

Application: Euler’s totient function

Let denote the number of invertible elements of . In Chapter 2, I proved that an integer is invertible mod if and only if . I will show you a formula for computing when the prime factorization of is known.

Suppose that where the are distinct primes and . Therefore, if and only if no divides . Let be the set of integers that are divisible by . The union of all the is thus precisely the set of elements of that are not invertible.

For each , consists of the multiple of , of which there are . Similarly, for any prime factors of , , there are many integers that share that prime factor. By the inclusion-exclusion principle, the number of integers that share no prime factors with is

Application: derangements

In many situations, the above formula may be simplified. One such example is when the summand depends only on the size of (and not the particular elements of ).

Corollary.

Add to the hypotheses of the inclusion-exclusion principle the condition that there is a function such that for all . Then,

Proof:

By the inclusion-exclusion principle, it is sufficient to notice that

A derangement is a permutation with no fixed points. That is, let be a bijection . Then is called a derangement if for all , . How many of the permutations are derangements? I will denote the number of derangements of a set of size by . Thus obviously .

Exercise.

Show that by using a combinatorial argument, that is, without using the formula below.

Derangement formula.

From Calculus, I know that the McLaurin series of the exponential function gives me

and thus is a good approximation of the probability that a random permutation of objects, for large , is a derangement. This limit converges rather quickly, and so with high probability, a random shuffle of cards will leave at least one card in the same place, for instance.

Exercise.

Show that and give a combinatorial interpretation of it.

The stars and bars theorem

Suppose I have bins and indistinguishable objects to put in them. If bins can be left empty, in how many ways can I place the objects in the bins?

The correct way to think about this problem is to ignore the bins and instead picture the bars separating the bins. As an example, here I placed an object in the first bin, left the second bin empty, three objects in the third bin, and so on.

Interchanging two stars makes no difference and I consider the arrangement the same (that’s what the object being indistinguishable means). There are two ways of counting the number of such arrangements. First, notice I have stars and bars for a total of symbols being permuted. The stars and bars are indistinguishable among themselves, so I must divide by each permutation of the two groups. In total, there are

star and bars arrangements. Alternatively, I can think of this as selecting, from a set of symbols, those that will be drawn as bars, or those that will be drawn as stars. In other words, respectively,

Of course, all of these numbers are equal.

Application: Number of Diophantine solutions

How many positive integers solve the equation

What about non-negative solutions?