\documentclass[numbers=enddot,12pt,final,onecolumn,notitlepage]{scrartcl}%
\usepackage[headsepline,footsepline,manualmark]{scrlayer-scrpage}
\usepackage[all,cmtip]{xy}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{framed}
\usepackage{comment}
\usepackage{color}
\usepackage[breaklinks=True]{hyperref}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{needspace}
\usepackage{tabls}
\usepackage{tikz}
\usepackage{bbding}
%TCIDATA{OutputFilter=latex2.dll}
%TCIDATA{Version=5.50.0.2960}
%TCIDATA{LastRevised=Thursday, March 07, 2024 12:41:17}
%TCIDATA{SuppressPackageManagement}
%TCIDATA{<META NAME="GraphicsSave" CONTENT="32">}
%TCIDATA{<META NAME="SaveForMode" CONTENT="1">}
%TCIDATA{BibliographyScheme=Manual}
%TCIDATA{Language=American English}
%BeginMSIPreambleData
\providecommand{\U}[1]{\protect\rule{.1in}{.1in}}
%EndMSIPreambleData
\usetikzlibrary{arrows.meta}
\usetikzlibrary{chains}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathmorphing}
\newcounter{exer}
\newcounter{exera}
\theoremstyle{definition}
\newtheorem{theo}{Theorem}[subsection]
\newenvironment{theorem}[1][]
{\begin{theo}[#1]\begin{leftbar}}
{\end{leftbar}\end{theo}}
\newtheorem{lem}[theo]{Lemma}
\newenvironment{lemma}[1][]
{\begin{lem}[#1]\begin{leftbar}}
{\end{leftbar}\end{lem}}
\newtheorem{prop}[theo]{Proposition}
\newenvironment{proposition}[1][]
{\begin{prop}[#1]\begin{leftbar}}
{\end{leftbar}\end{prop}}
\newtheorem{defi}[theo]{Definition}
\newenvironment{definition}[1][]
{\begin{defi}[#1]\begin{leftbar}}
{\end{leftbar}\end{defi}}
\newtheorem{remk}[theo]{Remark}
\newenvironment{remark}[1][]
{\begin{remk}[#1]\begin{leftbar}}
{\end{leftbar}\end{remk}}
\newtheorem{coro}[theo]{Corollary}
\newenvironment{corollary}[1][]
{\begin{coro}[#1]\begin{leftbar}}
{\end{leftbar}\end{coro}}
\newtheorem{conv}[theo]{Convention}
\newenvironment{convention}[1][]
{\begin{conv}[#1]\begin{leftbar}}
{\end{leftbar}\end{conv}}
\newtheorem{quest}[theo]{Question}
\newenvironment{question}[1][]
{\begin{quest}[#1]\begin{leftbar}}
{\end{leftbar}\end{quest}}
\newtheorem{warn}[theo]{Warning}
\newenvironment{warning}[1][]
{\begin{warn}[#1]\begin{leftbar}}
{\end{leftbar}\end{warn}}
\newtheorem{conj}[theo]{Conjecture}
\newenvironment{conjecture}[1][]
{\begin{conj}[#1]\begin{leftbar}}
{\end{leftbar}\end{conj}}
\newtheorem{exam}[theo]{Example}
\newenvironment{example}[1][]
{\begin{exam}[#1]\begin{leftbar}}
{\end{leftbar}\end{exam}}
\newtheorem{exmp}[exer]{Exercise}
\newenvironment{exercise}[1][]
{\begin{exmp}[#1]\begin{leftbar}}
{\end{leftbar}\end{exmp}}
\newenvironment{statement}{\begin{quote}}{\end{quote}}
\newenvironment{fineprint}{\begin{small}}{\end{small}}
\iffalse
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{convention}[1][Convention]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{question}[1][Question]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\fi
\let\sumnonlimits\sum
\let\prodnonlimits\prod
\let\cupnonlimits\bigcup
\let\capnonlimits\bigcap
\renewcommand{\sum}{\sumnonlimits\limits}
\renewcommand{\prod}{\prodnonlimits\limits}
\renewcommand{\bigcup}{\cupnonlimits\limits}
\renewcommand{\bigcap}{\capnonlimits\limits}
\newcommand\arxiv[1]{\href{http://www.arxiv.org/abs/#1}{\texttt{arXiv:#1}}}
\setlength\tablinesep{3pt}
\setlength\arraylinesep{3pt}
\setlength\extrarulesep{3pt}
\setlength\textheight{22.5cm}
\setlength\textwidth{14.8cm}
\newenvironment{verlong}{}{}
\newenvironment{vershort}{}{}
\newenvironment{noncompile}{}{}
\excludecomment{verlong}
\includecomment{vershort}
\excludecomment{noncompile}
\newcommand{\defn}[1]{{\color{darkred}\emph{#1}}}
\newcommand{\CC}{\mathbb{C}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\KK}{\mathbb{K}}
\newcommand{\set}[1]{\left\{ #1 \right\}}
\newcommand{\abs}[1]{\left| #1 \right|}
\newcommand{\tup}[1]{\left( #1 \right)}
\newcommand{\ive}[1]{\left[ #1 \right]}
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
\newcommand{\are}{\ar@{-}}
\newcommand{\arebi}[1][]{\ar@{<-}@/_/[#1] \ar@/^/[#1]}
\newcommand{\of}{\text{ of }}
\newtheoremstyle{plainsl}
{8pt plus 2pt minus 4pt}
{8pt plus 2pt minus 4pt}
{\slshape}
{0pt}
{\bfseries}
{.}
{5pt plus 1pt minus 1pt}
{}
\theoremstyle{plainsl}
\ihead{Lecture 14, version \today}
\ohead{page \thepage}
\cfoot{}
\begin{document}
\section*{Math 221 Winter 2023, Lecture 14: Enumeration}

\textbf{website:}
\texttt{\href{https://www.cip.ifi.lmu.de/~grinberg/t/23wd}{\texttt{https://www.cip.ifi.lmu.de/\symbol{126}%
grinberg/t/23wd}}}

\setcounter{section}{3}

\section{An introduction to enumeration}

\setcounter{subsection}{4}

\subsection{Maps (aka functions)}

\subsubsection{Functions, informally}

One of the main notions in mathematics is that of a \textbf{function}, aka
\textbf{map}, aka \textbf{mapping}, aka \textbf{transformation}.

Intuitively, a function is a \textquotedblleft black box\textquotedblright%
\ that takes inputs and transforms them into outputs. For example, the
\textquotedblleft$f\left(  t\right)  =t^{2}$\textquotedblright\ function takes
a real number $t$ and outputs its square $t^{2}$.

You can thus think of a function as a rule for producing an output from an
input. This gives the following \textbf{provisional} definition of a function:

\begin{definition}
[Informal definition of a function]\label{def.function.def-informal}Let $X$
and $Y$ be two sets. A \textbf{function} from $X$ to $Y$ is (provisionally) a
rule that transforms each element of $X$ into some element of $Y$.

If this function is called $f$, then the result of applying it to a given
$x\in X$ (that is, the output produced by $f$ when $x$ is the input) will be
called $f\left(  x\right)  $ (or sometimes $fx$).
\end{definition}

This is not a real definition, as it only kicks the can down the road: It
defines \textquotedblleft function\textquotedblright\ in terms of
\textquotedblleft rule\textquotedblright, but what is a rule? But it gives
some good intuition, provided that it is correctly understood. Here are some
comments that should clarify it:

\begin{itemize}
\item A function has to \textquotedblleft work\textquotedblright\ for each
element of $X$. It cannot decline to operate on some elements! Thus,
\textquotedblleft take the reciprocal\textquotedblright\ is not a function
from $\mathbb{R}$ to $\mathbb{R}$, since it does not operate on $0$ (because
$0$ has no reciprocal). However, \textquotedblleft take the
reciprocal\textquotedblright\ is a function from $\mathbb{R}\setminus\left\{
0\right\}  $ to $\mathbb{R}$, since any nonzero real number does have a reciprocal.

\item A function must not be ambiguous. Each input must produce exactly one
output. Thus, \textquotedblleft take your number to some random
power\textquotedblright\ is not a function from $\mathbb{R}$ to $\mathbb{R}$,
since different powers give different results. (There is a \textquotedblleft
multi-valued\textquotedblright\ variant of functions around, but they aren't
called \textquotedblleft functions\textquotedblright.)

\item We write \textquotedblleft$f:X\rightarrow Y$\textquotedblright\ for
\textquotedblleft$f$ is a function from $X$ to $Y$\textquotedblright.

\item Instead of saying \textquotedblleft$f\left(  x\right)  =y$%
\textquotedblright, we can say \textquotedblleft$f$ transforms $x$ into
$y$\textquotedblright\ or \textquotedblleft$f$ sends $x$ to $y$%
\textquotedblright\ or \textquotedblleft$f$ maps $x$ to $y$\textquotedblright%
\ or \textquotedblleft$f$ takes the value $y$ at $x$\textquotedblright\ or
\textquotedblleft$y$ is the value of $f$ at $x$\textquotedblright\ or
\textquotedblleft$y$ is the image of $x$ under $f$\textquotedblright\ or
\textquotedblleft applying $f$ to $x$ yields $y$\textquotedblright\ or
\textquotedblleft$f$ takes $x$ to $y$\textquotedblright\ or \textquotedblleft%
$f:x\mapsto y$\textquotedblright. All of these statements are synonyms.

For instance, if $f$ is the \textquotedblleft take the
square\textquotedblright\ function from $\mathbb{R}$ to $\mathbb{R}$, then
$f\left(  2\right)  =2^{2}=4$, so that $f$ transforms $2$ to $4$, or sends $2$
to $4$, or takes the value $4$ at $2$, etc., or $f:2\mapsto4$.

\item As the above terminology suggests, the \textbf{value} of a function $f$
at an input $x$ means the corresponding output $f\left(  x\right)  $.

\item The notation%
\begin{align*}
X  &  \rightarrow Y,\\
x  &  \mapsto\left(  \text{some expression involving }x\right)
\end{align*}
means \textquotedblleft the function from $X$ to $Y$ that sends each element
$x$ of $X$ to the expression on the right hand side\textquotedblright. Here,
the expression can (for example) be $x^{2}$ or $\dfrac{1}{x+4}$ or $\dfrac
{x}{x+2}$.

For example,%
\begin{align*}
\mathbb{R}  &  \rightarrow\mathbb{R},\\
x  &  \mapsto x^{2}%
\end{align*}
is the \textquotedblleft take the square\textquotedblright\ function (sending
each element $x$ of $\mathbb{R}$ to $x^{2}$). For another example,%
\begin{align*}
\mathbb{R}  &  \rightarrow\mathbb{R},\\
x  &  \mapsto\dfrac{x}{\sin x+15}%
\end{align*}
is the function that takes the sine of the input, then adds $15$, then divides
the input by the result. (Note that this is well-defined, since $\sin x+15$ is
never zero and thus the expression $\dfrac{x}{\sin x+15}$ is always
meaningful, so we really get a function from $\mathbb{R}$ to $\mathbb{R}$.)

For yet another example,%
\begin{align*}
\mathbb{R}  &  \rightarrow\mathbb{R},\\
x  &  \mapsto2
\end{align*}
is the function that sends each real number $x$ to $2$; this is an example of
a constant function. (This is a case where our \textquotedblleft expression
involving $x$\textquotedblright\ does not actually contain $x$. This is
perfectly fine; it's just a very simple particular case.)

For yet another example,%
\begin{align*}
\mathbb{Z}  &  \rightarrow\mathbb{Q},\\
x  &  \mapsto2^{x}%
\end{align*}
is a function. Some of its values are listed in the following table:%
\[%
\begin{tabular}
[c]{|c||c|c|c|c|c|}\hline
$x$ & $-2$ & $-1$ & $0$ & $1$ & $2$\\\hline
$2^{x}$ & $\dfrac{1}{4}$ & $\dfrac{1}{2}$ & $1$ & $2$ & $4$\\\hline
\end{tabular}
\]


\item The notation%
\begin{align*}
f:X  &  \rightarrow Y,\\
x  &  \mapsto\left(  \text{some expression involving }x\right)
\end{align*}
means that we take the function from $X$ to $Y$ that sends each $x\in X$ to
the expression on the right hand side, and we call this function $f$.

(Or, if a function named $f$ has already been defined, this notation means
that this $f$ \textbf{is} the function from $X$ to $Y$ that sends each $x\in
X$ to the expression on the right hand side.)

For example, if we write%
\begin{align*}
f:\mathbb{R}  &  \rightarrow\mathbb{R},\\
x  &  \mapsto x^{2}+1,
\end{align*}
then $f$ henceforth will denote the function from $\mathbb{R}$ to $\mathbb{R}$
that sends each $x\in\mathbb{R}$ to $x^{2}+1$.

\item If the set $X$ is finite, then a function $f:X\rightarrow Y$ can be
specified by simply listing all its values. For example, I can define a
function $h:\left\{  0,2,4\right\}  \rightarrow\mathbb{N}$ by setting%
\begin{align*}
h\left(  0\right)   &  =92,\\
h\left(  2\right)   &  =20,\\
h\left(  4\right)   &  =92.
\end{align*}
The values here have been chosen at whim, for no particular reason. A function
does not have to be \textquotedblleft natural\textquotedblright\ or
\textquotedblleft meaningful\textquotedblright\ in any way; all it has to do
is transform each element of $X$ into some element of $Y$.

\item If $f$ is a function from $X$ to $Y$, then the sets $X$ and $Y$ are part
of the function. Thus,%
\begin{align*}
g_{1}:\mathbb{Z}  &  \rightarrow\mathbb{Q},\\
x  &  \mapsto2^{x}%
\end{align*}
and%
\begin{align*}
g_{2}:\mathbb{N}  &  \rightarrow\mathbb{Q},\\
x  &  \mapsto2^{x}%
\end{align*}
and%
\begin{align*}
g_{3}:\mathbb{N}  &  \rightarrow\mathbb{N},\\
x  &  \mapsto2^{x}%
\end{align*}
are three distinct functions! We distinguish between them, so that we can
later speak of the \textquotedblleft domain\textquotedblright\ and the
\textquotedblleft target\textquotedblright\ of a function. Namely, the
\textbf{domain} of a function $f:X\rightarrow Y$ is defined to be the set $X$,
whereas the \textbf{target} of a function $f:X\rightarrow Y$ is defined to be
the set $Y$. Thus, the above function $g_{2}$ has target $\mathbb{Q}$, whereas
the function $g_{3}$ has target $\mathbb{N}$.

\item When are two functions equal? In programming, functions are often
understood to be (implemented) algorithms, and two algorithms can be different
even if they compute the same thing. In mathematics, it's different: Only the
domain, the target and the output values matter; the way they are computed
does not (and indeed there might not even be a way to compute them). Two
algorithms that (always) compute the same thing count for one function only.

So when are two functions considered to be equal?

Two functions $f_{1}:X_{1}\rightarrow Y_{1}$ and $f_{2}:X_{2}\rightarrow
Y_{2}$ are said to be \textbf{equal} if and only if%
\begin{align*}
X_{1}  &  =X_{2}\ \ \ \ \ \ \ \ \ \ \text{and}\ \ \ \ \ \ \ \ \ \ Y_{1}%
=Y_{2}\ \ \ \ \ \ \ \ \ \ \text{and}\\
f_{1}\left(  x\right)   &  =f_{2}\left(  x\right)
\ \ \ \ \ \ \ \ \ \ \text{for all }x\in X_{1}.
\end{align*}


An example of two equal functions is%
\begin{align*}
f_{1}:\mathbb{R}  &  \rightarrow\mathbb{R},\\
x  &  \mapsto x^{2}%
\end{align*}
and%
\begin{align*}
f_{2}:\mathbb{R}  &  \rightarrow\mathbb{R},\\
x  &  \mapsto\left\vert x\right\vert ^{2},
\end{align*}
since each $x\in\mathbb{R}$ satisfies $x^{2}=\left\vert x\right\vert ^{2}$.
\end{itemize}

At this point, we have a good idea of what a function is, but the provisional
definition given above (Definition \ref{def.function.def-informal}) wasn't as
precise as we would like. Even worse, the word \textquotedblleft
rule\textquotedblright\ in that definition is still unclear, and prevents us
from dealing with functions that can neither be given by an explicit formula
(such as \textquotedblleft take the square\textquotedblright) nor be specified
by a complete list of values (e.g., since the domain is infinite). Thus, we
need a better definition of a function.

This is what we will do today. The trick is to first define the more general
concept of a \textbf{relation}, and then to characterize functions as
relations with a certain property.

\subsubsection{Relations}

\textbf{Relations} (to be specific: binary relations) are another concept that
you have already seen on myriad examples:

\begin{itemize}
\item The relation $\subseteq$ is a relation between two sets. For example,
$\left\{  1,3\right\}  \subseteq\left\{  1,2,3,4\right\}  $ but $\left\{
1,5\right\}  \not \subseteq \left\{  1,2,3,4\right\}  $.

\item The order relations $\leq$ and $<$ and $>$ and $\geq$ are relations
between two integers (or rational numbers, or real numbers). For example,
$1\leq5$ but $1\nleq-1$.

\item The containment relation $\in$ is a relation between an object and a
set. For instance, $3\in\left\{  1,2,3,4\right\}  $ but $5\notin\left\{
1,2,3,4\right\}  $.

\item The divisibility relation $\mid$ is a relation between two integers.

\item The relation \textquotedblleft coprime\textquotedblright\ is a relation
between two integers.

\item In plane geometry, there are lots of relations: \textquotedblleft
parallel\textquotedblright\ (between two lines), \textquotedblleft
perpendicular\textquotedblright\ (between two lines), \textquotedblleft
congruent\textquotedblright\ (between two shapes), \textquotedblleft
similar\textquotedblright, \textquotedblleft directly
similar\textquotedblright, etc.

\item For any given integer $n$, the relation \textquotedblleft congruent
modulo $n$\textquotedblright\ is a relation between two integers. Let me call
it $\overset{n}{\equiv}$. Thus, $a\overset{n}{\equiv}b$ holds if and only if
$a\equiv b\operatorname{mod}n$. For example, $2\overset{3}{\equiv}8$ but
$2\overset{3}{\not \equiv }7$.
\end{itemize}

What do these relations all have in common? They can be applied to pairs of
objects. Applying a relation to a pair of objects gives a statement that can
be true or false. For example, applying the relation \textquotedblleft
coprime\textquotedblright\ to the pair $\left(  5,8\right)  $ yields the
statement \textquotedblleft$5$ is coprime to $8$\textquotedblright, which is
true. Applying it to the pair $\left(  5,10\right)  $ yields the statement
\textquotedblleft$5$ is coprime to $10$\textquotedblright, which is false.

A general relation $R$ relates elements of a set $X$ with elements of a set
$Y$. For any pair $\left(  x,y\right)  \in X\times Y$ (that is, for any pair
consisting of an element $x\in X$ and an element $y\in Y$), we can apply the
relation $R$ to the pair $\left(  x,y\right)  $, obtaining a statement
\textquotedblleft$x\ R\ y$\textquotedblright\ that is either true or false. To
describe this relation $R$, we need to know which pairs $\left(  x,y\right)
\in X\times Y$ do satisfy $x\ R\ y$ and which pairs don't. In other words, we
need to know the \textbf{set} of all pairs $\left(  x,y\right)  \in X\times Y$
that satisfy $x\ R\ y$. For a rigorous definition of a relation, we simply
take the relation $R$ to \textbf{be} this set of pairs. In other words, we
define relations as follows:

\begin{definition}
\label{def.relation}Let $X$ and $Y$ be two sets. A \textbf{relation} from $X$
to $Y$ is a subset of $X\times Y$.

If $R$ is a relation from $X$ to $Y$, and if $\left(  x,y\right)  \in X\times
Y$ is any pair, then

\begin{itemize}
\item we write $x\ R\ y$ if $\left(  x,y\right)  \in R$;

\item we write $x\ \not R  \ y$ if $\left(  x,y\right)  \notin R$.
\end{itemize}
\end{definition}

All the relations we have seen so far can be recast in terms of this definition:

\begin{itemize}
\item The divisibility relation $\mid$ is a subset of $\mathbb{Z}%
\times\mathbb{Z}$, namely the subset%
\begin{align*}
&  \left\{  \left(  x,y\right)  \in\mathbb{Z}\times\mathbb{Z}\ \mid\ x\text{
divides }y\right\} \\
&  =\left\{  \left(  x,y\right)  \in\mathbb{Z}\times\mathbb{Z}\ \mid
\ \text{there exists some }z\in\mathbb{Z}\text{ such that }y=xz\right\} \\
&  =\left\{  \left(  x,xz\right)  \ \mid\ x\in\mathbb{Z}\text{ and }%
z\in\mathbb{Z}\right\}  .
\end{align*}
For instance, the pairs $\left(  2,4\right)  $ and $\left(  3,9\right)  $ and
$\left(  10,20\right)  $ belong to this subset, whereas the pairs $\left(
2,3\right)  $ and $\left(  2,15\right)  $ and $\left(  10,5\right)  $ do not.

\item The coprimality relation (\textquotedblleft coprime to\textquotedblright%
) is a subset of $\mathbb{Z}\times\mathbb{Z}$, namely the subset%
\begin{align*}
&  \left\{  \left(  x,y\right)  \in\mathbb{Z}\times\mathbb{Z}\ \mid\ x\text{
is coprime to }y\right\} \\
&  =\left\{  \left(  x,y\right)  \in\mathbb{Z}\times\mathbb{Z}\ \mid
\ \gcd\left(  x,y\right)  =1\right\}  .
\end{align*}
It contains, for instance, $\left(  2,3\right)  $ and $\left(  7,9\right)  $,
but not $\left(  4,6\right)  $.

\item For any $n\in\mathbb{Z}$, the \textquotedblleft congruent modulo
$n$\textquotedblright\ relation $\overset{n}{\equiv}$ is a subset of
$\mathbb{Z}\times\mathbb{Z}$, namely the subset%
\begin{align*}
&  \left\{  \left(  x,y\right)  \in\mathbb{Z}\times\mathbb{Z}\ \mid\ x\equiv
y\operatorname{mod}n\right\} \\
&  =\left\{  \left(  x,\ x+nz\right)  \ \mid\ x\in\mathbb{Z}\text{ and }%
z\in\mathbb{Z}\right\}  .
\end{align*}


\item A geometric example: Let $P$ be the set of all points in the plane, and
let $L$ be the set of all lines in the plane. Then, the \textquotedblleft lies
on\textquotedblright\ relation (as in \textquotedblleft a point lies on a
line\textquotedblright) is a subset of $P\times L$, namely the subset%
\[
\left\{  \left(  p,\ell\right)  \in P\times L\ \mid\ \text{the point }p\text{
lies on the line }\ell\right\}  .
\]


\item If $A$ is any set, then the \textbf{equality relation} on $A$ is the
subset $E_{A}$ of $A\times A$ given by%
\begin{align*}
E_{A}  &  =\left\{  \left(  x,y\right)  \in A\times A\ \mid\ x=y\right\} \\
&  =\left\{  \left(  x,x\right)  \ \mid\ x\in A\right\}  .
\end{align*}
Two elements $x$ and $y$ of $A$ satisfy $x\ E_{A}\ y$ if and only if they are equal.

\item We can literally take any subset of $X\times Y$ (where $X$ and $Y$ are
two sets) and it will be a relation from $X$ to $Y$. Just as with functions, a
relation does not have to follow any \textquotedblleft
meaningful\textquotedblright\ rule. For example, here is a relation from
$\left\{  1,2,3\right\}  $ to $\left\{  5,6,7\right\}  $:%
\[
\left\{  \left(  1,6\right)  ,\ \left(  1,7\right)  ,\ \left(  3,5\right)
\right\}  .
\]
Equivalently, it can be specified by the table%
\[%
\begin{tabular}
[c]{c||ccc}
& $5$ & $6$ & $7$\\\hline\hline
$1$ & no & yes & yes\\
$2$ & no & no & no\\
$3$ & yes & no & no
\end{tabular}
\]
(where a \textquotedblleft yes\textquotedblright\ in row $x$ and column $y$
means that $\left(  x,y\right)  $ belongs to the relation). If we call this
relation $R$, then we have $1\ R\ 6$ and $1\ R\ 7$ and $3\ R\ 5$ but not
$1\ R\ 5$ or $2\ R\ 6$.
\end{itemize}

A good way to visualize a relation $R$ from a set $X$ to a set $Y$ (at least
when $X$ and $Y$ are finite) is by drawing the sets $X$ and $Y$ as blobs,
drawing their elements as nodes within these blobs, and drawing an arrow from
the $x$-node to the $y$-node for every pair $\left(  x,y\right)  $ that
belongs to the relation $R$. For example, the relation $R$ in our last example
can be visualized as follows:%
\begin{equation}%
%TCIMACRO{\TeXButton{tikz relation}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
%\node(1) at (0, 2) {$1$};
%\node(2) at (0, 1) {$2$};
%\node(3) at (0, 0) {$3$};
%\node(Cname) at (0, 3) {$X$};
%\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
%\node(5) at (3, 2) {$5$};
%\node(6) at (3, 1) {$6$};
%\node(7) at (3, 0) {$7$};
%\node(Dname) at (3, 3) {$Y$};
%\draw[->, very thick, green!50!black] (1) -- (6);
%\draw[->, very thick, green!50!black] (1) -- (7);
%\draw[->, very thick, green!50!black] (3) -- (5);
%\end{tikzpicture}} }%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
\node(1) at (0, 2) {$1$};
\node(2) at (0, 1) {$2$};
\node(3) at (0, 0) {$3$};
\node(Cname) at (0, 3) {$X$};
\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
\node(5) at (3, 2) {$5$};
\node(6) at (3, 1) {$6$};
\node(7) at (3, 0) {$7$};
\node(Dname) at (3, 3) {$Y$};
\draw[->, very thick, green!50!black] (1) -- (6);
\draw[->, very thick, green!50!black] (1) -- (7);
\draw[->, very thick, green!50!black] (3) -- (5);
\end{tikzpicture}
%EndExpansion
\label{eq.relation.123-567}%
\end{equation}


\subsubsection{Functions, formally}

We can now define functions rigorously:

\begin{definition}
[Rigorous definition of a function]\label{def.function.def-rig}Let $X$ and $Y$
be two sets. A \textbf{function} from $X$ to $Y$ means a relation $R$ from $X$
to $Y$ that has the following property:

\begin{itemize}
\item \textbf{Output uniqueness:} For each $x\in X$, there exists
\textbf{exactly one} $y\in Y$ such that $x\ R\ y$.
\end{itemize}

If $R$ is a function from $X$ to $Y$, and if $x$ is an element of $X$, then
the unique element $y\in Y$ satisfying $x\ R\ y$ will be called $f\left(
x\right)  $.
\end{definition}

In our above example, the relation%
\[
\left\{  \left(  1,6\right)  ,\ \left(  1,7\right)  ,\ \left(  3,5\right)
\right\}
\]
(which we illustrated in (\ref{eq.relation.123-567})) is not a function from
$\left\{  1,2,3\right\}  $ to $\left\{  5,6,7\right\}  $. In fact, it violates
output uniqueness at $x=1$ (since there are two $y\in\left\{  5,6,7\right\}  $
that satisfy $1\ R\ y$) and also violates it at $x=2$ (since there are no
$y\in\left\{  5,6,7\right\}  $ that satisfy $2\ R\ y$). Each of these two
violations is reason enough to disqualify this relation from being a function.

In our above list of relations, only the equality relation $E_{A}$ is a function.

Here is an example of a function from $X=\left\{  1,2,3\right\}  $ to
$Y=\left\{  5,6,7,8\right\}  $: the relation%
\[
\left\{  \left(  1,7\right)  ,\ \left(  2,5\right)  ,\ \left(  3,7\right)
\right\}  .
\]
This relation satisfies output uniqueness and thus is a function. Visualized
by blobs and arrows, it looks as follows:%
\[%
%TCIMACRO{\TeXButton{tikz relation}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
%\node(1) at (0, 2) {$1$};
%\node(2) at (0, 1) {$2$};
%\node(3) at (0, 0) {$3$};
%\node(Cname) at (0, 3) {$X$};
%\filldraw[fill=cyan!20!white] (3, 0.5) ellipse (1 and 2);
%\node(5) at (3, 2) {$5$};
%\node(6) at (3, 1) {$6$};
%\node(7) at (3, 0) {$7$};
%\node(8) at (3, -1) {$8$};
%\node(Dname) at (3, 3) {$Y$};
%\draw[->, very thick, green!50!black] (1) -- (7);
%\draw[->, very thick, green!50!black] (2) -- (5);
%\draw[->, very thick, green!50!black] (3) -- (7);
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
\node(1) at (0, 2) {$1$};
\node(2) at (0, 1) {$2$};
\node(3) at (0, 0) {$3$};
\node(Cname) at (0, 3) {$X$};
\filldraw[fill=cyan!20!white] (3, 0.5) ellipse (1 and 2);
\node(5) at (3, 2) {$5$};
\node(6) at (3, 1) {$6$};
\node(7) at (3, 0) {$7$};
\node(8) at (3, -1) {$8$};
\node(Dname) at (3, 3) {$Y$};
\draw[->, very thick, green!50!black] (1) -- (7);
\draw[->, very thick, green!50!black] (2) -- (5);
\draw[->, very thick, green!50!black] (3) -- (7);
\end{tikzpicture}%
%EndExpansion
\ \ .
\]
If we denote this function by $f$, then $f\left(  1\right)  =7$ and $f\left(
2\right)  =5$ and $f\left(  3\right)  =7$.

Our way of visualizing relations by blobs and arrows makes the output
uniqueness property quite intuitive: This property just says that for each
$x\in X$, there is \textbf{exactly one} arrow starting at the $x$-node. In
other words, each node in the $X$-blob has to be the starting point of exactly
one arrow. Thus, a function is a relation whose visual picture has exactly one
arrow coming out of each $X$-node.

\bigskip

Now we have two definitions of a function: the provisional definition
(Definition \ref{def.function.def-informal}) and the rigorous one (Definition
\ref{def.function.def-rig}). These two definitions are equivalent. Indeed:

\begin{itemize}
\item If $R$ is a function from $X$ to $Y$ in the sense of the rigorous
definition (i.e., a relation from $X$ to $Y$ that satisfies output
uniqueness), then $R$ can also be viewed as a rule that sends each element $x$
of $X$ to some element of $Y$ (namely, to the unique $y\in Y$ that satisfies
$x\ R\ y$). Thus, $R$ becomes a function in the provisional sense.

\item Conversely, if $f$ is a function from $X$ to $Y$ in the provisional
sense (i.e., a rule sending elements of $X$ to elements of $Y$), then $f$ can
also be viewed as a function in the rigorous sense (i.e., as a relation from
$X$ to $Y$ that satisfies output uniqueness), as follows: Let $R$ be the set%
\[
\left\{  \left(  x,\ f\left(  x\right)  \right)  \ \mid\ x\in X\right\}  .
\]
This set $R$ is a subset of $X\times Y$, that is, a relation from $X$ to $Y$.
(In a more intuitive language, this relation $R$ is characterized as follows:
Two elements $x\in X$ and $y\in Y$ satisfy $x\ R\ y$ if and only if
$y=f\left(  x\right)  $. That is, roughly speaking, the relation $R$ relates
each input $x\in X$ with the corresponding output value $f\left(  x\right)
\in Y$ and with nothing else.) This relation $R$ satisfies output uniqueness
(because each input $x\in X$ produces exactly one output value $f\left(
x\right)  $), and therefore is a function from $X$ to $Y$ in the rigorous
sense. Thus, $f$ becomes a function in the rigorous sense (namely, the
rigorous function $R$).
\end{itemize}

Therefore, we can translate rigorous functions into provisional ones and vice
versa. We thus shall think of the two concepts as being the same. In
particular, all the notations we have introduced for provisional functions
will be used for rigorous ones.

\subsubsection{Some more examples of functions}

Let us give some examples of functions as well as some examples of what looks
like functions but are not.

\begin{example}
Consider the function
\[
f_{0}:\left\{  1,2,3,4\right\}  \rightarrow\left\{  1,2,3,4\right\}
\]
that sends $1,2,3,4$ to $3,2,3,3$, respectively. As a rigorous function, it is
the relation $R$ that satisfies%
\[
1\ R\ 3,\ \ \ \ \ \ \ \ \ \ 2\ R\ 2,\ \ \ \ \ \ \ \ \ \ 3\ R\ 3,\ \ \ \ \ \ \ \ \ \ 4\ R\ 3
\]
(and nothing else). In other words, it is the relation%
\[
\left\{  \left(  1,3\right)  ,\ \left(  2,2\right)  ,\ \left(  3,3\right)
,\ \left(  4,3\right)  \right\}  .
\]

\end{example}

\begin{example}
What about the function%
\begin{align*}
f_{1}:\left\{  1,2,3,4\right\}   &  \rightarrow\left\{  1,2,3\right\}  ,\\
n  &  \mapsto n\text{\ \ \ \ ?}%
\end{align*}
Such a function $f_{1}$ does not exist, since it would have to send $4$ to
$4$, but $4$ is not in the target $\left\{  1,2,3\right\}  $.

This is a pedantic issue, but it should be kept in mind: Not every expression
that appears to define a function actually defines a function. Make sure that
the expression to the right of the \textquotedblleft$\mapsto$%
\textquotedblright\ symbol always is an actual element of the target (which,
in this case, is the set $\left\{  1,2,3\right\}  $).
\end{example}

\begin{example}
Consider the function%
\begin{align*}
f_{2}:\left\{  1,2,3,\ldots\right\}   &  \rightarrow\left\{  1,2,3,\ldots
\right\}  ,\\
n  &  \mapsto\left(  \text{the number of positive divisors of }n\right)  .
\end{align*}
As a relation, it is%
\[
\left\{  \left(  1,1\right)  ,\ \left(  2,2\right)  ,\ \left(  3,2\right)
,\ \left(  4,3\right)  ,\ \left(  5,2\right)  ,\ \left(  6,4\right)
,\ \left(  7,2\right)  ,\ \left(  8,4\right)  ,\ \left(  9,3\right)
,\ \ldots\right\}  .
\]
(We cannot list all the pairs, since there are infinitely many.) Thus,
$f_{2}\left(  1\right)  =1$ and $f_{2}\left(  2\right)  =2$ and $f_{2}\left(
3\right)  =2$ and so on.
\end{example}

\begin{example}
What about the function%
\begin{align*}
\widetilde{f}_{2}:\mathbb{Z}  &  \rightarrow\left\{  1,2,3,\ldots\right\}  ,\\
n  &  \mapsto\left(  \text{the number of positive divisors of }n\right)
\ \ \ \ \text{?}%
\end{align*}
There is no such function $\widetilde{f}_{2}$, since $\widetilde{f}_{2}\left(
0\right)  $ would have to be undefined or $\infty$ (because $0$ has infinitely
many positive divisors).

This is the exact same problem that we had with the non-function $f_{1}$ above.
\end{example}

\begin{example}
What about the function%
\begin{align*}
f_{3}:\left\{  1,2,3,\ldots\right\}   &  \rightarrow\left\{  1,2,3,\ldots
\right\}  ,\\
n  &  \mapsto\left(  \text{the smallest prime divisor of }n\right)
\ \ \ \ \text{?}%
\end{align*}
Again, there is no such function $f_{3}$, since $f_{3}\left(  1\right)  $
makes no sense (indeed, the number $1$ has no prime divisors, thus no smallest
prime divisor).

This is essentially the same problem as with the function $\widetilde{f}_{2}$
from the previous example, except that this time the value $f_{3}\left(
1\right)  $ is really undefined (as opposed to just failing to belong to the target).

Note that the function $f_{3}$ \textquotedblleft almost\textquotedblright%
\ exists: There is a relation \textquotedblleft$y$ is the smallest prime
divisor of $x$\textquotedblright\ from $\left\{  1,2,3,\ldots\right\}  $ to
$\left\{  1,2,3,\ldots\right\}  $, but this relation fails the output
uniqueness requirement at $x=1$, and thus is not a function. However, we can
make it into a function by removing the offending element $1$ from its domain.
That is, there is a function%
\begin{align*}
\widetilde{f}_{3}:\left\{  2,3,4,\ldots\right\}   &  \rightarrow\left\{
1,2,3,\ldots\right\}  ,\\
n  &  \mapsto\left(  \text{the smallest prime divisor of }n\right)  .
\end{align*}

\end{example}

\begin{example}
What about the function%
\begin{align*}
f_{4}:\mathbb{Q}  &  \rightarrow\mathbb{Z},\\
\dfrac{a}{b}  &  \mapsto a\ \ \ \ \ \left(  \text{for }a,b\in\mathbb{Z}%
\right)  \text{ ?}%
\end{align*}
Restated in words, this is to be a function that takes a rational number as
input, writes it as a ratio of two integers and outputs the numerator. Is
there such a function?

Again, the answer is \textbf{no}. Again, the problem is a failure of output
uniqueness, but this time, it fails not because the output does not exist (or
does not belong to the target), but rather because the output is non-unique.
For example, if $f_{4}$ was a function, then we would have the two equalities
\begin{align*}
f_{4}\left(  0.5\right)   &  =f_{4}\left(  \dfrac{1}{2}\right)
=1\ \ \ \ \ \ \ \ \ \ \text{and}\\
f_{4}\left(  0.5\right)   &  =f_{4}\left(  \dfrac{3}{6}\right)  =3,
\end{align*}
which contradict one another. The underlying issue is that a rational number
can be written as a fraction in several different ways, and the numerators of
these fractions will usually \textbf{not be the same}. Thus, if you follow the
rule $\dfrac{a}{b}\mapsto a$ to compute the output of $f_{4}$ for a given
input, your output will depend on how exactly you write your input as a
fraction, and this is a violation of output uniqueness.
\end{example}

\subsubsection{Well-definedness}

The issues that we have seen in the last few examples (supposed functions
failing to exist either because their output values make no sense, or because
these values don't lie in $Y$, or because these values are ambiguous) are
known as \textbf{well-definedness} issues. Often, mathematicians say that
\textquotedblleft a function is well-defined\textquotedblright\ when they mean
that its definition does not suffer from such issues (i.e., its definition
really defines a function). So you should read \textquotedblleft This function
is well-defined [or: not well-defined]\textquotedblright\ as \textquotedblleft
The definition we just gave really defines a function [or: does not actually
define a function]\textquotedblright.

For example, as we just saw, the function%
\begin{align*}
f_{4}:\mathbb{Q}  &  \rightarrow\mathbb{Z},\\
\dfrac{a}{b}  &  \mapsto a
\end{align*}
is not well-defined (i.e., there is no such function), but the function%
\begin{align*}
f_{5}:\mathbb{Q}  &  \rightarrow\mathbb{Q},\\
\dfrac{a}{b}  &  \mapsto\dfrac{a^{2}}{b^{2}}%
\end{align*}
is well-defined (because if you write a given rational number as $\dfrac{a}%
{b}$ for different pairs $\left(  a,b\right)  $, the resulting quotients
$\dfrac{a^{2}}{b^{2}}$ will all be equal). The function%
\begin{align*}
f_{1}:\left\{  1,2,3,4\right\}   &  \rightarrow\left\{  1,2,3\right\}  ,\\
n  &  \mapsto n
\end{align*}
is not well-defined (since its supposed output $f_{1}\left(  4\right)  $ fails
to lie in the target $\left\{  1,2,3\right\}  $), whereas the function%
\begin{align*}
f_{6}:\left\{  1,2,3,4\right\}   &  \rightarrow\left\{  1,2,3\right\}  ,\\
n  &  \mapsto1+\left(  n\%3\right)
\end{align*}
is well-defined (since its outputs at $1,2,3,4$ are $2,3,1,2$).

\subsubsection{The identity function}

\begin{definition}
For any set $A$, there is an \textbf{identity function} $\operatorname*{id}%
\nolimits_{A}:A\rightarrow A$. This is the function that sends each element
$a\in A$ to $a$ itself. In other words, it is precisely the relation $E_{A}$
defined above.
\end{definition}

Here is the blobs-and-arrows visualization of the identity function
$\operatorname*{id}\nolimits_{A}$ for $A=\left\{  1,2,3\right\}  $:%
\[%
%TCIMACRO{\TeXButton{tikz relation}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
%\node(1) at (0, 2) {$1$};
%\node(2) at (0, 1) {$2$};
%\node(3) at (0, 0) {$3$};
%\node(Cname) at (0, 3) {$X$};
%\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
%\node(5) at (3, 2) {$1$};
%\node(6) at (3, 1) {$2$};
%\node(7) at (3, 0) {$3$};
%\node(Dname) at (3, 3) {$Y$};
%\draw[->, very thick, green!50!black] (1) -- (5);
%\draw[->, very thick, green!50!black] (2) -- (6);
%\draw[->, very thick, green!50!black] (3) -- (7);
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
\node(1) at (0, 2) {$1$};
\node(2) at (0, 1) {$2$};
\node(3) at (0, 0) {$3$};
\node(Cname) at (0, 3) {$X$};
\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
\node(5) at (3, 2) {$1$};
\node(6) at (3, 1) {$2$};
\node(7) at (3, 0) {$3$};
\node(Dname) at (3, 3) {$Y$};
\draw[->, very thick, green!50!black] (1) -- (5);
\draw[->, very thick, green!50!black] (2) -- (6);
\draw[->, very thick, green!50!black] (3) -- (7);
\end{tikzpicture}%
%EndExpansion
\]


\subsubsection{Another example}

As we said before, a function $f:X\rightarrow Y$ can be described either by a
rule or by a list of values (if $X$ is finite) or as a relation. For instance,
the \textquotedblleft take the square\textquotedblright\ function on real
numbers is the function%
\begin{align*}
f:\mathbb{R}  &  \rightarrow\mathbb{R},\\
x  &  \mapsto x^{2}.
\end{align*}
As a relation, it is the set%
\[
\left\{  \left(  x,x^{2}\right)  \ \mid\ x\in\mathbb{R}\right\}  .
\]


\subsubsection{Composition of functions}

There are some ways to transform functions into other functions. The most
important one is \textbf{composition}:

\begin{definition}
Let $X$, $Y$ and $Z$ be three sets. Let $f:Y\rightarrow Z$ and $g:X\rightarrow
Y$ be two functions. Then, $f\circ g$ denotes the function%
\begin{align*}
X  &  \rightarrow Z,\\
x  &  \mapsto f\left(  g\left(  x\right)  \right)  .
\end{align*}
In other words, $f\circ g$ is the function that first applies $g$ and then
applies $f$. This function $f\circ g$ is called the \textbf{composition} of
$f$ with $g$ (and I pronounce it \textquotedblleft$f$ after $g$%
\textquotedblright).
\end{definition}

In terms of relations, if we view $f$ and $g$ as two relations $F$ and $G$ (as
in Definition \ref{def.function.def-rig}), then $f\circ g$ is the relation%
\[
\left\{  \left(  x,z\right)  \ \mid\ \text{there exists }y\in Y\text{ such
that }x\ G\ y\text{ and }y\ F\ z\right\}  \text{ from }X\text{ to }Z.
\]


\begin{example}
Let $\mathbb{R}_{\geq0}$ denote the set of all nonnegative real numbers.
Consider the two functions
\begin{align*}
f:\mathbb{R}_{\geq0} &  \rightarrow\mathbb{R}_{\geq0},\\
x &  \mapsto x^{2}%
\end{align*}
and%
\begin{align*}
g:\mathbb{R}_{\geq0} &  \rightarrow\mathbb{R}_{\geq0},\\
x &  \mapsto\dfrac{1}{x+7}.
\end{align*}
Then, for any nonnegative real $x\in\mathbb{R}_{\geq0}$, we have%
\[
\left(  f\circ g\right)  \left(  x\right)  =f\left(  g\left(  x\right)
\right)  =f\left(  \dfrac{1}{x+7}\right)  =\left(  \dfrac{1}{x+7}\right)  ^{2}%
\]
whereas%
\[
\left(  g\circ f\right)  \left(  x\right)  =g\left(  f\left(  x\right)
\right)  =g\left(  x^{2}\right)  =\dfrac{1}{x^{2}+7}.
\]
Note that these two results are different. Thus, $f\circ g\neq g\circ f$ in general.
\end{example}

\begin{example}
Consider the two functions $f:\left\{  1,2,3\right\}  \rightarrow\left\{
1,2,3,4\right\}  $ and $g:\left\{  1,2,3,4\right\}  \rightarrow\left\{
1,2,3\right\}  $ given by the following tables of values:%
\[%
\begin{tabular}
[c]{|c||c|c|c|}\hline
$i$ & $1$ & $2$ & $3$\\\hline
$f\left(  i\right)  $ & $1$ & $3$ & $2$\\\hline
\end{tabular}
\ \ \ \ \ \ \ \ \ \ \
\begin{tabular}
[c]{|c||c|c|c|c|}\hline
$i$ & $1$ & $2$ & $3$ & $4$\\\hline
$g\left(  i\right)  $ & $2$ & $1$ & $3$ & $2$\\\hline
\end{tabular}
\ \ \ .
\]


These two functions can be visualized using blobs and arrows, and we can even
reuse the target-blob from $g$ as the domain-blob for $f$:
\[%
%TCIMACRO{\TeXButton{tikz 3 blobs}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 0.5) ellipse (1 and 2);
%\node(1) at (0, 2) {$1$};
%\node(2) at (0, 1) {$2$};
%\node(3) at (0, 0) {$3$};
%\node(4) at (0, -1) {$4$};
%\node(Cname) at (0, 3) {$\set{1,2,3,4}$};
%\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
%\node(11) at (3, 2) {$1$};
%\node(22) at (3, 1) {$2$};
%\node(33) at (3, 0) {$3$};
%\node(Dname) at (3, 3) {$\set{1,2,3}$};
%\filldraw[fill=cyan!20!white] (6, 0.5) ellipse (1 and 2);
%\node(111) at (6, 2) {$1$};
%\node(222) at (6, 1) {$2$};
%\node(333) at (6, 0) {$3$};
%\node(444) at (6, -1) {$4$};
%\node(Ename) at (6, 3) {$\set{1,2,3,4}$};
%\draw[->, very thick, green!50!black] (11) -- (111);
%\draw[->, very thick, green!50!black] (22) -- (333);
%\draw[->, very thick, green!50!black] (33) -- (222);
%\draw[->, very thick, green!50!black] (1) -- (22);
%\draw[->, very thick, green!50!black] (2) -- (11);
%\draw[->, very thick, green!50!black] (3) -- (33);
%\draw[->, very thick, green!50!black] (4) -- (22);
%\node(oname) at (1.5, -0.5) {$\color{green!50!black}{g}$};
%\node(pname) at (4.5, -0.5) {$\color{green!50!black}{f}$};
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 0.5) ellipse (1 and 2);
\node(1) at (0, 2) {$1$};
\node(2) at (0, 1) {$2$};
\node(3) at (0, 0) {$3$};
\node(4) at (0, -1) {$4$};
\node(Cname) at (0, 3) {$\set{1,2,3,4}$};
\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
\node(11) at (3, 2) {$1$};
\node(22) at (3, 1) {$2$};
\node(33) at (3, 0) {$3$};
\node(Dname) at (3, 3) {$\set{1,2,3}$};
\filldraw[fill=cyan!20!white] (6, 0.5) ellipse (1 and 2);
\node(111) at (6, 2) {$1$};
\node(222) at (6, 1) {$2$};
\node(333) at (6, 0) {$3$};
\node(444) at (6, -1) {$4$};
\node(Ename) at (6, 3) {$\set{1,2,3,4}$};
\draw[->, very thick, green!50!black] (11) -- (111);
\draw[->, very thick, green!50!black] (22) -- (333);
\draw[->, very thick, green!50!black] (33) -- (222);
\draw[->, very thick, green!50!black] (1) -- (22);
\draw[->, very thick, green!50!black] (2) -- (11);
\draw[->, very thick, green!50!black] (3) -- (33);
\draw[->, very thick, green!50!black] (4) -- (22);
\node(oname) at (1.5, -0.5) {$\color{green!50!black}{g}$};
\node(pname) at (4.5, -0.5) {$\color{green!50!black}{f}$};
\end{tikzpicture}%
%EndExpansion
\ \ .
\]
This allows us to visually construct $f\circ g$ by removing the middle blob
and merging each $g$-arrow with the $f$-arrow that starts where the $g$-arrow
ends:
\[%
%TCIMACRO{\TeXButton{tikz merged}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 0.5) ellipse (1 and 2);
%\node(1) at (0, 2) {$1$};
%\node(2) at (0, 1) {$2$};
%\node(3) at (0, 0) {$3$};
%\node(4) at (0, -1) {$4$};
%\node(Cname) at (0, 3) {$\set{1,2,3,4}$};
%\filldraw[fill=cyan!20!white] (6, 0.5) ellipse (1 and 2);
%\node(111) at (6, 2) {$1$};
%\node(222) at (6, 1) {$2$};
%\node(333) at (6, 0) {$3$};
%\node(444) at (6, -1) {$4$};
%\node(Ename) at (6, 3) {$\set{1,2,3,4}$};
%\draw[->, very thick, green!50!black] (1) -- (333);
%\draw[->, very thick, green!50!black] (2) -- (111);
%\draw[->, very thick, green!50!black] (3) -- (222);
%\draw[->, very thick, green!50!black] (4) -- (333);
%\node(oname) at (3, -1) {$\color{green!50!black}{f \circ g}$};
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 0.5) ellipse (1 and 2);
\node(1) at (0, 2) {$1$};
\node(2) at (0, 1) {$2$};
\node(3) at (0, 0) {$3$};
\node(4) at (0, -1) {$4$};
\node(Cname) at (0, 3) {$\set{1,2,3,4}$};
\filldraw[fill=cyan!20!white] (6, 0.5) ellipse (1 and 2);
\node(111) at (6, 2) {$1$};
\node(222) at (6, 1) {$2$};
\node(333) at (6, 0) {$3$};
\node(444) at (6, -1) {$4$};
\node(Ename) at (6, 3) {$\set{1,2,3,4}$};
\draw[->, very thick, green!50!black] (1) -- (333);
\draw[->, very thick, green!50!black] (2) -- (111);
\draw[->, very thick, green!50!black] (3) -- (222);
\draw[->, very thick, green!50!black] (4) -- (333);
\node(oname) at (3, -1) {$\color{green!50!black}{f \circ g}$};
\end{tikzpicture}%
%EndExpansion
\]

\end{example}


\end{document}