% vim: tw=50
% 27/01/2022 11AM

\begin{proof}
    Use induction $n^{-1} \mapsto n$. For $n = 2$,
    check Example Sheet 1, Q4(e). For the
    inductive step:
    \begin{align*}
        \PP \left( \bigcup_{i = 1}^n A_i \right)
        &= \PP \left( \left( \bigcup_{i = 1}^{n -
        1} A_i \right) \cup A_n \right)  \\
        &= \PP \left( \bigcup_{i = 1}^{n - 1} A_i
        \right) + \PP (A_n) - \PP \left( \left(
        \bigcup_{i = 1}^{n - 1} A_i \right) \cap
        A_n \right)
    \end{align*}
    Idea:
    \[ \left( \bigcup_{i = 1}^{n - 1} A_i \right)
    \cap A_n = \bigcup_{i = 1}^{n - 1} (A_i \cap
    A_n) \]
    \[ \implies \bigcap_{i \in J} (A_i \cap A_n) =
    \bigcap_{i \in J \cup \{n\}} A_i \]
    ($J \subset \{1, \dots, n - 1\}$).
    \begin{align*}
        \PP \left( \bigcup_{i = 1}^n A_i \right)
        &= \sum_{\substack{J \subset \{1, \dots, n
        - 1\}\\J \neq \emptyset}} (-1)^{|J| + 1} \PP
        \left( \bigcap_{i \in J} A_i \right) +
        \PP(A_n) - \sum_{\substack{J \subset \{1,
        \dots, n - 1\}\\J \neq \emptyset}} (-1)^{|J| +
        1} \PP \left( \bigcap_{i \in J \cup \{n\}} A_i
        \right) \\
        &= \sum_{\substack{I \subset \{1, \dots, n
        - 1\}\\I \neq \emptyset}} (-1)^{|I| + 1}
        \PP \left( \bigcap_{i \in I} A_i \right) +
        \PP (A_n) + \sum_{\substack{I \subset \{1,
        \dots, n\}\\n \in I, |I| \ge 2}} (-1)^{|I|
        + 1} \PP \left( \bigcap_{i \in I} A_i
        \right) \\
        &= \sum_{\substack{I \subset \{1, \dots,
        n\}\\I \neq \emptyset}} (-1)^{|I| + 1} \PP
        \left( \bigcap_{i \in I} A_i \right)
    \end{align*}
    Where $J \cup \{n\} \mapsto I$, so $-(-1)^{|J| +
    1} \mapsto (-1)^{|I|}$.
\end{proof}

\subsubsection*{Bonferroni Inequalities}

\ul{Question}: What if you \emph{truncate}
Inclusion-Exclusion Principle? \\
Recall: $\PP (\cup A_i) \le \sum \PP(A_i)$
(\emph{union bound}).
\begin{itemize}
    \item When $r$ is even:
        \[ \PP \left( \bigcup_{i = 1}^n A_i
        \right) \le \sum_{k = 1}^r (-1)^{k +
        1} \sum_{i_1 < \cdots < i_k} \PP (A_{i_1}
        \cap \cdots \cap A_{i_k}) \]
    \item When $r$ is odd:
        \[ \PP \left( \bigcup_{i = 1}^n A_i
        \right) \ge \sum_{k = 1}^r (-1)^{k +
        1} \sum_{i_1 < \cdots < i_k} \PP (A_{i_1}
        \cap \cdots \cap A_{i_k}) \]
\end{itemize}
\myskip
\ul{Question}: When is it good to truncate at for
example $r = 2$?

\begin{proof}
    Induction on $r$ and $n$. For $r$ odd:
    \begin{align*}
        \PP \left( \bigcup_{i = 1}^n A_i \right)
        &= \PP \left( \bigcup_{i = 1}^{n - 1} A_i
        \right) + \PP (A_n) - \PP \left(
        \bigcup_{i = 1}^{n - 1} (A_i \cap A_n)
        \right) \\
        &\le \sum_{\substack{J \subset \{1, \dots,
        n - 1\}\\I \le |J| \le r}} (-1)^{|J| + 1}
        \PP \left( \bigcap_{i \in J} A_i \right) +
        \PP (A_n) - \sum_{\substack{J \subset \{1,
        \dots, n - 1\}\\1 \le |J| \le r - 1}}
        (-1)^{|J| + 1} \PP \left( \bigcap_{i \in J
        \cup \{n\}} A_i \right) \\
        &\le \sum_{\substack{I \subset \{1, \dots,
        n\}\\1 \le |I| \le r}} (-1)^{|I| + 1} \PP
        \left( \bigcap_{i \in I} A_i \right)
    \end{align*}
    $r$ even is similar.
\end{proof}

\subsubsection*{Counting with Inclusion-Exclusion Principle}

Uniform probability measure on $\Omega$, $|\Omega|
< \infty$.
\[ \PP (A) = \frac{|A|}{|\Omega|} \,\,\forall\,\,
A \subseteq \Omega .\]
Then $\forall\,\, A_1, \dots, A_n \subseteq
\Omega$.
\[ |A_1 \cup \cdots \cup A_n| = \sum_{k = 1}^n
(-1)^{k + 1} \sum_{i_1 < \cdots < i_k} |A_{i_1}
\cap \cdots \cap A_{i_k}| \]
(and similar for Bonferroni Inequalities).

\setcounter{customexample}{0}
\begin{example}
    \emph{Surjections} $f : \{1, \dots, n\} \to
    \{1, \dots, n\}$
    \[ \Omega = \{f : \{1, \dots, n\} \to \{1,
    \dots, m\}\} \qquad \text{all functions} \]
    \[ A = \{f : \mathrm{Im}(f) = \{1, \dots, m\}\}
    \qquad \text{all surjections} \]
    $\forall\,\, i \in \{1, \dots, m\}$. Define
    \[ B_i = \{f \in \Omega : i \not\in
    \mathrm{Im}(f)\} .\]
    Key observations:
    \begin{itemize}
        \item $A = B_1^c \cap \cdots \cap B_m^c =
            (B_1 \cup \cdots \cup B_m)^c$.
        \item $|B_{i_1} \cap \cdots \cap B_{i_k}|$
            is nice to calculate! In particular,
            it is
            \[ |\{f \in \Omega : i_1, \dots, i_k
            \not\in \mathrm{Im}(f)\}| = (m - k)^n
            .\]
    \end{itemize}
    Inclusion-Exclusion Principle implies:
    \begin{align*}
        |B_1 \cup \cdots \cup B_m|
        &= \sum_{k = 1}^m (-1)^{k + 1} \sum_{i_1 <
        \cdots < i_k} |B_{i_1} \cap \cdots \cap
        B_{i_k}| \\
        &= \sum_{k = 1}^m (-1)^{k + 1} {m \choose
        k} (m - k)^n
    \end{align*}
    \begin{align*}
        |A|
        &= m^n - \text{previous expression} \\
        &= \sum_{k = 0}^m (-1)^k {m \choose k} (m
        - k)^n
    \end{align*}
\end{example}
