In this lecture we turn to the next major section of CMSC 27100: Combinatorics and Probability. Probability is an everyday term, but combinatorics is perhaps less common. For the purpose of this class, it is a fancy word for "counting." Over the next two lectures, we'll come up with methods for counting the number of possible outcomes of an event, which will then enable us to compute the probability of certain outcomes. Probability has become an essential part of a computer scientist's toolbox. Whether studying data structures, cryptography, machine learning, or any number of other subareas of CS, probability is a foundational tool.
This lecture gives some more definitions from set theory and then covers the basics of relations and functions. This provides some examples of the modern mathematical idea that everything can be viewed as a set. Everything. Functions? Sets. Numbers? Sets. Problems? Sets. Sets? Sets. Redefining common objects within set theory might feel like a bit of game (akin to reimplementing programs in an esoteric programming language), but historically and practically it's an important and powerful idea that eliminates (essentially) all ambiguity in mathematical theorems.
We've already used sets a lot, but let's recall the definition here.
A set is an unordered collection of objects. If $S$ is a set and $a$ is a member of $S$, then we write $a \in S$. If $a$ is not a member of $S$, then we write $a \not \in S$.
Reminder that we originally introduced sets in Lecture 2, if you'd like a refresher. Sets are determined by nothing more than what they contain. That is, there are not two distinct sets that contain only the number $2$; They are both $\{2\}$. The next definition states this more formally.
Two sets $A$ and $B$ are equal if and only if they have the same elements. That is, $$A = B \iff (\forall x, x \in A \iff x \in B).$$
In particular, there is a unique set containing nothing:
The set $\{\}$ containing no elements is the empty set and is denoted by $\emptyset = \{\}$.
We will need the following notion of a subset, which describes when one set's elements are entirely contained in another set.
A set $S$ is a subset of $T$, written $S \subseteq T$, when every element of $S$ belongs to $T$. A set $S$ is a proper subset of a set $T$, written $S \subsetneq T$, when $S$ is a subset of $T$ and there exists an element of $T$ which does not belong to $S$.
Revisiting our conditional connective, $\to$, it's worth pointing out how it relates to subsets: $$S \subseteq T \Leftrightarrow (x \in S \to x \in T).$$
You may notice that sometimes $\subset$ is used for proper subset. This works quite nicely with $\subseteq$ meaning subset. However, we'll avoid this particular notation because there are many other mathematicians who use $\subset$ to mean (not necessarily a proper) subset. Instead, we will use $\subseteq$ and $\subsetneq$ to keep things clear.
From the above, we note that by definition, we have $S \subseteq S$ and if $S = T$, we have $S \subseteq T$ and $T \subseteq S$. This second definition gives us an alternate characterization of two sets that are equal.
The cardinality of a set $S$ is the number of elements in $S$ and is denoted $|S|$. If $S$ is finite, then this will be a natural number. So, the size of the set $\{1,2,4,8\}$ would be $|\{1,2,4,8\}| = 4$.
If $S$ is an infinite set, then things are a bit trickier. The cardinality of the natural numbers is defined to be $|\mathbb N| = \aleph_0$, while the cardinality of the real numbers is $|\mathbb R| = 2^{\aleph_0}$. Here, we reach into the Hebrew alphabet for $\aleph$ (aleph). Anyhow, the cardinalities of $\mathbb N$ and $\mathbb R$ are clearly not the same, a fact famously proved by Cantor in 1891. There are many infinite sets that have cardinality $\aleph_0$, such as the set of even natural numbers $\{n \mid \exists m \in \mathbb N, n = 2\cdot m\}$ or the set of rational numbers $\mathbb Q = \{\frac m n \mid \exists m,n \in \mathbb N\}$. There are also many sets with cardinality $2^{\aleph_0}$. This brings us to a famous problem call the Continuum Hypothesis: Are there any infinite sets that have cardinality strictly between $|\mathbb N| = \aleph_0$ and $|\mathbb R| = 2^{\aleph_0}$?
The power set of a set $A$ is the set containing all of the subsets of $A$, $$\mathcal P(A) = \{S \mid S \subseteq A\}.$$
If $A$ is a finite set, then $|\mathcal P(A)| = 2^{|A|}$.
We will prove this later, but you can do a proof by induction now if you like. Inspired by this fact, you'll sometimes see the power set of a set $A$ denoted by $2^A$. This might also give you some hint about how one could justify that $|\mathbb R| = 2^{\aleph_0}$.
The next definition defines ways for combining sets to form new sets.
The union of two sets $S$ and $T$, denoted $S \cup T$ is the set of all elements in $S$ or $T$: $$S \cup T = \{x \mid x \in S \vee x \in T\}.$$
The intersection of two sets $S$ and $T$, denoted $S \cap T$, is the set of all elements in $S$ and $T$: $$S \cap T = \{x \mid x \in S \wedge x \in T\}.$$
The set difference of two sets $S$ and $T$, denoted $S \setminus T$, is defined $$S \setminus T = \{x \mid x \in S \wedge x \not \in T\}.$$
The complement of a set $S$ (with respect to another set $U$, called the "universe"), written $\overline S$, is the set of all elements from $U$ not in $S$, that is, $$\overline S = \{x \in U \mid x \not \in S\}.$$
By definition, we get $\overline S = U \setminus S$. Set complements will be especially useful when we get to probability theory, where they will give us an intuitive way to rigorously model an event not happening.
The following definition is frequently useful.
We say two sets $S$ and $T$ are disjoint if $S \cap T = \emptyset$.
Set operations have a close intuitive and formal connection to logical connectives. Here's an example of an identity that has both a logical and set theory version.
For two sets $A$ and $B$, \begin{align} \overline{A \cup B} &= \overline A \cap \overline B, \text{and} \\ \overline{A \cap B} &= \overline A \cup \overline B. \end{align}
Let's prove the first statement and leave the second as an exercise. Recall from above that $A = B$ if and only if $A \subseteq B$ and $B \subseteq A$. Equivalently, $x \in A \Leftrightarrow x \in B$. Unpacking the definitions of $\cap$, $\cup$ and $\overline{S}$, we want to show that $$\neg (x \in A \vee x \in B) \Leftrightarrow \neg (x \in A) \wedge \neg (x \in B)$$
Note that this is exactly De Morgan's law for logic, where $x \in A$ is $P$ and $x \in B$ is $Q$.
\begin{align*} \overline{A \cup B} &= \{x \mid x \notin A \cup B\} &\text{definition of complement} \\ &= \{x \mid \neg(x \in A \cup B)\} &\text{definition of set membership} \\ &= \{x \mid \neg(x \in A \vee x \in B)\} &\text{definition of union} \\ &= \{x \mid \neg(x \in A) \wedge \neg(x \in B)\} &\text{De Morgan's laws} \\ &= \{x \mid x \not\in A \wedge x \not\in B\} &\text{definition of set membership} \\ &= \{x \mid x \in \overline A \wedge x \in \overline B\} &\text{definition of complement} \\ &= \{x \mid x \in \overline A \cap \overline B\} &\text{definition of intersection} \\ &= \overline A \cap \overline B &\text{set definition} \\ \end{align*} $$\tag*{$\Box$}$$We sometimes need a notion of an ordered collection (rather than an unordered collection, which is just a set).
An $n$-tuple $(a_1, a_2, \dots, a_n)$ is an ordered collection that has $a_1$ as its first element, $a_2$ as its second element, $\dots$, and $a_n$ as its $n$th element. An ordered pair is a 2-tuple.
Observe that since tuples are ordered, we have $(a_1, \dots, a_n) = (b_1, \dots, b_n)$ if and only if $a_i = b_i$ for $i = 1, \dots, n$.
The Cartesian product of two sets $A$ and $B$ is $$A \times B = \{(a,b) \mid a \in A, b \in B\}.$$
We generalize this to products of $n$ sets.
The Cartesian product of $n$ sets $A_1, A_2, \dots, A_n$, denoted $A_1 \times A_2 \times \cdots \times A_n$ is defined $$A_1 \times A_2 \times \cdots \times A_n = \{(a_1, a_2, \dots, a_n) \mid a_i \in A_i, i = 1, 2, \dots, n\}.$$
For any set $A$, we will sometimes write $A^2$ for $A\times A$. More generally, for any $n\in \mathbb{N}$, we will write $A^n$ for the Cartesian product of $A$ with itself $n$ times.