Reading

TO APPEAR

Warning!

This page has a lot more in it than we will cover in one lesson. It's just helpful to have all of this basic set theory stuff in one place. We'll do some material on the day of this lesson, and hit the rest of it in bits and pieces.

What is a set

Sets are the data structures of mathematics. They give us a formal language for math that's like a programming language, but much more flexible, while still being precise. They are tremendously useful for computer scientists and the kinds of mathematics they need.
A set is a collection of objects (called elements) with two key properties: the elements are unordered within the set, and there are no duplicates. A set is often defined by listing its elements, comma-delimited, with $\{\ \}$s.
So, for example, sets $\{2,\text{rat},3/5\}$ and $\{\text{rat},3/5,2\}$ are the same, since the order of elements is not meaningful. Similarly, sets $\{\text{blue},22\}$ $\{\text{blue},22,\text{blue}\}$ are the same, since the duplicate "$\text{blue}$" element is ignored.

Important! Mathematical objects have "type", just like objects in programs, and a set is a type. So, 4 and $\{4\}$ are different! The first is the number four, and the second is the set whose only element is the number four. So "$4$" is a number and "$\{4\}$" is a set. They have different type and therefore cannot be the same. By the same reason, $\{4\}$ and $\{\{4\}\}$ are not the same. Also by the same reason, $0$ and $\emptyset$ and "" are all different, because the first is a number, the second is a set, and the third is a string.

Set basics

ACTIVITY - Set stuff

Break up into groups of three
  1. Let $A = \{x1, x3, x5, \ldots\}$. Give an element of $A$ other than $x1$, $x3$, and $x5$.
  2. Let $B = \{\{0\},\{1\},\{2\}\}$. True or false, the elements of $B$ are numbers.
  3. Let $C = \{\{\},\{a\},\{\{b\}\},\{c\}\}$. Explicitly list the elements of the set $\{x|\mbox{ there is a $y \in C$ such that $x \in y$}\}$.
  4. Let $U = \{\ a,\ \{a\},\ \{\ \}\ \}$. Write out all the subsets of $U$. Hint: there are eight subsets. Why? $|U|=3$ and for each of the three elements you have two choices: put the element in the subset, or leave it out. This gives $2\cdot 2\cdot 2 = 8$ possible outcomes.
  5. Let $W$ be a set. Is it possible for some $X$ to be both an element of $W$ and a subset of $W$? I.e. is it possible for $X\in W$ and $X \subseteq W$ to both be true?
  6. Let $A = \{1,2,3\}$. Write out the elements of $A\times A$.
  7. Let $A = \{1,2,3\}$. Write out the elements of $\{(u,v) \in A \times A\ \big|\ u + v = 4\ \}$.
  8. Write out the elements of $\{x \in \mathbb{R}\ \big|\ x^2 + x - 1 = 0 \}$
  9. Write out the elements of $\{ x \in \{0,1,\ldots,40\}\ \big|\ \exists y \in \mathbb{N} [\ y^2 = x\ ] \}$
  10. If $\Sigma$ is an alphabet, we denote the set of all strings over $\Sigma$ as $\Sigma^*$. Given alphabet $\Sigma$, give a short english description of the set $\{w\in\Sigma^*\ \big|\ w = w^R\}$.
  11. Let $D_i$ be the set of $i$-digit decimal natural numbers. Give a definition of the set of all social security numbers in terms of the $D_i$'s. Note: A SS& like 123-45-6789 should be represented as $(123,45,6789)$.
  12. Let $A$ be a finte subset of $\mathbb{R}$. Give an expression for the average of the elements of $A$.
  13. Let $D_i$, where $i \in \mathbb{N}$ be defined as: $$ D_i = \{x \in \mathbb{N}\ \big|\ i = xy \mbox{ for some $y \in \mathbb{N}$} \} $$ Give a (short!) english language description of the set: $$P = \{i \in \mathbb{N}\ \big|\ |D_i| = 2\}$$ (Hint: Start by asking questions like this: Is 12 in $P$? Is 13 in $P$?) Note: This definition of the set $P$ is a lot like a computer program. I define a ``subroutine'' called ``$D_i$'' and use it in my ``main program'', which is the definition of $P$.

Functions!

Functions are hugely important in mathematics and computer science. You know them from math classes, you know them from programming, and you know them from first-order logic. So what are functions from the perspective of set theory? Informally, a function maps an input, which is an element of the function's domain, to an output, which is an element of the function's codomain. The rules are:
  1. for any input $x$ in the domain, the function must produce an output $y$ from the the codmain, and
  2. every time the function is applied to input $x$ it must produce the same output $y$.
Let $A$ and $B$ be sets, and let $f \subseteq A \times B$. $f$ is a function from domain $A$ to codomain $B$ if
  1. $\forall x \in A\left[ \exists y \in B [ (x,y) \in f ]\right]$, and
  2. $\forall x, y, y'[ (x,y)\in f \wedge (x,y') \in f \Longrightarrow y = y' ]$.
For notation, we write $f:A\rightarrow B$ to indicate that $f$ is a function from $A$ to $B$ (this called the function's signature), and we write $f(x) = y$ to indicate that $(x,y) \in f$. [Note that the order of $x$ and $y$ matters!]

Examples:

  1. $f_1 := \{ (0,b),(1,c),(2,b),(3,a) \}$ is a function, with $f_1:\{0,1,2,3\} \rightarrow \{a,b,c\}$.
  2. $f_2 := \{ (0,b),(1,c),(1,b),(2,a) \}$ is not a function, since "$(1,c)$" and "$(1,b)$" violate point (2) of the definition, because there are multiple outputs for the same input.
  3. If $f_3 := \{ (0,b),(1,c),(3,a) \}$, it is not the case that $f_3:\{0,1,2,3\} \rightarrow \{a,b,c\}$, because there is no output for $f_3(2)$, which violates point (1) of the definition.
  4. If $f_4 := \{ (0,b),(1,a),(2,b),(3,a) \}$, it is correct to say $f_4:\{0,1,2,3\} \rightarrow \{a,b,c\}$ even though $c$ is never an output value, because it is not required that every element of the codomain is the output of some input.
    Note: the range of a function is the set of all output values that actually appear.

Ways we define particular functions

We see from the definition that we can always define a particular function by describing the set of input/output pairs. That's good to keep in mind, and in many cases that's what we do. There are two other common ways for us to define particular functions:

ACTIVITY

  1. Given the definition below, what are the values of: $q(2.3,true)$, $q(-2.3,true)$, $q(2.3,false)$, $q(-2.3,false)$? $$ \begin{array}{l} q:\mathbb{R}\times \{true,false\}\rightarrow \mathbb{Z}\\ q(x,b) = \left\{ \begin{array}{cl} \lfloor x \rfloor & \text{ if } x \geq 0 \wedge \neg b \vee x \lt 0 \wedge b\\ \lceil x \rceil & \text{ otherwise} \end{array} \right. \end{array} $$
  2. Give a formal definition of the function mid that takes two real numbers and returns the midpoint between them.
  3. Give a formal definition of the function dist that takes two real numbers and returns the distance between them. Note: find a way to do it without using the absolute value function!
  4. Let $A = \{ \text{rock}, \text{paper}, \text{scissors} \}$. Use a table to define the $beats(\cdot,\cdot)$ function, which returns true if and only if the first argument beats the second in rock/paper/scissors. For example, $beats(\text{paper},\text{scissors})=\text{false}$ because paper does not beat scissors.
  5. Consider the function $m$ defined below. $m(3) = $_____________________________________ $$ \begin{array}{l} m:\mathbb{N}\rightarrow2^{\mathbb{N}}\\ m(k) = \{ i\cdot k\ \big|\ i \in \mathbb{N} \} \end{array} $$

Relations

A relation is a special kind of function that shows up in a lot of places.
Given set $A$, function $r$ with signature $r:A\times A \rightarrow \{true,false\}$ is called a relation on $A$ (more specifically, a binary relation).
Important! It is common to define a relation as a subset of $A\times A$, namely $\{(x,y)\in A\times A\ \big|\ r(x,y) = true\}$.

Relations are often written with infix operators. For example, $\lt$ is the "less than relation". We write "$x \lt y$" and we get "true" if x is less than y, and false otherwise. You are used to relations like <, ≥, =, etc. Perhaps you saw $\perp$, the "perpendicular" relation in geometry? If $L_1$ and $L_2$ are lines, "$L_1 \perp L_2$" is true if $L_1$ and $L_2$ are perpendicular, and false otherwise.

Let's define our own relation, The ${\small inv}$ relation on $\mathbb{Z_5}$, where $x\ {\small inv}\ y$ means that $x$ and $y$ are multiplicative inverses of one another in $\mathbb{Z_5}$. Then ${\small inv}$ is defined by $\{(1,1),(2,3),(3,2),(4,4)\}$.


Christopher W Brown