we'll start by finishing our discussion of well-defined functions; review the lecture 7 notes. I have updated those notes with the new material we covered.

- we'll start talking about combinatorics
reading: MCS 15.1–15.3

**Definition:** We say the **cardinality** (or **size**) of a set \(X\) is \(n\) (written \(|X| = n\)) if \(|X| = |\{1,2,\dots,n\}|\). Here we are using the definition of same-cardinality defined in lecture 5; that is, there must exists a bijection between \(X\) and \(\{1,2,3,\dots,n\}\).

If this is the case, we say \(X\) is **finite**.

**Claim:** if \(A\) and \(B\) are disjoint (that is, if \(A \cap B = \emptyset\)) then \(|A| + |B| = |A \cup B|\).

**Proof:** Suppose \(|A| = i\) and \(|B| = j\). Then there exists bijections \(f_A : \{1,\dots,i\} → A\) and \(f_B : \{1,\dots,j\} → B\). We can define a bijection \(f : \{1, \dots, i+j\} → A \cup B\) as follows: on input \(n\), if \(1 \leq n \leq i\) then let \(f(n) ::= f_A(n)\), and if \(i+1 \leq n \leq i+j\) then let \(f(n) ::= f_B(n-i)\).

We can easily check that \(f\) is a bijection:

it is a function because every \(n\) is either \(\leq i\) or \(\geq i+1\), and not both.

it is injective; if \(f(n_1) = f(n_2)\) then either \(f(n_1) \in A\), in which case both \(n_1\) and \(n_2\) are between \(1\) and \(i\), and we have \(f_A(n_1) = f(n_1) = f(n_2) = f_A(n_2)\). This implies that \(n_1 = n_2\) since \(f_A\) is injective. Similarly, if \(f(n_1) \in B\), we use the injectivity of \(f_B\).

it is also surjective; given \(y \in A \cup B\), either \(y \in A\) or \(y \in B\). if \(y \in A\), then (since \(f_A\) is surjective), there exists an \(n\) between \(1\) and \(i\) with \(f_A(n) = y\). But then \(f(n) = y\) by definition, so in this case there exists an \(n\) with \(f(n) = y\). On the other hand, if \(y \in B\), then there exists some \(n \in \{1,\dots,j\}\) with \(f_B(n) = y\). But then \(f(i+n) = f_B(n) = y\), so again, \(y\) is in the image of \(f\). Since \(y\) is in the image in either case, we see that \(f\) is surjective.

**Claim:** in general, \(|A \cup B| = |A| + |B| - |A \cap B|\).

**Note:** several students pointed out that we are am using the fact that \(A \cup B = (A \setminus B) \cup (A \cap B) \cup (B \setminus A)\), and also that these three sets are disjoint. I did not prove these facts, but they are certainly provable, using the definitions of intersection, union, and difference. For example, to show that \(A \cap B\) and \(A \setminus B\) are disjoint, we could do a proof by contradiction. Assume that there is some \(x\) in \(A \cap B\) and \(A \setminus B\). By the definition of \(\cap\), this means \(x \in B\), but by the definition of \(\setminus\), we see that \(x \notin B\). This is a contradiction.

**Proof:** We could construct a bijection as we did above, but it's easier to reuse what we've already proven. Let \(|A \setminus B| = i\), \(|A \cap B| = j\) and \(|B \setminus A| = k\).

Clearly (see note above) \(A = (A \setminus B) \cup (A \cap B)\). Note these are disjoint sets, so by above, \(|A| = i + j\). Similarly, \(|B| = j + k\). Moreover, \(A \cup B = (A \setminus B) \cup (A \cap B) \cup (B \setminus A)\) so \(|A \cup B| = i + j + k = (i + j) + (j + k) - j = |A| + |B| - |A \cap B|\) as required.