Counting
Finite sets
For any positive integer n, let Nn be the set
Nn = {1, 2, . . . , n} = {k ∈ Z : 1 ≤ k ≤ n}.
Let N0 = ∅.
Definition
A set X has cardinality n, or has n elements, written |X | = n, if
there is a bijection Nn → X . A set X is finite if |X | = n for some
integer n ≥ 0. A set is infinite if it is not finite.
We’re going to focus on finite sets first. We’ll get to infinite sets
next week. . .
Counting
Finite sets
Proposition
For finite sets, cardinality is well-defined.
“Well-defined” means that there is no ambiguity in the definition.
A not-well-defined function:
(
x +3
if x ≤ 0,
f (x) =
2x − 2 if x ≥ 0.
A not-well-defined operation on fractions: define ⊕ by
a
c
a+c
⊕ =
.
b d
b+d
Then
1 1
2
⊕ =
2 3
5
while
2 1
3
⊕ = .
4 3
7
Counting
Finite sets
Proposition
For finite sets, cardinality is well-defined. That is, if |X | = m and
|X | = n, then m = n.
This means that a set can’t have cardinality 12 and 300 at the
same time, for example. This proposition should make sense,
perhaps even be obvious, but it’s a little tricky to prove.
Proof.
We need to show that if there are bijections Nm → X and
Nn → X , then m = n. Given a bijection f : Nm → X , its inverse is
a bijection f −1 : X → Nm . Then given a bijection h : Nn → X , we
compose to get a bijection f −1 ◦ h : Nn → Nm . We need to show
that m = n.
Counting
Finite sets
Lemma (Lemma 10.1.4)
If there is an injection Nn → Nm , then n ≤ m.
Once we have proved the lemma, the proof of the proposition is
easy:
Proof of proposition, continued.
We have a bijection Nn → Nm , and its inverse Nm → Nn is also a
bijection. So we have injections Nn → Nm and Nm → Nn , and by
the lemma, n ≤ m and m ≤ n. Therefore n = m.
Proof of lemma.
The lemma is correct if n = 0 or m = 0.
Counting
Finite sets
Proof of lemma, continued.
So we assume that m and n are positive. We use induction on m.
When m = 1, then for any f : Nn → N1 = {1}, we have
f (n) = f (1). If f is injective, then n = 1, proving the base case.
Now for the inductive step, suppose that for any n and for some
k ≥ 1, if there is an injection Nn → Nk , then n ≤ k. We need to
prove the corresponding statement with k + 1 in place of k.
So assume that f : Nn → Nk+1 is an injection. We need to show
that n ≤ k + 1. Let g denote the restriction of f to
Nn − {n} = Nn−1 :
g : Nn−1 → Nk+1 − {f (n)}.
Then g is a well-defined injection. There is a bijection
h : Nk+1 − {f (n)} → Nk , so composing gives an injection
h ◦ g : Nn−1 → Nk . Thus the inductive hypothesis tells us that
n − 1 ≤ k, so n ≤ k + 1, as desired. This completes the inductive
step, and hence the proof.
Counting
Finite sets
Two counting principles
Proposition (Addition principle)
If X and Y are finite and disjoint, then X ∪ Y is finite, and
|X ∪ Y | = |X | + |Y |.
Proposition (Multiplication principle)
If X and Y are finite, then X × Y is finite, and |X × Y | = |X | · |Y |.
Proofs.
See the book.
Counting
Finite sets
Inclusion/exclusion
A refinement of the addition principle:
Theorem (Inclusion/exclusion)
If X and Y are finite, then X ∪ Y is finite, and
|X ∪ Y | = |X | + |Y | − |X ∩ Y | .
If X , Y , and Z are finite, then X ∪ Y ∪ Z is finite, and
|X ∪ Y ∪ Z | = |X | + |Y | + |Z | − |X ∩ Y | − |X ∩ Z | − |Y ∩ Z |
+ |X ∩ Y ∩ Z | .
Counting
Finite sets
1
Y
2
X ∩Y
2
3
Y ∩Z
X ∩Y ∩Z
1
X
2
X ∩Z
1
Z
Counting
Finite sets
Example
How many integers in N100 = {1, 2, . . . , 100} are not multiples of
2, 3, or 5?
We could just list them all, cross out the multiples of 2, 3, and 5,
and see what’s left. But we can also use inclusion/exclusion.
For any positive integer d, let Md = {n ∈ N100 : d|n} – elements
of N100 which are multiples of d. Then the question is asking for
|N100 − (M2 ∪ M3 ∪ M5 )| = 100 − |M2 ∪ M3 ∪ M5 | .
Note first that |M2 | = 50, |M3 | = 33, and |M5 | = 20. (For
instance, M3 consists of the numbers 3k, for 1 ≤ k ≤ 33.)
Also, M2 ∩ M3 is the set of numbers divisible by both 2 and 3, and
hence equals the set of numbers divisible by 6. So |M2 ∩ M3 | = 16.
Similarly, |M2 ∩ M5 | = 10 (numbers divisible by 10) and
|M3 ∩ M5 | = 6 (numbers divisible by 15).
Counting
Finite sets
Example (Example, continued)
Finally, M2 ∩ M3 ∩ M5 is the set of multiples of 30, which has
cardinality 3.
Summarizing: |M2 | = 50, |M3 | = 33, |M5 | = 20, |M2 ∩ M3 | = 16,
|M2 ∩ M5 | = 10, |M3 ∩ M5 | = 6, and |M2 ∩ M3 ∩ M5 | = 3.
Therefore
|M2 ∪ M3 ∪ M5 | = |M2 | + |M3 | + |M5 | − |M2 ∩ M3 | − |M2 ∩ M5 |
− |M3 ∩ M5 | + |M2 ∩ M3 ∩ M5 |
= 50 + 33 + 20 − 16 − 10 − 6 + 3 = 74.
So the answer is 100 − 74 = 26.
See the book for more examples and also a more general formula
(#4, pp. 182–183).
Counting
Finite sets
Recall:
Lemma (Lemma 10.1.4)
If there is an injection Nn → Nm , then n ≤ m.
Corollary
If X and Y are finite sets and there is an injection X → Y , then
|X | ≤ |Y |.
Proof.
Since X and Y are finite, there are non-negative integers m and n
and bijections Nn → X and Y → Nm . Composing with X → Y
gives
bijection
injection
bijection
Nn −−−−−→ X −−−−−→ Y −−−−−→ Nm ,
and this is an injection, so by the lemma, |X | = n ≤ m = |Y |.
Its contrapositive:
Counting
Finite sets
Theorem (Pigeonhole principle)
Suppose that X and Y are finite sets and that f : X → Y is a
function. If |X | > |Y |, then f is not injective: there exist
x1 , x2 ∈ X with x1 6= x2 but f (x1 ) = f (x2 ).
Related results:
1
If X → Nn is injective, then X is finite and |X | ≤ n.
(Proposition 11.1.4)
2
If X ⊆ Y and Y is finite, then X is finite and |X | ≤ |Y |.
(Corollary 11.1.5)
3
If X and Y are finite with |X | < |Y |, then no map f : X → Y
is a surjection. (Theorem 11.1.6, homework)
4
If X and Y are finite with |X | = |Y |, then any function
f : X → Y is injective if and only if it is surjective. (Theorem
11.1.7, homework)
Counting
Finite sets
Example
In any group of 13 people, at least two will have their birthday
in the same month.
In any group of 367 people, at least two will have the same
birthday (month and day). (In a group of 23 people, there is a
greater than 50% chance that at least two will have the same
birthday, but that’s a different theorem. Take a probability
course to learn about that.)
If you choose n + 1 distinct numbers from N2n , then you will
get at least two consecutive numbers. Imagine putting the
numbers into the sets {1, 2}, {3, 4}, {5, 6}, . . . , {2n − 1, 2n}.
There are n such sets, so if you have n + 1 numbers, then two
of them will go into the same set.
If four distinct numbers are chosen from {1, 2, 3, 4, 5}, then
two of these numbers add up to 6. The four numbers will fit
into the sets {1, 5}, {2, 4}, {3}. There are only three sets
here, so two of the numbers must go into the same set.
© Copyright 2026 Paperzz