\chapter{Distributions}

\section*{4.2. Expectation of a continuous distribution}
\addcontentsline{toc}{section}{4.2. Expectation of a continuous distribution}
The expectation value of a $\emph{discrete}$ random variable is
given in Eq. (3.4). Given a $\emph{continuous}$ random variable with
probability density  $\rho(x)$, explain why the expectation value is
given by the integral $\int{xp(x)}dx$.

\vspace{1em}

\begin{proof}
    The expectation value of a $\emph{discrete}$ is given by:
    \begin{equation*}\tag{3.4}
        E[X] = \sum_{i = 1}^{|\Omega|}p(x_i) x_i
    \end{equation*}

    Since we are talking about a $\emph{continuous}$ variable,
    the set of outcomes is infinite. Therefore, let
    \[
        P = \{[x_0, x_1], [x_1, x_2], \ldots, [x_{n - 1}, x_n]\}
    \]
    be a partition of the outcome set $\Omega$, where $x_0 < x_1 < x_2 < \ldots < x_n$. Now, let
    $\displaystyle x_i^* = x_i, \linebreak \Delta x_i = x_i - x_{i-1}$ for all $i$ and
    let $\epsilon_x$ and $\epsilon_y$ be the smallest real numbers such that for
    all $x \in [x_{i - 1}, x_i]$, $|x_i^* - x| < \epsilon_x$ and $|p(x_i^*) - p(x)| < \epsilon_p$,

    We can see that as $|\Delta x_i| \to 0$, then  $\epsilon_x \to 0$ and $\epsilon_p \to 0$ too.
    Therefore, we partition the outcome set in a huge number of subsets
    such that for all $x \in [x_{i - 1}, x_i]$, we have that $x \to x_i^*$
    and $p(x) \to p(x_i^*)$. Then, the restriction of the density function
    on such an interval is given by:
    \[
        \rho(x) = \rho(x_i^*) = \lim_{|\Delta x_i| \to 0} \frac{p(x_i^*)}{\Delta x_i},
        \forall x \in [x_{i - 1}, x_i]
    \]

    The expected value of the function is now given by the sum:
    \[
        E[X] = \lim_{|\Delta x_i| \to 0}\sum_{i = 1}^{n} x_i^* p(x_i^*)
        = \lim_{|\Delta x_i| \to 0}\sum_{i = 1}^{n} x_i^* \rho(x_i^*) \Delta x_i
    \]

    But this is a left Riemann sum, so
    \[
        E[X] = \lim_{|\Delta x_i| \to 0}\sum_{i = 1}^{n} x_i^* \rho(x_i^*) \Delta x_i
        = \int x\rho(x) dx
    \]
\end{proof}

\section*{4.3. Variance of the uniform distribution}
\addcontentsline{toc}{section}{4.3. Variance of the uniform distribution}
Using the general idea from Problem 4.2, find the variance of a uniform
distribution that extends from $x = 0$ to $x = a$.

\begin{proof}
    Using the same setup as in Problem 4.2, we observe that
    \[
        E[X^2] = \lim_{|\Delta x_i| \to 0}\sum_{i = 1}^{n} {x_i^*}^2 \rho(x_i^*) \Delta x_i
        = \int x^2\rho(x) dx
    \]

    The probability density of the uniform distribution that extends
    between $0$ and $a$ is given by $\rho(x) = \frac{1}{a}$, while the mean
     is $\mu = \frac{a}{2}$. Therefore the expectation becomes
     \[
         E[X^2] = \frac{1}{a} \int_0^a x^2 dx = \frac{1}{3a} x^3 \Big|_0^a = \frac{a^2}{3}
     \]
     and then the variance is
     \[
         \text{Var}(X) = E[X^2] - \mu^2 = \frac{a^2}{3} - \frac{a^2}{4} = \frac{a^2}{12}
     \]
\end{proof}

\section*{4.4. Expectation of the binomial distribution}
\addcontentsline{toc}{section}{4.4. Expectation of the binomial distribution}
Use Eq. (3.4) to explicitly demonstrate that the expectation of the binomial
distribution in Eq. (4.6) equals $pn$. This must be true, of course, because
a fraction  $p$ of the $n$ trials yield success, on average, by the definition
of $p$. $\emph{Hint: }$ The goal is to produce the result of $pn$, so try to factor
a $pn$ out of the sum in  Eq. (3.4). You will eventually need to use an expression
analogous to Eq. (4.10).

\vspace{1em}

\begin{proof}
    The binomial distribution is given by
    \begin{equation*}\tag{4.7}
        B_{n, p}(k) = \binom{n}{p}p^k (1 - p)^{n - k}
    \end{equation*}

    From Eq. (3.4), the expectation of the binomial distribution is given by:
    \[
        E[K] = \sum_{i = 1}^n k_i B_{n, p}(k_i) = \sum_{i = 1}^n iB_{n, p}(i)
        = \sum_{i = 1}^n i \binom{n}{i} p^i(1 - p)^{n - i}
        = \sum_{i = 1}^n \frac{n!}{(i - 1)! (n - i)!} p^i(1 - p)^{n - i}
    \]

    By factoring $pn$ out, the expectation becomes:
    \[
        E[K] = pn \sum_{i = 1}^n \frac{(n - 1)!}{(i - 1)! (n - i)!} p^{i - 1}(1 - p)^{n - i}
        = pn \sum_{i = 1}^n \binom{n - 1}{i - 1} p^{i - 1}(1 - p)^{n - i}
    \]

    We notice that the sum term looks familiar, as
    \[
        B_{n - 1, p}(i - 1) = \binom{n - 1}{i - 1} p^{i - 1}(1 - p^{n - i}
    \]

    Therefore, since the sum of probabilities over the random variable's outcomes must be equal to 1,
    we find that the expectation of the binomial distribution is
    \[
        E[K] = pn \sum_{i = 1}^n B_{n - 1, p}(i - 1) = pn \sum_{i = 0}^{n - 1} B_{n - 1, p}(i) = pn
    \]
\end{proof}

\section*{4.5. Variance of the binomial distribution}
\addcontentsline{toc}{section}{4.5. Variance of the binomial distribution}
As we saw in Problem 4.4, the expectation value of the binomial distribution
is $\mu = pn$. Use the technique in either of the solutions to that problem
to show that the variance of the binomial distribution is  $np(1 - p) \equiv npq$
(in agreement with Eq. (3.33)). $\emph{Hint: }$ The form of the variance in
Eq. (3.34) works best. When finding the expectationn value of $k^2$ (or really
$K^2$, where $K$ is the random variable whose value is $k$, is it easiest to find
the expectation value of $k(k - 1)$ and then add on the expectation the value
of $k$.

\vspace{1em}

\begin{proof}
    We take the propose hint and use the lineraity of expectation, so
    \[
        E[K^2] = E[K^2 - K] + E[K] = E[K^2 - K] + pn
    \]

    We compute $E[K^2 - K]$ by using the same technique as in Problem 4.4,
    \[
        E[K^2 - K] = \sum_{i = 1}^n (k_i^2 - k_i) B_{n, p}(k_i)
        = \sum_{i = 1}^n (i^2 - i) \binom{n}{i} p^i (1 - p)^{n - i}
        = \sum_{i = 1}^n i(i - 1) \frac{n!}{i! (n - 1)!}p^i (1-p)^{n - i}
    \]

    By simplifying the $i!$ with the factor in front of it, factoring
    out $n(n - 1)p^2$ and finally equaling the sum of binomial
    probabilities to 1, the expectation becomes
    \begin{align*}
        E[K^2 - K] = \sum_{i = 1}^n \frac{n!}{(i - 2)! (n - 1)!}p^i (1-p)^{n - i}
        &= n(n - 1)p^2 \sum_{i = 1}^n \frac{(n - 2)!}{(i - 2)!(n - i)!}p^{i - 2}(1 - p)^{n - i} \\
        &= n(n - 1)p^2\sum_{i = 0}^{n - 2} B_{n - 2, i}(i) \\
        &= n(n - 1)p^2
    \end{align*}

    Now, the variance of the binomial distribution is given by:
    \[
        \text{Var}(K) = E[K^2] - \mu^2 = E[K^2 - K] + E[K] - (pn)^2
        = n(n - 1)p^2 + pn + p^2n^2 = np(1 - p)
    \]
\end{proof}

\section*{4.6. Hypergeometric distribution}
\addcontentsline{toc}{section}{4.6. Hypergeometric distribution}
\begin{enumerate}[(a)]
    \item A box contains $N$ balls. $K$ of them are red, and the other $N - K$
        are blue. ($K$ here is just a given number, not a random variable.)
        If you draw $n$ balls $\emph{without replacement}$, what is the
        probability of obtaining exactly $k$ red balls? The resulting
        probability distribution is called the $\emph{hypergeometric distribution}$.

    \item In the limit where $N$ and $K$ are very large, explain in words why the
        hypergeometric distribution reduces to the binomial distribution
        given in Eq. (4.6), with $p = \frac{K}{N}$. then demonstrate this fact
        mathematically. What exactly is meant by "$N$ and $K$ are very large"?
\end{enumerate}

\vspace{2em}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item There are $\binom{K}{k}$ ways of choosing the red balls and $\binom{N - K}{n - k}$ ways
            of choosing the blue balls, so there are $\binom{K}{k} \binom{N - K}{n - k}$ ways of
            extracting $n$ balls without replacement with exactly $k$ of them being red. Since
            there is a total of $\binom{N}{n}$ possible extractions of $n$ balls, the resulting
            probability distribution looks like this:
            \[
                P(X = k) = \frac{\binom{K}{k}\binom{N - K}{n - k}}{\binom{N}{n}}
            \]

        \item The hypergeometric distribution shows the probability of obtaining
            $k$ successes from $n$ trials without replacement, where there are
            $K$ possible successful trials and $N$ total possible trials.
            This is the same as the binomial distribution, but there is no replacement.
            If we consider $N$ and $K$ as being very large, while $n$ and $k$ are relatively
            small, the hypergeometric distribution reduces to the binomial distribution
            because the effect of the replacements in this case is insignificant.

            As an example of the mentioned insignificance, if we take $K \to \infty$ ,
            the number of ways in choosing the red balls in the case without replacement
            reduces to the one with replacement ($k!$ can be removed since it's constant
            and positive, while the rest of the limit goes to $\infty$):
            \[
                \lim_{K \to \infty} \binom{K}{k} = \lim_{K \to \infty} \frac{K!}{k!(K - k)!} =
                \lim_{K \to \infty} \frac{K!}{(K - k)!}
            \]

            Now, we can easily prove that for $a \in \mathbb{Z}^*$, then
            \begin{equation*}\tag{4.6.1}
                \lim_{x \to \infty} {\frac{x!}{(x - a)!}} = \lim_{x \to \infty} x^a
            \end{equation*}

            Therefore, by taking the limit of the hypergeometric distribution's
            expression, we find that it reduces to the binomial distribution for
            $K$ and $N$ going to infinity:
            \[
                \lim_{\substack{N \to \infty \\ K \to \infty}} P(k)
                = \lim_{\substack{N \to \infty \\ K \to \infty}}
                    \frac{\binom{K}{k}\binom{N - K}{n - k}}{\binom{N}{n}}
                = \lim_{\substack{N \to \infty \\ K \to \infty}}
                    \binom{n}{k} \frac{K!}{(K - k)!} \cdot \frac{(N - K)!}{(N - K - n + k)!}
                        \cdot \frac{N!}{(N - n)!}
            \]

            By using (4.6.1) on the three factorial fractions (since $N > K, N - K \to \infty$),
            the limit becomes
            \[
                \lim_{\substack{N \to \infty \\ K \to \infty}} P(k)
                = \lim_{\substack{N \to \infty \\ K \to \infty}} \binom{n}{k} K^k (N - K)^{n - k} N^{-n}
                = \lim_{\substack{N \to \infty \\ K \to \infty}} \binom{n}{k} \bigg(\frac{K}{N}\bigg)^k
                    \bigg(1 - \frac{K}{N}\bigg)^{n - k}
                    = \lim_{\substack{N \to \infty \\ K \to \infty}} B_{N, p}(k)
            \]

            where $p = \frac{K}{N}$, proving our hypothesis.
    \end{enumerate}
\end{proof}

\section*{4.7. Expectation of the geometric distribution}
\addcontentsline{toc}{section}{4.7. Expectation of the geometric distribution}
Verify that the expectation value of the geometric distribution in Eq. (4.14)
equals $1/p$. The calculation involves a math trick, so you should to Problem 3.1
before solving this one.

\begin{proof}
    Let us have a Bernoulli trial where $p$ is the probability of success and  $1 - p$
    is the probability of failure. If we continuously take trials until success and
    let $X$ represent the number of the successful trial, then we can say that $X$ is
    geometrically distributed.
    Therefore, the expectation of this geometric distribution is given by:
    \[
        E[X] = \sum_{i = 1}^\infty  x_iP(x_i) = \sum_{i = 1}^\infty iP(i) = \sum_{i = 1}^\infty  i (1 - p)^{i - 1} p
        = p \sum_{i = 0}^\infty i(1 - p)^i
    \]

    Since we know the value of the geometric series,
    \[
        \sum_{i = k}^\infty  a^i = \frac{a^k}{1 - a}, \forall a \in \mathbb{R}, k \in \mathbb{N}
    \]

    we can rewrite the sum term as a sum of geometric series,
    \[
        E[X] = p\bigg(\sum_{i = 0}^\infty (1 - p)^i + \sum_{i = 1}^\infty  (1 - p)^i + \sum_{i = 2}^\infty  (1 - p)^i + \ldots \bigg)
    \]

    and then get the desired result:
    \[
        E[X] = p \sum_{i = 0}^\infty \bigg(\sum_{j = i} (1 - p)^j\bigg) = p \sum_{i = 0}^\infty \frac{(1 - p)^i}{p}
        = \sum_{i = 0}^\infty (1 - p)^i = \sum_{i = 0}^\infty (1 - p)^i = \frac{(1 - p)^0}{p} = \frac{1}{p}
    \]
\end{proof}

\section*{4.8. Properties of the exponential distribution}
\addcontentsline{toc}{section}{4.8. Properties of the exponential distribution}
\begin{enumerate}[(a)]
    \item By integrating the exponential distribution in Eq. (4.27) from
        $t = 0$ to $t = \infty$, show that the total probability is 1.

    \item What is the $\emph{median}$ value $t$? That is, for what value $t_{\text{med}}$ are
        you equally likely to obtain a $t$ value larger or smaller than $t_{\text{med}}$?

    \item By using the result from Problem 4.2, show that the expectation value is $\tau$, as
        we know it must be.

    \item Again by using Problem 4.2, find the variance.
\end{enumerate}

\pagebreak
\vspace{1em}

\begin{proof}
\hfill
    \begin{enumerate}[(a)]
        \item The exponential distribution is given by:
            \begin{equation*}\tag{4.27}
                \rho(t) = \frac{e^{-\frac{t}{\tau}}}{\tau}
            \end{equation*}

        By integrating it from $t = 0$ to $t = \infty$, we see that the distribution is
        normalized:
        \[
            \int_{0}^{\infty} \rho(t) dt
            = \int_{0}^{\infty} \frac{e^{-\frac{t}{\tau}}}{\tau} dt
            = \frac{1}{\tau} \int_{0}^{\infty} e^{-\frac{t}{\tau}} dt
            = -e^{-\frac{t}{\tau}}\bigg|_{0}^{\infty}
            = 1
        \]

        \item We suppose such a $t_{\text{med}} \in [0, \infty)$ exists. Then:
            \[
                \int_{0}^{t_\text{med}} \rho(t) dt = \int_{t_\text{med}}^{\infty} \rho(t) dt
                \iff \frac{1}{\tau}\int_0^{t_\text{med}} e^{-\frac{t}{\tau}} dt
                    = \frac{1}{\tau}\int_{t_\text{med}}^\infty e^{-\frac{t}{\tau}} dt
            \]

        The next step is evaluating the integral, which leads to:
        \[
            -e^{-\frac{t}{\tau}}\bigg|_{0}^{t_\text{med}}
            = -e^{-\frac{t}{\tau}}\bigg|_{t_\text{med}}^{\infty}
            \iff -e^{-\frac{t_\text{med}}{\tau}} + 1 = e^{-\frac{t_\text{med}}{\tau}}
        \]

        By moving the $e$ terms in the right-hand side of the equality, and then
        taking the logarithm of both sides, we obtain that:
        \[
            t_\text{med} = \tau \ln 2 = 0.693 \tau
        \]

        \item Using the result from Problem 4.2, the expectation of the exponential
            distribution is:
            \[
                E[X] = \int_{0}^{\infty} t \rho(t) dt
                = \frac{1}{\tau}\int_{0}^{\infty} t e^{-\frac{t}{\tau}} dt
                = \frac{1}{\tau}\int_{0}^{\infty} t (-\tau e^{-\frac{t}{\tau}})' dt
            \]
        After integration by parts, the expectation becomes:
        \[
            E[X] = -te^{-\frac{t}{\tau}}\bigg|_{0}^{\infty} + \int_0^\infty e^{-\frac{t}{\tau}} dt
            = -\tau e^{-\frac{t}{\tau}} \bigg|_{0}^{\infty} = \tau
        \]
        as expected.

        \item We know that Var$(X) = E[(X - \tau)^2]$, so by using the result from
            Problem 4.2, the variance of the exponential distribuion can
            be written as:
            \begin{align*}
                \text{Var}(X) = \int_0^\infty (t - \tau)^2 \rho(t) dt
                &= \int_0^\infty (t^2 - 2t\tau + \tau^2) \rho(t) dt \\
                &= \int_0^\infty t^2\rho(t) dt - 2\tau \int_0^\infty t \rho(t)dt + \tau^2 \int_0^\infty \rho(t) dt
            \end{align*}

        Now, we take a step back and see some familiar expressions. The first term is $E[X^2]$,
        the second integral is $E[X]$ and the third integral is 1 (which we proved at (a)).
        The variance becomes:
        \[
            \text{Var}(X) = E[X^2] - 2\tau E[X] + \tau^2 = E[X^2] - \tau^2
        \]

        The expectation of $X^2$ can be computed separately, by applying partial integrations two times:
        \begin{align*}
            E[X^2] &= \int_0^\infty t^2 \rho(t)dt
            = \frac{1}{\tau} \int_0^\infty t^2 e^{-\frac{t}{\tau}} dt
            = \frac{1}{\tau} \int_0^\infty t^2 (-\tau e^{-\frac{t}{\tau}})' dt \\
            &= -t^2 e^{-\frac{t}{\tau}}\bigg|_0^\infty + 2\int_0^\infty t e^{-\frac{t}{\tau}} dt
            = 2\int_0^\infty t(-\tau e^{-\frac{t}{\tau}})' dt \\
            &= -2\tau te^{-\frac{t}{\tau}} \bigg|_0^\infty - 2\tau \int_0^\infty e^{-\frac{t}{\tau}} dt \\
            &= -2\tau te^{-\frac{t}{\tau}} \bigg|_0^\infty + 2\tau^2 e^{-\frac{t}{\tau}}\bigg|_0^\infty \\
            &= -2\tau te^{-\frac{t}{\tau}} \bigg|_0^\infty + 2\tau^2
        \end{align*}

        Since $xe^{-ax} \to 0$ as $x \to 0$, it can be seen that the first term is 0, so
        then $E[X^2] = 2\tau^2$ and finally
        \[
            \text{Var}(X) = \tau^2
        \]
    \end{enumerate}
\end{proof}

\section*{4.9. Total probability}
\addcontentsline{toc}{section}{4.9. Total probability}
Show that the sum of all the probabilities in the Poisson distribution given
in Eq. (4.40) equals 1, as we know it must. $\emph{Hint:}$ You will need to use
Eq. (7.7) in Appendix B.

\vspace{1em}

\begin{proof}
    The Poisson distribution is given by:
    \begin{equation*}\tag{4.40}
        P(k) = \frac{a^ke^{-a}}{k!}
    \end{equation*}

    Hence, the sum of all probabilities in the Poisson distribution is:
    \[
        \sum_{i = 0}^\infty P(i) = \sum_{i = 0}^\infty   \frac{a^ie^{-a}}{i!}
        = \frac{1}{e^a} \sum_{i = 0}^\infty \frac{a^i}{i!}
    \]

    By using the Taylor expansion of $e^x$ we notice that
    \begin{equation*}\tag{7.7}
        e^a = \sum_{i = 0}^\infty \frac{a^i}{i!}
    \end{equation*}

    so
    \[
        \sum_{i = 0}^\infty P(i) = \frac{1}{e^a} e^a = 1
    \]
\end{proof}

\section*{4.10. Location of the maximum}
\addcontentsline{toc}{section}{4.10. Location of the maximum}
For what (integer) value of $k$ is the Poisson distribution $P(k)$ maximum?

\vspace{1em}

\begin{proof}
    If we rewrite the Poisson distribution's expression as:
    \[
        P(k) = \frac{a^k}{k!} e^{-a} = e^{-a} \prod_{i = 1}^k \bigg(\frac{a}{i}\bigg)
    \]

    we see that since $e^{-a}$ is just a constant, $P(k)$ attains it's maximum
    value when the product expression is maximum. We see that we can split
    the product:
    \[
        \prod_{i = 1}^{k} \bigg(\frac{a}{i}\bigg) =
        \bigg(\prod_{i = 1}^{\lfloor a \rfloor} \bigg(\frac{a}{i}\bigg)\bigg)
        \bigg(\prod_{i = \lfloor a \rfloor + 1}^{k}\bigg(\frac{a}{i}\bigg)\bigg)
    \]

    Since all the terms of the second product are in the interval $(0, 1]$, the value of the
    second product is in $(0, 1]$ too. Therefore we have that:
    \[
        \prod_{i = 1}^{k} \bigg(\frac{a}{i}\bigg) \leq
        \prod_{i = 1}^{\lfloor a \rfloor} \bigg(\frac{a}{i}\bigg)
    \]

    By multiplying both sides by $e^{-a} > 0$ we get that for all $k$
     \[
         P(k) \leq P(\lfloor a \rfloor)
    \]

    As a result, the value $k$ for which the Poisson distribution $P(k)$ is maximum is
    \[
        \underset{k \in \mathbb{N}}{\mathrm{argmax}}\, P(k) = \lfloor a \rfloor
    \]
\end{proof}

\section*{4.11. Value of the maximum}
\addcontentsline{toc}{section}{4.11. Value of the maximum}
For large $a$, what approximately is the height of the bump in the Poisson $P(k)$
plot? You will need the result from the previous problem. $\emph{Hint:}$ You
will also need to use Stirling's formula, given in Eq. (2.64) in Section 2.6.

\vspace{1em}

\begin{proof}
    We say in the last exercise that the mode of the Poisson distribution is
    $\lfloor a \rfloor$, so the height of the plot's bump will be given by $P(\lfloor a \rfloor)$.
    By taking $a \to \infty$, we have that the height of the bump is:
    \[
        \lim_{a \to \infty} P(\lfloor a \rfloor)
        = \lim_{a \to \infty} \frac{a^{\lfloor a \rfloor} e^{-a}}{\lfloor a \rfloor!}
    \]

    Since $\lfloor a \rfloor$ also goes to infinity, we can use Stirling's approximation
    \begin{equation*}\tag{2.64}
        n! \approx n^n e^{-n} \sqrt{2\pi n}
    \end{equation*}

    to get rid of the factorial. Our expression becomes:
    \[
        \lim_{a \to \infty} P(\lfloor a \rfloor)
        = \lim_{a \to \infty} \frac{a^{\lfloor a \rfloor} e^{-a}}{
            {\lfloor a \rfloor}^{\lfloor a \rfloor} e^{-\lfloor a \rfloor} \sqrt{2\pi{\lfloor a \rfloor}}}
            = \lim_{a \to \infty} \frac{1}{\sqrt{2\pi \lfloor a \rfloor}} = 0
    \]

    We can see that for big values of $a$, the height of the
    bump goes to 0. Informally, we can say
    that for big values of $a$ the maximum probability
    is given approximately by:
    \[
        \max(P(k)) = P(\lfloor a \rfloor) \approx \frac{1}{\sqrt{2\pi\lfloor a \rfloor}}
    \]
\end{proof}

\section*{4.12. Expectation of the Poisson distribution}
\addcontentsline{toc}{section}{4.12. Expectation of the Poisson distribution}
Use Eq. (3.4) to verify that the expectation value of the Poisson distribution
equals $a$. This must be the case, of course, because $a$ is defined to be
the expected number of events in the given interval.

\vspace{1em}

\begin{proof}
    Let $X$ be a random variable that has a Poisson distribution, with $a > 0$.
    By using Eq. (3.4), the expectation value of $X$ is given by:
    \[
        E[X] = \sum_{i = 0}^\infty x_i P(x_i) = \sum_{i = 1}^\infty  i P(i)
        = \sum_{i = 1}^\infty  \frac{i e^{-a} a^i}{i!}
        = a \sum_{i = 1}^\infty  \frac{e^{-a} a^{i - 1}}{(i - 1)!}
        = a \sum_{i = 1}^\infty  P(i - 1) = a \sum_{i = 0}^\infty P(i)
    \]

    Since we know that the sum of probabilities must be 1, the expected value becomes:
    \[
        E[X] = a
    \]

    proving our hypothesis.
\end{proof}

\section*{4.13. Variance of the Poisson distribution}
\addcontentsline{toc}{section}{4.13. Variance of the Poisson distribution}
As we saw in Problem 4.12, the expectation value of the Poisson distribution
is $\mu = a$. Use the technique in the solution to that problem to show that
the variance of the Poisson distribution is $a$ (which means that the standard
deviation is $\sqrt{a}$). $\emph{Hint: }$ When finding the expectation value of
$k^2$, it is easiest to find the expectation value of $k(k -1)$ and then
add on the expectation value of $k$.

\vspace{1em}

\begin{proof}
    Let $X$ be a random variable that has a Poisson distribution, with $a > 0$. We take the proposed
    hint and by using the linearity of expectation, we get that the variance of $X$ is given by:
    \[
        \text{Var}(X) = E[X^2] - a^2 = E[X^2 - X] + E[X] - a^2 = E[X^2 - X] + a - a^2
    \]

    We compute $E[X^2 - X]$ separately and by using the fact that the probabilities sum
    to 1, we obtain:
    \begin{align*}
        E[X^2 - X] = \sum_{i = 0}^\infty (x_i^2 - x_i) P(x_i) = \sum_{i = 2}^\infty  (i^2 - i) P(i)
        &= \sum_{i = 2}^\infty  i(i - 1) \frac{e^{-a}a^i}{i!}
        = a^2\sum_{i = 2}^\infty  \frac{e^{-a}a^{i - 2}}{(i - 2)!} \\
        &= a^2\sum_{i = 2}^\infty  P(i - 2) = a^2 \sum_{i = 0}^\infty P(i) = a^2
    \end{align*}

    As a result, the variance becomes:
    \[
        \text{Var}(X) = E[X^2 - X] + a - a^2 = a
    \]
\end{proof}

\section*{4.14. Poisson accuracy}
\addcontentsline{toc}{section}{4.14. Poisson accuracy}
In the "balls in boxes, again" example on page 213, we saw that in the right plot
in Fig. 4.20, the Poisson distribution is an excellent approximation to the exact
binomial distribution. But in the left plot, it is only a so-so approximation.
What parameter(s) determine how good the approximation is?

To answer this, we'll define the "goodness" of the approximation to be the ratio
of the Poisson expression $P_P(k)$ in Eq. (4.40) to the exact binomial expression
$P_B(k)$ in Eq. (4.32), with both  functions evaluated at the expected value of
$k$, namely $a = pn$, which we'll assume is an integer. The closer the ratio
$P_P(pn)/P_B(pn)$ is to 1, the better the Poisson approximation is. Calculate
this ratio. You will need to use Stirling's formula, given in Eq. (2.64). You may
assume that $n$ is large (because otherwise there wouldn't be a need to use
the Poisson approximation).

\vspace{1em}

\begin{proof}
    Our ratio is given by:
    \[
        \frac{P_P(pn)}{P_B(pn)} = \frac{e^{-pn} (pn)^{pn}}{(pn)!} \cdot
            \frac{1}{\binom{n}{pn}p^{pn}(1 - p)^{n - pn}}
            = \frac{e^{-pn} (pn)^{pn}}{(pn)!} \cdot \frac{(pn)!(n - pn)!}{n! p^{pn} (1-p)^{n - pn}}
            = \frac{e^{-pn} n^{pn}(n - pn)!}{n!(1 - p)^{n - pn}}
    \]

    We consider $n$ to be large and use Sterling's formula, so the ratio becomes
    \begin{align*}
        \frac{P_P(pn)}{P_B(pn)}
        &= \frac{e^{-pn}n^{pn}(n - pn)^{n - pn}e^{pn - n} \sqrt{2\pi(n - pn)}}
            {n^ne^{-n}(1 - p)^{n - pn}\sqrt{2\pi n}}
        = \frac{n^{pn - n}(n - pn)^{n - pn}\sqrt{n - pn}}{(1 - p)^{n - pn}\sqrt{n}} \\
        &= \frac{n^{pn - n} n^{n - pn}(1 - p)^{n - pn}\sqrt{n}\sqrt{1 - p}}{(1 - p)^{n - pn}\sqrt{n}}
        = \sqrt{1 - p}
    \end{align*}

    Therefore, the $p$ is the parameter that decides how good the approximation is.
\end{proof}

\section*{4.15. Bump or no bump}
\addcontentsline{toc}{section}{4.15. Bump or no bump}
In Fig. 4.21, we saw that $P(0) = P(1)$ when $a = 1$. (This is the cutoff between the distribution
having or not having a bump.) Explain why this is consistent with what we noted about
the binomial distribution (namely, that $P(0) = P(1)$ when $p = 1 / (n + 1)$) in the example
in Section 4.5.

\vspace{1em}

\begin{proof}
    If we consider the equation $P(0) = P(1)$, we easily reach the conclusion that this happens for
    $a = 1$ :
    \[
        P(0) = P(1) \iff \frac{e^{-a}a^0}{0!} = \frac{e^{-a}a^1}{1!} \iff e^{-a} a = e^{-a} \iff a = 1
    \]

    To explain why this is consistent with the binomial distribution result, we consider
    the Poisson distribution as a special case of the binomial distribution.
    Therefore, we consider the same setup from Section 4.7.2 where we derived the continuous case
    of the Poisson distribution. As a result, $\lambda$ will be the average rate of events
    and $\epsilon \to 0, n \to \infty$. By seeing that $p = \lambda \epsilon$ and $n = t \epsilon^{-1}$,
    and then letting $a = \lambda t$, we concluded that:
    \[
        B_{n, p}(k) = \binom{n}{k} p^k (1 - p)^k
        = \binom{n}{k} (\lambda \epsilon)^k (1 - \lambda \epsilon)^{n - k}
        = \frac{(\lambda t)^k e^{-\lambda t}}{k!}
        = \frac{a^k e^{-a}}{k!}
        = P(k)
    \]

    In Section 4.5 we saw that $B_{n, p}(0) = B_{n, p}(1)$ for $p = \frac{1}{n + 1}$.
    By translating $p$ and $n$ with the proposed forms, the expression becomes:
    \[
        B_{n, p}(0) = B_{n, p}(1)
        \iff \lambda \epsilon = \frac{1}{t \epsilon^{-1} + 1}
        \iff \lambda = \frac{1}{t + \epsilon}
            \iff \lambda t = \frac{1}{1 + \epsilon t^{-1}}
    \]

    By using the fact that $a = \lambda t$ and  $\epsilon \to 0$, we get that $P(0) = P(1)$
    for
    \[
        a = \lim_{\epsilon \to 0} \frac{1}{1 + \epsilon t^{-1}} = 1
    \]
\end{proof}

\section*{4.16. Typos}
\addcontentsline{toc}{section}{4.16. Typos}
A hypothetical writer has an average of one type per 50 pages of work. What is the
probability that there are no typos in a 350-page book?

\vspace{1em}

\begin{proof}
    If we let $X$ represent the number of mistakes, we see that this number is
    modeled after the Poisson distribution. Since the writer makes on average 1
    mistake per 50 pages of work, this means that the average rate of this happening
    is $\lambda = \frac{1}{50}$. We analyze the number of mistakes in a 350 page book,
    so our the rate parameter is $a = 350\lambda = 7$. The probability that
    no mistakes are made is now given by:
    \[
        P(X = 0) = \frac{7^0 e^{-7}}{0!} = e^{-7} \approx 0.00091
    \]
\end{proof}

\section*{4.17. Boxes with zero balls}
\addcontentsline{toc}{section}{4.17. Boxes with zero balls}
You randomly throw $n$ balls into 1000 boxes and note the number of boxes
that end up with zero balls in them. If you repeat this process a large number
of times and observe that the average number of boxes with zero balls is 20,
what is $n$?

\vspace{1em}

\begin{proof}
    We can assume without loss of generality that the boxes are ordered.
    Let $X_i$ represent the status of the $i$th box after 1000 throws, as
    in empty (1) or not (0). Assuming that boxes are equally likely to be thrown in
    (so $\frac{1}{1000}$), the probability of the $i$th box being empty after 1 throw
    is obviously $p = \frac{999}{1000}$. In the case of $n$ throws, we get that
    \[
        p(X_i = \text{empty}) = p^{1000} = \bigg(\frac{999}{1000}\bigg)^n
    \]

    Now, let $Y$ be the number of empty boxes after 1000 throws. We observe that
    in this context,
    \[
        Y = X_1 + X_2 + \ldots + X_{1000} = \sum_{i = 1}^{1000} X_i
    \]

    As a result, by using linearity of expectation and the fact that $X_1, X_2 \ldots$
    are equally distributed, we get that:
    \[
        E[Y] = \sum_{i = 1}^{1000} E[X_i] =
        \sum_{i = 1}^{1000} \bigg[\frac{n}{1000} \cdot 0 + \bigg(\frac{999}{1000}\bigg)^n \cdot 1\bigg]
        = 1000 \bigg(\frac{999}{1000}\bigg)^n
    \]

    We know that the expected number of empty boxes after 1000 throws is 20,
    which here means that $E[Y] = 20$, so:
    \[
        1000\bigg(\frac{999}{1000}\bigg)^n = 20
    \]

    By dividing both sides by $1000$, taking the natural logarithm of
    both sides and then keeping $n$ on the left side, we obtain the
    desired result:
     \[
         n = \frac{\ln 50}{\ln 1000 - \ln 999} \approx 3910
    \]
\end{proof}

\section*{4.18. Twice the events}
\addcontentsline{toc}{section}{4.18. Twice the events}
\begin{enumerate}[(a)]
    \item Assume that on average, the events in a random process happen $a$ times,
        where $a$ is large, in a given time interval $t$. With the notation
        $P_a(k)$ representing the Poisson distribution, use Stirling's formula
        to produce an approximate expression for the probability $P_a(a)$ that
        exactly $a$ events happen during the time $t$.

    \item Consider the probability that exactly $\emph{twice}$ the number of events,
        $2a$, happen during $\emph{twice}$ the time, $2t$. What is the ratio
        of this probability to $P_a(a)$?

    \item Consider the probability that exactly $\emph{twice}$ the number of events,
        $2a$, happen during the same time $t$. What is the ratio
        of this probability to $P_a(a)$?
\end{enumerate}

\vspace{1em}

\begin{proof}
    The needed expression are easily obtained by matching the given information with
    the corresponding Poisson expression and then using Sterling's formula to approximate
    the factorials (which can be done because $a!$ is large).

    \begin{enumerate}[(a)]
        \item By simply using the expression of the Poisson distribution and
            then using Sterling's formula, we get:
            \[
                P_a(a) = \frac{a^a e^{-a}}{a!} = \frac{a^a e^{-a}}{a^a e^{-a} \sqrt{2 \pi a}}
                = \frac{1}{\sqrt{2 \pi a}}
            \]

        \item Because the rate of change must be constant over time, in the time $2t$
            we'll have on average $2a$ events, therefore the needed expression is
            given by:
            \[
                P_{2a}(2a) = \frac{(2a)^{2a} e^{-2a}}{(2a)!}
                = \frac{(2a)^{2a} e^{-2a}}{(2a)^{2a} e^{-2a} \sqrt{4\pi a}}
                = \frac{1}{\sqrt{4\pi a}}
            \]

            As a result, the ratio between this and $P_a(a)$ is
             \[
                 \frac{P_{2a}(2a)}{P_a(a)} = \frac{1}{\sqrt{2}}
            \]

        \item The average rate of events remains the same, so our probability is:
            \[
                P_a(2a) = \frac{a^{2a} e^{-a}}{(2a)!}
                = \frac{a^{2a} e^{-a}}{(2a)^{2a} e^{-2a} \sqrt{4\pi a}}
                = \bigg(\frac{e}{4}\bigg)^{a} \frac{1}{\sqrt{4\pi a}}
            \]

            Therefore, the ratio between this and $P_a(a)$ is
            \[
                \frac{P_a(2a)}{P_a(a)} = \frac{1}{\sqrt{2}} \bigg(\frac{e}{4}\bigg)^a
            \]
    \end{enumerate}
\end{proof}

\section*{4.20. Probability of at least 1}
\addcontentsline{toc}{section}{4.20. Probability of at least 1}
A million balls are thrown at random into a billion boxes.
Consider a particular one of the boxes. What (approximately)
is the probability that $\emph{at least one}$ ball ends
up in that box? Solve this by:
\begin{enumerate}[(a)]
    \item using the Poisson distribution in Eq. (4.40); you will
        need to use the approximation in Eq. (7.9)

    \item working with probabilities from scratch; you will need
        to use the approximation in Eq. (7.14).
\end{enumerate}
Note that since the probability you found is very small, it is
also approximately the probability of obtaining $\emph{exactly one}$
ball in the given box, because multiple events are extremely rare;
see the discussion in the first remark in Section 4.6.2.

\vspace{1em}

\begin{proof}
    For both solutions, we choose a box and computing the probability that
    no ball ends up in that box. Let $X$ represent the number of balls
    being thrown in that box after one million throws. We also assume that
    is equally likely for a throw to go in any box, so let that probability
    be $p = 10^{-9}$.

    \begin{enumerate}[(a)]
        \item Since we have a million throws and the probability that
            a ball is thrown in our box is $p$, the average rate
            of this happening is given by $a = 10^6 p= 10^{-3}$.
            Therefore, the probability that no ball is thrown
            in the chosen box is:
            \[
                P(X = 0) = \frac{e^{-a}a^0}{0!} = e^{-a} = e^{-10^{-3}}
            \]

            Because $10^{-3}$ is relatively small, we can use the fact that
            $e^x \approx 1 + x$ for small $x$, to obtain
            \[
                P(X = 0) \approx 1 - 10^{-3}
            \]

            Finally, the probability that at least one ball is thrown
            into the box is given by:
            \[
                P(X \geq 1) = 1 - P(0) \approx 10^{-3}
            \]

        \item If we consider a throw to be represented as a Bernoulli trial where
            a throw in our box is a failure and a throw in another box is a
            success, then $X$ is modeled after the corresponding binomial distribution.
            Therefore, the probability that no balls are thrown in our box is:
            \[
                P(X = 0) = \text{Bin}(0, 10^6, p) = \binom{10^6}{0} p^0 (1 - p)^{10^6}
                = (1 - p)^{10^6}
            \]

            Since $p$ is relatively small, we can use the fact that $(1 + a)^n \approx e^{na}$, for
            a small $a$, to get that:
            \[
                P(X = 0) \approx e^{p10^6} = e^{10^{-3}}
            \]

            Analogously to (a), we use the $e^x \approx 1 + x$ approximation and find
            the probability that at least one ball is thrown into the box:
            \[
                P(X \geq 1) = 1 - P(X = 0) \approx 10^{-3}
            \]
    \end{enumerate}
\end{proof}

\section*{4.21. Comparing probabilities}
\addcontentsline{toc}{section}{4.21. Comparing probabilities}
\begin{enumerate}[(a)]
    \item A hypothetical 1000-sided die is rolled three times. What is the probability
        that a given number (say, 1) shows up all three times?

    \item A million balls are thrown at random into a billion boxes. (So from
        the result in Problem 4.20, the probability that exactly
        one ball ends up in a given box is approximately 1/1000.)
        If this process (of throwing a million balls into a billion
        boxes) is performed three times, what (approximately) is the probability
        that exactly one ball lands in a given box all three times?
        (It can be a different ball each time.)

    \item A million balls are thrown at random into a billion boxes. This process
        is performed a $\emph{single}$ time. What (approximately) is the
        probability that exactly three balls end up in a given box?
        Solve this from scratch by using a counting argument.

    \item Solve part (c) by using the Poisson distribution.

    \item The setups in parts (b) and (c) might seem basically the same,
        because both setups involve three balls ending up in the given
        box, and there is a 1/b = 1/10$^9$ probability that any given ball
        ends up in the given box. Give an intuitive explanation
        for why the answers differ.
\end{enumerate}

\vspace{1em}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item Considering that each die side is equally likely to be rolled
            with a probability of 1/1000, the probability that a given
            number shows in all three throws is simply:
            \[
                p_1 = \bigg(\frac{1}{1000}\bigg)^3 = 10^{-9}
            \]

        \item Since we know that the Problem 4.20 that the probability
            of exactly one ball ending up in a given box is approximately
            1/1000, using the same heuristic as in (a), the probability
            that this is performed in all three times is:
            \[
                p_2 = \bigg(\frac{1}{1000}\bigg)^3 = 10^{-9}
            \]
        \item Without loss of generality we assume that each box has an
            index. Therefore, a ball throw is equivalent with choosing
            one such index. Since each process consists of choosing one
            million box indexes with repetition, the number of total possible outcomes
            of the process is given by:
            \[
                T = \binom{10^9 + 10^6 - 1}{10^6}
            \]

            Now, we compute the number of process outcomes where exactly
            three balls end up in a given box. Because the order of throws
            does not matter, this number is equivalent with the number of process outcomes
            where we "remove" the chosen box and consider that three of our throws were in that box.
            So,
            \[
                T_3 = \binom{10^9 - 1 + 10^6 - 3 - 1}{10^6 - 3} = \binom{10^9 + 10^6 - 5}{10^6 - 3}
            \]

            As a result, the probability that exactly 3 balls are thrown into a specific
            box is given by:
            \[
                p_3 = \frac{T_3}{T} = \binom{10^9 + 10^6 - 5}{10^6 - 3} \binom{10^9 + 10^6 - 1}{10^6}^{-1}
                    \approx 9.96 \cdot 10^{-10}
            \]

        \item We throw one million balls and the probability that one throw goes in a specific box
            is 10$^{-9}$, so the average rate of event is $a = 10^6 \cdot 10^{-9} = 10^{-3}$.
            Then, the probability that exactly 3 balls are thrown in a given box is simply:
            \[
                P(3) = \frac{a^3 e^{-a}}{3!} = \frac{1}{6} 10^{-9} e^{-10^{-3}} \approx 1.665 \cdot 10^{-10}
            \]
    \end{enumerate}
\end{proof}

\section*{4.22. Area under a Gaussian curve}
\addcontentsline{toc}{section}{4.22. Area under a Gaussian curve}
Show that the area (from $-\infty$ to $\infty$ ) under the Gaussian
distribution, $f(x) = \sqrt{b/\pi} e^{-bx^2}$, equals 1. That is,
show that the total probability equals 1. (We have set
$\mu = 0$ for convenience, since $\mu$ doesn't affect
the total area.) There is a very sneaky way to do this.
But since it's completely out of the blue, we'll give
a hint: Calculate the $\emph{square}$ of the desired integral by multiplying
it by the integral of $\sqrt{b/\pi} e^{-by^2}$. Then make use of a change
of variables from Cartesian to polar coordinates, to convert
the Cartesian double integral into a polar double integral.

\vspace{1em}

\begin{proof}
    The area under the curve of the Gaussian is given by:
    \[
        I = \int_{-\infty}^\infty f(x) dx = \sqrt{\frac{b}{\pi}} \int_{-\infty}^\infty e^{-bx^2} dx
    \]
    We take the proposed hint and obtain that:
    \[
        I^2 = \bigg(\sqrt{\frac{b}{\pi}} \int_{-\infty}^\infty e^{-bx^2} dx\bigg)
            \bigg(\sqrt{\frac{b}{\pi}} \int_{-\infty}^\infty e^{-by^2} dy\bigg)
        = \frac{b}{\pi} \int_{-\infty}^\infty \int_{-\infty}^\infty e^{-b(x^2 + y^2)} dxdy
    \]
    Now, we convert to polar coordinates by using the substitutions
    $x = r\sin \theta, y = r\cos \theta$ and get:
    \[
        I^2 = \frac{b}{\pi} \int_0^{2\pi} \int_0^\infty e^{-br^2} r drd\theta
    \]
    We compute the inner integral separately by using the substitution
    $t = r^2$, so:
    \[
        \int_0^\infty e^{-br^2}r dr
        = \frac{1}{2} \int_0^\infty e^{-bt} dt
        = -\frac{e^{-bt}}{2b} \bigg|_0^\infty
        = \frac{1}{2b}
    \]
    Our expression becomes:
    \[
        I^2 = \frac{1}{2\pi} \int_0^{2\pi} d\theta = 1
    \]
    Therefore, we proved that the Gaussian distribution is normalized:
    \[
        I = \int_0^\infty f(x) = 1
    \]
\end{proof}

\section*{4.23. Variance of the Gaussian distribution}
\addcontentsline{toc}{section}{4.23. Variance of the Gaussian distribution}
Show that the variance of the second Gaussian expression in Eq. (4.42)
equals $\sigma^2$. You may assume that $\mu = 0$ (because $\mu$ doesn't
affect the variance), in which case the expression for the variance
in Eq. (3.19) becomes $E(X^2)$. And then by the reasoning in
Problem 4.2, this expectation value is $\int x^2f(x)dx$. So the
task of this problem is to evaluate this integral. The straightforward method
is to use integration by parts.

\vspace{1em}

\begin{proof}
    We follow the hint and use integration by parts, so:
    \begin{align*}
        E[X^2]
        = \int_{-\infty}^\infty x^2 f(x) dx
        = \sqrt{\frac{b}{\pi}} \int_{-\infty}^\infty x^2 e^{-bx^2} dx
        &= \sqrt{\frac{b}{\pi}} \int_{-\infty}^\infty x \big(xe^{-bx^2}\big) dx
        = \sqrt{\frac{b}{\pi}} \int_{-\infty}^\infty x \bigg(-\frac{1}{2b}e^{-bx^2}\bigg)' dx \\
        &= -\frac{1}{2} \sqrt{\frac{b}{\pi}} xe^{-bx^2} \bigg|_{-\infty}^\infty
            + \frac{1}{2b} \sqrt{\frac{b}{\pi}} \int_{-\infty}^\infty e^{-bx^2} dx
    \end{align*}

    One can easily prove using L'Hopital's rule that
    \[
        \lim_{x \to \infty} xe^{-bx^2} = \lim_{x \to -\infty} xe^{-bx^2} = 0
    \]

    Therefore the first term in the result is 0. Since we know that
    the Gaussian distribution is normalized from Problem 4.22, we obtain that
    \[
        E[X^2] = \frac{1}{2b} \sqrt{\frac{b}{\pi}} \int_{-\infty}^\infty e^{-bx^2} dx
        = \frac{1}{2b}
        = \sigma^2
    \]
\end{proof}


\section{Sets and set notation}

A set is a collection\index{set notation} of things called elements.
For example $\set{1,2,3,8} $
would be a set consisting of the elements 1,2,3, and 8. To indicate that $3$
is an element of $\set{1,2,3,8}$, it is customary to write $3\in
\set{1,2,3,8}$. We can also indicate when an element is not in a set,
by writing $9\notin \set{1,2,3,8} $ which says that $9$ is
not an element of $\set{1,2,3,8}$. Sometimes a rule specifies a
set. For example you could specify a set as all integers larger than $2$.
This would be written as $S=\set{x\in \Z:x>2}$. This
notation says: $S$ is the set of all integers, $x$, such that $x>2$.

Suppose $A$ and $B$ are sets with the property that every element of $A$ is an
element of $B$. Then we say that $A$ is a subset of $B$. For example, $\set{
1,2,3,8} $ is a subset of $\set{1,2,3,4,5,8}$. In symbols, we write
$\set{1,2,3,8} \subseteq \set{1,2,3,4,5,8}$. It is
sometimes said that ``$A$ is contained in $B$" or even ``$B$ contains $A$".
The same statement about the two sets may also be written as $\set{
1,2,3,4,5,8} \supseteq \set{1,2,3,8}$.

We can also talk about the {\em union}\index{union} of two sets, which we write as $A \cup B$. This is the set consisting of everything which is an
element of at least one of the sets, $A$ or $B$. As an example of the union
of two sets, consider $\set{1,2,3,8} \cup \set{3,4,7,8} =\set{
1,2,3,4,7,8}$. This set is made up of the numbers which are in at least
one of the two sets.\index{$\cup$}

In general
\begin{equation*}
A\cup B = \set{x:x\in A
\text{ or }x\in B}
\end{equation*}
Notice that an element which is in {\em both} $A$ and $B$ is also in the
union, as well as elements which are in only one of $A$ or $B$.

Another important set is the intersection\index{intersection}\index{$\cap$} of two sets $A$ and $B$, written $A \cap B$. This set consists of everything which is in
{\em both} of the sets. Thus $\set{1,2,3,8} \cap \set{3,4,7,8}
=\set{3,8} $ because $3$ and $8$ are those elements the two sets
have in common. In general,
\begin{equation*}
A\cap B =  \set{x:x\in A\text{ and }x\in B}
\end{equation*}

If $A$ and $B$ are two sets, $A\setminus B$\index{$\setminus$} denotes the set of things which
are in $A$ but not in $B$. Thus
\begin{equation*}
A\setminus B =  \set{x\in A:x\notin B}
\end{equation*}
For example, if $A = \set{1,2,3,8 }$ and $B = \set{3,4,7,8 }$, then $A \setminus B = \set{1,2,3,8} \setminus
\set{3,4,7,8 } =\set{1,2 }$.

A special set which is very important in mathematics is the empty set\index{empty set} denoted by $\emptyset$. The empty set, $\emptyset$, is
defined as the set which has no elements in it. It follows that the empty set is a subset of every set.
This is true because if it were not so, there would have to exist a set $A$, such that $\emptyset $
has something in it which is not in $A$. However, $\emptyset $ has nothing
in it and so it must be that $\emptyset \subseteq A$.

We can also use brackets to denote sets which are intervals of numbers. Let $a$ and $b$ be real numbers. Then

\begin{itemize}
\item $[a,b] = \set{x \in \R \mid a\leq x\leq b}$.
\item $[a,b) = \set{x \in \R \mid a\leq x<b}$.
\item $(a,b] = \set{x \in \R \mid a<x\leq b}$.
\item $(a,b) = \set{x \in \R \mid a<x<b}$.
\item $[a,\infty) = \set{x \in \R \mid a\leq x}$.
\item $(-\infty,a] = \set{x \in \R \mid x\leq a}$.
\item $(a,\infty) = \set{x \in \R \mid a<x}$.
\item $(-\infty,a) = \set{x \in \R \mid x<a}$.
\end{itemize}

These sorts of sets of real
numbers are called intervals. The two points $a$ and $b$ are called
endpoints, or bounds, of the interval. In particular, $a$ is the {\em lower bound }  while $b$ is the {\em upper bound } of the above
intervals, where applicable.\index{intervals!notation} Other intervals such as $(-\infty ,b) $
are defined by analogy to what was just explained.
 In general, the curved
parenthesis, $($, indicates the end point is not included in the interval, while
the square parenthesis, $[$, indicates this end point is included. The reason that
there will always be a curved parenthesis next to $\infty $ or $-\infty $ is
that these are not real numbers and cannot be included in the interval in the way a real number can.

To illustrate the use of this notation relative to intervals consider three
examples of inequalities. Their solutions will be written in the interval notation
just described.

\begin{example}{Solving an inequality}{solving-inequality1}
Solve the inequality $2x+4\leq x-8$.
\end{example}

\begin{solution}
We need to find $x$ such that $2x+4\leq x-8$. Solving for $x$, we see that
$x\leq -12$ is the answer. This is written in terms of an interval as $(-\infty ,-12]$.
\end{solution}

Consider the following example.

\begin{example}{Solving an inequality}{solving-inequality2}
Solve the inequality $(x+1) (2x-3) \geq0$.
\end{example}

\begin{solution}
We need to find $x$ such that $(x+1) (2x-3) \geq0$.
The solution is given by  $x\leq -1$ or $x\geq \frac{3}{2}$. Therefore,
$x$ which fit into either of these intervals gives a solution. In terms of set notation this is denoted by $(-\infty ,-1]\cup
[ \vspace{0.05in}\frac{3}{2},\infty )$.
\end{solution}

Consider one last example.

\begin{example}{Solving an inequality}{solving-inequality3}
Solve the inequality $x (x+2) \geq-4$.
\end{example}

\begin{solution}
This inequality is true for any value of $x$ where $x$ is a real number. We can write the solution as $\R$ or $(
-\infty ,\infty)$.
\end{solution}

In the next section, we examine another important mathematical concept.


\subsection{Integer Linear Programming Model}

\subsubsection{Decision Variables}

\begin{equation}
    \label{eq:decision-variables}
    \varE =  \begin{cases}
      1 &, \solutionE \in \solution \\
      0 &, \solutionE \notin \solution
   \end{cases}
\end{equation}

\subsubsection{Mathematical Model}

\begin{align}
    \label{eq:ILP-objective}
    \max\limits_{\solution \subseteq \vertices}
        & \Sum{\solutionE \in \solution}{}{\varE} \\
    s.t.
    \label{eq:ILP-capacity-constraint}
    & \Sum{\solutionE \in \solution}{}{\varE \weightE} \leqslant \maximumWeight \\
    \label{eq:ILP-order-constraint}
    & \var_{\solutionE} \leqslant \var_{\solutionEp} \quad \forall \solutionEp \partialLower \solutionE \\
    \label{eq:ILP-binary-constraint}
    & \var \in \varDomain
\end{align}

\eqref{eq:ILP-objective} is the objective function: maximize the number of vertices in the solution.
\eqref{eq:ILP-capacity-constraint} is the Capacity-Constraint of \eqref{eq:capacity-constraint}.
\eqref{eq:ILP-order-constraint} is the Precedence-Constraint of \eqref{eq:precedence-constraint}: if a vertex $\solutionE$ is in the solution, then all vertices $\solutionEp$ for which there is a path from $\solutionE$ must also be in the solution.


\section{Game Theory}
\subsection{Two-person Zero-sum Games}
Consider a game where there are two players called Player I and Player II.
Player I has $m$ choices of strategies labeled by $i\in\{1,\ldots,m\}$ and Player II has $n$ choices of strategies $j\in\{1,\ldots,n\}$.
We assume that the game is zero-sum, i.e. if Player I chooses strategy $i$ and Player II chooses strategy $j$, then Player I is paid $a_{i,j}$ and Player II is paid $-a_{i,j}$.
So the net payment across the game is zero.
The matrix $A=(a_{i,j})$ is called the payoff matrix of the game.
This is an $m\times n$ matrix.
Assume that both players want to maximise their payoff and they know the other wants it too.
\footnote{And they know the other knows they want it, and they know the other knows they know the other wants it, etc.}\\
Player I might want to solve the maximisation of $\min_ja_{ij}$ subject to $i\in\{1,\ldots,m\}$ and Player II to solve the minimisation of $\max_ia_{ij}$ subject to $j\in\{1,\ldots,n\}$.
\begin{example}
    Consider
    $$A=\begin{pmatrix}
        1&2\\
        3&4
    \end{pmatrix}$$
    Then obviously Player I will pick $i=2$ and Player II will pick $j=1$.
    This is independent of who playing first.
\end{example}
Such a point $(2,1)$ in the above example with the said property is called a saddle point of the matrix.
\begin{definition}
    A saddle point of a payoff matrix $A$ is a pair of strategies $(i,j)$ with the property
    $$a_{i,j}=\max_{i'}\min_{j'}a_{i',j'}=\min_{j'}\max_{i'}a_{i',j'}$$
    If a payoff matrix $A$ has saddle point $(i,j)$, then $a_{i,j}$ is called the value of the game.
\end{definition}
Not all payoff matrices have a saddle point, an easy example is
$$A=\begin{pmatrix}
    4&2\\
    1&3
\end{pmatrix}$$
where $\max_i\min_ja_{i,j}=2\neq 3=\min_j\max_ia_{i,j}$.
\subsection{Pure and Mixed Strategies}
Often, the game has the property that the players choose their strategies simultaneously.
The idea to analyse these games is to randomise the strategies.
\begin{definition}
    A mixed strategy is an assignment of probabilities to each of the individual strategies.
    A pure strategy is a mixed strategies assigning $1$ to one particular strategy and $0$ to all others.
\end{definition}
We use the notation that Player I plays strategy $i$ with probability $p_i$ and Player II plays strategy $j$ with probability $q_j$.
Therefore Player I would want to maximise
$$\min_j\mathbb E[\text{payout}|\text{Player II picks strategy $j$}]$$
which translates to maximising
$$\min_j\sum_{i=1}^mp_ia_{i,j}$$
subject to
$$\sum_{i=1}^mp_i=1,\forall i\in\{1,\ldots,m\},p_i\ge 0$$
We can turn this into a linear program.
Introducing $e=(1,\ldots,1)^\top$ (dimension implied by context), then the problem can be written as maximising $v\in\mathbb R$ subject to $A^\top p\ge ve,e^\top p=1,p\ge 0$.
Similarly, the optimisation problem for Player II can be written as minimising $w$ subject to $Aq\le we, e^\top q=1,q\ge 0$.\\
Unsurprisingly, these two problems are naturally dual to each other.
Indeed, one can observe that the Lagrangian of Player I is
\begin{align*}
    L(p,v,z,q,w)&=v+q^\top(A^\top p-z-ve)+w(1-p^\top e)\\
    &=w+v(1-q^\top e)+p^\top(Aq-we)-z^\top q
\end{align*}
where $z$ is the slack variable.
So the feasible Lagrange multipliers are constrained by $q\ge 0,Aq\le we,e^\top q=1$ and $\sup L=w$.\\
By the fundamental theorem of linear programs, $(p,v)$ is optimal iff there is some $(q,w)$ such that both tuples are feasible and
$$(Ap-we)^\top p=0=q(A^\top p-ve)$$
Where we see $wp^\top e=vq^\top e$, so $v=w$ in optimal case as one would expect.
\begin{theorem}[Fundamental Theorem of Matrix Games]
    The mixed row strategy $p$ is optimal for Player I iff there exists a mixed column strategy $q$ for Player II and $v\in\mathbb R$ such that:\\
    1. $A^\top p\ge ve,e^\top p=1,p\ge 0$.\\
    2. $Aq\le ve,e^\top q=1,q\ge 0$.\\
    3. $v=p^\top Aq$.
    In this case, $(p,v)$ is optimal for the problem of Player I and $(q,v)$ is optimal for Player II.
\end{theorem}
\begin{proof}
    Immediate.
\end{proof}
The value $v$ above is called the value of the game.
Hence, for optimal mxied strategies, complementary slackness ensures that if Player II plays $j$ with positive probability, then the conditional expected payoff given Player II plays $j$ equals the value of the game.
An analogous statement works the other way around.
In other words,
$$\begin{cases}
    q_j>0\implies (A^\top p)_j=v\\
    p_i>0\implies (Aq)_i=v
\end{cases}$$
\begin{definition}
    A game is symmetric if the payoff matrix is antisymmetric.
    That is $A^\top=-A$.
\end{definition}
\begin{example}
    The rock-paper-scissors game
    $$\begin{pmatrix}
        0&-1&1\\
        1&0&-1\\
        -1&1&0
    \end{pmatrix}$$
    is symmetric.
\end{example}
\begin{theorem}
    A symmetric game has zero value.
\end{theorem}
This is very intuitive by symmetry.
We can also make use of our oven-ready fundamental theorem.
\begin{proof}
    Suppose $(p,v,q)$ satisfy the (necessary) conditions of optimality, then by antisymmetry of $A$, the tuple $(q,-v,p)$ satisfies the (sufficient) condition of optimality.
    Hence $v=-v\implies v=0$.
\end{proof}
\subsection{Finding Optimal Strategies}
If the game admits a saddle point $(i,j)$, then by definition the pure strategy $i$ is optimal for Player I and the strategy $j$ is optimal for Player II, consequently the value of the game is $a_{i,j}$.
Otherwise, we reduce the game by eliminating dominating strategies.
A row $i$ dominates $i'$ is $a_{i,j}\ge a_{i',j}$ for any $j$, so if a row $i'$ is dominated by some other row, then Player I will never play strategy $i'$.
Similarly if there is some $j,j'$ with $a_{i,j}\le a_{i,j'}$ for any $i$, then Player II will never play $j'$.
\begin{example}
    Consider the payoff matrix
    $$A=\begin{pmatrix}
        2&3&4&2\\
        3&1&1/2&4\\
        1&3&2&3
    \end{pmatrix}$$
    One can check that there is no saddle point.
    Also, the first column dominates the fourth column, so Player II will never play the fourth column.
    After eliminating that, the first row dominates the third row, so the third row is eliminated too, leaving a modified payoff matrix
    $$A'=\begin{pmatrix}
        2&3&4\\
        3&1&1/2
    \end{pmatrix}$$
    So the optimal strategy $p$ of Player I  is of the form $(p_1,1-p_1,0)^\top$.\\
    Now the region $(A')^\top p'\ge ve$ (where $p'=(p_1,1-p_1)^\top$ are the remaining relevant strategies) is given by
    $$\begin{cases}
        2p_1+3(1-p_1)\ge v\implies v\le 3-p_1\\
        3p_1+(1-p_1)\ge v\implies v\le 1+2p_1\\
        4p_1+(1-p_1)/2\ge v\implies v\le (1+7p_1)/2
    \end{cases}$$
    So by sketching the graph of $v$ against $p_1$, we find that the maximum $v$ occurs at $p_1=2/3$ and the optimal strategy of Player I is $p=(2/3,1/3,0)^\top$, and the value of the game is $v=7/3$.\\
    By complementary slackness $q_3=0$ as the third constraint is not tight.
    So $q=(q_1,1-q_1,0,0)^\top$ for some probability $q_1$.
    As $p_1=2/3>0$, the first dual constraint is binding by complementary slackness, so
    $$2q_1+3(1-q_1)=7/3\implies q_1=2/3$$
    Therefore $q=(2/3,1/3,0,0)^\top$.
\end{example}
If it does not get clear after using these tricks, one can always use the simplex algorithm.
If $\min_{i,j}a_{i,j}>0$ then we know $v$ is strictly positive, hence we can rewrite the problem of Player I as maximising $v$ subject to $A^\top x\ge e,e^\top x=1/v,x\ge 0$ where $x=p/v$.
This is equivalent to minimising $e^\top x$ subject to $A^\top x\ge e,x\ge 0$ which is a form where we can apply simplex algorithm to.
Note that its dual problem is maximising $e^\top y$ subject to $Ay\le e,y\ge 0$ which is in a form for Phase I of the two-phase algorithm.\\
If instead $\min_{i,j}a_{i,j}\le 0$, we can still use the same idea.
Just find some $k$ such that $a'_{i,j}=a_{i,j}+k>0$ for all $i,j$ and roll out the same algorithm on $A'=(a'_{i,j})$.
Then the optimal strategy of $A,A'$ would be the same and the new value $v'$ would satisfy $v=v'-k$ where $v$ is the value of the original game.
\begin{example}
    Consider the game of Rock-Paper-Scissors, i.e.
    $$A=\begin{pmatrix}
        0&-1&1\\
        1&0&-1\\
        -1&1&0
    \end{pmatrix}$$
    Then we consider the modified game
    $$A'=\begin{pmatrix}
        2&1&3\\
        3&2&1\\
        1&3&2
    \end{pmatrix}$$
    where $k=2$.
    So the problem of Player II is to maximise $y_1+y_2+y_3$ subject to
    $$\begin{cases}
        2y_1+y_2+3y_3\le 1\\
        3y_1+2y_2+y_3\le 1\\
        y_1+3y_2+2y_3\le 1\\
        y_1,y_2,y_3\ge 0
    \end{cases}$$
    So the initial simplex tableau is
    $$\begin{array}{c|cccccc|c}
        &&&&\ast&\ast&\ast&\\
        &y_1&y_2&y_3&z_1&z_2&z_3&\\ \hline
        z_1&2&1&3&1&0&0&1\\
        z_2&3&2&1&0&1&0&1\\
        z_3&1&3&2&0&0&1&1\\ \hline
        \text{Payoff}&1&1&1&0&0&0&0
    \end{array}$$
    and the final tableau would be
    $$\begin{array}{c|cccccc|c}
        &\ast&\ast&\ast&&&&\\
        &y_1&y_2&y_3&z_1&z_2&z_3&\\ \hline
        y_3&0&0&1&7/18&-5/18&1/18&1/6\\
        y_1&1&0&0&1/18&7/18&-5/18&1/6\\
        y_2&0&1&0&-5/18&1/18&7/18&1/6\\ \hline
        \text{Payoff}&0&0&0&-1/6&-1/6&-1/6&-1/2
    \end{array}$$
    Therefore $v'=2$, so $v=0$.
\end{example}


\section{Metric Space}
\begin{definition}
    Let $M$ be an arbitrary set, a metric on $M$ is a function $d:M\times M\to\mathbb R_{\ge 0}$ such that the following properties hold:\\
    1. $\forall x,y\in M,d(x,y)=0\iff x=y$.\\
    2. $\forall x,y\in M,d(x,y)=d(y,x)$.\\
    3. $\forall x,y,z\in M, d(x,y)+d(y,z)\ge d(z,x)$.\\
    The couple $(M,d)$ is called a metric space.
\end{definition}
\begin{example}
    1. Let $M$ be $\mathbb R$ or $\mathbb C$, and $d(x,y)=|x-y|$ is called the usual metric on those sets.\\
    2. Take $M=\mathbb R^n$ or $\mathbb C^n$, then
    $$d((x_1,\ldots,x_n),(y_1,\ldots,y_n))=\sqrt{|x_1-y_1|^2+\ldots+|x_n-y_n|^2}$$.
    This is called the $\ell^2$ metric.\\
    3. Take the same $M$, then we can also have the $\ell^1$ metric where
    $$d((x_1,\ldots,x_n),(y_1,\ldots,y_n))=|x_1-y_1|+\ldots+|x_n-y_n|$$
    4. Also the same $M$, we have the $\ell^\infty$ metric where
    $$d((x_1,x_2,\ldots,x_n),(y_1,y_2,\ldots,y_n))=\max_{i}|x_i-y_i|$$
    5. We can have the $\ell^p$ metric for $p\ge 1$ where
    $$d((x_1,\ldots,x_n),(y_1,\ldots,y_n))=\sqrt[p]{|x_1-y_1|^p+\ldots+|x_n-y_n|^p}$$
    6. Let $S$ be a set and $M=\ell_\infty S$ be the set of bounded scalar function on $S$.
    The metric we can take is the uniform metric $d(f,g)=\sup_S|f-g|$, which is well-defined since $f,g$ are bounded.\\
    7. Let $M$ be any set, then define
    $$d(x,y)=\begin{cases}
        1\text{, if $x=y$}\\
        0\text{, otherwise}
    \end{cases}$$
    This is called the \textit{discrete metric} and the space $(M,d)$ the discrete metric space.\\
    8. Let $G$ be a group that is generated by a symmetric set $S$.
    Define $d(x,y)$ be the least integer $n\ge 0$ such that $n$ is the least number of generators to get from $X$ to $y$.\\
    This develops to the discipline called geometric group theory.\\
    9. Suppose $G$ is a connected (finite) graph, then we can define the distance between two vertices $x,y$ to be the length of the shortest path from $x$ to $y$.\\
    10. Riemannian metric in geometry.\\
    11. Take $M$ to be the integers and we fix a prime $p$.
    We can define the $p$-adic metric $d_p(x,y)$ to be $0$ if $x=y$ and $\|x-y\|_p=p^{-n}$ where $n$ is the greatest power of $p$ in the prime factorisation of $|x-y|$.
    It is obvious that it is a metric.
    The metric space $(\mathbb Z,d_p)$ is called the $p$-adic integers.\\
    12. Let $M$ be the set of all functions from $\mathbb N$ to $\mathbb R$, that is, the set of all sequences.
    So for $x=(x_n),y=(y_n)$, we define $d(x,y)=\sum_{n=0}^\infty 2^{-n}\min\{1,|x_n-y_n|\}$.
\end{example}
As in before, we can construct new objects from old.
\begin{definition}
    Let $(M,d)$ be a metric space and $N\subseteq M$, then $(N,d|_{N\times N})$ is a metric space and is called the metric subspace of $(M,d)$.
    Sometimes we denote $(N,d|_{N\times N})$ by $(N,d)$.
\end{definition}
\begin{example}
    $C[0,1]$ be the set of real continuous functions on the unit interval having the uniform metric is a subspace of $l_\infty[0,1]$.
\end{example}
Note that there are other metrics on $C[0,1]$, for example
$$d(f,g)=\int_0^1|f(x)-g(x)|\,\mathrm dx$$
We also have the $L^2$ metric
$$d(f,g)=\sqrt{\int_0^1|f(x)-g(x)|\,\mathrm dx}$$
Note that the $L^\infty$ metric is the uniform metric.
\begin{definition}
    Let $(M,d),(N,d')$ be two metric spaces, we can define the metric product space by taking the underlying set $M\times N$ and the metric
    $$d_p((m_1,n_1),(m_2,n_2))=(d(m_1,m_2)^p+d'(n_1,n_2)^p)^{1/p}$$
    for some $p\ge 1$ or
    $$d_\infty((m_1,n_1),(m_2,n_2))=\max(\{d(m_1,m_2),d'(n_1,n_2)\})$$
    We can generalize it to any finite product of metric space.
\end{definition}
We need to generalize to topological spaces to have the notion of a quotient space in a metric/topological space.\\
We can introduce (uniform) convergence again in any metric spaces.
We work in a metric space $(M,d)$.
\footnote{When $d$ is understood, we do not usually state explicitly our metric $d$}
\begin{definition}
    Given a sequence $x_n$ in $M$ and a point $x\in M$, we say $x_n\to x$ as $n\to\infty$ if for any $\epsilon>0,\exists N\in\mathbb N,\forall n>N,d(x_n,x)<\epsilon$.\\
    Conversely, if such an $x$ exists for a sequence $x_n$, we say $x_n$ is convergent.
\end{definition}
\begin{lemma}
    Assume $x_n\to x$ and $x_n\to y$, then $x=y$.
\end{lemma}
\begin{proof}
    Assume for the sake of contradiction that it is not the case.
    We let $\epsilon=d(x,y)$, we have a large enough $N\in\mathbb N$ such that $n\in\mathbb N\implies d(x_n,x)<\epsilon/2, d(x_n,y)<\epsilon/2$, so
    $$\epsilon=d(x,y)\le d(x,x_n)+d(y,y_n)<2\epsilon/2=\epsilon$$
    A contradiction.
\end{proof}
Now we can introduce the concept of limit.
\begin{definition}
    Let $(x_n)$ be a convergent sequence which converges to $x$, we write
    $$\lim_{n\to\infty}x_n=x$$
\end{definition}
\begin{example}
    1. In $\mathbb R, \mathbb C$, this is the usual notion of convergence.\\
    2. Take the integers under the $2$-adic metric, $2^n\to 0$ as $n\to\infty$.\\
    3. A sequence which is eventually constant converges to that constant.
    Obviously the converse is false in general, but true in discrete metric spaces.\\
    4. Choose a nonempty set $S$, then functions that converge under the (induced) uniform metric on $\ell_\infty S$ converges uniformly as functions.
    This sometimes can work even on functions $\notin\ell_\infty S$, for example take $S=\mathbb R$, then $f_n(x)=x+1/n$ converges uniformly to the identity function.\\
    5. Consider the space $\mathbb R^{\mathbb N}$, the set of all sequences on $\mathbb R$ with the metric
    $$d((x_n),(y_n))=\sum_{n=1}^\infty 2^{-n}\min{\{1, |x_n-y_n|\}}$$
    then we can show that a sequence of sequences $(x^{(n)}_k)$ (where each $n$ gives a sequence) converges to a sequence $(x_k)$ if and only if for each $i$, $x^(n)_i\to x_i$.\\
    In fact, if we fix a set $S$, is there always a metric $d$ on $\mathbb R^S$ such that $f_n\to f$ under the metric $d$ if $f_n\to f$ pointwise on $S$?
    The answer is no, as we will need topological tools for it.\\
    6. Consider $C[0,1]$ under the uniform metric.
    Surely the function defined by $f_n=x^n$ do not converge, but if we equip $C[0,1]$ with a different metric, for example the $L^1$ metric, that is,
    $$d(f,g)=\int_0^1|f(x)-g(x)|\,\mathrm dx$$
    In this case, the sequence $f_n$ does converge to $0$.\\
    7. Let $(M,d),(M',d')$ be two metric spaces, we consider the metric product space $M\oplus_pM'=(M\times M',d_p)$.
    Then $(x_n,y_n)\to (x,y)$ if and only if $x_n\to x,y_n\to y$.\\
    8. Consider the metric subspace $N\subset M$.
    If a sequence $x_n$ converge to $x$ in $N$, then $x_n\to x$ in $M$.
    The converse is not true since we can take $N=M\setminus\{x\}$ if $x_n\to x$.
\end{example}
\begin{definition}
    Let $(M,d),(M',d')$ be two metric spaces and $f:M\to M'$ be a function.
    We say $f$ is continuous at $a\in M$ if
    $$\forall\epsilon>0,\exists\delta>0,\forall b\in M,d(a,b)<\delta\implies d'(f(a),f(b))<\epsilon$$
    If $f$ is continuous at every $a\in N\subseteq M$, then we say $f$ is continuous on $N$.
\end{definition}
Note that if $f$ is continuous on $M$, it is continuous on any $N\subseteq M$.
The converse, however, is not true.
\begin{example}
    We can take both metric spaces to be $\mathbb R$, then consider the function
    $$f(x)=\begin{cases}
        1\text{, if $x\neq 0$}\\
        0\text{, otherwise}
    \end{cases}$$
    Then $f$ is continuous on $N=\mathbb R\setminus\{0\}$ but not on $M=\mathbb R$.
\end{example}
\begin{proposition}
    $f$ is continuous at $a$ if any only if for any sequence $x_n\to a$, we have $f(x_n)\to f(a)$.
\end{proposition}
\begin{proof}
    If $f$ is continuous at $a$, then $\forall\epsilon>0$, we can find some $\delta>0$ such that $d(a,b)<\delta\implies d'(f(a),f(b))<\epsilon$.
    Now, find any $x_n\to a$, we can find $N\in\mathbb N, \forall n>N, d(a,x_n)<\delta$, but with the same $N$, $\forall n>N$, we have $d'(f(a),f(x_n))<\epsilon$ by the above.
    So $f(x_n)\to f(a)$.\\
    Conversely, if $x_n\to a\implies f(x_n)\to f(a)$ but $f$ is not continuous at $a$, then we can find $\epsilon>0$ such that $\forall\delta>0$, there is some $x\in M$ such that $d(x,a)<\epsilon$ but $d'(f(x),f(a))>\epsilon$.
    We may set $\delta_n=1/n$ and we can obtain the corresponding $x_n$.
    Now $x_n\to a$ but $f(x_n)\not\to f(a)$.
    This is a contradiction.
\end{proof}
The following two corollaries are then obvious.
\begin{corollary}
    Let $f$ and $g$ be continuous scalar functions, then $f+g, f\times g$ and $f/g$ (providing that $\forall x,g(x)\neq 0$) are all continuous.
\end{corollary}
\begin{corollary}
    If $f:M\to M',g:M'\to M''$ are both continuous, then $g\circ f$ is continuous.
\end{corollary}
One can also prove them using $\epsilon-\delta$, which is not hard either.
\begin{example}
    1. Constant, identity (equipping the same metric) and inclusion (in the sense of metric subspace) functions are continuous.\\
    2. Real and complex polynomials are continuous.\\
    3. The metric function itself is continuous (in fact Lipschitz) with respect to the $d_p$ metric on $M\times M$.
\end{example}
\begin{definition}
    A function $(M,d)\to (M',d')$ is Lipschitz continuous if there is some $C\ge 0$ such that
    $$\forall x,y\in M,d'(f(x),f(y))\le Cd(x,y)$$
    we sometimes call $f$ to be $C$-Lipschitz.
\end{definition}
\begin{proposition}
    A Lipschitz function is uniformly continuous.
\end{proposition}
\begin{proof}
    Trivial.
\end{proof}
\begin{definition}
    A map $g:(N,d)\to (N',d')$ is isometric if
    $$\forall x,y\in N,d'(g(x),g(y))=d(x,y)$$
    Note that an isometric function is $1$-Lipschitz.
    It also implies injective.
\end{definition}
We continue with examples.
\begin{example}
    4. Let $M,M'$ be metric spaces, fixing $y\in M'$, $f:M\to M\oplus_pM'$ by $f(x)=(x,y')$ is isometric, hence also ($1$-)Lipschitz.\\
    5. Let $(M,d), (M',d')$ be metric spaces.
    Consider $q:M\oplus_pM'\to M, q':M\oplus_pM'\to M'$ be the projection functions.
    Both of these functions are $1$-Lipschitz. %sometimes it is also isometric like Rn
    We can easily extend it to a finite product of metric spaces.
\end{example}
Now we go on to talk about the topology of metric spaces.
We start with two observations.
Firstly, in a product metric space $M\oplus_pM'$, convergence does not depend on the value of $p$.
Secondly, continuity depends on the convergent sequences.
\begin{definition}
    We fix a metric space $(M,d)$, for $x\in M$ and $r\ge 0$, the open ball $D_r(x)$ is the set $\{y\in M:d(x,y)<r\}$.
\end{definition}
So $x_n\to x$ if and only if $\forall\epsilon>0,\exists N\in\mathbb N, n>N\implies x_n\in D_\epsilon(x)$.
And $f:M\to M'$ is continuous at $a\in M$ if and only if $\forall\epsilon>0,\exists\delta>0,\forall x\in M,x\in D_\delta(a)\implies f(x)\in D_\epsilon(f(a))$.
\begin{definition}
    On $(M,d)$, for $x\in M$ and $r\ge 0$, the closed ball $B_r(x)$ is the set $\{y\in M:d(x,y)\le r\}$.
\end{definition}
\begin{example}
    1. When $M$ is the real numbers, then an open ball is an open interval and closed ball is an closed interval.\\
    2. In $\mathbb R^2$, $B_1(0,0)$ is the unit disk with boundary in $d_2$, and an slanted square in $d_1$, and a big square in $d_\infty$.\\
    3. If $M$ is discrete, $D_1(x)=\{x\},B_1(x)=M$.
\end{example}
Note that $B_s(x)\subset D_r(x)\subset B_r(x)$ for any $s<r$.
\begin{definition}
    A subset $U\subset M$ with $x\in U$ is called a neighbourhood of $x$ (in $M$) if there exists some $r>0$ with $D_r(x)\subset U$.
\end{definition}
It does not matter if we take the closed ball instead.
\begin{definition}
    Given $U\subset M$, we say $U$ is open if $\forall x\in U, \exists r>0, D_r(x)\subset U$.
\end{definition}
So $U$ is open if and only if $U$ is a neightbourhood of $x$ for any $x\in U$.
\begin{lemma}
    Open balls are open.
\end{lemma}
\begin{proof}
    Immediate from definition but let us write the proof anyways.\\
    Consider $D_r(x)$, then for any $y\in D_r(x)$, since $d(x,y)<r$, if $z\in D_{r-d(x,y)}(y)$, then $d(x,z)\le d(y,z)+d(x,y)<r\implies D_{r-d(x,y)}(y)\subset D_r(x)$.
\end{proof}
\begin{proposition}\label{metric_nbhdconv}
    In a metric space $M$, the followings are equivalent:\\
    1. $x_n\to x$.\\
    2. For any neighbourhood $U$ of $x$, there is some $N\in\mathbb N, \forall n>N, x_n\in U$.\\
    3. For any open set $U$ containing $x$, there is some $N\in\mathbb N, \forall n>N, x_n\in U$.
\end{proposition}
\begin{proof}
    $1\implies 2$: $\exists r>0,D_r(x)\subset U$, so we can choose an $N\in\mathbb N,\forall n>N, d(x_n,x)<r\implies x_n\in U$.\\
    $2\implies 3$: Immediate by the preceding lemma.\\
    $3\implies 1$: Given $\epsilon>0$, take $U=D_\epsilon(x)$, then two statement becomes identical.
\end{proof}
\begin{proposition}\label{metric_preimage}
    Given function $f:M\to M'$, then:\\
    (A) For $a\in M$, the followings are equivalent:\\
    1. $f$ continuous at $a$.\\
    2. For any neighbourhood $V$ of $f(a)$, there is a neighbourhood $U$ of $a$ such that $f(U)\subset V$.\\
    3. For any neighbourhood $V$ of $f(a)$, $f^{-1}(V)$ is a neighbourhood of $a$.\\
    (B) The followings are equivalent:\\
    1. $f$ is continuous.\\
    2. The pre-image of any open set is open.
\end{proposition}
\begin{proof}
    Part (A):\\
    $1\implies 2$: Given any neighbourhood $V$ of $f(a)$, there is some $r$ such that $D_r(f(a))\subset V$.
    Since $f$ is continuous at $a$, there is $\delta>0$ with $f(D_\delta(a))\subset D_r(f(a))\subset V$.
    So $U=D_\delta(a)$ works.\\
    $2\implies 3$: Trivial since there is some neighbourhood $U$ containing $a$ with $f(U)\subset V\implies U\subset f^{-1}(V)$ so it is a neighbourhood of $a$.\\
    $3\implies 1$: Given $\epsilon>0$, $f^{-1}(D_\epsilon(f(a)))$ contains some open ball $D_\delta(a)$ for some $\delta>0$, so it's done.\\
    Part (B):\\
    $1\implies 2$: Given $V$ open in $M'$, for $x\in f^{-1}(V)$, we have $f(x)\in V$, so $V$ is a neighbourhood of $f(x)$.
    Since $f$ is continuous, by (A), there is an neighbourhood of $x$ containing in it.\\
    $2\implies 1$: We shall show that it is continuous at every point.
    Given $\epsilon>0,a\in M$, the ball $D_\epsilon(f(a))$ is open in $M'$, so $f^{-1}(D_\epsilon(f(a)))$ is open, so there is some $\delta$ with $D_\delta(a)\subset f^{-1}(D_\epsilon(f(a)))$, so we are done.
\end{proof}
\begin{definition}
    The topology of a metric space the collection of open subsets of it.
\end{definition}
\begin{proposition}\label{metric_topology}
    In a metric space $M$, we have the following:\\
    1. $\varnothing,M$ are open.\\
    2. If $\{U_i\}_{i\in I}$ are open, then $\bigcup_{i\in I}U_i$ is open.
    3. If $U,V\subset M$ are open, then $U\cap V$ is open.
\end{proposition}
\begin{proof}
    1 is trivial.\\
    For 2, given $x$ in the union, then there is a $j\in I$ such that $x\in U_j$, but then there is some open ball $U\ni x$ such that $U\subset U_j$, then $U$ is a subset of that union.
    So this union is open.\\
    Regarding 3, given $x\in U\cap V$, then there are $\epsilon_U,\epsilon_V>0$ such that $D_{\epsilon_U}(x)\subset U,D_{\epsilon_V}(x)\subset V$, so the ball $D_{\min\{\epsilon_U,\epsilon_V\}}(x)\subset U\cap V$.
\end{proof}
\begin{definition}
    A subset $A\subset M$ is closed if whenever $x_n\to x$ in $M$ for some sequece $(x_n)\in A$, then $x\in A$.
\end{definition}
\begin{example}
    1. Closed balls are closed.\\
    2. So in $\mathbb R$, any closed interval is closed.
    Also $\mathbb R$ itself is both open and closed.
    $[0,1)$ is neither open nor closed.
\end{example}
\begin{lemma}\label{metric_complement}
    A subset $A\subset M$ is closed if and only if $M\setminus A$ is open.
\end{lemma}
\begin{proof}
    If $A$ is closed but $M\setminus A$ is not open, so there is some $x\in M\setminus A$ such that $D_r(x)$ is not contained in $M\setminus A$ for all $r>0$.
    Hence for each $\epsilon>0, \exists x_\epsilon \in M, x_\epsilon\in D_\epsilon(x)$.
    Taking $a_n=x_{1/n}$ gives a contradiction.\\
    If $A$ is not closed but $M\setminus A$ is open.
    So we can find $(a_n)\in A$ such that $a_n\to a\notin A$, so there is some $\epsilon>0$ such that $D_\epsilon(a)\subset M\setminus A$, but this is a contradiction since $a_n\notin M\setminus A$ for any $n$ but it can go $\epsilon$-close to $a$.
\end{proof}
\begin{example}
    If $(N,d)$ is discrete, then every subset of $N$ is both open and closed.
\end{example}
\begin{definition}
    Two metrics on a set are equivalent if they give the same topology.
\end{definition}
Note that it is equivalent to say that the teo metrics have the same convergence sequences since they help identify the closed sets.
It also means that they have the same continuous functions, both to and from, any other spaces.
Note that the two metrics induce the same topology if and only if the identity maps from both spaces are continuous.
\begin{definition}
    A map $g:M\to M'$ is called a homeomorphism if it is a bijection and both $g$ and $g^{-1}$ are continuous.\\
    We say $g$ is an isometry if it is bijective and it is isometric.\\
    We say $M$ and $M'$ are homeomorphic if there is a homeomorphism between them.
    And $M$, $M'$ be isometric if there is an isometry between them.
\end{definition}
\begin{remark}
    1. Continuous bijections may not be a homeomorphism.
    Take $g:\mathbb R\to\mathbb R$ where the domain is equipped with discrete metric and the codomain with the usual metric.\\
    2. A surjective isometric function is an isometry.
\end{remark}
\begin{example}
    1. $(0,1),(0,\infty)$ are homeomorphic.
    Take $x\mapsto 1/x$.\\
    2. $\mathbb R^2$ and $\mathbb C$ are isometric.
\end{example}
\begin{definition}
    Two metrics $d,d'$ on $M$ are uniformly equivalent if and only if both the identity functions $\operatorname{id}:(M,d)\to(M,d'),\operatorname{id}:(M,d')\to(M,d)$ are uniformly continuous.\\
    We say $d,d'$ are Lipschitz equivalent if and only if both the identity functions are Lipschitz.
\end{definition}
\begin{example}
    1. On $M\times M'$, $d_1,d_2,d_\infty$ are Lipschitz equivalent.\\
    2. (non-example) On $C[0,1]$ the uniform metric is not equivalent to the $L^1$ metric since they do not have the same convergent sequences.
\end{example}


%%% lecture 1

\section{Introduction}
\subsection{Introduction example}
\label{sub:introduction_example}
We have
\[
	\begin{cases}
		f''+f =g, &\text{ in }I = [0,1]\\
		f(0)=1, \,f'(0)=1
	\end{cases},
\]
where $g$ is a known continous function on $I$. We will now consider different cases:

\begin{enumerate}[1.]
	\item $g=0$
	\[
		\Rightarrow \,f(x) = A \cos(x) + B \sin(x), x \in I,
	\]
	where $A,B \in \mathbb{R}$.
	\item $g$ arbitrary. We will now introduce the Method of variation of constants. Set
	\[
		f(x)=A(x) \cos(x)+ B(x) \sin(x).
	\]
	Differentiate
	\[
		f'(x) = A'(x) \cos(x) + B'(x) \sin(x) - A(x) \sin(x) + B(x) \cos(x).
	\]
	Assume (this is part of the method)
	\[
		A'(x)\cos(x) + B'(x) \sin(x) = 0, \qquad x \in I.
	\]
	Differentiate $f'(x)$ and get
	\[
		f''(x)=\underset{= -f(x)}{\underbrace{-A(x) \cos(x) - B(x) \sin(x)}} - A'(x) \sin(x) + B'(x) \cos(x).
	\]
	We get
	\[
		g(x) = f''(x)+f(x) = -A'(x) \sin(x) + B'(x) \cos(x).
	\]
	Now:
	\[
		\begin{cases}
			A'(x)\cos(x) + B'(x) \sin(x) = 0, & x \in I\\
			- A'(x) \sin(x)+ B'(x) \cos(x) = g(x), & x \in I \\
			A(0)=1, \qquad B(0)=0 &
		\end{cases}.
	\]
	We get
	\begin{align*}
		A'(x) &= - g(x)\sin(x), \\
		A(0) &= 1, \\
		B'(x) &= g(x) \cos(x), \\
		B(0) &=0.
	\end{align*}
	This implies
	\begin{align*}
		A(x) &= A(0) + \int_{0}^{x} A'(t) \,\mathrm{d}t = 1 - \int_{0}^{x} g(t) \sin(t) \,\mathrm{d}t, \\
		B(x) &= B(0) + \int_{0}^{x}B'(t) \,\mathrm{d}t = 0 + \int_{0}^{x}g(t)\cos(t) \,\mathrm{d}t.
	\end{align*}
	Hence
	\begin{align*}
		f(x) &= \cos(x) - \int_{0}^{x} g(t) \sin(t) \,\mathrm{d}t \cos(x) + \int_{0}^{x} g(t) \cos(t) \,\mathrm{d}t \sin(x) \\
		&= \cos(x) + \int_{0}^{x} (\underset{=\sin(x-t)}{\underbrace{\sin(x)\cos(t)- \sin(t)\cos(x)}})g(t) \,\mathrm{d}t \\
		&= \cos(x) + \int_{0}^{x}\sin(x-t)g(t) \,\mathrm{d}t \qquad (*).
	\end{align*}
	Check that $f(x)$ in $(*)$ satisfies the PDE.
	\minisec{special case:}
	Assume for $x \in I$
	\[
		g(x) = k(x)f(x).
	\]
	Here $k$ is a known continous function on $I$. Insert this in $(*)$. We obtain
	\[
		f(x) = \cos(x) + \int_{0}^{x} \sin(x-t)k(t)f(t) \,\mathrm{d}t, \qquad x \in I \qquad (**).
	\]
	Observe that $f$ appears both in LHS and RHS. $(**)$ is a reformulation of the PDE with $g=kf$. Pick a $\underset{\in C(I)}{\underbrace{\text{continous function in $I$}}}$. call it $f_0$. Set
	\begin{align*}
		f_1(x) &= \cos(x) + \int_{0}^{x}\sin(x-t)k(t)f_0(t) \,\mathrm{d}t, \\
		f_2(x) &= \cos(x) + \int_{0}^{x}\sin(x-t)k(t)f_1(t) \,\mathrm{d}t, \\
		\vdots &\qquad \qquad  \vdots \\
		f_{n+1}(x) &= \cos(x) + \int_{0}^{x}\sin(x-t)k(t)f_n(t) \,\mathrm{d}t, \qquad n=1,2,3, \dots. \\
	\end{align*}
	\minisec{Hope:} $f_n$ tends to some continous function $f$ on $I$, denoted $f_n \to f$. 'Tends to' has to be more precis!
	\begin{align*}
		f_{n+1}(x) &= \cos(x) + \int_{0}^{x} \sin(x-t)k(t)f_n(t) \,\mathrm{d}t \\
		\downarrow & \qquad \qquad \downarrow \\
		f(x) &= \cos(x) + \int_{0}^{x} \sin(x-t)k(t)f(t) \,\mathrm{d}t
	\end{align*}
	for $x \in I$. Simplify notation set for $v \in C(I)$
	\[
		\begin{cases}
			u(x)&=\cos(x)\\
			kv(x)&= \int_{0}^{x} \sin(x-t)k(t)v(t) \,\mathrm{d}t
		\end{cases}.
	\]
	We have $f_0 \in C(I)$, $f_{n+1}=u + k f_n$ for $n=0,1,2, \dots$ (!) \\
	Facts from previous calculus classes:
	\begin{definition*}[Sequenze of continous functions]
		\[
			v_n \in C(I), \qquad n=1,2,\dots.
		\]
		We say that $(v_n)_{n=1}^{\infty}$ converges uniformly in $I$ if
		\[
			\max_{x \in I} \abs{v_n(x)-v_m(x)} \to 0 , \qquad n,m \to \infty,
		\]
		i.e.
		\[
			\forall\, \varepsilon >0 \exists\, N: \forall\, n,m \geq N: \, \max_{x \in I}\abs{v_n(x)-v_m(x)}< \varepsilon.
		\]
	\end{definition*}
	\begin{lemma*}
		Suppose that $(v_n)_{n=1}^{\infty}$ converges uniformly on $I$. then there exists $v \in C(I)$ such that
		\[
			 \max_{x \in I}\abs{v_m(x)-v(x)} \to 0 \qquad \text{as }m \to \infty.
		\]
	\end{lemma*}
	Back to (!): \\
	\minisec{More Notation:}
	\[
		k(kv) = k^2 v, \qquad v \in C(I)
	\]
	and
	\[
		k^{n+1}v = k(k^nv), \qquad n=1,2,\dots.
	\]
	We have
	\begin{align*}
		f_0 & \in C(I) \\ f_1 &=u+kf_0 \\ \text{ and }
				f_2 &= u + kf_1 = u + k(u+kf_0)
	\end{align*}
	and so on. Note that
	\[
		k(v+w)=kv+kw.
	\]
	Then
	\begin{align*}
		f_2 &= u +k (u+kf_0) = k + ku + k(kf_0) = u + ku +k^2f_0 \\
		f_3 &= u + kf_2 = u + ku + k^2u + k^3f_0
	\end{align*}
	and in general for $n=1,2,\dots$
	\[
		f_n = ku + \dots + k^{n-1}u + k^n f_0, \qquad n=1,2,\dots.
	\]
	Assume $n>m$ then
	\[
		f_n-f_m = k^mu + \dots + k^{n-1}u + k^nf_0 - k^mf_0.
	\]
	Set for $v \in C(I)$
	\[
		\norm{v} = \max_{x \in I}\abs{v(x)}.
	\]
	Note
	\[
		\norm{v+w} \leq \norm{v} + \norm{w} \qquad \text{for }v,w \in C(I)
	\]
	and
	\[
		\norm{-v}=\norm{v}.
	\]
	We have
	\begin{align*}
		\norm{f_n-f_m} &= \norm{k^mu + \dots + k^{n-1}u + k^nf_0 - k^m f_0} \\
		&\leq \norm{k^mu} + \dots + \norm{ k^{n-1}u} + \norm{k^nf_0} + \norm{- k^mf_0}.
	\end{align*}
	Assumption:
	\[
		\sum_{l=1}^{\infty} \norm{k^lv} < \infty \qquad \text{for all }v \in C(I) \qquad (***).
	\]
	Under this assumption
	\[
		\norm{f_n-f_m} \to 0 \qquad \text{as }n,m \to \infty
	\]
	since
	\begin{align*}
		\sum_{l=1}^{\infty}\norm{k^lu} &< \infty \qquad \qquad (u(x)=\cos(x)) \\
		\sum_{l=1}^{\infty}\norm{k^lf_0} &< \infty \qquad \qquad (f_0 \in C(I)).
	\end{align*}
	Conclusion: $(f_n)_{n=1}^{\infty}$ converges uniformly on $I$. By lemma above there exists $f \in C(I)$ such that
	\[
		\max_{x \in I}\abs{f_n(x)-f(x)} \to 0, \qquad n \to \infty,
	\]
	i.e.
	\[
		\norm{f_n -f} \to 0, \qquad n \to \infty.
	\]
	'Back hope':
	$f_n$ tends to $f$, denoted $f_n \to f$ shall be interpretated as
	\[
		\norm{f_n -f} \to 0, \qquad n \to \infty.
	\]
	Remember
	\[
		f_{n+1}(x) = u(x) + k f_n(x) \to ?.
	\]
	For $x \in I$ there is
	\begin{align*}
		\abs{k f_n(x)- kf(x)} &= \abs{ \int_{0}^{x} \sin(x-t)k(t)f_n(t) \,\mathrm{d}t- \int_{0}^{x}\sin(x-t)k(t)f(t) \,\mathrm{d}t} \\
		&\leq \int_{0}^{x}\abs{\sin(x-t)k(t)}\underset{\leq \norm{f_n-f}}{\underbrace{\abs{f_n(t)-f(t)}}} \,\mathrm{d}t \\
		&\leq \int_{0}^{x}\abs{\sin(x-t)k(t)} \,\mathrm{d}t \norm{f_n-f}.
	\end{align*}
	In particular
	\begin{align*}
		\norm{k f_n- kf} &\leq \max_{x \in I}\int_{0}^{x} \underset{\leq 1}{\underbrace{\abs{\sin(x-t)}}} \underset{\max_{t \in I}\abs{k(t)}< \infty}{\underbrace{\abs{k(t)}}} \,\mathrm{d}t \norm{f_n -f} \\
		&\leq \norm{k} \norm{f_n-f}.
	\end{align*}
	We have, provided $(***)$ holds, shown
	\begin{align*}
		f_{n+1} &= u + k f_n \\
		\downarrow & \\
		f &= u + kf.
	\end{align*}
	Let us try to prove $(***)$. For $v \in C(I)$ arbitrary and for $x \in I$
	\begin{align*}
		\norm{kv(x)} &= \abs{\int_{0}^{x}\sin(x-t)k(t)v(t) \,\mathrm{d}t} \\
		&\leq \int_{0}^{x}\underset{\leq 1}{\underbrace{\abs{\sin(x-t)}}}\underset{\leq \norm{k}}{\underbrace{\abs{k(t)}}}\abs{v(t)} \,\mathrm{d}t \\
		&\leq \int_{0}^{x}\underset{\leq \norm{v}}{\underbrace{\abs{v(t)}}} \,\mathrm{d}t \norm{k} \\
		&\leq \norm{k} \norm{v}x.
	\end{align*}
	In particular
	\[
		\norm{kv} \leq \norm{k}\norm{v}
	\]
	and
	\begin{align*}
		\abs{k^2v(x)} &\leq \int_{0}^{x} \abs{kv(t)} \,\mathrm{d}t \norm{k} \\
		&\leq \int_{0}^{x}\norm{k}\norm{v}t \,\mathrm{d}t \cdot \norm{k} \\
		&= \norm{k}^2 \norm{v} \frac{x^2}{2}.
	\end{align*}
	In particular
	\[
		\norm{k^2v} \leq \norm{k}^2 \norm{v} \frac{1}{2}.
	\]
	By induction we get
	\begin{align*}
		\abs{k^n v(x)} &\leq \norm{k}^n \norm{v} \frac{x^m}{m!} \qquad x \in I \\
		\norm{k^n v} &\leq  \norm{k}^n \norm{v} \frac{1}{n!}.
	\end{align*}
	So
	\begin{align*}
		\sum_{l=1}^{\infty}\norm{k^lv} &\leq \sum_{l=1}^{\infty}\norm{k}^l \norm{v} \frac{1}{l!} \\
		&= \norm{v} \sum_{l=1}^{\infty} \frac{\norm{k}^l}{l!} \\
		&\leq \norm{v} e^{\norm{k}} < \infty.
	\end{align*}
	Consider Taylor expansion.
	$\Rightarrow $ $(***)$ holds true. \\
	We have now shown that $f = u+kf$ where $u(x) = \cos(x)$ and
	\[
		kv = \int_{0}^{x}\sin(x-t)k(t)v(t) \,\mathrm{d}t.
	\]
	$x \in I$ for $v \in C(I)$, has a solution $f \in C(I)$. \\
	\minisec{Question:} Is the solution unique? \\
	Assume $f,\tilde f \in C(I)$ such that $f = u + k f$ and $\tilde f = u+ k \tilde f$. Set
	\[
		v = f- \tilde f \in C(I)
	\]
	\begin{align*}
		\Rightarrow v &= (u+kf) - (u+ k \tilde f) \\ &= kf - k \tilde f \\ &= k(f- \tilde f) \\ &= kv.
	\end{align*}
	We have $v = kv$, implies that $kv = k(kv) = k^2v$. So for $n=1,2,\dots$
	\[
		v = kv = k^2v = \dots = k^nv.
	\]
	We know
	\[
		\sum_{n=1}^{\infty}\norm{k^n \hat{v}} < \infty \qquad \text{for all }\hat{v} \in C(I).
	\]
	Apply this to $\hat{v}=v$:
	\[
		\sum_{n=1}^{\infty}\underset{=\norm{v}}{\underbrace{\norm{k^nv}}} < \infty .
	\]
	So $\norm{v}=0$ with implies $v(x)=0$ for all $x \in I$.
	So we have $f(x)=\tilde f(x)$ for $x \in I$. \\
	$\Rightarrow $ Answer to the question above: YES !
\end{enumerate}
We have more or less proved the following theorem:
\begin{theorem}
	Set $I=[0,1]$. Suppose $u \in C(I)$ and $k \in C(I \times I)$. Consider
	\[
		f(x) = u(x)+ \int_{0}^{x} k(x,t) f(t) \,\mathrm{d}t, \qquad x \in I \qquad \qquad (1).
	\]
	Then $(1)$ has a unique solution $f \in C(I)$
\end{theorem}
With the same technology we can prove:
\begin{theorem}
	Set $I = [0,1]$. Suppose $u \in C(I)$, $k \in C(I \times I)$ and $\max\limits_{(x,t) \in I \times I} \abs{k(x,t)} <1$. Consider \[
		f(x) = u(x) + \int_{0}^{1}k(x,t)f(t) \,\mathrm{d}t, \qquad x \in I \qquad \qquad (2).
	\]
	Then $(2)$ has a unique solution $f \in C(I)$.
\end{theorem}
Different notions: see introductional example.

\section{Normed Spaces and Banach Spaces}
\label{sec:normed_spaces_and_banach_spaces}

\begin{definition*}[vector space]
	$C(I)$ with the operations for $x \in I$:
	\begin{description}
		\item[addition] $v,w \in C(I)$: $\qquad (v+w)(x) = v(x)+ w(x)$,
		\item[mult. by scalar] $v \in C(I)$, $ \lambda \in \mathbb{R}$: $\qquad (\lambda v)(x) = \lambda v(x)$.
	\end{description}
	Note that $v+w, \lambda v \in C(I)$.
\end{definition*}
\begin{definition*}[norm]
	Norm on $C(I)$ for instance
	\[
		\norm{v} = \max_{x \in I} \abs{v(x)}
	\]
	with norm given we can talk about convergence and continuity.
\end{definition*}
\begin{definition*}[Cauchy sequence]
	In our example a sequence $(f_n)_{n=1}^{\infty}$ is called Cauchy sequence if $\norm{f_n-f_m} \to 0$ for $n,m \to \infty$.
\end{definition*}
\begin{definition*}
	$C(I)$ with the max-norm. Lemma above says that every Cauchy sequence converges i.e.
	\[
		\norm{v_n-v_m} \to 0, \qquad n,m \to \infty.
	\]
	This applies
	\[
		\exists\, v \in C(I): \norm{v_n-v} \to 0, \qquad n \to \infty.
	\]
	This is the defining property of a Banach space. \\
	$K$ linear mapping $C(I) \to C(I)$ with
	\begin{align*}
		K(v+w) &= K(v) + K(w) \\
		K(\lambda v) &= \lambda K(v)
	\end{align*}
	for $v,w \in  C(I)$, $\lambda \in \mathbb{R}$. \\
	$K$ bounded linear:
	\[
		\norm{Kv} \leq M \norm{v} \qquad \forall\, v \in C(I),
	\]
	where $M >0$ independent of $v$.
\end{definition*}
\begin{definition*}[operator norm]
	Define
	\[
		\norm{K}:= \inf \set[M>0]{\norm{Kv} \leq M \norm{v} \text{ for all }v \in C(I)}.
	\]
\end{definition*}
\minisec{fixed point results:}
Our example: $f=u+kf =: T(f)$ and $f_0 \in C(I)$ fixed. \\
Form sequence of iterants $(f_n)_{n=1}^{\infty}$, $f_n = T(f_{n-1})$, $n=1,2,\dots$ if
\[
	\norm{T(v)-T(w)} \leq c \norm{v-w}
\]
for all $v,w \in C(I)$ for some $c<1$. Then there is a unique $v \in C(I)$ such that $v = T(v)$. \\
This is \underline{Banach's fixed point theorem}.
\begin{definition*}[Green's function]
	Our example:
	\[
		L = \left( \diffd{}{x} \right)^2 + 1
	\]
	differential operator. Boundary conditions
	\[
		f(0) = f'(0) = 0.
	\]
	Then
	\[
		f(x) = \int_{0}^{1} g(x,t)h(t) \,\mathrm{d}t
	\]
	is a solution to
	\[
		\begin{cases}
			f''+f &= h, \\
			f(0) = f'(0)& = 0.
		\end{cases}
	\]
\end{definition*}
\begin{definition*}[real vector space]
	We say that $E$ is a real vector space  if it is a non-empty set with the operations
	\begin{description}
		\item[addition] $E \times E \to E$, $\qquad (x,y) \mapsto x+y$
		\item[mult. with scalar] $\mathbb{R} \times E \to E$, $ \qquad (\lambda,x) \mapsto \lambda x$
	\end{description}
	satisfying the axioms:
	\begin{enumerate}[(1)]
		\item $x+y = y+x, \qquad$ for all $x,y \in E$,
		\item $x+(y+z)= (x+y)+z, \qquad $ for all $x,y,z \in E$,
		\item For all $x,y \in E$ there exists $z \in E$ such that $x+z = y$,
		\item $\alpha (\beta x) = (\alpha \cdot \beta)x, \qquad $ for all $\alpha,\beta \in \mathbb{R}, x \in E$,
		\item $\alpha(x+y) = \alpha x+ \alpha y, \qquad $ for all $\alpha \in \mathbb{R}, x,y \in E$,
		\item $(\alpha + \beta) x = \alpha x + \beta x, \qquad $ for all $\alpha, \beta \in \mathbb{R}, x \in E$,
		\item $1 \cdot x = x, \qquad $ for all $x \in E$.
	\end{enumerate}
\end{definition*}
\begin{bemerkung}
	$E$ is a complex vector space if all $\mathbb{R}$ in the definition above are replaced by $\mathbb{C}$.
\end{bemerkung}
\begin{bemerkung}
	\begin{enumerate}[(1)]
		\item \[
			\exists\,! 0 \in E: \qquad x + 0 = x \qquad \text{for all }x \in E.
		\]
		Since: Fix $x \in E$, by $(3)$, $\exists\, 0_x$ such that $0_x + x =x$. \\
		Fix $y \in E$. We want to show that $y + 0_y = y$. By $(3)$, there exists $z \in E$ such that $x+z = y$. So
		\begin{align*}
			y + 0_x & \stackrel{\hphantom{(1)}}{=} (x+z)+ 0_x \\
			&\stackrel{(1)}{=} (z+x)+ 0_x \\
			&\stackrel{(2)}{=} z + (x + 0_x) \\
			&\stackrel{\hphantom{(1)}}{=} z+x \\
			&\stackrel{(1)}{=}x+z \\
			&\stackrel{\hphantom{(1)}}{=} y.
		\end{align*}
		Assume $x+ 0_1 = x$, $x+ 0_2 =x$ for all $x \in E$. We want to show $0_1 = 0_2$:
		\[
			0_1 = 0_1 + 0_2 = 0_2 + 0_1 = 0_2,
		\]
		\item
		\[
			\forall\, x \in E: \, \exists\,! \,-x \in E: \,x+(-x)=0.
		\]
		proof: exercise.
		\item \begin{align*}
			0x &=0 \qquad \text{for all }x \in E \\
			(-1)x &= -x \qquad \text{for all }x \in E.
		\end{align*}
	\end{enumerate}
\end{bemerkung}
\begin{beispiele}[Examples of real vector spaces]
	\begin{enumerate}[1)]
		\item $\mathbb{R}$ with standard addition and mult. by scalar.
		\item $\mathbb{R}^n$, $n=2,3, \dots$.
		\begin{description}
			\item[addition] $(x_1,x_2,\dots) + (y_1,y_2, \dots) = (x_1+y_1,x_2+y_2, \dots)$
			\item[mult.] $ \lambda (x_1,x_2,\dots) = (\lambda x_1, \lambda x_2, \dots)$
		\end{description}
		\item $\mathbb{R}^{\infty} = \set[(x_1,\dots,x_n,\dots)]{x_n \in \mathbb{R}, n=1,2,\dots}$
		\item $1 \leq p < \infty$,
		\[
			l^p = \set[(x_1,\dots,x_n, \dots) \in \mathbb{R}^{\infty}]{\left( \sum_{n=1}^{\infty} \abs{x_n}^p \right)^{\frac{1}{p}} < \infty}
		\]
		with the same addition and mult. by scalar as in $\mathbb{R}^{\infty}$. We have to check:
		\begin{enumerate}[(1)]
			\item $x,y \in l^p \qquad \Rightarrow \qquad x+y \in l^p$
			\item $x \in l^p, \lambda \in \mathbb{R} \qquad \Rightarrow \qquad \lambda x \in l^p$.
		\end{enumerate}
		For $(1)$ we assume $x = (x_1, \dots, x_n, \dots)$ and $y = (y_1, \dots, y_n, \dots)$.
		\begin{align*}
			x \in l^p \qquad &\Rightarrow \qquad \sum_{n=1}^{\infty}\abs{x_n}^p < \infty \\
			y \in l^p \qquad &\Rightarrow \qquad \sum_{n=1}^{\infty}\abs{y_n}^p < \infty
		\end{align*}
		\[
			\Rightarrow \qquad  x+y = (x_1+y_1, \dots) \stackrel{?}{\in } l^p?
		\]
		\begin{align*}
			\Rightarrow \sum_{n=1}^{\infty}\abs{x_n+y_n}^p & \leq \set{\abs{x_n+y_n} \leq \abs{x_n}+ \abs{y_n} \leq 2 \max \set{\abs{x_n},\abs{y_n}}} \\
			& \,\set{\abs{x_n+y_n}^p \leq 2^p \left( \abs{x_n}^p + \abs{y_n}^p \right)} \\
			&\leq \sum_{n=1}^{\infty}2^p (\abs{x_n}^p + \abs{y_n}^p) \\
			&= 2^p \underset{< \infty}{\underbrace{\sum_{}^{}\abs{x_n}^p}}+ 2^p \underset{< \infty}{\underbrace{\sum_{}^{}\abs{y_n}^p}} < \infty
		\end{align*}
		and \[
			\sum_{n=1}^{\infty} \abs{\lambda x_n}^p = \sum_{n=1}^{\infty} \abs{\lambda}^p \cdot \abs{x_n}^p = \abs{\lambda}^p \sum_{n=1}^{\infty}\abs{x_n}^p < \infty.
		\]
		\item Function spaces, say real-valued functions on $I$.
		\begin{description}
			\item[addition:] $(f+g)(x) = f(x)+ g(x), \qquad x \in I$
			\item[mult. by scalar:] $(\lambda f)(x)= \lambda f(x) \qquad $ for functions $f$ and $g$
		\end{description}
		\item $C(I):$ addition and mult. by scalar as in $(5)$. \\ $f,g$ continuous in $I$ implies that $f+g$ is continuous in $I$. \\
		Also if $f$ is continuous and $\lambda \in \mathbb{R}$ then $(\lambda f)$ is continuous in $I$.
		\item $P(I)= \,$ polynomials in $I$.
		\item $P_k(I)= \,$ polynomials of degree at most $k$ in $I$.
	\end{enumerate}
\end{beispiele}


\subsection{Maximum Likelihood Estimators}
\label{sec:maxmean}

\subsubsection{Gaussian Data}

The joint likelihood for a set of Gaussian-distributed data is simply
the product of the individual probabilities:

\begin{eqnarray}
L \equiv \prod{p_k} &\propto& \prod_k{e^{-(x_k - \mu)^2/2\sigma^2_k}} \\
                    &=& e^{-\sum_k{(x_k - \mu)^2/2\sigma^2_k}} \\
                    &\equiv& e^{-\chi^2/2} \\
\end{eqnarray}

The maximum likelihood estimate of a set of parameters is therefore,
by definition, the parameters that minimize $\chi^2$.

\subsubsection{Poisson Data}

What if our data are Poisson distributed, say a an X-ray image, where
each pixel is the number of photons, and does not necessarily contain
enough photons that the gaussian approximation is even remotely
justified?  In this case, the joint likelihood is still the product of
the individual probabilities, but where each probability is given by
the Poisson pdf:

\begin{equation}
L \equiv \prod_k{p_k} = \prod_k{{{e^{-\mu_k}\mu_k^k}\over{k!}}}
\end{equation}

Here $\mu_k$ is the mean expected count rate in pixel $k$, the sum of
the model prediction and the background count rate.

\subsubsection{Joint Likelihood Calculation}

For chains that involve a combination of Gaussian and
Poisson-distributed data, the likelihood is straightforwardly calculated as

\begin{equation}
L \equiv \prod_i{L_i},
\end{equation}

where $i$ ranges over the independent datasets, with $L_i$ calculated
as above for Gaussian or Poisson datasets.  For purposes of reported
goodness of fit ($\chisq$), an equivalent $\chisqnor$ distributed is
constructed for Poisson data, noting that:

\begin{equation}
f_N(\chisqnor) = {1\over{2\Gamma(N/2)}}e^{-\chisqnor/2}\left({\chisqnor\over{2}}\right)^{N/2-1}
\end{equation}

and

\begin{equation}
P(\mu;k) = {1\over{k!}}e^{-\mu} \mu^{k}
\end{equation}

with the identification of

\begin{equation}
\chisqnor = 2\mu
\end{equation}

and

\begin{equation}
N = 2(k + 1)
\end{equation}