\section{Improper Integrals}\label{sec:ImproperIntegrals}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Recall that the Fundamental Theorem of Calculus says that if $f$ is a \underline{{\bf continuous}} function on the closed interval $[a,b]$, then
%$$\ds{\int_a^b f(x)~dx=F(x)\bigg|_a^b=F(b)-F(a)},$$
%where $F$ is any antiderivative of $f$.
%
%Both the {\bf continuity} condition and {\bf closed interval} must hold to use the Fundamental Theorem of Calculus, and in this case, $\ds\int_a^b f(x)\,dx$ represents the net area under $f(x)$ from $a$ to $b$:
%$$\includegraphics[width=2.25in]{images2/area-under}$$
%
%We begin with an example where blindly applying the Fundamental Theorem of Calculus can give an incorrect result.
%
%\begin{example}{Using FTC}{Using FTC}
%Explain why $\ds\int_{-1}^1\frac{1}{x^2}\,dx$ is not equal to $-2$.
%\end{example}
%
%\begin{solution}
%Here is how one might proceed:
%$$
%\int_{-1}^1\frac{1}{x^2}\,dx
%~=~ \int_{-1}^1 x^{-2}\,dx
%~=~ -x^{-1}\bigg|_{-1}^1
%~=~ -\frac{1}{x}\bigg|_{-1}^1
%~=~ \left(-\frac{1}{1}\right) - \left(-\frac{1}{(-1)}\right)
%~=~ -2$$
% However, the above answer is {\bf WRONG!}
% Since $f(x)=1/x^2$ is not continuous on $[-1,~1]$, we cannot directly apply the Fundamental Theorem of Calculus.
%Intuitively, we can see why $-2$ is not the correct answer by looking at the graph of $f(x)=1/x^2$ on $[-1,~1]$.
%The shaded area appears to grow without bound as seen in the figure below.
%$$\includegraphics[width=2.5in]{images2/improper-integral-example-1}$$
%\end{solution}
%
%Formalizing this example leads to the concept of an improper integral.
%There are two ways to extend the Fundamental Theorem of Calculus.
%One is to use an {\bf infinite interval}, i.e., $[a,\infty)$, $(-\infty,b]$ or $(-\infty,\infty)$.
%The second is to allow the interval $[a,b]$ to contain an infinite {\bf discontinuity} of $f(x)$.
%In either case, the integral is called an {\bf improper integral}.
%One of the most important applications of this concept is probability distributions.
%
%To compute improper integrals, we use the concept of limits along with the Fundamental Theorem of Calculus.
%
%\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}
%If $f(x)$ is continuous on $[a,\infty)$, then the improper integral of $f$ over $[a,\infty)$ is:
%$$\int_{a}^{\infty} f(x)\,dx:=\lim_{R\to\infty}\int_a^R f(x)\,dx.$$
%If $f(x)$ is continuous on $(-\infty,b]$, then the improper integral of $f$ over $(-\infty,b]$ is:
%$$\int_{-\infty}^b f(x)\,dx:=\lim_{R\to -\infty}\int_R^b f(x)\,dx.$$
%\end{definition}
%
%If the limit exists and is a finite number, we say the improper integral {\bf converges}. Otherwise, we say the  improper integral {\bf diverges}.
%
%To get an intuitive (though not completely correct) interpretation of improper integrals, we attempt to analyze $\ds\int_a^\infty f(x)\,dx$ graphically.
% Here assume $f(x)$ is continuous on $[a,\infty)$:
%$$\includegraphics[width=5in]{images2/improper-integral-theory-2}$$
% We let $R$ be a fixed number in $[a,\infty)$.
% Then by taking the limit as $R$ approaches $\infty$, we get the improper integral:
%$$\int_a^\infty f(x)\,dx:=\lim_{R\to\infty}\int_a^R f(x)\,dx.$$
% We can then apply the Fundamental Theorem of Calculus to the last integral as $f(x)$ is continuous on the closed interval $[a,R]$.
%
%We next define the improper integral for the interval $(-\infty,~\infty)$.
%
%\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}
% If both $\ds\int_{-\infty}^a f(x)\,dx$ and $\ds\int_{a}^{\infty} f(x)\,dx$ are convergent, then the improper integral of $f$ over $(-\infty,\infty)$ is:
%$$\int_{-\infty}^{\infty} f(x)\,dx:=\int_{-\infty}^a f(x)\,dx+\int_{a}^{\infty} f(x)\,dx$$
%\end{definition}
%
%The above definition requires {\bf both} of the integrals
%$$\int_{-\infty}^a f(x)\,dx\qquad\mbox{and}\qquad\int_{a}^{\infty} f(x)\,dx$$
%to be convergent for $\ds\int_{-\infty}^{\infty} f(x)\,dx$ to also be convergent.
% If {\bf either} of $\ds\int_{-\infty}^a f(x)\,dx$ or $\ds\int_{a}^{\infty} f(x)\,dx$ is divergent, then so is $\ds\int_{-\infty}^{\infty} f(x)\,dx$.
%
%\begin{example}{Improper Integral}{Improper Integral}
%Determine whether $\ds\int_1^\infty\frac{1}{x}\,dx$ is convergent or divergent.
%\end{example}
%
%\begin{solution}
% Using the definition for improper integrals we write this as:
%$$	\int_1^\infty \frac{1}{x}\,dx= \lim_{R\to\infty} \int_1^R\frac{1}{x}\,dx
%	= \lim_{R\to\infty} \ln|x|\bigg|_1^R
%	=\lim_{R\to\infty} \ln|R| - \ln|1|
%	= \lim_{R\to\infty} \ln|R|
%	= +\infty$$
% Therefore, the integral is {\bf divergent}.
%\end{solution}
%
%\begin{example}{Improper Integral}{Improper Integral}
%Determine whether $\ds\int_{-\infty}^\infty x\sin(x^2)\,dx$ is convergent or divergent.
%\end{example}
%
%\begin{solution}
% We must compute both $\ds\int_0^\infty x\sin(x^2)\,dx$ and $\ds\int_{-\infty}^0 x\sin(x^2)\,dx$.
% Note that we don't have to split the integral up at $0$, any finite value $a$ will work.
% First we compute the indefinite integral.
% Let $u=x^2$, then $du=2x\,dx$ and hence,
%$$\int x\sin(x^2)\,dx=\frac{1}{2} \int \sin(u)\,du=-\frac{1}{2}\cos(x^2)+C$$
%Using the definition of improper integral gives:
%$$\int_0^\infty x\sin(x^2)\,dx  =  \lim_{R\to\infty} \int_0^R x\sin(x^2)\,dx
%=\lim_{R\to\infty} \left[-\frac{1}{2}\cos(x^2)\right] \bigg|_0^R
%=  -\frac{1}{2} \lim_{R\to\infty} \cos(R^2) +\frac{1}{2}$$
%This limit does not exist since $\cos x$ {\bf oscillates} between $-1$ and $+1$.
% In particular, $\cos x$ does not approach any particular value as $x$ gets larger and larger.
% Thus, $\ds\int_0^\infty x\sin(x^2)\,dx$ diverges, and hence, $\ds\int_{-\infty}^\infty x\sin(x^2)\,dx$ diverges.
%\end{solution}
%
%When there is a discontinuity in $[a,b]$ or at an endpoint, then the improper integral is as follows.
%
%\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}
%If $f(x)$ is continuous on $(a,b]$, then the improper integral of $f$ over $(a,b]$ is:
%$$\int_a^b f(x)\,dx:=\lim_{R\to a^+}\int_R^b f(x)\,dx.$$
%If $f(x)$ is continuous on $[a,b)$, then the improper integral of $f$ over $[a,b)$ is:
%$$\int_a^b f(x)\,dx:=\lim_{R\to b^-}\int_a^R f(x)\,dx.$$
%\end{definition}
%
%If the limit above exists and is a finite number, we say the improper integral {\bf converges}.
%Otherwise, we say the improper integral {\bf diverges}.
%
%When there is a discontinuity in the interior of $[a,b]$, we use the following definition.
%
%\begin{definition}{Definitions for Improper Integrals}{Definitions for Improper Integrals}
%If $f$ has a discontinuity at $x=c$ where $c\in[a,b]$, and both
%both $\ds\int_a^c f(x)\,dx$ and $\ds\int_c^b f(x)\,dx$ are convergent, then $f$ over $[a,b]$ is:
%$$\int_a^b f(x)\,dx:=\int_a^c f(x)\,dx+\int_c^b f(x)\,dx$$
%\end{definition}
%
%Again, we can get an intuitive sense of this concept by analyzing $\ds\int_a^b f(x)\,dx$ graphically.
%Here assume $f(x)$ is continuous on $(a,b]$ but discontinuous at $x=a$:
%$$\includegraphics[width=5in]{images2/improper-integral-theory-1}$$
% We let $R$ be a fixed number in $(a,b)$.
% Then by taking the limit as $R$ approaches $a$ from the {\bf right},  we get the improper integral:
%$$\int_a^b f(x)\,dx:=\lim_{R\to a^+}\int_R^b f(x)\,dx.$$
% Now we can apply FTC to the last integral as $f(x)$ is continuous on $[R,b]$.
%
%\begin{example}{A Divergent Integral}{A Divergent Integral}
%Determine if $\ds\int_{-1}^1\frac{1}{x^2}\,dx$ is convergent or divergent.
%\end{example}
%
%\begin{solution}
% The function $f(x)=1/x^2$ has a discontinuity at $x=0$, which lies in $[-1,1]$.
% We must compute $\ds\int_{-1}^0 \frac{1}{x^2}\,dx$ and $\ds\int_0^1 \frac{1}{x^2}\,dx$. Let's start with $\ds\int_0^1 \frac{1}{x^2}\,dx$:
%$$\int_0^1 \frac{1}{x^2}\,dx = \lim_{R\to 0^+} \int_R^1 \frac{1}{x^2} \,dx = \lim_{R\to 0^+} -\frac{1}{x}\bigg|_R^1
%= -1 + \lim_{R\to 0^+} \frac{1}{R}$$
%which diverges to $+\infty$.
% Therefore, $\ds\int_{-1}^1\frac{1}{x^2}\,dx$ is {\bf divergent} since one of $\ds\int_{-1}^0 \frac{1}{x^2}\,dx$ and $\ds\int_0^1 \frac{1}{x^2}\,dx$ is divergent.
%\end{solution}
%
%
%% % % % % % %
%% % The following example 'Integral of the Logarithm' can be replaced with the next example if Integration by Parts is not included in the text adaptation.
%\begin{example}{Integral of the Logarithm}{Integral of the Logarithm}
%Determine if $\ds\int_0^1 \ln x \,dx$ is convergent or divergent. Evaluate it if it is convergent.
%\end{example}
%
%\begin{solution}
%Note that $f(x)=\ln x$ is discontinuous at the endpoint $x=0$.
%We first use integration by parts to compute $\ds\int\ln x\,dx$.
%We let $u=\ln x$ and $dv=dx$.
%Then $du=(1/x)dx$, $v=x$, giving:
%\begin{eqnarray*}
%\int \ln x\,dx &=& \ds x\ln x-\int x\cdot\frac{1}{x}\,dx\\
%&=& x\ln x-\int 1\,dx\\
%&=& x\ln x-x+C\\
%\end{eqnarray*}
% Now using the definition of improper integral for $\ds\int_0^1 \ln x \,dx$:
%$$
%	\int_0^1 \ln x \,dx = \lim_{R\to 0^+} \int_R^1 \ln x\,dx
%	=  \lim_{R\to 0^+} (x\ln x-x)\bigg|_R^1
%	%=  \lim_{R\to 0^+} \left(\left[\ln 1-1\right] - \left[R\ln R-R\right]\right)
%	=  -1 - \lim_{R\to 0^+}(R\ln R) + \lim_{R\to 0^+}R
%$$
%Note that $\ds\lim_{R\to 0^+}R=0$.
%We next compute $\ds\lim_{R\to 0^+}(R\ln R)$.
%First, we rewrite the expression as follows:
%$$\lim_{x\to0^+}(R\ln R)=\lim_{R\to0^+}\frac{\ln R}{1/R}.$$
%Now the limit is of the indeterminate type $(-\infty)/(\infty)$ and l'H\^opital's Rule can be applied.
%$$\lim_{R\to0^+}(R\ln R) =\lim_{R\to0^+}\frac{\ln R}{1/R}
%=\lim_{R\to0^+}\frac{1/R}{-1/R^2}
%=\lim_{R\to0^+}-\frac{R^2}{R}
%=\lim_{R\to0^+}(-R)
%=0$$
%Thus, $\ds\lim_{R\to 0^+}(R\ln R)=0$.
%Thus
%$$\int_0^1 \ln x \,dx = -1,$$
%and the integral is convergent to $-1$.
%
%Graphically, one might interpret this to mean that the net area under $\ln x$ on $[0,1]$ is $-1$ (the area in this case lies below the $x$-axis).
%$$\includegraphics[width=2.5in]{images2/improper-integral-example-2}$$
%\end{solution}
%
%\begin{example}{Integral of a Square Root}{IntSquareRoot}
%Determine if $\ds\int_0^4\frac{dx}{\sqrt{4-x}}$ is convergent or divergent. Evaluate it if it is convergent.
%\end{example}
%\begin{solution}
%Note that $\frac{1}{\sqrt{4-x}}$ is discontinuous at the endpoint $x=4$. We use a $u$-substitution to compute $\int \frac{dx}{\sqrt{4-x}}$. We let $u=4-x$, then $du=-dx$, giving:
%\begin{align*}
%\ds\int\frac{dx}{\sqrt{4-x}}&=\int-\frac{du}{u^{1/2}}	\\
%&=\int -u^{-1/2}\,du	\\
%&=-2(u)^{1/2}+C	\\
%&=-2\sqrt{4-x}+C
%\end{align*}
%Now using the definition of improper integrals for $\ds\int_0^4\frac{dx}{\sqrt{4-x}}$:
%\[\ds\int_0^4\frac{dx}{\sqrt{4-x}}=\lim_{R\to4^{-}}(-2\sqrt{4-x})\bigg|_0^R=\lim_{R\to4^{-}}-2\sqrt{4-R}+2\sqrt{4}=4\]
%\end{solution}
%
%\begin{example}{Improper Integral}{ImpIntExample}
%Determine if $\ds\int_{1}^{2}\dfrac{dx}{\left( x-1\right) ^{1/3}}$ is
%convergent or divergent. Evaluate it if it is convergent.
%\end{example}
%\begin{solution}
%Note that $f\left( x\right) =\dfrac{1}{\left( x-1\right) ^{1/3}}$
%is discontinuous at the endpoint $x=1.$ We first use substitution to find
%$\ds\int \dfrac{dx}{\left( x-1\right) ^{1/3}}.$ We let $u=x-1.$ Then $du=dx,$
%giving%
%\begin{equation*}
%\int \dfrac{dx}{\left( x-1\right) ^{1/3}}=\int \frac{du}{u^{1/3}}=\int
%u^{-1/3}du=\frac{3}{2}u^{2/3}+C=\frac{3}{2}\left( x-1\right) ^{2/3}+C.
%\end{equation*}%
%Now using the definition of improper integral for $\ds\int_{1}^{2}\dfrac{dx}{%
%	\left( x-1\right) ^{1/3}}:$%
%\begin{equation*}
%\int_{1}^{2}\dfrac{dx}{\left( x-1\right) ^{1/3}}=\lim_{R\rightarrow
%	1^{+}}\int_{R}^{2}\dfrac{dx}{\left( x-1\right) ^{1/3}}=\left.
%\lim_{R\rightarrow 1^{+}}\frac{3}{2}\left( x-1\right) ^{2/3}\right\vert
%_{R}^{2}=\frac{3}{2}-\lim_{R\rightarrow 1^{+}}\frac{3}{2}\left( R-1\right)
%^{2/3}=\frac{3}{2},
%\end{equation*}%
%and the integral is convergent to $\frac{3}{2}.$ Graphically, one might
%interpret this to mean that the net area under $\dfrac{1}{\left( x-1\right)
%	^{1/3}}$ on $\left[ 1,2\right] $ is $\frac{3}{2}$.
%
%$$\includegraphics[width=8cm]{images/improper-int-example}$$
%\end{solution}
%
%The following test allows us to determine convergence/divergence information about improper integrals that are hard to compute by comparing them to easier ones.
%We state the test for $[a,\infty)$, but similar versions hold for the other improper integrals.
%
%\begin{formulabox}[The Comparison Test]
%Assume that $f(x)\geq g(x)\geq 0$ for $x\geq a$.
%\begin{enumerate}[(i)]
%\item	If $\ds\int_a^\infty f(x)\,dx$ {\bf converges}, then $\ds\int_a^\infty g(x)\,dx$ also {\bf converges}.
%\item	If $\ds\int_a^\infty g(x)\,dx$ {\bf diverges}, then $\ds\int_a^\infty f(x)\,dx$ also {\bf diverges}.
%\end{enumerate}
%\end{formulabox}
%
%Informally, (i) says that if $f(x)$ is larger than $g(x)$, and the area under $f(x)$ is finite (converges), then the area under $g(x)$ must also be finite (converges).
%Informally, (ii) says that if $f(x)$ is larger than $g(x)$, and the area under $g(x)$ is infinite (diverges), then the area under $f(x)$ must also be infinite (diverges).
%
%$$\includegraphics[width=6in]{images2/improper-integral-theory-3}$$
%
%\begin{example}{Comparison Test}{Comparison Test}
%Show that $\ds\int_2^\infty \frac{\cos^2x}{x^2} \,dx$ converges.
%\end{example}
%
%\begin{solution}
%We use the comparison test to show that it converges.
%Note that $0\leq \cos^2x\leq 1$ and hence
%$$0 \leq\frac{\cos^2x}{x^2}\leq\frac{1}{x^2}.$$
%Thus, taking $f(x)=1/x^2$ and $g(x)=\cos^2x / x^2$ we have $f(x)\geq g(x)\geq 0$.
%One can easily see that $\ds\int_2^\infty \frac{1}{x^2}\,dx$ converges.
%Therefore, $\ds\int_2^\infty \frac{\cos^2x}{x^2} \,dx$ also converges.
%\end{solution}

We begin this section by considering the following definite integrals:
\begin{itemize}
\item	$\ds \int_0^{100}\frac1{1+x^2}\ dx \approx 1.5608,$
\item	$\ds \int_0^{1000}\frac1{1+x^2}\ dx \approx 1.5698,$
\item	$\ds \int_0^{10,000}\frac1{1+x^2}\ dx \approx 1.5707.$
\end{itemize}

Notice how the integrand is $1/(1+x^2)$ in each integral (which is sketched in Figure \ref{fig:improper1}). As the upper bound gets larger, one would expect the ``area under the curve'' would also grow. While the definite integrals do increase in value as the upper bound grows, they are not  increasing by much. In fact, consider:
$$\int_0^b \frac{1}{1+x^2}\ dx = \tan^{-1}x\Big|_0^b = \tan^{-1}b-\tan^{-1}0 = \tan^{-1}b.$$
As $b\rightarrow \infty$, $\tan^{-1}b \rightarrow \pi/2.$ Therefore it seems that as the upper bound $b$ grows, the value of the definite integral $\ds \int_0^b\frac{1}{1+x^2}\ dx$ approaches $\pi/2\approx 1.5708$. This should strike the reader as being a bit amazing: even though the curve extends ``to infinity,'' it has a finite amount of area underneath it.

\mfigure{.75}{Graphing $\ds f(x)=\frac{1}{1+x^2}$.}{fig:improper1}{
\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
%			xtick={-1,1},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
%			ytick={-1,1},
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=1.1,%
			xmin=-1,xmax=11%
]

\addplot [{\coloronefill},fill={\coloronefill}] coordinates {(0,1.)(0.1,0.9901)(0.2,0.9615)(0.3,0.9174)(0.4,0.8621)(0.5,0.8)(0.6,0.7353)(0.7,0.6711)(0.8,0.6098)(0.9,0.5525)(1.,0.5)(1.5,0.3077)(2.,0.2)(2.5,0.1379)(3.,0.1)(3.5,0.07547)(4.,0.05882)(4.5,0.04706)(5.,0.03846)(5.5,0.032)(6.,0.02703)(6.5,0.02312)(7.,0.02)(7.5,0.01747)(8.,0.01538)(8.5,0.01365)(9.,0.0122)(9.5,0.01096)(10.,0.009901)(10.5,0.0089)} -- (axis cs:0,0)--cycle;

\addplot [{\colorone},thick,smooth] coordinates {(0,1.)(0.1,0.9901)(0.2,0.9615)(0.3,0.9174)(0.4,0.8621)(0.5,0.8)(0.6,0.7353)(0.7,0.6711)(0.8,0.6098)(0.9,0.5525)(1.,0.5)(1.5,0.3077)(2.,0.2)(2.5,0.1379)(3.,0.1)(3.5,0.07547)(4.,0.05882)(4.5,0.04706)(5.,0.03846)(5.5,0.032)(6.,0.02703)(6.5,0.02312)(7.,0.02)(7.5,0.01747)(8.,0.01538)(8.5,0.01365)(9.,0.0122)(9.5,0.01096)(10.,0.009901)(10.5,0.0089)};

%\filldraw (axis cs:.707,.707) circle (1pt) node [shift={(6pt,11pt)}] {\scriptsize ($\cos \theta$,$\sin \theta$)};
%
%\draw (axis cs:.6,.25) node {\scriptsize $\ds\frac{\theta}{2}$};
%\draw (axis cs:-.75,1) node {\scriptsize $x^2+y^2=1$};

\end{axis}

\node [right] at (myplot.right of origin) { $x$};
\node [above] at (myplot.above origin) { $y$};
\end{tikzpicture}
}

When we defined the definite integral $\ds\int_a^b f(x)\ dx$, we made two stipulations:
	\begin{enumerate}
	\item		The interval over which we integrated, $[a,b]$, was a finite interval, and
	\item		The function $f(x)$ was continuous on $[a,b]$ (ensuring that the range of $f$ was finite).
	\end{enumerate}

In this section we consider integrals where one or both of the above conditions do not hold. Such integrals are called \textbf{improper integrals.}

\subsection*{Improper Integrals with Infinite Bounds}

\begin{definition}{Improper Integrals with Infinite Bounds; Converge, Diverge}{def:imp_int1}
{
\begin{enumerate}
\item		Let $f$ be a continuous function on $[a,\infty)$. Define \index{integration!improper}\index{improper integration}\index{convergence!of improper int.}\index{divergence!of improper int.}
$$\small\int_a^\infty f(x)\ dx \quad \text{to be}\quad \lim_{b\to\infty}\int_a^b f(x)\ dx.$$

\item		Let $f$ be a continuous function on $(-\infty,b]$. Define
$$\small\int_{-\infty}^b f(x)\ dx \quad \text{to be}\quad \lim_{a\to-\infty}\int_a^b f(x)\ dx.$$

\item		Let $f$ be a continuous function on $(-\infty,\infty)$. Let $c$ be any real number; define
$$\small\int_{-\infty}^\infty f(x)\ dx \quad \text{to be}\quad \lim_{a\to-\infty}\int_a^c f(x)\ dx\ +\ \lim_{b\to\infty}\int_c^b f(x)\ dx.$$
\end{enumerate}
An improper integral is said to \textbf{converge} if its corresponding limit exists; otherwise, it \textbf{diverges}. The improper integral in part 3 converges if and only if both of its limits exist.
}
\end{definition}

\begin{example}{Evaluating improper integrals}{ex_impint1}
{
Evaluate the following improper integrals.\\
\noindent%
\begin{minipage}[t]{.5\textwidth}
\begin{enumerate}
\item		$\ds\int_1^\infty \frac1{x^2}\ dx$
\item		$\ds\int_1^\infty \frac1x\ dx$
\end{enumerate}
\end{minipage}
\begin{minipage}[t]{.5\textwidth}
\begin{enumerate}\addtocounter{enumi}{2}
\item		$\ds\int_{-\infty}^0 e^x\ dx$
\item		$\ds\int_{-\infty}^\infty \frac1{1+x^2}\ dx$
\end{enumerate}
\end{minipage}
}
\end{example}

\begin{solution}
{\begin{enumerate}
\item		\hfill$\begin{aligned}[t] \int_1^\infty \frac{1}{x^2}\ dx\  =\ \lim_{b\to\infty} \int_1^b\frac1{x^2}\ dx\  &=\ \lim_{b\to\infty} \frac{-1}{x}\Big|_1^b \\
 %&= \lim_{b\to\infty} \frac{-1}{x}\Big|_1^b \\
 &= \lim_{b\to\infty} \frac{-1}{b} + 1\\
 &= 1.\end{aligned}$\hfill\null

A graph of the area defined by this integral is given in Figure \ref{fig:impint1a}.

\mfigure{.7}{A graph of $f(x) = \frac{1}{x^2}$ in Example \ref{exa:ex_impint1}.}{fig:impint1a}{
\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
tick label style={font=\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
			xtick={1,5,10},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
%			ytick={-1,1},
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=1.1,%
			xmin=-1,xmax=11%
]

\addplot [{\coloronefill},fill={\coloronefill}] coordinates {(1.,1.)(1.5,0.4444)(2.,0.25)(2.5,0.16)(3.,0.1111)(3.5,0.08163)(4.,0.0625)(4.5,0.04938)(5.,0.04)(5.5,0.03306)(6.,0.02778)(6.5,0.02367)(7.,0.02041)(7.5,0.01778)(8.,0.01563)(8.5,0.01384)(9.,0.01235)(9.5,0.01108)(10.,0.01)(10.5,0.009)} -- (axis cs:10.5,0)--(axis cs:1,0)--cycle;

\addplot [{\colorone},thick,smooth] coordinates {(1.,1.)(1.5,0.4444)(2.,0.25)(2.5,0.16)(3.,0.1111)(3.5,0.08163)(4.,0.0625)(4.5,0.04938)(5.,0.04)(5.5,0.03306)(6.,0.02778)(6.5,0.02367)(7.,0.02041)(7.5,0.01778)(8.,0.01563)(8.5,0.01384)(9.,0.01235)(9.5,0.01108)(10.,0.01)(10.5,0.009)};

\draw (axis cs:5,.75) node {\scriptsize $\ds f(x)=\frac{1}{x^2}$};

\end{axis}

\node [right] at (myplot.right of origin) { $x$};
\node [above] at (myplot.above origin) { $y$};
\end{tikzpicture}
}

\item		\hfill$\begin{aligned}[t]%
			\int_1^\infty \frac1x\ dx & = \lim_{b\to\infty}\int_1^b\frac1x\ dx \\
						&= \lim_{b\to\infty} \ln |x|\Big|_1^b \\
						&= \lim_{b\to\infty} \ln (b)\\
						&= \infty.
	\end{aligned}$\hfill\null

The limit does not exist, hence the improper integral $\ds\int_1^\infty\frac1x\ dx$ diverges. Compare the graphs in Figures \ref{fig:impint1a} and \ref{fig:impint1b}; notice how the graph of $f(x) = 1/x$ is noticeably larger. This difference is enough to cause the improper integral to diverge.

\mfigure{.8}{A graph of $f(x) = \frac{1}{x}$ in Example \ref{exa:ex_impint1}.}{fig:impint1b}{
\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
			xtick={1,5,10},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
%			ytick={-1,1},
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=1.1,%
			xmin=-1,xmax=11%
]

\addplot [{\coloronefill},fill={\coloronefill}] coordinates {(1.,1.)(1.5,0.6667)(2.,0.5)(2.5,0.4)(3.,0.3333)(3.5,0.2857)(4.,0.25)(4.5,0.2222)(5.,0.2)(5.5,0.1818)(6.,0.1667)(6.5,0.1538)(7.,0.1429)(7.5,0.1333)(8.,0.125)(8.5,0.1176)(9.,0.1111)(9.5,0.1053)(10.,0.1)(10.5,0.09524)} -- (axis cs:10.5,0)-- (axis cs:1,0)--cycle;

\addplot [{\colorone},thick,smooth] coordinates {(1.,1.)(1.5,0.6667)(2.,0.5)(2.5,0.4)(3.,0.3333)(3.5,0.2857)(4.,0.25)(4.5,0.2222)(5.,0.2)(5.5,0.1818)(6.,0.1667)(6.5,0.1538)(7.,0.1429)(7.5,0.1333)(8.,0.125)(8.5,0.1176)(9.,0.1111)(9.5,0.1053)(10.,0.1)(10.5,0.09524)};

\draw (axis cs:5,.75) node { $\ds f(x)=\frac{1}{x}$};
\end{axis}

\node [right] at (myplot.right of origin) { $x$};
\node [above] at (myplot.above origin) { $y$};
\end{tikzpicture}
}

\item		\hfill$\begin{aligned}[t]%
			\int_{-\infty}^0 e^x \ dx &= \lim_{a\to-\infty} \int_a^0e^x\ dx \\
					&=  \lim_{a\to-\infty} e^x\Big|_a^0 \\
					&= \lim_{a\to-\infty} e^0-e^a \\
					&= 1.
		\end{aligned}$\hfill\null

		A graph of the area defined by this integral is given in Figure \ref{fig:impint1c}.

\mfigure{.55}{A graph of $f(x) = e^x$ in Example \ref{exa:ex_impint1}.}{fig:impint1c}{
\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
			xtick={-1,-5,-10},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
			ytick={1},
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=1.1,%
			xmin=-11,xmax=1%
]

\addplot [{\coloronefill},fill={\coloronefill}] coordinates {(-10.5,0)(-10.,0)(-9.5,0)(-9.,0.0001234)(-8.5,0.0002035)(-8.,0.0003355)(-7.5,0.0005531)(-7.,0.0009119)(-6.5,0.001503)(-6.,0.002479)(-5.5,0.004087)(-5.,0.006738)(-4.5,0.01111)(-4.,0.01832)(-3.5,0.0302)(-3.,0.04979)(-2.5,0.08208)(-2.,0.1353)(-1.5,0.2231)(-1.,0.3679)(-0.5,0.6065)(0,1.)} -- (axis cs:0,0)--cycle;

\addplot [{\colorone},thick,smooth] coordinates {(-10.5,0)(-10.,0)(-9.5,0)(-9.,0.0001234)(-8.5,0.0002035)(-8.,0.0003355)(-7.5,0.0005531)(-7.,0.0009119)(-6.5,0.001503)(-6.,0.002479)(-5.5,0.004087)(-5.,0.006738)(-4.5,0.01111)(-4.,0.01832)(-3.5,0.0302)(-3.,0.04979)(-2.5,0.08208)(-2.,0.1353)(-1.5,0.2231)(-1.,0.3679)(-0.5,0.6065)(0,1.)};

\draw (axis cs:-5,.75) node {\scriptsize $\ds f(x)=e^x$};
\end{axis}

\node [right] at (myplot.right of origin) { $x$};
\node [above] at (myplot.above origin) { $y$};
\end{tikzpicture}
}

\item		We will need to break this into two improper integrals and choose a value of $c$ as in part 3 of Definition \ref{def:imp_int1}. Any value of $c$ is fine; we choose $c=0$.

\begin{align*}%
		\int_{-\infty}^\infty \frac1{1+x^2}\ dx &= \lim_{a\to-\infty} \int_a^0\frac{1}{1+x^2}\ dx + \lim_{b\to\infty} \int_0^b\frac{1}{1+x^2}\ dx \\
						&= \lim_{a\to-\infty} \tan^{-1}x\Big|_a^0 + \lim_{b\to\infty} \tan^{-1}x\Big|_0^b\\
						&= \lim_{a\to-\infty} \left(\tan^{-1}0-\tan^{-1}a\right) + \lim_{b\to\infty} \left(\tan^{-1}b-\tan^{-1}0\right)\\
						&= \left(0-\frac{-\pi}2\right) + \left(\frac{\pi}2-0\right).\\
						\intertext{Each	limit exists, hence the original integral converges and has value:}
						&= \pi.
\end{align*}
%\enlargethispage{2\baselineskip}
A graph of the area defined by this integral is given in Figure \ref{fig:impint1d}.

\mfigure{.8}{A graph of $f(x) = \frac{1}{1+x^2}$ in Example \ref{exa:ex_impint1}.}{fig:impint1d}{\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
%			xtick={-1,-5,-10},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
			ytick={1},
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=1.1,%
			xmin=-11,xmax=11%
]

\addplot [{\coloronefill},fill={\coloronefill}] coordinates {(-10.5,0.008989)(-10.,0.009901)(-9.5,0.01096)(-9.,0.0122)(-8.5,0.01365)(-8.,0.01538)(-7.5,0.01747)(-7.,0.02)(-6.5,0.02312)(-6.,0.02703)(-5.5,0.032)(-5.,0.03846)(-4.5,0.04706)(-4.,0.05882)(-3.5,0.07547)(-3.,0.1)(-2.5,0.1379)(-2.,0.2)(-1.5,0.3077)(-1.,0.5)(-0.5,0.8)(0,1.)(0.5,0.8)(1.,0.5)(1.5,0.3077)(2.,0.2)(2.5,0.1379)(3.,0.1)(3.5,0.07547)(4.,0.05882)(4.5,0.04706)(5.,0.03846)(5.5,0.032)(6.,0.02703)(6.5,0.02312)(7.,0.02)(7.5,0.01747)(8.,0.01538)(8.5,0.01365)(9.,0.0122)(9.5,0.01096)(10.,0.009901)(10.5,0.008989)} --cycle;

\addplot [{\colorone},thick,smooth] coordinates {(-10.5,0.008989)(-10.,0.009901)(-9.5,0.01096)(-9.,0.0122)(-8.5,0.01365)(-8.,0.01538)(-7.5,0.01747)(-7.,0.02)(-6.5,0.02312)(-6.,0.02703)(-5.5,0.032)(-5.,0.03846)(-4.5,0.04706)(-4.,0.05882)(-3.5,0.07547)(-3.,0.1)(-2.5,0.1379)(-2.,0.2)(-1.5,0.3077)(-1.,0.5)(-0.5,0.8)(0,1.)(0.5,0.8)(1.,0.5)(1.5,0.3077)(2.,0.2)(2.5,0.1379)(3.,0.1)(3.5,0.07547)(4.,0.05882)(4.5,0.04706)(5.,0.03846)(5.5,0.032)(6.,0.02703)(6.5,0.02312)(7.,0.02)(7.5,0.01747)(8.,0.01538)(8.5,0.01365)(9.,0.0122)(9.5,0.01096)(10.,0.009901)(10.5,0.008989)};

\draw (axis cs:6,.75) node { $\ds f(x)=\frac{1}{1+x^2}$};
\end{axis}

\node [right] at (myplot.right of origin) { $x$};
\node [above] at (myplot.above origin) { $y$};
\end{tikzpicture}
}
\end{enumerate}
\vskip-\baselineskip
}
\end{solution}

The previous section introduced l'H\^opital's Rule, a method of evaluating limits that return indeterminate forms. It is not uncommon for the limits resulting from improper integrals to need this rule as demonstrated next.\\

\begin{example}{Improper integration and l'H\^opital's Rule}{ex_impint2}
{
Evaluate the improper integral $\ds \int_1^\infty \frac{\ln x}{x^2}\ dx.$}
\end{example}

\begin{solution}
{This integral will require the use of Integration by Parts. Let $u = \ln x$ and $dv = 1/x^2\ dx$. Then
\mfigure{.6}{A graph of $f(x) = \frac{\ln x}{x^2}$ in Example \ref{exa:ex_impint2}.}{fig:impint2}{
\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
			xtick={1,5,10},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
%			ytick={1},
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=.2,%
			xmin=-.1,xmax=10.5%
]

%\addplot [{\coloronefill},fill={\coloronefill}] coordinates {(0.1,3.162)(0.2,2.236)(0.3,1.826)(0.4,1.581)(0.5,1.414)(0.6,1.291)(0.7,1.195)(0.8,1.118)(0.9,1.054)(1.,1.)} -- (axis cs:1,0)--(axis cs:.1,0)--cycle;

\addplot [smooth,\colorone, fill={\coloronefill},area style,domain=1:10.5] {(ln(x))/(x^2)} \closedcycle;

%\addplot [{\colorone},thick,smooth] coordinates {(0.1,3.162)(0.2,2.236)(0.3,1.826)(0.4,1.581)(0.5,1.414)(0.6,1.291)(0.7,1.195)(0.8,1.118)(0.9,1.054)(1.,1.)};

\draw (axis cs:5,.15) node {$\ds f(x)=\frac{\ln(x)}{x^2}$};
\end{axis}

\node [right] at (myplot.right of origin) { $x$};
\node [above] at (myplot.above origin) {$y$};
\end{tikzpicture}
}
\begin{align*}
\int_1^\infty\frac{\ln x}{x^2}\ dx &= \lim_{b\to\infty}\int_1^b\frac{\ln x}{x^2}\ dx \\
			&=  \lim_{b\to\infty}\left(-\frac{\ln x}{x}\Big|_1^b +\int_1^b \frac{1}{x^2} \ dx \right)\\
			&=  \lim_{b\to\infty} \left.\left(-\frac{\ln x}{x} -\frac1x\right)\right|_1^b\\
			&=	\lim_{b\to\infty} \left(-\frac{\ln b}{b}-\frac1b - \left(-\ln 1-1\right)\right).\\
			\intertext{The $1/b$ and $\ln 1$ terms go to 0, leaving $\ds \lim_{b\to\infty} -\frac{\ln b}b + 1.$ We need to evaluate $\ds \lim_{b\to\infty} \frac{\ln b}{b}$ with l'H\^opital's Rule. We have:}
		\lim_{b\to\infty}\frac{\ln b}b &\stackrel{\ \text{ by LHR \rule[-5pt]{0pt}{3pt}} \ }{=} \lim_{b\to\infty} \frac{1/b}{1} \\
		&= 0.
\intertext{Thus the improper integral evaluates as: }
\int_1^\infty\frac{\ln x}{x^2}\ dx &= 1.
\end{align*}
}
\end{solution}

\subsection*{Improper Integrals with Infinite Range}

We have just considered definite integrals where the interval of integration was infinite. We now consider another type of improper integration, where the range of the integrand is infinite.

\begin{definition}{Improper Integration with Infinite Range}{def:imp_int2}
{Let $f(x)$ be a continuous function on $[a,b]$ except at $c$, $a\leq c\leq b$, where $x=c$ is a vertical asymptote of $f$. Define\index{integration!improper}\index{improper integration}
$$\int_a^b f(x)\ dx = \lim_{t\to c^-}\int_a^t f(x)\ dx + \lim_{t\to c^+}\int_t^b f(x)\ dx.$$
Again, the integral converges if both limits exist and diverges otherwise.
}
\end{definition}

\begin{example}{Improper integration of functions with infinite range}{ex_impint3}
{
Evaluate the following improper integrals:
\vskip 10pt
$\ds 1.\ \int_0^1\frac1{\sqrt{x}}\ dx \hskip 50pt 2. \ \int_{-1}^1\frac{1}{x^2}\ dx.$
}
\end{example}

\begin{solution}
{\begin{enumerate}
\item		A graph of $f(x) = 1/\sqrt{x}$ is given in Figure \ref{fig:impint3}. Notice that $f$ has a vertical asymptote at $x=0$; in some sense, we are trying to compute the area of a region that has no ``top.'' Could this have a finite value?
\begin{align*} \int_0^1 \frac{1}{\sqrt{x}}\ dx &= \lim_{a\to0^+}\int_a^1 \frac1{\sqrt{x}}\ dx \\
			&=	\lim_{a\to0^+} 2\sqrt{x}\Big|_a^1 \\
			&= \lim_{a\to0^+} 2\left(\sqrt{1}-\sqrt{a}\right)\\
			&=	2.
\end{align*}
It turns out that the region does have a finite area even though it has no upper bound (strange things can occur in mathematics when considering the infinite).

{\textbf{Note:} In Definition \ref{def:imp_int2}, $c$ can be one of the endpoints ($a$ or $b$). In that case, there is only one limit to consider as part of the definition.}

\mfigure{.65}{A graph of $f(x)=\frac{1}{\sqrt{x}}$ in Example \ref{exa:ex_impint3}.}{fig:impint3}{
\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
%			xtick={1,5,10},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
%			ytick={1},
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=11,%
			xmin=-.1,xmax=1.1%
]

\addplot [{\coloronefill},fill={\coloronefill}] coordinates {(0.01,10.)(0.02,7.071)(0.03,5.774)(0.04,5.)(0.05,4.472)(0.06,4.082)(0.07,3.78)(0.08,3.536)(0.09,3.333)(0.1,3.162)(0.11,3.015)(0.12,2.887)(0.13,2.774)(0.14,2.673)(0.15,2.582)(0.16,2.5)(0.17,2.425)(0.18,2.357)(0.19,2.294)(0.2,2.236)(0.3,1.826)(0.4,1.581)(0.5,1.414)(0.6,1.291)(0.7,1.195)(0.8,1.118)(0.9,1.054)(1.,1.)} -- (axis cs:1,0)--(axis cs:.01,0)--cycle;

\addplot [{\colorone},thick,smooth] coordinates {(0.01,10.)(0.02,7.071)(0.03,5.774)(0.04,5.)(0.05,4.472)(0.06,4.082)(0.07,3.78)(0.08,3.536)(0.09,3.333)(0.1,3.162)(0.11,3.015)(0.12,2.887)(0.13,2.774)(0.14,2.673)(0.15,2.582)(0.16,2.5)(0.17,2.425)(0.18,2.357)(0.19,2.294)(0.2,2.236)(0.3,1.826)(0.4,1.581)(0.5,1.414)(0.6,1.291)(0.7,1.195)(0.8,1.118)(0.9,1.054)(1.,1.)};

\draw (axis cs:.5,5) node { $\ds f(x)=\frac{1}{\sqrt{x}}$};
\end{axis}

\node [right] at (myplot.right of origin) {\scriptsize $x$};
\node [above] at (myplot.above origin) {\scriptsize $y$};
\end{tikzpicture}
}

\item		The function $f(x) = 1/x^2$ has a vertical asymptote at $x=0$, as shown in Figure \ref{fig:impint3b}, so this integral is an improper integral. Let's eschew using limits for a moment and proceed without recognizing the improper nature of the integral. This leads to:
\begin{align*}
\int_{-1}^1\frac1{x^2}\ dx &= -\frac1x\Big|_{-1}^1\\
			&= -1 - (1)\\
			&=-2 !
\end{align*}
\mfigure{.6}{A graph of $f(x)=\frac{1}{x^2}$ in Example \ref{exa:ex_impint3}.}{fig:impint3b}{
\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
%			xtick={.1,.5,1},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
%			ytick={1},
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=11,%
			xmin=-1.1,xmax=1.1%
]

\addplot [{\coloronefill},fill={\coloronefill},smooth] coordinates {(-1.,1.)(-0.9,1.235)(-0.8,1.563)(-0.7,2.041)(-0.6,2.778)(-0.5,4.)(-0.4,6.25)(-0.3,11.11)(-0.2,25.)} -- (axis cs:0,11)--(axis cs:0,0)--(axis cs:-1,0) --cycle;

\addplot [{\colorone},thick,smooth] coordinates {(-1.,1.)(-0.9,1.235)(-0.8,1.563)(-0.7,2.041)(-0.6,2.778)(-0.5,4.)(-0.4,6.25)(-0.3,11.11)(-0.2,25.)};

\addplot [{\coloronefill},fill={\coloronefill},smooth] coordinates {(0.2,25.)(0.3,11.11)(0.4,6.25)(0.5,4.)(0.6,2.778)(0.7,2.041)(0.8,1.563)(0.9,1.235)(1.,1.)} -- (axis cs:1,0)--(axis cs:0,0)--(axis cs:0,11) --cycle;

\addplot [{\colorone},thick,smooth] coordinates {(0.2,25.)(0.3,11.11)(0.4,6.25)(0.5,4.)(0.6,2.778)(0.7,2.041)(0.8,1.563)(0.9,1.235)(1.,1.)};

\draw (axis cs:.7,7) node { $\ds f(x)=\frac{1}{x^2}$};
\end{axis}

\node [right] at (myplot.right of origin) {\scriptsize $x$};
\node [above] at (myplot.above origin) {\scriptsize $y$};
\end{tikzpicture}
}
Clearly the area in question is above the $x$-axis, yet the area is supposedly negative! Why does our answer not match our intuition? To answer this, evaluate the integral using Definition \ref{def:imp_int2}.
\begin{align*}
\int_{-1}^1\frac1{x^2}\ dx &= \lim_{t\to0^-}\int_{-1}^t \frac1{x^2}\ dx + \lim_{t\to0^+}\int_t^1\frac1{x^2}\ dx \\
			&= \lim_{t\to0^-}-\frac1x\Big|_{-1}^t + \lim_{t\to0^+}-\frac1x\Big|_t^1\\
			&= \lim_{t\to0^-}-\frac1t-1 + \lim_{t\to0^+} -1+\frac1t\\
			&\Rightarrow \Big(\infty-1\Big)\ + \ \Big(- 1+\infty\Big).
\end{align*}
Neither limit converges hence the original improper integral diverges. The nonsensical answer we obtained by ignoring the improper nature of the integral is just that: nonsensical.
%\mnote{.8}{\textbf{Note:} In Example \ref{ex_impint3}, \#2, the final line of calculation states:
%$$\text{``}(\infty-1)+(-\infty-1)\text{.''}$$
%Each parenthetical statement stands alone and is the result of an individual limit. We are \textit{not} dealing with the indeterminate form ``$\infty-\infty$'' as the ``infinities'' do not originate from one limit.}
\end{enumerate}
}
\end{solution}

\subsection*{ Understanding Convergence and Divergence}

Oftentimes we are interested in knowing simply whether or not an improper integral converges, and not necessarily the value of a convergent integral. We provide here several tools that help determine the convergence or divergence of improper integrals without integrating.

Our first tool is to understand the behavior of functions of the form $\ds \frac1{x\hskip1pt ^p}$.\\

\begin{example}{Improper integration of $1/x^p$}{ex_impint4}
{
Determine the values of $p$ for which $\ds \int_1^\infty \frac1{x\hskip1pt ^p}\ dx$ converges.
}
\end{example}

\begin{solution}
{We begin by integrating and then evaluating the limit.
\begin{align*}
\int_1^\infty \frac1{x\hskip1pt ^p}\ dx &=	\lim_{b\to\infty}\int_1^b\frac1{x\hskip1pt ^p}\ dx\\
		&=	\lim_{b\to\infty}\int_1^b x^{-p}\ dx \qquad \text{\small (assume $p\neq 1$)}\\
		&= \lim_{b\to\infty} \frac{1}{-p+1}x^{-p+1}\Big|_1^b\\
		&= \lim_{b\to\infty} \frac{1}{1-p}\big(b\hskip1pt^{1-p}-1^{1-p}\big).\\
\end{align*}
When does this limit converge -- i.e., when is this limit \textit{not} $\infty$? This limit converges precisely when the power of $b$ is less than 0: when $1-p<0 \Rightarrow 1<p$.

\mfigure{.75}{Plotting functions of the form $1/x\,^p$ in Example \ref{exa:ex_impint4}.}{fig:impint4}{
\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
			xtick={1},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
			ytick=\empty,
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=6,%
			xmin=-.1,xmax=2.1%
]

\addplot [dashed,thick,smooth] coordinates {(0.1,10.)(0.15,6.667)(0.2,5.)(0.25,4.)(0.3,3.333)(0.35,2.857)(0.4,2.5)(0.45,2.222)(0.5,2.)(0.55,1.818)(0.6,1.667)(0.65,1.538)(0.7,1.429)(0.75,1.333)(0.8,1.25)(0.85,1.176)(0.9,1.111)(0.95,1.053)(1.,1.)(1.05,0.9524)(1.1,0.9091)(1.15,0.8696)(1.2,0.8333)(1.25,0.8)(1.3,0.7692)(1.35,0.7407)(1.4,0.7143)(1.45,0.6897)(1.5,0.6667)(1.55,0.6452)(1.6,0.625)(1.65,0.6061)(1.7,0.5882)(1.75,0.5714)(1.8,0.5556)(1.85,0.5405)(1.9,0.5263)(1.95,0.5128)(2.,0.5)};

\addplot [{\colorone},thick,smooth] coordinates {(0.1,31.62)(0.15,17.21)(0.2,11.18)(0.25,8.)(0.3,6.086)(0.35,4.829)(0.4,3.953)(0.45,3.313)(0.5,2.828)(0.55,2.452)(0.6,2.152)(0.65,1.908)(0.7,1.707)(0.75,1.54)(0.8,1.398)(0.85,1.276)(0.9,1.171)(0.95,1.08)(1.,1.)(1.05,0.9294)(1.1,0.8668)(1.15,0.8109)(1.2,0.7607)(1.25,0.7155)(1.3,0.6747)(1.35,0.6375)(1.4,0.6037)(1.45,0.5727)(1.5,0.5443)(1.55,0.5182)(1.6,0.4941)(1.65,0.4718)(1.7,0.4512)(1.75,0.432)(1.8,0.4141)(1.85,0.3974)(1.9,0.3818)(1.95,0.3672)(2.,0.3536)};

\addplot [{\colortwo},thick,smooth] coordinates {(.05,4.47)(0.1,3.162)(0.15,2.582)(0.2,2.236)(0.25,2.)(0.3,1.826)(0.35,1.69)(0.4,1.581)(0.45,1.491)(0.5,1.414)(0.55,1.348)(0.6,1.291)(0.65,1.24)(0.7,1.195)(0.75,1.155)(0.8,1.118)(0.85,1.085)(0.9,1.054)(0.95,1.026)(1.,1.)(1.05,0.9759)(1.1,0.9535)(1.15,0.9325)(1.2,0.9129)(1.25,0.8944)(1.3,0.8771)(1.35,0.8607)(1.4,0.8452)(1.45,0.8305)(1.5,0.8165)(1.55,0.8032)(1.6,0.7906)(1.65,0.7785)(1.7,0.767)(1.75,0.7559)(1.8,0.7454)(1.85,0.7352)(1.9,0.7255)(1.95,0.7161)(2.,0.7071)};

\draw (axis cs:.7,5) node { $\ds f(x)=\frac{1}{x\,^q}$};
\draw (axis cs:.35,.8) node { $\ds f(x)=\frac{1}{x\,^p}$};
\draw (axis cs:1.5,3) node { $p<1<q$};
\end{axis}

\node [right] at (myplot.right of origin) { $x$};
\node [above] at (myplot.above origin) { $y$};
\end{tikzpicture}
}

Our analysis shows that if $p>1$, then $\ds\int_1^\infty \frac1{x\hskip1pt ^p}\ dx $ converges. When $p<1$ the improper integral diverges; we showed in Example \ref{exa:ex_impint1} that when $p=1$ the integral also diverges.

Figure \ref{fig:impint4} graphs $y=1/x$ with a dashed line, along with graphs of $y=1/x^p$, $p<1$, and $y=1/x^q$, $q>1$. Somehow the dashed line forms a dividing line between convergence and divergence. %A function of the form $1/x^q$ will be under the dashed line on $[1,\infty)$ when $q>1$. Even if $q$ is ``very close'' to 1, the difference will be enough to force convergence.
}\\
\end{solution}

The result of Example \ref{exa:ex_impint4} provides an important tool in determining the convergence of other integrals. A similar result is proved in the exercises about improper integrals of the form $\ds \int_0^1\frac1{x\hskip1pt ^p}\ dx$. These results are summarized in the following Theorem.

\begin{theorem}{Convergence of Improper Integrals $\ds \int_1^\infty\frac1{x\hskip1pt ^p}\ dx$ and $\ds \int_0^1\frac1{x\hskip1pt ^p}\ dx$.}{idea:impint1}
{
\begin{enumerate}
\item		The improper integral $\ds \int_1^\infty\frac1{x\hskip1pt ^p}\ dx$ converges when $p>1$ and diverges when $p\leq 1.$\index{convergence!of improper int.}\index{divergence!of improper int.}
\item		The improper integral $\ds \int_0^1\frac1{x\hskip1pt ^p}\ dx$ converges when $p<1$ and diverges when $p\geq 1.$
\end{enumerate}
}
\end{theorem}

%
A basic technique in determining convergence of improper integrals is to compare an integrand whose convergence is unknown to an integrand whose convergence is known. We often use integrands of the form $1/x\hskip1pt ^p$ to compare to as their convergence on certain intervals is known. This is described in the following theorem.

{\textbf{Note:} We used the upper and lower bound of ``1'' in Theorem \ref{thm:idea:impint1} for convenience. It can be replaced by any $a$ where $a>0$.
}

\begin{theorem}{Direct Comparison Test for Improper Integrals}{impint_comparison}
{
Let $f$ and $g$ be continuous on $[a,\infty)$ where $0\leq f(x)\leq g(x)$ for all $x$ in $[a,\infty)$.
	\begin{enumerate}
	\item		If $\ds \int_a^\infty g(x)\ dx$ converges, then $\ds \int_a^\infty f(x)\ dx$ converges.
	\index{integration!improper}\index{convergence!Direct Comparison Test!for integration}\index{divergence!Direct Comparison Test!for integration}\index{Direct Comparison Test!for integration}\index{convergence!of improper int.}\index{divergence!of improper int.}
	\item		If $\ds \int_a^\infty f(x)\ dx$ diverges, then $\ds \int_a^\infty g(x)\ dx$ diverges.
	\end{enumerate}
	%\item		Let $f$ and $g$ be continuous functions on $[a,b]$ except at $x=c$, where each has a vertical asymptote, and $0\leq f(x)\leq g(x)$ for all $x$ in $[a,b]$, $x\neq c$.
	%	\begin{itemize}
	%	\item		If $\ds \int_a^b g(x)\ dx$ converges, then $\ds \int_a^b f(x)\ dx$ converges.
	%	\item		If $\ds \int_a^b f(x)\ dx$ diverges, then $\ds \int_a^b g(x)\ dx$ diverges.
	%	\end{itemize}
	%\end{itemize}
	}
\end{theorem}

\begin{example}{Determining convergence of improper integrals}{ex_impint5}{
Determine the convergence of the following improper integrals.\\
%\noindent%
%\begin{minipage}[t]{.5\textwidth}
%\begin{enumerate}
1. $\ds \int_1^\infty e^{-x^2}\ dx$ \qquad\qquad 2. $\ds \int_3^\infty \frac{1}{\sqrt{x^2-x}}\ dx$
%\end{enumerate}
%\end{minipage}
%\begin{minipage}[t]{.5\textwidth}
%\begin{enumerate}\addtocounter{enumi}{2}
%\item		$\ds \int_0^2\frac{1}{(x+5)^{1/3}}\ dx$
%\end{enumerate}
%\end{minipage}
}
\end{example}

\begin{solution}
{\begin{enumerate}
\item The function $f(x) = e^{-x^2}$ does not have an antiderivative expressible in terms of elementary functions, so we cannot integrate directly. It is comparable to $g(x)=1/x^2$, and as demonstrated in Figure \ref{fig:impint5}, $e^{-x^2} < 1/x^2$ on $[1,\infty)$. We know from Theorem \ref{thm:idea:impint1} that $\ds \int_1^\infty \frac{1}{x^2}\ dx$ converges, hence $\ds\int_1^\infty e^{-x^2}\ dx$ also converges.

\mfigure{.6}{Graphs of $f(x) = e^{-x^2}$ and $f(x)= 1/x^2$ in Example \ref{exa:ex_impint5}.}{fig:impint5}{\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
%			xtick={1},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
%			ytick=\empty,
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=1.1,%
			xmin=-.1,xmax=4.1%
]

\addplot [{\colorone},thick,smooth] coordinates {(1.,0.3679)(1.1,0.2982)(1.2,0.2369)(1.3,0.1845)(1.4,0.1409)(1.5,0.1054)(1.6,0.0773)(1.7,0.05558)(1.8,0.03916)(1.9,0.02705)(2.,0.01832)(2.1,0.01216)(2.2,0.007907)(2.3,0.005042)(2.4,0.003151)(2.5,0.00193)(2.6,0.001159)(2.7,0.0006823)(2.8,0.0003937)(2.9,0.0002226)(3.,0.0001234)(3.1,0)(3.2,0)(3.3,0)(3.4,0)(3.5,0)(3.6,0)(3.7,0)(3.8,0)(3.9,0)(4.,0)};

\addplot [{\colortwo},thick,smooth] coordinates {(1.,1.)(1.1,0.8264)(1.2,0.6944)(1.3,0.5917)(1.4,0.5102)(1.5,0.4444)(1.6,0.3906)(1.7,0.346)(1.8,0.3086)(1.9,0.277)(2.,0.25)(2.1,0.2268)(2.2,0.2066)(2.3,0.189)(2.4,0.1736)(2.5,0.16)(2.6,0.1479)(2.7,0.1372)(2.8,0.1276)(2.9,0.1189)(3.,0.1111)(3.1,0.1041)(3.2,0.09766)(3.3,0.09183)(3.4,0.08651)(3.5,0.08163)(3.6,0.07716)(3.7,0.07305)(3.8,0.06925)(3.9,0.06575)(4.,0.0625)};

\draw (axis cs:.7,.45) node { $\ds f(x)=e^{-x^2}$};
\draw (axis cs:1.9,.8) node { $\ds f(x)=\frac{1}{x^2}$};

\end{axis}

\node [right] at (myplot.right of origin) { $x$};
\node [above] at (myplot.above origin) { $y$};
\end{tikzpicture}
}

\item		Note that for large values of $x$, $\ds \frac{1}{\sqrt{x^2-x}} \approx \frac{1}{\sqrt{x^2}} =\frac{1}{x}$. We know from Theorem \ref{thm:idea:impint1} and the subsequent note that  $\ds \int_3^\infty \frac1x\ dx$ diverges, so we seek to compare the original integrand to $1/x$.

It is easy to see that when $x>0$, we have $x = \sqrt{x^2} > \sqrt{x^2-x}$. Taking reciprocals reverses the inequality, giving $$\frac1x < \frac1{\sqrt{x^2-x}}.$$

Using Theorem \ref{thm:impint_comparison}, we conclude that since $\ds\int_3^\infty\frac1x\ dx$ diverges, $\ds\int_3^\infty\frac1{\sqrt{x^2-x}}\ dx$ diverges as well. Figure \ref{fig:impint5b} illustrates this.

\mfigure{.75}{Graphs of $f(x) = 1/\sqrt{x^2-x}$ and $f(x)= 1/x$ in Example \ref{exa:ex_impint5}.}{fig:impint5b}{
\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
%			xtick={1},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
%			ytick=\empty,
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=.5,%
			xmin=-.1,xmax=6.2%
]

\addplot [{\colorone},thick,smooth] coordinates {(3.,0.4082)(3.1,0.3919)(3.2,0.3769)(3.3,0.363)(3.4,0.3501)(3.5,0.3381)(3.6,0.3269)(3.7,0.3164)(3.8,0.3066)(3.9,0.2974)(4.,0.2887)(4.1,0.2805)(4.2,0.2728)(4.3,0.2655)(4.4,0.2585)(4.5,0.252)(4.6,0.2457)(4.7,0.2398)(4.8,0.2341)(4.9,0.2288)(5.,0.2236)(5.1,0.2187)(5.2,0.214)(5.3,0.2095)(5.4,0.2052)(5.5,0.201)(5.6,0.197)(5.7,0.1932)(5.8,0.1895)(5.9,0.186)(6.,0.1826)};

\addplot [{\colortwo},thick,smooth] coordinates {(3.,0.3333)(3.1,0.3226)(3.2,0.3125)(3.3,0.303)(3.4,0.2941)(3.5,0.2857)(3.6,0.2778)(3.7,0.2703)(3.8,0.2632)(3.9,0.2564)(4.,0.25)(4.1,0.2439)(4.2,0.2381)(4.3,0.2326)(4.4,0.2273)(4.5,0.2222)(4.6,0.2174)(4.7,0.2128)(4.8,0.2083)(4.9,0.2041)(5.,0.2)(5.1,0.1961)(5.2,0.1923)(5.3,0.1887)(5.4,0.1852)(5.5,0.1818)(5.6,0.1786)(5.7,0.1754)(5.8,0.1724)(5.9,0.1695)(6.,0.1667)};

\draw (axis cs:4,.45) node { $\ds f(x)=\frac{1}{\sqrt{x^2-x}}$};
\draw (axis cs:2.5,.2) node { $\ds f(x)=\frac{1}{x}$};

\end{axis}

\node [right] at (myplot.right of origin) {\scriptsize $x$};
\node [above] at (myplot.above origin) {\scriptsize $y$};
\end{tikzpicture}
}
%\item		Since $\ds \frac1{(x+5)^{1/3}} < \frac{1}{x^{1/3}}$ and by Key Idea \ref{idea:impint1} the integral $\ds \int_0^1\frac{1}{x^{1/3}}\ dx$ converges, the integral $\ds \int_0^2\frac{1}{(x+5)^{1/3}}\ dx$ converges as well.
\end{enumerate}
}
\end{solution}

Being able to compare ``unknown'' integrals to ``known'' integrals is very useful in determining convergence. However, some of our examples were a little ``too nice.'' For instance, it was convenient that $\ds \frac{1}x < \frac{1}{\sqrt{x^2-x}}$, but what if the ``$-x$'' were replaced with a ``$+2x+5$''? That is, what can we say about the convergence of $\ds \int_3^\infty\frac{1}{\sqrt{x^2+2x+5}}\ dx$? We have $\ds \frac{1}{x} > \frac1{\sqrt{x^2+2x+5}}$, so we cannot use Theorem \ref{thm:impint_comparison}.

In cases like this (and many more) it is useful to employ the following theorem.
%

\begin{theorem}{Limit Comparison Test for Improper Integrals}{impint_limit}
{
%\begin{itemize}
		Let $f$ and $g$ be continuous functions on $[a,\infty)$ where $f(x)>0$ and $g(x)>0$ for all $x$. If $$\lim_{x\to\infty} \frac{f(x)}{g(x)} = L,\qquad 0<L<\infty,$$
	then $$\int_a^\infty f(x)\ dx \quad \text{and} \quad \int_a^\infty g(x)\ dx$$ either both converge or both diverge.%
	\index{integration!improper}\index{convergence!Limit Comparison Test!for integration}\index{divergence!Limit Comparison Test!for integration}\index{Limit Comparison Test!for integration}\index{convergence!of improper int.}\index{divergence!of improper int.}
%	\item		Let $f$ and $g$ be continuous functions on $[a,b]$ except at $x=c$, where each has a vertical asymptote, and $f(x)>0$ and $g(x)>0$ for all $x$ in $[a,b]$, $x\neq c$. If
%	$$\lim_{x\to c^-} \frac{f(x)}{g(x)} = L_1 \quad \text{and} \quad \lim_{x\to c^+}\frac{f(x)}{g(x)} = L_2,\qquad 0<L_1,L_2<\infty,$$
%	then $$\int_a^b f(x)\ dx \quad \text{and} \quad \int_a^b g(x)\ dx$$ either both converge or both diverge.
%\end{itemize}
}
\end{theorem}

\begin{example}{Determining convergence of improper integrals}{ex_impint6}
{
Determine the convergence of $\ds \int_3^{\infty} \frac{1}{\sqrt{x^2+2x+5}}\ dx$.
}
\end{example}

\begin{solution}
{As $x$ gets large, the quadratic inside the square root function will begin to behave much like $y=x$. So we compare \small$\ds\frac{1}{\sqrt{x^2+2x+5}}$\normalsize\ to \small$\ds\frac1x$\normalsize\ with the Limit Comparison Test:

$$
\lim_{x\to\infty} \frac{1/\sqrt{x^2+2x+5}}{1/x} = \lim_{x\to\infty}\frac{x}{\sqrt{x^2+2x+5}}.$$

The immediate evaluation of this limit returns $\infty/\infty$, an indeterminate form. Using l'H\^opital's Rule seems appropriate, but in this situation, it does not lead to useful results. (We encourage the reader to employ l'H\^opital's Rule at least once to verify this.)

The trouble is the square root function. To get rid of it, we employ the following fact: If $\ds \lim_{x\to c} f(x) = L$, then $\ds\lim_{x\to c} f(x)^2 = L^2.$ (This is true when either $c$ or $L$ is $\infty$.) So we consider now the limit
$$\lim_{x\to\infty} \frac{x^2}{x^2+2x+5}.$$ This converges to 1, meaning the original limit also converged to 1. As $x$ gets very large, the function
\small$\ds\frac{1}{\sqrt{x^2+2x+5}}$\normalsize\ looks very much like \small$\ds\frac1x.$\normalsize\
Since we know that \small$\ds\int_3^{\infty} \frac1x\ dx$\normalsize\ diverges, by the Limit Comparison Test we know that \small$\ds\int_3^\infty\frac{1}{\sqrt{x^2+2x+5}}\ dx$\normalsize\ also diverges. Figure \ref{fig:impint6} graphs $f(x)=1/\sqrt{x^2+2x+5}$ and $f(x)=1/x$, illustrating that as $x$ gets large, the functions become indistinguishable.
\mfigure{.6}{Graphing $f(x)=\frac{1}{\sqrt{x^2+2x+5}}$ and $f(x)=\frac1x$ in Example \ref{exa:ex_impint6}.}{fig:impint6}{
\begin{tikzpicture}
\begin{axis}[width=\textwidth,%
axis y line=middle,axis x line=middle,name=myplot,axis on top,%
			%x=.37\marginparwidth,
			%y=.37\marginparwidth,
%			xtick={1},%
%			extra x ticks={.5,3},
%			extra x tick labels={$a$,$b$},
%			ytick=\empty,
			%minor y tick num=1,%extra y ticks={-5,-3,...,7},%
%			minor x tick num=4,
			ymin=-.1,ymax=.35,%
			xmin=-.1,xmax=21%
]

\addplot [{\colortwo},thick,smooth] coordinates {(3.,0.3333)(4.,0.25)(5.,0.2)(6.,0.1667)(7.,0.1429)(8.,0.125)(9.,0.1111)(10.,0.1)(11.,0.09091)(12.,0.08333)(13.,0.07692)(14.,0.07143)(15.,0.06667)(16.,0.0625)(17.,0.05882)(18.,0.05556)(19.,0.05263)(20.,0.05)};

\addplot [{\colorone},thick,smooth] coordinates {(3.,0.2236)(4.,0.1857)(5.,0.1581)(6.,0.1374)(7.,0.1213)(8.,0.1085)(9.,0.09806)(10.,0.08944)(11.,0.0822)(12.,0.07603)(13.,0.07071)(14.,0.06608)(15.,0.06202)(16.,0.05842)(17.,0.05522)(18.,0.05234)(19.,0.04975)(20.,0.0474)};

\draw (axis cs:10,.3) node {$\ds f(x)=\frac{1}{\sqrt{x^2+2x+5}}$};
\draw (axis cs:4,.09) node { $\ds f(x)=\frac{1}{x}$};

\end{axis}

\node [right] at (myplot.right of origin) { $x$};
\node [above] at (myplot.above origin) { $y$};
\end{tikzpicture}
}
}
\end{solution}

%
%\enlargethispage{3\baselineskip}
Both the Direct and Limit Comparison Tests were given in terms of integrals over an infinite interval. There are versions that apply to improper integrals with an infinite range, but as they are a bit wordy and a little more difficult to employ, they are omitted from this text.\\

This chapter has explored many integration techniques. We learned Substitution, which ``undoes'' the Chain Rule of differentiation, as well as Integration by Parts, which ``undoes'' the Product Rule. We also learned specialized techniques for handling trigonometric functions % and introduced the hyperbolic functions, which are closely related to the trigonometric functions.
All techniques effectively have this goal in common: rewrite the integrand in a new way so that the integration step is easier to see and implement.

As stated before, integration is, in general, hard. It is easy to write a function whose antiderivative is impossible to write in terms of elementary functions, and even when a function does have an antiderivative expressible by elementary functions, it may be really hard to discover what it is. The powerful computer algebra system \textit{Mathematica}\textsuperscript{\textregistered} has approximately 1,000 pages of code dedicated to integration.

Do not let this difficulty discourage you. There is great value in learning integration techniques, as they allow one to manipulate an integral in ways that can illuminate a concept for greater understanding. There is also great value in understanding the need for good numerical techniques: the Trapezoidal and Simpson's Rules are just the beginning of powerful techniques for approximating the value of integration.\\

Chapter \ref{chap:ApplicationsOfIntegration} stresses the uses of integration. We generally do not find antiderivatives for antiderivative's sake, but rather because they provide the solution to some type of problem. The following chapter introduces us to a number of different problems whose solution is provided by integration.

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

\begin{enumialphparenastyle}

\begin{ex}
	Determine whether $\ds\int_1^{\infty}\frac{1}{x^2}\,dx$ is convergent or divergent.
	\begin{sol}
		Converges to 1.
	\end{sol}
\end{ex}

\begin{ex}
	Determine whether $\ds\int_e^{\infty}\frac{1}{x\sqrt{\ln x}}\,dx$ is convergent or divergent.
	\begin{sol}
		Diverges.
	\end{sol}
\end{ex}

\begin{ex}
	Evaluate the improper integral $\ds\int_0^{\infty}e^{-3x}\,dx$.
	\begin{sol}
		1/3
	\end{sol}
\end{ex}

\begin{ex}
	Determine if $\ds\int_1^e\frac{1}{x(\ln x)^2}\,dx$ is convergent or divergent. Evaluate it if it is convergent.
	\begin{sol}
		Divergent.
	\end{sol}
\end{ex}

\begin{ex}
	Show that $\ds\int_0^{\infty}e^{-x}\sin^2\left(\frac{\pi x}{2}\right)\,dx$ converges.
\end{ex}

\begin{ex}
	Evaluate $\ds\int_{-\infty}^{\infty}\frac{1}{x^2+1}\,dx$ and $\ds\int_{-\infty}^{\infty}\frac{x}{x^2+1}\,dx$.
\end{ex}

\begin{ex}
	Determine whether the following improper integrals are convergent or divergent. Evaluate those that are convergent.
	\begin{enumerate}
		\item	$\int_{0}^{\infty}\dfrac{1}{x^2+1}\,dx$
		\item	$\int_{0}^{\infty}\dfrac{x}{x^2+1}\,dx$
		\item	$\int_{0}^{\infty}e^{-x}(\cos x+\sin x)\,dx$. [Hint: What is the derivative of $-e^{-x}\cos x?$]
		\item	$\int_{0}^{\pi/2}\sec^{2}x\,dx$
		\item	$\int_{0}^{4}\dfrac{1}{(4-x)^{2/5}}\,dx$
	\end{enumerate}
	\begin{sol}
		\begin{enumerate}
			\item	$\pi/2$
			\item	divergent (to $\infty$)
			\item	1
			\item	divergent (to $\infty$)
			\item	$\frac{5}{3}(4^{3/5})$
		\end{enumerate}
	\end{sol}
\end{ex}

\begin{ex}
	Prove that the integral $\int_{1}^{\infty}\dfrac{1}{x^p}\,dx$ is convergent if $p>1$ and divergent if $0<p\leq 1$.
\end{ex}

\begin{ex}
	Suppose that $p>0$. Find all values of $p$ for which $\int_{0}^{1}\dfrac{1}{x^p}\,dx$ converges.
	\begin{sol}
		$0<p<1$
	\end{sol}
\end{ex}

\begin{ex}
	Show that $\int_{1}^{\infty}\dfrac{\sin^2 x}{x(\sqrt{x}+1)}\,dx$ converges.
\end{ex}

\end{enumialphparenastyle}


\section{Calculus}
$x$ is a variable, $k$, $a$ and $b$ are constants, and $f$ and $g$ are functions.
\begin{center}
    \begin{longtable}{c|c|c}
        \textbf{Function} & \textbf{Derivative} & \textbf{Antiderivative}
        \\[0.25cm] \hline
        $x$ & $1$ & $\frac{1}{2}x^2$
        \\
        $x^n$ & $nx^{n - 1}$ & $\frac{1}{n + 1}x^{n + 1}$
        \\
        $\sqrt{x}$ & $\frac{1}{2 \sqrt{x}}$ & $\frac{2}{3}x^\frac{3}{2}$
        \\
        $\frac{1}{x}$ & $\frac{-1}{x^2}$ & $\ln(x)$
        \\
        $ax + b$ & $a$
        \\
        $k$ & $0$ & $kx + b$
        \\
        $\sin{x}$ & $\cos{x}$ & $-\cos{x}$
        \\
        $\cos{x}$ & $-\sin{x}$ & $\sin{x}$
        \\
        $\tan{x}$ & $1 + \tan^2{x} \quad \text{or} \quad \frac{1}{\cos^2{x}}$ & $\ln\left(\frac{1}{\cos{x}}\right)$
        \\
        $k \cdot f$ & $k \cdot f'$
        \\
        $f \pm g$ & $f' \pm g'$
        \\
        $f \cdot g$ & $f' \cdot g + f \cdot g'$
        \\
        $\frac{f}{g}$ & $\frac{f' \cdot g - f \cdot g'}{g^2}$
        \\
        $e^x$ & $e^x$ & $e^x$
        \\
        $10^x$ & $\ln(10) \cdot 10^x$ & $\frac{10^x}{\ln(10)}$
    \end{longtable}
\end{center}


\section{Discriminative / generative modeling}

\textbf{Discr.:} estimate $P(y\vert x)$, \enskip\textbf{Generative:} $P(y,x)$

\textbf{Chain rule:} \highlight*{$P(x,y) = P(y) P(x\vert y)$}

%\begin{highlightbox}
%	1. Estimate prior on labels $P(y)$\\
%	2. Est. cond. distr. for \textit{each class} $y$: $P(x\vert y)$\\
%	3. Predict using Bayes: \highlight*{$\textstyle P(y\vert x) = \frac{1}{Z} P(x,y)$},\\
%	\phantom{3.} $Z \!=\! P(x)  \!=\! \sum_{y'} P(x,y')$
%\end{highlightbox}

% ===
\emph{Deriving Decision Rules}\vspace{1pt}
\begin{highlightbox}
	1. Estimate prior on labels $P(y)$\\
	2. Est. cond. distr. for \textit{each class} $y$: $P(x\vert y)$\\
	\phantom{2.} $\rightsquigarrow Z \!=\! P(x)  \!=\! \sum_{y'} P(x,y')$\\
	3. Predict using Bayes: \highlight*{$\textstyle P(y\vert x) = \frac{1}{Z} P(x,y)$},\\
	4. Minimize misclassification error:\\
	\phantom{4.} $\hat y = \arg\!\max P(y\vert x) = \arg\!\max\limits_y P(y)P(x\vert y)$\vspace{-7pt}\\
	\phantom{4. $\hat y$}$\;= ... \prod_{i=1}^d P(x_i,y)$%\vspace{-7pt}
\end{highlightbox}

%\begin{highlightbox}
%	1. Est. $P(y)$ and $P(x\vert y)$ \enskip $\rightsquigarrow P(x) = \sum_{y'} ...$\\
%	2. $P(y\vert x) = ...$\\
%	3. Predict using Bayesian decision theory\\
%	4. Minimize misclassification error:\\
%	\phantom{4.} $\hat y = \arg\!\max\limits_y P(y)P(x\vert y)$ $\to ... \prod_{i=1}^d P(x_i,y)$\vspace{-3pt}
%\end{highlightbox}

\textbf{Binary:}
\highlight*{$y=\operatorname{sign}(f(x))$},
$f(x) = \log \frac{P(Y=+\!1\vert x)}{P(Y=-\!1\vert x)}$\\
{\small
$y\ped{pred} = [P(X, 1) \geq P(X, 0)] = [p_1P(X\vert) 1 \geq p_0P(X\vert 0)]$
}

%\subsection*{Example: Naive Bayes Model}
%cond. ind.:$P(X_1,...,X_d|Y) = \prod_{i=1}^d P(X_i|Y)$

% ===
\emph{Examples}

\textbf{MLE for Class.}: $P(y) = \highlight{p_y} = \frac{\operatorname{Count}(Y=y)}{n} = \frac{\highlight{\scriptstyle n_y}}{n}$

\textbf{MLE for $\mathbf{P(x\vert y)}$:}
$P(x_i\vert y) = \mathcal{N}(x_i;\mu_{y,i}, \sigma_{y,i}^2)$\\
{\small
$\highlight{\hat{\mu}_{y,i}} = \frac{1}{n_y} \sum_{j:y_j=y} x_{j,i}$\hfill
$\highlight{\hat{\sigma}_{y,i}^2} = \frac{1}{n_y} \sum_{j:y_j=y} (x_{j,i} - \hat{\mu}_{y,i})^2$
}\\
$x_{j,i}$: value of feature $i$ for instance $j$ ($x_j,y_j$)

\textbf{MLE for Poi.:} $\lambda = \operatorname{avg}(x_i) $\\
$\mathbb{R}^d$: $P(X \!\!=\! x\vert Y \!\!=\! y) = \prod_{i=1}^d Pois(\lambda_y^{(i)},x^{(i)})$

% ===
\emph{Gaussian Bayes Classifier}

$\hat{P}(x|y) = \mathcal{N}(x ; \hat{\mu}_y, \hat{\Sigma}_y)$

\textbf{MLE:}
$\hat{\mu}_{y} = \frac{1}{n_y} \sum_{j:y_j=y} x_j \color{gray}\in \mathbb{R}^d$\\
\phantom{\textbf{MLE:}}
$\hat{\Sigma}_{y} = \frac{1}{n_y} \sum_{j:y_j=y} (x_j - \hat{\mu}_{y})(x_j-\hat{\mu}_y)^T \color{gray}\in \mathbb{R}^{d \times d}$

\textbf{$\normalcolor\mathbf{c\!=\!2}$:}
{\small
$f(x) = \log\frac{p}{1-p}
+ \frac{1}{2} \Big[ \log\frac{\abs{\hat\Sigma_-}}{\abs{\hat\Sigma_+}} + \ldots$
}\\
\phantom{\textbf{$\normalcolor\mathbf{c\!=\!2}$:}}
{\small
$ \big( (x\!-\!\hat\mu_-)^\top \hat\Sigma_-^{-1} (x\!-\!\hat\mu_-) \big)
- \big( (x\!-\!\hat\mu_+)^\top \hat\Sigma_+^{-1} (x\!-\!\hat\mu_+) \big) \Big]$
}

\textbf{$\normalcolor\mathbf{c\!=\!2}$ -- Fisher's LDA:}\\
\phantom{\textbf{$\mathbf{c\!=\!2}$:}}
Assume:\enskip $p = 0.5$;\enskip $\hat{\Sigma}_- \!= \hat{\Sigma}_+ \equiv \hat{\Sigma}$\\
\phantom{\textbf{$\mathbf{c\!=\!2}$:}}
$\implies f(x) = w^\top x + w_0$\\
\phantom{\textbf{$\mathbf{c\!=\!2}$:}} where
$w = \hat{\Sigma}^{-1}(\hat{\mu}_+ - \hat{\mu}_-)$ and\\
\phantom{\textbf{$\mathbf{c\!=\!2}$:} where}
$w_0 = \frac{1}{2}(\hat{\mu}_-^\top\hat{\Sigma}^{-1}\hat{\mu}_- - \hat{\mu}_+^\top \hat{\Sigma}^{-1}\hat{\mu}_+)$

\columnbreak

% ===
\emph{Outlier Detection}

$P(x) \leq \tau$

% ===
\emph{Categorical (Naive) Bayes Classifier}

MLE for feature distr.:
$\hat{P}(X_i \!=\! c\vert Y \!=\! y) = \theta_{c\vert y}^{(i)}$\\
$\theta_{c\vert y}^{(i)} = \frac{\operatorname{Count}(X_i = c, Y = y)}{\operatorname{Count}(Y=y)}$, \enskip $\hat p_y = \frac{\operatorname{Count}(Y=y)}{n}$


\subsection{Markov chain recap}

In a Markov chain we move from state to state randomly, following a transtion matrix.

We have:

\begin{itemize}
\item \(S\) - the state space
\item \(s_1\) - the initial state
\item \(P\) - the transition model
\end{itemize}


\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage{hyperref}
\usepackage{cleveref}
\author{Daniel Celis Garza}
\title{Interpolation Notes}
\date{\today}
\begin{document}
\maketitle
\section{Neville's Algorithm}
For $n = 4$
\begin{align*}
x_{1}:\qquad& y_{1} =& P_{1,1} 	&					\hspace{-2cm}&				   \\
			&		 & 	& P_{1,2}			\hspace{-2cm}&				   \\
x_{2}:\qquad& y_{2} =& P_{2,2} 	&\qquad P_{1,2,3}	\hspace{-2cm}&				   \\
			&		 &		 	& P_{2,3}			\hspace{-2cm}& P_{1,2,3,4}	   \\
x_{3}:\qquad& y_{3}	=& P_{3,3}	&\qquad P_{2,3,4}	\hspace{-2cm}&				   \\
			&		 & 	& P_{3,4}			\hspace{-2cm}&				   \\
x_{1}:\qquad& y_{4} =& P_{4,4} 	&					\hspace{-2cm}&				   \\
\end{align*}

\begin{subequations}\label{e:nev}
\begin{align}
& P_{i,i} = y_{i}~, && 0\le i \le n \\
& P_{i,j} =
\dfrac{
(x_j-x)P_{i,j-1} + (x-x_i)P_{i+1,j}
}
{
x_{j}-x_{i}
}~, && 0\le i < j \le n
\end{align}
\end{subequations}

The original formula is:

\begin{align}\label{e:lag}
^{n}P(x) = \sum\limits_{i=0}^{n}\left(
\prod\limits_{\substack{0 \le j \le n \\ j \ne i}}
\dfrac{x-x_{j}}{x_{i}-x_{j}}
\right)y_{i}
\end{align}

For $n = 2$ \cref{e:nev} is
\begin{align*}
P_{1,2} &= \dfrac{(x_{2} - x)P_{1,1} + (x-x_{1})P_{2,2}}{x_{2}-x_{1}}\\
P_{1,2} &= \dfrac{(x_{2} - x)y_{1} + (x-x_{1})y_{2}}{x_{2}-x_{1}}	 \\
\end{align*}
and \cref{e:lag} is
\begin{align*}
^{n}P &= \dfrac{x-x_{2}}{x_{1}-x_{2}}y_{1} + \dfrac{x-x_{1}}{x_{2}-x_{1}}y_{2} \\
^{n}P &= \dfrac{-(x_{2}-x)}{-(x_{2}-x_{1})}y_{1} + \dfrac{x-x_{1}}{x_{2}-x_{1}}y_{2} \\
\end{align*}
\end{document}


%!TEX root =  ../main.tex

\subsection{3D Geometry}
For nearly 3,000 years, mathematicians have been interested in shapes called
conic sections.  Why?  What are they?  Surprisingly, they are the means to answer some
very basic problems, like doubling the size of a cube, or why it is almost impossible to make
a square with the same area as a circle.  While the Ancient Greek geometers were interested
in such problems, it is far easier to consider them in light of analytic geometry, where we
lay down the Cartesian plane, and place shapes in it, analyzing the algebra of their equations.

\marginfig[-0.5in]{\chapdir/pics/ConicSections_ajl.png}{The conic sections.}
The problems you worked in the lab were examples of three out of the four conic sections.
Why are they called such?  It is easy to model a cone intersecting a plane.  If we
imagine the cone as an idealized version of itself, it extends both up and down, forever
in two directions.  The plane of intersection is also the infinite plane of geometry, a flat
sheet that extends forever.

If the line through the middle of the cone intersects the plane at $90^\circ$ precisely
(what mathematicians call \textbf{normal} to the plane), then the shape on the plane will
be incredibly symmetrical, a \textbf{circle}.  Any slight variance in that angle will produce a
distorted circle, what is ordinarily called an `oval', but in mathematical parlance, an
\textbf{ellipse}. If we continue to tilt the plane, the ellipse will widen and widen.  As we
achieve an angle parallel to the side of the cone, the shape is our old friend, the
\textbf{parabola}.  Any angle past that will result in intersecting both parts of the cone,
a shape known as a \textbf{hyperbola}.

\subsection{Graphing form}
\subsubsection{Circles}
Drawing circles is very easy and so is the algebra equation underlying them.  With a center
at $(h,k)$ and radius $r$, they can be quickly graphed, even by hand.

\marginfig[-0.5in]{\chapdir/pics/Conic_sections.png}{The angle of intersection of the plane
and the cone may be plainly seen in the projection.}
\begin{derivation}{Equation of a Circle}
\label{eq:circle}
\begin{equation}
(x-h)^2+(y-k)^2=r^2
\end{equation}
\end{derivation}

\subsubsection{Ellipses}
We could imagine an straight-forward algebra manipulation which mirrors the geometric
manipulation from circles to ellipses: begin with Eq.~\ref{eq:circle}.  Now divide both sides
by $r^2$:
$$
\frac{(x-h)^2}{r^2} + \frac{(y-h)^2}{r^2} = 1
$$
If we consider that the two radii represented in the denominators might be different
(perhaps we might relabel them as $r_1^2$
and $r_2^2$), then we are very close to the graphing form of the equations for ellipses, and
we have a visual parallel: an ellipse is a circle with different radii for the $x$ and $y$!

\begin{derivation}{Equations of Ellipses}
\begin{equation}
\label{eq:ellipses}
\left(\frac{x-h}{a}\right)^2 + \left(\frac{y-k}{b}\right)^2 = 1 \quad \text{or} \quad \left(\frac{x-h}{b}\right)^2 + \left(\frac{y-k}{a}\right)^2 = 1
\end{equation}
\end{derivation}
By convention, we call whichever radii is bigger $a$, hence the two different forms.  (It will become
clearer in §DD.04 why.)

\subsubsection{Parabola}
You have done a lot of work with parabolas over the years, and the vertex form of Algebra II
requires very little manipulation to adapt to our purposes here (i.e. $y=a(x-h)^2+k$).  The only
caveats are that we like to keep the unit $(y-k)$ together, and that $a$ is four times the focal
length, conventionally called $p$.  Also, there are parabolas that open up-down, as well
as those that open left-right, as we saw in §3.3

\begin{derivation}{Equations of Parabolas}
\begin{equation}
(y-k) = 4p(x-h)^2 \quad  \text{or} \quad (x-h) = 4p (y-k)^2
\end{equation}
\end{derivation}

\subsection{Hyperbolas}
\marginfig[-1in]{\chapdir/pics/Drini-conjugatehyperbolas.png}{Hyperbolas can be horizontally or vertically oriented.}
Hyperbolas are very likely the least familiar to you of any of these objects.  Of course,
$y=\frac{1}{x}$ is a hyperbola, but that can be hard to see, unless you turn your head
$45^\circ$ to the left!  If you look at the hyperbola $x^2-y^2=1$, some of the standard
features are apparent.  There are two asymptotes, in this case, at $y=\pm x$.  They
go through the center of the graph (the origin), which is not part of the graph.  These
same two asymptotes would be the same ones for the graph of $y^2-x^2=1$, only
one opens left-right, while the other one is oriented up-down.

\begin{derivation}{Equations of Hyperbolas}
\begin{equation}
\left(\frac{x-h}{a}\right)^2 - \left(\frac{y-k}{b}\right)^2 = 1
\quad \text{or} \quad
\left(\frac{y-k}{a}\right)^2 - \left(\frac{x-h}{b}\right)^2 = 1
\end{equation}
\end{derivation}

Practically speaking, graphing from the equation is a multi-step process
\begin{enumerate}
\item Begin at the center $(h,k)$.
\item Whichever variable is underneath $x$ (either $a$ or $b$), proceed that distance right and left from the center.
\item Whichever variable is underneath $y$ (either $b$ or $a$), proceed that distance up and down from the center.
\item The preceeding dimensions are needed to draw the asymptotes, which either have slopes of $\pm\frac{b}{a}$ or $\pm\frac{a}{b}$.
\end{enumerate}

\marginfig[0in]{\chapdir/pics/Giperbola-koord.png}{A horizontal hyperbola centered at the origin.}


\documentclass[12pt]{cdblatex}
\usepackage{examples}

\lstset{numbers=left}

\begin{document}

\section*{The metric connection in Riemann normal coordinates}

In local Riemann normal coordinates, the metric components can always be expanded as a power series in the Riemann curvatures and its derivatives (provided the curvatives are finite at the expansion point). In particular
\begin{align*}
   g_{ab}(x) &= g_{a b} - \frac{1}{3} x^{c} x^{d} R_{a c b d}
                        - \frac{1}{6} x^{c} x^{d} x^{e} \nabla_{c}{R_{a d b e}} + \cdots\\
   g^{ab}(x) &= g^{a b} + \frac{1}{3} x^{c} x^{d} g^{a e} g^{b f} R_{c e d f}
                        + \frac{1}{6} x^{c} x^{d} x^{e} g^{a f} g^{b g} \nabla_{c}{R_{d f e g}} + \cdots
\end{align*}
where $g_{ab}$ and $g^{ab}$ are independent of the coordinates $x^a$ and where $\nabla$ is the metric compatable derivative operator (i.e., $\nabla(g)=0$). In applications in General Relativity the $g_{ab}$ are often chosen to be $g_{ab} = {\rm diag}(-1,1,1,1)$.

Here we will use the standard metric compatible connection
\begin{align*}
   \Gamma^{d}_{ab}(x) = \frac{1}{2} g^{dc}\left( g_{cb,a} + g_{ac,b} - g_{ab,c} \right)
\end{align*}
to compute $\Gamma^{d}_{ab}(x)$ to terms linear in $R_{abcd}$ and $\nabla_{e} R_{abcd}$.

\vspace{12pt}

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).

   D{#}::PartialDerivative.
   \nabla{#}::Derivative.

   g_{a b}::Metric.
   g^{a b}::InverseMetric.

   \delta{#}::KroneckerDelta.

   R_{a b c d}::RiemannTensor.

   x^{a}::Depends(D{#}).
   x^{a}::Weight(label=num,value=1).

   R_{a b c d}::Depends(\nabla{#}).

   DxaDxb := D_{a}{x^{b}}->\delta^{b}_{a}.

   # can chose lower order approximations by truncating the following pair

   gab := g_{a b} - 1/3 x^{c} x^{d} R_{a c b d}
                  - 1/6 x^{c} x^{d} x^{e} \nabla_{c}{R_{a d b e}}.                    # cdb(gab.000,gab)

   iab := g^{a b} + 1/3 x^{c} x^{d} g^{a e} g^{b f} R_{c e d f}
                  + 1/6 x^{c} x^{d} x^{e} g^{a f} g^{b g} \nabla_{c}{R_{d f e g}}.    # cdb(iab.000,iab)

   gab := g_{a b} -> @(gab).
   iab := g^{a b} -> @(iab).

   gam := 1/2 g^{d c} (D_{a}{g_{c b}} + D_{b}{g_{a c}} - D_{c}{g_{a b}}).             # cdb(gam.001,gam)

   substitute   (gam,gab)
   substitute   (gam,iab)
   distribute   (gam)              # cdb(gam.002,gam)
   unwrap       (gam)              # cdb(gam.003,gam)
   product_rule (gam)              # cdb(gam.004,gam)
   distribute   (gam)              # cdb(gam.005,gam)
   substitute   (gam,DxaDxb)       # cdb(gam.006,gam)
   eliminate_kronecker (gam)       # cdb(gam.007,gam)
   sort_product   (gam)            # cdb(gam.008,gam)
   rename_dummies (gam)            # cdb(gam.009,gam)
   canonicalise   (gam)            # cdb(gam.010,gam)

   def truncate (obj,n):

       ans = Ex(0)  # create a Cadabra object with value zero

       for i in range (0,n+1):
          foo := @(obj).
          bah  = Ex("num = " + str(i))
          distribute  (foo)
          keep_weight (foo, bah)
          ans = ans + foo

       return ans

   gam = truncate (gam,2)   # cdb (gam.101,gam)  # allow up to 2nd order in x^a

   # ==========================================================================
   # the remaining code is just for pretty printing

   {x^{a},g^{a b},R_{a b c d},\nabla_{e}{R_{a b c d}}}::SortOrder.

   def get_term (obj,n):

       foo := @(obj).
       bah  = Ex("num = " + str(n))
       distribute  (foo)
       keep_weight (foo, bah)

       return foo

   def reformat (obj,scale):

      foo  = Ex(str(scale))
      bah := @(foo) @(obj).

      distribute     (bah)
      sort_product   (bah)
      rename_dummies (bah)
      canonicalise   (bah)
      factor_out     (bah,$x^{a?},g^{b? c?}$)
      ans := @(bah) / @(foo).

      return ans

   gam1 = get_term (gam,1)       # cdb (gam1.301,gam1)
   gam2 = get_term (gam,2)       # cdb (gam2.301,gam2)

   gam1 = reformat (gam1,  3)    # cdb (gam1.301,gam1)
   gam2 = reformat (gam2, 12)    # cdb (gam2.301,gam2)

   Gamma  := @(gam1) + @(gam2).  # cdb (Gamma.301,Gamma)
   Scaled := 12 @(Gamma).        # cdb (Scaled.301,Scaled)

\end{cadabra}

\subsection*{The metric connection in Riemann normal coordinates}

\begin{dgroup*}
   \begin{dmath*} \Gamma^{d}_{a b} = \cdb{Gamma.301} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} 12 \Gamma^{d}_{a b} = \cdb{Scaled.301} \end{dmath*}
\end{dgroup*}

\vspace{20pt}

\begin{latex}
   \begin{dgroup*}
      \begin{dmath*} \Gamma^{d}_{a b} = \cdb{Gamma.301} \end{dmath*}
   \end{dgroup*}

   \begin{dgroup*}
      \begin{dmath*} 12 \Gamma^{d}_{a b} = \cdb{Scaled.301} \end{dmath*}
   \end{dgroup*}
\end{latex}

% uncomment the following to get more detail of the computations

% \begin{dgroup*}
%    \begin{dmath*} \cdb{gam.002} \end{dmath*}
%    \begin{dmath*} \cdb{gam.003} \end{dmath*}
%    \begin{dmath*} \cdb{gam.004} \end{dmath*}
%    \begin{dmath*} \cdb{gam.005} \end{dmath*}
%    \begin{dmath*} \cdb{gam.006} \end{dmath*}
%    \begin{dmath*} \cdb{gam.007} \end{dmath*}
%    \begin{dmath*} \cdb{gam.008} \end{dmath*}
%    \begin{dmath*} \cdb{gam.009} \end{dmath*}
%    \begin{dmath*} \cdb{gam.010} \end{dmath*}
% \end{dgroup*}

\end{document}


\documentclass[11pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{bm}

\newcommand{\e}{\epsilon}
\newcommand{\dl}{\delta}
\newcommand{\1}{\bm{1}}
\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\uu}[1]{\underline{\underline{#1}}}
\newcommand{\un}[1]{\underline{#1}}

\title{Lecture 4: Introduction to Cartesian tensors}
\begin{document}
\maketitle

The key ideas are
\begin{itemize}
  \item Index notation for basic operations
  \item Coordinate transformations for vector and tensors
  \item Isotropic tensors
\end{itemize}

\section{Index notation}
$$\bm{a}\cdot\bm{b}=a_ib_i$$
$$\bm{a}\wedge\bm{b}=\e_{ijk} a_j b_k$$
$$\bm{a}\bm{b}=a_ib_j$$

Using these notations, we can briefly define some quantities of interest in transport phenomena.\\
\begin{itemize}
\item The gradient vector
$$\nabla T = \pd{T}{x_i}$$
which points in the direction of fastest rate of change of the scalar field $T$. Its inner product with a direction gives the rate of change of $T$ in that direction.

\item The divergence of velocity field
$$\nabla \cdot \bm{u} = \pd{u_i}{x_i}$$
which gives the normalized volumetric rate of change of a local volume element ($\frac{1}{V}\pd{V}{t}$). It is zero for an incompressible flow.

\item The curl of velocity field (vorticity)
$$\nabla \wedge \bm{u} = \e_{ijk}\pd{u_k}{x_j} $$
which is a measure of the local rotation rate of the fluid.

\item The velocity gradient tensor
$$\nabla \bm{u} = \pd{u_i}{x_j}$$
which has information about the volumetric change, rotation as well as the local shear rate of the flow. A second order tensor packs much more information than a vector.
\end{itemize}

As examples of their usage, we can write down few equations in index notation
\begin{itemize}
  \item Convection-diffusion equation
$$\pd{T}{t} + \bm{u}\cdot \nabla T = \kappa \nabla^2 T \hfill \text{\footnotesize{\quad \quad \quad     (Gibbs notation)}}$$
$$\pd{T}{t} + u_j\pd{T}{x_j} = \kappa \pd{^2T}{x_i \partial x_i} \hfill \text{\footnotesize{\quad \quad \quad     (Index notation)}}$$

  \item Navier-Stokes equation
$$\rho(\pd{\bm{u}}{t} + \bm{u}\cdot\nabla\bm{u}) = -\nabla P +\mu \nabla^2 \bm{u} \text{\footnotesize{\quad \quad \quad     (Gibbs notation)}}$$
$$\rho(\pd{u_i}{t} + u_j\cdot\pd{u_i}{x_j}) = -\pd{P}{x_i} +\mu \frac{\partial^2 u_i}{\partial x_j \partial x_j} \text{\footnotesize{\quad \quad \quad     (Index notation)}}$$

\end{itemize}

We will henceforth be denoting second order tensors with a double underbar as $\uu{A}$ and vectors with a single underbar as $\un{A}$. Some identities for products of tensors are given below
\begin{align*}
\uu{B}\cdot \un{a} &= B_{ij} a_j \\
\uu{B} \cdot \uu{C} &= B_{ik}C_{kj} \\
\uu{B} \colon \uu{C} &= B_{ij}C_{ji} \\
\end{align*}

The last of these is used in calculation of viscous dissipation which is given by $2\mu\uu{E}\colon\uu{E}$, where $\uu{E}$ is a second order tensor given by
\begin{align*}
E_{ij} &= \frac{1}{2}(\nabla \un{u} + \nabla \un{u}^T)\\
&=\frac{1}{2}(\pd{u_i}{x_j} + \pd{u_j}{x_i})
\end{align*}

where the form highlights the symmetry of the strain-rate tensor. Two more important relations are
\begin{itemize}
  \item Scalar triple product
$$\un{a}\cdot(\un{b}\wedge\un{c}) = \e_{ijk}a_ib_jc_k$$
which is the determinant of the matrix with $\un{a},\un{b}$ and $\un{c}$ as its columns.

  \item Trace of $\uu{B} = B_{ii}$
\end{itemize}

\section{Coordinate Transformation}

\subsection{Vectors}

We want to find out how does the representation of a vector changes when the coordinate system is transformed into another coordinate system. We will mainly be concered with Orthogonal transformations. Mathematically, this means that, the transformation matrix $L$ is such that
$$L L^T = I \Rightarrow L = L^{-1}$$
Physically, these transformations preserve angles between any two lines. Specifically, if two vectors were orthogonal before the transformation, then their transformed counterparts will also be orthogonal. Orthogonal transformations comprise of rotations and reflections of the coordinate system. The group of all possible rotations of a $n$ dimenisonal coordinate system is known as the $SO_n$ group (Special Orthogonal group in n dimenisons).

Note that, in 3D, if the transformation is a rotation, then the matrix representing such a transformation has one and only one real eigenvalue, which is equal to 1. This is because the rotation matrix modifies every vector in the domain except the vector along its axis which is left unrotated (hence it's an eigenvector) and unstretched (hence the eigenvalue corresponding to it is 1). Other eigenvalues are imaginary. These transformations preserve the length of the vectors and the angle between any two vectors. In 2D, all vectors are transformed and hence both the eigenvalues are imaginary.

Let $L$ be such a tranformation in 3D that acts on the \textit{orthonormal unit vectors} $[\un{1}_1,\un{1}_2,\un{1}_3]$ and yields the transformed \textit{orthonormal unit vectors} $[\un{1'}_1,\un{1'}_2,\un{1'}_3]$. Then, we can write
$$\un{1}'_i  = l_{ij}\un{1}_j$$
The second order tensor $l_{ij}$ has nine elements, but they are not all indepenedent. The constraint of orthonormality of the transformed vectors gives six relations between the elements of $l_{ij}$
\begin{align*}
\un{1}'_i \cdot \un{1}'_j &= 0 \text{\quad \footnotesize{if $i\neq j$ (ensures orthogonality)}}\\
&= 1 \text{\quad \footnotesize{if $i = j$ (ensures normality)}}
\end{align*}

and hence a second order tensor in 3D, that represents an orthogonal transformation has only 3 independent parameters. For rotations, two of these are required to fix the axis and one more to specify the angle of rotation. For reflections, all three are needed to specify the plane of reflection.

For 2D, we get 3 constraints and hence the angle of rotation is the only parameter. What about 4 and higher dimensions? In a D dimensional space, we will have D constraints due to orthogonality and ${D\choose 2}$ due to normality. This results in $D(D-1)/2$ independent parameters.

Once the transformation rule for the unit vectors is clear, the transformation for any given vector $\un{a} = a_i\un{1}_i$ can be written as

$$\un{a}'_i= l_{ij}\un{a}_j$$
$$\un{a}_j = l_{ji}\un{a}'_i$$

\subsection{Second order tensors}

Let there be a second order tensor $\uu{B}$ with eigenvectors $[\un{X}_1,\un{X}_2,\un{X}_3]$. We assume a symmetric second order tensor which allows us to use the fact that three orthogonal eigenvectors will exist. Then, such a tensor can be written as
$$\uu{B}=[\lambda_1\un{X}_1\un{X}_1+\lambda_2\un{X}_2\un{X}_2+\lambda_3\un{X}_3\un{X}_3]$$

Let the transformed version of $\un{B}$ be $\un{B}'$ with eigenvectors $[\un{X}'_1,\un{X}'_2,\un{X}'_3]$. Then,
$$\uu{B}'=[\lambda_1\un{X}'_1\un{X}'_1+\lambda_2\un{X}'_2\un{X}'_2+\lambda_3\un{X}'_3\un{X}'_3]$$

Now we can use the trasformation rule for vectors $\un{a}'_i= l_{ij}\un{a}_j$ and transform the eigenvectors. This allows us to write down the final transformation rule in Gibbs notation as
$$\uu{B}'=\uu{L}\cdot\uu{B}\cdot\uu{L^T}$$
Or in index notation
\begin{align*}
B'_{ij} &= l_{ik}B_{km}l^T_{mj}\\
\Rightarrow B'_{ij} &= l_{ik}B_{km}l_{jm}\\
\Rightarrow B'_{ij} &= l_{ik}l_{jm}B_{km}
\end{align*}

The final expression is highly sugggestive of a pattern which will allow us to generalize this expression to higher order tensors

$$B'_{i_1i_2i_3...i_n} = l_{i_1j_1}l_{i_2j_2}l_{i_3j_3}...l_{i_nj_n}B_{j_1j_2j_3...j_n} \text{ \quad \quad \footnotesize{For the case of true tensors}}$$

$$B'_{i_1i_2i_3...i_n} = Det(\uu{L})l_{i_1j_1}l_{i_2j_2}l_{i_3j_3}...l_{i_nj_n}B_{j_1j_2j_3...j_n} \text{ \quad \quad \footnotesize{For pseudo tensors}}$$

Pseudo-tensors and pseudo-vectors are tensors which require a convention for their definition (such as the right hand screw rule). Their sign can change based on the convention. They do not directly represent physical quantities. E.g. vorticity, angular velocity and magnetic field. Another way to distinguish pseudo tensors is that they do not change direction upon reflection of the physical apparatus. A ball travelling to the right will be travelling to the left in the mirror; but a disc rotating clockwise is still rotating clockwise in the mirror. Its angular velocity vector doesn't flip sign.

\subsection{Quotient Rule}
A transformation or a physical law relating a vector to another vector must be mediated via a second order tensor; a law relating two second order tensors be mediated via a fourth order tensor and so on.

A law relating a vector to a second order tensor must be mediated by a third order tensor, so that two of the indices of the second and third order tensors can contract and result in a vector.

\section{Isotropic Tensors}
\begin{itemize}
  \item Zeroth order\\
  All scalars are isotropic except psedo-scalars. Pseudo-scalars form upon contraction of a true vector with a pseudo-vector and their sign changes with convention.

  \item First order (Vectors)\\
  The Null vector is the only isotropic vector. We are looking for a vector that is impervious to any orthogonal transformation. Since every vector suffers a change of direction under some or the other rotation, the only vector that remains unaffected under all rotations is the vector without a direction.

  \item Second order tensors\\
  $\dl_{ij}$ and its scalar multiples are the only second order isotropic vector. Since any vector is an eigenvector of the identity matrix, it implies that there is no special direction for such a matrix. Hence any direction changing transformation such as a rotation will leave it unchanged.

  \item Third order tensors\\
  There is no true third order isotropic tensor. $\e_{ijk}$ and its scalar multiples give a pseudo third order isotropic tensor.

  \item Third order tensors\\
  All higher order isotropic tensors are constructed using $\e_{ijk}$ and $\dl_{ij}$. E.g.
$$D_{ijkl} = c_1\dl_{ij}\dl_{kl} + c_2\dl_{ik}\dl_{jl} + c_3\dl_{il}\dl_{jk} $$
\end{itemize}

Some examples of the use of isotropy in tensors are given below

\begin{itemize}
  \item Fourier's law \\
  Fourier's law relates heat flux vector $\un{q}$ to the temperature gradient vector $\nabla T$
$$
q_i = K_{ij} \pd{T}{x_j}
$$

Here the thermal conductivity tensor $K_{ij}$ is a second order tensor with 3 independent elements. However, for an isotropic material, the tensor will also be isotropic because it should not prefer any one direction over the other. Therefore, we can write $K_{ij} = \kappa \dl_{ij}$ and there remains only one independent parameter to be determined experimentally.

  \item Newton's law of viscosity \\
  This is a relation between the stress tensor $\tau_{ij}$ and the strain-rate tensor $\nabla \un{u}$. Both of these are second order and hence the relation must be mediated by a fourth order tensor representing viscosity in some sense.
$$
\tau_{ij} = D_{ijkl} \pd{u_l}{x_k}
$$

If viscosity doesn't change with direction in a medium, then $\uu{D}$ must be an isotropic tensor. Hence we can write
$$D_{ijkl} = c_1\dl_{ij}\dl_{kl} + c_2\dl_{ik}\dl_{jl} + c_3\dl_{il}\dl_{jk} $$

But $\tau_{ij}$ is a symmetric tensor. Therefore, terms formed by interchange of $i$ and $j$ must be equal and hence $c_2$ must be equal to $c_3$. This gives us
\begin{align*}
D_{ijkl} &= \bigg(c_1\dl_{ij}\dl_{kl} + c_2(\dl_{ik}\dl_{jl} + \dl_{il}\dl_{jk})\bigg)\pd{u_l}{x_k}\\
D_{ijkl} &= c_1\pd{u_l}{x_l}\dl_{ij} + c_2(\pd{u_i}{x_j}+\pd{u_j}{x_i})
\end{align*}

Here, $c_1$ is associated with the divergence and hence informs us of the resistance of the fluid to change in its volume. This is the bulk viscosity of the fluid.

$c_2$ is associated with the strain-rate and tells about the resistance of the fluid to a shearing deformation (and also volumetric deformation). This leads to shear viscosity.

\end{itemize}

\section*{Appendix}
\subsection{Expanded form for some index notation results}
\begin{align*}
\bm{a} \cdot \bm{b} &= (a_1\1_1+a_2\1_2+a_3\1_3)\cdot(b_1\1_1+b_2\1_2+b_3\1_3)\\
&= \sum_{i=1}^{3} a_i \1_i \cdot \sum_{j=1}^{3} b_j \1_j\\
&= \sum_{i=1}^{3} \sum_{j=1}^{3} a_i b_j \1_i \cdot \1_j\\
&= \sum_{i=1}^{3} a_i b_i\\
&= a_i b_i
\end{align*}

In the last step, we have used Einstein's summation convention which mandates that repeated indices are to be summed over. Henceforth, repeated indices will imply a summation over that index.

\begin{align*}
\bm{a} \wedge \bm{b} &= (a_1\1_1+a_2\1_2+a_3\1_3)\wedge(b_1\1_1+b_2\1_2+b_3\1_3)\\
&=\sum_{i=1}^{3} a_i \1_i \wedge \sum_{j=1}^{3} b_j \1_j\\
&=\sum_{i=1}^{3}  \sum_{j=1}^{3} a_i b_j \1_i \wedge  \1_j\\
&=\sum_{i=1}^{3}  \sum_{j=1}^{3} a_i b_j \e_{ijk}\1_k\\
&=\e_{ijk}a_ib_j\\
&=\e_{ijk}a_jb_k
\end{align*}

Where we have just relabelled the indices in the last step so that the first index $i$ remains the direction specifying index.

\subsection{Area under a Gaussian}
The area under a suitably defined Gaussian is independent of its standard deviation.

\subsection{Gradient vector in cylindrical and spherical coordinates}
In any coordinate system, the gradient vector can be written immidiately if we incorporate the metric factors relevant to the coordinate system. Including the metric factor converts a small change in a coordinate variable to a small change in length along that coordinate (E.g.$d\theta$ to $rd\theta$ ).

\subsection{Proof for vector transformations}
$$\un{a}'_i= l_{ij}\un{a}_j$$
$$\un{a}_j = l_{ji}\un{a}'_i$$

\subsection{Symmetric matrices have orthogonal eigenvectors}

\subsection{Proof for the quotient rule}

\subsection{Proof that $\dl_{ij}$ and $\e_{ijk}$ are isotropic}

\end{document}


\subsection{K-nearest neighbours}

K-nearest neighbours is a non-parametric classifer. For a point with an unknown class we identify the classes of the \(K\)-nearest neighbours and assign the most common class.

For this we need to find the distance between observations. We can do this using norms.

Weightings of the dependent variables is important here.

\subsubsection{Practicality}

Requires space to store

N samples, d features

times: O(n.d)


\section{Methodology}\label{sec:method}

\subsection{Original Form of the SDP}
Consider a Boolean function $f$ such that
$f: D \rightarrow E$ where
$D \subseteq {\{0,1\}}^n$ and $E \subseteq {\{0,1\}}$.
We state Reichardt's formulation of the SDP \cite{reichardt2009span}.
(Note that $[n]$ denotes the array
$[1,2,...,n]$.)
The quantum query complexity of $f$ is
\begin{align} \label{Eq:reichardt_obj}
    \min_{\X} \max_{y \in D} \sum_{j \in [n]} \bra{y,j}\X\ket{y,j}
\end{align}
for some $\X$ subject to the constraints that $\X$ is positive semidefinite
(all its eigenvalues are non-negative)
and for ordered pairs ($y$,$z$) such that $f(y) \neq f(z)$,
\begin{align}\label{Eq:reichardt_F0}
    \sum_{j \in [n]: y_j \ne z_j}
    \bra{y,j} \X \ket{z, j} = 1.
\end{align}

\subsection{Standard Form of the SDP}
In order to implement an algorithm that solves
Reichardt's formulation, we convert the SDP
into the canonical standard form
\cite{boyd2004convex}.
Then the standard form objective function of the SDP is
\begin{align}\label{Eq:boyd_obj}
    \tr(C\Xb)
\end{align}
for some fixed matrix $C$ subject to the constraints
that $\Xb$ is semidefinite and for $i \in [p]$
\begin{align} \label{Eq:boyd_trace}
    \tr(A_i \Xb) = b_i
\end{align}
for some fixed matrices $A_i$ and $b_i$.

\subsection{Converting from Original to Standard Form}
We now convert the original form of the SDP to
the standard form by constructing appropriate matrices $A_i$, $b_i$, $\Xb$, and $C$.

To understand this conversion, we must first gain some intuition about $\X$.
It is clear from \cref{Eq:reichardt_obj} that for
each $y \in D$, there exists a corresponding $n \times n$ sub-matrix of $\X$ along its diagonal.
Then $\X$ must have a total of $n|D|$ rows and $n|D|$ columns.
In general, $|D| = 2^n$ but it is possible to take
worst-case subsets of $D$ and still find the correct solution, as discussed later.

To convert \cref{Eq:reichardt_F0} into \cref{Eq:boyd_trace},
we must construct $A_i$, $b_i$ for $i \in [p]$.
Let $p = |F|$, then each pair $(y,z) \in F$
is associated with a single $A_i$.
For each $(y,z)$, we are interested in the entries
in $\X$ that correspond to the bits $y_i$ and $z_i$
where $y_i \neq z_i$ for $i \in [n]$. These entries are intuitively of interest because they are the bits that must lead to different outputs.
They are necessarily off of the main diagonal,
because $y\neq z$,
so our $A_i$ will map them to the main diagonal
and ensure that the trace of $A_i \X$ is 1.
Note that $b_i = 1$.

To place particular entries of $\X$ onto the main diagonal,
let $A_i$ be the transpose of the zero matrix with
ones in the particular entries of interest.
We illustrate on a small example.
Let
\begin{align}
    \X = \left[ \begin{matrix} 1 & 2 \\ 3 & 4 \end{matrix} \right] \nonumber
\end{align}
and the particular entry of interest be the top right value of $\X$.
Then
\begin{align}
    A_i = \left[ \begin{matrix} 0 & 1 \\ 0 & 0 \end{matrix} \right]^\textrm{T} \nonumber
    = \left[ \begin{matrix} 0 & 0 \\ 1 & 0 \end{matrix} \right] \nonumber
\end{align}
so that
\begin{align}
    A_i \cdot \X = \left[ \begin{matrix} 2 & 0 \\ 4 & 0 \end{matrix} \right] \nonumber
\end{align}
and $\tr(A_i \cdot \X) = 2$ as desired.

Having converted the constraints, we must also convert the objective functions. Let $c_i$ be the sum of the $n$ entries
in the $i^\mathrm{th}$ section of the main diagonal of $\X$
such that
\begin{align}
    c_i = \sum_{j \in [n]} \bra{y,j}\X\ket{y,j}
    \nonumber
\end{align}
where $y$ is the $i^{th}$ element of $D$ for
$i \in [|D|]$.
Let $z$ be $\tr(C\X)$.
The last challenge is to satisfy \cref{Eq:boyd_obj}
by enforcing that $z$ is the maximum $c_i$.
Our solution is to introduce non-negative slack variables
$s_i$ for $i \in [|D|]$ and the constraints
$c_i + s_i = z$.

We construct a new matrix $\Xb$ to account for these slack variables. Call $S$ the zero matrix
whose diagonal holds the entries $s_1,...,s_{|D|}, z$.
Then
\begin{align}
    \Xb = \left[ \begin{matrix} \X & 0 \\ 0 & S \end{matrix} \right] \nonumber.
\end{align}
Since $\Xb$ is semidefinite, the main diagonal entries of
$\Xb$ must be non-negative so $s_i \geq 0$. Thus $C$ is defined to have $\tr{C\Xb}$ extract the bottom right entry of $\Xb$. Therefore, let $C$ be the zero matrix with a single one in the bottom right entry.

To enforce that $z$ is the maximum $c_i$ over all $i$,
we construct $\Ap_i$ and set $\bp_i$ to 0
for $i \in [|D|]$. For the purposes of the standard form,
we now have two sets of $A_i$ and $b_i$ constraints.
Let $\Ap_i$ be the zero matrix with ones
along the entries corresponding to the input $i$ of $D$,
a one in the entry corresponding to $s_i$,
and a negative one in the bottom right entry corresponding
to the objective function $z$.
Then
\begin{align}
    \tr (\Ap_i \Xb ) &= c_i + s_i -z = 0 \nonumber.
\end{align}
Because $s_i$ is non-negative and $z$ is being minimized,
$z$ is both greater than or equal to all $c_i$ and meets
some $c_i$. Thus $z$ is the maximum $c_i$ as desired.

The solution $\Xb$ that satisfies the standard form according
to the constructed $A_i$, $\Ap_i$, $b_i$, $\bp_i$, and $C$ will
also hold the solution $\X$ to the original form.
Therefore, to find the optimal quantum query complexity of $f$,
we need only solve \cref{Eq:boyd_obj} subject to our constraints.

\subsection{Query Efficient Span Programs}

A span program is a model of computation that outputs a
Boolean value corresponding to whether or not a set
of vectors "spans" to a target vector. The algorithm consists
of a set of
vectors such that on a given input, the vectors are
partitioned into available and unavailable sets. The
available vectors are turned into the columns of a
matrix $A$.
These vectors form a linear system $Ax = \tau$
for a fixed target vector $\tau$.
If this system is homogeneous-- there exists
some non-trivial vector $x$ that satisfies the equation--
then the algorithm returns true.
Otherwise, the algorithm returns false.

Both Childs and Reichardt mathematically formulate
algorithms for turning the results of the SDP we solved
into a span program \cite{reichardt2009span, childs}.
To begin, we must construct a set of vectors
$\bra{v_{y,i}}$ for all $y \in D$ where $i = [n]$.
Given any two input strings $y, z \in D$ such that $y\neq z$,
\begin{align}
    \sum_{i: y_i \ne z_i} \braket{v_{y,i}|v_{z,i}} = 1 - \delta_{f(y), f(z)} \nonumber
\end{align}
where $\delta_{f(y), f(z)} = 1$ if $f(y) = f(z)$ and $0$ otherwise.

Recall from \cref{Eq:reichardt_F0} that $\X$ satisfies
\begin{align}
    \forall (y,z) \in F \sum_{j \in [n]: y_j \ne z_j}
    \bra{y,j} \X \ket{z, j} = 1 \nonumber.
\end{align}
We would like to construct $\bra{v_{y,i}}$ and $\ket{v_{z,i}}$
from $\X$.
So we define a matrix $L$ such that $L^\dagger L = \X$.
Then $\bra{v_{y,i}} = \bra{y_i}L^\dagger$.
We can now reformulate the requirement of vectors $\bra{v_{y,i}}$
as
\begin{align}
    \sum_{i: y_i \ne z_i} \braket{v_{y,i}|v_{z,i}} &= \sum_{i: y_i \ne z_i}
    \bra{y,i} L^\dagger L \ket{z, i} \nonumber \\
    &= \sum_{i: y_i \ne z_i} \bra{y,i} \X \ket{z, i} = \begin{cases}
        1 & f(y) \ne f(z) \\
        0 & f(y) = f(z)
    \end{cases} \nonumber
\end{align}
The constraints enforce the $f(y) \neq f(z)$ case and we programatically
check the $f(y) = f(z)$ case before returning $\X$.

Given the set of vectors $\bra{v_{y,i}}$ for all $y \in
D$, $i = 0, 1, \ldots , n-1$, we construct
matrix $I$ that contains the vectors for the span
program. We will make use of the sets $F_i =
\{y \in D: f(y) = i\}$.
(Note that $F_i[k]$ denotes the $k^{th}$ element of $F_i$.)

\begin{align}\label{input_vectors}
    I = \sum_{k \in [|F_0|], j \in [n], y = F_0[k]}
    \ket{k}\bra{j, \overline{y_j}} \bra{v_{y,j}}
\end{align}

This matrix $I$ is divided into sub-matrices that
correspond to different bits in the input to the
algorithm.
The columns of $I$ are evenly divided into
$n$ chunks corresponding to each input bit.
Each of these sub-matrices is further evenly divided into a left and
right sub-matrix, corresponding to a $0$ or $1$
in the relevant bit of the input.
Let $I(y)$ be the set of columns in
$I$ that are available on input $y \in D$.
The target vector $\tau$
is a vector of ones vector with the same
dimension as $I$.
The output is true if and only if the available
vectors $I(y)$ span to $\tau$.
Reichardt proves that the span program $I$
and $\tau$ is a query optimal
quantum algorithm for $f$ \cite{reichardt2009span}.


\subsection{Higher-Genus Surfaces}
We want to construct Riemann surfaces with genus $n>1$.
\begin{example}
    Consider the Fermat curve of degree $d$:
    $$F_d'=\{(x,y)\in\mathbb C^2:x^d+y^d=1\}$$
    the understanding of whose rational point, incidentally, is Fermat's Last Theorem.
    This is obviously not we are interested in here.
    As usual we want to make it a Riemann surface.
    The coordinate projection $\pi_x:(x,y)\mapsto x$ has local inverse $\pi_x^{-1}(x_0)=(x_0,\sqrt[d]{1-x_0^d})$ which exists and is continuous in a neighbourhood of any $x_0$ unless $x_0$ is a $d^{th}$ root of unity, i.e. $x=\zeta_d^i$ for some $i$ where $d=\exp(2\pi i/d)$, which happens iff $y_0=0$ (where $(x_0,y_0)\in F_d'$).
    Symmetrically, $\pi_y$ provides charts on $F_d'\setminus\{(0,\zeta_d^i)\}$.
    These charts cover everything as the points where $\pi_x$ and $\pi_y$ don't work are distinct.
    The non-trivial transition functions are $\pi_y\circ\pi_x^{-1}(x)=\sqrt[d]{1-x^d},\pi_x\circ\pi_y^{-1}(y)=\sqrt[d]{1-y^d}$ which are analytic where they need to be.
    It is quite obvious that $F_d'$ is Hausdorff since it inherits its topology from $\mathbb C^2$.
    To see it is connected, consider
    $$D=\mathbb C\setminus\left(\bigcup_{i=1}^d\{t\zeta_d^i:t\ge 1,i\in\{0,\ldots,d-1\}\}\right)$$
    Now there are well-defined branches of $y=\sqrt[d]{1-x^d}$ in $D$ which can be extend continuously to $\zeta_d^i$.
    Let $(x_0,y_0)\in F_d'$.
    Suppose $x_0\in D$, then we can choose a branch of $y(x)=\sqrt[d]{1-x^d}$ such that $y(x_0)=y_0$.
    Let $\gamma$ be any path in $D$ from $x_0$ to $1$, then $\tilde\gamma(t)=(\gamma(t),y(\gamma(t)))$ is a path joining $(x_0,y_0)$ to $(1,0)$.
    As for the $d$ rays in $F_d'\setminus D$, we can also find a branch locally near that and join it to something nearby that is in $D$ (possible as $D$ is dense in $\mathbb C$).
    Therefore $F_d'$ has to be path-connected.
    Consequently it is indeed a Riemann surface.\\
    We can compactify by gluing $F_d=F_d'\cup_\Phi F_d''$.
    The details can be found from example sheet, where we also extend the covering map to a meromorphic $\hat\pi_x:F_d\to\mathbb C_\infty$ with $\deg\hat\pi_d=d$.
    Also $|\hat\pi_x^{-1}(\infty)|=d$, so $\infty$ is not a ramification point.
    The ramification points are then $\{(\zeta_d^i,0),i\in\{0,\ldots,d-1\}\}$ and all of them have multiplicity $d$.
    Riemann-Hurwitz then gives
    $$2g_{F_d}-2=d(0-2)+d(d-1)\implies g_{F_d}=\frac{(d-1)(d-2)}{2}$$
\end{example}
The conclusion is then there does exist Riemann surfaces with arbitrarily large genus.


\subsection{Minkowski functionals}\label{subsec:minkowski_functionals}

\begin{definition}\label{def:minkowski_functional}
  Let \( A \) is an \hyperref[def:neighborhood_set_types/absorbing]{absorbing} \hyperref[def:linear_combination/convex]{convex} set.

  We define the corresponding \term{Minkowski functional}
  \begin{balign*}
     & \rho_A: X \to [0, \infty),
     & \rho_A(x) = \inf \{ t > 0 \colon x \in tA \}.
  \end{balign*}
\end{definition}
\begin{proof}
  We will prove that \( \rho_A(x) \) is always a nonnegative real number. Obviously
  \begin{equation*}
    \rho_A(x) \geq 0
  \end{equation*}
  since the infimum over \( \BbbR_{>0} \) is \( 0 \).

  Now fix \( x \in X \). Since \( A \) is an absorbing set, there exists \( t_0 > 0 \) such that \( t_0 x \in A \). We need to take the infimum of all such numbers. This infimum exists since \( \BbbR \) is complete and the set over which we take the minimum is bounded.
\end{proof}