\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=Monday, December 12, 2022 20:34: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 }}
\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 20, version \today}
\ohead{page \thepage}
\cfoot{}
\begin{document}
\section*{Math 222 Fall 2022, Lecture 20: Binomial coefficients}

\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}}}

\setcounter{section}{1}

\section{Binomial coefficients (cont'd)}

\setcounter{subsection}{6}

\subsection{The principle of inclusion and exclusion (aka Sylvester's sieve
formula) (cont'd)}

\subsubsection{Applications}

Last time, we proved the Principle of Inclusion and Exclusion, which (in one
of its forms) says the following:

\setcounter{theo}{7}

\begin{theorem}
[Theorem, repeated for convenience]\label{thm.pie.bUU-repeat}Let
$n\in\mathbb{N}$. Let $U$ be a finite set. Let $A_{1},A_{2},\ldots,A_{n}$ be
$n$ subsets of $U$. Then,%
\begin{align*}
&  \left(  \text{\# of all }s\in U\text{ such that }s\notin A_{i}\text{ for
all }i\in\left[  n\right]  \right) \\
&  =\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\left(  \text{\# of all }s\in U\text{ such that }s\in
A_{i}\text{ for all }i\in I\right)  .
\end{align*}

\end{theorem}

\setcounter{theo}{12}

Here is yet another way to restate this theorem, which I find easier to
memorize (and thus also more convenient to apply):

\begin{statement}
\textbf{\textquotedblleft Rule-breaking interpretation\textquotedblright\ of
the Principle of Inclusion and Exclusion.}

Assume that we are given a finite set $U$, and we are given $n$ rules
(numbered $1,2,\ldots,n$) that each element of $U$ may or may not satisfy.
(For instance, a rule can say \textquotedblleft thou shalt be
even\textquotedblright\ (if $U$ is a set of numbers) or \textquotedblleft thou
shalt be nonempty\textquotedblright\ (if $U$ is a set of sets).)

Assume that, for each $I\subseteq\left[  n\right]  $, we know how many
elements $s\in U$ satisfy all rules in $I$ (but may or may not satisfy the
remaining rules). For example, this means that we know how many elements $s\in
U$ satisfy rules $2$, $3$ and $5$ simultaneously.

Then, we can compute the \# of elements $s\in U$ that violate all $n$ rules
$1,2,\ldots,n$ by the following formula:%
\begin{align*}
&  \left(  \text{\# of all }s\in U\text{ that violate all }n\text{ rules
}1,2,\ldots,n\right) \\
&  =\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\left(  \text{\# of all }s\in U\text{ that satisfy all rules in
}I\right)  .
\end{align*}

\end{statement}

(Indeed, this is just Theorem \ref{thm.pie.bUU-repeat}, applied to
$A_{i}=\left\{  s\in U\ \mid\ s\text{ satisfies rule }i\right\}  $.)

\bigskip

Now, let us use the Principle of Inclusion and Exclusion (in its
\textquotedblleft rule-breaking interpretation\textquotedblright) to count
several things that would otherwise be hard to count.

\bigskip

\textbf{Example 1: Counting surjections.} (See \S 2.9.4 in the 2019 notes for details.)

Let $m,n\in\mathbb{N}$. Let us compute $\operatorname*{sur}\left(  m,n\right)
$. As we recall, this is the \# of surjective maps (= surjections) from
$\left[  m\right]  $ to $\left[  n\right]  $.

We set $U=\left[  n\right]  ^{\left[  m\right]  }=\left\{  \text{all maps from
}\left[  m\right]  \text{ to }\left[  n\right]  \right\}  $. We want to impose
$n$ rules $1,2,\ldots,n$ on a map $s\in U$ in such a way that the surjective
maps will be precisely those maps that violate all $n$ rules $1,2,\ldots,n$.

We set rule $i$ to be \textquotedblleft thou shalt not take $i$ as a
value\textquotedblright. Then, a map $s:\left[  m\right]  \rightarrow\left[
n\right]  $ violates all rules $1,2,\ldots,n$ if and only if it takes each of
$1,2,\ldots,n$ as a value, i.e., if it is surjective. Hence,%
\begin{align}
&  \operatorname*{sur}\left(  m,n\right) \nonumber\\
&  =\left(  \text{\# of surjective maps }\left[  m\right]  \rightarrow\left[
n\right]  \right) \nonumber\\
&  =\left(  \text{\# of all }s\in U\text{ that violate all }n\text{ rules
}1,2,\ldots,n\right) \nonumber\\
&  =\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\left(  \text{\# of all }s\in U\text{ that satisfy all rules in
}I\right)  \label{eq.pie.apps.sur.1}%
\end{align}
(by the \textquotedblleft rule-breaking interpretation\textquotedblright\ of
the Principle of Inclusion and Exclusion).

Let us now compute the addends on the RHS of (\ref{eq.pie.apps.sur.1}).

We fix a subset $I$ of $\left[  n\right]  $. What is the \# of all $s\in U$
that satisfy all rules in $I$ ? This is just the \# of all maps $s:\left[
m\right]  \rightarrow\left[  n\right]  $ that take none of the $i\in I$ as a
value. These maps are essentially just the maps from $\left[  m\right]  $ to
$\left[  n\right]  \setminus I$. Thus, their \# is $\left\vert \left[
n\right]  \setminus I\right\vert ^{\left[  m\right]  }=\left(  n-\left\vert
I\right\vert \right)  ^{m}$. So we obtain%
\begin{equation}
\left(  \text{\# of all }s\in U\text{ that satisfy all rules in }I\right)
=\left(  n-\left\vert I\right\vert \right)  ^{m}. \label{eq.pie.apps.sur.2}%
\end{equation}


Forget that we fixed $I$. We thus have proved the equality
(\ref{eq.pie.apps.sur.2}) for every $I\subseteq\left[  n\right]  $. Thus,
(\ref{eq.pie.apps.sur.1}) becomes%
\begin{align*}
\operatorname*{sur}\left(  m,n\right)   &  =\sum_{I\subseteq\left[  n\right]
}\left(  -1\right)  ^{\left\vert I\right\vert }\underbrace{\left(  \text{\# of
all }s\in U\text{ that satisfy all rules in }I\right)  }_{\substack{=\left(
n-\left\vert I\right\vert \right)  ^{m}\\\text{(by (\ref{eq.pie.apps.sur.2}%
))}}}\\
&  =\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\left(  n-\left\vert I\right\vert \right)  ^{m}\\
&  =\sum_{k=0}^{n}\underbrace{\left(  \text{\# of subsets }I\subseteq\left[
n\right]  \text{ satisfying }\left\vert I\right\vert =k\right)  }_{=\dbinom
{n}{k}}\cdot\left(  -1\right)  ^{k}\left(  n-k\right)  ^{m}\\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{c}%
\text{here, we have split the sum according to}\\
\text{the value of }\left\vert I\right\vert \text{, and observed that all}\\
\text{subsets }I\text{ of }\left[  n\right]  \text{ satisfying }\left\vert
I\right\vert =k\text{\textsl{ }give identical}\\
\text{addends }\left(  -1\right)  ^{\left\vert I\right\vert }\left(
n-\left\vert I\right\vert \right)  ^{m}=\left(  -1\right)  ^{k}\left(
n-k\right)  ^{m}%
\end{array}
\right)  \\
&  =\sum_{k=0}^{n}\dbinom{n}{k}\cdot\left(  -1\right)  ^{k}\left(  n-k\right)
^{m}=\sum_{k=0}^{n}\left(  -1\right)  ^{k}\dbinom{n}{k}\left(  n-k\right)
^{m}\\
&  =\sum_{j=0}^{n}\left(  -1\right)  ^{n-j}\underbrace{\dbinom{n}{n-j}%
}_{=\dbinom{n}{j}}\left(  \underbrace{n-\left(  n-j\right)  }_{=j}\right)
^{m}\ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{c}%
\text{here, we substituted }n-j\\
\text{for }k\text{ in the sum}%
\end{array}
\right)  \\
&  =\sum_{j=0}^{n}\left(  -1\right)  ^{n-j}\dbinom{n}{j}j^{m}.
\end{align*}
Thus, we have proved the following:

\begin{theorem}
\label{thm.pie.apps.sur.formula}For any $m,n\in\mathbb{N}$, we have%
\[
\operatorname*{sur}\left(  m,n\right)  =\sum_{k=0}^{n}\left(  -1\right)
^{k}\dbinom{n}{k}\left(  n-k\right)  ^{m}=\sum_{j=0}^{n}\left(  -1\right)
^{n-j}\dbinom{n}{j}j^{m}.
\]

\end{theorem}

This is the optimal answer to the question of computing $\operatorname*{sur}%
\left(  m,n\right)  $; there is no simpler formula. Note that a few
corollaries spring out:

\begin{corollary}
\label{cor.pie.apps.sur.cors}Let $n\in\mathbb{N}$. Then:

\textbf{(a)} We have $\sum\limits_{k=0}^{n}\left(  -1\right)  ^{k}\dbinom
{n}{k}\left(  n-k\right)  ^{m}=0$ for any $m\in\mathbb{N}$ such that $m<n$.

\textbf{(b)} We have $\sum\limits_{k=0}^{n}\left(  -1\right)  ^{k}\dbinom
{n}{k}\left(  n-k\right)  ^{n}=n!$.

\textbf{(c)} We have $\sum\limits_{k=0}^{n}\left(  -1\right)  ^{k}\dbinom
{n}{k}\left(  n-k\right)  ^{m}\geq0$ for any $m\in\mathbb{N}$.

\textbf{(d)} The number $\sum\limits_{k=0}^{n}\left(  -1\right)  ^{k}%
\dbinom{n}{k}\left(  n-k\right)  ^{m}$ is divisible by $n!$ for any
$m\in\mathbb{N}$.
\end{corollary}

\begin{proof}
Theorem \ref{thm.pie.apps.sur.formula} yields that $\sum_{k=0}^{n}\left(
-1\right)  ^{k}\dbinom{n}{k}\left(  n-k\right)  ^{m}=\operatorname*{sur}%
\left(  m,n\right)  $. Hence,

\begin{itemize}
\item Corollary \ref{cor.pie.apps.sur.cors} \textbf{(a)} follows from
Proposition 2.4.10 \textbf{(f)} in Lecture 16.

\item Corollary \ref{cor.pie.apps.sur.cors} \textbf{(b)} follows from
Corollary 2.4.13 \textbf{(a)} in Lecture 17.

\item Corollary \ref{cor.pie.apps.sur.cors} \textbf{(c)} follows from
$\operatorname*{sur}\left(  m,n\right)  \geq0$, which is obvious.

\item Corollary \ref{cor.pie.apps.sur.cors} \textbf{(d)} follows from
Corollary 2.4.13 \textbf{(b)} in Lecture 17.
\end{itemize}

(Note that none of the four parts of Corollary \ref{cor.pie.apps.sur.cors} is
obvious algebraically!)
\end{proof}

\bigskip

\textbf{Example 2.} (See \S 2.9.5 in the 2019 notes for details.)

Recall that a \textbf{derangement} of a set $X$ means a permutation of $X$
that has no fixed points (i.e., a permutation $s$ of $X$ such that $s\left(
x\right)  \neq x$ for any $x\in X$).

We let $D_{n}$ denote the \# of derangements of $\left[  n\right]  $ for each
$n\in\mathbb{N}$. Let's compute $D_{n}$. (We discussed these numbers $D_{n}$
in \S 1.7.3 in Lecture 12; let us now see if we can derive some of the
formulas for $D_{n}$.)

Fix $n\in\mathbb{N}$. Let $U$ be the set of all permutations of $\left[
n\right]  $. We want to impose $n$ rules $1,2,\ldots,n$ on a permutation $s\in
U$ in such a way that the derangements will be precisely the permutations $s$
that violate all $n$ rules $1,2,\ldots,n$.

Namely, rule $i$ says \textquotedblleft thou shalt send $i$ to $i$%
\textquotedblright. Violating all these $n$ rules (for a permutation of
$\left[  n\right]  $) means sending no $i$ to $i$, which means being a
derangement. Thus,%
\begin{align}
D_{n}  &  =\left(  \text{\# of all derangements of }\left[  n\right]  \right)
\nonumber\\
&  =\left(  \text{\# of all }s\in U\text{ that violate all }n\text{ rules
}1,2,\ldots,n\right) \nonumber\\
&  =\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\left(  \text{\# of all }s\in U\text{ that satisfy all rules in
}I\right)  \label{eq.pie.apps.der.1}%
\end{align}
(by the \textquotedblleft rule-breaking interpretation\textquotedblright\ of
the Principle of Inclusion and Exclusion).

Again, we now need to compute the addends on the RHS.

So we fix a subset $I$ of $\left[  n\right]  $, and we try to find the \# of
all permutations $s\in U$ that satisfy all rules in $I$. For instance, if
$I=\left\{  2,5\right\}  $, then this is the \# of all permutations $s$ of
$\left[  n\right]  $ that satisfy $s\left(  2\right)  =2$ and $s\left(
5\right)  =5$. How many such permutations are there?

If a permutation $s$ of $\left[  n\right]  $ satisfies $s\left(  2\right)  =2$
and $s\left(  5\right)  =5$, then it has to permute the remaining elements of
$\left[  n\right]  $ (that is, the elements of $\left[  n\right]
\setminus\left\{  2,5\right\}  $) among each other; i.e., its restriction to
$\left[  n\right]  \setminus\left\{  2,5\right\}  $ has to be a permutation of
$\left[  n\right]  \setminus\left\{  2,5\right\}  $ (because the values $2$
and $5$ are already taken on the inputs $2$ and $5$, and a permutation cannot
take the same value twice). Thus, the \# of all permutations $s$ of $\left[
n\right]  $ that satisfy $s\left(  2\right)  =2$ and $s\left(  5\right)  =5$
is the \# of all permutations of $\left[  n\right]  \setminus\left\{
2,5\right\}  $. But the latter \# is $\left(  n-2\right)  !$ (by Theorem 1.7.2
in Lecture 12, since $\left[  n\right]  \setminus\left\{  2,5\right\}  $ is an
$\left(  n-2\right)  $-element set).

More generally, for any subset $I$ of $\left[  n\right]  $, a permutation $s$
of $\left[  n\right]  $ that satisfies all rules in $I$ is essentially just a
permutation of the set $\left[  n\right]  \setminus I$ (because it sends each
element of $I$ to itself, and thus must permute the elements of $\left[
n\right]  \setminus I$ among each other). Hence, the \# of the former
permutations equals the \# of the latter permutations. In other words,%
\begin{align}
&  \left(  \text{\# of all }s\in U\text{ that satisfy all rules in }I\right)
\nonumber\\
&  =\left(  \text{\# of all permutations of }\left[  n\right]  \setminus
I\right) \nonumber\\
&  =\left(  n-\left\vert I\right\vert \right)  ! \label{eq.pie.apps.der.2}%
\end{align}
(by Theorem 1.7.2 in Lecture 12, since $\left[  n\right]  \setminus I$ is an
$\left(  n-\left\vert I\right\vert \right)  $-element set).

Now, forget that we fixed $I$. We thus have proved (\ref{eq.pie.apps.der.2})
for every subset $I$ of $\left[  n\right]  $. Thus, (\ref{eq.pie.apps.der.1})
becomes%
\begin{align*}
D_{n} &  =\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\underbrace{\left(  \text{\# of all }s\in U\text{ that satisfy
all rules in }I\right)  }_{\substack{=\left(  n-\left\vert I\right\vert
\right)  !\\\text{(by (\ref{eq.pie.apps.der.2}))}}}\\
&  =\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\left(  n-\left\vert I\right\vert \right)  !\\
&  =\sum_{k=0}^{n}\underbrace{\left(  \text{\# of subsets }I\subseteq\left[
n\right]  \text{ satisfying }\left\vert I\right\vert =k\right)  }_{=\dbinom
{n}{k}}\cdot\left(  -1\right)  ^{k}\left(  n-k\right)  !\\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{c}%
\text{here, we have split the sum according to}\\
\text{the value of }\left\vert I\right\vert \text{, and observed that all}\\
\text{subsets }I\text{ of }\left[  n\right]  \text{ satisfying }\left\vert
I\right\vert =k\text{\textsl{ }give identical}\\
\text{addends }\left(  -1\right)  ^{\left\vert I\right\vert }\left(
n-\left\vert I\right\vert \right)  !=\left(  -1\right)  ^{k}\left(
n-k\right)  !
\end{array}
\right)  \\
&  =\sum_{k=0}^{n}\dbinom{n}{k}\left(  -1\right)  ^{k}\left(  n-k\right)
!=\sum_{k=0}^{n}\left(  -1\right)  ^{k}\underbrace{\dbinom{n}{k}\left(
n-k\right)  !}_{\substack{=\dfrac{n!}{k!}\\\text{(since }\dbinom{n}{k}%
=\dfrac{n!}{k!\cdot\left(  n-k\right)  !}\text{)}}}\\
&  =\sum_{k=0}^{n}\left(  -1\right)  ^{k}\dfrac{n!}{k!}=n!\cdot\sum_{k=0}%
^{n}\dfrac{\left(  -1\right)  ^{k}}{k!}.
\end{align*}
So we have proved the following:

\begin{theorem}
\label{thm.pie.apps.der.formula}Let $n\in\mathbb{N}$. Then, the \# of
derangements of $\left[  n\right]  $ is%
\begin{equation}
D_{n}=\sum_{k=0}^{n}\left(  -1\right)  ^{k}\dbinom{n}{k}\left(  n-k\right)
!=n!\cdot\sum_{k=0}^{n}\dfrac{\left(  -1\right)  ^{k}}{k!}.
\label{eq.thm.pie.apps.der.formula.eq}%
\end{equation}

\end{theorem}

We can transform this expression even further, if we recall a few facts from
real analysis. Let $e\approx2.718\ldots$ be Euler's number (well, one of the
many numbers that bear Euler's name). It is well-known that%
\[
e^{x}=\exp x=\sum_{k=0}^{\infty}\dfrac{x^{k}}{k!}\ \ \ \ \ \ \ \ \ \ \text{for
any }x\in\mathbb{R}.
\]
Applying this to $x=-1$, we obtain%
\begin{equation}
e^{-1}=\sum_{k=0}^{\infty}\dfrac{\left(  -1\right)  ^{k}}{k!}.
\label{eq.thm.pie.apps.der.formula.cor0}%
\end{equation}
The infinite sum on the RHS here resembles the finite sum on the RHS of
(\ref{eq.thm.pie.apps.der.formula.eq}). And indeed, the two sums are very
close to one another. To wit, for any $n\in\mathbb{N}$, we have%
\begin{equation}
\sum_{k=0}^{\infty}\dfrac{\left(  -1\right)  ^{k}}{k!}-\sum_{k=0}^{n}%
\dfrac{\left(  -1\right)  ^{k}}{k!}=\sum_{k=n+1}^{\infty}\dfrac{\left(
-1\right)  ^{k}}{k!}. \label{eq.thm.pie.apps.der.formula.cor1}%
\end{equation}
In view of (\ref{eq.thm.pie.apps.der.formula.cor0}) and
(\ref{eq.thm.pie.apps.der.formula.eq}), we can rewrite this as%
\begin{equation}
e^{-1}-\dfrac{D_{n}}{n!}=\sum_{k=n+1}^{\infty}\dfrac{\left(  -1\right)  ^{k}%
}{k!}. \label{eq.thm.pie.apps.der.formula.cor1b}%
\end{equation}


The RHS of this equality looks like it is very small (after all, the
factorials $k!$ grow very quickly, so their reciprocals $\dfrac{1}{k!}$
quickly get microscopic). How small exactly? There is a nice (and easily
proved) theorem in analysis that if $a_{0},a_{1},a_{2},\ldots$ are positive
real numbers satisfying $a_{0}>a_{1}>a_{2}>a_{3}>\cdots$, then $\left\vert
\sum_{k=m}^{\infty}\left(  -1\right)  ^{k}a_{k}\right\vert <a_{m}$ for any
$m\in\mathbb{N}$. Applying this to $a_{k}=\dfrac{1}{k!}$ and $m=n+1$, we
obtain%
\[
\left\vert \sum_{k=n+1}^{\infty}\dfrac{\left(  -1\right)  ^{k}}{k!}\right\vert
<\dfrac{1}{\left(  n+1\right)  !}=\dfrac{1}{n!\cdot\left(  n+1\right)  }.
\]
If $n\geq1$, then this becomes%
\begin{equation}
\left\vert \sum_{k=n+1}^{\infty}\dfrac{\left(  -1\right)  ^{k}}{k!}\right\vert
<\dfrac{1}{n!\cdot\left(  n+1\right)  }\leq\dfrac{1}{n!\cdot2}
\label{eq.thm.pie.apps.der.formula.cor2}%
\end{equation}
(since $n\geq1$ entails $n+1\geq2$). In view of
(\ref{eq.thm.pie.apps.der.formula.cor1b}), this can be rewritten as%
\[
\left\vert e^{-1}-\dfrac{D_{n}}{n!}\right\vert <\dfrac{1}{n!\cdot2}.
\]
Multiplying this equality by the positive real $n!$, we obtain%
\[
\left\vert n!\cdot e^{-1}-D_{n}\right\vert <\dfrac{1}{2}.
\]
In other words, the integer $D_{n}$ is less than $\dfrac{1}{2}$ away from the
real number $n!\cdot e^{-1}$ (provided that $n\geq1$). Hence, $D_{n}$ is the
nearest integer to the real number $n!\cdot e^{-1}=\dfrac{n!}{e}$. We can
rewrite this as follows:%
\[
D_{n}=\operatorname*{round}\dfrac{n!}{e},
\]
where $\operatorname*{round}x$ denotes the nearest integer to a given real
number $x$. Thus, we have proved the following:

\begin{theorem}
\label{thm.pie.apps.der.n!/e}For any integer $n\geq1$, we have%
\[
D_{n}=\operatorname*{round}\dfrac{n!}{e}.
\]

\end{theorem}

This strange formula for the \# of derangements is suddenly not mysterious any more!

Back in Lecture 12, we have also stated two recursive formulas for $D_{n}$:%
\begin{align*}
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.
\end{align*}
These formulas can be derived purely algebraically from Theorem
\ref{thm.pie.apps.der.formula}. (This is a fun exercise; for the solution, see
Exercise 2.9.4 in the 2019 notes.)

\begin{fineprint}
\begin{remark}
From Theorem \ref{thm.pie.apps.der.n!/e}, we can easily derive the famous
result that the number $e$ is irrational.

Indeed, assume the contrary. Thus, $e=n/q$ for some positive integers $n$ and
$q$. Consider these $n$ and $q$. Then, $\dfrac{n!}{e}=\dfrac{n!}{n/q}%
=q\cdot\dfrac{n!}{n}=q\cdot\left(  n-1\right)  !$ is an integer. Hence,
$\operatorname*{round}\dfrac{n!}{e}=\dfrac{n!}{e}$, so that Theorem
\ref{thm.pie.apps.der.n!/e} yields $D_{n}=\operatorname*{round}\dfrac{n!}%
{e}=\dfrac{n!}{e}$.

Also, from $\left(  n+1\right)  !=\left(  n+1\right)  \cdot n!$, we obtain
$\dfrac{\left(  n+1\right)  !}{e}=\left(  n+1\right)  \cdot\underbrace{\dfrac
{n!}{e}}_{=q\cdot\left(  n-1\right)  !}=\left(  n+1\right)  \cdot
q\cdot\left(  n-1\right)  !$, which is an integer as well. Thus,
$\operatorname*{round}\dfrac{\left(  n+1\right)  !}{e}=\dfrac{\left(
n+1\right)  !}{e}$. Hence, Theorem \ref{thm.pie.apps.der.n!/e} (applied to
$n+1$ instead of $n$) yields
\begin{align*}
D_{n+1}  & =\operatorname*{round}\dfrac{\left(  n+1\right)  !}{e}%
=\dfrac{\left(  n+1\right)  !}{e}=\left(  n+1\right)  \cdot\underbrace{\dfrac
{n!}{e}}_{=D_{n}}=\left(  n+1\right)  \cdot D_{n}\\
& =\underbrace{\left(  n+1\right)  \cdot n!}_{=\left(  n+1\right)  !}\cdot
\sum_{k=0}^{n}\dfrac{\left(  -1\right)  ^{k}}{k!}\ \ \ \ \ \ \ \ \ \ \left(
\text{by (\ref{eq.thm.pie.apps.der.formula.eq})}\right)  \\
& =\left(  n+1\right)  !\cdot\sum_{k=0}^{n}\dfrac{\left(  -1\right)  ^{k}}%
{k!}.
\end{align*}
Comparing this with%
\[
D_{n+1}=\left(  n+1\right)  !\cdot\sum_{k=0}^{n+1}\dfrac{\left(  -1\right)
^{k}}{k!}\ \ \ \ \ \ \ \ \ \ \left(  \text{by
(\ref{eq.thm.pie.apps.der.formula.eq}), applied to }n+1\text{ instead of
}n\right)  ,
\]
we obtain $\sum_{k=0}^{n+1}\dfrac{\left(  -1\right)  ^{k}}{k!}=\sum_{k=0}%
^{n}\dfrac{\left(  -1\right)  ^{k}}{k!}$. This entails $\dfrac{\left(
-1\right)  ^{n+1}}{\left(  n+1\right)  !}=0$, which is absurd. This
contradiction shows that our assumption was false, so that $e$ is indeed irrational.
\end{remark}
\end{fineprint}

\bigskip

\textbf{Example 3.} (See \S 2.9.6 in the 2019 notes for details.)

The following number-theoretical result is also due to Euler:\footnote{Recall
that two integers $a$ and $b$ are said to be \textbf{coprime} (to one another)
if $\gcd\left(  a,b\right)  =1$.}

\begin{theorem}
\label{thm.pie.apps.tot.formula}Let $c$ be a positive integer with prime
factorization%
\[
c=p_{1}^{a_{1}}p_{2}^{a_{2}}\cdots p_{n}^{a_{n}},
\]
where $p_{1},p_{2},\ldots,p_{n}$ are distinct primes, and where $a_{1}%
,a_{2},\ldots,a_{n}$ are positive integers. Then,%
\begin{align*}
&  \left(  \text{\# of all }s\in\left[  c\right]  \text{ that are coprime to
}c\right) \\
&  =c\cdot\prod_{i=1}^{n}\left(  1-\dfrac{1}{p_{i}}\right)  =\prod_{i=1}%
^{n}\left(  p_{i}^{a_{i}}-p_{i}^{a_{i}-1}\right)  .
\end{align*}

\end{theorem}

Note that the \# of all $s\in\left[  c\right]  $ that are coprime to $c$ is
usually denoted by $\phi\left(  c\right)  $, and the map $\phi:\left\{
1,2,3,\ldots\right\}  \rightarrow\mathbb{N}$ that sends each $c$ to
$\phi\left(  c\right)  $ is known as \textbf{Euler's totient function}.

\begin{example}
Let $c=18$. Then, the prime factorization of $c$ is $c=2^{1}\cdot3^{2}$. Thus,
Theorem \ref{thm.pie.apps.tot.formula} claims that%
\begin{align*}
&  \left(  \text{\# of all }s\in\left[  18\right]  \text{ that are coprime to
}18\right) \\
&  =18\cdot\left(  1-\dfrac{1}{2}\right)  \cdot\left(  1-\dfrac{1}{3}\right)
=\left(  2^{1}-2^{0}\right)  \cdot\left(  3^{2}-3^{1}\right)  .
\end{align*}
And indeed, both sides of this equality are $6$. The six numbers $s\in\left[
18\right]  $ that are coprime to $18$ are $1,5,7,11,13,17$.
\end{example}

Theorem \ref{thm.pie.apps.tot.formula} is proved in most textbooks on number
theory. Let us, however, outline a proof using the PIE. This proof will
heavily use \textbf{Euclid's lemma}, which (in one of its forms) says that if
a prime $p$ divides a product $b_{1}b_{2}\cdots b_{k}$ of some integers
$b_{1},b_{2},\ldots,b_{k}$, then $p$ must divide (at least) one of the factors
$b_{1},b_{2},\ldots,b_{k}$. This yields, in particular, that if a prime $p$
divides an integer $c$ whose prime factorization is $c=p_{1}^{a_{1}}%
p_{2}^{a_{2}}\cdots p_{n}^{a_{n}}$, then $p$ must be one of $p_{1}%
,p_{2},\ldots,p_{n}$. We will also use the \textbf{product divisibility
lemma}, which says that if several \textbf{distinct} \textbf{prime} numbers
$q_{1},q_{2},\ldots,q_{k}$ all divide a given integer $s$, then their product
$q_{1}q_{2}\cdots q_{k}$ also divides $s$. (More generally, this still holds
if we replace \textquotedblleft distinct prime\textquotedblright\ by
\textquotedblleft pairwise coprime\textquotedblright.)

\begin{proof}
[Proof of Theorem \ref{thm.pie.apps.tot.formula} (sketched).]Let $U=\left[
c\right]  $. A number $s\in U$ is coprime to $c$ if and only if it is not
divisible by any of the primes $p_{1},p_{2},\ldots,p_{n}$ (this follows from
Euclid's lemma stated in the preceding paragraph). This means that $s$
violates all $n$ rules $1,2,\ldots,n$, where rule $i$ says \textquotedblleft
thou shalt be divisible by $p_{i}$\textquotedblright. Hence,%
\begin{align}
&  \left(  \text{\# of all }s\in\left[  c\right]  \text{ that are coprime to
}c\right) \nonumber\\
&  =\left(  \text{\# of all }s\in\left[  c\right]  \text{ that violate all
}n\text{ rules }1,2,\ldots,n\right) \nonumber\\
&  =\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\left(  \text{\# of all }s\in\left[  c\right]  \text{ that
satisfy all rules in }I\right)  \label{pf.thm.pie.apps.tot.formula.1}%
\end{align}
(by the \textquotedblleft rule-breaking interpretation\textquotedblright\ of
the Principle of Inclusion and Exclusion).

Now, let $I$ be a subset of $\left[  n\right]  $. Then, an integer
$s\in\left[  c\right]  $ satisfies all rules in $I$ if and only if it is
divisible by all primes $p_{i}$ with $i\in I$; but this is equivalent to $s$
being divisible by $\prod\limits_{i\in I}p_{i}$ (here we are using the product
divisibility lemma). Therefore,%
\begin{align}
&  \left(  \text{\# of all }s\in\left[  c\right]  \text{ that satisfy all
rules in }I\right) \nonumber\\
&  =\left(  \text{\# of all }s\in\left[  c\right]  \text{ that are divisible
by }\prod\limits_{i\in I}p_{i}\right)  . \label{pf.thm.pie.apps.tot.formula.2}%
\end{align}
However, $\prod\limits_{i\in I}p_{i}$ is a divisor of $c$. Therefore, the
numbers $s\in\left[  c\right]  $ that are divisible by $\prod\limits_{i\in
I}p_{i}$ are the numbers%
\[
\prod\limits_{i\in I}p_{i},\ \ 2\prod\limits_{i\in I}p_{i},\ \ 3\prod
\limits_{i\in I}p_{i},\ \ \ldots,\ \ c.
\]
These are $\dfrac{c}{\prod\limits_{i\in I}p_{i}}$ many numbers. Therefore,%
\[
\left(  \text{\# of all }s\in\left[  c\right]  \text{ that are divisible by
}\prod\limits_{i\in I}p_{i}\right)  =\dfrac{c}{\prod\limits_{i\in I}p_{i}}.
\]
Hence, (\ref{pf.thm.pie.apps.tot.formula.2}) can be rewritten as%
\begin{align}
&  \left(  \text{\# of all }s\in\left[  c\right]  \text{ that satisfy all
rules in }I\right) \nonumber\\
&  =\dfrac{c}{\prod\limits_{i\in I}p_{i}}.
\label{pf.thm.pie.apps.tot.formula.3}%
\end{align}


Forget that we have fixed $I$. We thus have proved
(\ref{pf.thm.pie.apps.tot.formula.3}) for each subset $I$ of $\left[
n\right]  $. Now, (\ref{pf.thm.pie.apps.tot.formula.1}) becomes%
\begin{align}
&  \left(  \text{\# of all }s\in\left[  c\right]  \text{ that are coprime to
}c\right) \nonumber\\
&  =\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\underbrace{\left(  \text{\# of all }s\in\left[  c\right]
\text{ that satisfy all rules in }I\right)  }_{\substack{=\dfrac{c}%
{\prod\limits_{i\in I}p_{i}}\\\text{(by (\ref{pf.thm.pie.apps.tot.formula.3}%
))}}}\nonumber\\
&  =\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\dfrac{c}{\prod\limits_{i\in I}p_{i}}=c\cdot\sum_{I\subseteq
\left[  n\right]  }\left(  -1\right)  ^{\left\vert I\right\vert }\dfrac
{1}{\prod\limits_{i\in I}p_{i}}\nonumber\\
&  =c\cdot\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\prod\limits_{i\in I}\dfrac{1}{p_{i}}.
\label{pf.thm.pie.apps.tot.formula.4}%
\end{align}


The RHS of this equality turns out to be simplifiable. Indeed, for any $n$
numbers $a_{1},a_{2},\ldots,a_{n}$, we have%
\[
\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\prod\limits_{i\in I}a_{i}=\left(  1-a_{1}\right)  \left(
1-a_{2}\right)  \cdots\left(  1-a_{n}\right)
\]
(this is not hard to see by expanding the product on the RHS\footnote{For
example, for $n=3$, we have $\left(  1-a_{1}\right)  \left(  1-a_{2}\right)
\left(  1-a_{3}\right)  =1-a_{1}-a_{2}-a_{3}+a_{1}a_{2}+a_{1}a_{3}+a_{2}%
a_{3}-a_{1}a_{2}a_{3}$, which is precisely $\sum_{I\subseteq\left[  3\right]
}\left(  -1\right)  ^{\left\vert I\right\vert }\prod\limits_{i\in I}a_{i}$.
For a formal proof, see Lemma 2.9.21 \textbf{(b)} in the 2019 notes.}).
Applying this to $a_{i}=\dfrac{1}{p_{i}}$, we obtain%
\[
\sum_{I\subseteq\left[  n\right]  }\left(  -1\right)  ^{\left\vert
I\right\vert }\prod\limits_{i\in I}\dfrac{1}{p_{i}}=\left(  1-\dfrac{1}{p_{1}%
}\right)  \left(  1-\dfrac{1}{p_{2}}\right)  \cdots\left(  1-\dfrac{1}{p_{n}%
}\right)  =\prod_{i=1}^{n}\left(  1-\dfrac{1}{p_{i}}\right)  .
\]
Hence, we can rewrite (\ref{pf.thm.pie.apps.tot.formula.4}) as%
\[
\left(  \text{\# of all }s\in\left[  c\right]  \text{ that are coprime to
}c\right)  =c\cdot\prod_{i=1}^{n}\left(  1-\dfrac{1}{p_{i}}\right)  .
\]
We can rewrite this further:%
\begin{align*}
&  \left(  \text{\# of all }s\in\left[  c\right]  \text{ that are coprime to
}c\right)  \\
&  =\underbrace{c}_{\substack{=p_{1}^{a_{1}}p_{2}^{a_{2}}\cdots p_{n}^{a_{n}%
}\\=\prod_{i=1}^{n}p_{i}^{a_{i}}}}\cdot\prod_{i=1}^{n}\left(  1-\dfrac
{1}{p_{i}}\right)  =\left(  \prod_{i=1}^{n}p_{i}^{a_{i}}\right)  \cdot
\prod_{i=1}^{n}\left(  1-\dfrac{1}{p_{i}}\right)  =\prod_{i=1}^{n}%
\underbrace{\left(  p_{i}^{a_{i}}\left(  1-\dfrac{1}{p_{i}}\right)  \right)
}_{=p_{i}^{a_{i}}-p_{i}^{a_{i}-1}}\\
&  =\prod_{i=1}^{n}\left(  p_{i}^{a_{i}}-p_{i}^{a_{i}-1}\right)  .
\end{align*}
This completes the proof of Theorem \ref{thm.pie.apps.tot.formula}.
\end{proof}


\end{document}