\section{Fluxograma do Tableau}
\subsection{Problema de Maximização}

\begin{frame}
\frametitle{Fluxograma Tableau Simplex - \color{pink!100} MAXIMIZAÇÃO}
	\centering
	\begin{tikzpicture} [
							auto, node distance = 2cm,
							decisao/.style = { diamond, draw, shape aspect=2, thick, fill=red!20,
							                   text width=6em, text badly centered,
							                   inner sep=1pt},
							bloco/.style   = { rectangle, draw, thick, fill=blue!20,
												text width=5em, text centered,
							                   minimum height=1em },
							bloco2/.style   = { rectangle, draw, thick, fill=blue!20,
												text width=5em, text centered,
							                   minimum height=1em, node distance = 4.2cm },
							extremo/.style  = { ellipse, draw, fill=green!20,
							                   text width=5em, text centered,
							                   minimum height=2em },
							line/.style   = { draw, -latex' },
							goto/.style = {circle, draw, fill=yellow!60, text width=1em,
										   text centered, node distance = 1.8cm},
						    bullet/.style = {rectangle, draw, thick, fill=red!80,
						    				text width=9em, text centered,
						    				minimum height=1em},
						]

		\node [extremo] (inic) {\tiny INÍCIO}; \pause

		\node [bloco, below of = inic] (sbfi) {\tiny Montar Tableau Simplex com SBF Inicial};
		\path [line] (inic) -- (sbfi); \pause

		\node [decisao, below of = sbfi] (conv) {\tiny Existe Custo (coeficientes) $<$ 0 ?} ;
		\path [line] (sbfi) -- (conv); \pause

		\node[bloco, below of = conv] (otimo) {\tiny Solução Ótima};
		\path [line] (conv) -- node [near start] {\scriptsize \color{red} não} (otimo);
	    \node [extremo] at (2,-7.2) (fim) {\tiny Fim};
	    \path [line] (otimo) |- (2,-6.5) -- (fim); \pause

		\node[bloco2, right of = inic] (escolhe) {\tiny Escolher Variável Entrar na Base};
		\path [line] (conv) -| (2.2, 0) node [near start] {\scriptsize \color{red} sim} -- (escolhe); \pause

		\node[bloco, below of = escolhe] (razao) {\tiny Calcular Razão $ \frac{b_i}{coluna}$};
		\path [line] (escolhe) -- (razao); \pause

		\node [decisao, below of = razao] (finito) {\tiny Existe Razão $\ge 0$ finita ?} ;
		\path [line] (razao) -- (finito); \pause

		\node[bloco, below of = finito] (ilimit) {\tiny Solução Ilimitada};
		\path [line] (finito) -- node [near start] {\scriptsize \color{red} não} (ilimit);
		\path [line] (ilimit) |- (2,-6.5) -- (fim); \pause

		\node[bloco2, right of = razao] (saibase) {\tiny Escolher Variável Sair da Base};
		\path [line] (finito) -| (6.2, -2) node [near start] {\scriptsize \color{red} sim} -- (saibase); \pause

		\node[bloco, below of = saibase] (swap) {\tiny Troca Base e Recalc. Tableau};
		\path[line] (saibase) -- (swap); \pause

		\node[goto, below of = swap] (pula_a) {\tiny 1};
		\node[goto, left of = sbfi] (pula_b) {\tiny 1};
		\path[line] (pula_b) -- (conv);
		\path[line] (swap) -- (pula_a); \pause

		%\only<2>
		%{
			\node[bullet] at (7.5,-0.2) (obs1) {\tiny Coef mais negativo FOB};
			\path[line] (obs1) -- (escolhe);
		%}

		%\only<3>
		%{
			\node[bullet] at (7.7,-1) (obs2) {\tiny Menor Razão Positiva};
			\path[line] (obs2) -- (saibase);
		%}

	\end{tikzpicture}
\end{frame}

\begin{frame}
	\frametitle{\includegraphics[width=0.6cm,height=0.6cm]{number_4.jpg} \hspace{0.2cm} Passos da Resolução do PPL via Tableau Simplex}

	\only<1-2>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 4$
				&
				&
				& \\
				\cline{1-8}
			    \cellcolor{blue!100} \color{red} $\scriptstyle S_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 12$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 3$
				& \cellcolor{yellow!50} $\scriptstyle 2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 18$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle -3$
				& \cellcolor{yellow!50} $\scriptstyle -5$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				&
				&
				& \\
				\cline{1-8}
			\end{tabular}
		\end{table}
	}
	\only<3>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 4$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 12$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 3$
				& \cellcolor{gray!50} $\scriptstyle 2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 18$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle -3$
				& \cellcolor{gray!50} $\scriptstyle -5$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				&
				&
				& \\
				\cline{1-8}
				&
				&
				& \includegraphics[width=0.3cm,height=0.3cm]{setacima.jpg}
				&
				&
				&
				&
				&
				&
				& \\
				&
				&
				& \scriptsize \color{red} Entra
				&
				&
				&
				&
				&
				&
				& \\
				&
				&
				& \scriptsize \color{red} Base
				&
				&
				&
				&
				&
				&
				& \\

			\end{tabular}
		\end{table}
	}
	\only<4>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 4$
				& $ \scriptstyle \color{red} 4 \div 0 = \infty $
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 12$
				& $ \scriptstyle \color{red} 12 \div 2 = +6 $
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 3$
				& \cellcolor{gray!50} $\scriptstyle 2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 18$
				& $ \scriptstyle \color{red} 18 \div 2 = +9 $
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle -3$
				& \cellcolor{gray!50} $\scriptstyle -5$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				&
				&
				& \\
				\cline{1-8}
				&
				&
				& \includegraphics[width=0.3cm,height=0.3cm]{setacima.jpg}
				&
				&
				&
				&
				&
				&
				& \\
				&
				&
				& \scriptsize \color{red} Entra
				&
				&
				&
				&
				&
				&
				& \\
				&
				&
				& \scriptsize \color{red} Base
				&
				&
				&
				&
				&
				&
				& \\

			\end{tabular}
		\end{table}
	}
	\only<5>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 4$
				& $ \scriptstyle \color{red} 4 \div 0 = \infty $
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 12$
				& $ \scriptstyle \color{red} 12 \div 2 = +6 $
				& \includegraphics[width=0.3cm,height=0.2cm]{setaesquerda.jpg}
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 3$
				& \cellcolor{gray!50} $\scriptstyle 2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 18$
				& $ \scriptstyle \color{red} 18 \div 2 = +9 $
				& \includegraphics[width=0.3cm,height=0.2cm]{setaesquerda.jpg}
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle -3$
				& \cellcolor{gray!50} $\scriptstyle -5$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				&
				&
				& \\
				\cline{1-8}
				&
				&
				& \includegraphics[width=0.3cm,height=0.3cm]{setacima.jpg}
				&
				&
				&
				&
				&
				&
				& \\
				&
				&
				& \scriptsize \color{red} Entra
				&
				&
				&
				&
				&
				&
				& \\
				&
				&
				& \scriptsize \color{red} Base
				&
				&
				&
				&
				&
				&
				& \\

			\end{tabular}
		\end{table}
	}
	\only<6>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 4$
				& $ \scriptstyle \color{red} 4 \div 0 = \infty $
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_2$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 2$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 12$
				& $ \scriptstyle \color{red} 12 \div 2 = +6 $
				& \scriptsize \includegraphics[width=0.3cm,height=0.2cm]{setaesquerda.jpg}
				& \scriptsize \color{red} Sai Base \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 3$
				& \cellcolor{gray!50} $\scriptstyle 2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 18$
				& $ \scriptstyle \color{red} 18 \div 2 = +9 $
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle -3$
				& \cellcolor{gray!50} $\scriptstyle -5$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				&
				&
				& \\
				\cline{1-8}
				&
				&
				& \includegraphics[width=0.3cm,height=0.3cm]{setacima.jpg}
				&
				&
				&
				&
				&
				&
				& \\
				&
				&
				& \scriptsize \color{red} Entra
				&
				&
				&
				&
				&
				&
				& \\
				&
				&
				& \scriptsize \color{red} Base
				&
				&
				&
				&
				&
				&
				& \\

			\end{tabular}
		\end{table}
	}
	\only<7-8>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 4$
				& $ \scriptstyle \color{red} 4 \div 0 = \infty $
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{red!50} $\scriptstyle 2$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 12$
				& $ \scriptstyle \color{red} 12 \div 2 = +6 $
				& \scriptsize \includegraphics[width=0.3cm,height=0.2cm]{setaesquerda.jpg}
				& \scriptsize \color{red} Sai Base \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 3$
				& \cellcolor{gray!50} $\scriptstyle 2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 18$
				& $ \scriptstyle \color{red} 18 \div 2 = +9 $
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle -3$
				& \cellcolor{gray!50} $\scriptstyle -5$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				&
				&
				& \\
				\cline{1-8}
				&
				&
				& \includegraphics[width=0.3cm,height=0.3cm]{setacima.jpg}
				&
				&
				&
				&
				&
				&
				& \\
				&
				&
				& \scriptsize \color{red} Entra
				&
				&
				&
				&
				&
				&
				& \\
				&
				&
				& \scriptsize \color{red} Base
				&
				&
				&
				&
				&
				&
				& \\
			\end{tabular}
		\end{table}
	}
	% Recomeça
	\only<9-10>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 4$
				&
				&
				& \\
				\cline{1-8}
			    \cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 6$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle -1$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 6$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle -3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 5/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 30$
				&
				&
				& \\
				\cline{1-8}
			\end{tabular}
		\end{table}
	}
	\only<11>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 4$
				&
				&
				& \\
				\cline{1-8}
			    \cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 6$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle -1$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 6$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle -3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 5/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 30$
				&
				&
				& \\
				\cline{1-8}
				&
				& \includegraphics[width=0.3cm,height=0.3cm]{setacima.jpg}
				&
				&
				&
				&
				&
				&
				&
				& \\
				&
				& \scriptsize \color{red} Entra
				&
				&
				&
				&
				&
				&
				&
				& \\
				&
				& \scriptsize \color{red} Base
				&
				&
				&
				&
				&
				&
				&
				& \\
			\end{tabular}
		\end{table}
	}
	\only<12>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 4$
				& $\scriptstyle \color{red} 4 \div 1 = +4$
				&
				& \\
				\cline{1-8}
			    \cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 6$
				& $\scriptstyle \color{red}  6 \div 0 = \infty$
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle -1$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 6$
				& $\scriptstyle \color{red}  6 \div 3 = +2$
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle -3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 5/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 30$
				&
				&
				& \\
				\cline{1-8}
				&
				& \includegraphics[width=0.3cm,height=0.3cm]{setacima.jpg}
				&
				&
				&
				&
				&
				&
				&
				& \\
				&
				& \scriptsize \color{red} Entra
				&
				&
				&
				&
				&
				&
				&
				& \\
				&
				& \scriptsize \color{red} Base
				&
				&
				&
				&
				&
				&
				&
				& \\
			\end{tabular}
		\end{table}
	}
	\only<13>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 4$
				& $\scriptstyle  \color{red} 4 \div 1 = +4$
				& \includegraphics[width=0.3cm,height=0.3cm]{setaesquerda.jpg}
				& \\
				\cline{1-8}
			    \cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 6$
				& $\scriptstyle  \color{red} 6 \div 0 = \infty$
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle -1$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 6$
				& $\scriptstyle  \color{red} 6 \div 3 = +2$
				& \includegraphics[width=0.3cm,height=0.3cm]{setaesquerda.jpg}
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle -3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 5/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 30$
				&
				&
				& \\
				\cline{1-8}
				&
				& \includegraphics[width=0.3cm,height=0.3cm]{setacima.jpg}
				&
				&
				&
				&
				&
				&
				&
				& \\
				&
				& \scriptsize \color{red} Entra
				&
				&
				&
				&
				&
				&
				&
				& \\
				&
				& \scriptsize \color{red} Base
				&
				&
				&
				&
				&
				&
				&
				& \\
			\end{tabular}
		\end{table}
	}
	\only<14>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{white} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 4$
				& $\scriptstyle  \color{red} 4 \div 1 = +4$
				&
				& \\
				\cline{1-8}
			    \cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 6$
				& $\scriptstyle  \color{red} 6 \div 0 = \infty$
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_3$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 3$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle -1$
				& \cellcolor{gray!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 6$
				& $\scriptstyle  \color{red} 6 \div 3 = +2$
				& \includegraphics[width=0.3cm,height=0.3cm]{setaesquerda.jpg}
				& \scriptsize \color{red} Sai Base\\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle -3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 5/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 30$
				&
				&
				& \\
				\cline{1-8}
				&
				& \includegraphics[width=0.3cm,height=0.3cm]{setacima.jpg}
				&
				&
				&
				&
				&
				&
				&
				& \\
				&
				& \scriptsize \color{red} Entra
				&
				&
				&
				&
				&
				&
				&
				& \\
				&
				& \scriptsize \color{red} Base
				&
				&
				&
				&
				&
				&
				&
				& \\
			\end{tabular}
		\end{table}
	}
	\only<15-16>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{red} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{white} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 4$
				& $\scriptstyle  \color{red} 4 \div 1 = +4$
				&
				& \\
				\cline{1-8}
			    \cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 6$
				& $\scriptstyle  \color{red} 6 \div 0 = \infty$
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle X_1$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{red!50} $\scriptstyle 3$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle -1$
				& \cellcolor{gray!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle 6$
				& $\scriptstyle  \color{red} 6 \div 3 = +2$
				& \includegraphics[width=0.3cm,height=0.3cm]{setaesquerda.jpg}
				& \scriptsize \color{red} Sai Base\\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{gray!50} $\scriptstyle -3$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 5/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{gray!50} $\scriptstyle 30$
				&
				&
				& \\
				\cline{1-8}
				&
				& \includegraphics[width=0.3cm,height=0.3cm]{setacima.jpg}
				&
				&
				&
				&
				&
				&
				&
				& \\
				&
				& \scriptsize \color{red} Entra
				&
				&
				&
				&
				&
				&
				&
				& \\
				&
				& \scriptsize \color{red} Base
				&
				&
				&
				&
				&
				&
				&
				& \\
			\end{tabular}
		\end{table}
	}
	\only<17-20>
	{
		\begin{table}
			\begin{tabular}{c c c c c c c c c c c}
				\cline{1-8}
				\cellcolor{blue!100} \color{white} \scriptsize Base
				&\cellcolor{blue!100} \color{white} \scriptsize Z
				&\cellcolor{blue!100} \color{red} $\scriptstyle X_1$
				&\cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				&\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				&\cellcolor{blue!100} \color{white} $\scriptstyle S_2$
				&\cellcolor{blue!100} \color{white} $\scriptstyle S_3$
				&\cellcolor{blue!100} \color{white} \scriptsize b
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle S_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 1/3$
				& \cellcolor{yellow!50} $\scriptstyle -1/3$
				& \cellcolor{yellow!50} $\scriptstyle 2$
				&
				&
				& \\
				\cline{1-8}
			    \cellcolor{blue!100} \color{red} $\scriptstyle X_2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1/2$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 6$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{red} $\scriptstyle X_1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle -1/3$
				& \cellcolor{yellow!50} $\scriptstyle 1/3$
				& \cellcolor{yellow!50} $\scriptstyle 2$
				&
				&
				& \\
				\cline{1-8}
				\cellcolor{blue!100} \color{white} $\scriptstyle Z$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 0$
				& \cellcolor{yellow!50} $\scriptstyle 3/2$
				& \cellcolor{yellow!50} $\scriptstyle 1$
				& \cellcolor{yellow!50} $\scriptstyle 36$
				&
				&
				& \\
				\cline{1-8}
			\end{tabular}
		\end{table}
	}

	\begin{columns}
		\begin{column}{0.5\textwidth}
		\only<1>
		{
			\begin{mdframed}[backgroundcolor=orange!80]
				Parte da Solução Básica Factível (SBF)	inicial.
			\end{mdframed}
		}
		\only<2>
		{
			\begin{mdframed}[backgroundcolor=olive!80]
				Verificar se a solução é ótima! (Linha de Z).
			\end{mdframed}
		}
		\only<3>
		{
			\begin{mdframed}[backgroundcolor=orange!80]
				Escolhe variável com coeficiente mais negativo na FOB para entrar na base.
			\end{mdframed}
		}
		\only<4>
		{
			\begin{mdframed}[backgroundcolor=olive!80]
				Para cada linha do Tableau calcular razão $\frac{b_i}{\text{coluna}}$.
			\end{mdframed}
		}
		\only<5>
		{
			\begin{mdframed}[backgroundcolor=orange!80]
				Verifica se existe razão positiva e finita.
			\end{mdframed}
		}
		\only<6>
		{
			\begin{mdframed}[backgroundcolor=olive!80]
				A linha com a menor razão positiva finita sairá da base.
			\end{mdframed}
		}
		\only<7>
		{
			\underline{\textbf{Troca de Base}}
			\begin{mdframed}[backgroundcolor=orange!80]
				Cada linha da tabela deve possuir apenas uma VB com coeficiente unitário.
			\end{mdframed}
		}
		\only<8>
		{
			\scriptsize Zerar a coluna de $X_2$ com exceção da linha referente ao pivô que deve assumir o valor unitário. Para tanto:
			\begin{mdframed}[backgroundcolor=olive!80]
					\centering
					$
						\begin{matrix}
							\text{Linha}'_1 = \text{Linha}_1 \\
							\text{Linha}'_3 = \text{Linha}_3 - \text{Linha}_2\\
							\text{Linha}'_4 = \text{Linha}_4 + \frac{2}{5}\text{Linha}_2 \\
							\text{Linha}'_2 = \frac{1}{2}\text{Linha}_2 \\
						\end{matrix}
					$
			\end{mdframed}
		}
		\only<9>
		{
			\begin{mdframed}[backgroundcolor=orange!80]
				Novo Tableau !!!!
			\end{mdframed}
			Linhas com apenas uma VB com coeficiente unitário.
		}
		\only<10>
		{
			\begin{mdframed}[backgroundcolor=olive!80]
				Verificar se a solução é ótima! (Linha de Z).
			\end{mdframed}
		}
		\only<11>
		{
			\begin{mdframed}[backgroundcolor=orange!80]
				Escolhe variável com coeficiente mais negativo na FOB para entrar na base.
			\end{mdframed}
		}
		\only<12>
		{
			\begin{mdframed}[backgroundcolor=olive!80]
				Para cada linha do Tableau calcular razão $\frac{b_i}{\text{coluna}}$.
			\end{mdframed}
		}
		\only<13>
		{
			\begin{mdframed}[backgroundcolor=orange!80]
				Verifica se existe razão positiva e finita.
			\end{mdframed}
		}
		\only<14>
		{
			\begin{mdframed}[backgroundcolor=olive!80]
				A linha com a menor razão positiva finita sairá da base.
			\end{mdframed}
		}
		\only<15>
		{
			\underline{\textbf{Troca de Base}}
			\begin{mdframed}[backgroundcolor=orange!80]
				Cada linha da tabela deve possuir apenas uma VB com coeficiente unitário.
			\end{mdframed}
		}
		\only<16>
		{
			\scriptsize Zerar a coluna de $X_1$ com exceção da linha referente ao pivô que deve assumir o valor unitário. Para tanto:
			\begin{mdframed}[backgroundcolor=olive!80]
					\centering
					$
						\begin{matrix}
							\text{Linha}'_1 = \text{Linha}_1 - \frac{1}{3}\text{Linha}_3\\
							\text{Linha}'_2 = \text{Linha}_2\\
							\text{Linha}'_4 = \text{Linha}_4 + \text{Linha}_3 \\
							\text{Linha}'_3 = \frac{1}{3}\text{Linha}_3 \\
						\end{matrix}
					$
			\end{mdframed}
		}
		\only<17>
		{
			\begin{mdframed}[backgroundcolor=orange!80]
				Novo Tableau !!!!
			\end{mdframed}
			Linhas com apenas uma VB com coeficiente unitário.
		}
		\only<18>
		{
			\begin{mdframed}[backgroundcolor=olive!80]
				Verificar se a solução é ótima! (Linha de Z).
			\end{mdframed}
		}
		\only<19>
		{
			\begin{mdframed}[backgroundcolor=red!80]
				\centering
				OPTIMAL SOLUTION FOUND !!!!
			\end{mdframed}
		}
		\only<20>
		{
			\begin{table}
				\begin{tabular}{ c | c | c |}
					\hline
					\cellcolor{blue!100} \color{white}\scriptsize Tipo     &
					\cellcolor{blue!100} \color{white} \scriptsize Variável &
					\cellcolor{blue!100} \color{white} \scriptsize Valor \\
					\hline
					\cellcolor{green!100} \multirow{3}{1cm}{VB}  &
					\cellcolor{green!100} $\scriptstyle X_1$   &
					\cellcolor{green!100} $\scriptstyle 2$   \\
					\cellcolor{green!100} VB & \cellcolor{green!100} $\scriptstyle X_2$   &
					\cellcolor{green!100} $\scriptstyle 6$   \\
					\cellcolor{green!100} & \cellcolor{green!100} $\scriptstyle S_1$   &
					\cellcolor{green!100} $\scriptstyle 2$   \\
					\multirow{2}{1cm}{ VNB} &
					$\scriptstyle S_2$   &
					$\scriptstyle 0$   \\
					& $\scriptstyle S_3$   &
					$\scriptstyle 0$   \\
					\cellcolor{green!100}FOB 				 &
					\cellcolor{green!100} $\scriptstyle Z$     &
					\cellcolor{green!100} $\scriptstyle 36$  \\
					\hline
				\end{tabular}
			\end{table}
		}

		\end{column}
		\begin{column}{0.5\textwidth}
			\only<1>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_1.png}
			}
			\only<2>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_2.png}
			}
			\only<3>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_3.png}
			}
			\only<4>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_4.png}
			}
			\only<5>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_5.png}
			}
			\only<6>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_6.png}
			}
			\only<7-8>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_7.png}
			}
			\only<9>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_9.png}
			}
			\only<10>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_2.png}
			}
			\only<11>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_3.png}
			}
			\only<12>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_4.png}
			}
			\only<13>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_5.png}
			}
			\only<14>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_6.png}
			}
			\only<15-16>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_7.png}
			}
			\only<17>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_9.png}
			}
			\only<18>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_2.png}
			}
			\only<19-20>
			{
				\includegraphics[width=5.5cm,height=3cm]{Alg_8.png}
			}
		\end{column}
	\end{columns}
\end{frame}

\subsection{Problema de Minimização}
\begin{frame}
	\only<1>
	{
		\frametitle{Fluxograma Tableau Simplex - \color{pink!100} MAXIMIZAÇÃO}
	}
	\only<2>
	{
		\frametitle{Fluxograma Tableau Simplex - \color{cyan!100} MINIMIZAÇÃO}
	}

	\centering
	\only<1>
	{
	\begin{tikzpicture} [
							auto, node distance = 2cm,
							decisao/.style = { diamond, draw, shape aspect=2, thick, fill=red!20,
							                   text width=6em, text badly centered,
							                   inner sep=1pt},
							bloco/.style   = { rectangle, draw, thick, fill=blue!20,
												text width=5em, text centered,
							                   minimum height=1em },
							bloco2/.style   = { rectangle, draw, thick, fill=blue!20,
												text width=5em, text centered,
							                   minimum height=1em, node distance = 4.2cm },
							extremo/.style  = { ellipse, draw, fill=green!20,
							                   text width=5em, text centered,
							                   minimum height=2em },
							line/.style   = { draw, -latex' },
							goto/.style = {circle, draw, fill=yellow!60, text width=1em,
										   text centered, node distance = 1.8cm},
						    bullet/.style = {rectangle, draw, thick, fill=red!80,
						    				text width=9em, text centered,
						    				minimum height=1em},
						]

		\node [extremo] (inic) {\tiny INÍCIO};

		\node [bloco, below of = inic] (sbfi) {\tiny Montar Tableau Simplex com SBF Inicial};
		\path [line] (inic) -- (sbfi);

		\node [decisao, below of = sbfi] (conv) {\tiny Existe Custo (coeficientes) $<$ 0 ?} ;
		\path [line] (sbfi) -- (conv);

		\node[bloco, below of = conv] (otimo) {\tiny Solução Ótima};
		\path [line] (conv) -- node [near start] {\scriptsize \color{red} não} (otimo);
	    \node [extremo] at (2,-7.2) (fim) {\tiny Fim};
	    \path [line] (otimo) |- (2,-6.5) -- (fim);

		\node[bloco2, right of = inic] (escolhe) {\tiny Escolher Variável Entrar na Base};
		\path [line] (conv) -| (2.2, 0) node [near start] {\scriptsize \color{red} sim} -- (escolhe);

		\node[bloco, below of = escolhe] (razao) {\tiny Calcular Razão $ \frac{b_i}{coluna}$};
		\path [line] (escolhe) -- (razao);

		\node [decisao, below of = razao] (finito) {\tiny Existe Razão $\ge 0$ finita ?} ;
		\path [line] (razao) -- (finito);

		\node[bloco, below of = finito] (ilimit) {\tiny Solução Ilimitada};
		\path [line] (finito) -- node [near start] {\scriptsize \color{red} não} (ilimit);
		\path [line] (ilimit) |- (2,-6.5) -- (fim);

		\node[bloco2, right of = razao] (saibase) {\tiny Escolher Variável Sair da Base};
		\path [line] (finito) -| (6.2, -2) node [near start] {\scriptsize \color{red} sim} -- (saibase);

		\node[bloco, below of = saibase] (swap) {\tiny Troca Base e Recalc. Tableau};
		\path[line] (saibase) -- (swap);

		\node[goto, below of = swap] (pula_a) {\tiny 1};
		\node[goto, left of = sbfi] (pula_b) {\tiny 1};
		\path[line] (pula_b) -- (conv);
		\path[line] (swap) -- (pula_a);

		\node[bullet] at (7.5,-0.2) (obs1) {\tiny Coef mais negativo FOB};
		\path[line] (obs1) -- (escolhe);

		\node[bullet] at (7.7,-1) (obs2) {\tiny Menor Razão Positiva};
		\path[line] (obs2) -- (saibase);

	\end{tikzpicture}
	}

	\only<2>
	{
	\begin{tikzpicture} [
							auto, node distance = 2cm,
							decisao/.style = { diamond, draw, shape aspect=2, thick, fill=red!20,
							                   text width=6em, text badly centered,
							                   inner sep=1pt},
							bloco/.style   = { rectangle, draw, thick, fill=blue!20,
												text width=5em, text centered,
							                   minimum height=1em },
							bloco2/.style   = { rectangle, draw, thick, fill=blue!20,
												text width=5em, text centered,
							                   minimum height=1em, node distance = 4.2cm },
							extremo/.style  = { ellipse, draw, fill=green!20,
							                   text width=5em, text centered,
							                   minimum height=2em },
							line/.style   = { draw, -latex' },
							goto/.style = {circle, draw, fill=yellow!60, text width=1em,
										   text centered, node distance = 1.8cm},
						    bullet/.style = {rectangle, draw, thick, fill=red!80,
						    				text width=9em, text centered,
						    				minimum height=1em},
							decisao2/.style = { diamond, draw, shape aspect=2, thick, fill=cyan!80,
							                   text width=6em, text badly centered,
							                   inner sep=1pt},
						    bullet2/.style = {rectangle, draw, thick, fill=cyan!80,
						    				text width=9em, text centered,
						    				minimum height=1em},
						]

		\node [extremo] (inic) {\tiny INÍCIO};

		\node [bloco, below of = inic] (sbfi) {\tiny Montar Tableau Simplex com SBF Inicial};
		\path [line] (inic) -- (sbfi);

		\node [decisao2, below of = sbfi] (conv) {\tiny Existe Custo (coeficientes) $>$ 0 ?} ;
		\path [line] (sbfi) -- (conv);

		\node[bloco, below of = conv] (otimo) {\tiny Solução Ótima};
		\path [line] (conv) -- node [near start] {\scriptsize \color{red} não} (otimo);
	    \node [extremo] at (2,-7.2) (fim) {\tiny Fim};
	    \path [line] (otimo) |- (2,-6.5) -- (fim);

		\node[bloco2, right of = inic] (escolhe) {\tiny Escolher Variável Entrar na Base};
		\path [line] (conv) -| (2.2, 0) node [near start] {\scriptsize \color{red} sim} -- (escolhe);

		\node[bloco, below of = escolhe] (razao) {\tiny Calcular Razão $ \frac{b_i}{coluna}$};
		\path [line] (escolhe) -- (razao);

		\node [decisao, below of = razao] (finito) {\tiny Existe Razão $\ge 0$ finita ?} ;
		\path [line] (razao) -- (finito);

		\node[bloco, below of = finito] (ilimit) {\tiny Solução Ilimitada};
		\path [line] (finito) -- node [near start] {\scriptsize \color{red} não} (ilimit);
		\path [line] (ilimit) |- (2,-6.5) -- (fim);

		\node[bloco2, right of = razao] (saibase) {\tiny Escolher Variável Sair da Base};
		\path [line] (finito) -| (6.2, -2) node [near start] {\scriptsize \color{red} sim} -- (saibase);

		\node[bloco, below of = saibase] (swap) {\tiny Troca Base e Recalc. Tableau};
		\path[line] (saibase) -- (swap);

		\node[goto, below of = swap] (pula_a) {\tiny 1};
		\node[goto, left of = sbfi] (pula_b) {\tiny 1};
		\path[line] (pula_b) -- (conv);
		\path[line] (swap) -- (pula_a);

		\node[bullet2] at (7.5,-0.2) (obs1) {\tiny Coef mais positivo FOB};
		\path[line] (obs1) -- (escolhe);

		\node[bullet] at (7.7,-1) (obs2) {\tiny Menor Razão Positiva};
		\path[line] (obs2) -- (saibase);

	\end{tikzpicture}
	}

\end{frame}


\section{3D DP}

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{3-D DP}
  \begin{exampleblock}{Floyd-Warshall algorithm}
	\begin{enumerate}[(1)]
	  \item DP for Floyd-Warshall algorithm for APSP on \textcolor{red}{directed} graphs
	\end{enumerate}
  \end{exampleblock}

  \begin{description}
	\item[Subproblem:] $\text{dist}[i,j,k]$: the length of the shortest path from $i$ to $j$ via only nodes in $v_{1} \cdots v_{k}$
	\item[Goal:] $\text{dist}[i,j,n], \forall i,j$
  \end{description}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{3-D DP}
  \begin{exampleblock}{Floyd-Warshall algorithm}
	\begin{enumerate}[(1)]
	  \item DP for Floyd-Warshall algorithm for APSP on \textcolor{red}{directed} graphs
	\end{enumerate}
  \end{exampleblock}

  \begin{description}
	\item[Make choice:] Is $v_{k}$ on the $\text{ShortestPath}[i,j,k]$?
	\item[Recurrence:]
	  \[
		\text{dist}[i,j,k] = \min \set{\text{dist}[i,j,k-1], \text{dist}[i,k,k-1] + \text{dist}[k,j,k-1]}
	  \]

	  \fignocaption{width = 0.40\textwidth}{figs/floyd-warshall.png}
	  \pause
	\item[Init:]
	  \[
		\text{dist}[i,j,0] = \left\{\begin{array}{ll}
		  \textcolor{red}{0} & i = j \\
		  w(i,j) & (i,j) \in E \\
		  \infty & \text{o.w.}
		\end{array} \right.
	  \]
  \end{description}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{3-D DP}
  \begin{exampleblock}{Floyd-Warshall algorithm (Problem 6.25)}
	\begin{enumerate}[(1)]
	  \setcounter{enumi}{1}
	  \item Routing table for Floyd-Warshall algorithm
	\end{enumerate}
  \end{exampleblock}

  \begin{algorithmic}
	\ForAll{$k \gets 1 \dots n$}
	  \ForAll{$i \gets 1 \dots n$}
		\ForAll{$j \gets 1 \dots n$}
		  \If{$\text{dist}[i,j] > \text{dist}[i,k] + \text{dist}[k,j]$}
			\State $\text{dist}[i,j] \gets \text{dist}[i,k] + \text{dist}[k,j]$
			\uncover<3->{\State \textcolor{red}{$\text{Go}[i,j] \gets \text{Go}[i,k]$}}
		  \EndIf
		\EndFor
	  \EndFor
	\EndFor
  \end{algorithmic}

  \pause
  \vspace{0.50cm}
  \centerline{Time: $\Theta(n^3)$ \hspace{0.10cm} Space: $\Theta(n^2)$}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{3-D DP}
  \begin{exampleblock}{Floyd-Warshall algorithm (Problem 6.25)}
	\begin{enumerate}[(1)]
	  \setcounter{enumi}{1}
	  \item Routing table for Floyd-Warshall algorithm
	\end{enumerate}
  \end{exampleblock}

  \begin{columns}
	\column{0.50\textwidth}
	  \begin{algorithmic}
		\ForAll{$i \gets 1 \dots n$}
		  \ForAll{$j \gets 1 \dots n$}
			\State $\text{dist}[i,j] \gets \infty$
			\State \textcolor{red}{$\text{Go}[i,j] \gets \text{Nil}$}
		  \EndFor
		\EndFor

		\ForAll{$(i,j) \in E$}
		  \State $\text{dist}[i,j] \gets w(i,j)$
		  \State \textcolor{red}{$\text{Go}[i,j] \gets j$}
		\EndFor

		\ForAll{$i \gets 1 \dots n$}
		  \State $\text{dist}[i,i] \gets 0$
		  \State \textcolor{red}{$\text{Go}[i,i] \gets \text{Nil}$}
		\EndFor
	  \end{algorithmic}
	  \pause
	\column{0.50\textwidth}
	  \begin{algorithmic}
		\Procedure{Path}{$i,j$}
		  \If{$\text{Go}[i,j] = \text{Nil}$}
		  \State Output ``No Path.''
		  \EndIf

		  \Statex
		  \State Output ``$i$''
		  \While{$i \neq j$}
			\textcolor{red}{\State $i \gets \text{Go}[i,j]$}
			\State Output ``$i$''
		  \EndWhile
		\EndProcedure
	  \end{algorithmic}
  \end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{3-D DP}
  \begin{exampleblock}{Floyd-Warshall algorithm (Problem 6.29)}
	\begin{enumerate}[(1)]
	  \setcounter{enumi}{2}
	  \item Find minimum-weighted cycle of \textcolor{red}{directed} graph ($w(e) > 0$)
	\end{enumerate}
  \end{exampleblock}

  \[
	\text{dist}[i,i] \gets 0 \implies \text{dist}[i,i] \gets \infty
  \]

  \[
	\forall i: \text{dist}[i,i] = \infty
  \]

  \pause
  \[
	\textcolor{red}{\text{Q:}}\;\; \exists e: w(e) < 0
  \]

  \pause
  \begin{columns}
	\column{0.50\textwidth}
	  \[
		\exists i: \text{dist}[i,i] < 0
	  \]
	\column{0.50\textwidth}
	  \[
		\forall i: \text{dist}[i,i] \ge 0 \; (= \infty)
	  \]
  \end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Shortest paths on undirected graphs}
  \fignocaption{width = 0.70\textwidth}{figs/undirected-negative.png}

  \centerline{\url{https://cs.stackexchange.com/q/76578/4911}}
\end{frame}
%%%%%%%%%%%%%%%%%%%%


% Copyright 2018 Markus J. Pflaum, licensed under CC BY-NC-ND 4.0
% main author:
%   Markus J. Pflaum
%
\section{Orthonormal bases in Hilbert spaces}
\label{sec:orthonormal-baes-hilbert-spaces}

\begin{definition}
  A (possibly empty) subset $S$ of a Hilbert space $\hilbertH$ is called
  an \emph{orthogonal system} or just \emph{orthogonal} if for any  two different elements $v,w \in S$ the relation
  $\inprod{v,w} = 0$ holds true. If in addition $\norm{v}=1$ for all elements $v \in S$,
  then the set is called \emph{orthonormal} or an \emph{orthonormal system}.
  A family $(v_i)_{i\in I}$ of vectors in $\hilbertH$ is called \emph{orthogonal} if
  $\inprod{v_i,v_j} = 0$ for all  $i,j\in I$ with $i\neq j$ and  \emph{orthonormal}
  if in addition $\|v_i\| =1$ for all $i\in I$.
\end{definition}

\para
  Obviously, the set of orthonormal subsets of a Hilbert space is ordered by set-theoretic inclusion.
  Therefore, the following definition makes sense.

\begin{definition}
  A maximal orthonormal set in a Hilbert space $\hilbertH$ is called an \emph{orthonormal basis}
  or a \emph{Hilbert basis} of $\hilbertH$.
\end{definition}

\begin{proposition}
  Every  Hilbert space $\hilbertH$ has an orthonormal basis.
\end{proposition}

\begin{proof}
  Wothout loss of generality we can assume that $\hilbertH \neq \{ 0\}$, because
  $\emptyset$ is a Hilbert basis for $\{ 0 \}$.
  Let $\mathscr{O}$ denote the set of orthonormal subsets of $\hilbertH$. As mentioned before, $\mathscr{O}$
  is ordered by set-theoretic inclusion. Let $\mathscr{C} \subset \mathscr{O}$ be a non-empty chain.
  Put $U  = \bigcup_{S\in \mathscr{C}} S$. Then  $U$ is an upper bound of $\mathscr{C}$.
  So by Zorn's lemma $\mathscr{O}$ has a maximal element.
\end{proof}

\begin{remark}
  \begin{environmentlist}
  \item
    By slight abuse of language we sometimes call an orthonormal family $(b_i)_{i\in I}$ in a Hilbert space $\hilbertH$
    an \emph{orthonormal basis} or a \emph{Hilbert basis} of $\hilbertH$
    if the set $\{ b_i \mid i\in I \}$ is an orthornormal basis.
  \item
    If on an orthonormal basis $B \subset \hilbertH$ a total order relation is given,
    one calls $B$ an \emph{ordered Hilbert basis} of $\hilbertH$. Likewise,
    an orthonormal basis of the form $(b_i)_{i\in I}$ is called \emph{orderd} if the index set $I$ carries a total order.
  \end{environmentlist}
\end{remark}

\begin{proposition}[Pythagorean theorem for orthogonal families]\label{thm:pythagorean-theorem-infinite-families}\hspace{1mm}
  An orthogonal family $(v_i)_{i\in I}$ in a Hilbert space $\hilbertH$ is summable if and only if
  the family of norms $\left(\|v_i\| \right)_{i\in I}$ is square summable. In this case one has
  \[
     \left\|\sum_{i\in I} v_i\right\|^2 =  \sum_{i\in I} \|v_i\|^2 \ .
  \]
\end{proposition}

\begin{proof}
  Assume that $\left(\|v_i\| \right)_{i\in I}$ is square summable or in other words that the net of partial sums
  $\left( \sum_{i\in J} \|v_i\|^2 \right)_{J\in\mathscr{F} (I)}$  converges to some $s \in \R$.
  For $\varepsilon >0$ choose a finite $J_\varepsilon \subset I$ such that for all finite $J$ with
  $J_\varepsilon \subset J\subset I$ the relation
  \[
           \left| s - \sum_{i\in J} \|v_i\|^2   \right| < \frac{\varepsilon^2}{2}
  \]
  holds true. For finite $K\subset I$ with $K\cap J_\varepsilon  =\emptyset$ one then obtains by the pythagorean theorem for
  finite orthogonal families, Eq.~(\ref{eq:pythagorean-theorem}),
  \[
      \left\| \sum_{i\in K} v_i\right\|^2 =  \sum_{i\in K}  \left\| v_i\right\|^2 \leq
       \left| s - \sum_{i\in K \cup J_\varepsilon} \|v_i\|^2   \right|  + \left| s - \sum_{i\in  J_\varepsilon} \|v_i\|^2   \right|
       < \varepsilon^2 \ .
  \]
  Hence  $\left( \sum_{i\in J} v_i \right)_{J\in\mathscr{F} (I)}$ is a Cauchy net in $\hilbertH$, so convergent.

  Now let  $(v_i)_{i\in I}$ be  summable to $v\in \hilbertH$.
  Then there exists a $J_1 \in \mathscr{F} (I)$ such that for all finite $J \subset I$
  containing  $J_1$
  \[
    \left\| v -  \sum_{i\in J} v_i \right\| \leq 1 \ .
  \]
  This implies by the pythagorean theorem for finite orthogonal families
   \[
    \sum_{i\in J} \left\| v_i \right\|^2 =  \left\|  \sum_{i\in J} v_i \right\|^2  \leq
    \left(  \left\| v -  \sum_{i\in J} v_i \right\| +  \left\| v \right\| \right)^2 \leq  ( 1 + \| v\| )^2 \ .
  \]
  Hence the net of partial sums $\left( \sum_{i\in J} \|v_i\|^2 \right)_{J\in\mathscr{F} (I)}$ is bounded, so convergent
  since each term $\|v_i\|^2$ is $\geq 0$.

  By continuity of the inner product and pairwise orthogonality of the $v_i$ we finally obtain in the convergent case
  \[
   \left\| \sum_{i\in I} v_i \right\|^2 = \inprod{ \sum_{i\in I} v_i, \sum_{j\in I} v_j} =
   \sum_{i\in I} \inprod{ v_i, \sum_{j\in I} v_j} =  \sum_{i\in I} \sum_{j\in I} \inprod{ v_i, v_j} =  \sum_{i\in I} \left\| v_i \right\|^2 \ .
  \]
\end{proof}

\begin{proposition}
  Let $(v_i)_{i\in I}$ be an orthonormal family in a Hilbert space $\hilbertH$. Then for every $v \in \hilbertH$
  the family $\left( \inprod{v,v_i} \right)_{i\in I}$  is square summable and
  \emph{Bessel's inequality} holds true that is
  \[
    \sum_{i\in I} \left| \inprod{v,v_i} \right|^2 \leq \| v \|^2 \ .
  \]
\end{proposition}

\begin{proof}

\end{proof}

\begin{theorem}
Let $B$ be an orthonormal system in a Hilbert space $\hilbertH$. Then the following are equivalent:
\begin{numberlist}
  \item\label{ite:orthonormal-system-maximal} The orthonormal system $B$ is maximal, i.e.\ a Hilbert basis.
  \item\label{ite:orthonormal-system-total} The orthonormal system $B$ is  \emph{total} that is for all $v \in H$
      such that $\inprod{v, b} = 0$ for all $b \in B$ the equality $v = 0$ holds true.
  \item\label{ite:orthonormal-system-isomorphism}
     For every $b\in B$ let $\hilbertH_b = \{ r b \in \hilbertH \mid r \in \fldK\}$. Then the canonical map
     \[
       \iota: \widehat{\bigoplus_{b \in B}} \hilbertH_b \to \hilbertH , \:
       (v_b)_{b \in B} \mapsto \sum_{b \in B} v_b
     \]
     is an isometric isomorphism.
  \item\label{ite:orthonormal-system-closed-span}
     The closed linear span $\clSpan{B}$ coincides with $\hilbertH$.
  \item\label{ite:orthonormal-system-fourier-expansion} For all $v \in \hilbertH$, one has the
    \emph{Fourier expansion}
    \[ v = \sum_{b \in B} \inprod{v, b} b  \ . \]
  \item\label{ite:orthonormal-system-inner-product-expansion} For all $v, w \in \hilbertH$, one has
    \[ \inprod{v, w} = \sum_{b \in B}\inprod{v, b} \inprod{b, w} \ . \]
  \item\label{ite:orthonormal-system-parsevals-identity} For all $v \in \hilbertH$, \emph{Parseval's identity} holds true that is
    \[ \norm{v}^2 = \sum_{b \in B} \abs{\inprod{v, b}}^2  \ . \]
\end{numberlist}
\end{theorem}

\begin{proof}
 \ref{ite:orthonormal-system-maximal} $\Rightarrow$ \ref{ite:orthonormal-system-total}:
   If $v \neq 0$, then $\frac{v}{\norm{v}}$ is a unit vector orthogonal to each $v_i$. Hence $\{v\} \cup B$
   is an orthonormal system which is strictly larger than $B$, contradicting \ref{ite:orthonormal-system-maximal}.

 \ref{ite:orthonormal-system-total} $\Rightarrow$ \ref{ite:orthonormal-system-isomorphism}.
   First note that by the pythagorean theorem for infinite families, \Cref{thm:pythagorean-theorem-infinite-families},
   the canonical map $\iota: \widehat{\bigoplus}_{b \in B} H_b \rightarrow H$ is well-defined and an isometry.
   Hence $\iota$ is injective. It remains to show that $\iota$ is surjective.
   To this end observe that $\im \iota$ is closed in $\hilbertH$ since $\iota$ is an isometry (the image is complete).
   If $\iota$ is not surjective, then $\im \iota^\perp$ is not the zero vector space.
   Choose $v \in \im \iota^\perp \setminus \{ 0\}$.
   Then $v$ is orthogonal to each element of $B$, but $v \neq 0$. This contradicts
   \ref{ite:orthonormal-system-total}, so $\im \iota = \hilbertH$.

  \ref{ite:orthonormal-system-isomorphism} $\Rightarrow$ \ref{ite:orthonormal-system-fourier-expansion}:
    We can represent any $v \in \hilbertH$ in the form $v = \iota \left( (v_b)_{b \in B} \right) =
    \sum_{b\in B} v_b$ with $\left( v_b \right)_{b\in B} \in \widehat{\bigoplus}_{b \in B}  H_b$.
    Write $v_b = r_b \, b$ for every $b\in B$, where $r_b \in \fldK$ is uniquely determined by $v_b$.
    Then compute using continuity of the inner product
    \[
      \inprod{v, b} = \inprod{\sum_{c \in B} v_c, b} = \sum_{c \in B} r_c \inprod{c, b} = r_b \ .
    \]
    Therefore,
    \[
       v = \sum_{b \in B} r_b \, b = \sum_{b \in B} \inprod{v, b} b \ .
    \]

  \ref{ite:orthonormal-system-fourier-expansion} $\Rightarrow$ \ref{ite:orthonormal-system-inner-product-expansion}:
  Fourier expansion of $v, w \in H$ gives $v = \sum\limits_{b \in B} \inprod{v, b} b$ and
  $w = \sum\limits_{b \in B} \inprod{w, b} b$.   Then, by continuity of the inner product,
  \[
    \inprod{v, w} = \sum\limits_{b \in B} \inprod{v, b}\inprod{b, w} \ .
  \]

  \ref{ite:orthonormal-system-fourier-expansion} $\Rightarrow$ \ref{ite:orthonormal-system-closed-span}:
  Let $v\in \hilbertH$. Then $\sum\limits_{b\in J}\inprod{v, b} b \in \Span (B)$ for all finite  $J \subset B$.
  But by Fourier expansion $v$ is the limit of the net
  $\left( \sum\limits_{b\in J}\inprod{v, b} b \right)_{J\in \mathscr{F} (B)} $, so $v$ lies in the closure
  $\clSpan (B)$.

  \ref{ite:orthonormal-system-closed-span}  $\Rightarrow$ \ref{ite:orthonormal-system-total}:
  Assume that $\inprod{v, b} = 0$ for all $b \in B$. By \ref{ite:orthonormal-system-closed-span}, $v$ can be written as a limit
  $v = \lim\limits_{n\to\infty} v_n$, where $v_n \in \Span (B)$ for all $n\in \N$.
  Then  $\inprod{v, v_n} = 0$ for all $n\in \N$ by assumption.
  By continuity of the inner product this implies
  \[
     \norm{v}^2 = \lim\limits_{n\to\infty} \inprod{v, v_n} = 0 \ ,
  \]
  so $v=0$.

  \ref{ite:orthonormal-system-inner-product-expansion} $\Rightarrow$ \ref{ite:orthonormal-system-parsevals-identity}:
  Put $v = w$. Then, by assumption,
  \[
   \norm{v}^2 = \inprod{v, v} = \sum\limits_{b\in B} \inprod{v, b} \inprod{b, v} = \sum\limits_{b \in B} \abs{\inprod{v, b}}^2 \ .
  \]

  \ref{ite:orthonormal-system-parsevals-identity} $\Rightarrow$ \ref{ite:orthonormal-system-maximal}:
  Assume \ref{ite:orthonormal-system-parsevals-identity} and that \ref{ite:orthonormal-system-maximal} is not true.
  Then there exists $v \in H$ with $\norm{v} = 1$ and $\inprod{v, b} = 0$ for all $b \in B$. But then
  \[
    \norm{v}^2 = \sum_{b \in B} \abs{\inprod{v, b}}^2 = 0,
  \]
  which is a contradiction.

\end{proof}


\chapter{The reduce Library}

This manual describes the use of the \ml{reduce} library, as well as discussing
its design. The library is intended to ease the burden of performing tedious
and intellectually trivial tasks of arithmetic such as proving:

\begin{hol}\begin{verbatim}
  |- 2 EXP 6 = 64
\end{verbatim}\end{hol}

\noindent Anyone trying to prove the above by hand will testify to its extreme
tediousness. However, using the \ml{reduce} library, the evaluation of:

\begin{hol}\begin{verbatim}
  REDUCE_CONV "2 EXP 6"
\end{verbatim}\end{hol}

\noindent will perform the above automatically, and probably in far fewer
primitive inferences than a human would take. The library will also take care
of certain boolean expressions. This is mainly for the sake of completeness,
since the same effect can be achieved by careful use of rewriting.

\section{The representation of numbers}

The approach to representing natural number constants in \HOL\ is to provide a
conversion \ml{num\_CONV} which generates the definition of any nonzero numeral
in terms of its predecessor, for example:

\begin{hol}\begin{verbatim}
   #num_CONV "1";;
   |- 1 = SUC 0

   #num_CONV "256";;
   |- 256 = SUC 255
\end{verbatim}\end{hol}

\noindent This conversion uses \ml{mk\_thm}, so could be regarded as
unsatisfactory; however it is arguably no worse than expanding a constant
defined through the normal constant definition mechanism.

The \ml{reduce} library uses only the above conversion, together with certain
definitions and preproved theorems concerning the various arithmetic and
boolean operators, to derive, strictly by inference, reduction theorems for
certain expressions.

\section{Sample algorithm}

The following is an example of an algorithm for reducing addition expressions.
In fact, for reasons of efficiency, the library's \ml{ADD\_CONV} conversion is
implemented in a slightly more sophisticated way, but this example gives the
general flavour of how the various arithmetic conversions are defined.  Suppose
we want to apply the conversion to \ml{"m + n"} where \ml{m} and \ml{n} are
both numerals. Then

\begin{itemize}
  \item If the first numeral is zero, we need only specialize the first
  conjunct of the inbuilt definition \ml{ADD}:

  {\small\begin{verbatim}
    SPEC "n" (CONJUNCT1 ADD)
  \end{verbatim}}

  \item If the first numeral is not zero, then we call the conversion
  recursively to give:

  {\small\begin{verbatim}
    |- p + n = s
  \end{verbatim}}

  where \ml{p} is the predecessor of \ml{m}, and \ml{s} the corresponding sum.
  Now we can apply the following inferences:

  {\small\begin{verbatim}
    |- p + n = s                % [1] From recursive call             %
    |- (SUC p) + n = SUC(p + n) % [2] Instance of 2nd conjunct of ADD %
    |- (SUC p) + n = SUC s      % [3] Substituting [1] in [2]         %
    |- SUC p = m                % [4] SYM (num_CONV m)                %
    |- SUC s = t                % [5] SYM (num_CONV (s+1))            %
    |- m + n = t                % [6] Substituting [4] and [5] in [6] %
  \end{verbatim}}

  This gives the desired result. The above can easily be converted into a
  simple recursive procedure.

\end{itemize}

\section{Using the library}

The straightforward way to use the library is simply to do:

\begin{hol}\begin{verbatim}
   load_library `reduce`;;
\end{verbatim}\end{hol}

\noindent This will work only if the \HOL\/ being used has been installed
correctly; if this is not the case the user should refer to the \TUTORIAL\/ or
the \DESCRIPTION.

The library provides the following three ML bindings, which should be all that
is needed for most purposes:

\begin{itemize}

  \item \ml{REDUCE\_CONV} is a conversion which, when given an expression, will
  return a theorem expressing its equivalence with a reduced version, which in
  many cases will be simply a single numeral or boolean literal. For example:

  {\small\begin{verbatim}
    #REDUCE_CONV "(50 < 51) => (2 * 25) | (60 - 17)";;
    |- (50 < 51 => 2 * 25 | 60 - 17) = 50

    #REDUCE_CONV "(3 * x) + (1 + 2)";;
    |- (3 * x) + (1 + 2) = (3 * x) + 3

    #REDUCE_CONV "(1 < 2) /\ (2 <= 2)";;
    |- 1 < 2 /\ 2 <= 2 = T
  \end{verbatim}}

  \item \ml{REDUCE\_RULE} is a rule which applies the reductions corresponding
  to \ml{REDUCE\_CONV} to subterms of the theorem's conclusion

  \item \ml{REDUCE\_TAC} performs the same reductions on a goal.

\end{itemize}

\noindent For more sophisticated use, there are conversions specific to each
operator, for example \ml{ADD\_CONV} and \ml{OR\_CONV}. For more details of
these, refer to the next chapter. The arithmetic conversions and boolean
conversions may be loaded separately by loading (with \ml{loadt} for instance)
\ml{arithconv.ml} and \ml{boolconv.ml} respectively, in the main library
directory.


%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex
\chapter{The transport model} \label{chap:transportmodel}
\section{The reactive transport equation}
The evolution of the concentration of a particular constituent (or tracer) in an aquatic environment is described by the \textit{reactive transport equation}:
\begin{equation}\label{eq:ADR}
	\frac{\partial C}{\partial t} = q-\nabla \cdot \left(\b uC - \b K \nabla C\right).
\end{equation}
In this equation, $C$ is the concentration of the constituent in water, expressed in $\rm{kg/m^d}$, where $d$ is the dimension of the problem; $t$ is the time, expressed in seconds; $q$ is the local net production (i.e. production - destruction) rate of the constituent, expressed in $\rm{kg/(m^ds)}$; $\b u$ is the velocity vector whose units are $\rm{m/s}$; and $\b K$ is the \textit{diffusivity tensor}, whose entries are expressed in $\rm{m^2/s}$. Without loss of generality, we can assume $\b K$ to be symmetric. This is essentially because the impact of the anti-symmetric part of $\b K$, if any, may be viewed as additional advection. More details may be found in appendix A of \cite{deleersnijder2001concept}. Of course, the symmetric tensor $\b K$ must then be positive-definite in order to represent truly diffusive processes, namely phenomena which tend, at any time and location, to homogenize the concentration of any constituent.

In equation~\eqref{eq:ADR}, $\nabla \cdot (\b u C)$ is the \textit{advective} term, $\nabla \cdot (\b K \nabla C)$ is the \textit{diffusive} term, and $q$ is often called the \textit{source/sink} term. When $q=0$, equation~\eqref{eq:ADR} becomes the \textit{advection-diffusion} equation:
\begin{equation}\label{eq:C_PDE_vec}
 	\frac{\partial C}{\partial t} = -\nabla \cdot \left(\b uC - \b K \nabla C\right).
 \end{equation}
 When $q=0$, the tracer is said to be \textit{passive}.

The reactive transport equation is omnipresent in this work for several reasons. First, it is a fundamental equation in our purpose to develop consistent compartment models, as we will see in chapter~\ref{chap:compartment}. Furthermore, we have seen in chapter~\ref{chap:clustering} that the stability method is based on the knowledge of the \textit{transition probability matrix}. Computing that matrix in the case of geophysical flows cannot be done unless we understand the dynamics of the flow: we will see in chapter~\ref{chap:numerical} that efficient numerical methods allowing to track the fate of individual tracer's particles can be devised from equation~\eqref{eq:ADR}. The transition probability matrix can then easily be approximated from the particles trajectories. Finally, the particles trajectories can also be used to evaluate the concentration, and hence to assess the validity of the compartment models that will be developed further in this work.

\section{The continuity equation and the Boussinesq approximation}
In general, the (possibly time-dependent) velocity field in equation~\eqref{eq:ADR} is unknown and has to be solved from the Navier-Stokes equations. In this work, we will restrict ourselves to problems where the velocity field is known and stationary. The \textit{continuity equation} (local mass conservation)
\begin{equation} \label{eq:continuity}
	\frac{\partial \rho}{\partial t} + \nabla \cdot (\rho \b u) = 0
\end{equation}
must be satisfied everywhere on the domain. In equation~\eqref{eq:continuity}, $\rho$ is the density of the (sea)water mixture. In order to simplify the continuity equation, we make the very common \textit{Boussinesq approximation}. In the aquatic environment, water is, by far, the dominant constituent. The density of seawater is thus close to that of pure water, $\rho_w$. The latter depends on the temperature and pressure, but the variations are often very small: this consideration is at the basis of the Boussinesq approximation. Let $\bar{\rho}$ and $\Delta\rho$ be appropriate reference values of the density and the order of magnitude of its variation. The key assumption in the \textit{Boussinesq approximation} is that
\begin{equation} \label{eq:bouss_hyp}
	\frac{\Delta \rho}{\bar{\rho}} \ll 1.
\end{equation}
To assess the impact of this assumption on the continuity equation, we consider its dimensionless form. Let $U$, $T$ and $X$ be relevant velocity-, time- and space-scales. We use those parameters to scale the flow variables, leading to the following dimensionless variables (denoted by primes):
\begin{equation}
	\rho' = \frac{\rho - \bar{\rho}}{\Delta \rho}, \quad \b u' = \frac{\b u}{U}, \quad t' = \frac{t}{T}, \quad \mbox{and} \quad \b x' = \frac{\b x}{X},
\end{equation}
where $\b x = (y,z)$. The dimensionless version of the continuity equation~\eqref{eq:continuity} reads then:
\begin{equation}
	\frac{\Delta \rho}{T}\frac{\partial \rho'}{\partial t'} + \frac{U\Delta \rho}{X}\b u' \cdot \nabla' \rho' + \frac{U(\bar{\rho}+ \rho' \Delta \rho)}{X}\nabla' \cdot \b u' = 0.
\end{equation}
Multiplying both sides by $X/(U\bar{\rho})$ yields :
\begin{equation}
	\frac{X}{UT}\frac{\Delta \rho}{\bar{\rho}}\frac{\partial \rho'}{\partial t'} + \frac{\Delta \rho}{\bar{\rho}}\b u' \cdot \nabla' \rho' + \left(1+\frac{\Delta \rho}{\bar{\rho}}\rho'\right)\nabla' \cdot \b u' = 0.
\end{equation}
By taking~\eqref{eq:bouss_hyp} into account, this equation simplifies to $\nabla' \cdot \b u' = 0$, or equivalently in dimensional variables
\begin{equation}
	\nabla \cdot \b u = 0.
\end{equation}

\section{Properties of the solution of the reactive transport equation}\label{sec:propcontinuous}
In this section, we show the most important properties related to the reactive transport equation. To this end, let us first introduce some notations and terminology. Let $\Omega$ denote the (time independent) domain of interest and $\partial \Omega$ its boundary. Let $\hat{\b n}$ denote the unit vector, normal to $\partial \Omega$ and oriented towards the exterior of the domain. The volume of the domain is
\begin{equation}
	|\Omega| = \int_{\Omega} \rm d\Omega.
\end{equation}
The mean tracer concentration over the domain is
\begin{equation} \label{eq:Cmean}
	\bar{C}(t) = \frac{1}{|\Omega|}\int_{\Omega} C(\b x,t) \rm d\Omega,
\end{equation}
and the variance of the concentration over $\Omega$ is expressed as
\begin{equation} \label{eq:sigma2continuous}
 	\sigma^2(t) = \frac{1}{|\Omega|} \int_{\Omega} \left(\hat C(\b x,t)\right)^2 \rm d\Omega,
\end{equation}
where
\begin{equation} \label{eq:Chat}
	\hat C(\b x,t) := C(\b x,t) - \bar C
\end{equation}
denotes the deviation of the concentration with respect to $\bar C$.
The variance is a measure of the concentration inhomogeneity.
The mean net production rate is denoted
\begin{equation}
	\bar q(t) = \frac{1}{|\Omega|}\int_\Omega q\ \rm d\Omega.
\end{equation}
The flux that enters the domain through the boundary $\partial \Omega$ is
\begin{equation}
	\Phi = -\int_{\partial \Omega} (\b uC - \b K \cdot \nabla C)\cdot \n\ \rm d(\partial \Omega).
\end{equation}
An \textit{isolated} domain is such that there is no exchange with the environment, and hence no net flux of the fluid crossing the boundary:
\begin{equation} \label{eq:isolateddomain}
	\left[ \b u \cdot \hat{\b n}\right]_{\b x \in \partial \Omega} = 0 \quad \mbox{and} \quad \left[ (\b K \cdot \nabla C) \cdot \hat{\b n}\right]_{\b x \in \partial \Omega} = 0.
\end{equation}
Therefore, $\Phi=0$ if the domain is isolated.

\begin{property}\label{prop:cont1}
	The mean tracer concentration satisfies the following relation
	\begin{equation}
		\frac{d\bar{C}(t)}{dt} = \bar q + \frac{\Phi}{|\Omega|}.
	\end{equation}
\end{property}
\begin{proof}
	The time derivative of the mean concentration is expressed as
	\begin{equation} \label{eq:tracermass1}
		\frac{d\bar{C}(t)}{dt} = \frac{1}{|\Omega|} \frac{d}{dt} \int_{\Omega} C(\b x,t) \rm d\Omega = \frac{1}{|\Omega|} \int_{\Omega} \frac{\partial}{\partial t} C(\b x,t) \rm d\Omega.
	\end{equation}
	Injecting~\eqref{eq:ADR} into~\eqref{eq:tracermass1}, yields successively
	\begin{subequations}
	\begin{align}
		\frac{d\bar{C}(t)}{dt} &= \frac{1}{|\Omega|} \int_\Omega q\ \rm d\Omega + \frac{1}{|\Omega|} \int_{\Omega} -\nabla \cdot \left(\b uC - \b K \nabla C\right) \rm d\Omega\\
		 &= \bar q - \frac{1}{|\Omega|} \int_{\partial \Omega} \left(\b uC - \b K \nabla C\right) \cdot \n \ \rm d(\partial \Omega)\\
		 &= \bar q + \frac{\Phi}{|\Omega|},
	\end{align}
	\end{subequations}
	where we have used the divergence theorem.
\end{proof}

\begin{corollary}{prop:cont1} \label{prop:mass-is-constant}
	If the domain is isolated and the tracer is passive, the mean tracer concentration is constant.
\end{corollary}
\begin{proof}
	This is a straightforward consequence of property~\ref{prop:cont1} with $\Phi=0$ (isolated domain) and $\bar q = 0$ (passive tracer).
\end{proof}

\begin{property}
	For a passive tracer in an isolated domain, if the initial concentration is constant, then the concentration remains constant.
\end{property}
\begin{proof}
	Let $C_0 \ge 0$ and $C(\b x, 0) = C_0$. At time $t=0$, equation~\eqref{eq:ADR} becomes
	\begin{equation}
		\frac{\partial C}{\partial t} = q - C_0 \nabla \cdot \b u.
	\end{equation}
	But $q=0$ since the tracer is passive, and the Boussinesq approximation implies that $\b u$ is divergence-free (equation~\eqref{eq:continuity_boussinesq}). Hence
	\begin{equation}
		\frac{\partial C}{\partial t} = 0,
	\end{equation}
	and the concentration remains constant.
\end{proof}

\begin{property}
	For a passive tracer in an isolated domain, the variance of the concentration decreases monotonously with time until the concentration is everywhere equal to the mean concentration. In other words, the tracer concentration gets more and more homogeneous with time until the equilibrium state is reached, which happens when the concentration is constant and uniform everywhere on $\Omega$.
\end{property}
\begin{proof}
	By corollary~\ref{prop:mass-is-constant}, the mean concentration $\bar C$ is constant. Let $\hat C(\b x,t)$ be defined as in~\eqref{eq:Chat}. It is easy to show that $\bar C$ satisfies the advection diffusion equation:
	 \begin{equation}
	 	0 = \frac{\partial \bar C}{\partial t} = -\nabla \cdot \left(\b u \bar C - \b K \nabla \bar C\right) = - \bar C \nabla \cdot (\b u - 0) = 0,
	 \end{equation}
	 and thus
	 \begin{equation} \label{prop:variance1}
	 	\frac{\partial \hat C}{\partial t} = -\nabla \cdot \left(\b u \hat C - \b K \nabla \hat C\right).
	 \end{equation}
	 Multiplying equation~\eqref{prop:variance1} by $\hat C$ yields, after some calculations
	 \begin{equation} \label{prop:variance2}
	 	\frac{\partial \hat C^2}{\partial t} = - \nabla \cdot \left(\hat C^2 \b u \right) + 2\nabla \cdot \left(\hat C \b K \nabla \hat C \right) - 2 \nabla \hat C^\t \b K \nabla \hat C.
	 \end{equation}
	 Now, notice that
	 \begin{equation} \label{prop:variance3}
	 	\int_{\Omega} \frac{\partial \hat C^2}{\partial t} \rm d\Omega = \frac{d}{dt} \int_{\Omega} \left( \hat C(\b x,t) \right)^2 \rm d\Omega = |\Omega|\frac{d\sigma^2}{dt}.
	 \end{equation}
	 Combining~\eqref{prop:variance2} and~\eqref{prop:variance3} yields
	 \begin{equation}
	 	|\Omega|\frac{d\sigma^2}{dt} = - \int_{\Omega} \nabla \cdot \left(\hat C^2 \b u \right) \rm d\Omega + 2 \int_{\Omega} \nabla \cdot \left(\hat C \b K \nabla \hat C \right) \rm d\Omega -2 \int_{\Omega} \nabla \hat C^\t \b K \nabla \hat C \rm d\Omega.
	 \end{equation}
	 Using the divergence theorem and equations~\eqref{eq:isolateddomain}, we get
	 \begin{equation}
	 		|\Omega|\frac{d\sigma^2}{dt} = - \underbrace{\int_{\partial \Omega} \hat C^2 (\b u \cdot \n) \rm d(\partial \Omega)}_{=0} + 2\underbrace{\int_{\partial \Omega} \hat C (\b K \nabla \hat C \cdot \n) \rm d(\partial \Omega)}_{=0} -2 \int_{\Omega} \nabla \hat C^\t \b K \nabla \hat C \rm d\Omega.
	 \end{equation}
	 Finally,
	 \begin{equation}
	 	\frac{d\sigma^2}{dt} = -\frac{2}{|\Omega|} \int_{\Omega} \nabla \hat C^\t \b K \nabla \hat C \rm d\Omega.
	 \end{equation}
	 Since $\b K$ is positive definite, the variance of the concentration will decrease until $\nabla \hat C = 0$, hence until $C$ reaches a constant value everywhere on $\Omega$. The only possibility is $\bar C$, and thus we have shown that
	 \begin{equation}
	 	\lim_{t\rightarrow \infty} C(\b x,t) = \bar C.
	 \end{equation}
\end{proof}


\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage{listings}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}

\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
%If you want to title your bold things something different just make another thing exactly like this but replace "problem" with the name of the thing you want, like theorem or lemma or whatever

\begin{document}

%\renewcommand{\qedsymbol}{\filledbox}
%Good resources for looking up how to do stuff:
%Binary operators: http://www.access2science.com/latex/Binary.html
%General help: http://en.wikibooks.org/wiki/LaTeX/Mathematics
%Or just google stuff

\title{Assignment 2\\ MEEN 357}
\author{Jacob Hartzer}
\maketitle

 \section*{Task 6}
\begin{problem} {1} Machine Epsilon

Machine epsilon for this 9-bit floating-point number would be half the difference between the following floats: 000000000 and 000000001. This can be found as:
\begin{align*}
\epsilon &= \frac{-1^0 * 2^{1-3} * 0.00001 - -1^0 * 2^{1-3} * 0.00000}{2} \\
& = \frac{(0.0000001 – 0.0000000)}{2}\\
& = 0.00000001_2\\
&= 2^{-8}\\
&=0.00390625
\end{align*}

\end{problem}

\begin{problem}{2} Floats
 \subsubsection*{i}
\begin{align*}
0\: 110\: 11111 &= 2^(2^2+2^1 – 3) x 1.11111 \\
&= 1111.112\\
&= 2^4 + 2^3 +\dots{}+2^{-2}\\
&= 15.75_10
\end{align*}

 \subsubsection*{ii}
\begin{align*}
0\: 001\: 00001&= 2^{1-3} * 1.00001\\
&= .0100001_2\\
&= 2^{-2} + 2^{-7 }\\
&= 0.2578125_10
\end{align*}

 \subsubsection*{iii}
\begin{align*}
0\: 000\: 11111&= 2^{1-3} * 0.11111\\
&= 0.0011111_2\\
&= 2^{-3} +\dots{}+ 2^{-7}\\
&= 0.2421875_10
\end{align*}

 \subsubsection*{iv}
\begin{align*}
0\: 000\: 00001&= 2^{1-3} * 0.00001\\
&= 0.0000001_2\\
&= 2^{-7}\\
&= 0.0000078125_10
\end{align*}
\end{problem}

\begin{problem}{3} Floating Point Binary
\begin{center}
\begin{tabular}{ |c|c|c|c|c| }
 \hline
Number	&Number in Binary&	Exponential&	Exponential Binary&	Binary Float Representation\\\hline
0	& 0		& 0		& 000	& 0\: 000\: 00000\\
1	& 1		& 0+3	& 011	& 0\: 011\: 00000\\
2	& 10		& 1+3	& 100	& 0\: 100\: 00000\\
3	& 11		& 1+3	& 100	& 0\: 100\: 10000\\
4	& 100	& 2+3	& 101	& 0\: 101\: 00000\\
5	& 101	& 2+3	& 101	& 0\: 101\: 01000\\
6	& 110	& 2+3	& 101	& 0\: 101\: 10000\\
7	& 111	& 2+3	& 101	& 0\: 101\: 11000\\
8	& 1000	& 3+3	& 110	& 0\: 110\: 00000\\
9	& 1001	& 3+3	& 110	& 0\: 110\: 00100\\
10	& 1010	& 3+3	& 110	& 0\: 110\: 01000\\
11	& 1011	& 3+3	& 110	& 0\: 110\: 01100\\
12	& 1100	& 3+3	& 110	& 0\: 110\: 10000\\
13	& 1101	& 3+3	& 110	& 0\: 110\: 10100\\
14	& 1110	& 3+3	& 110	& 0\: 110\: 11000\\
15	& 1111	& 3+3	& 110 	& 0\: 110\: 11100\\

 \hline
\end{tabular}
\end{center}
\end{problem}
\end{document}


\documentclass[12pt]{article}

\pdfoutput=24
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{esvect}
\usepackage[toc,page]{appendix}
\usepackage{leftidx}
\usepackage{color}
\usepackage{framed, color}
\usepackage{multirow}
\usepackage{pdfpages}
\usepackage{multicol}
\usepackage{wrapfig,lipsum,booktabs}

\usepackage[utf8]{inputenc}
\usepackage{mathtools,hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=cyan,
    filecolor=cyan,
    urlcolor=red,
    citecolor=red,
}

\usepackage{cleveref}
\usepackage{commath}
\usepackage{enumitem}
\usepackage{amssymb}
\renewcommand{\qedsymbol}{$\blacksquare$}

%%%%%%%%%%%
%%%%%%%%%%%  User Defined Commands. (macros)
%%%%%%%%%%%

\definecolor{mgreen}{RGB}{25,147,100}
\definecolor{shadecolor}{rgb}{1,.8,.1}
\definecolor{shadecolor2}{RGB}{245,237,0}
\definecolor{orange}{RGB}{255,137,20}
\definecolor{orange}{RGB}{245,37,100}

%%%%%%%%%%%
%%%%%%%%%%%  Graphical Packages
%%%%%%%%%%%
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usepackage{mdframed}
\usepackage{adjustbox}
\usepackage{tcolorbox}
%\usepackage{graphics}
\usepackage{tikz,ifthen,fp,calc}
\usepackage{caption}
\usepackage{subcaption}
\usetikzlibrary{plotmarks}
\usepackage{graphicx}

%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% Theorem Styles
%%%%%%%%%%%%%%%%%
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{prop}{Proposition}[section]
\newtheorem{corr}{Corollary}[section]
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{remark}{Remark}[section]
\newtheorem{fact}{Fact}[section]

\usepackage[english]{babel}
\usepackage{babel,blindtext}
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{exmp}{Example}[section]
\usepackage{fullpage}
\usepackage{amsfonts}
\usepackage{lscape}
\usepackage{bbm}

\usepackage{todonotes}
\usepackage{cite}
\usepackage{verbatim}
\usepackage{bm}

\DeclareMathOperator*{\argmax}{arg\,max}
\usepackage[margin=1in]{geometry}
\providecommand{\keywords}[1]{\textbf{\textit{Keywords:---}} #1}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{authblk}
\usepackage{cite}

\newcommand*{\affaddr}[1]{#1} % No op here. Customize it for different styles.
\newcommand*{\affmark}[1][*]{\textsuperscript{#1}}
%\newcommand*{\email}[1]{\texttt{#1}}

\title{\textbf{Mahalanobis distance explained}}
\author{}
\date{}

\providecommand{\keywords}[1]{\textbf{\textit{Keywords:}} #1}

\begin{document}

\maketitle

\section{Diagonalizability}

Let $\mathbf{X}$ be a matrix whose rows are variables and
columns are observations that are centered about the mean.
Then the covariance of the $\mathbf{X}$ is given by

\begin{equation}
\mathbf{{\Large{\Sigma} }}= cov(\mathbf{X}) = \frac{1}{n-1}\mathbf{ XX^\text{T}}
\end{equation}

Assume we want to have a mapping $\mathbf{M}$ so that $\mathbf{Y=M^\text{T}X}$ has covariance
that is diagonal. Then

\begin{itemize}
\item Assume there is no observation with all zero values
\item Assume there is no two identical observations, i.e.columns are linearly independent.
\item (Rare) things like that which will make covariance matrix singular.
\end{itemize}

Then since covariance matrix is symmetric, with positive entries, etc., it is diagonalizable,
i.e. it can be written as

\begin{equation}\label{eq:eigendecomposition}
\mathbf{{\Large{\Sigma} }}  = \mathbf{U^{-1} D U = U^\text{T} D U}
\end{equation}

or equivalently

\begin{equation}\label{eq:eigendecomposition2}
\mathbf{U^\text{T} {\Large{\Sigma} }U }  = \mathbf{D}
\end{equation}

where $\mathbf{D}$ is diagonal and, in this case due to properties of covariance matrix, the
matrix $\mathbf{U}$ is orthogonal, i.e. $\mathbf{U^{-1} = U^\text{T}}$, i.e. $\mathbf{UU^\text{T}} = \mathbf{I}$

The columns of $\mathbf{U^{-1}}$ are eigenvectors of covariance matrix, entries of $\mathbf{D}$
are eigenvalues of covariance matrix, which are also variances of different variables in $\mathbf{X}$.

Assume we want to rotate the data, or represent them in a
coordinate system where it is represented with variables that are
orthogonal, i.e. the collinearity is killed. This is what PCA does.

Now lets pretend we do not know that. Lets say we want to
transform $\mathbf{X}$ into $\mathbf{Y}$ by a mapping $\mathbf{M^\text{T}}$, i.e. $\mathbf{Y= M^\text{T}X}$,
so that covariance of $\mathbf{Y}$ is diagonal matrix, $\mathbf{\hat{D}}$. \\
\pagebreak

So, we want $cov(\mathbf{Y}) = \frac{1}{n-1}\mathbf{Y}\mathbf{Y^\text{T}}$,
Lets take a look:

\begin{equation}\label{eq:diagonalize}
\begin{aligned}
\mathbf{\hat{D}} = cov({\mathbf{Y}}) &= \frac{1}{n-1}\mathbf{Y}\mathbf{Y^\text{T}}\\
                           &= \frac{1}{n-1}\mathbf{M^\text{T}X}\mathbf{(M^\text{T}X)^\text{T}}\\
                           &= \frac{1}{n-1} \mathbf{M^\text{T}}\mathbf{XX^\text{T}}\mathbf{ M}\\
                           &=  \mathbf{M^\text{T}}\mathbf{\Sigma}\mathbf{M}
\end{aligned}
\end{equation}

So, we arrived at $\mathbf{\hat{D}} = \mathbf{M^\text{T}}\mathbf{\Sigma}\mathbf{M}$.
Hence, if you choose $\mathbf{M}$ to be the same as $\mathbf{U}$, then
covariance of $\mathbf{Y}$ would be diagonal, and you have $\mathbf{\hat{D}}  = \mathbf{D}$.\\

Since, the the decomposition given by Eq.~(\ref{eq:eigendecomposition})
is eigen-decomposition of $\mathbf{\Sigma}$, we can see this is what PCA does.

\section{Equivalency}

\theoremstyle{definition}
\begin{definition}
Suppose the random vectors of $\mathbf{v}$ and $\mathbf{w}$ be drawn from a distribution
whose associated covariance matrix is given by $\mathbf{\Sigma}$. Then define the Malanoblis
distance as follows:

 \begin{equation}\label{eq:mahabDist}
 d = \mathbf{(v - w)^\text{T} \Sigma^{-1} (v - w)}
 \end{equation}
\end{definition}

Lets take a look:

\begin{equation}\label{eq:equivalency}
\begin{aligned}
\mathbf{d} &= \mathbf{(v - w)^\text{T} \Sigma^{-1} (v - w)} \\
                 &= \mathbf{(v - w)^\text{T}  (U^\text{T} D U) ^{-1} (v - w)} \\
                 &= \mathbf{(v - w)^\text{T}  (U^{-1} D^{-1} U^{-T}) (v - w)} \\
                 &= \mathbf{(v - w)^\text{T}  (U^\text{T} D^{-1} U) (v - w)} \\
                 &= \mathbf{(U(v - w))^\text{T}  D^{-1} (U (v - w))} \\
\end{aligned}
\end{equation}

Notice:
\begin{itemize}
\item The diagonal entries of $\mathbf{D}$ eigenvalues of covariance matrix,
which are variance of variables in $\mathbf{X}$. So, if the data in $\mathbf{X}$
was scaled by their variances, then this distance was equivalent to
 Euclidean distance.

\item Lets look at the last term in above equation:

\begin{equation}
\mathbf{ U (v - w)}  = \mathbf{ U v} - \mathbf{ U w}
\end{equation}

Each of these terms are mappings of $\mathbf{v}$ and $\mathbf{w}$
into the PCA space of the data $\mathbf{X}$.
\end{itemize}

Suppose $\mathbf{x}$ is a vector and we wish to represent it,
in the column space of a matrix $\mathbf{A} = [\mathbf{A}_1, \mathbf{A}_2, \dots \mathbf{A}_N]$,
where each $\mathbf{A}_i$ is a column of $\mathbf{A}$. So, we are looking for constants $y_1, y_2, \dots, y_N$ so that

\[\mathbf{x} = y_1 \mathbf{A}_1 + y_2 \mathbf{A}_2 \dots + \mathbf{A}_N y_N = \mathbf{Ay} \]

Hence, $\mathbf{y = A^{-1} X}$. So, $\mathbf{y}$ is the mapping of $\mathbf{x}$ into column space of
$\mathbf{A}$. Just like $\mathbf{Uv}$ which is mapping of $\mathbf{v}$ into column space of $\mathbf{U^{-1}}$
whose columns are eigenvectors of covariance, i.e. PCA.

\iffalse
P.S. I had to choose where to put the exponent \{-1\} to indicate inverse of the matrices,
whether to the left or right of  $\mathbf{\Sigma}$.
Either way would have made some parts easier, but some other parts harder to follow.\\

Now, the question is, when you mentioned M. Distance takes
care of scales and collinearity, where, in what context you learned that.
Did the context refer to this definition of distance as M. distance,
or they were talking about the distance between a point and distribution?
\fi
\end{document}