% This is stuff that I need for reference, but won't make it into the final
% text. Hence, it's all commented out.
% 
% -- Peter Harpending
% 
% \s{Numeric sets}

% Now, I'm going to throw more stuff at you. I'm sorry for all the notation, but
% it is important that you get used to it. There are a bunch of common sets you'll
% encounter in the real world.

% % Again, a list is easier
% \begin{enumerate}
% \item First of all, there are the integers: these are just the whole numbers,
%   like $-3, -2, -1, 0, 1, 2$.  Traditionally, this set is denoted $\mathbb{Z}$.

% \item The natural numbers, denoted $\mathbb{N}$, are all non-negative
%   integers\footnote{Conventions differ as to what the natural numbers are.
%     Everyone agrees that positive whole numbers (1, 2, 3\ldots) are natural.
%     Some people say $0$ is also a natural numbers, while others disagree.  In
%     this book, 0 {\it is} a natural number, so the natural numbers are 0, 1, 2,
%     and so on. This might seem like a stupid fight, why can't we just choose a
%     side? However, it actually turns out to be really important.}.

% \item The set of ``rational'' numbers, denoted $\mathbb{Q}$ is the set of all
%   numbers that can be written as a quotient (or fraction) $\frac{p}{q}$, where
%   $p$ and $q$ are integers.

%   In mathematical notation, you would write this as
%   $\left\{ \frac{p}{q} \mid p,\,q \in \mathbb{Z} \right\}$.  You should read
%   that as ``the set of all numbers $p$ over $q$, such that $p$ and $q$ are
%   elements of $\Z$.''

% \item Finally, the real numbers, denoted $\mathbb{R}$, contain everything on the
%   number line.  Equivalently, a real number is just any number you can write
%   down by writing down an integer, a decimal point, and then writing any
%   sequence of digits after the decimal point (even an infinite sequence).

%   Let us show you an example. Let's write down an integer. $2$. There we
%   go. Now, let's just write down a bunch of digits all in a row. $215455211$. By
%   the definition in the previous paragraph, $2.215455211$ is a real number. You
%   should get in the habit of writing ``$2.215455211$ is a real number'' as
%   $2.215455211 \in \R$.
% \end{enumerate}

% Sets certainly look simple enough to understand intuitively, but are they also
% interesting enough to be worth studying?  The answer to that is a resounding
% `yes.' Exciting, right?

% To give you a taste of the results, let's take a look at some of them.

% Intuitively, sets can be of different sizes: it's clear that the empty set is
% the smallest possible set, and that $\{2, 4\}$ is smaller than $\{1, 2, 3\}$.
% When we get to infinite sets, however, the intuition fails.

% Cantor formalised this intuition, and the formal version also worked for
% infinite sets.  The results he got were very surprising: for example, he found
% that there are as many natural numbers as rational numbers, but that there are
% strictly more real numbers.  Even worse, he proved that given any set, there is
% always a set larger than it.  If you've ever heard of people talking about
% ``different kinds of infinity'', this is probably what they meant.

% \sss{Exercises}

% \begin{enumerate}
%   \item Suppose $x$ is some object and $S$ is a set.  Does it make sense to ask
%     ``How many times does $S$ contain $x$?''
%   \item Earlier, we constructed the set $\{3, 5\}$.  We can also construct the
%     set $\{5, 3\}$.  Are these the same set?
%   \item Are the following true or false?
%     \begin{itemize}
%       \item $\emptyset \in \emptyset$
%       \item $\emptyset \in \{\emptyset\}$
%       \item $\emptyset = \{\emptyset\}$
%       \item $\{\emptyset\} \in \{\emptyset\}$
%     \end{itemize}
% \end{enumerate}

% \s{Functions}

% % So, we're sort of faced with a problem.

% % I'm going to try to explain functions in Layman's terms

% % \xti{Function} is like \xti{set}, in that it's a semi-common term, which us math
% % people use in a slightly different way. You can think of a ``function'' like a
% % magic box. You put some value into the function, and then a different value
% % comes out. Moreover, if you input the same thing multiple times, you get the
% % same output. This has the consequence that, for every input, there is at most 1
% % output value. That is, you can't have a function t

% % \ss{More formally}

% A function from a set $X$ to a set $Y$ specifies for every element of $X$ a
% corresponding element of $Y$.  In other words, if $f$ is a function from $X$ to
% $Y$ (denoted $f : X \to Y$) and $x \in X$, then $f(x) \in Y$.  A lot of high
% school mathematics is about functions from $\mathbb{R}$ to $\mathbb{R}$, even if
% they are never presented that way.  For example, solving linear equations is
% actually a question about functions: ``given a function
% $f : \mathbb{R} \to \mathbb{R}$ defined by

% \[
%   f(x) = 5x - 10
% \]

% find all $r \in \mathbb{R}$ such that $f(r) = 0$.''

% It turns out that by taking sets $X$ and $Y$ and asking what kind of functions
% exist between them, we can find out a lot about $X$ and $Y$ themselves.  We'll
% continue this line of thought after some exercises.

% \newpage

% \sss{Exercises}

% \begin{enumerate}
%   \item We can construct the set $\{0, 1\}$.  What functions can you find from
%     $\{0, 1\}$ to $\{0, 1\}$?  How many such functions are there?
%   \item Can you find a function from $\emptyset$ to $\{0, 1\}$?  What about in
%     the other direction?
%   \item Suppose $X$ is a set.  Prove that there exists at least one function
%     from $X$ to $X$.  How can this function be defined?  Why does this work if
%     $X$ is the empty set?
%   \item Suppose $X$, $Y$, and $Z$ are sets, and you are given functions $f : X
%   \to Y$ and $g : Y \to Z$.  Can you make a function from $X$ to $Z$?  How?
%   \item Suppose $X$ and $Y$ are sets, $f : X \to Y$, and $x, y \in X$.  Do you
%     think $x = y$ implies $f(x) = f(y)$?  Why, or why not?
% \end{enumerate}

% \newpage

% \sss{Solutions}

% % Left as an exercise...

% \newpage

% \s{Injective Functions}

% In the exercises, you saw that if $f : X \to Y$ and you had $x, y \in X$ such
% that $x = y$, then necessarily $f(x) = f(y)$.  A function $f$ is said to be
% injective if the converse is also true: if $x, y \in X$ and $x \neq y$, then
% $f(x) \neq f(y)$.

% Let's consider some examples.  Let $f : \mathbb{N} \to \mathbb{Z}$ be defined by
% $f(x) = x$.  Is this definition correct?  Well, we need to check that for any $n
% \in \mathbb{N}$, we have $f(n) \in \mathbb{Z}$.  But by definition, $f(n) = n$,
% so we need to check that if $n \in \mathbb{N}$, then also $n \in \mathbb{Z}$.
% Every non-negative integer is certainly an integer, so yes, the definition is
% correct.

% Now, is this function injective?  For that, let $n, k \in \mathbb{N}$ so that
% $f(n) = f(k)$.  We need to prove that $n = k$.  Again, this is easy: $f(n) = n$
% and $f(k) = k$, so by putting the three equalities together, we have $n = k$.

% We can construct the set $\{f(0), f(1), f(2)\ldots\}$.  If we want to be
% precise, we can use the {\it set comprehension} notation:

% \[
%   \{ f(x) \, | \, x \in \mathbb{N} \}
% \]

% You should read this as ``the set that contains $f(x)$ for each $x \in
% \mathbb{N}.$''  That's rather a mouthful, so we'll abbreviate this by
% $f(\mathbb{N})$.  Just imagine that instead of applying $f$ to one value in
% $\mathbb{N}$, you're applying it to all the values and looking at the results as
% a set.

% We can now ask ourselves: how big is $f(\mathbb{N})$?  In this case, we can see
% that $\mathbb{N} = f(\mathbb{N})$, so of course they're exactly the same size.
% However, what if instead of the $f$ we chose, we had chosen $f(x) = -x$, or $g :
% \mathbb{N} \to \mathbb{Q}$ defined by $g(x) = \frac{1}{1+x}$?  Prove that both
% of these are injective functions, and imagine $f(\mathbb{N})$ and
% $g(\mathbb{N})$.  How big are these sets?

% It should be clear that given any sets $X$ and $Y$ and any function $f : X \to
% Y$, $f(X)$ cannot possibly be bigger than $X$.  For every element $y \in f(X)$,
% there is some element $x \in X$ so that $f(x) = y$; that's how we defined $f(X)$
% in the first place.

% % TODO: rewrite this to require less proof.
% On the other hand, if $f$ is injective, $f(X)$ also shouldn't be any smaller
% than $X$.  Why?  Well, we can just define a function the other way.  Let $g :
% f(X) \to X$, and define $g(f(x)) = x$.  Now we know that $g(f(X))$ is no larger
% than $f(X)$.  But $g(f(X)) = \{ g(f(x)) \, | \, x \in X \} = \{ x \, | \, x \in
% X \} = X$!  That means, by the argument above, that $f(X)$ is no larger than
% $X$, just as we wanted.

% The careful reader might notice that the definition of $g$ is fishy.  Does a
% function defined this way really work?  The answer is that it does, but only
% because we were careful about $f$.  We know that if we have an element $y \in
% f(X)$, then there is an element $x \in X$ so that $y = f(x)$.  This means that
% $g$ really is defined for all $y \in f(X)$.  That's not all, though.
% Additionally, suppose there was also a $z \in X$ so that $y = f(z)$.  Then $g(y)
% = g(f(x)) = x$, but also $g(y) = g(f(z)) = z$.  For $g$ to be a function, we
% need to prove that $x = z$.  Here is where we need the injectivity of $f$: we
% know that since $f(x) = y = f(z)$, that $f(x) = f(z)$, and thus $x = z$.
% Therefore, $g$ really is a function, and so our argument holds.

% Our intuition thus tells us that however we define size, we should make sure
% that for any set $X$ and any injective function $f : X \to Y$, we should have
% $X$ and $f(X)$ be of equal size.  As $f(X)$ is just a part of $Y$, this means
% that $X$ should also be no bigger than $Y$.  By themselves, all these loose bits
% of intuition might not seem very useful, but in the next section we'll use them
% to show that a certain approach to define size {\it doesn't} work.  First,
% however, some exercises.

% \sss{Exercises}

% \begin{enumerate}
%   \item In an older exercise, you saw there were four functions from $\{0, 1\}$
%     to itself.  How many injective functions are there?  What about between
%     $\{0, 1, 2\}$ and itself?  What if you have even more elements?
%   % Something about seeing an injective function as an embedding.
% \end{enumerate}

% \s{Subsets}

% When people first hear that there are as many integers as natural numbers, their
% reaction is often ``Surely that can't be right?  Every natural number is an
% integer, and there are some others, too!''

% To make this argument formal we should introduce the notion of a subset.  We say
% that $X$ is a subset of $Y$ if every element of $X$ is also an element of $Y$.
% We denote this by $X \subseteq Y$.  We have, then $\emptyset \subseteq \mathbb{N}
% \subseteq \mathbb{Z} \subseteq \mathbb{Q} \subseteq \mathbb{R}$.  We will use $X
% \subset Y$ when $X$ is a subset of $Y$, but $X$ and $Y$ are not equal.

% Now let's denote the size of $X$ by $|X|$.  Can we define this size in such a
% way that for finite sets, $|X|$ is the number of elements in $X$, that for any
% sets $X$ and $Y$ such that $X \subset Y$ we have $|X| < |Y|$, and that if there
% exists an injective function $f : X -> Y$ then $|X| = |f(X)|$?

% We've already given away that this isn't possible.  The question becomes, how do
% we prove it?  It isn't enough to just try a few definitions of `size' and see
% that they don't work, as there'll always be a few that we haven't yet attempted.
% We need a way of showing that whatever definition we come up with, we'll be able
% to show it doesn't work.

% To do that, we'll assume that we were given some definition of `size' that
% satisfies the above requirements, but with no other assumptions.  You can
% imagine it as being given the definition by a friend, and now you have to show
% why it's wrong.  If the definition allows us to derive something that isn't
% true then there's certainly something wrong with it, so that's what we'll try to
% do.

% Assume that for every set $X$, we defined $|X|$.  Define $f : \mathbb{Z} \to
% \mathbb{Z}$ by $f(x) = 2x$.  We required that $|\mathbb{Z}| = |f(\mathbb{Z})|$.
% But because $1 \not \in f(\mathbb{Z})$, $f(\mathbb{Z}) \subset \mathbb{Z}$.
% This implies $|f(\mathbb{Z})| < |\mathbb{Z}|$, and so we conclude $|\mathbb{Z}|
% = |f(\mathbb{Z})| < |\mathbb{Z}|$.  Surely, though, a set can't be smaller than
% itself, so we've just derived a falsehood, and the definition of `size' that we
% started with can't work.

% If this proof doesn't feel quite right to you, don't worry: we'll look at
% arguments like this in-depth in the next chapter.  For now, the main result is
% that we are too strict in how we want to define size.  We need to relax one of
% the requirements, and in the next section we'll see that if we remove the
% requirement that $X \subset Y$ implies $|X| < |Y|$, we can find a good
% definition.

% \sss{Exercises}

% In these exercises we'll explore some more operations for constructing sets.
% The three most important ones are {\it union}, {\it intersection}, and {\it
% difference}.

% The union of $X$ and $Y$ is written as $X \cup Y$ and contains every element of
% $X$ and every element of $Y$.  We can write this using set comprehension
% notation:
% \[
%   X \cup Y = \{ x \, | \, x \in X \text{ or } x \in Y \}
% \]

% \begin{enumerate}
%   \item Write out the following sets:
%     \begin{enumerate}
%       \item $\{0, 1\} \cup \{2, 3\}$
%       \item $\{0, 1\} \cup \{1, 2\}$
%       \item $\{0, 1\} \cup \{0, 1\}$
%       \item $\{0, 1\} \cup \emptyset$
%     \end{enumerate}
%   \item We say that a set $A$ is the identity of $\cup$ if for every set $X$ we
%     have $X \cup A = X = A \cup X$.  Does $\cup$ have an identity?
%   \item Suppose $X$ and $Y$ are sets.  Convince yourself that $X \cup Y = Y \cup
%     X$.  This property of $\cup$ is called {\it commutativity}.
%   \item Suppose $X$, $Y$, and $Z$ are sets.  Convince yourself that $(X \cup Y)
%     \cup Z = X \cup (Y \cup Z)$.  This property is called {\it associativity}.
% \end{enumerate}

% The intersection of $X$ and $Y$ is written as $X \cap Y$ and contains all
% elements that are both in $X$ and $Y$.

% \begin{enumerate}
%   \item Do the first exercise on unions again, but replace $\cup$ with $\cap$.
%   \item Let $X$ and $Y$ be sets.  Write $X \cap Y$ as a set comprehension.
%   \item Does $\cap$ have an identity?
%   \item Is $\cap$ commutative and associative, just like $\cup$ is?
% \end{enumerate}

% The difference between $X$ and $Y$ is written as $X-Y$ (or, sometimes, $X \ Y$)
% and contains all elements that are in $X$ but are not in $Y$.

% \begin{enumerate}
%   \item Do the first exercise on unions a third time, but now taking the
%     difference.
%   \item Does set difference have an identity?
%   \item Is set difference commutative?  What about associative?
% \end{enumerate}

% \s{Cardinalities}

% % Recall that injective functions allow us to conclude |X| <= |Y|.  Introduce
% % surjections and bijections and argue that if f : X -> Y bijective, then f
% % injective, thus |X| = |f(X)|, but also f(X) = Y, thus |X| = |Y|.  State,
% % without proof, the Cantor-Shroder-Bernstein theorem, and define properly what
% % |X| <= |Y| and |X| = |Y| mean.

% % Exercises: show |N| = |Z| = |Q+| (introduce products).  Show |Q+| = |Q|.

% \s{The Power Set}

% % Define the power set.  Prove that the power set of X is strictly greater than
% % X.

% % Exercises: Continuum hypothesis.

% \s{The Category of Sets}

% % Point out the structure of "objects and arrows between objects".  Mention that
% % this is called a category, and point out some properties of functions
% % (composition (+associativity), existence of identities).  Express bijectivity
% % as a categorical notion.

% % Exercises: Express injectivity and surjectivity as categorical notions.

% \s{Special kinds of sets}
% \ss{Magmas}
% \ss{Semigroups}
% \ss{Monoids}