\documentclass[letter]{article}
\renewcommand{\baselinestretch}{1.25}

\usepackage[margin=1in]{geometry}
\usepackage{physics}
\usepackage{amsmath}
\usepackage{graphicx}
%\usepackage[language=Python]{listings}
\usepackage{pythonhighlight}

\newcommand{\CPS}{cyber-physical system}
\newcommand{\DT}{discrete-time}

\allowdisplaybreaks

%opening
\title{MECH 6327 - Homework 1}
\author{Jonas Wagner}
\date{2021, February 3}

\begin{document}

\maketitle

\section{Optimization Problem Formulation}
Find and research an example (ideally from your own research experience/interests) of an optimization problem in the real world. Write a short narrative of around 300 words to describe the
optimization variables, objective function(s), constraint function(s), and formulate the problem as
a mathematical optimization problem. Briefly discuss your knowledge of how computationally easy
or difficult the problem is, the number of variables and constraints in typical problem instances,
available algorithms or software for solving the problem, etc. (need not be formal, this is just to
assess and get you to think about the current state of your knowledge about the problem).\\

\noindent
\textbf{Solution:}\\
When dealing with ensuring the security of a \CPS an important component is the ability to detect if an attacker is occurring while also minimizing the number of false positives. Often what is done to detect if any sensors have been compromised is to compare the predicted state estimate with the sensor reading. In this case an optimization problem can be conducted to develop a detector that maximizes the detection rate for a given false positive value. Additional constraints on the detector can also be added, such as restricting system state estimates or adding a computational or refresh rate restriction. Additionally, an entirely different cost function could be added to find an optimal solution to minimize or maximize properties. Untimely in this problem more constraints are necessary to find the optimal detector. \cite{BELABBAS2019387}\\

\newpage
\section{Math Review}

\subsection{Cauchy-Schwarz Inequality Proof}
\textbf{Problem:}
Prove the Cauchy-Schwarz inequality, which states that $\forall x,y\in \real^n$, there holds
\begin{displaymath}
	\abs{\ip{x}{y}} \leq \norm{x}\norm{y},
\end{displaymath}
where $\norm{\cdot} = \sqrt{\ip{\cdot}{\cdot}}$.\\

\noindent
\textbf{Solution:}
Let $\norm{x}=\norm{y}=1$.\\
Consider
\begin{align*}
	\norm{x-y}^2 	&= \qty(\sqrt{\braket{x-y}})^2 = \braket{x-y}\\
	\braket{x-y}	&= \ip{x}{x-y} + \ip{-y}{x-y}\\
					&= \ip{x}{x} + \ip{x}{-y}  + \ip{-y}{x} + \ip{-y}{-y}\\
					&= \norm{x}^2 - \ip{x}{y}  - \ip{y}{x} + \norm{y}^2\\
	\norm{x-y}^2	&= \norm{x}^2 - 2\ip{x}{y}  + \norm{y}^2\\
	2\ip{x}{y}		&= \norm{x}^2 + \norm{y}^2 - \norm{x-y}^2
\intertext{Now taking the assumption of unit vectors from before and substituting,}
	2\ip{x}{y}		&= 1^2 + 1^2 - \norm{x-y}^2\\
	2\ip{x}{y}		&= 2 - \norm{x-y}^2\\
	\ip{x}{y}		&= 1 - \cfrac{\norm{x-y}^2}{2}\\
\intertext{Since $\norm{x}\norm{y} = 1$,}
	\ip{x}{y}		&= \norm{x}\norm{y} - \cfrac{\norm{x-y}^2}{2}\\
\intertext{Thus, for all unit vectors,}
	\ip{x}{y}		&\leq \norm{x}\norm{y}
\end{align*}

This demonstraction can be expanded to include any vectors becouse all vectors can be decomposed into a unit vector and a scaler magnitude:
$$\vb{z} = \frac{\vu{e}_z}{\norm{z}}$$
and both the inner product and norms are homogenous with respect to scaler quantities.

\newpage
\subsection{Norm Duality}
\textbf{Problem:}
Prove the dual norm relationship for the 1-, 2-, and $\infty$-norms.

%\noindent
%\textbf{Solution:}
\subsubsection{1- and $\infty$-norm}

\begin{align*}
	\norm{z}_{1*}	&= \max{z^T x \ | \ \norm{x}_1 \leq 1}\\
	\max{z^T x} &= \abs{\ip{z}{x}} \leq \norm{z}_1 \norm{x}_1\\
				&= \sum_{i=1}^n z_i x_i \leq \qty(\sum_{i=1}^n \abs{z_i})\qty(1)\\
				&= \cfrac{z^T x}{\norm{z}_1} \leq 1
\intertext{Since}
	\cfrac{z^T x}{\norm{z}_1} &= 1
\intertext{occurs when $x$ is chosen to isolate the maximum value, i.e. $z = \mqty[5\\0\\0], \ x = \mqty[1\\0\\0]$}
	\max{z^T x} &= \max{z_i} = \norm{z}_\infty
\end{align*}

\subsubsection{$\infty$- and 1-norm}
\begin{align*}
	\norm{z}_{\infty*}	&= \max{z^T x \ | \ \norm{x}_\infty \leq 1}\\
	\max{z^T x} &= \abs{\ip{z}{x}} \leq \norm{z}_\infty \norm{x}_\infty\\
	&= \sum_{i=1}^n z_i x_i \leq \qty(\max_i z_i)\qty(1)\\
	&= \sum_{i=1}^n \cfrac{z_i x_i}{\norm{z}_\infty} \leq 1
\intertext{Since}
	\cfrac{z^T x}{\norm{z}_\infty} &= 1
\intertext{occurs when $x$ maximizes the sum, i.e. $z = \mqty[1\\2\\3], \ x = \frac{1}{\sqrt{14}}\mqty[1\\2\\3], z^T x = 5$}
	\max{z^T x} &= \sum_{i=1}^n z_i = \norm{z}_1
\end{align*}

\newpage
\subsubsection{2- and 2-norm}
\begin{align*}
	\norm{z}_{2*} &= \max{z^T x \ | \ \norm{x}_2 \leq 1}\\
	\max z^T x 	&= \ip{z}{x} \leq \norm{z}_2 \norm{x}_2\\
				&= \sum_{i=1}^n z_i x_i \leq \qty(\sqrt{\sum_{i=0}^n z_i^2}) \qty(1)\\
				&=\sum_{i=1}^n \cfrac{ z_i x_i}{\sqrt{\sum_{i=0}^n z_i^2}} \leq 1\\
\intertext{Since}
	\cfrac{z^T x}{\norm{z}_2} &= 1
\intertext{occurs when all elements of $x = \cfrac{1}{\norm{z}_2}$, thus}
	\max z^T x &= \sqrt{\sum_{i=1}^n z_i^2} = \norm{z}_2
\end{align*}

\newpage
\subsection{Ploting the Unit Norm Balls}

\textbf{Problem:}
Plot the unit norm balls $\{x\in \real^2 \ | \ \norm{x}_p \leq 1\}$ for $p = 1,2,\infty$.\\

\noindent
\textbf{Solution:}\\
\begin{figure}[h]
	\centering
	\includegraphics[width=\linewidth]{fig/pblm2_3}
	\caption{Unit Norm Ball Plots}
	\label{fig:pblm23}
\end{figure}

\begin{python}
import numpy as np
import matplotlib.plot as plt

x = np.linspace(-1,1)
y1 = 1 - abs(x)
y2 = np.sqrt(1 - x**2)
y3 = 1

fig,axs = plt.subplots(1,3,sharex=True,figsize=(10,10))

axs[0].plot([x,x],[y1,-y1])
axs[0].set_box_aspect(1)
axs[0].set_title('p=1')

axs[1].plot([x,x],[y2,-y2])
axs[1].set_box_aspect(1)
axs[1].set_title('p=2')

axs[2].plot([x,x],[y3,-y3])
axs[2].set_box_aspect(1)
axs[2].set_title('p=infinity')

\end{python}

\newpage
\subsection{Eigenvalues Proof 1}
\textbf{Problem:}
Show that the eigenvalues of $A \in \mathbf{S}^n$ are real.\\

\noindent
\textbf{Solution:}
Every eigen-value, $\lambda$, of matrix, $A \in \mathbf{S}^{n \cross n}$, must satisfy the following:
\begin{displaymath}
	A x = \lambda x, \ \forall x \in \real^n
\end{displaymath}

The following must also be true:
\begin{align*}
	x^* A x &= x^* \lambda x\\
	\qty(x^* A x)^* &= \qty(x^* \lambda x)^*\\
	x^* A^* x &= x^* \lambda^* x\\
\end{align*}

Since, by definition, $A = A^*$,
\begin{align*}
	x^* A x = x^* \lambda x &= x^* \lambda^* x = x^* A^* x\\
	\lambda &= \lambda^*
\end{align*}

This means $\lambda$ must contain no imaginary components and therefore $\lambda \in \real$.

\newpage
\subsection{Eigenvalues Proof 2}
\textbf{Problem:}
Show that for $A \in \mathbf{S}^n$,
$$A \succeq 0 \iff \lambda_i\{A\} \geq 0 ,\ \forall i = 1, \dots, n$$\\

\noindent
\textbf{Solution:}
Every eigen-value, $\lambda \in \real$, of matrix, $A \in \mathbf{S}^{n \cross n}$, must satisfy the following:
\begin{displaymath}
	A x = \lambda x, \ \forall x \in \real^n
\end{displaymath}

By definition, a semi-positive definite matrix must satisfy the following:
$$x^T A x \geq 0, \ \forall x \in \real^n$$.

The following must also be true:
\begin{align*}
	x^T A x &\geq 0\\
	x^T \qty(\lambda x) &\geq 0
	\intertext{Thus,}
	\lambda x^T x  = x^T A x &\geq 0\\
\end{align*}

Since $\lambda x^T x \geq 0 \iff \lambda \geq 0$, the following is also true:
$$A \succeq 0 \iff \lambda \geq 0$$.

\newpage
\subsection{Optimal Control Problem Derivation}
\textbf{Problem:}
Derive the solution to the finite horizon open-loop optimal control problem:
\begin{displaymath}
	\text{minimize} \ \sum_{t=0}^{N-1} \qty(\norm{z_t}_2^2 + \norm{u_t}_2^2) + \norm{z_N}_2^2
\end{displaymath}
where $z_{t+1} = A z_t + B u_t$ with given $z_0$. Take the optimization variables to be $z_t \in \real ^n$ for $t = 1,\dots,N$ and $u_t \in \real^m$ for $t = 0,\dots,N-1$.\\

\noindent
\textbf{Solution:}\\
Define the following vectors:
\begin{align*}
	\vb{z} = \mqty[z_1^T\\ \vdots \\ z_N^T] \hspace{1in} \vb{u} = \mqty[u_0^T\\ \vdots \\ u_{N-1}^T]\\
\end{align*}

$\vb{z}$ can then be redefined in terms of $\vb{u}$ and $z_0$:
\begin{align*}
\intertext{Since}
	z_{t+1} &= A z_{t} + B u_{t}\\
	z_{1} 	&= A z_{0} + B u_{0}\\
	z_{2} 	&= A z_{1} + B u_{1}\\
			&= A \qty(A z_{0} + B u_{0}) + B u{1}\\
			&= A^2 z_0 + AB u_0 + B u_1\\
	z_{3}	&= A^3 z_0 + A^2 B u_0 + A B u_1 + B u_2\\
			& \ \ \vdots\\
	z_{N}	&= A z_{N-1} + B u_{N-1}\\
			&= A^n z_0 + A^{n-1} B u_0 + \dots + A B u_{n-1} + B u_n\\
\intertext{Additonally, this can be generalized as:}
	z_{t}	&= A^{t} z_0 + \sum_{i=0}^{t-1} A^{t-i} B \vb{u}_{i}\\
\intertext{The entire sum can be vectorized as follows:}
	\vb{z}	&= \mqty[\mqty{A \\ A^2 \\ \vdots \\ A^N}
					& \mqty{|\\|\\|\\|}
					& \mqty{B 	& 0 & \dots & 0\\
							AB 	& B & \dots & 0\\
							\vdots & \ddots &\ddots &\vdots\\
							A^{n-1}B &\dots &AB &B}] \mqty[z_0\\ \_\_ \\ \vb{u}]\\
			&= [A_{m} | B_{m}] \mqty[z_0\\ \_\_ \\ \vb{u}]\\
			&= A_m z_0 + B_m \vb{u} \\
			&= A_p \vb{u}_p
\end{align*}

This can then be substituted into the minimization funtion:
\begin{align*}
	\sum_{t=0}^{N-1} \qty(\norm{z_t}_2^2 + \norm{u_t}_2^2) + \norm{z_N}_2^2
	&= \sum_{t=0}^{N-1} \qty(\norm{\qty(A_{p,t} \vb{u}_{p,t})^2}_2)^2 + \norm{u_t}_2^2) + \sum_{t=0}^{N-1} \frac{1}{N} \norm{z_N}_2^2\\
	&= \sum_{t=0}^{N-1} \qty( \qty(\sqrt{\sum_{i=1}^{n} \qty(A_{p,t} \vb{u}_{p,t})})^2 + \qty(\sqrt{\sum_{i=1}^{n} u_{i}^2})^2 + \frac{1}{N} \qty(\sqrt{\sum_{i=1}^{n} z_{N,i}^2})^2)\\
	&= \sum_{t=0}^{N-1} \qty(\sum_{i=1}^{n} \qty(A_{p,t} \vb{u}_{p,t})^2 + \sum_{i=1}^{n} u_{i}^2  + \frac{1}{N} \sum_{i=1}^{n} z_{N,i}^2)\\
	&= \sum_{t=0}^{N-1} \sum_{i=1}^{n} \qty( \qty(A_{p,t} \vb{u}_{p,t})^2 + u_{i}^2 + \frac{1}{N} z_{N,i}^2)\\
	&= \sum_{t=0}^{N-1} \sum_{i=1}^{n} \qty( \qty(A_{p,t} \vb{u}_{p,t})^2 + u_{i}^2 + \frac{1}{N} z_{N,i}^2)\\
\intertext{From the definition of the 2-norm for vectors and the F- norm for matrices, the following can be found:}
	&= \norm{A_p\vb{u}_p + \vb{u} + \frac{1}{N} z_N}_F^2\\
\intertext{This can then be expanded into the follwoing matrix equivelent:}
	&= \norm{A_m z_0 + B_m\vb{u} + \vb{u} + \frac{1}{N} z_N}_F^2\\
	&= \norm{A_m z_0 + \qty(B_m + I) \vb{u} + \frac{1}{N} z_N }_F^2
\end{align*}

Returning to the matrix definitions
\begin{align*}
	A_m z_0 + \qty(B_m + I) \vb{u} + \frac{1}{N} z_N
	&= \mqty[\mqty{A \\ A^2 \\ \vdots \\ A^N}
			& \mqty{|\\|\\|\\|}
			& \mqty{B 	& 0 & \dots & 0\\
				AB 	& B & \dots & 0\\
				\vdots & \ddots &\ddots &\vdots\\
				A^{n-1}B &\dots &AB &B}]
		\mqty[z_0\\ \_\_ \\ \vb{u}] + \vb{u} + \frac{1}{N} z_N\\
	&= A_m z_0 + B_m \vb{u} + \vb{u} + \frac{1}{N} z_N\\
	&= A_m z_0 + \qty(B_m + I) \vb{u} + \frac{1}{N} z_N
\end{align*}

The minimization function can then be written as:
\begin{align*}
	\text{minimize} \ \norm{A_m z_0 + \qty(B_m + I) \vb{u} + \frac{1}{N} z_N I}_F^2
\end{align*}

which can be achieved by setting the gradient to be zero and finding the minimum solution:

\begin{align*}
	0
	&= \grad{\norm{A_m z_0 + \qty(B_m + I) \vb{u} + \frac{z_N}{N}  I}_F^2}\\
	&= \grad{\qty(\sqrt{(A_m z_0)^T(A_m z_0) + \qty(\qty(B_m + I) \vb{u})^T \qty(\qty(B_m + I) \vb{u}) + \qty(\frac{z_N}{N})^2 I})^2}\\
	&= \grad{\qty(z_0^T A_m^T A_m z_0 + \vb{u}^T\qty(B_m + I)^T\qty(B_m + I) \vb{u} + \frac{z_N^2}{N^2} I)}\\
	&= 2 (B_m + I) \vb{u}\\
	\vb{u} &= 0
\end{align*}

This result states that the result that minimizes the objective function, since $Z_n$ doesn't have an objective value, is to have $u = 0 \ \forall t \geq 0$.

Another verification can be done alternatively by defining the new vector, $$\vb{x} = \mqty[z_0\\ --\\z_N\\ --\\ \vb{u}],$$ and similarly minimizing:

\begin{align*}
		A_x \vb{x}
		&= \mqty[\mqty{A \\ A^2 \\ \vdots \\ A^N}
				& \mqty{|\\|\\|\\|}
				& \mqty{\frac{1}{N} \\ \frac{1}{N} \\ \vdots \\ \frac{1}{N}}
				& \mqty{|\\|\\|\\|}
				& \mqty{B + 1 	& 0 & \dots & 0\\
						AB 	& B + 1 & \dots & 0\\
						\vdots & \ddots &\ddots &\vdots\\
						A^{n-1}B &\dots &AB &B + 1}]
			\mqty[z_0\\ --\\z_N\\ --\\ \vb{u}]\\
\end{align*}

The minimization function can then be written as:
\begin{align*}
	\text{minimize} \ \norm{A_x \vb{x}}_F^2
\end{align*}

which can be achieved by setting the gradient to be zero and finding the minimum solution:

\begin{align*}
	\grad{\norm{A_x \vb{x}}_F^2} = 0
	&= \grad{\qty(\sqrt{\vb{x}^T A_x^T A_x \vb{x}})^2}\\
	&= \grad{\ \vb{x}^T A_x^T A_x \vb{x}}\\
	&= 2 \vb{x} A_x\\
	&= 2 \vb{x} A_x \qty(\frac{1}{2}) A_x^{-1}\\
	\vb{x} &= 0
\end{align*}
The minimum value for this case is actually found to be the trivial case of all variables set to zero, including $z_0$ and $z_N$ if they were variables. This would indicate more restrictions are needed for a non-trivial solution.

\newpage
\bibliographystyle{unsrt}
\bibliography{mybib.bib}

\end{document}


\documentclass{scrartcl}
\usepackage[a4paper,left=1in,right=1in,top=1.2in,bottom=1in]{geometry}
\usepackage{siunitx}
\usepackage{graphicx}
\setkomafont{disposition}{\normalfont\bfseries}
\usepackage{color}
%title
\title{Exercise 05:\\Operating point of a spiking neuron}
\subtitle{Theoretical Neuroscience I}
\author{Maria del Cerro \and Johannes G\"atjen \and Lorena Morton}

%use these for structure/overview
\newcommand\Question{%
  \textbf{Question:}%
}
\newcommand\Answer{%
  \textbf{Answer:}%
}

\begin{document}
\maketitle

In this exercise we simulate a leaky integrate-and-fire neuron with synaptic inputs. Additionally we simulate an identical neuron without a firing mechanism  to determine what the average membrane potential of our neuron would be. Figure \ref{memv} shows the membrane voltage over time for the spiking and the non-spiking neuron with one excitatory and one inhibitory presynaptic neuron. Because the membrane potential never reaches the threshold potential our neuron does not spike and the membrane potential is identical between the spiking and the non-spiking neuron. Only when we increase the excitatory synaptic activation as in Figure \ref{memv_high} do we see a difference between the two neurons.

Next we vary the number of excitatory and inhibitory inputs and observe the resulting output firing rate $\nu_\mathrm{spk}$, as well as the coefficient of variation $c_v$ of the inter-spike interval lengths and the corresponding average membrane potential of the non-spiking neuron $\langle V_\mathrm{ns}\rangle $. The results are summed up in Table \ref{rates}. When we fix the number of inhibitory inputs to zero and only change the number of excitatory inputs, $\langle V_\mathrm{ns}\rangle$ as well as $\nu_\mathrm{spk}$ rise with increasing $N_\mathrm{ex}$, while $c_v$ falls (i.e.\ more regular firing with higher $\langle V_\mathrm{ns}\rangle$). With $N_\mathrm{ex}$ fixed, $c_v$ also falls with rising $\langle V_\mathrm{ns}\rangle$ and $\nu_\mathrm{spk}$, but the differences are smaller than in the first case (less than $0.01$ difference in $c_v$ between 10.3\si{Hz} and 28.7\si{Hz}). Now a higher $N_\mathrm{in}$ produces a lower $\nu_\mathrm{spk}$.

The coefficient of variation is a measure of how regularly a neuron fires. As a rough rule of thumb, one can say, that the higher $\langle V_\mathrm{ns}\rangle$ is, the lower $c_v$ is. This is most clear, when comparing the firing behavior of the neuron for values of $\langle V_\mathrm{ns}\rangle$ a few \si{mV} above the threshold potential of the neuron with the firing behavior when $\langle V_\mathrm{ns}\rangle$ is a few \si{mV} below the threshold potential. In the former case, the ``standard'' behavior for the membrane potential is to rise quickly and reach the threshold potential, where it gets reset. Only when by chance a few more inhibitory than excitatory spikes occur, does the membrane potential not reach the threshold. In the latter case the ``standard'' behavior for the neuron is to maintain a membrane potential below the firing threshold, and it only fires, when by chance the number of excitatory spikes outnumbers the inhibitory spikes by enough. In the latter case spikes are irregular, while in the former case ``non-spikes'' are irregular.

\begin{figure}
\centering
\includegraphics[trim = {2.3cm 0 1cm 0.6cm}, width=0.6\textwidth, clip]{../pics/memv}
\caption{The membrane potential of a LIF neuron with synaptic inputs in blue compared with a non-spiking neuron shown with dashed red. The number of excitatory and inhibitory presynaptic neurons $N_\mathrm{ex}$ and $N_\mathrm{in}$ are both set to one, with the spiking rates $\nu_\mathrm{ex} = \nu_\mathrm{in} = 20\si{Hz}$. Whenever a presynaptic spike occurs the membrane potential increases or decreases a bit, depending on if the presynaptic spike was in the excitatory or the inhibitory neuron, before it relaxes back to the resting potential. Because the threshold potential is never reached the neuron never fires and there is no difference between the spiking and the non-spiking neuron.}
\label{memv}
\end{figure}

\begin{figure}
\centering
\includegraphics[trim = {2.3cm 0 1cm 0.6cm}, width=0.6\textwidth, clip]{../pics/memv_high_}
\caption{The same setup as in Figure \ref{memv}, but with $N_\mathrm{ex} = 30$. Multiple excitatory spikes in a short amount of time now push the membrane potential above the threshold potential and the spiking neuron fires, whereas the membrane potential of the non-spiking neuron continues to rise. If no spike occurs for some time the two membrane potentials become (almost) equal again.}
\label{memv_high}
\end{figure}

\begin{table}
\centering
\begin{tabular}{c c c c c}
$N_\mathrm{ex}$ & $N_\mathrm{in}$ & $\nu_\mathrm{spk} [\si{\hertz}]$ &$\langle V_\mathrm{ns}\rangle [\si{mV}]$ & $c_v$ \\ \hline \hline
30 & 0 & 10.53 & -57.35 & 0.86\\
40 & 0 & 30.27 & -55.17 & 0.70\\
56 & 0 & 69.13 & -51.98 & 0.53\\ \hline
100 & 30 & 10.33 & -61.33& 0.953\\
100 & 22 & 28.7 & -58.62& 0.946\\
100 & 13 & 70 & -54.55& 0.833\\
\end{tabular}
\caption{Number of excitatory presynaptic neurons $N_\mathrm{ex}$, Number of inhibitory presynaptic neurons $N_\mathrm{in}$, output spiking rate $\nu_\mathrm{spk}$, average non-spiking membrane potential $\langle V_\mathrm{ns}\rangle$ and coefficient of variation of the inter-spike interval lengths $c_v$. In the top part $N_\mathrm{in}$ was fixed to zero and $N_\mathrm{ex}$ was varied, in the bottom part $N_\mathrm{ex}$ was fixed to 100 and $N_\mathrm{in}$ was varied.}
\label{rates}
\end{table}

\subsection*{Operating point}

To determine the operating point of the neuron, we fix $N_\mathrm{ex}=100$ and vary $N_\mathrm{in}$ to find the maximum value of $c_v$. Figure \ref{cv_aveV} shows a plot of $c_v$ as a function of $\langle V_\mathrm{ns}\rangle$. $c_v$ decreases linearly for values of $\langle V_\mathrm{ns}\rangle > -58\si{mV}$ but for smaller values of $\langle V_\mathrm{ns}\rangle$ the data does not show a clear relation, as the values for $c_v$ fluctuate strongly. Nevertheless, $c_v$ appears to fall with smaller values of $\langle V_\mathrm{ns}\rangle$. As such, the operating point of the neuron can be estimated to be around $-58\si{mV}$, or $4\si{mV}$ below the threshold potential of $-54\si{mV}$.

\begin{figure}
\centering
\includegraphics[trim = {1.2cm 0 1cm 0.6cm}, width=0.8\textwidth, clip]{../pics/cv_aveV}
\caption{$c_v$ as a function of $\langle V_\mathrm{ns}\rangle$  for $N_\mathrm{ex}=100$ and varying $N_\mathrm{in}$. The original data is shown with blue points, and smoothed data is shown with the red line.}
\label{cv_aveV}
\end{figure}

%include picture
%\begin{figure}
%\centering
%\includegraphics[trim = {1.3cm 0 2cm 0.9cm}, width=\textwidth, clip]{../pics/picname}
%\caption{caption text}
%\label{label}
%\end{figure}
\end{document}


\documentclass{report}
\usepackage{longtable}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{fontspec}
\usepackage[section]{placeins}

\newfontfamily{\ttconsolas}{Consolas}

\title{Lab6\_Ripple Carry Adder design}
\author{201704150 Kangjun Heo}

\lstset{basicstyle=\ttfamily,breaklines=true}
\lstset{framextopmargin=10pt,framexbottommargin=10pt,frame=tb}

\begin{document}
    \maketitle
    \tableofcontents

    \chapter{Purpose of the lab}

        \paragraph{This lab aims to design 8-bit Ripple Carry Adder with Verilog language. This report contains Truth table, Boolean equation, Karnaugh map and Logic diagram.}

        \section{Ripple Carry Adder}

        \paragraph{\normalfont Ripple Carry Adder is a adder that consists of Full Adders, that outputs Sum and Carry for specific bits-sized data. For the 8-bit RCA, it gets two 8bit-sized data and 1 bit of carry, outputs 8bit-sized sum and 1 bit of carry.}

    \chapter{Design Procedure}

        \begin{figure}[!htb]
            \centering
            \includegraphics[width=\textwidth]{diagrams/full-adder-logic.PNG}
            \caption{Logic Diagram of Full Adder}
        \end{figure}

        \begin{figure}[!htb]
            \centering
            \includegraphics[width=\textwidth]{diagrams/rca-8b-logic.PNG}
            \caption{Logic Diagram of 8bit Ripple Carry Adder}
        \end{figure}

    \chapter{Simulation}
        \section{Source Code}
            \lstinputlisting[caption=Full Adder]{ripple-carry-adder/full_adder_1b.v}
            \lstinputlisting[caption=Full Adder]{ripple-carry-adder/rca_8b_top.v}
        \section{Testbench}
            \lstinputlisting[caption=Full Adder]{ripple-carry-adder/rca_8b_tb.v}

        \section{Simulation Result}
            \begin{figure}[!htb]
                \centering
                \includegraphics[width=\textwidth]{diagrams/rca-8b-waveform-part1.PNG}

                \caption{Waveform: 8-bit Ripple Carry Adder Part1}
                \label{fig:waveform_rca8bp1}
            \end{figure}

            \begin{figure}[!htb]
                \centering
                \includegraphics[width=\textwidth]{diagrams/rca-8b-waveform-part2.PNG}

                \caption{Waveform: 8-bit Ripple Carry Adder Part2}
                \label{fig:waveform_rca8bp2}
            \end{figure}

            \begin{longtable}[here,width=\textwidth]{|c|c|c|c|c|c|}
                \caption{Result table from Figure~\ref{fig:waveform_rca8bp1} Figure~\ref{fig:waveform_rca8bp2} \label{fig:result_table}}      \\

                \hline
                Case & X                         & Y                         & Cin                & S        & Cout               \\ \hline
                \#01 & \multirow{2}{*}{00000001} & \multirow{8}{*}{00000001} & 0                  & 00000010 & \multirow{4}{*}{0} \\ \cline{1-1} \cline{4-5}
                \#02 &                           &                           & 1                  & 00000011 &                    \\ \cline{1-2} \cline{4-5}
                \#03 & \multirow{2}{*}{00000011} &                           & 0                  & 00000100 &                    \\ \cline{1-1} \cline{4-5}
                \#04 &                           &                           & 1                  & 00000101 &                    \\ \cline{1-2} \cline{4-6}
                \#05 & \multirow{2}{*}{11111111} &                           & 0                  & 00000000 & \multirow{2}{*}{1} \\ \cline{1-1} \cline{4-5}
                \#06 &                           &                           & 1                  & 00000001 &                    \\ \cline{1-2} \cline{4-6}
                \#07 & \multirow{2}{*}{11111110} &                           & 0                  & 11111111 & 0                  \\ \cline{1-1} \cline{4-6}
                \#08 &                           &                           & 1                  & 00000000 & \multirow{2}{*}{1} \\ \cline{1-5}
                \#09 & \multirow{2}{*}{10000000} & 10000000                  & \multirow{8}{*}{0} & 00000000 &                    \\ \cline{1-1} \cline{3-3} \cline{5-6}
                \#10 &                           & \multirow{2}{*}{01000000} &                    & 11000000 & \multirow{7}{*}{0} \\ \cline{1-2} \cline{5-5}
                \#11 & 01000000                  &                           &                    & 10000000 &                    \\ \cline{1-3} \cline{5-5}
                \#12 & 00100000                  & 00100000                  &                    & 01000000 &                    \\ \cline{1-3} \cline{5-5}
                \#13 & 00010000                  & 00010000                  &                    & 00100000 &                    \\ \cline{1-3} \cline{5-5}
                \#14 & 00001000                  & 00001000                  &                    & 00010000 &                    \\ \cline{1-3} \cline{5-5}
                \#15 & 00000100                  & 00000100                  &                    & 00001000 &                    \\ \cline{1-3} \cline{5-5}
                \#16 & 00000010                  & 00000010                  &                    & 00000100 &                    \\ \hline
            \end{longtable}

    \chapter{Evaluation}
        \paragraph{\normalfont Figure~\ref{fig:waveform_rca8bp1}, Figure~\ref{fig:waveform_rca8bp2}, and Table~\ref{fig:result_table} shows the result of testbench simulation.  }

        \paragraph{\normalfont For the cases \#01 \~ \#08, Carries are successfully passed into next adder, and caused overflow. Also, Every adders can pass its carry to next stage, As if case \#11 \~ \#16.}

        \paragraph{\normalfont Therefore, The Ripple Carry Adder is properly designed.}
    \chapter{Discussions}
        \section{Key Part of This Lab}
            \paragraph{\normalfont In this lab, I've learned about how to draw and symbolize submodules in block diagram. Also, it could be defined as another module, that is able to be utilized in top or any other submodules.}

        \section{Mistakes}
            \begin{figure}[!htb]
                \centering
                \includegraphics[width=\textwidth]{diagrams/rca-8b-waveform-wrong.png}
                \caption{Wrong waveform due to design error}
            \end{figure}

            \paragraph{\normalfont I initially designed the Full Adder to determine sum as \texttt{ s = x \^{} y } and I got wrong waveforms.}

            \paragraph{\normalfont After I revise the line to \texttt{ s = x \^{} y \^{} cin } then I got the right waveform.}
        \section{Expected Improvements}

            \paragraph{\normalfont From this project, The system will be designed could be larger and complex, requires much more testing cases. }
\end{document}


\subsection{Concept Questions} % (fold)
\label{sub:concept_questions_types}

Read over the concepts in this chapter and answer the following questions:
\begin{enumerate}
  \item What is a type?
  \item What is the relationship between a type and a value?
  \item When you create your own type what have you created? A value, or something else?
  \item Why would you want to create your own type?
  \item What are the three main kinds of type you can create?
  \item What kind of data type(s) could you create to model the following in a program?
  \begin{enumerate}
    \item An address book, containing names, phone numbers, and email addresses.
    \item The kind of a `\emph{power up}' in a game, e.g. health pack, upgrade, bonus, etc.
    \item A field that is either an integer, a double, or some text.
    \item A button that has a location on the screen, a width and height, and some text that is drawn on the button.
  \end{enumerate}
  \item What is a record? What can it be used to model?
  \item What is an enumeration? What can it be used to model?
  \item What is a union? What can it be used to model?
  \item Why is it a good idea to use an enumeration in conjuncture with a union?
  \item Explain the different ways you can store/read a value when you are using a record.
  \item Explain the different ways you can store/read a value when you are using a enumeration.
  \item Explain the different ways you can store/read a value when you are using a union.
  \item Open one of your SwinGame projects and have a look in the \texttt{lib} folder. This folder contains a number of source code files used to access SwinGame functionality. Have a look in the \textbf{Types} file (types.c or sgTypes.pas), and examine the follow types. For each type write a short description of what it contains.
  \begin{enumerate}
    \item Rectangle
    \item Circle
    \item LineSegment
    \item Triangle
    \item Point 2D
    \item Vector
  \end{enumerate}
\end{enumerate}
% subsection concept_questions (end)

\clearpage
\subsection{Code Writing Questions: Applying what you have learnt} % (fold)
\label{sub:code_writing_questions_applying_what_you_have_learnt_types}

Apply what you have learnt to the following tasks:

\begin{enumerate}
  \item Create a \texttt{Contact} record that stores a person's name (50 characters), their phone number (20 characters), and email address (50) characters.
  \item Use the \texttt{Contact} record to create a small address book program that lets you enter in the details of four contacts, and then outputs these to the Terminal.
  \item Implement the Lights program from \sref{sub:lights}.
  \item Implement the Shape Drawing program, add the code to create Ellipse and Triangle shapes.
  \item Implement the Small DB program, including the support for the double data in the row.
\end{enumerate}
% subsection code_writing_questions_applying_what_you_have_learnt (end)

\bigskip
\subsection{Extension Questions} % (fold)
\label{sub:extension_questions_types}

If you want to further your knowledge in this area you can try to answer the following questions. The answers to these questions will require you to think harder, and possibly look at other sources of information.

\begin{enumerate}
  \item Extend the Small DB program so that each `\emph{row}' has three `\emph{columns}'.
  \item Explore the sizes of the different data types you have created using the \texttt{Size Of} function: \texttt{sizeof} in C, or \texttt{SizeOf} in Pascal.
\end{enumerate}
% subsection extension_questions (end)


\documentclass[Physics.tex]{subfiles}
\begin{document}
\chapter{Measurement}
\section{Quantities}
A \sldef{physical quantity} is a property of a phenomenon, body or substance quantifiable by measurement.

\sldef{Base quantities} are physical quantities that are the most fundamental and independent of each other. \sldef{Derived quantities} are quantities formed by combining base quantities.

A \sldef{scalar} is a physical quantity with magnitude only. A \sldef{vector} is a physical quantity with both magnitude and direction.

A \sldef{homogeneous equation} is one in which every term has the same units. All physical equations are homogenous.
\section{Error and uncertainty}
\sldef{Random error} is an error in measurement in which measured quantities differ from the mean value by different magnitudes and directions. Sources of random error include parallax error, environmental variations, inherent irregularities, or equipment limitations (e.g. very sensitive equipment).

\sldef{Systematic error} is an error in measurement in which measured quantities differ from the true value by a fixed magnitude and in the same direction. Sources of systematic error include zero error, parallax error, and the environment (e.g. background radiation when measuring radioactive decay). A zero error occurs when an instrument registers a reading when there should be none.

\sldef{Accuracy} is a measure of how close the results of an experiment agree with the true value (systematic error). \sldef{Precision} is a measure of how close the results of an experiment agree with one another (random error).
\subsection{Uncertainty propagation}
For uncertainty propagation, \begin{align}Y &= ma \pm nb \implies {\Delta}Y = m{\Delta}a + n{\Delta}b\\
Y &= a^mb^n \implies \frac{{\Delta}Y}{Y} = \left|m\frac{{\Delta}a}{a}\right| + \left|n\frac{{\Delta}b}{b}\right|\end{align}
\section*{Base quantities and units}
\begin{tabular}[c]{@{}llllll@{}}
\toprule
\textbf{Quantity} & & \textbf{Unit} & \tabularnewline
\midrule
mass & \(m\) & kilogram & \si{\kilogram}\tabularnewline
length & \(l\) & metre & \si{\metre}\tabularnewline
time & \(t\) & second & \si{\second}\tabularnewline
amount of substance & \(n\) & mole & \si{\mole}\tabularnewline
temperature & \(T\) & kelvin & \si{\kelvin}\tabularnewline
current & \(I\) & ampere & \si{\ampere}\tabularnewline
luminous intensity & \(L\) & candela & \si{\candela}\tabularnewline
\bottomrule
\end{tabular}
\section*{SI prefixes}
\begin{tabular}[c]{@{}llllll@{}}
\toprule
\textbf{Prefix} & \(10^n\) & \textbf{Prefix} & \(10^n\) & \textbf{Prefix} & \(10^n\)\tabularnewline
\midrule
pico, \si{\pico} & -12 & nano, \si{\nano} & -9 & micro, \si{\micro} & -6\tabularnewline
deci, \si{\deci} & -1 & kilo, \si{\kilo} & 3 & mega, \si{\mega} & 6\tabularnewline
\bottomrule
\end{tabular}
\end{document}


\section{Overview}
\index{pimd}

Path Integral Molecular Dynamics (PIMD) is an adaptation of Feynmann's
path integral method \cite{feynmann-65} for calculating the properties
of quantum systems. PIMD is derived from an earlier method known as
Path Integral Monte Carlo (PIMC) and is applicable to the same range
of molecular systems. However, despite being a molecular dynamics
technique PIMD is {\em not} an implementation of quantum dynamics and,
unlike classical molecular dynamics, provides {\em no} dynamical
information about the system under study. Properties such as time
dependent correlation functions and transport coefficients are
therefore beyond its scope.  It is purely concerned with obtaining
quantum corrected thermodynamics and structural properties. For this
reason, PIMD is best thought of as PIMC by other means.

PIMD was implemented in \D{} by Bill Smith. Users should note that the
implementation cannot deal with rigid bonds, rigid molecules (or rigid
molecular parts) or polarisable ions. It can however handle free atoms,
rigid ions and fully flexible molecules.

\section{Theory of PIMD}
\index{pimd!theory of}
\label{pimdtheory}

The theory of path integrals is described in a very accessible manner
in the book `Quantum Mechanics and Path Integrals' by Feynmann and
Hibbs \cite{feynmann-65} and a modern take on the subject can be found
in Mark Tuckermann's book `Statistical Mechanics: Theory and Molecular
Simulation' \cite{tuckerman-10}. Both are highly recommended. Aspects
of the theory implemented in \DD{} are described in chapter 12 of the
e-book `Elements of Molecular Dynamics' by Smith \cite{smith-14}. In
this section we outline the essential details only.

The central idea of both PIMD and PIMC is that the partition function
of a system of {\em quantum} particles is isomorphic with that of a
system of {\em classical} ring polymers. In this isomorphism each ring
polymer corresponds to one quantum particle\footnote{As far as \DD{}
  is concerned, a `quantum particle' is a simple atom or
  ion.}. The so-called `beads' of the polymer represent alternative
locations for the quantum particle according to the probabilistic
interpretation of the wave function and collectively describe the
`Heisenberg uncertainty' in the quantum particle's location. The ring
polymer is linked together by harmonic bonds acting between pairs of
beads, which maintain the integrity of the ring and constrain the
beads to locations that are consistent with quantum
probability. Otherwise the beads are essentially free particles
independently exploring phase space.

We can write the partition function ($Z_{N}$) for the N-particle
quantum system as follows (in which the resemblance to a system
composed of classical ring polymers should be evident):
\begin{equation}
  Z_{N}= \left ( \frac{mL}{2 \pi \hbar^{2} \beta} \right )^{3LN/2} \int \ldots \int \exp \left ( -\beta \sum_{j=1}^{N}
\sum_{k=1}^{L} \left [ \frac{\kappa}{2}(|\vek{ r}_{j,k}-\vek{ r}_{j,k-1}| )^{2}+
 \frac{1}{L} \Phi\left(\vek{ r}_{j,k}\right) \right ] \right ) \Pi_{j}^{N} \Pi_{k}^{L} d \vek{ r}_{j,k}, \label{qpartition}
\end{equation}
with
\begin{equation}
  \kappa = \frac{mL}{(\beta \hbar)^{2}}. \label{qspring}
\end{equation}
In this equation $N$ is the number of quantum particles and $L$ is the
number of beads chosen to represent each particle. Each pair of
indices $j$ and $k$ identifies the $j'th$ particle and its $k'th$
bead. Symbols $\Pi_{j}^{N} \Pi_{k}^{L} d \vek{r}_{j,k}$ represent a
product of the differential coordinates of all beads
(i.e. $dx_{j,k}dy_{j,k}dz_{j,k} \ldots etc.$).  The parameter $\kappa$
is the force constant of the harmonic bonds and (\ref{qspring}) shows
that it is defined by the quantum particle's mass, the system
temperature (through Boltzmann's constant $\beta=1/k_{B}T$), Planck's
constant $\hbar$ and the number of beads in the ring $(L)$. The number
$L$ is an adjustable parameter and its value reflects how
`quantum-like' the particle behaves. A low number of beads $(L\sim
10)$ implies the particle behaves semi-classically, while a large
number $L\sim 300$ implies significant quantum behaviour. This gives
some scope for `tuning' the quantum nature of the simulation to suit
the application. Formally, equation (\ref{qpartition}) is exact only
in the limit: $L \rightarrow \infty$, otherwise PIMD should be
regarded as semi-quantitative.

The potential function $\Phi\left (\vek{r}_{j,k}\right)$ appearing in
equation (\ref{qpartition}) describes how an individual bead, with
indices $j$ and $k$, interacts with its environment, and it is
significant from a quantum perspective that it appears in
(\ref{qpartition}) with the associated factor $1/L$.  The most
important quantum effect in atomistic simulations is arguably quantum
tunnelling - the ability of an atom to penetrate regions that are
classically forbidden. This effect can be seen in the radial
distribution function (for example), which describes the atomistic
structure and therfore impacts on the thermodynamics of the system. In
this context the potential factor of $1/L$ indicates that the bead
interaction with the environment is reduced in comparison with the
original classical particle. This allows a greater ability of the beads
to penetrate into classically improbable regions, which is consistent
with the idea of quantum tunnelling.

The energy of the harmonic bonds (determined by the parameter $\kappa$
in (\ref{qpartition})) is a component of the kinetic energy of the
quantum particle related to its zero point energy.  However, in the
classical simulation of the isomorphic ring polymers, this term is
manifestly a contributor to the configurational energy of the
rings. Its meaning is therefore different in the two systems and this
fact should be noted. (Incidentally, note that when the subscript
$k-1$ equals zero in (\ref{qpartition}) this is interpreted as the
index $L$, which is required by the closure of the ring polymer.)

When the environment of the quantum particle consists of other quantum
particles, the form of the potential function $\Phi\left
(\vek{r}_{j,k}\right)$ may (for example) be written as a sum of
bead-bead pair potentials:
\begin{equation}
  \Phi\left (\vek{r}_{j,k}\right )= \frac{1}{2} \sum_{j' \ne j}^{N} \phi_{pair}
  ( |\vek{r}_{j,k}- \vek{r}_{j',k} |), \label{qpair}
\end{equation}
where $\phi_{pair}$ is a pair potential of the van der Waals or
Coulombic kind.  What is noticeable about equation (\ref{qpair}) is
that there is no sum over the bead index $k$ on the right. This
reflects the fact that, due to a quirk of the path integral origins of
(\ref{qpair}) \cite{smith-14}, a given bead on the polymer ring ($k$)
can only interact with a single corresponding bead ($k'$) on
neighbouring polymer rings i.e. $k=k'$ and interactions where $k'\ne
k$ are forbidden\footnote{Technically speaking, beads $k$ and $k'$
  exist at different instants of imaginary time and are therefore
  invisible to each other.}. This requirement means the calculation of
the potential energy and force is considerably less costly than would
be expected in a simulation of true classical ring polymers. This
amounts to a substantial `decoupling' of the bead-bead interactions
(in classical terms) and means that, to a large extent, the whole
system can be simulated as a set of $L$ quasi-independent systems,
which are coupled via the harmonic springs. This decoupling is
exploited in the way \DD{} performs the PIMD simulations.

In principle, the simulation of a system of ring polymers with harmonic
bonds, bead masses and bead-bead interactions as defined above, will
effectively be a simulation of the corresponding quantum system, correct to
an accuracy determined by the chosen number of beads. From such a
simulation the structure and thermodynamics of the quantum system can
be obtained in a manner that is similar to any classical simulation.
It is evident that the simulation could equally be performed using
either molecular dynamics or Monte Carlo, though in the case of \DD{},
it is inevitably the former choice that is taken.

A potential problem with PIMD simulations is that harmonic bonds are
notoriously non-ergodic, which means that energy exchange between
degrees of freedom is inefficient and the system is slow to
equilibrate. Indeed, even very long simulations can fail to achieve
the equipartition necessary for a successful calculation of
thermodynamic properties {\em unless strong preventative measures are
  taken}.  As described in \cite{tuckerman-10} these measures include
the use of staging variables in place of the usual atomic coordinates
and an extensive regime of thermostatting using either Nos\'{e}-Hoover
chains \cite{martyna-92a,tuckerman-10} or the so-called `gentle'
thermostats of Leimkuhler {\em et al} \cite{leimkuhler-09a}, both of
which which are options in the \DD{} implementation.  Note that,
according to (\ref{qspring}), a large particle mass $m$, or a large
number of beads $L$, or a high temperature (i.e. small $\beta$)
implies a large force constant $\kappa$.  Large values of $\kappa$
worsen the ergodicity problems and simultaneously demand an unusually
short time step for stable simulations, which leads to slower sampling of
phase-space. It is therefore usual to decrease the number of beads
when the particle mass is large or the simulation temperature is high,
since the quantum particles behave more classically in these cases.

In PIMD molecular dynamics is used entirely as a means to explore the
phase space of the system. (In PIMC the same job is done by Metropolis
sampling.) The dynamics is based on a Hamiltonian of the form
\begin{equation}
H(\{\vek{p}_{j,k}\},\{\vek{r}_{j,k}\})=\sum_{j=1}^{N} \sum_{k=1}^{L}
\left [ \frac{p^{2}_{j,k}}{2m'}+ \frac{\kappa}{2}(|\vek{r}_{j,k}-\vek{
    r}_{j,k-1}| )^{2}+ \frac{1}{L} \Phi \left (\vek{ r}_{j,k} \right ) \right ], \label{qhamil}
\end{equation}
in which we have introduced the bead momentum $\vek{p}_{j,k}$ and a
so-called bead dynamical mass $m'$, which need not be the same as the
formal mass $m$ of the quantum particle if the intention is merely to
use this Hamiltonian to drive the dynamics of the classical system.
Suitable equations of motion are easily obtained from this. However,
as was mentioned above, it is essential to augment the dynamics with
methods to ensure ergodic behaviour. This is described in greater
detail below, following a description of properties calculable by
PIMD.

An important thermodynamic property of a quantum system is the
internal energy $E$, which is given thermodynamically as the
derivative of the partition function:
\begin{equation}
  \left \langle E \right \rangle =-\frac{\partial}{\partial \beta} ln (Z_{N}).
\end{equation}
Applying this rule to the partition function (\ref{qpartition}) leads
to the standard energy estimator for PIMD:
\begin{equation}
  \left \langle E \right \rangle =\frac{3LN}{2 \beta}- \left \langle
  \sum_{j=1}^{N} \sum_{k=1}^{L} \left [ \frac{\kappa}{2} (| \vek{ r}_{j,k}-\vek{
      r}_{j,k-1}| )^{2} -\frac{1}{L} \Phi\left (\vek{ r}_{j,k} \right ) \right ]  \right \rangle .
  \label{Est1}
\end{equation}
However, it was shown by Herman {\em et al.} \cite{herman-82a} that
fluctuations in this estimator grow linearly with the number of beads
$L$, raising concerns about the accuracy of the mean value. An
alternative estimator based on the virial was offered that overcame this
deficiency. This is written as
\begin{equation}
  \left \langle E \right \rangle =\frac{3N}{2 \beta}+ \left \langle \frac{1}{L}
  \sum_{j=1}^{N} \sum_{k=1}^{L} \left [ \frac{1}{2} (\vek{ r}_{j,k}-\vek{
      R}_{j} )\cdot \frac{\partial}{\partial \vek{r}_{j,k}}\Phi \left (\vek{ r}_{j,k} \right )+
    \Phi \left (\vek{ r}_{j,k} \right )\right ]  \right \rangle , \label{Est2}
\end{equation}
where
\begin{equation}
  \vek{R}_{j}=\frac{1}{L} \sum_{k=1}^{L} \vek{r}_{j,k}, \label{qcom}
\end{equation}
is the centre of mass of the $j'th$ ring. The virial estimator
(\ref{Est2}) ought to be more accurate than the standard energy
estimator (\ref{Est1}), but in practice this is not always the
case. Both versions are available in \DD{} and a comparison between the
two is useful as an indicator of statistical convergence.

A formula for the system pressure in PIMD simulations can be obtained
by differentiating the Hamiltonian (\ref{qhamil}) with respect to volume:
\begin{equation}
  P=-\left \langle \left ( \frac{\partial}{\partial V}H(\{\vek{p}_{j,k}\},\{\vek{r}_{j,k}\})
     \right ) \right \rangle .
\end{equation}
Assuming exclusively pair potentials for the bead-bead interactions leads to
\begin{equation}
  PV=\frac{LN}{\beta}-\frac{1}{3} \left \langle \sum_{j=1}^{N} \sum_{k=1}^{L}
  \left [ \kappa (| \vek{r}_{j,k}-\vek{r}_{j,k-1} |)^{2}+\frac{1}{2L} \sum_{j' \ne j}^{N}
    \left ( \frac{\partial}{\partial \vek{r}_{jj',k}}\phi_{pair}(\vek{ r}_{jj',k})
    \right )\cdot \vek{ r}_{jj',k}) \right ] \right \rangle .
\end{equation}
where
\begin{equation}
  \vek{r}_{jj',k}=\vek{r}_{j',k}-\vek{r}_{j,k} .
\end{equation}

With regard to structural properties, the radial distribution function
$g(r)$ can be obtained in a manner closely resembling the classical
case (allowing for the multiplicity of beads per atom):
\begin{equation}
  g(r)=\frac{1}{LN \rho} \left \langle \sum_{k=1}^{L} \sum_{j=2}^{N} \sum_{j'=1}^{j}
  \delta(|\vek{r}-\vek{r}_{j',k}+\vek{r}_{j,k}|) \right \rangle .
\end{equation}
From this formula it can be seen that $g(r)$ is calculated entirely
from correlations between corresponding beads $k$ on different ring
polymers.

Another useful structural property is the mean-square radius of
gyration of the polymer rings $\langle R^{2} \rangle$ . This provides a
measure of the {\em delocalisation} of the quantum particle implied by
Heisenberg uncertainty. It is defined as
\begin{equation}
  \left \langle R^{2} \right \rangle = \left \langle \frac{1}{LN}
  \sum_{j=1}^{N} \sum_{k=1}^{L} | \vek{r}_{j,k}-\vek{R}_{j} |^{2} \right \rangle
\end{equation}
where $\vek{R}_{j}$ is the centre of mass of the $j'th$ polymer ring
and is given by (\ref{qcom}).

The mean-square radius is related to the mean-square bondlength $
\langle B^{2} \rangle $ defined as
\begin{equation}
  \langle B^{2} \rangle =\left \langle |\vek{r}_{j+1,k}-\vek{r}_{j,k}|^{2} \right \rangle
\end{equation}
(where the index $j+1 \equiv 1$ when $j=L$.) The mean-square
radius and bondlength are related through the expression
\begin{equation}
  \left \langle R^{2} \right \rangle =\frac{L}{12} \langle B^{2} \rangle,
\end{equation}
which holds for ideal ring polymers in equilibrium. This relation
affords a rough check that the system is properly equilibrated, along
with other indicators of equilibrium, which are described below.

\section{Path Integral Dynamics}
\index{pimd!dynamics}
\label{pimddynamics}
In the main, the implementation of PIMD in \D{} follows the
prescription given by Tuckerman {\em et al} \cite{tuckerman-93a}. In
the first part, the Cartesian coordinates defining the positions of
the polymer beads are cast into collective coordinates better able to
address the range of time scales in the motion of the rings. This
process is known as `staging'. In the second part the dynamics of the
staged coordinates are subjected to an efficient thermostatting regime
to ensure the system dynamics are properly ergodic.

The staging coordinates $\vek{u}_{j,k}$  are defined in the following manner:
\begin{eqnarray}
  \vek{u}_{j,1}&=&\vek{r}_{j,1}  \nonumber \\
  \vek{u}_{j,k}&=&\vek{r}_{j,k}-\frac{(k-1)\vek{r}_{j,k+1}+\vek{r}_{j,1}}{k}\phantom{xxxxx} (k=2,\ldots,L),
\end{eqnarray}
for which the inverse is obtained using the reverse formula:
\begin{eqnarray}
  \vek{r}_{j,1}&=&\vek{u}_{j,1}  \nonumber \\
  \vek{r}_{j,k}&=&\vek{u}_{j,k}-\frac{(k-1)\vek{r}_{j,k+1}+\vek{r}_{j,1}}{k}\phantom{xxxxx} (k=L,\ldots,2).
\end{eqnarray}

In addition, a set of parameters $\mu_{k}$ is introduced, which is defined as follows:
\begin{eqnarray}
  \mu_{1}&=&0 \nonumber \\
  \mu_{k}&=&\frac{k}{k-1}\phantom{xxxxxxxxxxxxx} (k=2,\ldots,L).
\end{eqnarray}

In terms of these variables the driving Hamiltonian (\ref{qhamil}) can be re-written as
\begin{equation}
  H(\{\vek{\pi}_{j,k}\},\{\vek{u}_{j,k}\})=\sum_{j=1}^{N} \sum_{k=1}^{L}
  \left [ \frac{\pi^{2}_{j,k}}{2m_{k}'}+\mu_{k}\frac{\kappa}{2}(\vek{u}_{j,k}
    \cdot\vek{u}_{j,k} )+ \frac{1}{L} \Phi \left (\vek{r}_{j,k}(\{\vek{u}_{j',k}\} \right )) \right ],
  \label{qhamil2}
\end{equation}
where $\vek{\pi}_{j,k}$ represents the momentum associated with the
staged coordinate $\vek{u}_{j,k}$.  In this equation a new mass
parameter $m_{k}'$ has been introduced as the dynamical mass. The
recommended values given by Tuckerman {\em et al.} \cite{tuckerman-93a}
are
\begin{eqnarray}
  m_{1}'&=&m \nonumber \\
  m_{k}'&=& \mu_{k} m \phantom{xxxx}(k>1).
\end{eqnarray}
Using the Hamiltonian (\ref{qhamil2}) we may proceed to obtain the
equations of motion for the system of ring polymers. These are
presented below with the necessary thermostats included. The
thermostats, it should be noted, are applied to {\em every} degree of
freedom in the system individually - not collectively as is more
common in conventional molecular dynamics.

The equations of motion including Nos\'{e}-Hoover chains of length $M$
per bead degree of freedom \cite{tuckerman-93a} are
\begin{eqnarray}
  \vek{\dot{u}}_{j,k}&=&\frac{\vek{\pi}_{j,k}}{m_{k}'} \nonumber \\
  {\dot \pi}_{j,k}^{\alpha}&=&-\kappa \mu_{k}u_{j,k}^{\alpha}-\frac{1}{L} \frac{\partial}
  {\partial u_{j,k}^{\alpha}}\Phi\left (\vek{r}_{jk}(\{\vek{u}_{j',k}^{\alpha}\})\right )-
  \zeta_{j,k,1}^{\alpha}{\pi}_{j,k}^{\alpha} \nonumber \\
  {\dot \zeta}_{j,k,1}^{\alpha}&=&\frac{1}{Q_{1}} \left (\frac{(\pi_{j,k}^{\alpha})^{2}}{m_{k}'}-k_{B}T_{o} \right )
  -\zeta_{j,k,1}^{\alpha}\zeta_{j,k,2}^{\alpha} \label{pimd-nhc}\\
  {\dot \zeta}_{j,k,n}^{\alpha}&=&\frac{1}{Q_{k}} \left (Q_{k}(\zeta_{j,k,n-1}^{\alpha})^{2}-k_{B}T_{o} \right )
  -\zeta_{j,k,n}^{\alpha}\zeta_{j,k,n+1}^{\alpha}  \nonumber\\
  {\dot \zeta}_{j,k,M}^{\alpha}&=&\frac{1}{Q_{k}} \left (Q_{k}(\zeta_{j,k,M-1}^{\alpha})^{2}-k_{B}T_{o} \right ) \nonumber
\end{eqnarray}
where $\alpha=x,y,z$ as appropriate and $T_{o}$ is the target
temperature.  The variables $\zeta_{j,k,n}$ {\em etc.} are the
thermostat variables. The values of the thermostat `mass' parameters
$Q_{k}$ recommended by Tuckerman {\em et al} \cite{tuckerman-93a} are
\begin{equation}
  Q_{1}=k_{B}T_{o} \tau^{2}, \phantom{xxxxx} Q_{k}=\hbar^{2}/Lk_{B}T_{o},
\end{equation}
where $\tau$ is a user defined time scale parameter appropriate for
the timescale of the ring centre of mass motion..

The forces required to update the momentum components
${\pi}_{j,k}^{\alpha}$ above are obtained from
\begin{eqnarray}
  \frac{\partial}{\partial u_{j,1}^{\alpha}}\Phi \left (\vek{r}_{jk}(\{\vek{u}_{j',k}^{\alpha}\}) \right )&=&
  \frac{1}{L}\sum_{k=1}^{L}\frac{\partial}{\partial r_{j,k}^{\alpha}}\Phi\left (\vek{r}_{jk} \right ), \nonumber \\
  \frac{\partial}{\partial u_{j,k}^{\alpha}}\Phi\left (\vek{r}_{jk}(\{\vek{u}_{j',k}^{\alpha}\}) \right )&=&
  \frac{1}{L}\left ( \frac{(k-2)}{(k-1)}\frac{\partial}{\partial u_{j,k}^{\alpha}}+
  \frac{\partial}{\partial r_{j,k}^{\alpha}} \right ) \Phi\left (\vek{r}_{jk}(\{\vek{u}_{j',k}^{\alpha}\}) \right ).
\end{eqnarray}
In \DD{} these equations are integrated using the velocity Verlet
algorithm and it is useful to note that the following quantity is
formally conserved during the integration.
\begin{equation}
  E_{cons}=\sum_{j=1}^{N}\sum_{k=1}^{L} \left [ \frac{\pi_{j,k}^{2}}{2 m_{k}'}+
    \mu_{k} \frac{\kappa}{2} (\vek{u}_{j,k} \cdot \vek{u}_{j,k})+
    \frac{1}{L}\Phi\left (\vek{r}_{jk}(\{\vek{u}_{j',k}^{\alpha}\}) \right )+ \newline
    \sum_{n=1}^{M} \sum_{\alpha} \left \{ \frac{1}{2}Q_{k}({\dot \zeta}_{j,k,n}^{\alpha})^{2}
    +\frac{1}{\beta}\eta_{j,k,n}^{\alpha} \right \} \right ]. \label{qcons}
\end{equation}
The variables $\eta_{j,k,n}$ are obtained by integrating the variables
$\zeta_{j,k,n}$ using the equation
\begin{equation}
  {\dot \eta}_{j,k,n}^{\alpha}=\zeta_{j,k,n}^{\alpha}.
\end{equation}
The last sum on the right of (\ref{qcons}) clearly represents the
energy of the thermostats, while the preceeding terms refer to the quantum system.

The corresponding equations of motion with the gentle thermostats
of Leimkuhler {\em et al} \cite{leimkuhler-09a} (which is again
applied to every degree of freedom) are
\begin{eqnarray}
  \vek{\dot{u}}_{j,k}&=&\frac{\vek{\pi}_{j,k}}{m_{k}'} \nonumber \\
  {\dot \pi}_{j,k}^{\alpha}&=&-\kappa \mu_{k}u_{j,k}^{\alpha}-\frac{1}{L} \frac{\partial}
  {\partial u_{j,k}^{\alpha}}\Phi\left (\vek{r}_{jk}(\{\vek{u}_{j',k}^{\alpha}\})\right )-
  \zeta_{j,k}^{\alpha}{\pi}_{j,k}^{\alpha}   \label{pimd-gt} \\
  d{\zeta}_{j,k}^{\alpha}&=&\frac{1}{Q} \left (\frac{(\pi_{j,k}^{\alpha})^{2}}{m_{k}'}-k_{B}T_{o} \right )dt
  -\frac{Q\chi^{2}}{2 k_{B}T_{o}}\zeta_{j,k}^{\alpha}dt +\chi dW. \nonumber
\end{eqnarray}
The first two equations in this series determine the thermostatted
motion of the beads ({\em c.f.} (\ref{pimd-nhc})), while the third
determines the motion of the thermostats $\zeta_{j,k}$. On the far
right the third equation includes an impulse term $\chi dW$ for each
thermostat, where $\chi$ defines the impulse magnitude and $dW$ is a
random number selected from Gaussian distribution with zero mean and
unit standard deviation. Preceding this on the right is the
dissipation term, which extracts heat energy from the system to
maintain the average temperature. $\chi$ is a user-selected
parameter chosen to control the rate at which energy is put into the
system. The constant of dissipation $Q \chi^{2}/2 k_{B}T_{o}$ is
fixed by the fluctuation-dissipation theorem. In its original
conception \cite{leimkuhler-09a}, the gentle thermostat was intended
to have a minimal effect on the system dynamics, so $\chi$ was
small, which meant that time dependent properties could be preserved,
but that need not be a concern in PIMD simulations, which are
concerned with structure only.

In both approaches (\ref{pimd-nhc}) and (\ref{pimd-gt}), it is useful
to have some means of monitoring the simulation to ensure that it
properly samples from the canonical ensemble. This requires that the
kinetic energy of every degree of freedom has an average value of
$k_{B}T_{o}/2$ and that the staged momenta of the beads are
collectively represented by a Gaussian distribution. In \DD{} the
quality of the obtained momentum distribution is assessed by comparing
the even moments of the simulated distribution function with the ideal
values for a true Gaussian (see \cite{smith-14} ch. 12).  The expected
values for true Gaussian moments are
\begin{eqnarray}
  \left \langle (\pi_{j,k}^{2}/m_{k}') \right \rangle &=& k_{B}T_{o} \nonumber \\
  \left \langle (\pi_{j,k}^{2}/m_{k}')^{2} \right \rangle &=& 3 (k_{B}T_{o})^{2} \nonumber \\
  \left \langle (\pi_{j,k}^{2}/m_{k}')^{3} \right \rangle &=& 15(k_{B}T_{o})^{3}  \label{moments}\\
  \left \langle (\pi_{j,k}^{2}/m_{k}')^{4} \right \rangle &=& 105(k_{B}T_{o})^{4} \nonumber \\
  \left \langle (\pi_{j,k}^{2}/m_{k}')^{5} \right \rangle &=& 945(k_{B}T_{o})^{5}. \nonumber
\end{eqnarray}
Note that, in a simulation, the averages $\langle \ldots \rangle$ are
calculated over all momenta $\vek{\pi}_{j,k}$ and over many
configurations of the equilibrated simulation.  From (\ref{moments})
it follows that, in the ideal case
\begin{equation}
  1=\frac{\left \langle (\pi_{j,k}^{2}/m_{k}') \right \rangle }{k_{B}T_{o}}=
  \frac{\left \langle (\pi_{j,k}^{2}/m_{k}')^{2} \right \rangle }{3 (k_{B}T_{o})^{2}}=
  \frac{\left \langle (\pi_{j,k}^{2}/m_{k}')^{3} \right \rangle }{15 (k_{B}T_{o})^{3}}=
  \frac{\left \langle (\pi_{j,k}^{2}/m_{k}')^{4} \right \rangle }{105 (k_{B}T_{o})^{4}}=
  \frac{\left \langle (\pi_{j,k}^{2}/m_{k}')^{5} \right \rangle }{945 (k_{B}T_{o})^{5}}.
  \label{nmom}
\end{equation}
Thus the closeness of these ratios to the value unity indicates the
quality of the assumed Gaussian distribution for all momenta.  Note
the same analysis may also be conducted for the thermostat momenta and
this can be useful when exploring ergodicity issues. This is not
available in the default version of \D{}, but a subroutine for doing
this ({\sc thermostat\_moments}) is available in the module {\sc
  integrator\_module.f} and can be activated for the purpose.

\section{Invoking the PIMD Option}

To activate the PIMD option in \D{} appropriate entries must be made
in the CONTROL file. At the head of the CONTROL file, in place of the
{\bf integration} keyword, the keyword {\bf pimd} should be inserted,
followed by additional options. The syntax is one of the following
three options\newline
\newline
\noindent {\bf pimd nvt} {\em nbeads taut} \newline
\newline
\noindent for PIMD with a single Nos\'{e}-Hoover thermostat per degree of freedom, or \newline
\newline
\noindent {\bf pimd gth} {\em nbeads taut xsi} \newline
\newline
\noindent for PIMD with `gentle' thermostats, or \newline
\newline
\noindent {\bf pimd nhc} {\em nbeads nchain taut} \newline
\newline
\noindent for PIMD with Nos\'{e}-Hoover chains. \newline
\newline
The additional options appearing on the directives are:
\begin{itemize}
\item {\em nbeads} (integer) is the number of beads in each ring polymer.
\item {\em nchain} (integer) is the number of chained thermostats per degree of freedom.
\item {\em taut} (real) is the thermostat relaxation time $(\tau)$ in $ps$.
\item {\em chi} (real) is the magnitude of the impulse `force' $(\chi)$ in $ps^{-1}$
\end{itemize}
\noindent Each of these must be written in the indicated order. It is
permissible to use more informative invocations of these directives
({\em provided the sequence order given above is preserved}), such
as \newline
\newline
\noindent {\bf pimd nhc} nbeads=10 nchain=4 taut=0.1  \newline
\newline
\noindent These simple directives are sufficient to invoke a PIMD simulation.
However, the following points should also be noted.
\begin{itemize}
\item As is mentioned in the theory section above, the number of beads
  per ring polymer is a choice based on the expected degree of quantum
  behaviour of the constituent atoms. Some experience is required to
  make an appropriate choice, but note that the same number of beads
  represents {\em all} the atoms in the system, regardless of the
  different atoms that may be present.  The choice must therefore be
  made on the basis of the smallest atomic mass in the system if the
  quantum behaviour is to be properly handled.

\item The PIMD option implies velocity Verlet integration. The user
  should {\bf not} therefore specify the {\bf integration} keyword at
  the head of the CONTROL file. If one is specified, \DD{} will
  {\bf terminate} due to conflicting instructions.

\item PIMD also implies the NVT ensemble, so the user should {\bf not} use
  the {\bf ensemble} keyword in the CONTROL file. {\bf Termination} will
  again result if this is specified.
\end{itemize}

\section{PIMD Files}

In addition to the usual files \DD{} requires or creates, the PIMD
option also makes use of the following files.

\subsection{THENEW and THEOLD}

The file THENEW is created when a PIMD simulation completes. It
contains the current values of all the thermostat variables at the
time of completion. The data is required for a subsequent continuation
of the simulation using the {\bf restart} directive in the CONTROL
file. For this purpose the THENEW file must be renamed as THEOLD at
the restart. These files are {\em unformatted} and not human
readable. The contents, should the user need to know, are as follows.\\

\noindent {\bf Record 1} lists three variables:

\begin{itemize}
  \item Total number of beads in the system i.e. $natms \times nbeads$;
  \item Length of thermostat chain per bead i.e. the variable $nchain$;
  \item The system temperature i.e. that variable $temp$.
\end{itemize}

The subsequent records contain the thermostat chains. There are
$nchain \times natms \times nbeads$ records, each of which contains the following.

\noindent {\bf Records $2$ to $nchain \times natms \times nbeads+1$} list
six variables per record:

\begin{itemize}
  \item $\eta_{x}$ - x component of integrated thermostat of one bead
  \item $\eta_{y}$ - y component of integrated thermostat of one bead
  \item $\eta_{z}$ - z component of integrated thermostat of one bead
  \item $\zeta_{x}$ - x component of thermostat of one bead
  \item $\zeta_{y}$ - y component of thermostat of one bead
  \item $\zeta_{z}$ - y component of thermostat of one bead
\end{itemize}

The order in which the records are written is determined by three
nested loops, the first (outer) loop runs over the $nchain$ thermostat
chains, the second loop runs over the $natms$ atoms and the third
(inner) loop runs over the $nbeads$ beads for each atom.

\subsection{RNDNEW and RNDOLD}

The file RNDNEW is created when a PIMD simulation employing the gentle
thermostats completes. It contains the current values of all the
variables defining the state of the \DD{} parallel random number
generator {\sc puni()} at the time of completion. The information is
required to restart a simulation using the {\bf restart} directive in
the CONTROL file. The RNDNEW file must be renamed as RNDOLD at the
restart. These files are also {\em unformatted} and not human
readable.

For a simulation performed on a parallel computer with $mxnode$
processors, the files contain $mxnode$ records, each with 102
variables defining the state of {\sc puni()} on each processor.

\section{Things to be aware of when running a PIMD simulation}

\begin{itemize}
\item Usually, when starting a \DD{} simulation, the user supplies a
  CONFIG file for the system of interest containing the initial
  coordinates of every atom in the system. For the first run of a PIMD
  simulation however, it is not necessary to supply the coordinates
  for every bead of the ring polymers. Instead the user supplies the
  coordinates for each corresponding classical particle, which \DD{}
  expands using small random displacements into {\em nbeads} coordinates
  to complete the ring. This represents a first approximation to the
  ring polymers, which evolve dynamically thereafter.

\item After the first run of the simulation, the resulting REVCON file
  will contain coordinates for {\em all} the beads in the system. It
  follows that the CONFIG file used to {\bf restart} a simulation
  necessarily contains coordinates for every bead and \DD{} expects
  these data to be present in the file or else the restart will
  fail. This requirement also applies to the {\bf restart scale} and
  {\bf restart noscale} options.

\item The format of the expanded CONFIG file is essentially the same
  as a normal CONFIG file. If there are formally $N$ atoms (i.e. $N$
  quantum particles) in the system and each is represented by $L$
  beads, the expanded file contains $N\times L$ bead coordinates. The
  first $N$ coordinates refer to the first bead of each ring, the
  second set of $N$ coordinates refer to the second bead of each ring,
  and so on. This is important to know if the CONFIG file is to be
  used properly for non-\DD{} applications.

\item In addition to producing the standard output files: OUTPUT,
  REVCON, STATIS, REVIVE, RDFDAT {\em etc}, the PIMD option also
  produces a {\em thermostats} file called THENEW \index{THENEW file}
  (the format of which is described above). This file contains the
  current values of the thermostat parameters at the time the run
  finished. This file should be renamed THEOLD \index{THEOLD file} for
  a {\bf restart} of the PIMD simulation. The file THEOLD is not
  required for the {\bf restart scale} or {\bf restart noscale}
  options.

 \item The {\bf pimd gth} option also produces a thermostat file
   THENEW \index{THENEW file} on termination (and requires the
   corresponding THEOLD file for a restart). In addition however, it
   also produces a file RNDNEW, \index{RNDNEW} which stored the
   current state of the \DD parallel random number generator {\sc
     puni}. This must be renamed RNDOLD \index{RNDOLD} for a
   successful {\bf restart} of the simulation. It is important to
   note that in the current implementation it is assumed the restart
   will require the same number of parallel processors as the previous
   run. The file RNDOLD is not required for the {\bf restart scale} or
   {\bf restart noscale} options.

\item Equilibration and ergodicity are key issues in PIMD
  simulations. A good deal of effort is required sometimes to ensure
  that these requirements are properly fulfilled. Fortunately there
  are some indicators to assist with these matters. Firstly, the
  OUTPUT file lists the second, fourth, sixth, eighth and tenth
  moments (equation \ref{nmom}) of the momentum at the end of the
  simulation. If the momentum distribution is properly ergodic, the
  normalised moments should all be unity. In practice however, the
  higher moments tend to deviate increasingly from unity, though the
  agreement should still be close. Significant departure should be
  viewed critically. Also, if equilibration is good the standard
  \ref{Est1} and virial \ref{Est2} estimators should give closely
  similar results. If they don't then it is likely that ergodicity is
  an issue. The remedy is largely a matter of experimenting with the
  control parameter values for the {\bf pimd} directive or setting a
  shorter time step. To be more certain, using a different
  thermostatting method should afford a good comparison.

\item Two test cases are available to try out the \DD{} PIMD
  implementation (see Chapter \ref{data}). These systems are (a)
  neon (Test Case 40) and (b) water (Test Case 41), which both show
  significant quantum effects but are quite different in character.
  The first is an atomic system, while the latter includes the water
  as a polyatomic molecular entity. Both are outlined in the following
  chapter and both are available from the CCPForge repository, where
  the source code is located. It is worth trying different
  thermostatting methods in these systems from the one supplied.
\end{itemize}


\section{The statement of the conjecture}

\begin{itemize}
    \item Add Poincaré's first attempt at homology spheres being spheres
    \item Add the original statement
    \item Add the modern statement
\end{itemize}

It seems like an arbitrary simple question related to one of part of a classification of manifolds, so why is the question important?

One way to think about it is the following.
In ancient Egypt people were able to figure out using mathematics that the earth was actually not flat, but it was spherical.
This was hundreds of years before any human could travel outside the earth and look at the global structure, and not just the local ``flat'' one.
This shows that we can use local information to prove how the global information must be, at least in the case of the earth.
Now, ask the same question but a bit bigger.
Can humans ever (theoretically) confirm the shape of the universe without traveling outside it to view the global structure?
The Poincaré conjecture can be thought of as a mathematical gadget that gives us a partial answer to this.
The most likely shapes for the universe is either a sphere or a flat manifold (torus, cylinder), and if true, the Poincaré conjecture gives us a condition to answer this.
It gives us a (theoretically) testable procedure that would allow us to say for certain if the universe is a sphere or not.
Just simply fly everywhere in the universe with a rope to form loops and try to pull them in. If all loops can be pulled in, then we must live in a spherical universe.

\section{The solution}

Let $M$ be a closed 3-manifold.
Any Riemannian metric with constant Ricci curvature has constant sectional curvature.
By the Killing-Hopf theorem, any connected Riemannian manifold with constant positive curvature is homeomorphic to a quotient of its universal cover, $S^3$, with the linear free action of its fundamental group.
If we assume $M$ is simply connected and closed, like in the Poincare conjecture, a constant curvature must mean a constant positive one.
Hence a possible solution to the Poincare conjecture comes from solving the following question;
How can we construct a Riemannian metric on $M$ with constant Ricci curvature?

\subsection{Ricci flow}

\textbf{Slogan:} Ricci flow is a procedure for making a manifold ``rounder'' over time.

The Ricci flow equation is the following differential equation

$$\frac{\partial g(t)}{\partial t} = -2 Ric(g(t))$$

where $Ric(g(t))$ is the Ricci curvature of the metric $g(t)$.
Fixed points of this equation are the metrics with constant curvature.
A key insight by Hamilton was that if the Ricci curvature was always positive, i.e. $Ric(g(t))> 0$ then the manifold $M$ would become a point in finite time.
If we introduce a lower bound for the diameter of the manifold, we would get constant positive curvature everywhere, and hence have a sphere by the discussion earlier.
Hence we can define the Ricci flow on an interval $[0, T)$ where $T$ is dependent on the initial metric.

\begin{example}
Let $M$ be the sphere with radius $r$ in $\mathbb{R}^3$.
Then $g_{ij} = r^2\hat{g}_{ij}$ where $\hat{g}_{ij}$ is the metric for the unit sphere $S^3$.
The Ricci tensor $Ric_{ij} = 2\hat{g}_{ij}$ is independent of $r$.
Hence the Ricci flow becomes $\frac{dr^2}{dt} = -2\cdot 2$, which has a solution

$$r^2(t) = r^2(0)-2\cdot2t$$

Hence $M$ collapses to a point in finite time.
\end{example}

If however the initial metric is not positive, and we have a more complicated topology, for example in a complicated connected sum, we can get what we call finite time singularities forced by the topology.

\begin{example}
The simplest example comes from letting $(M, g)$ be a closed Riemannian Einstein manifold.
A manifold is called an Einstein manifold if there exists a $\lambda$ such that $Ric(g(t)) = \lambda g(t)$.
Then the equation $g_t = (1-2\lambda t)g$ is a Ricci flow with $g_0 = g$.
We se this because

$$\frac{\partial g_t}{\partial t}=-2\lambda g = -2 Ric(g(t)) = -2Ric(g_t(t)).$$

If we let $\lambda> 0$ then $1-2\lambda t < 1$ when $t>0$.
Hence we need $t<\frac{1}{2}\lambda$ in order for $g_t$ to be a Riemannian metric.
This means we get a singularity in finite time.
\end{example}

To solve this problem, i.e. having these nasty singularities, Hamilton introduced Ricci flow with surgery.

\subsection{Ricci flow with surgery}

\textbf{Slogan:} Ricci flow with surgery is like Ricci flow, except we are allowed to surgically cut away finite time singularities during the process.

If we have a finite amount of singularities, we can ``split'' $[0, T)$ into a finite number of disjoint intervals $[0, T_1), [T_1, T_2), \ldots, [T_{n-1}, T_n)$.
Now the manifold changes with the Ricci flow discontinuously only finitely many times.

The key insight of Perelman was that if these singularities appear in finite time they must look like spheres or cylinders, i.e. $\mathbb{R}\times S^2$ or $S^3.$
These manifolds we can easily cut away and continue the Ricci flow on the components we get.
Perelman proved that this Ricci flow, where we are allowed to surgically remove singularities, also converge to a point in finite time for simply connected compact 3-manifolds.

In fact he proved something even stronger.
We don't even need simply connected, only that the fundamental group of the manifold is a free product of finite groups and infinite cyclic groups.
This condition essentially means that if we decompose our manifold $M$ into its prime decomposition, then none of the components are weird and difficult manifolds.
This means that all the geometric components of $M$ have Thurston geometries based on the $\mathbb{R}\times S^2$ and $S^3$ geometries.
Perelman also used an extended method of infinite time to prove the more general Thurston geometrization theorem, which has the Poincaré conjecture as a consequence as well.

So, lets devise a cook-book strategy for showing that any simply connected closed 3-manifold is actually the 3-sphere.
\begin{enumerate}
    \item Start by running Ricci flow on $M$. This will produce several spheres, connected by hair-like strands.
    \item Cut these strands off and continue the Ricci flow on the components.
    \item Repeat this until we (by diameter restrictions) only have disconnected spheres left.
    \item The connected sum of these is a sphere, and since the original manifold was connected, $M$ also has to have been a sphere all along.
\end{enumerate}

\section{Generalizations and related problems}

Some related problems of this theorem were actually proven before the Poincaré conjecture itself.
The same statement was actually proven in all dimensions except for $n=4$, i.e. it was known that every homotopy $n$-sphere is homeomorphic to $S^n$ for $0< n\neq 4$.
For $n=1, 2$ these are quite easy problems, but there was little belief in that this should hold for $n\geq 5$.
The topology community was quite surprised when Stephen Smale proved it to hold for $n\geq 5$ in 1961.
The case $n=4$ was proven in 1982 by Michael Freedman.

We could also try to do the same statement in other categories of manifolds.

So, fix a category $\mathcal{C}$  of manifolds, i.e. $TopMan$, $Diff$ or $PLMan$.
The generalized Poincaré conjecture states that for every $n$, any object in $\mathcal{C}$ homotopy equivalent to the $n$-sphere is also isomorphic, in $\mathcal{C}$, to the $n$-sphere.
The normal Poincaré conjecture was the last piece of this theorem for $\mathcal{C} = TopMan$, hence the generalized theorem is true in this setting.

For smooth manifolds the theorem is false in general, due to Milnor proving the existence of exotic spheres when $n=7$.
It is however true for $n = 1, 2, 3, 5$ and $6$ .
It is still an open problem weather it holds in dimension $4$.
This is often called the smooth Poincaré conjecture.
It is however believed to be false by many in the field.
For $\mathcal{C} = PLMan$ the case in dimension $4$ is proven to be equivalent to the differential case, and is hence also still open.
It is however true for all $n\neq 4$.