\documentclass[10pt, leqno]{amsart}
\usepackage{amsthm, amsmath, amssymb}
\usepackage{mathrsfs,  mathtools}
\usepackage{dsfont, bbding, moresize}
\usepackage{setspace}
\usepackage{bm} %% Addes the \bm command for bolding certain math symbols
\usepackage[margin = 1.0in]{geometry}
% \usepackage[table]{xcolor}
% \usepackage{hyperref}

\onehalfspacing

\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows, calc, intersections}

\input{header}

%%=====================
%% Theorem Environments
%%=====================
\theoremstyle{plain}      \newtheorem{thm}{Theorem}%[section]
% \numberwithin{thm}{section}
\theoremstyle{plain}      \newtheorem*{thm*}{Theorem}%[section]
\theoremstyle{plain}      \newtheorem{lma}[thm]{Lemma}%[section]
\theoremstyle{plain}      \newtheorem*{lma*}{Lemma}
\theoremstyle{plain}      \newtheorem{cor}[thm]{Corollary}%[section]
\theoremstyle{plain}      \newtheorem*{cor*}{Corollary}%[section]
\theoremstyle{plain}      \newtheorem{claim}[thm]{Claim}%[section]
\theoremstyle{plain}      \newtheorem*{claim*}{Claim}
\theoremstyle{plain}      \newtheorem{prop}[thm]{Proposition}%[section]
\theoremstyle{plain}      \newtheorem*{prop*}{Proposition}%[section]
\theoremstyle{plain}      \newtheorem{observation}{Observation}
\theoremstyle{plain}      \newtheorem{property}{Property}
\theoremstyle{remark}     \newtheorem*{rmk}{Remark}
\theoremstyle{remark}     \newtheorem*{rcl}{Recall}
% \theoremstyle{remark}     \newtheorem*{fact}{Fact}
\theoremstyle{definition} \newtheorem{defn}[thm]{Definition}%[section]
\theoremstyle{definition} \newtheorem*{defn*}{Definition}%[section]
\theoremstyle{definition} \newtheorem{ex}{Example}%[section]
\theoremstyle{definition} \newtheorem*{ex*}{Example}%[section]

%%==================================
%% Solution and Problem Environments
%%==================================

%% New Solution Environments
\newenvironment{soln}{\vskip5bp \paragraph{\bf Solution:}}{\hfill$\qed$ \newline}
\newenvironment{resp}{\vskip5bp \paragraph{\bf Response:}}{\hspace{0pt} \newline}

%% New Solution With Counter
\newcounter{solno}
\setcounter{solno}{0}
\newenvironment{soln*}{
  \vskip5bp
  \addtocounter{solno}{1}
  \paragraph{\bf Solution~{\arabic{solno}}:} }
{
  \hfill$\qed$
  % \vskip10bp
}

%% macros for automatic problem numbering
\newcounter{probno}
\setcounter{probno}{0}
\newcounter{partno}
\setcounter{partno}{0}

%% Problem Environment
\newenvironment{problem}{
	\vskip10bp
  	\setcounter{partno}{0} %Set Part number counter to zero
      \setcounter{solno}{0} %Set the solution number counter to zero
  	\addtocounter{probno}{1} %Update Problem number counter
  	% \paragraph{
  		\begin{center}{\bf Problem~{\arabic{probno}}} \end{center}
      % {\bf Problem~{\arabic{probno}}}
  	% }
}
{
  \vskip10bp
}

%% Problem command
\newcommand{\prob}{
  \vskip10bp %Have some space at the top of the problem.
  \setcounter{partno}{0} %Set Part number counter to zero
  \setcounter{solno}{0} %Set the solution number counter to zero
  \addtocounter{probno}{1} %Update Problem number counter
  \begin{center}{\bf Problem~{\arabic{probno}}} \end{center} }
%% Probpart command
\newcommand{\probpart}{%\rule{0in}{0in}\\ \phantom{xxx}
  \addtocounter{partno}{1}%
  \noi {\bf Part \arabic{probno}\alph{partno}}.~~}
\newcommand{\probcont}{%
  {\bf Problem~\#{\arabic{probno}}}~(\emph{continued})}
\newcommand{\probo}{
  \setcounter{partno}{0}%
  \addtocounter{probno}{1}%
  {\bf (\#\arabic{probno})}\ \ }

%==============================
% Section Based Problem Command
%==============================

%% Prob Command with section based counting
\newcommand{\secprob}{
    \setcounter{probno}{0}

    %% Problem Environment
    \renewenvironment{problem}{
        \vskip10bp
        \setcounter{partno}{0} %Set Part number counter to zero
        \setcounter{solno}{0} %Set the solution number counter to zero
        \addtocounter{probno}{1} %Update Problem number counter
        \begin{center}{ \bf Problem~{\arabic{section}}.{\arabic{probno}}} \end{center}
    }
    {
      \vskip10bp
    }

    %% Problem Command
    \renewcommand{\prob}{
        \vskip10bp %Have some space at the top of the problem.
        \setcounter{partno}{0} %Set Part number counter to zero
        \setcounter{solno}{0} %Set the solution number counter to zero
        \addtocounter{probno}{1} %Update Problem number counter
        \begin{center}{\bf Problem~{\arabic{section}}.{\arabic{probno}}} \end{center}
    }

    %% Problem Part Command
    \renewcommand{\probpart}{%\rule{0in}{0in}\\ \phantom{xxx}
        \addtocounter{partno}{1}%
        \noi {\bf Part~{\arabic{section}}.\arabic{probno}\alph{partno}}.~~
    }
}

%====================================
% Remove Section Based Prob Numbering
%====================================

\newcommand{\nonsecprob}{
    \setcounter{probno}{0}

    %% Problem Environment
    \renewenvironment{problem}{
        \vskip10bp
        \setcounter{partno}{0} %Set Part number counter to zero
        \setcounter{solno}{0} %Set the solution number counter to zero
        \addtocounter{probno}{1} %Update Problem number counter
        \begin{center}{ \bf Problem~{\arabic{probno}}} \end{center}
    }
    {
      \vskip10bp
    }

    %% Problem Command
    \renewcommand{\prob}{
        \vskip10bp %Have some space at the top of the problem.
        \setcounter{partno}{0} %Set Part number counter to zero
        \setcounter{solno}{0} %Set the solution number counter to zero
        \addtocounter{probno}{1} %Update Problem number counter
        \begin{center}{\bf Problem~{\arabic{probno}}} \end{center}
    }

    %% Problem Part Command
    \renewcommand{\probpart}{%\rule{0in}{0in}\\ \phantom{xxx}
        \addtocounter{partno}{1}%
        \noi {\bf Part~\arabic{probno}\alph{partno}}.~~
    }
}

%================================================
% Bonus Problem Related Environments and Commands
%================================================
\newcounter{bonusno}
\setcounter{bonusno}{0}

%% Bonus Environement with Counter
\newenvironment{bonus}{
    \vskip10bp
    \setcounter{partno}{0} %Set Part number counter to zero
    \setcounter{solno}{0} %Set the solution number counter to zero
    \addtocounter{bonusno}{1} %Update Problem number counter

    \renewcommand{\probpart}{%\rule{0in}{0in}\\ \phantom{xxx}
        \addtocounter{partno}{1}%
        \noi {\bf Part B\arabic{bonusno}\alph{partno}}.~~
    }

    \begin{center}{ \bf Bonus Problem~{\arabic{probno}}} \end{center}
}
{
  \hspace{0pt} \newline
}

%% The Bonus Command
\newcommand{\thebonus}{
    \setcounter{probno}{0}

    %% Problem Environment
    \renewenvironment{problem}{
        \vskip10bp
        \setcounter{partno}{0} %Set Part number counter to zero
        \setcounter{solno}{0} %Set the solution number counter to zero
        \addtocounter{probno}{1} %Update Problem number counter
        \begin{center}{ \bf Bonus Problem~{\arabic{probno}}} \end{center}
    }
    {
      \hspace{0pt} \newline
    }

    %% Problem Command
    \renewcommand{\prob}{
        \vskip10bp %Have some space at the top of the problem.
        \setcounter{partno}{0} %Set Part number counter to zero
        \setcounter{solno}{0} %Set the solution number counter to zero
        \addtocounter{probno}{1} %Update Problem number counter
        \begin{center}{\bf Bonus Problem~{\arabic{probno}}} \end{center}
    }

    %% Problem Part Command
    \renewcommand{\probpart}{%\rule{0in}{0in}\\ \phantom{xxx}
        \addtocounter{partno}{1}%
        \noi {\bf Part B\arabic{probno}\alph{partno}}.~~
    }
}

\renewcommand{\qedsymbol}{\SquareShadowBottomRight}

% %% Bonus Environement without Counter
% \newenvironment{bonus*}{
%     \vskip10bp
%     \setcounter{partno}{0} %Set Part number counter to zero
%     \setcounter{solno}{0} %Set the solution number counter to zero
%     \addtocounter{bonusno}{1} %Update Problem number counter

%     \renewcommand{\probpart}{%\rule{0in}{0in}\\ \phantom{xxx}
%         \addtocounter{partno}{1}%
%         \noi {\bf Bonus Part (\alph{partno})}.~~
%     }

%     \begin{center}{ \bf Bonus Problem}} \end{center}
% }
% {
%   \hspace{0pt} \newline
% }


\section*{Context}
Often users of scattering methods are interested in the use of classical simulation to better understand the results that they have obtained.
However, regularly those with an experimental background aim to apply molecular simulation methods without true consideration of the potential pitfalls of using such methods.
These OERs were developed to introduce experimental colleagues\footnote{Additionally, in the case of \texttt{pylj} undergraduate students.} to classical simulation and MD.
They help to facilitate learning by providing a simple, but mathematically rigorous interface and enabling the ``worked example effect'' throughout.


\documentclass[a4paper, 12pt]{scrartcl}
  % Headers and footers.
  \usepackage{fancyhdr}
  % Enables the use of colour.
  \usepackage{xcolor}
  % Syntax high-lighting for code. Requires Python's pygments.
  \usepackage{minted}
  % Enables the use of umlauts and other accents.
  \usepackage[utf8]{inputenc}
  % Diagrams.
  \usepackage{tikz}
  % Settings for captions, such as sideways captions.
  \usepackage{caption}
  % Symbols for units, like degrees and ohms.
  \usepackage{gensymb}
  % Latin modern fonts - better looking than the defaults.
  \usepackage{lmodern}
  % Allows for columns spanning multiple rows in tables.
  \usepackage{multirow}
  % Better looking tables, including nicer borders.
  \usepackage{booktabs}
  % More math symbols.
  \usepackage{amssymb}
  % More math fonts, like \mathbb.
  \usepackage{amsfonts}
  % More math layouts, equation arrays, etc.
  \usepackage{amsmath}
  % More theorem environments.
  \usepackage{amsthm}
  % More column formats for tables.
  \usepackage{array}
  % Adjust the sizes of box environments.
  \usepackage{adjustbox}
  % Better looking single quotes in verbatim and minted environments.
  \usepackage{upquote}
  % Better blank space decisions.
  \usepackage{xspace}
  % Better looking tikz trees.
  \usepackage{forest}
  % URLs.
  \usepackage[hidelinks]{hyperref}
  % Plotting.
  \usepackage{pgfplots}
  % Calculates the number of pages.
  \usepackage{lastpage}
  % Styling the abstract.
  \usepackage{abstract}

  % Various tikz libraries.
  % For drawing mind maps.
  \usetikzlibrary{mindmap}
  % For adding shadows.
  \usetikzlibrary{shadows}
  % Extra arrows tips.
  \usetikzlibrary{arrows.meta}
  % Old arrows.
  \usetikzlibrary{arrows}
  % Automata.
  \usetikzlibrary{automata}
  % For more positioning options.
  \usetikzlibrary{positioning}
  % Creating chains of nodes on a line.
  \usetikzlibrary{chains}
  % Fitting node to contain set of coordinates.
  \usetikzlibrary{fit}
  % Extra shapes for drawing.
  \usetikzlibrary{shapes}
  % For markings on paths.
  \usetikzlibrary{decorations.markings}
  % For advanced calculations.
  \usetikzlibrary{calc}

  % GMIT colours.
  \definecolor{gmitblue}{RGB}{20,134,225}
  \definecolor{gmitred}{RGB}{220,20,60}
  \definecolor{gmitgrey}{RGB}{67,67,67}

  % Set minted up.
  \usemintedstyle{manni}
  \setminted{baselinestretch=1.2, bgcolor=gmitgrey!10}

  % Change the displayed name of the references section.
  \renewcommand{\refname}{\selectfont\large References}

  % Heading
  \title{\vspace{-20mm}Tasks 2020}
  \author{Machine Learning and Statistics}
  \date{Due: last commit on or before January 1\textsuperscript{st}, 2021\vspace{-6mm}}

\begin{document}

  \maketitle

  These are the instructions for the Tasks assessment for Machine Learning and Statistics in 2020.
  The assessment is worth 50\% of the marks for the module.
  Please read the \emph{Using git for assessments}~\cite{usinggit} document on the Moodle page which applies here.
  As always, you must also follow the code of student conduct and the policy on plagiarism~\cite{gmitqaf}.

  \section*{Instructions}
    Four tasks will be listed here at different times during the semester.
    You should complete all tasks in a single jupyter notebook.
    This, along with relevant files like a README, should be in a single git repository synced with a hosting provider like GitHub~\cite{github}.
    That URL should then be submitted using the link on the Moodle page.

    \begin{enumerate}
      \item
        \textbf{October 5\textsuperscript{th}, 2020:}
        Write a Python function called \mintinline{python}{sqrt2} that calculates and prints to the screen the square root of 2 to 100 decimal places.
        Your code should not depend on any module from the standard library\footnote{By the standard library, we mean the modules and packages that come as standard with Python. Anything built-in that can be used without an \mintinline{python}{import} statement can be used.} or otherwise.
        You should research the task first and include references and a description of your algorithm.
      \item
        \textbf{November 2\textsuperscript{nd}, 2020:}
        The Chi-squared test for independence is a statistical hypothesis test like a $t$-test. It is used to analyse whether two categorical variables are independent. The Wikipedia article gives the table below as an example~\cite{wikichisquare}, stating the Chi-squared value based on it is approximately $24.6$. Use \mintinline{python}{scipy.stats} to verify this value and calculate the associated $p$ value. You should include a short note with references justifying your analysis in a markdown cell.

        \begin{table}[H]
          \setlength{\tabcolsep}{12pt}
          \renewcommand{\arraystretch}{1.1}
          \centering
          \begin{tabular}{lrrrrr}
            & A & B & C& D & Total \\
            \midrule
            White collar & 90 & 60 & 104 & 95 & 349 \\
            Blue collar & 30 & 50 & 51 & 20 & 151 \\
            No collar & 30 & 40 & 45 & 35 & 150 \\
            \midrule
            Total & 150 & 150 & 200 & 150 & 650
          \end{tabular}
        \end{table}
        \newpage
      \item
        \textbf{November 16\textsuperscript{th}, 2020:}
        The standard deviation of an array of numbers \mintinline{python}{x} is calculated using \mintinline{python}{numpy} as \mintinline{python}{np.sqrt(np.sum((x - np.mean(x))**2)/len(x))}.
        However, Microsoft Excel has two different versions of the standard deviation calculation, \mintinline{python}{STDEV.P} and \mintinline{python}{STDEV.S}.
        The \mintinline{python}{STDEV.P} function performs the above calculation but in the \mintinline{python}{STDEV.S} calculation the division is by \mintinline{python}{len(x)-1} rather than \mintinline{python}{len(x)}.
        Research these Excel functions, writing a note in a Markdown cell about the difference between them.
        Then use \mintinline{python}{numpy} to perform a simulation demonstrating that the \mintinline{python}{STDEV.S} calculation is a better estimate for the standard deviation of a population when performed on a sample.
        Note that part of this task is to figure out the terminology in the previous sentence.
      \item
        \textbf{November 30\textsuperscript{th}, 2020:}
        \textbf{NB -- when I first posted this task, I accidentally wrote ``$k$-means'' where I meant to write ``$k$NN'' for $k$ Nearest Neighbours.
        Because of this, I will allow either algorithm to be used and have extended the deadline by two weeks.}
        Use \mintinline{python}{scikit-learn} to apply $k$ Nearest Neighbours clustering to Fisher's famous Iris data set.
        You will easily obtain a copy of the data set online.
        Explain in a Markdown cell how your code works and how accurate it might be, and then explain how your model could be used to make predictions of species of iris.
    \end{enumerate}

  \newpage

  \section*{Marking scheme}
    The following marking scheme will be used to mark your submission out of 100\%, which will then be scaled to 50\%.
    The examiner's overall impression of your submission may influence marks in each individual component.
    It is important that your submission provides direct evidence of each of the items listed in each category.
    For instance, your commit history should demonstrate and provide evidence that you had a pragmatic attitude to completing the assessment.
    Likewise, your submission should have references in it to demonstrate that you considered the literature and the work of others.

    \begin{center}
      \begin{tabular}{llp{8.4cm}}
        \toprule
        25\% & \textbf{Research} & Evidence of research performed on topic; submission based on referenced literature, particularly academic literature; evidence of understanding of the documentation for any software or libraries used. \\
        \midrule
        25\% & \textbf{Development} & Environment can be set up as described; code works without tweaking and as described; code is efficient, clean, and clear; evidence of consideration of standards and conventions appropriate to code of this kind. \\
        \midrule
        25\% & \textbf{Consistency} & Evidence of planning and project management; pragmatic attitude to work as evidenced by well-considered commit history; commits are of a reasonable size; consideration of how commit history will be perceived by others. \\
        \midrule
        25\% & \textbf{Documentation} & Clear documentation of how to create an environment in which any code will run, how to prepare the code for running, how to run the code including setting any options or flags, and what to expect upon running the code. Concise descriptions of code in comments and README. \\
        \bottomrule
      \end{tabular}
    \end{center}

  \bibliographystyle{ieeetrans}
  \bibliography{bibliography}

\end{document}


\section{Application to synthetic data}

We have simulated three sources whose horizontal projections are shown in
Figure \ref{fig:synthetic_data} as black lines.
These sources are a sphere with density contrast
$-1.25\, \mathrm{g/cm^3}$ and two rectangular prisms with density contrasts
$1.00\, \mathrm{g/cm^3}$ (upper-left prism)
and $1.30\, \mathrm{g/cm^3}$ (upper-right prism).
Figure \ref{fig:synthetic_data} shows the gravity disturbance (vertical component of
gravitational attraction) produced by these sources.
The synthetic data are contaminated with additive pseudorandom Gaussian
noise with zero mean and standard deviation of $0.1 \, \mathrm{mGal}$.
The data are computed at $N = 10,000$ observation points that are regularly spaced on a
$100 \times 100$ grid, at $z_{1} = -100$ m.
We have set a grid of equivalent sources, each one directly beneath each
observation point, at $z_{0} = 300$ m.

Figure \ref{fig:comparison_datafits}a and \ref{fig:comparison_datafits}b show the data fits
obtained, respectively, by the fast equivalent-layer technique \citep{siqueira-etal2017}
and by our method. They represent the differences between the simulated data (Figure \ref{fig:synthetic_data}) and the predicted data produced by both methods
(not shown) after $N^{it} = 40$ iterations.
As we can see, both methods produce virtually the same results.
This excellent agreement is confirmed by Figure \ref{fig:comparison_datafits}c, which shows
the differences between the predicted data produced by both methods.

We performed the upward and downward continuations of the simulated gravity data
(Figure \ref{fig:synthetic_data}) by using the fast equivalent-layer technique
\citep{siqueira-etal2017}, our method and also the classical approach in the
Fourier domain. This approach consists in performing the upward/downward continuation
by directly computing the Fourier transform of the gravity data
\citep[e.g., ][ p. 317]{blakely1996}.
Figure \ref{fig:upward_comparison} shows the upward-continued gravity data
obtained by the three methods.
As we can see, the residuals between the true data at $z = -300$ m
(Figure \ref{fig:upward_comparison}a) and the upward-continued data obtained by
using our method (Figure \ref{fig:upward_comparison}b) and
the fast equivalent-layer technique (Figure \ref{fig:upward_comparison}c) are very similar
to each other.
Note that the absolute values of the residuals produced by the classical Fourier
approach (Figure \ref{fig:upward_comparison}d) are $\approx 10$ times greater than
those produced by our method and the fast equivalent-layer technique
(Figure \ref{fig:upward_comparison}b and \ref{fig:upward_comparison}c),
with maximum values concentrated at the border of the simulated area.
Differently from the results yield by our method (Figure \ref{fig:upward_comparison}b)
and the fast equivalent-layer technique (Figure \ref{fig:upward_comparison}c),
that obtained with the classical Fourier approach exhibits a slight noise
amplification (Figure \ref{fig:upward_comparison}d).

Figure \ref{fig:downward_comparison} shows the results obtained by using all
methods to compute downward continuation of gravity data.
In this case, the maximum absolute values of the residuals produced by the
classical Fourier approach (Figure \ref{fig:downward_comparison}d) are
$\approx 20$ times greater than those produced by our method and the fast equivalent-layer technique (Figure \ref{fig:downward_comparison}b and \ref{fig:downward_comparison}c).
This noise amplification is a well-known problem of the downward continuation
produced by the classical Fourier approach \citep[e.g., ][ p. 320]{blakely1996}.

We opted for showing all the results (Figures \ref{fig:upward_comparison} and
\ref{fig:downward_comparison}) produced by all methods without removing the border
effects in order to properly compare them to each other.
We also stress that no padding function to expand the data was used in applying
our method, the fast equivalent-layer technique or the Fourier approach.
It is important to stress that the Fourier method shows heavy border effects at large
altitudes if no padding is applied \citep{baniamerian_etal2017}.
Another important aspect to be pointed out about these results
is that the computational time required by our method to estimate the physical-property
distribution on the equivalent layer and to perform the upward/downward continuations
is about two orders of magnitude lower than that spent by the fast equivalent-layer technique.
This significant reduction in computational time was obtained by using a data set
composed of $N = 10,000$ observation points. Considerably better results can be
obtained with larger data sets.

Finally, we did not compare the total computational times spent by our method
and the classical Fourier approach, but we can affirm that the second is smaller.
Because  the Fourier approach requires only one DFT/IDFT of the data, whereas
our method requires one DFT/IDFT per iteration, the former is computationally faster
than our method.
However, the considerably smaller noise amplification and practically nonexistent
border effects obtained without applying any padding function to expand
the data are the main advantages of our method over the classical Fourier
approach, especially in the downward continuation.


\documentclass[a4paper,12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{fullpage,url}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{listings}
\usepackage{amssymb,amsmath,amsthm}
\usepackage{color}

\title{A Formal Proof of Bellman-Ford Algorithm}
\author{Yuto Takei \\ The University of Tokyo }

\lstdefinelanguage{Why3}
{
basicstyle=\ttfamily,
keywordstyle=\color{blue},
morekeywords=[1]{inductive,predicate,function,goal,type,use,import,theory,end,in,axiom,lemma,export,forall,constant,module,let,exception,match,with,exists},%
%keywordstyle=[1]{\color{red}},%
morekeywords=[2]{true,false},%
%keywordstyle=[2]{\color{blue}},%
otherkeywords={},%
commentstyle=\itshape,%
columns=[l]fullflexible,%
sensitive=true,%
morecomment=[s]{(*}{*)},%
escapeinside={*?}{?*},%
keepspaces=true,
literate=%
{'a}{$\alpha$}{1}%
{'b}{$\beta$}{1}%
{<}{$<$}{1}%
{>}{$>$}{1}%
{<=}{$\le$}{1}%
{>=}{$\ge$}{1}%
{<>}{$\ne$}{1}%
{/\\}{$\land$}{1}%
{\\/}{ $\lor$ }{3}%
{\ or(}{ $\lor$(}{3}%
{not\ }{$\lnot$ }{1}%
{not(}{$\lnot$(}{1}%
{->}{$\rightarrow$}{2}%
{<->}{$\leftrightarrow$}{2}%
}

\lstnewenvironment{why3}
{\lstset{language=Why3}}
{}

\newcommand{\edgen}[3]{#1\rightarrow_{#3}#2}
\newcommand{\pathn}[3]{#1\rightarrow^\star_{#3}#2}

\begin{document}

\maketitle

\begin{abstract}
  This is the abstract.
\end{abstract}

\section{Introduction}

I want to \emph{emphasize} a word.

\section{Bellman-Ford Algorithm}

The Bellman-Ford algorithm is one of the algorithms to solve the
single-source shortest paths problem, i.e., to give the shortest paths
to all vertices from one given source vertex. To solve such a problem,
Dijkstra's algorithm is widely known as an effective solution, yet it
assums edges to have non-negative length. The Bellman-Ford algorithm
relaxed such the assumption and is able to compute the solution for
directed graphs with edges that have negative length.

However on the other hand, if the graph contains a cycle whose total
length of involving edges is negative, it may cause an inability to
compute the shortest paths. This is only limited to the case such a
negative-cylce is reachable from the given source, and the
Bellman-Ford algorithm detects and reports it without failure.

Now we give the formal description of the single-source shortest
paths. It is given as a triple $ (G,s,l) $, where $ G $ represents a
directed graph $ G=(V,E) $, $ s \in V $ is a source vertex, and $ l :
E \rightarrow \mathbf{R} $ gives the length for all edges. The goal
for this problem is either to produce the shortest path tree from $ s
$ or to prove that there is a negative-cycle reachable from $ s $.

The listing \ref{alg:bf} shows the psuedocode of the Bellman-Ford
algorithm \cite[p.~532]{algo}.

\newcommand{\initBF}{\ensuremath{\mbox{\sc Initialize-Single-Source}}}
\newcommand{\relaxBF}{\ensuremath{\mbox{\sc Relax}}}
\newcommand{\mainBF}{\ensuremath{\mbox{\sc Bellman-Ford}}}

\begin{algorithm}
\caption{$ \initBF (G,s) $}
\begin{algorithmic}[1]
\FORALL{ vertex $ v \in V[G] $}
\STATE{$ d[v] \leftarrow \infty $}
\STATE{$ \pi [v] \leftarrow nil $}
\ENDFOR
\STATE{$ d[s] \leftarrow 0 $}
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\caption{$ \relaxBF (u,v,l) $}
\begin{algorithmic}[1]
\IF{$ d[v]>d[u]+l(u,v) $}
\STATE{$ d[v] \leftarrow d[u]+l(u,v) $}
\STATE{$ \pi [v] \leftarrow u $}
\ENDIF
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\caption{$ \mainBF (G,s,l) $}\label{alg:bf}
\begin{algorithmic}[1]
\STATE{$ \initBF (G,s) $}
\FOR{$i = 1 \to |V[G]|-1 $}
\FORALL{ edge $ (u,v) \in E[G] $}
\STATE{$ \relaxBF (u,v,l) $}
\ENDFOR
\ENDFOR
\FORALL{edge $ (u,v)\in E[G] $}
\IF{$ d[v]>d[u]+l(u,v) $}
\RETURN{False}
\ENDIF
\ENDFOR
\RETURN{True}
\end{algorithmic}
\end{algorithm}

\section{Quick Overview of Why3}

Why3 is a software verification platfrom that enables one to describe
the algorithm properties by first-order logic. Its important feature
is the ability to separate the logical statements from programs
\cite{boogie11why3}.

\subsection{Logic}

Logic component is described by set of theories that contains the
definition of data types, their characteristics as either an axiom or
a lemma, and predicates (or functions if returns non-Boolean) upon the
given arguments.

\paragraph {[TODO: align the following paragraphs]}

\emph{Types.} Types are either a non-interpreted abstract type or an
algebraic type with polymorphism supported.

\emph{Predicates and functions.} Predicate takes any number of
arguments with the above type and returns a Boolean value. Function
plays the same role but returns non-Boolean values. They are strictly
typed before verification and recognized its recursiveness. The other
important things is that the termination of them is guaranteed by the
automated check of the structural decreasing of arguments.

\emph{Inductive predicates.} Inductive predicate is provided as an
other option to declare predicates. It is described by the set of
conditional clauses where the predicate holds, and defined as the
minimum predicate that all of them hold.

\subsection{Program}

Program component takes over the similar syntax as Objective Caml
\ref{ocaml}, but we define conditions of the program additionally.

\emph{Pre-condition and post-condition.} Pre-condition is the
assumption that the algorithm makes prior to its execution, and the
post-condition is the result the aglrotihm ensures after its
execution. It is often useful to describe the effect of the
algorithm. One should give the most strict statement for
pre-condition, and the most general statement for post-condition.

\emph{Loop variant.} Variant expression is used to guarantees the
terminability of recursive calls or loops. One must give an arbitral
integral expression for it, which necessarily decreases in the certain
sequential operations. With the assumption that the given expression
remains positive during the iteration, and firmly decreases at every
step, Why3 guarantees that the iteration will eventually terminate.

(TODO: Insertion of small example)

\section{Formal Proof}

\subsection{Specification}

Proving the algorithm first starts by providing the specification of
the algorithm. It should be minimal yet comprehensive to define the
behavior of algorithm and should be clearly distinguished from the
proofs. We now present minimal logical properties of graph data
structure as prerequisites for Bellman-For algorithm, and then
introduce those of the algorithm itself.

\subsubsection{Graph}

In order to show the correctness of algorithms that make use of graph
data structure, it is neccesary to define the characteristics of graph
itself in purely logical way. There are several ways to represent the
graph for formal verification.

\begin{enumerate}

\item Defining the logical functions, which give the set of vertices,
  successors to each of them, and weight between one vertex and
  another. Note that the verification context encapsulate the actual
  graph and thus the algorithm should obtain it by calling those
  global functions.

\item Passing the graph as one of the input parameters for the
  algorithm. Although this structure is more natural in practical
  implementation, one must pass the graph to all involving
  sub-functions as a parameter and describe the desired property of it
  as a pre-condition for them.

\end{enumerate}

Note that both of above will eventually result in the similar
proof. For the simplicity in this paper, we choose the first method.

Considering the Bellman-Ford algorithm, one must give the formal
definition of the path with the given length. We define such the path
by inductive manner. Let $\edgen{v_1}{v_2}{n}$ denote the existence of
the edge between $ v_1 $ and $ v_2 $ with the length $ n $, and $ \to
^* $ represent the transitive closure of $ \to $; then following two
properties are introduced.

\begin{displaymath}
  \frac{}
       {\pathn{v}{v}{0}}
  \qquad\qquad
  \frac{\pathn{v_1}{v_2}{m} \qquad \edgen{v_2}{v_3}{n}}
       {\pathn{v_1}{v_3}{m+n}}
\end{displaymath}

(\textbf{TODO:} My arrow is so ugly... $ \stackrel{m+n}{\longrightarrow^*} $)

After introducing the predicate for the path existence between certain
vertices, one can immediately precise that the property of the
shortest path from $ v_1 $ to $ v_2 $ with length $ n $, i.e., to
assert that there are no path shorter than $ n $ connecting $ v_1 $ to
$ v_2 $. Moreover, if no such path exists from $ v_1 $ to $ v_2 $, it
is suffice to say that there is no $ n $, which is the length between
those vertices.

With the specification in Why3 syntax, the formulation above is
expressed as in the listing~\ref{lst:why_graph}. Here all graph
structures and predicates are packed in the theory \mbox{\sc
  Graph}. Vertices are given as a global constant set namely \mbox{\sc
  vertices}, and edges and their weights are given by global functions
\mbox{\sc succ} and \mbox{\sc weight} respectively.

\begin{algorithm}
\caption{Definition of graph in logical way}\label{lst:why_graph}
\begin{why3}[1]
theory Graph
  use export int.Int
  use export set.Fset

  type vertex
  constant vertices : set vertex
  function succ vertex : set vertex
  function weight vertex vertex : int

  inductive path (v1 v2: vertex) (n: int) =
    | path_empty:
        forall v: vertex. path v v 0
    | path_succ:
        forall v1 v2 v3: vertex, n: int.
        path v1 v2 n -> mem v3 (succ v2) -> path v1 v3 (n + weight v2 v3)

  predicate shortest_path (v1 v2: vertex) (n: int) =
    path v1 v2 n /\
    forall m: int. m < n -> not (path v1 v2 m)

  predicate no_path (v1 v2: vertex) =
    forall n: int. not (path v1 v2 n)
end
\end{why3}
\end{algorithm}

\subsubsection{Bellman-Ford algorithm}

Now we discuss the foundamental characteristics of Bellman-Ford
algorithm. They consists of precondition, postcondition and
terminability of the algorithm, and we aim to describe it by utilizing
Hoare logic.

Although the psuedocode of Bellman-Ford algorithm in listing
\ref{alg:bf} returns an Boolean value and modify the distance and
parent mappings in imperatiev manner, we slightly change the format
for practical implementation in O'Caml and let it return a mapping
from vertex to shortest-distances rather than the indication of the
existence of negative-cycle. Additionally, we raise an exception in
presence of the negative-cycle.

As a result, our implementation will be a function that takes the
source vertex $ s $ as a single argument, and either returns the
mapping from $ v $ to \mbox{\sc int} for shortest paths, or raise an
exception indicating the presence of a negative cycle. Now we adapt
algorithmic characteristic into the implementation above.

\emph{Precondition.} The only requirement is that the source vertex $
s $ given must be contained in the graph $ G $, which is described by
the theory \mbox{\sc Graph}.

\emph{Postcondition.} If algorithm returns the value without the
exception, the resulting mapping at the key $ v $ should give the
length of the shortest path from $ s $ to $ v $. The existence of such
a path is indicated by the algebraic type, which either has a finite
integer value or an inifinity. With the exception returned, there
exists at least one negative-cycle.

\emph{Terminability.} (TODO)

Note that the case without the exception, one does not need to assert
the graph to be free of negative-cycle.

\begin{algorithm}
\caption{Specification of Bellman-Ford algorithm}\label{lst:why_bf}
\begin{why3}[1]
module BellmanFord
  use import map.Map
  use import Graph

  type dist = Finite int | Infinite
  type distmap = map vertex dist

  exception NegativeCycle

  let bellman_ford (s: vertex) : distmap =
    { mem s vertices }
    (* ... actual implementation comes here ... *)
    { forall v: vertex. mem v vertices ->
        match result[v] with
        | Finite n -> shortest_path s v n
        | Infinite -> no_path s v
        end }
    | NegativeCycle ->
    { exists v: vertex. mem v vertices /\
      exists n: int. n < 0 /\ path v v n  }
end
\end{why3}
\end{algorithm}

\subsection{Proof}

\section{Conclusion}

\bibliographystyle{plain}
\bibliography{./biblio}

\end{document}


\documentclass{beamer}
\usepackage[utf8]{inputenc}

\input{../../shared_slides.tex}

\newcounter{sauvegardeenumi}
\newcommand{\asuivre}{\setcounter{sauvegardeenumi}{\theenumi}}
\newcommand{\suite}{\setcounter{enumi}{\thesauvegardeenumi}}

\title{Mirror Descent}
\date{\today}

\begin{document}
\maketitle
\frame{\tableofcontents}

\section{About norms}

\begin{frame}
  \frametitle{Recap on (sub)-gradient descent}

  \begin{itemize}
    \item When we used a norm $\Vert \cdot \Vert$ we meant the \emph{$2$-norm}, i.e.\
          \begin{equation}
            \Vert x \Vert_2 = {\Big({\sum_{i=1}^{d} x_i^2} \Big)}^{1/2}.
          \end{equation}
    \item In \textbf{gradient descent} we used Lipschitz continuity:
          \begin{equation}
            \Vert \nabla f(x) - \nabla f(y) \Vert \le L \Vert x-y \Vert.
          \end{equation}
          (Lead to a complexity of $\mathcal{O}(\frac{L}{k})$) \\

  \onslide<2->{%
    \item For \textbf{sub-gradient descent} we used $\Vert g \Vert \le G$ which
    lead to a complexity of $\mathcal{O}(\frac{G}{\sqrt{k}})$.
  }

  \onslide<3->{%
    \item But there are \textcolor{blue}{other norms}
    \begin{equation}
      \Vert x \Vert_\infty \le \Vert x \Vert_2 \le \sqrt{d} \Vert x \Vert_\infty
    \end{equation}
    It can happen that $  \Vert g \Vert_\infty \le G \quad \text{but} \quad \Vert g \Vert_2 \approx \sqrt{d}G$.
  }
  \end{itemize}

\end{frame}

\begin{frame}
  \frametitle{Different norms?}
  \begin{center}
    \textit{But where did we use the norm in the \textbf{method}?}
  \end{center}

  \begin{block}{Gradient Descent}
    \begin{equation}
      x_{k+1} = x_k - \alpha_k \nabla f(x_k)
    \end{equation}
    equivalently
    \begin{equation}
      x_{k+1} = \argmin_{x \in \R^d} \left\{ f(x_k) + \langle \nabla f(x_k), x-x_k \rangle + \frac{1}{2 \alpha_k} \Vert x-x_k  \Vert_2^2 \right\}
    \end{equation}
  \end{block}
  We can replace the $2$-norm with a more general \textbf{distance}.
\end{frame}

\section{Bregman distances}%

\begin{frame}
  \frametitle{Bregman distance}
  $h: \R^d \to \R \cup \{+\infty\}$ is convex
  \begin{enumerate}
    \item h is differentiable of the interior of $\dom h$
    \item h is $1$-strongly convex w.r.t. $\Vert \cdot \Vert_2$
  \end{enumerate}
  Then
  \begin{equation}
    \Dh(x,y) := h(x) - h(y) - \langle \nabla h(y), x-y \rangle.
  \end{equation}

  \onslide<2->{%
    \begin{block}{Properties}
      \begin{itemize}
        \item $\Dh(x, y) \ge 0$
        \item $\Dh(x, y) \neq \Dh(y, x)$
        \item $\Dh(\cdot, y)$ is convex for all $y$
              \begin{equation}
                \Dh(x,y) \approx \frac12 \langle \nabla^2h(y)(x-y), x-y \rangle = \frac12 \Vert x-y \Vert_{\nabla^2h(y)}^2
              \end{equation}
        \item $\Dh(x, y) \ge \frac12 \Vert x-y \Vert^2$ ($1$-strong convexity)
      \end{itemize}
    \end{block}
  }
\end{frame}

\begin{frame}
  \frametitle{Examples} % of Bregman distances
  \begin{itemize}
    \item $h(x) = \frac12 \Vert x \Vert_2^2$ gives $\Dh(x,y) = \Vert x-y \Vert^2$
    \item $h(x) = \frac{1}{2(p-1)} \Vert x \Vert_p^2$ with $p \in [1, 2]$
    \item  $\Delta^d= \{x \in \R^d_+ : \sum_{i=1}^{d}x_i = 1\}$ the \emph{unit simplex} and
          \begin{equation}
            h(x) =
            \begin{cases}
              \sum_{i=1}^{d} x_i \log(x_i) & x_i > 0 \\
              +\infty & \text{otherwise}
            \end{cases}
          \end{equation}
          the \textbf{Negative entropy}.\\
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Negative entropy}
  \begin{itemize}
    \item Negative entropy: $h(x) = \sum_{i=1}^{d} x_i \log(x_i)$ for $ x_i > 0$. \\
    \item Then $ \nabla h(x) = \log(x) + \bm{1}$ (coordinatewise) and
    \begin{equation}
    \begin{aligned}
        \Dh(x,y) &= \sum_{i=1}^{d}x_i \log(x_i) - y_i \log(y_i) - \langle \log(y)+ \bm{1}, x-y \rangle \\
        &= \sum_{i=1}^{d} x_i \log(x_i) - \sum_{i=1}^{d} x_i \log(y_i) \\
        &= \sum_{i=1}^{d} x_i \log\left(\frac{x_i}{y_i}\right)
    \end{aligned}
    \end{equation}
    Known as \textcolor{blue}{Kullback-Leibler divergence} $K(X \Vert Y)$.
    \item Is strongly convex over $\Delta$
    \begin{equation}
      \D(x, y) \ge \frac12 \Vert x-y \Vert_1^2 \quad \text{Pinsker's ineq.}
    \end{equation}
  \end{itemize}
\end{frame}

\section{Mirror descent}%

\begin{frame}
  \frametitle{Mirror descent}
    Idea: replace squared Euclidian norm with more general object:
    \begin{equation}
      \begin{aligned}
        x_{k+1} &= \argmin_{x \in \R^d} \{ f(x_k) + \langle \nabla f(x_k), x-x_k \rangle + \frac{1}{\alpha_k} \Dh(x,x_k)\} \\
        \onslide<2->{%
          &= \argmin_{x \in \R^d} \{ \langle \nabla f(x_k), x \rangle + \frac{1}{\alpha_k} \Dh(x,x_k)\} \\
          &= \argmin_{x \in \R^d} \{ \langle \nabla f(x_k), x \rangle + \frac{1}{\alpha_k} (h(x) - h(x_k) - \langle \nabla h(x_k), x-x_k \rangle)\} \\
          &= \argmin_{x \in \R^d} \{ \langle \nabla f(x_k), x \rangle + \frac{1}{\alpha_k} (h(x) - \langle \nabla h(x_k), x \rangle)\} \\
          &= \argmin_{x\in \R^d} \{ \langle \alpha_k \nabla f(x_k) - \nabla h(x_k), x \rangle + h(x) \} \\
        }
      \end{aligned}
    \end{equation}

    \onslide<3->{%
      \textbf{Question:} But why \emph{mirror} descent?
    }
\end{frame}

\begin{frame}
  \frametitle{The Mirror part}
  \begin{equation}
    x_{k+1} = \argmin_{x\in \R^d} \{ \langle \alpha_k \nabla f(x_k) - \nabla h(x_k), x \rangle + h(x) \}
  \end{equation}
  By optimality condition:
  \begin{equation}
    0 = \alpha_k \nabla f(x_k) - \nabla h(x_k) + \nabla h(x_{k+1})
  \end{equation}
  Therefore
  \begin{equation}
    \nabla h(x_{k+1}) =  \nabla h(x_k)  - \alpha_k \nabla f(x_k)
  \end{equation}

\end{frame}

\begin{frame}
  \frametitle{Why it's called mirror descent}
  \begin{figure}[ht]
    \centering
    \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{mirror}
    \caption{$\psi = h$}
  \end{figure}
\end{frame}

% yura mirror descent part 2 begins here

\begin{frame}
  \frametitle{Mirror Descent on the unit simplex}
    \textcolor{blue}{Negative entropy}: $h(x) = \sum_{i=1}^{d} x_i \log(x_i)$ for $ x_i > 0$. \\
    We define $a := \alpha_k \nabla f(x_k) - \nabla h(x_k)$. Then
    \begin{equation}
      x_{k+1} = \argmin_{x \in \Delta} \{ \langle a, x \rangle + h(x)\}
    \end{equation}
    with $x_i \ge 0$ and $\sum x_i = 1$.
    \begin{block}{How to solve this?}
      Via \textbf{Lagrange }
      \begin{equation}
        L(x,\mu) = \langle a, x \rangle + h(x) - \mu (x_1+\cdots+ x_d -1)
      \end{equation}
    \end{block}
\end{frame}

\begin{frame}
  \frametitle{Mirror Descent on the unit simplex [contd]}
      Then,
      \begin{equation}
        \begin{aligned}
          \partial_{x_i} L(x,\mu) &= a_i + \log(x_i) +1 - \mu \overset{!}{=} 0 \\
          \log(x_i) &= \mu -1 - a_i  \\
          x_i &= e^{\mu - 1 - a_i} = \beta e^{-a_i}
        \end{aligned}
      \end{equation}
      with $\beta= e^{\mu-1}$.

      \onslide<2->{%
        Second constraint:
        \begin{equation}
          \begin{aligned}
            \sum_{i=1}^{d} x_i \overset{!}{=} 1
            &\Rightarrow \sum_{i=1}^{d} \beta e^{-a_i} = 1
            \Rightarrow \beta = \frac{1}{\sum_{i=1}^{d} e^{-a_i}} \Rightarrow x_i = \frac{e^{-a_i}}{\sum_{j=1}^{d} e^{-a_j}}
          \end{aligned}
        \end{equation}
      }

      \onslide<3->{%
        Final mirror descent update:
        \begin{equation}
          x_{k+1}(i) = \frac{x_k(i) e^{\alpha_k {[\nabla f(x_k)]}_i}}{\sum_{j=1}^{d}e^{\alpha_k {[\nabla f(x_k)]}_j}}
        \end{equation}
      }
\end{frame}

\begin{frame}
  \frametitle{(General) mirror descent convergence statement}
  Since we changed norm in the space of the variable $x$, we need to go to the \textcolor{blue}{dual norms} in the space of the subgradients
  \begin{equation}
    \Vert y \Vert_* := \max_{\Vert x \Vert=1} \{ \langle y, x \rangle\}.
  \end{equation}
  \begin{theorem}
    In $(\R^d, \Vert \cdot \Vert)$ and subgradients bounded in dual norm $\Vert g_k \Vert_* \le G$, then
    \begin{equation}
      f(\bar{x}_k) - f^* \le \frac{{(\D(x^*, x_0))}^{1/2} G}{\sqrt{k}},
    \end{equation}
    where $\bar{x}_k$ denotes the averaged iterates, as usual.
  \end{theorem}
\end{frame}

\begin{frame}
  \frametitle{Convergence on the unit simplex}
    \textbf{What about $\D(x^*, x_0) $?}
    Let $x_0 = (\frac{1}{n}, \cdots , \frac{1}{n})$, then
    \begin{equation}
      \D(x, x_0) = \sum x_i \log\left(\frac{x_i}{\frac1n}\right) = \sum x_i \log(x_i) + \log(n) \le log(n)
    \end{equation}
    while $ \Vert x_0 - x^* \Vert^2 \le 2$.

    But if
    \begin{equation}
      \Vert g \Vert_\infty = \Vert g \Vert_1^* \le G
    \end{equation}
    we can still have
    \begin{equation}
      \Vert g \Vert_2 \approx \sqrt{d} G.
    \end{equation}
\end{frame}

\begin{frame}
  \frametitle{Proof}
  In the Euclidian space we used
  \begin{align}
    \MoveEqLeft \langle x_{k+1}-x_k, x^* -x_{k+1} \rangle \\
    &= \frac12 \Vert x^*-x_k \Vert^2 - \frac12 \Vert x^*-x_{k+1} \Vert^2 - \frac12 \Vert x_{k+1}-x_k \Vert^2.
  \end{align}
  Similar \textcolor{blue}{$3$-point identity} holds for Bregman distances:
  \begin{align}
    \MoveEqLeft \langle \nabla h(x_{k+1})-\nabla h(x_k), x^*-x_{k+1} \rangle =\\
    &= D(x^*, x_k) - D(x^*, x_{k+1}) - D(x_{k+1}, x_k).
  \end{align}
  Therefore
  \begin{equation}
    D(x^*, x_{k+1}) \le  D(x^*, x_k) - D(x_{k+1}, x_k) + \alpha \langle g_k, x^*-x_{k+1} \rangle.
  \end{equation}
\end{frame}

\begin{frame}
  \frametitle{Proof II}
  \begin{equation}
    D(x^*, x_{k+1}) \le  D(x^*, x_k) - D(x_{k+1}, x_k) + \alpha \langle g_k, x^*-x_{k+1} \rangle.
  \end{equation}
  Last term is not quite right.
  \begin{align}
    \langle g_k, x^*-x_{k+1} \rangle &= \langle g_k, x^*-x_k \rangle + \langle g_k, x_k-x_{k+1} \rangle \\
                         &\le f(x^*)-f(x_k) + \Vert g_k \Vert_* \Vert x_k-x_{k+1} \Vert \\
    &\le f(x^*)-f(x_k) + \frac{\alpha \Vert g_k \Vert_*^2}{2} + \frac{\Vert x_k-x_{k+1} \Vert^2}{2 \alpha}.
  \end{align}
  Combined we get that
  \begin{align}
    D(x^*, x_{k+1}) &\le  D(x^*, x_k) - D(x_{k+1}, x_k) + \alpha (f(x^*)-f(x_k)) \\
    &\quad+ \frac{\alpha^2 \Vert g_k \Vert_*^2}{2} + \frac{\Vert x_k-x_{k+1} \Vert^2}{2}.
  \end{align}
\end{frame}

\begin{frame}
  \frametitle{Proof III}
  We assumed strong convexity of $h$:
  \begin{align}
    D(x_{k+1}, x_k) \ge \frac12 \Vert x_{k+1}-x_k \Vert^2.
  \end{align}
  Yields
  \begin{align}
    D(x^*, x_{k+1}) \le  D(x^*, x_k) + \alpha (f(x^*)-f(x_k))  + \frac{\alpha^2 \Vert g_k \Vert_*^2}{2} \\
  \end{align}
  Continue as always
  \begin{align}
    \frac{1}{k} \sum_{i=1}^{k} f(x_i) - f^* \le \frac{D(x^*, x_0)}{\alpha k}
    \frac{\alpha G^2}{2} \\
  \end{align}
\end{frame}

\begin{frame}
  \frametitle{What about the smooth case}

  \begin{itemize}
    \item Talked about how to get better constants in the ``bounded subgradients'' setting
    \item but can't make them bounded if they are not
  \end{itemize}
  However,
  \begin{itemize}
    \item Can also come up with a new notion of smoothness
          \begin{align}
            f(y) \le f(x) + \langle \nabla f(x), y-x \rangle + L D(y, x)
          \end{align}
    \item which might hold even if $f$ is not smooth in classical sense
  \end{itemize}

\end{frame}

\end{document}


\documentclass[a4paper]{article}
% \usepackage[margin=1.25in]{geometry}
\usepackage[inner=2.0cm,outer=2.0cm,top=2.5cm,bottom=2.5cm]{geometry}
% \usepackage{ctex}
\usepackage{color}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{bm}
\usepackage{hyperref}
\usepackage{multirow}
\usepackage{mathtools}
\usepackage{enumerate}
\usepackage{algorithm}
\usepackage{algorithmic}

\newcommand{\homework}[5]{
    \pagestyle{myheadings}
    \thispagestyle{plain}
    \newpage
    \setcounter{page}{1}
    \noindent
    \begin{center}
    \framebox{
        \vbox{\vspace{2mm}
        \hbox to 6.28in { {\bf Optimization Methods \hfill #2} }
        \vspace{6mm}
        \hbox to 6.28in { {\Large \hfill #1 \hfill} }
        \vspace{6mm}
        \hbox to 6.28in { {\it Instructor: {\rm #3} \hfill Name: {\rm #4}, StudentId: {\rm #5}}}
        \vspace{2mm}}
    }
    \end{center}
    % \markboth{#4 -- #1}{#4 -- #1}
    \vspace*{4mm}
}

\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}

\newenvironment{solution}
{\color{blue} \paragraph{Solution.\\}}
{\newline \qed}

\begin{document}
%==========================Put your name and id here==========================
\homework{Homework 3}{Fall 2019}{Lijun Zhang}{Li Weikang}{181220031}

\paragraph{Notice}
\begin{itemize}
    \item The submission email is: \textbf{njuoptfall2019@163.com}.
    \item Please use the provided \LaTeX{} file as a template. If you are not familiar with \LaTeX{}, you can also use Word to generate a \textbf{PDF} file.
\end{itemize}
\paragraph{Problem 1: Equality Constrained Least-squares}
~\\
Consider the equality constrained least-squares problem
\begin{gather*}
\begin{matrix}
\text{minimize~~} & \frac{1}{2}\|Ax-b\|_2^2\\
\text{subject to} & Gx=h~~\\
\end{matrix}
\end{gather*}
where $A\in\mathbf{R}^{m\times n}$ with $\mathbf{rank}~A=n$, and $G\in\mathbf{R}^{p\times n}$ with $\mathbf{rank}~G=p$.
\begin{enumerate}[a)]
    \item Derive the Lagrange dual problem with Lagrange multiplier vector $v$.
    \item Derive expressions for the primal solution $x^\star$ and the dual solution $v^\star$.
\end{enumerate}
\begin{solution}
a) It is easy to see that the Lagrangian is
\begin{equation}\nonumber
\begin{aligned}
	\mathcal{L}(x,v) \ &=\  \frac{1}{2}\|Ax-b\|_2^2+v^T(Gx-h)\\ \ &=\ \frac{1}{2} x^TA^TAx + (G^Tv - A^Tb)^Tx - v^Th + \frac{1}{2} b^Tb,
\end{aligned}
\end{equation}
with minimizer $x=-(A^TA)^{-1}(G^Tv-A^Tb)$. Accordingly the dual function is $$g(v)=-\frac{1}{2}(G^Tv-2A^Tb)^T(A^TA)^{-1}(G^Tv-2A^Tb)-v^Th+\frac{1}{2}b^Tb$$
Therefore, the Lagrange dual problem can be described as
\begin{gather*}
\begin{matrix}
\text{maximize~~} & -\frac{1}{2}(G^Tv-2A^Tb)^T(A^TA)^{-1}(G^Tv-2A^Tb)-v^Th+\frac{1}{2}b^Tb
\end{matrix}
\end{gather*}
\quad b) The KKT optimality conditions are $$A^T(Ax^*-b)+G^Tv^*=0,\quad Gx^*=h.$$
From the first equation, $$x^*=(A^TA)^{-1}(A^Tb-G^Tv^*).$$ Plugging this expression for $x^*$ into the second equation gives $$G(A^TA)^{-1}A^Tb-G(A^TA)^{-1}G^Tv^*=h$$ $i.e.,$ $$v^*=-(G(A^TA)^{-1}G^T)^{-1}(h-G(A^TA)^{-1}A^Tb).$$ Substituting in the first expression gives an analytical expression for $x^*$.
\end{solution}

\paragraph{Problem 2: Support Vector Machines}
~\\
Consider the following optimization problem
\begin{gather*}
\begin{matrix}
\text{minimize~~} & \sum_{i=1}^n\max\left(0,1-y_i(w^Tx_i+b)\right)+\frac{\lambda}{2}\|w\|_2^2\\
\end{matrix}
\end{gather*}
where $x_i\in\mathbf{R}^{d},y_i\in \mathbf{R},i=1,\cdots,n$ are given, and $w\in \mathbf{R}^d,b\in\mathbf{R}$ are the variables.
\begin{enumerate}[a)]
    \item Derive an equivalent problem by introducing new variables $u_i,i=1,\cdots,n$ and equality constraints \[u_i=y_i(w^Tx_i+b),i=1,\cdots,n.\]
    \item Derive the Lagrange dual problem of the above equivalent problem.
    \item Give the Karush-Kuhn-Tucker conditions.
\end{enumerate}

\noindent\emph{Hint: Let $\ell(x)=\max(0,1-x)$. Its conjugate function $\ell^\ast(y)=\sup\limits_{x}(yx-\ell(x))=\left\{
\begin{aligned}
&y, \quad-1\leq y\leq0 \\
&\infty,\quad\text{otherwise}
\end{aligned}
\right.$}
\begin{solution}
a) We plug the equality constraints into the original problem to derive the equivalent problem
\begin{gather*}
\begin{matrix}
\text{minimize~~} &\sum_{i=1}^n\max\left(0,1-u_i\right)+\frac{\lambda}{2}\|w\|_2^2\\
\text{subject to} &u_i=y_i(w^Tx_i+b),\quad i=1,\cdots,n.~~\\
\end{matrix}
\end{gather*}
\quad b) From the equivalent problem above we derive its Lagrangian
$$\mathcal{L}(w,b,u,v)=\sum_{i=1}^n\max\left(0,1-u_i\right)+\frac{\lambda}{2}\|w\|_2^2+\sum_{i=1}^nv_i(u_i-y_i(w^Tx_i+b))$$
Thus, the Lagrangian dual function is
\begin{equation}\nonumber
\begin{aligned}
g(v)&=\inf_{w,b,u}\sum_{i=1}^n\max\left(0,1-u_i\right)+\frac{\lambda}{2}\|w\|_2^2+\sum_{i=1}^nv_i(u_i-y_i(w^Tx_i+b))\\ &=\ \inf_{u}\sum_{i=1}^n\left[\max\left(0,1-u_i\right)+v_iu_i\right]+\frac{1}{2\lambda}\|\sum_{i=1}^nv_ix_iy_i\|^2-\sum_{i=1}^n\frac{v_iy_i}{\lambda}\sum_{j=1}^nv_jx_j^Tx_i2y_j
\end{aligned}
\end{equation}
Here we introduce $\ell(x)=\max(0,1-x)$. \\And its conjugate function $\ell^\ast(y)=\sup\limits_{x}(yx-\ell(x))=\left\{
\begin{aligned}
&y, \quad-1\leq y\leq0 \\
&\infty,\quad\text{otherwise}
\end{aligned}
\right.$\\
Therefore,
\begin{equation}\nonumber
\begin{aligned}
g(v) &= \inf_{u}\sum_{i=1}^n\left[\ell(u_i)+v_iu_i\right]+\frac{1}{2\lambda}\|\sum_{i=1}^nv_ix_iy_i\|^2-\sum_{i=1}^n\frac{v_iy_i}{\lambda}\sum_{j=1}^nv_jx_j^Tx_iy_j\\ &= -\sup_u\sum_{i=1}^n\left[-v_iu_i-\ell(u_i)\right]+\frac{1}{2\lambda}\|\sum_{i=1}^nv_ix_iy_i\|^2-\sum_{i=1}^n\frac{v_iy_i}{\lambda}\sum_{j=1}^nv_jx_j^Tx_iy_j\\ &= -\sum_{i=1}^n\sup_u\left[-v_iu_i-\ell(u_i)\right]+\frac{1}{2\lambda}\|\sum_{i=1}^nv_ix_iy_i\|^2-\sum_{i=1}^n\frac{v_iy_i}{\lambda}\sum_{j=1}^nv_jx_j^Tx_iy_j\\ &= \sum_{i=1}^nv_i+\frac{1}{2\lambda}\|\sum_{i=1}^nv_ix_iy_i\|^2-\sum_{i=1}^n\frac{v_iy_i}{\lambda}\sum_{j=1}^nv_jx_j^Tx_iy_j\\
\end{aligned}
\end{equation}
where $0 \leq v_i \leq 1.$\\
Finally, the Lagrangian dual problem is
\begin{gather*}
\begin{matrix}
\text{maximize~~} &\sum_{i=1}^nv_i+\frac{1}{2\lambda}\|\sum_{i=1}^nv_ix_iy_i\|^2-\sum_{i=1}^n\frac{v_iy_i}{\lambda}\sum_{j=1}^nv_jx_j^Tx_iy_j\\
\text{subject to} &\sum_{i=1}^nv_iy_i=0,\\&0 \leq v_i \leq 1.~~\\
\end{matrix}
\end{gather*}
\quad c) The KKT optimality conditions are:
$$u_i^*=y_i({w^*}^Tx_i+b^*),i=1,\cdots,n.$$
$$\nabla\sum_{i=1}^n\max\left(0,1-u_i^*\right)+\frac{\lambda}{2}\|w^*\|_2^2+\nabla\sum_{i=1}^nv_i(u_i^*-y_i({w^*}^Tx_i+b^*))=0.$$
\end{solution}

\paragraph{Problem 3: Euclidean Projection onto the Simplex}
~\\
Consider the following optimization problem
\begin{gather*}
\begin{matrix}
\text{minimize~~} & \frac{1}{2}\left\|y-x\right\|^2_2\quad\\
\text{subject to} & \mathbf{1}^Ty=r\quad\quad\\
&y\succeq0\quad\quad\quad
\end{matrix}
\end{gather*}
where $r>0$, $x\in \mathbb{R}^n$ is given, and $y\in \mathbf{R}^n$ is the variable. Give an algorithm to solve this problem and prove the correctness of your algorithm.

\noindent\emph{Hint: Derive the Lagrangian of this problem and apply the Karush-Kuhn-Tucker conditions. If you need more hints, please read the following paper \cite{Wang2013}}
\begin{solution}
	To begin with, we put forward an efficient algorithm to solve the problem.
\begin{algorithm}[!h]
	\caption{Euclidean projection of a vector onto the probability simplex.}
	\begin{algorithmic} \color{blue}
		\REQUIRE $\textbf{x} \in \mathbb{R}^n$
		\STATE Sort \textbf{x} into \textbf{u}: $u_1 \geq u_2 \geq \cdots \geq u_n$
		\STATE Find $\rho$ = $\max\{1 \leq j \leq n: u_j+\frac{1}{j}(r - \sum_{i=1}^ju_i)>0\}$
		\STATE Define $\lambda=\frac{1}{\rho}(r - \sum_{i=1}^\rho u_i)$
		\ENSURE $\textbf{y}\ \mathrm{s.t.}\ y_i = \max\{x_i+\lambda, 0\},i=1,\dots ,n.$
	\end{algorithmic}
\end{algorithm}\\
$\textit{Proof.}$ The Lagrangian of the problem is
	$$\mathcal{L}(\mathbf{y},\lambda,\beta)=\frac{1}{2}\|y-x\|_2^2-\lambda(\mathbf{1}^Ty-r)-\beta^Ty$$ where $\lambda$ and $\mathbf{\beta}=[\beta_1,\dots,\beta_n]^T$ are the Lagrange multipliers for the constraints. At the optimal solution $\mathbf{y}$ the following KKT conditions hold:
\begin{align}
	y_i-x_i-\lambda-\beta_i &= 0,\qquad i = 1,\dots,n\\
	y_i & \geq 0,\qquad i = 1,\dots,n\\
	\beta_i &\geq 0,\qquad i = 1,\dots,n\\
	y_i\beta_i &= 0,\qquad i = 1,\dots,n\\
	\sum_{i=1}^ny_i &= r.
\end{align}
From the condition (4), it is trivial that if $y_i > 0$, we must have $\beta_i=0$ and $y_i=x_i+\lambda$; if $y_i = 0$, we must have $\beta_i \geq 0$ and $y_i=x_i+\lambda+\beta_i=0$, thus $x_i+\lambda=-\beta_i \leq 0$. It is obvious that the components of the optimal solution $\textbf{y}$ that are zeros correspond to the smaller components of $\textbf{x}$. Without loss of generality, we assume the components of $\textbf{x}$ are sorted and $\textbf{y}$ uses the same ordering, i.e.,
\begin{equation}\nonumber
\begin{aligned}
	&x_1\geq \cdots \geq x_\rho \geq x_\rho+1 \geq \cdots \geq x_n,
	\\&y_1\geq \cdots \geq y_\rho > y_\rho+1 = \cdots = y_n,
\end{aligned}
\end{equation}
and that $y_1\geq \cdots \geq y_\rho > 0$, $y_\rho+1 = \cdots = y_n=0$ In other words, $\rho$ is the number of positive components in the solution $\textbf{y}$. Now we apply the last condition and have
$$r=\sum_{i=1}^ny_i=\sum_{i=1}^\rho y_i=\sum_{i=1}^\rho (x_i+\lambda)$$
which gives $\lambda=\frac{1}{\rho}\left(r-\sum_{i=1}^\rho x_i \right)$. Hence $\rho$ is the key to the solution. And once we know $\rho$(there are only $n$ possible values of it), we can compute $\lambda$ and the optimal solution is obtained by just adding $\lambda$ to each component of $\textbf{x}$ and thresholding as in the end of Algorithm 1.(It is easy to check that this solution indeed satisfies all KKT conditions.) In the algorithm, we carry out the tests for $j=1,\dots,n$ if $t_j=x_j+\frac{1}{j}\left(r-\sum_{i=1}^j x_i\right)>0 $ We now prove that the number of times this test turns out positive is exactly $\rho$. The following theorem is essentially Lemma 3 of Shalev-Shwartz and Singer (2006).\\
$\textit{Theorem }$1. Let $\rho$ be the number of positive components in the solution \textbf{y}, then
$$\rho=\max\{1\leq j\leq n: x_j+\frac{1}{j}(r-\sum_{i=1}^j x_i)>0\}.$$
$\textit{Proof.}$ From the KKT condition (2) we have that $\lambda\rho=\left(r-\sum_{i=1}^\rho x_i \right)$, $x_i+\lambda >0$ for $i=1,\dots,\rho$ and $x_i+\lambda \leq 0$ for $i=\rho+1,\dots,n.$ In the sequel, we know that for $j=1,\dots,n,$ the test will continue to be positive until $j=\rho$ and then stay non-positive afterwards, i.e., $x_j+\frac{1}{j}\left(r-\sum_{i=1}^j x_i\right)>0$ for $j\leq\rho$, and $x_j+\frac{1}{j}\left(r-\sum_{i=1}^j x_i\right)\leq 0$ for $j>\rho.$
\begin{enumerate} [(i)]
\item For $j=\rho$, we have
$$x_\rho+\frac{1}{\rho}\left(r-\sum_{i=1}^\rho x_i\right)=x_\rho+\lambda=y_\rho>0$$
\item For $j<\rho$, we have
\begin{equation}\nonumber
\begin{aligned}
x_j+\frac{1}{j}\left(r-\sum_{i=1}^j x_i\right)=\frac{1}{j}(jx	_j+r-\sum_{i=1}^j x_i)=\frac{1}{j}\left(jx_j+\sum_{i=j+1}^\rho x_i+r-\sum_{i=1}^\rho x_i\right)=\frac{1}{j}\left(jx_j+\sum_{i=j+1}^\rho x_i+\rho\lambda\right) \\ =\frac{1}{j}\left(j(x_j+\lambda)+\sum_{i=j+1}^\rho(x_i+\lambda)\right).
\end{aligned}
\end{equation}
Since $x_i+\lambda>0$ for $i=j,\dots,\rho,$ we have $x_j+\frac{1}{j}(r-\sum_{i=1}^jx_i)>0.$
\item For $j>\rho ,$ we have
\begin{equation}\nonumber
\begin{aligned}
x_j+\frac{1}{j}\left(r-\sum_{i=1}^j x_i\right)=\frac{1}{j}(jx_j+r-\sum_{i=1}^j x_i)=\frac{1}{j}\left(jx_j+r-\sum_{i=1}^\rho x_i-\sum_{i=\rho +1}^j x_i\right)=\frac{1}{j}\left(jx_j+\rho\lambda-\sum_{i=\rho+1}^j x_i\right) \\ =\frac{1}{j}\left(\rho(x_j+\lambda)+\sum_{i=\rho+1}^j(x_j-x_i)\right).
\end{aligned}
\end{equation}
\end{enumerate}
\qquad Notice that $x_j+\lambda\leq 0$ for $j>\rho$, and $x_j\leq x_i$ for $j\geq i$ since $\textbf{x}$ is sorted, therefore $x_j+\frac{1}{j}(1-\sum_{i=1}^jx_i)<0.$
\end{solution}

\paragraph{Problem 4: Optimality Conditions}
~\\
Consider the problem
\begin{equation*}
    \begin{split}
        &\text{minimize~~} \quad  \text{tr}(2X) - \log{\det{(3X)}} \\
        &\text{subject to} \quad~  2Xs=y
    \end{split}
\end{equation*}
with variable $X \in \mathbf{S}^n$ and domain $\mathbf{S}_{++}^n$. Here, $y \in \mathbf{R}^n$ and $s \in \mathbf{R}^n$ are given, with $s^T y =1$.
\begin{enumerate}[a)]
    \item Give the Lagrange and then derive the Karush-Kuhn-Tucker conditions.
    \item Verify that the optimal solution is given by
\

    \begin{equation*}
        X^\star = \frac{1}{2} \left(I + yy^T - \frac{ss^T}{s^T s}\right) .
    \end{equation*}
\end{enumerate}

\begin{solution}
We introduce a Lagrange multiplier $z \in \mathbf{R}^n$ for the equality constraint.\\
According to the properties of \textbf{trace}, $\nabla_A\text{tr}(AB)=\nabla_A\text{tr}(BA)=B^T.$ \\Thus, we have:
$$\nabla_X\text{tr}(nX)=n\nabla_X\text{tr}(IX)=nI$$
Refer to the proof in \textbf{section A.4.1} of the book Stephen Boyd, Lieven Vandenberghe, Convex Optimization, we have:
$$\nabla_X\text{log det} X=X^{-1}$$
The KKT optimality conditions are:
$$X \succ 0,\quad 2Xs=y, \quad X^{-1}=2I+zs^T+sz^T.\eqno{(1)}$$
We first determine $z$ from the condition $2Xs=y.$ Multiplying the gradient equation on the right with y gives
$$s=\frac{1}{2}X^{-1}y=y+\frac{1}{2}(z+(z^Ty)s).\eqno{(2)}$$
By taking the inner product with y on both sides and simplifying, we get $z^Ty=1-y^Ty.$\\ Substituting in (2) we get $$z=-2y+(1+y^Ty)s,$$ and substitute this expression for $z$ in (1) gives
\begin{equation}\nonumber
\begin{aligned}
X^{-1} \ &= \ 2(I -ys^T-sy^T+(1+y^Ty)ss^T)
\end{aligned}\
\end{equation}
Finally we verify that this inverse of the matrix $X^*$ given above:
\begin{equation}\nonumber
\begin{aligned}
2(I -ys^T-sy^T+(1+y^Ty)ss^T)X^* &= \ (I+yy^T-(1/s^Ts)ss^T)+(1+y^Ty)(ss^T+sy^T-ss^T)\\ &\quad \  -(ys^T+yy^T-ys^T)-(sy^T+(y^Ty)sy^T-(1/s^Ts)ss^T)\\ &= \ I
\end{aligned}
\end{equation}
To complete the solution, we prove that $X^* \succ 0.$ An easy way to see this is to note that  $$X^\star = \frac{1}{2} \left(I + yy^T - \frac{ss^T}{s^T s}\right) = \frac{1}{2}\left(I+ \frac{ys^T}{\|s\|_2}-\frac{ss^T}{s^Ts}\right)\left(I+ \frac{ys^T}{\|s\|_2}-\frac{ss^T}{s^Ts}\right)^T.$$
\end{solution}

\begin{thebibliography}{1}

\bibitem{Wang2013}
Weiran Wang, and Miguel \'{A}. Carreira-Peroi\~{n}\'{a}n.
\newblock Projection onto the probability simplex: An efficient algorithm with a simple proof, and an application.
\newblock \emph{arXiv:1309.1541}, 2013.

\end{thebibliography}

\end{document}


\documentclass[revision-guide.tex]{subfiles}
\setcounter{chapter}{9}
%% Current Author: CJRU
\begin{document}

\chapter{Rotational Mechanics}

This chapter contains revision on the topics of:

\begin {itemize}
\item kinematics of uniform circular motion
\item centripetal acceleration
\item moments of inertia
\item kinematics of rotational motion
\end {itemize}

\textbf{Candidates should be able to:}

\spec{Define and use the radian}

An angle in radians is defined by the length of the arc of circle it subtends divided by the radius of the circle. Numerically $2\pi$ radians is equivalent to 360 degrees.

\spec{Understand the concept of angular velocity, and recall and use the equations $v = r \omega $
 and $T = \frac{2\pi}{\omega}$
}

These equations are valid for an object travelling in a circle in a uniform manner.

Angular velocity is defined as the rate of change of angle, $\omega = \frac{d\theta}{dt}$ ie how many radians per second the rotating object passes through. Hence the time for one complete rotation will be $T = \frac{2\pi}{\omega}$

\begin{figure}[h]
	\begin{center}
		\begin{tikzpicture}[remember picture]
		\draw [very thick,gray](0.225,0.5) arc (65:92:0.5);
		\draw[very thick, black, ->] (0,2.5) -- node[below] {$\mathbf{\delta s}$}  (1,2.3);
		\draw[very thick, purple, -] (0,0) -- node[left] {$\mathbf{r}$} (0,2.5);
		\draw[very thick, purple, -] (0,0) -- node[right]{$\mathbf{r}$} (1,2.3);
		\draw [gray](-0.1,1) node[right]{$\delta\theta$};

		\draw (0,0) circle (2.5cm);
		\end{tikzpicture}
	\end{center}
	\caption{}
\end{figure}

From the definition of the radian, in a small time interval $\delta t$ we can say that the displacement of the rotating object is $\delta s \approx r\delta\theta$ (see figure 10.1), and hence in the limit as we make the time interval smaller that means $v=\frac{ds}{dt} = r\frac{d\theta}{dt}=r\omega$

\begin{example}
	Calculate the linear velocity of the Earth relative to the sun, given the Earth-Sun distance is 1.5 x $10^{11} $m

\answer First calculate the angular velocity of the Earth. It performs a complete orbit (ie $2\pi$ radians) in 1 year, so $\omega= \frac{2\pi}{365\times24\times3600}$

Then $v=r\omega$ = 30000 $ms^{-1}$
\end{example}
\spec{
	Derive, recall and use the equations for centripetal acceleration $a = \frac{v ^{2}}{r}$ and $a = r\omega ^{2}$
}

Since acceleration is defined as change in velocity, we can see from the following diagram (figure 10.2) that the velocity change when a uniformly rotating object moves through a small angle $\delta\theta$ can be written as $\delta v = v\delta\theta$ since the magnitudes of the initial and final velocity are both equal to v.
\\
\\

\begin{figure}[h]
	\begin{center}
		\begin{tikzpicture}
		\draw [very thick,gray](0.225,0.5) arc (65:92:0.5);
		\draw[very thick, black, ->] (0,2.5) -- node[above] {$\mathbf{v_i}$}  (1,2.5);
		\draw[very thick, black, ->] (1,2.3) -- node[below] {$\mathbf{v_f}$}  (1.8,1.9);
		\draw[very thick, purple, -] (0,0) -- node[left] {} (0,2.5);
		\draw[very thick, purple, -] (0,0) -- node[right] {} (1,2.3);
		\draw [gray](-0.1,1) node[right]{$\delta\theta$};

		\draw (0,0) circle (2.5cm);

		\draw [very thick,gray](7,0) arc (180:150:1);

		\draw[very thick, black, ->] (8,0) -- node[below] {$\mathbf{-v_i}$}  (4,0);
		\draw[very thick, black, ->] (4.6,2) -- node[above] {$\mathbf{v_f}$}  (8,0);
		\draw[very thick, purple, ->] (4.6,2) -- node[left] {$\mathbf{\delta v}$} (4,0);
		\draw [gray](6.4,0.35) node[right]{$\delta\theta$};

		\draw [black](4,-1) node[right]{$\mathbf{-v_i}$ and $\mathbf{-v_f}$ both have magnitude $v$, };
		\draw [black](4,-1.5) node[right] {therefore $\delta v = v \delta\theta$};
		\end{tikzpicture}
	\end{center}
	\caption{}
\end{figure}

The acceleration is therefore $a\approx\frac{v\delta\theta}{\delta t}$ and as we let $\delta t\rightarrow0$ we get $a=v\frac{d\theta}{dt}=v\omega$.
\\
since $v=r\omega$ we also get $a=\frac{v^2}{r}=r\omega^2$

\spec{Recall that F = ma applied to circular motion gives resultant $F=\frac{mv^2}{r}$}

Since $a = \frac{v ^{2}}{r}$ and $F=ma$ we can combine these to give $F=\frac{mv^2}{r}$. This can be very useful for example when combined with Newton's law of Gravity to explain planetary orbits etc.
\\
\\

\begin{example}
	Show that, for a circular orbit, the time period squared is proportional to the radius cubed.

 	\answer Start by equating $F=mr\omega^2$ with $F= \frac{GMm}{r^2}$ (we can ignore the minus sign)
\\

$mr\omega^{2}= \frac{GMm}{r^2}$
\\
\\
Then rearrange and cancel $m$ to find
\\
\\
$r^{3}=\frac{GM}{\omega^2}$
\\
\\
then using $\omega=\frac{2\pi}{T}$ we get
\\
\\
$r^{3}=\frac{GM}{4\pi^{2}}T^2$

\end{example}

\spec{Describe qualitatively the motion of a rigid solid object under the influence of a single force in terms of
linear acceleration and rotational acceleration.}

When a rigid solid object has a single force applied to it, it may just result in linear acceleration, if the force acts through the centre of mass of the object. However it is more likely that the force will not act through this point, and therefore also cause some rotational acceleration, causing the object's angular velocity to change.
\\
\\
The remaining sections in this chapter deal with how we describe this rotational acceleration, but it should be noted that they are asterisked sections so will only form part of section 2 of paper 3.

\
\spec{*Recall and use $I = \Sigma mr^2$ to calculate the moment of inertia of a body consisting of three or fewer point
particles fixed together}

The moment of inertia of a body is the rotational analogue of mass, and basically describes how resistant an object is to angular acceleration when a torque is applied (in the same way that mass describes how resistant an object is to accelerating linearly when a force is applied...)

A point mass $m$ at a distance $r$ from an axis of rotation will have Moment of Inertia $I=mr^2$

More generally the moment of inertia is the sum of all the $mr^2$ values for all the point masses that make up an object. For a small number of particles this can just be found by adding the values of individual moments of inertia.
\\
\spec{*Use integration to calculate the moment of inertia of a ring, a disk and a rod}

For more complex bodies, the summing of moments of inertia needs to be done by setting up an integration. This is acheived by summing moments of inertia for a series of small sections of the object, strips or rings of thickness $\delta x$ say, and using the fact that as $\delta x \rightarrow0$ the sum $\Sigma \delta x \equiv \int dx$

As an example, consider a disk of radius r , thickness t and density $\rho$. The moment of inertia about its central axis could be found by splitting it up into rings of radius $x$ and thickness $\delta x$. See figure 10.3.
\\
\begin{figure}[h]
	\begin{center}
		\begin{tikzpicture}
		\draw[very thick, gray, ->] (0,0) -- node[left] {{axis of rotation}}  (0,5);

	\draw[very thick, purple, ->] (0,0) -- node[below] {$x$} (-2.2,0.5);
	\draw[very thick, purple, <->] (-3.2,0) -- node[left] {$\delta x$} (-3.0,0);
	\draw[very thick, green, ->] (0,0) -- node[above] {$r$} (4.0,0);
		\draw (0,0) ellipse (4cm and 1cm);
		\draw (0,0) ellipse (3cm and 0.75cm);
		\draw (0,0) ellipse (3.2cm and 0.8cm);
		\end{tikzpicture}
		\caption{}
	\end{center}
\end{figure}

Each ring has moment of inertia equal to its mass multiplied by $x^2$, as all the particles in it have (approximately) the same distance from the axis.\footnote{This can be proved by another, much simpler, sum. If you imagine the ring as the sum of many small points of mass $\delta m$ each at the same radius $r$, the moment of inertia becomes $\Sigma r^{2}\delta m$ which is the same as $r^{2}\Sigma \delta m$ and hence $I=mr^2$}
\\

Hence $I_{ring}= (2\pi x t \rho\delta x )x^2 = 2\pi \rho x^{3} \delta x$
\\

To find the moment of inertia of the disk, we sum all the rings and let their size $\delta x$ tend to 0.

$I_{disk}= \Sigma 2\pi \rho x^{3} \delta x$
\\

$I_{disk}= \int\displaylimits_0^r 2\pi \rho  t x^{3}\delta x $
\\

giving
\\

$I_{disk} = \frac{2\pi\rho t r^4}{4}$
\\

which is equal to

$I_{disk} = \frac{mr^2}{2}$
\\

Other objects would be derived in a similar way. You should get $I=\frac{mr^2}{3}$ for a rod rotating about one end, and $I =\frac{mr^2}{12}$ for a rod rotating about its centre of mass.
\\

\spec{*Deduce equations for rotational motion by analogy with Newton’s laws for linear motion, including
$E =\frac{1}{2}I\omega ^2$, $ L = I\omega$ and $\Gamma=I \frac{d\omega}{dt}$}

Here is a table outlining the analogies between linear and rotational moton:
\\

\begin{center}
	\begin{tabular}{||c c||}
		\hline
		\textbf{Linear Motion} & \textbf{Rotational Motion}\\ [0.5ex]
		\hline\hline
		 Mass m &Moment of Inertia I\\
		\hline
		linear velocity v &Angular velocity $\omega$\\
		\hline
		Force F & Torque $\Gamma$ \\
		\hline
		Linear Momentum p  & Angular Momentum L \\
		\hline
		$p=mv$ & $ L = I\omega$  \\
		\hline
		$F=ma =m\frac{dv}{dt}$ & $\Gamma=I \frac{d\omega}{dt}$ \\
		\hline
		$KE_{linear}=\frac{1}{2}mv^2$ & $KE_{rotational} =\frac{1}{2}I\omega ^2$\\ [1ex]
		\hline
	\end{tabular}
\end{center}

\
\spec{*Apply the laws of rotational motion to perform kinematic calculations regarding a rotating object when
the moment of inertia is given.}

\begin{example}
	The moment of inertia of a large flywheel in a factory is 60 kgm$^2$. Calculate how long it would take the flywheel to obtain an angular velocity of 6.0 rad s$^{-1}$ when a torque of 24 Nm was applied.
	\answer
First use $\Gamma=I \frac{d\omega}{dt}$ to find the angular acceleration:

$\frac{d\omega}{dt}=\frac{\Gamma}{I}=\frac{24}{60}= 0.4$ rad s$^{-2}$

Then the time taken will be

$T=\frac{6}{0.4}=15$ seconds
\end{example}
\end{document}


% Like most advanced LaTeX files, this one begins with a lot of
% boilerplate. You don't need to understand (or even read) most of it.
% All you need to do is fill in your name, UMN ID, email address,
% and the number of the pset. (Search for "METADATA" to find the place
% for this.) Then, you can go straight to the "EXERCISE 1"
% section and start writing your solutions.
% The "VARIOUS USEFUL COMMANDS" section is probably worth taking a
% look at at some point.

%----------------------------------------------------------------------------------------
%	PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[paper=a4, fontsize=12pt]{scrartcl} % A4 paper and 12pt font size
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amsthm,amssymb} % Math packages
\usepackage{mathrsfs}    % More math packages
\usepackage{sectsty}  % Allows customizing section commands
\allsectionsfont{\centering \normalfont\scshape} % Make all section titles centered, the default font and small caps %remove this to left align section tites
\usepackage{hyperref} % Turns cross-references into hyperlinks,
                      % and defines \url and \href commands.
\usepackage{graphicx} % For embedding graphics files.
\usepackage{framed}   % For the "leftbar" environment used below.
\usepackage{ifthen}   % Used for the \powset command below.
\usepackage{lastpage} % for counting the number of pages
\usepackage[headsepline,footsepline,manualmark]{scrlayer-scrpage}
\usepackage[height=10in,a4paper,hmargin={1in,0.8in}]{geometry}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}     % This is a powerful tool to draw vector
                      % graphics inside LaTeX. In particular, you can
                      % use it to draw graphs.
\usepackage{verbatim} % For the "verbatim" environment, in which
                      % special symbols can be used freely without
                      % confusing the compiler. (And it's typeset in
                      % a constant-width font.)
                      % Useful, e.g., for quoting code (or ASCII art).

%\numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)

\setlength\parindent{20pt} % Makes indentation for paragraphs longer.
                           % This makes paragraphs stand out more.

%----------------------------------------------------------------------------------------
%	VARIOUS USEFUL COMMANDS
%----------------------------------------------------------------------------------------
% The commands below might be convenient. For example, you probably
% prefer to write $\powset[2]{V}$ for the set of $2$-element subsets
% of $V$, rather than writing $\mathcal{P}_2(V)$.
% Notice that you can easily define your own commands like this.
% Caveat: Some of these commands need to be properly "guarded" when
% they occur in subscripts or superscripts. So you should not write
% $K_\CC$, but rather $K_{\CC}$.
\newcommand{\CC}{\mathbb{C}} % complex numbers
\newcommand{\RR}{\mathbb{R}} % real numbers
\newcommand{\QQ}{\mathbb{Q}} % rational numbers
\newcommand{\NN}{\mathbb{N}} % nonnegative integers
\newcommand{\DD}{{\mathbb{D}}} % dual numbers
\newcommand{\PP}{\mathbb{P}} % positive integers
\newcommand{\Z}[1]{\mathbb{Z}/#1\mathbb{Z}} % integers modulo k
                                            % (syntax: "\Z{k}")
\newcommand{\ZZ}{\mathbb{Z}} % integers
\newcommand{\id}{\operatorname{id}} % identity map
\newcommand{\lcm}{\operatorname{lcm}}
% Lowest common multiple. For historical reasons, LaTeX has a \gcd
% command built in, but not an \lcm command. The preceding line
% rectifies that.
\newcommand{\set}[1]{\left\{ #1 \right\}}
% $\set{...}$ compiles to {...} (set-brackets).
\newcommand{\abs}[1]{\left| #1 \right|}
% $\abs{...}$ compiles to |...| (absolute value, or size of a set).
\newcommand{\tup}[1]{\left( #1 \right)}
% $\tup{...}$ compiles to (...) (parentheses, or tuple-brackets).
\newcommand{\ive}[1]{\left[ #1 \right]}
% $\ive{...}$ compiles to [...] (Iverson bracket, aka truth value; also, set of first n integers).
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
% $\floor{...}$ compiles to |_..._| (floor function).
\newcommand{\underbrack}[2]{\underbrace{#1}_{\substack{#2}}}
% $\underbrack{...1}{...2}$ yields
% $\underbrace{...1}_{\substack{...2}}$. This is useful for doing
% local rewriting transformations on mathematical expressions with
% justifications. For example, try this out:
% $ \underbrack{(a+b)^2}{= a^2 + 2ab + b^2 \\ \text{(by the binomial formula)}} $
\newcommand{\powset}[2][]{\ifthenelse{\equal{#2}{}}{\mathcal{P}\left(#1\right)}{\mathcal{P}_{#1}\left(#2\right)}}
% $\powset[k]{S}$ stands for the set of all $k$-element subsets of
% $S$. The argument $k$ is optional, and if not provided, the result
% is the whole powerset of $S$.
\newcommand{\mapeq}[1]{\underset{#1}{\equiv}}
% $\mapeq{f}$ yields $\underset{f}{\equiv}$.
% This is the "equality upon applying $f$" relation.
\newcommand{\eps}{\varepsilon}
% Just a shorthand for a commonly-used symbol.
\newcommand{\N}{\operatorname{N}} % norm of a complex number
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height
\newcommand{\nnn}{\nonumber\\} % Don't number this line in an "align" environment, and move on to the next line.

%----------------------------------------------------------------------------------------
%	MAKING SUMMATION SIGNS ALWAYS PUT THEIR BOUNDS ABOVE AND BELOW
%	THE SIGN
%----------------------------------------------------------------------------------------
% The following are hacks to ensure that sums (such as
% $\sum_{k=1}^n k$) always put their bounds (i.e., the $k=1$ and the
% $n$) underneath and above the sign, as opposed to on its right.
% Same for products (\prod), set unions (\bigcup) and set
% intersections (\bigcap). Remove the 8 lines below if you do not want
% this behavior.
\let\sumnonlimits\sum
\let\prodnonlimits\prod
\let\cupnonlimits\bigcup
\let\capnonlimits\bigcap
\renewcommand{\sum}{\sumnonlimits\limits}
\renewcommand{\prod}{\prodnonlimits\limits}
\renewcommand{\bigcup}{\cupnonlimits\limits}
\renewcommand{\bigcap}{\capnonlimits\limits}

%----------------------------------------------------------------------------------------
%	ENVIRONMENTS
%----------------------------------------------------------------------------------------
% The incantations below define how theorem environments
% (\begin{theorem} ... \end{theorem}) and their likes will look like.
\newtheoremstyle{plainsl}% <name>
  {8pt plus 2pt minus 4pt}% <Space above>
  {8pt plus 2pt minus 4pt}% <Space below>
  {\slshape}% <Body font>
  {0pt}% <Indent amount>
  {\bfseries}% <Theorem head font>
  {.}% <Punctuation after theorem head>
  {5pt plus 1pt minus 1pt}% <Space after theorem headi>
  {}% <Theorem head spec (can be left empty, meaning `normal')>

% Environments which make the text inside them slanted:
\theoremstyle{plainsl}
  \newtheorem{theorem}{Theorem}[section]
  \newtheorem{proposition}[theorem]{Proposition}
  \newtheorem{lemma}[theorem]{Lemma}
  \newtheorem{corollary}[theorem]{Corollary}
  \newtheorem{conjecture}[theorem]{Conjecture}
% Environments that don't:
\theoremstyle{definition}
  \newtheorem{definition}[theorem]{Definition}
  \newtheorem{example}[theorem]{Example}
  \newtheorem{exercise}[theorem]{Exercise}
  \newtheorem{examples}[theorem]{Examples}
  \newtheorem{algorithm}[theorem]{Algorithm}
  \newtheorem{question}[theorem]{Question}
 \theoremstyle{remark}
  \newtheorem{remark}[theorem]{Remark}
\newenvironment{statement}{\begin{quote}}{\end{quote}}
\newenvironment{fineprint}{\begin{small}}{\end{small}}

%----------------------------------------------------------------------------------------
%	METADATA
%----------------------------------------------------------------------------------------
\newcommand{\myname}{Darij Grinberg} % ENTER YOUR NAME HERE
\newcommand{\myid}{00000000} % ENTER YOUR UMN ID HERE
\newcommand{\mymail}{dgrinber@umn.edu} % ENTER YOUR EMAIL HERE
\newcommand{\psetnumber}{5} % ENTER THE NUMBER OF THIS PSET HERE

%----------------------------------------------------------------------------------------
%	HEADER AND FOOTER
%----------------------------------------------------------------------------------------
\ihead{Solutions to homework set \#\psetnumber} % Page header left
\ohead{page \thepage\ of \pageref{LastPage}} % Page header right
\ifoot{\myname, \myid} % left footer
\ofoot{\mymail} % right footer

%----------------------------------------------------------------------------------------
%	TITLE SECTION
%----------------------------------------------------------------------------------------
\title{
\normalfont \normalsize
\textsc{University of Minnesota, School of Mathematics} \\ [25pt] % Your university, school and/or department name(s)
\horrule{0.5pt} \\[0.4cm] % Thin top horizontal rule
\huge Math 4281: Introduction to Modern Algebra, \\
Spring 2019:
Homework \psetnumber\\% The assignment title
\horrule{2pt} \\[0.5cm] % Thick bottom horizontal rule
}
\author{\myname}

\begin{document}

\maketitle % Print the title

\begin{center} % Delete this if you want to save space!
{\large due date: \textbf{Monday, 1 April 2019} at the beginning of class, \\
or before that by email or canvas.

Please solve \textbf{at most 3 of the 6 exercises}!}
\end{center}

%----------------------------------------------------------------------------------------
%	EXERCISE 1
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 1: Sums of powers of divisors}

\subsection{Problem}

Let $n$ be a positive integer. Let $k \in \NN$.
Prove that
\[
\sum_{d \mid n} d^k
= \prod_{p \text{ prime}} \tup{p^{0k} + p^{1k} + \cdots + p^{v_p\tup{n}\cdot k} }.
\]
Here, the summation sign ``$\sum_{d \mid n}$'' means a sum over
all \textbf{positive} divisors $d$ of $n$.

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 2
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 2: Another version of Jacobi's two-squares theorem}

\subsection{Problem}

Let $n$ be a positive integer.
Prove that
\begin{align*}
& \tup{\text{the number of pairs $\tup{x, y} \in \ZZ^2$ such that $n = x^2 + y^2$}} \\
& = 4 \tup{\text{the number of positive divisors $d$ of $n$ such that $d \equiv 1 \mod 4$}} \\
& \qquad - 4 \tup{\text{the number of positive divisors $d$ of $n$ such that $d \equiv 3 \mod 4$}} .
\end{align*}

[\textbf{Hint:} The formula for the left hand side
that we proved in class can be freely used.]

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 3
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 3: Characterizing Gaussian primes}

\subsection{Problem}

Let $\pi$ be a Gaussian prime.

Prove the following:

\begin{enumerate}

\item[\textbf{(a)}]
If $\pi$ is unit-equivalent to an integer, then $\pi$
is unit-equivalent to a prime\footnote{%
The unqualified word ``prime'' always means a prime in the
original sense, i.e., an integer $p > 1$ whose only positive
divisors are $1$ and $p$.}
of Type 3.

\end{enumerate}

\noindent
(Recall that a prime $p$ is said to be \textit{of Type 3}
if it is congruent to $3$ modulo $4$.)

Assume, from now on, that $\pi$ is \textbf{not}
unit-equivalent to any integer.
Let $\tup{p_1, p_2, \ldots, p_k}$ be a prime factorization
of the positive integer $\N\tup{\pi}$.
(Thus, $p_1, p_2, \ldots, p_k$ are primes such that
$\N\tup{\pi} = p_1 p_2 \cdots p_k$.)

\begin{enumerate}

\item[\textbf{(b)}]
Prove that $\pi \mid p_i$ for some $i \in \set{1, 2, \ldots, k}$.

\end{enumerate}

Fix an $i \in \set{1, 2, \ldots, k}$ such that $\pi \mid p_i$.

\begin{enumerate}

\item[\textbf{(c)}]
Prove that $p_i = \pi \overline{\pi}$.

\item[\textbf{(d)}]
Prove that $p_i$ is a prime of Type 1 or of Type 2.

\end{enumerate}

\noindent
(Recall that a prime $p$ is said to be \textit{of Type 1} if
it is congruent to $1$ modulo $4$,
and is said to be \textit{of Type 2} if it
equals $2$.)

\subsection{Remark}

This exercise yields that the Gaussian primes are the
primes of Type 3 and the Gaussian prime divisors of the
primes of Types 1 and 2 (up to unit-equivalence).
Conversely, any of the latter are indeed Gaussian primes
(as we proved in class).
This completes the characterization of Gaussian primes.

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 4
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 4: Gaussian integers modulo a Gaussian integer}

\subsection{Problem}

For any Gaussian integer $\tau$, we
let $\mapeq{\tau}$ be the binary relation on
$\ZZ\ive{i}$ defined by
\[
\tup{\alpha \mapeq{\tau} \beta}
\ \iff \ \tup{\alpha \equiv \beta \mod \tau} .
\]
It is straightforward to see (just as in the case of
integers) that this relation $\mapeq{\tau}$ is an
equivalence relation.
(You don't need to prove this.)
We shall refer to the equivalence classes of this
relation $\mapeq{\tau}$ as the \textit{Gaussian
residue classes modulo $\tau$};
let $\ZZ\ive{i} / \tau$ be the set of all these classes.

Let $n$ be a nonzero integer.

Prove that the equivalence classes of the relation
$\mapeq{n}$ (on $\ZZ\ive{i}$) are the $n^2$ classes
$\ive{a + bi}_{\mapeq{n}}$ for
$a, b \in \set{0, 1, \ldots, \abs{n}-1}$,
and that these $n^2$ classes are all distinct.

\subsection{Remark}

This exercise yields
$\abs{\ZZ\ive{i} / n} = n^2 = \N\tup{n}$ for any nonzero
integer $n$.
This is \cite[Lemma 7.15]{Conrad-Gauss}.
(Conrad proves this ``by example''; you can follow the
argument but you should write it up in full generality.)

More generally,
$\abs{\ZZ\ive{i} / \tau} = \N\tup{\tau}$
for any nonzero Gaussian integer $\tau$.
This is proven in \cite[Theorem 7.14]{Conrad-Gauss}
(using the above exercise as a stepping stone).

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 5
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 5: A Fibonacci divisibility}

\subsection{Problem}

Let $\phi = \dfrac{1+\sqrt5}{2}$ and $\psi = \dfrac{1-\sqrt5}{2}$
be the two (real) roots of the polynomial $x^2 - x - 1$.
(The number $\phi$ is known as the \textit{golden ratio}.)
It is easy to see that $\phi + \psi = 1$ and $\phi \cdot \psi = -1$.

Let $\ZZ\ive{\phi}$ be the set of all reals of the form
$a + b \phi$ with $a, b \in \ZZ$.

\begin{enumerate}

\item[\textbf{(a)}]
Prove that any $\alpha, \beta \in \ZZ\ive{\phi}$ satisfy
$\alpha + \beta \in \ZZ\ive{\phi}$ and
$\alpha - \beta \in \ZZ\ive{\phi}$ and
$\alpha \beta \in \ZZ\ive{\phi}$.

\end{enumerate}

(In the terminology of abstract algebra, this is saying
that $\ZZ\ive{\phi}$ is a subring of $\RR$.)

\begin{enumerate}

\item[\textbf{(b)}]
Prove that every element of $\ZZ\ive{\phi}$ can be
written as $a + b \phi$ for a \textbf{unique} pair
$\tup{a, b}$ of integers.
(In other words, if four integers $a, b, c, d$
satisfy $a + b \phi = c + d \phi$, then $a = c$
and $b = d$.)

\end{enumerate}

Given two elements $\alpha$ and $\beta$ of $\ZZ\ive{\phi}$,
we say that \textit{$\alpha \mid \beta$ in $\ZZ\ive{\phi}$}
if and only if there exists some $\gamma \in \ZZ\ive{\phi}$
such that $\beta = \alpha \gamma$.
Thus, we have defined divisibility in $\ZZ\ive{\phi}$.
Basic properties of divisibility of integers (such as
Proposition 2.2.4) still apply
to divisibility in $\ZZ\ive{\phi}$ (with the same proofs).

\begin{enumerate}

\item[\textbf{(c)}]
If $a$ and $b$ are two elements of
$\ZZ$ such that $a \mid b$ in $\ZZ\ive{\phi}$,
then prove that $a \mid b$ in $\ZZ$.

\end{enumerate}

Let $\tup{f_0, f_1, f_2, \ldots}$ be the sequence of nonnegative
integers defined recursively by
\[
f_0 = 0, \qquad
f_1 = 1, \qquad \text{and} \qquad
f_n = f_{n-1} + f_{n-2} \text{ for all } n \geq 2 .
\]
This is the so-called \textit{Fibonacci sequence} (and continues
with $f_2 = 1$, $f_3 = 2$, $f_4 = 3$, $f_5 = 5$ etc.).

It is well-known (\textit{Binet's formula}) that
\[
f_n = \dfrac{\phi^n - \psi^n}{\sqrt5}
\qquad \text{for all } n \geq 0 .
\]
(You don't need to prove this; there is a completely
straightforward proof by induction on $n$.)

\begin{enumerate}

\item[\textbf{(d)}]
Prove that $f_d \mid f_{dn}$ for any nonnegative integers
$d$ and $n$.

\end{enumerate}

[\textbf{Hint:} Lemma 2.10.11 \textbf{(a)} holds not just
for integers.]

\subsection{Remark}

This exercise (specifically its part \textbf{(d)}) is an
example of how a property of integers (here, $f_d \mid f_{dn}$)
can often be proved by working in a larger domain
(in our case, $\ZZ\ive{\phi}$).
Another example is our study of sums of two perfect squares
using Gaussian integers (done in class).
There are various others.
While part \textbf{(d)} of this exercise has fairly simple
solutions using integer arithmetic alone, some other properties
of Fibonacci numbers are best understood by means of working
in $\ZZ\ive{\phi}$.
For example, if $p \neq 5$ is a prime, then one of the two
Fibonacci numbers $f_{p-1}$ and $f_{p+1}$ is divisible by
$p$, while the other is $\equiv 1 \mod p$.

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 6
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 6: Non-unique factorization in $\ZZ\ive{\sqrt{-3}}$}

\subsection{Problem}

We let $\sqrt{-3}$ denote the complex number $\sqrt3 i$.

Let $\ZZ\ive{\sqrt{-3}}$ be the set of all complex numbers
of the form $a + b \sqrt{-3}$ with $a, b \in \ZZ$.
These complex numbers are called the
\textit{$3$-Gaussian integers}.

It is easy to see that the set $\ZZ\ive{\sqrt{-3}}$
is closed under addition, subtraction and multiplication
(i.e., that any $\alpha, \beta \in \ZZ\ive{\sqrt{-3}}$ satisfy
$\alpha + \beta \in \ZZ\ive{\sqrt{-3}}$ and
$\alpha - \beta \in \ZZ\ive{\sqrt{-3}}$ and
$\alpha \beta \in \ZZ\ive{\sqrt{-3}}$).
(In the terminology of abstract algebra, this is saying
that $\ZZ\ive{\sqrt{-3}}$ is a subring of $\CC$.)

It is also easy to see that each element of $\ZZ\ive{\sqrt{-3}}$
can be written as $a + b \sqrt{-3}$ for a \textbf{unique} pair
$\tup{a, b}$ of integers.

\begin{enumerate}

\item[\textbf{(a)}]
Prove that each $3$-Gaussian integer $\alpha$ satisfies
$\N\tup{\alpha} \in \NN$ and
$\N\tup{\alpha} \not\equiv 2 \mod 3$.

\end{enumerate}

\noindent
(Recall that $\N\tup{\alpha}$ is defined for every complex
number $\alpha$, and thus for every $3$-Gaussian integer
$\alpha$, since $3$-Gaussian integers are complex numbers.)

Given two elements $\alpha$ and $\beta$ of $\ZZ\ive{\sqrt{-3}}$,
we say that \textit{$\alpha \mid \beta$ in $\ZZ\ive{\sqrt{-3}}$}
if and only if there exists some $\gamma \in \ZZ\ive{\sqrt{-3}}$
such that $\beta = \alpha \gamma$.
Thus, we have defined divisibility in $\ZZ\ive{\sqrt{-3}}$.
Basic properties of divisibility of integers (such as
Proposition 2.2.4) still apply
to divisibility in $\ZZ\ive{\sqrt{-3}}$ (with the same proofs).

If $\alpha \in \ZZ\ive{\sqrt{-3}}$, then a
\textit{$3$-Gaussian divisor of $\alpha$} shall mean a
$\beta \in \ZZ\ive{\sqrt{-3}}$ such that $\beta \mid \alpha$
in $\ZZ\ive{\sqrt{-3}}$.

We define the notions of ``inverse'', ``unit'' and
``unit-equivalent'' for $3$-Gaussian integers
as we did for Gaussian integers.

A nonzero $3$-Gaussian integer $\pi$ that is not a unit is
called a \textit{$3$-Gaussian prime} if each $3$-Gaussian
divisor of $\pi$ is either a unit or unit-equivalent to $\pi$.

\begin{enumerate}

\item[\textbf{(b)}]
List all the $3$-Gaussian integers having norms $< 4$.

\item[\textbf{(c)}]
List all units in $\ZZ\ive{\sqrt{-3}}$.

\item[\textbf{(d)}]
Prove that $2$, $1 + \sqrt{-3}$ and $1 - \sqrt{-3}$ are
$3$-Gaussian primes.

\item[\textbf{(e)}]
Prove that
$2 \cdot 2 = \tup{1 + \sqrt{-3}} \cdot \tup{1 - \sqrt{-3}}$.

\item[\textbf{(f)}]
Define two $3$-Gaussian integers $\alpha$ and $\beta$
by $\alpha = 2$ and $\beta = 1 + \sqrt{-3}$.
Prove that there exist no $3$-Gaussian integers $\gamma$
and $\rho$ such that $\alpha = \gamma \beta + \rho$
and $\N\tup{\rho} < \N\tup{\beta}$.

\end{enumerate}

[\textbf{Hint:} Your list in part \textbf{(b)} should
contain $5$ entries.
Your list in part \textbf{(c)} should contain $2$
entries: Unlike the ring $\ZZ\ive{i}$ with its $4$ units,
the ring $\ZZ\ive{\sqrt{-3}}$
has only $2$ units.

For \textbf{(d)}, discuss the norm
of any possible $3$-Gaussian divisor.]

\subsection{Remark}

Parts \textbf{(d)} and \textbf{(e)} of this exercise
show that unique factorization into primes is not
automatically preserved when we extend a number system.
Neither is division with remainder, as part \textbf{(f)}
illustrates (though we already have seen the geometric
reason for this in class).
(Neither is the existence of a well-behaved greatest
common divisor.)

\subsection{Solution}

[...]

\begin{thebibliography}{99999999}                                                                                %

% Feel free to add your sources -- or copy some from the source code
% of the class notes ( http://www.cip.ifi.lmu.de/~grinberg/t/19s/notes.tex ).

% This is the bibliography: The list of papers/books/articles/blogs/...
% cited. The syntax is: "\bibitem[name]{tag}Reference",
% where "name" is the name that will appear in the compiled
% bibliography, and "tag" is the tag by which you will refer to
% the source in the TeX file. For example, the following source
% has name "GrKnPa94" (so you will see it referenced as
% "[GrKnPa94]" in the compiled PDF) and tag "GKP" (so you
% can cite it by writing "\cite{GKP}").

% I've commented the below references out, since I'm not citing
% them above.

% \bibitem[GrKnPa94]{GKP}Ronald L. Graham, Donald E. Knuth, Oren Patashnik,
% \textit{Concrete Mathematics, Second Edition}, Addison-Wesley 1994.\\
% See \url{https://www-cs-faculty.stanford.edu/~knuth/gkp.html} for errata.

% \bibitem[Grinbe19]{detnotes}Darij Grinberg,
% \textit{Notes on the combinatorial fundamentals of algebra},
% 10 January 2019. \\
% \url{http://www.cip.ifi.lmu.de/~grinberg/primes2015/sols.pdf}
% \\
% The numbering of theorems and formulas in this link might shift
% when the project gets updated; for a ``frozen'' version whose
% numbering is guaranteed to match that in the citations above, see
% \url{https://github.com/darijgr/detnotes/releases/tag/2019-01-10} .

\bibitem[ConradG]{Conrad-Gauss}Keith Conrad, \textit{The Gaussian
integers}.\newline\url{http://www.math.uconn.edu/~kconrad/blurbs/ugradnumthy/Zinotes.pdf}

\end{thebibliography}

\end{document}


\documentclass{article}

\usepackage[margin=0.5in]{geometry}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\usepackage{cleveref}

\title{CE EN 507: Coding Assignment 1}
\author{ Jared J.~Thomas}

\begin{document}
\maketitle

\section{Plot the exact and approximate solution for each $f(x)$ and $n$. Describe the behavior of the solution at the nodes and the interior of the elements for each f(x)? To what can you attribute the differences?}
Please see the plots of the exact and approximate solution for each $f(x)$ and $n$ in \cref{fig:fandn}.
\begin{figure}
	\centering
        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func0_Nell10}
                \label{fig:gull}
        \end{subfigure}%
        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func1_Nell10}
                \label{fig:gull2}
        \end{subfigure}%
        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func2_Nell10}
                \label{fig:tiger}
        \end{subfigure}%

        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func0_Nell100}
                \label{fig:gull}
        \end{subfigure}%
        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func1_Nell100}
                \label{fig:gull2}
        \end{subfigure}%
        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func2_Nell100}
                \label{fig:tiger}
        \end{subfigure}%

        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func0_Nell1000}
                \label{fig:gull}
        \end{subfigure}%
        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func1_Nell1000}
                \label{fig:gull2}
        \end{subfigure}%
        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func2_Nell1000}
                \label{fig:tiger}
        \end{subfigure}%

        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func0_Nell10000}
                \label{fig:gull}
        \end{subfigure}%
        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func1_Nell10000}
                \label{fig:gull2}
        \end{subfigure}%
        \begin{subfigure}[b]{0.33\textwidth}
                \includegraphics[width=\linewidth]{displacement_func2_Nell10000}
                \label{fig:tiger}
        \end{subfigure}%
        \caption{Exact and approximate solutions for each $f(x)$ and $n$}\label{fig:fandn}
\end{figure}

The approximate solution is exact at the nodes for the constant and linear forcing functions because we are approximating using first order polynomials. However, for the second order polynomial forcing function, the solution is not even exact at the nodes because we are ignorming higher order terms in our approximation. For all the forcing functions, the approximation is closer to the exact solution at points closer to nodes and further from the exact solution at points further from the nodes.

\section{Compute and report the global error for each $f(x)$ and $n$ (12 numbers)}
\begin{tabular}{l | l l l}
N-elements              & $f(x)=c$ & $f(x)=x$ & $f(x)=x^2$ \\
\hline
10 & 9.128709291753452602e-04 & 5.264090438827071818e-04& 5.908095390718911578e-04 \\
100 & 9.128709291329707023e-06 & 5.270399081649309119e-06 & 5.931474041855632921e-06  \\
1,000  & 9.128709226791299245e-08 & 5.270462112780296755e-08 & 5.931707788287919871e-08          \\
10,000     & 9.129188732190131811e-10 & 5.270659276938995368e-10 & 5.931669081979712336e-10  \\
\end{tabular}

\section{Employing the data for n = 10, 100, 1000, 10000 generate a log-log plot for $e$ versus $h$ for each $f(x)$ (1 plot). Determine the slope of the graph for the two cases when $f(x)$ is non-constant. The slope of this graph is the rate of convergence of the method or how fast the approximate solution is converging to the exact solution as the mesh is refined. How does the rate of convergence depend on $n$?}

Please see the error plot in \cref{fig:error}. The slope of the graph in loglog space is 1.99981946665 when $f(x)=x$ and 1.99942352808 when $f(x)=x^2$. The rate of convergence decreases as $n$ increases. This means that there are diminisiong returns in accuracy for increasing the number of elements.

\begin{figure}
	\includegraphics{error}
	\caption{Error plot for each $f(x)$ and $n$}\label{fig:error}
\end{figure}
\end{document}