\documentclass[paper=a4, fontsize=11pt]{scrartcl} % A4 paper and 11pt font size

\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage{fourier} % Use the Adobe Utopia font for the document - comment this line to return to the LaTeX default
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amsthm,amssymb} % Math packages

\usepackage{caption}
\usepackage{graphicx, subfig}

\usepackage{algorithm, algorithmic}
\renewcommand{\algorithmicrequire}{\textbf{Input:}} %Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}} %UseOutput in the format of Algorithm

\usepackage{listings}
\lstset{language=Matlab}

\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template

\usepackage{sectsty} % Allows customizing section commands
\allsectionsfont{\centering \normalfont\scshape} % Make all sections centered, the default font and small caps

\usepackage{fancyhdr} % Custom headers and footers
\pagestyle{fancyplain} % Makes all pages in the document conform to the custom headers and footers
\fancyhead{} % No page header - if you want one, create it in the same way as the footers below
\fancyfoot[L]{} % Empty left footer
\fancyfoot[C]{} % Empty center footer
\fancyfoot[R]{\thepage} % Page numbering for right footer
\renewcommand{\headrulewidth}{0pt} % Remove header underlines
\renewcommand{\footrulewidth}{0pt} % Remove footer underlines
\setlength{\headheight}{13.6pt} % Customize the height of the header

\numberwithin{equation}{section} % Number equations within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
\numberwithin{figure}{section} % Number figures within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
\numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)

\setlength\parindent{0pt} % Removes all indentation from paragraphs - comment this line for an assignment with lots of text

\newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height

\title{
\normalfont \normalsize
\textsc{Shanghai Jiao Tong University, UM-SJTU JOINT INSTITUTE} \\ [25pt] % Your university, school and/or department name(s)
\horrule{0.5pt} \\[0.4cm] % Thin top horizontal rule
\huge Turbulence \\ HW2 \\ % The assignment title
\horrule{2pt} \\[0.5cm] % Thick bottom horizontal rule
}

\author{Yu Cang \\ 018370210001}

\date{\normalsize \today}

\begin{document}

\maketitle

\section{Exercise1}
	Consider the N-S equation
	\begin{equation}
		\frac{\partial u_j}{\partial t} + u_k \frac{\partial u_j}{\partial x_k} = -\frac{1}{\rho}\frac{\partial p}{\partial x_j} + \nu \frac{\partial^2 u_j}{\partial x_k \partial x_k} + f_j
	\end{equation}

	With the ensemble average, each quantity can be decomposed into mean and fluctuation. Namely
	\begin{equation}
		\begin{aligned}
			u_j & = U_j + u_j'\\
			p & = P + p'\\
			f_j &= F_j + f_j'
		\end{aligned}
	\end{equation}
	Thus, the N-S equation can be expanded as
	\begin{equation}
		\Bigg(\frac{\partial U_j}{\partial t} + \frac{\partial u_j'}{\partial t}\Bigg) + \Bigg(U_k\frac{\partial U_j}{\partial x_k} + u_k'\frac{\partial U_j}{\partial x_k} + U_k \frac{\partial u_j'}{\partial x_k} + u_k'\frac{\partial u_j'}{\partial x_k}\Bigg) = -\frac{1}{\rho}\Bigg(\frac{\partial P}{\partial x_j} + \frac{\partial p'}{\partial x_j}\Bigg) + \nu \Bigg(\frac{\partial^2 U_j}{\partial x_k \partial x_k} + \frac{\partial^2 u_j'}{\partial x_k \partial x_k}\Bigg) + (F_j + f_j')
	\end{equation}

	Taking ensemble average on the equation above yiels the so called Reynolds equation
	\begin{equation}
		\frac{\partial U_j}{\partial t} + U_k \frac{\partial U_j}{\partial x_k} + \overline{u_k'\frac{\partial u_j'}{\partial x_k}} = -\frac{1}{\rho}\frac{\partial P}{\partial x_j} + \nu \frac{\partial^2 U_j}{\partial x_k \partial x_k} + F_j
	\end{equation}

	Substract the Reynolds equation by N-S equation that has been expaneded yields
	\begin{equation}
		\frac{\partial u_j'}{\partial t} + u_k'\frac{\partial U_j}{\partial x_k} + U_k \frac{\partial u_j'}{\partial x_k} + u_k'\frac{\partial u_j'}{\partial x_k} - \overline{u_k'\frac{\partial u_i'}{\partial x_k}} = -\frac{1}{\rho}\frac{\partial p'}{\partial x_j} + \nu \frac{\partial^2 u_j'}{\partial x_k \partial x_k} + f_j'
	\end{equation}

	With the continuity equation for incompressible flow
	\begin{equation}
		\frac{\partial u_k'}{\partial x_k} = 0
	\end{equation}
	the substracted equation can be re-written as
	\begin{equation}
		N_j\{\vec{x}, t\} \triangleq \frac{\partial u_j'}{\partial t} + u_k' \frac{\partial \overline{u_j}}{x_k} + \overline{u_k}\frac{\partial u_j'}{\partial x_k} + \frac{\partial [u_j' u_k']}{\partial x_k} - \frac{\partial \overline{u_j' u_k'}}{\partial x_k} + \frac{1}{\rho} \frac{\partial p'}{\partial x_j}-\nu \frac{\partial^2 u_j'}{\partial x_k \partial x_k} - f_j' = 0
		\label{eq:sns}
	\end{equation}

	Also, an identity is frequently used within the exercise
	\begin{equation}
		\frac{d u(t+s)}{dt} = \frac{d u(t+s)}{d(t+s)} = \frac{d u(t+s)}{ds}
	\end{equation}

	Since the two-point correlation function is defined as
	\begin{equation}
		R_{ij} = \overline{u_i'(\vec{x}, t) u_j'(\vec{x}+\vec{r}, t + \tau)}
	\end{equation}

	Thus, for $D^{(i)}\{R_{ij}\} = \overline{u_j'(\vec{x} + \vec{r}, t+\tau) N_i\{\vec{x}, t\}}$, components in the expansion are calculated as
	\begin{equation}
		\begin{aligned}
			\overline{u_j'(\vec{x} + \vec{r}, t+\tau) \frac{\partial u_i'(\vec{x}, t)}{\partial t}}
			& = \overline{\frac{\partial (u_i'(\vec{x}, t)u_j'(\vec{x} + \vec{r}, t+\tau))}{\partial t} - u_i'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial t}}\\
			& = \frac{\partial \overline{u_i'(\vec{x}, t)u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial t} - \overline{u_i'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial \tau}}\\
			& = \frac{\partial R_{ij}}{\partial t} - \frac{\partial \overline{u_i'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial \tau}\\
			& = \frac{\partial R_{ij}}{\partial t} - \frac{\partial R_{ij}}{\partial \tau}
		\end{aligned}
	\end{equation}

	\begin{equation}
		\begin{aligned}
			\overline{u_j'(\vec{x} + \vec{r}, t+\tau) \overline{u_k}\frac{\partial u_i'}{\partial x_k}}
			& = \overline{u_k(\vec{x}, t)} \overline{u_j'(\vec{x} + \vec{r}, t+\tau) \frac{\partial u_i'(\vec{x}, t)}{\partial x_k}}\\
			& = \overline{u_k(\vec{x}, t)} \Bigg[\frac{\partial \overline{u_i'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial x_k}- \overline{u_i'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial (x_k + r_k)}}\Bigg]\\
			& = \overline{u_k(\vec{x}, t)} \Bigg[\frac{\partial R_{ij}}{\partial x_k}- \overline{u_i'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial r_k}}\Bigg]\\
			& = \overline{u_k(\vec{x}, t)} \Bigg[\frac{\partial R_{ij}}{\partial x_k}- \frac{\partial \overline{u_i'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial r_k}\Bigg]\\
			& = \overline{u_k(\vec{x}, t)} \Bigg[\frac{\partial R_{ij}}{\partial x_k}- \frac{\partial R_{ij}}{\partial r_k}\Bigg]
		\end{aligned}
	\end{equation}

	\begin{equation}
			\overline{u_j'(\vec{x} + \vec{r}, t+\tau) u_k'(\vec{x}, t) \frac{\partial \overline{u_i(\vec{x}, t)}}{\partial x_k}} = \overline{u_k'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)} \frac{\partial \overline{u_i(\vec{x}, t)}}{\partial x_k} = R_{kj}\frac{\partial \overline{u_i(\vec{x}, t)}}{\partial x_k}
	\end{equation}

	\begin{equation}
		\begin{aligned}
			\overline{u_j'(\vec{x} + \vec{r}, t+\tau) \frac{\partial [u_i'(\vec{x}, t)u_k'(\vec{x}, t)]}{\partial x_k}}
			& = \overline{\frac{\partial [u_i'(\vec{x}, t)u_k'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)]}{\partial x_k}} - \overline{u_i'(\vec{x}, t)u_k'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial x_k}}\\
			& = \frac{\partial R_{(ik)j}}{\partial x_k} - \overline{u_i'(\vec{x}, t)u_k'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial r_k}}\\
			& = \frac{\partial R_{(ik)j}}{\partial x_k} - \overline{\frac{\partial [u_i'(\vec{x}, t)u_k'(\vec{x}, t)u_j'(\vec{x} + \vec{r}, t+\tau)]}{\partial r_k}}\\
			& = \frac{\partial R_{(ik)j}}{\partial x_k} - \frac{\partial R_{(ik)j}}{\partial r_k}
		\end{aligned}
	\end{equation}

	\begin{equation}
		\overline{u_j'(\vec{x} + \vec{r}, t+\tau) \frac{\partial \overline{u_i'(\vec{x}, t)u_k'(\vec{x}, t)}}{\partial x_k}} = \overline{u_j'(\vec{x} + \vec{r}, t+\tau)} \frac{\partial \overline{u_i'(\vec{x}, t)u_k'(\vec{x}, t)}}{\partial x_k} = 0
	\end{equation}

	\begin{equation}
		\begin{aligned}
			\overline{u_j'(\vec{x} + \vec{r}, t+\tau) \frac{\partial p'(\vec{x}, t)}{\partial x_i}}
			& = \overline{\frac{\partial p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial x_i}} - \overline{p'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial x_i}}\\
			& = \frac{\partial \overline{p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial x_i} - \overline{p'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial (x_i + r_i)}}\\
			& = \frac{\partial \overline{p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial x_i} - \overline{p'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial r_i}}\\
			& = \frac{\partial \overline{p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial x_i} - \overline{\frac{\partial p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}{\partial r_i}}\\
			& = \frac{\partial \overline{p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial x_i} - \frac{\partial \overline{p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial r_i}
		\end{aligned}
	\end{equation}

	\begin{equation}
		\begin{aligned}
			& \overline{u_j'(\vec{x} + \vec{r}, t + \tau) \frac{\partial^2 u_i'(\vec{x}, t)}{\partial x_k \partial x_k}}
			= \overline{u_j'(\vec{x} + \vec{r}, t + \tau) \frac{\partial}{\partial x_k}\Bigg(\frac{\partial u_i'(\vec{x}, t)}{\partial x_k}\Bigg)}\\
			 = & \overline{\frac{\partial}{\partial x_k} \Bigg(u_j'(\vec{x} + \vec{r}, t + \tau) \frac{\partial u_i'(\vec{x}, t)}{\partial x_k}\Bigg)} - \overline{\frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial x_k} \frac{\partial u_i'(\vec{x}, t)}{\partial x_k}}\\
		= 	& \overline{\frac{\partial}{\partial x_k} \Bigg(\frac{\partial [u_j'(\vec{x} + \vec{r}, t + \tau) u_i'(\vec{x}, t)]}{\partial x_k} - u_i'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial x_k}\Bigg)} - \overline{\frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial x_k} \frac{\partial u_i'(\vec{x}, t)}{\partial x_k}}\\
			 = &\frac{\partial^2 R_{ij}}{\partial x_k \partial x_k} - \overline{\frac{\partial}{\partial x_k} \Bigg(u_i'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial r_k}\Bigg)} - \overline{\frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial x_k} \frac{\partial u_i'(\vec{x}, t)}{\partial x_k}}\\
			 =& \frac{\partial^2 R_{ij}}{\partial x_k \partial x_k} - \overline{\frac{\partial}{\partial x_k} \frac{\partial [u_i'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t + \tau)]}{\partial r_k}} - \overline{\frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial r_k} \frac{\partial u_i'(\vec{x}, t)}{\partial x_k}}\\
		 =	& \frac{\partial^2 R_{ij}}{\partial x_k \partial x_k} - \frac{\partial^2 R_{ij}}{\partial x_k \partial r_k} - \overline{\Bigg(\frac{\partial}{\partial x_k}\Bigg(u_i'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial r_k} \Bigg) - u_i'(\vec{x}, t) \frac{\partial^2 u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial x_k \partial r_k}\Bigg)}\\
		 = 	&\frac{\partial^2 R_{ij}}{\partial x_k \partial x_k} - \frac{\partial^2 R_{ij}}{\partial x_k \partial r_k} - \overline{\Bigg(\frac{\partial}{\partial x_k}\Bigg(\frac{\partial [u_i'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t + \tau)]}{\partial r_k} \Bigg) - u_i'(\vec{x}, t) \frac{\partial^2 u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial r_k \partial r_k}\Bigg)}\\
			 = &\frac{\partial^2 R_{ij}}{\partial x_k \partial x_k} - 2\frac{\partial^2 R_{ij}}{\partial x_k \partial r_k} + \overline{\frac{\partial^2 [u_i'(\vec{x}, t)u_j'(\vec{x} + \vec{r}, t + \tau)]}{\partial r_k \partial r_k}}\\
			 =& \frac{\partial^2 R_{ij}}{\partial x_k \partial x_k} - 2\frac{\partial^2 R_{ij}}{\partial x_k \partial r_k} + \frac{\partial^2 R_{ij}}{\partial r_k \partial r_k}\\
		\end{aligned}
	\end{equation}

	then, detailed expression for  $D^{(i)}\{R_{ij}\}$ is given as
	\begin{equation}
		\begin{aligned}
			D^{(i)}\{R_{ij}\} = \frac{\partial R_{ij}}{\partial t} - \frac{\partial R_{ij}}{\partial \tau} + \overline{u_k(\vec{x}, t)} \Bigg[\frac{\partial R_{ij}}{\partial x_k}- \frac{\partial R_{ij}}{\partial r_k}\Bigg] + R_{kj}\frac{\partial \overline{u_i(\vec{x}, t)}}{\partial x_k} \\ + \frac{\partial R_{(ik)j}}{\partial x_k} - \frac{\partial R_{(ik)j}}{\partial r_k} + \frac{1}{\rho} \Bigg(\frac{\partial \overline{p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial x_i} - \frac{\partial \overline{p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial r_i}\Bigg) \\ - \nu \Bigg(\frac{\partial^2 R_{ij}}{\partial x_k \partial x_k} - 2\frac{\partial^2 R_{ij}}{\partial x_k \partial r_k} + \frac{\partial^2 R_{ij}}{\partial r_k \partial r_k}\Bigg) - \overline{u_j'(\vec{x} + \vec{r}, t+\tau) f_i'(\vec{x}, t)} = 0
		\end{aligned}
	\end{equation}

	 For $D^{(j)}\{R_{ij}\} = \overline{u_i'(\vec{x}, t) N_j\{\vec{x} + \vec{r}, t + \tau\}}$, components in the expansion are calculated as
	 \begin{equation}
	 	\overline{u_i'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial (t + \tau)}} = \overline{u_i'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial \tau}} = \overline{ \frac{\partial u_i'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial \tau}} = \frac{\partial R_{ij}}{\partial \tau}
	 \end{equation}

	 \begin{equation}
	 	\begin{aligned}
	 		\overline{u_i'(\vec{x}, t) \overline{u_k(\vec{x} + \vec{r}, t + \tau)}\frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial (x_k + r_k)}}
	 		 = \overline{u_k(\vec{x} + \vec{r}, t + \tau)} \overline{u_i'(\vec{x}, t) \frac{\partial u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial r_k}}\\
	 		 = \overline{u_k(\vec{x} + \vec{r}, t + \tau)} \overline{\frac{\partial [u_i'(\vec{x}, t)u_j'(\vec{x} + \vec{r}, t + \tau)]}{\partial r_k}} = \overline{u_k(\vec{x} + \vec{r}, t + \tau)} \frac{\partial R_{ij}}{\partial r_k}
	 	\end{aligned}
	 \end{equation}

	 \begin{equation}
	 	\overline{u_i'(\vec{x}, t)u_k'(\vec{x} + \vec{r}, t + \tau)\frac{\partial \overline{u_j(\vec{x} + \vec{r}, t + \tau)}}{\partial (x_k+r_k)}} = R_{ik} \frac{\partial \overline{u_j(\vec{x} + \vec{r}, t + \tau)}}{\partial r_k}
	 \end{equation}

	 \begin{equation}
	 	\begin{aligned}
	 		\overline{u_i'(\vec{x}, t) \frac{\partial [u_j'(\vec{x} + \vec{r}, t + \tau)u_k'(\vec{x} + \vec{r}, t + \tau)]}{\partial  (x_k+r_k)}} = \overline{u_i'(\vec{x}, t) \frac{\partial [u_j'(\vec{x} + \vec{r}, t + \tau)u_k'(\vec{x} + \vec{r}, t + \tau)]}{\partial r_k}}\\
	 		= \overline{\frac{\partial [u_i'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t + \tau)u_k'(\vec{x} + \vec{r}, t + \tau)]}{\partial r_k}} = \frac{\partial R_{i(jk)}}{\partial r_k}
	 	\end{aligned}
	 \end{equation}

	 \begin{equation}
	 	\overline{u_i'(\vec{x}, t) \frac{\partial \overline{u_j'(\vec{x} + \vec{r}, t + \tau)u_k'(\vec{x} + \vec{r}, t + \tau)}}{\partial (x_k+r_k)}} = \overline{u_i'(\vec{x}, t)} \frac{\partial \overline{u_j'(\vec{x} + \vec{r}, t + \tau)u_k'(\vec{x} + \vec{r}, t + \tau)}}{\partial r_k} = 0
	 \end{equation}

	 \begin{equation}
	 	\overline{u_i'(\vec{x}, t) \frac{\partial p'(\vec{x} + \vec{r}, t + \tau)}{\partial (x_j + r_j)}} = \overline{u_i'(\vec{x}, t) \frac{\partial p'(\vec{x} + \vec{r}, t + \tau)}{\partial r_j}} = \overline{\frac{\partial p'(\vec{x} + \vec{r}, t + \tau)u_i'(\vec{x}, t)}{\partial r_j}}
	 \end{equation}

	 \begin{equation}
	 	\begin{aligned}
	 		\overline{u_i'(\vec{x}, t) \frac{\partial^2 u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial (x_k+r_k) \partial (x_k+r_k)}}
	 		&= \overline{u_i'(\vec{x}, t) \frac{\partial^2 u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial r_k \partial r_k}} \\
	 		& = \overline{ \frac{\partial^2 u_i'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t + \tau)}{\partial r_k \partial r_k}} = \frac{\partial R_{ij}}{\partial r_k \partial r_k}
	 	\end{aligned}
	 \end{equation}

	 then, detailed expression for  $D^{(j)}\{R_{ij}\}$ is given as
	 \begin{equation}
		 \begin{aligned}
		 	D^{(j)}\{R_{ij}\} = \frac{\partial R_{ij}}{\partial \tau} + \overline{u_k(\vec{x} + \vec{r}, t + \tau)} \frac{\partial R_{ij}}{\partial r_k} + R_{ik} \frac{\partial \overline{u_j(\vec{x} + \vec{r}, t + \tau)}}{\partial r_k} + \frac{\partial R_{i(jk)}}{\partial r_k} \\
		 	+ \frac{1}{\rho}\frac{\partial \overline{p'(\vec{x} + \vec{r}, t + \tau)u_i'(\vec{x}, t)}}{\partial r_j} - \nu \frac{\partial R_{ij}}{\partial r_k \partial r_k} - \overline{u_i'(\vec{x}, t) f_j'(\vec{x} + \vec{r}, t + \tau)} = 0
		 \end{aligned}
	 \end{equation}

	 Therefore, the two-point correlation equation is calculated as
	 \begin{equation}
	 	\begin{aligned}
	 		D^{(i)}\{R_{ij}\} + D^{(j)}\{R_{ij}\}
	 		= \frac{\partial R_{ij}}{\partial t}
	 		+ \overline{u_k(\vec{x}, t)} \frac{\partial R_{ij}}{\partial x_k}
	 		+ \Big[\overline{u_k(\vec{x} + \vec{r}, t + \tau)} - \overline{u_k(\vec{x}, t)}\Big]\frac{\partial R_{ij}}{\partial r_k}\\
	 		+ R_{kj}\frac{\partial \overline{u_i(\vec{x}, t)}}{\partial x_k} + R_{ik} \frac{\partial \overline{u_j(\vec{x} + \vec{r}, t + \tau)}}{\partial r_k}
	 		 + \frac{\partial R_{(ik)j}}{\partial x_k} - \frac{\partial [R_{(ik)j}-R_{i(jk)}]}{\partial r_k}\\
	 		 + \frac{1}{\rho} \Bigg(\frac{\partial \overline{p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial x_i} - \frac{\partial \overline{p'(\vec{x}, t) u_j'(\vec{x} + \vec{r}, t+\tau)}}{\partial r_i} + \frac{\partial \overline{p'(\vec{x} + \vec{r}, t + \tau)u_i'(\vec{x}, t)}}{\partial r_j}\Bigg) \\
	 		 - \nu \Bigg(\frac{\partial^2 R_{ij}}{\partial x_k \partial x_k} - 2\frac{\partial^2 R_{ij}}{\partial x_k \partial r_k} + 2\frac{\partial^2 R_{ij}}{\partial r_k \partial r_k}\Bigg) - \overline{u_j'(\vec{x} + \vec{r}, t+\tau) f_i'(\vec{x}, t)}
	 		 - \overline{u_i'(\vec{x}, t) f_j'(\vec{x} + \vec{r}, t + \tau)} = 0
	 	\end{aligned}
	 \end{equation}

\section{Exercise 2}
	Refer to (\ref{eq:sns}), kinetic energy equation of each velocity component is given as
	\begin{equation}
		\begin{aligned}
			u_1'N_1 & = 0\\
			u_2'N_2 & = 0\\
			u_3'N_3 & = 0\\
		\end{aligned}
		\label{eq:kc}
	\end{equation}
	In the pure shear flow case, assumptions can be made as
	\begin{equation}
		\begin{aligned}
			\frac{\partial}{\partial x_1} & = \frac{\partial}{\partial x_3} = 0\\
			U_2 & = U_3 = 0\\
			U_1 & = f(x_2)
		\end{aligned}
	\end{equation}
	Hence, (\ref{eq:kc}) can be simplified as
	\begin{equation}
		\begin{aligned}
			\frac{\overline{D}}{\overline{D} t}\Big(\frac{u_1'^2}{2}\Big) & = -u_2' u_1'\frac{\partial U_1}{\partial x_2} - u_1'\frac{\partial [u_1'u_2']}{\partial x_2} + u_1'\frac{\partial \overline{u_1' u_2'}}{\partial x_2} + u_1'\nu \frac{\partial^2 u_1'}{\partial x_2 \partial x_2}\\
			\frac{\overline{D}}{\overline{D} t}\Big(\frac{u_2'^2}{2}\Big) & = -u_2'\frac{\partial [u_2'u_2']}{\partial x_2} + u_2'\frac{\partial \overline{u_2' u_2'}}{\partial x_2} - \frac{u_2'}{\rho}\frac{\partial p'}{\partial x_2}+ u_2'\nu \frac{\partial^2 u_2'}{\partial x_2 \partial x_2}\\
			\frac{\overline{D}}{\overline{D} t}\Big(\frac{u_3'^2}{2}\Big) & = -u_3'\frac{\partial [u_3'u_2']}{\partial x_2} + u_3'\frac{\partial \overline{u_3' u_2'}}{\partial x_2} + u_3'\nu \frac{\partial^2 u_3'}{\partial x_2 \partial x_2}\\
		\end{aligned}
		\label{eq:kt}
	\end{equation}
	where
	\begin{equation}
		\frac{\overline{D}}{\overline{D} t} = \frac{\partial}{\partial t} + U_k \frac{\partial}{\partial x_k}
	\end{equation}
	and it should be noted that the $U_k \frac{\partial}{\partial x_k}$ term vanishes in (\ref{eq:kt}).\\
	Estimations on each term can be made respectively.\\
	For the first equation in (\ref{eq:kt})
	\begin{equation}
		\begin{aligned}
			u_2' u_1'\frac{\partial U_1}{\partial x_2} & \sim \frac{u'^2 U}{L}\\
			u_1'\frac{\partial [u_1'u_2']}{\partial x_2} & \sim \frac{u'^3}{L}\\
			u_1'\frac{\partial \overline{u_1' u_2'}}{\partial x_2} & \sim u'\nu \frac{\partial U_1}{\partial x_2} \sim \nu \frac{u' U}{L}\\
			u_1'\nu \frac{\partial^2 u_1'}{\partial x_2 \partial x_2} & \sim \nu \frac{u'^2}{L^2}
		\end{aligned}
	\end{equation}

	For the second equation in (\ref{eq:kt})
	\begin{equation}
		\begin{aligned}
			u_2'\frac{\partial [u_2'u_2']}{\partial x_2} & \sim \frac{u'^3}{L}\\
			u_2'\frac{\partial \overline{u_2' u_2'}}{\partial x_2} & \sim \frac{u'^3}{L}\\
			\frac{u_2'}{\rho}\frac{\partial p'}{\partial x_2} & \sim \frac{u'}{\rho} \rho \\
			u_2'\nu \frac{\partial^2 u_2'}{\partial x_2 \partial x_2} & \sim \nu \frac{u'^2}{L^2}
		\end{aligned}
	\end{equation}

	For the third equation in (\ref{eq:kt})
	\begin{equation}
		\begin{aligned}
			u_3'\frac{\partial [u_3'u_2']}{\partial x_2} & \sim \frac{u'^3}{L}\\
			u_3'\frac{\partial \overline{u_3' u_2'}}{\partial x_2} & \sim \frac{u'^3}{L}\\
			u_3'\nu \frac{\partial^2 u_3'}{\partial x_2 \partial x_2} & \sim \nu \frac{u'^2}{L^2}
		\end{aligned}
	\end{equation}

\end{document}


\documentclass[twoside]{MATH77}
\usepackage{multicol}
\usepackage[fleqn,reqno,centertags]{amsmath}
\begin{document}
\begmath 2.1 Inverse Hyperbolic Functions

\silentfootnote{$^\copyright$1997 Calif. Inst. of Technology, \thisyear \ Math \`a la Carte, Inc.}

\subsection{Purpose}

These subprograms compute the inverse hyperbolic functions.

\subsection{Usage}

\subsubsection{Program Prototype, Single Precision}

\begin{description}
\item[REAL]  \ {\bf X, U, SASINH, SACOSH, SATANH, SACTNH, SASECH, SACSCH}
\end{description}

Assign a value to X and obtain the desired value of an inverse hyperbolic
function using one of the following:
\begin{center}
\begin{tabular}{l@{\hspace{.3in}}l}
\fbox{\bf U = SASINH(X)} & \fbox{\bf U = SACOSH(X)}\\\\
\fbox{\bf U = SATANH(X)} & \fbox{\bf U = SACSCH(X)}\\\\
\fbox{\bf U = SASECH(X)} & \fbox{\bf U = SACTNH(X)}
\end{tabular}
\end{center}
where the functions SASINH, ..., SACTNH compute respectively, the inverse
hyperbolic: sine, cosine, tangent, cosecant, secant, and cotangent.

\subsubsection{Program Prototype, Double Precision}

For double precision computation use the function names DASINH, DACOSH,
DATANH, DACSCH, DASECH, and DACTNH and type the argument, function name and
result double precision.

\subsection{Example and Remarks}

See DRSASINH and ODSASINH for an example of the usage of these subprograms.

\subsection{Functional Description}

\subsubsection{Method}

The basic formulas and valid argument domains are
\begin{equation*}
\hspace{-15pt}\begin{array}{ll}
\asinh(x) = \sgn (x) \ln (|x| + \sqrt {x^2+1})& \text{all }x\\
\acosh(x) = \ln (x + \sqrt {x^2-1})& x \geq 1\\
\atanh(x) = \frac{1}{2} \sgn (x) \ln ((1+|x|)/(1-|x|))& |x| < 1\\
\acsch(x) = \asinh(1/x)& x \neq 0\\
\asech(x) = \acosh(1/x)& 0 < x \leq 1\\
\actnh(x) = \atanh(1/x)& |x| > 1
\end{array}
\end{equation*}
To avoid unnecessary loss of relative accuracy as function values approach
zero, a different method is used whenever the argument of the logarithm
function would be in the range [1.0,~2.718]. In this range the argument for
acosh or atanh is converted to an argument for asinh, and asinh is computed
by argument reduction to the interval [0.0,~0.125326] followed by evaluation
of its Taylor series. The number of terms needed in this series is
determined by use of the System Parameters subprogram, Chapter~19.1. The
prestored coefficients will support accuracy to about 25 significant decimal
digits.

For large arguments the formulas involving $x^2$ are reformulated to avoid
unnecessary overflow. Specifically, when $x > 10^{16}$ it is presumed that $%
x^2 \pm 1$ will not be distinguishable from $x^2$, and thus the formulas
given above for asinh and acosh are replaced by
\begin{align*}
\asinh(x) &= \sgn (x) [\ln (2) + \ln (|x|)], \quad \text{and}\\
\acosh(x) &= \ln (2) + \ln (x)
\end{align*}
Let $\Omega $ denote the machine overflow limit and $\rho $ denote
the difference between $1.0$ and the next smaller machine number. Define $a
= \frac{1}{2} \ln (2/\rho )$ and $b = \ln (2\Omega )$. Then the
ranges of the computed function values are
\begin{equation*}
\begin{array}{l@{\qquad }l}
|\asinh(x)\,| < b & 0 \leq \acosh(x) < b\\
|\atanh(x)\,| \leq a & 0 < |\acsch(x)\,| < b\\
0 \leq \asech(x) < b & 0 < |\actnh(x)\,| \leq a
\end{array}
\end{equation*}
\subsubsection{Accuracy Tests}

The single precision subprograms were tested on an IBM compatible PC
by comparison with the double precision subprograms at 300,000 to
800,000 points in the domain of each function.
Using $\rho = 2^{-23} \approx 0.119 \times 10^{-6}$, which is the relative
precision of IEEE single precision arithmetic, these tests may be
summarized as follows:
\begin{center}
\begin{tabular}{lcr}
& \multicolumn{1}{c}{\bf Argument} & \multicolumn{1}{c}{\bf Max. Rel.}\\
\multicolumn{1}{c}{\bf Function} & \multicolumn{1}{c}{\bf Range} &
\multicolumn{1}{c}{\bf Error}\\
SASINH & All $x$ & 0.9 $\rho $\rule[-7pt]{0pt}{8pt}\phantom{~el.}\\
SACOSH & [1.00, 1.21] & 1.6 $\rho $\phantom{~el.}\\
 & $x \geq 1.21$ & 0.5 $\rho $\rule[-7pt]{0pt}{8pt}\phantom{~el.}\\
SATANH & [$-$0.44, 0.44] & 1.3 $\rho $\phantom{~el.}\\
 & [0.44, 0.92] & 1.3 $\rho $\phantom{~el.}\\
 & [0.92, 1.0] & 0.5 $\rho $\rule[-7pt]{0pt}{8pt}\phantom{~el.}\\
SACSCH & $x \neq 0$  & 0.9 $\rho $\rule[-7pt]{0pt}{8pt}\phantom{~el.}\\
SASECH & [0.0, 0.24]  & 0.8 $\rho $\phantom{~el.}\\
 & [0.24, 0.68] & 1.2 $\rho $\phantom{~el.}\\
 & [0.68, 0.88] & 3.2 $\rho $\phantom{~el.}\\
 & [0.88, 1.] & 989.1 $\rho $\rule[-7pt]{0pt}{8pt}\phantom{~el.}\\
SACTNH & [1.0, 1.16] & 153.5 $\rho $\phantom{~el.}\\
 & [1.16, 2.2] & 1.7 $\rho $\phantom{~el.}\\
 & $x \geq 2.2$ & 1.6 $\rho $\phantom{~el.}
\end{tabular}
\end{center}
The instances of very large relative errors in this table are in regions
where the slope of the graph of the function is becoming vertical.
Note that relative errors may be significantly larger on machines
that do not have proplerly rounded arithmetic.

The functions were tested using identities of the form $x - \sinh(\asinh(x)) =
0$.  When scaled by the precision of the arithmetic used, the double precision
and single precision functions had similar perfomance.

\subsection{Error Procedures and Restrictions}

If an argument is outside the valid domain, an error message will be
issued, and the value zero will be returned.  Error messages are
processed using the subroutines of Chapter~19.2 with an error level of zero.

\subsection{Supporting Information}

The source language for these subroutines is ANSI Fortran 77.

All double precision entries are in the file DASINH, which also needs
files: AMACH, DERM1, DERV1, ERFIN, and ERMSG.

All single precision entries are in the file SASINH, which also needs
files: AMACH, ERFIN, ERMSG, SERM1, and SERV1.

Designed and programmed by C. Lawson and S. Chiu, JPL, 1983. Modified Nov.,
1988 to use R1MACH and D1MACH.

\begin{tabular}{ll@{\hspace{.3in}}ll}
\multicolumn{4}{c}{\bf Entries\rule[-6pt]{0pt}{8pt}}\\
DACOSH & DACSCH & SACOSH & SACSCH\\
DACTNH & DASECH & SACTNH & SASECH\\
DASINH & DATANH & SASINH & SATANH\\
\end{tabular}

\begcodenp

\medskip\
\lstset{language=[77]Fortran,showstringspaces=false}
\lstset{xleftmargin=.8in}

\centerline{\bf \large DRSASINH}\vspace{10pt}
\lstinputlisting{\codeloc{sasinh}}

\vspace{30pt}\centerline{\bf \large ODSASINH}\vspace{10pt}
\lstset{language={}}
\lstinputlisting{\outputloc{sasinh}}
\end{document}


\documentclass{article}

\usepackage{arxiv}

\usepackage[utf8]{inputenc} % allow utf-8 input
\usepackage[T1]{fontenc}    % use 8-bit T1 fonts
\usepackage{hyperref}       % hyperlinks
\usepackage{url}            % simple URL typesetting
\usepackage{booktabs}       % professional-quality tables
\usepackage{amsfonts}       % blackboard math symbols
\usepackage{nicefrac}       % compact symbols for 1/2, etc.
\usepackage{microtype}      % microtypography
\usepackage{lipsum}		% Can be removed after putting your text content
\usepackage{amssymb,amsmath,amsthm}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{apacite}

\newtheorem{theorem}{Theorem}

\title{Sampling from the Bayesian poster of an agent-based model given partial observations}

%\date{September 9, 1985}	% Here you can change the date presented in the paper title
%\date{} 					% Or removing it

\author{
  Daniel Tang\\
  Leeds Institute for Data Analytics\thanks{This project has received funding from the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No. 757455)}\\
  University of Leeds\\
  Leeds, UK\\
  \texttt{D.Tang@leeds.ac.uk} \\
  %% examples of more authors
  %% \AND
  %% Coauthor \\
  %% Affiliation \\
  %% Address \\
}

\begin{document}
\maketitle

\begin{abstract}
abstract
\end{abstract}

% keywords can be removed
\keywords{Data assimilation, Bayesian inference, Agent based model, Integer linear programming, predator prey model}

\section{Introduction}
%##########################################

Suppose we have a closed, convex polyhedron defined as
\begin{equation}
AX = B
\label{polyhedron}
\end{equation}
subject to
\[
x_i \in \mathbb{Z}_{\ge 0}
\]
for all $i$, where $X = x_1...x_n$. And a probability distribution over the space of X
\begin{equation}
P(X) = \prod_i \omega_i^{x_i}
\label{probability}
\end{equation}
Our aim is to sample from valid points (i.e. those that satisfy the constraints) with the given probability distribution.

\section{Pivot sampling}

\begin{theorem}
For any two extreme positive, integer solutions of $AX_a = B$ and $AX_b = B$ there exists a sequence of positive solutions $X_0...X_N$ such that $X_0 = X_a$, $X_N = X_b$ and there exists a sequence of pivots $\pi_1...\pi_N$ such that pivoting at these points produces the sequence of solutions $X_0...X_N$.
\end{theorem}

\begin{proof}
Start with a full pivot with $X_a$ as a solution. Now let $C$ be the set of events/columns in $X_b$ that are not currently pivoted-in and let $R$ be the set of rows whose currently pivoted columns are not in $X_a \cup X_b$. While there exists a column $j \in C$ and a row $i \in R$ such that $A_{ij} = \pm 1$ pivot on $(i,j)$. Since all rows with pivoted columns not in $X_a$ have $B_i = 0$ then, $i \in R \implies B_i = 0$ so the pivot does not alter the solution.

All remaining events/columns in $C$ must have all rows in $R$ either $0$, $>1$ or $<-1$.

If there is an event/column with all rows in $R$ equal to $0$, then we have found a loop in $X_b-X_a$ which must be positive [proof? no subset of $X_b - X_a$ can, when added to $X_a$ result in a negative number], so we can pivot it in.

So, we need to show that it is impossible that we end up with all multiple occupation numbers outside of $X_a \cup X_b$ for all columns/events left in $C$. For Fermionic ABMs this is necessarily true [proof?].

If we choose a currently pivoted-in event at random and fan out along currently pivoted-in events according to the original constraint matrix for those events, then each row has a "distance" from that point. If we pivot as soon as we reach a row that contains a pivot of an event in $C$, then ...?

Multiple occupation can only occur for interactions (disregarding predicates) so there must remain only interactions in $C$. Also, if interactions must have only singleton states in the original constraint matrix, there must exist singleton events in the pivoted equivalent. So all these singleton events must be in $X_a \cup X_b$ if all events in $R$ are multiply occupied.

At any point during pivoting, there must exist events in $C$ that

If a column has multiple occupation on all rows in $R$, there must be at least one member of $C$ which replaces at least some of these multiple occupations, since in the final pivot, these will all be zero. But maybe this too has all multiple occupations in $R$. This can't go on forever though...at some point the event must join to $X_a$ in at least one point.

Consider a branch that has multiple occupation in a column

\end{proof}

(Assume partially observed start/end conditions)

Start with the agent conservation equations.

Find the nearest positive corner points to $X_a$ and $X_b$ (call them $X_a'$ and $X_b'$) and make those the first and last transitions.

Form the tree from sources to sinks where nodes are agent-state/timestep pairs and parents are events in $X_a$ that have the node state as a consequence. Since $X_a$ is an extreme point, this tree must exist. Now add agent-state/timestep nodes in $X_b$ that aren't in $X_a$. Now add events in $X_b$ that join sources from separate trees. The remaining events in $X_b$ are pivots. [we can add one more loop for the root of the tree...but which one?].

[Better to think in terms of loops rather than trees?]

%Form the bipartite graph with rows-id's on the left and column-id's on the right with edges where there is a non-zero element in (row,column) in $A$. Add only columns with non-zero values in $X_a'$ of $X_b'$. Find a maximal one-one mapping $\mu$ that contains all non-zero columns in $X_a'$ as a subset (this must exist since $X_a'$ is a corner).

Each edge represents a pivot point. Pivot on each edge in the one-one mapping. The remaining edges $\pi_1...\pi_N$ are pivot points in the sequence.

Since $X_a'$ and $X_b'$ are trees, each $\pi_i$ must be a point where the b-tree joins the a-tree.

Each pivot has the effect of clipping off a subtree and adding the root of the subtree to the children of another node. If all edges are positive edges, then the solution is positive.

Each new branch may "require" other agents to be present at certain space-time points. Since the requirements of an event may only contain events in a previous timestep, there cannot be cycles of requirements. So, if we take the pivot with the earliest time, all its requirements must be fulfilled (otherwise $X_b$ would not be a solution), so we arrange the pivots in chronological order and there's the answer!

%\bibliographystyle{unsrtnat}
%\bibliographystyle{apalike}
\bibliographystyle{apacite}
\bibliography{references}

\end{document}


\section{Genetic Operators}\label{sec:genetic_operators}
As has been mentioned, genetic operators are applied to members of an existing population to generate a new population. For this assignment the operators used included reproduction, crossover and mutation. As detailed by Koza and Poli \cite{koza2005genetic}, these operators can be briefly summarized as follows:

\begin{itemize}
    \item Reproduction: Copy the selected individual program to the new population as is.
    \item Crossover: Create offspring for the new population by combining randomly chosen parts from two selected programs.
    \item Mutation: Create one new offspring for the new population by randomly mutating a randomly chosen part of a selected individual.
\end{itemize}

Of course, these operators will not be used uniformly to generate new populations. Rather, every operator is associated with a probability which determines the likelihood that it will be used to select the next individual for the new population. In an attempt to determine the most effective probabilities for the operators, 10 tests were run using each of three different combinations of probabilities. The best fitness achieved by each combination is summarized in table \ref{tab:genetic_operator_combinations}.

\begin{table}[H]
\resizebox{\textwidth}{!}{\begin{tabular}{|c|c|c|c|}
\hline
\textbf{Crossover Probability} & \textbf{Reproduction Probability} & \textbf{Mutation Probability} & \textbf{Best Fitness} \\ \hline
0.8                            & 0.1                               & 0.1                           & 9                     \\ \hline
0.9                            & 0.05                              & 0.05                          & 10                    \\ \hline
0.95                           & 0.025                             & 0.025                         & 10                    \\ \hline
\end{tabular}}
\caption{Genetic Operator Combinations}
\label{tab:genetic_operator_combinations}
\end{table}

Following the results of the tests summarized in table \ref{tab:genetic_operator_combinations}, the probability for crossover was selected as 0.8, the probability for mutation was selected as 0.1 and the probability for mutation was also selected as 0.1.

In addition, when applying operators decisions must be made regarding whether to select internal or leaf nodes. The probability for selecting a leaf node was chosen as 0.1 whereas the probability for selecting an internal node was chosen as 0.9.

Finally, a maximum tree depth of 16 was applied as a constraint to the individuals of a new population. In the case of crossover and mutation, the operators would try to produce a valid individual up to 10 times before proceeding to the application of the next operator.

With the selection methods and genetic operators having been identified, figure \ref{fig:breeding_pipeline} depicts the entire breeding pipeline for generating a new population from an existing population.

\begin{figure}[H]
\centering
\includegraphics[width=\textwidth]{report/05_genetic_operators/breeding_pipeline.png}
\caption{Breeding Pipeline}
\label{fig:breeding_pipeline}
\end{figure}


\documentclass[../main.tex]{subfiles}

\begin{document}

\section{Operations, Primitives and Algorithms}
The following sections introduce, define and explain Operations, Primitives and Algorithms generally using the Terminology presented below. Operations are the building blocks of Primitives whereas Primitives are the building blocks of Algorithms. The definitions which follow are flexible enough to support implementation across programing languages but have been inspired by the core concepts found within Lisp and Z. The focus of these sections is to define the properties of and interactions between Operations, Primitives and Algorithms in a general way which doesn't place unnecessary bounds on their range of possible functionality with respect to processing xAPI data.

\subsection{Terminology}

Within this document, (s) indicates one or more.

\subsubsection{Scalar}
When working with xAPI data, Statements are written using \href{https://www.json.org/}{JavaScript Object Notation} (JSON).
This data model supports a few fundamental types as described by \href{https://json-schema.org/understanding-json-schema/reference/type.html}{JSON Schema}.
In order to speak about a singular valid JSON value (string, number, boolean, null) generically, the term Scalar is used.
To talk about a scalar within a Z Schema, the following free and basic types are introduced.
\begin{zed}
  [STRING, NULL] \\
  Boolean :== true ~| ~false \\
  Scalar :== Boolean ~| ~STRING ~| ~NULL ~| ~\num
\end{zed}
Arrays and Objects are also valid JSON values but will be referenced using the terms Collection and Map $\lor$ KV respectively.

\subsubsection{Collection}
a sequence $\langle ... \rangle$ of items $c$ such that each $c : \nat \cross V \implies (\nat, V) \implies \nat \mapsto V$
\begin{axdef}
  C : Collection
  \where
  C = \langle c_{i}..c_{n}..c_{j} \rangle \implies \{~i \mapsto c_{i}, n \mapsto c_{n}, j \mapsto c_{j} \} @
  i \leq n \leq j \implies i \prec n \prec j \iff i \not= n \not= j
\end{axdef}
And the following free type is introduced for collections
\begin{argue}
  Collection :== emptyColl ~| ~append \ldata Collection \cross Scalar ~\lor Collection ~\lor KV \cross \nat \rdata \\
  \t1 emptyColl & the empty Collection $\langle  \rangle$ \\
  \t1 append & is a constructor and is inferred to be an injection \\
  \t1 KV & a free type introduced bellow \\
  append(emptyColl, c?, 0) = \langle c_{0} \rangle \implies \{~0 \mapsto c?\} & $append$ adds $c?$ to $\langle  \rangle$ at $\nat$
\end{argue}

\subsubsection{Key}

An identifier $k$ paired with some value $v$ to create an ordered pair $(k, v)$. $k$ can take on any valid JSON value (Scalar, Collection, KV)
except for the Scalar null. The following free type is introduced for keys.
\begin{zed}
  K ::= (Scalar \hide NULL) ~| ~Collection ~| ~KV
\end{zed}

\subsubsection{Value}

A value $v$ is paired with an identifier $k$ to create an ordered pair $(k, v)$. $v$ can be any valid JSON value (Scalar, Collection, KV)
The following free type is introduced for values.

\begin{zed}
  V ::= Scalar ~| ~Collection ~| ~KV
\end{zed}

\subsubsection{Map}
Within the Z Notation Introduction section, Maps are introduced using the free type $KV$.
\begin{zed}
  KV ::= base ~| ~associate \ldata~KV \cross X \cross Y \rdata
\end{zed}
This definition is more accurately
\begin{zed}
  KV ::= base ~| ~associate \ldata~KV \cross K \cross V \rdata
\end{zed}
which indicates the usage of Key $k$ and Value $v$ within $associate$. Using this updated definition,
\begin{zed}
  associate(base, k, v) = \ldata (k, v) \rdata
\end{zed}
such that a Map is a Collection of ordered pairs $(k_{n}, v_{n})$ and thus a Collection of mappings
\begin{zed}
  (k_{n}, v_{n}) \implies k_{n} \mapsto v_{n}
\end{zed}
but Maps are special cases of Collections as $k_{n}$ is the unique identifier of $v_{n}$ within a Map
but the opposite is not true. In fact, keys are their own identifiers
\begin{zed}
  \id v_{n} = k_{n} \\
  \id k_{n} \not= v_{n} \\
  \id k_{n} = k_{n}
\end{zed}
Given a Map $M = \ldata (k_{i}, v_{i})~..~(k_{n}, v_{n})~..~(k_{j}, v_{j}) \rdata$ the following demonstrates the uniqueness of Keys
but the same is not true for all $v$ within $M$
\begin{zed}
  k_{i} \not= k_{n} \not= k_{j} \\
  v_{i} = v_{n} \lor v_{i} \not= v_{n} \
  v_{i} = v_{j} \lor v_{i} \not= v_{j} \
  v_{j} = v_{n} \lor v_{j} \not= v_{n}
\end{zed}
which can all be stated formally as
\begin{gendef}[K, V]
  Map : K \cross V \bij KV
  \where
  Map = \ldata (k_{i}, v_{i})~..~(k_{n}, v_{n})~..~(k_{j}, v_{j}) \rdata @ \\
  \t1 \dom Map = \{~ k_{i}~..~k_{n}~..~k_{j}\} \\
  \t1 \ran Map = \{~v_{i}~..~v_{n}~..~v_{j}\} \\
  \t1 first(k_{i}, v_{i}) \not= first(k_{n}, v_{n}) \not= first (k_{j}, v_{j}) ~\land \\
  \t1 v_{i} = v_{n} \lor v_{i} \not= v_{n} \ v_{i} = v_{j} \lor v_{i} \not= v_{j} \ v_{j} = v_{n} \lor v_{j} \not= v_{n} ~\land \\
  \t1 \id ~v_{i} = k_{i} ~\land \id ~v_{n} = k_{n} ~\land \id ~v_{j} = k_{j} ~\land \\
  \t1 \id ~k_{i} = k_{i} ~\land \id ~k_{n} = k_{n} ~\land \id k_{j} = k_{j}
\end{gendef}
Given that $v$ can be a Map $M$, or a Collection $C$, Arbitrary nesting is allowed within Maps but the properties of a Map hold at any depth.
$$M = \ldata (k_{i}, v_{i})~..~(k_{n}, \ldata (k_{ni}, v_{ni}) \rdata)~..(k_{j}, \langle v_{ji}~..~\ldata (k_{jn}, v_{jn}) \rdata~..~\langle v_{jji}~..~v_{jjn}~..~v_{jjj}\rangle\rangle) \rdata$$
such that $\ldata (k_{ni}, v_{ni}) \rdata$ and $\ldata (k_{nj}, v_{nj}) \rdata$ are both Maps and adhere to the constraints enumerated above.

\subsubsection{Statement}

Immutable Map conforming to the \href{https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#24-statement-properties}{xAPI Specification} as described in the xAPI Formal Definition section of this document. The immutability of a Statement $s$ is demonstrated by the following
which indicates that $s$ was not altered when passed to $associate$.
\begin{axdef}
  s!, s? : STATEMENT \\
  k? : K \\
  v? : V \\
  \where
  s! = associate(s?, k?, v?) = s? \implies (k?, v?) \not \in s! \implies s! = s? \\
\end{axdef}
 Additionally, given the schema $Statements$ the following is true for all $Statement$(s)
\begin{axdef}
  Statements \\
  Keys : STRING \\
  S : Collection
  \where
  Keys = \{~id, actor, verb, object, result, context, attachments, timestamp, stored\} \\
  \dom statement = K \dres Keys \\
  S = \langle ~statement_{i}~..~statement_{n}~..~statement_{j} \rangle @ \\
  \t1 atKey(statement_{i}, id) \not= atKey(statement_{n}, id) \not= atKey(statement_{j}, id) \implies \\
  \t1 id_{i} \not= id_{n} \not= id_{j} \iff statement_{i} \not= statement_{n} \not= statement_{j}
\end{axdef}
Which confirms the constraints found in the schema $Statement$ and adds an additional constraint
to $Statements$ such that every unique $Statement$ in a $Collection$ of $Statements$ has a unique $id$.

\subsubsection{Algorithm State}

Mutable Map $state$ without any domain restriction such that
\begin{axdef}
  state?, state! : KV \\
  k? : K \\
  v? : V
  \where
  associate(state?, k?, v?) = state! @ (k, v) \in state! \implies state? \not= state!
\end{axdef}

\subsubsection{Option}

Mutable Map $opt$ which is used to alter the result of an Algorithm. The effect of $opt$ on an Algorithm will be discussed in the Algorithm Result section bellow.

\section{Operation}

An Operation is a function of arbitrary arguments and is defined using Z. For example, Operations pulled directly from "The Z Notation: A Reference Manual" include
\begin{itemize}
\item $first$
\item $second$
\item $succ$
\item $\min$
\item $\max$
\item $count \equiv \#$
\item $\cat$
\item $rev$
\item $head$
\item $last$
\item $tail$
\item $front$
\item $\extract$
\item $\filter$
\item $\dcat$
\item $\disjoint$
\item $\partition$
\item $\otimes$
\item $\uplus$
\item $\uminus$
\item $items$
\end{itemize}

\subsection{Domain}
The arguments passed to an Operation can be any of the following but the definition of an Operation may limit the domain to a subset of the following
\begin{itemize}
\item Key(s)
\item Value(s)
\item Set(s)
\item Collection(s)
\item Bag(s)
\item KV(s)
\item Statement(s)
\item Algorithm State
\end{itemize}

\subsection{Range}
The result of an Operation can be any of the following but the definition of an Operation may limit this range to a subset of the following

\begin{itemize}
\item Key(s)
\item Value(s)
\item Set(s)
\item Collection(s)
\item Bag(s)
\item KV(s)
\item Statement(s)
\item Algorithm State
\end{itemize}

\section{Primitive}
Primitives break the processing of xAPI data down into discrete units that can be composed to create new analytical functions.
Primitives allow users to address the methodology of answering research questions as a sequence of generic algorithmic steps
which establish the necessary data transformations, aggregations and calculations required to reach the solution in an implementation agnostic way.

Within this document, they will be defined as a Collection of Operations and/or Primitives where the output is piped from member to member.
In this section, $o_{n}$ and $p_{n}$ can be used as to describe Primitive members but for simplicity, only $o_{n}$ will be used.
\begin{zed}
  p_{\langle i~..~n~..~j \rangle} = o_{i} ~\pipe ~o_{n} ~\pipe ~o_{j}
\end{zed}
Within any given Primitive $p$, variables local to $p$ and any global variables may be passed as arguments to any member of $p$
and there is no restriction on the ordering of arguments with respect to the piping.
In the following, $q?$ is a global variable whereas the rest are local.
\begin{axdef}
  x?, y?, z?, i!, n!, j!, p! : Value \\
  o_{i} : Value \pfun Value \\
  o_{n} : Value \cross Value \pfun Value \\
  o_{j}, p : Value \cross Value \cross Value \pfun Value \\
  \where
  i! = o_{i}(x?) \\
  n! = o_{n}(i!, y?) \\
  j! = o_{j}(z?, n!, q?) \\
  p! = j! \implies o_{j}(z?, o_{n}(o_{i}(x?), y?), q?)
\end{axdef}
In the rest of this document, the following notation is used to distinguish between
the functionality of a Primitive and its composition. This notation should be used when defining Primitives.
\begin{axdef}
  primitiveName~\_ : ~\_~\pfun~\_
  \where
  primitiveName = \langle primitiveName_{i}~\_~..~primitiveName_{n}~\_~..~primitiveName_{j}~\_~ \rangle
\end{axdef}
\begin{itemize}
\item The top line indicates the Primitive
  \begin{itemize}
  \item should be written using postfix notation within other schemas
  \item is at least a partial function from some input to some output
  \end{itemize}
\item The bottom line is an enumeration of the composing Operations and/or Primitives and their order of execution
\end{itemize}
This means the definition of $p$ from above can be updated as follows.
\begin{axdef}
  p~\_ : Value \cross Value \cross Value \pfun Value
  \where
  p = \langle ~o_{i}, ~o_{n}, ~o_{j} \rangle \\
  p(x?, y?, z?) = o_{j}(z?, o_{n}(o_{i}(x?), y?), q?)
\end{axdef}
Additionally, this notation supports declaration of recursive iteration via the presence of $recur~\_$ within a Primitive chain
\begin{axdef}
  primitiveName_{i} = \langle \langle  primitiveName_{ii}~\_~, primitiveName_{in}~\_ ~\rangle, ~ recur~\_ ~ \rangle \bsup \#~\_ \esup
  \where
  \langle \langle primitiveName_{ii}~\_~, primitiveName_{in}~\_ ~\rangle, ~ recur~\_ ~ \rangle \bsup \#~\_ \esup \implies \\
  \t2 (primtiveName_{ii} ~\pipe ~primitiveName_{in}) \bsup \#~\_ \esup @ \\
  \t3 \forall ~n : i~..~j @ j = \#~\_ ~ \land ~i ~\leq ~n ~\leq j ~|~ \exists_1 p_{n} : ~\_~\pfun \_\_ \pfun~\_ @ \\
  \t4 let ~~ \ \ p_{i} == primtiveName_{ii} ~\pipe ~primitiveName_{in} \implies \\
  \t6 p_{i}~\_ = primitiveName_{in}(primitiveName_{ii}~\_)  \\
  \t5 p_{n} == p_{i} ~\pipe ~ primtiveName_{ii} ~\pipe ~primitiveName_{in} \implies\\
  \t6 p_{n}~\_ = primitiveName_{in}(primitiveName_{ii}(p_{i}~\_)) \\
  \t5 p_{j} == p_{n} ~\pipe ~ primtiveName_{ii} ~\pipe ~primitiveName_{in} \implies\\
  \t6 p_{j}~\_ = primitiveName_{in}(primitiveName_{ii}(p_{n}~\_)) \\
  \t3 p_{j} = (primtiveName_{ii} ~\pipe ~primitiveName_{in}) \bsup \#~\_ \esup @ j = 3 \implies \\
  \t5 ~ (primtiveName_{ii} ~\pipe ~primitiveName_{in}) ~ \pipe \\
  \t5 ~ (primtiveName_{ii} ~\pipe ~primitiveName_{in}) ~ \pipe \\
  \t5 ~ (primtiveName_{ii} ~\pipe ~primitiveName_{in}) \implies \\
  \t6 primitiveName_{in}( \\
  \t7 primitiveName_{ii}( \\
  \t8 primitiveName_{in}( \\
  \t9 primitiveName_{ii}(p_{i}~\_))))
\end{axdef}
Here, $p_{i}$ was chosen to only be two primitives $primtiveName_{ii} ~ \land ~ primitiveName_{in}$ for simplicity sake.
The Primitive chain can be of arbitrary length. The number of iterations is described using the count operation $\#~\_$.
Above $j = 3$ was used to demonstrate the piping between iterations but $j$ is not exclusively $= 3$. Given above,
the term Primitive Chain can be defined as:
\begin{zed}
  (primtiveName_{i} ~\pipe ~primitiveName_{n} ~ \pipe ~ primitiveName_{j})\bsup \#~\_ \esup @ \\
  \t1 \#~\_ = 0 \implies primtiveName_{i} ~\pipe ~primitiveName_{n} ~ \pipe ~ primitiveName_{j}
\end{zed}
where a Primitive chain iterated to the 0 is just the chain itself hence recursion is not a requirement of, but is supported within, the definition of Primitives.

\subsection{Domain}
Any of the following dependent upon the Operations which compose the Primitive

\begin{itemize}
\item Key(s)
\item Value(s)
\item Set(s)
\item Collection(s)
\item Bag(s)
\item KV(s)
\item Statement(s)
\item Algorithm State
\end{itemize}

\subsection{Range}
Any of the following dependent upon the Domain and Functionality of the Primitive

\begin{itemize}
\item Key(s)
\item Value(s)
\item Set(s)
\item Collection(s)
\item Bag(s)
\item KV(s)
\item Statement(s)
\item Algorithm State
\end{itemize}

\section{Algorithm}
Given a Collection of statement(s) $S_{\langle a..b..c \rangle}$ and potentially option(s) $opt$ and potentially an existing Algorithm State $state$ an Algorithm $A$ executes as follows

\begin{enumerate}
\item call $init$
\item for each $stmt \in S_{\langle a..b..c \rangle}$
  \begin{enumerate}
  \item $relevant?$
  \item $accept?$
  \item $step$
  \end{enumerate}
\item return $result$
\end{enumerate}
with each process within $A$ is enumerated as

\begin{lstlisting}[frame=single]
  (init [state] body)
   - init state

  (relevant? [state statement] body)
   - is the statement valid for use in algorithm?

  (accept? [state statement] body)
   - can the algorithm consider the current statement?

  (step [state statement] body)
   - processing per statement
   - can result in a modified state

  (result [state] body)
   - return without option(s) provided
   - possibly sets default option(s)

  (result [state opt] body)
   - return with consideration to option(s)
\end{lstlisting}
\begin{itemize}
\item $body$ is a collection of Primitive(s) which establishes the processing of inputs $\to$ outputs
\item $state$ is a mutable Map of type $KV$ and synonymous with Algorithm State
\item $statement$ is a single statement within the collection of statements passed as input data to the Algorithm $A$
\item $opt$ are additional arguments passed to the algorithm $A$ which impact the return value of the algorithm and synonymous with Option
\end{itemize}
An Algorithm must be passed an Algorithm State and a Collection of Statement(s). Option is optional.
\begin{itemize}
\item Statement(s)
\item Algorithm State
\item Option(s)
\end{itemize}
An Algorithm will return an Algorithm State.
\begin{itemize}
\item Algorithm State
\end{itemize}
An Algorithm can be described via its components. A formal definition for an Algorithm
is presented at the end of this section. The following subsections go into more detail about the components of an Algorithm.
\begin{zed}
  Algorithm ::= Init ~\pipe ~Relevant? ~\pipe ~Accept? ~\pipe ~Step ~\pipe Result
\end{zed}
\subsection{Initialization}

First process to run within an Algorithm which returns the Algorithm State for the current iteration.

\begin{schema}{Init[KV]}
  state?, state! : KV \\
  init~\_: KV \surj KV
  \where
  init = \langle body \rangle \\
  state! = init(state?) @ state! = state? ~\lor ~state! \not = state?
\end{schema}
such that some $state!$ does not need to be related to its arguments $state?$
but $state!$ could be derived from some seed $state?$.
This functionality is dependent upon the composition of $body$ within $init$.
\subsubsection{Domain}

\begin{itemize}
\item Algorithm State
\end{itemize}

\subsubsection{Range}

\begin{itemize}
\item Algorithm State
\end{itemize}

\subsection{Relevant?}

First process that each $stmt$ passes through $\implies relevant? \prec accept? \prec step$
\begin{schema}{Relevant?[KV, STATEMENT]}
  state? : KV \\
  stmt? : STATEMENT \\
  relevant?~\_ : KV \cross STATEMENT \fun Boolean
  \where
  relevant? = \langle body \rangle \\
  relevant?(state?, stmt?) = true ~\lor false
\end{schema}
resulting in an indication of whether the $stmt$ is valid within algorithm $A$.
The criteria which determines validity of $stmt$ within $A$ is defined by the $body$ of $relevant?$

\subsubsection{Domain}

\begin{itemize}
\item Statement
\item Algorithm State
\end{itemize}

\subsubsection{Range}

\begin{itemize}
\item Boolean
\end{itemize}

\subsection{Accept?}

Second process that each $stmt$ passes through $\implies relevant? \prec accept? \prec step$
\begin{schema}{Accept?[KV, STATEMENT]}
  state? : KV \\
  stmt? : STATEMENT \\
  accept?~\_ : KV \cross STATEMENT \fun Boolean
  \where
  accept? = \langle body \rangle \\
  accept?(state?, stmt?) = true ~\lor false
\end{schema}
resulting in an indication of whether the $stmt$ can be sent to $step$ given the current $state$.
The criteria which determines usability of $stmt$ given $state$ is defined by the $body$ of $accept?$

\subsubsection{Domain}

\begin{itemize}
\item Statement
\item Algorithm State
\end{itemize}

\subsubsection{Range}

\begin{itemize}
\item Scalar
\end{itemize}

\subsection{Step}

An Algorithm Step consists of a sequential composition of Primitive(s)
where the output of some function is passed as an argument to the next function both within and across Primitives in $body$.
$$body = p_{i} ~\pipe ~p_{n} ~\pipe ~p_{j} \implies o_{ii} ~\pipe ~o_{in} ~\pipe ~o_{ij} ~\pipe ~o_{ni} ~\pipe ~o_{nn} ~\pipe ~o_{nj} ~\pipe ~o_{ji} ~\pipe ~o_{jn} ~\pipe ~o_{jj}$$
The selection and ordering of Operation(s) and Primitive(s) into an Algorithmic Step determines how the Algorithm State changes during iteration through Statement(s) passed as input to the Algorithm.
\begin{axdef}
  P = \langle p_{i}~..~p_{n}~..~p_{j} \rangle @ i \leq n \leq j \implies i \prec n \prec j \iff i \not= n \not= j @ p_{i} ~\pipe ~p_{n} ~\pipe ~p_{j} \\
  P' = \langle p_{i'}~..~p_{n'}~..~p_{j'} \rangle @ i' \leq n' \leq j' \implies i' \prec n' \prec j' \iff i' \not= n' \not= j' @ p_{i'} ~\pipe ~p_{n'} ~\pipe ~p_{j'} \\
  P'' = \langle p_{x}~..~p_{y}~..~p_{z}\rangle @ x \leq y \leq z \implies x \prec y \prec z \iff x \not= y \not= z @ p_{x} ~\pipe ~p_{y} ~\pipe ~p_{z}
  \where
  P = P' \iff i \mapsto i' ~\land ~n \mapsto n' ~\land ~j \mapsto j' \\
  P = P'' \iff (i \mapsto x ~\land n \mapsto y ~\land j \mapsto z) ~\land (p_{i} \equiv p_{x} ~\land p_{n} \equiv p_{y} ~\land p_{j} \equiv p_{z})
\end{axdef}
$step$ may or may not update the input Algorithm State given the current Statement from the Collection of Statement(s).
\begin{axdef}
  S : Collection \\
  stmt_{a}, stmt_{b}, stmt_{c} : STATEMENT \\
  state?, step_{a}!, step_{b}!, step_{c}! : KV \\
  step~\_ : KV \cross STATEMENT \surj KV
  \where
  S = \langle stmt_{a}..stmt_{b}..stmt_{c} \rangle @ a \leq b \leq c \implies a \prec b \prec c \iff a \not= b \not= c \\
  step_{a}! = step(state?, stmt_{a}) @ step_{a}! = state? ~\lor ~step_{a}! \not= state? \\
  step_{b}! = step(step_{a}!, stmt_{b}) @ step_{b}! = step_{a}! ~\lor ~step_{b}! \not= step_{a}! \\
  step_{c}! = step(step_{b}!, stmt_{c}) @ step_{c}! = step_{b}! ~\lor ~step_{c}! \not= step_{b}!
\end{axdef}
In general, this allows $step$ to be defined as
\begin{schema}{Step[KV, STATEMENT]}
  state?, state! : KV \\
  stmt? : STATEMENT \\
  step~\_ : KV \cross STATEMENT \surj KV
  \where
  step = \langle body \rangle \\
  state! = step~(state?, stmt?) = state? ~\lor ~state! \not= state?
\end{schema}
A change of $state? \to state! @ state! \not= state?$ can be predicted to occur given
\begin{itemize}
\item The definition of individual Operations which constitute a Primitive
\item The ordering of Operations within a Primitive
\item The Primitive(s) chosen for inclusion within the body of $step$
\item The ordering of Primitive(s) within the body of $step$
\item The key value pair(s) in both Algorithm State and the current Statement
\item The ordering of Statement(s)
\end{itemize}

\subsubsection{Domain}

\begin{itemize}
\item Statement
\item Algorithm State
\end{itemize}

\subsubsection{Range}

\begin{itemize}
\item Algorithm State
\end{itemize}

\subsection{Result}

Last process to run within an Algorithm which returns the Algorithm State $state$
when all $s \in S$ have been processed by $step$

\begin{zed}
  relevant? \prec accept? \prec step \prec result \prec relevant? \iff S \not= \emptyset \\
  relevant? \prec accept? \prec step \prec result \iff S = \emptyset
\end{zed}
and does so without preventing subsequent calls of $A$
\begin{schema}{Result[KV, KV]}
  result!, state?, opt? : KV \\
  result~\_ : KV \cross KV \surj KV
  \where
  result = \langle body \rangle \\
  result! = result(state?, opt?) = state? ~\lor ~state! \not= state?
\end{schema}
such that if at some future point $j$ within the timeline $i~..~n~..~j$
\begin{argue}
  S(t_{n}) = \emptyset & S is empty at $t_{n}$ \\
  S(t_{j}) \not= \emptyset & S is not empty at $t_{j}$ \\
  S(t_{n - i}) & stmts(s) added to $S$ between $t_{i}$  and $t_{n}$ \\
  S(t_{j - n}) & stmts(s) added to $S$ between $t_{n}$  and $t_{j}$ \\
  S(t_{j - i}) = S(t_{n - i}) \ \cup \ S(t_{j - n}) & stmts(s) added to $S$ between $t_{i}$ and $t_{j}$
\end{argue}
Algorithm $A$ can pick up from a previous $state_{n}$ without losing track of its own history.
\begin{axdef}
  state_{n-i} = A(state_{i},\ S(t_{n - i})) \\
  state_{n-1} = A(state_{n-2}, \ S(t_{n - 1})) \\
  state_{n} = A(state_{n-1},\ S(t_{n})) \\
  state_{j-n} = A(state_{n}, \ S(t_{j-n})) \\
  state_{j} = A(state_{i},\ S(t_{j - i}))
  \where
  state_{n} = state_{n-1} \iff S(t_{n}) = \emptyset ~\land S(t_{n-1}) \not = \emptyset \\
  state_{j} = state_{j-n} \iff state_{n-i} = state_{n} = state_{n-1}
\end{axdef}
Which makes $A$ capable of taking in some $S_{\langle i..n..j..\infty \rangle}$ as not all $s \in S_{\langle i..\infty \rangle}$ have to be considered at once. In other words, the input data does not need to persist across the history of $A$, only the effect of $s$ on $state$ must be persisted.
Additionally, the effect of $opt$ is determined by the $body$ within $result$ such that
\begin{zed}
  A(state_{n}, \ S(t_{j-n}), \ opt) \\
  \t1 \equiv A(state_{i}\ S(t_{j - i})) \\
  \t1 \equiv A(state_{i},\ S(t_{j - i}), \ opt) \\
  \t1 \equiv A(state_{n}, \ S(t_{j-n}))
\end{zed}
implying that the effect of $opt$ doesn't prevent backwards compatibility of $state$.

\subsubsection{Domain}

\begin{itemize}
\item Algorithm State
\item Option(s)
\end{itemize}

\subsubsection{Range}

\begin{itemize}
\item Algorithm State
\end{itemize}

\subsection{Algorithm Formal Definition}\label{AFD_ref}
In previous sections, $A~\_$ was used to indicate calling an Algorithm.
In the rest of this document, that notation will be replaced with $algorithm~\_$.
This new notation is defined using the definitions of Algorithm Components presented above.
The previous definition of an Algorithm
\begin{zed}
  Algorithm ::= Init ~\pipe ~Relevant? ~\pipe ~Accept? ~\pipe ~Step ~\pipe Result
\end{zed}
can be refined using the Operation $recur$ and Primitive $algorithmIter$ (defined in following subsections)
to illustrate how an Algorithm processes a Collection of Statement(s).
\begin{schema}{Algorithm[KV, Collection, KV]}
  Algorithm ~Iter, ~Recur, ~Init, ~Result \\
  opt?, state?, state! : KV \\
  S? : Collection @ \forall s? \in S? ~| ~s? : STATEMENT \\
  algorithm~\_ : KV \cross Collection \cross KV \surj KV
  \where
  algorithm = \langle ~init~\_~, \langle ~algorithmIter~\_~, ~recur~\_~\rangle \bsup \#~S? \esup, ~result~\_~\rangle \\
  state! = algorithm(state?, S?, opt?) @ \\
  \t1 let \ \ ~ init! == init(state?) @ \\
  \t1 \forall s_{n} \in S? ~|~ s_{n} : STATEMENT, n : \nat @ i \leq n \leq j ~@ \\
  \t2 \exists_1 state_{n} ~|~ state_{n} : KV @ \\
  \t3 let \ \ ~ S?_{n} = tail(S?)\bsup n-i \esup \\
  \t4 state_{i} = algorithmIter(init!, ~S?_{n}) \implies ~S?_{n} = S? \iff n = i \\
  \t4 state_{n} = recur(state_{i}, ~S?_{n}, ~\_~algorithmIter~\_)\bsup j-1 \esup \iff n \not = i ~\land n \not = j\\
  \t4 state_{j} = recur(state_{n}, (\{j-1, j\} \extract S?), ~\_~algorithmIter~\_) \iff n = j \\
  \t4 state_{j+1}  = state_{j} \implies recur(state_{j}, (j \extract S?), ~\_~algorithmIter~\_) \iff n = j+1\\
  \t1 \ \ = result(state_{j}, opt?)
\end{schema}
Within the schema above, the following notation is intended to show that $algorithm$ is a Primitive $\implies$ Collection of Primitives and/or Operations.
$$\langle ~init~\_~, \langle ~algorithmIter~\_~, ~recur~\_~\rangle \bsup \#~S? \esup, ~result~\_~\rangle$$
Within that notation, the following notation is intended to represent the iteration through the Statement(s) via tail recursion.
$$\langle ~algorithmIter~\_~, ~recur~\_~\rangle \bsup \#~S? \esup$$
which implies that each Statement is passed to $algorithmIter~\_$ and
the result is then passed on to the next iteration of the loop.
The completion of this loop is the prerequisites of $result~\_$

\subsubsection{Recur}
The following schema introduces the Operation $recur$ which expects an accumulator ($KV$),
a $Collection$ of Value(s) ($V$) being iterated over and
a function ($\_~\pfun~\_$) which will be called as the result of $recur$.
This Operation has been written to be as general purpose as possible and represents
the ability to perform \href{https://cs.stackexchange.com/questions/6230/what-is-tail-recursion}{tail recursion}.
Given this intention, $recur$ must only ever be the last Operation within a Primitive
\begin{axdef}
  p_{i~..~j} : \seq_1 @ \forall o \in p ~|~ o : \_~\pfun~\_
  \where
  p_{i~..~j} = \langle ~\forall ~n : \nat ~|~ i \leq n \leq j ~\land~ o_{n} \in p_{i~..~j} @ \\
  \t2 \exists_1 o_{n} @ o_{n} \not = recur ~\lor ~o_{n}= recur \iff n = j \rangle ~ \implies \\
  \t3 front(p_{i~..~j}) \filter recur = \langle  \rangle
\end{axdef}
and results in a call to the passed in function where the
accumulator $ack?$ and the Collection (minus the first member)
are passed as arguments to $fn?$. If this would result in the empty Collection ($\langle  \rangle$)
being passed to $fn?$, instead the accumulator $ack?$ is returned.
\begin{schema}{Recur[KV, Collection, (\_~\pfun~\_)]}
  ack? : KV \\
  S? : Collection \\
  fn? : (\_~\pfun~\_) \\
  recur~\_ : KV \cross Collection \cross (\_~\pfun~\_) \rel (KV \cross Collection ~\pfun~\_)
  \where
  recur(ack?, S?, fn?) = fn?(ack?, tail(S?)) \iff tail(S?) \not = \langle  \rangle \\
  recur(ack?, S?, fn?) = first(ack?, tail(S?)) \iff tail(S?) = \langle  \rangle
\end{schema}
In the context of Algorithms,
\begin{zed}
  ack? = Algorithm State \\
  S? = Collection of Statement(s) \\
  fn? = algorithmIter
\end{zed}
\subsubsection{Algorithm Iter}
The following schema introduce the Primitive $algorithmIter$ which
demonstrates the life cycle of a single statement as its passed through the components of an Algorithm.
\begin{schema}{Algorithm Iter[KV, Collection]}
  Relevant?, ~Accept?, ~Step \\
  state?, state! : KV \\
  S? : Collection \\
  s? : STATEMENT \\
  algorithmIter~\_ : KV \cross STATEMENT \surj KV
  \where
  algorithmIter = \langle ~relevant?~\_~, ~accept?~\_~, ~step~\_ ~\rangle \\
  s? = head(S?) \\
  state! = algorithmIter(state?, s?) @ \\
  \t1 let \ \ ~ relevant! == relevant?(state?, s?) \\
  \t2 accept! == accept?(state?, s?) \\
  \t2 step! == step(state?, s?)\\
  \t1 \ ~ = (state? \iff relevant! = false ~ \lor ~ accept! = false) ~\lor \\
  \t1 \ \ \ \ ~ (step! \iff relevant! = true ~ \land ~ accept! = true)
\end{schema}
If a statement if both relevant and acceptable, $state!$ will be the result of $step$. Otherwise,
the passed in state is returned $\implies step! = state?$.
\end{document}


\documentclass[]{article}
\usepackage{amsmath}
\usepackage[a4paper]{geometry}
\usepackage{graphicx}
\usepackage{microtype}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage[colorlinks=false, pdfborder={0 0 0}]{hyperref}
\usepackage{cleveref}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}

\begin{document}

\title{Auto-Regression}
\author{Dun Wang}
\maketitle

\section{Auto-Regression}
 In additional to predicting the Kepler data point from the pixel values of other stars, we can also make the pixel values of the same stars but from different time as predictors, the auto-regression:

\begin{align*}
  I_{mn}^{*}=\sum_{m' \in M_{m}} a_{mnm'}I_{m'n} + \sum_{n' \in N_{n'}} a_{mnn'}I_{mn'}
\end{align*}
\\
$N_{n'}$ is the time window we used as predictors from target pixel, $a_{mnn'}$ is the corresponding auto-regression coeffecient

\section{Auto-Regression Window and Edge Effects}

We want to make use of the data points both before and after the target data point at time t and also leave N data points around the target data point tobe untouched , where $\left|  t-t_N \right|>\Delta t$, $\Delta t$ is the transit duration, to make sure that the auto-regression will not fit out the transit signal. So basically, we use a window $[-\Delta, -N] \cup [N, \Delta]$ as the data set in auto-regression, where $\Delta$ is the largest time shifts, which should be decided by optimizing our objective
\\
On the edge of the data sets, to overcome the edge effects, we may only use the data points before or after the target data points, that is either window $[-\Delta, -N]$ or $[N, \Delta]$ as the auto-regression data set

\end{document}


\section{Model Architecture}

\subsection{Model}
\begin{frame}{Model architecture figure}
\begin{columns}
\column{.4\textwidth}
\begin{itemize}
\item Stack of N=6 layers
\item Position-wise feed forward network
\item Residual connection
\item Same dimesion output $d_{model}=512$
\end{itemize}

\column{.6\textwidth}
\begin{figure}[!h]
\includegraphics[width=\textwidth]{assets/model-fig.png}
\caption{fig}
\end{figure}

\end{columns}
\end{frame}

\begin{frame}{Attention architecture figure}
\begin{columns}

\column{.4\textwidth}
\begin{itemize}
\item SDPA: Attention(Q,K,V)=softmax($\frac{QK^{T}}{\sqrt{d_k}}$)V
\item MHA: MultiHead(Q,K,V)=Concat(head_1,...,head_h)W^o, where $head_i=Attention(QW_{i}^{Q},KW_{i}^{K},VW_{i}^{V})$
\end{itemize}

\column{.6\textwidth}
\begin{figure}[!h]
\includegraphics[width=\textwidth]{assets/attention-fig.png}
\caption{fig}
\end{figure}

\end{columns}
\end{frame}


\newcommand{\TeamNo}{31}

\newcommand{\HWno}{05}

\newcommand{\AuthorOneName}{Merve Nur Öztürk}
\newcommand{\AuthorOneID}{2311322}

\newcommand{\AuthorTwoName}{Atakan Süslü}
\newcommand{\AuthorTwoID}{2311371}

\newcommand{\AuthorThreeName}{Betül Rana Kuran}
\newcommand{\AuthorThreeID}{2311173}

\documentclass[letterpaper,12pt]{article}
\usepackage{tabularx} % extra features for tabular environment
\usepackage{amsmath}  % improve math presentation
\usepackage{amssymb}
\usepackage{xcolor}
\usepackage{float}
\usepackage[export]{adjustbox}
\usepackage{graphicx} % takes care of graphic including machinery
\usepackage[margin=1in,letterpaper]{geometry} % decreases margins
\usepackage{cite} % takes care of citations

\begin{document}
\begin{center}
AE 305, 2020-21 Fall \hfill \textbf{HW \HWno} \hfill \textbf{Team \TeamNo} \\
\noindent\rule{\textwidth}{0.4pt}
\begin{tabular}{p{0.33\textwidth} | p{0.33\textwidth} | p{0.33\textwidth} }
	\AuthorOneName&\AuthorTwoName&\AuthorThreeName\\
	\textit{\AuthorOneID}&\textit{\AuthorTwoID}&\textit{\AuthorThreeID}
\end{tabular}
\noindent\rule{\textwidth}{0.4pt}
\end{center}

%Report start

\section{Introduction}
Elliptic partial differential equations can be solved by using finite difference equations,
and the most common FDE for the solution of an elliptic PDE is obtained by second-order
central difference approximations of the derivatives. Afterwards, the FDE can
be solved either by direct solution methods or iterative methods. In this homework, a 2D
heat equation is given:

\begin{equation}
	\frac{\partial^2T}{\partial x^2} + \frac{\partial^2T}{\partial y^2} = 0
	\label{eqn:heateqn}
\end{equation}

It is requested to compute the steady state temperature distribution on a given 2D model
of a room having a width of 10m and a height of 6m by solving the above equation for
two different cases, one is with a radiator and the other is without a radiator. First,
the iterative methods are used; Point Jacobi, Gauss-Seidel, SOR and Line Gauss-Seidel
methods, then the solution is obtained by the direct solution methods. For the final
solution, it is asked to plot the heat flux distribution in the room, and the heat flux
vector is given as follows:

\begin{equation}
	\vec{q} = -k \nabla T
	\label{eqn:heatflux}
\end{equation}

It is also asked to compare the convergence rates of the iterative methods.
\section{Method}
FDE of the governing equation of this homework (Equation \ref{eqn:heateqn}) is an elliptic partial differential
equation,and it is obtained by second-order central difference approximations of the derivatives.
\begin{equation}
	\frac{T_{i+1,j}-2T_{i,j}+T_{i-1,j}}{\Delta x^2}+\frac{T_{i,j+1}-2T_{i,j}+T_{i,j-1}}{\Delta y^2}
	\label{eqn:fde}
\end{equation}
When $i$ and $j$ coincide with the boundries of the room or the radiator, they are excluded
from the solution of the heat equation since at these points the temperatures are equal to
temperatures of the boundries.\\
When $\beta = \frac{\Delta x}{\Delta y}$ substituted into Equation \ref{eqn:fde}, equation becomes:
\begin{eqnarray}
	T_{i+1,j}-2T_{i,j}+T_{i-1,j}+\beta ^2(T_{i,j+1}-2T_{i,j}+T_{i,j-1})&=&0 \nonumber \\
	\beta^2T_{i,j-1}+T_{i-1,j}-2(1+\beta^2)T_{i,j}+T_{i+1,j}+\beta ^2T_{i,j+1}&=&0
	\label{eqn:basic}
\end{eqnarray}
This five-point formula gives the system of linear algebraic equations, which can be solved by two methods,
namely direct solution methods and iterative solution methods.
\subsection{Direct Solution Method}
\subsubsection{Gauss Elimination}
In this homework, Gauss elimination method is used as direct solution method. The system of linear
equations formed by five-point formula (Equation \ref{eqn:basic}).
\begin{equation}
	aT_{i-1,j}+bT_{i,j}+cT_{i+1,j}+dT_{i,j-1}+eT_{i,j+1}=0
\end{equation}
with Neumann type BC for insulated wall and Dirichlet type BCs for other walls,
the system of equations can be writen in $\underline{A}\mbox{ }\underline{T}=\underline{f}$ form
where $\underline{A}$ is coefficient matrix.
This equation is solved by Gauss elimination method.

\subsection{Iterative Solution Methods}
\label{subsec:iterative}
\subsubsection{Point Iterative Methods}
\paragraph{Point Jacobi Iteration}
In this method, every terms in Equation \ref{eqn:basic} are kept at $k$
where $k$ is denoted as iteration level except $T_{i,j}$. $T_{i,j}$ which is kept
at new iteration level $k+1$. Then equation becomes:
\begin{equation}
	T_{i,j}^{k+1}=\frac{1}{2(1+\beta^2)}[T_{i-1,j}^{k}+T_{i+1,j}^{k}+\beta ^2(T_{i,j-1}^{k}+T_{i,j+1}^{k})]
\label{eqn:jacobi}
\end{equation}
where $k$ corresponds previous calculated values or initial guess at the start
of iteration process of $T$ values over the room except boundary conditions.
\paragraph{Gauss-Seidel Iteration}
Differently from Point Jacobi method, in Gauss-Seidel method, the unknown dependent
variable values of Equation \ref{eqn:basic} are used as soon as they become available
at the $k+1$ iteration level.
\begin{equation}
	T_{i,j}^{k+1}=\frac{1}{2(1+\beta^2)}[T_{i-1,j}^{k+1}+T_{i+1,j}^{k}+\beta ^2(T_{i,j-1}^{k+1}+T_{i,j+1}^{k})]
\label{eqn:gs}
\end{equation}
\paragraph{Successive Over-Relaxation Method}
In this method, the convergence of solution is can be accelerated by multiplying the relaxation
parameter, $\omega$, with the amount of the change in each step. First, $T_{i,j}^k$ is substracted
from the Gauss-Seidel iteration method to obtain $\Delta T$.
\begin{equation}
	T_{i,j}^{k+1}\vert_{GS}-T_{i,j}^{k}=\Delta T\vert{GS}=\frac{1}{2(1+\beta^2)}[T_{i-1,j}^{k+1}+T_{i+1,j}^{k}+\beta ^2(T_{i,j-1}^{k+1}+T_{i,j+1}^{k})]-T_{i,j}^{k}
\label{eqn:sor1}
\end{equation}
Then, $\Delta T$ is multiplied by $\omega$
\begin{eqnarray}
	T_{i,j}^{k+1}\vert_{SOR}&=&T_{i,j}^{k}+\omega\Delta T\vert{GS} \nonumber \\
	&=&(1-\omega)T_{i,j}^{k}+\frac{\omega}{2(1+\beta^2)}[T_{i-1,j}^{k+1}+T_{i+1,j}^{k}+\beta^2(T_{i,j-1}^{k+1}+T_{i,j+1}^{k})]
	\label{eqn:sor}
\end{eqnarray}
To obtain convergent solutions, relaxatation parameter,$\omega$, is chosen in (0,2) interval.
The optimum value of $\omega$ can be determined by numerical experimentations. If $\omega$ is chosen in
(0,1) interval, under-relaxation occurs, which prevents the divegence by slowing the convergence for the solution of
certain non-linear partial derivative equations.
\subsubsection{Line Iterations}
\paragraph{Line Gauss-Seidel Method} In this method, iterations are made line by line, in one direction. One more term of Equation
\ref{eqn:gs} is expressed at $k+1$ iteration level. Then, equation becomes:
\begin{equation}
	T_{i,j}^{k+1}=\frac{1}{2(1+\beta^2)}[T_{i-1,j}^{k+1}+T_{i+1,j}^{k+1}+\beta ^2(T_{i,j-1}^{k+1}+T_{i,j+1}^{k})]
\end{equation}
To make iteration line by line, j is kept constant. Therefore, every $T_{ ,j}$ term should be in left
hand side of the equation.
\begin{equation}
	T_{i-1,j}^{k+1}-2(1+\beta^2)T_{i,j}^{k+1}+T_{i+1,j}^{k+1}=-\beta^2(T_{i,j+1}^{k}+T_{i,j-1}^{k+1})]
\label{eqn:lgs}
\end{equation}
For constant j grid lines, Equation \ref{eqn:lgs} is applied to all i's. The
system of linear equations which includes tridiagonal coefficient matrix is formed. Its
convergence rate is higher than the Gauss-Seidel method. On the other hand, a system of equations
is solved every iterations;hence, in each iteration, it requires more computations.
The effect of BCs at i=0 and i=imax is instantly visible in the solution.
\newpage
\section{Results and Discussion}

\subsection{Solution of the Heat Equation in the Absence of a Radiator}
Figures \ref{fig:pointnorad}, \ref{fig:gaussnorad}, \ref{fig:sornorad}, \ref{fig:linegaussnorad}, and \ref{fig:directnorad}
illustrates the solution of the heat equation by using Point Jacobi, Gauss-Seidel,
SOR, Line Gauss-Seidel, and Direct methods, respectively. As can be seen from these figures, all the solutions
with different methods converged to approximately the same heat flux distributions.
In all solutions, flux vectors have the same directions, which are from the walls
with higher temperature to the wall with the lower temperature perpendicularly.
Moreover, near the insulated wall, these flux vectors are parallel and the temperature
contours are perpendicular to the wall since the temperature gradient is zero at the
insulated wall. Therefore, there is no heat transfer across the insulated wall.

\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/point_norad/point_norad.png}
	\caption{Solution of the heat equation by Point Jacobi method.}
 	\label{fig:pointnorad}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/gauss_norad/gauss_norad.png}
	\caption{Solution of the heat equation by Gauss-Seidel method.}
 	\label{fig:gaussnorad}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/SOR_O19_norad/SOR_O19_norad.png}
	\caption{Solution of the heat equation by SOR method.}
 	\label{fig:sornorad}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/linegauss_norad/linegauss_norad.png}
	\caption{Solution of the heat equation by Line Gauss-Seidel method.}
 	\label{fig:linegaussnorad}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/linegauss_norad/linegauss_norad.png}
	\caption{Solution of the heat equation by Direct method.}
 	\label{fig:directnorad}
\end{figure}

\subsubsection{Temperature Distributions along x=5m and y=3m}
Figures \ref{fig:x5norad} and \ref{fig:y3norad} shows the temperature distributions along
x=5 and y=3 lines respectively. It can be oberved that all methods gave the same result with
a negligible difference among them although their convergence rates differ.
\begin{figure}[H]
	\centering
	\includegraphics[max height=9cm]{graphs/x5_SOR19_norad.eps}
	\caption{Temperature distributions along x=5m}
 	\label{fig:x5norad}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=9cm]{graphs/y3_SOR19_norad.eps}
	\caption{Temperature distributions along y=3m}
 	\label{fig:y3norad}
\end{figure}

\subsection{Solution of the Heat Equation with Existence of a Radiator}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/point_rad_default/point_rad_default.png}
	\caption{Solution of the heat equation by Point Jacobi method.}
 	\label{fig:pointrad}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/gauss_rad_default/gauss_rad_default.png}
	\caption{Solution of the heat equation by Gauss-Seidel method.}
 	\label{fig:gaussrad}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/SOR_O19_rad_default/SOR_O19_rad_default.png}
	\caption{Solution of the heat equation by SOR method.}
 	\label{fig:sorrad}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/linegauss_rad_default/linegauss_rad_default.png}
	\caption{Solution of the heat equation by Line Gauss-Seidel method.}
 	\label{fig:linegaussrad}
\end{figure}
Figures \ref{fig:pointrad}, \ref{fig:gaussrad}, \ref{fig:sorrad}, and \ref{fig:linegaussrad}
demonstrates the solution of the heat equation by using Point Jacobi, Gauss-Seidel,
 SOR,and Line Gauss-Seidel methods, respectively.From these figures, it can be observed that all the solutions
with different methods converged to nearly the same heat flux distributions.
In all solutions, the directions of the flux vectors are from the highest temperature surface
,which is the radiator, to the lower temperature surfaces, which is the walls of the room,
perpendicularly, except the insulated wall. Since the wall is insulated, the temperature
gradient across the wall is zero; hence the flux vectors are parallel near the surface.
Also, from the figures, it can be seen that all temperature contours which are intersect
with the insulated wall are perpendicular to the wall. Thus, it can said that heat transfer
does not occur from the room to the wall or reverse of it.

\subsubsection{Temperature Distributions along x=5m and y=3m}
\begin{figure}[H]
	\centering
	\includegraphics[max height=9cm]{graphs/x5_SOR19_defaultrad.eps}
	\caption{Temperature distributions along x=5m}
 	\label{fig:x5rad}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=9cm]{graphs/y3_SOR19_defaultrad.eps}
	\caption{Temperature distributions along y=3m}
 	\label{fig:y3rad}
\end{figure}
Figures \ref{fig:x5rad} and \ref{fig:y3rad} illustrates the temperature distributions with the
existence of radiator along x=5m and y=3m lines, respectively. In Figure \ref{fig:x5rad}, sudden
change is observed near the y = 6m. The reason for this is that there is radiator between y = 5.6m
and 5.8m. Therefore, a sudden rise in temperature is seen before y=5.8 meters. This causes distortion
in both figures. However, in Figure \ref{fig:y3rad}, due to the the length of the radiator is
longer in x-axis, its effect along y = 3m is less sudden.

\subsection{Comparison of the Convergence Rates}
Figures \ref{fig:convnorad} and \ref{fig:convrad} demonstrate the convergence rates of Point
Jacobi, Gauss-Seidel,SOR, and Line Gauss-Seidel methods for the solutions of the heat equation without and with
the radiator, respectively. As can be observed from these figure, the responses of Point Jacobi
method are the slowest. On the other hand, Gauss-Seidel method converges faster for both.
This is because it uses newly computed values of the unknowns as they become available as
mentioned in Subsection \ref{subsec:iterative}. Furthermore, Line Gauss-Seidel method gives the faster convergence
rate than Gauss-Seidel method. Because as mentioned in Subsection \ref{subsec:iterative}, in Line-Gauss Seidel method,
system of equations are solved simultaneously and it includes one more unknown variable than Gaus-Seidel method.
.However, among all methods, SOR method computed the solutions with minimum number
of iterations which is a result of the use of the relaxation parameter. This is also mentioned
in Subsection \ref{subsec:iterative}. The relaxation parameter is taken 1.9 for both since this is its largest
possible value which is found experimentally. For higher relaxation parameter values, the
solutions did not converge.

\begin{figure}[H]
	\centering
	\includegraphics[max height=9cm]{graphs/residual_SOR19_norad.eps}
	\caption{Convergence rates of Point Jacobi, Gauss-Seidel and SOR methods in the absence of the radiator.}
 	\label{fig:convnorad}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[max height=9cm]{graphs/residual_SOR19_defaultrad.eps}
	\caption{Convergence rates of Point Jacobi, Gauss-Seidel and SOR methods in the presence of the radiator.}
 	\label{fig:convrad}
\end{figure}
\subsection{Temperature Distribution on a 2D Model of a Room with Radiator with SOR Method}
\subsubsection{Comparison of Different values of $\Delta$x and $\Delta$y}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/imax75jmax40_default/imax75jmax40_default.png}
	\caption{Temperature distribution in the room with $\Delta x=0.135$ and $\Delta y = 0.154$}
 	\label{fig:7540}
\end{figure}

Figure \ref{fig:sorrad}, \ref{fig:7540}, and \ref{fig:402242} illustrates temperature
distribution in the room with SOR method with different $\Delta x$ and $\Delta y$ values.
It can be seen that although low $\Delta x$ and $\Delta y$ values give a more precise result,
if $\Delta x$ and $\Delta y$ values are reasonably seleced, differences in the result would
be negligible. On the other hand, when $\Delta x$ and $\Delta y$ values are lower, convergence rate
of the solution is slower, which can be seen from Figure \ref{fig:converratedelta}. It can be concluded that,
too low values of $\Delta x$ and $\Delta y$ should be avoided because they would increase solution time and they
would not increase the accuracy of result significantly.

\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/imax402jmax242_default/imax402jmax242_default.png}
	\caption{Temperature distribution on the room with $\Delta x=0.025$ and $\Delta y = 0.025$}
 	\label{fig:402242}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=8cm]{graphs/residual_deltax.eps}
	\caption{Convergence rates of SOR method with different $\Delta x$ and $\Delta y$ values.}
 	\label{fig:converratedelta}
\end{figure}
\subsubsection{Comparison of Different Sizes and Locations of the Radiator}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/radiator_middle_long/radiator_middle_long.png}
	\caption{Temperature distribution on the room with radiator at middle of the room}
 	\label{fig:middle}
\end{figure}
\begin{figure}[H]
	\centering
	\includegraphics[max height=12cm]{graphs/radiator_middle/radiator_middle.png}
	\caption{Temperature distribution on the room with radiator at middle of the room with different size}
 	\label{fig:middlelong}
\end{figure}
Figure \ref{fig:sorrad} demonstrates the temperature distribution
on the room with radiator with size $6m\times0.2m$, which is
neighbor to the wall with $0^\circ C$. Figure \ref{fig:middlelong} illustrates the
temperature distribution on the room with radiator with the same size but at
the middle of the room. Figure \ref{fig:middle} shows the temperature
distribution with radiator at the middle of the room with size $2m\times2m$.
It can be obtained from Figure \ref{fig:sorrad} and \ref{fig:middlelong},
changing the location of the radiator from the coldest wall to the middle
of the room causes inefficiency to evenly heat the entire room. Since all walls do not have
the same temperature, putting the source of heat at the middle of the room
is not reasonable to heat everywhere evenly. Moreover, from Figure \ref{fig:middlelong}
and \ref{fig:middle}, it can be observed that  changing the size of the radiator is
not logical. Since horizontal length of the radiator is shortened, it can not be
sufficient to heat area near to the edges of the coldest wall. But, vertical length
of the raditor is extended, it is more effective to heat the middle of the coldest
wall than in Figure \ref{fig:middlelong}. Overall, its effectiveness less than the other radiator
which is longer in horizontal direction.

\section{Conclusion}
Given a 2D model of a room, with a size of 10m x 6m, it is requested to solve heat conduction equation for
the room. For this purpose, various numerical methods for the solution of an elliptic partial differential
equation are used. First, Point Jacobi, Gauss-Seidel, Line Gauss-Seidel and SOR methods are used for two cases,
one in the existence of a radiator and the other is in the absence of a radiator. It was concluded that Point Jacobi method is the slowest responding method since it does not uses the newly computed values of unknowns in the k+1 iteration
level as they become available whereas Gauss-Seidel, Line Gauss-Seidel and SOR methods use them. As a result of this, Gauss-Seidel,
Line Gauss-Seidel and SOR methods converged faster than Point Jacobi method. Comparing Gauss-Seidel and Line Gauss-Seidel methods,
Line Gauss-Seidel method converges faster as one more unknown variable is expressed at the k + 1 iteration level and the influence
of the BC at $i = 1$ and $i = imax$ are reflected into the solution immediately. Furthermore, it was obvious
from Figures \ref{fig:convnorad} and \ref{fig:convrad}, convergence of SOR method occurs earlier then
that of all methods. This is because SOR method makes use of the amount of change in each step to
estimate the unknown variable at the new iteration level to accelerate the convergence of the solution, and
it multiplies the change by the relaxation parameter.

According to the experimentations made, the value of $\Delta x$ and $\Delta y$ had an impact on the solution.
For the calculations mentioned above, $\Delta x = 0.05$ and $\Delta y = 0.05$ . Then the calculations are
repeated for higher and smaller values of $\Delta x$ and $\Delta y$ such that for the former $\Delta x = 0.135$
and $\Delta y = 0.154$ and for the latter $\Delta x = 0.025$ and $\Delta y = 0.025$. It was observed that the
medium and higher values yield to more accurate results whereas smaller values lead to distortions in the
temperature distribution.

The location and the size of the radiator also changed the solution. For the first calculations, the radiator
was placed near the upper wall and its size was 6m x 0.2m. When it is moved to the middle of the room, the upper
wall is less heated. While it is still in the middle of the room, but changed in size (2m x 2m), the middle of
the upper wall is more heated since the radiator is longer vertically, but the edges of the upper wall is less
heated since the radiator is shorter horizontally.
\end{document}