\transitionFrame{Network Capacity \& Adversarial Robustness}

\begin{frame}
	\onslide<+->{Solving the following equation is not enough to guarantee the robustness and accuracy of the classifier.
		\begin{equation*}
		{\min_{\params} \rho(\params)}\text{, where } \rho(\params) = \mathbb{E}_{(\X,\y) \sim \distr} \sbrack{{ \max_{\perturb \in \sPerturb} \loss (\X + \perturb, \y ; \params)}}
		\end{equation*}
	}

	\onslide<+->{The problem must have a small \colortext{green}{\textit{value}}, which means that the final loss achieved by the classifier against adversarial examples must be small.}

	\vspace{4pt}

	\onslide<+->{Therefore, a very small \colortext{blue}{$\rho(\params)$} corresponds to a perfect classifier that is robust to adversarial inputs.}

	\vspace{4pt}

	\onslide<+->{For a fixed set $\sPerturb$, the value of the problem is entirely dependent on the
		architecture of the classifier.}

	\vspace{4pt}

	\onslide<+->{Therefore, the architectural capacity of the model is very important for its over performance.}
\end{frame}

\begin{frame}{Visualizing the Effect of Capacity}
	\begin{columns}
		\begin{column}{0.32\textwidth}
			\onslide<+->{
				\begin{center}
					\includegraphics[scale=0.3]{capacity/benign_only.pdf}

					(Benign) binary classification using a \\\blue{linear decision boundary}
				\end{center}
			}
		\end{column}
		\begin{column}{0.32\textwidth}
			\onslide<+->{
				\begin{center}
					\includegraphics[scale=0.3]{capacity/misclassified_adv.pdf}

					Adversarial $\ell_{\infty}$ balls
					\\
					\red{$\star$} misclassified \\ adversarial examples
				\end{center}
			}
		\end{column}
		\begin{column}{0.32\textwidth}
			\onslide<+->{
				\begin{center}
					\includegraphics[scale=0.3]{capacity/complicated_decision.pdf}

					``Complicated'' decision boundary required
				\end{center}
			}
		\end{column}
	\end{columns}
\end{frame}

\begin{frame}{}
	\begin{columns}
		\begin{column}{0.48\textwidth}
			\onslide<+->{
				\begin{center}
					\includegraphics[scale=0.18]{nc_ar/mnist.png}

					MNIST
				\end{center}
			}
		\end{column}
		\begin{column}{0.48\textwidth}
			\onslide<+->{
				\begin{center}
					\includegraphics[scale=0.44]{nc_ar/cifar10.png}

					CIFAR10
				\end{center}
			}
		\end{column}
	\end{columns}
\end{frame}

\begin{frame}
	\onslide<+->{Verified by their experiments, capacity is crucial for:
		\begin{itemize}[<+->]
			\setlength\itemsep{8pt}
			\item Robustness
			\item The ability to successfully train a classifier against strong adversaries.
		\end{itemize}
	}
	\begin{columns}
		\begin{column}{0.99\textwidth}
			\onslide<+->{
				\begin{center}
					\includegraphics[scale=0.38]{nc_ar/fig4.png}
				\end{center}
			}
		\end{column}
	\end{columns}
\end{frame}

\begin{frame}
	\onslide<+->{What they found:
		\begin{itemize}[<+->]
			\setlength\itemsep{3pt}
			\item Capacity alone helps
				\begin{itemize}[<+->]
					\setlength\itemsep{1pt}
					\item Even with training on natural examples, increase in capacity increases the robustness against one-step perturbation
					\item  This effect is greater when considering adversarial examples with smaller $\varepsilon$
				\end{itemize}
			\item FGSM adversaries don’t increase robustness (for large  $\varepsilon$)
			\begin{itemize}[<+->]
				\setlength\itemsep{1pt}
				\item Training a network with FGSM adversaries and large  $\varepsilon$ results in
				\item Known as label leaking
				\item For smaller $\varepsilon$, FGSM adversaries are close to PGD, which makes it reasonable
			\end{itemize}
			\item Weak (small capacity) models may fail to learn non-trivial classifiers
			\begin{itemize}[<+->]
				\setlength\itemsep{1pt}
				\item Even though the model could converge to an accurate classifier through standard training, it is sacrificed for any kind of robustness against adversarial inputs
				\item But the model is still vulnerable to attacks
			\end{itemize}
			\item The value of the saddle point problem decreases as we increase the capacity
			\item More capacity and stronger adversaries decrease transferability
			\begin{itemize}[<+->]
				\setlength\itemsep{1pt}
				\item Otherwise, tranferability results in vulnerability to attacks even when there is no direct access to the target network
			\end{itemize}
		\end{itemize}
	}
\end{frame}

\subsection{Experiments}
\begin{frame}
	\onslide<+->{Two key elements in training their robust classifiers
		\begin{itemize}[<+->]
			\setlength\itemsep{8pt}
			\item A sufficiently high capacity network
			\item The strongest possible adversary
		\end{itemize}
	}
	\vspace{15pt}
	\onslide<+->{Using a "complete" first-order adversary by PGD for both MNIST and CIFAR10:
		\begin{itemize}[<+->]
			\setlength\itemsep{8pt}
			\item Multiple epochs for training the model. Therefore, no benefit from restarting PGD multiple times per batch
		\end{itemize}
	}
\end{frame}

\begin{frame}
	The steady decrease in the training loss of adversarial examples indicates the successfulness of the solution for the original optimization problem during training.

	\begin{columns}
		\begin{column}{0.99\textwidth}
			\onslide<+->{
				\begin{center}
					\includegraphics[scale=0.3]{nc_ar/fig5.png}
				\end{center}
			}
		\end{column}
	\end{columns}
\end{frame}

\begin{frame}
	\onslide<+->{Models are trained against a range of adversaries:
		\begin{itemize}[<+->]
			\setlength\itemsep{4pt}
			\item White-box attacks with PGD for a different number of iterations and restarts (A)
			\item White-box attacks with PGD using the Carlini-Wagner (CW) \cite{tramer2017space}, and CW+ when ${\kappa = 50}$ (i.e. attack with a high confidence)
			\begin{itemize}[<+->]
				\setlength\itemsep{4pt}
				\item ${f(x^{'}) = max(max\{Z(x^{'})_{i}: i \neq t\} - Z(x^{'})_{t}, -\kappa)}$
				\item z is the output of all layers except the softmax in a NN (so z is the logit)
			\end{itemize}
			\item Black-box attacks from an independently trained copy of the network (A$^{'}$).
			\item Black-box attacks from a version of the same network trained only on natural examples (A$_{nat}$)
			\item Black-box attacks from a different convolution architecture (B)
		\end{itemize}
	}
\end{frame}

\begin{frame}
	\begin{columns}
		\begin{column}{0.48\textwidth}
			\onslide<+->{
				\begin{center}
					\includegraphics[scale=0.3]{nc_ar/table1.png}
					MNIST
				\end{center}
			}
		\end{column}
		\begin{column}{0.48\textwidth}
			\onslide<+->{
				\begin{center}
					\includegraphics[scale=0.4]{nc_ar/table2.png}
					CIFAR10
				\end{center}
			}
		\end{column}
	\end{columns}
\end{frame}

\begin{frame}
	Resistance for different values of $\varepsilon$ and $\ell_{2}$-bounded attacks
	\begin{columns}
		\begin{column}{0.99\textwidth}
			\onslide<+->{
				\begin{center}
					\includegraphics[scale=0.3]{nc_ar/fig6.png}
				\end{center}
			}
		\end{column}
	\end{columns}
\end{frame}

\begin{frame}
	\onslide<+->{Conclusion:
		\begin{itemize}[<+->]
			\setlength\itemsep{15pt}
			\item Although deep neural networks very vulnerable to adversarial attacks, they can be made resistant to adversarial attacks
			\item Based on the theory and experiments, reliable adversarial training methods can be designed because of the unexpectedly regular structure of the underlying optimization task:
			\begin{itemize}[<+->]
				\setlength\itemsep{15pt}
				\item Even though the relevant problem corresponds to the maximization of a highly
				non-concave function with many distinct local maxima, their values are highly concentrated.
			\end{itemize}
		\end{itemize}
	}
\end{frame}

\section{Related Works}
\begin{frame}
	\begin{itemize}[<+->]
		\setlength\itemsep{15pt}
		\item Robust optimization, not a new topic
		\item Adversarial ML, not a new topic
		\item Having the above in the context of DNN is their contribution
	\end{itemize}
	\vspace{8pt}
	\onslide<+->{
		Recent work on adversarial training on ImageNet also observed that the model capacity is important for adversarial training.
	}
	\vspace{8pt}

	\onslide<+->{
		( Their contribution) Training against multi-step methods (PGD) does lead to resistance against adversaries
	}
\end{frame}

\begin{frame}
	\onslide<+->{
		There are previous works on the min-max optimization problem. But, there are three differences:
		\begin{itemize}[<+->]
			\setlength\itemsep{15pt}
			\item (Previous works) the inner maximization problem can be difficult to solve, (they) it
			is possible to obtain sufficiently good solutions using randomly re-started projected gradient descent
			\item (Previous works) one-step adversaries, (they) multi-step methods
			\item (Previous works)  FGSM --FGSM-only evaluations are not fully reliable, (they) PGD
		\end{itemize}
	}
\end{frame}


\input{../ex_template.tex}

\title{BPP Exercise 3 - Directing the Flow}
\author{A. Hain, M. Nipshagen}
\date{23.04.2018, 8:00}

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

% do not include solutions
% \renewcommand\sol[1]{}

\begin{document}

The deadline for this exercise sheet is \textbf{Monday, \thedate.}
%
%\section*{Introductory Words}
%In case we have some information that doesn't directly concern the current exercises.
%
\section{Boolean Operators}
Determine the truth values of the following boolean operators for each configuration
of truth values as given in the tables

\subsection{}
\begin{tabular}{| c | c | c | c |}
  \hline
  \textbf{a} & \textbf{b} & \textbf{c} & \textbf{(b or c) and (a or c)} \\
  \hline
  true & true & true & \sol{true} \\
  \hline
  true & true & false & \sol{true} \\
  \hline
  true & false & true & \sol{true} \\
  \hline
  true & false & false & \sol{false} \\
  \hline
  false & true & true & \sol{true} \\
  \hline
  false & true & false & \sol{false} \\
  \hline
  false & false & true & \sol{true} \\
  \hline
  false & false & false & \sol{false} \\
  \hline
\end{tabular}

\subsection{}
\begin{tabular}{| c | c | c | c |}
  \hline
  \textbf{a} & \textbf{b} & \textbf{c} & \textbf{a or (b and c) and (not c or not a)} \\
  \hline
  true & true & true & \sol{true} \\
  \hline
  true & true & false & \sol{true} \\
  \hline
  true & false & true & \sol{true} \\
  \hline
  true & false & false & \sol{true} \\
  \hline
  false & true & true & \sol{true} \\
  \hline
  false & true & false & \sol{false} \\
  \hline
  false & false & true & \sol{false} \\
  \hline
  false & false & false & \sol{false} \\
  \hline
\end{tabular}

\subsection{}
\begin{tabular}{| c | c | c | c |}
  \hline
  \textbf{a} & \textbf{b} & \textbf{c} & \textbf{not(not(b and not(c or a)))} \\
  \hline
  true & true & true & \sol{false} \\
  \hline
  true & true & false & \sol{false} \\
  \hline
  true & false & true & \sol{false} \\
  \hline
  true & false & false & \sol{false} \\
  \hline
  false & true & true & \sol{false} \\
  \hline
  false & true & false & \sol{true} \\
  \hline
  false & false & true & \sol{false} \\
  \hline
  false & false & false & \sol{false} \\
  \hline
\end{tabular}

\section{Warm up -- Prof Strikes Again}
Remember the task from last week? Now that your prof computed your numerical grade, the
functionality of this program shall be extended by automatically determining whether
someone passed the class or not based on this grade.\\
Write a function \texttt{passed} that takes a grade
as a parameter and returns whether the student passed or failed.

\cprotect\sol{
\begin{python}
def passed(grade):
  """Returns True if the grade is a passing one"""
  return grade <= 4.0
\end{python}
}

\section{Loops}

\subsection{N Bottles of Beer}
Similar to Hello World programs, 99 bottles programs give us an idea of how
a programming language looks as they show the basic loop concepts.
The 99 bottles program “sings” a little song which goes like this:\\\\
\textit{
99 bottles of beer on the wall, 99 bottles of beer. Take one down and
pass it around, 98 bottles of beer on the wall.\\
98 bottles of beer on the wall, 98 bottles of beer. Take one down and
pass it around, 97 bottles of beer on the wall.\\
. . .\\
1 bottle of beer on the wall, 1 bottle of beer. Take one down and
pass it around, no more bottles of beer on the wall.\\\\
}
Write a function \texttt{n\_bottles(n)} in the script \texttt{n\_bottles.py} which
sings the song starting with n bottles instead of 99. If n is bigger than 99 or
smaller than 5 print a message that you want to sing a funnier song than n bottles
(of course replace n with the current n). Your final result may also structure
the verses in a different layout.

\cprotect\sol{
\begin{python}
def bottles(n):
    """Formats plural according to number of bottles."""
    return ('1 bottle' if n == 1 else str(n) + ' bottles') + ' of beer'

def n_bottles(n):
    """
    Go through the bottles of beer on the wall, and pass them around.

    Calls `bottles(n)` for formatting, and reduces n by 1 each iteration
    """
    if 5 <= n <= 99:
        while(n > 0):
            print(bottles(n) + ' on the wall,\n  ' + bottles(n) + '.')
            n = n - 1
            print('Take one down and pass it around,\n  ' +
                # conditional expression to determine whethere there are bottles left
                bottles(n if n > 0 else 'no more') +
                ' on the wall.\n')
    else:
        print('I want to sing funnier songs than "' + bottles(n) + '".\n')

n_bottles(3)
n_bottles(1011)
n_bottles(5)
\end{python}
Output:
\texttt{
\small{\\
I want to sing funnier songs than "3 bottles of beer".\\\\
I want to sing funnier songs than "1011 bottles of beer".\\\\
5 bottles of beer on the wall,\\
\indent 5 bottles of beer.\\
Take one down and pass it around,\\
\indent 4 bottles of beer on the wall.\\\\
4 bottles of beer on the wall,\\
\indent 4 bottles of beer.\\
Take one down and pass it around,\\
\indent 3 bottles of beer on the wall.\\\\
3 bottles of beer on the wall,\\
\indent 3 bottles of beer.\\
Take one down and pass it around,\\
\indent 2 bottles of beer on the wall.\\\\
2 bottles of beer on the wall,\\
\indent 2 bottles of beer.\\
Take one down and pass it around,\\
\indent 1 bottle of beer on the wall.\\\\
1 bottle of beer on the wall,\\
\indent 1 bottle of beer.\\
Take one down and pass it around,\\
\indent no more bottles of beer on the wall.\\
}
}
}

\subsection{Return of the turtle}
\FloatBarrier
You hopefully remember the turtle from the first week -- you drew a Saint Nicholas' house with it.
This time we will draw even more houses! And some trees to keep them company.\\
Write a script \texttt{turtle\_world.py}. Develop a function \texttt{draw\_house} that draws a house --
it doesn't need to be the Saint Nicholas' house, but you can recylce your code if you like.
Then write a function \texttt{draw\_tree{height}} that draws a tree of a given "height".
The height serves a double purpose as the branching factor of the tree. Your tree is going to be a fractal,
which means that it will be a pattern that repeats itself recursively.

\begin{figure}[h]
  \includegraphics[scale=0.8]{recursive_tree}
  \caption{Example Tree}
  \label{fig:tree:1}
\end{figure}

\noindent To build the tree follow this algorithm:\\
\begin{lstlisting}
To draw a tree with height h:
  If height h is 0, stop.
  Draw a line of length L * h.
  Rotate left by angle A.
  Draw a tree of height h - 1.
  Rotate right by angle 2A.
  Draw a tree of height h - 1.
  Rotate left by angle A.
  Move back to the beginning of the line.
\end{lstlisting}

\noindent The resulting tree should look similar to Figure \ref{fig:tree:1}. Choose $A$ and $L$ as you like, be creative!\\
Now draw a simple landscape. Draw a house, a small tree, a big tree, a small tree, and repeat this pattern a couple of times
(Figure \ref{fig:world:flat}). Or build a different one. Just make it repetitive (Yes, use loops).

\begin{figure}[h]
	\includegraphics[width=\textwidth]{flat_world}
	\caption{Flat World}
	\label{fig:world:flat}
\end{figure}

\noindent\textbf{Bonus}: Can you build a round world like in Figure \ref{fig:world:round}?

\begin{figure}[h]
	\includegraphics[width=\textwidth]{round_world}
	\caption{Round World}
	\label{fig:world:round}
\end{figure}

\FloatBarrier
\cprotect\sol{
\begin{python}
# pylint: disable=E1101
import time
import turtle

# constants for all draw functions for a nice and consistent look
LENGTH = 6
ANGLE = 35

def draw_tree(height):
    """
    Draws a fractal tree with `height` repetitions.

    `height` defines the overall height of the tree is also responsible for
    the length of each branch in every iteration
    """
    if height == 0:
        return
    # left branch
    turtle.forward(LENGTH * height)
    turtle.left(ANGLE)
    draw_tree(height - 1) # drawing the little tree at the end of the branch
    # right branch
    turtle.right(2 * ANGLE)
    draw_tree(height - 1)  # drawing the little tree at the end of the branch
    turtle.left(ANGLE)
    turtle.backward(LENGTH * height)

def draw_house():
    """This draws a nice and simple house!"""
    # the dimensions of our house
    height = 5 * LENGTH
    width = 7 * LENGTH
    roofside = (width ** 2 / 2) ** (1 / 2)

    # left wall
    turtle.forward(height)
    # roof
    turtle.right(45)
    turtle.forward(roofside)
    turtle.right(90)
    turtle.forward(roofside)
    turtle.right(45)
    # right wall
    turtle.forward(height)
    turtle.right(90)
    # bottom line
    turtle.forward(width)
    turtle.right(90)

def draw_world(curvature_step=0):
    """
    This draws a turtle world.

    The curvature step is relevant for drawing a round world.
    The higher the curvature step is, the smaller our circle will be.

    Each village will consist of one house and 3 trees, with one being taller.
    """
    if curvature_step > 0: # this ensures we are going full circle
        villages = 360 // 4 // curvature_step
    else: # 5 villages for our flat world
        villages = 5

    # the _ is called an anonymous variable, since we don't use it anyway
    # we don't need to give it a name. It just acts as a counter.
    for _ in range(villages):
        prepare_drawing()
        draw_house()
        finish_drawing()

        turtle.right(curvature_step)
        turtle.forward(LENGTH * 11)

        # and draw the three trees
        for j in range(3):
            prepare_drawing()
            # the middle one will be 5 high, since we iterate over 0,1,2
            # and only for 1 modulo 2 is 1 returned.
            draw_tree(3 + j % 2 * 2)
            finish_drawing()

            turtle.right(curvature_step)
            turtle.forward(LENGTH * 3)

        turtle.forward(LENGTH)

def init():
    """set up the turtle parameters"""
    turtle.reset()
    turtle.shape('turtle')
    turtle.speed('fastest')
    turtle.up()

def prepare_drawing():
    """move the pen down to actually draw and make turtle upright"""
    turtle.down()
    turtle.left(90)

def finish_drawing():
    """move pen up to stop drawing and return turtle to axis"""
    turtle.right(90)
    turtle.up()

def draw_flat_world():
    """wrapper to start drawing a flat world with 0 curvature"""
    init()
    turtle.goto(-300, 0)

    draw_world()
    turtle.goto(0,0)

def draw_round_world(curvature_step=5):
    """wrapper to draw a curved world with a default curvature step of 5"""
    init()
    turtle.goto(0, 300)
    draw_world(curvature_step)
    turtle.goto(0,0)

def draw():
    """Draw the flat world. Rest shortly to marvel at it. Draw round world."""
    draw_flat_world()
    time.sleep(3)
    draw_round_world()
    turtle.done()

# Start the party!
draw()

\end{python}
}

\end{document}


\documentclass[final,leqno,onetabnum]{siamltex0315}
\usepackage{amsfonts,amsmath,amssymb}
\usepackage{subfigure}
\usepackage{psfrag}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{lineno}

\makeatletter
\renewcommand{\ALG@name}{\sc Algorithm}
\makeatother

% Environments that will be called into the paper.

\newtheorem{assumption}[theorem]{\textit{Assumption}}
\newtheorem{remark}[theorem]{\textit{Remark}}

% Definitions used by included articles, reproduced here for
% educational benefit, and to minimize alterations needed to be made
% in developing this sample file.

\newcommand{\pe}{\psi}
\def\d{\delta}
\def\ds{\displaystyle}
\def\e{{\epsilon}}
\def\eb{\bar{\eta}}
\def\enorm#1{\|#1\|_2}
\def\Fp{F^\prime}
\def\fishpack{{FISHPACK}}
\def\fortran{{FORTRAN}}
\def\gmres{{GMRES}}
\def\gmresm{{\rm GMRES($m$)}}
\def\Kc{{\cal K}}
\def\norm#1{\|#1\|}
\def\wb{{\bar w}}
\def\zb{{\bar z}}

% Some definitions used in the sample assumption.

\newcommand{\lW}[1]{\ensuremath{\lambda(W({#1},\rho))}}
\newcommand{\rhol}{\ensuremath{\rho_{\text{1,d}}}}
\newcommand{\rhoo}{\ensuremath{\rho_{\text{0,d}}}}
\newcommand{\ad}{\ensuremath{a_{\text{d}}}}
\newcommand{\rhoT}{\ensuremath{\rho_{\text{T,d}}}}

% Some definitions of bold math italics to make typing easier.
% They are used in the corollary.

\def\bfE{\mbox{\boldmath$E$}}
\def\bfG{\mbox{\boldmath$G$}}

% Line numbering to aid with review. Disabled before publication.

\linenumbers

% Title line. The thanks line in the title should be filled in if there
% is any support acknowledgement for the overall work to be included
% This \thanks is also used for the received by date info, but
% authors are not expected to provide this.

\title{eXample File for SIAM \LaTeX\ Macro Package\thanks{This
        work was supported by the Society for Industrial and
        Applied Mathematics, Philadelphia, Pennsylvania.}}

\author{Sue Susans\thanks{Production Department, Society
        for Industrial and Applied Mathematics, 3600 Market St.,
        Philadelphia, PA
        19104-2688 (\email{pseudonym@siam.org}, \email{alias@siam.org}).}
   \and James Jameson\footnotemark[2]
   \and A.~U.~Thors\thanks{Institute of Applied Mathematics, Department of
        Mathematics, Vancouver, BC V6T 1Z1, Canada (\email{au.thors@math.ubc.ca}).
        The research of this author was partially supported by various foundation grants.}}

\begin{document}

\maketitle

\begin{abstract}
An example of SIAM \LaTeX\ macros is presented. Various
aspects of composing manuscripts for SIAM's journal series
are illustrated with actual examples from accepted
manuscripts. SIAM's stylistic standards are adhered to
throughout and are illustrated.  When writing your own abstract, keep it to a single paragraph, avoid
displayed math, and use standard TeX terms instead of your own definitions.
\end{abstract}

\begin{keywords}
sign-nonsingular matrix, LU-factorization, indicator
polynomial
\end{keywords}

\begin{AMS}
15A15, 15A09, 15A23
\end{AMS}

\pagestyle{myheadings}
\thispagestyle{plain}
\markboth{S.~SUSANS, J.~JAMESON, AND A.~U.~THORS}{SIAM MACRO EXAMPLES}

\section{Introduction and examples}
This paper presents a sample file for the use of SIAM's
\LaTeX\ macro package. It illustrates the features of the
macro package, using actual examples culled from various
papers published in SIAM's journals. It is to be expected
that this sample will provide examples of how to use the
macros to generate standard elements of journal papers. This paper also
serves as an example of SIAM's stylistic preferences for
the formatting of such elements as bibliographic references,
displayed equations, and equation arrays, among others.  More information
about SIAM's editorial style can be found in the style manual, available
at \url{http://www.siam.org/journals/pdf/stylemanual.pdf}.

{\em Note:} This paper is not to be read in any form for content.
The conglomeration of equations, lemmas, and other text elements were
put together solely for typographic illustrative purposes and don't
make any sense as lemmas, equations, etc.

\subsection{Sample text}
The following are a few sentences showing normal setup of math in text: Let $S=[s_{ij}]$ ($1\leq i,j\leq n$) be a $(0,1,-1)$-matrix
of order $n$. Then $S$ is a {\em sign-nonsingular matrix}
(SNS-matrix) provided that each real matrix with the same
sign pattern as $S$ is nonsingular. There has been
considerable recent interest in constructing and
characterizing SNS-matrices \cite{bs}, \cite{klm}, \cite{LiZeng2012a}. There
has also been interest in strong forms of
sign-nonsingularity \cite{djd}. In this paper we give a new
generalization of SNS-matrices and investigate some of
their basic properties.

Blackboard bold characters, such as $\mathbb{C}$ and $\mathbb{R}$, should be created with use of the {\tt amssymb} package and its definitions.

Let $S=[s_{ij}]$ be a $(0,1,-1)$-matrix of order $n$ and
let $C=[c_{ij}]$ be a real matrix of order $n$. The pair
$(S,C)$ is called a {\em matrix pair of order} $n$.
Throughout, $X=[x_{ij}]$ denotes a matrix of order $n$
whose entries are algebraically independent indeterminates
over the real field. Let $S\circ X$ denote the Hadamard
product (entrywise product) of $S$ and $X$. We say that the
pair $(S,C)$ is a {\em sign-nonsingular matrix pair of
order} $n$, abbreviated SNS-{\em matrix pair of order} $n$,
provided that the matrix \begin{linenomath*}\[A=S\circ X+C\]\end{linenomath*} is nonsingular
for all positive real values of the $x_{ij}$.  If $C=O$
then the pair $(S,O)$ is a SNS-matrix pair if and only if
$S$ is a SNS-matrix.  If $S=O$ then the pair $(O,C)$ is a
SNS-matrix pair if and only if $C$ is nonsingular. Thus
SNS-matrix pairs include both nonsingular matrices and
sign-nonsingular matrices as special cases.   Now  let $\alpha>0$ and let $x^*$ be the weak$^*$-limit of some net $\{x_\tau^*\}
  \subseteq (\sum_{i\in I}N_{C_i}(x))\cap\alpha\mathbf{B}$.

Matrices of no more than two rows appearing in text should be created with the commands {\tt atop},
{\tt choose}, or {\tt smallmatrix}: The multiplication is conformable at the block level, and the orthogonal
matrix $[ \begin{smallmatrix} B_{11} & B_{12} \\ B_{21} & B_{22} \end{smallmatrix} ]$,
said to be in \emph{bidiagonal-block form}, can be parameterized by
$\theta_{1},\dots,\theta_{r}\in[0,\frac{\pi}{2}]$ and $\phi_{1},\dots,\phi_{r-1}\in[0,\frac{\pi}{2}]$.  Matrices with three or more
rows should be used in display equations: The pairs $(S,C)$ with
\begin{linenomath*}
\[S=\left[\begin{array}{cc}1&0\\0&0\end{array}\right],\qquad
C=\left[\begin{array}{cc}1&1\\1&1\end{array}\right]\] and
\[S=\left[\begin{array}{ccc}1&1&0\\1&1&0\\0&0&0\end{array}\right],\qquad
C=\left[\begin{array}{ccc}0&0&1\\0&2&0\\
3&0&0\end{array}\right]\]
\end{linenomath*}
are examples of SNS-matrix pairs.

\subsection{A remuneration list}
In this paper we consider the evaluation of integrals of the
following forms:
\begin{linenomath*}
\begin{equation}
\int_a^b \left( \sum_i E_i B_{i,k,x}(t) \right)
         \left( \sum_j F_j B_{j,l,y}(t) \right) dt,\label{problem}
\end{equation}
\end{linenomath*}
\begin{linenomath*}
\begin{equation}
\int_a^b f(t) \left( \sum_i E_i B_{i,k,x}(t) \right) dt,\label{problem2}
\end{equation}
\end{linenomath*}
where $B_{i,k,x}$ is the $i$th B-spline of order $k$ defined over the
knots $x_i, x_{i+1}, \ldots, x_{i+k}$.
We will consider B-splines normalized so that their integral is one.
The splines may be of different orders and
defined on different knot sequences $x$ and $y$.
Often the limits of integration will be the entire real line, $-\infty$
to $+\infty$. Note that (\ref{problem}) is a special case of (\ref{problem2})
where $f(t)$ is a spline \cite{BDM}.

There are five different methods for calculating (\ref{problem})
that will be considered:
\begin{remunerate}
\item Use Gauss quadrature on each interval.
\item Convert the integral to a linear combination of
      integrals of products of B-splines and provide a recurrence for
      integrating the product of a pair of B-splines.
\item Convert the sums of B-splines to piecewise
      B\'{e}zier format and integrate segment
      by segment using the properties of the Bernstein polynomials.
\item Express the product of a pair of B-splines as a linear combination
      of B-splines.
      Use this to reformulate the integrand as a linear combination
      of B-splines, and integrate term by term.
\item Integrate by parts.
\end{remunerate}
Of these five, only methods 1 and 5 are suitable for calculating
(\ref{problem2}). The first four methods will be touched on and the
last will be discussed at length.

\subsection{Some displayed equations and {\tt \{eqnarray\}}s}
     By introducing the product topology on  $R^{m \times m} \times
R^{n \times n}$  with the induced inner product
\begin{linenomath*}
\begin{equation}
\langle (A_{1},B_{1}), (A_{2},B_{2})\rangle := \langle A_{1},A_{2}\rangle
+ \langle B_{1},B_{2}\rangle,\label{eq2.10}
\end{equation}
\end{linenomath*}
we calculate the Fr\'{e}chet derivative of  $F$  as follows:
\begin{linenomath*}
\begin{eqnarray}
 F'(U,V)(H,K) &=& \langle R(U,V),H\Sigma V^{T} + U\Sigma K^{T} -
P(H\Sigma V^{T} + U\Sigma K^{T})\rangle \nonumber \\
         &=& \langle R(U,V),H\Sigma V^{T} + U\Sigma K^{T}\rangle \label{eq2.11} \\
&=& \langle R(U,V)V\Sigma^{T},H\rangle + \langle \Sigma^{T}U^{T}R(U,V),K^{T}\rangle.     \nonumber
\end{eqnarray}
\end{linenomath*}
In the middle line of (\ref{eq2.11}) we have used the fact that the range of
$R$ is always perpendicular to the range of $P$.  The gradient $\nabla F$  of
$F$, therefore,  may be interpreted as the
pair of matrices:
\begin{linenomath*}
\begin{equation}
 \nabla F(U,V) = (R(U,V)V\Sigma^{T},R(U,V)^{T}U\Sigma ) \in
R^{m \times m} \times R^{n \times n}.       			\label{eq2.12}
\end{equation}
\end{linenomath*}
Because of the product topology, we know
\begin{linenomath*}
\begin{equation}
 {\cal T}_{(U,V)}({\cal O} (m) \times {\cal O} (n)) =
{\cal T}_{U}{\cal O} (m) \times {\cal T}_{V}{\cal O} (n),  		\label{eq2.13}
\end{equation}
\end{linenomath*}
where  ${\cal T}_{(U,V)}({\cal O} (m) \times {\cal O} (n))$  stands for the
tangent space to the manifold  ${\cal O} (m) \times {\cal O} (n)$  at  $(U,V)
\in {\cal O} (m) \times {\cal O} (n)$  and so on.  The projection of
$\nabla F(U,V)$  onto  ${\cal T}_{(U,V)}({\cal O} (m) \times {\cal O} (n))$,
therefore, is the product of the projection of the first component of
$\nabla F(U,V)$  onto  ${\cal T}_{U}{\cal O} (m)$  and the projection of the
second component of  $\nabla F(U,V)$  onto  ${\cal T}_{V}{\cal O} (n)$.
In particular, we claim that the
projection $ g(U,V)$  of the gradient  $\nabla F(U,V)$  onto
${\cal T}_{(U,V)}({\cal O} (m) \times {\cal O} (n))$  is given by the pair of
matrices:
\begin{linenomath*}
\begin{eqnarray}
g(U,V) = && \left( \frac{R(U,V)V\Sigma^{T}U^{T}-U\Sigma V^{T}R(U,V)^{T}}{2}U,
\right.			\nonumber \\[-1.5ex]
\label{eq2.14}\\[-1.5ex]
&&\quad \left. \frac{R(U,V)^{T}U\Sigma V^{T}-V
   \Sigma^{T}U^{T}R(U,V)}{2}V \right).\nonumber
\end{eqnarray}
\end{linenomath*}
Thus, the vector field
\begin{linenomath*}
\begin{equation}
\frac{d(U,V)}{dt} = -g(U,V) 	\label{eq2.15}
\end{equation}
\end{linenomath*}
defines a steepest descent flow on the manifold  ${\cal O} (m) \times
{\cal O} (n)$ for the objective function  $F(U,V)$.

\section{Environments}\label{S2}

Let $(S,C)$ be a matrix pair of order $n$.  The determinant
\[\det (S\circ X+C)\]
is a polynomial in the indeterminates of $X$ of degree at
most $n$ over the real field. We call this polynomial the
{\em indicator polynomial} of the matrix pair $(S,C)$
because of the following proposition.

\begin{theorem}[see \cite{SS13}]
\label{th:prop}
The matrix pair $(S,C)$ is a {\rm SNS}-matrix pair if and
only if all the nonzero coefficients in its indicator
polynomial have the same sign and there is at least one
nonzero coefficient.
\end{theorem}

\begin{proof}
Assume that $(S,C)$ is a SNS-matrix pair.  Clearly the
indicator polynomial has a nonzero coefficient.  Consider a
monomial
\begin{linenomath*}
\begin{equation}
\label{eq:mono}
b_{i_{1},\ldots,i_{k};j_{1},\ldots,j_{k}}x_{i_{1}j_{1}}\cdots
x_{i_{k}j_{k}}
\end{equation}
\end{linenomath*}
occurring in the indicator polynomial with a nonzero
coefficient.  By taking the $x_{ij}$ that occur in
(\ref{eq:mono}) large and all others small, we see that any
monomial that occurs in the indicator polynomial with a
nonzero coefficient can be made to dominate all others.
Hence all the nonzero coefficients have the same sign. The
converse is im-\linebreak mediate. \qquad\end{proof}

For SNS-matrix pairs $(S,C)$ with $C=O$ the indicator
polynomial is a homogeneous polynomial of degree $n$. In
this case Theorem \ref{th:prop} is a standard fact about
SNS-matrices.

\begin{lemma}[{\rm stability}]
\label{stability}
Given $T>0$, suppose that $\| \epsilon (t) \|_{1,2} \leq h^{q-2}$
for $0 \leq t \leq T$ and $q \geq 6$.
Then there exists a positive number $B$ that depends on
$T$ and the exact solution $\pe$ only such that for all $0 \leq t \leq T$,
\begin{linenomath*}
\begin{equation}
\label{Gron}
\frac {d}{dt} \| \epsilon (t) \| _{1,2}  \leq B
   ( h^{q-3/2} + \| \epsilon (t) \|_{1,2})\;.
\end{equation}
\end{linenomath*}
The function $B(T)$ can be chosen to be nondecreasing in time.
\end{lemma}

\begin{theorem}
\label{th:gibson}
The maximum number of nonzero entries in a {\rm SNS}-matrix
$S$ of order $n$ equals \[\frac{n^{2}+3n-2}{2}\] with
equality if and only if there exist permutation matrices
such that $P|S|Q=T_{n}$ where
\begin{linenomath*}
\begin{equation}
\label{eq:gibson}
T_{n}=\left[\begin{array}{cccccc} 1&1&\cdots&1&1&1\\
1&1&\cdots&1&1&1\\ 0&1&\cdots&1&1&1\\
\vdots&\vdots&\ddots&\vdots&\vdots&\vdots\\
0&0&\cdots&1&1&1\\ 0&0&\cdots&0&1&1\end{array}\right].
\end{equation}
\end{linenomath*}
\end{theorem}

We note for later use that each submatrix of $T_{n}$ of
order $n-1$ has all 1s on its main diagonal.

We now obtain a bound on the number of nonzero entries of
$S$ in a SNS-matrix pair $(S,C)$ in terms of the degree of
the indicator polynomial. We denote the strictly upper
triangular (0,1)-matrix of order $m$ with all 1s above the
main diagonal by $U_{m}$. The all 1s matrix of size $m$ by
$p$ is denoted by $J_{m,p}$.

\begin{proposition}[{\rm convolution theorem}]
\label{pro:2.1}  Let
\begin{linenomath*}
\begin{eqnarray*}
a\ast u(t) = \int_0^t a(t- \tau) u(\tau) d\tau, \hspace{.2in} t \in
(0, \infty).
\end{eqnarray*}
Then
\begin{eqnarray*}
\widehat{a\ast u}(s) = \widehat{a}(s)\widehat{u}(s).
\end{eqnarray*}
\end{linenomath*}
\end{proposition}

\begin{lemma}
\label{lem:3.1}
For $s_0 >0$, if
\begin{linenomath*}
$$
\int_0^{\infty} e^{-2s_0 t}v^{(1)}(t) v(t) dt \; \leq 0 \;,
$$
\end{linenomath*}
then
\begin{linenomath*}
\begin{eqnarray*}
\int_0^{\infty} e^{-2s_0 t} v^2(t) dt \; \leq \; \frac{1}{2s_0} v^2(0).
\end{eqnarray*}
\end{linenomath*}
\end{lemma}

\begin{corollary}\label{c4.1}
Let $ \bfE $ satisfy $(5)$--$(6)$ and
suppose $ \bfE^h $ satisfies $(7)$ and $(8)$
with a general $ \bfG $.  Let $ \bfG= \nabla \times {\bf \Phi} + \nabla p,$
$p \in H_0^1 (\Omega) $. Suppose that $\nabla p$ and $ \nabla \times
{\bf \Phi} $ satisfy all the assumptions of Theorems {\rm \ref{th:prop}} and
{\rm \ref{th:gibson}}, respectively. In addition suppose all the regularity
assumptions of Theorems {\rm \ref{th:prop}} and
{\rm \ref{th:gibson}} are satisfied.  Then
for $ 0 \le t \le T $ and $ 0 < \epsilon \le \epsilon_0 $ there exists a
constant $ C = C(\epsilon, T) $ such that
\begin{linenomath*}
$$
\Vert (\bfE - \bfE^h)(t) \Vert_0 \le C h^{k+1- \epsilon},
$$
\end{linenomath*}
where $ C $ also depends on the constants given in Theorems
$4.1$ and $4.2$.
\end{corollary}

\begin{definition}
{\rm Let $S$ be an isolated invariant set with isolating neighborhood $N$.
An {\em index pair} for $S$ is a pair of compact sets $(N_{1},N_{0})$
with $N_{0} \subset N_{1} \subset N$ such that:
\begin{romannum}
\item $cl(N_{1} \backslash N_{0})$
is an isolating neighborhood for $S$.
\item $N_{i}$ is positively invariant relative to $N$ for $i=0,1$,
i.e., given
$x \in N_{i}$ and $x \cdot [0,t] \subset N$, then $x \cdot [0,t] \subset
N_{i}$.
\item $N_{0}$ is an exit set for $N_{1}$, i.e. if $x \in N_{1}$,
$x \cdot [0, \infty ) \not\subset N_{1}$, then there is a $T \geq 0$ such
that $x \cdot [0,T] \subset N_{1}$ and $x \cdot T \in N_{0}$.
\end{romannum}}
\end{definition}

SIAM's preferred style for environments such as remarks, assumptions, and examples is italic lowercase headings and roman text.  They can be formatted by adding the line
\begin{verbatim}{\newtheorem{remark}[theorem]{\textit{Remark}}\end{verbatim} (as appropriate) to the preamble.  The body of each remark is made italic with the command \texttt{rm}.

\begin{remark}[Lagrange multipliers]{\rm
The multipliers $p,\,p_{1},\,p_{2}$ are the Lagrange multipliers for the given constraints. The Lagrange multiplier $p$ represents the PDE constraint, the multiplier $p_{1}$ gives the dependency
 of the initial control $w$ to the initial condition $\rho(0,\cdot),$ and, finally, $p_{2}$ represents the relation between the control $a$ and the inflow $\lW{\cdot}\rho(\cdot,0)$.}\end{remark}

\begin{assumption}[compatibility conditions on  $\ad,\rhoo$ and $\rhol,\rhoT$ and the weights in the cost functional]\label{ass:compatibility}{\rm
For continuity reasons, we require the two compatibility conditions
\begin{linenomath*}
\[
 \ad(0)=\lambda(W(0,\rhoo))\,\rhoo(0),\qquad \rhol(T)=\rhoT(1)
\]
\end{linenomath*}
to hold at the origin $(0,0)$ and at the final point $(T,1)$, respectively, and the conditions on the weights in the cost functional, that is,
\begin{linenomath*}
\[
 \alpha=\lambda(W(0,\rhoo))^{-1}\,\epsilon,\qquad\gamma=\delta.
\]
\end{linenomath*}
}\end{assumption}

There is no default style for algorithms in the macro at present, but the preferred style would have a heading like that for theorems, i.e., small caps.  The body of the algorithm, if not
code, may be either italic or roman.  The following sample uses the \texttt{algorithm} style package, with the addition of a definition to change the appearance of the heading.
\begin{algorithm}
\caption{\hspace*{-4.3pt}{.} $T = \operatorname{BuildTree}(d,p)$.}
\label{alg:buildtree}
\begin{algorithmic}
\STATE{Define $P:=T:=\{ \{1\},\ldots,\{d\}$\}}
\WHILE{$\#P > 1$}
\STATE{Choose $C^\prime\in\mathcal{C}_p(P)$ with $C^\prime := \operatorname{argmin}_{C\in\mathcal{C}_p(P)} \varrho(C)$}
\STATE{Find an optimal partition tree $T_{C^\prime}$ }
\STATE{Update $P := (P{\setminus} C^\prime) \cup \{ \bigcup_{t\in C^\prime} t \}$}
% \STATE{Update $T := T \cup \{ \bigcup_{t\in\tau} t: \tau\in T_{C^\prime}{\setminus}\mathcal{L}(T_{C^\prime}) \}$}
\STATE{Update $T := T \cup \{ \bigcup_{t\in\tau} t : \tau\in T_{C^\prime}{\setminus} \mathcal{L}(T_{C^\prime})\}$}
\ENDWHILE
\RETURN $T$
\end{algorithmic}
\end{algorithm}

\subsection{Numerical experiments, with figures and tables} We conducted numerical experiments
in computing inexact Newton steps for discretizations of a
{\em modified Bratu problem}, given by
\begin{linenomath*}
\begin{eqnarray}
{\ds \Delta w + c e^w + d{ {\partial w}\over{\partial x} } }
&=&{\ds f \quad {\rm in}\ D, }\nonumber\\[-1.5ex]
\label{bratu} \\[-1.5ex]
{\ds w }&=&{\ds 0 \quad {\rm on}\ \partial D , } \nonumber
\end{eqnarray}
\end{linenomath*}
where $c$ and $d$ are constants. The actual Bratu problem has $d=0$ and
$f \equiv0$. It provides a simplified model of nonlinear diffusion
phenomena, e.g., in combustion and semiconductors, and has been
considered by Glowinski, Keller, and Rheinhardt \cite{GloKR85},
as well as by a number of other investigators; see \cite{GloKR85}
and the references therein. See also problem 3 by Glowinski and  Keller
and problem 7 by Mittelmann in the collection of nonlinear model
problems assembled by Mor\'e \cite{More}. The modified problem
(\ref{bratu}) has been used as a test problem for inexact Newton
methods by Brown and Saad \cite{Brown-Saad1}.

In our experiments, we took $D = [0,1]\times[0,1]$, $f \equiv0$,
$c=d=10$, and discretized (\ref{bratu}) using the usual second-order
centered differences over a $100\times100$ mesh of equally
spaced points in $D$. In \gmres($m$), we took $m=10$ and used fast
Poisson right preconditioning as in the experiments in section \ref{S2}. The computing
environment was as described in section \ref{S2}. All computing was done
in double precision.

In the first set of experiments, we allowed each method to
run for $40$ {\gmresm} iterations, starting with zero as the initial
approximate solution, after which the limit of residual norm
reduction had been reached. The results are shown in Figure~\ref{f1}.
In Figure~\ref{f1}, the top curve was produced by method FD1.
The second curve from the top is actually a superposition of
the curves produced by methods EHA2 and FD2; the two curves are
visually indistinguishable. Similarly, the third curve from
the top is a superposition of the curves produced by methods EHA4
and FD4, and the fourth curve from the top, which lies barely above
the bottom curve, is a superposition of the curves produced by
methods EHA6 and FD6. The bottom curve was produced by method A.

\begin{figure}
\centering \subfigure[$\epsilon_{\textnormal{max}} =
5\%$]{\includegraphics{lexample_fig1}}\qquad
\subfigure[$\epsilon_{\textnormal{max}} =
0.5\%$]{\includegraphics{lexample_fig2}} \caption[]{Avoid use of low line weights and light colors, which
tend to disappear during printing.  Compare with Figure {\rm \ref{f2}}.}
\label{f1}
\end{figure}

\begin{figure}
\psfrag{lambda1}{\scriptsize$\lambda^2=1$}
\psfrag{lambda2}{\scriptsize$\lambda^2=10^{-3}$}
\psfrag{lambda3}{\scriptsize$\lambda^2=10^{-7}$}
\psfrag{lambda4}{\scriptsize$\lambda^2=0$}
\psfrag{deltat}{$\Delta t$}
\psfrag{Nerror}{$L^1$ error on $N$}
\psfrag{Psierror}{$L^1$ error on $\Psi$}
\subfigure{\includegraphics[scale=0.32]{lexample_fig3.eps}}
\subfigure{\includegraphics[scale=0.32]{lexample_fig4.eps}}
\caption{Note darker lines on this figure.}
\label{f2}
\end{figure}

In the second set of experiments, our purpose was to assess the
relative amount of computational work required by the methods
which use higher-order differencing to reach comparable levels
of residual norm reduction. We compared pairs of methods EHA2
and FD2, EHA4 and FD4, and EHA6 and FD6 by observing in each of
20 trials the number of {\gmresm} iterations, number of $F$-evaluations,
and run time required by each method to reduce the residual norm
by a factor of $\e$, where for each pair of methods $\e$ was chosen
to be somewhat greater than the limiting ratio of final to
initial residual norms obtainable by the methods. In these trials,
the initial approximate solutions were obtained by generating random
components as in the similar experiments in section \ref{S2}. We note that for every
method, the numbers of {\gmresm} iterations and $F$-evaluations required
before termination did not vary at all over the 20 trials. The {\gmresm}
iteration counts, numbers of $F$-evaluations, and means and standard
deviations of the run times are given in Table \ref{t1}.

\begin{table}
\caption{Tables are to appear in $8$-point {\rm(}{\tt footnotesize}{\rm)} type.}

\begin{center} {\footnotesize
\begin{tabular}{|c|c|c|c|c|c|} \hline
&& Number of & Number of & Mean run time & Standard \\
Method & $\e$ & iterations & $F$-evaluations& (seconds) & deviation \\ \hline
\lower.3ex\hbox{EHA2} & \lower.3ex\hbox{$10^{-10}$} & \lower.3ex\hbox{26} &
\lower.3ex\hbox{32} & \lower.3ex\hbox{47.12} & \lower.3ex\hbox{.1048} \\
FD2 & $10^{-10}$ & 26 & 58 & 53.79 & .1829 \\ \hline
\lower.3ex\hbox{EHA4} & \lower.3ex\hbox{$10^{-12}$} & \lower.3ex\hbox{30} &
\lower.3ex\hbox{42} & \lower.3ex\hbox{56.76} & \lower.3ex\hbox{.1855} \\
FD4 & $10^{-12}$ & 30 & 132 & 81.35 & .3730 \\ \hline
\lower.3ex\hbox{EHA6} & \lower.3ex\hbox{$10^{-12}$} & \lower.3ex\hbox{30} &
\lower.3ex\hbox{48} & \lower.3ex\hbox{58.56} & \lower.3ex\hbox{.1952} \\
FD6 & $10^{-12}$ & 30 & 198 & 100.6 & .3278 \\ \hline
\end{tabular}}
\end{center}
\label{t1}
\end{table}

In our first set of experiments, we took $c=d=10$ and used right
preconditioning with a fast Poisson solver from {\fishpack}
\cite{Swarztrauber-Sweet}, which is very effective for these
fairly small values of $c$ and $d$. We first started each method
with zero as the initial approximate solution and allowed it
to run for 40 {\gmresm} iterations, after which the limit of residual
norm reduction had been reached. Figure \ref{f2} shows plots
of the logarithm of the Euclidean norm of the residual versus
the number of {\gmresm} iterations for the three methods. We note
that in  Figure~\ref{f2} and in all other figures below, the plotted
residual norms were not the values maintained by {\gmresm}, but rather
were computed as accurately as possible ``from scratch.''  That is,
at each {\gmresm} iteration, the current approximate solution was
formed and its product with the coefficient matrix was subtracted
from the right-hand side, all in double precision.
It was important to compute the residual norms in this way because
the values maintained by {\gmresm} become increasingly untrustworthy
as the limits of residual norm reduction are neared; see \cite{Walker88}.
It is seen in Figure~\ref{f2} that Algorithm EHA achieved
the same ultimate level of residual norm reduction as the FDP
method and required only a few more {\gmresm} iterations to do
so.

In our second set of experiments, we took $c=d=100$ and carried out
trials analogous to those in the first set above. No preconditioning
was used in these experiments, both because we wanted to compare
the methods without preconditioning and because the fast
Poisson preconditioning used in the first set of experiments is
not cost effective for these large values of $c$ and $d$. We first
allowed each method to run for 600 {\gmresm} iterations,
starting with zero as the initial approximate solution, after which
the limit of residual norm reduction had been reached.

\section{Numbering and linking within the article}
The SIAM macro numbers sections, environments, and equations by section.  Environments may be given single numbers
by using the optional argument \texttt{onethmnum} in the \texttt{documentclass} command, and equations are single numbered
by including \texttt{oneeqnum}.  Tables and figures are given single numbers in the current SIAM macro to facilitate linking in the PDF.

\section{References}
References are usually numbered, but the author may also use a combination of letters and numbers in
brackets after {\tt bibitem} to create reference identifiers of his or her choice.  Use of \texttt{natbib} is also permitted.

The aforementioned style manual contains many examples of preferred styles for different types of references.

\section{Supplemental material}
Authors should use the standard SIAM macro for supplemental material that resembles the normal article, such as appendices.  Ideally, numbered items should be prefaced
by the letter M (as in Theorem M.1).

\section*{Acknowledgments}
The authors thanks the anonymous authors whose work largely constitutes this example file. We are also thankful for the many
recommendations and suggestions that have made this macro example file what it is today.

\begin{thebibliography}{10}
\bibitem{bs} {\sc R.~A. Brualdi and B.~L. Shader},
{\em On sign-nonsingular matrices and the conversion of the
permanent into the determinant}, in Applied Geometry and
Discrete Mathematics, The Victor Klee Festschrift, P.
Gritzmann and B. Sturmfels, eds., American Mathematical
Society, Providence, RI, 1991, pp. 117--134.

\bibitem{djd} {\sc J. Drew, C.~R. Johnson, and P. van den Driessche},
{\em Strong forms of nonsingularity}, Linear Algebra Appl.,
162 (1992), to appear.

\bibitem{g} {\sc P.~M. Gibson}, {\em Conversion of the permanent into the
determinant}, Proc. Amer. Math. Soc., 27 (1971),
pp.~471--476.

\bibitem{klm}
{\sc V.~Klee, R.~Ladner, and R.~Manber}, {\it
Signsolvability revisited}, Linear Algebra Appl., 59
(1984), pp.~131--157.

\bibitem{m}
{\sc K. Murota}, LU-{\em decomposition of a matrix with
entries of different kinds}, Linear Algebra Appl., 49
(1983), pp.~275--283.

\bibitem{Axelsson}
{\sc O.~Axelsson}, {\em Conjugate gradient type methods for unsymmetric and
  inconsistent systems of linear equations}, Linear Algebra Appl., 29 (1980),
  pp.~1--16.

\bibitem{BDM}
{\sc C. Bernardi, M. Dauge, and Y. Maday}, {\em Polynomials in the Sobolev
World}, \href{https://hal.archives-ouvertes.fr/hal-00153795v1}{https://hal.archives-ouvertes.fr/hal-00153795v1} (3 September 2007).

\bibitem{BMD09a}
{\sc C. Boutsidis, M.W. Mahoney, and P. Drineas},
 {\em An improved approximation algorithm for the column subset selection problem},
 in Proceedings of the 20th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), 2009, pp. 968--977.

\bibitem{Brown-Saad1}
{\sc P.~N. Brown and Y.~Saad}, {\em Hybrid {K}rylov methods for nonlinear
  systems of equations}, SIAM J. Sci. Statist. Comput., 11 (1990),
  pp.~450--481.

\bibitem{Cswarm11}
{\sc I.~Chattopadhyay}, {\em Scalable $\epsilon$-optimal self-organization in
  communicating swarms using implicit probabilistic automata}, in \ Proceedings of the American
  Control Conference (ACC), IEEE Press, Piscataway, NJ, 2012, pp.~6047--6052.

\bibitem{DES}
{\sc R.~S. Dembo, S.~C. Eisenstat, and T.~Steihaug}, {\em Inexact {N}ewton
  methods}, SIAM J. Numer. Anal., 19 (1982), pp.~400--408.

\bibitem{EES}
{\sc S.~C. Eisenstat, H.~C. Elman, and M.~H. Schultz}, {\em Variational
  iterative methods for nonsymmetric systems of linear equations}, SIAM J.
  Numer. Anal., 20 (1983), pp.~345--357.

\bibitem{Elman}
{\sc H.~C. Elman}, {\em Iterative methods for large, sparse, nonsymmetric
  systems of linear equations}, Ph.D. thesis, Department of Computer
  Science, Yale University, New Haven, CT, 1982.

\bibitem{GloKR85}
{\sc R.~Glowinski, H.~B. Keller, and L.~Rheinhart}, {\em Continuation-conjugate
  gradient methods for the least-squares solution of nonlinear boundary value
  problems}, SIAM J. Sci. Statist. Comput., 6 (1985), pp.~793--832.

\bibitem{Golub-VanLoan}
{\sc G.~H. Golub and C.~F. Van~Loan}, {\em Matrix Computations},
  Second ed., The Johns  Hopkins University Press, Baltimore, MD,  1989.

\bibitem{LiZeng2012a}
{\sc C. P. Li and F. H. Zeng,}  {\em Finite difference methods for
fractional differential equations}, {Internat. J. Bifur.
Chaos Appl. Sci. Engrg.}, {22} (2012), 1230014.

\bibitem{More}
{\sc J.~J. Mor\'e}, {\em A collection of nonlinear model problems}, in
  Computational Solutions of Nonlinear Systems of Equations, E.~L. Allgower and
  K.~Georg, eds., Lectures in Applied Mathematics, Vol. 26, American
  Mathematical Society, Providence, RI, 1990, pp.~723--762.

\bibitem{Saad}
{\sc Y.~Saad}, {\em Krylov subspace methods for solving large unsymmetric
  linear systems}, Math. Comp., 37 (1981), pp.~105--126.

\bibitem{Saad-Schultz}
{\sc Y.~Saad and M.~H. Schultz}, {\em {\rm GMRES}: A generalized minimal
  residual method for solving nonsymmetric linear systems}, SIAM J. Sci. Statist.
  Comput., 7 (1986), pp.~856--869.

\bibitem{SS13}
{\sc Cl.~Schillings and Ch.~Schwab}, {\em Sparsity in Bayesian inversion of parametric operator equations},
 Inverse Problems, 30 (2014), \href{http://dx.doi.org/10.1088/0266-5611/30/6/065007}{http://dx.doi.org/10.1088/0266-5611/30/6/065007}.

\bibitem{Swarztrauber-Sweet}
{\sc P.~N. Swarztrauber and R.~A. Sweet}, {\em Efficient {\rm FORTRAN}
  subprograms for the solution of elliptic partial differential equations}, ACM
  Trans. Math. Software, 5 (1979), pp.~352--364.

\bibitem{Walker88}
{\sc H.~F. Walker}, {\em Implementation of the {\rm GMRES} method using
  {H}ouseholder transformations}, SIAM J. Sci. Statist. Comput., 9 (1988),
  pp.~152--163.

\bibitem{Walker89}
{\sc H.~F. Walker}, {\em Implementations of
  the {\rm GMRES} method}, Computer Phys. Comm., 53 (1989),  pp.~311--320.

\end{thebibliography}

\end{document}


% $Source: /home/cvs/M2/Macaulay2/ComputationsBook/chapters/preface/chapter.tex,v $
% $Revision: 1.36.2.3 $
% $Date: 2001/05/22 14:47:48 $

\chapter*{Preface}
\markboth{Preface}{Preface}
\addcontentsline{toc}{section}{Preface}

\bgroup

Systems of polynomial equations arise throughout mathematics, science, and
engineering.
Algebraic geometry provides powerful theoretical techniques for
studying the qualitative and quantitative features of their solution sets.
Recently developed algorithms have made theoretical aspects of the subject
accessible to a broad range of mathematicians and scientists.
The algorithmic approach to the subject has two
principal aims: developing new tools for research within mathematics,
and providing new tools for modeling and solving problems
that arise in the sciences and engineering.  A healthy
synergy emerges, as new theorems yield new algorithms and emerging
applications lead to new theoretical questions.

This book presents algorithmic tools for algebraic geometry and experimental
applications of them.  It also introduces a
software system in which
the tools have been implemented and with which the experiments can
be carried out.  \Mtwo is a computer
algebra system devoted to supporting research in algebraic geometry,
commutative algebra, and their applications.
The reader of this book will encounter \Mtwo in the context of concrete
applications and
practical computations in algebraic geometry.

The expositions of the algorithmic tools presented here are designed to serve
as a useful guide for those wishing to bring such tools to bear on their own
problems.
A wide range of mathematical scientists should find these expositions valuable.
This includes both the users of other programs
similar to \Mtwo (for example, Singular and CoCoA) and those who
are not interested in explicit machine computations at all.

The chapters are ordered roughly by increasing mathematical
difficulty. The first part of the book is meant to be accessible to
graduate students and computer algebra users from across the
mathematical sciences and is primarily concerned
with introducing \Mtwo.  The second part emphasizes the
mathematics: each chapter exposes some domain of mathematics at an
accessible level, presents the relevant algorithms, sometimes with
proofs, and illustrates the use of the program.  In both parts, each chapter comes with
its own abstract and its own bibliography; the index at the back of
the book covers all of them.

One of the first computer algebra packages aimed at algebraic geometry
was {\sl Macaulay,} the predecessor of \Mtwo, written during the years
1983-1993 by Dave Bayer and Mike Stillman. Worst-case estimates
suggested that trying to compute Gr\"obner bases might be a hopeless
approach to solving problems. But from the first prototype, \Macaulay
was successful surprisingly often, perhaps because of the geometrical
origin of the problems attacked.  \Macaulay improved steadily during
its first decade.  It helped transform the theoretical notion of a
projective resolution into an exciting new practical research tool,
and became widely used for research and teaching in commutative
algebra and algebraic geometry.  It was possible to write routines in
the top-level language, and many important algorithms were added by
David Eisenbud and other users, enhancing the system and broadening its
usefulness.

There were certain practical drawbacks for the researcher who wanted to use
\Macaulay effectively.  A minor annoyance was that only finite prime fields
were available as coefficient rings.  The major problem was that the language
made available to users was primitive and barely supported high-level
development of new algorithms; it had few basic data types and didn't support
the addition of new ones.

\Mtwo is based on experience gained from writing and using its predecessor
\Macaulay, but is otherwise a fresh start.  It was written by Dan Grayson and
Mike Stillman with the generous financial support of the U.S. National
Science Foundation, with the work starting in 1993\footnote{NSF grants DMS
  92-10805, 92-10807, 96-23232, 96-22608, 99-70085, and 99-70348.}.
It also incorporates
some code from other authors: the package
SINGULAR-FACTORY\footnote{\texttt{SINGULAR-FACTORY},
        a subroutine library for factorization,
        by G.-M. Greuel, R. Stobbe, G. Pfister, H. Schoenemann, and J. Schmidt;
        available at ftp://helios.mathematik.uni-kl.de/pub/Math/Singular/Factory/.}
provides for factorization of polynomials;
SINGULAR-LIBFAC\footnote{\texttt{SINGULAR-LIBFAC},
        a subroutine library for characteristic sets and irreducible decomposition,
        by M. Messollen;
        available at ftp://helios.mathematik.uni-kl.de/pub/Math/Singular/Libfac/.}
uses FACTORY to enable the computation of characteristic
sets and thus the decomposition of subvarieties into their irreducible
components; and
GNU MP\footnote{\texttt{GMP}, a library for arbitrary precision arithmetic,
        by Torbj\"orn Granlund,
        John Amanatides,
        Paul Zimmermann,
        Ken Weber,
        Bennet Yee,
        Andreas Schwab,
        Robert Harley,
        Linus Nordberg,
        Kent Boortz,
        Kevin Ryde, and
        Guillaume Hanrot;
        available at {ftp://ftp.gnu.org/gnu/gmp/}.}
by Torbj\"orn Granlund and others provides
for multiple precision arithmetic.

\Mtwo aims to support efficient computation associated with a wide
variety of high level mathematical objects, including Galois fields,
number fields, polynomial rings, exterior algebras, Weyl algebras,
quotient rings, ideals, modules, homomorphisms of rings and modules,
graded modules, maps between graded modules, chain complexes, maps
between chain complexes, free resolutions, algebraic varieties, and
coherent sheaves.  To make the system easily accessible, standard
mathematical notation is followed closely.

As with \Macaulay, it was hoped that users would join in the further
development of new algorithms for \Mtwo, so the developers
tried to make the language available to
the users as powerful as possible, yet easy to use.
Indeed, much of the high-level part of the system is written in the same language
available to the user.  This ensures that the user will find it just as easy
as the developers did to implement a new type of mathematical object or to
modify the high-level aspects of the current algorithms.

The language available to the user is interpreted.  The interpreter itself
is written in a convenient language designed to be mostly type-safe and to
handle memory allocation and initialization automatically.  For maximum
efficiency, the core mathematical algorithms are written in C++ and compiled,
not interpreted.  This includes the arithmetic operations of rings, modules,
and matrices, the Gr\"obner basis algorithm (in several enhanced versions,
tailored for various situations), several algorithms for computing free
resolutions of modules, the algorithm for computing the Hilbert series of a
graded ring or module, the algorithms for computing determinants and
Pfaffians, the basis reduction algorithm, factoring, etc.

In one way \Mtwo is like a standard computer algebra system, such as {\sl
Mathematica} or {\sl Maple}: the user enters
mathematical expressions at the keyboard, and the program computes the value
of the expression and displays the answer.

Here is the first input prompt offered to the user.
\[\text{\tt i1\ :\ }\]
In response to the prompt, the user may enter, for example, a simple arithmetic expression.
<<<3/5 + 7/11>>>
The answer itself is displayed to the right of the output
label \[\text{\tt o1\ = \ }\] and its type (or class) is displayed to the
right of the following label.
\[\text{\tt o1\ :\ }\]
The symbol {\tt QQ} appearing in this example
denotes the class of all rational numbers, and is meant to be reminiscent of
the notation $\mathbb Q$.

\Mtwo often finds itself being run in a window with horizontal scroll bars,
so by default it does not wrap output lines, but instead lets them grow
without bound.  This book was produced by an automated mechanism that submits
code provided by the authors to \Mtwo and incorporates the result into the
text.  Output lines that exceed the width of the pages of this book are
indicated with ellipses, as in the following example.
<<<100!>>>

Next we describe an important difference between
general computer algebra systems (such as {\sl Maple} and {\sl Mathematica})
and \Mtwo.  Before entering an expression involving variables (such as {\tt x+y})
into \Mtwo the user must first create a ring containing those variables.
Rings are important
objects of study in algebraic geometry; quotient rings of polynomial rings,
for example, encapsulate the essential information about a system of
polynomial equations, including, for example, the field from which the
coefficients are drawn.  Often one has several rings under consideration at
once, along with ring homomorphisms between them, so it is important to treat
them as first-class objects in the computer, capable of being named and
manipulated the same way numbers and characters can be manipulated in simpler
programming languages.

Let's give a hint of the breadth of types of mathematical objects available
in \Mtwo with some examples.
In \Mtwo one defines a quotient ring of a polynomial ring $R$ over the
rational numbers by entering a command such as the one below.
<<<R = QQ[x,y,z]/(x^3-y^3-z^3)>>>
Having done that, we can compute in the ring.
<<<(x+y+z)^3>>>
We can make matrices over the ring.
<<<b = vars R>>>
<<<c = matrix {{x^2,y^2,z^2}}>>>
We can make modules over the ring.
<<<M = coker b>>>
<<<N = ker c>>>
We can make projective resolutions of modules.
<<<res M>>>
We can make projective varieties.
<<<X = Proj R>>>
We can make coherent sheaves and compute their  cohomology.
<<<HH^1 cotangentSheaf X >>>

At this writing, \Mtwo is available for GNU/Linux and other flavors of Unix,
and also for Microsoft Windows and the Macintosh operating system. Although it can be used
as a free-standing program, it is most convenient to use it in an
editor's buffer;
Emacs (on Unix or Windows systems) or MPW on Macintosh systems are
currently the editors of choice.
To obtain \Mtwo, download it from the
website\footnote{{\Mtwo}, a software system for research in algebraic geometry,
        by Daniel R. Grayson and Michael E. Stillman;
        available online in source code form and compiled for various architectures
        at \texttt{http://www.math.uiuc.edu/Macaulay2/}.}
and unpack the file.
Among the resulting files will be a file called {\tt Macaulay2/README.txt},
which you should read.  It will tell you how to run the {\tt setup} script,
and how to install a few lines of code in your {\tt emacs} init file to
enable you to run {\tt M2} in an emacs buffer and to edit \Mtwo code.  A
system administrator of a Unix system may optionally arrange for those lines
of code to be available to every emacs user.

The editors thank the authors of the chapters for their valuable
contributions and hard work, and the National Science Foundation for funding
the development of \Mtwo and for partial funding of the authors who have
contributed to this volume.

\nobreak
\bigskip
\nobreak
\vbox{
    \noindent
    May, 2001       \hfill\itshape   David Eisenbud\break
    \raggedleft                      Daniel R. Grayson\break
                                     Michael E. Stillman\break
                                     Bernd Sturmfels\par
}

\egroup


\documentclass[12pt]{article}

\title{CSC 420 - Assignment 2}
\author{ Group 3 \\
        Robert Krency, kre1188@calu.edu}
\date{\today}

\usepackage{tikz}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{setspace}

% Geometry
\usepackage{geometry}
\geometry{letterpaper, left=20mm, top=20mm, right=20mm, bottom=20mm}

\onehalfspacing

% Add vertical spacing to tables
\renewcommand{\arraystretch}{1.4}

% Macros
\newcommand{\definition}[1]{\underline{\textbf{#1}}}

\newenvironment{rcases}
  {\left.\begin{aligned}}
  {\end{aligned}\right\rbrace}

% Begin Document
\begin{document}

\maketitle

\vspace{1cm}

\section{Question 1}

Determine the order of nodes visited in the graph with each of the following algorithms:

\begin{enumerate}
    \item Breadth-First Search
    \begin{enumerate}
        \item 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
    \end{enumerate}

    \item Depth Limited Search (limit: 3)
    \begin{enumerate}
        \item 1, 2, 4, 8, 9, 5, 10, 11, 3, 6, 12
    \end{enumerate}

    \item Iterative Deepening Search
    \begin{enumerate}
        \item Limit 1 $\to$ 1, 2, 3
        \item Limit 2 $\to$ 1, 2, 4, 5, 3, 6, 7
        \item Limit 3 $\to$ 1, 2, 4, 8, 9, 5, 10, 11, 3, 6, 7
    \end{enumerate}

\end{enumerate}

\pagebreak
\section{Question 2}

\subsection{Problem Formulation}

\begin{description}
    \item[Initial State:] The Robot is at (1,1), 10 objects are available for pickup, 10 destinations are open for drop off.
    \item[Goal State:] The Robot is at (1,1) and all objects are placed in a destination.
    \item[Transition:] Go(row\#, col\#) moves the robot to the grid cell (row\#, col\#)
    \item[Action Cost:] The amount of grid spaces needed to move from current to destination.
\end{description}

In this case, each state would represent the action of moving to an Object and then moving it to a Destination.
The robot, in all cases, would also require a concluding action of returning to the start position.

As we generate each node, we would account for four values:

\begin{enumerate}
    \item Total Distance Traveled
    \item Distance between the Robot and the Object
    \item Distance between the Object and its Destination
    \item The heuristic value
\end{enumerate}

The proposed heuristic value would be the sum of two values:

\begin{enumerate}
    \item The sum of the distances between remaining objects and their closest open destination
    \item The distance between the destination and the start position
\end{enumerate}

\subsection{Search Algorithm Usage}

I would recommend usage of the A* algorithm in this case.
If we consider that moving to an object and then moving that object to a destination to be a State,
then the maximum amount of States that could be visited with $n$ nodes would be $O((n!)^2)$.

\pagebreak

\section{Question 3}

\subsection{Expand Dobreta}

\begin{center}
\begin{tikzpicture}

    \node [red] [draw] {Dobreta} [sibling distance = 4cm]
        child {node [draw] {Mehadia} edge from parent node [draw=none,fill=white] {$316$}}
        child {node [draw] {Craiova} edge from parent node [draw=none,fill=white] {$280$}};

\end{tikzpicture}
\end{center}

\subsection{Expand Craiova}

\begin{center}
\begin{tikzpicture}

    \node [draw] {Dobreta} [sibling distance = 4cm]
        child {node [draw] {Mehadia} edge from parent node [draw=none,fill=white] {$316$}}
        child {node [red] [draw] {Craiova}
            child {node [draw] {Pitesti} edge from parent node [draw=none,fill=white] {$358$}}
            child {node [draw] {Rimnicu Vilcea} edge from parent node [draw=none,fill=white] {$459$}}
            edge from parent node [draw=none,fill=white] {$280$}}

        ;

\end{tikzpicture}
\end{center}

\subsection{Expand Mehadia}

\begin{center}
\begin{tikzpicture}

    \node [draw] {Dobreta} [sibling distance = 4cm]
        child {node [red] [draw] {Mehadia}
            child {node [draw] {Lugoj} edge from parent node [draw=none,fill=white] {$389$}}
            edge from parent node [draw=none,fill=white] {$316$}
        }
        child {node [draw] {Craiova}
            child {node [draw] {Pitesti} edge from parent node [draw=none,fill=white] {$358$}}
            child {node [draw] {Rimnicu Vilcea} edge from parent node [draw=none,fill=white] {$459$}}
            edge from parent node [draw=none,fill=white] {$280$}
        }

        ;

\end{tikzpicture}
\end{center}

\subsection{Expand Pitesti}

\begin{center}
\begin{tikzpicture}

    \node [draw] {Dobreta} [sibling distance = 4cm]
        child {node [draw] {Mehadia}
            child {node [draw] {Lugoj} edge from parent node [draw=none,fill=white] {$389$}}
            edge from parent node [draw=none,fill=white] {$316$}
        }
        child {node [draw] {Craiova}
            child {node [red] [draw] {Pitesti}
                child {node [draw] {Bucharest} edge from parent node [draw=none,fill=white] {$359$}}
                edge from parent node [draw=none,fill=white] {$358$}
            }
            child {node [draw] {Rimnicu Vilcea} edge from parent node [draw=none,fill=white] {$459$}}
            edge from parent node [draw=none,fill=white] {$280$}
        }

        ;

\end{tikzpicture}
\end{center}

\subsection{Expand Bucharest}

\begin{center}
\begin{tikzpicture}

    \node [draw] {Dobreta} [sibling distance = 4cm]
        child {node [draw] {Mehadia}
            child {node [draw] {Lugoj} edge from parent node [draw=none,fill=white] {$389$}}
            edge from parent node [draw=none,fill=white] {$316$}
        }
        child {node [draw] {Craiova}
            child {node [draw] {Pitesti}
                child {node [red] [draw] {Bucharest} edge from parent node [draw=none,fill=white] {$359$}}
                edge from parent node [draw=none,fill=white] {$358$}
            }
            child {node [draw] {Rimnicu Vilcea} edge from parent node [draw=none,fill=white] {$459$}}
            edge from parent node [draw=none,fill=white] {$280$}
        }

        ;

\end{tikzpicture}
\end{center}

Search ends here, as the expansion candidate is the goal.

\end{document}


\documentclass{article}

% Imports
\usepackage{fancyhdr}
\usepackage{mathtools}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{enumitem}

% Macros
% Homework Macros
\newcommand{\hmwkTitle}{Homework 1}
\newcommand{\hmwkClass}{Class Title}
\newcommand{\hmwkClassTime}{Section 001}
\newcommand{\hmwkClassInstructor}{Professor's Name -}
\newcommand{\hmwkAuthorName}{Student's Name}
\newcommand{\hmwkUNID}{Student ID}
\newcommand{\tabHere}{\par\setlength\parindent{24pt}}

% Basic Document Settings
\topmargin		=-0.45in
\evensidemargin	=0in
\oddsidemargin	=0in
\textwidth		=6.5in
\textheight		=9.0in
\headsep		=0.25in

\linespread{1.1}

\pagestyle{fancy}
%\lhead{\hmwkAuthorName}
\lhead{\hmwkAuthorName}
\rhead{\hmwkClass\ (\hmwkClassInstructor\ \hmwkClassTime): \hmwkTitle}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

% Front Page
% Title Page
\title{
    \vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \vspace{0.1in}\large{\textit{\hmwkClassInstructor\ \hmwkClassTime}}
    \vspace{3in}
    \author{\textbf{\hmwkAuthorName}}
    \date{\today}
}

\begin{document}
	\maketitle
	\pagebreak

\subsection*{Problem 1. (Question 1, Section 7.1)}
(a.) $2x+y = (2x_1, 2x_2, 2x_3) + (y_1, y_2, y_3) = (1,3,5)$\\
(b.) $x\cdot y = -1 + 0 + 2 = 1$\\
(c.) $||x|| = \sqrt{x\cdot x} = \sqrt{1+0+4} = \sqrt{5}$,  $||y|| = \sqrt{y\cdot y} = \sqrt{1+9+1} = \sqrt{11}$\\
(d.) The cosine of the angle is given by
\[
\frac{u \cdot v}{||u||\hspace{.1cm} ||v||} = \cos \theta
\]
Therefore the cosine of the angle between $x$ and $y$ is
\[
\frac{x \cdot y}{||x||\hspace{.1cm} ||y||} = \frac{1}{\sqrt{5}\sqrt{11}} = \frac{1}{\sqrt{55}}\approx 0.13484
\]\\
(e.) The distance is given by the metric $||x-y||$ giving us
\[
\sqrt{(x-y) \cdot (x-y)} = \sqrt{(2,-3,1) \cdot (2,-3,1)} = \sqrt{14}
\]

\subsection*{Problem 2. (Question 6, Section 7.1)}
Let $u$ and $v$ be vectors in $\mathbb{R}^d$ where $v=au$ and $a\in\mathbb{R}$ and $a\neq0$ (trivial case). Then by the Cuachy Schwartz inequality we know that
\[
|u\cdot v| \leq ||u||\hspace{.1cm}||v||
\]
Substituting values for $v$ we get
\begin{align*}
	|u\cdot v|			 &\leq	 ||u||\hspace{.1cm}||v||  \\
	|u\cdot au|		   &\leq   ||u||\hspace{.1cm}||au||  \\
	|a(u\cdot u)|	  &\leq	  ||u||\hspace{.1cm}||au||  &\text{ by 7.1.4(c)}\\
	|a||u\cdot u|	&\leq	|a|\hspace{.1cm}||u||\hspace{.1cm}||u||  &\text{ by 7.1.10(b)}\\
	|u\cdot u|	&\leq	\sqrt{u\cdot u}\sqrt{u \cdot u} \\
	|u\cdot u|	&\leq	(u\cdot u)
\end{align*}
By by 7.1.4(d) it the inner product must always be positive, which means that
\[
|u\cdot u|	\leq	(u\cdot u) \implies |u\cdot u|	= (u\cdot u)
\]
Therefore if $v$ is a scalar multiple of $u$ it must be an equality.

\subsection*{Problem 3. Question 8, Section 7.1}
The prove that $||\cdot ||_\infty$ is a norm of $\mathbb{R}^d$ we must show that the following three conditions hold:
\begin{itemize}
	\item[(1)] $||x+y|| \leq ||x|| + ||y||$
	\item[(2)] $||ax||  = |a|||x||$
	\item[(3)] $ ||x|| = 0 \implies x=0$
\end{itemize}
\textbf{Condition 1:}\\
Let $x\in\mathbb{R}^d$ and $y\in\mathbb{R}^d$. Also, let $x_m = \max\{|x_1|, \dotsm, |x_d|\}$ and let $y_m = \max\{|y_1|, \dotsm, |y_d|\}$. By the triangle inequality we know that
\[
|x_m + y_m|  \leq |x_m| + |y_m| \implies ||x+y||_\infty \leq ||x||_\infty + ||y||_\infty
\]
Therefore it satisfies condition 1.
\pagebreak
\\\\\textbf{Condition 2:} \\
Distributing out the absolute value we see that
\[
|ax_m| = |a||x_m| \implies |a|||x||_\infty
\]
There it satisfies condition 2.
\\\\\textbf{Condition 3:}\\
If $||x||_\infty = 0$, then $\max\{ |x_1, \dotsm, x_d\}] = 0$. Since the maximum value of any $x_j \leq x_m$ and $x_m=0$, then all $x_j=0.$. Since this forces all $x_j =0$, then $x=(0, \dotsm, 0)$ for every entry in the vector so $x=0$
\\\\
As these three conditions are satisfied, we then know that $||\cdot||_\infty$ is a norm on $\mathbb{R}^d$.

\subsection*{Problem 4 (Question 12, Section 7.1)}
Note that
\[
\sum_{k=1}^{\infty} |x_ky_k| \leq\sum_{k=1}^{\infty} |x_ky_k|^2
\]
Then summing up to $n$, we can see by Cauchy Schwartz that
\[
\sum_{k=1}^{n} x_k^2 y_k^2  \leq \sum_{k=1}^{n} x_k^2\sum_{k=1}^{n} y_k^2
\]
Taking the limit gives us $n\to\infty$
\[
\sum_{k=1}^{\infty} |x_ky_k| \leq \sum_{k=1}^{\infty} x_k^2 y_k^2  \leq \sum_{k=1}^{\infty} x_k^2\sum_{k=1}^{\infty} y_k^2 < \infty \implies \sum_{k=1}^{\infty} |x_ky_k| < \infty
\]
\subsection*{Problem 5 (Question 1, Section 7.2)}
We have that $x_n - x = \big(\frac{n}{1+n}-1, \frac{1-n}{n}+1\big)$. Then
\[
||x_n - x|| = \bigg|\bigg|\bigg(\frac{n}{1+n}-1, \frac{1-n}{n}+1\bigg)\bigg|\bigg| = \sqrt{\bigg(\frac{n}{1+n}-1\bigg) ^2  +  \bigg(\frac{1-n}{n}+1\bigg)^2} = \sqrt{\frac{1}{(n+1)^2} + \frac{1}{n^2}}
\]
Then by approximation
\[
\sqrt{\frac{1}{(n+1)^2} + \frac{1}{n^2}} \leq \sqrt{\frac{2}{n^2}} = \frac{\sqrt{2}}{n}
\]
Set $N = \frac{\sqrt{2}}{\epsilon}$, then for all $\epsilon >0$, if $n>N$
\[
||x_n - x|| \leq \frac{\sqrt{2}}{n} \leq \frac{\sqrt{2}}{N} = \epsilon
\]
Showing that $(1,1)$ is indeed the limit.
\subsection*{Problem 6. (Question 2, Section 7.2)}
The sequence $\{x_n\}$ should converge. By Theorem 7.2.13  the sequence $\{x_n\}$ converges if and only if each component of $\{x_n\}$ converges to it's corresponding component of $x$. Let $x=(\frac{1}{3}, 1)$. If the limit for each component can be found then by 7.2.13 the vector should also converge.

From 3210, we know that
\[
\frac{n^2 + n -1}{3n^2+} \to \frac{1}{3} \hspace{.5cm}\text{ and }\hspace{.5cm} \frac{n-1}{n+1} \to 1
\]
Therefore $x_n \to x$ by Theorem 7.2.13.

\subsection*{Problem 7. (Question 12, Section 7.2)}
To prove something is a metric we must show that the following conditions are satisfied:
\begin{itemize}
	\item[(1)] $d(x,y) = d(y,x)$
	\item[(2)] $d(x,y) = 0 \text{ iff } x=y$
	\item[(3)] $d(x,z) \leq d(x,y) + d(y,z)$
\end{itemize}

From the problem description, condition (2) is given. Therefore we only need to show condition (1) and 3 are satisfied.
\\\\
(1) If $x\neq y$ then $y\neq x \implies d(y,x) = 1 = d(x,y) \implies d(x,y) = d(y,x)$ \\\\
(3) By cases, we can see that
\begin{itemize}
	\item if $x=y$         and $y=z 		\implies d(x,z) \leq d(x,y) + d(y,z) \implies 0 \leq 0$
	\item if $x\neq y$ and $y=z			\implies d(x,z) \leq d(x,y) + d(y,z) \implies 1 \leq 1$
	\item if $x= y$		   and $y\neq z	\implies d(x,z) \leq d(x,y) + d(y,z) \implies 1 \leq 1$
	\item if $x\neq y$ and $y\neq z$ and $x \neq  z\implies d(x,z) \leq d(x,y) + d(y,z) \implies 1\leq 2$
	\item if $x\neq y$ and $y\neq z$ and $x =  z\implies d(x,z) \leq d(x,y) + d(y,z) \implies 0\leq 2$
\end{itemize}
Since these are all true, then condition (3) is satisfied. Thus, since al three conditions are satisfied, we know that this is a metric on $\mathbb{R}$.

\subsection*{Problem 8. (Question 17, Section 7.2)}
Let $X$ be the set of rooms, and $d(x,y)$ be the shortest possible path from room $x$ to $y$. If we take the shortest possible path from room $x$ to $y$, then we can simply retrace our steps from room $y$ to $x$ to follow the exact same path. Therefore $d(x,y) = d(y,x)$
\\\\
If we are in room $x$ which also happens to be the same room as $y$, then the shortest path from $x$ to $y$ is to not move, since we are already in the room. Therefore $d(x,y)=0$ if $x=y$.
\\\\
Finally, If we start at room $x$ and plan to go to room $z$, but stop at at least one other room $y$ before arriving at $z$, then the distance it takes it go from room $x$ to $z$ if $y$ is along the way is the same as just going to room $z$ directly. (Assuming that "going" to a room doesn't take any extra time). However, if the room $y$ is not along the way, then we will have to spend some more time going to $y$, and then going back to room $z$, so overall the distance we walked was more than if had just went to room $z$ directly. Therefore, $d(x,z) \leq d(x,y) + d(y,z)$
\\\\
Since these three conditions are true in this situation, then our shortest possible path is a metric for the rooms in the building.

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% UMB-CS110-2015S: Introduction to Computing
% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>
% Creative Commons Attribution-ShareAlike 4.0 International License
% More info: https://github.com/ghorbanzade/UMB-CS110-2015S
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \topDirectory {.}
\def \texDirectory {\topDirectory/src/main/tex}

\documentclass[12pt,letterpaper,twoside]{article}
\usepackage{\texDirectory/template/style/directives}
\usepackage{\texDirectory/template/style/assignment}
\input{\texDirectory/template/config}

\begin{document}

\doc{title}{Final Exam Practice}
\doc{points}{20}

\prepare{header}

\subsection*{Question 1}

The following code snippet either do not compile or do not run as expected. There are five \textbf{distinct} problems. You are expected to find and fix all errors so that given command-line argument will lead to expected output as indicated.

%\lstset{language=java, tabsize=2}
\begin{lstlisting}
public class Factorial {
	public static void main(String[] args) {
		long product = 1;
		long a = Long.parseLong(args[0]);
		for (i = a: i >= 0: i--) {
			product *= a;
		}
		System.out.println(a! + " is " + product );
	}
}
\end{lstlisting}

\newpage

\subsection*{Question 2}

The following code snippet compiles and runs without error. Determine the output of the program and support your answer by explaining how the program works.

\begin{enumerate}[label=(\alph*)]
\item \texttt{Loops.java}
%\lstset{language=java, tabsize=2}
\begin{lstlisting}
public class Loops {
	public static void main(String[] args) {
		int num = 0;
		for (int i = 1; i <= 4; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(++num +" ");
			}
			System.out.println();
		}
	}
}
\end{lstlisting}
\item \texttt{Arrays.java}
%\lstset{language=java, tabsize=2}
\begin{lstlisting}
public class Arrays {
	public static void main(String[] args) {
		int[][] array = new int[5][4];
		for (int i = 0; i < array.length; i++)
			for (int j = 0; j < array[0].length; j++)
				array[i][j] = i*j;
		for (int i = 0; i < array[0].length; i++)
			System.out.print(array[i][2]*array[2][i]+" ");
	}
}
\end{lstlisting}
\end{enumerate}

\newpage

\subsection*{Question 3}

Your manager has called for an urgent meeting to announce that a recent patch to the project code was reported to have caused several crashes to the project software in some cases.

%\lstset{language=java, tabsize=2}
\begin{lstlisting}
import java.util.Scanner;
public class Patch {
	public static void main(String[] args) {
		Scanner scnr = new Scanner(System.in);
		int num = scnr.nextInt();
		scnr.close();
		int[] matrix = new int[num];
		for (int i = 0; i <= num; i++)
			matrix[i] = i;
		System.out.println((Math.sqrt(matrix[num/2]));
	}
}
\end{lstlisting}

He has asked you to explain the cause(s) of error and attach a new version of the patch that maintains control flow of the program regardless of user inputs.

\newpage

\subsection*{Question 4}

Develop a simple method \texttt{findPow(int num, int pow)} that can recursively calculate any power of a given number \texttt{num} by using built-in Java arithmetic operators.

\newpage

\subsection*{Question 5}

A fridge can be plugged or unplugged and can be set to operate at a desired temperature between $43$F to $68$F. You can store items as much as its capacity allows (assuming dimensions of items can be changed as desired). You can also take items out (based on their capacity) as long as the fridge is not empty.
You can always read a fridge's inner temperature and set your desired temperature. The inner temperature is fixed on the desired temperature while plugged and on room temperature (68F) while unplugged.

\begin{enumerate}[label=(\alph*)]
	\item Draw the UML diagram for class \texttt{Fridge.java}.
	\item Develop the class \texttt{Fridge.java} based on assumptions provided in question, respecting all object-oriented concepts.
	\item Develop a class \texttt{FridgeTest.java} to instantiate a fridge of capacity 15 cubic feet and keep 5 cubic feet of food in 50F.
\end{enumerate}

\newpage

\subsection*{Question 6}

Researchers at Winko Inc. have invented a new generation of cellphone batteries that discharge only during phone calls and at a rate of 0.1\% per minute. To make most out of this technology, Winko has decided to manufacture its own phones, called \textit{Winkophone}. Like any other phone, you can \texttt{call()} with a \textit{Winkophone} while its \texttt{battery} is not empty. Upon purchase, the battery of Winkophone is fully charged.

\begin{enumerate}[label=(\alph*)]
	\item Develop two classes \texttt{Phone.java} and \texttt{Winkophone.java} to be used in another class in which one can instantiate a Winkophone and use it.
	\item Draw the UML diagram for classes \texttt{Phone.java} and \texttt{Winkophone.java} and show relations between the two classes.
\end{enumerate}

\prepare{footer}

\end{document}