Cardinality
Cardinality measures the size of a set. For finite sets, this is just counting elements. Infinite sets require a deeper idea: two sets have the same size when their elements can be paired perfectly by a bijection. This makes it possible to compare infinities without treating all infinite sets as the same.
The topic is surprising because infinite sets can behave unlike finite sets. A proper subset of an infinite set can have the same cardinality as the whole set, as the even positive integers do with the positive integers. At the same time, Cantor's diagonal argument shows that some infinite sets are strictly larger than countable ones.
Definitions
Sets and have the same cardinality, written , if there is a bijection . For finite sets, this agrees with ordinary counting. For infinite sets, bijections replace subtraction or division as the reliable comparison tool.
A set is countably infinite if it has the same cardinality as the positive integers . A set is countable if it is finite or countably infinite. A set is uncountable if it is not countable.
Useful examples:
- is countably infinite.
- is countably infinite.
- is countably infinite.
- The set of finite strings over a finite alphabet is countable.
- is uncountable.
- The set of infinite bit strings is uncountable.
For finite sets, . For any set , its power set is the set of all subsets of . Cantor's theorem says for every set , finite or infinite.
An enumeration of a set is a list that contains every element of the set at least once. A countably infinite set can be enumerated without omission. If repetitions occur, they can usually be skipped to form a bijective listing.
Key results
The integers are countable. One enumeration is
This lists every integer exactly once, so it defines a bijection from to after indexing the sequence.
The rational numbers are countable. Arrange positive rationals in an infinite grid by numerator and denominator. Traverse the grid diagonally and skip fractions that are not in lowest terms. This gives a list containing every positive rational exactly once. Interleaving positive and negative rationals and including gives a countable list of all rationals.
Cantor's diagonal argument shows that real numbers in are uncountable. Suppose they could be listed:
Write each in decimal form. Construct a new real number whose th digit differs from the th digit of and avoids ambiguous choices such as repeating s. Then differs from every in at least one decimal place, so it is not on the list. This contradicts the assumption that the list was complete.
Cantor's theorem for power sets has a related diagonal proof. Suppose were onto. Define
Since , surjectivity would require for some . But then iff , a contradiction. Hence no function from to can be onto.
Visual
Counting the integers by zigzag:
index: 0 1 2 3 4 5 6 7
value: 0 1 -1 2 -2 3 -3 4 ...
Counting positive rationals by diagonals:
q=1 q=2 q=3 q=4
p=1 1/1 1/2 1/3 1/4
p=2 2/1 2/2 2/3 2/4
p=3 3/1 3/2 3/3 3/4
p=4 4/1 4/2 4/3 4/4
Traverse p+q=2, then p+q=3, then p+q=4, ...
Skip duplicates such as 2/2 because 2/2 = 1/1.
| Set | Cardinality type | Reason |
|---|---|---|
| finite set with elements | finite | direct counting |
| even positive integers | countably infinite | bijection |
| integers | countably infinite | zigzag enumeration |
| rationals | countably infinite | diagonal enumeration by numerator and denominator |
| real numbers in | uncountable | Cantor diagonal argument |
| uncountable | Cantor's theorem |
Worked example 1: Build a bijection from natural numbers to integers
Problem. Give an explicit bijection , where .
Method.
- Use the zigzag list
- Even indices should map to nonpositive integers; odd indices should map to positive integers.
- One compact formula is
This gives , , , , and . That is a zigzag list with negatives first after zero.
- To see every integer appears, let . If , then . If , then .
- To see no integer appears twice, the preimage formulas above are unique.
Checked answer. The function is a bijection. Therefore is countably infinite.
Worked example 2: Use diagonalization on infinite bit strings
Problem. Show that the set of infinite bit strings is uncountable.
Method.
- Suppose, for contradiction, that all infinite bit strings could be listed:
- Write the strings as rows, with bits :
- Construct a new infinite bit string by flipping the diagonal bit:
- For each row , the string differs from in position .
Checked answer. The constructed is not equal to any listed string, contradicting the claim that the list was complete. Therefore the set of infinite bit strings is uncountable.
Code
from math import gcd
def integers():
yield 0
n = 1
while True:
yield n
yield -n
n += 1
def rationals(limit_sum):
yield (0, 1)
for s in range(2, limit_sum + 1):
for p in range(1, s):
q = s - p
if gcd(p, q) == 1:
yield (p, q)
yield (-p, q)
print([next(integers()) for _ in range(1)]) # starts a generator
g = integers()
print([next(g) for _ in range(10)])
print(list(rationals(6)))
The rational generator follows diagonal layers and skips duplicate rational representations.
Common pitfalls
- Assuming every infinite set has the same size. Countable and uncountable infinities differ.
- Saying a proper subset must be smaller. That is true for finite sets but not for infinite sets.
- Listing a pattern without proving every element appears. An enumeration must be complete.
- Forgetting to remove duplicate fractions when enumerating rationals.
- Using decimal expansions in diagonal arguments without handling ambiguous representations. Bit strings avoid this issue cleanly.
- Confusing "not yet listed" with "not listable." Diagonalization proves no complete list can exist.
For countability proofs, an explicit listing is helpful but not always necessary. It is enough to describe a systematic enumeration that eventually reaches every object. Listing strings by length works because every finite string has some finite length, and all shorter lengths are completed first. Diagonal enumeration of rationals works because every numerator-denominator pair lies on some finite diagonal.
When proving two infinite sets have the same cardinality, a bijection must be both one-to-one and onto. The function from positive integers to positive even integers is one-to-one because equal outputs force equal inputs, and onto because every positive even integer has the form . Both directions are part of the proof.
Diagonal arguments do more than exhibit a missing element from one attempted list. They show how to defeat any proposed list. Given any enumeration of infinite bit strings, the diagonal construction builds a new string that differs from row in position . Since the argument works for an arbitrary list, no complete list exists.
The power-set theorem is a general diagonal argument. The set is defined to disagree with each proposed image at the element . If , then asking whether gives a contradiction. This proof works for finite and infinite sets, so power sets are always strictly larger.
Countability also has consequences for computation. There are countably many finite programs because programs are finite strings over a finite alphabet. There are uncountably many languages over a nonempty finite alphabet because languages are sets of strings, i.e. elements of a power set. Therefore most languages cannot be decided by any program.
A countability proof should say how long one waits before an object appears. In diagonal listings of rationals, a fraction appears on diagonal , so it is eventually reached. In listings by string length, a string of length appears after all shorter strings. This "eventually" argument is what turns a pattern into an enumeration.
For uncountability proofs, be clear about the contradiction. The diagonal object is not merely absent from the first several rows; it differs from row in position for every . Therefore it is absent from the entire proposed list. That universal disagreement is the heart of the argument.
Connections
- Functions, sequences, and sums supplies bijections and sequences.
- Sets and set operations introduces power sets and subsets.
- Proof techniques covers contradiction and diagonal-style arguments.
- Finite-state machines and computation uses countability to compare programs and languages.