Here are the details of the proof we gave today that if \(|A| \leq |B|\) and if \(|B| \leq |A|\) that \(|A| = |B|\). This is called the Cantor-Schröder-Bernstein Theorem.

See Wikipedia for another writeup.

First a reminder of some relevant definitions:

A function \(f : A \rightarrow B\) is one-to-one if for all \(x_1\) and \(x_2 \in A\), \(f(x_1) \neq f(x_2)\) unless \(x_1 = x_2\). We will use the contrapositive definition:

\(f\) is

**one-to-one**if, for all \(x_1\) and \(x_2\), if \(f(x_1) = f(x_2)\) then \(x_1 = x_2\).A function \(f\) is

**onto**if, for every \(y\) in the codomain, there is some \(x\) in the domain with \(f(x) = y\).**\(|A| \leq |B|\)**if there exists a function \(f : A \rightarrow B\) that is one-to-one.**\(|A| = |B|\)**if there exists a function \(f : A \rightarrow B\) that is both one-to-one and onto.

We will do a direct proof. Assume that \(|A| \leq |B|\) and \(|B| \leq |A|\). By definition, this means that there exists functions \(f : A → B\) and \(g : B → A\) that are both one-to-one.

Our goal is to piece these together to form a function \(h : A → B\) which is both one-to-one *and* onto.

To build the function \(h\), we need to give its output on every input. To define it, we need to consider *chains* of elements that are formed by repeatedly applying \(f\) and \(g\).

The chain of an element \(x \in A\) contains \(x\), \(f(x)\), \(g(f(x))\), \(f(g(f(x)))\), \(g(f(g(f(x))))\) and so on. It also contains any elements that can be reached by going *backwards* along the chain. That is, if there happens to be some \(y\) such that \(g(y) = x\), then \(y\) is in the chain.

There need not be such a \(y\) because \(g\) is not onto. However, if there is a \(y\), it must be unique, because \(g\) is one-to-one. If such a \(y\) exists, we will call it \(g^{-1}(y)\). This discussion shows that \(g^{-1}\) is a partial function.

Similarly, the chain of \(x\) will include \(f^{-1}(g^{-1}(x))\), \(g^{-1}(f^{-1}(g^{-1}(x)))\) and so on.

We want to distinguish between various types of chains, based on what happens as you walk backwards along them (that is, if we consider \(x\), \(g^{-1}(x)\), \(f^{-1}(g^{-1}(x))\), ... as defined above). There are 4 types:

- The chain forms a loop
- Chains that go "backwards" forever without repeating.
- Chains that stop in \(A\). That is, they end on some \(x\) with \(g^{-1}(x)\) undefined.
- Chains that stop in \(B\).

Note that every element of both \(A\) and \(B\) is part of exactly one chain.

We define \(h\) as follows. If \(x\) is in a chain of type 1, 2, or 3, then we define \(h(x) = f(x)\). If \(x\) is in a chain of type 4, then we define \(h(x) = g^{-1}(x)\). \(g^{-1}(x)\) is defined, because if it wasn't, then \(x\) would be in a chain of type 3.

What's left is to show that \(h\) is one-to-one and onto.

We must show that whenever \(h(x_1) = h(x_2)\), that \(x_1 = x_2\). We will prove this directly: assume that \(h(x_1) = h(x_2)\). Notice that \(h(x)\) is always part of the same chain as \(x\). Therefore, \(x_1\) and \(x_2\) must be in the same chain.

Let's consider the possible types of chains:

If the chain of \(x_1\) and \(x_2\) is of type 1, 2, or 3, then \(h(x_1) = f(x_1)\) and \(h(x_2) = f(x_2)\). Therefore, \[f(x_1) = h(x_1) = h(x_2) = f(x_2)\] Since \(f\) is one-to-one, this implies that \(x_1 = x_2\) as required.

If the chain is of type 4, then we have that \(h(x_1) = y_1\) with \(g(y_1) = x_1\), and \(h(x_2) = y_2\) with \(g(y_2) = x_2\). Since \(h(x_1) = h(x_2)\), we have \(y_1 = y_2\), so \[x_1 = g(y_1) = g(y_2) = x_2\] as required.

In any case, we have shown that \(x_1 = x_2\), so we conclude that \(h\) is one-to-one.

Given an arbitrary \(y \in B\), we must find some \(x \in A\) with \(h(x) = y\). We consider the chain containing \(y\).

If that chain is of type 1, 2, or 3, then we know there is some \(x\) such that \(f(x) = y\). Since \(x\) and \(y\) are in the same chain, we have that \(x\)'s chain is of type 1, 2 or 3, so \(h(x) = f(x) = y\).

If the chain is of type 4, then we know that \(g(y)\) is also in a chain of type 4. That means that \(h(g(y)) = y\). Therefore there is some \(x\) (namely \(g(y)\)) that maps to \(y\).

In either case, we have found an element that maps to \(y\), so \(h\) is onto.

We have defined a function \(h : A → B\) and shown that it is both one-to-one and onto. Therefore (by definition) \(|A| = |B|\).