# Counting and Cardinality

The cardinality of a set is roughly the number of elements in a set. This poses few difficulties with finite sets, but infinite sets require some care.

I can tell that two sets have the same number of elements by trying to pair the elements up. For example, the sets

have the same number of elements because I can pair the elements of the first set with the elements of the second:

This kind of pairing is called a bijection or a one-to-one correspondence; it's easy to understand with finite sets, but I need to be more careful if I'm going to use the same idea with infinite sets. I'll begin by reviewing the relevant definitions.

Definition. Let X and Y be sets and let be a function.

1. f is injective if implies .
2. f is surjective if for all , there is an such that .
3. f is bijective (or a one-to-one correspondence) if it is injective and surjective.

Definition. Let S and T be sets, and let be a function from S to T. A function is called the inverse of f if

I proved the following lemma earlier.

Lemma. Let S and T be sets, and let be a function. f is invertible if and only if f is bijective.

Example. Let

Define by

I'll show that f is a one-to-one correspondence by constructing an inverse for f. The inverse should "undo" the effect of f:

As you can see, I need to define

I've constructed so that for all . To be complete, I should check that it works the other way, too:

So really is the inverse of f, and f is a bijection. (For that matter, is a bijection as well, because the inverse of is f.)

Notice that this function is also a bijection from S to T:

If there is one bijection from a set to another set, there are many (unless both sets have a single element).

I introduced bijections in order to be able to define what it means for two sets to have the same number of elements. The number of elements in a set is called the cardinality of the set.

Definition. Sets S and T have the same cardinality if there is a bijection f from S to T. I'll write to mean that S and T have the same cardinality.

A set S is finite if it is empty, or if there is a bijection for some integer . A set which is not finite is infinite.

If S is a nonempty finite set and there is a bijection for some integer , I'll say that S has cardinality n or that S has n elements. In this case, I'll write .

At this point, there is an apparently silly issue that needs to be resolved: Could a finite set be bijective with both and (say)? Of course, everyday experience says that this is impossible. However, mathematicians always take the point of view that if something is really obvious, then it ought to be easy to justify.

Actually, this particular point isn't that simple to justify --- try to prove it yourself! --- but it's true, and I'll omit the proof.

Example. Prove that the set of natural numbers has the same cardinality as the set of positive even integers.

Define by

This function has an inverse given by

Note that since , m is even, so m is divisible by 2 and is actually a positive integer.

Here's the proof that f and are inverses:

This situation looks a little strange. E is contained in , but I've just shown that the two sets "have the same number of elements". The only reason this looks funny is that it contradicts your real world experience --- which only deals with finite objects. In fact, it's characteristic of infinite sets that they have the same number of elements as some of their proper subsets.

Informally, if the elements of an infinite set can be listed

then the set has the same cardinality as the natural numbers.

In fact, to define listable precisely, you'd end up saying "the set has the same cardinality as the natural numbers". But this is a good picture to keep in mind. I'll show that the real numbers, for instance, can't be arranged in a list in this way.

The next part of this discussion points out that the notion of cardinality behaves the way "the number of things in a set" ought to behave.

Lemma. Let S, T, and U be sets.

1. The identity function given by is a bijection.
2. The inverse of a bijection is a bijection.
3. If and are bijections, then the composite is a bijection.

Proof. (a) The identity function has an inverse, namely itself. Therefore, the identity function is a bijection.

(b) If is a bijection, then by definition it has an inverse . To be inverses means that

But these equation also say that f is the inverse of , so it follows that is a bijection.

(c) Suppose that and are bijections. Let and be their respective inverses. I'll prove that is the inverse of .

This proves that is the inverse of , so is a bijection.

Corollary. Let S, T, and U be sets.

1. (Reflexivity) .
2. (Symmetry) If , then .
3. (Transitivity) If and , then .

Proof. (a) By the lemma, the identity function is a bijection, so .

(b) If , then there is a bijection . By the lemma, is a bijection. Therefore, .

(c) If and , then there are bijections and . By the lemma, is a bijection, so .

As you know, these three properties mean that having the same cardinality is an equivalence relation. This actually justifies my use of the " " when I write " ".

Example. Prove that the interval has the same cardinality as .

(Remember that stands for the open interval .)

First, notice that the open interval has the same cardinality as the real line. To prove this, I have to construct a bijection . It's easy: just define

To show that f is bijective, I have to show that it has an inverse; the inverse is .

Now I know that and have the same cardinality. Next, I'll show that and have the same cardinality.

The idea is to multiply by to stretch to . Then I subtract to shift to .

All together, I define by

First, if , then , so . This shows that g takes inputs in and produces outputs in .

To show that g is bijective, I have to produce an inverse. The standard "swap the x's and y's" procedure works; you get

Here's the proof that g and are inverses:

Therefore, g is a bijection, so and have the same cardinality. By transitivity, and have the same cardinality.

Example. Prove that has the same cardinality as .

Define by

Note that if

Therefore, f does map to .

I claim that . If , then , so maps to . Moreover,

Thus, f is a bijection.

Define by

If , then . Therefore, g does map to .

I claim that . If , then , so maps to . Moreover,

Therefore, g is a bijection.

With the bijections f and g, I have , so and have the same cardinality.

In many situations, it's difficult to show that two sets have the same cardinality by actually constructing a bijection between them. The theorem that follows gives an indirect way to show that two sets have the same cardinality.

Theorem. (Schröder-Bernstein) Let S and T be sets. Suppose there are injective functions and . Then S and T have the same cardinality.

The proof of the Schröder-Bernstein theorem is a little tricky, so I won't do it here.

The Schröder-Bernstein theorem says that if S has the same cardinality as a subset of T, and T has the same cardinality as a subset of S, then S and T must have the same cardinality.

It is a powerful tool for showing that sets have the same cardinality. Here are some examples.

Example. Show that the open interval and the closed interval have the same cardinality.

The open interval is a subset of the closed interval . In this situation, there is an "obvious" injective function , namely the function for all . (f is called an inclusion map.) If , then , so f is injective.

Next, I'll construct an injective function . The idea is to find a "copy" of in , then do some scaling and translation to map onto the copy. I'll use the interval as my target in . The target has length 0.5, so I'll multiply by 0.5 to shrink to . Next, I'll add 0.25 to shift to . All together, I get

First, if , then , so . This proves that g is a function from to .

Next, I need to show that g is injective. Suppose that , I must prove that . Now means that

Therefore, g is injective. (In fact, g is bijective, and you could prove injectivity by constructing --- though it would be overdoing it a bit.)

Now I have injective functions and . By Schröder-Bernstein, .

Example. Prove that has the same cardinality as .

The two sets don't "look alike" --- the first set is a single interval which is closed on both ends, while the second set consists of two open intervals. When two sets don't look alike but you think they have the same cardinality, consider using the Schröder-Bernstein theorem. I'll define injective functions going from each set into the other.

I'll describe in words how I'm getting the definitions of the functions. (Note that there are many functions you could use to do this!)

The first set is an interval of length 2, which (because of its endpoints) won't fit in either of the intervals that make up the second set. Since the second set's intervals don't have endpoints, if I just slide over, its endpoints will stick out of the ends of either or . So the idea is to shrink first, then slide it inside either or .

If I multiply by 0.5, I get , an interval of length 1. This will surely fit inside (say), and I can slide into by adding 2. This takes to . I just have to do the two steps one after the other. So define by

First, I have to show that this makes sense --- that is, that f really takes into . Suppose . Then

Since , obviously , so f {\it does} map into .

Next, I have to show that f is injective. Suppose . Then

Hence, f is injective.

Next, I have to define an injective function . Now occupies a total length of , whereas the target interval has length 2. If I multiply by , I'll shrink to , which has a total length of 1. Next, I can slide inside by subtracting 0.7, which should give .

Thus, define by

I need to check that g maps into . Let . Then certainly x is between 1 and 6, i.e. . (Of course, does not imply that . Do you see why?) So

Since , obviously , so g {\it does} map into .

Next, I have to show that g is injective. Suppose . Then

Therefore, g is injective.

Hence, and have the same cardinality, by the Schröder-Bernstein theorem.

I've already noted that it's easy to find finite sets of different cardinalities: for example, a set with three elements does not have the same cardinality as a set with 42 elements. I've also given examples of infinite sets which have the same cardinality. It's an important fact that not all infinite sets have the same cardinality --- there are different kinds of "infinity"! Here's some terminology which I'll used to describe the situation.

Definition. A set is countably infinite if it has the same cardinality as the natural numbers . An infinite set which is not countably infinite is uncountably infinite or uncountable.

A set is countable if it is either finite or countably infinite.

I know that some infinite sets --- the even integers, for instance --- are countably infinite. I know of other infinite sets, such as the real numbers. Is the set of real numbers countably infinite? The answer is no; the proof is due to Georg Cantor (1845--1918), and is called the diagonalization argument.

Theorem. The open interval is uncountably infinite.

Proof. I'm going to be a little informal in this proof so that the main idea isn't lost in a lot of notation.

Suppose on the contrary that is countably infinite. Represent numbers in the interval as decimals . (If a number ends in an infinite sequence of 9's, rewrite it as a finite decimal --- so, for instance, becomes 0.135.) Since is countably infinite by assumption, I can arrange the numbers in in a list:

I emphasize that, by assumption, this list contains all of the numbers in the interval .

Now go down the diagonal and make a number using the digits. In this case, I get the number .

Take each of the digits in this number and change it to any other digit except 9. For example, you could add 1 to each digit from 0 to 7 and change 8 or 9 to 0. This would produce the number .

(The reason you do not want to change digits to 9 is so that you don't wind up with a number that ends in an infinite sequence of 9's.)

The number differs from each of the numbers in my list. Specifically, the digit of is different from the digit in the number on the list. This means that is not in my list --- which is a contradiction, because I assumed that my list contained all of the numbers in the interval .

Therefore, the interval must be uncountably infinite.

Since the interval has the same cardinality as , is uncountably infinite as well. Notice that (which is countably infinite) is a subset of . Are there any sets which are "between" and in cardinality?

The Continuum Hypothesis states that there are no sets which are "between" and in cardinality; it was first stated by Cantor, who was unable to construct a proof. Kurt Gödel [2] proved around 1940 that the Continuum Hypothesis was consistent relative to the standard axioms of set theory. Paul Cohen [1] proved in 1963 that the Continuum Hypothesis is undecidable: It is independent of the standard axioms for set theory.

In other words, the question of the existence of a subset of which has cardinality different from either or can't be settled without adding assumptions to standard mathematics --- and you can assume either that such a set exists, or that it doesn't, without causing a contradiction.

Definition. Let S be a set. The power set of S is the set of all subsets of S.

Example. Let . The power set of S is

Notice that the power set includes the empty set and the set S itself.

If you're constructing a subset of a set, there are two alternatives for each element: Either it is in the subset, or it is not. So if the set has n elements, the two alternatives for each element give possibilities in all. Therefore, if S is finite and , then .

In this example, , and .

Theorem. If S is a set, then S and do not have the same cardinality.

Proof. Suppose first that . Now , so . Hence, while , and the result is true in this case.

Now suppose that . I'll prove the result by contradiction. Suppose that . This means that there is a bijection .

Since f is a bijection, every element of the power set --- that is, every subset of S --- is paired up with an element of S. For example, there must be an element for which .

Of course, . So s is an element which is paired up with a subset that doesn't contain it. And in general, f takes an element of S to a subset of S, and that subset either contains the element or it doesn't.

Here's a particular example to help you get your bearings. In the picture below, the set is and the function f is depicted by the arrows.

In this example, f takes b and c to subsets that contain them; f takes a and d to subsets which don't contain them.

Continuing with the proof, let

That is, T is the subset of elements of S which f takes to subsets which don't contain them. I know there is at least one such element, namely the element which f takes to the empty set.

Now f is bijective, and T is a subset of S, so there is an element such that . Question: Is ?

If , then by definition of T, . This is a contradiction.

If , then , so satisfies the defining condition for T --- which means . This is a contradiction.

Since and both lead to contradictions, I've actually contradicted my first assumption --- that . Therefore, , as I wanted to prove.

Example. The power set of the natural numbers has the same cardinality as .

I showed earlier that is countably infinite, whereas is uncountably infinite, so this confirms the theorem in this particular case.

Example. If S and T are finite, then .

For example, if S has 42 elements and T has 5 elements, then has elements.

Interesting things happen when S and T are infinite. For example, is countably infinite; how big is ? It turns out the is countably infinite as well.

is the set of pairs , where m and n are natural numbers:

I'm going to list the pairs starting with in the order shown by the grey line. This means I'm constructing a function . Here it is:

Here is why this works. is the element on the diagonal line whose elements add up to . Previous to that, I've gone through

elements. That gives .

It's a little tricky to show f is injective, so I'll omit the proof here. There is an obvious way to make an injective function from to :

If , then , so , and hence g is injective. By the Schröder-Bernstein theorem, and have the same cardinality.

[1] Paul J. Cohen, Set Theory and the Continuum Hypothesis, Reading, Massachusetts: The Benjamin-Cummings Publishing Company, Inc., 1966 [ISBN 0-8053-2327].

[2] Kurt Gödel, Consistency-proof for the generalized continuum hypothesis, Proc. Nat. Acad. Sci. U.S.A., 25(1939), 220-204.