\documentclass[12pt, leqno]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%american mathematical society - AMS

\usepackage{enumerate}

\usepackage{wrapfig}
\usepackage{subfig}

\oddsidemargin = 0in
\textwidth=6.5in

\numberwithin{equation}{section}

\numberwithin{figure}{section}

\begin{document}

%\baselineskip=20pt

Hello world! This is the beginning of \LaTeX! \\

We can start a new paragraph at any time by leaving a blank line.
Not that there are many special characters in \LaTeX or just \TeX.
In particular \&, \%, \#, \_, \{, \}, carets and tildes.  and  \textbackslash
are all special characters -- if \LaTeX sees any of these without a preceding backslash,
it thinks they are commands. \\

A macro is just a markup command.

\section*{Typesetting Mathematics!}

Donnie Knuth is the creator of \TeX. To typeset mathematics and it is very good at it.
We could type a vector as:

$ (v_1, v_2, v_3)^T $.

We can create display math in a number of ways.

$$ %display math mode.
f(x) = x^n + 500x^n-1 + \cdots + 501x
$$
We can type many things in \TeX that were not possible in HTML, for example

\begin{equation}
y = x
\end{equation}

\begin{displaymath}
g(x) = \int_0^\infty G(t,x) \, dx  % \, adds just a little bit of extra space -- only in math mode.
\end{displaymath}

We can now do more complicated constructions. For example, we say that $\lambda$ is an eigenvalue of a matrix $A$ corresponding to a vector $\vec{u}$ or \(u\) if $Au = \lambda u $ For example

%put some bullshit right here.
%Remember that you CANNOT HAVE BLANK SPACE AT END OF EQUATION!!!

so $-1$ is an eigenvalue corresponding to eigenvector $[1,0]^T$

\LaTeX\ can do more sophisticated mathematical typesetting. We can make piecewise defined functions as follows:

\[
f(x) = \begin{cases}
x^2 & x\ge 0 \\
0 & \text{otherwise}.
\end{cases}
\]

Here is an example involving some Greek letters and special functions:
$$
\Lambda_N =
\sum_{n=0}^{N}\left(\frac{1}{\cos\lambda^n}\right).
$$

We could write the key part of the proof that the harmonic series diverges as

% &= means align on this thing

\begin{align}
\sum_{i=1}^{2^N-1}
\frac{1}{i} &= 1 + \frac{1}{2} + \frac{1}{3} + \cdots + \frac{1}{2^N-1}\\
&> \frac{1}{2} + \frac{1}{4} + \frac{1}{4} +
\overbrace{\frac{1}{8} + \cdots + \frac{1}{8}}^{\text{4 times}} +
\cdots + \frac{1}{2^N-1} \quad \text{for} N > 3
\end{align}

\section*{Counting}
%\label{sec:math}
%\nonumber will give the equation no number.
As we saw in Section %\ref{sec:math}
\LaTeX counts many things, such as chapters, sections and other document body parts, equations,
citations, theorems and so on. We can manipulate those counters by using the setcounter and addtocounter macros.

To make our own counter, we just use the \texttt{setcounter} macro:
\newcounter{numberthes}
\setcounter{numberthes}{42}
for instance, the number of times the word "the" has occurred so far is
\arabic{numberthes} but now, the number of times ``the" has occurred. is
\addtocounter{numberthes}{2}
\arabic{numberthes}
% these are back quotes by unix geeks `````````

% there are two environments 'align' starts a bunch of stuff(math mode, number equations, align equal signs)
% there is 'aligned' that does NOT start math mode. It only starts in math mode.
%ampersands are for alignment

\subsection*{Theorems \& Stuff}
\label{subsec:theorems}
In this subsection, numbered, \ref{subsec:theorems}, we will discuss the numbering scheme for theorems, definitions corollaries, and such.

\newtheorem{theorem}{Theorem}[section] %the counter is at the end.
\newtheorem{definition}[theorem]{Definition}

\newtheorem{lemma}[theorem]{Lemma} %counter in the middle uses an exsisting counter

\begin{definition}
The definition is where we put the meanings of the terms we use in our theorems.
\end{definition}

First, we prove a technical result.
\begin{lemma}
here is where we prove some little technical result taht we will use in the proof of the theorem.
\end{lemma}

\begin{theorem}
Theorems are where we prove things about the terms we defined in the definitions.
\end{theorem}

\section*{Lists}
There are three kinds of lists in every markup language:
ordered lists, unordered lists, and description lists.

\begin{enumerate}[A)]
\item The first item
\item The second item
\item The ultimate item
\end{enumerate}

Here is an unordered list.
%\noindent
\begin{itemize}
\item one
\item two
\item three
\end{itemize}

Here is a description list.
\begin{description}
\item[The first definition -] the first def.
\item[second -] the second. etc etc
\end{description}

\section*{Page layout and spacing}
Page layout in \TeX\ is not as transparent as it is in writing in WYSiWYG word processor
instead of setting margins, as we woul in a WYSiWYG program, \LaTeX\ knows only where the
upper left corner of hte text area is relative to the page, and how wide
and tall the text area is.
For this purpose it sets many variables that control the positions and sizes of the text area.
We can change the values of these variables.

There are two ways to change the values of these variables: We can do it directly (set the variable equal to exactly what we want.); or we can use the \texttt{newdimension} command.
Here is a list(possibly incomplete) of the variables of what we can change and control.

\begin{description}
\item[oddsidemargin-]This is distance of the text area from the left edge of the page on \textbf{odd} numbered pages.
This is useful when you are writing a book! In the article documentclass, this controls both odd and even numbered pages. Note that the distance we specify here is relative to default 1 inch margin. Not that the documentclass also imposes a separate default.
\item[evensidemargin-]this is the distance of the text area from the left edge of the page on even-numbered pages This only applies in some documentclasse, such as in book.
\item[topmargin-] This is the top of the page.
\item[textwidth-]the width of the text area.
\item[textheight-] the height of the text area.
\item[headheight-] The height of the header.
\item[headsep-]The height of the separation of the header from the text area.
\item[footskip-] The distance from th text area to the footer.
\item[baselineskip-] The distance from the bottom of on line to the next.
\item[baselinestrech] This is actually not a dimension; it is a macro that controls how much the space between
line is stretched. For example, to get double-spaced text you could type\\
%\texttt{\textbackslash renewcommand\{\textbackslash baselinestretch\{2\}\}}
\item[parskip-] The extra distance to place between paragraphs.
\item[parindent-] the amount o indentation at the beginning of every paragraph. Except the first paragraph in article class.

\subsection{Spacing}

Before we can really discuss spacing, we have to talk about horizontal and vertical mode. \LaTeX\
takes characters not separated by spaces and pastes them together into a word.
It takes other white space and replaces it by so-called \textit{glue}.
This is illustrated below:
%\begin{description}

%\begin{center}
%\fboxsep=0pt
%\framebox(stuff){M}
%\end{center}

All of this word and line formation takes place in horizontal mode.
Putting lines one after another requires going into vertical mode -- where \LaTeX\ figures out how to fit the various lines on the page.

we can make horizontal spaces \hspace{10pt} any time we are in horizontal mode.
\vspace{0.5in} \\
Space can be either positive or negative. Note that \LaTeX cannot put in vertical space except when it is in vertical mode.

%\end{description}

there are some special spacing commands that allow us to put in a lot of glue at once.
In particular in horizontal mode, the \texttt{hfil} and \texttt{hfill} commands put in as much space as we need.
For example, look below.
\begin{center}
Left \hfill Right \\
Left \hfil Right \\
Left \hfill middle \hfill right
\end{center}

Likewise, there are commands called \texttt{vfil} and \texttt{vfill} that give as much vertical space as we need.
There are a couple of similar macros that put dots or rules in place of these spaces. These are called \texttt{dotfill} and \texttt{hrulefill}, respectively.
\begin{center}
Chapter 12 \dotfill 121
\end{center}

Another aspect of spacing is the boxes \TeX\ constantly uses form lines and so on.
For example, we already saw that we could put a box around any text using \texttt{framebox} \framebox{framebox}.
We can make a a plain box any time using \makebox[3in]{makebox}

\parbox{2in}{To get a paragraph of a certain size, use \texttt{parbox}. Not that the width of this is an obligatory argument.}

\end{description}

\section{Graphics}

Before we start, we should probably mention one or two ways of storing graphics that are not traditional
image formats. In particular, the EPS(Encapsulated PostScript) format is often used for storing images used in \TeX.
This is an old-fashioned way to do

to incorporate images into your document, you must first load the \texttt{graphicx}, After that we can use the famous \texttt{includegraphics} command to put in your image: viz\\
\begin{figure}[ht] % 'h' means put it here and 'ht' means that put it at top the and here. 'ht!' put it here now!
\centering
%\includegraphics[width=0.5\textwidth]{/path/to/picture.jpg}
%\caption{Who brought the cat?!}
\end{figure}

Note that from now on we will never refer to figures using any formulations such as ``in the figure below''. Instead, we always give the figure a name (number), and then refer to it using that.

there are many more packages to allow us to place our figures cleverly, attractively, etc., but we must load each
one separately. Note that some of the these packages are not compatible with features of other packages -- never load packages you do not need. For example, if we want to place a figure to one side of the page with text flowing around it, we use the \texttt{wrapfig} package.

%\begin{wrapfigure}{l}{2.54in}
%\includegraphics[width=2.5in]{/path/to/filname/cat.jpg}
%caption{Tijgertje's like to sleep}
%\label{fig:hanger}
%\end{wrapfigure}

Note that if we want to have figure numbers in the form section.figure, we can again use the \texttt{numberwithin} macro. We can also refer to %\ref{fig:hanger}
using a \texttt{ref} command. Also note that the figure number is not incremented until we use the \texttt{caption}
macro -- do not use your \texttt{label} macro until after that happens.

Another common requirement is to have two figures side by side. We could actually do that in an ordinary \texttt{figure} environment, but we would not get captions on each individual figure. Figure environment isn't about figures, but about floating elements. If we want captions then we must load another package: the \texttt{subfig} package.
%\begin{figure}[ht!]
%\begin{subfloat}[How it is not done.]
%{
%\includegraphics[.45\textwidth]{/path/to/the/image/cat.jpg}
%\label{fig:done}
%}
%\end{subfloat}
%\end{figure}
%
%\begin{figure}
%\begin{subfloat}[How it is done.]
%{
%\includegraphics[.45\textwidth]{/path/to/the/image/cat.jpg}
%}
%\end{subfloat}
%\end{figure}

Now we can refer to Figure \ref{fig:done} using the \texttt{label-ref} system as usual.

\section*{Tables}

There is another environment that works exactly like the \texttt{figure} environment, except that the object in it that the objects in it that have captions are labeled  ``Table''. That environment is, not surprisingly, called the \texttt{table} environment. In order to make an actual table we must invoke the \texttt{tabular} environment.
Table \ref{tab:pets} shows an example of some of the simplest features of the \texttt{tabular} environment.

\begin{table}[ht!] %difference between a table and a figure? Nothing other than the name.
\caption{A summary of pets}
\label{tab:pets}
\begin{tabular}{| l | c | p{2in} |}
Animal & Sociability & something and feeding \\
\hline
Dog & high & blah blah bblah \\
\hline
Cat & low & blah blah blah \\
\cline{2-3}
politician & \multicolumn{2}{c|}{Avoid this pet at all costs} \\
\hline
\end{tabular}
\end{table}

Note that the wrapfig package supplies a \texttt{wraptable} environment that lets tables float to one side or the other.

\section{References}

We often (always) need to make references to other sources in our documents. One way of handling those is to use
the \texttt{thebibliography} environment. The key macros associated with this are called \texttt{bibitem}
and \texttt{cite} command to actually refer to it. For example, this document contains some bogus references to Donald Knuth's work \cite{ref:knuth79}.

Note that most scholars create a database of references for the work they cite often. For this they use software called Bib\TeX. We will say no more about this.

\begin{thebibliography}{XX}

\bibitem{ref:knuth79} %when we refer to it by name we use this name.
Donald Knuth, \textbf{The \TeX book} Addison Wesley, New York, 1979.

\bibitem{ref:lamport69}
Leslie Lamport, \textbf{The \LaTeX\ Book}, Addison Wesley, New York, 1969.
\end{thebibliography}

\section{Programming}

\newcommand{\wsu}{Washington State University}

We can let \TeX\ do a lot of our work for us. For example, if there is some text that appears very often in our
paper, we can define our own macro to make that text.
We can use \texttt{newcommand} to create a new command that
will save us a bunch of time.

\newcommand{\tc}[1]{\textbackslash\texttt{#1}}

Sometimes we need to define commands that operate on some argument. For example we have needed to typeset the \TeX\ commands we were talking about, but we were too lazy to type all the stuff every time. Above we defined a \TeX\ command called \tc{tc} that does all that for us. This way we can talk about any command we like, such as \tc{numberwithin}, and get the output while only having to type the argument. Here is another.

\newcommand{\ltx}[2]{L\raisebox{#1}{a}\raisebox{#2}{}$\chi$}

This one makes a \LaTeX\ command that raises the a as much as we want: viz. \ltx{2pt}{-2pt}.

There is also a \tc{newenvironment} command that defines an environment that way we want it.

\section{Odds 'n ends}

\begin{enumerate}
\item We have seen that tilde is a special character. It is actually a non-breaking space. The hyphenation program is not allowed to hyphenate there.
\item If you need to give \TeX\ a hint about where a convenient place to hyphenate is, you cna use the \textbackslash- command.
\item The \texttt{verbatim} environment allows us to typeset text obeying all spaces, line breaks and so on. This is used particularly in typesetting computer code.
\end{enumerate}

\begin{verbatim}
function f(x)
f = 5
return f
\end{verbatim}

\end{document}


%---------------------------Aspect Ratio----------------------------------
\section{Aspect Ratio\label{s:tet-aspect-ratio}}

The aspect ratio of a tetrahedron $K$ is:
\[
\frac{L_{\max}}{2\sqrt{6}r}.
\]

\tetmetrictable{aspect ratio}%
{$1$}%                  Dimension
{$[1,3]$}%              Acceptable range
{$[1,DBL\_MAX]$}%       Normal range
{$[1,DBL\_MAX]$}%       Full range
{$1$}%                  Equilateral tet
{\cite{frey:00}}%        Citation
{v\_tet\_aspect\_ratio}%                            Verdict function name


\section{Generalization of Wright-Fisher model dynamics to non-fixed population size where the population size fluctuates randomly}
\subsection{Motivation}
Todo: Describe motivation - maybe add few sentences to motivate the research
\subsection{Results}
Let me introduce the specific model with three main assumptions:
\begin{enumerate}
\item
non-fixed population size,
\item
non-overlapping generations,
\item
random selection.
\end{enumerate}
The model is inspired directly by Wright-Fisher model without a fixed population size assumption, hence it can be considered as a generalization of the latter. Random selection feature corresponds to random mating assumption in Wright-Fisher model and means that in order to form a new generation each individual copies the state of a randomly selected parent, so no a priori defined fitness plays role except for the obvious rule that the rich gets richer.
It is difficult to observe non-overlapping generations in the nature, however this assumption plays a crucial role in the model so cannot be relaxed. One can think of a model without this limitation but deriving analytics results will be more challenging in such a setup. On the other hand the model should be not more difficult than it has to be and it might be that after appropriate scaling this feature has none or little effect on the quantitative output however may influence the qualitative outcome.
Further necessary assumptions are:
\begin{enumerate}
\item
Start with fixed number of $n_0$ individuals - each possess a different opinion
\item
Expected population of each generation stays positive i.e.
\begin{equation}
\mathbb{E}(\sum_{i=1}X_t(i))>0
\end{equation}
\item
Population of each generation is independent:
\begin{equation}
n_t\equiv\sum_{i=1}X_t(i)
\end{equation}
\end{enumerate}

In terms of graph theory language we start with a fixed setup - initial generation $0$ consists of $n_0$ nodes. Each node $x_i$ has a different colour $i$. Every successive generation $t$ consists of $n_t$ nodes. Each node inherits a colour of its parent - a uniformly selected node from the generation $t-1$.
Now one initial node $i$ (from generation $0$) is selected and a following martingale is considered
\begin{equation}
\{Y_t(i)=\frac{X_t(i)}{n_t}\}_{t\geq0}
\end{equation}
where $X_t(i)$ is a number of offsprings of node $i$ in generation $t$. For a given fixed $T>0$ we consider a following stopping time:
\begin{equation}
\tau=\begin{cases} t_0 &\qquad \mbox{ if } X_{t_0}(i)=0 \mbox{ for some time } t_0 \leq T \mbox{ (process dies until T) }\\ T &\qquad \mbox{ if } X_{T}(i)>0\end{cases}
\end{equation}
Next by applying Optional Stopping Theorem for martingale we have:
\begin{equation}
\mathbb{E}(Y_{\tau}(i))=\frac{1}{n_0}=\mbox{Pr}\{Y_T(i)>0\}\cdot\mathbb{E}(Y_{T}(i) | X_{T}(i)>0)
\end{equation}
$Pr\{Y_T(i)>0\}$ is a probability that the process will not die until time $T$. Hence, the number of colours at time $T$ is given by the formula:
\begin{equation}
\mathbb{E}(\mbox{\# colours at time } T)=\frac{1}{\mathbb{E}(Y_T(i) | X_T(i) >0)}
\end{equation}

In order to go further let’s switch a perspective.
The model can be alternatively viewed as a (possibly infinite) series of urns (non-overlapping generations) where the content of each urn (population of the generation) depends only on the content of the previous urn and the capacity of the current urn. Zeroth urn is filled with $n_0$ different balls. Then the process of populating the $t$-th urn is constrained with $n_t$ drawings with replacement from the previous $t-1$-th urn filled with $n_{t-1}$ labelled balls where each ball has exactly single label and some labels could be sticked to many balls. Thus multiplicity of labels/colours/languages can be approximated using mixed Poisson distribution in the following way:

Multiplicity of colours to observe in first generation $X_1$ is a discrete random variable which can be approximated by poisson distribution with $\lambda_1=\frac{n_1}{n_0}$, so $Pr\{X_1(i)=0\}=\exp(-\lambda_1)$ meaning that expected number of $\exp(-\frac{n_1}{n_0})$ colours will disappear from the system at the first time step.
In general multiplicity of colurs in the first urn is fully described by the Poisson distribution:
\begin{equation}
P(X_1(i)=k)=\mbox{exp}(-\lambda_1)\frac{\lambda_1^k}{k!}
\end{equation}
Let’s proceed to the content of the next urn. We start from stating an exact formula for conditional probability of $X_2(i)$ under condition that we know the value of $X_1(i)$ (i.e. multiplicity of $i$-th colour in the first urn is known apriori):
\begin{equation}
P\left(X_2(i)=l|X_1(i)=k\right)=\mbox{exp}\left(-k\lambda_2\right)\frac{\left(k\lambda_2\right)^l}{l!}
\end{equation}
where $\lambda_i\equiv\frac{n_i}{n_{i-1}}$ is a factor which corresponds to scaling of the population in the $i$-th step. The above formula is well defined only for $X_1(i)>0$. Let’s further assume that $P(X_t(i)=0|X_{t-1}(i)=0)\equiv1$ (so if a colour/a label is lost at some point, then it cannot be pushed back in the system in the future). Now we can calculate unconditional probability of $X_2(i)$ using the law of total probability:
\begin{equation*}
\begin{split}
P\left(X_2(i)=l\right) & =\sum_{k}P\left(X_2(i)=l|X_1(i)=k\right)P\left(X_1(i)=k\right) \\ & =\sum_{k=1}\mbox{exp}\left(-k\lambda_2\right)\frac{\left(k\lambda_2\right)^l}{l!}\mbox{exp}\left(-\lambda_1\right)\frac{\left(\lambda_1\right)^k}{k!} + \delta_{l0}\cdot\mbox{exp}\left(-\lambda_1\right)
\end{split}
\end{equation*}

This can be simplified by observing a fact that under the sum we have a sum of probability mass function of another Poisson distribution (except for mass of point $0$ and normalization factor). The computation is lengthy but straightforward and will be given in details only for $X_2(i)$ as further time steps involves the same method:
\begin{equation*}
\begin{split}
P\left(X_2(i)=0\right) & =\sum_{k}P\left(X_2(i)=0|X_1(i)=k\right)P\left(X_1(i)=k\right) \\ & =\sum_{k=1}\mbox{exp}\left(-k\lambda_2\right)\mbox{exp}\left(-\lambda_1\right)\frac{\left(\lambda_1\right)^k}{k!} + \mbox{exp}\left(-\lambda_1\right) \\ &
=\mbox{exp}\left(-\lambda_1\right)\left(\sum_{k=1}\frac{\left(\lambda_1\mbox{exp}\left(-\lambda_2\right)\right)^k}{k!} + 1 \right) \\ &
=\mbox{exp}\left(-\lambda_1\right)\left(\left(1-\mbox{exp}
\left(-\lambda_1\mbox{exp}\left(-\lambda_2\right)\right)\right)\mbox{exp}\left(\lambda_1
\mbox{exp}\left(-\lambda_2\right)\right)+1\right)
\end{split}
\end{equation*}

Finally, the calculation above gives the elegant exact formula for probability of extinction until $t=2$:
\begin{equation}
P(X_2(i)=0)=\mbox{exp}\left(-\lambda_1\left(1-\mbox{exp}\left(-\lambda_2\right)\right)\right)
\end{equation}
TODO: Now the missing part - please compute explicit the value of $P(X_2(i)=l>0)$.
Without that computation, all remaining results are not valid.
Please check \url{https://en.wikipedia.org/wiki/Poisson_distribution#Higher_moments} for further reference.

In fact the following exact formula is valid for any $t>1$:
\begin{equation}
P(X_t(i)=0)=\mbox{exp}\left(- \lambda_1 \left(\cdots\left(1-\mbox{exp}\left(- \lambda_{t-1}\left(1 - \mbox{exp}\left(-\lambda_{n_t}\right)\right)\right)\right)\cdots\right)\right)
\end{equation}

Proof of this formula is based on induction and very useful property explained above on the recurrent use of sum of probability mass function except mass point $0$ - that for any $a$, $b$ and $\left(x_k\right)_{k\in \mathbb{N}}$ being a collection of positive iterators, we have:
\begin{equation}
\sum_{x_k=1}\exp(a)^{x_k}\frac{(x_{k-1}b)^{x_k}}{x_k!}=
\exp(x_{k-1}b\exp(a))-1
\end{equation}

\begin{equation*}
\begin{split}
P\left(X_{t}(i)=0\right) & =\sum_{x_{t-1}}P\left(X_{t}(i)=0|X_{t-1}(i)=x_{t-1}\right)P\left(X_{t-1}(i)=x_{t-1}\right) \\ &
=\sum_{x_{t-1}}P\left(X_{t}(i)=0|X_{t-1}(i)=x_{t-1}\right)\cdots \sum_{x_{1}}P\left(X_{2}(i)=x_{2}|X_{1}(i)=x_{1}\right)P\left(X_{1}(i)=x_1\right)
\end{split}
\end{equation*}

\begin{equation*}
\begin{split}
& P\left(X_{t}(i)=0\right) \\ & = \sum_{x_{t-1}=1} \exp(-\lambda_{t})^{x_{t-1}}
\sum_{x_{t-2}=1} \exp(- \lambda_{t-1})^{x_{t-2}}\frac{\left(x_{t-2}\lambda_{t-1}\right)^{x_{t-1}}}{x_{t-1}!} \cdots \sum_{x_{1}=1} \exp( - \lambda_1)\frac{\lambda_1^{x_1}}{x_1!} + P\left(X_{t-1}(i)=0\right)
\end{split}
\end{equation*}


\chapter{Deep Learning and Large Scale Computing}
\section{Deep Learning and Large Scale Computing}
	\subsection{What is a learning algorithm?}

		A \textbf{machine learning algorithm} is an algorithm that is able to learn form data. But	what do we mean by learning? Mitchell (1997) provides the definition "A computer program is said to learn from experience $E$	with respect to some class of tasks	$T$	and performance measure	$P$, if its performance at tasks in	$T$, as measured by $P$, improves with experience $E$."Learning is not the task, but the means of attaining the ability to perform the task. The result of the learning is a model that is used to perform tasks.

		The machine learning algorithm grew out of work in \textbf{Artificial Intelligence (AI)} and take advantage of new capability of computing resources. \textbf{Deep learning} is a subset of machine learning.

	\subsection{Types of learning algorithm}

		 Machine learning algorithms can be broadly categorized as \textbf{unsupervised} or \textbf{supervised} or \textbf{Reinforcement learning algorithms
		 }	by what kind of experience they are allowed to have during the learning process.
	\begin{itemize}
		\item Unsupervised learning algorithms learn from a dataset containing many features, then learn useful properties of the structure of this dataset. E.g. K-means clustering
		\item Supervised learning algorithms learn from a dataset containing features, but each example is also associated with a label or target. E.g. classification , regression method to predict housing price
		\item Reinforcement learning algorithms interact with an environment, so there is feedback loop between the learning system and its experience. But it's out of the scope of this note.
	\end{itemize}
	Here we offer a simple example to illustrate the difference between the supervised and unsupervised learning algorithm.

	 Suppose we have a set of points in $\mathbb{R}^2: \{(x_1,y_1),(x_2,y_2),\dots,(x_n,y_n)\}$.
	 \begin{itemize}
	 	\item Ther's no more information about the points except their coordinates. We want to split them into several subsets (which is 'clustering') based on their coordinates. That's an unsupervised algorithm.
	 	\item The points are painted red or blue. We want to learn from the data about the reason why the point is red or blue. If given a new point, we can label it as red or blue according the points before. That's an example of classification, which is one kind of supervised learning algorithm.
	 \end{itemize}
	\section{Maximum Likelihood Estimation}
	As the process of machine learning is to estimate a set of parameters $\theta$ based on observations of examples X, \textbf{maximum likelihood} is often considered the preferred estimator to use for machine learning.

	\begin{itemize}
		\item Consider a set of $m$ examples $\mathbb X=\{\bm x^{(1)},...,\bm x^{(m)}\}$ drawn independently from the true but unknown data generating distribution $p_{data}(\bm x)$.
		\item Let $p_{model}(\bm x;\bm \theta)$ be a parametric family of probability distributions over the same space indexed by $\bm \theta$.
		\item The maximum likelihood estimator for $\bm \theta$ is then defined as
		\begin{equation*}
		\begin{split}
		\bm \theta_{ML} &= \arg \max_{\bm \theta}p_{model}(\mathbb X;\bm \theta) \\
		&=\arg \max_{\bm \theta}\prod_{\bm x \in \mathbb X} p_{model}(\bm x;\bm \theta)\\
		&=\arg \max_{\bm \theta}\sum_{\bm x \in \mathbb X} \log p_{model}(\bm x;\bm \theta)\\
		\end{split}
		\end{equation*}
	\end{itemize}

	\section{Input data}
	Previously observed data in the experience can be split to three categories:
	\begin{itemize}
		\item Training data: used to train the model
		\item Validation data: used to adjust the model
		\item Test data: used to evaluate the generalization of the model
	\end{itemize}
	Training data and validation data are usually split from a large observed data set. The ratio between training data and validation data is commonly 4:1 or 9:1.
	\subsection{Capacity and Performance}

	The capacity of the learning algorithms can be underfitting, appropriate capacity and overfitting. Underfitting occurs when the model is not able to obtain a sufficiently low error value on the training set. Overfitting occurs when the gap between the training error and test error is too large.

	The factors determining the performance of the machine learning algorithms are:
	\begin{itemize}
		\item Test error (final error of the generated model) The error is calculated by a cost function based on the test data set
		\item The gap between training and validation error
	\end{itemize}
	The central challenge in machine learning is that we must perform well on new, previously unseen inputs, not just those on which our model was trained. So Machine learning algorithms indirectly minimize the test error. Regularization is the modification of machine learning algorithms to reduce validation error but not the training error in order to avoid overfitting.

\section{Neural Network}
According to Maureen Caudill{\color{red} LZ:???} neural network is a computing system made up of a number of simple, highly interconnected processing elements, which process information by their dynamic state response to external inputs.

{\bf Activation function}. In a neural network, an activation function of a node determines the output of that node for a given input. Inspired by biological neurons, an activation function basically works as a switch that can set the neuron on "ON" or "OFF".

The sigmoid function is a common choice for activation function. It is defined by
\begin{equation}
\sigma(t) = \frac{1}{1+e^{-t}}.
\end{equation}
The sigmoid function is monotonically increasing over $\mathbb{R}$ and is infinitely-differentiable. It has limit 0 and 1 as $t$ approaches $-\infty$ and $+\infty$, respectively.
%The graph of $\sigma(t)$ is shown in Figure \ref{fsig}.

A useful property of $\sigma(t)$ is that its derivative can be expressed by the function itself.
{\color{red} LZ:Add graph of sigmoid}
\begin{lemma}
\label{lsig}
$\sigma'(t) = \sigma(t)(1-\sigma(t))$.
\end{lemma}

Besides the sigmoid function, commonly used activation functions are:

\begin{enumerate}
\item
Binary step function: $f(t) = \mathbbm{1}_{t\ge 0}$.
\item
Hyperbolic tangent function: $f(t) = \tanh(t)=\frac{2}{1+e^{2t}}-1$.
\item
Arctan function: $f(t) = \tan^{-1}(t)$.
\item
Rectified linear unit (ReLU) $f(t) = \max\{0, t\}$.
\end{enumerate}

A \textit{neural network} is a network model with non-linear unites on its hidden layers.

{\bf Hyper-parameters.} Most machine learning algorithms involve hyper-parameters which are variables set before actually optimizing the model's parameters. For a neural network, hyper-parameters include the depth of the network $d$, the width of each layer $n$, the regularization parameter $\lambda$, the learning rate for gradient descent $r$, and the initial values for weight matrices $(\bm{W_1}(0),...,\bm{W_d}(0))$ and biases $(\bm{b_1}(0),...,\bm{b_d}(0))$. {\color{red} LZ:???}There is no theorem stating how to choose the best hyper-parameters, we now choose them merely by experience and luck.

\section{Back Propagation}

{\bf Training a neural network model}. Suppose we have $m$ labeled training examples
$$\{(\bm{x^1, y^1}),...,(\bm{x^m, y^m})\}.$$ Let $\sigma_k$, $\bm{W_k}$, $\bm{b_k}$, be the activation function, weight matrix, bias vector, resp. for the $k_{th}$ hidden layer, $k=1,2,...,d-1$. Let $\sigma_d$, $\bm{W_d}$ and $\bm{b_d}$ be the activation function, weight matrix and bias vector for the output layer.

The neural network model can be defined recursively as follows:
\begin{equation}
\label{enn}
\aligned
\bm{z_1}=&\bm{W_1^Tx}+\bm{b_1}\\
\bm{a_1}=&\sigma_1(\bm{z_1})\\
\bm{z_k}=&\bm{W_k^T}\bm{a_{k-1}}+\bm{b_k}\\
\bm{a_k}=&\sigma_k(\bm{z_k}), k=2,...,d.
\endaligned
\end{equation}
Here we use the convention $\sigma(x_1,...,x_n) = (\sigma(x_1),...,\sigma(x_n))$ and call $\bm{z_k}$ weighted input and $\bm{a_k}$ weighted output hence $\bm{a_d}(\bm{x})$ is the output from the neural network given $\bm{x}$ as the input data.

{\bf Cost function}.
The error of a neural network with respect to a sample $(\bm{x^j, y^j})$ is defined by cost (loss) function. One way is to use the quadratic loss function
\begin{equation}
L(\bm{x^j, y^j}) =\|\bm{y^j} - \bm{a_d}(\bm{x^j})\|^2+\lambda \sum_{i=1}^d ||\bm{W_i}||_F^2,
\end{equation}
where the second term is the regularization term to avoid overfitting and $\lambda$ is the regularization parameter.{\color{red} LZ: remove regularization?}

An alternative way is to use the cross-entropy loss function
\begin{equation}
L(\bm{x^j, y^j}) = -[\bm{y^j} \ln (\bm{a_d}(\bm{x^j}))+(1-\bm{y^j}) \ln (1-\bm{a_d}(\bm{x^j}))]+\lambda \sum_{i=1}^d ||\bm{W_i}||_F^2,
\end{equation}
{\color{red} LZ: remove regularization?}

The goal of training a neural network model is to find parameters $(\bm{W_1},...,\bm{W_d},\bm{b_1},..,\bm{b_d})$ such that the total loss
\begin{equation}
\label{etotalloss}
L_{total} = \frac{1}{m} \sum_{j=1}^m L(\bm{x^j, y^j})
\end{equation}
is as small as possible.

{\bf Back propagation}.
The parameters are adjusted using the following process called \textit{back-propagation} w.r.t. $L_{total}$.

There is an intuition to introduce the error $\delta_l^j$.
Suppose there is a very small change $\Delta z_l^j$ added to the weighted input to the $j_{th}$ neuron in the $l_{th}$ layer, after the forward propagation, the final cost function changes by $\frac{\partial}{\partial \bm{z_l^j}}L_{total} \Delta z_l^j$. If the partial derivative $\frac{\partial}{\partial \bm{z_l^j}}L_{total}$ is large, we can choose $\Delta z_l^j$ with the different sign to decrease the cost function. Otherwise if the partial derivative is near zero, it's difficult to change the cost function. Therefore we use $\delta_l^j = \frac{\partial}{\partial \bm{z_l^j}}L_{total}$ to denote the error of the $j_{th}$ neuron in the $l_{th}$ layer.
First  we compute the error in the last layer.
{\color{red}LZ: bold sigma}

\begin{equation}
\aligned
\bm{\delta_d^j} =& \frac{\partial}{\partial z_d^j}L_{total}\\
=& \sum_{k} \frac{\partial L_{total}}{\partial a_k^j}\frac{\partial a_k^j}{\partial z_d^j}\\
=& \frac{\partial L_{total}}{\partial a_d^j} \sigma'(z_d^j),\\
\bm{\delta_d} =& \nabla_{a_d} L_{total}\odot \sigma'(z_d).
\endaligned
\end{equation}
Here $\odot$ is the Hadamard product meaning component-wise multiplication of two vectors. In the third equality results from that $a_d^k$ relies only on the weighted input $z_d^k$.

Then we compute the error in the $l_{th}$ layer, $l=1,2,...,d-1$.
\begin{equation}
\aligned
\delta_l^j =& \frac{\partial}{\partial {z_l^j}}L_{total}\\
=& \sum_{k} \frac{\partial L_{total}}{\partial z_{l+1}^k}\frac{\partial z_{l+1}^k}{\partial z_l^j}\\
=& \sum_{k} \frac{\partial z_{l+1}^k}{\partial z_l^j} \bm\delta_{l+1}^k\\
=& \sum_{k} W_{l+1}^{kj} \delta_{l+1}^k \sigma'(z_l^j),\\
\bm{\delta_l} =& ((W_{l+1})^T \bm\delta_{l+1} \odot \sigma'(z_l).
\endaligned
\end{equation}

The computation of $\bm{\delta^k}$ depends on the knowledge of $\bm{\delta^{k+1}}$, and here comes the name back-propagation. The gradient of the loss function with respect to each parameter can be computed as follows: for each $k=1,...,d$ we have
\begin{equation}
\label{ebpparam}
\aligned
\frac{\partial}{\partial W_l^{jk}}L_{total}
=& \sum_{i} \frac{\partial L_{total}}{\partial z_l^i}\frac{\partial z_l^i}{\partial W_l^{jk}}\\
=& \frac{\partial L_{total}}{\partial z_l^j}\frac{\partial z_l^j}{\partial W_l^{jk}}\\
=& \delta_l^j a_{l-1}^k,\\
\frac{\partial}{\partial b_l^{j}}L_{total}
=& \sum_{i} \frac{\partial L_{total}}{\partial z_l^i}\frac{\partial z_l^i}{\partial b_l^{j}}\\
=& \frac{\partial L_{total}}{\partial z_l^j}\frac{\partial z_l^j}{\partial b_l^{j}}\\
=& \delta_l^j.
\endaligned
\end{equation}
{\color{red}LZ: matrix form:
\begin{align*}
    \frac{\partial L_{total}}{\partial \bm W_l} =& \bm{\delta_l}\bm a_{l-1}\\
    \frac{\partial L_{total}}{\partial \bm b_l} =& \bm{\delta_l}
\end{align*}}

With the gradients computed, we use the following update rule to adjust the parameters:
\begin{equation}
\label{ebpup}
\aligned
W_l^{jk} =& W_l^{jk} - r\frac{\partial L_{total}}{\partial W_l^{jk}}\\
b_l^{j} =& b_l^{j} - r\frac{\partial L_{total}}{\partial b_l^{j}},
\endaligned
\end{equation}
where r is the learning rate, for $l=1,...,d$. The learning rate r and the regularization parameter $\lambda$ are hyper parameters, we still don't know why and how to choose them.{\color{red}LZ: $\lambda$? overstatement?} Therefore we normally choose them by experience and manually parameter tuning to decide the optimal hyper parameters.


\subsection{Rings}\label{subsec:rings}

\begin{definition}\label{def:ring}
  A \term{ring} is a \hyperref[def:semiring]{semiring} with additive inverses. More precisely, this means that the additive monoid is a group.

  As for semirings, rings can also be nonunital, with \hyperref[def:semiring_ideal]{ring ideals} being the main example.

  Rings have the following metamathematical properties:
  \begin{thmenum}
    \thmitem{def:ring/theory} We can construct a \hyperref[def:first_order_theory]{first-order theory} for rings by adding a unary functional symbol \( - \) and the involution axiom \eqref{eq:def:group/theory/inverse_axiom} to the \hyperref[def:semiring/theory]{theory of semirings}.

    \thmitem{def:ring/homomorphism} A \hyperref[def:first_order_homomorphism]{first-order homomorphism} between the rings \( R \) and \( T \) is a \hyperref[def:semiring/homomorphism]{semiring homomorphism} \( \varphi: R \to T \) that additionally preserves additive inverses.

    As shown in \fullref{thm:group_homomorphism_single_condition}, this condition is not only redundant, but the structure of a ring rather than semiring also automatically implies that \( \varphi(0_R) = 0_S \).

    \thmitem{def:ring/submodel} The set \( A \subseteq R \) is a \hyperref[thm:substructure_is_model]{submodel} of \( R \) if it is both a \hyperref[def:semiring]{sub-semiring} of \( R \) and an additive submonoid of \( R \).

    As a consequence of \fullref{thm:positive_formulas_preserved_under_homomorphism}, the image of a ring homomorphism is a subring of its range.

    \thmitem{def:ring/trivial} The \hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} ring is the \hyperref[def:pointed_set/trivial]{trivial pointed set} \( \set{ 0 } \).

    \thmitem{def:ring/commutative} If multiplication is commutative, we call the ring itself \term{commutative}. Unless multiplication corresponds to function composition, most rings we will encounter will be commutative.

    \thmitem{def:ring/category} The corresponding \hyperref[def:category_of_small_first_order_models]{category of \( \mscrU \)-small models} \( \ucat{Ring} \) is \hyperref[def:concrete_category]{concrete} over \hyperref[def:monoid]{\( \ucat{SRing} \)}. We denote the category of commutative rings by \( \cat{CRing} \).

    Unlike the category \hyperref[def:group/category]{\( \cat{Grp} \)} of groups, \( \cat{Ring} \) is not as well-behaved. Nevertheless, kernels and quotients of rings are commonly established concepts.

    The category of unital rings does not have a zero object, but the category of nonunital rings does, and we will sometimes consider nonunital ring homomorphisms between unital rings. That is, ring homomorphisms that may not preserve the multiplicative identity.

    \thmitem{def:ring/kernel} The \term{kernel} of a ring homomorphism \( \varphi: R \to T \) is simply its \hyperref[def:zero_locus]{zero locus} \( \varphi^{-1}(0_S) \). This is precisely the kernel of the additive group in the sense of \fullref{def:group/kernel}, and the \hyperref[def:zero_morphisms/cokernel]{categorical kernel} in the category of nonunital rings.

    Furthermore, \( \ker \varphi \) is an ideal of \( R \) because, if \( x \in \ker \varphi \),
    \begin{equation*}
      \varphi(xy)
      =
      \varphi(x) \varphi(y)
      =
      0_S \varphi(y)
      =
      0_S,
    \end{equation*}
    and thus \( xy \in \ker \varphi \).

    Despite being categorical kernels only in the category of nonunital rings, the kernel is defined and used mainly for unital ring homomorphism.

    \thmitem{def:ring/quotient} The \hyperref[def:zero_morphisms/cokernel]{categorical cokernel} of homomorphism \( \varphi: R \to T \) in the category of nonunital rings is, similarly to the case for groups in \fullref{def:group/quotient}, a partition of \( T \) induced by the image of \( \varphi \).

    This is not merely the cokernel \( T / \img \varphi \) of the additive group, however. Multiplication induces an additional restriction on congruences: \( x \cong x' \) and \( y \cong y' \) together imply \( x y \cong x' y' \). Hence, \( [x][y] = [xy] \).  Denote the coset \( [0_S] \) by \( I \). We have \( I[x] = [0x] = I \), therefore the cokernel inherits absorption from \( T \).

    Additive subgroups of \( T \) that absorb multiplication are precisely the \hyperref[def:semiring_ideal]{two-sided ideals} of \( T \). Hence, \( I \) is the ideal generated by \( \img \varphi \). From the general case for groups it follows that quotient ring cosets have the form \( x + I \).

    Finally, given an ideal \( I \) of an arbitrary ring \( R \), we can define the \term{quotient ring} \( R / I \) as the cokernel of the inclusion \( \iota: I \to R \). That is, \( R / I \) consists of the cosets \( x + I \) for \( x \in R \). In practice, quotients are conveniently characterized by \fullref{thm:quotient_algebra_universal_property}.

    Somewhat similarly to \fullref{thm:def:group/kernel_cokernel_compatibility} for groups, the kernel \( \ker \pi \) of the canonical projection \( \pi(x) \coloneqq x + I \) is the ideal \( I \) itself.

    Despite being \hyperref[def:zero_morphisms/cokernel]{categorical cokernel} only in the category of nonunital rings, the quotient \( R / I \) is defined and used mainly for unital rings.

    Fortunately, for unital ring \( R \), the quotient \( R / I \) is also unital. The projection morphism is an epimorphism by \fullref{thm:equalizer_invertibility}, and hence \( R / I \) is a \hyperref[def:subobject_and_quotient]{categorical quotient object}.

    \thmitem{def:ring/simple} Analogously to \hyperref[def:group/simple]{simple groups}, if the only proper \hyperref[def:semiring_ideal]{ideal} of \( R \) is the \hyperref[def:ring/trivial]{trivial ideal} \( \set{ 0_R } \), we say that \( R \) is a \term{simple ring}.

    The trivial ring itself is not simple, because it has no proper ideals.
  \end{thmenum}
\end{definition}

\begin{proposition}\label{thm:quotient_equality_via_difference}
  Given an \hyperref[def:semiring_ideal]{ideal} \( I \) in a \hyperref[def:ring]{ring} \( R \), we have \( x + I = y + I \) if and only if \( x - y \in I \).
\end{proposition}
\begin{proof}
  Trivial.
\end{proof}

\begin{proposition}\label{thm:ring_of_integers_modulo}
  For a positive integer \( n > 1 \), we extend the group \hyperref[thm:group_of_integers_modulo]{\( \BbbZ_n \)} of integers modulo \( n \) with the operation
  \begin{equation*}
    x \odot y \coloneqq \rem(xy, n).
  \end{equation*}

  Then \( \BbbZ_n \) is a \hyperref[def:ring/commutative]{commutative ring} called the \term{ring of integers modulo} \( n \).
\end{proposition}
\begin{proof}
  Note that
  \begin{balign*}
    &\phantom{{}\cong{}} \rem(x, n) \rem(y, n)
    &\cong \pmod n \\ &\cong
    (x - n \quot(x, n)) (y - n \quot(y, n))
    &\cong \pmod n \\ &\cong
    xy - n \quot(x, n) - n \quot(y, n) + n^2 \quot(x, n) \quot(y, n)
    &\cong \pmod n \\ &\cong
    xy.
  \end{balign*}

  The proof that multiplication in \( \BbbZ_n \) is associative, unital and commutative becomes trivial.

  We will prove that multiplication distributes over addition. Fix \( x, y, z \in \BbbZ_n \). We have
  \begin{balign*}
    (x \oplus y) \odot z
     & =
    \rem((x \oplus y) z, n)
    =    \\ &=
    \rem(\rem(x + y, n) z, n)
    =    \\ &=
    \rem((x + y - n \quot(x + y, n)) z, n)
    =    \\ &=
    \rem((x + y)z, n).
  \end{balign*}
  and
  \begin{balign*}
    (x \odot z) \oplus (y \odot z)
     & =
    \rem([(x \odot z) + (y \odot z)], n)
    =    \\ &=
    \rem([xz - n \quot(xz, n) + yz - n \quot(yz, n)], n)
    =    \\ &=
    \rem(xz + yz, n)
    =    \\ &=
    \rem((x + y)z, n).
  \end{balign*}

  Hence,
  \begin{equation*}
    (x \oplus y) \odot z = (x \odot z) \oplus (y \odot z).
  \end{equation*}
\end{proof}

\begin{proposition}\label{thm:ring_characteristic_homomorphism}
  Similarly to how \( \BbbN \) is an \hyperref[def:universal_objects/initial]{initial object} in the category \hyperref[def:semiring/category]{\( \cat{SRing} \)} of semirings, \( \BbbZ \) is an initial object in the category \hyperref[def:ring/category]{\( \cat{Ring} \)} of rings.
\end{proposition}
\begin{proof}
  Follows from \fullref{thm:semiring_characteristic_homomorphism} with the addition of \( (-n)x = -nx \).
\end{proof}

\begin{definition}\label{def:ring_characteristic}\mimprovised
  We define the \term{characteristic} \( \op{char}(R) \) of a ring \( R \) via the following equivalent definitions:
  \begin{thmenum}
    \thmitem{def:ring_characteristic/embedding} \( \op{char}(R) \) is the unique nonnegative integer \( n \) for which \( \BbbZ_n \) can be embedded into \( R \). That is,
    \begin{equation*}
      \BbbZ_n \cong \BbbZ / \ker \iota,
    \end{equation*}
    where \( \iota \) is the homomorphism from the integers defined via \eqref{eq:thm:ring_characteristic_homomorphism}.

    We use here that \( \BbbZ_0 \) is the \hyperref[def:ring/trivial]{trivial ring}.

    \thmitem{def:ring_characteristic/direct} \( \op{char}(R) \) is the \hyperref[def:group_order]{order} of the additive group of \( R \) and, if it exists, and \( 0 \) otherwise.

    That is, \( \op{char}(R) \) is the smallest positive integer \( n \) such that \( n \cdot 1_R = 0_R \) and \( \op{char}(R) = 0 \) if \( 0_R \) cannot be obtained in this way.
  \end{thmenum}
\end{definition}
\begin{defproof}
  \EquivalenceSubProof{def:ring_characteristic/homomorphism}{def:ring_characteristic/direct} Let \( n \) be such that
  \begin{equation*}
    n \BbbZ = \ker\iota.
  \end{equation*}

  In particular, \( \iota(0) = \iota(n) \).

  If \( n = 0 \), \( \ker\iota \) is a trivial group and \( \iota \) is an embedding. Then there cannot exist a positive integer \( n \) such that
  \begin{equation*}
    n \cdot 1_R = 0_R.
  \end{equation*}

  Otherwise, \( n \) is the smallest positive integer such that
  \begin{equation*}
    n \cdot 1_R = 0 \cdot 1_R = 0_R.
  \end{equation*}
\end{defproof}

\begin{proposition}\label{thm:ring_embedding_preserves_characterstic}
  If \( \varphi: R \to S \) is a \hyperref[def:ring/homomorphism]{ring embedding}, then \( S \) inherits its \hyperref[def:semiring_characteristic]{characteristics} from \( R \).
\end{proposition}
\begin{proof}
  First suppose that \( R \) has positive characteristic \( n \). Then \( n \cdot 1_R = 0_R \), which implies \( n \cdot \varphi(1_R) = \varphi(0_R) \), hence \( \op{char}(T) \leq n \). But \( \varphi \) is an embedding, hence if \( k \cdot 1_R \neq 0_R \), then
  \begin{equation*}
    k \cdot \varphi(1_R) \neq \varphi(0_R).
  \end{equation*}

  This implies that \( \op{char}(S) \geq \op{char}(R) \), which in turn shows that \( \op{char}(S) = \op{char}(R) \).

  If \( R \) has characteristic zero, then \( \iota: \BbbN \to R \) is an embedding and thus \( \varphi \bincirc \iota: \BbbN \to S \) is also an embedding. It is unique as shown in \fullref{thm:ring_characteristic_homomorphism}. Therefore, \( S \) also has characteristic zero.
\end{proof}

\begin{example}\label{ex:def:ring_characteristic}
  The following are examples of \hyperref[def:ring_characteristic]{ring characteristics}:
  \begin{thmenum}
    \thmitem{ex:def:ring_characteristic/natural_numbers} The \hyperref[def:set_of_integers]{integers} \( \BbbZ \) have characteristic \( \op{char}(\BbbZ) = 0 \) because \( \iota \) is an isomorphism. Consequently, by \fullref{thm:ring_embedding_preserves_characterstic}, any superring of \( \BbbZ \) has characteristic zero, most notably the fields \( \BbbQ \), \( \BbbR \) and \( \BbbC \).

    \thmitem{ex:def:ring_characteristic/integers_modulo} The ring \hyperref[thm:ring_of_integers_modulo]{\( \BbbZ_n \)} of integers modulo \( n \) has characteristic \( \op{char}(\BbbZ_n) = n \) because of \fullref{thm:integers_modulo_isomorphic_to_quotient_group}.

    \thmitem{ex:def:ring_characteristic/polynomial_ring} An \hyperref[def:algebra_over_semiring]{algebra} \( M \) over a nontrivial commutative unital ring \( R \) has the same characteristic as \( R \) because of the canonical embedding of \( R \) in \( M \). In particular, the \hyperref[def:polynomial_algebra]{polynomial ring} \( R[X] \) has the same characteristic as their ring.
  \end{thmenum}
\end{example}

\begin{proposition}\label{thm:grothendieck_semiring_completion}\mcite[80]{OpenLogicFull}
  The \hyperref[def:monoid_grothendieck_completion]{Grothendieck completion} \( \overline{R} \) of the additive monoid of a \hyperref[def:semiring]{semiring} \( R \) becomes a \hyperref[def:ring]{ring} with the operation
  \begin{equation*}
    [(a, b)] \odot [(c, d)] \coloneqq [(ac + bd, ad + bc)].
  \end{equation*}

  This definition is motivated in the proof of \fullref{thm:grothendieck_semiring_completion_universal_property}.
\end{proposition}
\begin{proof}
  Multiplication on \( R \) does not depend on the representative of the equivalence class. Indeed, let \( (a, b) \sim (a', b') \) and \( (c, d) \sim (c', d') \). Then there exist \( u \) and \( v \) such that
  \begin{align*}
    a + b' + u &= a' + b + u, \\
    c + d' + v &= c' + d + v.
  \end{align*}

  Then
  \begin{align*}
    &\phantom{{}={}}
    \hi{ac} + b'c + uc + a'd + \hi{bd} + ud + a'c + \hi{a'd'} + a'v + \hi{b'c'} + b'd + b'v
    = \\ &=
    (a + b' + u)c + (a' + b + u)d + a'(c + d' + v) + b'(c' + d + v)
    = \\ &=
    (a' + b + u)c + (a + b' + u)d + a'(c' + d + v) + b'(c + d' + v)
    = \\ &=
    a'c + \hi{bc} + uc + \hi{ad} + b'd + ud + \hi{a'c'} + a'd + a'v + b'c + \hi{b'd'} + b'v.
  \end{align*}

  Therefore,
  \begin{equation*}
    (a \cdot c + b \cdot d, a \cdot d + b \cdot c) \sim (a' \cdot c' + b' \cdot d', a' \cdot d' + b' \cdot c').
  \end{equation*}

  Associativity and distributivity in \( \overline{R} \) are inherited from \( R \).
\end{proof}

\begin{theorem}[Grothendieck semiring completion universal property]\label{thm:grothendieck_semiring_completion_universal_property}
  The \hyperref[thm:grothendieck_semiring_completion]{Grothendieck completion} \( \overline{R} \) of a semiring \( R \) satisfies the following \hyperref[rem:universal_mapping_property]{universal mapping property}:
  \begin{displayquote}
    For every ring \( T \) and every semiring homomorphism \( \varphi: R \to T \), there exists a unique ring homomorphism \( \widetilde{\varphi}: \overline{R} \to T \) such that the following diagram commutes:
    \begin{equation}\label{eq:thm:grothendieck_semiring_completion_universal_property/diagram}
      \begin{aligned}
        \includegraphics[page=1]{output/thm__semiring_grothendieck_completion_universal_property.pdf}
      \end{aligned}
    \end{equation}
  \end{displayquote}

  Via \fullref{rem:universal_mapping_property}, \( \overline{\anon} \) becomes \hyperref[def:category_adjunction]{left adjoint} to the \hyperref[def:concrete_category]{forgetful functor}
  \begin{equation*}
    U: \cat{CRing} \to \cat{CSRing}.
  \end{equation*}

  Compare this result to \fullref{thm:grothendieck_monoid_completion_universal_property}.
\end{theorem}
\begin{proof}
  \Fullref{thm:grothendieck_monoid_completion_universal_property} suggests the definition
  \begin{equation*}
    \overline{\varphi}([(a, b)]) \coloneqq \varphi(a) - \varphi(b).
  \end{equation*}

  We must only show that \( \overline{\varphi} \) is a ring homomorphism. Clearly
  \begin{equation*}
    \overline{\varphi}([(1, 0)]) = \varphi(1) - \varphi(0),
  \end{equation*}
  which implies that \( \varphi \) preserves multiplicative identities. Also,
  \begin{balign*}
    \overline{\varphi}\parens[\Big]{ [(a, b)] \odot [(c, d)] }
    &=
    \overline{\varphi}\parens[\Big]{ [(a \cdot b + c \cdot d, a \cdot d + b \cdot c)] }
    = \\ &=
    \varphi(a \cdot b + c \cdot d) - \varphi(a \cdot d + b \cdot c)
    = \\ &=
    \varphi(c) \parens[\Big]{ \varphi(d) - \varphi(b) } - \varphi(a) \parens[\Big]{ \varphi(d) - \varphi(b) }
    = \\ &=
    \parens[\Big]{ \varphi(c) - \varphi(a) } \parens[\Big]{ \varphi(d) - \varphi(b) }
    = \\ &=
    \overline{\varphi}\parens[\Big]{ [(a, c)] } \overline{\varphi}\parens[\Big]{ [(b, d)] }.
  \end{balign*}
\end{proof}

\begin{proposition}\label{thm:def:grothendieck_semiring_completion}
  The \hyperref[thm:grothendieck_semiring_completion]{Grothendieck completion} \( \overline{R} \) of a semiring \( R \) satisfies the following basic properties:
  \begin{thmenum}
    \thmitem{thm:def:grothendieck_semiring_completion/commutative} If \( R \) is commutative, so is \( \overline{R} \).
    \thmitem{thm:def:grothendieck_semiring_completion/entire} If \( R \) is \hyperref[def:divisibility/zero]{entire}, so is \( \overline{R} \).
  \end{thmenum}
\end{proposition}
\begin{proof}
  \SubProofOf{thm:def:grothendieck_semiring_completion/commutative} This is clear from the definition of multiplication.
  \SubProofOf{thm:def:grothendieck_semiring_completion/entire} Suppose that
  \begin{equation*}
    \underbrace{[(a, b)] \cdot [(c, d)]}_{[(ac + bd, ad + bc)]} = [(0, 0)]
  \end{equation*}

  Then there exists an element \( u \) in \( R \) such that
  \begin{equation*}
    (ac + bd) + 0 + u = 0 + (ad + bc) + u.
  \end{equation*}

  Suppose that \( d = c + e \). Then
  \begin{equation*}
    ac + b(c + e) = a(c + e) + bc
  \end{equation*}
  and
  \begin{equation*}
    (ac + bc) + be = (ac + bc) + ae.
  \end{equation*}

  Cancelling \( e \), we obtain that \( a = b \). But \( [(a, b)] = [(0, 0)] \).
\end{proof}

\begin{definition}\label{def:ring_commutator}
  Let \( R \) be an arbitrary ring. We define the \term{commutator} of the elements \( x \) and \( y \) as
  \begin{equation*}
    [x, y] \coloneqq xy - yx.
  \end{equation*}

  The \term{commutator ideal} \( [R, R] \) of \( R \) is the two-sided ideal \hyperref[def:generated_ring_ideal]{generated} by all the commutators in \( G \).
\end{definition}

\begin{theorem}[Ring abelianization universal property]\label{thm:ring_abelianization_universal_property}\mcite[prop. 7.4]{Knapp2016BasicAlgebra}
  The quotient \( R / [R, R] \) of a ring \( R \) by its commutator ideal \( [R, R] \) is a commutative ring, which we call the \term{abelianization} of \( R \), and satisfies the following \hyperref[rem:universal_mapping_property]{universal mapping property}:
  \begin{displayquote}
    For every commutative ring \( T \) and every ring homomorphism \( \varphi: R \to T \), \( \varphi \) \hyperref[def:factors_through]{uniquely factors through} \( R / [R, R] \). That is, there exists a unique ring homomorphism \( \widetilde{\varphi}: R / [R, R] \to T \) such that the following diagram commutes:
    \begin{equation}\label{eq:thm:ring_abelianization_universal_property/diagram}
      \begin{aligned}
        \includegraphics[page=1]{output/thm__ring_abelianization_universal_property.pdf}
      \end{aligned}
    \end{equation}
  \end{displayquote}

  Via \fullref{rem:universal_mapping_property}, the abelianization functor becomes \hyperref[def:category_adjunction]{left adjoint} to the \hyperref[def:concrete_category]{forgetful functor}
  \begin{equation*}
    U: \cat{CRing} \to \cat{Ring}.
  \end{equation*}

  Compare this result to \fullref{thm:group_abelianization_universal_property}.
\end{theorem}
\begin{proof}
  This is a refinement of \fullref{thm:group_abelianization_universal_property}, and we only need to show that \( R / [R, R] \) is a commutative ring. For \( x \) and \( y \) in \( R \), since \( yx - xy \in I \), we have
  \begin{equation*}
    (x + I) (y + I)
    =
    (xy + I)
    =
    (xy + yx - xy + I)
    =
    (yx + I)
    =
    (y + I) (x + I).
  \end{equation*}
\end{proof}

\begin{definition}\label{def:multiplicative_set_in_semiring}\mcite[428]{Knapp2016BasicAlgebra}
  We call the subset of the semiring \( R \) a \term{multiplicative set} if it contains \( 1_R \) and, furthermore, it is closed under multiplication.
\end{definition}

\begin{proposition}\label{thm:complement_of_prime_ideal}
  The \hyperref[def:semiring_ideal]{ideal} \( P \) in the \hyperref[def:semiring/commutative]{commutative semiring} \( R \) is \hyperref[def:semiring_ideal/prime]{prime} if and only if \( R \setminus P \) is a \hyperref[def:multiplicative_set_in_semiring]{multiplicative set}.

  Not all multiplicative sets are obtained as complements of prime ideals --- see \fullref{ex:def:ring_localization/powers_of_two}.
\end{proposition}
\begin{proof}
  By \fullref{thm:def:semiring_ideal/ideal_containing_unit}, \( P \) is a proper ideal if and only if \( 1_R \in R \setminus P \).

  By \fullref{thm:def:semiring_ideal/prime_pointwise}, \( P \) is prime if and only if \( x, y \in R \setminus P \) implies \( xy \in R \setminus P \).
\end{proof}

\begin{definition}\label{def:ring_localization}\mcite[428]{Knapp2016BasicAlgebra}
  Let \( R \) be a \hyperref[def:ring/commutative]{commutative ring} and let \( S \subseteq R \) be a \hyperref[def:multiplicative_set_in_semiring]{multiplicative set}.

  Define the equivalence relation \( (r, s) \sim (r', s') \) on \( R \times S \) to hold if and only if there exists some \( u \in S \) such that \( u r s' = u r' s \).

  Consider the set
  \begin{equation*}
    S^{-1} R \coloneqq R \times S / \sim,
  \end{equation*}
  whose cosets we will denote by \( \ifrac r s \) rather than \( [(r, s)] \).

  Define on \( S^{-1} R \) the operations
  \begin{align*}
    \frac a b + \frac c d     &\coloneqq \frac {a d + b c} {b d}, \\
    \frac a b \cdot \frac c d &\coloneqq \frac {a c} {b d},
  \end{align*}
  and the canonical inclusion
  \begin{equation*}
    \begin{aligned}
      &\iota: R \to S^{-1} R \\
      &\iota(r) \coloneqq \frac r {1_R}.
    \end{aligned}
  \end{equation*}

  This ring is called the \term{localization} of \( R \) with respect to \( A \); we denote it by \( S^{-1} R \). In case \( S \) is the \hyperref[thm:boolean_algebra_of_subsets/complement]{complement} of a \hyperref[def:semiring_ideal/prime]{prime ideal}, we may denote the localization by \( R_P \) (or \( R_p \) if \( P = \braket{ p } \)).

  The image under \( \iota \) of every element \( s \) of \( S \) is invertible in \( S^{-1} R \), and we call the inverse \( \ifrac {1_R} s \) the \term{reciprocal} of \( s \).

  This construction is very similar to the \hyperref[def:monoid_grothendieck_completion]{Grothendieck completion} of a monoid or semiring, although with notable differences --- the set \( S \) may be a strict subset of \( R \), and addition in the Grothendieck completion corresponds to multiplication in the localization, while addition in the completion has no analogy.
\end{definition}
\begin{defproof}
  The proof that \( {\sim} \) is an equivalence relation is the same as in \fullref{def:monoid_grothendieck_completion}. The result is then a ring if the operations are well-defined.

  We will show that both operations are well-defined. Let \( u ab' = u a'b \), meaning that \( (a, b) \sim (a', b') \) and hence \( \ifrac a b = \ifrac {a'} {b'} \), and let \( v cd' = v c'd \).

  For addition, we have
  \begin{align*}
    u v (ad + bc) b' d'
    &=
    v dd' (u ab') + u bb' (v cd')
    = \\ &=
    v dd' (u a'b) + u bb' (v c'd)
    = \\ &=
    u v (a'd' + b'c') b d,
  \end{align*}
  hence \( (ad + bc, bd) \sim (a'd' + b'c', b'd') \).

  The proof for correctness of multiplication is the same as the proof of correctness of addition in \fullref{def:monoid_grothendieck_completion}.
\end{defproof}

\begin{theorem}[Ring localization universal property]\label{thm:ring_localization_universal_property}\mcite[431]{Knapp2016BasicAlgebra}
  The \hyperref[def:ring_localization]{localization} of \( R \) by \( S \) satisfies the following \hyperref[rem:universal_mapping_property]{universal mapping property}:
  \begin{displayquote}
    For every commutative ring \( T \) and every ring homomorphism \( \varphi: R \to T \) such that \( \varphi(s) \) is invertible in \( T \) for every \( s \in S \), \( \varphi \) \hyperref[def:factors_through]{uniquely factors through} \( S^{-1} R \). That is, there exists a unique ring homomorphism \( \widetilde{\varphi}: S^{-1} R \to T \) such that the following diagram commutes:
    \begin{equation}\label{eq:thm:ring_localization_universal_property/diagram}
      \begin{aligned}
        \includegraphics[page=1]{output/thm__ring_localization_universal_property.pdf}
      \end{aligned}
    \end{equation}
  \end{displayquote}
\end{theorem}
\begin{proof}
  The condition suggests the definition
  \begin{equation*}
    \widetilde{\varphi}\parens*{ \frac r s } \coloneqq \varphi(r) \varphi(s)^{-1}.
  \end{equation*}
\end{proof}

\begin{example}\label{ex:def:ring_localization}
  We list several examples of \hyperref[def:ring/commutative]{commutative ring} \hyperref[def:ring_localization]{localization}.

  \begin{thmenum}
    \thmitem{ex:def:ring_localization/zero} If \( S \) contains \( 0_R \), then \( S^{-1} R \) is the trivial ring.

    \thmitem{ex:def:ring_localization/powers_of_two} The localization \( S^{-1} \BbbZ \) by the set \( S \coloneqq \set{ 2^n \given n \geq 0 } \) is (a ring isomorphic to) the rational numbers with denominators that are powers of two. This is an example of a multiplicative set that is not the complement of a prime ideal.

    This ring is isomorphic to the ring \( \BbbZ[\ifrac 1 2] \) obtained by \hyperref[thm:adjoining_elements_to_semiring]{adjoining} the rational number \( \ifrac 1 2 \) to \( \BbbZ \).

    \thmitem{ex:def:ring_localization/prime_number} Let \( p \) be a \hyperref[def:prime_number]{prime number}. The localization \( S^{-1} \BbbZ \) by \( S \coloneqq \BbbZ \setminus \braket{ p } \) is (a ring isomorphic to) the rational numbers with denominators coprime to \( p \).

    For \( p = 2 \), this localization consists of rational numbers whose denominator is an odd number.
  \end{thmenum}
\end{example}

\begin{proposition}\label{thm:def:ring_localization}
  \hyperref[def:ring_localization]{Ring localization} has the following basic properties:

  \begin{thmenum}
    \thmitem{thm:def:ring_localization/image_of_ideal}\mcite[432]{Knapp2016BasicAlgebra} Localization preserves \hyperref[def:semiring_ideal]{ideals}. More precisely, given a commutative ring \( R \), a multiplicative set \( S \) and an ideal \( I \), the set
    \begin{equation*}
      S^{-1} I \coloneqq \set*{ \frac r s \given* r \in I \T{and} s \in S }
    \end{equation*}
    is an ideal of the localization \( S^{-1} R \).

    \thmitem{thm:def:ring_localization/prime_ideals}\mcite[exer. 4.3]{КоцевСидеров2016} The map \( I \mapsto S^{-1} I \) is a \hyperref[def:partially_ordered_set/homomorphism]{strict order isomorphism} between the set of \hyperref[def:ring/submodel]{prime ideals} of \( R \) not intersecting \( S \) and the set of all prime ideals of \( S^{-1} R \).

    \thmitem{thm:def:ring_localization/by_prime_ideal}\mcite[exer. 4.2a)]{КоцевСидеров2016} The localization \( R_P \) by a \hyperref[def:semiring_ideal/prime]{prime ideal} \( P \) has a unique maximal ideal \( S^{-1} P \) (here \( S \coloneqq R \setminus P \)).

    \thmitem{thm:def:ring_localization/injective_inclusion} The canonical inclusion \( \iota: R \to S^{-1} R \) is injective if and only if \( S \) contains no zero divisors.
  \end{thmenum}
\end{proposition}
\begin{proof}
  \SubProofOf{thm:def:ring_localization/image_of_ideal} Trivial since \( S \) is closed under multiplication.

  \SubProofOf{thm:def:ring_localization/prime_ideals} Let \( P \) be a prime ideal in \( R \) disjoint from \( S \). By \fullref{thm:def:ring_localization/image_of_ideal}, \( S^{-1} P \) is an ideal of \( S^{-1} R \). If the product \( \ifrac {ac} {bd} \) belong to \( S^{-1} P \), then \( ac \in P \) and \( bd \in S \). Since \( P \) is prime, \( a \in P \) or \( c \in P \). If \( a \in P \), then \( ba \in P \) and \( \ifrac a d = \ifrac {ba} {bd} \in S^{-1} P \); if \( c \in P \), we proceed analogously. Thus, \( S^{-1} P \) is a prime ideal, i.e. the image under \( I \mapsto S^{-1} I \) of a prime ideal is a prime ideal.

  \SubProofOf[def:function_invertibility/injective/equality]{injectivity} Let \( S^{-1} P = S^{-1} Q \) for prime ideals \( P \) and \( Q \) disjoint from \( S \). Suppose that \( P \setminus Q \) contains at least one element, say \( p \). Then \( \iota(p) = \ifrac p 1 \) belongs to both \( S^{-1} P \) and \( S^{-1} Q \); hence, \( Q \) contains an element \( q \) such that, for some \( s \in S \) and \( u \in S \),
  \begin{equation*}
    p \cdot s \cdot u = 1 \cdot q \cdot u.
  \end{equation*}

  Since \( Q \) is an ideal, \( qu \in Q \), and hence \( psu \in Q \). But neither \( p \), \( s \) nor \( u \) belong to \( Q \), which contradicts the assumption that \( Q \) is prime. Therefore, \( P \setminus Q \) is empty. Generalizing, we obtain that \( I \mapsto S^{-1} I \) is injective on prime ideals.

  \SubProofOf[def:function_invertibility/surjective/existence]{surjectivity} Fix a prime ideal \( T \) in \( S^{-1} R \) and let \( P \) be the set of numerators in \( T \), i.e. if \( \ifrac p s \in T \), then \( p \in P \). We will show that \( P \) is a prime ideal; clearly \( T = S^{-1} P \).

  Clearly \( 0_R \in P \). Let \( a, c \in P \). Then there exist \( b, d \in S \) such that \( \ifrac a b \) and \( \ifrac c d \) belong to \( T \). But \( T \) is closed under multiplication with members of \( R \), hence \( \ifrac a {1_R} = b (\ifrac a b) \) and \( \ifrac c {1_R} = d (\ifrac c d) \) also belong to \( T \). Then their sum \( \ifrac {(a + c)} 1 \) belongs to \( T \), and hence also to \( P \). Thus, \( P \) is closed under addition. We analogously obtain that it is closed under multiplication.

  We have shown that \( P \) is an ideal in \( R \). We must show that it is a prime ideal. Let \( ac \in P \). Then
  \begin{equation*}
    \frac a b \cdot \frac c d \in T
  \end{equation*}
  for some \( b, d \in S \). Hence, \( \ifrac a b \) or \( \ifrac c d \) belongs to \( T \), implying that \( a \in P \) or \( c \in P \).

  \SubProofOf[def:partially_ordered_set/homomorphism]{monotonicity} Follows from \fullref{thm:order_embedding_is_strict}.

  \SubProofOf{thm:def:ring_localization/by_prime_ideal} In the localization \( R_P \) be a prime ideal, all members of \( P \) become invertible. Hence, a maximal ideal cannot contain members of \( P \). By \fullref{thm:def:ring_localization/image_of_ideal}, \( S^{-1} P \) is an ideal, therefore it must be the largest proper ideal.

  \SubProofOf{thm:def:ring_localization/injective_inclusion} Let \( sr = 0 \) for \( s \in S \). Then \( \iota(s) = \ifrac s {1_R} \) is invertible in \( S^{-1} R \) and hence
  \begin{equation*}
    \frac {0_R} {1_R}
    =
    \frac {sr} {1_R}
    =
    \frac {1_R} s \cdot \frac {sr} {1_R}
    =
    \frac r {1_R}.
  \end{equation*}

  Hence, \( \iota(r) = \iota(0_R) \).

  It follows that \( \iota \) is injective if and only if \( S \) contains no zero divisors.
\end{proof}

\begin{definition}\label{def:division_ring}\mcite[144]{Knapp2016BasicAlgebra}
  If every nonzero element of a ring is \hyperref[def:divisibility/unit]{invertible}, we call it a \term{division ring}.
\end{definition}

\begin{proposition}\label{thm:division_ring_is_entire}
  A nontrivial \hyperref[def:division_ring]{division ring} is \hyperref[def:entire_semiring]{entire}.
\end{proposition}
\begin{proof}
  Let \( xy = 0 \). If \( x \) is nonzero, multiplying both sides by \( x^{-1} \), we obtain \( y = 0 \). Analogously, \( y \neq 0 \) implies that \( x = 0 \). In all cases, either \( x \) or \( y \) is necessarily zero.

  Therefore, the ring has no nontrivial zero divisors.
\end{proof}

\begin{definition}\label{def:field}
  We will call the \hyperref[def:ring/trivial]{nontrivial} \hyperref[def:ring]{ring} \( \BbbK \) a \term{field} if any of the following equivalent conditions hold:
  \begin{thmenum}
    \thmitem{def:field/simple} \( \BbbK \) is \hyperref[def:ring/commutative]{commutative} and \hyperref[def:ring/simple]{simple}.
    \thmitem{def:field/division_ring} \( \BbbK \) is a \hyperref[def:ring/commutative]{commutative} \hyperref[def:division_ring]{division ring}.
  \end{thmenum}

  Fields have the following metamathematical properties:
  \begin{thmenum}
    \thmitem{def:field/theory} We can construct a \hyperref[def:first_order_theory]{first-order theory} for fields by adding to the \hyperref[def:semiring/theory]{theory of rings} the axioms \( \neg (0 \doteq 1) \) and
    \begin{equation}\label{eq:def:field/theory/invertibility}
      (\xi \doteq 0) \vee \qexists \eta (\xi \cdot \eta \doteq 1).
    \end{equation}

    These axioms are not \hyperref[def:positive_formula]{positive formulas}, hence fields automatically get worse metamathematical properties than rings, for example.

    \thmitem{def:field/homomorphism}\mcite[453]{Knapp2016BasicAlgebra} A \hyperref[def:first_order_homomorphism]{first-order homomorphism} between fields is simply a \hyperref[def:ring/homomorphism]{unital ring homomorphism}.

    \thmitem{def:field/submodel} If for two fields \( \Bbbk \) and \( \BbbK \) are have \( \Bbbk \subseteq \BbbK \), we say that \( \BbbK \) is a \term{field extension} of \( \Bbbk \) and that \( \Bbbk \) is a \term{subfield} of \( \BbbK \). In particular, if \( \BbbK = \Bbbk \), we say that the extension is trivial.

    \thmitem{def:field/category} The category of \hyperref[def:large_and_small_sets]{\( \mscrU \)-small} fields \( \ucat{Field} \) is a full subcategory of \hyperref[def:ring/category]{\( \ucat{CRing} \)} with objects restricted to fields.
  \end{thmenum}
\end{definition}
\begin{defproof}
  The equivalence of definitions follows from \fullref{thm:def:semiring_ideal/units}.
\end{defproof}

\begin{proposition}\label{thm:field_of_fractions}
  Let \( D \) be an \hyperref[def:integral_domain]{integral domain}. The \hyperref[def:ring_localization]{localization} of \( D \) at the zero ideal \( \set{ 0_R } \) is a \hyperref[def:field]{field}, which we call the \term{field of fractions} of \( D \).
\end{proposition}
\begin{proof}
  By \fullref{thm:def:ring_localization/prime_ideal}, the localization by the prime ideal \( \set{ 0_R } \) has  whose only maximal ideal is \( S^{-1} \set{ 0_R } \). Since \( 0_R \) is absorbing, \( S^{-1} \set{ 0_R } \) is again the zero ideal.  Therefore, it is the only proper ideal of the localization \( S^{-1} D \), and hence the localization is a \hyperref[def:ring/simple]{simple ring}.

  Since \( D \) is an integral domain, by \fullref{thm:def:ring_localization/injective_inclusion}, \( S^{-1} D \) is a superring of \( D \). It is therefore a nontrivial commutative simple ring, and thus it satisfies \fullref{def:field/simple}.
\end{proof}

\begin{theorem}[Field of fractions universal property]\label{thm:field_of_fractions_universal_property}
  The \hyperref[def:field_of_fractions]{field of fractions} \( \BbbK \) of the integral domain \( D \) satisfies the following \hyperref[rem:universal_mapping_property]{universal mapping property}:
  \begin{displayquote}
    For every field \( \BbbL \) and every ring homomorphism \( \varphi: D \to \BbbL \), \( \varphi \) \hyperref[def:factors_through]{uniquely factors through} \( \BbbK \). That is, there exists a unique field homomorphism \( \widetilde{\varphi}: \BbbK \to \BbbL \) such that the following diagram commutes:
    \begin{equation}\label{eq:thm:field_of_fractions_universal_property/diagram}
      \begin{aligned}
        \includegraphics[page=1]{output/thm__field_of_fractions_universal_property.pdf}
      \end{aligned}
    \end{equation}
  \end{displayquote}
\end{theorem}
\begin{proof}
  This is simply a special case of \fullref{thm:ring_localization_universal_property}.
\end{proof}

\begin{definition}\label{def:rational_function_field}
  The field of \term{rational algebraic functions} \( D(\mscrX) \) for the set of indeterminates \( \mscrX \) over the \hyperref[def:integral_domain]{integral domain} \( D \) is the \hyperref[thm:field_of_fractions]{field of fractions} of the \hyperref[def:polynomial_algebra]{polynomial ring} \( D[\mscrX] \).

  Despite the name, elements of the field of fractions are not actually functions, but merely formal expressions. In particular, an analog of \fullref{thm:polynomial_algebra_universal_property} does not really make sense.
\end{definition}

\begin{proposition}\label{thm:adjoining_elements_to_field}
  Let \( \Bbbk \subseteq \BbbK \) be \hyperref[def:field]{fields} and let \( A \) be an arbitrary subset of \( \BbbK \).

  Let \( \Bbbk[A] \) be the ring obtained by adjoining the elements of \( A \) to \( \Bbbk \) as described in \fullref{thm:adjoining_elements_to_semiring}. The \hyperref[def:field_of_fractions]{field of fractions} of \( \Bbbk[A] \) is the smallest field extension of \( \Bbbk \) containing \( A \).

  We denote this extension by \( \Bbbk(A) \). It should not be confused with the image of the evaluation homomorphism on the \hyperref[def:rational_function_field]{field of rational functions}; the rational functions do not actually have an evaluation homomorphism.
\end{proposition}
\begin{proof}
  It follows from \fullref{thm:adjoining_elements_to_semiring} that \( \Bbbk[A] \) is the smallest superring of \( \Bbbk \) containing \( A \). By \fullref{thm:field_of_fractions_universal_property}, \( \Bbbk(A) \) is the smallest field containing \( \Bbbk[A] \).
\end{proof}


\documentclass[a4paper]{article}

\def\npart{IB}

\def\ntitle{Optimisation}
\def\nlecturer{M.\ Tehranchi}

\def\nterm{Easter}
\def\nyear{2017}

\input{header}

\begin{document}

\input{titlepage}

\tableofcontents

\section{Introduction}

The typical problem is of the form

\begin{center}
  minimise $f(x)$ subject to $g(x) = b,\: x \in X$,
\end{center}

where

\begin{itemize}
\item $f : \mathbb{R}^n → \mathbb{R}$ is the \emph{objective function},
\item $X \subseteq \mathbb{R}^n$ defines a \emph{regional constraint},
\item $g: \mathbb{R}^n → \mathbb{R}^m$ defines $m$ \emph{functional constraints},
\item $b \in \mathbb{R}^m$ is the \emph{right-hand side}.
\end{itemize}

We will also use the terminology

\begin{itemize}
\item a \emph{feasible solution} is any $x \in X$ s.t. $g(x) = b$,
\item an \emph{optimal solution} is a feasible solution $x^*$ s.t. $f(x^*) ≤ f(x)$ for all feasible $x$.

\end{itemize}

A problem with inequality constraints can be put into equality form by introducing \emph{slack variables}:

\begin{center}
  minimise $f(x)$ subject to $g(x) ≤ b,\: x \in X$

  minmise $f(x)$ subject to $g(x) + z = b,\: x \in X$.
\end{center}

\section{Lagrangian Methods}

Consider the problem

\begin{center}
  minimise $f(x)$ subject to $g(x) = b,\: x \in X$.
\end{center}

Introduce a new function $L : \mathbb{R}^n × \mathbb{R}^m → \mathbb{R},\: L(x, \lambda) = f(x) + \lambda^T (b - g(x))$, the \emph{Lagrangian} of the problem. The components $\lambda_i$ is called the \emph{Lagrangian multiplier} for the $i$-th functional constraint.

\subsection{Lagrangian Sufficiency}

\begin{theorem}[Lagrangian Sufficiency Theorem]
  Let $x^*$ be feasible. Suppose there exists $\lambda^* \in \mathbb{R}^m$ s.t.
  \[
    L(x^*, \lambda^*) ≤ L(x, \lambda^*) \: \text{for all } x \in X
  \]

  then $x^*$ is optimal.

\end{theorem}

\begin{proof}
  For any feasible $x$ and any $\lambda$ we have
  \[
    L(x, \lambda) = f(x) + \lambda^T (b - g(x)) = f(x)
  \]

  so
  \begin{align*}
    f(x^*) &= L(x^*, \lambda^*) \\
           &≤ L(x, \lambda^*) \: \text{for all} x \in X \: \text{by assumption } \\
           &= f(x) \: \text{for all feasible } x \in X
  \end{align*}
\end{proof}

\subsection{Steps}

Consider the problem to

\begin{center}
  minimise $f(x)$ subject to $g(x) = b,\: x \in X$
\end{center}

\begin{itemize}
\item[Step 1] $\Lambda := \{\displaystyle \lambda \in \mathbb{R}^n: \inf_{x \in X} L(x, \lambda) > -∞\}$
\item[Step 2] For each $\lambda \in \Lambda$ find the optimal solution to the unconstrained problem

\begin{center}
  minimise $L(x, \lambda)$ subject to $x \in X$
\end{center}

Let $x(\lambda)$ be the minimiser
\item[Step 3] Find a $\lambda^* \in \Lambda$ s.t. $x^* = x(\lambda^*)$ is feasible for the original problem, i.e. $g(x^*) = b$.
\end{itemize}

Note that $x^*$ is optimal by Lagrangian sufficiency theorem.

\subsection{Complementary Slackness}

Given an inequality constraint, we introduce the equivalent equality constraint problem with slack variables. The Lagrangian is now
\[
  L(x, z, \lambda) = f(x) + \lambda^T (b - g(x)) - \lambda^T z
\]

Note that for the infimum to exist, $\lambda ≤ 0$. The inequality constraint $g(x) ≤ b $ for the variable $x$ introduces a \emph{sign constraint} $\lambda ≤ 0$ for the Lagrange multiplier $\lambda$.

In addition, for $\lambda ≤ 0$ we have $\displaystyle \inf_{z ≥ 0} (-\lambda^T z) = 0$. Thus for each $\lambda \in \Lambda$, the optimal $z = z(\lambda)$ satisfis the \emph{compementary slacknes} condition $\lambda^T z = 0$. Hence $\lambda_i z_i = 0$ for all $i$.

\subsection{Lagrangian Necessity}

Note that for any Lagrange multiplier $\lambda$ we have

\begin{align*}
  \inf_{x \in X,\: g(x) = b} f(x) &= \inf_{x \in X,\: g(x) = b} (f(x) + \lambda^T (b - g(x))) \\
                                &= \inf_{x \in X,\: g(x) = b} L(x, \lambda) \\
                                &≥ \inf_{x \in X} L(x, \lambda)
\end{align*}

since $\{x \in X: g(x) = b\} ⊆ X$. We say the Lagrangian method works if there exists a Lagrange multiplier $\lambda^*$ s.t. there is an equality. To characterise when the Lagrangian method works, we need to define some terms.

\begin{definition}
  $\psi: \mathbb{R}^m → \mathbb{R}$ has a \emph{supporting hyperplane} at a point $b \in \mathbb{R}^m$ if there exist a $\lambda$ s.t.
  \[
    \psi(c) ≥ \psi(b) + \lambda^T (c-b)
  \]
  for all $c \in \mathbb{R}^m$.
\end{definition}

\begin{definition}
  The \emph{value function} $φ$ on $\mathbb{R}^n$ is defined by $\displaystyle\phi(c) = \inf_{x \in X,\: g(x) = c} f(x)$.
\end{definition}

\begin{theorem}[Lagrangian Necessity Theorem]
  The Lagrangian method works for the problem iff the value function has a supporting hyperplane at $b$.
\end{theorem}

\begin{proof}
  The Lagrangian method works iff there exists a $\lambda$ s.t.
  \[
   \phi(b) = \inf_{x \in X} (f(x) + \lambda^T (b - g(x)))
  \]

  The value function has a supporting hyperplane at $b$ iff there exists a $\lambda$ s.t.
  \[
   \phi(b) = \inf_{c \in \mathbb{R}^m} (\phi(c) + \lambda^T (b - c))
  \]

  Thus the equivalence of the two hypotheses is proven by noting the equality
  \begin{align*}
    \inf_{x \in X} (f(x) + \lambda^T (b - g(x))) &= \inf_{c \in \mathbb{R}^m} \underbrace{\inf_{x \in X,\: g(x) = c} (f(x)}_{\phi(c)} + \lambda^T \underbrace{(c - g(x))}_{= 0} + \lambda^T (b - c)) \\
                                         &= \inf_{c \in \mathbb{R}^m} (\phi(c) + \lambda^T (b - c))
  \end{align*}
\end{proof}

To check whether a function has a supporting hyperplane, we have to define a few terms.

\begin{definition}
  A subset $C \subseteq \mathbb{R}^n$ is \emph{convex} if
  \[
    x, y \in C \: \text{implies } \theta x + (1 - \theta)y \in C \: \text{for all } 0 \subseteq \theta \subseteq 1.
  \]
\end{definition}

\begin{definition}
  A function $\psi: \mathbb{R}^m \rightarrow \mathbb{R}^m$ is \emph{convex} if
  \[
    \psi(\theta x + (1 - \theta) y \leq \theta\psi(x) + (1-\theta) \psi(y) \: \text{for all } x, y \in \mathbb{R}^m \: \text{and } 0 \leq \theta \leq 1.
  \]
\end{definition}

\begin{corollary}
  A fucntion $\psi : \mathbb{R}^m \rightarrow \mathbb{R}$ is convex iff the set
  \[
    C := \{(x, y) : \psi(x) \leq y \} \subseteq \mathbb{R}^{m + 1}
  \]
  is convex\footnote{The set $C$ defined above is call the \emph{epigraph} of $\psi$.}.
\end{corollary}

\begin{theorem}[Non-examinable]
  A function is convex iff it has a supporting hyperplane at each point.
\end{theorem}

\begin{proposition}
  If
  \begin{enumerate}
  \item the set $X$ is convex,
  \item the objective function $f$ is convex, and
  \item the functional constraint is
    \begin{itemize}
    \item either $g(x) = b$ and $g$ is linear, or
    \item $g(x) \leq b$ and $g$ is convex.
    \end{itemize}
  \end{enumerate}

  then $\psi$ is convex.
\end{proposition}

\section{Dual Problem}

Consider the \emph{primal} problem

\begin{center}
  $P:$ minimise $f(x)$ subject to $g(x) = b,\: x \in X$.
\end{center}

As before, introduce the Lagrangian $L$ and the set of Lagrange multipliers $\Lambda$. Now define the \emph{dual objective function} $h: \Lambda \rightarrow \mathbb{R}$ by
\[
  h(\lambda) = \inf_{x \in X} L(x, \lambda).
\]

The \emph{dual} problem is defined to be

\begin{center}
  $D:$ maximise $h(\lambda)$ subject to $\lambda \in \Lambda$.
\end{center}

The set $\Lambda$ is the set of \emph{feasible solutions to the dual problem}.

\begin{theorem}[Weak Duality]
  Let $x$ be feasible for $P$ and let $\lambda$ be feasible for $D$. Then
  \[
    h(\lambda) \leq f(x)
  \]

  and in particular
  \[
    \sup_{\lambda \in \Lambda} \leq \inf_{x \in X,\: g(x) = b} f(x).
  \]
\end{theorem}

\begin{proof}
  Let $x$ and $f$ be feasible for their respective problems, then
  \begin{align*}
    h(\lambda) &= \inf\{L(x', \lambda): x' \in X \} \\
               &\leq L(x, \lambda) \: \text{for all } x \in X \\
               &= f(x) \: \text{for all feasible } x
  \end{align*}
\end{proof}

The difference
\[
  \inf_{x \in X,\: g(x) = b} f(x) - \sup_{\lambda \in \Lambda} h(\lambda)
\]

is called the \emph{duality gap}. Weak duality says that the duality gap is non-negative while in the case where the conditions of Lagrangian necessity are met, the duality gap is zero. This is called strong duality.

\begin{eg}[Linear Programming]
  Consider the primal problem
  \begin{center}
    $P:$ maximise $c^T x$ subject to $Ax \leq b,\: x \geq 0$
  \end{center}
  where $A$ is a $m \times n$ matrix, $b \in \mathbb{R}^m$, and $c \in \mathbb{R}^n$.

  The dual problem is found as follows:
  \begin{enumerate}
  \item Introduce slack variables
    \begin{center}
      $P:$ maximise $c^T x$ subject to $Ax + z = b, \: x \geq 0, \: z \geq 0$
    \end{center}
  \item The Lagrangian is
    \[
      L(x, z, \lambda) = b^T \lambda + (c - A^T \lambda)^T x - \lambda ^T z.
    \]
  \item The set of feasible solutions to the dual problem is
    \begin{align*}
      \Lambda &= \{\lambda \in \mathbb{R}^m: \sup_{x \geq 0,\: z \geq 0} L(x, z, \lambda) < \infty \} \\
              &= \{\lambda \in \mathbb{R}^m: A^T \lambda \geq c,\: \lambda \geq 0\}.
    \end{align*}
  \item The dual objective funtion
    \[
      \sup_{x \geq 0, z \geq 0} L(x, z, \lambda) = b^T \lambda \: \text{for } \lambda \in \Lambda.
    \]

    The dual problem is then

    \begin{center}
      $D:$ minimise $b^T \lambda$ subject to $A^T \lambda \geq c,\: \lambda \geq 0$.
    \end{center}
  \end{enumerate}
\end{eg}

We can verify that the dual of the dual is the original problem.

\begin{theorem}[Fundamental Theorem of Linear Programming]
  Consider the problem

  \begin{center}
    $P:$ maximise $c^T x$ subject to $Ax \leq b,\: x \geq 0$.
  \end{center}

  A vector $x^* \in \mathbb{R}^n$ is optimal for $P$ iff there exists a vector $\lambda^* \in \mathbb{R}^m$ s.t.

  \begin{itemize}
  \item $A x^* \leq b,\: x^* \geq 0$ \: (primal feasibility)
  \item $A^T \lambda^* \geq c,\: \lambda^* \geq 0$ \: (dual feasibility)
  \item $(\lambda^*)^T (b - A x^*) = 0 = (x^*)^T (c - A^T \lambda ^*)$ \: (complementary slackness)
  \end{itemize}
\end{theorem}

In this case, the value of the primal problem $c^T x^* = b^T \lambda^*$ equals the value of the dual problem.

\subsection{Extreme Points and Basic Feasible Solutions}

Suppose $\psi$ is a convex function, then give $x, y \in X$ and $0 \leq \theta \leq 1$,

\begin{align*}
  \psi(\theta x + (1 - \theta) y) & \leq \theta \psi(x) + (1 - \theta)\psi(y) \\
                                  &\leq \max\{\psi(x), \psi(y)\}
\end{align*}

That is to say the maximimum of $\psi$ on any segment occurs at one of the end points. Thus to find the maximum of $\psi$ over $X$ we over have to consider points of $X$ that do not lie on a line segment contained in $X$.

\begin{definition}
  Let $C \subseteq \mathbb{R}^n$ be a convex set. A point $x \in C$ is an \emph{extreme point} if

  \[
    x = \theta y + (1 - \theta) z
  \]
  for $y, z \in X$ and $0 \leq \theta \leq 1$ imples $x = y = z$.
\end{definition}

\begin{definition}
  The \emph{standard form} of a linear programme is

  \begin{center}
    maximise $c^T x$ subject to $Ax = b,\: x\geq 0$
  \end{center}
  where $c \in \mathbb{R}^n,\: b \in \mathbb{R}^m$ and $A$ is a $m \times n$ matrix. The set $C := \{x \in \mathbb{R}^n: Ax = b\}$ is the set of feasible solutions to the problem.
\end{definition}

\begin{proposition}
  The set $C$ is convex.
\end{proposition}

\begin{proof}
  Suppose $x, y \in C$. Then $Ax = b,\: x \geq 0$, and $Ay = b,\: y \geq 0$. Fix $\theta \in [0, 1]$ and let $z = \theta x + (1 - \theta)y$. Then

  \begin{align*}
    Az &= \theta Ax + (1 - \theta) Ay = b \\
    z_i &= \theta x_i + (1 - \theta) y_i \geq 0 \: \text{for all } i
  \end{align*}

  Hence $z \in C$.
\end{proof}

A solution $x \in \mathbb{R}^n$ of the equation $Ax = b$ is called \emph{basic} if at least $n - m$ entries of $x$ are zero. If $x$ is a basic solution and $x \geq 0$ then $x$ is called a \emph{basic feasible solution}, abbreviated \emph{b.f.s}.

\begin{theorem}
  Let $x$ be a point in $C$ with the property that have at least $m+1$ indices $i$ s.t. $x_i>0$. Then $x$ is not a extreme point of $C$.
\end{theorem}

\begin{proof}
  \texttt{to be filled in}
\end{proof}

\begin{theorem}
  Suppose that every set of $m$ columns of $A$ is linearly independent. Let $x$ be a point in $C$ with the property that at most $m$ indices $i$ are s.t. $z_i>0$. Then $x$ is an extreme point of $C$.
\end{theorem}

\begin{proof}
  \texttt{to be filled in}
\end{proof}

\subsection{Simplex Algorithm}

We assume $A$ is a $m\times n$ matrix and $n > m$ and that every set of $m$ columns of $A$ is linearly independent. From discussion above it suffices to consider the extreme points of $C$. Fix $B \subset \{1, \ldots ,n\}$ with $|B|=m$, and let $N=\{1,\ldots, n\} \setminus B$. If $B=\{i_1,\ldots,i_m\}$, let $A_B=(A_{i_1}\:\ldots\:A_{i_m})$ bethe $m\times m$ matrix formed by takning the colums of $A$ indexed by $i \in B$. By assumption $A_B$ is invertible. Define $x_B$ and $c_B$ similarly. Similar for the set $N$.

Using this notation, the equation is
\[
  A_B x_B + A_N x_N = b
\]

Setting $x_N=0$ yields $x_B=A_B^{-1}b$ so by rearranging the coordinates we may write the basic point as $x=\binom{x_B}{x_N}\binom{A_B^{-1}b}{0}$. To check this $x$ is feasible, we need $A_B^{-1}b \geq 0$. If it is, compute the objective function $c^Tx=c_B^Tx_B$.

To check the optimality, we use the fundamental theorem. For the b.f.s. $x=\binom{A_B^{-1}b}{0}$, we associate to it a Lagrange multiplier $\lambda$ by complementary slackness

\begin{align*}
  0 &= (c - A^T\lambda)^Tx \\
    &= (c_B - A_B^T\lambda)^Tx_B
\end{align*}

Assuming \emph{non-degeneracy}, we take $\lambda=(A_B^T)^{-1}c_B$. By construction $x$ satisfies primal feasibility and $\lambda$ satisfies complementary slackness. Thus $x$ is optimal iff $\lambda$ satisfies dual feasibility. Thus if $A^T\lambda\geq c$ then we know we have found an optimal solution.

\section{Two-person Zero-sum Game}

Suppose Player I and Player II are competing. I has $m$ choices of strategies, labelled $i \in \{1,\ldots,m\}$ while II has $n$, labelled $j \in \{1,\ldots,n\}$. Zero-sum means that if I chooses strategy $i$ and II chooses strategy $j$ then

\begin{itemize}
\item I is paid $a_{i,j}$
\item II is paid $-a_{i,j}$
\end{itemize}

So the net payment is zero. The matrix $A=(a_{i,j})_{i,j}$ is called the \emph{payoff} matrix of the game
\end{document}


\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{physics}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1em}
\relpenalty=10000
\binoppenalty=10000

\begin{document}

\section{Vectors}
\subsection{Rules}
\begin{enumerate}
\item
The angle between vectors $\mathbf{a}$ and $\mathbf{b}$ is the angle one should rotate vector $\mathbf{a}$ to align it with $\mathbf{b}$.
Then:
\begin{enumerate}
\item
$\angle (\mathbf{a},\mathbf{b}) = - \angle (\mathbf{b},\mathbf{a})$
\item
$\angle (\mathbf{a},\mathbf{b}) + \angle (\mathbf{b},\mathbf{c}) = \angle (\mathbf{a},\mathbf{c})$
\item
$\angle (\mathbf{a},\mathbf{b}) = \angle (\mathbf{-a},\mathbf{b}) - 180 ^\circ$
\end{enumerate}

\item
The dot product (also inner product or scalar product) of vectors $\mathbf{a}$ and $\mathbf{b}$ is: \\
$$\mathbf{a} \cdot \mathbf{b} \equiv (\mathbf{a},\mathbf{b}) = \abs{\mathbf{a}} \abs{\mathbf{b}} \cos \angle (\mathbf{a},\mathbf{b}) $$
Then:
\begin{enumerate}
\item
$\mathbf{a} \cdot \mathbf{b} = \mathbf{b} \cdot \mathbf{a}$
\item
$\abs{\mathbf{a} \cdot \mathbf{b}} \leq  \abs{\mathbf{a}} \abs{\mathbf{b}} $
\item
$(\lambda \mathbf{a} + \mu \mathbf{b}) \cdot \mathbf{c} = \lambda \mathbf{a} \cdot \mathbf{c} + \mu \mathbf{b} \cdot \mathbf{c}$
\item
If $\abs{\mathbf{a}},\abs{\mathbf{b}} \ne 0$,then $\mathbf{a} \cdot \mathbf{b}=0$ if and only if when $\mathbf{a} \perp \mathbf{b}$.
\end{enumerate}
\item
The cross product (also vector product) of vectors $\mathbf{a}$ and $\mathbf{b}$ has direction for which $\mathbf{c} \perp \mathbf{a}$ and $\mathbf{c} \perp \mathbf{b}$ and magnitude of: \\
$$\abs{\mathbf{a} \cross \mathbf{b}} = \abs{\mathbf{a}} \abs{\mathbf{b}} \sin \angle (\mathbf{a},\mathbf{b})$$ \\
Alternatively:
$$ \mathbf{a} \cross \mathbf{b} = \det
\left(
\begin{matrix}
\mathbf{i} & \mathbf{j} & \mathbf{k} \\
a_1 & a_2 & a_3 \\
b_1 & b_2 & b_3
\end{matrix}
\right)
$$
where $\mathbf{i},\mathbf{j},\mathbf{k}$ are unit vectors. Then:
\begin{enumerate}
\item
$\mathbf{a} \cross \mathbf{b} = - \mathbf{b} \cross \mathbf{a} $
\item
$(\lambda \mathbf{a} + \mu \mathbf{b}) \times \mathbf{c} = \lambda \mathbf{a} \times \mathbf{c} + \mu \mathbf{b} \times \mathbf{c}$

\item
If $\abs{\mathbf{a}},\abs{\mathbf{b}} \ne 0$,then $\mathbf{a} \cross \mathbf{b}=0$ if and only if when $\mathbf{a} \parallel \mathbf{b}$.
\end{enumerate}
\end{enumerate}

\newpage
\subsection{Problems}
\begin{enumerate}
\item
Prove that $\abs{\mathbf{a} + \mathbf{b}}^2 + \abs{\mathbf{a} - \mathbf{b}}^2 = 2(\abs{\mathbf{a}}^2 + \abs{\mathbf{b}}^2)$.

\item
Prove that if $(\mathbf{a}+\mathbf{b}) \perp (\mathbf{a}-\mathbf{b})$, then $\abs{\mathbf{a}} = \abs{\mathbf{b}}$.

\item
Let $\overrightarrow{OA} + \overrightarrow{OB} + \overrightarrow{OC} = 0$ and $\abs{OA}=\abs{OB}=\abs{OC}$. Prove that $ABC$ is an equilateral triangle

\item %Prasolov 13.1
Prove that it is possible to make another triangle $KLM$ from the medians $AA_1$,$BB_1$,$CC_1$ of a triangle $ABC$. Similarly, triangle $XYZ$ is formed from the medians of $KLM$. Prove that $\triangle ABC \sim \triangle XYZ$ and find their similarity coefficient.

\item %Prasolov 13.4
From a point inside a convex $n$-gon, the rays are drawn perpendicular to the sides and intersecting the sides (or their continuations). On these rays the vectors $\mathbf{a_1}, \dots , \mathbf{a_n}$ whose lengths are equal to the lengths of the corresponding sides are drawn. Prove that
$\mathbf{a_1} + \dots + \mathbf{a_n} = 0$.

\item % Prasolov 13.7
Consider n pairwise non-codirected vectors ($n \geq 3$) whose sum is equal to zero. Prove that there exists a convex $n$-gon such that the set of vectors formed by its sides coincides with the given set of vectors.

\item % Napoleonic triangles
(\emph{Napoleon's theorem})Three equilateral triangles $ABD$, $BCE$, $CAF$ are constructed outside the triangle $ABC$. Prove that the centres of the constructed triangles form an equilateral triangle.

\item %Prasolov 13.12
\begin{enumerate}
\item Let A, B, C and D be arbitrary points on a plane. Prove that
$$ \overrightarrow{AB} \cdot \overrightarrow{CD} +
\overrightarrow{BC} \cdot \overrightarrow{AD} +
\overrightarrow{CA} \cdot \overrightarrow{BD} = 0
 $$
\item Prove that the heights of a triangle intersect at one point.
\end{enumerate}

\item %Prasolov 13.13
Let $O$ be the centre of the circumcircle of triangle $ABC$ and let point $H$
satisfy $\overrightarrow{OH} = \overrightarrow{OA} + \overrightarrow{OB} + \overrightarrow{OC}$. Prove that $H$ is the intersection point of heights of triangle.

\item %Prasolov 13.19
Given points $A$, $B$, $C$ and $D$. Prove that $AB^2 + BC^2 + CD^2 + DA^2 \geq AC^2 + BD^2$,
where the equality is attained only if $ABCD$ is a parallelogram.

\item % Prasolov13.22.
Points $A_1,\dots, A_n$ lie on a circle with center $O$ and $\overrightarrow{OA_1} +\dots+ \overrightarrow{OA_n}=0$. Prove
that for any point $X$ we have $XA_1 + \dots + XA_n \geq nR$, where $R$ is the radius of the circle.

\item
Prove Ceva's theorem: $X$, $Y$ and $Z$ are points on the sides $BC$, $CA$ and $AB$ of a triangle $ABC$ respectively. Then, lines $AX$, $BY$,$CZ$ intersect at a single point if and only if
$$\frac{\overrightarrow{BX}}{\overrightarrow{XC}} \cdot \frac{\overrightarrow{CY}}{\overrightarrow{YA}} \cdot \frac{\overrightarrow{AZ}}{\overrightarrow{ZB}} = 1$$

\item
Prove Menelaus's theorem: $X$, $Y$ and $Z$ are points on the sides (or their elongations) $BC$, $CA$ and $AB$ of a triangle $ABC$ respectively. Then, $X$,$Y$ and $Z$ lie on the same line if and only if
$$\frac{\overrightarrow{BX}}{\overrightarrow{XC}} \cdot \frac{\overrightarrow{CY}}{\overrightarrow{YA}} \cdot \frac{\overrightarrow{AZ}}{\overrightarrow{ZB}} = -1$$

\item % IMO-2013-4
Let $ABC$ be an acute-angled triangle with orthocentre $H$, and let $W$ be a point on the side $BC$, lying strictly between $B$ and $C$. The points $M$ and $N$ are the feet of the altitudes from $B$ and $C$, respectively. Denote by $\omega_1$ the circumcircle of $BWN$, and let $X$ be the point on $\omega_1$ such that $WX$ is a diameter of $\omega_1$. Analogously, denote by $\omega_2$ the circumcircle of $CWM$, and let $Y$ be the point on $\omega_2$ such that $WY$ is a diameter of $\omega_2$. Prove that $X$, $Y$ and $H$ are collinear.

\item
Is it possible to construct a triangle for which both coordinates of each vertex are integers?

\item %http://www.math.olympiaadid.ut.ee/eng/archive/prob1314.pdf p12
The angles of a triangle are $22.5^\circ$, $45^\circ$ and $112.5^\circ$. Prove that inside this triangle there exists a point that is located on the median through one vertex, the angle bisector through another vertex and the altitude through the third vertex.

\end{enumerate}

\end{document}