\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsthm}
%\usepackage{a4wide}
%\usepackage{enumerate}

\newcommand{\R}{\mathbb{R}}
\newcommand{\Z}{\mathbb{Z}}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}[theorem]{Proposition}
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}
\newtheorem*{remarkn}{Remark}

\begin{document}

\section{Notes on {\tt valuations.lean}}

We define {\tt linear\_ordered\_comm\_group} and {\tt linear\_ordered\_comm\_monoid} to be a commutative group / monoid with a linear order satisfying $a\leq b\implies ca \leq cb$. Within the namespace {\tt linear\_ordered\_comm\_group} we prove some basic lemmas.

We then define {\tt is\_convex}, a property of subgroups of a linearly ordered commutative group. A subgroup $H$ is convex if whenever $x\leq z\leq y$ and $x,y\in H$ we have $z\in H$. An example to keep in mind is that if $\mathbb{R}^2$ has the lexicographic order $(a,b)< (c,d)\iff a<c \lor (a=c \land b<d)$ then the subgroup $$\{0\}\times\mathbb{R}$$ is convex. The kernel of an order-preserving group homomorphism is shown to be convex (an example would be the projection onto the first factor in the $\mathbb{R}^2$ example above).

The height of a linearly ordered commutative group is the number of proper convex subgroups. For example one can check that $\mathbb{R}^2$ above has height~2.

The construction of a totally ordered monoid $\Gamma\cup\{0\}$ from a totally ordered group $\Gamma$ is done using the {\tt option} function -- the ``extra'' element {\tt none} is identified with zero. It is proved that this extension of a linearly ordered group is a linearly ordered monoid. All of this happens within the {\tt linear\_ordered\_comm\_group} namespace.

We then define a valuation on a commutative ring, taking values in the monoid associated to a linearly ordered commutative group. Within the {\tt is\_valuation} namespace we prove some basic results about valuations. For some reason {\tt is\_valuation} is a typeclass. Some basic lemmas about valuations are proved, including the fact that the support of a valuation is a prime ideal.
\end{document}


\section{Results}
%DONE – Describe your experimental protocol (proportions used to divide the data into training, validation and test sets, data preprocessing, etc.).
The COIL100 dataset contains 100 different object. From this dataset, 30 objects were selected randomly to be the labeled examples. The other 70 objects were used for the video dataset. The remaining 30 objects were separated into three datasets. For each object, 4 angles were used for the training (0, 90, 180, 270 degrees) and 4 angles were used for the validation (45, 135, 225, 315 degrees). The rest of the angles were used as test data.

Since the article mentioned the pictures were 72X72 pixels, the images from the dataset were resized to this format prior to any experiment. The images were converted into grayscale format. The intra-image mean was substracted for each image. Each pixel was then divided by the intra-image standard deviation.

\subsection{Results for different hyper-parameters}

The results for different hyper-parameters are presented in the table~\ref{tab:results}. They were all executed with a look-ahead of 10 epochs. It is interesting to note that the validation dataset is harder than the test dataset for most of the configurations. This is probably due to the fact that the validation angles were chosen to be the fartest from the training angles.

\begin{table}[f]
\label{tab:results}
\small
\begin{tabular}{@{}rrrrrrrrrrr@{}}
\toprule
\multicolumn{1}{l}{lr1} & \multicolumn{1}{l}{lr2} & \multicolumn{1}{l}{dc} & \multicolumn{1}{l}{sizes} & \multicolumn{1}{l}{best\_it} & \multicolumn{1}{l}{train1} & \multicolumn{1}{l}{valid1} & \multicolumn{1}{l}{test1} & \multicolumn{1}{l}{train2} & \multicolumn{1}{l}{valid2} & \multicolumn{1}{l}{test2} \\ \midrule
0.01 & 0.05 & 0.0E+00 & {[}12,48,176,672{]} & 73 & 0.058 & 0.358 & 0.233 & 0.278 & 1.254 & 0.859 \\
0.01 & 0.07 & 0.0E+00 & {[}12,48,176,672{]} & 15 & 0.858 & 0.875 & 0.878 & 3.343 & 3.349 & 3.348 \\
0.01 & 0.08 & 0.0E+00 & {[}12,48,176,672{]} & 14 & 0.875 & 0.875 & 0.880 & 3.351 & 3.357 & 3.355 \\
0.01 & 0.1 & 0.0E+00 & {[}12,48,176,672{]} & 72 & 0.058 & 0.367 & 0.239 & 0.307 & 1.267 & 0.885 \\
0.015 & 0.05 & 0.0E+00 & {[}12,48,176,672{]} & 53 & 0.083 & 0.358 & 0.241 & 0.281 & 1.296 & 0.883 \\
0.015 & 0.07 & 0.0E+00 & {[}12,48,176,672{]} & 8 & 0.858 & 0.875 & 0.871 & 3.367 & 3.371 & 3.370 \\
0.015 & 0.08 & 0.0E+00 & {[}12,48,176,672{]} & 52 & 0.075 & 0.350 & 0.240 & 0.341 & 1.261 & 0.900 \\
0.015 & 0.1 & 0.0E+00 & {[}12,48,176,672{]} & 7 & 0.858 & 0.883 & 0.870 & 3.373 & 3.377 & 3.376 \\
0.02 & 0.05 & 0.0E+00 & {[}12,48,176,672{]} & 56 & 0.017 & 0.317 & 0.171 & 0.065 & 1.185 & 0.681 \\
0.02 & 0.1 & 0.0E+00 & {[}12,48,176,672{]} & 56 & 0.017 & 0.333 & 0.184 & 0.059 & 1.231 & 0.730 \\
0.025 & 0.01 & 0.0E+00 & {[}10,40,160,640{]} & 52 & 0.025 & 0.325 & 0.184 & 0.103 & 1.356 & 0.787 \\
0.025 & 0.01 & 1.0E-07 & {[}10,40,160,640{]} & 53 & 0.017 & 0.325 & 0.184 & 0.082 & 1.301 & 0.760 \\
0.025 & 0.05 & 0.0E+00 & {[}10,40,160,640{]} & 57 & 0.008 & 0.317 & 0.179 & 0.039 & 1.280 & 0.716 \\
0.025 & 0.05 & 1.0E-07 & {[}10,40,160,640{]} & 42 & 0.050 & 0.333 & 0.201 & 0.250 & 1.412 & 0.900 \\
0.025 & 0.08 & 0.0E+00 & {[}10,40,160,640{]} & 44 & 0.042 & 0.317 & 0.190 & 0.202 & 1.345 & 0.850 \\
0.025 & 0.08 & 1.0E-07 & {[}10,40,160,640{]} & 51 & 0.025 & 0.333 & 0.177 & 0.112 & 1.250 & 0.744 \\
0.025 & 0.2 & 0.0E+00 & {[}10,40,160,640{]} & 54 & 0.017 & 0.325 & 0.189 & 0.065 & 1.242 & 0.734 \\
0.025 & 0.2 & 1.0E-07 & {[}10,40,160,640{]} & 43 & 0.042 & 0.342 & 0.207 & 0.203 & 1.401 & 0.891 \\
0.03 & 0.05 & 0.0E+00 & {[}12,48,176,672{]} & 44 & 0.025 & 0.300 & 0.173 & 0.116 & 1.229 & 0.742 \\
0.03 & 0.07 & 0.0E+00 & {[}12,48,176,672{]} & 50 & 0.025 & 0.317 & 0.172 & 0.053 & 1.160 & 0.699 \\
\textbf{0.03} & \textbf{0.08} & \textbf{0.0E+00} & \textbf{{[}12,48,176,672{]}} & \textbf{43} & \textbf{0.025} & \textbf{0.283} & \textbf{0.167} & \textbf{0.115} & \textbf{1.166} & \textbf{0.719} \\
0.03 & 0.1 & 0.0E+00 & {[}12,48,176,672{]} & 47 & 0.033 & 0.283 & 0.171 & 0.109 & 1.127 & 0.714 \\
0.05 & 0.01 & 0.0E+00 & {[}10,40,160,640{]} & 37 & 0.017 & 0.325 & 0.201 & 0.048 & 1.417 & 0.864 \\
0.05 & 0.01 & 1.0E-07 & {[}10,40,160,640{]} & 2 & 0.692 & 0.717 & 0.727 & 3.389 & 3.391 & 3.390 \\
0.05 & 0.05 & 0.0E+00 & {[}10,40,160,640{]} & 32 & 0.025 & 0.325 & 0.209 & 0.213 & 1.669 & 1.063 \\
0.05 & 0.05 & 1.0E-07 & {[}10,40,160,640{]} & 41 & 0.000 & 0.308 & 0.164 & 0.011 & 1.234 & 0.713 \\
0.05 & 0.08 & 0.0E+00 & {[}10,40,160,640{]} & 30 & 0.025 & 0.333 & 0.207 & 0.262 & 1.679 & 1.092 \\
0.05 & 0.08 & 1.0E-07 & {[}10,40,160,640{]} & 2 & 0.700 & 0.717 & 0.729 & 3.389 & 3.391 & 3.390 \\
0.05 & 0.2 & 0.0E+00 & {[}10,40,160,640{]} & 35 & 0.025 & 0.317 & 0.190 & 0.108 & 1.295 & 0.818 \\
0.05 & 0.2 & 1.0E-07 & {[}10,40,160,640{]} & 40 & 0.025 & 0.317 & 0.193 & 0.130 & 1.361 & 0.896 \\
0.09 & 0.01 & 0.0E+00 & {[}10,40,160,640{]} & 2 & 0.650 & 0.717 & 0.729 & 3.387 & 3.390 & 3.389 \\
0.09 & 0.01 & 1.0E-07 & {[}10,40,160,640{]} & 2 & 0.633 & 0.717 & 0.724 & 3.387 & 3.390 & 3.389 \\
0.09 & 0.05 & 0.0E+00 & {[}10,40,160,640{]} & 2 & 0.617 & 0.708 & 0.699 & 3.387 & 3.390 & 3.389 \\
0.09 & 0.05 & 1.0E-07 & {[}10,40,160,640{]} & 11 & 0.633 & 0.633 & 0.638 & 2.454 & 2.538 & 2.503 \\
0.09 & 0.08 & 0.0E+00 & {[}10,40,160,640{]} & 2 & 0.642 & 0.717 & 0.715 & 3.387 & 3.390 & 3.389 \\
0.09 & 0.08 & 1.0E-07 & {[}10,40,160,640{]} & 2 & 0.642 & 0.733 & 0.722 & 3.386 & 3.390 & 3.389 \\
0.09 & 0.2 & 0.0E+00 & {[}10,40,160,640{]} & 2 & 0.642 & 0.742 & 0.724 & 3.387 & 3.390 & 3.390 \\
0.09 & 0.2 & 1.0E-07 & {[}10,40,160,640{]} & 2 & 0.617 & 0.733 & 0.716 & 3.387 & 3.390 & 3.389 \\ \bottomrule
\end{tabular}
\caption{Results for different hyper-parameters. The best value is in bold.}
\end{table}

\subsection{Results details}
%DONE – Present any results that validate the correctness of your implementation.
The figure~\ref{fig:results_bestrun} presents the training and validation error for the best hyper-parameters. It is of interest to note the small decrease of the classification error at the beginning of the optimization. This pattern was repeated with almost every selection of hyper-parameters. This effect was accounted for by increasing the value of the look-ahead.

\begin{figure}[htbf]
\label{fig:results_bestrun}
\includegraphics[width=0.48\textwidth]{result1.png}
\includegraphics[width=0.48\textwidth]{result2.png}
\caption{Training and validation error of the training procedure with the best validation error.}
\end{figure}

\subsection{Comparison}
%TODO – Present the results of your algorithm on the test set and make a comparison with an alternative, simple baseline.

In order to demonstrate performance of the algorithm, the temporal coherence CNN was compared against a CNN without the temporal coherence regularisation. The results for different sets of hyper-parameters are shown in table~\ref{tab:cnn}. As shown in this table, it is possible to see that the best value in validation using the temporal coherence CNN and the baseline CNN are similar. However, the size of the neural network needed to achieve these performances is much smaller with temporal coherence. Also, there are more sets of hyper-parameters that achieve interesting performance with this method than baseline CNN.

\begin{table}[f]
\begin{tabular}{@{}rrrrrrrrr@{}}
\toprule
\multicolumn{1}{l}{lr} & \multicolumn{1}{l}{sizes} & \multicolumn{1}{l}{best\_it} & \multicolumn{1}{l}{train1} & \multicolumn{1}{l}{valid1} & \multicolumn{1}{l}{test1} & \multicolumn{1}{l}{train2} & \multicolumn{1}{l}{valid2} & \multicolumn{1}{l}{test2} \\ \midrule
0.01 & {[}15,60,240,1700{]} & 9 & 0.833 & 0.867 & 0.851 & 3.383 & 3.386 & 3.385 \\
0.01 & {[}2,8,32,300{]} & 1 & 0.942 & 0.967 & 0.962 & 3.401 & 3.401 & 3.401 \\
0.01 & {[}200,100,50,25{]} & 1 & 0.892 & 0.908 & 0.908 & 3.401 & 3.401 & 3.401 \\
0.01 & {[}4,16,64,600{]} & 1 & 0.933 & 0.933 & 0.933 & 3.401 & 3.401 & 3.401 \\
0.01 & {[}8,32,128,1000{]} & 28 & 0.817 & 0.833 & 0.853 & 3.346 & 3.353 & 3.351 \\
0.03 & {[}100,200,400,1000{]} & 33 & 0.250 & 0.417 & 0.383 & 0.783 & 1.743 & 1.355 \\
0.03 & {[}15,60,240,1700{]} & 27 & 0.408 & 0.483 & 0.485 & 1.466 & 1.877 & 1.711 \\
0.03 & {[}2,8,32,300{]} & 5 & 0.925 & 0.958 & 0.948 & 3.395 & 3.396 & 3.396 \\
0.03 & {[}200,100,50,25{]} & 10 & 0.808 & 0.875 & 0.851 & 3.388 & 3.389 & 3.389 \\
0.03 & {[}4,16,64,600{]} & 4 & 0.933 & 0.933 & 0.933 & 3.394 & 3.395 & 3.395 \\
0.03 & {[}50,100,200,500{]} & 37 & 0.192 & 0.433 & 0.353 & 0.772 & 1.562 & 1.238 \\
0.03 & {[}8,32,128,1000{]} & 10 & 0.750 & 0.783 & 0.784 & 3.352 & 3.359 & 3.357 \\
\textbf{0.05} & \textbf{{[}100,200,400,1000{]}} & \textbf{42} & \textbf{0.017} & \textbf{0.275} & \textbf{0.163} & \textbf{0.070} & \textbf{1.249} & \textbf{0.755} \\
0.05 & {[}100,200,400,1000{]} & 35 & 0.000 & 0.325 & 0.186 & 0.002 & 1.683 & 0.942 \\
0.05 & {[}15,60,240,1700{]} & 8 & 0.725 & 0.717 & 0.719 & 3.218 & 3.228 & 3.225 \\
0.05 & {[}2,8,32,300{]} & 24 & 0.642 & 0.617 & 0.643 & 2.527 & 2.600 & 2.574 \\
0.05 & {[}200,100,75,50{]} & 19 & 0.483 & 0.550 & 0.530 & 1.357 & 1.914 & 1.669 \\
0.05 & {[}200,100,75,50{]} & 14 & 0.717 & 0.692 & 0.718 & 3.011 & 3.015 & 3.015 \\
0.05 & {[}4,16,64,600{]} & 8 & 0.842 & 0.883 & 0.874 & 3.367 & 3.371 & 3.370 \\
0.05 & {[}5,20,80,400{]} & 28 & 0.275 & 0.492 & 0.421 & 0.913 & 1.834 & 1.463 \\
0.05 & {[}5,20,80,400{]} & 7 & 0.850 & 0.892 & 0.873 & 3.376 & 3.379 & 3.379 \\
0.05 & {[}8,32,128,1000{]} & 12 & 0.708 & 0.725 & 0.722 & 3.073 & 3.086 & 3.081 \\
0.07 & {[}100,200,400,1000{]} & 11 & 0.675 & 0.675 & 0.690 & 2.690 & 2.791 & 2.757 \\
0.07 & {[}15,60,240,1700{]} & 6 & 0.658 & 0.692 & 0.686 & 3.246 & 3.255 & 3.252 \\
0.07 & {[}2,8,32,300{]} & 16 & 0.717 & 0.725 & 0.738 & 2.766 & 2.810 & 2.793 \\
0.07 & {[}200,100,50,25{]} & 3 & 0.825 & 0.850 & 0.860 & 3.396 & 3.397 & 3.397 \\
0.07 & {[}4,16,64,600{]} & 25 & 0.492 & 0.583 & 0.593 & 1.754 & 2.170 & 1.996 \\
0.07 & {[}50,100,200,500{]} & 36 & 0.025 & 0.292 & 0.183 & 0.211 & 1.350 & 0.878 \\
0.07 & {[}8,32,128,1000{]} & 9 & 0.683 & 0.683 & 0.687 & 3.065 & 3.078 & 3.073 \\
0.09 & {[}15,60,240,1700{]} & 7 & 0.667 & 0.683 & 0.691 & 2.871 & 2.879 & 2.876 \\
0.09 & {[}2,8,32,300{]} & 12 & 0.767 & 0.800 & 0.794 & 3.093 & 3.105 & 3.103 \\
0.09 & {[}200,100,50,25{]} & 3 & 0.800 & 0.858 & 0.844 & 3.395 & 3.396 & 3.396 \\
0.09 & {[}4,16,64,600{]} & 4 & 0.750 & 0.800 & 0.780 & 3.380 & 3.384 & 3.383 \\
0.09 & {[}8,32,128,1000{]} & 3 & 0.642 & 0.750 & 0.713 & 3.378 & 3.383 & 3.381 \\ \bottomrule
\end{tabular}
\caption{Results for the normal convolutional-neural network}
\label{tab:cnn}
\end{table}


\clearpage
\subsection{C Function Call} % (fold)
\label{sub:c_function_call}

\csyntax{csynt:function-decl-function-call}{a Function Call}{function-decl/function-call}

\csection{\ccode{clst:test-fn-call}{Example of Function Calls.}{code/c/storing-using-data/test-fn-calls.c}}

\mynote{
\begin{itemize}
  \item A C function call is similar to a \nameref{sub:procedure call}.
  \item You use the name of the \nameref{sub:function}, its identifier, to indicate which function is called.
  \item Following the Function's name is the list of \emph{arguments}, these are the values (or variables) that are being passed to the called Function.
  \item The return type of the Function determines where the Function may be called.
  \begin{itemize}
    \item Procedure, \texttt{void} Functions, can only be called in a \nameref{sub:procedure call} \nameref{sub:statement}.
    \item Other Functions can be used in Expressions, see \nameref{sub:expressions_with_variables_}. In these cases the type of data returned by the Function will determine the type of the Function Call.
  \end{itemize}
  \item In Listing \ref{clst:test-fn-call} the values of the inner function calls are passed to the arguments of the outer calls. This means that \texttt{square(5)} is calculated first then \texttt{sqaure(4)}. The results of these two Function Calls are then passed as the \emph{arguments} into the call to the \texttt{sum} Function. In this case the Function call will be \texttt{sum(25, 16)} with \texttt{25} being the result returned by \texttt{square(5)} and \texttt{16} being the result returned by \texttt{square(4)}.
\end{itemize}
}
% subsection c_procedure_declaration (end)


\subsection{Multi-parameter dialogue}
In code 18 we examined above,
user-interface is very poor since before calculation the user must input\ldots
click\ldots input\ldots click\ldots for total of four times.
To ease this exhausting series of input process,
you could create a dialog box that asks the user to input several parameters at once.
We use \ilcom{Dialog} functions.

\lstinputlisting[morekeywords={*, Dialog, create, addMessage, addNumber, addCheckbox, show, getNumber, getCheckbox}]{code/code18_5.ijm}

%figure
\begin{figure}[htbp]
\begin{center}
\includegraphics[scale=0.6]{fig/fig2421_GenDialog.png}
\caption{Custom Parameter Input Dialog}
\label{figGenericDialog}
\end{center}
\end{figure}

Line 2 to 9 creates a dialog box that has multiple input boxes that looks like Fig. \ref{figGenericDialog}.

\begin{itemize}
\item Line 3 defines the title of the dialog window.

\item Line 4 texts will be shown within the window.

\item Line 5 to 11 defines the parameter input fields. Fields appear in the dialog box in the order of lines with Dialog.addNumber function in the macro. When you press OK button in the dialog box, parameter will be stored in the same order.

\item Line 15 to 19 These values then are assigned to each variable by Dialog.getNumber().

\item Line 20 Checkbox is independent from these number fields and the value is returned by \ilcom{Dialog.getCheckbox()}. When you check the check box, the return value is 1. If not, the return value is 0. We use this Boolean value (true or false)  to decide if the scale will be multiplied to the distance [pixel] in Line 24.

\item Line 24 This if-statement does not have braces. Such simplification is possible if there is one line when "if" is true.
\end{itemize}

You may also realize that the if statement in line 24 (and also in Line 28) does not have comparison like == or <  or so on. This is because \ilcom{switchscale} takes only 0 or 1 (\textbf{boolean}), which are interpreted as true ( \ilcom{switchscale} = 1) or false ( \ilcom{switchscale} = 0). So even without comparison, \ilcom{switchscale} is already a decision.

\begin{indentexercise}{1}
Modify Code 5 so that two parameters are asked in a single dialog box.
\end{indentexercise}


%% LyX 2.0.6 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}
\geometry{verbose,tmargin=1cm,bmargin=2cm,lmargin=2.5cm,rmargin=2.5cm,headheight=1cm,headsep=1cm,footskip=1.5cm}
\setlength{\parindent}{0bp}
\usepackage{babel}
\usepackage{float}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{setspace}
\PassOptionsToPackage{normalem}{ulem}
\usepackage{ulem}
\usepackage[unicode=true,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
 {hyperref}

%%%%%%%%%% Easily edit these definitions:
\def\LabNumber{II}
\def\year{2013}
%%%%%%%%%%
\hypersetup{pdftitle={Lab Exercise \LabNumber: Introduction to Binary Stars},
 pdfauthor={Amit Vishwas},
 pdfsubject={Astronomy 1103}}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

\makeatother

\begin{document}
\begin{table}[H]
\begin{doublespace}
\begin{centering}
\uline{Lab \LabNumber ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}
\par\end{centering}
\end{doublespace}

\centering{}%
\begin{tabular}{lclc}
 &  &  & \tabularnewline
Name: & ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ & Partner(s): & ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\tabularnewline
 &  &  & \tabularnewline
Student ID\#: &  & Date: & \tabularnewline
\end{tabular}
\end{table}

\vspace{0.15in}

\begin{center}
{\LARGE{Lab Exercise \LabNumber : Introduction to Binary Stars}}
\par\end{center}{\LARGE \par}

\medskip{}

\section{Purpose}

To allow you to investigate the orbital properties of binary star systems and how the masses of stars are determined.

\section{Introduction to Binary Stars}

One of the fundamental properties that we want to know about a star is its mass. The only way that we can determine the masses of stars is to study the orbital motions of binary stars. Application of the
laws of celestial mechanics allows us to calculate the masses of the stars from measures of their orbital periods, sizes and velocities.

\smallskip{}

Five to ten percent of the stars visible to us are visual binaries. Careful spectroscopic studies of nearby solar-type stars show that about two thirds of them have stellar companions. We estimate that
roughly half of all stars in the sky are indeed members of binaries.

\smallskip{}

% % Add location of the python program here
Using the Orbit Simulator available on the lab computer, we will experiment with many of the observable properties of binary star systems.

\smallskip{}
\pagebreak{}

\begin{doublespace}
\begin{center}
\uline{Lab \LabNumber ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}
\par\end{center}
\end{doublespace}

\section{Binary Stars}

\subsection{Mass Ratios and the Center of Mass }

Start with the eccentricity and inclination set to zero. Do this by dragging the sliders labeled \textit{Ecc} and \textit{Inc} to 0. Since a circle is just an ellipse with eccentricity equal to zero, that means that the orbits are circular.
Set the mass of each body to be equal to 1 (sliders $m_{1}$ and $m_{2}$ each show masses in units of solar mass, $M_{\circledcirc}$). For $m_{1}=m_{2}$, the ratio, $\frac{m_{1}}{m_{2}}$, is one. Now vary the mass ratio. When the mass ratio is greater than one, the red star (with mass $m_{1}$) is more massive and the blue one (with mass $m_{2}$) is the less massive. Answer the following Questions:

\vspace{0.2in}

\begin{enumerate}
\item Vary the Mass Ratio

\begin{enumerate}
\item What happens to the orbit of the more massive star as the ratio of the masses $\frac{m_{1}}{m_{2}}$ grows?
\end{enumerate}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}\vspace{0.2in}
\rule[0.5pt]{0.75\paperwidth}{0.3pt}\vspace{0.1in}

\item Let\textquoteright{}s digress from the simulator for a moment. Assume we have observations of two binary star systems. In both systems,
the orbital period is eight years. For one system, the mass ratio is one; for the other, it is three. Using the Kepler\textquoteright{}s Third Law, calculate the semimajor axis in each system?

\begin{enumerate}
\item \textbf{Binary \#1:} P = 8 yr , $m_{1}=m_{2}$ = 1 $M_{\circledcirc}$ , a = \rule[0.5pt]{0.05\paperwidth}{0.3pt} AU\vspace{0.2in}

\item \textbf{Binary \#2:} P = 8 yr , $m_{1}=3m_{2}$; $m_{2}$ = 1 $M_{\circledcirc}$
, a = \rule[0.5pt]{0.05\paperwidth}{0.3pt} AU
\end{enumerate}

Based on your calculations, how does the semimajor axis change with varying mass ratio for binaries with the same period and $m_{2}$ fixed?

\vspace{0.1in}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}\vspace{0.1in}

\item The Sun is about 1000 times more massive than Jupiter, the most massive of the planets. Is the center of mass of the Solar System closer to the Sun or to Jupiter?

\rule[0.5pt]{0.75\paperwidth}{0.3pt}\vspace{0.1in}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}\vspace{0.2in}

\end{enumerate}
\pagebreak{}

\begin{doublespace}
\begin{center}
\uline{Lab II ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}
\par\end{center}
\end{doublespace}

\subsection{Eccentricity }

Notice that you can change the eccentricity from 0 to 0.9. Highly eccentric orbits are very rare in nature. In the Solar System, most of the planets
follow almost circular orbits. The eccentricity of the Earth\textquoteright{}s orbit is 0.0167; the most eccentric of the planetary orbits is that of Pluto with e = 0.2484. Now, answer the following questions:

\vspace{0.2in}

\begin{enumerate}
\item Set the mass ratio to 100:1 and the eccentricity to 0. Watch the orbit. Then change the eccentricity to 0.1, 0.2, 0.3 and 0.4 and, each time,
watch what happens to the orbits. We can now define two extreme points on the less massive star\textquoteright{}s orbit. \textbf{Periastron}
occurs when the two stars are closest together. \textbf{Apastron} occurs when the two stars are furthest apart. In the space below, sketch the case for $e=0.3$ and label on your sketch the locations
of \textbf{Periastron} and \textbf{Apastron}. Also, label the locations of the two stars $m_{1}$ and $m_{2}$ and the center of mass. (Tip: You can pause the motion of the stars by clicking anywhere on the window)

\begin{enumerate}
\item Case: $m_{1}=100m_{2}$ , $e=0.3$
\end{enumerate}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}

\vspace{1in}

\item Leave the eccentricity at 0.3. Now set the mass ratio to 1:1. Again, sketch below the orbits of the two stars. Indicate where the two stars
will be when $m_{1}$ is at periastron. Locate and label the center of mass.

\begin{enumerate}
\item Case: $m_{1}=m_{2}$ , $e=0.3$
\end{enumerate}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}

\vspace{1in}

\item When the blue star is at periastron, where is the red star in its orbit?

\vspace{0.1in}
\rule[0.5pt]{0.75\paperwidth}{0.3pt}\vspace{0.1in}

\begin{enumerate}
\item When the blue star is at apastron, where is the red star in its orbit?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\item What can you say about the distances of the two stars from the center of mass at periastron?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\end{enumerate}

\pagebreak{}

\uline{\hspace{-0.4in}Lab \LabNumber ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}\vspace{0.3in}

\item Now change the mass ratio to 3:1. Sketch the orbit below. Show the two stars\textquoteright{} locations at apastron. Mark the center of mass.

\begin{enumerate}
\item Case: $m_{1}=3m_{2}$ , $e=0.3$
\end{enumerate}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}

\vspace{1in}

\item Watch the less massive star. Does it travel at the same speed at all points in its orbit?

\vspace{0.1in}
\rule[0.5pt]{0.75\paperwidth}{0.3pt}
\begin{enumerate}
\item When does it travel fastest?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\item Which of Kepler\textquoteright{}s laws predicts this? Explain.

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\item If the orbit were circular, what can you say about periastron and apastron?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\item Does the speed of the bodies change in the same way as when eccentricity is set to e = 0.3?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\end{enumerate}
\end{enumerate}

\subsection{Inclination}

Up until now, we have been viewing orbits that lie flat in the plane of the computer screen. In our simulation, the screen is like the plane of the sky. Of course, real binary star systems can orbit in
planes that have any orientation with respect to the plane of sky as viewed from the Earth, and so we have to introduce another variable:
the \textbf{\textit{Inclination}} of the true orbit with respect to the sky. According to convention, the inclination is zero degrees when the orbit is flat in the plane of the sky, i.e., perpendicular
to our line of sight. When the orbit is inclined 90 degrees with respect to the plane of the sky, it lies in a plane aligned with the line of sight. So far, we have only dealt with the $0^{\circ}$ case. Notice the \textit{Top View} available on the top-left of the screen.
It allows you to view the orbit from the top down, as if it were flat in the plane of the sky, no matter what the inclination is.

\vspace{0.1in}

When the inclination is $90^{\circ}$, a star passing exactly in front of its companion may block out the light we see from the companion. When this happens, we say that the companion is eclipsed, and the
system is called an \textbf{Eclipsing Binary}. For such eclipses to be seen, the inclination must be close to or exactly $90^{\circ}$. Lets try answering the questions on the next page.

\pagebreak{}

\begin{doublespace}
\begin{center}
\uline{Lab \LabNumber ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}
\par\end{center}
\end{doublespace}

\vspace{0.2in}

\begin{enumerate}
\item Set the mass ratio equal to 3:1 and the eccentricity equal to zero.
Remind yourself of what the orbit should look like; this is the true orbit of the system. Now vary the inclination angle. What happens to a true circular orbit when it is viewed with a non-zero inclination
angle?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\item Now set the eccentricity equal to 0.3 and the inclination angle to $45^{\circ}$. Watch both the view as seen by Observer and the \textquotedbl{}Top view\textquotedbl{} (on the top-left). The top
view is the true orbit. In the space below, sketch both views.

\begin{enumerate}
\item Case: $m_{1}=3m_{2}$ , $e=0.3$ , $i=45^{\circ}$
\end{enumerate}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}

\vspace{1in}

\end{enumerate}
\textbf{True Orbit - Apparent Orbit}

\vspace{0.1in}

\begin{enumerate}
\item [3.]\setcounter{enumi}{3}How does the distance from either star to the center of mass at apastron vary as the inclination changes? (Tip: Click anywhere on the window to pause the simulation)

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\item Now set the inclination to $90^{\circ}$. Sketch the apparent orbit.

\begin{enumerate}
\item Case: $m_{1}=3m_{2}$ , $e=0.3$ , $i=90^{\circ}$
\end{enumerate}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}

\vspace{1in}

\item Set the inclination to $30^{\circ}$. Sketch the apparent orbit.

\begin{enumerate}
\item Case: $m_{1}=3m_{2}$ , $e=0.0$ , $i=30^{\circ}$
\end{enumerate}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}

\vspace{1in}

\end{enumerate}
\pagebreak{}

\begin{doublespace}
\begin{center}
\uline{Lab \LabNumber ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}
\par\end{center}
\end{doublespace}

\vspace{-0.1in}
\subsection{Radial Velocity}

The radial velocity is the speed of the star towards or away from us, that is, along our line of sight to the star. In the simulator program, set $m_{1}=3m_{2}$ and eccentricity, $ecc = 0$ and inclination, $Inc = 90^{\circ}$

\vspace{0.1in}

During each orbital period, each star has to travel around its orbit once. Since the orbital period of each is the same but the distance each star must travel in order to make one circuit of its orbit is
different, the speed of travel is different for the two stars.

\vspace{0.1in}

Notice that when we measure the maximum radial velocity, also referred to as the \textit{amplitude of the radial velocity} curve and designated
$K$, we really measure the true velocity $V$ modified by the inclination:
$V\, sin\,(i)$. Answer the following questions now:

\vspace{0.1in}

\begin{enumerate}
\item Which star has the greatest maximum radial velocity, the more massive star or the less massive one?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\begin{enumerate}
\item Now vary the mass ratio and look at the maximum radial velocities of the two stars in each case. What happens when the mass ratio is
one: $m_{1}=m_{2}$?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\item What can you say in general about how the radial velocities of the two stars compare depending on their mass ratio?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\end{enumerate}
\item {}

\begin{enumerate}
\item Set the mass ratio to 3:1, the eccentricity to 0, and the inclination to $30^{\circ}$. Sketch the results and properly label the axis. Show how the velocity varies during two orbital periods. Be sure to indicate which is the curve for the less massive star and which is for the more massive one.

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{1in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\item You found in \textbf{\textit{Section 3.2 - Q5}} the location in the orbit when the star travels fastest. In the case you are displaying now, what can you say about the apparent speed of the blue star? Is it actually traveling fastest when its radial velocity is most positive? Justify your answers with a short argument.

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\end{enumerate}
\item Now change the eccentricity to 0.3, 0.5, and 0.7. What happens to the radial velocity of the blue star as the eccentricity changes? Explain why this happens.

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}\pagebreak{}

\uline{\hspace{-0.4in}Lab \LabNumber ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}\vspace{0.3in}

\item Set the eccentricity back to 0 and set the inclination to $0^{\circ}$. What does the radial velocity curve look like? Why?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.8in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\item Set the eccentricity to 0.3. Now change the inclination to $30^{\circ}$, $45^{\circ}$, $60^{\circ}$ and $90^{\circ}$. In comparison with
what you did in Q3 above, which is more critical in making the radial velocity curve change, the inclination or the eccentricity?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.8in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\end{enumerate}

\subsection{Node Angle }

The last important parameter is the orientation of the major axis of the binary relative to the line of sight, or what we call the \textbf{Node Angle}. When the node angle is set to zero the two stars are lined
up in the horizontal direction. The display shows both the top view and the view as seen by the observer. You can change the node angle by adjusting
the $Node Angle$ slider. Now set the mass ratio to 3, eccentricity to 0.5 and inclination to 0. Change the node angle to $-45^{\circ}$, $45^{\circ}$, etc. You will see what we mean by node angle. Leave the inclination at $0^{\circ}$ and return the node
angle to $0^{\circ}$.

\vspace{0.1in}

The node angle is probably the hardest concept to visualize, but we hope that this demonstration will help. When the node angle and inclination
are both $0^{\circ}$, the orbit we view from Earth (the \textbf{Apparent orbit}) is actually the true orbit. When the mass ratio is 3 and the eccentricity is 0.5, you see the two stars move in elliptical orbits around the center of mass. When you change the inclination to $30^{\circ}$, you tilt the orbit with respect to the flat computer screen (the plane of the sky in the real case). The node angle rotates the major axis of the ellipse relative to the line of sight. We start out with the node angle at $0^{\circ}$, that is, perpendicular to the line of
sight. When the node angle is $90^{\circ}$, the major axis of the ellipse is aligned along the line of sight.

\vspace{0.1in}

A good way to think about this is to draw an ellipse on a pad of paper. Hold the pad in front of you with the long axis of the ellipse oriented horizontally. To change the inclination, tilt the pad toward or away
from you. To change the node angle, rotate the pad. Be sure to understand this concept before you proceed. Ask me (your T.A.) for help if you don\textquoteright{}t understand. If all set, answer the following question.

\vspace{0.1in}

\pagebreak{}

\begin{doublespace}
\begin{center}
\uline{Lab \LabNumber ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}
\par\end{center}
\end{doublespace}
\begin{enumerate}
\item Set the inclination to $30^{\circ}$ , the mass ratio to 3:1 and the eccentricity to 0.3. Start with the node angle at $0^{\circ}$. Watch what happens to the radial velocity curve as you vary the node angle.
Sketch below the radial velocity curves over one orbital period for each of the following node angles: $0^{\circ}$, $30^{\circ}$, $45^{\circ}$,
$60^{\circ}$, $90^{\circ}$.

\begin{itemize}
\item Node Angle = $0^{\circ}$, $30^{\circ}$, $45^{\circ}$, $60^{\circ}$,
$90^{\circ}$
\item Case: $m_{1}=3m_{2}$ , $e=0.3$ , i = $30^{\circ}$
\end{itemize}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}

\vspace{6in}

\item What can you say in general about how the node angle changes the shape of the radial velocity curve?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}

\item Does the maximum radial velocity of either star change if only the node angle is changed?

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}\vspace{0.1in}

\rule[0.5pt]{0.7\paperwidth}{0.3pt}

\end{enumerate}
\pagebreak{}

\begin{doublespace}
\begin{center}
\uline{Lab \LabNumber ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}
\par\end{center}
\end{doublespace}

\subsection{The Masses of Binary Stars }

You now have found two simple ways that we can learn something about the masses of binary stars by observing their orbits:

\vspace{0.1in}

\textbf{I. }If the system is a \textbf{``visual''} binary (we can actually see two stars) so that the orbits of the two stars around the center of mass can be traced, then we can derive the sum of the masses of the two stars by applying Kepler\textquoteright{}s Third Law. Hence, for a visual binary, we can determine $(m_{1}+m_{2})$.

\vspace{0.1in}

\textbf{II.} If the system is a \textbf{``spectroscopic}'' binary (we can\textquoteright{}t see two stars but spectra indicate these are two stars) binary so that we can observe the radial velocity curves, then we can derive the ratio of the masses by comparing their radial velocity curves and, in the simplest case, their maximum radial velocities. Hence, for a spectroscopic binary, we can determine $\frac{m_{2}}{m_{1}}$.

\vspace{0.1in}

If a binary is both a visual \textbf{and} a spectroscopic system, then we can determine both $m_{1}$ and $m_{2}$ distinctly. Notice that we also have to know the distance to the binary and its period.

\vspace{0.1in}

Furthermore, we do need some idea of the eccentricity, the inclination and the node angle of the orbit, and the rules given above are somewhat
more simplistic than the true case, if for example, the node angle is much different from $0^{\circ}$.

\vspace{0.1in}

\subsection{The Orbit of Sirius}

Sirius is the brightest star in the sky. As early as 1834, Bessel noticed that its proper motion was variable, that is, it appears to be moving in a non-uniform manner. In 1844, he hypothesized that both
Sirius and Procyon were \textquotedbl{}genuine binary systems, each consisting of a visible and an invisible star\textquotedbl{}.

\vspace{0.1in}

Sirius is easily visible from Ithaca (if it\textquoteright{}s clear!) in the southern part of the sky during the observing lab. Now answer the following question:
\begin{enumerate}
\item To see what Sirius\textquoteright{} orbit looks like, set the mass ratio to 2.5:1 (it is really $2.56:1$  but let's keep it simple), the eccentricity to 0.6 (actual, $e = 0.588$) and the inclination to $45^{\circ}$ (actual, $i = 44.5^{\circ}$).
For this demonstration, set the node angle to $0^{\circ}$. Sketch below the orbit of Sirius and its less massive companion as viewed from Earth.

\begin{enumerate}
\item For Sirius: $m_{1}=2.5\, m_{2}$ , $e=0.6$ , $i=45^{\circ}$
\end{enumerate}

\rule[0.5pt]{0.75\paperwidth}{0.3pt}

\vspace{1in}

\end{enumerate}

\subsubsection*{\pagebreak{}}

\begin{doublespace}
\begin{center}
\uline{Lab \LabNumber ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}
\par\end{center}
\end{doublespace}

\subsubsection*{View from Earth}

We also know that the period of the orbit of Sirius is 50.2 years, the semimajor axis, 'a' of the true ellipse is 7.63 seconds of arc, and the parallax p is 0.375 seconds of arc. We can use this information
to derive the masses of the two stars. If we know the parallax, we can determine the distance. If we know the distance, then we can convert the angular semimajor axis to a linear measurement in AU. The semimajor axis in AU is obtained by dividing the semimajor axis in seconds of arc by the parallax:

\vspace{0.1in}

\[
a\,(\mathrm{in\;AU})=\frac{a\,(\mathrm{in\;seconds\;of\;arc})}{p\,(\mathrm{in\;seconds\;of\;arc})}
\]

\subsubsection*{The Masses of Spectroscopic Binaries}

If we know the parallax p and the semimajor axis a in seconds of arc, then we can write Kepler\textquoteright{}s Third Law as

\vspace{0.1in}

\[
m_{1}+m_{2}=\left(\frac{a^{3}}{p^{3}}\right)\frac{1}{P^{2}}
\]

where the masses are in solar masses and the period P is in years. We also know that the semimajor axis $a$ of the true orbit is the maximum separation of the two stars: $a=a_{1}+a_{2}$, where $a_{1}$ and $a_{2}$ are the semimajor axes of the individual orbits around
the center of mass of the system. The distance of each star away from the center of mass depends on its mass so that,

\vspace{0.1in}

\[
m_{1}a_{1}=m_{2}a_{2}
\]

If the inclination is not $0^{\circ}$, the observed separation of the stars is not the true separation, but is modified by the sine of the inclination. This factor is also found in the equation for radial velocity:

\vspace{0.1in}

\[
K_{1}=v_{1}sin\,(i)
\]

\[
K_{2}=v_{2}sin\,(i)
\]

\[
\frac{K_{1}}{K_{2}}=\frac{m_{1}}{m_{2}}=\frac{v_{1}}{v_{2}}
\]

where K is the amplitude of the radial velocity curve. Notice that the previous equations have involved the ratio of the two masses, not the masses themselves. From the spectroscopic data alone, the
total mass of the system cannot be derived. Answer the following questions:

\vspace{0.1in}

\begin{enumerate}
\item The semimajor axis of Sirius\textquoteright{} orbit is: \rule[0.5pt]{0.05\paperwidth}{0.3pt}
A.U.

\begin{enumerate}
\item Estimate how many times further away from each other are the two stars at apastron than a periastron?
\end{enumerate}

\vspace{0.1in}
\rule[0.5pt]{0.7\paperwidth}{0.3pt}

\item The sum of the masses is calculated from Kepler\textquoteright{}s Third Law.

\vspace{0.1in}

\begin{enumerate}
\item For Sirius, $(m_{1}+m_{2})$ = \rule[0.5pt]{0.05\paperwidth}{0.3pt} $M_{\circledcirc}$
\end{enumerate}
\item Since we know that $m_{1}=2.5\, m_{2}$, then the masses of the two stars are:

\vspace{0.1in}

\begin{enumerate}
\item $m_{1}$ = \rule[0.5pt]{0.05\paperwidth}{0.3pt} $M_{\circledcirc}$

\vspace{0.1in}

\item $m_{2}$ = \rule[0.5pt]{0.05\paperwidth}{0.3pt} $M_{\circledcirc}$
\end{enumerate}
\end{enumerate}
\pagebreak{}

\begin{doublespace}
\begin{center}
\uline{Lab II ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}
\par\end{center}
\end{doublespace}

\subsection{The Orbit of a Double-lined Spectroscopic Binary }

As a simple example, we will consider a model based on the binary system PSR 1855+09. The graph below shows two radial velocity curves beginning at some starting time t = 0. Refer to the diagram below to answer the final questions on this handout.

\begin{figure}[H]

\begin{centering}
\includegraphics[scale=0.75]{2_ds}
\par\end{centering}

\end{figure}

\vspace{0.1in}

\begin{enumerate}
\item Label on the graph which curve is for the more massive star and which one is for the less massive star.

\begin{enumerate}
\item What is the radial velocity with respect to the Earth of the center of mass of the binary system?

\vspace{0.1in}

\rule[0.5pt]{0.15\paperwidth}{0.3pt} km/sec

\item Draw a horizontal line on the graph to indicate the radial velocity of the center of mass. Now estimate the maximum radial velocities of the two stars, relative to the center of mass.\vspace{0.1in}

\begin{enumerate}
\item more massive star, $K_{1}$ \rule[0.5pt]{0.1\paperwidth}{0.3pt} km/sec

\begin{center}
\vspace{0.1in}

\par\end{center}

\item less massive star, $K_{2}$ \rule[0.5pt]{0.1\paperwidth}{0.3pt} km/sec
\end{enumerate}
\end{enumerate}
\item From the exact sinusoidal nature of the radial velocity curve, what is the eccentricity of the orbit?

\begin{enumerate}
\item eccentricity $e=$ \rule[0.5pt]{0.1\paperwidth}{0.3pt}
\end{enumerate}
\item What is the period of the orbit? P = \rule[0.5pt]{0.1\paperwidth}{0.3pt} days

\vspace{0.1in}

\item Calculate the ratio of the masses. $\frac{m_{1}}{m_{2}}$ = \rule[0.5pt]{0.1\paperwidth}{0.3pt}

\pagebreak{}

\uline{\hspace{-0.4in}Lab \LabNumber ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fall \year ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Astro 1103 - Nature of the Universe}\vspace{0.3in}

\item Suppose that the system is also an eclipsing binary so $i=90^{\circ}$. We can use the equations given in the lab to derive the masses of the two stars and the orbit semimajor axis $a=a_{1}+a_{2}$.

First, we need to know the semimajor axis. Given the eccentricity of the system you can figure out $a_{1}$ and $a_{2}$ because you know the orbital period and the velocity. To help yourself, draw a picture of the ``top view'' of the orbit:

\vspace{2in}

Similar to above questions, determine what is the orbital velocity of:

\vspace{0.1in}

\begin{enumerate}
\item more massive star \rule[0.5pt]{0.05\paperwidth}{0.3pt} km/sec

\begin{center}
\vspace{0.1in}

\par\end{center}

\item less massive star \rule[0.5pt]{0.05\paperwidth}{0.3pt} km/sec

\begin{center}
\vspace{0.1in}

\par\end{center}

\end{enumerate}

Label $a_{1}$ and $a_{2}$ on the picture and indicate which star is the more massive.

\end{enumerate}
\vspace{0.1in}

You can now calculate the distances traveled by each star in its orbit, because you know what the orbit looks like, how fast the star travels, and how long it takes to make one orbit. Notice that the:

\vspace{0.1in}

Number of seconds in a day = 24 hrs $\times$ 60 $\frac{min}{hr}$ $\times$ 60 $\frac{sec}{min}$ = $8.64\times10^{4}$ sec/day

\vspace{0.1in}

Also, note that 1 AU = $1.50\times10^{8}$ km

\vspace{0.1in}

Now calculate $a_{1}$ and $a_{2}$ in AU. Show your calculation below. (HINT: speed = distance/time, so distance = speed $\times$ time.)

\begin{center}
\vspace{0.1in}
$a_{1}$ = \rule[0.5pt]{0.05\paperwidth}{0.3pt} AU
\par\end{center}

\begin{center}
\vspace{0.1in}
$a_{2}$ = \rule[0.5pt]{0.05\paperwidth}{0.3pt} AU
\par\end{center}

\begin{center}
Remember that, $a_{2}sin\,(i)=K_{2}$ , $a_{1}sin\,(i)=K_{1}$. The semimajor axis a is just the sum of $a_{1}+a_{2}$:
\par\end{center}

\begin{center}
\vspace{0.1in}
$a$ = \rule[0.5pt]{0.05\paperwidth}{0.3pt} AU
\par\end{center}

Calculate the sum of the masses (remember you need the period in years!) and then the separate masses (since you know the mass ratio).

\begin{center}
\vspace{0.1in}
P = \rule[0.5pt]{0.05\paperwidth}{0.3pt} years
\par\end{center}

\begin{center}
\vspace{0.1in}
$m_{1}+m_{2}$= \rule[0.5pt]{0.05\paperwidth}{0.3pt} $M_{\circledcirc}$
, $m_{1}$ = \rule[0.5pt]{0.05\paperwidth}{0.3pt} $M_{\circledcirc}$
, $m_{2}$ = \rule[0.5pt]{0.05\paperwidth}{0.3pt} $M_{\circledcirc}$
\par\end{center}
\end{document}


\section{Discussion}

To analyze and compare the reported results we will consider existing, manually derived heuristics for the TSP.

Firstly, Johnson et. al. \cite{johnson2007experimental} report on the results of Cycle Patching (P), Kanellakis-Papadimitriou (KP), Zhang's heuristic (Z) and Helsgaun's Heuristic (H) for the asymmetric TSP.

Secondly, Glover et. al. \cite{glover2001construction} report on the results of the Greedy  algorithm (GR), Random Insertion (RI), Karp-Steele  patching (KSP), a modified Karp±-Steele patching heuristic (GKS), a recursive path contraction algorithm (RPS), and a contract heuristic (COP) on both symmetric and asymetric problems.

Finally, Halim and Ismail \cite{halim2019combinatorial} report on the results of the Nearest Neighbor  algorithm (NN), a Genetic Algorithm (GA), Simulated Annealing (SA), Tabu Search (TS), Ant Colony Optimization (ACO), and Tree Physiology Optimization (TPO) on both symmetric and asymetric problems.

The performance - in terms of \% over optimal distances - for each of the algorithms above is summarized in table \ref{tab:test_comparison}. Where there are no reported results for an algorithm, the cell is left empty. In addition, the results for the Genetic Programming approach used in this assignment (GP) are summarized in the final column of the table.

\begin{table}[H]
\resizebox{\textwidth}{!}{\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
\hline
\multirow{3}{*}{Instance} & \multicolumn{17}{c|}{\% Over Optimal}                                                                                \\ \cline{2-18}
                          & \multicolumn{4}{c|}{Johnson et. al. \cite{johnson2007experimental}}               & \multicolumn{6}{c|}{Glover et. al. \cite{glover2001construction}}                                                   & \multicolumn{6}{c|}{Halim and Ismail \cite{halim2019combinatorial}}                                               &             \\ \cline{2-18}
                          & \textbf{P} & \textbf{KP} & \textbf{Z} & \textbf{H} & \textbf{GR} & \textbf{RI} & \textbf{KSP} & \textbf{GKS} & \textbf{RPS} & \textbf{COP} & \textbf{NN} & \textbf{GA} & \textbf{SA} & \textbf{TS} & \textbf{ACO} & \textbf{TPO} & \textbf{GP} \\ \hline
\textbf{ch150}            & -          & -           & -          & -          & -           & -           & -            & -            & -            & -            & 8.42        & 7.30        & 8.18        & 5.12        & 12.60        & 6.35         & 408.10      \\ \hline
\textbf{eil51}            & -          & -           & -          & -          & -           & -           & -            & -            & -            & -            & 18.56       & 6.60        & 3.08        & 3.08        & 9.73         & 2.64         & 148.59      \\ \hline
\textbf{eil101}           & -          & -           & -          & -          & -           & -           & -            & -            & -            & -            & 17.01       & 9.04        & 6.86        & 6.14        & 19.70        & 7.31         & 200.47      \\ \hline
\textbf{rat195}           & -          & -           & -          & -          & -           & -           & -            & -            & -            & -            & 13.15       & 3.94        & 9.25        & 2.19        & 6.12         & 10.78        & 73.22       \\ \hline
\textbf{rd400}            & -          & -           & -          & -          & -           & -           & -            & -            & -            & -            & 19.23       & 8.42        & 10.05       & 35.62       & 26.03        & 19.04        & 791.02      \\ \hline
\textbf{ftv170}           & 1.38       & 4.44        & 0.36       & 0.00       & 32.05       & 28.97       & 2.40         & 1.38         & 25.66        & 3.59         & -           & -           & -           & -           & -            & -            & 159.38      \\ \hline
\textbf{rbg323}           & 0.00       & 0.78        & 0.00       & 0.00       & 8.52        & 29.34       & 0.00         & 0.00         & 0.53         & 0.00         & -           & -           & -           & -           & -            & -            & 321.64      \\ \hline
\textbf{rbg358}           & 0.00       & 1.50        & 0.00       & 0.00       & 7.74        & 42.48       & 0.00         & 0.00         & 2.32         & 0.26         & -           & -           & -           & -           & -            & -            & 414.61      \\ \hline
\textbf{rbg403}           & 0.00       & 0.22        & 0.00       & 0.00       & 0.85        & 9.17        & 0.00         & 0.00         & 0.69         & 0.20         & -           & -           & -           & -           & -            & -            & 195.94      \\ \hline
\textbf{rbg443}           & 0.00       & 0.11        & 0.00       & 0.00       & 0.92        & 10.48       & 0.00         & 0.00         & 0.00         & 0.00         & -           & -           & -           & -           & -            & -            & 185.88      \\ \hline
\end{tabular}}
\caption{Comparison of Results}
\label{tab:test_comparison}
\end{table}

In comparing the results in table \ref{tab:test_comparison}, it is obvious that the generation constructive hyper-heuristic explored in this assignment provides poor solutions in comparison to existing manually derived heuristics . However, considering that minimal experimentation was done with regards to parameter optimization and implementation variations, it is still worthwhile to further explore genetic programming in generating constructive low-level heuristics. Future research may also expand upon the execution times of these approaches, which were reported on in this assignment, but not discussed.


\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}

\title{Behaviour Dynamics in Social Networks - Assignment 3}

\author{Maria Hotoiu, Federico Tavella}

\date{\today}

\begin{document}
\maketitle

\begin{abstract}
As the first step of this assignment, you are asked to model the example of temporal-causal network
model described in Chapter 2. The following figure shows the graphical conceptual representation of
this model. You can use the Excel template created for this modeling purpose (available on Blackboard
of the course). For more information about this model, please read Section 4 of Chapter 2.
\end{abstract}

\section{Simulation result}

\begin{figure}[!htpb]
\center
\includegraphics[width=\textwidth]{res/img/results}
\caption{Simulation result}
\label{fig:simulation_result}
\end{figure}

\section{Physical action}

The value of $es_a$ is going above 0.5 somewhere between 7 and 8 seconds. In order to delay the physical response, we should change the speed factor to a smaller value (e.g. $\eta_{es_{a}} = 0.1$). If we want the value of $es_{a}$ to overcome 0.5 after 20 seconds, we should use $\eta_{es_{a}} = 0.05$.

\begin{figure}[!htpb]
\center
\includegraphics[width=\textwidth]{res/img/results_speed_factor}
\caption{Simulation result with $\eta_{es_{a}} = 0.05$}
\label{fig:simulation_result_speed_factor}
\end{figure}

\section{Smoother curves}

In order to obtain smoother curves, we have to change the $\Delta t$ to a smaller value.

\begin{figure}[!htpb]
\center
\includegraphics[width=\textwidth]{res/img/results_delta_t}
\caption{Simulation result with $\Delta t = 0.1$}
\label{fig:simulation_result_delta_t}
\end{figure}

Now, the value of $es_{a}$ is becoming higher than 0.5 after 7.2 seconds, which is between 7 and 8 seconds, as for Q2.
$\Delta t$ does not affect how fast the values are changing, it only changes the frequency of the observations. On the other hand, the speed factor influences how rapidly the values are varying. Moreover, the $\Delta t$ is shared for the whole model, while the speed factor is characteristic to each node.

\section{Tuning $es_{a}$}

The closer we could get to the given empirical values for $es_{a}$ was by using the following parameters: $\eta_{es_{a}} = 0.33,$ $\sigma_{es_{a}} = 62$ and $\tau_{es_{a}} = 0.948$. With these values, we obtained $es_{a}(t = 0) = 0$, $es_{a}(t = 15) = 0.114$ and $es_{a}(t = 30) = 0.946$.

\begin{figure}[!htpb]
\center
\includegraphics[width=\textwidth]{res/img/tuning}
\caption{Tuning of parameters for $es_{a}$}
\label{fig:tuning}
\end{figure}

\section{Real world scenarios}

Real world domains where we can have different $\Delta t$ for different processes to have a most accurate simulation: the first scenario is observing patients in a mental institute and the second one is neurology.

\begin{enumerate}
\item We can have a small $\Delta t$ when we need to check the changes of the values more often. For example, if we are studying a case where people with severe depression are concerned, we want to check the evolution of the emotions really often, otherwise we could not predict if they are going to hurt themselves. With a bigger $\Delta t$, we check the evolution of states less frequently. In this case, we can monitor people with OCD less frequently because they are less likely to be in danger.
\item When performing neurological observations, after a surgery for example, there is no published consensus on how frequently these observations should be recorded. One factor which will determine the frequency is the patient’s presenting condition and medical diagnosis. So we can say that for certain patients a higher value of the $\Delta t$ will lead to more accurate results, while for others a smaller value is more appropriate.
\end{enumerate}

Two real world application domains for which one value of $\Delta t$ will make a most accurate simulation:
\begin{enumerate}
\item Measuring weight when on a diet should be done daily and also at the same time of day for an accurate interpretation of the diet's result.

\item In sociology experiments, we may want to check how the insertion of a person with different opinion affects the behaviour of the whole network. To obtain a better results, we may want to repeat the same experiment in different groups. In this case, we want to use the same $\Delta t$ for each group, in order to check the evolution of the network after the same amount of time.
\end{enumerate}

\section{Comparision of $\Delta t$ and speed factor}

True sentence: (g). False sentences: all the other ones.
$\Delta t$ is only a property of the model: in reality, the process is continuous, while in a simulation it is discrete. On the other hand, the speed factor is a property of both real world and the model: all real life processes have a certain speed and to represent them we need to include the speed factor as a property of the model.

\end{document}


\section{Conclusion}
\label{sec:conclusion}

Reinforcement learning is a general class of algorithms that allow an agent to learn how to behave in a stochastic and possibly unknown environment simply by trial-and-error. In this paper, after recalling the basic concepts of RL, we presented an application of some state-of-the-art learning algorithms to the classical financial problem of determining a profitable long-short trading strategy. For a synthetic asset, the strategies produced outperform the simple Buy \& Hold strategy, even when investment decisions are only based on extremely basic autoregressive features. Contrarily to standard prediction-based trading systems, the learning algorithms employed are able to adapt as expected to the introduction of transaction costs by reducing the frequency of reallocation and of short positions. This shows the potential of RL techniques in effectively dealing with complex sequential decision problems that are typical in financial applications.\\
The algorithms above have also been tested on historical data but we couldn't find a trading strategy that consistently outperformed the simple Buy \& Hold strategy. This was partly expected as it is extremely difficult to find profitable daily patterns in highly liquid assets, especially when using such simple features. We believe that developing more complex features for the trading strategy, perhaps employing some deep learning feature extraction techniques such as deep auto-encoders or deep (recurrent) neural networks, would allow us to beat the market. Another possibility we considered is to decrease the sampling frequency of the historical data and let the algorithms look for some profitable patters. At the moment, these ideas are still work in progress.


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{physics}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\bea}{\begin{flalign*}}
\newcommand{\eea}{\end{flalign*}}

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Assignment\ \#4}
\newcommand{\hmwkDueDate}{Due on 8th November, 2018}
\newcommand{\hmwkClass}{Advanced Quantum Mechanics}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{}
\newcommand{\hmwkAuthorName}{\textbf{Aditya Vijaykumar}}

%
% Title Page
%

\title{
    %\vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{\hmwkDueDate\ }\\
%    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle
(\textbf{Acknowledgements} - I would like to thank Chandramouli Chowdhury, Biprarshi Chakraborty and Junaid Majeed for discussions.)
\\

	Let Hamiltonian $ H = H_0  + \lambda V$, $ H_0\ket{n^{0}} = E_n^{0}\ket{n^{0}}  $, $ H\ket{n} = E_n \ket{n} $. Let $ \Delta_n = E_n - E_n^{0} $ and $ \phi_n = 1 - \ket{n^{0}}\bra{n^{0}} $ be the projector onto the orthogonal space of $ \ket{n^{0}} $. $ \ket{n} $ and $ \Delta_n $ are given by,

	\begin{equation*}
	\ket{n} =\ket{n^{0}} + \dfrac{ \phi_n (\lambda V - \Delta_n)\ket{n}}{E_n^{0} - H_0} = \ket{n^{0}} +\sum_{k\ne n} \dfrac{ \lambda \mel{k^0}{V}{n} - \Delta_n \ip{k^{0}}{n}}{E_n^{0} - E_k^{0}}\ket{k^{0}} \qq{and} \Delta_n = \lambda \mel{n^{0}}{V}{n}
	\end{equation*}
	We work with normalization $ \ip{n}{n^0} = 1 \implies \ip{n^j}{n^0} = 0 \qq{;} j\ne0$.
	We assume the following,
	\begin{equation*}
	\Delta_n = \lambda \Delta^{1}_n + \lambda^2 \Delta_n^2 + \ldots \qq{and} \ket{n} = \ket{n^{0}} +  \lambda \ket{n^{1}} + \lambda^2 \ket{n^{2}} + \ldots
	\end{equation*}

	Putting these into the equations for $ \ket{n} $ and $ \Delta_{n} $ and equating order by order, we get,
	\begin{align}
	\Delta_n^{1} &= \ev{V}{n^0} \label{1}\\
	\ket{n^1} &= \sum_{k\ne n} \dfrac{ \mel{k^0}{V}{n^0} }{E_n^{0} - E_k^{0}}\ket{k^{0}}  \label{2}\\
	\Delta_n^2 &= \sum_{k\ne n} \dfrac{ \abs{\mel{k^0}{V}{n^0}}^2 }{E_n^{0} - E_k^{0}}  \label{3}\\
	\ket{n^2} &= \sum_{k\ne n} \dfrac{ \mel{k^0}{V}{n^1} - \Delta_n^1 \ip{k^{0}}{n^1}}{E_n^{0} - E_k^{0}}\ket{k^{0}}
	\label{4}
	\end{align}
\begin{homeworkProblem}[1]
	We note that,
	\begin{align*}
	\ip{E_n}{E_n} &= \ip{E_n}{E_n^0} + \lambda\qty(\ip{E_n^1}{E_n^0} + \ip{E_n^0}{E_n^1})  + \lambda^2 \qty(\ip{E_n^2}{E_n^0} + \ip{E_n^0}{E_n^2} + \ip{E_n^1}{E_n^1}) \\
	&= 1 + \lambda^2 \qty(\ip{E_n^1}{E_n^1})
	\end{align*}
	One needs to find the following,
	\begin{align*}
	\dfrac{\ip{E_n^0}{E_n}}{\sqrt{\ip{E_n}{E_n}\ip{E_n^0}{E_n^0}}} &= \dfrac{1}{\sqrt{1 + \lambda^2 \qty(\ip{E_n^1}{E_n^1})}}\\
	&= 1 - \dfrac{\lambda^2}{2}\sum_{k\ne n} \dfrac{\abs{\mel{E_k^0}{V}{E_n^0} }^2}{(E_n^{0} - E_k^{0})^2}
	\end{align*}
	where we have used (\ref{2}) in going to the last step. Hence, the required probability is $  1 - \dfrac{\lambda^2}{2}\sum_{k\ne n} \dfrac{\abs{\mel{E_k^0}{V}{E_n^0} }^2}{(E_n^{0} - E_k^{0})^2} $.
\end{homeworkProblem}

\begin{homeworkProblem}[2]
	\textbf{Part (a)}\\
	From the form of the Hamiltonian, we can see that the energy will have the form,
	\begin{equation*}
	E_{n_x,n_y} = (n_x + 0.5 + n_y + 0.5)\omega = (n_x + n_y + 1) \omega
	\end{equation*}
	The three lowest lying states are,
	\begin{align*}
	n_x = 0 \qq{,} n_y= 0 &\implies E_{00}^{(0)} = \omega\\
	n_x = 1 \qq{,} n_y= 0 &\implies E_{10}^{(0)} = 2 \omega\\
	n_x = 0 \qq{,} n_y= 1 &\implies E_{01}^{(0)} = 2 \omega
	\end{align*}
	We see that there is a double-degeneracy with energy $ 2\omega $.
	\\

	\textbf{Part (b)}\\
	Let's denote states by $ \ket{n_x n_y} $. $ x $ and $ y $ can be written in terms of corresponding creation and annhilation operators as follows,
	\begin{equation*}
	x = \dfrac{1}{\sqrt{2m\omega}}(a_x + a_x^\dagger) \qq{and} y = \dfrac{1}{\sqrt{2m\omega}}(a_y + a_y^\dagger)
	\end{equation*}
	The perturbation is $ V = \lambda m \omega^2 x y $. Let's denote the $m$-th order energy shift by $ \Delta^m_{n_x n_y} $. Let's first consider $ \ket{00} $. The zeroth order energy eigenstate is given by,
	\begin{equation*}
	\psi_{00}^0 = \psi_0 (x) \psi_0 (y) = \sqrt{\dfrac{m\omega}{\pi}} e^{-\frac{m\omega}{2}(x^2 + y^2)}
	\end{equation*}
	Consider $\Delta^1_{00} $,
	\begin{align*}
	\Delta^1_{00} &= \ev{V}{00}\\
	&= \dfrac{m\omega^2}{2m\omega} \qty( \ev{a_x a_y}{00} + \ev{a_x a_y^\dagger}{00} + \ev{a_x^\dagger a_y ^\dagger}{00} + \ev{a_x^\dagger a_y}{00})\\
	\Delta^1_{00} &= 0
	\end{align*}
	The states $ \ket{10} $ and $ \ket{01} $ are degenerate, and hence we need to apply degenerate perturbation formalism. For this, we construct the matrix elements of $ V $ between the degenerate states. As we have seen in the $ \ket{00} $ case, the operator $ xy $ changes a given state to one which has at least one of the quantum numbers different (by 1). Hence $\ev{V}{01} = \ev{V}{10} = 0$. We proceed to calculate $ \mel{01}{V}{10} $,
	\begin{align*}
	\mel{01}{V}{10} &= \dfrac{\lambda m\omega^2}{2m \omega} \qty(\mel{01}{a_x a_y}{10} + \mel{01}{a_x a_y^\dagger}{10} + \mel{01}{a_x^\dagger a_y ^\dagger}{10} + \mel{01}{a_x^\dagger a_y}{10})\\
	&= \dfrac{\lambda \omega }{2}\qty(0+ 1+ 0 + 0)\\
	\mel{01}{V}{10} &= \dfrac{\lambda \omega }{2}\\
	\implies \mel{10}{V}{01} &= \dfrac{\lambda \omega }{2}\\
	\therefore V &= \dfrac{\lambda \omega }{2} \mqty(\admat[0]{1,1})
	\end{align*}

	The eigenvalues of the above matrix are $ \pm \dfrac{\lambda \omega }{2} \implies E = 2\omega \pm \lambda \dfrac{\omega}{2}$ with eigenstates $ \dfrac{1}{\sqrt{2}}(\ket{10} \pm \ket{01}) $
	\\
	\textbf{Part (c)}\\
	The aim is to now solve for the Hamiltonian exactly.
	\begin{align*}
	H &= \dfrac{p_x^2}{2m} + \dfrac{p_y^2}{2m} + \dfrac{m\omega^2}{2}(x^2 + y^2 + 2\lambda xy)\\
	&= \dfrac{p_x^2}{2m} + \dfrac{p_y^2}{2m} + \dfrac{m\omega^2}{4}((x+ y )^2 + (x-y)^2+ \lambda[(x+y)^2 - (x-y)^2])\\
	&= \dfrac{p_x^2}{2m} + \dfrac{p_y^2}{2m} + \dfrac{m\omega^2}{2}\qty[\qty(\dfrac{x+ y }{\sqrt{2}})^2(1+\lambda) + \qty(\dfrac{x-y}{\sqrt{2}})^2(1-\lambda)]
	\end{align*}
	Let $ \alpha = \dfrac{x+ y }{\sqrt{2}} $ and $ \beta = \dfrac{x - y }{\sqrt{2}} $. We can see that $ \dot{\alpha}^2 + \dot{\beta}^2 = \dot{x}^2 + \dot{y}^2 \implies p_\alpha^2 + p_\beta^2 = p_x^2 + p_y^2$. In the new coordinates, the Hamiltonian is,
	\begin{equation*}
	H = \dfrac{p_\alpha^2}{2m} + \dfrac{m(\omega\sqrt{1+\lambda})^2}{2}\alpha^2 +  \dfrac{p_\beta^2}{2m} + \dfrac{m(\omega\sqrt{1- \lambda})^2}{2}\beta^2
	\end{equation*}
	We have essentially decoupled the Hamiltonian into two harmonic oscillators of frequencies $ \omega_1 = \omega\sqrt{1+\lambda} $ and $ \omega_2 = \omega\sqrt{1 - \lambda} $. The three lowest energies are,
	\begin{align*}
	\dfrac{\omega(\sqrt{1+\lambda} + \sqrt{1 - \lambda})}{2} &= \omega + \order{\lambda^2}\\
	\dfrac{\omega(3\sqrt{1+\lambda} + \sqrt{1 - \lambda})}{2} &= 2\omega +  \lambda \dfrac{\omega}{2} + \order{\lambda^2}\\
	\dfrac{\omega(\sqrt{1+\lambda} + 3\sqrt{1 - \lambda})}{2} &= 2\omega - \lambda \dfrac{\omega}{2} + \order{\lambda^2}
	\end{align*}
	We see that the above values match with those calculated from perturbation theory.
	\end{homeworkProblem}

\begin{homeworkProblem}[3]
	We first note that $ x^2 - y^2 = r^2 \sin^2 \theta \cos 2 \phi = r^2 \sin^2 \theta \dfrac{e^{2i\phi} + e^{-2i\phi}}{2}$ when expressed in polar coordinates. As we are dealing with states that differ only in their $ m $ values, we label the states as $ \ket{m} $. We note the following eigenstates $ \psi_{n,l,m} $ of the hydrogen atom,
	\begin{equation*}
	\psi_{2,1,\pm 1}(r,\theta,\phi) = \ket{\pm 1} = \dfrac{1}{8\sqrt{\pi}a_0^{5/2}}r e^{-\frac{2r}{a_0}} \sin\theta e^{\pm i\phi} \qq{and} \psi_{2,1,0}(r,\theta,\phi) = \ket{0} = \dfrac{\sqrt{2}}{8\sqrt{\pi}a_0^{5/2}}r e^{-\frac{2r}{a_0}} \cos\theta
	\end{equation*}
	The above eigenstates are degenerate. The perturbing Hamiltonian is $ V = \lambda (x^2 - y^2) = \lambda r^2 \sin^2 \theta \cos 2 \phi = \lambda V' $. As we are dealing with states that differ only in their $ m $ values, we label the states as $ \ket{m} $. As in the previous problem, we proceed to construct the matrix elements of $ V' $. In each element $ \mel{p}{V}{q} $, the $ \phi $ integral will be $ \sim \int_{0}^{2\pi} e^{i(q - p)\phi} (e^{2i\phi} + e^{-2i\phi}) d\phi$. We can see that this integral will be zero unless $ q - p = \pm 2 $. Hence, only terms where $ p -q = \pm 2 $ will contribute, ie $ p=1, q = -1 $ and $ p=-1 , q=1 $. Let's evaluate $ \mel{-1}{V'}{1} $,
	\begin{align*}
	\mel{-1}{V'}{1} &= -\dfrac{1}{64\pi a_0^{5}} \int_{0}^{2\pi} \dfrac{e^{4i\phi} + 1}{2} d\phi\int_{0}^{\pi} \sin^4 \theta d(\cos\theta) \int_{0}^{\infty}r^6 e^{-\frac{4r}{a_0}}dr\\
	&= -\dfrac{1}{64\pi a_0^{5}} (\pi) \int_{0}^{\pi}  (1 - \cos^2\theta)^2  d(\cos\theta) \int_{-\infty}^0 \qty(\dfrac{a_0}{4})^7t^6 e^{t}dr \qq{ } \qty(\impliedby t = - \dfrac{4r}{a_0})\\
	&= -\dfrac{1}{64\pi a_0^{5}} (\pi) \int_{0}^{\pi} (\cos^4 \theta - 2 \cos^2 \theta + 1)  d(\cos\theta) \qty[\qty(\dfrac{a_0}{4})^7 6!] \qq{ } \\
	&= -\dfrac{ a_0^{2}}{64} \qty(\dfrac{-2}{5} + \dfrac{4}{3} - 2 ) \qty[\qty(\dfrac{45}{2^{10}})] = \dfrac{ a_0^{2}}{64} \qty(\dfrac{16}{15}) \qty[\qty(\dfrac{45}{2^{10}})] = \dfrac{3}{2^{12}}a_0^2 = \alpha
	\end{align*}
	\begin{equation*}
	\therefore \mel{-1}{V'}{1} = \mel{-1}{V'}{1} = \alpha  = \dfrac{3}{2^{12}}a_0^2
	\end{equation*}
	\begin{equation*}
	V' = \mqty(0 & 0 & \alpha\\0 & 0 & 0 \\\alpha & 0 & 0)
	\end{equation*}
	The eigenvalues of $ V' $ are $ 0 $, $ \pm \alpha $ and the corresponding eigenstates are $ \ket{0} $, $ \dfrac{\ket{1} \pm \ket{-1}}{\sqrt{2}} $ respectively. So the first order energy shifts are $ 0 $, $ \pm \alpha $.
\end{homeworkProblem}

\begin{homeworkProblem}[4]
	\begin{equation*}
	H = \mqty(E_1 & 0 & \lambda a\\ 0 & E_1 & \lambda b \\ \lambda a^* & \lambda b^* & E_2) = \underbrace{\mqty(\dmat[0]{E_1, E_1, E_2})}_{H_0} + \lambda \underbrace{\mqty(0 & 0 & a\\ 0 & 0 &  b \\  a^* &  b^* & 0)}_V
	\end{equation*}
	$ H $ has the following three eigenvalues.
	\begin{align*}
	\dfrac{{E_1}+{E_2}}{2} \pm \sqrt{\lambda^2 \left(a^2+b^2\right)+\qty(\dfrac{{E_1}-{E_2}}{2})^2} \qq{and} E_1\\
	\implies \approx E_1 + \lambda^2 \dfrac{\abs{a}^2 + \abs{b}^2}{E_1 - E_2} \qq{and} \approx E_2 - \lambda^2 \dfrac{\abs{a}^2 + \abs{b}^2}{E_1 - E_2} \qq{and} E_1
	\end{align*}
	We also notice that $ H_0 $ has a two-fold degeneracy with energy $ E_1 $, corresponding to the eigenstates $ \ket{0} = \mqty[1 & 0 & 0]^T $ and $ \ket{1} = \mqty[0 & 1 & 0]^T $, as well as energy eigenstate $ \ket{0} = \mqty[0 & 0 & 1]^T  $ with energy $ E_2 $. We also note that the block in $ V $ corresponding to these eigenstates in made up of zeros, hence there is no hope of breaking the degeneracy at first order in perturbation theory.

	Now we know that provided we choose the correct basis, $ \Delta_n^2 = \mel{n^1}{V}{n^0} $. For this, let's calculate the first order perturbed eigenstate. We have $ (H_0 + \lambda V) \ket{l_i} = E_{d_i} \ket{l_i}$. Substitute $ \ket{l_i} = \ket{l_i^0} + \lambda \ket{l_i^1} + \ldots $ (where $ \ket{l_i} = c_0\ket{0} + c_1 \ket{1} $) and $  E_{d_i} = E_1 +  \lambda E_{d_i}^1 + \ldots$. At first order, the equation then becomes,
	\begin{equation*}
	H_0 \ket{l_i^1} + V \ket{l_i^0} = E_1 \ket{l_i^1} + E_{d_i}^1 \ket{l_i^0}
	\end{equation*}
	But as degeneracy is not removed as first order, $ E_{d_i}^1 = 0 $. Taking the inner product with $ l_i^{0} $
	\begin{equation*}
	V \ket{l_i^0} = (E_1 - H_0) \ket{l_i^1}
	\end{equation*}
	Taking the inner product with $ \bra{l_i^0} $, we get that $ \ev{V}{{l_i^0}}  = 0 \implies$ that $ V \ket{l_i^0} $ has no component along $ \ket{l_i^0} $. Then we can write,
	\begin{equation*}
	\ket{l_i^1} =  \dfrac{1}{E_1 - H_0} V\ket{l_i^0} \implies \mel{l_i^1}{V}{l_i^0} = \ev{V\dfrac{1}{E_1 - H_0} V}{l_i^0}
	\end{equation*}
	Now all that is left to do is diagonalize $G = V\dfrac{1}{E_1 - H_0} V$. We note,
	\begin{equation*}
	V \ket{0} = a^* \ket{2} \qq{and} V \ket{1} = b^* \ket{2}
	\end{equation*}
	We can use these to construct the matrix elements,
	\begin{align*}
	\mel{0}{G}{0} &= \abs{a}^2 \ev{\dfrac{1}{E_1 - H_0}}{2} =\dfrac{ \abs{a}^2 }{E_1 - E_2}\\
	\mel{0}{G}{1} = \dfrac{ab^*}{E_1 - E_2} &\qq{ } \mel{1}{G}{1} = \dfrac{\abs{b}^2}{E_1 - E_2} \qq{ } \mel{1}{G}{0} = \dfrac{a^* b}{E_1 - E_2}\\
	\therefore G &= \dfrac{1}{E_1-E_2}\mqty(\abs{a}^2 & ab^*\\ a^*b & \abs{b}^2)
	\end{align*}
	The eigenvalues of $ G $ are $ 0 $ and $ \dfrac{\abs{a}^2 + \abs{b}^2}{E_1 - E_2}  $ and the corresponding eigenstates are $ \dfrac{-b \ket{0} + a \ket{1}}{\sqrt{\abs{a}^2 + \abs{b}^2}} $ and $ \dfrac{a \ket{0} + b\ket{1}}{\sqrt{\abs{a}^2 + \abs{b}^2}} $.

	We now look at the state with energy $ E_2 $. The second order perturbed energy for this case is straighforward,
	\begin{equation*}
	\Delta^2  =\dfrac{ \abs{\mel{0}{V}{2}}^2  + \abs{\mel{1}{V}{2}}^2}{E_2 - E_1} = - \dfrac{\abs{a}^2 + \abs{b}^2}{E_1 - E_2}
	\end{equation*}

	So then, the final energies upto second order in $ \lambda $ are,
	\begin{equation*}
	 E_1 \qq{,} E_1 + \lambda^2 \dfrac{\abs{a}^2 + \abs{b}^2}{E_1 - E_2} \qq{and} E_2 - \lambda^2 \dfrac{\abs{a}^2 + \abs{b}^2}{E_1 - E_2}
	\end{equation*}
	which is commensurate with the actual eigenvalues upto second order.
	￼

\end{homeworkProblem}

\begin{homeworkProblem}[5]
	Let $ L^2 = L_x^2 + L_y^2 + L_z^2 $. We work in the basis of states $ \ket{l,m} $ such that $ L^2 \ket{l,m} = l(l+1)\ket{l,m} $ and $ L_z \ket{l,m} = m \ket{l,m} $. The Hamiltonian then is,
	\begin{equation*}
	H = H_0 + \lambda V = AL^2 + BL_z + \lambda C L_y
	\end{equation*}
	The eigenstates of $ H_0 $ are,
	\begin{equation*}
	H_0 \ket{l,m} = \qty(Al(l+1) + Bm)\ket{l,m} = E_{lm}\ket{l,m}
	\end{equation*}

	For future use, let's evaluate $ \mel{l',m'}{V}{l,m} $,
	\begin{align*}
	\mel{l',m'}{V}{l,m} &= C \mel{l',m'}{L_y}{l,m}\\
	&= \dfrac{C}{2i} \mel{l',m'}{L_+ - L_-}{l,m}\\
	&= \dfrac{C}{2i} \qty(\sqrt{l(l+1) - m(m+1)} \delta_{l',l} \delta_{m',m+1} - \sqrt{l(l+1) - m(m-1)} \delta_{l',l} \delta_{m',m-1})\\
	\abs{\mel{l',m'}{V}{l,m}}^2 &=  \dfrac{C^2}{4} \qty([{l(l+1) - m(m+1)} ]\delta_{l',l} \delta_{m',m+1} + [{l(l+1) - m(m-1)}] \delta_{l',l} \delta_{m',m-1})
	\end{align*}
	The first order energy shift is given by,
	\begin{align*}
	\Delta_{lm}^{(1)} &= \ev{V}{l,m}\\
	&=  \dfrac{C}{2i} \qty(\sqrt{l(l+1) - m(m+1)} \delta_{l,l} \delta_{m,m+1} - \sqrt{l(l+1) - m(m-1)} \delta_{l,l} \delta_{m,m-1})\\
	\Delta_{lm}^{(1)} & = 0
	\end{align*}
	Then one needs to find higher order energy shifts. Considering $ \Delta_{lm}^2$ and using (\ref{3}),
	\begin{align*}
	\Delta_{lm}^2 &= \sum_{l\ne l', m\ne m'}\dfrac{ \abs{\mel{l',m'}{V}{l,m}}^2}{E_{lm} - E_{l'm'}}\\
	 &= \dfrac{C^2}{4} \sum_{l\ne l', m\ne m'}\dfrac{\qty([{l(l+1) - m(m+1)} ]\delta_{l',l} \delta_{m',m+1} + [{l(l+1) - m(m-1)}] \delta_{l',l} \delta_{m',m-1})}{Al(l+1) + Bm - Al'(l'+1) - Bm'}\\
	 &= \dfrac{C^2}{4}\qty( \dfrac{-[{l(l+1) - m(m+1)}]}{B} + \dfrac{[{l(l+1) - m(m - 1)}]}{B} )\\
	 &= \dfrac{C^2m}{2B}
	\end{align*}

\end{homeworkProblem}

\begin{homeworkProblem}[6]
	The Hamiltonian to deal with is,
	\begin{equation*}
	H = \dfrac{p^2}{2m} + \dfrac{m\omega^2}{2}x^2
	\end{equation*}
	and the given trial wavefunction is,
	\begin{equation*}
	\psi_\beta(x) = N e^{-\beta\abs{x}}
	\end{equation*}
	where $ N $ is some normalization. We first calculate $ \pdv[2]{\psi_\beta}{x}$,
	\begin{align*}
	\pdv[2]{\psi_\beta}{x} &=N \pdv{x}\qty(\pdv{e^{-\beta \abs{x}}}{x})\\
	&=-\beta N\pdv{x}\qty(\dfrac{x}{\abs{x}}e^{-\beta \abs{x}})\\
	&= N\qty(\beta^2e^{-\beta \abs{x}} -\dfrac{\beta}{\abs{x}}e^{-\beta \abs{x}} + \dfrac{\beta x}{x^2}e^{-\beta \abs{x}})
	\end{align*}
	Let's calculate $ \expval{H}{\psi_\beta} $,
	\begin{align*}
	\expval{H}{\psi_\beta} &= N^2 \int_{-\infty}^{\infty} e^{-\beta\abs{x}} \qty(-\dfrac{1}{2m}\pdv[2]{x}+ \dfrac{m\omega^2}{2}x^2)e^{-\beta\abs{x}}dx\\
	&=  \lim\limits_{\epsilon \rightarrow 0} N^2 \qty[ 2 \int_{\epsilon}^{\infty}  e^{-\beta x} \qty(-\dfrac{1}{2m}\pdv[2]{x}+ \dfrac{m\omega^2}{2}x^2) e^{-\beta x } dx + \int_{-\epsilon}^{\epsilon}  e^{-\beta\abs{x}} \qty(-\dfrac{1}{2m}\pdv[2]{x}+ \dfrac{m\omega^2}{2}x^2)e^{-\beta\abs{x}} dx]\\
	&=  \lim\limits_{\epsilon \rightarrow 0} N^2 \left[ 2 \int_{\epsilon}^{\infty}  e^{-2\beta x} \qty(-\dfrac{\beta^2}{2m} + \dfrac{m\omega^2}{2}x^2) dx - \int_{-\epsilon}^{\epsilon}  e^{-\beta\abs{x}} \qty(\dfrac{1}{2m}\pdv[2]{x} ) e^{-\beta\abs{x}} dx  + \int_{-\epsilon}^{\epsilon}  e^{-2\beta\abs{x}} \qty(\dfrac{m\omega^2}{2}x^2) dx \right]
	\end{align*}
	The last integral goes to zero as $ \epsilon \rightarrow 0 $. The second integral transforms into an integral only over the double derivative, since $  e^{-\beta\abs{x}} $ is almost constant from $ -\epsilon $ to $ \epsilon $. Then,
	\begin{align*}
	\expval{H}{\psi_\beta} &=  N^2 \left[ \qty(-\dfrac{\beta}{2m} + \dfrac{m\omega^2}{4\beta^3})-  \lim\limits_{\epsilon \rightarrow 0} \dfrac{e^{-\beta\abs{x}}}{2m} \eval{\qty(\pdv{x} e^{-\beta\abs{x}})}_{-\epsilon}^{\epsilon}  \right]\\
	&=  N^2 \left[ \qty(-\dfrac{\beta}{2m} + \dfrac{m\omega^2}{4\beta^3})+ \dfrac{\beta}{m} \right]\\
	&=  N^2 \qty[\dfrac{\beta}{2m} + \dfrac{m\omega^2}{4\beta^3}]
	\end{align*}
	We need to also fix the normalization,
	\begin{align*}
	N^2 \int_{-\infty}^{\infty}e^{-2\beta\abs{x}} = 1 \implies N^2 = \beta
	\end{align*}
	Hence,
	\begin{align*}
	\expval{H}{\psi_\beta} = &\ev{H} = \dfrac{\beta^2}{2m} +  \dfrac{m\omega^2 }{4 \beta^2}\\
	\eval{\dv{\ev{H}}{\beta}}_{\beta_0} = 0 \implies \dfrac{\beta_0}{m} - \dfrac{m\omega^2}{2\beta_0^3} = 0 \implies \beta_0 & = \pm \qty(\dfrac{m^2\omega^2}{2})^{1/4} \implies \ev{H}_{min} = \dfrac{\omega}{2\sqrt{2}} + \dfrac{\omega}{2\sqrt{2}} = \dfrac{\omega}{\sqrt{2}}
	\end{align*}
	Hence the ground state energy has an estimate of $ \dfrac{\omega}{\sqrt{2}} $ (which clearly is off from the actual value by a factor of $\dfrac{1}{\sqrt{2}}$ ).
\end{homeworkProblem}

\end{document}


\section{Iterators}
\subsection{What they are}
\begin{frame}
  \frametitle{What is an Iterator?}
  \begin{block}{Design pattern [GoF]}
    Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
  \end{block}
  \vfill
  \begin{block}{Stepanov}
    Iterator is a coordinate.
  \end{block}
  \vfill
  \begin{block}{A generalization of a pointer}
    \begin{itemize}
    \item indirect access (\texttt{operator*()}, \texttt{operator->()})
    \item operations for moving to point to a new element (\texttt{operator++()}, \texttt{operator--()})
    \end{itemize}
  \end{block}
\end{frame}

\subsection{Iterators in the STL}

\begin{frame}
  \frametitle{Iterators in the STL}
  \begin{block}{Their role}
    \begin{itemize}
    \item Iterators are the glue that ties the standard-library alogorithms to their data
    \item Iterators are the mechanism used to minimize an algorithm's dependence on the data structures on which it operates.
      \end{itemize}
  \end{block}
\vfill
  \begin{block}{Alex Stepanov}
    The reason that STL containers and algorithms work so well together is that they know nothing of each other.
    \end{block}
\end{frame}

\begin{frame}[fragile]
  %% \frametitle{How to use iterators}
  \vfill
  \begin{lstlisting}
       while( first != last )
  \end{lstlisting}
  \vfill
\end{frame}

\subsection{Iterator categories}
\begin{frame}
  \frametitle{Iterator categories}
  \centering
  \includegraphics[height=0.8\textheight]{img/iterators.png}
\end{frame}

\begin{frame}[fragile]
  \frametitle{How to implement our own iterator?}
\begin{lstlisting}
  template <typename T>
  class List<T>::Iterator {
    ...
  };
\end{lstlisting}
\end{frame}

\subsection{Our List iterator}
\begin{frame}[fragile]
  \frametitle{How to implement our own iterator?}
\begin{lstlisting}
  #include <iterator>
  ...
  template <typename T>
  class List<T>::Iterator{
    typename List<T>::node* current;
    public:
    using value_type = T;
    using difference_type = std::ptrdiff_t;
    using iterator_category =
      std::forward_iterator_tag;
    using reference = value_type&;
    using pointer = value_type*;
    ...
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{How to implement our own iterator?}
\begin{lstlisting}
    ...
    reference operator*() {
      return current->value; }
    pointer operator->() { return &**this; }
    Iterator& operator++() {
      current = current->next;
      return *this;
    }
    friend
    bool operator==(const Iterator&, const Iterator&);
    friend
    bool operator!=(const Iterator&, const Iterator&);
  };
\end{lstlisting}
\end{frame}