\documentclass{article}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{ dsfont }
\usepackage{amssymb}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{subcaption}

% Questa linea raddoppia lo spazio tra una riga e l'altra per tutto il documento %
\doublespacing

\begin{document}
% Abstract %
\thispagestyle{plain}
\begin{center}
    \Large
    \textbf{Computational Mathematics for Learning and Data Analysis}

    \vspace{0.4cm}
    \large
    2019 / 2020

    \vspace{0.4cm}
    \textbf{Poggiali Alessandro, Berti Stefano}

    \vspace{0.9cm}
\end{center}

% Nuova pagina %
\newpage
% Setting the stage %
\section{Setting the stage}\label{sec:setting-the-stage}

\subsection{The problem: Least Squares}\label{subsec:linear-square-problem}
Our problem is to find an array x such that \\\\
\centerline{$\min_{x \in \mathds{R}^n}\|Ax-b\|$} \\\\
holds, where
\begin{itemize}
	\item $A$ is a \textit{tall thin matrix} (so it is a matrix $A\in M(m, n, R)$ where $m \gg n$)
	\item $b$ is a vector of real number
	\item $\|.\|$ is the \textit{2-norm} or \textit{Euclidean Norm}: $\|x\| := \sqrt{\sum_{i=1}^n x_i^2}$
\end{itemize}
and so to find the closest vector to $b$ inside the hyperplane $Im(A)$.

% Conjugate gradiend method %
\subsection{First algorithm: Conjugate Gradient Method}\label{subsec:conjugate-gradient-method}
In general, if a square matrix $B = B^{T}$ is positive definite, then we can find a solution to $Bx = c$ by minimizing the (strictly convex) function
\begin{equation}\label{eq:cgfunction}
f(x) = \frac{1}{2}x^{T}Bx - c^{T}x
\end{equation}
(that is equal to set $\nabla f(x) = Bx - c = 0$).
However our matrix $A$ is a \emph{tall thin matrix} and since in this case finding a solution to  $Ax = b$ is equivalent to solving the normal equations
\[
A^{T}Ax - A^{T}b = 0
\]
then we can use \textit{Conjugate gradient} method to minimize the function
\[
f(x) = \frac{1}{2}x^{T}A^{T}Ax - x^{T}A^{T}b
\]
From now on we set $B = A^{T}A$ and $c = A^{T}b$ so our function to minimize become exactly the~\eqref{eq:cgfunction}, where $B$ is positive definite.
\\We remember that \begin{itemize}
\item \textbf{B-orthogonal}: $x, y \in R^{m}$ are B-orthogonal if $x^{T}By = 0$
\item \textbf{B-norm}: the B-norm of $x \in R^{m}$ is $\|x\|_{B} := (x^{t}Bx)^{\frac{1}{2}}$.
\item Note that if B is \textit{positive definite}, then the B-norm is $\geq 0$ (it is $0$ only for the $0$ vector)
\end{itemize}
Let $x_{k}$ be the parameter vector after the $k$-th iteration, then the residual vector is $r_{k} = b - Ax_{k}$ and the negative gradient $g_{k} = -\nabla f(x_{k}) = c - Bx_k = A^{T}b - A^{T}Ax_k = A^{T}r_{k}$.
The step size $\alpha_{k}$ can be computed in a similar way as in the standard CG method, but here the denominator is $d_{k}^{T}Bd_k= d_{k}^{T}A^{T}Ad_k = \|Ad_{k}\|^2$ and so it can be obtained without calculating $B = A^{T}A$.
\\To update the residual, we use the fact that $r_{k} = b - Ax_{k} = [x_{k} = x_{k-1} + \alpha_{k-1}d_{k-1}] = b - A(x_{k-1} + \alpha_{k-1}d_{k-1}) = [b-Ax_{k-1} = r_{k-1}] = r_{k-1} - \alpha_{k-1}Ad_{k-1}$.
The trick about conjugate gradient is that at each step we generate a new search direction, which is not exactly the residual, but is the residual modified to be $B$-orthogonal to the previous search direction.
In this way, $\beta_{k}$ is a scalar that is chosen s.t. $d_{k}$ is $B$-orthogonal to $d_{k-1}$.

% QR factorization method %
\subsection{Second algorithm: QR factorization with Householder Reflectors}\label{subsec:qr-factorization-with-householder-reflectors}
To solve the Least Square Problem, we use the \textit{thin QR factorization} with all the optimization seen (fast Householder-vector product, cancellation problem resolution, manually changing known entries) in order to factorize $A$ as $Q_{1}R_{1}$.
We use a variant~\cite{nla} of the \textit{thin QR factorization} where we do not form the matrix $Q$, but we keep the Householder vector $u_{k}$ to perform implicit product with $Q$ and $Q^{T}$.
With this factorization, we can write $\|Ax - b\|$ as $\left\lVert \begin{bmatrix} R_{1}x - Q_{1}^{T}b \\ Q_{2}^{T}b\end{bmatrix} \right\lVert$
and now we can chose $x$ such that $R_{1}x - Q_{1}^{T}b = 0$, which is $x = R_{1}^{-1}Q_{1}^{T}b$ (if $R_{1}$ is invertible).
We can write $x = R^{-1}(Q^{T}b) = R^{-1}(((I-2v_{1}v_{1}^{T})(I-2v_{2}v_{2}^{T})\dots(I-2v_{m}v_{m}^{T}))^{T}b)$
Finally we should have $x  = \arg\!\min_{x \in  \mathds{R}^n}\|Ax - b\| = R_{1}^{-1}Q_{1}^{T}b$ and $\|Ax - b\| = \|Q_{2}^{T}b\|$.

\section{What to expect from the algorithms}\label{sec:what-to-expect-from-the-algorithms}

\subsection{Conjugate Gradient}\label{subsec:conjugate-gradient}
Our system $Ax = b$ is equivalent to the system $Bx = c$, where $B = A^{T}A$ is symmetric and positive definite and $c = A^{T}b$.
However, from a numerical point of view, the two systems are different, because of rounding-off errors that occur in joining the product $A^{T}A$.
But since our algorithm does not involve the computation of $B = A^{T}A$, then we have the same convergence result as in the standard CG method.
In particular we know that this method gives the solution in $n$ steps if no rounding-off error occurs, where $n$ is the size of $B$, namely the smallest size of our original rectangular matrix $A$.
In realistic cases, the absence of rounding-off errors cannot be assured and so we need more than $n$ step or even to restart the algorithm many times.
Also the basic relations concerning convergence ($<r_i,r_k>\,= 0, <Ad_i,d_k>\,= 0$ for $i \ne k$) will not be satisfied exactly and therefore $x_n$ will not be as good an estimate the exact solution as desired.
From~\cite{hestenes1952methods} follows that the larger the ratios $\alpha_i / \alpha_{i-1}$, the more rapidly the rounding-off errors accumulate.
Moreover, since $\alpha_i$ lies on the range
\[
1 / \lambda_{\max} < \alpha_i < 1 / \lambda_{\min}
\]
the ratio $\rho = \lambda_{\max}/\lambda_{\min}$ gives us an upper bound of the critical ratio  $\alpha_i / \alpha_{i-1}$ which determines the stability of the entire process.
So we would like to have $\rho$ near one, that means our matrix is near multiple of the identity and then the CG method is relatively stable.

The algorithm performs at every step two multiplications  (one is enough if we compute it and store it) of $A$ with the $n$-vector $d_i$ $(O(mn))$ and one multiplication of $A^{T}$ with the $m$-vector $r_i$ $(O(nm))$.
So, the total cost is $n(O(mn) + O((nm)) + O(n)) \approx O(n^{2}m)$, where $O(n)$ comes from the scalars product between $n$-vectors to compute the norms for every steps.

The convergence of the Conjugate Gradient Method depends on the maximum eigenvalue $\lambda_{\max}$ and the minimum eigenvalue $\lambda_{\min}$, and CG converges with rate
\begin{equation}\label{eq:cgconv}
\|x-x_{k}\| \leq \left\lVert\frac{\sqrt{\lambda_{max}}-\sqrt{\lambda_{min}}}{\sqrt{\lambda_{max}}+\sqrt{\lambda_{min}}}\right\rVert^{k}  \|x - x_{0}\|
\end{equation}

\subsection{QR with HouseHolder}\label{subsec:qr-with-householder}
The QR factorization has a cancellation problem during the Householder reflector construction that is easily fixed by summing first entry and norm instead of subtract it.
\\Apart from that, since every step is \textit{backward stable}, the factorization algorithm is \textit{backward stable}: the computed $Q$, $R$ are the exact result of $qr(A + \Delta A)$ where $ \left\lVert \Delta A \right\rVert \leq O(u)\left\lVert A \right\rVert$, so we only have intrinsic representation errors.
\\By looking at the residual $\left\lVert A x - b\right\rVert$, we can't say if our computed $x$ is close to the true solution $x^{*}$: the residual can be arbitrarily large because it depends on the problem.
The computed $x$ solves the modified problem $\min \left\lVert Ax - (b + Q_{1}r)\right\rVert$, and $x$ is close to the true solution $x^{*}$ if the residual of the top block $r_{1} = Q_{1}^{T}(Ax - b)$ is close to 0.
Moreover, $\frac{\left\lVert x - x^{*} \right\rVert}{ \left\lVert x^{*} \right\rVert} \leq k_{rel, b\rightarrow x}\frac{\left\lVert r \right\rVert}{\left\lVert b \right\rVert}$.
\\The computational cost for thin QR factorization is $2mn^2 - \frac{2}{3}n^3 + O(mn)$ flops, which represents two cases: if $m \approx n$, we have that the cost is $\frac{4}{3}n^3$, if $m \gg n$ the cost scales like $2mn^2$, so it scales linearly with respect to the biggest dimension of A .
\\Before we said that $x = R_{1}^{-1}Q_{1}^{T}b$, but to be able to calculate it we need $R_{1}$ to be invertible.
We know that $A$ has full column rank $\iff Az \neq 0 \forall z \neq 0 \iff z^{T}A^{T}Az = \left\lVert Az \right\rVert^{2} \forall z \neq 0 \iff A^{T}A$ is positive definite $\iff$ all eigenvalues of $A^{T}A$ are $> 0\iff $0 is not an eigenvalue of $A^{T}A \iff A^{T}A = (Q_{1}R_{1})^{T}Q_{1}R_{1} = R_{1}^{T}Q_{1}^{T}Q_{1}R_{1} = R_{1}^{T}R_{1}$ is invertible $\iff \det(A^{T}A) = \det(R_{1}^{T})\det(R_{1}) \neq 0 \iff \det(R_{1}) \neq 0 \iff R_{1}$ is invertible.
So if $A$ has full column rank, $\min_{x \in \mathds{R}^n}\|Ax-b\|$ has solution and it is unique.
$R_{1}$ is invertible also if all elements on its diagonal are $\neq 0$.
\\The cost to solve $x = R_{1}^{-1}(Q_{1}^{T})b$ is a multiplication $c = (Q_{1}^{T})b$, which costs $O(mn)$, and the resolution of the triangular system $R_{1}x = c$ with back-substitution, which costs $O(n^{2})$.
Anyway, the overall cost $O(mn) + O(n^{2})$ is negligible with respect to the cost $O(mn^{2})$ to compute $Q_{1}, R_{1}$.
This factorization algorithm is bandwidth heavy and not parallelizable, as every reflection that produces a new zero element changes the entirety of both Q and R matrices

\section{Input data}\label{sec:input-data}
Our input data is the matrix A, which is the tall thin matrix used as input in the \textit{ML-cup 2019--2020} competition.
Its shape is $(1765, 20)$, we augmented it with few functions of the features of the dataset:
\begin{itemize}
	\item \textbf{21\textsuperscript{st} column}: logarithm of the absolute value of the 1\textsuperscript{st} column
	\item \textbf{22\textsuperscript{nd} column}: product of 2\textsuperscript{nd}, 3\textsuperscript{rd} and 4\textsuperscript{th} columns
	\item \textbf{23\textsuperscript{rd} column}: 5\textsuperscript{th} column to square
\end{itemize}
So the final shape of $A$ is $(1765, 23)$.
    The condition number of the matrix $A$ (calculated with \textit{numpy.linalg.cond}, which does SVD and $\frac{\sigma_{1}}{\sigma_{n}}$) is $\approx 400000 (4 \times 10^{5})$, while the condition number of a random matrix with the same dimension and same range of values (min and max of the 2 matrices are the same) is $\approx 1.7$.
    We can conclude that the matrix $A$ is ill conditioned, so it is almost singular and the solution of our problem could be not accurate.
    Anyway, we know that the solution of the least square problem exists and it is unique, because $A$ is a full column rank matrix ($rank(A) = n = 23$), where rank is calculated as the number of singular values $> \max(\sigma_{i}) \times \max(m, n) \times eps$, which is the same approach used in MATLAB .

\section{Code}\label{sec:code}
The code has been implemented in \textit{Python}, we used \textit{Numpy} for array manipulation.
\subsection{Conjugate gradient method Code}\label{subsec:conjugate-gradient-method-code}
The Algorithm 1 performs the CG method applied to our function~\ref{eq:cgfunction}, starting from an initial guess of $x$.
For each iteration we store the product $Ad_k$ in a variable so that it can be computed only once instead of twice.
% CG pseudocode
\makeatletter
\makeatother
\begin{algorithm}
\caption{LS resolution with CG method}
\begin{algorithmic}[1]
\Function{$x \gets A, b$}{}
\State $x_0 \gets starting\,guess$
\State $r_0 \gets b -  Ax_0$
\State $g_0 \gets A^{T}r_0$
\State \emph{for i = 1:m}:
\State \quad\emph{if $g_{k-1} = 0$}:
\State\quad\quad\textit{return $x_{k-1}$}
\State \quad\emph{if $i > 1$}:
\State\quad\quad{$\beta_{k} = - \|g_{k-1}\|^2 / \|g_{k-2}\|^2$}
\State \quad\emph{if $i = 1$}:
\State\quad\quad{$d_{k} = g_{0}$}
\State \quad\emph{else}:
\State\quad\quad{$d_{k} = g_{k-1} - \beta_{k}d_{k-1}$}
\State\quad $\alpha_{k} = \|g_{k-1}\|^2 / \|Ad_{k}\|^2$
\State\quad $x_{k} = x_{k-1} + \alpha_{k}d_{k}$
\State\quad $r_{k} = r_{k-1} - \alpha_{k}Ad_{k}$
\State\quad $g_{k} = A^{T}r_{k}$
\State\textit{return $x_{m}$}
\EndFunction
\end{algorithmic}
\end{algorithm}
\subsection{QR factorization method code}\label{subsec:qr-code}
In line 6 of Algorithm 4, we used \textit{scipy.linalg.solve\_triangular} to compute the solution of the linear system $R_{1}x = Q_{1}^{T}b$ by back-substitution, where $Q_{1}^{T}b$ is the vector computed by implicit product.
 % Householder reflector pseudocode
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother
\begin{algorithm}
\caption{Householder reflector}
\begin{algorithmic}[1]
\Function{$[v, s] \gets householder\_vector(x)$}{}
\State $s \gets -sign(x[0]) \times norm(x)$
\State $v \gets x$
\State $v[0] \gets v[0] -s$
\State $v \gets \frac{v}{norm(v)}$
\State \textit{return v, s}
\EndFunction
\end{algorithmic}
\end{algorithm}
% QR factorization pseudocode
\makeatletter
\makeatother
\begin{algorithm}
\caption{QR factorization with Householder Reflectors}
\begin{algorithmic}[1]
\Function{$[V, R] \gets qr\_factorization(A)$}{}
\BState \emph{top}:
\State $\textit{[m, n]} \gets \textit{size(A)}$
\State $\textit{V} \gets \textit{emptyList}$
\BState \emph{loop}:
\State \emph{for j = 1:min(m-1, n)}:
\State \quad$\textit{[v, s]} \gets \textit{householder\_vector(A(j:end, j))}$
\State \quad$\textit{A[j, j]} \gets \textit{s}$
\State \quad$\textit{A[j+1:end, j]} \gets \textit{0}$
\State \quad$\textit{A[j:end, j:end]} \gets \textit{A[j:end, j:end]} - 2\times v \times (v^{T} \times \textit{A[j:end, j+1:end])}$
\State \quad$\textit{V} \gets \textit{V.insert(v)}$
\BState \emph{end}:
\State $\textit{R = A}$
\State \textit{return V, R}
\EndFunction
\end{algorithmic}
\end{algorithm}
% Resolution pseudocode
\makeatletter
\makeatother
\begin{algorithm}
\caption{LS resolution with QR factorization}
\begin{algorithmic}[1]
\Function{$x \gets A, b$}{}
\State $\textit{[V, R]} \gets \textit{qr\_factorization(A)}$
\State $x \gets b$
\State \emph{for i = 1:n}:
\State \quad$x[i:end] \gets x[i:end] - 2 \times v_{i} \times (v_{i}^{T} \times x[i:end])$
\State $x \gets R^{-1}x$
\State \textit{return x}
\EndFunction
\end{algorithmic}
\end{algorithm}

\section{Experimental set up}\label{sec:experimental-set-up}
We are going to compare the two methods over the ML-cup in terms of time spent, memory usage and quality of the solution.
We will look how much our solutions are good in terms of residual and how much we got close to the true solution.
We will check the condition angle of the problem, to understand how much our solution is stable, and we will compare it with a random matrix with the same dimension and range of values of the ML-cup one.
Finally, we will test which is the maximum problem dimension computable for the two methods with a given RAM .
Moreover, for the QR factorization, we are going to test how the computational cost scales varying the dimension $m$ over the 3 matrices $m \times m$, $m \times n$ with $m > n$ and $m \times n$ with $m \gg n$.

\section{Results}\label{sec:results}
\begin{table}[h!]
    \begin{center}
        \caption{Results for ML-cup}
        \label{tab:table4}
        \begin{tabular}{l|c|c|c|c|r}
            \textbf{method} & \textbf{Time [ns]} & \textbf{Space [bytes]} & $\frac{\|\textbf{Ax - b}\|}{\left\lVert b \right\rVert}$ & $\|\textbf{A}^{T}(\textbf{Ax} - \textbf{b})\|$ & $\|\textbf{Q}^{T}\textbf{(Ax - b)}\|$\\
            \hline
            CG & 3039378 & 15040 & 0.4369 & 7.86e-03 & - \\
            QR & 6588780 & 322736 & 0.4369 & 1.7228-07 & 1.4577e-09 \\
            np.linalg.qr & 1039482 & 328992 & 0.4369 & 2.7481e-08 & 4.4336e-10 \\
            scipy.linalg.qr & 2876662 & 328992 & 0.4369 & 3.3332e-08 & 5.0628e-10
        \end{tabular}
    \end{center}
\end{table}

\subsection{Time}\label{subsec:time}
For the time results we averaged 1000 run using \textit{time.monotonic\_ns()}, and we removed the best and worst 100 ones.
The CG method is $\sim 2$ times faster than the QR method: for the QR method we need n steps to compute the n $v_{i}$'s vector and the matrix $R$, while the CG method is an iterative method and we can choose after how many iterations to stop.
In Table~\ref{tab:table4} we report the results obtained performing the CG method for $n$ iterations, since theoretically this algorithm should return the exact solution after $n$ steps.
However, after such a low number of iterations we fail to achieve a good accuracy.
Plots in Figure~\ref{cg_acc} show how the number of iterations changes according to different levels of accuracy required by the algorithm.
The maximum level of accuracy reached by the CG method applied to our problem is $\approx 10^{-11}$ [figure~\ref{cg_acc1}].
After that the rounding-off errors accumulate a lot and the algorithm no longer converges.
This is because our problem is ill conditioned.
In fact, if we execute the same approach to a random problem (random matrix $A$ and random vector $b$ with the same dimensions and the same ranges of values of our inputs) we note that [figure~\ref{cg_acc2}] the number of iterations required to get the same accuracy is definitely lower.
These graphs show also that the convergence of the CG method is almost linear, as formula~\eqref{eq:cgconv} states.
For what concerns the choice of the initial vector $x_0$ we used the 0 vector for all the experiments.
Since our function to minimize is a convex function, whatever starting point we choose the algorithm converges to the (unique) optimal solution.
In Figure~\ref{cg_x0} we report in how many iterations the CG method converges to the optimal solution with a fixed level of accuracy ($10^{-11}$) with different starting point.
We note that if we start close to the optimal solution the algorithm requires few iterations while if we choose a starting vector far away from the optimum the number of iterations increases until it reaches a constant trend.
In fact, from~\eqref{eq:cgconv} follows that the rate of convergence is determined by the distance between the initial vector and the optimal solution.
So it is preferable to start with an initial guess close to the optimum but since we don't have such estimate in advance, the 0 vector is a good trade-off.
\subsection{Space}\label{subsec:space}
With space we mean the additional number of bytes used by the methods in addition to the inputs, we measured it with \textit{numpy.array.nbytes}.
The space used by the QR method, if we assume that we don't want to preserve the input matrix A (that will become the upper triangular matrix R), is the number of bytes needed to save the n $v_{i}$'s vector of floats with length in [1765, 1743], and it is $\sim 1725 \times 23 \times 8$.
The computation to calculate x is done "in place", so no more space is required.
There is a little difference between the space used by our implementation and the one of numpy, because we don't form the matrix $Q$ of size $m \times n$, but we have $n$ vector of size $m, m-1, \dots, m-n$.
The CG method stores five $n$-vectors ($x, d, g, g_{i-1}$ and $g_{i-2}$) and one $m$-vector ($r$) for each iteration but since we don't need to keep whole ‘history’ we can rewrite them every time.
So the total space for CG is $(23\times5 + 1765)\times8 = 15040$.
If we assume to have a RAM of 4 GB and we fix $n$, we can compute the maximum computable dimension of m that we call $M$.
We obtain that, if $n=10$, $M_{QR} = 50 \times 10^{6}$ and $M_{CG}\sim 500 \times 10^{6} (499999950)$, and with $n=10000$, $M_{QR} = 50 \times 10^{3}$ and still $M_{CG} \sim 500\times 10^{6} (499950000)$.
The maximum dimension in case of square matrix $N$ is $N_{CG} = \frac{RAM}{48} = 500 \times 10^{9}$ and $N_{QR} = \sqrt{\frac{RAM}{8}} = 22360$.
We can conclude that the space needed by CG is $O(n+m)$, while the space needed by QR is $O(nm)$ for the general case.
For square matrices ($n=m$) the space needed by the CG is $O(n)$ and the space needed by the QR is $O(n^{2})$.
It turns out that the CG method is more suitable for large matrices in terms of space.

\subsection{Quality of solution}\label{subsec:quality-of-solution}
The angle $\theta$ between $Ax$ and $b$ is telling us how well we can approximate $b$ from $Ax$, and the bigger it is, the higher is the changing in the solution $x$ w.r.t a small change in $b$.
We compute it as $\arccos\left(\frac{\left\lVert Ax \right\rVert}{\left\lVert b \right\rVert}\right)$, and its value is 0.45.
To understand if this value is big or not, we compared it with the one obtained with random inputs $A$ and $b$ with same dimensions and range of values, and we obtained 0.82, so this value doesn't seem to be such big.
Anyway, the condition number of the matrix A is big ($k(A) \sim 400000$), and if we compute the condition number w.r.t input b we obtain $k_{rel, b\rightarrow x} \leq \frac{k(A)}{\cos(\theta)} \sim 450000$ and w.r.t input A we obtain $k_{rel, A \rightarrow x} \leq k(A) + k(A)^{2} \tan(\theta) \sim 80\times 10^{9}$
So the problem is highly conditioned, specially for $A$ w.r.t $x$.
The solution have a similar residual $\left\lVert Ax - b \right\rVert$, but looking at the value $\left\lVert A^{T}(Ax - b)\right\rVert$, we can say that the QR solution is three order of magnitude closer to the true solution.
Anyway the residual is quite big because it is problem dependent and it tells us how well we can extract $b$ from $Im(A)$.
% Anyway, the solutions are similar in terms of residual, it can be observed that both are close to the true solution, because the value $A^{T}Ax - A^{T}b$ for the CG method and $Q^{T}(Ax - b)$ for the QR method are close to zero for both, but the residual is big anyway.
%\begin{table}[h!]
%    \begin{center}
%        \caption{Maximum problem size with 4 GB of RAM, n independent and m dependent}
%        \label{tab:table5}
%        \begin{tabular}{l|c|c|c|r}
%            \textbf{} & \textbf{n = 10} & \textbf{n = 100} & \textbf{n = 1000} & \textbf{n = 10000}\\
%            \hline
%            \textbf{CG max m} & $50 \times 10^{6}$ & $50 \times 10^{5}$ & $50 \times 10^{4}$ & $50 \times 10^{3}$\\
%            \textbf{QR max m} & $\sim 500 \times 10^{6}$ & $\sim 500 \times 10^{6}$ & $\sim 500 \times 10^{6}$ & $\sim 500 \times 10^{6}$
%        \end{tabular}
%    \end{center}
%\end{table}
\subsection{Computational cost}\label{subsec:computational-cost}
The computational cost of the QR method scales linearly with the largest dimension $m$ of the matrix $A$ of the ML-cup as expected [figure~\ref{qr_cost}].
By looking at the plots, we see that the QR methods scales quadratically for square matrices [figure~\ref{square}], almost linearly for $m>n$ [figure~\ref{little_m}] and linearly for $m\gg n$ [figure~\ref{big_m}] as expected.
In all the 3 cases, CG outperform QR in terms of time.
         \begin{figure}
		\centering
		\begin{subfigure}{.5\textwidth}
  		\centering
 		 \includegraphics[width=\textwidth]{../results/cg_accuracy.png}
  		\caption{convergence of our problem}
  		\label{cg_acc1}
		\end{subfigure}%
		\begin{subfigure}{.5\textwidth}
 		 \centering
 		 \includegraphics[width=\textwidth]{../results/cg_accuracy_rand.png}
 		 \caption{convergence of a random problem}
 		 \label{cg_acc2}
		\end{subfigure}
		\caption{CG accuracy: number of iterations required to get a specific accuracy value }
		\label{cg_acc}
	\end{figure}
	\begin{figure}
            \includegraphics[width=\linewidth]{../results/cg_x0_ite.png}
            \caption{CG with different starting points and with an accuracy of $10^{-11}$, the red star is the 0 vector}
             \label{cg_x0}
       \end{figure}
         \begin{figure}
            \includegraphics[width=\linewidth]{../results/qr_linear_scaling.png}
            \caption{QR computational time: time required to solve the ML-cup LS problem with the first m rows of A}
             \label{qr_cost}
        \end{figure}
        \begin{figure}
            \includegraphics[width=\linewidth]{../results/square.png}
            \caption{QR and CG methods: Computational time w.r.t.\ dimension n for square matrix $n \times n$}
            \label{square}
        \end{figure}
        \begin{figure}
            \includegraphics[width=\linewidth]{../results/little_m.png}
            \caption{QR and CG methods: Computational time w.r.t.\ dimension m for tall thin matrix $m \times n$ with $m > n$}
            \label{little_m}
        \end{figure}
        \begin{figure}
            \includegraphics[width=\linewidth]{../results/big_m.png}
            \caption{QR and CG methods: Computational time w.r.t.\ dimension m for tall thin matrix mxn with $m \gg n$}
            \label{big_m}
        \end{figure}

\section{Conclusion}\label{sec:conclusion}
Both QR and CG methods did solve the high conditioned LS problem of ML-cup, but the QR method is three order of magnitude more accurate and, as opposite as CG method, it doesn't require an initial point, a formula for $\beta$ and a number of iteration.
Anyway, the CG method was $\sim 2$ times faster than the QR one, and it is more suitable for large problem because the space it needs is $O(n+m)$ instead of $O(nm)$ ($O(n)$ and $O(n^{2}$) respectively for square matrices).
Finally, to reduce the condition number of the problem and hence to get a more accurate result with the CG method, it would be possible to apply the preconditioning technique.

\bibliography{bibliography}
\bibliographystyle{unsrt}

\end{document}


\section{Node Leaf intersections Lumberyard Interior}

%this file needs luberyard interior and exterior N4L1-16 and N8L1-16

\pgfplotsset{
	every axis/.append style={colorbar = false},
}

simple visualization of the table Lumberyard interior.
Reminder: Node intersection is when a ray might hit a node and all the Aabbs inside this node are tested. Aabb intersections are the exact number how often we do a ray aabb test.

\begin{figure}[!htb]
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y = primaryNodeIntersections, col sep=comma]{Data/amazonLumberyardInteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y = primaryLeafIntersections, col sep=comma]{Data/amazonLumberyardInteriorTable.txt};

		\legend{Node intersections, Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		%ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		%x expr = \thisrow{subdivision}
		\addplot+[thick, mark=none]table[x = leafSize, y =primaryNodeIntersections, col sep=comma]{Data/amazonLumberyardInteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryLeafIntersections} * 4, col sep=comma]{Data/amazonLumberyardInteriorTable.txt};

		\legend{Node intersections, 4 * Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\caption{Node and Leaf Intersections}
\end{figure}

\begin{figure}[!htb]
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y = primaryAabb, col sep=comma]{Data/amazonLumberyardInteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y = primaryPrimitive, col sep=comma]{Data/amazonLumberyardInteriorTable.txt};

		\legend{Aabb intersections, Triangle intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		%x expr = \thisrow{subdivision}
		\addplot+[thick, mark=none]table[x = leafSize, y =primaryAabb, col sep=comma]{Data/amazonLumberyardInteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryPrimitive} * 4, col sep=comma]{Data/amazonLumberyardInteriorTable.txt};

		\legend{Aabb intersections, 4 * Triangle intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\caption{Aabb and Triangle intersections}
\end{figure}

\newpage

Numbers normalized by the sum of Node Intersection + Leaf Intersection of the specific Leaf size.

\begin{figure}[!htb]
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryNodeIntersections} / ( \thisrow{primaryNodeIntersections} + \thisrow{primaryLeafIntersections}), col sep=comma]{Data/amazonLumberyardInteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryLeafIntersections} / ( \thisrow{primaryNodeIntersections} + \thisrow{primaryLeafIntersections}), col sep=comma]{Data/amazonLumberyardInteriorTable.txt};

		\legend{Node intersection, Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		%ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		%x expr = \thisrow{subdivision}
		\addplot+[thick, mark=none]table[x = leafSize,  y expr = \thisrow{primaryNodeIntersections} / ( \thisrow{primaryNodeIntersections} + \thisrow{primaryLeafIntersections} * 4), col sep=comma]{Data/amazonLumberyardInteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize,  y expr = \thisrow{primaryLeafIntersections} * 4 / ( \thisrow{primaryNodeIntersections} + \thisrow{primaryLeafIntersections} * 4), col sep=comma]{Data/amazonLumberyardInteriorTable.txt};

		\legend{Node intersections, 4 * Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\caption{Node and Leaf Intersections normalized}
\end{figure}

\begin{figure}[!htb]
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryAabb} / ( \thisrow{primaryAabb} + \thisrow{primaryPrimitive}), col sep=comma]{Data/amazonLumberyardInteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryPrimitive} / ( \thisrow{primaryAabb} + \thisrow{primaryPrimitive}), col sep=comma]{Data/amazonLumberyardInteriorTable.txt};

		\legend{Node intersection, Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		%ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		%x expr = \thisrow{subdivision}
		\addplot+[thick, mark=none]table[x = leafSize,  y expr = \thisrow{primaryAabb} / ( \thisrow{primaryAabb} + \thisrow{primaryPrimitive} * 4), col sep=comma]{Data/amazonLumberyardInteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize,  y expr = \thisrow{primaryPrimitive} * 4 / ( \thisrow{primaryAabb} + \thisrow{primaryPrimitive} * 4), col sep=comma]{Data/amazonLumberyardInteriorTable.txt};

		\legend{Node intersections, 4 * Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\caption{Aabb and Triangle intersections normalized}
\end{figure}

\newpage

Now to the intersection success ratio. (how many of the triangle tests where positive). For Nodes its always about 0.3 (mostly affected by branching factor)

\begin{figure}[!htb]
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Success ratio,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y = primaryTriangleSuccessRatio, col sep=comma]{Data/amazonLumberyardInteriorTable.txt};

		\legend{Triangle success ratio}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Successfull Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryTriangleSuccessRatio} * \thisrow{primaryPrimitive}, col sep=comma]{Data/amazonLumberyardInteriorTable.txt};

		\legend{Number triangle hits}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
\end{figure}

So when we increase the leafsize we also get a bit more positive hits, but i think those hits are mostly within one leaf node.

\section{Node Leaf intersections Lumberyard Exterior}

Same as above but nor for the lumberyard exterior scene. The results are very similar and the lines would mostly overlap when in one graph.

\begin{figure}[!htb]
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y = primaryNodeIntersections, col sep=comma]{Data/amazonLumberyardExteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y = primaryLeafIntersections, col sep=comma]{Data/amazonLumberyardExteriorTable.txt};

		\legend{Node intersections, Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		%ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		%x expr = \thisrow{subdivision}
		\addplot+[thick, mark=none]table[x = leafSize, y =primaryNodeIntersections, col sep=comma]{Data/amazonLumberyardExteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryLeafIntersections} * 4, col sep=comma]{Data/amazonLumberyardExteriorTable.txt};

		\legend{Node intersections, 4 * Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\caption{Node and Leaf Intersections}
\end{figure}

\begin{figure}[!htb]
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y = primaryAabb, col sep=comma]{Data/amazonLumberyardExteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y = primaryPrimitive, col sep=comma]{Data/amazonLumberyardExteriorTable.txt};

		\legend{Aabb intersections, Triangle intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		%x expr = \thisrow{subdivision}
		\addplot+[thick, mark=none]table[x = leafSize, y =primaryAabb, col sep=comma]{Data/amazonLumberyardExteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryPrimitive} * 4, col sep=comma]{Data/amazonLumberyardExteriorTable.txt};

		\legend{Aabb intersections, 4 * Triangle intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\caption{Aabb and Triangle intersections}
\end{figure}

\newpage

\begin{figure}[!htb]
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryNodeIntersections} / ( \thisrow{primaryNodeIntersections} + \thisrow{primaryLeafIntersections}), col sep=comma]{Data/amazonLumberyardExteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryLeafIntersections} / ( \thisrow{primaryNodeIntersections} + \thisrow{primaryLeafIntersections}), col sep=comma]{Data/amazonLumberyardExteriorTable.txt};

		\legend{Node intersection, Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		%ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		%x expr = \thisrow{subdivision}
		\addplot+[thick, mark=none]table[x = leafSize,  y expr = \thisrow{primaryNodeIntersections} / ( \thisrow{primaryNodeIntersections} + \thisrow{primaryLeafIntersections} * 4), col sep=comma]{Data/amazonLumberyardExteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize,  y expr = \thisrow{primaryLeafIntersections} * 4 / ( \thisrow{primaryNodeIntersections} + \thisrow{primaryLeafIntersections} * 4), col sep=comma]{Data/amazonLumberyardExteriorTable.txt};

		\legend{Node intersections, 4 * Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\caption{Node and Leaf Intersections normalized}
\end{figure}

\begin{figure}[!htb]
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryAabb} / ( \thisrow{primaryAabb} + \thisrow{primaryPrimitive}), col sep=comma]{Data/amazonLumberyardExteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryPrimitive} / ( \thisrow{primaryAabb} + \thisrow{primaryPrimitive}), col sep=comma]{Data/amazonLumberyardExteriorTable.txt};

		\legend{Node intersection, Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		%ylabel = Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		%x expr = \thisrow{subdivision}
		\addplot+[thick, mark=none]table[x = leafSize,  y expr = \thisrow{primaryAabb} / ( \thisrow{primaryAabb} + \thisrow{primaryPrimitive} * 4), col sep=comma]{Data/amazonLumberyardExteriorTable.txt};
		\addplot+[thick, mark=none]table[x = leafSize,  y expr = \thisrow{primaryPrimitive} * 4 / ( \thisrow{primaryAabb} + \thisrow{primaryPrimitive} * 4), col sep=comma]{Data/amazonLumberyardExteriorTable.txt};

		\legend{Node intersections, 4 * Leaf intersections}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\caption{Aabb and Triangle intersections normalized}
\end{figure}

\begin{figure}[!htb]
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Success ratio,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y = primaryTriangleSuccessRatio, col sep=comma]{Data/amazonLumberyardExteriorTable.txt};

		\legend{Triangle success ratio}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
	\begin{minipage}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}
		[
		%view={90}{0} for x, view={0}{0} for y restriction
		view={0}{0},
		xlabel = Leaf size,
		ylabel = Successfull Intersections,
		cycle list name = linestyles*,
		legend style={at={(0.05,1.25)}, anchor = north west},
		%xtick = {0, 2, ..., 20},
		%xticklabels={$8$,$16$,$24$,$32$,$40$,$48$,$56$,$64$,$72$,$80$,$88$,$96$,$104$,$112$,$120$,$128$},
		]
		\addplot+[thick, mark=none]table[x = leafSize, y expr = \thisrow{primaryTriangleSuccessRatio} * \thisrow{primaryPrimitive}, col sep=comma]{Data/amazonLumberyardExteriorTable.txt};

		\legend{Number triangle hits}
		\end{axis}
		\end{tikzpicture}
	\end{minipage}
\end{figure}


\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{physics}
\usepackage{circuitikz}
\setlist[enumerate]{itemsep=1pt,topsep=2pt}
\setlist[itemize]{itemsep=1pt,topsep=2pt}
%--------------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{April 6, 2017} % put lecture date here
\def\scribe{Scribe: Henry Cooney} % put your name here
\def\lecnum{2} % change the lecture number
\lecture{\lecnum}{\lecdate}{\prof}{\scribe}%

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

%==============================%
\section{The tensor product}
%==============================%

Recall that we may represent bits as probability vectors. For example, suppose we have $u, v$ and:

\begin {align}
u &= \begin{bmatrix}
	3/4 \\
	1/4
\end{bmatrix} \\
v &= \begin{bmatrix}
	1/3 \\
	2/3
\end{bmatrix}
\end{align}

Then the \textit{tensor product} of u and v, denoted $u \otimes v$, is the vector:

\begin {align}
u \otimes v &= \begin{bmatrix}
	1/4 \\
	1/2 \\
	1/12 \\
	1/6
\end{bmatrix} \\
\end{align}

The tensor product is used to represent the \textit{joint probability} of multiple bits in a single vector. Each row simply corresponds to the probability of that bit combination: for example the probability that u is 1, and v is 0, is the element $(u \otimes v)_{10}$, which is 1/12.

\subsection{Computing the Tensor Product}

Suppose we have an $m \times n$ matrix A, and a $k \times l$ matrix B. So:

\begin {align}
A &= \begin{bmatrix}
	a_{11} & \dots & a_{1n} \   \\
	\vdots & \ddots & \vdots \\
	a_{m1} & \dots & a_{mn}
\end{bmatrix} \\
B &= \begin{bmatrix}
	b_{11} & \dots & b_{1k} \   \\
	\vdots & \ddots & \vdots \\
	b_{l1} & \dots & b_{lk}
\end{bmatrix} \\
\end{align}

The tensor product is computed by multiplying each element of A with the entire matrix B, and tiling the the result. So:

\begin {align}
A \otimes B &= \begin{bmatrix}
	a_{11} B & \dots & a_{1n} B \   \\
	\vdots & \ddots & \vdots \\
	a_{m1} B & \dots & a_{mn} B
\end{bmatrix} \\
\end{align}

Thus, the dimension of $A \otimes B$ is $mk \times nl$.

So, for example, the tensor product of u and v, used above, is calculated as follows:

\begin {align}
u \otimes v &= \begin{bmatrix}
	3/4 \begin{bmatrix} 1/3 \\ 2/3 \end{bmatrix} \\
	1/4 \begin{bmatrix} 1/3 \\ 2/3 \end{bmatrix}
\end{bmatrix}  \\
	&= 	\begin{bmatrix}
		1/4 \\
		1/2 \\
		1/12 \\
		1/6
	\end{bmatrix}
\end{align}

\subsection {Properties of the Tensor Product}

A few tensor product properties:

\begin{enumerate}
	\item
	Distributive: $A \otimes (B + C) = A \otimes B + A \otimes C$
	\item
	You can move a scalar around: $(\alpha A) \otimes B = A \otimes (\alpha B) = \alpha(A \oplus B)$
	\item
	Preserves unitary-ness: if u and v are unitary, $u \otimes v$ is unitary.
	\item
	NOT commutative!! It is not always true that $A \otimes B = B \otimes A$.
\end{enumerate}
% \\\\
Another interesting property is that there are some vectors that cannot be written as a tensor product. For example, for the following vector x:

\begin {align}
x &= \begin{bmatrix}
	1/2 \\
	0 \\
	0 \\
	1/2
\end{bmatrix}
\end{align}

There is no pair of vectors u and v such that $u \otimes v = x$. In this case, we say that u and v are \textit{correlated}. Only uncorrelated systems may be written as a tensor product. This will be an important property later.

\subsection{Tensor produces with qubits}

We can use similarly use tensor products to describe associated probabilities on qubits. Suppose X and Y are qubits such that:

\begin {align}
X: \ket{\phi} = \alpha \ket{0} + \beta \ket{1} =	\begin{bmatrix}
	\alpha \\
	\beta
\end{bmatrix} \\
Y: \ket{\psi} = \gamma \ket{0} + \delta \ket{1} =	\begin{bmatrix}
	\gamma \\
	\delta
\end{bmatrix}
\end{align}

Note: this is using Dirac notation, covered in Lecture 1 -- or p. 10 of the Watrous notes (link on main course page).

So, what is the state of the joint system? We can compute the tensor product to find out:

\begin {align}
X: \ket{\phi} \otimes \ket{\psi} = \begin{bmatrix}\alpha \\ \beta \end{bmatrix} \otimes \begin{bmatrix} \gamma \\ \delta \end{bmatrix} = \begin{bmatrix} \alpha \gamma \\ \alpha \delta \\ \beta \gamma \\ \beta \delta \end{bmatrix} \\
\end{align}

This can equivalently be written as:

\begin {align}
\ket{\phi} \otimes \ket{\psi} = (\alpha \ket{0} + \beta \ket{1}) \otimes (\gamma \ket{0} + \delta \ket{1}) \\
& = \alpha \gamma (\ket{0} \otimes \ket{0}) + \alpha \delta (\ket{0} \otimes \ket{1}) + \beta \gamma (\ket{1} \otimes \ket{0}) + \beta \delta (\ket{1} \otimes \ket{1})
\end{align}

\section{Multiple Qubits and Dirac Notation}

Above, we ended up with the long expression, $\alpha \gamma (\ket{0} \otimes \ket{0}) + \alpha \delta (\ket{0} \otimes \ket{1}) + \beta \gamma (\ket{1} \otimes \ket{0}) + \beta \delta (\ket{1} \otimes \ket{1})$. Why write it this way? As it turns out, vectors like $\ket{0} \otimes \ket{1}$ form an orthonormal basis. There is a special notation for these vectors -- for example, $\ket{00} = \ket{0} \otimes \ket{0}$. We can also denote the tensor product of any two states $\phi$ and $\psi$ as follows: $\phi \otimes \psi = \ket{\phi} \ket{\psi}$.

\break
So, our four basic states that can result from $\ket{0}$ and $\ket{1}$ (and thus the orthonormal basis for 2-bit systems) are:

\begin {align}
\ket{00} &= \begin{bmatrix}
	1 \\
	0 \\
	0 \\
	0
\end{bmatrix} \\
\ket{01} &= \begin{bmatrix}
	0 \\
	1 \\
	0 \\
	0
\end{bmatrix} \\
\ket{10} &= \begin{bmatrix}
	0 \\
	0 \\
	1 \\
	0
\end{bmatrix} \\
\ket{11} &= \begin{bmatrix}
	0 \\
	0 \\
	0 \\
	1
\end{bmatrix}
\end{align}

These allow us to write certain superpositions more compactly using Dirac notation. For example:

\begin {align}
\frac{1}{\sqrt{2}} (\ket{00} + \ket{11}) =   \begin{bmatrix}
	\frac{1}{\sqrt{2}} \\
	0 \\
	0 \\
	\frac{1}{\sqrt{2}}
\end{bmatrix}
\end{align}

Note that the superposition above is one of the special vectors which \textit{cannot be written as a tensor product}. A superposition which cannot be written as a tensor product is called \textit{entangled}. A superposition that can be written as a tensor product is called a \textit{product state}. Entangled superpositions will be important in the future. An pair of entangled qubits is also called an \textit{EPR pair}. \\

As mentioned above, $\ket{00}$, $\ket{01}$, $\ket{10}$, and $\ket{11}$ form an orthonormal basis for $\mathbb{C}^4$.  More bits would mean an orthonormal basis for a higher-dimensional space. For example, suppose we have n qubits. Then: \\

\begin{align}
\{ \ket{0 ... 0} ... \ket{1...1} \}
\end{align}

Is the basis for $(\mathbb{C}^2)^n$, with dimensions $2^n$.

\section {Circuit Models}

\subsection {Classical Circuit Models}

Circuit models represent computation as a network of logical gates. This model is equivalent in power to a Turing machine.\\

Some basic gates are and, or, and not:
\\

And:
\[
\Qcircuit @C=1em @R=0em {
	& \multigate{1}{\land} & \qw \\
	& \ghost{\land}
}
\]

Or:
\[
\Qcircuit @C=1em @R=0em {
		& \multigate{1}{\lor} & \qw \\
		& \ghost{\lor}
}
\]

Not:
\[
\Qcircuit @C=1em @R=0em {
		& \gate{\lnot} & \qw
}
\]

These make a very powerful combination. A circuit with s gates maybe converted to a Turing machine that runs in $O(s \log{s})$ time. Similarly, a Turing machine that that runs in time t can be converted to a circuit with $O(t \log{t})$ gates.
One thing which classical circuits often lack is \textit{randomness}. Therefore, we also introduce the 'coin flip' gate, which randomly outputs 0 or 1:

% \\

Coin flip:
\[
\Qcircuit @C=1em @R=0em {
	& \boxed{\$} \quad& \qw
}
\]

We can use this to make a more interesting circuit:

\[
\Qcircuit @C=1em @R=1em {
	& \boxed{\$} \quad & \ctrl{1} & \qw & x \\
	& 1 \ & \gate{\land} & \qw & y
}
\]

This circuit outputs either 11 or 00, each with probability 1/2.

\subsection{Quantum Circuits}

Quantum gates are different from classical circuit gates. Instead, they correspond to the unitary Pauli operators:
\\

The X operator:

\begin {align}
X &= \begin{bmatrix}
	0 & 1 \\
	1 & 0
\end{bmatrix}
\end{align}

\[
\Qcircuit @C=1em @R=0em {
	& \gate{X} & \qw
}
\]

The Y operator:

\begin {align}
Y &= \begin{bmatrix}
	0 & -i \\
	i & 0
\end{bmatrix}
\end{align}

\[
\Qcircuit @C=1em @R=0em {
& \gate{Y} & \qw
}
\]

The Z operator:

\begin {align}
Z &= \begin{bmatrix}
	1 & 0 \\
	0 & -1
\end{bmatrix}
\end{align}

\[
\Qcircuit @C=1em @R=0em {
& \gate{Z} & \qw
}
\]

The Identity operator:

\[
\Qcircuit @C=1em @R=0em {
	& \gate{I} & \qw
}
\]

Finally, the Hadamard Operator:
\begin {align}
Z &= \begin{bmatrix}
	\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\
	\frac{1}{\sqrt{2}} & \frac{-1}{\sqrt{2}}
\end{bmatrix}
\end{align}

We can also create 2-qubit gates by taking two 1-qubit gates and applying the tensor product to their matrices. Not that, as per the rules of the tensor product, this will yield a 4x4 matrix.

\subsection{More Interesting Gates}

A more interesting gate is the 'controlled not' gate, or CNOT. It has the following matrix:

\begin {align}
CNOT &= \begin{bmatrix}
	1 & 0 & 0 & 0 \\
	0 & 1 & 0 & 0 \\
	0 & 0 & 0 & 1 \\
	0 & 0 & 1 & 0
\end{bmatrix}
\end{align}

CNOT takes as input a 'control' qubit and a 'target' qubit. The control qubit will pass through unchanged, but the target will be xored with the control. So, if the control is a and the target is b, CNOT will output a and $a \oplus b$. CNOT has a special circuit diagram, shown below:

\[
\Qcircuit @C=1em @R=1em {
	 & \lstick{a} & \qw & \ctrl{1} & \qw & \rstick{a}  \\
	 & \lstick{b} & \qw & \targ & \qw & \rstick{a \oplus b}
}
\]

For the basic 2-bit states, the output of CNOT looks like this:

\begin{align}
CNOT \ket{00} = \ket{00} \\
CNOT \ket{01} = \ket{01} \\
CNOT \ket{10} = \ket{11} \\
CNOT \ket{11} = \ket{10}
\end{align}

Note that, if the first bit is 1, the second bit is flipped -- as one would expect for an xor-like operation.

Another complex gate is the Tofolli gate. This takes 3 input qubits, a, b, and c, and changes c to $c \oplus (a \land b)$. You can look up the matrix, but the Toffoli gate circuit looks like this:
\[
\Qcircuit @C=1em @R=1em {
	& \lstick{a}  & \ctrl{1} &  \rstick{a} \qw  \\
	& \lstick{b}  & \ctrl{1} &  \rstick{b} \qw  \\
	& \lstick{c}  & \targ &  \rstick{c \oplus (a \land b)}\qw
}
\]

A final unique gate type is the Measure gate. This represents actually measuring the qubit, collapsing it to a classical value. It's represented by a meter symbol:

\[
\Qcircuit @C=1em @R=0em {
	& \meter & \qw
}
\]

\subsection {An Example Quantum Circuit}

\[
\Qcircuit @C=1em @R=1em {
	& \lstick{\ket{0}} & \gate{H} & \ctrl{1} & \meter & \qw  \\
	& \lstick{\ket{0}} & \qw      & \targ  & \meter & \qw
}
\]

The possible outputs of this circuit are 00 and 11, each with probability 1/2. Note that, just before measurement, the state of the qubits is $\frac{1}{\sqrt{2}} (\ket{00} + \ket{11})$ -- the entangled state that was mentioned in equation (21). So, this circuit makes use of an EPR pair!

\subsection{Partial measurement}

Suppose we have the following quantum circuit:

\[
\Qcircuit @C=1em @R=1em {
	& \lstick{\ket{0}} & \multigate{1}{QCKT} & \meter & \qw  \\
	& \lstick{\ket{0}} & \ghost{QCKT}        & \qw    & \qw
}
\]

Here, QCKT is some arbitrary quantum circuit. Suppose we want to know the state of the qubits just before the measurement is taken, which will will call $\ket{\phi}$. Then we could write this as:

\begin{align}
\ket{\phi} = \alpha_{00}\ket{00} + \alpha_{01}\ket{01} + \alpha_{10}\ket{10} + \alpha_{11}\ket{11}
\end{align}

So, the probability of seeing a 0 in the first bit is:

\begin{align}
	|\alpha_{00}|^2 + |\alpha_{01}|^2
\end{align}

And the probability of seeing 1 in the first bit is:

\begin{align}
|\alpha_{10}|^2 + |\alpha_{11}|^2
\end{align}

However, this is BEFORE measurement. After measurement, the probability on the other bit will change -- measuring the first bit gives you additional information about the second. Suppose you measure 0 for bit 1. Then bit 1's state is now:

\begin{align}
\frac{\alpha_{00}\ket{0} + \alpha_{01}\ket{1}} {\sqrt{|\alpha_{00}|^2 + |\alpha_{01}|^2 }}
\end{align}

And, if 1 is measured for bit 1, bit 2's state is:

\begin{align}
\frac{\alpha_{10}\ket{0} + \alpha_{11}\ket{1}} {\sqrt{|\alpha_{10}|^2 + |\alpha_{11}|^2 }}
\end{align}

Note that we must divide by the square root term to normalize the probabilities, so they still add up to one.
A final note -- the order in which measurements are performed does NOT affect the output probabilities. You may measure in any order and still get the same result.

\end{document}


\subsection{Uniform spaces}\label{subsec:uniform_spaces}

\begin{remark}\label{rem:entourage_notation}
  \hyperref[def:uniform_space]{Uniform spaces} are an extension of both \hyperref[def:metric_space]{metric spaces} and \hyperref[def:topological_group]{topological groups} (including \hyperref[def:topological_vector_space]{topological vector spaces}). They are topological spaces that are \enquote{uniform} in the sense that different parts of the space behave the same, unlike \hyperref[def:topological_manifold]{manifolds}.

  In metric spaces, we use the notation \( \mu(x, y) < \varepsilon \) to mean that \( x \) and \( y \) are close (at a distance less than \( \varepsilon \)).

  In (\hyperref[rem:additive_magma]{additive}) topological groups, we instead have linear operations and use \( x - y \in U \) to mean that \( x \) and \( y \) are close (their difference belongs to some neighborhood of \( 0 \)).

  A proper generalization needs to make both metric spaces and topological groups feel natural as special cases. Generalizing metric space \hyperref[def:metric_space/ball]{balls} or neighborhoods of \hyperref[thm:origin_neighborhoods_in_topological_groups]{zero} are nice options which unfortunately introduces some asymmetry since, for example for metric spaces, \( \mu(x, y) < \varepsilon \) can be written as either \( y \in B(x, \varepsilon) \) or \( x \in B(y, \varepsilon) \). This approach does not go far beyond what general topological spaces offer as a notation.

  \cite[section 8]{Engelking1989} uses the notation \( \abs{x - y} < V \) to mean that \( x \) and \( y \) belong to the \hyperref[def:entourage]{entourage} \( V \). This is a bit confusing because no absolute \hyperref[def:absolute_value]{value} nor subtraction are defined in uniform spaces. We find it simpler to not introduce any special notation beyond that of \hyperref[def:relation]{relations} and, so we denote the same by \( (x, y) \in V \).
\end{remark}

\begin{definition}\label{def:entourage}\mcite[sec. 8.1]{Engelking1989}
  Let \( X \) be a set. For two binary \hyperref[def:relation]{relations} \( V \) and \( U \) on \( X \) we define their sum as
  \begin{equation*}
    V + U \coloneqq \{ (x, z) \colon \exists y \in X: (x, y) \in U, (y, z) \in V \}
  \end{equation*}
  and \( nV \) by \( n \)-fold iterative addition.

  For any relation \( V \), we denote by \( -V \) the \hyperref[def:binary_relation/converse]{inverse relation}.

  A relation \( V \) on \( X \) is called an \term{entourage} if \( V \) is \hyperref[def:binary_relation/reflexive]{reflexive} and \hyperref[def:binary_relation/symmetric]{symmetric}.

  In analogy to \hyperref[def:metric_space]{metric spaces}, we define
  \begin{thmenum}
    \thmitem{def:entourage/ball} We define the \term{open ball} or simply \term{ball} with \term{center} \( x \) and \term{radius} \( V \) to be the set
    \begin{equation*}
      B(x, V) \coloneqq \{ y \in X \colon (y, x) \in V \}.
    \end{equation*}

    \thmitem{def:entourage/bounded_set} We say that the set \( S \subseteq X \) is \term{bounded} if it is contained in some ball.
  \end{thmenum}
\end{definition}

\begin{proposition}\label{thm:entourage_simulates_metric}\mcite[sec. 8.1]{Engelking1989}
  Using the notation of \fullref{def:entourage}, we obtain properties similar to those of metrics:
  \begin{thmenum}
    \refitem{def:metric_space/M1} \( (x, x) \in V \)
    \refitem{def:metric_space/M2} \( (x, y) \in V \) if and only if \( (y, x) \in V \)
    \refitem{def:metric_space/M3} If \( (x, y) \in U \) and \( (y, z) \in V \), then \( (x, y) \in U + V \).
  \end{thmenum}
\end{proposition}

\begin{definition}\label{def:uniform_space}\mcite[sec. 8.1]{Engelking1989}
  A \term{uniform space} is a set \( X \) with a nonempty family \( \mscrV \) of \hyperref[def:entourage]{entourages} on \( X \) such that
  \begin{thmenum}
    \thmitem[def:uniform_space/U1]{U1} If \( V \in V \) and \( V \subseteq W \) for some entourage \( W \) on \( X \), then \( W \in V \).
    \thmitem[def:uniform_space/U2]{U2} If \( V_1, V_2 \in V \), then \( V_1 \cap V_2 \in V \).
    \thmitem[def:uniform_space/U3]{U3} For every \( V \in V \) there exists \( W \in V \) such that \( 2W \subseteq V \).
    \thmitem[def:uniform_space/U4]{U4} \( \bigcap \mscrV = \Delta_X \), where \( \Delta_X \) is the \hyperref[def:binary_relation/diagonal]{diagonal relation}.
  \end{thmenum}

  The family \( \mscrV \) is called a \term{uniform structure} or \term{uniformity} on \( X \).
\end{definition}

\begin{definition}\label{def:uniform_topology}
  Let \( (X, \mscrV) \) be a \hyperref[def:uniform_space]{uniform space}. We define its \term{uniform topology} or \term{induced topology} as the \hyperref[def:topological_space]{topology} generated by the \hyperref[def:topological_local_base]{neighborhood system}
  \begin{equation*}
    \mathcal{B}(x) \coloneqq \{ B(x, V) \colon V \in V \}.
  \end{equation*}

  If for some topological space \( (X, \mscrT) \) there exists a uniformity such that \( \mscrT \) is its induced topology, we say that the topology \( \mscrT \) is \term{uniformizable}.
\end{definition}
\begin{proof}
  This proof of correctness does not actually rely on the uniform structure (except for \( \mscrV \) being nonempty), but rather on the properties of entourages.

  It is indeed a neighborhood system because
  \begin{refenum}
    \refitem{thm:topological_local_base_axioms/BP1} Every \hyperref[def:entourage]{entourage} is reflexive, hence \( x \) is contained in every ball in \( \mathcal{B}(x) \).

    \refitem{thm:topological_local_base_axioms/BP2} For \( B(x, U) \) and \( B(x, V) \) we have
    \begin{balign*}
      B(x, U \cap V)
       & =
      \{ y \in X \colon (x, y) \in U \cap V \}
      =    \\ &=
      \{ y \in X \colon (x, y) \in U \text{ and } (x, y) \in V \}
      =    \\ &=
      B(x, U) \cap B(x, V).
    \end{balign*}

    \refitem{thm:topological_local_base_axioms/BP3} Fix \( x, y \in X \) and a ball \( B(y, V) \in \mathcal{B}(y) \) that contains \( x \). We will show that \( B(y, V) \subseteq B(x, 2V) \).

    Fix \( z \in B(y, V) \). We have \( (z, y) \in V \). Then \( (z, x) \in V + V = 2V \). Since \( z \in B(y, V) \) was arbitrary, we conclude that \( B(y, V) \subseteq B(x, 2V) \).
  \end{refenum}
\end{proof}

\begin{theorem}\label{thm:tychonoff_spaces_are_uniformizable}\mcite[thm. 8.1.20]{Engelking1989}
  A topological space is \hyperref[def:uniform_topology]{uniformizable} if and only if it is a \hyperref[def:sequential_space]{Tychonoff space}.
\end{theorem}

\begin{definition}\label{def:uniform_space_base}
  Fix a uniform space \( (X, \mscrV) \). The subfamily \( \mscrB \subseteq V \) if entourages is called a \term{base} for \( \mscrV \) if every entourage \( V \in V \) contains a member of \( \mscrV \).
\end{definition}

\begin{definition}\label{thm:uniform_space_base_axioms}\mcite[prop. 8.1.14]{Engelking1989}
  Let \( X \) be an arbitrary set and let \( \mscrB \) be a family of entourages satisfying the following axioms:
  \begin{thmenum}
    \thmitem[thm:uniform_space_base_axioms/BU1]{BU1} If \( V_1, V_2 \in B \), there exists an entourage \( V \in B \) such that \( V \subseteq V_1 \cap V_2 \).
    \thmitem[thm:uniform_space_base_axioms/BU2]{BU2} For every \( V \in B \) there exists \( W \in B \) such that \( 2W \subseteq V \).
    \thmitem[thm:uniform_space_base_axioms/BU3]{BU3} \( \bigcap \mscrB = \Delta_X \)
  \end{thmenum}

  Then the family of entourages
  \begin{balign}\label{thm:uniform_space_base_axioms/uniformity}
    \mscrV \coloneqq \left\{ V \subseteq X \times X \colon \exists B \in B: B \in V \T{and} V \text{ is reflexive and symmetric} \right\}
  \end{balign}
  is a uniform structure on \( X \). Furthermore, \( \mscrB \) is a \hyperref[def:uniform_space_base]{base} of \( \mscrV \).

  In particular, the base on any topology satisfies \fullref{thm:uniform_space_base_axioms/BU1} -- \fullref{thm:uniform_space_base_axioms/BU2}.
\end{definition}

\begin{lemma}\label{thm:uniform_space_neighborhood_contains_ball}
  In a uniform space \( (X, \mscrV) \), for every neighborhood \( A \) (in the topology) of a point \( x_0 \in X \) there exists an entourage \( V \in V \) such that \( B(x_0, V) \subseteq A \).
\end{lemma}
\begin{proof}
  By \fullref{def:uniform_topology} and \fullref{def:topological_base/union}, \( A \) is a union of balls centered at \( x_0 \). For any ball \( B(x_0, V) \) of this union, we have \( B(x_0, V) \subseteq A \).
\end{proof}

\begin{proposition}\label{thm:def:uniform_topology/properties}
  The \hyperref[def:uniform_topology]{uniform topology} \( \mscrT \) on \( (X, \mscrV) \) the following basic properties:
  \begin{thmenum}
    \thmitem{thm:def:uniform_topology/properties/ball_is_open} All \hyperref[def:entourage/ball]{balls} are open sets.
    \thmitem{thm:def:uniform_topology/properties/neighborhood_contains_ball} Every neighborhood of every point a ball centered at that point.
  \end{thmenum}
\end{proposition}
\begin{proof}
  \SubProofOf{thm:def:uniform_topology/properties/ball_is_open} We defined the balls to be the base of the uniform topology, therefore they are open.
  \refitem{thm:def:uniform_topology/properties/neighborhood_contains_ball} Fix a point \( x_0 \). It is a trivial consequence of \fullref{def:topological_base/subset} that every neighborhood of \( x_0 \) contains some ball centered at a point that is not necessarily \( x_0 \). By \fullref{thm:topological_local_base_axioms/BP3}, this ball contains another ball centered at \( x_0 \).
\end{proof}

\begin{proposition}\label{thm:uniform_space_local_convergence}
  Fix a topological space \( (X, \mscrT) \) and a uniform space \( (Y, \mscrU) \). Let \( A \subseteq X \) be a nonempty set and let \( f: A \to Y \) be a function. Then \( y_0 \) is a limit point of \( f \) at \( x_0 \in X \) in the sense of \fullref{def:local_continuity} if and only if
  \begin{equation}\label{thm:uniform_space_local_convergence/topological_source}
    \forall V \in V \ \exists A \in T(x_0) : x \in A \implies (f(x), y_0) \in V.
  \end{equation}

  If instead, \( (X, \mscrU) \) is a uniform space, then \( y_0 \) is a limit point of \( f \) at \( x_0 \in X \) if and only if
  \begin{equation}\label{thm:uniform_space_local_convergence/uniform_source}
    \forall V \in V \ \exists U \in U : (x, x_0) \in U \implies (f(x), y_0) \in V.
  \end{equation}

  Note that the limit point may not be unique because uniform spaces are not \hyperref[def:separation_axioms/T2]{Hausdorff} in general.
\end{proposition}
\begin{proof}
  We will only prove \fullref{thm:uniform_space_local_convergence/uniform_source} because the proof of \fullref{thm:uniform_space_local_convergence/topological_source} is a special case.

  \SufficiencySubProof Suppose that \( y_0 \) is a limit point of \( f \) at \( x_0 \) and fix a neighborhood \( B \) of \( y_0 \). Then there exists a neighborhood \( A \) of \( x_0 \) such that \( f(A) \subseteq B \).

  Fix an entourage \( V \in V \). Then \( B(y_0, V) \) is also a neighborhood of \( y_0 \). By \fullref{thm:uniform_space_neighborhood_contains_ball} and \fullref{def:uniform_space/U2}, there exists an entourage \( V' \subseteq V \) such that \( B(f(x), V') \subseteq B \cap B(y_0, V) \).

  Fix an entourage \( U \in U \) such that \( B(x_0, U) \subseteq A \). Then for any \( x \in X \), if \( (x, x_0) \in U \), we have \( (f(x), y_0) \in V' \). But \( V' \subseteq V \), therefore
  \begin{equation*}
    (x, x_0) \in U \implies (f(x), y_0) \in V.
  \end{equation*}

  This concludes the proof.

  \NecessitySubProof Fix a neighborhood \( B \) of \( y_0 \) and an entourage \( V \in V \) such that \( B(x_0, V) \subseteq B \) (see \fullref{thm:uniform_space_neighborhood_contains_ball} for a justification). Then there exists \( U \in U \) such that
  \begin{equation*}
    (x, x_0) \in U \implies (f(x), y_0) \in V.
  \end{equation*}

  Therefore, \( A \coloneqq B(x_0, U) \) is a neighborhood of \( x_0 \) such that \( f(A) \subseteq B \).
\end{proof}

\begin{corollary}\label{thm:uniform_space_local_continuity}
  A function \( f: (X, \mscrV) \to (Y, \mscrU) \) between uniform spaces is continuous at \( x_0 \in X \) if and only if
  \begin{equation*}
    \forall V \in V \ \exists U \in U : (x, x_0) \in U \implies (f(x), f(x_0)) \in V.
  \end{equation*}
\end{corollary}

\begin{definition}\label{def:bounded_function}
  Fix a set \( X \) and a \hyperref[def:uniform_space]{uniform space} \( (Y, \mscrV) \). Fix a function \( f: X \to Y \).

  \begin{thmenum}
    \thmitem{def:bounded_function/bounded} We say that the function \( f: X \to Y \) is \term{bounded} if \( f(X) \) is a bounded set, that is, if there exists a \hyperref[def:entourage/ball]{ball} \( B(y, V) \) such that \( f(X) \subseteq B(y, V) \).

    \thmitem{def:bounded_function/bounded_family} We say that the family of functions \( \mscrF \) from \( X \) to \( Y \) is \term{bounded} at \( x_0 \) if there exists a ball \( B(y, V) \) such that the set \( \mscrF(x_0) \coloneqq \{ f(x_0) \colon f \in F \} \) is contained in \( B(y, V) \).

    \thmitem{def:bounded_function/pointwise} We say that \( \mscrF \) is \term{pointwise bounded} on the set \( S \subseteq X \) if
    \begin{equation*}
      \forall x \in S \ \exists B(y, V) : \mscrF(x) \subseteq B(y, V).
    \end{equation*}

    \thmitem{def:bounded_function/uniform} We say that \( \mscrF \) is \term{uniformly bounded} on \( S \subseteq X \) if
    \begin{equation*}
      \exists B(y, V) \ \forall x \in S : \mscrF(x) \subseteq B(y, V).
    \end{equation*}

    \thmitem{def:bounded_function/locally_bounded} If there is a topology \( \mscrT \) on \( X \), we say that the function \( f: X \to Y \) is \term{locally bounded} if there exists an entourage \( V \in V \) such that for each neighborhood \( A \in T(x) \) we have \( \diam{f(A)} < V \).
  \end{thmenum}
\end{definition}

\begin{proposition}\label{thm:continuous_implies_locally_bounded}
  Let \( (X, \mscrT) \) be a topological space and \( (Y, \mscrV) \) be a uniform space. Any \hyperref[thm:uniform_space_local_convergence/topological_source]{continuous function} from \( X \) to \( Y \) is locally \hyperref[def:bounded_function/locally_bounded]{bounded}.
\end{proposition}
\begin{proof}
  Trivial.
\end{proof}

\begin{definition}\label{def:function_net_convergence}
  Fix a set \( X \) and a \hyperref[def:uniform_space]{uniform space} \( (Y, \mscrV) \). Let \( \{ f_k \}_{k \in \mscrK} \) be a \hyperref[def:topological_net]{net} of functions from \( X \) to \( Y \). We say that \( \{ f_k \}_{k \in \mscrK} \) \term{converges pointwise} to the function \( f \) and write \( f_k \to f \) if
  \begin{equation}\label{def:function_net_convergence/pointwise}
    \forall V \in V \ \underbrace{\forall x \in X \ \exists k_0 \in \mscrK} : k \geq k_0 \implies (f_k(x), f(x)) \in V
  \end{equation}
  and that \( \{ f_k \}_{k \in \mscrK} \) \term{converges uniformly} to \( f \) and write \( f_k \multto f \) if
  \begin{equation}\label{def:function_net_convergence/uniform}
    \forall V \in V \ \underbrace{\exists k_0 \in \mscrK \ \forall x \in X} : k \geq k_0 \implies (f_k(x), f(x)) \in V
  \end{equation}

  In the special case where \( X \) is a topological space with topology \( \mscrT \), we call the sequence \( \{ f_k \}_{k \in \mscrK} \) \term{locally uniformly convergent} (see \cite{ProofWiki:locally_uniform_convergence}) if every point in \( S \) has a neighborhood in which the sequence converges uniformly. Symbolically,
  \begin{equation}\label{def:function_net_convergence/locally_uniform}
    \forall V \in V \ \forall x_0 \in S \ \exists A \in T(x_0) \ \exists k_0 \in \mscrK \ \forall x \in A : k \geq k_0 \implies (f_k(x), f(x)) \in V.
  \end{equation}

  If the index \( k_0 \) does not depend on the neighborhood \( A \) and the point \( x_0 \), then this is equivalent to uniform convergence. It is still more powerful than pointwise convergence. For example, \hyperref[def:convergent_power_series]{power series} are locally uniformly convergent on the interior of their domain of convergence - see \fullref{thm:power_series_are_locally_uniform_convergent}.

  A slightly weaker notion is that of \term{compact convergence} (see \cite{ProofWiki:compact_convergence}), which is defined as uniform convergence on any compact subset. Symbolically,
  \begin{equation}\label{def:function_net_convergence/compact}
    \forall V \in V \ \forall \text{ compact } C \subseteq S \ \exists k_0 \in \mscrK \ \forall x \in C : k \geq k_0 \implies (f_k(x), f(x)) \in V.
  \end{equation}
\end{definition}

\begin{definition}\label{def:uniform_continuity}\mcite[435]{Engelking1989}
  Fix two \hyperref[def:uniform_space]{uniform spaces} \( (X, \mscrU) \) and \( (Y, \mscrV) \). We say that the function \( f: X \to Y \) if is \term{uniformly continuous} on the set \( S \subseteq X \) if
  \begin{equation}\label{def:uniform_continuity/uniform}
    \forall V \in V \ \underbrace{\exists U \in U \ \forall x_1, x_2 \in S} : (x_1, x_2) \in U \implies (f(x_1), f(x_2)) \in V.
  \end{equation}

  Compare this to \term{pointwise continuity} on \( S \), which is defined by \fullref{thm:uniform_space_local_convergence/uniform_source} as convergence for any \( x_1 \in X \):
  \begin{equation}\label{def:uniform_continuity/pointwise}
    \forall V \in V \ \underbrace{\forall x_1, x_2 \in S \ \exists U \in U} : (x_1, x_2) \in U \implies (f(x_1), f(x_2)) \in V.
  \end{equation}
\end{definition}

\begin{definition}\label{def:function_set_continuity}\mcite[285]{BouziadTroallic2004}
  Fix a topological space \( (X, \mscrT) \) and a \hyperref[def:uniform_space]{uniform space} \( (Y, \mscrV) \). We say that the family \( \mscrF \) of functions from \( X \) to \( Y \) is \term{functionwise continuous} at \( x_0 \in X \) if
  \begin{equation}\label{def:function_set_continuity/functionwise}
    \forall V \in V \ \underbrace{\forall f \in F \ \exists A \in T(x_0)} : f(A) \subseteq B(f(x_0), V),
  \end{equation}
  and \term{equicontinuous} at \( x_0 \in X \) if
  \begin{equation}\label{def:function_set_continuity/equicontinuous}
    \forall V \in V \ \underbrace{\exists A \in T(x_0) \ \forall f \in F} : f(A) \subseteq B(f(x_0), V).
  \end{equation}

  In the special case where \( (X, \mscrU) \) is a uniform space, then we can define \term{uniform equicontinuity} of the family \( \mscrF \) on the set \( S \subseteq X \) as
  \begin{equation}\label{def:function_set_continuity/uniform_equicontinuous}
    \forall V \in V \ \underbrace{\exists U \in U \ \forall f \in F \ \forall x_1, x_2 \in S} : (x_1, x_2) \in U \implies (f(x_1), f(x_2)) \in V
  \end{equation}

  Compare this to \term{pointwise equicontinuity} of \( \mscrF \) on \( S \), as defined by \fullref{def:function_set_continuity/equicontinuous} for all \( x_1, x_2 \in S \),
  \begin{equation}\label{def:function_set_continuity/pointwise_equicontinuous}
    \forall V \in V \ \underbrace{\forall x_1, x_2 \in S \ \exists U \in U \ \forall f \in F} : (x_1, x_2) \in U \implies (f(x_1), f(x_2)) \in V
  \end{equation}
  to \term{functionwise uniform continuity} of \( \mscrF \) on \( S \), which is defined by \fullref{def:uniform_continuity/uniform} for all \( f \in F \),
  \begin{equation}\label{def:function_set_continuity/uniform_functionwise}
    \forall V \in V \ \underbrace{\forall f \in F \ \exists U \in U \ \forall x_1, x_2 \in S} : (x_1, x_2) \in U \implies (f(x_1), f(x_2)) \in V
  \end{equation}
  and to \term{functionwise pointwise continuity} of \( \mscrF \) on \( S \), i.e. regular continuity as defined by \fullref{thm:uniform_space_local_continuity} for all \( x_1, x_2 \in S \) and all \( f \in F \),
  \begin{equation}\label{def:function_set_continuity/functionwise_pointwise}
    \forall V \in V \ \underbrace{\forall f \in F \ \forall x_1, x_2 \in S \ \exists U \in U} : (x_1, x_2) \in U \implies (f(x_1), f(x_2)) \in V
  \end{equation}
\end{definition}

\begin{proposition}\label{thm:uniform_limit_of_continuous_functions}
  \hfill
  \begin{thmenum}
    \thmitem{thm:uniform_limit_of_continuous_functions/continuous} A locally \hyperref[def:function_net_convergence]{uniform limit} of functions continuous at a \hyperref[thm:uniform_space_local_continuity]{point} is continuous at that point.
    \thmitem{thm:uniform_limit_of_continuous_functions/uniform} A uniform limit of functions uniformly \hyperref[def:uniform_continuity]{continuous} on a set is uniformly continuous on the set.
  \end{thmenum}
\end{proposition}
\begin{proof}
  The two proofs are similar, but have a lot of subtle differences.

  Fix uniform spaces \( (X, \mscrU) \) and \( (Y, \mscrV) \). Let \( \{ f_k \}_{k \in \mscrK} \) be a \hyperref[def:topological_net]{net} of functions from \( S \subseteq X \) to \( (Y, \mscrV) \).

  \SubProofOf{thm:uniform_limit_of_continuous_functions/continuous} Assume that the functions \( f_k, k \in \mscrK \) are continuous and that they converge to the function \( f \) locally \hyperref[def:function_net_convergence/locally_uniform]{uniformly}.

  Fix an entourage \( W \in V \) and use \fullref{def:uniform_space/U3} to obtain \( V \subseteq W \) such that \( 3V \subseteq W \).

  . and a point \( x_0 \in S \). Let \( A \) be a neighborhood of \( x_0 \). From locally \hyperref[def:function_net_convergence]{uniform convergence}, there exists an index \( k_0 \in \mscrK \) such that
  \begin{equation*}
    \forall k > k_0 \ \forall x \in A : (f_k(x), f(x)) \in V.
  \end{equation*}

  Fix \( k > k_0 \). From \hyperref[def:function_net_convergence/locally_uniform]{uniform continuity}, there exists an entourage \( U \in U \) such that
  \begin{equation*}
    \forall x \in S : (x, x_0) \in U \implies (f_k(x_0), f_k(x)) \in V.
  \end{equation*}

  Combining the last two inequalities, we note that for any \( x \in A \),
  \begin{itemize}
    \item \( (f(x_0), f(x)) \in V \),
    \item \( (f_k(x_0), f(x_0)) \in V \),
    \item \( (f_k(x), f(x)) \in V \),
  \end{itemize}
  thus by applying the triangle inequality in \fullref{thm:entourage_simulates_metric} twice, we obtain
  \begin{equation*}
    (f(x_0), f(x)) \in 3V \subseteq W \quad\forall x \in A \cap B(x_0, U).
  \end{equation*}

  Given an entourage \( W \in V \), we found a neighborhood \( A \cap B(x_0, U) \) of \( x_0 \) such that \fullref{thm:uniform_space_local_convergence/topological_source} is satisfied. Thus, \( f \) is continuous at \( x_0 \).

  \SubProofOf{thm:uniform_limit_of_continuous_functions/continuous} Assume that the functions \( f_k, k \in \mscrK \) are uniformly continuous and that they converge to \( f \) \hyperref[def:function_net_convergence/locally_uniform]{uniformly}.

  As in \fullref{thm:uniform_limit_of_continuous_functions/continuous}, fix entourages \( V, W \in V \) such that \( 3V \subseteq W \). From \hyperref[def:uniform_continuity]{uniform continuity},
  \begin{equation*}
    \forall k \in \mscrK \ \exists U \in U \ \forall x_1, x_2 \in S : (x_1, x_2) \in U \implies (f_k(x_1), f_k(x_2)) \in V.
  \end{equation*}

  From \hyperref[def:function_net_convergence]{uniform convergence}, there exists an index \( k_0 \in \mscrK \) such that
  \begin{equation*}
    \forall k > k_0 \ \forall x \in S : (f_k(x), f(x)) \in V.
  \end{equation*}

  Fix an index \( k > k_0 \) and let \( U \in U \) be such that
  \begin{equation}\label{thm:uniform_limit_of_continuous_functions/uniform/continuity}
    \forall x_1, x_2 \in S : (x_1, x_2) \in U \implies (f_k(x_1), f_k(x_2)) \in V.
  \end{equation}

  For any two points \( x_1, x_2 \in S \), we also have that
  \begin{equation}\label{thm:uniform_limit_of_continuous_functions/uniform/convergence}
    (f(x_i), f_k(x_i)) \in V, i = 1, 2.
  \end{equation}

  Analogously to \fullref{thm:uniform_limit_of_continuous_functions/continuous}, from \eqref{thm:uniform_limit_of_continuous_functions/uniform/continuity} and \eqref{thm:uniform_limit_of_continuous_functions/uniform/convergence}, we obtain
  \begin{equation*}
    \forall x_1, x_2 \in S : (x_1, x_2) \in U \implies (f(x_1), f(x_2)) \in 3V \subseteq W.
  \end{equation*}

  Thus, the entourage \( U \) depends on \( W \) and not on \( x_1 \) and \( x_2 \). Technically, it also depends on \( k_0 \), however we are only concerned with existence and not uniqueness. Hence, \( f \) is uniformly continuous.
\end{proof}

\begin{definition}\label{def:category_of_uniform_spaces}
  Uniform spaces and \hyperref[def:uniform_continuity]{uniformly continuous functions} form a subcategory of \( \cat{Top} \) (see \fullref{def:category_of_small_topological_spaces}). We denote this category by \( \cat{Met} \).
\end{definition}

\begin{definition}\label{def:fundamental_net}
  A \hyperref[def:topological_net]{net} \( \{ x_k \}_{k \in \mscrK} \) in a uniform space \( (X, \mscrV) \) is called a \term{fundamental net} or \term{Cauchy net} if
  \begin{equation*}
    \forall V \in V \ \exists k_0 \in \mscrK \ \forall k, m \geq k_0 : (x_k, x_m) \in V.
  \end{equation*}
\end{definition}

\begin{lemma}\label{thm:convergent_net_is_fundamental}
  A net in a uniform space that has a limit \hyperref[def:net_convergence/limit]{point} is \hyperref[def:fundamental_net]{fundamental}.
\end{lemma}
\begin{proof}
  If \( x_0 \) is a limit point of the net \( \{ x_k \}_{k \in \mscrK} \), the net is eventually in every ball \( B(x_0, V) \), which implies \fullref{def:fundamental_net}.
\end{proof}

\begin{definition}\label{def:complete_uniform_space}\mcite[446]{Engelking1989}
  A uniform space is called \term{complete} if it is \hyperref[def:separation_axioms/T2]{Hausdorff} and if every \hyperref[def:fundamental_net]{fundamental net} \hyperref[def:net_convergence/limit]{converges}.

  The \term{completion} of uniform space \( (X, \mscrV) \) is a (\hyperref[def:uniform_continuity]{uniformly continuous}) \hyperref[def:morphism_invertibility/left_cancellative]{embedding} \( f: X \to Y \) into a complete uniform space \( (Y, \mscrU) \) such that \( \img(X) \) is \hyperref[def:topologically_dense_set/dense]{dense} in \( Y \).
\end{definition}

\begin{theorem}[Uniform space completion]\label{thm:uniform_space_completion}\mcite[thm. 8.3.12]{Engelking1989}
  Every uniform space has a unique (up to an isomorphism) \hyperref[def:complete_uniform_space]{completion}.

  See also \fullref{thm:metric_space_completion}.
\end{theorem}

\begin{theorem}[Cauchy's net convergence criterion]\label{thm:cauchys_net_convergence_criterion}
  A net in a complete \hyperref[def:complete_uniform_space]{uniform space} is convergent if and only if it \hyperref[def:fundamental_net]{fundamental}.

  Explicitly, a net \( \{ x_k \}_{k \in \mscrK} \) in a complete uniform space \( (X, \mscrV) \) is \hyperref[def:net_convergence/limit]{convergent} if and only if for every entourage \( V \in V \) there exists an index \( k_0 \) such that
  \begin{equation*}
    (x_k, x_m) \in V \quad\forall k, m \geq k_0.
  \end{equation*}
\end{theorem}
\begin{proof}
  \SufficiencySubProof Given by \fullref{thm:convergent_net_is_fundamental}
  \NecessitySubProof Given by \fullref{def:complete_uniform_space}
\end{proof}


\documentclass[12]{scrartcl}
\usepackage{amssymb,amsmath,gensymb,dsfont,calc,multicol,fullpage}
\makeatletter
\newcommand\Aboxed[1]{
   \@Aboxed#1\ENDDNE}
\def\@Aboxed#1&#2\ENDDNE{%
   &
   \settowidth\@tempdima{$\displaystyle#1{}$}
   \setlength\@tempdima{\@tempdima+\fboxsep+\fboxrule}
   \kern-\@tempdima
   \boxed{#1#2}
}
\makeatother

\begin{document}

\title{Homework 13, Section 2.4; 1, 4, 5, 10, 12, 15, 19, 20}
\author{Alex Gordon}
\date{\today}
\maketitle
\section*{Homework}
\subsection*{1.}
$ \begin{bmatrix} A & B \\ EA + C & EB + D   \end{bmatrix}$
\subsection*{4.}
$ \begin{bmatrix} W& X \\ -EW + Y& -EX + Z   \end{bmatrix}$
\subsection*{5.}
$Y = B^{-1}A, X = -B^{-1}A,  Z = C$
\subsection*{10.}
$Q = -B + DA, P = -A, R = -D$
\subsection*{12. A)}
False. Both BA and AB are defined, but they have different dimensions. $AB = \begin{bmatrix} A_1B_1& A_1B_2 \\ A_2B_1 & A_2B_2   \end{bmatrix}$
\subsection*{12. B)}
False. $R^T$ and $Q^T$ have to be switched for it to be correct.
\subsection*{15.}
$G_{k+1} = G_k + X_k + 1 X^{T}_{k+1}$
\subsection*{19.}
$W(s) = I = C(A - sI)^-1 B$
\subsection*{20.}
The compliment is $I_m - C(A - BC - sI_n)^{-1}$

\end{document}