% Appendix

% Thomas, 2/2 -- feel free to delete this
\section{More category theory: properties of morphisms}

As we have seen, limits and colimits allow us ways to construct new objects, morphisms, and universal properties, over indexing diagrams. In particular we might be interested in relating certain properties of morphisms in a category to induced morphisms produced out of a colimit. As a motivating example, consider the following question.

\begin{question} Let $I$ be a small indexing diagram, and let $\alpha,\beta: I \to \Set$ denote two functors, and let $A_i := \alpha(i)$ and $B_i = \beta(i)$ denote the sets at each object $i\in I$. Suppose we have a natural transformation between these functors, consisting of functions $f_i \colon A_i \to B_i$ for each $i$. \textit{If each $f_i$ is injective, is it true that the induced map $f\colon \colim \alpha \to \colim \beta$ is injective as well?}
\end{question}

It turns out the answer to this diagram depends on the shape of $I$. It is true if the colimits are \textit{filtered}, which is a condition on the indexing diagram which tells us that it interacts well with finite limits. This motivates the more broad question of what properties of morphisms are preserved under limits and colimits. In general this is a hard question, but it will be important when we investigate fibrations and cofibrations in the category of topological spaces.

\subsection{Stability and closure definitions}

Let $\mathscr{C}$ be a category, not necessarily assumed to be locally small. We start with an easy definition.

\begin{definition}\label{def:closed-under-pullback} Let \textbf{P} be a property of morphisms in $\mathscr{C}$. We say that \textbf{P} is \textit{closed under composition} if, anytime we have two composable morphisms $f: x \to y$ and $g: y \to z$, if both $f$ and $g$ have property \textbf{P}, then the composite $g\circ f$ does as well.
\end{definition}

\begin{definition}\label{def:2-out-of-3} Let \textbf{P} be a property of morphisms in $\mathscr{C}$. We say that \textbf{P} \textit{satisfies 2-out-of-3} if for every commutative diagram of the form
\[ \begin{tikzcd}
    A\rar["f" above]\ar[dr,"g\circ f" below left] & B\dar["g" right]\\
     & C,\\
\end{tikzcd} \]
if any two of $f$, $g$, or $g\circ f$ have property \textbf{P}, then the third does as well.
\end{definition}

\begin{exercise} $\ $
\begin{enumerate}
    \item Prove that isomorphisms satisfy 2-out-of-3.
    \item In the category $\Set$, prove that injections and surjections do not satisfy 2-out-of-3.
\end{enumerate}
\end{exercise}

\begin{definition}\label{def:cancellative-properties} Let \textbf{P} be a property of morphisms.
\begin{enumerate}
    \item We say that \textbf{P} is a \textit{left cancellative property} if any time $g\circ f$ has property \textbf{P}, this implies that $f$ has property \textbf{P} as well.
    \item We say that \textbf{P} is a \textit{right cancellative property} if any time $g\circ f$ has property \textbf{P}, this implies that $g$ has property \textbf{P} as well.
\end{enumerate}
\end{definition}
As a warning to the reader, \textbf{the terminology in} \autoref{def:cancellative-properties} \textbf{is not standard}, although we would advocate for its usage. The notion of left cancellative properties is referred to as (CANC) in \cite[Appendix~C]{GortzWedhorn}, and has many examples in algebraic geometry (e.g. immersions, locally of finite type, purely inseparable, quasi-separated, separated). Many other examples occur under hypotheses on $g$, e.g. if it is separated or unramified. In a broader categorical context, we will see that mono-(resp. epi-)morphisms are left (resp. right) cancellative.

\begin{definition}\label{def:closed-under-retracts} Let \textbf{P} be a property of morphisms. We say that \textbf{P} is \textit{closed under retracts} if, for any $f: A \to B$ with property \textbf{P}, and any $g: X \to Y$ fitting into a commutative diagram
\[ \begin{tikzcd}
    X\ar[rr,bend left=30,"\id_X" above]\dar["g" left]\rar & A\dar["f"]\rar & X\dar["g" right]\\
    Y\rar\ar[rr,bend right=30,"\id_Y" below] & B\rar & Y,
\end{tikzcd} \]
we have that $g$ has property \textbf{P} as well.
\end{definition}

\begin{definition} Let \textbf{P} be a property of morphisms. Then we say that \textbf{P} is \textit{stable under pullback} (often also called \textit{stable under base change}) if for any pullback diagram of the form
\[ \begin{tikzcd}
    C\rar["j" above]\dar["k" left]\pb & D\dar["f" right]\\
    A\rar["g" below] & B,\\
\end{tikzcd} \]
if $f$ has property \textbf{P}, then $k$ has property \textbf{P} as well. Dually, we say that \textbf{P} is \textit{stable under pushout} if for any pushout diagram of the form
\[ \begin{tikzcd}
    C\rar["j" above]\dar["k" left] & D\dar["f" right]\\
    A\rar["g" below] & B\po,\\
\end{tikzcd} \]
if $k$ has property \textbf{P}, then $f$ has property \textbf{P} as well.
\end{definition}

\begin{exercise}\label{exer:injective-stable-under-pullback} $\ $
\begin{enumerate}
    \item Prove that isomorphisms are always stable under pushout and pullback.
    \item Prove in the category $\Set$ that injective functions are stable under pullback, and surjective functions are stable under pushout.
\end{enumerate}
\end{exercise}

Thus far we have discussed closure properties internal to a category. We might wonder how properties translate across functors.

\begin{definition}\label{def:functor-preserve-reflect-properties} Let $F: \mathscr{C} \to \mathscr{D}$ be a functor, and let \textbf{P} be a property of morphisms.
\begin{enumerate}
    \item We say that $F$ \textit{preserves property} \textbf{P} if any time $f: x \to y$ is a morphisms in $\mathscr{C}$ with property \textbf{P}, we have that $Ff: Fx \to Fy$ has property \textbf{P} as well.

    \item We say that $F$ \textit{reflects property} \textbf{P} if any tie $f:x \to y$ is a morphism in $\mathscr{C}$, if $Ff: Fx \to Fy$ has property \textbf{P}, then $f$ must necessarily have property \textbf{P} as well.
\end{enumerate}
\end{definition}

\begin{remark} We have that $F$ always preserves isomorphisms (this is part of the property of being a functor). It is \textit{not true} that $F$ needs to reflect isomorphisms. For example if $X$ is a topological space with a non-trivial topology, then the map $\id : X \to X_{\text{disc}}$ from $X$ to itself with the discrete topology is not a homeomorphism, however its underlying set map is a bijection. (That is, the forgetful functor $\Top \to \Set$ does not reflect isomorphisms).
\end{remark}

\begin{exercise} If $F$ is full and faithful, it reflects isomorphisms.
\end{exercise}

\subsection{Monomorphisms and epimorphisms}

\autoref{exer:injective-stable-under-pullback} generalizes, as the notions of being injective and surjective in $\Set$ are equivalent to more abstract categorical conditions. We begin by generalizing injections.

\begin{definition}\label{def:monomorphism} Let $\mathscr{C}$ be a category. Then a morphism $f: x \to y$ is a \textit{monomorphism} if any of the following equivalent conditions hold:
\begin{enumerate}
    \item For any pair of morphisms $g,h : z \to x$ so that $f\circ g = f\circ h$, that is:
    \begin{align*}
        z \rightrightarrows x \to y,
    \end{align*}
    we have that $g = h$. (Another way of phrasing this is that $f$ is \textit{left cancellable}).

    \item The following diagram is a pullback:
\[ \begin{tikzcd}
    x\rar["\id_x" above]\dar["\id_x" left]\pb & x\dar["f" right]\\
    x\rar["f" below] & y.
\end{tikzcd} \]

If $\mathscr{C}$ is locally small, there is another equivalent condition:
\end{enumerate}

\begin{enumerate}
\setcounter{enumi}{2}
    \item The induced functor $\Hom_\mathscr{C}(-,x) \xto{f\circ -} \Hom_\mathscr{C}(-,y)$ is a natural injection, meaning that $\Hom_\mathscr{C}(z,x) \xto{f\circ -} \Hom_\mathscr{C}(z,y)$ is an injective function for any $z\in \mathscr{C}$.
\end{enumerate}
\end{definition}

\begin{exercise} Prove that the definitions in \autoref{def:monomorphism} are equivalent.
\end{exercise}

\begin{example} We have that isomorphisms and equalizers are always monomorphisms. Any morphism from a terminal object is a monomorphism.
\end{example}

\begin{exercise} \textit{(Closure properties of monomorphisms)}
\begin{enumerate}
    \item Monomorphisms are closed under composition
    \item Monomorphisms are stable under pullback
    \item Monomorphisms are left cancellative.
\end{enumerate}
\end{exercise}

\begin{exercise}\label{exer:left-adjoints-preserve-monomorphisms} \textit{(Left adjoints preserve monomorphisms)} Let $F: \mathscr{C} \rightleftarrows \mathscr{D} : G$ be an adjunction betweem locally small categories. Then if $f: x\to y$ is a monomorphism in $\mathscr{C}$, we have that $Ff : Fx \to Fy$ is a monomorphism in $\mathscr{D}$. (Hint: use the natural bijection associated to the adjunction, together with \autoref{def:monomorphism}, Definition (iii)).
\end{exercise}

There is a dual notion, called an \textit{epimorphism}.

\begin{definition}\label{def:epimorphism} Let $\mathscr{C}$ be a category. Then a morphism $f: x \to y$ is a \textit{epimorphism} if any of the following equivalent conditions hold:
\begin{enumerate}
    \item For any pair of morphisms $g,h : y \to z$ so that $g\circ f = h\circ f$, that is:
    \begin{align*}
         x \to y \rightrightarrows z,
    \end{align*}
    we have that $g = h$. (Another way of phrasing this is that $f$ is \textit{right cancellable}).

    \item The following diagram is a pushout:
\[ \begin{tikzcd}
    x\rar["f" above]\dar["f" left] & y\dar["\id_y" right]\\
    y\rar["\id_y" below] & y\po.
\end{tikzcd} \]

If $\mathscr{C}$ is locally small, there is another equivalent condition:
\end{enumerate}

\begin{enumerate}
\setcounter{enumi}{2}
    \item The induced functor $\Hom_\mathscr{C}(y,-) \xto{-\circ f} \Hom_\mathscr{C}(x,-)$ is a natural injection, meaning that $\Hom_\mathscr{C}(y,z) \xto{-\circ f} \Hom_\mathscr{C}(x,z)$ is an injective function for any $z\in \mathscr{C}$.
\end{enumerate}
\end{definition}

Epimorphisms satisfy all the dual properties to monomorphisms.

\begin{exercise}\label{exer:properties-of-epimorphisms} \textit{(Properties of epimorphisms)}
\begin{enumerate}
    \item Every isomorphism is an epimorphism, as is every coequalizer.
    \item Any morphism to an initial object is an epimorphism.
    \item Epimorphisms are closed under composition.
    \item Epimorphisms are stable under pushout.
    \item Epimorphisms are right cancellative.
    \item Right adjoints preserve epimorphisms.
\end{enumerate}
\end{exercise}

As we have hinted at, monomorphisms and epimorphisms generalize the notions of injectivity and surjectivity in $\Set$. We can ask then whether categories which we think of as ``sets with extra data'' have the property that their monomorphisms are just those underlain by injections. Phrased differently, does the forgetful functor $U: \mathscr{C} \to \Set$ reflect mono and epimorphisms? This turns out to be true in some generality, but we must first make rigorous what it means to be a ``set with extra structure.''

\begin{definition}\label{def:concrete-category} A \textit{concrete category} is a locally small category $\mathscr{C}$, together with faithful functor to sets $U : \mathscr{C} \to \Set$. We think of this functor as ``forgetting'' the data.
\end{definition}

\begin{examples}\label{exs:concrete-categories} The following categories are concrete: $\Grp$, $\Poset$, $\Vect$, $\Top$, \todo{add more}.
\end{examples}

\begin{proposition} Any faithful functor reflects monomorphisms and epimorphisms.
\end{proposition}

Thus we see that all the categories in \autoref{exs:concrete-categories} have the property that their monomorphisms are underlying injections, and epimorphisms are underlying surjections. We summarize this in the following table.

\begin{table}[h]
    \centering
    \caption{Examples of monomorphisms and epimorphisms}
    \begin{tabular}{ p{2cm} l  p{5cm}  p{8cm} }
        \toprule
\textbf{Category}
& \textbf{Monomorphisms}
& \textbf{Epimorphisms} \\\midrule
$\Set$ & injections & surjections \\\hline

$\Grp$ & underlying injections & underlying surjections  \\\hline	 \bottomrule
    \end{tabular}
\end{table}

\begin{counterexample} We have that the inclusion $\Z \hookto \mathbb{Q}$ is an epimorphism in the category $\Ring$ of unital rings. This tells us that the forgetful functor $U: \Ring \to \Set$ is \textit{not} faithful.
\end{counterexample}

\subsection{Properties of morphisms can induce properties of objects}

Suppose we have a commutative diagram of the form
\[ \begin{tikzcd}
    A\rar["i" above]\ar[dr,"\id_A" below left] & B\dar["r" right]\\
     & A.
\end{tikzcd} \]
In this case we say the object $A$ is a \textit{retract} of $B$. We can ask about what properties of objects descend to their retracts, motivating the following definition.

\begin{definition}\label{def:property-objects-closed-under-retracts} Let \textbf{O} be a property of objects in $\mathscr{C}$ (we can just think of this as some subclass of the class of objects). Then we say that \textbf{O} is \textit{closed under retracts} if, any time $B \in \mathbf{O}$, and $A$ is a retract of $B$, we have that $A\in \mathbf{O}$ as well.
\end{definition}

We can ask about how a property of objects could potentially be related to a property of morphisms. In particular, we could ask about how properties of morphisms might induce properties of objects. Our perspective on this is stolen from algebraic geometry, in which a scheme is defined to have a property if and only if its structure morphism has the associated property. In the world of schemes and varieties, there basically don't exist properties for objects, only properties for morphisms. This is a feature of life with a terminal object. In many situations, such as topological spaces, we have the same luxury.

\begin{terminology}\label{term:inducing-properties-of-objects-from-properties-of-morphisms} Let $\mathscr{C}$ be a category with a terminal object $\ast$, and let \textbf{P} be a property of morphisms in $\mathscr{C}$. Then we have an \textit{induced property of objects} \textbf{O}, defined by saying that $X\in \mathbf{O}$ if the unique morphism $X \xto{!} \ast$ lies in \textbf{P}.
\end{terminology}

\begin{exercise} Let $\mathscr{C}$ be a category with a terminal object. Prove that if \textbf{P} is a property of morphisms closed under retracts in the sense of \autoref{def:closed-under-retracts}, then the induced property of objects is closed under retracts in the sense of \autoref{def:property-objects-closed-under-retracts}.
\end{exercise}

\begin{remark} The passage from fibrations to fibrant objects follows \autoref{term:inducing-properties-of-objects-from-properties-of-morphisms}.
\end{remark}

\subsection{Preservation properties under limits and colimits}

\begin{definition}\label{def:naturally-P} Let $I$ be an indexing category, let $\mathscr{C}$ be a category, and let \textbf{P} be a property of morphisms in $\mathscr{C}$. Let $f_1, f_2 : I \to \mathscr{C}$ be two diagrams in $\mathscr{C}$, and let $\eta: f_1 \Rightarrow f_2$ be a natural transformation between them. We say that $\eta$ \textit{has property} \textbf{P} \textit{levelwise} (or \textit{has property} \textbf{P} \textit{naturally}) if each of the components $\eta_c : f_1(c) \to f_2(c)$ has property \textbf{P}. As some examples:
\begin{enumerate}
    \item a \textit{natural isomorphism} is a natural transformation whose components are isomorphisms.
    \item a \textit{natural monomorphism} is a natural transformation whose components are monomorphisms.
\end{enumerate}
\end{definition}

\begin{definition}\label{def:colimit-preserve-property} Let $I$ be an indexing category, and let \textbf{P} be a property of morphisms in $\mathscr{C}$. We say that \textbf{P} \textit{is preserved under} $I$\textit{-shaped colimits} if, any time we have a natural transformation $\eta: f_1 \Rightarrow f_2$ which has property \textbf{P} levelwise, we have that the induced map
\begin{align*}
    \colim_I(f_1) \to \colim_I(f_2)
\end{align*}
is in \textbf{P} as well (assuming both colimits exist). Dually we have a notion of preservation under $I$-shaped limits.
\end{definition}

\begin{example} We have that isomorphisms are preserved under arbitrary limits and colimits.
\end{example}

\begin{example} If $I = \bullet\ \bullet$ is a discrete category on two points, we say that a property \textbf{P} is \textit{preserved under products} (resp. \textit{coproducts}) if it is preserved under $I$-shaped limits (resp. colimits).
\end{example}

\begin{proposition}\label{prop:monos-preserved-under-products} We have that
\begin{enumerate}
    \item Monomorphisms are preserved under products
    \item Epimorphisms are preserved under coproducts.
\end{enumerate}
\end{proposition}
\begin{proof} We will prove (1) and remark that (2) follows formally. Let $f: A \to B$ and $g: C \to D$ be monomorphisms. Then assuming their products exist, there is an induced map $(f \times g) : A \times C \to B \times D$. We claim that this is a monomorphism as well. Via \autoref{def:monomorphism}, we can restate the statement that $f$ and $g$ are monomorphisms into the statement that these diagrams are pullbacks
\[ \begin{tikzcd}
    A\rar\dar\pb & A\dar\\
    A\rar & B
\end{tikzcd} \quad\quad  \begin{tikzcd}
    C\rar\dar\pb & C\dar\\
    C\rar & D.
\end{tikzcd} \]
Since limits commute, we have that taking a product of the two pullbacks is the same as the pullback of the product of the two diagrams, that is, the following diagram is a pullback
\[ \begin{tikzcd}
    A \times C\rar["\id \times \id"]\dar["\id \times \id" left]\pb & A \times C\dar["f \times g" right]\\
    A \times C \rar["f \times g" below] & B \times D.
\end{tikzcd} \]
Thus $f \times g$ is a monomorphism.
\end{proof}

This is an instance of a more general phenomenon, namely functors preserving limits and colimits.

\begin{definition}\label{def:preserve-reflect-create-limits} Let $F:\mathscr{C} \to \mathscr{D}$ be a functor, and let $I$ be an indexing diagram.
\begin{enumerate}
    \item We say that $F$ \textit{preserves} $I$-shaped limits if, for any functor $j: I \to \mathscr{C}$, we have that the natural map is an isomorphism
    \begin{align*}
        F(\lim(j)) \cong \lim(F\circ j).
    \end{align*}
    That is, a limit cone over $j$ is sent to a limit cone over $F\circ j$.

    \item We say that $F$ \textit{reflects} $I$-shaped limits if, for any functor $j: I \to \mathscr{C}$, if we have that $F(c)$ is the limit of $F\circ j$, then $c$ is a limit of $j$. Phrased differently, a limit cone over $F\circ j$ in the image of $F$ must have come from a limit cone over $j$.

    \item We say $F$ \textit{creates} limits if it preserves and reflects them.
\end{enumerate}
We have analogous definitions for colimits.
\end{definition}

This relates to some things we have already seen: e.g. \autoref{prop:LAPC} said that left adjoints preserve colimits, and right adjoints preserve limits.

\begin{proposition}\label{prop:hom-functors-preserve-limits} Hom functors preserve limits in both arguments. That is, if $\mathscr{C}$ is a locally small category, then the bifunctor
\begin{align*}
    \Hom : \mathscr{C}^\op \times \mathscr{C} &\to \Set
\end{align*}
preserves limits in both arguments (limits in $\mathscr{C}^\op$ are colimits in $\mathscr{C}$).
\end{proposition}

\begin{corollary}\label{cor:Yoneda-embedding-preserves-limits} Let $\mathscr{C}$ be locally small. Then the Yoneda embedding $y: \mathscr{C} \hookto \Fun(\mathscr{C}^\op, \Set)$ preserves and reflects all limits.
\end{corollary}

\begin{proposition}\label{prop:fully-faithful-functor-reflects-limits-colimits} A fully faithful functor reflects all limits and colimits.
\end{proposition}

\begin{remark}\label{rmk:labelname} If $F$ is a functor preserving all limits over the diagram $I = \bullet \to \bullet \from \bullet$, we say that it \textit{preserves pullbacks}. Dually if $F$ preserves limits over the span diagram $J = \bullet \from \bullet \to \bullet$, we say it is \textit{preserves pushouts}.
\end{remark}

\begin{exercise}\label{exer:pullback-preserving-functor-preserves-monos} Let $F: \mathscr{C}\to \mathscr{D}$ be a functor.
\begin{enumerate}
    \item If $F$ preserves pullbacks, then it preserves monomorphisms.
    \item If $F$ preserves pushouts, then it preserves epimorphisms.
\end{enumerate}
\end{exercise}

Thus far we have defined two notions of preservation of properties. Namely, properties preserved under functors (as in \autoref{def:functor-preserve-reflect-properties}), and properties preserved under limits and colimits (as in \autoref{def:colimit-preserve-property}). We can see that these are both instances of the same idea.

\subsection{Colimits and limits as functors}

In order to relate these two notions of preservation, we should relate one to the other. In particular we claim that the most general notion of preservation of properties of morphisms is under a functor. In order to see that this encapsulates the other definition, we should view the construction of limits and colimits as a functor in some sense.

Let $\mathscr{C}$ be a category, and $I$ be an indexing category which we want to take limits and colimits over. Then there is a \textit{diagonal functor}
\begin{align*}
    \Delta : \mathscr{C} &\to \Fun(I, \mathscr{C}).
\end{align*}
This sends an object $c$ to the functor $\Delta_c: I \to \mathscr{C}$, where $\Delta_c(i) = c$ for all $i\in I$, and $\Delta_c(i \to i') = \id_c$. That is, $\Delta_c$ is really a constant functor at the object $c\in \mathscr{C}$. For a morphism $f:c\to c'$, we have an induced natural transformation  $\Delta_c \Rightarrow \Delta_{c'}$, all of whose components are $f$.

\begin{exercise}\label{exer:diagonal-functor-into-functor-cat-fully-faithful} Show that $\Delta$ is fully faithful.
\end{exercise}

\begin{remark} We can consider the construction of colimits as a functor
\begin{align*}
    \colim : \Fun(I, \mathscr{C}) \to \mathscr{C},
\end{align*}
sending a diagram $I \to \mathscr{C}$ to the nadir of its colimit cone. Similarly $\lim: \Fun(I, \mathscr{C}) \to \mathscr{C}$ is a functor, sending a diagram to the apex of its limit cone.
\end{remark}

\begin{proposition} We have that $\colim \dashv \Delta \dashv \lim$ are adjoint functors.
\[ \begin{tikzcd}
    \mathscr{C}\rar["\Delta"] & \Fun(I,\mathscr{C})\lar[bend right=40,"\colim" above]\lar[bend left=40,"\lim" below].
\end{tikzcd} \]
\end{proposition}
\begin{proof} Let $c\in \mathscr{C}$, and let $j: I \to \mathscr{C}$ be a diagram. Then we have that $\Hom_{\Fun(I,\mathscr{C})}(\Delta_c, j)$ are the natural transformations of diagrams from $\Delta_c \to j$. That is, it is the \textit{set of cones over $j$ with vertex $c$}. By the universal property of the limit, for any such diagram, there is a unique map $c \to \lim(j)$, that is, we have a natural transformation
\begin{align*}
    \Hom_{\Fun(I,\mathscr{C})}(\Delta_c, j) \cong \Hom_\mathscr{C}(c, \lim(j)).
\end{align*}
A dual argument works to show that $\colim \dashv \Delta$.
\end{proof}

\begin{remark}\label{rmk:colimits-in-functor-categories} Since $\colim$ is a left adjoint, it now preserves colimits by \autoref{thm:LAPC}. We can ask what a colimit in $\Fun(I,\mathscr{C})$ looks like. Suppose we have a diagram of the form
\begin{align*}
    I \to \Fun(J, \mathscr{C}).
\end{align*}
This corresponds under adjunction to a map $I \times J \to \Fun(\mathscr{C})$. We can ask whether
\begin{align*}
    \colim \left( I \to \Fun(J, \mathscr{C}) \right) \overset{?}{=} \colim \left( I \times J \to \mathscr{C} \right).
\end{align*}
If $I$ and $J$ are small indexing diagrams, and $\mathscr{C}$ has all colimits, this is certainly true {\color{blue} because Kan extensions are computed pointwise in this context --- find a better way to explain this though}.
\end{remark}

\begin{theorem}\label{thm:colimits-commute} \textit{(Colimits commute)} Let $I$ and $J$ be small indexing diagrams, and let $\mathscr{C}$ be cocomplete (or at least have all the colimits we are discussing here exist). Then for any bifunctor
\begin{align*}
    F: I \times J \to \mathscr{C}
\end{align*}
we have a canonical isomorphism
\begin{align*}
    \lim_i \lim_j F(i,j) \cong \lim_j \lim_i F(i,j).
\end{align*}
See for example \cite[3.8.1]{Riehl-context}. A dual statement is true for colimits as well.
\end{theorem}

\begin{center}
    [[todo]]
\end{center}

\subsection{Filtered limits and colimits}

In \autoref{thm:colimits-commute}, we could replace one of the limits with a colimit and ask if everything is still true. Phrased differently, if we have a functor $F: I \times J \to \mathscr{C}$, we can compare
\begin{align*}
    \colim_j \lim_i F(i,j) \text{ and } \lim_i \colim_j F(i,j).
\end{align*}
We first show that there definitely exists a map between them.

\begin{proposition}\label{prop:labelname} There is a canonical map
\begin{align*}
    \colim_j \lim_i F(i,j) \to \lim_i \colim_j F(i,j).
\end{align*}
\end{proposition}

\begin{proof} By \autoref{exer:diagonal-functor-into-functor-cat-fully-faithful}, we have that $\Delta$ is fully faithful, therefore the unit and counit maps are natural isomorphisms:
\begin{align*}
    1_{\Fun(I,\mathscr{C})} \xto{\sim} \lim \circ \Delta \\
    \colim \circ \Delta \xto{\sim}  1_\mathscr{C}.
\end{align*}
Now consider the diagram
\[ \begin{tikzcd}
    \Fun(I \times J, \mathscr{C})\rar[bend left=30,"\colim_I" above]\rar[bend right=30,"\lim_I" below] & \Fun(J, \mathscr{C})\lar["\Delta"]\rar[bend left=30,"\colim_J" above]\rar[bend right=30,"\lim_J" below] & \mathscr{C}\lar["\Delta"].\\
\end{tikzcd} \]

The composite $\colim_J \lim_I$ weaves through the middle of this diagram in a wave shape. By looping through the units of adjunctions, we have a map

Therefore we see that
\begin{align*}
    \colim_J \lim_I = 1 \colim_J \lim_I 1 \to \left( \lim_J \Delta \right)\colim_J \lim_I \left( \Delta \colim_I \right) \\
    &=
\end{align*}
For an explicit computation of this map, see \cite[3.8.3]{Riehl-context}.
\end{proof}

\begin{center}
    [[todo]]
\end{center}

\section{Unsorted subsections on category theory}

\subsection{Conventions}

We record some standard notation for use in these notes.

\begin{notation}\label{nota:initial-terminal-objects} We denote an \textit{initial object} in a category $\mathscr{C}$ by $\emptyset$. We denote a \textit{terminal object} in a category $\mathscr{C}$ by $\ast$. If $X \in \mathscr{C}$ is arbitrary, it receives a unique map from the initial object and to the terminal object. We decorate each of these with a shriek:
\begin{align*}
    \emptyset &\xto{!} X \\
    X &\xto{!} \ast.
\end{align*}
\end{notation}

\begin{notation}\label{nota:diagonal-map} Let $\mathscr{C}$ be a category, and let $X\in \mathscr{C}$ be an arbitrary object. If the product $X \times X$ exists, there is a \textit{diagonal map}, which we denote by
\begin{align*}
    X \xto{\Delta} X \times X,
\end{align*}
defined to be the unique map provided to us by the universal property of the product
\[ \begin{tikzcd}
     & X\dar\ar[ddl,bend right=10,"\id_X" left]\ar[ddr,bend left=10,"\id_X" right]\dar[dashed,"\Delta" right] & \\
     & X \times X\ar[dl,"\pr_1" below right]\ar[dr,"\pr_2" below left] & \\
    X &  & X.
\end{tikzcd} \]
\end{notation}
\begin{notation}\label{nota:fold-map} Let $\mathscr{C}$ be a category, and let $X\in \mathscr{C}$ be an arbitrary object. If the coproduct $X \amalg X$, there is a \textit{fold map}, which we denote by
\begin{align*}
    X \amalg X \xto{\nabla} X,
\end{align*}
defined to be the unique map provided to us by the universal property of the coproduct
\[ \begin{tikzcd}
    X\ar[dr,"i_1" above right]\ar[ddr,bend right=10,"\id_X" left] &  & X\ar[dl,"i_2" above left]\ar[ddl,bend left=10,"\id_X" right]\\
     & X \amalg X\dar[dashed,"\nabla" right]& \\
     & X. & \\
\end{tikzcd} \]
\end{notation}

The terminology for the \textit{diagonal} map comes from the world of sets (or concrete categories more generally), where the function $\Delta: X \to X \times X$ is defined elementwise by $x \mapsto (x,x)$. That is, its image is the diagonal in the product. The \textit{fold} map comes from the mental image of taking two disjoint copies of $X$ and folding them over one another into one copy of $X$.

\begin{notation}\label{nota:product-coproduct-of-morphisms} Let $\mathscr{C}$ be a category with products, and let $f: A \to B$ and $g: C \to D$ be two morphisms. Then we denote by
\begin{align*}
    f \times g : A \times C \to B \times D
\end{align*}
the morphism given via the universal property
\[ \begin{tikzcd}
     & A \times B\ar[dl]\ar[dr]\dar[dashed,"f \times g"] & \\
    A\dar["f" left] & C \times D\ar[dl]\ar[dr] & B\dar["g" right]\\
    C &  & D.
\end{tikzcd} \]
Similarly if $\mathscr{C}$ is a category with coproducts, we denote by
\begin{align*}
    f \amalg g : A \amalg C \to B \amalg D
\end{align*}
the morphism provided by the universal property
\[ \begin{tikzcd}
    A\ar[dr]\dar["f" left] &  & B\ar[dl]\dar["g" right]\\
    C\ar[dr] & A\amalg B\dar[dashed,"f \amalg g"] & D\ar[dl]\\
     & C \amalg D. &
\end{tikzcd} \]

\end{notation}

\subsection{Laws for pullbacks and pushouts}

Frequently we will be asked to glue together commutative squares and talk about whether the composite square is a pullback and/or whether the individual squares are pullbacks. This is discussed in the so-called \textit{pasting law}.

\begin{proposition}\label{prop:pasting-law-pullbacks-pushouts} \textit{(Pasting law for pullbacks and pushouts)} Let $\mathscr{C}$ be an arbitrary category, and consider a commutative diagram of the following form
\[ \begin{tikzcd}
    \bullet\rar\dar & \bullet\rar\dar & \bullet\dar\\
    \bullet\rar & \bullet\rar & \bullet.
\end{tikzcd} \]
\begin{enumerate}
    \item If the right square is a pullback, then the total square is a pullback if and only if the left square is a pullback.
    \item If the left square is a pushout, then the total square is a pushout if and only if the right square is a pushout.
\end{enumerate}
\end{proposition}

We also have the ``magic square,'' which is generally stated for varieties or schemes, but holds in a more broad context.

\begin{proposition}\label{prop:magic-pullback-square} \textit{(Magic pullback square)} Let $\mathscr{C}$ be a locally small category with products and pullbacks. Let $f: X \to Z$, and $g: Y \to Z$ be morphisms in $\mathscr{C}$. Then the following square is a pullback
\[ \begin{tikzcd}
    X \times_Y Z\rar\dar\pb & X \times Y\dar["f \times g" right]\\
    Z\rar["\Delta" below] & Z \times Z.
\end{tikzcd} \]
\end{proposition}
\begin{proof} We first check that this holds if $\mathscr{C} = \Set$. This is certainly true, since elements of $(X \times Y)\times_{Z \times Z} Z$ are precisely elements $(x,y) \in X \times Y$ so that $f(x) = g(y)$. Then for any locally small category $\mathscr{C}$, we have that this diagram is a levelwise pullback in $\Fun \left( \mathscr{C}^\op, \Set \right)$. Finally we remark that under the Yoneda embedding $y : \mathscr{C} \hookto \Fun(\mathscr{C}^\op, \Set)$, limits are reflected.
\end{proof}

The magic pullback square is generally stated in the following form.

\begin{corollary}\label{cor:magic-square-over-S} Let $\mathscr{C}$ be a locally small category, and $S\in \mathscr{C}$ be any element. Then if $f: X \to Z$ and $g : Y \to Z$ are morphisms over $S$, we have a pullback square
\[ \begin{tikzcd}
    X \times_Y Z\rar\dar\pb & X \times_S Y\dar["f \times g"]\\
    Z\rar["\Delta" below] & Z \times_S Z.
\end{tikzcd} \]
\end{corollary}

\section{Homotopy colimits}

Here we explore instances in which homotopy (co)limits appear in the basic curriculum of algebraic topology, namely in \cite{Hatcher} and \cite{May}. A rigorous treatment of homotopy colimits is not provided here, we defer to the far better expositors Dugger and Riehl for their expositions of simplicial and categorical understandings of homotopy colimits \cite{Dugger,Riehl-hocolims}. We would posit that homotopy colimits are an intuitive concept to grasp and work with, and that recognizing them as they occur in basic algebraic topology provides the reader with another tool to grasp the material.

\subsection{Intro to homotopy colimits}

As described above, we neglect to provide a rigorous definition of homotopy colimits, as the rigorous definitions ($\hocolim$ is the derived functor of $\colim$; homotopy colimits are the geometric realization of the simplicial replacement) are technical to state. Instead, we provide the following characterization of homotopy colimits, based on an intuitive understanding of colimits:
\begin{center}
    Colimits are obtained by gluing spaces.\\
    \textit{Homotopy colimits} are obtained by gluing spaces \textit{with wiggle room, in a continuous fashion}.
\end{center}

What do we mean by this? Say we want to glue two spaces $X$ and $Y$ together along distinguished basepoints to form a wedge product $X \vee Y$. How do we do this in general? We take the disjoint union $X \amalg Y$ and mod out by the equivalence relation $x_0 \sim y_0$. Phrased differently, we glue $x_0$ and $y_0$ together to force them to become the same point in the quotient space.

Instead of gluing them directly together, we could instead draw a path connecting $x_0$ and $y_0$. Now instead of formally identifying the two points, we provide them a path by which one can travel to the other.

\begin{figure}[H]
  \scalebox{0.2}{\includegraphics{pics/whisker-gluing.png}}
  \centering
\end{figure}

\begin{example} As another example, suppose $\ast \hookto X$ is the inclusion of a point $x\in X$. Taking the cofiber of this map\footnote{Recall the cofiber of a map $f: X \to Y$ is the colimit $\colim \left( \ast \from X \xto{f} Y \right)$.} is the same as simply gluing the point $\ast$ to $x\in X$, and you simply end up with the space $X$. If, instead, you wanted to take the \textit{homotopy cofiber} of this map, you would end up with the space $X$, with a small whisker protruding from the point $x$, ending at the point $\ast$. This procedure has a name, and it is actually called \textit{whiskering}. For example if $(X,x)$ is a based space which is not well based\footnote{Recall a space is \textit{well-based/non-degenerately based} if the inclusion of the basepoint is a cofibraion.}, we can take the based space $(\hocolim(\ast \hookto X),\ast)$, which becomes well-based.
\end{example}

\begin{figure}[H]
  \scalebox{0.2}{\includegraphics{pics/whisker.png}}
  \centering
\end{figure}

\begin{example} Consider the map $S^1 \to \ast$ collapsing the sphere to a point. The cofiber of this map is $\ast$, that is, a one-point space. However to form the homotopy cofiber, we must draw a path from each point on $S^1$ to the point $\ast$. Here is where we sweep some more rigor under the rug, and illustrate what we mean by ``in a continuous fashion'' in our characterization of homotopy colimits. When creating our paths from points on $S^1$ to $\ast$, a small change in the choice of point on the circle $S^1$ should correspond to a small change in the path drawn. We shouldn't think of these paths as a loose collection of uncountably many strings, flying everywhere and connecting each point on $S^1$ to $\ast$. Instead, nearby strings should coagulate to form surfaces.

\begin{figure}[H]
  \scalebox{0.2}{\includegraphics{pics/cone.png}}
  \centering
\end{figure}

If you've followed this rough description, then it would make sense to you that the homotopy cofiber of the map $S^1 \to \ast$ becomes a hollow cone over $S^1$, whose vertex is the point $\ast$. If, on the other hand, this lack of rigor has disgusted you, then the authors understand wholeheartedly and invite you to read \cite{Dugger}.
\end{example}

In the previous examples, the resulting space obtained by taking a homotopy colimit was weakly homotopy equivalent to the original one obtained by taking a colimit. We can ask whether this will always be the case, which the following example (a rephrased version of Example 2.1 in \cite{Dugger}) illustrates.

\begin{example} Consider the diagram $\ast \from S^1 \to \ast$. Its colimit is the pushout $\ast \amalg_{S^1} \ast \cong \ast$, which is just a one-point space. On the other hand, its homotopy colimit can be constructed via the previous example. By gluing $S^1$ to each point $\ast$, we obtain two hollow cones which are identified together along their bases. That is, we obtain a 2-sphere $S^2$. Note that $S^2 \not \simeq \ast$!
\end{example}

This is an example of a general phenomena; for a diagram $D: I \to \Top$, it is often the case that $\colim(D) \not\simeq \hocolim(D)$.

\begin{remark} In the previous section we have said that a homotopy colimit ``is'' a certain space. The reader should be advised that homotopy colimits are only defined up to weak equivalence. This turns out to be both a blessing and a curse, in that we fail to obtain a well-defined construction in the topological category, however the ambiguity allows homotopy colimits to satisfy a property that colimits fail to satisfy: \textit{homotopy invariance.} We will make this precise.
\end{remark}

\subsection{Homotopy Invariance}

\begin{definition} A \textit{weak homotopy equivalence of diagrams} is a natural transformation $D \Rightarrow D'$ (occasionally denoted $D \simeq D'$) between two diagrams $D,D' : I \to \Top$ whose components are weak homotopy equivalences.
\end{definition}

\begin{example}\label{ex:we-of-diagrams} Let our index category be $I = \bullet \from \bullet \to \bullet$, and let $D(I) = \left(D^{n+1} \hookfrom S^n \hookto D^{n+1}\right)$, and $D'(I) = \left(\ast \from S^n \to \ast \right)$. Then there is a weak homotopy equivalence of diagrams $D \Rightarrow D'$ whose components are the identity map on $S^n$ and the contraction $D^{n+1} \xto{\sim} \ast$ on the disks.
\end{example}

\begin{remark} Colimits fail to satisfy \textit{homotopy invariance}. That is, for a weak homotopy equivalence of diagrams $D\simeq D'$, we may have that $\colim(D) \not\simeq \colim(D')$.
\end{remark}

\begin{exercise} See in Example \ref{ex:we-of-diagrams} that $\colim(D) = S^{n+1}$ but $\colim(D') = \ast$.
\end{exercise}

\begin{theorem} Homotopy colimits satisfy homotopy invariance. That is, for $D\simeq D'$, one always has that
\begin{align*}
    \hocolim(D) \simeq \hocolim(D').
\end{align*}
\end{theorem}

\begin{corollary} Given any diagram, we may replace maps and objects in the diagram by weakly equivalent ones and obtain the same homotopy colimit.
\end{corollary}

\subsection{Homotopy colimits coinciding with colimits}

There are many deep questions to ask about homotopy colimits, but perhaps the first one that we might be curious about is when homotopy colimits and colimits coincide. This question is non-trivial to answer, and as always we defer to \cite{Dugger} for a full treatment. However we will give one example, which is a stronger condition on a diagram than one needs in general, but will suit our examples:

\begin{proposition} If a diagram $D: I \to \Top$ has the property that all of its maps are cofibrations, then $\colim(D) \simeq \hocolim(D)$.
\end{proposition}

In particular, if the maps are inclusions of subspaces which form a relative CW complex, they are cofibrations.

This fact, combined with homotopy invariance of homotopy colimits, will allow us to provide a characterization of a lot of phenomena occurring in algebraic topology in terms of homotopy colimits.

\begin{example} We have that $\Sigma X = \hocolim(\ast \from X \to \ast)$.
\end{example}
\begin{proof} Let $CX$ denote the cone over $X$, and note that $CX \simeq \ast$ is contractible. Then since the inclusion $X \hookto CX$ is a relative CW complex, one has
\begin{align*}
    \Sigma X &= \colim \left( \begin{tikzcd}[ampersand replacement=\&] X\rar[hook]\dar[hook] \& CX \\ CX \& \end{tikzcd} \right) = \hocolim \left( \begin{tikzcd}[ampersand replacement=\&] X\rar[hook]\dar[hook] \& CX \\ CX \& \end{tikzcd} \right) \\
    &=\hocolim \left( \begin{tikzcd}[ampersand replacement=\&] X\rar[hook]\dar[hook] \& \ast \\ \ast \& \end{tikzcd} \right).
\end{align*}
\end{proof}

\begin{example} Let $\phi: S^n \to X_n$ be the attaching map for an $(n+1)$-cell, and let $X_{n+1}$ be the space obtained by attaching this cell. Then
\begin{align*}
    X_{n+1} = \hocofib\left(S^n \xto{\phi} X_n\right).
\end{align*}
\end{example}
\begin{proof} Again we apply the previous proposition and homotopy invariance of homotopy colimits. We have that
\begin{align*}
    X_{n+1} &= \colim \left( \begin{tikzcd}[ampersand replacement=\&] S^n\rar[hook,"\phi" above]\dar[hook] \& X_n \\ D^{n+1} \& \end{tikzcd} \right) = \hocolim \left( \begin{tikzcd}[ampersand replacement=\&] S^n\rar[hook,"\phi" above]\dar[hook] \& X_n \\ D^{n+1} \& \end{tikzcd} \right) \\
    &=\hocolim \left( \begin{tikzcd}[ampersand replacement=\&] S^n\rar[hook,"\phi" above]\dar[hook] \& X_n \\ \ast \& \end{tikzcd} \right) = \hocofib(\phi).
\end{align*}
\end{proof}

\begin{example} For a map $f: X\to Y$, the \textit{mapping cylinder}, defined on \cite[p.2]{hatcher} may be thought of as $M_f = \hocolim(X \xto{f} Y)$.
\end{example}

\begin{example} For a map $f: X\to Y$ \textit{mapping cone} $C_f$, defined on \cite[p.13]{hatcher}, is the homotopy cofiber of the map $f$:
\begin{align*}
    C_f = \hocofib(f).
\end{align*}
\end{example}

\begin{example} The \textit{join} of two spaces $X$ and $Y$, defined on \cite[p.9]{hatcher}, is the homotopy pushout $\hocolim(X \from X\times Y \to Y)$.
\end{example}

\begin{example} As a generalization of the previous example, the \textit{double mapping cylinder}, defined on \cite[p.80]{may}, is the homotopy pushout $\hocolim( A \from X \to B)$.
\end{example}

\begin{example} The \textit{mapping telescope}, defined on \cite[p.138]{hatcher}, is the homotopy colimit
\begin{align*}
    \hocolim\left(X_0 \xto{f_0} X_1 \xto{f_1} \cdots \right).
\end{align*}

\end{example}

\begin{theorem} \cite[Theorem~24.9]{chacholski} Homotopy colimits commute.
\end{theorem}

\begin{corollary} On \cite[p.57]{may}, a critical aspect of the cofiber sequence generated by a map $f$ is that there is a weak equivalence (really a homeomorphism) $\Sigma C_f \simeq C(\Sigma f)$. This can be easily remembered by the fact that homotopy colimits commute.
\end{corollary}


\chapter{Matrices}
\section{Properties}
\subsection{Dimension}
The dimension
\footnote{Not to be confused with the dimenson of a vector space, see \ref{dimension}} is the number of rows \(a\) and columns \(b\) of a Matrix \(A\)
\begin{equation}
    \dim{A} = a \times b
\end{equation}
Denoted as:
\begin{align*}
    A^{a \times b}
\end{align*}
\begin{example}
    \begin{equation*}
        \dim{\begin{bmatrix}
                1 & 2 & 3 \\
                4 & 5 & 6
            \end{bmatrix}} = 2 \times 3
    \end{equation*}
\end{example}
\begin{example}[Linearly dependent rows/columns]
    \begin{equation*}
        \dim{\begin{bmatrix}
                1 & 2 \\
                2 & 4
            \end{bmatrix}}= 2 \times 2
    \end{equation*}
\end{example}
\begin{matlab}
    \apilink{size}{https://www.mathworks.com/help/matlab/ref/size.html}
    \begin{lstlisting}
    A = [[1,2,3],[1,2,3]]
    size(A)
    ans 2 3
    \end{lstlisting}
\end{matlab}
\subsection{Rank (Rang)} \label{rank}
\subsubsection{Rowsapce, columnspace}
The rowspace \( C \) of a matrix ist the span of its column vectors. \\
The definied as is the span of its row vectors. It is dentoed as \( C(A^T) \)\\
The dimension of the column and rowspace are always equal.
\begin{example}
    \begin{align*}
        A         & = \begin{bmatrix}
            1 & 2 & 4 \\ 1 & 2 & 4
        \end{bmatrix}      \\
        C(A)      & = \setb{
        \begin{bmatrix}
                c \\ c
            \end{bmatrix}}{c \in \mathbb{R}} \\
        C(A^T)    & = \setb{
        \begin{bmatrix}
                c \\ 2c \\ 4c
            \end{bmatrix}}{c \in \mathbb{R}} \\
        \dim C(A) & = \dim C(A^T) = 1                \\
    \end{align*}
\end{example}
\subsubsection{Rank}
The rank of a matrix \(A\) is the maximal number of linearly independent columns
(or the number of linearly independent rows, is the same thing). Or equally, the rank
of a matrix A is the dimenson of its columnspace (or rowspace):
\begin{equation}
    \rank A = \dim C(A) = \dim C(A^T)
\end{equation}
\begin{example}
    \begin{equation*}
        \rank \begin{bmatrix}
            1 & 2 & 3 \\
            4 & 5 & 6
        \end{bmatrix} = 2
    \end{equation*}
\end{example}
\begin{example}[Both rows are linearly dependent]
    \begin{equation*}
        \rank \begin{bmatrix}
            1 & 2 & 3 \\
            2 & 4 & 6
        \end{bmatrix}  = 1 \\
    \end{equation*}
\end{example}
\begin{example}[Only a matrix containing zeroes has a rank of 0]
    \begin{equation*}
        \rank \begin{bmatrix}
            0 & 0 & 0 \\
            0 & 0 & 0
        \end{bmatrix} = 0
    \end{equation*}
\end{example}
\begin{example}
    Both columns are linearly independent, some rows are linearly dependent.
    \begin{equation*}
        \rank \begin{bmatrix}
            1 & 2 \\ 2 & 4 \\ 5 & 7
        \end{bmatrix} = 2
    \end{equation*}
\end{example}
\begin{matlab}
    \apilink{rank}{https://www.mathworks.com/help/matlab/ref/rank.html}
    \begin{lstlisting}
    A = [[1,2,3],[1,2,3]]
    rank(A)
    ans = 1
    \end{lstlisting}
\end{matlab}
\subsection{Trace (Spur)}
The trace of a square matrix \( A \) is the sum of all its main diagonal elements.
\begin{equation}
    tr(A) = \sum_{i=0}^{n} a_{ii}
\end{equation}

\begin{example}
    \begin{align*}
        A     & = \begin{bmatrix}
            1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9
        \end{bmatrix} \\
        tr(A) & = 1 + 5 + 9 = 15
    \end{align*}
\end{example}

\begin{matlab}
    \apilink{trace}{https://www.mathworks.com/help/matlab/ref/double.trace.html}
    \begin{lstlisting}
>> A = [1,2,3;4,5,6;7,8,9]
>> trace(A)
ans =
15
\end{lstlisting}
\end{matlab}
\subsection{Minor, Cofactors}\label{minor}
\subsubsection{Submatrix}
A submatrix \(S_ij\) of a Matrix \(A\) is the Matrix obtained by deleting the \(i\)th Row and deleting the \(j\)th column.
\begin{example}
    \begin{align*}
        A      & = \begin{bmatrix}
            1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9
        \end{bmatrix} \\
        S_{12} & = \begin{bmatrix}
            4 & 6 \\ 7 & 9
        \end{bmatrix}
    \end{align*}
\end{example}
\subsubsection{Minor}
A minor \(M_{ij}\) of a matrix \(A\) is the determinant of the submatrix \(S_{ij}\).
\subsubsection{Cofactors}
A cofactor \( C_{ij} \) is obtained by multiplying the minor \( M_{ij} \) by \( (-1)^{i + j} \). The cofactor Matrix \(C \) is given by:
\begin{equation}
    C = \begin{bmatrix}
        C_{11} & C_{12} & \dots  & C_{1i} \\
        C_{21} & C_{22} & \dots  & C_{1i} \\
        \vdots & \vdots & \ddots          \\
        C_{j1} & C_{j2} &        & C_{ij} \\
    \end{bmatrix} =  \begin{bmatrix}
        M_{11}            & -M_{12}             & \dots  & (-1)^{i + 1}M_{1i}  \\
        -M_{21}           & M_{22}              & \dots  & (-1)^{i + 2} M_{2i} \\
        \vdots            & \vdots              & \ddots                       \\
        (-1)^{1+ j}M_{j1} & (-1)^{2 + j} M_{j2} &        & (-1)^{i + j} M_{ij} \\
    \end{bmatrix}
\end{equation}
\begin{example}\label{minor_example}
    \begin{align*}
        A = \begin{bmatrix}
            1 & 2 & 3 \\
            4 & 5 & 6 \\
            7 & 8 & 9 \\
        \end{bmatrix} \\
    \end{align*}
    \begin{align*}
        M_{11} & = det(\begin{bmatrix}
            5 & 6 \\
            8 & 9 \\
        \end{bmatrix}) = -3  &
        M_{12} & = det(\begin{bmatrix}
            4 & 6 \\
            7 & 9 \\
        \end{bmatrix}) = -6  &
        M_{13} & = det(\begin{bmatrix}
            4 & 5 \\
            7 & 8 \\
        \end{bmatrix}) = -3    \\
        M_{21} & = det(\begin{bmatrix}
            2 & 3 \\
            8 & 9 \\
        \end{bmatrix}) = -6  &
        M_{22} & = det(\begin{bmatrix}
            1 & 3 \\
            7 & 9 \\
        \end{bmatrix}) = -12 &
        M_{23} & = det(\begin{bmatrix}
            1 & 2 \\
            7 & 8 \\
        \end{bmatrix}) = -6    \\
        M_{31} & = det(\begin{bmatrix}
            2 & 3 \\
            5 & 6 \\
        \end{bmatrix}) = -3  &
        M_{32} & = det(\begin{bmatrix}
            1 & 4 \\
            3 & 6 \\
        \end{bmatrix}) = -6  &
        M_{33} & = det(\begin{bmatrix}
            1 & 2 \\
            4 & 5 \\
        \end{bmatrix}) = -3
    \end{align*}
    \begin{equation*}
        C = \begin{bmatrix}
            M_{11}  & -M_{12} & M_{13}  \\
            -M_{21} & M_{22}  & -M_{23} \\
            M_{31}  & -M_{32} & M_{33}  \\
        \end{bmatrix} = \begin{bmatrix}
            -3 & 6   & -3 \\
            6  & -12 & 6  \\
            -3 & 6   & -3 \\
        \end{bmatrix}
    \end{equation*}
\end{example}
\begin{example}
    \begin{equation*}
        A = \begin{bmatrix}
            1 & 2 \\ 3 & 4
        \end{bmatrix}
    \end{equation*}
    \begin{align*}
        M_{11} & = 4 & M_{12} & = 3 \\
        M_{21} & = 2 & M_{22} & = 1
    \end{align*}
    \begin{equation*}
        C = \begin{bmatrix}
            M_{11}  & -M_{12} \\
            -M_{21} & M_22
        \end{bmatrix} = \begin{bmatrix}
            4 & -3 \\ -2 & 1
        \end{bmatrix}
    \end{equation*}
\end{example}
\subsection{Determinant}
\subsubsection{2x2 Matrix}
For 2x2 Matrix the formula is as given:
\begin{align*}
    \determinant{\begin{bmatrix}
            x_1, x_2 \\
            x_3, x_4 \\
        \end{bmatrix}} = x_1 \cdot x_4 - x_2 \cdot x_4
\end{align*}
\begin{example}
    \begin{align*}
        \determinant{
            \begin{bmatrix}
                3 & 7 \\ -5 & 11
            \end{bmatrix}
        } = 3 \cdot 11 - 7 \cdot (-5) = 68
    \end{align*}
\end{example}
\subsubsection{3x3 Matrix}
The determinant of a 3x3 Matrix can be calculated using its minors.
\begin{align*}
    \determinant{\begin{bmatrix}
            x_1 & x_2 & x_3  \\
            x_4 & x_5 & x_6  \\
            x_7 & x_8 & x_9) \\
        \end{bmatrix}} & = x_1 \cdot
    \determinant{\begin{bmatrix}
            x_5 & x_6 \\
            x_8 & x_9 \\
        \end{bmatrix}}- x_2 \cdot
    \determinant{\begin{bmatrix}
            x_4 & x_6 \\
            x_7 & x_9 \\
        \end{bmatrix}}+ x_3 \cdot \determinant{\begin{bmatrix}
            x_4 & x_5 \\
            x_7 & x_8 \\
        \end{bmatrix}}                                   \\
                                             & = x_1 (x_5x_9 - x_6 x_8) - x_2 (x_4 x_9 - x_6 x_7) + x_3 (x_4 x_8 - x_5 x_7)        \\
                                             & = x_1 x_5 x_9 + x_2 x_6 x_7 + x_3 x_4 x_8 - x_3 x_5 x_7 - x_2 x_4 x_9 - x_1 x_6 x_8
\end{align*}
For higher order matrices you can apply this method recursively.
\begin{example}
    Minors were calculated in previous example.
    \begin{align*}
        \determinant{\begin{bmatrix}
                1 & 2 & 3 \\
                4 & 5 & 6 \\
                7 & 8 & 9 \\
            \end{bmatrix}} & = 1 \cdot(-3) - 2 \cdot(-6) + 3 \cdot(-3) = 0 \\
    \end{align*}
\end{example}
\subsubsection{Triangular matrx}
\begin{align*}
    D = \begin{bmatrix}
        x_{11} & x_{12} & \cdots & x_{1n} \\
        0      & x_{22} &        &        \\
        \vdots &        & \ddots          \\
        0      & 0      & \cdots & x_{nn} \\
    \end{bmatrix} \det(D) & = x_{11} \cdot x_{22} \dots x_{nn} = \prod_{i=1}^n x_{}
\end{align*}
\subsubsection{Singular matrix}
Singular matrices are matrices with \( \det = 0 \).
Singular matrices have rows and/or columns that are not linearly independent.
\begin{example}
    \begin{align*}
        A               & = \begin{bmatrix}
            1 & 2 \\ -2 & -4
        \end{bmatrix}      \\
        \determinant{A} & = 1 \cdot (-4) - (-2) \cdot 2 = 0
    \end{align*}
\end{example}
\begin{matlab}
    \apilink{det}{https://www.mathworks.com/help/matlab/ref/det.html}
    \begin{lstlisting}
>> a =[[3,7];[4,12]]
>> det(a)
ans = 8
\end{lstlisting}
\end{matlab}
\subsection{Eigenvalues, Eigenvectors}\label{eigen}
An eigenvector \( v \) of a square matrix \(A\) is a nonzero vector that changes at most by a scalar factor when that linear transformation is applied to it. The corresponding eigenvalue $\lambda$ is the factor by which the eigenvector is scaled.
\begin{equation} \label{eigenexpression}
    A\cdot v = \lambda \cdot v
\end{equation}
\begin{example}
    \begin{align*}
        A         & = \begin{bmatrix}
            5 & 1 \\ 0 & 3
        \end{bmatrix}                                                               \\
        v         & = \begin{bmatrix}
            1 \\ 0
        \end{bmatrix}, \lambda = 5                                                  \\
        A \cdot v & = \begin{bmatrix}
            5 & 1 \\ 0 & 3
        \end{bmatrix} \cdot \begin{bmatrix}
            1 \\ 0
        \end{bmatrix} = \begin{bmatrix}
            5 \\ 0
        \end{bmatrix}
    \end{align*}
\end{example}
\subsubsection{Characteristic polynomial}
The expression \ref{eigenexpression} can be written as:
\begin{align}
    A\cdot v = \lambda \cdot I \cdot v \tag*{Multiplying with identity Matrix} \\
    A \cdot v - \lambda \cdot I \cdot v = 0                                    \\
    v \cdot (A - \lambda \cdot I) = 0
\end{align}
Since \(v\) per definition can't be the zero vector, the expression \( (A - \lambda \cdot I) \) must be zero.
\begin{align*}
    A - \lambda \cdot I = 0                 \\
    \determinant{ A - \lambda \cdot I } = 0 \\
    \determinant{
        \begin{bmatrix}
            a_{11} - \lambda & a_{12}           & \cdots & a_{1n}           \\
            a_{12}           & a_{22} - \lambda &        &                  \\
            \vdots           &                  & \ddots &                  \\
            a_{n1}           &                  &        & a_{nn} - \lambda
        \end{bmatrix}
    } & = 0
\end{align*}
The characteristic polynomial \( P_{A}\) of a matrix \(A\) is defined as:
\begin{equation}
    P_A(t) = \determinant{A - t I}
\end{equation}
If a square matrix A with \( \dim(A) = n \times n \) then \(p_A(t)\) will have a degree of \(n\). The characteristic polynomial is always monic (the leading coefficient is 1)
\begin{example}\label{eigenexample}
    \begin{align*}
        A      & = \begin{bmatrix}
            5 & 7 \\ 11 & 3
        \end{bmatrix}                                                                    \\
        p_A(t) & = \determinant{\begin{bmatrix}
                5 - t & 7 \\ 11 & 3 -t
            \end{bmatrix}} = (5 - t) \cdot (3 - t) - 7 \cdot 11 = t^2 - 8t - 62
    \end{align*}
    Note for a \(2 \times 2 \) matrix \( p_A(t) \) is always:
    \begin{equation}
        p_A(t) = t^2 - \trace(A) t - \determinant{A}
    \end{equation}
\end{example}
\begin{matlab}
    \apilink{charpoly}{https://www.mathworks.com/help/symbolic/sym.charpoly.html}
    \begin{lstlisting}
    >> charpoly([5, 7 ; 11, 3])
    ans =
         1    -8   -62
   \end{lstlisting}
\end{matlab}
If  A gets pluged into \(p_A(t)\) then the result will be the zero-matrix.
\begin{equation}
    P_a(A) = A^n + b_2 A^{n-1} \cdots b_{n-1} A + b_n I = 0 \\
\end{equation}
\begin{example}
    From previous example.
    \begin{gather*}
        p_A(t) = t^2 - 8t - 62 \\
        p_A(A) =  \begin{bmatrix}
            5 & 7 \\ 11 & 3
        \end{bmatrix}^2  - \begin{bmatrix}
            5 & 7 \\ 11 & 3
        \end{bmatrix} - 62 I \\
        = \begin{bmatrix}
            102 & 56 \\ 88 & 86
        \end{bmatrix} - \begin{bmatrix}
            40 & 56 \\ 88 & 24
        \end{bmatrix} - \begin{bmatrix}
            62 & 0 \\ 0 & 62
        \end{bmatrix} = \begin{bmatrix}
            0 & 0 \\ 0 & 0
        \end{bmatrix}
    \end{gather*}
\end{example}
\subsubsection{Characteristic equation}
The roots of the characteristic polynomial are the eigenvalues \(\lambda_i \) of \(A\). The expression
\begin{equation}
    p_A(t) = 0\\
\end{equation}
is called the characteristic equation. The characteristic polynomial can be written as:
\begin{equation}
    p_A(t) = (t - \lambda_1)(t - \lambda_2) \cdots (t - \lambda_i)
\end{equation}
\begin{example}\label{eigenexampld}
    \begin{align*}
        A      & = \begin{bmatrix}
            3 & 7 \\ 2 & 5
        \end{bmatrix}                                                 \\                                                                                \\
        p_A(t) & = \det(A - t I)  = \determinant{\begin{bmatrix}
                3 - t & 7 \\2  & 5 - t
            \end{bmatrix}} =  t^2 - 8 t + 1 \\
    \end{align*}
    We get the eigenvalues by setting \(p_A(\lambda) = 0\) and solving for \( \lambda \)
    \begin{align*}
        \lambda^2 - 8 \lambda + 1 = 0                                           \\
        \lambda_{12} = -\frac{-8}{2} \pm \sqrt{\left( \frac{-8}{2}\right)^2 -1} \\
        \lambda_1 = 4 - \sqrt{15},  \lambda_2 = 4 + \sqrt{15}                   \\
    \end{align*}
\end{example}
\subsubsection{Arithmetic Multiplity}
A matrix can have multiple eigenvalues $\lambda_i$ with the same value.
The characteristic polynomial can be written as:
\begin{align*}
    p_A(t) = (t-\lambda_1)(t-\lambda_2) \dots (t-\lambda_n)
\end{align*}
The arithmetic Multiplicity $\mu_A(\lambda_1)$ is the number of times $(t - \lambda_i)$ can divide $p_A(t)$,
so the highest power $(t - \lambda_i)$ can have (simply said the number of times a value appears).
\begin{example}
    \begin{align*}
        A = \begin{bmatrix}
            1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
            0 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 3 & 0 & 0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 3 & 0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 3 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 & 4 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 & 0 & 4 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 & 0 & 0 & 4 & 0 \\
            0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 4 \\
        \end{bmatrix}
    \end{align*}
    A has 4 eigenvalues: 1, 2, 3, 4($=\lambda_{1..10})$\\
    The characteristic polynomial can be expressed by using only distinct eigenvalues:
    \begin{align*}
        p_A(t) = (t -1)(t-2)^2(t-3)^3(t-4)^4
    \end{align*}
\end{example}
For example $\mu_A(\lambda_4) = 4$, because $(t - 4)$ divides $p_A(t)$ 4 times.
\subsubsection{Eigenvectors, eigenspace}
To find the eigenvector of an associatited eigenvalue we need to find the kernel of the following linear map:
\begin{align*}
    L:  (A - \lambda_i \cdot I) x = y \\
    \epsilon_i = \ker L
\end{align*}
Since the kernel of a tranformation forms a vectorspace  \( \epsilon \) called \textbf{eigenspace}. So following properites are satisfied:
\begin{align*}
    v_1, v_2 \in \epsilon_i, c \in \mathbb{F} \\
    v_1 + v_2 \in \epsilon_i                  \\
    c \cdot v_1 \in \epsilon_i                \\
\end{align*}
\begin{example}
    Continuing  example \ref{eigenexample}.
    \begin{align*}
        A & = \begin{bmatrix}
            3 & 7 \\ 2 & 5
        \end{bmatrix}                      \\                                                                                \\
        \lambda_1 = 4 - \sqrt{15},  \lambda_2 = 4 + \sqrt{15} \\
    \end{align*}
    \(\lambda_1\):
    \begin{align*}
        \begin{bmatrix}
            3 - (4 - \sqrt{15}) & 7 \\ 2 & 5 - ( 4 - \sqrt{15})
        \end{bmatrix}
        \begin{bmatrix}
            x_1 \\ x_2
        \end{bmatrix}= \begin{bmatrix}
            0 \\ 0
        \end{bmatrix}                           \\
        \begin{bmatrix}
            -1 + \sqrt{15} & 7 \\ 2 & 1 + \sqrt{15}
        \end{bmatrix}\begin{bmatrix}
            x_1 \\ x_2
        \end{bmatrix}= \begin{bmatrix}
            0 \\ 0
        \end{bmatrix} \\
    \end{align*}
    We can eliminate the II row by subtracting I $ \left( \frac{2}{-1 + \sqrt{15}} \right) $ \\
    \begin{align*}
        \begin{bmatrix}
            -1 + \sqrt{15} & 7 \\ 2 & 1 + \sqrt{15}
        \end{bmatrix} \rightarrow
        \begin{bmatrix}
            -1 + \sqrt{15} & 7 \\ 2 - 2 & (1 + \sqrt{15})-  \left(\frac{14}{-1 + \sqrt{15}} \right)
        \end{bmatrix} = \begin{bmatrix}
            -1 + \sqrt{15} & 7 \\ 0 & 0
        \end{bmatrix}
    \end{align*}
    Since the last row was eliminated, we see that  of $rank(A- \lambda I)$ is 1. It means $x_1$ or $x_2$ can be freely chosen.

    Keep in mind we are interest only in the 'form' of the eigenvector, because an eigenvector of $A$ multiplied with a scalar is still an eigenvector of $A$.
    \begin{align*}
        0 & = (-1 + \sqrt{15})x + 7y     \\
        y & = \frac{(1 - \sqrt{15})x}{7}
    \end{align*}
    We can eliminate the fraction by setting  $x=7$.
    \begin{align*}
        x   & = 7                                          \\
        y   & = \frac{(1 - \sqrt{15})7}{7} = 1 - \sqrt{15} \\
        v_1 & = \begin{bmatrix}
            7 \\ 1 - \sqrt{15}
        \end{bmatrix}
    \end{align*}
    Same for $\lambda_2$:
    \begin{align*}
        \begin{bmatrix}
            3 - (4 + \sqrt{15}) & 7                   \\
            2                   & 5 - (4 - \sqrt{15})
        \end{bmatrix} \begin{bmatrix}
            x_1 \\ x_2
        \end{bmatrix} = \begin{bmatrix}
            0 \\ 0
        \end{bmatrix}
    \end{align*}
    \begin{align*}
        \begin{bmatrix}
            -1 - \sqrt{15} & 7             \\
            2              & 1 - \sqrt{15}
        \end{bmatrix} \begin{bmatrix}
            x_1 \\ x_2
        \end{bmatrix} = \begin{bmatrix}
            0 \\ 0
        \end{bmatrix}
    \end{align*}
    We can eliminate the II row by subtracting I $ \left( \frac{2}{-1 - \sqrt{15}} \right) $ \\
    \begin{align*}
        \begin{bmatrix}
            -1  - \sqrt{15} & 7 \\
            0               & 0
        \end{bmatrix} \begin{bmatrix}
            x_1 \\ x_2
        \end{bmatrix} = \begin{bmatrix}
            0 \\ 0
        \end{bmatrix} \\
    \end{align*}
    Solving for $x_1$, $x_2$:
    \begin{align*}
        (-1-\sqrt{15}) x_1 + 7 x_2 & = 0                          \\
        x_2                        & = \frac{1 + \sqrt{15}x_1}{7} \\
        x_1                        & = 7  \text{ (chosen)}        \\
        x_2                        & = 1 + \sqrt{15}              \\
        v_2                        & = \begin{bmatrix}
            7 \\ 1 + \sqrt{15}
        \end{bmatrix}
    \end{align*}
\end{example}
\begin{matlab}
    \apilink{eig}{https://www.mathworks.com/help/matlab/ref/eig.html}
    \begin{lstlisting}
        >> [a, d] = eig([3, 7; 11, 3])
    a =
        0.6236   -0.6236
        0.7817    0.7817
    d =
        11.7750         0
        0   -5.7750
    \end{lstlisting}
\end{matlab}
\subsubsection{Geometric multiplicity}
The geometry multiplicity \(\gamma_A \) of an eigenvalue is the dimension of the associatited eigenspace.
\begin{equation}
    \gamma_a(\lambda_i) = \dim \ker\left(A - I \lambda_i \right)
\end{equation}

The geometry multiplicity of an eigenvalue can't be larger than the arithmetic multiplicity.
\begin{equation}
    \gamma_A(\lambda_i) \leq \mu_a(\lambda_1)
\end{equation}
For a square Matrix \(A^{n \times n}\) with \(m\) eigenvalues it holds:
\begin{equation}
    \sum_{i=1}^{m} \gamma(\lambda_i) + \mu(\lambda_i) = n
\end{equation}
\begin{example}
    \begin{align*}
        A = \begin{bmatrix}
            2 & 0 & 0 & 0 \\ 0 & 0 & 0 &0 \\ 0 & 0 &0 &0 \\ 0 & 0 & 1 & 0
        \end{bmatrix}                                                  \\
        p_A(t) = t^3(t- 2)                                                               \\
        \lambda_1 = 2, \lambda_2 = 0                                                     \\
        \mu_A(2) = 1, \mu_A(0) = 3,                                                      \\
        \epsilon_1 = \span \{ \begin{bmatrix}
            2 \\ 0 \\ 0 \\ 0
        \end{bmatrix} \}                             \\
        \epsilon_2 = \span \{ \begin{bmatrix}
            0 \\ 1 \\ 0 \\ 0
        \end{bmatrix}, \begin{bmatrix}
            0 \\ 0 \\ 0 \\ 1
        \end{bmatrix}\} \\
        \gamma_a(2) = \dim \epsilon_1 = 1                                                \\
        \gamma_a(0) = \dim \epsilon_2 = 2
    \end{align*}
\end{example}
\subsection{Similarity}\label{similiarity}
Two square matrices $A$ and $B$ are similar when an if there exists an invertible $n \times n$ matrix P such that:
\begin{gather}
    A = P^{-1}BP \\
    B = PAP^{-1}
\end{gather}
It is denoted as
\begin{equation*}
    A \tilde{=} B
\end{equation*}
U is also called the change of base matrix.
Similar matrices have the same:
\begin{itemize}
    \item Characteristic polynomial
    \item Eigenvalues (but not eigenvectors)
    \item Determinant
    \item Trace
\end{itemize}
Similarity is an equivalence relation
\begin{itemize}
    \item A is similar to A
    \item If A is similar to B, then B is similar to A.
    \item If A is similar to B and B is similar to C, then A is similar to C.
\end{itemize}
\begin{example}
    \begin{align*}
        B = \begin{bmatrix}
            2 & 3 \\ 0 & 4
        \end{bmatrix}, A = \begin{bmatrix}
            3 & 4 \\ \frac{1}{4} & 3
        \end{bmatrix}, P = \begin{bmatrix}
            3 & 0 \\ 1 & 4
        \end{bmatrix}, P^{-1} = \begin{bmatrix}
            \frac{1}{3} & 0 \\ -\frac{1}{12} & \frac{1}{4}
        \end{bmatrix}
    \end{align*}
    \begin{align*}
        P^{-1}BP = \begin{bmatrix}
            \frac{1}{3} & 0 \\ -\frac{1}{12} & \frac{1}{4}
        \end{bmatrix}
        \begin{bmatrix}
            2 & 3 \\ 0 & 4
        \end{bmatrix}
        \begin{bmatrix}
            3 & 0 \\ 1 & 4
        \end{bmatrix} = \begin{bmatrix}
            \frac{2}{3} & 1 \\ -\frac{1}{6} & \frac{3}{4}
        \end{bmatrix}\begin{bmatrix}
            3 & 0 \\ 1 & 4
        \end{bmatrix} = \begin{bmatrix}
            3 & 4 \\ \frac{1}{4} & 3
        \end{bmatrix}
    \end{align*}
    \begin{align*}
        \det(B) & = 2 \cdot 4 - 3 \cdot 0 = 8                           \\
        \det(A) & = 3 \cdot 3 - 1 \cdot \frac{1}{4} = 8                 \\
        tr(A)   & = 3 + 3 = 6                                           \\
        tr(B)   & = 2 +4 = 6                                            \\
        p_B(t)  & = (2 - t)(4 - t) - 4 \cdot 0 = t^2 - 6t + 8           \\
        p_A(t)  & = (3 - t)(3 - t) - 4 \cdot \frac{1}{4} = t^2 - 6t + 8 \\
    \end{align*}
\end{example}
\subsection{Defective matrices}
If there is one eigenvalue \(\lambda_i\) with \(\mu_A(\lambda_i) \neq \gamma_A(\lambda_i) \) then the corresponding Matrix \(A\) defective:
\begin{itemize}
    \item The matrix has less than \(n\) lienary independent eigenvectors
    \item The sum of the dimesons of the eigensapces has a dimension less than \( n\)
\end{itemize}
The eigenvalue is called defective eigenvalue.
\begin{example}
    \begin{gather*}
        A = \begin{bmatrix}
            1 & 1 & 0 \\ 0 & 1 & 1 \\ 0 & 0 & 4
        \end{bmatrix}\\
        \lambda_1 = 1, \lambda_2 = 4\\
        v_1 = \begin{bmatrix}
            1 \\ 0 \\ 0
        \end{bmatrix}, v_2 = \begin{bmatrix}
            \frac{1}{9} \\ \frac{1}{3} \\ 1
        \end{bmatrix}\\
        \mu_A(\lambda_1) = 2 \neq \gamma_A(\lambda_1) = 1 \\
    \end{gather*}
\end{example}
Defective matrices can't be diagonalized.
\subsection{Geeralized eigenvectors}
Let \(L : V \rightarrow V\) with a defective transformation matrix \(A\). A generalized eigenvector \(w\) of a defective eigenvalue is the solution of:
\begin{equation}
    \begin{split}
        \left(A - \lambda I \right)^m w = 0\\
        \left(A - \lambda I \right)^{m-1} w \neq 0 \\
        m > 1, m \in \mathbb{N}\\
    \end{split}
\end{equation}
\(m\) is called the rank of the generalized eigenvector.
\subsubsection{Jordan chain}
Let \(v\) be an ordinary eigenvector of \(A\):
\begin{align*}
    (A - \lambda I)v = 0         \\
    (A - \lambda I)w_1 = v       \\
    (A - \lambda I)w_2 = w_1     \\
    (A - \lambda I)w_3 = w_2     \\
    \vdots                       \\
    (A - \lambda I)w_{n-1} = w_n \\
\end{align*}
\begin{example}
    \begin{align*}
        A = \begin{bmatrix}
            3 & 2 & 0 \\ 0 & 3 & 4 \\  0 & 0 & 3
        \end{bmatrix}
    \end{align*}
    The matrix has single eigenvalue \(\lambda = 3\) with \(\mu_a(3) = 3\) but only one eigenvector \(v_1\).
    \begin{align*}
        A - I \lambda = \begin{bmatrix}
            0 & 2 & 0 \\ 0 & 0 & 4 \\  0 & 0 & 0
        \end{bmatrix}                                                   \\
        \begin{bmatrix}
            0 & 2 & 0 \\ 0 & 0 & 4 \\  0 & 0 & 0
        \end{bmatrix} v =  \begin{bmatrix}
            0 \\ 0 \\ 0
        \end{bmatrix}, v = \begin{bmatrix}
            1 \\ 0 \\ 0
        \end{bmatrix} \\
        \begin{bmatrix}
            0 & 2 & 0 \\ 0 & 0 & 4 \\  0 & 0 & 0
        \end{bmatrix} w_1 =  \begin{bmatrix}
            1 \\ 0 \\ 0
        \end{bmatrix}, w_1 = \begin{bmatrix}
            0 \\ \frac{1}{2} \\ 0
        \end{bmatrix}
    \end{align*}
\end{example}
\subsection{Shift matrix}
A shift matrix that has 1 on its superdiagonal and 0 elsewhere.
\begin{equation*}
    S  = \begin{bmatrix}
        0      & 1 & 0      & \cdots &        \\
        \vdots & 0 & 1      & 0      & \cdots \\
        \vdots &   & \ddots &        &        \\
               &   &        & 0      & 1      \\
               &   & \ddots & 0      & 0      \\
    \end{bmatrix}
\end{equation*}
When multplied wiht another matrix \(A\) it shifts the columns of \(A\) by one to the right.
\begin{align*}
    A         & = \begin{bmatrix}
        c_1 & c_2 & \cdots & c_{n -1} & c_n
    \end{bmatrix} \\
    A \cdot S & = \begin{bmatrix}
        0 & c_2 & \cdots & c_{n -2} & c_{n - 1}
    \end{bmatrix}
\end{align*}
\begin{example}
    \begin{gather*}
        \begin{bmatrix}
            1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9
        \end{bmatrix} \cdot \begin{bmatrix}
            0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0
        \end{bmatrix} = \begin{bmatrix}
            0 & 1 & 2 \\ 0 & 4 & 5 \\ 0 & 7 & 8
        \end{bmatrix}
    \end{gather*}
\end{example}
\subsection{Nilpotent matrix}
A matrix is nilpotent of degree k if
\begin{gather*}
    A^i \neq 0 \\
    A^k = 0 \\
    0 \leq i < k
\end{gather*}
\begin{example}
    Let A be a Matrix containing only zeroers except on its superdiagonal. A is nilpotent of degree  \( k +1 \) where \(k\) is the number of nonzero element. An example
    would be the shift matrix:
    \begin{align*}
        S^{1} = \begin{bmatrix}
            0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0
        \end{bmatrix}
        S^{2} = \begin{bmatrix}
            0 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0
        \end{bmatrix}
        S^{3} = \begin{bmatrix}
            0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0
        \end{bmatrix}
    \end{align*}
\end{example}
\begin{example}
    Only the zero matrix is nilpotent with degree 1.
\end{example}
\begin{example}
    A diagonal matrix is not nilpotent.
    \begin{align*}
        D = \begin{bmatrix}
            2 & 0 \\ 0 & 4
        \end{bmatrix} \\
        D^n = \begin{bmatrix}
            2^{n} & 0 \\ 0 & 4^{n}
        \end{bmatrix}
    \end{align*}
\end{example}
\subsection{Jordan normal form}
\subsubsection{Jordan Block}
A jordan block is a square matrix with the same value for each element on its main diagonal and 1 on it superdiagonal. The other elements are 0.
\begin{equation*}
    B_{\lambda}  = \begin{bmatrix}
        \lambda & 1       & 0      & \cdots  &         \\
        0       & \lambda & 1      & 0       & \cdots  \\
        \vdots  &         & \ddots &         &         \\
                &         &        & \lambda & 1       \\
                &         & \ddots & 0       & \lambda \\
    \end{bmatrix}
\end{equation*}

\subsubsection{Jordan box}
Let \(lambda\) be an eigenvalue of \(A\) with \(\mu(\lambda) = n\) and \( \gamma_a(\lambda) = m \).
A Jordan box is the direct sum of
\begin{equation}
    J_{\lambda} = D_{\lambda} \oplus B_{\lambda}
\end{equation}
where:
\begin{gather*}
    \dim J_{\lambda} = n \\
    \dim D_{\lambda} = m \\
    \dim B_{\lambda} = n - m \\
\end{gather*}
\begin{example}
    \begin{gather*}
        \mu(\lambda) = 4, \gamma(\lambda) = 2 \\
        D_{\lambda} = \begin{bmatrix}
            \lambda
        \end{bmatrix}
        B_{\lambda} = \begin{bmatrix}
            \lambda & 1 & 0 \\ 0 & \lambda & 1 \\ 0 & 0 & \lambda
        \end{bmatrix} \\
        J_{\lambda} = \begin{bmatrix}
            \lambda & 0       & 0       & 0       \\
            0       & \lambda & 1       & 0       \\
            0       & 0       & \lambda & 1       \\
            0       & 0       & 0       & \lambda \\
        \end{bmatrix}
    \end{gather*}
\end{example}
\begin{example}
    \begin{gather*}
        \mu(\lambda) = 4, \gamma(\lambda) = 3 \\
        D_{\lambda} = \begin{bmatrix}
            \lambda & 0 \\  0 & \lambda
        \end{bmatrix}
        B_{\lambda} = \begin{bmatrix}
            \lambda & 1 \\ 0 & \lambda
        \end{bmatrix} \\
        J_{\lambda} = \begin{bmatrix}
            \lambda & 0       & 0       & 0       \\
            0       & \lambda & 0       & 0       \\
            0       & 0       & \lambda & 1       \\
            0       & 0       & 0       & \lambda \\
        \end{bmatrix}
    \end{gather*}
\end{example}
\section{Operations}
\subsection{Transposing}
Transpose of a matrix \( A \) is an operator which flips a matrix over its diagonal; that is, it switches the row and column indices of the matrix A by producing another matrix, often denoted by $A^T$.
\begin{example}
    \begin{align*}
        \begin{bmatrix}
            1 & 2 & 3
        \end{bmatrix}^T = \begin{bmatrix}
            1 \\
            2 \\
            3 \\
        \end{bmatrix}
    \end{align*}
\end{example}
\begin{example}
    \begin{align*}
        \begin{bmatrix}
            1 & 2 & 3 \\
            4 & 5 & 6 \\
            7 & 8 & 9 \\
        \end{bmatrix}^T = \begin{bmatrix}
            1 & 4 & 7 \\
            2 & 5 & 8 \\
            3 & 6 & 9 \\
        \end{bmatrix}
    \end{align*}
\end{example}
Notice the diagonal elements do not get swaped by transposing. So for any diagonal matrix D holds $D=D^T$.
\begin{matlab}
    \apilink{transpose}{https://www.mathworks.com/help/matlab/ref/transpose.html}
    \begin{lstlisting}
    A = [1,2,3;4,5,6]
    transpose(A)
    ans =
    1     4
    2     5
    3     6
    \end{lstlisting}
\end{matlab}
\subsection{Direct sum}
The direct sum of two matrixes \(A^{a \times b}\) and \(B^{c \times d}\) is defined as
\begin{equation}
    \begin{split}
        C = A \oplus B = \begin{bmatrix}
            A & N_1 \\ N_2 & B
        \end{bmatrix} \\
        \dim C = (a + c) \times (b + d)
    \end{split}
\end{equation}
\(N_1\) and \(N_2\) are zero matrices with dimensons \(\dim N_1 = b\)
\subsection{Diagonalisation}
A matrix $A$ is diagonalizabe if $A$ is similar (see \ref{similiarity}) to a diagonal matrix $D$.
\begin{equation*}
    D = U^{-1}AU \\
\end{equation*}
\subsubsection{Eigendecomposition}
A  matrix can be diagonalized using its eigenvalues and eigenvectors.
D is a diagonal matrix containing the eigenvalues $\lambda_i$ on it main diagonal.
The the eigenspaces $\epsilon_i$ form a base called \textbf{eigenbase} (when the arithmetic multiplicity of an eigenvalue is 1 then $\epsilon$ is just the eigenvector).
So change of base matrix $U$ has the base vectors of the eigenspaces as it's columns.
\begin{equation}
    A = U D U^{-1} \\
\end{equation}
\begin{equation}
    U = \begin{bmatrix}
        v_1 & v_2 \cdots v_n
    \end{bmatrix}
\end{equation}
\begin{example}
    \begin{equation*}
        A = \begin{bmatrix}
            3 & 0 & 1 \\ 0 & 2 & 0  \\ 5 & 0 & -1
        \end{bmatrix}
    \end{equation*}
    The eigenvalues $\lambda_i$ and eigenvectors $v_i$ are:
    \begin{gather*}
        \lambda_1 = 4, v_1 = \begin{bmatrix}
            1 \\ 0 \\ 1
        \end{bmatrix}  \\
        \lambda_2 = -2, v_2 = \begin{bmatrix}
            -\frac{1}{5} \\ 0 \\ 1
        \end{bmatrix} \\
        \lambda_3 = 2, v_3 = \begin{bmatrix}
            0 \\ 1 \\ 0
        \end{bmatrix}  \\
    \end{gather*}
    We can construct U and D. Keep in mind that the order of the eigenvalues in the diagonal of $D$ must match the order of the order of eigenvector columns in $U$ (and $U^{-1}$).
    \begin{align*}
        D      & = \begin{bmatrix}
            2 & 0 & 0 \\ 0 & 4 & 0 \\ 0 & 0 & -2
        \end{bmatrix}  \\
        U      & =  \begin{bmatrix}
            -\frac{1}{5} & 0 & 1   \\
            0            & 0 & 1 & \\
            1            & 1 & 0   \\
        \end{bmatrix} \\
        U^{-1} & = \begin{bmatrix}
            \frac{5}{6}   & 0 & \frac{1}{6} \\
            - \frac{5}{6} & 0 & \frac{5}{6} \\
            0             & 1 & 0
        \end{bmatrix}
    \end{align*}
    The diagonalized A is:
    \begin{equation*}
        A = \begin{bmatrix}
            -\frac{1}{5} & 0 & 1   \\
            0            & 0 & 1 & \\
            1            & 1 & 0   \\
        \end{bmatrix} \begin{bmatrix}
            2 & 0 & 0 \\ 0 & 4 & 0 \\ 0 & 0 & -2
        \end{bmatrix}
        \begin{bmatrix}
            \frac{5}{6}   & 0 & \frac{1}{6} \\
            - \frac{5}{6} & 0 & \frac{5}{6} \\
            0             & 1 & 0
        \end{bmatrix}     \end{equation*}
    \begin{matlab}
        \begin{lstlisting}
    >> a = [3,0,1;0,2,0;5,0,-1]
    >> [v, d] = eig(a)
        v =
            0.7071   -0.1961         0
                0         0    1.0000
            0.7071    0.9806         0
        d =
            4     0     0
            0    -2     0
            0     0     2
    >> v*d*inv(v)
            ans =
                3.0000         0    1.0000
                     0    2.0000         0
                5.0000         0   -1.0000

   \end{lstlisting}
    \end{matlab}
    \subsection{Raising a matrix to the nth power using diagonalisation}
    Using the definition of matrix multiplication a single squaring a matrix takes \(O(n^3)\) computation steps. Raising a matrix to the \(m\)th power would take \(O(m \cdot n^3)\) steps.
    For any diagonal matrix it holds:
    \begin{equation}
        D^{m} = \begin{bmatrix}
            x_{11}^{m} &            &        &            \\
                       & x_{22}^{m} &        &            \\
                       &            & \ddots &            \\
                       &            &        & x_{nn}^{m}
        \end{bmatrix}
    \end{equation}
    Using diagonalisation a more effcient calculation can be achieved:
    \begin{gather*}
        A = UDU^{-1} \\
        A^2 = A \cdot A =  UD \cancel{U^{-1}  U} DU^{-1} = UD^2U^{-1} \\
        A^3 = A^2 \cdot A = UD^2 \cancel{U^{-1} U} D U^{-1} = U D^3 U^{-1}  \\
        \vdots \\
        A^{n} = U D^n U^{-1}
    \end{gather*}
\end{example}
\subsection{Matrix exponential}\label{sec:matrixexponent}
The taylor series of the exponential functions is given as:
\begin{equation}
    e^{x} = \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1 + x + \frac{x^2}{2} + \frac{x^3}{6} \cdots
\end{equation}
Using this definition you can define the matrix exponential:
\begin{equation}
    e^{A} = \sum_{n=0}^{\infty} \frac{A^n}{n!} = I + A + \frac{A^2}{2} + \frac{A^3}{6} \cdots
\end{equation}
\subsubsection{Diagonal Case}
\begin{align*}
    e^{D} & = I +
    \begin{bmatrix}
        x_{11} &        &        &        \\
               & x_{22} &        &        \\
               &        & \ddots &        \\
               &        &        & x_{nn}
    \end{bmatrix} + \frac{1}{2}
    \begin{bmatrix}
        x_{11}^{2} &            &        &            \\
                   & x_{22}^{2} &        &            \\
                   &            & \ddots &            \\
                   &            &        & x_{nn}^{2}
    \end{bmatrix}  + \frac{1}{6}
    \begin{bmatrix}
        x_{11}^{3} &            &        &            \\
                   & x_{22}^{3} &        &            \\
                   &            & \ddots &            \\
                   &            &        & x_{nn}^{3}
    \end{bmatrix} + \frac{1}{24}
    \begin{bmatrix}
        x_{11}^{4} &            &        &            \\
                   & x_{22}^{4} &        &            \\
                   &            & \ddots &            \\
                   &            &        & x_{nn}^{4}
    \end{bmatrix} + \cdots                                    \\
          & = I + \begin{bmatrix}
        x_{11} &        &        &        \\
               & x_{22} &        &        \\
               &        & \ddots &        \\
               &        &        & x_{nn}
    \end{bmatrix} +
    \begin{bmatrix}
        \frac{x_{11}^{2}}{2} &                      &        &                      \\
                             & \frac{x_{22}^{2}}{2} &        &                      \\
                             &                      & \ddots &                      \\
                             &                      &        & \frac{x_{nn}^{2}}{2}
    \end{bmatrix}  +
    \begin{bmatrix}
        \frac{x_{11}^{3}}{6} &                      &        &                      \\
                             & \frac{x_{22}^{3}}{6} &        &                      \\
                             &                      & \ddots &                      \\
                             &                      &        & \frac{x_{nn}^{3}}{6}
    \end{bmatrix} +
    \begin{bmatrix}
        \frac{ x_{11}^{4}}{24} &                       &        &                       \\
                               & \frac{x_{22}^{4}}{24} &        &                       \\
                               &                       & \ddots &                       \\
                               &                       &        & \frac{x_{nn}^{4}}{24}
    \end{bmatrix} + \cdots                                    \\
          & = \begin{bmatrix}
        \sum_{m=0}^{\infty} \frac{x_{11}^m}{m!} &                                         &        &                                         \\
                                                & \sum_{m=0}^{\infty} \frac{x_{22}^m}{m!} &        &                                         \\
                                                &                                         & \ddots &                                         \\
                                                &                                         &        & \sum_{m=0}^{\infty} \frac{x_{22}^m}{m!}
    \end{bmatrix}   =   \begin{bmatrix}
        e^{x_{11}} &             &        &            \\
                   & e^{x_{22} } &        &            \\
                   &             & \ddots &            \\
                   &             &        & e^{x_{nn}}
    \end{bmatrix} \\
\end{align*}
\subsection{Diagonalizable case}
If \(A\) is diagonalizabe with \(UDU^{-1}\) then:
\begin{align*}
    e^{A} & = \sum_{n=0}^{\infty} \frac{U D^n U^{-1}}{n!} = U I U^{-1} + \frac{U D U^{-1}}{n!}  + \frac{{U D^2 U^{-1}}}{2} + \frac{U D^3 U^{-1}}{6} \cdots \\
          & = U^{-1} \left(\sum_{n=0}^{\infty} \frac{D^n}{n!}\right)U = U^{-1}e^DU                                                                         \\
          & = U^{-1} \begin{bmatrix}
        e^{\lambda_1} &                &        &               \\
                      & e^{\lambda_2 } &        &               \\
                      &                & \ddots &               \\
                      &                &        & e^{\lambda_n}
    \end{bmatrix} U                                                                                \\
\end{align*}
\begin{example}
    \begin{gather*}
        A = \begin{bmatrix}
            3 & -4 \\ -5 & -5 \\
        \end{bmatrix} \\
        \lambda_1 = -7, v_1 = \begin{bmatrix}
            \frac{2}{5} \\ 1
        \end{bmatrix} \\
        \lambda_2 = 5, v_2 = \begin{bmatrix}
            -2 \\ 1
        \end{bmatrix} \\
        e^D =         \begin{bmatrix}
            \frac{2}{5} & -2 \\ 1 & 1
        \end{bmatrix}
        \begin{bmatrix}
            e^{-7} & 0 \\0 & e^5
        \end{bmatrix}
        \begin{bmatrix} \frac{5}{12} & \frac{5}{6} \\ \frac{-5}{12} & \frac{1}{6} \end{bmatrix}
    \end{gather*}
\end{example}
\begin{matlab}
    \apilink{expm}{https://www.mathworks.com/help/matlab/ref/expm.html}
    \begin{lstlisting}
     >> a = [3, -4; -5, -5]
     >> expm(a)
        ans =
            123.6778  -49.4707
            -61.8384   24.7363
    \end{lstlisting}
\end{matlab}
\subsubsection{Comuting matrices}
If two matrices \(A\) and \(B\) commute (\(AB = BA\)) then
\begin{equation}
    e^{A + B} = e^{A}e^{B}
\end{equation}
\subsubsection{Jordan bock}
A Jordan block \(B_{\lambda}\) of size m can be separated into:
\begin{equation}
    B_{\lambda} = D_{\lambda} + S
\end{equation}
where \(S\) is the shift matrix (the shift matrix is nilpotent of degree \(m\)).
\begin{align}
    e^{B_\lambda} = e^{D_{\lambda} + S} =  e^{D_{\lambda}} \cdot e^{S} \tag{Note \(D_{\lambda} \) and S commute}
\end{align}
\begin{align*}
     & =  e^{D_{\lambda}} \cdot e^{S} = e^{D_{\lambda}} \left( \sum_{n=0}^{m - 1} \frac{S^n}{n!} = I + S + \frac{S^2}{2} + \frac{S^3}{6} \cdots \right) \\
     & =  e^{D_{\lambda}} \left(I + \begin{bmatrix} 0 & 1 & 0  &  0 & \cdots \\ 0 & 0 & 1 & 0 & \cdots \\ 0 & 0 & 0 & 1 & \cdots \\ \vdots & & & \end{bmatrix} +
    \frac{1}{2} \begin{bmatrix} 0 & 0 & 1  &  0 & \cdots \\ 0 & 0 & 0 & 1 & \cdots \\ 0 & 0 & 0 & 0 & \cdots \\ \vdots & & & \end{bmatrix} + \cdots +
    \frac{1}{(m-1)!} \begin{bmatrix} 0 &  \cdots & 0 & 1  \\ 0 & \cdots & & 0 \\  \vdots & & & \end{bmatrix}  \right)                                                                                \\
     & = e^{D_{\lambda}} \begin{bmatrix}
        1      & 1 & \frac{1}{2} & \frac{1}{6} & \cdots & \frac{1}{(m -1)!} \\
        0      & 1 & 1           & \frac{1}{2} & \cdots & \frac{1}{(m -2)!} \\
        0      & 0 & 1           & 1           & \cdots & \frac{1}{(m -3)!} \\
        \vdots &   &             &
    \end{bmatrix} = \begin{bmatrix}
        e^{\lambda} & e^{\lambda} & \frac{1}{2} e^{\lambda} & \frac{1}{6}  e^{\lambda} & \cdots & \frac{1}{(m-1)!}    e^{\lambda} \\
        0           & e^{\lambda} & e^{\lambda}             & \frac{1}{2}  e^{\lambda} & \cdots & \frac{1}{(m-2)!}   e^{\lambda}  \\
        0           & 0           & e^{\lambda}             & e^{\lambda}              & \cdots & \frac{1}{(m-3)!}   e^{\lambda}  \\
        \vdots      &             &                         &
    \end{bmatrix}
\end{align*}
\begin{example}
    \begin{align*}
        B_2 = \begin{bmatrix}
            2 & 1 & 0 & 0 \\
            0 & 2 & 1 & 0 \\
            0 & 0 & 2 & 1 \\
            0 & 0 & 0 & 2 \\
        \end{bmatrix} \\
        e^{B_2} = \begin{bmatrix}
            e^{2} & e^{2} & \frac{1}{2} e^{2} & \frac{1}{6} e^{2} \\
            0     & e^{2} & e^{2}             & \frac{1}{2} e^{2} \\
            0     & 0     & e^{2}             & e^{2}             \\
            0     & 0     & 0                 & e^{2}             \\
        \end{bmatrix}
    \end{align*}
\end{example}


\section{Maximum Likelihood \& Maximum a Posteriori}
\smallskip \hrule height 2pt \smallskip
(Also see paragraph at the end of this PDF near vocab for a MLE/MAP comparison.) \hfill \\

\underline{Vocab}
\begin{itemize}
	\item\textbf{likelihood}: the probability of the data given a parameter.  E.g. $P(D | \theta)$ (for discrete like Binomial).
	Need not a pdf; need not be normalized.   %  http://www.robots.ox.ac.uk/~az/lectures/est/lect34.pdf  + Erick
 	\item \textbf{log-likelihood}: lower-case: $l(\theta|x) = \log L(\theta | x)$
	\item \textbf{maximum likelihood} (ML):
	\item \textbf{MLE}: Maximum Likelihood Estimation.
	\item \textbf{PAC}: Probability Approximately Correct.
	\item \textbf{Posterior}: the likelihood times the prior, normalized  % Murphy 2012 pg 70
\end{itemize}

\underline{MLE}: Maximum Likelihood Estimation \hfill \\
Choose $\theta$ to maximize probability of D. \hfill \\
Set derivative of \_\_ to zero and solve.  If function is multivariate, set each partial derivative to zero and solve. \hfill \\
$\hat{\theta} = \argmax_\theta P(D | \theta) = \argmax_\theta \ln P(D | \theta) $ \hfill \\
Note we are using $\ln$, not $\log_2$ as we did for entropy above.  Want it to cancel exponents now.
 \hfill \\

\hfill \\
\underline{Binomial Distribution} \hfill \\
Assumes i.i.d: $D=\{x_i | i=1 \dots n\}, P(D | \theta) = \prod_i P(x_i \mid \theta)$. \hfill \\
Likelihood function: $P(D | \theta) = \theta^{\alpha_H} (1-\theta)^{\alpha_T}$  \hfill \\
P(heads) = $\theta$, P(tails) = $1 - \theta$ \hfill \\
\begin{align*}
	\hat{\theta} &= \argmax_\theta \ln P(D| \theta) \\
	 	 &= \argmax_\theta \ln \theta*{\alpha H}(1-\theta)^{\alpha T}
\end{align*}
Find optimal theta by setting the derivative to zero:
\begin{align*}
	\frac{d}{d\theta} \ln P(D| \theta) &= \frac{d}{d\theta}  \ln \theta*{\alpha H}(1-\theta)^{\alpha T} \\
	 	 &= \argmax_\theta \ln \theta*{\alpha H}(1-\theta)^{\alpha T} \\
		 & = \dots = \frac{\alpha_H}{\alpha_H  + \alpha_T}
\end{align*}

For Binomial, there is exponential decay in uncertainty with \# of observations.  % slide 7 at http://courses.cs.washington.edu/courses/cse446/16wi/Slides/3_PointEstimation.pdf
You can also find the probability that you are approximately correct (see \href{http://courses.cs.washington.edu/courses/cse446/16wi/Slides/3_PointEstimation.pdf}{notes}).  \hfill \\
$P(|\widehat{\theta} = \theta*| \geq \epsilon) \leq 2e^{-2N\epsilon^2}$.  Can calculate N (\# of flips) to have error less than $\epsilon$ with probability of being incorrect $\delta$.  Your sensitivity depends on your problem; error on stock market data might cost billions.

What if you had prior beliefs?  Use MAP instead of MLE.


%% Solution of part 1
\subsubsection*{1.A}
Since the input signal $r_k$ is white, the $R$ matrix only has non-zero entries in its main diagonal:

\begin{equation}
R = \mathrm{diag}([1, \sigma^2_r, \ldots, \sigma^2_r]) \implies \mathrm{tr}(R) = (L+1)\sigma^2_r + 1,
\end{equation}
where the first entry is 1 because the bias weight input is always $+1$. Therefore,
\begin{equation}
\mu = 0.01\frac{1}{\mathrm{tr}(R)} = \frac{0.01}{(L+1)\sigma^2_r + 1} = 2.439\times 10^{-4}.
\end{equation}

\subsubsection*{1.B}
The Matlab code to calculate the learning curve is included below. Figure~\ref{fig:part1-learning-curve} shows the learning curve averaged over 100 independent input realizations, and  Figure~\ref{fig:part1-weights} shows the converged weight vector. Note that the bias weight value is very significant.

\FloatBarrier
\begin{figure}[h!]
	\centering
	\includegraphics[scale=0.8]{part1_learning_curve.eps}
	\caption{Experimental learning curve for nonlinear plant indemnification using a linear filter. The learning curve was averaged 100 times.}
	\label{fig:part1-learning-curve}
\end{figure}
\FloatBarrier

\FloatBarrier
\begin{figure}[h!]
	\centering
	\includegraphics[scale=0.8]{part1_weights.eps}
	\caption{Weight vector after convergence.}
	\label{fig:part1-weights}
\end{figure}
\FloatBarrier

\subsubsection*{1.C}
As shown in Figure~\ref{fig:part1-learning-curve}, the MMSE estimated using the last 200 samples was equal to $\approx 0.051$.

\subsubsection*{1.D}
As discussed in class, the convergence time of the learning curve depends on the eigenvalues of the matrix $R$. Since $R$ is a diagonal matrix, its eigenvalues are equal to the entries in the main diagonal:
\begin{equation}
\lambda_1 = 1, \qquad \lambda_2 = \ldots = \lambda_{L+2} = \sigma_r^2.
\end{equation}

The time constants $\tau_n = 1/2\mu\lambda_n$ are therefore
\begin{equation}
\tau_1 = \frac{1}{2\mu}, \qquad \tau_2 = \ldots = \tau_{L+2} = \frac{1}{2\mu\sigma_r^2}.
\end{equation}

The learning curve has two modes. One due to the bias weight, and another due to the signal inputs. The slowest mode will determine the convergence time of the learning curve.

In the first case, when $\sigma_r^2 = 4$, the slowest mode is due to the bias weight since $\tau_n < \tau_1, n > 1$. Therefore, the slowest time constant is $\tau_1 = 2050$. The approximate number of iterations for convergence is given by $(T_{mse})_1 = 0.5\tau_1 = 1025$, which we can verify this from Figure~\ref{fig:part1-learning-curve}.

When, $\sigma_r^2$ is made small. The mode due to the signal inputs will become the slowest one. And since we're assuming that $(L+1)\sigma_r^2 << 1$, the time constant due to the input signals is inversely proportional to the signal variance $\sigma_r^2$, as $\mu\approx 0.01$. Thus, the time constant is $\tau_n = 50/\sigma_r^2 >> 2050$. Therefore, the convergence time of the learning curve increases as we decrease the input signal power.

As for the MMSE, the MMSE is smaller for smaller $\sigma_r^2$. When the input signal is small enough to make the plant nonlinearity negligible, the plant is essentially the linear filter $\frac{1}{2}H_1(z)H_2(z)$, which is an FIR filter with 11 taps. The factor of $\frac{1}{2}$ appears because $g(x) \approx x/2, x \to 0$, which follows from the Taylor series expansion of $g(x)$. The adaptive filter has 10 taps plus the bias weight, and thus it could model the plant not perfectly, but very well.

\subsubsection*{1.E}
The Matlab code is the same as for part (B) and it is shown below. The output of the plant is compared to the output of the adaptive filter in Figure~\ref{fig:part1-test}.

\FloatBarrier
\begin{figure}[h!]
	\centering
	\includegraphics[scale=0.8]{part1_test.eps}
	\caption{Test of the adaptive filter after convergence with a sinusoidal signal. During the first $L+1$ samples, the filter was being initialized.}
	\label{fig:part1-test}
\end{figure}
\FloatBarrier


\section*{Exercises}

\begin{ex}
  Consider the vectors
  \begin{equation*}
    \vect{u}_1 = \begin{mymatrix}{r} 1 \\ 1 \\ -2 \end{mymatrix},\quad
    \vect{u}_2 = \begin{mymatrix}{r} 1 \\ 2 \\ -2 \end{mymatrix},\quad
    \vect{u}_3 = \begin{mymatrix}{r} 1 \\ -3 \\ -2 \end{mymatrix},\quad
    \vect{u}_4 = \begin{mymatrix}{r} -1 \\ 1 \\ 2 \end{mymatrix}.
  \end{equation*}
  Which of the following vectors are in
  $\sspan\set{\vect{u}_1,\ldots,\vect{u}_4}$? For each vector that is
  in the span, exhibit a linear combination of
  $\vect{u}_1,\ldots,\vect{u}_4$ that equals this vector.
  \begin{equation*}
    (a)\quad
    \vect{x} = \begin{mymatrix}{r} 1 \\ 2 \\ -1 \end{mymatrix},
    \qquad
    (b)\quad
    \vect{y} = \begin{mymatrix}{r} 2 \\ -3 \\ -4 \end{mymatrix},
    \qquad
    (c)\quad
    \vect{z} = \begin{mymatrix}{r} 1 \\ 5 \\ -2 \end{mymatrix}.
  \end{equation*}
  \vspace{-2ex}
  \begin{sol}
    (a) $\vect{x}$ is not in the span.
    (b) $\vect{y} = 7\vect{u}_1-5\vect{u}_2$.
    (c) $\vect{z} = -3\vect{u}_1+4\vect{u}_2$.
  \end{sol}
\end{ex}

\begin{ex}
  Describe the span of the vectors
  $\vect{u}=\begin{mymatrix}{r} 1 \\ 0 \\ 2 \end{mymatrix}$ and
  $\vect{v}=\begin{mymatrix}{r} 2 \\ -1 \\ 1 \end{mymatrix}$ in
  $\R^3$.
  \begin{sol}
    It is the plane $2x + 3y - z = 0$.
  \end{sol}
\end{ex}

\begin{ex}
  Describe the span of the following vectors in $\R^4$:
  \begin{equation*}
    \vect{u}_1=\begin{mymatrix}{r} 1 \\ 1 \\ -1 \\ -1 \end{mymatrix},\quad
    \vect{u}_2=\begin{mymatrix}{r} 5 \\ 1 \\ 1 \\ 0 \end{mymatrix},\quad
    \vect{u}_3=\begin{mymatrix}{r} 0 \\ -2 \\ 2 \\ 1 \end{mymatrix},\quad
    \vect{u}_4=\begin{mymatrix}{r} 3 \\ 1 \\ 1 \\ 1 \end{mymatrix}.
  \end{equation*}
  \begin{sol}
    It is the hyperplane given by the equation $x - 2y - 3z + 2w = 0$.
  \end{sol}
\end{ex}

\begin{ex}
  Let $\vect{u}=\begin{mymatrix}{r} 2 \\ 1 \\ 0 \end{mymatrix}$,
  $\vect{v}=\begin{mymatrix}{r} 1 \\ 3 \\ 5 \end{mymatrix}$, and
  $\vect{w}=\begin{mymatrix}{r} 1 \\ 0 \\ -1 \end{mymatrix}$.
  Show that
  $\sspan\set{\vect{u},\vect{v},\vect{w}} =
  \sspan\set{\vect{u},\vect{v}}$.
\end{ex}

\begin{ex}
  Suppose $\set{\vect{u}_1,\ldots,\vect{u}_k}$ is a set of
  vectors from $\R^n$. Show that
  $\vect{0}\in\sspan\set{\vect{u}_1,\ldots,\vect{u}_k}$.
  \begin{sol}
    $0\vect{u}_1+\ldots+0\vect{u}_k = \vect{0}$.
  \end{sol}
\end{ex}

\begin{ex}
  In this exercise, we use scalars from the field $\Z_5$ of integers
  modulo $5$ instead of real numbers (see Section~\ref{sec:fields},
  ``Fields''). Consider the vectors
  \begin{equation*}
    \vect{u}_1 = \begin{mymatrix}{r} 1 \\ 4 \\ 3 \end{mymatrix},\quad
    \vect{u}_2 = \begin{mymatrix}{r} 0 \\ 2 \\ 3 \end{mymatrix},\quad
    \vect{u}_3 = \begin{mymatrix}{r} 2 \\ 1 \\ 3 \end{mymatrix},\quad
    \vect{u}_4 = \begin{mymatrix}{r} 3 \\ 1 \\ 0 \end{mymatrix}.
  \end{equation*}
  Which of the following vectors are in
  $\sspan\set{\vect{u}_1,\ldots,\vect{u}_4}$? For each vector that is
  in the span, exhibit a linear combination of
  $\vect{u}_1,\ldots,\vect{u}_4$ that equals this vector.
  \begin{equation*}
    (a)\quad
    \vect{x} = \begin{mymatrix}{r} 0 \\ 1 \\ 4 \end{mymatrix},
    \qquad
    (b)\quad
    \vect{y} = \begin{mymatrix}{r} 1 \\ 1 \\ 2 \end{mymatrix},
    \qquad
    (c)\quad
    \vect{z} = \begin{mymatrix}{r} 2 \\ 0 \\ 4 \end{mymatrix}.
  \end{equation*}
  \vspace{-2ex}
  \begin{sol}
    (a) $\vect{x} = 3\vect{u}_2$.
    (b) $\vect{y}$ is not in the span.
    (c) $\vect{z} = 2\vect{u}_1 + 1\vect{u}_2$.
  \end{sol}

\end{ex}