This blogpost is inspired to a large part by comments made by Rob Ghrist, in connection to his talks on using the Euler characteristic integration theory to count targets detected by sensor networks.
He pointed out that the underlying principle inducing the rule

goes under many names, among those \emph{Inclusion-Exclusion}, favoured among computer scientists (and combinatoricists). He also pointed out that the origin of this principle is the Mayer-Vietoris long exact sequence

In this blog post, I’d like to give more meat to this assertion as well as point out how the general principle of Inclusion-Exclusion for finite sets follows immediately from Mayer-Vietoris.
Inclusion-Exclusion, and the passage from two sets to many
The basic principle of Inclusion-Exclusion says that if we have two sets,
and
, then the following relationship of cardinalities holds:

A first proof would be performed by referring to an appropriate Venn
diagram, or by pointing out that if we try to count all the elements
of
by adding the counts for
and
, then we’ve overcounted the elements of
, and thus need to subtract these.
Now, this is good and convincing for the situation where we have just two sets, but what if we had a whole family? What if we had
? Well, our old friend the complete induction rides to our rescue. Suppose we had already proven that for
sets
, the following formula holds:

If you think this formula is imposing, let me show you the first few ways it works out, so that you can get a feeling for it:


Here it starts becoming apparent why it is called the Inclusion-Exclusion formula: we include all elements from all sets, but then we’ve gotten too many elements from the pairwise intersections, so we exclude those, but then we’ve gotten too few elements from the triple intersections, so we re-include those, but then we’ve gotten too few elements from the quadruple intersections – and on it goes.
If our assumption holds, we can consider what the appropriate size of the union of
different sets should be. We can pick one set, say
, and treat it separately. Then, certainly, the union of the rest has size given by the formula, by our induction assumption. So, consider what happens when we add in the elements in
. We then overcount all elements in any of the intersections
, so we have to subtract those. But we then have undercounted all elements in any intersection on the form
, so we need to add those back in. And so we go on, and for each intersection that occurred in the formula for
sets, we find ourselves forced to add one new term, of the opposite sign, that counts the intersection of that old term with
.
Thus, the new formula takes on the exact guise of the general formula we wanted to prove, since the terms involving
are precisely indexed, in that formula, by the terms excluding
, but with opposite signs.
Encoding set sizes homologically
So, now that we know that pairwise Inclusion-Exclusion implies the general Inclusion-Exclusion, let us take a look on how we can express Inclusion-Exclusion with homology. We note first of all that
counts the number of path-connected components of a space
. This follows easily from a few properties. First, a basis for the
-chains of
is given by the points in
. Second, two
-chains are homologous precisely if there is a
-chain whose boundary is the difference between those
-chains. The boundary of a path is the difference of its endpoints, so we end up with two basis elements being homologous precisely if there is a path connecting them.
Thus, two
-chain elements are homologous precisely if they’re in the same path-component of
. So, the homology classes of
-chains are precisely the path-connected components.
So, the
-degree homology classes count path-components. How do we use that? Well … if we consider a finite set
with the discrete topology – i.e. open sets are single points and any unions of single point sets, then a path is a continuous function
, i.e. one where the preimage of any open set is open. Thus, the preimage of any point is an open set. Suppose a path contains more than one point. Then we can partition the interval
into two disjoint open sets, by taking one set to be the preimage of one of the points, and the other set to be the preimage of everything else. However, the interval
is connected, which means that if there are two such open sets, one of them has to be empty.
Thus, the path-connected components of a discrete topological space are the points themselves. So if
is discrete, then
.
Long exact sequences in homology and the Mayer-Vietoris sequence
It is a theorem from homological algebra that if we have a short exact sequence of chain complexes

then there is a long exact sequence in homology given by

Almost all interesting long exact sequences in topology are special cases of this particular fact. We will derive one interesting sequence: the Mayer-Vietoris sequence from this.
Take a topological space
. The singular chain complex
forms a chain complex with
the free abelian group of
-chains and the differential given by the usual formula.
Suppose we have two spaces:
and
. Then any
-chain on
is an
-chain on
and an
-chain on
. So we get an inclusion map
by
. We choose this sign instead of the image
to make the next step cleaner. It is an injection because
is a free abelian group, and the injections
are set maps on bases for the corresponding chain groups.
Compatibility of this map with the differential is almost as easy. If we first apply the differential and then map into the direct sum, we get the map
. If we instead first map into the direct sum, and then apply the differentials, we get the map
. These are equal, and thus the map we’ve constructed is a chain map.
So,
is an injective map of chain complexes.
If we now have a pair of chains, we can construct a chain on the union of the two spaces. An
-chain on
is automatically an
-chain on
. Similarly, an
-chain on
is automatically an
-chain on
. So both
and
inject into
by the same kind of argument as with the injection
.
The injections we get this way can be put together to a map
by, for instance,
. I am going to fudge over the issue of whether the
-chains on
and
form a generating set for the
-chains on
, and just take it on faith that this works. The details are not particularly difficult – they are just obnoxiously long and annoying.
Now, given that we believe we can get a generating set by taking the union of the bases for the
-chains on
and
, then this means that the map I gave above is surjective. Indeed, a basis element
is hit by the element
, and a basis element
is hit by the element
.
This argument proves exactness at the first and last term of the short exact sequence

and it remains to prove exactness at the middle term. So we need to prove that

Now, since
, the inclusion of the image in the kernel is obvious. So, suppose now that
,
and
. Then, in
, we know that
. But then,
since
and similarly
since
. So
and
. But then this kernel element really is in the image of the inclusion we gave.
So this is a short exact sequence of chain complexes. It follows from the theorem of long exact sequences in homology that there is an associated long exact sequence, called the Mayer-Vietoris sequence:

Putting it all together
Suppose
is a discrete topological space. Then any continuous map from a
-simplex
to
is by necessity constant at one point. So all the singular simplices in
are constant maps, and thus a basis for any
-chain group is given by just the points in
as such. The differential acts on such a constant map by sending it to an alternating sum of identical maps the cardinality of which is one more than the dimension of the simplex. So the differential vanishes at every other point in the chain complex, and is an isomorphism on the rest. But then we have exactly two possibilities for a homology computation:
Case 1: 
Here, the kernel is the entire chain group. But so is the image. Thus the homology group is trivial.
Case 2: 
Here, the kernel is trivial, but then again, so is the image. Thus, again, so is the homology group.
The only part not really covered by this is the homology group
, since this is computed from a diagram on the shape
. So
behaves like we showed above, and is the only non-trivial homology group of the discrete space.
But then, the only bit that remains non-zero in the Mayer-Vietoris sequence is

If we have a short exact sequence of free abelian groups, then this relates the number of basis elements in each of the groups with the structure of the sequence. Let our short exact sequence be given by
. then, by injectivity of the map
, the cardinality of a basis of the image in
is equal to the cardinality of a basis for
. By surjectivity of the map
, and by Noether’s theorem, the cardinality of a basis of
is equal to the cardinality of a basis of the kernel of this map, plus the cardinality of a basis of
. By exactness in the middle, this kernel basis is equal to the image basis from A. So, we have, writing
for the cardinality of a basis of the free abelian group
, that
. Thus,
.
And if we apply this to the Mayer-Vietoris sequence fragment we acquired, it follows that

and thus

And no link? Sure, some of the details are off (damn the edge cases) as noted in the comments, but it’s easy enough to patch.
This is ’cause I said I didn’t like Buffy, isn’t it?