\documentclass{memoir}
\usepackage{notestemplate}
\usetikzlibrary{arrows,chains,matrix,positioning,scopes}

\makeatletter
\tikzset{join/.code=\tikzset{after node path={%
\ifx\tikzchainprevious\pgfutil@empty\else(\tikzchainprevious)%
edge[every join]#1(\tikzchaincurrent)\fi}}}
\makeatother

\tikzset{>=stealth',every on chain/.append style={join},
         every join/.style={->}}

%\logo{~/School-Work/Auxiliary-Files/resources/png/logo.png}
%\institute{Rice University}
%\faculty{Faculty of Whatever Sciences}
%\department{Department of Mathematics}
%\title{Class Notes}
%\subtitle{Based on MATH xxx}
%\author{\textit{Author}\\Gabriel \textsc{Gress}}
%\supervisor{Linus \textsc{Torvalds}}
%\context{Well, I was bored...}
%\date{\today}

%\makeindex

\begin{document}

% \maketitle

% Notes taken on 06/08/21

Consider modules \(A,C\). One question worth exploring is if there exists a module \(B\) such that \(A / B \cong C\); that is, \(B\) is an extension of \(C\) by \(A\). The tools we develop to understand this question are exact sequences. If \(A\) is isomorphic to a submodule of \(B \), there is an injective homomorphism from \(A\) to \(B\). And if \(C\) is isomorphic to the quotient, then there is a surjective homomorphism from \(B\) to \(C\). This will give us a chain
\begin{align*}
	A \to B \to C
\end{align*}
where the homomorphisms are compatible with. We formalize this idea via exact sequences.

\begin{defn}[Exact Sequences]
	Let \(\alpha ,\beta \) be homomorphisms so that
	\begin{align*}
		X \to^{\alpha } Y \to^{\beta }Z.
	\end{align*}
	If \(\textrm{Im}(\alpha ) = \textrm{Ker}(\beta )\), then we say the pair of homomorphisms are \textbf{exact}.\\

	A sequence of homomorphisms
	\begin{align*}
		\ldots \to X_{n-1} \to X_n \to X_{n+1} \to \ldots
	\end{align*}
	is said to be an \textbf{exact sequence} if it is exact at every \(X_n\) between a pair of homomorphisms.
\end{defn}
Hence, our goal is to see whether we can form an exact sequence \(A\to B\to C\). Our notions of injectivity and surjectivity correspond exactly to the notions of exactness.
\begin{prop}
	Let \(A,B,C\) form \(R\)-modules over some ring \(R\). Then the sequence
	\begin{align*}
		0 \to A \to^{\psi }B
	\end{align*}
	is exact at \(A\) if and only if \(\psi \) is injective. Likewise, the sequence
	\begin{align*}
		B \to^{\varphi }\to C \to 0
	\end{align*}
	is exact at \(C\) if and only if \(\varphi \) is surjective.
\end{prop}
Combining the two ideas, the sequence
\begin{align*}
	0 \to A \to^{\psi }B \to^{\varphi }C \to 0
\end{align*}
is exact if and only if \(\psi \) is injective, \(\varphi \) is surjective, and \(\textrm{Im}(\psi ) = \textrm{Ker}(\varphi )\).

\begin{defn}
	An exact sequence of the form
	\begin{align*}
		0 \to A \to^{\psi }B \to^{\varphi }C \to 0
	\end{align*}
	is called an \textbf{short exact sequence}.
\end{defn}
Our goal then is to determine if two modules admit a short exact sequence, and if so, how many.\\

Notice that any exact sequence can be written as a succession of short exact sequences. For example, if
\begin{align*}
	X \to^{\alpha }Y \to^{\beta }Z
\end{align*}
is exact at \(Y\), then equivalently
\begin{align*}
	0 \to \alpha (X) \to Y \to Y / \textrm{Ker}(\beta ) \to 0
\end{align*}
is a short exact sequence.

\begin{exmp}

\end{exmp}

For fixed \(A,C\), there can be many extensions of \(C\) by  \(A\). Hence, we need to determine a notion of a homomorphism to distinguish exact sequences.

\begin{defn}[Homomorphism of Short Exact Sequences]
	Let
	\begin{align*}
		0 \to A \to B \to C \to 0\\
		0 \to A' \to B' \to C' \to 0
	\end{align*}
	be two short exact sequences of modules. A \textbf{homomorphism of short exact sequences} is a collection of module homomorphisms \(\alpha ,\beta ,\gamma \) such that the following diagram commutes:
\begin{center}
\begin{tikzpicture}
  \matrix (m) [matrix of math nodes, row sep=3em, column sep=3em]
    { 0 & A  & B  & C  & 0 \\
      0 & A' & B' & C' & 0 \\ };
  { [start chain] \chainin (m-1-1);
    \chainin (m-1-2);
    { [start branch=A] \chainin (m-2-2)
        [join={node[right] {$\alpha $}}];}
    \chainin (m-1-3) [join={node[above] {}}];
    { [start branch=B] \chainin (m-2-3)
        [join={node[right] {$\beta $}}];}
    \chainin (m-1-4) [join={node[above] {}}];
    { [start branch=C] \chainin (m-2-4)
        [join={node[right] {$\gamma $}}];}
    \chainin (m-1-5); }
  { [start chain] \chainin (m-2-1);
    \chainin (m-2-2);
    \chainin (m-2-3) [join={node[above] {}}];
    \chainin (m-2-4) [join={node[above] {}}];
    \chainin (m-2-5); }
\end{tikzpicture}
\end{center}
This is an \textbf{isomorphism of short exact sequences} if \(\alpha ,\beta ,\gamma \) are isomorphisms in which case the extensions \(B,B'\) are \textbf{isomorphic extensions}.\\

The two exact sequences are called \textbf{equivalent} if \(A = A'\), \(C = C'\), and there is an isomorphism between them where  \(\alpha ,\gamma \) are identity. In this case \(B\) and \(B'\) are \textbf{equivalent extensions}.
\end{defn}
Equivalency by extensions is stronger than just \(R\)-module isomorphisms between \(B\) and \(B'\)-- it tells us tat there is an \(R\)-module isomorphism between \(B\) and \(B'\) that restricts to an isomorphism from \(A\) to \(A'\) and induces an isomorphism on the quotients by \(C\) and \(C'\).

\begin{exmp}

\end{exmp}

\begin{prop}[Short Five Lemma]
	Let \(\alpha ,\beta ,\gamma \) be a homomorphism of short exact sequences
\begin{center}
\begin{tikzpicture}
  \matrix (m) [matrix of math nodes, row sep=3em, column sep=3em]
    { 0 & A  & B  & C  & 0 \\
      0 & A' & B' & C' & 0 \\ };
  { [start chain] \chainin (m-1-1);
    \chainin (m-1-2);
    { [start branch=A] \chainin (m-2-2)
        [join={node[right] {$\alpha $}}];}
    \chainin (m-1-3) [join={node[above] {}}];
    { [start branch=B] \chainin (m-2-3)
        [join={node[right] {$\beta $}}];}
    \chainin (m-1-4) [join={node[above] {}}];
    { [start branch=C] \chainin (m-2-4)
        [join={node[right] {$\gamma $}}];}
    \chainin (m-1-5); }
  { [start chain] \chainin (m-2-1);
    \chainin (m-2-2);
    \chainin (m-2-3) [join={node[above] {}}];
    \chainin (m-2-4) [join={node[above] {}}];
    \chainin (m-2-5); }
\end{tikzpicture}
\end{center}
\begin{itemize}
	\item If \(\alpha ,\gamma \) are injective then so is \(\beta \)
	\item If \(\alpha ,\gamma \) are surjective then so is \(\beta \)
	\item If \(\alpha ,\gamma \) are isomorphisms then so is \(\beta \)
\end{itemize}
\end{prop}
These results also hold for short exact sequences of groups.

\begin{proof}[Proof of Short Five Lemma]

\end{proof}
There is always at least one extension of a module \(C\) by \(A\) given by \(B = A \oplus C\).

\begin{defn}
	Let \(R\) be a ring and let
	\begin{align*}
		0 \to A \to^{\psi }B \to^{\varphi }C \to 0
	\end{align*}
	be a short exact sequence of \(R\)-modules. We say the sequence is \textbf{split} if there is an \(R\)-module complement to \(\psi (A)\) in \(B\). If this holds, then \(B = A \oplus C\) up to isomorphism by
	\begin{align*}
		B = \psi (A) \oplus C'
	\end{align*}
	for some submodile \(C'\), where \(\varphi (C') \cong C\).\\

	We say \(B\) is a \textbf{split extension of \(C\) by \(A\)}.
\end{defn}
This is really just the question of existence of a complement to \(\psi (A)\) in \(B\) that is isomorphic by \(\varphi \) to \(C\).

\begin{prop}
	The short exact sequence
	\begin{align*}
		0 \to A \to^{\psi }B \to^{\varphi }C \to 0
	\end{align*}
	of \(R\)-modules is split if and only if there is an \(R\)-module homomorphism \(\mu :C \to B\) such that \(\varphi \circ \mu \cong \textrm{Id}_C\).\\

	Any set map \(\mu :C\to B\) such that \(\varphi \circ \mu = \textrm{Id}_C\) is called a \textbf{section} of \(\varphi \). If \(\mu \) is a homomorphism, then \(\mu \) is called a \textbf{splitting homomorphism} for the sequence.
\end{prop}
A section of \(\varphi \) is merely a choice of coset representative in \(B\) for \(B / \textrm{Ker}\varphi  \cong C\). A section is a homomorphism if this set of coset representatives forms a submodule, in which case this submodule gives a complement to \(\psi (A)\) in \(B\).

\begin{exmp}

\end{exmp}

\begin{prop}
	Let
	\begin{align*}
		0 \to A \to^{\psi }B \to^{\varphi }C \to 0
	\end{align*}
	be a short exact sequence of modules. Then \(B = \psi (A) \oplus C'\) for some submodule \(C'\) of \(B\) with \(\varphi (C') \cong C\) if and only if there is a homomorphism \(\lambda :B\to A\) such that \(\lambda \circ \psi = \textrm{Id}_A\) .
\end{prop}
For groups, this is a stronger notion. The existence of a splitting homomorphism on the left end of the sequence gives that the extension group is a direct product (instead of a semidirect product). Of course, in modules there is no distinction as the underlying groups are abelian.

\subsection{Projective Modules}
\label{sub:projective_modules}

Let \(R\) be a ring and suppose that \(\prescript{}{R}M\) is an extension of \(N\) by \(L\), so that
\begin{align*}
	0 \to L \to^{\psi }M \to^{\varphi }N \to 0.
\end{align*}
If another \(R\)-module has an \(R\)-module homomorphism into \(L\) or \(N\), can it extend to a homomorphism to \(M\)?\\

We can see directly that if \(f \in \textrm{Hom}_R(D,L)\) then \(f' = \psi \circ f\) is an \(R\)-module homomorphism from \(D\) to \(M\):
\begin{align*}
	\psi': \textrm{Hom}_R(D,L) \to \textrm{Hom}_R(D,M)\\
	f \mapsto f' = \psi \circ f.
\end{align*}

\begin{prop}
	Let \(D,L,\) and \(M\) form \(R\)-modules and let \(\psi :L \to M\) be an \(R\)-module homomorphism. Then the map
	\begin{align*}
		\psi': \textrm{Hom}_R(D,L) &\to \textrm{Hom}_R(D,M)\\
		f &\mapsto f' = \psi \circ f
	\end{align*}
	is a homomorphism of abelian groups. If \(\psi \) is injective, then \(\psi '\) is injective. Hence, if
	\begin{align*}
		0 \to L \to^{\psi }M
	\end{align*} is exact, then
	\begin{align*}
		0 \to \textrm{Hom}_R(D,L) \to^{\psi '} \textrm{Hom}_R(D,M)
	\end{align*}
	is exact.
\end{prop}

Unfortunately, if there is an \(R\)-module homomorphism \(f:D \to N\), it isn't always the case that \(f\) \textbf{lifts} to an \(R\)-module homomorphism \(f:D\to M\) by
\begin{align*}
	\varphi ': \textrm{Hom}_R(D,M) &\to \textrm{Hom}_R(D,N)\\
	F &\mapsto F' = \varphi \circ F
\end{align*}
This only holds if and only if \(f\) is in the image of \(\varphi '\).

\begin{exmp}

\end{exmp}

\begin{thm}
	Let \(D,L,M,N\) form \(R\)-modules. If
	\begin{align*}
		0 \to L \to^{\psi }M \to^{\varphi }N \to 0
	\end{align*}
	is exact, then
	\begin{align*}
		0 \to \textrm{Hom}_R(D,L) \to^{\psi '} \textrm{Hom}_R(D,M) \to^{\varphi '} \textrm{Hom}_R(D,N)
	\end{align*}
	is exact.\\

	A homomorphism \(f:D\to N\) lifts to a homomorphism \(F:D\to M\) if and only if \(f \in \textrm{Hom}_R(D,N)\) is in the image of \(\varphi '\). In general \(\varphi '\) is surjective if and only if every homomorphism from \(D\) to \(N\) lifts to a homomorphism from \(D\) to \(M\), in which case the sequence above extends to a short exact sequence.\\

	The sequence above is exact for all \(R\)-modules \(D\) if and only if
	\begin{align*}
		0 \to L \to^{\psi }M \to^{\varphi }N
	\end{align*}
	is exact.
\end{thm}
Hence, by the theorem, the sequence
\begin{align*}
	0 \to \textrm{Hom}_R(D,L) \to^{\psi '}\textrm{Hom}_R(D,M) \to^{\varphi '} \textrm{Hom}_R(D,N) \to 0
\end{align*}
is in general not a short exact sequence, as \(\varphi '\) may not be surjective. In fact, this sequence is exact if and only if there is a bijection between homomorphisms \(F:D \to M\) and \(g:D\to L\), \(f:D\to N\) where
\begin{align*}
	F\mid_{\varphi (L)} = \psi'(g)\\
	f = \varphi'(F).
\end{align*}
Notice that if the original sequence is spit exact, then the sequence of homomorphisms is also split exact.
\begin{prop}
	Let \(D,L,N\) form \(R\)-modules. Then
	\begin{align*}
		\textrm{Hom}_R(D,L\oplus N) \cong \textrm{Hom}_R(D,L) \oplus \textrm{Hom}_R(D,N)\\
		\textrm{Hom}_R(L \oplus N, D) \cong \textrm{Hom}_R(L,D) \oplus \textrm{Hom}_R(N,D)
	\end{align*}
\end{prop}
Of course this extends by induction to any finite direct sum of \(R\)-modules. In other words, the group of module homomorphisms commute with dfinite direct sums in either variable.

\begin{rmrk}
	For infinite direct sums, this does not always hold. If \(L \oplus N\) is replaced by an arbitrary direct sum, and the direct sum on the right hand side is replaced by a direct product, then
	\begin{align*}
		\textrm{Hom}_R(D,L\oplus \left\{ N_i \right\}_{i \in I}) \cong \textrm{Hom}_R(D,L) \otimes \left\{ \textrm{Hom}_R(D,N_i) \right\}_{i \in I}
	\end{align*}
	holds. The second part must be translated into
	\begin{align*}
		\textrm{Hom}_R(L \otimes \left\{ N_i \right\}_{i \in I},D) \cong \textrm{Hom}_R(L,D) \otimes \left\{ \textrm{Hom}_R(N_i,D) \right\}_{i \in I}
	\end{align*}
\end{rmrk}

Hence, a split short exact sequence of \(R\)-modules induces a split short exact sequence of abelian groups for every \(R\)-module \(D\). In fact, the converse holds:
\begin{hw}
	Prove that if
	\begin{align*}
		0 \to \textrm{Hom}_R(D,L) \to^{\psi '} \textrm{Hom}_R(D,M) \to^{\varphi'} \textrm{Hom}_R(D,N) \to 0
	\end{align*} is exact for every \(R\)-module \(D\), then
	\begin{align*}
		0 \to L \to^{\psi }M \to^{\varphi }N \to 0
	\end{align*}
	is a split short exact sequence.\\

	This implies that if the original homomorphism sequence is exact for every \(D\), then it is in fact split exact for every \(D\).
\end{hw}

\begin{prop}
	Let \(P\) be an \(R\)-module. Then the following are equivalent:
	\begin{itemize}
		\item Let \(L,M,N\) form \(R\)-modules. If
			\begin{align*}
				0 \to L \to^{\psi }M \to^{\varphi }N \to 0
			\end{align*}
			is a short exact sequence, then
			\begin{align*}
				0 \to \textrm{Hom}_R(P,L) \to^{\psi '} \textrm{Hom}_R(P,M) \to^{\varphi '} \textrm{Hom}_R(P,N) \to 0
			\end{align*}
			is a short exact sequence.
		\item Let \(M,N\) form \(R\)-modules. If
			 \begin{align*}
				M \to^{\varphi }N \to 0
			\end{align*}
			is exact, then every \(R\)-module homomorphism from \(P\) into \(N\) lifts to an \(R\)-module homomorphism into \(M\), so the following diagram commutes:
\begin{center}
\begin{tikzpicture}% Fix later by making mu dashed
  \matrix (m) [matrix of math nodes, row sep=3em, column sep=3em]
    {  & P  &   \\
      M & P & 0 \\ };
  { [start chain];
    \chainin (m-1-2);
    { [start branch=P] \chainin (m-2-1)
        [join={node[left] {$\mu  $}}];}
    { [start branch=P'] \chainin (m-2-2)
	[join={node[right] {$\textrm{Id} $}}];}}
  { [start chain] \chainin (m-2-1);
    \chainin (m-2-2) [join={node[above] {\(\varphi \)}}];
    \chainin (m-2-3) ;}
\end{tikzpicture}
\end{center}
	\item If \(P\) is a quotient of the \(R\)-module \(M\) then \(P\) is isomorphic to a direct summand of \(P\). That is, every short exact sequence
		\begin{align*}
			0\to L \to M\to P\to 0
		\end{align*}
		splits.
	\item \(P\) is a direct summand of a free \(R\)-module.
	\end{itemize}
\end{prop}

\begin{defn}[Projective Modules]
	An \(R\)-module \(\prescript{}{R}P\) is called \textbf{projective} if any module \(M\) that projects onto \(P\) has an isomorphic copy of \(P\) as a direct summand.
\end{defn}
A projective module is merely one that satisfies any of the above equivalent conditions.

\begin{cor}
	Free modules are projective modules.\\

	A finitely generated module is projective if and only if it is the direct summand of a finitely generated free module.\\

	Every free module is a quotient of a projective module.
\end{cor}

\begin{exmp}

\end{exmp}

% Category theory explanation and functors

\subsection{Injective Modules}
\label{sub:injective_modules}

Of course we can also consider the reverse case-- when do \(R\)-module homomorphisms from \(L\) or \(N\) to \(D\) exist?\\

We can see that an \(R\)-module map from \(N\) to \(D\) induces a map from \(M\) to \(D\) by composition by
\begin{align*}
	\varphi' : \textrm{Hom}_R(N,D) &\to \textrm{Hom}_R(M,D)\\
	f &\mapsto f' = f \circ \varphi
\end{align*}
which is injective, and hence if the sequence
\begin{align*}
	M\to^{\varphi }N \to 0
\end{align*} is exact, then
\begin{align*}
	0 \to \textrm{Hom}_R(N,D) \to^{\varphi '} \textrm{Hom}_R(M,D)
\end{align*} is exact.\\

The reverse does not hold in general.

\begin{exmp}

\end{exmp}

\begin{thm}
	Let \(D,L,M,N\) form \(R\)-modules. If
	\begin{align*}
		0 \to L \to^{\psi }M \to^{\varphi }N \to 0
	\end{align*}
	is exact, then
	\begin{align*}
		0 \to \textrm{Hom}_R(N,D) \to^{\varphi '} \textrm{Hom}_R(M,D) \to^{\psi'} \textrm{Hom}_R(L,D)
	\end{align*} is exact.\\

	A homomorphism \(f:L\to D\) lifts to a homomorphism \(F:M\to D\) if and only if \(f\) is in the image of \(\psi '\).\\

	The sequence of homomorphisms is exact for all \(R\)-modules \(D\) if and only if
	\begin{align*}
		L \to^{\psi }M \to^{\varphi }N \to 0
	\end{align*}
	is exact.
\end{thm}
Hence the sequence
\begin{align*}
	0 \to \textrm{Hom}_R(N,D) \to^{\varphi '}\textrm{Hom}_R(M,D) \to^{\psi '}\textrm{Hom}_R(L,D) \to 0
\end{align*} is not a short exact sequence in general, as \(\psi '\) may not be surjective.\\

Of course, this sequence is exact if the original exact sequence is a split exact sequence (in which case the sequence of homomorphisms is a split exact sequence for every \(R\)-module \(D\)).

\begin{hw}
	If
	\begin{align*}
		0 \to \textrm{Hom}_R(N,D) \to^{\varphi '}\textrm{Hom}_R(M,D) \to^{\psi '}\textrm{Hom}_R(L,D) \to 0
	\end{align*}
	is exact for every \(R\)-module \(D\), then
	\begin{align*}
		0 \to L \to^{\psi }M \to^{\varphi }N \to 0
	\end{align*}
	is a split short exact sequence.\\

	This implies that if the homomorphism sequence is exact for every \(D\), then it is split exact for every \(D\).
\end{hw}

\begin{prop}
	Let \(Q\) be an \(R\)-module. Then the following are equivalent:
	\begin{itemize}
		\item Let \(L,M,N\) form \(R\)-modules. If
			\begin{align*}
				0 \to L \to^{\psi }M \to^{\varphi }N \to 0
			\end{align*}
			is a short exact sequence, then
			\begin{align*}
				0 \to \textrm{Hom}_R(N,Q) \to^{\varphi '} \textrm{Hom}_R(M,Q) \to^{\psi '} \textrm{Hom}_R(L,Q) \to 0
			\end{align*}
			is also a short exact sequence.
		\item Let \(L,M\) form \(R\)-modules. If \(0 \to L\to^{\psi }M\) is exact, then every \(R\)-module homomorphism from \(L\) to \(Q\) lifts to an \(R\)-module homomorphism of \(M\) into \(Q\). That is, the following diagram commutes:
\begin{center}
\begin{tikzpicture}% Fix later by making F dashed
  \matrix (m) [matrix of math nodes, row sep=3em, column sep=3em]
    { 0 & L  & M  \\
       & Q &  \\ };
  { [start chain];
    \chainin (m-1-1);
    \chainin (m-1-2);
    { [start branch=L] \chainin (m-2-2)
    [join={node[left] {\(f\) }}];}
    \chainin (m-1-3) [join={node[above] {\(\psi \)}}];
    { [start branch=M] \chainin (m-2-2)
	[join={node[right] {$F $}}];}}
\end{tikzpicture}
\end{center}
\item If \(Q\) is a submodule of the \(R\)-module \(M\), then \(Q\) is a direct summand of \(M\). That is, every short exact sequence
	\begin{align*}
		0 \to Q \to M \to N \to 0
	\end{align*}
	splits.
	\end{itemize}
\end{prop}

\begin{defn}[Injective Modules]
	An \(R\)-module \(\prescript{}{R}Q\) is called \textbf{injective} if for any module \(M\) that \(Q\) injects into, \(M\) has an isomorphic copy of \(Q\) as a direct summand.
\end{defn}

\begin{exmp}

\end{exmp}

%Category theory stuff again

Unfortunately, there is not a nice equivalent to the direct summand of a free \(R\)-module condition from projective modules. Instead:
\begin{prop}[Baer's Criterion]
	Let \(Q\) form an  \(R\)-module. \(\prescript{}{R}Q\) is injective if and only if for every left ideal \(I\triangleleft R\), any \(R\)-module homomorphism \(g:I\to Q\) can be extended to an \(R\)-module homomorphism \(G:R\to Q\).
\end{prop}
If \(R\) is a PID, then \(Q\) is injective if and only if \(rQ = Q\) for every nonzero \(r \in R\). Hence, a \(\Z\)-module is injective if and only if it is divisible. When \(R\) is a PID, quotient modules of injective \(R\)-modules are injective.
\begin{proof}

\end{proof}

\begin{cor}
	Every \(\Z\)-module is a submodule of an injective \(\Z\)-module.
\end{cor}
This can be useful to prove the more general statement:
\begin{thm}
	Let \(R\) be a ring and \(\prescript{}{R}M\) an \(R\)-module. Then \(M\) is contained in an injective \(R\)-module.
\end{thm}

\subsection{Flat Modules}
\label{sub:flat_modules}

Suppose \(D\) forms a right \(R\)-module. For every homomorphism \(f:X\to Y\) of left \(R\)-modules, we obtain a homomorphism
\begin{align*}
	1 \otimes f: D \otimes_R X \to D \otimes_R Y
\end{align*}
of abelian groups. If \(D \) is also an \((S,R)\)-bimodule, then \(1 \otimes f\) is a homomorphism of left \(S\)-modules.

\begin{thm}
	Let \(D\) form a right \(R\)-module, and \(L,M,N\) form left \(R\)-modules. If
	\begin{align*}
		0 \to L \to^{\psi }M \to^{\varphi }N \to 0
	\end{align*}
	is exact, then
	\begin{align*}
		D \otimes_R L ^{1 \otimes \psi }D \otimes_R M \to^{1 \otimes \varphi }D \otimes_R N \to 0
	\end{align*}
	is exact.\\

	If \(D\) is an \((S,R)\)-bimodule then the sequence of abelian groups is an exact sequence of left \(S\)-modules. Hence, if \(S = R\) is commutative, then the sequence of abelian groups is an exact sequence of \(R\)-modules. The map \(1 \otimes \varphi \) is not necessarily injective, so the sequence may not extend to a short exact sequence.\\

	The sequence of abelian groups is exact for all right \(R\)-modules \(D\) if and only if
	\begin{align*}
		L \to^{\psi }M \to^{\varphi }N \to 0
	\end{align*}
	is exact.
\end{thm}

\begin{prop}
	Let \(A\) form a right \(R\)-module. Then the following are equivalent:
	\begin{itemize}
		\item Let \(L,M,N\) form left \(R\)-modules. If
			\begin{align*}
				0 \to L \to^{\psi } M \to^{\varphi }N \to 0
			\end{align*}
			is a short exact sequence, then
			\begin{align*}
				0 \to A \otimes_R L \to^{1 \otimes \psi } A \otimes_R M \to^{1 \otimes \varphi } A \otimes_R N \to 0
			\end{align*}
			is a short exact sequence.
		\item  Let \(L,M\) be left \(R\)-modules, if
			\begin{align*}
				0 \to L \to^{\psi }M
			\end{align*} is an exact sequence of left \(R\)-modules, then
			\begin{align*}
				0 \to A \otimes_R L \to^{1 \otimes \psi } A \otimes_R M
			\end{align*} is an exact sequence of abelian groups.
	\end{itemize}
\end{prop}

\begin{defn}
	A right \(R\)-module \(\prescript{}{R}A\) is called \textbf{flat} if either of the above conditions hold.
\end{defn}

\begin{cor}
	Free modules are flat. Moreover, projective modules are flat.
\end{cor}

\begin{exmp}

\end{exmp}

\begin{thm}
	Let \(R,S\) be rings, left \(A\) form a right \(R\)-module, let \(B\) form an \((R,S)\)-bimodule and let \(C\) form a right \(S\)-module. Then there is an isomorphism of abelian groups:
	\begin{align*}
		\textrm{Hom}_S(A \otimes_R B, C) \cong \textrm{Hom}_R(A, \textrm{Hom}_S(B,C))
	\end{align*}
\end{thm}
If \(R=S\) is commutative this is an isomorphism of \(R\)-modules with the standard \(R\)-module structures.

\begin{cor}
	If \(R\) is commutative then the tensor product of two projective \(R\)-modules is projective.
\end{cor}

\end{document}


\section{Tree-based Methods}
\subsection{Decision Trees}
Decision Trees are created via the Classification and Regression Trees (CART)
training algorithm. They can be represent as binary trees where at each node the
partition the data space according to a threshold to minimize either gini impurity
or entropy between the two child nodes.
\subsection{Random Forest}
Random forests are a tree-based technique that uses a high number of decision
trees built out of randomly selected sets of features. Contrary to the simple
decision tree, it is highly uninterpretable but its generally good performance
makes it a popular algorithm. It averages the decisions across several trees
to combat overfitting. Random forests are a type of ensemble methods.
\subsection{Boosting}
The idea of boosting methods is to combine several weak learners to form a
stronger one. The main ones are summed up below:
\begin{enumerate}
  \item Adaptive boosting: Known as adaboost, it places high weights on errors
    to improve at the next boosting step.
  \item Gradient boosting: Weak learners are trained on the remaining errors.
\end{enumerate}
Boosting requires training several models to improve upon previous ones.


\documentclass[t,usenames,dvipsnames]{beamer}
\usetheme{Copenhagen}
\setbeamertemplate{headline}{} % remove toc from headers
\beamertemplatenavigationsymbolsempty

\usepackage{amsmath, tikz, xcolor}
\usetikzlibrary{arrows.meta, calc}

\title{Circles}
\author{}
\date{}

\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Objectives}
    \tableofcontents[currentsection]
  \end{frame}
}

\begin{document}

\begin{frame}
    \titlepage
\end{frame}

\section{Write the Standard Form of the Equation of a Circle.}

\begin{frame}{}
A \alert{circle} is the set of all points $(x, y)$ in the plane whose distance (the \textit{radius}) from a fixed point (the \textit{center}) is constant.   \newline\\

\begin{center}
    \begin{tikzpicture}[scale=0.8]
    \draw (0,0) circle (1in);
    \draw [fill=black] (0,0) circle (1pt) node [below] {$(h, k)$};
    \draw (0,0) -- (45:1in) node [above right] {$(x,y)$};
    \draw [fill=black] (45:1in) circle (1pt);
    \node at (45:0.5in) [above left] {$r$};
    \end{tikzpicture}
\end{center}
\pause
The equation can be found by incorporating the distance formula (Pythagorean Theorem):
\[
r^2 = (x-h)^2 + (y-k)^2
\]
\end{frame}

\begin{frame}{Example 1}
Write the standard from of the equation of a circle with center $(-2, 3)$ and radius 5.
\begin{align*}
    \onslide<2->{(x-(-2))^2 + (y-3)^2 = 5^2} \\[10pt]
    \onslide<3->{(x+2)^2 + (y-3)^2 = 25} \\
\end{align*}
\end{frame}

\begin{frame}{Example 2}
Write the standard form of the equation of a circle which has $(-1, 3)$ and $(2, 4)$ as the endpoints of the diameter.  \newline\\ \pause

The center is the \alert{midpoint} of the endpoints of the diameter:
\begin{align*}
    \onslide<3->{h = \frac{-1+2}{2} \quad & \quad k = \frac{3+4}{2}} \\[10pt]
    \onslide<4->{h = \frac{1}{2} \quad & \quad k = \frac{7}{2}} \\
\end{align*}
\end{frame}

\begin{frame}{Example 2}
\onslide<1->{The radius is half the length of the diameter.}
\begin{align*}
    \onslide<2->{d &= \sqrt{(2-(-1))^2 + (4-3)^2}} \\[10pt]
    \onslide<3->{&= \sqrt{10}} \\[10pt]
    \onslide<4->{r &= \frac{\sqrt{10}}{2}} \\[8pt]
\end{align*}
\end{frame}

\begin{frame}{Example 2}
$h = \frac{1}{2} \qquad k = \frac{7}{2} \qquad r = \frac{\sqrt{10}}{2}$
\begin{align*}
\onslide<1->{\left(x-\frac{1}{2}\right)^2 + \left(y-\frac{7}{2}\right)^2 &= \left(\frac{\sqrt{10}}{2}\right)^2}  \\[10pt]
\onslide<2->{\left(x-\frac{1}{2}\right)^2 + \left(y-\frac{7}{2}\right)^2 &= \frac{10}{4}}    \\[10pt]
\onslide<2->{\left(x-\frac{1}{2}\right)^2 + \left(y-\frac{7}{2}\right)^2 &= \frac{5}{2}} \\
\end{align*}
\end{frame}

\section{Find the Center and Radius of a Circle.}

\begin{frame}{Example 3}
Find the center and radius of $(x+2)^2 + (y-1)^2 = 4$.   \newline\\ \pause

$h = -2 \qquad k = 1$   \pause  \newline\\

Center: $(-2, 1)$   \pause

\begin{align*}
    \onslide<4->{r^2 &= 4} \\
    \onslide<5->{r & = 2}
\end{align*}

\onslide<6->{Radius: 2}
\end{frame}

\begin{frame}{Finding Center and Radius When Not in Standard Form}
We can use the techniques of finding vertices of parabolas to find the center and radius of a circle not in standard form.   \newline\\    \pause

\begin{enumerate}
    \item Move any constants to the other side of the equation. \newline\\ \pause
    \item Find the $x$-coordinates of the vertices of the $x$ and $y$ terms. These are your $h$ and $k$, respectively.    \newline\\ \pause
    \begin{itemize}
        \item Use $x$'s as the variable when finding the vertex for the $y$'s parabola.  \newline\\ \pause
    \end{itemize}
    \item Add the absolute value of the $y$-coordinates of the vertices to the right side.
\end{enumerate}
\end{frame}

\begin{frame}{Example 4a}
Find the center and radius of each. \newline\\
(a) \quad $3x^2 - 6x + 3y^2 +4y - 4 = 0$
\begin{align*}
    \onslide<2->{{\color{red}3x^2-6x} + {\color{blue}3y^2 + 4y} &= 4}
\end{align*}
\begin{minipage}{0.4\textwidth}
\onslide<3->{
\begin{tikzpicture}[scale=0.6]
\draw[dashed,gray] (-1,-3) grid (3,2);
\draw[<->,>=stealth] (-1.5,0) -- (3.5,0) node [right] {$x$};
\draw[<->,>=stealth] (0,-3.5) -- (0,2.5) node [right] {$y$};
\draw[<->,>=stealth,color=red,line width=1.25,domain=-0.25:2.25] plot (\x,{3*\x*\x - 6*\x});
\draw[color=red,fill=red] (1,-3) circle (3pt) node [below right] {\scriptsize $(1,-3)$};
\node[color=red, anchor=west] at (2.2,1.2) {\scriptsize $3x^2-6x$};
\end{tikzpicture}
}
\end{minipage}
\hspace{0.25cm}
\onslide<4->{
\begin{minipage}{0.4\textwidth}
\begin{tikzpicture}[scale=0.66]
\draw[dashed,gray] (-2,-2) grid (2,2);
\draw[<->,>=stealth] (-2.5,0) -- (2.5,0) node [right] {$x$};
\draw[<->,>=stealth] (0,-2.5) -- (0,2.5) node [right] {$y$};
\draw[<->,>=stealth,color=blue,line width=1.25,domain=-1.6:0.27] plot (\x,{3*\x*\x + 4*\x});
\draw[color=blue,fill=blue] (-0.667,-1.333) circle (3pt) node [below right] {\scriptsize $\left(-\frac{2}{3},-\frac{4}{3}\right)$};
\node[color=blue, anchor=west] at (0.5,1.1) {\scriptsize $3x^2+4x$};
\end{tikzpicture}
\end{minipage}
}
\end{frame}

\begin{frame}{Example 4a}
    \begin{align*}
    {\color{red}3(x-1)^2} + {\color{blue}3\left(y+\frac{2}{3}\right)^2} &= 4 + {\color{red}|-3|} + {\color{blue}\left|-\frac{4}{3}\right|} \\[10pt]
    \onslide<2->{3\left(x-1\right)^2 + 3\left(y+\frac{2}{3}\right)^2 &= \frac{25}{3}} \\[10pt]
    \onslide<3->{(x-1)^2 + \left(y+\frac{2}{3}\right)^2 &= \frac{25}{9}} \\
    \end{align*}

\onslide<4->{Center: $\left(1, -\frac{2}{3}\right)$} \qquad
\onslide<5->{Radius: $\sqrt{\frac{25}{9}} = \frac{5}{3}$}
\end{frame}

\begin{frame}{Example 4b}
(b) \quad $2x^2 + 5x + 2y^2 - 8y + 1 = 0$
\begin{align*}
\onslide<2->{{\color{red}2x^2+5x} + {\color{blue}2y^2-8y} &= -1}
\end{align*}
\begin{minipage}{0.5\textwidth}
\onslide<3->{
\begin{tikzpicture}
\draw[dashed, gray] (-3,-3) grid (1,1);
\draw[<->,>=stealth] (-3.5,0) -- (1.5,0) node [right] {$x$};
\draw[<->,>=stealth] (0,-3.5) -- (0,1.5) node [above] {$y$};
\draw[<->,>=stealth,color=red,line width=1.25,domain=-2.75:0.25] plot (\x, {2*\x*\x + 5*\x}) node [right] {\scriptsize $2x^2+5x$};
\draw[color=red,fill=red] (-1.25,-3.125) circle (3pt);
\node[color=red, anchor=north east] at (-1.25,-3.125) {\scriptsize $\left(-\frac{5}{4}, -\frac{25}{8}\right)$};
% \node[color=red, anchor=west] at (0,-0.5) {\scriptsize $2x^2+5x$};
\end{tikzpicture} }
\end{minipage}
\hspace{0.25cm}
\onslide<4->{
\begin{minipage}{0.4\textwidth}
\begin{tikzpicture}[scale=0.5]
\draw[dashed,gray] (-1,-8) grid (4,1);
\draw[<->,>=stealth] (-1.5,0) -- (4.5,0) node [right] {$x$};
\draw[<->,>=stealth,] (0,-8.5) -- (0,1.5) node [above] {$y$};
\draw[<->,>=stealth,color=blue,line width=1.25,domain=-0.15:4.15] plot (\x, {2*\x*\x - 8*\x}) node [right] {\scriptsize $2x^2-8x$};
\draw[color=blue,fill=blue] (2,-8) circle (3pt) node [below] {\scriptsize $(2,-8)$};
\end{tikzpicture}
\end{minipage}
}
\end{frame}

\begin{frame}{Example 4b}
\begin{align*}
    {\color{red}2\left(x+\frac{5}{4}\right)^2} + {\color{blue}2\left(y-2\right)^2} &= -1 + {\color{red}\left|-\frac{25}{8}\right|} + {\color{blue}|-8|} \\[8pt]
    \onslide<2->{2\left(x+\frac{5}{4}\right)^2 + 2(y-2)^2 &= \frac{81}{8}} \\[8pt]
    \onslide<3->{\left(x+\frac{5}{4}\right)^2 + (y-2)^2 &= \frac{81}{16}}   \\
\end{align*}

\onslide<4->{Center: $\left(-\frac{5}{4}, 2\right)$} \qquad
\onslide<5->{Radius: $\sqrt{\frac{81}{16}} = \frac{9}{4}$}
\end{frame}

\end{document}


    \filetitle{!symbolic}{Attempt to solve the current equations block symbolically using the Symbolic Maths Toolbox}{sstatelang/symbolic}

	\paragraph{Syntax}

 \begin{verbatim}
 !equations
     EQUATION;
     EQUATION;
     EQUATION;
     ...

     !symbolic
     !solvefor
         LIST_OF_VARIABLES
 \end{verbatim}

 \paragraph{Description}

 \paragraph{Example}


% Copyright 2018 Melvin Eloy Irizarry-Gelpí
\chapter{WXY Octonion}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A WXY octonion has the form
\begin{equation}
    a_{0} + a_{1} W + a_{2} X + a_{3} WX + a_{4} Y + a_{5} WY + a_{6} XY + a_{7} WXY
\end{equation}
These follow from a parabolic Cayley-Dickson construct on the WX quaternions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Arithmetic Operations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Multiplication}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Conjugate Operations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Asterisk Conjugation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Quadrance}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Cloak Conjugation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Dagger Conjugation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Hodge Star}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Zero-Divisors}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Differential Operators}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...


\subsection{Preservation of Value}
\label{sec:preservation-of-value}

As visualized in Figure~\ref{fig:fund-preservation},
the total amount of lovelace in any given chain state
$\var{s}\in\ChainState$ is completely contained within the values of the six
variables:

\begin{tabular}{||l|l|l|l||}\hline\hline

  \textbf{Variable} & \textbf{Name in Figure~\ref{fig:fund-preservation}}
                    & \textbf{Nesting Inside Chain State} & \textbf{Kind} \\ \hline
  utxo & circulation & s.nes.es.ls.utxoSt & Map over Lovelace Values  \\ \hline
  deposits & deposits &  s.nes.es.ls.utxoSt & Lovelace Value ($\Coin$) \\ \hline
  fees & fees &  s.nes.es.ls.utxoSt & Lovelace Value ($\Coin$) \\ \hline
  rewards & reward accounts & s.nes.es.ls.dpstate.dstate  & Lovelace Value ($\Coin$)  \\ \hline
  treasury & treasury &  s.nes.es.acnt  & Lovelace Value ($\Coin$) \\ \hline
  reserves & reserves & s.nes.es.acnt & Map over Lovelace Values \\ \hline
  \hline
\end{tabular}

\noindent
Notice that $\var{deposits}$, $\var{fees}$, $\var{treasury}$, and $\var{reserves}$
are all single lovelace values, while $\var{utxo}$, and $\var{rewards}$ are
maps whose values are lovelace.

We define the \emph{Lovelace Value} of a given chain state as:
\begin{definition}[Lovelace Value]
  \label{def:val}
  \begin{equation*}
    \Val(s~\in~\var{State}) =
        \Val(\var{utxo}) +
            \Val(\var{deposits}) +
            \Val(\var{fees}) +
            \Val(\var{reserves}) +
            \Val(\var{treasury}) +
            \Val(\var{rewards})
  \end{equation*}
  where
  \begin{equation*}
      \Val(x \in \Coin) = x
  \end{equation*}
  \begin{equation*}
      \Val((\wcard\mapsto (y \in \Coin))^{*}) = \sum y
  \end{equation*}
\end{definition}

\noindent
For any state that is used in a given subtransition of $\mathsf{CHAIN}$,
we define $\Val{}$ in an analogous way, setting the value of any variable that is not explicitly
represented in the state to zero.
For example, given $\var{utxoSt}\in\UTxOState$,
\begin{equation*}
  \Val(\var{utxoSt}) =
  \left(\sum_{\wcard\mapsto(\wcard,~v)\in\var{utxo}}v\right) + \var{deposits} + \var{fees}
\end{equation*}

\noindent
The key property that we want to prove is that no semantic transition changes the value that
is captured in the state ($\Val{s}$).
This property is easy to state: intuitively,
the \emph{Lovelace Value}before the transition is the same as the
\emph{Lovelace Value} after that transition.

\begin{theorem}[Preservation of Value]
  \label{thm:chain-pres-of-value}
  For all environments $e$, blocks $b$, and states $s$, $s'$, if
  \begin{equation*}
    e\vdash s\trans{\hyperref[fig:rules:chain]{chain}}{b}s'
  \end{equation*}
  then
  \begin{equation*}
    \Val(s) = \Val(s')
  \end{equation*}
\end{theorem}

\noindent
We will prove the soundness of Theorem~\ref{thm:chain-pres-of-value} via a few lemmas.

\begin{lemma}
  \label{lemma:value-sum-pres-1}
  For any mapping $m:A\mapsto\Coin$ and set $s\in\powerset{A}$,
  \begin{equation*}
    \Val(\var{m}) = \Val(s\subtractdom m) + \Val(s\restrictdom m)
  \end{equation*}
\end{lemma}
\begin{proof}
  easy
\end{proof}

\begin{lemma}
  \label{lemma:value-sum-pres-2}
  For any mappings $m_1, m_2:A\mapsto\Coin$,
  if $\dom{m_1}\cap\dom{m_2}=\emptyset$,
  then
  \begin{equation*}
    \Val(m_1\cup m_2) = \Val(m_1) + \Val(m_2)
  \end{equation*}
\end{lemma}
\begin{proof}
  easy
\end{proof}

\begin{lemma}
  \label{lemma:utxo-pres-of-value}
  For all environments $e$, transactions $t$, and states $s$, $s'$, if
  \begin{equation*}
    e\vdash s\trans{\hyperref[fig:rules:utxo-shelley]{utxo}}{t}s'
  \end{equation*}
  then
  \begin{equation*}
    \Val(s) + w = \Val(s')
  \end{equation*}
  where $w = \fun{wbalance}~(\fun{txwdrls}~{t})$.
\end{lemma}

\begin{proof}
  The proof is essentially unfolding the definition of the predicate
  \begin{equation}
    \label{cons-is-prod}
    \consumed{pp}{utxo}{t} = \produced{pp}{stpools}{t}
  \end{equation}
  and applying a little algebra.
%
If we let:
  \begin{equation*}
    \begin{array}{r@{~=~}l}
      k & \keyRefunds{pp}{stkCreds}{t} \\
      f & \txfee{t} \\
      d & \totalDeposits{pp}{stpools}{(\txcerts{t})} \\
    \end{array}
  \end{equation*}
  then equation~\ref{cons-is-prod} can be rewritten as:
  \begin{equation*}
    \Val(\txins{t} \restrictdom{\var{utxo}}) + w + k = \Val(\outs{t}) + f + d
  \end{equation*}
  where $\outs{}$ is defined in Figure~\ref{fig:functions:utxo} and returns a value of type $\UTxO$.
  Therefore, moving $k$ to the right and adding $\txins{t} \subtractdom{\var{utxo}}$ to each side,
  \begin{equation*}
    \Val(\txins{t} \restrictdom{\var{utxo}}) + \Val(\txins{t} \subtractdom{\var{utxo}}) + w
    = \Val(\outs{t}) + f + d - k + \Val(\txins{t} \subtractdom{\var{utxo}})
  \end{equation*}
  (Though not needed for the proof at hand,
  note that $d-k$ is non-negative since the deposits will always be large enough to cover
  the current obligation. See Theorem~\ref{thm:non-neg-deposits}.)
%
  It then follows that:
  \begin{equation*}
    \begin{array}{r@{~=~}lr}
      \Val(\var{utxo}) + w
    & \Val(\outs{t}) + f + d - k + \Val(\txins{t} \subtractdom{\var{utxo}})
    & \text{(by Lemma~\ref{lemma:value-sum-pres-1})}
    \\
    & \Val((\txins{t} \subtractdom{\var{utxo}})\cup\outs{t}) + (d - k) + f
    & \text{(by Lemma~\ref{lemma:value-sum-pres-2})}
    \end{array}
  \end{equation*}
  Note that in order to apply Lemma~\ref{lemma:value-sum-pres-2} above,
  it must be true that $(\txins{t} \subtractdom{\var{utxo}})$ and $(\outs{t})$
  have disjoint domains, which follows from the uniqueness of the transaction IDs.

  Therefore, by adding the deposits and fees from $s$ to the equality above,
  it follows that $\Val(s) + w = \Val(s')$.
\end{proof}

\begin{lemma}
  \label{lemma:deleg-pres-of-value}
  For all environments $e$, transactions $c$, and states $s$, $s'$, if
  \begin{equation*}
    e\vdash s\trans{\hyperref[fig:delegation-rules]{deleg}}{c}s'
  \end{equation*}
  then
  \begin{equation*}
    \Val(s) = \Val(s')
  \end{equation*}
\end{lemma}

\begin{proof}
  The only variable with value in this transition is \var{rewards}.
  Only two of the rules in $\mathsf{DELEG}$ can change \var{rewards},
  namely $\mathsf{Deleg{-}Reg}$ and $\mathsf{Deleg{-}Dereg}$.
  However, $\mathsf{Deleg{-}Reg}$ only adds a zero value,
  and $\mathsf{Deleg{-}Dereg}$ only removes a zero value.
\end{proof}

\begin{lemma}
  \label{lemma:delegs-pres-of-value}
  For all environments $e$, certificates $\Gamma$, and states $s$, $s'$, if
  \begin{equation*}
    e\vdash s\trans{\hyperref[fig:rules:delegation-sequence]{delegs}}{\Gamma}s'
  \end{equation*}
  then
  \begin{equation*}
    \Val(s) = \Val(s') + w
  \end{equation*}
  where $w = \fun{wbalance}~(\fun{txwdrls}~{t})$,
  and $t$ is the transaction in the environment $e$.
\end{lemma}

\begin{proof}
  The proof is by induction on the length of $\Gamma$.
  Note that the only variable with value in this transition is \var{rewards}.

  \vspace{2ex}
  \noindent
  \emph{In the base case}, we look at the rule $\mathsf{Seq{-}delg{-}base}$.
  Since $\var{wdrls}\subseteq\var{rewards}$, then
  $\var{rewards} = \var{wdrls}\cup\var{(\var{rewards}\setminus\var{wdrls})}$.
%
  Therefore
  \begin{equation*}
    \begin{array}{r@{~=~}lr}
      \Val{(\var{rewards})}
      & \Val{(\var{rewards}\setminus\var{wdrls})} + \Val{(\var{wdrls})}
      & \text{by Lemma~\ref{lemma:value-sum-pres-2}}
      \\
      & \Val{(\var{rewards}\setminus\var{wdrls})} + w
      & \text{by definition}
      \\
      & \Val\left(\var{rewards}\unionoverrideRight\{(w, 0) \mid w \in \dom \var{wdrls}\}\right) + w
    \end{array}
  \end{equation*}
  Therefore $\Val(s) = \Val(s')$.

  \vspace{2ex}
  \noindent
  \emph{In the inductive case}, we look at the rule $\mathsf{Seq{-}delg{-}ind}$.
  In this case, the lemma then follows directly from Lemma~\ref{lemma:deleg-pres-of-value}.
\end{proof}

\begin{lemma}
  \label{lemma:poolreap-pres-of-value}
  For all environments $e$, epoch $\epsilon$, and states $s$, $s'$, if
  \begin{equation*}
    e\vdash s\trans{\hyperref[fig:rules:pool-reap]{poolreap}}{\epsilon}s'
  \end{equation*}
  then
  \begin{equation*}
    \Val(s) = \Val(s')
  \end{equation*}
\end{lemma}

\begin{proof}
  The $\mathsf{POOLREAP}$ value is contained in
  $\var{deposits}$, $\var{treasury}$, and $\var{rewards}$.
  Notice that $\var{unclaimed}$ is added to $\var{treasury}$
  and subtracted from the $\var{deposits}$.
  Moreover, $\var{refunded}$ is subtracted from $\var{deposits}$.
  (Note that $\var{deposits}-(\var{unclaimed}+\var{refunded})$
  is non-negative by Theorem~\ref{thm:non-neg-deposits}.)
  It therefore suffices to show that
  \begin{equation*}
    \begin{array}{r@{~=~}l}
    \Val(\var{rewards}\unionoverridePlus\var{refunds})
    & \Val(\var{rewards}) + \Val(\var{refunds})
    \\
    & \Val(\var{rewards}) + \var{refunded}
    \end{array}
  \end{equation*}
  But this is clear from the definition of $\unionoverridePlus$.
\end{proof}

\begin{lemma}
  \label{lemma:ru-pres-of-value}
  For every $(\Delta t,~\Delta r,~\var{rs},~\Delta f)$ in the range of $\fun{createRUpd}$,
  \begin{equation*}
    \Delta t + \Delta r + \Val(rs) + \Delta f = 0
  \end{equation*}
\end{lemma}

\begin{proof}
  In the definition of $\fun{createRUpd}$ in Figure~\ref{fig:functions:reward-update-creation},
  We see that:
  \begin{equation*}
    \begin{array}{r@{~=~}l}
      \var{rewardPot} & \var{feeSS} + \Delta r \\
      \var{R} & \var{rewardPot} - \Delta t_1 \\
      \Delta t_2 & R - \Val(\var{rs})\\
      \Delta t & \Delta t_1 + \Delta t_2 \\
    \end{array}
  \end{equation*}
  Therefore
  \begin{equation*}
    \begin{array}{r@{~=~}l}
      (\var{feeSS} + \Delta r) & \var{rewardPot} = R + \Delta t_1 = \Delta t_2 + \Val(rs) + \Delta t_1  \\
      0 & (\Delta t_1 + \Delta t_2 ) - \Delta r + \Val(rs)- \var{feeSS} \\
      0 & \Delta t - \Delta r + \Val(rs)- \var{feeSS} \\
    \end{array}
  \end{equation*}
  It then suffices to notice that $\fun{createRUpd}$ returns
  $(\Delta t,-~\Delta r,~\var{rs},~-\var{feeSS})$.
\end{proof}

\noindent

Note that Lemma~\ref{lemma:ru-pres-of-value} is not strictly need for the proof of
Theorem~\ref{thm:chain-pres-of-value}, since the $\mathsf{NEWEPOCH}$ transition
requires that $\Delta t + \Delta r + \Val(rs) + \Delta f = 0$ holds.
It does, however, give us confidence that the $\mathsf{CHAIN}$ transition can proceed.

We are now ready to prove Theorem~\ref{thm:chain-pres-of-value}.

\begin{proof}
  For a given transition $\mathsf{TR}$, let \POV{TR}
  be the statement:

  \begin{tabular}{l}
    for all environments $e$, signals $\sigma$, and states $s$, $s'$,
    $$
    $e\vdash s\trans{tr}{\sigma}s'~\implies~\Val(s) = \Val(s')$.
    $$
  \end{tabular}

  \noindent
  Our goal is to prove \POV{CHAIN}.
  Lemmas~\ref{lemma:utxo-pres-of-value} and \ref{lemma:delegs-pres-of-value} imply \POV{LEDGER},
  since $\mathsf{UTXOW}$ transforms state exactly as $\mathsf{UTXO}$ does.
  \POV{LEDGERS} then follows by straightforward induction on the length of $\Gamma$:
  the base case is trivial;
  and the inductive case follows directly from \POV{LEDGER}.
%
  \POV{SNAP} holds trivially, since it contains no value.
  Similarly, \POV{NEWPP} holds since $\var{diff}$ is added to $\var{reserves}$
  and subtracted from $\var{deposits}$.
  Therefore \POV{EPOCH} holds by Lemma~\ref{lemma:poolreap-pres-of-value}.
  \POV{MIR} holds since
  $\Val{i_{rwd}'}=\var{tot}$ in Figure~\ref{fig:rules:mir}.
  Morover, \POV{NEWEPOCH} holds in the presence of $\fun{applyRUpd}$
  since the transition requires $\Delta t + \Delta r + \Val(rs) + \Delta f = 0$.
  \POV{CHAIN} easily follows from this.
\end{proof}

\subsection{Non-negative Deposit Pot}  % TODO - this section is out of date due to no decaying deposits
\label{sec:non-negative-deposit-pot}

The \emph{deposit pot} (the variable $\var{deposits}$ in the UTxO State)
represents the amount of \emph{lovelace} that is set aside by the system as a whole for refunding deposits.
Deposits are added to this pot, which then decays exponentially over time,
and is also depleted by any refunded deposits.
At an epoch boundary, the decayed parts of any deposits (including, possibly, deposits for any transactions that will complete in future epochs)
will be distributed as additional \emph{rewards}, as described in~\cite{delegation_design}.
Since $\var{deposits}$ is only used to record the value of future refunds or rewards whose costs have
already been incurred, both it and any reward value will always be non-negative.
Note that there are two types of deposits which are recorded in the same pot: those for stake keys; and those for stake pools.
Stake keys are deregistered in the slot in which the deregistration certificates
is processed. Stake pools, however, are staged for retirement on epoch boundaries.
%
The following theorem ensures that the deposit pot is properly maintained
and will always be large enough to meet all of its obligations.

\begin{figure}[h!]
  \begin{tabular}{||l|l|l|l||}\hline\hline

    \textbf{Variable} & \textbf{Value}
                      & \textbf{Nesting Inside Chain State} & \textbf{Kind} \\ \hline
    deposits & 0 &  s.nes.es.ls.utxoSt & $\Coin$ \\ \hline
    stkCreds & $\emptyset$ & s.nes.es.ls.dpstate.dstate.stkCreds
             & $\StakeCreds$ ($\Credential\mapsto\Slot$)  \\ \hline
    stpools & $\emptyset$ & s.nes.es.ls.dpstate.pstate.stpools
            & $\StakePools$ ($\KeyHash\mapsto\Slot$)  \\ \hline
  \end{tabular}
  \caption{Initial Chain State}
  \end{figure}

\begin{theorem}[Non-negative Deposit Pot]
  \label{thm:non-neg-deposits}
  Let $n\in\N$ and $c_0\in\ChainState$ be a chain state in which $\var{deposits} ~=~0$, $\var{stkCreds}~=~\emptyset$ and $\var{stPools}~=~\emptyset$, as shown above:
%  \\~\\
  If
  \begin{equation*}
    s_0\vdash c_0\trans{\hyperref[fig:rules:chain]{chain}}{b_0}c_1,~~
    s_1\vdash c_1\trans{\hyperref[fig:rules:chain]{chain}}{b_1}c_2,~~
    \ldots,~~
    s_n\vdash c_n\trans{\hyperref[fig:rules:chain]{chain}}{b_n}c_{n+1},~~n \ge 0
  \end{equation*}
  is a sequence of valid $\mathsf{CHAIN}$ transitions,
  then $\forall i, 0 \le i \le n, \var{deposits} ~(c_{n+1}) \ge 0$.
\end{theorem}

\begin{proof}

  We will prove a slightly stronger condition, namely that some stronger invariants hold
  most of the time, and that when they do fail to hold, then $\var{deposits}$ is still non-negative.
  These stronger invariants will require a few additional definitions.
%
  Given a slot $s$, let $\ell(s)$ be the first slot of the epoch that $s$ occurs in,
  that is $\ell = \fun{firstSlot}\circ\fun{epoch}$.
  Given a mapping $m\in\mathsf{T}\to\Slot$ and a slot $s\in\Slot$,
  let $\fun{sep}$ be the function that separates $m$ into two maps,
  those whose value is strictly less than $s$ and those whose value is at least $s$.
  So,
  \begin{equation*}
    \fun{sep}~m~s = \forall x\mapsto t~\in~m,~~
    \left(\{x\mapsto t~\mid~t<s\},~\{x\mapsto t~\mid~t\geq s\}\right)
  \end{equation*}

  \noindent
  If we assume that the \emph{protocol parameters}, $pp$, are fixed\footnote{Note that the
    protocol parameters can only change in the $\mathsf{NEWPP}$ transition.}, then we can provide convenience functions
  $R_c$ and $R_p$ for the \emph{stake credential} and \emph{stake pool} refunds, respectively:
  \begin{equation*}
    \begin{array}{r@{~=~}l}
      R_c~s_0~s_1 & \refund{d_{val}}{d_{min}}{\lambda_d}{s_1-s_0} \\
      R_p~s_0~s_1 & \refund{p_{val}}{p_{min}}{\lambda_p}{s_1-s_0} \\
    \end{array}
  \end{equation*}
  where $d_{val}$, $d_{min}$, $\lambda_d$, $p_{val}$, $p_{min}$, $\lambda_p$
  are the protocol parameter values from $pp$, and $\fun{refund}$ is defined in
  Figure~\ref{fig:functions:deposits-refunds}.
  We let \DBE{c}{s} (``Deposits (precisely) Big Enough"), be the following property:
  \begin{equation}\tag{DBE}\label{DBE}
    \var{deposits}
    = \left(\sum_{\wcard\mapsto t\in C_{old}}R_c~t~\ell(s)\right)
    + |C_{new}|\cdot d_{val}
    + \left(\sum_{\wcard\mapsto t\in P_{old}}R_p~t~\ell(s)\right)
    + |P_{new}|\cdot p_{val}
  \end{equation}
  where
  \begin{equation*}
    \begin{array}{r@{~=~}l}
      C_{old},~C_{new} & \fun{sep}~\var{stkCreds}~{\ell(s)} \\
      P_{old},~P_{new} & \fun{sep}~\var{stpools}~{\ell(s)},
    \end{array}
  \end{equation*}
  for some slot, $s$, where $\var{pp}$, $\var{stkCreds}$, $\var{stpools}$ are in the corresponding chain state, $c$.
%
  In other words, \DBE{c}{s} asserts that the deposit pot is equal to the
  sum of the deposit refunds that were available at the previous epoch boundary,
  plus the sum of the initial deposit values for all the deposits from the current epoch.

  Notice that for a chain state $c$ and slot $s$, if the range of
  $\var{stkCreds}$ and $\var{stpools}$ contains only slots from the previous epoch,
  then \DBE{c}{s} is equivalent to
  \begin{equation}\tag{DEO}\label{DEO}
    \var{deposits} = \obligation{pp}{stkCreds}{stpools}{\ell(s)}
  \end{equation}
  where $\fun{obligation}$ is defined in Figure~\ref{fig:funcs:epoch-helper-rewards}.
%
  It is generally true that \DBE{c'}{s_i} holds after each subtransition of
  $s_i\vdash c_i\trans{\hyperref[fig:rules:chain]{chain}}{b_i}c_{i+1}$.
  However, this invariant can fail to hold after the
  $\hyperref[fig:delegation-transitions]{\mathsf{DELEG}}$ transition,
  since this transition can add and remove stake credentials, and can also add stake pools,
  but the deposit pot is not adjusted accordingly
  until the next subtransiton of $\hyperref[fig:rules:ledger]{\mathsf{LEDGER}}$,
  namely $\hyperref[fig:rules:utxo-shelley]{\mathsf{UTXO}}$.
%
  The invariant can also fail to hold if the slot increases while the chain state remains the same.
  That is, if \DBE{c_{i+1}}{s_i} holds, then \DBE{c_{i+1}}{s_{i+1}} can fail to hold if
  $\epoch{s_i} < \epoch{s_{i+1}}$, since the value of the deposit
  in the left hand side of equation~\ref{DBE} remains the same, but the
  refunded values become smaller\footnote{Note that if $\epoch{s_i} = \epoch{s_{i+1}}$, then \DBE{c_{i+1}}{s_{i+1}} is trivially true.}.
  Therefore, in this situation we can consider the slightly weaker constraint:
  \begin{equation}\tag{DGO}\label{DGTO}
    \var{deposits} \geq \obligation{pp}{stkCreds}{stpools}{\ell(s)}
  \end{equation}
  The difference between the left and right hand sides of the inequality
  corresponds to the lovelace value in $c_{i+1}$ that decays between $s_i$ and $s_{i+1}$.

  There are four sub-transitions where $\var{deposits}$ is changed:
  $\mathsf{SNAP}$ (Figure~\ref{fig:rules:snapshot}),
  $\mathsf{POOLREAP}$ (Figure~\ref{fig:rules:pool-reap}),
  $\mathsf{NEWPP}$ (Figure~\ref{fig:rules:new-proto-param}),
  $\mathsf{UTXO}$ (Figure~\ref{fig:rules:utxo-shelley}).
  This ordering is also the order in which $\var{deposits}$ is changed.
  Of these sub-transitions, only $\mathsf{UTXO}$ actually changes the value of $\var{deposits}$
  when $s_i$ is in the same epoch as $s_i$.
  (We say that $s_i$ \emph{crosses the epoch boundary} if the precondition of
  Rule~\ref{eq:new-epoch} in Figure~\ref{fig:rules:new-epoch} is met,
  namely if $\epoch{s_i} \ge e_\ell+1$.)
%
  The proof then proceeds by induction on $n$, showing the following:
  \begin{itemize}
    \item
      Let $c$ be the chain state after the $\mathsf{SNAP}$ transition
      in $s_i\vdash c_i\trans{\hyperref[fig:rules:chain]{chain}}{b_i}c_{i+1}$.
      If \DGO{c_i}{s_i}, then \DBE{c}{s_i} holds.
    \item $\mathsf{POOLREAP}$ preserves \ref{DBE}.
    \item $\mathsf{NEWPP}$ preserves \ref{DBE}.
    \item The property for $\mathsf{UTXO}$ requires a bit of explanation.
      Let $\var{nes}\in\NewEpochState$ be the new epoch state in $c_i$.
      Note that the property \ref{DBE} makes sense for values of $\NewEpochState$
      since it contains all the relevant variables.
      Similarly, \ref{DBE} also makes sense for values of $\UTxOState\times\PParams$.
      Let
      $$
        {\begin{array}{c}
           \var{gkeys} \\
         \end{array}}
        \vdash\var{nes}\trans{\hyperref[fig:rules:tick]{tick}}{\var{bh}}\var{nes'}
      $$
      be the first sub-transition of
      $s_i\vdash c_i\trans{\hyperref[fig:rules:chain]{chain}}{b_i}c_{i+1}$.
      If \DBE{\var{nes'}}{s_i} holds, then \DBE{(us', pp)}{s_i} holds for every transaction
      $tx$ in $b_i$, where:
      $$
      \var{env}\vdash \var{us} \trans{\hyperref[fig:rules:utxow-shelley]{utxo}}{tx} \var{us'},
      $$
      is a sub-transition of
      $s_i\vdash c_i\trans{\hyperref[fig:rules:chain]{chain}}{b_i}c_{i+1}$,
      and $\var{pp}$ is the protocol parameters in $\var{nes'}$.
  \end{itemize}

  \noindent
  Case $\hyperref[fig:rules:snapshot]{\mathsf{SNAP}}$.
  We must show that
  if $c$ is the chain state after the $\mathsf{SNAP}$ transition
  in $s_i\vdash c_i\trans{\hyperref[fig:rules:chain]{chain}}{b_i}c_{i+1}$,
  and \DGO{c_i}{s_i} holds, then so does \DBE{c}{s_i}.
%
  We can assume that $s_i$ crosses the epoch boundary,
  since otherwise the $\mathsf{SNAP}$ transition will not occur.
  Since the $\mathsf{SNAP}$ transition only happens within the $\mathsf{TICK}$ transition
  on the epoch boundary, it follows that
  $c_i$ does not contain any stake credentials or pools from the current epoch,
  and so \ref{DBE} will be equivalent to \ref{DEO} (the current epoch is $\epoch{s_i}$).
  However, \DBE{c}{s_i} holds trivially, since it is determined from the $\fun{obligation}$ value.
  \\~\\
  Case $\hyperref[fig:rules:pool-reap]{\mathsf{POOLREAP}}$.
  We must show that \ref{DBE} is preserved.
%
  We again assume that $s_i$ crosses the epoch boundary.
  The $\mathsf{POOLREAP}$ transition does the following:
  \begin{enumerate}
    \item leaves $\var{stkCreds}$ unchanged,
    \item removes $\var{retired}$ from $\var{stpools}$,
    \item subtracts $\var{unclaimed}+\var{refunded}$ from $\var{deposits}$.
  \end{enumerate}
%
  Notice that the domain of the $\var{pr}$ is $\var{retired}$,
  and similarly the domain of the $\var{rewardAcnts}$ is also $\var{retired}$
  since the domains of $\var{stpools}$ and $\var{poolParams}$ are the same.
  Therefore $\var{retired}$ is the disjoint union of
  $\dom({\var{refunds}})$ and $\dom({\var{mRefunds}})$, so that
  \begin{equation*}
    \begin{array}{r@{~=~}l}
      \var{unclaimed}+\var{refunded}
      &
      \left(
        \sum\limits_{\wcard\mapsto t\in\var{refunds}}R_p~t~\ell(s)
      \right)+
      \left(
        \sum\limits_{\wcard\mapsto t\in\var{mRefunds}}R_p~t~\ell(s)
      \right)
      \\
      &
      \sum\limits_{\wcard\mapsto t\in\var{rewardAcnts'}}R_p~t~\ell(s)
      \\
      &
      \left(
        \sum\limits_{\wcard\mapsto t\in\var{stpools}}R_p~t~\ell(s)
      \right)-
      \left(
        \sum\limits_{\wcard\mapsto t\in\var{retired}\subtractdom\var{stpools}}R_p~t~\ell(s)
      \right)
    \end{array}
  \end{equation*}
  Therefore, it follows that if \ref{DEO} holds before $\mathsf{POOLREAP}$, then it also holds afterwards.
  \\~\\
  Case $\hyperref[fig:rules:new-proto-param]{\mathsf{NEWPP}}$.
  We must show that \ref{DBE} is preserved.
%
  We again assume that $s_i$ crosses the epoch boundary.
  In this transition $\var{pp}$ can change, but $\var{stkCreds}$, $\var{stpools}$,
  and $\var{deposits}$ do not change.
  As in the $\mathsf{SNAP}$ case, \DBE{c}{s_i} holds trivially,
  since it is set to the value that is determined by $\fun{obligation}$.
  \\~\\
  Case $\hyperref[fig:rules:utxo-shelley]{\mathsf{UTXO}}$.
  We assume that \DBE{\var{nes'}}{s_i} holds, where $\var{nes'}$
  is the new epoch state after the $\mathsf{TICK}$ transition.
  We must show that \ref{DBE} is preserved after each $\mathsf{UTXO}$ transition.
%
  The $\mathsf{DELEGS}$ transition can result in values being
  added to or deleted from $\var{stkCreds}$, and added to $\var{stpools}$.
  Let $A_s$ be the added stake credentials, $D_s$ be the deleted credentials, and
  $A_p$ be the added stake pools, where $\var{stkCreds}'$ is the stake credential mapping
   $\var{stpools}'$ is the stake pools, and $\var{deposits}'$ is the deposit pot  after $\mathsf{DELEGS}$.
  We have that
  \begin{equation*}
    \begin{array}{rcl}
      \var{D_s} & \subseteq & \var{\var{stkCreds}\cup\var{A_s}} \\
      \var{stkCreds}' & = & (\var{stkCreds}\cup\var{A_s})\setminus\var{D_s} \\
      \var{stpools}' & = & \var{stpools}\cup\var{A_p} \\
    \end{array}
  \end{equation*}
  The slots in the range of $A_s$ will all be equal to $s_i$,
  but the slots in the range of $D_s$
may either be from the current epoch or an earlier one, so we split them using $\fun{sep}$:
  \begin{equation*}
    (\var{D_{s\_old}},~\var{D_{s\_new}}) = \fun{sep}~\var{D_s}~\ell(s_i)
  \end{equation*}
  We must then show that
  \begin{equation*}
    \var{deposits}' = \var{deposits}
    + |A_s|\cdot d_{val}
    + |P_c|\cdot p_{val}
    - |D_{s\_new}|\cdot d_{val}
    - \left(\sum_{\wcard\mapsto t\in D_{s\_old}}R_c~t~\ell(s_i)\right)
  \end{equation*}
  Looking at the $\mathsf{UTXO}$ transition in Figure~\ref{fig:rules:utxo-shelley},
  \begin{equation*}
    \var{deposits}' = \var{deposits} + \totalDeposits{pp}{stpools}{(\txcerts{tx})}
    - (\var{refunded} + \var{decayed})
  \end{equation*}
  The function $\fun{totalDeposits}$ is defined in Figure~\ref{fig:functions:deposits-refunds}
  and it is clear that here it is equal to
  $$|A_s|\cdot d_{val} + |P_c|\cdot p_{val.}$$
  Recall that
  \begin{equation*}
    \begin{array}{r@{~=~}l}
      \var{refunded} & \keyRefunds{pp}{stkCreds}~{tx} \\
      \var{decayed} & \decayedTx{pp}{stkCreds}~{tx}
    \end{array}
  \end{equation*}
  where $\fun{keyRefunds}$ is defined in Figure~\ref{fig:functions:deposits-refunds}.
  This iterates $\fun{keyRefund}$ from the same figure,
  which in turn just looks up the creation slot for a transaction and returns $R_c$.
  The function to calculate the value of decayed deposits, $\fun{decayedTx}$, is defined in Figure~\ref{fig:functions:deposits-decay}.
  This iterates $\fun{decayedKey}$ from the same figure.
  Therefore, to show that
  \begin{equation}\label{deleted-is-refunds-plus-decayed}
    |D_{s\_new}|\cdot d_{val} + \sum_{\wcard\mapsto t\in D_{s\_old}}R_c~t~\ell(s_i)
    = \var{refunded} + \var{decayed},
  \end{equation}
  and thus complete the proof for the $\mathsf{UTXO}$ case,
  it suffices to show that for a given $\var{c}\mapsto s\in D_s$,
  the $R_c$ value plus the $\fun{decayedKey}$ value that is associated with the stake
  credential $c$ is equal to $d_{val}$ if $\epoch(s)=\epoch(s_i)$, and is otherwise equal to $R_c~s~\ell(s_i)$.
  Looking at the definition of $\fun{decayedKey}$, observe that if $\epoch(s)=\epoch(s_i)$
  then $\var{start}=\var{created}$ and so the decayed value is $(R_c~s~s)-(R_c~s~s_i)$.
  However, $R_c~s~s = d_{val}$, so the refund plus the decayed value is
  $d_{val}-(R_c~s~s_i)+(R_c~s~s_i)=d_{val}$.
  Otherwise, if $s$ is from a previous epoch, then $\var{start}=\ell(s_i)$, and so
  the decayed value is $(R_c~s~\ell(s_i))-(R_c~s~s_i)$.
  The refund plus the decayed value is thus
  $(R_c~s~\ell(s_i))-(R_c~s~s_i)+(R_c~s~s_i)=(R_c~s~\ell(s_i))$.
  Therefore, equation~\ref{deleted-is-refunds-plus-decayed} holds, and
  consequently so also does \DBE{c'}{s_i}.

\end{proof}


\section{\texorpdfstring{$\mathcal{O}$}{O}-Notation}

\toclesssubsection{Motivation / Definition}

\begin{frame}{$\mathcal{O}$-Notation}{Motivation}
  \textbf{We are interested in:}
  \begin{itemize}
  \item
    Example: \texttt{sorting}
    \begin{itemize}
      \item
        Runtime of \texttt{Minsort} \enquote{is growing as}
        $\quad{}\quad{}n^2$
      \item
         Runtime of \texttt{Heapsort} \enquote{is growing as}
         $\quad{}n \, \log n$
    \end{itemize}
    \item<2- |handout:1>
      Growth of a function in runtime $T(n)$
      \begin{itemize}
      \item the role of constants (e.g. $1ns$) is minor
      \item it is enough if relation holds for some $n\geq \ldots$
      \end{itemize}
    \item<3- |handout:1>
      Describe the growth of the function \textbf{more formally}
    \begin{itemize}
      \item
        by the means of Landau-Symbols \cite{wikipedia_big_o_notation}):
            \begin{itemize}
                \item
                    {\color{Mittel-Blau}$\mathcal{O}(n)$} (Big O of $n$),
                \item
                    {\color{Mittel-Blau}$\Omega (n)$} (Omega of $n$),
                \item
                    {\color{Mittel-Blau}$\Theta (n)$} (Theta of $n$)
            \end{itemize}
    \end{itemize}
  \end{itemize}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Definition}
  \textbf{Big $\mathcal{O}$-Notation:}
  \begin{itemize}
    \item<2- |handout:1>
     Consider the function:
      $f\!: \mathbb{N} \to \mathbb{R}, \; n \mapsto f(n)$
      \begin{itemize}
        \item
          $\mathbb{N}\!:$ Natural numbers $\rightarrow$ input size
        \item
          $\mathbb{R}\!:$ Real numbers $\rightarrow$ runtime
      \end{itemize}
   \item<3- |handout:1>
     \textbf{Example:}
     \begin{itemize}[<+- |handout:1>]
       \item
         $f(n) = 3 \, n$
       \item
         $f(n) = 2 \, n \, \log n$
       \item
         $f(n) = \frac{1}{10} n^2$
       \item
         $f(n) = n^2 + 3 \, n \, \log n - 4 \, n$
      \end{itemize}
  \end{itemize}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Definition}
  \textbf{Big $\mathcal{O}$-Notation:}
  \begin{itemize}
    \item<2- |handout:1>
      Given two functions $f$ and $g$:\\
      $f,g\!: \mathbb{N} \to \mathbb{R}$
    \item<3- |handout:1>
      \textbf{Intuitive:} $f$ is Big-O of $g$ ($f$ is $\mathcal{O}(g)$)
      \begin{itemize}
        \item
          $\ldots$ if $f$ relative to $g$ does not grow faster than $g$
        \item
          the growth rate matters, not the absolute values
      \end{itemize}
  \end{itemize}
\end{frame}

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

% For every picture that defines or uses external nodes, you'll have to
% apply the 'remember picture' style. To avoid some typing, we'll apply
% the style to all pictures.
\tikzstyle{every picture}+=[remember picture]

% By default all math in TikZ nodes are set in inline mode. Change this to
% displaystyle so that we don't get small fractions.
%\everymath{\displaystyle}

\tikzstyle{na} = [baseline=-.5ex]

\begin{frame}{$\mathcal{O}$-Notation}{Definition}
  \textbf{Big $\mathcal{O}$-Notation:}%
  \begin{itemize}
    \item<2- |handout:1>
      \textbf{Informal:} $f = \mathcal O(g)$
      \begin{itemize}
        \item<2- |handout:1>
           \enquote{$=$} corresponds to "is" not "is equal to"
        \item<3- |handout:1>
           $\ldots$ if for some value $n_0$ for all $n \geq n_0$
        \item<4- |handout:1>
           $f(n) \leq C \cdot g(n)$ for a constant C
        \item<5- |handout:1>
            ($f = \mathcal O(g)$: From a value $n_0$ for all
            $n \geq n_0 \rightarrow f(n) \leq C \cdot g(n)$)
      \end{itemize}
	\item<6- |handout:1>
      \textbf{Formal:} $f \in \mathcal O(g)$\\
  \end{itemize}
  \begin{block}{\textbf{Formal:} $f \in \mathcal O(g)$}<6- |handout:1>
    \begin{math}
      \mathcal O(g) = \lbrace \tikz[baseline] {
        \node (fun) [anchor=base] {f};
      }: \mathbb{N} \to \mathbb{R} ~ \tikz[baseline] {
        \node (for) [anchor=base] {|};
      }\tikz[baseline] {
        \node (exone) [anchor=base] {$\exists$};
      }\!\!n_0 \in \mathbb{N},
      \tikz[baseline] {
        \node (extwo) [anchor=base] {$\exists$};
      }\!\!C > 0,\tikz[baseline] {
        \node (forall) [anchor=base] {$\forall$};
      }\!\!n \geq n_0\!\!\tikz[baseline] {
        \node (such) [anchor=base] {:};
      }
      f(n) \leq C \cdot g(n)\rbrace
    \end{math}
  \end{block}
  \tikz[baseline] {\node (funtext) [anchor=north] {
    {\footnotesize\onslide<7- |handout:1>{\begin{tabular}[c]{@{}c@{}}
          ``set of\\
          all functions''
        \end{tabular}}
  }};}\quad{} \tikz[baseline] {\node (fortext) [anchor=north] {
    {\footnotesize\onslide<8- |handout:1>{\begin{tabular}[c]{@{}c@{}}
        ``for which''
        \end{tabular}}
  }};}\quad{} \tikz[baseline] {\node (extext) [anchor=north] {
    {\footnotesize\onslide<9- |handout:1>{\begin{tabular}[c]{@{}c@{}}
        ``it exists''
        \end{tabular}}
  }};}\quad{} \tikz[baseline] {\node (foralltext) [anchor=north] {
    {\footnotesize\onslide<10- |handout:1>{\begin{tabular}[c]{@{}c@{}}
        ``for all''
        \end{tabular}}
  }};}\quad{} \tikz[baseline] {\node (suchtext) [anchor=north] {
    {\footnotesize\onslide<11- |handout:1>{\begin{tabular}[c]{@{}c@{}}
        ``such that''
        \end{tabular}}
  }};}
  \begin{tikzpicture}[>=stealth,overlay,thick]
    \path[->,color=red]<7- |handout:1> (funtext) edge [bend left]  (fun);
    \path[->,color=red]<8- |handout:1> (fortext) edge [bend left]  (for);
    \path[->,color=red]<9- |handout:1> (extext) edge [bend left]  (exone);
    \path[->,color=red]<9- |handout:1> (extext) edge [bend right]  (extwo);
    \path[->,color=red]<10- |handout:1> (foralltext) edge [bend left]  (forall);
    \path[->,color=red]<11- |handout:1> (suchtext) edge [bend left]  (such);
  \end{tikzpicture}
\end{frame}

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

\subsection{Examples}

\begin{frame}{$\mathcal{O}$-Notation}{Examples}
  \textbf{Illustration of the Big O-Notation:}\\[-1.0em]
  \begin{columns}
    \begin{column}{0.9\textwidth}
      \begin{figure}[!h]
        \includegraphics[width=\linewidth]{Images/BigONotationRuntime.png}
        \caption{Runtime of two algorithms $f_1, f_2$}
        \label{fig:big_o_runtime_example}
      \end{figure}
    \end{column}
    \begin{column}{0.1\textwidth}
      \vspace{-4.75em}\\
      \hspace*{-2.5em}$g(n)$\\[2.0em]
      \hspace*{-2.5em}$f_2 \in \mathcal{O}(g)$\\[2.5em]
      \hspace*{-2.5em}$f_1 \in \mathcal{O}(g)$
    \end{column}
  \end{columns}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Examples}
  \textbf{Example:}
  \begin{itemize}
    \item
      $f(n) = 5 \, n + 7, \; g(n) = n$\\
      $\Rightarrow$ $5 \, n + 7 \in \mathcal{O}(g)$\\
      $\Rightarrow f \in \mathcal{O}(g)$
     \item
      \textbf{Intuitive:}\\
      $f(n) = 5 \, n + 7$ $\rightarrow$ linear growth
  \end{itemize}
  \begin{alertblock}{Attention}
    $f(n) \leq g(n)$ is not guaranteed, better is
    $f(n) \leq C \cdot g(n) \;\; \forall n \geq n_0$.
  \end{alertblock}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Proof}
  \label{slide:proofone}
  \begin{proof}[
    We have to proof:
    \begin{math}
      \exists n_0, \, \exists C, \, \forall n \geq n_0 \! : \;
        5 \, n + 7 \leq C \cdot n
    \end{math}
  ]
    \begin{eqnarray*}
      \onslide<2- |handout:1>{
        &5 \, n + 7 &\leq \;\; 5 \, n + n
        \hspace{1em} (\text{for} ~ n \geq 7)
      }\\
      \quad{}\onslide<3- |handout:1>{
        && = \;\; 6 \, n
      }
    \end{eqnarray*}
    \onslide<4- |handout:1>{
      $\hspace{1.5em} \Rightarrow n_0 = 7, \, C = 6$ \qedhere
    }
  \end{proof}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Proof}
  \begin{proof}[Alternate proof:]
    \begin{eqnarray*}
      \onslide<2- |handout:1>{
        &5 \, n + 7 &\leq \;\; 5 \, n + 7 \, n
        \hspace{1em} (\text{for} ~ n \geq 1)
      }\\
      \quad{}\onslide<3- |handout:1>{
        && = \;\; 12 \, n
      }
    \end{eqnarray*}
    \onslide<4- |handout:1>{
      $\hspace{1.5em} \Rightarrow n_0 = 1, \, C = 12$ \qedhere
    }
  \end{proof}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Examples}
  \textbf{Big O-Notation:}
  \begin{itemize}
    \item
      We are only interested in the term with the highest-order,
      the fastest growing summand, the others will be ignored
    \item
      $f(n)$ is limited {\color{Mittel-Blau}from above} by $C \cdot g(n)$
  \end{itemize}
  \textbf{Examples:}
  \begin{align*}
     2 \, n^2 + 7 \, n - 20 \in & \,\mathcal{O}(n^2)\\
     2 \, n^2 + 7 \, n \, \log n - 20 \in & {}\\
     7 \, n \, \log n - 20 \in & {}\\
     5 \in & {}\\
     2 \, n^2 + 7 \, n \, \log n + n^3 \in & {}\\
  \end{align*}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Examples}
  \textbf{Harder Example:}
  \begin{itemize}
    \item Polynomes are simple
    \item More problematic: combination of complex functions
      \begin{displaymath}
        2 \sqrt{x} + 3 \ln x \in \mathcal{O} (??)
      \end{displaymath}
  \end{itemize}
\end{frame}

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

\section{\texorpdfstring{$\Omega$}{Omega}-Notation}

\begin{frame}{$\Omega$-Notation}{Definition}
  \textbf{Omega-Notation:}
  \begin{itemize}
    \item
      \textbf{Intuitive}:
      \begin{itemize}
        \item
          $f \in \Omega(g)$, $f$ is growing at least as fast as $g$
        \item
          So the same as Big-O but with \textit{at-least} and not
          \textit{at-most}
      \end{itemize}
  \end{itemize}
  \begin{block}{\textbf{Formal:} $f \in \Omega(g)$}
    \begin{math}
      \Omega(g) = \lbrace f: \mathbb{N} \to \mathbb{R} ~ | ~
        \exists n_0 \in \mathbb{N}, \, \exists C > 0, \,  \forall n \geq n_0:\,
        f(n) \tikz[baseline] {\node (geq) [anchor=base] {$\geq$};}
        C \cdot g(n)\rbrace
    \end{math}
  \end{block}
  \begin{center}
    \tikz[baseline] {\node (geqtext) [anchor=base] {
      {\footnotesize\onslide<1->{\begin{tabular}[c]{@{}c@{}}
        ``in $O(n)$\\
        we had $\leq$''
      \end{tabular}}
    }};}
  \end{center}
  \begin{tikzpicture}[>=stealth,overlay,thick]
    \path[->,color=red] (geqtext) edge [bend right] (geq);
  \end{tikzpicture}
\end{frame}

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

\begin{frame}{$\Omega$-Notation}{Proof}
  \label{slide:prooftwo}
  \textbf{Example:}\\
  \begin{proof}[Proof of $f(n) = 5n + 7 \in \Omega(n)$:]
    \begin{eqnarray*}
      &\underbrace{5 \, n + 7}_{f(n)} &\geq \;\; \underbrace{1 \cdot n}_{g(n)}
      \hspace{1em} (\text{for} ~ n \geq 1)
    \end{eqnarray*}
    $\hspace{1.5em} \Rightarrow n_0 = 1, \, C = 1$ \qedhere
  \end{proof}
\end{frame}

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

\begin{frame}{$\Omega$-Notation}{Examples}
  \textbf{Illustration of the Omega-Notation:}\\[-1.0em]
  \begin{columns}
    \begin{column}{0.9\textwidth}
      \begin{figure}[!h]
        \includegraphics[width=\linewidth]{Images/OmegaNotationRuntime.png}
        \caption{Runtime of two algorithms $f_1, f_2$}
        \label{fig:omega_o_runtime_example}
      \end{figure}
    \end{column}
    \begin{column}{0.1\textwidth}
      \vspace{-4.75em}\\
      \hspace*{-2.5em}$f_2 \in \Omega(g)$\\[2.0em]
      \hspace*{-2.5em}$f_1 \in \Omega(g)$\\[2.5em]
      \hspace*{-2.5em}$g(n)$
    \end{column}
  \end{columns}
\end{frame}

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

\begin{frame}{$\Omega$-Notation}{Examples}
  \textbf{Big Omega-Notation:}
  \begin{itemize}
    \item
      We are only interested in the term with the highest-order,
      the fastest growing summand, the others will be ignored
    \item
      $f(n)$ is limited {\color{Mittel-Blau}from underneath} by
      $C \cdot g(n)$
  \end{itemize}
  \textbf{Examples:}
  \begin{align*}
    2 \, n^2 + 7 \, n - 20 \in & \,\Omega(n^2)\\
    2 \, n^2 + 7 \, n \, \log n - 20 \in & {}\\
    7 \, n \, \log n - 20 \in & {}\\
    5 \in & {}\\
    2 \, n^2 + 7 \, n \, \log n + n^3 \in & {}
  \end{align*}
\end{frame}

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

\section{\texorpdfstring{$\Theta$}{Theta}-Notation}

\begin{frame}{$\Theta$-Notation}{Definition}
  \textbf{Theta-Notation:}
  \begin{itemize}
    \item
      \textbf{Intuitive}: $f$ is Theta of $g$ $\ldots$
      \begin{itemize}
        \item
          $\ldots$ if $f$ is growing as much as $g$
        \item
          $f \in \Theta(g)$, $f$ is growing at the same speed as $g$
       \end{itemize}
  \end{itemize}
  \begin{block}{\textbf{Formal:} $f \in \Theta(g)$}
    $\Theta(g) = \underbrace{\mathcal O(g) \cap \Omega(g)}_{Intersection}$
  \end{block}
  \textbf{Example:}\\
  \hspace*{1.5em}$f(n) = 5 \, n + 7, \;
    f(n) \in \mathcal{O}(n), \,
    f(n) \in \Omega(n)$\\
  \hspace*{3.0em}$\Rightarrow f(n) \in \Theta(n)$\\[0.5em]
  \begin{center}
   \textit{Proof for $\mathcal{O}(g)$ and $\Omega(g)$ look at
     slides~\ref{slide:proofone} and~\ref{slide:prooftwo}}
  \end{center}
\end{frame}

\begin{frame}{$\Theta$-Notation}{Graphs}
  \begin{center}
    \includegraphics[width=0.8\textwidth]{Images/lower-upper-bound.pdf}
  \end{center}
  \begin{itemize}
    \item $f$ and $g$ have the same ``growth''
  \end{itemize}
\end{frame}
%-------------------------------------------------------------------------------

\section{Runtime}

\toclesssubsection{Summary}

\begin{frame}{Runtime}{Landau-Symbol Summary}
  \textbf{Big O-Notation} $\mathcal{O}(n)$\textbf{:}\\
    \begin{itemize}
      \item
        $f$ is growing {\color{Mittel-Blau}at most} as fast as $g$
      \item
        $C \cdot g(n)$ is the upper bound
    \end{itemize}
  \textbf{Big Omega-Notation} $\Omega(n)$\textbf{:}\\
  \begin{itemize}
    \item
      $f$ is growing {\color{Mittel-Blau}at least} as fast as $g$
    \item
      $C \cdot g(n)$ is the lower bound
  \end{itemize}
  \textbf{Big Theta-Notation} $\Theta(n)$\textbf{:}\\
  \begin{itemize}
    \item
      $f$ is growing at {\color{Mittel-Blau}the same} speed as $g$
      \begin{itemize}
        \item
          $C_1 \cdot g(n)$ is the lower bound
        \item
          $C_2 \cdot g(n)$ is the upper bound
      \end{itemize}
  \end{itemize}
\end{frame}

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

\begin{frame}{Runtime}{Common Runtimes}
  \label{slide:theta-examples}
  \begin{table}[!h]
    \begin{center}
      \caption{Common runtime types}
      \label{RuntimeTable}
      \begin{tabularx}{\textwidth}{XX}
        Runtime & Growth\\
        \hline
        $f \in \Theta (1)$ & constant time\\
        $f \in \Theta (\log n) = \Theta (\log_k n)$ & logarithmic time\\
        $f \in \Theta (n)$ & linear time\\
        $f \in \Theta (n \, \log n)$ & n-log-n time (nearly linear)\\
        \hline
        $f \in \Theta (n^2)$ & squared time\\
        $f \in \Theta (n^3)$ & cubic time\\
        $f \in \Theta (n^k)$ & polynomial time\\
        \hline
        $f \in \Theta (k^n)$, $f \in \Theta(2^n)$ & exponential time
      \end{tabularx}
    \end{center}
  \end{table}
\end{frame}

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

\subsection{Limit / Convergence}

\begin{frame}
  \begin{itemize}
  \item So far discussed:
    \begin{itemize}
      \item Membership in $O(\ldots)$ proofed by hand:\\
        {\color{MainA}Explicit calculation of $n_0$ and $C$}
	  \vspace{1em}
      \item
	    \textbf{However:} Both hint at {\color{MainA}limits} in calculus
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}{$\mathcal{O}$-Notation}{Limit / Convergence}
  \label{slide:limit}
  \textbf{Definition of \enquote{Limit}}
  \begin{itemize}
    \item
      The {\color{MainA}limit $L$} exists for an infinite sequence
	  $f_1, f_2, f_3, \ldots$\\
      if for all $\epsilon > 0$ one $n_0 \in \mathbb{N}$ exists,
      such that for all\\
      $n \geq n_0$ the following holds true:
      $\left| f_n - L \right| \leq \epsilon$
    \item
      A function $f\!: \mathbb{N} \rightarrow \mathbb{R}$ can be written as a
      sequence\\
      $\Rightarrow$ $\lim\limits_{n \rightarrow \infty} f_n = L$
  \end{itemize}
  \begin{block}<2- |handout:1>{The limit is converging:}
    \begin{math}
      \forall \epsilon > 0 \; \exists n_0 \in \mathbb{N} \;\;
      \forall n \geq n_0 \! : \; \left| f_n - L \right| \leq \epsilon
    \end{math}
  \end{block}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Limit / Convergence}
  \begin{itemize}
  \item Example for the proof of a limit
  \item Function $f(n) = 2 + \frac{1}{n}$ with limes $\lim_{n \to \infty} f(n) = 2$
  \item \enquote{Engineering} solution: use $n = \infty{}$
    \begin{displaymath}
      \frac{1}{\infty} = 0 \Rightarrow \lim_{n \to \infty} f(n)
        = \lim_{n \to \infty} 2 + \dfrac{1}{n}
        = 2
    \end{displaymath}
  \end{itemize}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Limit / Convergence}
  \begin{itemize}
  \item Now a more formal proof for $\displaystyle\lim_{n \to \infty} 2 +
    \dfrac{1}{n}  = 2$
  \item We need to show: for all given $\epsilon$ there is an $n_0$ such
    that for all $n \geq n_0$
    \begin{displaymath}
      \left| 2 + \dfrac{1}{n} - 2 \right| =  \left| \dfrac{1}{n}  \right| \leq \epsilon
    \end{displaymath}
  \item<2- |handout:1>
    E.g.: for $\epsilon=0.01$ we get $\frac{1}{n} \leq \epsilon$
    for $n\geq 100$
  \item<3- |handout:1>
    In general
    \begin{displaymath}
      n_0 = \left\lceil \dfrac{1}{\epsilon} \right\rceil
    \end{displaymath}
  \item<4- |handout:1>
    Then we get:
    \begin{eqnarray*}
      \left|
        \frac{1}{n} \vphantom{\dfrac{1}{\frac{1}{\epsilon}}}
      \right| = \dfrac{1}{n}
      \; \leq \;
      \dfrac{1}{n_0} = \dfrac{1}{\left\lceil\frac{1}{\epsilon}\right\rceil}
      \leq \dfrac{1}{\frac{1}{\epsilon}}
      = \epsilon \qed
    \end{eqnarray*}
  \end{itemize}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Limit / Convergence}
  \label{slide:fraction}
  Let $f,g \! : \; \mathbb{N} \to \mathbb{R}$ with an existing limit
  \[\lim_{n \to \infty} \dfrac{f(n)}{g(n)} = L\]
  Hence the following holds:
  \begin{align}
    \label{eq:big-O}
    & f \in \mathcal{O}(g) & \Leftrightarrow
    && \lim_{n \to \infty} \dfrac{f(n)}{g(n)} < \infty\\
    & f \in \Omega(g) & \Leftrightarrow
    && \lim_{n \to \infty} \dfrac{f(n)}{g(n)} > 0\\
    & f \in \Theta(g) & \Leftrightarrow
    && 0 < \lim_{n \to \infty} \dfrac{f(n)}{g(n)} < \infty
  \end{align}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Limit / Convergence}
  \[
    f \in \mathcal{O}(g)
    \; \Leftrightarrow \;
    \lim\limits_{n \rightarrow \infty} \frac{f(n)}{g(n)} < \infty
  \]
  \begin{proof}[Forward proof ($\Rightarrow$):]
     $f \in \mathcal{O}(g) \stackrel{\text{def. of }\mathcal{O}(n)}{\Rightarrow}
     \exists n_0, \, C\; \forall n \geq n_0:
     \; f(n) \leq C \cdot g(n)$
     \begin{alignat*}{2}
       \Rightarrow && \exists n_0, \, C\; \forall n \geq n_0:
       \dfrac{f(n)}{g(n)} &\leq \; C\\
       \Rightarrow && \displaystyle
       \lim_{n \to \infty}\dfrac{f(n)}{g(n)} &\leq \; C
       \qedhere
      \end{alignat*}
  \end{proof}
\end{frame}

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

\begin{frame}{$\mathcal{O}$-Notation}{Limit / Convergence}
  \begin{proof}[Backward proof ($\Leftarrow$):]
    \begin{center}
      \vspace{-0.5em}
      \begin{math}
        \begin{aligned}
          & {} & \lim_{n \to \infty} \frac{f(n)}{g(n)} &< \; \infty\\
          & \Rightarrow & \lim_{n \to \infty} \frac{f(n)}{g(n)} &= \; C &&
          \hspace*{1.5em}\text{For some } C \in \mathbb{R} \text{ (Limit)}
        \end{aligned}
      \end{math}
      \vspace{1.0em}\\
      \begin{math}
        \begin{aligned}
          \stackrel{\text{def. limes}}{\Rightarrow} \hspace*{0.5em} &&
          \exists n_0, \, \forall n \geq n_0: \hspace*{1.0em}&&
          \frac{f(n)}{g(n)} &\leq \; C + \varepsilon \;\;\;
            (e.g.\;\varepsilon = 1)\\
          \Rightarrow \; &&
          \exists n_0, \, \forall n \geq n_0: \hspace*{1.0em}&&
          f(n) &\leq \; \underbrace{(C + 1)}_{O-notation\;constant} \cdot g(n)\\
          \Rightarrow \; &&
          f \in \mathcal{O}(g)
          \qedhere
        \end{aligned}
      \end{math}
    \end{center}
  \end{proof}
\end{frame}


\section{Overview of statistics}

One characterization of statistics is that it is the science of learning
about natural phenomena. The process of learning about natural phenomena proceeds
in a cyclical fashion. One first posits a ``model'' for a natural phenomenon.
She designs an experiment to measure a quantity related to the phenomenon of interest.
She then collects data, summarizes it as a statistic, and performs a test of
competing hypotheses before updating her hypothesis about the natural phenomenon.
The newly updated hypothesis replaces the original hypothesis in the second
iteration of the cycle.

For example, we might wish to study the genetics of body weight in mice.
We first posit the existence of body weight quantitative trait loci (QTL), which
are regions of the genome that affect mouse body weight. We quantitatively state the competing possibilities as the null hypothesis that there is no QTL against the alternative hypothesis of presence of a QTL. We then design an experiment, perhaps using genetically diverse mice, like those from the Diversity Outbred mouse population. We measure body weight in, say, 100 Diversity Outbred mice and obtain genome-wide genetic data from each. We then summarize our observations by performing multiple instances of a statistical technique called ``linear regression''. We perform statistical hypothesis tests to quantify the evidence against the null hypothesis.

\section{Maximum likelihood methods}

\section{Restricted maximum likelihood methods}


\section{Dynamic Type Checking}

Expressions evaluate to numbers, boolean values, strings, arrays or function values. Implementations
of Source generate error messages when unexpected values are used as follows.

Only function values can be applied using the syntax:

\begin{eqnarray*}
 \textit{expression}
                                   & ::=   &  \textit{name}
                                               \texttt{\textbf{(}}\  \textit{expressions} \
                                               \texttt{\textbf{)}}\\
\end{eqnarray*}

For compound functions, implementations need to check that the number of \textit{expressions}
matches the number of parameters.

The following table specifies what arguments Source's operators
take and what results they return. Implementations need to check the types of arguments and
generate an error message when the types do not match.

\begin{center}
\begin{tabular}{c|c|c|c}
operator & argument 1 & argument 2 & result\\ \hline
\texttt{\textbf{+}} & number   & number     & number\\
\texttt{\textbf{+}} & string   & string     & string\\
\texttt{\textbf{-}} & number   & number     & number\\
\texttt{\textbf{*}} & number   & number     & number\\
\texttt{\textbf{/}} & number   & number     & number\\
\texttt{\textbf{\%}} & number   & number     & number\\
\texttt{\textbf{===}} & any  & any     & bool\\
\texttt{\textbf{!==}} & any   & any     & bool\\
\texttt{\textbf{>}} & number   & number     & bool\\
\texttt{\textbf{>}} & string   & string     & bool\\
\texttt{\textbf{<}} & number   & number     & bool\\
\texttt{\textbf{<}} & string   & string     & bool\\
\texttt{\textbf{>=}} & number   & number     & bool\\
\texttt{\textbf{>=}} & string   & string     & bool\\
\texttt{\textbf{<=}}    & number   & number     & bool\\
\texttt{\textbf{<=}} & string   & string     & bool\\
\texttt{\textbf{\&\&}} & bool & any & any\\
\texttt{\textbf{||}}   & bool & any & any\\
\texttt{\textbf{!}}    & bool &      & bool\\
\texttt{\textbf{-}}    & number &    & number
\end{tabular}
\end{center}

Preceding \texttt{\textbf{?}} and following \texttt{\textbf{if}}, Source only allows
boolean expressions.

In array access \texttt{\textbf{arr[key]}},
only arrays are allowed as \texttt{\textbf{arr}} and
only integers are allowed as \texttt{\textbf{key}}.

Array indices in Source are limited to integers $i$ in the range $0 \le i < 2^{32} - 1$.

Pairs in Source are represented by arrays with two elements. Therefore,
\begin{lstlisting}
is_pair([1, 2]);
\end{lstlisting}
and
\begin{lstlisting}
equal(pair(1, 2), [1, 2]);
\end{lstlisting}
evaluate to \texttt{true}.

Access of an array with an array index to which no prior assignment has been
made on the array returns \texttt{undefined}.


\clearpage
\subsection{Vector Rotation}

These instructions provide bitwise rotation support for the
Vector Extension, analogous to the scalar rotation instructions\footnote{
See \url{https://github.com/AndyGlew/Ri5-stuff/wiki/VROT---Vector-Rotate}
for the initial design discussion around vector rotations.
}.

\begin{cryptoisa}
vrot.vv     vd, vs2, vs1, vm        // Vector-Vector
    vd.eew[i] = vm[i] ? rotate(EEW,vs2[i], vs1[i]) : 0
\end{cryptoisa}

\begin{figure}[h]
\lstinputlisting[language=sail,firstline=405,lastline=426]{../sail/riscv_insts_crypto_rvv_alu.sail}
\caption{
Sail specification for the vector-vector right rotate instruction.
Other variants such as vector-scalar and vector-xreg can be found in
the Sail code.
}
\label{fig:sail:vrot}
\end{figure}

The vector-vector variant splits \vrd, \vrs{1} and \vrs{2} into
EEW-bit wide elements.
If the corresponding mask bit in \vm is set,
the EEW-bit element in \vrs{2} is rotated
{\em right} by the value in \vrs{1}.
Only the low $log_2(EEW)$ bits of \vrs{1} are used as the rotation
amount; all other bits are {\em ignored}.
If the mask bit in \vm is clear, then the element of \vrd is zeroed.

\question{The zeroing v.s. leave-unmodified semantics of the vector
mask registers are an implementation option. Which should we specify?}

Vector-vector rotation is extremely important to Keccak-based algorithms
SHA3 and SHAKE.
It is also important to the ChaCha20 stream cipher.

Other forms of rotate instruction include:
vector-scalar (\texttt{.vs}),
vector-immediate (\texttt{.vi})
and
vector-xreg (\texttt{.vx}).
Presently, the vector-vector variant is the most important from a
cryptographic perspective.
We defer requiring other forms until they are required.