Survey of Mathematics

0.3 Sets, functions, and counting infinity

Sets and functions are the language everything else is written in. A perfect matching (a bijection) is how we compare sizes, and it shows that the integers and the rationals are as small as the counting numbers while the real numbers are strictly larger.

Beyond the courseCS 240 (sets, functions, countable sets)Hammack, Book of Proof, ch. 1, 8, 12, 13Velleman, How to Prove It, ch. 2, 4, 5Abbott, Understanding Analysis, ch. 1.5

Two questions drive this chapter. What are the basic objects that all of mathematics is built from, and how do you decide whether two collections have “the same number of elements” when neither can be counted to the end? The answers are sets and functions. A set is a collection, a function is a rule, and a perfect pairing between two collections is what “same size” turns out to mean. With that one idea the whole numbers, the integers and the fractions all turn out to be the same size, and the real numbers do not.

Before you start

0.1 for reading and negating statements, and 0.2 for the shapes of proofs (direct, contradiction, cases, induction, well-ordering). Three quick checks.

Quick checkWhat is the negation of 'the number xx is in AA and in BB'?
Quick checkTo prove 'for every xx, if P(x)P(x) then Q(x)Q(x)' directly, how do you begin?
Quick checkEvery non-empty set of positive integers has a smallest element. Is the same true for the set of all positive rational numbers?

The picture

Take A={1,2,3,4}A = \{1, 2, 3, 4\} and B={3,4,5}B = \{3, 4, 5\}, inside the universe U={1,2,3,4,5,6}U = \{1, 2, 3, 4, 5, 6\}. Everything in this chapter’s first half is a question about which numbers land where.

SetElementsIn words
A∪BA \cup B{1,2,3,4,5}\{1, 2, 3, 4, 5\}in AA, or in BB, or both
A∩BA \cap B{3,4}\{3, 4\}in both
A∖BA \setminus B{1,2}\{1, 2\}in AA but not in BB
AcA^c{5,6}\{5, 6\}in the universe but not in AA

For the second half, picture two cinema halls with a seat for each person and no empty seats. You can tell that they hold the same number of people without counting anyone: send each person of one group to the seat of their partner. If everyone has a seat, and no seat is shared, and no seat is empty, the groups match. That matching is what mathematicians call a bijection, and it works equally well when the groups are infinite.

Here is the surprise to look for. The counting numbers 1,2,3,…1, 2, 3, \dots can be matched with the even numbers 2,4,6,…2, 4, 6, \dots by n↦2nn \mapsto 2n. The evens are only some of the counting numbers, and yet the matching leaves nobody out. For infinite sets “a part can be as big as the whole”.

The idea, in words

A set is a collection of things, and a function is a rule that sends each thing in one set to exactly one thing in another. Almost every object in mathematics is one of these: a sequence is a function on the counting numbers, a vector space is a set with extra rules, a probability is a function on a set of events.

Why· Why a perfect matching is the right idea of 'same size'

For finite sets, “same size” means that you get the same number when you count. But counting is a matching: you pair the objects with 1,2,3,…1, 2, 3, \dots and stop. Strip away the numbers and what remains is a pairing with no one left over on either side. That makes sense for any pair of sets, finite or not. Comparing sizes without counting is also how a shepherd checks that no sheep is missing: one pebble per sheep.

Each phrase in “no one left out and no seat shared” becomes a word below. “No one on the left is unpaired” is that the rule is a function. “No seat is shared” is injective. “No seat is empty” is surjective. Both together is bijective.

Where this came from· Before Cantor: Galileo noticed it, and gave up

In his Two New Sciences (1638), Galileo pointed out that each counting number has a square, so the squares 1,4,9,16,…1, 4, 9, 16, \dots match up with all the counting numbers. Yet most counting numbers are not squares. His conclusion was that “equal”, “less” and “greater” make no sense for infinite collections. Bernard Bolzano took the problem up again in a book published after his death (1851). He accepted that an infinite set can be matched with a part of itself, but he still held that the part must be smaller than the whole, so a matching alone did not make two sets equal in size for him. Georg Cantor, in the 1870s, did the opposite: he made the matching the definition of “same size” and gave up the idea that a part is always smaller. He then discovered that infinite sets come in different sizes after all. The rest of this chapter follows his road.

Definitions and theorems

Sets

Definition B

Set

A set is a collection of objects, called its elements. We write x∈Ax \in A for ”xx is an element of AA”, and x∉Ax \notin A for ”x∈Ax \in A is false”. Two ways to describe a set:

  • Roster: list the elements, as in {2,3,5,7}\{2, 3, 5, 7\}. Order and repeats do not matter: {1,2,2}={2,1}\{1, 2, 2\} = \{2, 1\}.
  • Set-builder: {x∈D:P(x)}\{x \in D : P(x)\}, read “the set of all xx in DD such that P(x)P(x)”. The colon means “such that” (CS 240 uses a colon, because the bar is also used for absolute value and divisibility).

The empty set ∅\varnothing has no elements. The standard number sets are N={1,2,3,… }\mathbb N = \{1, 2, 3, \dots\}, Z\mathbb Z (all integers), Q={z/b:z∈Z, b∈N}\mathbb Q = \{ z / b : z \in \mathbb Z,\ b \in \mathbb N \} (the rationals) and R\mathbb R (the reals). CS 240 puts 00 in N\mathbb N. Here N\mathbb N starts at 11 because we will use its elements as positions in a list: first, second, third.

In one lineA collection of objects, called its elements; what matters is only which objects are in it.

Why it existsSets are the raw material: numbers, functions, vectors and events are all described by saying which objects belong to a set.

The statement x∉Ax \notin A is the negation of x∈Ax \in A. That is why the negation rules from 0.1 will do all the work in this section.

Definition B

Subset

AA is a subset of BB, written A⊆BA \subseteq B, if ∀x (x∈A⇒x∈B)\forall x\ (x \in A \Rightarrow x \in B). We write A⊊BA \subsetneq B when also A≠BA \ne B (a proper subset; CS 240 writes this A⊂BA \subset B, and some books use ⊂\subset for plain subset, so check each book).

In one lineA⊆BA \subseteq B means every element of AA is also an element of BB.

Why it existsIt is the tool for comparing sets, and for proving two sets are equal.

To prove A⊆BA \subseteq B you use the recipe from 0.2 for a statement of the shape “for every xx, if … then …”.

  1. Write “Let x∈Ax \in A be arbitrary.”
  2. Derive "x∈Bx \in B" using the definition of AA.

Two things follow from reading the definition exactly. First, ∅⊆A\varnothing \subseteq A for every set AA: the statement "x∈∅⇒x∈Ax \in \varnothing \Rightarrow x \in A" has a false hypothesis for every xx, so it is true (vacuous truth, as in 0.1). Second, A⊈BA \not\subseteq B (read ”AA is not a subset of BB”) means, by the negation rules, ∃x (x∈A∧x∉B)\exists x\ (x \in A \land x \notin B). To disprove a subset claim, name one such xx.

Theorem B

Double inclusion

For sets AA and BB: A=BA = B if and only if A⊆BA \subseteq B and B⊆AB \subseteq A.

In one lineA=BA = B exactly when A⊆BA \subseteq B and B⊆AB \subseteq A.

Why it is trueTwo sets are equal when they have the same elements, and 'same elements' is two one-way statements.

ProofHammack 8.3
The idea: Equal sets have the same elements. Write that as an if-and-only-if for every x, and split it into its two directions.
A=BA = B means ∀x (x∈A⇔x∈B)\forall x\ (x \in A \Leftrightarrow x \in B).
This is the definition of equality of sets: they are the same exactly when they have the same elements.
That is ∀x (x∈A⇒x∈B)\forall x\ (x \in A \Rightarrow x \in B) and ∀x (x∈B⇒x∈A)\forall x\ (x \in B \Rightarrow x \in A).
An if-and-only-if is two implications (0.1). The quantifier ∀x\forall x can be applied to each implication separately.
So A=BA = B if and only if A⊆BA \subseteq B and B⊆AB \subseteq A.
The first is the definition of A⊆BA \subseteq B and the second is the definition of B⊆AB \subseteq A.

This theorem is the standard way to prove two sets equal: show each is inside the other, by taking an arbitrary element of one and chasing it into the other. We call that element-chasing.

Worked example Hammack 8.1
Show that if A⊆BA \subseteq B and B⊆CB \subseteq C, then A⊆CA \subseteq C.

Solution.

  1. Set up the goal. We must show ∀x (x∈A⇒x∈C)\forall x\ (x \in A \Rightarrow x \in C). So let x∈Ax \in A be arbitrary. The recipe for a subset proof: an arbitrary element of the smaller set.
  2. Use the first hypothesis. A⊆BA \subseteq B and x∈Ax \in A, so x∈Bx \in B. That is the definition of A⊆BA \subseteq B, applied to our xx.
  3. Use the second hypothesis. B⊆CB \subseteq C and x∈Bx \in B, so x∈Cx \in C. The definition again, applied to the same xx.

Answer. Our arbitrary x∈Ax \in A lies in CC, so A⊆CA \subseteq C.

Union, intersection, complement

Definition B

Union

A∪B={x:x∈A∨x∈B}A \cup B = \{x : x \in A \lor x \in B\}.

In one lineA∪BA \cup B is the set of everything that is in AA or in BB (or both).

Why it existsIt is the set-version of 'or': it collects everything that satisfies at least one of two conditions.

Definition B

Intersection

A∩B={x:x∈A∧x∈B}A \cap B = \{x : x \in A \land x \in B\}. Sets with A∩B=∅A \cap B = \varnothing are called disjoint.

In one lineA∩BA \cap B is the set of everything that is in both AA and BB.

Why it existsIt is the set-version of 'and': it collects everything that satisfies both conditions at once.

Definition B

Complement

Fix a universe UU, the set that all elements under discussion belong to. The complement of AA is Ac={x∈U:x∉A}A^c = \{x \in U : x \notin A\}. The related difference is A∖B={x:x∈A∧x∉B}A \setminus B = \{x : x \in A \land x \notin B\}, so Ac=U∖AA^c = U \setminus A. The Cartesian product is A×B={(a,b):a∈A, b∈B}A \times B = \{(a, b) : a \in A,\ b \in B\}, the set of ordered pairs. Order matters: (1,2)≠(2,1)(1, 2) \ne (2, 1). If AA has 3 elements and BB has 2, then A×BA \times B has 3⋅2=63 \cdot 2 = 6.

In one lineAcA^c is everything in the universe UU that is not in AA.

Why it existsIt is the set-version of 'not'. It only makes sense relative to a universe, the big set that all our elements come from.

Notice that each definition rewrites ”xx belongs to the new set” as a statement built from "x∈Ax \in A" with and, or, not. That is the whole secret of proofs about sets: membership in A∪BA \cup B is, by definition, a logical sentence, so logic from 0.1 applies.

The rules for ‘not in’

A question you asked: what are the rules on “doesn’t belong to”? There is nothing new to memorize. “Not in” is the negation of “in”, so the negation rules of 0.1 apply to the definitions.

Fact B

Rules for not in

For x∈Ux \in U and sets A,BA, B:

  1. x∉A∩Bx \notin A \cap B if and only if x∉Ax \notin A or x∉Bx \notin B.
  2. x∉A∪Bx \notin A \cup B if and only if x∉Ax \notin A and x∉Bx \notin B.
  3. x∉Acx \notin A^c if and only if x∈Ax \in A.
  4. x∉A∖Bx \notin A \setminus B if and only if x∉Ax \notin A or x∈Bx \in B.
  5. (x,y)∉A×B(x, y) \notin A \times B if and only if x∉Ax \notin A or y∉By \notin B.
  6. x∉{y:P(y)}x \notin \{y : P(y)\} if and only if P(x)P(x) is false.

In one lineNot in an intersection means missing from at least one; not in a union means missing from both; not in a complement means in the original set.

Why it is trueEach rule is a negation rule of 0.1 applied to the definition of the set operation.

Proofstandard
The idea: Write what membership means, put 'not' in front, and push the 'not' inward with the rules of 0.1.
Rule 1: ¬(x∈A∧x∈B)\neg(x \in A \land x \in B) is x∉A∨x∉Bx \notin A \lor x \notin B.
By the definition of intersection, x∈A∩Bx \in A \cap B means x∈A∧x∈Bx \in A \land x \in B. Negate it with De Morgan (rule 1 of 0.1).
Rule 2: ¬(x∈A∨x∈B)\neg(x \in A \lor x \in B) is x∉A∧x∉Bx \notin A \land x \notin B.
By the definition of union, x∈A∪Bx \in A \cup B means x∈A∨x∈Bx \in A \lor x \in B. Rule 2 of 0.1.
Rule 3: ¬(x∉A)\neg(x \notin A) is x∈Ax \in A.
By definition, x∈Acx \in A^c means x∉Ax \notin A (for x∈Ux \in U). Negating a negation gives back the original.
Rule 4: ¬(x∈A∧x∉B)\neg(x \in A \land x \notin B) is x∉A∨x∈Bx \notin A \lor x \in B.
x∈A∖Bx \in A \setminus B means x∈A∧x∉Bx \in A \land x \notin B. De Morgan, then ¬(x∉B)\neg(x \notin B) is x∈Bx \in B.
Rule 5: ¬(x∈A∧y∈B)\neg(x \in A \land y \in B) is x∉A∨y∉Bx \notin A \lor y \notin B.
(x,y)∈A×B(x, y) \in A \times B means x∈A∧y∈Bx \in A \land y \in B, since a pair is in the product exactly when each coordinate is in its set. De Morgan again.
Rule 6: x∈{y:P(y)}x \in \{y : P(y)\} means P(x)P(x), so its negation is that P(x)P(x) is false.
Membership in a set-builder set is, by its definition, the truth of the condition.

In practice you rarely quote the rules by number. You write what membership means, then negate with the rules of 0.1, and the word “or” appears whenever an “and” was negated.

Quick checkWhich statement is equivalent to x∉A∖Bx \notin A \setminus B?
Quick checkTo prove that A⊈BA \not\subseteq B (that AA is NOT a subset of BB), what must you do?
Worked example
Is (A∪B)∖B=A(A \cup B) \setminus B = A true for all sets AA and BB? Prove it or disprove it.

Solution.

  1. Try to prove it by element-chasing. x∈(A∪B)∖Bx \in (A \cup B) \setminus B means x∈A∪Bx \in A \cup B and x∉Bx \notin B, that is (x∈Ax \in A or x∈Bx \in B) and x∉Bx \notin B. Unpack the definitions of difference and union, as in the proofs above.
  2. See where it stops. Since x∉Bx \notin B, the part "x∈Bx \in B" is false, so x∈Ax \in A must hold. That gives x∈Ax \in A and x∉Bx \notin B, which is the set A∖BA \setminus B, not AA. The two sets agree only if x∈Ax \in A already forces x∉Bx \notin B.
  3. Build a counterexample. Take A={1,2}A = \{1, 2\} and B={2,3}B = \{2, 3\}. We need an element of AA that is also in BB, so that it is removed on the left. The element 22 does that.
  4. Compute both sides. (A∪B)∖B={1,2,3}∖{2,3}={1}(A \cup B) \setminus B = \{1, 2, 3\} \setminus \{2, 3\} = \{1\}, but A={1,2}A = \{1, 2\}. The element 22 is in AA but not in the left side, so the two sets differ.

Answer. False in general. The left side equals A∖BA \setminus B, so the identity holds exactly when AA and BB are disjoint. To disprove a statement “for all sets”, one specific example is enough.

Worked example
Let U={1,…,6}U = \{1, \dots, 6\}, A={1,2,3,4}A = \{1, 2, 3, 4\}, B={3,4,5}B = \{3, 4, 5\}, C={4,6}C = \{4, 6\}. Describe the elements that are NOT in (A∩B)∪C(A \cap B) \cup C, and check with the list.

Solution.

  1. Negate the outer operation first. x∉(A∩B)∪Cx \notin (A \cap B) \cup C means x∉A∩Bx \notin A \cap B and x∉Cx \notin C. The outermost operation is a union, so use rule 2: not in a union means not in either part.
  2. Negate the inner operation. x∉A∩Bx \notin A \cap B means x∉Ax \notin A or x∉Bx \notin B. So the condition is: (x∉A or x∉B)(x \notin A \text{ or } x \notin B) and x∉Cx \notin C. Rule 1: not in an intersection means missing from at least one.
  3. Test each element of UU. For x=1x = 1: 1∉B1 \notin B (true) and 1∉C1 \notin C (true), so 11 qualifies. For x=2x = 2: 2∉B2 \notin B and 2∉C2 \notin C, so 22 qualifies. For x=3x = 3: 3∈A3 \in A and 3∈B3 \in B, so the first bracket fails. For x=4x = 4: 4∈C4 \in C, so it fails. For x=5x = 5: 5∉A5 \notin A and 5∉C5 \notin C, so 55 qualifies. For x=6x = 6: 6∈C6 \in C, so it fails. The condition is a sentence about one element, so we check it element by element.
  4. Check against the direct computation. A∩B={3,4}A \cap B = \{3, 4\}, so (A∩B)∪C={3,4,6}(A \cap B) \cup C = \{3, 4, 6\}, whose complement in UU is {1,2,5}\{1, 2, 5\}. The two methods must agree.

Answer. The elements not in the set are 1,2,51, 2, 5.

De Morgan’s laws for sets

Another question you asked: if De Morgan’s laws are not given on a CS 240 exam, how can you use them for sets? The answer is that you do not need them as a given fact. You prove them from the definitions, and the proof is short, because the set statement is the logic statement in disguise.

Theorem B

De Morgan's laws for sets

For sets A,BA, B inside a universe UU:

(A∪B)c=Ac∩Bc,(A∩B)c=Ac∪Bc.(A \cup B)^c = A^c \cap B^c, \qquad (A \cap B)^c = A^c \cup B^c.

In one line(A∪B)c=Ac∩Bc(A \cup B)^c = A^c \cap B^c and (A∩B)c=Ac∪Bc(A \cap B)^c = A^c \cup B^c.

Why it is trueMembership in each side is a statement built from 'in', 'and', 'or', 'not', and the two sides are De Morgan's laws of logic.

ProofCS 240; Hammack 8.4
The idea: Take an arbitrary x in the universe. Turn 'x is in the left side' into a statement about x in A and x in B, apply a negation rule, and turn it back into 'x is in the right side'. Every line is an if-and-only-if, so one chain proves both inclusions at once.
Let x∈Ux \in U. We show x∈(A∪B)c⇔x∈Ac∩Bcx \in (A \cup B)^c \Leftrightarrow x \in A^c \cap B^c.
This is the form of the goal that element-chasing needs: x∈Ux \in U is arbitrary, and we will show the two memberships are equivalent.
x∈(A∪B)c⇔x∉A∪Bx \in (A \cup B)^c \Leftrightarrow x \notin A \cup B.
Definition of complement: x∈Ux \in U, so x∈(A∪B)cx \in (A \cup B)^c means x∉A∪Bx \notin A \cup B.
⇔ x∉A and x∉B\Leftrightarrow\ x \notin A \text{ and } x \notin B.
Rule 2 of 'not in': the negation of 'in AA or in BB' is 'not in AA and not in BB'. This is De Morgan from 0.1.
⇔ x∈Ac and x∈Bc\Leftrightarrow\ x \in A^c \text{ and } x \in B^c.
Definition of complement, applied to AA and to BB separately (x∈Ux \in U).
⇔ x∈Ac∩Bc\Leftrightarrow\ x \in A^c \cap B^c. So the first law holds, because every element of the universe is in one side exactly when it is in the other.
Definition of intersection.
The second law has the same proof.
The same chain, with 'union' and 'intersection' swapped, using rule 1 of 'not in' instead of rule 2: x∈(A∩B)c⇔x∉A∩B⇔(x∉A or x∉B)⇔(x∈Ac or x∈Bc)⇔x∈Ac∪Bcx \in (A \cap B)^c \Leftrightarrow x \notin A \cap B \Leftrightarrow (x \notin A \text{ or } x \notin B) \Leftrightarrow (x \in A^c \text{ or } x \in B^c) \Leftrightarrow x \in A^c \cup B^c.

This is the answer to “how can I use De Morgan if it is not given”: you write the chain above, with the justification beside each line, whenever a proof needs it. A proof that wants an identity as a step should either quote a theorem it is allowed to cite or reprove it like this. In CS 240 the justification column reads “definition of complement”, “De Morgan’s law (logic)”, and “definition of intersection”.

Worked example CS 240 practice
Prove A∖(B∪C)=(A∖B)∩(A∖C)A \setminus (B \cup C) = (A \setminus B) \cap (A \setminus C) for all sets A,B,CA, B, C.

Solution. The plan: take an arbitrary xx and turn each side into a statement about x∈Ax \in A, x∈Bx \in B, x∈Cx \in C.

  1. Unpack the left side. x∈A∖(B∪C)x \in A \setminus (B \cup C) means x∈Ax \in A and x∉B∪Cx \notin B \cup C. Definition of difference.
  2. Negate the union. That is x∈Ax \in A and (x∉Bx \notin B and x∉Cx \notin C). Rule 2 of ‘not in’.
  3. Repeat the common part. That is equivalent to (x∈Ax \in A and x∉Bx \notin B) and (x∈Ax \in A and x∉Cx \notin C). Saying ”PP and (QQ and RR)” is the same as saying ”(PP and QQ) and (PP and RR)”, because PP and PP is just PP (the idempotent law of CS 240).
  4. Repack as set operations. x∈A∖Bx \in A \setminus B and x∈A∖Cx \in A \setminus C, which means x∈(A∖B)∩(A∖C)x \in (A \setminus B) \cap (A \setminus C). Definitions of difference and intersection, read backwards.

Answer. Every line was an if-and-only-if, so an element is in the left side exactly when it is in the right side. The sets are equal.

Quick checkWhich is the complement of A∩B∩CA \cap B \cap C (all inside UU)?

Functions

Definition B

Function

A function f:A→Bf: A \to B assigns to every a∈Aa \in A exactly one element f(a)∈Bf(a) \in B. The set AA is the domain, BB is the codomain, and f(a)f(a) is the image of aa. The range (or image) of ff is f(A)={f(a):a∈A}f(A) = \{f(a) : a \in A\}, the outputs actually used, which may be smaller than the codomain. Two functions are equal when they have the same domain, the same codomain, and the same output for every input. For T⊆BT \subseteq B the preimage is f−1(T)={a∈A:f(a)∈T}f^{-1}(T) = \{a \in A : f(a) \in T\} (this notation does not need an inverse function to exist).

In one lineA rule f:A→Bf: A \to B that assigns to every input in AA exactly one output in BB.

Why it existsFunctions describe how one quantity depends on another, and let us compare sets by matching them.

“Exactly one” contains two promises: every input has an output, and no input has two. So x↦±xx \mapsto \pm\sqrt x is not a function, and neither is "x↦1/xx \mapsto 1/x" on R\mathbb R, which has no output at x=0x = 0. Chapter 0.4 returns to this point, because defining a function on fractions requires checking that the output does not depend on how you write the fraction.

There are two further properties, and each says half of a perfect matching. Apostol and chapter 2.3 call them one-to-one and onto.

Definition B

Injective

f:A→Bf: A \to B is injective (also one-to-one) if for all x,y∈Ax, y \in A: f(x)=f(y)⇒x=yf(x) = f(y) \Rightarrow x = y. By the contrapositive of 0.1, this is the same as: x≠y⇒f(x)≠f(y)x \ne y \Rightarrow f(x) \ne f(y).

In one lineff is injective (one-to-one) if different inputs always give different outputs: f(x)=f(y)f(x) = f(y) forces x=yx = y.

Why it existsIt says no two inputs are sent to the same place, so no information is lost and the output determines the input.

Definition B

Surjective

f:A→Bf: A \to B is surjective (also onto) if ∀b∈B ∃a∈A: f(a)=b\forall b \in B\ \exists a \in A:\ f(a) = b.

In one lineff is surjective (onto) if every element of the codomain is an output: the range is the whole codomain.

Why it existsIt says nothing in the target is unreachable, so every equation f(x)=bf(x) = b has a solution.

Definition B

Bijective

f:A→Bf: A \to B is bijective if it is injective and surjective. Then every b∈Bb \in B has exactly one a∈Aa \in A with f(a)=bf(a) = b (at least one from surjective, at most one from injective).

In one lineff is bijective if it is both injective and surjective: every element of the codomain is hit by exactly one input.

Why it existsA bijection is a perfect matching between two sets, which is what 'same size' means.

Read the quantifiers as in 0.1. Surjective is ∀∃\forall \exists: you pick bb first, and the proof must then produce an aa, which may depend on bb. Injective is a statement about every pair of inputs. This gives two templates.

  • To prove injective: “Suppose f(x)=f(y)f(x) = f(y).” Then work until you get x=yx = y.
  • To prove surjective: “Let b∈Bb \in B be arbitrary.” Solve f(a)=bf(a) = b for aa, write the answer as a formula in bb, and check that your aa lies in the domain AA.
  • To disprove either: exhibit two different inputs with the same output (not injective), or one target nobody reaches (not surjective).
Worked example
Is f:R→Rf: \mathbb R \to \mathbb R, f(x)=3x+2f(x) = 3x + 2 injective? Surjective? Find the inverse.

Solution.

  1. Injective. Suppose f(x)=f(y)f(x) = f(y), that is 3x+2=3y+23x + 2 = 3y + 2. Subtract 22 and divide by 33 to get x=yx = y. The template for injective: assume equal outputs, derive equal inputs.
  2. Surjective. Let b∈Rb \in \mathbb R be arbitrary. Solving 3a+2=b3a + 2 = b gives a=(b−2)/3a = (b - 2)/3, which is a real number, so it is in the domain. Check: f(a)=3⋅b−23+2=bf(a) = 3 \cdot \tfrac{b - 2}{3} + 2 = b. The template for surjective: solve for the input, make sure it is in the domain, and check that it works.
  3. Read off the inverse. The formula from step 2 undoes ff: f−1(b)=(b−2)/3f^{-1}(b) = (b - 2)/3. The solution of f(a)=bf(a) = b is exactly the inverse rule (see the theorem on inverses below).

Answer. ff is bijective, with inverse f−1(x)=(x−2)/3f^{-1}(x) = (x - 2)/3.

Worked example
Classify g:Z→Zg: \mathbb Z \to \mathbb Z, g(n)=n2g(n) = n^2, and h:N→Nh: \mathbb N \to \mathbb N, h(n)=n2h(n) = n^2.

Solution.

  1. gg is not injective. g(2)=4=g(−2)g(2) = 4 = g(-2) but 2≠−22 \ne -2. One pair of different inputs with the same output disproves injective.
  2. gg is not surjective. The target 22 is not a square: if ∣n∣≤1\lvert n \rvert \le 1 then n2≤1n^2 \le 1, and if ∣n∣≥2\lvert n \rvert \ge 2 then n2≥4n^2 \ge 4, so n2=2n^2 = 2 is impossible. To show a target is missed, we must rule out every input, not just try a few.
  3. hh is injective. For positive x,yx, y, if x2=y2x^2 = y^2 then (x−y)(x+y)=0(x - y)(x + y) = 0, and x+y>0x + y > 0, so x=yx = y. Positivity removes the −2-2 that spoiled gg. The domain matters.
  4. hh is not surjective. The target 22 is again not a square. Same argument as step 2.

Answer. gg is neither. hh is injective but not surjective. The formula alone does not decide the answer; the domain and codomain are part of the function.

Worked example
Prove that f:R∖{2}→R∖{1}f: \mathbb R \setminus \{2\} \to \mathbb R \setminus \{1\}, f(x)=x+1x−2f(x) = \dfrac{x + 1}{x - 2} is a bijection, and find its inverse.

Solution.

  1. Check that ff lands in the codomain. f(x)=1+3x−2f(x) = 1 + \dfrac{3}{x - 2}, and 3x−2\dfrac{3}{x-2} is never 00, so f(x)≠1f(x) \ne 1. A function must send every input into the stated codomain. Here the codomain leaves out 11 for exactly this reason.
  2. Injective. Suppose x+1x−2=y+1y−2\dfrac{x + 1}{x - 2} = \dfrac{y + 1}{y - 2}. Cross-multiplying (both denominators are non-zero) gives (x+1)(y−2)=(y+1)(x−2)(x + 1)(y - 2) = (y + 1)(x - 2), that is xy−2x+y−2=xy−2y+x−2xy - 2x + y - 2 = xy - 2y + x - 2. This simplifies to 3y=3x3y = 3x, so x=yx = y. The template for injective: assume equal outputs, derive equal inputs.
  3. Surjective. Let b≠1b \ne 1 be arbitrary. Solve a+1a−2=b\dfrac{a + 1}{a - 2} = b: a+1=ab−2ba + 1 = ab - 2b, so a(1−b)=−2b−1a(1 - b) = -2b - 1, so a=2b+1b−1a = \dfrac{2b + 1}{b - 1}. This is defined because b≠1b \ne 1. The template for surjective: solve for the input as a formula in bb.
  4. Check that this aa is in the domain. If a=2a = 2 then 2b+1=2b−22b + 1 = 2b - 2, which is impossible, so a≠2a \ne 2. Check: a−2=3b−1a - 2 = \dfrac{3}{b-1} and a+1=3bb−1a + 1 = \dfrac{3b}{b-1}, so f(a)=bf(a) = b. The solution must be a legal input, and it must really work. Skipping this check is the usual slip.

Answer. ff is a bijection with inverse f−1(x)=2x+1x−1f^{-1}(x) = \dfrac{2x + 1}{x - 1}. Spot check: f(3)=4f(3) = 4 and f−1(4)=9/3=3f^{-1}(4) = 9/3 = 3.

Watch out· In JEE you wrote 'one-one onto', and the codomain was quietly part of the question

JEE asks “is ff one-one? onto?” for rules like exe^x on R\mathbb R. The honest answer depends on the codomain: ex:R→Re^x: \mathbb R \to \mathbb R is injective but not onto (it never reaches 00 or negative numbers), while ex:R→(0,∞)e^x: \mathbb R \to (0, \infty) is bijective, with inverse ln⁡\ln. Restricting the codomain to the range is always allowed and always makes a function surjective. That is why “the inverse of exe^x is ln⁡x\ln x” needs the codomain (0,∞)(0, \infty).

Quick checkf:Z→Zf: \mathbb Z \to \mathbb Z, f(n)=2nf(n) = 2n. Which is true?

Composition. If f:A→Bf: A \to B and g:B→Cg: B \to C, the composition g∘f:A→Cg \circ f: A \to C is the function (g∘f)(a)=g(f(a))(g \circ f)(a) = g(f(a)): first ff, then gg. The identity function on a set AA is idA(a)=a\mathrm{id}_A(a) = a.

Proposition B

Composition of injections and surjections

Let f:A→Bf: A \to B and g:B→Cg: B \to C.

  1. If ff and gg are injective, then g∘fg \circ f is injective.
  2. If ff and gg are surjective, then g∘fg \circ f is surjective.

In one lineIf ff and gg are injective, so is g∘fg \circ f; if both are surjective, so is g∘fg \circ f; hence a composition of bijections is a bijection.

Why it is trueFollow the chain of equalities (injective) or the chain of pre-images (surjective) one function at a time.

ProofHammack 12.2
The idea: Injective: peel off g, then peel off f. Surjective: given a target in C, find where g came from, then where f came from.
(1) Suppose (g∘f)(x)=(g∘f)(y)(g \circ f)(x) = (g \circ f)(y), that is g(f(x))=g(f(y))g(f(x)) = g(f(y)).
Template for injective: assume equal outputs.
Then f(x)=f(y)f(x) = f(y).
gg is injective, so equal outputs of gg come from equal inputs.
Then x=yx = y. So g∘fg \circ f is injective.
ff is injective.
(2) Let c∈Cc \in C.
Template for surjective: take an arbitrary target in the final codomain.
Pick b∈Bb \in B with g(b)=cg(b) = c.
gg is surjective, so something in BB is sent to cc.
Pick a∈Aa \in A with f(a)=bf(a) = b.
ff is surjective, so something in AA is sent to bb.
So cc is an output of g∘fg \circ f, and g∘fg \circ f is surjective.
Substitute: (g∘f)(a)=g(f(a))=g(b)=c(g \circ f)(a) = g(f(a)) = g(b) = c.
Theorem B

Bijections and inverses

A function f:A→Bf: A \to B is bijective if and only if there is a function g:B→Ag: B \to A with g(f(a))=ag(f(a)) = a for every a∈Aa \in A and f(g(b))=bf(g(b)) = b for every b∈Bb \in B. This gg is called the inverse of ff and written f−1f^{-1}. In particular, f−1f^{-1} is also bijective.

In one linef:A→Bf: A \to B is bijective exactly when there is a function g:B→Ag: B \to A that undoes it in both orders; this gg is the inverse f−1f^{-1}.

Why it is trueA bijection pairs each target with exactly one source, and reading the pairing backwards is the inverse.

ProofHammack 12.3
The idea: (Forward) Define g by 'the one input that lands on b', which exists because f is onto and is unique because f is one-to-one. (Backward) Use g to show f is injective and surjective.
(Bijective implies inverse.) Let b∈Bb \in B. There is exactly one a∈Aa \in A with f(a)=bf(a) = b. Define g(b)=ag(b) = a.
Surjective gives at least one input for each target; injective gives at most one. So 'the' input is well defined.This is the first time the two halves of 'bijective' are both used. Surjective makes g defined everywhere; injective makes g single-valued.
Then f(g(b))=bf(g(b)) = b for every bb.
By the definition of gg, the input chosen for bb is sent by ff to bb.
And g(f(a))=ag(f(a)) = a for every aa.
For a∈Aa \in A, put b=f(a)b = f(a). The unique input sent to bb is aa itself, so g(b)=ag(b) = a.
(Inverse implies bijective.) If f(x)=f(y)f(x) = f(y), then x=g(f(x))=g(f(y))=yx = g(f(x)) = g(f(y)) = y. So ff is injective.
Apply gg to both sides of f(x)=f(y)f(x) = f(y) and use g(f(⋅))=idg(f(\cdot)) = \mathrm{id}.
For b∈Bb \in B, f(g(b))=bf(g(b)) = b, so bb is an output of ff. So ff is surjective.
Given bb, the input g(b)g(b) is sent by ff to bb.
Finally ff is an inverse of gg, so gg is bijective too.
The conditions in the theorem are symmetric: they also say that ff is an inverse of gg. Apply the theorem to gg.
Quick checkf:A→Bf: A \to B and g:B→Cg: B \to C are functions, and g∘fg \circ f is injective. What must be true?

Size without counting

Definition B

Finite set

Write {1,…,n}\{1, \dots, n\} for the first nn counting numbers (∅\varnothing when n=0n = 0). A set AA is finite with cardinality (size) ∣A∣=n\lvert A \rvert = n if there is a bijection {1,…,n}→A\{1, \dots, n\} \to A. A set that is not finite is infinite. Two sets AA and BB have the same cardinality if there is a bijection A→BA \to B.

In one lineA set is finite with n elements if it can be matched with 1, 2, ..., n by a bijection; the number n is its size.

This definition would be useless if one set could be matched to both {1,…,5}\{1, \dots, 5\} and {1,…,6}\{1, \dots, 6\}. The pigeonhole principle says it cannot, so ∣A∣\lvert A \rvert is well defined.

Theorem B

Pigeonhole principle

If n>mn > m, every function f:{1,…,n}→{1,…,m}f: \{1, \dots, n\} \to \{1, \dots, m\} is not injective.

In one lineIf more pigeons than holes, two pigeons share a hole: there is no injective function from {1,…,n}\{1, \dots, n\} to {1,…,m}\{1, \dots, m\} when n>mn > m.

Why it is trueRemove one hole and the pigeon in it, and use induction on the number of holes.

Proofstandard
The idea: Induct on the number of holes m. For the step, look at the last hole: take out the pigeon sitting in it (if any) and use the smaller case.
We prove S(m)S(m) for m=1,2,3,…m = 1, 2, 3, \dots by induction.
Mathematical induction on mm (0.2). The statement S(m)S(m) is: every function from a set with more than mm elements into {1,…,m}\{1, \dots, m\} is not injective.
S(1)S(1) holds.
Base case. If m=1m = 1 and n≥2n \ge 2, then f(1)=1=f(2)f(1) = 1 = f(2), since there is only one possible output.
Take ff as above. Split into two cases.
Inductive step: assume S(m)S(m) and let n>m+1n > m + 1 and f:{1,…,n}→{1,…,m+1}f: \{1, \dots, n\} \to \{1, \dots, m + 1\}. If two inputs already map to m+1m + 1 we are done, so assume at most one does.
Case 1: if no input goes to m+1m + 1, then ff is not injective by S(m)S(m).
Case 1: no input is sent to m+1m + 1. Then ff is a function into {1,…,m}\{1, \dots, m\} from n>m+1>mn > m + 1 > m points, and S(m)S(m) applies directly.
Case 2: if exactly one input kk goes to m+1m + 1, define hh on {1,…,n−1}\{1, \dots, n-1\} by skipping kk.
Case 2: exactly one input kk goes to m+1m + 1. Delete kk and close the gap in the numbering: h(i)=f(i)h(i) = f(i) for i<ki \lt k and h(i)=f(i+1)h(i) = f(i + 1) for i≥ki \ge k. Then hh maps n−1>mn - 1 > m points into {1,…,m}\{1, \dots, m\}.
So ff is not injective, and S(m+1)S(m + 1) holds.
S(m)S(m) says hh is not injective: h(i)=h(j)h(i) = h(j) for some i≠ji \ne j. These come from two different inputs of ff with the same value, so ff is not injective either.

If AA could be matched with both {1,…,n}\{1, \dots, n\} and {1,…,m}\{1, \dots, m\} with n>mn > m, composing one bijection with the inverse of the other would give an injective function {1,…,n}→{1,…,m}\{1, \dots, n\} \to \{1, \dots, m\}, which is impossible. So the size of a finite set is well defined.

Your answerThere are 12 months in a year. What is the smallest number of people that guarantees two of them have a birthday in the same month?

Using bijections to compare any two sets gives something that behaves like “equals”: it is reflexive (the identity), symmetric (inverses, by the theorem above) and transitive (compositions, by the proposition above). In the language of 0.4, “has the same cardinality as” is an equivalence relation, and a cardinality is a class of sets that can be matched with each other.

Countable and uncountable

Now the main question. The counting numbers N\mathbb N are the smallest infinite set we know. Which infinite sets can be matched with it?

Definition B

Countable

A set AA is countable if it is finite, or there is a bijection f:N→Af: \mathbb N \to A. Writing an=f(n)a_n = f(n), such a bijection is a listing a1,a2,a3,…a_1, a_2, a_3, \dots of AA. A countable infinite set is also called countably infinite. (Some books, such as Abbott’s, reserve “countable” for the infinite case and say “at most countable” for the rest. CS 240 calls a bijection like this an enumeration.)

In one lineA set is countable if its elements can be put in a list, first, second, third, with every element appearing exactly once; finite sets count too.

Why it existsCountable sets are the 'discrete' ones. Everything a computer can store or enumerate is countable.

Definition B

Uncountable

A set is uncountable if it is not countable.

In one lineA set is uncountable if it is not countable: no list, however cleverly made, contains all its elements.

Why it existsIt shows that infinity comes in more than one size, and that some infinite sets are strictly bigger than the counting numbers.

How to prove a set is countable

You asked for this explicitly, and for the pieces that are easy to leave out. A listing a1,a2,a3,…a_1, a_2, a_3, \dots of AA is a bijection N→A\mathbb N \to A, so you must show three things. The first is easy to forget, and the other two are the ones you named.

  1. Every position gives an element of AA. The rule n↦ann \mapsto a_n really produces members of AA (it is a function into AA).
  2. Every element of AA appears. For each x∈Ax \in A you can say at which position it shows up: the listing is onto. Without this, you have only listed part of AA.
  3. No element appears twice. Different positions give different elements: the listing is one-to-one. Without this, you have listed things with repeats, which can make AA look bigger than it is.

Here is the template, as the lines you would write in a proof. Suppose you propose the rule f(n)=…f(n) = \dots for the nnth element.

  1. Define f(n)f(n) for every n∈Nn \in \mathbb N.
  2. It lands in AA. Check that f(n)∈Af(n) \in A for every nn.
  3. It hits everything. Take an arbitrary x∈Ax \in A. Find the position nn with f(n)=xf(n) = x (a formula in xx), and check that this nn really is a counting number.
  4. No repeats. Suppose f(n)=f(m)f(n) = f(m). Show that n=mn = m.
  5. Conclude. ff is a bijection N→A\mathbb N \to A, so AA is countable.

Steps 3 and 4 are the two halves of “bijection”: step 3 is onto, step 4 is one-to-one. Leaving out step 3 is the most common way to write a wrong proof. A list of 0,1,2,3,…0, 1, 2, 3, \dots followed by −1,−2,−3,…-1, -2, -3, \dots looks like a listing of Z\mathbb Z, but the negative numbers would sit after the end of an infinite list, so no position is ever given to −1-1. Step 3 fails for it, and the proof breaks there.

Quick checkA student 'lists' Z\mathbb Z as 0,1,2,3,…0, 1, 2, 3, \dots and then continues −1,−2,−3,…-1, -2, -3, \dots after all of those. What is wrong?

The “no repeats” condition often fails in natural attempts (as with fractions: 1/21/2 and 2/42/4), so the next theorem says exactly which of the conditions you can relax.

Theorem B

Three ways to show a set is countable

For a set AA, the following are equivalent for A≠∅A \ne \varnothing (and (a), (b) are equivalent for A=∅A = \varnothing too):

  • (a) AA is countable;
  • (b) there is an injective function A→NA \to \mathbb N;
  • (c) there is a surjective function N→A\mathbb N \to A.

In one lineAA is countable iff there is an injection A→NA \to \mathbb N; and a non-empty AA is countable iff there is a surjection N→A\mathbb N \to A (a list that may have repeats).

Why it is trueAn injection into the counting numbers lets you read off a position for each element, and a list with repeats can be cleaned by keeping the first appearance of each element.

ProofAbbott 1.5; Hammack 13.3
The idea: (a) implies (b) by inverting the listing. (b) implies (a) by sorting the used numbers in increasing order, which uses well-ordering. (c) implies (b) by sending each element to the first position where it appears. (a) implies (c) by listing, repeating the last element if finite.
(a) implies (b).
If AA is finite with nn elements, there is a bijection h:{1,…,n}→Ah: \{1, \dots, n\} \to A and its inverse maps AA into N\mathbb N. If AA is countably infinite with listing ff, then f−1:A→Nf^{-1}: A \to \mathbb N. Inverses of bijections are bijections, hence injective.
(b) implies (a). Set B=φ(A)B = \varphi(A).
Let φ:A→N\varphi: A \to \mathbb N be injective. If AA is finite we are done, so assume AA is infinite. Let B=φ(A)⊆NB = \varphi(A) \subseteq \mathbb N. Then φ:A→B\varphi: A \to B is a bijection (injective, and onto BB by definition), so BB is infinite too.
Sort BB by repeatedly taking the least element not yet taken: b1,b2,b3,…b_1, b_2, b_3, \dots.
Well-ordering: every non-empty set of counting numbers has a least element. Let b1b_1 be the least element of BB. Having chosen b1,…,bkb_1, \dots, b_k, the set B∖{b1,…,bk}B \setminus \{b_1, \dots, b_k\} is non-empty because BB is infinite; let bk+1b_{k+1} be its least element.
The sequence is strictly increasing. Define g(k)=bkg(k) = b_k. Then gg is injective, since different positions have different values.
bk+1b_{k+1} lies in B∖{b1,…,bk−1}B \setminus \{b_1, \dots, b_{k-1}\}, where bkb_k was the least element, so bk≤bk+1b_k \le b_{k+1}. They are different, so bk<bk+1b_k \lt b_{k+1}.
Also bk≥kb_k \ge k for every kk.
Since b1≥1b_1 \ge 1 and each bk+1>bkb_{k+1} \gt b_k is at least one more, induction gives bk≥kb_k \ge k.
gg is surjective onto BB: no element of BB is skipped.
Suppose m∈Bm \in B is never chosen. Then for every kk, m∈B∖{b1,…,bk}m \in B \setminus \{b_1, \dots, b_k\}, so the least element bk+1b_{k+1} of that set satisfies bk+1≤mb_{k+1} \le m. Taking k=mk = m gives bm+1≤mb_{m+1} \le m, but bm+1≥m+1b_{m+1} \ge m + 1. This is a contradiction, so every m∈Bm \in B equals some bkb_k.
So φ−1∘g:N→A\varphi^{-1} \circ g: \mathbb N \to A is a bijection, and AA is countable.
Composition of bijections is a bijection, and inverses are bijections.
(c) implies (b).
(c) implies (b). Let s:N→As: \mathbb N \to A be onto. For a∈Aa \in A the set {n:s(n)=a}\{n : s(n) = a\} is non-empty, so by well-ordering it has a least element. Define φ(a)\varphi(a) to be that least element, so s(φ(a))=as(\varphi(a)) = a.
So φ\varphi is injective.
If φ(a)=φ(a′)\varphi(a) = \varphi(a'), then a=s(φ(a))=s(φ(a′))=a′a = s(\varphi(a)) = s(\varphi(a')) = a'.
Every non-empty countable set has a surjection from N\mathbb N.
(a) implies (c), for A≠∅A \ne \varnothing. If AA is countably infinite, the listing itself is onto. If A={a1,…,an}A = \{a_1, \dots, a_n\}, define s(k)=aks(k) = a_k for k≤nk \le n and s(k)=ans(k) = a_n for k>nk \gt n.

In practice this means: if listing without repeats is awkward, you may list with repeats, but you may never leave an element out.

Quick checkYou build a list a1,a2,a3,…a_1, a_2, a_3, \dots of a non-empty set AA. Every element of AA appears at least once, and some appear several times. What can you conclude?

Three consequences are used constantly.

Corollary B

Closure properties of countable sets

  1. If BB is countable and A⊆BA \subseteq B, then AA is countable.
  2. If AA is countable and g:A→Cg: A \to C is onto, then CC is countable.
  3. If AA and BB are countable, then so is A×BA \times B (provided N×N\mathbb N \times \mathbb N is countable, proved below).

In one lineSubsets of countable sets are countable; the image of a countable set under any function is countable; a product of two countable sets is countable.

Why it is trueEach one follows by composing with the injections and surjections of the previous theorem.

Proofstandard
The idea: Each part builds the required injection or surjection by composing functions.
(1) The restriction of ψ\psi to AA is an injection A→NA \to \mathbb N, so AA is countable by (b) implies (a).
By (a) implies (b), there is an injection ψ:B→N\psi: B \to \mathbb N. Restricting an injection to a smaller domain keeps it injective.
(2) g∘s:N→Cg \circ s: \mathbb N \to C is onto, so CC is countable by (c) implies (a).
If A=∅A = \varnothing then C=∅C = \varnothing, which is finite. Otherwise (a) implies (c) gives a surjection s:N→As: \mathbb N \to A, and a composition of surjections is a surjection.
(3) Compose that map with an injection N×N→N\mathbb N \times \mathbb N \to \mathbb N (the theorem below).
Take injections φ:A→N\varphi: A \to \mathbb N and ψ:B→N\psi: B \to \mathbb N. The map (a,b)↦(φ(a),ψ(b))(a, b) \mapsto (\varphi(a), \psi(b)) is injective into N×N\mathbb N \times \mathbb N, since equal pairs have equal coordinates, and each coordinate map is injective.
So A×BA \times B is countable by (b) implies (a).
The composite of injections is injective (the proposition above), so A×BA \times B injects into N\mathbb N.

The integers are countable

Theorem B

The integers are countable

The function f:N→Zf: \mathbb N \to \mathbb Z defined by f(n)=n/2f(n) = n/2 for even nn and f(n)=−(n−1)/2f(n) = -(n - 1)/2 for odd nn is a bijection.

In one lineZ\mathbb Z can be listed as 0,1,−1,2,−2,3,−3,…0, 1, -1, 2, -2, 3, -3, \dots with every integer exactly once.

Why it is trueAlternate between non-positive and positive integers, so that going outward on both sides still reaches each integer at a definite position.

The first values are in the table.

Position nn123456789
f(n)f(n)01-12-23-34-4
ProofCS 240; Abbott 1.5
The idea: Check the three things: f lands in the integers, every integer is hit (find its position), and no integer is hit twice. Positive integers sit at the even positions, and zero and negatives at the odd positions.
ff takes integer values.
Both formulas give integers: n/2n/2 is an integer for even nn, and (n−1)/2(n-1)/2 is an integer for odd nn. So ff is a function N→Z\mathbb N \to \mathbb Z (property 1).
Let z∈Zz \in \mathbb Z. If z≥1z \ge 1, then f(2z)=zf(2z) = z.
Onto, positive case (property 2). If z≥1z \ge 1, take n=2zn = 2z, which is even and in N\mathbb N. Then f(n)=2z/2=zf(n) = 2z/2 = z.
If z≤0z \le 0, then f(1−2z)=zf(1 - 2z) = z.
Onto, non-positive case. If z≤0z \le 0, take n=1−2zn = 1 - 2z, which is odd and at least 11, so in N\mathbb N. Then f(n)=−(1−2z−1)/2=−(−2z)/2=zf(n) = -(1 - 2z - 1)/2 = -(-2z)/2 = z.
Suppose f(n)=f(m)f(n) = f(m). Then nn and mm are both even or both odd.
One-to-one, property 3. Suppose f(n)=f(m)f(n) = f(m). Even inputs give positive integers (n/2≥1n/2 \ge 1) and odd inputs give integers at most 00 (−(n−1)/2≤0-(n-1)/2 \le 0). So nn and mm cannot have different parity.
In either case n=mn = m.
If both are even, n/2=m/2n/2 = m/2, so n=mn = m. If both are odd, −(n−1)/2=−(m−1)/2-(n-1)/2 = -(m-1)/2, so n=mn = m.
So ff is a bijection and Z\mathbb Z is countable.
A bijection N→Z\mathbb N \to \mathbb Z is exactly a listing of Z\mathbb Z in which every integer appears once.
Your answerUsing the listing of Z\mathbb Z above (f(n)=n/2f(n) = n/2 for even nn, f(n)=−(n−1)/2f(n) = -(n-1)/2 for odd nn), at which position nn does the integer −7-7 appear?
Proof workshopRebuild the proof that the integers are countable

Tap the lines in the order a proof would write them. Each line can only use what is already above it.

    A common worry is that the list “uses up” a whole infinite supply of positives before it reaches any negatives. It does not: the list is an alternating weave, so the positive integer zz appears at position 2z2z, and the negative −k-k appears at position 2k+12k + 1. Each integer has a finite position.

    The pairs of counting numbers are countable

    The next step is the one that surprises people: a whole plane of pairs fits into a single list.

    Theorem B

    The counting-number pairs are countable

    The function P:N×N→NP: \mathbb N \times \mathbb N \to \mathbb N, P(m,n)=(m+n−2)(m+n−1)2+mP(m, n) = \tfrac{(m + n - 2)(m + n - 1)}{2} + m, is a bijection.

    In one lineN×N\mathbb N \times \mathbb N can be listed diagonal by diagonal, and the position of (m,n)(m, n) is P(m,n)=(m+n−2)(m+n−1)2+mP(m, n) = \tfrac{(m + n - 2)(m + n - 1)}{2} + m.

    Why it is trueEach diagonal m+n=sm + n = s is finite, so listing diagonals one after another reaches every pair after finitely many steps.

    Picture the pairs as a grid. Row mm and column nn hold the pair (m,n)(m, n). The diagonal where m+n=sm + n = s holds exactly s−1s - 1 pairs: (1,s−1),(2,s−2),…,(s−1,1)(1, s - 1), (2, s - 2), \dots, (s - 1, 1). List the diagonals in order of s=2,3,4,…s = 2, 3, 4, \dots and each diagonal from top to bottom.

    Proofstandard
    The idea: The pairs with m + n = s fill positions from T(s-2) + 1 to T(s-1), where T(j) = j(j+1)/2 counts the pairs on the diagonals before. Show each position lies in exactly one such block and, inside it, picks out exactly one pair.
    So P(m,n)=T(s−2)+mP(m, n) = T(s - 2) + m where s=m+ns = m + n.
    Definition: the triangular number T(j)=1+2+⋯+j=j(j+1)/2T(j) = 1 + 2 + \dots + j = j(j+1)/2, with T(0)=0T(0) = 0. The diagonals s=2,…,s−1s = 2, \dots, s - 1 hold 1+2+⋯+(s−2)=T(s−2)1 + 2 + \dots + (s - 2) = T(s - 2) pairs.
    So the pairs of diagonal ss land in the block of positions T(s−2)+1,…,T(s−1)T(s-2) + 1, \dots, T(s-1), which has s−1s - 1 places.
    Property 1: PP lands in N\mathbb N. For a pair on diagonal ss, we have 1≤m≤s−11 \le m \le s - 1, so T(s−2)<P(m,n)≤T(s−2)+(s−1)=T(s−1)T(s-2) \lt P(m,n) \le T(s-2) + (s - 1) = T(s-1).
    Every k∈Nk \in \mathbb N lies in exactly one block, for exactly one ss.
    The numbers T(0)<T(1)<T(2)<…T(0) \lt T(1) \lt T(2) \lt \dots are strictly increasing and unbounded (T(j)≥jT(j) \ge j), so the blocks for s=2,3,4,…s = 2, 3, 4, \dots are disjoint and together cover every counting number.
    Every position kk is the position of some pair.
    Onto (property 2). Given kk, find the ss with T(s−2)<k≤T(s−1)T(s-2) \lt k \le T(s-1). Put m=k−T(s−2)m = k - T(s-2), which satisfies 1≤m≤s−11 \le m \le s - 1, and n=s−m≥1n = s - m \ge 1. Then m,n∈Nm, n \in \mathbb N and P(m,n)=T(s−2)+m=kP(m, n) = T(s-2) + m = k.
    No position is shared by two pairs.
    One-to-one (property 3). If P(m,n)=P(m′,n′)=kP(m, n) = P(m', n') = k, then kk lies in a single block, so s=m+ns = m + n equals s′=m′+n′s' = m' + n'. Then m=k−T(s−2)=m′m = k - T(s-2) = m', and n=s−m=n′n = s - m = n'.

    So the whole infinite grid is one list: (1,1),(1,2),(2,1),(1,3),(2,2),(3,1),…(1,1), (1,2), (2,1), (1,3), (2,2), (3,1), \dots Every pair is reached after finitely many steps, because it sits on a finite diagonal. (An alternative injection is (m,n)↦2m3n(m, n) \mapsto 2^m 3^n, which is injective by unique factorization into primes, proved in 0.5.)

    Your answerUse P(m,n)=(m+n−2)(m+n−1)2+mP(m, n) = \tfrac{(m + n - 2)(m + n - 1)}{2} + m. At which position does the pair (4,3)(4, 3) appear in the diagonal listing?
    Your answerHow many pairs (m,n)(m, n) of counting numbers have m+n≤10m + n \le 10?

    The rationals are countable

    Theorem B

    The rationals are countable

    The set Q\mathbb Q of rational numbers is countable.

    In one lineQ\mathbb Q can be listed, even though between any two rationals there are infinitely many more.

    Why it is trueEvery rational is a fraction of integers, and pairs of integers are countable. The repeats like 1/2 and 2/4 are removed by keeping only the first appearance.

    ProofAbbott 1.5; CS 240
    The idea: Do not try to list the rationals in order of size; there is no 'next' one. Instead, list the fractions (all pairs of integers), which are countable, and then cover each rational by at least one fraction. A list with repeats is enough, by the theorem on three ways.
    Z×N\mathbb Z \times \mathbb N is countable.
    Z\mathbb Z is countable by the integers theorem, and N\mathbb N is countable (the identity is a listing). A product of countable sets is countable.
    Define q:Z×N→Qq: \mathbb Z \times \mathbb N \to \mathbb Q by q(z,b)=z/bq(z, b) = z / b. It is onto.
    By the definition of Q\mathbb Q, every rational is z/bz/b for some z∈Zz \in \mathbb Z and b∈Nb \in \mathbb N. So the function q(z,b)=z/bq(z, b) = z/b is onto Q\mathbb Q. It is not one-to-one: q(1,2)=q(2,4)q(1, 2) = q(2, 4).
    So Q\mathbb Q is countable.
    Closure property 2: the image of a countable set under a function that is onto its target is countable. The repeats do not matter, because the proof of (c) implies (b) keeps only the first position of each rational.

    What does the resulting list look like, and why does each rational appear exactly once? The proof says: walk through the pairs in the diagonal order and write a/ba/b for each pair, skipping a fraction if it equals one already written. Do that for positive fractions and put −q-q after each new qq. Here is the start of the list.

    Every rational q=z/bq = z/b is reached: its fraction (∣z∣,b)(|z|, b) sits at a finite position in the diagonal order, so it is written at that position or earlier. No rational is written twice, because a rational is written only if it is not already on the list.

    Quick checkBetween any two rational numbers there is another rational (for example their average). So the rationals are 'dense', and there is no next one. Does that make Q\mathbb Q uncountable?

    The real numbers are not countable

    We now meet a set that cannot be listed at all. Cantor’s idea is to show that any list that claims to contain every number is lying, by writing down a number that the list misses. The number is built from the list itself.

    First two school facts that we use about decimal expansions. We take them as known; Unit 1 builds the real numbers carefully enough to prove them.

    1. Every real xx with 0<x<10 \lt x \lt 1 can be written as an infinite decimal 0.d1d2d3…0.d_1 d_2 d_3 \dots with digits di∈{0,1,…,9}d_i \in \{0, 1, \dots, 9\}.
    2. A number has more than one such expansion only when one of them ends in all zeros and the other in all nines, like 0.5000⋯=0.4999…0.5000\dots = 0.4999\dots. So an expansion that does not end in all zeros or all nines is the only expansion of its number.
    Theorem B Cantor 1891

    The real numbers are uncountable

    The set (0,1)={x∈R:0<x<1}(0, 1) = \{x \in \mathbb R : 0 \lt x \lt 1\} is uncountable. Consequently R\mathbb R is uncountable.

    In one lineThe interval (0,1)(0, 1), and so the set R\mathbb R of all real numbers, cannot be listed.

    Why it is trueGiven any list, build a number that differs from the nnth number of the list in its nnth digit. It is in (0,1)(0, 1) but is not on the list.

    Here is the idea on a concrete list. Suppose someone claims that this list contains every number in (0,1)(0, 1), and the digits shown are the start of each expansion.

    Why digits 44 and 55? Any rule “make the digit different” works, as long as the new digits are never 00 or 99. That avoids the double-expansion trap (0.5000⋯=0.4999…0.5000\dots = 0.4999\dots), which could otherwise make yy equal to some xnx_n in value while differing in digits.

    ProofCantor 1891; Abbott Thm 1.6.1
    The idea: Assume for contradiction that (0, 1) can be listed. Write each listed number as a decimal. Build y by changing the n-th digit of the n-th number to something else (never 0 or 9). Then y is in (0, 1) but differs from every listed number, which contradicts the list being complete.
    Suppose (0,1)(0, 1) is countable. Then there are numbers x1,x2,x3,…x_1, x_2, x_3, \dots such that every number in (0,1)(0, 1) equals some xnx_n.
    Proof by contradiction (0.2): assume the statement is false. (0,1)(0, 1) is infinite, so countable means there is a bijection N→(0,1)\mathbb N \to (0, 1). We only use that it is onto.
    For each nn fix a decimal expansion xn=0.dn1dn2dn3…x_n = 0.d_{n1} d_{n2} d_{n3} \dots Here dnkd_{nk} is the kkth digit of xnx_n.
    School fact 1: every number in (0,1)(0, 1) has a decimal expansion. If a number has two, pick either one and fix the choice.
    Define y=0.e1e2e3…y = 0.e_1 e_2 e_3 \dots by en=5e_n = 5 if dnn≠5d_{nn} \ne 5, and en=4e_n = 4 if dnn=5d_{nn} = 5.
    This is the diagonal: for each nn, look at the digit dnnd_{nn} in position nn of xnx_n, and choose a digit of yy that disagrees with it. The choices 44 and 55 are never 00 or 99.
    So y∈(0,1)y \in (0, 1).
    All digits of yy are 44 or 55, so 0.444⋯≤y≤0.555…0.444\dots \le y \le 0.555\dots, which is strictly between 00 and 11.
    So y=xny = x_n for some nn.
    The assumption: every number of (0,1)(0, 1) is on the list.
    Then the digits of xnx_n are the digits e1,e2,e3,…e_1, e_2, e_3, \dots of yy.
    School fact 2: the digits of yy never end in all zeros or all nines, so 0.e1e2…0.e_1 e_2 \dots is the only expansion of yy. The chosen expansion of xnx_n is also an expansion of y=xny = x_n, so the two expansions are identical.
    So dnn=end_{nn} = e_n.
    Compare position nn on both sides: the nnth digit of xnx_n is dnnd_{nn}, and the nnth digit of yy is ene_n.
    This contradicts the definition of ene_n. So (0,1)(0, 1) is not countable.
    But by construction en≠dnne_n \ne d_{nn} for every nn. We have a statement and its negation, a contradiction.
    Hence R\mathbb R is uncountable too: otherwise (0,1)⊆R(0,1) \subseteq \mathbb R would be countable.
    Closure property 1: a subset of a countable set is countable. If R\mathbb R were countable, its subset (0,1)(0, 1) would be countable.
    Proof workshopRebuild Cantor's diagonal argument

    Tap the lines in the order a proof would write them. Each line can only use what is already above it.

      Watch out· 'Just add y to the list' does not fix anything

      The usual objection is: “fine, yy was missing, so put it at the top and the list is complete.” It is not, because the argument works for every list. Give me the new list and I run the same construction on it and build a new missing number. The point is not that one number is missing. It is that no list can ever be complete.

      A preview· Preview: why the real numbers are 'more' than the rationals

      Q\mathbb Q is countable, and R\mathbb R is not, so almost all real numbers are irrational, in a strong sense that measure theory later makes precise. What separates them is completeness: the real line has no gaps, while Q\mathbb Q is full of holes (for example 2\sqrt 2, see 0.2). Cantor’s first proof, in 1874, used completeness directly. Chapter 1.1 states completeness and uses it to prove that sequences that should converge really do.

      Where this came from· Cantor, 1874 and 1891

      Georg Cantor’s first proof that the real numbers cannot be listed appeared in 1874, in a paper whose title announced something else: a property of the collection of all real algebraic numbers (roots of polynomials with integer coefficients). He showed that these algebraic numbers can be listed, and that the reals cannot, which proved that there are non-algebraic (“transcendental”) numbers without exhibiting one. That proof used the completeness of the real line. In 1891 he published the diagonal argument you just followed, which works with infinite sequences and also gives the general fact that every set has strictly more subsets than elements. What he was trying to settle was whether all infinite sets are the same size. The answer, no, changed what mathematicians meant by infinity.

      Quick checkIn the diagonal argument, why can we not build yy by 'adding 1 to the diagonal digit'?

      Examples of countability proofs

      The recipe from the previous section applies to any new set. First find an injection into a set you already know is countable (or a surjection from one), then use the theorem on three ways. Here are three sets of the kind the problems ask for: one by a listing, one by weaving two lists together, one by an injection.

      Worked example CS 240
      Prove that the set E={2,4,6,8,… }E = \{2, 4, 6, 8, \dots\} of positive even integers is countable.

      Solution. The plan: write down a listing and check the three properties.

      1. Name the listing. Let f(n)=2nf(n) = 2n. The list is 2,4,6,…2, 4, 6, \dots This is the natural enumeration, a rule that gives the element in each position.
      2. Check it lands in EE. For each n∈Nn \in \mathbb N, 2n2n is positive and equals 2⋅n2 \cdot n with nn an integer, so it is a positive even integer. Property 1: every position gives an element of the set.
      3. Check it hits everything. Let k∈Ek \in E. Then k=2jk = 2j for some integer jj, and j=k/2>0j = k/2 > 0, so j∈Nj \in \mathbb N and f(j)=kf(j) = k. The element kk sits at position k/2k/2. Property 2: for each element we can name the position, and the position is a legal one.
      4. Check there are no repeats. If f(n)=f(m)f(n) = f(m) then 2n=2m2n = 2m, so n=mn = m. Property 3: different positions give different elements.

      Answer. ff is a bijection N→E\mathbb N \to E, so EE is countable. Note that E⊊NE \subsetneq \mathbb N and the two sets still match perfectly.

      Worked example Hammack 13.3
      Prove that the union A∪BA \cup B of two countable sets is countable.

      Solution. The plan: use surjections from N\mathbb N and weave the two lists together.

      1. Get two lists. If one of A,BA, B is empty the claim is trivial. Otherwise the theorem on three ways gives surjections s:N→As: \mathbb N \to A and t:N→Bt: \mathbb N \to B. A surjection is a list that is allowed to repeat, which is all we need.
      2. Weave them. Define u(n)=s((n+1)/2)u(n) = s((n + 1)/2) if nn is odd and u(n)=t(n/2)u(n) = t(n/2) if nn is even. The odd positions list AA and the even positions list BB, in the same alternating pattern that listed Z\mathbb Z.
      3. Check uu is onto A∪BA \cup B. An element a∈Aa \in A equals s(k)s(k) for some kk, and then a=u(2k−1)a = u(2k - 1). An element b∈Bb \in B equals t(k)t(k) for some kk, and then b=u(2k)b = u(2k). Every element of the union is in AA or in BB, and each is reached.
      4. Conclude. uu is a surjection from N\mathbb N onto A∪BA \cup B, so A∪BA \cup B is countable. Part (c) implies (a) of the theorem. We did not need to check for repeats, because a repeat only matters for a bijection.

      Answer. A∪BA \cup B is countable.

      Worked example
      Prove that the set WW of all finite strings of 00s and 11s (including the empty string) is countable.

      Solution. The plan: this time use an injection into N\mathbb N and conclude by the theorem on three ways.

      1. Define the map. For a string ss, let φ(s)\varphi(s) be the counting number whose binary (base 2) notation is the digit 11 followed by ss. For example φ(empty)=12=1\varphi(\text{empty}) = 1_2 = 1, φ(0)=102=2\varphi(0) = 10_2 = 2, φ(1)=112=3\varphi(1) = 11_2 = 3, φ(00)=1002=4\varphi(00) = 100_2 = 4. Putting a leading 11 in front stops leading zeros of ss from being lost, so strings like 00 and 0000 get different numbers.
      2. It lands in N\mathbb N. Every binary notation starting with 11 is a counting number. Property 1: the rule produces members of the target.
      3. It is injective. Suppose φ(s)=φ(t)\varphi(s) = \varphi(t). Then the binary notations "1s1s" and "1t1t" are notations of the same number, and a number has only one binary notation that starts with 11. So 1s=1t1s = 1t as strings, hence s=ts = t. The template for injective: equal outputs force equal inputs. Uniqueness of binary notation is the fact used.
      4. Conclude. An injection W→NW \to \mathbb N exists, so WW is countable. Part (b) implies (a) of the theorem. With an injection we do not have to show that every counting number is used; the theorem sorts out the positions for us.

      Answer. WW is countable. The same trick shows that the set of all finite programs, written as strings over a fixed alphabet, is countable.

      Where it is used

      Used inside maths· Inside maths: sequences, probability, and what 'almost all' means

      A sequence is a function N→R\mathbb N \to \mathbb R, so the whole of Unit 1 is the study of functions defined on a countable set. In probability (MATH 431) the axioms ask for additivity over countably many disjoint events, and “choose a real number uniformly in (0,1)(0, 1)” is only possible because the reals are uncountable: each single number must have probability 00. Later in analysis you will see that every countable set of reals has total length 00, so the rationals, though dense, take up no room on the line.

      Used in the real world· Computer science: what a program can and cannot name

      A program is a finite string of characters, and finite strings over a fixed alphabet can be listed (all strings of length 1 first, then length 2, and so on, each length being a finite list). So there are only countably many programs, but there are uncountably many functions from N\mathbb N to {0,1}\{0, 1\} (the same diagonal argument; see the stretch problem). Hence most functions are computed by no program at all, which is the starting point of Turing’s 1936 paper on what computers cannot do. The same argument says that only countably many real numbers can ever be named by a formula or computed to any precision.

      The pigeonhole principle is the practical cousin: a checksum with 16 bits has 216=65 5362^{16} = 65\,536 possible values, so among 65 53765\,537 different files two must have the same checksum. No injective function from a large set to a small set exists, however clever the hash. A SQL query that joins a table of 1000 customers with a table of 50 products, with no condition, produces their Cartesian product: 1000×50=50 0001000 \times 50 = 50\,000 rows. The condition in a WHERE clause then selects a subset of it (a relation, see 0.4).

      Traps

      Watch out· Countable does not mean finite, and uncountable does not mean 'big'

      “Countable” means “can be put in an infinite list” (or is finite). The integers are infinite and countable. “Uncountable” is the statement that no list can ever be complete. Nobody is asking you to count to the end.

      Watch out· A list with repeats still proves countability, but a list with gaps does not

      When a listing for Q\mathbb Q repeats 1/21/2 and 2/42/4, you may leave the repeats in: a surjection from N\mathbb N is enough. What you may not do is skip elements. Whenever you propose a listing, say at which position an arbitrary element of the set appears.

      Watch out· Complement flips union and intersection

      (A∪B)c=Ac∩Bc(A \cup B)^c = A^c \cap B^c, never Ac∪BcA^c \cup B^c. When you push a complement inside brackets, every union becomes an intersection and every intersection becomes a union, just as ‘or’ becomes ‘and’ when you negate.

      Watch out· Subset symbols and the empty set

      CS 240 writes ⊆\subseteq for subset and ⊂\subset for proper subset. Many textbooks write ⊂\subset for the plain subset, so read the book’s convention first. And ∅≠{∅}\varnothing \ne \{\varnothing\}: the empty set has no elements, while {∅}\{\varnothing\} has one, namely the empty set. Both of these are subsets of {∅}\{\varnothing\}.

      Watch out· A function must be defined everywhere, once

      A rule is a function only if every input in the domain has exactly one output in the codomain. f(x)=1/xf(x) = 1/x is not a function on R\mathbb R (no output at 00), and "±x\pm\sqrt{x}" gives two outputs. Always say the domain and codomain, because injective and surjective depend on them.

      Watch out· Injective is 'f(x) = f(y) implies x = y', not the other way round

      The statement ”x=yx = y implies f(x)=f(y)f(x) = f(y)” is true for every function; it is just what “function” means. Injectivity is the converse. This is the converse trap of chapter 0.1, in a new place.

      Problems

      check

      Let A={1,2,3}A = \{1, 2, 3\} and B={2,3,4,5}B = \{2, 3, 4, 5\} in U={1,…,6}U = \{1, \dots, 6\}. List A∪BA \cup B, A∩BA \cap B, A∖BA \setminus B, BcB^c, and say how many elements A×BA \times B has.

      Solution

      A∪B={1,2,3,4,5}A \cup B = \{1, 2, 3, 4, 5\}, A∩B={2,3}A \cap B = \{2, 3\}, A∖B={1}A \setminus B = \{1\}, Bc={1,6}B^c = \{1, 6\}. A×BA \times B has 3⋅4=123 \cdot 4 = 12 elements.

      check

      Write, using the rules for ‘not in’, exactly what x∉(A∪B)∩Cx \notin (A \cup B) \cap C means (in words, with “and” and “or”).

      Solution

      x∈(A∪B)∩Cx \in (A \cup B) \cap C means (x∈A or x∈B)(x \in A \text{ or } x \in B) and x∈Cx \in C. Its negation is: (x∉Ax \notin A and x∉Bx \notin B) or x∉Cx \notin C. The ‘and’ became ‘or’ (rule 1) and the ‘or’ became ‘and’ (rule 2).

      check

      Is f:R→Rf: \mathbb R \to \mathbb R, f(x)=x3f(x) = x^3 injective? Surjective? What about f:R→Rf: \mathbb R \to \mathbb R, f(x)=x3−xf(x) = x^3 - x?

      Solution

      x3x^3: injective, since x3=y3x^3 = y^3 implies x=yx = y (real cube roots are unique), and surjective, since every bb is b33\sqrt[3]{b}^3. So bijective. x3−xx^3 - x: surjective (a continuous function going from −∞-\infty to +∞+\infty takes every value, by the intermediate value theorem of Unit 1), but not injective: f(0)=f(1)=f(−1)=0f(0) = f(1) = f(-1) = 0.

      checkCS 240

      At which position does the integer −5-5 appear in the listing of Z\mathbb Z above, and which integer is at position 5050?

      Solution

      −5-5 is at position 1−2(−5)=111 - 2(-5) = 11 (check: f(11)=−(11−1)/2=−5f(11) = -(11 - 1)/2 = -5). Position 5050 is even, so the integer is 50/2=2550/2 = 25.

      useHammack 8.3

      Prove A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C) by element-chasing, justifying each line.

      Solution

      Let xx be arbitrary. x∈A∩(B∪C)x \in A \cap (B \cup C) iff x∈Ax \in A and (x∈Bx \in B or x∈Cx \in C) (definitions of ∩\cap and ∪\cup) iff (x∈Ax \in A and x∈Bx \in B) or (x∈Ax \in A and x∈Cx \in C) (distributive law of logic, checkable by a truth table) iff x∈A∩Bx \in A \cap B or x∈A∩Cx \in A \cap C (definition of ∩\cap) iff x∈(A∩B)∪(A∩C)x \in (A \cap B) \cup (A \cap C) (definition of ∪\cup). Every line is an if-and-only-if, so the sets are equal.

      use

      Find a counterexample to "(A∖B)∪B=A(A \setminus B) \cup B = A" for all sets A,BA, B, and then say what extra condition makes it true.

      Solution

      Take A={1,2}A = \{1, 2\} and B={2,3}B = \{2, 3\}. Then A∖B={1}A \setminus B = \{1\} and (A∖B)∪B={1,2,3}≠A(A \setminus B) \cup B = \{1, 2, 3\} \ne A. In general x∈(A∖B)∪Bx \in (A \setminus B) \cup B means (x∈Ax \in A and x∉Bx \notin B) or x∈Bx \in B, which is the same as x∈Ax \in A or x∈Bx \in B (if x∈Bx \in B the second part holds, and if x∉Bx \notin B the first part reduces to x∈Ax \in A). So the set equals A∪BA \cup B, which is AA exactly when B⊆AB \subseteq A.

      use

      Prove that f:R∖{1}→R∖{2}f: \mathbb R \setminus \{1\} \to \mathbb R \setminus \{2\}, f(x)=2xx−1f(x) = \dfrac{2x}{x - 1} is a bijection, and find its inverse.

      Solution

      Injective: if 2xx−1=2yy−1\frac{2x}{x-1} = \frac{2y}{y-1}, cross-multiplying gives 2x(y−1)=2y(x−1)2x(y - 1) = 2y(x - 1), so −2x=−2y-2x = -2y and x=yx = y. Surjective: given b≠2b \ne 2, solve 2aa−1=b\frac{2a}{a - 1} = b: 2a=ab−b2a = ab - b, so a(2−b)=−ba(2 - b) = -b, so a=bb−2a = \frac{b}{b - 2}. This is defined because b≠2b \ne 2, and a≠1a \ne 1 since bb−2=1\frac{b}{b-2} = 1 would need b=b−2b = b - 2. Then f(a)=bf(a) = b. The inverse is f−1(b)=bb−2f^{-1}(b) = \frac{b}{b - 2}, that is f−1(x)=xx−2f^{-1}(x) = \frac{x}{x - 2} for x≠2x \ne 2. Check: f(2)=4f(2) = 4 and f−1(4)=4/(4−2)=2f^{-1}(4) = 4/(4-2) = 2.

      use

      Prove that the set OO of odd positive integers is countable, and that Z×Z\mathbb Z \times \mathbb Z is countable.

      Solution

      OO: f(n)=2n−1f(n) = 2n - 1 is a bijection N→O\mathbb N \to O. It lands in OO (2n−12n - 1 is odd and positive). It is onto: if k=2j−1k = 2j - 1 is odd and positive, then j=(k+1)/2∈Nj = (k + 1)/2 \in \mathbb N and f(j)=kf(j) = k. It is one-to-one: 2n−1=2m−12n - 1 = 2m - 1 implies n=mn = m. Z×Z\mathbb Z \times \mathbb Z: Z\mathbb Z is countable, and a product of countable sets is countable (closure property 3, which composes an injection into N×N\mathbb N \times \mathbb N with the diagonal bijection PP).

      proveHammack 12.2

      Prove: if f:A→Bf: A \to B and g:B→Cg: B \to C and g∘fg \circ f is surjective, then gg is surjective. Is ff necessarily surjective?

      Solution

      Let c∈Cc \in C. Since g∘fg \circ f is surjective, there is a∈Aa \in A with g(f(a))=cg(f(a)) = c. Then b=f(a)∈Bb = f(a) \in B satisfies g(b)=cg(b) = c. So gg is surjective. ff need not be: let A={1}A = \{1\}, B={1,2}B = \{1, 2\}, C={1}C = \{1\}, f(1)=1f(1) = 1 and g(1)=g(2)=1g(1) = g(2) = 1. Then g∘fg \circ f is onto CC, but ff misses 22.

      prove

      Prove that if f:A→Bf: A \to B is injective and AA is infinite, then f(A)f(A) is infinite. Separately, show: if AA is uncountable and A⊆BA \subseteq B, then BB is uncountable.

      Solution

      Suppose f(A)f(A) were finite with a bijection h:{1,…,n}→f(A)h: \{1, \dots, n\} \to f(A). Since f:A→f(A)f: A \to f(A) is a bijection (injective and onto its range), h−1∘f:A→{1,…,n}h^{-1} \circ f: A \to \{1, \dots, n\} is a bijection, so AA would be finite, a contradiction. For the second claim, suppose BB were countable. Then its subset AA would be countable (closure property 1), which contradicts AA being uncountable. So BB is uncountable. This is the step used to pass from (0,1)(0,1) to R\mathbb R.

      proveAbbott 1.5

      Prove that the set of all finite subsets of N\mathbb N is countable.

      Solution

      Let F\mathcal F be the family of finite subsets of N\mathbb N. Define φ:F→N\varphi: \mathcal F \to \mathbb N by φ(S)=1+∑k∈S2k\varphi(S) = 1 + \sum_{k \in S} 2^{k} (the empty sum is 00, so φ(∅)=1\varphi(\varnothing) = 1). The number ∑k∈S2k\sum_{k \in S} 2^k has binary digits equal to 11 exactly at the positions in SS. Binary expansions of whole numbers are unique, so different sets SS give different numbers, and φ\varphi is injective. By the theorem on three ways ((b) implies (a)), F\mathcal F is countable.

      prove

      In Cantor’s argument, a student changes the rule to “let en=1e_n = 1 if dnn≠1d_{nn} \ne 1 and en=2e_n = 2 if dnn=1d_{nn} = 1”. Is the proof still correct? What if the rule is “let en=0e_n = 0 if dnn≠0d_{nn} \ne 0, and en=1e_n = 1 if dnn=0d_{nn} = 0”?

      Solution

      The first rule works, for the same reason as 4,54, 5: the digits of yy are 11 and 22, never 00 or 99, so yy has a unique expansion and differs from each xnx_n in digit nn. The second rule can fail. It uses the digit 00, which is dangerous: for instance y=0.1000…y = 0.1000\dots equals 0.0999…0.0999\dots as a number, so yy could be a listed number xnx_n whose chosen expansion is 0.0999…0.0999\dots, and then comparing digits would not show y≠xny \ne x_n. If every diagonal digit is nonzero, the rule even gives y=0.000⋯=0y = 0.000\dots = 0, which is not in (0,1)(0, 1). That is why we avoid 00 and 99.

      stretchCantor 1891

      Prove Cantor’s theorem: for every set AA there is no surjection f:A→P(A)f: A \to \mathcal P(A), where P(A)\mathcal P(A) is the set of all subsets of AA. Deduce that P(N)\mathcal P(\mathbb N) is uncountable.

      Solution

      Suppose f:A→P(A)f: A \to \mathcal P(A) is onto. Let D={a∈A:a∉f(a)}D = \{a \in A : a \notin f(a)\}. Then D⊆AD \subseteq A so D∈P(A)D \in \mathcal P(A), so D=f(a0)D = f(a_0) for some a0∈Aa_0 \in A. Is a0∈Da_0 \in D? By the definition of DD, a0∈Da_0 \in D iff a0∉f(a0)=Da_0 \notin f(a_0) = D. This says a0∈Da_0 \in D iff a0∉Da_0 \notin D, a contradiction. So no surjection exists. (This is the diagonal argument: the set DD disagrees with f(a)f(a) about the element aa.) If P(N)\mathcal P(\mathbb N) were countable, then since it is non-empty there would be a surjection N→P(N)\mathbb N \to \mathcal P(\mathbb N) by part (c) of the theorem on three ways, which was just ruled out. So P(N)\mathcal P(\mathbb N) is uncountable. Applying the theorem again and again gives infinitely many different sizes of infinity.

      stretch

      Explain why the set of all real numbers that you can define in English with a sentence of at most 1000 characters is countable (in fact finite), and why that does not contradict R\mathbb R being uncountable. What does it say about almost every real number?

      Solution

      A sentence of at most 1000 characters from an alphabet of, say, NN symbols is one of at most N+N2+⋯+N1000N + N^2 + \dots + N^{1000} strings, a finite number. Each defines at most one real number, so at most finitely many reals are definable this way. Allowing sentences of any finite length, the set of all finite strings is countable (list by length, then by dictionary order inside each length, which is a finite list), so at most countably many reals are definable. There is no contradiction: R\mathbb R is uncountable, so the definable reals form a tiny part of it, and almost every real number has no finite description at all.

      Summary

      • A set is described by its elements; proofs about sets go through “let xx be arbitrary” and the definitions. A=BA = B is shown by double inclusion.
      • Membership in A∪BA \cup B, A∩BA \cap B, AcA^c is a logical sentence, so the rules for ‘not in’ are the negation rules of 0.1: not-in-an-intersection is “missing from one”, not-in-a-union is “missing from both”.
      • De Morgan for sets is not a given fact: it is proved by a chain of if-and-only-ifs from the definitions.
      • A function gives each input exactly one output. Injective means different inputs give different outputs, surjective means every target is hit, and bijective means both, which is exactly “has an inverse”.
      • Two sets have the same size if a bijection joins them. A listing of a set is a bijection from N\mathbb N; to prove one you show that it lands in the set, hits every element, and repeats none. An injection into N\mathbb N, or a surjection from it, is enough.
      • Z\mathbb Z, N×N\mathbb N \times \mathbb N and Q\mathbb Q are all countable. The rationals are listed by walking the grid of fractions diagonally and skipping repeats.
      • Cantor’s diagonal argument shows (0,1)(0, 1), and so R\mathbb R, is uncountable: given any list, change the nnth digit of the nnth number and get a number that is not on it.
      • Consequence: only countably many reals can ever be named or computed, so most reals cannot. This is the seed for completeness in chapter 1.1.

      Watch and read

      The same ideas explained by someone else. Use these when an explanation here does not land.

      Where this sits

      Comes from
      0.1 How to read a theorem
      0.2 Proof techniques
      Leads to
      0.4 Equivalence relations and partitions
      0.5 Integers mod n, gcd and Bézout
      1.1 The real numbers and completeness
      2.1 Vector spaces and subspaces
      Same idea elsewhere
      CS 240: Sets, set-builder notation, functions, and countable sets come from CS 240. This chapter adds what CS 240 postponed: proofs about sets from the definitions, one-to-one and onto, and a full proof that the real numbers are uncountable.
      MATH 431: An event is a set, and the rules for 'not in' are exactly how you compute with complements. The probability axioms ask for additivity over countably many disjoint events, so 'countable' is part of the definition of probability.
      MATH 521: Sequences are functions from the counting numbers, and the construction of the real numbers (chapter 1.1) is what separates the countable rationals from the uncountable reals.
      MATH 541: Homomorphisms are functions, and 'injective' and 'surjective' become 'trivial kernel' and 'onto'. Bijections that respect structure are called isomorphisms.