\section{Second Order Homogeneous Equations}{}{}\label{sec:second order homogeneous}
A second order differential equation is one containing the second
derivative $y''$. These are in general quite complicated, but one fairly
simple type is useful: The second order linear equation with constant
coefficients.

\begin{example}{Second Order Homogeneous Equation}{Second Order Homogeneous Equation}\label{Second Order Homogeneous Equation}
Analyze the intial value problem $y''-y'-2y=0$,
$y(0)=5$, $y'(0)=0$.
\end{example}

\begin{solution}
We make an inspired guess: might there be a
solution of the form $\ds e^{rt}$? This seems at least plausible,
since in this case $\ds y''$, $\ds y'$, and $y$ all
involve $\ds e^{rt}$.

If such a function is a solution then
\begin{eqnarray*}
r^2 e^{rt}-r e^{rt}-2e^{rt}&=&0\cr
e^{rt}(r^2-r-2)&=&0\cr
(r^2-r-2)&=&0\cr
(r-2)(r+1)&=&0,
\end{eqnarray*}
so $r$ is $2$ or $-1$. Not only are $\ds f=e^{2t}$ and $\ds g=e^{-t}$
solutions, but notice that $\ds y=Af+Bg$ is also, for any constants $A$
and $B$:
\begin{eqnarray*}
(Af+Bg)''-(Af+Bg)'-2(Af+Bg)&=&Af''+Bg''-Af'-Bg'-2Af-2Bg\cr
&=&A(f''-f'-2f)+B(g''-g'-2g)\cr
&=&A(0)+B(0)=0.
\end{eqnarray*}
Can we find $A$ and $B$ so that this is a solution to the initial
value problem? Let's substitute:
$$
5=y(0)=Af(0)+Bg(0)=Ae^0+Be^0=A+B
$$
and
$$0=y'(0)=Af'(0)+Bg'(0)=A2e^{0}+B(-1)e^0=2A-B.$$
So we need to solve this system of \underline{two} equations with \underline{two} unknowns:
\[
\left\{
\begin{array}{ll}
A+B	&	=5	\\
2A-B	&	=0
\end{array}
\right.
\]
Let $B=2A$, substitute into the first equation to get $5=A+2A=3A$. Then $A=5/3$ and $B=10/3$, and the
desired solution is $\ds (5/3)e^{2t}+(10/3)e^{-t}$. You now see why
the initial condition in this case included both $y(0)$ and $y'(0)$:
We needed two equations in the two unknowns $A$ and $B$
\end{solution}

You should of course wonder whether there might be other solutions, but as it turns out,
the answer is no. We will not prove this, but here is the theorem that
tells us what we need to know:

\begin{theorem}{Solutions to Second Order Homogeneous}{Solutions to Second Order Homogeneous}\label{Solutions to Second Order Homogeneous}
Given the differential equation $\ds ay''+by'+cy=0$, $a\not=0$,
consider the quadratic polynomial $ar^2+br+c=0$, called the
\dfont{characteristic polynomial}. Using the quadratic formula, this polynomial
always has one or two roots, call them $r_1$ and $r_2$.  The general
solution of the differential equation is:

\begin{enumerate}[(a)]
\item	$\ds y=Ae^{r_1t}+Be^{r_2t}$, if the roots $r_1$ and $r_2$ are real
  numbers, and $r_1\not=r_2$.
\item	$\ds y=Ae^{r_1t}+Bte^{r_2t}$, if $r_1=r_2$ is a real, repeated root.
\item	$\ds y=A\cos(\beta t)e^{\alpha t}+B\sin(\beta t)e^{\alpha t}$,
if the roots are complex numbers, $r=\alpha\pm\beta i$.
\end{enumerate}
\end{theorem}

\begin{example}{}{}
	Solve the differential equation $y''+A^2y=0$.
\end{example}
\begin{solution}
	First we write the characteristic equation, $r^2+A^2=0$. Then we find the roots of the characteristic equation:
	\[r^2=-A^2\implies r=\pm Ai\]
	These are imaginary roots, so the solution of the differential equation is in the form:
	\[y=c_1\cos(At)+c_2\sin(At)\]
\end{solution}

\begin{example}{}{}
	Solve the differential equation $y''-A^2y=0$.
\end{example}
\begin{solution}
	First we write the characteristic equation, $r^2-A^2=0$. Then we find the roots of the characteristic equation:
	\[r^2=A^2\implies r=\pm A\]
	These are imaginary roots, so the solution of the differential equation is in the form:
	\[y=c_1e^{At}+c_2e^{-At}=c_1e^{At}+\frac{c_2}{e^{At}}\]
\end{solution}

\begin{example}{Damped Spring Oscillation}{Damped Spring Oscillation}\label{Damped Spring Oscillation}
Use a differential equation to describe the position of a mass hung on a spring.
\end{example}

\begin{solution}
 Suppose a mass $m$ is hung on a spring with spring
constant $k$. If the spring is compressed or stretched and then
released, the mass will oscillate up and down. Due to friction,
the oscillation will be damped: Eventually the motion will cease. The
damping will depend on the amount of friction; for example, if the
system is suspended in oil the motion will cease sooner than if the
system is in air. Using some simple physics, it is not hard to see
that the position of the mass is described by the differential
equation:
$\ds my''+by'+ky=0$. Using $m=1$, $b=4$, and $k=5$ we find the
motion of the mass. The characteristic polynomial is
$r^2+4r+5=0$, with roots $r=(-4\pm\sqrt{16-20})/2=-2\pm i$. Thus the
general solution is
$\ds y=A\cos(t)e^{-2t}+B\sin(t)e^{-2t}$.
Suppose we know that $y(0)=1$ and $y'(0)=2$. Then as before we
form two simultaneous equations: From $y(0)=1$ we get
$1=A\cos(0)e^0+B\sin(0)e^0=A$. For the second we compute
$$y''=-2Ae^{-2t}\cos(t)+Ae^{-2t}(-\sin(t))-2Be^{-2t}\sin(t)+
Be^{-2t}\cos(t),$$
and then
$$2=-2Ae^0\cos(0)-Ae^0\sin(0)-2Be^0\sin(0)+Be^0\cos(0)
=-2A+B.$$
So we get $A=1$, $B=4$, and $\ds y=\cos(t)e^{-2t}+4\sin(t)e^{-2t}$.

Here is a useful trick that makes this easier to understand: We have
$\ds y=(\cos t+4\sin t)e^{-2t}$. The expression $\cos t+4 \sin t$ is a
bit reminiscent of the trigonometric formula
$\cos(\alpha-\beta)=\cos(\alpha)\cos(\beta)+\sin(\alpha)\sin(\beta)$
with $\alpha=t$.
Let's rewrite it a bit as
$$\sqrt{17}\left({1\over\sqrt{17}}\cos t + {4\over\sqrt{17}}\sin t\right).$$
Note that $\ds (1/\sqrt{17})^2+(4/\sqrt{17})^2=1$,
which means that there is an angle
$\beta$ with $\ds \cos\beta=1/\sqrt{17}$ and
$\ds \sin\beta=4/\sqrt{17}$ (of course, $\beta$ may not be a ``nice'' angle). Then
$$\cos t+4\sin t = \sqrt{17}\left(\cos t\cos \beta+\sin\beta\sin t\right)
=\sqrt{17}\cos(t-\beta).$$
Thus, the solution may also be written
$\ds y=\sqrt{17}e^{-2t}\cos(t-\beta)$.
This is a cosine curve  that has been shifted $\beta$ to the
right; the $\ds \sqrt{17}e^{-2t}$ has the effect of diminishing the
amplitude of the cosine as $t$ increases.
%; see figure~\ref{fig:damped oscillation}. The oscillation is damped very
%quickly, so in the first graph it is not clear that this is an
%oscillation. The second graph shows a restricted range for $t$.
\end{solution}

Other physical systems that oscillate can also be described by such
differential equations. Some electric circuits, for example, generate
oscillating current.

%\figure[!ht]
%%\texonly
%\hbox to \hsize{\hfill
%\def\yarrow{-- +(-1.5pt,-3pt) +(0pt,0pt) -- +(1.5pt,-3pt) +(0pt,0pt)}
%\def\xarrow{-- +(-3pt,-1.3pt) +(0pt,0pt) -- +(-3pt,1.5pt) +(0pt,0pt) }
%\tikzpicture[domain=0:3,x=1.2cm,y=3cm]
%\draw (0,0) -- (5.2,0) \xarrow node [right] {$x$};
%\draw (0,0) -- (0,1.3) \yarrow node [above] {$y$};
%\gpad
%\draw[color=black] plot[smooth,id=\the\gpnum,domain=0:5] function{sqrt(17)*exp(-2*x)*cos(x-asin(4/sqrt(17)))};
%\foreach \x in {1,2,3,4,5} \draw (\x,0) -- (\x,-2pt) node[anchor=north] {$\x$};
%\foreach \y in {0,1} \draw (0,\y) -- (-2pt,\y) node[anchor=east]
         %{$\y$};
%\endtikzpicture
%\hfill
%\tikzpicture[domain=2.5:5,x=1.6cm,y=120cm]
%\draw (2.5,0) -- (5.2,0) \xarrow node [right] {$x$};
%\draw (2.5,0) -- (2.5,0.03) \yarrow node [above] {$y$};
%\gpad
%\draw[color=black] plot[smooth,id=\the\gpnum,domain=2.5:5] function{sqrt(17)*exp(-2*x)*cos(x-asin(4/sqrt(17)))};
%\foreach \x in {3,4,5} \draw (\x,0) -- (\x,-2pt) node[anchor=north] {$\x$};
%\foreach \y in {0,0.01,0.02} \draw (2.5,\y) -- (2.4,\y) node[anchor=east] {$\y$};
%\endtikzpicture
%\hfill}%\endtexonly
%%\figrdef{fig:damped oscillation}
%%\htmlfigure{DE-damped_oscillation.html}
%\caption{\label{fig:damped oscillation}
%Graph of a damped oscillation.}
%%\endcaption
%\endfigure

\begin{example}{}{}\label{}
 Find the solution to the intial value problem
$\ds y''-4y'+4y=0$, $y(0)=-3$, $y'(0)=1$.
\end{example}

\begin{solution}
The characteristic polynomial is $r^2-4r+4=(r-2)^2$, so there is one root,
$r=2$,
and the general solution is $\ds Ae^{2t}+Bte^{2t}$. Substituting
$t=0$ we get $-3=A+0=A$. The first derivative is
$\ds 2Ae^{2t}+2Bte^{2t}+Be^{2t}$; substituting $t=0$ gives
$1=2A+0+B=2A+B=2(-3)+B=-6+B$, so $B=7$. The solution is
$\ds -3e^{2t}+7te^{2t}$.
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:second order homogeneous}}

\begin{enumialphparenastyle}

%%%%%%%%%%%
%\begin{ex}
 %Verify that the function in part (a) of
%theorem~\xrefn{thm:solns to second order homogeneous} is a solution to
%the differential equation $\ds ay''+by'+cy=0$.
%\end{ex}
%
%%%%%%%%%%%
%\begin{ex}
 %Verify that the function in part (b) of
%theorem~\xrefn{thm:solns to second order homogeneous} is a solution to
%the differential equation $\ds ay''+by'+cy=0$.
%\end{ex}
%
%%%%%%%%%%%
%\begin{ex}
 %Verify that the function in part (c) of
%theorem~\xrefn{thm:solns to second order homogeneous} is a solution to
%the differential equation $\ds ay''+by'+cy=0$.
%\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem $\ds y''-\omega^2y=0$,
$y(0)=1$, $\ds y'(0)=1$, assuming $\omega\not=0$.
\begin{sol}
 $\ds {\omega+1\over2\omega}e^{\omega t}+
{\omega-1\over2\omega}e^{-\omega t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem $\ds2y''+18y=0$,
$y(0)=2$, $\ds y'(0)=15$.
\begin{sol}
 $\ds 2\cos(3t)+5\sin(3t)$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''+6y' +5y=0$,
$y(0)=1$, $\ds y'(0)=0$.
\begin{sol}
 $\ds -(1/4)e^{-5t}+(5/4)e^{-t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''-y'-12y=0$,
$y(0)=0$, $\ds y'(0)=14$.
\begin{sol}
 $\ds-2e^{-3t}+2e^{4t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''+12y'+36y=0$,
$y(0)=5$, $\ds y'(0)=-10$.
\begin{sol}
 $\ds 5e^{-6t}+20te^{-6t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''-8y'+16y=0$,
$y(0)=-3$, $\ds y'(0)=4$.
\begin{sol}
 $\ds (16t-3)e^{4t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''+5y=0$,
$y(0)=-2$, $\ds y'(0)=5$.
\begin{sol}
 $\ds -2\cos(\sqrt5t)+\sqrt{5}\sin(\sqrt{5}t)$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''+y=0$,
$y(\pi/4)=0$, $\ds y'(\pi/4)=2$.
\begin{sol}
 $\ds -\sqrt2\cos t+\sqrt2\sin t$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''+12y'+37y=0$,
$y(0)=4$, $\ds y'(0)=0$.
\begin{sol}
 $\ds e^{-6t}\left(4\cos t+24\sin t\right)$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''+6y'+18y=0$,
$y(0)=0$, $\ds y'(0)=6$.
\begin{sol}
 $\ds 2e^{-3t}\sin(3t)$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''+4y=0$,
$y(0)=\sqrt3$, $\ds y'(0)=2$.
%Put your answer in the form developed
%at the end of exercise~\xrefn{example:damped spring oscillation}.
\begin{sol}
 $\ds 2\cos(2t-\pi/6)$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''+100y=0$,
$y(0)=5$, $\ds y'(0)=50$.
%Put your answer in the form developed
%at the end of exercise~\xrefn{example:damped spring oscillation}.
\begin{sol}
 $\ds 5\sqrt2\cos(10t-\pi/4)$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''+4y'+13y=0$,
$y(0)=1$, $\ds y'(0)=1$.
%Put your answer in the form developed
%at the end of exercise~\xrefn{example:damped spring oscillation}.
\begin{sol}
 $\ds \sqrt2 e^{-2t}\cos(3t-\pi/4)$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Solve the initial value problem
$\ds y''-8y'+25y=0$,
$y(0)=3$, $\ds y'(0)=0$.
%Put your answer in the form developed
%at the end of exercise~\xrefn{example:damped spring oscillation}.
\begin{sol}
 $\ds 5e^{4t}\cos(3t+\arcsin(4/5))$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 A mass-spring system $\ds my''+by'+kx$ has
$k=29$, $b=4$, and $m=1$. At time $t=0$ the position is $y(0)=2$ and
the velocity is $y'(0)=1$. Find $y(t)$.
\begin{sol}
 $\ds (2\cos(5t)+\sin(5t))e^{-2t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 A mass-spring system $\ds my''+by'+kx$ has
$k=24$, $b=12$, and $m=3$. At time $t=0$ the position is $y(0)=0$ and
the velocity is $y'(0)=-1$. Find $y(t)$.
\begin{sol}
 $\ds-(1/2)e^{-2t}\sin(2t)$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Consider
%\exrdef{exer:second order really first order}
the differential equation $\ds ay'' + by'=0$,
with $a$ and $b$ both non-zero. Find the general solution by the
method of this section. Now let $\ds g=y'$; the equation may be
written as $\ds ag'+bg=0$, a first order linear homogeneous
equation. Solve this for $g$, then use the relationship $\ds g=y'$ to
find $y$.
\end{ex}

%%%%%%%%%%
\begin{ex}
 Suppose that $y(t)$ is a solution to $\ds ay''+by'+cy=0$, $y(t_0)=0$, $\ds y'(t_0)=0$. Show that $y(t)=0$.
\end{ex}

\end{enumialphparenastyle}


% Copyright 2016 The FANCy Project, licensed under GNU FDL v1.3
% main author:
%   Markus J. Pflaum
%
\section{Some useful inequalities}
\label{sec:useful-inequalities}
%
%
In this section we collect several inequalities from real analysis which will
be of use later in this monograph.
\begin{theorem}[Young's inequality]
\label{thm:Youngs-inequality}
Let $a,b \geq 0$, and assume that $p,q >1$ satisfy the relation $\frac 1p + \frac 1q =1$. Then
\[
   ab \leq \frac 1p a^p + \frac 1q b^q \: .
\]
  Equality holds if and only if $a^p = b^q$.
\end{theorem}
\begin{proof}
Since the second derivative $\exp''$ of the exponential function attains
only positive values, the function $\exp$ is strictly convex that means satisfies
\[
   \exp \big( \lambda x + (1-\lambda) y \big) \leq
   \lambda \exp ( x ) +   (1-\lambda)  \exp ( y )
\]
for all $x,y\in \R$ and $\lambda \in [0,1]$ with equality holding true if and only if $x = y$ or $\lambda \in \{ 1,0 \}$.
Putting $x = p \ln a$, $y = q \ln b$, and $\lambda = \frac 1p$ one obtains
\[
   ab = \exp\big( \lambda x + (1-\lambda) y \big)   \leq
   \lambda \exp ( x ) +   (1-\lambda)  \exp ( y ) = \frac 1p a^p + \frac 1q b^q \: .
\]
Equality holds if and only if $x = y$ which is equivalent to  $a^p = b^q$.
\end{proof}
\begin{theorem}[Cauchy--Schwarz inequality for sums]
\label{thm:Cauchy-Schwartz-inequality-for-sums}
Let $v,w \in \C^n$. Then
\[
  \Big| \sum_{i=1}^n v_i \overline{w_i} \: \Big|^2 \leq \Big( \sum_{i1}^n |v_i|^2 \Big)  \Big( \sum_{i=1}^n |w_i|^2 \Big).
\]
Equality holds true if and only if  $v$ and $w$ are linearly dependant.
\end{theorem}
\begin{proof}
Let us use the \emph{inner product} notation
\[
   \langle v,w\rangle := \sum_{i=1}^n v_i \overline{w_i} \quad \text{for } v,w\in \C^n.
\]
Then the $\ell^2$-\emph{norm}
\[
  \| v \| :=  \left( \sum_{i=1}^n |v_i|^2\right)^{1/2} = \langle v , v \rangle^{1/2}
\]
is well-defined and non-negative for any $v\in \C^n$. If $\|v \| =0$ or $\| w \|= 0$, then $v=0$ or $w=0$, and
the claim is trivial. So we assume $\|v \|, \| w \| > 0$ and compute
\begin{equation}
\label{eq:inequality-chain}
\begin{split}
  0 \leq \, & \big\langle \|w\| v - \|v\| w , \|w\| v - \|v\| w \big\rangle  =
  \sum_{i=1}^n \big( \|w\| v_i - \|v\| w_i \big)\big( \|w\| \overline{v_i} - \|v\| \overline{w_i} \big)  = \\
  = \, &   \sum_{i=1}^n \|w\|^2 v_i\overline{v_i} - \|w\| \|v\| v_i \overline{w_i}  -  \|w\| \|v\| w_i \overline{v_i}
    +  \|v\|^2 w_i\overline{w_i}  = \\
  = \, &  2 \|v\|\|w\| \Big(  \|v\|\|w\| - \Re \langle v,w \rangle \Big) .
\end{split}
\end{equation}
Now choose $c \in \C$ with $|c|=1$ such that $ c \langle  v,w \rangle = |\langle  v,w \rangle|$. Replacing $v$ by $cv$
in inequality \eqref{eq:inequality-chain} and observing that $\|cv \|$ and $ \| w \| $ are positive then entails
\[
  0 \leq \|c v\|\|w\| - \Re \langle c v,w \rangle  =  \|v\|\|w\| - \Re (c \langle v,w \rangle) =
  \|v\|\|w\| -  |\langle  v,w \rangle|,
\]
which is the claimed Cauchy--Schwartz inequality for sums in abbreviated form.

Equality holds true if and only if $\|w\| c v - \|v\| w =0$. So if $\|v\|\|w\| =  |\langle  v,w \rangle| $,
then $v$ and $w$ are linearly dependant. To show the converse, assume that $av =bw$ for some $a,b\in \C$
with $(a,b) \neq (0,0)$. Because we consider  the nontrivial case where both $v$ and $w$ are nonzero, we can
assume without loss of generality that $b=1$. But then
\[ |\langle v,w \rangle |= |\langle v, av \rangle | = |a| \|v\|^2 = \|v\| \, \|w\| \ , \]
hence equality holds in this case. The proof is finished.
\end{proof}

\para
Besides the $\ell^2$-norm on $\C^n$ one has the so-called $\ell^p$-norms
$\| \cdot \| : \C^n \to \R_{\geq 0}$ for $p \geq 1$.
They are defined by
\[
  \| v \|_p = \left( \sum_{k=1}^n |v_k|^p \right)^{1/p} \quad \text{for } v \in \C^n  \ .
\]
The \emph{maximum norm} or $\ell^\infty$-norm $\| \cdot \|_\infty$ is given by
\[
  \| v \|_\infty = \sup \big\{ |v_k| \bigmid k = 1,\ldots , n \big\}  \ .
\]
The $\ell^p$-norms are all norms indeed as we will later see.
\begin{theorem}[H\"older's inequality for sums]
Let $p,q \in [1, \infty )$ such that $\frac 1p + \frac 1q =1$. Then
\[
   \sum_{k=1}^n | v_k w_k | \leq  \| v \|_p \cdot \| w\|_q \quad \text{for all } v,w\in \C^n \ .
\]
\end{theorem}
\begin{proof}
If $p=1$ or $q=1$ the claim is immediate, because then $q=\infty$  or $p=\infty$, respectively,
and  the two estimates
\[
  \sum_{k=1}^n | v_k w_k | \leq  \left( \sum_{k=1}^n | v_k | \right) \cdot
  \sup\big\{ |w_k| \bigmid k = 1,\ldots , n \big\}
\]
and
\[
  \sum_{k=1}^n | v_k w_k | \leq  \left( \sum_{k=1}^n | w_k | \right) \cdot
  \sup \big\{ |v_k| \bigmid k = 1,\ldots , n \big\}
\]
obviously hold. So we can assume $1 < p,q < \infty$. Moreover we can assume that both $v$ and $w$
are nonzero because otherwise the claim is trivial. Now observe that by Young's inequality
\[
  \frac{|v_k|}{\| v \|_p} \cdot \frac{|w_k|}{\| w \|_q} =
  \left(\frac{|v_k|^p}{\| v \|_p^p} \right)^{1/p} \cdot \left(\frac{|w_k|^q}{\| w \|_q^q} \right)^{1/q}
  \leq \frac 1p \frac{|v_k|^p}{\| v \|_p^p} + \frac 1q \frac{|w_k|^q}{\| w \|_q^q} \quad
  \text{for } k=1,\ldots , n\ .
\]
Summing over all $k$ gives
\[
   \sum_{k=1}^n \frac{|v_k|}{\| v \|_p} \cdot \frac{|w_k|}{\| w \|_q} \leq
   \frac 1p  \frac{\|v\|_p^p}{\| v \|_p^p} + \frac 1q \frac{\|w\|_q^q}{\| w \|_q^q} =
   \frac 1p + \frac 1q = 1 \ .
\]
Multiplication of both sides by $ \| v \|_p \cdot \| w\|_q$ entails H\"older's inequality.
\end{proof}

\begin{theorem}[Minkowski's inequality for sums]
Let $p  \in [1, \infty )$. Then
\[
   \| v + w \|_p \leq \| v\|_q + \| w \|_p \quad \text{for all } v,w\in \C^n \ .
\]
\end{theorem}

\begin{proof}
For $p=1$ the claim is trivial, likewise for $p=\infty$. So assume $1  < p <  \infty$
and put $q := \frac{p}{p-1}$. Then $\frac 1p + \frac 1q =1$, and we can apply
H\"older's inequality to compute
\begin{equation*}
  \begin{split}
   \| v + w \|_p^p\, &  =  \sum_{k=1}^n | v_k + w_k|^p \leq
   \sum_{k=1}^n |v_k| \, | v_k + w_k|^{p-1} +  |v_k| \, | v_k + w_k|^{p-1}
   \leq \\
   &\leq  \| v \|_p \cdot \left(  | v_k + w_k|^{(p-1)q} \right)^{1/q} +
   \| w \|_p \cdot \left(  | v_k + w_k|^{(p-1)q} \right)^{1/q}  = \\
   & = \left( \| v \|_p +  \| w \|_p \right) \,  \| v + w \|_p^{p/q} \ .
\end{split}
\end{equation*}
Minkowski's inequality follows.
\end{proof}


%!TEX root =  ../main.tex

\subsection{Real Analysis}

\objective{Apply the basic principles of Analysis to solve improper integral and use hyperreal numbers}

An \textbf{improper integral} is a definite limit where one and/or the other bound is
an infinity.  For example,
$$
\int_0^\infty e^{-x}dx
$$
In this case, we integrate like normal, but take the upper bound to be a limit,
written more simply.  (No one wanted to write a limit on top of an integral!)
$$
\int_0^\infty e^{-x}dx = \left.-e^{-x}\right|_0^\infty = \lim_{x\rightarrow\infty} -e^{-x} - -e^0
$$
The limit approaches 0 while the function evaluates to -1.  We say, therefore, that
the entire integral is assigned a value of 1.  What are we saying?  The area under
an infinite curve is a finite number?  Remarkable.

\subsubsection{Special Functions}
Some functions come up so often in higher mathematics that they are given
their own name, often involving Greek letters.  Many of them have wildly
complicated definitions, and not a few are improper integrals.  One such
function is the Gamma function, which is defined thus:

\begin{equation}
\Gamma(z)=\int_{0}^{\infty}x^{z-1}e^{-x}dx
\end{equation}

We shall see in chapter 14 that there is very common function in math called
\textbf{factorial}.  The Gamma function is the \textbf{analytic continuation} of
the factorial function, such that $\Gamma(n) = (n-1)!$.  This has many uses in
probability theory, allowing us to calculate values in between the integers.

\subsection{Non-Standard Analysis}
When Leibniz and Newton invented Calculus in the mid-17th century, their discoveries were
a culmination of two centuries of fierce debate over the idea of infinitesimals.  Was the
continuum (we might use the were ``number line'' or Reals) made up on indivisible, smallest
elements or not?  Leibniz called the infinitesimals and Newton called them fluxions.
The assumption of their existence had made it possible to grow beyond a dependence
upon Euclid and the Classics, and enabled the ability to make new discoveries in
mathematics, along the lines of Analytic Geometry (the algebra of Geometry).

Unfortunately, Newton and Leibniz did not cultivate a rigor science of infinitesimals,
and later centuries have much preferred the work of Cauchy and Weierstrauss,
because of its consistency and explanatory power.  However, given the antiquity of
the method of \textbf{exhaustion} and current understand of Planck Length,
Planck Time, Planck Mass, etc., this textbook has attempted to keep some measure
of the method of infinitesimals at its core.  These methods were made rigorous in
the 1960s by Abraham Robinson and codified in a system of numbers known as
\textbf{Hyperreal} Numbers, or simply, the Hyperreals.

The hyperreals are an extension of the reals, as the name implies.  We need only
posit two numbers: $\omega$ and $\epsilon$.  $\omega$ (the last letter of the
Greek alphabet, only always lowercase, pronounced oh-MEG-uh or oh-MAY-guh)
is analogous to infinity as most people think of it.  Infinity is \emph{supposed}
to be a concept, not a number, the idea of going on without end.  $\omega$ is
a number bigger than any real number, just smaller than infinity.  $\epsilon$ is
its reciprocal, a positive number smaller than any real number but not zero.

This leads to a system where numbers may be composed of two (even three)
parts.  For example, $3+2\epsilon$ may not be simplified any further.  But
$\omega(3+2\epsilon)$ can be: $3\omega + 2$.  What good is such an arbitrary,
new system.  Well actually, its quite old and caused the invention of calculus!

\subsubsection{Old Definitions}
The Difference Quotient can be stated without limits using hyperreals as
\begin{equation}
f'(x) = \frac{f(x+\epsilon) - f(x)}{x+\epsilon -x}  \outnote{(Hyperreal Difference Quotient)}
\end{equation}

$e$ can be stated without limits as follows:
\begin{equation}
e = (1+\epsilon)^\omega  \outnote{(Hyperreal Definition of $e$)}
\end{equation}

\subsubsection{Derivative}
Let us do one example, with several others in the exercises, finding the derivative of
$x^2$.
$$
(x^2)' = \frac{(x+\epsilon)^2-x^2}{\epsilon} = \frac{x^2+2x\epsilon+\epsilon^2-x^2}{\epsilon}
= 2x+\epsilon
$$
Unlike limits notation, the infinitesimal does not disappear.  Every $\epsilon$ step in
the $x$-direction produces a jump of $2x$ in the $y$-direction.  According to quantum
mechanics (and Zeno's Paradox), the jumps are done without intervening steps,
that at the smallest level, elementary particles proceed in a way quite unlike
our macroscopic world.


\documentclass[main.tex]{subfiles}
\begin{document}

\marginpar{Tuesday\\ 2020-11-3, \\ compiled \\ \today}

A \textbf{stationary distribution} for a Markov Chain is a probability distribution \(p(\vec{x})\) for \(\vec{x}\) in \(\Omega \) such that the following property holds:
%
\begin{align}
p(\vec{y}) = \sum _{\vec{x} \in \Omega} \mathbb{P}(\vec{y} | \vec{x}) p(\vec{x})
\,,
\end{align}
%
where \(\mathbb{P}(\vec{y} | \vec{x})\) is the transition probability from \(\vec{x}\) to \(\vec{y}\): the probability that we are in \(\vec{y}\), given that we were in \(\vec{x}\) at the previous step.
What this means is that after a step in the chain leaves \(p(\vec{x})\) unchanged.

In terms of the transition matrix, the problem reads \(p_i = T_{ij} p_j\), so \(p_i\) is an eigenvector of \(T_{ij}\) with eigenvalue \(1\).

In our case, we want to build a MC which converges to a stationary probability distribution which is our posterior.
So, first we need to ask whether this can be done, and then how long it takes for us to converge to that distribution.

\begin{theorem}
    A finite, ergodic Markov chain has a unique stationary distribution.
\end{theorem}

A state has \textbf{period} \(k\) if any return to it requires a multiple of \(k\) steps. Formally,
%
\begin{align}
k(\vec{x}) =  \gcd \qty{ n \in \mathbb{N}: \text{the probability of returning from \(\vec{x}\) to \(\vec{x}\) in \(n\) steps is } >0}
\,.
\end{align}
%

If \(k=1\) the state is aperiodic.
If a MC is ergodic and one state is aperiodic then all states are.

A state is \textbf{recurrent} if with probability 1 we will return to it at some point if we leave it.
It is called \textbf{transient} otherwise.

A recurrent state is \textbf{positive recurrent} if the expected return time is finite; \textbf{null recurrent} if it diverges.

\begin{theorem}
    A finite, ergodic, positive recurrent, aperiodic Markov Chain converges to its stationary distribution as \(n \to \infty \).
\end{theorem}

So, eventually convergence is ensured, but we must also design a MC which converges \emph{quickly}.

Let us now give a practical example, with \(\Omega = \qty{A, B, C}\).
The transition matrix is
%
\begin{align}
T_{ij} =
\left[\begin{array}{ccc}
\num{.25} & \num{.5} & \num{0.25} \\
0 & \num{.5} & \num{.5} \\
\num{.33} & \num{.33} & \num{.34}
\end{array}\right]
\,,
\end{align}
%
as required all the rows are normalized to one.
The initial condition is given by \(q_0 = [0, \num{.5}, \num{.5}]\).

The following steps can be calculated as \(q_n = q_0 (T^{n}) \).

Let us define \(m(s_i, s_j)\) as the mean time to go from \(s_i\) to \(s_j\). How do we compute it? We need to make sure that it is finite.
Let us fix a state, say \(C\). What is \(m(C, C)\)?

Suppose that the first step is from \(C\) to \(B\). Then, we will have \(m(C,C) = 1 + m(B, C)\). Similarly, if we go from \(C\) to \(A\) we have \(m(C, C) = 1 + m(A, C)\); while if we jump directly to \(C\) we have \(m(C, C) =1\).

The overall recurrence time is obtained by integrating over all the possibilities:
%
\begin{align}
m(C, C) &=
\mathbb{P}(C | A) \qty[1 + m(A, C)] +
\mathbb{P}(C | B) \qty[1 + m(B, C)]
+  \mathbb{P}(C | C)  \\
&=
\underbrace{\mathbb{P}(C |A ) +
\mathbb{P}(C |B) +
\mathbb{P}(C |C )}_{1} +
\mathbb{P}(C |A ) m(A, C) +
\mathbb{P}(C |B ) m(B, C) +
\,.
\end{align}

We can do a similar thing for the other recurrence times, this yields a linear system we can solve, in terms of the three unknowns \(m(*, C)\).
In this case we get \(m(C, C) = \num{2.54}\), \(m(B, C) = \num{2.0}\), \(m(A,C) = \num{2.67}\).

Therefore, this MC will admit a stationary distribution and converge to it.\footnote{Check out the convergence by downloading the notebook at \url{https://github.com/jacopok/notes/blob/master/ap_third_semester/astrostatistics_cosmology/figures/markov.ipynb}!}
We can calculate it through the left eigenvalue problem \(\pi = \pi T\).

A Markov Chain is \textbf{reversible} if there exists a probability distribution \(\pi \) such that \(\mathbb{P}(x | y) \pi (y) = \mathbb{P}(y | x) \pi (x)\).
This is called the \textbf{detailed balance} equation, and if it holds it tells us that \(\pi \) is the stationary distribution of the Markov chain: if we sum over \(y\) we get
%
\begin{align}
\sum _{y} \mathbb{P}(x | y) \pi (y) = \sum _{y} \mathbb{P}(y | x) \pi (x)
= \pi (x) \sum _{y} \mathbb{P}(y | x ) = \pi (x)
\,,
\end{align}
%
which is precisely the stationarity condition.

\subsection{Metropolis-Hastings}

Suppose we have a posterior \(p(\vec{\theta})\), in terms of a parameter vector \(\vec{\theta}\).

The current state is denoted as
%
\begin{align}
X_\theta = \qty(\theta_{1, t },  \dots, \theta_{n, t})
\,.
\end{align}

We choose a transition distribution \(Q\);
this can be some easy-to-sample distribution of our choosing.

Then, the new state is \textbf{proposed} by updating the old position
%
\begin{align}
Y \sim Q ( \cdot | X_t)
\,,
\end{align}
%
and choose to accept it or reject it depending on the following: we draw a uniform variable, and accept with probability
%
\begin{align}
\alpha (X_{t+1} = y | X_t = x) =
\min \qty{ \frac{\mathscr{L}(\vec{y})}{\mathscr{L}(\vec{x})} \frac{Q(\vec{x} | \vec{y})}{Q(\vec{y} | \vec{x})}, 1}
\,.
\end{align}

Simply put, we favor steps which move us in a region of higher likelihood.
The ratio of the \(Q\)s might well go away if we choose a symmetric transition matrix.

This satisfies the detailed balance equation: let us show it.
One side of the equation reads
%
\begin{align}
\underbrace{\alpha (\vec{y} | \vec{x}) Q (\vec{y} | \vec{x})}_{\text{transition probability}} p(\vec{x})
&= \min \qty{\frac{\mathscr{L}(\vec{y})}{\mathscr{L}(\vec{x})}
\frac{Q(\vec{x} | \vec{y})}{Q(\vec{y} | \vec{x})}, 1} Q(\vec{y} | \vec{x}) p(\vec{x})  \\
&= \min \qty{Q(\vec{x} | \vec{y}) \mathscr{L}(\vec{y}), Q(\vec{y} | \vec{x}) \mathscr{L}(\vec{x})} \mathscr{L} (\vec{x} )
\,,
\end{align}
%
\todo[inline]{check calculation}

We apply Bayes' theorem\dots
Finally, we show that
%
\begin{align}
\alpha (\vec{y} | \vec{x}) Q (\vec{y} | \vec{x}) p(\vec{x})
= \alpha (\vec{x} | \vec{y}) Q(\vec{x} | \vec{y}) p(\vec{y})
\,.
\end{align}

\end{document}


\subsection{Topological vector spaces}\label{subsec:topological_vector_spaces}

\begin{definition}\label{def:topological_vector_space}
  Let \( X \) be any vector space and let \( \mscrT \) be a topology on \( X \). The space \( (X, +, \cdot, \mscrT) \) is called a \term{topological vector space} if the linear and topological structure agree, that is, the operations \( +: X \times X \to X \) and \( \cdot: X \times \BbbR \to X \) are continuous with respect to \( \mscrT \).

  Both the additive group \( (X, +) \) and the multiplicative group \( (X \setminus \{ 0 \}, \cdot) \) are \hyperref[def:topological_group]{topological groups}. We regard \( X \) as a subgroup of its additive topological group.

  See \fullref{rem:hausdorff_topological_groups}, \fullref{def:continuous_dual_space} and \fullref{def:category_of_topological_vector_spaces} for more nuances.
\end{definition}

Given that a topological vector space \( X \) has both a topological and an algebraic structure, we should adapt certain definitions.

\begin{definition}\label{def:continuous_dual_space}
  We define the \term{continuous dual space} \( X^* \) of a topological space \( X \) as the vector space of all \hyperref[def:global_continuity]{continuous} linear functionals. This differs drastically from \fullref{def:dual_vector_space} because in the general case, the continuous dual space may be trivial, i.e. only contain the zero functional. See \fullref{def:locally_convex_duality_pairing}.

  We use the same notation for both the algebraic dual spaces and the continuous dual space because the meaning is usually clear from the context. In particular, hyperplanes as defined in \fullref{def:hyperplane} are only relevant to continuous linear functionals.
\end{definition}

\begin{definition}\label{def:category_of_topological_vector_spaces}
  The category \( \cat{TopVect}_{\BbbK} \) of topological vector spaces over \( \BbbK \) is a subcategory of both \( \cat{Top} \) and \( \cat{Vect}_K \). Its morphisms are the \hyperref[def:global_continuity]{continuous} linear \hyperref[def:linear_operator]{maps}.
\end{definition}

\begin{remark}\label{rem:origin_neighborhoods_in_topological_vector_spaces}
  As in \fullref{rem:origin_neighborhoods_in_topological_groups}, we are only interested in neighborhoods of the origin \( 0 \) since any neighborhood \( U \) of \( x \) is simply a translation of the neighborhood \( U - x \) of the origin.
\end{remark}

\begin{proposition}\label{thm:topological_vector_space_is_uniform}
  A Hausdorff topological vector space \( X \) is a uniform space with the families of entourages
  \begin{balign*}
     & V_A \coloneqq \{ (x, y) \in X \times X \colon x - y \in A \},
  \end{balign*}
  where \( A \) is a \hyperref[def:neighborhood_set_types/symmetric]{symmetric} neighborhood of the origin \( 0 \).
\end{proposition}
\begin{proof}
  Follows from \fullref{thm:topological_group_uniform_space}.
\end{proof}

\begin{proposition}\label{thm:linearity_of_sequence_limits}
  If \( \{ a_\alpha \}_{\alpha \in \mscrK} \) and \( \{ b_\alpha \}_{\alpha \in \mscrK} \) are \hyperref[def:topological_net]{nets} in a Hausdorff topological vector space \( X \) that converge to \( a \) and \( b \), correspondingly, then
  \begin{thmenum}
    \thmitem{thm:linearity_of_sequence_limits/addition} \( a_\alpha + b_\alpha \to a + b \).
    \thmitem{thm:linearity_of_sequence_limits/scalar_multiplication} \( \lambda a_\alpha \to \lambda a \) for any scalar \( \lambda \in \BbbK \).
  \end{thmenum}
\end{proposition}
\begin{proof}
  Fix a neighborhood \( U \) of \( 0 \) and fix an index \( \alpha_0 \) such that for \( \alpha \geq \alpha_0 \) we have both \( a - a_\alpha \in U \) and \( b - b_\alpha \in U \).

  \SubProofOf{thm:linearity_of_sequence_limits/addition} For addition, we have
  \begin{equation*}
    (a + b) - (a_\alpha + b_\alpha) = (a - a_\alpha) + (b - b_\alpha) \in 2U.
  \end{equation*}

  \SubProofOf{thm:linearity_of_sequence_limits/scalar_multiplication} For scalar multiplication, we have
  \begin{equation*}
    \lambda a - \lambda a_\alpha \in \lambda U.
  \end{equation*}

  In both cases the containing neighborhood does not depend on \( \alpha \), hence the nets converge to their desired values.
\end{proof}

\begin{corollary}\label{thm:linearity_of_function_limits}
  If \( f, g: X \to Y \) are continuous functions between topological vector spaces, then for any point \( x_0 \in X \) we have
  \begin{equation*}
    \lim_{x \to x_0} (f(x) + g(x)) = \lim_{x \to x_0} f(x) + \lim_{x \to x_0} g(x)
  \end{equation*}
  and for any \( \lambda \in \BbbK \)
  \begin{equation*}
    \lim_{x \to x_0} \lambda f(x) = \lambda \lim_{x \to x_0} f(x).
  \end{equation*}
\end{corollary}

\begin{definition}\label{def:locally_convex_space}\mcite[1.8]{Rudin1991Functional}
  We say that a \hyperref[def:topological_vector_space]{topological vector space} is \term{locally convex} if there exists a \hyperref[def:topological_base]{topological base} of \hyperref[def:convex_set]{convex} sets.
\end{definition}

\begin{remark}\label{def:locally_convex_duality_pairing}
  Given a Hausdorff locally convex space \( X \), \fullref{thm:hahn_banach_implies_functionals_vanish_nowhere} shows that the canonical duality pairing as defined in \fullref{def:locally_convex_duality_pairing} is nondegenerate. If the space is not locally convex, we cannot guarantee that the pairing will be nondegenerate and our restriction to continuous linear functionals could interfere with our habits of working with linear functionals.
\end{remark}

\begin{definition}\label{def:sublinear_functional}
  We say that \( f: X \to \BbbR \) is a \term{sublinear functional} if it satisfies
  \begin{thmenum}
    \thmitem{def:sublinear_functional/subadditivity}(subadditivity) \( f(x + y) \leq f(x) + f(y) \) for any \( x, y \in X \).
    \thmitem{def:sublinear_functional/positive_homogeneity}(positive homogeneity) \( f(tx) \leq t f(x) \) for any \( t > 0 \) and \( x \in X \).
  \end{thmenum}

  Compare this definition to \fullref{def:linear_operator}.
\end{definition}


This appendix describes the equations for handling the cross-sections in different sections of this thesis.

\section{Group constants homogenization}
\label{appendix:group-const-homo}

% duderstadt 10-17 and stacey 14.56
The following relations homogenize the group constants over a certain volume $V_T$ \cite{duderstadt_nuclear_1976}

\begin{align}
  & \phi_{g, T} = \frac{\sum_i \phi_{g, i} V_i}{V_T}  \\
  & \Sigma^t_{g, T} = \frac{\sum_i \Sigma^t_{g, i} \phi_{g, i} V_i}{\phi_g V_T}  \\
  & \nu\Sigma^f_{g, T} = \frac{\sum_i \nu\Sigma^f_{g, i} \phi_{g, i} V_i}{\phi_g V_T}  \\
  & \Sigma^s_{g'\rightarrow g, T} = \frac{\sum_i \Sigma^s_{g'\rightarrow g, i} \phi_{g, i} V_i}{\phi_g V_T}  \\
  & \chi^t_{g, T} = \frac{\sum_i \chi^t_{g, i} \nu\Sigma^f_{g, i} \phi_{g, i} V_i}{\nu\Sigma^f_g \phi_g V_T}  \\
  & D_{g, T} = \frac{\sum_i D_{g, i} \phi_{g, i} V_i}{\phi_g V_T}
\intertext{where}
  & \phi_{g, i} = \mbox{group $g$, region $i$ neutron flux } [n \cdot cm^{-2} \cdot s^{-1}] \notag \\
  & V_i = \mbox{region $i$ volume } [cm^{3}] \notag \\
  & V_T = \mbox{total volume where the homogenization takes place } [cm^{3}] \notag \\
  & \Sigma^t_{g, i} = \mbox{group $g$, region $i$ macroscopic total cross-section } [cm^{-1}] \notag \\
  & \nu = \mbox{number of neutrons produced per fission } [-] \notag \\
  & \Sigma^f_{g, i} = \mbox{group $g$, region $i$ macroscopic fission cross-section } [cm^{-1}] \notag \\
  & \Sigma^s_{g'\rightarrow g, i} = \mbox{group $g'$ to group $g$, region $i$ macroscopic scattering cross-section } [cm^{-1}] \notag \\
  & \chi^t_{g, i} = \mbox{group $g$, region $i$ total fission spectrum } [-] \notag\\
  & D_{g, i} = \mbox{group $g$, region $i$ diffusion coefficient } [cm]. \notag
\end{align}

\section{Group constants condensation}
\label{appendix:group-const-condense}

% duderstadt 7-54 and tsoulfiniadis 5.12
The following equations collapse the group constants \cite{duderstadt_nuclear_1976}
\begin{align}
  & \phi_{h} = \sum_g \phi_{g} \\
  & \chi_{h}^t = \sum_g \chi_g^t \\
  & D_{h}^t = \frac{\sum_g D_g^t \phi_{g}}{\phi_{g'}} \\
  & \Sigma_{h}^t = \frac{\sum_g \Sigma_g^t \phi_{g}}{\phi_{g'}} \\
  & \nu\Sigma_{h}^f = \frac{\sum_g \nu\Sigma_g^f \phi_{g}}{\phi_{g'}} \\
  & \Sigma_{h'\rightarrow h}^s = \frac{\sum_{g'} \sum_{g} \Sigma_{g'\rightarrow g}^s \phi_{g'}}{\phi_{h'}}
  \intertext{where}
  & \phi_g = \mbox{group $g$ neutron flux } [n \cdot cm^{-2} \cdot s^{-1}] \notag \\
  & \chi_g^t = \mbox{group $g$ total fission spectrum } [-] \notag\\
  & D_g = \mbox{group $g$ diffusion coefficient } [cm] \notag \\
  & \Sigma_g^t = \mbox{group $g$ macroscopic total cross-section } [cm^{-1}] \notag \\
  & \nu = \mbox{number of neutrons produced per fission } [-] \notag \\
  & \Sigma_g^f = \mbox{group $g$ macroscopic fission cross-section } [cm^{-1}] \notag \\
  & G = \mbox{original number of energy groups } [-] \notag \\
  & H = \mbox{new number of energy groups } [-] \notag \\
  & \Sigma_{g'\rightarrow g}^s = \mbox{group $g'$ to group $g$ macroscopic scattering cross-section } [cm^{-1}]. \notag
\end{align}

\section{Benchmark group constants}
\label{appendix:group-const-bench}

The benchmark specifies the following group constants: the normalized neutron flux $\phi_g$, the total fission spectrum $\chi_g^t$, the diffusion coefficient $D_g$, the macroscopic total cross-section $\Sigma_g^t$, number of neutrons produced per fission by the macroscopic fission cross-section $\nu\Sigma_g^f$, the macroscopic fission cross-section $\Sigma_g^f$, and the macroscopic scattering cross-section $\Sigma_{g'\rightarrow g}^s$.

Moltres solves equation \ref{eq:app-eigenvalue}, and requires the following group constants: the diffusion coefficient $D_g$, the macroscopic removal cross-section $\Sigma_g^r$, the macroscopic scattering cross-section $\Sigma_{g'\rightarrow g}^s$, the total fission spectrum $\chi_g^t$, and the number of neutrons produced per fission by the macroscopic fission cross-section $\nu\Sigma_g^f$.

% duderstadt 7-23
Equation \ref{eq:app-removal} calculates the removal cross-section \cite{duderstadt_nuclear_1976}
\begin{align}
% \Sigma_{r,g} &= \Sigma_{a,g} + \sum_{g' \ne g} \Sigma_{s,g \rightarrow g'} = \Sigma_{t,g} - \Sigma_{s, g \rightarrow g} \label{eq:app-removal}
\Sigma_{r,g} &= \Sigma_{t,g} - \Sigma_{s, g \rightarrow g}. \label{eq:app-removal}
\end{align}


\subsection{2017 Free-Response Questions}
Questions 1 and 2 are part of the same section and are allotted 30 minutes for completion with the aid of a graphing calculator.
Questions 3 through 6 are part of the same section and are allotted 1 hour for completion without the aid of a graphing calculator.

\begin{table}[H]
	\begin{center}
		\begin{tabular}{|c||c|c|c|c|}
			\hline
			$h$ (feet) & 0 & 2 & 5 & 10 \\
			\hline
			$A(h)$ (square feet) & 50.3 & 14.4 & 6.5 & 2.9 \\
			\hline
		\end{tabular}
	\end{center}
\end{table}

\begin{enumerate}

	\item A tank has a height of 10 feet.
		The are of the horizontal cross section of the tank at $h$ feet is given by the function $A$, where $A(h)$ is measured in square feet.
		The function $A$ is continuous and decreases as $h$ increases.
		Selected values for $h$ are given in the table above.
		\begin{enumerate}
			\item Use a left Riemann sum with three subintervals indicated by the data to approximate the volume of the tank.
				Indicate units of measure.
			\item Does the approximate in part (a) overestimate or underestimate the volume of the tank?
				Explain your reasoning.
			\item The area, in square feet, of the horizontal cross section at height $h$ feet is modeled by the function $f$ given by $f(h)=\frac{50.3}{e^{0.2h}+h}$.
				Based on this model, find the volume of the tank.
				Indicate units of measure.
			\item Water is pumped into the tank.
				When the height of the water is 5 feet, the height is increasing at a rate of 0.26 foot per minute.
				Using the model from part (c), find the rate at which the volume of water is changing with respect to time when the height of the water is 5 feet.
				Indicate units of measure.
		\end{enumerate}

	\begin{figure}[H]
		\label{2017_2}
		\centering
		\includegraphics{./additional_materials/2017_2.png}
		\caption{\hyperref{https://apcentral.collegeboard.org/pdf/ap-calculus-bc-frq-2017.pdf}{}{}{AP Calculus BC 2017 Exam Free-Response Question 2}}
	\end{figure}

	\item The figure above show the polar curves $r=f(\theta)=1+\sin{\theta}\cos{(2\theta)}$ and $r=g(\theta)=2\cos{\theta}$ for $0 \leq \theta \leq \frac{\pi}{2}$.
		Let $R$ be the region in the first quadrant bounded by the curve $r=f(\theta)$ and the $x$-axis.
		Let $S$ be the region in the first quadrant bounded by the curve $r=f(\theta)$ the curve $r=g(\theta)$, and the $x$-axis.
		\begin{enumerate}
			\item Find the area of $R$.
			\item The ray $\theta = k$, where $0 < k < \frac{\pi}{2}$, divides $S$ into two regions of equal area.
				Write out, but do not solve, an equation involving one or more integrals whose solution gives the value of $k$.
			\item For each $\theta$, $0 \leq \theta \leq \frac{\pi}{2}$, let $w(\theta)$ be the distance between the points with polar coordinates $(f(\theta),\theta)$ and $(g(\theta),\theta)$.
				Write an expression for $w(\theta)$.
				Find $w_A$, the average value of $w(\theta)$ over the interval $0 \leq \theta \leq \frac{\pi}{2}$.
			\item Using the information given from part (c), find the value of $\theta$ for which $w(\theta)=w_A$.
				Is the function $w(\theta)$ increasing or decreasing at that value of $\theta$?
				Give a reason for your answer.
		\end{enumerate}

	\begin{figure}[H]
		\label{2017_3}
		\centering
		\includegraphics{./additional_materials/2017_3.png}
		\caption{\hyperref{https://apcentral.collegeboard.org/pdf/ap-calculus-bc-frq-2017.pdf}{}{}{AP Calculus BC 2017 Exam Free-Response Question 3, Graph of $f^\prime$}}
	\end{figure}

	\item The function $f$ is differentiable on the closed interval $[-6,5]$ and satisfies $f(-2)=7$.
		The graph of $f^\prime$, the derivative of $f$, consists of a semicircle and three line segments, as shown in the figure above.
		\begin{enumerate}
			\item Find the values of $f(-6)$ and $f(5)$.
			\item On what intervals is $f$ increasing?
				Justify your answer.
			\item Find the absolute minimum value of $f$ on the closed interval $[-6,5]$.
				Justify your answer.
			\item For each of $f^{\prime\prime}(-5)$ and $f^{\prime\prime}(3)$, find the value or explain why it doesn't exist.
		\end{enumerate}

	\item At time $t=0$, a boiled potato is taken from a pot on a stove and left to cool in a kitchen.
		The internal temperature of the potato is 91 degrees Celsius ($^\circ C$) at time $t=0$, and the internal temperature of the potato is greater than $27^\circ C$ for all time $t > 0$.
		The internal temperature of the potato at time $t$ minutes can be modeled by a function $H$ that satisfies the differential equation $\dd{H}{t} = -\frac{1}{4}(H-27)$, where $H(t)$ is measured in degrees Celsius and $H(0)=91$.
		\begin{enumerate}
			\item Write an equation for the line tangent to the graph of $H$ at $t=0$.
				Use this equation to approximate the internal temperature of the potato at time $t=3$.
			\item Use $\dd{^2H}{t^2}$ to determine whether your answer in part (a) is an underestimate or overestimate of the internal temperature of the potato at time $t=3$.
			\item For $t<10$, an alternate model for the internal temperature of the potato at time $t$ minutes is the function $G$ that satisfies the differential equation $\dd{G}{t} = -(G-27)^{2/3}$, where $G(t)$ is measured in degrees Celsius and $G(0)=91$.
				Based on this model, what is the internal temperature of the potato at time $t=3$?
		\end{enumerate}

	\item Let $f$ be the function defined by $f(x) = \frac{3}{2x^2-7x+5}$.
		\begin{enumerate}
			\item Find the slope of the tangent line of the graph of $f$ at $x=3$.
			\item Find the $x$-coordinate of each critical point of $f$ in the interval $1 < x < 2.5$.
				Classify each critical point as the location of a relative minimum, a relative maximum, or neither.
				Justify your answer.
			\item Using the identity that $\frac{3}{2x^2-7x+5} = \frac{2}{2x-5} - \frac{1}{x-1}$, evaluate $\int_{5}^{\infty}{f(x)\d{x}}$ or show that the integral diverges.
			\item Determine whether the series $\sum_{n=5}^{\infty}{\frac{3}{2n^2-7n+5}}$ converges or diverges.
				State the conditions of the test used for determining convergence or divergence.
		\end{enumerate}

	\begin{align*}
		f(0) &= 0 \\
		f^\prime(0) &= 1 \\
		f^{(n+1)}(0) &= -n\cdot f^{(n)}(0) \text{ for all } n \geq 1
	\end{align*}

	\item A function $f$ has derivatives of all order for $-1 < x < 1$.
		The derivatives of $f$ satisfy the conditions above.
		The Maclaurin Series for $f$ converges to $f(x)$ for $\abs{x} < 1$.
		\begin{enumerate}
			\item Show that the first four non-zero terms of the Maclaurin series for $f$ are $x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4}$, and write the general term for the Maclaurin series for $f$.
			\item Determine whether the Maclaurin series described in part (a) converges absolutely, converges conditionally, or diverges at $x=1$.
				Explain your reasoning.
			\item Write the first four nonzero terms and the general term for the Maclaurin series for $g(x) = \int_{0}^{x}{f(t)\d{t}}$.
			\item Let $P_n\left(\frac{1}{2}\right)$ represent the $n$th degree Taylor polynomial for $g$ about $x=0$ and evaluated at $x=\frac{1}{2}$, where $g$ is the function defined in part (c).
				Use the alternating series error bound to show that
				\begin{equation*}
					\biggr\lvert P_4\left(\frac{1}{2}\right) - g\left(\frac{1}{2}\right) \biggr\rvert < \frac{1}{500}.
				\end{equation*}
		\end{enumerate}

\end{enumerate}


% BASIC SETTINGS
\documentclass[a4paper,12pt]{article} % Set paper size and document type
\usepackage{lmodern} % Use a slightly nicer looking font
\usepackage{enumitem} % Allow lists to pick up numbering where the last list left off

% Change margins - default margins are too broad
\usepackage[margin=20mm]{geometry}

% PREPARE TITLE
\title{\textbf{Homework \#2 - Binary Numbers}}
\author{Name: }
\date{} % Hide the date

% START DOCUMENT
\begin{document}

\maketitle % Insert the title

\section{Intro}

If we want to write good computer programs, we need to understand a little bit about the inner workings of computers. All modern computers use electronic devices to store and manipulate data and programs. To help make them simpler, these devices are built to work with only two voltages, an "ON" and an "OFF" voltage (usually 0V and 3.3V or 0V and 5V). Because of this, all data in the computer is represented using the numbers "0" and "1" (the 0 is the "OFF" state and the 1 is the "ON" state). Everything, and I mean \textbf{everything} that the computer can do is done using only these two numbers. Videos, text, pictures, and computer programs themselves are all stored inside the computer as sequences of ones and zeros. We have to understand how these numbers work (how to do math with them, compare them etc...) in order to write good computer programs. I have introduced you to binary, decimal, and hexadecimal numbers in class before. This homework tests your ability to understand and convert between these three types of numbers.

\section{Binary Conversion}

Convert the following numbers into binary (\textbf{hint}: use the repeated division method we talked about in class):

\begin{enumerate}
\item $45_{10} = $
\item $255_{10} = $
\item $0_{10} = $
\item $36_{10} = $
\end{enumerate}

\noindent
What would happen if you tried to convert 256 into an 8-bit binary number? Can you do this or do you need more than 8 bits?

\section{Binary to Decimal Conversion}

Convert the following binary numbers into decimal:

\begin{enumerate}[resume]
\item $101_{2} = $
\item $00001111_{2} = $
\item $10000000_{2} = $
\item $10101010_{2} = $
\end{enumerate}

\section{Addition for positive numbers}

\noindent
Add these binary numbers together:

\begin{enumerate}[resume]
\item $1010_{2} + 0010_{2} = $
\item $0010_{2} + 1110_{2} = $
\item $11110010_{2} + 00101110_{2} = $
\end{enumerate}

\noindent
Think about what happens if you try to add two 8-bit numbers together and the result uses more than 8-bits. What will the computer do?

\section{Forming the two's complement}

In the computer, positive and negative numbers are \textbf{not} stored using the "sign magnitude" form we are used to, where a number has a + or - in front to show its sign. Instead, negative numbers in binary are represented by forming the "two's complement" of a positive number with the correct magnitude (size). For instance, in binary the number "5" is represented by "101" or if our computer uses 8-bit memory, "00000101". That is the same as "+5". How do we make "-5"? We have to change all of the "1"s to "0"s and then add an additional "1" to the number. Like this:

$$00000101_{2} \rightarrow 11111010_{2} + 1_{2} \rightarrow 11110101_{2}$$

\noindent
So "-5" is actually represented by "11110101". You try! Convert the following \textbf{negative} decimal numbers to their negative binary equivalents:

\begin{enumerate}[resume]
\item $-45_{10} = $
\item $-255_{10} = $
\item $-0_{10} = $
\item $-36_{10} = $
\end{enumerate}

\noindent
\textbf{Hint:} Since these are the same decimal numbers you converted to binary at the beginning of the homework, you can use the binary conversions you already did to form the two's complement. What happens when you form the two's complement of 0? Does this seem like the right behavior?

\section{Representing fractions}

In decimal or base 10 numbers, a fraction like 0.255 is represented as:

$$2 \cdot 10^{-1} + 5 \cdot 10^{-2} + 5 \cdot 10^{-3}$$

\noindent
You can see that it's the same system we use for representing integers (225, 34) but with negative exponents. We can do this with binary numbers as well. For instance 0000.1000 in binary would convert to the following decimal number:

$$1 \cdot 2^{-1} + 0 \cdot 2^{-2} + 0 \cdot 2^{-3} + 0 \cdot 2^{-4} = $$
$$0.5 + 0 + 0 + 0 = 0.5$$

\clearpage

\noindent
So $0.1_{2} = 0.5_{10}$. Try it yourself for the following numbers:

\begin{enumerate}[resume]
\item $0000.1010_{2} = $
\item $0000.0010_{2} = $
\item $1010.0101_{2} = $
\item $1100.0011_{2} = $
\end{enumerate}

\noindent
Now try to go the other way!

\begin{enumerate}[resume]
\item $0.5_{10} = $
\item $0.1_{10} = $
\item $2.5_{10} = $
\item $45.25_{10} = $
\end{enumerate}

\noindent
Notice that some numbers do not have an exact representation when you convert them from one base to another. 0.1 in decimal has no exact representation in base 2 because it repeats forever!

\section{Understanding Hexadecimal}

Converting between bases is easier when they share the relationship $R_{1} = R_{2}^K$. This is the case for base 2 and base 16 where $16 = 2^4$, and because of this base 16 is a popular way to represent numbers when talking about computer systems. Hexadecimal numbers are shorter than their binary equivalents which makes them easier to read and write, and there's a lower chance of making mistakes when writing them. In hexadecimal, there are actually 16 different symbols instead of the 10 (0 to 9) we use in decimal. In hexadecimal, the first 10 digits are represented by the numbers 0 to 9 just like in decimal, but the last 6 digits are represented by the letters A to F, where A = 10, B = 11, ...up to F = 15\\

\noindent
Because the bases are closely related, you can easily convert to and from hexadecimal and binary almost just by looking at a number. Each hexadecimal digit represents 4 binary digits, so the number A in hex would be 1010 in binary, or 10 in decimal. The number F is decimal 15 or 1111, so FF would be 11111111, and so on... Try it yourself for the numbers below:

\begin{enumerate}[resume]
\item $FE_{16} = $
\item $FF_{16} = $
\item $DEAD_{16} = $
\item $ABCD_{16} = $
\end{enumerate}

\noindent
Now try to go the other way, converting into hexadecimal (note if a binary number does NOT break evenly into groups of 4 digits, just add zeros on the left side of the number until it does!):

\begin{enumerate}[resume]
\item $1010_{2} = $
\item $0010_{2} = $
\item $001_{2} = $
\item $10101111_{2} = $
\end{enumerate}

\end{document}


\subsection*{Observations}

1. Problem Formulation: the Networked Cournot Game can be described by the following set of constrained optimization problems (ref. Equation (5) of \citep{Yi_2019}, note the difference in the last inequality constraints):
\begin{equation}
\label{eq:original_problem}
\def\arraystretch{1}
\begin{array}{rl}
\min & g(x_i) = f_i(x_i, \mathbf{x}_{-i}) = c_i(x_i) - (P(Ax))^TA_ix_i \\
\text{s.t.} & x_i \in \Omega_i \subsetneq \mathbb{R}^{n_i} \\
& Ax \leqslant r
\end{array}
\qquad i = 1, \ldots, N
\end{equation}
where
\begin{align*}
& c_i: \Omega_i \to \mathbb{R} \text{ is the local production cost function,} \\
& P: \mathbb{R}^m \to \mathbb{R}^m \text{ maps the total supply of each market to its corresponding price,}
\end{align*}
$A = [A_1, \ldots, A_N]$, $x = \operatorname{col}(x_1, \ldots, x_N)$, $Ax = \sum\limits_{1 \leqslant j \leqslant N} A_jx_j$, $\Omega_i$ the feasible set of $x_i$, usually a rectangle in the Euclidean space. The last constraint is called the shared affine coupling constraint.

This set of optimization problems can be reformulated as unconstrained optimization problems:
\begin{equation}
\label{eq:reformulated_problem}
\begin{array}{rl}
\min & g_i(x_i) + \langle \lambda_i, r-Ax \rangle + \iota_{\Omega_i} (x_i), \quad \lambda_i \in \mathbb{R}_-^m
\end{array}
\end{equation}
where $\iota_{\Omega_i} (x_i)$ is the indicator function of $\Omega_i$, whose subgradient is the normal cone $\mathcal{N}_{\Omega_i} (x_i)$ of $\Omega_i$, and $\operatorname{prox}_{\mathcal{N}_{\Omega_i}}(x_i) = \Pi_{\Omega_i}(x_i)$. Then applying (Douglas-Rachford? not the same) splitting, one gets the Algorithms (Algorithm 1 and 2) proposed in \citep{Yi_2019}.

2. It is stated in the numerical study section of \citep{Yu_2017} that ``\textcolor{red!60}{However, we rely on (110) in the simulations to examine the numerical performance regardless of solution feasibility.}'', where (110) is the constraints on the market capacities, similar to
\begin{align*}
A_i x_i \leqslant r_i, ~ \sum r_i \leqslant r ~ (\text{or } \sum r_i = r).
\end{align*}

In the first paragraph of section 3.2 of \citep{Yi_2019}, it is stated that ``\textcolor{red!60}{the shared affine coupling constraint is decomposed such that each player only knows a local block of the constraint matrix. Notice that $A_i$ characterizes how agent $i$ is involved in the coupling constraint (shares the global resource), also assumed to be privately known by player $i$. Then, the globally shared constraint $Ax \geqslant b$ couples the agents’ feasible decision sets, but is not known by any agent}''.

\begin{question}
What does it mean by ``each player only knows a local block of the constraint matrix''?
\end{question}

If one changes the original problem \eqref{eq:original_problem} to
\begin{equation}
\label{eq:new_problem}
\def\arraystretch{1}
\begin{array}{rl}
\min & g(x_i) = f_i(x_i, \mathbf{x}_{-i}) = c_i(x_i) - (P(Ax))^TA_ix_i \\
\text{s.t.} & x_i \in \Omega_i \subsetneq \mathbb{R}^{n_i} \\
& A_ix_i \leqslant r_i \\
& \sum r_i = r
\end{array}
\qquad i = 1, \ldots, N
\end{equation}
Then the reformulated unconstrained problem is
\begin{equation}
\label{eq:reformulated_new_problem}
\begin{array}{rl}
\min & g_i(x_i) + \langle \lambda_i, r_i-A_ix_i \rangle + \langle \mu_i, r - \sum r_i \rangle + \iota_{\Omega_i} (x_i), \quad \lambda_i \in \mathbb{R}_-^m
\end{array}
\end{equation}

3. In the last paragraph of section 3.2 of \citep{Yi_2019}, it is stated that ``\textcolor{red!60}{The update of $z_i$ in Algorithm 1 can be regarded as the discrete-time integrator for the consensual errors of local multipliers, which will ensure the consensus of $\lambda_i$ eventually}''. Since the authors stated that ``In this work, we seek a GNE with the same Lagrangian multiplier for all the agents, called variational GNE'' in section 3.1

\begin{question}
What is the situation for problems where the multipliers do not need a consensus?
\end{question}

TO ADD MORE ...

\subsection*{Computation of Gradients}

Computation of the gradient of the function in equation (36) in \citep{Yi_2019}

Consider the objective function
$$g(x_i) = f_i(x_i, \mathbf{x}_{-i}) = c_i(x_i) - (P(Ax))^T A_ix_i,$$

Let $p_i: \mathbb{R}^{n_i} \to \mathbb{R}^m$ be the function of supply of the $i$-th company to the markets, i.e. $p_i(x_i) = P(Ax) = P\left(\sum\limits_{1 \leqslant j \leqslant N} A_jx_j\right)$. Then
\begin{align*}
\operatorname{grad} g(x_i) & = \nabla_{x_i} f_i(x_i, \mathbf{x}_{-i}) = \operatorname{grad} c_i(x_i) - \left( \dfrac{\partial \left( (p_i(x_i))^T A_ix_i \right)}{\partial (x_i)_k} \right)_{k=1}^{n_i} \\
& = \operatorname{grad} c_i(x_i) - \left( \dfrac{\partial \left( \sum\limits_{1\leqslant t \leqslant m} (p_i(x_i))_t (A_ix_i)_t \right)}{\partial (x_i)_k} \right)_{k=1}^{n_i} \\
& = \operatorname{grad} c_i(x_i) - \left( \sum\limits_{1\leqslant t \leqslant m}\left( \dfrac{\partial \left( (p_i(x_i))_t \right)}{\partial (x_i)_k} (A_ix_i)_t + \dfrac{\partial \left( (A_ix_i)_t \right)}{\partial (x_i)_k} (p_i(x_i))_t \right) \right)_{k=1}^{n_i} \\
% & = \operatorname{grad} c_i(x_i) - \left( \sum\limits_{1\leqslant t \leqslant m}\left( \left(\operatorname{Jac} (p_i(x_i)) \right)_{tk} (A_ix_i)_t + \dfrac{\partial \left( \sum\limits_{s} (A_i)_{ts} (x_i)_s \right)}{\partial (x_i)_k} (p_i(x_i))_t \right) \right)_{k=1}^{n_i} \\
& = \operatorname{grad} c_i(x_i) - \left( \sum\limits_{1\leqslant t \leqslant m}\left( \left(\operatorname{Jac} (p_i)(x_i) \right)_{tk} (A_ix_i)_t + (A_i)_{tk} (p_i(x_i))_t \right) \right)_{k=1}^{n_i} \\
& = \operatorname{grad} c_i(x_i) - \left( \langle \operatorname{Jac}(p_i)(x_i)_{[:,k]}, A_ix_i \rangle + \langle (A_i)_{[:,k]}, p_i(x_i) \rangle \right)_{k=1}^{n_i} \\
& =\operatorname{grad} c_i(x_i) - \left( \operatorname{Jac}(p_i)(x_i) \right)^T A_ix_i - A_i^T p_i(x_i),
\end{align*}
with $\operatorname{Jac}(p_i)(x_i) = \left( \operatorname{Jac}(P)\left(\sum\limits_j A_jx_j\right) \right) \cdot A_i$.

When $p$ is the linear inverse demand function $P(s) = p − Ds$, where $p, s \in \mathbb{R}^m$, $D = \operatorname{diag}(d_1, \ldots, d_m) \in \operatorname{GL}_m(\mathbb{R})$. Then $\operatorname{Jac}(P)(s) = -D$. Let the local production cost functions be $c_i(x_i) = \pi_i \left(\sum\limits_{j=1}^{n_i} [x_i]_j\right)^2 + b_i^Tx_i$, then $\operatorname{grad} c_i(x_i) = 2\pi_i \left(\sum\limits_{j=1}^{n_i} [x_i]_j\right) + b_i$. Therefore,
\begin{align*}
\operatorname{grad} g(x_i) & = \left(2\pi_i \left(\sum\limits_{j=1}^{n_i} [x_i]_j\right) + b_i \right) + \left( A_i^TDA_ix_i - A_i^T \left( p - D\sum\limits_{1 \leqslant j \leqslant N} A_jx_j \right) \right)
\end{align*}

The expression of $\operatorname{Jac}(p_i)(x_i)$ corresponds to the function \texttt{market\_price\_jac} in the file \texttt{python/simulation.py}, the expression of $\operatorname{grad} g(x_i)$ corresponds to the attribute \texttt{\_objective\_grad} of the \texttt{Company} class in \texttt{python/networked\_cournot\_game.py}.

\subsection*{Minimal Example}

Consider the networked Cournot game where there is one market with two companies. Let the price function of the market be $p(s) = 4 - s$ where $s$ is the supply. Let the production cost functions for the two companies be identical: $c(x_i) = x_i^2 + x_i$, $i = 1, 2$. Then the objective function for the companies are
$$\begin{cases}
\text{min} \ x_1^2 + x_1 - (4 - (x_1 + x_2)) x_1 \\
\text{min} \ x_2^2 + x_2 - (4 - (x_1 + x_2)) x_2 \\
\end{cases}$$
The solution is $x_1 = x_2 = 0.6.$

\printbibliography


\chapter{Limits}

Here is a function:

$$f(x) = \frac{x^2}{x} + 1$$

This $f$ is defined for any real number \emph{except 0}. (You can't
divide anything, including zero, by zero.)

Let's plot $f$:

\begin{tikzpicture}[
tl/.style = {% tick labels
    fill=white, inner sep=1pt, font=\scriptsize,
            },                        ]
% grid
\draw[sdkblue, very thin] (-3,-3) grid (3,3);

    \draw[<->,thick,dashed] (-3.2,0) -- (3.2,0) node[right] {$x$};
    \draw[<->,thick,dashed] (0,-3.2) -- (0, 3.2) node[above] {$y$};
% curve
\draw[<-,draw=black,thick,domain=-3:-0.1,samples=300,variable=\x] plot (\x,{\x + 1});
\draw[thick] (0,1) circle (0.1);
\draw[->,draw=black,thick,domain=0.1:2,samples=300,variable=\x] plot (\x,{\x + 1});
\end{tikzpicture}

You can see that the function is the same as $x + 1$ everywhere except
$x = 0$.  You can see that as the function approaches $x=0$ from the
left, the value of the function approaches 1.  You can see that as the
function approaches $x=1$ from the right, the value of the function
approaches 1.

Mathematicians say ``The \newterm{limit} of $f$ as $x$ approaches 0, is 1.''  We have a notation for this:

$$\lim_{x \rightarrow 0} f(x) = 1$$

We generally use limit whenever we mean ``We are getting arbitrarily
close, but we can never really get there.''  For example, you might
say ``The limit of $1/t$ as $t$ goes to infinity is 0.''

\begin{tikzpicture}[
tl/.style = {% tick labels
    fill=white, inner sep=1pt, font=\scriptsize,
            },                        ]
% grid
\draw[sdkblue, very thin] (-5,-5) grid (5,5);
    \draw[<->,thick,dashed] (-5.2,0) -- (5.2,0) node[below] {$t$};
    \draw[<->,thick,dashed] (0,-5.2) -- (0, 5.2);
% curve
\draw[<->,draw=black,thick,domain=0.2:5,samples=300,variable=\x] plot (\x,{1/\x});
\draw[<->,draw=black,thick,domain=-5:-0.2,samples=300,variable=\x] plot (\x,{1/\x});
\draw (5.0, 0.2) node[above] {$t \rightarrow \infty$, $1/t \rightarrow 0$};
\draw (0.0, 5.2) node[above] {$t \rightarrow 0$ from the right, $1/t \rightarrow \infty$};
\draw (0.0, -5.2) node[below] {$t \rightarrow 0$ from the left, $1/t \rightarrow -\infty$};
\draw (-5.0, -0.2) node[below] {$t \rightarrow -\infty$, $1/t \rightarrow 0$};

\end{tikzpicture}

What is the limit of $1/t$ as $t$ approaches zero? The limit isn't
defined because if you approach from the right, $1/t$ goes to
infinity, but if you approach from the left, $1/t$ goes to negative
infinity.


\subsection{Helices}
\noindent
A helix looks like a spring and appears to look like a circle when viewed from the top looking down.
It has the form $\vec{r}(t) = \langle r\cos{t}, r\sin{t}, ct\rangle$ where $a\in\mathbb{R}$. $a$ defines the ``tightness'' between consecutive windings.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.5\textwidth]{./vectorValuedFunctions/Helix.png}
	\caption{A helix}
\end{figure}


\documentclass[revision-guide.tex]{subfiles}
%% Current Author: PS
\setcounter{chapter}{16}
\begin{document}
\raggedbottom
\chapter{Nuclear Physics}
\begin{content}
    \item equations of radioactive decay
    \item mass excess and nuclear binding energy
    \item antimatter
    \item the standard model
\end{content}
\section*{Candidates should be able to:}

\spec{recall and show that the random nature of radioactive decay leads to the differential equation
\begin{equation} \label{n-diff} \frac{dN}{dt} = -\lambda N \end{equation} and that
\begin{equation} \label{n-exp} N = N_0 e^{-\lambda t} \end{equation} is a solution to this equation.}

Radioactive decay is characterised by the fact that the number of nuclei which disintegrate per unit time is directly proportional to the number of unchanged nuclei remaining. Since a disintegrating nucleus reduces the number remaining, there is a negative sign in the proportionality. This relationship can be expressed mathematically as equation \ref{n-diff}. Where $N$ is the number of nuclei and $\lambda$ is called the decay constant, with units \si{\per\second}.

Equation \ref{n-diff} is a differential equation with respect to time and therefore the solution to it is a function of time. We can show that equation \ref{n-exp} is a solution to this equation by differentiating it.

\begin{align*}
N &= N_0 e^{-\lambda t} \\
\frac{dN}{dt} &= \left( -\lambda \right) N_0 e^{-\lambda t} \\
&= -\lambda N
\end{align*}

\spec{recall that activity \begin{equation} A = -\frac{d N}{dt} \end{equation} and show that \( A = \lambda N \)  and \( A = A_0e^{-\lambda t}\)}

Every time a radioactive nucleus disintegrates it emits a particle of ionising radiation. Thus the activity is simply the negative of the rate of change of the number of unchanged nuclei remaining. Simple substitutions allow the derivation of the following equations.

\begin{align*}
A &= -\frac{dN}{dt} & N &= N_0 e^{-\lambda t} \\
&= -(-\lambda N) & -\lambda N &= -\lambda N_0 e^{-\lambda t} \\
&= \lambda N & A &= A_0e^{-\lambda t}
\end{align*}

Note that we do not measure the true activity as that would mean detecting all of the radiation given off by the sample. However, we assume that the measured activity is proportional to the true activity and therefore all our measurements behave in the same way.

\spec{show that the half-life \[ t_\frac{1}{2} = \frac{\ln{2}}{\lambda} \]}

The half-life is defined as the time take for half of the nuclei to decay. Therefore I can substitute $N = \frac{N_0}{2}$ into equation \ref{n-diff} to give:
\begin{align*}
\frac{1}{2} = e^{-\lambda t_\frac{1}{2}}  \\
\ln{\frac{1}{2}} = -\lambda t_\frac{1}{2} \\
t_\frac{1}{2} = \frac{\ln{2}}{\lambda}
\end{align*}

\spec{use the equations in (a), (b) and (c) to solve problems}

\spec{recognise and use the equation \begin{equation} \label{I-exp} I = I_0e^{- \mu x} \end{equation} as applied to attenuation losses}

When a wave or ionising radiation travels through a medium its amplitude will reduce due to \emph{attenuation}. This is due to scattering and/or absorption by the medium. Note that is this different to a reduction in intensity due to the radiation spreading out. It is assumed that if a given fraction of the intensity is absorbed in a unit length then equation \ref{n-diff} can be used, replacing $N$ with intensity, $t$ with distance, $x$ and the constant of proportionality with $\mu$. This gives
\begin{equation} \label{I-diff}
\frac{dI}{dx} = -\mu I
\end{equation}
Using a similar logic to that for equation \ref{n-exp} we can show that equation \ref{I-exp} is a solution to this equation.

\spec{recall that radiation emitted from a point source and travelling through a non-absorbing material obeys an inverse square law and use this to solve problems}

\begin{figure}[h]
  \begin{center}
    \begin{tikzpicture}[scale=0.6]
      \draw[->-, thick]  (0,0.5) -- (0,4);
      \draw[->-, thick] ({sqrt(.125)},{sqrt(.125)}) -- ({sqrt(9)},{sqrt(9)});
      \draw[->-, thick] (.5,0) -- (4,0);
      \draw[->-, thick] ({sqrt(.125)},-{sqrt(.125)}) -- ({sqrt(9)},-{sqrt(9)});
      \draw[->-, thick] (0,-.5) -- (0,-4);
      \draw[->-, thick] (-{sqrt(.125)},-{sqrt(.125)}) -- (-{sqrt(9)},-{sqrt(9)});
      \draw[->-, thick] (-.5,0) -- (-4,0);
      \draw[->-, thick] (-{sqrt(.125)},{sqrt(.125)}) -- (-{sqrt(9)},{sqrt(9)});
      \filldraw[fill=yellow] (0,0) circle (0.5cm);
    \end{tikzpicture}
  \end{center}
  \caption{Radial radiation}
  \label{radiation-spreading}
\end{figure}

Radiation emitted from a point source spreads out symmetrically in all directions as shown in figure \ref{radiation-spreading}. The intensity is defined as the power per unit area of radiation. A distance $r$ from the centre of the source the radiation is spread over the surface of a sphere and is therefore calculated using
\begin{equation}
  I = \frac{P}{4\pi r^2}
\end{equation}

Since $I\propto r^{-2}$ this is known as an inverse-square law.

\spec{estimate the size of a nucleus from the distance of closest approach of a charged particle}

When particles approach a nucleus head-on they begin with kinetic energy $E_K$. All of this kinetic energy is converted to electrical potential energy, $EPE$. If the energy of the alpha particles is known then a distance of minimum separation can be calculated.

\begin{example}
  Calculate the minimum distance of separation of a alpha particle of kinetic energy \SI{4.0}{\mega\electronvolt} travelling directly towards a gold nucleus ($Z=79$).

  \answer

  Equating the initial kinetic energy to the electrostatic potential gives
  \[ E_k = \frac{Q_1 Q_2}{4\pi \epsilon_0 d} \]
  therefore
  \begin{align*}
    d &= \frac{Q_1 Q_2}{4 \pi \epsilon_0 E_k} \\
    &= \frac{2\times79\times (\num{1.6e-19})^2}{4\pi \epsilon_0 \times \num{4.0e6} \times \num{1.6e-19}} \\
    &= \SI{5.7e-14}{\meter}
  \end{align*}
\end{example}

It turns out that if high energy alpha particles are fired at the nucleus then Rutherford's deflection formulae break down and the distribution of alpha particles no longer fits the expectation. Under these circumstances it can be assumed the alpha particle is interacting with the nucleus and therefore has been able to approach to within the nuclear radius.

\newpage
\spec{understand the concept of nuclear binding energy, and recognise and use the equation $ \Delta E = c^2 \Delta m$ (binding energy will be taken to be positive)}

It turns out that the mass of a nucleus is always smaller than the total mass of the constituent protons and neutrons. This difference is called the \emph{mass deficit} and can be converted to an energy using $ \Delta E = c^2 \Delta m$. The reduction in mass corresponds to the energy released by combining the nucleons.

\begin{example}
  Calculate the binding energy of a helium-4 nucleus of mass \SI{4.0015}{\amu}

  \answer

  The helium-4 nucleus is composed of two protons and two neutrons. Their total mass is
  \[ 2\times \SI{1.00728}{\amu}+2\times \SI{1.00867}{\amu} = \SI{4.0319}{\amu} \]
  The mass deficit, $\Delta m$, is given by
  \[ \Delta m = \SI{4.0319}{\amu} - \SI{4.00215}{\amu} = \SI{0.0304}{\amu} \]
  Therefore the binding energy is calculated as
  \[ \num{0.0304} \times \num{1.66e-27} \times c^2 = \SI{4.54e-12}{\joule} = \SI{28.4}{\mega\electronvolt} \]
\end{example}

\newpage
\spec{recall, understand and explain the curve of binding energy per nucleon against nucleon number}

A useful measure of the stability of the nucleus is given by its \emph{binding energy per nucleon}. This is the binding energy divided by the nucleon number. A plot of the binding energy per nucleon against nucleon number is show in figure \ref{binding-energy}.  The nucleus with the largest binding energy is iron-56 and this therefore is the most stable nucleus. Nuclei with nucleon numbers below iron-56 will release energy when they undergo nuclear fusion and those above iron-56 will release energy when they undergo fission.

\begin{figure}[h]
  \begin{center}
    \begin{tikzpicture}[scale=0.75]
      \draw[-] (0,0) -- (0,9);
      \foreach \y in {0,1,...,9} {
        \draw (-.2,\y) node {\y};
        \draw (0,\y) -- (0.1,\y);
      }
      \draw[-] (0,0) -- (12,0);
      \foreach \x in {0,40,80,...,240} {
        \draw (\x/20,-0.4) node{{\x}};
        \draw (\x/20,0) -- (\x/20,0.1);
      }
      \draw[thick] (0.1,1) .. controls (0.1,9) and (2,8.8) .. (2.8,8.8) .. controls (4.8,8.8) and (9,8.5) .. (12,7.8);
      \draw (6,-1) node{Nucleon Number};
      \draw (-0.9,4.5) node {\rotatebox{90}{Binding Energy per Nucleon / MeV}};
    \end{tikzpicture}
  \end{center}
  \caption{Variation of binding energy per nucleon with nucleon number}
  \label{binding-energy}
\end{figure}

\spec{recall that antiparticles have the same mass but opposite charge and spin to their corresponding
particles}

All normal particles have an antiparticle partner with the same mass, but some properties which are opposite including electrical charge.

\spec{relate the equation $\Delta E = c^2 \Delta m$ to the creation or annihilation of particle-antiparticle pairs}

A particle-antiparticle pair can be created whenever there is enough energy present to do so. For example, if a photon of light is near an atomic nucleus it can spontaneously convert into an electron-positron pair.

\begin{example}
  Calculate the minimum energy a photon must have in order to create an electron-positron pair.
  \answer
  \[ E = c^2 \Delta m = c^2 \times 2 \times\num{9.11e-31} = \SI{1.02}{\mega\electronvolt} \]
\end{example}

\spec{recall the quark model of the proton (uud) and the neutron (udd)}

The theory of quarks was developed to explain the large number of particles discovered in the early particle colliders. Particles made of quarks are called \emph{hadrons}. Normal matter is made up of two types of quark, the up quark (charge $+\frac{2}{3}e$) and the down quark (charge $-\frac{1}{3}e$). From the charges it is possible to see that the proton must be uud and the neutron udd.

\spec{understand how the conservation laws for energy, momentum and charge in beta-minus decay were used to predict the existence and properties of the antineutrino}

The existence of the antineutrino was first predicted from the energy spectrum of beta decay. Beta particles are produced when a neutron in the nucleus is converted into a proton and a high energy electron. These electrons leave the nucleus at high speed and are detected as beta particles. In such a scenario (a two body process) the electrons should have a fixed amount of energy due to the conservation of momentum. However, the electron was found to have a range of energies. The explanation provided was that whenever an electron was emitted with little energy a third particle has carried away a lot of energy (and vice-versa). The particle had to be neutral (to conserve charge) and of very small mass and was named the \textbf{neutrino}.

The full beta decay equation now becomes
\[ \text{n} \rightarrow \text{p} + \text{e}^- + \overline{\nu}_\text{e} \]

Further evidence for the existence of this third particle comes from bubble chamber tracks left by beta decay which show the nucleus and electron both recoiling away from a particle which does not leave a trace in the bubble chamber - the neutrino. A photo of this decay can be seen at the science photo library here: \url{http://www.sciencephoto.com/media/1210/view}

\spec{balance nuclear transformation equations for alpha, beta-minus and beta-plus emissions}

When these nuclear decays occur total nucleon number remains the same and charge is conserved. In order to make life easier we give beta-minus particles a proton number of $-1$ and a nucleon number of zero. Beta-plus particles (positrons) are given a proton number of $+1$. Alpha particles are helium-4 nucleii ($_2^4\text{He}$).

As an example, if we know that magnesium-23 decays by beta-plus decay we can write
\[ _{12}^{23}\text{Mg} \rightarrow _Z^A\text{X} + _{1}^{0}e^+ \]

We can deduce the identity of X by conserving nucleon number ($A+0=23$) and proton number ($Z+1 = 12$). Therefore:

\[ _{12}^{23}\text{Mg} \rightarrow _{11}^{23}\text{Na} + _{1}^{0}e^+ \]

\spec{recall that the standard model classifies matter into three families: quarks (including up and down),leptons (including electrons and neutrinos) and force carriers (including photons and gluons)}

An important feature to note is that quarks and gluons are never observed on their own. There are further `generations' of quarks and leptons but these only exist at higher energies.

\spec{recall that matter is classified as baryons and leptons and that baryon numbers and lepton numbers are conserved in nuclear transformations.}

Baryons are made up of three quarks and have a baryon number of +1. Similarly, leptons have a lepton number of +1. Anti-baryons and anti-leptons have respective numbers of -1.

For example, conservation of baryon number prohibits the following:
\begin{align*}
    p + n &\rightarrow p + e^+ + e^- \\
    B = 1 + 1 &\neq 1 + 0 + 0
\end{align*}

Conservation of lepton number also shows why the anti-electron neutrino is required in beta decay:
\begin{align*}
    n &\rightarrow p + e^- + \overline{\nu}_e \\
    L = 0 &= 0 + 1 + (-1) \\
    B = 1 &= 1 + 0 + 0
\end{align*}

\end{document}


\problemname{Gwen's Gift}

Gwen loves most numbers. In fact, she loves every number that is \textit{not} a multiple of $n$ (she really hates the number $n$).
For her friends' birthdays this year, Gwen has decided to draw each of them a sequence of $n-1$ flowers.
Each of the flowers will contain between $1$ and $n-1$ flower petals (inclusive).
Because of her hatred of multiples of $n$, the total number of petals in
any non-empty contiguous subsequence of flowers cannot be a multiple of $n$. For example, if $n = 5$, then the top two paintings are valid,
while the bottom painting is not valid since the second, third and fourth flowers have a total of $10$ petals.
(The top two images are Sample Input $3$ and $4$.)

\begin{center}
 \includegraphics[width=0.9\textwidth]{gift-flowers.png}
\end{center}

Gwen wants her paintings to be unique, so no two paintings will have
the same sequence of flowers.  To keep track of this, Gwen recorded
each painting as a sequence of $n-1$ numbers specifying the number of
petals in each flower from left to right.  She has written down all
valid sequences of length $n-1$ in lexicographical order. A sequence
$a_1,a_2,\dots, a_{n-1}$ is lexicographically smaller than
$b_1, b_2, \dots, b_{n-1}$ if there exists an index $k$ such that $a_i = b_i$
for $i < k$ and $a_k < b_k$.

What is the $k$th sequence on Gwen's list?

\section*{Input}

The input consists of a single line containing two integers $n$~($2 \leq n \leq 1\,000$),
which is Gwen's hated number, and $k$~($1 \leq k \leq 10^{18}$), which is the index of the valid sequence in question
if all valid sequences were ordered lexicographically.
It is guaranteed that there exist at least $k$ valid sequences for this value of $n$.

\section*{Output}

Display the $k$th sequence on Gwen's list.


\section{Formulation of the Data Compression Problem}
Z-checker has plentiful algorithms and functions for assessing lossy compressors on scientific data sets.
We list the metrics that Z-checker can evaluate for assessing lossy compressors as follows.
\begin{itemize}
\item Pointwise compression error between original and reconstructed data sets, for example, absolute error and value-range-based relative error. In this report, we will present the value range of the data in the description-of-data section, and then adopt the absolute error bound (a constant such as 1E-5) to control the error in the compression.
\item Statistical compression error between original and reconstructed data sets, such as root mean squared error (RMSE), normalized RMSE (NRMSE), and peak signal-to-noise ratio (PSNR). According to the definition of NRMSE and PSNR, the smaller NRMSE, the larger the PSNR. In this report, hence, we focus on PSNR, which is compuated as follows.
\begin{equation}
PSNR = 20\cdot \log_{10}{(value\_range)} - 10\cdot \log_{10}{(MSE)}.
\end{equation}
where value\_range and MSE refer to data value range and the mean squared compression error respectively.
\item Distribution of compression errors refers to the probability distribution density of the compression errors.
It is an important metric for some scientific researchers require the compression errors to follow some certain distributions, such as Gaussian distribution.
\item Compression ratio (a.k.a, compression factor) is to evaluate the reduction size as a result of the compression. It is calculated by the original data size divided by the compressed data size.
\item Bit rate (bits/value) represents the amortized number of bits used to represent a data point's value after compression.
\item Rate-distortion based on statistical compression error and bit rate. It represents the distortion quality per bit of compressed storage.
Rate refers to bit rate in bits/value. Distortion refers to the overall deviation of the data after compression and is generally assessed via PSNR.
\item Compression and decompression rate is to evaluate the processing speed.
In order to save I/O time during the execution, not only do the users hope to get a high compression factor, but the compression also has to suffer from limited compression/decompression time such that the overall execution performance can be maximized.
Compression/decompression rate refers to the amount of data to be compressed/decompressed per second, e.g., MB/s.
\item Autocorrelation of compression errors is important for assessing the degree of autocorrelation (if any) that the lossy compressors add to the original data sets.
\item Distortion of spectrum is to evaluate the distortion of the spectrum values (generated by discrete Fourier transform) between original and reconstructed data sets.
Minimizing such distortion is required by some scientist researchers.
\end{itemize}