\documentclass[12pt,a4paper]{article}
\usepackage{algorithm, algpseudocode, amsmath, amssymb, csquotes, empheq, geometry, graphicx, hyperref, listings, multirow, physics, siunitx, subcaption, upgreek}
\usepackage[section]{placeins}
\usepackage[justification=centering]{caption}

\title{Computational Physics\\Problem Set 5}
\author{Saleh Shamloo Ahmadi\\Student Number: 98100872}
\date{October 25, 2021}

\hypersetup{colorlinks=true, urlcolor=cyan}
\newcommand{\fig}{../fig}

\begin{document}
	\newgeometry{top=1in, bottom=1in}
	\maketitle
	\section{2D Random Walk}
	As described in the lecture notes, we expect
	\begin{equation}
		\expval{r^2} = 2dDt
	\end{equation}
	where $d$ is the number of dimensions (degrees of freedom), $t$ is the time the walker has spent moving and
	\begin{equation}
		D = \frac{l}{2d\tau}
	\end{equation}
	where $l$ and $\tau$ are the space and time steps respectively. In our simulations, units are normalized
	such that both $l$ and $\tau$ are equal to 1. Hence, we expect
	\begin{equation}
		\expval{r^2} = t,
	\end{equation}

	\begin{figure}[htb!]
		\centering
		\includegraphics[width=\linewidth]{\fig/randomwalk-2d-small}
	\end{figure}
	\newgeometry{top=0.3in, bottom=1in}
	\begin{figure}
		\centering
		\includegraphics[width=\linewidth]{\fig/randomwalk-2d-large}
	\end{figure}
	\begin{figure}
		\centering
		\includegraphics[width=\linewidth]{\fig/randomwalk-2d-msd}
		\caption{The results of the simulations are consistent the theoretical analysis}
	\end{figure}

	\newgeometry{top=0.8in, bottom=0.9in}
	\section{Diffusion-Limited Aggregation (DLA)}
	In this process, particles undergoing a random walk stick together to form clusters. The generated shapes
	appear in many systems in nature. DLA can describe aggregation in any system where diffusion is the primary
	means of transport in the system. You can read more about DLA on
	\href{https://en.wikipedia.org/wiki/Mersenne_Twister}{Wikipedia} and
	\href{http://paulbourke.net/fractals/dla/}{Paul Bourke's blog}.

	The particles start moving from outside the boundaries of the shape and get stuck as soon as they come in contact
	with the cluster. The system starts growing from a \enquote{seed}, which consists of the starting particles.

	\begin{figure}[htb!]
		\centering
		\begin{subfigure}{\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/dla-500}
		\end{subfigure}
		\begin{subfigure}{\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/dla-350}
		\end{subfigure}
		\begin{subfigure}{\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/dla-200}
		\end{subfigure}
		\caption{DLA with periodic boundary conditions and a line seed.
			Particles start moving form the top of the cluster.}
	\end{figure}

	\section{Self-Avoiding Walk (SAW)}
	In this type of walk, the path of the walker cannot cross itself. The problem of counting the number of possible
	paths of a given length is NP-hard, but it can be approximated with good accuracy.

	\begin{algorithm}
        \caption{Recursively Counting Every Possible Self-Avoiding Walk of Length N in a Graph G}
        \begin{algorithmic}[1]
            \Function{CountSAW}{$N, G, p$} \Comment{$p$ is the starting position}
				\If{$N = 0$}
					\textbf{return} 1
				\Else
					\State mark $p$ as passed
					\State $count \gets 0$
					\ForAll{$q \in G.neighbors(p)$}
						\If{$q$ is not passed}
							\State $count \gets count + \mathrm{CountSAW}(N - 1, G, q)$
						\EndIf
					\EndFor
					\State mark $p$ as unpassed
					\Comment{This step is called \enquote{backtracking}}
					\State \textbf{return} $count$
				\EndIf
            \EndFunction
        \end{algorithmic}
    \end{algorithm}

	\begin{figure}[htb!]
		\centering
		\includegraphics[width=\linewidth]{\fig/saw-path-count-small}
	\end{figure}
	\newgeometry{top=1.5in, bottom=1.5in}
	\begin{figure}[htb!]
		\centering
		\includegraphics[width=\linewidth]{\fig/saw-path-count}
	\end{figure}
	\begin{figure}[htb!]
		\centering
		\includegraphics[width=\linewidth]{\fig/self-avoiding-vs-random-walk}
	\end{figure}
	\begin{figure}[htb!]
		\centering
		\includegraphics[width=\linewidth]{\fig/self-avoiding-to-random-walk-ratio}
	\end{figure}
	\begin{figure}[htb!]
		\centering
		\includegraphics[width=\linewidth]{\fig/self-avoiding-to-random-walk-ratio-log}
	\end{figure}
	As you can see, the growth is consistently exponential. This is explored in more detail in the lecture notes.

	\restoregeometry
	\section{Random Number Generator (RNG)}
	I use the Julia programming language for solving these problems. The default random engine on Julia is a
	\href{https://en.wikipedia.org/wiki/Mersenne_Twister}{Mersenne Twister}, so that is the engine that I analize here.
	\subsection{Distribution}
	The bare minimum requirement for an RNG is a uniform output distribution.
	\subsection{Coefficient of Variation}
	For random distributions, the coefficient of variation must be proportional to the inverse square root of the
	number of samples.
	\begin{equation}
		CV = \frac{\sigma}{N} \sim \frac{1}{\sqrt{N}}
	\end{equation}
	Note that this is exactly the same as random ballistic distribution, which we explored before.
	\subsection{Numbers Coming Before 4}
	We can also analize the behavior of an RNG in other ways; If we take every number coming before a 4 in a random
	series generated by the RNG, the results must stay the same.
	\newgeometry{top=0.1in, bottom=0.1in, left=0in, right=0in}
	\thispagestyle{empty}
	\begin{figure}
		\centering
		\begin{subfigure}{0.42\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/rng-distribution}
		\end{subfigure}
		\begin{subfigure}{0.42\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/rng-growth}
		\end{subfigure}
		\par\bigskip
		\begin{subfigure}{0.42\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/rng-cv-single}
		\end{subfigure}
		\begin{subfigure}{0.42\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/rng-cv}
		\end{subfigure}
		\caption{The distribution of numbers is fairly uniform, as expected.\\The numbers are more evenly
				distributed as the number of random samples increases.}
	\end{figure}
	\begin{figure}
		\centering
		\begin{subfigure}{0.42\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/rng-b4-distribution}
		\end{subfigure}
		\begin{subfigure}{0.42\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/rng-b4-growth}
		\end{subfigure}
		\par\bigskip
		\begin{subfigure}{0.42\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/rng-b4-cv-single}
		\end{subfigure}
		\begin{subfigure}{0.42\linewidth}
			\centering
			\includegraphics[width=\linewidth]{\fig/rng-b4-cv}
		\end{subfigure}
		\caption{Taking numbers before 4 in a series gives the same results, as expected}
	\end{figure}
	\restoregeometry
\end{document}


\documentclass{article}
\usepackage[utf8]{inputenc}

\title{Problem Set 8}
\author{Karley Nadolski}
\date{March 31, 2021}

\begin{document}

\maketitle
\section{Comparing $\hat{\beta}_{OLS}$ to $\beta$ values}
\begin{table} [h]
\centering
\begin{tabular}[t]{lcc}
  & $\hat{\beta}_{OLS}$ using lm() & True $\beta$ values\\
X1 & 1.493 & 1.5\\
 & (0.005)\\
X2 & -1.014 & -1\\
 & \vphantom{8} (0.010)\\
X3 & -0.238 & -0.25\\
 & \vphantom{7} (0.010)\\
X4 & 0.728 & 0.75\\
 & \vphantom{6} (0.010)\\
X5 & 3.493 & 3.5\\
 & \vphantom{5} (0.010)\\
X6 & -1.993 & -2\\
 & \vphantom{4} (0.010)\\
X7 & 0.483 & 0.5\\
 & \vphantom{3} (0.010)\\
X8 & 0.996 & 1\\
 & \vphantom{2} (0.010)\\
X9 & 1.252 & 1.25\\
 & \vphantom{1} (0.010)\\
X10 & 1.980 & 2\\
 & (0.010)\\
Num.Obs. & 10000\\
R2 & 0.971\\
R2 Adj. & 0.971\\
AIC & 14359.7\\
BIC & 14439.0\\
Log.Lik. & -7168.850\\
F & 33160.246\\
\end{tabular}
\end{table}

The $\hat{\beta}_{OLS}$ estimates from using the lm() function are definitely similar to the true $\beta$ values, but aren't as precise as estimates from other optimization methods (like gradient descent, L-BFGS, or the Nelder-Mead algorithm). That being said, most of the estimates (besides X4) are within two standard errors of the true beta value. Even for the estimate for X4, the true value of $/beta$ is 0.75 and the $\hat{\beta}_{OLS}$ estimate is 0.728. With a standard error of 0.010, the true value lies just 0.02 beyond the estimate with the addition of two standard errors.

\end{document}


\section{Three Address Code}
\subsection{IR for Assembly Code Generation}
This is low level IR and is meant for assembly code generation. Typically this IR is present in compiler tool chains of almost all languages.
IR resembles high-level assembly. Some properties for such IR are:
\begin{itemize}
    \item  They have register names similar to assembly language. Unlike assembly code, they have unlimited numbers of registers.
    \item They have control structures like conditional and unconditional branches(similar to assembly). They are lower level than if-else(in C) etc.
    \item They have opcodes. They have higher level opcodes, something like doing vector addition. These opcodes are very similar to the ones in assembly which make their conversion to assembly opcodes easier. Sometimes IR opcodes could be lower level as well. For eg., some assembly opcodes can do multiple operations (\emph{add}, \emph{multiply}) in one instruction which might not be the case with the IR opcode. These need to be kept into mind while converting from IR to assembly code.
    An opcode is higher level if its translation to assembly code results in more than 1 instruction. If more than one opcodes translate to one instruction in assembly code, then it is considered lower level opcode.
\end{itemize}

\subsection{IR Characteristics}
Each instruction is of the form\\

$x$ = $y$ op $z$  (binary operation)
\\
or
\\

$x$ = op $y$ (unary operation)\\
where $y$ and $z$ are registers or constants, can be scalars or vectors.
This type of IR is called \emph{Three-Address Code}. This is because, for each operation, there are at max 3 addresses ($x$, $y$, $z$). Addresses are registers or memory addresses.

\subsection{Three Address Code Property}
Expression $x+y*z$ translates to \\

$t1 = y*z$ \\

$t2 = x+t1$ \\

\textbf{Property} : Each sub-expression has a name which makes compilation easier later on from the perspective of optimization.
Assembly operations such as \emph{load} and \emph{store} are also supported.

\subsection{IR Code Generation}
This is very similar to assembly code generation.
\\ \\
Define function \textbf{$igen(e,t)$} as a function which\\ \\
(INPUT) : takes an expression $e$ and a value $t$. $t$ represents the register name in which the value of expression should be computed.\\ \\
(OUTPUT) : $igen(e,t)$ generates code to compute the value of expression $e$ in register $t$. (Currently assuming that there are unlimited number of registers)

\subsubsection{IR CodeGen Example}
\begin{math}
\begin{array}{lcl}
    igen(e_1+e2,t) =  &  \\
     & igen(e_1, t_1) \\
     & igen(e_2, t_2)\\
     & t=t_1+t_2
\end{array}
\end{math}\\
$t_1$ and $t_2$ are fresh registers.

\subsubsection{Three Address Code IR}
\textit{LLVM (Low level Virtual Machine)} is the one of most popular \emph{Three Address Code} IRs.\\ \\
 \underline{\textbf{Types} in LLVM are} : \\
 (integer) $i1$, $i8$, $i32$.. ($i1$ stands for 1-bit integer and so on..) \\
 (float)\\
 (pointers) i32*, i32**..\\
 (vector types)$\langle4 * i32\rangle$\\
 (struct types) $\{i32, i16\}$
  \\ \\
The size of the integer is not consequential to optimization, so we make this decision by the time we reach IR. \\ \\
\underline{\textbf{Risc-like opcodes}} : \textit{LLVM} has opcodes like add, load, store, call, ret, branch, conditional branch...
Unlike assembly code, these opcodes can have unbounded number of arguments.


\documentclass[11pt]{article}
\usepackage[
top    = 2.50cm,% presumably you don't want it to be 0pt as well?
bottom = 2.50cm,
left   = 2cm,
right  = 2cm,
marginparsep = 0pt,
marginparwidth=0pt,
]{geometry}

\usepackage{amssymb}
\usepackage{fancyhdr}
\usepackage{amsmath}

\pagestyle{fancy}
\fancyhead[l]{Optics - Abridged edition}
\fancyhead[r]{Giorgio G.}
\title{Optics\\
\large short notes
}
\date{}

\begin{document}

\section{Snell's law}
	\subsection{Disregarding ray velocity:}
	 	\[\eta_1\sin\theta_1 = \eta_2\sin\theta_2\]

	\subsection{Considering ray velocity:}
 	 	\[\frac{\sin\theta_1}{\sin\theta_2} = \frac{v_1}{v_2} = \frac{\eta_1}{\eta_2}\]

\section{Application of ray diagrams:}

 	 \begin{itemize}
 	 	\item{Beyond $2F$}
 	 		\subitem{Image: $\mathbb{R}$, $F$'$ <I<2F$', inverted, smaller}
 	 	\item{On $2F$}
 	 	 	\subitem{Image: $\mathbb{R}$, $I=2F$', inverted, same size}
		\item{Between $2F$}
			\subitem{Image: $\mathbb{R}$, $I>F$', inverted, larger}
		\item{On $F$}
			\subitem{Image at $\infty$}
		\item{Between $F$ \ and lens}
			\subitem{Image: virtual, $I<2F$, erect, larger}
 	 \end{itemize}

\section{Gauss lens equations:}
			\[\frac{1}{f}=\frac{1}{v}+\frac{1}{u}\]
			\[\text{real-is-positive convention}\]

\section{Linear magnification ratio:}

			\[m=\frac{v}{u}=\frac{h_i}{h_o}\]

\section{Arranged form of linear magn. ratio:}
			\[m=\frac{1}{f}\cdot v - 1\]

\end{document}


\providecommand{\main}{..}
\documentclass[\main/thesis.tex]{subfiles}
\begin{document}
\chapter*{Abstract}
Numbers are everywhere in our daily lives, and positional numeral systems are
arguably the most important and common representation of numbers.
In this work, we will investigate interesting properties and applications of
some variations of positional numeral systems and construct a generalized
positional numeral system to model and formalize them in Agda.
We will not only examine properties of our representation and its relationship
with the classical unary representation of natural numbers but also demonstrate
how to translate propositions and proofs between them.
\end{document}


\section{\src{dyn_horiz_adv_flux}}

\subsection{Description}

Kernel \src{dyn_horiz_adv_flux} is taken from the original subroutine
\src{horizontal_flux} in \NICAM.
%
This subroutine is originally defined in \src{mod_src_tracer}.
%
Subroutine \src{horizontal_flux} is to calculate horizontal advection
term, i.e. horizontal mass flux and mass centroid position of an area,
which is used for the estimation of mass flux passing through an edge of control cell during one time step.
%
In NICAM, a third order upwind scheme proposed by \cite{Miura:2007bs} is used
for the horizontal tracer advection on the icosahedral grid, briefly
described in \autoref{s:upwind_scheme}.
See section 4. in \cite{Tomita2010ecmwf} for details of tracer scheme in \NICAM, too.

\subsection{Discretization and code}

Argument lists and local variables definition part of this subroutine is
as follows.

\begin{LstF90}[name=horizontal_flux]
subroutine horizontal_flux( &
     flx_h,  flx_h_pl,  &
     GRD_xc, GRD_xc_pl, &
     rho,    rho_pl,    &
     rhovx,  rhovx_pl,  &
     rhovy,  rhovy_pl,  &
     rhovz,  rhovz_pl,  &
     dt                 )
  implicit none

  real(RP), intent(out) :: flx_h    (ADM_gall   ,ADM_kall,ADM_lall   ,6)               ! horizontal mass flux
  real(RP), intent(out) :: flx_h_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl  )
  real(RP), intent(out) :: GRD_xc   (ADM_gall   ,ADM_kall,ADM_lall   ,AI:AJ,XDIR:ZDIR) ! mass centroid position
  real(RP), intent(out) :: GRD_xc_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl,      XDIR:ZDIR)
  real(RP), intent(in)  :: rho      (ADM_gall   ,ADM_kall,ADM_lall   )                 ! rho at cell center
  real(RP), intent(in)  :: rho_pl   (ADM_gall_pl,ADM_kall,ADM_lall_pl)
  real(RP), intent(in)  :: rhovx    (ADM_gall   ,ADM_kall,ADM_lall   )
  real(RP), intent(in)  :: rhovx_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl)
  real(RP), intent(in)  :: rhovy    (ADM_gall   ,ADM_kall,ADM_lall   )
  real(RP), intent(in)  :: rhovy_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl)
  real(RP), intent(in)  :: rhovz    (ADM_gall   ,ADM_kall,ADM_lall   )
  real(RP), intent(in)  :: rhovz_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl)
  real(RP), intent(in)  :: dt

  real(RP) :: rhot_TI  (ADM_gall   ) ! rho at cell vertex
  real(RP) :: rhot_TJ  (ADM_gall   ) ! rho at cell vertex
  real(RP) :: rhot_pl  (ADM_gall_pl)
  real(RP) :: rhovxt_TI(ADM_gall   )
  real(RP) :: rhovxt_TJ(ADM_gall   )
  real(RP) :: rhovxt_pl(ADM_gall_pl)
  real(RP) :: rhovyt_TI(ADM_gall   )
  real(RP) :: rhovyt_TJ(ADM_gall   )
  real(RP) :: rhovyt_pl(ADM_gall_pl)
  real(RP) :: rhovzt_TI(ADM_gall   )
  real(RP) :: rhovzt_TJ(ADM_gall   )
  real(RP) :: rhovzt_pl(ADM_gall_pl)

  real(RP) :: rhovxt2
  real(RP) :: rhovyt2
  real(RP) :: rhovzt2
  real(RP) :: flux
  real(RP) :: rrhoa2

  integer  :: gmin, gmax, kall, iall
  real(RP) :: EPS

  integer  :: ij
  integer  :: ip1j, ijp1, ip1jp1
  integer  :: im1j, ijm1

  integer  :: i, j, k, l, n, v
  !---------------------------------------------------------------------------
\end{LstF90}

Output variable \src{flx_h} is horizontal mass flux and \src{GRD_xc} is
the spatial position $\bm{C}_i$ in \autoref{f:2007mwr2101_1-0}(b).
%
Note that
\src{flx_h} has 4th dimension whose size is 6, specifying
6 edges of hexagon control volume.
%
Similarly,
\src{GRD_xc} has 4th dimension ranged \src{(AI:AJ)} and 5th
dimension ranged \src{(XDIR:ZDIR)}, the former specifies three arc
points and the latter specifies 3 coodinates of the position.
%
Input variable \src{rho}, \src{rhovx},
\src{rhovy} and \src{rhovz} are $\rho$, $\rho v_x$, $\rho v_y$, and $\rho v_z$
at cell center with metrics multiplied, respectively.
%
Other arguments with suffix \src{_pl} are for the pole region.

Among local variables, \src{rhot_TI}, \src{rhot_TJ} are interpolated $\rho$ at
the gravitational center of downward triangle and upward triangle, respectively.
Other variables \src{rho*} with suffix \src{_TI}, \src{_TJ} are the same.

The first half of main part is as follows.

\begin{LstF90}[name=horizontal_flux,firstnumber=last]
  call DEBUG_rapstart('____horizontal_adv_flux')

  gmin = ADM_gmin
  gmax = ADM_gmax
  kall = ADM_kall
  iall = ADM_gall_1d

  EPS  = CONST_EPS

  do l = 1, ADM_lall
     !$omp parallel default(none), &
     !$omp private(i,j,k,ij,ip1j,ip1jp1,ijp1,im1j,ijm1,                                        &
     !$omp         rrhoa2,rhovxt2,rhovyt2,rhovzt2,flux),                                       &
     !$omp shared(l,ADM_have_sgp,gmin,gmax,kall,iall,rho,rhovx,rhovy,rhovz,flx_h,dt,           &
     !$omp        rhot_TI,rhovxt_TI,rhovyt_TI,rhovzt_TI,rhot_TJ,rhovxt_TJ,rhovyt_TJ,rhovzt_TJ, &
     !$omp        GRD_xc,GRD_xr,GMTR_p,GMTR_t,GMTR_a,EPS)
     do k = 1, kall

        ! (i,j),(i+1,j)
        !$omp do
        do j = gmin-1, gmax
        do i = gmin-1, gmax
           ij     = (j-1)*iall + i
           ip1j   = ij + 1

           rhot_TI  (ij) = rho  (ij  ,k,l) * GMTR_t(ij,K0,l,TI,W1) &
                         + rho  (ip1j,k,l) * GMTR_t(ij,K0,l,TI,W2)
           rhovxt_TI(ij) = rhovx(ij  ,k,l) * GMTR_t(ij,K0,l,TI,W1) &
                         + rhovx(ip1j,k,l) * GMTR_t(ij,K0,l,TI,W2)
           rhovyt_TI(ij) = rhovy(ij  ,k,l) * GMTR_t(ij,K0,l,TI,W1) &
                         + rhovy(ip1j,k,l) * GMTR_t(ij,K0,l,TI,W2)
           rhovzt_TI(ij) = rhovz(ij  ,k,l) * GMTR_t(ij,K0,l,TI,W1) &
                         + rhovz(ip1j,k,l) * GMTR_t(ij,K0,l,TI,W2)

           rhot_TJ  (ij) = rho  (ij  ,k,l) * GMTR_t(ij,K0,l,TJ,W1)
           rhovxt_TJ(ij) = rhovx(ij  ,k,l) * GMTR_t(ij,K0,l,TJ,W1)
           rhovyt_TJ(ij) = rhovy(ij  ,k,l) * GMTR_t(ij,K0,l,TJ,W1)
           rhovzt_TJ(ij) = rhovz(ij  ,k,l) * GMTR_t(ij,K0,l,TJ,W1)
        enddo
        enddo
        !$omp end do

        ! (i,j+1),(i+1,j+1)
        !$omp do
        do j = gmin-1, gmax
        do i = gmin-1, gmax
           ij     = (j-1)*iall + i
           ijp1   = ij + iall
           ip1jp1 = ij + iall + 1

           rhot_TI  (ij) = rhot_TI  (ij) + rho  (ip1jp1,k,l) * GMTR_t(ij,K0,l,TI,W3)
           rhovxt_TI(ij) = rhovxt_TI(ij) + rhovx(ip1jp1,k,l) * GMTR_t(ij,K0,l,TI,W3)
           rhovyt_TI(ij) = rhovyt_TI(ij) + rhovy(ip1jp1,k,l) * GMTR_t(ij,K0,l,TI,W3)
           rhovzt_TI(ij) = rhovzt_TI(ij) + rhovz(ip1jp1,k,l) * GMTR_t(ij,K0,l,TI,W3)

           rhot_TJ  (ij) = rhot_TJ  (ij) + rho  (ip1jp1,k,l) * GMTR_t(ij,K0,l,TJ,W2) &
                                         + rho  (ijp1  ,k,l) * GMTR_t(ij,K0,l,TJ,W3)
           rhovxt_TJ(ij) = rhovxt_TJ(ij) + rhovx(ip1jp1,k,l) * GMTR_t(ij,K0,l,TJ,W2) &
                                         + rhovx(ijp1  ,k,l) * GMTR_t(ij,K0,l,TJ,W3)
           rhovyt_TJ(ij) = rhovyt_TJ(ij) + rhovy(ip1jp1,k,l) * GMTR_t(ij,K0,l,TJ,W2) &
                                         + rhovy(ijp1  ,k,l) * GMTR_t(ij,K0,l,TJ,W3)
           rhovzt_TJ(ij) = rhovzt_TJ(ij) + rhovz(ip1jp1,k,l) * GMTR_t(ij,K0,l,TJ,W2) &
                                         + rhovz(ijp1  ,k,l) * GMTR_t(ij,K0,l,TJ,W3)
        enddo
        enddo
        !$omp end do

        if ( ADM_have_sgp(l) ) then
           !$omp master
           j = gmin-1
           i = gmin-1

           ij   = (j-1)*iall + i
           ip1j = ij + 1

           rhot_TI  (ij) = rhot_TJ  (ip1j)
           rhovxt_TI(ij) = rhovxt_TJ(ip1j)
           rhovyt_TI(ij) = rhovyt_TJ(ip1j)
           rhovzt_TI(ij) = rhovzt_TJ(ip1j)
           !$omp end master
        endif

\end{LstF90}%$$

In long $l$-loop and $k$-loop, first part calculate $\rho$, $\rho v_x$,
$\rho v_y$, $\rho v_z$ at two center points of triangle at \src{TI} and \src{TJ}.
%
Note that two triangular points are surrounded by 4 grid points $(i,j)$,
$(i+1,j)$, $(i+1,j+1)$ and $(i,j+1)$.
%
The first $i,j$-double loop(l.73-) calculates contribution from the former two
grid points, and the second $i,j$-double loop(l.97-) does from the latter
two grid points.
%
\src{IF} clause from l.120 is treatment for the singular point.
%
\src{GMTR_t} is the metrics for triangle linear interpolation from three trianglar vertices to gravitational center point of triangle.
In original \NICAM, this array is defined as \src{GMTR_T_var} in module
\src{mod_gmtr}.
%
In this kernel program, this is read from input data file.
%
Note that \src{TI}, \src{TJ}, \src{W1}, \src{W2} and \src{W3} are not
loop index but constant defined in \file{problem_size.inc}, those are
originally defined in \src{mod_gmtr} in \NICAM.

The second half of main part is as follows.

\begin{LstF90}[name=horizontal_flux,firstnumber=last]
        !--- calculate flux and mass centroid position

!OCL XFILL
        !$omp do
        do j = 1, iall
        do i = 1, iall
           if (      i < gmin .OR. i > gmax &
                .OR. j < gmin .OR. j > gmax ) then
              ij = (j-1)*iall + i

              flx_h(ij,k,l,1) = 0.0_RP
              flx_h(ij,k,l,2) = 0.0_RP
              flx_h(ij,k,l,3) = 0.0_RP
              flx_h(ij,k,l,4) = 0.0_RP
              flx_h(ij,k,l,5) = 0.0_RP
              flx_h(ij,k,l,6) = 0.0_RP

              GRD_xc(ij,k,l,AI ,XDIR) = 0.0_RP
              GRD_xc(ij,k,l,AI ,YDIR) = 0.0_RP
              GRD_xc(ij,k,l,AI ,ZDIR) = 0.0_RP
              GRD_xc(ij,k,l,AIJ,XDIR) = 0.0_RP
              GRD_xc(ij,k,l,AIJ,YDIR) = 0.0_RP
              GRD_xc(ij,k,l,AIJ,ZDIR) = 0.0_RP
              GRD_xc(ij,k,l,AJ ,XDIR) = 0.0_RP
              GRD_xc(ij,k,l,AJ ,YDIR) = 0.0_RP
              GRD_xc(ij,k,l,AJ ,ZDIR) = 0.0_RP
           endif
        enddo
        enddo
        !$omp end do

        !$omp do
        do j = gmin  , gmax
        do i = gmin-1, gmax
           ij     = (j-1)*iall + i
           ip1j   = ij + 1
           ijm1   = ij - iall

           rrhoa2  = 1.0_RP / max( rhot_TJ(ijm1) + rhot_TI(ij), EPS ) ! doubled
           rhovxt2 = rhovxt_TJ(ijm1) + rhovxt_TI(ij)
           rhovyt2 = rhovyt_TJ(ijm1) + rhovyt_TI(ij)
           rhovzt2 = rhovzt_TJ(ijm1) + rhovzt_TI(ij)

           flux = 0.5_RP * ( rhovxt2 * GMTR_a(ij,k0,l,AI ,HNX) &
                           + rhovyt2 * GMTR_a(ij,k0,l,AI ,HNY) &
                           + rhovzt2 * GMTR_a(ij,k0,l,AI ,HNZ) )

           flx_h(ij  ,k,l,1) =  flux * GMTR_p(ij  ,k0,l,P_RAREA) * dt
           flx_h(ip1j,k,l,4) = -flux * GMTR_p(ip1j,k0,l,P_RAREA) * dt

           GRD_xc(ij,k,l,AI,XDIR) = GRD_xr(ij,K0,l,AI,XDIR) - rhovxt2 * rrhoa2 * dt * 0.5_RP
           GRD_xc(ij,k,l,AI,YDIR) = GRD_xr(ij,K0,l,AI,YDIR) - rhovyt2 * rrhoa2 * dt * 0.5_RP
           GRD_xc(ij,k,l,AI,ZDIR) = GRD_xr(ij,K0,l,AI,ZDIR) - rhovzt2 * rrhoa2 * dt * 0.5_RP
        enddo
        enddo
        !$omp end do

        !$omp do
        do j = gmin-1, gmax
        do i = gmin-1, gmax
           ij     = (j-1)*iall + i
           ip1jp1 = ij + iall + 1

           rrhoa2  = 1.0_RP / max( rhot_TI(ij) + rhot_TJ(ij), EPS ) ! doubled
           rhovxt2 = rhovxt_TI(ij) + rhovxt_TJ(ij)
           rhovyt2 = rhovyt_TI(ij) + rhovyt_TJ(ij)
           rhovzt2 = rhovzt_TI(ij) + rhovzt_TJ(ij)

           flux = 0.5_RP * ( rhovxt2 * GMTR_a(ij,k0,l,AIJ,HNX) &
                           + rhovyt2 * GMTR_a(ij,k0,l,AIJ,HNY) &
                           + rhovzt2 * GMTR_a(ij,k0,l,AIJ,HNZ) )

           flx_h(ij    ,k,l,2) =  flux * GMTR_p(ij    ,k0,l,P_RAREA) * dt
           flx_h(ip1jp1,k,l,5) = -flux * GMTR_p(ip1jp1,k0,l,P_RAREA) * dt

           GRD_xc(ij,k,l,AIJ,XDIR) = GRD_xr(ij,K0,l,AIJ,XDIR) - rhovxt2 * rrhoa2 * dt * 0.5_RP
           GRD_xc(ij,k,l,AIJ,YDIR) = GRD_xr(ij,K0,l,AIJ,YDIR) - rhovyt2 * rrhoa2 * dt * 0.5_RP
           GRD_xc(ij,k,l,AIJ,ZDIR) = GRD_xr(ij,K0,l,AIJ,ZDIR) - rhovzt2 * rrhoa2 * dt * 0.5_RP
        enddo
        enddo
        !$omp end do

        !$omp do
        do j = gmin-1, gmax
        do i = gmin  , gmax
           ij     = (j-1)*iall + i
           ijp1   = ij + iall
           im1j   = ij - 1

           rrhoa2  = 1.0_RP / max( rhot_TJ(ij) + rhot_TI(im1j), EPS ) ! doubled
           rhovxt2 = rhovxt_TJ(ij) + rhovxt_TI(im1j)
           rhovyt2 = rhovyt_TJ(ij) + rhovyt_TI(im1j)
           rhovzt2 = rhovzt_TJ(ij) + rhovzt_TI(im1j)

           flux = 0.5_RP * ( rhovxt2 * GMTR_a(ij,k0,l,AJ ,HNX) &
                           + rhovyt2 * GMTR_a(ij,k0,l,AJ ,HNY) &
                           + rhovzt2 * GMTR_a(ij,k0,l,AJ ,HNZ) )

           flx_h(ij  ,k,l,3) =  flux * GMTR_p(ij  ,k0,l,P_RAREA) * dt
           flx_h(ijp1,k,l,6) = -flux * GMTR_p(ijp1,k0,l,P_RAREA) * dt

           GRD_xc(ij,k,l,AJ,XDIR) = GRD_xr(ij,K0,l,AJ,XDIR) - rhovxt2 * rrhoa2 * dt * 0.5_RP
           GRD_xc(ij,k,l,AJ,YDIR) = GRD_xr(ij,K0,l,AJ,YDIR) - rhovyt2 * rrhoa2 * dt * 0.5_RP
           GRD_xc(ij,k,l,AJ,ZDIR) = GRD_xr(ij,K0,l,AJ,ZDIR) - rhovzt2 * rrhoa2 * dt * 0.5_RP
        enddo
        enddo
        !$omp end do

        if ( ADM_have_sgp(l) ) then
           !$omp master
           j = gmin
           i = gmin

           ij = (j-1)*iall + i

           flx_h(ij,k,l,6) = 0.0_RP
           !$omp end master
        endif

     enddo
     !$omp end parallel
  enddo

\end{LstF90}

There are 4 $i,j$-double loops in the long $k$ and $l$ loop
continued from previous section.
%
After setting halo region as $0.0$, each 3 loops calculates\src{flx_h} and
\src{GRD_x}c at each 3 arc points specified by \src{AI}, \src{AIJ}, \src{AJ}.
%
Here \src{GMTR_a} is the metrics for the arc points (the normal vector on the arc point).
%
In original \NICAM, the array is defined as \src{GMTR_A_var} in module
\src{mod_gmtr}. In this kernel program, this is read from input data file.
%
Similarly, \src{GMTR_p} is the metrics for grid points (the reciprocal number of the area of the control cell).

The last part is for the pole region, doing almost same calculation with
the normal region.

\begin{LstF90}[name=horizontal_flux,firstnumber=last]
  if ( ADM_have_pl ) then
     n = ADM_gslf_pl

     do l = 1, ADM_lall_pl
     do k = 1, ADM_kall

        do v = ADM_gmin_pl, ADM_gmax_pl
           ij   = v
           ijp1 = v + 1
           if( ijp1 == ADM_gmax_pl + 1 ) ijp1 = ADM_gmin_pl

           rhot_pl  (v) = rho_pl  (n   ,k,l) * GMTR_t_pl(ij,K0,l,W1) &
                        + rho_pl  (ij  ,k,l) * GMTR_t_pl(ij,K0,l,W2) &
                        + rho_pl  (ijp1,k,l) * GMTR_t_pl(ij,K0,l,W3)
           rhovxt_pl(v) = rhovx_pl(n   ,k,l) * GMTR_t_pl(ij,K0,l,W1) &
                        + rhovx_pl(ij  ,k,l) * GMTR_t_pl(ij,K0,l,W2) &
                        + rhovx_pl(ijp1,k,l) * GMTR_t_pl(ij,K0,l,W3)
           rhovyt_pl(v) = rhovy_pl(n   ,k,l) * GMTR_t_pl(ij,K0,l,W1) &
                        + rhovy_pl(ij  ,k,l) * GMTR_t_pl(ij,K0,l,W2) &
                        + rhovy_pl(ijp1,k,l) * GMTR_t_pl(ij,K0,l,W3)
           rhovzt_pl(v) = rhovz_pl(n   ,k,l) * GMTR_t_pl(ij,K0,l,W1) &
                        + rhovz_pl(ij  ,k,l) * GMTR_t_pl(ij,K0,l,W2) &
                        + rhovz_pl(ijp1,k,l) * GMTR_t_pl(ij,K0,l,W3)
        enddo

        do v = ADM_gmin_pl, ADM_gmax_pl
           ij   = v
           ijm1 = v - 1
           if( ijm1 == ADM_gmin_pl - 1 ) ijm1 = ADM_gmax_pl

           rrhoa2  = 1.0_RP / max( rhot_pl(ijm1) + rhot_pl(ij), EPS ) ! doubled
           rhovxt2 = rhovxt_pl(ijm1) + rhovxt_pl(ij)
           rhovyt2 = rhovyt_pl(ijm1) + rhovyt_pl(ij)
           rhovzt2 = rhovzt_pl(ijm1) + rhovzt_pl(ij)

           flux = 0.5_RP * ( rhovxt2 * GMTR_a_pl(ij,K0,l,HNX) &
                           + rhovyt2 * GMTR_a_pl(ij,K0,l,HNY) &
                           + rhovzt2 * GMTR_a_pl(ij,K0,l,HNZ) )

           flx_h_pl(v,k,l) = flux * GMTR_p_pl(n,K0,l,P_RAREA) * dt

           GRD_xc_pl(v,k,l,XDIR) = GRD_xr_pl(v,K0,l,XDIR) - rhovxt2 * rrhoa2 * dt * 0.5_RP
           GRD_xc_pl(v,k,l,YDIR) = GRD_xr_pl(v,K0,l,YDIR) - rhovyt2 * rrhoa2 * dt * 0.5_RP
           GRD_xc_pl(v,k,l,ZDIR) = GRD_xr_pl(v,K0,l,ZDIR) - rhovzt2 * rrhoa2 * dt * 0.5_RP
        enddo

     enddo
     enddo
  endif

  call DEBUG_rapend  ('____horizontal_adv_flux')

  return
end subroutine horizontal_flux
\end{LstF90}

\subsection{Input data and result}

Max/min/sum of input/output data of the kernel subroutine are output as
a log.
%
Below is an example of \src{$IAB_SYS=Ubuntu-gnu-ompi} case.

\begin{LstLog}
 ### Input ###
 +check[flx_h           ] max=  1.5610710092943020E-01,min= -1.5670677438306818E-01,sum=  2.5627807148368471E+00
 +check[flx_h_pl        ] max=  1.1002449397299904E-01,min= -1.0379423223736732E-01,sum=  2.3428578735122479E-02
 +check[GRD_xc          ] max=  6.3711740974481208E+06,min= -2.8421843880731151E+06,sum=  2.0008127660775812E+13
 +check[GRD_xc_pl       ] max=  6.3711707368004546E+06,min= -6.3711702446065033E+06,sum= -5.2402711763852555E+05
 +check[rhog_mean       ] max=  1.3664531579209602E+00,min=  3.0688241919459083E-02,sum=  3.0079615977439255E+05
 +check[rhog_mean_pl    ] max=  1.3664531579209602E+00,min=  3.0688131204860365E-02,sum=  2.1686973266477614E+02
 +check[rhogvx          ] max=  2.4807620495454326E+01,min= -2.6743430307618826E+01,sum= -7.2284486916298035E+05
 +check[rhogvx_pl       ] max=  2.3291561831945440E+01,min= -1.7023283571413913E+01,sum=  7.6579748418940346E+02
 +check[rhogvy          ] max=  3.6016622784129858E+01,min= -3.3418704823922688E+01,sum=  8.9473900044437428E+05
 +check[rhogvy_pl       ] max=  8.7323000593655760E+00,min= -9.4486634372500102E+00,sum=  1.2151517834227268E+03
 +check[rhogvz          ] max=  2.3202617358688446E+01,min= -2.4977800359078525E+01,sum=  1.1280540293791931E+05
 +check[rhogvz_pl       ] max=  1.6015604765102806E-01,min= -1.3081853271482025E-01,sum=  1.6285945760677518E+00
 +check[GRD_xr          ] max=  4.0592444288400000E+13,min= -9.9998999999999996E+30,sum= -1.5719842799999647E+34
 +check[GRD_xr_pl       ] max=  6.3711570243787766E+06,min= -9.9998999999999996E+30,sum= -5.9999399999999993E+31
 +check[GMTR_p          ] max=  3.1937623126446486E+09,min= -1.0000000000000000E+00,sum=  5.2568771941580258E+13
 +check[GMTR_p_pl       ] max=  2.6945919723895960E+09,min= -1.0000000000000000E+00,sum=  3.0761871439307461E+10
 +check[GMTR_t          ] max=  1.5988904134747729E+09,min=  0.0000000000000000E+00,sum=  5.1787428410119117E+13
 +check[GMTR_t_pl       ] max=  1.9722549493151660E+09,min=  0.0000000000000000E+00,sum=  1.9722549503025471E+10
 +check[GMTR_a          ] max=  6.3362880879999531E+04,min= -6.0857794015098916E+04,sum=  7.9258961023823655E+08
 +check[GMTR_a_pl       ] max=  5.7873883883004550E+04,min= -5.7872753043726123E+04,sum= -4.3064210331067443E-07
 ### Output ###
 +check[flx_h           ] max=  1.5610710092943020E-01,min= -1.5670677438306818E-01,sum=  2.5627807148368471E+00
 +check[flx_h_pl        ] max=  1.1002449397299904E-01,min= -1.0379423223736732E-01,sum=  2.3428578735122479E-02
 +check[GRD_xc          ] max=  6.3711740974481208E+06,min= -2.8421843880731151E+06,sum=  2.0008127660775812E+13
 +check[GRD_xc_pl       ] max=  6.3711707368004546E+06,min= -6.3711702446065033E+06,sum= -5.2402711763852555E+05
 ### Validation : point-by-point diff ###
 +check[check_flx_h     ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[check_flx_h_pl  ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[check_GRD_xc    ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[check_GRD_xc_pl ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 *** Finish kernel
\end{LstLog}

Check the lines below \src{``Validation : point-by-point diff''} line,
that shows difference between calculated output array and
pre-calculated reference array.
These should be zero or enough small to be acceptable.

There are sample output log files in \file{reference/}
in each kernel program directory, for reference purpose.

\subsection{Sample of perfomance result}

Here's an example of the performance result part of the log output.
Below is an example executed with the machine environment described in \autoref{s:measuring_env}.
%
Note that in this program kernel part is iterated one time.

\begin{LstLog}
 *** Computational Time Report
 *** ID=001 : MAIN_dyn_horiz_adv_flux          T=     0.040 N=      1
 *** ID=002 : ____horizontal_adv_flux          T=     0.040 N=      1
\end{LstLog}


\section{The Guarded Recursion Checker}
\label{sec:guard-recurs-check}
The term inferred by the inference system is potentially ill-typed according to the
guarded recursion typing rules. If this is the case, the input term can not be
guaranteed to be productive. We therefore need a way of checking types of
guarded recursive terms.

The checking algorithm is based on the typing rules defined by M\o
gelberg\,\citep{Mogelberg:2014}, although they have been adjusted according to
the restrictions imposed by the singleton clock. In Figure~\ref{fig:gr_rules_sin_clock}, we
present the adjusted typing rules. Each rule is presented alongside the original
rule, and the translation is explained. Note that the
checking environment(\emph{CE}) is expanded with a recursive reference, $\iota$, a modality, $\Psi$,
and a singleton clock environment. These extensions to the environment
have the same definitions as those given for the inference environment in
Section~\ref{sec:inference-system}. Also, the $fix^\kappa$-rule from M\o
gelberg's set of rules is missing. Due to fixed point elimination, discussed in
Section~\ref{sec:fixkappa-rule}, the rule for the fixed point operator is
replaced by rules for the recursive reference, for both the causal and the non-causal case.

As the input to the guarded recursion checking system is TT terms, the checking system is a
decoupled extension to the existing TT type system presented in Section~\ref{sec:tt-core-type}. In any situation where
both a standard TT rule and a guarded recursion rule applies, the guarded
recursion rule must be chosen in order to ensure that all side conditions are checked.

% the standard Idris typing
% rules\,\citep{BradyIdrisImpl13} do also apply, however the guarded recursive
% rules take precedence and will be applied if possible.

\subsubsection{The Typing Judgment}
The checking system operates with a standard typing judgment.
\begin{center}
  ${CE\vdash e : A}$
\end{center}
It reads: ``$e$ has type $A$ in the checking environment $CE$''.

\input{figures/guarded_typing_rules}
\subsection{An Example}
In Figure~\ref{fig:repeat_inference_proof} an inference of the guarded recursive
version of the function \texttt{repeat}'s guarded-recursive counterpart was shown. In continuation of this, we
show that $_g$\texttt{repeat} is productive according to the guarded recursion
checking rules. The derivation is given in Figure~\ref{fig:repeat_typing_example}. Additional examples of such proofs can be found in Appendix~\ref{app:check-guard-recurs}.

\input{figures/repeat_typing_example}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../copatterns-thesis"
%%% End:


\subsubsection{Influence of Sliding Window Filter} \label{influence_of_sliding_window_filter}
23 different simulations were tested that use $\eta$DTW with a Sakoe-Chiba band of size 36\% depending on the input
time series length, \textit{HAveD} as threshold determination and \textit{Mid} as window size determination. One of
those simulations has no filter, the other 22 simulations have a filter with the underlying time series measure LNCE or
VAR in combination with eleven different blur factors. Figure \ref{fig:sliding_window_filter_result} illustrates the
distribution of the three subsets. 20 simulations are reaching a $F_{1}score_{\mu}$ value greater or equal to 0.7. Every
underlying time series measure for the filter is represented in those 20 simulations. One simulation with a filter
reaches the same $F_{1}score_{\mu}$ as the best performing simulation without filter.

\begin{figure}[H]
    \begin{center}
        \resizebox {\textwidth} {!} {
            \begin{tabular}{cc}
                \resizebox {!} {\height} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            legend pos=north west,
                            xmin=0.7,
                            xmax=0.9,
                            ymin=0.5,
                            ymax=0.7,
                            width=\axisdefaultwidth,
                            height=\axisdefaultwidth,
                            xlabel=$Precision_{\mu}$,
                            ylabel=$Recall_{\mu}$,
                            samples=100]
                            \addplot[blue, mark=o, only marks] table {../data/fig/sliding_window_filter_result/lnce.dat};
                            \addlegendentry{LNCE}
                            \addplot[red, mark=triangle, only marks] table {../data/fig/sliding_window_filter_result/var.dat};
                            \addlegendentry{VAR}
                            \addplot[black, mark=square, only marks] table {../data/fig/sliding_window_filter_result/nofilter.dat};
                            \addlegendentry{No Filter}
                            \addplot[gray, domain=0.31:1] {(0.6 * x) / (2 * x - 0.6)};
                            \addplot[gray, domain=0.36:1] {(0.7 * x) / (2 * x - 0.7)};
                        \end{axis}
                    \end{tikzpicture}
                } &
                \resizebox {!} {\height} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            xmin=0,
                            xmax=1,
                            ymin=0,
                            ymax=1,
                            width=\axisdefaultwidth,
                            height=\axisdefaultwidth,
                            xlabel=$Precision_{\mu}$,
                            ylabel=$Recall_{\mu}$,
                            samples=100]
                            \addplot[blue, mark=o, only marks] table {../data/fig/sliding_window_filter_result/lnce.dat};
                            \addplot[red, mark=triangle, only marks] table {../data/fig/sliding_window_filter_result/var.dat};
                            \addplot[black, mark=square, only marks] table {../data/fig/sliding_window_filter_result/nofilter.dat};
                            \addplot[gray, domain=0.051:1] {(0.1 * x) / (2 * x - 0.1)};
                            \addplot[gray, domain=0.11:1] {(0.2 * x) / (2 * x - 0.2)};
                            \addplot[gray, domain=0.16:1] {(0.3 * x) / (2 * x - 0.3)};
                            \addplot[gray, domain=0.21:1] {(0.4 * x) / (2 * x - 0.4)};
                            \addplot[gray, domain=0.26:1] {(0.5 * x) / (2 * x - 0.5)};
                            \addplot[gray, domain=0.31:1] {(0.6 * x) / (2 * x - 0.6)};
                            \addplot[gray, domain=0.36:1] {(0.7 * x) / (2 * x - 0.7)};
                            \addplot[gray, domain=0.41:1] {(0.8 * x) / (2 * x - 0.8)};
                            \addplot[gray, domain=0.46:1] {(0.9 * x) / (2 * x - 0.9)};
                        \end{axis}
                    \end{tikzpicture}
                }
            \end{tabular}
        }
    \end{center}
    \caption{$Precision_{\mu}$ and $Recall_{\mu}$ of all simulations that use $\eta$DTW with a Sakoe-Chiba band of size
    36\% depending on the input time series length, \textit{HAveD} as threshold determination and \textit{Mid} as window
    size determination, separated by the used sliding window filter. The left plot is a zoomed version of the right
    plot. Gray lines are illustrating the distribution of $F_{1}score_{\mu}$ in $\frac{1}{10}$ steps.}
    \label{fig:sliding_window_filter_result}
\end{figure}

\input{experiment/evaluation/influence_of_sliding_window_filter/influence_of_blur_factor.tex}


\documentclass[11pt]{article}
%============Macros==================%
% you don't need to change anything. start editing from main body.
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{qcircuit}
\usepackage[margin=1in]{geometry}
%--------------Cosmetic----------------%
\usepackage{mathtools}
\usepackage{hyperref}
\usepackage{fullpage}
\usepackage{microtype}
\usepackage{xspace}
\usepackage[svgnames]{xcolor}
\usepackage[sc]{mathpazo}
\usepackage{enumitem}
\usepackage{braket}
\usepackage{amsmath}
\setlist[enumerate]{itemsep=1pt,topsep=2pt}
\setlist[itemize]{itemsep=1pt,topsep=2pt}
\usepackage{graphicx}
\graphicspath{ {images/} }
\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
%--------------Header------------------%
\def\course{CS 410/510 Introduction to Quantum Computing}
\def\term{Portland State U, Spring 2017}
\def\prof{Lecturer: Fang Song}
\newcommand{\handout}[5]{
   \renewcommand{\thepage}{\arabic{page}}
   \begin{center}
   \framebox{
      \vbox{
    \hbox to 5.78in { \hfill \large{\course} \hfill }
       \vspace{2mm}
       \hbox to 6in { {\Large \hfill #5  \hfill} }
       \vspace{2mm}
       \hbox to 6in { \term \hfill \emph{#2}}
       \hbox to 6in { {#3 \hfill \emph{#4}}}
      }
   }
   \end{center}
   \vspace*{4mm}
}
\newcommand{\lecture}[4]{\handout{#1}{#2}{#3}{#4}{{Lecture #1}}}
%=============Main Doc=================%
\begin{document}
%-----Specs: change accordingly--------%
\def\lecdate{May 04, 2017} % put lecture date here
\def\scribe{Scribe: Asher Toback} % put your name here
\def\lecnum{10} % change the lecture number

\lecture{\lecnum}{\lecdate}{\prof}{\scribe}%

\begin{center}
{\textsc{Version: \today}}
\end{center}

%\section{Introduction}
In this lecture we'll be discussing why Grover's search is the optimal
searching algorithm in the query model of quantum computing. It's
assumed the reader already has a working knowledge of how Grover's
Searching Algorithm works; namely, that it can be done within
$O(\sqrt{N})$ querries, where $N = 2^n$. We'll show that any searching
algorithm must take a minimum of this many querries, and thus Grover's
is optimal. We'll do this by arguing what a general searching
algorithm must look like, prove two lemmas, and then use these lemmas
to prove the optimality of Grover. Let's begin.

%\begin{figure}[h!]
%\centering
%\includegraphics[scale=1.7]{universe.jpg}
%\caption{The Universe}
%\label{fig:univerise}
%\end{figure}

\section{General Search Algorithm Setup}

We'll be concerning ourselves with the strictest search algorithm,
where there is only one marked element that we're searching
for. Namely, we're given a boolean function $f$

{
\[f : \{0,1\}^n \xrightarrow{} \{0,1\}\]
}

where $\exists! r \text{ such that } f(r) = 1.$ We also assume we have access to an oracle $O_f$ such that

{
\[\ket{x}  \xrightarrow{O_f } (-1)^{f(x)}\ket{x}.\]
}

Because $r$ is the only element such that $f(r) = 1$, we see that if we had a superposition $\sum\alpha_x\ket{x}$ and applied $O_f$ you get

\abovedisplayskip=0pt\relax
\[
\sum\alpha_x\ket{x} \xrightarrow{O_f}
\begin{cases}
-\alpha_r\ket{r}  & \text{if } x = r\\
\alpha_x\ket{x}  & \text{if } x \neq r
\end{cases}
\]

Now, we're assuming $\alpha_r$ is small, otherwise we wouldn't need a searching algorithm. Thus, when we apply $O_f$ to our superposition, the superposition won't be affected very much. So, intuitively, we must spend many querries to find $r$. We'll show that it requires $\sqrt{N}$.

\section{Theorem Setup}

We claim that any k-query quantum search algorithm has the circuit form.

{
\[\ket{0^m} \xrightarrow{U_0}\xrightarrow{O_f}\xrightarrow{U_1}\xrightarrow{O_f}...\xrightarrow{U_k}\xrightarrow{O_f} \ket{\psi_r^{(k)}}\]
}

Namely, you apply an arbitrary unitary followed by a call to the oracle to the input state, and you do this $k$ times. It should be noted that each unitary could be different. We then compare this to the circuit:

{
\[\ket{0^m} \xrightarrow{U_0}\xrightarrow{\mathbb{I}}\xrightarrow{U_1}\xrightarrow{\mathbb{I}}...\xrightarrow{U_k}\xrightarrow{\mathbb{I}} \ket{\phi^{(k)}}\]
%\[U_i \text{ then } \mathbb{I} : \ket{0^m} \xrightarrow{} \ket{\phi^{(k)}}\]
}

Where $\mathbb{I}$ is the identity matrix and the unitaries applied are identical to the ones applied in the previous circuit. Now, we will try to show that $\exists r$ such that $\lVert \ket{\psi_r^{(k)}} - \ket{\phi^{(k)}} \rVert \leq 2k/2\sqrt{N}$, where $\lVert \text{.} \rVert$ is the euclidean distance metric. Intuitively this is saying that these two processes are practically indistinguishable. However, since we aren't querrying the oracle in the second circuit, this means we aren't learning anything about $r$, the marked element. Thus, we're essentially saying we learn nothing about $r$ from $\ket{\psi_r^{(k)}}$ unless we query enough times so that $2k/2\sqrt{N}$ is big. But this would mean we'd need to query close to $\sqrt{N}$ times, which is just what we want to show. In order to prove this we must prove two lemmas first. Before we do, let's introduce two simplifying notations. First:

{
\[D^{(i)}_r := \lVert \ket{\psi_r^{(i)}} - \ket{\phi^{(i)}} \rVert \]
}

This is simply comparing the states after the $i^{th}$ step of the two circuits. With this notation we then want to show that $\exists r$ such that $D^{(k)}_r \leq 2k/2\sqrt{N}$. And lastly:

{
\[E^{(j-1)}_r := \lVert O_f\ket{\phi^{(j-1)}} - \ket{\phi^{(j-1)}} \rVert \]
}

This equation can be thought of as the $error$ the second circuit made by not querrying the oracle $O_f$. With these let's proceed.

\section{Lemma 1}

We'll first prove that

{
\[D^{(j)}_r \leq D^{(j-1)}_r + E^{(j-1)}_r\]
}

for $ j = \{0,1,...,k-1\}$. Let's first rewrite $D^{(j)}_r$. Clearly the $j^{th}$ step of each circuit can be thought of as applying $U^j$ and either $O_f$ or $\mathbb{I}$, depending on which circuit you're in, to the $(j-1)^{th}$ step of the circuit. Namely:

{
\[D^{(j)}_r = \lVert \ket{\psi_r^{(j)}} - \ket{\phi^{(j)}} \rVert\]
\[= \lVert U_j O_f\ket{\psi_r^{(j-1)}} - U_j \mathbb{I} \ket{\phi^{(j-1)}} \rVert\]
\[= \lVert U_j O_f\ket{\psi_r^{(j-1)}} - U_j O_f \ket{\phi^{(j-1)}} + U_j O_f \ket{\phi^{(j-1)}} - U_j \mathbb{I} \ket{\phi^{(j-1)}} \rVert\]
}

Then, by the triangle inequality:

{
\[\leq \lVert U_j O_f(\ket{\psi_r^{(j-1)}} -\ket{\phi^{(j-1)}}) \rVert + \lVert U_j (O_f\ket{\phi^{(j-1)}} -\mathbb{I} \ket{\phi^{(j-1)}}) \rVert\]
}

However, we know that unitaries don't effect the length of these vectors. Thus:

{
\[= \lVert \ket{\psi_r^{(j-1)}} -\ket{\phi^{(j-1)}} \rVert + \lVert O_f\ket{\phi^{(j-1)}} -\mathbb{I} \ket{\phi^{(j-1)}} \rVert\]
\[= D^{(j-1)}_r + E^{(j-1)}_r\]
}

Which is just what we wanted to show.

\section{Lemma 2}

We'll now prove that

{
\[E^{(j)}_r \leq 2 \abs{ \alpha_r^{(j)}} \]
}

for $ j = \{0,1,...,k-1\}$. Let's first rewrite $E^{(j)}_r$ using it's definition.

{
\[E^{(j)}_r = \lVert O_f\ket{\phi^{(j)}} - \ket{\phi^{(j)}} \rVert \]
}

But, by analysis given in section 2 of this paper, we know that $O_f$ only truly affects the marked element, so we know that we can rewrite this as:

{
\[= \lVert (\sum_{x \neq r}\alpha_x^{(j)}\ket{x} - \alpha_r^{(j)}\ket{r}) - (\sum_{x \neq r}\alpha_x^{(j)}\ket{x} + \alpha_r^{(j)}\ket{r})\rVert \]
\[= 2\lVert \alpha_r^{(j)} \ket{r}\rVert\]
}

But $\lVert \ket{r}\rVert = 1$. Thus,

{
\[= 2\abs{\alpha_r^{(j)}}\]
}

Just as we wanted.

\section{Theorem Proof}

Let's now use these two lemmas to prove our claim. To reiterate, we want to prove that $D_r^{(k)} \leq 2k/2\sqrt{N}$. Let's first use the definition of $D_r^{(k)}$:

{
\[\lVert \ket{\psi_r^{(j)}} - \ket{\phi^{(j)}} \rVert = D^{(j)}_r\]
}

Then, by consecutive applications of Lemma 1 we get:

{
\[ \leq  D^{(j-1)}_r + E^{(j-1)}_r \leq  D^{(j-2)}_r + E^{(j-2)}_r + E^{(j-1)}_r\]
\[ \leq  ... \leq\]
\[ \leq  D_r^{(0)} + \sum_{j=0}^{k-1}E_r^{(j)}\]
}

But we know that $D_r^{(0)} = 0$ because both circuits have the same initial state. Thus:

{
\[ =\sum_{j=0}^{k-1}E_r^{(j)}\]
}

This should intuitively make sense. Essentially, the difference between the ending states of the two circuits is just the error incurred at each step by not applying $O_f$. Now that we've proved this, let's sum over all the elements in our space, of which we're trying to find $r$, and then apply Lemma 2.

{
\[\sum_{r\in\{0,1\}^n}D_r^{(k)} \leq \sum_r \sum_{j=0}^{k-1}E_r^{(j)}\]
}

We know this above statement is true because we literally just proved it. Then, re-ordering the sums and using Lemma 2:

{
\[= \sum_{j=0}^{k-1}\sum_r E_r^{(j)} \leq \sum_{j=0}^{k-1}\sum_r 2\abs{\alpha_r^{(j)}}\]
}

We now must find a clever way to rewrite $\sum_{r\in\{0,1\}^n}\abs{\alpha_r^{(j)}}$. Luckily, we know that $\sum_{r\in\{0,1\}^n}\abs{\alpha_r^{(j)}}^2 = 1$ because our vectors must be normalized. So, we essentially need to come up with a mathematical fact that says if we have

{
\[a_1^2 +a_2^2 + ... + a_N^2 = 1\ \text{ then }\]
\[a_1 +a_2 + ... + a_N \leq \text{ ? } = \sqrt{N}\]
}

Luckily, there exists such a fact. It takes advantage of the Cauchy-Schwarz inequality, which is:

{
\[\abs{\bra{u}\ket{v}} \leq \lVert u \rVert * \lVert v \rVert\]
}

Where $\bra{.}\ket{.}$ represents the inner product of our metric. In our case, we can use this in the following manner:

{
\[\abs{\bra{1}\ket{\alpha_x^{(j)}}} \leq \sqrt{ \sum_{x\in\{0,1\}^n}1^2  } = \sqrt{N}\]
}

We're now essentially finished. We can thus do the following rewrite:

{
\[D_r^{(k)} \leq \sum_{j=0}^{k-1}\sum_{r\in\{0,1\}^n} 2\abs{\alpha_r^{(j)}} \leq \sum_{j=0}^{k-1} 2\sqrt{N} = 2k\sqrt{N} \]
}

However, there's only 1 element $r$ out of $N$ that is marked. So, on average, the difference between the ending states of the two circuits is:

{
\[\lVert \ket{\psi_r^{(k)}} - \ket{\phi^{(k)}} \rVert = D^{(k)}_r \leq 2k\sqrt{N}/N = 2k/\sqrt{N}\]
}

This concludes our proof as this is just what we wanted to show.

\end{document}


\title{Untitled document}
\author{
    Alex Tsui
}
\date{\today}

%\documentclass[12pt]{report}
%\documentclass[12pt]{article}
\documentclass[tikz,border=10pt]{standalone}
%\usepackage{tikz}
\usetikzlibrary{quotes,angles}
%\usepackage{amsmath}
%\usepackage{amsthm}
%\usepackage{amssymb}
%\usepackage{hyperref}
%\usepackage{graphicx}
%\usepackage{underscore}
%\usepackage{makeidx}
%\usepackage{ulem}
%\usepackage{xcolor,listings}
%\usepackage{csquotes}
%\usepackage{hyperref} % this should be last package loaded
%\newcommand{\sgn}{\operatorname{sgn}}
%\lstloadlanguages{[LaTeX]TeX, [primitive]TeX,fortran}
%\lstset{language={[LaTeX]TeX},
%      escapeinside={{(*@}{@*)}},
%       gobble=0,
%       stepnumber=1,numbersep=5pt,
%       numberstyle={\footnotesize\color{gray}},%firstnumber=last,
%      breaklines=true,
%      framesep=5pt,
%      basicstyle=\small\ttfamily,
%      showstringspaces=false,
%      keywordstyle=\ttfamily\textcolor{blue},
%      stringstyle=\color{orange},
%      commentstyle=\color{black},
%      rulecolor=\color{gray!10},
%      breakatwhitespace=false,
%      showspaces=false,  % shows spacing symbol
%      backgroundcolor=\color{gray!15}}
%\SetBlockEnvironment{quotation}
%\makeindex
%
%\begin{document}
%\maketitle
%
%\section{Section}
%Hello world!
%
%\end{document}
%This is never printed
%\documentclass[tikz,border=10pt]{standalone}
%\usetikzlibrary{quotes,angles}
\begin{document}
\begin{tikzpicture}
  \draw
    (3,-1) coordinate (a) node[right] {a}
    -- (0,0) coordinate (b) node[left] {b}
    -- (2,2) coordinate (c) node[above right] {c}
    pic["$\alpha$", draw=orange, <->, angle eccentricity=1.2, angle radius=1cm]
    {angle=a--b--c};
\end{tikzpicture}
\end{document}


%%=======================================
%% Section 1.05: Singularity near $x = 0$
%%=======================================
\documentclass[../dissertation.tex]{subfiles}
\def\rest{\text{rest}}

\begin{document}

\section{Green's Function Singularity near $x=0$} \label{sec1:KSingularity}
As we continue our analysis of $K^+$, recall that our ultimate goal for this
section is to finish the proof of Theorem \ref{thm1:krep}. To determine the
properties of $G_\star^+$ ($\star = L \text{, or }R$) near $x$, it suffices
to analyze the integrability of $K^+$ for small $|x|$. The discussion that
follows within this section is based on the unpublished notes of Prof.
Allen Wu.

We take without
loss of generality $0 < x < 1$ and consider the integral
\[
	K_\zeta(x)
		:= \int_{\mathbb R}
				\frac{e^{ix \xi}}{\xi - \zeta\left(1-e^{-2\xi}\right)+i\pi}
			\, \mathrm{d}\xi
\]
\label{sym1:Kzeta}for the three cases $0< \zeta < \zeta_0$, $\zeta_0 \leq  \zeta \leq \zeta_1$ and
$\zeta > \zeta_1$, where $\zeta_0> 1$ is chosen sufficiently small, and
$\zeta_1 \gg 1$ is chosen sufficiently large. In each of these three cases, we perform
a dyadic decomposition on $K_\zeta(x)$ so that
\begin{align}
	K_\zeta(x) = \sum_q K_q(x),
\end{align}
where
\[
	K_q(x)
		:= \int_{\mathbb R}
				\frac{e^{ix\xi} \chi\left( 2^{-q} x \xi\right)}
					{\xi - \zeta\left(1-e^{-2\xi}\right)+i\pi}
			\, \mathrm{d}\xi.
\]
\label{sym1:Kq}and $\chi$ is an even, smooth function with compact support near $|\xi| =1$ so that
$\displaystyle \sum_q \chi(2^{-q} \xi) = 1$ for $\xi \ne 0$.

The main result of our analyses is summarized in Theorem \ref{thm:1.04-smallx}. Though,
the three major cases in the proof of Theorem \ref{thm:1.04-smallx} are shown in the
proofs of Lemmas \ref{lma:1.04-smallz} through \ref{lma:1.04-largez}.

\begin{thm}%[Main summarizing result]
	\label{thm:1.04-smallx}
	Suppose $|x| < 1$. Then
	\begin{align} \label{eq:1.04-Kbnd}
		\left| K_\zeta(x) \right| \leq C + C \big|\log |x| \big|
	\end{align}
	for all $\zeta > 0$.
\end{thm}
\begin{proof}
	Since analogous results to Lemmas \ref{lma:1.04-smallz} through \ref{lma:1.04-medz}
	also hold for $-1< x < 0$, Theorem \ref{thm:1.04-smallx} is an immediate consequence
	of these three lemmas.
\end{proof}

\begin{lma}%[Small $\zeta$ result]
	\label{lma:1.04-smallz}
	For $\zeta_0 := \zeta(\lambda_0)$ and $\lambda_0$ chosen sufficiently small that
	\[
		1 - \frac{\lambda}{\lambda+1}\frac{e^{-2}e^{-2\lambda}-1}{e^{-2\lambda}-1}
			> \frac{1}{2}
	\]
	and
	\[
		1 - \frac{\lambda}{\lambda - 1} \frac{e^2 e^{-2\lambda} -1}{e^{-2\lambda}-1}
			<-1
	\]
	whenever $\lambda < \lambda_0$, the bound \eqref{eq:1.04-Kbnd} holds
	for all $0 < \zeta < \zeta_0$ and $0 < x < 1$.
\end{lma}
\begin{proof}
	Notice that $\chi\left( 2^{-q} x \xi\right)$ is non-zero only for
	$\left|2^{-q} x \xi\right| \approx 1$. Thus, for $2^{-q} x \xi \in \supp \chi$,
	$|\xi| \approx 2^{q}/x$. For a given $\zeta = \zeta(\lambda)$ and $x$, there are at most
	five values of $q$ for which
	\[
		\frac{1}{2} < \frac{|\xi|}{|\lambda|} < 2
		\qquad \text{and} \qquad |\xi| \approx \frac{2^{q}}{x}
	\]
	We first estimate $K_q$ for these values of $q$ as follows.

	Observe that $\displaystyle \frac{1-e^{-2\xi}}{\xi}$ is a positive, decreasing function.
	If $\xi > \lambda +1$, then
	\[
		\frac{\xi - \zeta\left(1-e^{-2\xi}\right)}{\xi}
			= 1 - \frac{\lambda}{\xi} \frac{1 - e^{-2\xi}}{1- e^{-2\lambda}}
			> 1 - \frac{\lambda}{\lambda+1}\frac{e^{-2}e^{-2\lambda}-1}{e^{-2\lambda}-1}
			> \frac{1}{2}.
	\]
	It follows that
	\begin{align} \label{eq:1.04-smallz-1}
		\left| \xi - \zeta\left(1 - e^{-2\xi}\right) \right| > \frac{1}{2}|\xi|
	\end{align}
	when $\xi > \lambda +1$.

	On the other hand, if $\xi < \lambda -1$,
	\begin{align} \label{eq:1.04-smallz-2}
		\frac{\xi - \zeta\left(1-e^{-2\xi}\right)}{\xi}
			= 1 - \frac{\lambda}{\xi} \frac{1 - e^{-2\xi}}{1- e^{-2\lambda}}
			< 1 - \frac{\lambda}{\lambda - 1} \frac{e^2 e^{-2\lambda} -1}{e^{-2\lambda}-1}
			<-1.
	\end{align}

	Thus, it follows from \eqref{eq:1.04-smallz-1} and \eqref{eq:1.04-smallz-2} that
	\[
		\left| \xi - \zeta\left(1 - e^{-2\xi}\right) \right| > \frac{1}{2}|\xi|
	\]
	when $|\xi - \lambda| > 1$. Thus
	\begin{align}
		\left| K_q(x) \right|
			\leq C + C
				\int_{|\xi - \lambda| > 1}
					\frac{\chi(2^{-q} x \xi)}{|\xi| + \pi}
				\, \mathrm{d}\xi
			\leq C + C
				\int_{\mathbb R}
					\frac{\chi(2^{-q} x \xi)}{|\xi| + \pi}
				\, \mathrm{d}\xi
			\leq C.
	\end{align}

	For the remainder of this proof, we assume $\displaystyle |\xi| < \frac{1}{2} |\lambda|$,
	or $|\xi| > 2 |\lambda|$. In particular, we have $|\xi - \lambda| > 1$ and
	$\displaystyle \left|\xi - \zeta\left(1 - e^{-2\xi}\right)\right| > \frac{1}{2}|\xi|$.

	Next, we focus all all those $q$'s satisfying $2^{q} \lesssim x$. For such $q$'s,
	\begin{align}
		\left| K_q(x) \right|
			\leq \int_{\mathbb R} \frac{\chi\left(2^{-q} x \xi\right)}{\pi} \, \mathrm{d}\xi
			\leq C 2^q x.
	\end{align}
	The sum of these terms are bounded by
	\[
		\sum_{2^q \leq x} C 2^q / x \leq C.
	\]

	We now focus on all those $q$'s satisfying $x \lesssim 2^q \lesssim 1$. For such $q$'s,
	\begin{align}
		\left| K_q(x) \right|
			\leq C \int_{\mathbb R} \frac{\chi\left(2^{-q} x \xi\right)}{|\xi|} \, \mathrm{d}\xi
			\leq C.
	\end{align}
	The sum of these terms gives
	\begin{align}
		C \sum_{x \lesssim 2^q \lesssim 1} 1
			\leq C |\log x|.
	\end{align}

	Lastly, we consider the $K_q$ terms for which $q \gtrsim 1$. For these values of $q$,
	we integrate by parts and ignore a factor of $i$ to get
	\begin{align*}
		K_q(x)
			&= K_{1q}(x) + K_{2q}(x) \\
			&= 2^{-q}
				\int_{\mathbb R}
					\frac{e^{i x \xi}}{\xi - \zeta(1 - e^{-2\xi}) + i\pi} \chi'(2^{-q}x\xi)
				\, \mathrm{d}\xi \\
			&\quad +
				\int_{\mathbb R}
					\frac{1}{x} e^{ix\xi} \chi\left(2^{-q} x \xi\right)
						\left[ \frac{1}{\xi - \zeta(1 - e^{-2\xi}) + i\pi} \right]'
					\, \mathrm{d}\xi.
	\end{align*}
	Observe that
	\begin{align}\label{eq:1.04-smallz-7}
		|K_{1q}(x)|
			\leq C 2^{-q} \int_{\mathbb R} \frac{|\chi'(2^{-q}x\xi)|}{|\xi|} \, \mathrm{d}\xi
			\leq 2 2^{-q}.
	\end{align}

	We can compute $K_{2p}$ and write it as
	\begin{align}\label{eq:1.04-smallz-8}
		2^{-q}
		\int_{\mathbb R}
			\chi\left( 2^{-q} x \xi \right)
			\frac{1}{\left[\xi - \zeta\left(1-e^{-2\xi}\right) + i \pi \right]^2}
			\frac{1}{x}
		\, \mathrm{d}\xi
	\end{align}
	Using the condition $2^{-q} x |\xi| \approx 1$ whenever $2^{-q} x \xi \in \supp \chi$,
	we bound \eqref{eq:1.04-smallz-8} by
	\begin{align}\label{eq:1.04-smallz-9}
		2^{-q}
		\int_{\mathbb R} \chi\left( 2^{-q} x \xi \right)
			\left|
				\frac{\xi(1 - 2 \zeta e^{-2\xi})} {\left[\xi - \zeta\left(1-e^{-2\xi}\right) + i \pi \right]^2}
			\right|
		\, \mathrm{d}\xi
	\end{align}
	Let us first assume $\displaystyle |\xi| < \frac{1}{2}|\lambda|$. In this case, we obviously have
	$|\xi - \lambda| > 1$ and
	$\displaystyle \left| \xi - \zeta\left(1-e^{-2\xi}\right) \right| \geq \frac{1}{2}$.
	Furthermore, we claim that $\left|\zeta e^{-2\xi}\right| \leq C$. In fact, for
	$s = \xi - \lambda/2 > 0$, we have
	\begin{align*}
		\left| \zeta e^{-2\xi} \right|
			&\leq C + \left| \zeta\left(1 - e^{-2\xi}\right) \right|
			&\leq C
				\left|
					\frac{\lambda}
						{1-e^{-2\lambda}}\left(1 - e^{-2(\lambda/2+s}\right)
				\right|
			&\leq C + C\left|\lambda e^{\lambda} e^{-2s}\right|
			\leq C.
	\end{align*}

	Since $\lambda < \lambda_0$ is sufficiently negative, \eqref{eq:1.04-smallz-9}
	is bounded by
	\begin{align}\label{eq:1.04-smallz-10}
		C 2^{-q}
		\int_{\mathbb R}
			\chi\left(2^{-q} x \xi\right) \left|\frac{\xi}{\xi^2}\right|
		\,d\xi
		\leq 2^{-q}.
	\end{align}

	Finally, we assume $|\xi| > 2 |\lambda|$. The part of $\xi$ that is positive is obviously
	bounded by $C2^{-q}$. We focus on the part of $\xi$ such that $\xi < 2 \lambda$. Since for
	this part $\xi - \lambda < -1$, with the similar estimates above, we claim that
	\begin{align}
		-\zeta (1 - e^{-2\xi}) > -2 \xi.
	\end{align}
	We further claim that
	\begin{align*}
		\left| \frac{\xi}{\zeta(1-e^{-2\xi})} \right|
			\leq \frac{C}{|\xi|}.
	\end{align*}
	In fact, for $s = 2 \lambda - \xi > 0$, we have
	\begin{align*}
		\left| \frac{\xi}{\zeta(1-e^{-2\xi})} \right|
			&\leq \left|
					\frac{1-e^{-2\lambda}}{\lambda}
					\frac{(2\lambda-s)^2}{1 - e^{-2(2\lambda-s)}}
				\right| \\
			&\leq C \left|
					e^{2\lambda} e^{-2s} \left( 4\lambda - 4s + \frac{s^2}{\lambda} \right)
				\right| \\
			&\leq C.
	\end{align*}
	Again, remembering that $\lambda < \lambda_0$ is sufficiently negative,
	with the estimates
	above we see that \eqref{eq:1.04-smallz-9} is bounded by
	\begin{align*}
		C 2^{-q}
		\int_{\mathbb R}
			\chi\left( 2^{-q} x \xi \right)
			\frac{|\xi\left(1-2\zeta e^{-2\xi}\right)}{\left|\zeta\left(1-e^{-2\xi}\right)\right|^2}
		\, \mathrm{d}\xi
			&\leq C 2^{-q}
				\int_{\mathbb R}
					\chi\left( 2^{-q} x \xi \right) \frac{1}{|\xi|}
				\, \mathrm{d}\xi \\
			&\leq C 2^{-q}.
	\end{align*}
	In summary, we have $|K_q(x)| \leq C 2^{-q}$ for $2^{q} \gtrsim 1$ whose
	the sum gives $\displaystyle \sum_{2^q \gtrsim 1} C 2^{-q}$. Combining
	all the above estimates, we get the desired result.
\end{proof}

\begin{lma}%[Large $\zeta$ result]
	\label{lma:1.04-largez}
	Let $\xi_0 > 1$ be sufficiently large that
	\[
		\frac{1}{2}
			< \frac{1-e^{-2\xi}-2 \xi e^{-2\xi}}{\left(1-e^{-2\xi}\right)^2}
			< 2
	\]
	for $\xi > \xi_0$ and let $\l_1 > \xi_0$. Then, the estimate
	\eqref{eq:1.04-Kbnd} holds for all for all $0 < x < 1$ and
	$\zeta > \zeta_1 := \zeta(\lambda_1)$.
\end{lma}
\begin{proof}
	By the mean value theorem,
	\begin{align}\label{eq:1.04-14}
		\frac{\xi}{1-e^{-2\xi}} - \frac{\lambda}{1-e^{-2\lambda}}
			= \left.
					\frac{1- e^{-2\xi} - 2 \xi e^{-2\xi}}{\big(1-e^{-2\xi}\big)^2}
				\right|_{\xi = \theta}.
	\end{align}
	Here $\theta$ is between $\xi$ and $\lambda$. Let $\chi_{\xi_0+}(\xi)$ be a smooth
	cutoff function that is 1 for $\xi > \xi_0 +1$ and 0 for $\xi \leq \xi_0$, with
	gradient bounded by 2. We write
	\begin{align*}
		K_{\zeta}(x)
			&= K_{1\zeta}(x) + K_{2\zeta}(x) \\
			&:= \int_{\mathbb R}
					\frac{e^{ix\xi}\big(1 - \xi_{\xi_0+}(\xi) \big)}
						{\xi - \zeta\big( 1 - e^{-2\xi} \big) + i\pi}
				\, \mathrm{d}\xi
				+
				\int_{\mathbb R}
					\frac{e^{ix\xi}\big(\xi_{\xi_0+}(\xi)}
						{\xi - \zeta\big( 1 - e^{-2\xi} \big) + i\pi}
				\, \mathrm{d}\xi
	\end{align*}
	Take some $\lambda_1 > \xi_0$ and estimate $K_{1\zeta}$ by
	\begin{align*}
		|K_{1\zeta}(\xi)|
			&\leq C +
				\int_{-\infty}^{-1}
					\frac{1}{\big(e^{-2\xi}-1\big)\left(\zeta-\frac{\xi}{1-e^{-2\xi}}\right)}
				\, \mathrm{d}\xi \\
			&\leq C +
				\frac{1}{\zeta(\lambda_1) - \zeta(-1)}
				\int_{-\infty}^{-1}
					\frac{1}{e^{-2\xi}-1}
				\, \mathrm{d}\xi.
	\end{align*}
	To estimate $K_{2\zeta}$, we take a dyadic decomposition
	\begin{align*}
		K_{1\zeta}(\xi)
			= \sum_q K_q(x)
			= \sum_q
				\int_{\mathbb R}
					\frac{e^{ix\xi}\chi_{\xi_0+}(\xi)}
						{\xi -\zeta\big(1-e^{-2\xi}\big)+i\pi}
					\chi\big(e^{-q} x (\xi - \lambda)\big)
				\, \mathrm{d}\xi.
	\end{align*}
	for $2^q \gtrsim x$, $|K_q(x)| \leq C2^q/x$. These terms sum to $C$. For
	$x \lesssim 2^q \lesssim 1$, we notice that since $\xi, \lambda \geq \xi_0$,
	\begin{align*}
		\left| \xi - \zeta\big(1-e^{-2\xi}\big) \right|
			=
				\left|
					\big(1-e^{-2\xi}\big)
					\left(
						\frac{\xi}{1-e^{-2\xi}} - \frac{\lambda}{1-e^{-2\lambda}}
					\right)
				\right|
			\approx \big|\xi-\lambda\big|.
	\end{align*}
	Thus
	\begin{align*}
		|K_q(x)|
			\leq C\int_{\mathbb R}
					\frac{1}{|\xi - \lambda|}
					\chi\big(2^{-q} x(\xi - \lambda)\big)
				\, \mathrm{d}\xi
			\leq C,
	\end{align*}
	which implies
	\[
		\sum_{x \lesssim 2^q \lesssim 1} |K_q(x)| \leq C |\log x|.
	\]
	For $2^q \gtrsim 1$, we integrate $K_p$ by parts to obtain
	\begin{align}
		&\int_{\mathbb R}
			e^{ix\xi}
			\frac{\chi\big(2^{-q} x( \xi - \lambda) \big)}
				{\xi-\zeta\big(1-e^{-2\xi}\big)+i \pi}
			\frac{\chi_{\xi_0+}(\xi)'}{x} \, \mathrm{d}\xi
		\,d\xi \label{eq: Gp part 1}\\
		&\quad + 2^{-q}
			\int_{\mathbb R}
				\frac{e^{ix\xi}\chi_{\xi_0+}}
					{\xi-\zeta\big(1-e^{-2\xi}\big)+i \pi}
				\frac{\chi_{\xi_0+}'(\xi)}{x} \, \mathrm{d}\xi
				\chi'\big( 2^{-q} x(\xi - \lambda) \big)
			\, \mathrm{d}\xi \label{eq: Gp part 2} \\
		&\quad - \int_{\mathbb R}
				e^{ix\xi} \chi_{\xi_0+}(\xi)
				\frac{1-2\zeta e^{-2\xi}}
					{\big(\xi-\zeta\big(1-e^{-2\xi}\big)+i\pi\big)^2}
				\frac{\chi\big(2^{-q} x(\xi - \lambda))} {x}
			\, \mathrm{d}\xi \label{eq: Gp part 3}
	\end{align}

	Noticing the condition $\frac1x\approx 2^{-q}|\xi-\lambda|$, \eqref{eq: Gp part 1}
	is bounded by
	\begin{align*}
		C2^{-q}
		\int_{\mathbb R}
			\frac{|\xi-\lambda|}{|\xi-\lambda|}|\chi'_{\xi_0+}(\xi)|
		\,d\xi
		\le C2^{-q}.
	\end{align*}
	\eqref{eq: Gp part 2} is bounded by
	\begin{align*}
		C2^{-q}
		\int_{\mathbb R}
			\frac{|\chi'(2^{-q}x(\xi-\lambda))|}{|\xi-\lambda|}
		\, \mathrm{d}\xi
		\le C2^{-q}.
	\end{align*}
	\eqref{eq: Gp part 3} is bounded by
	\begin{align}
		&C2^{-q}
			\int_{\mathbb R}
				\chi_{\xi_0+}(\xi)
				\frac{|1-2\zeta e^{-2\xi}|}{|\xi-\lambda|}\chi(2^{-q}x(\xi-\lambda))
			\, \mathrm{d}\xi
			\notag\\
	 	&\qquad\le C2^{-q}
	 		\int_{\mathbb R}
	 			\frac{\chi(2^{-q}x(\xi-\lambda))}{|\xi-\lambda|}
	 		\, \mathrm{d}\xi
	 		+ C2^{-q}
	 		\int_0^\infty
	 			\frac{\lambda e^{-2\lambda} e^{-2(\xi-\lambda)}}
	 				{|\xi-\lambda|}
	 			\chi(2^{-q}x(\xi-\lambda))
	 		\, \mathrm{d}\xi
	 		\notag\\
		&\qquad\le
			C2^{-q}
			+C2^{-q} \lambda e^{-2\lambda}
			\int_{-2^{-q}x\lambda}^\infty
				\frac{e^{-\xi 2^{q+1}/x}}{|\xi|}\chi(\xi)
			\, \mathrm{d}\xi
			\notag\\
		&\qquad\le
			C2^{-q}
			+C2^{-q}\lambda e^{-2\lambda}
			\int_{-2^{-q}x\lambda}^0\
				\frac{e^{-\xi 2^{q+1}/x}}{|\xi|}\chi(\xi)
			\, \mathrm{d}\xi
			\label{eq: Gp 4}
	\end{align}
	Let's say $\chi$ is supported between $\frac12$ and $2$, then the integral in
	\eqref{eq: Gp 4} is nonzero only when $2^{-q}x\lambda \ge \frac12$. If
	$\frac12\le 2^{-q}x\lambda\le 2$, the integral in \eqref{eq: Gp 4} is bounded by
	\begin{align*}
		C
		\int_{-2^{-q}x\lambda}^0
			e^{-\xi 2^{q+1}/x}\,
		d\xi
		\le
		C2^{-(q+1)}xe^{2\lambda}.
	\end{align*}
	Thus \eqref{eq: Gp 4} is bounded by
	\begin{align*}
		C2^{-q}+C2^{-q}\lambda 2^{-(q+1)}x\le C2^{-q}.
	\end{align*}
	If $2^{-q}x\lambda \ge 2$, the integral in \eqref{eq: Gp 4} is bounded by
	\begin{align*}
		C\int_{-2}^0 e^{-\xi 2^{q+1}/x}~d\xi\le C2^{-(q+1)}x e^{2\dotarg 2^{q+1}/x}.
	\end{align*}
	Thus \eqref{eq: Gp 4} is bounded by
	\begin{align*}
		C2^{-q}
		+C2^{-q}
			\frac{\lambda e^{-2\lambda}}
				{(2^{q+1}/x)e^{-2\dotarg 2^{q+1}/x}}
		\le C2^{-q}.
	\end{align*}
	The last step above follows from the condition $2^{q+1}/x\le \lambda$, and the fact
	that $\lambda e^{-2\lambda}$ is decreasing for $\lambda>\frac12$.

	Therefore, the sum $\displaystyle \sum_{2^q\gtrsim 1}|K_q(x)|\le C$. As a consequence,
	\[
		\left|K_\zeta(x)\right|
			\le C+C|\log x|
	\]
	for all $\zeta>\zeta_1$, and $0<x<1$.
\end{proof}

\begin{lma}%[Medium $\zeta$ result]
	\label{lma:1.04-medz}
	Inequality \eqref{eq:1.04-Kbnd} holds for every $\zeta$ between
	$\zeta_0$ and $\zeta_1$, where $\zeta_0$ and $\zeta_1$ are as respectively
	defined in the statements of Lemmas \ref{lma:1.04-smallz} and \ref{lma:1.04-largez}.
\end{lma}
\begin{proof}
	Now that we have the uniform estimates on $G_\zeta$ for
	$\zeta < \zeta_0 = \zeta(\lambda_0)$ and $\zeta > \zeta_1 = \zeta(\lambda_1)$,
	we can fill the gap $\zeta_0 < \zeta < \zeta_1$. We take the dyadic sum
	\begin{align}
		\sum_q K_q(x)
			= \sum_q
				\int_{\mathbb R}
					\frac{
						e^{ix\xi}\chi\left(2^{-q}x\xi\right)
						\big(1-\chi_{\lambda_0 \lambda_1}(\xi)\big)
					}
					{\xi - \zeta\left(1-e^{-2\xi}\right) + i \pi}
				\, \mathrm{d}\xi.
	\end{align}
	Notice we have cut off a piece from $\lambda_0-1$ to $2\zeta_1$ by the
	cutoff function
	$\chi_{\lambda_0\lambda_1}(\xi)$. Of course, the piece that's cut off is uniformly
	bounded. Observe that for $\xi<\lambda_0-1$ and $\zeta>\zeta_0$,
	\begin{align*}
		\left|\xi-\zeta\left(1-e^{-2\xi}\right)\right|
			= \left|\left(1-e^{-2\xi}\right)\big(\zeta(\xi)-\zeta\big)\right|
			\ge Ce^{-2\xi},
	\end{align*}
	while for $\xi>2\zeta_1$ and $\zeta<\zeta_1$,
	\begin{align*}
		\big|\xi-\zeta\big(1-e^{-2\xi}\big)\big|
			\approx |\xi|, \quad 2\zeta e^{-2\xi}<\frac12.
	\end{align*}
	A similar argument as above gives the uniform estimates.
\end{proof}

\end{document}