\documentclass[12pt]{article}

\usepackage{graphicx}
\usepackage[margin=1in,nohead,nofoot]{geometry}
\usepackage{wrapfig}
\usepackage{xcolor}
\usepackage{enumitem}
\setlist[itemize]{noitemsep}
\usepackage{hyperref}
\hypersetup{linkbordercolor=blue}
\usepackage{sidecap}
\usepackage{cite}
\usepackage{setspace}
\usepackage[backgroundcolor = blue!0,bordercolor = red]{todonotes}
\usepackage{xcolor}
\usepackage{amsmath}

\usepackage{fancyhdr}
\setlength{\headheight}{60pt}
\setlength{\topmargin}{-50pt}
\setlength{\headsep}{10pt}
\pagestyle{fancy}
\rhead{\textit{Robot to Camera Calibration}}
\lhead{}
\chead{}
\lfoot{March 3, 2016}
\cfoot{\thepage}
\rfoot{Georgia Tech - Michael Sobrepera}
\renewcommand{\headrulewidth}{0.1pt}
\renewcommand{\footrulewidth}{0.1pt}

\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage{subcaption}

\setlength{\footskip}{20pt}

%Eat whitespace
\singlespacing
\usepackage[subtle]{savetrees}

\begin{document}

	\section{Motivation}
	When using a robot and a fixed camera together it is often necessary to calibrate the camera's coordinate frame to that of the robot base. This allows what is seen in the camera to be turned into meaningful commands for the robot.

	In order to do this, I propose to use a single grid, arbitrarily mounted to the robot, past its final degree of freedom. By moving the grid to a number of different positions and capturing those positions kinematically from the robot and visually from the camera. This will generate a series of equations which can then be solved to determine the transformation from the camera to the robot.

	\section{Setup}
	In order to perform this procedure, the robot and camera should be fixed, with the camera viewing the robot. A checkerboard grid should be attached to the robot past the final joint, it is easiest to attach the grid to the tool flange. The grid should be asymmetrical and should have a white border.

	\section{Math}
	The center of this problem is finding a transformation given a set of parallel transformations and many sample points. This can be seen in \autoref{fig:transformations}

	\begin{figure}
		\centering
		\def\svgwidth{\textwidth}
		\input{transformatin_diagram.pdf_tex}
		\caption{\textbf{Transformations}. The transformation $C$ can be measured by tracking the grid, so long as the camera intrinsics are well calibrated. The transformation $G$ is unknown, however, it does not change as the grid is rigidly attached to the tool center point (TCP). The transformation $T$ can be gathered directly from the robots forward kinematics. The goal is to solve for the transformation $R$, which is unknown, but constant.}
		\label{fig:transformations}
	\end{figure}

	Given \autoref{fig:transformations} we can develop some math using dual quaternions to solve for $R$ given a number of matches pairs samples of $T$ and $C$.

	First we re-define $T$ a more useful version of $T$
	\begin{equation}
	T = T^*
	\end{equation}

	We then define the transformation from the camera to the TCP using dual quaternions where given dual quaternion $q$ the dual quaternion can be decomposed into quaternions $q_r +  q_d$ which can be further decomposed to individual elements $q_{r_w} + q_{r_x} i + q_{r_y} j + q_{r_z} k + (q_{d_w} + q_{d_x} i + q_{d_y} j + q_{d_z} k)\epsilon$.

	We can now describe, in steps, the transformation from the camera to the UR Base. We begin by defining the transformation from the Camera to the Grid:
	\begin{equation}
		C_r G_r+(C_r G_d + C_d G_r)\epsilon
	\end{equation}
	We then extend this from the camera to the UR Base, which is equivalent to $R$:
	\begin{equation}
		R = C_r G_r T_r + (C_r G_r T_d + (C_r G_d + C_d G_r)T_r)\epsilon
	\end{equation}
	We then proceed to expand this into individual units and standard math:

	\begin{equation}
		\begin{split}
			R_{r_w} = \\&
			(C_{r_w} G_{r_w}-C_{r_x} G_{r_x}-C_{r_y} G_{r_y}-C_{r_z} G_{r_z}) T_{r_w}+\\&(C_{r_x} G_{r_w}+C_{r_w} G_{r_x}-C_{r_z} G_{r_y}+C_{r_y} G_{r_z}) T_{r_x}+\\&(C_{r_y} G_{r_w}+C_{r_z} G_{r_x}+C_{r_w} G_{r_y}-C_{r_x} G_{r_z}) T_{r_y}+\\&(C_{r_z} G_{r_w}-C_{r_y} G_{r_x}+C_{r_x} G_{r_y}+C_{r_w} G_{r_z}) T_{r_z}
		\end{split}
		\label{eq:rrw}
	\end{equation}
	\begin{equation}
		\begin{split}
			R_{r_x} = \\&
			(C_{r_x} G_{r_w}+C_{r_w} G_{r_x}-C_{r_z} G_{r_y}+C_{r_y} G_{r_z}) T_{r_w}-\\&(C_{r_w} G_{r_w}-C_{r_x} G_{r_x}-C_{r_y} G_{r_y}-C_{r_z} G_{r_z}) T_{r_x}+\\&(C_{r_z} G_{r_w}-C_{r_y} G_{r_x}+C_{r_x} G_{r_y}+C_{r_w} G_{r_z}) T_{r_y}-\\&(C_{r_y} G_{r_w}+C_{r_z} G_{r_x}+C_{r_w} G_{r_y}-C_{r_x} G_{r_z}) T_{r_z}
		\end{split}
		\label{eq:rrx}
	\end{equation}
	\begin{equation}
		\begin{split}
			R_{r_y} = \\&
			(C_{r_y} G_{r_w}+C_{r_z} G_{r_x}+C_{r_w} G_{r_y}-C_{r_x} G_{r_z}) T_{r_w}-\\&(C_{r_z} G_{r_w}-C_{r_y} G_{r_x}+C_{r_x} G_{r_y}+C_{r_w} G_{r_z}) T_{r_x}-\\&(C_{r_w} G_{r_w}-C_{r_x} G_{r_x}-C_{r_y} G_{r_y}-C_{r_z} G_{r_z}) T_{r_y}+\\&(C_{r_x} G_{r_w}+C_{r_w} G_{r_x}-C_{r_z} G_{r_y}+C_{r_y} G_{r_z}) T_{r_z}
		\end{split}
		\label{eq:rry}
	\end{equation}
	\begin{equation}
		\begin{split}
			R_{r_z} = \\&
			(C_{r_z} G_{r_w}-C_{r_y} G_{r_x}+C_{r_x} G_{r_y}+C_{r_w} G_{r_z}) T_{r_w}+\\&(C_{r_y} G_{r_w}+C_{r_z} G_{r_x}+C_{r_w} G_{r_y}-C_{r_x} G_{r_z}) T_{r_x}-\\&(C_{r_x} G_{r_w}+C_{r_w} G_{r_x}-C_{r_z} G_{r_y}+C_{r_y} G_{r_z}) T_{r_y}-\\&(C_{r_w} G_{r_w}-C_{r_x} G_{r_x}-C_{r_y} G_{r_y}-C_{r_z} G_{r_z}) T_{r_z}
		\end{split}
		\label{eq:rrz}
	\end{equation}
	\begin{equation}
		\begin{split}
			R_{d_w} = \\&
			(C_{r_w} G_{r_w} - C_{r_x} G_{r_x} - C_{r_y} G_{r_y} -
			C_{r_z} G_{r_z}) T_{d_w} +\\& (C_{r_x} G_{r_w} +
			C_{r_w} G_{r_x} - C_{r_z} G_{r_y} +
			C_{r_y} G_{r_z}) T_{d_x} + \\&(C_{r_y} G_{r_w} +
			C_{r_z} G_{r_x} + C_{r_w} G_{r_y} -
			C_{r_x} G_{r_z}) T_{d_y} +\\& (C_{r_z} G_{r_w} -
			C_{r_y} G_{r_x} + C_{r_x} G_{r_y} +
			C_{r_w} G_{r_z}) T_{d_z} +\\& (C_{r_w} G_{d_w} -
			C_{r_x} G_{d_x} - C_{r_y} G_{d_y} - C_{r_z} G_{d_z} +
			C_{d_w} G_{r_w} - C_{d_x} G_{r_x} - C_{d_y} G_{r_y} -
			C_{d_z} G_{r_z}) T_{r_w} -\\& (C_{r_x} G_{d_w} +
			C_{r_w} G_{d_x} - C_{r_z} G_{d_y} + C_{r_y} G_{d_z} +
			C_{d_x} G_{r_w} + C_{d_w} G_{r_x} - C_{d_z} G_{r_y} +
			C_{d_y} G_{r_z}) T_{r_x} -\\& (C_{r_y} G_{d_w} +
			C_{r_z} G_{d_x} + C_{r_w} G_{d_y} - C_{r_x} G_{d_z} +
			C_{d_y} G_{r_w} + C_{d_z} G_{r_x} + C_{d_w} G_{r_y} -
			C_{d_x} G_{r_z}) T_{r_y} - \\&(C_{r_z} G_{d_w} -
			C_{r_y} G_{d_x} + C_{r_x} G_{d_y} + C_{r_w} G_{d_z} +
			C_{d_z} G_{r_w} - C_{d_y} G_{r_x} + C_{d_x} G_{r_y} +
			C_{d_w} G_{r_z}) T_{r_z}
		\end{split}
		\label{eq:rdw}
	\end{equation}
	\begin{equation}
		\begin{split}
			R_{d_x} = \\&
			(C_{r_x} G_{r_w} +
			C_{r_w} G_{r_x} - C_{r_z} G_{r_y} +
			C_{r_y} G_{r_z}) T_{d_w} -\\& (C_{r_w} G_{r_w} -
			C_{r_x} G_{r_x} - C_{r_y} G_{r_y} -
			C_{r_z} G_{r_z}) T_{d_x} +\\& (C_{r_z} G_{r_w} -
			C_{r_y} G_{r_x} + C_{r_x} G_{r_y} +
			C_{r_w} G_{r_z}) T_{d_y} - \\&(C_{r_y} G_{r_w} +
			C_{r_z} G_{r_x} + C_{r_w} G_{r_y} -
			C_{r_x} G_{r_z}) T_{d_z} +\\& (C_{r_x} G_{d_w} +
			C_{r_w} G_{d_x} - C_{r_z} G_{d_y} + C_{r_y} G_{d_z} +
			C_{d_x} G_{r_w} + C_{d_w} G_{r_x} - C_{d_z} G_{r_y} +
			C_{d_y} G_{r_z}) T_{r_w} + \\&(C_{r_w} G_{d_w} -
			C_{r_x} G_{d_x} - C_{r_y} G_{d_y} - C_{r_z} G_{d_z} +
			C_{d_w} G_{r_w} - C_{d_x} G_{r_x} - C_{d_y} G_{r_y} -
			C_{d_z} G_{r_z}) T_{r_x} - \\&(C_{r_z} G_{d_w} -
			C_{r_y} G_{d_x} + C_{r_x} G_{d_y} + C_{r_w} G_{d_z} +
			C_{d_z} G_{r_w} - C_{d_y} G_{r_x} + C_{d_x} G_{r_y} +
			C_{d_w} G_{r_z}) T_{r_y} + \\&(C_{r_y} G_{d_w} +
			C_{r_z} G_{d_x} + C_{r_w} G_{d_y} - C_{r_x} G_{d_z} +
			C_{d_y} G_{r_w} + C_{d_z} G_{r_x} + C_{d_w} G_{r_y} -
			C_{d_x} G_{r_z}) T_{r_z}
		\end{split}
		\label{eq:rdx}
	\end{equation}
	\begin{equation}
		\begin{split}
			R_{d_y} = \\&
			(C_{r_y} G_{r_w} +
			C_{r_z} G_{r_x} + C_{r_w} G_{r_y} -
			C_{r_x} G_{r_z}) T_{d_w} -\\& (C_{r_z} G_{r_w} -
			C_{r_y} G_{r_x} + C_{r_x} G_{r_y} +
			C_{r_w} G_{r_z}) T_{d_x} -\\& (C_{r_w} G_{r_w} -
			C_{r_x} G_{r_x} - C_{r_y} G_{r_y} -
			C_{r_z} G_{r_z}) T_{d_y} +\\& (C_{r_x} G_{r_w} +
			C_{r_w} G_{r_x} - C_{r_z} G_{r_y} +
			C_{r_y} G_{r_z}) T_{d_z} + \\&(C_{r_y} G_{d_w} +
			C_{r_z} G_{d_x} + C_{r_w} G_{d_y} - C_{r_x} G_{d_z} +
			C_{d_y} G_{r_w} + C_{d_z} G_{r_x} + C_{d_w} G_{r_y} -
			C_{d_x} G_{r_z}) T_{r_w} +\\& (C_{r_z} G_{d_w} -
			C_{r_y} G_{d_x} + C_{r_x} G_{d_y} + C_{r_w} G_{d_z} +
			C_{d_z} G_{r_w} - C_{d_y} G_{r_x} + C_{d_x} G_{r_y} +
			C_{d_w} G_{r_z}) T_{r_x} +\\& (C_{r_w} G_{d_w} -
			C_{r_x} G_{d_x} - C_{r_y} G_{d_y} - C_{r_z} G_{d_z} +
			C_{d_w} G_{r_w} - C_{d_x} G_{r_x} - C_{d_y} G_{r_y} -
			C_{d_z} G_{r_z}) T_{r_y} -\\& (C_{r_x} G_{d_w} +
			C_{r_w} G_{d_x} - C_{r_z} G_{d_y} + C_{r_y} G_{d_z} +
			C_{d_x} G_{r_w} + C_{d_w} G_{r_x} - C_{d_z} G_{r_y} +
			C_{d_y} G_{r_z}) T_{r_z}
		\end{split}
		\label{eq:rdy}
	\end{equation}
	\begin{equation}
		\begin{split}
			R_{d_z} = \\&
			(C_{r_z} G_{r_w} -
			C_{r_y} G_{r_x} + C_{r_x} G_{r_y} +
			C_{r_w} G_{r_z}) T_{d_w} + \\&(C_{r_y} G_{r_w} +
			C_{r_z} G_{r_x} + C_{r_w} G_{r_y} -
			C_{r_x} G_{r_z}) T_{d_x} - \\&(C_{r_x} G_{r_w} +
			C_{r_w} G_{r_x} - C_{r_z} G_{r_y} +
			C_{r_y} G_{r_z}) T_{d_y} - \\&(C_{r_w} G_{r_w} -
			C_{r_x} G_{r_x} - C_{r_y} G_{r_y} -
			C_{r_z} G_{r_z}) T_{d_z} + \\&(C_{r_z} G_{d_w} -
			C_{r_y} G_{d_x} + C_{r_x} G_{d_y} + C_{r_w} G_{d_z} +
			C_{d_z} G_{r_w} - C_{d_y} G_{r_x} + C_{d_x} G_{r_y} +
			C_{d_w} G_{r_z}) T_{r_w} -\\& (C_{r_y} G_{d_w} +
			C_{r_z} G_{d_x} + C_{r_w} G_{d_y} - C_{r_x} G_{d_z} +
			C_{d_y} G_{r_w} + C_{d_z} G_{r_x} + C_{d_w} G_{r_y} -
			C_{d_x} G_{r_z}) T_{r_x} +\\& (C_{r_x} G_{d_w} +
			C_{r_w} G_{d_x} - C_{r_z} G_{d_y} + C_{r_y} G_{d_z} +
			C_{d_x} G_{r_w} + C_{d_w} G_{r_x} - C_{d_z} G_{r_y} +
			C_{d_y} G_{r_z}) T_{r_y} +\\& (C_{r_w} G_{d_w} -
			C_{r_x} G_{d_x} - C_{r_y} G_{d_y} - C_{r_z} G_{d_z} +
			C_{d_w} G_{r_w} - C_{d_x} G_{r_x} - C_{d_y} G_{r_y} -
			C_{d_z} G_{r_z}) T_{r_z}
		\end{split}
		\label{eq:rdz}
	\end{equation}

	We have 6 terms which put together generate one unique equation set. Given enough samples, and with knowledge that $R$ and $G$ never change, this system becomes solvable. To do this, we will reformat the equations into a computationally friendly matrix form.

	Lets try to make a matrix from this with the form:
	\begin{equation}
		\begin{bmatrix}
			a
		\end{bmatrix}
		\begin{bmatrix}
			coeff
		\end{bmatrix}
		=
		\begin{bmatrix}
			b
		\end{bmatrix}
		\label{eq:generalFormMatrix}
	\end{equation}

	\begin{equation}
		\begin{bmatrix}
			a_{0,0} & \cdots & a_{1,15} \\
			\vdots  & \ddots & \vdots   \\
			a_{n,0} & \cdots & a_{n,15}
		\end{bmatrix}
		\begin{bmatrix}
			G_{r_w} \\
			G_{r_x} \\
			G_{r_y} \\
			G_{r_z} \\
			G_{d_w} \\
			G_{d_x} \\
			G_{d_y} \\
			G_{d_z} \\
			R_{r_w} \\
			R_{r_x} \\
			R_{r_y} \\
			R_{r_z} \\
			R_{d_w} \\
			R_{d_x} \\
			R_{d_y} \\
			R_{d_z}
		\end{bmatrix}
		=
		\begin{bmatrix}
			0
		\end{bmatrix}
		\label{eq:generalMatrix}
	\end{equation}

	Each sample will generate a set of 8 equations ($R_{r_w}$, $R_{r_x}$, $R_{r_y}$, $R_{r_z}$, $R_{d_w}$, $R_{d_x}$, $R_{d_y}$, $R_{d_z}$) to add to the matrix. We group the equations by unknowns.

	From \autoref{eq:rrw} we generate:
	\begin{equation}
	    \begin{split}
	0= \\&
	G_{r_w} (C_{r_w} T_{r_w}+C_{r_x} T_{r_x}+C_{r_y} T_{r_y}+C_{r_z} T_{r_z})+\\&
	G_{r_x} (-C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z})+\\&
	G_{r_y} (-C_{r_y} T_{r_w}-C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\&
	G_{r_z} (-C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}+C_{r_w} T_{r_z})+\\&
	 R_{r_w}(-1)
	\end{split}
	\end{equation}

	Which in turn generates a row of the $a$ matrix in \autoref{eq:generalMatrix}:

	\begin{equation}
	    \begin{bmatrix}
	    C_{r_w} T_{r_w}+C_{r_x} T_{r_x}+C_{r_y} T_{r_y}+C_{r_z} T_{r_z}\\
	    -C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z}\\
	    -C_{r_y} T_{r_w}-C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\
	    -C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}+C_{r_w} T_{r_z}\\
	    0 \\ 0 \\ 0 \\ 0 \\ -1 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0
	    \end{bmatrix}^T
	\end{equation}

	From \autoref{eq:rrx} we generate:
	\begin{equation}
	    \begin{split}
	0= \\&
	G_{r_y} (-C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}-C_{r_w} T_{r_z})+\\&
	G_{r_z} (C_{r_y} T_{r_w}+C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\&
	G_{r_w} (C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z})+\\&
	G_{r_x} (C_{r_w} T_{r_w}+C_{r_x} T_{r_x}-C_{r_y} T_{r_y}-C_{r_z} T_{r_z})+\\&
	 R_{r_x}(-1)
	 \end{split}
	 \end{equation}

	 Which in turn generates another row of the $a$ matrix in \autoref{eq:generalMatrix}:

	 \begin{equation}
	     \begin{bmatrix}
	     -C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}-C_{r_w} T_{r_z}\\
	     C_{r_y} T_{r_w}+C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\
	     C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z}\\
	     C_{r_w} T_{r_w}+C_{r_x} T_{r_x}-C_{r_y} T_{r_y}-C_{r_z} T_{r_z}\\
	     0 \\ 0 \\ 0 \\ 0 \\ 0 \\ -1 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0
	      \end{bmatrix}^T
	  \end{equation}

	From \autoref{eq:rry} we generate:
	\begin{equation}
	    \begin{split}
	0= \\&
	G_{r_w} (C_{r_y} T_{r_w}-C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\&
	G_{r_x} (C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}+C_{r_w} T_{r_z})+\\&
	G_{r_y} (C_{r_w} T_{r_w}-C_{r_x} T_{r_x}+C_{r_y} T_{r_y}-C_{r_z} T_{r_z})+\\&
	G_{r_z} (-C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z})+\\&
	 R_{r_y}(-1)
	 \end{split}
	 \end{equation}

	 Which in turn generates another row of the $a$ matrix in \autoref{eq:generalMatrix}:

	 \begin{equation}
	     \begin{bmatrix}
	     C_{r_y} T_{r_w}-C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\
	     C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}+C_{r_w} T_{r_z}\\
	     C_{r_w} T_{r_w}-C_{r_x} T_{r_x}+C_{r_y} T_{r_y}-C_{r_z} T_{r_z}\\
	     -C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z}\\
	     0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ -1 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0
	      \end{bmatrix}^T
	  \end{equation}

	  From \autoref{eq:rrz} we generate:
	  \begin{equation}
	      \begin{split}
	  0= \\&
	  G_{r_w} (C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}-C_{r_w} T_{r_z})+\\&
	  G_{r_x} (-C_{r_y} T_{r_w}+C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\&
	  G_{r_y} (C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z})+\\&
	  G_{r_z} (C_{r_w} T_{r_w}-C_{r_x} T_{r_x}-C_{r_y} T_{r_y}+C_{r_z} T_{r_z})+\\&
	   R_{r_z}(-1)
	   \end{split}
	   \end{equation}

	   Which in turn generates another row of the $a$ matrix in \autoref{eq:generalMatrix}:

	   \begin{equation}
	       \begin{bmatrix}
	       C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}-C_{r_w} T_{r_z}\\
	       -C_{r_y} T_{r_w}+C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\
	       C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z}\\
	       C_{r_w} T_{r_w}-C_{r_x} T_{r_x}-C_{r_y} T_{r_y}+C_{r_z} T_{r_z}\\
	       0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ -1 \\ 0 \\ 0 \\ 0 \\ 0
	        \end{bmatrix}^T
	    \end{equation}

From \autoref{eq:rdw} we generate:
\begin{equation}
    \begin{split}
0= \\&
G_{r_w} (C_{r_w} T_{d_w}+C_{r_x} T_{d_x}+C_{r_y} T_{d_y}+C_{r_z} T_{d_z}+C_{d_w} T_{r_w}+C_{d_x} T_{r_x}+C_{d_y} T_{r_y}+C_{d_z} T_{r_z})+\\&
G_{r_x} (-C_{r_x} T_{d_w}+C_{r_w} T_{d_x}+C_{r_z} T_{d_y}-C_{r_y} T_{d_z}-C_{d_x} T_{r_w}+C_{d_w} T_{r_x}+C_{d_z} T_{r_y}-C_{d_y} T_{r_z})+\\&
G_{r_y} (-C_{r_y} T_{d_w}-C_{r_z} T_{d_x}+C_{r_w} T_{d_y}+C_{r_x} T_{d_z}-C_{d_y} T_{r_w}-C_{d_z} T_{r_x}+C_{d_w} T_{r_y}+C_{d_x} T_{r_z})+\\&
G_{r_z} (-C_{r_z} T_{d_w}+C_{r_y} T_{d_x}-C_{r_x} T_{d_y}+C_{r_w} T_{d_z}-C_{d_z} T_{r_w}+C_{d_y} T_{r_x}-C_{d_x} T_{r_y}+C_{d_w} T_{r_z})+\\&
G_{d_w} (C_{r_w} T_{r_w}+C_{r_x} T_{r_x}+C_{r_y} T_{r_y}+C_{r_z} T_{r_z})+\\&
G_{d_x} (-C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z})+\\&
G_{d_y} (-C_{r_y} T_{r_w}-C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\&
G_{d_z} (-C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}+C_{r_w} T_{r_z})+\\&
 R_{d_w}(-1)
 \end{split}
 \end{equation}

 Which in turn generates another row of the $a$ matrix in \autoref{eq:generalMatrix}:

 \begin{equation}
     \begin{bmatrix}
     C_{r_w} T_{d_w}+C_{r_x} T_{d_x}+C_{r_y} T_{d_y}+C_{r_z} T_{d_z}+C_{d_w} T_{r_w}+C_{d_x} T_{r_x}+C_{d_y} T_{r_y}+C_{d_z} T_{r_z}\\
     -C_{r_x} T_{d_w}+C_{r_w} T_{d_x}+C_{r_z} T_{d_y}-C_{r_y} T_{d_z}-C_{d_x} T_{r_w}+C_{d_w} T_{r_x}+C_{d_z} T_{r_y}-C_{d_y} T_{r_z}\\
     -C_{r_y} T_{d_w}-C_{r_z} T_{d_x}+C_{r_w} T_{d_y}+C_{r_x} T_{d_z}-C_{d_y} T_{r_w}-C_{d_z} T_{r_x}+C_{d_w} T_{r_y}+C_{d_x} T_{r_z}\\
     -C_{r_z} T_{d_w}+C_{r_y} T_{d_x}-C_{r_x} T_{d_y}+C_{r_w} T_{d_z}-C_{d_z} T_{r_w}+C_{d_y} T_{r_x}-C_{d_x} T_{r_y}+C_{d_w} T_{r_z}\\
     C_{r_w} T_{r_w}+C_{r_x} T_{r_x}+C_{r_y} T_{r_y}+C_{r_z} T_{r_z}\\
     -C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z}\\
     -C_{r_y} T_{r_w}-C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\
     -C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}+C_{r_w} T_{r_z}\\
     0 \\ 0 \\ 0 \\ 0 \\ -1 \\ 0 \\ 0 \\ 0
      \end{bmatrix}^T
  \end{equation}

  From \autoref{eq:rdx} we generate:
  \begin{equation}
      \begin{split}
  0= \\&
  G_{r_w} (C_{r_x} T_{d_w}-C_{r_w} T_{d_x}+C_{r_z} T_{d_y}-C_{r_y} T_{d_z}+C_{d_x} T_{r_w}-C_{d_w} T_{r_x}+C_{d_z} T_{r_y}-C_{d_y} T_{r_z})+\\&
  G_{r_x} (C_{r_w} T_{d_w}+C_{r_x} T_{d_x}-C_{r_y} T_{d_y}-C_{r_z} T_{d_z}+C_{d_w} T_{r_w}+C_{d_x} T_{r_x}-C_{d_y} T_{r_y}-C_{d_z} T_{r_z})+\\&
  G_{r_y} (-C_{r_z} T_{d_w}+C_{r_y} T_{d_x}+C_{r_x} T_{d_y}-C_{r_w} T_{d_z}-C_{d_z} T_{r_w}+C_{d_y} T_{r_x}+C_{d_x} T_{r_y}-C_{d_w} T_{r_z})+\\&
  G_{r_z} (C_{r_y} T_{d_w}+C_{r_z} T_{d_x}+C_{r_w} T_{d_y}+C_{r_x} T_{d_z}+C_{d_y} T_{r_w}+C_{d_z} T_{r_x}+C_{d_w} T_{r_y}+C_{d_x} T_{r_z})+\\&
  G_{d_w} (C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z})+\\&
  G_{d_x} (C_{r_w} T_{r_w}+C_{r_x} T_{r_x}-C_{r_y} T_{r_y}-C_{r_z} T_{r_z})+\\&
  G_{d_y} (-C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}-C_{r_w} T_{r_z})+\\&
  G_{d_z} (C_{r_y} T_{r_w}+C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\&
   R_{d_x}(-1)
   \end{split}
   \end{equation}

   Which in turn generates another row of the $a$ matrix in \autoref{eq:generalMatrix}:

   \begin{equation}
       \begin{bmatrix}
       C_{r_x} T_{d_w}-C_{r_w} T_{d_x}+C_{r_z} T_{d_y}-C_{r_y} T_{d_z}+C_{d_x} T_{r_w}-C_{d_w} T_{r_x}+C_{d_z} T_{r_y}-C_{d_y} T_{r_z}\\
       C_{r_w} T_{d_w}+C_{r_x} T_{d_x}-C_{r_y} T_{d_y}-C_{r_z} T_{d_z}+C_{d_w} T_{r_w}+C_{d_x} T_{r_x}-C_{d_y} T_{r_y}-C_{d_z} T_{r_z}\\
       -C_{r_z} T_{d_w}+C_{r_y} T_{d_x}+C_{r_x} T_{d_y}-C_{r_w} T_{d_z}-C_{d_z} T_{r_w}+C_{d_y} T_{r_x}+C_{d_x} T_{r_y}-C_{d_w} T_{r_z}\\
       C_{r_y} T_{d_w}+C_{r_z} T_{d_x}+C_{r_w} T_{d_y}+C_{r_x} T_{d_z}+C_{d_y} T_{r_w}+C_{d_z} T_{r_x}+C_{d_w} T_{r_y}+C_{d_x} T_{r_z}\\
       C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}-C_{r_y} T_{r_z}\\
       C_{r_w} T_{r_w}+C_{r_x} T_{r_x}-C_{r_y} T_{r_y}-C_{r_z} T_{r_z}\\
       -C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}-C_{r_w} T_{r_z}\\
       C_{r_y} T_{r_w}+C_{r_z} T_{r_x}+C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\
       0 \\ 0 \\ 0 \\ 0 \\ 0 \\ -1 \\ 0 \\ 0
        \end{bmatrix}^T
    \end{equation}

	From \autoref{eq:rdy} we generate:
	\begin{equation}
	    \begin{split}
	0= \\&
	G_{r_w} (C_{r_y} T_{d_w}-C_{r_z} T_{d_x}-C_{r_w} T_{d_y}+C_{r_x} T_{d_z}+C_{d_y} T_{r_w}-C_{d_z} T_{r_x}-C_{d_w} T_{r_y}+C_{d_x} T_{r_z})+\\&
	G_{r_x} (C_{r_z} T_{d_w}+C_{r_y} T_{d_x}+C_{r_x} T_{d_y}+C_{r_w} T_{d_z}+C_{d_z} T_{r_w}+C_{d_y} T_{r_x}+C_{d_x} T_{r_y}+C_{d_w} T_{r_z})+\\&
	G_{r_y} (C_{r_w} T_{d_w}-C_{r_x} T_{d_x}+C_{r_y} T_{d_y}-C_{r_z} T_{d_z}+C_{d_w} T_{r_w}-C_{d_x} T_{r_x}+C_{d_y} T_{r_y}-C_{d_z} T_{r_z})+\\&
	G_{r_z} (-C_{r_x} T_{d_w}-C_{r_w} T_{d_x}+C_{r_z} T_{d_y}+C_{r_y} T_{d_z}-C_{d_x} T_{r_w}-C_{d_w} T_{r_x}+C_{d_z} T_{r_y}+C_{d_y} T_{r_z})+\\&
	G_{d_w} (C_{r_y} T_{r_w}-C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\&
	G_{d_x} (C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}+C_{r_w} T_{r_z})+\\&
	G_{d_y} (C_{r_w} T_{r_w}-C_{r_x} T_{r_x}+C_{r_y} T_{r_y}-C_{r_z} T_{r_z})+\\&
	G_{d_z} (-C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z})+\\&
	 R_{d_y}(-1)
	 \end{split}
	 \end{equation}

	 Which in turn generates another row of the $a$ matrix in \autoref{eq:generalMatrix}:

	 \begin{equation}
	     \begin{bmatrix}
	     C_{r_y} T_{d_w}-C_{r_z} T_{d_x}-C_{r_w} T_{d_y}+C_{r_x} T_{d_z}+C_{d_y} T_{r_w}-C_{d_z} T_{r_x}-C_{d_w} T_{r_y}+C_{d_x} T_{r_z}\\
	     C_{r_z} T_{d_w}+C_{r_y} T_{d_x}+C_{r_x} T_{d_y}+C_{r_w} T_{d_z}+C_{d_z} T_{r_w}+C_{d_y} T_{r_x}+C_{d_x} T_{r_y}+C_{d_w} T_{r_z}\\
	     C_{r_w} T_{d_w}-C_{r_x} T_{d_x}+C_{r_y} T_{d_y}-C_{r_z} T_{d_z}+C_{d_w} T_{r_w}-C_{d_x} T_{r_x}+C_{d_y} T_{r_y}-C_{d_z} T_{r_z}\\
	     -C_{r_x} T_{d_w}-C_{r_w} T_{d_x}+C_{r_z} T_{d_y}+C_{r_y} T_{d_z}-C_{d_x} T_{r_w}-C_{d_w} T_{r_x}+C_{d_z} T_{r_y}+C_{d_y} T_{r_z}\\
	     C_{r_y} T_{r_w}-C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\
	     C_{r_z} T_{r_w}+C_{r_y} T_{r_x}+C_{r_x} T_{r_y}+C_{r_w} T_{r_z}\\
	     C_{r_w} T_{r_w}-C_{r_x} T_{r_x}+C_{r_y} T_{r_y}-C_{r_z} T_{r_z}\\
	     -C_{r_x} T_{r_w}-C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z}\\
	     0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ -1 \\ 0
	      \end{bmatrix}^T
	  \end{equation}

From \autoref{eq:rdz} we generate:
\begin{equation}
    \begin{split}
0= \\&
G_{r_w} (C_{r_z} T_{d_w}+C_{r_y} T_{d_x}-C_{r_x} T_{d_y}-C_{r_w} T_{d_z}+C_{d_z} T_{r_w}+C_{d_y} T_{r_x}-C_{d_x} T_{r_y}-C_{d_w} T_{r_z})+\\&
G_{r_x} (-C_{r_y} T_{d_w}+C_{r_z} T_{d_x}-C_{r_w} T_{d_y}+C_{r_x} T_{d_z}-C_{d_y} T_{r_w}+C_{d_z} T_{r_x}-C_{d_w} T_{r_y}+C_{d_x} T_{r_z})+\\&
G_{r_y} (C_{r_x} T_{d_w}+C_{r_w} T_{d_x}+C_{r_z} T_{d_y}+C_{r_y} T_{d_z}+C_{d_x} T_{r_w}+C_{d_w} T_{r_x}+C_{d_z} T_{r_y}+C_{d_y} T_{r_z})+\\&
G_{r_z} (C_{r_w} T_{d_w}-C_{r_x} T_{d_x}-C_{r_y} T_{d_y}+C_{r_z} T_{d_z}+C_{d_w} T_{r_w}-C_{d_x} T_{r_x}-C_{d_y} T_{r_y}+C_{d_z} T_{r_z})+\\&
G_{d_w} (C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}-C_{r_w} T_{r_z})+\\&
G_{d_x} (-C_{r_y} T_{r_w}+C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z})+\\&
G_{d_y} (C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z})+\\&
G_{d_z} (C_{r_w} T_{r_w}-C_{r_x} T_{r_x}-C_{r_y} T_{r_y}+C_{r_z} T_{r_z})+\\&
 R_{d_z}(-1)
 \end{split}
 \end{equation}

 Which in turn generates another row of the $a$ matrix in \autoref{eq:generalMatrix}:

 \begin{equation}
     \begin{bmatrix}
     C_{r_z} T_{d_w}+C_{r_y} T_{d_x}-C_{r_x} T_{d_y}-C_{r_w} T_{d_z}+C_{d_z} T_{r_w}+C_{d_y} T_{r_x}-C_{d_x} T_{r_y}-C_{d_w} T_{r_z}\\
     -C_{r_y} T_{d_w}+C_{r_z} T_{d_x}-C_{r_w} T_{d_y}+C_{r_x} T_{d_z}-C_{d_y} T_{r_w}+C_{d_z} T_{r_x}-C_{d_w} T_{r_y}+C_{d_x} T_{r_z}\\
     C_{r_x} T_{d_w}+C_{r_w} T_{d_x}+C_{r_z} T_{d_y}+C_{r_y} T_{d_z}+C_{d_x} T_{r_w}+C_{d_w} T_{r_x}+C_{d_z} T_{r_y}+C_{d_y} T_{r_z}\\
     C_{r_w} T_{d_w}-C_{r_x} T_{d_x}-C_{r_y} T_{d_y}+C_{r_z} T_{d_z}+C_{d_w} T_{r_w}-C_{d_x} T_{r_x}-C_{d_y} T_{r_y}+C_{d_z} T_{r_z}\\
     C_{r_z} T_{r_w}+C_{r_y} T_{r_x}-C_{r_x} T_{r_y}-C_{r_w} T_{r_z}\\
     -C_{r_y} T_{r_w}+C_{r_z} T_{r_x}-C_{r_w} T_{r_y}+C_{r_x} T_{r_z}\\
     C_{r_x} T_{r_w}+C_{r_w} T_{r_x}+C_{r_z} T_{r_y}+C_{r_y} T_{r_z}\\
     C_{r_w} T_{r_w}-C_{r_x} T_{r_x}-C_{r_y} T_{r_y}+C_{r_z} T_{r_z}\\
     0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ -1
      \end{bmatrix}^T
  \end{equation}

These rows can then be put into a solver, such as numpy.linalg.lstsq, with the b matrix set to a single column of all zeros, equal in length to the height of the resulting $a$ matrix.
\end{document}


\chapter{Taxonomy}

Artificial intelligence is constrained optimization.
Brain minimizes free energy \cite{friston2006free,friston2010free}.

Generate vs discriminative.

Type type of an \emph{expert system} is \(Facts \to Query \to Answer\).
Decision tree.
Linearized decision tree.

A learning algorithm is \emph{stable} iff its generalization error is bounded.

\section{Voronoi classifier}

Find out the cluster centers.
Let the Voronoi diagram be the boundary.

\section{Hyperplane classifier}

Let \(h\) be a hyperplane.
Define \(m : \Real^\infty \to \{0,1\}\),
the \emph{hard linear binary classifier} of \(h\),
as \(m~x = [h~x \ge 0]\)
where \([x]\) is 1 iff \(x\) is true or 0 iff \(x\) is false.
Soft classifier: define \(m~x = \tanh^{-1}~(h~x)\).

\section{Support vector machine}

A training point \(x\) is a support of \(h\) iff
it is the closest point to \(h\)
among all points in the class of \(x\).

Alternative formulation:
An upper level is a hyperplane \(h_u\) such that \(\forall a \in U : h_u~a > 0\).
A lower level is a hyperplane \(h_l\) such that \(\forall b \in L : h_l~b < 0\).
Let \(h_u\) and \(h_l\) be parallel.
Maximize the distance between \(h_u\) and \(h_l\).
Then \(h_u\) is the upper margin and \(h_l\) is the lower margin.
Define \(h\) as the hyperplane exactly between \(h_u\) and \(h_l\).

Define \(m : \Real^\infty \to \{0,1\}\),
the \emph{support vector machine} (SVM) of \(h\),
as \(m~x = [h~x \ge 0]\).
Such SVM is a binary classifier.


\subsubsection{Geothermal Heat Flux}
The heat flux accross the basal boundary depends on past temperature variations since temperature perturbations penetrate the bed rock if the ice is frozen to the ground \citep{Ritz1987}.
The heat equation for the bed rock layer is given by the diffusion equation
\begin{equation}
  \label{num.eq.diffu_rock}
  \frac{\pd T}{\pd t} = \frac{k_{\text{rock}}}{\rho_{\text{rock}}c_{\text{rock}}}\nabla^2T=\frac{k_{\text{rock}}}{\rho_{\text{rock}}c_{\text{rock}}}
  \left(\frac{\pd^2 T}{\pd x^2}+\frac{\pd^2 T}{\pd y^2}+\frac{\pd^2 T}{\pd z^2}\right),
\end{equation}
where $k_{\text{rock}}$ is the thermal conductivity, $\rho_{\text{rock}}$ the density and $c_{\text{rock}}$ the specific heat capacity of the bed rock layer.

Initial conditions for the temperature field $T$ are found by applying the geothermal heat flux, $G$ to an arbitrary surface temperature $T_0$:
\begin{equation}
  T(x,y,z)=T_0+\frac{G}{k_{\text{rock}}}z.
\end{equation}
This ensures that initially the geothermal heat flux experienced by the ice sheet is equal to the regional heat flux. The basal boundary condition of the bedrock layer is kept constant, i.e.
\begin{equation}
  T(x,y,H_{\text{rock}})=T_0+\frac{G}{k_{\text{rock}}}H_{\text{rock}}.
\end{equation}
Lateral boundary conditions are given by
\begin{equation}
  \left.\frac{\pd T}{\pd x}\right|_{x=0} = \left.\frac{\pd T}{\pd x}\right|_{x=L_x} = \left.\frac{\pd T}{\pd y}\right|_{y=0} = \left.\frac{\pd T}{\pd y}\right|_{y=L_y} = 0.
\end{equation}
At the upper boundary, the heat flux of the rock layer has to be matched with the heat flux in the basal ice layer when the ice is frozen to the bed, i.e.
\begin{equation}
  \label{num.eq.gthf_bc}
  k_{\text{rock}}\left.\frac{\pd T}{\pd z}\right|_{z=-0}=k_{\text{ice}}\left.\frac{\pd T}{\pd z}\right|_{z=+0}.
\end{equation}
Otherwise the temperature of the top bedrock layer is set to the surface temperature (if the cell has been occupied by ice, but there is no ice present) or the basal ice temperature (if there is ice). Equation \eqref{num.eq.gthf_bc} is automatically fulfilled if we set the top bedrock temperature to the basal ice temperature \emph{everywhere} and then calculate the geothermal heat flux to be used as boundary condition for Equation \eqref{temp.eq.temp_z}.

\subsection{Numerical Solution}
The horizontal grid is described in Section \ref{num.sec.grid}. The vertical grid is irregular like the vertical grid of the ice sheet model. However, it is not scaled. Also for now, I have ignored topography or isostatic adjustment, i.e. the bedrock layer is assumed to be flat and constant.

The horizontal second derivative in Equation \eqref{num.eq.diffu_rock} becomes using finite--differences
\begin{equation}
  \left.\frac{\pd^2T}{\pd x^2}\right|_{x_i,y_i,z_i} = T_{xx,i,j,k} = \frac{T_{i+1,j,k}-2T_{i,j,k}+T_{i-1,j,k}}{\Delta x}
\end{equation}
and similarly for $\pd^2T/\pd y^2$. The vertical second derivative $\pd^2T/\pd z^2$ is similar to Equation \eqref{temp.eq.dsigma2}:
\begin{multline}
  \left.\frac{\pd^2 T}{\pd z^2}\right|_{x_i,y_i,z_i} = T_{zz,i,j,k} = \frac{2T_{i,j,k-1}}{(z_k-z_{k-1})(z_{k+1}-z_{k-1})} - \frac{2T_{i,j,k}}{(z_{k+1}-z_k)(z_k-z_{k-1})}\\
  + \frac{2T_{i,j,k+1}}{(z_{k+1}-z_k)(z_{k+1}-z_{k-1})}
\end{multline}

Using the Crank-Nicholson scheme, Equation \eqref{num.eq.diffu_rock} becomes
\begin{equation}
  \label{num.eq.diffu_rock_disc}
  \frac{T_{i,j,k}^{t+1}-T_{i,j,k}^{t}}{\Delta t}=D\left\{\frac{T_{xx,i,j,k}^{t+1}+T_{xx,i,j,k}^{t}}2 + \frac{T_{yy,i,j,k}^{t+1}+T_{yy,i,j,k}^{t}}2 + \frac{T_{zz,i,j,k}^{t+1}+T_{zz,i,j,k}^{t}}2 \right\},
\end{equation}
with $D=k_{\text{rock}}/(\rho_{\text{rock}}c_{\text{rock}})$. Equation \eqref{num.eq.diffu_rock_disc} is solved by gathering all $T^{t+1}$ terms on the LHS and all other terms on the RHS. The index $(i,j,k)$ is linearised using $\iota = i+(j-1)N+(k-1)NM$. The resulting matrix system is solved using the same bi--conjugate gradient solver as for the ice thickness evolution.


%---------------------------Radius Ratio-----------------------------
\section{Radius Ratio}

Let $h_{\max}$ be the maximum length of all edges and diagonals
\[
  h_{\max} = \max\left(L_{\max},D_{\max}\right)
\]
and ${\cal L}_2$ be the sum of the squares of all edge lengths
\[
{\cal L}_2 = \sum_{i=0}^3\normvec{L_i}^2
\]
and ${\cal A}_i$ be the area of one of the 4 triangles formed by pairs of quadrilateral neighboring edges
\[
  {\cal A}_i = \left|\frac{\alpha_i}{2}\right|.
\]
Then the radius ratio of a planar quadrilateral is
\[
  q = \frac{{\cal L}_2 h_{\max}}{\min_{i\in\{0,1,2,3\}}{\cal A}_i}.
\]

\quadmetrictable{radius ratio}%
{$1$}%                                      Dimension
{$[1,1.3]$}%                                Acceptable range
{$[1,DBL\_MAX]$}%                           Normal range
{$[1,DBL\_MAX]$}%                           Full range
{$1$}%                                      Square
{\cite{pebay:04}}%                          Citation
{v\_quad\_radius\_ratio}%                   Verdict function name


\section{Discussion}

We have implemented a prototype of the tool described above. Out of the features we had envised, the alotted time for this thesis allowed us to build a working prototype that can abstract programs running under PSO. In this section, we discuss our expectations of the tool's behaviour and performance. We also show the results of run time measurements made with the tool and we compare it to the implementation of Dan et al. \cite{danetal13}.

\subsection{Complexity}

We examine the time- and space complexities of the individual phases of our computation:

\subsubsection{Buffer size analysis}

Computing the buffer size increases caused by each program point has a time complexity linear to the number of program points. For PSO programs, computing the actual buffer sizes needed at each program point requires a comparison of all buffer sizes per variable per program point. For TSO programs however, differentiating between variables is not needed. Therefore, the overall time complexity for the buffer size analysis in itself is $\mathcal{O}(mn)$ in PSO, and $\mathcal{O}(m)$ in TSO, with $m$ being the number of program points in $P$, and $n$ being the number of global variables in $P$.\\

Examining the replacement codes of both PSO and TSO, we see that the time we need to generate replacement code blocks is mainly the time of the actual output, as there is no more complex computation necessary to be able to output the code, than the output itself needs. Therefore, generating the replacement codes has the following complexity by statement and store order: store statements: $\mathcal{O}(K)$ in both TSO and PSO; load statements: $\mathcal{O}(K)$ in both TSO and PSO; fence statements: $\mathcal{O}(n)$ in PSO, $\mathcal{O}(K)$ in TSO; flush statements: $\mathcal{O}(nK)$ for TSO and PSO. Therefore, we can conclude that the code replacements following the buffer size analysis are bounded by the $\mathcal{O}(nK)$-complex flush replacement. Since all replaceable statements are program points, the entire process of replacing them is multiplied by $m$ in complexity.\\

Therefore, the buffer size analysis stage has a time complexity of $\mathcal{O}(mnK)$

\subsubsection{Predicate abstraction}

Our implementation of the predicate abstraction performed in accordance with our expectation of the Z3 \cite{z3} calls being by far the most time-consuming, with run time percentages ranging from an average of 43.5\% for Dekker's algorithm, to an average of 76.3\% for the alternating bit protocol, as shown in Table 1. This shows that while complexity reduction is always an issue as long as we have problems of an untractable complexity, reducing the number of satisfiability modulo theory (SMT) solver calls has the most potential for speedup.\\

The complexity of all function calls in the predicate abstraction phase is therefore much less significant than the complexity of the number of SMT calls. Employing the optimisations described in section 4., the number of SMT solver calls is bounded by $|E|$ to the power of the maximum number of terms in a cube. This bound is in practice significantly lower when implicative cubes are found that are below the specified size limit, but this number is highly specific to the algorithm and the corresponding predicates.

\subsection{Evaluation}

We have implemented the procedures as described so far in a tool we call SROTOGAP. Then, we have run numerous tests on the following concurrent algorithms: the alternating bit protocol, Lamport's Bakery Algorithm, Dekker's Algorithm, Peterson's Algorithm, a lock-free queue, and Szyma\'nski's Mutual Exclusion Algorithm. All experiments were conducted on an Intel(R) Core(TM) i7-3770 3.40GHz with 8GB RAM. The key questions were whether the buffer size analysis has significantly shortened the time needed to perform a correct predicate abstraction, and whether the replacement techniques employed in the predicate abstraction stage have warded off the complexity explosion that would have resulted from the na\"ive execution of current predicate analysis methods on the additional predicates spawned from the buffer abstraction.\\

We compare our results to those of Dan et al. \cite{danetal13}, as the measurements had been done on the same algorithms, and the methods were similar. To be more precise: this work seeks to improve on the methods described in \cite{danetal13}, and we hope to show that our modifications have helped to improve the performance of those methods. The modifications done are as follows:\\

\paragraph{Buffer size analysis}

As opposed to Dan et al. \cite{danetal13}, we perform a buffer size analysis on the program in order to be able to minimise the lines of code generated during our replacement phase by seeking to omit parts which we know never to be reached during run-time. We approach this task by statically analising the input, and performing replacements which can be generated in polynomial time.\\

\paragraph{Flush abstraction optimisation}

In \cite{danetal13}, flushes have been modeled in a way that caused each iteration to shift at most $K$ variables, which would have effectively increased the run time of a flush, and the number of program states for each flush operation. In our implementation, the buffer is modelled to be ``immobile'', i.e. a value stored in the buffer is considered to remain in place until it has been flushed or otherwise deleted. This provides us with the following advantages: each flush iteration only adds one state to the set of program states; the time complexity of flushes is dominated by finding the value to be flushed, not iterating over every value in the buffer; and finally, if the buffer size is exceeded at run time, an immobile buffer tail will always trigger an overflow error at the $K + 1$st consecutive store, while the approach in \cite{danetal13} would non-deterministically cause the buffer tail to recede from the buffer size limit with each flush - though this might be beneficial from an efficient resource allocation point of view, we would like to simplify reaching possible erroneous states for purposes of error detection.\\

\pagebreak

\begin{center}
\textbf{Table 1.} Boolean program generation\\
\begin{tabular}{|r|r|r|r|r|r|r|}

	\hline
	algorithm & \vtop{\hbox{\strut \# input}\hbox{\strut predicates}} & \vtop{\hbox{\strut \# total}\hbox{\strut predicates}} & \vtop{\hbox{\strut \# unique}\hbox{\strut cubes}} & \vtop{\hbox{\strut \# SMT}\hbox{\strut calls}} & time (s) & \vtop{\hbox{\strut maximum}\hbox{\strut cube size}}	\\ \hline
	Dekker		&	7	&	27	&	15		&	566		&	6.01	&	1	\\ \hline
	Peterson	&	7	&	27	&	99		&	572		&	4.40	&	2	\\ \hline
	ABP			&	8	&	12	&	129		&	488		&	2.36	&	2	\\ \hline
	Szyma\'nski	&	20	&	70	&	801		&	1257	&	10.05	&	2	\\ \hline
	LF Queue	&	7	&	32	&	939		&	2556	&	15.24	&	4	\\ \hline
	Bakery		&	15	&	75	&	25931	&	85268	&	974.71	&	4	\\ \hline

\end{tabular}\\

\paragraph{}
\textbf{Table 2.} Model checking until error state found\\
\begin{tabular}{|r|r|r|r|}

	\hline
	algorithm & \vtop{\hbox{\strut \# states}\hbox{\strut before error}} & memory used (MB) & evaluation time (s) \\ \hline
	Dekker		&	98	&	5	&	0.030	\\ \hline
	Peterson	&	98	&	5	&	0.034	\\ \hline
	ABP			&	327	&	4	&	0.045	\\ \hline
	Szyma\'nski	&	247	&	7	&	0.043	\\ \hline
	LF Queue	&	157	&	24	&	0.388	\\ \hline
	Bakery		&	310	&	36	&	0.323	\\ \hline

\end{tabular}
\end{center}

All measurements were done under PSO with $K = 5$, i.e. the implementation of the principles discussed for TSO is not included in this work. Furthermore, the model checker has judged all abstractions to be incorrect. This proves that the boolean programs generated by our prototype are not yet verifiable by Fender. Though there was no time to completely debug our code, we can still compare the overall performance of the tool, to get an idea of the potential changes in performance and complexity. Note that we omitted evaluating the ticket locking algorithm, although it had been tested in \cite{danetal13}, as our definition of SALPL does not include blocks of atomic code.\\

Comparing the measurements in \cite{danetal13} with ours, we first note that we have worked the sequential consistency predicates although we have abstracted programs under PSO, as it was our goal to abstract programs using only the predicates needed to prove correctness under sequential consistency constraints. The predicates actually generated by our program are far more numerous and their numbers are less expressive, as their number increases with the multitude of variables and the newly generated predicates do not cause any additional SMT calls.\\

Another fact we notice is that SROTOGAP generates about 100 times as many cubes as CUPEX \cite{danetal13} for low cube sizes, but less cubes for high cube sizes. This result should be observed with caution however, as in all cases with the cube size limit being $> 2$, the largest cube disjunction, the disjunction of cubes implying $false$, has timed out in SROTOGAP, which has triggered a halt in that computation, thus preventing the inception of a number of cubes possibly orders of magnitude larger than their counterparts in \danetal{13}. This comes as no surprise, as even without SMT calls, the cubes generated using heuristics grows with the number of total predicates $|E \cup E'|$.\\

The numbers of model checker states are markably lower in our work than they were in \cite{danetal13}. This metric however, along with the other two model checker metrics, is possibly the least significant for our intended comparison, as the model checker has obviously received erroneous outputs from SROTOGAP.


\section{Fourier Series}
\subsection{Periodic Functions}
\begin{definition}
    A function $f$ is periodic with period $T$ is $f(x+T)=f(x)$ for any $x$.
\end{definition}
\begin{example}
    The physical quantities in a simple harmonic motion are periodic in time $t$.
    For example, if we take a simple pendulum, then the height of the pendulum bulb can be described
    \footnote{Approximated.}
    by $y=A\sin(\omega t)$, so $y$ is periodic (in $t$) with period $T=2\pi/\omega$.
    So it has angular frequency $\omega$ and frequency $f=1/T$.\\
    In space, the wavelength is $\lambda=2\pi/k$ and the (angular) wavenumber is $k=2\pi/\lambda$.
\end{example}
Consider the set of functions $g_n(x)=\cos(n\pi x/L)$ and $h_n(x)=\sin(n\pi x/L)$ where $n$ is taken as positive integer.
They are obviously all periodic with period $2L$.
\begin{definition}
    For (sufficiently nice) $f,g:[0,2L)\to\mathbb R$, we define their inner product to be
    $$\langle f,g\rangle =\int_0^{2L}f(x)g(x)\,\mathrm dx$$
\end{definition}
\begin{proposition}
    The functions $g_n,h_n$ are mutually orthogonal on the inteval $[0,2L]$ with respect to the inner product above.
\end{proposition}
\begin{proof}
    Recall the identites we learnt half an eternity ago:
    \begin{align*}
        \cos A\cos B&=\frac{\cos(A-B)+\cos(A+B)}{2}\\
        \sin A\sin B&=\frac{\cos(A-B)-\cos(A+B)}{2}\\
        \sin A\cos B&=\frac{\sin(A-B)+\sin(A+B)}{2}
    \end{align*}
    We can obtain, by simply integrating, that $\langle h_n,g_m\rangle=0$ for any $m,n$.
    Similarly, for any $m\neq n$, $\langle h_n,h_m\rangle=\langle g_n,g_m\rangle=0$.
    So they are orthogonal.
\end{proof}
What if $m=n$?
By integrating again, we can get
$$\langle g_n,g_n\rangle=\begin{cases}
    L\text{, if $n\neq 0$}\\
    2L\text{, if $n=0$}
\end{cases},\langle h_n,h_n\rangle=\begin{cases}
    L\text{, if $n\neq 0$}\\
    0\text{, if $n=0$}
\end{cases}$$
This shows that $g_n$ and $h_n$ form a linearly independent set.
We decree that this set actually ``spans'' the space of ``well-behaved'' periodic functions with period $2L$.
We will get to the intuitive reason why we make such an assertion (and what does it actually mean) in a moment.\\
In finite dimensional vector spaces like $\mathbb R^3$, we have the standard basis which forms a orthonormal basis.
We can make the analogy to the space of nice enough functions mentioned above so that we can say this set of trigonometric functions form a ``basis'' there given that we can indeed represent every (nice) function with a (possibly infinite) series of linear combinations of $f_n,g_n$.
\footnote{As you expect, something not rigourous shall start to happen.}
\subsection{Definition of a Fourier Series}
We assert that we can represent any ``well-behaved'' periodic functions $f$ with period $2L$ in the form
$$\frac{1}{2}a_0+\sum_{n=1}^\infty a_n\cos\frac{n\pi x}{L}+\sum_{n=1}^\infty b_n\sin\frac{n\pi x}{L}$$
We sure will want this series to converge to $f$ wherever $f$ is continuous.
As a jump discontinuity, we would want this series to converge to the average value of the upper and lower limits of $f$ at that point.\\
If these conditions are satisfied and we are allowed to exchange limiting operations, previous discussions then yield
$$\langle h_n,f\rangle=Lb_n\implies b_n=\frac{1}{L}\langle h_n,f\rangle=\frac{1}{L}\int_0^{2L}f(x)\sin\frac{n\pi x}{L}\,\mathrm dx$$
Similarly, for any $n$ we have
$$a_n=\frac{1}{L}\langle g_n,f\rangle=\frac{1}{L}\int_0^{2L}f(x)\cos\frac{n\pi x}{L}\,\mathrm dx$$
\begin{note}
    1. The coefficient $1/2$ in front of $a_0$ helped here as it makes the above formula work for $n=0$ too.
    Actually $a_0/2$ is the average value of $f$ over the interval $[0,2L)$.\\
    2. The range of integration actually does not matter much as long as its length is $2L$.
    E.g. we can replace it by $[-L,L)$ as well.\\
    3. We can think of the Fourier series of a function as decomposing the function into harmonics.
\end{note}
\begin{example}[Sawtooth wave]
    Consider a $2L$-periodic function where $f(x)=x$ for $x\in [-L,L)$.
    Then obviously $a_n=0$ for any $n$ as $f$ is odd.
    Whereas integration by part reveals that $b_n=2L(-1)^{n+1}/(n\pi)$.
    So the Fourier series has the form
    $$2L\sum_{n=1}^\infty\frac{(-1)^{n+1}}{n\pi}\sin\frac{n\pi x}{L}$$
    We know this is (slowly) convergent by the alternating series test.
    A plot of the truncated series seems to show that it does converge to what we want.
\end{example}
\begin{note}
    In the above example, as $n\to\infty$, the Fourier series approximation improves and convergent where the original function is continuous.
    Also, at the discontinuity, it does converge to the average value of the limits from two sides.
    So this particular Fourier series behaves as advertised.\\
    One should also observe that this Fourier series has a persistent ``overshoot'' near the discontinuity which is approximately $9\%$.
    This is known as the Gibbs' Phenomenon.
\end{note}
\subsection{The Dirichlet Conditions and Fourier's Theorem}
A natural question is then which functions are allowed to have a proper Fourier series.
Surprisingly, a big, yet hard to precisely characterise, class of functions has a convergent Fourier series that has the desired properties.
This class even includes some classical counterexamples in analysis.
As an applied course, we will just look at some of the sufficient conditions.
\begin{theorem}[Fourier's Theorem]
    If $f$ is a bounded periodic function with period $2L$ with a finite number of minima, maxima, and discontinuities in $[0,2L)$, then its Fourier series converges to $f$ where it is continuous and converges to the average of the two side limits.
\end{theorem}
The conditions in this theorem is known as the Dirichlet conditions.
\begin{note}
    1. These conditions are hella weak compared to our conditions for a function to have e.g. a Taylor series.
    However, pathological functions like $1/x,\sin(1/x),1_{\mathbb R\setminus\mathbb Q}(x)$ are excluded from these conditions.\\
    2. The converse is not true, as $\sin(1/x)$ has a Fourier series we desire.
\end{note}
\begin{proof}
    You don't really expect to see an actual proof here, do you?
\end{proof}
Another subject of interest is the rate of convergence of a Fourier series.
Perhaps unsurprisingly, it depends on the smoothness of the function.
\begin{theorem}
    If $f(x)$ is $p^{th}$ differentiable but $f^{(p)}$ is not continuous, then its Fourier series converges as $O(n^{-(p+1)})$ as $n\to\infty$.
\end{theorem}
\begin{proof}
    Ditto.
\end{proof}
\begin{example}
    1. Consider the square wave
    $$f(x)=\begin{cases}
        1\text{, for $0\le x<1$}\\
        -1\text{, for $-1\le x<0$}
    \end{cases}$$
    That extends periodically with period $2$.
    Then it has a Fourier series
    $$4\sum_{m=1}^\infty\frac{\sin[(2m-1)\pi x]}{(2m-1)\pi}$$
    which, as one can see both from the preceding theorem (with $p=0$) and observation, converges slowly.\\
    2. Consider the general ``see-saw'' wave
    $$f(x)=\begin{cases}
        x(1-\xi)\text{, for $x\in[0,\xi)$}\\
        \xi(1-x)\text{, for $x\in[\xi,1)$}
    \end{cases}$$
    which extends as an odd periodic function with period $2$.
    This has Fourier series
    $$2\sum_{m=1}^\infty\frac{\sin (n\pi\xi)\sin (n\pi x)}{(n\pi)^2}$$
    which converges with $p=1$ in the preceding theorem.
    In particular, $\xi=1/2$ gives
    $$2\sum_{m=1}^\infty(-1)^{m+1}\frac{\sin[(2m-1)\pi x]}{[(2m-1)\pi]^2}$$
    which can be seen, immediately, that it converges faster than the series in the previous example.\\
    3. Take $f(x)=x(1-x)/2$ for $x\in[0,1)$ that extends as an odd periodic function with period $2$.
    Then its Fourier series is
    $$4\sum_{m=1}^\infty\frac{\sin[(2m-1)\pi x]}{[(2m-1)\pi]^3}$$
    which has $p=2$.\\
    4. Take $f(x)=(1-x^2)^2$, then $a_n=O(n^{-4})$.
\end{example}
Of course, we want to integrate and differentiate a Fourier series term-by-term.
Integration, as one expect, seldom yields problems as it imposed very few restrictions on the function.
And indeed, we are just going to assume we can integrate any Fourier series term-by-term and they guarantee to yield a smoother function, which satisfies the Dirichlet conditions if the original function does.\\
Differentiation is more problematic when doing it term-by-term.
\begin{example}
    Take the square wave again which is known to have Fourier series
    $$4\sum_{m=1}^\infty\frac{\sin[(2m-1)\pi x]}{(2m-1)\pi}$$
    which, after term-by-term differentiation, yields
    $$4\sum_{m=1}^\infty\cos[(2m-1)\pi x]$$
    which is clearly divergent.
    This is perhaps unsurprising as the original function is not even continuous.
\end{example}
\begin{theorem}
    If $f(x)$ is differentiable and both $f,f^\prime$ satisfy Dirichlet conditions, then we can differentiate the Fourier series of $f$ term-by-term to get the Fourier series of $f^\prime$.
\end{theorem}
\begin{proof}
    Haha.
\end{proof}
\begin{example}
    If we differentiate the see-saw curve with $\xi=1/2$, then we will get an offset of the Fourier series of the square wave.
\end{example}
\subsection{Parseval's Theorem}
There is some interesting relation between the integral of the square of a function and the square of the Fourier coefficients of that function.
If the function is nice enough to have a nice enough Fourier series, then by orthogonality,
\begin{align*}
    \int_0^{2L}f(x)^2\,\mathrm dx&=\int_0^{2L}\left( \frac{a_0}{2}+\sum_{n\ge 1}a_n\cos\frac{n\pi x}{2}+\sum_{n\ge 1}b_n\sin\frac{n\pi x}{2} \right)^2\,\mathrm dx\\
    &=\int_0^{2L}\left( \frac{a_0^2}{4}+\sum_{n\ge 1}a_n^2\cos^2\frac{n\pi x}{2}+\sum_{n\ge 1}b_n^2\sin^2\frac{n\pi x}{2} \right)\,\mathrm dx\\
    &=L\left( \frac{a_0^2}{2}+\sum_{n\ge 1}(a_n^2+b_n^2) \right)
\end{align*}
This is also called the completeness relation as the left hand side would be greater than or equal to the right hand side if any basis functions are missing from the series.
This is known as Parseval's Theorem.
\begin{theorem}[Parseval's Theorem]\label{parseval}
    For a nice enough function $f$ with Fourier coefficients $a_n,b_n$, we have
    $$\int_0^{2L}f(x)^2\,\mathrm dx=L\left( \frac{a_0^2}{2}+\sum_{n\ge 1}(a_n^2+b_n^2) \right)$$
\end{theorem}
\begin{proof}
    Above.
\end{proof}
\begin{example}
    Consider the sawtooth curve with $f(x)=x,x\in[-L,L)$ with period $2L$.
    Then Parseval's Theorem reveals that
    $$\frac{2}{3}L^3=\int_{-L}^Lx^2\,\mathrm dx=L\sum_{n=1}^\infty\frac{4L^2}{n^2\pi^2}=\frac{4L^3}{\pi^2}\sum_{n=1}^\infty\frac{1}{n^2}\implies \sum_{n=1}^\infty\frac{1}{n^2}=\frac{\pi^2}{6}$$
\end{example}
\begin{remark}
    If we think of the integral of the square as the inner product of a function with itself, then Parseval's Theorem can be thought of an analog of Pythagoras' Theorem in this space of functions.
\end{remark}
\subsection{Alternative Fourier Series}
Consider a function $f:[0,L)\to\mathbb R$.
We can extend $f$ to a periodic function of period $2L$ in two ways:\\
1. We can require the function to be odd, then $a_n=0$ for all $n$ and
$$b_n=\frac{2}{L}\int_0^Lf(x)\sin\frac{n\pi x}{L}\,\mathrm dx$$
and the Fourier series would be $\sum_{n\ge 1}b_n\sin(n\pi x/L)$, which is called a Fourier sine series.
The sawtooth function is an example of this.\\
2. We can require the function to be even, then $b_n=0$ for all $n$ and
$$a_n=\frac{2}{L}\int_0^Lf(x)\cos\frac{n\pi x}{L}\,\mathrm dx$$
So the Fourier series is $a_0/2+\sum_{n\ge 1}a_n\cos(n\pi x/L)$.
This is called a Fourier cosine series.
$f(x)=(1-x^2)^2$ is an example (where $L=1$).\\
The actual thing we want is tp represent the Fourier series more neatly in terms of exponentials.
We know that
$$\cos\frac{n\pi x}{L}=\frac{e^{in\pi x/L}+e^{-in\pi x/L}}{2},\sin\frac{n\pi x}{L}=\frac{e^{in\pi x/L}-e^{-in\pi x/L}}{2i}$$
So by writing $c_0=a_0/2$ and
$$c_m=\begin{cases}
    (a_m-ib_m)/2\text{, for $m>0$}\\
    (a_{-m}+ib_{-m})/2\text{, for $m<0$}
\end{cases}$$
We obtain
$$\frac{a_0}{2}+\sum_{n=1}^\infty a_n\cos\frac{n\pi x}{L}+\sum_{n=1}^\infty b_n\sin\frac{n\pi x}{L}=\sum_{m=-\infty}^\infty c_me^{im\pi x/L}$$
Equivalently, if we extend our inner product to the complex functions
$$\langle f,g\rangle=\int_{-L}^Lf(x)g^*(x)\,\mathrm dx$$
Then $\langle e^{im\pi x/L},e^{in\pi x/L}\rangle=2L\delta_{mn}$, which means they are orthogonal as well and we can then obtain
$$c_m=\frac{1}{2L}\langle f(x),e^{im\pi x/L}\rangle=\frac{1}{2L}\int_{-L}^Lf(x)e^{-im\pi x/L}\,\mathrm dx$$
By thinking them as a set of basis of a space of nice-enough functions in the way we did for $\sin$ and $\cos$.
Parseval's Theorem can then be stated as
$$\int_{-L}^Lf(x)^2\,\mathrm dx=2L\sum_{n=-\infty}^\infty|c_n|^2$$
\subsection{Some Motivations of Fourier Series}
\begin{definition}
    The complex inner product $\langle,\rangle:\mathbb C^N\times\mathbb C^N\to\mathbb C$ is defined by
    $$\langle\underline{u},\underline{v}\rangle=\underline{u}^\dagger\underline{v}$$
\end{definition}
An $N\times N$  matrix $A$ is self-adjoint (or Hermitian) if
$$\forall\underline{u},\underline{v}\in\mathbb C^N,\langle A\underline{u},\underline{v}\rangle=\langle\underline{u},A\underline{v}\rangle$$
One can show easily that this is just saying $A^\dagger=A$.
It can be easily shown that $A$ satisfies:\\
1. All eigenvalues are real for all $n$.\\
2. Eigenvectors associated with different eigenvalues are orthogonal with respect to $\langle,\rangle$.\\
Spectral Theorem then shows that we have an orthonormal basis of $\mathbb C^N$ consisting of eigenvectors $\{\underline{v}_1,\ldots,\underline{v}_N\}$.\\
Now, given any $\underline{b}$, if we want to solve for $\underline{x}$ in $A\underline{x}=\underline{b}$, then a way to do it is to express $\underline{b}=\sum_nb_n\underline{v}_n$ and observe that if $\sum_nc_n\underline{v}_n$ is a solution then
$$\sum_nb_n\underline{v}_n=A\left(\sum_{n=1}^Nc_n\underline{v}_n\right)=\sum_{n=1}^Nc_n\lambda_n\underline{v}_n$$
where $\lambda_n$ is the eigenvalue associated with $\underline{v}_n$.
So if $A$ is nonsingular, then none of the $\lambda_n$ is zero and we can write $c_n=b_n/\lambda_n$ and get the solution
$$\underline{x}=\sum_{n=1}^N\frac{b_n}{\lambda_n}\underline{v}_n$$
This means we can easily solve an linear equation if there is a basis consisting of eigenvectors of the matrix.
We want an analogy of this in solving linear ODEs.
Consider the differential operator
$$\mathcal Ly=-\frac{\mathrm d^2y}{\mathrm dx^2}$$
and suppose we want to solve $\mathcal Ly=f(x)$ for a function $f(x)$ subject to boundary conditions $y(0)=y(L)=0$.
The related eigenvalue problem is then $\mathcal L y_n=\lambda_ny_n$ with $y_n(0)=y_n(L)=0$ which has solutions
$$y_n(x)=\sin\frac{n\pi x}{L},\lambda_n=\left( \frac{n\pi}{L} \right)^2$$
So we will want to write
$$y(x)=\sum_{n=1}^\infty c_n\sin\frac{n\pi x}{L},f(x)=\sum_{n=1}^\infty b_n\sin\frac{n\pi x}{L},b_n=\frac{2}{L}\int_0^Lf(x)\sin\frac{n\pi x}{L}\,\mathrm dx$$
and ignore every convergence problem.
Then this substitution yields
$$\sum_{n=1}^\infty b_n\sin\frac{n\pi x}{L}=\mathcal Ly=-\frac{\mathrm d^2y}{\mathrm dx^2}\left( \sum_{n=1}^\infty c_n\sin\frac{n\pi x}{L} \right)=\sum_{n=1}^\infty c_n\left( \frac{n\pi}{L} \right)^2\sin\frac{n\pi x}{L}$$
Hence, $c_n=b_n(L/(n\pi))^2$ by orthogonality, so we can get a particular solution of the problem in the form
$$y(x)=\sum_{n=1}^\infty \frac{b_n}{\lambda_n}y_n$$
which is the analogy we wanted.
\begin{example}\label{odd_sq_fourier_ode}
    Let $L=1$ and set $f$ to be the odd square wave with $f(x)=1$ for $x\in[0,1)$.
    This has Fourier series
    $$4\sum_{m=1}^\infty\frac{\sin[(2m-1)\pi x]}{(2m-1)\pi}$$
    So the above discussion instantly yield a solution
    $$y(x)=\sum_{n=1}^\infty \frac{b_n}{\lambda_n}y_n=4\sum_{m=1}^\infty\frac{\sin[(2m-1)\pi x]}{[(2m-1)\pi]^3}$$
    which is the Fourier series of $y(x)=x(1-x)/2$ on $[0,1)$ extending as an odd periodic function with period $2$.\\
    Indeed, as one can verifty, if we integrate $\mathcal y=1$ directly with the appropriate boundary conditions, we can get basically the same solution.
\end{example}
\subsection{A Glimpse into Green's Functions}
Fix $L=1$ and consider an odd function $f$.
We have
\begin{align*}
    y(x)&=\sum_{n=1}^\infty\frac{b_n}{\lambda_n}\sin(\pi x)\\
    &=\sum_{n=1}^\infty\frac{2}{(n\pi)^2}\left(\int_0^1f(\xi)\sin(n\pi\xi)\,\mathrm d\xi\right)\sin(n\pi x)\\
    &=\int_0^12\sum_{n=1}^\infty\frac{\sin(n\pi x)\sin(n\pi\xi)}{(n\pi)^2}f(\xi)\,\mathrm d\xi\\
    &=\int_0^1G(x,\xi)f(\xi)\,\mathrm d\xi
\end{align*}
where
$$G(x,\xi)=2\sum_{n=1}^\infty\frac{\sin(n\pi x)\sin(n\pi\xi)}{(n\pi)^2}$$
But we have seen $G$ before!
It is exactly the general see-saw wave
$$G(x,\xi)=\begin{cases}
    x(1-\xi)\text{, for $x\in[0,\xi)$}\\
    \xi(1-x)\text{, for $x\in[\xi,1)$}
\end{cases}$$
This is the Green's function for this ODE $\mathcal Ly=f$.
One can actually solve this integral and get what we got in Example \ref{odd_sq_fourier_ode}.


\subsection{Fisher information}

The Fisher information is the variance:

\(E[(\dfrac{\delta }{\delta \theta }\log f(X, \theta ))^2 |\theta ]\)

\(E[\dfrac{\delta^2 }{\delta \theta^2 }\log f(X, \theta ) |\theta ]\)

Same as expectation of score squared, because centred around \(0\).

\subsection{Fisher information matrix}

We have \(k\) parameters.

\(I(\theta )_{ij}=E[(\dfrac{\delta }{\delta \theta_i}\log f(X, \theta ))(\dfrac{\delta }{\delta \theta_j }\log f(X, \theta ))|\theta ]\)

\subsection{Observed Fisher information matrix}

The Fisher information matrix contains informatio about the population

The observed Fisher infoirmation is the negative of the Hessian of the log likelihood.

We have:

\begin{itemize}
\item \(l(\theta |\mathbf X)=\sum_i\ln P(\mathbf x_i|\theta )\)
\item \(J(\theta^*)=-\nabla \nabla^Tl(\theta|mathbf X )|_{\theta = \theta^*}\)
\end{itemize}

The Fisher information is the expected value of this.

\(I(\theta )=E[J(\theta)]\)


\section{The Richardson iteration}

\begin{intro}
  As a first example and prototype for all other iterative methods we
  consider Richardson's method, which for matrices and vectors in
  $\R^n$ reads
  \begin{gather}
    \label{eq:richardson:1}
    \vec x^{(k+1)}
    = \vec x^{(k)}
    - \omega_k \bigl(\mat A \vec x^{(k)} - \vec b \bigr).
  \end{gather}
  $\omega_k$ is a relaxation parameter, which can be chosen a priori
  or can be changed in every step. We will for simplicity assume
  $\omega_k = \omega$.
\end{intro}

\begin{Lemma}{richardson-error-step}
  \label{lemma:richardson:1}
  The error after one step of the Richardson method is given by
  \begin{gather}
    \label{eq:richardson:14}
    \vec x^{(k+1)} - x = \mat E \left(
      \vec x^{(k)} - x \right),
  \end{gather}
  where the \putindex{error propagation operator} is
  \begin{gather}
    \label{eq:richardson:15}
    \mat E = \mat I - \omega \mat A.
  \end{gather}
\end{Lemma}

\begin{proof}
  Using the fact that $\vec x = \mat A^{-1} \vec b$, we write
  \begin{gather*}
    \vec x^{(k+1)} - \vec x
    = \vec x^{(k)}
    - \omega \bigl(\mat A \vec x^{(k)} - \vec b \bigr) -  \vec x^{(k)}
    =  \vec x^{(k)} - \vec x - \omega \mat A \bigl(
     \vec x^{(k)} -  \vec x \bigr).
  \end{gather*}
\end{proof}

\begin{Theorem}{richardson-convergence1}
  \label{theorem:richardson:1}
  If $\mat A$ is symmetric, positive definite, with extremal
  eigenvalues $\lambda>0$ and $\Lambda>0$, then Richardson's method
  converges if and only if $0 < \omega < 2/\Lambda$. The optimal
  relaxation parameter is
  \begin{gather}
    \label{eq:richardson:2}
    \omega_{\text{opt}} = \frac{2}{\lambda+\Lambda},
  \end{gather}
  which yields an optimal contraction rate of
  \begin{gather}
    \label{eq:richardson:4}
    \rho_{\text{opt}}
    = 1-\frac{2\lambda}{\lambda+\Lambda}
    = \frac{\Lambda-\lambda}{\Lambda+\lambda}
    = \frac{\kappa-1}{\kappa+1}
    = 1 -\frac2\kappa + \mathcal
    O\left(\kappa^{-2}\right),
  \end{gather}
  where $\kappa = \Lambda/\lambda$ is the so called \define{spectral
    condition number}.
\end{Theorem}

\begin{proof}
  Convergence of this method is analyzed through the \putindex{Banach
    fixed-point theorem}, which requires contraction
  property of the matrix $\mat M = \mat I - \omega \mat A$.
  Alternatively, we studied a theorem that
  states, that a matrix iteration converges if and only if the
  spectral radius
  \begin{gather*}
    \rho(\mat M) = \max \left|\lambda(\mat M)\right| < 1,
  \end{gather*}
  the maximum absolute value of the eigenvalues of $\mat M$ is
  strictly less than one.

  If $\mat A$ is symmetric, positive definite, with eigenvalues
  $\lambda_i > 0$, we have that
  \begin{gather}
    \label{eq:richardson:13}
    \rho(\mat M) = \max_i \left|1-\omega \lambda_i\right|.
  \end{gather}
  Let the extremal eigenvalues be determined by the minimum and
  maximum of the Rayleigh quotient,
  \begin{gather}
    \label{eq:richardson:3}
    \lambda
    = \min_{x\in \R^n} \frac{\vec x^T\mat A\vec x}{\vec x^T\vec x},
    \qquad\text{and}\qquad
    \Lambda = \max_{x\in \R^n} \frac{\vec x^T\mat A\vec x}{\vec x^T\vec x}.
  \end{gather}
  Then, equation~\eqref{eq:richardson:13} yields that the method
  converges for $0 < \omega < 2/\Lambda$. Furthermore, for
  $1/\Lambda \le \omega \le 2/\Lambda$ we have
  \begin{gather*}
    \rho(\mat M) = \max \bigl\{ -1+\omega \Lambda,  1-\omega \lambda \bigr\}.
  \end{gather*}
  The optimal parameter $\omega$ is the one where both values are
  equal and thus~\eqref{eq:richardson:2} and~\eqref{eq:richardson:4} hold.
\end{proof}

\begin{intro}
  The analysis of finite element methods shows that it is beneficial
  to give up the focus on finite dimensional spaces and rather use
  theory that applies to separable Hilbert spaces. If results can
  obtained in this context, they can easily be restricted to finite
  dimensional subspaces and thus become uniform with respect to the
  mesh parameter. Thus, we will first reformulate Richardson's method
  for this case and then derive convergence estimates.
\end{intro}

\begin{intro}
  Elements of an abstract Hilbert space $X$ will be denoted by
  $u,v,w$, etc. On the other hand, coefficient vectors in $\R^n$ are
  denoted by letters $\vec x,\vec y,\vec z$, etc.
\end{intro}

\begin{Definition}{richardson-method}
  Let $X$ be a Hilbert space with inner product $\scal(.,.)$. Let
  $a(.,.)$ be a second bilinear form on $X$ and the domain of its
  operator is $V$. Then, for any right hand
  side $f\in V$ and any start vector $u^{(0)}\in V$,
  \define{Richardson's method} is defined by the iteration
  \begin{gather}
    \label{eq:richardson:5}
    \scal(u^{(k+1)},v) = \scal(u^{(k)},v)
    - \omega_k \bigl(a(u^{(k)},v) - \scal(f,v)\bigr), \qquad \forall v\in X.
  \end{gather}
  $\omega_k$ is a suitable \putindex{relaxation parameter}, chosen
  such that the method converges.
\end{Definition}

\begin{intro}
  The scalar products in~\eqref{eq:richardson:5} become necessary,
  since different from the case in $\R^n$, the result of applying the
  bilinear form $a(.,.)$ to $u^{(k)}$ in the first argument yields a
  linear form on $X$. In order to convert this to a vector in $X$, we
  have to apply the isomorphism induced by the \putindex{Riesz
    representation theorem}.
\end{intro}

\begin{Theorem}{richardson-convergence2}
  \label{theorem:richardson:2}
  Let the bilinear form $a(.,.)$ be bounded and elliptic on $X\times
  X$, namely, let there exist positive constants $\Lambda$ and $\lambda$ such
  that for all $u,v\in X$ there holds
  \begin{gather}
    \label{eq:richardson:6}
    a(u,v) \le \Lambda \norm{u} \norm{v},
    \qquad
    a(u,u) \ge \lambda \norm{u}^2.
  \end{gather}
  Then, Richardson's iteration converges for
  $\omega_k = \omega$ for any $\omega \in (0, 2\lambda/\Lambda^2)$.
\end{Theorem}

\begin{proof}
  We define the iteration operator $T$ as the solution operator of
  equation~\eqref{eq:richardson:5}, namely $T u^{(k)} := u^{(k+1)}$. We
  have to prove that $T$ is a contraction on $X$ under the assumptions
  of the theorem.

  For two arbitrary vectors $u^1, u^2 \in X$, let $w = u^1-u^2$ be
  their difference. Due to linearity, we have $T w = T u^1-T u^2$ and
  \begin{gather*}
    \scal(T w,v) = \scal(w,v) - \omega a(w,v) = \scal(w-\omega A w,v).
  \end{gather*}
  Using $v=Tw$ as a test function, we obtain
  \begin{align*}
    \norm{Tw}^2
    & = \scal(w-\omega A w,w-\omega A w) \\
    &= \norm{w}^2 - 2\omega a(w,w) + \omega^2 \norm{Aw}^2\\
    & \le \norm{w}^2 - 2\lambda\omega \norm{w}^2
    +  \Lambda^2 \omega^2\norm{w}^2\\
    & = \underbrace{\bigl(1-2\lambda\omega
      + \Lambda^2\omega^2\bigr)}_{=:\rho(\omega)} \norm{w}^2.
  \end{align*}
  The function $\rho(\omega)$ is a parabola open to the top, which
  at zero equals one and has a negative derivative. Thus, it is less
  than one for small positive valuers of $\omega$. The other
  point where $\rho(\omega) = 1$ is $\omega = 2\lambda/\Lambda^2$.
\end{proof}

\begin{remark}
  The condition on $\omega$ in Theorem~\ref{theorem:richardson:2} is
  more restrictive than in Theorem~\ref{theorem:richardson:1}, since
  $\lambda/\Lambda \le 1$. This is
  due to the fact, that in Theorem~\ref{theorem:richardson:1} we
  assume symmetry, and thus orthogonal diagonalizability of the matrix
  $\mat A$. With similar assumptions,
  Theorem~\ref{theorem:richardson:2} could be made sharper.
\end{remark}

\begin{remark}
  It is clear that the boundedness and ellipticity
  estimates~\eqref{eq:richardson:6} hold for any finite dimensional
  subspace $X_n\subset X$, and thus the convergence
  estimate~\eqref{eq:richardson:4} becomes independent of $n$.

  More interesting and also more common is the case where the bilinear form
  $a(.,.)$ is unbounded on $X$. While it is still bounded on each
  finite subspace $X_n$, this bound cannot be independent of $n$ if
  the sequence $\{X_n\}$ approximates $X$.
\end{remark}

\begin{Definition}{riesz-isomorphism}
  We define an operator $B:X\to X^*$ such that $Bu = b(u,.) :=
  \scal(u,.)$. By the Riesz representation theorem, there is a
  continuous inverse operator $B^{-1}: X^*\to X$, which is often
  called \define{Riesz isomorphism}.
\end{Definition}

\begin{Definition}{p-richardson-method}
  \label{definition:richardson:2}
  When we apply Richardson's method as in~\eqref{eq:richardson:5} on a
  computer, each step involves a multiplication with the matrix $\mat A$,
  but an inversion of the matrix $\mat B$, corresponding to the iteration
  \begin{gather*}
    \mat B \vec x^{(k+1)}
    = \mat B \vec x^{(k)}
    - \omega_k \bigl(\mat A \vec x^{(k)} - \vec b \bigr),
  \end{gather*}
  or equivalently,
  \begin{gather}
    \label{eq:richardson:7}
    \vec x^{(k+1)}
    = \vec x^{(k)}
    - \omega_k \mat B^{-1}\bigl(\mat A \vec x^{(k)} - \vec b \bigr).
  \end{gather}
\end{Definition}

\begin{remark}
  The iteration in~\eqref{eq:richardson:7} is commonly referred to as
  \define{preconditioned Richardson iteration} and $\mat B^{-1}$ as the
  \define{preconditioner}. Note that by introducing the iteration in
  its weak form~\eqref{eq:richardson:5}, the preconditioner arrives
  naturally and with necessity.

  The goal of this chapter is finding preconditioners $\mat B^{-1}$, or
  equivalently inner products $\scal(.,.)$, such that the bilinear
  form $a(.,.)$ is bounded and the condition number
  $\kappa = \Lambda/\lambda$ is small.

  In order to reduce (or increase) confusion, we will refer to the
  inner product that we search in order to bound the condition number
  as $b(.,.)$ instead of $\scal(.,.)$, this way separating the
  Hilbert space $X$ more clearly from the task of
  preconditioning. Thus, the operator $B$ and the matrix $\mat B$ will
  be associated with a bilinear form $b(.,.)$ and the final version of
  the preconditioned Richardson iteration is
  \begin{gather}
    \label{eq:richardson:10}
    b(u^{(k+1)},v) = b(u^{(k)},v)
    - \omega_k \bigl(a(u^{(k)},v) - f(v)\bigr), \qquad \forall v\in X,
  \end{gather}
  or in operator form
  \begin{gather}
    \label{eq:richardson:11}
    u^{(k+1)} = u^{(k)} - \omega_k B^{-1} (A u^{(k)} - f).
  \end{gather}
\end{remark}

\begin{remark}
  The space $X$ and is inner product does not appear anymore in this
  formulation, since the bilinear form $b(.,.)$ has replaced
  it. Thus, finding a preconditioner also amounds to changing the
  space in which we iterate. This is reflected by the following:
\end{remark}

\begin{corollary}
  Let the symmetric bilinear forms $a(.,.)$ and $b(.,.)$ in the
  Richardson iteration~\eqref{eq:richardson:10} be both bounded and
  positive definite on the
  same space $V$ and fulfill the
  \define{spectral equivalence} relation
  \begin{gather}
    \label{eq:richardson:12}
    \lambda b(u,u) \le a(u,u) \le \Lambda b(u,u), \quad \forall u\in V.
  \end{gather}
  Then, if $\omega_k \equiv \omega \in (0,2\Lambda)$, the iteration is
  a contraction on $V$. The optimal contraction number is $\rho$
  according to equation~\eqref{eq:richardson:4} for $\omega$ chosen as
  in~\eqref{eq:richardson:2}.
\end{corollary}

\begin{proof}
  This corollary is equivalent to Theorem~\ref{theorem:richardson:2}
  if the inner product $\scal(.,.)$ is replaced by the bilinear form
  $b(.,.)$.
\end{proof}

\begin{remark}
  Originally, the space $V$ was chosen as the domain of $A$ which
  essentially meant $V \subset H^2(\Omega)$, since we required $Av \in
  X$. An additional benefit of the preconditioned version is, that now
  $V \subset H^1(\Omega)$ is sufficient and at least here no
  regularity assumption is required.
\end{remark}

\begin{notation}
  \index{lambdaBA@$\lambda(B,A)$}
  \index{Lambdaba@$\Lambda(B,A)$}
  In order to distinguish different preconditioners, we will also us
  the notation $\lambda(B,A)$ and $\Lambda(B,A)$ to refer to the
  constants in the norm equivalence~\eqref{eq:richardson:12}.
\end{notation}

\begin{example}
  Let us take the example~\eqref{eq:itintro:1}.
  By the Poincaré-Friedrichs inequality, $a(.,.)$ is an inner product
  on $X$ and thus we can choose $\scal(.,.) = a(.,.)$. In
  particular, $\lambda = \Lambda = 1$ and the optimal choice is
  $\omega = 1$. Then, Richardson's iteration becomes
  \begin{gather*}
    a(u^{(k+1)},v) = a(u^{(k)},v)
    - \bigl(a(u^{(k)},v) - f(v)\bigr) =  f(v), \qquad \forall v\in X,
  \end{gather*}
  which converges in a single step, but we have to solve the original
  equation for $u$. Thus, either the inversion of the matrix $A_n$ is
  trivial on each finite dimensional subspace $X_n$, or the method is
  useless. With usual finite element bases, the latter is true.
\end{example}

\begin{example}
  In the other extreme, we would like to use the $\R^n$ or $L^2$
  inner product on $X_n$ or $X$, such that the Riesz isomorphism is
  easily computable. But then, the bilinear form $a(.,.)$ is unbounded
  on $X$. Thus, while for each finite $n$, the condition number
  $\kappa_n = \Lambda_n/\lambda_n$ exists, it converges to infinity if
  $n\to\infty$.
\end{example}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


\subsection{Open Delta Neighborhoods}
\noindent
An open delta neighborhood of a point $x_0$ is defined as the set
\begin{equation*}
	N\left(x_0, \delta\right) = \left\{x \in \mathbb{R}^n \mid \norm{x-x_0} < \delta\right\}
\end{equation*}

[INSERT IMAGE]

\noindent
This simply means all points less than a distance $\delta$ away from $x_0$.\\
For example, $N(\langle 1, 2\rangle, 7) = \left\{ (x,y) \mid \sqrt{(x-1)^2 + (y-2)^2}<7 \right\}$, which is a ball (filled-in circle) of radius 7 centered at $(1, 2)$.


    \filetitle{difflog}{First log-difference pseudofunction}{modellang/difflog}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
difflog(Expr)
difflog(Expr,K)
\end{verbatim}

\paragraph{Description}\label{description}

If the input argument \texttt{K} is not specified, this pseudofunction
expands to

\begin{verbatim}
(log(Expr)-log(Expr{-1}))
\end{verbatim}

If the input argument \texttt{K} is specified, it expands to

\begin{verbatim}
(log(Expr)-log(Expr{K}))
\end{verbatim}

The two derived expressions, \texttt{Expr\{-1\}} and \texttt{Expr\{K\}},
are based on \texttt{Expr}, and have all its time subscripts shifted by
--1 or by \texttt{K} periods, respectively.

\paragraph{Example}\label{example}

The following two lines of code

\begin{verbatim}
difflog(Z)
difflog(X{1}/Y{-1},-2)
\end{verbatim}

will expand to

\begin{verbatim}
(log(Z)-log(Z{-1}))
(log(X{1}/Y{-1})-log(X{-1}/Y{-3}))
\end{verbatim}


\subsection{Topological groups}\label{subsec:topological_groups}

\begin{definition}\label{def:topological_group}
  Let \( G \) be any \hyperref[def:group]{group} and let \( \mscrT \) be a topology on \( G \). The tuple \( (G, \cdot, \mscrT) \) is called a \term{topological group} if the group structure and topological structure agree, that is, the operations \( \cdot: X \times X \to X \) and \( (-)^{-1}: X \to X \) are continuous with respect to \( \mscrT \).

  See \fullref{rem:hausdorff_topological_groups} and \fullref{def:category_of_topological_groups} for more nuances.
\end{definition}

\begin{remark}\label{rem:hausdorff_topological_groups}
  It is conventional to require the topology in a topological group to be \( T_1 \) (see \fullref{def:separation_axioms}). We will not do this due to our goal of not assuming more than is necessary.

  Due to \fullref{thm:topological_group_t0_iff_t3.5}, it is immaterial whether we require the topology to be \( T_0 \) or \( T_{3.5} \) or anywhere in between. It is customary to call the space \enquote{Hausdorff} (although stronger separation axioms actually hold) and require \( T_1 \) to hold (since it is simple to state).

  We will explicitly mention when we want a topological group to be Hausdorff. This is usually, so when we speak of convergence.
\end{remark}

\begin{definition}\label{def:category_of_topological_groups}
  The category \( \cat{TopGrp} \) of topological groups is a subcategory of both \( \cat{Top} \) and \( \cat{Grp} \). Its morphisms are the \hyperref[def:global_continuity]{continuous} group \hyperref[thm:group_homomorphism_single_condition]{homomorphisms}.
\end{definition}

\begin{proposition}\label{thm:neighborhood_translations_in_topological_groups}
  Fix \( x, y \in G \) in a topological group \( G \). If \( U \) is a neighborhood of \( x \), then both \( V = yx^{-1} U \) and \( W = U x^{-1}y \) are neighborhoods of \( y \).
\end{proposition}
\begin{proof}
  Since the group operations are continuous, for fixed \( x \) and \( y \), the function \( f(z) \coloneqq xy^{-1}z \) is continuous.

  Note that \( U = f(V) \), hence \( V \) is the preimage of \( U \) under \( f \) and it follows from the continuity of \( f \) that \( V \) is open.

  Since \( x \in U \), \( yx^{-1}x = ye = y \in V \). Therefore, \( V \) is a neighborhood of \( y \).

  The proof that \( W \) is a neighborhood of \( y \) is analogous.
\end{proof}

\begin{corollary}\label{thm:origin_neighborhoods_in_topological_groups}
  In a topological group \( G \), every neighborhood is a translation of e neighborhood of the origin \( e \).
\end{corollary}

\begin{remark}\label{rem:origin_neighborhoods_in_topological_groups}
  \Fullref{thm:origin_neighborhoods_in_topological_groups} provides a lot of uniformity by allowing us to only consider neighborhoods of zero when working with topological groups.
\end{remark}

\begin{proposition}\label{thm:topological_group_t0_iff_t3.5}
  If a topological group is \( T_0 \), it is automatically \( T_{3.5} \).
\end{proposition}

\begin{proposition}\label{thm:topological_group_uniform_space}
  A Hausdorff topological group \( G \) can be made into a uniform space by the families of entourages
  \begin{balign*}
     & V^l_A \coloneqq \{ (x, y) \in G \times G \colon x^{-1} y \in A \}, \\
     & V^r_A \coloneqq \{ (x, y) \in G \times G \colon x y^{-1} \in A \},
  \end{balign*}
  where \( A \) is a \hyperref[def:neighborhood_set_types/symmetric]{symmetric} neighborhood of the origin \( e \).

  If \( G \) is abelian, the two families of entourages coincide.
\end{proposition}

\begin{proposition}\label{thm:limits_are_topological_group_homomorphisms}
  If \( \{ a_\alpha \}_{\alpha \in \mscrK} \) and \( \{ b_\alpha \}_{\alpha \in \mscrK} \) are \hyperref[def:topological_net]{nets} in a Hausdorff topological group \( X \) that converge to \( a \) and \( b \), correspondingly, then \( a_\alpha b_\alpha \to a b \).
\end{proposition}
\begin{proof}
  Special case of \fullref{thm:linearity_of_sequence_limits}.
\end{proof}


\sec{Higher order linear ODEs - linear algebra}
This section has more theory as compared to the other sections. However, these are some key concepts that must be known.\\
\subsection{Solutions}
In this section, we shall be considering equations of the following form.
\begin{defn}[Linear ODE]
	An ordinary differential equation of the form
	\begin{equation} \label{eq:lininhom}
		y^{(n)} + p_{n-1}(x)y^{(n-1)} + \cdots + p_1(x)y^{(1)} + p_0(x)y = r(x)
	\end{equation}
	is a \defin{linear ODE} of $n^{\text{th}}$ order.
\end{defn}
We shall be assuming that all the $p_j$s are continuous on an open interval $I \subset \mathbb{R}.$\\
Note very carefully that the coefficient of $y^{(n)}$ is assumed to be $1.$ (This could have been replaced with any nonzero constant.)\\
The ODE (\ref{eq:lininhom}) is said to be \defin{homogeneous} iff $r \equiv 0,$ that is, $r(x) = 0$ for all $x \in I.$\\
Given such a linear ODE, we have the \defin{associated homogeneous linear ODE} defined as
\begin{equation} \label{eq:linhom}
	y^{(n)} + p_{n-1}(x)y^{(n-1)} + \cdots + p_1(x)y^{(1)} + p_0(x)y = 0.
\end{equation}

Now, we make the following observation:

\begin{mdframed}[style=boxstyle, frametitle={}]
	If $y_g(x)$ is the \emph{general} solution of (\ref{eq:linhom}) and $y_p(x)$ is a \emph{particular} solution of (\ref{eq:lininhom}), then
	\[y_p(x) + y_g(x)\]
	is the general solution of (\ref{eq:lininhom}).
\end{mdframed}
(Compare the above with what you saw in MA 106 regarding the null-space of $A$ and a particular solution of $A\mathbf{x} = \mathbf{b}$.)

\subsection{Dimensions}
Recall the vector space of functions from $\mathbb{R}$ to $\mathbb{R}$. Let $V$ denote the set of functions which are solutions of (\ref{eq:linhom}). It can be verified that $V$ is a vector space with the usual addition and scalar multiplication. (We use the fact that the ODE is homogeneous.)
\begin{thm}
	\[\dim V = n.\]
	To elaborate, the dimension of the solution space of
	\[y^{(n)} + p_{n-1}(x)y^{(n-1)} + \cdots + p_0(x)y = 0\]
	is equal to $n.$
\end{thm}

\subsection{Linear independence and the Wronskian}
We recall the following from Linear Algebra.
\begin{defn}[Linear Independence]
	Let $f_1, \ldots, f_n:I \to \mathbb{R}$ be functions defined on some open interval $I.$ The functions are said to be \defin{linearly dependent} if there exist real numbers $a_1, \ldots, a_n$ \textbf{not all zero} such that
	\[a_1f_1(x) + \cdots + a_nf_n(x) = 0 \quad \forall x \in I.\]
	The functions are said to be \defin{linearly independent} if they are not linearly dependent.
\end{defn}
\begin{mdframed}[style=boxstyle, frametitle={A rephrasing}]
	In other words, the functions are linearly independent if
	\[a_1f_1(x) + \cdots + a_nf_n(x) = 0 \quad \forall x \in I\]
	implies $a_1 = \cdots = a_n = 0.$\\
	In yet another words, their linear combination being identically zero is possible if and only if every scalar is $0.$
\end{mdframed}
\begin{defn}[Wronskian]
	Let $f_1, \ldots, f_n:I \to \mathbb{R}$ be sufficiently differentiable functions defined on some open interval $I.$ Their \defin{Wronskian} is another function defined on $I$ as:
	\[W(f_1, \ldots, f_n)(x) := \det\begin{bmatrix}
		f_1(x) & f_2(x) & \ldots & f_n(x)\\
		f_1'(x) & f_2'(x) & \ldots & f_n'(x)\\
		\vdots & \vdots & \ddots & \vdots\\
		f_1^{(n-1)}(x) & f_2^{(n-1)}(x) & \ldots & f_n^{(n-1)}(x)\\
	\end{bmatrix}.\]
\end{defn}
\exercise{%
\begin{enumerate}[leftmargin=*]
	\item Show that if $f_1, \ldots, f_n$ are linearly dependent, then their Wronskian is identically zero. This can be written as $W(f_1, \ldots, f_n) \equiv 0.$
	\item Show that the converse is not true.
\end{enumerate}
}
We now state a case when the converse \emph{\textbf{is}} true.
\begin{thm}
	If $y_1(x), \ldots, y_n(x)$ are solutions of a linear homogeneous ODE as (\ref{eq:linhom}), then they are linearly dependent if and only if $W(y_1, \ldots, y_n) \equiv 0.$
\end{thm}
\begin{mdframed}[style=boxstyle, frametitle={A particular application}]
	Suppose $y_1$ and $y_2$ are solutions of
	\[y'' + P(x)y' + Q(x)y = 0\]
	over an open interval $I \subset \mathbb{R}.$ Let $a \in I$ be such that
	\[y_1(a) = 0, y_1'(a) = 1,\quad y_2(a) = 1, y_2'(a) = 0.\]
	Then, any other solution of the ODE is given by
	\[c_1y_1(x) + c_2y_2(x).\]
\end{mdframed}
The hypothesis tells us that $y_1$ and $y_2$ are two linearly independent solutions of the ODE. As the dimension of the solution space is $2,$ the functions must form a basis.
\begin{mdframed}[style=boxstyle, frametitle={A result}]
	Suppose $y_1$ and $y_2$ are solutions of
	\[y'' + P(x)y' + Q(x)y = 0\]
	over an open interval $I \subset \mathbb{R}.$ Let $a \in I$ be such that
	\[y_1(a) = y_2(a),\quad y_1'(a) =y_2'(a).\]
	Then, $y_1 = y_2.$
\end{mdframed}
This is to say that if two functions satisfy an ODE and have the same initial conditions, then they are identically equal.
\exercise{%
Show that the following sets of functions are linearly independent on $\mathbb{R}$ (unless otherwise mentioned):
\begin{enumerate}[leftmargin=*]
	\item $\{1, x, \ldots, x^n\}.$
	\item $\{e^{m_1x}, \ldots, e^{m_nx}\}$ where $m_1, \ldots, m_n$ are distinct real numbers.
	\item $\{e^{mx}, xe^{mx}, \ldots, x^ne^{mx}\}.$
	\item $\{\sin x, \sin 2x, \ldots, \sin nx\}.$ (Wronskian could get quite messy. Try integration. Recall inner products.)
	\item $\{x^m, x^m(\ln x), \ldots, x^m(\ln x)^n\}.$ Show that this is linearly independent on $(0, \infty).$
\end{enumerate}
}

\newpage

\subsection{Abel-Liouville Formula}
\begin{mdframed}[style=boxstyle, frametitle={The formula}]
	Suppose $y_1, \ldots, y_n$ are solutions of
	\[y^{(n)} + P_1(x)y^{(n-1)} + \cdots + P_n(x)y = 0\]
	over an open interval $I \subset \mathbb{R}.$\\
	Let $W$ denote their Wronskian.	Then,
	\[\dfrac{dW}{dx} = -P_1(x)W.\]
	Hence, we have
	\[W(x) = W(x_0)\exp\left(-\int_{x_0}^{x} p(t) dt\right)\]
\end{mdframed}
(Note that here, $P_1$ is the coefficient of $y^{(n-1)}$ and not $y'$.)

\begin{cor} \label{cor:wronskian}
	The above formula shows that either $W \equiv 0$ or that the Wronskian \textbf{never} vanishes. (In fact, it never changes sign.)
\end{cor}

\begin{mdframed}[style=boxstyle, frametitle={An application}]
	Suppose $y_1$ is a solution of
	\[y'' + P(x)y' + Q(x)y = 0.\]
	Then, a second \emph{linearly independent} solution is given by
	\[y_2(x) = y_1(x)\int \dfrac{1}{(y_1(x))^2}\exp\left(-\int P(x) dx\right) dx.\]
\end{mdframed}


\chapter{Tetrahedral Quality Metrics}

All the metrics in this section are defined on a tetrahedral element with vertices
shown in Figure~\ref{f:tet}. Furthermore, we define the following edge vectors for
convenience
\begin{equation*}
\begin{array}{lcl}
\vec L_0 &=& \vec P_1 - \vec P_0\\
\vec L_1 &=& \vec P_2 - \vec P_1\\
\vec L_2 &=& \vec P_0 - \vec P_2
\end{array}\rule{10em}{0pt}
\begin{array}{lcl}
\vec L_3 &=& \vec P_3 - \vec P_0\\
\vec L_4 &=& \vec P_3 - \vec P_1\\
\vec L_5 &=& \vec P_3 - \vec P_2
\end{array}.
\end{equation*}

\begin{figure}[htb]
  \begin{center}
    \includegraphics[height=2.0in]{tet}
    \caption{Vertices of a tetrahedron.%
                                                                  \label{f:tet}}
  \end{center}
\end{figure}

The tetrahedron edge lengths are denoted as follows:
\[
L_0 = \normvec{L_0}\quad
L_1 = \normvec{L_1}\quad
L_2 = \normvec{L_2}\quad
L_3 = \normvec{L_3}\quad
L_4 = \normvec{L_4}\quad
L_5 = \normvec{L_5}
\]
and the largest and smallest edge lengths are, respectively,
\[
L_{\min} = \min\left(L_0, L_1, L_2, L_3, L_4, L_5\right)
  \rule{2em}{0pt}
L_{\max} = \max\left(L_0, L_1, L_2, L_3, L_4, L_5\right)
\]

The volume can then be defined in terms of the edge vectors as
\begin{equation*}
V = \frac{\left(\vec L_2\times\vec L_0\right)\cdot\vec L_3 }{6}.
\end{equation*}

In addition, we will respectively denote $R$ and $r$ the circumradius
and the inradius of the tetrahedron, \emph{i.e.}, respectively, the radii
of the circumscribed and inscribed spheres of this tetrahedron.
Note that the inradius is
\[
 r = \frac { 3V } { A }
\]
where $A$ is the  surface area of the tetrahedron:
\[
A = \frac{1}{2} \left(
      \normvec{L_2 \times \vec L_0} +
      \normvec{L_3 \times \vec L_0} +
      \normvec{L_4 \times \vec L_1} +
      \normvec{L_3 \times \vec L_2}  \right),
\]
and that the the circumradius is
\[
 R = \frac {\Big\lVert
   \normvec{L_3}^2 \left( \vec L_2 \times \vec L_0 \right) +
   \normvec{L_2}^2 \left( \vec L_3 \times \vec L_0 \right) +
   \normvec{L_0}^2 \left( \vec L_3 \times \vec L_2 \right)
   \Big\rVert}{12 V }.
\]

Sometimes, we will to refer to the edge vectors indexed by their endpoints:
\begin{equation*}
\begin{array}{lcl}
\vec L_{01} &=& \vec L_0\\
\vec L_{12} &=& \vec L_1\\
\vec L_{20} &=& \vec L_2
\end{array}\rule{10em}{0pt}
\begin{array}{lcl}
\vec L_{03} &=& \vec L_3\\
\vec L_{13} &=& \vec L_4\\
\vec L_{23} &=& \vec L_5
\end{array}
\end{equation*}

% -------------------Metric Table-------------------
\newcommand{\tetmetrictable}[8]{%
  \begin{center}
  \begin{tabular}{ll}
    \multicolumn{2}{r}{\textbf{\sffamily\Large tetrahedral #1}}\\\hline
    Dimension:                            & #2\\
    Acceptable Range:                     & #3\\
    Normal Range:                         & #4\\
    Full Range:                           & #5\\
    $q$ for unit equilateral tetrahedron: & #6\\
    Reference:                            & #7\\
    \verd\ function:       & \texttt{#8}\\ \hline
  \end{tabular}
  \end{center}
}
\clearpage
\newpage \input{TetEdgeRatio}
\newpage \input{TetAspectBeta}
\newpage \input{TetAspectDelta}
\newpage \input{TetAspectFrobenius}
\newpage \input{TetAspectGamma}
\newpage \input{TetAspectRatio}
\newpage \input{TetCollapseRatio}
\newpage \input{TetCondition}
\newpage \input{TetDistortion}
\newpage \input{TetJacobian}
\newpage \input{TetMinimumAngle}
\newpage \input{TetRadiusRatio}
\newpage \input{TetRelativeSizeSquared}
\newpage \input{TetScaledJacobian}
\newpage \input{TetShape}
\newpage \input{TetShapeAndSize}
\newpage \input{TetVolume}