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.
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,…,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,…,n}.
If this is the case, we say X is finite.
Claim: if A and B are disjoint (that is, if A∩B=∅) then |A|+|B|=|A∪B|.
Proof: Suppose |A|=i and |B|=j. Then there exists bijections fA:{1,…,i}→A and fB:{1,…,j}→B. We can define a bijection f:{1,…,i+j}→A∪B as follows: on input n, if 1≤n≤i then let f(n)::=fA(n), and if i+1≤n≤i+j then let f(n)::=fB(n−i).
We can easily check that f is a bijection:
it is a function because every n is either ≤i or ≥i+1, and not both.
it is injective; if f(n1)=f(n2) then either f(n1)∈A, in which case both n1 and n2 are between 1 and i, and we have fA(n1)=f(n1)=f(n2)=fA(n2). This implies that n1=n2 since fA is injective. Similarly, if f(n1)∈B, we use the injectivity of fB.
it is also surjective; given y∈A∪B, either y∈A or y∈B. if y∈A, then (since fA is surjective), there exists an n between 1 and i with fA(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∈B, then there exists some n∈{1,…,j} with fB(n)=y. But then f(i+n)=fB(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∪B|=|A|+|B|−|A∩B|.
Note: several students pointed out that we are am using the fact that A∪B=(A∖B)∪(A∩B)∪(B∖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∩B and A∖B are disjoint, we could do a proof by contradiction. Assume that there is some x in A∩B and A∖B. By the definition of ∩, this means x∈B, but by the definition of ∖, we see that x∉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∖B|=i, |A∩B|=j and |B∖A|=k.
Clearly (see note above) A=(A∖B)∪(A∩B). Note these are disjoint sets, so by above, |A|=i+j. Similarly, |B|=j+k. Moreover, A∪B=(A∖B)∪(A∩B)∪(B∖A) so |A∪B|=i+j+k=(i+j)+(j+k)−j=|A|+|B|−|A∩B| as required.