\section{Numerical Tests}
\label{sec:numerical}

In this section we present numerical results obtained with the DG-IMEX scheme developed in this paper.
The first set of tests (Section~\ref{sec:smoothProblems}) are included to compare the time integration schemes in various regimes.
We are not concerned with moment realizability in Section~\ref{sec:smoothProblems}, and we do not apply the realizability-enforcing limiter in these tests.
The tests in Sections~\ref{sec:packedBeam} and \ref{sec:fermionImplosion} are designed specifically to demonstrate the robustness of the scheme to dynamics near the boundary of the realizable set $\cR$.
The test in Section~\ref{sec:homogeneousSphere} (Homogeneous Sphere) is of astrophysical interest.
Here we consider moment realizability and compare results obtained with various moment closures.

\subsection{Problems with Known Smooth Solutions}
\label{sec:smoothProblems}

To compare the accuracy of the IMEX schemes, we present results from smooth problems in streaming, absorption, and scattering dominated regimes in one spatial dimension.
For all tests in this subsection, we use third order accurate spatial discretization (polynomials of degree $k=2$) and we employ the maximum entropy closure in the low occupancy limit (i.e., the Minerbo closure).
We compare results obtained using IMEX schemes proposed here (PA2+ and PD-ARS) with IMEX schemes from Hu et al. \cite{hu_etal_2018} (PA2), McClarren et al. \cite{mcclarren_etal_2008} (PC2), Pareschi \& Russo \cite{pareschiRusso_2005} (SSP2332), and Cavaglieri \& Bewley \cite{cavaglieriBewley2015} (RKCB2).
In the streaming test, we also include results obtained with second-order and third-order accurate explicit strong stability-preserving Runge-Kutta methods \cite{gottlieb_etal_2001} (SSPRK2 and SSPRK3, respectively).
See \ref{app:butcherTables} for further details.
The time step is set to $\dt=0.1\times\dx$.

When comparing the numerical results to analytic solutions, errors are computed in the $L^{1}$-error norm.
We compare results either in the absolute error ($E_{\mbox{\tiny Abs}}^{1}$) or the relative error ($E_{\mbox{\tiny Rel}}^{1}$), defined for a scalar quantity $u_{h}$ (approximating $u$) as
\begin{equation}
  E_{\mbox{\tiny Abs}}^{1}[u_{h}](t)
  =\f{1}{|D|}\sum_{\bK\in\mathscr{T}}\int_{\bK}|u_{h}(\vect{x},t)-u(\vect{x},t)|\,d\vect{x}
  \label{eq:errorNormAbsolute}
\end{equation}
and
\begin{equation}
  E_{\mbox{\tiny Rel}}^{1}[u_{h}](t)
  =\f{1}{|D|}\sum_{\bK\in\mathscr{T}}\int_{\bK}|u_{h}(\vect{x},t)-u(\vect{x},t)|/|u(\vect{x},t)|\,d\vect{x},
  \label{eq:errorNormRelative}
\end{equation}
respectively.
The integrals in Eqs.~\eqref{eq:errorNormAbsolute} and \eqref{eq:errorNormRelative} are computed with a simple $3$-point equal weight quadrature.

\subsubsection{Sine Wave: Streaming}

The first test involves the streaming part only, and does not include any collisions ($\sigma_{\Ab}=\sigma_{\Scatt}=0$).
We consider a periodic domain $D=\{x:x\in[0,1]\}$, and let the initial condition be given by
\begin{equation}
  \cJ(x,t=0)=\cH_{x}(x,t=0)=0.5+0.49\times\sin\big(2\pi\,x\big).
  \label{eq:initialConditionStreaming}
\end{equation}
We evolve until $t=10$, when the sine wave has completed 10 crossings of the computational domain.
We vary the number of elements ($N$) from $8$ to $128$ and compute errors for various time stepping schemes.

In Figure~\ref{fig:SineWaveStreaming}, the absolute error for the number density $E_{\mbox{\tiny Abs}}^{1}[\cJ_{h}](t=10)$ is plotted versus $N$ (see figure caption for details).
Errors obtained with SSPRK3 are smallest and decrease as $N^{-3}$ (cf. bottom black dash-dot reference line), as expected for a scheme combining third-order accurate time stepping with third-order accurate spatial discretization.
For all the other schemes, using second-order accurate explicit time stepping, the error decreases as $N^{-2}$.
Among the second-order accurate methods, SSP2332 has the smallest error, followed by RKCB2.
Errors for the remaining schemes (including SSPRK2) are indistinguishable on the plot.
\begin{figure}[H]
  \centering
    \includegraphics[width=\textwidth]{figures/SineWaveStreaming}
   \caption{Absolute error (cf. Eq.~\eqref{eq:errorNormAbsolute}) versus number of elements $N$ for the streaming sine wave test.  Results employing various time stepping schemes are compared: SSPRK2 (cyan triangles pointing up), SSPRK3 (cyan triangles pointing down), PA2 (red), PA2+ (purple), PC2 (blue), RKCB2 (dark green), SSP2332 (green), and PD-ARS (light red circles).  Black dash-dot reference lines are proportional to $N^{-1}$ (top), $N^{-2}$ (middle), and $N^{-3}$ (bottom), respectively.}
  \label{fig:SineWaveStreaming}
\end{figure}

\subsubsection{Sine Wave: Damping}

The next test we consider, adapted from \cite{skinnerOstriker_2013}, consists of a sine wave propagating with unit speed in a purely absorbing medium ($f_{0}=0$, $\sigma_{\Scatt}=0$), which results in exponential damping of the wave amplitude.
We consider a periodic domain $D=\{x:x\in[0,1]\}$, and let the initial condition ($t=0$) be given as in Eq.~\eqref{eq:initialConditionStreaming}.
For a constant absorption opacity $\sigma_{\Ab}$, the analytical solution at $t>0$ is given by
\begin{equation}
  \cJ(x,t)=\cJ_{0}(x-t)\times\exp(-\sigma_{\Ab} t)
  \quad\text{and}\quad
  \cH_{x}(x,t)=\cJ(x,t),
\end{equation}
where $\cJ_{0}(x)=\cJ(x,0)$.

We compute numerical solutions for three values of the absorption opacity ($\sigma_{\Ab}=0.1$, $1$, and $10$), and adjust the end time $t_{\mbox{\tiny end}}$ so that $\sigma_{\Ab}t_{\mbox{\tiny end}}=10$, and the initial condition has been damped by factor $e^{-10}$.
Thus, for $\sigma_{\Ab}=0.1$ the sine wave crosses the domain 100 times, while for $\sigma_{\Ab}=10$, it crosses the grid once.

Figure~\ref{fig:SineWaveDamping} shows convergence results, obtained using different values of $\sigma_{\Ab}$, for various IMEX schemes at $t=t_{\mbox{\tiny end}}$.
Results for $\sigma_{\Ab}=0.1$, $1$, and $10$ are plotted with red, green, and blue lines, respectively (see figure caption for further details).
All the second-order accurate schemes (PA2, PA2+, RKCB2, and SSP2332) display second-order convergence rates (cf. bottom, black dash-dot reference line).
For $\sigma_{\Ab}=0.1$, SSP2332 is the most accurate among these schemes, while PA2+ is the most accurate for $\sigma_{\Ab}=10$.
On the other hand, PC2 and PD-ARS are indistinguishable and display at most first-order accurate convergence, as expected.
(For $\sigma_{\Ab}=0.1$, PC2 and PD-ARS are the most accurate schemes for $N=8$ and $N=16$.)

\begin{figure}[H]
  \centering
    \includegraphics[width=\textwidth]{figures/SineWaveDamping}
   \caption{Relative error (cf. Eq.~\eqref{eq:errorNormRelative}) versus number of elements for the damping sine wave test.  Results for different values of the absorption opacity $\sigma_{\Ab}$, employing various IMEX time stepping schemes, are compared.  Errors for $\sigma_{\Ab}=0.1$, $1$, and $10$ are plotted with red, green, and blue lines, respectively.  The IMEX schemes employed are: PA2 (triangles pointing left), PA2+ (triangles pointing right), PC2 (asterisk), RKCB2 ($\times$), SSP2332 ($+$), and PD-ARS (circles).  Black dash-dot reference lines are proportional to $N^{-1}$ (top) and $N^{-2}$ (bottom), respectively.}
  \label{fig:SineWaveDamping}
\end{figure}

\subsubsection{Sine Wave: Diffusion}

The final test with known smooth solutions, adopted from \cite{radice_etal_2013}, is diffusion of a sine wave in a purely scattering medium ($f_{0}=0$, $\sigma_{\Ab}=0$).
The computational domain $D=\{x:x\in[-3,3]\}$ is periodic, and the initial condition is given by
\begin{equation}
  \cJ_{0}(x)=0.5+0.49\times\sin\big(\f{\pi\,x}{3}\big)
  \quad\text{and}\quad
  \cH_{x,0}
  =-\f{1}{3\sigma_{\Scatt}}\pderiv{\cJ_{0}}{x}.
  \label{eq:initialConditionDiffusion}
\end{equation}
For a sufficiently high scattering opacity, the moment equations limit to a diffusion equation for the number density (deviations appear at the $1/\sigma_{\Scatt}^{2}$-level).
With the initial conditions in Eq.~\eqref{eq:initialConditionDiffusion}, the analytical solution to the limiting diffusion equation is given by
\begin{equation}
  \cJ(x,t)=\cJ_{0}(x)\times\exp\big(-\f{\pi^{2}\,t}{27\,\sigma_{\Scatt}}\big),
\end{equation}
and $\cH_{x}=(3\,\sigma_{\Scatt})^{-1}\pd{\cJ}{x}$.
When computing errors for this test, we compare the numerical results obtained with the two-moment model to the analytical solution to the limiting diffusion equation.
We compute numerical solutions using three values of the scattering opacity ($\sigma_{\Scatt}=10^{2}$, $10^{3}$, and $10^{4}$), and adjust the end time so that $t_{\mbox{\tiny end}}/\sigma_{\Scatt}=1$.
The initial amplitude of the sine wave has then been reduced by a factor $e^{-\pi^{2}/27}\approx0.694$ for all values of $\sigma_{\Scatt}$.

\begin{figure}[H]
  \centering
  \includegraphics[width=1.0\textwidth]{figures/SineWaveDiffusionN}
   \caption{Absolute error (cf. Eq.~\eqref{eq:errorNormAbsolute}) for the number density $\cJ$ versus number of elements for the sine wave diffusion test.  Results with different values of the scattering opacity $\sigma_{\Scatt}$, employing different IMEX schemes, are compared.  Errors with $\sigma_{\Scatt}=10^{2}$, $10^{3}$, and $10^{4}$ are plotted with red, green, and blue lines, respectively.  The IMEX schemes employed are: PA2 (triangle pointing left), PA2+ (triangle pointing right), PC2 (asterisk), RKCB2 (cross), SSP2332 (plus), and PD-ARS (circle).  Black dash-dot reference lines are proportional to $N^{-1}$ (top) and $N^{-2}$ (bottom), respectively.}
  \label{fig:SineWaveDiffusionJ}
\end{figure}

\begin{figure}[H]
  \centering
  \includegraphics[width=1.0\textwidth]{figures/SineWaveDiffusionG}
   \caption{Same as in Figure~\ref{fig:SineWaveDiffusionJ}, but for the number flux $\cH_{x}$.}
  \label{fig:SineWaveDiffusionH}
\end{figure}

In Figures~\ref{fig:SineWaveDiffusionJ} and \ref{fig:SineWaveDiffusionH} we plot the absolute error, obtained using different values of $\sigma_{\Scatt}$, for various IMEX schemes at $t=t_{\mbox{\tiny end}}$.
Results for $\sigma_{\Scatt}=10^{2}$, $10^{3}$, and $10^{4}$ are plotted with red, green, and blue lines, respectively (see figure caption for further details).
(Scheme PC2 has been shown to work well for this test \cite{radice_etal_2013}, but is included here for comparison with the other IMEX schemes.)
Schemes PD-ARS, RKCB2, and SSP2332 are accurate for this test, and display third-order accuracy for the number density $\cJ$ and second-oder accuracy for $\cH_{x}$.
For $\sigma=10^{2}$, the errors do not drop below $10^{-6}$ because of differences between the two-moment model and the diffusion equation used to obtain the analytic solution.
For larger values of the scattering opacity, the two-moment model agrees better with the diffusion model, and we observe convergence over the entire range of $N$.
Schemes PA2 and PA2+ do not perform well on this test (for reasons discussed in Section~\ref{sec:imex}).
For $\sigma_{\Scatt}=10^{2}$, errors in $\cJ$ and $\cH_{x}$ decrease with increasing $N$, but for $\sigma_{\Scatt}=10^{4}$, errors remain constant with increasing $N$ over the entire range.

\subsection{Packed Beam}
\label{sec:packedBeam}

Next we consider a one-dimensional test with discontinuous initial conditions.
The purpose of this test is to further gauge the accuracy of the two-moment model and demonstrate the robustness of the DG scheme for dynamics close to the boundary of the realizable set $\cR$.
The computational domain is $D=\{x:x\in[-1,1]\}$, and the initial condition is obtained from a distribution function given by
\begin{equation}
  f(x,\mu)
  =\left\{
  \begin{array}{cl}
    1        & \text{if} ~ x\le x_{\mbox{\tiny D}}, ~ \mu\ge\mu_{\mbox{\tiny D}} \\
    \delta & \text{if} ~ x\le x_{\mbox{\tiny D}}, ~ \mu<   \mu_{\mbox{\tiny D}} \\
    \delta & \text{otherwise},
  \end{array}
  \right.
\end{equation}
so that, with $\mu_{\mbox{\tiny D}}=0$, $\vect{\cM}\equiv\vect{\cM}_{\mbox{\tiny L}}=\big(0.5\,(1+\delta),0.25\,(1-\delta)\big)^{T}$ for $x\le x_{\mbox{\tiny D}}$, and $\vect{\cM}\equiv\vect{\cM}_{\mbox{\tiny R}}=\big(\delta,0\big)^{T}$ for $x> x_{\mbox{\tiny D}}$, where $\delta>0$ is a small parameter ($\delta\ll1$).
We let $\delta=10^{-8}$, so that the initial conditions are very close to the boundary of the realizable domain (cf. Figure~\ref{fig:RealizableSetFermionic}).
The analytical solution can be easily obtained by solving the transport equation for all angles $\mu$ (independent linear advection equations), and taking the angular moments.
The numerical results shown in this section were obtained with the third-order scheme (polynomials of degree $k=2$ and the SSPRK3 time stepper) using $400$ elements.
The time step is set to $\dt=0.1\times\dx$

Figure~\ref{fig:PackedBeam} shows results for various times obtained with the two-moment model.
In the upper panels we plot the number density, while the number flux density is plotted in the lower panels.
Numerical solutions are plotted with solid lines, while the analytical solution is plotted with dashed lines.
In the left panels, the algebraic maximum entropy closure of Cernohorsky \& Bludman (CB) \cite{cernohorskyBludman_1994} (cf. Eqs.~\eqref{eq:eddingtonFactor} and \eqref{eq:closureMECB}) was used, while in the right panels the Minerbo closure (cf. Eqs.~\eqref{eq:eddingtonFactorLow} and \eqref{eq:closureMECB}) was used.
For this test, the use of the realizability-preserving limiter described in Section~\ref{sec:limiter} was essential in order to avoid numerical problems.
For the results obtained with the CB closure, the limiter was enacted whenever moments ventured outside the realizable set given by Eq.~\eqref{eq:realizableSet}.
For the results obtained with the Minerbo closure, which is not based on Fermi-Dirac statistics, we used a modified limiter, which was enacted when the moments ventured outside the realizable domain of positive distributions; i.e., not bounded by $f < 1$, so that $\cJ > 0$ and $\cJ > \vect{\cH}|$ (e.g., \cite{levermore_1984}; see red line in Figure~\ref{fig:RealizableSetFermionic}).

\begin{figure}[H]
  \centering
  \begin{tabular}{cc}
    \includegraphics[width=0.5\textwidth]{figures/PackedBeam_ME_CB} &
    \includegraphics[width=0.5\textwidth]{figures/PackedBeam_ME_MI}
  \end{tabular}
   \caption{Numerical results from the packed beam problem at various times: $t=0$ (cyan), $t=0.2$ (magenta), $t=0.4$ (blue), and $t=0.8$ (black).  Results obtained with the Cernohorsky \& Bludman closure are displayed in the left panels, while results obtained with the Minerbo closure are displayed in the right panels.  The analytical solution (dashed lines) is also plotted.}
  \label{fig:PackedBeam}
\end{figure}

As can be seen in Figure~\ref{fig:PackedBeam}, with the CB closure the numerical solution obtained with the two-moment model tracks the analytic solution well, while with the Minerbo closure the numerical solution deviates substantially from the analytic solution.
With the Minerbo closure, the solution also evolves outside the realizable domain for Fermi-Dirac statistics.

In the left panel in Figure~\ref{fig:PackedBeam_Realizability} we plot $\gamma(\vect{\cM})=\big(1-\cJ\big)\,\cJ-|\vect{\cH}|$ versus position for various times.
With the Minerbo closure, $\gamma(\vect{\cM})$ becomes negative in regions of the computational domain (dashed lines), while $\gamma(\vect{\cM})$ remains positive for all $x$ and $t$ the CB closure.
In the right panel of Figure~\ref{fig:PackedBeam_Realizability} we plot the numerical solutions in the $(\cH,\cJ)$-plane.
Initially, the moments are located in two points: $\vect{\cM}_{\mbox{\tiny L}}$ and $\vect{\cM}_{\mbox{\tiny R}}$, for $x\le0$ and $x>0$, respectively (marked by circles in Figure~\ref{fig:PackedBeam_Realizability}).
For $t>0$, the solutions trace out curves in the $(\cH,\cJ)$-plane, connecting $\vect{\cM}_{\mbox{\tiny L}}$ and $\vect{\cM}_{\mbox{\tiny R}}$.
With the CB closure, the solution curve (blue points) follows the boundary of the realizable set $\cR$ defined in Eq.~\eqref{eq:realizableSet} (cf. black line in Figure~\ref{fig:PackedBeam_Realizability}).
With the Minerbo closure (magenta points), the solution follows a different curve --- outside the realizable domain for distribution functions bounded by $f\in(0,1)$, but inside the realizable domain of positive distributions (cf. red line in Figure~\ref{fig:PackedBeam_Realizability}).
We have also run this test using the algebraic maximum entropy closure of Larecki \& Banach \cite{lareckiBanach_2011} and the simpler Kershaw-type closure in \cite{banachLarecki_2017a}.
The numerical solutions obtained with both of these closures follow the analytic solution well, and remain within the realizable set $\cR$.
We point out that simply using the realizability-preserving limiter described in Section~\ref{sec:limiter} with the Minerbo closure does not result in a realizability-preserving scheme for Fermi-Dirac statistics because of the properties of this closure discussed in Section~\ref{sec:algebraicClosure}, and plotted in the right panel of Figure~\ref{fig:MabWithDifferentClosure}.

\begin{figure}[H]
  \centering
  \begin{tabular}{cc}
    \includegraphics[width=0.485\textwidth]{figures/PackedBeam_Realizability} &
    \includegraphics[width=0.485\textwidth]{figures/PackedBeam_RealizableDomain}
  \end{tabular}
   \caption{In the left panel, $\gamma(\vect{\cM})=(1-\cJ)\,\cJ-|\vect{\cH}|$ is plotted versus $x$ for various times in the packed beam problem: $t=0$ (cyan), $t=0.2$ (magenta), $t=0.4$ (blue), and $t=0.8$ (black).  Results obtained with the CB closure, which remain positive throughout the evolution, are plotted with solid lines, while results obtained with the Minerbo closure are plotted with dashed lines.  In the right panel, the moments are plotted in the $(\cH,\cJ)$-plane for the same times as in the left panel.  Results obtained with the CB and Minerbo closures are plotted in blue and magenta, respectively.  The solid black and red lines are contours where $(1-\cJ)\,\cJ=\cH$ and $\cJ=\cH$, respectively.  The initial states are marked with black circles.}
  \label{fig:PackedBeam_Realizability}
\end{figure}

\subsection{Fermion Implosion}
\label{sec:fermionImplosion}

The next test is inspired by line source benchmark (cf. \cite{brunner_2002,garrettHauck_2013}), which is a challenging test for approximate transport algorithms.
The original line source test consists of an initial delta function particle distribution in radius $R=|\vect{x}|$; i.e., $f_{0}=\delta(R)$.
For $t>0$, a radiation front propagates in the radial direction, away from $R=0$.
Apart from capturing details of the exact transport solution, maintaining realizability of the two-moment solution is challenging.

Here, a modified version of the line source --- dubbed \emph{Fermion Implosion},  designed to test the realizability-preserving properties of the two-moment model for fermion transport --- is computed on a two-dimensional domain $D=\{\vect{x}\in\bbR^{2}:x^{1}\in[-1.28,1.28], x^{2}\in[-1.28,1.28]\}$.
Instead of initializing with a delta function, we follow the initialization procedure in \cite{garrettHauck_2013}, and approximate the initial condition using an isotropic Gaussian distribution function.
However, different from \cite{garrettHauck_2013}, the initial distribution function is bounded $f_{0}\in(0,1)$, and reaches a minimum in the center of the computational domain (hence implosion)
\begin{equation}
  f_{0}
  =1-\max\Big[\,e^{-R^{2}/(2\,\sigma_{0}^{2})},10^{-8}\,\Big].
\end{equation}
We set $\sigma_{0}=0.03$, and evolve to a final time of $t=1.0$.
We run this test using a grid of $512^{2}$ elements, polynomials of degree $k=1$, and the SSPRK2 time stepping scheme with $\dt=0.1\times\dx^{1}$.
(There are no collisions included in this test; i.e., $\sigma_{\Ab}=\sigma_{\Scatt}=0$.)
For comparison, we present results using the algebraic closures of Cernohorsky \& Bludman (CB) and Minerbo.

\begin{figure}[H]
  \centering
  \begin{tabular}{cc}
    \includegraphics[width=0.495\textwidth]{figures/Implosion_Image} &
    \includegraphics[width=0.495\textwidth]{figures/Implosion_Lineout} \\
    \includegraphics[width=0.495\textwidth]{figures/Implosion_RealizableDomain} &
    \includegraphics[width=0.495\textwidth]{figures/Implosion_LimiterParameters}
  \end{tabular}
   \caption{Numerical results for the Fermion Implosion problem, computed both the CB and Minerbo closures.  Spatial distribution of the number density $\cJ$ (CB closure only) at $t=1$ (upper left panel).  In the upper right panel we plot the number density $\cJ$ versus radius $R=|\vect{x}|$ for various times ($t=0$, $0.1$, $0.2$, and $0.4$) for the CB (blue), the Minerbo (magenta) closures, and the reference transport solution (dashed black lines).  (The initial condition, which is the same for all models, is plotted with cyan.)  Numerical solutions in the $(\cH_{x},\cJ)$-plane (lower left panel), for the same times as plotted in the upper right panel are plotted for CB and Minerbo.  Limiter parameters $\vartheta_{1}$ (solid) and $\vartheta_{2}$ (dashed) in Section~\ref{sec:limiter} (minimum over the whole computational domain) versus time (lower right panel).}
  \label{fig:Implosion}
\end{figure}

Numerical results for the Fermion Implosion problem are plotted in Figure~\ref{fig:Implosion}.
For $t>0$, the low-density region in the center of the computational domain is quickly filled in, and a cylindrical perturbation propagates radially away from the center.
For the model with the CB closure, this perturbation, seen as a depression in the density relative to the ambient medium, has reached $R\approx1$ for $t=1$ (upper left panel in Figure~\ref{fig:Implosion}).
The right panel in Figure~\ref{fig:Implosion} illustrates the difference in dynamics resulting from the two closures.
(We also plot a reference transport solution obtained using the filtered spherical harmonics scheme described in \cite{garrettHauck_2013}; dashed black lines.\footnote{Kindly provided by Dr. Ming Tse Paul Laiu (private communications).})
With the CB closure (blue lines), the central density increases towards the maximum value of unity, and an low-density pulse propagates radially.
The amplitude of the pulse decreases with time due to the geometry of the problem.
For $t=0.4$, the peak depression in located around $R=0.34$ (with $\cJ\approx0.96$).
With the Minerbo closure, the central density continues to increase beyond unity, and reaches a maximum of about $\cJ\approx1.37$ at $t=0.1$.
The central density starts to decrease beyond this point in time, and a steepening pulse propagates radially away from the center.
(This pulse is trailing the pulse in the model computed with the CB closure.)
At $t=0.4$, a discontinuity appears to have formed around $R=0.2$, resulting in numerical oscillations.
Except for the realizability-enforcing limiter (which is not triggered for this model), no other limiters are used to prevent numerical oscillations.
Although the solutions obtained with the two-moment model differ from the reference transport solution, the results obtained with the CB closure are in closer agreement with the transport solution.
This is likely because the CB closure is consistent with the bound $f<1$ satisfied by the transport solution in this test.
(For tests involving lower occupancies, the CB and Minerbo closures are expected to perform similarly.)
In the lower left panel in Figure~\ref{fig:Implosion}, the moments are plotted in the $(\cH_{x},\cJ)$-plane for the same times as plotted in the upper left panel.
(Each dot represents the moments at a specific spatial point and time.)
Initially, $\vect{\cH}=0$, and all the moments lie on the line connecting $(0,0)$ and $(0,1)$; cyan points.
With the CB closure (blue points), the moments are confined to evolve inside the realizable domain $\cR$ (black), while with the Minerbo closure, the moments are not confined to $\cR$, but to the region above the red lines (the realizable domain for moments of positive distribution functions), and this is the reason for the difference in dynamics in the two models.
For the model with the CB closure, some moments evolve very close to the boundary of the realizable domain, and the positivity limiter is continuously triggered to damp these moments towards the cell average, which is realizable by the design of the numerical scheme.
In the lower right panel in Figure~\ref{fig:Implosion} we plot the limiter parameters $\vartheta_{1}$ (solid) and $\vartheta_{2}$ (dashed) (cf. \eqref{eq:limitDensity} and \eqref{eq:limitMoments}) versus time for the CB closure model (blue) and the Minerbo closure model (magenta); the minimum over the whole computational domain is plotted.
For the CB closure model, the limiter is triggered to prevent both density overshoots and $\gamma(\cM)<0$.
Late in the simulation ($t\gtrsim0.7$), the minimum value of $\vartheta_{2}$ is around $0.1$.
For the model using the Minerbo closure, the limiter is not triggered ($\vartheta_{1}=\vartheta_{2}=1$).

\subsection{Homogeneous Sphere}
\label{sec:homogeneousSphere}

The homogeneous sphere test (e.g., \cite{smit_etal_1997}) considers a sphere with radius $R$.
Inside the sphere (radius $<R$), the absorption opacity $\sigma_{\Ab}$ and the equilibrium distribution function $f_{0}$ are set to constant values.
The scattering opacity $\sigma_{\Scatt}$ is set to zero in this test (i.e., $\xi=1$).
Outside the sphere, the absorption opacity is zero.
The steady state solution, obtained by solving the transport equation in spherical symmetry, is given by
\begin{equation}
  f_{\mbox{\tiny A}}(r,\mu)=f_{0}\,\big(1-e^{-\chi_{0}\,s(r,\mu)}\big),
  \label{eq:distributionHomogeneousSphere}
\end{equation}
where $r=|\vect{x}|$,
\begin{equation}
  s(r,\mu)
  =\left\{
  \begin{array}{lll}
    r\,\mu+R\,g(r,\mu) & \mbox{if}\quad r<R, & \mu\in[-1,+1], \\
    2\,R\,g(r,\mu) & \mbox{if}\quad r \ge R, & \mu\in[(1-(R/r)^{2})^{1/2},+1], \\
    0 & \mbox{otherwise},
  \end{array}
  \right.
\end{equation}
and $g(r,\mu)=[1-(r/R)^{2}(1-\mu^{2})]^{1/2}$.
Thus, $f_{\mbox{\tiny A}}(r,\mu)\in(0,f_{0})~\forall~r,\mu$.

Here, this test is computed using a three-dimensional Cartesian domain $D=\{\vect{x}\in\bbR^{3}:x^{1}\in[0,2], x^{2}\in[0,2], x^{3}\in[0,2]\}$.
Because of the symmetry of the problem, and to save computational resources, we only compute the solution in one octant.
On the inner boundaries, we impose reflecting boundary conditions, while we impose 'homogeneous' boundary conditions on the outer boundary in all three coordinate dimensions; i.e., values for all moments in a boundary element are set equal to the corresponding values in the nearest element just inside $D$.
Since this test is computed with Cartesian coordinates using a relatively low spatial resolution ($64^{3}$), we have found it necessary to smooth out the opacity over a finite radial extent to avoid numerical artifacts due to a discontinuous absorption opacity.
Specifically, we use an absorption opacity of the following form
\begin{equation}
  \sigma_{\Ab}(r)=\f{\sigma_{\Ab,0}}{(r/R_{0})^{p}+1}.
\end{equation}
We set $f_{0}=1$, and compute three versions of this test: one with $\sigma_{\Ab,0}=1$, $R_{0}=1$, and $p=80$ (Test~A), one with $\sigma_{\Ab,0}=10$, $R_{0}=1$, and $p=80$ (Test~B), and one with $\sigma_{\Ab}=10^{3}$, $R_{0}=0.85$, and $p=40$ (Test~C).
(These values for $R_{0}$ and $p$ result in similar radius for where the optical depth equals $2/3$ in Test~B and Test~C.)
We compute until $t=5$, when the system has reached an approximate steady state.
In all the tests, we use the IMEX scheme PD-ARS with $\dt=0.1\times\dx^{1}$ --- the least compute-intensive of the convex-invariant IMEX schemes presented here.
The main purpose of this test is to compare the results obtained using the different algebraic closures discussed in Section~\ref{sec:algebraicClosure}.

In Figure~\ref{fig:HomogeneousSphere}, we plot results obtained for all tests at $t=5$: Test~A (top panels), Test~B (middle panels), and Test~C (bottom panels).
The particle density $\cJ$ and the flux factor $h=|\vect{\cH}|/\cJ$ (left and right panels, respectively) are plotted versus radius $r=|\vect{x}|$.
In each panel, results obtained with the various algebraic closures discussed in Section~\ref{sec:algebraicClosure} are plotted: Minerbo (magenta), CB (blue), BL (green), and Kershaw (cyan).
The analytical solution is also plotted (dashed black lines).
\begin{figure}[H]
  \centering
  \begin{tabular}{cc}
    \includegraphics[width=0.5\textwidth]{figures/HomogeneousSphere_ClosureComparison_Chi_1e0_Density}
    \includegraphics[width=0.5\textwidth]{figures/HomogeneousSphere_ClosureComparison_Chi_1e0_FluxFactor} \\
    \includegraphics[width=0.5\textwidth]{figures/HomogeneousSphere_ClosureComparison_Chi_1e1_Density}
    \includegraphics[width=0.5\textwidth]{figures/HomogeneousSphere_ClosureComparison_Chi_1e1_FluxFactor} \\
    \includegraphics[width=0.5\textwidth]{figures/HomogeneousSphere_ClosureComparison_Chi_1e3_Density}
    \includegraphics[width=0.5\textwidth]{figures/HomogeneousSphere_ClosureComparison_Chi_1e3_FluxFactor}
  \end{tabular}
   \caption{Results obtained for the homogeneous sphere problem with the two-moment model for different values of the absorption opacity $\sigma_{\Ab,0}$: $1$ (top panels), $10$ (middle panels), and $1000$ (bottom panels).  The particle density (left panels) and the flux factor (right panels) are plotted versus radius.  Numerical results obtained with the algebraic closures of Minerbo (magenta), CB (blue), BL (green), and Kershaw (cyan) are compared with the analytic solution (dashed black lines).}
  \label{fig:HomogeneousSphere}
\end{figure}

We find good overall agreement between the results obtained with the two-moment model and the analytical solution.
Partly due to the smoothing of the absorption opacity around the surface, the numerical and analytical solutions naturally differ around $r=1$.
Aside from some differences discussed in more detail below, the numerical and analytical solutions --- for all values of the absorption opacity $\sigma_{\Ab,0}$ and all closures --- agree well as $r$ tends to zero, as well as when $r\gg1$.
The results obtained with the maximum entropy closures CB and BL are practically indistinguishable on the plots.
This is consistent with the similarity of the Eddington factors for these two closures, as shown in Figure~\ref{fig:EddingtonFactorsWithDifferentClosure}.
We also find that the results obtained with the fermionic Kershaw closure agree well with the maximum entropy closures based on Fermi-Dirac statistics (CB and BL).
From the plots of the particle density (left panels in Figure~\ref{fig:HomogeneousSphere}), the results obtained with all the closures, including Minerbo, appear very similar.
(For Test~A, the particle density obtained with the Minerbo closure deviates the most from the analytic solution inside $r\approx0.75$; upper left panel).
From the plots of the flux factor (right panels in Figure~\ref{fig:HomogeneousSphere}), it is evident that the results obtained with the Minerbo closure --- the only closure not based on Fermo-Dirac statistics --- deviates the most from the analytic solution outside $r=1$, where the flux factor is consistently higher than the analytical solution for all values of $\sigma_{\Ab,0}$.
The fermionic closures (CB, BL, and Kershaw) track the analytic solution better.
Similar agreement between the numerical and analytical solutions was reported by Smit et al. \cite{smit_etal_1997}, when using the CB maximum entropy closure with $f_{0}=0.8$ and an unsmoothed absorption opacity $\sigma_{\Ab}=4$.
We also note that our results appear to be somewhat at odds with the results recently reported by Murchikova et al. \cite{murchikova_etal_2017}, who compared results obtained with the two-moment model using a large number of algebraic closures for this same problem (albeit using an unsmoothed and slightly different value for the absorption opacity).
Murchikova et al. do not plot the particle density, but find essentially no difference in the flux factor and the Eddington factor when comparing results obtained with the maximum entropy closures of Minerbo and Cernohorsky \& Bludman (CB).

In Figure~\ref{fig:HomogeneousSphereRealizability}, we further compare the results obtained when using the Minerbo and CB closures by plotting the solutions to the homogeneous sphere problem for Test~C at $t=5$ in the $(|\vect{\cH}|,\cJ)$-plane (cf. the realizable domain in Figure~\ref{fig:RealizableSetFermionic}).
The numerical solution at each spatial point is represented by a blue (CB) or magenta (Minerbo) dot in the panels.
In the lower two panel we zoom in on the results obtained with the two closures around the top and lower right regions of the realizable domain (lower left and lower right panel, respectively; cf. green boxes in the upper right panel).
\begin{figure}[H]
  \centering
  \includegraphics[width=1.0\textwidth]{figures/HomogeneousSphere_Realizability_Chi_1e3_CBandMinerbo}
  \begin{tabular}{cc}
    \includegraphics[width=0.5\textwidth]{figures/HomogeneousSphere_Realizability_Chi_1e3_CBandMinerbo_Box1}
    \includegraphics[width=0.5\textwidth]{figures/HomogeneousSphere_Realizability_Chi_1e3_CBandMinerbo_Box2}
  \end{tabular}
   \caption{Scatter plots of the numerical solution to the homogeneous sphere problem for Test~C in the $(|\vect{\cH}|,\cJ)$-plane.  Results obtained with the CB and Minerbo closures are plotted in the upper panel, blue and magenta points, respectively.  Zoom-ins on the solutions obtained with the two closures are plotted in the lower two panels (cf. green boxes in the upper panel).  The boundaries of the realizable domains $\cR$ and $\cR^{+}$ are indicated with solid black and solid red curves, respectively.  See text for further details.  }
  \label{fig:HomogeneousSphereRealizability}
\end{figure}
As can be seen in the upper panel in Figure~\ref{fig:HomogeneousSphereRealizability}, the solutions to the homogeneous sphere problem obtained with the two closures trace out distinct curves relative to the realizable domain $\cR$, whose boundary is indicated by solid black curves in each panel.
When using the CB closure, the realizability-preserving DG-IMEX scheme developed here maintains solutions within $\cR$.
When using the Minerbo closure, the appropriate realizable domain is given by $\cR^{+}$ (cf. Eq.~\eqref{eq:realizableSetPositive}), whose boundary is indicated by solid red lines in Figure~\ref{fig:HomogeneousSphereRealizability}, and we find that the numerical solution ventures outside $\cR$.
Near the surface around $r=1$, the number density slightly exceeds unity (lower left panel), while for larger radii, the computed flux may exceed the value allowed by Fermi-Dirac statistics (lower right panel).


\documentclass[a4paper, 12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\usepackage[]{amsfonts}
\usepackage[]{graphicx}

\title{CS231A Course Notes 5: Active and Volumetric Stereo}
\author{Kenji Hata and Silvio Savarese}
\date{}

\renewcommand\emph{\textbf}

\numberwithin{equation}{section}
\begin{document}

\maketitle

\section{Introduction}
In traditional stereo, the main idea is to use corresponding points $p$ and $p'$ to estimate the location of a 3D point $P$ by triangulation. A key challenge here, is to solve the correspondence problem: how do we know whether a point $p$ actually corresponds to a point $p'$ in another image? This problem is further accentuated by the fact that we need to handle the many 3D points that are present in the scene. The focus of these notes will discuss alternative techniques that work well in reconstructing the 3D structure.

\section{Active stereo}
\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/active_stereo_setup.png}
    \caption{The active stereo setup that projects a point into 3D space.}
    \label{fig:active_stereo_setup}
\end{figure}

First, we will an introduce a technique known as \emph{active stereo} that helps mitigate the correspondence problem in traditional stereo. The main idea of active stereo is to replace one of the two cameras with a device that interacts with the 3D environment, usually by projecting a pattern onto the object that is easily identifiable from the second camera.  This new projector-camera pair defines the same epipolar geometry that we introduced for camera pairs, whereby the image plane of the replaced camera is replaced with a \emph{projector virtual plane}. In Figure~\ref{fig:active_stereo_setup}, the projector is used to project a point $p$ in the virtual plane onto the object in 3D space, producing a point in 3D space $P$. This 3D point $P$ should be observed in the second camera as a point $p'$. Because we know what we are projecting (e.g. the position of $p$ in the virtual plane, the color and intensity of the projection, etc.), we can easily discover the corresponding observation in the second camera $p'$.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/active_stereo_line.png}
    \caption{The active stereo setup that projects a line into 3D space.}
    \label{fig:active_stereo_line}
\end{figure}

A common strategy in active stereo is to project from the virtual plane a vertical stripe $s$ instead of a single point. This case is very similar to the point case, where the line $s$ is projected to a stripe in 3D space $S$ and observed as a line in the camera as $s'$. If the projector and camera are parallel or rectified, then we can discover the corresponding points easily by simply intersecting $s'$ with the horizontal epipolar lines. From the correspondences, we can use the triangulation methods introduced in the previous course notes to reconstruct all the 3D points on the stripe $S$. By swiping the line across the scene and repeating the process, we can recover the entire shape of all visible objects in the scene.

Notice that one requirement for this algorithm to work is that the projector and the camera need to be calibrated. An active stereo system can be calibrated using similar techniques as described in previous notes. We can first calibrate the camera using a calibration rig. Then, by projecting known stripes onto the calibration rig, and using the corresponding observations in the newly calibrated camera, we can set up constraints for estimating the projector intrinsic and extrinsic parameters. Once calibrated, this active stereo setup can produce very accurate results. In 2000, Marc Levoy and his students at Stanford demonstrated that by using a finely tuned laser scanner, they could recover the shape of Michaelangelo's Pieta with sub-millimeter accuracy.

However, in some cases, having a finely tuned projector may be too expensive or cumbersome. An alternative approach that uses a much cheaper setup leverages shadows to produce active patterns to the object we want to recover. By placing a stick between the object and a light source at a known position, we can effectively project a stripe onto the object as before. Moving the stick allows us to project different shadow stripes onto the object and recover the object in a similar manner as before. This method, although much cheaper, tends to produce less accurate results because it requires very good calibration between the stick, camera, and light source, while needing to maintain a tradeoff between the length and thinness of the stick's shadow.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/active_multicolor_setup.png}
    \caption{The active stereo setup that uses multiple colored lines to reconstruct an object from a single projection.}
    \label{fig:active_multicolor_setup}
\end{figure}

One limitation of projecting a single stripe onto objects is that it is rather slow, as the projector needs to swipe across the entire object. Furthermore, this means that this method cannot capture deformations in real time. A natural extension is to instead attempt to reconstruct the object from projecting a single frame or image. The idea is to project a known pattern of different stripes to the entire visible of the object, instead of a single stripe. The colors of these stripes are designed in such a way that the stripes can be uniquely identified from the image. Figure~\ref{fig:active_multicolor_setup} illustrates this multiple color-coded stripes method. This concept powered many versions of modern depth sensors, such as the original version of the Microsoft Kinect. In practice, these sensors use infrared laser projectors , which  allow it to capture video data in 3D under any ambient light conditions.

\section{Volumetric stereo}
\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/volumetric_setup.png}
    \caption{The setup of volumetric stereo, which takes points from a limited, working volume and performs consistency checks to determine 3D shape.}
    \label{fig:volumetric_setup}
\end{figure}
An alternative to both the traditional stereo and active stereo approach is \emph{volumetric stereo}, which inverts the problem of using correspondences to find 3D structure. In volumetric stereo, we assume that the 3D point we are trying to estimate is within some contained, known volume. We then project the hypothesized 3D point back into the calibrated cameras and validate whether these projections are consistent across the multiple views. Figure~\ref{fig:volumetric_setup} illustrates the general setup of the volumetric stereo problem. Because these techniques assume that the points we want to reconstruct are contained by a limited volume, these techniques are mostly used for recovering the 3D models of specific objects as opposed to recovering models of a scene, which may be unbounded.

The main tenet of any volumetric stereo method is to first define what it means to be ``consistent'' when we reproject a 3D point in the contained volume back into the multiple image views. Thus, depending on the definition of the concept of consistent observations, different techniques can be introduced. In these notes, we will briefly outline three major techniques, which are known as space carving, shadow carving, and voxel coloring.

\subsection{Space carving}
\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/visual_cone.png}
    \caption{The silhouette of an object we want to reconstruct contains all pixels of the visible portion of the object in the image. The visual cone is the set of all possible points that can project into the silhouette of the object in the image.}
    \label{fig:visual_cone}
\end{figure}
The idea of space carving is mainly derived from the observation that the contours of an object provide a rich source of geometric information about the object. In the context of multiple views, let us first set up the problem illustrated in Figure~\ref{fig:visual_cone}. Each camera observes some visible portion of an object, from which a contour can be determined. When projected into the image plane, this contour encloses a set of pixels known as the \emph{silhouette} of the object in the image plane. Space carving ultimately uses the silhouettes of objects from multiple views to enforce consistency.

However, if we do not have the information of the 3D object and only images, then how can we obtain silhouette information? Luckily, one practical advantage of working with silhouettes is that they can be easily detected in images if we have control of the background behind the object that we want to reconstruct. For example, we can use a ``green screen" behind the object to easily segment the object from its background.

Now that we have the silhouettes, how can we actually use them? Recall that in volumetric stereo, we have an estimate of some volume that we guarantee that the object can reside within. We now introduce the concept of a \emph{visual cone}, which is the enveloping surface defined by the camera center and the object contour in the image plane. By construction, it is guaranteed that the object will lie completely in both the initial volume and the visual cone.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/visual_hull.png}
    \caption{The process of estimating the object from multiple views involves recovering the visual hull, which is the intersection of visual cones from each camera.}
    \label{fig:visual_hull}
\end{figure}

Therefore, if we have multiple views, then we can compute visual cones for each view. Since, by definition, the object resides in each of these visual cones, then it must lie in the intersection of these visual cones, as illustrated in Figure~\ref{fig:visual_hull}. Such an intersection is often called a \emph{visual hull}.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/space_carving.png}
    \caption{The result of space carving when done on a voxel grid. The region is the reconstructed object after carving from two views, while the shaded part on the inside is the actual object. Notice that the reconstruction is always conservative.}
    \label{fig:space_carving}
\end{figure}

In practice, we first begin by defining a working volume that we know the object is contained within. For example, if our cameras encircle the object, then we can simply say that the working volume is the entire interior of the space enclosed by the cameras. We divide this volume into small units known as \emph{voxels}, defining what is known as a voxel grid. We take each voxel in the voxel grid and project it into each of the views. If the voxel is not contained by the silhouette in a view, then it is discarded. Consequently, at the end of the space carving algorithm, we are left with the voxels that are contained within the visual hull.

Although the space carving method avoids the correspondence problem and is relatively straightforward, it still has many limitations. One limitation of space carving is that it scales linearly with the number of voxels in the grid. As we reduce the size of each voxel, the number of voxels required by the grid increases cubically. Therefore, to get finer reconstruction results in much larger run time. However, some methods such as using octrees can be used mitigate this problem. Related, but simpler methods include doing iterative carvings to reduce the size of the initial voxel grid.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/concavity.png}
    \caption{Space carving cannot handle some concavities, as demonstrated here, because it cannot carve into that region, as doing so will carve through the object. Note this means that generally the only concavities that space carving can handle are holes through an object. }
    \label{fig:concavity}
\end{figure}

Another limitation is that the efficacy of space carving is dependent on the number of views, the preciseness of the silhouette, and even the shape of the object we are trying to reconstruct. If the number of views is too low, then we end of up with a very loose estimate of the visual hull of the object. As the number of views increases, the more extraneous voxels can be removed by the consistency check. Furthermore, the validity of the consistency check is solely upheld by the fact that we believe that the silhouettes are correct. If the silhouette is too conservative and contains more pixels than necessary, then our carving may not be precise. In a potentially even worse case, the silhouette misses portions of the actual object, resulting in a reconstruction that is overly carved. Finally, a major drawback of space carving is that it is incapable of modeling certain concavities of an object, as shown in Figure~\ref{fig:concavity}.

\subsection{Shadow carving}
To circumvent the concavity problem posed by space carving, we need to look to other forms of consistency checks. One important cue for determining the 3D shape of an object that we can use is the presence of \emph{self-shadows}. Self-shadows are the shadows that an object projects on itself. For the case of concave objects, an object will often cast self-shadows in the concave region.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/shadow_carving.png}
    \caption{The setup of shadow carving, which augments space carving by adding a new consistency check from an array of lights surrounding the camera.}
    \label{fig:shadow_carving}
\end{figure}

\emph{Shadow carving} at its core augments space carving with the idea of using self-shadows to better estimate the concavities. As shown in Figure~\ref{fig:shadow_carving}, the general setup of shadow carving is very similar to space carving. An object is placed in a turntable that is viewed by a calibrated camera. However, there is an array of lights in known positions around the camera whose states can be appropriately turned on and off. These lights will be used to make the object cast self-shadows.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/shadow_carving_detailed.png}
    \caption{Shadow carving relies on a new consistency check that removes voxels that are in the self-shadow visual cone of the camera and the visual cone of the light.}
    \label{fig:shadow_carving_detailed}
\end{figure}

As shown in Figure~\ref{fig:shadow_carving_detailed}, the shadow carving process begins with an initial voxel grid, which is trimmed down by using the same approach as in space carving. However, in each view, we can turn on and off each light in the array surrounding the camera. Each light will produce a different self-shadow on the object. Upon identifying the shadow in the image plane, we can then find the voxels on the surface of our trimmed voxel grid that are in the visual cone of the shadow. These surface voxels allow us to then make a new visual cone with the image source. We then leverage the useful fact that a voxel that is part of both visual cones cannot be part of the object to eliminate voxels in the concavity.

Like space carving, the runtime of shadow carving is dependent on the resolution of the voxel grid. The runtime scales cubically with the resolution of the voxel grid. However, if there are $N$ lights, then shadow carving takes approximately $N+1$ times longer than space carving, as each voxel needs to be projected into the camera and each of the $N$ lights can be turned on and off.

In summary, shadow carving always produces a conservative volume estimate that better reconstructs 3D shapes with concavities. The quality of the results depends on both the number of views and the number of light sources. Some disadvantages of this approach are that it cannot handle cases where the object contains reflective or low albedo regions. This is because shadows cannot be detected accurately in such conditions.

\subsection{Voxel coloring}
The last technique we cover in volumetric stereo is \emph{voxel coloring}, which uses color consistency instead of contour consistency in space carving.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.8\textwidth]{figures/voxel_coloring.png}
    \caption{The setup of voxel coloring, which makes a consistency check of the color of all projections of a voxel.}
    \label{fig:voxel_coloring}
\end{figure}

As illustrated in Figure~\ref{fig:voxel_coloring}, suppose that we are given images from multiple views of an object that we want to reconstruct. For each voxel, we look at its corresponding projections in each of the images and compare the color of each of these projections. If the colors of these projections sufficiently match, then we mark the voxel as part of the object. One benefit of voxel coloring not present in space carving is that color associated with the projections can be transferred to the voxel, giving a colored reconstruction.

Overall, there are many methods that one could use for the color consistency check. One example would be to set a threshold between the color similarity between the projections. However, there exists a critical assumption for any color consistency check used: the object being reconstructed must be \emph{Lambertian}, which means that the perceived luminance of any part of the object does not change with viewpoint location or pose. For non-Lambertian objects, such as those made of highly reflective material, it is easy to conceive that the color consistency check would fail on voxels that are actually part of the object.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.4\textwidth]{figures/ambiguity1.png}
    \includegraphics[width = 0.4\textwidth]{figures/ambiguity2.png}
    \caption{An example of an ambiguous case of vanilla voxel coloring.}
    \label{fig:ambiguity}
\end{figure}

One drawback of vanilla voxel coloring is that it produces a solution that is not necessarily unique, as shown in Figure~\ref{fig:ambiguity}. Finding the true, unique solution complicates the problem of reconstruction by voxel coloring. It is possible to remove the ambiguity in the reconstruction by introducing a visibility constraint on the voxel, which requires that the voxels be traversed in a particular order.

In particular, we want to traverse the voxels layer by layer, starting with voxels closer to the cameras and then progress to further away voxels. When using this order, we perform the color consistency check. Then, we check if the voxel is viewable by at least two of the cameras, which constructs our visibility constraint. If the voxel was not viewable by at least two cameras, then it must be occluded and thus not part of the object. Notice that our order of processing the closer voxels allows us to make sure that we keep the voxels that can occlude later processed voxels to enforce this visibility constraint.

To conclude, voxel coloring has the advantage of simultaneously capturing the shape and texture of an object. Some of the drawbacks include that the object is assumed to be Lambertian and that the cameras cannot be in certain locations, as the voxels need to be processed in a certain order due to the visibility constraint.
\end{document}


\documentclass[10pt, compress]{beamer}

\usetheme{amii}

\usepackage[scale=2]{ccicons}
\usepackage{booktabs}
\usepackage{minted}
\usepackage{tikz}

\usemintedstyle{trac}
\usetikzlibrary{arrows,automata,shapes.geometric,shapes.multipart}

\title{{\large Comparing Direct and Indirect Temporal-Difference Methods for Estimating the Variance of the Return}}
\subtitle{}
\date{\vspace{-0.5em}}
\author{Craig Sherstan, Dylan R. Ashley$^{*}$, Brendan Bennett$^{*}$, Kenny Young, \newline
        Adam White, Martha White, Richard S. Sutton}
\institute{Reinforcement Learning and Artificial Intelligence Laboratory, University of Alberta}

\begin{document}

\maketitle

\section{Background}

\begin{frame}{What is reinforcement learning?}
    Reinforcement learning considers an agent interacting with an environment:

    \begin{figure}
        \centering
        \includegraphics[height=8em]{{images/reinforcement_learning.pdf}}
    \end{figure}

    The function the agent uses to pick actions in states is known as the policy. Often the challenge is to find a "good" policy.
\end{frame}

\begin{frame}{What is a good policy?}\vspace{1em}
    In reinforcement learning the return is defined as follows:
    \begin{equation*}
        G_{\,t} = R_{\,t + 1} + \gamma_{\,t + 1} \,R_{\,t + 2} + \gamma_{\,t + 1} \,\gamma_{\,t + 2} \,R_{\,t + 3} + \ldots
    \end{equation*}

    Often we want to maximize the \alert{expected value} of the return. But "good" does depend on what we want.
\end{frame}

\begin{frame}{How can we learn it's expected value?}\vspace{1em}
    Temporal-difference (TD) methods have been fairly successful in tackling reinforcement learning problems so far. TD methods use predictions to update predictions.

    \vspace{1em}
    One of the most straightforward TD methods is TD($\lambda$):
    \begin{align*}
        \delta_{\,t} &= R_{\,t + 1} + \gamma_{\,t + 1} \,w_{\,t}^{\,T} \,x_{\,t + 1} - w_{\,t}^{\,T} \,x_{\,t} \\
        z_{\,t} &= \gamma_{\,t} \,\lambda_{\,t} \,z_{\,t - 1} + x_{\,t} \\
        w_{\,t + 1} &= w_{\,t} + \alpha_{\,t + 1} \,\delta_{\,t} \,z_{\,t} \\
    \end{align*}
\end{frame}

\begin{frame}{So what's this presentation about?}\vspace{1em}
    Recall what the return is:
    \begin{equation*}
        G_{\,t} = R_{\,t + 1} + \gamma_{\,t + 1} \,R_{\,t + 2} + \gamma_{\,t + 1} \,\gamma_{\,t + 2} \,R_{\,t + 3} + \ldots
    \end{equation*}

    We're not limited to learning only it's expected value. We could also learn more parts of its distribution such as its \alert{variance}.
\end{frame}

\section{Motivation}

\begin{frame}{Why might we want to learn its variance?}
    The variance might tell us things about the distribution that the expected value can't. Sometimes these things are \alert{interesting}. For example it could differentiate these two domains:

    \vspace{1em}
    \begin{figure}
        \centering
        \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,semithick]

            \tikzstyle{every state}=[draw=black,text=black]
            \tikzstyle{every text node part}=[align=center]
            \tikzstyle{terminal}=[regular polygon,regular polygon sides=4,thick,minimum size=1.5cm,draw=black]

            \node[initial,state] (0)              {$s_0$};
            \node[terminal]      (1) [right of=0] {};

            \small
            \draw[-latex]  (0) edge node [align=center,above] {\(R_{\,t + 1} = 0\)} (1);
        \end{tikzpicture}
    \end{figure}

    \begin{figure}
        \centering
        \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,semithick]

            \tikzstyle{every state}=[draw=black,text=black]
            \tikzstyle{every text node part}=[align=center]
            \tikzstyle{terminal}=[regular polygon,regular polygon sides=4,thick,minimum size=1.5cm,draw=black]

            \node[initial,state] (0)              {$s_0$};
            \node[terminal]      (1) [right of=0] {};

            \small
            \draw[-latex]  (0) edge node [align=center,above] {\(R_{\,t + 1} = \mathcal{N}(0, 1)\)} (1);
        \end{tikzpicture}
    \end{figure}
\end{frame}

\begin{frame}{Any better reasons?}
    The variance can give us \alert{useful} information about the distribution. It can tell us how risky an action is to take in a state.

    \vspace{1em}
    Humans take risk into decisions and don't necessarily act in a way that maximizes the expected value.
\end{frame}

\begin{frame}{Anything else?}
    We can use an estimate of the variance to \alert{learn} how to learn. For example here is an algorithm that uses an estimate of the variance to tune $\lambda$ on the fly:

    \begin{figure}
        \centering
        \href{https://arxiv.org/abs/1607.00446}{\includegraphics[height=15em]{{images/lambda_greedy.png}}}
    \end{figure}
\end{frame}

\section{Learning the Variance}

\begin{frame}{How can we learn its variance?}
    We can use this identity:
    \begin{equation*}
        Var(X) = \mathbb{E}\big[X^{\,2}\big] - \big(\mathbb{E}\big[X\big]\big)^2
    \end{equation*}

    If we are learning \(\mathbb{E}_{\pi} [G_{\,t} \,|\, S_{\,t} = s]\) then we can just learn \(\mathbb{E}_{\pi} [G_{\,t}^{\,2} \,|\, S_{\,t} = s]\) on the side and use both our estimates to try to estimate \(Var_{\pi}(G_{\,t} \,|\, S_{\,t} = s)\).
\end{frame}

\begin{frame}{What would this look like?}
   Using the identity \(Var(X) = \mathbb{E}\big[X^{\,2}\big] - \big(\mathbb{E}\big[X\big]\big)^2\) one can estimate the variance using the following structure:

    \vspace{1em}
    \begin{figure}
        \centering
        \includegraphics[height=8em]{{images/indirect.pdf}}
    \end{figure}
\end{frame}

\begin{frame}{Is there another way?}
    We can also use this identity:
    \begin{equation*}
        Var(X) = \mathbb{E}\big[\big(X - \mathbb{E}\big[X\big]\big)^{\,2}]
    \end{equation*}

    If we are learning \(\mathbb{E}_{\pi} [G_{\,t} \,|\, S_{\,t} = s]\) then we can approximate the variance using the following:
    \vspace{1em}
    \begin{equation*}
        Var_{\pi}(G_{\,t} \,|\, S_{\,t} = s) \approx \mathbb{E}_{\pi} \left[\delta_{\,t}^{\,2} + \sum\limits_{i \,= \,t + 1}^{\infty} \left(\delta_{\,i} \prod\limits_{j \,=\, t + 1}^{i} \gamma_{\,j} \,\right)^{2} \,\Bigg|\, S_{\,t} = s\right]
    \end{equation*}
\end{frame}

\begin{frame}{So how would this look?}
    Using the identity \(Var(X) = \mathbb{E}\big[\big(X - \mathbb{E}\big[X\big]\big)^{\,2}]\) one can estimate the variance using the following structure:

    \vspace{1em}
    \begin{figure}
        \centering
        \includegraphics[height=7.277em]{{images/direct.pdf}}
    \end{figure}
\end{frame}

\begin{frame}{What would be the update equations for this?}
    Using TD($\lambda$) with $\overline{w}$ as the parameter vector for estimating the variance we obtain the following update equations:
    \vspace{1em}
    \begin{align*}
        \delta_{\,t} &= R_{\,t + 1} + \gamma_{\,t + 1} \,w_{\,t}^{\,T} \,x_{\,t + 1} - w_{\,t}^{\,T} \,x_{\,t} \\
        z_{\,t} &= \gamma_{\,t} \,\lambda_{\,t} \,z_{\,t - 1} + x_{\,t} \\
        w_{\,t + 1} &= w_{\,t} + \alpha_{\,t + 1} \,\delta_{\,t} \,z_{\,t} \\[1em]
        %
        \overline{\delta}_{\,t} &= \delta_{\,t}^{\,2} + \gamma_{\,t + 1}^{\,2} \,\overline{w}_{\,t}^{\,T} \,x_{\,t + 1} - \overline{w}_{\,t}^{\,T} \,x_{\,t} \\
        \overline{z}_{\,t} &= \gamma_{\,t}^{\,2} \,\overline{\lambda}_{\,t} \,\overline{z}_{\,t - 1} + x_{\,t} \\
        \overline{w}_{\,t + 1} &= \overline{w}_{\,t} + \overline{\alpha}_{\,t + 1} \,\overline{\delta}_{\,t} \,\overline{z}_{\,t}
    \end{align*}
\end{frame}

\begin{frame}{How do they compare visually?}
    \vspace{1em}
    \begin{figure}
        \flushleft
        \includegraphics[height=8em]{{images/indirect.pdf}}
    \end{figure}
    \vspace{1em}
    \begin{figure}
        \flushleft
        \includegraphics[height=7.277em]{{images/direct.pdf}}
    \end{figure}
\end{frame}

\section{Empirical Comparison}

\begin{frame}{What do we want to know?}\vspace{1em}
    Ideally we want to know if the direct method

    \begin{itemize}
        \item is faster or slower to converge than the indirect method,
        \item is more robust or less robust to differences in the value and variance learner, and
        \item performs better or worse under linear function approximation.
    \end{itemize}
\end{frame}

\begin{frame}{What is the simplest domain we can compare them on?}\vspace{1em}
    We begin by comparing them on the following simple Markov chain with gaussian rewards:

    \vspace{1em}
    \begin{figure}
        \hspace{-2.5em}\includegraphics[width=0.8\linewidth]{{images/chain/state_diagram.pdf}}
    \end{figure}
\end{frame}

\begin{frame}{How do they compare when \(\alpha = \overline{\alpha}\) ?}\vspace{1em}
    When \(\alpha = \overline{\alpha} = 0.001\) both perform roughly the same:

    \vspace{1em}
    \begin{figure}
        \hspace{-2.5em}\includegraphics[width=0.9\linewidth]{{images/chain/same_step_size.pdf}}
    \end{figure}
\end{frame}

\begin{frame}{What about when \(\alpha > \overline{\alpha}\) ?}\vspace{1em}
    When \(\alpha = 0.01\) and \(\overline{\alpha} = 0.001\) the variance of the indirect method is higher:

    \vspace{1em}
    \begin{figure}
        \includegraphics[width=0.9\linewidth]{{images/chain/value_step_size_greater.pdf}}
    \end{figure}
\end{frame}

\begin{frame}{So what about when \(\alpha < \overline{\alpha}\) ?}\vspace{1em}
    When \(\alpha = 0.001\) and \(\overline{\alpha} = 0.01\) the variance of the indirect method is higher and the direct method is more stable:

    \vspace{1em}
    \begin{figure}
        \includegraphics[width=0.9\linewidth]{{images/chain/variance_step_size_greater.pdf}}
    \end{figure}
\end{frame}

\begin{frame}{Does this result generalize?}\vspace{1em}
    In this domain we only see the two perform similarly when both step sizes are equal (note that the dotted line represents the indirect method and the solid line represents the direct method):

    \vspace{1em}
    \begin{figure}
        \includegraphics[width=0.7\linewidth]{{images/chain/sweep.png}}
    \end{figure}
\end{frame}

\begin{frame}{What about under function approximation?}\vspace{1em}
    We use the following domain previously used to evaluate the indirect method:

    \begin{figure}
        \hspace{-2.5em}\includegraphics[width=0.9\linewidth]{{images/random_walk/state_diagram.pdf}}
    \end{figure}

    For each state $s_{\,i}$ we use \(\phi(s_{\,i}) = [1, \,i / 30]^{\,T}\) for our value estimator and \(\phi_{\,2}(s_{\,i}) = [1, \,i / 30, \,(i / 30)^{\,2}]^{\,T}\) for our variance estimator.
\end{frame}

\begin{frame}{How do they perform on this domain?}\vspace{0.75em}
    Here the direct method vastly outperforms the indirect method:

    \vspace{0.5em}
    \begin{figure}
        \includegraphics[height=17em]{{images/random_walk/performance.png}}
    \end{figure}
\end{frame}

\begin{frame}{What is the quality of the solutions reached?}\vspace{0.75em}
    The direct method reaches a much better fixed point and exhibits much less variance in its variance estimates:

    \vspace{0.5em}
    \begin{figure}
        \includegraphics[height=17em]{{images/random_walk/quality.pdf}}\hspace{2.5em}
    \end{figure}
\end{frame}

\begin{frame}{What is the parameter sensitivity?}\vspace{0.75em}
    In this domain, the direct method is much less sensitive to the choice of step sizes than the indirect method:

    \vspace{0.5em}
    \begin{figure}
        \includegraphics[height=17em]{{images/random_walk/sensitivity.pdf}}\hspace{2.5em}
    \end{figure}
\end{frame}

\begin{frame}{Summary}
    We have described a method of directly estimating the variance of the return using temporal-difference methods. We have argued that learning the variance of the return can

    \begin{itemize}
        \item tell us \alert{interesting} information about our domain,
        \item tell us \alert{useful} information about the distribution of our return, and
        \item can be used to \alert{learn} how to learn.
    \end{itemize}
\end{frame}

\begin{frame}{Summary (continued)}
    We have furthermore shown evidence that the direct method:

    \begin{itemize}
        \item learns just as fast and occasionally \alert{faster} than the indirect method,
        \item is \alert{more robust} to inconsistencies in the value and variance learner, and
        \item exhibits substantially \alert{better} performance under linear function approximation.
    \end{itemize}
\end{frame}

\plain{}{Questions?}

\end{document}


\section{Sums of Products}
\todo[inline]{Add a description of what a universe is}

A different way of describing datatypes in a generic representation, besides pattern functors, are \textit{Sums of Products}\cite{vries2014sums} (SOP). SOP is a generic representation with additional constraints which more faithfully reflects the Haskell datatypes: each datatype is a single n-ary sum, where each component of the sum is a single n-ary product. The SOP universe is described using \textit{codes} of kind \texttt{[[*]]}. The outer list describes an n-ary sum, representing the choice between constructors and each inner list an n-ary products, representing the constructor arguments.  The code of kind \inlinehaskell{[[*]]} can then be interpreted to describe Haskell datatypes of kind \inlinehaskell{*}. To define a code, the tick mark \inlinehaskell{`} is used to lift the list to a type-level.

\begin{minted}{haskell}
Code (Tree a) = `[`[a], `[Tree a, a, Tree a]]
\end{minted}

The usage of SOP has a positive effect on expressing generic functions easily or at all. Additionally, the SOP completely divides the structural representation from the metadata. As a result, you do not have to deal with metadata while writing generic functions. However, the additional constraints on the generic representation makes the SOP universe size comparatively bigger than pattern functors. Therefore, it is more complex to extend the SOP than for pattern functors.

% \begin{itemize}
%     \item While many of the libraries that are
%     commonly in use today represent datatypes as arbitrary combinations of binary sums and products, SOP reflects the structure of datatypes more faithfully: each datatype is a single n-ary sum, where each component of the sum is a single n-ary product.
%     \item A major plus of the SOP view is that it allows separating function-specific metadata from the main structural representation and recombining this information later.
%     \item In this paper, we introduce a view (which we call SOP) which is based on a single, n-ary, sum, where each component of the sum is a single, n-ary, product.
%     \item The SOP view also takes a very interesting approach to metadata. In most generic views, metadata is intertwined with the structural representation, which means that every generic function has to deal with it in some way—even if it is just ignored, as in the M1 case for \texttt{garities} shown above. Furthermore, metadata sometimes leads to additional implicit assumptions about the shape of the data.
%     \item In the SOP view, metadata is completely independent from the data representation. This means that functions which do not need it, don't have to deal with it; conversely, it also means that we can easily define application-specific metadata, i.e., type-directed additional information that “configures” how a particular generic function should behave.
%     \item The tick marks are used to explicitly indicate that we mean the promoted type.
%     \item The fundamental idea of the SOP universe is that the kind of codes is a (promoted) list of list of types, written [[*]]. The goal of the universe is to provide descriptions of Haskell datatypes (of kind *)
% \end{itemize}


\section{Herbie: Improving Floating Point Accuracy}
\label{sec:herbie}

Herbie automatically improves accuracy
  for floating-point expressions,
  using random sampling to measure error,
  a set of rewrite rules for generating program variants,
  and algorithms that prune and combine program variants
  to achieve minimal error.
Herbie received PLDI 2015's Distinguished Paper award~\cite{herbie}
  and has been continuously developed since then,
  sporting hundreds of Github stars, hundreds of downloads,
  and thousands of users on its online version.
Herbie uses \egraphs for algebraic simplification of mathematical expressions,
  which is especially important for avoiding floating-point errors
  introduced by cancellation, function inverses, and redundant computation.

Until our case study,
  Herbie used a custom \egraph implementation
  written in Racket (Herbie's implementation language)
  that closely followed traditional \egraph implementations.
With timeouts disabled,
  \egraph-based simplification consumed
  the vast majority of Herbie's run time.
As a fix, Herbie sharply limits the simplification process,
  placing a size limit on the \egraph itself and a time limit on the whole
  procedure.
When the timeout is exceeded, simplification fails altogether.
Furthermore, the Herbie authors knew of several features
  that they believed would improve Herbie's output
  but could not be implemented because
  they required more calls to simplification
  and would thus introduce unacceptable slowdowns.
Taken together, slow simplification reduced Herbie's performance, completeness,
  and efficacy.

We implemented a \egg simplification backend for Herbie.
The \egg backend is over $3000\times$ faster than Herbie's initial simplifier and
  is now used by default as of Herbie 1.4.
Herbie has also backported some of \egg's features like batch simplification and
  rebuilding to its \egraph implementation
  (which is still usable, just not the default),
  demonstrating the portability of \egg's conceptual improvements.
% This has led to over a $200\times$ speedup over its initial design,
%   demonstrating that \egg's

\subsection{Implementation}

Herbie is implemented in Racket while \egg is in Rust;
  the \egg simplification backend is thus implemented as a Rust library that
  provides a C-level API for Herbie to access via foreign-function interface (FFI).
The Rust library defines the Herbie expression grammar
  (with named constants, numeric constants, variables, and operations)
  as well as the \eclass analysis necessary to do constant folding.
The library is implemented in under 500 lines of Rust.

Herbie's set of rewrite rules is not fixed;
  users can select which rewrites to use using command-line flags.
Herbie serializes the rewrites to strings,
  and the \egg backend parses and instantiates them on the Rust side.

Herbie separates exact and inexact program constants:
  exact operations on exact constants
  (such as the addition of two rational numbers)
  are evaluated and added to the \egraph,
  while operations on inexact constants or that yield inexact outputs
  are not.
We thus split numeric constants in the Rust-side grammar
  between exact rational numbers and inexact constants,
  which are described by an opaque identifier,
  and transformed Racket-side expressions into this form
  before serializing them and passing them to the Rust driver.
To evaluate operations on exact constants,
  we used the constant folding \eclass analysis
  to track the ``exact value'' of each \eclass.%
\footnote{Herbie's rewrite rules guarantee that different exact values
  can never become equal; the semilattice \textsf{join} checks this invariant on the Rust side.}
Every time an operation \enode is added to the \egg \egraph,
  we check whether all arguments to that operation have exact value (using the analysis data),
  and if so do rational number arithmetic to evaluate it.
The \eclass analysis is cleaner than the corresponding code in Herbie's implementation,
  which is a built-in pass over the entire \egraph.

\subsection{Results}

\begin{figure}
  \centering
  \includegraphics[height=8cm]{herbie}
  \caption{
    Herbie sped up its expression simplification phase
      by adopting \egg-inspired features like
      batched simplification and rebuilding
      into its Racket-based \egraph implementation.
    Herbie also supports using \egg itself for additional speedup.
    Note that the y-axis is log-scale.
  }
  \label{fig:herbie-results}
\end{figure}

Our \egg simplification backend
  is a drop-in replacement to the existing Herbie simplifier,
  making it easy to compare speed and results.
We compare using
  Herbie's standard test suite of roughly 500 benchmarks,
  with timeouts disabled.
\autoref{fig:herbie-results} shows the results.
The \egg simplification backend is over
  $3000\times$ faster than Herbie's initial simplifier.
This speedup eliminated Herbie's largest bottleneck:
  the initial implementation dominated Herbie's total run time at $98.1\%$,
  backporting \egg improvements into Herbie cuts
  that to about half the total run time,
  and \egg simplification takes under $5\%$ of the total run time.
Practically, the run time of Herbie's initial implementation was smaller, since
  timeouts cause tests failures when simplification takes too long.
Therefore, the speedup also improved Herbie's completeness,
  as simplification now never times out.

Since incorporating \egg into Herbie, the Herbie developers have backported some
  of \egg's key performance improvements into the Racket \egraph implementation.
First, batch simplification gives a large speedup because Herbie simplifies many
  similar expressions.
When done simultaneously in one equality saturation, the \egraph's structural
  sharing can massively deduplicate work.
Second, deferring rebuilding (as discussed in \autoref{sec:rebuilding}) gives a
  further $2.2\times$ speedup.
As demonstrated in \autoref{fig:eval-iter}, rebuilding offers an asymptotic
  speedup, so Herbie's improved implementation (and the \egg backend as well)
  will scale better as the search size grows.

%%% Local Variables:
%%% TeX-master: "../thesis"
%%% End:


\documentclass[9pt, a4paper, oneside]{amsart}

\usepackage{enumitem}
\usepackage{parskip}
\usepackage{fancyhdr}
\usepackage{color}
\usepackage{multicol}
\pagestyle{fancy}

\newlist{questions}{enumerate}{1}
\setlist[questions, 1]{label = \bf Q.\arabic*., itemsep=1em}

% \setlength{\topmargin}{-10mm}
% \setlength{\textheight}{235mm}
% \setlength{\oddsidemargin}{-3mm}
% \setlength{\textwidth}{165mm}
% \setlength{\footskip}{10mm}

\lhead{\scshape Apurva Nakade}
\rhead{\scshape Honors Single Variable Calculus}
\renewcommand*{\thepage}{\small\arabic{page}}
\title{Problem Set 03}

\begin{document}

\maketitle
\thispagestyle{fancy}

\section*{Part 1 - Continuity}

\begin{questions}[resume]

	\item
	\begin{enumerate}
		\item Use the $ \epsilon - \delta$ definition to show that the constant function $ f(x) = c $ is continuous everywhere.

		\item Use the $ \epsilon - \delta$ definition to show that the function $ f(x) = x $ is continuous everywhere.

		\item Let $ p(x)$ a polynomial of degree $ n$. Use Theorem 2 to prove that $p(x)$ is continuous everywhere.
	\end{enumerate}

	Trigonometric functions, exponential functions and logarithms are also continuous wherever they are defined. We will assume this fact without proof for now and perhaps come back to it later.

	\item
	\begin{enumerate}
		\item Prove that if $ \lim \limits_{x \rightarrow 0} f(x)/x = l$ and $ b \neq 0$ then $$ \lim \limits_{x \rightarrow 0} f(bx)/x = bl$$
		\item Assuming $ \lim \limits_{x \rightarrow 0} \sin x / x = 1$ find  $ \lim \limits_{x \rightarrow 0}$ for each of the following functions,
		      \begin{multicols}{3}
		      	\begin{enumerate}
		      		\item $\sin (2x)/ x$
		      		\item $\sin (ax)/ \sin(bx)$
		      		\item $\sin^2 (2x)/ x$
		      		\item $\sin^2 (2x)/ x^2$
		      	\end{enumerate}
		      \end{multicols}

	\end{enumerate}

	\item Determine, with proof, the points at which the following function is continuous.
	$$ f(x) = \begin{cases} 0 & \mbox{ if $ x$ is rational } \\ x & \mbox{ otherwise }\end{cases}$$

	\item Suppose that $ g$ is continuous on $[a,b]$ and $ h$ is continuous on $[b,c]$ and that $ g(b) = h(b)$. Define a new function
	\begin{align*}
		f(x) = \begin{cases} g(x) & \mbox{ if }a \le x < b \\ h(x) & \mbox{ if }b \le x \le c  \end{cases}
	\end{align*}
	Show that $ f(x)$ is continuous on $ [a,c]$. (Thus, continuous functions can be `glued'.)

\end{questions}

\newpage
\section*{Part 2 - Three Hard Theorems}
In this HW you can use any of the Theorems 1-9 from Chapter 7 to solve the problems.
\begin{questions}[resume]
	\item For each of the polynomial functions $ f$, find (by trial and error) an integer $ n$ such that $ f(x) = 0$ for some $ x$ in  $[n,n+1]$.
	\begin{multicols}{2}
		\begin{enumerate}
			\item $ x^3 - x + 3$
			\item $ x^5 + 5x^4 + 2x + 1$
			\item $ x^5 + x +1$
			\item $ 4x^2 - 4x + 1$
		\end{enumerate}
	\end{multicols}

	\item Suppose $ f$ and $ g$ are continuous on $ [a,b]$ and that $ f(a) < g(a)$ and $ f(b) > g(b)$. Prove that $ f(x) = g(x)$ for some $ x$ in $ (a,b)$.

	\item Suppose that $ f$ is a continuous function with $ f(x) > 0$ for all $ x$, and $ \lim \limits_{x \rightarrow \infty} f(x) = 0 = \lim \limits_{x \rightarrow -\infty} f(x)$. (Draw a picture.) We want to prove that there is some number $ y$ such that $ f(y) \ge f(x)$ for all $ x$.
	\begin{enumerate}
		\item Choose an arbitrary positive real number $s$. Using the $ \epsilon - \delta $ definition of $ \lim \limits _ {x \rightarrow \infty}$ and $ \lim \limits _ {x \rightarrow -\infty}$ show that there is a number $ N$ such that $f(s) > f(x)$ for all $ |x| > N$.
		\item Let $ M = \max(N,s)$ and let $ y$ be the real number in the the interval $ [-M,M]$ such that $ f(y) \ge f(x)$ for all $ x$ in $[-M,M]$. Why does such a $ y$ exist?
		\item Using the fact that $ s \le M$ show that $ f(y) > f(x)$ for all $ |x| > M$.
		\item  Using part (2) and (3) conclude that $ f(y) \ge f(x)$ for all real numbers $ x$.

		\item (Optional) Does there exist a real number $ y$ such that $ f(y) \le f(x)$ for all $ x$?
	\end{enumerate}

	\item Suppose that $ f(x)$ is continuous on $ [a,b]$ and that $ f(x)$ is always rational. What can be said about $ f$? (Hint: Use the intermediate value theorem.)

\end{questions}

\newpage
\section*{Part 3 - Least Upper Bounds}
\begin{questions}[resume]
	\item In this problem we'll prove the following theorem.
	\begin{quote}
		\textbf{Theorem 9.} For every polynomial $ p(x)$ of odd degree $ n$ there is a real number $ x$ such that $ p(x)=0$.
	\end{quote}
	The idea of the proof is to show that for large values of $|x|$ the polynomial $ p(x)$ behaves like $ x^n$. Without any loss of generality assume that the polynomial is of the form
	\begin{align*}
		p(x) & = x^n + a_{1} x^{n-1} + a_{2} x^{n-2} + \cdots + a_{n-1} x + a_n                                                      \\
		     & = x^n\left( 1 + \dfrac{a_{1}} {x} + \dfrac{a_{2}} {x^2} + \cdots + \dfrac{a_{n-1}}{x^{n-1}} + \dfrac{a_n}{x^n}\right)
	\end{align*}
	\begin{enumerate}
		\item Argue that there exists a number $ N$ such that $ \left|\dfrac{a_{i}}{x^{i}}\right| < \dfrac{1}{2n}$ for all $ |x| > N$ and for all $1 \le i \le n$. \\(It's ok to not be completely rigorous for this part.)
		\item Show that for all $ |x| > N$,
		      \begin{align*}
		      	-\dfrac{1}{2} < \dfrac{a_{1}} {x} + \dfrac{a_{2}} {x^2} + \cdots + \dfrac{a_{n-1}}{x^{n-1}} + \dfrac{a_n}{x^n} < \dfrac{1}{2}
		      \end{align*}
		\item
		      Show that for all $ |x| > N$,
		      \begin{align*}
		      	\dfrac{1}{2} < \dfrac{p(x)}{x^n} < \dfrac{3}{2}
		      \end{align*}
		\item Argue that because $ n$ is odd this implies that there exist real numbers $ a > N$, $b < -N$ with $ p(a) > 0 > p(b)$. Conclude that $ p(x) = 0$ for some number $ x$.
	\end{enumerate}

	\item
	Find the supremum (least upper bound) and infimum (greatest lower bound) of the following sets. (Proofs are not required, it's enough to draw pictures.)
	\begin{multicols}{2}
		\begin{enumerate}
			\item $ \left\{ 1/n : n \in \mathbb{N} \right\}$
			\item $ \left\{ 1/n : n \in \mathbb{Z} \mbox{ and } n \neq 0 \right\}$
			\item $ \left\{ 1/n + (-1)^n: n \in \mathbb{N} \right\}$
			\item $ \left\{ x : x^2 < 2 \mbox{ and } x \mbox{ is rational} \right\}$
			\item $ \left\{ x : x^2 + x - 2 \ge 0  \right \}$
			\item $ \left\{ x : x^2 + x - 2 \le 0  \right \}$
		\end{enumerate}
	\end{multicols}
	%
	% \item For a non-empty set $ A$ let $ -A$ denote the set of all $ -x$ for $ x$ in $ A$. Prove that
	% \begin{enumerate}
	% 	\item $ \sup (-A) = - \inf A$
	% 	\item $ \inf (-A) = - \sup A$
	% \end{enumerate}

	\item In this problem we'll prove the Intermediate Value Theorem using (P13).
	\begin{quote}
		\textbf{Intermediate Value Theorem.} If $ f$ is a continuous function on $ [a,b]$ satisfying $ f(a) < c < f(b)$, then there exists some $ x$ in $ [a,b]$ such that $ f(x) = c$.
	\end{quote}

	\begin{enumerate}
		\item Let $ A$ be the set of $ x$ in $ [a,b]$ such that $ f(x) \le c$. Why is the set $ A$ non-empty?

		\item 	As $ A$ is a non-empty subset of $ [a,b]$ by (P13) $ A$ has a least upper bound, let $ y = \sup A$. We want to show that $ f(y) = c$. We'll prove this by contradiction, assume on the contrary that $ f(y) \neq c$.
		      \begin{description}
		      	\item[Case I $ f(y) < c$ ] In this case argue that for some $ \delta$ the number $ y + \delta$ is in $ A$ and hence $ y$ cannot be an upper bound.
		      	\item[Case II $ f(y) > c$ ] In this case argue that for some $ \delta$ the number $ y - \delta$ is also an upper bound of $ A$ and hence $ y$ cannot be the \emph{least} upper bound.
		      \end{description}

		\item Give an example to show that the Intermediate Value Theorem does not hold if the function $ f$ is discontinuous. Also describe the set $ A$, defined as above, for your example and explain why the above proof fails for this case.
	\end{enumerate}

	% \item Proofs are not required for this problem, however describe your answers as precisely as possible.
	%
	% \begin{enumerate}
	% 	\item Find a function which is discontinuous at $1, \frac{1}{2}, \frac{1}{3},\frac{1}{4}, \ldots$ but continuous at all other points.
	% 	\item Find a function which is discontinuous at $1, \frac{1}{2}, \frac{1}{3},\frac{1}{4}, \ldots$ and 0 but continuous at all other points.
	% \end{enumerate}
	% If $ \lim \limits _ {x \rightarrow a} f(x)$ exists but is $ \neq f(a)$ then $ f$ is said to have a \textbf{removable singularity} at $ a$.
	% \begin{enumerate}[resume]
	% 	\item Give an example of a function $ f$ with a removable discontinuity at 0.
	% 	\item Given an example of a function $ f$ with a discontinuity at 0	which is not removable.
	% \end{enumerate}

\end{questions}

\end{document}