\section{Precise Definition of a Limit}\label{sec:LimitsFormal}

This section introduces the formal definition of a limit. Many refer to this as ``the epsilon--delta,'' definition, referring to the letters $\epsilon$ and $\delta$ of the Greek alphabet.\\

Before we give the actual definition, let's consider a few informal ways of describing a limit.  Given a function $y=f(x)$ and an $x$-value, $c$, we say that ``the limit of the function $f$, as $x$ approaches $c$, is a value~$L$'':

\begin{description}
\item[1.]if ``$y$ tends to $L$'' as ``$x$ tends to $c$.''
\item[2.]if ``$y$ approaches $L$'' as ``$x$ approaches $c$.''
\item[3.]if ``$y$ is near $L$'' whenever ``$x$ is near $c$.''
\end{description}

The problem with these definitions is that the words ``tends,'' ``approach,'' and especially ``near'' are not exact.  In what way does the variable $x$ tend to, or approach, $c$? How near do $x$ and $y$ have to be to $c$ and $L$, respectively?  \\

The definition we describe in this section comes from formalizing {\bf 3}.  A quick restatement gets us closer to what we want:

\begin{description}
\item[$\textbf{3}^\prime$.]If $x$ is within a certain \textit{tolerance level} of $c$, then the corresponding value $y=f(x)$ is within a certain \textit{tolerance level} of $L$.
\end{description}

The traditional notation for the $x$-tolerance is the lowercase Greek letter delta, or $\delta$, and the $y$-tolerance is denoted by lowercase epsilon, or $\epsilon$. One more rephrasing of $\textbf{3}^\prime$ nearly gets us to the actual definition:

\begin{description}
\item[$\textbf{3}^{\prime \prime}$.]If $x$ is within $\delta$ units of $c$, then the corresponding value of $y$ is within $\epsilon$ units of $L$.
\end{description}

We can write ``$x$ is within $\delta$ units of $c$'' mathematically as
$$|x-c| < \delta, \qquad \text{which is equivalent to }\qquad c-\delta < x < c+\delta.$$
Letting the symbol ``$\longrightarrow$'' represent the word ``implies,'' we can rewrite $\textbf{3}''$ as
$$
|x - c| < \delta \longrightarrow  |y - L| < \epsilon
\qquad \textrm{or} \qquad c - \delta < x < c + \delta \longrightarrow L - \epsilon < y < L + \epsilon.
$$
The point is that $\delta$ and $\epsilon$, being tolerances, can be any positive (but typically small) values.  Finally, we have the formal definition of the limit with the notation  seen in the previous section.

\begin{definition}{The Limit of a Function $f$}{def:limit}
{Let $I$ be an open interval containing $c$, and let $f$ be a function defined on $I$, except possibly at $c$. The \textit{limit of $f(x)$, as $x$ approaches $c$, is $L$}, denoted by
$$\displaystyle \lim_{x\rightarrow c} f(x) = L,$$
means that given any $\epsilon > 0$, there exists $\delta > 0$ such that for all $x\neq c$,
if  $|x - c| < \delta$, then $|f(x) - L| < \epsilon$.\index{limit!definition}
}
\end{definition}

(Mathematicians often enjoy writing ideas without using any words. Here is the wordless definition of the limit:\\

$\displaystyle \lim_{x\rightarrow c} f(x) = L \iff$
$\forall \, \epsilon > 0, \exists \, \delta > 0 \; s.t. \;
0<|x - c| < \delta \longrightarrow |f(x) - L| < \epsilon$.\text{)}\\

Note the order in which $\epsilon$ and $\delta$ are given.  In the definition, the $y$-tolerance $\epsilon$ is given \textit{first} and then the limit will exist {\bf if} we can find an $x$-tolerance $\delta$ that works.

An example will help us understand this definition.  Note that the explanation is long, but it will take one through all steps necessary to understand the ideas.\\

\begin{example}{Evaluating a limit using the definition}{ex_compute_lim1}{
Show that $\displaystyle \lim_{x\rightarrow 4} \sqrt{x} = 2 $.}
\end{example}

\begin{solution}
{Before we use the formal definition, let's try some numerical tolerances.  What if the $y$ tolerance is 0.5, or $\epsilon =0.5$?  How close to 4 does $x$ have to be so that $y$ is within 0.5 units of 2, i.e., $1.5 < y < 2.5$?  In this case, we can proceed as follows:
\begin{align*}
1.5 &< \parbox{15pt}{\centering $y$} < 2.5 \\
1.5 &< \parbox{15pt}{\centering $\sqrt{x}$} < 2.5\\
1.5^2 &< \parbox{15pt}{\centering $x$} < 2.5^2\\
2.25 &< \parbox{15pt}{\centering $x$} < 6.25.
\end{align*}

So, what is the desired $x$ tolerance?  Remember, we want to find a symmetric interval of $x$ values, namely
$4 - \delta < x < 4 + \delta$.  The lower bound of $2.25$ is $1.75$ units from 4; the upper bound of 6.25 is 2.25 units from 4. We need the smaller of these two distances; we must have $\delta \leq 1.75$. See Figure \ref{fig:choose_e_d}.\\

\begin{figure}
	\centering
	\begin{subfigure}[t]{0.5\textwidth}
		\begin{tikzpicture}
		\begin{axis}[minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-.1,ymax=3.1,xmin=-.1,xmax=7.1,xtick={2,4,6},ytick={1,2},name=myplot]
		\addplot [{\colorone},thick,smooth] coordinates {(0.,0.) (0.05,0.223607) (0.1,0.316228) (0.15,0.387298) (0.2,0.447214) (0.25,0.5) (0.5,0.707107) (0.75,0.866025) (1.,1.) (1.25,1.11803) (1.5,1.22474) (1.75,1.32288) (2.,1.41421) (2.25,1.5)(2.5,1.58114) (2.75,1.65831) (3.,1.73205) (3.25,1.80278)(3.5,1.87083) (3.75,1.93649) (4.,2.) (4.25,2.06155) (4.5,2.12132)(4.75,2.17945) (5.,2.23607) (5.25,2.29129) (5.5,2.34521) (5.75,2.39792) (6.,2.44949) (6.25,2.5)(6.5,2.54951) (6.75,2.59808) (7.,2.64575)
		};
		\fill[black] (axis cs:4,2) circle (1pt);
		\draw[thin,dashed,thick,{\colortwo}] (axis cs:0,1.5) -- (axis cs:2.25,1.5);
		\draw[thin,dashed,thick,{\colortwo}] (axis cs:0,2.5) -- (axis cs:6.25,2.5);
		\draw (axis cs:-.1,1.75) node [right]{ $\left.\rule{0pt}{7.5pt}\right\}\epsilon = .5$};
		\draw (axis cs:-.1,2.25) node [right]{ $\left.\rule{0pt}{7.5pt}\right\}\epsilon = .5$};
		\fill[{\colortwo}] (axis cs:2.25,1.5) circle (1pt);
		\fill[{\colortwo}] (axis cs:6.25,2.5) circle (1pt);
		\draw (axis cs:4,1) node [text width = 80pt,align=center] {  Choose $\epsilon>0$. Then ...};
		\end{axis}
		%\fill[{\colortwo}] (1,1) circle (1pt);
		\node [right] at (myplot.right of origin) {  $x$};
		\node [above] at (myplot.above origin) {  $y$};
		\end{tikzpicture}
        \label{ }
        \caption{}
    \end{subfigure}%
    \begin{subfigure}[t]{0.5\textwidth}
    \begin{tikzpicture}[>=stealth]
    \begin{axis}[minor x tick num=1,axis y line=middle,axis x line=middle,ymin=-.1,ymax=3.1,xmin=-.1,xmax=7.1,xtick={2,4,6},ytick={1,2},name=myplot]
    \addplot [{\colorone},smooth,thick] coordinates {(0.,0.) (0.05,0.223607) (0.1,0.316228) (0.15,0.387298) (0.2,0.447214) (0.25,0.5) (0.5,0.707107) (0.75,0.866025) (1.,1.) (1.25,1.11803) (1.5,1.22474) (1.75,1.32288) (2.,1.41421) (2.25,1.5)(2.5,1.58114) (2.75,1.65831) (3.,1.73205) (3.25,1.80278)(3.5,1.87083) (3.75,1.93649) (4.,2.) (4.25,2.06155) (4.5,2.12132)(4.75,2.17945) (5.,2.23607) (5.25,2.29129) (5.5,2.34521) (5.75,2.39792) (6.,2.44949) (6.25,2.5)(6.5,2.54951) (6.75,2.59808) (7.,2.64575)
    };
    \fill[black] (axis cs:4,2) circle (1pt);
    \draw[thin,dashed,gray,thick] (axis cs:0,1.5) -- (axis cs:2.25,1.5);
    \draw[thin,dashed,gray,thick] (axis cs:0,2.5) -- (axis cs:6.25,2.5);
    \draw[thin,dashed,{\colortwo},thick] (axis cs:2.25,0) -- (axis cs:2.25,1.5);
    \draw[thin,dashed,{\colortwo},thick] (axis cs:6.25,0) -- (axis cs:6.25,2.5);
    \draw (axis cs:-.1,1.75) node [right]{$\left.\rule{0pt}{7.5pt}\right\}\epsilon = .5$};
    \draw (axis cs:-.1,2.25) node [right]{$\left.\rule{0pt}{7.5pt}\right\}\epsilon = .5$};
    \fill[{\colortwo}] (axis cs:2.25,1.5) circle (1pt);
    \fill[{\colortwo}] (axis cs:6.25,2.5) circle (1pt);
    \draw (axis cs:3.125,.1) node [above,align=center,text width = 45pt] { width\\[-2pt] = 1.75\\[-3pt] $\overbrace{\rule{30pt}{0pt}}$};
    \draw (axis cs:5.125,.1) node [above,align=center,text width = 45pt] { width\\[-2pt] = 2.25\\[-3pt] $\overbrace{\rule{39pt}{0pt}}$};
    \draw (axis cs:4.3,1.35)	node [align=center,text width = 80pt] { ... choose $\delta$ smaller than each of these};
    \draw [->,thin] (axis cs:4,1) -- (axis cs:3,.8);
    \draw [->,thin] (axis cs:4,1) -- (axis cs:5,.8);
    \end{axis}
    %\fill[{\colortwo}] (1,1) circle (1pt);
    \node [right] at (myplot.right of origin) { $x$};
    \node [above] at (myplot.above origin) { $y$};
    \end{tikzpicture}
        \label{ }
        \caption{With $\epsilon=0.5$, we pick any $\delta < 1.75$.}
    \end{subfigure}
    \caption{ Illustrating the $\epsilon-\delta$ process. \label{fig:choose_e_d}}
\end{figure}

NOTE: The concept of a \dfont{one-sided limit} can also be made precise.

\begin{definition}{One-sided Limit}{onesided}
 Suppose that $f(x)$ is a function. We say that
$\ds \lim_{x\to a^-}f(x)=L$ if for every $\epsilon>0$ there is a $\delta >
0$ so that whenever $0 < a-x < \delta$, $|f(x)-L|<\epsilon$.  We say
that $\ds\lim_{x\to a^+}f(x)=L$ if for every $\epsilon>0$ there is a
$\delta > 0$ so that whenever $0 < x-a < \delta$, $|f(x)-L|<\epsilon$.
\end{definition}

%\mtable{.4}{Illustrating the $\epsilon-\delta$ process.}{fig:choose_e_d}{%
%%		\begin{tabular}{c}
%		\myincludegraphics{figures/figLimitProof1a}\\
%		\myincludegraphics{figures/figLimitProof1b}\\
%		\noindent\parbox{200pt}{With $\epsilon=0.5$, we pick any $\delta < 1.75$.}
%%		\end{tabular}
%	}

Given the $y$ tolerance $\epsilon =0.5$, we have found an $x$ tolerance, $\delta \leq 1.75$, such that whenever $x$ is within $\delta$ units of 4, then $y$ is within $\epsilon$ units of 2.  That's what we were trying to find.\\

Let's try another value of $\epsilon$.\\

What if the $y$ tolerance is 0.01, i.e.,  $\epsilon =0.01$?  How close to 4 does $x$ have to be in order for $y$ to be within 0.01 units of 2 (or $1.99 < y < 2.01$)?  Again, we just square these values to get
$1.99^2 < x < 2.01^2$, or
$$3.9601 < x < 4.0401.$$
What is the desired $x$ tolerance?  In this case we must have $\delta \leq 0.0399$, which is the minimum distance from 4 of the two bounds given above.  %Note that in some sense, it looks like there are two tolerances (below 4 of 0.0399 units and above 4 of 0.0401 units).  However, we couldn't use the larger value of $0.0401$ for $\delta$ since then the interval for $x$ would be  $3.9599 < x < 4.0401$ resulting in $y$ values of $1.98995 < y < 2.01$ (which contains values NOT within 0.01 units of 2).\\

What we have so far: if $\epsilon =0.5$, then $\delta \leq 1.75$ and if $\epsilon = 0.01$, then $\delta \leq 0.0399$. A pattern is not easy to see, so we switch to general $\epsilon$ try to determine $\delta$ symbolically.  We start by assuming $y=\sqrt{x}$ is within $\epsilon$ units of 2:

\begin{eqnarray*}
|y - 2| < \epsilon &\\
-\epsilon < y - 2 < \epsilon& \qquad \textrm{(Definition of absolute value)}\\
-\epsilon < \sqrt{x} - 2 < \epsilon  &\qquad (y=\sqrt{x})\\
2 - \epsilon < \sqrt{x} < 2+ \epsilon &\qquad \textrm{ (Add 2)}\\
(2 - \epsilon)^2 < x < (2+ \epsilon) ^2 &\qquad \textrm{ (Square all)}\\
4 - 4\epsilon + \epsilon^2 < x < 4 + 4\epsilon + \epsilon^2 &\qquad \textrm{ (Expand)}\\
4 - (4\epsilon - \epsilon^2) < x < 4 + (4\epsilon + \epsilon^2). &\qquad \textrm{ (Rewrite in the desired form)}
\end{eqnarray*}

The ``desired form'' in the last step is ``$4-\textit{something} < x < 4 +\textit{something}$.''
Since we want this last interval to describe an $x$ tolerance around 4, we have that either $\delta \leq 4\epsilon - \epsilon^2$ or $\delta \leq 4\epsilon + \epsilon^2$, whichever is smaller: $$\delta \leq \min\{4\epsilon - \epsilon^2, 4\epsilon + \epsilon^2\}.$$  Since $\epsilon > 0$, the minimum is $\delta \leq 4\epsilon - \epsilon^2$.  That's the formula: given an $\epsilon$, set $\delta \leq 4\epsilon-\epsilon^2$.

We can check this for our previous values.  If $\epsilon=0.5$, the formula gives
$\delta \leq 4(0.5) - (0.5)^2 = 1.75$ and when $\epsilon=0.01$, the formula gives $\delta \leq 4(0.01) - (0.01)^2 = 0.399$.
%\drawexampleline

So given any $\epsilon >0$, set $\delta \leq 4\epsilon - \epsilon^2$. Then if $|x-4|<\delta$ (and $x\neq 4$), then $|f(x) - 2| < \epsilon$,  satisfying the definition of the limit.  We have shown formally (and finally!) that $\displaystyle \lim_{x\rightarrow 4} \sqrt{x} = 2 $.
}
\end{solution}

%FOOTNOTE $**$: Actually, it is a pain, but this won't work if $\epsilon \ge 4$.  This shouldn't really occur since $\epsilon$ is supposed to be small, but it could happen.  In the cases where $\epsilon \ge 4$, just take $\delta = 1$ and you'll be fine.
The previous example was a little long in that we sampled a few specific cases of $\epsilon$ before handling the general case. Normally this is not done.  The previous example is also a bit unsatisfying in that $\sqrt{4}=2$; why work so hard to prove something so obvious? Many $\epsilon$-$\delta$ proofs are long and difficult to do. In this section, we will focus on examples where the answer is, frankly, obvious, because the non--obvious examples are even harder. In the next section we will learn some theorems that allow us to evaluate limits \textit{analytically}, that is, without using the $\epsilon$-$\delta$ definition.\\
%That is why theorems about limits are so useful! After doing a few more $\epsilon$--$\delta$ proofs, you will really appreciate the analytical ``short cuts'' found in the next section.\\

\begin{example}{Evaluating a limit using the definition}{ex_compute_lim2}{
Show that $\displaystyle \lim_{x\rightarrow 2} x^2 = 4$.}
\end{example}

\begin{solution}
{Let's do this example symbolically from the start.  Let $\epsilon > 0$ be given; we want $|y-4| < \epsilon$, i.e.,  $|x^2-4| < \epsilon$.  How do we find $\delta$ such that when $|x-2| < \delta$, we are guaranteed that $|x^2-4|<\epsilon$?% for some $\delta$ (in terms of $\epsilon$)?

This is a bit trickier than the previous example, but let's start by noticing that
$|x^2-4| = |x-2|\cdot|x+2|$.  Consider:\\
\begin{equation} |x^2-4| < \epsilon \longrightarrow |x-2|\cdot|x+2| < \epsilon \longrightarrow |x-2| < \frac{\epsilon}{|x+2|}.\label{eq:limit1}\end{equation}
Could we not set $\displaystyle \delta = \frac{\epsilon}{|x+2|}$?

We are close to an answer, but the catch is that $\delta$ must be a \textit{constant} value (so it can't contain $x$).  There is a way to work around this, but we do have to make an assumption.  Remember that $\epsilon$ is supposed to be a small number, which implies that $\delta$ will also be a small value.  In particular, we can (probably) assume that $\delta < 1$.  If this is true, then $|x-2| < \delta$ would imply that $|x-2| < 1$, giving $1 < x < 3$.

Now, back to the fraction $\displaystyle \frac{\epsilon}{|x+2|}$.  If $1<x<3$, then $3<x+2<5$ (add 2 to all terms in the inequality).  Taking reciprocals, we have
\begin{align}
\frac15 <& \frac1{|x+2|} < \frac 13 & \text{which implies}\notag\\
\frac15 <& \frac1{|x+2|} & \text{which implies}\notag\\
\frac\epsilon5<&\frac{\epsilon}{|x+2|}.\label{eq:limit2}
\end{align}

%$\displaystyle \frac{1}{5}<\frac{1}{|x+2|}<\frac{1}{3}$ so that, in particular,
%\begin{equation} \frac{\epsilon}{5}<\frac{\epsilon}{|x+2|}.\label{eq:limit2}\end{equation}
This suggests that we set
$\displaystyle \delta \leq \frac{\epsilon}{5}$. To see why, let consider what follows when we assume $|x-2|<\delta$:

\small
\begin{align*}
|x - 2| &< \delta &\\
|x - 2| &< \frac{\epsilon}{5}&  \text{\small(Our choice of $\delta$)}\\
|x - 2|\cdot|x + 2| &< |x + 2|\cdot\frac{\epsilon}{5}&  \text{\small(Multiply by $|x+2|$)}\\
|x^2 - 4|&< |x + 2|\cdot\frac{\epsilon}{5}&  \text{\small(Combine left side)}\\
|x^2 - 4|&< |x + 2|\cdot\frac{\epsilon}{5}< |x + 2|\cdot\frac{\epsilon}{|x+2|}=\epsilon &
\text{\small(Using (\ref{eq:limit2}) as long as $\delta <1$)}
\end{align*}
\normalsize

We have arrived at $|x^2 - 4|<\epsilon$ as desired.  Note again, in order to make this happen we needed $\delta$ to first be less than 1.  That is a safe assumption; we want $\epsilon$ to be arbitrarily small, forcing $\delta$ to also be small.

We have also picked $\delta$ to be smaller than ``necessary.'' We could get by with a slightly larger $\delta$, as shown in Figure \ref{fig:limit_eover5}. The dashed outer lines show the boundaries defined by our choice of $\epsilon$. The dotted inner lines show the boundaries defined by setting $\delta = \epsilon/5$. Note how these dotted lines are within the dashed lines. That is perfectly fine; by choosing $x$ within the dotted lines we are guaranteed that $f(x)$ will be within $\epsilon$ of 4.%If the value we eventually used for $\delta$, namely $\epsilon/5$, is not less than 1, this proof won't work.  For the final fix, we instead set $\delta$ to be the minimum of 1 and $\epsilon/5$. This way all calculations above work.

\mfigure{.8}{Choosing $\delta = \epsilon/5$ in Example \ref{ex_compute_lim2}.}{fig:limit_eover5}{ %
\begin{tikzpicture}
\begin{axis}[axis y line=middle,axis x line=middle,ymin=2,ymax=6,xmin=1.3,xmax=3.3,xtick={2},ytick={4},name=myplot]
\addplot [{\colorone},smooth,thick] coordinates {((0.,0.) (0.25,0.0625) (0.5,0.25) (0.75,0.5625) (1.,1.) (1.25,1.5625)
(1.5,2.25) (1.75,3.0625) (2.,4.) (2.25,5.0625) (2.5,6.25)
(2.75,7.5625) (3.,9.)
};
\fill[black] (axis cs:2,4) circle (1pt);
\draw[thin,dashed,thick,{\colortwo}] (axis cs:0,3) -- (axis cs:1.73,3);
\draw[thin,dashed,thick,{\colortwo}] (axis cs:0,5) -- (axis cs:2.24,5);
\draw[thin,dashed,thick,{\colortwo}] (axis cs:2.24,0) -- (axis cs:2.24,5);
\draw[thin,dashed,thick,{\colortwo}] (axis cs:1.73,0) -- (axis cs:1.73,3);
\draw[dotted,ultra thick,gray] (axis cs:2.2,0) -- (axis cs:2.2,4.84);
\draw[dotted,ultra thick,gray] (axis cs:1.8,0) -- (axis cs:1.8,3.24);
\draw (axis cs:-.1,4.5) node [right]{ $\left.\rule{0pt}{12pt}\right\}\epsilon$};
\draw (axis cs:2.1,2.15) node [above] { $\delta$};
\draw (axis cs:2.1,2.05) node [above,scale=.35] {$\overbrace{\phantom{..........}}$};
\draw (axis cs:2.3,4.5)  -- (axis cs: 3.2,4.5);
\draw (axis cs:2.3,4.3)  -- (axis cs: 2.5,4.3);
\draw (axis cs:2.75,4.7) node [align=center]{  length of $\epsilon$};
\draw (axis cs:2.75,3.9) node [align=center,text width=35pt]{ length of\\[-2pt] $\delta=\epsilon/5$};
\fill[{\colortwo}] (axis cs:1.73,3) circle (1pt);
\fill[{\colortwo}] (axis cs:2.24,5) circle (1pt);
\end{axis}
%\fill[{\colortwo}] (1,1) circle (1pt);
\node [right] at (myplot.right of origin) {  $x$};
\node [above] at (myplot.above origin) { $y$};
\end{tikzpicture}}

In summary, given $\epsilon > 0$, set $\delta=\leq\epsilon/5$.  Then $|x - 2| < \delta$ implies
$|x^2 - 4|< \epsilon$ (i.e. $|y - 4|< \epsilon$) as desired.  This shows that $\displaystyle \lim_{x\rightarrow 2} x^2 = 4 $. Figure \ref{fig:limit_eover5} gives a visualization of this; by restricting $x$ to values within $\delta = \epsilon/5$ of 2, we see that $f(x)$ is within $\epsilon$ of $4$.
}
\end{solution}

It probably seems obvious that $\ds \lim_{x\to2}x^2=4$, and it is worth
examining more closely why it seems obvious. If we write $\ds x^2=x\cdot
x$, and ask what happens when $x$ approaches 2, we might say something
like, ``Well, the first $x$ approaches 2, and the second $x$
approaches 2, so the product must approach $2\cdot2$.'' In fact this is
pretty much right on the money, except for that word ``must.'' Is it
really true that if $x$ approaches $a$ and $y$ approaches $b$ then
$xy$ approaches $ab$? It is, but it is not really obvious, since $x$
and $y$ might be quite complicated. The good news is that we can see
that this is true once and for all, and then we don't have to worry
about it ever again. When we say that $x$ might be ``complicated'' we
really mean that in practice it might be a function. Here is then what
we want to know:

\begin{theorem}{Limit Product}{LimitProduct}
Suppose $\ds \lim_{x\to a} f(x)=L$ and $\ds \lim_{x\to a}g(x)=M$. Then
$\ds \lim_{x\to a} f(x)g(x) = LM$.
\end{theorem}

\begin{proof}
We must use the Precise Definition of a Limit to prove the Produce Law for Limits.
So given any $\epsilon$ we need to find a $\delta$ so that $0<|x-a|<\delta$ implies
$|f(x)g(x)-LM|<\epsilon$. What do we have to work with? We know that we can make
$f(x)$ close to $L$ and $g(x)$ close to $M$, and we have to somehow connect these
facts to make $f(x)g(x)$ close to $LM$.

We use, as is often the case, a little algebraic trick:
\begin{align*}
|f(x)g(x)-LM|&=|f(x)g(x)-f(x)M+f(x)M-LM|	\\
&=|f(x)(g(x)-M)+(f(x)-L)M|	\\
&\leq |f(x)(g(x)-M)|+|(f(x)-L)M|	\\
&=|f(x)||g(x)-M|+|f(x)-L||M|.
\end{align*}

This is all straightforward except perhaps for the ``$\leq$''. That is an example
of the \emph{triangle inequality}, which says that if $a$ and $b$ are any real numbers
then $|a+b|\leq|a|+|b|$. If you look at a few examples, using positive and negative numbers
in various combinations for $a$ and $b$, you should quickly understand why this is true.
We will not prove it formally.

Suppose $\epsilon>0$. Since $\ds\lim_{x\to a} f(x)=L$, there is a value $\delta_1$
such that $0<|x-a|<\delta_1$ implies $\ds|f(x)-L|<\frac{\epsilon}{2(1+|M|)}$.
This means that $0<|x-a|<\delta_1$ implies $|f(x)-L||M|<|f(x)-L|(1+|M|)<\epsilon/2$.

Now we focus our attention on the other term in the inequality, $|f(x)||g(x)-M|$.
We can make $|g(x)-M|$ smaller than any fixed number by making $x$
close enough to $a$; unfortunately, $\epsilon/(2f(x))$ is not a fixed
number, since $x$ is a variable. Here we need another little trick,
just like the one we used in analyzing $x^2$. We can find a $\delta_2$
so that $|x-a|<\delta_2$ implies that $|f(x)-L|<1$, meaning that $L-1
< f(x) < L+1$. This means that $|f(x)|<N$, where $N$ is either $|L-1|$
or $|L+1|$, depending on whether $L$ is negative or positive. The
important point is that $N$ doesn't depend on $x$. Finally, we know that
there is a $\delta_3$ so that $0<|x-a|<\delta_3$ implies
$|g(x)-M|<\epsilon/(2N)$. Let $\delta$ be the smallest of $\delta_1$, $\delta_2$, and
$\delta_3$. Then $|x-a|<\delta$ implies that
$|f(x)-L|<\epsilon/(2(1+|M|))$, $|f(x)|<N$, and
$|g(x)-M|<\epsilon/(2N)$. Then
\begin{align*}
|f(x)g(x)-LM|&\leq |f(x)||g(x)-M|+|f(x)-L||M|	\\
&< N\frac{\epsilon}{2N}+\frac{\epsilon}{2(1+|M|)}(1+|M|)	\\
&=\frac{\epsilon}{2}+\frac{\epsilon}{2}=\epsilon.
\end{align*}
This is just what we needed, so by the official definition,
$\ds \lim_{x\to a}f(x)g(x)=LM$.
\end{proof}

Examples \ref{exa:ex_compute_lim1} and \ref{exa:ex_compute_lim2} determine $\delta$ by using logic that is difficult to recreate as one learns this topic. For instance, Equation \eqref{eq:limit2} is used based on the following facts:
	\begin{enumerate}
	\item		We want $\delta \leq \frac{\epsilon}{|x+2|}$. Since we cannot let $\delta$ vary according to $x$,
	\item		we notice that $|x+2|<5$ for the values we are interested in, so
	\item		$\frac{\epsilon}{5} < \frac{\epsilon}{|x+2|}$ and setting $\delta<\frac{\epsilon}{5}$ ensures that $\delta<\frac{\epsilon}{|x+2|}$.
	\end{enumerate}

The following theorem offers some inequalities that are useful when creating $\delta$--$\epsilon$ proofs.

\begin{theorem}{Power Function Inequalities}{power_ineq}
{Let $x>y>0$ and $n>1$. The following inequalities hold:
\begin{itemize}
\item		$\ds x^n+y^n < (x+y)^n$
\item		$\ds (x-y)^n < x^n - y^n$
\item		$\ds\sqrt[n]{x+y} < \sqrt[n]{x}+\sqrt[n]{y}$
\item		$\ds \sqrt[n]{x}-\sqrt[n]{y}<\sqrt[n]{x-y}$
\end{itemize}
}
\end{theorem}

%
%We revisit the limit found in Example \ref{ex_compute_lim2} to demonstrate the use of Theorem \ref{thm:power_ineq}.
%
%\example{ex_compute_lim2b}{Show that $\ds \lim_{x\to 2} x^2=4$ using Theorem \ref{thm:power_ineq}.}
%{We start the same as before; let $\epsilon >0$ be given. We want to find $\delta>0$ such that $|x^2-4|<\epsilon$ whenever $|x-2|<\delta$. Consider the following inequalities:
%\begin{align*}
%|x^2-4|<\epsilon & \\
%-\epsilon < x^2-4 < \epsilon & \qquad \text{\small (Definition of abs. value)}\\
%4-\epsilon < x^2 < 4+\epsilon & \qquad \text{\small (add 4)}\\
%\sqrt{4-\epsilon} < x < \sqrt{4+\epsilon} & \qquad \text{\small (Take square roots)}\\
%\sqrt{4}-\sqrt{\epsilon} < \sqrt{4-\epsilon} < x < \sqrt{4+\epsilon}< \sqrt{4}+\sqrt{\epsilon} & \qquad \text{\small (apply Theorem \ref{thm:power_ineq})}\\
%2-\sqrt{\epsilon} < x < 2 + \sqrt{\epsilon} & \text{\small (Simplify)}
%\end{align*}
%This implies that when $x$ is within $\sqrt{\epsilon}$ of $2$, $x^2$ will be within $\epsilon$ of $4$. Thus set $\delta = \sqrt{\epsilon}$. We can now start with $|x-2|<\delta$ and reverse the above steps:
%\begin{align*}
%|x-2| < \delta & \\
%-\delta < x-2 < \delta & \qquad \text{\small (Definition of abs. value)}\\
%2-\delta < x < 2+ \delta & \\
%2-\sqrt{\epsilon} < x < 2+\sqrt{\epsilon} & \\
%\end{align*}
%}

Make note of the general pattern exhibited in these last two examples. In some sense, each starts out ``backwards.'' That is, while we want to
\begin{enumerate}
	\item start with $|x-c|<\delta$ and conclude that
	\item $|f(x)-L|<\epsilon$,
\end{enumerate}
we actually start by assuming
\begin{enumerate}
	\item $|f(x)-L|<\epsilon$, then perform some algebraic manipulations to give an inequality of the form
	\item $|x-c|<$ \textit{something}.
\end{enumerate}
%then perform some algebraic manipulations to transform that inequality into an inequality where the ``less than'' side is $|x-c|$.
When we have properly done this, the \textit{something} on the ``greater than'' side of the inequality becomes our $\delta$. We can refer to this as the ``scratch--work'' phase of our proof. Once we have $\delta$, we can formally start with $|x-c|<\delta$ and use algebraic manipulations to conclude that $|f(x)-L|<\epsilon$, usually by using the same steps of our ``scratch--work'' in reverse order.

We highlight this process in the following example.\\

\begin{example}{Evaluating a limit using the definition}{ex_compute_lim4}
{Prove that $\ds \lim_{x\rightarrow 1}x^3-2x = -1$.}
\end{example}

\begin{solution}
{We start our scratch--work by considering $|f(x) - (-1)| < \epsilon$:
\begin{align}
|f(x)-(-1)| &< \epsilon \notag\\
|x^3-2x + 1|&< \epsilon & \text{(Now factor)}\notag\\
|(x-1)(x^2+x-1)|&< \epsilon \notag\\
|x-1| &<\frac{\epsilon}{|x^2+x-1|}.\label{eq:lim4}
\end{align}
We are at the phase of saying that $|x-1|<$ \textit{something}, where \textit{something}$=\epsilon/|x^2+x-1|$. We want to turn that \textit{something} into $\delta$.

Since $x$ is approaching 1, we are safe to assume that $x$ is between 0 and 2. So
\begin{align*}
0&< x<2  & \\
0&< x^2<4.&\text{(squared each term)}\\
\intertext{Since $0<x<2$, we can add $0$, $x$ and $2$, respectively, to each part of the inequality and maintain the inequality.}
0&< x^2+x<6 &\\
-1&< x^2+x-1<5.&\text{(subtracted 1 from each part)}
\end{align*}

In Equation \eqref{eq:lim4}, we wanted $|x-1|<\epsilon/|x^2+x-1|$. The above shows that given any $x$ in $[0,2]$, we know that
\begin{align}
x^2+x-1 &< 5 &\text{which implies that}\notag\\
\frac15 &< \frac{1}{x^2+x-1} &\text{which implies that}\notag\\
\frac{\epsilon}5 &< \frac{\epsilon}{x^2+x-1}.\label{eq:lim4b}
\end{align}
 So we set $\delta \leq \epsilon/5$. This ends our scratch--work, and we begin the formal proof (which also helps us understand why this was a good choice of $\delta$).

Given $\epsilon$, let $\delta \leq \epsilon/5$. We want to show that when $|x-1|<\delta$, then $|(x^3-2x)-(-1)|<\epsilon$. We start with $|x-1|<\delta$:
\begin{align*}
|x-1| &< \delta \\
|x-1| &< \frac{\epsilon}5\\
|x-1| &< \frac\epsilon5 < \frac{\epsilon}{|x^2+x-1|} & \text{(for $x$ near 1, from Equation \eqref{eq:lim4b})}\\
|x-1|\cdot |x^2+x-1| &< \epsilon\\
|x^3-2x+1| &< \epsilon\\
|(x^3-2x)-(-1)| &<\epsilon,
\end{align*}
which is what we wanted to show. Thus $\ds \lim_{x\to 1}x^3-2x = -1$.
}
\end{solution}

%
We illustrate evaluating limits once more.\\

\begin{example}{Evaluating a limit using the definition}{ex_compute_lim3}
{Prove that $\displaystyle \lim_{x\rightarrow 0} e^x = 1 $.}
\end{example}

\begin{solution}
{Symbolically, we want to take the equation $|e^x - 1| < \epsilon$ and unravel it to the form $|x-0| < \delta$.  Here is our scratch--work:
\begin{eqnarray*}
|e^x - 1| < \epsilon&\\
-\epsilon < e^x - 1 < \epsilon& \qquad \textrm{(Definition of absolute value)}\\
1-\epsilon < e^x < 1+\epsilon & \qquad \textrm{(Add 1)}\\
\ln(1-\epsilon) < x < \ln(1+\epsilon) & \qquad \textrm{(Take natural logs)}\\
\end{eqnarray*}
Making the safe assumption that $\epsilon<1$ ensures the last inequality is valid (i.e., so that $\ln (1-\epsilon)$ is defined). We can then set $\delta$ to be the minimum of $|\ln(1-\epsilon)|$ and $\ln(1+\epsilon)$; i.e.,  %  Well, there is a catch.  The value of $\epsilon$ is supposed to be small, but if it happens that $\epsilon \ge 1$, then $\ln(1-\epsilon)$ would be undefined!  The way to work around this is to simply define a new epsilon that is guaranteed to be smaller than the original epsilon \textit{and} less than 1 (let's say less than 1/2 just to be on the safe side).  Let's call this new value $\epsilon_1$ and define it to be $\epsilon_1 = \min\{\epsilon, 1/2\}$.  Then we can use the calculations above to define
$$\delta = \min\{|\ln(1-\epsilon)|, \ln(1+\epsilon)\} = \ln(1+\epsilon).$$
{\textbf{Note:} Recall $\ln 1= 0$ and $\ln x<0$ when $0<x<1$. So $\ln (1-\epsilon) <0$, hence we consider its absolute value.}

Now, we work through the actual the proof:

\begin{align*}
|x - 0|&<\delta\\
-\delta &< x < \delta &  \textrm{(Definition of absolute value)}\\
-\ln(1+\epsilon) &< x < \ln(1+\epsilon). &\\
\ln(1-\epsilon) &< x < \ln(1+\epsilon). & \text{(since $\ln(1-\epsilon) < -\ln(1+\epsilon)$)}\\
\intertext{The above line is true by our choice of $\delta$ and by the fact that since $|\ln(1-\epsilon)|>\ln(1+\epsilon)$ and $\ln(1-\epsilon)<0$, we know $\ln(1-\epsilon) < -\ln(1+\epsilon )$.} %\textrm{(By our choice of}\; \delta)\\
1-\epsilon &< e^x < 1+\epsilon &  \textrm{(Exponentiate)}\\
-\epsilon &< e^x - 1 < \epsilon &  \textrm{(Subtract 1)}\\
%-\epsilon < e^x - 1 < \epsilon & \qquad \textrm{(Since}\; \epsilon_1 \le \epsilon)\\
\end{align*}

In summary, given $\epsilon > 0$, let $\delta = \ln(1+\epsilon)$. Then $|x - 0| < \delta$ implies $|e^x - 1|< \epsilon$ as desired.  We have shown that $\displaystyle \lim_{x\rightarrow 0} e^x = 1 $.
}
\end{solution}

We note that we could actually show that $\lim_{x\rightarrow c} e^x = e^c $ for any constant $c$.  We do this by factoring out $e^c$ from both sides, leaving us to show $\lim_{x\rightarrow c} e^{x-c} = 1 $ instead.  By using the substitution $u=x-c$, this reduces to showing $\lim_{u\rightarrow 0} e^u = 1 $ which we just did in the last example.  As an added benefit, this shows that in fact the function $f(x)=e^x$ is \textit{continuous} at all values of $x$, an important concept we will define in Section \ref{sec:Continuity}.\\

This formal definition of the limit is not an easy concept grasp. Our examples are actually ``easy'' examples, using ``simple'' functions like polynomials, square--roots and exponentials. It is very difficult to prove, using the techniques given above, that $\ds \lim_{x\to 0}(\sin x)/x = 1$, as we approximated in the previous section.

There is hope. The next section shows how one can evaluate complicated limits using certain basic limits as building blocks. While limits are an incredibly important part of calculus (and hence much of higher mathematics), rarely are limits evaluated using the definition. Rather, the techniques of the following section are employed.

\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for Section \ref{sec:LimitsFormal}}

\begin{enumialphparenastyle}

% % % % % % % % % % %
\begin{ex}
\begin{enumerate}
\item {What is wrong with the following ``definition'' of a limit?
	\begin{quote}
``The limit of $f(x)$, as $x$ approaches $a$, is $K$'' means that given any $\delta>0$ there exists $\epsilon>0$ such that whenever $|f(x)-K|< \epsilon$, we have $|x-a|<\delta$.
	\end{quote}
}

\item {Which is given first in establishing a limit, the $x$--tolerance or the $y$--tolerance?}

\item {T/F: $\epsilon$ must always be positive.}

\item {T/F: $\delta$ must always be positive.}
\end{enumerate}

\begin{sol}
\begin{enumerate}
\item {$\epsilon$ should be given first, and the restriction 	$|x-a|<\delta$ implies $|f(x)-K|< \epsilon$, not the other way around.}
\item {The $y$--tolerance.}
\item {T}
\item
{T}
\end{enumerate}
\end{sol}

\end{ex}
% % % % % % % % % % % %
% % % % % % % % % % %
\begin{ex}
Prove the given limit using an $\epsilon - \delta$ proof.
\begin{enumerate}

\item {$\displaystyle \lim_{x\to 2} 5 = 5$}

\item {$\displaystyle \lim_{x\to 5} 3-x = -2$}

\item {$\displaystyle \lim_{x\to 3} x^2-3 = 6$}

\item {$\displaystyle \lim_{x\to 2} x^3-1 = 7$}
\item {$\displaystyle \lim_{x\to 0} e^{2x}-1 = 0$}

\item {$\displaystyle \lim_{x\to 0} \sin x= 0$ (Hint: use the fact that $|\sin x| \leq |x|$, with equality only when $x=0$.)}
\item {$\displaystyle \lim_{x\to 4} x^2+x-5 = 15$}

\end{enumerate}

\begin{sol}
\begin{enumerate}
\item {Let $\epsilon >0$ be given. We wish to find $\delta >0$ such that when $|x-2|<\delta$, $|f(x)-5|<\epsilon$. However, since $f(x)=5$, a constant function, the latter inequality is simply $|5-5|<\epsilon$, which is always true. Thus we can choose any $\delta$ we like; we arbitrarily choose $\delta =\epsilon$.
}
\item {Let $\epsilon >0$ be given. We wish to find $\delta >0$ such that when $|x-5|<\delta$, $|f(x)-(-2)|<\epsilon$.

Consider $|f(x)-(-2)|<\epsilon$:
\begin{gather*}
|f(x) + 2 | < \epsilon \\
|(3-x) + 2 |<\epsilon \\
| 5-x | < \epsilon \\
-\epsilon < 5-x < \epsilon \\
-\epsilon < x-5 < \epsilon. \\
\end{gather*}
This implies we can let $\delta =\epsilon$. Then:
\begin{gather*}
|x-5|<\delta \\
-\delta < x-5 < \delta\\
-\epsilon < x-5 < \epsilon\\
-\epsilon < (x-3)-2 < \epsilon \\
-\epsilon < (-x+3)-(-2) < \epsilon \\
|3-x - (-2)| < \epsilon,
\end{gather*}
which is what we wanted to prove.
}

\item {Let $\epsilon >0$ be given. We wish to find $\delta >0$ such that when $|x-3|<\delta$, $|f(x)-6|<\epsilon$.

Consider $|f(x)-6|<\epsilon$, keeping in  mind we want to make a statement about $|x-3|$:
\begin{gather*}
|f(x) -6 | < \epsilon \\
|x^2-3 -6 |<\epsilon \\
| x^2-9 | < \epsilon \\
| x-3 |\cdot|x+3| < \epsilon \\
| x-3 | < \epsilon/|x+3| \\
\end{gather*}
Since $x$ is near 3, we can safely assume that, for instance, $2<x<4$. Thus
\begin{gather*}
2+3<x+3<4+3 \\
5 < x+3 < 7 \\
\frac{1}{7} < \frac{1}{x+3} < \frac{1}{5} \\
\frac{\epsilon}{7} < \frac{\epsilon}{x+3} < \frac{\epsilon}{5} \\
\end{gather*}
Let $\delta =\frac{\epsilon}{7}$. Then:
\begin{gather*}
|x-3|<\delta \\
|x-3| < \frac{\epsilon}7\\
|x-3| < \frac{\epsilon}{x+3}\\
|x-3|\cdot|x+3| < \frac{\epsilon}{x+3}\cdot|x+3|\\
\end{gather*}
Assuming $x$ is near 3, $x+3$ is positive and we can drop the absolute value signs on the right.
\begin{gather*}
|x-3|\cdot|x+3| < \frac{\epsilon}{x+3}\cdot(x+3)\\
|x^2-9| < \epsilon\\
|(x^2-3) - 6| < \epsilon,
\end{gather*}
which is what we wanted to prove.
}
\item
{Let $\epsilon >0$ be given. We wish to find $\delta >0$ such that when $|x-2|<\delta$, $|f(x)-7|<\epsilon$.

Consider $|f(x)-7|<\epsilon$, keeping in  mind we want to make a statement about $|x-2|$:
\begin{gather*}
|f(x) -7 | < \epsilon \\
|x^3-1 -7 |<\epsilon \\
| x^3-8 | < \epsilon \\
| x-2 |\cdot|x^2+2x+4| < \epsilon \\
| x-3 | < \epsilon/|x^2+2x+4| \\
\end{gather*}
Since $x$ is near 2, we can safely assume that, for instance, $1<x<3$. Thus
\begin{gather*}
1^2+2\cdot1+4<x^2+2x+4<3^2+2\cdot3+4 \\
7 < x^2+2x+4 < 19 \\
\frac{1}{19} < \frac{1}{x^2+2x+4} < \frac{1}{7} \\
\frac{\epsilon}{19} < \frac{\epsilon}{x^2+2x+4} < \frac{\epsilon}{7} \\
\end{gather*}
Let $\delta =\frac{\epsilon}{19}$. Then:
\begin{gather*}
|x-2|<\delta \\
|x-2| < \frac{\epsilon}{19}\\
|x-2| < \frac{\epsilon}{x^2+2x+4}\\
|x-2|\cdot|x^2+2x+4| < \frac{\epsilon}{x^2+2x+4}\cdot|x^2+2x+4|\\
\end{gather*}
Assuming $x$ is near 2, $x^2+2x+4$ is positive and we can drop the absolute value signs on the right.
\begin{gather*}
|x-2|\cdot|x^2+2x+4| < \frac{\epsilon}{x^2+2x+4}\cdot(x^2+2x+4)\\
|x^3-8| < \epsilon\\
|(x^3-1) - 7| < \epsilon,
\end{gather*}
which is what we wanted to prove.
}
\item {Let $\epsilon >0$ be given. We wish to find $\delta >0$ such that when $|x-0|<\delta$, $|f(x)-0|<\epsilon$.

Consider $|f(x)-0|<\epsilon$, keeping in  mind we want to make a statement about $|x-0|$ (i.e., $|x|$):
\begin{gather*}
|f(x) -0 | < \epsilon \\
|e^{2x}-1 |<\epsilon \\
-\epsilon< e^{2x}-1 < \epsilon \\
1-\epsilon< e^{2x} < 1+\epsilon \\
\ln (1-\epsilon) < 2x < \ln (1+\epsilon) \\
\frac{\ln (1-\epsilon)}{2} < x < \frac{\ln (1+\epsilon)}{2} \\
\end{gather*}
Let $\delta = \min\left\{\left|\frac{\ln(1-\epsilon)}{2}\right|,\frac{\ln(1+\epsilon)}{2}\right\}=\frac{\ln(1+\epsilon)}{2}.$

Thus:
\begin{gather*}
|x| < \delta \\
%|x| < \min\left\{\left|\frac{\ln(1-\epsilon)}{2}\right|,\left|\frac{\ln(1+\epsilon)}{2}\right|\right\} \\
|x| <\frac{\ln(1+\epsilon)}{2}<\left|\frac{\ln(1-\epsilon)}{2}\right| \\
\frac{\ln(1-\epsilon)}{2} < x < \frac{\ln(1+\epsilon)}{2}\\
\ln(1-\epsilon)< 2x < \ln(1+\epsilon)\\
1-\epsilon < e^{2x} < 1+\epsilon\\
-\epsilon < e^{2x}-1 < \epsilon\\
|e^{2x}-1-(0)| < \epsilon,
\end{gather*}
which is what we wanted to prove.
}
\item
{Let $\epsilon >0$ be given. We wish to find $\delta >0$ such that when $|x-0|<\delta$, $|f(x)-0|<\epsilon$. In simpler terms, we want to show that when $|x|<\delta$, $|\sin x| < \epsilon$.

Set $\delta = \epsilon$. We start with assuming that $|x|<\delta$. Using the hint, we have that $|\sin x | < |x| < \delta = \epsilon$. Hence if $|x|<\delta$, we know immediately that $|\sin x| < \epsilon$.
}
\item {Let $\epsilon >0$ be given. We wish to find $\delta >0$ such that when $|x-4|<\delta$, $|f(x)-15|<\epsilon$.

Consider $|f(x)-15|<\epsilon$, keeping in  mind we want to make a statement about $|x-4|$:
\begin{gather*}
|f(x) -15 | < \epsilon \\
|x^2+x-5 -15 |<\epsilon \\
| x^2+x-20 | < \epsilon \\
| x-4 |\cdot|x+5| < \epsilon \\
| x-4 | < \epsilon/|x+5| \\
\end{gather*}
Since $x$ is near 4, we can safely assume that, for instance, $3<x<5$. Thus
\begin{gather*}
3+5<x+5<5+5 \\
8 < x+5 < 10 \\
\frac{1}{10} < \frac{1}{x+5} < \frac{1}{8} \\
\frac{\epsilon}{10} < \frac{\epsilon}{x+5} < \frac{\epsilon}{8} \\
\end{gather*}
Let $\delta =\frac{\epsilon}{10}$. Then:
\begin{gather*}
|x-4|<\delta \\
|x-4| < \frac{\epsilon}{10}\\
|x-4| < \frac{\epsilon}{x+5}\\
|x-4|\cdot|x+5| < \frac{\epsilon}{x+5}\cdot|x+5|\\
\end{gather*}
Assuming $x$ is near 4, $x+5$ is positive and we can drop the absolute value signs on the right.
\begin{gather*}
|x-4|\cdot|x+5| < \frac{\epsilon}{x+5}\cdot(x+5)\\
|x^2+x-20| < \epsilon\\
|(x^2+x-5) -15| < \epsilon,
\end{gather*}
which is what we wanted to prove.
}

\end{enumerate}
\end{sol}

\end{ex}
% % % % % % % % % % % %

\begin{ex}
Let $\epsilon$ be a small positive real number. How close to 2 must we hold $x$ in order to be sure that $3x+1$ lies within $\epsilon$ units of 7?
\end{ex}

\end{enumialphparenastyle}

\clearpage


\subsection{Linear Discriminant Analysis (LDA)}

Assume data is mixed gaussian. Use this to estimate classes.


%! Author = tstreule

\section{Molecular Adsorption and Electron Transfer}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Quantum Mechanics}
%
\formula{Schrödinger eq.}{\hat{H}\psi(\vec{r}) = E\psi(\vec{r})}
\quad where $\hat{H} = -\frac{\hbar}{2m}\pderiv[2]{~}{x} + V$

\formula{\textbf{1D potential well}}{\psi(x) = \sqrt{\frac{2}{L}} \sin(k_nx)}
\quad for $0\leq x\leq L$
\formtex{~}{where $k_n = \frac{n\pi}{L}$, $n\in\mathbb{N}$ and $E_n = \frac{\hbar^2k_n^2}{2m}$}

\formula{\textbf{1D potential barrier} (tunneling)}{
    \psi(x) =
    \begin{cases}
        A\eu^{\iu k'x} + B\eu^{-\iu k'x}	& \phantom{for } x\leq0\\
        C\eu^{\iu k''x} + D\eu^{-\iu k''x}	& \text{for }    0\leq x\leq d\\
        F\eu^{\iu k'x}						& \phantom{for } \text{otw.}
    \end{cases}
}
\formtex{~}{where $k' =\sqrt{2mE}/\hbar$ and $k''\!\!=\sqrt{2m(V_0\!-\!E)}/\hbar$}

\formbox{transm./tunneling probability}{T = \frac{F^*\!F}{A^*\!A} = B\eu^{-\beta d}}
, $\beta {=} {-}2\sqrt{2m(V_0{-}E)}/\hbar$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Electronic Transport through Molecules}
%
\formbox{Quantum conductance (1D)}{G = G_0\cdot T}
\enskip $G_0 = \frac{2e^2}{h}$,
\enskip in parallel: $G = N\cdot G_0$
\formbox{Tunneling probability}{T = B\eu^{-\beta d}}
$\propto\;\;\; \eu^{-\beta d} = \left(\eu^{-\beta_{N\!P}d}\right)^N$
\formbox{1D channel current}{j = {-}(\mu_1{-}\mu_2)e\;v\;\rho_E}
\enskip $\rho_E {=} DOS {=} \frac{1}{\hbar\pi}\sqrt{2m/E}$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Atomic and Molecular Orbitals}
%
%	The linear combination of atomic orbitals (\textbf{LCAO}) approximation supposes that molecular orbitals can be constructed from linear superpositions of atomic orbitals centred on individual atoms.\\
%	IMPORTANT: linear combinations of n atomic orbitals each with its own energy level (even if of the same E value!!!) give rise to n energy levels.
%
\textbf{Bond order}: defined by difference (\#electrons) divided by two\\
$\to$ If the bond order is different from zero, then the bond is \textit{stable}
%
%	\textbf{HOMO - LUMO} (highest occupied vs lowest unoccupied MO):\\
%	If we add thermal energy, the electrons will begin to jump. Since all lower states are filled, the first electron will jump from HOMO to LUMO.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	\subsection{Electrical Biosensor}
%	%
%	\includegraphics[width=.5\columnwidth]{Electrical_Biosensor}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Transition State Theory \textnormal{$A+B \to [AB] \to C+D$}}
%
%	Criterion is that colliding molecules must have sufficient energy to overcome a potential energy barrier (the activation energy) to react.
%
\formula{Gibbs free energy}{G = H - TS = U + pV - TS}
\formbox{\textbf{Ideal gas law}}{pV = n\ped{total}RT}
\vspace{-1mm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Marcus Theory}
%
\begin{minipage}{.5\columnwidth}
    \includegraphics[width=.8\columnwidth]{Electrochemistry_Marcus_Theory}
\end{minipage}%
\begin{minipage}{.5\columnwidth}
    See \textbf{section \ref{sec:butler-volmer}} (Butler-Volmer)\par
    \begin{tabular}{r@{$\;=\;$}l}
        $k\ped{red}$	& $v\ped{red} \; \eu^{-\frac{\Delta^\ddagger G\ped{red}}{RT}}$\\
        $k\ped{ox}$		& $v\ped{ox}  \; \eu^{-\frac{\Delta^\ddagger G\ped{ox}}{RT}}$\\
        \addlinespace
        $\Delta^\ddagger G\ped{red}$	& $\!\!~^\ddagger G-G\ped{ox,min}$\\
        $\Delta^\ddagger G\ped{ox}$	& $\!\!~^\ddagger G-G\ped{red,min}$
    \end{tabular}
\end{minipage}
%
%	\formula{rate constant}{k_{et} \propto \eu^{-\frac{\Delta^\ddagger G}{RT}}}
%		\quad with \quad $R = k_B N_A = \unit[8.3]{J\;K^{-1}mol^{-1}}$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Gerischer's view}
%
\begin{minipage}{.4\columnwidth}
    \includegraphics[width=\columnwidth]{Redox_Energy_Levels_1}%
    \hspace{-.6\columnwidth}
    \parbox[b]{.4\columnwidth}{
        $D\ped{ox}(\lambda,E)$ \vspace{20mm}\\\vspace{2mm}
        $D\ped{red}(\lambda,E)$
    }
\end{minipage}%
\begin{minipage}{.15\columnwidth}
    \centering
    \includegraphics[width=.9\columnwidth]{Redox_Energy_Levels_2}
\end{minipage}%
\begin{minipage}{.45\columnwidth}
    \quad\includegraphics[width=.55\columnwidth]{Electrochemistry_Gerischers_View_Cathodic}%
    \hfill\hspace{-\columnwidth}
    \parbox[b]{\columnwidth}{
        \hfill \textbf{cathodic} polariz. \par
        \hfill $i^+ \gg i^-$\vspace{22mm}\\
    }
%		Gaussian curve: ($+$: red, $-$: ox)\\
%		$W\ped{red/ox} = \frac{1}{\sqrt{4\pi\lambda k\ped{B}T}} \eu^{-\frac{(E-E_F\pm\lambda)^2}{4\lambda k\ped{B}T}}$
\end{minipage}


\subsection{Error Correction Model}

\subsubsection{Static model}

Like PAM we start with static estimator.

\subsubsection{The ECM}

The ECM does a regression with first differences, and includes lagged error terms.

We start with a basic first-difference model.

\(\Delta y_t= \Delta x_t\)

We could also expand this to include laggs for both x and y. Here we don't.

We know that long term \(y_t=\theta x_t\). We use the error from this in a first difference model.

\(\Delta y_t= \alpha \Delta x_t + \beta (y_{t-1}-\theta x_{t-1})\)

Page on identifying error terms

Also, page on Vector Error Correction Model (VECM)


\documentclass[12pt,english]{article}
% math tool collection
\usepackage{mathtools}
% for math fonts
\usepackage{bm}
\usepackage{accents}
% for links
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
}

% Titling and Author
\title{Latex Special Symbols}
\author{\href{https://fanwangecon.github.io/}{Fan Wang}\thanks{https://fanwangecon.github.io, repository: \href{https://fanwangecon.github.io/Tex4Econ/}{Tex4Econ}}}
\date{\today}
\begin{document}

\maketitle

Dependencies:
\begin{verbatim}
  \usepackage{mathtools}
  \usepackage{bm}
  \usepackage{accents}
\end{verbatim}

\section{Bold Romans and Greeks}

Testing \textbf{mathbf}:

\begin{align}
  \begin{gathered}
    mathbf\mathbf{this is bold} not bold\\
    a + b \mathbf{+ a + b} + a + b\\
    A + B \mathbf{+ A + B} + A + B\\
    \alpha + \beta \mathbf{+ \alpha + \beta} + \alpha + \beta
  \end{gathered}
\end{align}

Testing \textbf{boldsymbol}:

\begin{align}
  \begin{gathered}
    boldsymbol\boldsymbol{this is boldsymbol} not boldsymbol\\
    a + b \boldsymbol{+ a + b} + a + b\\
    A + B \boldsymbol{+ A + B} + A + B\\
    \alpha + \beta \boldsymbol{+ \alpha + \beta} + \alpha + \beta
  \end{gathered}
\end{align}

\section{Under and Below Hat, Bar and Tilde}

Under and below bar, allowing for bold notation for vector.

\subsection{Accents Package}

Reference:
\begin{itemize}
  \item \href{https://tex.stackexchange.com/questions/125412/bar-below-symbol}{SE: bar-below-symbol}
  \item \href{https://tex.stackexchange.com/questions/66537/making-hats-and-other-accents-bold}{SE: Making hats (and other accents) bold}
\end{itemize}

\subsubsection{Accents Package Regular Font}

Define:

\newcommand{\uhat}[1]{\underaccent{\hat}{#1}}
\newcommand{\ubar}[1]{\underaccent{\bar}{#1}}
\newcommand{\utilde}[1]{\underaccent{\tilde}{#1}}
% \newcommand{\barbm}[1]{\bm{\bar{#1}}}
% \newcommand{\ubarbm}[1]{\underaccent{\bar}{\bm{#1}}}
\begin{verbatim}
  \newcommand{\uhat}[1]{\underaccent{\hat}{#1}}
  \newcommand{\ubar}[1]{\underaccent{\bar}{#1}}
  \newcommand{\utilde}[1]{\underaccent{\tilde}{#1}}
\end{verbatim}

Now write letters with under and over bars etc:

\begin{verbatim}
  \hat{ABC}, \bar{ABC}, \tilde{ABC},
  \uhat{ABC}, \ubar{ABC}, \utilde{ABC},
\end{verbatim}
\begin{align}
    \begin{gathered}
      \hat{a}, \bar{a}, \tilde{a}, \uhat{a}, \ubar{a}, \utilde{a},
      \hat{A}, \bar{A}, \tilde{A}, \uhat{A}, \ubar{A}, \utilde{A}
      \\
      \hat{abc}, \bar{abc}, \tilde{abc}, \uhat{abc}, \ubar{abc}, \utilde{abc},
      \hat{ABC}, \bar{ABC}, \tilde{ABC}, \uhat{ABC}, \ubar{ABC}, \utilde{ABC}
      \\
      \hat{\alpha}, \bar{\alpha}, \tilde{\alpha}, \uhat{\alpha}, \ubar{\alpha}, \utilde{\alpha},
      \hat{\alpha}, \bar{\alpha}, \tilde{\alpha}, \uhat{\alpha}, \ubar{\alpha}, \utilde{\alpha}
      \\
      \hat{\alpha\Gamma\beta}, \bar{\alpha\Gamma\beta}, \tilde{\alpha\Gamma\beta}, \uhat{\alpha\Gamma\beta}, \ubar{\alpha\Gamma\beta}, \utilde{\alpha\Gamma\beta},
      \hat{\alpha\Gamma\beta}, \bar{\alpha\Gamma\beta}, \tilde{\alpha\Gamma\beta}, \uhat{\alpha\Gamma\beta}, \ubar{\alpha\Gamma\beta}, \utilde{\alpha\Gamma\beta}
      \\
    \end{gathered}
\end{align}

\subsubsection{Accents Package Bold}

Define these new commands that combine \href{https://ctan.org/pkg/accents?lang=en}{accent} and the \href{https://ctan.org/pkg/bm?lang=en}{bm} packages. Note that the accents are defined outside of the bold letters, so accents are not bold. Can not define bold accents with bm directly using the accents package it seems:

\newcommand{\hatbm}[1]{\hat{\bm{#1}}}
\newcommand{\barbm}[1]{\bar{\bm{#1}}}
\newcommand{\tildebm}[1]{\tilde{\bm{#1}}}
\newcommand{\uhatbm}[1]{\underaccent{\hat}{\bm{#1}}}
\newcommand{\ubarbm}[1]{\underaccent{\bar}{\bm{#1}}}
\newcommand{\utildebm}[1]{\underaccent{\tilde}{\bm{#1}}}
\begin{verbatim}
\newcommand{\hatbm}[1]{\hat{\bm{#1}}}
\newcommand{\barbm}[1]{\bar{\bm{#1}}}
\newcommand{\tildebm}[1]{\tilde{\bm{#1}}}
\newcommand{\uhatbm}[1]{\underaccent{\hat}{\bm{#1}}}
\newcommand{\ubarbm}[1]{\underaccent{\bar}{\bm{#1}}}
\newcommand{\utildebm}[1]{\underaccent{\tilde}{\bm{#1}}}
\end{verbatim}

Now write letters with under and over bars etc:

\begin{verbatim}
  \hatbm{ABC}, \barbm{ABC}, \tildebm{ABC},
  \uhatbm{ABC}, \ubarbm{ABC}, \utildebm{ABC},
\end{verbatim}
\begin{align}
    \begin{gathered}
      \hatbm{\Gamma}, \uhatbm{\Gamma\beta}\\
      \barbm{a}, \ubarbm{a}\\
      \tildebm{a}, \utildebm{a}\\
      \hatbm{a}, \barbm{a}, \tildebm{a}, \uhatbm{a}, \ubarbm{a}, \utildebm{a},
      \hatbm{A}, \barbm{A}, \tildebm{A}, \uhatbm{A}, \ubarbm{A}, \utildebm{A},
      \\
      \hatbm{abc}, \barbm{abc}, \tildebm{abc}, \uhatbm{abc}, \ubarbm{abc}, \utildebm{abc},
      \hatbm{ABC}, \barbm{ABC}, \tildebm{ABC}, \uhatbm{ABC}, \ubarbm{ABC}, \utildebm{ABC},
      \\
      \hatbm{\alpha}, \barbm{\alpha}, \tildebm{\alpha}, \uhatbm{\alpha}, \ubarbm{\alpha}, \utildebm{\alpha},
      \hatbm{\alpha}, \barbm{\alpha}, \tildebm{\alpha}, \uhatbm{\alpha}, \ubarbm{\alpha}, \utildebm{\alpha}\\
      \hatbm{\alpha\Gamma\beta}, \barbm{\alpha\Gamma\beta}, \tildebm{\alpha\Gamma\beta}, \uhatbm{\alpha\Gamma\beta}, \ubarbm{\alpha\Gamma\beta}, \utildebm{\alpha\Gamma\beta},
      \hatbm{\alpha\Gamma\beta}, \barbm{\alpha\Gamma\beta}, \tildebm{\alpha\Gamma\beta}, \uhatbm{\alpha\Gamma\beta}, \ubarbm{\alpha\Gamma\beta}, \utildebm{\alpha\Gamma\beta}\\
    \end{gathered}
\end{align}

\subsubsection{Mathcal and Accents}

\begin{verbatim}
  \bar{\mathcal{Q}^{C}}, \ubar{\mathcal{Q}^{C}},
  \barbm{\mathcal{Q}^{C}}, \ubarbm{\mathcal{Q}^{C}}
\end{verbatim}
\begin{align}
    \begin{gathered}
      \bar{\mathcal{A}}, \ubar{\mathcal{A}},
      \barbm{\mathcal{A}}, \ubarbm{\mathcal{A}}\\
      \bar{\mathcal{Q}^{C}}, \ubar{\mathcal{Q}^{C}},
      \barbm{\mathcal{Q}^{C}}, \ubarbm{\mathcal{Q}^{C}}\\
      \tilde{\mathcal{A}}, \utilde{\mathcal{A}},
      \tildebm{\mathcal{A}}, \utildebm{\mathcal{A}}\\
      \tilde{\mathcal{Q}^{C}}, \utilde{\mathcal{Q}^{C}},
      \tildebm{\mathcal{Q}^{C}}, \utildebm{\mathcal{Q}^{C}}\\
    \end{gathered}
\end{align}

\subsubsection{bm and Underline and Overline}

Rather than using bar and under bar that are fixed width, use underline and overline which change width and can change in boldness.

\newcommand{\overlinebm}[1]{\bm{\overline{#1}}}
\newcommand{\underlinebm}[1]{\bm{\underline{#1}}}
\begin{verbatim}
\newcommand{\overlinebm}[1]{\bm{\overline{#1}}}
\newcommand{\underlinebm}[1]{\bm{\underline{#1}}}
\end{verbatim}

\begin{verbatim}
  \bar{\mathcal{Q}^{C}}, \ubar{\mathcal{Q}^{C}},
  \barbm{\mathcal{Q}^{C}}, \ubarbm{\mathcal{Q}^{C}}
\end{verbatim}
\begin{align}
    \begin{gathered}
      \overlinebm{\mathcal{Q}^{C}}, \underlinebm{\mathcal{Q}^{C}}, \overlinebm{\mathcal{ABC}^{C}}, \underlinebm{\mathcal{ABC}^{C}}\\
      \overlinebm{\alpha\Gamma\beta}, \underlinebm{\alpha\Gamma\beta}\\
    \end{gathered}
\end{align}

\end{document}


\subsection{Stochastic processes}

In a stochastic process we have a mapping from a variable (time) to a random variable.

\subsubsection{Discrete and continuous time}

Time could be discrete, or continuous.

Temperature over time is a stochastic process, as is the number of cars sold each day.

\subsubsection{Discrete and continous state space}

The state space for temperature is continous, the number of people on the moon is discrete.


\documentclass[a4paper,11pt]{article}
\pdfoutput=1
\usepackage{jcappub}\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{xcolor}

\newcommand{\eq}[1]{Eq. (\ref{#1})}
\newcommand{\ee}[1]{\begin{equation}#1\end{equation}}
\newcommand{\ea}[1]{\begin{align}#1\end{align}}
\newcommand{\eg}[1]{\begin{gather}#1\end{gather}}
\providecommand{\f}[2]{\frac{{#1}}{{#2}}}
\def\hmax{\varphi_{\rm bar}}

\newcommand{\B}[1]{{\color{blue} #1}}

\title{Notes}
\begin{document}

\section{The model}
The action
%
\ee{S=\int d^4x\,\sqrt{|g|}\bigg[\f{R}{2}\left({M_{\rm P}^2}+{\xi}\phi^2\right)-\f{1}{2}(\nabla\phi)^2-\f{1}{2}m^2\phi^2-\f{\lambda}{4}\phi^4\bigg]\,,\label{eq:act}}
gives the equation of motion
\ee{\left(-\Box+m^2-\xi R\right){\phi}+\lambda\phi^3=0\,.}
The scalar curvature at the location $\mathbf{r}$ given by a neutron star binary (with equal masses) we model as
\ee{R=\f{\rho_0}{M_{\rm P}^2}\bigg(e^{-|\mathbf{r}-\mathbf{r}_1|^2/r_{\rm n}^2}+e^{-|\mathbf{r}-\mathbf{r}_2|^2/r_{\rm n}^2}\bigg)=\f{3 M}{4\pi r_{\rm n}^3M_{\rm P}^2}\bigg(e^{-|\mathbf{r}-\mathbf{r}_1|^2/r_{\rm n}^2}+e^{-|\mathbf{r}-\mathbf{r}_2|^2/r_{\rm n}^2}\bigg)\,,}
where $\mathbf{r}_{1,2}$ are the locations of the neutron stars and $M$ and $r_{\rm n}$ are the mass and the radius. For the mass and radius we use
\ee{M\approx 1.4M_{\odot}\approx 1.6\cdot 10^{57}{\rm GeV}\,,\qquad r_{\rm n}\approx 10^4{\rm m}\approx 5\cdot10^{19}({\rm GeV})^{-1}\,.}
\section{Units}
Assuming a space-time lattice, in Minkowski space the discretised d'Alembertian reads
\ea{-\Box\phi&\approx\f{\phi(t+\Delta t)-2\phi(t)+\phi(t-\Delta t)}{\Delta t^2}-\sum_i\f{\phi(x_i+\Delta x)-2\phi(x_i)+\phi(x_i-\Delta x)}{\Delta x^2}%\nonumber\\&\equiv (\Delta t)^{-2}D_t\phi-(\Delta x)^{-2}\sum_iD_i\phi
\,.}
A convenient choice of lattice units is
\ee{t = n_t\Delta t = n_t T_o\tilde{\Delta t}=T_o\tilde{t}\,,\qquad x_i = n_i\Delta x = n_i r_{\rm n}\tilde{\Delta x}=r_n\tilde{x}\,,}
where $T_o$ is the orbital period ({\color{red}check!})
\ee{T_o=2\pi\sqrt{\f{32\pi M_{\rm P}^2r_o^3}{M}}\,,}
$r_{\rm n}$ the radius of the neutron star and $n_t,n_i,\tilde{\Delta t},\tilde{\Delta x}$ are dimensionless numbers. We choose a dimensionless $\tilde{\phi}$ as
\ee{\phi=(T_o)^{-1}\tilde{\phi}\,,}
allowing us to write the equation of motion as
\ea{{\tilde{\phi}(n_t+1)-2\tilde{\phi}(n_t)+\tilde{\phi}(n_t-1)}&=\underbrace{\left(\f{\Delta t}{\Delta x}\right)^2}_{\equiv C}\sum_i\left[{\tilde{\phi}(n_i+1)-2\tilde{\phi}(n_i)+\tilde{\phi}(n_i-1)}\right]\nonumber \\&+\tilde{\Delta t}^2\bigg(-\tilde{m}^2\tilde{\phi}+\xi\tilde{R}\tilde{\phi}-\lambda \tilde{\phi}^3\bigg)\,,\label{eq:eom}}
with the dimensionless scalar curvature
\ee{\tilde{R}\equiv RT_o^2=\f{3 MT_o^2}{4\pi r_{\rm n}^3M_{\rm P}^2}\bigg(e^{-|\mathbf{r}-\mathbf{r}_1|^2/r_{\rm n}^2}+e^{-|\mathbf{r}-\mathbf{r}_2|^2/r_{\rm n}^2}\bigg)=\f{96\pi^2r_o^3}{r_{\rm n}^3}\bigg(e^{-|\mathbf{n}-\mathbf{n}_1|^2/n_{\rm n}^2}+e^{-|\mathbf{n}-\mathbf{n}_2|^2/n_{\rm n}^2}\bigg)\,,}
where the location of star 1 is given by
\ea{\mathbf{r}_{1}&=\left({r}_{1,x},{r}_{1,y},{r}_{1,z}\right)=\bigg(r_o\sin\left(\f{2\pi t}{T_o}\right),r_o\cos\left(\f{2\pi t}{T_o}\right),0\bigg)\nonumber \\\Leftrightarrow\quad
\mathbf{n}_{1}&=\left({n}_{1,x},{n}_{1,y},{n}_{1,z}\right)=\left(n_o\sin\left(2\pi \f{n_t}{n_{T_o}}\right),n_o\cos\left(2\pi \f{n_t}{n_{T_o}}\right),0\right)\,,}
and similarly for star 2. The dimensionless mass is
\ee{\tilde{m}^2= (T_om)^2=\frac{128 \pi ^3 m^2 {M_{\rm P}}^2 r_{o}^3}{M}\,.}
\section{Bounday conditions \& initialization}
The boundary conditions for $\phi$ we choose in the following manner: on the edges i.e. at $x,y,z = 0$ or $L$ where $L$ is our box size we set the field to vanish, $\phi(t,0)=\phi(t,L)=0$. Since the wave equation is second order in time derivatives we also need to specify the time derivative at some instant. For simplicity we choose the speed to vanish at the beginning (here $t=0$ for simplicity), $\dot{\phi}(t=0,\mathbf{x})=0$. For the discretized equation of motion (\ref{eq:eom}), this allows one to solve for the "phantom point" $\tilde{\phi}(n_t=-1)$ via
\ee{\f{\tilde{\phi}(1)-\tilde{\phi}(-1)}{2\tilde{\Delta t}}=0\,.}

At the start of the simulation we need the binary to contain a stationary distribution i.e. $\phi$ has to have relaxed into the minimum given by the potential $(1/2)(m^2-\xi R)\phi^2 +(\lambda/4)\phi^4$, surrounded by empty space. To give the field an initial kick we set $\phi(0,\mathbf{x})$ as white noise, for simplicity with positive values. Note that it is perfectly possible to have either star to have the field  relaxed in either vacuum, or even contain a domain wall. To force the system to relax we introduce a damping term $\propto \dot{\phi}$, discretely
\ee{\propto\tilde{\Delta t}\left[\tilde{\phi}(n_t)-\tilde{\phi}(n_t-1)\right]\,,}
on the right-hand side of the equation of motion which we switch off before the start of the rotation.
\section{Energy}
The energy-density, where $R$ taken is just a potential term, is
\ea{T_{00} &=\f12\bigg[\partial_\rho\phi\partial^\rho\phi+(m^2-\xi R)\phi^2+\f{\lambda}{2}\phi^4\bigg]+(\partial_t\phi)^2\nonumber\\ &=\f12\bigg[(\partial_t \phi)^2+\sum_i(\partial_i \phi)^2+(m^2-\xi R)\phi^2+\f{\lambda}{2}\phi^4\bigg] \,,}
 and when discretised is conveniently given in units of $(T_o)^{-4}$ as
\ea{T_{00} = (T_o)^{-4}\f12\bigg[&\bigg(\f{\tilde{\phi}(n_t+1)-\tilde{\phi}(n_t-1)}{2\tilde{\Delta t}}\bigg)^2+C\sum_i\bigg(\f{\tilde{\phi}(n_{i}+1)-\tilde{\phi}(n_i-1)}{2\tilde{\Delta t}}\bigg)^2\nonumber \\&+(\tilde{m}^2-\xi \tilde{R})\tilde{\phi}^2+\f{\lambda}{2}\phi^4\bigg]\equiv(T_o)^{-4} \tilde{T}_{00}\,.}
The energy is then
\ee{E=\int dxdydz\,T_{00}\approx(\Delta x)^3\sum_{i,j,k}T_{00}=\f{r_{\rm n}^3}{T_o^4}(\tilde{\Delta x})^3\sum_{i,j,k}\tilde{T}_{00}\equiv\f{r_{\rm n}^3}{T_o^4}\tilde{E}\,.}
\section{Flux}
Assuming a constant increase of particle density inside the box, we can write the flux straightforwardly if we know how the energy increases over time as
\ee{f = \f{\Delta E}{\Delta t}  = \f{r_n^3}{T_o^5}\f{\Delta \tilde{E}}{\Delta \tilde{t}}\,.}
The loss of energy after one orbit is then
\ee{\Delta E = \f{r_n^3}{T_o^4}\f{\Delta \tilde{E}}{\Delta \tilde{t}}\,.}
\end{document}


\documentclass{article}

\usepackage{palatino}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[utf8]{inputenc}
\usepackage[colorlinks=true]{hyperref}

% macros
\newcommand{\LL}{\mathcal{L}}
\newcommand{\half}{\frac{1}{2}}
\newcommand{\norm}[1]{\left|\left|#1\right|\right|}
\newcommand{\dd}{d}
\newcommand{\ddd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\block}[1]{\left(#1\right)}
\newcommand{\mat}[1]{ \begin{pmatrix} #1 \end{pmatrix} }
\newcommand{\inv}[1]{#1^{-1}}
\newcommand{\argmin}[1]{\underset{#1}{\textrm{argmin}}}

\begin{document}
\title{Compliant Reference}
\author{Maxime Tournier}
\date{\today}
\maketitle
%
\begin{abstract}
  Quick notes about the mathematical framework used in Compliant. We
  review the time-stepping scheme, kinematic constraint handling,
  potential forces as compliant constraints, and KKT systems.
\end{abstract}
%
\section*{TODO}
\begin{itemize}
  \item Code cheat sheet
  \item finish sections :-)
  \item references
  \item wikipedia links
  \item introduction ?
\end{itemize}

\section{Lagrangian Dynamics}
Given an $n$-dimensional state space $Q$, we consider a Lagrangian
$\LL$ defined as usual:
%
\begin{equation}
\LL(q, v) = \half v^TMv - V(q)
\end{equation}
%
where $V(q)$ a the potential energy of the form:
%
\begin{equation}
V(q) = \half \norm{g(q)}_N^2
\end{equation}
%
for a matrix norm $N$ in the suitable deformation space $Im(g)$. To be
fully general, we include a Rayleigh dissipation function $\half
v^TDv$, where $D$ is PSD. The Euler-Lagrange equations of motions are,
in this case:
%
\begin{equation}
 \frac{d}{dt}\ddd{\LL}{v} = \ddd{\LL}{q} - \ddd{D}{v}
\end{equation}
%
For simplicity, we restrict to the case where $M$ is constant, which
yields:
%
\begin{equation}
  \label{eq:dynamics}
  M \dot{v} = -\nabla_q V - D v
\end{equation}
%
\section{Time Stepping}
%
We now discretize time using a fixed time step $h$. We use forward
differences for $\dot{v}$ as follows:
%
\begin{equation}
  h\ \dot{v}_{k+1} \approx v_{k+1} - v_k
\end{equation}
%
Equation \eqref{eq:dynamics} becomes:
%
\begin{equation}
  M v_{k+1} = M v_k - h \block{\nabla_q V_{k+1} + D v_{k+1}}
\end{equation}
%
Or, calling $p_k = M v_k$ the momentum of the system and $f_k =
-\nabla_q V_k$ the potential forces:
%
\begin{equation}
  \block{M + h\ D} v_{k+1} = p_k + h f_{k+1}
\end{equation}
%
In order to control how implicit our integrator is on forces, we
introduced a blending parameter $\alpha \in [0, 1]$ as follows:
%
\begin{equation}
  \block{M + h \alpha D} v_{k+1} = p_k - h(1 - \alpha) D v_k + h \block{(1 - \alpha) f_k + \alpha f_{k+1}}
\end{equation}
%
We linearize the above using the Hessian of the potential energy:
%
\begin{equation}
\nabla_q V_{k+1} \approx \nabla_q V_k + \nabla_q^2 V_k \block{q_{k+1} - q_k}
\end{equation}
%
so that:
%
\begin{equation}
  (1 - \alpha) f_k + \alpha f_{k+1} = f_k - \alpha \nabla_q^2 V_k \block{q_{k+1} - q_k}
\end{equation}
%
Finally, we use the following position time-stepping scheme:
%
\begin{equation}
  q_{k+1} = q_k + h \block{ (1-\beta) v_k + \beta v_{k+1}}
\end{equation}
%
where $\beta \in [0, 1]$ is again a blending parameter.
%
Letting the stiffness matrix be $K = \nabla_q^2 V_k$ %
\footnote{
%
  This is the opposite of the stiffness matrix as defined in SOFA,
  \emph{i.e.} $\nabla f(q) = -\nabla_q^2 V$. I find it easier to work with
  PSD matrices.} and $d_k = -D v_k$ be the damping forces, we put
everything together as:
%
\begin{equation}
  \label{eq:time-stepping}
  \block{M + h\alpha D + h^2 \alpha \beta K} v_{k+1} =
  p_k + h \block{ f_k + (1 - \alpha) d_k} - \alpha ( 1 - \beta) h^2 K v_k
\end{equation}
%
(and yes, this is very ugly). Fortunately, everyone would use the much
friendlier, fully implicit scheme $\alpha = \beta = 1$ as follows:
%
\begin{equation}
   \block{M + hD + h^2K} v_{k+1} = p_k + h f_k
\end{equation}
%
\section{Response Matrix, Net Momentum}
%
From now on, we will refer to the \emph{response matrix} defined as
follows:
%
\begin{equation}
  \label{eq:response-matrix}
  W = \block{M + h\alpha D + h^2 \alpha \beta K}
\end{equation}
%
We will also refer to the \emph{net momentum} of the system at time
step $k$:
%
\begin{equation}
  \label{eq:net-momentum}
  c_k = p_k + h \block{ f_k + (1 - \alpha) d_k} - \alpha ( 1 - \beta) h^2 K v_k
\end{equation}
%
The time-stepping scheme \eqref{eq:time-stepping} thus involves solving
the following linear system:
%
\begin{equation}
  W v_{k+1} = c_k
\end{equation}
%
The numerical solvers for time-stepping will be described in section
\ref{sec:solvers}.
%
\section{Constraints}
\label{sec:constraints}
%
We now introduce holonomic constraints of the form:
%
\begin{equation}
  g(q) = 0
\end{equation}
%
where $g$ again maps kinematic DOFs to a suitable deformation space
$Im(g)$. Such constraints are satisfied by introducing constraint
forces $J^T\lambda$, where $J = \dd g$ is the constraint Jacobian
matrix, and $\lambda$ are the \emph{Lagrange multipliers}:
%
\begin{align}
  \label{eq:constrained-dynamics}
  M \dot{v} &= -\nabla_q V - D v + J^T \lambda\\
  g(q) &= 0
\end{align}
%
Again, we discretize time and $\dot{v}$ as follows:
%
\begin{align}
  M v_{k+1} &= p_k + h \block{f_{k+1} + d_{k+1} + J_{k+1}^T\lambda_{k+1}} \\
  g\block{q_{k+1}} &= 0
\end{align}
%
And again:
\begin{equation}
g( q_{k+1}) = g_k + h J_k \block{ (1 - \beta) v_k + \beta v_{k+1}}
\end{equation}
%
At this point we become lazy so we approximate constraints as
\emph{affine} functions, meaning that $J_{k+1} \approx J_k$, otherwise
computing the constraint Hessian $\dd^2 g$ would be too costly, and
would result in a non-linear system to solve anyways (\emph{i.e.}
with terms involving $v_{k+1}^T\dd^2g_k \lambda_{k+1}$). As we will
see later, such approximation is consistent with our treatment of
potential forces as compliant constraints. The time-discrete system is
then:
%
\begin{align}
  M v_{k+1} &= p_k + h \block{f_{k+1} + d_{k+1} + J_k^T\lambda_{k+1}} \\
  J_k v_{k+1} &= -\frac{g_k}{\beta h} - \frac{1 - \beta}{\beta} J_k v_k \label{eq:constraintvalue}
\end{align}
%
At this point, we \emph{could} introduce an implicit blending between
$\lambda_k$ and $\lambda_{k+1}$, but this would result in unneeded
complication as $\lambda_{k+1}$ would need to be computed anyways. The
blended force would then be:
\[ J_k^T\block{ (1-\alpha) \lambda_k + \alpha \lambda_{k+1} } \] which
simply offsets $\lambda_{k+1}$ with respect to $\lambda_k$. We will
thus happily ignore such blending. The final linear system to solve
(for $v_{k+1}$ and $\lambda_{k+1}$) becomes:
%
\begin{align}
\label{eq:constrained-integrator}
  W v_{k+1} - J_k^T \lambda_{k+1} &= c_k  \\
  J_k v_{k+1} &= -b_k
\end{align}
where $b_k = \frac{g_k}{\beta h} + \frac{1 - \beta}{\beta} J_k
v_k$. Before leaving, note the sneaky accounting of $h$ inside
$\lambda_{k+1}$.
%
\section{Compliance}
\label{sec:compliance}
%
We will now establish a connection between elastic forces and
constraint forces through a compliance matrix. Remember that we
defined potential energy as:
%
\begin{equation}
  V(q) = \half \norm{g(q)}_N^2
\end{equation}
%
where $g$ maps kinematic DOFs to an appropriate deformation space
$Im(g)$. This means the potential forces are:
%
\begin{equation}
  f = - \nabla_q V = J^T N g(q)
\end{equation}
%
Now, the Hessian or stiffness matrix is :
%
\begin{equation}
  K = \nabla^2_q V = \dd J^T N g(q) + J^T N J
\end{equation}
%
As in section \ref{sec:constraints}, we are too lazy for computing
second derivatives so we approximate deformation mappings as affine
maps, meaning that $\dd J \approx 0$. We are left with the following
response matrix \eqref{eq:response-matrix}:
%
\begin{equation}
  W = \block{M + h\alpha D + h^2 \alpha \beta J_k^T N J_k}
\end{equation}
%
The net momentum \eqref{eq:net-momentum} becomes:
%
\begin{equation}
  c_k = p_k + h (1 - \alpha) d_k - h J_k^TN \block{ g_k + h \alpha ( 1 - \beta) J_k v_k}
\end{equation}
%
If we write the potential force as $J_k^T \lambda_{k+1}$, we have:
\begin{equation}
  \lambda_{k+1} = -N\block{h^2 \alpha \beta J_k v_{k+1} + h g_k + h^2 \alpha (1 - \beta) J_k v_k}
\end{equation}
It turns out that this system can be rewritten as a \emph{larger} system:
%
\begin{equation}
  \mat{M + h \alpha D & -J_k \\
    J_k & \frac{\inv{N}}{h^2 \alpha \beta} } \mat{v_{k+1} \\ \lambda_{k+1}} = \mat{p_k + h (1 - \alpha) d_k \\ -\frac{g_k}{h \alpha \beta} - \frac{( 1 - \beta)}{\beta} J_k v_k }
\end{equation}
%
(pffew !) One can notice that this system is \emph{almost} exactly the
one we obtained with kinematic constraints in
\eqref{eq:constrained-integrator}, with $\alpha = 1$, with the
exception of the $\inv{N}$ term in the $(2, 2)$ block. We call matrix
$C = \inv{N}$ the \emph{compliance} matrix. We see that kinematic
constraints simply correspond to a zero compliance matrix, \emph{i.e.}
infinite stiffness, as one would intuitively expect. It can be checked
that taking $\alpha$ into account for constraint forces produces the
same system with $C = 0$. (TODO) We now recall the main results for
the unified elastic/constraint treatment:
%
\subsection*{Linear System}
\begin{equation}
  \label{eq:time-stepping-kkt}
  \mat{ W & -J \\
    -J & -\frac{C}{h^2 \alpha \beta} } \mat{v \\ \lambda} = \mat{c_k \\ b_k}
\end{equation}
%
\subsection*{Response Matrix}
%
\begin{equation}
  W = M + h\alpha D
\end{equation}
%
\subsection*{Net Momentum}
%
\begin{equation}
c_k = p_k + h (1 - \alpha) d_k
\end{equation}
%
\subsection*{Constraint Value}
%
\begin{equation}
  b_k = \frac{g_k}{h \alpha \beta} + \frac{( 1 - \beta)}{\beta} J_k v_k
\end{equation}
%
TODO pourquoi c'est cool: transition seamless entre contraintes et
elasticite, traitement unifié contraintes/elasticité, conditionnement
pour les sytemes très raides. par contre ca fait des systèmes plus gros.
%
\section{KKT Systems, Compliance and Relaxation}
%
At this point, it is probably a good idea to introduce a few notions
on saddle-point (or KKT) systems. Such systems are (for now, linear)
systems of the form:
%
\begin{equation}
 \label{eq:kkt-system}
 \mat{Q & -A^T \\-A & 0} \mat{x\\\lambda} = \mat{c\\b}
\end{equation}
%
KKT systems typically arise from the Karush-Kuhn-Tucker (hence the
name) optimality conditions of constrained optimization problems. For
instance, the KKT system \eqref{eq:kkt-system} corresponds to the
following equality-constrained Quadratic Program (QP):
%
\begin{equation}
  \label{eq:constrained-optimization}
  \underset{Ax + b = 0}{\textrm{argmin}} \quad \half x^T Q x - c^T x
\end{equation}
%
The KKT system summarizes the optimality conditions for the following
unconstrained function (also called the \emph{Lagrangian}, this time in the
context of optimization):
%
\begin{equation}
  \LL(x, \lambda) \quad = \quad \half x^T Q x - c^T x \quad - \quad \block{A x + b}^T \lambda
\end{equation}
%
and whose critical points (in fact, saddle-points) solve the
constrained problem \eqref{eq:constrained-optimization}. As one can
see, the constrained integrator \eqref{eq:constrained-integrator} is
an example of such KKT systems:
\begin{equation}
  \mat{W & -J\\-J & 0} \mat{v \\ \lambda} = \mat{c \\ b}
\end{equation}
%
where we dropped subscripts for the sake of readability. As symmetric
\emph{indefinite} systems, they tend to be more difficult to solve
than positive definite ones: CG and Cholesky $LDL^T$ factorizations
may breakdown on such systems. However, when the $(1, 1)$ block (here,
matrix $Q$) is invertible, one can use \emph{pivoting} to obtain the
following smaller system:
%
\begin{align}
  x &= \inv{Q}\block{c - A^T \lambda} \\
  -A x &= A\inv{Q}A^T \lambda - A\inv{Q} c = b \\
  \label{eq:schur-complement}
  A\inv{Q}A^T\lambda &= b - A \inv{Q} c
\end{align}
%
This smaller system \eqref{eq:schur-complement} is known as the
\emph{Schur} complement of the KKT system. It is always SPD as long as
$A^T$ is full column-rank, but requires to invert $Q$ which might be
costly in practice. The Schur complement system also corresponds to an
(unconstrained) optimization problem:
%
\begin{equation}
  \argmin{\lambda}\quad \half \lambda^T S \lambda - s^T \lambda
\end{equation}
%
where $S = A \inv {Q} A^T$ is the Schur complement, and $s = b +
A\inv{Q}c$. The minimized quantity has a physical interpretation:
typically, holonomic constraints minimize the total kinetic energy. If
we now consider systems with compliance, such as:
%
\begin{equation}
  \label{eq:compliant-kkt-system}
  \mat{Q & -A^T \\-A & -D} \mat{x\\\lambda} = \mat{c\\b}
\end{equation}
%
we see that they correspond to the following Lagrangian:
%
\begin{equation}
  \LL(x, \lambda) \quad = \quad \half x^T Q x - c^T x \quad -
  \quad \block{A x + b}^T \lambda \quad - \quad \half \lambda^T D \lambda
\end{equation}
%
One can check that the Schur complement becomes $S + D$, and
corresponds to:
%
\begin{equation}
  \argmin{\lambda}\quad \half \lambda^T S \lambda - s^T \lambda \quad +
  \quad \half \lambda^T D \lambda
\end{equation}
%
We see that $D$ acts as a form of numerical damping on the resolution
of constraints, by biasing the solution of the constrained system
towards zero. It is a form of \emph{constraint
  relaxation}. Physically, elastic forces minimize a mix between the
kinetic energy of the system and the $D$-norm of the forces
$\lambda$. Under their most general form, KKT systems include
unilateral and complementarity constraints. We will develop these in
more details in section \ref{sec:unilateral-constraints}.
%
\section{Geometric Stiffness}
%
For both constraint and elastic forces, we happily neglected
second-order derivatives of the deformation mapping $g$. In the case
of elastic forces, this resulted in a nice stiffness matrix of the
form:
%
\begin{equation}
  \nabla_q^2 V(q) \approx J^T N J = K
\end{equation}
%
which enabled us to treat elastic forces as a compliant kinematic
constraints. But what about the second order terms $\tilde{K}=(\dd
J)^T N g(q)$ ? First of all, when the configuration space is a vector
space $Q$ and $g$ is $\mathcal{C}^2$-continuous, the Schwarz' theorem
ensures that $\nabla_q^2 V$ is symmetric, hence so is $\tilde{K}$. We
call $\tilde{K}$ the \emph{geometric stiffness}, as it is induced by
the variation of the deformation mapping $g$. We do not know whether
in the general case, it is possible to factor \emph{both} $K$ and
$\tilde{K}$ as:
%
\begin{equation}
  \nabla_q^2 V(q) = K + \tilde{K} \overset{?}{=} J^T\block{N + \tilde{N}}J
\end{equation}
%
even though some specific examples exist (\emph{e.g.} mass spring
systems). Of course, it is always possible to apply a Cholesky
factorization directly on $\nabla_q^2 V(q)$ as:
%
\begin{equation}
  \nabla_q^2 V(q) = LDL^T
\end{equation}
%
and get back on our feet, but this would be highly inefficient in
practice. Therefore, unless an ad-hoc derivation provides the needed
factorization, we are left with only one alternative: treat the
geometric stiffness as a regular stiffness instead of compliance.
%
\section{Unilateral Constraints}
\label{sec:unilateral-constraints}
%
We now consider \emph{unilateral constraints} (inequality) instead of
bilateral ones:
%
\begin{equation}
  \label{eq:unilateral-constraint}
  g(q) \geq 0
\end{equation}
%
Examples of such constraints include non-penetration constraints, or
angular limits for an articulated rigid body. Just like in the
bilateral case, the constraints are enforced by the addition of
constraint forces $J^T \lambda$, satisfying velocity constraints of
the form:
%
\begin{equation}
  J v_{k+1} \geq -b_k
\end{equation}
%
obtained by differentiation of \eqref{eq:unilateral-constraint},
according to the time-stepping scheme. Furthermore, reaction forces
must satisfy additional requirements known as the Signorini
conditions:
%
\begin{itemize}
\item constraint forces must be repulsive: $\lambda_{k+1} \geq 0$
\item constraint forces don't act when the constraint is inactive, and
  conversely:
  \[ J_k v_{k+1} > -b_k \Rightarrow \lambda_{k+1} = 0, \quad \lambda_{k+1} > 0 \Rightarrow J_k v_{k+1} = -b_k \]
\end{itemize}
%
Intuitively, a non-penetration contact force is not allowed to push
bodies further apart when they are already separating. The
requirements on constraint forces are summarized by the following
\emph{complementarity} constraint:
%
\begin{equation}
  \label{eq:complementarity-constraint}
  0 \leq J_k v_{k+1} + b_k \ \bot \ \lambda_{k+1} \geq 0
\end{equation}
%
The time-stepping scheme with constraint forces is, as before:
%
\begin{equation}
  \label{eq:time-stepping-unilateral}
  W v_{k+1} -J_k^T \lambda_{k+1} = c_k
\end{equation}
%
It turns out that the complementarity constraints
\eqref{eq:complementarity-constraint} together with time-stepping
equation \eqref{eq:time-stepping-unilateral} form the KKT conditions
of the following \emph{inequality-constrained} Quadratic Program:
%
\begin{equation}
  v_{k+1} = \argmin{J_kv + b_k\  \geq\  0} \quad \half v^TWv - c_k^T v
\end{equation}
%
Therefore, time-stepping in the presence of unilateral constraints can
be readily solved by a general QP solver. As in the bilateral case,
when $W$ is easily invertible, it is possible to compute the Schur
complement in order to obtain an equivalent, but smaller problem:
%
\begin{equation}
  \label{eq:lcp}
  0 \leq J\inv{W}J^T \lambda_{k+1} + b_k - A\inv{W} c_k\ \bot \ \lambda_{k+1} \geq 0
\end{equation}
%
(TODO: check formula) Such problem is known as a \emph{Linear
  Complementarity Problem} (LCP) and can be solved by various
algorithms, some of which will be presented in section
\ref{sec:solvers}.
%
\section{Stabilization}
%

\section{Restitution}
%
TODO: velocity constraints for contact with restitution (rigid),
mention Generalized Reflections
%
\section{Numerical Solvers}
\label{sec:solvers}
%
TODO: CG, Cholesky, Minres, GS, PGS, Sequential Impulses

\section{Code Cheat Sheet}

A quick reminder of who does what where in the code:

\subsection{CompliantImplicitSolver}

\begin{itemize}
\item Performs KKT system assembly
\item Builds right-hand sides (correction/dyamics) computation
\item Integrate system solution, update graph and stuff
\end{itemize}

\subsection{Right-hand side computation}

Lots of cases:
\begin{itemize}
\item Bilateral (default), unilateral, friction constraint type
\item Elastic constraints, kinematic constraints (can be stabilized) (default), restitution constraints, \ldots ?
\end{itemize}

A constraint has a BaseConstraintValue constraint value (if not, the
default is assigned) that produces a correct constraint violation term
(the right-hand side for constraints in the KKT system) depending on
the correction/dynamics phase.

Elastic constraints have zero rhs during correction, and -error / dt
during dynamics.

Stabilized constraints (Stablization component) correct the error
during stabilization, but have zero rhs during dynamics (holonomic
kinematic constraints)

Restitution constraints: stabilize when velocity is small and when the constraint is not violated,
otherwise flip relative velocity.

Depending on the type (bilateral, unilateral, friction), the
constraint also has an associated Projector, that you can find in the
KKT system.

\subsection{KKTSolver}
Solves a KKT system (AssemledSystem), for both correction/dynamics cases.

\section{Alternative formulations}

Alternative formulations allow more complex projective constraints (e.g. velocity constraints) where the velocity formulation can only handle the fixed projective constraint.
Howerver their corresponding linear system seems harder to resolve for constraints.
Note that stabilization is always performed in velocity.

\subsection{Acceleration}

By considering $v_{k+1} = v_k + h a $, eq. (\ref{eq:time-stepping}) becomes :

\begin{equation}
  \block{M + h\alpha D + h^2 \alpha \beta K} a =
  f_k - D v_k - \alpha h K v_k
\end{equation}

and eq. (\ref{eq:constraintvalue}) becomes :

\begin{align}
  J_k a &= \frac{ -\frac{g_k}{\alpha h} - J_k v_k } {\beta h}
\end{align}

\subsection{Velocity variation}

By considering $v_{k+1} = v_k + dv $, eq. (\ref{eq:time-stepping}) becomes :

\begin{equation}
  \block{M + h\alpha D + h^2 \alpha \beta K} dv =
  h f_k - h D v_k - \alpha h^2 K v_k
\end{equation}

and eq. (\ref{eq:constraintvalue}) becomes :

\begin{align}
  J_k dv &= \frac{ -\frac{g_k}{\alpha h} - J_k v_k } {\beta}
\end{align}

\end{document}


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

\title{Data Science Mathematics}
\author{Krystal Maughan }
\date{December 2017}

\begin{document}

\maketitle

\mathversion{normal}

\section{Data Science Notes}
A set is a collection
\\
\\
2 ${\in}$ A means 2 is an element of A
\\
\\
Cardinality: size of a set A is the number of elements A
\\
\\
represented as $|$A$|$ = number
\\
\\
A $\cap$ B is A intersect B
\\
\\
A $\cup$ B is A union B
\\
\\
$|$ $\emptyset$ $|$ = 0
\\
\\
writing conditions that satisfy a set
\\
\\
A $\cap$ B = $\brace X: X \in A and X \in B$
\\
\\
Inclusion/Exclusion Formula
\\
$|$A$\cup$B$|$ = $|$A$|$ + $|$B$|$ - $|$A $\cap$ B$|$
\\
\\
\\
\\
disjoint sets
\\
\\
\\
\\
\section{The Infinite World of Real Numbers}
IR - real numbers
\\
everything between integers is also real number
\\
\\
Absolute value is denoted by $|$num$|$
\\
\\
If A B and C are numbers and C is not 0,
\\
and A = B,
\\
C * A = C * B
\\
\\
\section{Sigma}
dummy indices
\\
Simplification rules for Sigma Notation
\\
distributive property
\\
Mean $\mu$ vs Variance
\\
mean centering
\\
subtract the mean from every value
\\
Variance is spread $\sigma$ squared
\\
Standard deviation

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Written By Michael Brodskiy
% Class: Analytic Geometry & Calculus III (Math-292)
% Professor: V. Cherkassky
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[12pt]{article}
\usepackage{alphalph}
\usepackage[utf8]{inputenc}
\usepackage[russian,english]{babel}
\usepackage{titling}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{amssymb}
\usepackage[super]{nth}
\usepackage{everysel}
\usepackage{ragged2e}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{cancel}
\geometry{top=1.0in,bottom=1.0in,left=1.0in,right=1.0in}
\newcommand{\subtitle}[1]{%
  \posttitle{%
    \par\end{center}
    \begin{center}\large#1\end{center}
    \vskip0.5em}%

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

\urlstyle{same}

\title{Lecture XXI Notes}
\date{\today}
\author{Michael Brodskiy\\ \small Professor: V. Cherkassky}

% Mathematical Operations:

% Sum: $$\sum_{n=a}^{b} f(x) $$
% Integral: $$\int_{lower}^{upper} f(x) dx$$
% Limit: $$\lim_{x\to\infty} f(x)$$

\begin{document}

\maketitle

\section{Fundamental Theorem of Line Integrals $-$ 16.3}

The Fundamental Theorem of Line Integrals states that, if $C$ is a smooth, continuous curve, and $\overrightarrow{r}'(t)$, $a\leq t\leq b$, then:

$$\int_a^b \nabla f\,dr=f(\overrightarrow{r}(b))-f(\overrightarrow{r}(a))$$

\textit{Example:} Given $f(x,y,z)=\cos(\pi x)+\sin(\pi y)-xyz$, and $C$ is any path from $(1,\frac{1}{2}, 2)$ to $(2,1,-1)$, Find:

$$\int_C \nabla f\,dr$$

$$\int_C \nabla f\,dr=f(2,1,-1)-f\left(1,\frac{1}{2},2\right)$$

$$(\cos(2\pi)+\sin(\pi)+2)-(\cos(\pi)+\sin\left(\frac{\pi}{2}\right)-1)$$

$$\int_C \nabla f\,dr=4$$

Recalling conservative vector fields, where $\overrightarrow{F}=\nabla f \Leftarrow$ potential function

The Fundamental Theorem of Line Integrals also states that conservative vector fields are independent of path. That is, as long as any path, say $C_1$ and $C_2$, start and end at the same point, then:

$$\int_{C_1} \nabla f\,dr=\int_{C_2} \nabla f\,dr$$

Any path, $C$, that starts at the same point at which it terminates is called closed.

There are two types of closed paths:

\begin{enumerate}

  \item Simple

  \item Non-Simple

\end{enumerate}

A simple path is a shape such as a circle or ellipse. A non-simple path crosses over itself, and example of such a shape being the ``$\infty$'' symbol.

A region, $D$ is called open when it does not contain any of its own boundaries.

Any region, $D$, in which one may connect any two points without exiting the boundaries is known as connected.

Furthermore, a region, $D$ may be called simply connected when there are no holes.

\begin{enumerate}

  \item If $C$ is independent of path:
    $$\int_{C_1}\nabla f\,dr=\int_{C_2}\nabla f\,dr$$

  \item $\overrightarrow{F}$ is conservative if $\overrightarrow{F}=\nabla f$

  \item $\overrightarrow{F}$ is a conservative vector field if $D$ is an open and connected region, where $\int_C \overrightarrow{F}\,dr$ is independent of path (in $D$).

  \item $\int_C \overrightarrow{F}\,dr$ is independent of path in a region, $D$, if $\int_C \overrightarrow{F}\,dr=0$ on every closed path $C$ in $D$.

\end{enumerate}

    Given a function, $\overrightarrow{F}(x,y)=P(x,y)\bold{\hat{i}}+Q(x,y)\bold{\hat{j}}$,  $\overrightarrow{F}$ is conservative if:
    $$\frac{\partial P}{\partial y}=\frac{\partial Q}{\partial x}$$

    \subsection{Solving for $\nabla f$}

    Given $\overrightarrow{F}(x,y)=(2x^3y^4+x)\bold{\hat{i}}+(2x^4y^3+y)\bold{\hat{j}}$, determine whether $\overrightarrow{F}$ is a conservative vector field, and, if so, find $\nabla f$

    $$\frac{\partial P}{\partial y}=8x^3y^3$$
    $$\frac{\partial Q}{\partial x}=8x^3y^3$$
    Therefore, it is conservative

    $$\frac{\partial f}{\partial x}=2x^3y^4+x$$
    $$\frac{\partial f}{\partial y}=2x^4y^3+y$$
    $$f(x,y)=\int_C 2x^3y^4+x\,dx\Rightarrow\frac{1}{2}(x^4y^4+x^2)+h(y)$$
    $$\frac{\partial f}{\partial y}=2x^4y^3+h'(y)=2x^4y^3+y$$
    $$\cancel{2x^4y^3}+h'(y)=\cancel{2x^4y^3}+y$$
    $$h'(y)=y\Rightarrow h(y)=\frac{1}{2}y^2$$
    $$f(x,y)=\frac{1}{2}(x^4y^4+x^2+y^2)$$

\end{document}


\chapter{Bathroom Security}\label{bathroom-security}

\href{https://adventofcode.com/2016/day/2}{Link}

You arrive at \emph{Easter Bunny Headquarters} under cover of darkness.
However, you left in such a rush that you forgot to use the bathroom!
Fancy office buildings like this one usually have keypad locks on their
bathrooms, so you search the front desk for the code.

``In order to improve security,'' the document you find says, ``bathroom
codes will no longer be written down. Instead, please memorize and
follow the procedure below to access the bathrooms.''

The document goes on to explain that each button to be pressed can be
found by starting on the previous button and moving to adjacent buttons
on the keypad: \mintinline[]{idris}{U} moves up, \mintinline[]{idris}{D}
moves down, \mintinline[]{idris}{L} moves left, and
\mintinline[]{idris}{R} moves right. Each line of instructions
corresponds to one button, starting at the previous button (or, for the
first line, \emph{the ``5'' button}); press whatever button you're on at
the end of each line. If a move doesn't lead to a button, ignore it.

You can't hold it much longer, so you decide to figure out the code as
you walk to the bathroom. You picture a keypad like this:

\begin{minted}[]{text}
1 2 3
4 5 6
7 8 9
\end{minted}

Suppose your instructions are:

\begin{minted}[]{text}
ULL
RRDDD
LURDL
UUUUD
\end{minted}

\begin{itemize}
\tightlist
\item
  You start at ``5'' and move up (to ``2''), left (to ``1''), and left
  (you can't, and stay on ``1''), so the first button is
  \mintinline[]{idris}{1}.
\item
  Starting from the previous button (``1''), you move right twice (to
  ``3'') and then down three times (stopping at ``9'' after two moves
  and ignoring the third), ending up with \mintinline[]{idris}{9}.
\item
  Continuing from ``9'', you move left, up, right, down, and left,
  ending with \mintinline[]{idris}{8}.
\item
  Finally, you move up four times (stopping at ``2''), then down once,
  ending with \mintinline[]{idris}{5}.
\end{itemize}

So, in this example, the bathroom code is \mintinline[]{idris}{1985}.

Your puzzle input is the instructions from the document you found at the
front desk.

\section{Module Declaration and
Imports}\label{module-declaration-and-imports}

\begin{minted}[]{idris}
||| Day 2: Bathroom Security
module Data.Advent.Day02

import public Data.Advent.Day
import public Data.Ix

import Data.Vect

import public Lightyear
import public Lightyear.Char
import public Lightyear.Strings
\end{minted}

\section{Data Types}\label{data-types}

\begin{minted}[]{idris}
%access public export

||| Up, down, left or right.
data Instruction = ||| Up
                   U
                 | ||| Down
                   D
                 | ||| Left
                   L
                 | ||| Right
                   R

||| A single digit, i.e. a number strictly less than ten.
Digit : Type
Digit = Fin 10

implementation Show Digit where
  show = show . finToInteger

implementation [showDigits] Show (List Digit) where
  show = concatMap show

||| A pair of coordinates on the keypad, `(x, y)`.
Coordinates : Type
Coordinates = (Fin 3, Fin 3)
\end{minted}

\newpage

\section{Parsers}\label{parsers}

\begin{minted}[]{idris}
%access export

up : Parser Instruction
up = char 'U' *> pure U <?> "up"

down : Parser Instruction
down = char 'D' *> pure D <?> "down"

left : Parser Instruction
left = char 'L' *> pure L <?> "left"

right : Parser Instruction
right = char 'R' *> pure R <?> "right"

instruction : Parser Instruction
instruction = up <|> down <|> left <|> right <?> "up, down, left or right"

partial instructions : Parser (List Instruction)
instructions = some instruction <* (skip endOfLine <|> eof)
\end{minted}

\section{Part One}\label{part-one}

\begin{quote}
  What is the bathroom code?
\end{quote}

\begin{minted}[]{idris}
namespace PartOne

  ||| A keypad like this:
  |||
  ||| ```
  ||| 1 2 3
  ||| 4 5 6
  ||| 7 8 9
  ||| ```
  keypad : Vect 3 (Vect 3 Digit)
  keypad = [ [1, 2, 3],
             [4, 5, 6],
             [7, 8, 9] ]

  move : Coordinates -> Instruction -> Coordinates
  move (x, y) U = (x, pred y)
  move (x, y) D = (x, succ y)
  move (x, y) L = (pred x, y)
  move (x, y) R = (succ x, y)
\end{minted}

\newpage

\begin{minted}[]{idris}
  button : Coordinates -> List Instruction -> (Coordinates, Digit)
  button loc@(x, y) [] = (loc, index x (index y keypad))
  button loc (i :: is) = button (move loc i) is

partial partOne : List (List Instruction) -> String
partOne = show @{showDigits} . go ((1,1), [])
  where
    go : (Coordinates, List Digit) -> List (List Instruction) -> List Digit
    go (_, ds) []            = reverse ds
    go (loc, ds) (is :: iis) = let (loc', d) = PartOne.button loc is in
                                   go (loc', d :: ds) iis

namespace PartOne

  ||| ```idris example
  ||| example
  ||| ```
  partial example : String
  example = fromEither $ partOne <$>
            parse (some instructions) "ULL\nRRDDD\nLURDL\nUUUUD"
\end{minted}

\section{Part Two}\label{part-two}

You finally arrive at the bathroom (it's a several minute walk from the
lobby so visitors can behold the many fancy conference rooms and water
coolers on this floor) and go to punch in the code. Much to your
bladder's dismay, the keypad is not at all like you imagined it.
Instead, you are confronted with the result of hundreds of man-hours of
bathroom-keypad-design meetings:

\begin{minted}[]{text}
    1
  2 3 4
5 6 7 8 9
  A B C
    D
\end{minted}

You still start at ``5'' and stop when you're at an edge, but given the
same instructions as above, the outcome is very different:

\begin{itemize}
\tightlist
\item
  You start at ``5'' and don't move at all (up and left are both edges),
  ending at \mintinline[]{idris}{5}.
\item
  Continuing from ``5'', you move right twice and down three times
  (through ``6'', ``7'', ``B'', ``D'', ``D''), ending at
  \mintinline[]{idris}{D}.
\item
  Then, from ``D'', you move five more times (through ``D'', ``B'',
  ``C'', ``C'', ``B''), ending at \mintinline[]{idris}{B}.
\item
  Finally, after five more moves, you end at \mintinline[]{idris}{3}.
\end{itemize}

\newpage

So, given the actual keypad layout, the code would be
\mintinline[]{idris}{5DB3}.

\begin{quote}
  Using the same instructions in your puzzle input, what is the correct
  \textit{bathroom code}?
\end{quote}

\begin{minted}[]{idris}
namespace PartTwo

  keypad : Vect 5 (n ** Vect n Char)
  keypad = [ (1 **           ['1'])
           , (3 **      ['2', '3', '4'])
           , (5 ** ['5', '6', '7', '8', '9'])
           , (3 **      ['A', 'B', 'C'])
           , (1 **           ['D'])
           ]

  -- NOTE: This will wrap at the bounds, which might be unexpected.
  partial convert : (n : Nat) -> Fin m -> Fin n
  convert (S j) fm {m} =
      let delta = half $ if S j > m
                            then S j `minus` m
                            else m `minus` S j in
          the (Fin (S j)) $ fromNat $ finToNat fm `f` delta
    where
      f : Nat -> Nat -> Nat
      f = if S j > m then plus else minus
      partial half : Nat -> Nat
      half = flip div 2

  canMoveVertically : (Fin (S k), Fin 5) -> Instruction -> Bool
  canMoveVertically (x, y) i with ((finToNat x, finToNat y))
    canMoveVertically (x, y) U | (col, row) =
        case row of
             Z                   => False
             S Z                 => col == 1
             S (S Z)             => inRange (1,3) col
             _                   => True
    canMoveVertically (x, y) D | (col, row) =
        case row of
             S (S Z)             => inRange (1,3) col
             S (S (S Z))         => col == 1
             S (S (S (S Z)))     => False
             _                   => True
    canMoveVertically _ _ | _ = True
\end{minted}

\newpage

\begin{minted}[]{idris}
  partial move : (Fin (S k), Fin 5) -> Instruction ->
    ((n ** Fin n), Fin 5)
  move (x, y) U = if canMoveVertically (x, y) U
                     then let n = fst (index (pred y) keypad) in
                              ((n ** convert n x), pred y)
                     else ((_ ** x), y)
  move (x, y) D = if canMoveVertically (x, y) D
                     then let n = fst (index (succ y) keypad) in
                              ((n ** convert n x), succ y)
                     else ((_ ** x), y)
  move (x, y) L = let n = fst (index y keypad) in
                      ((n ** convert n (pred x)), y)
  move (x, y) R = let n = fst (index y keypad) in
                      ((n ** convert n (succ x)), y)

  partial button : (Fin (S k), Fin 5) -> List Instruction ->
    (((n ** Fin n), Fin 5), Char)
  button loc@(x, y) [] =
      let (n ** row) = index y PartTwo.keypad
          xx = convert n x in
          (((n ** xx), y), index xx row)
  button loc (i :: is) =
      let ((S _ ** x), y) = move loc i in
          button (x, y) is

partial partTwo : List (List Instruction) -> String
partTwo = go (((5 ** 0),2), [])
  where
    partial go : (((n ** Fin n), Fin 5), List Char) ->
      List (List Instruction) -> String
    go (_, cs) []            = pack $ reverse cs
    go (loc, cs) (is :: iis) =
        let ((S k ** xx), y) = loc
            (loc', c) = PartTwo.button (xx, y) {k=k} is in
            go (loc', c :: cs) iis

namespace PartTwo

  ||| ```idris example
  ||| PartTwo.example
  ||| ```
  partial example : String
  example = fromEither $ partTwo <$>
            parse (some instructions) "ULL\nRRDDD\nLURDL\nUUUUD"
\end{minted}

\section{Main}\label{main}

\begin{minted}[]{idris}
namespace Main

  partial main : IO ()
  main = runDay $ MkDay 2 (some instructions)
         (pure . partOne)
         (pure . partTwo)
\end{minted}


\section{A data exploration case study}

% Suppose you want to
% Different kinds of statistical approach are appropriate to the analysis
% of different combinations of variables. For example, to test whether a
% continuous dependent variable (e.g. life-span) varies significantly
% across a categorical independent variable (e.g. handedness), then a t
% test might be appropriate. However, a t test would be inappropriate to
% test whether a continuous dependent variable (e.g. growth rate) varies
% significantly across a continuous independent variable (e.g. nutrient
% concentration): here some sort of regression would be required. It is
% critical that you know what sorts of test are appropriate to different
% kinds of data.
 % If your dependent variable is count data, random variation in the
 % variable is likely to be distributed according to the Poisson
 % distribution, and particular care must be taken in its analysis.
%
%

We will use the famous {\it Iris} data set which is available in R (one
of many) as a case study for data exploration and descriptive
statistics. This dataset gives the measurements in centimeters of the
variables sepal length and width and petal length and width,
respectively, for 50 flowers from each of 3 species of iris: {\it Iris
setosa}, {\it I. versicolor}, and {\it I. virginica}. All data came
from the same  pasture, and picked on the same day and measured at the
same time by the same person with the same apparatus.

\section{Subsetting Data}
Often, you will need to get only part of a matrix, dataframe, etc. Here
are ways to subset your data:
\begin{snugshade}
\footnotesize
\begin{verbatim}
> M <- matrix(1:9, 3, 3)
> M
	 [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9
> M[1,1]
[1] 1
> M[1, ]
[1] 1 4 7
> M[1:2, ]
	 [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
> M[c(1, 3), 2]
[1] 4 6
> M[-3,]
	 [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
> M[-3,-2]
	 [,1] [,2]
[1,]    1    7
[2,]    2    8
> attach(iris)
> iris
	 Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1            5.1         3.5          1.4         0.2 setosa
2            4.9         3.0          1.4         0.2 setosa
3            4.7         3.2          1.3         0.2 setosa
4            4.6         3.1          1.5         0.2 setosa
5            5.0         3.6          1.4         0.2 setosa
6            5.4         3.9          1.7         0.4 setosa
7            4.6         3.4          1.4         0.3 setosa
8            5.0         3.4          1.5         0.2 setosa
9            4.4         2.9          1.4         0.2 setosa
10           4.9         3.1          1.5         0.1 setosa
> iris$Sepal.Width[1:5]
[1] 3.5 3.0 3.2 3.1 3.6
> iris[1:3, c("Sepal.Width","Petal.Width")]
	Sepal.Width Petal.Width
1         3.5         0.2
2         3.0         0.2
3         3.2         0.2
> iris[(Sepal.Width < 3.5) & (Sepal.Length > 7.2),]
 Sepal.Length Sepal.Width Petal.Length Petal.Width Species
106      7.6         3.0          6.6         2.1 virginica
108      7.3         2.9          6.3         1.8 virginica
119      7.7         2.6          6.9         2.3 virginica
123      7.7         2.8          6.7         2.0 virginica
131      7.4         2.8          6.1         1.9 virginica
136      7.7         3.0          6.1         2.3 virginica
\end{verbatim}
\end{snugshade}

\noindent
\section{Basic Statistics in R}
R contains several functions to perform basic (and advanced!)
statistics.
\begin{snugshade} \footnotesize
\begin{verbatim}
> attach(iris)
> summary(iris)
  Sepal.Length    Sepal.Width     Petal.Length  Petal.Width
 Min.   :4.300   Min.   :2.000   Min.   :1.000 Min.   :0.100
 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600 1st Qu.:0.300
 Median :5.800   Median :3.000   Median :4.350 Median :1.300
 Mean   :5.843   Mean   :3.057   Mean   :3.758 Mean   :1.199
 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100 3rd Qu.:1.800
 Max.   :7.900   Max.   :4.400   Max.   :6.900 Max.   :2.500
       Species
 setosa    :50
 versicolor:50
 virginica :50
> table(Species)
Species
    setosa versicolor  virginica
        50         50         50

> table(Species, Petal.Width)
            Petal.Width
Species      0.1 0.2 0.3 0.4 0.5 0.6  1 1.1 1.2 1.3 1.4 ...
  setosa       5  29   7   7   1   1  0   0   0   0   0 ...
  versicolor   0   0   0   0   0   0  7   3   5  13   7 ...
  virginica    0   0   0   0   0   0  0   0   0   0   1 ...
            Petal.Width
Species      2.1 2.2 2.3 2.4 2.5
  setosa       0   0   0   0   0
  versicolor   0   0   0   0   0
  virginica    6   3   8   3   3
> t.test(Sepal.Width[which(Species == "setosa")],
         Sepal.Width[which(Species == "versicolor")])

	Welch Two Sample t-test

data:  Sepal.Width[which(Species == "setosa")] and
       Sepal.Width[which(Species == "versicolor")]
t = 9.455, df = 94.698, p-value = 2.484e-15
alternative hypothesis: true difference in means is
not equal to 0
95 percent confidence interval:
 0.5198348 0.7961652
sample estimates:
mean of x mean of y
    3.428     2.770
> summary(lm(Sepal.Width ~ Sepal.Length))

Call:
lm(formula = Sepal.Width ~ Sepal.Length)

Residuals:
    Min      1Q  Median      3Q     Max
-1.1095 -0.2454 -0.0167  0.2763  1.3338

Coefficients:
             Estimate Std. Error t value Pr(>|t|)
(Intercept)   3.41895    0.25356   13.48   <2e-16 ***
Sepal.Length -0.06188    0.04297   -1.44    0.152
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.4343 on 148 degrees of freedom
Multiple R-squared: 0.01382,	Adjusted R-squared: 0.007159
F-statistic: 2.074 on 1 and 148 DF,  p-value: 0.1519
\end{verbatim}
\end{snugshade}