\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=Tuesday, December 06, 2022 09:33:36}
%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 }}
\definecolor{darkgreen}{rgb}{0,.5,0}
\newtheoremstyle{plainsl}
{8pt plus 2pt minus 4pt}
{8pt plus 2pt minus 4pt}
{\slshape}
{0pt}
{\bfseries}
{.}
{5pt plus 1pt minus 1pt}
{}
\theoremstyle{plainsl}
\ihead{Lecture 12, version \today}
\ohead{page \thepage}
\cfoot{}
\begin{document}
\section*{Math 222 Fall 2022, Lecture 12: Introduction}

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

\section{Introduction (cont'd)}

\setcounter{subsection}{5}

\subsection{Interchange of summations}

\setcounter{subsubsection}{1}

\subsubsection{The Fubini principle with a predicate (cont'd)}

\setcounter{theo}{7}

Last time we stated a \textquotedblleft triangular Fubini
principle\textquotedblright\ for interchanging non-independent summation
signs. Here is another such principle:

\begin{corollary}
\label{cor.fubini.triang2}Let $n\in\mathbb{N}$. For each pair $\left(
x,y\right)  \in\left[  n\right]  \times\left[  n\right]  $ satisfying $x\leq
y$, let $a_{\left(  x,y\right)  }$ be a number. Then,%
\[
\sum_{x=1}^{n}\ \ \sum_{y=x}^{n}a_{\left(  x,y\right)  }=\sum
_{\substack{\left(  x,y\right)  \in\left[  n\right]  \times\left[  n\right]
;\\x\leq y}}a_{\left(  x,y\right)  }=\sum_{y=1}^{n}\ \ \sum_{x=1}%
^{y}a_{\left(  x,y\right)  }.
\]

\end{corollary}

Visually speaking, this is saying that the entries of a triangular table of
the form%
\[%
\begin{array}
[c]{ccccc}%
a_{\left(  1,1\right)  } & a_{\left(  1,2\right)  } & \cdots & a_{\left(
1,n-1\right)  } & a_{\left(  1,n\right)  }\\
& a_{\left(  2,2\right)  } & \cdots & a_{\left(  2,n-1\right)  } & a_{\left(
2,n\right)  }\\
&  & \rotatebox{20}{$\ddots$} & \vdots & \vdots\\
&  &  & a_{\left(  n-1,n-1\right)  } & a_{\left(  n-1,n\right)  }\\
&  &  &  & a_{\left(  n,n\right)  }%
\end{array}
\]
can be summed in any order (row by row, column by column, or just
arbitrarily). This allows us to interchange summation signs if the index of
the outer sum appears as a bound (either lower or upper) of the inner sum.

Again, Corollary \ref{cor.fubini.triang2} follows easily from the finite
Fubini principle with a predicate.

Last time, we saw an application of one of our triangular Fubini principles.
See \S 1.6 in the 2019 notes for two other such applications.

\subsubsection{Interchange of infinite sums}

Time for a cautionary tale.

We have mostly been talking about finite sums so far. However, for
convenience, we have sometimes used infinite sums as well. Specifically, we
have used \textbf{essentially finite sums} -- i.e., sums that have only
finitely many nonzero addends.\footnote{For example, we have used such sums in
the proof of the binomial formula.}

Almost all rules of summation that apply to finite sums can be mindlessly
applied to essentially finite sums as well. For instance, the rule%
\[
\sum_{s\in S}\left(  a_{s}+b_{s}\right)  =\sum_{s\in S}a_{s}+\sum_{s\in
S}b_{s}%
\]
holds no matter whether the set $S$ is finite or infinite, as long as the two
sums $\sum_{s\in S}a_{s}$ and $\sum_{s\in S}b_{s}$ are essentially
finite.\footnote{We have actually used this in our proof of the binomial
formula.}

There is one exception: interchange of summations. Let us see what happens
when we try to interchange two essentially finite sums.

For any $x,y\in\mathbb{N}$, let%
\[
a_{\left(  x,y\right)  }=\left[  y=x\right]  -\left[  y=x+1\right]  .
\]
Then, the numbers $a_{\left(  x,y\right)  }$ can be arranged in an infinite
table, the first few rows and columns of which look as follows:%
\[%
\begin{tabular}
[c]{|c||c|c|c|c|c|}\hline
& $y=0$ & $y=1$ & $y=2$ & $y=3$ & $\cdots$\\\hline\hline
$x=0$ & $1$ & $-1$ &  &  & $\cdots$\\\hline
$x=1$ &  & $1$ & $-1$ &  & $\cdots$\\\hline
$x=2$ &  &  & $1$ & $-1$ & $\cdots$\\\hline
$x=3$ &  &  &  & $1$ & $\cdots$\\\hline
$\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ & $\ddots$\\\hline
\end{tabular}
\
\]
(the \textquotedblleft missing\textquotedblright\ entries are $0$'s).

Thus,%
\begin{align*}
\sum_{x\in\mathbb{N}}\ \ \sum_{y\in\mathbb{N}}a_{\left(  x,y\right)  }  &
=\underbrace{\sum_{y\in\mathbb{N}}a_{\left(  0,y\right)  }}%
_{\substack{=1+\left(  -1\right)  +0+0+0+\cdots\\=0}}+\underbrace{\sum
_{y\in\mathbb{N}}a_{\left(  1,y\right)  }}_{\substack{=0+1+\left(  -1\right)
+0+0+\cdots\\=0}}+\underbrace{\sum_{y\in\mathbb{N}}a_{\left(  2,y\right)  }%
}_{\substack{=0+0+1+\left(  -1\right)  +0+\cdots\\=0}}+\cdots\\
&  =0+0+0+\cdots=0,
\end{align*}
but%
\begin{align*}
\sum_{y\in\mathbb{N}}\ \ \sum_{x\in\mathbb{N}}a_{\left(  x,y\right)  }  &
=\underbrace{\sum_{x\in\mathbb{N}}a_{\left(  x,0\right)  }}%
_{\substack{=1+0+0+0+0+\cdots\\=1}}+\underbrace{\sum_{x\in\mathbb{N}%
}a_{\left(  x,1\right)  }}_{\substack{=\left(  -1\right)  +1+0+0+0+0+\cdots
\\=0}}+\underbrace{\sum_{x\in\mathbb{N}}a_{\left(  x,2\right)  }%
}_{\substack{=0+\left(  -1\right)  +1+0+0+0+\cdots\\=0}}+\cdots\\
&  =1+0+0+\cdots=1.
\end{align*}
All the sums involved here are essentially finite (each having at most two
nonzero addends!), but the results are not the same! So we cannot interchange
the $\sum_{x\in\mathbb{N}}$ and $\sum_{y\in\mathbb{N}}$ signs in this example.

\bigskip

This is scary. Can we ever interchange two infinite sums?

Yes, we can, but only if a certain extra requirement is satisfied. Namely, the
finite Fubini principle can be extended to infinite sums as long as the
\textquotedblleft\textbf{total sum}\textquotedblright\ $\sum\limits_{\left(
x,y\right)  \in X\times Y}a_{\left(  x,y\right)  }$ is essentially finite
(i.e., as long as only finitely many \textbf{pairs} $\left(  x,y\right)  \in
X\times Y$ satisfy $a_{\left(  x,y\right)  }\neq0$). In other words, we have
the following:

\begin{theorem}
[essentially finite Fubini principle]Let $X$ and $Y$ be two (not necessarily
finite!) sets. Let $a_{\left(  x,y\right)  }$ be a number for every $\left(
x,y\right)  \in X\times Y$. Assume that only finitely many \textbf{pairs}
$\left(  x,y\right)  \in X\times Y$ satisfy $a_{\left(  x,y\right)  }\neq0$.
Then,%
\[
\sum_{x\in X}\ \ \sum_{y\in Y}a_{\left(  x,y\right)  }=\sum_{\left(
x,y\right)  \in X\times Y}a_{\left(  x,y\right)  }=\sum_{y\in Y}\ \ \sum_{x\in
X}a_{\left(  x,y\right)  }.
\]

\end{theorem}

So, if the MHS\footnote{\textquotedblleft MHS\textquotedblright\ is short for
\textquotedblleft middle hand side\textquotedblright. This is how we refer to
the $b$ part in an equality chain of the form $a=b=c$.} of this equality is
well-defined, then the LHS\footnote{This is short for \textquotedblleft left
hand side\textquotedblright.} and the RHS\footnote{Guess what this is short
for.} are equal to it. However, if the MHS is not well-defined, then the LHS
and RHS need not be equal, even if they themselves happen to be well-defined!
This is the situation that we saw in the above scary example.

The upshot is: We can interchange two infinite summation signs $\sum_{x\in X}$
and $\sum_{y\in Y}$ provided that the corresponding $\sum\limits_{\left(
x,y\right)  \in X\times Y}$ sum is essentially finite.

\subsection{Counting permutations: an introduction}

Now, we return to counting maps. This time, we shall count \textbf{bijective}
maps from a set to itself; these are also known as \emph{permutations}.

\subsubsection{Permutations and derangements}

There are two different things called \textquotedblleft
permutations\textquotedblright. One is a kind of mappings (\textquotedblleft
active permutations\textquotedblright), and the other is a kind of lists
(\textquotedblleft passive permutations\textquotedblright). We shall here only
refer to the former as \textquotedblleft permutations\textquotedblright. (The
latter will later be called \textquotedblleft anagrams\textquotedblright.)
Here is the formal definition:

\begin{definition}
\label{def.perm}A \textbf{permutation} of a set $X$ means a bijection from $X$
to $X$.
\end{definition}

Recall that \textquotedblleft bijection\textquotedblright\ is short for
\textquotedblleft bijective map\textquotedblright\ (i.e., a map that is both
surjective and injective), which is also known as \textquotedblleft one-to-one
correspondence\textquotedblright. A bijective map is furthermore the same as
an invertible map (i.e., a map that has an inverse).

We shall use the two-line notation for maps. (That is, we shall encode a map
from a finite set $X$ to a set $Y$ by a two-row table, where the top row has
the elements of $X$ listed in it, and the bottom row has their corresponding
images under the map.)

Thus, for example,%
\[
\left(
\begin{array}
[c]{ccccc}%
0 & 1 & 5 & 7 & 9\\
1 & 7 & 9 & 0 & 5
\end{array}
\right)
\]
denotes the map from $\left\{  0,1,5,7,9\right\}  $ to $\left\{
0,1,5,7,9\right\}  $ that sends $0,1,5,7,9$ to $1,7,9,0,5$, respectively. This
map is a permutation of $\left\{  0,1,5,7,9\right\}  $, since it is bijective.
Meanwhile, the map%
\[
\left(
\begin{array}
[c]{ccccc}%
0 & 1 & 5 & 7 & 9\\
1 & 7 & 7 & 0 & 5
\end{array}
\right)
\]
is not a permutation (worse yet, it is neither injective nor surjective, since
$9$ is not in its image, while $7$ appears as an image twice).

The most obvious counting question that we can ask has a simple answer:

\begin{theorem}
\label{thm.perm.count-1}Let $n\in\mathbb{N}$. Let $X$ be an $n$-element set.
Then,%
\[
\left(  \text{\# of permutations of }X\right)  =n!.
\]

\end{theorem}

We shall prove this later, when we have more convenient terminology for the
proof. (The proof is easy to explain by waving one's hands, but formalizing it
takes some more work.)

\begin{example}
The $3$-element set $\left[  3\right]  $ has $3!=6$ permutations, whose
two-line notations are%
\begin{align*}
&  \left(
\begin{array}
[c]{ccc}%
1 & 2 & 3\\
1 & 2 & 3
\end{array}
\right)  ,\ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{ccc}%
1 & 2 & 3\\
1 & 3 & 2
\end{array}
\right)  ,\ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{ccc}%
1 & 2 & 3\\
2 & 1 & 3
\end{array}
\right)  ,\\
&  \left(
\begin{array}
[c]{ccc}%
1 & 2 & 3\\
2 & 3 & 1
\end{array}
\right)  ,\ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{ccc}%
1 & 2 & 3\\
3 & 1 & 2
\end{array}
\right)  ,\ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{ccc}%
1 & 2 & 3\\
3 & 2 & 1
\end{array}
\right)  .
\end{align*}

\end{example}

\bigskip

Let us next focus on a specific kind of permutations:

\begin{definition}
Let $X$ be a set.

\textbf{(a)} If $f:X\rightarrow X$ is a map, then a \textbf{fixed point} of
$f$ means an element $x\in X$ such that $f\left(  x\right)  =x$.

\textbf{(b)} A \textbf{derangement} of $X$ means a permutation of $X$ that has
no fixed points.
\end{definition}

\begin{example}
\textbf{(a)} The map $\left(
\begin{array}
[c]{ccccc}%
0 & 1 & 5 & 7 & 9\\
7 & 1 & 5 & 0 & 9
\end{array}
\right)  $ has fixed points $1$, $5$ and $9$. So it is not a derangement.

\textbf{(b)} The map $\left(
\begin{array}
[c]{ccccc}%
0 & 1 & 5 & 7 & 9\\
1 & 7 & 9 & 0 & 5
\end{array}
\right)  $ has no fixed points and is a permutation. So it is a derangement.

\textbf{(c)} Among the $6$ permutations of $\left[  3\right]  $, only two are
derangements, namely%
\[
\left(
\begin{array}
[c]{ccc}%
1 & 2 & 3\\
2 & 3 & 1
\end{array}
\right)  \ \ \ \ \ \ \ \ \ \ \text{and}\ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{ccc}%
1 & 2 & 3\\
3 & 1 & 2
\end{array}
\right)  .
\]

\end{example}

\subsubsection{Only the size counts}

How many derangements does a given $n$-element set have?

A first simplification is to restrict our focus to a specific $n$-element set,
namely $\left[  n\right]  $, because all $n$-element sets should be
interchangeable as far as their \# of derangements is concerned. This relies
on the following lemma:

\begin{lemma}
\label{lem.count.dera.X=n}Let $n\in\mathbb{N}$. Let $X$ be any $n$-element
set. Then,%
\[
\left(  \text{\# of derangements of }X\right)  =\left(  \text{\# of
derangements of }\left[  n\right]  \right)  .
\]

\end{lemma}

\begin{proof}
Informally, this is clear: The derangements of an $n$-element set should not
depend on the \textquotedblleft private life\textquotedblright\ of the
elements of this set. In other words, relabelling the set should just relabel
the derangements, without affecting their number.

Can we turn this into a formal proof? Yes, but surprisingly this takes some
work (mostly writing). I will restrict myself to an outline here, but the
details can be found in \S 1.7.2 of the 2019 notes. Essentially, we need to
fix a way to \textquotedblleft relabel\textquotedblright\ the $n$ elements of
our set $X$ as the numbers $1,2,\ldots,n$, and then use this \textquotedblleft
relabelling\textquotedblright\ to turn the derangements of $X$ into the
derangements of $\left[  n\right]  $.

The first of these two steps is easy. To \textquotedblleft
relabel\textquotedblright\ the elements of $X$ as the numbers $1,2,\ldots,n$
means (in rigorous mathematical language) to choose a bijection $\phi
:X\rightarrow\left[  n\right]  $. Such a bijection $\phi$ exists because the
two sets $X$ and $\left[  n\right]  $ have the same size (since both $X$ and
$\left[  n\right]  $ are $n$-element sets). Generally, there are many such
bijections $\phi$, and there is no reason to prefer one over another. We just
pick one such $\phi$ and stick with it. Thus, we can think of each element
$x\in X$ being \textquotedblleft relabelled\textquotedblright\ as the number
$\phi\left(  x\right)  \in\left[  n\right]  $.

Now to the second step: We have to use this bijection $\phi$ to turn each
derangement $\omega$ of $X$ into a derangement $\omega^{\prime}$ of $\left[
n\right]  $. This needs to be done in a bijective manner (so that each
$\omega$ gives rise to exactly one $\omega^{\prime}$ and vice versa). There is
an easy way to do this, using our \textquotedblleft
relabelling\textquotedblright\ bijection $\phi$: Namely, if
\[
\omega=\left(
\begin{array}
[c]{cccc}%
x_{1} & x_{2} & \cdots & x_{n}\\
y_{1} & y_{2} & \cdots & y_{n}%
\end{array}
\right)  :X\rightarrow X
\]
is a derangement of $X$ (written in two-line notation), then we set%
\[
\omega^{\prime}:=\left(
\begin{array}
[c]{cccc}%
\phi\left(  x_{1}\right)  & \phi\left(  x_{2}\right)  & \cdots & \phi\left(
x_{n}\right) \\
\phi\left(  y_{1}\right)  & \phi\left(  y_{2}\right)  & \cdots & \phi\left(
y_{n}\right)
\end{array}
\right)  :\left[  n\right]  \rightarrow\left[  n\right]
\]
(again, written in two-line notation), which is easily seen to be a
derangement of $\left[  n\right]  $. Notice that this $\omega^{\prime}$ can be
written more compactly as follows:%
\[
\omega^{\prime}=\phi\circ\omega\circ\phi^{-1}.
\]
You can convince yourself of this using the following picture (which shows a
situation in which $n=3$ and $X=\left\{  \text{cat},\text{ dog},\text{
fox}\right\}  $, and where we choose our \textquotedblleft
relabelling\textquotedblright\ bijection $\phi$ to relabel \textquotedblleft
cat\textquotedblright, \textquotedblleft dog\textquotedblright\ and
\textquotedblleft fox\textquotedblright\ as $1$, $2$ and $3$, respectively):%
\[%
%TCIMACRO{\TeXButton{tikz four eggs}{\begin{tikzpicture}
%\filldraw[fill=yellow!20!white] (0, 3) ellipse (1 and 2);
%\node(A1) at (0, 4) {$1$};
%\node(A2) at (0, 3) {$2$};
%\node(A3) at (0, 2) {$3$};
%\filldraw[fill=yellow!20!white] (3, 3) ellipse (1 and 2);
%\node(Aname) at (0, 0.6) {$\left[n\right]$};
%\node(B1) at (3, 4) {$1$};
%\node(B2) at (3, 3) {$2$};
%\node(B3) at (3, 2) {$3$};
%\node(Bname) at (3, 0.6) {$\left[n\right]$};
%\draw[->, very thick, darkgreen] (A1) -- (B2);
%\draw[->, very thick, darkgreen] (A2) -- (B3);
%\draw[->, very thick, darkgreen] (A3) -- (B1);
%\filldraw[fill=cyan!20!white] (0, 8) ellipse (1 and 2);
%\node(C1) at (0, 9) {cat};
%\node(C2) at (0, 8) {dog};
%\node(C3) at (0, 7) {fox};
%\node(Cname) at (0, 10.4) {$X$};
%\filldraw[fill=cyan!20!white] (3, 8) ellipse (1 and 2);
%\node(D1) at (3, 9) {cat};
%\node(D2) at (3, 8) {dog};
%\node(D3) at (3, 7) {fox};
%\node(Dname) at (3, 10.4) {$X$};
%\draw[->, very thick, darkgreen] (C1) -- (D2);
%\draw[->, very thick, darkgreen] (C2) -- (D3);
%\draw[->, very thick, darkgreen] (C3) -- (D1);
%\draw[->, very thick, red] (C1) edge[bend right=50] (A1);
%\draw[->, very thick, red] (C2) edge[bend right=50] (A2);
%\draw[->, very thick, red] (C3) edge[bend right=50] (A3);
%\draw[->, very thick, red] (D1) edge[bend left=50] (B1);
%\draw[->, very thick, red] (D2) edge[bend left=50] (B2);
%\draw[->, very thick, red] (D3) edge[bend left=50] (B3);
%\node(phinameL) at (-1.6, 5) {$\color{red}{\phi}$};
%\node(phinameR) at (4.6, 5) {$\color{red}{\phi}$};
%\node(oname) at (1.5, 8.8) {$\color{darkgreen}{\omega}$};
%\node(o'name) at (1.5, 1.8) {$\color{darkgreen}{\omega^{\prime}}$};
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=yellow!20!white] (0, 3) ellipse (1 and 2);
\node(A1) at (0, 4) {$1$};
\node(A2) at (0, 3) {$2$};
\node(A3) at (0, 2) {$3$};
\filldraw[fill=yellow!20!white] (3, 3) ellipse (1 and 2);
\node(Aname) at (0, 0.6) {$\left[n\right]$};
\node(B1) at (3, 4) {$1$};
\node(B2) at (3, 3) {$2$};
\node(B3) at (3, 2) {$3$};
\node(Bname) at (3, 0.6) {$\left[n\right]$};
\draw[->, very thick, darkgreen] (A1) -- (B2);
\draw[->, very thick, darkgreen] (A2) -- (B3);
\draw[->, very thick, darkgreen] (A3) -- (B1);
\filldraw[fill=cyan!20!white] (0, 8) ellipse (1 and 2);
\node(C1) at (0, 9) {cat};
\node(C2) at (0, 8) {dog};
\node(C3) at (0, 7) {fox};
\node(Cname) at (0, 10.4) {$X$};
\filldraw[fill=cyan!20!white] (3, 8) ellipse (1 and 2);
\node(D1) at (3, 9) {cat};
\node(D2) at (3, 8) {dog};
\node(D3) at (3, 7) {fox};
\node(Dname) at (3, 10.4) {$X$};
\draw[->, very thick, darkgreen] (C1) -- (D2);
\draw[->, very thick, darkgreen] (C2) -- (D3);
\draw[->, very thick, darkgreen] (C3) -- (D1);
\draw[->, very thick, red] (C1) edge[bend right=50] (A1);
\draw[->, very thick, red] (C2) edge[bend right=50] (A2);
\draw[->, very thick, red] (C3) edge[bend right=50] (A3);
\draw[->, very thick, red] (D1) edge[bend left=50] (B1);
\draw[->, very thick, red] (D2) edge[bend left=50] (B2);
\draw[->, very thick, red] (D3) edge[bend left=50] (B3);
\node(phinameL) at (-1.6, 5) {$\color{red}{\phi}$};
\node(phinameR) at (4.6, 5) {$\color{red}{\phi}$};
\node(oname) at (1.5, 8.8) {$\color{darkgreen}{\omega}$};
\node(o'name) at (1.5, 1.8) {$\color{darkgreen}{\omega^{\prime}}$};
\end{tikzpicture}%
%EndExpansion
\]


Thus, to each derangement $\omega$ of $X$, we have assigned a
\textquotedblleft corresponding\textquotedblright\ derangement $\omega
^{\prime}=\phi\circ\omega\circ\phi^{-1}$ of $\left[  n\right]  $. This
assignment is bijective -- i.e., each $\omega$ corresponds to a unique
$\omega^{\prime}$ and vice versa. In other words, we have obtained a bijection%
\begin{align*}
\left\{  \text{derangements of }X\right\}   &  \rightarrow\left\{
\text{derangements of }\left[  n\right]  \right\}  ,\\
\omega &  \mapsto\phi\circ\omega\circ\phi^{-1}.
\end{align*}
Indeed, this map is easily seen to be well-defined (you just need to show that
$\phi\circ\omega\circ\phi^{-1}$ is a derangement of $\left[  n\right]  $
whenever $\omega$ is a derangement of $X$), and its bijectivity follows from
observing that its inverse map is%
\begin{align*}
\left\{  \text{derangements of }\left[  n\right]  \right\}   &  \rightarrow
\left\{  \text{derangements of }X\right\}  ,\\
\omega^{\prime}  &  \mapsto\phi^{-1}\circ\omega^{\prime}\circ\phi.
\end{align*}
Thus, by the bijection principle, we get
\[
\left\vert \left\{  \text{derangements of }X\right\}  \right\vert =\left\vert
\left\{  \text{derangements of }\left[  n\right]  \right\}  \right\vert .
\]
In other words,
\[
\left(  \text{\# of derangements of }X\right)  =\left(  \text{\# of
derangements of }\left[  n\right]  \right)  .
\]
This proves Lemma \ref{lem.count.dera.X=n}.
\end{proof}

Lemma \ref{lem.count.dera.X=n} is not really specific to derangements. It is
merely an instance of a general principle, which I shall now state in a
semi-formal form:

\begin{statement}
\textbf{\textquotedblleft Isomorphism principle\textquotedblright%
\ (informal):} Assume that we are given a way to assign a number $f\left(
S\right)  $ to any finite set $S$, and this way does not depend on what the
elements of $S$ are (i.e., its definition works the same no matter whether the
elements of $S$ are numbers or tuples or maps or anything else). Let
$n\in\mathbb{N}$. Let $X$ be an $n$-element set. Then,%
\[
f\left(  X\right)  =f\left(  \left[  n\right]  \right)  .
\]

\end{statement}

Lemma \ref{lem.count.dera.X=n} is the particular case of this principle for%
\[
f\left(  S\right)  =\left(  \text{\# of derangements of }S\right)  .
\]
Similarly, we can apply the same principle to%
\begin{align*}
f\left(  S\right)   &  =\left(  \text{\# of subsets of }S\right)
,\ \ \ \ \ \ \ \ \ \ \text{or}\\
f\left(  S\right)   &  =\left(  \text{\# of }5\text{-element subsets of
}S\right)  ,\ \ \ \ \ \ \ \ \ \ \text{or}\\
f\left(  S\right)   &  =\left(  \text{\# of permutations of }S\right)
,\ \ \ \ \ \ \ \ \ \ \text{or}\\
f\left(  S\right)   &  =\left(  \text{\# of surjective maps }S\rightarrow
\left[  3\right]  \right)  ,\ \ \ \ \ \ \ \ \ \ \text{or}\\
f\left(  S\right)   &  =\sum_{T\subseteq S}\left\vert T\right\vert .
\end{align*}
But we cannot apply it to%
\[
f\left(  S\right)  =\left(  \text{\# of lacunar subsets of }S\right)  ,
\]
since the lacunarity of a set depends on the elements of this set (and, no
surprise, $f\left(  \left\{  1,3\right\}  \right)  $ is different from
$f\left(  \left[  2\right]  \right)  $).

I will not formally state the isomorphism principle, but every time I will
apply it, I hope it will be clear how it could be proved formally if one wants to.

\subsubsection{Intermezzo: OEIS}

So, in order to count derangements of any $n$-element set, it suffices to
count derangements of $\left[  n\right]  $. Let us try to do it.

\begin{definition}
\label{def.count.dera.Dn}For each $n\in\mathbb{N}$, let%
\[
D_{n}:=\left(  \text{\# of derangements of }\left[  n\right]  \right)  .
\]

\end{definition}

Here is a table of the first ten $D_{n}$'s:%
\[%
\begin{tabular}
[c]{|c||c|c|c|c|c|c|c|c|c|c|}\hline
$n$ & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ & $8$ & $9$\\\hline
$D_{n}$ & $1$ & $0$ & $1$ & $2$ & $9$ & $44$ & $265$ & $1854$ & $14833$ &
$133496$\\\hline
\end{tabular}
\ \
\]


What now? Is there any simple formula for $D_{n}$ ?

\bigskip

Here is a very modern method for solving counting problems, and more generally
for dealing with sequences of integers: You use the OEIS\ (short for
\textquotedblleft Online Encyclopedia of Integer Sequences\textquotedblright),
a search engine for integer sequences. It is available at
\url{https://oeis.org} and knows many thousands of sequences along with their
properties, formulas and references. When you have a sequence of integers you
want to recognize (and learn more about), you compute its first few entries,
then plug them into the OEIS, and finally check whether any of the results
fits your definition (or, barring that, if it still seems to result in the
same sequence). In our case, we quickly figure out that $\left(  D_{0}%
,D_{1},D_{2},\ldots\right)  $ is the sequence
\href{https://oeis.org/A000166}{A000166}, and several formulas are known for
it:%
\begin{align*}
D_{n} &  =n!\cdot\sum_{k=0}^{n}\dfrac{\left(  -1\right)  ^{k}}{k!};\\
D_{n} &  =\left\lfloor \dfrac{n!}{e}+\dfrac{1}{2}\right\rfloor
=\operatorname*{round}\dfrac{n!}{e}\ \ \ \ \ \ \ \ \ \ \text{for all }%
n\geq1\text{ }\left(  \text{where }e=\sum_{k=0}^{\infty}\dfrac{1}{k!}\right)
;\\
D_{n} &  =nD_{n-1}+\left(  -1\right)  ^{n}\ \ \ \ \ \ \ \ \ \ \text{for all
}n\geq1;\\
D_{n} &  =\left(  n-1\right)  \left(  D_{n-1}+D_{n-2}\right)
\ \ \ \ \ \ \ \ \ \ \text{for all }n\geq2;\\
&  \ldots
\end{align*}
We will eventually (in Lecture 20, Example 2) prove the first two of these formulas.


\end{document}