\documentclass[aspectratio=149]{beamer}

\input{../../shared_slides.tex}
\usepackage{bbm}
\newcommand{\G}{\mathcal{G}}
\renewcommand{\D}{\mathcal{D}}

\title{Matrix games}
\subtitle{and more general min-max problems}
\date{\today}

\begin{document}
\maketitle
\frame{\tableofcontents}

\section{Introduction}%

\begin{frame}
  \frametitle{Introduction}
  Given
  \begin{itemize}
    \item Player I (rows, Alice)
          \item Player II (columns, Bob)
          \item a \emph{payoff} matrix $A \in \R^{m \times n}$
  \end{itemize}
  Every round
  \begin{enumerate}
    \item Alice picks (row) strategy $i\in [m]:= \{1,\dots, m\}$\\
          Bob picks (col) strategy $j\in [n]$
    \item Bob pays Alice the amount $a_{i,j}$
  \end{enumerate}
  \begin{center}
    \textbf{zero-sum game}
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Example: penalty game}
  \begin{figure}[ht]
    \centering
    \includegraphics[scale=0.4]{penalty-game}
    \caption{penalty game}
  \end{figure}
\end{frame}

\begin{frame}
  \frametitle{Example: prisoners dilemma}
  \begin{figure}[ht]
    \centering
    \includegraphics[width=0.5\textwidth]{prison}
    \caption{prisoners dilemma (not zero-sum)}
  \end{figure}
\end{frame}

\begin{frame}
  \frametitle{Worst case}

  \begin{itemize}
    \item if Alice chooses strategy $i$ she gets (at least): $\min_{j\in [n]} a_{i,j}$
    \item Alice can ensure payoff $\max_{i\in [m]} \min_{j\in [n]} a_{i,j}$
    \item Bob pays (at most) $\min_{j\in [n]} \max_{i\in [m]} a_{i,j}$
  \end{itemize}
  \onslide<2->{%
    We claim:
    \begin{equation}
      \max_i \min_j a_{i,j} \le \min_{j} \max_i a_{i,j}
    \end{equation}
    \begin{center}
      \textit{``Tallest dwarf is not as tall as the smallest giant.''}
    \end{center}
    But: \textbf{No equality in general!}
  }
\end{frame}

\begin{frame}
  \frametitle{Proof of the min-max theorem}
  \begin{equation}
    \begin{aligned}
      a_{ij} &\le a_{ij} & \forall i,j \\
      a_{ij} &\le \max_i a_{ij} & \forall i,j\\
      \min_j a_{ij} &\le \min_j \max_i a_{ij} & \forall i\\
    \end{aligned}
  \end{equation}
  \onslide<2->{%
  \begin{definition}
    We call $(i^*, j^*)$ a saddle point (or \emph{Nash equilibrium}) if
    \begin{equation}
      \max_i a_{ij^*} = a_{i^*j^*} = \min_j a_{i^*j}.
    \end{equation}
    These are called \emph{pure strategies}.
  \end{definition}
  }
\end{frame}

% Talk about stackelberg?

\begin{frame}
  \frametitle{Rock paper scissors}
  \begin{equation}
    \begin{array}{l|ccc}
        & R & P & S \\
      \hline
      R & 0 & -1 & 1 \\
      P & 1 & 0 & -1 \\
      S & -1 & 1 & 0
    \end{array}
  \end{equation}
  \begin{center}
    \textbf{No saddle-point!}
  \end{center}
  \vspace{1cm}
  \onslide<2->{%
    \center\textit{With pure strategies we do not always have a saddle point.}
  }

\end{frame}

\begin{frame}
  \frametitle{Mixed Strategies}
  \begin{block}{von Neumann (1928) --- Mixed strategies}
    \begin{itemize}
      \item Alice picks strategies $1, \dots, m$ \emph{with probabilities} $x\in \Delta_m$
      \item Bob picks strategies $1, \dots, n$ \emph{with probabilities} $y\in \Delta_n$
    \end{itemize}
    Expected gain of Alice is
    \begin{equation}
      \langle Ax, y \rangle = \sum_{i,j} a_{ij} x_i y_j
    \end{equation}
  \end{block}
  \onslide<2->{%
    \begin{theorem}[Saddle point exists]
      Expected gain of Alice $=$ expected loss of Bob
      \begin{equation}
        \max_{x \in \Delta} \min_{y \in \Delta} \langle Ax, y \rangle = \min_{y \in \Delta} \max_{x \in \Delta} \langle Ax, y \rangle.
      \end{equation}

    \end{theorem}
  }
\end{frame}

\section{Algorithms}%
\label{sec:}

\begin{frame}
  \frametitle{Stopping criteria}
  \begin{equation}
    \begin{aligned}
      \min_{x \in \Delta} \,\underbrace{\max_{y \in \Delta} \langle Ax, y \rangle}_{f_p(x)} =: \bm{v}  = \max_{y \in \Delta} \, \underbrace{\min_{x \in \Delta} \langle Ax, y \rangle}_{f_d(y)}
    \end{aligned}
  \end{equation}
  \begin{block}{stopping criterion}
    \begin{equation}
      \begin{aligned}
        f_p(x) - f_p(x^*) &= f_p(x) - v \onslide<2->{\textcolor{red}{\, \le \epsilon/2}}\\
        f_d(y^*) - f_d(y) &= v - f_d(y) \onslide<2->{\textcolor{red}{\, \le \epsilon/2}} \\
        \onslide<2->{\Rightarrow f_p(x) - f_d(y) \le \epsilon}
      \end{aligned}
    \end{equation}
  \end{block}
  \onslide<2->{%

  \begin{center}
    Before we never had the optimal value!
  \end{center}
  \textcolor{gray}{
  $f_p$ and $f_d$ is easy to compute (solution is on the boundary):
  \begin{equation}
    f_p(x) = \max_{y \in \Delta} \, \langle A x, y \rangle = \max_{j} \, \langle A x, e_j \rangle
  \end{equation}}
  }
\end{frame}

\begin{frame}
  \frametitle{}
  Consider
  \begin{equation}
      \min_{x \in \Delta}\,  \max_{y \in \Delta} \, \langle Ax, y \rangle
  \end{equation}
  as a minimization problem
  \begin{equation}
      \min_{x \in \Delta}\,   f_p(x) = \langle x, A^T y^* \rangle .
  \end{equation}
  Then, by the \textbf{first-order optimality condition}
  \begin{equation}
    x^* \in \argmin_{x \in \Delta}\,  f_p(x)  \Leftrightarrow \langle \nabla f_p(x^*), x-x^* \rangle \ge 0 \quad \forall x \in \Delta
  \end{equation}
  Thus
  \begin{equation}
    \begin{aligned}
      \langle A^T y^*, x-x^* \rangle &\ge 0 \quad \forall  x \in \Delta \\
      \langle -A x^*, y-y^* \rangle &\ge 0 \quad \forall  y \in \Delta \\
    \end{aligned}
  \end{equation}
  Concatenate the two conditions to get
  \begin{equation}
  \left\langle \begin{bmatrix}
      0 & A^T \\
      -A & 0
    \end{bmatrix}
    \left(\begin{array}{c}
      x^*\\ y^*
    \end{array}  \right),
    \left(\begin{array}{c}
      x \\ y
    \end{array}  \right)
    - % chktex 8
    \left(\begin{array}{c}
      x^* \\
      y^*
    \end{array} \right)
 \right\rangle \ge 0. % chktex 1
  \end{equation}
\end{frame}

\begin{frame}
  \frametitle{Games as Variational Inequalities}
  We had:
  \begin{equation}
  \left\langle \begin{bmatrix}
      0 & A^T \\
      -A & 0
    \end{bmatrix}
    \left(\begin{array}{c}
      x^*\\ y^*
    \end{array}  \right),
    \left(\begin{array}{c}
      x \\ y
    \end{array}  \right)
    - % chktex 8
    \left(\begin{array}{c}
      x^* \\
      y^*
    \end{array} \right)
 \right\rangle \ge 0. % chktex 1
  \end{equation}
  By rewriting $z=(x,y)$ and $F(z) = [A^T y; -Ax]$, then
  \begin{equation}\tag{VI}
    \label{eq:VI}
    \langle F(z^*), z-z^* \rangle \ge 0 \quad \forall z \in \Delta_n \times \Delta_m =: C
  \end{equation}
  \begin{center}
    \textbf{Variational inequality}
  \end{center}

  \begin{block}{}
  If $F = \nabla \phi$ then~\eqref{eq:VI} would be equivalent to
  \begin{equation}
    \min_{z\in C} \, \phi(z)
  \end{equation}
  \end{block}
\end{frame}

\begin{frame}
  \frametitle{Potential --- integrability}

  \textbf{Question:} Does there exist a potential $\phi$ for $F$, such that $F = \nabla \phi$

  \begin{block}{Integrability condition (from calculus)}
    Is the case if
    \begin{equation}
      \frac{\partial \phi}{\partial x \partial y} = \frac{\partial \phi}{\partial y \partial x}
    \end{equation}
  \end{block}
  But
  \begin{equation}
    \frac{\partial F_1}{\partial y} = \frac{\partial}{\partial y} A^T y = A^T \neq - A = \frac{\partial}{\partial x} -Ax =\frac{\partial F_2}{\partial x}.
  \end{equation}
  \textcolor{gray}{Recall
    \begin{equation}
      F = \begin{bmatrix}
      0 & A^T \\
      -A & 0
    \end{bmatrix}.
    \end{equation}}
\end{frame}

\begin{frame}
  \frametitle{VI as Fixed point equation}
  \begin{block}{}
    \vspace{-0.5cm}
  \begin{align}
    \langle F(z^*), z-z^* \rangle \ge 0 \quad \forall z \in C \\
    \Leftrightarrow z^* = P_C (z^* - F(z^*)) \label{eq:FP}\tag{FP}
  \end{align}
  \end{block}
  \begin{proof}
    Applying the property of the projection
    \begin{equation}
      \langle P_C(x)-x, x' - P_C(x) \rangle \ge 0 \quad \forall x' \in C
    \end{equation}
    with~\eqref{eq:FP}, gives
    \begin{equation}
    \langle z^* - (z^* - F(z^*)), z-z^* \rangle \ge 0 \quad \forall z \in C.\hfill \qedhere\qed
    \end{equation}
  \end{proof}
  \begin{itemize}
    \item should remind us of (projected) gradient descent
          \item when you see a \textbf{\textcolor{blue}{fixed point equation: iterate!}}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{But is it any good?}
  Consider the \textbf{unconstrained case}
  \begin{equation}
    \langle F(z^*), z-z^* \rangle \ge 0 , \, \forall z  \quad \Leftrightarrow \quad F(z^*) = 0.
  \end{equation}
  \begin{equation}
    z_{k+1} = z_k - \alpha F(z_k)
  \end{equation}
  Then
  \begin{equation}
    \begin{aligned}
      \Vert z_{k+1} \Vert^2 &= \Vert z_k \Vert^2 - \underbrace{2 \alpha \langle F(z_k), z_k \rangle}_{=0} + \alpha^2 \Vert F(z_k) \Vert^2 \\
      &=\Vert z_k \Vert^2 + \alpha^2 \Vert F(z_k) \Vert^2 \\
    \end{aligned}
  \end{equation}
  Resulting in $\Vert z_{k+1} \Vert \ge \Vert z_k \Vert$.
  \begin{center}
    $\Rightarrow$ \textbf{No bueno!}
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{}

We can still show
  \begin{theorem}
    Convergence rate for \textbf{averaged iterates} in terms of \textbf{primal-dual gap}
    \begin{equation}
      f_p(\bar{x}_k) - f_d(\bar{y}_k) \le \frac{C}{ \sqrt{k}},
    \end{equation}
    where $\bar{x}_k = \frac{1}{k} \sum_{i=0}^{k-1} x_i $
  \end{theorem}

  \begin{itemize}
    \item with the same analysis as for subgradient descent
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Sketch of the proof}
  With the notation $g_k = F(z_k)$ we get
  \begin{equation}
    \begin{aligned}
      \Vert x_{k+1} - x^* \Vert^2 &\le \Vert x_k - \alpha_k g_k - x^* \Vert^2 \\
      &= \Vert x_k-x^* \Vert^2 + 2 \alpha_k \langle g_k, x^*-x_k \rangle + \alpha^2 \Vert g_k \Vert^2.
    \end{aligned}
  \end{equation}
  But this time $\langle g_k, x^* - x_k \rangle = [f_d(y_k) - f_p(x_k)]$.
  % Rest of the proof is left as an exercise.
\end{frame}

\begin{frame}
  \frametitle{A better method}

  \begin{algorithm}[H]
    \caption{Extragradient Method [1976]}
    \begin{algorithmic}[1]
      \For{$k = 1,2, \dots$}
      \State{ $w_{k+1} = z_k  - \alpha_k F(z_k)$}
      \State{ $z_{k+1} = z_k  - \alpha_k F(w_k)$}
      \EndFor{}
    \end{algorithmic}
  \end{algorithm}

  \begin{itemize}
    \item more conservative
    \item works for general min-max problems
          \begin{equation}
            \min_x \max_y \, \Phi(x,y) \quad \Rightarrow F(x,y) = {(\nabla_x \Phi(x,y), - \nabla_y \Phi(x,y))}^T
          \end{equation}
    \item can even improve behavior of pure minimization ($F = \nabla f$)
    \item improved rate of $\mathcal{O}(1/k)$ for averaged iterates
  \end{itemize}
\end{frame}

\section{More min-max problems}%
\label{sec:}

\begin{frame}
  \frametitle{Robust Optimization}
  \begin{itemize}
    \item uncertainty in the \textbf{objective} ($u \in U$ \text{ \textcolor{blue}{uncertainty set}})
          \begin{equation}
            \min_x f(x, u)
          \end{equation}
    \item bound the \textbf{worst case}
          \begin{equation}
            \min_x \max_{u \in U}\, f(x, u)
          \end{equation}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Vulnerability of Neural Networks}
  \begin{minipage}{0.45\textwidth}
    \begin{figure}[ht]
      \centering
      \includegraphics[width=\textwidth,keepaspectratio]{vulnerable3}
      % \caption{\label{fig:label} }
    \end{figure}
  \end{minipage}
  \begin{minipage}{0.5\textwidth}
    \begin{figure}[ht]
      \centering
      \includegraphics[width=\textwidth,keepaspectratio]{vulnerable4}
    \end{figure}
  \end{minipage}

  \begin{figure}[ht]
    \centering
    \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{adversarial-example}
    \caption{$\epsilon=0.007$}
  \end{figure}
\end{frame}

\begin{frame}
  \frametitle{Vulnerability in ``real life''}
  \begin{figure}[ht]
    \centering
    \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{washer}
  \end{figure}
\end{frame}

\begin{frame}
  \frametitle{Generation of adversarial examples}
  \begin{block}{Training objective}
    \begin{equation}
      \min_\theta J(\theta, x, y)
    \end{equation}
    \begin{itemize}
      \item $\theta$ parameters (weights, biases)
      \item $x$ images
      \item $y$ corresponding labels
    \end{itemize}
  \end{block}
  \begin{block}{Attack direction (``white box'')}
    \begin{equation}
      \nabla_x J(\theta, x, y)
    \end{equation}
  \end{block}
  Typically only the sign is used.
\end{frame}

\begin{frame}
  \frametitle{Adversarial training}

  \begin{block}{Augment training data with adversarial examples}
    \begin{itemize}
      \item grab a fresh training example $x$
      \item perturb image: $\tilde{x} \leftarrow x - \epsilon \text{sign}(\nabla_x J(\theta, x, y))$
      \item update weights:  $\theta \leftarrow \theta - \nabla_\theta J(\theta, \tilde{x}, y)$
    \end{itemize}
  \end{block}

  Corresponds to solving the robust \textcolor{blue}{min-max} problem
  \begin{align}
    &\min_\theta \max_{\tilde{x}} \, J(\theta, \tilde{x}, y) \\
    &\text{s.t. } \Vert \tilde{x}-x \Vert_\infty \le \epsilon
  \end{align}
\end{frame}

\begin{frame}
  \frametitle{GANs}
  \begin{figure}[ht]
    \centering
    \includegraphics[width=\textwidth]{GAN_quote.png}
    % \caption{\label{fig:label} }
  \end{figure}
\end{frame}

\begin{frame}
  \frametitle{What do they \emph{generate}?}
    \begin{figure}[ht]
      \centering
      \begin{subfigure}[c]{.45\textwidth}
        \includegraphics[width=\linewidth]{one_does_not_simply.jpg}
      \end{subfigure}
      \begin{subfigure}[c]{.52\textwidth}
        \includegraphics[width=\linewidth]{paper_generating_memes.png}
      \end{subfigure}
    \end{figure}
\end{frame}

\begin{frame}
  \frametitle{How did they do?}
  \begin{figure}[ht]
    \centering
    \includegraphics[width=\textwidth]{generated_memes.jpg}
  \end{figure}
\end{frame}

\begin{frame}
  \frametitle{More serious applications (inpainting)}
  \begin{figure}[ht]
    \centering
    \includegraphics[scale=0.4]{inpainting}
    % \caption{\label{fig:label} }
  \end{figure}
\end{frame}

\begin{frame}
  \frametitle{Or less serious\ldots}

    \begin{figure}[ht]
      \centering
      \includegraphics[width=\textwidth]{inpainting_beach}
      % \caption{\label{fig:label} }
    \end{figure}
\end{frame}

\begin{frame}
  \frametitle{Creating Art}

    \begin{figure}[ht]
      \centering
      \begin{subfigure}[c]{.47\textwidth}
        \includegraphics[width=\linewidth]{GAN_price}
      \end{subfigure}
      \begin{subfigure}[c]{.47\textwidth}
        \includegraphics[width=\linewidth]{expensive_GAN}
      \end{subfigure}
    \end{figure}
\end{frame}

\begin{frame}
  \frametitle{Why Adversarial?}
  Two NNs trained at the same time.
  \begin{figure}[ht]
    \centering
    \includegraphics[width=.95\textwidth]{GAN}
    % \caption{\label{fig:label} }
  \end{figure}
\end{frame}

\begin{frame}
  \frametitle{GANs mathematically}
  Given by the \textcolor{blue}{\emph{two-player game}}.
  \begin{equation}
    \min_{\G} \max_{\D} \, \E_{x\sim p_{data}} [\log(\D(x))] + \E_{z\sim p_{noise}}
    [\log(1- \D(\G(z)))]
  \end{equation}
  where
  \begin{itemize}
    \item $p_{z}(z)$ is the input noise variable,
    \item $\G$ is the \emph{generator},
    \item $\D$ is the \emph{discriminator}.
  \end{itemize}
  \begin{block}{}
    Discriminator gives probability that $x$ came from the (true) data rather than
    from the generator.
  \end{block}
\end{frame}

\end{document}


\section{Testing and findings}
\label{sec:testing-findings}
There have been some test to identify the impact of certain adjustments which have been summarized in this section.
Also there is a brief evaluation of the algorithm itself and its recommendations.

\subsection{Rocchio weights}
\label{sec:rocchio-weights}
This test checks how well the algorithm can be adjusted by the weights introduced in section~\ref{sec:rocchio}.
It will be tested how many steps it takes that all recommendations include a given term and after how many more the user vector adopts to another term.
Whereas a "step" is the combination of adding a item to the list of relevant items and updating the user vector.

The test-data includes 25 documents which include the term "white" which will be the first term queried.
After all recommended items include "white", the next term "black" will be queried.
56 documents include "black" as term.
There are 595 documents in the database in total consisting of 1159 terms.
The number of recommendations displayed will be 5.
\\

%\noindent
\paragraph{High $\alpha$}
The first test will use following weights:
$$\alpha = 1, \beta = 0.9, \gamma = 0.1$$
After marking two items as which include "white" as term as relevant, all 5 recommendations are products with "white" as term.

After choosing 53 (of 56) products all five recommendations turned to products with black as term.

Even thought the recommender quickly responded to "white" as desired term, it took quite some time for it to react to the term "black".
A possible reason is, that $\alpha$ set to 1 let's the vector stick to the past.
This means, that old recommendations are hold onto more persistently.
\\

\paragraph{Low $\alpha$}
The second test will use following weights:
$$\alpha = 0.2, \beta = 0.9, \gamma = 0.1$$
Even after marking all 25 white documents as relevant Rocchio will only recommend three items containing "white" at once.
Nevertheless the recommendations quickly adopted to the term "white" and already recommended three white items after setting three white items as relevant.

The same rule applies when shifting to black items.
Because $\alpha$ was set to a value too low it appears that the algorithm couldn't ``remember" what the user searched for and therefore could not generate credible recommendations.
\\

\paragraph{Balanced $\alpha$}
For a final test the weighting of $\alpha$ will be something in-between of test one and two:
$$\alpha = 0.6, \beta = 0.9, \gamma = 0.1$$
With $\alpha$ set to 0.6 there have been way better results achieved.
After choosing three white items all recommendations consisted of items with "white" as term.

And after selecting eight black items all recommendations have turned to products consisting of the term "black".
\\

Depending on the use-case one can adapt $\alpha$ to either make a fast-learning recommender system or one that will remember the users preferences for a long time.
With high values for $\alpha$ Rocchio's algorithm will slowly adapt to recent changes in the users mind.
A low $\alpha$ will result in way faster adaption, while the quality of recommendations may decrease.

\paragraph{Weighting $\beta$ and $\gamma$}
$\gamma$ however may depend on the kind of feedback the RS expects.
\citeauthor{manning:2009} suggest that systems which only allow positive feedback (meaning that the user cannot dislike any item) should set $\gamma$ to 0.\citep[p.~183]{manning:2009}
In general following rule applies: $\beta > \gamma$.
Otherwise Rocchio's algorithm would shift the user vector close to items which he has not rated as relevant.
This would result in recommending items which are possibly disliked by the user.

\subsection{Hamming vs. Euclidean}
\label{sec:hamming-vs-euclidean}
Even though recommender.lib's implementation of kNN uses Euclidean distance as default for calculating distance of two vectors it is still possible to use other functions.
Therefore recommender.lib offers both Euclidean and Hamming distance.
Since both of them are available the question arouses which of them is better suited for working with Rocchio's algorithm.

While using the online shop with hamming distance no useful recommendations could be generated.
Hamming distance requires a direct match of terms between the user- and product-vector.
Since this hardly happens Hamming will not find any item related to the user.
An example of actual working data is given is table~\ref{tab:hamming-vs-euclidean}.
Even thought some of the terms are similar in both vectors hamming does not indicate any analogy because the are not exactly identical.
Euclidean however is more forgiving and therefore delivers better results.

\begin{table}

    \center

    \rowcolors{1}{\dustRowFirst}{\dustRowSecond}
    \begin{tabular}{ c | c }
        \rowcolor{\dustRowHead}
        item vector         & user vector\\\hline
        -0.2589067897584001 & 0.5179678217626879\\
        1.2304489213782739  & 0.5434189653908308\\
        1.5984257066728682  & -0.08814390410064984\\
        1.066946789630613   & 0.4084510980066114\\
        2.7745169657285493  & -0.010199900912164779\\
        2.7745169657285493  & -0.010199900912164779\\
        -0.2597102950420011 & 0.5214848464808467\\
        0.7788817711309995  & 1.2507554711157618\\
        \hline
        \rowcolor{\dustRowHead}
        \multicolumn{2}{ c }{resulting distance}\\
        \hline
        Hamming distance    & 8\\
        Euclidean distance  & 4.549275177751399\\
    \end{tabular}

    \caption{Comparison of Hamming and Euclidean distance results}
    \label{tab:hamming-vs-euclidean}
\end{table}

\subsection{Final verdict}
Even thought Rocchio's algorithm has already been successfully used for information retrieval purposes in general \citep[p.~183]{manning:2009} the usage of the online-shop is not too promising yet.
There are various possible reasons.
The test data on which the algorithm worked was neither great in number, nor good in quality.
There have only been two different kinds of clothing (blouses and trousers) and those haven't even been described well enough.
Also there there a well-known problems which may cause the algorithm to result in lower quality recommendations:
\begin{itemize}

    \item Synonyms which are used through different documents/items result can heavily impact Rocchio's algorithm.
        Terms with the same meaning may be relatively far away from each other in within the vector space model.
        \citep[p.~184]{manning:2009}
        While both 'beige' and 'off-white' may describe the same color the problem is more clear for the same word in different languages such as 'white' and 'wei\ss{}'.
        This are actual examples from the data which has been used to power the build recommender system.

    \item Even thought this problem did not apply to this online shop it may happen, that words which are popular in different domains also confuse Rocchio's algorithm.
    \citep[p.~184]{manning:2009}
\end{itemize}

\noindent
When the algorithm is used on a real online-shop there are some restrictions that should be met.
Instead of tracking a user for a long time-period and successively refining his vector the algorithm should be applied new for every session.
Whereas a session is the time a user looks for one given item without leaving the online shop or starting to search for some more items.
The recommendations will get inaccurate if the user switches his focus from one one kind of item to another as done by the test when changing the search from white to black items.
If this happens, the user-vector will still contain the information about white items while he already searches for the complete opposite.
This effect can be countered by choosing a relatively low $\alpha$, but this also results in worse recommendations in general.
\\

In regard to \textbf{Q6} one must say that usefulness of Rocchio's algorithm in a recommender system is heavily influenced by the way it is used.
For the first product a user searches it delivers fairly good results, while all subsequent searches on the same user vector mostly result in recommendations not as good as the previous ones.
Early expectations of the author that changing $\alpha$ to a low value could be exploited to handle short period trends (such as often appear in fashion) have not been met.
(The idea was that that the algorithm will "forget" about a preference by the time a trend is over. The user should for example not get clothing recommendations based on his preferences of 10 years ago)
\\

Based on the results of this thesis it is unlikely that Rocchio's algorithm can be used as primary module on a recommender system.
Instead it would work better when using it for its original purpose of refining user defined search queries.
Nevertheless Rocchio's algorithm might also be used in combination with other RS approaches.
\citeauthor{burke:2007} discussed the performance of different recommender systems mixed together in his article "Hybrid Web Recommener Systems" and identified some combinations of content-based approaches and others which may work well.
Therefore the best way of implementing Rocchio's algorithm in an online shop (\textbf{Q7}) would either be using it for preselecting items based on a user search query or using it in combination with another recommender algorithm.


\section{Comparing Stress and Allowable Stress}

\newthought{now armed with the calculations} for the shaft stresses and design factor, you will need to select nodes along the shaft that you feel may be critical to its operation. This is for you to decide and to discuss within your reports.

With the nodes selected, you can start to populate the excel spreadsheet that is provided. Placing the calculations within the cells enables you to quickly perform iterations of the shafts design and clearly articulate the changes to the shafts geometry. You will be submitting the final spreadsheet so we can review your calculations within the cells. Please do not alter the format of the spreadsheet.

\begin{table}[h!]
  \caption{Spreadsheet stress model}
  \centering
  \small
  \begin{tabular}{l | c | c c c}
    \toprule
      & Node No. & 1 & 2 & 3\\
    Node Details & Units & \\
    \midrule
    Diameter \\
    Area \\
    Second Moment of Area \\
    Second Polar Moment of Area \\
    \midrule
    Forces \\
    \midrule
    Vertical \\
    Horizontal \\
    Resultant \\
    Resultant Angle \\
    \midrule
    Bending \\
    \midrule
    Vertical \\
    Horizontal \\
    Resultant \\
    Torque \\
    \midrule
    Stresses \\
    \midrule
    Direct Stress \\
    Bending Stress \\
    Torsional Stress \\
    \midrule
    Principal Stresses \\
    \midrule
    Principal Stress 1 (+) \\
    Principal Stress 2 (-) \\
    Shear Stress \\
    \midrule
    Safety Factors \\
    \midrule
    a \\
    b \\
    c \\
    d \\
    k \\
    Nu \\
    \midrule
    UTS \\
    Allowable Stress \\
    \bottomrule
  \end{tabular}
\end{table}


% !TEX root = ./physics_of_fluids.tex
% !TEX TS-program = xelatex
% !TEX encoding = UTF-8 Unicode
\newpage
\section*{Modelling fluids}
%fixme: add intro with the birth and death of a bubble
\chapter{Fluid motion}
\label{chap:fluid-motion}

The description of fluid flows can rapidly be obscured behind seemingly complex equations (e.g. Navier--Stokes). Even worse these equations can change depending on the context and problem considered. Actually, the governing equations for fluid motion express truly simple physical principles, namely \textbf{mass conservation} (the mass $m(t)$ of a fluid particle is constant), \textbf{momentum conservation} (a fluid particle's momentum obeys Newton's second law $m \matrixsym \gamma = \Sigma \bF$) and \textbf{energy conservation} (the energy of a fluid particle follows the first and second principle of thermodynamics).  In this introduction we will review the derivation of the fluid mechanics equations by expressing these fundamental conservation principles.
\section{Forces}
As other continuum media, fluids carry force fields that determine their equilibrium (when the net force contribution is zero) or their motion. If each fluid particle is subject to \textit{body forces}, it is also exposed to \textit{surface forces} called \textbf{stresses}, as for example pressure~(Fig.~\ref{fig:weather_map}) that we now examine.
\begin{figure}[htbp]
\begin{center}
\includegraphics[height=5cm]{19621216Surface.jpg}
\includegraphics[height=5cm]{covid.png} %fixme: change picture
\caption{\textbf{Illustrations of pressure forces in daily-life phenomena.} Left: France isobaric map from December, 16 1962. The map reveals low-pressure area and anticyclones (high-pressure area). The clustering isobars near Corsica are a signature of the violent winds that swept the region (force 12 on the Beaufort scale i.e. the threshold for hurricanes for sailors ; 216 km/h at the cap Corse). Source: \url{http://tempetes.meteo.fr}. Right: a coughing event is associated with a violent lung compression. The resulting overpressure drives a rapid airflow that may torn and transport liquid droplets and aerosols \citep{Mittal2020}.}
\label{fig:weather_map}
\end{center}
\end{figure}

\subsection{Pressure}
\prg{Archimedes\index{Archimedes principle} principle without equation.} Consider a fluid at equilibrium in the gravity field (Fig.~\ref{fig:archimedes}). Let's isolate now mentally a fluid portion. It experiences from the gravity field a force corresponding to its \textit{weight}  $\bP$ pointing downwards. It also bears \textit{pressure forces} from the surrounding fluid. Since the fluid portion is at equilibrium, the net pressure force has to balance the weight (equal in intensity but opposite in direction). Now if in our mind experiment we were to replace the fluid portion by a solid object, the resulting action of the external forces would not change: the net force exerted by pressure forces is still equal in intensity to the weight of the fluid ``displaced'' by the solid. The resultant of pressure forces corresponds to the \textit{buoyancy} \citep{Lighthill1986}. Of course if the solid is denser (or less dense) than the surrounding fluid, the equilibrium would be lost and fluid/body motion would set in.

\noindent Pressure is a force per unit surface which is \textbf{normal} to the considered surface\footnote{We may see this feature as the \textit{definition} of a fluid, i.e. a medium unable to resist shear \citep{Prandtl1957}. A shear stress would therefore unvariably set the fluid into motion. Actually \citet[][\S1.3]{Batchelor1967} argue that if the pressure force would not be aligned with the normal vector, equilibrium could not be achieved.}. This type of distributed force in a fluid is a specificity of continuum media, and is referred to as \textbf{stress}. Here the corresponding stress expression is therefore:
\begin{equation}
\mathrm d \bff = -p \,\bn \,\dS.
\label{eq:pressure_stress}
\end{equation}
The minus sign translate the state of compression in which fluids generally are (so that pressure is a positive quantity, unless in very specific cases of tensile solicitations of fluids).
\prg{Pressure as a body force.} On figure~\ref{fig:pressure_gradient} we illustrate the action of pressure forces exerted on a small cylindrical fluid portion. The portion has a base $S$ and a height $\mathrm dn$ leaning on two isobars $p$ and $p+\mathrm dp$. The action of pressure forces on the side of the cylinder is zero by symmetry, so that the net pressure force is simply the sum of the contributions exerted on each bounding face : $S\,p$ and $-S\,\lp p+\mathrm dp\rp$ (let's count positively -- and arbitrarily -- the forces oriented along the pressure gradient), which is $-S \,\mathrm dp$. If we divide this force by the volume of the small element, $S \, \mathrm dn$, it appears that pressure forcescan be perceived as a body force of intensity $-\pd{p}{n}$ acting along $\nabla p$. In other words pressure forces may be understood as body forces of intensity $-\nabla p$; this is the meaning of this term appearing in both Euler and the Navier--Stokes equations.
\begin{figure}[htbp]
\begin{center}
\includegraphics[page=1,width=5cm]{./pics/pressure_gradient.pdf}
\caption{Writing down a force balance on a volume portion $S\,\mathrm dn$ leaning on two isobars (of level $p$ and $p + \mathrm dp$), we see that the pressure action may be understood as a body force per unit volume of intensity~$-\pd{p}{n}$.}
\label{fig:pressure_gradient}
\end{center}
\end{figure}
This is here a physical interpretation of the divergence theorem which would have given directly:
$$
-\iint_{\partial V} p \,\bn \, \dS = -\iiint_V \nabla p \,\dV.
$$

\subsection{Stresses}
\begin{figure}[htbp]
\begin{center}
\includegraphics[page=1,width=5cm]{./pics/01_pics.pdf}\qquad\includegraphics[page=2,width=5cm]{./pics/01_pics.pdf}
\caption{Left: when at equilibrium in the gravity field, every fluid portion experiences pressure forces that exactly balance the weight action $\bP$. Right: the pressure stress is normal to each surface element.}
\label{fig:archimedes}
\end{center}
\end{figure}
In the general context of a flowing fluid, stress has no particular reason to be aligned with the normal -- and, as a matter of fact, it is not. But multiplying the normal vector $\bn$ with a scalar can only give another vector still aligned with $\bn$, and using the cross product is of no help either because the cross product between any vector and $\bn$ can only give a vector perpendicular to $\bn$. So we need another mean to obtain a vector arbitrarily oriented from the unique knowledge of $\bn$. The mathematical object allowing to perform this operation is the 2-rank tensor. On using Einstein notations, this gives:
\begin{equation}
\mathrm df_i = \sigij n_j \, \dS.
\end{equation}
We have here to remember that this object is only a mean to obtain $\mathrm d \bff$ not necessarily aligned with $\bn$.

\noindent Of course it is possible to obtain the simple case of a stress aligned with $\bn$ using this formalism. As an example, the stress tensor of a fluid at rest (éq.~\ref{eq:pressure_stress}) is:
\begin{equation}
\sigij = -p\, \delij.
\label{eq:static_stress_tensor}
\end{equation}

\noindent It is possible to show that this stress tensor $\mathsfbfit \sigma$ is necessarily a symmetric tensor, i.e. $\sigij = \sigji$ \citep{Batchelor1967}. The demonstration's main idea is to write an angular momentum balance at the fluid particle level; the only dominant term in this equation involves the antisymmetric part of $\mathsfbfit{\sigma}$. As it is not balanced by any term, it necessarily vanishes. There is one exception however: in the very particular case of a \textit{moment density}, as in active matter or certain magnetic colloids, this term can be balanced and the tensor be non-symmetric \citep[see for example the study of][]{Soni2019}.
\subsection{Body forces}
\noindent Fluids are also subject to more conventional body forces, which can be magnetic, electrostatic, gravity or result from non-inertial effects (think of centrifuge or Coriolis pseudo-forces). On noting $\bF$ the body force \textbf{per unit mass} acting on the fluid particle level, we can write the net body force exerted on a fluid portion $V$ as:
\begin{equation}
\iiint_V \rho \bF \,\dV.
\end{equation}
\prg{To summarize.} The net force acting on a fluid portion $V$ is the sum of surface and body forces:
\begin{equation}
\oiint_{\partial V} \mathsfbfit \sigma \!\cdot\! \bn\,\dS + \iiint_V \rho \bF \,\dV.
\end{equation}
\section{Fluid equilibrium}
\noindent At equilibrium, pressure and body force exerted on any part $V$ of a fluid balance each other:
$$
\iiint_V \rho \bF \,\dV -\iint_{\partial V} p \, \bn \, \dS = \boldsymbol 0,
$$
or, on using the divergence theorem:
\begin{equation}
\iiint_V \lp \,\rho \bF -\nabla p \rp\,\dV = \boldsymbol 0.
\end{equation}
This relation being verified for \textit{any} fluid domain, we necessarily get at the local level:
\begin{equation}
\rho \bF =\nabla p.
\end{equation}
And we recover here the pressure force expressed as a body force $-\nabla p$.

\textbf{Remark}: Only those density and force fields such that $\rho \bF$ can be expressed as a gradient allow to reach hydrostatic equilibrium (counter-example: the baroclinic instability developing when iso-$p$ differ from iso-$\rho$, or in other words as soons as pressure is not a simple function of $\rho$).
\prg{The case of conservative forces.} Conservative forces derive from the potential $\Psi$:
\begin{equation}
\bF = - \nabla \Psi,
\end{equation}
so that
\begin{equation}
-\rho \nabla \Psi = \nabla p,
\end{equation}
and therefore
\begin{equation}
\nabla \rho \times \nabla \Psi = \boldsymbol 0.
\end{equation}
The iso-$\rho$ (isopycnals) are then superimposed to equipotentials, themselved superimposed with isobars. \\
\textbf{Consequence}:~in~such~a~system, a free surface corresponding to  $p = 0$ for example will also be an equipotential $\Psi = \text{const}$.

\prg{Example: the equilibrium of a rotating fluid.} Let's consider a rotating container filled with liquid. The container rotates at angular velocity $\Omega$ in the gravity field (the axis of rotation is vertical, i.e. directed along  $\matrixsym e_{z}$). In the rotating frame, each fluid particle experiences gravity but also the centrifuge pseudo-force:
\begin{equation}
\rho\bF_\text{cent} = -\rho \,\matrixsym \Omega \times \lp \matrixsym  \Omega \times \matrixsym r\rp.
\end{equation}
Here $\matrixsym \Omega = \Omega \,\matrixsym e_{z}$. We can then write:
\begin{equation}
\rho\bF_\text{cent} = \rho \Omega^2 r \,\matrixsym e_{r} = -\rho \nabla \Psi_\text{cent},
\end{equation}
where
\begin{equation}
\Psi_\text{cent} = -\frac{1}{2} \Omega^2 r^2 = -\frac{1}{2} \Omega^2 \lp x^2 + y^2\rp.
\end{equation}
Adding gravity effects with $\Psi_\text{grav} = gz$ we get
\begin{equation}
\Psi_\text{tot} = \Psi_\text{grav} + \Psi_\text{cent}  = gz -\frac{1}{2} \Omega^2 \lp x^2 + y^2\rp.
\end{equation}
We here remark that the equipotentials are paraboloids. As a result the free surface characterised with $p = 0$\footnote{see chapter~\ref{chap:boundary_conditions} for a discussion of the hypotheses behind this boundary condition.} will also adopt a paraboloidal shape:
\begin{equation}
z_\text{surf} = \frac{1}{2} \frac{\Omega^2}{g} r^2 + \text{const}.
\end{equation}
\prg{Exercise: fluid planet equilibrium.} Consider a self-gravitating fluid sphere. The gravity force per unit masse $\bF$ exerted on each fluid particle derives from the gravity potential $\Psi$ such that:
\begin{equation}
\nabla^2 \Psi = 4 \mathrm \pi \mathcal G \rho,
\end{equation}
where $\mathcal G$ is the universal gravitational constant. With the help of the hydrostatic equation, and supposing that the fluid has a constant density\footnote{This is a really crude approximation on the density profile, which better describes incompressible (!) planets rather than gaseous ones or stars. The hydrostatics of stars can however be rationalised by taking into account the state law of polytropes, and possibly the radiation pressure adding up to the kinetic pressure. The reader interested in stellar hydrostatics may look at the \textit{Lane-Emden equation} described e.g. in \citet[][chap. IV]{Chandrasekhar1957}.} $\rho_0$, show that the radial pressure profile satisfies:
\begin{equation}
p(r) = \tfrac{2}{3} \mathrm \pi \mathcal G \rho_0^2 \lp R^2 - r^2\rp,
\end{equation}
with $R$ the planet radius.
\section{Fluid motion}
Now that we have described the forces at play in a fluid and the conditions for equilibrium, let's focus on fluid motion.

One technical issue with the simple conservation laws mentioned at the beginning of the chapter is that they are expressed at the fluid particle level. This seems quite natural, but it conflicts with our usual representation of space. Let's clarify what we mean by this by considering a typical fluid flow, for example the one around an airplane wing. Typically we are interested in estimating the forces exerted by the flowing fluid on a the plane, and this requires to build a knowledge of the stresses exerted on the wing. The pressure applied at one given point of the wing is ultimately a consequence of the conservation laws evoked earlier, but we clearly do not want to track the life and trajectory of every fluid particle\footnote{There is actually an alternate form of the fluid mechanics equations called \textit{Lagrangian fluid mechanics} that exploit this viewpoint, but it gets quickly untractable and only a few specific flows can be described with this approach \citep{Bennett2006}.} that will ever very shortly pass in the neighbourhood of the airplane to get this prediction! Rather we seek to make sure that the conservation laws are satisfied while looking at a fixed point of space (and therefore see quite a number of fluid particles passing there). In order to express the conservation laws governing the motion, we thus need to describe the variation of any quantity attached to a fluid particle, such as a concentration or its momentum.
\subsection{Differentiation along motion}
Let's take the example of a concentration field $c(\bx,t)$. Following a fluid particle in its motion, we can write down how the concentration attached to it varies with time:
\begin{equation}
c(\bx+\bu\, \delt,t+\delt) - c(\bx,t) = \delt\underbrace{\lp\pd{c}{t} + \lp \bu \!\cdot\! \nabla \rp c\rp}_{\D{c}{t}} + \mathcal O\lp\delt^2\rp,
\end{equation}
where we made the rate of concentration change $\D{c}{t}$ appear. Note that this quantity differs from $\pd{c}{t}$ which would rather measure the variation of  $c$ at a fixed (\textit{eulerian}) position of space, without following the fluid particle. The operator $\D{}{t}$ is called \textbf{particle derivative} (or material, or convective, or Lagrangian derivative) :
\begin{equation}
\D{c}{t} = \pd{c}{t} + \lp \bu \!\cdot\! \nabla \rp c.
\end{equation}
As an illustration, the equation governing the concentration field transported by a flowing fluid without considering diffusion effects is therefore simply:
\begin{equation}
\D{c}{t} = 0 \quad \text{or}\quad\pd{c}{t} + \lp \bu \!\cdot\! \nabla \rp c = 0.
\end{equation}
We note also that the \textit{acceleration} of a fluid particle is simply $\D{\bu}{t}$.
\subsection{Diffusive and convective fluxes\index{flux}}
When flowing, fluids transport mass, but also chemical species, energy and momentum. To describe the corresponding transport modes, we will use the notion of \textbf{flux} (of mass, momentum, energy).
The vectorial flux $\bj$ characterises the transfer of a quantity across an oriented surface $\delA \,\bn$ per unit time:
\begin{equation}
\bj \!\cdot\! \bn \,\delA
\end{equation}
\subsection{Advection\index{flux!advective}}
\label{sec:advection}
The first transport mode for mass, momentum or energy is advection.
Let's suppose that a given field, for example concentration $c$ again, is \textbf{transported} with the fluid at velocity\index{velocity (definition)}\footnote{The velocity $\bu$ is understood as the average velocity of molecules in the vicinity of the considered point. With this definition we see that the velocity already incorporates  diffusion effects. In mixtures chemical species usually have different velocities that need a careful treatment \citep[][\S17.7]{Bird2002}.} $\bu$, i.e. each fluid particle conserves its concentration. Consider now the \textbf{fixed} surface element $\delA$ represented figure~\ref{fig:slanted_cylinder}. The matter quantity $c$ flowing across the surface\footnote{We here make use of the fact that a slanted cylinder of length $\|\bu\| \mathrm dt$ is the same as a right cylinder of same height $\lp\bu\!\cdot\!\bn\rp$. This is Cavalieri's principle -- which can also be demonstrated with a simple integration.} during a short moment~$\delt$ is $\lp c \,\bu \!\cdot\! \bn\rp \delA \,\delt$.
As a result the matter quantity transported across $\delA$ per unit surface and per unit time is $\bj_\text{adv} \!\cdot\! \bn$ where
\begin{equation}
\bj_\text{adv} = c\, \bu
\end{equation}
is the matter \textbf{flux} associated with advection.
\begin{figure}[htbp]
\begin{center}
\includegraphics{./pics/slanted_cylinder.pdf}
\caption{A surface portion $\delA$ of normal $\bn$ is traversed by a fluid volume $\lp\bu \!\cdot\!\bn\rp\delA\,\delt$ during $\delt$. This volume is counted positively if  $\bu$ points towards the same half-space as $\bn$ (in which case $\bu \!\cdot\! \bn > 0$), and negatively otherwise.}
\label{fig:slanted_cylinder}
\end{center}
\end{figure}
Now if the surface element is \textbf{mobile} and moves at velocity $\bw$, the advection flux generalises to:
 \begin{equation}
\bj_\text{adv} = c\, (\bu-\bw)
\end{equation}
We note that in the context of a \textbf{material domain}, i.e. moving with the same velocity as the fluid, we get $\bw = \bu$ and the advection flux cancels out by construction.
\subsection{Diffusion\index{flux!diffusive}}
Now, even without any underlying flow, simple matter (species concentration), energy or momentum inhomogeneities will give rise to transfer spontaneously. These \textbf{diffusive} exchanges are quantified per unit surface and time with the \textbf{diffusive flux}~$\bj_\text{diff}$.
Even if a detailed modelling of these exchanges is a complex feat, they can nonetheless be described with phenomenological relations (constrained with thermodynamical arguments) such as Fick's law for mass transport for example (see \S\ref{sec:constitutive_laws}).
\section{Balance equation for an integrated quantity\index{conservation law}}
Fluxes characterise exchanges across surfaces. With their help we can determine the evolution of a quantity $c$ contained in a domain in the most general way\footnote{This relation is obtained on \textbf{physical} grounds.}:
\begin{equation}
\underbrace{\vphantom{\oiint_{\partial V}}\dd{}{t}\iiint_{V}c\, \dV}_\text{Variation} = -\underbrace{\oiint_{\partial V} \bj\!\cdot\!\bn\,\dS}_\text{Exchange} + \underbrace{\vphantom{\oiint_{\partial V}}\iiint_{V} \varphi\,\dV}_\text{Production},
\label{eq:conservation_law}
\end{equation}
so that the \textit{variation} of an integrated quantity in  $V$ is given by a balance of entering/leaving quantity into/from the domain (\textit{exchange}) and the possible \textit{production} (or destruction) of $c$ inside $V$.
Before going deeper into the derivation of conservation laws, we have to precise the meaning of the integral derivation appearing in the left hand side. If the considered volume is fixed, the derivation process is easy as we can just swap derivation and integration. But if the domain is moving or deforming, care must be taken in writing this derivation.
\subsection{Volume variation of a material domain and integral derivation}
We will now give a meaning to the derivation of an integral performed over a deformable domain. To start with, let's consider the quite specific (but still really common) case of a \textbf{material} domain, i.e. we follow the same fluid particles though time. As time flows this domain may see its volume change as indicated on figure~\ref{fig:volume_change}, hence as:
\begin{equation}
\dd{}{t}\iiint_{V}\, \dV = \oiint_{\partial V} \bu\!\cdot\!\bn\,\dS \quad \lp = \iiint_V \nabla \!\cdot\! \bu \, \dV\rp.
\end{equation}
\begin{figure}[htbp]
\begin{center}
\includegraphics{./pics/volume_change.pdf}
\caption{A material volume is transported by a velocity field $\bu$. Each portion $\delA$ of the domain boundaries is advected with $\bu$ and this yields a volume change $\lp\bu\!\cdot\!\bn\rp\delA\delt$ during $\delt$. The resulting total volume change rate $\dd{V}{t}$ is given by $\iint \lp\bu\!\cdot\!\bn\rp \dA$.}
\label{fig:volume_change}
\end{center}
\end{figure}

\paragraph{$\rhd$ Signification of the divergence.\index{divergence (meaning)}} The previous relation allows to shed light on the divergence of a velocity field~$\bu$. Actually, consider a material volume $\tau(t)$ constituted with the same fluid particles. The previous balance might be rewritten with the help of the divergence theorem as:
\begin{align}
\dd{\tau}{t} &= \iint \bu \!\cdot\! \bn \, \dS\\
		&= \iiint \nabla \!\cdot\! \bu \, \dV.
\end{align}
Thus in the limit where $\tau(t)$ is really small (in fact sufficiently small so that we can consider  $\nabla \!\cdot\! \bu$ constant throughout the domain), we can write:
\begin{equation}
\lim_{\tau \to 0} \frac{1}{\tau} \dd{\tau}{t} = \nabla \!\cdot\! \bu.
\end{equation}
The divergence of a velocity field can therefore be understood as the \textit{rate of volume change of a fluid particle.}
\prg{Integral derivation.} We now have the toolset enabling the clarification of the derivation of the integral over a material domain $V(t)$. Let's focus on the variation of the following quantity:
$$
\dd{}{t} \iiint_{V(t)} \theta \,\dV.
$$
To shed some light over this quantity, let's divide mentally the domain in a multitude of tiny cubes or fluid particles.
As the fluid domain moves, the value of $\theta$ will change for all fluid particles at the rate $\D{\theta}{t}$. Moreover the integration element $\mathrm dV$ will change as well with the rate $\lp\nabla\!\cdot\!\bu\rp\mathrm dV$. In other words\footnote{This relation is obtained on \textbf{mathematical} grounds.}\footnote{We note that this relation can directly be generalised to the case where the domain moves with a velocity differing from that of the fluid (fictitious velocity, flame propagation, balance over a domain moving with a wave). In this case, it suffices to replace $\bu$ with the domain velocity $\bw$.}  :
\begin{equation}
\dd{}{t} \iiint_{V(t)} \theta \,\dV = \iiint_{V(t)} \D{\theta}{t} \,\dV + \iiint_{V(t)} \theta \underbrace{\D{\dV}{t}}_{\lp\nabla \cdot \bu\rp\dV}
\end{equation}
\subsection{Conservation of a quantity. Application to mass conservation}
Now that the derivation of an integral has been elucidated, we are in a position to use equation~(\ref{eq:conservation_law}) which expresses the general conservation of a quantity, for either a fixed or moving domain. Choosing one type of domain or another is largely a matter of context. For example we may consider a moving domain to establish the momentum conservation equation of a given fluid portion. A balance over a fixed domain may also present some interest, when designing for example the evolution of a quantity traversing a fixed mesh cell in a numerical code. Depending on the application, we will choose the more relevant viewpoint.

In order to clarify the use of balances over fixed or moving domains, let's now establish the mass conservation equation (without production nor destruction of mass), first in a fixed domain and then in a moving one.
\begin{enumerate}
\item \textbf{Mass conservation in a fixed domain} $V_\text{fixed}$. The balance equation~(\ref{eq:conservation_law}) reads :
\begin{equation}
\dd{}{t}\iiint_{V_\text{fixed}} \rho \, \dV = - \oiint_{\partial V_\text{fixed}} \rho \bu \!\cdot\! \bn \, \dS.
\end{equation}
The domain being fixed, we let the derivation enter in the integral:
\begin{equation}
\iiint_{V_\text{fixed}} \pd{\rho}{t} \, \dV = - \oiint_{\partial V_\text{fixed}} \rho \bu \!\cdot\! \bn \, \dS,
\end{equation}
and, on applying the divergence theorem, we obtain:
\begin{equation}
\iiint_{V_\text{fixed}} \pd{\rho}{t}  + \nabla \!\cdot\! \lp\rho \bu \rp \, \dV = 0.
\end{equation}
Further noting that this balance is actually true for every possible domain, it follows that the integrand actually vanishes:
\begin{equation}
\pd{\rho}{t}  + \nabla \!\cdot\! \lp\rho \bu \rp = 0.
\label{eq:continuity}
\end{equation}
This is the \textbf{continuity equation\index{conservation law!mass conservation}\index{continuity equation}}\footnote{This denomination has been used for a long time, but is actually not really justifiable\dots} that embodies mass conservation. This type of reasoning exploiting the validity of an integral expression for any volume to obtain a relation at the fluid particle (or \textit{local}) level is very common.
\item \textbf{Mass conservation for a material domain} $V(t)$. This time there is no flux term because no fluid particle enters nor leaves the material domain, by definition. The balance equation~(\ref{eq:conservation_law}) then reads:
\begin{equation}
\dd{}{t}\underbrace{\iiint_{V(t)} \rho \, \dV}_{m(t)} = 0.
\end{equation}
But as the domain is now moving, we have to apply the integral derivation procedure seen earlier:
\begin{equation}
\dd{}{t} \iiint_{V(t)} \rho\, \dV = \iiint_{V(t)} \D{\rho}{t} + \rho \nabla \!\cdot\! \bu\,\dV = 0.
\end{equation}
From the latter we recover again the continuity equation~(\ref{eq:continuity}).
\end{enumerate}
\prg{Conservation of a quantity per unit mass.} Thanks to the continuity relation it is possible to obtain a simplified expression for the transport of a quantity per unit mass $\xi$ (i.e. such that the quantity associated with a fluid particle be $\rho\xi$):
\begin{equation}
\dd{}{t} \iiint_{V(t)} \rho \xi\, \dV = \iiint_{V(t)} \rho \D{\xi}{t} \,\dV.
\end{equation}
We let the reader demonstrate this relation.
\prg{The incompressible fluid.}
A recurring case of great practical value is that of an \textbf{incompressible evolution} where we do \textit{not} suppose that the whole fluid a constant density, but rather that each fluid particle conserves its density. This implies:
\begin{equation}
\D{\rho}{t} = 0 \quad\text{and therefore}\quad \nabla\!\cdot\!\bu=0.
\end{equation}
A velocity field  $\bu$ satisfying the zero divergence property qualifies as a \textit{solenoidal} field.
\subsection{Conservation of a possibly diffusing passive scalar. Convection-diffusion equation}
Let's consider again a concentration field $c$ advected in a fluid domain with the velocity field $\bu$. Due to molecular thermal agitation, this field is also subject to diffusion phenomena characterised by the flux $\bj_\text{diff}$. Here again we can obtain the evolution equation for the concentration by following two different routes:
\begin{enumerate}
\item By considering a \textbf{fixed domain} $V_\text{fixed}$. In this case, and in absence of any source/sink for the concentration, we will simply write that the total variation is given by the sum of the fluxes:
$$
\dd{}{t} \iiint_{V_\text{fixed}} c \, \dV = - \oiint_{\partial V_\text{fixed}} (\bj_\text{conv} + \bj_\text{diff}) \!\cdot\!\bn\,\dS,
$$
so that:
$$
\iiint_{V_\text{fixed}} \pd{c}{t} \, \dV = - \iiint_{V_\text{fixed}} \nabla \!\cdot\! (\bj_\text{conv} + \bj_\text{diff})\,\dS.
$$
Anticipating on \S \ref{sec:constitutive_laws} by writing the diffusive flux with Fick's law $\bj_\text{diff} = - D \nabla c$ we obtain at the local level:
\begin{equation}
\pd{c}{t} + \nabla \!\cdot\! \lp c\bu\rp = \nabla \!\cdot\! (D \nabla c)
\label{eq:conv_diff}
\end{equation}
For an incompressible evolution with a constant diffusion coefficient, this equation reduces to the classic \textbf{advection-diffusion equation}:
\begin{equation}
\pd{c}{t} + \lp\bu\!\cdot\!\nabla\rp c = D \nabla^2 c.
\label{eq:conv_diff_incompressible}
\end{equation}
\item Or by considering a \textbf{material domain} $V_\text{mat}$. This time there is no convective flux by construction (see \S\ref{sec:advection}) but only a diffusive flux:
$$
\dd{}{t} \iiint_{V_\text{mat}} c \, \dV = - \oiint_{\partial V_\text{mat}} \bj_\text{diff} \!\cdot\!\bn\,\dS,
$$
so that, by deriving the integral over the material domain:
$$
\iiint_{V_\text{mat}} \D{c}{t} + c \lp\nabla\!\cdot\!\bu\rp \, \dV = \iiint_{V_\text{mat}} \nabla \!\cdot\! (D \nabla c)\,\dS.
$$
This relation holds true for every possible domain, and as a result we retrieve the local form of equation~$\lp\ref{eq:conv_diff}\rp$.
\end{enumerate}
\subsection{Equation for momentum conservation\index{conservation law!momentum conservation}}
Momentum conservation for a fluid domain simply follows from Newton' second law $m \matrixsym \gamma = \Sigma \matrixsym F$, never forget this!
Let's write this law for a material domain $V(t)$ :
\begin{equation}
\dd{}{t} \iiint_{V_\text{mat}} \rho u_i\,\dV = \oiint_{\partial V_\text{mat}} \sigij n_j\,\dS + \iiint _{V_\text{mat}}\rho F_i \,\dV
\end{equation}
or, going to the local level:
\begin{equation}
\rho \D{u_i}{t} = \pd{\sigij}{x_j} + \rho F_i
\label{eq:momentum_conservation}
\end{equation}
That was quite simple. However there is a loophole in the previous expression as the stress tensor $\mathsfbfit \sigma$ is here unknown (except in the case of limited interest of a static fluid, see equation \eqref{eq:static_stress_tensor}). Even if equation~\eqref{eq:momentum_conservation} holds true whatever the nature of the fluid (even for say exotic viscoelastic fluids), it is of limited use as long as this stress tensor is not clarified. We therefore have to make a connection between the stresses and the motion of the fluid, for we expect that the stresses will change as soon as the fluid starts to flow. This connection will me be made thanks to \textit{constitutive laws} that will really characterise the fluid we are looking at.

\section{Constitutive laws\index{constitutive laws}}
\label{sec:constitutive_laws}
The conservation laws expressed for a flowing fluid are expressed with fluxes and stresses whose precise form still remains to be determined. In order to make some progress in this determination, let's consider the following situation: without any macroscopic motion, a liquid contains a colourant with concentration $c$ distributed inhomogeneously, with area more or less concentrated. Even in absence of a mean motion, the collisions between molecules will lead the colourant molecules to migrate randomly in the liquid. As a result, due to the inhomogeneous colourant distribution, there will be an excess of particles traversing $\delA$ that originate from a more concentrated area than the reverse. The consequence is a net transport of colourant molecules from more concentrated area to less concentrated ones, that will be active as long as the non-equilibrium situation persists: this is the \textbf{diffusion process}. It seems difficult to track the motion of each colourant particles from a statistical viewpoint. But from a \textit{phenomenological} viewpoint, it is quite clear that diffusion will remain active only if a concentration gradient $\nabla c$ exists. The idea of \textbf{gradient-type laws} is to suppose that the components of the flux $\bj_\text{diff}$\ depend linearly on $\nabla c$, i.e. :
\begin{equation}
\lp \bj_\text{diff}\rp_i = \kij \pd{c}{x_j}.
\end{equation}
For an isotropic fluid, it seems reasonable to consider that in absence of any privileged axes the flux will be aligned with $\nabla c$ and of opposite sign (so as to restore equilibrium rather than to destroy it further!), so that :
\begin{equation}
\bj_\text{diff} = -k \nabla c,
\end{equation}
and therefore:
\begin{equation}
\kij = -k \delij.
\end{equation}
We here recover the general form of mass (Fick) and energy (Fourier) transport:
\begin{empheq}[left=\empheqlbrace]{alignat=2}
&\text{\textbf{Fick}'s law} :\qquad &  \bj_\text{mass} = -D \nabla c\label{eq:fick_flux} \\
&\text{\textbf{Fourier}'s law} :\qquad & \bj_\text{energy} =-k \nabla T\label{eq:fourier_flux}
\end{empheq}
\prg{Momentum diffusion and viscous stress.} The case of momentum diffusion is a bit more complex due to the vectorial nature of $\rho \bu$. To start with let's consider the simple situation of a parallel flow $\lp U(y),0,0\rp$. Due to intermolecular collisions, there is a vertical \textbf{diffusion} of momentum. As for mass transport, we suppose that the flux is linear with the momentum gradient, so that:
\begin{equation}
j_\text{diff} = -\mu \dd{U}{y},
\label{eq:momentum_flux}
\end{equation}
Note that this vertical flux of horizontal momentum has the following dimensions;
$$
\text{momentum per unit volume} \times \text{volume} / \text{area} / \text{time}
$$
or $[\mathsf{ML^{-1}T^{-2}}]$, the same dimension of a stress. This dimensional similitude is no coincidence: the transferred momentum is achieved with a stress, in accordance with Newton' second law. We may indeed rewrite~\eqref{eq:momentum_flux} as:
\begin{equation}
\sigxy = \mu \dd{U}{y},
\label{eq:momentum_flux_stress}
\end{equation}
which is the horizontal stress exerted on a surface with a vertical normal\footnote{the reader will note the sign difference between the expressions~\eqref{eq:momentum_flux} and~\eqref{eq:momentum_flux_stress} that originate from the notation convention for stresses.}. The proportionality coefficient $\mu$ characterising the efficiency of momentum transport is the \textit{dynamic viscosity\index{viscosity}}.
\prg{General expression for the stress tensor of a Newtonian fluid.} In the context of a general flow, we can foresee that the stress tensor will depend on each component of the velocity gradient\footnote{This is this linear dependence to shear that qualifies a fluid as Newtonian. But we can imagine (and actually there exists) more complex relations, of nonlinar nature, between stress and shear. \textbf{Rheology} is the discipline that studies these particular non-newtonian behaviours.}, so that:
\begin{equation}
\sigij = -p \,\delij + \alphaijkl \pd{u_k}{x_l}.
\end{equation}
This form of the stress tensor is compatible with the static fluid stress tensor presented earlier: as soon as the velocity vanishes, the stress tensor adopts its static limit~\eqref{eq:static_stress_tensor}. But we can go further. If we decompose the velocity gradient tensor into a symmetric part \textbf{\textsf{\textit{e}}} (associated with a deformation) and an antisymmetric part $\mathsfbfit \omega$ (associated with solid body rotation) :
$$
u_{i,j} = e_{i,j} + \omega_{i,j} \quad \text{with}\quad
e_{i,j} = \frac{1}{2}\lp\pd{\vphantom{u_j}u_i}{x_j}+\pd{u_j}{x_i}\rp \quad\text{et}\quad
\omega_{i,j}= \frac{1}{2}\lp\pd{\vphantom{u_j}u_i}{x_j}-\pd{u_j}{x_i}\rp,
$$
Actually momentum diffusion (i.e. viscous stress) can only occur when the flow deviates from solid-body motion (translation or rotation): as a result $\mathsfbfit \sigma$ cannot depend on $\mathsfbfit \omega$ and:
\begin{equation}
\sigij = -p\, \delij + \Aijkl e_{kl}.
\end{equation}
Additional considerations on the fluid isotropy that we will not develop here allow for a drastic reduction in the number of coefficients to finally get:
\begin{equation}
\sigij = -p \,\delij + 2 \mu e_{ij} + \lambda \lp\nabla\!\cdot\!\bu\rp \delij.
\label{eq:newtonian_stress_tensor}
\end{equation}

\section{Navier-Stokes equation}
Having elucidated the structure of the stress tensor~\eqref{eq:newtonian_stress_tensor} we can rewrite the equation for momentum conservation~\eqref{eq:momentum_conservation} :
\begin{equation}
\rho \D{u_i}{t} =  \rho f_i  - \pd{p}{x_i} + \pd{}{x_j} \lp 2 \mu e_{ij} + \lambda \lp\nabla\!\cdot\!\bu\rp \delij \rp
\end{equation}
This equation is the \textit{Navier-Stokes equation}.

In the particular case (but of great practical interest) of an incompressible evolution with viscosity gradient, this equation simplifies to:
\begin{equation}
\rho \D{u_i}{t} =  \rho f_i  - \pd{p}{x_i} + \mu \frac{\partial^2 u_i}{\partial x_j\partial x_j},
\end{equation}
or, in vectorial form:
\begin{equation}
\underbrace{\rho \lp\pd{\bu}{t} + \lp\bu\!\cdot\!\nabla\rp\bu\rp}_{m\matrixsym\gamma} = \underbrace{\vphantom{\lp\pd{\bu}{t}\rp}-\nabla p + \mu \nabla^2 \bu + \rho \bff}_{\Sigma \bF}.
\end{equation}

%\section{Mini-projet : sur l'intérêt de l'adimensionnement}
%Manip parachute


\chapter{Overview of the axioms in this book}

\begin{enumerate}
\item We assumed the function extensionality axiom in \cref{axiom:funext}. Function extensionality was later derived from the univalence axiom in \cref{thm:funext-univalence}.
\item We assumed the univalence axiom in \cref{axiom:univalence}.
\item We assumed that universes are closed under propositional truncations in \cref{axiom:propositional-truncations}. It was shown in \cref{thm:join-construction-propositional-truncations} that any universe that is closed under homotopy pushouts is also closed under propositional truncations.
\item We assumed the type theoretic replacement axiom in \cref{axiom:replacement}. It was shown in \cref{thm:replacement} that replacement holds for any universe that is closed under homotopy pushouts.
\item We assumed in \cref{axiom:circle} that the circle is a type in the base universe $\UU_0$. In \cref{thm:circle-replacement} the circle was shown to be a type in the base universe using the replacement axiom. It was shown that the In \cref{thm:circle-pushout}, the circle was constructed as a pushout.
\item In \cref{axiom:pushouts} that universes are closed under pushouts.
\end{enumerate}


%%%%%%%%%%%%
\section{Cut Property and Cycle Property}

%%%%%%%%%%%%%
\begin{frame}{Cut property of MST}
  \begin{exampleblock}{Cut Property \pno{3.6.18 (a)}}
    \begin{itemize}
	  \item Graph $G = (V, E)$ (undirected, connected, weighted)
	  \item \textcolor{gray}{Weights are distinct}
	  \item A cut $(S, V \setminus S)$ where $S, V-S \neq \emptyset$
	  \item Let $e = (u,v)$ be \emph{a} minimum-weight edge across $(S, V \setminus S)$
	\end{itemize}
	Then $e$ must be in \emph{some} MST of $G$.
  \end{exampleblock}

  \fignocaption{width = 0.35\textwidth}{fig/cut-property-no-name.pdf}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{Cut property of MST}
  \begin{block}{Cut Property \pno{3.6.18 (a)}}
    \begin{proof}
      Basic idea: $T$ is an MST of $G$.
      \begin{itemize}
	\item $e \in T$
	\item $e \notin T \Rightarrow e \in T'$
	  \begin{itemize}
	    \item $T + \set{e}$ to construct a cycle $C$
	    \item $\exists e' = (u',v') \in C$ ($e' \in P_{u,v}$), $e'$ crosses $(S, V \setminus S)$
	    \item $T' = T + \set{e} - \set{e'}$: spanning tree (connected, acyclic)
	    \item $w(e') \geq w(e) \Rightarrow w(T') \le w(T) \Rightarrow w(T') = w(T)$
	  \end{itemize}
      \end{itemize}
    \end{proof}
  \end{block}

  \begin{alertblock}{Remark.}
    \begin{itemize}
      \item a minimum-weight edge; $\in$ some MST
      \item exchange argument
    \end{itemize}
  \end{alertblock}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{Cut property of MST}
  \begin{exampleblock}{Application of cycle property \pno{3.6.15}}
    \begin{itemize}
      \item \pno{3.6.15 (3)}: $e \in G$ is a lightest edge $\Rightarrow$ $e \in \exists$ MST of $G$
      \item \pno{3.6.15 (4)}: $e \in G$ is the unique lightest edge $\Rightarrow$ $e \in \forall$ MST
      \item \pno{3.6.15 (9)}: $e = (u,v) \in \exists$ MST $T$ of $G$ $\Rightarrow$ $e$ is a lightest edge across some cut $(S, V \setminus S)$ \emph{(converse of cut property)}
    \end{itemize}
  \end{exampleblock}

  \begin{block}{Solution.}
    \begin{itemize}
      \item \pno{3.6.15 (3)}: $(S=\set{u}, V \setminus S)$
      \item \pno{3.6.15 (4)}: By contradiction. $e \notin T$; $T' = T + \set{e} - \set{e'} \Rightarrow w(T') < w(T)$
      \item \pno{3.6.15 (9)}:
	\begin{enumerate}
	  \item to find the cut $(S, V \setminus S)$
	    \begin{itemize}
	      \item $T - \set{e}$
	    \end{itemize}
	  \item to prove that $e$ is a lightest edge across $(S, V \setminus S)$
	    \begin{itemize}
	      \item by contradiction: $T' = T - \set{e} + \set{e'}$
	    \end{itemize}
	\end{enumerate}
    \end{itemize}
  \end{block}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{Cut property of MST}
  \begin{exampleblock}{Wrong divide-and-conquer algorithm for MST \pno{3.6.29}}
    \begin{itemize}
      \item $G = (V, E, w)$
      \item $(V_{1}, V_{2}): ||V_{1}| - |V_{2}|| \le 1$
      \item $T_{1} + T_{2} + \set{e}$: $e$ is a lightest edge across $(V_{1}, V_{2})$
    \end{itemize}
  \end{exampleblock}

  \begin{block}{Solution.}
    \fignocaption{width = 0.30\textwidth}{fig/divide-conquer-mst-counterexample.pdf}
  \end{block}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{Cycle property of MST}
  \begin{block}{Cycle property \pno{3.6.18 (b)}}
	\begin{itemize}
	  \item $G = (V,E,w)$
	  \item Let $C$ be any cycle in $G$
	  \item $e = (u,v)$ is \emph{a} maximum-weight edge in $C$
	\end{itemize}
	Then $\exists \textrm{ MST } T \text{ of } G: e \notin T$.
  \end{block}

  \fignocaption{width = 0.40\textwidth}{fig/cycle-property.pdf}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{Cycle property of MST}
  \begin{block}{Cycle property \pno{3.6.18 (b)}}
    \begin{proof}
      Basic idea: pick any MST $T$ of $G$
      \begin{itemize}
	\item $e \notin T$
	\item $e \in T \Rightarrow e \notin T'$
	  \begin{itemize}
	    \item $T - \set{e}$ $\Rightarrow$ $(S, V \setminus S)$
	    \item $\exists e' = (u', v') \in C$ ($e' \in P_{u,v}$) across the cut
	    \item \textcolor{red}{$T' = T - \set{e} + \set{e'}$}: spanning tree
	    \item $w(e') \leq w(e) \Rightarrow w(T') \leq w(T) \Rightarrow w(T') = w(T)$
	  \end{itemize}
      \end{itemize}
    \end{proof}
  \end{block}

  \begin{alertblock}{Remark.}
    \begin{itemize}
      \item Why don't we pick any $e' \in C$?
      \item ``Anti-Kruskal'' (reverse-delete; also by Kruskal) \pno{3.6.20 (c)}
    \end{itemize}
  \end{alertblock}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{Applications of cycle property}
  \begin{exampleblock}{Applications of cycle property \pno{3.6.15}}
    \begin{itemize}
      \item \pno{3.6.15 (2)}: $C \subseteq G, e \in C$, $e$ is the unique maximum-weighted edge of $G$ $\Rightarrow$ $e \notin$ any MST of $G$
      \item \pno{3.6.15 (5); 3.6.18 (c)}: $C \subseteq G, e \in C$, $e$ is the unique lightest edge of $C$ $\Rightarrow^{?} e \in \forall$ MST
      \item \pno{3.6.15 (1)}: $G = (V, E), |E| > |V| - 1$, $e$ unique maximum-weighted edge $\Rightarrow^{?} e \notin$ any MST
      \item \pno{3.6.20 (a)}: $e$ does not belong to any cycle $\Rightarrow$ $e \in \forall$ MST
    \end{itemize}
  \end{exampleblock}

  \begin{block}{Solution.}
    \begin{itemize}
      \item \pno{3.6.15 (2)}: By contradiction. $T' = T - \set{e} + \set{e'}$
      \item \pno{3.6.15 (5); 3.6.18 (c)}
	\fignocaption{width = 0.20\textwidth}{fig/cycle-property-inverse.pdf}
      \item \pno{3.6.15 (1)}: (bridge)
      \item \pno{3.6.20 (a)}: disconnected o.w.
    \end{itemize}
  \end{block}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{Properties of MST}
  \begin{exampleblock}{\cmark or \xmark \pno{3.6.15}}
    \begin{enumerate}
      \item \xmark $|E| > |V| - 1$, $e$ is the unique maximum edge $\Rightarrow$
      $e$ does not belong to any MST.
      \item \cmark If $G$ has a cycle with a unique maximum edge $e$, then $e$ cannot
      be part of any MST. (\textcolor{blue}{Prove}: Cycle property)
      \item \cmark Let $e$ be any edge of minimum edge in $G$. Then $e$ belongs to
      some MST. (\textcolor{blue}{Prove}: Cut property)
      \item \cmark If the minimum edge is unique, then it belongs to every MST.
      \item \xmark If $G$ has a cycle with a unique minimum edge $e$, then $e$
      belongs to every MST.
	\fignocaption{width = 0.20\textwidth}{fig/cycle-property-inverse.pdf}
	  \newcounter{enumTemp}
      \setcounter{enumTemp}{\theenumi}
    \end{enumerate}
  \end{exampleblock}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{Properties of MST}
  \begin{exampleblock}{\cmark or \xmark \pno{3.6.15}}
    \begin{enumerate}
      \setcounter{enumi}{\theenumTemp}
      \item \xmark The shortest-path tree computed by Dijkstra's algorithm is
      necessarily an MST.
      \item \xmark The shortest path between two nodes is necessarily part of some
      MST.
      \fignocaption{width = 0.10\textwidth}{fig/mst-sssp.pdf}
      \item \cmark Prim's algorithm works correctly when there are negative edges.
      \item \cmark If $e$ belongs to some MST, then $e$ is a minimum edge across some
      cut.
      \item \cmark $w > 0$; Vertex $s$; shortest-path tree of $s$ and some MST share
      a common edge
      \pno{6.1.5}
      \item \cmark $w'(e) = \left(w(e)\right)^2$ \pno{6.2.2}
    \end{enumerate}
  \end{exampleblock}
\end{frame}
%%%%%%%%%%%%
\begin{frame}{Uniqueness of MST}
  \begin{exampleblock}{Uniqueness of MST \pno{3.6.21}}
    Distinct weights $\Rightarrow$ unique MST.
  \end{exampleblock}

  % \fignocaption{width = 0.35\textwidth}{fig/mst-unique.pdf}
  \begin{block}{Solution.}
    \begin{proof}
      By contradiction: two MSTs $T_1 \neq T_2$.
      \begin{itemize}
	\item $\Delta E = \set{e \mid e \in T_1 \setminus T_2 \lor e \in T_2
	  \setminus T_1}$
	\item $e = \min \Delta E$. Suppose $e \in T_1 \setminus T_2$
	\item $T_2 + \set{e} \Rightarrow C$
	\item $\exists (e' \in C) \notin T_1 \Rightarrow e' \in T_{2} \setminus T_{1} \Rightarrow e' \in \Delta E \Rightarrow w(e') > w(e)$
	\item $e' \in T_{2} \setminus T_{1} \Rightarrow e' \in \Delta E$
	\item $T' = T_{2} + \set{e} - \set{e'} \Rightarrow w(T') < w(T_{2})$
      \end{itemize}
    \end{proof}
  \end{block}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{Uniqueness of MST}
  \begin{block}{Conditions for Uniqueness of MST \pno{3.6.19}}
    \begin{itemize}
      \item \pno{3.6.19 (a)}: unique MST $\nRightarrow$ equal weights
        \fignocaption{width = 0.20\textwidth}{fig/unique-mst-partition.pdf}
      \item \pno{3.6.19 (c)}: Counterexamples
        \begin{itemize}
          \item \xmark cut: minimum-weight edge across any cut is unique
          \item \xmark cycle: maximum-weight edge in any cycle is unique
        \end{itemize}
        \begin{columns}
          \column{0.50\textwidth}
            \fignocaption{width = 0.40\textwidth}{fig/unique-mst-partition.pdf}
          \column{0.50\textwidth}
            \fignocaption{width = 0.45\textwidth}{fig/unique-mst-cycle.pdf}
        \end{columns}
    \end{itemize}
  \end{block}
\end{frame}
%%%%%%%%%%%%
\section{Updating MST}

%%%%%%%%%%%%
\begin{frame}{Updating MST}
  \begin{exampleblock}{Decreasing/increasing edge weight \pno{3.6.6}}
    $G$ and an MST $T$
    \begin{enumerate}
      \item $w(e)$ is decreased: $w'(e) = w(e) - k$
      \item $w(e)$ is increased
    \end{enumerate}
  \end{exampleblock}

  \begin{block}{Solution for (1).}
    \begin{itemize}
      \item $e \in T$: no need to update $T' = T$.
	$w'(T') = w(T) - k \Rightarrow w'(T') < w(T)$.

	To prove that $T'$ is an MST of $G'$:

	Suppose $\exists T'':$ $T''$ is an ST of $G'$ and $w'(T'') < w'(T')$.
	\begin{itemize}
	  \item $e \notin T''$: $w(T'') = w'(T'') < w'(T') < w(T)$
	  \item $e \in T''$: $w(T'') = w'(T'') + k < w'(T') + k = w(T)$
	\end{itemize}
      \item $e \notin T$: $T' = T + \set{e} - \set{e'}$; $e'$ is the
	maximum-weight edge in cycle and $w(e') > w(e)$
	\begin{itemize}
	  \item $e \notin T''$: $w(T'') = w'(T'') < w'(T') < w(T)$
	  \item $e \in T''$: \textcolor{red}{???}
	\end{itemize}
    \end{itemize}
  \end{block}

  \textcolor{red}{To verify it:} \url{http://cs.stackexchange.com/q/43309/4911}
\end{frame}
%%%%%%%%%%%%
\begin{frame}{Updating MST}
  \begin{exampleblock}{Adding vertex to MST \pno{3.6.2}}
    \begin{itemize}
      \item $G = (V,E)$; an MST $T$
      \item $G' = (V',E')$: $V' = V + \set{X}, E' = E + E_X$; $E_X$: incident
      edges to $X$
      \item To find an MST $T'$ of $G'$
    \end{itemize}
  \end{exampleblock}

  \begin{block}{Solution.}
    \begin{enumerate}
      \item Recomputing $O((m+n) \log n)$
      \item
        \begin{itemize}
          \item There \emph{exists} an MST of $G'$ that includes no edges in $G
          \setminus T$
          \item Run MST alg. on $G'' =(V + \set{X}, T + E_X)$
          \item $O(n \log n)$
        \end{itemize}
      \item $O(n)$
        \begin{itemize}
          \item ``On Finding and Updating Spanning Tress and Shortest Paths'', 1975
          \item ``Algorithms for Updating Minimum Spanning Trees'', 1978
        \end{itemize}
    \end{enumerate}
  \end{block}
\end{frame}
%%%%%%%%%%%%%
\section{Variants of MST}

%%%%%%%%%%%%%
\begin{frame}{Variants of MST}
  \begin{exampleblock}{Feedback edge set: \pno{3.6.4}}
    \begin{enumerate}
      \item maximum spanning tree
      \item (minimum) feedback edge set:
	\begin{itemize}
	  \item a set of edges which, when removed from the graph, leave an acyclic graph $G'$
	  \item assuming $G$ is connected $\Rightarrow$ $G'$ is connected
	  \item feedback \emph{arc} set: ``cycle'' $\Rightarrow$ circular dependency
	\end{itemize}
    \end{enumerate}
  \end{exampleblock}

  \begin{block}{Solution.}
    \begin{itemize}
      \item $G'$ is connected + acyclic $\Rightarrow$ $G'$ is an ST
      \item $\textrm{FES} \Leftrightarrow G \setminus \textrm{Max-ST}$
    \end{itemize}
  \end{block}
\end{frame}
%%%%%%%%%%%%
\begin{frame}{Variants of MST}
  \begin{exampleblock}{Edge weights \pno{3.6.15 (8); 3.6.16}}
    \begin{itemize}
      \item \pno{3.6.15 (8)}: negative edges for Prim algorithm
      \item \pno{3.6.16}: $w'(e) = (w(e))^{2}$
    \end{itemize}
  \end{exampleblock}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{Variants of MST}
  \begin{exampleblock}{MST with specified leaves: \pno{3.6.7}}
    \begin{itemize}
      \item $G = (V, E), U \subset V$
      \item finding an MST with $U$ as leaves
    \end{itemize}
  \end{exampleblock}

  \begin{block}{Solution.}
    \begin{columns}
      \column{0.60\textwidth}
	\begin{itemize}
	  \item $G' = G \setminus U$
	  \item MST $T'$ of $G'$
	  \item attach $\forall u \in U$ to $T'$ (lightest edge)
	\end{itemize}
      \column{0.40\textwidth}
	\fignocaption{width = 0.50\textwidth}{fig/mst-specified-leaves.pdf}
    \end{columns}
  \end{block}
\end{frame}
%%%%%%%%%%%%
\begin{frame}{Variants of MST}
  \begin{block}{ST with specified edges: \pno{3.6.10}}
    \begin{itemize}
      \item $G = (V,E), S \subset E$ (no cycle in S)
      \item finding an MST with $E$ as edges
    \end{itemize}
  \end{block}

  \begin{block}{Solution.}
    \begin{itemize}
      \item contract each isolated component of $S$ to a \emph{super-vertex}
      \item $G \to G'$
      \item find MST of $G'$
    \end{itemize}
  \end{block}
\end{frame}
%%%%%%%%%%%%%
\section{MST vs. Shortest Paths}

%%%%%%%%%%%%%
\begin{frame}{MST vs. shortest paths}
  \begin{exampleblock}{\pno{3.6.15}}
     \begin{itemize}
       \item \pno{3.6.15 (6)}: Dijkstra $\Rightarrow$ SSSP tree $\Rightarrow^{?}$ MST
       \item \pno{3.6.15 (7)}: $s \to t$ shortest path $\Rightarrow^{?} \subseteq \exists \text{ MST}$
     \end{itemize}
  \end{exampleblock}
\end{frame}
%%%%%%%%%%%%%
\begin{frame}{MST vs. shortest paths}
  \begin{exampleblock}{Sharing edges \pno{3.6.5}}
    \begin{itemize}
      \item $G = (V, E), w(e) > 0$
      \item Given $s$: all sssp trees from $s$ must share some edge with \textcolor{red}{all} (\textcolor{gray}{some}) MSTs of $G$
    \end{itemize}
  \end{exampleblock}

  \begin{block}{Solution}
    $E'$: lightest edges leaving $s$
    \begin{itemize}
      \item any MST $T$ of $G$: $T \cap E' \neq \emptyset$
      \item $E' \subset \forall \text{ sssp trees}$
    \end{itemize}
  \end{block}
\end{frame}
%%%%%%%%%%%%%


\section{Introduction}

The results of a Bayesian multivariate classifier are presented.
An explanation of its development is provided.
The classifier was trained to work with three categories $C_i$ and a
feature vector of size 2.

The classifier was trained using the Iris flower data set
\cite{fisher1936iris}, available from the UCI Machine
Learning Repository \footnote{https://archive.ics.uci.edu/ml/datasets/Iris}.
The dataset describes five properties of three different flower species:
petal length, petal width, sepal length, sepal width and variety.
Whilst the first four are quantitative traits, the last one is qualitative.
This trait describes the type flower associated with the entry:
Iris setosa, Iris versicolor and Iris virginica.
Figure \ref{fig: iris} presents the species in the dataset.

\begin{figure}[htb!]
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{Iris_versicolor_3}
        \caption{Iris versicolor}
        \label{fig: versicolor}
    \end{subfigure}
    ~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc.
      %(or a blank line to force the subfigure onto a new line)
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{Iris_virginica}
        \caption{Iris virginica}
        \label{fig: virginica}
    \end{subfigure}
    ~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc.
    %(or a blank line to force the subfigure onto a new line)
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{Kosaciec_szczecinkowaty_Iris_setosa}
        \caption{Iris setosa}
        \label{fig: setosa}
    \end{subfigure}
    \caption{Species in the iris dataset}\label{fig: iris}
\end{figure}

\section{Features in the data set}

From the data set, two groups of features are identified: length and width for petal and sepal.
To develop a classifier of size two, it is necessary to select the two entries from the feature vector
that will be used in the classifier.
Observing the grouping of datapoints for length and width
(Figure \ref{fig: dataset}) it becomes evident that the petal traits are ideal for the classifier.
This is due to how the data is already grouped into three easily identifiable groups.

\begin{figure}[htb!]
\centering
 \includegraphics[width=\textwidth]{dataset}
 \caption{Data clusters}
 \label{fig: dataset}
\end{figure}


%====================================================================================
\section{Motivation}
%====================================================================================

\begin{frame}{Unobserved-Heterogeneity}
	\begin{itemize}
		\item Controlling unobserved time invariant heterogeneity in cross-sectional models.
		\item Dynamics of cross-sectional populations through time; change in permanent component of each household or unit across time.
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Unobserved-Heterogeneity}
	\textbf{Identification problem}. Considering the following
		\begin{align*}
			\text{true model} \quad :& \quad Y=X_{1}\beta _{1}^{\ast }+X_{2}\beta_{2}+u \\
			\text{estimated model} \quad :& \quad Y=X_{1}\beta _{1}+u
		\end{align*}
	having the classical properties e.g $u$ is $i.i.d$. we estimate the model%
		\begin{align}
			\widehat{\beta }_{1} = &\left( X_{1}^{\prime }X_{1}\right)^{-1}X_{1}^{\prime }Y  \notag \\
			\widehat{\beta }_{1} = &\left( X_{1}^{\prime }X_{1}\right)
			^{-1}X_{1}^{\prime }\left( X_{1}\beta _{1}^{\ast }+X_{2}\beta _{2}+u\right)
			\notag \\
			\widehat{\beta}_{1} = &\beta_{1}^{\ast}+\left(X_{1}^{\prime}X_{1}\right)^{-1}X_{1}^{\prime}X_{2}\beta_{2}+\left(X_{1}^{\prime}X_{1}\right) ^{-1}X_{1}^{\prime}u
		\end{align}
	the estimator is biased.
\end{frame}
%------------------------------------------------
\begin{frame}{Unobserved-Heterogeneity}
		\begin{align}
			E\left( \widehat{\beta }_{1}\right) = &\beta _{1}^{\ast }+\left(X_{1}^{\prime }X_{1}\right) ^{-1}X_{1}^{\prime }X_{2}\beta _{2}  \notag \\
			E\left( \widehat{\beta }_{1}\right) = &\beta _{1}^{\ast }+\frac{cov\left(X_{1},X_{2}\right) }{var\left( X_{1}\right) }\beta _{2}
		\end{align}
	We have effects in the variance as well%
		\begin{gather}
			var\left( \widehat{\beta }_{1}\right) -var\left( \widehat{\beta }_{1}^{\ast}\right) =\sigma ^{-2}\left( \left( X_{1}^{\prime }X_{2}\right) \left(X_{1}^{\prime }X_{2}\right) ^{-1}\left( X_{1}^{\prime }X_{2}\right) \right)
		\end{gather}
	above expression is positive
\end{frame}
%------------------------------------------------
\begin{frame}{Unobserved-Heterogeneity}
	why is this important?
		\begin{figure}
			\centering
				\includegraphics[width = 0.6\linewidth]{figures/density.png}
		\end{figure}
\end{frame}
%------------------------------------------------
\begin{frame}{Unobserved-Heterogeneity}
	\textbf{Identification problem}. What if we have redundant variables?.Considering the following
		\begin{align*}
			\text{estimated model}\quad :& \quad Y=X_{1}\beta_{1}+X_{2}\beta_{2}+u \\
			\text{true model}\quad :& \quad Y=X_{1}\beta_{1}^{\ast}+u
		\end{align*}
	having the classical properties e.g $u$ is \emph{i.i.d}. In this particular case $X_{1}=\iota_{T}$ (the true model just has a constant). We estimate the model with the classical procedure of deviations from time means:
		\begin{align}
			\widehat{\beta}_{2} & = \left(\widetilde{X}_{2}^{\prime}\widetilde{X}_{2}\right)^{-1}\widetilde{X}_{2}^{\prime}\widetilde{Y} \notag \\
			\widehat{\beta}_{2} & = \left(\widetilde{X}_{2}^{\prime}\widetilde{X}_{2}\right)^{-1}\widetilde{X}_{2}^{\prime}\left(\widetilde{X}_{1}\beta_{1}^{\ast}+\widetilde{u}\right) \notag \\
			\widehat{\beta}_{2} & = 0
		\end{align}
	getting the constant $\beta_{1}^{\ast }=\overline{Y}-\overline{X}_{2}\widehat{\beta}_{2}=\overline{Y}$
\end{frame}
%------------------------------------------------
\begin{frame}{Unobserved-Heterogeneity motivation}
	If we have redundant variables in our regression model
		\begin{itemize}
			\item OLS estimator is unbiased and consistent
		\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Observables and Unobservables}
	In some cases we would expect correlation between unobservales and observables. For instance in the demand- and supply-equation model
		\begin{align}
			Q^{d} & = p^{\prime }\beta +\left( f^{\prime }\gamma +\epsilon \right) \label{demand equation} \\
			p     & = Q^{s\prime}\phi +\psi  \notag
		\end{align}
	being $\beta <0$ and $\phi >0.$ $f$ is an unobservable variable (shocks related to preferences, culture) In equilibrium:
			$$p=\frac{f^{\prime }\gamma \phi }{\left( 1-\beta \right) }+\frac{\epsilon \phi +\psi }{\left( 1-\beta \right)}$$
	So, $E\left( p,f\right) \not=0.$ In a regression model, we wonder if we have a demand or supply equation.
\end{frame}
%------------------------------------------------
\begin{frame}{Observables and Unobservables}
	\begin{itemize}
		\item Classical approach to pinpoint demand equation is to regress quantity on price, because of correlation between price and unobservable the classical strategy is useless.
		\item Strategies for identifying demand equation is available in econometric literature (see Gujarati). For example we suppose that supply equation is given by:
				$$p=\rho p_{-1}+Q^{s\prime }\lambda +\xi$$
		so a valid instrument should be $Z=p_{-1}$, thus the staregy of identification would be%
				$$Q^{d}=Z^{\prime }\beta +\zeta$$
		because of $E\left( Z,f\right) =0.$
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Observables and Unobservables}
	\begin{itemize}
		\item Earnings equations:
					$$wage_{it}=\alpha +\alpha _{s}\cdot schooling_{it}+\alpha_{u}Union_{it}+\varepsilon _{it}$$
			  thus estimator of $\alpha ^{\prime }s$ is $E\left( X_{it}\prime \varepsilon_{it}\right) =0.$ But, ability is correlated with schooling, so makes sense to have a model including a individual specific variable or endownment
					$$wage_{it}=\alpha +\alpha _{s}\cdot schooling_{it}+\alpha _{u}Union_{it}+\mu_{i}+\varepsilon _{it}$$
		\item Cost or production function (firm data). In a general sense $\mu _{i}$ measures a \emph{``managerial ability''} or \emph{``entrepreneurial''} ability or firm efficiency.
		\item Demand equation or consumption functions. Differences across states, countries or individuals.
	\end{itemize}
\end{frame}


\chapter{An Example of Mathematical Writing}
\index{An Example of Mathematical Writing%
@\emph{An Example of Mathematical Writing}}%

\section{Generalized Fatou's Lemma}
\index{Generalized Fatou's Lemma%
@\emph{Generalized Fatou's Lemma}}%

Here we show an application of the following lemma:

\begin{lem}[Generalized Fatou's Lemma] \label{l:fatou}

Let $A$ be a Dedekind ring and $F$ a rational series
in $A[[X]]$, i.e., $F = p/q$ for some
$p, q \in A[X]$. Then there exist two polynomials
$P, Q \in A[X]$ such that $F = P/Q$,
where $P$ and $Q$ are relatively prime and
$Q(0) = 1$.

\end{lem}

\proof
See \cite{bertin:psn}, p.~15, theorem~1.3.
\endproof

\begin{thm} \label{l:req}
Let $\{c_n\}_{n=-\infty}^{\infty}$ a set of
elements from $K$ such that $c_n \in k'$ for every
$n \geq n_0$, and verifying the following recurrence
relation of order M:
\begin{equation}
c_n\ =\ r_1\,c_{n-1} + r_2\,c_{n-2} + \dots + r_M\,c_{n-M}
\end{equation}
for every $n \in \mathbb Z$, where $r_1,r_2,\dots,r_M$ are in
$K$, $r_M \neq 0$.
Then:

\item{(i)} The coefficients $r_1,r_2,\dots,r_M$ are in
$k'$, and for every $n \in \mathbb Z$, $c_n \in k'$.

\item{(ii)} If $c_n \in \mathcal O_{k',v}$
for every $n \geq n_0$, then the coefficients
$r_1,r_2,\dots,r_M$ are all in
$\mathcal O_{k',v}$.

\end{thm}

\proof

\item{(i)} Let $C_n$ and $R$ be the matrices:

\begin{equation}
C_n\ =
\ \left(
\begin{array}{llll}
              c_n & c_{n+1} & \hdots & c_{n+M-1} \\
              c_{n+1} & c_{n+2} & \hdots  & c_{n+M} \\
              \vdots & \vdots & \ddots & \vdots \\
              c_{n+M-1} & c_{n+M} & \hdots & c_{n+2M-2}
\end{array}
\right)
\end{equation}
and
\begin{equation}
R\ =
\ \left(
\begin{array}{lllll}
              0 & 1 & 0 & \hdots & 0 \\
              0 & 0 & 1 & \hdots & 0 \\
             \vdots & \vdots & \vdots & \ddots & \vdots \\
              0 & 0 & 0 & \hdots & 1 \\
              r_M & r_{M-1} & r_{M-2} & \hdots & r_1
\end{array}
\right)
\end{equation}

We have that $C_{n+1} = R\,C_n$. Since the recurrence
relation is of order M, $C_n$ is non singular.
On the other hand, $R = C_{n+1}\,C_{n}^{-1}$. Since the
elements of $C_n$ are in $k'$ for $n \geq n_0$, the entries
of $R$, and those of $R^{-1}$, will be in $k'$. Since
$C_{n-1} = R^{-1}\,C_n$, we get that the entries of
$C_n$ will be in $k'$ also for $n < n_0$.

\item{(ii)} For each $t \geq n_0$ define the formal
power series

\begin{equation}
F_t(X)\ =\ \sum_{n=0}^{\infty} c_{t+n}\,X^n
\end{equation}
which is in $\mathcal O_{k',v}[[X]]$.
We have $F_t(X) = p_t(X)/q(X)$,
where $p_t(X),q(X) \in k'[X]$ are the following:
\begin{equation}
p_t(X)\ =\ \sum_{j=0}^{M-1} \Bigl( c_{t+j} -
                    \sum_{i=1}^{j} r_i\,c_{t+j-i} \Bigr)\,X^j
\end{equation}
\begin{equation}
q(X)\ =\ 1 - r_1\,X - r_2\,X^2 - \dots - r_M\,X^M
\end{equation}
This can be checked by multiplying $F_t(X)$ by $q_t(X)$
and using the recurrence relation, which gives
$F_t(X)\,q(X) = p_t(X)$ (see \cite{poorten:sp}).

Now we will prove that $p_t(X)$ and $q(X)$ are relatively
prime. To do so, we will see that they cannot have any
common root (in $\overline {k'}$). In fact, assume
that $\alpha$ is a common root of $p_{t_0}(X)$ and $q(X)$
for some $t_0 \geq n_0$, i.e.:
$p_{t_0}(\alpha) = q(\alpha) = 0$.
Since $q(0)=1$, then $\alpha \neq 0$. Now we have:
\begin{equation}
X\,F_{t_0+1}(X) = F_{t_0}(X) - c_{t_0}
\end{equation}
so:
\begin{multline}
X\,p_{t_0+1}(X) = X\,q(X)\,F_{t_0+1}(X) \\
= q(X)\,(F_{t_0}(X) - c_{t_0}) = p_{t_0}(X) - c_{t_0}\,q(X)
\end{multline}
Hence $p_{t_0+1}(\alpha) = 0$, which means that $\alpha$ is
also a root of $p_{t_0+1}(X)$. By induction we get that
$p_t(\alpha) = 0$ for every $t \geq t_0$. Grouping the
terms of $p_t(X)$ with respect to $c_t,c_{t+1},\dots,c_{t+M-1}$,
we get:
\begin{equation}
p_t(X) = \sum_{j=0}^{M-1} a_j(X)\,c_{t+j}
\end{equation}
where
\begin{equation}
a_j(X) = X^j\,\Bigl( 1 - \sum_{i=1}^{M-j-1} r_i\,X^i \Bigr)
\end{equation}
Note that $a_0(X),a_1(X),\dots,a_{M-1}(X)$ do not depend on t.
On the other hand $p_t(\alpha)=0$ implies
\begin{equation}
\label{e:coldep}
\sum_{j=0}^{M-1} a_j(\alpha)\,c_{t+j} = 0
\end{equation}
for every $t \geq t_0$. Note that $a_{M-1}(\alpha)=\alpha^{M-1}
\neq 0$, so $a_0(\alpha),a_1(\alpha),\dots,a_{M-1}(\alpha)$
are not all zero, and (\ref{e:coldep}) means that the columns
of the matrix $C_{t_0}$ are linearly dependent, so
$\det C_{t_0}=0$, which contradicts the fact that $C_{t_0}$
is non singular. Hence, the hypothesis that $p_t(X)$ and
$q(X)$ have a common root has to be false. This proves that
$p_t(X)$ and $q(X)$ are relatively prime.

By (generalized Fatou's) lemma~\ref{l:fatou},
and taking into account that
$\mathcal O_{k',v}$ is a Dedekind ring,
we get that there exist two relatively prime
polynomials $P_t(X)$ and $Q_t(X)$ in
$\mathcal O_{k',v}[X]$ such that
$F_t(X) = P_t(X)/Q_t(X)$ and $Q_t(0)=1$. Hence:
$p_t(X)\,Q_t(X) = q(X)\,P_t(X)$. By unique factorization
of polynomials in $k'[X]$, there is a $u \in k'$ such that
$P_t(X) = u\,p_t(X)$ and $Q_t(X) = u\,q_t(X)$. Since
$Q_t(0)=q(0)=1$, we get that $u=1$, so
$P_t(X) = p_t(X)$ and $Q_t(X) = q(X)$.
Hence, the coefficients of $q(X)$ are in
$\mathcal O_{k',v}$.

\endproof

\section{Other Examples of Mathematical Writing}

\subsection{An Example of a Commutative Diagram}
\index{An Example of a Commutative Diagram%
@{An Example of a Commutative Diagram}}%

The following is an example of a commutative diagram.
\index{commutative diagram}%
It requires the \texttt{amscd} package.
\index{amscd package@{\texttt{amscd} package}}

\begin{equation*}
\newcommand{\End}{\operatorname{End}}
\begin{CD}
S^{{\mathcal{W}}_\Lambda}\otimes T   @>j>>   T\\
@VVV                                    @VV{\End P}V\\
(S\otimes T)/I                  @=      (Z\otimes T)/J
\end{CD}
\end{equation*}

That diagram has been made with the following commands:

\begin{verbatim}
\newcommand{\End}{\operatorname{End}}
\begin{CD}
S^{{\mathcal{W}}_\Lambda}\otimes T   @>j>>   T\\
@VVV                                    @VV{\End P}V\\
(S\otimes T)/I                  @=      (Z\otimes T)/J
\end{CD}
\end{verbatim}

\subsection{Using AMS Fonts}
\index{Using AMS Fonts@{Using AMS Fonts}}

To use AMS fonts it is necessary to choose from an assortment
of \LaTeX{} packages. For instance the command
\cn{usepackage\{amsfonts\}} calls in the \emph{amsfonts} package,
which provides blackboard bold letters (e.g. $\mathbb{R}$) and
some math symbols. A superset of that package is
\emph{amssymb}. Other packages are \emph{eufrak}
for Frankfurt letters (e.g. $\mathfrak{R}$)
and \emph{eucal} for Euler script
(e.g. $\mathcal{R}$).
Consult the \LaTeX{} documentation about this subject
for additional information.


% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.

\subsection*{gaussian.m}

\begin{par}
\textbf{Summary:} Generate n samples from a Gaussian \$p(x)=\ensuremath{\backslash}mathcal N(m,S). Sampling is based on the Cholesky factorization of the covariance matrix S
\end{par} \vspace{1em}

\begin{verbatim}  function x = gaussian(m, S, n)\end{verbatim}
    \begin{par}
\textbf{Input arguments:}
\end{par} \vspace{1em}
\begin{verbatim}m      mean of Gaussian                                         [D x 1]
S      covariance matrix of Gaussian                            [D x D]
n      (optional) number of samples; default: n=1\end{verbatim}
\begin{par}
\textbf{Output arguments:}
\end{par} \vspace{1em}
\begin{verbatim}x      matrix of samples from Gaussian                          [D x n]\end{verbatim}
\begin{par}
Copyright (C) 2008-2013 by Marc Deisenroth, Andrew McHutchon, Joe Hall, and Carl Edward Rasmussen.
\end{par} \vspace{1em}
\begin{par}
Last modified: 2013-03-21
\end{par} \vspace{1em}

\begin{lstlisting}
function x = gaussian(m, S, n)
\end{lstlisting}

\subsection*{Code}

\begin{lstlisting}
if nargin < 3; n = 1; end

x = bsxfun(@plus, m(:), chol(S)'*randn(size(S,2),n));
\end{lstlisting}