\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage{enumitem}
\usepackage{tabu}
\usepackage{xcolor}
 \usepackage{mathtools}
 \usepackage{gensymb}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}

\newcommand{\nspace}{\vspace*{.5cm}}
\newcommand{\nline}{\nspace \noindent}

\newcommand{\expected}[1]{\text{E}(#1)}

\newenvironment{nscenter}
 {\parskip=0pt\par\nopagebreak\centering}
 {\par\noindent\ignorespacesafterend}

\def\SPSB#1#2{\rlap{\textsuperscript{\textcolor{black}{#1}}}\SB{#2}}

 % 7.2 3.b, 13, 14, 21

\begin{document}
\title{Math 487 Homework 6}
\author{Jacob Shiohira}
\maketitle

\subsection*{Section 7.2}
\noindent
\textbf{Ch 7.2 Q3} Suppose again that $Z = X + Y$ . Find $f_Z$ if

\begin{enumerate}[label=(\alph*)]
\item

\[ f_X(x) = f_Y(x) = \begin{cases}
      \frac{x}{2} & \text{ if } 0 < x < 2, \\
      0 & \text{ otherwise}.
      \end{cases} \]

\noindent
Given $Z = X + Y$, $0 < X < 2$, and $0 < Y < 2$, we know that $f_Z$ will take on the following,

\begin{equation*}
\int_{- \infty}^{\infty} f_X(z-y) f_Y(y) dy \enspace \text{ or } \enspace \int_{- \infty}^{\infty} f_Y(z-x) f_X(x) dx.
\end{equation*}

\noindent
We will use the former. From the restrictions on $X$ and $Y$, we can derive the following, $y < z < 2+y$ and $z-2 < y < z$. These will help us calculate our bounds of integration and ranges of the $Z$ random variable. The $Z$ ranges over which $f_Z$ will have a value is $0 < z < 2$ and $2 < z < 4$. So, we will go ahead and calculate those,

\begin{align*}
f_Z(x) &= \int_{0}^{z} \frac{z-2}{2} - \frac{y}{2} \text{ } dy = \int_{0}^{z} \frac{zy}{4} - \frac{y^2}{4} \text{ } dy = \Bigg [ \frac{zy^2}{8} - \frac{y^3}{12} \Bigg ]_{0}^{z} = \frac{z^3}{8} - \frac{z^3}{12} = \frac{z^3}{24},
\end{align*}

\begin{align*}
f_Z(x) &= \int_{z-2}^{2} \frac{z-2}{2} - \frac{y}{2} \text{ } dy \\
&= \int_{z-2}^{2} \frac{zy}{4} - \frac{y^2}{4} \text{ } dy \\
&= \Bigg [ \frac{zy^2}{8} - \frac{y^3}{12} \Bigg ]_{z-2}^{2} \\
&= \frac{4}{8}z - \frac{8}{12} - \Big [ \frac{z(z-2)^2}{8} - \frac{(z-2)^3}{12} \Big ] \\
&= \frac{4}{8}z - \frac{8}{12} - \Big [ \frac{z^3 - 4z^2 + 4z}{8} - \frac{z^3-6z^2+12z-8}{12} \Big ] \\
&= \frac{4}{8}z - \frac{8}{12} - \frac{3z^3 - 12z^2 + 12z - 2z^3 +12z^2 - 24z + 16}{24} \\
&= z - \frac{z^3}{24} - \frac{4}{3}.
\end{align*}

\noindent
Thus,

\[ f_Z(x) = \begin{cases}
      \frac{x^3}{24} & \text{ if } 0 \leq x \leq 2, \\
      x - \frac{x^3}{24} - \frac{4}{3} & \text{ if } 2 \leq z \leq 4.
      \end{cases} \]

\item
\[ f_X(x) = f_Y(x) = \begin{cases}
     \frac{1}{2}(x-3) & \text{ if } 3 < x < 5, \\
      0 & \text{ otherwise}.
      \end{cases} \]

% TODO: 3.b
Given $Z = X + Y$, $3 < X, Y < 5$, we know that $f_Z$ will take on the following,

\begin{equation*}
\int_{- \infty}^{\infty} f_X(z-y) f_Y(y) dy \enspace \text{ or } \enspace \int_{- \infty}^{\infty} f_Y(z-x) f_X(x) dx.
\end{equation*}

\noindent
We will use the former. From the restrictions on $X$ and $Y$, we can derive the following, $3 + y < z < 5+y$ and $z-5 < y < z-3$. These will help us calculate our bounds of integration and ranges of the $Z$ random variable. The $Z$ ranges over which $f_Z$ will have a value is $6 < z < 8$ and $6 < z < 8$. So, we will go ahead and calculate those,

\begin{align*}
f_Z(x) &= \int_{3}^{z-3} \dfrac{y^2+z\left(3-y\right)-9}{4} \text{ } dy \\
&= \frac{1}{4} \Bigg [ \dfrac{y^3}{3}-\dfrac{zy^2}{2}+\left(3z - 9 \right)y \Bigg ]_{3}^{z-3} \\
&= - \frac{z^3-18z^2+81z-108}{24}-\frac{9z-36}{8} \\
&= \dfrac{z^3-18z^2+108z-216}{24}
\end{align*}

\begin{align*}
f_Z(x) &= \int_{z-5}^{5} \dfrac{y^2+z\left(3-y\right)-9}{4} \text{ } dy \\
&= \frac{1}{4} \Bigg [ \dfrac{y^3}{3}-\dfrac{zy^2}{2}+\left(3z - 9 \right)y \Bigg ]_{z-5}^{5} \\
&= \frac{z^3-18z^2+69z-20}{24}+\frac{15z-20}{24} \\
&= \dfrac{z^3-18z^2+84z-40}{24}
\end{align*}

\noindent
Thus,

\[ f_Z(x) = \begin{cases}
      \dfrac{z^3-18z^2+108z-216}{24} & \text{ if } 6 \leq x \leq 8, \\
      \dfrac{z^3-18z^2+84z-40}{24} & \text{ if } 8 \leq x \leq 10.
      \end{cases} \]

\item
\[ f_X(x) = \begin{cases}
      \frac{1}{2} & \text{ if } 0 < x < 2, \\
      0 & \text{ otherwise}.
      \end{cases} \]

 \[ f_Y(x) = \begin{cases}
      \frac{x}{2} & \text{ if } 0 < x < 2, \\
      0 & \text{ otherwise}.
      \end{cases} \]

\noindent
Given $Z = X + Y$, $0 < X < 2$, and $0 < Y < 2$, we know that $f_Z$ will take on the following,

\begin{equation*}
\int_{- \infty}^{\infty} f_X(z-y) f_Y(y) dy \enspace \text{ or } \enspace \int_{- \infty}^{\infty} f_Y(z-x) f_X(x) dx.
\end{equation*}

\noindent
We will use the former. From the restrictions on $X$ and $Y$, we can derive the following, $y < z < 2+y$ and $z-2 < y < z$. These will help us calculate our bounds of integration and ranges of the $Z$ random variable. The $Z$ ranges over which $f_Z$ will have a value is $0 < z < 2$ and $2 < z < 4$. So, we will go ahead and calculate those,

\begin{align*}
f_Z(x) &= \int_{0}^{z} \frac{y}{4} \text{ } dy = \Bigg [ \frac{y^2}{8} \Bigg ]_{0}^{z} = \frac{z^2}{8},
\end{align*}

\begin{align*}
f_Z(x) &= \int_{z-2}^{2} \frac{y}{4} \text{ } dy = \Bigg [ \frac{y^2}{8} \Bigg ]_{z-2}^{2} = \frac{1}{2} - \frac{(z-2)^2}{8}.
\end{align*}

\noindent
Thus,

\[ f_Z(x) = \begin{cases}
      \frac{z^2}{8} & \text{ if } 0 \leq x \leq 2, \\
      \frac{1}{2} - \frac{(z-2)^2}{8} & \text{ if } 2 \leq z \leq 4.
      \end{cases} \]

% \item What can you say about the set $E = { z : f_Z(z) > 0 }$ in each case?
\end{enumerate}

\vspace*{.5cm}
\noindent
\textbf{Ch 7.2 Q9} Assume that the service time for a customer at a bank is exponentially distributed with mean service time $2$ minutes. Let $X$ be the total service time for $10$ customers. Estimate the probability that $X > 22$ minutes.

\vspace*{.5cm}
\noindent
We can view $X$ as the sum of $10$ independent, exponentially distributed random variables with mean service time of $2$ minutes. Let $X_i$ with $i = 0, \ldots, 10$ be these independent random variables. Then,

\begin{equation*}
X = X_1 + X_2 + \cdots + X_{10}.
\end{equation*}

\noindent
Since all the $X_i$ are exponentially distributed with mean $\frac{1}{\lambda}$, then

\begin{equation*}
X = \frac{\lambda e^{- \lambda x} (\lambda x)^{n-1}}{(n-1)!}.
\end{equation*}

\noindent
Thus,

\begin{equation*}
\mathbb{P}(X > 22) = 1 - \int_{0}^{22} \frac{.5 e^{- .5 x} (.5 x)^{9}}{9!} dx = .341.
\end{equation*}

\vspace*{.5cm}
\noindent
\textbf{Ch 7.2 Q10} Let $X_1, X_2, \ldots , X_n$ be $n$ independent random variables each of which has an exponential density with mean $\mu$. Let $M$ be the \textit{minimum value} of the $X_j$ . Show that the density for $M$ is exponential with mean $\mu / n$. Hint: Use cumulative distribution functions.

\vspace*{.5cm}
\noindent
Since $X_1, X_2, \ldots , X_n$ are $n$ independent random variables with exponential density and mean $\mu$, the probability distribution of $X_j$ for $j = 1, 2, \ldots, n$ is

\begin{equation*}
f(x) = \frac{1}{\mu} e^{-\frac{x}{\mu}}.
\end{equation*}

\noindent
It follows that the cumulative distribution function can be calculated from the integral of $f(x)$,

\begin{equation*}
F(x) = \int \frac{1}{\mu} e^{-\frac{x}{\mu}} = e^{-\frac{x}{\mu}} + C.
\end{equation*}

\noindent
We can plug in $F(0) = 0$ to find that $C = -1$ and $F(x) = 1 - e^{-\frac{x}{\mu}}$. Then, if $M$  is the minimum value of $X_j$ for $j = 1, 2, \ldots, n$, we can find $F_M(x)$,

 \begin{equation*}
P( \text{min}(X_1, \ldots, X_n) > M ) = \big [ P(X_1 > x) \big ]^n = \big [ 1 - F(x) \big ]^n =  \big [ 1 - (1 - e^{- x / \mu }) \big ]^n = 1 - e^{ - \frac{n}{\mu} x }.
\end{equation*}

\noindent
Then, we can find $f_M(X)$ by differentiating $F_M(x)$ to get

\begin{equation*}
f_M(x) = \frac{n}{\mu} e^{- \frac{n}{\mu} x }.
\end{equation*}

\noindent
This then satisfies that the minimum value of $X_j$ for $j = 1, 2, \ldots, n$ has exponential distribution with mean $n / \mu$.

\vspace*{.5cm}
\noindent
\textbf{Ch 7.2 Q11} A company buys $100$ light bulbs, each of which has an exponential lifetime of $1000$ hours. What is the expected time for the first of these bulbs to burn out? (See Exercise $10$.)

\vspace*{.5cm}
\noindent
Since we are looking for the first bulb to burn out, we can refer to the result of the last problem. Let $X_1$ denote the first bulb to burn out. Then, E$(X_1) = \mu / n = 1000 / 100 = 10$ hours.

\vspace*{.5cm}
\noindent
\textbf{Ch 7.2 Q13} Particles are subject to collisions that cause them to split into two parts with each part a fraction of the parent. Suppose that this fraction is uniformly distributed between 0 and 1. Following a single particle through several splittings we obtain a fraction of the original particle $Z_n = X_1 \cdot X_2 \cdot \ldots \cdot X_n$ where each $X_j$ is uniformly distributed between $0$ and $1$. Show that the density for the random variable $Z_n$ is

\begin{equation*}
f_n(z) = \frac{1}{(n-1)!} (- \text{log} z)^{n-1}.
\end{equation*}

\noindent
Hint: Show that $Y_k = - \text{log} X_k$ is exponentially distributed. Use this to find the density function for $S_n = Y_1 + Y_2+ \cdots + Y_n$, and from this the cumulative distribution and density of $Z_n = e^{−S_n}$.

\vspace*{.5cm}
\noindent
Since $Y_k = - \text{log} X_k$, we see that

\begin{equation*}
P(Y_k \leq y_k) = P(- \text{log} X_k \leq y_k) = P(X_k \geq e^{- y_k}) = 1 - P(X_k \leq e^{- y_k}) = 1 - e^{- y_k}.
\end{equation*}

\noindent
Thus, $Y_k$ is exponentially distributed. Then, it follows that $Y_k \sim \text{exp}(1)$ for all $k = 1, 2, \ldots, n$. So, $S_n$ is distributed according to the gamma function,

\begin{equation*}
f_{S_n}(x) = \frac{e^{- x } x^{n-1}}{\left(n-1\right)!}.
\end{equation*}

\noindent
Then, per the hint, $Z_n = e^{−S_n}$ can be used to yield the cumulative distribution of $f_A$. So, we will start with

\begin{equation*}
F_{Z_n}(z) = P(Z_n \leq z) = P(e^{- S_n} \leq z) = P(S_n \geq - \text{ln} z) = 1 - P(Z_n \leq - \text{ln} z) = 1 - F_s(- \text{ln} z).
\end{equation*}

\noindent
By the properties of probability density functions, we can differentiate $F_{Z_n}(z)$ with respect to $z$ to get,

\begin{equation*}
f_{Z_n}(z) = \frac{d}{dz} 1 - F_s(- \text{ln} z) = \frac{(- \text{ln} z)^{n-1}}{ \left(n-1\right)!}.
\end{equation*}

\vspace*{.5cm}
\noindent
\textbf{Ch 7.2 Q14} Assume that $X_1$ and $X_2$ are independent random variables, each having an exponential density with parameter $\lambda$. Show that $Z = X_1 - X_2$ has density

\begin{equation*}
f_Z(z) = \frac{1}{2} \lambda e^{- \lambda \lvert z \rvert}.
\end{equation*}

\noindent
We can think of $Z = X_1 - X_2$ as $Z = X_1 + (-X_2)$. Then, it is easily seen that $X_1$ and $X_2$ have probability density functions

\begin{equation*}
f_{X_1}(x) = \begin{cases}
             0  & \text{ for } x < 0, \\
             \lambda e^{- \lambda x}  & \text{ for } x > 0.
       \end{cases} \quad
f_{X_2}(x) = \begin{cases}
		      \lambda e^{- \lambda x}  & \text{ for } x < 0, \\
             0  & \text{ for } x > 0.
       \end{cases}
\end{equation*}

\noindent
The convolution of $Z = X_1 + (-X_2)$ is therefore

\begin{equation*}
f_Z(z) = (f_1 \cdot f_2)(z) = \int_{- \infty}^{\infty} f_1(z - x)f_2(x) \text{ } dx.
\end{equation*}

\noindent
As a result of the ranges of $X_1$ and $X_2$, the analysis on $Z$ can be broken down into the two cases: $z > 0$ and $z < 0$,

\begin{align*}
f_Z(z) &= \int_{- \infty}^{z} f_1(z - x)f_2(x) \text{ } dx \\
&= \lambda^2 e^{- \lambda z} \int_{- \infty}^{z} e^{2 \lambda x} \text{ } dx  \\
&= \lambda^2 e^{- \lambda z} \frac{e^{2 \lambda x}}{2 \lambda}  \text{ } dx  \\
&= \frac{\lambda}{2} e^{- \lambda z} \\
\end{align*}

\begin{align*}
f_Z(z) &= \int_{- \infty}^{0} f_1(z - x)f_2(x) \text{ } dx \\
&= \lambda^2 e^{- \lambda z} \int_{- \infty}^{0} e^{2 \lambda x} \text{ } dx  \\
&= \lambda^2 e^{- \lambda z} \frac{1}{2 \lambda}  \\
&= \frac{\lambda}{2} e^{- \lambda z}  \\
\end{align*}

\noindent
Since $f_Z(z)$ has the same definition when $z < 0$ and $z > 0$, we can

\begin{equation*}
f_Z(z) = \frac{\lambda}{2} e^{- \lambda \lvert z \rvert }.
\end{equation*}

\vspace*{.5cm}
\noindent
\textbf{Ch 7.2 Q20} Let $X_1, X_2, \ldots , X_n$ be a sequence of independent random variables, all having a common density function $f_X$ with support $[a, b]$ (see Exercise $19$). Let $S_n = X_1 + X_2 + \cdots + X_n$, with density function $f_{S_n}$. Show that the support of $f_{S_n}$ is the interval $[na, nb]$. Hint: Write $f_{S_n} = f_{S_n-1} \cdot f_X$. Now use Exercise $19$ to establish the desired result by induction.

\vspace*{.5cm}
\noindent
Suppose that $n=1$. Then, $f_{S_n} = f_{S_1} = f_{X_1}$ has support in the interval $[na, nb] = [a,b]$ because $f_X$ is defined to have support $[a, b]$.

\vspace*{.5cm}
\noindent
Next, suppose that for some $k \geq n$, $f_{S_k}$ has support on $[ka, kb]$. Then, since we know $f_{S_n} = f_{S_n-1} \cdot f_X$, we can say that $f_{S_{k+1}} = f_{S_k} \cdot f_X$. $f_{S_{k+1}}$ then has support on $\big [ ka  + a, kb + b \big ] = \big [(k+1) a, (k+1) b \big ]$.

\vspace*{.5cm}
\noindent
Thus, by induction, we have shown that the support of $f_{S_n}$ is the interval $[na, nb]$ for all $n$.

\vspace*{.5cm}
\noindent
\textbf{Ch 7.2 Q21} Let $X_1, X_2, . . . , X_n$ be a sequence of independent random variables, all having a common density function $f_X$. Let $A = S_n/n$ be their average. Find $f_A$ if

\begin{enumerate}[label=(\alph*)]
\item $f_X(x) = (1 / \sqrt{2 \pi}) e^{- \frac{x^2}{2}}$ (normal density).

\noindent
Since we know that $A = S_n/n$, $\text{E}(A) = \text{E}(S_n / n) = \frac{1}{n} \text{E}(S_n)$. Then, since $X_1, X_2, . . . , X_n$ is a sequence of independent random variables, the expected value of the sums is the sum of the expected values of each $X_i$ for $i = 1, 2, \ldots $. So, $\text{E}(S_n) = n \cdot \text{E}(X_i) = n \mu$. By plugging in $\text{E}(X_i)$, we can see that $\text{E}(A) = \mu_{X_i} = 0$.

\noindent
A similar approach can be taken with the variance such that $\text{V}(A) = \text{V}(S_n / n) = \frac{1}{n^2} \text{V}(S_n) = \frac{1}{n^2} n = \frac{1}{n}$.

\noindent
Then, we use the fact that the sum of independent normally distributed random variables is normally distributed to plug in our values of $\mu$ and $\lambda$ for $A$,

\begin{equation*}
f_A(x) = \frac{1}{\sqrt{\frac{n}{2 \pi}}} e^{\frac{-n x^2}{2}}.
\end{equation*}

\item $f_X(x) = e^{- x}$ (exponential density). \textit{Hint}: Write $f_A(x)$ in terms of $f_{S_n}(x)$.

\noindent
We know that the sum of exponentially distributed random variables is gamma distributed. So, we need to find parameters $\alpha$ and $\beta$ that satisfy $f_A(x)$ based on the distribution of $f_X(x) = e^{- x}$. This is clearly exponentially distributed with parameter $\lambda = 1$. The resulting expected value is $\text{E}(x) = \frac{1}{\lambda}$ and the resulting variance is $\text{E}(x) = \frac{1}{\lambda^2}$.

\noindent
The resulting distributions of the sums of random variables, $S_n = \frac{e^{-x} x^{n-1}}{(n-1)!}$. The parameters of this distribution are thus $\alpha = n$ and $\beta = 1$. Since we know that $A = S_n/n$, $\text{E}(A) = \text{E}(S_n / n) = \frac{1}{n} \text{E}(S_n) = \frac{1}{n} \frac{\alpha}{\beta} = \frac{1}{n} \frac{n}{1} = 1$.

\noindent
A similar approach can be taken with the variance such that $\text{V}(A) = \text{V}(S_n / n) = \frac{1}{n^2} \text{V}(S_n) = \frac{1}{n^2} n = \frac{1}{n} = \frac{\alpha}{\beta^2}$. Since $\text{E}(A) = \frac{\alpha}{\beta} = 1$, it is seen that that $\alpha = \beta$. By plugging this into our variance equation, we can solve for both $\alpha$ and $\beta$ such that $\alpha = \beta = n$.

\noindent
Then, we use the fact that the sum of independent exponentially distributed random variables is gamma distributed to plug in our values of $\alpha$ and $\beta$ for $A$,

\begin{equation*}
f_A(x) = \frac{n^n x^{n-1} e^{-xn}}{(n-1)!}.
\end{equation*}

\end{enumerate}
\end{document}


%!TEX root =  ../main.tex

\subsection{Various Forms}

\objective{Find attributes and graphs of parabolas from equations and/or geometric criteria.}

You should have a fair amount of experience graphing, factoring, and describing
parabola and quadratic equations.  The principles of algebra one learns dealing with quadratics
apply generally to the rest of mathematics and will serve you well for the rest of your life.
The slope of lines tangent to parabola are easy to calculate.
Find the difference quotient of $f(x)=x^2+6x+5$ for any $x$.

The spread out for of $ax^2+bx+c$ has three advantages.
It can be easily differentiated
It shows the y-intercept plainly
It can be plugged into the quadratic formula as is

However, for graphing, it can be a little obtuse.  We might start by factoring, and see that it is
$(x+5)(x+1)$.  This form --- called intercept form --- \index{quadratic!intercept form}
has only one advantage: it is immediately obvious what the zeros of the function are.

\index{quadratic!vertex form}
Lastly, it is a bit more work, but completing the square and writing in the form $a(x-h)^2+k$
is the easiest to graph from, its one advantage:
the vertex is immediately obvious

\subsection{Angles of Incidence}
Not usually taught in an Algebra class, parabolas have many geometric properties.  The most
physically useful is that every incoming line has an angle of incidence that will take them all
through the same place, called the focus.  This is why headlights and telescopes are paraboloids,
3D parabolas.  A corollary to this property is that every parabola is the set of points equidistant
from a point and a line.  The distance from the vertex to this focus (and directrix) is $p$, in the
formula\index{quadratic!parabolic form}

$$
y-k = \frac{1}{4p}(x-h)^2
$$

~\vfill


% This is part of the TFTB Reference Manual.
% Copyright (C) 1996 CNRS (France) and Rice University (US).
% See the file refguide.tex for copying conditions.

\markright{tfrzam}
\section*{\hspace*{-1.6cm} tfrzam}

\vspace*{-.4cm}
\hspace*{-1.6cm}\rule[0in]{16.5cm}{.02cm}
\vspace*{.2cm}

{\bf \large \sf Purpose}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
Zhao-Atlas-Marks time-frequency distribution.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Synopsis}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
\begin{verbatim}
[tfr,t,f] = tfrzam(x)
[tfr,t,f] = tfrzam(x,t)
[tfr,t,f] = tfrzam(x,t,N)
[tfr,t,f] = tfrzam(x,t,N,g)
[tfr,t,f] = tfrzam(x,t,N,g,h)
[tfr,t,f] = tfrzam(x,t,N,g,h,trace)
\end{verbatim}
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Description}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
        {\ty tfrzam} computes the Zhao-Atlas-Marks distribution of a
        discrete-time signal {\ty x}, or the cross Zhao-Atlas-Marks
        representation between two signals. This distribution writes
\[ZAM_x(t,\nu)=\int_{-\infty}^{+\infty} \left[\ h(\tau)\
\int_{t-|\tau|/2}^{t+|\tau|/2} x(s+\tau/2)\ x^*(s-\tau/2)\ ds\right]\
e^{-j2\pi \nu \tau}\ d\tau. \]
  It is also known as the {\it Cone-Shaped Kernel distribution}. \\

\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}
Name & Description & Default value\\
\hline
        {\ty x}     & signal if auto-ZAM, or {\ty [x1,x2]} if cross-ZAM {\ty
			(Nx=length(x))}\\
        {\ty t}     & time instant(s)          & {\ty (1:Nx)}\\
        {\ty N}     & number of frequency bins & {\ty Nx}\\
        {\ty g}     & time smoothing window, {\ty G(0)} being forced to {\ty 1}, where {\ty G(f)} is the Fourier transform of {\ty g(t)}
                                         & {\ty window(odd(N/10))}\\
        {\ty h}     & frequency smoothing window, {\ty h(0)} being forced to {\ty 1}
                                         & {\ty window(odd(N/4))}\\
        {\ty trace} & if nonzero, the progression of the algorithm is shown
                                         & {\ty 0}\\
     \hline {\ty tfr}   & time-frequency representation\\
        {\ty f}     & vector of normalized frequencies\\

\hline
\end{tabular*}
\vspace*{.2cm}

When called without outpout arguments, {\ty tfrzam} runs {\ty tfrqview}.
\end{minipage}

\newpage

{\bf \large \sf Example}
\begin{verbatim}
         sig=fmlin(128,0.05,0.3)+fmlin(128,0.15,0.4);
         g=window(9,'Kaiser'); h=window(27,'Kaiser');
         tfrzam(sig,1:128,128,g,h,1);
\end{verbatim}
\vspace*{.5cm}

{\bf \large \sf See Also}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
all the {\ty tfr*} functions.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Reference}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
[1] Y. Zhao, L. Atlas, R. Marks ``The Use of the Cone-Shaped Kernels for
Generalized Time-Frequency Representations of Nonstationary Signals'' IEEE
Trans. on Acoust., Speech and Signal Proc., Vol. 38, No. 7, pp. 1084-91,
1990.
\end{minipage}


\documentclass{article}
\usepackage{amsmath}
\author{a1trl9}
\title{Algebra Review}
\date{}

\setlength\parindent{0pt}
\counterwithin*{equation}{section}

\newcommand{\V}[1]{\boldsymbol{#1}}
\newcommand{\TM}{\bigtriangledown}

\begin{document}
\maketitle

\section{System of Linear Equations}
\textbf{Proposition 1:} for a homogeneous system of linear equations on
\(K\), if the number of equations \(m\) is fewer than the number of
variables \(n\), then it must have a non-trival solution.

\vspace{2mm}
\textbf{Mathematical Induction}

When \(m=1, n>m\), if one coefficient \(a_{1k}=0\), then one
solution is \(x_k=1\) and
all other variables are equal to \(0\). If no
coefficient is equal to \(0\). Then one solution is
\(x_k = -\frac{a_{1k+1}}{a_{k}},
x_{k+1}=1\), all other variables are equal to \(0\).

\vspace{1mm}
Considering when \(m > 1\) while for \(m-1\) the proposition holds.

If all coefficients for \(x_1\) are equal to zero, then one solution is
\(x_1=1, x_2=0, \cdots, x_n=0\).

If not, then change the order of equations so that \(\alpha_{11} \neq 0\).
Now repeat the step \(eq(k) - \frac{a_{11}}{a_{k1}}eq(1)\) where \(eq(t)\)
presents the equation \(t\) and \(k=2,3,\cdots,n\). Finally, the system
of equations are transformed to:
\begin{equation}
\left\{
\begin{split}
    &a_{11}x_1+a_{12}x_2+\cdots+a_{1n}x_n=0 \\
    &a'_{22}x_2 + \cdots + a'_{2n}x_n=0 \\
    &\vdots\\
    &a'_{m2}x_2 + \cdots + a'_{mn}x_n=0 \\
\end{split}
\right.
\end{equation}

Now the second to last equations construct a new homogeneous system
of equations with \(m-1\) equations and \(n-1\) variables:
\begin{equation}
\left\{
\begin{split}
    &a'_{22}x_2 + \cdots + a'_{2n}x_n=0 \\
    &a'_{32}x_2 + \cdots + a'_{3n}x_n=0 \\
    &\vdots\\
    &a'_{m2}x_2 + \cdots + a'_{mn}x_n=0 \\
\end{split}
\right.
\end{equation}

Since \(n>m\), \(n-1>m-1\). And the proposition hold for \(m-1\). There
exists one non-trival solution \(x_2=k_2, \cdots, x_n=k_n\).

Back to (1). Since \(a_{11} \neq 0\), with
\(x_2=k_2, \cdots, x_n=k_n\), there must be one solution \(x_1=k_1\)
letting \(a_{11}k_1+a_{12}k_2+\cdots+a_{1n}k_n=0\).

\section{Vector space \& Matrix \& System of Linear Equations}

\subsection{Vector space}

\textbf{Proposition 2.1.4:} Given two sets of vectors:

\begin{equation}
\begin{split}
    \alpha_1, \alpha_2, \cdots, \alpha_r, \quad\quad (\mathbf{I}) \\
    \beta_1, \beta, \cdots, \beta_s, \quad\quad (\mathbf{II})
\end{split}
\end{equation}

If each vector in \((\mathbf{I})\) can be defined as a linear combination
of \((\mathbf{II})\), and \(r>s\). Then \((\mathbf{I})\) are linearly dependent.

\vspace{2mm}
\textbf{Proof}

As each vector in \((\mathbf{I})\) can be defined as a linear combination
of \((\mathbf{II})\):

\begin{equation}
\begin{split}
&\alpha_1 = x_{11}\beta_1 + x_{12}\beta_2 + \cdots + x_{1s}\beta_s \\
&\alpha_2 = x_{21}\beta_1 + x_{22}\beta_2 + \cdots + x_{2s}\beta_s \\
&\vdots\\
&\alpha_r = x_{r1}\beta_1 + x_{r2}\beta_2 + \cdots + x_{rs}\beta_s \\
\end{split}
\end{equation}

Then given \(k_1, k_2, \cdots, k_s\):

\begin{equation}
\sum_{i=1}^{r}k_i\alpha_i=
\sum_{j=1}^{s}x_{j1}k_j\beta_1
+\sum_{j=1}^{s}x_{j2}k_j\beta_2
+\cdots
+\sum_{j=1}^{s}x_{jr}k_j\beta_r
\end{equation}

In which, since \(r>s\), for:

\begin{equation}
\left
\{
\begin{split}
&x_{11}k_1 + x_{21}k_2 + \cdots + x_{s1}k_s = 0 \\
&x_{12}k_1 + x_{22}k_2 + \cdots + x_{s2}k_s = 0 \\
&\vdots\\
&x_{1r}k_1 + x_{2r}k_2 + \cdots + x_{sr}k_s = 0 \\
\end{split}
\right.
\end{equation}

According to proposition 1 in section 1, there
must be a non-trival solution. That is, there exists \(k_1, k_2, \cdots, k_s\),
in which at least one \(k_n \neq 0\), for \(i = 1, 2, \cdots, r\), \(\sum_{j=1}^s
x_{ji}k_j=0\), in which case \(\sum_{i=1}^rk_i\alpha_i=0\) as well.
. So, \(\alpha_1, \alpha_2,
\cdots, \alpha_r\) are linearly dependent.

\subsection{Matrix operations}

\subsubsection{Operations and rank}

\textbf{Proposition 2.2.4:}: \(r(AB)\leq min(r(A), r(B))\).

\vspace{2mm}
\textit{Lemma 1:}
For two matrics:

\begin{equation}
\begin{split}
    &A=\begin{bmatrix}
    \alpha_1, \alpha_2, \cdots, \alpha_r \\
    \end{bmatrix}\\
    &B=\begin{bmatrix}
    \beta_1, \beta_2, \cdots, \beta_s
    \end{bmatrix}
\end{split}
\end{equation}

if each column vector of \(A\) could be defined as a linear combination
of column vectors in \(B\), then \(r(A)\leq r(B)\).

\vspace{2mm}
\textbf{Proof}

Since each column vector of \(A\) could be defined as a linear combination
of column vectors in \(B\), the maximally linearly independent set
of \(A\): \(\alpha_{i_1}, \alpha_{i_2}, \cdots, \alpha_{i_k}\)
could be defined as a linear combination of
the maximally linearly independent set of \(B\):
\(\beta_{j_1}, \beta_{j_2}, \cdots, \beta_{j_m}\) as well.

Since \(\alpha_{i_1}, \alpha_{i_2}, \cdots, \alpha_{i_k}\) must be
linearly independent, according to proposition 2.1.4,
\(i_k \leq j_m \), that is \(r(A)\leq r(B)\).

\vspace{2mm}
\textbf{Proof for proposition 2.2.4}

Let \(C=AB=\begin{bmatrix}c_1,c_2,\cdots,c_n\end{bmatrix}\). Then
for \(c_i, i = 1, 2, \cdots, n\):

\begin{equation}
\begin{split}
c_i &= \begin{bmatrix}
a_{11}b_{i1}+a_{12}b_{i2}+\cdots+a_{1m}b_{im}\\
a_{21}b_{i1}+a_{22}b_{i2}+\cdots+a_{2m}b_{im}\\
a_{k1}b_{i1}+a_{k2}b_{i2}+\cdots+a_{km}b_{im}\\
\end{bmatrix}\\
&=\alpha_1b_{i1}+\alpha_2b_{i2}+\cdots+\alpha_mb_{im}
\end{split}
\end{equation}

That is, each column vector of \(C\) could be presented as
a combination of column vectors of \(A\). So according
to the lemma, \(r(C)\leq r(A)\). Similarly, \(r(C)\leq r(B)\)
(using transpose). Therefore, \(r(AB)\leq min(r(A), r(B))\).

\subsection{Square matrix}

\textbf{Proposition 2.3.3:} for a \(n\) square matrix \(A\) in the number
field \(K\), the sufficient and necessary condition for \(A\) is
invertable is \(A\) has full rank.

\vspace{2mm}
\textbf{Proof}

\vspace{2mm}
\textit{Sufficiency}

When \(A\) has full rank, there exist elementary matrics
\(P_i, Q_j, i = 1, 2, \cdots, n, j=1,2,\cdots,m\), such that:

\begin{equation}
    P_1P_2\cdots P_nA = E
\end{equation}

And:

\begin{equation}
    AQ_1Q_2\cdots Q_m = E
\end{equation}

Let \(P=P_1P_2\cdots P_n\), and \(Q=Q_1Q_2\cdots Q_m\).

Then:

\begin{equation}
P=PE=PAQ=(PA)Q=EQ=Q
\end{equation}

So \(AP=PA=E\), A is invertable.

\vspace{2mm}

\textit{Necessity}

Since \(A\) is invertable, there exists \(P\), \(AP=E\).
According to proposition 2.2.4, \(r(E)=n\leq min(r(A), r(P))\leq r(A)\).
Therefore \(r(A)=n\) and has full rank.

\vspace{2mm}
\textbf{Proposition 2.3.5}: For a \(n \times n\) square matrix \(\mathbf{X}\),
\(X"X\) is a positive semi-definite matrix.

\vspace{2mm}
\textbf{Proof}
If we present \(X=[X_1, X_2, \cdots, X_n]'\) and
\(X'=[X_1, X_2, \cdots, X_n]\)
It can be shown \(\mathbf{A}=\mathbf{X}'\mathbf{X}\) is symmetric as
\begin{equation}
   a_{ij}=X_i \cdot X_j =a_{ji}
\end{equation}

Where \(a_{kl}\) presents the element located in the \(k\)th row and \(l\)th column
of \(A\).

Then for any non-zero vector \(\V{v}\):
\begin{equation}
\V{v}'A\V{v}=\V{v}'\mathbf{X}'\mathbf{X}\V{v}=(\mathbf{X}\V{v})'\mathbf{X}\V{v}
=||\mathbf{X}\V{v}||^2\geq 0
\end{equation}

\section{Determinant}

\subsection{Definition}

\subsubsection{Linearity and Antisymmetry}

Considering the set consisting of all
\(n \times n\) matrix \(M_n(K)\) in the number field \(K\) and
a function \(f\) in the domain,
the linearity by row embodies as:

For matrix:

\begin{equation*}
A=
\begin{bmatrix}
    \alpha_1 \\
    \alpha_2 \\
    \vdots \\
    \alpha_n
\end{bmatrix}
\end{equation*}

If for \(i \in [1, n]\):

\begin{equation*}
    \alpha_i=k\alpha+l\beta
\end{equation*}

Then:

\begin{equation}
f(A)=
\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_i \\
    \vdots \\
    \alpha_n
\end{bmatrix} =
kf(
\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha \\
    \vdots \\
    \alpha_n
\end{bmatrix}) + lf(
\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \beta \\
    \vdots \\
    \alpha_n
\end{bmatrix}
)
\end{equation}

Similarly, the linearity by column embodies as:

\begin{equation}
\begin{split}
\begin{bmatrix}
    \alpha_1 &
    \cdots &
    \alpha_i &
    \cdots &
    \alpha_n
\end{bmatrix} & =
kf(
\begin{bmatrix}
    \alpha_1 &
    \cdots &
    \alpha &
    \cdots &
    \alpha_n
\end{bmatrix}) \\
& + lf(
\begin{bmatrix}
    \alpha_1 &
    \cdots &
    \beta &
    \cdots &
    \alpha_n
\end{bmatrix}
)
\end{split}
\end{equation}

Moreover, the function \(f\) holding the characteristic above is
said antisymmetric if
\(f(A)=0\) when any two rows/columns of \(A\) are identical.

\vspace{2mm}
\textbf{Proposition 3.1.1:}

if function \(f\) holds all characteristics above (i.e. linear
by row/column, antisymmetric), then:

\begin{itemize}
    \item Swap two rows/coloums of matrix \(A\) to matrix \(B\),
    \(f(A)=-f(B)\).
    \item Add \(\lambda\alpha_j\) to \(\alpha_i\) to get matrix \(B\),
    \(f(A)=f(B)\).
\end{itemize}

\vspace{2mm}
\textbf{Proof:}

Assuming \(f\) holds linearity by row, then:
\begin{equation}
\begin{split}
f(
\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_i \\
    \vdots \\
    \alpha_j \\
    \vdots \\
    \alpha_n
\end{bmatrix}) +
f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_j \\
    \vdots \\
    \alpha_i \\
    \vdots \\
    \alpha_n
\end{bmatrix})
=
f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_i + \alpha_j \\
    \vdots \\
    \alpha_j + \alpha_i \\
    \vdots \\
    \alpha_n
\end{bmatrix})=0
\end{split}
\end{equation}

Therefore:
\begin{equation}
f(
\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_i \\
    \vdots \\
    \alpha_j \\
    \vdots \\
    \alpha_n
\end{bmatrix}) =
-f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_j \\
    \vdots \\
    \alpha_i \\
    \vdots \\
    \alpha_n
\end{bmatrix})
\end{equation}

Besides:

\begin{equation}
f(
\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_i + \lambda\alpha_j \\
    \vdots \\
    \alpha_j \\
    \vdots \\
    \alpha_n
\end{bmatrix}) =
f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_i \\
    \vdots \\
    \alpha_j \\
    \vdots \\
    \alpha_n
\end{bmatrix}) +
\lambda f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_j \\
    \vdots \\
    \alpha_j \\
    \vdots \\
    \alpha_n
\end{bmatrix}) =
f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_i \\
    \vdots \\
    \alpha_j \\
    \vdots \\
    \alpha_n
\end{bmatrix}) + 0 =
f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_i \\
    \vdots \\
    \alpha_j \\
    \vdots \\
    \alpha_n
\end{bmatrix})
\end{equation}

For \(f\) holding the linearity by column, the proof is similar.

\vspace{2mm}
\textbf{Inference 1}

Together with the rule indicated in (1), namely:

\begin{equation}
f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \lambda\alpha_i \\
    \vdots \\
    \alpha_n
\end{bmatrix})=
\lambda f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_i \\
    \vdots \\
    \alpha_n
\end{bmatrix})
\end{equation}

And:

\begin{equation}
f(\begin{bmatrix}
    \alpha_1 &
    \cdots &
    \lambda\alpha_i &
    \cdots &
    \alpha_n
\end{bmatrix})=
\lambda f(\begin{bmatrix}
    \alpha_1 &
    \cdots &
    \alpha_i &
    \cdots &
    \alpha_n
\end{bmatrix})
\end{equation}

These three rules correspond to three types of elementary transformations
by row/column. Therefore, it is obvious that for two functions \(f,g\) holding
antisymmetry and linearity, if \(f(A)=g(A)\) and \(B=AP_1P_2\cdots P_n\)
where \(P_1, P_2, \cdots, P_n\) are all elementary matrics, then
\(f(B)=g(B)\).

\vspace{2mm}
\textbf{Inference 2}

The necessary and sufficient condition for a function \(f\) holding
linearity by row/column to be antisymmetric is for each matrix
\(A\) that is rank deficient, \(f(A)=0\).

\vspace{2mm}
\textbf{Proof:}

\vspace{1mm}
\textit{Sufficient:}

Since for each matrix \(A\) that is rank deficient, \(f(A)=0\),
and obviously if \(A\) has two identical rows/columns, \(A\) is
rank deficient. So \(f(A)=0\) when \(A\) has two identical rows/columns.

\vspace{2mm}
\textit{Necessary:}

Assuming \(f\) holds linearity by row. Then for \(\lambda \neq 0\):

\begin{equation}
\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \mathbf{0} \\
    \vdots \\
    \alpha_n
\end{bmatrix} =
\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \lambda \mathbf{0} \\
    \vdots \\
    \alpha_n
\end{bmatrix} =
\lambda\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \mathbf{0} \\
    \vdots \\
    \alpha_n
\end{bmatrix}
\end{equation}

Therefore:

\begin{equation}
\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \mathbf{0} \\
    \vdots \\
    \alpha_n
\end{bmatrix} = 0
\end{equation}

Besides, if \(A\) is rank deficient, with \(\alpha_i = k_1\alpha_1 + \cdots +
k_{i-1}\alpha_{i-1} + k_{i+1}\alpha_{i+1} + \cdots + k_n\alpha_n\),
repeat the step that \(\alpha'_i=\alpha_i - k_j \alpha_{j}\) for
\(k = 1, 2, \cdots, i-1, i+1, \cdots, n\). Finally, \(\alpha'_i=\mathbf{0}\).
Considering \(f\) holds the linearity:

\begin{equation}
f(A)=f(
\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha_i \\
    \vdots \\
    \alpha_n
\end{bmatrix})=
f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \alpha'_i \\
    \vdots \\
    \alpha_n
\end{bmatrix})=
f(\begin{bmatrix}
    \alpha_1 \\
    \vdots \\
    \mathbf{0} \\
    \vdots \\
    \alpha_n
\end{bmatrix})=0
\end{equation}

For \(f\) holding the linearity by column, the proof is similar.

\subsubsection{Definition}

There are three characteristics that a determinant function holds:

\begin{itemize}
    \item If matrix \(A\) is rank deficient, \(f(A)=0\).
    \item For identity matrix \(E\), \(f(E)=1\).
    \item Linearity by column.
\end{itemize}

\vspace{2mm}
\textbf{Proposition 3.1.2:} The determinant function is unique.

\vspace{2mm}
\textbf{Proof:}

Assuming there are two determinant functions: \(f, g\).

For matrix \(A\), When \(r(A)<n\), according to the three characteristics,
\(f(A)=g(A)=0\).

When \(r(A)=n\), \(A\) can be presented as \(EP_1P_2\cdots P_m\) where
\(E\) is an identity matrix and \(P_1, P_2, \cdots, P_m\) are elementary
matrics. As \(f(E)=g(E)\), together with \textbf{Inference 1},
\(f(A)=g(A)\).

So \(f, g\) are identical.

\vspace{2mm}
\textbf{Proposition 3.1.3:}
For a determinant function \(f\), \(f(A)=f(A')\) where \(A'\) is
the transpose of matrix \(A\).

\vspace{2mm}
\textbf{Proof:}

When \(r(A)<n\), then \(f(A)=f(A')=0\).

When \(r(A)=n\), \(A\) can be presented as \(EP_1P_2\cdots P_m\) where
\(E\) is an identity matrix and \(P_1, P_2, \cdots, P_m\) are elementary
matrics. \(f(A)=(-1)^r\lambda_1\lambda_2\cdots \lambda_s\) where \(r,s\)
are numbers of the type I \& type II elementary matrics (i.e. \(P_i=P_n(j,k)\) or
\(P_i=P_n(\lambda\cdot k)\)) respectively.
Similarly, \(A'=EP'_mP'_{m-1}\cdots P'_1\).
\(f(A')=(-1)^{r'}\lambda_1\lambda_2\cdots \lambda_{s'}\).

When \(P_i\) is the
first or second type of elementary, matrics , \(P_i=P'_i\). So \(P_1P_2\cdots P_m\)
and \(P'_mP'_{m-1}\cdots P'_1\) contain the same number of type I and type
II elementary matrics.
When \(P_i\) is the
third type (i.e. \(P_i=P_n(\lambda\cdot j, k)\)), \(P'_i\) is also the
third type, therefore \(f(XP_i)=f(X)\) and \(f(XP'_i)=f(X)\) (\(P_i,
P'_i\) will not change the output of \(f\)).

So \(f(A)=f(EP_1P_2\cdots P_m)=f(EP'_mP'_{m-1}\cdots P'_1)=f(A')\).

\end{document}


\chapter{Overview}
\section{Summary}
We start by taking a quick look at finite-precision arithmetic. We then discuss how to solve ordinary differential equations (ODE) and partial differential equations (PDE) using the technique of separation of variables. We then introduce numerical time-stepping schemes that can be used to solve ODEs and PDEs. Next we introduce pseudo spectral methods by giving an overview of the discrete Fourier Transform (DFT) and the Fast Fourier Transform (FFT) algorithm that is used to quickly calculate the DFT. Finally we will combine all of this to solve a couple of different PDEs first in a serial setting and then in a parallel setting. The programs will use Matlab\footnote{\url{http://www.mathworks.com/products/matlab/index.html} -- if this is not available, we suggest modifying the Matlab programs to use Octave which can be freely downloaded at {\url{http://www.gnu.org/software/octave/}}.} and Fortran. A Python{\footnote{\url{http://python.org/}} implementation of some of the Matlab programs is also provided.

\section{Prerequisites}
We assume that the reader has introductory programming experience, for example using C, C++, Fortran, Matlab, Octave, Python or equivalent. Since detailed programming examples have been provided, we do not expect a significant programming background, but hope the required knowledge will be acquired as one works through the examples. We also assume the level of mathematical maturity obtained in a demanding calculus course, for example at the level of Courant and Johns ``Introduction to Calculus and Analysis''. A course in differential equations would also be helpful, but for many scientists or engineers, their fields of interest will provide numerous examples of these. More programming experience or mathematical background will make the material easier to understand. Checking whether the simulations are correct may also be easier for those with knowledge of the behavior of solutions of the partial differential equations that are being approximated, however we have tried to choose representative differential equations that will make it easy for one to use the programs and then adapt them to the use being considered.

\section{Using the Programs}

The programs have been tested on several different computers. The programs are located in program directories which correspond to the chapter in which the programs first appear. While they are not explicitly hyperlinked, one can find their locations either by reading the LaTeX source code or by searching the appropriate directory.

The Matlab programs are guaranteed to work with Matlab R2011b, but should also work with other recent versions of Matlab. They should also be easy to modify so that they work with Octave. The Fortran programs have been tested primarily with the GCC 4.6.2 compiler suite, although they should work with most other recent compilers. If using an implementation of MPI that depends on a particular compiler, we suggest also using the GCC compiler. We expect that the programs should work with minor modifications with other compilers, but cannot guarantee this.  For simplicity and to allow checking of program correctness, we have chosen to use a low compiler optimization level. We encourage users to increase the compiler optimization level and compiler flags once they have checked that the programs are working correctly on their systems. FFTW, a free Fast Fourier transform library, is also required to run the programs. This can be downloaded from \url{http://fftw.org/}. The MPI programs make use of the library 2DECOMP\&FFT which can be downloaded from \url{http://www.2decomp.org}. Finally, the last part of the tutorial requires the use of the free and open source VisIt parallel visualization program, which can be obtained from \url{https://wci.llnl.gov/codes/visit/home.html}. If you expect to do large parallel simulations (A guide for large at present is 20\% of the system for systems larger than 10,000 cores), it may be worth learning the most efficient system settings for performing output and for parallelization. We do not address this in this tutorial, but suggest that you contact your computing center for suggestions.

\section{Course Outlines / Assessment Rubric}

The material in these notes can form the basis of a short course. The most important portions are chapters 1 to  11.  A selection can then be made from chapters 12, 13 and 14. A selection of the problems can be used to assess student learning. Note that problems in chapters 8.  12, 13 and 14 can develop into extensive research projects, so only a sample of these should be given to any students if they only have a limited time to solve them. A student will have successfully understood the material if they can run the example Matlab/Python, serial Fortran, OpenMP Fortran and MPI Fortran programs, and can also modify them to solve related problems. Successful completion of problems which test these abilities will be enough to indicate that students have understood the fundamental concepts.


\chapter{Properties of Cheby\-shev-Vander\-monde Ma\-trices}
\label{chap:CV_Prop}

In this chapter we discuss properties of Chebyshev polynomials
and Chebyshev-Vander\-monde (C\-/V) matrices that we will
use in later chapters to develop fast algorithms for
solving interpolation and differential equations.


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{September 3, 2014}
\maketitle
\section*{1.1 \#11}
if $a>0$ then $(ab,ac)=a(b,c)$

assume $a,b,c\in\mathbb{Z}, a>0$
\begin{align*}
  d&=(ab,ac)\\
  d&=mab+mac\text{ theorem 1.1.6}\\
  &=a(mb+nc)\text{ this is a linear combination of gcd for }a,b\\
  mb+nc&\in\gcd(b,c)\mathbb{Z}\\
  d&=ad_1
\end{align*}
now prove that $d|ad_1$.
\begin{align*}
  d_1&=m'b+n'c\text{ for some }m',n'\in\mathbb{Z}\\
  ad_1&=m'ab+n'ac\\
  d&=(ab,ac)\rightarrow d|m'ab+n'ac\rightarrow d|ad_1
\end{align*}
\section*{$3x+7$ divisible by 11 (problem 22)}
$x=11+5k,k\in\mathbb{Z}$, note there are infinitely many solutions, and the difference between any two solutions is 11

if $x=5+11k$ for $k\in\mathbb{Z}$ then $3x+7=3(5+11k)+7$

assume $3x+7$ is divisible by 11. $11q+r=x, 0\le r<10$ then $3x+7=3(11q+r)+7=33q+3r+7$ so $3r+7$ is divisible by 11. we know that $0\le r<11$ so $7\le 3r+7\le37$, $3r+7\in\{11,22,33\}\rightarrow r=5$
\section*{fundamental  theorem of arithmetic}
any integer $a>1$ can be factored uniquely as a product of prime numbers. $a=p_1^{\alpha_1}p_2^{\alpha_2}...p_n^{\alpha_n}...$ with $p_1<p_2<...<p_n$ and $\alpha_1,\alpha_2,...\alpha_n$ positive integers
\section*{least common multiple}
given $a,b\in\mathbb{Z}^+$, we say that the positive integer $m$ is the lcm of $a$ and $b$ if
\begin{enumerate}
\item
$a|m$ and $b|m$
\item
if $a|c$ and $b|c$ then $m|c$
\end{enumerate}
\subsubsection*{fact}
$a=p_1^{\alpha_1}p_2^{\alpha_2}...p_n^{\alpha_n}$

$b=p_1^{\beta_1}p_2^{\beta_2}...p_n^{\beta_n}$

$p_1<p_2<...<p_n, \alpha_i,\beta_i\ge 0$

then $(a,b)=p_1^{\min\{\alpha_1,\beta_1\}}...p_n^{\min\{\alpha_n,\beta_n\}}$

then $[a,b]=p_1^{\max\{\alpha_1,\beta_1\}}...p_n^{\max\{\alpha_n,\beta_n\}}$
\subsubsection*{example}
\begin{align*}
  6&=2^13^15^0\\
  15&=2^03^15^1\\
  (6,15)&=2^03^15^0=3\\
  [6,15]&=2^13^15^1=30
\end{align*}
\subsubsection*{observe}
$(a,b)[a,b]=ab$

least common multiple of $a,b$ is $ab$
\section*{congruences}
\subsection*{definition}
given $a,b\in\mathbb{Z}$ and $n\in\mathbb{Z}, n>0$ we say that $a\equiv b \mod n$ if $a$ and $b$ give the same remainder when divided by $n$

exercise from last time showed $a\equiv b \mod n\Leftrightarrow n|(a-b)$
\subsubsection*{properties}
\begin{enumerate}
\item
\begin{align*}
  a\equiv b \mod n\\
  c\equiv d \mod n\\
  \intertext{implies}
  a\pm c\equiv b\pm d \mod n\\
  \intertext{and}
  ac\equiv bd \mod n\\
\end{align*}
\subsubsection*{proof}
we prove that $ac\equiv bd \mod n$

we know that $n|(a-b)$ and $n|(c-d)$. write that $a-b=n\alpha, \alpha\in\mathbb{Z}$ and $c-a=n\beta, \beta\in\mathbb{Z}$ then $ac-bd=(b+n\alpha)(d+m\beta)-bd=$multiple of $n \Box$

\item
$a\in\mathbb{Z}, n>1, n\in\mathbb{Z}$ then there exist $b\in\mathbb{Z}$ such that $ab\equiv 1 \mod n$ if and only if $(a,n)=1$

\emph{note} $3x+7$ divisible by 11 is like saying $3x\equiv -7\equiv4 \mod 11$. $12x\equiv-28 \mod 11$
\subsubsection*{proof}
$\Rightarrow$

assume $ab\equiv1\mod n$ for some $b\in\mathbb{Z}$. Then $ab-1=n\alpha$ for some $\alpha\in\mathbb{Z}$ and $ab+n\alpha=1\rightarrow d=(a,b)$ so $d|1\rightarrow d=1$

$\Leftarrow$

assume $(a,n)=1$. there exist $\alpha,\beta\in\mathbb{Z}$ such that $a\alpha+n\beta=1$ and then $a\alpha\equiv1\mod n$
\end{enumerate}
\end{document}


\subsection{Integers}

\begin{frame}
  \frametitle{Solving \Lia with \Lra}

  The Simplex can be used also to reason (in a complete way) about the integers (\Lia),
  e.g., using known techniques in linear programming
  \vfill
  Given a set of \Lia constraints $S$
  \begin{itemize}
    \item If $S$ is unsatisfiable
          on \Lra\footnote{This means that we allow variables to assume values in \Rat instead of \Int.}
	  then it is also unsatisfiable on \Lia
    \item If $S$ is satisfiable on \Lra, then we have to check if there is an integer solution
  \end{itemize}
  \vfill\pause
  For the latter case the convex polytope on \Rat is explored sistematically.
  However, in general, search is necessary: \Lia is NP-Complete, like SAT
  \begin{itemize}
    \item in SAT we split $a$ and $\neg a$, in \Lia we split $x \leq c$ and $x \geq c+1$
    \item in SAT we learn clauses, in \Lia we learn new tableau rows (new constraints)
  \end{itemize}
  \vfill\pause
  When on the integers, $\delta$ is set to $1$ ($\Rat_\delta$ numbers are not used)

\end{frame}


\documentclass[11pt, oneside]{article}

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

\usepackage{sets}
\usepackage{topological-spaces}
\usepackage{groups}
\usepackage{real-numbers}

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

\begin{document}

\maketitle

\begin{abstract}
This article contains Z Notation type declarations for the real numbers, $\R$, and some related objects.
It has been type checked by \fuzz.
\end{abstract}

\section{Introduction}

The real numbers, $\R$, are foundational to many mathematical objects such as vector spaces and manifolds,
but are not built-in to Z Notation.
This article provides type declarations for $\R$ and related objects so that they can be used and type checked in formal Z specifications.

No attempt has been made to provide complete, axiomatic definitions of all these objects since that would only be of use for proof checking.
Although proof checking is highly desirable, it is beyond the scope of this article.
The type declarations given here are intended to provide a basis for future axiomatization.

\section{Real Numbers}

Z notation does not predefine the set of real numbers, so we define it here.

\subsection{\zcmd{R}}

Let $\R$ denote the set of real numbers.
We define it to be simply a given set.
We'll add further axioms as needed below.

\begin{zed}
[\R]
\end{zed}

\subsection{\zcmd{addR}, \zcmd{zeroR}, \zcmd{negR}, and \zcmd{subR}}

Let $x$ and $y$ be real numbers.
Let $x \addR y$ denote addition,
let $\zeroR$ denote zero,
let $\negR x$ denote negation,
and let $x \subR y$ denote subtraction.

\begin{axdef}
	\_ \addR \_: \R \cross \R \fun \R \\
	\zeroR: \R \\
	\negR: \R \fun \R
\end{axdef}

Although these real number objects are displayed using the same symbols as the corresponding integer objects,
they represent distinct mathematical objects.
This distinction is apparent to the \fuzz\ type-checker and should not cause confusion to the human reader
because the underlying types of objects will, as a rule, be clear from the context.
Visually distinct symbols will be used in cases where confusion is possible.

The real numbers form an Abelian group under addition.

\begin{zed}
(\_ \addR \_) \in \abgroup \R
\also
\zeroR = identity\_element(\_ \addR \_)
\also
\negR = inverse\_operation(\_ \addR \_)
\end{zed}

Subtraction is defined in terms of addition and negative.

\begin{axdef}
	\_ \subR \_: \R \cross \R \fun \R
	\where
	\forall x, y: \R @ x \subR y = x \addR (\negR y)
\end{axdef}

\subsection{\zcmd{Rnz}}

Let $\Rnz$ denote the set of non-zero real numbers,
also referred to as the {\it punctured real number line}.

\begin{zed}
	\Rnz == \R \setminus \{ \zeroR \}
\end{zed}

\subsection{\zcmd{mulR}}

Let $x$ and $y$ be real numbers.
Let $x \mulR y$ denote multiplication.

\begin{axdef}
	\_ \mulR \_: \R \cross \R \fun \R
\end{axdef}

\subsection{\zcmd{mulRnz}, \zcmd{oneR}, \zcmd{invRnz}, and \zcmd{divR}}

Let $(\_ \mulRnz \_)$ denote the restriction of $(\_ \mulR \_)$ to $\Rnz$.

\begin{axdef}
	\_ \mulRnz \_: \Rnz \cross \Rnz \fun \Rnz
	\where
	(\_ \mulRnz \_) = (\lambda x, y: \Rnz @ x \mulR y)
\end{axdef}

Let $x$ be real number and let $y$ be a non-zero real number.
let $\oneR$ denote one,
let $y \invRnz$ denote inverse,
and let $x \divR y$ denote division.

\begin{axdef}
	\oneR: \Rnz \\
	\_ \invRnz: \Rnz \fun \Rnz
\end{axdef}

The non-negative real numbers form an Abelian group under multiplication.

\begin{zed}
(\_ \mulRnz \_) \in \abgroup \Rnz
\also
\oneR = identity\_element(\_ \mulRnz \_)
\also
(\_ \invRnz) = inverse\_operation(\_ \mulRnz \_)
\end{zed}

Division is defined in terms of multiplicative inverse.

\begin{axdef}
	\_ \divR \_: \R \cross \Rnz \fun \R
	\where
	\forall x: \R; y: \Rnz @ x \divR y = x \mulR (y \invRnz)
\end{axdef}

Addition is distributive over multiplication.

\begin{zed}
	\forall x, y, z: \R @ (x \addR y) \mulR z = x \mulR z \addR y \mulR z
\end{zed}

\subsection{\zcmd{ltR}, \zcmd{leR}, \zcmd{gtR}, and \zcmd{geR}}

Let $x \ltR y$, $x \leR y$, $x \gtR y$, and $x \geR y$ denote the usual comparison relations.

\begin{axdef}
	\_ \ltR \_: \R \rel \R \\
	\_ \leR \_: \R \rel \R \\
	\_ \gtR \_: \R \rel \R \\
	\_ \geR \_: \R \rel \R
\end{axdef}

\subsection{\zcmd{absR}}

Let $\absR(x)$ denote $\abs{x}$, the absolute value of $x$.

\begin{axdef}
	\absR: \R \fun \R
\where
	\forall x: \R @ \\
	\t1	\absR(x) = \IF x \geR \zeroR \THEN x \ELSE \negR~x
\end{axdef}

\subsection{\zcmd{Rpos}}

Let $\Rpos$ denote the set of positive real numbers.

\begin{zed}
	\Rpos == \{~ x: \R | x \gtR \zeroR ~\}
\end{zed}

\subsection{\zcmd{sqrtR}}

For non-negative $x$, let $\sqrtR(x)$ denote $\sqrt{x}$, the non-negative square root of $x$.

\begin{axdef}
	\sqrtR: \R \pfun \R
\where
	\sqrtR = \{~ x: \R | x \geR \zeroR @ x \mulR x \mapsto x ~\}
\end{axdef}

\section{Open Sets}

\subsection{\zcmd{intervalR}}

For any real numbers $a$ and $b$, let $\intervalR(a,b)$ denote $(a,b)$, the open interval bounded by $a$ and $b$.

\begin{axdef}
	\intervalR: \R \cross \R \fun \power \R
\where
	\forall a, b: \R @ \\
	\t1	\intervalR(a,b) = \{~ x: \R | a \ltR x \ltR b ~\}
\end{axdef}

\begin{remark}
If $a \geR b$ then $\intervalR(a,b) = \emptyset$.
\end{remark}

\subsection{\zcmd{ballR}}

For any real numbers $x$ and $r$, let $\ballR(x,r)$ denote the set of all real numbers within distance $r$ of $x$.

\begin{axdef}
	\ballR: \R \cross \R \fun \power \R
\where
	\forall x, r: \R @ \\
	\t1	\ballR(x,r) = \{~ x': \R | \absR(x' \subR x) \ltR r ~\}
\end{axdef}

\begin{remark}
Balls are intervals.

\begin{zed}
	\forall x, r: \R @ \\
	\t1	\ballR(x,r) = \intervalR(x \subR r, x \addR r)
\end{zed}

\end{remark}

\begin{remark}
If $r \gtR 0$ then $x$ is in $\ballR(x, r)$.

\begin{zed}
	\forall x: \R; r: \Rpos @ \\
	\t1	x \in \ballR(x,r)
\end{zed}

\end{remark}

\begin{remark}
If $r \leR 0$ then $\ballR(x,r)$ is empty.

\begin{zed}
	\forall x, r: \R | r \leR \zeroR @ \\
	\t1	\ballR(x,r) = \emptyset
\end{zed}

\end{remark}

\subsection{\zcmd{ballsR}}

Let $\ballsR$ denote the set of all open balls in $\R$.

\begin{axdef}
	\ballsR: \family~\R
\where
	\ballsR = \{~ x, r: \R @ \ballR(x,r) ~\}
\end{axdef}

\subsection{\zcmd{openR}}

A subset $U$ of $\R$ is said to be {\it open} if every point $x \in U$ is surrounded by some open ball $B \subset U$ that lies
strictly within $U$.
Let $\openR$ denote the set of all open subsets of $\R$.

\begin{axdef}
	\openR: \family~\R
\where
	\openR = \\
	\t1	\{~ U:  \power \R | \\
	\t2		\forall x: U @ \\
	\t3			\exists B: \ballsR @ x \in B \subset U ~\}
\end{axdef}

\begin{remark}
All balls are open.

\begin{zed}
	\ballsR \subset \openR
\end{zed}

\end{remark}

\begin{remark}
The empty set is open.

\begin{zed}
	\emptyset \in \openR
\end{zed}

\end{remark}

\begin{remark}
The set of all real numbers is open.

\begin{zed}
	\R \in \openR
\end{zed}

\end{remark}

\subsection{\zcmd{tauR}}

The topology generated by the open balls of $\R$ is referred to as the {\it usual} or {\it standard} topology on $\R$ .
Let $\tauR$ denote the usual topology on $\R$.

\begin{axdef}
	\tauR: top[\R]
\where
	\tauR = topGen[\R] \ballsR
\end{axdef}

\begin{remark}

\begin{zed}
	\tauR = \openR
\end{zed}

\end{remark}

\subsection{\zcmd{Rtau}}

Let $\Rtau$ denote the topological space defined by $\R$ with the usual topology.

\begin{axdef}
	\Rtau: topSpaces[\R]
\where
	\Rtau = (\R, \tauR)
\end{axdef}

\begin{example}

\begin{zed}
	\Rtau \in topSpace[\R]
\end{zed}

\end{example}

\subsection{\zcmd{neighR}}

Let $x$ be a real number.
Any open set that contains $x$ is called a {\it neighbourhood} of it.
Let $\neighR(x)$ denote the set of all neighbourhoods of $x$.

\begin{axdef}
	\neighR: \R \fun \family~\R
\where
	\forall x: \R @ \\
	\t1	\neighR(x) = \{~ U: \openR | x \in U~\}
\end{axdef}

Clearly, every real number has an infinity of neighbourhoods.

\begin{remark}
Any open ball that contains $x$ is a neighbourhood of $x$.

\begin{zed}
	\forall x: \R; B: \ballsR | \\
	\t1	x \in B @ \\
	\t2		B \in \neighR(x)
\end{zed}

\end{remark}

\section{Functions}

The following sections define continuity, limits, and differentiability, which are point-wise properties of functions.
These properties are {\it local} in the sense that in order to determine if they hold at a given point it is sufficient to
consider the restriction of the function to an arbitrarily small neighbourhood of the point.
It is therefore useful to first introduce the set of {\it locally defined} functions,
namely those functions that are defined in some neighbourhood of each point of  their domains.

\subsection{\zcmd{FunR}}

For $x$ a real number,
let $\FunR(x)$ denote the set of all real-valued, partial functions on $\R$ that are locally defined at $x$.

\begin{axdef}
	\FunR: \R \fun \power(\R \pfun \R)
\where
	\forall x: \R @ \\
	\t1	\FunR(x) = \{~ f: \R \pfun \R | \exists U: \neighR(x) @ U \subseteq \dom f ~\}
\end{axdef}

\begin{remark}
The function $\sqrtR$ is not locally defined at $0$ because it's defined only for non-negative numbers,
but every neighbourhood of $0$ contains some negative numbers.

\begin{zed}
	\sqrtR \notin \FunR(\zeroR)
\end{zed}

\end{remark}

\subsection{\zcmd{FunPR}}

For $U$ a subset of $\R$,
let $\FunPR(U)$ denote the set of all real-valued functions on $U$ that are locally defined at each point of $U$.

\begin{axdef}
	\FunPR: \power \R \fun \power (\R \pfun \R)
\where
	\forall U: \power \R @ \\
	\t1	\FunPR(U) = \{~ f: U \fun \R | \forall x: U @ f \in \FunR(x) ~\}
\end{axdef}

\begin{remark}
If $f \in \FunPR(U)$ then $U \in \openR$.

\begin{zed}
	\forall U: \power \R @ \\
	\t1	\FunPR(U) \neq \emptyset \implies U \in \openR
\end{zed}

\end{remark}

\section{Continuity}

Let $f$ be a real-valued partial function on $\R$
that is locally defined at $x$ and let $U$ be a neighbourhood of $x$
contained within the domain of $f$.
The function $f$ is said to be {\it continuous} at $x$ if
for any $\epsilon > 0$ there is some $\delta > 0$ for which
$f(x')$ is always within $\epsilon$ of $f(x)$
when $x' \in U$ is within $\delta$ of $x$.
\begin{argue}
\forall \epsilon > 0 @ \exists \delta > 0 @ \forall x' \in U @ \\
\t1	\abs{x' - x} < \delta \implies \abs{f(x') - f(x)} < \epsilon
\end{argue}

\begin{schema}{RealContinuous}
	f: \R \pfun \R \\
	x: \R
\where
	f \in \FunR(x)
\also
	\forall \epsilon: \Rpos @ \exists \delta: \Rpos@ \forall x': \dom f @ \\
	\t1	\absR(x' \subR x) \ltR \delta \implies \absR(f(x') \subR f(x)) \ltR \epsilon
\end{schema}

\subsection{\zcmd{CzeroR}}

Let $\CzeroR(x)$ denote the set of all real-valued partial functions on $\R$ that are continuous at $x$.
\begin{axdef}
	\CzeroR: \R \fun \power(\R \pfun \R)
\where
	\forall x: \R @ \\
	\t1	\CzeroR(x) = \{~ f: \FunR(x) | RealContinuous ~\}
\end{axdef}

\subsection{\zcmd{CzeroPR}}

Let $U$ be any subset of $\R$.
Define $\CzeroPR(U)$ to be the set of all real-valued functions on $U$ that are continuous at each point in $U$.

\begin{axdef}
	\CzeroPR: \power \R \fun \power (\R \pfun \R)
\where
	\forall U: \power \R @ \\
	\t1	\CzeroPR(U) = \{~ f: \FunPR(U) | \forall x: U @ f \in   \CzeroR(x) ~\}
\end{axdef}

\begin{remark}
If $f \in \CzeroPR(U)$ then $U$ is open.

\begin{zed}
	\forall U: \power \R @ \\
	\t1	\CzeroPR(U) \neq \emptyset \implies U \in \openR
\end{zed}

\end{remark}

\begin{remark}
The $\epsilon-\delta$ definition of continuity given above is compatible with the definition
of continuity for mappings between topological spaces when we consider $\Rtau$, the usual topology on $\R$,
and $\Rtau \inducedTopSp U$, the topology induced on the subset $U$.

\begin{zed}
	\forall U: \openR @ \\
	\t1	\CzeroPR(U) = \CzeroTT(\Rtau \inducedTopSp U, \Rtau)
\end{zed}

\end{remark}

\section{Limits}

Let $x$ and $l$ be real numbers and
let $f$ be a real-valued partial function on $\R$ that is defined everywhere in some
neighbourhood $U$ of $x$, except possibly at $x$.
The function $f$ is said to approach the limit $l$ at $x$ if $f \oplus \{ x \mapsto l \}$ is continuous at $x$.
$$
	\lim_{x' \to x}{f(x')} = l
$$

\begin{schema}{Limit}
	f: \R \pfun \R \\
	x, l: \R
\where
	f \oplus \{x \mapsto l\} \in \CzeroR(x)
\end{schema}

\subsection{\zcmd{limRR}}

Let $\limRR(x,l)$ denote the set of all real-valued partial functions on $\R$ that approach the limit $l$ at $x$.

\begin{axdef}
	\limRR: \R \cross \R \fun \power(\R \pfun \R)
\where
	\forall x, l: \R @ \\
	\t1	\limRR(x,l) = \{~ f: \R \pfun \R | Limit ~\}
\end{axdef}

\begin{theorem}
If a function $f$ approaches some limit at $x$ then that limit is unique.
\begin{zed}
	\forall x, l, l': \R @ \\
	\t1	\forall f : \limRR(x,l) \cap \limRR(x,l') @ \\
	\t2		l = l'
\end{zed}
\end{theorem}

\begin{proof}
Suppose we are given real numbers
\begin{argue}
	x, l, l' \in \R
\end{argue}
and a function
\begin{argue}
	f \in \limRR(x,l) \cap \limRR(x,l')
\end{argue}
Let $\epsilon$ be any positive real number
\begin{argue}
	\epsilon > 0
\end{argue}
Since $f$ approaches limits $l$ and $l'$ at $x$ there exists a real number $\delta > 0$ such that
\begin{argue}
	\forall x' \in \R |  \\
	\t1	\zeroR \ltR \abs{x' \subR x}< \delta @ \\
	\t2		 \abs{f(x') - l} < \epsilon \land \abs{f(x') - l'} < \epsilon
\end{argue}
For any such real number $x'$ we have
\begin{argue}
	\abs{l' - l} \\
	\t1	= \abs{(f(x') - l) - (f(x') - l')} 			& add and subtract $f(x')$ \\
	\t1	\leq \abs{f(x') - l} + \abs{f(x') - l'} 	& triangle inequality \\
	\t1	= 2\epsilon					& definition of limits
\end{argue}
Since the above holds for any $\epsilon > 0$ we must have
\begin{argue}
	l = l'
\end{argue}

\end{proof}

\subsection{\zcmd{limFR}}

If $f$ approaches the limit $l$ at $x$ then let $\limFR(f,x)$ denote $l$.
By the preceding theorem, $\limFR(f,x)$ is well-defined when it exists.

\begin{axdef}
	\limFR: (\R \pfun \R) \cross \R \pfun \R
\where
	\limFR = \{~ Limit @ (f, x) \mapsto l ~\}
\end{axdef}

\section{Differentiability}

Let $f$ be a real-valued partial function on $\R$, let $x$ be a real number,
and let $f$ be defined on some neighbourhood $U$ of $x$.

The function $f$ is said to be {\it differentiable} at $x$ if the following limit holds for some number denoted by $f'(x)$.
$$
\lim_{h \to 0} \frac{f(x+h) - f(x)}{h} = f'(x)
$$

\begin{remark}
If $f$ is differentiable at $x$ then $f$ is continuous at $x$.
\end{remark}

The geometric intuition behind the concept of differentiability is that $f$ is differentiable at $x$
when, very near $x$, the graph of $f$ is approximately a straight line through the point $(x, f(x))$ with slope $f'(x)$.
$$
f(x + h) \approx f(x) + f'(x) h \quad \text{when} \quad \abs{h} \approx 0
$$
The slope $f'(x)$ is called the {\it derivative} of $f$ at $x$
and $f'$ is called the {\it derived function}.

We can read this definition as saying that the approximate slope function $m(h)$ defined for
small enough, non-zero values of $h$ by
$$
	m(h) = \frac{f(x + h) - f(x)}{h}
$$
approaches the limit $l = f'(x)$ as $h \to 0$.
$$
	\lim_{h\to 0}{m(h)} = l = f'(x)
$$

\begin{schema}{Differentiable}
	f: \R \pfun \R \\
	x, l: \R
\where
	f \in \CzeroR(x)
\also
	\LET m == (\lambda h: \Rnz | x \addR h \in \dom f @ (f(x \addR h) \subR f(x)) \divR h) @ \\
	\t1	\limFR(m, \zeroR) = l
\end{schema}

\begin{remark}
If $f$ is differentiable at $x$ then the limit $l$ is unique.
\end{remark}

\subsection{\zcmd{diffRR}}

Let $\diffRR(x,l)$ denote the set of all functions $f$ that are differentiable at $x$ with $f'(x) = l$.

\begin{axdef}
	\diffRR: \R \cross \R \fun \power(\R \pfun \R)
\where
	\forall x, l: \R @ \\
	\t1	\diffRR(x, l) = \{~ f: \R \pfun \R | Differentiable ~\}
\end{axdef}

\subsection{\zcmd{diffR}}

Let $\diffR(x)$ denote the set of all functions that are differentiable at $x$.

\begin{axdef}
	\diffR: \R \fun \power(\R \pfun \R)
\where
	\forall x: \R @ \\
	\t1	\diffR(x) = \bigcup \{~ l: \R @ \diffRR(x,l) ~\}
\end{axdef}

\subsection{\zcmd{diffPR}}

Let $U$ be any subset of $\R$.
Let $\diffPR(U)$ denote the set of all functions on $U$
that are differentiable at each point of $U$.

\begin{axdef}
	\diffPR: \power \R \fun \power(\R \pfun \R)
\where
	\forall U: \power \R @ \\
	\t1	\diffPR(U) = \{~ f: \CzeroPR(U) | \forall x: U @ f \in \diffR(x) ~\}
\end{axdef}

\section{Derivatives}

\subsection{\zcmd{derivFR}}

Let $\derivFR(f,x)$ denote $f'(x)$, the derivative of $f$ at $x$.

\begin{axdef}
	\derivFR: (\R \pfun \R) \cross \R \pfun \R
\where
	\derivFR = \{~ Differentiable @ (f,x) \mapsto l ~\}
\end{axdef}

\subsection{\zcmd{derivF}}

Let $\derivF(f)$ denote $f'$, the derived function.

\begin{axdef}
	\derivF: (\R \pfun \R) \fun (\R \pfun \R)
\where
	\forall f: \R \pfun \R @ \\
		\t1	\derivF f = (\lambda x: \R | f \in \diffR(x) @ \derivFR(f,x))
\end{axdef}

\begin{remark}
If $f$ is differentiable on $U$ then $f'$ is not necessarily continuous on $U$.
Counterexamples exist.
\end{remark}

\begin{remark}
If $f$ is uniformly differentiable on $U$ then $f'$ is continuous on $U$.
A further discussion of uniform differentiability is beyond the scope of this article.
\end{remark}

\section{Higher Order Derivatives}

Let $n$ be a natural number and let $x$ be a real number.
In differential geometry we normally deal with $C^n(x)$, the set of functions
that possess continuous derivatives of order $0, \ldots, n$ at $x$.

\subsection{\zcmd{CnR}}

Let $\CnR(n,x)$ denote the set of all functions that have continuous derivatives of order $0, \ldots, n$ at $x$.

\begin{axdef}
	\CnR: \nat \cross \R \fun \power(\R \pfun \R)
\where
	\forall x: \R @ \\
	\t1	\CnR(0,x) = \CzeroR(x)
\also
	\forall n: \nat; x: \R @ \\
	\t1	\CnR(n + 1, x) = \{~ f: \diffR(x) | \derivF f \in \CnR(n,x) ~\}
\end{axdef}

\subsection{\zcmd{CnPR}}

Let $n$ be a natural number and let $U$ be a subset of $\R$.
Let $\CnPR(n,U)$ denote the set of all functions on $U$ that have continuous derivatives of order $0, \ldots, n$
at every point of $U$.

\begin{axdef}
	\CnPR: \nat \cross \power \R \fun \power(\R \pfun \R)
\where
	\forall n: \nat; U: \power \R @ \\
	\t1	\CnPR(n,U) = \{~ f: \FunPR(U) | \forall x: U @ f \in \CnR(n,x) ~\}
\end{axdef}

\section{Smoothness}

\subsection{\zcmd{smoothR}}

A function is said to be {\it smooth} if it possesses continuous derivatives of all orders.
Let $x$ be a real number.
Let $\smoothR(x)$ denote the set of all functions that are smooth at $x$.

\begin{axdef}
	\smoothR: \R \fun \power(\R \pfun \R)
\where
	\forall x: \R @ \\
	\t1	\smoothR(x) = \{~ f: \FunR(x) | \forall n: \nat @ f \in \CnR(n, x) ~\}
\end{axdef}

\subsection{\zcmd{smoothPR}}

Let $\smoothPR(U)$ denote the set of all functions on $U$ that are smooth at every point of $U$.

\begin{axdef}
	\smoothPR: \power \R \fun \power (\R \pfun \R)
\where
	\forall U: \power \R @ \\
	\t1	\smoothPR(U) = \{~ f: \FunPR(U) | \forall x: U @ f \in \smoothR(x) ~\}
\end{axdef}

\section{Important Constants and Functions}

This section defines several important constants and functions.

\subsection{$integer\_as\_real$}

The real numbers contains a natural copy of the integers.
Let $integer\_as\_real$ denote this embedding.

\begin{axdef}
	integer\_as\_real : \num \inj \R
\end{axdef}

\subsection{\zcmd{realZ}}

We introduce the notation $\realZ x = integer\_as\_real~x$ for this embedding.

\begin{zed}
	\realZ == integer\_as\_real
\end{zed}

The real numbers $\zeroR$ and $\oneR$ are the images of the corresponding integers under this
embedding.

\begin{zed}
	\realZ 0 = \zeroR
\also
	\realZ 1 = \oneR
\end{zed}

\subsection{$IntegerTimesReal$}

We can use the embedding to define the product $y = n * x$ where $n$ is an integer
and $x$ and $y$ are real numbers.

\begin{schema}{IntegerTimesReal}
	n : \num \\
	x, y : \R
\where
	y = (\realZ n) \mulR x
\end{schema}

\subsection{$integer\_times\_real$}

Let $y = integer\_times\_real(n, y)$ denote this multiplication operation.

\begin{zed}
	integer\_times\_real == \{~ IntegerTimesReal @ (n, x) \mapsto y ~\}
\end{zed}

\subsection{\zcmd{mulZR}}

We introduce the notation $n \mulZR x = integer\_times\_real(n, x)$.

\begin{zed}
	(\_ \mulZR \_) == integer\_times\_real
\end{zed}

\subsection{$RealDivInteger$}

Similarly, we can define division of a real number $x$ by a nonzero integer $n$
to give the quotient $y = x / n$.

\begin{schema}{RealDivInteger}
	n : \num \\
	x, y : \R
\where
	n \neq 0
\also
	y = x \divR (\realZ n)
\end{schema}

\subsection{$real\_div\_integer$}

Let $y = real\_div\_integer(x, n)$ denote this division operation.

\begin{zed}
	real\_div\_integer == \{~ RealDivInteger @ (x, n) \mapsto y ~\}
\end{zed}

\subsection{\zcmd{divRZ}}

We introduce the notation $y = x \divRZ n$.

\begin{zed}
	(\_ \divRZ \_) == real\_div\_integer
\end{zed}

\subsection{\zcmd{sinR}}

Let $\sinR(x)$ denote the usual trigonometric sine function of the real number $x$.

\begin{axdef}
	\sinR : \R \fun \R
\end{axdef}

\subsection{\zcmd{cosR}}

Let $\cosR(x)$ denote the usual trigonometric cosine function of the real number $x$.

\begin{axdef}
	\cosR : \R \fun \R
\end{axdef}

\subsection{\zcmd{piR}}

Let $\piR$ denote the usual ratio of the perimeter of a circle to its diameter.

\begin{axdef}
	\piR : \R
\end{axdef}

\section{The Real Plane}

In order to define what it means for an arrangement of test tubes to be balanced,
we need to use some concepts from Euclidean geometry and classical mechanics.
Classical mechanics is phrased in terms of real coordinate systems.
We therefore start by defining the usual real plane and its coordinates.

\subsection{\zcmd{Rtwo}}

We model the real plane as pairs of real numbers.
Let $\Rtwo$ denote the real plane.

\begin{zed}
	\Rtwo == \R \cross \R
\end{zed}

\subsection{$zero\_real\_plane$}

Let the point $zero\_real\_plane \in \Rtwo$ denote the origin of the real plane.

\begin{zed}
	zero\_real\_plane == (\zeroR, \zeroR)
\end{zed}

\subsection{\zcmd{zeroRtwo}}

We introduce the usual notation $\zeroRtwo = zero\_real\_plane$ for the origin of the real plane.

\begin{zed}
	\zeroRtwo == zero\_real\_plane
\end{zed}

\subsection{$RealPlane$}

Let $point \in \Rtwo$ be a point in the real plane.
Its Cartesian coordinates are denoted by $x$ and $y$.
Let the schema $RealPlane$ denote this situation.

\begin{schema}{RealPlane}
	point: \Rtwo \\
	x, y : \R
\where
	point = (x, y)
\end{schema}

\subsection{$ScaleRealPlane$}

Let $a \in \R$ be a scaling factor and let $point \in \Rtwo$ be a point.
Let $point' = a * point$ be  $point$ scaled by $a$.
Let the schema $ScaleRealPlane$ denote this situation.

\begin{schema}{ScaleRealPlane}
	a : \R \\
	RealPlane \\
	RealPlane'
\where
	x' = a \mulR x
\also
	y' = a \mulR x
\end{schema}

\subsection{$scale\_real\_plane$}

Let $point' = scale\_real\_plane(a, point)$ denote the operation of scalar multiplication.

\begin{zed}
	scale\_real\_plane == \{~ ScaleRealPlane @ (a, point) \mapsto point' ~\}
\end{zed}

\subsection{\zcmd{smulRtwo}}

We introduce the notation $a \smulRtwo point = scale\_real\_plane(a, point)$
for scalar multiplication.

\begin{zed}
	(\_ \smulRtwo \_) == scale\_real\_plane
\end{zed}

\subsection{$ScaleIntRealPlane$}

It is convenient to allow scaling of points in the real plane by integers.
Let $n \in \num$ be a scaling factor and let $point \in \Rtwo$ be a point.
Let $point' = n * point$ be  $point$ scaled by $n$.
Let the schema $ScaleIntRealPlane$ denote this situation.

\begin{schema}{ScaleIntRealPlane}
	n : \num \\
	RealPlane \\
	RealPlane'
\where
	x' = n \mulZR x
\also
	y' = n \mulZR x
\end{schema}

\subsection{$scale\_int\_real\_plane$}

Let $point' = scale\_int\_real\_plane(n, point)$ denote the operation of scalar multiplication
by an integer.

\begin{zed}
	scale\_int\_real\_plane == \{~ ScaleIntRealPlane @ (n, point) \mapsto point' ~\}
\end{zed}

\subsection{\zcmd{smulZRtwo}}

We introduce the notation $n \smulZRtwo point = scale\_int\_real\_plane(n, point)$
for scalar multiplication.

\begin{zed}
	(\_ \smulZRtwo \_) == scale\_int\_real\_plane
\end{zed}

\subsection{$AddRealPlane$}

Let $point_1$ and $point_2$ be points.
We can define their sum $point' = point_1 + point_2$ by component-wise addition.
Let the schema $AddRealPlane$ denote this situation.

\begin{schema}{AddRealPlane}
	RealPlane_1 \\
	RealPlane_2 \\
	RealPlane'
\where
	x' = x_1 \addR x_2
\also
	y' = y_1 \addR y_2
\end{schema}

\subsection{$add\_real\_plane$}

Let $add\_real\_plane(point_1, point_2) = point_1 + point_2$ denote addition of points in the
real plane.

\begin{zed}
	add\_real\_plane == \{~ AddRealPlane @ (point_1, point_2) \mapsto point' ~\}
\end{zed}

\subsection{\zcmd{addRtwo}}

We introduce the usual notation $point_1 \addRtwo point_2 = add\_real\_plane(point_1, point_2)$
to denote addition of points in the real plane.

\begin{zed}
	(\_ \addRtwo \_) == add\_real\_plane
\end{zed}

\subsection{$sum\_real\_plane$}

Given a sequence $a$ of zero or more points in the real plane,
we define its sum $sum\_real\_plane(a)$ recursively as follows.

\begin{axdef}
	sum\_real\_plane : \seq \Rtwo \fun \Rtwo
\where
	sum\_real\_plane(\langle \rangle) = \zeroRtwo
\also
	\forall point : \Rtwo; a : \seq \Rtwo @ \\
	\t1	sum\_real\_plane(\langle point \rangle \cat a) = point \addRtwo sum\_real\_plane(a)
\end{axdef}

\subsection{\zcmd{sumRtwo}}

We introduce the notation $\sumRtwo(a) = sum\_real\_plane(a)$.

\begin{zed}
	\sumRtwo == sum\_real\_plane
\end{zed}

\subsection{\zcmd{addFRtwo}}

Let $\genT$ be any set and let $f$ and $g$ be partial functions from $\genT$ to $\Rtwo$.
Let $h(x) = f(x) + g(x)$ denote their pointwise sum on their common domain of definition.
Let the schema $AddFunctionsRealPlane$ denote this situation.

\begin{schema}{AddFunctionsRealPlane}[\genT]
	f, g, h : \genT \pfun \Rtwo
\where
	h = (\lambda x : \dom f \cap \dom g @ f~x \addRtwo g~x)
\end{schema}

Let the function $add\_functions\_real\_plane(f, g) = h$ map two functions with values in $\Rtwo$ to their pointwise sum.

\begin{gendef}[\genT]
	add\_functions\_real\_plane : (\genT \pfun \Rtwo) \cross (\genT \pfun \Rtwo) \fun (\genT \pfun \Rtwo)
\where
	add\_functions\_real\_plane = \\
	\t1	\{~ AddFunctionsRealPlane[\genT] @ (f, g) \mapsto h ~\}
\end{gendef}

We introduce the notation $f \addFRtwo g = add\_functions\_real\_plane(f, g)$.

\begin{zed}
	(\_ \addFRtwo \_)[\genT] == add\_functions\_real\_plane[\genT]
\end{zed}

\subsection{$PolarRealPlane$}

Let $(x, y)$ be the Cartesian coordinates of a point in the plane.
Let $r$ denote the distance of the point from the origin and
let $a$ denote the counter-clockwise angle of the point from the $x$-axis.
The pair $(r, a)$ is called the \textit{polar coordinates} of the point.
Conversely, given an pair $(r, a)$ we can compute the corresponding
Cartesian coordinates.
Let the schema $PolarRealPlane$ denote this situation.

\begin{schema}{PolarRealPlane}
	RealPlane \\
	r, a : \R
\where
	x = r \mulR \cosR a
\also
	y = r \mulR \sinR a
\end{schema}

\subsection{$polar\_to\_cartesian$}

Let the function $polar\_to\_cartesian(r, a) = (x, y)$ denote the mapping from
polar to Cartesian coordinates.

\begin{zed}
	polar\_to\_cartesian == \{~ PolarRealPlane @ (r, a) \mapsto (x, y) ~\}
\end{zed}

Note that this function is not one-to-one for the following reasons.
\begin{itemize}
	\item The pairs $(r, a + 2k\pi)$ for any $k \in \num$ map to the same points.
	\item The pairs $(r, a)$ and $(-r, a + \pi)$ map to the same points.
	\item The pairs $(0, a)$ and $(0, a')$ map to the same points.
\end{itemize}

\printbibliography

\end{document}


%
% CMPT 379: Principles of Compiler Design - A Course Overview
% Section: Syntax Analysis (Parsing)
%
% Author: Jeffrey Leung
%

\section{Syntax Analysis (Parsing)}
	\label{sec:syntax-analysis}
\begin{easylist}

& \textbf{Syntax analysis (parsing):} Translation of a set of strings into a valid structure using a grammar
	&& \textbf{Language:} Description of a valid string of tokens

& Symbols and rules:
	&& \textbf{Terminal symbol:} Token or base symbol which does not represent any other symbols
	&& \textbf{Non-terminal symbol:} Set of strings potentially consisting of one or more terminal or non-terminal symbols
	&& \textbf{Production/Rule/Production rule:} Function on a non-terminal symbol which generates a sequence of terminal and/or non-terminal symbols
		&&& \textbf{Expansion:} Sequence of symbols resulting from the application of a production rule

\end{easylist}
\subsection{Context-Free Grammars}
	\label{subsec:syntax-analysis:context-free-grammars}
\begin{easylist}

& \textbf{Context-Free Grammar (CFG):} Recursive notation for the structure of a valid syntax; subset of regular grammars
	&& Generates a \textit{Context-Free Language (CFL)}
	&& Defined by a set of non-terminal states $N$, a start state $S \in N$, a set of terminal states $T$, and a set of productions to create a set of states
		&&& Each state is a string consisting of non-terminal and/or terminal symbols
		&&& If multiple productions exist from the start state, then in order to backtrack from a terminal state to the start state, create a new start state $S'$ which has a single production to the original state state
		&&& Productions can be implemented using a transition matrix
	&& E.g. Given grammar $\bigg\{ (^i)^i | i \geq 0 \bigg\}$ (i.e. The number of opening brackets must match the number of closing brackets) the productions are:
		&&& $S \rightarrow \epsilon$
		&&& $S \rightarrow (S)$
		&&& $N = \{ S \}$
		&&& $T = \big\{ (, ) \big\}$
	&& E.g. Given language $\bigg\{ wcw^R | w \in (a|b)* \bigg\}$, a CFG which produces this language is $S \rightarrow aSa | bSb | c$
	&& E.g. Given language $\bigg\{ a^n b^m c^m d^n | n \geq 1, m \geq 1 \bigg\}$, a CFG which produces this language is $S \rightarrow aSd | aAd; A \rightarrow bAc | bc$
	&& \textbf{Ambiguous:} CFG which can produce multiple unique parse trees
		&&& Unacceptable for programming languages
		&&& Prevention techniques:
			&&&& Rewriting grammar unambiguously
			&&&& Separating non-terminal states by different precedence levels
				&&&&& E.g. $E \rightarrow E - E; E \rightarrow T; T \rightarrow T / T$
				&&&&& E.g. $A \rightarrow A - B; A \rightarrow B$
			&&&& \textbf{Left/Right associative:} Property of an operator specifying which of multiple operations with the same precedence should be evaluated first
	&& \textbf{Recursive in non-terminal $X$:} CFG where, in one or more productions, $X$ can derive a sequence of symbols including $X$
		&&& \textbf{Left recursive in non-terminal $X$:} CFG where, in one or more productions, $X$ can derive a sequence of symbols which begins with $X$
		&&& \textbf{Right recursive in non-terminal $X$:} CFG where, in one or more productions, $X$ can derive a sequence of symbols which ends with $X$

\end{easylist}
\subsection{Parsing}
	\label{subsec:syntax-analysis:parsing}
\begin{easylist}

& \textbf{Parse tree:} Tree-shaped sequence of CFG productions used to generate a valid derivation of symbols, with the root being the start symbol and children being productions of the parent (i.e. for a given production $X \rightarrow Y_1 \dotsc Y_n$, the children of $X$ are $Y_1 \dotsc Y_n$)
	&& \textbf{Leftmost derivation:} Sequence of CFG productions to create a parse tree by continually processing the leftmost non-terminal state
	&& \textbf{Rightmost derivation:} Sequence of CFG productions to create a parse tree by continually processing the rightmost non-terminal state
	&& E.g. For the production rules in table~\ref{tab:parse-tree-example-1-prod-rules}, the parse tree of $id + id * id$ is shown in figure~\ref{fig:parse-tree-example-1}
	&& E.g. For the production rules in table~\ref{tab:parse-tree-example-2-prod-rules}, the parse tree of $id + id * id$ is shown in figure~\ref{fig:parse-tree-example-2}

\end{easylist}
\begin{figure}[!htb]
	\caption{Parse Tree Example 1: Production Rules}
	\label{tab:parse-tree-example-1-prod-rules}
	\begin{center}
		\begin{tabular}{ l }
			$E \rightarrow E + E$ \\
			$E \rightarrow E * E$ \\
			$E \rightarrow id$
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

\end{easylist}
\begin{figure}[!htb]
	\caption{Parse Tree Example 1}
	\label{fig:parse-tree-example-1}
	\begin{center}
		String: $id + id * id$ \\[1em]
		\begin{forest}
			[$E$
				[$E$
					[$E$[$id$]]
					[$+$]
					[$E$[$id$]]
				]
				[$*$]
				[$E$
					[$id$]
				]
			]
		\end{forest}
	\end{center}
\end{figure}
\begin{easylist}

\end{easylist}
\begin{figure}[!htb]
	\caption{Parse Tree Example 2: Production Rules}
	\label{tab:parse-tree-example-2-prod-rules}
	\begin{center}
		\begin{tabular}{ l }
			$E \rightarrow T + E$ \\
			$E \rightarrow T$ \\
			$T \rightarrow int$ \\
			$T \rightarrow int * T$ \\
			$T \rightarrow (E)$
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

\end{easylist}
\begin{figure}[!htb]
	\caption{Parse Tree Example 2}
	\label{fig:parse-tree-example-2}
	\begin{center}
		String: $int * int + int$ \\[1em]
		\begin{forest}
			[$E$
				[$T$
					[$int$]
					[$*$]
					[$T$[$int$]]
				]
				[$+$]
				[$E$[$T$[$int$]]]
			]
		\end{forest}
	\end{center}
\end{figure}
\begin{easylist}

& \textbf{Pushdown automaton (PDA):} \hyperref[subsec:finite-state-automata]{Finite State Automata} system which utilizes a stack to parse a CFL
	&& Notations:
		&&& Finite set of states: $S$
		&&& Start state: Outlined
		&&& Final/accepting state: Double-outlined
		&&& Production rules: $P$
	&& Uses a stack structure to hold symbols
	&& For each CFG, there exists an equivalent PDA

& \textbf{Shift-reduce parsing:} Method of bottom-up parsing which reduces a string to a start symbol, using reversed production rules
	&& Uses a left substring containing terminal or non-terminal symbols, and a right substring containing as-of-yet unprocessed symbols
	&& Starts with the entire string in the right substring
	&& Right substring utilizes a stack with the following options:
		&&& \textbf{Shift:} Retrieving a symbol from the stack (right substring) and placing it on the left substring
		&&& \textbf{Reduce:} Removing one or more symbols from the stack (right substring), processing them with a reversed production rule, and returning the result to the stack
	&& Example:
	\end{easylist}
	\begin{align*}
		\textrm{Stack} & | \textrm{Input} & \textrm{Action} \\
		\hline
		& | x_1 x_2 x_3 x_4 & \textrm{Begin}\\
		x_1 & | x_2 x_3 x_4 & \textrm{Shift } x_1 \\
		x_1 & | y_1 x_4 & \textrm{Reduce } x_2 x_3 \textrm{ to } y_1 \\
		x_1 y_1 & | x_4 & \textrm{Shift } y_1 1\\
		x_1 y_1 & | y_2 & \textrm{Reduce } x_4 \textrm{ to } y_2 \\
		x_1 y_1 y_2 & | & \textrm{Shift } y_2
	\end{align*}
	\begin{easylist}

	&& \textbf{Shift-reduce conflict:} Situation in shift-reduce parsing where either a shift or reduce can create valid parses
		&&& Solution: Precedence/associativity declarations
	&& \textbf{Reduce-reduce conflict:} Situation in shift-reduce parsing where multiple different reduces can create valid parses
		&&& Solution: Rewrite grammar to no longer be ambiguous
	&& \textbf{Handle:} Sequence of symbol(s) at the top of the stack which is a valid reduction allowing further reductions towards the start symbol
		&&& \textbf{Prune:} Action of reducing a handle and pushing the result onto the stack
		&&& To find a handle, heuristics are used; no efficient algorithms exist

\end{easylist}
\clearpage


\documentclass[40pt,letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{cancel}
\usepackage{datetime}
\usepackage{fullpage}
\usepackage{verbatim}
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
\author{Dmitri Priimak}
\title{Josephson Junctions Array}
\def\spvec#1{\left(\vcenter{\halign{\hfil$##$\hfil\cr \spvecA#1;;}}\right)}
\def\spvecA#1;{\if;#1;\else #1\cr \expandafter \spvecA \fi}
\begin{document}
 \begin{center}
  \underline{Array of Josephson Junctions in the periodic a/c field.}
 \end{center}
  \begin{center}
    \underline{Rev. 1}
  \end{center}
   	\section{Many Josephson Junctions}
  	\begin{eqnarray}
  	\frac{\text{d}q}{\text{d}t} &=& q_1 \\
  	\frac{\text{d}\phi_k}{\text{d}t} &=& i_{dc}
  		+ i_1 \cos(\Omega_{1}t) - \sin(\phi_k)
  		- q_1 \\
  	\frac{\text{d}q_1}{\text{d}t} &=&
  	\frac{1}{l}\left[N \left( i_{dc}
  		+ i_1 \cos(\Omega_1 t) - q_1\right)
  		- \sum_{k=0}^{N-1} \sin(\phi_k)
  		\right]
  		-\frac{r}{l}q_1 - \Omega_0^2 q
  	\end{eqnarray}
  	Let us introduce new vector $\mathbf{r} = \spvec{q;\{\phi_k\};q_1}$ and a vector function $\mathbf{f}$ corresponding to the functions on
  	the right of the equal sign in the equations above.
	\begin{equation}
  		\mathbf{f}(t, \mathbf{r})=\spvec{q;
  		i_{dc}
  		  		+ i_1 \cos(\Omega_{1}t) - \sin(\phi_k)
  		  		- q_1;
  		\frac{1}{l}\left[N \left( i_{dc}
  		  		+ i_1 \cos(\Omega_1 t) - q_1\right)
  		  		- \sum_{k=0}^{N-1} \sin(\phi_k)
  		  		\right]
  		  		-\frac{r}{l}q_1 - \Omega_0^2 q}
  	\end{equation}
  	Then set of differenetial equations can be written simply as:
  	\begin{equation}
  	\frac{\text{d}\mathbf{r}}{\text{d}t}=\mathbf{f}(t, \mathbf{r})
  	\end{equation}

 	\begin{comment}
  	We use forth order Runge-Kutta method to solve this equation. To than end we step over time with step $\Delta t$. And introduce time step supperscript to $\mathbf{r}$. Thus $\mathbf{r}^t$ and \mathbf{r}^{t+1}$ are values of $\mathbf{r}$ for two consequetive time steps.
  	\begin{eqnarray}
  	\mathbf{k}_1 &=& \mathbf{f}(t, \mathbf{r}^t) \\
  	\mathbf{\tilde{r}} &=& \mathbf{r}^t + \frac{\Delta t}{2}\mathbf{k}_1 \\
  	\mathbf{k}_2 &=& \mathbf{f} \left(t + \frac{\Delta t}{2}, \mathbf{\tilde{r}}\right) \\
  	\mathbf{\tilde{r}} &=& \mathbf{r}^t + \frac{\Delta t}{2}\mathbf{k}_2 \\
  	\mathbf{k}_3 &=& \mathbf{f} \left(t + \frac{\Delta t}{2}, \mathbf{\tilde{r}}\right) \\
  	\mathbf{\tilde{r}} &=& \mathbf{r}^t + \Delta t\mathbf{k}_3 \\
  	\mathbf{k}_4 &=& \mathbf{f} \left(t + \Delta t, \mathbf{\tilde{r}}\right)
  	\end{eqnarray}
  	\begin{equation}
  	\mathbf{r}^{t+1} = \mathbf{r}^t + \frac{\Delta t}{6}\left(\mathbf{k}_1 + 2 \mathbf{k}_2 + 2 \mathbf{k}_3 + \mathbf{k}_4\right)
  	\end{equation}
  	\newpage
    \end{comment}
  	\section{One Josephson Junction}
  	\begin{eqnarray}
  	\frac{\text{d}q}{\text{d}t} &=& q_1 \\
  	\frac{\text{d}\phi}{\text{d}t} &=& i_{dc}
  		+ i_1 \cos(\Omega_{1}t) - \sin(\phi)
  		- q_1 \\
  	\frac{\text{d}q_1}{\text{d}t} &=&
	\frac{i_{dc}}{l} +
	\frac{i_1}{l}\cos(\Omega_1 t)
	- \frac{1 + r}{l}q_1 - \frac{1}{l}\sin(\phi)
	- \Omega_0^2 q
  	\end{eqnarray}
  	Free parameters $i_{dc}, i_1, r, l, \Omega_0, \Omega_1$. And this is the equation we solve, to which end we use
  	three different methods: First Order Euler, Midpoint Method and Fourth Order Runge–Kutta and compare
	it with c++ code provided by Olesia Pozdniakova, which uses Fourth Order Runge–Kutta. Our program, written in
	C, is called \textbf{1jja\_c} and C++ program by Olesia is called \textbf{jja\_cpp\_time\_eval}.
	First we compare results produced by both programs.
	\begin{figure}[h]
	\includegraphics{figures/experiments_001_and_002.pdf}
	\caption{Here we are using \textbf{1jja\_c} to compute average voltage $\overline{v}$ across the junction while varying $i_{dc}$. Input parameters are $\Omega_{1}=0.4$,
	$i_1=0.3$,
	$\phi=0.0$, $\Omega_{0}=0.4$, $b=0.01$, $r=0.0$. Time step $\Delta t=0.001$. Averaging of voltage starts from $t=40$, which is more than sufficient to for the system to settle
	down. External period of driving system is determined by parameter $\Omega_1$ and is $T=2\pi/\Omega_1$. Thus original assumption was that we can perform averaging
	over just one such period. That turned out not to be the case. Number of periods used for voltage averaging is denoted as $N_{av}$. Red line shows voltage averaged
	over time $3T$, while black one over just one period $T$. You can see that for sufficiently large values of $i_{dc}$ there is a difference between these values
	of $\overline{v}$. Blue line shows that difference. First there is a long region for $i_{dc}$ from $0$ to about $0.8$ where both averaging techniques give the same
	$\overline{v}$. Oddly, however is the presence of two more regions where they match. These two regions are marked by light gray rectangles named $a$ and $b$.}
	\end{figure}

\begin{comment}
  	\subsection{First Order Euler}
  	\begin{eqnarray}
  	q^{t+\Delta t} &=& q^t + q_1 \Delta t \\
  	\phi^{t+\Delta t} &=& \phi^t + \Delta t
  	\left[
  	i_{dc} + i_1 \cos(\Omega_{1}t) - \sin(\phi)
  	- q^{t}_1
  	\right] \\
  	q^{t+\Delta t}_1 &=& q^t_1 + \Delta t
  	\left[
	\frac{i_{dc}}{l} +
	\frac{i_1}{l}\cos(\Omega_1 t)
	- \frac{1 + r}{l}q^t_1 - \frac{1}{l}\sin(\phi^t)
	- \Omega_0^2 q^t
  	\right]
  	\end{eqnarray}
\end{comment}
\end{document}


\section{Introduction}
Schroedinger's equation for two electrons in a three-dimensional harmonic osillator well

\section{Task 02a}
Mathematical intermezzo: A unitary transformation preserves the orthogonality of the obtained eigenvectors. We assume the basis is orthogonal:
$\mathbf{v_j^Tv_i} = \delta_{ij}$

Show that an orthogonal or unitary transformation $\mathbf{w_i} = \mathbf{Uv_i}$ preserves the dot product and orthogonality, where U is a matrix.

Say $\mathbf{w_j} = \mathbf{Uv_j}$\\
\\
$\mathbf{w_j^T} = \mathbf{Uv_j}^T = \mathbf{v_j^TU^T}$\\
\\
$\mathbf{w_j^Tw_i} = \mathbf{v_j}^T \mathbf{U^TUv_i} $\\
\\
$U^TU = I \implies \mathbf{w_j^Tw_i} = \mathbf{v_j^Tv_i} = \delta_{ij}$

\section{Task 02b}
Write a function which implements Jacobi's rotation algorithm to solve the tridiagonal matrix eigenvalue problem:

The function test\_rho\_max\_jacobi in the source code of project 2 plots the three lowest eigenvalues for n = 80, 160, 320, as shown in figure ~\ref{fig:Eigenvalue_states_n_80}, ~\ref{fig:Eigenvalue_states_n_160} and ~\ref{fig:Eigenvalue_states_n_320}. The wanted error of approximately four leading digits was obtained after increasing n to 320. I tried several values for $\rho_{max}$ and found that the normalized energy became very small for $\rho_{max}>5$. $\rho_{max} = 5$ was chosen because it gave the desired error for the eigenvalues as shown in figure ~\ref{fig:Eigenvalue_states_n_320}.

\FloatBarrier
\begin{figure}[!ht]
\centering
\FloatBarrier
\includegraphics[width=0.45\textwidth]{eigenvector_rho49n80.png}

\caption{Normalized energy for the three lowest eigenvalues for a system with no repulsive Coulomb interaction with n=80}
\label{fig:Eigenvalue_states_n_80}
\end{figure}
\FloatBarrier

\FloatBarrier
\begin{figure}[!ht]
\centering
\FloatBarrier
\includegraphics[width=0.45\textwidth]{eigenvector_rho49n160.png}

\caption{Normalized energy for the three lowest eigenvalues for a system with no repulsive Coulomb interaction with n=160}
\label{fig:Eigenvalue_states_n_160}
\end{figure}
\FloatBarrier

\FloatBarrier
\begin{figure}[!ht]
\centering
\FloatBarrier
\includegraphics[width=0.45\textwidth]{eigenvector_rho49n320.png}

\caption{Normalized energy for the three lowest eigenvalues for a system with no repulsive Coulomb interaction with n=320}
\label{fig:Eigenvalue_states_n_320}
\end{figure}
\FloatBarrier

The function jacobi\_method finds the eigenvalues and eigenvectors for a symmetric matrix A through rotational transformations.
If the non-diagonal matrix elements are exactly 0, the diagonal elements are the eigenvalues. How many similarity transformations are needed to reach the accepted error tolerance for a given n is shown with different scalings in figure ~\ref{fig:Similarity_transformations_threshold_logy} and ~\ref{fig:Similarity_transformations_threshold_loglog}. The reference plot of $3n^2-5n$ is the theoretical value given in the lecture notes on the Jacobi method (Ch. 7.4, 23.10.17).

\FloatBarrier
\begin{figure}[!ht]
\centering
\FloatBarrier
\includegraphics[width=0.45\textwidth]{num_iterations512n8logy.png}

\caption{Number of similarity transformations needed to reach the accepted error tolerance of $10^{-8}$ for the non-diagonal matrix elements, plotted with a logarithmic y-axis}
\label{fig:Similarity_transformations_threshold_logy}
\end{figure}
\FloatBarrier

\FloatBarrier
\begin{figure}[!ht]
\centering
\FloatBarrier
\includegraphics[width=0.45\textwidth]{num_iterations512n8loglog.png}

\caption{Number of similarity transformations needed to reach the accepted error tolerance of $10^{-8}$ for the non-diagonal matrix elements, plotted with a logarithmic x- and y-axis}
\label{fig:Similarity_transformations_threshold_loglog}
\end{figure}
\FloatBarrier

The convergence rate of the Jacobi method is poor. According to the lecture notes, one typically needs $3n^2-5n$. My calculations gave $1.7n^2-3.98n$, which is marginally better than the text book.

\section{Task 02c}
This section is about testing the code.

I set up three tests for the code, implemented with the program test\_project\_2.py given in my list of files to be found at my Github.

The tests are: \\
\begin{itemize}

\item test\_three\_first\_eigenvalues tests that the three first eigenvalues are correct within a tolerance of $10^{-4}$
\item test\_jacobi\_eigenvectors\_are\_orthogonal makes sure the eigenvectors are orthogonal
\item test\_jacobi\_solves\_eigen\_value\_eq makes sure the jacobi method solves the eigenvalue equation.

\end{itemize}

\section{Task 02d}
Schroedingers equation rewritten with a different potential to make it more general, allowing for a system with repulsive Coulomb interaction.\\

For figure ~\ref{fig:Eigenvalue_states_n_320_omega_100} the normalized energies are very similar compared to the non-interactive case from figure ~\ref{fig:Eigenvalue_states_n_320}. This is because the potential is very similar: Noninteractive case has potential $\rho^2$, whereas the interactive case has potential $\omega_r^2\rho^2+1/\rho$. For $\omega_r = 1$ the difference is only a term $1/\rho$, which is a small deviation for sufficiently large $\rho$. \\

The varying $\omega_r$ from figure ~\ref{fig:Eigenvalue_states_n_128_omega_1} to figure ~\ref{fig:Eigenvalue_states_n_320_omega_500} shows that the spikes of the energy increases with increasing $\omega_r$, which was expected since the potential is dependent on $\omega_r^2$. This means that the uncertainty for where the electrons are positioned is lower for larger $\omega_r$. At low values of $\omega_r$ the potential is spread over a wider range, giving the term $1/\rho$ more importance. To compensate for $\omega_r = 0.01$, I had to increase $\rho_{max}$ to 60  to fully capture the most probable position of the electrons. The theoretical approximate groundstate wavefunction is given right after equation 16a in the article by M.Taut 1993;  "Two electrons in an external oscillator potential", is plotted as reference with a dashed line.

\FloatBarrier
\begin{figure}[!ht]
\centering
\FloatBarrier
\includegraphics[width=0.45\textwidth]{eigenvector_rho595n128omega1}

\caption{Normalized energy for the three lowest eigenvalues for a system with repulsive Coulomb interaction with n=128 and $\omega_r$=0.01}
\label{fig:Eigenvalue_states_n_128_omega_1}
\end{figure}
\FloatBarrier

\FloatBarrier
\begin{figure}[!ht]
\centering
\FloatBarrier
\includegraphics[width=0.45\textwidth]{eigenvector_rho99n128omega50.png}

\caption{Normalized energy for the three lowest eigenvalues for repulsive Coulomb interaction with n=128 and $\omega_r$=0.5}
\label{fig:Eigenvalue_states_n_128_omega_50}
\end{figure}
\FloatBarrier

\FloatBarrier
\begin{figure}[!ht]
\centering
\FloatBarrier
\includegraphics[width=0.45\textwidth]{eigenvector_rho59n128omega100.png}

\caption{Normalized energy for the three lowest eigenvalues for repulsive Coulomb interaction with n=128 and $\omega_r$=1}
\label{fig:Eigenvalue_states_n_320_omega_100}
\end{figure}
\FloatBarrier

\FloatBarrier
\begin{figure}[!ht]
\centering
\FloatBarrier
\includegraphics[width=0.45\textwidth]{eigenvector_rho29n128omega500.png}

\caption{Normalized energy for the three lowest eigenvalues for repulsive Coulomb interaction with n=128 and $\omega_r$=5}
\label{fig:Eigenvalue_states_n_320_omega_500}
\end{figure}
\FloatBarrier

\subsection{Comments}
I realize that I probably should have plotted only the lowest ground state for the four last plots.


\subsection*{Introduction}

The problem consists of a dataset containing significant wave-heights recorded 14 times a month during several winter months in the north Atlantic. This is could for example be used to predict the probability of high waves in the north atlantic to warn oil platforms. One can estimate the extreme value of this dataset by assuming that the data has a \textit{Gumpel Distribution} with distribution function
\[ F(x; \mu, \beta)=\exp\left(-\exp\left(-\frac{x-\mu}{\beta}\right)\right), \quad x\in\mathbb{R}, \]
where $\mu\in\mathbb{R}$ and $\beta>0$. The paramaters of this distribution for an arbitrary dataset was estimated using the matlab function \texttt{est\_gumbel.m}. \\

During a 100 year interval, one can calculate a estimate of the likelihood of an 100--year return period event. It is a statistical measurement typically based on historic data denoting the average recurrence interval over an extended period of time. The analysis assumes that the probability does not vary in time and is independant of past events. \\

The expected 100-year return value of the data gives the largest expected wave-height during a 100-year period. The $T$:th return value is denoted by $F^{-1}(1-1/T;\mu,\beta)$. Since the data has been observed during 14 times a month and assuming we have three winter months during a year, $T$ is $T=3\cdot14\cdot100$. The investigated dataset is shown below in figure \ref{fig:waves}. \\

\begin{figure}[H]
\centering
	\includegraphics[scale=0.26]{./Figures/waves.png}
\caption{A figure, showing the data of the significant observed wave-heights}
\label{fig:waves}

\end{figure}

To perform a statistical test on the dataset, we use a parametric bootstrap approach. The bootstrap technique evaluates the uncertainty of an unknown distribution or data. The bootstrap replaces the unknown statistic by data-based approximations and analyzes the variation using MC simulation from the approximation. The approximations are done using a \textbf{empirical distribution} (ED) associated with the data and gives equal weights to each observed value. Below we will present a brief description of a general bootstrap method.

\begin{itemize}
\item{For a given statistic y, we replace $\mathbb{P}_0$ by $\hat{\mathbb{P}}_0$.}
\item{Approximation can be done by plugging $\hat{\mathbb{P}}_0$ into the quantity, i.e.
\[ \tau=\tau(\mathbb{P}_0)\approx \hat{\tau}=\tau(\hat{\mathbb{P}}_0) \].}
\item{Uncertainty of $t(y)$ is analyzed by looking at the variation of $\Delta(Y^*)=t(Y^*)-\hat{\tau}$ by drawing repeatedly $Y^*\sim \hat{\mathbb{P}_0}$.}
\end{itemize}

In our case, we have done a parametric bootstrap, where we assume that the data comes from a distribution $\mathbb{P}_0=\mathbb{P}_{\theta_0}\in\{\mathbb{P}_\theta;\theta \in \Theta\}$ belonging to some parametric family. Instead of using the ED, we find an estimate $\hat{\theta}=\hat{\theta}(y)$ of $\theta_0$ from the observations and
\begin{enumerate}
\item{generate new bootstrapped samples $Y_b^*,b\in \{1,2,\dots,B\}$, from $\hat{\mathbb{P}_0}=\mathbb{P}_{\hat{\theta}}$.}
\item{then we form bootstrap estimates $\hat{\theta}(Y_b^*)$ and errors $\Delta_b^*=\hat{\theta}(Y_b^*)-\hat{\theta},b\in\{1,2,\dots,B\}$}.
\end{enumerate}

For this assigment we approximated the data as being that of \textit{Gumpel distributed} data points. In the figure \ref{fig:waveshist} we have plotted the histogram of the atlantic wave-heights, indicating that the data has a a \textit{Gumpel} distribution.

\begin{figure}[H]
\centering
	\includegraphics[scale=0.26]{./Figures/waveshist.png}
\caption{A figure, showing the data of the significant observed wave-heightsdata, in \texttt{atlantic.mat}}
\label{fig:waveshist}

\end{figure}