6.7 Finite, countable and uncountable sets

Recall the definition of cardinality that we saw in Block 2:

See 4.16

This definition tells us that sets AA and BB have the same cardinality if there exists a bijection between AA and BB. So functions can help us compare the size of sets!

Theorem 6.50.

Let XX and YY be finite sets and let f:XYf:X\rightarrow Y be a function.

  1. 1.

    If ff is injective, then |X||Y||X|\leq|Y|.

  2. 2.

    If ff is surjective, then |X||Y||X|\geq|Y|.

  3. 3.

    If ff is bijective, then |X|=|Y||X|=|Y|.

Proof.
  1. 1.

    Since XX is finite, we can list its elements as x1,,xnx_{1},\ldots,x_{n} where n=|X|n=|X|. If ff is injective, then the elements f(x1),,f(xn)f(x_{1}),\ldots,f(x_{n}) are distinct, so there are exactly nn elements in the set B={f(x1),,f(xn))}B=\{f(x_{1}),\ldots,f(x_{n}))\}. Since this is a subset of YY, the set YY must have at least as many elements as BB, so |Y|n=|X||Y|\geq n=|X|.

  2. 2.

    Since YY is finite, we can list its elements as y1,,ymy_{1},\ldots,y_{m} where m=|Y|m=|Y|. If ff is surjective, then for each i=1,,mi=1,\ldots,m, we can choose some xiXx_{i}\in X such that f(xi)=yif(x_{i})=y_{i}. The elements x1,,xmx_{1},\ldots,x_{m} of XX are distinct, since if xi=xjx_{i}=x_{j} then f(xi)=f(xj)f(x_{i})=f(x_{j}) by the definition of a function i.e. yi=yjy_{i}=y_{j}, hence i=ji=j. Thus, XX has at least mm distinct elements, giving |X|m=|Y||X|\geq m=|Y|.

  3. 3.

    This follows by combining (1) and (2).

As we can also define functions on infinite sets, we can generalise these ideas to infinite sets too.

Definition 6.51 (Countable and uncountable sets).

A set SS is said to be countable if it is finite or if there is a bijection from \mathbb{N} to SS.

An infinite countable set is said to be countably infinite.

A set that is not countable is said to be uncountable.

It follows almost immediately from the definition that the set \mathbb{N} itself is countably infinite. Indeed, the identity function idid_{\mathbb{N}} is a bijection from \mathbb{N} to itself.

Proposition 6.52.

Every subset of \mathbb{N} is countable.

Proof.

Suppose SS is a subset of \mathbb{N}. If SS is finite then, by definition, it is countable and the proof is complete. If SS is an infinite proper subset of \mathbb{N} then the elements of SS can be listed in order starting with the smallest; write S={s1,s2,s3,}S=\{s_{1},s_{2},s_{3},\ldots\} where s1<s2<s3<s_{1}<s_{2}<s_{3}<\cdots. Then define f:Sf:\mathbb{N}\to S by f(n)=snf(n)=s_{n}. The function ff is bijective.

Exercise 6.53.

Explain why ff as defined in the proof of Proposition 6.52 is bijective.

Solution (please try for yourself before looking)

The function f:Sf:\mathbb{N}\to S defined by f(n)=snf(n)=s_{n} is injective because s1<s2<s3<s_{1}<s_{2}<s_{3}<\cdots and so f(1)<f(2)<f(3)<f(1)<f(2)<f(3)<\cdots. That is, if f(m)=f(n)f(m)=f(n) then m=nm=n. We can see ff is surjective because S={s1,s2,s3,}S=\{s_{1},s_{2},s_{3},\ldots\} and thus for every smSs_{m}\in S, f(m)=smf(m)=s_{m}

It may seem intuitive to you that every subset of \mathbb{N} is countable. But less intuitively, it is also possible for sets that contain \mathbb{N} as a proper subset to be countable too!

Example 6.54.

We will show that \mathbb{Z} is countable by defining a bijection between \mathbb{Z} and \mathbb{N}.

Consider the function f:f:\mathbb{N}\to\mathbb{Z} which is defined by:

f(n)={n2if n is even,n12if n is odd.f(n)=\begin{cases}-\frac{n}{2}&\text{if $n$ is even,}\\ \frac{n-1}{2}&\text{if $n$ is odd.}\end{cases}

Notice that f(1)=0f(1)=0, f(1)=1f(1)=-1, f(3)=1f(3)=1 and so on.

To prove that ff is bijective, we need to show that it is both injective and surjective.

To show that ff is injective, we need to show that if f(n)=f(n)f(n)=f(n^{\prime}) for n,nn,n^{\prime}\in\mathbb{N}, then n=nn=n^{\prime}.

So, suppose n,nn,n^{\prime}\in\mathbb{N} such that f(n)=f(n)f(n)=f(n^{\prime}). Then, nn is either even or odd. If nn is even, then f(n)=n2=n2=f(n)f(n)=-\frac{n}{2}=-\frac{n^{\prime}}{2}=f(n^{\prime}). Rearranging, we get n=nn=n^{\prime} as desired.

Alternatively, if nn is odd, then f(n)=n12=n12=f(n)f(n)=\frac{n-1}{2}=\frac{n^{\prime}-1}{2}=f(n^{\prime}). Again, rearranging gives n=nn=n^{\prime}.

This completes the proof that ff is injective.

To show that ff is surjective, we need to show that for all mm\in\mathbb{Z}, there is some nn\in\mathbb{N} such that m=f(n)m=f(n).

Let mm\in\mathbb{Z}. If mm is non-negative, then we can take n=2m+1n=2m+1. Note that nn is an odd natural number so f(n)=2m+112=mf(n)=\frac{2m+1-1}{2}=m as desired.

On the other hand, if mm is negative, then we can set n=2mn=-2m. Then nn is an even positive number and hence a natural number. We have f(n)=2m2=mf(n)=-\frac{-2m}{2}=m.

Therefore ff is surjective.

As ff is both surjective and injective, it is bijective.

Since such a bijection exists, this means that \mathbb{Z} is countable.

In fact, as the next theorem states, if we want to show that an infinite set SS is countable, it turns out that proving there exists a surjection from \mathbb{N} to SS is enough because Proposition 6.52 does the rest of the work for us. We don’t have to go the extra mile to prove the existence of a bijection in this case.

Theorem 6.55.

Let SS be any infinite set. The following are equivalent:

  1. (i)

    SS is countably infinite;

  2. (ii)

    there is a surjection from \mathbb{N} to SS;

  3. (iii)

    there is an injection from SS to \mathbb{N}.

Proof.

  • (i) \Rightarrow (ii): If SS is countably infinite then, by definition, there is a bijection from \mathbb{N} to SS. This function is surjective.

  • (ii) \Rightarrow (iii): Suppose f:Sf:\mathbb{N}\to S is surjective. Then, for any xSx\in S, the set f1({x})f^{-1}(\{x\})\subseteq\mathbb{N} is nonempty and so has a unique smallest element, call it nxn_{x}. Then g:Sg:S\to\mathbb{N} defined by g(x)=nxg(x)=n_{x} is injective. [Check that you understand why!]

  • (iii) \Rightarrow (i): Suppose h:Sh:S\to\mathbb{N} is injective. Then, since SS is an infinite set and no pair of elements in SS are mapped (under hh) to the same natural number, h(S)h(S) is an infinite subset of \mathbb{N} and is therefore countable by Proposition 6.52.

Exercise 6.56.

Prove that any subset of a countable set is countable.

Solution (please try for yourself before looking)

Let CC be a countable set and suppose SCS\subseteq C is subset.

If CC is finite then so is SS, and so SS is also countable.

If CC is countably infinite then, by Theorem 6.55, there exists an injection f:Cf:C\to\mathbb{N}. We claim that the function g:Sg:S\to\mathbb{N} such that g(x)=f(x)g(x)=f(x) for all xSx\in S is also an injection. Indeed, suppose x,ySCx,y\in S\subseteq C such that g(x)=g(y)g(x)=g(y). Then, f(x)=f(y)f(x)=f(y) and, since ff is an injection, this means that x=yx=y. Thus gg is an injection and, by Theorem 6.55 again, this means that SS is countable.

Exercise 6.57.

Let SS be any set and suppose CC is a countably set. Prove that if there is a bijection f:CSf:C\to S then SS is also countable.

Solution (please try for yourself before looking)

Suppose SS and CC are sets where CC is a countable set and suppose there exists a bijection f:CSf:C\to S. Since CC is countable. There exists a bijection g:Cg:\mathbb{N}\to C. By Proposition 6.47, this means fg:Sf\circ g:\mathbb{N}\to S is a bijection and hence, SS is countable.

Countability is also preserved when we take the Cartesian product of two countable sets.

Proposition 6.58.

The set ×\mathbb{N}\times\mathbb{N} is countable.

Proof.

Let f:×f:\mathbb{N}\to\mathbb{N}\times\mathbb{N} be defined by the following rule. Given nn\in\mathbb{N}, by the Fundamental Theorem of Arithmetic we can write n=2pqn=2^{p}q where pp is as large as possible. (In other words, factorise nn as a power of 22 multiplied by an odd integer.) Let ff be the function that maps nn to (p+1,(q+1)/2)(p+1,(q+1)/2). Then ff is a bijection [As an exercise, you should prove this], and thus ×\mathbb{N}\times\mathbb{N} is countable.

Exercise 6.59.

Prove that the Cartesian product of two countable sets is countable.

Solution (please try for yourself before looking)

Suppose C1C_{1} and C2C_{2} are countable sets, with bijections f1:C1f_{1}:\mathbb{N}\to C_{1} and f2:C2f_{2}:\mathbb{N}\to C_{2}.

Let f:×f:\mathbb{N}\to\mathbb{N}\times\mathbb{N} be defined by the following rule. Given nn\in\mathbb{N}, by the Fundamental Theorem of Arithmetic we can write n=2pqn=2^{p}q where pp is as large as possible. (In other words, factorise nn as a power of 22 multiplied by an odd integer.) Let ff be the function that maps nn to (p+1,(q+1)/2)(p+1,(q+1)/2).

Let’s define the function g:×C1×C2g:\mathbb{N}\times\mathbb{N}\to C_{1}\times C_{2} where g:(a,b)(f1(a),f2(b))g:(a,b)\mapsto(f_{1}(a),f_{2}(b)) for every (a,b)×(a,b)\in\mathbb{N}\times\mathbb{N}. We claim that gg is a bijection. Indeed, for every a,b,c,da,b,c,d\in\mathbb{N} where g((a,b))=g((c,d))g((a,b))=g((c,d)), we have

(f1(a),f2(b))=(f1(c),f2(d))f1(a)=f1(c) and f2(b)=f2(d)(f_{1}(a),f_{2}(b))=(f_{1}(c),f_{2}(d))\iff f_{1}(a)=f_{1}(c)\text{ and }f_{2}% (b)=f_{2}(d)

which means that a=ca=c and b=db=d, since f1f_{1} and f2f_{2} are injections. Hence, (a,b)=(c,d)(a,b)=(c,d) and thus, gg is an injection. Also, for every (x,y)C1×C2(x,y)\in C_{1}\times C_{2}, the surjectivity of f1f_{1} and f2f_{2} means there exists some t,rt,r\in\mathbb{N} such that f1(t)=xf_{1}(t)=x and f2(r)=yf_{2}(r)=y. Thus, g((t,r))=(f1(t),f2(r))=(x,y)g((t,r))=(f_{1}(t),f_{2}(r))=(x,y). Hence, gg is surjective.

Thus, gg is bijective and so, since ×\mathbb{N}\times\mathbb{N} is countable, 6.57 tells us that C1×C2C_{1}\times C_{2} is also countable.

Exercise 6.60.

Prove that a set with an uncountable subset is uncountable.

Solution (please try for yourself before looking)

This is the contrapositive of 6.56.

6.7.1 The set of real numbers is uncountable

Theorem 6.61.

The set (0,1)(0,1)\subseteq\mathbb{R} is uncountable.

Proof.

Suppose f:(0,1)f:\mathbb{N}\to(0,1) is a function. We know from Block 1 that every real number in (0,1)(0,1) has a non-terminating decimal representation. So we may write:

f(1)=0.x11x12x13x14x15f(2)=0.x21x22x23x24x25f(3)=0.x31x32x33x34x35f(k)=0.xk1xk2xk3xk4xk5\begin{array}[]{cccccccccc}f(1)&=&0&.&x_{11}&x_{12}&x_{13}&x_{14}&x_{15}&% \ldots\\ f(2)&=&0&.&x_{21}&x_{22}&x_{23}&x_{24}&x_{25}&\ldots\\ f(3)&=&0&.&x_{31}&x_{32}&x_{33}&x_{34}&x_{35}&\ldots\\ \vdots&&&&&&&&&\\ f(k)&=&0&.&x_{k1}&x_{k2}&x_{k3}&x_{k4}&x_{k5}&\ldots\\ \vdots&&&&&&&&&\\ \end{array}

where xij{0,1,,9}x_{ij}\in\{0,1,\ldots,9\} for all i,ji,j\in\mathbb{N}.

We shall construct a real number in the interval (0,1)(0,1) that is not on this list, proving that ff is not surjective, and so cannot be a bijection.

Let yy be the real number with decimal representation ‘0.y1y20.y_{1}y_{2}\ldots’ where

yk={1if xkk12if xkk=1,y_{k}=\begin{cases}1&\text{if $x_{kk}\neq 1$}\\ 2&\text{if $x_{kk}=1$},\end{cases}

for every kk\in\mathbb{N}.

Then certainly y(0,1)y\in(0,1) because 0.1¯y0.2¯0.\overline{1}\leq y\leq 0.\overline{2}. Moreover, for every kk\in\mathbb{N}, yf(k)y\neq f(k) because yky_{k} differs from xkkx_{kk}.

Thus ff is not surjective and so cannot be a bijection.

The above proof uses a technique known as Cantor’s diagonal argument.

Corollary 6.62.

The set of real numbers is uncountable.

Proof.

For a contradiction, assume there is a bijection f:f:\mathbb{N}\to\mathbb{R}. We claim that the function g:(0,1)g:\mathbb{R}\to(0,1) defined by g(x)=1πarctan(x)+12g(x)=\frac{1}{\pi}\arctan(x)+\frac{1}{2} is a bijection.

Indeed, if x,yx,y\in\mathbb{R} such that g(x)=g(y)g(x)=g(y), then we have

1πarctan(x)+12=1πarctan(y)+12arctan(x)=arctan(y),\frac{1}{\pi}\arctan(x)+\frac{1}{2}=\frac{1}{\pi}\arctan(y)+\frac{1}{2}\iff% \arctan(x)=\arctan(y),

which means that x=yx=y since arctan:(π/2,π/2)\arctan:\mathbb{R}\to(-\pi/2,\pi/2) is injective. So gg is injective.

Also, if z(0,1)z\in(0,1), then

π2<π(z12)<π2-\frac{\pi}{2}<\pi\left(z-\frac{1}{2}\right)<\frac{\pi}{2}

and thus there exists some xx\in\mathbb{R} such that arctan(x)=π(z12)\arctan(x)=\pi\left(z-\frac{1}{2}\right) since arctan\arctan is surjective. Thus,

g(x)=1πarctan(x)+12=z,g(x)=\frac{1}{\pi}\arctan(x)+\frac{1}{2}=z,

and hence gg is surjective.

Therefore gf:(0,1)g\circ f:\mathbb{N}\to(0,1) is a bijection by Proposition 6.47, and so (0,1)(0,1) is countable. This contradicts Theorem 6.61, and so no such function ff can exist.