\chapter{Probability}

\section*{2.2. Rules for three events}
\addcontentsline{toc}{section}{2.2. Rules for three events}
\begin{enumerate}[(a)]
    \item Consider three events, $A$, $B$, and $C$.
        If they are all independent of each other,
        show that
        \begin{equation*}\tag{2.76}
            P(A \text{ and } B \text{ and } C) = P(A) \cdot P(B) \cdot P(C)
        \end{equation*}

    \item If they are (possibly) dependent, show that
        \begin{equation*}\tag{2.77}
            P(A \text{ and } B \text{ and } C) = P(A) \cdot P(B | A) \cdot P(C | A \text{ and } B)
        \end{equation*}

    \item If they are all mutually exclusive, show that
        \begin{equation*}\tag{2.78}
            P(A \text{ or } B \text{ or } C) = P(A) + P(B) + P(C)
        \end{equation*}

    \item If they are (possibly) nonexclusive, show that
        \begin{align*}\tag{2.79}
            P(A \text{ or } B \text{ or } C) =& P(A) + P(B) + P(C) \\
                                          &- P(A \text{ and } B) - P(A \text{ and } C) - P(B \text{ and } C) \\
                                          &+ P(A \text{ and } B \text{ and } C)
        .\end{align*}
\end{enumerate}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item Using (2.9) we find that:
            \[
                P(A \text{ and } B \text{ and } C) = P(A) \cdot P(B \text{ and } C | A)
                = P(A) \cdot P(B | A) \cdot P(C | A \text{ and } B)
            .\]
            Because the events are independent, $P(B | A) = P(B)$ and $P(C | A \text { and } B) = P(C)$, so
            \begin{equation*}\tag{2.76}
                P(A \text{ and } B \text{ and } C) = P(A) \cdot P(B) \cdot P(C).
            \end{equation*}

        \item Proved at (a).

        \item By (2.18),
            \begin{align*}
                P(A \text{ and } B \text{ and } C)
                    &= P(A) + P(B \text{ or } C) - P(A \text{ and } (B \text{ or } C)) \\
                    &= P(A) + P(B) + P(C) - P(B \text{ and } C) - P(A) \cdot P(B \text{ or } C | A)
            .\end{align*}

            We compute the subtracted member:
            \begin{align*}
                P(A) \cdot P(B \text{ or } C | A)
                    &= P(A) \cdot (P(B|A) + P(C|A) - P(B \text{ and } C | A))) \\
                    &= P(A \text{ and } B) + P(A \text{ and } C) - P(A \text{ and } B \text{ and } C)
            .\end{align*}

            By substituting in the initial expression, we get:
            \begin{align*}\tag{2.79}
                P(A \text{ or } B \text{ or } C) =& P(A) + P(B) + P(C) \\
                                              &- P(A \text{ and } B) - P(A \text{ and } C) -
                                                P(B \text{ and } C) \\
                                              &+ P(A \text{ and } B \text{ and } C)
            .\end{align*}

            Since the events are mutually exclusive, all $\emph{and}$ probabilities are 0, so:
            \begin{equation*}\tag{2.78}
                P(A \text{ or } B \text{ or } C) = P(A) + P(B) + P(C)
            \end{equation*}

        \item Proved at (c).
    \end{enumerate}
\end{proof}

\section*{2.7. Proofreading}
\addcontentsline{toc}{section}{2.7. Proofreading}
Two people each proofread the same book. One person finds 100 errors, and the other finds 60.
There are 20 errors common to both people. Assume that all errors are equally likely to be found (which is
undoubtedly not true in practice), and also that the discovery of an error by a person is independent
of the discovery of that error by the other person. Given these assumptions, roughly how many error
does the book have? $\emph{Hint:}$ Draw the picture similar to Fig. 2.1, and then find the probability
of each person finding a given error.

\vspace{1em}

\begin{proof}
    \hfill

    Let $P(A)$ be the probability that a random error is one of the errors discovered
    by the person with 100 errors, and respectively let $P(B)$ be the same for the person with 60 errors.
    Also, let $N$ be the estimated number of total errors.
    Since the discoveries of errors are independent events,
    \[
        P(A \text{ and } B) = P(A) \cdot P(B) = \frac{100}{N} \cdot \frac{60}{N} = \frac{6000}{N^2}
    .\]
    But we know that 20 errors are common between the two persons, so
    \[
        P(A \text{ and } B) = \frac{20}{N}
    .\]
    Therefore, we get the estimated total number of errors:
    \[
        \frac{20}{N} = \frac{6000}{N^2} \iff N = 300
    .\]
\end{proof}

\section*{2.9. Sock pairs}
\addcontentsline{toc}{section}{2.9. Sock pairs}
\begin{enumerate}[(a)]
    \item Four red socks and four blue socks are in a drawer. You reach in and pull out two socks at random.
        What is the probability that you obtain a matching pair?

    \item Answer the same question, but now in the general case with $n$ red socks and $n$ blue socks.

    \item Presumably you answered the above questions by counting the relevant pairs of socks.
        Can you think of a quick probability argument, requiring no counting, that gives the
        answer to part (b) (and part(a))?
\end{enumerate}

\vspace{1em}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item The total number of possible extracted pairs is $\binom{8}{2} = 28$ and the number
            of possible matching pair (of any color) extractions is $2 \cdot \binom{4}{2} = 12$.
            Therefore, the probability of pulling a matching pair is:

            \[
                \frac{12}{28} = \frac{3}{7} \approx 0.428
            \]

        \item As before, the total number of possible extracted pairs is $\binom{2n}{2} = n(2n - 1)$ and
            the number of possible matching pair (of any color) extractions is
            $2 \cdot \binom{n}{2} = n(n - 1)$. As a result, the probability of pulling a
            matching pair is:
            \[
                \frac{n(n-1)}{n(2n - 1)} = \frac{n - 1}{2n - 1} \to \frac{1}{2}
            \]
        \item The first sock can either be red or blue. After the extraction, the drawer contains
            $2n - 1$ socks and $n - 1$ socks of the matching color, so the probability of pulling
            a matching pair is given by:
            \[
                \frac{n - 1}{2n - 1} \to \frac{1}{2}
            \]
    \end{enumerate}
\end{proof}

\section*{2.11. At least one 6}
\addcontentsline{toc}{section}{2.11. At least one 6}
Three dice are rolled. What is the probability of obtaining at least one 6? We solved
this in Section 2.3.1, but your task here is to solve it the long way, by adding up the
probabilities of obtaining exactly one, two, or three 6's.

\begin{proof}
    Since each dice can take values from 1 to 6, the dices can be rolled in $6^3 = 216$ ways.
    Then, there are $3 \cdot 5 \cdot 5 = 75$ ways in which only one dice is a 6 (we assume
    each individual dice rolls a 6 and the other two roll differently), so the probability
    of doing that is $\frac{75}{216}$. Also, there are $3 \cdot 5 = 15$
    ways of having exactly two 6 dices, so the probability of this event is $\frac{15}{216}$.
    Finally, the event of having all dices being rolled as sixes can occur in only one way, so the
    probability of it happening is $\frac{1}{216}$. In conclusion, the probability of rolling at least a 6
    from three dice rolls is given by:
    \[
        \frac{75}{216} + \frac{15}{216} + \frac{1}{216} = \frac{91}{216} \approx 0.421
    \]
\end{proof}

\section*{2.15 My birthday}
\addcontentsline{toc}{section}{2.15. My birthday}
\begin{enumerate}[(a)]
    \item You are in a room with 100 other people. Let $p$ be the probability that at least one
        of these 100 people has your birthday. Without doing any calculations, state whether $p$
        is larger, smaller, or equal to 100/365.

    \item Now calculate the exact value of $p$.
\end{enumerate}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item Assuming all birthdays are equally likely to be encountered and that a year has 365 days,
            the probability that at least one person of the 100 has the same birthday as me is strictly less
            than $\frac{100}{365}$, since some people may have the same birthday and only unique
            birthdays are counted. The $\frac{100}{365}$ probability would be acquired if we consider
            the 100 people in the room as having unique birthdays.

        \item The probability that a random person doesn't have the same birthday as me is $\frac{364}{365}$,
            so the probability that none of the 100 people in the room has the same birthday as me is
            $(\frac{365}{365})^{100}$. Therefore, the probability that at least one of them has the
            same birthday as me is:
            \[
                p = 1 - \bigg(\frac{364}{365}\bigg)^{100} \approx 0.24
            \]
    \end{enumerate}
\end{proof}

\section*{2.16. My birthday, again}
\addcontentsline{toc}{section}{2.16. My birthday, again}
We saw at the end of Section 2.4.1 that 253 is the answer to the question, "How many people (in addition to
me) need to be present in order for there to be at least a 1/2 chance that someone else has $\emph{my}$
birthday?" We solved this by finding the smallest $n$ for which $(364/365)^n$ is less than 1/2. Answer
this question again, by making use of the approximation in Eq. (7.14) in Appendix C. What is the answer
in the general case where there are N days in a year instead of 365? Assume N is large.

\vspace{1em}

\begin{proof}
    We are given the approximation formula:
    \begin{equation*}\tag{7.14}
        (1 + a)^n \approx e^{na}
    \end{equation*}

    We consider two cases:
    \begin{enumerate}[(1)]
        \item A year has 365 days. We've seen in the previous exercise that the probability that at
            least one of $n$ given people has the same birthday as me is given by the expression:
            \[
                p_n = 1 - \bigg(\frac{364}{365}\bigg)^n
            \]

            Let's assume that $p_n \approx \frac{1}{2}$, then:
            \[
                \bigg(\frac{364}{365}\bigg)^n \approx \frac{1}{2} \iff
                \bigg(1 - \frac{1}{365}\bigg)^n \approx \frac{1}{2}
            \]

            Using (7.14), we have that:
            \[
               e^{-\frac{n}{365}} \approx \frac{1}{2}
            \]

            By taking the logarithm of both sides and then negating the terms, we see that
            $\frac{n}{365} \approx \ln{2}$, so the number of people that should be present such
            that there is a least $\frac{1}{2}$ chance that someone else has my birthday is:
            \[
                n = 365 \ln{2} \approx 253
            \]

        \item A year has $N$ days. Similarly to the previous exercise, we see that the probability
            of a person not having the same birthday as me is $\frac{N - 1}{N}$. Then it is
            easily deduced that the probability of a person having the same birthday as me is:
            \[
                p_n = 1 - \bigg(\frac{N - 1}{N}\bigg)^n
            \]

            Let's assume that $p_n \approx \frac{1}{2}$, then:
            \[
                \bigg(\frac{N - 1}{N}\bigg)^n \approx \frac{1}{2} \iff
                \bigg(1 - \frac{1}{N}\bigg)^n \approx \frac{1}{2}
            \]

            Using (7.14), we have that:
            \[
               e^{-\frac{n}{N}} \approx \frac{1}{2}
            \]

            By taking the logarithm of both sides and then negating the terms, we see that
            $\frac{n}{N} \approx \ln{2}$, so the number of people that should be present such
            that there is a least $\frac{1}{2}$ chance that someone else has my birthday is:
            \[
                n \approx N\ln{2} \approx 0.693N
            \]
    \end{enumerate}
\end{proof}

\section*{2.18. A random game-show host}
\addcontentsline{toc}{section}{2.18. A random game-show host}
Consider the following variation of the Game-Show Problem we discussed in Section 2.4.2. A game-show
host offers you the choice of three doors. Behind one of these doors is the grand prize, and behind
the other two are goats. The host announces that after you select a door (without opening it), he will
$\emph{randomly}$ open one of the other doors, and the result happens to be a goat. He then offers
you the chance to switch your choice to the remaining door. Should you switch or not? Or does it
not matter?

\vspace{1em}

\begin{proof}
    Since the doors can be reordered and not change the setup of the problem, we can pick the first
    door without loss of generality. There are three equally likely possibilities
    for what is behind the three doors: PGG, GPG, and GGP, where P denotes the prize and G denotes
    a goat. Let us use the subscript $H$ to show that a door was opened by the host. Considering that
    the host cannot choose our door (the first one), we have the following door layouts after the host
    opens a door:

    \pagebreak

    \begin{table}[h]
        \centering
        \begin{tabular}{cc}
            $PG_H G$ & $PGG_H$ \\
            $GP_HG$ & $GPG_H$ \\
            $GG_HP$ & $GGP_H$
        \end{tabular}
    \end{table}

    Since the host doesn't choose the door with the prize, those layouts have 0 probability of
    occuring. The encounters of the other 4 layouts are equally likely, so they have a probability
    of occuring of $\frac{1}{4}$. We can see that if we keep the initial choice of the door,
    there is a $\frac{1}{2}$ possibility of winning. Likewise, if we switch the door, there
    is a $\frac{1}{2}$ probability of winning. Therefore, it does not matter if we switch our choice or not.
\end{proof}

\section*{2.19. Boy girl problem with general information}
\addcontentsline{toc}{section}{2.19. Boy girl problem with general information}
This problem is an extension of the Boy/Girl problem from Section 2.4.4. You should study that
problem thoroughly before tackling this one. As in the original version of the problem, assume
that all processes are completely random. The new variation is the following:

You bump into a random person on the street who says, "I have two children. At least one of them
is a boy whose birthday is in the summer." What is the probability that the other child is also
a boy? What if the clause is changed to, "whose birthday is on August 11th"? Or "who was born
during a particular minute on August 11th"? Or more generally, "who has a particular characteristic
that occurs with probability $p$ "? $\emph{Hint:}$ Make a table of all of the various possibilities,
analogous to the tables in Section 2.4.4.

\vspace{1em}

\begin{proof}
    Without taking into account the particular characteristic, we have the following possible
    children couples:

    \begin{table}[h]
        \centering
        \begin{tabular}{c c c c}
            BB & BG & GB & GG
        \end{tabular}
    \end{table}

    , where B represents a boy and G a girl. Each of these groups is equally likely and
    is encountered with a probability of $\frac{1}{4}$. If we add a subscript C to the children
    that possess the particular characteristic, we get the following possible pairs:

    \begin{table}[h]
        \centering
        \begin{tabular}{c c c c}
            $B_CB_C$ & $B_CG_C$ & $G_CB_C$ & $G_CG_C$ \\
            $B_CB$ & $B_CG$ & $G_CB$ & $G_CB$ \\
            $BB_C$ & $BG_C$ & $GB_C$ & $GG_C$ \\
            $BB$ & $BG$ & $BB$ & $GG$
        \end{tabular}
    \end{table}

    Since the probability of a kid to have the characteristic is $p$, then the probability
    of not having it is $1 - p$. We split the groups in 3 categories (following the
    lines in the table):
    \begin{itemize}
        \item Line 1: Both children have the characteristic. The probability that one
            given couple is of this type is $\frac{1}{4}p^2$
        \item Lines 2 and 3: Only one kid has the characteristic. The probability that such
            a group is encountered is $\frac{1}{4}p(1 - p)$
        \item Line 4: None of the kids has the characteristic. The probability that a given
            group is in this category is $\frac{1}{4}(1 - p)^2$
    \end{itemize}

    \pagebreak

    Now, we find that the groups that contain at least one boy who has the characteristic are:
    \begin{table}[h]
        \centering
        \begin{tabular}{c c c}
            $B_CB_C$ & $B_CG_C$ & $G_CB_C$ \\
            $B_CB$ & $B_CG$ & \\
            $BB_C$ & & $GB_C$ \\
        \end{tabular}
    \end{table}

    We have 3 groups that contain two boys and at least one of them has the characteristic
    (first column). Also, there are a total of 7 groups containing at least a boy with the
    characteristic (3 groups from the first line, 2 from the second
    line and 2 from the third line). Therefore, knowing that one children is a boy that possesses
    the characteristic $p$, the probability that the other kid is also a boy is:
    \[
        P_{BB} = \frac{\frac{1}{4}p^2 + 2 \frac{1}{4}p(1 - p)}{3 \frac{1}{4}p^2 + 4 \frac{1}{4} p(1 - p)}
        = \frac{p^2 + 2p(1 - p)}{3p^2 + 4p(1 - p)}
        = \frac{2p - p^2}{4p - p^2}
        = \frac{2 - p}{4 - p}
    \]

    In the base case, the characteristic is "having a birthday in the summer", so $p = \frac{1}{4}$.
    We get that the probability of the other kid being a boy is:
    \[
        P_{BB} = \frac{2 - \frac{1}{4}}{4 - \frac{1}{4}} = \frac{7}{15} \approx 0.467
    \]

    The second characteristic is "having a birthday on August 11th", so $p = \frac{1}{365}$.
    The sought probability is then
    \[
        P_{BB} = \frac{2 - \frac{1}{365}}{4 - \frac{1}{365}} = \frac{729}{1459} \approx \frac{1}{2}
    \]

    Finally, if the characteristic is "being born during a particular minute on August 11th",
    so $p = \frac{1}{365} \frac{1}{1440} = \frac{1}{525600}$
    the probability that the other children is a boy is:
    \[
        P_{BB} = \frac{2 - \frac{1}{525600}}{4 - \frac{1}{525600}} = \frac{1051199}{2102399} \approx \frac{1}{2}
    \]
\end{proof}

\section*{2.20. A second test}
\addcontentsline{toc}{section}{2.20. A second test}
Consider the setup in the "False positives" example in Section 2.5. If we instead perform
$\emph{two}$ successive tests on each person, what is the probability that a person
who tests positive both times actually has the disease?

\begin{proof}
    The setup provided in the "False positives" example is the following:
    \begin{itemize}
        \item 2\% of the overall population has the disease.

        \item If a person $\emph{does}$ have the disease, then the test has a 95\% chance of correctly
            indicating that the person has it. (So 5\% of the time, the test incorrectly indicates
            that the person doesn't have the disease.)

        \item If a person $\emph{does not}$ have the disease, then the test has a 10\% chance of
            incorrectly indicating that the person has it; this is a "false positive" result.
            (So 90\% of the time, the test correctly indicates that the person doesn't have the
            disease.)
    \end{itemize}

    Let $N$ be the population number and let's consider two cases:
    \begin{enumerate}
        \item The person has the disease, and the tests were positive results.
            The probability of a positive result for a diseased person is 90\%.
            Therefore the probability of a diseased person being diagnosed twice
            as positive is $95\% \cdot 95\% = 90.25\%$. 2\% of the population is diseased,
            so the number of diseased persons that are tested twice as positive is
            $2\%N \cdot 90.25\% = 1.805\%N$.

        \item The person does not have the disease, and both tests are "false positives".
            The probability of a "false positive" for a healthy person is 10\%.
            As a result, the probability of a healthy person being tested twice as false positive
            is $10\% \cdot 10\% = 1\%$. 98\% of the population is healthy, so the number
            of healthy people that are tested twice as "false positives" is
            $98\%N \cdot 1\% = 0.98\%N$.
    \end{enumerate}

    Therefore, the probability of a person who tests positive both times actually has the disease
    is:
    \[
        \frac{1.805\%N}{1.805\%N + 0.98\%N} = \frac{1.805\%N}{2.785\%N} \approx 0.6481 = 64.81\%
    \]
\end{proof}


%!TEX root = ../Thesis.tex
\chapter{Harmonic Oscillator - Hamilton's Equations and Numerical Analysis}

\section{Equations of Motion}
\begin{figure}[ht!]
\centering
\includegraphics[scale=0.7]{fig/harmonic_oscillator.pdf}
\caption{The harmonic oscillator}
\label{fig:ho}
\end{figure}
\begin{description}
\item[Step 0 \quad Lagrangian $L$] \ \\[0.5cm]
Generalized coordinate: $x$. \\[0.2cm]
$T = \frac{1}{2} m \dot{x}^2.$ \\[0.2cm]
$V = \frac{1}{2} k x^2$ \\[0.2cm]
$L(x, \dot{x}) = T - V = \frac{1}{2} m \dot{x}^2 - \frac{1}{2} k x^2$

\item[Step 1 \quad Generalized momentum $p$] \ \\[0.2cm]
$p(x,\dot{x}) = \dfrac{\partial L}{\partial \dot{x}} = k \dot{x}$

\item[Step 2 \quad Transform $\dot{x}$] \ \\[0.5cm]
$\dot{x} = \dot{x}(x, p) = \dfrac{p}{k}$

\item[Step 3 \quad The Hamiltonian $H(\vec{q}, \vec{p}, t) = \sum\limits_{i=1}^n p_i \dot{q_i} - L$] \ \\
\begin{align}
\notag H &= p \cdot \dot{x} - \left(\frac{1}{2} m \dot{x}^2 - \frac{1}{2} k x^2\right) \\
\notag  &= p \cdot \dfrac{p}{m} - \left(\frac{1}{2} m \left(\frac{p}{m}\right)^2 - \frac{1}{2} k x^2\right) \\
&= \dfrac{p^2}{2m} + \dfrac{1}{2}k x^2
\end{align}
, which we recognize simply as the total energy. The first term is the kinetic energy in terms of the momentum $p$ and the second term is the potential energy $V$.

\item[Step 4 \quad Hamilton's Equations of Motion]
\begin{align}
\begin{split}
\label{eq:ho-eom}
\dot{x} = +\dfrac{\partial H}{\partial p} &= \dfrac{p}{m} ,
\\[0.2cm]
\dot{p}_x = -\dfrac{\partial H}{\partial x} &= - k x
\end{split}
\end{align}
\end{description}

\section{Numerical Analysis}
We will now solve the harmonic oscillator's equations of motion, \eqref{eq:ho-eom}. For simplicity we'll set $k = m = 1$. Note that by choice of $m=1$ the momentum $p$ is equal to the velocity $v$. The first step is to discretize the equations
\begin{alignat}{2}
&\dod{x}{t} = p  & \qquad \implies \qquad &\Delta x = p \Delta t \\[0.5cm]
&\dod{p}{t} = - x & \qquad \implies \qquad &\Delta p = - x \Delta t
\end{alignat}
The solution for this linear system of equations is well known and can be expressed as
\begin{align}
\begin{split}
\label{eq:ho-analytical}
x(t) = A \cos{\omega t} + B \sin{\omega t} \\
p(t) = -A \sin{\omega t} + B \cos{\omega t}
\end{split}
\end{align}
A good way to test the validity and precision a numerical method is to compare it's solution to a problem of which we know an analytical solution. Hence we will use the analytical solution \eqref{eq:ho-analytical} to analyze the $x(t)$ and $p(t)$ errors of the solutions found with the following three algorithms.

\subsection{Explicit Euler algorithm}
\begin{align}
\begin{split}
\label{al:ho-euler_e}
x_{i+1} &= p_i\Delta t + x_i \\
p_{i+1} &= -x_i\Delta t + p_i
\end{split}
\end{align}
In the explicit Euler, time step $i+1$ only reference values from the old time step $i$.

\subsection{Implicit Euler algorithm}
\begin{align}
\begin{split}
x_{i+1} &= p_{i+1}\Delta t + x_i \\
p_{i+1} &= -x_{i+1}\Delta t + p_i
\end{split}
\end{align}
In the implicit Euler, time step $i+1$ only reference the new values from the same time step. In general this leads to a system of equations that may not have an analytical solutions, and function roots would have to be found numerically using e.g. Newton Raphson. In the case of the harmonic oscillator we have a system of linear equations that can be solved analytically for $(x_{i+1},p_{i+1}$
\begin{align}
\notag &x_{i+1} = p_{i+1}\Delta t + x_i \\
\notag &p_{i+1} = -x_{i+1}\Delta t + p_i \\[0.4cm]
\notag & \Downarrow \\[0.4cm]
\notag &x_{i+1} - p_{i+1}\Delta t = x_i \\
\notag &p_{i+1} + x_{i+1}\Delta t = p_i \\[0.4cm]
\notag &\Downarrow \\[0.4cm]
\notag &\begin{bmatrix}
  1 & -\Delta t \\
  \Delta t & 1
\end{bmatrix}
\begin{bmatrix}
  x_{i+1} \\
  p_{i+1}
\end{bmatrix}
= \begin{bmatrix}
  x_i \\
  p_i
\end{bmatrix} \\[0.4cm]
\notag &\Downarrow \\[0.4cm]
&\begin{bmatrix} \label{al:ho-euler_i}
  x_{i+1} \\
  y_{i+1}
\end{bmatrix}
= \dfrac{1}{{\Delta t}^2 + 1}
\begin{bmatrix}
  1 & \Delta t \\
  -\Delta t & 1
\end{bmatrix}
\begin{bmatrix}
  x_i \\
  y_i
\end{bmatrix}
\end{align}

\subsection{Symplectic Euler algorithm}
\begin{align}
\begin{split}
\label{al:ho-euler_s1}
x_{i+1} &= p_{i+1}\Delta t + x_i  \\
p_{i+1} &= -x_i\Delta t + p_i
\end{split}
\end{align}
or
\begin{align}
\begin{split}
\label{al:ho-euler_s2}
x_{i+1} &= p_{i}\Delta t + x_i  \\
p_{i+1} &= -x_{i+1}\Delta t + p_i
\end{split}
\end{align}
In the symplectic Euler, time step $i+1$ reference the new values one the coordinate equation and the old $i$ value in the momentum equation. This mixing of time step values makes the Euler method symplectic, i.e. energy conserving.

In the first version \eqref{al:ho-euler_s1}, clearly $p_{i+1}$ needs to be run before $x_{i+1}$ in each time step. We can also do it the other way around as in \eqref{al:ho-euler_s2}. They give essential identical solutions. In this case the only difference is a phase shift of the momentum error by $\pi$ (Appendix \ref{app:symplectic_difference}).

Algorithms \crefrange{al:ho-euler_e}{al:ho-euler_s1} was implemented in Python (Appendix \ref{app:ho}).

\section{Plots}
\begin{figure}
    \centering
        \subbottom[Explicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_x(t)_euler_explicit.pdf}
            \label{fig:ho_x(t)_euler_explicit}
        }
        \subbottom[Implicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_x(t)_euler_implicit.pdf}
            \label{fig:ho_x(t)_euler_implicit}
        }
        \subbottom[Symplectic Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_x(t)_euler_symplectic.pdf}
            \label{fig:ho_x(t)_euler_symplectic}
        }
        \caption{Position x(t)}
    \label{fig:ho_x(t)_euler}
\end{figure}

\begin{figure}
    \centering
        \subbottom[Explicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_p(t)_euler_explicit.pdf}
            \label{fig:ho_p(t)_euler_explicit}
        }
        \subbottom[Implicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_p(t)_euler_implicit.pdf}
            \label{fig:ho_p(t)_euler_implicit}
        }
        \subbottom[Symplectic Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_p(t)_euler_symplectic.pdf}
            \label{fig:ho_p(t)_euler_symplectic}
        }
        \caption{Momentum p(t), equivalent to v(t) by choice of $m=1$}
    \label{fig:ho_p(t)_euler}
\end{figure}

\begin{figure}
    \centering
        \subbottom[Explicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_x(t)-error_euler_explicit.pdf}
            \label{fig:ho_x(t)-error_euler_explicit}
        }
        \subbottom[Implicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_x(t)-error_euler_implicit.pdf}
            \label{fig:ho_x(t)-error_euler_implicit}
        }
        \subbottom[Symplectic Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_x(t)-error_euler_symplectic.pdf}
            \label{fig:ho_x(t)-error_euler_symplectic}
        }
        \caption{Position x(t) error. Note the y-scale difference in symplectic \ref{fig:ho_x(t)-error_euler_symplectic}}
    \label{fig:ho_x(t)-error_euler}
\end{figure}

\begin{figure}
    \centering
        \subbottom[Explicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_p(t)-error_euler_explicit.pdf}
            \label{fig:ho_p(t)-error_euler_explicit}
        }
        \subbottom[Implicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_p(t)-error_euler_implicit.pdf}
            \label{fig:ho_p(t)-error_euler_implicit}
        }
        \subbottom[Symplectic Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_p(t)-error_euler_symplectic.pdf}
            \label{fig:ho_p(t)-error_euler_symplectic}
        }
        \caption{Momentum p(t) error}
    \label{fig:ho_p(t)-error_euler}
\end{figure}

\begin{figure}
    \centering
        \subbottom[Explicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_E(t)_euler_explicit.pdf}
            \label{fig:ho_E(t)_euler_explicit}
        }
        \subbottom[Implicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_E(t)_euler_implicit.pdf}
            \label{fig:ho_E(t)_euler_implicit}
        }
        \subbottom[Symplectic Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_E(t)_euler_symplectic.pdf}
            \label{fig:ho_E(t)_euler_symplectic}
        }
        \caption{Normalized energy E(t)}
    \label{fig:ho_E(t)_euler}
\end{figure}

\begin{figure}
    \centering
        \subbottom[Explicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_phase-space_euler_explicit.pdf}
            \label{fig:ho_phase-space_euler_explicit}
        }
        \subbottom[Implicit Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_phase-space_euler_implicit.pdf}
            \label{fig:ho_phase-space_euler_implicit}
        }
        \subbottom[Symplectic Euler]{
            \includegraphics[scale=0.24]{fig/ho/ho_phase-space_euler_symplectic.pdf}
            \label{fig:ho_phase-space_euler_symplectic}
        }
        \caption{Phase-space}
    \label{fig:ho_phase-space_euler}
\end{figure}

Things to note about the integrators from the figures \crefrange{fig:ho_x(t)_euler}{fig:ho_phase-space_euler}:
\begin{itemize}
    \item Explicit and implicit drift in position amplitude but stay true in phase.
    \item Symplectic drift in phase but stay true in amplitude (and thereby energy).
    \item In terms of energy, symplectic stays close to the analytic solution for much longer time. This is what defines a symplectic integrator and it is it's primary benefit.
    \item Explicit tends to add energy to the system (spiral outwards in phase-space plot), implicit ends to remove energy from the system (spiral inward in phase-space plot). Symplectic stays in the same orbit in phase-space, i.e. conserves the energy.
\end{itemize}

\subsection{The Two Symplectic Euler Methods Compared} \label{app:symplectic_difference}
We call the first version \eqref{al:ho-euler_s1} ``Symplectic1'' and the second version \eqref{al:ho-euler_s2} ``Symplectic2''. We see that they yield essential identical solutions. In this case the only difference is a phase shift of the momentum error by $\pi$ in figure \ref{fig:symplectic-difference}.
\begin{figure}
    \centering
        \subbottom[Symplectic1]{
            \includegraphics[scale=0.35]{fig/ho/ho_x(t)_euler_symplectic.pdf}
        }
        \subbottom[Symplectic2]{
            \includegraphics[scale=0.35]{fig/ho/ho_x(t)_euler_symplectic2.pdf}
        }
        \caption{Position x(t)}
\end{figure}

\begin{figure}
    \centering
        \subbottom[Symplectic1]{
            \includegraphics[scale=0.35]{fig/ho/ho_x(t)-error_euler_symplectic.pdf}
        }
        \subbottom[Symplectic2]{
            \includegraphics[scale=0.35]{fig/ho/ho_x(t)-error_euler_symplectic2.pdf}
        }
        \caption{Position x(t) error}
\end{figure}

\begin{figure}
    \centering
        \subbottom[Symplectic1]{
            \includegraphics[scale=0.35]{fig/ho/ho_p(t)_euler_symplectic.pdf}
        }
        \subbottom[Symplectic2]{
            \includegraphics[scale=0.35]{fig/ho/ho_p(t)_euler_symplectic2.pdf}
        }
        \caption{Momentum p(t)}
\end{figure}

\begin{figure}
    \centering
        \subbottom[Symplectic1]{
            \includegraphics[scale=0.35]{fig/ho/ho_p(t)-error_euler_symplectic.pdf}
        }
        \subbottom[Symplectic2]{
            \includegraphics[scale=0.35]{fig/ho/ho_p(t)-error_euler_symplectic2.pdf}
        }
        \caption{Momentum p(t) error. Note the difference in phase.}
    \label{fig:symplectic-difference}
\end{figure}

\begin{figure}
    \centering
        \subbottom[Symplectic1]{
            \includegraphics[scale=0.35]{fig/ho/ho_E(t)_euler_symplectic.pdf}
        }
        \subbottom[Symplectic2]{
            \includegraphics[scale=0.35]{fig/ho/ho_E(t)_euler_symplectic2.pdf}
        }
        \caption{Energy E(t)}
\end{figure}

\begin{figure}
    \centering
        \subbottom[Symplectic1]{
            \includegraphics[scale=0.35]{fig/ho/ho_phase-space_euler_symplectic.pdf}
        }
        \subbottom[Symplectic2]{
            \includegraphics[scale=0.35]{fig/ho/ho_phase-space_euler_symplectic2.pdf}
        }
        \caption{Phase-space}
\end{figure}


\section{Fourier Analysis}

$L(\Omega_h)$ is the set of functions $\Omega_h \rightarrow \mathbb{R}$; $L(\Omega_h)$ is isomorphic, as $\mathbb{R}^{(N-1)^2}$.

The function in $L(\Omega_h)$ are extended to $\overline{\Omega_h}$ by setting value zero there.

So, we can now consider the Laplacian $\Delta_h$ as an operator $L(\Omega_h) \rightarrow L(\Omega_h)$.

Is this operator invertible? Or, for $f_h \in L(\Omega_h)$, there exists a unique function $v_h$ such that:
\begin{equation*}
\Delta_h v_h = f_h
\end{equation*}

\begin{equation}
\Delta_h v_h(x, y) = f_h(x, y)  \quad (x, y) in \Omega_h
\end{equation}

\begin{equation}
v_h(x, y) = 0 \quad (x, y) \in \Gamma_h
\end{equation}

This means $\Delta_h$ invertible.

We know that the previous problem has a unique solution.

So $\Delta_h$ is invertible and $\Delta_h^{-1}$ exists.
Is $\Delta_h^{-1}$ uniformly bounded with respect to $h$?

Consider $L(\Omega_h)$ with the $L^\infty(\Omega_h)$.

\begin{equation*}
|| \Delta_h^{-1} || = \sup_{f_h \in L^{\infty}(\Omega_h), f_h \neq 0} \frac{||v_h||_{L^{\infty}(\Omega_h)}}{||f_h||_{L^{\infty}(\Omega_h)}}
\end{equation*}

$\Delta_h^{-1}$ uniformly bounded with respect to $h$ means there exists $C \ge 0$, independent of $h$, such that:

\begin{equation*}
|| \Delta_h^{-1} || \le C
\end{equation*}

For the five-point discretization, we have:

\begin{equation*}
||v_h||_{L^{\infty}(\Omega_h)} \le \frac{1}{8} ||f_h||_{L^{\infty}(\Omega_h)}
\end{equation*}

for any problem with right-hand side $f_h$.

Then:

\begin{equation*}
|| \Delta_h^{-1} || \le \underbrace{\frac{1}{8}}_{= C}
\end{equation*}

The relation between the convergence error:

\begin{equation*}
e_h = u_h - {u|}_{\Omega_h} \in L(\Omega_h)
\end{equation*}

and the consistency error:

\begin{equation*}
\epsilon_h = \Delta_h u|_{\overline{\Omega_h}} - (\Delta u)|_{\Omega_h} \in L(\Omega_h)
\end{equation*}

is:
\begin{equation*}
\Delta_h e_h = - \epsilon_h
\end{equation*}

So:
\begin{equation*}
e_h = \Delta_h^{-1}(-\epsilon_h)
\end{equation*}

and then:
\begin{equation*}
||e_h||_{L^{\infty}(\Omega_h)} \le || \Delta_h^{-1} || {|| \epsilon_h ||}_{L^\infty(\Omega_h)}
\end{equation*}

and then:
\begin{equation*}
||e_h||_{L^{\infty}(\Omega_h)} \le C {|| \epsilon_h ||}_{L^\infty(\Omega_h)}
\end{equation*}

$L^\infty$ on $L(\Omega_h)$ is the discrete analogous of the $L^\infty$ on $L(\Omega)$.

We introduce a norm on $L(\Omega_h)$ that is a discrete analogous of the $L^2$ norm on $L^2(\Omega)$.

For $v: \Omega \rightarrow \mathbb{R}$,

\begin{equation*}
|| v || = \sqrt{\int_{(x, y) \in \Omega} v(x,y)^2 d(x, y)}
\end{equation*}

is called the $L^2$ norm of $v$.

$L^2(\Omega)$ is the set of the function $\Omega \rightarrow \mathbb{R}$ such that:

\begin{equation*}
\int_{(x, y) \in \Omega} v(x,y)^2 d(x, y) < \infty
\end{equation*}

On $L^2(\Omega)$, we can introduce the scalar product:
\begin{equation*}
<v, w> = \int_{(x, y) \in \Omega} v(x,y) w(x,y) d(x, y)
\end{equation*}
with $v, w \in L^2(\Omega)$.

Then, the $L^2$ norm is the norm derived by this scalar product:
\begin{equation*}
||v|| = \sqrt{<v, v>}, \quad L^2(\Omega)
\end{equation*}

Now, we introduce discrete forms of this scalar product and this norm on $L(\Omega_h)$ and then to bound uniformly with respect to $h$ the operator norm:

\begin{equation*}
|| \Delta_h^{-1} || = \sup_{f_h \in L^{\infty}(\Omega_h), f_h \neq 0} \frac{||v_h||_h}{||f_h||_h}
\end{equation*}

where $||.||_h$ is the discrete $L^2$ norm.

First, we consider the $1D$ version of the Poisson problem.

\begin{equation*}
\Omega = (0, 1) =: I
\end{equation*}
\begin{equation*}
\Omega_h = \{h, 2h, \dots, (N-1)h \} =: I_h
\end{equation*}

$L^2(I)$ is the set of the functions $v: I \rightarrow \mathbb{R}$ such that:

\begin{equation*}
\int_{0}^{1} v(x)^2 d(x) < +\infty
\end{equation*}

The scalar product on $L^2(I)$ is:
\begin{equation*}
<v, w> = \int_0^1 v(x) w(x) d(x), \quad v, w \in L^2(I)
\end{equation*}

and the $L^2$ norm is:
\begin{equation*}
||v|| = \sqrt{\int_0^1 v(x)^2 d(x)}, \quad v \in L^2(I)
\end{equation*}

On $L(I_n)$ we introduce the scalar product:
\begin{equation*}
<v_h, w_h> = h \sum_{k=1}^{N-1} v_h(k h) w_h(kh)
\end{equation*}

and the norm:
\begin{equation*}
{|| v_h ||}_h = \sqrt{<v_h, v_h>} = \sqrt{h \sum_{k=1}^{N-1} v_h(k h)^2}, \quad v_h \in L(I_h)
\end{equation*}

$||.||$ is the $L^2$ norm on $I_h$.

\subsubsection{Exercise}
Explain why the previous scalar product and norm on $L(I_h)$ are discretizations of the scalar product and norm on $L^2(I)$.

\begin{equation*}
\int_{0}^{1} g(x) dx \approx h \sum_{k=1}^{N-1} g(kh) = \sum_{k=1}^{N-1} g(kh) h
\end{equation*}

When $g = v w \rightarrow $ scalar product, $g = v^2 \rightarrow L^2$ norm.

In $L^2(I)$ we have Fourier series. Consider the functions $\Phi_m \in L^2(I)$, $m \in \{1, 2, 3, \dots \}$ given by:

\begin{equation*}
\Phi_m(x) = sin(m \pi x), \quad x \in (0, 1)
\end{equation*}

These functions are orthogonal:
\begin{equation*}
<\Phi_m, \Phi_n> = 0 \quad \forall m \neq n
\end{equation*}

They constitute an orthogonal base for $L^2(I)$; for any $v \in L^2(I)$ we have the \textit{Fourier series of $v$}:
\begin{equation*}
v = \sum_{m=1}^{\infty} c_m \Phi_m
\end{equation*}

with:
\begin{equation*}
c_m = \frac{<v, \Phi_m>}{<\Phi_m, \Phi_m>}, \quad m \in \{1, 2, 3, \dots \}
\end{equation*}

The Fourier series converges in $L^2$:
\begin{equation*}
\lim_{M \rightarrow \infty} || v - \sum_{m = 1}^{M} c_m \Phi_m || = 0
\end{equation*}

We have the \textit{Parseval's identity}:
\begin{equation*}
|| v ||^2 = \sum_{m = 1}^\infty c_m^2 || \Phi_m ||^2, \quad v \in L^2(I)
\end{equation*}

The functions $\Phi_m$, with $m \in \{1, 2, 3, \dots\}$ are eigenvectors of the 1D Laplacian: $\Delta$ = "second derivative".

For $m \in \{1, 2, 3, \dots \}$, we have:
\begin{equation*}
\Delta \Phi_m(x) = \frac{d^2}{d x^2} \sin(m \pi x) = \frac{d}{dx}(m \pi \cos(m \pi x)) = m \pi (-m \pi \sin(m \pi x)) = -m^2 \pi^2 \sin(m \pi x)
\end{equation*}
\begin{equation*}
= - m^2 \pi^2 \Phi_m(x), \quad x \in (0, 1)
\end{equation*}

$\Phi_m$ is an eigenvector of $\Delta$ with relevant eigenvalue $- m^2 \pi^2 = \lambda_m$.

We do the same for $L(I_h)$.

We introduce the functions $\Phi_{m,h} \in L(I_h), m \in \{1, 2, \dots \}$, given by:
\begin{equation*}
\Phi_{m,h}(x) = \sin(m \pi x), \quad x \in I_h
\end{equation*}

The functions $\Phi_{m,h}, m \in \{1, 2, \dots \}$, are eigenvectors of the discrete laplacian:
\begin{equation*}
\Delta_h v_h(x) = \frac{v_h(x-h) - 2v_h(x) + v_h(x + h)}{h^2}, \quad x \in I_h and v_h \in L(I_h)
\end{equation*}

For $m \in \{1, 2, 3, \dots \}$,
\begin{equation*}
\Delta_h \Phi_{m,h} (x) = \frac{\sin(m \pi (x-h)) - 2 \sin (m \pi x) + \sin(m \pi (x + h))}{h^2}
\end{equation*}

Using Prostapheresis formulas:
\begin{equation*}
= \frac{2 \sin(m \pi x) \cos(m \pi x) - 2 \sin(m \pi x)}{h^2}
\end{equation*}

\begin{equation*}
= - \frac{1 - 2 \cos(m \pi x)}{h^2} \underbrace{\sin(m \pi x)}_{\Phi_{m,h}(x)}, \quad x \in I_h
\end{equation*}

$\Phi_{m,h}$ is an eigenvector of the discrete 1D laplacian with relevant eigenvalue:

$\lambda_{m, h} = -2 \frac{1 - \cos(m \pi h)}{h^2} = -2 \frac{2 \sin^2(\frac{m \pi x}{2})}{h^2} = -4 \frac{\sin^2(\frac{m \pi x}{2})}{h^2}$

We have:
\begin{equation*}
0 > \lambda_{1, h} > \lambda_{2, h} > \dots > \lambda_{N - 1, h}
\end{equation*}

\subsubsection{Exercise}

Prove that:
\begin{enumerate}
	\item $\lim_{h \rightarrow 0} \lambda_m = - m^2 \pi^2$
	\item $\lambda_{N - 1, h} > - \frac{4}{h^2}$
	\item $- 8 \ge \lambda_{1,h}$
\end{enumerate}

Proofs:
\begin{enumerate}
	\item
\begin{equation*}
\lim_{h \rightarrow 0} \lambda_m = \lim_{h \rightarrow 0}( -4 \frac{\sin^2(\frac{m \pi x}{2})}{h^2})
\end{equation*}
	Using the limit $\lim_{x \rightarrow 0} \frac{\sin x}{x} = 1$ and $\lim_{x \rightarrow 0} \frac{\sin^2 x}{x^2} = 1$
\begin{equation*}
= -m^2 h^2 \lim_{h \rightarrow 0} (\frac{\sin(\frac{m \pi x}{2})}{\frac{m \pi x}{2}})^2 = - m^2 h^2
\end{equation*}

	\item
\begin{equation*}
\lambda_{N - 1, h} = - 4 \frac{\sin^2(\frac{(N-1) \pi x h}{2})}{h^2} > -4 \frac{\sin^2(\pi/2)}{h^2} = - \frac{4}{h^2}
\end{equation*}

	\item
\begin{equation*}
\lambda_{1,h} = - 4 \frac{\sin^2(\frac{\pi h}{2})}{h^2} = - \pi^2 ( \frac{\sin (\frac{\pi h}{2})}{\frac{\pi h}{2}})^2
\end{equation*}
As a function of $h$, $\lambda_{1, h}$ obtains the maximum value when $h$ is the maximum.

The maximum $h$ possible is $h = \frac{1}{2}$.

\begin{equation*}
\lambda_{1,h} \le \lambda_{1, \frac{1}{2}} = - 4 \frac{\sin^2(\pi \frac{1}{2})}{(\frac{1}{2})^2} = -4 \frac{\sin^2(\frac{\pi}{4})}{\frac{1}{4}} = - 16 (\frac{\sqrt{2}}{2})^2 = -8
\end{equation*}

\end{enumerate}

$\blacksquare$

$\Phi_{1,h}, \dots, \Phi_{N-1,h}$ are a bases for the space $L(I_h) = \mathbb{R}^{N-1}$.

So for any $v_h \in \mathbb{R}^{N-1}$, we have $v_h = \sum_{m=1}^{N-1} c_{m,h} \Phi_{m,h}$.

Moreover, observe that $\Delta_h$ is symmetric and so $\Phi_{1,h}, \dots, \Phi_{N-1,h}$ are orthogonal in the standard scalar product:

\begin{equation*}
<v_h, w_h> = \sum_{x \in I_h} v_h(x) w_h(x)
\end{equation*}

of $\mathbb{R}^{N-1}$. The scalar product introduced in $L(I_h)$ is:

\begin{equation*}
<v_h, w_h>_h = h <v_h, w_h>
\end{equation*}

So $\Phi_{1,h}, \dots, \Phi_{N-1,h}$ are orthogonal also in the scalar product $<., .>_h$

\subsubsection{Exercise}

For $v_h \in L(I_h)$, prove that:

\begin{equation*}
c_{m,h} = \frac{<v_h, \Phi_{m,h}>}{||\Phi_{m,h}||_h^2} = <\Phi_{m,h}, \Phi_{m,h}> \quad, m \in \{1, \dots, N-1\}
\end{equation*}

Moreover, prove that the discrete Parceval's identity:

\begin{equation*}
||v_h||_h^2 = \sum_{m=1}^{N-1} c_{m,h}^2 ||\Phi_{m,h}||_h^2
\end{equation*}

We have:
\begin{equation*}
<v_h, \Phi_{m,h}>_h = <\sum_{n=1}^{N-1} c_{n,h} \Phi_{n,h}, \Phi_{m,h}>_h = \sum_{n=1}^{N-1} c_{n,h} \underbrace{<\Phi_{n,h}, \Phi_{m,h}>_h}_{=0 \;\; \forall n \neq m} = c_{m,h} <\Phi_{m,h}, \Phi_{m,h}>
\end{equation*}

\begin{equation*}
||v_h||_h^2 = <v_h, v_h>_h = <\sum_{n=1}^{N-1} c_{n,h} \Phi_{n,h}, \sum_{m=1}^{N-1} c_{m,h} \Phi_{m,h}>_h = \sum_{n=1}^{N-1} \sum_{n=1}^{N-1} c_{n,h} c_{m,h} <\Phi_{n,h}, \Phi_{m,h}>_h = \sum_{m=1}^{N-1} c_{m,h}^2 \underbrace{<\Phi_{m,h}, \Phi_{m,h}>}_{= ||\Phi_{m,h}||}
\end{equation*}

Now we're ready for the band of:

\begin{equation*}
||\Delta_h^{-1} || = \sup_{f_h \in L(I_h)} \frac{||v_h||_h}{||f_h||_h}
\end{equation*}

where $v_h$ is the solution of:

\begin{equation*}
\Delta_h v_h = f_h
\end{equation*}

Let:
\begin{equation*}
v_h = \sum_{m=1}^{N-1} c_{m,h} \Phi_{m,h}
\end{equation*}
the discrete Fourier series for $v_h$.

We have:
\begin{equation*}
f_h = \Delta_h v_h = \Delta_h \sum_{m=1}^{N-1} c_{m,h} \Phi_{m,h} = \sum_{m=1}^{N-1} c_{m,h} \underbrace{\Delta_h\Phi_{m,h}}_{= \lambda_{m, h}\Phi_{m,h}} = \sum_{m=1}^{N-1} (c_{m,h} \lambda_{m, h}) \Phi_{m,h}
\end{equation*}
which is the discrete Fourier series of $f_h$.

Now we use the discrete Parseval's identity:
\begin{equation*}
||f_h||_h^2 = \sum_{m=1}{N-1} (c_{m,h} \lambda_{m,h})^2 ||\Phi_{m,h}||_h^2 = \sum_{m=1}{N-1} c_{m,h}^2 \underbrace{\lambda_{m,h}^2}_{= |\lambda_{m,h}|^2} ||\Phi_{m,h}||_h^2
\end{equation*}

\begin{equation*}
-8 \ge \lambda_{1,h} \ge \lambda_{2,h} \ge \dots \implies 8 \le |\lambda_{1,h}| \le |\lambda_{2,h}| \le \dots
\end{equation*}

\begin{equation*}
\ge \sum_{m=1}^{N-1} 8^2 c_{m,h}^2 ||\Phi_{m,h}||_h^2 = 8^2 \underbrace{\sum_{m=1}^{N-1} c_{m,h}^2 ||\Phi_{m,h}||_h^2}_{= ||v_h||_h^2}
\end{equation*}

So, we have proved:
\begin{equation*}
||v_h||^2 \le \frac{1}{8^2} \dots
\end{equation*}

Since $f_h \in L(I_h)$ is arbitrary we have:
\begin{equation*}
||\Delta_h^{-1}|| \sup_{f_h \in L(I_h)} \frac{||v_h||_h}{||f||_h} \le \frac{1}{8}
\end{equation*}

Now we pass to the 2D case.

In the 2D case:
\begin{equation*}
\Omega = (0, 1)^2 = I^2
\end{equation*}

\begin{equation*}
\Omega_h = I^2 = \{(mh, nh): m,n \in \{1, \dots, N-1 \}\}
\end{equation*}

$L(\Omega_h)$ is isomorphic to $\mathbb{R}^{(N-1)^2}$:
\begin{equation*}
L(\Omega_h) = \mathbb{R}^{(N-1)^2}
\end{equation*}

We introduce, for $m,n \in \{1, \dots, N-1\}$, the functions $\Phi_{m,n,h} \in L(\Omega_h)$ given by:
\begin{equation*}
\Phi_{m,n,h}(x,y) = \Phi_{m,h}(x) \Phi_{n,h}(y) \quad (x,y) \in \Omega_h
\end{equation*}

where $\Phi_{m,h}$ and $\Phi_{n,h}$ were defined in the 1D case.

The scalar product on $L(\Omega_h)$ is:
\begin{equation*}
<v_h, w_h> = h^2 \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} v_h (m_h, n_h) w_h(m_h, n_h)
\end{equation*}

and the $L^2$ norm is:
\begin{equation*}
||v_h||_h = \sqrt{<v_h, v_h>} = \sqrt{h^2 \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} v_h(m_h, n_h)^2}
\end{equation*}
for $v_h, w_h \in L(\Omega_h)$.

For $m, n \in \{1, \dots, N-1\}$, $\Phi_{m,n,h}$ is an eigenvector of the 2D discrete laplacian $\Delta_h$.

\begin{equation*}
\Delta_h \Phi_{m,n,h}(x,y) = \frac{\Phi_{m,n,h}(x-h, y) - 2 \Phi_{m,n,h}(x, y) + \Phi_{m,n,h}(x+h, y)}{h^2} + \frac{\Phi_{m,n,h}(x, y-h) - 2 \Phi_{m,n,h}(x, y) + \Phi_{m,n,h}(x, y+h)}{h^2}
\end{equation*}

\begin{equation*}
= \frac{\Phi_{m,h}(x - h) \Phi_{n,h}(y) - 2 \Phi_{m,h}(x) \Phi_{n,h}(y) + \Phi_{m,h}(x+h)\Phi_{n,h}(y)}{h^2} + \frac{\Phi_{m,h}(x) \Phi_{n,h}(y - h) - 2 \Phi_{m,h}(x) \Phi_{n,h}(y) + \Phi_{m,h}(x)\Phi_{n,h}(y+h)}{h^2}
\end{equation*}

\begin{equation*}
= \frac{\Phi_{m,h}(x - h) - 2 \Phi_{m,h}(x) + \Phi_{m,h}(x+h) }{h^2} \Phi_{m,h}(y) +  \Phi_{m,h}(x) \frac{\Phi_{n,h}(y - h) - 2\Phi_{n,h}(y) + \Phi_{n,h}(y+h)}{h^2}
\end{equation*}

\begin{equation*}
= \lambda_{m,h} \Phi_{m,h}(x) \Phi_{n,h}(y) + \Phi_{m,h}(x) \lambda_{n,h} \Phi_{n,y}(y) = (\lambda_{m,h} + \lambda_{n,h}) \underbrace{\Phi_{m,h}(x) \Phi_{n,h}(y)}_{= \Phi_{m,n,h}(x,y)}
\end{equation*}

We have proved that $\Phi_{m,n,h}$ is an eigenvector of 2D $\Delta_h$ with relevant eigenvalue $\lambda_{m, h} + \lambda_{n,h}$.

Now, we prove that $\Phi_{m,n,h}, m,n \in \{1, \dots, N-1\}$ are orthogonal in the scalar product of $L(\Omega_h)$ we have introduced.

For $m,n,p,q \in \{1, \dots, N-1\}$ with $(m, n) \neq (p, q)$:
\begin{equation*}
<\Phi_{m,n,h}, \Phi_{p,q,h}>_h = h^2 \sum_{k=1}^{N-1} \sum_{l=1}^{N-1} \Phi_{m,n,h}(kh, lh) \Phi_{p,q,h}(kh, lh)
\end{equation*}

\begin{equation*}
= h^2 \sum_{k=1}^{N-1} \sum_{l=1}^{N-1} \Phi_{m,h}(kh)\Phi_{n,h}(lh) \Phi_{p,h}(kh)\Phi_{q,h}(lh)
\end{equation*}

\begin{equation*}
= h^2 (\sum_{k=1}^{N-1} \Phi_{m,h}(kh)\Phi_{p,h}(kh)) (\sum_{l=1}^{N-1} \Phi_{n,h}(lh)\Phi_{q,h}(lh))
\end{equation*}

\begin{equation*}
= \underbrace{<\Phi_{m,h}, \Phi_{p,h}>_h}_{1D scalar product} \cdot \underbrace{<\Phi_{n,h}, \Phi_{q,h}>_h}_{1D scalar product}
\end{equation*}

Remember $(m,n) \neq (p, q)$:
\begin{equation*}
m \neq p \text{ or } m n \neq q
\end{equation*}
so the above scalar product is zero.

Since the $(N-1)^2$ functions $\Phi_{m,n,h}$, $m,n \in \{1, \dots, N-1\}$ are nonzero orthogonal functions, they $(N-1)^2$ linearly independent functions of $\mathbb{R}^{(N-1)^2}$ and so they constitute a bases for $\mathbb{R}^{(N-1)^2}$.

So any $v_h \in L(\Omega_h)$ can be written as:
\begin{equation*}
v_h = \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} \dots
\end{equation*}

Exactly as in the 1D case, we have:
\begin{equation*}
c_{m,n,h} = \frac{<v_h, \Phi_{m,n,h}>_h}{||\Phi_{m,n,h}||} \dots
\end{equation*}

\dots

Now we are ready to give a bond for
\begin{equation*}
||\Delta_h^{-1}|| = \sup_{f_h \in L(\Omega_h)} \frac{||v_h||_h}{||f_h||_h}
\end{equation*}

where $v_h$ is the solution of: $\Delta_h v_h = f_h$

\dots

Let $f_h \in L(\Omega_h)$ and let $v_h$ be the solution of $\Delta_h v_h = f_h$. Let:
\begin{equation*}
v_h = \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} c_{m,n,h} \Phi_{m,n,h}
\end{equation*}
be the Fourier series of $v_h$.

We have:
\begin{equation*}
f_h = \Delta_h v_h = \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} c_{m,n,h} \underbrace{\Delta_h \Phi_{m,n,h}}_{(\lambda_{m,h} + \lambda_{n,h})\Phi_{m,n,h}} = \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} c_{m,n,h} (\lambda_{m,h} + \lambda_{n,h}) c_{m,n,h} \Phi_{m,n,h}
\end{equation*}
which is the discrete Fourier series of $f_h$.

So:
\begin{equation*}
||f_h||_h^2 = \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} \underbrace{(\lambda_{m,h} + \lambda_{n,h})^2}_{||\Phi_{m,n,h}||_h^2} c_{m,n,h}^2
\end{equation*}

\begin{equation*}
= \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} (\underbrace{|\lambda_{m,h}|}_{\ge 8} + \underbrace{|\lambda_{n,h}|}_{\ge 8})^2 c_{m,n,h}^2 \ge \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} 16^2 c_{m,n,h}^2
\end{equation*}

Then we have:
\begin{equation*}
||v_h||_h^2 \le \frac{1}{16^2} ||f_h||_h^2
\end{equation*}

\begin{equation*}
||v_h||_h \le \frac{1}{16} ||f_h||_h
\end{equation*}

Since $f_h \in L(\Omega_h)$ is arbitrary:
\begin{equation*}
||\Delta_h^{-1}|| = \sup_{f_h \in L(\Omega_h)} \frac{||v_h||_h}{||f_h||_h} \le \frac{1}{16}
\end{equation*}

Remember we have:
\begin{equation*}
\Delta_h \underbrace{e_h}_{convergence error} = - \underbrace{\epsilon_h}_{consistency error}
\end{equation*}

So:
\begin{equation*}
||e_h||_h \le ||\Delta_h^{-1}|| ||\epsilon_h||_h \le \frac{1}{16} ||\epsilon_h||_h
\end{equation*}

In case of the $L^\infty$ norm, we had:
\begin{equation*}
||e_h||_{L^\infty(\Omega_h)} \le \frac{1}{8} ||\epsilon_h||_{L^\infty(\Omega_h)}
\end{equation*}

\subsubsection{Exercise}

Prove that, for $v_h \in L(\Omega_h)$, we have:
\begin{equation*}
||v_h|| \le ||v_h||_{L^\infty(\Omega_h)}
\end{equation*}

and then conclude with the estimate:
\begin{equation*}
||e_h||_h = O(h^2), h \rightarrow 0
\end{equation*}

\begin{equation*}
||v_h||_h = \sqrt{h^2 \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} \underbrace{v_h(kh, nh)^2}_{\le ||v_h||_{L^\infty(\Omega_h)}^2}}
\end{equation*}

\begin{equation*}
\le \sqrt{h^2 \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} ||v_h||_{L^\infty(\Omega_h} } = ||v_h||_{L^\infty(\Omega_h} \sqrt{h^2 \sum_{m=1}^{N-1} \sum_{n=1}^{N-1} 1}
\end{equation*}

\begin{equation*}
= ||v_h||_{L^\infty(\Omega_h} \underbrace{\sqrt{h^2 (N-1)}}_{= h (N-1)}
\end{equation*}

\begin{equation*}
\le ||v_h||_{L^\infty(\Omega_h} \underbrace{h N}_{= 1} = ||v_h||_{L^\infty(\Omega_h}
\end{equation*}

Then:
\begin{equation*}
||e_h||_h \le \frac{1}{16} ||\epsilon_h||_h \le \frac{1}{16} \overbrace{||\epsilon_h||_{L^\infty(\Omega_h)}}^{= O(h^2), \, h \rightarrow 0}
\end{equation*}

and then:
\begin{equation*}
\qquad\qquad\qquad\qquad\qquad\qquad ||e_h||_h = O(h^2), \, h \rightarrow 0   \qquad\qquad\qquad\qquad\qquad\qquad \blacksquare
\end{equation*}

\section{Some notes needs to be copied from paper here}

...

We proved: for $v: \overline{\Omega} \rightarrow \mathbb{R}$ of class $C^3$:

..

The order of consistency error is only $O(h)$, not $O(h^2)$ as in the case of the square.
We have the discrete problem:

\begin{equation*}
\Delta_h u_h (x, y) = f(x, y), \quad (x, y) \in \Omega_h
\end{equation*}
\begin{equation*}
u_h(x, y) = g(x, y), \quad (x,y) \in \Gamma_h
\end{equation*}

This is a linear system of M unknowns $u_h(x, y), \quad (x,y) \in \Omega_h$, where $M$ is the number of points in $\Omega_h$, into $M$ equations; we have an equation for any point in $\Omega_h$.

With respect to the case of the square, the matrix of the system is in general non-symmetric, because:

\begin{equation*}
\Delta_h u_h(x, y) = \frac{2}{h_1 (h_1 + h_2)} u_h(x - h_1, y) - \frac{2}{h_1 h_2} (x, y) + \frac{2}{h_2 (h_1 + h_2)} (x + h_2, y) + \frac{2}{h_3 (h_3 + h_4)} u_h(x, y - h_3) - \frac{2}{h_3 h_4} (x, y) + \frac{2}{h_3 (h_3 + h_4)} (x, y + h_4) = f(x, y), \quad (x,y) \in \Omega_h
\end{equation*}

Symmetric matrix: $a_{ij} = a_{ji}$
the coefficient of the \textit{j}-th matrix, in the \textit{i}-th equation is equal to the coefficient of the \textit{i}-th matrix in the \textit{j}-th equation.
The coefficient in the \textit{j}-th equation of the \textit{i}-th unknown is

\begin{equation*}
\frac{2}{h_2 (h_2 + \hat{h_2})} u_h(x, y) - \frac{2}{h_2 \hat{h_2}} u_h(x + h_2, y)+ \frac{2}{\hat{h_2}(h_2 + \hat{h_2})} u_h(x + \hat{h_2}, y)
\end{equation*}

Characteristics of the matrix that are maintained in the general case:
\begin{itemize}
	\item sparsity (the matrix is sparse): in any row there are at most 5 non-zero elements;
	\item diagonal elements are negative and off-diagonal elements are positive
	\item diagonal dominance
\end{itemize}

An MxM matrix A is called diagonal dominant if:

\begin{equation*}
\forall i \in \{1, \dots, M\}: |a_{ii}| \ge \sum_{j=1, j \neq i}^{M} |a_{ij}|
\end{equation*}

Maximum sum of the off-diagonal elements is:

\begin{equation*}
\frac{2}{h_1 (h_1 + h_2)} + \frac{2}{h_2 (h_1 + h_2)} + \frac{2}{h_3 (h_3 + h_4)} + \frac{2}{h_4 (h_3 + h_4)} = \frac{2}{h_1 + h_2} (\frac{1}{h_1} + \frac{1}{h_2}) + \frac{2}{h_3 + h_4 (\frac{1}{h_3} + \frac{1}{h_4})}
\end{equation*}

\begin{equation*}
\frac{2}{h_1 + h_2} \frac{h_1 + h_2}{h_1 h_2} + \frac{2}{h_3 + h_4} \frac{h_3 + h_4}{h_3 h_4} = \frac{2}{h_1 + h_2} + \frac{2}{h_3 + h_4}
\end{equation*}

We have, by stability plus consistency of order one, convergence of order one. But
\begin{enumerate}
	\item Points in $\mathring{\Omega}_h$ have consistency error $O(h^2)$;
	\item number of points in $\Omega_h \mathring{\Omega}_h$ (where the consistency error is $O(h)$)  divided by number of points in $\mathring{\Omega}_h$ (where the consistency error is $O(h^2)$) $= O(h)$
	\item Points of $\Omega_h \\ \mathring{\Omega}_h$ are at a distance $O(h)$ of the boundary $\Gamma_h$, where the solution is known exactly.
\end{enumerate}


\subsection{Acceleration Field for a Rigid Body}
\begin{frame}
	Acceleration vector $\vb{a}{}=\xvec[:]{\bm{r}}$ with respect to time $t$:
	\[\vb{a}{}= \frac{d}{dt}(\vb{v}{O} + \vb{\omega}{}\times\vb{r}{}) = \xvec[.]{\bm{r}}_{\bm{M}}+\xvec[.]{\bm{\omega}}\times\vb{r}{} + \vb{\omega}{}\times\xvec[.]{\bm{r}} = \vb{a}{0}+\vb{\alpha}{}\times\vb{r}{}+\vb{\omega}{}\times(\vb{\omega}{}\times\vb{r}{})\]
	where $\displaystyle \vb{\alpha}{} = \xvec[.]{\bm{\omega}} = \dot{\omega}_x\ih + \dot{\omega}_y\jh + \dot{\omega}_z\kh + \omega_x\frac{d\ih}{dt} + \omega_y\frac{d\jh}{dt}+\omega_z\frac{d\kh}{dt}$\\
	$\hskip 22mm\displaystyle = \alpha_x\ih + \alpha_y\jh + \alpha_z\kh + \omega_x\vb{\omega}{}\times\ih + \omega_y\vb{\omega}{}\times\jh + \omega_z\vb{\omega}{}\times\kh$\\
	$\hskip 22mm\displaystyle = \alpha_x\ih + \alpha_y\jh + \alpha_z\kh + \vb{\omega}{}\times\vb{\omega}{}$\\
	$\hskip 22mm\displaystyle = \alpha_x\ih + \alpha_y\jh + \alpha_z\kh$
	\begin{block}{Formula}
		For any point of a rigid body, its acceleration equation is:
		\[
		\vb{a}{}=\vb{a}{0}+\vb{\alpha}{}\times\vb{r}{}+\vb{\omega}{}\times(\vb{\omega}{}\times\vb{r}{})
		\]
		where $\vb{\alpha}{}\times\vb{r}{}$ is tangential acceleration\\\hskip10.5mm
		$\vb{\omega}{}\times(\vb{\omega}{}\times\vb{r}{})$ is centripetal acceleration
	\end{block}
\end{frame}

\begin{frame}
	In matrix form, acceleration vector $\vb{a}{M}$ of point $M$ relative to fixed reference frame $(O_0x_0y_0z_0)$ can be written as:
	\[
	\vb{a}{M}=
	\begin{bmatrix}
	a_x\\a_y\\a_z
	\end{bmatrix}=
	\begin{bmatrix}
	a_{Ox}+(z\alpha_y-y\alpha_z)+\omega_y(y\omega_x-x\omega_y)+\omega_z(x\omega_x-x\omega_z)\\
	a_{Oy}+(x\alpha_z-z\alpha_x)+\omega_z(z\omega_y-y\omega_z)+\omega_x(x\omega_y-y\omega_z)\\
	a_{Oz}+(y\alpha_x-x\alpha_y)+\omega_x(x\omega_z-z\omega_x)+\omega_y(y\omega_z-z\omega_y)
	\end{bmatrix}
	\]\hskip7mm
	$\displaystyle= \vb{a}{O}+\vb{\alpha}{}\times\vb{r}{MO} + \vb{\omega}{}\times(\vb{\omega}{}\times\vb{r}{MO}) = \vb{a}{O} +\vb{a}{MO}^{\bm t}+ \vb{a}{MO}^{\bm n}$\\
	where
	\[
	\vb{a}{MO}^{\bm t}=
	\begin{cases}
	\perp \vb{r}{MO}\rightturn \vb{\alpha}{}\\\alpha r_{MO}
	\end{cases}
	\]
	\[
	\hskip 6mm\vb{a}{MO}^{\bm n}=
	\begin{cases}
	\uparrow\uparrow \vb{r}{MO}\\\omega^2r_{MO}=\frac{v_{MO}^2}{r_{MO}}
	\end{cases}
	\]
	For planar motions: $\vb{\omega}{}\times(\vb{\omega}{}\times\vb{r}{MO})=-\vb{\omega}{}^2\vb{r}{MO}$
\end{frame}


\subsection{Probability unit (probit)}

\subsubsection{The function}

The cumulative distribution function of the normal distribution.

\(\Phi (z)\)

\subsubsection{The derivative}

The normal distribution:

\(\Phi'(z)=\phi (z)\)


\subsection{Conversions}
\begin{itemize}
	\item From spherical to Cartesian
	\begin{equation*}
		(\rho, \theta, \phi) = (r\cos{\theta}\sin{\phi}, \rho\sin{\theta}\sin{\phi}, \rho\cos{\phi})
	\end{equation*}
	\item From Cartesian to Spherical
	\begin{equation*}
		(x, y, z)=\left(\sqrt{x^2 + y^2 + z^2}, \arctan{\left(\frac{y}{x}\right)}, \arccos{\left(\frac{z}{\sqrt{x^2 + y^2 + z^2}}\right)}\right)
	\end{equation*}
\end{itemize}


\subsection{Statistical Analysis}
\label{sec:statistical-analysis}

The first stage in our engine is analyzing the expanded tuples.
This phase collects simple statistics including average, variance, standard deviation, and approximate cardinality on each column of the table and estimates which sets of columns are correlated.

These statistics have three purposes.
First, they are used to detect univariate outliers, for example values that are several standard deviations from the mean in numerical attributes, or that have never occurred before in low cardinality attributes.
Second, they are used to determine which columns in the table are correlated.
Third, these statistics precompute parameters required by certain data models, thus speeding up the training phase of the models.

We focus on two inter-column correlation strategies:

\begin{itemize}
\item For mostly non-numerical datasets, we use a cardinality-based measure, flagging groups of expanded columns as correlated when their joint cardinality is below a user-specified threshold. When two columns are correlated (e.g., when one is computed directly from the other), the number of distinct pairs in the columns is similar to the number of distinct items in either column. On the other hand, when two columns are independent, the number of distinct pairs is close to the product of the number of distinct values in each column.
\item For mostly-numerical datasets, we use Pearson's product-moment
  correlation. It relies on the Pearson correlation coefficient,
  which measures linear dependencies between two vectors.

  Given two column vectors $X$ and $Y$, Pearson's coefficient $R$ is given by the following formula:
  \begin{align}
    \label{eqn:pearson}
    R = \frac{\Covar(X,Y)}{\sqrt{\Var(X)\Var(Y)}}
  \end{align}

  $R$'s value always lies between $-1$ and $1$. An $R$ value close to 0 indicates little or no correlation, while values close to $+1$ or $-1$ indicate strong positive or negative correlations, respectively. Pairs of columns with a value of \(R\) above a user-specified threshold are added to a list of correlation hints, for use by the models.
\end{itemize}

It is debatable whether correlations between expanded tuple fields from the same original value lead to better outlier detection. On the one hand such dependencies may provide valuable insight about the data (e.g., an event that occurs every Monday of May and every Thursday of June). On the other hand, taking these subtuple correlations into account vastly increases the size of the search space, and may add spurious hits to the results. Experimentally, we found that disregarding intra-field correlations made the entire process faster and more robust, and did not hurt accuracy on our test sets.

All aforementioned statistics and correlation hints can be computed using a single pass over the data: the expanded tuples are analyzed one row at a time, and the final statistics and correlations are computed after the last tuple has been processed. This contrasts with more advanced approaches to the detection of correlations and soft functional dependencies, such as the one used in CORDS~\cite{Ilyas2004}. Our simpler approaches yields a lower specificity, but still achieves good classification results, in part because each model only uses correlation hints as a guideline for interesting groups of columns to analyze. An excessive number of hints can thus affect performance, but does not significantly diminish the quality of the results. On the other hand, missing a correlation causes models to not analyze the corresponding group of columns, and thus to fail to uncover potential outliers. As with the other parts of our system, the correlation detector used in the statistical analysis phase is modular and could be replaced by any other scheme, including CORDS.

The results of the analysis pass are available to all models used at later stages in the tool.


\section{Linear Maps, Isomorphisms and the Rank-Nullity Theorem}
\begin{definition}[Linear Map]
    Let $V,W$ are vector spaces over $F$, a function $\alpha:V\to W$ is linear if for any $\lambda_1,\lambda_2\in F$ and $v_1,v_2\in V$,
    $$\alpha(\lambda_1v_1+\lambda_2v_2)=\lambda_1\alpha(v_1)+\lambda_2\alpha(v_2)$$
\end{definition}
\begin{example}
    1. Let $M$ be an $m\times n$ matrix, then $\alpha:\mathbb R^n\to\mathbb R^m$ via $x\mapsto Mx$ is a linear map.\\
    2. The functional $\alpha:C([0,1])\to C^1([0,1])$ via
    $$\alpha(f)(x)=\int_0^xf(t)\,\mathrm dt$$
    is a linear map.\\
    3. Fix $x\in[a,b]$, then the evaluation map $\alpha:C([a,b])\to\mathbb R$ via $f\mapsto f(x)$ is a linear map.
\end{example}
\begin{remark}
    The identity map is a linear map.
    Composition of linear maps is also a linear map.
\end{remark}
\begin{lemma}
    Let $V,W$ be vector spaces over $F$ and $B$ a basis for $V$.
    Let $\alpha_0:B\to W$ be a function, then there is a unique linear map $\alpha:V\to W$ that extends $\alpha_0$.
\end{lemma}
\begin{proof}
    For any $(b_i)\in B$, necessarily $\alpha\left(\sum_i\lambda_ib_i\right)=\sum_i\lambda\alpha_0(b_i)$.
    This is sufficient.
\end{proof}
\begin{remark}
    This lemma is true for infinite dimensional vector spaces as well.
    Often, to define linear map, we often just define its values on a basis and extend it by this lemma.
\end{remark}
\begin{corollary}
    Two linear maps that agree on a basis are the same.
\end{corollary}
\begin{proof}
    This is just the uniqueness statement.
\end{proof}
\begin{definition}
    Let $V,W$ be vector spaces over $F$.
    A linear bijection $\alpha:V\to W$ is an isomorphism (of vector spaces).
    If such a map exists, then we say $V,W$ are isomorphic (as vector spaces), written as $V\cong W$.
\end{definition}
\begin{remark}
    If $\alpha$ is an isomorphism, so is $\alpha^{-1}$.
\end{remark}
\begin{lemma}
    $\cong$ is an equivalence relation on the class of all vector spaces over $F$.
\end{lemma}
\begin{proof}
    Just check.
\end{proof}
\begin{theorem}
    If $V$ is a vector space over $F$ of dimension $n$, then $V\cong F^n$.
\end{theorem}
\begin{proof}
    Take a basis $\{b_1,\ldots,b_n\}$ of $V$, then
    $$\alpha(x_1b_1+\cdots+x_nb_n)=(x_1,\ldots,x_n)$$
    is an isomorphism.
\end{proof}
\begin{remark}
    Choosing a basis of $V$ is then just equivalent to choosing an isomorphism from $V$ to $F^n$.
\end{remark}
\begin{theorem}
    Let $V,W$ be finite dimensional vector spaces over $F$.
    Then $V\cong W$ iff $\dim V=\dim W$
\end{theorem}
\begin{proof}
    Any basis of $V$ induces a basis of $W$ via the isomorphism, so they have the same dimension.
    Therefore are both isomorphic to $F^n$ where $n=\dim V=\dim W$.
\end{proof}
\begin{definition}
    Let $\alpha:V\to W$ be a linear map.
    We define the kernel of $\alpha$ to be $\ker\alpha=\{v\in V:\alpha(v)=0\}$ and the image to be $\operatorname{Im}\alpha=\alpha(V)=\{w\in W:\exists v\in V,\alpha(v)=w\}$.
\end{definition}
\begin{lemma}
    $\ker\alpha\le V,\operatorname{Im}\alpha\le W$.
\end{lemma}
\begin{proof}
    Obvious.
\end{proof}
\begin{example}
    Take $\alpha:C^\infty(\mathbb R)\to C^\infty(\mathbb R)$ by $\alpha(f)(t)=f^{\prime\prime}(t)+f(t)$.
    Then $\ker\alpha$ is spanned by $t\mapsto e^t$ and $t\mapsto e^{-t}$ and $\operatorname{Im}\alpha=C^{\infty}(\mathbb R)$.
\end{example}
\begin{theorem}
    Let $V,W$ be vector spaces over $F$ and $\alpha:V\to W$ be linear, then $V/{\ker\alpha}\cong \operatorname{Im}(\alpha)$ via $v+\ker\alpha\mapsto \alpha(v)$.
\end{theorem}
\begin{proof}
    Just check.
\end{proof}
\begin{definition}
    The rank of $\alpha:V\to W$ is $r(\alpha)=\dim\operatorname{Im}\alpha$ and nullity is $n(\alpha)=\dim\ker\alpha$.
\end{definition}
Hence in the finite dimensional case, we can rewrite the preceding theorem to get
\begin{theorem}[Rank-Nullity Theorem]
    Let $\alpha:V\to W$ be linear where $V$ is finite dimensional.
    Then $\dim V=r(\alpha)+n(\alpha)$.
\end{theorem}
\begin{proof}
    Follows from the preceding theorem.
\end{proof}
\begin{corollary}[Classification of Isomorphism]
    Let $V,W$ be finite dimensional vector spaces with $\dim V=\dim W$ and $\alpha:V\to W$ be linear, then the followings are equivalent:\\
    1. $\alpha$ is injective.\\
    2. $\alpha$ is surjective.\\
    3. $\alpha$ is an isomorphism.
\end{corollary}
\begin{proof}
    Follows immediately by considering dimensions.
\end{proof}
\begin{example}
    Consider
    $$V=\left\{ \begin{pmatrix}
        x\\
        y\\
        z
    \end{pmatrix}\in\mathbb R^3:x+y+z=0\right\}$$
    We want to compute $\dim V$.
    Consider $\alpha:\mathbb R^3\to\mathbb R$ via $(x,y,z)^\top\mapsto x+y+z$, then $r(\alpha)=1$ and $n(\alpha)=V$, so $\dim V=3-1=2$.
    Geometrically, $V$ is just a plane with normal $(1,1,1)^\top$.
\end{example}


% !TEX root =../thesis-letomes.tex
\chapter{Using Hamiltonian Mechanics} \label{apx:using-hamilton-mechanics}

\section{Hamilton's Equations - A 5-step Process}
We will now look at the procedure for using Hamiltonian mechanics in practice (this section is borrowed from \cite{Saxe2015}). In the next chapter ``Numerical Methods'' we will then solve the equations of motion, in part to demonstrate the validity of Hamilton's equations of motion, and in part to analyze how various numerical techniques perform.
\begin{description}
\item[Step 0 \quad Lagrangian $L$] \ \vspace{0.3cm}
\begin{enumerate}[label=(\alph*)]
\item Define general coordinates $q_i$, $i=1,2 \dots n$, where $n$ is the degrees of freedom for the system.
\item Determine kinetic energy $T(\vec{q},\dot{\vec{q}}, t)$ = $\frac{1}{2}m v^2$.
\item Determine potential energy $V(\vec{q},\dot{\vec{q}}, t)$.
\item Lagrangian: \begin{align}
L = T - V.
\end{align}
\end{enumerate}
\item[Step 1 \quad Generalized momenta $p_i$] \ \vspace{0.3cm}
\begin{align}
p_i(\vec{q},\vec{\dot{q}}, t) = \dfrac{\partial L}{\partial \dot{q_i}},
\end{align}
for all $i = 1 \dots n$.
%
\item[Step 2 \quad Transform all the $\dot{q_i}$] \ \vspace{0.3cm} \\
Technically called a Legendre transform, this is the step that takes us from Lagrangian mechanics to Hamiltonian mechanics. We basically isolate the $\dot{q_i}$ in the $p_i$-equations from step 1, and eliminate all $\dot{q_i}$ in the equations in favor of $p_i$. Thus we go from independent variables $(\vec{q}, \vec{\dot{q}})$ to $(\vec{q}, \vec{p})$ by transforming:
\begin{align}
\dot{q_i} = \dot{q_i}(\vec{q}, \vec{p}, t).
\end{align}
%
\item[Step 3 \quad The Hamiltonian $H$] \ \vspace{0.3cm}
\begin{align}
H(\vec{q}, \vec{p}, t) = \sum\limits_{i=1}^n p_i \dot{q_i} - L,
\end{align}
for all $n=1\cdots n$, where it is understood that all the $q_i$ are substituted with expressions found in step 2.
%
\item[Step 4 \quad Hamilton's Equations of Motion]
\begin{align}
\begin{split}
\dot{q_i} &= +\dfrac{\partial H}{\partial p_i},
\\[0.2cm]
\dot{p_i} &= -\dfrac{\partial H}{\partial q_i},
\end{split}
\end{align}
\end{description}
for $i = 1 \dots n$, which gives us $2n$ 1st order coupled PDEs of $2n$ variables \\
$(q_1,q_2,\dots,q_n,p_1,p_2,\dots,p_n)$.

In general $T$ and $V$ can be time-dependent (and therefore $L$ and $H$ can too). However in many applications, including the our model problem, they are not time-dependent.

An important property of the Hamiltonian is that if it is not explicitly time dependent then it is conserved $\mathrm{d}H/\mathrm{d}t = 0$ along the $(\vec{p}(t),\vec{q(t)})$ flow \cite{Knudsen2002}.

\subsection{$H$ vs. $E$} \label{ch:HvsE}

An important characteristic of a closed physical system is it's energy $E$. By a clever choice of coordinate system, it is possible to have systems where Hamiltonian $H$ is conserved, but the total mechanical energy $E$ is not. In that sense in can be argued that the Hamiltonian is a more general concept than energy. It can be shown that $H = E$ if and only if the following three conditions are met: \cite[pp.~60--64]{Goldstein2002} \cite{ucsd-quadratic} \cite{unige-quadradic}

\begin{enumerate}
    \item Equations of constraints, $T$ and $V$ have no explicit time-dependency.
    \item $V$ is independent of $\vec{\dot{q}}$.
    \item T is a homogeneous quadratic in the $\dot{q}$s, in particular if $T(\vec{q},\vec{\dot{q}}) = \frac{1}{2} \vec{\dot{q}}^\top M(q)\vec{\dot{q}}$, where $M(q)$ is some symmetric and positive definite matrix.
\end{enumerate}
Meeting these conditions also implies that the generalized impulses $p_i$ will be equal to well known conserved quantities such as linear momentum, angular momentum etc. We will later see that the equations for restricted three-body system satisfy the conditions. Another way to see if $T$ is a quadratic form is if its a homogeneous polynomial, i.e. all terms have same degree in a number of variables. For example $P(x,y) = 4x^2 + 2 x y + 3y^2$ \cite{wiki-quadratic} is quadratic.


\section{Complex Integration}
\subsection{Definition}
We want to generalize the notion of the real Riemann integration to the integration to complex valued functions on the complex plane.
\begin{definition}
    If $f:[a,b]\to\mathbb C$ is continuous, then we define the integral of $f$ to be
    $$\int_a^b f(x)\,\mathrm dx :=\int_a^b\operatorname{Re}f(x)\,\mathrm dx+i\int_a^b\operatorname{Im}f(x)\,\mathrm dx$$
\end{definition}
Easy to check that both integrals are well-defined and the integral is linear.
\begin{proposition}
    $$\left|\int_a^bf(t)\,\mathrm dt\right|\le (b-a)\sup_{t\in [a,b]}|f(t)|$$
\end{proposition}
\begin{proof}
    If the integral is zero then there is nothing to prove.
    Otherwise we can write it in the form $re^{i\theta}$ for some $r\in\mathbb R_{>0},\theta\in\mathbb R$, so
    \begin{align*}
        \left|\int_a^bf(t)\,\mathrm dt\right|=r&=\int_a^be^{-i\theta}f(t)\,\mathrm dt\\
        &=\int_a^b\operatorname{Re}(e^{-i\theta}f(t))\,\mathrm dt\\
        &\le \int_a^b|\operatorname{Re}(e^{-i\theta}f(t))|\,\mathrm dt\\
        &\le \int_a^b|f(t)|\,\mathrm dt\\
        &\le (b-a)\sup_{t\in [a,b]}|f(t)|
    \end{align*}
    As desired.
\end{proof}
Note that the equality holds iff $f$ is constant.
\begin{definition}
    Let $\gamma:[a,b]\to\mathbb C$ be a $C^1$ curve, then the length of $\gamma$ is
    $$\int_a^b|\gamma^\prime(t)|\,\mathrm dt$$
    Also this curve is called simple iff $\gamma(t_1)=\gamma(t_2)\iff t_1\equiv t_2\pmod{b-a}$
\end{definition}
\begin{definition}
    Let $\gamma:[a,b]\to\mathbb C$ be a $C^1$ curve and $f:U\to\mathbb C$ be continuous, then we define the integral of $f$ over $\gamma$ by
    $$\int_\gamma f(t)\,\mathrm dt=\int_a^b(f\circ\gamma)(t)\gamma^\prime(t)\,\mathrm dt$$
\end{definition}
One can check that
\begin{proposition}
    1.
    $$\left(\int_{\gamma}f\right)+\alpha\left(\int_\gamma g\right)=\int_\gamma(f+\alpha g)$$
    2.
    $$\int_{\gamma\pm\delta}=\int_\gamma\pm\int_\delta$$
    3. Let $\gamma,\delta$ be two parameterizations of the same curve linked by an injective $C^1$ function, then
    $$\int_\gamma=\int_\delta$$
\end{proposition}
Where the addition and substraction of paths are defined the way a sensible person would expect.
\begin{proof}
    Trivial.
\end{proof}
\begin{definition}
    For continuous piecewise $C^1$ curves $\gamma=\gamma_1+\gamma_2+\cdots+\gamma_n$, we set
    $$\int_\gamma=\sum_{k=1}^n\int_{\gamma_k}$$
\end{definition}
Note that by additivity of the integral over paths, this is well-defined.
\begin{proposition}
    For any continuous function $f:U\to\mathbb c$ and any (piecewise $C^1$) curve $\gamma:[a,b]\to U$, we have
    $$\left|\int_\gamma f(z)\,\mathrm dz\right|\le\sup_{t\in[a,b]}|f(\gamma(t))|\int_a^b|\gamma^\prime(t)|\,\mathrm dt$$
\end{proposition}
\begin{proof}
    Suffices to show the case when $\gamma$ is $C^1$, then
    \begin{align*}
        \left|\int_\gamma f(z)\,\mathrm dz\right|&=\left|\int_a^bf(\gamma(t))\gamma^\prime(t)\,\mathrm dt\right|\\
        &\le\int_a^b|f(\gamma(t))||\gamma^\prime(t)|\,\mathrm dt\\
        &\le\sup_{t\in[a,b]}|f(\gamma(t))|\int_a^b|\gamma^\prime(t)|\,\mathrm dt
    \end{align*}
    As desired.
\end{proof}
\subsection{Cauchy's Theorem}
\begin{theorem}[Fundamental Theorem of Calculus for Complex Integrals]
    For a continuous function $f:U\to\mathbb C$, if there is a holomorphic $F:U\to\mathbb C$ such that $F^\prime=f$, then for any (piecewise $C^1$) curve $\gamma:[a,b]\to\mathbb C$ we have
    $$\int_\gamma f(z)\,\mathrm dz=F(\gamma(b))-F(\gamma(a))$$
\end{theorem}
In particular we have
$$\oint_\gamma f(z)\,\mathrm dz=0$$
For closed $\gamma$.
\begin{proof}
    Again suffices to consider $\gamma$ as $C^1$, then we have
    $$\int_\gamma f(z)\,\mathrm dz=\int_a^bF^\prime(\gamma(t))\gamma^\prime(t)\,\mathrm dt=\int_a^b(F\circ\gamma)^\prime(t)\,\mathrm dt=F(\gamma(b))-F(\gamma(a))$$
    Done.
\end{proof}
\begin{example}
    For $\gamma:[0,\pi]\to\mathbb C$ by $t\mapsto Re^{2it}$, we have for $n\neq -1$
    $$\oint_\gamma z^n\,\mathrm dz=0$$
    Indeed it is the derivative of the holomorphic function $z^{n+1}/(n+1)$.\\
    But for $n=-1$,
    $$\oint_\gamma z^{-1}\,\mathrm dz=2\pi R$$
    which is nonzero, hence it does not have an antiderivative defined on any open set containing $\gamma$, so logarithm has no branch on $\mathbb C^\star$.
\end{example}
What is interesting is the converse of the theorem.
\begin{theorem}
    Let $U$ be a path-connected open set, and $f:U\to\mathbb C$ be continuous.
    If for any (piecewise $C^1$) closed curve $\gamma:[a,b]\to U$ we have
    $$\oint_\gamma f(z)\,\mathrm dz$$
    then $f$ has an antiderivative on $U$.
\end{theorem}
\begin{proof}
    Fix $\alpha\in U$.
    Consider the function $F:U\to\mathbb C$ with
    $$F(z)=\int_\gamma f(z)\,\mathrm dz$$
    where $\gamma$ is a piecewise $C^1$ curve on $U$ connecting $\alpha$ and $z$.
    To see the existence of $\gamma$, we know by path-connectedness of $U$ that there is a continuous curve from $\alpha$ to $z$, then we can construct a piecewise $C^1$ one by a compactness argument.\\
    Then such an $F$ is well defined by our condition.
    One can simply check to see that $F$ is holomorphic and $F^\prime=f$.
\end{proof}
\begin{definition}
    A domain $U$ is star-shaped if $\exists s\in U$ such that any other $x\in U$, there is a straight line joining $x$ and $s$.
\end{definition}
\begin{definition}
    A triangle $T$ is the convex hull of three non-colinear points on the complex plane, so
    $$T(z_1,z_2,z_3)=\{az_1+bz_2+cz_3:a,b,c\in [0,1],a+b+c=1\}$$
    We denote by $\partial T$ the boundary of $T$, which is the union of three line segments, and we choose it to be with anticlockwise direction.
\end{definition}
\begin{corollary}
    In any star-shaped domain, if for any triangle $T$ in the domain we have
    $$\oint_{\partial T}f(z)\,\mathrm dz=0$$
    then $f$ admits a holomorphic antiderivative.
\end{corollary}
\begin{proof}
    Basically the same proof but take $\alpha=s$ and take the path to be a straight line.
\end{proof}
\begin{theorem}[Cauchy's Theorem]
    For a holomorphic $f$ and closed $\gamma$,
    $$\oint_\gamma f(z)\,\mathrm dz=0$$
\end{theorem}
\begin{theorem}[Cauchy's Theorem for Triangles]
    Let $U\subset C$ be open and $f:U\to\mathbb C$ holomorphic.
    If $T$ is a triangle in $U$, then
    $$\oint_{\partial T}f(z)\,\mathrm dz=0$$
\end{theorem}
\begin{proof}
    We subdivide the triangles by joining the midpoints, so we disassembles $T$ into $4$ smaller triangles.
    Call them $T^1,T^2,T^3,T^4$, and the directions of their boundaries are consistently given (anticlockwise), so we have
    $$\oint_{\partial T}f(z)\,\mathrm dz=\sum_{k=1}^4\oint_{\partial T^k}f(z)\,\mathrm dz$$
    We set
    $$\eta(T)=\oint_{\partial T}f(z)\,\mathrm dz$$
    So $\eta(T)=\sum_{k}\eta(T^k)$, hence there is some $k$ such that $|\eta(T^k)|\ge|\eta(T)|/4$, and $\operatorname{length}(\partial T^k)=\operatorname{length}(\partial T)/2$, so we repeat this process to get a nested sequence of triangles $T=T_0\supset T_1\supset T_2\supset\cdots$ such that $|\eta(T_k)|/4\le|\eta(T_{k+1})|$ and $\operatorname{length}(\partial T_{k+1})=\operatorname{length}(\partial T_k)/2$.
    But each $T_k$ is closed and the diameter goes to $0$, hence $\bigcap_kT_k=\{z_0\}$ for some $z_0\in\mathbb C$.
    For any $\epsilon>0$, there is some $\delta>0$ such that $|z-z_0|<\delta\implies |f(z)-f(z_0)-f^\prime(z_0)(z-z_0)|<\epsilon|z-z_0|$
    For $n$ large enough, we have $T_n\subset D_\delta(z_0)$.
    \begin{align*}
        |\eta(T_n)|&=\left|\oint_{\partial T_n}f(z)-(f(z_0)+f^\prime(z_0)(z-z_0))\,\mathrm dz\right|\\
        &\le\sup_{z\in \delta T_n}|f(z)-(f(z)+f^\prime(z_0)(z-z_0)|\operatorname{length}(\partial T_n)\\
        &\le\epsilon\sup_{z\in\partial T_n}|z-z_0|\operatorname{length}(\partial T_n)\\
        &\le\epsilon(\operatorname{length}(\partial T_n))^2
    \end{align*}
    So
    $$\frac{\eta(T)}{4^n}\le\epsilon(\operatorname{length}(\partial T^n))^2=\frac{\epsilon(\operatorname{length}(\partial T))^2}{4^n}\implies\forall\epsilon>0,\eta(T)\le \epsilon(\operatorname{length}(\partial T))^2$$
    Hence we must have $\eta(T)=0$.
\end{proof}
\begin{theorem}
    Let $f:U\to\mathbb C$ be continuous.
    If $S\subset U$ is a finite set and if $f$ is holomorphic in $U\setminus S$, then
    $$\oint_{\partial T}f(z)\,\mathrm dz=0$$
    for any triangle $T\subset U$.
\end{theorem}
\begin{proof}
    Subdivide $T$ into $N=4^n$ parts as before to $T_1,T_2,\ldots,T_N$, then $|I|\le 6|S|$ where $I=\{j:T_j\cap S\neq\varnothing\}$.
    Hence we have, by Cauchy's Theorem on triangles,
    \begin{align*}
        \left|\oint_{\partial T}f(z)\,\mathrm dz\right|&=\left|\sum_{j\in I}\oint_{\partial T_j}f(z)\,\mathrm dz\right|\\
        &\le\sum_{j\in I}\sup_{z\in\partial T_j}|f(z)|\operatorname{length}(\partial T_j)\\
        &\le 6|S|\sup_{z\in\partial T}|f(z)|\operatorname{length}(\partial T)\frac{1}{2^n}
    \end{align*}
    Letting $n\to\infty$ finishes the proof.
\end{proof}
\begin{corollary}[Cauchy's Theorem on Star-Shaped Domains]
    Let $U\subset C$ be a star-shaped domain and $f:U\to\mathbb C$ be continuous, and holomorphic on $U\setminus S$ where $S$ is a finite set.
    Then
    $$\oint_\gamma f(z)\,\mathrm dz=0$$
    for any closed curve on $U$.
\end{corollary}
\begin{proof}
    Follows directly.
\end{proof}
\subsection{Cauchy Integral Formula and Consequences}
\begin{theorem}[Cauchy's Integral Formula for a disk]
    Let $D=D_r(a)$, and let $f:D\to\mathbb C$ be holomorphic, then for any $0<\rho<r$ and any $w\in D_\rho(a)$, we have
    $$f(w)=\frac{1}{2\pi i}\oint_{\partial D_\rho(a)}\frac{f(z)}{z-w}\,\mathrm dz$$
    where $\partial D_\rho(a)$ denotes the curve $[0,1]\ni t\mapsto a+\rho e^{2\pi it}$
\end{theorem}
In particular,
$$f(a)=\int_0^1 f(a+\rho e^{2\pi it})\,\mathrm dt$$
This is known as the mean-value property.
\begin{proof}
    We have
    $$\oint_{\partial D_\rho(a)}\frac{f(z)-f(w)}{z-w}\,\mathrm dz=0$$
    by the preceding theorem.
    So we have
    \begin{align*}
        \oint_{\partial D_\rho(a)}\frac{f(z)}{z-w}\,\mathrm dz&=f(w)\oint_{\partial D_\rho(a)}\frac{1}{z-w}\,\mathrm dz\\
        &=f(w)\oint_{\partial D_\rho(a)}\frac{1}{z-a}\,\mathrm dz+f(w)\oint_{\partial D_\rho(a)}\sum_{n=1}^\infty\frac{(w-a)^n}{(z-a)^{n+1}}\,\mathrm dz\\
        &=f(w)2\pi i+f(w)\sum_{n=1}^\infty(w-a)^n\oint_{\partial D_\rho(a)}\frac{1}{(z-a)^{n+1}}\,\mathrm dz\\
        &=f(w)2\pi i
    \end{align*}
    Note that we can change the order of integration and summation since the series (as a geometric series) converges uniformly (which is easy enough to prove).
\end{proof}
So we can prove that a bounded entire function is constant.
\begin{proof}[Proof of Theorem \ref{holo_bdd_const}]
    Let $f$ be a bounded entire function.
    It suffice to assume that $f$ has sublinear growth since it is bounded.
    So $|f(z)|\le C(1+|z|^\alpha)$ for some $C\ge 0$ and $\alpha\in (0,1)$.
    Let $w\in\mathbb C$, by Cauchy integral formula, for any $\rho>|w|$ we have
    $$f(w)=\frac{1}{2\pi i}\oint_{D_\rho(0)}\frac{f(z)}{z-w}\,\mathrm dz$$
    Also
    $$f(0)=\frac{1}{2\pi i}\oint_{D_\rho(0)}\frac{f(z)}{z}\,\mathrm dz$$
    Hence
    \begin{align*}
        |f(w)-f(0)|&=\left|\frac{1}{2\pi i}\oint_{D_\rho(0)}f(z)\left(\frac{1}{z-w}-\frac{1}{z}\right)\,\mathrm dz\right|\\
        &=\frac{|w|}{2\pi}\left|\oint_{D_\rho(0)}\frac{f(z)}{z(z-w)}\,\mathrm dz\right|\\
        &\le|w|\rho\sup_{z\in D_\rho(0)}\frac{|f(z)|}{|z||z-w|}\\
        &=\sup_{z\in D_\rho(0)}\frac{|w||f(z)|}{|z-w|}\\
        &\le\sup_{z\in D_\rho(0)}\frac{|w|C(1+\rho^\alpha)}{|z-w|}\to 0
    \end{align*}
    As $\rho\to\infty$.
    Hence $f(w)=f(0)$.
\end{proof}
\begin{corollary}
    Every nonconstant polynomial with complex coefficient has a root in $\mathbb C$.
\end{corollary}
\begin{proof}
    Assume there is a complex polynomial $p(z)=a_nz^n+\cdots+a_0$ with $n\ge1,a_n\neq 0$ which has no root, then $p$ is never $0$, hence $1/p$ is entire.
    So it suffices to show that $p$ is bounded.
    Note that for $z\neq 0$ we have $|p(z)|=|z^n||a_n+a_{n-1}z^{-1}+\cdots+a_0z^{-n}|\to\infty$ as $|z|\to\infty$.
    Hence we can choose $R>0$ such that $p(z)\ge 1$ for any $|z|>R$, so $p$ is bounded outside the disk $B_R(0)$, but it is also bounded inside it since $B_R(0)$ is compact.
    So by Theorem \ref{holo_bdd_const}, $p$ must be a constant, contradiction.
\end{proof}
\begin{theorem}[Local Maximum Modulus Principle]
    Let $f:D_r(a)\to\mathbb C$ be holomorphic.
    If $|f(z)|\le|f(a)|$ for any $z\in D_r(a)$, then $f$ is constant.
\end{theorem}
\begin{proof}
    We shall use the mean-value property.
    $$f(a)=\int_0^1 f(a+\rho e^{2\pi it})\,\mathrm dt$$
    for any $0<\rho<r$.
    So
    $$|f(a)|=\left|\int_0^1 f(a+\rho e^{2\pi it})\,\mathrm dt\right|\le\sup_{t\in [0,1]}|f(a+\rho e^{2\pi it})|\le|f(a)|$$
    So automatically all inequality must be equality, therefore $|f(a+\rho e^{2\pi it})|$ must be constant.
    But this works for all $\rho\in (0,r)$, so $|f|$ is constant, which implies $f$ being constant by Cauchy-Riemann equation.
\end{proof}
\begin{theorem}[Taylor Series]
    Let $f:D_r(a)\to\mathbb C$ be holomorphic.
    Then $f$ has a convergent power series representation on $D_a(r)$ in the form
    $$f(w)=\sum_{n=0}^\infty c_n(w-a)^n,c_n=\frac{1}{2\pi i}\oint_{\partial D_\rho(a)}\frac{f(z)}{(z-a)^{n+1}}\,\mathrm dz$$
    for $|w|<\rho<r$.
\end{theorem}
Once we have established this, we immediately know that $f$ is infinitely differentiable on $D_a(r)$, therefore $c_n=f^{(n)}(a)/n!$.
\begin{proof}
    For any $w\in D_r(a)$ and any $\rho$ with $|w-a|<\rho<r$ we have
    \begin{align*}
        f(w)&=\frac{1}{2\pi i}\oint_{\partial D_\rho(a)}\frac{f(z)}{z-w}\,\mathrm dz\\
        &=\frac{f(z)}{2\pi i}\oint_{\partial D_\rho(a)}\sum_{n=0}^\infty\frac{(w-a)^n}{(z-a)^{n+1}}\,\mathrm dz\\
        &=\sum_{n=0}^\infty(w-a)^n\frac{1}{2\pi i}\oint_{\partial D_\rho(a)}\frac{f(z)}{(z-a)^{n+1}}\,\mathrm dz
    \end{align*}
    We can change the order of integration since a geometrical series is uniform.
    This gives us the desired series.
\end{proof}
\begin{corollary}
    If $f:U\to\mathbb C$ is holomorphic where $U$ is open, then $f$ has derivative of all orders and they are all holomorphic.
\end{corollary}
\begin{proof}
    Follows directly.
\end{proof}
A function, real or complex, is said to be analytic on an open set if it has a convergent power series representation there.
So for a complex function, being analytic is equivalent to being holomorphic.
But for real functions, even infinite differentiability does not imply a function is analytic, for example
$$f(x)=\begin{cases}
    e^{-1/x^2}\text{, for $x\neq 0$.}\\
    0\text{, for $x=0$.}
\end{cases}$$
From now on, we can use analytic and holomorphic interchangably.
We can also say now that if we decompose $f=u+iv$, then $u,v$ are automatically smooth given $f$ holomorphic.
\begin{theorem}[Morera's Theorem]
    Let a complex function $f:U\to\mathbb C$ be continuous.
    Suppose that its integral is $0$ along any closed curve, then $f$ is holomorphic.
\end{theorem}
\begin{proof}
    The antiderivative exists and is holomorphic, so its derivative $f$ is holomorphic.
\end{proof}
\begin{theorem}[Cauchy's Integral Formula for Derivatives]
    For a holomorphic function $f:D=D_r(a)\to\mathbb C$ and for any $w\in D$ and $|w|<\rho<r$, we have
    $$f^\prime(w)=\frac{1}{2\pi i}\oint_{\partial D_\rho(a)}\frac{f(z)}{(z-w)^2}\,\mathrm dz$$
    More generally,
    $$f^{(n)}(w)=\frac{n!}{2\pi i}\oint_{\partial D_\rho(a)}\frac{f(z)}{(z-w)^{n+1}}\,\mathrm dz$$
\end{theorem}
\begin{proof}
    Consider the function $g(z)=f(z)/(z-w)$ and its derivative gives the $n=1$ case.
    The general case follows from induction.
\end{proof}
\begin{definition}
    Let $U\subset\mathbb C$ be an open set and let $(f_n)$ be a sequence of complex functions.
    We say it converges locally uniformly if for any $a\in U$, there is some $r>0$ such that $(f_n)$ converges uniformly on $D_r(a)\subset U$.
\end{definition}
\begin{proposition}
    $(f_n)$ converges locally uniformly on $U$ iff it converges uniformly on any compact subset of $U$.
\end{proposition}
\begin{proof}
    Easy.
\end{proof}
\begin{theorem}
    Let $f_n:U\to\mathbb C$ be a sequence of holomorphic functions that converges to $f$ locally uniformly on $U$, then $f$ is holomorphic.
    Moreover, $f_n^\prime\to f^\prime$ locally uniformly on $U$.
\end{theorem}
\begin{remark}
    This is totally not true in the real case since we can approximate any continuous function on a closed interval locally uniformly by polynomials (Weierstrass Approximation Theorem).
\end{remark}
\begin{proof}
    $f$ is continuous since continuity is a local property and we already know that the uniform limit of continuous functions is continuous.
    Pick any point $a\in U,r>0$ with $B_r(a)\subset U$ and $f_n\to f$ uniformly on $B_r(a)$, the by Cauchy's Theorem on star-shaped domains, we have
    $$\oint_\gamma f_n(z)\,\mathrm dz=0$$
    for any closed $\gamma$ on the disk.
    Then by uniformity
    $$\oint_\gamma f(z)\,\mathrm dz=\oint_\gamma\lim_{n\to\infty}f_n(z)\,\mathrm dz=\lim_{n\to\infty}\oint_\gamma f_n(z)\,\mathrm dz$$
    So $f$ is holomorphic on the disk.
    The derivative case follows from Cauchy Integral Formula for derivatives.
\end{proof}
\begin{theorem}[Principle of Isolated Zero]
    Let $f:D_R(w)\to\mathbb C$ be holomorphic and not identically zero, then the zeros of $f$ are isolated, that is, there exists $0<r\le R$ such that $f(z)\neq 0$ for any $0<|z-w|<r$.
\end{theorem}
\begin{proof}
    Trivial.
\end{proof}
\begin{remark}
    The zeros of a holomorphic function can have a limit point on the boundary of the domain.
    For example, $f(z)=\sin(1/z)$ on $\mathbb C^\star$.
\end{remark}
\subsection{Analytic Continuation}
By Taylor Series, we know that a holomorphic function $f$ on a disk $D_R(a)$ is completely determined by the values of the derivatives of $f$ at $a$.
Does this generalize to arbitrary domains?
\begin{theorem}
    Let $D'\subset D$ be domains and $f:D'\to\mathbb C$ be analytic.
    Then there is at most one analytic function $g:D\to\mathbb C$ such that $g|_{D'}=f$.
\end{theorem}
Such a function $g$ is called an analytic continuation of $f$ to $D$.
\begin{proof}
    Suppose there are two of the functions $g_1,g_2$ satisfying this condition, then $g_1|_{D'}=g_2|_{D'}=f$ and $h=g_1-g_2$.
    Let $D_0=\{z\in D:\exists r>0, h|_{D_r(z)}\equiv 0\}$.
    Then $D_0$ is open.
    We shall show that it is also closed, which shall finish our proof.
    But $D_1=\{z\in D:\exists n\in\mathbb N, h^{(n)}(z)\neq 0\}=D\setminus D_0$ is also open in $D$, so one of them is empty by connectedness.
    But $D'\subset D_1$ hence $D_1$ is empty, therefore $h\equiv 0\implies g_1=g_2$.
\end{proof}
Actually this is a direct consequence of the Principle of Isolated Zeros, but one want to show that this depends entirely on the existence of Taylor series.
\begin{remark}
    1. The proof depends on the result that the functions have convergent Taylor series at every point, so it is valid for real valued analytic functions.\\
    2. Analytic continuations to larger domains need not always exist.
    For example, the function
    $$f(z)=\sum_{n=0}^\infty z^{n!}$$
    is analytic on $D_1(0)$, but we will prove in example sheet that this cannot be extend to larger domains.
    $\partial D_1(0)$ is called the natural boundary of $f$.
\end{remark}
\begin{corollary}[Identity Principle]
    Let $U\subset \mathbb C$ be a domain and let $f,g:U\to\mathbb C$ be holomorphic and the set $\{z\in U:f(z)=g(z)\}$ has a non-isolated point, then $f\equiv g$.
\end{corollary}
\begin{proof}
    Immediate.
\end{proof}
\begin{corollary}[Global Maximum Principle]
    Let $U\subset\mathbb C$ be a bounded domain and let $f:\bar{U}\to\mathbb C$ be continuous and holomorphic in $U$, then $\sup|f|$ is attained on the boundary $\partial U=\bar U\setminus U^\circ$.
\end{corollary}
\begin{proof}
    Follows from the Local Maximum Principle and Identity Principle.
\end{proof}
\begin{remark}
    Some of the theorems can generalize even further to help us to solve elliptic PDEs as a generlization to Laplace's Equation.
    For example, we also have an analogue of analytic continuation and we can show that harmonic functions in any dimensions are infinitely differentiable.
    Also some analogue of the Local Maximum Modulus Principle also hold.
    So does the mean value property (but this time only for harmonic functions instead of general functions satisfying elliptic PDEs).
    In fact, if the mean value property hold, the function has to be harmonic.
\end{remark}