\subsection{Overall Approach}
\label{approach_approach}

On a conceptual level, there are three distinct aspects of the model
    development process.
First, a pre-processing step transforms the platform's tabular order data into
    either time series in Sub-section \ref{grid} or feature matrices in
    Sub-section \ref{ml_models}.
Second, a benchmark methodology is developed in Sub-section \ref{unified_cv}
    that compares all models on the same scale, in particular, classical
    models with ML ones.
Concretely, the CV approach is adapted to the peculiar requirements of
    sub-daily and ordinal time series data.
This is done to maximize the predictive power of all models into the future
    and to compare them on the same scale.
Third, the forecasting models are described with respect to their assumptions
    and training requirements.
Four classification dimensions are introduced:
\begin{enumerate}
\item \textbf{Timeliness of the Information}:
    whole-day-ahead vs. real-time forecasts
\item \textbf{Time Series Decomposition}: raw vs. decomposed
\item \textbf{Algorithm Type}: "classical" statistics vs. ML
\item \textbf{Data Sources}: pure vs. enhanced (i.e., with external data)
\end{enumerate}
Not all of the possible eight combinations are implemented; instead, the
    models are varied along these dimensions to show different effects and
    answer the research questions.


\section{Ensemble Methods}

\smallskip \hrule height 2pt \smallskip

Vocab
\begin{itemize}
	\item \textbf{decision tree stump}:
	\item \textbf{decision stub}:  (used in lecture 10 pg 14: boosting)  ?? horizontal or vertical line only?
	\item \textbf{axis aligned classifier}
\end{itemize}

Instead of learning a single classifier, learn many weak classifiers that are good at different parts of the data.
The output class is a weighted vote of each classifier.
\begin{itemize}
	\item classifiers that are most "sure" will vote with more conviction
	\item classifiers will be most "sure" about a particular part of the space.
	\item on average, these will do better than a single classifier.
\end{itemize}

% transcribed understanding of audio from week 8
This is better than breaking up the space into a bunch of sub-spaces and making single classifiers for each.
If you had single classifiers for sub-spaces, you would be losing information about the surroundings.
It is better to have all classifiers cover the whole space, but let them vote.

\subsection{Bagging vs Boosting}
\textbf{Bagging:} % http://stats.stackexchange.com/questions/18891/bagging-boosting-and-stacking-in-machine-learning
\begin{itemize}
	\item parallel ensemble: each model is built independently
	\item aim to decrease variance, not bias
	\item suitable for high variance low bias models (complex models)
	\item \textbf{samples are drawn with replacement}
	\item each model in the ensemble vote with equal weight % https://en.wikipedia.org/wiki/Ensemble_learning
	\item an example of a tree based method is random forest, which develop fully grown trees (note that RF modifies the grown procedure to reduce the correlation between trees)
\end{itemize}

\textbf{Boosting:}  % http://stats.stackexchange.com/questions/18891/bagging-boosting-and-stacking-in-machine-learning
\begin{itemize}
	%\item sequential ensemble: try to add new models that do well where previous models lack
	\item \textbf{incrementally building an ensemble by training each new model instance to emphasize the training instances that previous models mis-classified.}
	\item aim to decrease bias, not variance
	\item suitable for low variance high bias models
	\item an example of a tree based method is gradient boosting
	\item In some cases, boosting has been shown to yield better accuracy than bagging, but it also tends to be more likely to over-fit the training data. % https://en.wikipedia.org/wiki/Ensemble_learning
	\item AdaBoost is the most common
\end{itemize}

\subsection{Bagging}
\textbf{"Bagging" = \underline{B}ootstrap \underline{AGG}regation.}
For $i = 1, 2, \dots, K$:   (?? translate to english ??)
\begin{itemize}
	\item $T_i \leftarrow$ randomly select $M$ training instances with replacement.
	\item $h_i \leftarrow$ learn($T_i$)
\end{itemize}
Then combine the $h_i$ together with uniform voting ($w_i = 1/K$ for all $i$).

\subsubsection{Example: CART decision boundary}
CART is a decision tree learning algorithm. \hfill \\

100 bagged trees:  shades of blue/red indicate the strength of votes for particular classifications. \hfill \\
Picked random subsets of the data, and built classifiers.  These classifiers are weighted!! \hfill \\  % week 8 audio
?? (not the strength of different classifiers.)   \hfill \\
?? Is white an overall uncertain vote ??   \hfill \\
\includegraphics[width=2in]{figures/100_bagged_trees.pdf} \hfill \\
Approximating the circle with a set of lines.  Piecewise linear functions. \hfill \\ % wk 8 audio
The more trees you have, the smoother the boundary will be.

\subsubsection{Fighting the bias-variance tradeoff}
Simple (a.k.a. weak) learners are good. \hfill \\
Examples of weak learners we can use: \hfill \\
Naive Bayes, logistic regression, perceptron, decision stumps, shallow decision trees, etc. \hfill \\
These learners have low variance; they don't usually overfit.

But simple (a.k.a. weak) learners are also bad: \hfill \\
They have high bias (high error), so you can't solve hard learning problems. \hfill \\

The solution: Boosting.

\subsection{Boosting}

\underline{TA summary:} \hfill \\
We take a "weak" learner (e.g. a decision tree with depth 1), and learn the optimal classifier $h_1$.
We then reweight the data points, increasing the relative weight of the misclassified points, and learn an optimal classifier $h_2$ which is heavily biased against mislabelling the same points.
We repeat this process, and output a final classifier which uses a linear combination of the weak learners' predictions: $H(x) = sgn(\sum_t \alpha_t h_t(x))$.
Although the weak learners may have high-bias, and therefore simple decision boundaries, the "strong" classifier can be a complicated decision boundary.

\begin{itemize}
	\item Combine	weak	classifiers	to get very strong classifier.
		The weak classifiers only have to be slightly better than random on the training data.
		You end up with a very strong classifier.  You can get zero training error.
	\item AdaBoost is the most common algorithm
	\item Similar to logistic regression:
		\begin{itemize}
			\item both linear models.  Boosting "learns" features.
			\item similar loss functions
			\item single optimization (Logistic Regression) versus incrementally improving classification (Boosting)
		\end{itemize}
	\item  boosting with a weak classifier is better than using a fancy classifier.
		A boosted version will always do better than the vanilla one.
\end{itemize}

An approach to calculate the output using several different models and then average the result using a weighted average approach.
By combining the advantages and pitfalls of these approaches by varying your weighting formula you can come up with a good predictive force for a wider range of input data, using different narrowly tuned models.  % http://stats.stackexchange.com/questions/18891/bagging-boosting-and-stacking-in-machine-learning

Boosting is ensemble method. \hfill \\
\underline{The idea}: given a weak learner, run it multiple times on (reweighted) training data,
	then let the learned classifiers vote.  \hfill \\

On each iteration $t$:
\begin{itemize}
	\item weight each training example by how incorrectly it was classified.
	\item learn a hypothesis: $h_t$
	\item Use strength $\alpha_t$ for this hypothesis.
\end{itemize}
Final classifier: $\displaystyle h(x) = sign \left( \sum_i \alpha_i h_i(x)  \right)$ \hfill \\
This is both useful in a practical sense and theoretically interesting.

Can use boosting with any kind of classifier.  %https://www.youtube.com/watch?v=UHBmv7qCey4

\subsection{Bagging}

Stands for Bootstrap Aggregation. \hfill \\
The way decrease the variance of your prediction by generating additional data for training from your original dataset using combinations with repetitions to produce multisets of the same cardinality/size as your original data. By increasing the size of your training set you can't improve the model predictive force, but just decrease the variance, narrowly tuning the prediction to expected outcome.  % http://stats.stackexchange.com/questions/18891/bagging-boosting-and-stacking-in-machine-learning

\textbf{Bagging allows encoding a curvy decision boundary} with a bunch of weak classifiers. \hfill \\
 \hfill \\

By averaging a bunch of low bias, high variance functions, we can reduce the variance without significantly increasing the bias. \hfill \\

Making a strong classifier out of a set of weak classifiers. \hfill \\
\hfill \\

We should always avoid making hard decisions early.  % week 8 audo.
So don't put a lot of trust in classifiers early on in bagging.
If we did, the result might not generalize well.  \hfill \\

Instead, pay more attention to the ones you got wrong and less attention to the ones we got right.  % week 8 audio

We want instance based weighting, not classifier based weighting.  % week 8 audio

We want to have weights for each instance. \hfill \\
\underline{Protocol:}  % week 8 audio
\begin{itemize}
	\item Start with uniform weights.  Each value is equally important.
	\item Train classifier 1.  After this, instances are not equally important.
	\item The points classifier 1 got correctly are now considered less important.
	\item We want classifier 2 to be more worried about the ones that we got wrong.
\end{itemize}

\subsubsection{Example}
\includegraphics[width=2.5in]{figures/bagging_example.pdf}  \hfill \\
After making 300 classifiers, we can get a step-like decision boundary.
Stopping at 100 would have been better; it is not over-fit (not shown).  \hfill \\

The blue, green, yellow, and red lines:   % I e-mailed the forum to figure this out.
\begin{itemize}
	\item blue = training error = same as usual.  Randomly choose a subset to hold-out for testing
	\item green = test error = same as usual.  Randomly choose a subset to hold-out for testing
	\item yellow = hypothesis error = the error of the new weak learner generated on that step
			(i.e. a decision stump) \hfill \\
		"Last classifier we added was 38\% wrong. "
		for time = 100 when Hypothesis error said 0.38
	\item red = theoretical bound = the bound on the training error, derived in the later slides
\end{itemize}
% TA: Training/test sets are selected as always: randomly choosing a subset to hold-out for testing. Hypothesis error tells you the error of the new weak learner generated on that step (i.e. a decision stump). Theoretical bound is the bound on the training error, derived in the later slides.

\subsubsection{Learning from weighted data}
Consider a weighted data set: \hfill \\
\begin{itemize}
	\item $D(i)$ is the weight of the $i^{th}$ training example/point (not classifier!).
		It gets bigger each time point $i$ is predicted incorrectly.
		It doesn't get smaller, but you normalize (see below).
		\hfill \\
		Point = $(\bm{x}^i, \bm{y}^i)$
	\item interpretations:
		\begin{itemize}
			\item the $i^{th}$ training example counts as if it occurred $D(i)$ times
			\item these extra counts mean that if we were to "resample" data,
				we would get more samples of "heavier" data points.
		\end{itemize}
	\item Now we always do weighted calculations:
		\begin{itemize}
			\item e.g. MLE for Naive Bayes
			\item redefine Count(Y=y) to be a weighted count: \hfill \\
				$\displaystyle Count(Y=y) = \sum_{j=1}^n D(j) \delta (Y^j = y)$
			\item ?? Is this counting the number of points we have right?? No.. what is it counting?
			\item if point $j$ has been wrong many times before,
					it becomes more important, as reflected by $D(j)$ being large.
			\item setting $D(j) = 1$ (or any constant value!) for all $j$ recreates the unweighted case.
		\end{itemize}
\end{itemize}

Note, we can use decision stumps for boosting.  Can also use logistic regression, but it isn't as easy to show as our clas stump example.  \hfill \\
\hfill \\

That's just about weighing the samples.  How do we weight the classifiers?
We want to weight across \underline{all} data points.
Use $\alpha$ to allow classifiers to have different votes.

\subsubsection{Algorithm: Binary case}
\underline{Given}: points $(x^1, y^1), \dots, x^m, y^m$.  \hfill \\
For this case, $x^i \in \mathbb{R}$, and binary labels: $y^i \in \{-1, +1\}$ \hfill \\
\underline{Initialize}: $D_1(i) = 1/m$ for $i=1, \dot, m$.  \hfill \\
For $t = 1, \dots, T:$
\begin{itemize}
	\item Train base classifier $h_t(x)$ using $D_t$
	\item Chose the weight of importance for this classifier, $\alpha_t$. \hfill \\
		Note that this comes after training the classifier.  \hfill \\
		There are many possibilities for choosing $\alpha$, which are discussed later.  \hfill \\
	\item Update, for $i= 1 \dots m$:  \hfill \\
		$D_{t+1}(i) \propto D_t(i) exp(-\alpha_t y^i h_t(x^i))$ \hfill \\
				with normalization constant $\displaystyle \sum_{i=1}^M D_t(i) \exp(-\alpha_t y^i h_t(x^i))$
		\begin{itemize}
			\item The $D$ is getting reweighted for the next round.  \hfill \\
			What's happening inside: \hfill \\
			If $y^i h_t(x^i) > 0$, $h_i$ was correct.  \hfill \\
			But if $y^i h_t(x^i) < 0$, $h_i$ was wrong.  \hfill \\
			You multiply by $\alpha_t$, which can flip the sign inside the $\exp()$. \hfill \\
			If $h_i$ is correct and $\alpha > 0$, then $D_{t+1}(i) < D_t(i)$.  \hfill \\
			But if $h_i$ is wrong and $\alpha > 0$, then $D_{t+1}(i) > D_t(i)$.  \hfill \\
		\end{itemize}
	\item Output a final classifier: $\displaystyle h = sign \left( \sum_{i=1}^T \alpha_t h_t(x) \right)$ \hfill \\
		This is a linear sum of "base" (weak) classifier outputs. \hfill \\
		Note that $D$ is no longer in the picture.
\end{itemize}
If you had two classifiers, your result would be $\alpha_1 h_1 + \alpha_2 h_2$

\textbf{How to chose $\alpha$}: \hfill \\
First calculate $\displaystyle  \epsilon_t = \sum_{i=1}^m D_t(i) \delta(h_t(x^i \neq y^i)))$ \hfill \\
This is the error of $h_t$, weighted by $D_t$ \hfill \\
Then use $\displaystyle  \alpha_t = \frac{1}{2} \ln \left( \frac{1 - \epsilon_t}{\epsilon_t} \right)$  (derived below) \hfill \\
This transforms alpha according to:  \hfill \\
\includegraphics[width=1.2in]{figures/alpha_from_epsilon.pdf}
\begin{itemize}
	\item no errors:  $\epsilon_t = 0 \rightarrow \alpha_t = \infty$
	\item all errors:  $\epsilon_t = 1 \rightarrow \alpha_t = -\infty$
	\item random:  $\epsilon_t = 0.5 \rightarrow \alpha_t = 0$
\end{itemize}
Truncate at 2 or 3.  Don't want to allow weight = infinity. \hfill \\  % week 9 audio
Think of this like NB with weighting. \hfill \\  % week 8 audio.
\underline{Why would we want/have negative weights on classifiers?} \hfill \\
A classifier that does worse than chance is backwards.
If it is worse than chance, flip the sign then use it.
A classifier that is wrong 90\% of the time is a good classifier.
A truly random classifier does not provide information.  Thow those away.

\hfill \\
If you get something right a bunch of times, the weight should converge to zero.  % week 8 audio
\hfill \\

We want to run this loop until it converges.
But if we run it too long, it will overfit.

\subsubsection{How to chose $\alpha_t$ for hypothesis $h_t$?}
It would be cool to find the $\alpha_t$ that works best for that classifier, take derivative with respect to $\alpha_t$, and find an $\alpha$ that minimizes error. \hfill \\
We can't optimize the training set error, but we can minimize a bound on it. \hfill \\
$\displaystyle  \sum_{i=1}^m \delta(H(x^i) \neq y^i) \leq \sum_{i=1}^m D_t(i) \exp(-y^i f(x^i))$ \hfill \\
where $\displaystyle f(x) = \sum_t \alpha_t h_t(x)$; $H(x) = sign(f(x))$ \hfill \\
\includegraphics[width=2.5in]{figures/chosing_alpha_step_func.pdf}

We know the training set error (\# of instances wrong) it is bounded by the sum on the right.
Why?  The left side of the equality is the left piece of the step function.
The exponential function of label*prediction has the expo curve.
Note that \textbf{the exponential curve is always above the step function}.
So we can use expo as the upper bound.
This is kind of like logistic regression: same form.

% --------
\subsubsection{You can choose $\alpha_t$ to minimize the error bound.}
Note that each classifier is independent of alpha.
Each classifier is already a classifier by itself.
We want to train the weighted combinations of classifiers.
Note we are not directly using the error.
We are using a function that maps the error to a \# we can use.
That's the role of the alpha vs epsilon curve.
We liked its properties.
There are two parameters in the $\exp()$:  $h$ and $\alpha.$
You can optimize for h and alpha together.
We have a way to make the classifier sand learn the weights at the same time.
We might still learn the classifiers first.
For those of you who care about joint optimization, you can flip between optimizing the two.

\includegraphics[width=2.7in]{figures/chosing_alpha--telescoping_sums.pdf}

\includegraphics[width=2.7in]{figures/chosing_alpha--telescoping_sums2.pdf}

Note that our $D$ values are not going up by more than 1 each time, like the intro to the concept showed.
There is an exponential term that generally shrinks the sum of the $D$ values to 1 (at least in the class example).  \hfill \\
\hfill \\

After the third iteration for our class example:
\includegraphics[width=3.4in]{figures/boosting_example_3rd_iteration.pdf} \hfill \\
The $\epsilon$ values are dependent on the previous iteration's $D$ values,
	but the current iterations $h$ classifier. \hfill \\
Once you find your new $\epsilon$ from your old $D$s and new $h$,
	you can find $\alpha$ and thus your new $D$s for the next round.   \hfill \\
%?? Does your previous classifier know anything about your other classifiers ??    \hfill \\
%?? Should we think of the fact that it was trained using $D$s from previous classifiers as knowledge about other classifiers ??   \hfill \\
?? Is it typical to have your alpha weights grow ??  Can I explain what is driving this ??
\hfill \\
\hfill \\

\textbf{The D after normalization is a probability.}

\subsubsection{Assembling weak classifiers}
If each classifier is (at least slightly) better than random: $\epsilon_t < 0.5$: \hfill \\
Another bound on error:
$$ \frac{1}{m} \sum_{i=1}^m \delta (H(x^i) \neq y^i) \leq \prod_t Z_t \leq \exp \left( -2 \sum_{t=1}^T (\frac{1}{2} - \epsilon_t)^2 \right)$$
This implies training error will reach zero exponentially fast. \hfill \\
The error is bounded by an exponential of how far you are from random. \hfill \\

Note that it isn't too hard to achieve better than random training error, especially for binary classification.   \hfill \\
Boosting is powerful!  \hfill \\

Note that test error can continue to decrease after training error goes to zero.

\includegraphics[width=2.2in]{figures/boosting_train_test_error.pdf}

Also in this figure, the lack of up-tick at the right shows that boosting does not overfit.

\subsubsection{Using your classifier}
Say you have a trained/converged classifier.
That means you have $h$s and $\alpha$s : weak classifiers and their corresponding weights.
Plug in new $x$ into $H(x)$ %, which puts into $H(x)$.

\textbf{How do we know when to stop? } \hfill \\
If the training error keeps getting better we keep going.
This could lead to over-fitting, but it turns out boosting is robust to overfitting.   \hfill \\
(We didn't actually conclude when to stop in class.)

There was a theory (Freund \& Schapire, 1996) that suggested
$$ error_{true}(H) \leq error_{train}(H) + \tilde{\mathcal{O}} \left( \sqrt{\frac{Td}{m}} \right) $$
Suggests you don't want to use complicated classifiers in your boosting.  d would get high, we could end up over-fitting. % week 9 audio

$T$: number of boosting rounds.  Higher $T$ $\rightarrow$ looser bound.  \hfill \\
$d$: VC dimension of weak learner.  Measures complexity of classifier.  \hfill \\
$m$: number of training examples.  More data $\rightarrow$ tighter bound.  \hfill \\
\hfill \\

It turns out boosting is robust to overfitting.  The test set error decreases even after the training error reaches zero.  So this theory doesn't hold.

\subsubsection{Boosting and Logistic Regression}
Both smooth approximations of 0/1 step loss.

\includegraphics[width=2.2in]{figures/losses--boosting_and_logistic_regression.pdf}

\includegraphics[width=2.7in]{figures/logistic_regression_and_boosting_summary.pdf}

As noted above:
Similar to logistic regression:
\begin{itemize}
	\item both linear models.  Boosting "learns" features.
	\item similar loss functions
	\item single optimization (Logistic Regression) versus incrementally improving
\end{itemize}


\section{System design and composition}
\subsection{Model}
The system is modelled in two parts: the moving base and the\ldots
% TODO: describe the moving base, and the attachment, whatever it ends up being.
% Include physical models.

% Describe the states of the system.
We argue for the folloing five states of the system:
\begin{inline-enum}
\item waiting for a command;
\item moving to a destination;
\item following a navigation-line;
\item picking an object up; and
\item dropping an object off.
\end{inline-enum}
The relation between these five states are visually described in the state machine of Fig~\ref{fig:state_machine}.
\begin{figure*}[ht]
  \centering
  \begin{tikzpicture}
    \node[state, initial, accepting] (wait) {waiting for \\ command};
    \node[state, right of=wait] (move) {moving to \\ destination};
    \node[state, below of=move] (follow) {following \\ line};
    \node[state, right of=follow] (pickup) {picking \\ up object};
    \node[state, left of=follow] (dropoff) {dropping \\ off object};

    \path[->] (wait) edge node{Arrowhead \\ signal} (move)
    (move) edge[sloped] node{line detected \\} (follow)
    (follow) edge[sloped] node{station detection \\ (system w/o object)} (pickup)
    (follow) edge[sloped] node{station detection \\ (system w/ object)} (dropoff)
    (pickup) edge[sloped] node{object picked up \\} (move)
    (dropoff) edge[sloped] node{object dropped \\} (wait)
    ;
  \end{tikzpicture}
  \caption{High-level state machine of the system.}
  \label{fig:state_machine}
\end{figure*}
\subsubsection{Mobile platform}
The model used in this case is the unicycle model, due to the differential steering.
This is because of the mobile platform has only two wheels/trucks and it is not able to apply any steering angle to its wheels.
The only way this robot can change orientation is by giving different velocity on each wheel-driving servo on left- and right- side.
With this feature it is also possible to change the orientation of the mobile platform without changing the position of the platform.
I.e. the robot is able to spin while the right-hand sidewheels have the same velocity as the left-hand side wheels, in opposite direction.

\begin{figure}[h!]
\centering
\includegraphics[width=0.4\textwidth]{sections/assets/car-unicycle.png}
\caption{Unicycle model of a car-like robot.
$v_L$ and $v_R$ represent the left- and right-hand side wheels' velocities respectively.
The robot follows a path around the instantaneous center of rotation (ICR) where $R_L$ and $R_R$ are the distances from left and right wheels to ICR respectively and $w$ is the distance between them.}
\label{fig:UnicycleModel}
\end{figure}

As shown in Fig.~\ref{fig:UnicycleModel} The robot follows a curved path with the instantaneous center of rotation at its center.
The left-hand side wheels have velocity $v_L$ and moves along an arc with radius $R_L$ during the time that right-hand side wheels moves along another arc with radius $R_R$ at the speed of $v_R$.
The turning rate of the body is
        \begin{equation*}
            \dot{\theta}= \frac{v_L}{R_L} = \frac{v_R}{R_R}
        \end{equation*}
        since $R_R = R_L + W$ the expression can be simplified as
        \begin{equation}
            \dot{\theta}= \frac{v_R - v_L}{W} = \frac{v_\Delta}{W}\label{eq:ThetaDot3}
        \end{equation}
        the equations of motion for this model are
        \begin{eqnarray}
            \begin{aligned}
                \dot{x} &= v\,cos(\theta)\\
                \dot{y} &= v\,sin(\theta)\\
                \dot{\theta} &= \frac{v_\Delta}{W}
            \end{aligned}
            \label{eq:MotionEq3}
        \end{eqnarray}
        where the average velocity\parencite{Corke2011} is given by
        \begin{equation}
            v = \frac{v_R + v_L}{2}
            \label{eq:av_velocity}
        \end{equation}{}

\subsection{Simulation}
% Simulte the models from the previous section and show that it will work.
% Motivate regulation approach.

\subsection{Hardware}
% Explain the raspberry pi and it's attachments.

\subsection{Software}
\subsubsection{Reproducible system image generation}
% Explain the repo's *.nix files and what they do
The system image of the Raspberry Pi is generated via the repository's \texttt{mmc-image.nix} file ---
an auxiliary \texttt{build.sh} script is available to generate and subsequently flash a target storage device in a single command execution.
\texttt{mmc-image.nix} contains an expression of the Nix language.
Together with the usage of \texttt{nixpkgs} --- an extensive library of build and package declarations,
\texttt{mmc-image.nix} allows us to reliably and reproducibly build a bootable image of the complete software environment the project requires.
To then boot the generated image, it only needs to be flashed on a MultiMediaCard (MMC\footnote{Commonly referred to as: SD card, memory card.}) and slotted into the MMC-slot on the Raspberry Pi.

% Explain the pros of Nix
When building derivations (nomenclature for anything built with Nix: an executable binary, shared library file, a system environment, etc.) their dependencies are in complete isolation with each other, which effectively allows the avoidance of dependency hell.\footnote{Colloquial term referring to the frustration often generated when dealing with version-specific dependencies.
See \href{https://en.wikipedia.org/wiki/Dependency_hell}{Wikipedia}.}

% Explain the rollback functionality git provide us.
In combination with git, one may trivially roll back to previous derivations that are known to work by checking out a commit and rebuilding.

% Explain why treating the MMC as volatile is a good idea (MMCs have a tendency to just stop working).
In addition, by preferring a work flow where the target storage is considered volatile, any deficiencies of the target medium are mitigated.

% TODO: improve
\subsubsection{System-external services}
The software environment generated for the Raspberry Pi automatically connects to Eduroam if credentials are available.
Eduroam places some limitations on connected clients: firewall, e.g.
To enable easy remote access to the system, a reverse SSH proxy is established with a known bastion host which has a static IP address.
By exposing this proxy via a known port on the bastion, any system connected to the Internet may trivially access the Raspberry Pi remotely via a static endpoint.
While not a necessity for the project itself, this external service is a great convenience for ad-hoc experiments and general system debugging.

% Explain the content of contrib/bastion.nix


\chapter{Data on the Sphere}
\label{ch_intro}

\section{Introduction}

In a number of areas of scientific activity, data is gathered which naturally maps to the sphere. For instance, remote sensing of the
Earth's surface and atmosphere,\emph{e.g.} with POLDER\footnote{\emph{http://polder.cnes.fr}}, generates spherical data maps which are
crucial for global and local geophysical studies such as understanding climate change, geodynamics or monitoring human-environment
interactions. More examples can be found in medical imaging or computer graphics. In astronomy and astrophysics, recent and upcoming
ground based and satellite borne experiments such as WMAP\footnote{\emph{http://map.gsfc.nasa.gov}} or Planck-Surveyor\footnote{\emph{http://astro.estec.esa.nl/Planck}}
for the observation of the Cosmic Microwave Background radiation field over the whole celestial sphere, have and will produce full-sky
maps in a wide range of wavelengths. These maps are necessarily digitized and hence distributed as a finite set of pixel values on some
grid. The properties of this grid will affect the subsequent analysis of the data, and a good choice will make standard computations,
such as the spherical harmonics transform, much faster and accurate. Considerable work has been dedicated to the development of
pixelization schemes on the sphere. In particular, Healpix\cite{healpix} is a sampling scheme which has some attractive geometrical
features profitably used in this spherical data analysis software package. \\

Processing spherical data maps requires specific tools or somehow adapting traditional methods used on flat images to the spherical
topology, such as multiscale transforms for image processing. Among these, Wavelets and related representations are by now successfully
used in all areas of signal and image processing. Their recent inclusion in JPEG 2000 -- the new still-picture compression standard --
is an illustration of this lasting and significant impact. Wavelets are also very popular tools in astronomy \cite{starck:book02} which
have led to very impressive results in denoising and detection applications. For instance, both the Chandra and the XMM data centers
use wavelets for the detection of extended sources in X-ray images. For denoising and deconvolution, wavelets have also demonstrated
how powerful they are for discriminating signal from noise \cite{starck:sta02_2}. In cosmology, wavelets have been used in many studies
such as for analyzing the spatial distribution of galaxies \cite{astro:slezak93,astro:escalera95,starck:sta05,starck:martinez05},
determining the topology of the universe \cite{astro:rocha04}, detecting non-Gaussianity in the CMB maps \cite{gauss:aghanim99,gauss:barreiro01_1,wave:vielva04,starck:sta03_1},
reconstructing the primordial power spectrum \cite{astro:pia03}, measuring the galaxy power spectrum \cite{astro:fang00} or reconstructing
weak lensing mass maps \cite{starck:sta05b}. It has also been shown that noise is a problem of major concern for N-body simulations of
structure formation in the early Universe and that using wavelets for removing noise from N-body simulations is equivalent to simulations
with two orders of magnitude more particles \cite{rest:romeo03,rest:romeo04}.

Wavelets owe part of their success to their ability for sparse approximation of point singularities. However they are not as good at detecting
highly anisotropic features such as curvilinear singularities in images. This is where other multiscale systems such as Ridgelets \cite{cur:candes99_1}
and Curvelets \cite{cur:donoho99,starck:sta01_3}, which exhibit high directional sensitivity and are highly anisotropic, come into play. Digital
implementations of both ridgelet and curvelet transforms for image denoising are described in \cite{starck:sta01_3}. Inspired by the successes
of \emph{Euclidean} wavelets, ridgelets and curvelets, this package provides implementations of new multiscale decompositions for spherical images
namely the isotropic undecimated wavelet transform, the ridgelet transform and the curvelet transform each of which is invertible.

\section{Pixelization}

Despite the apparent simplicity of the sphere, deriving numerical schemes on the sphere is not a trivial task. A major difficulty encountered
in the design of numerical methods on the sphere is that of pixelization: there is no obvious way in which to reconcile the requirements
for a \emph{maximally} uniform sampling and for an exact and invertible computation of the spherical harmonics decomposition of band-limited
functions \cite{healpix,icosahedron}. Also, the sampling strategy determines largely the achievable algorithmic complexity of these computations.
Several sampling schemes have been proposed recently such as Tegmark's Icosahedron \cite{icosahedron}, the Igloo \cite{igloo} or Healpix \cite{healpix}
methods which tend to favor approximate uniformity among other properties. The Glesp \cite{glesp} pixelization was developed with a strong
focus on the accuracy of the spherical harmonics transform.

\subsection*{Healpix}

The Healpix representation is a curvilinear hierarchical partition of the sphere into quadrilateral pixels of exactly equal area but with
varying shape. The base resolution divides the sphere into 12 quadrilateral faces of equal area placed on three rings around the poles
and equator. Each face is subsequently divided into $nside^{2}$ pixels following a quadrilateral multiscale tree structure. The pixel
centers are located on iso-latitude rings, and pixels from the same ring are equispaced in azimuth. This is critical for computational
speed of all operations involving the evaluation of spherical harmonics transforms, including standard numerical analysis operations such
as convolutions, power spectrum estimation\ldots \\

\begin{figure}
\centering
\includegraphics{pixelhealpix}
\caption{The Healpix sampling grid.}
\label{pixelhealpix}
\end{figure}

An important geometrical feature of the Healpix sampling grid is the hierarchical quadrilateral tree structure. This defines a \emph{natural}
one-to-one mapping of the sphere sampled according to the Healpix grid, into twelve \emph{flat} images, on all scales. It is then easy to
partition a spherical map using Healpix into quadrilateral blocks of a specified size. One first extracts the twelve base-resolution faces,
and each face is then decomposed into overlapping blocks of the specified size. This decomposition into blocks is an essential step of the
traditional \emph{flat} 2D curvelet transform. Based on the reversible warping of the sphere into a set of flat images made possible by the
Healpix sampling grid, the ridgelet and curvelet transforms can be extended to the sphere.

With the decomposition into blocks described above, there is no overlapping between neighboring blocks belonging to different base-resolution faces.
This may result for instance in blocking effects in denoising experiments \emph{via} non linear filtering. It is possible to overcome this difficulty
in some sense by working simultaneously with various rotations of the data with respect to the sampling grid. This will average out undesirable
effects at edges between base resolution faces.

\section{Multiscale methods on the sphere}

\subsection{Wavelets on the sphere}

In the last years, several wavelet transforms on the sphere have been proposed. Schr{\"o}der and Sweldens \cite{wave:sweldens95a} have developed
an orthogonal wavelet transform on the sphere based on the Haar wavelet function which then suffers from the poor properties of the Haar function
and the problems inherent to the orthogonal decomposition. A few papers describe continuous wavelet transforms on the sphere \cite{wave:antoine99,wave:tenerio99,wave:cayon01,wave:holschneider96}.
An application to the detection of non-Gaussianity in the CMB radiation using the stereographic Mexican hat wavelet is reported in \cite{wave:vielva04}.
These methods have been extended to directional wavelet transforms \cite{wave:antoine01,wave:hobson04,wave:wiaux}. Although profitable for data
analysis, these continuous transforms lack an inverse transform and hence are clearly not suitable for restoration purposes. The algorithm proposed
by Freeden and Maier\cite{freeden97,freeden98}, based on the Spherical Harmonic Decomposition, is to our knowledge the only one to have an inverse transform.\\

A very popular wavelet algorithm in astrophysical applications is the so-called ``\emph{\`a trous} algorithm'' (a better name would be the
``isotropic undecimated wavelet transform'' ), which possesses the following features: i) it is isotropic, ii) it is undecimated, iii) it uses
an order three Box-Spline as scaling function. The isotropy of the wavelet function makes this decomposition optimal for the detection of
isotropic objects. The non decimation makes the decomposition redundant (the number of coefficients in the decomposition is equal to the number
of samples in the data multiplied by the number of scales) and allows us to avoid Gibbs aliasing after reconstruction in image restoration
applications, as generally occurs with orthogonal or bi-orthogonal wavelet transforms. The choice of a $B_3$-spline is motivated by the fact
that we want an analyzing function close to a Gaussian, but verifying the dilation equation, which is required in order to have a fast transformation.
Finally the last property of this algorithm is to provide a very straightforward reconstruction. Indeed, the sum of all the wavelet scales and
of the coarsest resolution image reproduces exactly the original image. \\

The \mrs package offers an implementation of a new isotropic wavelet transform on the sphere. Its properties are similar to those of the \emph{\`a trous}
algorithm and therefore should be very useful for data denoising and deconvolution. This algorithm, described in chapter~\ref{ch_mms}, is directly derived
from the FFT-based wavelet transform proposed in\cite{starck:sta94_3} for aperture synthesis image restoration. It is relatively close to the Freeden and
Maier \cite{freeden98} method, except that the reconstruction process is as straightforward as in the \emph{\`a trous} algorithm (i.e. the sum of the scales
reproduces the original data). This new wavelet transform can also be easily extended to a pyramidal wavelet transform, which may be very important for
larger data sets such such as from the future Planck experiment.

\subsection{Ridgelets and Curvelets on the sphere}

When analyzing data which contains anisotropic features, wavelets are no longer optimal. This has motivated the development of new multiscale
decompositions such as the ridgelet and the curvelet transforms \cite{cur:donoho99,starck:sta01_3}. Among possible applications of those data
analysis methods, it was shown in Starck et al. \cite*{starck:sta03_1} that the \emph{flat} curvelet transform could be useful for the detection
of non Gaussianity in \emph{flat} patches of CMB data, and also to discriminate among different causes of non Gaussianity.

In this area, further insight will come from the analysis of full-sky data mapped to the sphere thus requiring the development of a curvelet
transform on the sphere. The \mrs package offers an implementation of ridgelet and curvelet transforms for spherical maps. Those implementations
are derived as extensions of the digital ridgelet and curvelet transforms described in \cite{starck:sta01_3}. The implemented undecimated isotropic
wavelet transform on the sphere and the specific geometry of the Healpix sampling grid are important components of the present implementation of
curvelets on the sphere. \\

Further motivation for developing these new multiscale methods on the sphere follows from the results obtained in different data processing applications.
As described in chapter\ref{ch_restore}, the \mrs package provides the necessary tools to experiment with these new spherical multiscale transforms in
denoising applications, for instance using the Combined Filtering Method, which allows us to filter data on the sphere using both the Wavelet and the
Curvelet transforms. The analysis of multichannel data mapped to the sphere, a problem encountered for instance in the processing of WMAP and Planck
observations, is another issue that is shown to benefit from the developed multiscale representations on the sphere. This is reported in chapter~\ref{ch_mrs_ica}
which is dedicated to describing some methods in multichannel data analysis extended to spherical maps which are implemented in the \mrs package.

\section{Processing of polarized datas on the sphere}

Polarized maps are a special kind of multi-dimentionnal datas with strong links between their components. The polarization is of great importance
in physics or astrophysics as it's analysis denotes fundamentals characteristics of the observed object or phenomenum. An example of great interest
is today the cosmic microwave background \cite{starck}.

The statistical analysis of the slight intensity fluctuations in the primordial cosmic microwave background radiation field, for which evidence was
found for the first time in the early 1990's in the observations made by COBE~\cite{gauss:smoot92}, is a major issue in modern cosmology as these
are strongly related to the cosmological scenarios describing the properties and evolution of our Universe. In the Big Bang model, the observed CMB
anisotropies are an imprint of primordial fluctuations in baryon-photon density from a time when the temperature of the Universe was high enough above
3000~K for matter and radiation to be tightly coupled. At that time, the attraction of gravity and the repulsive radiation pressure were opposed, thus
generating so-called acoustic oscillations in the baryon-photon fluid, causing peaks and troughs to appear in the power spectrum of the spatial anisotropies
of the CMB. With the Universe cooling down as it expanded, matter and radiation finally decoupled. Photons were set free in a nearly transparent Universe,
while the density fluctuations collapsed under the effect of gravity into large scale structures such as galaxies or clusters of galaxies. Due to the
expansion of the Universe, the CMB photons are now observed in the microwave range but are still distributed according to an almost perfect black body
emission law. Another major result was the measurement of the polarization state and anisotropies of the CMB radiation field by DASI~\cite{dasi}.
Only a fraction of the total CMB radiation is polarized so that extremely sensitive instruments are needed. Polarization of the CMB radiation is a
consequence of the Thomson scattering of photons on electrons. But for the outgoing population of photons to be polarized, the radiation incident on
the scatterer needs to be anisotropic and have a quadrupole moment. The statistics of the CMB polarization anisotropies are also a source of information
for cosmology. Inference of cosmological parameters from the joint statistics of the CMB anisotropies should benefit from both the complementarity and
the redundancy of the information carried by the additional measurement of CMB polarization. Hence the full-sky maps with unprecedented sensitivity and
angular resolution of both temperature and polarization anisotropies of the CMB to be delivered by the upcoming Planck Surveyor satellite experiment are
awaited with excitement.

\subsection{Orthogonal representation of polarized datas}
\label{sec:polar}

\begin{figure*}[htb]
\includegraphics[width=\textwidth]{fig_pola_qu_owt_trans.pdf}
\caption{Q-U orthogonal Wavelet Transform.}
\label{fig_qu_owt_trans}
\end{figure*}
Full-sky CMB polarization data, as expected from the upcoming Planck experiment, consists of measurements of the Stokes parameters so that in addition
to the temperature $T$ map, $Q$ and $U$ maps are given as well. The fourth Stokes parameter commonly denoted $V$ is a measure of circular polarization.
In the case of CMB which is not expected to have circularly polarized anisotropies, $V$ vanishes. The former three quantities, $T$, $Q$ and $U$ then
fully describe the linear polarization state of the CMB radiation incident along some radial line of sight : $T$ is the total incoming intensity, $Q$ is
the difference between the intensities transmitted by two perfect orthogonal polarizers the directions of which define a reference frame in the tangent
plane, and $U$ is the same as $Q$ but with polarizers rotated 45 degrees in that tangent plane. Clearly, $Q$ and $U$ are not invariant through a rotation
of angle $\phi$ of the local reference frame around the line of sight. In fact, it is easily shown that~:
\begin{eqnarray}
Q ' = & \cos (2 \phi) Q + \sin(2 \phi) U \\ \nonumber
U ' = & \cos (2 \phi) U - \sin(2 \phi) Q
\end{eqnarray}
which can also be written $Q' \pm i U' = e^{\mp i\phi} ( Q \pm i U )$ which by definition expresses the fact that the quantities $Q \pm i U$ are
spin-2 fields on the sphere. The suitable generalization of the Fourier representation for such fields is the spin-2 spherical harmonics basis
denoted $_{\pm 2}Y_{\ell m}$, in which we can expand~:
\begin{eqnarray}\label{QU}
Q \pm i U  = \sum_{\ell, m} { _{\pm 2}a_{\ell m}} {_{\pm 2}Y_{\ell m} }
\end{eqnarray}

It is convenient~\cite{zalda} to introduce the two quantities denoted $E$ and $B$ which are defined on the sphere by~:
\begin{eqnarray}\label{EB}
E = & \sum_{\ell, m} a_{\ell m} ^E Y_{\ell m} = \sum_{\ell, m} - \frac{1}{2} ( {_{ 2}a_{\ell m}} + {_{- 2}a_{\ell m}} ) Y_{\ell m} \\ \nonumber
B = & \sum_{\ell, m} a_{\ell m} ^B Y_{\ell m} = \sum_{\ell, m} i \frac{1}{2} ( {_{ 2}a_{\ell m}} - {_{- 2}a_{\ell m}} ) Y_{\ell m}
\end{eqnarray}

\subsection{Multiscale transform on the sphere for polarized datas}

Inprovements in the second version of the \mrs package includes extension of the 1D multiscale transforms to the case of polarized maps with
the three fields $T$, $Q$ and $U$ (or the fields $T$, $E$ and $B$). The easiest way to build a multiscale transform for polarized data is to
use the Healpix\footnote{http://healpix.jpl.nasa.gov} representation \cite{pixel:healpix}, and to apply a bi-orthogonal wavelet transform
on each face of the Healpix map, separately for $Q$ and $U$. Fig.~\ref{fig_qu_owt_trans} shows the flow-graph of this Q-U orthogonal wavelet
transform (QU-OWT). Most of the algorithms included in \mrs for the processing of 1D images know have a version for polarized maps.

% \clearpage
% \newpage


\documentclass{amsart}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{enumerate}
\usepackage{mathtools}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\LL}{\mathcal{L}}

\newcommand{\F}{\mathbb{F}}
\newcommand{\Fp}{\mathbb{F}_p}
\newcommand{\Fq}{\mathbb{F}_q}

\newcommand{\M}{\mathfrak{M}}

\newcommand{\Hom}{\operatorname{Hom}}
\newcommand{\Isom}{\operatorname{Isom}}
\newcommand{\im}{\operatorname{im}}
\newcommand{\rank}{\operatorname{rank}}
\newcommand{\supp}{\operatorname{Sup}}
\newcommand{\ord}{\operatorname{ord}}
\newcommand{\cf}{\operatorname{coef}}
\newcommand{\spn}{\operatorname{span}}
\newcommand{\characteristic}{\operatorname{char}}

\newcommand{\NN}{\operatorname{Norm}}
\newcommand{\OK}{\mathcal{O}_K}
\newcommand{\Cl}{\operatorname{Cl}}
\newcommand{\lcm}{\operatorname{lcm}}
\newcommand{\sign}{\operatorname{sign}}
\newcommand{\remainder}{\operatorname{remainder}}
\newcommand{\quotient}{\operatorname{quotient}}

\DeclarePairedDelimiterX\set[2]{\{}{\}}{\,#1 \;\delimsize\vert\; #2\,}

\begin {document}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem*{conjecture}{Conjecture}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

\title{Finiteness of the class group}

\maketitle

%------------------------------------------
\section{Introduction}\label{intro}
%------------------------------------------

In order to formalize, e.~g.~ in the theorem prover \emph{Lean}, the finiteness of the class group of rings of integers in number fields, we write some proof in detail. Much of the proof actually applies uniformly to the function field case, assuming (for the time being \ldots) it's a separable extension of the \lq base\rq\ field $\Fq(t)$.

NOTE: the only actual intended use of this informal document was to use it in combination with discussions, explanations, etc. to formalize finiteness results for class groups in Lean. In particular, with very few exceptions, no attempt was made to correct errors or complete omissions unless still beneficial for the formalization process.
Perhaps it will be \lq polished\rq\ a little bit more in the future.

%------------------------------------------
\section{Notation and conventions}\label{notation}
%------------------------------------------

%Throughout this paper we let $k,n \in \N$.
For ideals $I,J$ in some commutative ring $R$, we use standard divisibility-notation $I|J$, meaning $IH=J$ for some ideal $H$ in $R$.

%------------------------------------------
\section{Preliminaries on Dedekind domains}
%------------------------------------------

For ideals in Dedekind domains we have \lq to contain is to divide\rq.
\begin{proposition}\label{prop contain is divide}
Let $I,J$ be ideals in a Dedekind domain $R$. Then
\begin{equation}\label{eqn contain is divide}
I \supseteq J \Leftrightarrow I|J.
\end{equation}
\end{proposition}

\begin{proof}
\lq $\Leftarrow$\rq: trivial (assuming $I|J$, which means $J=IH$ for some ideal $H$, it remains to show $IH \subseteq I$, which is obvious).\\
\lq $\Rightarrow$\rq: Assume $I \supseteq J$. If $I=0$, then $J=0$, and hence $I|J$. We are left with the case $I\not=0$.
We take as a starting point that nonzero fractional ideals in a Dedekind domain are invertible. So in particular $I$ is invertible. As fractional ideals we have $H:=I^{-1} J \subseteq I^{-1} I=R$. So $H$ is in fact an ideal, and $I H=I I^{-1} J=J$ So $I|J$ (as ideals of $R$).
\end{proof}

It is convenient to have a characterization of prime ideals in terms of ideals only.

\begin{lemma}\label{lem prime ideal ideals}
Let $R$ be a commutative ring and $P$ be an ideal in $R$. Then $P$ is a prime ideal if and only if $P\not=R$ and
\begin{equation}\label{eqn prime ideal ideals}
\forall \text{ ideals } I,J \subseteq R: IJ \subseteq P \Rightarrow I \subseteq P \text{ or } J \subseteq P.
\end{equation}
\end{lemma}

\begin{proof}
Unfold definitions etc.\ldots
\end{proof}

Lemma~\ref{lem prime ideal ideals} and Proposition~\ref{prop contain is divide} above, now yields the well known \lq prime property\rq, but now for ideals.

\begin{corollary}\label{cor prime property ideal}
Let $I,J,P$ be ideals in a Dedekind domain $R$ with $P$ prime. Then
\[ P|IJ \Rightarrow \left (P|I \text{ or } P|J \right).\]
\end{corollary}

Another useful property is the \emph{cancellation rule} for ideal multiplication in Dedekind domains.

\begin{proposition}\label{prop cancellation ideals}
Let $H,I,J$ be ideals in a Dedekind domain $R$ with $H$ nonzero. Then
\[ IH=JH \Rightarrow I=J.\]
\end{proposition}

\begin{proof}
Again, using the characterization of Dedekind domains that all nonzero fractional ideal are invertible, the result follow by multiplying LHS and RHS of $IH=JH$ by (the fractional ideal) $H^{-1}$..
\end{proof}

We now have enough ingredients to our disposal to establish unique factorization in terms of ideals in a Dedekind domain.
\begin{theorem}\label{thm Dedekind unique fac}
Let $R$ be a Dedekind domain. Then every nonzero ideal $I$ of $R$ can be written as a product of prime ideals of $R$ in a unique way, apart from the order of the factors.
\end{theorem}

\begin{proof}
\emph{Existence.} If $I=R$, then we are done by the canonical convention that the empty product (of ideals) gives the unit ideal, i.e. $R$. So Let $I \not=R$. By Zorn's Lemma we get that $I$ is contained in a maximal ideal, which is a nonzero prime ideal $P_1$.
(If one does not like the appeal to Zorn's lemma, which is equivalent to the axiom of choice, then for $R=\mathcal{O}_K$ one can also use $R/I$ is finite instead.)
By Proposition~\ref{prop contain is divide} we see that $P_1|I$, i.e. $I=P_1 I_1$ for some nonzero ideal $I_1$ of $R$. Continuing inductively we get $I=P_1P_2\ldots P_k I_k$ for nonzero prime ideals $P_1,P_2,\ldots, P_k$ and nonzero ideal $I_k$ of $R$. If this process would continue indefinitely, then this woud give us an infinite ascending chain of ideals $I\subsetneq I_1 \subsetneq I_2 \subsetneq \ldots$. Since $R$ is Noetherian, this cannot happen, so we must have that for some $k$ the ideal $I_k$ is not divisible by a prime ideal, i.e. $I_k=R$ and consequently $I=P_1P_2\ldots P_k$. This completes the existence part of the proof.\\
\emph{Uniqueness.} Let $I=P_1P_2\ldots P_k=Q_1Q_2\ldots Q_l$ be two factorizations of $I$ into (nonzero) prime ideals. By Corollary~\ref{cor prime property ideal} (and induction) we get that $P_1$ divides $Q_i$ for some $i=1,2,\ldots,l$. Since $Q_i$ is maximal we get $P_1=Q_i$. Change notation so that $i=1$. Now the cancellation rule, i.e. Proposition~\ref{prop cancellation ideals}, gives $P_2 \ldots P_k=Q_2 \ldots Q_l$. With induction we get that $k=l$ and, after permuting the indices of the $Q_i$'s, that $P_i=Q_i$ for all $i$. This yields Theorem~\ref{thm Dedekind unique fac}.
\end{proof}

\begin{proposition}\label{prop finitely many ideal divisors}
Let $I$ be a nonzero ideal in a Dedekind domain $R$. Then there are only finitely many ideals $J$ in $R$ such that $J|I$.
\end{proposition}

\begin{proof}
This follows e.~g.~ from unique factorization~\ref{thm Dedekind unique fac}.
\end{proof}

%------------------------------------------
\section{Further preliminaries}
%------------------------------------------

An \emph{absolute value} on a ring $R$ with values in an ordered ring $S$ is a function
\[R \to S, \quad x \mapsto |x|\]
satisfying for all $x,y \in R$
\begin{itemize}
\item $|x|\geq 0$;
\item $|x|=0 \Leftrightarrow x=0$;
\item $|x y|=|x| |y|$;
\item $|x+y|\leq |x|+|y|$.
\end{itemize}

If $R$ and $S$ are domains, with fields of fractions $K$ and $L$ respectively, then an absolute value on $R$ with values in $S$ extends uniquely to an absolute value on $K$ with values in $L$ by letting $|x/y|:=|x|/|y|$ for any $x,y \in R$ with $y\not=0$.

We note that it follows very quickly that
\[|1|=|-1|=1.\]

Two easy examples are as follows.
\begin{lemma}
The following functions are absolute values.
\begin{itemize}
\item \[ |.|_{\text{arch}}: \Z \to \Z, \quad x \mapsto \sign(x)x\]
\item For any domain $D$ and integer $c>1$
\[ |.|_{\deg}: D[t] \to \Z, \quad f \mapsto c^{\deg f} (\text{if necessary, treat separately}\ 0 \mapsto 0).\]
In particular, taking $D=\F_q$ (a finite field with $q$ elements) and $c=q$, we get
\[ |.|_{\deg}: \F_q[t] \to \Z, \quad |f|_{\deg}=q^{\deg f}.\]
\end{itemize}
\end{lemma}

\begin{proof}
Write out definitions, and use standard properties of the degree function, i.e. $\deg (fg)=\deg f+\deg g$ and $\deg(f+g)\leq \max(\deg f,\deg g)$ (treating the zero polynomials separately, or setting $\deg(0)=-\infty$ with the appropriate operations/inequalities for $-\infty$). The second case gives the stronger triangle inequality $|f+g|_{\deg} \leq \max(|f|_{\deg},|g|_{deg})$, which  immediately implies the weaker \lq normal\rq\ triangle inequality.
\end{proof}

We note that taking $c=q$ for the last absolute value is just some natural normalisation choice. It is of no importance for the results here. So if e.~g.~ taking $c=2$ would make things easier, that choice would be fine too. Also, just considering $q=p$ (so $\F_q=\F_p \simeq \Z/p\Z$) suffices for our purposes.

A crude estimate for the determinant of a matrix is given below.
\begin{lemma}
Let $R$ and $S$ be commutative rings with $S$ ordered, and $|.|:R \to S$ an absolute value.
Let $A$ be a matrix of size $n \times n$ (for some $n\in \N$) with coefficients in $R$. Then
\[|\det(A)|\leq n! \left(\max_{1\leq i,j\leq n} |A_{i,j}|\right)^n.\]
\end{lemma}

\begin{proof}
Induction using row expansion, or using permutation formula/definition for determinant.
\end{proof}

The following will be used for estimating norms.

\begin{corollary}\label{cor estimate norm}
Let $R$ and $S$ be commutative rings with $S$ ordered, and $|.|:R \to S$ an absolute value.
Let $A_1,\ldots A_n$ be a matrix of size $n \times n$ (for some nonzero $n\in \N$) with coefficients in $R$. Let $s_1\ldots s_n \in R$. Then
\[ \left|\det(\sum_{k=1}^n s_k A_k) \right| \leq n! \left(n \max_{1\leq i,j,k\leq n} |(A_k)_{i,j}|\right)^n \left( \max_{1\leq k\leq n}(|s_k|) \right)^n.\]
\end{corollary}

%------------------------------------------
\section{Generalized division with remainder}
%------------------------------------------

$R$ is a PID (hence Dedekind domain) with nontrivial absolute value $|.| : R \to \Z$, and field of fractions $K$.
$L$ is a finite and separable (for the time being..) field extension of $K$, and we let $S$ be the integral closure of $R$ in $L$. So $S$ is a Dedekind domain.
We have the norm map $\NN: L \to K$, restricting to a function $S \to R$. Denote $n:=[L:K]$. Also assume $R$ to be infinite (our main theorem becomes trivial if $R$ is finite).

We also assume that $|.|: R \to \Z$ is a \emph{Euclidean function}, i.e. for all $a,b \in R$ with $b\not=0$ there exists a $q \in R$ such that $|a-qb|<|b|$.
In fact, we take $R$ to be a Euclidean domain as defined in Lean. So it comes with a choice of quotient function $q: R^2 \to \Z$ (ignoring currying in this math writeup).
%, and the well founded relation ...

Since $R$ is a PID, $S$ contains an $R$-integral basis, i.e. there are (basis elements) $b_1,b_2,\ldots,b_n \in S$ such that for every $x \in S$ there are unique (scalars) $s_1,s_2,\ldots s_n \in R$ with $x=\sum_{i=1}^n s_i b_i$.
The scalars define a function $s: S \to R^n, x \mapsto (s_1,\ldots,s_n)$, which is obviously $R$-linear.

We start with an estimate on norms.

\begin{lemma}\label{lem norm estimate}
There exists a constant $C \in \R_{> 0}$, depending only on the $R$-integral basis $b_1,\ldots,b_n \in S$, such that for any $x=\sum_{i=1}^n s_i b_i \in S$
\[|\NN(x)| \leq C (\max_i |s_i|)^n.\]
\end{lemma}

\begin{proof}
Follows from Corollary~\ref{cor estimate norm}.
\end{proof}

We will focus on Euclidean domains with the property that \lq sufficiently many remainders come arbitrary close to each other\rq (in higher dimensions) in the following sense.

\begin{definition}\label{def admissible}
We call $R$ \emph{admissible} if both:
\begin{itemize}
\item We have a function $\M : \R_{>0} \times \N \to \N$;
\item For all $ \epsilon \in \R_{>0}$, $n \in \N$, $b \in R$, and $A : \N_{\leq \M(\epsilon,n)} \to R^n$ there exists $j,k \in \N_{\leq \M(\epsilon,n)}$ such that
\[j \neq k \text{ and for all } i\in\{1,\ldots,n\},\ |\remainder(A(k)_i,b)-\remainder(A(j)_i,b)| < \epsilon |b|.\]
\end{itemize}
\end{definition}

There are equivalent, arguably cleaner, definitions (e.~g.~ without actually incorporating division with remainder), but for the time being this one seems to work just fine. (And will probably be handy for actual computations at some point.)

We will show later that $\Z$ and $\Fq[t]$ are admissible domains.
Now our main ingredient for the finiteness of the class group.

\begin{theorem} Assume $R$ is admissible.
There exists a finite set $M \subset R-\{0\}$, depending only on the $R$-integral basis $b_1,\ldots,b_n \in S$, such that
for all $a \in S$ and $b \in R-\{0\}$ there exist $q \in S$ and $r \in M$ with $|\NN(ra-qb)| < |\NN(b)|$.
\end{theorem}

\begin{proof}

Let $C$ be as in Lemma~\ref{lem norm estimate} and choose $\epsilon \in \R_{>0}$ such that
\begin{equation}\label{eqn choice epsilon}
\epsilon \leq 1/\sqrt[n]{C}.
\end{equation}
Let $\M$ be as in Definition~\ref{def admissible}.

Write $a=\sum_{i=1}^n s_i b_i$ ($s_i\in R)$.

Choose $\M(\epsilon,n)+1$ \emph{distinct} elements $\mu^{(0)},\ldots,\mu^{(\M(\epsilon,n))}$ of $R$ (possible since we assumed $R$ to be infinite).
And let $M:=\{\mu^{(k)}-\mu^{(j)} : 0\leq j<k\leq \M(\epsilon,n)\}$, so $M \subseteq R-\{0\}$ (the containment is in fact strict since $M$ is finite and $R$ is not).

For any $j \in \{0,\ldots,\M(\epsilon,n)\}$ and $i \in \{1,\ldots n\}$ we let $q^{(j)}_i:=\quotient(\mu^{(j)} s_i,b)$ and $r^{(j)}_i:=\remainder(\mu^{(j)} s_i,b)$. So $q^{(j)}_i,r^{(j)}_i \in R$ and
\[\mu^{(j)} s_i =q^{(j)}_i b+r^{(j)}_i \text{ and } |r^{(j)}_i|<|b|,\]
and hence
\begin{equation}\label{eqn vector q and r}
\mu^{(j)} a=\sum_{i=1}^n \mu^{(j)} s_i b_i= \sum_{i=1}^n (q^{(j)}_i b+r^{(j)}_i)b_i=\left( \sum_{i=1}^n q^{(j)}_i b_i\right)b+\sum_{i=1}^n r^{(j)}_i b_i.
\end{equation}
Consider the function $A : \N_{\leq \M(\epsilon,n)} \to R^n,\ j \mapsto (\mu^{(j)} s_1,\ldots,\mu^{(j)} s_n)$. Then by Definition~\ref{def admissible} we have indices $j,k$ with $0\leq j<k\leq \M(\epsilon,n)$ such that
\begin{equation}\label{eqn remainder bounds}
\text{for all } i \in\{1,\ldots,n\},\ |r^{(k)}_i - r^{(j)}_i| < \epsilon |b|.
\end{equation}
Now define
\[r:=\mu^{(k)}-\mu^{(j)} \in M\]
and
\[q:=\sum_{i=1}^n (q^{(k)}_i-q^{(j)}_i) b_i \in S.\]
Then by~\eqref{eqn vector q and r} (with that $j$ specialised to both (the new) $j$ and $k$), we have
\[ra-qb=\sum_{i=1}^n \left(r^{(k)}_i - r^{(j)}_i\right) b_i.\]
So it remains to show that
\begin{equation}\label{eqn final norm estimate}
\left|\NN \left(\sum_{i=1}^n \left(r^{(k)}_i - r^{(j)}_i\right) b_i\right)\right| < |\NN(b)|.
\end{equation}
Note that since $b \in R$ (coerced into $S$ before taking the norm), we get
\begin{equation}\label{eqn norm b}
\NN(b)=b^n.
\end{equation}
Now we have
\begin{alignat*}{3}
& \left|\NN \left(\sum_{i=1}^n \left(r^{(k)}_i - r^{(j)}_i\right) b_i\right)\right|  && \leq C\left( \max_i |r^{(k)}_i - r^{(j)}_i| \right)^n  && \quad \text{(by Lemma~\ref{lem norm estimate})}\\
& && < C (\epsilon |b|)^n&& \quad \text{(by~\eqref{eqn remainder bounds})}\\
& && \leq |b|^n&& \quad \text{(by~\eqref{eqn choice epsilon} )}\\
& && =|\NN(b)| && \quad \text{(by multiplicativity of $|.|$ and~\eqref{eqn norm b})}.
\end{alignat*}
This proves~\eqref{eqn final norm estimate} and thereby finishes the proof of the theorem.
\end{proof}

Now we need to generalize the result above from $b \in R$ to $b \in S$ (nonzero).

\begin{corollary}\label{cor generalized norm euclidean}
Assume $R$ is admissible.
There exists a finite set $M \subset R-\{0\}$, depending only on the $R$-integral basis $b_1,\ldots,b_n \in S$, such that
for all $a, b \in S$ with $b \not=0$ there exist $q \in S$ and $r \in M$ with $|\NN(ra-qb)| < |\NN(b)|$.
\end{corollary}

\begin{proof}
Unfold definitions (via $\gamma=a/b)$ and use multiplicativity of the norm \ldots
\end{proof}

%------------------------------------------
\section{Finiteness of the class group in the admissible case}
%------------------------------------------

Notation as in previous section.

The following is a trivial statement about choosing an element of minimal nonzero absolute norm in a nonzero ideal (which obviously also holds for any subset containing a nonzero element).
\begin{lemma}\label{lem element of nonzero minimal norm}
Let $I$ be a nonzero ideal of $S$. Then there exists a nonzero $b \in I$ such that for all $c \in I$
\begin{equation}\label{eqn element of nonzero minimal norm}
|\NN(c)| < |\NN(b)| \Rightarrow c=0.
\end{equation}
\end{lemma}

\begin{proof}
Trivial, namely $\{|\NN(b)| : b \in I-\{0\} \}$ contains a smallest element, which is a positive integer \ldots
\end{proof}

\begin{theorem}
Let $M$ be as in Corollary~\ref{cor generalized norm euclidean} and let $m$ be a nonzero common multiple of all elements in $M$ (e.~g.~ the product, so it exists).
Then for any nonzero ideal $I$ of $S$, there exists an ideal $J$ of $S$ such that $I \sim J$ and $J | \langle m \rangle_S$.
\end{theorem}

\begin{proof}
Let $I$ be a nonzero ideal of $S$.
\begin{itemize}
\item Choose a nonzero $b \in I$ such that for all $c \in I$ we have~\eqref{eqn element of nonzero minimal norm}.
(Possible by Lemma\ref{lem element of nonzero minimal norm}.)
\item Let $a \in I$. Since $M$ is as in Corollary~\ref{cor generalized norm euclidean}, we get $q \in S$ and $r \in M$ with $|\NN(r a-qb)| < |\NN(b)|$. Let $c:=ra-qb \in I$ (since $a,b \in I$), then the previous item gives us $ra-qb=0$, i.e.
\[ra=qb.\]
\item
So $\langle m \rangle_S I \subseteq \langle b \rangle$.
\item
Now $ \langle m \rangle I = \langle b \rangle J$ for a nonzero ideal $J$ of $S$, and consequently $I \sim J$. Furthermore, $b \in I$, so $ \langle b \rangle \subset I$, so $ \langle m \rangle \langle b \rangle \subset \langle m \rangle I = \langle b \rangle J$. This gives $\langle m \rangle \subset J$, and hence $J | \langle m \rangle$.
\end{itemize}
\end{proof}

\begin{theorem}\label{thm class group finite admissible}
The class group of $S$ is finite.
\end{theorem}

\begin{proof}
Previous theorem, together with Proposition~\ref{prop finitely many ideal divisors} gives finitely may possibilities for $J$. So finitely many possibilities for $\overline{I} \in \Cl(S)$. Hence $\Cl(S)$ is finite.
\end{proof}

%------------------------------------------
\section{Admissibility of $\Z$ and $\F_q[t]$}
%------------------------------------------

\begin{lemma}\label{lem Z admissible}
$\Z$ (with $|.|_{\text{arch}}$) is admissible.
\end{lemma}

\begin{proof}
This easily follows directly from the box principle\ldots
\end{proof}

The remainder of this section is about the admissibility of $\F_q[t]$, where $\F_q$ denotes a finite field wit $q$ elements.
The key is the following result.

\begin{lemma}
Let $D \in \N$, $b \in \F_q[t]$ (nonzero if that makes live easier), and define $M:=q^D$. Then for every function
$A_1: \N_{\leq M} \to \F_q[t]$ with $\forall j \in  \N_{\leq M}, \deg A_1(j) < \deg b$, there exists $j,k \in \N_{\leq M}$ such that
\[j \neq k \text{ and } \deg(A_1(k)-A_1(j)) < \deg b-D.\]
\end{lemma}

\begin{proof}
WLOG $D \leq \deg b$ (note we use $\deg 0 = -\infty < $ any integer).

Every $A_1(j)$ is of the form $\sum_{i \in \N_{< \deg b}} c_i^{(j)} t^i$ with coefficients $c_i^{(j)} \in \F_q$.
There are a priori $M=q^D$ possibilities for the coefficients $c_{\deg b-1}^{(j)}, c_{\deg b-2}^{(j)},\ldots, c_{\deg b-D}^{(j)}$.
So by the box principle, among the $q^D+1$ polynomials $A_1(0), \ldots, A_1(M)$, there must be at least two, say $A_1(j), A_1(k),\ j\not=k$ with coefficients
\[c_{\deg b-1}^{(j)}=c_{\deg b-1}^{(k)}, c_{\deg b-2}^{(j)}= c_{\deg b-2}^{(k)},\ldots, c_{\deg b-D}^{(j)}= c_{\deg b-D}^{(k)}.\] Hence we can write
 \[A_1(k)-A_1(j)=\sum_{i \in \N_{<\deg b-D}} (c_i^{(k)}-c_i^{(j)}) t^i,\]
i.e. $\deg (A_1(k)-A_1(j))<\deg b-D$, as was to be shown.
\end{proof}

We now translate the previous lemma.
\begin{lemma}
Let $\epsilon \in \R_{>0}$, $b \in \F_q[t]$, and choose $D \in \N$ such that $M:=q^D\geq 1/\epsilon$ (e.~g.~ $D:=\operatorname{ceiling} (-\log \epsilon/\log q)$).
Then for every function
$A_1: \N_{\leq M} \to \F_q[t]$ there exists $j,k \in \N_{\leq M}$ such that
\[j \neq k \text{ and } |\remainder(A_1(k),b)-\remainder(A_1(j),b)| < \epsilon |b|.\]
\end{lemma}

\begin{proof}
Choose $A_1$ and write $f_i:= |\remainder(A_1(i),b)|$, so $\deg f_i < \deg b$. By the previous Lemma we have $j\not=k$ such that
\[\deg (f_k-f_j) <\deg b -D.\]
It suffices to show that
\[|f_k-f_j| <\epsilon |b|.\]
This holds, since:
\[ |f_k-f_j|=q^{\deg(f_k-f_j)}<q^{\deg b -D}=q^{\deg b}/M=|b|/M\leq \epsilon |b|.\]
\end{proof}

\begin{lemma}\label{lem admissible 1D}
For $R=\F_q[t]$ both:
\begin{itemize}
\item we have a function $\M_1 : \R_{>0} \to \N$;
\item for all $ \epsilon \in \R_{>0}$, $b \in R$, and $A_1: \N_{\leq \M_1(\epsilon)} \to R$ there exists $j,k \in \N_{\leq \M_1(\epsilon)}$ such that
\[j \neq k \text{ and } |\remainder(A_1(k),b)-\remainder(A_1(j),b)| < \epsilon |b|.\]
\end{itemize}
\end{lemma}

\begin{proof}
Follows from previous lemma (with $\M_1(\epsilon)=M=q^D$).
\end{proof}

\begin{lemma}\label{lem Fqt admissible}
$\F_q[t]$ (with $|.|_{\deg}$) is admissible.
\end{lemma}

\begin{proof}
Follows from Lemma~\ref{lem admissible 1D} for any $R$ with a nonarchimedean absolute value, by using the box principle\ldots
(Taking $\M(\epsilon,n)=\M_1(\epsilon)^n$.)
\end{proof}

%------------------------------------------
\section{On the finiteness of the class group for global fields}
%------------------------------------------

Let $\F$ be a finite field. Let us specialise to $R=\Z$ or $R=\F[t]$, with fraction field $K=\Q$ or $K=\F(t)$ respectively. As before, we let $L$ be a finite separable field extension of $K$ (where separability is automatic if $K=\Q$) and denote by $S$ the integral closure of $R$ in $L$, called the ring of integers of $L$ (which strictly speaking depends on $R$ in the positive characteristic case).

From Lemmata~\ref{lem Z admissible} and~\ref{lem Fqt admissible} together with Theorem~\ref{thm class group finite admissible} we now get our main theorem.

\begin{theorem}
The class group of $S$ is finite.
\end{theorem}

\end{document}

%------------------------------------------
\section{Example: The class group of $\Q[\sqrt{-5}]$}
%------------------------------------------

We claim that for $K=\Q(\sqrt{-5})$, the statements hold for $M=2$.
...

More precisely,  $J | \langle 2 \rangle = \langle 2,1+\sqrt{-5} \rangle^2$, where $P:=\langle 2,1+\sqrt{-5} \rangle$ is a nonprincipal prime ideal. From which we now see that $\Cl(\OK)=\{\overline{\OK},\overline{P}\}$, in particular $h(\OK)=\#\Cl(\OK)=2$.

\end{document}

%------------------------------------------
\bibliographystyle{amsplain}
%------------------------------------------

\bibliography{FinitenessClassGrou[}