\chapter{Number theory}
\label{chap:Number theory}

In this chapter, you will learn about the
number theoretic functions in libzahl.

\vspace{1cm}
\minitoc

\newpage
\section{Odd or even}
\label{sec:Odd or even}

There are four functions available for testing
the oddness and evenness of an integer:

\begin{alltt}
   int zodd(z_t a);
   int zeven(z_t a);
   int zodd_nonzero(z_t a);
   int zeven_nonzero(z_t a);
\end{alltt}

\noindent
{\tt zodd} returns 1 if {\tt a} contains an
odd value, or 0 if {\tt a} contains an even
number. Conversely, {\tt zeven} returns 1 if
{\tt a} contains an even value, or 0 if {\tt a}
contains an odd number. {\tt zodd\_nonzero} and
{\tt zeven\_nonzero} behave exactly like {\tt zodd}
and {\tt zeven}, respectively, but assumes that
{\tt a} contains a non-zero value, if not
undefined behaviour is invoked, possibly in the
form of a segmentation fault; they are thus
sligtly faster than {\tt zodd} and {\tt zeven}.

It is discouraged to test the returned value
against 1, we should always test against 0,
treating all non-zero value as equivalent to 1.
For clarity, we use also avoid testing that
the returned value is zero, for example, rather
than {\tt !zeven(a)} we write {\tt zodd(a)}.

\newpage
\section{Signum}
\label{sec:Signum}

There are two functions available for testing
the sign of an integer, one of the can be used
to retrieve the sign:

\begin{alltt}
   int zsignum(z_t a);
   int zzero(z_t a);
\end{alltt}

\noindent
{\tt zsignum} returns $-1$ if $a < 0$,
$0$ if $a = 0$, and $+1$ if $a > 0$, that is,

\vspace{1em}
\( \displaystyle{
    \mbox{sgn}~a = \left \lbrace \begin{array}{rl}
        -1 & \textrm{if}~ a < 0 \\
         0 & \textrm{if}~ a = 0 \\
        +1 & \textrm{if}~ a > 0
    \end{array} \right .
}\)
\vspace{1em}

\noindent
It is discouraged to compare the returned value
against $-1$ and $+1$; always compare against 0,
for example:

\begin{alltt}
   if (zsignum(a) >  0)  "positive";
   if (zsignum(a) >= 0)  "non-negative";
   if (zsignum(a) == 0)  "zero";
   if (!zsignum(a))      "zero";
   if (zsignum(a) <= 0)  "non-positive";
   if (zsignum(a) <  0)  "negative";
   if (zsignum(a))       "non-zero";
\end{alltt}

\noindent
However, when we are doing arithmetic with the
signum, we may relay on the result never being
any other value than $-1$, $0$, and $+0$.
For example:

\begin{alltt}
   zset(sgn, zsignum(a));
   zadd(b, sgn);
\end{alltt}

{\tt zzero} returns 0 if $a = 0$ or 1 if
$a \neq 0$. Like with {\tt zsignum}, avoid
testing the returned value against 1, rather
test that the returned value is not 0. When
however we are doing arithmetic with the
result, we may relay on the result never
being any other value than 0 or 1.

\newpage
\section{Greatest common divisor}
\label{sec:Greatest common divisor}

There is no single agreed upon definition
for the greatest common divisor of two
integer, that cover non-positive integers.
In libzahl we define it as

\vspace{1em}
\( \displaystyle{
    \gcd(a, b) = \left \lbrace \begin{array}{rl}
        -k & \textrm{if}~ a < 0, b < 0 \\
        b  & \textrm{if}~ a = 0 \\
        a  & \textrm{if}~ b = 0 \\
        k  & \textrm{otherwise}
    \end{array} \right .
}\),
\vspace{1em}

\noindent
where $k$ is the largest integer that divides
both $\lvert a \rvert$ and $\lvert b \rvert$. This
definion ensures

\vspace{1em}
\( \displaystyle{
    \frac{a}{\gcd(a, b)} \left \lbrace \begin{array}{rl}
        > 0 & \textrm{if}~ a < 0, b < 0 \\
        < 0 & \textrm{if}~ a < 0, b > 0 \\
        = 1 & \textrm{if}~ b = 0, a \neq 0 \\
        = 0 & \textrm{if}~ a = 0, b \neq 0 \\
        \in \textbf{N} & \textrm{otherwise if}~ a \neq 0, b \neq 0
    \end{array} \right .
}\),
\vspace{1em}

\noindent
and analogously for $\frac{b}{\gcd(a,\,b)}$. Note however,
the convension $\gcd(0, 0) = 0$ is adhered. Therefore,
before dividing with $\gcd(a, b)$ you may want to check
whether $\gcd(a, b) = 0$. $\gcd(a, b)$ is calculated
with {\tt zgcd(a, b)}.

{\tt zgcd} calculates the greatest common divisor using
the Binary GCD algorithm.

\vspace{1em}
\hspace{-2.8ex}
\begin{minipage}{\linewidth}
\begin{algorithmic}
    \RETURN $a + b$ {\bf if} $ab = 0$
    \RETURN $-\gcd(\lvert a \rvert, \lvert b \rvert)$ {\bf if} $a < 0$ \AND $b < 0$
    \STATE $s \gets \max s : 2^s \vert a, b$
    \STATE $u, v \gets \lvert a \rvert \div 2^s, \lvert b \rvert \div 2^s$
    \WHILE{$u \neq v$}
        \STATE $v \leftrightarrow u$ {\bf if} $v < u$
        \STATE $v \gets v - u$
        \STATE $v \gets v \div 2^x$, where $x = \max x : 2^x \vert v$
    \ENDWHILE
    \RETURN $u \cdot 2^s$
\end{algorithmic}
\end{minipage}
\vspace{1em}

\noindent
$\max x : 2^x \vert z$ is returned by {\tt zlsb(z)}
\psecref{sec:Boundary}.

\newpage
\section{Primality test}
\label{sec:Primality test}

The primality of an integer can be tested with

\begin{alltt}
   enum zprimality zptest(z_t w, z_t a, int t);
\end{alltt}

\noindent
{\tt zptest} uses Miller–Rabin primality test,
with {\tt t} runs of its witness loop, to
determine whether {\tt a} is prime. {\tt zptest}
returns either

\begin{itemize}
\item {\tt PRIME} = 2:
{\tt a} is prime. This is only returned for
known prime numbers: 2 and 3.

\item {\tt PROBABLY\_PRIME} = 1:
{\tt a} is probably a prime. The certainty
will be $1 - 4^{-t}$.

\item {\tt NONPRIME} = 0:
{\tt a} is either composite, non-positive, or 1.
It is certain that {\tt a} is not prime.
\end{itemize}

If and only if {\tt NONPRIME} is returned, a
value will be assigned to {\tt w} — unless
{\tt w} is {\tt NULL}. This will be the witness
of {\tt a}'s completeness. If $a \le 1$, it
is not really composite, and the value of
{\tt a} is copied into {\tt w}.

$\gcd(w, a)$ can be used to extract a factor
of $a$. This factor is however not necessarily,
and unlikely so, prime, but can be composite,
or even 1. In the latter case this becomes
utterly useless. Therefore using this method
for prime factorisation is a bad idea.

Below is pseudocode for the Miller–Rabin primality
test with witness return.

\vspace{1em}
\hspace{-2.8ex}
\begin{minipage}{\linewidth}
\begin{algorithmic}
    \RETURN NONPRIME ($w \gets a$) {\bf if} {$a \le 1$}
    \RETURN PRIME {\bf if} {$a \le 3$}
    \RETURN NONPRIME ($w \gets 2$) {\bf if} {$2 \vert a$}
    \STATE $r \gets \max r : 2^r \vert (a - 1)$
    \STATE $d \gets (a - 1) \div 2^r$
    \STATE {\bf repeat} $t$ {\bf times}

    \hspace{2ex}
    \begin{minipage}{\linewidth}
        \STATE $k \xleftarrow{\$} \textbf{Z}_{a - 2} \setminus \textbf{Z}_{2}$ \textcolor{c}{\{Uniformly random assignment.\}}
        \STATE $x \gets k^d \mod a$
        \STATE {\bf continue} {\bf if} $x = 1$ \OR $x = a - 1$
        \STATE {\bf repeat} $r$ {\bf times or until} $x = 1$ \OR $x = a - 1$

        \hspace{2ex}
        \begin{minipage}{\linewidth}
            \vspace{-1ex}
            \STATE $x \gets x^2 \mod a$
        \end{minipage}
        \vspace{-1.5em}
        \STATE {\bf end repeat}
        \STATE {\bf if} $x = 1$ {\bf return} NONPRIME ($w \gets k$)
    \end{minipage}
    \vspace{-0.8ex}
    \STATE {\bf end repeat}
    \RETURN PROBABLY PRIME
\end{algorithmic}
\end{minipage}
\vspace{1em}

\noindent
$\max x : 2^x \vert z$ is returned by {\tt zlsb(z)}
\psecref{sec:Boundary}.


\section{Parallelism}
Speedup:
$$S(n) = \frac{T(1)}{T(n)}$$
Ahmdahl's law:
$$ S(n) = \frac{1}{(1 - p)+\frac{p}{n}}$$
wobei $p$ der parallelisierbare Anteil ist (in \%)
\subsection{Deadlocks}
\paragraph{Coffman conditions}
\begin{enumerate}
	\item Mutual Exclusion
	\item Hold and wait
	\item No preemption
	\item Circular wait
\end{enumerate}
All of these conditions must apply for a deadlock to be possible
\subsection{Livelocks}
Threads switching but not making any progress
\subsection{Starvation}
Occurs if a thread cannot aquire any resources even if no deadlocks exist

\subsection{Flynn's taxonomy}

\begin{enumerate}
	\item SISD: Single instruction x single data
	\item SIMD: Single instruction x multiple data
	\item MIMD: Multiple instruction x multiple data
	\item MISD: Multiple instruction x multiple data
\end{enumerate}

\includegraphics[width=\columnwidth]{images/flynn.png}


% Copyright 2018 Melvin Eloy Irizarry-Gelpí
\chapter{ABW Octonion}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
An ABW octonion has the form
\begin{equation}
    a_{0} + a_{1} A + a_{2} B + a_{3} AB + a_{4} W + a_{5} AW + a_{6} BW + a_{7} ABW
\end{equation}
These follow from a parabolic Cayley-Dickson construct on the AB quaternions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Arithmetic Operations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Multiplication}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Conjugate Operations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Asterisk Conjugation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Quadrance}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Cloak Conjugation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Dagger Conjugation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Hodge Star}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Zero-Divisors}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Differential Operators}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...


% !TeX root = ../thuthesis-example.tex

\chapter{MATHEMATICAL SYMBOLS AND FORMULA}

\section{Symbols}

As required by the national formatting standards, the template uses \pkg{unicode-math} for formatting mathematical symbols, which differs to the default used by LATEX.

\begin{enumerate}
  \item Capital Greek letters are italic by default e.g. \cs{Delta}：$\Delta$。
  \item Increment symbol: $\increment$（U+2206）
  \item Vectors, matrices, tensors should be ITALIC, and BOLD using the \cs{symbf} command; for example: $\symbf{A}$, $\symbf{\alpha}$.
  \item For constants and special functions, use the \cs{symup} command. For example:
    $\symup{\pi} = 3.14\dots$; $\symup{e} = 2.718\dots$，
  \item Example of integrals and differentials: $\int f(x) \dif x$。
\end{enumerate}

For more usage of symbols, you could use the following references
\href{http://mirrors.ctan.org/macros/latex/contrib/unicode-math/unicode-math.pdf}{\pkg{unicode-math}}
\href{http://mirrors.ctan.org/macros/latex/contrib/unicode-math/unimath-symbols.pdf}{\pkg{unimath-symbols}}.

For units and metrics, it is recommended to use the following package:
\href{http://mirrors.ctan.org/macros/latex/contrib/siunitx/siunitx.pdf}{\pkg{siunitx}}
It can conveniently handle the space between Greek letters/numbers and the unit. For example:
\SI{6.4e6}{m}，
\SI{9}{\micro\meter}，
\si{kg.m.s^{-1}}，
\SIrange{10}{20}{\degreeCelsius}。

\section{Mathematical formula}

You can use the following environments \env{equation} 和 \env{equation*} for mathematical formulae.

Please pay attention that round brackets should be included before and after referencing an equation: e.g. Equation \eqref{eq:example}.

\begin{equation}
  \frac{1}{2 \symup{\pi} \symup{i}} \int_\gamma f = \sum_{k=1}^m n(\gamma; a_k) \mathscr{R}(f; a_k)
  \label{eq:example}
\end{equation}

When there are multiple equations, please try to align them at the "equal" sign if possible. We recommend using the \env{align} environment.
For example:
\begin{align}
  a & = b + c + d + e \\
    & = f + g
\end{align}

\section{Mathematical axioms and proofs}

You can use \pkg{amsthm} or \pkg{ntheorem} packages to set up your axiom. After loading one of those package, the template will automatically setup the environments: \env{theorem} and \env{proof}

An example:
\begin{theorem}[Lindeberg--Lévy Central Limit Theorem]
  Set random variables $X_1, X_2, \dots, X_n$ i.i.d., with expectation mean of $\mu$ and variance $\sigma^2 \ne 0$. By formula, $\bar{X}_n = \frac{1}{n} \sum_{i+1}^n X_i$, we have
  \begin{equation}
    \lim_{n \to \infty} P \left(\frac{\sqrt{n} \left( \bar{X}_n - \mu \right)}{\sigma} \le z \right) = \Phi(z),
  \end{equation}
  where $\Phi(z)$ is the function of a normal distribution.
\end{theorem}
\begin{proof}
  Trivial.
\end{proof}

The template also provides the following environments: \env{assumption}、\env{definition}、\env{proposition}、
\env{lemma}、\env{theorem}、\env{axiom}、\env{corollary}、\env{exercise}、
\env{example}、\env{remar}、\env{problem}、\env{conjecture}


\subsubsection{Single Fungal Species}
It is simple to analyze and predict a single species of fungus, because in this ideal environment, the growth and reproduction process of a single fungus can be accurately represented by the \textbf{Logistic Model}. Substitute data of $F_A\sim F_E$ into the previous differential equation \textit{Eq.~(\ref{12eq})} and get \textit{Eq.~(\ref{14eq})} as follows.
\begin{equation}
  \label{14eq}
  \begin{cases}
    \frac{1}{N_A(t)}\frac{dN_A(t)}{dt} = r_A(1-\frac{N_A(t)}{{N_A}_{max}}) \\ \\
    \frac{1}{N_B(t)}\frac{dN_B(t)}{dt} = r_B(1-\frac{N_B(t)}{{N_B}_{max}}) \\ \\
    \frac{1}{N_C(t)}\frac{dN_C(t)}{dt} = r_C(1-\frac{N_C(t)}{{N_C}_{max}}) \\ \\
    \frac{1}{N_D(t)}\frac{dN_D(t)}{dt} = r_D(1-\frac{N_D(t)}{{N_D}_{max}}) \\ \\
    \frac{1}{N_E(t)}\frac{dN_E(t)}{dt} = r_E(1-\frac{N_E(t)}{{N_E}_{max}}) \\
  \end{cases}
\end{equation}
The function curves of $N_A(t)$, $N_B(t)$, $N_C(t)$, $N_D(t)$, and $N_E(t)$ are as follows.
\par
\begin{figure}[H]
  \centering
  \label{functioncurves}
  \includegraphics[width=\textwidth]{figures/Single.png}
  \caption{Function curves of each single fungus.}
\end{figure}
\par
The fungal data in the above figure are all based on the research and analysis of the environmental climate in \textit{Table~\ref{fivetypicalfungalspecies}}. The temperature, moisture and so on indicated in the table are the most suitable environmental conditions for the five fungi. Looking up the climatic data, it is found that the optimal growth environment of the five fungi corresponds exactly to the five typical climatic characteristics, including arid, semi-arid, temperate, arboreal and tropical rain forests. Therefore, it is obvious that when five species of fungi $F_A\sim F_E$, grow and reproduce under the optimal conditions, they can exert their greatest advantages in decomposing lignin or cellulose. On the contrary, these fungi will be at disadvantages due to excessive environmental blocking.
\begin{table}[H]
  \centering
  \caption{Corresponding optimal environment for the five fungi.}
  \label{correspondingoptimalenvironment}
  \begin{tabular*}{\hsize}{@{\extracolsep{\fill}}cccc}
    \toprule
    & Fungi & Corresponding Environment & \\
    \midrule
    & $F_A$ & Arid & \\
    & $F_B$ & Semi-arid & \\
    & $F_C$ & Temperate & \\
    & $F_D$ & Arboreal & \\
    & $F_E$ & Tropical rain forests & \\
    \bottomrule
  \end{tabular*}
\end{table}
The above table illustrates the corresponding optimal environment when the five fungi live alone, but it is quite different from the real situation in the nature. The following will further analyze the combinations between fungal species.


\documentclass{article}
\usepackage{amsmath}
\usepackage[margin=1.0in]{geometry}
\usepackage{xcolor}

\begin{document}

\noindent
Does $\displaystyle \sum_{n=1}^\infty \frac{1}{n^{3/2}}$
diverge, converge absolutely, or converge conditionally?

\subsection*{Solution}

$\displaystyle \sum_{n=1}^\infty \frac{1}{n^{3/2}}$ is a $p$-series with $p=\frac32$. Since $p>1$, the series $\displaystyle \sum_{n=1}^\infty \frac{1}{n^{3/2}}$ converges by the $p$-series test.

Since $\sum |a_n| = \sum a_n$, the series $\displaystyle \sum_{n=1}^\infty  \frac{1}{n^{3/2}}$ converges absolutely.

\subsection*{Other solution}

You can also use the Integral Test, but when the $p$-test works, why work more?

\end{document}%%%%%%%%%%%%%%%%%

\begin{align*}
L&=\lim_{n \to \infty} \sqrt[n]{|a_n|}\\
&= \lim_{n \to \infty} \sqrt[n]{\left| \right|}\\
\end{align*}

\begin{align*}
L&=\lim_{n \to \infty} \left|\frac{a_{n+1}}{a_n}\right|\\
&= \lim_{n \to \infty} \left| \right|\\
\end{align*}

\begin{align*}
\lim_{n \to \infty} a_n
&= \lim_{n \to \infty} \\
\end{align*}

Since $\sum |a_n| = \sum a_n$, the series $\displaystyle \sum_{n=1}^\infty AAAAAAAAAAAAAA$ converges absolutely.

Since $|r| < 1$, the series ...  converges by the Geometric Series Test.

Since $|r| \geq 1$, the series ...  diverges by the Geometric Series Test.

The function $f(x)=\frac{}{}$ is continuous, positive, and decreasing on $[1,\infty)$.

\subsection*{Solution}


\mychapter{14}{Lesson 14} %181114

\subsubsection{Decisional Diffie-Hellman (cont'd)}

%AP190913: Is p supposed to be prime?
\begin{claim}
    \ddh{} is not hard for groups $\integer_p^\times$
\end{claim}

\begin{proof}
    Let $\quadres_p$ be the group of quadratic residues modulo $p$, where the group operation is multiplication:
    \[
        \quadres(p) = \{y : \exists x \in \integer_p \implies y \equiv_p x^2\} = \{g^z : \forall z\}
    \]
    where $g$ generates $\integer_p^\times$.Then, we can test if a give number $y$ is in $\quadres_p$ by checking if $y^{(p-1)/2} \equiv_p 1$, because:
    \[
        \exists z : y = g^{2z} \implies y^{(p-1)/2} = g^{\frac{2z(p-1)}{2}} = g^{z(p-1)} \equiv_p 1
    \]
    Otherwise: % AP190208: Not sure at all that this is correct
    \[
        \nexists z : y = g^{2z} \implies y^{(p-1)/2} \equiv_p g^{z(p-1)} \cdot g^{(p-1)/2} \not\equiv_p 1
    \]

    Furthermore: $g^{xy} \in \quadres_p \implies x \equiv_2 0 \vee y \equiv_2 0$. With this in mind, given a random choice of $x$ and $y$, the probability that $g^{xy}$ falls in $\quadres(p)$ is $\frac{3}{4}$, and the probability of it being outside the group is $\frac{1}{4}$. This is an advantage available to a polynomial adversary.
\end{proof}

Nevertheless, some other groups are believed to harden quadratic residue membership; examples of such groups are $\quadres_p$ itself for $p = 2q + 1$, where $q$ is prime, or the elliptic curve groups.

\subsubsection{Extended \ddh}

This is a construction that takes the \ddh{} assumption to an extreme using groups. The \ddh{} assumption is reported here:
\[
    (G, g, q) \pickUAR \groupgen(1^\lambda), \forall i\: X_i, Y_i, Z_i \sim \unifdist(G) \implies (g^X, g^Y, g^{XY}) \compindist (g^X, g^Y, g^Z)
\]
where $X$, $Y$ and $Z$ are distribution ensembles.

The construction extends this concept of hardness in detecting $xy$ by replicating it $n$-times:
\begin{theorem}
    Let $X$, $Y_{1\upto n}$ and $Z_{1 \upto n}$ be distribution ensembles over a group $(G, g, q)$ Then:
    \[
        (g^X, g^{Y_1}, g^{XY_1}, \dots, g^{Y_n}, g^{XY_n}) \compindist (g^X, g^{Y_1}, g^{Z_1}, \dots, g^{Y_n}, g^{Z_n})
    \]
\end{theorem}

\begin{proof}
    \todo{The game is modified a bit to ease the analysis of the reduction, must take care...

    Also, this kind of proof is ``tight''; the hybridization would have introduced a negligible difference instead}

    The proof can be structured by progressive hybridization over the sequences, and breaking the \ddh{} assumption at any step $i$. Here instead, we will simulate the \textsc{ext} sequence directly in the distinguishing game, and assume there is $\distinguisher^{\textsc{ext}}$ capable of telling them apart; figure \ref{cryptoredux:extddh} shows the steps to take.

    \begin{cryptoredux}
        {extddh}
        {Breaking \ddh{} by distinguishing the \ddh{} sequence}
        {ddh}
        {ext}

        \cseqdelay
        \receive{\shortstack[l]{
            %AP190913: Actually, the adversary knows this!
            $(G, g, q) \pickUAR \groupgen(1^\lambda)$ \\
            $x, y \pickUAR \integer_q$ \\
            $b \pickUAR \binary$ \\
            $\beta_b \pickUAR \{0, \integer_q\setminus\{0\}\}$ \\
            $z_b = xy + \beta_b$
        }}{$(g^x, g^y, g^{z_b})$}{}

        \cseqbeginloop
        \cseqdelay
        \cseqadversary{\shortstack[r]{
            $u_i, v_i \pickUAR \integer_p$ \\
            $g^{y_i} = (g^y)^{u_j}g^{v_j}$ \\
            $g^{z_i} = (g^z)^{u_j}(g^x)^{v_j}$
        }}
        \cseqdelay
        \cseqendloop
        \cseqdelay

        \invoke{}{$(g^x, g^{y_1}, g^{z_1}, \dots)$}{}

        \return{}{$b'$}{}

        \send{}{$b'$}{\textsc{Output 1 iff} $b' = b$}

    \end{cryptoredux}

\end{proof}

Notice that $(g^y)^{u_j}g^{v_j}= g^{yu_j + v_j}$, and $(g^z)^{u_j}(g^x)^{v_j} = g^{zu_j + xv_j}$, which depending on what $z$ is, becomes either $g^{x(yu_j + v_j)}$, matching perfectly the $y_i$ case, or remains as a random linear combination, matching the $z_i$ case.

\subsubsection{Naor-Reingold \prf}

This is an alternative to the extended \ddh{} seen above, designed by Moni Naor and Omer Reingold. It constructs a \prf{} as follows:
\[
    F^{\textsc{nr}} \in \integer_q^{(n+1)} \times \binary^n \to (G, g, q) : f^{\textsc{nr}}_k(x_{1\upto n}) \mapsto g^{k_0\prod_{i = 1}^{n}k_i^{x_i}}
\]

\todo{Transcribing notes directly:
\{
This is \ggm{} with $G^{g, q, a}(g^b) = G_0(g^b) \mathrel{||} G_1(g^b) = (g^b, g^{ab})$

E.g.: $011 \mapsto g^{a_0a_1^0a_2^1a_3^1}$

\}

Notes about claw-free permutations follow; also, hash functions make an appearance

}

\begin{figure}
    \centering
    \begin{tikzpicture}[
        level 1/.style={sibling distance=16em},
        level 2/.style={sibling distance=8em},
        level 3/.style={sibling distance=4em}]

        \node{$g^{a_0}$}
            child{ node {}
                child { node {}
                    child { node (a) {$g^{a_0}$} node [below of = a] {$\vdots$}}
                    child { node (a) {} node [below of = a] {$\vdots$}}
                }
                child { node {}
                    child { node (a) {} node [below of = a] {$\vdots$}}
                    child { node (a) {} node [below of = a] {$\vdots$}}
                }
            }
            child { node {}
                child { node {}
                    child { node (a) {} node [below of = a] {$\vdots$}}
                    child { node (a) {} node [below of = a] {$\vdots$}}
                }
                child { node {}
                    child { node (a) {} node [below of = a] {$\vdots$}}
                    child { node (a) {$g^{a_0a_1a_2a_3}$} node [below of = a] {$\vdots$}}
                }
            };
    \end{tikzpicture}
    \caption{Depicting Naor-Reingold method as a tree-like structure}
    \label{fig:nrtree}
\end{figure}

\section{Public key encryption schemes}

Now we discuss a substantially different way of encrypting messages, which involves two separate keys per party instead of a single, shared key; hence the names \emph{Public key scheme}, or \pke{}, or \emph{Asymmetric key scheme}.

\subsubsection{\textsc{Cpa}-security, revisited}

In a \pke{} setting, the adversary knows the public key by design, which in turn is all that he needs to preform encryptions; therefore, the queries in a hypothetical \cpa{} game are moot, because \adversary{} can make the encryptions on its own; figure \ref{cryptogame:pkecpa} shows the changed game for a \pke{}.

\begin{cryptogame}
    {pkecpa}
    {Chosen plaintext attacks, revisited for \pke{} schemes}
    {cpa2}

    \receive{$(\pk, \sk) \pickUAR \keygen(1^\lambda)$}{$\pk$}{}

    \cseqbeginloop
    \cseqadversary{$c = \Enc(\pk, m)$}
    \cseqendloop

    \send{}{$m_0, m_1$}{}

    \receive{\shortstack[l]{
        $b \pickUAR \binary$ \\
        $c_b = \Enc(\pk, m_b)$
    }}{$m_b$}{}

    \cseqbeginloop
    \cseqadversary{$c = \Enc(\pk, m)$}
    \cseqendloop

    \send{}{$b'$}{\textsc{Output 1 iff} $b' = b$}

\end{cryptogame}

\todo{Another verbatim transcription:

Abstract construction (inefficient) for trapdoor permutation

$(Gen, f, f')$, where $gen= \keygen : \singleton \to \Xi_\pk, f(\pk, \cdot) \in \Xi_\pk \to \Xi_\pk, f' = f^{-1}(\sk, \cdot) \in \Xi_\pk \to \Xi_\pk$

Correctness: $f^{-1}(\sk, f(\pk, m)) = m$

$TDP \implies PKE$, Easy but not trivial

$\cryptog{tdp}$... same as \cpa2?

Why $f, f'$ is not cpa-secure? Because they are deterministic

Use $f$'s hardcore predicate

}


\def \bookname {Analysis II}

\documentclass[13pt,a4paper]{report}

\usepackage[margin=1in]{geometry}
\usepackage{amsthm}
\usepackage{amsmath}

\theoremstyle{definition}

\newtheorem{lemma}{Lemma}[section]
\newtheorem{exercise}{Exercise}[section]
\newtheorem{solution}{Solution}[section]

\begin{document}
\chapter{Metric spaces}
\section{Definitions and examples}

\begin{lemma}\label{convergence_lemma_1}
Let $(x_n)^\infty_{n=m}$ be a sequence of real numbers, and let $x$ be another real number. Then
$(x_n)^\infty_{n=m}$ converges to $x$ if and only if $\lim_{n \rightarrow \infty}
d(x_n, x) = 0$.
\end{lemma}

\begin{exercise}
Prove Lemma \ref{convergence_lemma_1}.
\end{exercise}

\begin{solution}
By definition of limit, for any $\varepsilon > 0$ there exists an $N \ge m$ such that
$d(x_n, x) = |x_n - x| < \varepsilon$ for all $n \ge N$. This is exactly the definition
of convergence in previous book.
\end{solution}

\begin{exercise}
Show that the real line with the metric $d(x, y) := |x - y|$ is indeed a metric space.
(Hint: you may wish to review your proof of Proposition 4.3.3.)
\end{exercise}

\begin{solution} We verify the four properties listed in Definition 1.1.2
\begin{itemize}
    \item[1.] $d(x, x) = |x - x| = 0$.
    \item[2.] For all $x \ne y$, $d(x, y) = |x - y| > 0$.
    \item[3.] For all $x$ and $y$, $d(x, y) = |x - y| = |y - x| = d(y, x)$.
    \item[4.] For all $x, y$ and $z$, $d(x, y) = |x - y| = |x - z + z - y| \le
    |x - z| + |z - y| = d(x, z) + d(z, y)$.
\end{itemize}
\end{solution}

\begin{exercise}
Let $X$ be a set, and let $d: X \times X \rightarrow [0, \infty)$ be a function.
\begin{itemize}
    \item[(a)] Give an example of a pair $(X, d)$ which obeys axioms (bcd) of Definition 1.1.2,
    but not (a). (Hint: modify the discrete metric.)
    \item[(b)] Give an example of a pair $(X, d)$ which obeys axioms (acd) of Definition 1.1.2,
    but not (b).
    \item[(c)] Give an example of a pair $(X, d)$ which obeys axioms (abd) of Definition 1.1.2,
    but not (c).
    \item[(d)] Give an example of a pair $(X, d)$ which obeys axioms (abc) of Definition 1.1.2,
    but not (d). (Hint: try examples where $X$ is a finite set.)
\end{itemize}
\end{exercise}

\begin{solution} In general, setting $X$ to be a finite set and defining $d$ by specifying values
for all pairs of elements can produce a lot of metric spaces for each of the problem. For this
exercise to be more challenging, we try to avoid abusing this approach.
\begin{itemize}
    \item[(a)] Let $d$ be the metric such that for all $x, y \in X$, $d(x, y) = 1$. This is similar
    to the discrete metric except that $d(x, x) = 1$ so it does not obey (a).
    \item[(b)] Similar to (a), we can as well set $d(x, y) = 0$ for all $x, y \in X$.
    \item[(c)]
    \item[(d)] Let $X = \{ 1, 2, 3 \}$ and define $d(x, x) = 0$ for $x \in X$, $d(1, 2) = d(2, 1)
    = 1$, $d(2, 3) = d(3, 2) = 1$ and finally $d(1, 3) = d(3, 1) = 3$.
\end{itemize}
\end{solution}

\begin{exercise}
Show that the pair $(Y, d|_{Y \times Y})$ defined in Example 1.1.5 is indeed a metric space.
\end{exercise}

\begin{solution}
Each of the four properties remains after $d$ is restricted to $Y \subset X$ and is vacuous to
verify.
\end{solution}

\begin{exercise}\label{exercise_1_1_5}
Let $N \ge 1$, and let $a_1, a_2, \ldots, a_n$ and $b_1, b_2, \ldots, b_n$ be real numbers. Verify
the identity
    \begin{equation*}
    \Bigg(\sum_{i = 1}^n a_i b_i\Bigg)^2 + \frac{1}{2} \sum_{i = 1}^n \sum_{j = 1}^n
    (a_i b_j - a_j b_i)^2 = \Bigg(\sum_{i = 1}^n a_i^2 \Bigg) \Bigg(\sum_{j = 1}^n b_j^2 \Bigg)
    \end{equation*}
and conclude the \it{Cauchy-Schwarz inequality}
    \begin{equation*}
    \Bigg|\sum_{i = 1}^n a_i b_i \Bigg| \le \Bigg(\sum_{i = 1}^n a_i^2\Bigg)^{\frac{1}{2}}
    \Bigg(\sum_{j = 1}^n b_j^2\Bigg)^{\frac{1}{2}}
    \tag{(1.3)}
    \end{equation*}
Then use the Cauchy-Schwarz inequality to prove the \it{triangle inequality}
    \begin{equation*}
    \Bigg(\sum_{i = 1}^n (a_i + b_i)^2\Bigg)^{\frac{1}{2}} \le
    \Bigg(\sum_{i = 1}^n a_i^2\Bigg)^{\frac{1}{2}} +
    \Bigg(\sum_{j = 1}^n b_j^2\Bigg)^{\frac{1}{2}}
    \end{equation*}
\end{exercise}

\begin{solution}
\end{solution}

\begin{exercise}
Show that $({\bf R}^n, d_{l^2})$ in Example 1.1.6 is indeed a metric space. (Hint: use Exercise
\ref{exercise_1_1_5}.)
\end{exercise}

\begin{exercise}
Show that the pair $({\bf R}^n, d_{l^1})$ in Example 1.1.7 is indeed a metric space.
\end{exercise}

\begin{exercise}
Prove the two inequalities in (1.1). (For the first inequality, square both sides. For the second
inequality, use Exercise \ref{exercise_1_1_5}.)
\end{exercise}

\begin{exercise}
Show that the pair $({\bf R}^n, d_{l^\infty})$ in Example 1.1.9 is indeed a metric space.
\end{exercise}

\begin{exercise}
Prove the two inequalities in (1.2).
\end{exercise}

\begin{exercise}
Show that the discrete metric ${\bf R}^n, d_{\text{disc}}$ in Example 1.1.11 is indeed a metric
space.
\end{exercise}

\begin{exercise}
Prove Proposition 1.1.18.
\end{exercise}

\begin{exercise}
Prove Proposition 1.1.19.
\end{exercise}

\begin{exercise}
Prove Proposition 1.1.20. (Hint: modify the proof of Proposition 6.1.7.)
\end{exercise}

\begin{exercise}
Let
    \begin{equation*}
    X := \Bigg\{ (a_n)_{n = 0}^\infty : \sum_{n = 0}^\infty |a_n| < \infty \Bigg\}
    \end{equation*}
be the space of absolutely convergent sequences. Define the $l^1$ and $l^\infty$ metrics on this
space by
    \begin{equation*}

    \end{equation*}
\end{exercise}

\begin{exercise}
\end{exercise}

\end{document}


\chapter{Derivation Steps in Detail}
In this appendix chapter we provide some further derivation steps used to derive some of our equations.

\section{Taylor Series Approximation}
\label{chap:taylorseriesapproxappendix}

In order to prove equation $\ref{eq:taylorseriesapproximationofp}$ from section $\ref{sec:taylorapproximation}$ we have to show the following: For any $N\mathbb{\in N}$ and
\begin{equation}
 \sum_{n=0}^{N}\frac{(ikwh)^{n}}{n!}\mathcal{F}\left\{ h{}^{n}\right\} (\alpha,\beta) \approx P(\alpha,\beta)
\end{equation}
we have to prove:

\begin{enumerate}
\item Show that there exist such an $N\mathbb{\in N}$s.t the approximation
holds true.
\item Find a value for B s.t. this approximation is below a certain error
bound, for example machine precision $\epsilon$.
\end{enumerate}

\subsection{Proof Sketch of 1.}
By using the \textbf{ratio test} which is on Taylor's theorem$\footnote{Please have a look at \texttt{http://en.wikipedia.org/wiki/Taylors\textunderscore theorem} in order to see a proper definiton of the ratio test.}$ it is possible to show that the series

\begin{equation}
  \sum_{n=0}^{N}\frac{(ikwh)^{n}}{n!}\mathcal{F}\left\{ h{}^{n}\right\} (\alpha,\beta)
\end{equation}
converges absolutely.

\myparagraph{Proof of that the section converges absolutely}
Let us Consider

\begin{equation}
  \sum_{k=0}^{\infty}\frac{y^{n}}{n!}
\end{equation}

for which we define

\begin{equation}
  a_{k}=\frac{y^{k}}{k!}
\end{equation}

By applying the definition of the ratio test for this series it follows:

\begin{equation}
 \forall y:limsup_{k\rightarrow\infty}|\frac{a_{k+1}}{a_{k}}|=limsup_{k\rightarrow\infty}\frac{y}{k+1}=0
\end{equation}

Thus this series converges absolutely, no matter what value we will pick for $y$. Q.E.D.

\subsection{Part 2: Find such an N}
Let $f(x)=e^{x}$. We can formulate its Taylor series, stated above. Let $P_{n}(x)$ denote the n-th Taylor polynomial,

\begin{equation}
 P_{n}(x)=\sum_{k=0}^{n}\frac{f^{(k)}(a)}{k!}(x-a)^{k}
\end{equation}

where $a$ is our developing point (here a is equal zero). We can define the error of the n-th Taylor polynomial to be equal to

\begin{equation}
  E_{n}(x)=f(x)-P_{n}(x)
\end{equation}

The error of the n-th Taylor polynomial is difference between the value of the function and the Taylor polynomial. This directly implies that

\begin{equation}
  |E_{n}(x)|=|f(x)-P_{n}(x)|
\end{equation}

By using the Lagrangian Error Bound it follows:

\begin{equation}
 |E_{n}(x)|\leq\frac{M}{(n+1)!}|x-a|^{n+1}
\end{equation}

with $a=0$, where \textbf{M} is some value satisfying

\begin{equation}
  |f^{(n+1)}(x)|\leq M
\end{equation}

on the interval $I=[a,x]$. Since we are interested in an upper bound of the error and since \textbf{a} is known, we can reformulate the interval as $I=[0,x_{max}]$, where

\begin{equation}
 x_{max} = \|i\| k_{max} w_{max} h_{max}
\end{equation}

We are interested in computing an error bound for $e^{ikwh(x,y)}$. E.g. let us assuming the following parameters (used within Stam's Paper):

\begin{itemize}
  \item Height of bump: 0.15$\mu m$
  \item Width of a bump: 0.5$\mu m$
  \item Length of a bump: 1$\mu m$
  \item $k=\frac{2\pi}{\lambda}$ is the wavenumber, $\lambda\in[\lambda_{min,}\lambda_{max}]$ and
  thus $k_{max}=\frac{2\pi}{\lambda_{min}}$. Since $(u,v,w) = -\omega_i - \omega_r$ and both are unit direction vectors,
  each component can have a value in range {[}-2, 2{]}.
  \item for simplification, assume$[\lambda_{min,}\lambda_{max}]=[400nm,700nm].$
\end{itemize}

We get:

\begin{align}
x_{max}
 &= \|i\| \cdot k_{max} \cdot w_{max} \cdot h_{max} \nonumber \\
 &= k_{max} \cdot w_{max} \cdot h_{max} \nonumber \\
 &=2\cdot(\frac{2\pi}{4 \cdot 10^{-7}m}) \cdot 1.5 \cdot 10^{-7} \nonumber \\
 &=1.5\pi
\end{align}

and it follows for our interval $I=[0,1.5\pi]$. Next we are going to find the value for $M$. Since the exponential function is monotonically growing (on the interval $I$) and the derivative of the exponential function is again an exponential function, we can find such an $M$:

\begin{align*}
 M
 &=e^{x_{max}} \nonumber \\
 &=exp(1.5\pi)
\end{align*}

and $|f^{(n+1)}(x)|\leq M$ holds. With

\begin{align}
|E_{n}(x_{max})|
 &\leq\frac{M}{(n+1)!}|x_{max}-a|^{n+1} \nonumber \\
 &= \frac{exp(1.5\pi)*(1.5\pi)^{n+1}}{(n+1)!}
\end{align}

we now can find a value of $n$ for a given bound, i.e. we can find an value of $N\mathbb{\in N}$ s.t. $\frac{exp(1.5\pi)*(1.5\pi)^{N+1}}{(N+1)!}\leq\epsilon$. With Octave/Matlab we can see:

\begin{itemize}
\item if N=20 then $\epsilon\approx2.9950*10^{-4}$
\item if N=25 then $\epsilon\approx8.8150*10^{-8}$
\item if N=30 then $\epsilon\approx1.0050*10^{-11}$
\end{itemize}

With this approach we have that $\sum_{n=0}^{25}\frac{(ikwh)^{n}}{n!}\mathcal{F}\left\{ h{}^{n}\right\} (\alpha,\beta)$ is an approximation of $P(u,v)$ with error $\epsilon\approx8.8150*10^{-8}$. This means we can precompute 25 Fourier Transformations in order to approximate P(u,v) having an error $\epsilon\approx8.8150*10^{-8}$.

\section{PQ approach}
\subsection{One dimensional case}
\label{sec:pqonedimappendix}
Since our series is bounded, we can simplify the right-hand-side of equation $\ref{eq:pqgeometricseries}$. Note that $e^{-ix}$ is a complex number. Every complex number can be written in its polar form, i.e.

\begin{equation}
e^{-ix} = cos(x) + i sin(x)
\label{eq:polarform}
\end{equation}

Using the following trigonometric identities
\begin{gather}
cos(-x) = cos(x) \nonumber \\
sin(-x) = -sin(x)
\end{gather}

combined with $\ref{eq:polarform}$ we can simplify the series $\ref{eq:pqgeometricseries}$ even further to:

\begin{align}
\frac{1-e^{iwT(N+1)}}{1-e^{-iwT}}
& =\frac{1-cos(wT(N+1)) + i sin(wT(N+1)) }{1-cos(wT) + i sin(wT)}
\label{eq:pq1minusexp}
\end{align}

Equation $\ref{eq:pq1minusexp}$ is still a complex number, denoted as $(p+iq)$. Generally, every complex number can be written as a fraction of two complex numbers. This implies that the complex number $(p+iq)$ can be written as $(p+iq) = \frac{(a+ib)}{(c+id)}$ for any $(a+ib), (c+id) \neq 0$. Let us use the following substitutions:

\begin{align}
a& := 1 - cos(wT(N+1))&
b& =sin(wT(N+1)) \nonumber \\
c& =1-cos(wT)&
d& =sin(wT)
\label{eq:pqabcdsubstitudes}
\end{align}

Hence, using $\ref{eq:pqabcdsubstitudes}$, it follows

\begin{equation}
  \frac{1-e^{iwT(N+1)}}{1-e^{-iwT}} = \frac{(a+ib)}{(c+id)}
\end{equation}

By rearranging the terms, it follows $(a+ib) = (c+id)(p+iq)$ and by multiplying its right hand-side out we get the following system of equations:

\begin{align}
(cp-dq)& =a \nonumber \\
(dp + cq)& =b
\label{eq:cdadcn}
\end{align}

After multiplying the first equation of $\ref{eq:cdadcn}$ by $c$ and the second by $d$ and then adding them together, we get using the law of distributivity new identities for $p$ and $q$:

\begin{align}
p& =\frac{(ac+bd)}{c^2 + d^2} \nonumber \\
q& =\frac{(bc+ad)}{c^2 + d^2}
\label{eq:pq1}
\end{align}

Using some trigonometric identities and putting our substitution from $\ref{eq:pqabcdsubstitudes}$ for $a$, $b$, $c$, $d$ back into the current representation $\ref{eq:pq1}$ of $p$ and $q$ we will get:

\begin{align}
p& =\frac{1}{2}+\frac{1}{2}\left(\frac{cos(wTN)-cos(wT(N+1))}{1-cos(wT)}\right) \nonumber \\
q& =\frac{sin(wT(N+1))-sin(wTN)-sin(wT)}{2(1-cos(wT))}
\end{align}

Since we have seen, that $\sum_{n=0}^N e^{-uwnT}$ is a complex number and can be written as $(p+iq)$, we now know an explicit expression for $p$ and $q$. Therefore, the one dimensional inverse Fourier transform of $S$ is equal:

\begin{align}
\mathcal{F}^{-1}\{S\}(w)
& =\mathcal{F}^{-1}\{f\}(w) \sum_{n=0}^{N} e^{-iwnT} \nonumber \\
& = (p+iq) \mathcal{F}^{-1}\{f\}(w)
\label{eq:mainfinding1dappendix}
\end{align}

\subsection{Two dimensional case}
\label{sec:pqtwodimappendix}

\begin{align}
\mathcal{F}^{-1}\{S\}(w_1, w_2)
& = \int_{-\infty}^{\infty}\int_{-\infty}^{\infty} \sum_{n_2=0}^{N_1} \sum_{n_2=0}^{N_2} h(x_1 + n_1 T_1, x_2 + n_2 T_2) e^{iw(x_1 + x_2)}dx_1 dx_2 \nonumber \\
& = \int_{-\infty}^{\infty}\int_{-\infty}^{\infty} \sum_{n_2=0}^{N_1} \sum_{n_2=0}^{N_2} h(y_1, y_2) e^{iw((y_1 - n_1 T_1) + (y_2 + n_2 T_2))}dx_1 dx_2 \nonumber \\
& =\sum_{n_2=0}^{N_1} \sum_{n_2=0}^{N_2} \int_{-\infty}^{\infty}\int_{-\infty}^{\infty} h(y_1, y_2) e^{iw(y_1 + y_2)} e^{-iw(n_1 T_1 + n_2 T_2)}dy_1 dy_2 \nonumber \\
& =\sum_{n_2=0}^{N_1} \sum_{n_2=0}^{N_2} e^{-iw(n_1 T_1 + n_2 T_2)} \int_{-\infty}^{\infty}\int_{-\infty}^{\infty} Box(y_1, y_2) e^{iw(y_1 + y_2)} dy_1 dy_2 \nonumber \\
& =\left(\sum_{n_2=0}^{N_1} \sum_{n_2=0}^{N_2} e^{-iw(n_1 T_1 + n_2 T_2)}\right) \mathcal{F}^{-1}\{h\}(w_1,w_2) \nonumber \\
& =\left(\sum_{n_2=0}^{N_1} e^{-iw n_1 T_1}\right) \left(\sum_{n_2=0}^{N_2} e^{-iw n_2 T_2}\right) \mathcal{F}^{-1}\{h\}(w_1,w_2) \nonumber \\
& =(p_1 + i q_1)(p_2 + i q_2) \mathcal{F}^{-1}\{h\}(w_1,w_2) \nonumber \\
& =((p_1 p_2 - q_1 q_2) + i(p_1 p_2 + q_1 q_2)) \mathcal{F}^{-1}\{h\}(w_1,w_2) \nonumber \\
& =(p + iq) \mathcal{F}_{DTFT}\{h\}(w_1,w_2)
\label{eq:pqmainfindingappendix}
\end{align}

Where we have defined

\begin{align}
p := (p_1 p_2 - q_1 q_2) \nonumber \\
q := (p_1 p_2 + q_1 q_2)
\label{eq:pqsubst2dappendix}
\end{align}


\section{Algorithms}\label{section:word}

\begin{definition}[Approximation algorithm]
    Find approximate solutions to~\nameref{optproblem}
\end{definition}

\begin{definition}[Asymptotic Polynomial-time Approximation Scheme, APTAS]
\label{APTAS}
    A family of algorithms, and a constant $c$ such that all solutions has an
    approximation of $(1 + \epsilon)\times{OPT} + c$ for minimization problems.
\end{definition}

\begin{definition}[Bin-packing]
    A series of algorithms to learn how to distribute $n$ numbers into $k$ bins.
    First-fit, best-fit, worst-fit (stack into where there is most free space),
    best-fit, etc.
\end{definition}

\begin{definition}[Complimentary slackness]
    Given an optimal solution to a linear program,
    $Z_{LP}$ and it's dual $Y_{LP}$, with $x_{1}, x_{2}, \dots x_{n}$ and
    $y_{1}, y_{2}, \dots y_{n}$ respecively, with
    $w_{1}, w_{2}, \dots w_{n}$ and $z_{1}, z_{2}, \dots z_{n}$  as slack
    variables for each solution, respectively,
    then $\forall x, x_{i}z_{i} = 0$ and $\forall y, y_{i} w_{i} = 0$

    This necessary condition for optimality conveys a fairly simple economic
    principle.  In standard form (when maximizing), if there is slack in a
    constrained primal resource (i.e., there are ``leftovers''),
    then additional quantities of that resource must have no value.
\end{definition}

\begin{definition}[Difference heuristic and approximation]
    While an heurisitc makes a choice, without a guarantee of optimality,
    an approximation can make a choice and know that this choice will render
    a solution within a factor of OPT.\
\end{definition}

\begin{definition}[EDD]\label{EDD}
    Earliest Due Date
\end{definition}

\begin{definition}[F-approximation]
    Also referred to as a linear approximation, using a function f,
    which is affine.
\end{definition}

\begin{definition}[FPTAS, fully polynomial approximation scheme]\label{FPTAS}
    As in~\nameref{PTAS}, just $\frac{1}{\epsilon}$.
    The algoritm is required to be polynomial both in running time and problem
    size.

    Note that strongly NP-complete problems do not have any FPTAS.\
\end{definition}

\begin{definition}[Integrality gap]\label{integralitygap}
    The biggest difference between an IP and LP
\end{definition}

\begin{definition}[Locality of Reference]
     also known as the principle of locality, is a phenomenon describing the
     same value, or related storage locations, being frequently accessed. There
     are two basic types of reference locality – temporal and spatial locality.
     Temporal locality refers to the reuse of specific data, and/or resources,
     within a relatively small time duration. Spatial locality refers to the
     use of data elements within relatively close storage locations. Sequential
     locality, a special case of spatial locality, occurs when data elements
     are arranged and accessed linearly, such as, traversing the elements in a
     one-dimensional array

\end{definition}

\begin{definition}[Makespan]
    The total length of a schedule; from 0 to $C_{\max}$
\end{definition}

\begin{definition}[$\tilde{O}$]\label{otilde}
    Given function $f(x)$, $\tilde{O}(f(x)) = O(f(x)\cdot{\log^{k}{f(x)}})$
\end{definition}

\begin{definition}[Optimization problem]\label{optproblem}
    To find the best solution of $n$ feasible solutions.
\end{definition}

\begin{definition}[Perfect matching]
    A collection $E^{\prime} \subseteq E$ of edges in a graph
    $G = (V,E)$, such that $\forall v \in V$, are connected
    from $E^{\prime}$ only once.
\end{definition}

\begin{definition}[Pre-empty schedule]\label{pre-emptive}
    You can interrupt task and re-continue them.
\end{definition}

\begin{definition}[PTAS, Polynomial-time approximation scheme]\label{PTAS}
    Given an optimization problem (e.g.\ an NP-problem) and a parameter
    $\epsilon$, produce a solution within (($1 + \epsilon) \times OPT$)
    $\epsilon > 0$

    E.g.\ for the traveling salesman, a tour would be of length max
    $(1 + \epsilon) \times L$, with $L$ being the length of the tour

    Note that for minimization, there is $1 + \epsilon$, and for maximization,
    there is $1 - \epsilon$

    If you have a scheme with $(1 \pm \epsilon) \times OPT + \kappa$, then
    it is not under PTAS.\ PTAS only handles the former part, $(1 \pm \epsilon)$

    For MAX SNP, there does not exist polynomial approximation schemes
\end{definition}

\begin{definition}[Parallel Random Access Machine]
    an abstract computer for designing parallel algorithms

\end{definition}

\begin{definition}[$\rho$-approximation]
    Polynomial algorithm that is guaranteed to have objective function
    to OPT within $\rho$ of
    optimum (not the ($1 + \epsilon$) of~\nameref{PTAS}).
\end{definition}

\begin{definition}[Scheduling]
    See~\nameref{srpt},
    \begin{itemize}
        \item \textbf{$P_{i}$} = time to do a job $i$
        \item \textbf{$R_{i}$} = earliest time a job $i$ can start
        \item \textbf{$C_{i}$} = time of completion for job $i$
        \item \textbf{$D_{i}$} = due date for job $i$
        \item \textbf{$L_{i}$} = $C_{i} - D_{i}$
    \end{itemize}
\end{definition}

\begin{definition}[Strong duality]
    The optimal value of the dual is equal to that of the primal linear program.

    $ \sum{y^{*}_{i}} = \sum{w_{i}x_{i}}$
\end{definition}

\begin{definition}[Weak duality property]
    No dual program has a solution greater than the optimal of the primal
    linear program
\end{definition}

\begin{definition}[$\alpha$ approximation]
    Produce a solution who's value is within a factor of $\alpha$
    of the optimal.
\end{definition}