\chapter{Reconstructing  CT Signals}

In the previous lecture we focused on sampling of CT signals to produce a DT signal $x[n] = x(nT)$ with sample index $n$ and sample time $T$. In this lecture we consider \emph{reconstruction}, converting from a DT signal $x[n]$ to a CT signal $x(t)$ using a sample time $T$ as the spacing between samples. Ideally a conversion from $x(t)$ to $x[n]$ and back again would result in identical signal.

\section{Reconstruction Theory}
Given a DT signal $x[n]$ and a sample spacing $T$, we can define a corresponding CT signal as
\[
x_p(t) = \sum\limits_{n = -\infty}^{\infty} x[n] \, \delta(t-nT)
\]
the impulse train with each impulse weighted by the DT signal.

CT signal reconstruction can be viewed from two different (but equivalent) perspectives. In the time domain perspective, the CT signal $x(t)$ corresponding to a DT signal $x[n]$ can be viewed as \emph{interpolation}, where the values of the CT signal are equal to the DT signal at intervals of the sample time, i.e. $x(nT) = x[n]$, and in between the value of $x(t)$ is interpolated. If the interpolation is of zero-order, the value at $x(nT)$ is held constant until $x(nT+T)$. This is called a \emph{zero-order hold}, and can mathematically modeled as convolution of the weighted impulse train with a pulse $p(t) = u(t) - u(t-T)$ whose width is the sample time, called the interpolation function.
\[
y(t) = p(t)*x_p(t)
\]
This is illustrated below
\begin{center}
  \includegraphics[scale=1]{graphics/zero-order-hold-interp.pdf}
\end{center}

The zero-order hold is not a very accurate representation of a band-limited signal. So, what interpolation function is optimal?

To answer this question we can turn to the alternative perspective on reconstruction, that of the frequency domain. Recall the sampled signal $x(nT)$ in the frequency domain can be viewed as the summation of the Fourier transform of $x(t)$, $X(j\omega)$, and periodic replicas or images centered at multiples of the sampling frequency. If we assume the original signal was band-limited and sampled appropriately (using the Nyquist criteria), then if we ideal low-pass filter the sampled signal we will preserve the central portion of the Fourier spectrum that corresponds to the original signal, and chop off the images. For this reason the reconstruction filter is also called an anti-imaging filter.

\begin{center}
  \includegraphics[scale=1]{graphics/bandlimitedreconstructed1.pdf}
\end{center}

Recall filtering is multiplication the frequency domain and convolution in the time domain, so the optimal interpolation function corresponds to the impulse response of the ideal low-pass filter with cutoff frequency $\omega_c = 2\pi B$, a sinc function.

\[
h(t) = \mathcal{F}^{-1} \left\{ H(j\omega) \right\} = \frac{1}{2\pi} \int\limits_{\-\omega_c}^{\omega_c} e^{j\omega t} \; d\omega = \frac{1}{\pi t}\sin(\omega_c t)
\]

Thus the ideal ideal interpolation function is the sinc function, and reconstruction is low-pass filtering of the weighted impulse train $x_p(t)$ \footnote{As an aside this also gives an intuitive view of convolution with an impulse train, as interpolation}.

\section{Practical Reconstruction}

As we have seen before we cannot physically represent the impulse train nor the ideal low-pass filter. Thus practical reconstruction uses an approximation of the ideal reconstruction filter by a digital-to-analog converter (DAC), followed by a causal (and thus physically possible) low-pass filter.

\subsection{Zero-order hold using an R-2R ladder}

A zero-order hold DAC can be implemented by a circuit called a resistor ladder. Consider a digital output with $N$ bits and a reference voltage $V_{ref}$ (for example an 8-bit output port on a micro-controller using CMOS 3.3v logic).

If this port is connected to a resistor network consisting of resistor values $R$ and $2R$ as follows

\begin{center}
  \includegraphics[scale=1]{graphics/resistor-ladder.pdf}
\end{center}

then depending on the bit pattern at the output port $V$, the output of the buffer op-amp will be
\[
V_o = V_{ref}\frac{V}{2^N}
\]

If the port value is changed every sample time $T$, then the resister ladder and buffer op-amp combine to implement a zero-order hold circuit.

\subsection{Reconstruction(anti-imaging) filter}

The zero-order hold is followed by the reconstruction (anti-imaging) filter which low-pass filters the output and smooths-out the jumps from value to value.

\begin{center}
  \includegraphics[scale=1]{graphics/sinc-interp.pdf}
\end{center}

In general the reconstruction filter is of a similar, or identical form to the anti-aliasing filter.


%!TEX root=ClassNotes.tex

\section{Applications of Integrals}

\subsection{Improper Integrals}
Improper integrals compute areas of unbounded regions. These integrals are a source of several false paradoxes. As we'll see below, counter-intuitive as it may seem, unbounded regions {\it can} have finite areas.\\

We'll study two types of improper integrals: depending on whether the corresponding region is unbounded along the $x$-axis or along the $y$-axis.
The idea is to {\it view an unbounded region as a limit of bounded regions}.

\begin{definition}
  {\bf Improper integrals} (of the first kind) are integrals where one (or both) of the bounds is $\pm \infty$.\footnote{Note that $\infty$ is not a number here either, but represents a limit.}
  Let $f$ be a continuous function.
  Define,
	\begin{align*}
		\int \limits_a^{\infty} f(t) \: dt
		 & =
		\lim \limits_{x \rightarrow \infty}\int \limits_a^{x} f(t) \: dt \\
		\int \limits_{-\infty}^a f(t) \: dt
		 & =
		\lim \limits_{x \rightarrow -\infty}\int \limits_{x}^{a} f(t) \: dt \\
		\int \limits_{-\infty}^{\infty} f(t) \: dt
		 & =
		\lim \limits_{x \rightarrow \infty}\int \limits_0^{x} f(t) \: dt
    +
    \lim \limits_{x \rightarrow -\infty}\int \limits_{x}^{0} f(t) \: dt
	\end{align*}
  where $a$ is a real number.
\end{definition}

\begin{exercise}
	For the following problems, draw the region whose area the integral is computing (you can use a calculator for graphing) and compute the integral.
	\begin{multicols}{2}
		\begin{enumerate}
			\item $\int \limits_1^{\infty} \dfrac{1}{t} \: dt$
			\item $\int \limits_1^{\infty} \dfrac{1}{t^2} \: dt$
			\item $\int \limits_0^{\infty} \sin t \: dt$
			\item $\int \limits_0^{\infty} 2t e^{-t^2} \: dt$
			\item $\int \limits_{1}^{\infty} \dfrac{9}{(1 - 3t)^4} \: dt$
			\item $\int \limits_{-\infty}^{\infty} \dfrac{6 t^3}{(t^4 + 1)^2} \: dt$
		\end{enumerate}
	\end{multicols}
\end{exercise}

\begin{exercise}
  \begin{enumerate}
    \item The choice of the number 0 in the definition of $\int_{-\infty}^{\infty}$ is not important. We can replace 0 with any real number and the answer would not change.
    Compute
    \begin{align*}
      \lim \limits_{x \rightarrow \infty}\int \limits_1^{x} \dfrac{6 t^3}{(t^4 + 1)^2} \: dt
      +
      \lim \limits_{x \rightarrow -\infty}\int \limits_{x}^1 \dfrac{6 t^3}{(t^4 + 1)^2} \: dt
    \end{align*}
    and compare it with Problem 6 of the previous exercise. Why does the answer not change?

    \item On the other hand, consider the following change.
    Compute
    \begin{enumerate}
      \item $\lim \limits_{x \rightarrow \infty}\int \limits_{-x}^{x} \sin t \: dt$, and
      \item $\lim \limits_{x \rightarrow \infty}\int \limits_0^{x} \sin t \: dt
      +
      \lim \limits_{x \rightarrow -\infty}\int \limits_{x}^{0} \sin t \: dt$
    \end{enumerate}
    Why are the two answers different?
  \end{enumerate}
  Thus, when limits are involved, our intuition does not always provide us with the correct answer.
\end{exercise}

\begin{definition}
  {\bf Improper integrals} (of the second kind) are integrals where the function being integrated has a discontinuity in the interval of integration.
  Let $[a,b]$ be an interval and let $c \in [a, b]$ be a point such that $f(x)$ is discontinuous at $c$ but continuous on the rest of interval. Define,
	\begin{align*}
    \mbox{if } a < c < b, &&
    \int \limits_a^b f(t) \: dt
		 & =
		\lim \limits_{x \rightarrow c^{-}}\int \limits_a^{x} f(t) \: dt
    +
    \lim \limits_{x \rightarrow c^{+}}\int \limits_{x}^{b} f(t) \: dt \\
    \mbox{if } c = a, &&
    \int \limits_c^b f(t) \: dt
		 & =
    \lim \limits_{x \rightarrow c^{+}}\int \limits_{x}^{b} f(t) \: dt \\
    \mbox{if } c = b, &&
    \int \limits_a^c f(t) \: dt
		 & =
		\lim \limits_{x \rightarrow c^{-}}\int \limits_a^{x} f(t) \: dt
	\end{align*}
\end{definition}

\begin{exercise}
	For the following problems, draw the region whose area the integral is computing (you can use a calculator for graphing if you like) and compute the integral.
	\begin{multicols}{2}
		\begin{enumerate}
			\item $\int \limits_0^{3} \dfrac{1}{\sqrt{3 - t}} \: dt$
			\item $\int \limits_{2}^{3} \dfrac{4t}{\sqrt[3]{t^2 - 4}} \: dt$
			\end{enumerate}
	\end{multicols}
\end{exercise}

It is possible to compute integrals of more general unbounded regions using the same ideas.

\subsection{Arc Length}
Recall that the integral $\int_a^b f(t) \: dt$ is defined as the limit of the Riemann sum
\begin{align*}
  \sum_{i = 0}^{n-1} m_i (x_{i+1} - x_{i})
\end{align*}
where $x_i$'s form a partition of the interval $[a,b]$ and $m_i$ is the min (inf) of the $f(x)$ values in the interval $[x_i, x_{i+1}]$. One way to {\it represent} this sum is as the sum of several quantities of the form
\begin{align*}
  y \: \Delta x
\end{align*}
where $\Delta x$ stands for the length of the interval $x_{i+1} - x_i$ which can be thought of as {\bf the change in $x$}, and $y$ stands for {\bf the minimum value of $f(x)$} for $x \in[x_i, x_{i+1}]$. So that
\begin{align}
  \label{eq:sum_limit}
  \lim \limits_{\Delta x \rightarrow 0} \left(\sum y \: \Delta x \right) = \int y \: dx
\end{align}
The reason for doing this, is that this allows us to interpret several {\it naturally occurring} quantities as integrals (which is why the Riemann sum formulation of integral is much more useful than the area formulation). One such example is an {\bf arc length}.\\

{\bf Arc length} is just a fancy name for the length of a curve. For example, the arc length of a circle of radius $r$ is $2 \pi r$. We are interested in computing the arc length of the graph of a function $y=f(x)$.
\begin{figure}[H]
  \centering
  \includegraphics[width=0.5\textwidth]{ArcLength.png}
  \caption*{Approximating the graph $y=f(x)$ by line segments}
\end{figure}
We do this by partitioning the interval $[a,b]$ and approximating the graph $ y = f(x)$ over each partition by a straight line. The length of each small straight line segment equals
\begin{align*}
  \sqrt{\Delta x^2 + \Delta y^2}
\end{align*}
and hence the arc length equals
\begin{align*}
  \lim \limits_{\Delta x \rightarrow 0}  \left(\sum \sqrt{\Delta x^2 + \Delta y^2}\right)
\end{align*}
This looks very close to \eqref{eq:sum_limit}. Next we need to separate a $\Delta x$ term.
\begin{align*}
  \lim \limits_{\Delta x \rightarrow 0} \left(\sum \sqrt{1 + \left(\dfrac{\Delta y}{\Delta x}\right)^2} \Delta x \right)
\end{align*}
This looks exactly like \eqref{eq:sum_limit} with $y$ replaced with $\sqrt{1 + \left(\frac{\Delta y}{\Delta x}\right)^2}$. Finally we notice that
\begin{align*}
  \lim \limits_{\Delta x \rightarrow 0} \dfrac{\Delta y}{\Delta x} = \dfrac{dy}{dx}
\end{align*}
which gives us the formula for the arc length.
\begin{theorem}
  \label{thm:arclength}
  Let $f$ be a differentiable function on the interval $[a,b]$. The arc length of the graph $y = f(x)$ over the interval $[a,b]$ is given by the integral
  \begin{align*}
    \int \limits_a^b \sqrt{1 + \left(\dfrac{dy}{dx} \right)^2}  \: dx
  \end{align*}
\end{theorem}
While the above derivation is not a {\it proof}, it can be converted into a proof using $\sup$'s and $\inf$'s, using the same method we used to prove the Fundamental Theorem of Calculus.

\begin{exercise}
  Using the arc length formula in Theorem \ref{thm:arclength} compute the following:
  \begin{enumerate}
    \item Circumference of a circle of radius r.
    \item Arc length of the parabola $y = x^2$ from 0 to 1.
    \item Arc length of line segment $y = m x$ from $a$ to $b$, where $m$, $a$, $b$ are real numbers. Explain the result geometrically.
  \end{enumerate}
\end{exercise}

\begin{exercise}
  Here we encounter the first example of a {\it naturally occurring} unsolvable integral.
  Find the expression for the arc length of the sine curve $y = \sin x$ from 0 to $a$.
  This integral, called an {\bf elliptic integral}, cannot be algebraically computed.\footnote{Even though elliptic integrals cannot be simplified algebraically, they have deep connections to number theory.
  The impossibility of algebraically evaluating elliptic integrals presents the first obstacle towards a complete understanding of prime numbers!\\
  See: \url{https://en.wikipedia.org/wiki/Elliptic_function}}
\end{exercise}

\begin{exercise}{\bf (Optional)}
  In this problem, you'll need to use the fact that the (curved) surface area of a cylinder is $2 \pi r h$ and the volume is $\pi r^2 h$, where $r$ is the radius and $h$ is the height of the cylinder.
  \begin{figure}[H]
    \centering
    \includegraphics[width=0.5\textwidth]{SurfaceOfRevolution.png}
  \end{figure}
  \end{exercise}
  \begin{enumerate}
    \item Derive the formula for the area of the surface obtained by revolving the curve $y = f(x)$ over the interval $[a,b]$ about the $x$-axis.
   Such a surface is called a {\bf surface of revolution}.
    \item Derive the formula for the volume of the solid obtained by revolving the region under the curve $y = f(x)$ over the interval $[a,b]$ about the $x$-axis.
    Such a solid is called a {\bf solid of revolution}.
  \end{enumerate}
We can do both of these constructions by revolving the curve about the $y$-axis instead of the $x$-axis. In this case, we simply switch $x$ and $y$ and use the function $x=f^{-1}(y)$ instead of $y = f(x)$.\\

\subsection{Differential Equations}
It would be remiss to not mention differential equations while studying applications of calculus.
Calculus was invented by Newton to find solutions to his laws of motion, which are a set of differential equations.

A {\bf differential equation} is any equation involving derivatives $\frac{dy}{dx}$, $\frac{d^2y}{dx^2}$ etc.
Solving a differential equation means finding a function $y = f(x)$ that satisfies the equation.

We've already encountered one very simple differential equation.
The Fundamental Theorem of Calculus is essentially a statement about the solution of a differential equation.
We can rephrase it as saying:\\ {\it The solution to the differential equation
\begin{align*}
  \dfrac{dy}{dx} = g(x)
\end{align*}
is given by
\begin{align*}
  y = \int g(x) \: dx.
\end{align*}
}

In this section, we'll see some examples of differential equations without going into any details.
It is not possible to {\it solve} this differential equation in the same way that we solve algebraic equations. Instead, we {\it guess} a solution and verify it.

\begin{exercise}
  A {\bf separable} differential equation is of the form
  \begin{align*}
    \dfrac{dy}{dx} = f(x) \cdot g(y)
  \end{align*}
  for some functions $f$ and $g$. The solution of this differential equation is given by
  \begin{align*}
    \int \dfrac{1}{g(y)} \: dy  = \int f(x) \: dx
  \end{align*}
  It is called separable because the variables $x$ and $y$ can be ``separated'' i.e. all the terms involving $y$ are on the left hand side and all the terms involving $x$ are on the right hand side. A non-example is $\frac{dy}{dx} = x + y$.

  Find solutions for the following separable differential equations and verify that your solution satisfies the differential equation.
  \begin{multicols}{2}
    \begin{enumerate}
      \item $\dfrac{dy}{dx} = 2y$
      \item $\dfrac{dy}{dx} = xy$
      \item $\dfrac{dy}{dx} = \dfrac{3x^2}{\cos y}$
      \item $\dfrac{dy}{dx} = - \dfrac{y}{x}$
      \item $\dfrac{dy}{dx} = - \dfrac{x}{y}$
      \item $\dfrac{dy}{dx} = e^{-y}(2x - 4) $
    \end{enumerate}
  \end{multicols}
\end{exercise}

\newpage
\begin{exercise}
  The following differential equation is called a {\bf damped harmonic oscillator},
  \begin{align*}
    m \dfrac{d^2y}{dx^2} + c \dfrac{dy}{dx} + k y = 0
  \end{align*}
  where $m$, $k$, and $c$ are constants.
  This differential equation is used to model simple oscillatory systems.
  \begin{enumerate}
    \item Find a number(s) $r$ such that $y=e^{rx}$ solves the differential equation
    \begin{align*}
       \dfrac{d^2y}{dx^2} - 4 y = 0
    \end{align*}
    \item Find a number(s) $r$ such that $y=e^{rx}$ solves the differential equation
    \begin{align*}
       \dfrac{d^2y}{dx^2} + 4 y = 0
    \end{align*}
    \item Find a number(s) $r$ such that $y=e^{rx}$ solves the differential equation
    \begin{align*}
       \dfrac{d^2y}{dx^2} - 2 \dfrac{dy}{dx} + y = 0
    \end{align*}
    For this $r$, verify that $y = x e^{rx}$ is also a solution.
    \item Notice that the three equations have very different kinds of solutions.
    How would you describe the difference between the three equations?
  \end{enumerate}
\end{exercise}

Differential equations in general are very very difficult to solve. Finding solutions to differential equations has been a guiding question for much of modern mathematics. It is still not known whether a solution exists to the differential equation that describes fluid motion.\footnote{See \url{https://en.wikipedia.org/wiki/Navier-Stokes_equations}.} Nevertheless a lot of techniques now exist for solving a variety of differential equations either exactly or numerically.
Differential equations is one of the most active areas of mathematical research today.


\chapter{Linear Regression}
\label{chp:linreg}

%Linear regression is an approach in supervised learning. It is used for predicting a quantitative response and it is widely used for statistical learning methods. It may seem that it is a bit simple compared to some of the more modern statistical learning approaches, but it serves as a good base as newer approaches can be seen as a generalization or extension of the linear regression.
%This chapter presents the key ideas of a linear regression model and it will describe the least squares approach
%which is the most commonly used to fit this model\\

This chapter presents Linear regression which is an approach in supervised learning that can be used for predicting a quantitative response. Furthermore the least squares approach is explained as the most commonly used method for fitting a linear regression model.

\section{Simple Linear Regression}

Simple linear regression is used for predicting a quantitative response, often denoted Y, based on a single predictor, often denoted X.
The relationship between X and Y can be expressed as:

\begin{equation}
Y \approx \beta_0 + \beta_1X
\end{equation}

In equation (2.1) $\beta_0$ represents the intercept and $\beta_1$ which is multiplied with X represents the slope.
%This means that Y is approximately modeled as X or in other words Y is regressing on X.
%$\beta_0$ and $\beta_1$ are two unknown constants that represent the intercept and slope in the linear model. They are also known as model coefficients or parameters.
In linear regression training data containing observations of X and Y is used to estimate $\hat{\beta_0}$ and $\hat{\beta_1}$.
This can be mathematically expressed as:

\begin{equation}
\hat{y} = \hat{\beta_0} + \hat{\beta_1}x
\end{equation}

%$\hat{y}$ is the prediction of Y based on X = x. The \textit{hat} %symbol is used to denote the estimated value for an unknown parameter or coefficient or to predict a value of the response.

%When estimating the coefficients
%$\hat{\beta_0}$ and  $\hat{\beta_1}$ are in practice unknown. So %in order to use (2.1) to make predictions, $\hat{\beta_0}$ and  %$\hat{\beta_1}$ needs to be estimated so the data can be used.

%First Let
%\begin{equation}
%(x_1, y_1), (x_2, y_2),..., (x_n, y_n)
%\end{equation}

%represent n observation pairs where each of them have a measurement of X and a measurement of Y. n can represent lots of thing. can be the number of different markets, or different cities. It depends on the data.

$\hat{\beta_0}$ and  $\hat{\beta_1}$ must be estimated to fit all the observations as good as possible. This can be ensured by using the least squared approach.
%In other words $\hat{\beta_0}$ is the intercept and  $\hat{\beta_1}$ is a slope, so the resulting line is as close as possible to n\{th} data points

%First the prediction for Y will be written as $\hat{y_i} = \hat{\beta_0} + \hat{\beta_1} x_i$ based on the \emph{i}th value of X.
%Then $e_i = y_i - \hat{y_i}$ will represent the \emph{i}th residual, which is the difference between the \emph{i}th observed response value and the \emph{i}th response value that is predicted by the linear model.

Least squared approach determines the $\hat{\beta_0}$ and  $\hat{\beta_1}$ to minimize the residual sum of squares.
The residual is defined as the difference between the predicted and the true response value: $y-\hat{y}$. $\hat{y}$ can be replaced with $\hat{\beta_0} + \hat{\beta_1}x$ and the residual sum of squares can then be defined as:

\begin{equation}
RSS = (y_1 - (\hat{\beta_0} + \hat{\beta_1}X_1))^2 + (y_2 - (\hat{\beta_0} + \hat{\beta_1}X_2))^2 + ... + (y_n - (\hat{\beta_0} + \hat{\beta_1}X_n))^2
\end{equation}

%The least squares approach can then be used to choose $\hat{\beta_0}$ and $\hat{\beta_1}$ to minimize the RSS (2.5).
%The minimization is written as:

The least squares coefficients can then be estimated from the minimizers of RSS defined in equation in (2.4) and (2.5).
\begin{equation}
\hat{\beta_1} = \dfrac{\sum\limits_{i=1}^n(x_i - \bar{x})(y_i - \bar{y})}{\sum\limits_{i=1}^n(x_i - \bar{x})^2}
\end{equation}

\begin{equation}
\hat{\beta_0} = \bar{y} -\hat{\beta_1}\bar{x}
\end{equation}

%n (3.4) $\hat{y} \equiv \dfrac{1}{n}\sum\limits_{i=1}^ny_i$ and %$\hat{x}\equiv \dfrac{1}{n}\sum\limits_{i=1}^nx_i$ are the ample eans and the function is used to define the least squares coefficient estimates for a simple linear regression

\subsection{Lab 3.6.2 - Simple Linear Regression}

In Lab 3.6.2 the data set \emph{Boston} is given. It consists of records from about 506 neighborhoods around Boston. The task is to predict \emph{medv} (median house value) via the predictor \emph{lstat} (percent of households with low socioeconomic status).

The data is initially prepared before the linear regression can be performed. This is shown in listing \ref{lst:lin_reg_prep}. The data is loaded and then the \emph{lstat} data is added to \emph{boston\_X\_train} and the \emph{medv} data is added to \emph{boston\_Y\_train}.

\begin{lstlisting}[caption={Data preparation for linear regression}, label=lst:lin_reg_prep, mathescape=true]
boston = datasets.load_boston()

#Extract 'lstat'-
boston_X_train = boston.data[:, np.newaxis, 12]

#Extract 'medv'
boston_Y_train = boston.target
\end{lstlisting}

To perform the linear regression the library sklearn is used in python. In listing \ref{lst:lin_reg} it is shown how a linear regression model is fitted to the training data \emph{boston\_X\_train} and the \emph{boston\_Y\_train}.

\begin{lstlisting}[caption={Python linear regression function}, label=lst:lin_reg, mathescape=true]
lm = linear_model.LinearRegression()
lm.fit(boston_X_train, boston_Y_train)
\end{lstlisting}

\FloatBarrier

The code in listing \ref{lst:lin_reg_plot} is used to plot \emph{medv} and \emph{lstat} along with the least squares regression line. In line 1 the test data is plotted to see how it corresponds to the least squares regression line. To plot the least squares regression line the command 'plot' is used. This is seen in line 2 where 'boston\_X\_test' is the test data which consist of the \emph{lstat} data. The result is plotted in Figure \ref{fig:lin_reg_plot}. The plots shows that the relation between \emph{lstat} and \emph{medv} is somewhat non-linear.

\begin{lstlisting}[caption={Python plotting of linear regression function}, label=lst:lin_reg_plot, mathescape=true]
plt.scatter(boston_X_test, boston_Y_test,  color='black')
plt.plot(boston_X_test, lm.predict(boston_X_test), color='blue',
linewidth=3)

plt.xticks(())
plt.yticks(())

plt.show()
\end{lstlisting}

\myFigure{lin_reg_plot.PNG}{Linear regression of \emph{medv} and \emph{lstat}}{fig:lin_reg_plot}{0.5}

\section{Multiple Linear Regression}

When using simple linear regression only one predictor is used. But often more than one predictor is available. Instead multiple linear regression uses two or more predictors to predict the response variable Y. The relationship between the predictor variable and response variable with simple linear regression can be described as a one-to-one, while multiple linear regression is a many-to-one relationship, as illustrated in Figure \ref{fig:relation}.

\myFigure{relation.PNG}{Relationship between predictor variables "P.V" and response variables "R.V" in Simple- and Multiple Linear Regression}{fig:relation}{0.8}

\FloatBarrier
As specified in Lab 3.6.2, the predictors are called X, while Y is the response. This means for multiple linear regression, that the relationship between X and Y is expressed as:

\begin{equation}
Y \approx \beta_0 + \beta_1 * X_1 + \beta_2 * X_2 + … + \beta_k * X_k
\end{equation}

Similar to simple linear regression, the regression coefficients are estimated using the least squares approach so that $\beta_0$, $\beta_1$,...$\beta_p$ is chosen to minimize the RSS.

\subsection{Lab 3.6.3 - Multiple Linear Regression}

In this exercise multiple linear regression is used. In Listing \ref{lst:mul_lin_reg} all 13 predictors in the Boston data set is used for performing multiple linear regression.

\begin{lstlisting}[caption={Linear regression of multiple predictors}, label=lst:mul_lin_reg, mathescape=true]
boston_X_train = boston.data
boston_Y_train = boston.target

lm = linear_model.LinearRegression()
lm.fit(boston_X_train, boston_Y_train)
\end{lstlisting}

%In listing \ref{lst:print} the calculated coefficients, intercept and variance for the linear regression model is printed.

%\begin{lstlisting}[caption={Printing regression overview}, label=lst:print, mathescape=true]
%print("Coefficients:")
%print(lm.coef_)
%print("Intercept: ")
%print(lm.intercept_)
%print("Variance score: %.2f" % lm.score(boston_X_test, boston_Y_test))
%\end{lstlisting}

The printed output is shown in figure \ref{fig:multiOutput}. The output first shows the estimated coefficients for the linear regression model. The first value -0.1072 is $\beta_1$ and is multiplied with the predictor \emph{crim}. The next value 0.0464 is $\beta_2$ and is multiplied with the predictors \emph{zn}. In total there are 13 coefficients, one for each predictor.

Furthermore the intercept value $\beta_0$ is printed. This is the value of the interception with the y-axis. Lastly multiple $R^2$ is printed. The $R^2$ of the simple linear regression was only calculated to 0.544, while for the multiple linear regression model including all 13 predictors the $R^2$ coefficient was improved to 0.74. This indicates that the model is improved using multiple linear regression.

\myFigure{MultiLinRegOutput.PNG}{Resulting coefficients, intercept value and multiple $R^2$ for the multiple linear regression model}{fig:multiOutput}{0.8}


\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\title{Solution to the Monty Hall Problem with the Bayesian Theorem}
\date{\today}
\author{Lukas Prokop}

\newcommand{\Pc}[2]{P(#1\,|\,#2)}

\begin{document}
\maketitle

\section{The problem}
%
In a quizshow, the candidate has to select one of three doors.
Behind two doors there is a goat (an undesirable prize).
Behind the one door there is a car.
At the beginning the candidate tries to guess the door with the car.
Afterwards the moderator Monty Hall opens one of the doors with a goat which is not the candidate's door.
So two doors are left where one of them is the one, the candidate has chosen.
Monty asks the candidate whether he would like to change his mind; he is
free to select the other door.

In general, is it better to change the mind, stick to the first selection
or doesn't it matter?

\section{Bayesian approach}
%
Assumption (one of three cases): The candidate selects door \#1.
\begin{center}
  \begin{tabular}{cc}
    $D_1$ & Car behind door \#1 \\
    $D_2$ & Car behind door \#2 \\
    $D_3$ & Car behind door \#3
  \end{tabular}
\end{center}

\noindent
We define the corresponding probabilities:
\[
    P(D_1) = \frac13  \qquad
    P(D_2) = \frac13  \qquad
    P(D_3) = \frac13
\]

We somehow have to model the behavior of the moderator.
Therefore we introduce a hypothesis $H$ that he opens door \#3.
The probability that he selects door \#3 in favor of door \#2
is $\frac12$, because \#1 is already taken by the candidate:
\[
    P(H) = \frac12
\]

\noindent
Furthermore,
\[
    \Pc{H}{D_1} = \frac12  \qquad
    \Pc{H}{D_2} = 1        \qquad
    \Pc{H}{D_3} = 0
\]

So the probability that he opens door \#3 under the condition that door \#1
contains the car is $\frac12$ (moderator will select door \#2 or door \#1
because \#1 is candidate's door). The probability is $1$ if the car is in
door \#2 (door \#1 is candidate's door and \#2 contains the car).
And if the car is in door \#3, the moderator will never show door \#3.

We can spot some asymmetry here. This point is evidently responsible why
an intuition like ``it does not matter'' might be wrong.

So we will use the Bayes' Theorem:
\[
    \underbrace{\Pc{A}{B}}_{\text{posterior probability}} =
      \frac{\overbrace{\Pc{B}{A}}^{\text{Likelihood}} \cdot
        \overbrace{P(A)}^{\text{priori probability}}
      }{
        \underbrace{P(B)}_{\text{expectedness}}
      }
\]

The important question is: Under the assumption that we have selected door \#1
(our first assumption) and Monty opens door \#3 (our hypothesis or
``expectedness''), what is the probability that the car is behind door \#1
compared to door \#2?
\[
    \Pc{D_1}{H} = \frac{\Pc{H}{D_1} \cdot P(D_1)}{P(H)}
        = \frac{\frac12 \cdot \frac13}{\frac12} = \frac13
\] \[
    \Pc{D_2}{H} = \frac{1 \cdot \frac13}{\frac12} = \frac23
\]

So apparently, the probability that door \#2 contains the car is higher than
for door \#1. Or in other words: in this case the candidate should prefer
to change his mind.

Now we have to evaluate this for other hypotheses (moderator opens door \#2)
and other candidate selections (door \#2 and door \#3). The approach is the
same and not carried out here. But the conclusion keeps the same in all cases:
Being open to change your mind will make you probabilistically win the car.

\end{document}


\documentclass[11pt, oneside]{article}

\usepackage{../../shared/preamble}
\addbibresource{../../shared/references.bib}

\usepackage{../sets/sets}
\usepackage{../groups/groups}
\usepackage{../topological-spaces/topological-spaces}
\usepackage{../real-numbers/real-numbers}
\usepackage{vector-spaces}

\title{Vector Spaces}
\author{Arthur Ryman, {\tt arthur.ryman@gmail.com}}
\date{\today}

\begin{document}

\maketitle

\begin{abstract}
This article contains Z Notation type declarations for vector spaces and some related objects.
It has been type checked by \fuzz.
\end{abstract}

\section{Real Vector Spaces}

Real vector spaces are multidimensional generalizations of real numbers.
They are the objects studied in linear algebra and are foundational to differential geometry.

In the following let $\genT$ denote a set of elements which we'll refer to as {\em vectors}
and let $A$ denote an Abelian group over the vectors in which the binary operation is denoted as addition.
Let $v$ and $w$ denote vectors and
and let $x$ and $y$ denote real numbers.

\subsection{Notation for Vector Addition, Zero, and Negative: \zcmd{addV}, \zcmd{zeroV}, and \zcmd{negV}}

Let $v \addV w$ denote vector addition,
let $\zeroV$ denote the zero vector,
and let $\negV v$ denote the negative vector.

\subsection{Real Scalar Multiplication: \zcmd{mulS}, \zcmd{timesS}, and $RealScalarMultiplication$}

A {\em real scalar multiplication} operation on the vectors is an operation $smul$
that maps the pair $(x, v)$ to another vector, typically denoted $x \mulS v$ or $x \timesS y$,
such that
multiplication by 0 maps all vectors to the group identity element,
multiplication by 1 maps each vector to itself,
multiplication preserves group addition,
and multiplication distributes over both real and group addition.

Let $RealScalarMultiplication$ denote this situation.

\begin{schema}{RealScalarMultiplication}[\genT]
A: \abgroup \genT \\
smul: \R \cross \genT \fun \genT
\where
\LET (\_ \addV \_) == A; \\
\t1	\zeroV == identity\_element~A; \\
\t1	(\_ \mulS \_) == smul @ \\
\t2		\forall x, y: \R; v, w: \genT @ \\
\t3			\zeroR \mulS v = \zeroV \land \\
\t3			\oneR \mulS v = v \land \\
\t3			(x \mulR y) \mulS v = x \mulS (y \mulS v) \land \\
\t3			(x \addR y) \mulS v = x \mulS v \addV y \mulS v \land \\
\t3			x \mulS (v \addV w) = x \mulS v \addV x \mulS w
\end{schema}

\begin{itemize}
	\item Multiplying by $\zeroR$ gives the zero vector.
	\item Multiplying by $\oneR$ gives the same vector.
	\item Scalar multiplication is associative.
	\item Scalar addition distributes over scalar multiplication.
	\item Vector addition distributes over scalar multiplication.
\end{itemize}

\subsection{The Set of All Real Vector Spaces: \zcmd{vecR}}

A {\em real vector space} is a pair $(A, smul)$ where $A$ is an Abelian group and $smul$
is a real scalar multiplication on the elements of $A$.
The elements of $A$ are referred to as \textit{vectors}.

Let $\vecR \genT$ denote the set of all real vector spaces over $\genT$,

\begin{zed}
\vecR \genT == \{~ RealScalarMultiplication[\genT] @ (A, smul) ~\}
\end{zed}

\subsection{Real Linear Transformations: $RealLinearTransformation$}

Let $V_1$ and $V_2$ be real vector spaces and let $f$ be a homomorphism of the underlying
Abelian groups.
The map $f$ is said to be a {\em linear transformation} if $f$ maps scalar multiples of vectors to the
scalar multiple of the mapped vectors.

Let $RealLinearTransformation$ denote this situation.

\begin{schema}{RealLinearTransformation}[\genT, \genU]
f: \genT \fun \genU \\
V_1: \vecR \genT \\
V_2: \vecR \genU
\where
\LET A_1 == first~V_1; (\_ \mulS \_) == second~V_1; \\
\t1	A_2 == first~V_2; (\_ \timesS \_) == second~V_2 @ \\
\t2		f \in \homGroup(A_1, A_2) \land \\
\t2		(\forall x: \R; v: \genT @ \\
\t3			f(x \mulS v) = x \timesS(f~v))
\end{schema}

\begin{itemize}
\item The vector space $V_1$ has Abelian group $A_1$ and scalar multiplication $(\_ \mulS \_)$.
\item The vector space $V_2$ has Abelian group $A_2$ and scalar multiplication $(\_ \timesS \_)$.
\item The map $f$ is a homomorphism of the underlying Abelian groups.
\item The map $f$ maps scalar multiples of vectors in $\genT$ to scalar multiples of the mapped vectors in $\genU$.
\end{itemize}

\subsection{The Set of All Real Linear Transformations: \zcmd{homVecR}}

Let $V_1$ and $V_2$ be real vector spaces.
Let $\homVecR(V_1, V_2)$ denote the set of all linear transformations from $V_1$ to $V_2$.
A linear transformation is also referred to as a \textit{homomorphism} of vector spaces.

\begin{zed}
\homVecR[\genT, \genU] == \\
\t1	(\lambda V_1: \vecR \genT; V_2: \vecR \genU @ \\
\t2		\{~ f: \genT \fun \genU | \\
\t3			RealLinearTransformation[\genT, \genU] ~\})
\end{zed}

\section{Real $n$-tuples}

The preceding section described real vector spaces abstractly.
In this section we define a family of finite-dimensional real vector spaces
whose elements are finite sequences of real numbers, also referred to as \textit{real tuples}.

\subsection{The Set of All Finite Sequences of Real Numbers: \zcmd{Rinf}}

Let $n$ be a natural number.
A finite sequence of $n$ real numbers is called a {\it real $n$-tuple}.
Let $\Rinf$ denote the set of all real $n$-tuples for any $n$.

\begin{zed}
	\Rinf == \seq \R
\end{zed}

\subsection{The Component Projection Function: \zcmd{piRinf}}

The real numbers that comprise an $n$-tuple are called its \textit{components}.
Let $v$ be a real $n$-tuple and let $i$ be an integer where $1 \le i \le n$.
The real number $v(i)$ is the $i$-th component of $v$.
Let $\piRinf(i)$ be the projection function that maps an $n$-tuple $v$ to its $i$-th component $v(i)$.

\begin{axdef}
	\piRinf: \nat_1 \fun \Rinf \pfun \R
\where
	\forall i: \nat_1 @ \\
	\t1	\piRinf(i) = (\lambda v: \Rinf | i \in \dom v @ v(i))
\end{axdef}

\subsection{The Set of All Well-Dimensioned Subsets of $\Rinf$: \zcmd{DeltaRinf}}

A non-empty subset of $\Rinf$ is said to be \textit{well-dimensioned} if each of its elements has the same number
of components.
Let $\DeltaRinf$ denote the family of all well-dimensioned subsets of $\Rinf$ .

\begin{axdef}
	\DeltaRinf: \family~\Rinf
\where
	\DeltaRinf = \{~ S: \power_1 \Rinf | \forall v, w: S @ \# v = \# w ~\}
\end{axdef}

\subsection{The Dimension of a Well-Dimensioned Set of Tuples: \zcmd{dimRinf}}

Let $S \in \DeltaRinf$ be a well-dimensioned set of tuples.
The number of components of each tuple in $S$ is called its \textit{dimension}.
Let $\dimRinf(S)$ denote the dimension of $S$.

\begin{axdef}
\dimRinf: \DeltaRinf \fun \nat
\where
%	\forall n: \nat @ \forall U: \power(\Rtup(n)) @ \\
%	\t1	\dimRinf(U) = n
\forall S: \DeltaRinf @ \\
\t1	\dimRinf S = (\mu v: S @ \# v)
\end{axdef}

\subsection{The Set of All Compatible Pairs of Tuples: \zcmd{RinfDelta}}

The pair of real tuples $(v, w)$ is said to be \textit{compatible} if each member has the same number of components.
Let $\RinfDelta$ denote the set of all compatible pairs of real tuples.
If the pair $(v, w)$ is compatible then $v$ and $w$ are said to be compatible with each other.

\begin{axdef}
	\RinfDelta: \Rinf \rel \Rinf
\where
	\RinfDelta = \{~ v, w: \Rinf | \# v = \# w ~\}
\end{axdef}

\subsection{Addition of Compatible Tuples: \zcmd{addRinf}}

Let $v$ and $w$ be $n$-tuples.
Vector addition of $v$ and $w$ is the $n$-tuple $v \addRinf w$ defined by component-wise addition.

\begin{axdef}
	\_ \addRinf \_: \RinfDelta \fun \Rinf
\where
	\langle \rangle \addRinf \langle \rangle = \langle \rangle
\also
\forall n: \nat_1; v, w: \Rinf | n = \#v = \# w @ \\
\t1	v \addRinf w = (\lambda i: 1 \upto n @ v~i \addR w~i)
\end{axdef}

\subsection{Subtraction of Compatible Tuples: \zcmd{subRinf}}

Vector subtraction is defined similarly.

\begin{axdef}
	\_ \subRinf \_: \RinfDelta \fun \Rinf
\where
	\langle \rangle \subRinf \langle \rangle = \langle \rangle
\also
\forall n: \nat_1; v, w: \Rinf | n = \#v = \# w @ \\
\t1	v \subRinf w = (\lambda i: 1 \upto n @ v~i \subR w~i)
\end{axdef}

\subsection{The Negative of a Tuple: \zcmd{negRinf}}

Let $\negRinf v$ denote the negative of $v$.

\begin{axdef}
\negRinf: \Rinf \fun \Rinf
\where
\negRinf \langle \rangle = \langle \rangle
\also
\forall n: \nat_1; v: \Rinf | n = \# v @ \\
\t1	\negRinf v = (\lambda i: 1 \upto n @ \negR(v~i))
\end{axdef}

\subsection{Scalar Multiplication of a Tuple: \zcmd{smulRinf}}

Let $v$ be an $n$-tuple and let $c$ be a real number.
Scalar multiplication of $v$ by $c$ is the $n$-tuple $c \smulRinf v$ defined by component-wise multiplication.

\begin{axdef}
\_ \smulRinf \_ : \R \cross \Rinf \fun \Rinf
\where
\forall c: \R @ \\
\t1	c \smulRinf \langle \rangle = \langle \rangle
\also
\forall c: \R; n: \nat_1; v: \Rinf | n = \# v @ \\
\t1	c \smulRinf v = (\lambda i: 1 \upto n @ c \mulR (v~i))
\end{axdef}

\begin{remark}
Scalar multiplication is associative in the sense that $(a \mulR b) \smulRinf v = a \smulRinf (b \smulRinf v)$

\begin{zed}
	\forall a, b: \R; v: \Rinf @ \\
	\t1	(a \mulR b) \smulRinf v = a \smulRinf (b \smulRinf v)
\end{zed}

\end{remark}

\subsection{The Set of All Real $n$-tuples: \zcmd{Rtup}}

Let $\Rtup(n)$ denote $\R^n$, the set of all $n$-tuples for some given $n$.
\begin{axdef}
	\Rtup: \nat \fun \power \Rinf
\where
	\forall n: \nat @ \\
	\t1	\Rtup(n) = \{~ v: \Rinf | \# v = n ~\}
\end{axdef}

\begin{remark}

\begin{zed}
	\Rinf = \bigcup \{~ n: \nat @ \Rtup(n) ~\}
\end{zed}

\end{remark}

\begin{remark}
The subset $\Rtup(n)$ is well-dimensioned.

\begin{zed}
	\forall n: \nat @ \\
	\t1	\Rtup(n) \in \DeltaRinf
\end{zed}

\end{remark}

\begin{remark}
The dimension of $\Rtup(n)$ is $n$.

\begin{zed}
	\forall n: \nat @ \\
	\t1	\dimRinf(\Rtup(n)) = n
\end{zed}

\end{remark}

\subsection{Addition of $n$-tuples: $addRtup$}

Let $addRtup(n)$ denote the restriction of addition to $\Rtup(n)$.

\begin{zed}
addRtup == \\
\t1	(\lambda n: \nat @ \\
\t2		(\lambda v, w: \Rtup(n) @ v \addRinf w))
\end{zed}

\begin{example}
The binary operation $addRtup(n)$ defines an Abelian group over $\Rtup(n)$.

\begin{zed}
\forall n: \nat @ \\
\t1	addRtup(n) \in \abgroup(\Rtup(n))
\end{zed}

\end{example}

\subsection{Subtraction of $n$-tuples: $subRtup$}

Let $subRtup(n)$ denote the restriction of subtraction to $\Rtup(n)$.

\begin{zed}
subRtup == \\
\t1	(\lambda n: \nat @ \\
\t2		(\lambda v, w: \Rtup(n) @ v \subRinf w))
\end{zed}

\subsection{The Negative of an $n$-tuple: $negRtup$}

Let $negRtup(n)$ denote the restriction of the negative operation to $\Rtup(n)$.

\begin{zed}
negRtup == \\
\t1	(\lambda n: \nat @ \\
\t2		(\lambda v: \Rtup(n) @ \negRinf v))
\end{zed}

\begin{remark}
The operation $negRtup(n)$ is the inverse operation of the Abelian group $addRtup(n)$.

\begin{zed}
\forall n: \nat @ \\
\t1	negRtup(n) = inverse\_operation(addRtup(n))
\end{zed}

\end{remark}

\subsection{The Zero Real $n$-tuple: \zcmd{zeroRtup}}

Let $\zeroRtup(n)$ denote the $n$-tuple consisting of all zeroes.

\begin{axdef}
	\zeroRtup: \nat \fun \Rinf
\where
	\zeroRtup(0) = \langle \rangle
\also
	\forall n: \nat_1 @ \\
	\t1	\zeroRtup(n) = (\lambda i: 1 \upto n @ \zeroR)
\end{axdef}

\begin{remark}
Every component of $\zeroRtup(n)$ is $\zeroR$.

\begin{zed}
\forall n: \nat @ \\
\t1	\forall i: 1 \upto n @ \\
\t2	(\piRinf i)(\zeroRtup n) = \zeroR
\end{zed}

\end{remark}

\begin{remark}
The tuple $\zeroRtup(n)$ is in $\Rtup(n)$.

\begin{zed}
\forall n: \nat @ \\
\t1	\zeroRtup(n) \in \Rtup(n)
\end{zed}

\end{remark}

\begin{remark}
The tuple $\zeroRtup(n)$ is the identity element of the Abelian group $addRtup(n)$.

\begin{zed}
\forall n: \nat @ \\
\t1	\zeroRtup(n) = identity\_element(addRtup(n))
\end{zed}

\end{remark}

\subsection{Scalar Multiplication of an $n$-tuple: $smulRtup$}

Let $smulRtup(n)$ denote scalar multiplication restricted to $\Rtup(n)$.

\begin{zed}
smulRtup == \\
\t1	(\lambda n: \nat @ \\
\t2		(\lambda c: \R; v: \Rtup(n) @ c \smulRinf v))
\end{zed}

\subsection{The Real Vector Space of $n$-tuples: $vecRtup$}

Let $vecRtup(n)$ denote the real vector space of $n$-tuples.

\begin{zed}
vecRtup == \\
\t1	(\lambda n: \nat @ (addRtup(n), smulRtup(n)))
\end{zed}

\begin{remark}
The pair $vecRtup(n)$ defines a vector space over $\Rtup(n)$.

\begin{zed}
\forall n: \nat @ \\
\t1	vecRtup(n) \in \vecR(\Rtup(n))
\end{zed}

\end{remark}

\subsection{Linear Transformations of $n$-tuples: \zcmd{linRtup}}

Define $\linRtup(n,m)$ to be the set of all linear transformations from $\R^n$ to $\R^m$.
\begin{axdef}
	\linRtup: \nat \cross \nat \fun \power(\Rinf \pfun \Rinf)
\where
	\forall n,m: \nat @ \\
	\t1	\linRtup(n,m) = \homVecR(vecRtup(n), vecRtup(m))
\end{axdef}

\subsection{The Identity Transformation of $n$-tuples: \zcmd{idRtup}}

Let $\idRtup(n)$ denote the identity function on $\Rtup(n)$.

\begin{axdef}
	\idRtup: \nat \fun \Rinf \pfun \Rinf
\where
	\forall n: \nat @ \\
	\t1	\idRtup(n) = \id(\Rtup(n))
\end{axdef}

\begin{remark}
The function $\idRtup(n)$ is a linear transformation.

\begin{zed}
	\forall n: \nat @ \\
	\t1	\idRtup(n) \in \linRtup(n, n)
\end{zed}

\end{remark}

\section{The Metric Topology on Real $n$-tuples}

\subsection{The Dot Product of Tuples: \zcmd{dotRinf}}

The {\it inner} or {\it dot} product of $n$-tuples $v$ and $w$ is the real number $v \dotRinf w$
defined by the sum of the component-wise products.

\begin{axdef}
	\_ \dotRinf \_ : \RinfDelta \fun \R
\where
	\langle \rangle \dotRinf \langle \rangle = \zeroR
\also
	\forall x, y: \R; v, w: \Rinf | \# v = \# w @ \\
	\t1	(\langle x \rangle \cat v) \dotRinf (\langle y \rangle \cat w) = x \mulR y \addR v \dotRinf w
\end{axdef}

Each $\Rtup(n)$ is a real inner product space under the operation of dot product defined above.

\subsection{The Norm of a Tuple: \zcmd{normRinf}}

The norm $\norm{v}$ of the $n$-tuple $v$ is the positive square root of its dot product with itself.
$$
	\norm{v} = \sqrt{v \dotRinf v}
$$

Define $\normRinf(v)$ to be $\norm{v}$.
\begin{axdef}
	\normRinf: \Rinf \fun \R
\where
	\forall v: \Rinf @ \\
	\t1	\normRinf(v) = \sqrtR(v \dotRinf v)
\end{axdef}

The concepts of continuity, limits, and differentiability extend to functions between normed vector spaces such as $\R^n$.

\subsection{The Open Ball at a Tuple: \zcmd{ballRinf}}

Let $\ballRinf(v,r)$ denote the \textit{open ball} in $\Rtup(n)$ of radius $r  \in \Rpos$ centred at $v \in \Rtup(n)$.

\begin{axdef}
\ballRinf: \Rinf \cross \Rpos \fun \power \Rinf
\where
\forall v: \Rinf; r: \Rpos @ \\
\t1	\LET n == \# v @ \\
\t2		\ballRinf(v, r) = \{~ w: \Rtup(n) | \normRinf(v \subRinf w) \ltR r ~\}
\end{axdef}

\subsection{The Set of All Open Balls at an $n$-tuple: \zcmd{ballsRtup}}

Let $\ballsRtup(n)$ denote the family of all open balls in $\Rtup(n)$.

\begin{axdef}
	\ballsRtup: \nat \fun \family~\Rinf
\where
	\forall n: \nat @ \\
	\t1	\ballsRtup(n) =  \{~ v: \Rtup(n); r: \Rpos @ \ballRinf(v,r) ~\}
\end{axdef}

\begin{remark}
The set of all open balls in $\Rtup(n)$ is a family of sets in $\Rtup(n)$.

\begin{zed}
\forall n: \nat @ \\
\t1	\ballsRtup(n) \in \family(\Rtup(n))
\end{zed}

\end{remark}

\subsection{The Usual Topology on $n$-tuples: \zcmd{tauRtup}}

The \textit{usual topology} on $\Rtup(n)$ is the topology generated by the open balls in $\Rtup(n)$.
Let $\tauRtup(n)$ denote the usual topology on $\Rtup(n)$.

\begin{axdef}
	\tauRtup: \nat \fun \family~\Rinf
\where
	\forall n: \nat @ \\
	\t1	\tauRtup(n) = topGen[\Rtup(n)] (\ballsRtup(n))
\end{axdef}

\begin{remark}

If $n \in \nat$ then $\tauRtup(n)$ is a topology on $\Rtup(n)$.

\begin{zed}
	\forall n: \nat @ \tauRtup(n) \in top[\Rtup(n)]
\end{zed}
\end{remark}

\subsection{The Set of All Neighbourhoods of a Tuple: \zcmd{neighRinf}}

Let $v \in \Rtup(n)$.
An open set $U$ in the usual topology $\tauRtup(n)$ that contains $v$
is called a \textit{neighbourhood} of $v$.
Let $\neighRinf(v)$ denote the set of all neighbourhoods of $x$.

\begin{axdef}
\neighRinf: \Rinf \fun \family~\Rinf
\where
\forall n: \nat; v: \Rinf | n = \#v @ \\
\t1	\neighRinf(v) = \{~ U: \tauRtup(n) | v \in U ~\}
\end{axdef}

\begin{remark}

The set of all neighbourhoods of $v \in \Rtup(n)$ is a family of sets in $\Rtup(n)$.

\begin{zed}
\forall n: \nat; v: \Rinf | n = \#v @ \\
\t1	\neighRinf(v) \in \family(\Rtup(n))
\end{zed}

\end{remark}

\subsection{The Topological Space of $n$-tuples: \zcmd{tsRtup}}

Let $\tsRtup(n)$ denote the topological space defined by the usual topology on $\Rtup(n)$.

\begin{axdef}
	\tsRtup: \nat \fun topSpaces[\Rinf]
\where
	\forall n: \nat @ \\
	\t1	\tsRtup(n) = (\Rtup(n), \tauRtup(n))
\end{axdef}

\section{Continuity}

\subsection{Real-Valued Functions That Are Continuous on the Set of All $n$-tuples: \zcmd{CzeroRtup}}

A function $f \in \R^n \fun \R$ is said to be \textit{continuous} if it is continuous with respect to the usual topologies
on $\R^n$ and $\R$.
Let $\CzeroRtup(n)$ denote the set of these continuous functions.

\begin{axdef}
	\CzeroRtup: \nat \fun \power(\Rinf \pfun \R)
\where
	\forall n: \nat @ \\
	\t1	\CzeroRtup(n) = \CzeroTT(\tsRtup(n), \Rtau)
\end{axdef}

\subsection{Real-Valued Functions That Are Continuous on a Subset of $n$-tuples: \zcmd{CzeroSubsetRtup}}

Let $U$ be a subset of $\R^n$.
A function $f \in U \fun \R$ is said to be \textit{continuous on} $U$
if it is continuous with respect to the topology induced on $U$.
Let $\CzeroSubsetRtup(U)$ denote the set of these continuous functions.

\begin{axdef}
	\CzeroSubsetRtup: \DeltaRinf \fun \power(\Rinf \pfun \R)
\where
	\forall U: \DeltaRinf @ \\
	\t1	\LET n == \dimRinf U @ \\
	\t2		\CzeroSubsetRtup(U) = \CzeroTT(\tsRtup(n) \inducedTopSp U, \Rtau)
\end{axdef}

\subsection{Real-Valued Functions That Are Continuous at an $n$-tuple: \zcmd{CzeroPointRtup}}

A partial function $f$ from $\R^n$ to $\R$ is said to be \textit{continuous at} $x \in \R^n$ if its domain contains a neighbourhood $U$ of $x$
such that its restriction to $U$ is continuous on $U$.
Let $\CzeroPointRtup(x)$ denote the set of such functions.

\begin{axdef}
	\CzeroPointRtup: \Rinf \fun \power(\Rinf \pfun \R)
\where
	\forall x: \Rinf @ \\
	\t1	\LET n == \# x @ \\
	\t2		\CzeroPointRtup(x) = \{~ f: \Rtup(n) \pfun \R | \exists U: \neighRinf(x) | U \subseteq \dom f @ U \dres f \in \CzeroSubsetRtup(U) ~\}
\end{axdef}

\subsection{$m$-tuple-Valued Functions That Are Continuous on the Set of All $n$-tuples: \zcmd{CzeroRtupRtup}}

A mapping $f$ from $\Rtup(n)$ to $\Rtup(m)$ is said to be continuous if it is continuous with respect to the usual topologies.
Let $\CzeroRtupRtup(n,m)$ denote the set of these continuous mappings.

\begin{axdef}
	\CzeroRtupRtup: \nat \cross \nat \fun \power(\Rinf \pfun \Rinf)
\where
	\forall n, m: \nat @ \\
	\t1	\CzeroRtupRtup(n,m) = \CzeroTT(\tsRtup(n), \tsRtup(m))
\end{axdef}

\begin{example}
The function $\idRtup(n)$ is continuous.

\begin{zed}
	\forall n: \nat @ \\
	\t1	\idRtup(n) \in \CzeroRtupRtup(n,n)
\end{zed}

\begin{theorem}
Linear functions are continuous.

\begin{zed}
	\forall n, m: \nat@ \\
	\t1	\linRtup(n, m) \subseteq \CzeroRtupRtup(n,m)
\end{zed}

\end{theorem}

\end{example}

\subsection{$m$-tuple-Valued Functions That Are Continuous on a Subset of $n$-tuples: \zcmd{CzeroSubsetRtupRtup}}

Let $U$ be any subset of $\Rtup(n)$.
Let $\CzeroSubsetRtupRtup(U,m)$ denote the set of continuous mappings from the topology induced by $\tsRtup(n)$ on $U$ to $\tsRtup(m)$.

\begin{axdef}
	\CzeroSubsetRtupRtup: \DeltaRinf \cross \nat \fun \power (\Rinf \pfun \Rinf)
\where
	\forall n, m: \nat @ \\
	\t1	\forall U: \DeltaRinf | \dimRinf(U) = n @ \\
	\t2		\CzeroSubsetRtupRtup(U, m) = \CzeroTT(\tsRtup(n) \inducedTopSp U, \tsRtup(m))
\end{axdef}

\begin{remark}

\begin{zed}
	\forall n, m: \nat @ \\
	\t1	\CzeroSubsetRtupRtup(\Rtup(n),m) = \CzeroRtupRtup(n,m)
\end{zed}

\end{remark}

\subsection{$m$-tuple-Valued Functions That Are Continuous at an $n$-tuple:
$VectorConinuous$, \zcmd{CzeroPointRtupRtup}}

Let $x \in \Rtup(n)$ and let $f$ be a partial function from $\Rtup(n)$ to $\Rtup(m)$
whose domain includes some neighbourhood $U$ of $x$ such that $f$ restricted to $U$ is continuous.
In this case $f$ is said to be {\it continuous at $x$}.

\begin{schema}{VectorContinuous}
	n, m: \nat \\
	f: \Rinf \pfun \Rinf \\
	x: \Rinf
\where
	f \in \Rtup(n) \pfun \Rtup(m)
\also
	\exists U: \neighRinf(x) | \\
	\t1	U \subseteq \dom f @ \\
	\t2		U \dres f \in \CzeroSubsetRtupRtup(U,m)
\end{schema}

Let $\CzeroPointRtupRtup(x,m)$ denote the set of all partial functions $f$ from $\Rtup(n)$ to $\Rtup(m)$
that are continuous at $x$.

\begin{axdef}
	\CzeroPointRtupRtup: \Rinf \cross \nat \fun \power (\Rinf \pfun \Rinf)
\where
	\forall n, m: \nat @ \forall x: \Rtup(n)  @ \\
	\t1	\CzeroPointRtupRtup(x, m) = \\
	\t2		\{~ f: \Rtup(n) \pfun \Rtup(m) | VectorContinuous ~\}
\end{axdef}

\begin{example}
The function $\idRtup(n)$ is continuous at every point $x \in \Rtup(n)$.

\begin{zed}
	\forall n: \nat @ \forall x: \Rtup(n) @ \\
	\t1	\idRtup(n) \in \CzeroPointRtupRtup(x, n)
\end{zed}

\end{example}

\begin{theorem}
Linear functions are continuous everywhere.

\begin{zed}
	\forall n, m: \nat @ \\
	\t1	\forall x: \Rtup(n); L: \linRtup(n,m) @ \\
	\t2		L \in \CzeroPointRtupRtup(x, m)
\end{zed}

\end{theorem}

\section{Differentiability}

Let $x \in \R^n$ and let $f: \R^n \pfun \R^m$ be continuous at $x$.
Then $f$ is said to be {\it differentiable at $x$} if there exists a linear transformation $L: \R^n \fun \R^m$
such that $f(x + h) - f(x)$ is approximately linear in $h$ for very small $h$.
$$
f(x + h) - f(x) \approx  L(h) + O(h^2) \quad \text{when} \quad \norm{h} \approx 0
$$

This condition can be written as a limit.
$$
\lim_{h \to 0} \frac{\norm{f(x+h) - f(x) - L(h)}}{\norm{h}} = 0
$$

\subsection{The Difference Quotient: $DifferenceQuotient$ and $diffQuot$}

The limit exists when the following difference quotient function $q: \R^n \pfun \R$ is continuous at $0$.
$$
q(h) =
\begin{cases}
	\frac{\norm{f(x+h) - f(x) - L(h)}}{\norm{h}}	&	\text{if } h \neq 0\\
	0								&	\text{otherwise}
\end{cases}
$$

Given a function $f$ that is continuous at $x$, and a linear transformation $L$,
we can define the difference quotient $q$.
Clearly $q$ is uniquely determined by $f$, $x$, and $L$.
Let $DifferenceQuotient$ denote this situation.

\begin{schema}{DifferenceQuotient}
	VectorContinuous \\
	L: \Rinf \pfun \Rinf \\
	q: \Rinf \pfun \R
\where
	L \in \linRtup(n, m)
\also
	\dom q = \{~ h: \Rtup(n) | x \addRinf h \in \dom f ~\}
\also
	\forall h: \dom q | h \neq \zeroRtup(n) @ \\
	\t1	q(h) = \normRinf(f(x \addRinf h) \subRinf f(x) \subRinf L(h)) \divR \normRinf(h)
\also
	q(\zeroRtup(n)) = \zeroR
\end{schema}

\begin{itemize}
\item $L$ is a linear transformation from $\Rtup(n)$ to $\Rtup(m)$.
\item The difference quotient $q$ is defined on a subset of $\Rtup(n)$ that contains $\zeroRtup(n)$.
\item $q(h)$ is defined as the quotient when $h$ is non-zero.
\item $q(0)$ is defined as zero.
\end{itemize}

Let $diffQuot(f,x,L)$ denote the difference quotient $q$.

\begin{zed}
diffQuot == \{~ DifferenceQuotient @ (f, x, L) \mapsto q ~\}
\end{zed}

\subsection{The Derivative of a Continuous $m$-tuple-Valued Function: $VectorDifferentiable$}

The continuous function $f$ is \textit{differentiable at} $x$ when there exists a linear transformation $L$
such that the difference quotient $q$ is continuous at $0$.
In this case $L$ is unique and is referred to as the \textit{derivative at} $x$.

\begin{schema}{VectorDifferentiable}
VectorContinuous \\
L: \Rinf \pfun \Rinf
\where
\LET q == diffQuot(f, x, L) @ \\
\t1	q \in \CzeroPointRtup(\zeroRtup(n))
\end{schema}

\begin{itemize}
\item The continuous function $f$ is differentiable at $x$ with derivative $L$ if the resulting
difference quotient $q$ is continuous at $\zeroRtup(n)$.
\end{itemize}

\begin{remark}
If $L$ exists then it is unique.
\end{remark}

Let $\smoothRnm(x,m)$ denote the set of all functions $f \in \Rtup(n) \pfun \Rtup(m)$ that are smooth at $x \in \Rtup(n)$.

\printbibliography

\end{document}


\documentclass{article}
\usepackage{graphicx}
\usepackage{amssymb,amsmath}
\usepackage{breqn}
\usepackage{fancyhdr}
\pagestyle{fancyplain}
\rhead{Prepared by Adam Beardsley on \today}

\begin{document}

\section{Image to PS Notes}

We start with an image of the sky, $I_{Jy}(\theta_x,\theta_y,f)$, in units of Jy / str. We can convert to temperature units using the Rayleigh-Jeans law.
\begin{equation}
I_T(\theta_x,\theta_y,f) = 10^{-23}\frac{c^2 \;\text{str}}{2 f^2 k_B} I_{Jy}(\theta_x,\theta_y,f)
\end{equation}
$A_b$ is the array beam in steradians. The factor of $10^{-23}$ in front is for the conversion from Jy to SI units ($10^{-26}$), and from K to mK ($10^{3}$). In this space we can easily convert angles and frequency to physical space (Mpc) using the following transformations (Morales and Hewitt, 2004).
\begin{subequations}\label{eq:transformations}
\begin{align}
r_x & = D_M(z) \theta_x \\
r_y & = D_M(z) \theta_y \\
r_z & = \frac{c(1+z)^2}{H_0 f_{21} E(z)} \Delta f
\end{align}
\end{subequations}
Where $r_z$ is measured relative to the closest distance line-of-sight of the observation, and $\Delta f$ is the channel frequency relative to the top of the observing band.

The next step is to Fourier transform the image to $k-$space. This is done in practice with a two dimensional discrete transform in the perpendicular direction and a FFT in the parallel direction. Mathematically all three steps can be written with a sum over all three dimensions of $\mathbf{r}$, where the indices $i,j$ indicate that $\mathbf{r}$ and $\mathbf{k}$ are discrete.
\begin{equation}
\tilde{I}(\mathbf{k}_j) = \sum_{\mathbf{r}_i} I(\mathbf{r}_i)e^{-i \mathbf{k}_j \cdot \mathbf{r}_i} \Delta r_x \Delta r_y \Delta r_z
\end{equation}
This expression has units of mK Mpc$^3$. I will drop the indices to simplify notation.

Next we square and relate to the power spectrum (e.g. Morales and Wyithe, 2010).
\begin{equation}
\left<\left|\tilde{I}(\mathbf{k})\right|^2\right> = \frac{1}{(2\pi)^3}\int P(\mathbf{k}')\left|W(\mathbf{k}-\mathbf{k}')\right|^2 d^3\mathbf{k}'
\end{equation}
Note in previous versions of this memo, the $2\pi$'s were omitted. Correspondence with Matt McQuinn confirmed they should be there.
The window function is compact and sharply peaked in $k-$space, so we approximate the power spectrum to be constant over the integral (e.g. Bowman, 2006). We then arrive at our estimate of $P(\mathbf{k})$.
\begin{equation}\label{eq:PS}
\hat{P}(\mathbf{k}) = \frac{\left<\left|\tilde{I}(\mathbf{k}\right|^2\right> }{ \frac{1}{(2\pi)^3}\int \left|\widetilde{W}(\mathbf{k}-\mathbf{k}')\right|^2 d^3\mathbf{k}'}
\end{equation}

The integral of the window function is determined by the bandwidth and field of view of the instrument (See e.g. Morales, 2005; Morales and Hewitt, 2004; and Bowman, 2006). In our units system this is given by
\begin{equation}
\frac{1}{(2\pi)^3} \int \left|\widetilde{W}(\mathbf{k}-\mathbf{k}')\right|^2 d^3\mathbf{k}' = \int \left|W(\mathbf{r}-\mathbf{r}')\right|^2 d^3 \mathbf{r}' \approx D_M(z)^2 \Omega \Delta D
\end{equation}
where $\Omega$ is the solid angle of the observation, and $\Delta D$ is the extent of the observation in the line-of-sight direction. This integral has units of Mpc$^3$. Thus our units for the power spectrum in Eq. \ref{eq:PS} are mK$^2$ Mpc$^3$ as expected.

\section{Detailed Window Function Calculation}
We can calculate the integrated window function for zenith pointing analytically using a MWA beam model. We treat a tile as a set of short dipoles sitting above a ground plane. The dipoles will have relative phases with respect to one another based on the direction of some source. We will calculate the response for an individual dipole at location $(x_i,y_i,h)$ relative to the center of the tile. The vertical component, $h$, is the height of the dipole, and we will assume it is the same for all dipoles on a single tile.

The phase difference for the dipole is found using simple geometry.
\begin{equation}
\Delta\phi_i = \frac{2\pi}{\lambda} (x_i \sin\theta_x+y_i \sin\theta_y)
\end{equation}

In addition to the phase differences, the ground plane also serves as an amplitude modulation. If the reflected wave is in phase with the incoming wave, the dipole will have twice the response as if the plane was not there. On the other hand, if the reflection is completely out of phase, the dipole will have zero response. We can derive the form of the amplitude modulation using geometry again. This time we find the phase difference between the incident wave and the reflected wave. The reflected part can be found by modeling the path difference between the true dipole above the plane and a virtual dipole below the plane.

\begin{equation}
\Delta D = 2 h \cos\theta_z
\end{equation}
Here $\theta_z$ is the zenith angle. The phase will be given by this path difference as well as a $\pi$ flip at the ground plane interface.
\begin{equation}
\Delta\phi_{r,i} = \pi + \frac{2 \pi}{\lambda} (2h \cos\theta_z)
\end{equation}

Because this phase is independent of dipole (assumed $h$ is the same for all dipoles), we can solve for the amplitude of the incident plus reflected wave.
\begin{subequations}
\begin{align}
A & = \left|1 + e^{i \Delta \phi_r} \right| \\
& = \left( (1 + \cos(\Delta \phi_r))^2 + (\sin(\Delta \phi_r))^2\right)^{1/2} \\
& = \left(1 + 2\cos(\Delta \phi_r) + \cos^2(\Delta\phi_r) + \sin^2(\Delta\phi_r) \right)^{1/2} \\
& = \left(2(1+\cos(\Delta \phi_r))\right)^{1/2} \\
& = 2 \left|\cos(\Delta \phi_r/2)\right| \\
& = 2 \left|\cos\left(\pi/2 + \frac{2 \pi}{\lambda}h \cos\theta_z\right))\right| \\
& = 2 \sin\left(\frac{2 \pi}{\lambda}h \cos\theta_z\right)
\end{align}
\end{subequations}

The dipole will be sensitive only to radiation with polarization aligned along its axis. Due to the orthogonality between direction of propagation and polarization, a non polarized source will appear polarized to the instrument if it is off zenith. For a dipole with single polarization, the amplitude attenuation is given by
\begin{equation}
P = 1-\sin(\theta_z)\cos(\theta_{az}),
\end{equation}
where $\theta_{az}$ is the azimuth angle.

The response for the dipole is then given by
\begin{subequations}
\begin{align}
R_i &= APe^{i \Delta \phi_i} \\
& = 2 \sin\left(\frac{2\pi}{\lambda}h\cos\theta_z\right) \mathrm{exp}\left[\frac{2\pi i}{\lambda}(x_i \sin\theta_x + y_i cos\theta_y)\right]\left(1-\sin(\theta_z)\cos(\theta_{az})\right)
\end{align}
\end{subequations}

Next we construct the response for the full tile by summing over the dipoles. We can leverage the symmetry of the tile by defining a horizontal space, $\delta_x$, which we will assume to be uniform.
\begin{subequations}
\begin{align}
R_{tile} &= \sum_i R_i \\
& = \sum_i 2 \sin\left(\frac{2\pi}{\lambda}h\cos\theta_z\right) \mathrm{exp}\left[\frac{2\pi i}{\lambda}(x_i \sin\theta_x + y_i cos\theta_y)\right]\left(1-\sin(\theta_z)\cos(\theta_{az})\right) \\
& = 2 \sin\left(\frac{2\pi}{\lambda}h\cos\theta_z\right) \sum_j \sum_k  \mathrm{exp}\left[\frac{2\pi i}{\lambda}(j \delta_x \sin\theta_x + k \delta_x cos\theta_y)\right]\left(1-\sin(\theta_z)\cos(\theta_{az})\right)
 \end{align}
\end{subequations}
The $j$ and $k$ sums are over the half integers -3/2, -1/2, 1/2, and 3/2.

In the approximation that the tiles are identical (and thus have the same $R_{tile}$), the window function is simply the magnitude squared of the response. We also normalize the window so that at phase center it is equal to unity. Further, the window function in general is a function of the frequency, but we will assume it is constant within a channel.
\begin{equation}
W(\theta_x,\theta_y,f) = \frac{\left|R_{tile}(\theta_x,\theta_y)\right|^2}{\left|R_{tile}(0,0)\right|^2}
\end{equation}

Next we can use the transformations from Eq. \ref{eq:transformations} to rewrite the window function in terms of cosmological axes ($\mathbf{r}$). With some simplification we arrive at the following for the window function squared.
\begin{dmath}
\left| W(\mathbf{r})\right|^2 = \frac{1}{256 \left|\sin\left(\frac{2\pi h}{\lambda}\right)\right|^4} \left| \sin\left(\frac{2\pi h \cos(\frac{\sqrt{r_x^2+r_y^2}}{D_m})}{\lambda}\right) \times \\ \\
\left(\cos\left(\frac{\pi \delta_x \sin(r_x/D_m)}{\lambda}\right)+\cos\left(\frac{3\pi \delta_x \sin(r_x/D_m)}{\lambda}\right) \right) \times \\ \\
\left(\cos\left(\frac{\pi \delta_x \sin(r_y/D_m)}{\lambda}\right)+\cos\left(\frac{3\pi \delta_x \sin(r_y/D_m)}{\lambda}\right) \right)\right|^4 \times \\ \\
\left(1-\sin\left(\frac{\sqrt{r_x^2+r_y^2}}{D_m}\right)\frac{r_y}{\sqrt{r_x^2+r_y^2}}\right)^4
\end{dmath}

This can then be integrated (probably numerically) to arrive at our estimate of the integrated window function (with the assumptions of identical tiles phased at zenith). As an example I compute this integral for observing parameters shown in Table \ref{tbl:obs_params}, and find
\begin{equation}
\int |W(\mathbf{r})|^2d^3 \mathbf{r} \approx 7.0 \times 10^8 \text{ Mpc}^3
\end{equation}

\begin{table}
\begin{center}
\begin{tabular}{l c c}
\hline
Parameter & Symbol & Value \\
\hline
Redshift & $z$ & 8 \\
Wavelength & $\lambda$ & 1.90 m \\
Dipole spacing & $\delta_x$ & 1.1 m \\
Dipole height & $h$ & 0.35 m \\
Bandwidth & $B$ & 8 MHz
\end{tabular}
\caption{Observing and instrument parameters for example calculation}
\label{tbl:obs_params}
\end{center}
\end{table}

\section{Calculating Window Function from Ian's Data Cubes}

We now aim to calculate the above integral from the data cubes that Ian produces with FHD. In particular, these are cubes of the weights and the variance of each pixel (in image space). Let the symbols for these cubes be $w$ and $\sigma^2$ respectively. I will continue to use a capital $W$ for the window function.

The first step is to Fourier transform the weights and variances to $(k_x,k_y,r_z)$ space. This is the space in which the weights and variances are non-covariant and easiest to manipulate.

We begin by relating the weights cube $w$ to the sampled window function. There may be a normalization difference, which we will solve for, and the weights account for all the gridded visibilities ($N_{\text{vis}}$) rather than a single beam. The same factors come into the variance cube. So we can write,
\begin{subequations} \label{eq:relate_w_to_W}
\begin{align}
\sum_{\text{beam}} W(k_{\perp},r_z) & = \frac{1}{N_{\text{vis}}} \sum_{\text{cube}} W_0 w(k_{\perp},r_z) \\
\sum_{\text{beam}} |W(k_{\perp},r_z)|^2 & = \frac{1}{N_{\text{vis}}} \sum_{\text{cube}} |W_0|^2 \sigma^2(k_{\perp},r_z)
\end{align}
\end{subequations}
where $W_0$ is the normalization constant.

Next we solve for $W_0$ by forcing $W(r_x=0,r_y=0,r_z) = 1$ (as in the previous section). The window function is $\mathbf{r}$ space is related to the window function in $(k_{\perp},r_z)$ space by a two dimensional inverse Fourier transform. Our convention for the Fourier transform did not have $2\pi$ in going from $k$ to $r$, so now we must include it.
\begin{equation}
W(\mathbf{r}) = \frac{1}{(2\pi)^2} \int W(k_{\perp},r_z) e^{i \mathbf{k}_{\perp} \cdot \mathbf{r}_{\perp}} d^2 k_{\perp}
\end{equation}
We can then evaluate when $r_{\perp}=0$ and apply our normalization.
\begin{equation}
W(r_{\perp}=0,r_z) =  \frac{1}{(2\pi)^2} \int W(k_{\perp},r_z) d^2 k_{\perp} = 1
\end{equation}
This integral can be approximated with a sum and related to the weights using Eq. \ref{eq:relate_w_to_W} to solve for $W_0$.
\begin{subequations} \label{eq:solve_W0}
\begin{align}
1 & = \frac{1}{(2\pi)^2} \int W(k_{\perp},r_z) d^2 k_{\perp} \\
& \approx  \frac{1}{(2\pi)^2} \sum_{\text{beam}} W(k_{\perp},r_z) (\Delta k_{\perp})^2 \\
& =  \frac{(\Delta k_{\perp})^2}{N_{\text{vis}}(2\pi)^2} \sum_{\text{cube}} W_0  w(k_{\perp},r_z) \\
\rightarrow W_0 & = \frac{N_{\text{vis}}(2\pi)^2}{(\Delta k_{\perp})^2} \frac{1}{\sum_{\text{cube}} w(k_{\perp},r_z)}
\end{align}
\end{subequations}
Note that this result is dependent on our normalization choice which is only true at zenith pointing and phase center. So the sum over the weights should be done for that particular case, and used for other pointings and phase centers in the following work.

Armed with a solution for $W_0$ we now seek to solve the integral in question.
\begin{subequations}
\begin{align}
\int |W(\mathbf{r})|^2 d^3 \mathbf{r} & = \frac{1}{(2\pi)^2} \int |W(k_{\perp},r_z)|^2 d^2k_{\perp}d r_z \\
& \approx \frac{\Delta D}{(2\pi)^2} \sum_{\text{beam}} |W(k_{\perp},r_z)|^2 (\Delta k_{\perp})^2 \\
& = \frac{\Delta D (\Delta k_{\perp})^2}{(2\pi)^2} \frac{1}{N_{\text{vis}}} \sum_{\text{cube}} |W_0|^2 \sigma^2(k_{\perp},r_z) \\
& = \frac{\Delta D (\Delta k_{\perp})^2}{(2\pi)^2 N_{\text{vis}}} \frac{N_{\text{vis}}^2(2\pi)^4}{(\Delta k_{\perp})^4} \frac{\sum_{\text{cube}} \sigma^2(k_{\perp},r_z)}{\left|\sum_{\text{cube}} w(k_{\perp},r_z)\right|^2}  \\
& = \frac{(2\pi)^2 \Delta D N_{\text{vis}}}{(\Delta k_{\perp})^2} \frac{\sum_{\text{cube}} \sigma^2(k_{\perp},r_z)}{\left|\sum_{\text{cube}} w(k_{\perp},r_z)\right|^2}
\end{align}
\end{subequations}
In the first step we used Parseval's theorem to relate the integral of the function squared in one space to the integral of the Fourier transform squared. The second step is approximating the integral as a sum, and doing the trivial integral over $r_z$ (the window is assumed to be constant over the band). Next we make use of Eq. \ref{eq:relate_w_to_W} to replace the sum over the window function. The fourth step is using the result of Eq. \ref{eq:solve_W0} to plug in for $W_0$. Finally we simplify in the last step. It is worth noting that the units of our final expression are Mpc$^3$, as expected.

This result should allow for a check on the data pipeline by comparing this calculation to that of the previous section. There are still a few outstanding questions (in my mind anyway):
\begin{itemize}
  \item Is the normalization correct? I believe there are assumptions in the noise calculations that require the window function to be normalized to the collecting area. How exactly is that done? \\ \\
 { \bf Answer:} The normalization is fixed by how we do our calibration. By saying that our apparent flux of a source on phase center is equal to the true flux of that source, we have set the normalization of the window function to be unity at phase center. So the assumption above is correct.
  \item In what space should the integral be computed? In the past we have said it doesn't matter if the integral is done in $r$ or $k$ space because of Parseval's theorem. However, there are $2\pi$'s relating the two spaces, and it is important to use the correct version.
  \item There are probably more\ldots will add when I think of them.
\end{itemize}

\section{A couple notes on W-projection}
For computational reasons, we seek to estimate the effect W-projection has on our longest baselines. Let us consider a single baseline, projected onto a plane perpendicular to the line of pointing.
\begin{figure}[h!]
\includegraphics[width=\columnwidth]{W_projection.png}
\caption{A projected baseline with non zero pointing.}
\label{fig:proj_base}
\end{figure}
Let $b$ represent the longest baseline, and $b'$ represent the projected baseline. We wish to find the ratio $b'/b$.

By inspection we can see that the projected baseline length can be determined from a pure geometric projection combined with the diffraction opening angle, $\alpha$. Mathematically,
\begin{equation}
b' = b\cos(\theta) + x = b\cos(\theta) + b\sin(\theta)\tan(\alpha).
\end{equation}
Alpha is approximately half of the primary beam width. So our ratio becomes
\begin{equation} \label{eq:bprimeb}
\frac{b'}{b} = \cos(\theta) + \sin(\theta)\tan(\mathrm{FoV}/2)
\end{equation}
We can plot this ratio as a function of $\theta$ for a conservative field of view of 40$^{\circ}$ (Fig. \ref{fig:bprimeb}).
\begin{figure}[h!]
\includegraphics[width=\columnwidth]{bprimeb.png}
\caption{Projected baseline ratio as a function of pointing angle.}
\label{fig:bprimeb}
\end{figure}

We are mostly interested in the maximum of this ratio. We set the derivative with respect to theta equal to zero and solve.
\begin{subequations}
\begin{align}
\frac{\partial}{\partial\theta}(b'/b)  = -\sin(\theta) + \cos(\theta)\tan(\mathrm{FoV}/2) &= 0 \\
 \tan(\theta_{max}) & = \tan(\mathrm{FoV}/2) \\
 \rightarrow \theta_{max} &= \mathrm{FoV}/2
\end{align}
\end{subequations}
Plugging this result back into Eq. \ref{eq:bprimeb}, we have the maximum ratio for a given field of view.
\begin{subequations}
\begin{align}
\left.\frac{b'}{b}\right\vert_{\theta_{max}} & = \cos(\mathrm{FoV}/2) + \sin(\mathrm{FoV}/2)\tan(\mathrm{FoV}/2) \\
& = \sec(\mathrm{FoV}/2)
\end{align}
\end{subequations}

\end{document}


\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1em}

\begin{document}

\section{Functions in number theory}
\subsection{Rules}
\begin{enumerate}
\item
\textbf{Fermat's little theorem.} \\
For prime $p$ and integer $a$
$$a^p \equiv a \mod p$$

\item
\textbf{Wilson's theorem.} \\
$$(p-1)! \equiv -1 \mod p$$
if and only if when $p$ is prime number.

\item
\textbf{Number of factors} \\
The number of positive factors of $n=p_1^{\alpha_1} \dots p_k^{a_k}$
$$d(n)= (\alpha_1+1)(\alpha_2+1)\dots (\alpha_k+1)$$
\item
\textbf{Sum of factors} \\
The sum of positive factors of $n=p_1^{\alpha_1} \dots p_k^{a_k}$

$$\sigma(n)= \frac{p_1^{\alpha_1+1}-1}{p_1-1} \dots  \frac{p_k^{\alpha_k+1}-1}{p_k-1}$$

\item
\textbf{Euler's function} \\
Euler’s function or totient function $\varphi(n)$ is defined for $n=p_1^{\alpha_1} \dots p_k^{a_k}$ as the number
of positive integers less than $n$ and coprime to $n$. Then
$$\varphi(n) = n \left(1-\frac{1}{p_1}\right) \dots  \left(1-\frac{1}{p_k}\right)$$

\item
\textbf{Euler's theorem}  (Generalisation of Fermat's theorem)\\
Let $n$ be a natural number and $a$ an integer such that $\gcd(a,n)=1$. Then
$$a^{\varphi(n)} \equiv 1 \mod n $$

\end{enumerate}

\subsection{Problems}
\begin{enumerate}

\item
Find all primes $p$, for which the sum of all positive factors of $p^4$ is a perfect square.

\item
Prove that for positive integer $n$
$$\sum_{d|n} \varphi (d) =n $$

\item
Prove that for positive integers $a$ and $b$
$$ \varphi(ab) = \varphi (a)\varphi(b)\frac{\gcd(a,b)}{\varphi(\gcd(a,b))} $$

\item % https://artofproblemsolving.com/wiki/index.php?title=Fermat%27s_Little_Theorem#Problems
One of Euler's conjectures was disproved in the 1960s by three American mathematicians when they showed there was a positive integer such that $133^5+110^5+84^5+27^5=n^5$. Find the value of ${n}$.

\item  %p46 http://s3.amazonaws.com/aops-cdn.artofproblemsolving.com/resources/articles/olympiad-number-theory.pdf
How many prime numbers $p$ are there, such that $29^p+1$ is a multiple of $p$?

\item
Prove that if $\gcd(a,n)=1$, then
$$a^b \equiv a^{b \mod \varphi(n)}  \mod n$$

\item % http://s3.amazonaws.com/aops-cdn.artofproblemsolving.com/resources/articles/olympiad-number-theory.pdf
Find the last three digits of $2008^{2007^{2006^{\dots^{^{}2^{1}}}}}$.

\item
Prove that there exists no positive integer for which $n! + 19^{93}$ is a perfect square.

\item
Find all pairs of positive prime numbers $(p_1,p_2)$ for which the equation $$\phi(n^2) = n + p_1p_2$$
has a solution for $n$ in positive integers.

\item % http://www.math.olympiaadid.ut.ee/eng/archive/bw/bw05sol.pdf

Let $p$ be a prime number and let $n$ be a positive integer. Let $q$ be a positive divisor of $(n+1)^p-n^p$. Show that $q-1$ is divisible by $p$.

\end{enumerate}

\end{document}


%!TEX root =  ../main.tex

\subsection{Indeterminate Forms}

\objective{Classify difficult limits problems and solve via certain techniques}

Just as we used limits to define the derive six chapters ago, now they return the favor
and derivatives themselves allow us to find certain limits.  We have seen how removable
discontinuities take the form $\frac{0}{0}$, but what are we to do if a derivative
produce that form?  In fact, there are many forms which mathematicians classify
as \textbf{indeterminate}

$$
\frac{0}{0} , \frac{\infty}{\infty} , 0\times\infty , \infty-\infty , 0^0 , ^\infty \text{, and } \infty^0
$$

These are all indicative of a variety of answers, some finite, some infinite.  There is
no way to know what answer will predominate in the end without more work.
Consider this limit
\begin{equation}
\lim_{x\rightarrow0}\frac{5x}{\ln(x+1)}
\end{equation}
Obviously, if we attempt a direct evaluation, we get a meaningless answer.  But
consider what we know about this quotient function.  Every ``nudge'' in the $x$
direction (dx) will produce a small change in the top half of the fraction: 5dx, to
be precise.  Similarly, the change in the denominator (it's implicit differential)
is $\frac{1}{x+1}$dx.  As a fraction, this is $\cfrac{5dx}{\frac{1}{x+1}dx}$ or
$5(x+1)$.  Notice this is not like the maneuvering we did with removable
discontinuities; we have not constructed an identical but hole-less version
of the equation.  Our new equation is useful because it goes through the hole.

This technique for solving limits at indeterminate value is call \textbf{L'Hopital's}
Rule (LO-pee-talz), even though it was found by L'Hopital's collegue Bernoulli.

\personfeature[0in]{\chapdir/pics/Leopold_Kronecker_1865}{Leopold Kronecker}{1823 -
1891}{was a German mathematician who worked on number theory, algebra and logic.
He criticized Cantor's work on set theory, and said, ``God made the integers,
all else is the work of man.''  He studied elliptic functions and conjectured his
``dearest dream of youth", a generalization that was later put forward by
Hilbert in a modified form as his twelfth problem.
\href{https://en.wikipedia.org/wiki/Leopold_Kronecker}{Wikipedia}}

\subsection{Infinite Forms}
Not every form with a zero in the denominator or an infinity in it is indeterminate.
The following forms resolve in other ways, and cannot be solved with L'Hopital's
Rule:
$$
\frac{1}{0} , \frac{\infty}{1} , \frac{\infty}{0} , \infty + \infty , \infty \times\infty
$$

Some other fractions you should recognize from algebra and/or experience as zero:
$$
\frac{0}{1} = \frac{1}{\infty} = \frac{0}{\infty}
$$

To return to our earlier equation of $\frac{5x}{\ln(x+1)}$, what is the limit as $x$
approaches infinity?  Logarithmic graphs \emph{seem} to taper off, and direct
evaluation is useless (plugging in infinity for $x$) because we get $\frac{\infty}{\infty}$.
But L'Hopital's Rule works here too, because that is an indeterminate form.
Our limit will be the same as
\begin{equation}
\lim_{x\rightarrow0}5(x+1)
\end{equation}
which is infinite.


\section{Previous work}
\label{sec:previous:work}

First of all, we recall some modular arithmetic fundamentals. Let
$a,b\in\mathbb{Z}$ and $n\in\mathbb{N}$, \textit{$a$ is congruent to $b$ modulo
$n$}, written as $a \equiv_{n} b$, if $a \mod n = b \mod n$; from this, follows
that $n \left| (a-b)\right.$ and $a - b = nk$, for some $k\in\mathbb{Z}$, are
equivalent definitions.

%\subsection{Lucas theorem exposed}

In \cite{fine:1947}, Fine exposes the following theorem which is a fundamental
result for our work,

\begin{theorem}[Lucas] Let $p$ be a prime and $m,n\in\mathbb{N}$, then
    \begin{displaymath}
        {{m}\choose{n}} \equiv_{p}
            {{m_{0}}\choose{n_{0}}}
            {{m_{1}}\choose{n_{1}}}
            \cdots
            {{m_{k}}\choose{n_{k}}}
    \end{displaymath}
    representing $m=\left(m_{0},m_{1},\ldots,m_{k}\right)_{p}$ and
    $n=\left(n_{0},n_{1},\ldots,n_{k}\right)_{p}$ in base $p$, for some $k\in\mathbb{N}$.
    \iffalse
    So both $m_{j}$ and $n_{j}$ are in $\lbrace 0,\ldots, p-1 \rbrace$, for
    $j\in\lbrace 0,\ldots,k\rbrace$.
    \fi
    \label{thm:lucas:theorem}
\end{theorem}

\iffalse
\begin{proof}
    Consider the sequence
    $\vect{\alpha}_{m}=\left({{m}\choose{n}}\right)_{n\in\mathbb{N}}$ of
    binomial coefficients which count the number of $n$-elements subsets out of
    a set composed by $m$ elements. We use $\vect{\alpha}_{m}$ to
    define a formal power series on the indeterminate variable $t$ and its generating
    function
    \begin{displaymath}
        %\begin{split}
            \sum_{n=0}^{m}{{{m}\choose{n}}\,t^{n}} %&
                = \left(1+t\right)^{m}
                = \left(1+t\right)^{m_{0}+m_{1}p+\cdots+m_{k}p^{k}}%\\
                %&
                = \prod_{r=0}^{k}{{\left(1+t\right)^{m_{r}p^{r}}}}
                = \prod_{r=0}^{k}{\left(\left(1+t\right)^{p^{r}}\right)^{m_{r}}}
        %\end{split}
    \end{displaymath}
    where $m=\left(m_{0},m_{1},\ldots,m_{k}\right)_{p}$ is represented in
    base $p$. The expansion of $\left(1+t\right)^{p^{r}}$ yields
    \begin{displaymath}
            \left(1+t\right)^{p^{r}} = \sum_{s=0}^{p^{r}}{{{p^{r}}\choose{s}}\,t^{s}}
                = 1+\sum_{s=1}^{p^{r}-1}{{{p^{r}}\choose{s}}\,t^{s}}+t^{p^{r}}
    \end{displaymath}
    and the application of the congruence relation $\equiv_{p}$ makes the last sum
    vanish because $\displaystyle p\left|{{p^{r}}\choose{s}}\right.$, therefore
    $\left(1+t\right)^{p^{r}} \equiv_{p} 1+t^{p^{r}}$ holds and it allows us to rewrite
    the products as
    \begin{displaymath}
            \prod_{r=0}^{k}{\left(\left(1+t\right)^{p^{r}}\right)^{m_{r}}}
                \equiv_{p} \prod_{r=0}^{k}{\left(1+t^{p^{r}}\right)^{m_{r}}}
                \equiv_{p} \prod_{r=0}^{k}{\sum_{s_{r}=0}^{m_{r}}{{{m_{r}}\choose{s_{r}}}t^{s_{r}p^{r}}}}.
    \end{displaymath}
    there is a product of $k+1$ formal power series, properly shifted according to
    $p_{0},p_{1},\ldots,p_{k}$: such product yields a new formal power series which satisfies
    \begin{displaymath}
        \sum_{n=0}^{m}{{{m}\choose{n}}\,t^{n}}
        \equiv_{p}
        \sum_{n=0}^{m}{\left(\sum_{\vect{\omega}\in\Omega_{n}}{\prod_{i=0}^{k}{{{m_{i}}\choose{\omega_{i}}}}}\right)\,t^{n}}
    \end{displaymath}
    where $\Omega_{n}=\left\lbrace\vect{\omega}=\left(\omega_{0},\ldots,\omega_{k}\right):
        \sum_{j=0}^{k}{\omega_{j}p^{j}}=n\right\rbrace$.
    There exists a \emph{unique} set of coefficients
    $\lbrace n_{0},n_{1},\ldots,n_{k}\rbrace$ such that $n=\sum_{j=0}^{k}{n_{j}p^{j}}$, therefore
    each set $\Omega_{n}$ contains only one element, namely $\vect{\omega}=(n_{0},\ldots,n_{k})$, so
    \begin{displaymath}
        \sum_{n=0}^{m}{{{m}\choose{n}}\,t^{n}}
        \equiv_{p} \sum_{n=0}^{m}{\left({\prod_{i=0}^{k}{{{m_{i}}\choose{n_{i}}}}}\right)\,t^{n}}
    \end{displaymath}
    holds and the argument follows by equating coefficients attached to $t^{n}$,
    %for $n\in\lbrace0,\ldots,m\rbrace$,
    as required.

\end{proof}
\fi

%\subsection{Divisibility -- with visibility}

In \cite{sved:1988}, Marta Sved gives solid bases to understand
\textit{divisibility properties} of some \emph{counting numbers}, namely
coefficients occurring in combinatorics such as binomials and Stirling numbers,
that shows divisibility structures of remarkable design.

She starts working on the Pascal triangle $\mathcal{P}$, whose coefficients
are defined by the recurrence
\begin{equation}
    {{n}\choose{k}}={{n-1}\choose{k-1}}+{{n-1}\choose{k}},
    \label{eq:binomial:recurrence}
\end{equation}
and studies a new triangle $\mathcal{P}_{\equiv_{p}}$ obtained from
$\mathcal{P}$ where each coefficient is taken modulo $p$, for some small prime
number $p$. Besides, she introduces a little language that allows her to
characterize these "modular" triangles and we readly adopt it as well.

Let $\mathcal{M}=\left(m_{n,k}\right)_{n,k\in\mathbb{N}}$ be an infinite, lower
triangular array so that $m_{n,k}=0$ if $n<k$. Choose a prime $p$, then the
array $\displaystyle\mathcal{M}_{\equiv_{p}} = \left(m_{n,k}\mod p :
m_{n,k} \in \mathcal{M}\right)_{n,k\in\mathbb{N}}$ contains the following regions
\begin{itemize}

\item a \emph{principal cell} $\mathcal{M}_{\equiv_{p}}^{\bigtriangleup} =
        \left(m_{n,k}\in \mathcal{M}_{\equiv_{p}}\right)_{n,k\in\lbrace 0,\ldots,p-1\rbrace}$;

\item a \emph{cell} $c_{p,\beta}=\left( \beta\,m_{n,k}\mod p:m_{n,k}\in
\mathcal{M}_{\equiv_{p}}^{\bigtriangleup}\right)_{n,k\in\mathbb{N}}$ which is a
copy of the \emph{principal cell} with each entry multiplied by the same
constant $\beta\in\mathbb{N}$;

\item a \emph{principal cluster} $\mathcal{M}_{\equiv_{p}}^{(\alpha)} =
\left(m_{n,k}\in \mathcal{M}_{\equiv_{p}}\right)_{n,k\in\lbrace
0,\ldots,p^{\alpha}-1\rbrace}$ of order $\alpha\in\mathbb{N}$, so that for
$\alpha=1$ it denotes the \emph{principal cell};

\item a \emph{cluster} $\mathcal{C}_{p,\beta}^{(\alpha)}=\left(
\beta\,m_{n,k}\mod p:m_{n,k}\in
\mathcal{M}_{\equiv_{p}}^{(\alpha)}\right)_{n,k\in\mathbb{N}}$ of order
$\alpha\in\mathbb{N}$ which is a copy of the \emph{principal cluster} of order
$\alpha$ with each entry multiplied by the same constant $\beta\in\mathbb{N}$;

\item finally, a \emph{zero-hole} of order $\alpha\in\mathbb{N}$ which is an
\emph{upside-down} triangular array of coefficients where each one is a
multiple of $p$, from here the name, distributed according to the scheme
(i)~$p^{\alpha}-1$ coefficients lie on the first row, (ii)~$p^{\alpha}-2$
coefficients lie on the second row down to (iii)~a single coefficient that lies
on the $(p^{\alpha}-1)$-th row, eventually.  Observe that a \emph{zero-hole} of
order $\alpha$ has $p^{\alpha}-1$ rows, one less than a \emph{principal
cluster} of the same order.

\end{itemize}

Although a formal proof can be stated by induction using
\autoref{eq:binomial:recurrence}, Marta shows that the following  theorem  has
an easier formulation using the proposed language.

\begin{theorem}[Sved]
    Let $p$ be a prime and $\mathcal{P}_{\equiv_{p}}$ be the
    modular Pascal array. The principal cluster $\mathcal{P}_{\equiv_{p}}^{(\alpha+1)}$
    of order $\alpha + 1$ consists of $p$ layers of clusters of order $\alpha$ alternating
    with zero-holes of order $\alpha$, while the first layer contains the principal
    cluster of order $\alpha$ only.
\end{theorem}


%================================
\section{Continuous Maps}
%================================

%--------------------------------
\begin{definition}
	Let $(X, \mathcal T_X)$ and $(Y, \mathcal T_Y)$ be topological spaces. A function $f: X \to Y$ is \textit{continuous} iff
	$$
	\forall U \in \mathcal T_Y, \quad f^{-1}[U] \in \mathcal T_X.
	$$
\end{definition}
%--------------------------------

%--------------------------------
\begin{note} \
	\begin{enumerate}
		\item Let $(X, \mathcal T)$ and $(X, \mathcal T')$ be topological spaces, let identity map $i:(X, \rho) \to (X, \rho')$ be surjective. By definition, $i$ is continuous over $X$ iff $\mathcal T \supseteq \mathcal T'$.
		\item Let $(X, \mathcal T_X)$ and $(Y, \mathcal T_Y)$ be topological spaces if $\mathcal T_X$ is the discrete topology, then any function $f: X \to Y$ is continuous over $X$, because any sets in $X$ is open. Naturally, for any $U \in \mathcal T_Y$, $f^{-1}[U]$.
		\item By the previous conditions, if $\mathcal T_X$ is indiscrete topology but $\mathcal T_Y$ is not, then no function $f: X \to Y$ is continuous. (Check again!)
		\item TO DO: Find valued example by point sets, for example let $\mathcal T = \{a, b, c, d, e\}$.
	\end{enumerate}
\end{note}
%--------------------------------

%--------------------------------
\begin{lemma}
	Let $(X, \mathcal T_X)$ and $(Y, \mathcal T_X)$ be topological space. A function: $f:X\to Y$ is continuous iff for any closed subset $V$ of $Y$, the preimage $f^{-1}[V]$ is closed in $X$.
\end{lemma}
%--------------------------------

%--------------------------------
\begin{proof}
	If $V$ is closed in $Y$, then there is a $U \in \mathcal T_Y$, such that $V = Y \setminus U$.
	$$
	f^{-1}[V] = f^{-1}[Y \setminus U] = X \setminus f^{-1}[U] \in \mathcal T_Y.
	$$
\end{proof}
%--------------------------------

%--------------------------------
\begin{lemma}
	Continuous maps preserve convergence of sequence..
\end{lemma}
%--------------------------------

%--------------------------------
\begin{note}
	This is not vise versa, i.e., there exists discontinuous map preserve convergence of sequence either.

	For example, let $(X, \mathcal T)$ and $(X, \mathcal T')$ be topological space. Let $\mathcal T'$ be discrete topology, and let
	$$
	\mathcal T = \{ \text{monotones of $X$} \} \cup \{ \emptyset, X \}.
	$$
	Then any $\{x_n\} \subseteq X$ converges iff it is in the form of
	$$
	x, x, x, \ldots
	$$
	Clearly, for all $f:(X, \mathcal T) \to (X, \mathcal T')$, for any $\{x_n\}$ converges to $x \in (X, \mathcal T)$, $\{f(x_n)\}$ also converges to $f(x) \in (X, \mathcal T')$. It is in the form of
	$$
	f(x), f(x), f(x), \ldots
	$$
	But, $f$ is not continuous over $(X, \mathcal T)$. (For any $U \subsetneq X$ with $|U|>1$, $f^{-1}[U] \notin \mathcal T$).
\end{note}
%--------------------------------

%


\documentclass{pset_template}

\title{Boolean Algebra}
\date{February 1, 2019}
\editorOne{Alexander Sun}
\editorTwo{Sanjit Bhat}
\lectureNum{1}
\contestMonth{February}

\begin{document}
\maketitle

\section{Introduction}
Boolean algebra is the branch of algebra in which the variables store truth value. All variables are true(1) or false(0).
There are 3 main operations that create the base for boolean algebra: $\textbf{AND(conjunction)}$, $\textbf{OR(disjunction)}$, and $\textbf{NOT(negation)}$.

\bigskip
\noindent
\section{Basic Operations}
\textbf{AND}, denoted x $\land$ y or x AND y or x $\cdot$ y, satisfies x $\land$ y = 1 if x = y = 1 , else x $\land$ y = 0

\noindent
\textbf{OR}, denoted x $\lor$ y or x OR y or x + y, satisfies x $\lor$ y = 0 if x = y = 0 , else x $\lor$ y = 1

\noindent
\textbf{NOT}, denoted $\neg$x or NOT x or $\sim$x or $\bar{x}$, satisfies $\neg$x = 0 if x = 1 and $\neg$x = 1 if x = 0, reverses truth values of operation

\begin{center}
\begin{tabular}{ |c|c|c|c| }
 \hline
 x & y & x$\land$y & x$\lor$y \\
 \hline
  0 & 0 & 0 & 0 \\
 \hline
 1 & 0 & 0 & 1 \\
 \hline
 0 & 1 & 0 & 1 \\
 \hline
 1 & 1 & 1 & 1 \\
 \hline
\end{tabular}
\end{center}

\begin{center}
\begin{tabular}{ |c|c| }
 \hline
 x & $\neg$x \\
 \hline
  0 & 1  \\
 \hline
 1 & 0 \\
 \hline
\end{tabular}
\end{center}

\section{Secondary Operations}

\textbf{Material Implication}, denoted  x $\rightarrow$ y = $\neg$x$\lor$y, if x = 1, then x $\rightarrow$ y = y, if x = 0, then x $\rightarrow$ y = 1

\noindent
\textbf{Exclusive Or}, denoted x $\oplus$ y or x XOR y, x $\oplus$ y = 1 if x = 1 $\&$ y = 0 or x = 0 $\&$ y = 1, else x $\oplus$ y = 0, true when values are different

\noindent
\textbf{Equivalence}, denoted x $\equiv$ y, x $\equiv$ y = 1 if x =1 $\&$ y =1, or if x = 0 $\&$ y = 0, complement of XOR, true when values are the same
\noindent
\textbf{Dual}, the dual is found by replacing all OR's with AND's and all AND's with OR's, and all 1's with 0's and all 0's with 1's

\noindent
\textbf{Complement}, found by negating each individual value and replaving all OR's with AND's and all AND's with OR's and all 1's with 0's and all 0's with 1's
\bigskip

\noindent
Memorizing boolean algebra laws is extremely beneficial to being able to solve problems quickly and efficiently. Here is a link to page with almost every law. Most are derivable, but should still be memorized.  http://www.uiltexas.org/files/academics/UILCS-BooleanIdentities.pdf

Demorgan's Rule is crucial to simplifying boolean algebra problems. It states: $$ \bar{A} + \bar{B} = \overline{AB}$$ or $$ \bar{A} * \bar{B} = \overline{A+B}$$

\bigskip

\noindent
With these basic rules memorized, all boolean algebra problems should be simple to work through

\section{Exercises}
\begin{enumerate}
\item Simplify completely:(ACSL 2001-2002)
$( A + B )\oplus A B$

\item Simplify the following expression: F = BC + $\overline{BC}$ + BA

\item Simplify the Boolean expression (A+B+C)$\overline{(D+E)}$ + (A+B+C)(D+E):
\end{enumerate}

For more practice resources on boolean algebra, read through
\href{http://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra}{the ACSL Wiki page}.
\end{document}