\RequirePackage[l2tabu, orthodox]{nag}	% tells out-of-date packages
\documentclass[10pt, letterpaper]{scrartcl}

\usepackage{amssymb,amsfonts}
\usepackage{amsthm} % if using theorems and proofs
\usepackage[cmex10]{amsmath}
\usepackage[usenames,dvipsnames,svgnames]{xcolor} % use like \textcolor{red}{..} or {\color{red} ...}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}% can also add 'nohead', or leave blank

%\usepackage{url}

\usepackage{cancel} % for canceling terms

\usepackage{booktabs}

\usepackage{pdfpages} % for including pdfs

\usepackage{algpseudocode}  %algorithmicx
\usepackage{wrapfig}

%\usepackage{listings}
\usepackage[numbered,framed]{matlab-prettifier}
\lstdefinestyle{mat}{
    frame=single,
    language=matlab,
    showstringspaces=false,
    %  keywordstyle=\bfseries\color{blue},
    %  commentstyle=\color{green},
    %  stringstyle=\color{magenta},
}
\lstset{
    style              = Matlab-editor,
    basicstyle         = \mlttfamily,
    escapechar         = ",
    mlshowsectionrules = true,
}
%% use withL: \lstinputlisting{myODEfunction.m}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} % important!

\usepackage{hyperref}
\hypersetup{pdfauthor={Stephen Becker},
    pdftitle={},
    colorlinks=true,
    citecolor=MidnightBlue,
    urlcolor=Bittersweet,
}
% -- Input macros and such --
\IfFileExists{custom_headers.tex}{
\input{custom_headers}}{
\input{../custom_headers}}{
}
\let\oldenumerate\enumerate
\renewcommand{\enumerate}{
  \oldenumerate
  \setlength{\itemsep}{1em}
  \setlength{\parskip}{1em}
  \setlength{\parsep}{0pt}
}
\usepackage{enumitem}
%\setlist{noitemsep}
% See http://mirrors.fe.up.pt/pub/CTAN/macros/latex/contrib/enumitem/enumitem.pdf
% and now, set par indent to zero
\newlength{\savedparindent}
\setlength{\savedparindent}{\parindent}
\setlist[enumerate]{listparindent=\savedparindent}
%\setlength{\parindent}{0pt} % Jan 2017, HW 3/4, comment this out.

\usepackage{xspace}
%\newcommand{\collaboration}{\textbf{Collaboration Allowed}\xspace}
%\newcommand{\nocollaboration}{\textbf{No Collaboration}\xspace}

\renewcommand{\T}{\mathbb{T}}
\newcommand{\fn}{\widehat{f}_n} % Fourier coefficients
\newcommand{\spi}{\frac{1}{\sqrt{2\pi}}}
\renewcommand{\H}{\mathcal{H}}
\renewcommand{\phi}{\varphi}
\DeclareMathOperator{\ran}{ran} % ker already defined, and with lower case

\newcommand*\Laplace{\mathop{}\!\mathbin\bigtriangleup}
\renewcommand{\SS}{\mathcal{S}} % Schwartz space

% My solution environment
%%\newenvironment{solution}{\setlength{\parindent}{\savedparindent}{\bfseries Solution}:}{}
\makeatletter
\newcommand\solParagraph{\@startsection{paragraph}{4}{\z@}%
%    {-3.25ex \@plus -1ex \@minus -0.2ex}%
    {-.55ex \@plus -1ex \@minus -0.2ex}%
    {0.01pt}%
    {\raggedsection\normalfont\sectfont\nobreak\size@paragraph}%
}
\makeatother
\newenvironment{solution}{\setlength{\parindent}{\savedparindent}\solParagraph{Solution:}}{}

%\newenvironment{solution}{\emph{Solution}:}{}
\newenvironment{instructions}{}{}
\newenvironment{SolnComment}{}{}
\usepackage{comment}

%\def\solutions{1}  % define solutions  % !!! COMMENT or UNCOMMENT THIS LINE

% NOTE: \begin{solution} should have NO SPACES BEFORE OR AFTER IT,
% 	Can give very weird errors, hiding text, etc. See http://tex.stackexchange.com/a/91431/4603
\ifdefined\solutions
    \newcommand{\solTitle}[1]{#1}
    \excludecomment{instructions}
\else
   \excludecomment{solution}% uncomment this line to hide solution
   \newcommand{\solTitle}[1]{}
   \excludecomment{SolnComment}
\fi

\title{Homework 4 \solTitle{Selected Solutions} \\APPM 4720/5720 Spring 2019 \\ Randomized Algorithms}
%\author{Stephen Becker}
\date{}
\begin{document}
\maketitle
\vspace{-6em}
\textbf{Due date}: Friday, Feb 8 2019

Theme: Sketches   \hfill Instructor: Stephen Becker %Dr.\ Becker
%\vspace{1em}

\begin{instructions}
\paragraph{Instructions}
Collaboration with your fellow students is allowed and in fact recommended, although direct copying is not allowed.  Please write down the names of the students that you worked with. The internet is allowed for basic tasks only, not for directly looking for solutions.

An arbitrary subset of these questions will be graded.

%\paragraph{Reading}
%Read the rest of chapters 9--11 in [BV2004].
%%Read chapter 3.1, 3.2 and 3.3 in [BV2004].
%%Students are \textbf{strongly advised} to skim appendices A and C in [BV2004] to look for unfamiliar material (and read in more detail if there is unfamiliar material)
%
%%\vspace{1em}
%%\textbf{Special instructions this week}:
%
\end{instructions}

\begin{enumerate}[align=left, leftmargin=*, label=\bfseries Problem \arabic*:]

    \item \ [MATH] Let $A$ be a $m \times n$ matrix with $m\ge n$, and $\sigma_{\max} = \|A\|$ the maximum singular value of $A$, and $\sigma_{\min}$ the minimum singular value of $A$ (which may be zero).  Prove that for all vectors $x,y\in \R^n$ that
    \[
    \sigma_{\min} \| x-y\|_2 \le \|Ax-Ay\|_2 \le \sigma_{\max}\|x-y\|_2
    \]
    (and note that there exist $x,y$ such that these inequalities are tight, so they cannot be improved). Note: the upper bound is still true even if $m < n$.

    \item \ [PROGRAMMING] Using the $10 \times 10^9$ matrix $U$ that is stored in the file \\ \texttt{/rc\_scratch/stbe1590/data\_U.mat} on the research computing (rc) filesystem, compute its spectral norm $\|U\|$.
    The file was saved in the ``version 7.3'' Matlab file format, which uses \href{https://www.hdfgroup.org/}{HDF5}.  The file is about 72 GB, so I suggest \emph{not} transferring it to your computer.

    \textbf{Deliverable}: What is $\|U\|$? And how much time did your code spend reading the data from disk, and how much time did it take to actually do the computations?

    \emph{Hints}: on the rc login node, you must request a compute node. You should have access to the 2 special nodes on the Blanca cluster that the applied math department owns. To access these nodes, run \texttt{module load slurm/blanca} and then request an interactive session on one core of one of these nodes with the command \texttt{sinteractive -{}-account blanca-appm}.  Now you have command line access on a compute node.  If you want to run Matlab, it's simplest to do it without the GUI.  First run \texttt{module load matlab} and then run \texttt{matlab -nodisplay} to launch a terminal version of Matlab. You can edit script files, and then call them from the Matlab command lines.  If you use Python, you can use JupyterHub to run your Jupyter notebook so that the notebook runs in your web browser but the computation is done on the Blanca node; see \href{https://curc.readthedocs.io/en/latest/gateways/jupyterhub.html}{docs} and \href{https://jupyter.rc.colorado.edu/}{jupyter.rc.colorado.edu}.

    In Matlab, you can load just parts of the file by using the \texttt{matfile} command, rather than the \texttt{load} command. Please read the documentation of \texttt{matfile}.

    In Python, install the h5py package \url{https://www.h5py.org/} to be able to read the\ .mat file. The \texttt{scipy.io.loadmat} package will not work.

    There is a smaller file \texttt{/rc\_scratch/stbe1590/data\_U\_small.mat} which holds a  $10 \times 10^5$ matrix;  you might find this helpful for checking whether your code is correct.

\begin{solution}
TBD
     % Matlab prettifier package
     % see https://mirror.hmc.edu/ctan/macros/latex/contrib/matlab-prettifier/matlab-prettifier.pdf
\begin{lstlisting}
% Code TBD
\end{lstlisting}
\end{solution}

   \item \ [PROGRAMMING] \textbf{Are random projections that good?}  We often use random projections precisely because they are \emph{agnostic} to the data. What if we custom tailer a projection to the data?

Load the dataset \texttt{/rc\_scratch/stbe1590/MNIST\_subsampled.mat}, which is a sub-sampled version of the \href{https://en.wikipedia.org/wiki/MNIST_database}{MNIST} dataset. The file contains two variables, \texttt{X} which contains a $784 \times 3000$ matrix of the data, and \texttt{labels} which contains $3000$ labels. Each label is a digit 0--9, and each column of the data matrix is a $784$ length vector that represents a hand-drawn digit. You can reshape each column to be a $28 \times 28$ matrix if you'd like to graphically see what the look like.  This\ .mat file was not saved in ``version 7.3'' Matlab format, so it is easy to read in Python using \texttt{scipy.io.loadmat}.

Perform the following three types of dimensionality reduction methods:
\begin{enumerate}
    \item Write your own code to run PCA on the matrix, using either SVD or eigenvalue routines. Don't forget to center your variables first. Keep the top 2 or 3 principal components.
    \item Use a Gaussian matrix to project the data to 2 or 3 dimensions.
    \item Run the \href{https://en.wikipedia.org/wiki/T-distributed_stochastic_neighbor_embedding}{tSNE} algorithm on the data to reduce it to 2 dimensions. You can download Matlab and Python code that runs tSNE from \url{https://lvdmaaten.github.io/tsne/}; alternatively, it is implemented in the Python scikit-learn package in \texttt{sklearn.manifold.TSNE} in case you already have that installed.
\end{enumerate}

\textbf{Deliverables}:
For each dimensionality reduction method, plot your data in 2 or 3 dimensions. You should color code it according to the true labels (or adjust the marker shape, etc.).
Make some short concluding remarks about the effectiveness of each method (for your own benefit, you might want to make a 3D plot and then interact with it).

    \item \ [JUST FOR FUN] (Not required)
\textbf{The Waiting Time Paradox}. Buses arrive at a bus stop at random times according to a Poisson
process with intensity $\lambda$. I arrive at time $t$ and ask how much time $\E(W)$ on average I will
have to wait for the next bus. There are two contradictory arguments.
\begin{enumerate}
    \item ``The lack of the memory of the Poisson process implies that the distribution of my waiting
time should not depend on my arrival time. In this case $\E(W) = 1/\lambda$.''
\item ``The time of my arrival is chosen at random in the interval between two consecutive
buses, and for reasons of symmetry, my expected waiting time should be half the time the
expected time between two consecutive buses, that is $\E(W) = 1/(2\lambda)$.''
\end{enumerate}
Which answer is correct? Carefully explain why the other answer is incorrect. [exercise taken from \url{https://statweb.stanford.edu/~candes/acm116/Hw/hw4.pdf}; you can look on the internet \emph{after} attempting the problem, and there are many good explanations and simulations and comparison with real data ]

\end{enumerate}

\end{document}


% Modified based on Xiaoming Sun's template
\documentclass{article}
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{extramarks}
\usepackage{chngpage}
\usepackage{soul,color}
\usepackage{graphicx,float,wrapfig}

\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
}

\newcommand{\Class}{Mathematics for Computer Science}

% Homework Specific Information. Change it to your own
\newcommand{\Title}{Homework 6}

% In case you need to adjust margins:
\topmargin=-0.45in      %
\evensidemargin=0in     %
\oddsidemargin=0in      %
\textwidth=6.5in        %
\textheight=9.0in       %
\headsep=0.25in         %

% Setup the header and footer
\pagestyle{fancy}                                                       %
\chead{\Title}  %
\rhead{\firstxmark}                                                     %
\lfoot{\lastxmark}                                                      %
\cfoot{}                                                                %
\rfoot{Page\ \thepage\ of\ \protect\pageref{LastPage}}                          %
\renewcommand\headrulewidth{0.4pt}                                      %
\renewcommand\footrulewidth{0.4pt}                                      %

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Some tools
\newcommand{\enterProblemHeader}[1]{\nobreak\extramarks{#1}{#1 continued on next page\ldots}\nobreak%
                                    \nobreak\extramarks{#1 (continued)}{#1 continued on next page\ldots}\nobreak}%
\newcommand{\exitProblemHeader}[1]{\nobreak\extramarks{#1 (continued)}{#1 continued on next page\ldots}\nobreak%
                                   \nobreak\extramarks{#1}{}\nobreak}%

\newcommand{\homeworkProblemName}{}%
\newcounter{homeworkProblemCounter}%
\newenvironment{homeworkProblem}[1][Problem \arabic{homeworkProblemCounter}]%
  {\stepcounter{homeworkProblemCounter}%
   \renewcommand{\homeworkProblemName}{#1}%
   \section*{\homeworkProblemName}%
   \enterProblemHeader{\homeworkProblemName}}%
  {\exitProblemHeader{\homeworkProblemName}}%

\newcommand{\homeworkSectionName}{}%
\newlength{\homeworkSectionLabelLength}{}%
\newenvironment{homeworkSection}[1]%
  {% We put this space here to make sure we're not connected to the above.

   \renewcommand{\homeworkSectionName}{#1}%
   \settowidth{\homeworkSectionLabelLength}{\homeworkSectionName}%
   \addtolength{\homeworkSectionLabelLength}{0.25in}%
   \changetext{}{-\homeworkSectionLabelLength}{}{}{}%
   \subsection*{\homeworkSectionName}%
   \enterProblemHeader{\homeworkProblemName\ [\homeworkSectionName]}}%
  {\enterProblemHeader{\homeworkProblemName}%

   % We put the blank space above in order to make sure this margin
   % change doesn't happen too soon.
   \changetext{}{+\homeworkSectionLabelLength}{}{}{}}%

\newcommand{\Answer}{\ \\\textbf{Answer:} }
\newcommand{\Acknowledgement}[1]{\ \\{\bf Acknowledgement:} #1}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make title
\title{\textmd{\bf \Class: \Title}}
\date{April 8, 2019}
\author{Xingyu Su 2015010697}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{spacing}{1.1}
\maketitle \thispagestyle{empty}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin edit from here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}[Special Problem 1]
Show that for some fixed constants $c$, $c' > 0$, the randomized routing algorithm discussed in class has the following performance for Phase 2:

\begin{equation*}
Pr\{T>cn\}\leq 2^{-c'n}
\end{equation*}

\Answer

From \textbf{Homework 4: SP3a}, we have Chernoff bound as below:
\begin{equation*}
Pr\{X\geq\beta \mu\}\leq\left( \frac{e^{\beta-1}}{\beta^\beta}\right)^\mu
\end{equation*}

And in randomized routing algorithm, we have $E[T] \leq 2n$, so:
\begin{equation*}
Pr\{T>cn\} \leq \left( \frac{e^{c/2-1}}{(c/2)^{c/2}}\right)^{2n}
  =\left(\frac{c}{2e}\right)^{-cn}e^{-2n}
\end{equation*}

So if $c\geq4e$, there is a $c'$ satisfies $Pr\{T>cn\}\leq 2^{-c'n}$.

\end{homeworkProblem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}[Special Problem 2]
Solve each of the following recurrence relations:

(a) $a_0 = 1,\ a_1 = 2,\ a_n=4a_{n-1}-3a_{n-2}+3n+1$ for all $n\geq 2$.

(b) $a_0 = 1,\ a_n = \frac{a_{n-1}}{1+3a_{n-1}}$ for $n\geq 1$.

\Answer

(a) First, try to get the recursive equation into a simpler form that $b_n=4b_{n-1}-3b{n-2}$. It's easy to assume $b_{n} = a_{n} + bn^2 + cn + d$. So:
\begin{equation*}
(a_n+bn^2+c_n+d) = 4(a_{n-1}+b(n-1)^2+c(n-1)+d)-3(a_{n-2}+b(n-2)^2+c(n-2)+d)
\end{equation*}

Which get:
\begin{equation*}
a_n = 4a_{n-1}-3a_{n-2}+4bn-8b+2c
\end{equation*}

Compare the coefficients, we get:
\begin{align*}
4b &= 3      & b = \frac{3}{4}\\
-8b+2c &= 1  & c = \frac{7}{2}
\end{align*}

Assume $b_n = a_n + \frac{3}{4}n^2+\frac{7}{2}n$, and $b_0=a_0=1$, $b_1=a_1+\frac{3}{4}+\frac{7}{2}=\frac{25}{8}$. And there is $b_n = 4b_{n-1}-3b_{n-2}$. Let $b_n = z^n$, we get
\begin{equation*}
z^2 = 4z-3
\end{equation*}
The roots are: $z_1 = 1,\ z_2=3$, so $b_n = A+B3^n$. Getting with $b_0=1$, $b_1= \frac{25}{8}$, we have $A=-\frac{13}{8}$, $B=\frac{21}{8}$. So finnaly, we get $a_n$ as:
\begin{equation*}
a_n = \frac{21}{8}3^n-\frac{3}{4}n^2-\frac{7}{2}n-\frac{13}{8}
\end{equation*}

(b) Consider the characteristic equation:
\begin{equation*}
\lambda = \frac{\lambda}{1+3\lambda}
\end{equation*}
Get roots $\lambda_1=\lambda_2=0$. And we have $a_n$ is never zero for the reason that $a_0=1\neq 0$. So:
\begin{equation*}
\frac{1}{a_n} = \frac{1+3a_{n-1}}{a_{n-1}}=\frac{1}{a_{n-1}}+3
\end{equation*}
So obviously $\frac{1}{a_{n}}=3n+1$ so $a_n=\frac{1}{3n+1}$.

\end{homeworkProblem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}[Special Problem 3]
Consider a sequence of $2n$ people in a line at a cashier. Suppose $n$ of the people pay 1 yuan each and $n$ of the people get 1 yuan each. A \textit{paying pattern} is a binary sequence $\sigma = a_1 a_2 \cdots a_{2n}$ with exactly $n$ 1’s and $n$ 0’s; the interpretation is that $a_j = 1$ if person $j$ pays 1 yuan, and $a_j = 0$ otherwise. Note that there are exactly $\binom{2n}{n}$ paying patterns. Let $b_n$ denote the number of paying patterns in which the cashier never goes in debt (i.e., at every stage at least as many people have paid in 1 yuan as were paid out 1 yuan).

(a) Derive a recurrence equation for $b_n$ , and find an explicit expression for the generating function $\sum_{n\geq1}b_nx^n$. Determine a closed-form solution for $b_n$.

(b) Use an alternative way (a \textit{combinatorial proof}) to establish a closed form solution $b_n = \binom{2n}{n} - \binom{2n}{n+1}$. (\textbf{Hint:} Show a one-to-one correspondence between paying patterns where at some stage the cashier goes at least 1 yuan in debt and all binary sequences of length $2n$ with exactly $n + 1$ 1’s.)

\Answer

(a) Counting by hands, it's easily to get $b_1=1$, $b_2=2$, $b_3=5$.

Consider the sequence $\sigma=a_1 a_2 \cdots a_{2n}$ in which the cashier never goes in debt, then $a_1 = 1$ and since there are $n$ 1's and $n$ 0's, there must be a $1\leq j \leq 2n-1$ that $[a_{j},a_{j+1}] = [1,0]$.

Treat the money in and out as a \textbf{stack}. Then \textit{the first yuan} the cashier got can be paid out only at an even turn, denote as \textit{the first yuan} is the $l_{\text{th}}$ got paid out at $2l$ turn. Then there are still $l-1$ yuan paid before \textit{the first yuan} and $n-l$ yuan to be paid after \textit{the first yuan}. Thus, the sequence is divided into two unkown parts $a_2, \cdots, a_{2l-1}$ and $a_{2l+1}, a_{2l+2}, \cdots, a_{2n}$, and both of them satisfies the original rule.

So the recurrence is: (set $b_0 = 1$ for comprensively understanding)
\begin{equation*}
b_{n+1} = \sum_{i=0}^{n} b_i b_{n-i}
\end{equation*}

The generating function is:
\begin{align*}
f(x)
  &= \sum_{i\geq0} b_n x^n = b_0 + b_1x+b_2x^2+b3x^3+\cdots \\
f^2(x)
  &= \left(\sum_{i\geq0} b_n x^n\right) \left(\sum_{i\geq0} b_n x^n\right) \\
  &= b_0 b_0 + (b_0b_1+b_1b_0)x+(b_0b_2+b_1b_1+b_2b_0)x^2+\cdots \\
  &= \sum_{n\geq 1} b_n x^{n-1}
\end{align*}

So $f(x)-xf^2(x)=b_0=1$, get the roots:
\begin{equation*}
f(x) = \frac{1\pm \sqrt{1-4x}}{2x}
\end{equation*}

Known that
\begin{equation*}
\lim_{x\to0^+}f(x)= \lim_{x\to0^+}\frac{1\pm \sqrt{1-4x}}{2x} = b_0 = 1
\end{equation*}

We get $f(x) = \frac{1 - \sqrt{1-4x}}{2x}$, so $\sum_{n\geq 1} b_n x^n = f(x)-b_0 = \frac{1 - \sqrt{1-4x}}{2x} - 1$. With $(1+x)^\alpha=1+\sum_{n=1}^{\infty}\binom{n}{\alpha}x^n$, we have:
\begin{align*}
(1-4x)^{\frac{1}{2}}
  &= 1+\sum_{n=1}^{\infty}\binom{n}{1/2}(-4x)^n \\
  &= 1+\sum_{n=1}^{\infty}\frac{\frac{1}{2} \cdot (\frac{1}{2}-1)\cdots(\frac{3}{2}-n)}{n!}(-4x)^n \\
  &= 1-\sum_{n=1}^{\infty}\frac{1\cdot 3 \cdots (2n-3)}{n!}2^n x^n\\
  &= 1-\sum_{n=1}^{\infty}\frac{1\cdot 3 \cdots (2n-3)}{n!}\frac{2\cdot 4\cdots(2n-2)}{(n-1)!} 2 x^n \\
  &= 1-2\sum_{n=1}^{\infty}\frac{(2n-2)!}{n!(n-1)!}x^n
\end{align*}

So:
\begin{align*}
\frac{1 - \sqrt{1-4x}}{2x}
  &= \sum_{n=1}^{\infty}\frac{(2n-2)!}{n!(n-1)!}x^{n-1} \\
  &= \sum_{n=0}^{\infty}\frac{(2n)!}{(n+1)!n!}x^{n}
\end{align*}

Finally we get: $b_n=\frac{(2n)!}{(n+1)!n!}x^{n}$.

(b) Consider the sequence $\sigma=a_1 a_2 \cdots a_{2n}$ and call it wanted if $\sum_{i=1}^k (2a_i-1)\geq0$ for all $k=1,2,\cdots,2n$. Then for each unwanted sequence $\sigma$, there exists at least one $k$ that $\sum_{i=1}^k(2a_i-1) \geq 0$. So there must be a $k_0$ satisfies $\sum_{i=1}^{k_0}(2a_i-1)=-1$ and all $k=1,2,\cdots,k_0-1$ satisfies $\sum_{i=1}^k(2a_i-1)\geq 0$, especially $\sum_{i=1}^{k_0}(2a_i-1)=0$.

Obviously $k_0$ must be an odd number, denoting as $k_0=2m+1$. So there is $m$ 1's and $m$ 0's in $a_1 a_2 \cdots a_{2m}$ and $a_{2m+1}=0$. After reversing $a_1 a_2 \cdots a_{2m+1}$ of $\sigma$, we will get the sequence $\sigma'$ which has $n+1$ 1's and $n-1$ 0's.

On the other hand, given a sequence $\sigma'=a'_1 a'_2 \cdots a'_{2n}$ which consists of $n+1$ 1's and $n-1$ 0's. For the reason that the number of 1's is more than 0's, there must be a $k_0=2m+1$ that $\sum_{i=1}^{k_0}(2a_i-1)=-1$ and $\sum_{i=1}^k(2a_i-1) \geq 0$ for all $k=1,2,\cdots,2m$. Reversing $a'_1 a'_2 \cdots a'_{2m+1}$ of $\sigma'$, we will get a sequence $\sigma$ satisfies our rules with $n$ 1's and $n$ 0's.

Finally, we get a one-to-one correspondence between paying patterns unwanted and all binary sequences of length $2n$ with exactly $n+1$ 1's. So the number of unwanted patterns is $\binom{2n}{n+1}$. And there is $\binom{2n}{n}$ sequences in total. Thus, $b_n=\binom{2n}{n}-\binom{2n}{n+1}$.

\end{homeworkProblem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ACKNOWLEGEMENT
\Acknowledgement

Thanks to \href{https://en.wikipedia.org/wiki/Catalan_number}{Wikipedia: Catalan number} for SP3a.

Thanks to \href{https:\\botao.hu}{Botao Hu} for SP3b.

% End edit to here
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{spacing}
\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{bm}
\usepackage[fleqn]{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{listings}
\usepackage{fancyhdr}
\usepackage{graphicx}
\newtheorem{thm}{Theorem}
\pagestyle{fancy}
\usepackage{commath}

\usepackage{mathtools}

% \newcommand{\norm}[1]{\left\lVert#1\right\rVert}

\newcommand{\false}{\ensuremath{\mathbf{f}}\xspace}
\newcommand{\true}{\ensuremath{\mathbf{t}}\xspace}

\renewcommand{\theenumi}{\alph{enumi}}
\newcommand{\impl}{\mathbin{\Rightarrow}}
\newcommand{\biim}{\mathbin{\Leftrightarrow}}
\newcommand{\id}[1]{\mbox{\textit{#1}}}
\newcommand{\tuple}[1]{\langle #1 \rangle}
\newcommand{\ma}{\mathsf{a}}
\newcommand{\mb}{\mathsf{b}}
\newcommand{\mc}{\mathsf{c}}
\newcommand{\md}{\mathsf{d}}
\newcommand{\nat}{\mathbb{N}}
\newcommand{\intg}{\mathbb{Z}}

\newcommand{\set}[1]{\left\{
    \begin{array}{l}#1
    \end{array}
  \right\}}

\newcommand{\sset}[2]{\left\{~#1 \left|
      \begin{array}{l}#2\end{array}
    \right.     \right\}}

\topmargin -.5in
\textheight 9in
\oddsidemargin -.25in
\evensidemargin -.25in
\textwidth 7in

\begin{document}

\author{XuLin Yang, 904904}
\title{COMP30026 Models of Computation \\ Assignment 2}
\maketitle

\medskip

% Q1 -------------------------------------------------
\section*{Challenge 1}

Give context-free grammars for these languages:
\begin{enumerate}
% Q1 a --------------------
\item
The set $A$ of odd-length strings in $\{\ma,\mb\}^*$ whose first,
middle and last symbols are all the same.
For example, $\mb$ and $\ma \mb \ma \mb \ma$ are in $A$,
but $\epsilon$, $\ma \ma \ma \ma$, and $\ma \mb \mb \mb \mb$ are not.

context-free grammar $F$ is a 4-tuple $(V, \Sigma, R, S)$ where \\
$V \text{ is } \{ T,\ X,\ Y \}$ \\
$\Sigma \text{ is } \{ \ma,\ \mb \}$ \\
$R$ is
\[
\begin{array}{lrl}
   T & \rightarrow & \ma\ X\ \ma \mid \mb\ Y\ \mb \mid \ma \mid \mb \\
   X & \rightarrow & \ma\ X\ \mb \mid \mb\ X\ \ma \mid \mb\ X\ \mb \mid \ma\ X\ \ma \mid \ma \\
   Y & \rightarrow & \ma\ Y\ \mb \mid \mb\ Y\ \ma \mid \mb\ Y\ \mb \mid \ma\ Y\ \ma \mid \mb \\
\end{array}
\]
$S \text{ is } T $

% Q1 b --------------------
\item
The set $B = \{\ma^i \mb \ma^j \mid i \not= j\}$.
For example, $\ma \mb$ and $\ma \mb \ma \ma \ma$ are in $B$,
but $\epsilon$, $\ma$, $\mb$, and $\ma \ma \mb \ma \ma$ are not.

context-free grammar $G$ is a 4-tuple $(V, \Sigma, R, S)$ where \\
$V \text{ is } \{ T,\ X,\ Y,\ Z \}$ \\
$\Sigma \text{ is } \{ \ma,\ \mb \}$ \\
$R$ is
\[
\begin{array}{lrl}
   T & \rightarrow & X \mid \mb \mid \epsilon \\
   X & \rightarrow & \ma\ X\ \ma \mid Y \mid Z \\
   Y & \rightarrow & \ma\ Y \mid b  \\
   Z & \rightarrow & Z\ \ma \mid b \\
\end{array}
\]
$S \text{ is } T $

\end{enumerate}

% Q2 -------------------------------------------------
\section*{Challenge 2}
Consider the language
\[
  C = \set{w \in \{\texttt{a},\texttt{b}\}^* \mid
        \mbox{$w$ contains at least as many \texttt{a}s as \texttt{b}s}}
\]
For example, $\epsilon$, \verb!aaa!, \verb!aba!, and \verb!bbaababaa!
are all in $C$,
but \verb!bbb! and \verb!bbaaabb! are not.
\begin{enumerate}
% Q2 a --------------------
\item
Construct a 3-state push-down automaton to recognise $C$.
Provide the solution as a transition diagram.
Partial marks are given for a $C$ recogniser with more than 3 states.

\includegraphics[width=0.9\textwidth]{2a.png} \\

% Q2 b --------------------
\item
Prove formally that the following context-free grammar $G$ generates $C$:
\[
\begin{array}{lrl}
   S & \rightarrow
     & \epsilon
\\   & \mid
     & \texttt{a}
\\   & \mid
     & \texttt{a}\ S\ \texttt{b}
\\   & \mid
     & \texttt{b}\ S\ \texttt{a}
\\   & \mid
     & S\ S
\end{array}
\]
Hint: Proceed in two steps;
prove that every string in $L(G)$ is in $C$
(by structural induction)
and prove that every string in $C$ is in $L(G)$
(by induction on the length of the string).

\textbf{Given:}

context-free language $C$:
\[
  C = \set{w \in \{\texttt{a},\texttt{b}\}^* \mid
        \mbox{$w$ contains at least as many \texttt{a}s as \texttt{b}s}}
\]
and

context-free grammar $G$:
\[
\begin{array}{lrl}
   S & \rightarrow
     & \epsilon
\\   & \mid
     & \texttt{a}
\\   & \mid
     & \texttt{a}\ S\ \texttt{b}
\\   & \mid
     & \texttt{b}\ S\ \texttt{a}
\\   & \mid
     & S\ S
\end{array}
\]

\textbf{To be proved:} $G$ generates $C$

\textbf{Proof:}

\begin{enumerate}
    % step 1
    \item \textbf{Step 1}: prove that every string in $L(G)$ is in $C$ (by structural induction)

    \textbf{Let}  string $x \in L(G)$, string $S' \in L(G)$, string $S'' \in L(G)$. \\
    $A(string) = \text{number of } \texttt{a}s \text{ in the } string$ \\
    $B(string) = \text{number of } \texttt{b}s \text{ in the } string$

    \textbf{Assume:} every string in $L(G)$ is in $C$.

    \begin{enumerate}
        \item \textbf{base case:}

        \begin{enumerate}

            % base case 1
            \item \textbf{$1^{st}$ base case:} $x = \epsilon$

            As $\epsilon \in C$ by definition, so $x \in C$. \\
            $\therefore$ $1^{st}$ base case is in $C$.

            % base case 2
            \item \textbf{$2^{nd}$ base case:} $x = \texttt{a}$

            As $\texttt{a} \in C$ by definition, so $x \in C$. \\
            $\therefore$ $2^{nd}$ base case is in $C$.

        \end{enumerate}

        \item \textbf{inductive case:}

        \begin{enumerate}

            % inductive case 1
            \item \textbf{$1^{st}$ inductive case:} $x = \texttt{a} S' \texttt{b}$ where $S' \in L(G)$

            As $S' \in C$, $S'$ has at least as many \texttt{a}s as \texttt{b}s. \\
            So add one \texttt{a} at the start of $S'$ and one \texttt{b} at the end of $S'$ still makes $x$ has at least as many \texttt{a}s as \texttt{b}s. \\
            In other words, as $A(x) = 1 + A(S')$, $B(x) = 1 + B(S')$ and $A(S') \geq B(S')$, so $A(x) \geq B(x)$

            $\therefore$ $1^{st}$ inductive case is in $C$.

            % inductive case 2
            \item \textbf{$2^{nd}$ inductive case:} $x = \texttt{b} S' \texttt{a}$ where $S' \in L(G)$

            Symmetrically, as $S' \in C$, $S'$ has at least as many \texttt{a}s as \texttt{b}s. \\
            So add one \texttt{b} at the start of $S'$ and one \texttt{a} at the end of $S'$ still makes $x$ has at least as many \texttt{a}s as \texttt{b}s. \\
            In other words, as $A(x) = 1 + A(S')$, $B(x) = 1 + B(S')$ and $A(S') \geq B(S')$, so $A(x) \geq B(x)$

            $\therefore$ $2^{nd}$ inductive case is in $C$.

            % inductive case 3
            \item \textbf{$3^{rd}$ inductive case:} $x = S' S''$ where $S' \in L(G)$, $S'' \in L(G)$

            As $A(x) = A(S') + A(S'')$, $B(x) = B(S') + B(S'')$, $A(S') \geq B(S')$, $A(S'') \geq B(S'')$, so $A(x) \geq B(x)$

            $\therefore$ $3^{rd}$ inductive case is in $C$.

        \end{enumerate}
    \end{enumerate}

    \textbf{Hence}, in no case, string in $L(G)$ is not in $C$. \\
    \textbf{Therefore}, every string in $L(G)$ is in $C$. \\

    % step 2
    \item \textbf{Step 2}: prove that every string in $C$ is in $L(G)$ (by induction on the length of the string)

    \textbf{Let} string $w \in C$, $\abs{w}$ = length($w$). \\
    \textbf{Assume:} if $\abs{w} = n$ where $n \geq 0$, $w \in L(G)$.

    \begin{enumerate}
        % base case
        \item \textbf{base case:}

        \begin{enumerate}

            % base case 1
            \item \textbf{$1^{st}$ base case:} $n = 0$, $w = \epsilon$. \\
            As $\epsilon \in L(G)$ by definition, so $w \in L(G)$. \\
            $\therefore$ $1^{st}$ base case is in $L(G)$.

            % base case 2
            \item \textbf{$2^{nd}$ base case:} $n = 1$, $w = a$. \\
            As $a \in L(G)$ by definition, so $w \in L(G)$. \\
            $\therefore$ $2^{nd}$ base case is in $L(G)$.

        \end{enumerate}

    \end{enumerate}

    \begin{enumerate}
        % inductive case
        \item \textbf{inductive case:}

        \begin{enumerate}

            % inductive case 1
            \item \textbf{$1^{st}$ inductive case:} $\abs{w'} = n + 1$, $w' = aw$. \\
            As $a \in L(G)$ by definition and $w \in L(G)$ by assumption,  so $w' \in L(G)$ because $S = S'S'', S \in L(G) \text{ where } S' \in L(G) \text{ and } S'' \in L(G)$. \\
            $\therefore$ $1^{st}$ inductive case is in $L(G)$.

            % inductive case 2
            \item \textbf{$2^{nd}$ inductive case:} $\abs{w'} = n + 1$, $w' = wa$. \\
            Symmetrically, as $a \in L(G)$ by definition and $w \in L(G)$ by assumption,  so $w' \in L(G)$ because $S = S'S'', S \in L(G) \text{ where } S' \in L(G) \text{ and } S'' \in L(G)$. \\
            $\therefore$ $2^{nd}$ inductive case is in $L(G)$.

            % inductive case 3
            \item \textbf{$3^{rd}$ inductive case:} $\abs{w'} = n + 2$, $w' = awb$. \\
            As $w \in L(G)$ by assumption, $S' = aSb$ where $S' \in L(G) \text{ and } S \in L(G)$, so $w' \in L(G)$. \\
            $\therefore$ $3^{rd}$ inductive case is in $L(G)$.

            % inductive case 4
            \item \textbf{$4^{th}$ inductive case:} $\abs{w'} = n + 2$, $w' = bwa$. \\
            Symmetrically, as $w \in L(G)$ by assumption, $S' = bSa$ where $S' \in L(G) \text{ and } S \in L(G)$, so $w' \in L(G)$. \\
            $\therefore$ $4^{th}$ inductive case is in $L(G)$.
        \end{enumerate}

        \textbf{Hence}, in $\abs{w'} = n + 1$ , $\abs{w'} = n + 2$ cases and base cases, the assumption if $\abs{w} = n$ where $n \geq 0$, $w \in L(G)$ is true. \\
    \textbf{Therefore}, every string in $L(G)$ is in $C$. \\
    \end{enumerate}

\end{enumerate}

\textbf{Conclusion:} Since every string in $L(G)$ is in $C$ and every string in $C$ is in $L(G)$, we can say that context-free grammar $G$ generates $C$.

\end{enumerate}

% Q3 -------------------------------------------------
\section*{Challenge 3}
Consider the two language-transformer functions $\id{triple}$ and
$\id{snip}$ defined as follows:
\[
\begin{array}{lcl}
   \id{triple}(L) &=& \{w w w \mid w \in L\}
\\ \id{snip}(L) &=& \{ xz \mid x y z \in L \mbox{ and } |x| = |y| = |z|\}
\end{array}
\]
Note that $\id{snip}(L)$ discards a string $w$ from $L$ unless $w$
has length $3k$ for some $k \in \mathbb{N}$ (possibly 0), and then
the strings whose lengths are multiples of 3 have their middle
thirds removed.
For example, if
$L= \{\ma\mb,\mb\ma\mb,\mb\mb\mb,\mb\ma\mb\mb\ma,\ma\ma\mb\mb\ma\ma\}$
then $\id{snip}(L) = \{\mb\mb,\ma\ma\ma\ma\}$.
\begin{enumerate}
% Q3 a --------------------
\item
Let $R$ be a regular language.
Is $R^3 = R \circ R \circ R$ necessarily regular?
Justify your answer.

According to the theorem: The class of regular languages is closed under $\circ$. \\
As $R$ is regular, so does $R \circ R$, and so does $R \circ R \circ R$. \\
$\therefore R^3 = R \circ R \circ R$ is regular.

% Q3 b --------------------
\item
Let $R$ be a regular language.
Is $\id{triple}(R)$ necessarily regular?
Justify your answer.

\includegraphics[width=0.3\textwidth]{3b_1.png} \\

Let us have this dfa (deterministic finite state automaton) that recognize the regular language $R$ without considering the detail of this dfa.

\includegraphics[width=1\textwidth]{3b_2.png} \\

As we have the dfa defined above, design the nfa that recognize $triple(R)$ by concatenate three dfas such that first two dfas' accept states become normal states and have epsilon transitions to next dfa's start state, and the third dfa's accept states becomes as the accept states for the whole nfa. \\
By the Theorem: Every NFA has an equivalent DFA. \\
We can some how find the equivalent dfa for this nfa. \\
So we have a dfa that can recognize $tripple(R)$. \\
By the Theorem: A language is regular iff there is a finite automaton that recognises it. \\
$\therefore tripple(R)$ is regular.

% Q3 c --------------------
\item
Let $R$ be a regular language.
Show that $\id{snip}(R)$ is not necessarily regular.

\textbf{Assume:} $\id{snip}(R)$ is regular. \\
\textbf{Let:} $p$ be the pumping length.

% Consider string $wxyz \in R \text{ where } \abs{wx} = \abs{y} = \abs{z} = p,\ \abs{wxyz} = 3p$ and $\abs{x} \neq \epsilon$. \\
% By the bumping lemma, $wxz \in snip(R) \text{ where } wx^{i}x \in snip(R)\ \forall i \geq 0$. \\
% But $\abs{wxxz} \neq 2p$

Consider string $xyz \in R \text{ where } \abs{x} = \abs{y} = \abs{z} = p,\ \abs{xyz} = 3p$. \\
By the bumping lemma, $xz \in snip(R) \text{ where } \abs{xz} = 2p \text{ (imples the length is a multiple of 2 which is even) } \text{ and } xz = uvw \text{ where } uv^{i}w \in snip(R)\ \forall i \geq 0,\ v \neq \epsilon \text{ and } \abs{uv} \leq p$. \\
But when $\abs{v} = q$ where $q$ is odd, then $\abs{uvvw}$ is odd as $\abs{uvw} = \abs{xz}$ and $\abs{uvvw} = \abs{xz} + q = 2p + q$ is also odd and then $uvvw \notin snip(R)$ when $\abs{v}$ is odd, a contradiction.

\textbf{In conclusion:} $\id{snip}(R)$ is not necessarily regular.
\end{enumerate}

\end{document}
\grid
\grid


\documentclass{article}
\setlength{\oddsidemargin}{0.25 in}
\setlength{\evensidemargin}{-0.25 in}
\setlength{\topmargin}{-0.6 in}
\setlength{\textwidth}{6.5 in}
\setlength{\textheight}{8.5 in}
\setlength{\headsep}{0.75 in}
\setlength{\parindent}{0 in}
\setlength{\parskip}{0.1 in}

\usepackage{amsmath,amsfonts,graphicx}
\usepackage{tikz}
\usepackage{epsfig}
\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}
\usepackage{mathtools}
\usepackage{breqn}
%\usepackage{fourier}
\usepgfplotslibrary{statistics}
\newcounter{lecnum}
\renewcommand{\thepage}{\thelecnum-\arabic{page}}
\renewcommand{\thesection}{\thelecnum.\arabic{section}}
\renewcommand{\theequation}{\thelecnum.\arabic{equation}}
\renewcommand{\thefigure}{\thelecnum.\arabic{figure}}
\renewcommand{\thetable}{\thelecnum.\arabic{table}}

\newcommand{\lecture}[4]{
  \pagestyle{myheadings}
  \thispagestyle{plain}
  \setcounter{lecnum}{#1}
  \setcounter{page}{1}
  \noindent
  \begin{center}
    \framebox{
      \vbox{\vspace{2mm}
        \hbox to 6.28in { {\bf Analysis of Uncertainties
	    \hfill Fall 2014} }
        \vspace{4mm}
        \hbox to 6.28in { {\Large \hfill Lecture #1: #2  \hfill} }
        \vspace{2mm}
        \hbox to 6.28in { {\it Lecturer: #3 \hfill Notes by: #4} }
        \vspace{2mm}}
    }
  \end{center}
  \markboth{Lecture #1: #2}{Lecture #1: #2}
  \vspace*{4mm}
}

\renewcommand{\cite}[1]{[#1]}
\def\beginrefs{\begin{list}%
    {[\arabic{equation}]}{\usecounter{equation}
      \setlength{\leftmargin}{2.0truecm}\setlength{\labelsep}{0.4truecm}%
      \setlength{\labelwidth}{1.6truecm}}}
\def\endrefs{\end{list}}
\def\bibentry#1{\item[\hbox{[#1]}]}

\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newenvironment{proof}{{\bf Proof:}}{\hfill\rule{2mm}{2mm}}

\newcommand\E{\mathbb{E}}

\begin{document}
\lecture{1}{20 October 2014}{Prof. Kate Scholberg}{Douglas Davis}
\section{Introduction}
Think about the value for Newton's gravitational constant $G$; the current accepted value in literature is something around (call it $G_{\text{m1}}$, this doesn't have to be correct we're just making a point).
$$ G_{\text{m1}} = (6.674215\pm0.000092) \times 10^{11} \text{ m}^3\text{ kg}^{-1}\text{ s}^{-2}. $$
Now imagine we perform some experiments where we measure $G$. Imagine we measure a a new value, call it $G_{\text{m2}}$,
$$ G_{\text{m2}} = (6.674400\pm0.000010) \times 10^{11} \text{ m}^3\text{ kg}^{-1}\text{ s}^{-2}. $$
And we measure another value, $G_{\text{m3}}$,
$$ G_{\text{m3}} = (6.6741\pm0.0221) \times 10^{11} \text{ m}^3\text{ kg}^{-1}\text{ s}^{-2}. $$
If we look closely at the values and the uncertainties, we see that the value $G_{\text{m2}}$ is in disagreement with $G_{\text{m1}}$, because the values do not lie within the other value's uncertainty. This means some further investigation is needed! If we look at $G_{\text{m3}}$, we see that it is in agreement with both $G_{\text{m1}}$ and $G_{\text{m1}}$, but the uncertainty is so large that this measurement really did nothing for the advancement of science. This can be seen graphically in Figure~\ref{fig:G}.
\begin{figure}[h!]
  \centerline{
    \begin{tikzpicture}
      \draw [->] (0,0) -- (4,0);
      \draw [->] (0,0) -- (0,3);
      \node at (2,-.85) {Measurements};
      \node at (-.5,1.5) {$G$};
      \node at (1,-.35) {1};
      \node at (2,-.35) {2};
      \node at (3,-.35) {3};
      \draw [|-|,dashed,blue] (1,.9) -- (1,1.9);
      \draw [|-|,dashed,blue] (2,2.2)-- (2,2.6);
      \draw [<->,dashed,blue] (3,.1) -- (3,2.9);
      \draw [fill=red] (1,1.4) circle (2pt);
      \draw [fill=red] (2,2.4) circle (2pt);
      \draw [fill=red] (3,1.0) circle (2pt);
    \end{tikzpicture}
  }
  \caption{Three measurements for $G$, the values are red bullets, and the uncertainties are shown with blue dashed error bars}
  \label{fig:G}
\end{figure}
The point of this example is to show that uncertainties seriously matter. When interpreting results and planning new experiments, a scientist must always be thinking about uncertainties. Why build an experiment if the expected uncertainty in the measurement will yield nothing better than what is already known? Or, what does this new measurement mean that is it so much more constrained than the previous measurement? Is this method so great we should expand it elsewhere, and why is it so much better?

\section{Important Definitions}
Our first two important definitions are \emph{statistical} and \emph{systematic uncertainties}. A \emph{statistical uncertainty} is a random uncertainty that arises simply from random fluctuations in the data. As the sample size of the data approaches infinity ($N \rightarrow \infty$), the statistical uncertainty approaches 0. A \emph{systematic uncertainty} comes from a lack of knowledge about the experimental apparatus/measurement. An example would be the possibly of an inexact measurement from an imperfect ruler. Systematic uncertainties can also have some randomness, if an apparatus is affected by temperature change, the random fluctuations of temperature in the room cause systematic uncertainties because of the effect on the apparatus. To quote the systematic and statistical uncertainties, results are often written in the form:
\begin{align}
  x \pm \Delta x\,(\text{sys.}) \pm \Delta x\,(\text{stat.}),
\end{align}
with the two values separate. As the amount of data increases, the statistical uncertainty always decreases. The same cannot be said for systematic. In theory, studying systematic uncertainties more thoroughly may lead to a decrease, but it is possible that a better understanding of the systematics may cause an increase in the uncertainty.
\noindent Our next definition is a \emph{sample}. The \emph{sample} is the collection of measurements. If we want to measure some value $x$, then the sample is simply:
$$x_1,\,x_2,\,x_3,\,...\,,\,x_N,$$
where $x_i$ is just the $i$th measurement. An infinite number of measurements would yield the sample's \emph{parent distribution}, which we denote with $P(x)$. Figure~\ref{fig:sample,parent} shows an example of a histogrammed sample with it's parent distribution. As $N\rightarrow\infty$, the shape of the histogram would approach the shape of $P(x)$.

\begin{figure}[h!]
  \centerline{
    \input{tikz/histo.tex}
  }
  \caption{A sample distribution in histogram form overlayed by its parent distribution.}
  \label{fig:sample,parent}
\end{figure}

\noindent Now we will define some characteristics of the sample and the parent distribution. First, the \emph{mean of the sample}, which we denote with $\overline{x}$:
\begin{align}
  \overline{x} = \frac{1}{N}\sum_i^N x_i.
  \label{eq:sample_mean}
\end{align}
The \emph{mean of the parent distribution}, denoted by $\mu$:
\begin{align}
  \mu = \lim_{N\rightarrow\infty}\frac{1}{N}\sum_i^N x_i.
  \label{eq:parent_mean}
\end{align}
To quantify the spread we may first think to use the \emph{deviation}, denoted by $d$,
\begin{align}
  d_i = x_i - \mu,
  \label{eq:deviation}
\end{align}
and take the limit:
\begin{align}
  \lim_{N\rightarrow\infty} \frac{1}{N}\sum_i^N d_i = \lim_{N\rightarrow\infty} \frac{1}{N}\sum_i^N (x_i-\mu),
\end{align}
but because $d_i$ can be positive or negative, this limit tends to zero. We may also think to take the absolute value of the deviation, $|d_i|$, but this math turns out to be pretty bad. Instead we go with something called the \emph{variance}, which we denote with $\sigma^2$:
\begin{align}
  \sigma^2 = \lim_{N\rightarrow\infty}\frac{1}{N}\sum_i^N(x_i - \mu)^2.
  \label{eq:variance}
\end{align}
Which can also be written as:
\begin{align}
  \sigma^2 = \lim_{N\rightarrow\infty}\left[\frac{1}{N}\sum_i^N x_i^2\right] - \mu^2
  \label{eq:variance2}
\end{align}
In real world experiments, we probably do not know the parent mean, so we take $\mu\rightarrow \overline{x}$. Now we define the \emph{sample variance}, denoted by $s^2$:
\begin{align}
  s^2 = \frac{1}{N-1}\sum_i^N\left(x_i-\overline{x}\right)^2
  \label{eq:sample_variance}
\end{align}
Notice the difference between the fraction in equation~\ref{eq:variance} and equation~\ref{eq:sample_variance}, we change from $1/N$ to $1/(N+1)$. The reason for this can be worked out mathematically (ref), but we will just explain the following reason. Imagine taking only 1 measurement ($N=1$). Equation~\ref{eq:variance} would yield a variance of only 1. This does not make sense for a single measurement, the outcome using equation~\ref{eq:sample_variance} would be an undefined variance, which does make sense. There is no variance in a single measurement. The sample variance defined in equation~\ref{eq:sample_variance} is known as an \emph{unbiased estimator}. Closing side note: for practical purposes many scientists use the notation of $\sigma^2$ for the sample variance and $\mu$ for the sample mean.

\section{Propagation of uncertainties}
Let's suppose the value we are attempting to measure, $x$, is a function of $u$:
\begin{align}
  x = f(u) = u^2
  \label{eq:x_func}
\end{align}
We know that our measurement, $x$, will have some uncertainty (which we will denote as $\delta x$ or $\sigma_x$), and our independent variable must also have some uncertainty: $\delta u,\,\sigma_u$. We can (to first order, assuming $\delta x$ is small) write:
\begin{align}
  \delta x = f(u+\delta u) - f(u).
\end{align}
We can then write:
\begin{align}
  \frac{\delta x}{\delta u} = \frac{f(u+\delta u) - f(u)}{\delta u} = \frac{df}{du}\rightarrow \delta x = \left|\frac{df}{du}\right|\delta u,
\end{align}
or:
\begin{align}
  \sigma_x = \left|\frac{df}{du}\right|\sigma_u
\end{align}
Therefore, the measurement related to equation~\ref{eq:x_func} would be of the form:
\begin{align}
  \text{measured value} = x\pm|2u|\sigma_u
\end{align}
An example of this would be the area of a square with side length $u$, and an uncertainty in the ruler used to measure the side which is $\sigma_u$.

\noindent Now let's expand this to an arbitrary number of independent variables. Let's take $x$ in the form of $f$ again:
\begin{align}
  x = f(u,v,w,...),
\end{align}
it follows that:
\begin{align}
  \overline{x} = f(\overline{u},\overline{v},\overline{w},...) \hspace{1cm} x_i = f(u_i,v_i,w_i,...)
\end{align}
We can write:
\begin{dmath}
  x_i - \overline{x} \cong (u_i - \overline{u})\left(\frac{\partial x}{\partial u}\right)_{v,w,...} + (v_i - \overline{v})\left(\frac{\partial x}{\partial v}\right)_{u,w,...} + ...
  \label{eq:iminusbar}
\end{dmath}
Now recall equation~\ref{eq:variance}, we can write:
\begin{dmath}
  \sigma_x^2 = \lim_{N\rightarrow\infty}\frac{1}{N}\sum_i^N\biggl[(u_i - \overline{u})^2\left(\frac{\partial x}{\partial u}\right)^2 + (v_i -\overline{v})^2\left(\frac{\partial x}{\partial v}\right)^2 + ... + \underbrace{2(u_i - \overline{u})(v_i - \overline{v})\left(\frac{\partial x}{\partial u}\right)\left(\frac{\partial x}{\partial v}\right)+...}_{\text{cross terms from squaring eq.~\ref{eq:iminusbar}}}\biggr]
  \label{eq:bigguy}
\end{dmath}
Now using our standard variance equation with the form:
\begin{align}
  \sigma_u^2 = \lim_{N\rightarrow\infty}\frac{1}{N}\sum_i^N (u_i - \overline{u})^2,
\end{align}
and now introducing the covariance between $u$ and $v$:
\begin{align}
  \sigma_{uv}^2 = \lim_{N\rightarrow\infty}\frac{1}{N}\sum_i^N (u_i - \overline{u})(v_i - \overline{v}).
  \label{eq:covariance}
\end{align}
We can now rewrite equation~\ref{eq:bigguy} in the form:
\begin{align}
  \sigma_x^2 \cong \sigma_u^2\left(\frac{\partial x}{\partial u}\right) + \sigma_v^2\left(\frac{\partial x}{\partial v}\right) + ... + 2\sigma_{uv}^2\left(\frac{\partial x}{\partial u}\right)\left(\frac{\partial x}{\partial v}\right) + ...
\end{align}
If $u$ and $v$ are independent of eachother, in the large $N$ limit, $\sigma_{uv}^2 \rightarrow 0$ and all of the ``cross-terms'' vanish, yielding a variance of:
\begin{align}
  \sigma_x^2 \cong \sigma_u^2\left(\frac{\partial x}{\partial u}\right) + \sigma_v^2\left(\frac{\partial x}{\partial v}\right) + ...
\end{align}
\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Here is a citation, just for fun~\cite{CW87}.

\section*{References}
\beginrefs
\bibentry{CW87}{\sc D.~Coppersmith} and {\sc S.~Winograd},
``Matrix multiplication via arithmetic progressions,''
         {\it Proceedings of the 19th ACM Symposium on Theory of Computing},
         1987, pp.~1--6.
         \endrefs


\section{Introduction}

The idea of using trapped ions for quantum computing has been around for a long time~\cite{Shore1993,Meekhof1996} but one of the most promising turned out to be the architecture proposed by Molmer and Sorenson in 1999~\cite{MolmerSorenson} which then began to be achieved experimentally soon after~\cite{Wineland2000,Monroe2000}.

One of the problems turned out, however, to be heating during the operation of the gate~\cite{Berkeland1998,HAFFNER2008,Johnson2016}.  The ability of the gate to perform universal quantum computation depends on the system's vibrational quantum number staying reasonably constant.  Much work looked at possible mechanisms for observed heating including r.f. heating~\cite{Turchette2000} and micromotion.

The basic Hamiltonian is, as laid out by Molmer and Sorenson~\cite{MolmerSorenson}.
\begin{align*}
  \hat{H} &= \hat{H}_0 + \hat{H}_{\text{int}} \\
  \hat{H}_0 &= \hbar \nu \left(  \hat{a}^{\dagger} \hat{a}   + \frac{1}{2}\right)  + \frac{\hbar \omega_{eg}}{2} \sum_{i} \sigma_{zi} \\
  \hat{H}_{\text{int}} &= \sum_{i} \frac{\hbar \Omega_i}{2} \left( \sigma_{+i} e^{i \left[ \eta_i \left( \hat{a}^{\dagger} + \hat{a} \right) - \omega_i t \right]}  +  \sigma_{-i} e^{-i \left[ \eta_i \left( \hat{a}^{\dagger} + \hat{a} \right) - \omega_i t \right]} \right)
\end{align*}
To which we will focus on $\hat{H}_{\text{int}}$.  The form supplied in these equations makes the tacit assumption that the transition strength is constant with respect to the nuclear configuration of the system; the only nuclear component of the transition comes from the recoil operator($e^{-i  \eta_i \left( \hat{a}^{\dagger} + \hat{a} \right) }$) coming from the laser momentum projected onto the direction of the trap.  Put another way, the actual Rabi frequency $\Omega_i$ approximately does not change with vibrational state.  Condon first articulated this approximation~\cite{Condon} for molecular spectra in 1928 but recent scholarship has shown lots of ways this approximation can lead to incorrect interpretation of experiments involving electronic transitions~\cite{MavrosNonCondon,hellerGraphene,photosyntheticKappa}. In particular, because (if one thinks of things in the position basis) a transition dipole variation such as this will deform the wavefunction upon application, this does imply that the system is heated upon laser excitation if this is indeed the case.  Since Heating is a constant problem for the operation of any quantum computer, we take it upon ourselves to investigate the effect a variation in transition dipole will have on a Molmer-Sorenson type System.

Mathematically, this means we are taking $\Omega_i$ and adding a position dependence which can then be decomposed into creation and annihilation operators
\begin{align}
	\Omega_i &\rightarrow \Omega_i \mu(x) \\
	\mu(x) &= \mu_0 \sum_{i=0} \kappa^{(i)} x^i \\
	&= \mu_0 \sum_{i=0} c^{(i)} \left( \hat{a} + \hat{a}^{\dagger}\right)^i
\end{align}
We assume that $c^{(1)}=0$ and all odd numbered corrections because the excited vibrational manifold is no different than the excited vibrational manifold so only symmetric orders in $x$ should physically be present.  Furthermore, and linear dependence would directly effect the calculated Rabi Frequency $\tilde{\Omega}$ but we are looking for an insipid effect to explain heating, not a major effect that should have been noticed by now.

We then explore a rather drastic shift and set $c^{(2)} = .1$ and explore the effect it would have on the dynamics of the system.  To wit, we recreate Figure 2 in ~\cite{MolmerSorenson} with this system in our Figure \ref{fig:c2_big_dynamics}.  This is a very large effect which would doubtless make a system completely unusable.

\begin{figure}
   \includegraphics[width=1.0\columnwidth]{MS_fig2_noAct.png}
   \caption{This is a reproduction of Figure 2 from the original paper by Molmer and Sorenson where they proposed using a gate which operates like this to perform quantum computations.  Any needed state is accessible by turning off the excitation lasers at a given time during operation.}
	\label{fig:MS_big_dynamics}
\end{figure}

\begin{figure}
   \includegraphics[width=1.0\columnwidth]{MS_fig2_c2.png}
   \caption{This is what Figure 2 from the original paper by Molmer and Sorenson would have looked like with a large quadratic term in the transition dipole $\mu(x)$.  Note that the nice unitary dynamics are almost completely gone.  This is not due, however, to heating but tot he}
	\label{fig:c2_big_dynamics}
\end{figure}

We next look at the Fidelity~\cite{Bowdrey2002} of the state compared to the ideal, unitary dynamics for multiple values of $c^{(2)}$ from $10^{-5}\rightarrow 1$ and plot the result in Figure \ref{fig:c2_fidelity deviation}.  As would be expected, small corrections don't induce much of a problem at all, but larger correction have the potential to affect the fidelity a great deal.
\begin{figure}
   \includegraphics[width=1.0\columnwidth]{MS_fidelityDeviation_cComparison.png}
   \caption{ This show on a log scale the deviation from the ideal unitary dynamics for various values of  $c^{(2)}$.  Notably, the larger the value of  $c^{(2)}$, the greater the deviation.  The effect is still not very big.}
	\label{fig:c2_fidelity deviation}
\end{figure}

Another way of looking at this would be the average quantum number of the gate during operation and we plot that for the same values of  $c^{(2)}$ in Figure \ref{fig:MS_heating_cComparison}.  The laser beam appears to impart some heat at the beginning based on the value of $c^{(2)}$ but the value is not much.  What is increasing is the variation in the expected quantum number.  If we calculate, instead, the standard deviation of the vibrational quantum number, there is a clear trend up as $c^{(2)}$ goes up as seen in Figure \ref{fig:MS_heating_stdev}

\begin{figure}
   \includegraphics[width=1.0\columnwidth]{MS_heating_cComparison.png}
   \caption{ This show on a log scale the expected value of the vibrational quantum number during gate operation, for various values of  $c^{(2)}$.  Once again, the larger the value of  $c^{(2)}$, the greater the amount of heating but oddly, compared to such effects in ultrafast systems, the system very quickly reaches the higher level of heat, and then very slowly declines as the laser continues operation.  This effect is also not terribly large}
	\label{fig:MS_heating_cComparison}
\end{figure}

\begin{figure}
   \includegraphics[width=1.0\columnwidth]{stdev_heating.png}
   \caption{ This show on a linear scale the standard deviation of the vibrational quantum number during gate operation, for various values of  $c^{(2)}$.  There is a very clear increasing relationship between this variation and  $c^{(2)}$.  This increases uncertainty in the state of the gate when the laser is turned off. }
	\label{fig:MS_heating_stdev}
\end{figure}

\section{Typical values for $c^{(i)}$}
If we take Yb+, and do a back of the envelope calculation.  The

\section{Conclusion}
We have shown the effect that a term quadratic in the nuclear position on the transition operator, can do to the fidelity of a Molmer-Sorenson gate.  Values of this term are, however, likely not large enough to be of any concern to experimentalists as they are very small.  As trap frequencies get higher and traps begin to include more and more atoms, this effect could potentially cascade and cause problems for future implementations of trapped-ion quantum computers.

\section{Supplemental Material}

\subsection{Rabi Frequency}

We want to see how this will nuclear dependence of the transition dipole will affect the calculated Rabi Frequency (to second order).  The formula in the original paper is

\begin{align*}
	\left(  \frac{\tilde{\Omega}}{2} \right)^2 &= \frac{1}{\hbar^2} \left|  \sum_m  \frac{\bra{een}H_{\text{int}}  \ket{m}\bra{m} H_{\text{int}} \ket{ggn} }{E_{ggn} + \hbar \omega_i - E_m} \right|^2
\end{align*}
Our $H_{\text{int}}$ for this derivation will assume $\eta = \eta_i = \eta_2$ and $\Omega = \Omega_1 = \Omega_2$ and has the added vibrational transition dipole moment $f(z)$
\begin{align*}
	\hat{H}_{\text{int}} &= \frac{\hbar \Omega}{2} \sum_{i}  \left( f(z) \sigma_{+i} e^{i \left[ \eta\left( \hat{a}^{\dagger} + \hat{a} \right) - \omega_i t \right]}  + f^*(z) \sigma_{-i} e^{-i \left[ \eta \left( \hat{a}^{\dagger} + \hat{a} \right) - \omega_i t \right]} \right)
\end{align*}
now we act this on the appropriate states:

\begin{align*}
	\hat{H}_{\text{int}} \ket{ggn} &= \frac{\hbar \Omega}{2}f(z) e^{i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) } \left(  \ket{egn}e^{- i\omega_1 t } + \ket{gen}e^{- i\omega_2 t }   \right) \\
	\hat{H}_{\text{int}} \ket{een} &= \frac{\hbar \Omega}{2}f^*(z) e^{-i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) } \left(  \ket{egn}e^{ i\omega_2 t } + \ket{gen}e^{i\omega_1 t }   \right)
\end{align*}
if we do as the paper does and restrict $m$ to be $\ket{egn+1}, \ket{gen-1}$

\begin{align*}
	\bra{gen - 1}\hat{H}_{\text{int}} \ket{ggn} &= \frac{\hbar \Omega}{2}\bra{gen - 1}f(z) e^{i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) } \left(  \ket{egn}e^{- i\omega_1 t } + \ket{gen}e^{- i\omega_2 t }   \right) \\
	&= \frac{\hbar \Omega}{2}  \bra{n-1} f(z) e^{i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) } \ket{n}e^{- i\omega_2 t }   \\
	\bra{egn + 1}\hat{H}_{\text{int}} \ket{ggn} &= \frac{\hbar \Omega}{2}\bra{egn + 1}f(z) e^{i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) } \left(  \ket{egn}e^{- i\omega_1 t } + \ket{gen}e^{- i\omega_2 t }   \right) \\
	&= \frac{\hbar \Omega}{2}\bra{n + 1}f(z) e^{i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) } \ket{n}e^{- i\omega_1 t }
\end{align*}
then the de-excitations from the doubly excited state
\begin{align*}
	\bra{gen - 1}\hat{H}_{\text{int}} \ket{een} &= \frac{\hbar \Omega}{2}\bra{gen - 1} f^*(z) e^{-i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) } \left(  \ket{egn}e^{ i\omega_2 t } + \ket{gen}e^{i\omega_1t }   \right)\\
	&= \frac{\hbar \Omega}{2}\bra{n - 1} f^*(z) e^{-i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) } \ket{n}e^{i\omega_1 t }   \\
	\bra{egn + 1}\hat{H}_{\text{int}} \ket{een} &= \frac{\hbar \Omega}{2}\bra{egn + 1} f^*(z) e^{-i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) } \left(  \ket{egn}e^{ i\omega_2 t } + \ket{gen}e^{i\omega_1 t }   \right)\\
	&= \frac{\hbar \Omega}{2}\bra{n + 1} f^*(z) e^{-i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) }  \ket{n}e^{ i\omega_2 t }
\end{align*}

Now is the time to think.  Our vibrational correction to the electronic transition moment, should only have even corrections to it.  And Molmer and Sorenson only expanded the laser recoil operator out to first order, meaning a typical matrix element from above will look like:
\begin{align*}
	\bra{n + 1} f^*(z) e^{-i \eta\left( \hat{a}^{\dagger} + \hat{a} \right) }  \ket{n} &\approx -i \eta \bra{n + 1} f^*(z) \left( \hat{a}^{\dagger} + \hat{a} \right)  \ket{n}
\end{align*}
and since $f$ will look like this:
\begin{align*}
	 f(z) &= 1 + c^{(2)}\left( \hat{a}^{\dagger} + \hat{a}  \right)^2 \\
	 &= 1 + c^{(2)}\left( \hat{a}^{\dagger}\hat{a}^{\dagger} + \hat{a}\hat{a}^{\dagger} + \hat{a}^{\dagger}\hat{a} + \hat{a}\hat{a}  \right)
\end{align*}
quick math aside:
\begin{align*}
	 [\hat{a}, \hat{a}^{\dagger}] &= 1\\
	 \hat{a} \hat{a}^{\dagger} - \hat{a}^{\dagger}\hat{a} &= 1\\
	 \hat{a} \hat{a}^{\dagger} - \hat{N} &= 1\\
	 \hat{a} \hat{a}^{\dagger}  &= 1 + \hat{N}
\end{align*}
\begin{align*}
	 f(z) &= 1 + c^{(2)}\left( \hat{a}^{\dagger}\hat{a}^{\dagger} + \left(  1 + \hat{N} \right) + \hat{N} + \hat{a}\hat{a}  \right) \\
	 &= 1 + c^{(2)}  + 2 c^{(2)} \hat{N} +  c^{(2)}\left( \hat{a}^{\dagger}\hat{a}^{\dagger} + \hat{a}\hat{a}  \right)
\end{align*}
So this indicates that we must be very careful when adding an $f(z)$ term as we're trying to imply an effect that hasn't been seen before, so we ought to renormalize and keep the Rabi Frequency the same as what we saw before we knew there was a polynomial transition dipole.
\begin{align*}
	 f(z) &= 1 - c^{(2)} (1 + 2 \bar{n}_0 ) + c^{(2)}\left( \hat{a}^{\dagger} + \hat{a}  \right)^2
\end{align*}

\subsection{Proper Unitary Dynamics}
According to Molmer and Sorenson's original paper, when you input both detunings to both ions, you get the following dynamics which are essentially a quantum process matrix... after a little bit of algebra
\begin{align*}
	\ket{gg} &\rightarrow \cos \left(\frac{\tilde{\Omega} T}{2} \right) \ket{gg} + i  \sin \left(\frac{\tilde{\Omega} T}{2} \right)\ket{ee}\\
	\ket{ee} &\rightarrow \cos \left(\frac{\tilde{\Omega} T}{2} \right) \ket{ee} + i  \sin \left(\frac{\tilde{\Omega} T}{2} \right) \ket{gg}\\
	\ket{ge} &\rightarrow \cos \left(\frac{\tilde{\Omega} T}{2} \right) \ket{ge} - i  \sin \left(\frac{\tilde{\Omega} T}{2} \right) \ket{eg}\\
	\ket{eg} &\rightarrow \cos \left(\frac{\tilde{\Omega} T}{2} \right) \ket{eg} - i  \sin \left(\frac{\tilde{\Omega} T}{2} \right) \ket{ge}
\end{align*}
If we want to know what the density matrix elements are, this requires some more work:
being a bit more mathematically precise we get:
\begin{align*}
	U(T)\ket{gg} &= \cos \left(\frac{\tilde{\Omega} T}{2} \right) \ket{gg} + i  \sin \left(\frac{\tilde{\Omega} T}{2} \right)\ket{ee}\\
	U(T)\ket{ee} &= \cos \left(\frac{\tilde{\Omega} T}{2} \right) \ket{ee} + i  \sin \left(\frac{\tilde{\Omega} T}{2} \right) \ket{gg}\\
	U(T)\ket{ge} &= \cos \left(\frac{\tilde{\Omega} T}{2} \right) \ket{ge} - i  \sin \left(\frac{\tilde{\Omega} T}{2} \right) \ket{eg}\\
	U(T)\ket{eg} &= \cos \left(\frac{\tilde{\Omega} T}{2} \right) \ket{eg} - i  \sin \left(\frac{\tilde{\Omega} T}{2} \right) \ket{ge}
\end{align*}
which will give us the elements of $U(T)$,
\begin{align*}
	\bra{gg}U(T)\ket{gg} &= \cos \left(\frac{\tilde{\Omega} T}{2} \right) \\
	\bra{ee}U(T)\ket{gg} &=  i  \sin \left(\frac{\tilde{\Omega} T}{2} \right)\\
	\bra{ee}U(T)\ket{ee} &= \cos \left(\frac{\tilde{\Omega} T}{2} \right) \\
	\bra{gg}U(T)\ket{ee} &=  i  \sin \left(\frac{\tilde{\Omega} T}{2} \right) \\
	\bra{ge}U(T)\ket{ge} &= \cos \left(\frac{\tilde{\Omega} T}{2} \right) \\
	\bra{eg}U(T)\ket{ge} &= - i  \sin \left(\frac{\tilde{\Omega} T}{2} \right)\\
	\bra{eg}U(T)\ket{eg} &= \cos \left(\frac{\tilde{\Omega} T}{2} \right) \\
	\bra{ge}U(T)\ket{eg} &=  - i  \sin \left(\frac{\tilde{\Omega} T}{2} \right)
\end{align*}
so there are all the nonzero elements of the time-evolution operator.
\begin{align*}
	U(T) &= \begin{bmatrix}
		\cos \left(\frac{\tilde{\Omega} T}{2} \right) & 0 & 0 & i\sin \left(\frac{\tilde{\Omega} T}{2} \right) \\
		0 & \cos \left(\frac{\tilde{\Omega} T}{2} \right) & -i\sin \left(\frac{\tilde{\Omega} T}{2} \right) & 0\\
		0 & -i\sin \left(\frac{\tilde{\Omega} T}{2} \right)  & \cos \left(\frac{\tilde{\Omega} T}{2} \right) & 0\\
		i\sin \left(\frac{\tilde{\Omega} T}{2} \right)  & 0 & 0 & \cos \left(\frac{\tilde{\Omega} T}{2} \right) \\
	\end{bmatrix}
\end{align*}
You can see from above that $U^{\dagger}U = I$ as we would expect
And we can use this operator to calculate the time-dependent density matrix through:
\begin{align*}
	\rho(T) &= \ket{\Psi(T)}\bra{\Psi(T)} \\
	&= U(T) \ket{\Psi(0)}\bra{\Psi(0)} U^{\dagger}(T)\\
	&= U(T) \rho(0) U^{\dagger}(T)
\end{align*}


\chapter{Introduction}

Nearly eight years after the appearance of the World Wide Web, it is still a difficult medium to use for the transmission
of mathematics and scientific material in spite of its success in other areas. Sending mathematics via e-mail or reading
mathematics into a software package from a web page is not a simple task, depriving the scientific community from a
powerful communications tool which is the Internet. Likewise, displaying mathematics on the Internet in a way that allows
editing and reuse has until now been impossible.

As the Internet continues to grow it is becoming ever more important to facilitate the exchange of mathematics amongst
users and computer algebra software packages, offering automatic processing of expressions, searching, editing and reuse.

To overcome these difficulties, various companies and societies have joined together to produce standards for representing mathematics whilst
preserving mathematical meaning. The World Wide Web Consortium\index{World Wide Web Consortium}~\cite{w3c} and the OpenMath\index{OpenMath
Society} society~\cite{openmath} have developed the two leading standards currently receiving most attention. These are MathML\index{MathML}
\cite{mathml} and OpenMath\index{OpenMath} \cite{openmathspec} respectively.

The chief purpose of OpenMath\index{OpenMath} is to facilitate consistent communication of mathematics between
mathematical applications. MathML\index{MathML} however, concentrates on displaying mathematics on the web whilst
maintaining its meaning. Both standards are complementary and used together can provide the opportunity to expand our
ability to represent, encode and successfully communicate mathematical ideas with one another across the Internet.

The primary aim of this project is to understand the differences and similarities between OpenMath\index{OpenMath} and
MathML\index{MathML}, to assess their exchangeability and develop a way of mapping one standard to the other. The main
objective will be to ultimately design and implement an interface running on REDUCE\index{REDUCE} which will translate
OpenMath\index{OpenMath} into MathML\index{MathML} and vice versa. This interface will provide REDUCE\index{REDUCE} with
the capability of exchanging mathematics with other applications as well as displaying output on the World Wide Web and
reading from it, allowing REDUCE to join the MathML/OpenMath trend.

\chapter{Literature Review}

The notation of mathematics has constantly evolved with the appearance of new concepts and ideas. Modern mathematical
notation is the result of centuries of refinement. As a result of this, the sophisticated symbols with which we write
mathematics pose certain problems when bringing them onto printed paper. Publishing mathematics is a difficult task simply
because mathematics do not lend themselves easily to publication.

Recently, the advances in Internet publishing, following the Internet expansion, have added a new dimension to
mathematical publishing. New problems as well as new requirements must be dealt with. We want the Internet not only to be
a medium for displaying mathematics around the world, but also a communications tool for transmitting them.

How can we ensure that mathematics published on a web page are reusable? Editable? The outputs of one application should
be displayed on the Internet in a way humans can understand and other applications can reuse. But because there is a
distinction between presenting mathematical objects, and transmitting their content, merging both into one notation to
achieve this duality is a non-trivial task.

In order to fully understand the motivations of this project, as well as appreciating its outcome, it is important to
carefully illustrate any related issues. We will look into the development of mathematical publishing and how it has
evolved with the growth of the Internet. This will permit us to better understand the need for mathematical representation
standards such as MathML\index{MathML} and OpenMath\index{OpenMath} which we shall introduce. Finally we will talk about
the relation between these standards, the existing software supporting them, and their future.

With such an overview of the current situation, the necessity of a MathML\index{MathML} to OpenMath\index{OpenMath}
interface for REDUCE\index{REDUCE} will become clear.

\section{Mathematical Publishing}

Before the foundation of the World Wide Web, encoding of mathematical documents was already a widespread practice. Back in
the days when computers were starting to become popular, the ASCII\index{ASCII} character set (and encodings based on it)
was the only widely available encoding scheme. The restrictions of such a limited symbol set were soon apparent.

In the mid seventies, Donald Knuth developed \TeX\index{\TeX}, from which variants such as \LaTeX\index{\LaTeX} stemmed. Layout and
typesetting of mathematics is extremely demanding and until now, Donald Knuth's \TeX\index{\TeX} had been able to address
these difficulties in a successful way, appealing to the scientific community who has now made it a standard in scientific
publishing. \TeX\index{\TeX} has become the tool of choice for producing scientific and mathematical documents.

Despite its widespread use and ease with which it is authored, \TeX\index{\TeX} does not preserve mathematical semantic
value, making it unpractical for use in web documents and useless for transmission between applications. \TeX\index{\TeX}
is only concerned with describing the presentation of mathematics, not the content. Because people are interested in
transmitting their ideas and research via e-mail or web pages it is fundamental that semantic value is kept.

While \TeX\index{\TeX} is mainly a UNIX based application, PC applications dealing with mathematical encoding have also emerged. Generally these
are equipped with a graphical user interface making them easier to use: Design Science\index{Design Science}'s MS Word Equation Editor,
FrameMaker\index{FrameMaker}, WordPerfect\index{WordPerfect} or ScientificWord\index{ScientificWord} are a few to name examples. All these
applications\footnote{It is worth noting that PC applications have not had the same success as \TeX\index{\TeX}.} just deal with displaying
mathematics and ignore semantic value. They are usually vendor specific making them unpractical for use in mathematical web publishing.

\section{Mathematics and the Internet Challenge}

\subsection{Html and Mathematics}

In the early 1990's, The World Wide Web Consortium\index{World Wide Web Consortium}'s Html \index{Html} became the
standard markup language for publishing on the World Wide Web. It has since evolved and has become an extensible and very
powerful means of representing interactive Internet documents. In terms of representing mathematics however, Html has
little support.

In the first versions of Html\index{Html} , no support for mathematics was included. It was not until 1993 that the first
intent of embedding mathematics within Internet documents was attempted in the Html+\index{Html!Html+} draft \cite{htmlp}
presented by the World Wide Web Consortium\index{World Wide Web Consortium}. Equations were represented directly as
Html+\index{Html!Html+} using an SGML\index{SGML} \cite{sgml} based notation, inspired by \LaTeX's\index{\LaTeX} approach.

In 1994, the World Wide Web Consortium\index{World Wide Web Consortium} went further in mathematics Internet publishing by
presenting the Html 3.0\index{Html!Html 3.0} draft \cite{html3} (which later was officially published as the Html
3.2\index{Html!Html 3.2} \cite{html3.2} specification with a few modifications) which offered a more comprehensive support.
They claimed {\it ``Html math is powerful enough to describe the range of math expressions you can create in common word
processing packages, as well as being suitable for rendering to speech.''}

Nonetheless, both drafts failed because of lack of interest from popular browser vendors. But even though the mathematical
ideas in the Html 3.2\index{Html!Html 3.2} specification were never fully deployed, people started thinking more carefully
about mathematics, and how they could be represented on the WWW.

In the meantime, while the World Wide Web Consortium\index{World Wide Web Consortium} and other societies continued
working on developing mathematical support for Internet documents, other solutions to transmitting mathematics on the web
arose. The lack of a standard approach to uniformly represent mathematics on the Internet pushed mathematicians and
scientists to use a variety of different techniques to achieve this purpose. Let us give a brief overview of the main
ones.

\subsection{Embedded Graphics}

One way of displaying mathematics on the web is by the use of embedded graphics inside Html documents. Mathematical
equations are represented by graphical images (e.g. gifs) which all browsers display without difficulties. Formulae can be
viewed in their original rendering, without the browser requiring additional fonts or external viewing programs.

Nevertheless, these images display low resolutions and printing them results in poor quality documents. There are also
problems with alignment and sizing. Because graphical images are generally slow to download, documents might take more
time than desired to be rendered. Since we are only dealing with images, the equations are not editable. No modifications
can be done on them. For the same reasons, they are not reusable, because semantic value is completely lost.

This method is widespread but not very appreciated. In the Html 3.0\index{Html!Html 3.0} draft, the World Wide Web
Consortium\index{World Wide Web Consortium} specifically states its intention of helping users avoid the use of inline
images to display equations.

This is the approach used by programs such as \LaTeX\index{\LaTeX}2Html \cite{latex2html} or \TeX\index{\TeX}4ht
\cite{tex4ht} which can convert \LaTeX\index{\LaTeX} and \TeX\index{\TeX} documents to Html\index{Html} format for direct insertion into the
Internet. \LaTeX\index{\LaTeX} markup is translated into Html while mathematical equations are converted into graphical
images. It is worth noting however, that there exist programs such as TtM\index{TtM} \cite{TtM} which translate the
mathematical sections directly into MathML\index{MathML} presentation markup \index{MathML!presentation markup}.

\subsection{Graphical Page Display}

Another way of approaching the problem is by using graphical page displays. The page is rendered into a page-description
language such as postscript\index{postscript} or PDF\index{PDF}. Internet browsers, aided by an external viewer or plug-in
can then display the page in its integrity, including any mathematical formulae within it. When using this method,
documents are displayed with exactly the same layout as the original documents, which could be \TeX\index{\TeX} documents
for instance. The printing resolution is also maintained at a high quality level.

But using an external viewer or plug-in involves everyone possessing a copy. A viewer also requires a verbose and large
file format including all the non-standard fonts used. Just in the same way as the embedded graphics display, any
mathematics contained within these documents looses its semantic value, as well as the possibility to edit it or modify
it.

\section{OpenMath\index{OpenMath} and MathML\index{MathML}}

These interim solutions have only contributed to the problem by putting in evidence the need of a consistent standardized methodology for the
transmission of mathematics via the World Wide Web. In view of the failure of existing methods MathML and OpenMath's\footnote{Describing these
standards in detail is not in the scope of this report. We do encourage the reader to have a careful read through both standard specifications
\cite{openmath}\cite{mathml} in order to better understand this report and its implications.} significance and importance increased. Both standards
are complementary yet serving different purposes.

The primary aim of OpenMath\index{OpenMath} is to facilitate reliable communication of mathematical objects between mathematical applications. It
ensures semantic content is preserved within the notation. The semantic scope of OpenMath\index{OpenMath} is defined within its content
dictionaries\index{content dictionaries} (CD) where all symbols used are described defining their semantic value. Related symbols and functions are
grouped into CD groups. It is expected that applications using OpenMath\index{OpenMath} declare which CD groups they understand.

MathML\index{MathML} however is World Wide Web oriented in that it seeks to display mathematics on web pages.
MathML\index{MathML} has two combinable versions, one encoding mathematical objects (presentation
markup\index{MathML!presentation markup}) and the other encoding mathematical meaning (content markup\index{content
markup}). Both versions allow authors to encode both the notation which represents a mathematical object and the
mathematical structure of the object itself. Moreover, authors can mix both kinds of encoding in order to specify both the
presentation and content of a mathematical idea.

In fact there are strong links between both recommendations. The communities developing both standards are closely
related, with some members belonging to both groups. This has resulted in both standards superceding each other in some
areas.

The {\it core} OpenMath\index{OpenMath} CD group is the principal CD group. The {\it core} CD group was designed based on
MathML\index{MathML!MathML 1.0} 1.0, extending the set of symbols covered by MathML\index{MathML!MathML 1.0} 1.0. Its
intention is not to be very specific, only covering everyday and K-12 (kindergarden to high school level) mathematics just
as MathML\index{MathML} does.

For completeness, a MathML\index{MathML} CD group was introduced in the OpenMath\index{OpenMath} standard. It is a subset
of the {\it core} CD group and has the same semantic scope as do the content elements of MathML\index{MathML}. It is
expected that most applications will understand the {\it core} CD group, automatically understanding the
MathML\index{MathML} CD group.

The recently published MathML\index{MathML!MathML 2.0} 2.0 version has incorporated elements of the {\it core}
OpenMath\index{OpenMath} CD group which weren't before in MathML\index{MathML!MathML 1.0} 1.0. But in order to keep the
scope of content markup\index{content markup} down to a reasonable size, the designers of MathML\index{MathML} have
restricted the mathematics that it attempts to cover to high school level mathematics limiting MathML\index{MathML}'s
ability to convey mathematical meaning. Because OpenMath\index{OpenMath} is more powerful in this respect, the designers
of MathML\index{MathML} have introduced means allowing for extensibility. It is possible to encode semantic information
inside MathML by embeding OpenMath\index{OpenMath} objects within MathML\index{MathML} code.

This demonstrates the close ties existing between both the World Wide Web Consortium\index{World Wide Web Consortium} and
the OpenMath\index{OpenMath Society} society. In the MathML\index{MathML!MathML 2.0} 2.0 specification one can read: {\it
``The MathML\index{MathML} content elements are heavily indebted to the OpenMath\index{OpenMath} project \ldots''}

\section{Current Support}

Both standards have received considerable attention, and have mobilized many developers. Support for MathML\footnote{For a comprehensive list of software supporting MathML look at the W3C web site~\cite{w3c}}
\index{MathML}
and OpenMath\index{OpenMath} is being introduced in many areas now that a future seems to profile itself.

The dominance of Java\index{Java} on the Internet today has made it a good candidate for offering a solution to the
problem of publishing mathematics. The flexibility and power of Java\index{Java} applets can be used in conjunction with
MathML or OpenMath to display mathematical formulae.

This approach is currently best represented by WebEQ\index{WebEQ} \cite{webeq}. WebEQ\index{WebEQ} is a collection of programs and Java\index{Java}
programming libraries dealing with all aspects of putting math on the Web.  Because WebEQ\index{WebEQ} is based on MathML\index{MathML},
WebEQ\index{WebEQ} tools can easily be combined with each other and with other MathML\index{MathML} software to accomplish a wide range of tasks.
The applet takes a representation of an equation as input, and displays it. The representation has to be some markup language which the applet
supports (MathML\index{MathML} or Web\TeX\index{WebTeX}). Another Java\index{Java} application is ICEBrowser \cite{ice}. A browser component
written in Java\index{Java} which renders MathML\index{MathML}.

By using a Java\index{Java} applet we encounter the same difficulties as when using embedded graphics. In addition to
this, Java\index{Java} applets have a larger initial download overhead, which can be disturbing to some users.
Java\index{Java} applets usually offer good equation displays, but different vendors supply different solutions and markup
languages.

Another set of applications currently offering MathML support are plug-ins. The main distinction in principle between
using plug-ins or Java\index{Java} applets is that plug-ins need to be pre-installed on the Internet browser for any
rendering to take place. IBM\index{IBM} Techexplorer\index{TechExplorer} \cite{ibm} is a representative example under
development. It currently supports MathML\index{MathML} encodings. IBM\index{IBM}'s approach to the problem is definetely
bordering the solution the scientific community is hoping to see. Techexplorer can display MathML\index{MathML} and the
quality of display is acceptable. Hopefully, IBM\index{IBM}'s techexplorer initiative will push other browser vendors and
companies to adopt MathML\index{MathML} as the leading standard.

But as with the other temporary solutions, plug-ins also have their limitations.
Plug-ins have trouble getting the current HTML document font size, changing the size of the window to fit the display, or getting the current HTML document background color. Plug-ins such as IBM\index{IBM}'s are not
yet widespread, and most people are not familiar with plug-in download and installation.

In the area of computer algebra, soon many computer algebra packages should have interfaces to both standards. An example
of this is the MathML\index{MathML} to REDUCE\index{REDUCE} interface available in REDUCE\index{REDUCE} 3.7, or the MathML
interface built in Mathematica Version 4.

Various programs convert \LaTeX~documents into MathML. This is important because of the large amount of documents written
in LaTeX\index{\LaTeX} until now. An example of a program accomplishing this task is TtM\index{TtM} \cite{TtM} for
instance.

Various equation editors such as MathType or Design Science\index{Design Science}'s MS equation editor also support
MathML\index{MathML}. They manipulate expressions and offer easy to use graphical user interfaces. It is possible to
export equations to MathML format.

Until now however, both Explorer\index{Explorer} and Netscape\index{Netscape} have not yet incorporated support for
MathML\index{MathML}, although they have committed themselves in doing so in the near future. Because these are the most
popular browsers, it is important that they soon provide MathML\index{MathML} facilities in order to boost the use of
MathML\index{MathML}.

\newpage

\section{The future}

\begin{quotation}

\emph{``While many in the mathematical and scientific community have already adopted \LaTeX~as the standard for writing
papers, it appears that MathML\index{MathML} is the future of scientific and mathematical notation on the Web.''} Bob
Henshaw, UNC.

\end{quotation}

Regardless of how efficient MathML \index{MathML}and OpenMath are in transmitting and displaying mathematics, it is clear
that they will only be of any use if all communities adopt it. It is expected however that most popular software companies
working on the Internet or on computer algebra packages will soon support MathML and OpenMath. It seems as if MathML and
OpenMath will recieve the necessary support due to the commitment that various big companies have already shown
(IBM\index{IBM}, Netscape\index{Netscape}, Microsoft\index{Microsoft}, Wolfram\index{Wolfram}, Design Science\index{Design
Science}, and many others).

At the moment some browsers have already implemented MathML\index{MathML} rendering facilities (Amaya\index{Amaya} for
instance), and soon other bigger browser vendors will join the trend. Mozilla has recently released its latest browser
which does render MathML. Netscape should follow soon with Navigator5\index{Netscape!Navigator 5}. MathType from Design
Science\index{Design Science} has released a new version incorporating various tools for dealing with MathML and OpenMath.
For those not familiar with Design Science\index{Design Science}, they also make MS Word's equation editor. Other
companies (mainly Stilo) are developing equation editors with MathML and OpenMath facilities which will soon hit the
market.

While substantial progress has been made, there are still areas in which more work is required before MathML can be
incorporated easily into the Internet. Further improvement in coordination between browsers and embedded elements will be
necessary. Furthermore, higher printing resolution must be achieved.

MathML and OpenMath are the first XML\index{XML} based markup language to appear on the Internet. They will show the power and limitations of XML.
An example has been set for other specialist areas which also want to benefit from the Internet.; areas such as Chemical Engineering or Music are
using XML to develop representation standards. Both standards have been recieved enthousiastically and it will surely not take long before they are
used widely by the scientific community.


\title{CS 301, Course Project - Report} % You may change the title if you want.
% \subtitle{Hello}
\author{Abhishek Raj (180010002), Harsh Raj (180010017), Rishit Saiya (180010027)}

\date{\today}

\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{enumitem}
\usepackage{amsmath,mathtools}
\usepackage{amssymb}
\usepackage[super]{nth}
\usepackage{textcomp}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
}
\begin{document}
\maketitle

%---------------------------------------------------------------------

\section{Abstract}
The report touches upon an \href{https://en.wikipedia.org/wiki/ARM_architecture}{ARM} project where we are given an array of unpacked BCD numbers are stored starting from memory location U\_BCD. We have converted the unpacked BCD numbers to packed BCD numbers and stored the array starting from memory location P\_BCD.

We have also explained upon some the problem statements explaining in detail about parameters like Number of Static \& Dynamic Instructions, Instruction Counts under various constraints, Code Coverage, Execution Time, etc. It also explains in details of our previous versions/ideas and the breakpoints where we chose a different idea to enhance and achieve the results. \\

\textbf{Note about Codes:} \\
    \textbf{\textit{main.s}} contains the main ARM code (This code is written without conditional execution). \textbf{\textit{main\_thumb.s}} contains the code using THUMB instructions.
%---------------------------------------------------------------------

\section{Simulator \& Software Dependencies}

ARM Assembly Language Programming is used to code in the \textbf{.asm} file.
We are using \href{https://www.nxp.com/docs/en/data-sheet/LPC1769_68_67_66_65_64_63.pdf}{NXP’s ARM Cortex M3 – LPC1768} for simulation of our program. All the statistics mentioned in this report are in state-of-art to the software packs for LPC1768 updates to this date.
We have performed simulation using \href{https://www.keil.com}{Keil SDE} which provides a wide range of ARM Cortex-M based microcontroller devices.
%---------------------------------------------------------------------

\section{Q.1 - Static \& Dynamic Instructions}
The basic definitions of Static \& Dynamic Instructions are as follows: \\

\textbf{\textit{Static Instruction:}} The number of instructions of the program will constitute number of Static Instructions. \\
The number of Static Instructions of our code is \textbf{\textit{20}}.

\textbf{\textit{Dynamic Instruction:}} The actual number of instructions executed by the CPU for a specific program execution will constitute as number of Dynamic Instructions. \\

The generalised expression for number of Dynamic Instructions is as follows: \\
\begin{equation*}
    Dynamic \, Instructions = \frac{5n^{2} + 29n}{2} + 9
\end{equation*}
where n is the number of unpacked BCD numbers in an array

%---------------------------------------------------------------------

\section{Q.2 - Instruction Counts under various Constraints}
\begin{enumerate}[label=(\alph*)]
    \item The number of Instruction Counts when code without conditional execution was involved is \textbf{\textit{20}}.
    \item By usage of Conditional Execution in our code, we observed that there was no change in number of instructions than previous but there were instances where it could increase. So we avoid that.
    \item We observed that when code written with THUMB instructions was implemented, the code execution time dropped which is a sign of an efficient implementation. Upon seeing the reason, we came to know that it happens so due to reduced number of instructions along with less variation in values of flags.
    The number of instructions in this case was \textbf{\textit{17}}. \\

    Figure 1 further approves towards the fact that with Thumb Instruction, the code execution took \textbf{3.833 µs} whereas without Thumb Instructions, the code execution took \textbf{5.250 µs}.
    \begin{center}
    \begin{figure}
        \centering
        \includegraphics[width=15cm, height=8cm]{Course Project/Thumb.png}
        \caption{Screenshot of code using THUMB instructions showing its execution time is less}
    \end{figure}
\end{center}

\end{enumerate}

%---------------------------------------------------------------------

\section{Q.3 - Code Coverage, Code Execution Time, No. of Calls Executed}
\begin{enumerate}[label=(\alph*)]
    \item The code coverage and its contents were migrated into a file \textbf{mainlog} whose contents are as follows:
    \begin{verbatim}
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\Reset_Handler -
100% (2 of 2 instructions executed)
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\NMI_Handler -
0% (0 of 1 instructions executed)
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\HardFault_Handler -
0% (0 of 1 instructions executed)
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\MemManage_Handler -
0% (0 of 1 instructions executed)
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\BusFault_Handler -
0% (0 of 1 instructions executed)
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\UsageFault_Handler -
0% (0 of 1 instructions executed)
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\SVC_Handler -
0% (0 of 1 instructions executed)
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\DebugMon_Handler -
0% (0 of 1 instructions executed)
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\PendSV_Handler -
0% (0 of 1 instructions executed)
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\SysTick_Handler -
0% (0 of 1 instructions executed)
\\project\RTE/Device/LPC1768/startup_LPC17xx.s\Default_Handler -
0% (0 of 1 instructions executed)
\\project\main.s\__asm_0x100 - 100% (20 of 20 instructions executed)

Event Recorder log file: <none>
       command log file: mainlog
        serial log file: <none>
       Itm/Rta log file: <none>
LOG >>  mainlog
*** error 63: logfile already active

    \end{verbatim}
Code Coverage References - \href{https://www.keil.com/support/man/docs/uv4cl/uv4cl_cm_coverage.htm}{Code Coverage}, \href{https://www.keil.com/support/man/docs/uv4cl/uv4cl_cm_log.htm}{Logs}

    \item The Code Execution time and related details were taken from the \textbf{mainlog} file and they are as follows:
    \begin{verbatim}
    Time spent in code without debug info - Time:  217.500 µs (97%)
    Functions sorted by execution time consumption:
  '__asm_0x100' - Time:    5.250 µs (2%), Calls: 1
  'Reset_Handler' - Time:    0.417 µs (0%), Calls: 1
  'BusFault_Handler' - Time: 0 µs (0%), Calls: 0
  'SVC_Handler' - Time: 0 µs (0%), Calls: 0
  'PendSV_Handler' - Time: 0 µs (0%), Calls: 0
  'Default_Handler' - Time: 0 µs (0%), Calls: 0
  'SysTick_Handler' - Time: 0 µs (0%), Calls: 0
  'DebugMon_Handler' - Time: 0 µs (0%), Calls: 0
  'UsageFault_Handler' - Time: 0 µs (0%), Calls: 0
  'MemManage_Handler' - Time: 0 µs (0%), Calls: 0
  'HardFault_Handler' - Time: 0 µs (0%), Calls: 0
  'NMI_Handler' - Time: 0 µs (0%), Calls: 0

    Execution times by Modules and Functions:
    App: 'project', Time:    5.667 µs (3%)
    Module: 'RTE/Device/LPC1768/startup_LPC17xx.s', Time:    0.417 µs (0%)
  Function: 'Reset_Handler', Time:    0.417 µs (0%), Calls: 1
  Function: 'NMI_Handler', Time: 0 µs (0%), Calls: 0
  Function: 'HardFault_Handler', Time: 0 µs (0%), Calls: 0
  Function: 'MemManage_Handler', Time: 0 µs (0%), Calls: 0
  Function: 'BusFault_Handler', Time: 0 µs (0%), Calls: 0
  Function: 'UsageFault_Handler', Time: 0 µs (0%), Calls: 0
  Function: 'SVC_Handler', Time: 0 µs (0%), Calls: 0
  Function: 'DebugMon_Handler', Time: 0 µs (0%), Calls: 0
  Function: 'PendSV_Handler', Time: 0 µs (0%), Calls: 0
  Function: 'SysTick_Handler', Time: 0 µs (0%), Calls: 0
  Function: 'Default_Handler', Time: 0 µs (0%), Calls: 0
 Module: 'RTE/Device/LPC1768/startup_LPC17xx.s', Time: 0 µs (0%)
 Module: 'main.s', Time:    5.250 µs (2%)
  Function: '__asm_0x100', Time:    5.250 µs (2%), Calls: 1
    \end{verbatim}
Code Execution Time References - \href{https://www.keil.com/support/docs/971.htm}{µVision Debugger}, \href{https://www.keil.com/support/man/docs/uv4/uv4_db_dbg_execprofiler.htm}{Execution Profiler}

    \item  The number of calls for our code \textbf{\textit{main.s}} is \textbf{\textit{1}}. The information regarding the same is given in above snippet.

\end{enumerate}

%---------------------------------------------------------------------

\end{document}