\toclesssection{Hashing}

\toclesssubsection{Recapitulation}

\begin{frame}{Hashing}{Recapitulation}
  \onslide<1->
  \textbf{Hashing:}
  \begin{itemize}
  \item<2->
    No hash function is good for all key sets!\\
    \begin{itemize}
    \item<3->
      This cannot work, because a big universe
      is mapped onto a small set: {\color{MainA}$\vert \mathbb{U} \vert > m$}
    \end{itemize}
  \item<4->
    For random key sets also simple hash functions work, e.g.
     {\color{MainA}\[\Rightarrow h(x) = x \mod m\]}\vspace*{-2em}
     \begin{itemize}
    \item<5->
      Then the random keys make sure that it is distributed evenly
     \end{itemize}
  \item<6->
   To find a good hash function for every key set, universal hashing is needed
     \begin{itemize}
    \item<7->
      Then however, for a fixed set of keys not every hash function is suitable,
      but only some
    \end{itemize}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Recapitulation}
  \textbf{Rehashing:}
  \begin{itemize}
    \item<2->
      It is possible to get bad hash functions with universal hashing, but it
      is unlikely
    \item<3->
      This is determinable by monitoring the maximum bucket size

    \item<4-> If a pre-defined level is exceeded, then a {\color{MainA}rehash} is performed
  \end{itemize}
  \onslide<5->
  \textbf{How to rehash?}
  \begin{itemize}
    \item<5->
      New hash table with a new random hash function
    \item<6->
      Copy elements into the new table
      \begin{itemize}
        \item<7->
          Expensive but does not happen often
        \item<8->
          Therefore the average cost is low
        \item<9->
          Look at {\color{MainA}amortized analysis} in the next lecture
      \end{itemize}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\subsection{Treatment of hash collisions}

\begin{frame}{Hashing}{Linked List}
  \textbf{Buckets as linked list:}
  \begin{itemize}
    \item<2->
      Each bucket is a linked list
    \item<3->
      Colliding keys are inserted into the linked list of a bucket, either sorted or appended at the end
  \onslide<4->
%  \vspace*{-1.0em}
\includegraphics[height=0.35\textheight]{Images/hashtable-buckets.pdf}
  % \begin{table}[!b]
  %   \label{tab:hashing:linked_list:hash_table}
  %   \begin{tabularx}{0.875\textwidth}{c|l}
  %     Bucket & Value\\
  %     \midrule
  %     0 & \lstinline[
  %       language=Python,
  %       style={python-idle-code},
  %       basicstyle=\small
  %     ]|None|\\
  %     1 &
  %     \lstinline[
  %       language=Python,
  %       style={python-idle-code},
  %       mathescape=true,
  %       basicstyle=\small
  %     ]|(3126, "B") $\rightarrow$ (4561, "D") $\rightarrow$ None|\\
  %     2 &
  %     \lstinline[
  %       language=Python,
  %       style={python-idle-code},
  %       mathescape=true,
  %       basicstyle=\small
  %     ]|(5147, "C") $\rightarrow$ None|\\
  %     3 &
  %     \lstinline[
  %       language=Python,
  %       style={python-idle-code},
  %       mathescape=true,
  %       basicstyle=\small
  %     ]|(3903, "A") $\rightarrow$ (1683, "D")
  %       $\rightarrow$ (4818, "E")
  %       $\rightarrow$ None|\\
  %     4 & \lstinline[
  %       language=Python,
  %       style={python-idle-code},
  %       basicstyle=\small
  %     ]|None|\\
  %   \end{tabularx}
  % \end{table}
   \item<5->
     Operations in {\color{MainA}$O(1)$} are possible if a suitable table size and hash function is
     selected
   \item<6->
     Worst case {\color{MainA}$O(n)$}, e.g. table size of 1
   \item<7->
     Dynamic number of elements is possible
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\subsection{Open Addressing}

\begin{frame}{Hashing}{Open Addressing}
  \begin{itemize}
    \item<1->
      For colliding keys we choose a new free entry
    \item<2->
      Static, fixed number of elements
    \item<3->
      The \textbf{probe sequence} determines for each key, in which sequence
      all hash table entries are searched for a free bucket
      \begin{itemize}
      \item<4->
        If an entry is already occupied, then iteratively the
        {\color{MainA}following entry} is checked.
        If a free entry is found the element is inserted
      \item<5->
        If element is not found at the corresponding table entry, even if
        the entry is occupied, then probing has to be performed until
        the element or a free entry has been found
    \end{itemize}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing}
  \textbf{Definitions:}
  \begin{itemize}
    \item<2->[\color{MainA}$h(s)$]
      Hash function for key {\color{MainA}$s$}
    \item<3->[\color{MainA}$g(s,j)$]
      Probing function for key {\color{MainA}$s$}
      with overflow positions {\color{MainA}$j \in \{0,\dots,m-1\}$}
      e.g. {\color{MainA}g(s,j)=j}
    \item<4->
      The \textbf{probe sequence } is calculated by
      \begin{displaymath}
        {\color{MainA}h(s,j)}
        = ({\color{MainA}h(s)} - {\color{MainA}g(s,j)})
        \mod m \in \{0,\dots,m-1\}
      \end{displaymath}
  \end{itemize}
  \vspace{-1em}
  \begin{center}
    \begin{adjustbox}{width=0.75\linewidth}%
      \onslide<4->\input{Images/OpenAddressing/LinearProbing-definition.tikz}%
    \end{adjustbox}
  \end{center}
\end{frame}

%-------------------------------------------------------------------------------

\codeslide{python}{
\begin{frame}{Hashing}{Open Addressing - Python}
  \lstinputlisting[
    language=Python,
    basicstyle=\small,
    tabsize=4,
    style={python-idle-code},
    breaklines=false,
    emph={insert, None, h, g},
    emphstyle=\color{blue}
  ]{Code/OpenHashing_Insert.py}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Python}
  \lstinputlisting[
    language=Python,
    basicstyle=\small,
    tabsize=4,
    style={python-idle-code},
    breaklines=false,
    emph={lookup, None, h, g},
    emphstyle=\color{blue}
  ]{Code/OpenHashing_Lookup.py}
\end{frame}
}

%-------------------------------------------------------------------------------

\codeslide{java}{
\begin{frame}{Hashing}{Open Addressing - Java}
  \lstinputlisting[
    language=Java,
    basicstyle=\scriptesize,
    tabsize=4,
    style={java-eclipse-code},
    breaklines=false,
    mathescape=true,
    escapechar={@},
    emph={j},
    emphstyle=\color{java_variable}
  ]{Code/OpenHashing_Insert.java}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Java}
  \lstinputlisting[
    language=Java,
    basicstyle=\scriptesize,
    tabsize=4,
    style={java-eclipse-code},
    breaklines=false,
    mathescape=true,
    escapechar={@},
    emph={j},
    emphstyle=\color{java_variable}
  ]{Code/OpenHashing_Lookup.java}
\end{frame}
}

%-------------------------------------------------------------------------------

\codeslide{cpp}{
\begin{frame}{Hashing}{Open Addressing - C++}
  \lstinputlisting[
    language=C++,
    basicstyle=\small,
    tabsize=2,
    style={cpp-eclipse-code},
    breaklines=false,
    escapechar={@}
  ]{Code/OpenHashing_Insert.cpp}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - C++}
  \lstinputlisting[
    language=C++,
    basicstyle=\small,
    tabsize=2,
    style={cpp-eclipse-code},
    breaklines=false,
    morekeywords={nullptr},
    escapechar={@}
  ]{Code/OpenHashing_Lookup.cpp}
\end{frame}
}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Linear Probing}
  \begin{figure}[!h]
    \begin{adjustbox}{width=0.75\linewidth}%
      \input{Images/OpenAddressing/LinearProbing.tikz}%
    \end{adjustbox}
    \vspace{-1.0em}
    \caption{Linear probe sequence}%
    \label{fig:hashing:open_addressing:linear_probing}%
  \end{figure}
  \vspace{-1.0em}
  \begin{itemize}
    \item<2->
      Check the element with lower index:
      \begin{math}
        {\color{MainA}g(s,j)} := {\color{MainA}j}
      \end{math}\\
      $\Rightarrow$ Hash function:
      \begin{math}
        {\color{MainA}h(s,j)}
        = ({\color{MainA}h(s)} - {\color{MainA}j}) \mod m
      \end{math}
    \item<3->
      This leads to the following probe sequence
      \begin{displaymath}
        {\color{MainA}h(s)},
        {\color{MainA}h(s)}-1,
        {\color{MainA}h(s)}-2,
        \dots,
        \underbrace{0, m-1}_\text{clipping},
        m-2,
        \dots,
        {\color{MainA}h(s)}+1
      \end{displaymath}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Linear Probing}
  \begin{figure}[!h]
    \begin{adjustbox}{width=0.75\linewidth}%
      \input{Images/OpenAddressing/LinearProbing.tikz}%
    \end{adjustbox}
    \vspace{-0.5em}
    \caption{Linear probe sequence}%
    \label{fig:hashing:open_addressing:linear_probing2}%
  \end{figure}
  \vspace{-1.5em}
  \begin{itemize}
    \item<2->
      Can result in primary clustering
    \item<3->
      Dealing with a hash collision will result in a higher probability of hash
      collisions in close entries
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Linear Probing}
  \textbf{Example:}
  \begin{itemize}
    \item<2->
      Keys:
        \begin{math}
          {\color{MainA}
         \{12, 53, 5, 15, 2, 19\}}
      \end{math}
    \item<3->
      Hash function:
      \begin{math}
        {\color{MainA}h(s,j)
        = (s \mod 7 - j) \mod 7}
      \end{math}
  \end{itemize}
  \hfill\\[0.5em]
   \begin{itemize}
    \item<4->
      \lstinline[
        language=Python,
        style={python-idle-code},
        mathescape=true,
        basicstyle=\small
      ]|t.insert(12, "A")|$,\;$
      \begin{math}
        {\color{MainA}h(12, 0)} = 5
      \end{math}
      \begin{figure}[!h]
        \def\LPEData{
          \relax/0,
          \relax/1,
          \relax/2,
          \relax/3,
          \relax/4,
          {12, {\color{green2}A}}/5,
          \relax/6
        }%
        \def\LPEShowIndex{1}%
        \begin{adjustbox}{width=0.75\linewidth}%
          \input{Images/OpenAddressing/LinearProbingExample.tikz}%
        \end{adjustbox}
        \vspace{-0.5em}%
%        \caption{Probe sequence}%
        \label{fig:hashing:open_addressing:linear_probing_example}%
      \end{figure}
      \hfill\\[1.0em]
    \item<5->
      \lstinline[
        language=Python,
        style={python-idle-code},
        mathescape=true,
        basicstyle=\small
      ]|t.insert(53, "B")|$,\;$
      \begin{math}
        {\color{MainA}h(53, 0)} = 4
      \end{math}
      \begin{figure}[!h]
        \def\LPEData{
          \relax/0,
          \relax/1,
          \relax/2,
          \relax/3,
          {53, {\color{green2}B}}/4,
          {12, {\color{green2}A}}/5,
          \relax/6
        }%
        \def\LPEShowIndex{0}%
        \begin{adjustbox}{width=0.75\linewidth}%
          \input{Images/OpenAddressing/LinearProbingExample.tikz}%
        \end{adjustbox}
        \vspace{-0.5em}%
        \caption{Probe/Insertion sequence on a hash map}%
        \label{fig:hashing:open_addressing:linear_probing_example2}%
      \end{figure}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Linear Probing}
  \textbf{Example:}
  \begin{itemize}
    \item
      Hash function:
      \begin{math}
        {\color{MainA}h(s,j)}
        = ({\color{MainA}s} \mod 7 - {\color{MainA}j}) \mod 7
      \end{math}
  \end{itemize}
  \hfill\\[0.5em]
  \begin{itemize}
    \item<2->
      \lstinline[
        language=Python,
        style={python-idle-code},
        mathescape=true,
        basicstyle=\small
      ]|t.insert(5, "C")|$,\;$
      \begin{math}
        {\color{MainA}h(5, 0)} = 5 ,\;
        {\color{MainA}h(5, 1)} = 4 ,\;
        {\color{MainA}h(5, 2)} = 3
      \end{math}
      \begin{figure}[!h]
        \def\LPEData{
          \relax/0,
          \relax/1,
          \relax/2,
          {5, {\color{green2}C}}/3,
          {53, {\color{green2}B}}/4,
          {12, {\color{green2}A}}/5,
          \relax/6
        }%
        \def\LPEShowIndex{1}%
        \begin{adjustbox}{width=0.75\linewidth}%
          \input{Images/OpenAddressing/LinearProbingExample.tikz}%
        \end{adjustbox}
        \vspace{-0.5em}%
%        \caption{Insertion sequence}%
        \label{fig:hashing:open_addressing:linear_probing_example3}%
      \end{figure}
      \hfill\\[1.0em]
    \item<3->
      \lstinline[
        language=Python,
        style={python-idle-code},
        mathescape=true,
        basicstyle=\small
      ]|t.insert(15, "D")|$,\;$
      \begin{math}
        {\color{MainA}h(15, 0)} = 1
      \end{math}
      \begin{figure}[!h]
        \def\LPEData{
          \relax/0,
          {15, {\color{green2}D}}/1,
          \relax/2,
          {5, {\color{green2}C}}/3,
          {53, {\color{green2}B}}/4,
          {12, {\color{green2}A}}/5,
          \relax/6
        }%
        \def\LPEShowIndex{0}%
        \begin{adjustbox}{width=0.75\linewidth}%
          \input{Images/OpenAddressing/LinearProbingExample.tikz}%
        \end{adjustbox}
        \vspace{-0.5em}%
        \caption{Probe/Insertion sequence on a hash map}%
        \label{fig:hashing:open_addressing:linear_probing_example4}%
      \end{figure}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Linear Probing}
  \textbf{Example:}
  \begin{itemize}
    \item
      Hash function:
      \begin{math}
        {\color{MainA}h(s,j)}
        = ({\color{MainA}s} \mod 7 - {\color{MainA}j}) \mod 7
      \end{math}
  \end{itemize}
  \hfill\\[0.5em]
  \begin{itemize}
    \item<2->
      \lstinline[
        language=Python,
        style={python-idle-code},
        mathescape=true,
        basicstyle=\small
      ]|t.insert(2, "E")|$,\;$
      \begin{math}
      {\color{MainA}h(2, 0)} = 2
      \end{math}
      \begin{figure}[!h]
        \def\LPEData{
          \relax/0,
          {15, {\color{green2}D}}/1,
          {2, {\color{green2}E}}/2,
          {5, {\color{green2}C}}/3,
          {53, {\color{green2}B}}/4,
          {12, {\color{green2}A}}/5,
          \relax/6
        }%
        \def\LPEShowIndex{1}%
        \begin{adjustbox}{width=0.75\linewidth}%
          \input{Images/OpenAddressing/LinearProbingExample.tikz}%
        \end{adjustbox}
        \vspace{-0.5em}%
%        \caption{Insertion sequence on a hash map}%
        \label{fig:hashing:open_addressing:linear_probing_example6}%
      \end{figure}
      \hfill\\[1.0em]
    \item<3->
      \lstinline[
        language=Python,
        style={python-idle-code},
        mathescape=true,
        basicstyle=\small
      ]|t.insert(19, "F")|$,\;$
      \begin{math}
        {\color{MainA}h(19, 0)} = 5 ,\;
        {\color{MainA}h(19, 1)} = 4 ,\;
      \end{math}\\
      \begin{math}
        \hspace{1.5em}
        {\color{MainA}h(19, 2)} = 3 ,\;
        {\color{MainA}h(19, 3)} = 2 ,\;
        {\color{MainA}h(19, 4)} = 1 ,\;
        {\color{MainA}h(19, 5)} = 0
      \end{math}
      \begin{figure}[!h]
        \def\LPEData{
          {19, {\color{green2}F}}/0,
          {15, {\color{green2}D}}/1,
          {2, {\color{green2}E}}/2,
          {5, {\color{green2}C}}/3,
          {53, {\color{green2}B}}/4,
          {12, {\color{green2}A}}/5,
          \relax/6
        }%
        \def\LPEShowIndex{0}%
        \begin{adjustbox}{width=0.75\linewidth}%
          \input{Images/OpenAddressing/LinearProbingExample.tikz}%
        \end{adjustbox}
        \vspace{-0.5em}%
        \caption{Probe/Insertion sequence on a hash map}%
        \label{fig:hashing:open_addressing:linear_probing_example7}%
      \end{figure}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Squared Probing}
  \textbf{Squared probing:}
  \begin{itemize}
    \item<2->
      Motivation: avoid local clustering
      \begin{displaymath}
        {\color{MainA}g(s,j)}
        := (-1)^{\color{MainA}j}
        \left\lceil \frac{{\color{MainA}j}}{2} \right\rceil^2
      \end{displaymath}
    \onslide<3->
    \vspace{-2.0em}
  \begin{figure}[!h]
    \begin{adjustbox}{width=0.7\linewidth}%
      \input{Images/OpenAddressing/SquaredProbing.tikz}%
    \end{adjustbox}
    \vspace{-1.0em}
    \caption{Squared probe sequence}%
    \label{fig:hashing:open_addressing:squared_probing}%
  \end{figure}
    \item<4->
      This leads to the following probe sequence
      \begin{displaymath}
        {\color{MainA}h(s) ,\;
        h(s)+1 ,\;
        h(s)-1 ,\;
        h(s)+4 ,\;
        h(s)-4 ,\;
        h(s)+9 ,\;
        h(s)-9 ,\;}
        \dotsc
      \end{displaymath}
  \end{itemize}
  \vspace{1.0em}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Squared Probing}
  \textbf{Squared probing:}
  \begin{displaymath}
    {\color{MainA}g(s,j)
    := (-1)^j
    \left\lceil \frac{j}{2} \right\rceil^2}
  \end{displaymath}
  \vspace{-1.0em}
  \begin{itemize}
    \item<2->
      If ${\color{MainA}m}$ is a prime number for which
      \begin{math}
        {\color{MainA}m = 4 \cdot k + 3}
      \end{math}
      then the probe sequence is a permutation of the indices of
      the hash tables
   \item<3->
      Alternatively:
      \begin{math}
        {\color{MainA}h(s,j) := (h(s) - c_1 \cdot j + c_2 \cdot j^2) \mod m}
      \end{math}
    \item<4->
      Problem of secondary clustering:\\
      No local clustering anymore, but keys with same hash value
      have similar probe sequence
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Uniform Probing}
  \textbf{Uniform Probing:}
  \begin{itemize}
    \item<2->
      Motivation: so far function ${\color{MainA}g(s,j)}$  uses only the step
      counter ${\color{MainA}j}$ for linear and squared probing\\
      {\color{red}$\Rightarrow$ The probe sequence is independent of the key
        $s$}
    \item<3->
      Uniform probing computes the sequence ${\color{MainA}g(s,j)}$ of permutations of all possible indices dependent on key ${\color{MainA}s}$
    \item<4->
      \textbf{Advantage:}
      prevents clustering because different keys with the same hash
      value do not produce the same probe sequence
    \item<5->
      \textbf{Disadvantage:}
      hard to implement
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Double Hashing}
  \textbf{Double Hashing:}
  \vspace{-1.0em}
  \begin{figure}[!h]
    \begin{adjustbox}{width=0.9\linewidth}%
      \input{Images/OpenAddressing/DoubleHashing.tikz}%
    \end{adjustbox}
    \caption{double hashing probe sequence}%
    \label{fig:hashing:open_addressing:double_hashing}%
  \end{figure}
  \vspace{-1.0em}
  \begin{itemize}
    \item<2->
      Motivation: consider key {\color{MainA}$s$} in probe sequence
    \item<3->
      Use two independent hash functions
      \begin{math}
        {\color{MainA}h_1(s)},
        {\color{MainB}h_2(s)}
      \end{math}
    \item<4->
      Hash function:
      \begin{math}
        {\color{MainA}h(s,j)
        = ({\color{MainA}h_1(s)}
        + {\color{MainA}j} \cdot {\color{MainB}h_2(s)})}
        \mod m
      \end{math}
  \end{itemize}

\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Double Hashing}
  \textbf{Double Hashing:}
  \begin{itemize}
    \item
      Hash function:
      \begin{math}
        {\color{MainA}h(s,j)
        = ({\color{MainA}h_1(s)}
        + {\color{MainA}j} \cdot {\color{MainB}h_2(s)})}
        \mod m
      \end{math}
    \item<2->
      Probe sequence:
      \begin{displaymath}
        {\color{MainA}h_1(s)} ,\;
        {\color{MainA}h_1(s)} + {\color{MainB}h_2(s)} ,\;
        {\color{MainA}h_1(s)} + 2 \cdot {\color{MainB}h_2(s)} ,\;
        {\color{MainA}h_1(s)} + 3 \cdot {\color{MainB}h_2(s)} ,\;
        \dotsc
      \end{displaymath}
    \item<3->
      Works well in practical use
    \item<4->
      This method is an approximation of uniform probing
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Double Hashing - Example}
  \textbf{Example:}
  %\begin{itemize}
  %  \item
  %    The efficiency of double hashing is dependent on
  %    \begin{math}
  %      {\color{MainA}h_1(s)} \neq {\color{MainB}h_2(s)}
  %    \end{math}
  %  \item
  %    The diversion sequence is dependent on the key ${\color{MainA}s}$
  %\end{itemize}
  \onslide<2->
  {\color{MainA}
  \begin{align*}
    {\color{MainA}h_1(s)} &= {\color{MainA}s \mod 7}\\
    {\color{MainB}h_2(s)}
      &= \left({\color{MainA}s} \mod 5\right) + 1\\
    {\color{MainA}h(s,j)}
      &= {\color{MainA}h_1(s)}
      + {\color{MainA}j} \cdot {\color{MainB}h_2(s)}
      \mod 7
  \end{align*}}
  \vspace{-1.0em}
  \onslide<3->
  \begin{table}[!h]
    \caption{comparing both hash functions}
    \begin{tabular}{c|cccccc}
      {\color{MainA}s} & 10 & 19 & 31 & 22 & 14 & 16\\
      \midrule
      ${\color{MainA}h_1(s)}$ & 3 & 5 & 3 & 1 & 0 & 2\\
      ${\color{MainB}h_2(s)}$ & 1 & 5 & 2 & 3 & 5 & 2
    \end{tabular}
  \end{table}
  \begin{itemize}
    \item
      The efficiency of double hashing is dependent on
      \begin{math}
       {\color{MainA}h_1(s)} \neq {\color{MainB}h_2(s)}
      \end{math}
 \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Double Hashing - Optimization}
  \vspace{-2.0em}
  \begin{figure}[!h]
    \begin{adjustbox}{width=0.9\linewidth}%
      \input{Images/OpenAddressing/DoubleHashingNoBrent.tikz}%
    \end{adjustbox}
    \vspace{-1.0em}
    \caption{double hashing}%
    \label{fig:hashing:open_addressing:double_hashing_no_brent}%
  \end{figure}
  \textbf{Double hashing by Brent:}
  \begin{itemize}
    \item<2-> Motivation:\\
      Because different keys have different probe sequences,
      the sequence of the insertions has impact on efficiency of a sucessful search
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Double Hashing - Optimization}
  \vspace{-2.0em}
  \begin{figure}[!h]
    \begin{adjustbox}{width=0.9\linewidth}%
      \input{Images/OpenAddressing/DoubleHashingNoBrent.tikz}%
    \end{adjustbox}
    \vspace{-1.0em}
    \caption{double hashing}%
    \label{fig:hashing:open_addressing:double_hashing_no_brent2}%
  \end{figure}
  \vspace{-1.0em}
  \textbf{Example:}
  \begin{itemize}
    \item<1->
      The key ${\color{MainA}s_1}$ is inserted at position
      \begin{math}
        p_1 = {\color{MainA}h(s_1, 0)}
      \end{math}
    \item<2->
      The hash function for ${\color{MainB}s_2}$ also results in
      \begin{math}
        p_2 = {\color{MainB}h(s_2, 0)} = p_1
      \end{math}
    \item<3->
      The locations
      \begin{math}
        {\color{MainB}h(s_2, j)}, \;
        {\color{MainA}j} \in \{1,\dots,n\}
      \end{math}
      are also occupied
    \item<6->
      If we insert ${\color{MainB}s_2}$ at position
      ${\color{MainB}h(s_2, n + 1)}$ the search will be inefficient
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Double Hashing - Optimization}
  \vspace{-2.0em}
  \begin{figure}[!h]
    \begin{adjustbox}{width=0.9\linewidth}%
      \input{Images/OpenAddressing/DoubleHashingBrent.tikz}%
    \end{adjustbox}
    \vspace{-1.0em}
    \caption{double hashing by Brent}%
    \label{fig:hashing:open_addressing:double_hashing_brent}%
  \end{figure}
  \vspace{-1.0em}
  \begin{itemize}
  \item<4->
    Reversed sequence of keys would have been better
  \item<5->
    \textbf{Brent's idea:}
    \begin{itemize}
    \item<6->
      Test if location ${\color{MainA}h(s_1, 1)}$ is free
    \item<7->
      If yes, move ${\color{MainA}s_1}$ from
      ${\color{MainA}h(s_1, 0)}$ to ${\color{MainA}h(s_1, 1)}$
      and insert ${\color{MainB}s_2}$ at
      ${\color{MainB}h(s_2, 0)}$
    \end{itemize}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Ordered Hashing}
  \textbf{ Idea:}
  \begin{itemize}
    \item Motivation:
      colliding elements are inserted in the hash table sorted.
    \item
      Therefore, in case of an unsuccessful search of elements
      in combination with linear probing or double hashing,
      aborting is possible earlier because single probing steps
      have a fixed length
  \end{itemize}
  \hfill\\[0.5em]
  \textbf{Implementation:}
  \begin{itemize}
    \item
      Compare both keys if a collision occurs
    \item
      Insert the smaller key at $p_1$
    \item
      Search a position based on the diversion order for the bigger key
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Ordered Hashing}
  \textbf{Example:}
  \begin{itemize}
    \item
      The key ${\color{MainA}12}$ is saved at position
      $p_1 = {\color{MainA}h(12, 0)}$
    \item
      We insert the key ${\color{MainA}5}$ into the hash map
    \item
      We assume ${\color{MainA}h(5,0)}$ results in location $p_1$
    \item
      Because ${\color{MainA}5} < {\color{MainA}12}$ we insert
      the key ${\color{MainA}5}$ at position $p_1$
    \item
      For the key ${\color{MainA}12}$ we iterate through the sequence
      \begin{displaymath}
        {\color{MainA}h(12, 1)} ,\;
        {\color{MainA}h(12, 2)} ,\;
        {\color{MainA}h(12, 3)} ,\;
        \dots
      \end{displaymath}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Robin-Hood Hashing}
  \textbf{Motivation:}
  \begin{itemize}
    \item <2->
      Having similiar length of probe sequences for all elements.
      Total costs stay the same, but they are distributed evenly.
      Results in approximately similar search times for all elements
  \end{itemize}
  \hfill\\[0.5em]
  \onslide<3->
  \textbf{Implementation:}
  \begin{itemize}
    \item<4->
      If two keys ${\color{MainA}s_1}, {\color{MainA}s_2}$ collide
      (\begin{math}
        p_1 = {\color{MainA}h(s_1, j_1)}
            = {\color{MainA}h(s_2, j_2)}
      \end{math})
      we compare the length of the sequence
      (\begin{math}
        {\color{MainA}j_1} \;\text{or}\; {\color{MainA}j_2}
      \end{math})
    \item<5->
      The key with the bigger search sequence is inserted at $p_1$.
      The other key is assigned to a new location based on the sequence
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Robin-Hood Hashing}
  \textbf{Example:}
  \begin{itemize}
    \item
      The key ${\color{MainA}12}$ is saved at position
      $p_1 = {\color{MainA}h(12, 7)}$
    \item
      We insert the key ${\color{MainA}5}$ into the hash map
    \item
      We assume ${\color{MainA}h(5,0)}$ results in location $p_1$
    \item
      Because
      \begin{math}
        {\color{MainA}j_1} < {\color{MainA}j_2} \;
        ({\color{MainA}0} < {\color{MainA}7})
      \end{math}
      key ${\color{MainA}12}$ stays at position $p_1$
    \item
      For key ${\color{MainA}5}$ we iterate through the
      sequence
      \begin{displaymath}
        {\color{MainA}h(5, 1)} ,\;
        {\color{MainA}h(5, 2)} ,\;
        {\color{MainA}h(5, 3)} ,\;
        \dots
      \end{displaymath}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Implement Insert / Remove}
  \textbf{Problem:}
  \begin{itemize}
    \item
      The key ${\color{MainA}s_1}$ is inserted at position $p_1$
    \item
      The key ${\color{MainA}s_2}$ returns the same hash value,
      but is inserted at position $p_2$ because of the probing order
    \item
      If ${\color{MainA}s_1}$ is removed, it is impossible to find
      ${\color{MainA}s_2}$
  \end{itemize}
  \vspace{1.0em}
  \onslide<2->
  \textbf{Solution:}
  \begin{itemize}
    \item<3->
      \textbf{Remove:}
      elements are marked as removed, but not deleted
    \item<4->
      \textbf{Inserting:}
      elements marked as removed will we overwritten
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\subsection{Summary}

\begin{frame}{Hashing}{Open Addressing - Summary Collision Handling}
  \textbf{Bucket as linked list:}
  {\color{MainA}(dynamic, number of elements variable)}
  \begin{itemize}
    \item
      Save colliding elements as linked list
  \end{itemize}
  \vspace{1.0em}
  \textbf{Open hashing:}
  {\color{MainA}(static, number of elements fixed)}
  \begin{itemize}
    \item
      Determine a probe sequence, permutation of all hash values
    \item
      Linear, quadratic probing:
      \begin{itemize}
        \item
          Easy to implement
        \item
          Raises the probability of collisions because probing order does
          not depend on the key
      \end{itemize}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Summary Collision Handling}
  \textbf{Open hashing:}
         {\color{MainA}(static, number of elements fixed)}
  \onslide<2->
  \begin{itemize}
    \item
      Uniform probing, double hashing:
      \begin{itemize}
        \item
          Different probing orders for different keys
        \item
          Avoids clustering of elements
      \end{itemize}
  \end{itemize}
  \vspace{1.0em}
  \onslide<3->
  \textbf{Improving efficiency:}
  {\color{MainA}(Brent, Ordered Hashing)}
  \begin{itemize}
    \item
      Improve search efficiency by sorting colliding insertions
      \begin{itemize}
        \item
          Abortion of unsuccessfull search
        \item
          Search sequence length balancing
      \end{itemize}
  \end{itemize}
\end{frame}

%-------------------------------------------------------------------------------

\begin{frame}{Hashing}{Open Addressing - Summary Hashing}
  \textbf{Hashing:}
  \begin{itemize}
    \item<2->
      Efficiency of dictionary operations:\\
      \hspace{1.5em}\texttt{Insert:} $O(1) \dots O(n)$\\
      \hspace{1.5em}\texttt{Search:} $O(1) \dots O(n)$\\
      \hspace{1.5em}\texttt{Remove:} $O(1) \dots O(n)$
    \item<3->
      Direct access oto all elements in a hash table
    \item<4->
      Using a hash function to find the position (hash value) in the hash table
    \item<5->
      Hash function, size of the hash table and strategy to
      avoid hash collisions all influence the efficiency of the
      data structure
  \end{itemize}
\end{frame}


\section{Models}
\subsection{Regression}
\subsubsection{Linear Regression (Normal)}
\subsubsection{L1 Regression (Laplace)}
\subsubsection{Ridge Regression (Normal + Normal Prior on Weights)}
\subsubsection{Lasso Regression (Normal + Laplace Prior on Weights)}
\subsubsection{Poisson Regression (Poisson)}
\subsubsection{Negative Binomial Regression (Negative Binomial)}
% \subsubsection{Binomial Regression (Binomial)}

\subsection{Classification}
\subsubsection{Logistic Regression (Bernoulli)}
\subsubsection{Bayesian Logistic Regression (Bernoulli)}
\subsubsection{Softmax Regression (Categorical)}
\subsubsection{Bernoulli Naive Bayes (Bernoulli - Bernoulli)}
\subsubsection{Gaussian Naive Bayes (Categorical - Gaussian)}
\subsubsection{Multinomial Naive Bayes (Categorical - Categorical)}
\subsubsection{Linear Discriminant Analysis (Categorical - Shared Covariance)}
\subsubsection{Quadratic Discriminant Analysis (Categorical - Multivariate Gaussian)}

\subsection{Clustering}
\subsubsection{Gaussian Mixture Model (Categorical - Multivariate Gaussian)}

\subsection{Unconstrained Matrix Factorization (Gaussian)}

\subsection{Principle Components Analysis}
\subsubsection{PCA}
\subsubsection{EM-PPCA}
\subsubsection{Variational PPCA}

\subsection{Generative Adversarial Networks}
\subsubsection{Generative Adversarial Networks}
\subsubsection{GAN Model}
\subsubsection{MMGAN Model}
\subsubsection{WGAN Model}
\subsubsection{LSGAN Model}

\subsection{Variational Auto-Encoders}


\documentclass[12pt]{article}
\usepackage[dvips]{graphicx}
\topmargin -40pt
\headsep 30pt
\evensidemargin 0pt
\oddsidemargin 0pt
\textwidth 490pt
\textheight 650pt

\def\beq{\begin{equation}}
\def\eeq{\end{equation}}

\begin{document}

%\newpage
\section*{Verdict Triangle Metrics:}

\subsection*{Variable Definitions:}

\begin{figure}[htb]
  \begin{center}
    \includegraphics[height=2.0in]{tri.eps}
    \caption{Vertices of Triangle}
    \label{fig:blank}
  \end{center}
\end{figure}

\begin{center}
$\vec P_0 = (x_0, y_0, z_0) $
\end{center}

\begin{displaymath}
\vec P_1 = (x_1, y_1, z_1)
\end{displaymath}

\begin{displaymath}
\vec P_2 = (x_2, y_2, z_2)
\end{displaymath}

\begin{displaymath}
A = \frac {| ( \vec P_1 - \vec P_0 ) \times ( \vec P_2 - \vec P_0 ) |}
          {2}
\end{displaymath}

\begin{center}
$DBL\_MAX = 1.0E+30 $
\end{center}

\begin{flushleft}
The indices \emph n, (\emph n = 0,1,2), are taken modulo three so that, for example,
if \emph n = 1, then \emph n + 1 becomes 2 and \emph n + 2 becomes 0.
\end{flushleft}

\subsection*{Overflow:}

\begin{flushleft}
NOTE:  The metrics below are all checked for overflow like so:
\end{flushleft}

\begin{flushleft}
${IF \quad metric\_value > 0;  \quad metric\_value = MIN( metric\_value, DBL\_MAX )}$
\end{flushleft}

\begin{flushleft}
${ELSE \quad metric\_value = MAX( metric\_value, -DBL\_MAX )}$
\end{flushleft}

\subsection*{Metric Ranges:}

\begin{flushleft}
Acceptable Range: Well-behaved elements will have metrics in this range.
\end{flushleft}
\begin{flushleft}
Normal Range:     All elements except those with degeneracies will have  \newline
                  metrics in this range.
\end{flushleft}
\begin{flushleft}
Full Range:       All elements including degenerate ones will have metrics \newline
                  in this range.
\end{flushleft}

%---------------------------Area-----------------------------
\subsection*{Area:}

\begin{displaymath}
\textrm{area} = A
\end{displaymath}

\begin{tabular}{lll}
& Metric Description:  & (1/2) * Cross-product at any corner node. \\
& Dimension:           & 2                              \\
& Acceptable Range:    & 0 to $DBL\_MAX$                      \\
& Normal Range:        & 0 to $DBL\_MAX$                      \\
& Full Range:          & 0 to $DBL\_MAX$                       \\
& Note:                & Since $A$ is non-negative, the currrent version of \\
&                      & Verdict cannot detect inverted triangles. \\
& Reference:           & \cite{three}                     \\
\end{tabular}

%---------------------------Aspect Ratio-----------------------------
\subsection*{Aspect Ratio:}

\begin{displaymath}
aspect~ratio = \frac {{|\vec{P_1} - \vec{P_0} |}^{2} +
                            {|\vec{P_2} - \vec{P_1} |}^{2} +
                            {|\vec{P_0} - \vec{P_2} |}^{2} }
                            {4A \sqrt{3}}
\end{displaymath}

\begin{tabular}{lll}
& Metric Description:  & Ratio of sum of edge lengths squared to \\
&                      & triangle area. Measures element shape. \\
& Dimension:           & 0                      \\
& Acceptable Range:    & 1 to 1.3               \\
& Normal Range:        & 1 to $DBL\_MAX$                      \\
& Full Range:          & 1 to $DBL\_MAX$ \\
& Value of metric on Unit Equilateral Triangle:       & Aspect Ratio = 1.0 \\
& Value of metric on 'Flat' Triangle:  & Aspect Ratio = $DBL\_MAX$ \\
& Note:                & When $A = 0$, Verdict returns \\
&                      & Aspect Ratio = $DBL\_MAX$  \\
& Reference:           &  \cite{one}  \cite{two}  \\
\end{tabular}

%---------------------------Condition Number-----------------------------
\subsection*{Condition Number:}

\begin{displaymath}
\vec v_1 = {\vec P_1 - \vec P_0}
\end{displaymath}

\begin{displaymath}
\vec v_2 = {\vec P_2 - \vec P_0}
\end{displaymath}

\begin{displaymath}
condition~number = \frac {\Big( (\vec v_1 \bullet \vec v_1) +
                        (\vec v_2 \bullet \vec v_2) -
                        (\vec v_1 \bullet \vec v_2) \Big)}
                        { 2A \sqrt 3 }
\end{displaymath}

\begin{tabular}{lll}
& Metric Description:  & Condition number of weighted Jacobian matrix.         \\
&                      & Measures element shape.   \\
& Dimension:           & 0                      \\
& Acceptable Range:    & 1 to 1.3               \\
& Normal Range:        & 1 to $DBL\_MAX$        \\
& Full Range:          & 1 to $DBL\_MAX$        \\
& Value of metric on Unit Equilateral Triangle:       & Condition Number = 1.0 \\
& Value of metric on 'Flat' Triangle:  & Condition Number = $DBL\_MAX$  \\
& Note:                & When $A = 0$, Verdict returns  \\
&                      & Condition Number = $DBL\_MAX$  \\
&                      & Condition Number is invariant to which \\
&                      & node it is computed at. \\
& Reference:           & \cite{four}, \cite{five} \\
\end{tabular}

%---------------------------Distortion-----------------------------
\subsection*{Distortion:}

\begin{displaymath}
distortion = \frac{ |J|*master\textrm{-}area } { true\textrm{-}area }
\end{displaymath}

\begin{flushleft} Where, \end{flushleft}
$|J| = $ minimum determinant of the Jacobian computed over all gauss points  \newline
of the element.  The location of the Gauss points is not documented. \newline
$master\textrm{-}area =$ area of the master tri, where the master tri's corner nodes \newline
are as follows: \newline

 $\vec P_0 = ( -1, -\frac {\sqrt{3}}{3}, 0 )$,
 $\vec P_1 = ( 1, -\frac{\sqrt{3}}{3}, 0 )$,
 $\vec P_1 = ( 0, \frac{2\sqrt{3}}{3}, 0 )$ \newline

\begin{tabular}{lll}
& Metric Description:  & Minimum Gauss Point Jacobian divided by tri \\
&                      & area, times master tri's area. \\
& Dimension:           & $L^0$              \\
& Acceptable Range:    & 0.5 to 1            \\
& Normal Range:        & 0 to 1        \\
& Full Range:          & $-DBL\_MAX$ to $DBL\_MAX$        \\
& Value of metric on Unit Equilateral Triangle:       & Distortion = 1.0 \\
& Note:                & This metric is currently unsupported. \\
& Reference:           &  Adapted from \cite{six} \\
\end{tabular}

%---------------------------Maximum Angle-----------------------------
\subsection*{Maximum Angle:}

\begin{displaymath}
\theta_{max}= \arccos{\Bigg( \frac {(\vec P_{n+1} - \vec P_n) \bullet (\vec P_{n-1} - \vec P_n)}
                 {|\vec P_{n+1} - \vec P_n | |\vec P_{n-1} - \vec P_n| } \Bigg) }
                 \Bigg( \frac {180} {\pi} \Bigg)
\end{displaymath}

\begin{flushleft}
where $n$ in $\theta_n$ is the index of the node opposite the longest edge length
\end{flushleft}

\begin{tabular}{lll}
& Metric Description:  & Maximum included angle in triangle. \\
& Dimension:           & degrees                             \\
& Acceptable Range:    & 60 to 90                            \\
& Normal Range:        & 60 to 180                           \\
& Full Range:          & 0 to 180                           \\
& Value of metric on Unit Equilateral Triangle:       & $\theta_{max}= 60 $ \\
& Value of metric on 'Flat' Triangle:  & $\theta_{max} = 0 $\\
& Note:                & If $P_0$ = $P_1$ or $P_0$ = $P_2$ or $P_1$ = $P_2$, \\
&                      & Verdict returns $\theta_{max}$ = 0.0  \\
& Reference:           & \cite{three} \\
\end{tabular}

%---------------------------Minimum Angle-----------------------------
\subsection*{Minimum Angle:}

\begin{displaymath}
\theta_{min}= \arccos{\Bigg( \frac {(\vec P_{n+1} - \vec P_n) \bullet (\vec P_{n-1} - \vec P_n)}
                 {|\vec P_{n+1} - \vec P_n | |\vec P_{n-1} - \vec P_n| } \Bigg) }
                 \Bigg( \frac {180} {\pi} \Bigg)
\end{displaymath}

\begin{flushleft}
where $n$ in $\theta_n$ is the index of the node opposite the shortest edge length
\end{flushleft}

\begin{tabular}{lll}
& Metric Description:  & Minimum included angle in triangle. \\
& Dimension:           & degrees                             \\
& Acceptable Range:    & 30 to 60                            \\
& Normal Range:        & 0 to 60                           \\
& Full Range:          & 0 to 360                           \\
& Value of metric on Unit Equilateral Triangle:       & $\theta_{min}= 60 $ \\
& Note:                & If $P_0$ = $P_1$ or $P_0$ = $P_2$ or $P_1$ = $P_2$, \\
&                      & Verdict returns $\theta_{min}$ = 360.0  \\
& Value of metric on 'Flat' Triangle:  & $\theta_{min} = 360$ \\
& Reference:           & \cite{three}  \\
\end{tabular}

%---------------------------Scaled Jacobian-----------------------------
\subsection*{Minimum Scaled Jacobian:}

\begin{displaymath}
L_{max} = MAX( | \vec P_1 - \vec P_0 | * | \vec P_2 - \vec P_1 |,
               | \vec P_1 - \vec P_0 | * | \vec P_0 - \vec P_2 |,
               | \vec P_2 - \vec P_1 | * | \vec P_0 - \vec P_2 | )
\end{displaymath}

\begin{displaymath}
IF( \vec surf\_normal_{at~tri~center} \times ( \vec P_0 - \vec P_2 \times \vec P_1 - \vec P_0 ) > 0 )
~~jacobian = -1 * jacobian
\end{displaymath}

\begin{displaymath}
scaled~jacobian = \frac {2 * jacobian } { \sqrt 3 * L_{max} }
\end{displaymath}

\begin{tabular}{lll}
& Metric Description:  & Jacobian divided by the lengths of 2 longest edges times $\frac{2}{\sqrt 3}$. \\
& Dimension:           & 0                                          \\
& Full Range:          & -1.155 to +1.155                           \\
& Acceptable Range:    & 0.5 to 1.155                               \\
& Note:                & If $L_{max} < DBL\_MIN, scaled~jacobian = 0$ \\
& Reference:           & \cite{four} \\
\end{tabular}

%---------------------------Relative Size-Squared-----------------------------
\subsection*{Relative Size-Squared:}

\begin{displaymath}
R = \Bigg(\frac {A} {Average \quad Triangle \quad Area} \Bigg)^2
\end{displaymath}
\begin{displaymath}
relative~size \textrm{-}squared = MIN( R, \frac{1}{R} )
\end{displaymath}

\begin{tabular}{lll}
& Metric Description:  & Measures ratio of triangle area to average area \\
&                      & of all triangles in mesh.             \\
& Dimension:           & 0                                          \\
& Acceptable Range:    & 0.25 to 1                                     \\
& Normal Range:        & 0 to 1                           \\
& Full Range:          & 0 to 1                           \\
& Value of metric on Unit Equilateral Triangle:   & Any triangle whose area is the same as the \\
&                      & average area over the mesh, \\
&                      & Relative Size-Squared = 1.0  \\
& Value of metric on 'Flat' Triangle:  & Relative Size-Squared = 0.0               \\
& Note:                & If $Average$ $Triangle$ $Area$ = 0 or $A$ = 0, \\
&                      & Verdict returns Relative Size-Squared = 0.0 \\
& Reference:           & \cite{five} \\
\end{tabular}

%---------------------------Shape-----------------------------
\subsection*{Shape:}

\begin{displaymath}
shape = \frac { 1 } { condition~number }
\end{displaymath}

\begin{tabular}{lll}
& Metric Description:  & 1/Condition Number of weighted Jacobian \\
&                      & matrix. Measures element shape.   \\
& Dimension:           & 0                                          \\
& Acceptable Range:    & 0.25 to 1                                     \\
& Normal Range:        & 0 to 1                           \\
& Full Range:          & 0 to 1                           \\
& Value of metric on Unit Equilateral Triangle:       & Shape = 1.0 \\
& Value of metric on 'Flat' Triangle:  & Shape = 0.0  \\
& Reference:           & \cite{five} \\
\end{tabular}

%---------------------------Shape & Size-----------------------------
\subsection*{Shape and Size:}
\begin{displaymath}
  shape~and~size = shape * relative~size \textrm{-}squared
\end{displaymath}

\begin{tabular}{lll}
& Metric Description:  & Product of Shape and Relative Size \\
& Dimension:           & 0                                  \\
& Acceptable Range:    & 0.25 to 1                                     \\
& Normal Range:        & 0 to 1                           \\
& Full Range:          & 0 to 1                           \\
& Value of metric on Unit Equilateral Triangle: & If triangle's area equals the average Area,  \\
&                      & Shape and Size = 1.0 \\
& Value of metric on 'Flat' Triangle:  & Shape and Size = 0.0 \\
& Reference:           &  \cite{five} \\
\end{tabular}

\begin{thebibliography}{99}

\bibitem{one} Bhatia, R.P. and Lawrence, K.L. "Two-dimensional
finite element mesh generation based on stripwise automatic
triangulation," Computers and Structures, 36:309-319, 1990.

\bibitem{two} Bank, R.E. and Xu, J.  "An algorithm
for coarsening unstructured meshes,"Numerische Mathematik,
73, p1-36, 1996.

\bibitem{three} Traditional.

\bibitem{four} P. Knupp, "Achieving Finite Element Mesh Quality
via Optimization of the Jacobian Matrix Norm and Quantities",
Intl. J. Numer. Meth. Engng. 2000, 48:1165-1185.

\bibitem{five} P. Knupp, "Algebraic mesh quality metrics for
unstructured initial meshes" Finite Elements in Analysis and
Design, Vol 39, p217-241, 2003.

\bibitem{six} SDRC/IDEAS Simulation: Finite Element
Modeling--User's Guide.

\end{thebibliography}

\end{document}


\section{Outputs}

\subsection{Incidence}
Incidence represents the rate of onset of new disease episodes,
(regardless of symptoms or detection).
It is calculated as the rate of transition between the early and late active model compartments.
Therefore, this indicator is slightly lagged relative to the onset of infectiousness,
and occurs at the same point in the disease episode as for case isolation
(for those persons for whom self-isolation occurs).
Thus, this indicator can be reasonably considered as relating to the point in a disease episode
at which significant symptoms would develop.
However, we stress that this indicator includes all disease episodes,
including asymptomatic and symptomatic undetected episodes.

\subsection{Notifications}
Notifications are derived from the calculation of incidence described above,
but limited to the detected clinical stratum (see \ref{clin}).
Therefore, this considers case detection as being interchangeable with notification.
A gamma distribution convolution is then applied to the detected case incidence to allow for the lag
between symptom onset and case reporting.  % Refer to the parameters table for the specific parameters
The mass of the gamma distribution between each sequential pair of time points is
used in the calculation.

\subsection{COVID-19-related mortality}
COVID-19-related deaths are derived from the calculation of incidence described above,
but limited to the two symptomatic clinical strata (both detected and undetected).
Calculations are made separately for each age group, each vaccine-induced immunity stratum,
and each strain, given that all these factors influence disease-induced mortality rates.
A convolution is applied to each age, immunity and strain-specific symptomatic incidence rate calculation.
The base case fatality rate (CFR) is first determined as a model input,  % Refer to the parameters table
which is then adjusted according to the protection afforded by vaccine-induced immunity.
This may then be adjusted according to better match the local epidemic characteristics through an
``adjuster'' parameter.
This parameter applies equally to each age group and acts to inflate or deflate the case fatality rate
adjusted for vaccine-induced immunity.
However, rather than directly multiplying the case fatality rate by this adjuster,
we apply the adjuster to the odds of death equivalent to the risk death.
That is, the adjusted case fatality rate is calculated as:
\[CFR_{adj} = \frac{CFR_{base} \times adjuster}{CFR_{base} \times (adjuster - 1) + 1}\]
Next, the adjusted CFR is again adjusted for the severity of the strain
responsible for the disease episode.
Having determined the age, immunity and strain-specific CFR,
a gamma-distributed convolution is calculated such that the total density
of the distribution is equal to the CFR determined as described above.  % Refer to the parameters table
As for notifications, the mass of the gamma distribution between each sequential pair of time points is
used in the calculation.

\subsection{Hospital admissions}
The rate of new hospital admissions is calculated from symptomatic incidence in an exactly analogous way
to that described for mortality in the previous section.
Age, immunity and strain-specific risks of hospitalisation are calculated,
with adjustment of all rates for local context as required, and a convolution is applied.
As for notifications and deaths, the mass of the gamma distribution between each sequential pair of time points is
used in the calculation.

\subsection{Hospital occupancy}
Having calculated the rate of hospital admissions,
a second gamma-distributed convolution is applied to this output to calculate
the total hospital occupancy from the admissions at every previous time point modelled.
Differing from the convolution used to calculate the rates of notifications,
the gamma distribution is used to determine the probability that an admitted patient
would remain in hospital after the time lag from the hospital admission rate being considered.
That is, the complement of the cumulative distribution function for the rate of hospital
discharge is applied.

\subsection{ICU admissions and occupancy}
The calcuation of ICU admissions and occupancy is analogous to that of hospital admissions and occupancy.


\input{preamble}
\usepackage{scrextend}

\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=newest}

% \includeonly{02}

\title{Cohomology via Sheaves: Solutions to Selected Solutions}
\author{\small{Apurva Nakade}}
\date{}
\fancyhead[LO]{Cohomology via Sheaves: Solutions to Selected Problems}

\begin{document}

\section{Topological Preliminaries: Solutions}
\vspace{3em}
\noindent \textbf{Question 4. g)} Good cover for $S^2$:\\
\begin{addmargin}[2em]{0em}
For any triangulation of the sphere $S^2$, the faces of the triangulation form a good cover. This is more generally true for any surface.
\begin{figure}[H]
		\centering
		\includegraphics[height=5cm]{SphereTetrahedron}
    \caption{Triangulating a Sphere. (googled image)}
	\end{figure}
  \vspace{6em}
\end{addmargin}

\noindent \textbf{Question 5.} Good cover for $X \vee Y$:\\
\begin{addmargin}[2em]{0em}
In general, if $X$ and $Y$ have good covers $\U$ and $\U'$ such that the `point of gluing' belongs to a unique $U \in \U$ and $U' \in \U'$. Then we can just use the open covers $\U$ and $\U'$ but glue the open sets $U$ and $U'$ at a point. We can easily check that this indeed forms a good cover. The only non-trivial fact needed to be shown is that if $U$ and $U'$ are contractible then so is $U \vee U'$ (exercise).
\end{addmargin}

\newpage

\noindent \textbf{Question 2. b)} If $X \times Y$ is contractible then so is $X$:\\
\begin{addmargin}[2em]{0em}
(I think you don't need the contractibility of $Y$, if you find a flaw in the following proof please let me know.)

Because $X \times Y$ is contractible, there is a point $(x_0, y_0) \in X \times Y$ and a continuous map
\begin{align*}
  \Phi: X \times Y \times [0,1] \rightarrow X \times Y
\end{align*}
such that
\begin{align*}
  \Phi(x,y,0) & = (x,y)   \\
  \Phi(x,y,1) & = (x_0,y_0)
\end{align*}
for all $ (x,y) \in X \times Y$ i.e. there are ``continuously varying paths'' connecting each point in $ X \times Y$ to $ (x_0,y_0)$.

Restrict the map $\Phi$ to $X \times \{ y_0 \}$ so that we get a map
\begin{align*}
  \Phi|_{y=y_0}: X \times [0,1] &\rightarrow X \times Y \\
  (x,t) &\mapsto \Phi(x,y_0,t)
\end{align*}
This is almost the map we want. Now we compose with the projection onto the first component $\pi_X: X \times Y \rightarrow X$ to get a map $\Psi = \pi_X \circ \Phi$
\begin{align*}
  \Psi : X \times [0,1] \xrightarrow{\Phi|_{y=y_0}} X \times Y \xrightarrow{\pi_X} X
\end{align*}
One can check that $\Psi(x,0) = x $ and $\Psi(x,1) = x_0$. Further, $\Psi$ is continuous as it is a composition of two continuous functions and hence $\Psi$ witnesses the contractibility of $X$.

(Try to draw pictures of what this proof is saying geometrically.)
\end{addmargin}

\end{document}


\section{``Size'' of a molecule}\index{Size of molecule}\index{Molecular size}
A useful measure of a molecule is its size.  There are several possible ways of
defining the size of a molecule.  The definition used in MOPAC is as follows:

The first dimension is the maximum distance between any pair of atoms.

For systems  of 20 or fewer atoms, this distance, and the atoms involved, is
worked out explicitly.  For systems of 21 or more atoms, an atom is selected;
the atom, $K$,  most distant from it is then identified, then the atom, $L$,
most distant  from $K$ is identified.  In most systems, the distance R($K-L$)
is the first dimension.  To ensure that it is, the point half-way between $K$
and $L$ is  selected, and atom $K$ is then re-defined as the atom most distant
from  that point.  A new $L$ is determined.  This sequence in repeated up to 10
times, or until atoms $K$ and $L$ no longer change. There is no guarantee that
the first dimension is, in fact, the largest distance, but it is likely to be
close to the largest possible value.

The second dimension is the maximum distance in the plane perpendicular to the
first dimension between any pair of atoms.

The technique that was used in determining the first dimension for systems of
over 21 atoms is used here.

The third dimension is the maximum distance between any two atoms on the line
perpendicular to the plane of the first two atoms.

This quantity is explicitly calculated.

Note that the second and third dimensions do {\em not} define the smallest
rectangular slot that a molecule would go through; it will normally be slightly
larger than the minimum slot. Nevertheless, the ``dimensions'' of a molecule
can be regarded as a good measure of the size of hole that the molecule could
pass through.  Of course, allowance must be made for the finite size of atoms.

Monatomic systems have no ``dimension'', linear systems have two zero
``dimensions'', and flat systems have one zero ``dimension''.


\documentclass[10pt]{report}

\usepackage{subcaption} % for subfigures
\usepackage{amsthm} % for QED
\usepackage{mathtools} % for delimiter

\usepackage{listings} % for code
\lstset{
	language=R,
	basicstyle=\ttfamily,
	numbers=none,
	stepnumber=1,
	numbersep=8pt,
	showspaces=false,
	showstringspaces=false,
	showtabs=false,
	frame=single,
	tabsize=2,
	captionpos=t,
	breaklines=true,
	breakatwhitespace=false
}

\usepackage{float} % for figure [H]
\usepackage{booktabs} % for tabular
\usepackage{caption} % for \caption*
\usepackage[export]{adjustbox} % for valign=t
\usepackage{array} % for column type m
\usepackage{verbatim}
\usepackage{graphicx}
%\graphicspath{ {imgs/} }
\usepackage{fancyhdr}
\usepackage{amssymb}
\usepackage{amsmath}

%%%%%% Pagination
\setlength{\topmargin}{-.3 in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textheight}{9.in}
\setlength{\textwidth}{6.5in}

%Title page
\newcommand{\hwTitle}{Homework \#2}
\newcommand{\hwCourse}{Applied Statistics/Regression}
\newcommand{\hmwkClassInstructor}{Professor Lulu Kang}

\title{
	\vspace{2in}
	\textmd{\textbf{\hwCourse\\\hwTitle}}\\
	\vspace{0.3in}\large{\textit{\hmwkClassInstructor}}
	\vspace{3in}
}

%\title{Homework 1}
\author{\textbf{Zhihao Ai}}
\date{}

%Header setting.
\pagestyle{fancy}
\fancyhead[L]{Zhihao Ai}
\fancyhead[C]{Math 484}
\fancyhead[R]{Homework 2}
%%%%%%

%Global setting.
%\everymath{\displaystyle}
\setlength\parindent{0pt}

%Custom general commands.
\newcommand{\ds}{\displaystyle}
\newcommand{\ts}{\textstyle}
\newcommand{\f}[1] {f\left(#1\right)}
\newcommand{\eva}[2] {\left. #1 \right|_{#2}}
\newcommand{\dintt}[4] {\int_{#1}^{#2} #3 d#4}

\newcolumntype{N}{ >$ c <$}
\newcolumntype{M}[1]{>{\centering\arraybackslash $}m{#1}<{$}}

\newcommand{\abs}[1] {\left| #1 \right|}

\DeclarePairedDelimiter\autoparen{(}{)}
\newcommand{\pa}[1]{\autoparen*{#1}}
\DeclarePairedDelimiter\autodvert{\Vert}{\Vert}
\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor}
\newcommand{\norm}[1]{\autodvert*{#1}}

\newcommand{\var}{\text{var}}

\begin{document}

\maketitle

\subsection*{Ex 2.27}
Refer to Muscle mass Problem 1.27.
\begin{enumerate}
	\item [a.]
	Conduct a test to decide whether or not there is negative linear association between amount of muscle mass and age. Control the risk of Type I error at .05. State the alternatives, decision rule, and conclusion. What is the \textit{P}-value of the test?

	The two alternatives are:
	\begin{align*}
		H_0: \beta_1 \ge 0\\
		H_a: \beta_1 < 0
	\end{align*}
	The test statistic is $t^* = \frac{\hat{\beta}_1}{s\{\hat{\beta}_1\}}$ and the decision rule is
	\begin{align*}
		\text{If } t^* \ge -t_{\alpha, n-2} = -1.67, \text{ conclude } H_0\\
		\text{If } t^* < -t_{\alpha, n-2} = -1.67, \text{ conclude } H_a
	\end{align*}
	\lstinputlisting{27a.txt}
	Since $t^* = -13.19 < -1.67$, we conclude $H_a$, that there is a negative linear association between the two attributes. The \textit{P}-value of the test is $0+$.

	\item [b.]
	The two-sided \textit{P}-value for the test whether $\beta_0 = 0$ is $0+$. Can it now be concluded that $b_0$ provides relevant information on the amount of muscle mass at birth for a female child?

	Since the data is sampled from women aged from 40 to 79, the amount of muscle mass for female children at birth is not included. Also it is not reasonable to infer the muscle mass of children from that of adults. Therefore, it cannot be concluded that $b_0$ provides relevant information.

	\item [c.]
	Estimate with a 95 percent confidence interval the difference in expected muscle mass for women whose ages differ by one year. Why is it not necessary to know the specific ages to make this estimate?
	\[
	s\{\hat{\beta}_1\} = \frac{\sigma^2}{S_{xx}} = \frac{\hat{\sigma}^2}{S_{xx}} = \frac{SSE/(n-2)}{S_{xx}} = 0.0902
	\]
	 Also we have $t_{0.025, 58} = 2.0017$. So the 95 percent confidence interval is $(\hat{\beta}_1 - t_{0.025, 58}\cdot s\{\hat{\beta}_1\}, \hat{\beta}_1 + t_{0.025, 58}\cdot s\{\hat{\beta}_1\}) = (-1.37, -1.01)$. Since the confidence interval is calculated based on the distribution of $\hat{\beta}_1$ and the $t$ multiple, the specific $x$ value is not needed.
\end{enumerate}

\subsection*{Ex 1.19}
\textbf{Grade point average.} The director of admissions of a small college selected 120 students at random from the new freshman class in a study to determine whether a student's grade point average(GPA) at the end of the freshman year(Y) can be predicted from the ACT test score(X). The results of the study follow. Assume that first-order regression model(1.1) is appropriate.
\begin{enumerate}
	\item [a.]
	Obtain the least squares estimates of $\beta_0$ and $\beta_1$, and state the estimated regression function.
	\lstinputlisting{19a.txt}
	The least square estimates of $\beta_0$ and $\beta_1$ are $\hat{\beta}_0 = 2.11, \hat{\beta}_1 = 0.04$. The estimated regression function is $\hat{Y} = 0.04x + 2.11$.

	\item [b.]
	Plot the estimated regression function and the data. Does the estimated regression function appear to fit the data well?
	\begin{figure}[H]
		\centering
		\includegraphics[width=.6\linewidth]{19b.png}
	\end{figure}
	This function generally gives not a very good but acceptable fit.

	\item [c.]
	Obtain a point estimate of the mean freshman GPA for students with ACT test score $X=30$.

	A point estimate is $\hat{Y}(30) = 0.04(30) + 2.11 = 3.31$.

	\item [d.]
	What is the point estimate of the change in the mean response when the entrance test score increses by one point?

	The point estimate is $\hat{\beta}_1 = 2.11$.
\end{enumerate}

\subsection*{Ex 2.13}
Refer to Grade point average Problem 1.19.
\begin{enumerate}
	\item [a.]
	Obtain a 95 percent interval estimate of the mean freshman GPA for students whose ACT test score is 28. Interpret your confidence interval.
	\lstinputlisting{13a.txt}
	The interval is $(3.06,3.34)$, meaning there is 95 precent probability that the mean GPA for students whose ACT test score is 28 would fall into this interval.

	\item [b.]
	Mary Jones obtained a score of 28 on the entrance test. Predict her freshman GPA using a 95 percent prediction interval. Interpret your prediction interval.
	\lstinputlisting{13b.txt}
	The interval is $(1.96,4.44)$, meaning there is 95 precent probability that her freshman GPA would fall into this interval.

	\item [c.]
	Is the prediction interval in part (b) wider than the confidence interval in part (a)? Should it be?

	Yes, it is wider than that in part (a). It should be because the interval in part (a) is to  predict the mean response for $X=28$ while the interval in part (b) is to predict $y$ for $X=28$ and takes into account the variation of error.

	\item [d.]
	Determine the boundary values of the 95 percent confidence band for the regression line when $X_h = 28$. Is your confidence band wider at this point than the confidence interval in part (a)? Should it be?
	\[
	s\{\hat{Y}\} = \sqrt{\hat{\sigma}^2 \pa{\frac{1}{n} - \frac{(x_h-\bar{x})^2}{S_{xx}}}} = \sqrt{\frac{RSS}{n-2}\pa{\frac{1}{n} - \frac{(x_h-\bar{x})^2}{S_{xx}}}} = 0.0706
	\]
	Since $W = \sqrt{2F_{0.95, 2, 118}} = 2.479$, the boundary values of the confidence band for $X_h = 28$ are $\hat{Y} \pm W\cdot s\{\hat{Y}\}$. Hence, the interval is $(3.026, 3.376)$. It is wider that that in part (b) and it should be because the confidence band must encompass the entire regression line, whereas the confidence limits for $E(\hat{Y})$ at $X = 28$ apply only at the single level of $X = 28$.
\end{enumerate}

\subsection*{Ex 2.23}
Refer to Grade point average Problem 1.19.
\begin{enumerate}
	\item [a.]
	Set up the ANOVA table.
	\lstinputlisting{23a.txt}

	\item [b.]
	What is estimated by $MSR$ in your ANOVA table? by $MSE$? Under what condition do $MSR$ and $MSE$ estimate the same quantity?

	The mean square for act which is 3.5878 is estimated by $MSR$. The mean square for residuals which is 0.3883 is estimated by $MSE$. When $\beta_1 = 0$, $MSR$ and $MSE$ will estimate the same quantity.

	\item [c.]
	Conduct an $F$ test of whether or not $\beta_1 = 0$. Control the $\alpha$ risk at .01. State the alternatives, decision rule, and conclusion.

	The two alternatives are:
	\begin{align*}
		H_0: \beta_1 = 0\\
		H_a: \beta_1 \ne 0
	\end{align*}
	The test statistic is
	\[
	F^* = \frac{SSR/\sigma^2}{1} \div \frac{SSE/\sigma^2}{n-2} = \frac{MSR}{MSE}
	\]
	The decision rule is
	\begin{align*}
		\text{If } F^* \le F_{\alpha, 1, n-2} = 6.85, \text{ conclude } H_0\\
		\text{If } F^* > F_{\alpha, 1, n-2} = 6.85, \text{ conclude } H_a
	\end{align*}
	Given by the ANOVA table, $MSR = 3.59$ and $MSE = 0.39$. Since $F^* = 3.5878/0.3883 = 9.24 > 6.85$, we conclude $H_a$, that $\beta_1 \ne 0$.

	\item [d.]
	What is the absolute magnitude of the reduction in the variation of $Y$ when $X$ is introduced into the regression model? What is the relative reduction? What is the name of the latter measure?

	\lstinputlisting{23d.txt}
	The absolute magnitude of the reduction is $SSR = 3.588$. The relative reduction is $\frac{SSR}{SSTO} = \frac{3.588}{3.588+45.818} = 0.07262$. The latter measure is $R^2$.

	\item [e.]
	Obtain $r$ and attach the appropriate sign.

	$r = +\sqrt{R^2} = 0.269$ since the sign of $\hat{\beta}_1$ is positive.

	\item [f.]
	Which measure, $R^2$ or $r$, has the more clear-cut operational interpretation? Explain.

	$R^2$, because it shows the proportionate reduction of total variation associated with the use of the predictor variable $X$.
\end{enumerate}

{\large\bf Show that for simple linear regression, the t-ratio, $t=\frac{\hat{\beta}_1}{s.e.(\hat{\beta}_1)}$ and the F-ratio, $F=\frac{SS_{reg}}{\hat{\sigma}^2}$ has the relationship, $t^2=F$.}
\begin{align*}
	SS_{reg}
	&= \sum_{i=1}^{n} (\hat{y}_i - \bar{y})^2
	= \sum_{i=1}^{n} (\hat{\beta}_1 x_i + \hat{\beta}_0 - \bar{y})^2
	= \sum_{i=1}^{n} (\hat{\beta}_1 x_i + \bar{y} - \hat{\beta}_1 \bar{x} - \bar{y})^2\\
	&= \sum_{i=1}^{n} (\hat{\beta}_1 (x_i - \bar{x}))^2
	= \hat{\beta}_1^2 \sum_{i=1}^{n} (x_i - \bar{x})^2\\
	F
	&= \frac{SS_{reg}}{\hat{\sigma}^2}
	= \frac{\hat{\beta}_1^2 \sum_{i=1}^{n} (x_i - \bar{x})^2}{\hat{\sigma}^2}
	= \frac{\hat{\beta}_1^2}{\hat{\sigma}^2/S_{xx}}
	= \pa{\frac{\hat{\beta}_1}{s/\sqrt{S_{xx}}}}^2
	= \pa{\frac{\hat{\beta}_1}{s.e.(\hat{\beta}_1)}}^2
	= t^2
\end{align*}
\qed

\end{document}


\section{Normed Spaces. Banach Spaces}
\setcounter{subsection}{2}
\subsection{Further Properties of Normed Spaces}
  \paragraph{4.}
    cf. Prob. 13, Sec 1.2
  \begin{proof}
    The continuity of addition and multiplication follows respectively from the
    inequalities
    \[
      \|(x_1+y_1)-(x_2+y_2)\| \le \|x_1-x_2\|+\|y_1-y_2\|
    \]
    and
    \[
      \|\alpha_1x_1-\alpha_2x_2\| =
      \|\alpha_1x_1-\alpha_1x_2+\alpha_1x_2-\alpha_2x_2\|
      \le |\alpha_1|\|x_1-x_2\| + |\alpha_1-\alpha_2|\|x_2\|.
    \]
  \end{proof}

  \paragraph{7.}
  \begin{proof}
    Let $Y$ and $y_n$ be defined as in the hint. Then $\|y_n\|=1/n^2$,
    constituting a convergent number series. However,
    \[
      \sum_{n=1}^N y_n = (1,1/4, \dots, 1/N^2, 0,\dots),
    \]
    which is divergent as $N\to\infty$.
  \end{proof}

  \paragraph{8.}
  \begin{proof}
    Let $(x_n)$ be a Cauchy sequence in $X$. Hence, for every $n>0$, there
    exists some $K_n>0$ such that for all $p,q>K_n$, $\|x_p-x_q\|<1/n^2$.
    Without loss of generality, we may assume that $(K_n)$ is increasing. Since
    the series $\|x_{K_{n+1}}-x_{K_n}\|$ is bounded by $1/n^2$, it converges.
    By the hypothesis, the series $(x_{K_{n+1}}-x_{K_n})$ also converges. Hence,
    \[
      x_{K_n} = x_{K_1} + \sum_{i=1}^{n-1}(x_{K_{i+1}}-x_{K_i}) \to x
      \quad\text{as } n\to\infty.
    \]\par
    Now we show that $(x_n)$ converges to $x$. For every $\vep>0$, since $(x_n)$
    is a Cauchy sequence, there exists some $N_1$ such that for all $p,q>N_1$,
    $\|x_p-x_q\|<\vep$. Meanwhile, since $x_{K_n}\to x$, once $K_n$ is large
    enough, $\|x-x_{K_n}\|<\vep$. Let $K_n>N_1$. Then for every $n>K_n$
    \[
      \|x_n-x\| \le \|x_n-x_{K_n}\| + \|x_{K_n}-x\| \le 2\vep.
    \]
    Thus, $X$ is complete.
  \end{proof}

  \paragraph{9.}
  \begin{proof}
    Let $(x_n)$ be an absolutely convergent series in Banach space $X$. Let
    $s_n=\sum_{i=1}^n x_n$. Now we show that $s_n$ is a Cauchy sequence and
    therefore convergent. Since $\sum_{i=1}^\infty\|x_i\|<\infty$, for every
    $\vep>0$, there exists some $N>0$ such that for all $n>N$, $\sum_{i=n}
    ^\infty\|x_i\|<\vep$. Hence, for every $N<p\le q$,
    \[
      \|s_q-s_p\| = \left\|\sum_{i=p+1}^q x_i\right\|
      \le \sum_{i=p+1}^q\|x_i\| < \vep,
    \]
    completing the proof.
  \end{proof}

  \paragraph{10.}
  \begin{proof}
    Let $(e_n)$ be Schauder basis of $X$. Denote the underlying field of $X$ by
    $\mathbb{K}$ and let $\mathbb{W}=\mathbb{Q}$ if $\mathbb{K}=\mathbb{R}$ and
    $\mathbb{W}=\{p+iq:\, p,q\in\mathbb{Q}\}$ if $\mathbb{K}=\mathbb{C}$. Now we
    show that
    \[
      S = \left\{\sum_{i=1}^n\alpha_ie_i:\,
      \alpha_i\in\mathbb{W}, n=1,2,\dots\right\},
    \]
    a countable subset of $X$, is dense in $X$ to derive the separability. \par
    For every $x\in X$ and $\vep>0$, by the definition of Schauder basis, there
    exists $\beta_1,\dots,\beta_n\in\mathbb{K}$ such that $\|x-(\beta_1e_1+
    \cdots+\beta_ne_n)\|<\vep$. Let $M=\max_{i}\|e_i\|$. If $M=0$, then there is
    nothing to prove. Otherwise, since $\mathbb{W}$ is dense in $\mathbb{K}$,
    for $i=1,\dots,n$, there exists $\alpha_i\in\mathbb{W}$ with $|\alpha_i-
    \beta_i|<\vep/2^iM$. Hence,
    \begin{align*}
      \left\|x-\sum_{i=1}^n\alpha_ie_i\right\|
      \le& \left\|x-\sum_{i=1}^n\beta_ie_i\right\| +
           \left\|\sum_{i=1}^n(\beta_i-\alpha_i)e_i\right\| \\
      \le& \vep + \sum_{i=1}^n|\alpha_i-\beta_i|\|e_i\|  \\
      \le& 2\vep.
    \end{align*}
    Thus, $S$ is dense in $X$ and therefore $X$ is separable.
  \end{proof}

  \paragraph{14.}
  \begin{proof}
    Clear that $\|\cdot\|_0$ is nonnegative. And $\|\alpha\hat{x}\|_0= \inf_{x
    \in\hat{x}}\|\alpha x\| = |\alpha|\|\hat{x}\|_0$. Meanwhile, $\|\hat{x}+
    \hat{y}\|_0=\inf_{z\in\hat{x}+\hat{y}}\|z\|\le\inf_{z\in\hat{x}}\|z\|+
    \inf_{z\in\hat{y}}\|z\|=\|\hat{x}\|_0+\|\hat{y}\|_0$. Finally, we show that
    $\|\hat{x}\|_0=0$ implies $\hat{x}=Y$ and invoke Prob. 4, Sec 2.2 to
    complete the proof. Since $\|\hat{x}\|_0=0$, there exists $(x_n)\subset
    \hat{x}$ which converges to $0$. Since $Y$ is closed, $Y$ is complete and so
    is its cosets. Therefore, $0\in\hat{x}$, enforcing $\hat{x}$ to be $Y$.
  \end{proof}
% end

\subsection{Finite Dimensional Normed Spaces}
  \paragraph{3.}
  \begin{proof}
    The reflexive property clearly holds. If there are positive $a$ and $b$ such
    that $a\|x\|_0\le\|x\|_1\le b\|x\|_0$ for all $x\in X$, then $\|x\|_1/b\le
    \|x\|_0\le\|x\|/a$. Hence the relation is symmetric. Next we further suppose
    there exists positive $c$ and $d$ such that that $c\|x\|_1\le\|x\|_2\le
    d\|x\|_1$. Then $ac\|x\|_0\le \|x\|_2\le bd\|x\|_0$, giving the transitive
    property. Thus, the axioms of an equivalence relation hold.
  \end{proof}

  \paragraph{4.}
  \begin{proof}
    Suppose the norms $\|\cdot\|$ and $\|\cdot\|_0$ are equivalent. Let $E
    \subset X$ be any open set with respect to $\|\cdot\|$, i.e., for every $x_0
    \in E$, there exists some $\delta>0$ such that $A=\{x\in X:\, \|x-x_0\|<
    \delta\}\subset E$. Since $\|\cdot\|\sim\|\cdot\|_0$, there exists some
    positive $c$ such that $\|x-x_0\|\le c\|x-x_0\|_0$. Hence, $B=\{x\in X:\,
    \|x-x_0\|<\delta/c \}\subset A\subset E$. Namely, $E$ is also open with
    respect to $\|\cdot\|_0$. Interchanging the roles of $\|\cdot\|$ and
    $\|\cdot\|_0$ completes the proof.
  \end{proof}

  \paragraph{5.}
  \begin{proof}
    Suppose the norms $\|\cdot\|$ and $\|\cdot\|_0$ are equivalent. Then for
    every $x\in X$, there exists some $c>0$ such that $\|x\|_0\le c\|x\|$. Let
    $(x_n)$ be a Cauchy sequence with respect to $\|\cdot\|$, i.e., for every
    $\vep>0$, there exists some $N>0$ such that for all $n,m>N$, $\|x_n-x_m\|<
    \vep/c$. Hence, $\|x_n-x_m\|_0<c\|x_n-x_m\|\le \vep$. Thus, $(x_n)$ is also
    a Cauchy with respect to $\|\cdot\|_0$. Interchanging the roles of
    $\|\cdot\|$ and $\|\cdot\|_0$ completes the proof.
  \end{proof}
% end

\subsection{Compactness and Finite Dimension}
  \paragraph{5.}
  \begin{proof}
    Clear that every point in $\mathbb{R}^n$ or $\mathbb{C}^n$ has a closed
    bounded, and therefore compact, neighborhood. Hence, $\mathbb{R}^n$ and
    $\mathbb{C}^n$ are locally compact.
  \end{proof}

  \paragraph{6.}
  \begin{proof}
    Let $X$ be a compact metric space and $x$ any point in $X$. Let $E$ be a
    closed neighborhood of $x$. By Prob 10, $E$ is compact. Thus, $X$ is locally
    compact.
  \end{proof}

  \paragraph{7.}
  \begin{proof}
    It suffices to show that $a=\inf_{y\in Y}\|v-y\|$ can actually be obtained.
    Let $\{b_1,\dots,b_n\}$ be a basis of $Y$ and $y_k=y_{k,1}b_1+\cdots+y_{k,n}
    b_n$ a sequence in $Y$ with $\|v-y_k\|\to a$. We may assume without loss of
    generality that $\|v-y_k\|$ is bounded. \par
    Since $Y$ is a proper subset of $Z$, $v,b_1,\dots,b_n$ are linearly
    independent. Therefore, by Lemma 2.4-1, there exists a scalar $c>0$ such
    that for every $k$,
    \[
      \|v-y_{k,1}b_1-\cdots-y_{k,n}b_n\| \ge c(1+|y_{k,1}|+\cdots+|y_{k,_n}|).
    \]
    Hence, the sequence $(y_{k,1},\dots,y_{k,n})$ of $n$-tuples is bounded and
    therefore has a convergent subsequence. Consequently, $(y_k)$ also has a
    convergent subsequence. Suppose that it converges to $z\in Z$. Note that
    $\|v-z\|=a$ and as $Y$ is closed, $z\in Y$. Thus, $a$ can be attained in
    $Y$.
  \end{proof}

  \paragraph{8.}
  \begin{proof}
    Since the unit ball $B$ with respect to $\|\cdot\|_2$ in $\mathbb{R}^n$ and
    $\mathbb{C}^n$ is compact and $\|\cdot\|$ is continuous, by 2.5-7, $x\mapsto
    \|x\|$ can attains its minimum, denoted by $a$, on $B$. Due to the positive
    definite property of a norm, $a$ is positive. Hence, $0<a\le \|x/\|x\|_2\|$.
    Namely, $a\|x\|_2\le\|x\|$.
  \end{proof}

  \paragraph{9.}
  \begin{proof}
    For every $(x_n)\subset M\subset X$, since $X$ is compact, there exists a
    subsequence $(x_{n_k})$ of $(x_n)$ which converges to some $y\in X$. Since
    $M$ is closed, $y\in M$. Hence, $M$ is compact.
  \end{proof}

  \paragraph{10.}
  \begin{proof}
    From 1.3-4 and the definition of closed sets, we conclude that a mapping is
    continuous iff the preimage of a closed set under it is also a closed set.
    Hence, to show that the inverse of $T$ is also continuous, it suffices to
    show that the image of a closed set $A\subset X$ under $T$ is again a closed
    set. Since $X$ is compact and $A$ is closed, $A$ is compact. Since $T$ is
    continuous, by 2.5-6, $T(A)$ is compact and therefore closed. Hence, $T$ is
    a homeomorphism.
  \end{proof}
% end

\setcounter{subsection}{6}
\subsection{Bounded and Continuous Linear Operators}
  \paragraph{2.}
  \begin{proof}
    First suppose $T$ to be bounded and let $A$ be any bounded set in $X$. Then
    there exists $K<\infty$ such that for all $x\in A$, $\|x\|<K$. Due to the
    boundedness of $T$, $\|Tx\|\le \|T\|\|x\|<K\|T\|$. Namely, $T(A)$ is also
    bounded.\par
    Now suppose that $T$ maps bounded sets in $X$ into bounded sets in $Y$.
    Clear that the unit ball $B$ of $X$ is bounded and therefore so is $T(B)$.
    Namely, $\|Tx/\|x\|\|$ is bounded for $x\ne 0$.\footnote{Note that the two
    $\|\cdot\|$ here are different norms.} Hence, $T$ is bounded.
  \end{proof}

  \paragraph{3.}
  \begin{proof}
    For every $x$ with $\|x\|<1$, $\|Tx\|\le \|T\|\|x\|<\|T\|$.
  \end{proof}

  \paragraph{4.}
  \begin{proof}
    Suppose that the linear operator $T$ is continuous at $x_0\in
    \mathcal{D}(T)$. For every $(x_n)\subset\mathcal{D}(T)$ with $\|x_n-x\|\to
    0$, by the continuity of $T$ at $x_0$
    \[
      \|Tx_n-Tx\|=\|T(x_n-x+x_0)-Tx_0\| \to 0.
    \]
    Hence, $T$ is continuous.
  \end{proof}

  \paragraph{7.}
  \begin{proof}
    The inequality implies $\mathcal{N}(T)=0$. Hence, by Theorem 2.6-10, $T\inv$
    exists. For every $y\in Y$, suppose that $y=Tx$. Then
    \[
      \|T\inv y\| = \|x\| \le \frac{1}{b}\|Tx\| = \frac{1}{b}\|y\|.
    \]
    Thus, $T\inv$ is bounded.
  \end{proof}

  \paragraph{12.}
  \begin{proof}
    The compatibility follows immediately from the definition of the supremum.
    Suppose $\|x\|_1=\max_j|\xi_j|$ and $\|y\|_2=\max_j\|\eta_j\|$, then
    \[
      Ax =
      \begin{bmatrix}
        x_1\alpha_{11} + \cdots + x_n\alpha_{1n} \\
        \vdots \\
        x_1\alpha_{r1} + \cdots + x_n\alpha_{rn}.
      \end{bmatrix}
    \]
    Since for all $j$, $x_j\le \|x_j\|_1$,
    \[
      \frac{\max_j|x_1\alpha_{j1}+\cdots+x_n\alpha_{jn}|}{\|x\|_1}
      =\max_j\left|\frac{x_1}{\|x\|_1}\alpha_{j1}+\cdots
      +\frac{x_n}{\|x\|_1}\alpha_{jn}\right|
      \le \max_{j}\sum_{k=1}^n|\alpha_{jk}|.
    \]
    Hence,
    \begin{equation}
      \label{eq:2.8.12}
      \|A\|\ge \frac{\|Ax\|_2}{\|x\|_1} \quad\text{for all $x$}.
    \end{equation}
    Suppose that maximum of $\sum_{k=1}^n|\alpha_{jk}|$ is obtained at $j=p$.
    Then choosing $x_k$ to be $\sgn \alpha_{pk}$ shows that the equality in
    \eqref{eq:2.8.12} can actually be attained. Hence, $\|A\|=\max_{j}
    \sum_{k=1}^n|\alpha_{jk}|$.
  \end{proof}
% end

\subsection{Linear Functionals}
  \paragraph{8.}
  \begin{proof}
    For every $x_1,x_2\in N(M^*)$, $a,b\in\mathbb{K}$ and $f\in M^*$,
    \[
      f(ax_1+bx_2) = af(x_1)+bf(x_2) = 0.
    \]
    Hence, $ax_1+bx_2\in N(M^*)$. Namely, $N(M^*)$ is a vector space.
  \end{proof}

  \paragraph{9.}
  \begin{proof}
    First we show the uniqueness. Suppose that $x=\alpha_1x_0+y_1=\alpha_2x_0+
    y_2$. Then $0 = (\alpha_1-\alpha_2)x_0 + (y_1-y_2)$. Hence,
    \[
      0 = f((\alpha_1-\alpha_2)x_0 + (y_1-y_2)) =
      (\alpha_1-\alpha_2)f(x_0) + f(y_1)-f(y_2).
    \]
    Since $y_1,y_2\in\mathcal{N}(f)$, $f(y_1)-f(y_2)=0$ while $f(x_0)\ne 0$ as
    $x_0\notin\mathcal{N}(f)$. Hence, $\alpha_1=\alpha_2$, which forces $y_1$
    and $y_2$ to coincide.\par
    For the existence, it suffices to show that for any fixed $x$, the function
    $g(\alpha)=f(x-\alpha x_0)$ has a zero. It is easy to verify that $\alpha=
    f(x)/f(x_0)$ is a zero of $g$. Note that $x_0\notin\mathcal{N}(f)$ and
    therefore $f(x_0)\ne 0$.
  \end{proof}

  \paragraph{10.}
  \begin{proof}
    First we suppose that $x_1,x_2\in x_0+\mathcal{N}(f)\in X/\mathcal{f}$. Then
    together with Prob. 9, $x_i=x_0+y_i$ where $y_i\in\mathcal{N}(f)$. Hence,
    for $i=1,2$, $f(x_i)=f(x_0)+f(y_i)=f(x_0)$.\par
    For the converse, note that $f(x_1)=f(x_2)$ implies $f(x_1-x_2)=0$. Namely,
    $x_1-x_2\in\mathcal{N}(f)$. Hence, $x_1,x_2$ belongs to the same element in
    $X/\mathcal{N}(f)$.\par
    To show $\codim\mathcal{N}(f)=1$, we show that $X/\mathcal{N}(f)$ and
    $\mathbb{K}$ are isomorphic. For every $\hat{x}\in X/\mathcal{N}(f)$, define
    $I(\hat{x})=f(x)$. By the previous discussion, this definition is
    well-defined. Clear that $I$ is linear and therefore is injective. And by
    the linearity of $f$, $I$ is surjective. Thus, $I$ is an isomorphism between
    $X/\mathcal{N}(f)$ and $\mathbb{K}$. Hence, $\codim\mathcal{N}(f)=1$.
  \end{proof}

  \paragraph{11.}
  \begin{proof}
    Put $N=\mathcal{N}(f_1)=\mathcal{N}(f_2)$ and choose $x_0\in X\setminus N$.
    By Prob. 9, for every $x\notin N$, $x=\alpha x_0+y$ where $y\in N$ and
    $\alpha\ne 0$. Hence,
    \[
      \frac{f_1(x)}{f_2(x)} =
      \frac{\alpha f_1(x_0)+f_1(y)}{\alpha f_2(x_0)+f_2(y)} =
      \frac{f_1(x_0)}{f_2(x_0)}.
    \]
  \end{proof}

  \paragraph{12.}
  \begin{proof}
    Prob. 10, justifies the discussion on hyperplanes parallel to the
    $\mathcal{N}(f)$. It suffices to show that $H_1=b+\mathcal{N}(f)$ for some
    $b\in X$. Choose $x_1\in H_1$. Then
    \[
      x\in \mathcal{N}(f) \:\Leftrightarrow\:
      x+x_1\in x_1+\mathcal{N}(f) \:\Leftrightarrow\:
      f(x+x_1) = f(x)+f(x_1) = 1 \:\Leftrightarrow\:
      x+x_1\in H_1.
    \]
    Hence, $H_1=x_1+\mathcal{N}(f)$. Namely, $H_1$ is a hyperplane parallel to
    $\mathcal{N}(f)$.
  \end{proof}

  \paragraph{13.}
  \begin{proof}
    We argue by contradiction. Assume that there exists a $y_1\in Y$ such that
    $f(y_1)\ne c\ne 0$. Then for every $d\in\mathbb{K}$, by the linearity of
    $f$, $f(dy_1/c) = d$. Contradiction. Hence, $f=0$ on $Y$.
  \end{proof}

  \paragraph{14.}
  \begin{proof}
    For every $\vep>0$, there exists $x_1\in X$ with $f(x_1)=1$ such that
    $\tilde{d}+\vep\ge\|x_1\|$. Hence,
    \[
      \|f\|(\tilde{d}+\vep)\ge\|f\|\|x_1\| \ge |f(x_1)| = 1.
    \]
    Since the choice of $\vep>0$ is arbitrary, $\|f\|\tilde{d}\ge 1$. Meanwhile,
    there exists $x_2\in X$ with $\|x_2\|=1$ such that $|f(x_2)|\ge \|f\|-\vep$.
    Put $x_3 = x_2/f(x_2)$. Then $f(x_3)=1$. Hence,
    \[
      (\|f\|-\vep)\tilde{d} \le |f(x_2)|\|x_3\| = \|x_2\| = 1,
    \]
    which implies $\|f\|\tilde{d}\le 1$. Thus, $\|f\|\tilde{d}=1$.
  \end{proof}

  \paragraph{15.}
  \begin{proof}
    For every $x$ with $\|x\|\le 1$, $f(x)\le \|f\|\|x\|\le c$. Hence, $x\in
    X_{c_1}$. Meanwhile, for every $\vep>0$, by the definition of the supremum,
    there exists a $x$ with $\|x\|=1$ such that $|f(x)|>\|f\|-\vep$. By the
    linearity of $f$, we may remove the $|\cdot|$ on the right side. Hence,
    $f(x)\notin X_{c_1}$ where $c=\|f\|-\vep$.
  \end{proof}
% end

\subsection{Operators on Finite Dimensional Spaces}
  \paragraph{8.}
  \begin{proof}
    Let $\{b_2,\dots,b_n\}$ be a basis of $Z$ and $\{b_1,\dots,b_n\}$ a basis of
    $X$. Define $f\in X^*$ to be $f(b_i)=\delta_{1i}$. Clear that $\mathcal{N}
    (f)=Z$. By Prob. 11, Sec 2.8, $f$ is uniquely determined up to a scalar
    multiple.
  \end{proof}

  \paragraph{12.}
  \begin{proof}
    Let $\varphi:X\to\mathbb{K}^p$ be defined by $x\mapsto [f_1(x),\dots,
    f_p(x)]^T$. It can be verified that $\varphi$ is a linear operator. Since
    $\dim X=n>p$, $\varphi$ can not be injective. Hence, there exists $0\ne x\in
    X$ such that $\varphi(x)=0$.
  \end{proof}

  \paragraph{13.}
  \begin{proof}
    Let $\{b_1,\dots,b_m\}$ be a basis of $Z$ and $\{b_1,\dots,b_n\}$ a basis of
    $X$. Define $\tilde{f}\in X^*$ to be identical with $f$ on $b_1,\dots,b_m$
    and $0$ on $b_{m+1},\dots,b_n$. Clear that $\tilde{f}|_Z=f$.
  \end{proof}
% end

\subsection{Normed Spaces of Operators. Dual Space}
  \paragraph{8.}
  \begin{proof}
    First we construct a linear bijection $T$ between $c_0\hp$ and $l^1$. A
    Schauder basis for $c_0$ is $(e_k)$, where $e_k=(\delta_{kj})$. Then for
    every $f\in c_0\hp$, define $Tf=(\gamma_k)=(f(e_k))$. Clear that $T$ is
    linear. Now we show that $Tf=(\gamma_k)\in l^1$, that is, $\sum_{k=1}^n|
    \gamma_k|$ is bounded and therefore convergent. Define $x_n=(\xi_k^{(n)})$
    with
    \[
      \xi_k^{(n)}=\begin{cases}
        \sgn\gamma_k, & k\le n, \\
        0,            & k>n.
      \end{cases}
    \]
    Clear that $x_n\in c_0$. By the linearity and boundedness of $f$,
    \begin{equation}
      \label{eq:2.10.8}
      f(x_n)=\sum_{k=1}^\infty \xi_k^{(n)}\gamma_k = \sum_{k=1}^n|\gamma_k|.
    \end{equation}
    Since $f$ is bounded, $|f(x_n)| \le \|f\|\|x_n\| \le \|f\|$. Hence, $\sum\|
    \gamma_k\|$ is bounded. Thus, $Tf\in l^1$.\par
    Meanwhile, for every $y=(\beta_k)\in l^1$, define $Sy=g$ to be the
    functional $g(x)=\sum_{k=1}^\infty\xi_k\beta_k$ for $x=(\xi_k)$. On $c_0$,
    the summation does converge and clear that $g$ is linear and bounded. Hence,
    $g\in c_0\hp$. It can be verify that $ST=TS=I$ and $T$ is linear. Thus, $c_0
    \hp$ and $l^1$ is isomorphic.\par
    Now we show that $T$ constructed preserve the norm to complete the proof.
    For $x\in c_0$ with $\|x\|=1$,
    \[
      |f(x)| = \left|\sum_{k=1}^\infty \xi_k\gamma_k\right|\le
      \sum_{k=1}^\infty |\gamma_k| = \|Tf\|.
    \]
    Hence, $\|f\|\le\|Tf\|$. And \eqref{eq:2.10.8} implies $\sum_{k=1}^n||\gamma
    |\le \|f\|$. Letting $n\to\infty$ yields $\|Tf\|\le \|f\|$. Thus, $\|Tf\|=
    \|f\|$.
  \end{proof}

  \paragraph{9.}
  \begin{proof}
    Let $(b_k)$ be a Hamel basis of $X$ and suppose that $f,g\in X^*$ coincide
    on every $b_k$. Then for every $x=\sum_{k=1}^\infty\xi_k b_k\in X$,
    \[
      f(x)-g(x) = \sum_{k=1}^n\xi_k(f(b_k)-g(b_k)) = 0.
    \]
    Thus, $f=g$. Namely, $f$ is uniquely determined.
  \end{proof}

  \paragraph{10.}
  \begin{proof}
    Let $(b_k)$ be a Hamel basis of $X$ and without loss of generality we may
    assume $\|b_k\|=1$. Justified by Prob. 9, we can define $T\in X^*$ with
    $Tb_k=k$, which is clearly unbounded.
  \end{proof}

  \paragraph{11.}
  \begin{proof}
    It follows immediately from Prob. 10.
  \end{proof}

  \paragraph{13.}
  \begin{proof}
    For any $f,g\in M^a$ and scalar $a,b$, $(af+bg)(x)=af(x)+bg(x)=0$ for every
    $x\in M$. Hence, $M^a$ is a vector space. For $(f_n)\subset M^a\subset
    X\hp$, suppose that $f_n\to f\in M^*$. Since $M\hp$ is complete, it is
    closed and therefore $f\in M\hp$. For every $0\ne x\in M$, since $f_n\to f$,
    \[
      \frac{|f_n(x)-f(x)|}{\|x\|} \to 0,\,\text{as $n\to\infty$}.
    \]
    Hence, $f(x)=0$. Thus, $M^a$ is closed.\par
    $X^a = \{0\}$ and $\{0\}^a = X\hp$.
  \end{proof}

  \paragraph{14.}
  \begin{proof}
    Let $\{b_1,\dots,b_m\}$ be a basis of $M$ and $\{b_1,\dots,b_n\}$ a basis of
    $X$. And let $\{\beta_1,\dots,\beta_n\}$ be the dual basis. Clear that $b_1,
    \dots,b_m\notin M^a$ whereas $b_{m+1},\dots,b_n$ does. Together with Prob.
    13, this implies $M^a=\spn(b_{m+1},\dots,b_n)$. Thus, $\dim M^a = n-m$.
  \end{proof}
% end