\par These notes are entirely based on the material of the course Computational Mathematics for Learning and Data Analysis held by Professor Antonio Frangioni and Professor Federico Poloni at University of Pisa. The course is part of the M.Sc. degree in Computer Science.

\section{Mathematical Background}
\subsection{Notations and Nomenclatures}
\par Let's start with introducing some notations and nomenclatures that we are going to use throughout this book. Given a set $\mathcal{X}$, that we call \textbf{feasible region}, and a function $f : \mathcal{X} \rightarrow \mathbb{R}$, that we call \textbf{objective function}, we want to find the solution to the following problem:
\begin{equation}
    f_{*} = \min_{x \in \mathcal{X}}\ \{f(x)\}
    \label{eq:opt_problem_def}
\end{equation}
where $f_{*}$ is called \textbf{optimal value}. The argument $x$ that \textit{minimises} the objective function $f$ is called \textbf{optimal solution}. It is generally denoted with $x_{*}$.\\[5px]
%
\underline{Note that}: $f_{*}$ lives in the output space while $x$ lives in the input space. This is going to be very important where we speak about convergence of the various algorithms that we will see during this brief journey.\\[5px]
%
Obviously, from the moment that we are minimising the function $f$, we have the following property:
\[
    \forall\ x \in \mathcal{X}\ f(x) \geq f(x_{*})
\]
Here again, note that we do not state any ordering relation in the input space; $x$ may be larger, equal or even smaller than $x_{*}$.
\par As we will see in the next chapters, we often employ \textit{iterative methods} for finding the optimal value/optimal solution. Applying an iterative method implies producing a certain sequence of the form $x_1, x_2, ...$ that will bring us to the optimum solution; and thus to the optimal value. Typically we cannot hope to get exactly to $f_{*}$, what we hope instead is to get \textit{as close as possible} to it. Accordingly, limits are very important to us.
We say that:
\begin{equation}
    \lim_{i \rightarrow \infty} x_i = x \iff \forall \epsilon > 0\ \exists h : |x_i - x| \leq \epsilon\ \forall i \geq h
    \label{eq:limit_def}
\end{equation}
In other words, the sequence $\{x_i\}$ converges to $x$, written as $\{x_i\} \rightarrow x$, if and only if... the rest of the formula :). Just kidding. So we were saying, the sequence $\{x_i\}$ converges to $x$ if and only if for \textit{any} tiny number $\epsilon$ that we can choose (as long as it is greater than 0), at some point in our sequence, starting from the number $x_h$, all the numbers in it will be at distance at most $\epsilon$ from $x$.
\par Not all sequences have the limit. For instance think of $(-1)^i$. This sequence does not converge to neither of -1, 0 or 1. This is the reason why we introduce the concept of \textbf{infima} and \textbf{suprema}, or respectively $\liminf$ and $\limsup$. We define the following two quantities:
\[
    \{x_i\} \rightarrow \underbar{$x$}_i = \inf\{x_h : h \geq i\}
\]
and
\[
    \{x_i\} \rightarrow \bar{x}_i = \sup\{x_h : h \geq i\}
\]
Now if we take the sequence of $\{\underbar{x}_i\}$ we are sure that $\underbar{x}_1 \leq \underbar{x}_2 \leq \underbar{x}_3 \leq ...$ and the sequence of $\{\bar{x}_i\}$ we are sure that $\bar{x}_1 \geq \bar{x}_2 \geq \bar{x}_3 \geq ...$. Accordingly, they have a limit! So we can speak about inferior and superior limit of a certain sequence $\{x_i\}$. We have the following equality:
\begin{align}
    &\liminf_{i \rightarrow \infty} x_i = \lim_{i \rightarrow \infty}\inf\{x_h : h \geq i\} = \lim_{i \rightarrow \infty} \underbar{x}_i\\
    &\limsup_{i \rightarrow \infty} x_i = \lim_{i \rightarrow \infty}\sup\{x_h : h \geq i\} = \lim_{i \rightarrow \infty} \bar{x}_i
    \label{eq:liminf_limsup_def}
\end{align}
Now obviously $\bar{x}_i \geq \underbar{x}_i$. But if these two quantities are equal, then we are sure that the limit of the sequence exists:
\[
    \lim_{i \rightarrow \infty} x_i = v \iff \liminf_{i \rightarrow \infty} x_i = v = \limsup_{i \rightarrow \infty} x_i
\]
%
\par Now the life would be pretty straightforward and we would not need to study optimisation if we worked just with single numbers, i.e. in $\mathbb{R}$. We need to scale.
%
\subsection{Euclidean Space \texorpdfstring{$\mathbb{R}^n$}{Rn}}
\par We will mostly use function that operate on vectors not numbers. We need to define the space in which these vectors have some meaning. We thus define the \textbf{Euclidean Space} as the Cartesian product of $n$ one dimensional spaces $\mathbb{R}$:
\begin{equation}
    \mathbb{R}^n = \underbrace{\mathbb{R} \times ... \times \mathbb{R}}_{n\ \text{times}}
    \label{eq:euclidean_space}
\end{equation}
The elements of this space are vectors of $n$ components, i.e. $x \in \mathbb{R}^n = [x_1, ..., x_n]$.\\[5px]
\underline{\textbf{Note}}: during this book we will always assume to work with \textbf{column vectors}. When we use \textbf{row vectors} we will use the transposition sign.\\[5px]
\par The Euclidean space is \textbf{closed} under summation and scalar multiplication. This means that whenever we take two vectors and we sum them, or we take a constant $\alpha$ and we multiply all the components of a vector with $\alpha$, we will always get a new vector that is for sure still in our Euclidean space.
\par The Euclidean space is a \textbf{finite} vector space: this means that each $x \in \mathbb{R}^n$ can be obtained from a \textbf{finite basis}. A basis is a set of vectors such that for whatever vector $x$ in the space, we can somehow linearly combine the vectors from the basis to obtain $x$. Linearly combine means summations and scalar multiplications.
\par The Euclidean space is \textit{not a totally ordered set}. We do not have a natural concept of which one comes first.
\par Since we will work a lot with distances we also need to define the concept of distance in this space. Before talking about the distance we need to introduce a very important concept that we will use constantly. \textbf{The norm}. We define Euclidean norm as:
\begin{equation}
    \lVert x \rVert = \sqrt{\sum_{i=1}^n x_i^2}
    \label{eq:2norm_def}
\end{equation}
Some of the properties of the Euclidean norm are:
\begin{itemize}
    \item $\lVert x \rVert \geq 0$ $\forall x \in \mathbb{R}^n$ with 0 only in case that $x$ is the zero vector
    \item $\lVert \alpha x \rVert = |\alpha| \lVert x \rVert$ $\forall x \in \mathbb{R}^n$ $\forall \alpha \in \mathbb{R}$
    \item $\lVert x+y \rVert \leq \lVert x \rVert + \lVert y \rVert$ $\forall x,y \in \mathbb{R}^n$. This property is called \textbf{triangular inequality}.
\end{itemize}
The norm function is nothing more than a simple function that maps vectors to numbers (also matrices to numbers). Apart from the norm we have defined in the equation \ref{eq:2norm_def}, we have also:
\begin{itemize}
    \item 0-norm $\lVert . \rVert_0 = |i : |x_i| > 0|$, i.e. the cardinality of the set of all non zero components in the vector $x$
    \item 1-norm $\lVert . \rVert_1 = \sum_{i=1}^n |x_i|$
    \item $\infty$-norm $\lVert . \rVert_\infty = \max_{i \in I}\{|x_i|\}$
\end{itemize}
All these norms (including 2-norm) are the special cases of the unique definition of the p-norm:
\begin{equation}
    \lVert x \rVert_p = \Big(\sum_{i=1}^n |x_i|^p\Big)^{\frac{1}{p}}
    \label{eq:p_norm}
\end{equation}
In figure \ref{fig:norms} we show how the function of the norm changes as we augment $p$. Note that for $p \geq 1$ we have a convex function while for $p < 1$ we have a concave function.
\begin{figure}
    \centering
    \includegraphics[scale=0.4]{figures/1/1-norms.png}
    \caption{The various types of norms}
    \label{fig:norms}
\end{figure}
\par It is not very important which norm we are using since all of them are topologically equivalent. This means that whatever two norms we choose, there is a simple linear relation between them:
\begin{equation}
    \forall\ \lVert . \rVert_x, \lVert . \rVert_y\ \exists\ 0 < \alpha < \beta : \alpha \lVert . \rVert_y \leq \lVert . \rVert_x \leq \beta \lVert . \rVert_y
    \label{eq:norm_equivalence}
\end{equation}
Accordingly, we are free to work with whatever norm. We will generally use the two norm, unless stated otherwise.
\par Another concept we have to introduce before defining the distance in the Euclidean space is the \textbf{scalar product} between two vectors. We define the scalar product as:
\begin{equation}
    \langle x,y \rangle = y^{T}x = \sum_{i=1}^n = x_i y_i
    \label{eq:scalar_product}
\end{equation}
Like the norm function, the scalar product is a simple function that takes two vectors and returns the value, i.e. $\langle.\rangle : \mathbb{R}^n \times \mathbb{R}^n \rightarrow \mathbb{R}$. It satisfies the following properties ($\forall\ x,y,z \in \mathbb{R}^n, \forall\ \alpha \in \mathbb{R}$):
\begin{itemize}
    \item $\langle x, y \rangle = \langle y, x \rangle$ (symmetry)
    \item $\langle x, y \rangle \geq 0$
    \item $\langle x, x \rangle = 0 \iff x = 0$
    \item $\langle \alpha x, y \rangle = \alpha \langle x, y \rangle$
    \item $\langle x + y, z \rangle = \langle x, z \rangle + \langle y, z \rangle$
    \item $\langle x, x \rangle = \lVert x \rVert^2$ (only for $\lVert . \rVert_2$)
    \item $\langle x, y \rangle^2 \leq \langle x, x \rangle \langle y, y \rangle = \lVert x \rVert^2 \lVert y \rVert^2$. This is a very important property and it is called \textbf{Cauchy-Schwarz inequality}
\end{itemize}
The scalar product have another definition, the one that uses the cosine function:
\begin{equation}
    \langle x,y \rangle = \lVert x \rVert \lVert y \rVert \cos \theta
    \label{eq:scalar_product_cos}
\end{equation}
From this definition it is clear that when two vectors are perpendicular to each other then the scalar product is 0 (figure \ref{fig:scalar}).
\begin{figure}
    \centering
    \includegraphics[scale=0.4]{figures/1/2-scalar.png}
    \caption{Angle $\theta$ between $x$ and $y$}
    \label{fig:scalar}
\end{figure}
When the two vectors point to the same direction then the scalar product is $> 0$. Cosine of an angle that is between 0 and $\frac{\pi}{2}$ is positive, thus the scalar product is positive (the norms are always $\geq 0$). This will be very useful when we will speak about various descent methods for unconstrained optimisation.
\par We are now ready to introduce the \textbf{Euclidean distance}. The Euclidean distance between $x \in \mathbb{R}^n$ and $y \in \mathbb{R}^n$ is defined as:
\begin{equation}
    d(x,y) = \lVert x - y \rVert = \sqrt{\sum_{i=1}^n(x_i - y_i)^2}
    \label{eq:euclidean_distance}
\end{equation}
The euclidean distance satisfies the following properties ($\forall\ x,y,z \in \mathbb{R}^n$ and $\forall\ \alpha \in \mathbb{R}$):
\begin{itemize}
    \item The distance between two vectors is always $\geq 0$: $d(x,y) \geq 0$
    \item $d(\alpha x, y) = |\alpha|d(x,y)$
    \item $d(x,y) \leq d(x,z) + d(z,y)$ (triangular inequality)
\end{itemize}
So the distance between two vectors is given by the norm of the vector difference between them.
\par We concept of Euclidean distance is useful for defining a very important mathematical object in optimisation.
%
\subsection{Ball, Interior, Boundary and Bounded sets}
\begin{definition}
    Given a centre $x \in \mathbb{R}^n$ and a radius $r > 0 \in \mathbb{R}$, we call \textbf{Ball}:
    \[
        \mathcal{B}(x,r) = \{y \in \mathbb{R}^n : d(x,y) \leq r\}
    \]
    \label{def:ball}
\end{definition}
Having these new mathematical objects, we can restate the concepts of converging sequences as:
\[
    \{x_i\}_{i \rightarrow \infty} \rightarrow x \iff \forall\epsilon > 0\ \exists h : d(x_i,x) \leq \epsilon\ \forall i \geq h
\]
or
\[
    \{x_i\}_{i \rightarrow \infty} \rightarrow x \iff \forall\epsilon > 0\ \exists h : x_i \in \mathcal{B}(x,\epsilon)\ \forall i \geq h
\]
or even
\[
    \lim_{i \rightarrow \infty} d(x_i,x) = 0
\]
Why we are so interested in these sequences of points? Because if we consider the optimisation problem again:
\[
    f_{*} = \min_{x \in \mathcal{X}}\ \{f(x)\}
\]
we want to construct the so called \textit{minimising sequence} $\{x_i\}_{i \rightarrow \infty}$ such that $\{f(x_i)_{i \rightarrow \infty}\} \rightarrow f_{*}$.\\
Note again (again, yes) that $\{f(x_i)_{i \rightarrow \infty}\} \rightarrow f_{*} \centernot\Rightarrow \{x_i\}_{i \rightarrow \infty} \rightarrow x_{*}$. These are two different problems.
\par It is not sufficient to just solve analytically a problem. Consider for instance the following problem:
\[
    \min \{x : x \in \mathbb{R}^n \wedge x > 0\}
\]
The optimal solution $f_{*}$ is infinitely close to 0 but cannot be reached by the sequence $\{x_i = \frac{1}{i}\}_{i \rightarrow \infty}$ ($\{f(x_i)_{i \rightarrow \infty}\} \rightarrow 0$). What can we do in order to avoid this situation. Generally we cannot. What we can do, as we will see during this book, is to require certain properties on the set or functions on which we optimise in order to guarantee that certain situations can never happen.
\begin{definition}
    Given $\mathcal{S} \subseteq \mathbb{R}^n$ we define:
    \begin{align}
        &\text{interior of $\mathcal{S}$} \equiv \text{int}(\mathcal{S}) = \{x : x \in \mathcal{S} \wedge \exists r > 0 : \mathcal{B}(x,r) \subseteq \mathcal{S}\}\\
        &\text{boundary of $\mathcal{S}$} \equiv \partial(\mathcal{S}) = \{x : \forall r \exists y,z \in \mathcal{B}(x,r) : y \in \mathcal{S} \wedge z \centernot \in \mathcal{S}\}
    \end{align}
\end{definition}
\begin{definition}
    The set $\mathcal{S}$ is said to be open $\iff \mathcal{S} = \textit{int}(\mathcal{S})$.
\end{definition}
\begin{definition}
    The set $\mathcal{S}$ is said to be closed $\iff \mathcal{S} = \textit{int}(\mathcal{S}) \cup \partial \mathcal{S}$. Or equivalently if $\mathbb{R}^n \setminus \mathcal{S}$ is open set.
\end{definition}
The union of $\textit{int}(\mathcal{S}) \cup \partial \mathcal{S}$ is called \textit{closure} of the set $\mathcal{S}$.\\[5px]
\textbf{Exercise}: Prove that both $\mathbb{R}^n$ and $\emptyset$ are both open and closed.\\
Let us start from the easiest one: empty set. In order to be open its interior should be equal to itself. The interior of an empty set is empty, thus they are equal. In order to be a closed set, it should be equal to the union of its interior and its boundary. But both of these are empty sets, thus the union is an empty set again.\\
Now consider the case of $\mathbb{R}^n$. This set does not have a boundary, $\partial(\mathbb{R}^n) = \emptyset$. Thus it is equal to its interior. Thus it is open. The union of its interior and an empty set is equal to its interior. Thus it is also closed.\\[3px]
\textbf{Exercise}: Exhibit a set that is neither closed nor open.\\
TODO
\par The concept of the minimising sequences and closed sets can be connected by the following property:
\begin{theorem}
    S is closed $\iff \forall \{x_i\} \subset S \rightarrow x \Rightarrow x \in S$
\end{theorem}
This basically means that $S$ is closed if and only if all accumulation points of sequences in $S$ are in $S$.
\par Suppose we have an infinite sequence of sets $\{S_i\}_{i \rightarrow \infty}$. If the sets are all open, then their union is also an open set.
\begin{equation}
    \cup_{i \in I} S_i\ \text{is open}
\end{equation}
On the other hand, if the sets are all closed, then their intersection is also closed.
\begin{equation}
    \cap_{i \in I} S_i\ \text{is closed}
\end{equation}
Note that the union of an infinite family of closed sets is not necessarily a closed set and that the intersection of an infinite family of open sets is not necessarily an open set. As a counterexample, suppose we define a family of open sets in the following manner:
\begin{equation}
    D_i = \mathcal{B}(x_0, \frac{1}{i})\ i \in \mathbb{N}-\{0\}
\end{equation}
Then the intersection of these sets tends to a set with only one point (0), which is obviously not an open set. The same reasoning can be applied to the union of a family of closed sets.
\par Another important concept when talking about balls and sets, is the concept of a \textbf{Bounded set}.
\begin{definition}
    $S \subseteq \mathbb{R}^n$ is called Bounded if $\exists r > 0 : S \subseteq \mathcal{B}(0,r)$.
\end{definition}
This translates into: $S$ is a Bounded set if we can choose a radius $r$ strictly greater than 0 such that we can create a ball with centre in 0 so that it fully contains the whole $S$.
\begin{definition}
    If a set $S$ is both closed and bounded, it is called \textbf{Compact}.
\end{definition}
%
\subsection{Bolzano-Weierstrass Theorem}
TODO BETTER
\par Before announcing this important theorem, we need to introduce the concept of subsequence.
\begin{definition}
    Given a sequence of points $\{x_i\} \in \mathbb{R}^n$ and a sequence of indexes $\{n_i\} \in \mathbb{N}$, the sequence $\{x_{n_i}\} \subseteq \{x_i\}$ is called a subsequence.
\end{definition}
The \textbf{Bolzano–Weierstrass theorem}, named after Bernard Bolzano and Karl Weierstrass, is a fundamental result about convergence in a finite-dimensional Euclidean space $\mathbb{R}^n$. The theorem states that each bounded sequence in $\mathbb{R}^n$ has a convergent subsequence. An equivalent formulation is that a subset of $\mathbb{R}^n$ is sequentially compact if and only if it is closed and bounded. The theorem is sometimes called the sequential compactness theorem.
%
\subsection{Functions}
\par Remember that our problem is to minimise functions (equation \ref{eq:opt_problem_def}). As we can see, we have two mathematical objects in this equation: the set $\mathcal{X}$ and the function $f$. Up until now we have discussed about sets and the properties we would like to have on them in order to make our life simpler. Now we need to do the same thing with the functions.
\par Note that the functions live in a different space ($\mathbb{R}^{n+1}$) w.r.t. their inputs ($\mathbb{R}^n$). Nevertheless, sometimes we'd like to see how sequences of the functional values behave in the input space. To this end there is a concept of \textbf{level sets} and \textbf{sublevel sets}.
\begin{definition}
    The set $L(f,v) = \{x \in \text{dom}(f) : f(x) = v\}$ is called level set of the function $f$ and level $v$ (figure \ref{fig:levelsets}).
\end{definition}
\begin{definition}
    The set $S(f,v) = \{x \in \text{dom}(f) : f(x) \leq v\}$ is called sublevel set of the function $f$ and level $v$ (figure \ref{fig:sublevelsets}).
\end{definition}
\begin{figure}
    \centering
    \includegraphics[scale=0.4]{figures/1/3-levelsets.png}
    \caption{Level set}
    \label{fig:levelsets}
\end{figure}
\begin{figure}
    \centering
    \includegraphics[scale=0.4]{figures/1/4-sublevelsets.png}
    \caption{Sublevel set}
    \label{fig:sublevelsets}
\end{figure}
\par In case that $f$ is unbounded below, we cannot actually talk about sublevel sets. We can reverse the concept and talk about superlevel sets.
%
\par The first property that we'd like that our functions that we minimise have is continuity.
\begin{definition}
    $f:\mathbb{R}^n \rightarrow \mathbb{R}$ is continuous in $x \in \mathbb{R}^n$ if
    \begin{itemize}
        \item $\{x_i\} \rightarrow x \Rightarrow \{f(x_i) \rightarrow f(x)\}$
        \item $\forall \epsilon > 0\ \exists \delta > 0 : |f(y) - f(x)| < \epsilon\ \forall y \in \mathcal{B}(x,\delta)$
    \end{itemize}
\end{definition}
We say that $f$ is continuous on a set $S \subseteq \mathbb{R}^n$ if it is continuous on each $x \in S$.
\begin{theorem}[Intermediate Value Theorem]
    Suppose we have function $f : \mathbb{R} \rightarrow \mathbb{R}$ continuous on a closed interval $[a,b]$. Then:
    \[
        \forall v : \min \{f(a),f(b)\} \leq v \leq \max \{f(a),f(b)\}\ \exists c \in [a,b] : f(c) = v
    \]
\end{theorem}
All the considerations pointed out so far bring us to the Weistrass extreme value theorem. This theorem is one of the most important in optimisation.
\begin{theorem}[Weistrass Extreme Value Theorem]
Suppose we have a set $X \subseteq \mathbb{R}^n$ compact and a function $f$ that is continuous, then the minimising problem has an optimal solution.
\end{theorem}
From this statement, this theorem doesn't seem to be so meaningful. But, if we exploit a little bit some of the considerations explained so far, we can say that this statement is equivalent to say that: if our set is closed and our function continuous, then all the accumulation points of any minimising sequence are optimal solutions and there is at least one of them.
Up until now, we have understand that having a continuous function is a really great thing and for this reason, in a lot of the methods we'll consider, the basic assumptions will be: a compact set and a continuous function.
But, if we are really lucky, we can ask for more. More we have, simpler it is to gain better results.
Talking about continuity, a more strict version of it is Lipschitz continuity.
\begin{theorem}[Lipschitz continuity]
\[
    \exists L > 0 \quad \forall x,y \in X : |f(x) - f(y)| \leq L \lVert x - y \rVert
\]
\end{theorem}
Since this is a stronger definition of continuity, all the considerations said so far for the continuity case are still true. Moreover, with L continuity, we know that our function doesn't jump wildly. This is a very good result, but unfortunately, a lot of functions are not L continuous. If this is the case, we could see if our function is lower semi continuous (or upper).
%
\par Now, we have to remember our main task: find the minimum of an iterative sequence. For simplicity, we focus our attention on functions in two dimensions. We know that a derivative gives us a linear approximation of the function in that point. So, if I compute the derivative in $x$, in which way of the linear approximation ($f'(x)$) should I go? Of course, we have to go where the line decrease: if the slope of my line is greater than zero, I have to go left, otherwise right. I can stop to iterate when I find $f'(x)=0$ (since I know that in this case we are on a saddle point or a max or min).
\par The saddest part of it is that not all the function have a first derivative and that even if they have it, it may be the case that it isn't continuous. In order to understand when a function is differentiable or not, the definition of derivative is necessary: TODO

\subsection{Useful results about derivatives}
\begin{figure}
    \centering
    \includegraphics[scale=0.3]{figures/1/chapter1-mean_value_theorem1.png}
    \caption{A differentiable function $f(x)$ and two points $a$ and $b$.}
    \label{fig:chapter1-mean_value_theorem1}
\end{figure}
\par Suppose you have a differentiable function like in figure \ref{fig:chapter1-mean_value_theorem1}, with two points and a line connecting those two points. Then according to the \textbf{mean value theorem} we have the following:
\begin{theorem}
    Given a function $f : \mathbb{R} \rightarrow \mathbb{R}$ continuous on $[a,b]$ and differentiable on $(a,b)$ then there exists a point $c \in (a,b)$ such that the slope of the derivative in point $c$ is the same of the slope of the line connecting $a$ and $b$. In other words:
    \[
        f'(c) = \frac{f(b)-f(a)}{b-a} = m
    \]
    where $m$ is the usual slope of a line.
\end{theorem}
Why do we care about this simple theorem? Because there is a special case of it, namely when $f(a) = f(b)$. This takes the name of \textbf{Rolle's theorem} (see figure \ref{fig:chapter1-rolles_theorem1}) and it says:
\begin{theorem}
    Given a function $f : \mathbb{R} \rightarrow \mathbb{R}$ continuous on $[a,b]$ and differentiable on $(a,b)$, if $f(a) = f(b)$ then there exists a point $c \in (a,b)$ such that the slope of the derivative in point $c$ equals 0.
\end{theorem}
\begin{figure}
    \centering
    \includegraphics[scale=0.3]{figures/1/chapter1-rolles_theorem1.png}
    \caption{Rolle's theorem.}
    \label{fig:chapter1-rolles_theorem1}
\end{figure}
This theorem assures us that if $f(a) = f(b)$ in the middle there must me at least one local minimum or maximum, or both.
\par Actually, we can even state that between two consecutive roots of $f$ there is an odd number of roots of the derivative $f'$ in the range of $(a,b)$. If $a$ and $b$ are two consecutive roots of $f$ then the sign of their derivatives are opposite to each other.
\par \textit{Exercise}. Prove that between two consecutive roots of $f'$ there is at most one root of $f$.
\par Suppose $a$ and $b$ are two consecutive roots of $f'$. Suppose now by contradiction that there are two different points $c,d \in (a,b)$ that are also the roots of $f$. According to Rolle's theorem, there must exist at least one point $e \in (c,d)$ such that $f'(e)=0$. This contradicts the fact that $a$ and $b$ are two consecutive roots of $f'$.

\subsection{A different interpretation of the gradient}
\par Remember that the function is a mathematical object that lives in $\mathbb{R}^{n+1}$. The gradient is the linear function approximating $f$ in a point. Thus, the gradient it self lives again in $\mathbb{R}^{n+1}$. It is important also to look at it from the input space, i.e. in $\mathbb{R}^n$. We can do that via level sets again.
\par The gradient turns out to be \textit{normal} to the level sets. In other words, it is tangent to the level set.
\subsection{Vector valued function}


\subsection{Tangent Planes}
\noindent
Although the tangent lines at a point on a surface can all be different depending on the direction one approaches a point from, all of these tangent lines lie in the same plane, defining the tangent plane. This means that the tangent plane to $z = f(x_0, y_0)$ has the following properties:
\begin{itemize}
	\item The z-value of the tangent plane at $(x_0, y_0)$ is the same as $f(x_0, y_0)$.
	\item The value of the first-order partial derivatives of the tangent plane at $(x_0, y_0)$ should match those of $f(x_0, y_0)$.
\end{itemize}

\noindent
The general form of a plane at $(x_0, y_0, z_0)$ is $P(x,y) = A(x-x_0) + B(y-y_0) + z_0$.\\
We want $P_x = f_x$ and $P_y = f_y$.\\
This means that $P_x = f_x = A$ and $P_y = f_y = B$.\\
Rewriting, $P(x,y) = f_x(x-x0) + f_y(y-y_0) + z_0$.\\
The normal vector is $\langle \pm f_x,\pm f_y, \mp 1\rangle$.\\
So, the point normal form of the plane is
\begin{equation*}
	\langle -f_x, -f_y, 1\rangle \cdot \langle x-x_0, y-y_0, z-f(x_0,y_0) \rangle = 0
\end{equation*}

[INSERT IMAGE]


\section{Background}

\subsection{Theory}

Data collected via magnetic resonance (MR) imaging is inherently complex-valued, containing both real and imaginary (or equivalently, phase and magnitude) components (Figure~\ref{fig:Complex_Plane}).  Phase data is useful in a variety of applications, such as harmonic phase (HARP) analysis of tagged MR \cite{Osman1999}, susceptibility weighted imaging (SWI) \cite{Li2011}, and phase contrast angiography/venography .  Although phase at a given pixel can generally take on any value, it is impossible to distinguish between true ($\phi$) and principal ($\hat{\phi}$) phase values separated by an arbitrary multiple $k$ of $2\pi$, such that the measured phase value is `wrapped' within the range $(-\pi, \pi]$.  In theory, true phase may be recovered from principle phase by adding an integer multiple $k$ of $2\pi$, in a process known as `unwrapping' (Equation~\ref{eqn:PrinciplePhase}).

\begin{equation}
\label{eqn:PrinciplePhase}
\phi = \hat{ \phi } + k2\pi
\end{equation}

\begin{figure}[h] % h indicates inline
\center
\begin{tikzpicture}[scale=2.5]
\draw [very thin, lightgray] (0,0) circle [radius=1]; % circle
\draw [<->, black] (-1.2,0) -- (1.2,0); % imaginary
\draw [<->, black] (0,-1.2) -- (0,1.2); % real
\draw [->, thick, gray] (0.7071,0) -- (0.7071,0.7071); % b
\draw [->, thick, gray] (0,0) -- (0.7071, 0); % a
\draw [->, very thick, teal] (0,0) -- (0.7071,0.7071); % R
\node [above right] at (0.2,0) {$\hat{\phi}$};
\node [below] at (0.3535, 0) {$a$};
\node [right] at (0.7071, 0.3535) {$b$};
\node [above left] at (0.3535, 0.3535) {$R$};
\node [right] at (1.2, 0) {Real};
\node [above] at (0, 1.2) {Imaginary};
\end{tikzpicture}
\itkcaption[Complex_Plane]{The Complex Plane.  Here a complex number, $z$, is represented as a point on the complex plane.  $z$ can be represented equivalently in cartesian coordinates as the sum of a real and an imaginary number ($z = a+bi$) or in polar coordinates as a magnitude phase pair ($[R,\phi]$).}
\label{fig:Complex_Plane}
\end{figure}

The reverse operation, by which principle phase is obtained from its true phase, is denoted by the wrapping operator $W{}$ (Equation~\ref{eqn:Wrapping_Operator}), which can be practically implimented with the four-quadrant arctangent function (\code{std::atan2(x,y)}).

\begin{equation}
\label{eqn:Wrapping_Operator}
\hat{\phi} = \arctan( \sin( \phi ), \cos( \phi )) \equiv W \left\{ \phi \right\}
\end{equation}

Itoh \cite{Itoh1982} observed that the locally `corrected' phase gradient (i.e., the phase gradient after appropriate addition of $k2\pi$ such that the difference between adjacent pixels is in the range $(-\pi,\pi]$) may be written in terms of the wrapping operator (Equation~\ref{eqn:Wrapped_Phase_Gradient}).\footnote{$i$ is used in this submission both to refer to the mathematical constant meaning $\sqrt{-1}$, as previously, and, in this context, to pixel index along an arbitrary dimension ($0 < i < M-1$, where M is the number of pixels along that dimension).  The difference in usage should be clear from context.  Note also that the above definition only applies when both $i$ and $i-1$ are completely within the image; otherwise, $\Delta \phi_i \equiv 0$.}

\begin{equation}
\label{eqn:Wrapped_Phase_Gradient}
\Delta \phi_{i} \equiv W \left \{ \hat{\phi_{i}} - \phi_{i-1} \right \}
\end{equation}

A target pixel ($\phi_{i}$) may be `unwrapped' relative to an adjacent reference pixel ($\phi_{i-1}$) such that their difference is in the range $(-\pi, \pi]$.  This operation can be written in terms of the wrapped phase gradient (Equation~\ref{eqn:Binary_Unwrap}).

\begin{equation}
\label{eqn:Binary_Unwrap}
\phi_{i} = \phi_{i-1} + \Delta \phi_{i}
\end{equation}

\subsection{Introduction to the ITKPhase Module}

The presented module provides the unary wrap operator as a functor, \code{itk::Functor::WrapPhaseFunctor} (defined in \code{itkWrapPhaseFunctor.h}).  The following snippet demonstrates the basic use of the class.\footnote{The constant \code{vnl\_math::pi} is defined in the \code{vnl/vnl\_math.h} header file. \code{std::cout} and \code{std::endl} are defined in the \code{<iostream>} header file.}

\small
\begin{verbatim}
  itk::Functor::WrapPhaseFunctor< double > wrapFunc;

  std::cout << wrapFunc( 3 ) << std::endl; // 3
  std::cout << wrapFunc( 0 ) << std::endl; // 0
  std::cout << wrapFunc( -3 ) << std::endl; // -3
  std::cout << wrapFunc( 1 + vnl_math::pi ) << std::endl; // -2.14159
  std::cout << wrapFunc( -vnl_math::pi - 1 ) << std::endl; // 2.14159
\end{verbatim}
\normalsize

\code{itk::PhaseImageToImageFilter} (defined in \code{itkPhaseImageToImageFilter.h}) inherits from \doxygen{ImageToImageFilter} and serves as the base class for most classes in this module.

This class provides two methods, \code{Wrap(pixel)} and \code{Unwrap(target,relativeToReference)}.  The first takes one argument and provides an interface to \code{WrapPhaseFunctor} (see Equation~\ref{eqn:Wrapping_Operator}).  The second makes use of the first to unwrap one pixel relative to another (see Equation~\ref{eqn:Binary_Unwrap}).

\begin{figure}[h]
\center

\includegraphics[width=0.24\textwidth]{images/2/00a_ramp_wrapped.png}
\includegraphics[width=0.24\textwidth]{images/2/00b_ramp_unwrapped.png}
\includegraphics[width=0.24\textwidth]{images/2/00c_noise_wrapped.png}
\includegraphics[width=0.24\textwidth]{images/2/00d_noise_unwrapped.png}

\itkcaption[Simulated_Phase_Examples]{Simulated phase images, created by the \code{itk::PhaseExamplesImageSource} class.  Wrapped phase ramp (far left); wrapped phase ramp with noise patch (center left); unwrapped phase ramp (center right); unwrapped phase ramp with noise patch (far right).}
\label{fig:Simulated_Phase_Examples}
\end{figure}

For convenience, the ITKPhase module also includes \code{itk::PhaseExamplesImageSource} (defined in \code{itkPhaseExamplesImageSource.h}), which provides simple simulated phase examples for demonstrating the functionality of the module's classes.

By default, the class outputs a simple, wrapped phase ramp (Figure~\ref{fig:Simulated_Phase_Examples}, far left).\footnote{For visualization purposes, all images have been rescaled prior to writing to png.}

\small
\begin{verbatim}
  typedef itk::PhaseExamplesImageSource< WorkImageType > ExampleType;
  ExampleType::Pointer phase = ExampleType::New();
  phase->Update();
\end{verbatim}
\normalsize

A patch of additive gaussian noise can be added by calling \code{phase->SetNoise(true)} (Figure~\ref{fig:Simulated_Phase_Examples}, center right), and unwrapped versions of these images can be obtained by calling \code{phase->SetWrap(false)} (Figure~\ref{fig:Simulated_Phase_Examples}, center left and far right, respectively).  Though not demonstrated in this submission, the mean, standard deviation, and seed of the noise can be manually set using the \code{SetNoiseMean()}, \code{SetNoiseSD()}, and \code{SetNoiseSeed()} methods.


\chapter{Gravity and Geometry}
The observable universe is stable. There are two obvious configurations in which this is possible:
\begin{enumerate}
    \item Static universe, masses are arranged in a grid, all nett forces cancel.
    However small fluctuations cause the system to collapse therefore this is
    no possible description for the universe.
%TODO picture
    \item Expanding universe, all masses move away from each other, overcoming the gravitational attraction.
    Theoretically such a system can be described by using Newtonian Physics introducing additional energy contributions.
    This turns out to be inconsistent.
\end{enumerate}
Since in the second description all particles are accelerated relative to each other, there are no inertial systems.
A theory in which all observers are equal must therefore be local and thus be described by means of differential geometry.
We claim that the laws of physics are the same in every system.
If we assume that the \name{Maxwell}'s equations are right, the
Newtonian theory of gravity must be wrong.
Implications:
All free falling systems are equivalent (i.e. indistinguishable by the observer).
Light must bend, otherwise a beam could be used to deduce whether your system is inertial.
The following example illustrates that Euclidean geometry is no
adequate description of space-time.
\begin{example}[Rotating Sphere]
see Introduction to tensor calculus
%TODO copy or reference page
\end{example}
\section{Coordinate Systems}
We will start by studying coordinate systems in the flat space $\Reals^2$, which
should be familiar.
\subsection*{Cartesian Coordinates}
Cartesian coordinates are described by two coordinates $x,y$ that are measured
in two orthogonal directions from the origin. The distance $s$ between two
arbitrary points $(x_1,y_1)$ and $(x_2,y_2)$ can be calculated using
\name{Pythagoras}' theorem
\begin{equation}
    s^2=(x_1-x_2)^2+(y_1-y_2)^2\,.
\end{equation}
An infinitesimal distance is likewise given by
\begin{equation}
    \dif s^2=\dif x^2+\dif y^2\,.  \label{eq:cartline}
\end{equation}
\subsection*{Polar Coordinates}
If we describe a point in flat space by an angle $\varphi$ and an distance $r$
from the origin, we get polar coordinates. The conversion between the systems
reads
\begin{equation}
    x= r\cos\varphi\quad y= r\sin\varphi\,.
\end{equation}
A infinitival change in the polar coordinates therefore results in
\begin{align}
    \dif x&= \dpd{x}{r}\dif r+\dpd{x}{\varphi}\dif \varphi = \cos\varphi\dif
    r-r\sin\varphi\dif \varphi\,,\\
    \dif y&= \dpd{x}{r}\dif r+\dpd{y}{\varphi}\dif \varphi = \sin\varphi\dif
    r+r\cos\varphi\dif \varphi\,.
\end{align}
Plugging this into \eqref{eq:cartline} gives the line element in polar coordinates
\begin{equation}
    \dif s^2=\dif r^2+r^2\dif \varphi^2
\end{equation}
\begin{figure}[hbtp!]
\centering
 \includegraphics{cartcoord.pdf}
 \includegraphics{polarcoord.pdf}
\caption{}
%TODO Caption
\end{figure}
\begin{figure}[hbtp!]
\centering
 \includegraphics[scale=0.75]{CoordinateGridCartesian.pdf}\quad
 \includegraphics[scale=0.75]{CoordinateGridPolar.pdf}
\caption{Coordinate grids.}
%TODO Caption
\end{figure}

In matrix form
\begin{equation}
\dif s^2=
\begin{bmatrix}
\dif r& \dif \varphi
\end{bmatrix}
\begin{bmatrix}
1& 0\\
0& r^2\\
\end{bmatrix}
\begin{bmatrix}
\dif r\\ \dif \varphi
\end{bmatrix}\, .
\end{equation}
The matrix
\begin{equation}
g(\vec{r})=
\begin{bmatrix}
1& 0\\
0& r^2\\
\end{bmatrix}\, ,
\end{equation}
is called the \emph{metric}.
In general we have
\begin{equation}
    \dif s^2 = g_{ij}\dif x^i\dif x^j\, .
\end{equation}
The idea is to keep the law of inertia, i.e. particles still move on straight
line. However, we need to generalize the concept of a 'straight' line, in a
curved space.
\section{Variation Principle}
\label{sec:varprinc}
We know that straight lines are curves minimizing the distance between two
points. We generalize this concept to curved space by an variation principle.
Again we take a look at flat space, but with curved coordinates.
The length $S$ of a curve $\gamma$ with $\gamma^i(\lambda) = x^i(\lambda)$ is
given by the integral
\begin{equation}
    S=\int_{\gamma}\sqrt{\dif s^2} =
    \int_{\gamma}\sqrt{\tensor{g}{_i_j}\dif \tensor{x}{^i}\dif
    \tensor{x}{^j}}=\int_{a}^{b}\sqrt{\tensor{g}{_i_j}\dod{\tensor{x}{^i}}{\lambda}
    \dod{\tensor{x}{^j}}{\lambda}}\dif \lambda\, .
\end{equation}
As stated above generalised straight lines satisfy $\delta S = 0$. If we define
$L:=\left(\tensor{g}{_i_j}\od{\tensor{x}{^i}}{\lambda}
\od{\tensor{x}{^j}}{\lambda}\right)^{\nicefrac{1}{2}}$, $S$ takes a form
familiar from classical mechanics:
\begin{equation}
    S=\int_a^b L\dif \lambda\, .
\end{equation}
The extremal condition implies the Euler Lagrange equations
\begin{equation}
    \dod{}{\lambda}\pd{L}{\left(\pd{\tensor{x}{^i}}{\lambda}\right)}
    -\pd{L}{\tensor{x}{^i}}
    =0\, .		\end{equation}
We can calculate the relevant terms to
\begin{align}
\dpd{L}{\tensor{x}{^i}}&=\frac{1}{2\sqrt{g_{ij}\od{x^i}{\lambda}
\od{x^j}{\lambda}}}\tensor{g}{_j_k_{,i}}\dod{x^j}{\lambda}
\dod{x^k}{\lambda}\,,\\
\dpd{L}{\left(\pd{\tensor{x}{^i}}{\lambda}\right)}
&=\frac{1}{\sqrt{g_{ij}\od{x^i}{\lambda}
\od{x^j}{\lambda}}}\tensor{g}{_j_i}\dod{x^j}{\lambda}\, .
\end{align}
If we choose the parameter $\lambda$ so that we are parametrised by the arc
length\footnote{this is impossible for null i.e. lightlike geodesics, it can be
shown however, that the resulting equation also holds true for null geodesics.}
i.e.
\begin{equation}
\od{}{\lambda}\left(\sqrt{g_{ij}\od{x^i}{\lambda}\od{x^j}{\lambda}}\right)=0\,,
\end{equation}
the Euler Lagrange equations simplify to
\begin{equation}
0=\frac{1}{\sqrt{\tensor{g}{_i_j}\od{\tensor{x}{^j}}{\lambda}
\od{\tensor{x}{^j}}{\lambda}}}\dod{}{\lambda}
\left(\tensor{g}{_j_i}\dod{\tensor{x}{^j}}{\lambda}\right)
-\frac{1}{2\sqrt{\tensor{g}{_i_j}\od{x^i}{\lambda}
\od{\tensor{x}{^j}}{\lambda}}}\tensor{g}{_j_k_{,i}}\dod{\tensor{x}{^j}}{\lambda}
\dod{\tensor{x}{^k}}{\lambda}\,,
\end{equation}
or equivalently
\begin{equation}
\begin{split}
0
&=\dod{}{\lambda}\left(\tensor{g}{_j_i}\dod{\tensor{x}{^j}}{\lambda}\right)
-\frac{1}{2}\tensor{g}{_j_k_{,i}}\dod{x^a}{\lambda}
\dod{x^k}{\lambda}\\
&=\tensor{g}{_j_i_{,k}}\dod{\tensor{x}{^j}}{\lambda}\dod{\tensor{x}{^k}}{\lambda}
+\tensor{g}{_j_i}\dod[2]{\tensor{x}{^j}}{\lambda}
-\frac{1}{2}\tensor{g}{_j_k_{,i}}\dod{\tensor{x}{^j}}{\lambda}\\
&=\tensor{g}{_j_i}\dod[2]{\tensor{x}{^j}}{\lambda}
+\frac{1}{2}\left(\tensor{g}{_j_i_{,k}}+\tensor{g}{_i_j_{,k}}
-\tensor{g}{_j_k_{,i}}\right)\dod{\tensor{x}{^j}}{\lambda}
\dod{\tensor{x}{^k}}{\lambda}\label{eq:PreGeo}\,.
\end{split}
\end{equation}
The term invoking derivatives of the metric defines the \emph{Christoffel
symbols of the first kind}
\begin{equation}
    \csym{j}{k}{i}:=\frac{1}{2}
    \left(\tensor{g}{_j_i_{,k}}+\tensor{g}{_i_j_{,k}} -\tensor{g}{_j_k_{,i}}\right)\, .
\end{equation}
It is convenient to multiply \eqref{eq:PreGeo} by the inverse metric $g^{li}$ so
that we obtain the \emph{geodesic equation}
\begin{equation}
    0 =
    \od[2]{\tensor{x}{^l}}{\lambda}
    +\cSym{l}{j}{k}\od{\tensor{x}{^j}}{\lambda}\od{\tensor{x}{^k}}{\lambda}\,
    .\label{eq:geodeq}
\end{equation}
Where $\cSym{l}{j}{k}$ are the \emph{Christoffel symbols of the second kind}
\begin{equation}
    \cSym{l}{j}{k}:=g^{li}\csym{j}{k}{i}=\frac{1}{2}g^{li}
    \left(\tensor{g}{_j_i_{,k}}+\tensor{g}{_i_j_{,k}} -\tensor{g}{_j_k_{,i}}\right)\, .
\end{equation}
% remark is obsolete as long as bracket notation for christoffel symbols is used
%\begin{remark}
%Although the notation looks as the Christoffel symbols form a tensor, however
% they do not.
%\end{remark}
In flat space we have $\tensor{g}{_i_j}=\tensor{\eta}{_i_j}$ and can easily
check that all Christoffel symbols vanish. We therefore recover the ordinary equation of motion for a free particle
\begin{equation}
    0 = \od[2]{\tensor{x}{^i}}{\lambda}\, .
\end{equation}
\begin{figure}[hbtp!]
\centering
 \includegraphics{sphere_geodesics1.pdf}
\caption{Great circles are geodesics, i.e. shortest connections of points, on
a sphere.}
%TODO Caption
\end{figure}
\begin{figure}[hbtp!]
\centering
 \includegraphics{WorldlineLightcones.pdf}
\caption{}
%TODO Caption
\end{figure}

% \begin{example}
% Suppose a observer follows a free falling body in a homogeneous field.
% Therefore a transformation between the system of the earth and the one of the body are given by
% (for simplicity we only consider the coordinate along it is falling)
% \begin{equation}
%     (t,x)\to\left(t,x-\frac{1}{2}gt^2\right)
% \end{equation}
% Analogous to the Riemannian case discussed before, the line element takes the form
% \begin{equation}
%     \begin{split}
% \dif s^2&=-\dif t^2 +\dif x^2\\
% &=-\dif t'^2+(\dif x'- gt\dif t')(\dif x'- gt\dif t')\\
% &=(g^2t'^2-1)\dif t'^2-2gt\dif x'\dif t'+\dif x'^2
% \end{split}
% \end{equation}
% \end{example}
% \section{Newtonian Limit}


\section{Introduction}
This paper is a brief summary of differential algebra. We will discuss some introductory defintions and theorems and, later on, some examples. Basic knowledge of commutative algebra is required. We assume each ring $R$ to be commutative and unital. Furthermore, we omit subscripts where they can be inferred from context. The dual of an $R$ module $M$ is denoted by $M^*$.
\subsection{Basics}
Let $R$ be a ring and $A$ an $R$ algebra, that is $A$ is an $R$ module with $R$ linear map
$$\mu : A \otimes A \longrightarrow A,\ a \otimes a' \longmapsto a a'.$$
We denote an algebra $A$ with multiplication $m$ by $(A, \mu)$. We call $A$ associative if
$$\xymatrix{
A^{\otimes 3} \ar[r]^{\mu \otimes id_A} \ar[d]_{id_A \otimes \mu} & A^{\otimes 2}\ar[d]^{\mu}\\
A^{\otimes 2} \ar[r]_{\mu} &A\\
}$$
commutes. We call a map $\eta \in \mathrm{Hom}(R,A)$ unit map if
$$\xymatrix{
&A^{\otimes 2}\ar[d]^\mu&\\
R \otimes A \ar[r]_{\simeq}\ar[ru]^{\eta \otimes id_A} &A&A \otimes R \ar[lu]_{id_A \otimes \eta}\ar[l]^\simeq\\
}$$
commutes. In this case, we call $A$ a unital algebra over $R$ (denoted by $(A, \mu, \eta)$).
\subsubsection{Derivations}
\begin{defi}[Leibniz-rule]
We call a map $\partial \in \mathrm{End}_R(A)$ an $R$ derivation if
$$\partial(a a') = \partial(a) a' + a \partial(a'),\ \forall a, a' \in A.$$
A unital (associative) algebra $(A, \mu, \eta)$ with derivation $\partial$ is denoted by
$$(A, \mu, \eta, \partial).$$
The subset $B \subset A$ with $\partial(b) = 0$ for all $b \in B$ is called the set of constants and is denoted by
$$A^\partial := \{a \in A : \partial(a) = 0\}.$$
\end{defi}
From this definition we get
\begin{koro}
Let $A$ and $A^\partial$ be as above and let $A^\times = \{b \in A : \exists b' \in A, b b' = 1_A\} \neq \emptyset$.
\bn
\item The set of constants $A^\partial$ is an $R$ subalgebra of $A$,
\item the unit $1_A \in A$ is constant and
\item if $A$ is a division algebra (field) then $A^\partial$ is a division algebra (field).
\en
\end{koro}
\bws is straight forward.
\bn
\item Clearly, $A^\partial$ is an $R$ submodule. Thus, it suffice to show that $A^\partial$ is an algebra over $R$. Let $a, a' \in A^\partial$ then
$$\partial(a a') = \partial(a) a' + a \partial(a') = 0 \cdot a' + a \cdot 0 = 0$$
proving that products of constants are also constant.
\item Let $2 \neq \chr R$. By definition, we have
$$\partial(1_A) = \partial(1_A \cdot 1_A) = \partial(1_A) 1_A + 1_A \partial(1_A) = 2 \partial(1_A) \Leftrightarrow 0 = \partial(1_A)$$
showing our claim, in parts. Let us assume that $\chr R = 2$ and fix some $n \in 2 \nz$ (i.e. an even number). We have that
$$1_A = \underbrace{1_A \cdot \ldots \cdot 1_A}_{n-\mathrm{times}} \Rightarrow \partial(1_A) = \sum_{i=1}^n \underbrace{1_A \cdot \ldots \cdot 1_A}_{n-1\mathrm{-times}} \partial(1_A) = 0 \mod 2$$
again showing our assumption under given circumstances. Note, that an odd $n$ would yield
$$\partial(1_A) = \partial(1_A) \Leftrightarrow \partial(0) = 0.$$
\item If $a \in A^\times \cap A^\partial := \{b \in A^\partial : \exists b' \in A, b b' = 1_A\}$ and $a^{-1} \in A^\times$ its inverse then:
$$\partial(a a^{-1}) = \partial(1_A) \stackrel{!}{=} 0 = \partial(a) a^{-1} + a \partial(a^{-1}) = a \partial(a^{-1}) \Leftrightarrow a^{-1} \in A^\partial.$$
\en
\bmk Obviously, the algebra of constants over any differential ring $(R, \partial)$ is called the ring of constants. As we just saw, a differential division algebra has a division algebra as algebra of constants, therefore we get that the ring of constants of a differential field is a field.
\bsp Let $R$ be a ring.
\bn
\item With $\chr R = 0$ then $\left(R[X],\mu_{R[X]}, \eta, \partial = \left[X \longmapsto 1_R\right]\right)$ has $R$ as its sole ring of constants.
\item With $\chr R = p$, the ring of constants can be non-trivial - let $p \in \zz_{>0}$ be prime:
$$
\bao{rrcl}
\partial : &R[X^p] &\longrightarrow& R[X^p],\\
&&&\\
&\sum r_k X^{p^k}& \longmapsto& \sum r_k \partial\left(X^{p^k}\right)\\
&&&\\
&& = & \sum r_k p^k X^{p^k-1}\partial(X)\\
&&&\\
&&=& 0\\
\ea$$
Thus, in prime characterisic, the ring of constants is strictly larger than $R$: $R[X]^\partial = R[X^p]$.
\en

\section{Generalisations}
There are two prominent ways to formalise and generalise the concept of derivations and their algebras.
\subsection{Lie Algebras}
The first way of formalisations are Lie algebras.
\begin{defi}

An $R$ algebra $(\lieg,\mu)$ is called a Lie algebra if $\mu : \lieg \otimes \lieg \longrightarrow \lieg$ fulfills:
\bn
\item Jacobian identity:
$$\sum_{i=0}^2 \mu \circ (\mu \otimes id_{\lieg}) \circ \sigma_3^i(g_1 \otimes g_2 \otimes g_3) = 0,\ \mathrm{for~all}\ g_1 \otimes g_2 \otimes g_3 \in \lieg^{\otimes 3}.$$
Here, $\sigma_3 := (1,2,3) \in \mathrm{Gl}_R(\lieg^{\otimes3})$ is a $3$-cycle with $\sigma_3^3 = id$.
\item Antissymmetry:
$$\mu \circ \tau = - \mu,\ \mathrm{for}\ \tau = [g \otimes h \longmapsto h \otimes g].$$
\en
\end{defi}
\begin{koro}
Given any associative algebra $(A,\mu)$:
\bn
\item The commutator
$$[,] = [a \otimes b \longmapsto \mu(a \otimes b) - \mu(b \otimes a)] = \mu - \mu \tau,$$
defines a Lie algebra $(\lieg(A),[,])$ on $A$. As $R$ modules, they are identical.
\item The module of $R$ derivations on $A$ forms a Lie algebra $\mathrm{Der}_R(A)$ with commutator
$$[,] : \lieg(\mathrm{End}_R(A)) \otimes \lieg(\mathrm{End}_R(A)) \longrightarrow \lieg(\mathrm{End}_R(A)),$$
restricted to the sub Lie algebra.
\en
\end{koro}
\bmk The proof is left to the reader. We shall extend our
\begin{defi}
Let $(\lieg,\mu)$ be an $R$-Lie algebra. We call an $R$-submodule $\lieh \subset \lieg$ an $R$-Lie subalgebra if
$$(\lieh,\mu\mid_{\frk{h}}) \subset (\lieg,\mu)$$
is a Lie algebra in its own right. Given two Lie algebras $(\lieg,\mu_{\lieg})$ and $(\lieh,\mu_{\lieh})$ and a homomorphism $f \in \mathrm{Hom}_R(\lieg,\lieh)$. We call $f$ a homomorphism of Lie algebras if
$$\xymatrix{
\lieg^{\otimes 2}\ar[r]^{f\otimes f}\ar[d]_{\mu_{\lieg}}&\lieh^{\otimes 2}\ar[d]^{\mu_{\lieh}}\\
\lieg \ar[r]_f& \lieh\\
}$$
commutes. We call a Lie subalgebra $\liea \subset \lieg$ a Lie ideal if
$$\mu(\liea \otimes_R \lieg) \subset \liea.$$
We call a Lie algebra $\lieg$ nilpotent if each sequence $(g_n) \in \lieg^{\nz}$ with
$$\mu^{n-1}(g_1 \otimes g_2 \otimes \ldots \otimes g_n) = 0$$
has finite length. Here, $\mu^n := \mu^{n-1}(\mu \otimes id_{\lieg^{\otimes (n - 1)}})$, $\mu^0 = id_\lieg$ and $\mu^1 = \mu$. For each Lie algebra $\lieg$ we get a chain of descending ideals: the so called $n$-th derived Lie algebra:
$$\mathcal{D}^n(\lieg) := \mu(\mathcal{D}^{n-1}(\lieg) \otimes \lieg),\ \mathrm{and}\ \mathcal{D}^0(\lieg) = \lieg.$$
We call $\lieg$ solvable if $\mathcal{D}(\lieg) = \mathcal{D}^1(\lieg)$ is nilpotent.
\end{defi}

\bsp Let $R$ be a ring and $A = R[X]$ - its ring of polynomials. The endomorphism $\partial_X = [X \longmapsto 1] \in \mathrm{End}_R(A)$ is the classical example of a non-trivial $R$-derivation. Moreover, $\mathrm{Der}_R(R[X])$ contains $R[X]$-left modules:\\
\indent Claim: for any derivation $\partial : R[X] \longrightarrow R[X]$, the $R$-submodule
$$R[X].\partial \subset \der{R[X]}$$
is an $R[X]$-left module in $\der{R[X]}$.
\paragraph{Proof} Given a derivation $\partial \in \der{R[X]}$ and two polynomials $p, q \in R[X]$:
$$\bao{rcl}
[p \partial,q \partial] &=& p \partial(q \partial) - q \partial(p \partial)\\&&\\ &=& p \partial(q) \partial + p q \partial^2 - q \partial(p) \partial - q p \partial^2\\
&&\\
&=& (p \partial(q) - q \partial(p)) \partial + (p q - p q) \partial^2\\
&&\\
&=& (p \partial(q) - q \partial(p)) \partial \in R[X].\partial\\
\ea$$
\bmk This proof actually applies to any differential algebra - given any derivation $\partial \in \dera$, the $R$-submodule $R . \partial$ generates an $A$-left submodule in $\dera$.
\begin{defi}

\end{defi}
\subsection{Coalgbras}
Speaking in a categorical manner, for every ring $R$ algebras are the dual category of the category of $R$ coalgebras. We compare the diagrams defining algebras and coalgebras. Again, $(A, \mu, \eta)$ is an unital associative $R$ algebra - we call an $R$ module $C$ a coalgebra if there is an $R$ linear map $\Delta : C \longrightarrow C^{\otimes2}$. In addition, we call a coalgebra $(C, \Delta)$ coassociative or counital for a given $\eps \in \mathrm{Hom}(C,R) = C^\ast$ if
$$(\eps \otimes id_C) \Delta = (id_C \otimes \eps) \Delta = id_C$$
and the following diagrams commute:
\begin{longtable}{|c|cc|}
\hline
Coalgebras: &$$
\xymatrix{
C^{\otimes 3}  & C^{\otimes 2}\ar[l]_{id_C \otimes \Delta}\\
C^{\otimes 2} \ar[u]^{\Delta \otimes id_C}&C\ar[l]^{\Delta} \ar[u]_{\Delta}\\
}$$
&$$
\xymatrix{
&C^{\otimes 2}\ar[ld]_{\eps \otimes id_C}\ar[rd]^{id_C \otimes \eps}&\\
R \otimes C  &C\ar[u]_\Delta\ar[r]_{\simeq}\ar[l]^\simeq&C \otimes R \\
}$$\\
&Coassociativity & Counitality\\
\hline
&&\\
Algebras: &$$
\xymatrix{
A^{\otimes 3} \ar[r]^{\mu \otimes id_A} \ar[d]_{id_A \otimes \mu} & A^{\otimes 2}\ar[d]^{\mu}\\
A^{\otimes 2} \ar[r]_{\mu} &A\\
}$$
&$$
\xymatrix{
&A^{\otimes 2}\ar[d]^\mu&\\
R \otimes A \ar[r]_{\simeq}\ar[ru]^{\eta \otimes id_A} &A&A \otimes R \ar[lu]_{id_A \otimes \eta}\ar[l]^\simeq\\
}$$\\
&Associativity & Unitality\\
\hline
\end{longtable}
Clearly, each column is simply the inversion of arrows within the respective diagram. More interesting is the fact that the dual module $C^\ast$ for each coalgebra $(C, \Delta, \eps)$ is an algebra with multiplication
$$\mu_{C^\ast} := \Delta^\ast = \left[\alpha \otimes \beta \longmapsto (\alpha \otimes \beta) \Delta = \left[c \longmapsto \mu_R(\alpha \otimes \beta)\Delta(c) = \sum_{(c)} \alpha(c_{(1)}) \beta(c_{(2)})\right]\right],$$
with Sweedler notation $\Delta(c) = \sum_{(c)} c_{(1)} \otimes c_{(2)}$ and $\mu_R$ denoting the multiplication on $R$. With the dual of the counit we get a unit: $\eta_{C^\ast} = \eps^\ast = [1_R \longmapsto \eps]$.\\
We call a coalgebra $C$ cocommutative if
$$\xymatrix{
&C \ar[rd]^\Delta \ar[dl]_\Delta&\\
C^{\otimes2} \ar[rr]_\tau &&C^{\otimes2}\\
}$$
commutes for $\tau : C^{\otimes2} \longrightarrow C^{\otimes2}, c \otimes c' \longmapsto c' \otimes c$ the flip isomorphism.
\subsubsection{Group-likes and skew primitives}
Unless stated otherwise, we will always assume a coalgebra $C$ to be coassociative and counital.
\begin{defi}
We call an element $c \in C$ group-like if
$$\Delta(c) = c \otimes c.$$
We call an element $c$ $(g,h)$ skew primitive, for two group-like elements $g, h \in C$, if
$$\Delta(c) = g \otimes c + c \otimes h.$$
\end{defi}
Firstly, a group-like element $c \in C$ has $\eps(c) = 1$ as $(id_C \otimes \eps)\Delta(c) = id(c) \otimes \eps(c) = \eps(c) c \stackrel{!}{=} 1 \Leftrightarrow \eps(c) = 1$. Secondly, for two group-like $g, h \in C$ we have that a $(g,h)$ skew primitive element $c \in C$:
$$\bao{rcl}
c &\stackrel{!}{=}& (id_C \otimes \eps)\Delta(c) = id_C(g) \otimes \eps(c) + id_C(c) \otimes \eps(h)\\
&&\\
&\stackrel{!}{=}& (\eps \otimes id_C)\Delta(c) = \eps(g) \otimes id_C(c) + \eps(c) \otimes id_C(h)\\
\Leftrightarrow\\
\eps(c) &=& 0\\
\ea$$
\bmk Consider Skew primitive elements are, in essence, a generalisation of derivations - each derivation is simply a