\documentclass{article}
\usepackage{amsmath}
\usepackage[margin=1.0in]{geometry}
\usepackage{xcolor}

\begin{document}

\noindent
Does $\displaystyle \sum_{n=1}^\infty \frac{1}{3n^5+n^4+n^3+n^2+n+1}$
diverge, converge absolutely, or converge conditionally?

\subsection*{Solution}

Note that $3n^5 \geq n^5$. In fact, it is even further the case that
\[3n^5+n^4+n^3+n^2+n+1 \geq n^5\]
and dividing both sides by $(n^5)(3n^5+n^4+n^3+n^2+n+1)$, we get
\[ \frac1{n^5} \geq \frac{1}{3n^5+n^4+n^3+n^2+n+1}.\]
Since the series $\displaystyle \sum_{n=1}^\infty \frac1{n^5}$ converges by the $p$-series test, the series $\displaystyle \sum_{n=1}^\infty \frac{1}{3n^5+n^4+n^3+n^2+n+1}$ converges by the Direct Comparison Test.

Since $\sum |a_n| = \sum a_n$, the series $\displaystyle \sum_{n=1}^\infty \frac{1}{3n^5+n^4+n^3+n^2+n+1}$ converges absolutely.

\subsection*{Comment}

This series can be studied using the Limit Comparison Test as well, but this is much more convenient using the Direct Comparison Test.

\end{document}%%%%%%%%%%%%%%%%%

\begin{align*}
L&=\lim_{n \to \infty} \sqrt[n]{|a_n|}\\
&= \lim_{n \to \infty} \sqrt[n]{\left| \right|}\\
\end{align*}

\begin{align*}
L&=\lim_{n \to \infty} \left|\frac{a_{n+1}}{a_n}\right|\\
&= \lim_{n \to \infty} \left| \right|\\
\end{align*}

\begin{align*}
\lim_{n \to \infty} a_n
&= \lim_{n \to \infty} \\
\end{align*}

Since $\sum |a_n| = \sum a_n$, the series $\displaystyle \sum_{n=1}^\infty AAAAAAAAAAAAAA$ converges absolutely.

Since $|r| < 1$, the series ...  converges by the Geometric Series Test.

Since $|r| \geq 1$, the series ...  diverges by the Geometric Series Test.

The function $f(x)=\frac{}{}$ is continuous, positive, and decreasing on $[1,\infty)$.

\subsection*{Solution}


%---------------------------Relative Size-Squared-----------------------------
\section{Relative Size Squared\label{s:tri-rel-size-squared}}

Let $R$ be ratio of the triangle area $A$ to the average area $\overline{A}$ of an ensemble of triangles
\[
  R = \frac{A}{\overline{A}}
\]
The relative size is the minimum of $R$ and its inverse and the relative size squared is
\[
  q = \left( \min\left\{R,\frac{1}{R}\right\} \right)^2.
\]

Note that if $R = 0$, we take $q = 0$.

\trimetrictable{relative size squared}%
{$1$}%                                                Dimension
{$[0.25,1]$}%                                         Acceptable range
{$[0,1]$}%                                            Normal range
{$[0,1]$}%                                            Full range
{Dependent on $\overline{A}$}%                        Unit equilateral triangle value
{\cite{knu:03}}%                                      Reference(s)
{v\_tri\_relative\_size\_squared}%                            Verdict function name


\section{Probability}

\subsection*{Unit 6: Derived distributions}
$Z = X+Y$ (independent)\\
$p_Z(z) = \sum_x p_X(x) p_Y(z-x)$\\
$f_Z(z) = \int_{-\infty}^{\infty} f_X(x) f_Y(z-x) dx$\\
Sum of independent normals is normal.\\

Monotonic transformation: $Y = g(X)$\\
$F_Y(y) = f_X(h(y))\left|\frac{dh}{dy}(y)\right|, h(y) = g^{-1}(x)$

\subsection*{Unit 6: Deeper view of conditioning}

Law of iterated expectations $\mathbf{E}[X] = \mathbf{E}\left[\mathbf{E}[X|Y] \right]$.

Law of total variance $Var(X) = \mathbf{E}\left[Var(X|Y)\right] + Var(\mathbf{E}[X|Y])$

Sum of a random number of independent r.v.'s: $Y = X_1 + \ldots + X_N$

$\mathbf{E}[Y] = \mathbf{E}[N] \cdot \mathbf{E}[X]$

$Var(Y) = \mathbf{E}[N]\,Var(X) + (\mathbf{E}[X])^2\,Var(N)$

\subsection*{Unit 8: Limit theorems and classical statistics}

Markov inequality: $X \geq 0$ and $a > 0$, then $\mathbf{P}(X \geq a) \leq \frac{\mathbf{E}[X]}{a}$

Chebyshev inequality: $c > 0$, then $\mathbf{P}(|X - \mathbf{E}[X]| \geq c) \leq \frac{Var(X)}{c^2}$

Convergence in probability: for every $\epsilon > 0$, $\mathbf{P}(|X_n - a| \geq \epsilon) \rightarrow 0$

Weak law of large numbers: $X_i$ (i.i.d.), $M_n = \frac{X_1 + \ldots + X_n}{n} \rightarrow \mathbf{E}[X]$

Central limit theorem: $X_i$ (i.i.d.), $\text{CDF of }\frac{X_1 + \ldots + X_n - n\mathbf{E}[X]}{\sqrt{n}\sigma_X} \rightarrow \text{ standard normal CDF}$

\subsection*{Unit 9: The Bernoulli and Poisson processes}

% \begin{table}[h!]
%     \begin{tabular}{lll}
%     ~                        & Poisson             & Bernoulli     \\
%     Times of arrival         & Continuous          & Discrete      \\
%     Arrival Rate             & $\lambda$/unit time & $p$/per trial \\
%     PMF of \# of Arrivals    & Poisson             & Binomial      \\
%     Interarrival Time Distr. & Exponential         & Geometric     \\
%     Time to $k$-th arrival   & Erlang              & Pascal
%     \end{tabular}
% \end{table}

\subsubsection*{Bernoulli process}

Number of successes/arrivals $S$ in $n$ time slots:\\
$S = X_1 + \ldots + X_n$ (Binomial)\\
$\mathbf{P}(S=k) = {n \choose k} p^k (1-p)^(n-k), k=0,\ldots,n$\\
$\mathbf{E}[S] = np$\\
$Var(S) = np(1-p)$\\

Time until the first sucess/arrival $T_1$\\
$T_1 = \min\lbrace i: X_i = 1\rbrace$ (Geometric)\\
$\mathbf{P}(T_1=k) = (1-p)^(k-1)p, k=1,2,\ldots$\\
$\mathbf{E}[T_1] = \frac{1}{p}$\\
$Var(T_1) = \frac{1-p}{p^2}$\\

Time of the $k$-th sucess/arrival\\
$Y_k = T_1 + \ldots + T_k$ (Pascal), $T_i$ are iid Geometric($p$)\\
$p_{Y_k}(t) = {t-1 \choose k-1} p^k (1-p)^{t-k}, t=k, k+1, \ldots$\\
$\mathbf{E}[Y_k] = \frac{k}{p}$\\
$Var(Y_k) = \frac{k(1-p)}{p^2}$\\

Merged process\\
$\text{Bernoulli}(p) + \text{Bernoulli}(q) = \text{Bernoulli}(p+q-pq)$\\
$\mathbf{P}(\text{arrival in first process} | \text{arrival}) = \frac{p}{p+q-pq}$\\

Splitting process\\
Split arrivalssuccesses into two streams, using independent coin flips of a coin with bias $q$:\\
Resulting streams are Bernoulli, successes rates are $pq$ and $p(1-q)$.\\
The two streams are not independent\\

\subsubsection*{Poisson Process}

Number of arrivals in interval $\tau$: $N_\tau$ (Poisson)\\
$P(N_\tau = k, \tau) = \frac{(\lambda \tau)^k e^{-\lambda \tau}}{k!}, k=0, 1, \ldots$\\
$\mathbf{E}[N_\tau] = \lambda\tau$\\
$Var(N_\tau) = \lambda\tau$\\

Time until the first sucess/arrival $T_1$ (Exponential($\lambda$))\\
$T_1 = \min\lbrace i: X_i = 1\rbrace$ (Geometric)\\
$f_{T_1}(t) = \lambda e^{-\lambda t}, t \geq 0$\\
$\mathbf{E}[T_1] = \frac{1}{\lambda}$\\
$Var(T_1) = \frac{1}{\lambda^2}$\\

Time of the $k$-th sucess/arrival:\\
$Y_k = T_1 + \ldots + T_k$ (Erlang), $T_i$ are iid Exponentials($\lambda$)\\
$f_{Y_k}(y) = \frac{\lambda^k y^{k-1} e^{-\lambda y}}{(k-1)!}, y \geq 0$\\
$\mathbf{E}[Y_k] = \frac{k}{\lambda}$\\
$Var(Y_k) = \frac{k}{\lambda^2}$\\

Merged process\\
$\text{Poisson}(\lambda_1) + \text{Poisson}(\lambda_2) = \text{Poisson}(\lambda_1+\lambda_2)$\\
$\mathbf{P}(k\text{-th arrival comes from first process}) = \frac{\lambda_1}{\lambda_1+\lambda_2}$\\
Independence for different arrivals\\

Splitting process\\
Split arrivals into two streams, using independent coin flips of a coin with bias $q$:\\
Resulting streams are Poisson, rates $\lambda q$ and $\lambda (1-q)$.\\
Resulting streams are independent!


\lab{Python}{Polynomial Interpolation Using Chebyshev Polynomials}{Polynomial Interpolation Using Chebyshev Polynomials}
\label{lab:cheb_interp}

\objective{Explore basic uses of polynomial interpolation using Chebyshev polynomials.}

\section*{Chebyshev nodes}

In previous labs we have explored ways to compute interpolating polynomials given sets of points.
We have also noted that such interpolation may still be a very poor approximation to a function depending on the function itself and the choice of interpolating points.
The question then arises, "when can polynomial interpolation be a good approximation to a given function?"
You may recall that equally spaced points provided a very poor approximation to a given function around the edge of the interval where we are performing the interpolation.
This weakness in interpolation using equispaced points is called Runge's Phenomenon.
We can avoid Runge's Phenomenon by choosing to interpolate our function with a different set of points.
Since there is an increased amount of instability toward the edges of the interval where we are interpolating we will choose more points toward the edges of the interval so that the approximation remains accurate throughout the whole interval.

It can be shown that, when forming an interpolating polynomial of degree $n$, the ideal points to use for interpolation on the interval $[-1, 1]$ are the points $\cos{\frac{\pi k}{n}}$ for $k\in\mathbb{Z}$, $0 \leq k \leq n$.
These points are called the Chebyshev nodes.
These points can also be viewed as the projection of equispaced points along the half-circle in the complex plane projected onto the real axis.
This interpretation is shown in Figure \ref{fig:cheb_nodes_projection}.
They can be shifted and scaled appropriately for use on any interval.
As we have presented them here they are on the interval $[-1, 1]$.
These nodes provide for much more stable interpolation of functions as can be seen in Figure \ref{fig:runge_chebyshev}.

\begin{figure}
\includegraphics[width=\textwidth]{node_project.pdf}
\caption{The Chebyshev nodes are the projection of equispaced points on the upper half-circle onto the horizontal axis.
In Complex Analysis these points are known as the roots of unity.}
\label{fig:cheb_nodes_projection}
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth]{runge_chebyshev.pdf}
\caption{Different polynomial interpolants for the Runge function $\frac{1}{1 + 25 x^2}$ constructed by sampling at the Chebyshev nodes.}
\label{fig:runge_chebyshev}
\end{figure}

\begin{problem}
Write a function that, given the endpoints $a$ and $b$ of an interval and the order of the desired interpolating polynomial returns the $k+1$ Chebyshev nodes on the interval $[ a, b ]$.
\end{problem}

\section*{Chebyshev Polynomials}
This sort of interpolation is also related to what are called the Chebyshev polynomials.
Chebyshev Polynomials can be used very nicely to approximate functions on $[ -1, 1 ]$ and, with proper scaling, can be used to approximate reasonably well-behaved functions on any interval.
The $k$'th Chebyshev polynomial is commonly written $T_k \left( x \right)$.
One way to define the Chebyshev Polynomials is that the $k$'th Chebyshev polynomial on the unit circle is the real part of the function $z^k$ on the unit circle.
More precisely, let $z(x) = t + i \sqrt{1 - x^2}$, then the $k$'th Chebyshev polynomial on $[-1, 1]$ is the real part of the polynomial $x^k$.
We can write this real part explicitly as
\[T_k \left( x \right) = \frac{1}{2} \left( z^k + z^{-k} \right) = \cos \left( k \cos^{-1} \left( x \right) \right)\]
Notice that, as this function has been defined, the Chebyshev polynomial of order $k$ on an interval takes values of $1$ and $-1$ at the $k+1$ chebyshev points corresponding to interpolation with a polynomial of order $k$ on that interval.
The first few Chebyshev polynomials are shown in Figure \ref{fig:cheb_polys}.

\begin{figure}
\includegraphics[width=\textwidth]{cheb_polys.pdf}
\caption{The first few Chebyshev Polynomials.}
\label{fig:cheb_polys}
\end{figure}

These polynomials are orthogonal with respect to the integral inner product
\[\langle f, g \rangle = \int_{-1}^1 \frac{1}{\sqrt{1 - x^2}} f\left( x \right) g\left( x \right) dx\]
This inner product allows us to write many functions as an infinite series of Chebyshev polynomials.
In particular, we can write any polynomial as a finite series of Chebyshev polynomials.
As it turns out, it is relatively easy to compute the Chebyshev series representation of an interpolating polynomial for a function on a given interval.
These approximations converge to the function we are approximating nearly as well as the partial sums of the infinite series formed using the inner product above, so, in practice, we will use them instead.

It can be shown that the Chebyshev polynomials follow the following recurrence relation: $ T_{k+1} \left( x \right) = 2 x T_k \left( x \right) - T_{k-1}$.
$T_0 \left( x \right)$ is equal $1$ and $T_1 \left( x \right)$ is equal to $x$ (still working on the interval $[-1, 1]$.)
This recurrence relation forms the basis for what is known as Clenshaw's Algorithm.
Clensaw's Algorithm says that, given a polynomial of degree $n$ represented as a sum of Chebyshev polynomials:
\[p\left(x\right) = \sum_{k=0}^{n} a_k T_k\left(x\right)\]
$p(x)$ can be evaluated by the recursion process outlined in Algorithm \ref{alg:clenshaw_recursion}.

\begin{algorithm}
\begin{algorithmic}[1]
\Procedure{ClenshawRecursion}{$X, c$}
	\State $u_{n+1} \gets 0$
	\State $u_{n} \gets a_{n}$
	\State $k \gets n-1$
	\While{$k \geq -1$}
		\State $u_k \gets 2 x u_{k+1} - u_{k+2} + a_k$
		\State $k \gets k-1$
	\EndWhile
	\State \pseudoli{return} $\frac{1}{2} \left( a_0 + u_0 - u_2 \right)$
\EndProcedure
\end{algorithmic}
\caption{Clenshaw Recursion}
\label{alg:clenshaw_recursion}
\end{algorithm}

The following recursion is equivalent to Algorithm \ref{alg:clenshaw_recursion}.
Let $u_{n+1} = 0$ and $u_{n} = a_n$ and $u_k = 2 x u_{k+1} - u_{k+2} + a_k$ for $k = n-1, n-2, \dots, 0$, then $p(x) = \frac{1}{2} \left( a_0 + u_0 - u_2 \right)$.

\begin{problem}
Write a Python function that performs Clenshaw's algorithm to evaluate a series of Chebyshev polynomials for an array of points in the interval $[-1, 1]$.
Use it to plot the first $5$ Chebyshev polynomials on that interval.
\end{problem}

\section*{Chebyshev Polynomials and Fourier Series}
In looking at the plots of the Chebyshev polynomials you may have noticed that the Chebyshev polynomials take alternating values of $1$ and $-1$ at the Chebyshev points on the interval $[-1,1]$ similar to how the functions $\cos\left(k x \right)$ change between $-1$ and $1$ on equispaced points in the interval $[ 0 , \pi ]$.
Recall that, as mentioned above, $T_k \left( x \right) = \cos \left( k \cos^{-1} \left( x \right) \right)$.
For discrete samples, this means that the Chebyshev coefficients for the interpolating polynomial through a function at the Chebyshev nodes has the same coefficients as the discrete cosine series would at the points $\cos^{-1} x$ where $x$ is a chebyshev node.
In practice this means we can compute an array of samples of a function at the Chebyshev nodes of the interval $[-1, 1]$, then compute the discrete cosine transform to get the corresponding coefficients to the Chebyshev interpolation.
This is very helpful since the discrete cosine transform is a close relative of the discrete Fourier transform.
\li{scipy.fftpack} and \li{pyfftw} both include discrete cosine transforms as \li{scipy.fftpack.dct} and \li{pyfftw.interfaces.scipy_fftpack.dct} respectively.
The discrete cosine transform is defined a little differently than the coefficients we need here.
To get the coefficients, follow these steps:

\begin{itemize}

\item Sample the function you desire to approximate at the Chebyshev nodes.

\item Compute the discrete cosine transform of the data.
Use the option \li{type=1} to tell either scipy or pyfftw the version of the discrete cosine transform you want to use. (this one is the closest to the version we want).

\item Divide all the coefficients by $\left( N - 1 \right)$ where $N$ is the number of nodes used.

\item Divide the first and last coefficient by $2$.

\item Multiply all the odd indices by $-1$.

\end{itemize}

\begin{problem}
Write a function that, given the samples for a function at the chebyshev nodes for a funciton on an interval computes the coefficients for the Chebyshev representation of the interpolating polynomial through the samples at the Chebyshev nodes.
\end{problem}

\section*{NumPy's Chebyshev Module}

NumPy includes a module for working with Chebyshev polynomials and Chebyshev series alongside its polynomials module.
It does not include all of the functions we had you write today, but it does include many other useful things.
This module includes a Python class for Chebyshev polynomials.
It works much like the poly1d class that is used for polynomials.
Here are a few lines of code that use NumPy's Chebyshev class to evaluate the 20'th Chebyshev polynomial.
We will plot the corresponding function using Matplotlib.
\begin{lstlisting}
import numpy as np
from numpy.random import rand
import numpy.polynomial.chebyshev as ch
from matplotlib import pyplot as plt
coefficients = np.zeros(20)
coefficients[-1] = 1
poly = ch.Chebyshev(coefficients)
X = np.linspace(-1, 1, 2001)
Y = poly(X)
plt.plot(X, Y)
plt.show()
\end{lstlisting}

Here we used the Chebyshev class to evaluate a Chebyshev series.
It also includes other methods that allow you to multiply, divide, differentiate, and integrate Chebyshev series.
We will discuss integration and differentiation later on.
There are also functions that allow you to convert back and forth between Chebyshev series and standard polynomials.

\begin{problem}
\label{prob:cheb_interpolations}
We will briefly consider the rate of convergence of these polynomial approximations.
Compute the coefficients for the interpolating Chebyshev series for the function $\cos x$ on the interval $[-1, 1]$.
This approximation converges very rapidly, so the first $20$ terms or so should be more than enough.
How many of these coefficients have absolute value greater than $10^{-14}$?
How close does your series approximate the actual function?

Now compute the coefficients for a degree $100000$ polynomial approximating the function
\[\sin \left( \frac{1}{x} \right) \sin \left( \frac{1}{\sin \left( \frac{1}{x} \right)} \right) \]
on the interval $[-1, 1]$.
How large are the last $10$ coefficients in the series?
Use NumPy's Chebyshev class to plot this function at $100001$ equispaced points on the interval $[-1, 1]$.
Plot it with the original function.
Compare the two.
How close are they?
Notice how the interpolating polynomial is able to approximate the original function about as well as the discrete sample of the original function.
\end{problem}

Problem \ref{prob:cheb_interpolations} also illustrates an interesting principle.
These series converge more quickly when a function is infinitely differentiable everywhere in the complex plane (the proper term for a function like this is "entire").
For functions that do not satisfy this property, it can be shown (roughly speaking) that the rate of convergence depends on how many times differentiable the function is on the interval of interpolation.
For a less well-behaved function like the one considered in the second half of Problem \ref{prob:cheb_interpolations} the coefficients converge much more slowly.
The last $10$ coefficients for the interpolant of degree $2^{23} - 1$ are still
\begin{lstlisting}
[9.52973125e-08,  -1.89451973e-09,  -7.42182166e-08,
 1.89319137e-09,   5.26564839e-08,  -1.89451836e-09,
 -3.13050802e-08,   1.89319005e-09,   1.03700608e-08,
 -9.47258778e-10]
\end{lstlisting}

% We could add in a problem where they interpolate the PDF of the standard normal distribution and use it to estimate the CDF at different values.
% Given a proper setup, such an approximation gives correct answers to machine precision in about the same amount of time as the version in Scipy.stats.
% The only limitation is that the interpolant is limited to a specific interval instead of allowing approximation anywhere.
% That isn't much of an issue though since the PDF is practically 0 outside a reasonably-sized interval anyway.


\section{Multidimensional Gaussian}
A random variable $X$ in $\mathbb R$ is called Gaussian if $X\sim\mu+\sigma Z$ for $Z\sim\mathcal N(0,1)$.
It has density, as we have seen,
$$f_X(x)=\frac{1}{\sqrt{2\pi\sigma^2}}e^{-(x-\mu)^2/(2\sigma^2)}$$
and we denote this by $X\sim\mathcal N(\mu,\sigma^2)$.
We want to generalize this to higher dimensions.
\begin{definition}
    A random variable $X=(X_1,\ldots,X_n)$ is Gaussian if for any $u\in\mathbb R^n$, $u^\top X$ is Gaussian in $\mathbb R$.\\
    We call $X$ a Gaussian vector.
\end{definition}
Suppose now that we have an $n\times n$ matrix $A$ and $b\in\mathbb R^n$, then $AX+b$ is also Gaussian.
This is obvious from definition.\\
Set
$$\mu=\mathbb E[X]=\begin{pmatrix}
    \mathbb E[X_1]\\
    \vdots\\
    \mathbb E[X_n]
\end{pmatrix},V=\operatorname{Var}(X)=\mathbb E[(X-\mu)(X^\top-\mu)]=(\operatorname{Cov}(X_i,X_j))_{i,j}$$
Let $u\in\mathbb R^n$, then $\mathbb E[u^\top X]=u^\top\mu$ and the variance is $\operatorname{Var}(u^\top X)=u^\top Vu$, so $u^\top X\sim\mathcal N(u^\top\mu,u^\top Vu)$.
$V$ is symmetric as $\operatorname{Cov}$ is, also by above $u^\top Vu$ is always nonegative, so $V$ is nonnegative definite.
We want to know the MGF of $X$.
Let $\lambda\in\mathbb R^n$, then $m(\lambda)=\mathbb E[e^{\lambda^\top X}]$, but we know the distribution of $\lambda^\top X$ which is $\mathcal N(u^\top\mu,u^\top Vu)$, therefore $m(\lambda)=e^{\lambda^\top\mu+\lambda^\top V\lambda/2}$.
So by uniqueness of MGFs, we see that the distribution of a Gaussian vector is uniquely characterized by its mean $\mu$ and variance $V$, so we write $X\sim\mathcal N(\mu,V)$.\\
As $V$ is real symmetric and nonnegative definite, we can write $V=U^\top DU$ where $U$ is real orthogonal and $D=\operatorname{diag}(\lambda_1,\ldots,\lambda_n)$ where $\lambda_i\ge 0$ for all $i$.
So we define the square root matrix of $V$ to be
$$\sigma=U^\top \sqrt{D}U,\sqrt{D}=\operatorname{diag}(\sqrt{\lambda_1},\ldots,\sqrt{\lambda_n})$$
So $\sigma^2=V$, therefore we can write $X\sim\mathcal N(\mu,\sigma^2)$.\\
Let $Z_1,\ldots,Z_n$ be i.i.d. $\mathcal N(0,1)$ and $Z=(Z_1,\ldots,Z_n)^\top$, then $Z$ is Gaussian (by e.g. looking at its MGF) and $Z\sim\mathcal N(0,I)$.
Let $X=\mu+\sigma Z$ where $\mu\in\mathbb R^n$ and $\sigma$ is real symmetric and nonnegative definite, then $X$ is Gaussian since $x\mapsto \mu+\sigma x$ is linear.
Also $\mathbb E[X]=\mu$ and
$$\operatorname{Var}(X)=\mathbb E[(X-\mu)(X-\mu)^\top]=\sigma\mathbb E[ZZ^\top]\sigma=\sigma I\sigma=\sigma^2$$
So $X\sim\mathcal N(\mu,\sigma^2)$.\\
We want to find the density function of a multivariate normal.
Assuming that $V$ is positive definite and $X\sim\mathcal N(\mu,V)$, then $\det V=\prod_i\lambda_i>0$.
Also since $X=\mu+\sigma Z$, we can invert to get $Z=\sigma^{-1}(X-\mu)$, hence
\begin{align*}
    f_X(x)&=f_Z(z)|J|\\
    &=\prod_{i=1}^n\frac{e^{-z_i^2/2}}{\sqrt{2\pi}}\det(\sigma^{-1})=\frac{1}{\sqrt{(2\pi)^n\det V}}e^{-z^\top z/2}\\
    &=\frac{1}{\sqrt{(2\pi)^n\det V}}e^{-(x-\mu)^\top V^{-1}(x-\mu)/2}
\end{align*}
If we only assume $V$ is nonnegative definite, then we can have $0$ eigenvalues hence $0$ determinant.
In this case, we can change the basis to get something of the form
$$\begin{pmatrix}
    U&0\\
    0&0
\end{pmatrix}$$
where $U$ is positive definite $m\times m$ matrix and $\mu=(\lambda^\top,\nu^\top)^\top$ where $\lambda\in\mathbb R^m,\nu\in\mathbb R^n$, then we write $X=(Y^\top,\nu^\top)^\top$ where $Y$ has
$$f_Y(y)=\frac{1}{\sqrt{(2\pi)^n\det U}}e^{-(y-\lambda)^\top U^{-1}(y-\lambda)/2}$$
\begin{proposition}
    Let $X=(X_1,\ldots,X_n)$ be Gaussian, and suppose that $\operatorname{Cov}(X_i,X_j)=0$ when $i\neq j$, then $X_i$ are independent Gaussians.
\end{proposition}
Note that the converse is obviously true.
\begin{proof}
    The covariant matrix is diagonal, so the density factorizes.
\end{proof}
Another way to see it is by simply looking at the MGF.\\
Now we consider the bivariate Gaussians.
Suppose $X=(X_1,X_2)$ is Gaussian and we set $\mu_k=\mathbb E[X_k],\sigma_k=\sqrt{\operatorname{Var}(X_k)}$ and suppose $\sigma_k>0$, we define
$$\rho=\operatorname{corr}(X_1,X_2)=\frac{\operatorname{Cov}(X_1,X_2)}{\sqrt{\operatorname{Var}(X_1)\operatorname{Var}(X_2)}}$$
Hence we have
$$V=\operatorname{Var}(X)=\begin{pmatrix}
    \sigma_1^2&\rho\sigma_1\sigma_2\\
    \rho\sigma_1\sigma_2&\sigma_2^2
\end{pmatrix}$$
We want to show that $V$ is nonnegative definite for any $\rho$.
Indeed, for any $x=(x_1,x_2)^\top$, we have $x^\top Vx\ge 0$ by calculation.
in particular, if $\rho=0$ and $\sigma_k>0$, then $f_{X_1,X_2}(x_1,x_2)$ can be found by multiplying the $\mathcal N(\mu_k,\sigma_k)$ since $X_1,X_2$ are independent as we have seen before.\\
Let $a\in\mathbb R$, then $\operatorname{Cov}(X_2-aX_1,X_1)=\operatorname{Cov}(X_1,X_2)-a\operatorname{Var}(X_1)=\rho\sigma_1\sigma_2-a\sigma_1^2$.
Take $a=\rho\sigma_1/\sigma_2$ and $Y=X_2-aX_1$, then $\operatorname{Cov}(X_1,Y)=0$ and we can write
$$\begin{pmatrix}
    X_1\\
    Y
\end{pmatrix}=\begin{pmatrix}
    1&0\\
    -a&1
\end{pmatrix}\begin{pmatrix}
    X_1\\
    X_2
\end{pmatrix}$$
So $(X_1,Y)^\top$ is also Gaussian.
$X_1,Y$ are independent and we can write $X_2=Y+aX_1$ and $\mathbb E[X_2|X_1]=\mathbb E[Y]+aX_2$.
\begin{theorem}
    Let $X$ be a Gaussian vector in $\mathbb R^k$ with finite variance.
    Suppose $X$ has covariance matrix $\Sigma$.
    Let $X_1,\ldots$ be i.i.d. copies of $X$, then
    $$S_n=\frac{1}{\sqrt{n}}\sum_{i=1}^n(X_i-\mathbb E[X_i])\to\mathcal N(0,\Sigma)$$
    in the sense that for any (measurable) $B\in\mathbb R^k$, $\mathbb P(S_n\in B)\to \mathbb P(\mathcal N(0,\Sigma)\in B)$.
\end{theorem}


\section{Uniqueness of the {\rref}}

\begin{outcome}
  \begin{enumerate}
  \item Determine whether two systems of equations are row equivalent,
    by comparing their {\rref}.
  \item For two homogeneous systems of equations that are not row
    equivalent, find a solution to one system that is not a solution
    to the other.
  \end{enumerate}
\end{outcome}

We have seen in earlier sections that every matrix can be brought into
{\rref} by a sequence of elementary row operations. Here we will prove
that the resulting matrix is unique; in other words, the resulting
matrix in {\rref} does not depend upon the particular sequence of
elementary row operations or the order in which they were performed.

Let $A$ be the augmented matrix of a homogeneous system of linear
equations in the variables $x_1, x_2,\ldots, x_n$ which is also in
{\rref}. Recall that the matrix $A$ divides the set of variables in
two different types: $x_i$ is a {\em pivot variable}%
\index{variable!pivot} when column $i$ is a pivot column, and a {\em
  free variable}%
\index{variable!free} otherwise.

\begin{example}{Pivot and free variables}{pivot-free}
  Find the pivot and free variables in the following system, and find
  the general solution.
  \begin{equation*}
    \begin{array}{c}
      x+2y-z+w=0 \\
      x+y-z+w=0 \\
      x+3y-z+w=0
    \end{array}
  \end{equation*}
\end{example}

\begin{solution}
  The {\rref} of the augmented matrix is
  \begin{equation*}
    \begin{mymatrix}{rrrr|r}
      \circled{1} & 0 & -1 & 1 & 0 \\
      0 & \circled{1} & 0 & 0 & 0 \\
      0 & 0 & 0 & 0 & 0
    \end{mymatrix}.
  \end{equation*}
  From this, we see that columns $1$ and $2$ are pivot
  columns. Therefore, $x$ and $y$ are pivot variables and $z$ and $w$
  are free variables. We can write the solution to this system as
  \begin{equation*}
    \begin{array}{r@{~}c@{~}l}
      x &=& s-t \\
      y &=& 0 \\
      z &=& s \\
      w &=& t.
    \end{array}
  \end{equation*}
\end{solution}

In general, all solutions can be written in terms of the free
variables. In such a description, the free variables are written as
parameters, while the pivot variables are written as functions of
these parameters. Indeed, a pivot variable $x_i$ is a function of {\em
  only} those free variables $x_j$ with $j>i$. This leads to the
following observation.

\begin{proposition}{Pivot and free variables}{pivot-free}
  If $x_i$ is a pivot variable of a homogeneous system of linear
  equations, then any solution of the system with $x_j=0$ for all
  those free variables $x_j$ with $j>i$ must also have $x_i=0$.
\end{proposition}

Using this proposition, we prove a lemma which will be used in the
proof of the main result of this section.

\begin{lemma}{Solutions and the {\rref} of a matrix}{rref-solutions}
  Let $A$ and $B$ be two augmented matrices for two homogeneous
  systems of $m$ equations in $n$ variables, such that $A$ and $B$ are
  each in {\rref}. If $A$ and $B$ are different, then the two systems
  do not have exactly the same solutions.
\end{lemma}

\begin{proof}
  With respect to the linear systems associated with the matrices $A$ and $B$, there are two cases to consider:
  \begin{itemize}
  \item Case $1$: the two systems have the same pivot variables
  \item Case $2$: the two systems do not have the same pivot variables
  \end{itemize}
  In case $1$, the two matrices will have exactly the same pivot
  positions. However, since $A$ and $B$ are not identical, there is
  some row of $A$ which is different from the corresponding row of $B$
  and yet the rows each have a pivot in the same column position. Let
  $i$ be the index of this column position. Since the matrices are in
  {\rref}, the two rows must differ at some entry in a column
  $j>i$. Let these entries be $a$ in $A$ and $b$ in $B$, where
  $a \neq b$. Since $A$ is in {\rref}, if $x_j$ were a pivot variable
  for its linear system, we would have $a=0$. Similarly, if $x_j$ were
  a pivot variable for the linear system of the matrix $B$, we would
  have $b=0$. Since $a$ and $b$ are unequal, they cannot both be equal
  to $0$, and hence $x_j$ cannot be a pivot variable for both linear
  systems. However, since the systems have the same pivot variables,
  $x_j$ must then be a free variable for each system. We now look at
  the solutions of the systems in which $x_j$ is set equal to $1$ and
  all other free variables are set equal to $0$. For this choice of
  parameters, the solution of the system for matrix $A$ has $x_i=-a$,
  while the solution of the system for matrix $B$ has $x_i=-b$, so
  that the two systems have different solutions.

  In case $2$, there is a variable $x_i$ which is a pivot variable for
  one matrix, let's say $A$, and a free variable for the other matrix
  $B$. The system for matrix $B$ has a solution in which $x_i=1$ and
  $x_j=0$ for all other free variables $x_j$. However, by
  Proposition~\ref{prop:pivot-free} this cannot be a solution of the
  system for the matrix $A$. This completes the proof of case $2$.
\end{proof}

Now, we say that the matrix $B$ is \textbf{row equivalent}%
\index{matrix!row equivalence}%
\index{row equivalence}%
\index{equivalence!row equivalence}
to the matrix $A$ if $B$ can be obtained from
$A$ by performing a sequence of elementary row operations. By
Theorem~\ref{thm:elementary-operations-and-solutions}, we know that row
equivalent systems have exactly the same solutions. Now, we can use
Lemma~\ref{lem:rref-solutions} to prove the main result of this
section, which is that each matrix $A$ has a unique {\rref}.

\begin{theorem}{Uniqueness of the {\rref}}{unique-rref}
  Every matrix $A$ is row equivalent to a unique matrix in {\rref}.
\end{theorem}

\begin{proof}
  By Gauss-Jordan elimination, we already know that every matrix is
  row equivalent to some {\rref}. What we must show is that the
  resulting {\rref} is unique, i.e., does not depend on the order in
  which row operations are performed.

  Therefore, let $A$ be an $m \times n$-matrix and let $B$ and $C$ be
  matrices in {\rref}, each row equivalent to $A$. We have to show
  that $B=C$.

  Let $A^{+}$ be the matrix $A$ augmented with a new rightmost column
  consisting entirely of zeros. Similarly, augment matrices $B$ and
  $C$ each with a rightmost column of zeros to obtain $B^{+}$ and
  $C^{+}$. Note that $B^{+}$ and $C^{+}$ are augmented matrices in
  {\rref}, and that both $B^{+}$ and $C^{+}$ are row equivalent to
  $A^{+}$, because the addition of a column of zeros does not change
  the effect of any row operations.

  Now, $A^{+}$, $B^{+}$, and $C^{+}$ can all be considered as
  augmented matrices of homogeneous linear systems in the variables
  $x_1, x_2,\ldots, x_n$. Because all three systems are row
  equivalent, they have exactly the same solutions. By
  Lemma~\ref{lem:rref-solutions}, we conclude that $B^{+}=C^{+}$.
  Omitting the final column of zeros, we must also have $B=C$.
\end{proof}

\begin{example}{Row equivalent systems}{determinant-row-equivalent}
  Determine whether the following two systems of equations are row
  equivalent.
  \begin{equation*}
    \begin{array}{r@{~}c@{~}l}
      2x + 3y + z &=& 12 \\
      x - 2y + 4z &=& -1 \\
      x + 2z &=& 3,
    \end{array}
    \quad\quad
    \begin{array}{r@{~}c@{~}l}
      x + 2y &=& 7 \\
      3x - y + 7z &=& 7 \\
      y - z &=& 2.
    \end{array}
  \end{equation*}
\end{example}

\begin{solution}
  The augmented matrices for the two systems are:
  \begin{equation*}
    \begin{mymatrix}{rrr|r}
      2 & 3 & 1 & 12 \\
      1 & -2 & 4 & -1 \\
      1 & 0 & 2 & 3
    \end{mymatrix},
    \quad\quad
    \begin{mymatrix}{rrr|r}
      1 & 2 & 0 & 7 \\
      3 & -1 & 7 & 7 \\
      0 & 1 & -1 & 2
    \end{mymatrix}.
  \end{equation*}
  The {\rref}s of the two augmented matrices are:
  \begin{equation*}
    \begin{mymatrix}{rrr|r}
      1 & 0 & 2 & 3 \\
      0 & 1 & -1 & 2 \\
      0 & 0 & 0 & 0
    \end{mymatrix},
    \quad\quad
    \begin{mymatrix}{rrr|r}
      1 & 0 & 2 & 3 \\
      0 & 1 & -1 & 2 \\
      0 & 0 & 0 & 0
    \end{mymatrix}.
  \end{equation*}
  Since both systems have the same {\rref}, they are row equivalent.
\end{solution}

\begin{example}{Non-row equivalent systems}{non-row-equivalent}
  Determine whether the following two systems of equations are row
  equivalent. If they are not row equivalent, find a solution to one
  system that is not a solution to the other.
  \begin{equation*}
    \begin{array}{r@{~}c@{~}l}
      x - 2y - 5z &=& 0 \\
      x + z &=& 0 \\
      x + y + 4z &=& 0,
    \end{array}
    \quad\quad
    \begin{array}{r@{~}c@{~}l}
      2x + 2y + z &=& 0 \\
      x + y + 3z &=& 0 \\
      -x - y + 2z &=& 0.
    \end{array}
  \end{equation*}
\end{example}

\begin{solution}
  The augmented matrices for the two systems are:
  \begin{equation*}
    \begin{mymatrix}{rrr|r}
      1 & -2 & -5 & 0 \\
      1 & 0 & 1 & 0 \\
      1 & 1 & 4 & 0
    \end{mymatrix},
    \quad\quad
    \begin{mymatrix}{rrr|r}
      2 & 2 & 1 & 0 \\
      1 & 1 & 3 & 0 \\
      -1 & -1 & 2 & 0
    \end{mymatrix}.
  \end{equation*}
  The {\rref}s of the two augmented matrices are:
  \begin{equation*}
    \begin{mymatrix}{rrr|r}
      1 & 0 & 1 & 0 \\
      0 & 1 & 3 & 0 \\
      0 & 0 & 0 & 0
    \end{mymatrix},
    \quad\quad
    \begin{mymatrix}{rrr|r}
      1 & 1 & 0 & 0 \\
      0 & 0 & 1 & 0 \\
      0 & 0 & 0 & 0
    \end{mymatrix}.
  \end{equation*}
  Since the two systems have different {\rref}s, they are not row
  equivalent.  Following the proof of Lemma~\ref{lem:rref-solutions},
  we see that $z$ is a free variable for the first system, but a pivot
  variable for the second system. Therefore, there exists a solution
  of the first system with $z=1$, namely $(x,y,z) = (-1,-3,1)$. But
  there exists no solution for the second system with $z=1$, and in
  particular, $(x,y,z) = (-1,-3,1)$ is not a solution of the second
  system.
\end{solution}

We finish this section by pointing out an important consequence of
Theorem~\ref{thm:unique-rref}, namely that the rank%
\index{rank} of a matrix is well-defined. Recall that in
Definition~\ref{def:rank}, we defined the rank of a matrix $A$ to be
the number of pivot entries of ``any'' {\ef} of $A$. It was not clear,
however, why different {\ef}s of $A$ could not have different numbers
of pivot entries. Now we can answer this question. By the Gauss-Jordan
algorithm, we know that every {\ef} can be converted to a {\rref}
without changing the number or position of the pivots. Since the
{\rref} is unique, it follows that all {\ef}s of $A$ have the same
number of pivot entries (and in fact the same pivot
columns). Therefore, the rank of $A$ is a well-defined quantity.


\section{Periodic Scheduling}
Periodic scheduling is always preemptive.
\begin{center}
	{\renewcommand{\arraystretch}{2}
	\begin{tabular}{|c|c|c|}
		\hline
							& Deadline = Period	& Deadline $\leq$ Period	\tabularnewline\hline
		Static Priority		& Rate Monotonic	& Deadline Monotonic		\tabularnewline\hline
		Dynamic Priority	& EDF				& EDF*						\tabularnewline\hline
	\end{tabular}}
\end{center}

\subsection{Definitions}
\begin{itemize}
	\item $\Gamma = \set{\tau_1, \tau_2, \dots \tau_n}$	is set of periodic tasks.
	\item $\tau_{i,j}$ is the $j$-th instance of task $\tau_i$.
	\item $a_{i,j}, r_{i,j}, d_{i,j}, s_{i,j}, f_{i,j}$ are the same as for aperiodic tasks.
	\item $\Phi_i$ is the phase of task $i$ (release time of the first instance).
	\item $D_i$ is the relative deadline of task $i$.
	\item $T_i$ is the period of the task (time between 2 releases).
\end{itemize}

The following hypotheses are assumed
\begin{itemize}
	\item $r_{i,j} = \Phi_i + (j - 1) T_i$
	\item $C_i$ is constant.
	\item $d_{i,j} = \Phi_i + (j - 1) T_i + D_i$
	\item The tasks are independent
\end{itemize}

\subsection{Rate Monotonic}
Always schedule the task that has the shortest period.
Sufficient (but not necessary) schedulability test:
\begin{equation*}
	\sum_{i = 1}^n \frac{C_i}{T_i} \leq n \left( 2^{\frac{1}{n}} - 1 \right)
\end{equation*}

\subsection{Deadline Monotonic}
Always schedule the task that has the shortest relative deadline.
Sufficient (but not necessary) schedulability test:
\begin{equation*}
	\sum_{i = 1}^n \frac{C_i}{D_i} \leq n \left( 2^{\frac{1}{n}} - 1 \right)
\end{equation*}

\subsection{Necessary and sufficient schedulability test}
We define the interference $I_i$ for task $i$ as
\begin{equation*}
	I_i(t) = \sum_{j = 1}^{i - 1} \ceil{\frac{t}{T_j}} C_j
\end{equation*}
where the tasks are ordered such that $m < n \iff D_m < D_n$

\subsubsection{Algorithm}
The tasks are ordered as described above.
\begin{lstlisting}[escapeinside={(*}{*)}]
foreach ((*$\tau_i$*) (*$\in$*) (*$\Gamma$*)) {
	I = 0;
	do {
		R = I + (*$C_i$*);
		if (R > (*$D_i$*)) return false; // unschedulable
		I = (*$\sum\limits_{j = 1}^{i - 1} \ceil{\frac{\mathrm{R}}{T_j}} C_j$*);
	} while (I + (*$C_i$*) > R);
}
return true;
\end{lstlisting}
The final values \texttt{R} are the longest response times.

\subsection{EDF}
Always schedule the task with the earliest deadline.
For $D_i = T_i$ the tasks are schedulable with EDF iff
$\sum\limits_{i = 1}^{n} \frac{C_i}{T_i} = U \leq 1$.

If $D_i \leq T_i$, then the test
$\sum\limits_{i = 1}^{n} \frac{C_i}{D_i} \leq 1$ is sufficient but not
neccesary.


\documentclass[../../main.tex]{subfiles}
\begin{document}
\section{Definitions and preliminaries}

In the course of this thesis, we will among others need the following definitions.

%%%%%%%%%%%%%%%%   Partition  %%%%%%%%%%%%%%%%

\begin{definition}
A partition of a set $A$, is a family, $\{A_{i}\}_{i\in \N}$ of subsets of $A$, satisfying:
\begin{itemize}
\item $A_{i} \cap A_{j} = \emptyset$ for all $i, j\in \N$ with $i \neq j$,
\item $\bigcup_{i\in \N} A_{i}=A$.
\end{itemize}
\end{definition}

%%%%%%%%%%%%%%%%   Sigma-algebra, measurable space, and measures  %%%%%%%%%%%%%%%%

\begin{definition}
A $\sigma$-algebra, $\m{A}$, on a set $X$, is a family of subsets of $X$ satisfying
\begin{itemize}
\item $X\in \m{A}$,
\item $A \in \m{A} \Rightarrow A^{c}\in \m{A}$,
\item $A_{1}, A_{2}, \dots \in \m{A} \Rightarrow \bigcup_{i\in \N} A_{i} \in \m{A}$.
\end{itemize}
\end{definition}

If $\m{A}$ is a $\sigma$-algebra on $X$, we call $(X, \m{A})$ a measurable space.

\begin{definition}
Let $(X,\m{A})$ be a measurable space. A (positive) measure is a set function $\mu:\m{A} \to [0,\infty]$ satisfying:
\begin{itemize}
\item $\mu(\emptyset) = 0$,
\item For all collections $\{A_{i}\}_{i\in N}$ of pairwise disjoint sets,
\begin{align*}
	\mu\left(\bigcup_{i\in \N} A_{i}\right) = \sum_{i\in \N} \mu(A_{i})
\end{align*}
\end{itemize}
The last property is called \textbf{countable additivity} or $\textbf{$\mathbf{\sigma}$-additivity}$.
\end{definition}

If $\mu:(X,\m{A})\to [0, \infty]$ is a measure, we call $(X, \m{A}, \mu)$ a measure space. However this notation is at times cumbersome, so often we will just denote the measure(-able) space: $\m{A}$ when the set and measure in question is obvious or subordinate.

We can generalize the notion of a positive measure by the following

\begin{definition}
A real (or signed) measure on a $\sigma$-algebra $\m{A}$, is a set function $\mu: \m{A} \to [-\infty, \infty]$ which is countably additive, and where $\mu(\emptyset)=0$. Since a real measure is countably additive, it can take on the value $+\infty$ or $-\infty$ but not both.
\end{definition}

\begin{definition}
Let $(X, \m{A})$ be a measurable space, and $Y$ a topological space. A mapping $f: X \to Y$ is said to be measurable if $f^{-1}(U)\in \m{A}$ for all open sets $U$ in $Y$.
\end{definition}

\begin{definition}
A subset $A$ of a set $X$ is called convex if for any $x,y \in A$, and all $\alpha \in (0,1)$ we have
\begin{align*}
	\alpha x + (1-\alpha)y \in A
\end{align*}
\end{definition}

\begin{theorem}\label{thm: average lies in S}
Suppose $\mu$ is a finite positive measure on a measurable space $(X, \m{A})$, $f\in L^{1}(\mu)$, $S$ is a closed set in $\C$, and the averages
\begin{align*}
	A_{B}(f)=\frac{1}{\mu(B)}\int_{B}fd\mu
\end{align*}
lie in $S$ for every $B\in \m{A}$ with $\mu(B)>0$. Then $f(x)\in S$ for $\mu$ almost all $x \in X$.
\end{theorem}
\begin{proof}
For $r>0$, let $\Delta=\overline{B(\alpha, r)}\subseteq S^{c}$. Since $S^{c}$ is the union of countably many such discs, it is enough to prove that $\mu(B)=0$, where $B=f^{-1}(\Delta)$.

If $\mu(B)>0$, we would have
\begin{align*}
	|A_{B}(f)-\alpha| = \frac{1}{\mu(B)} \left| \int_{B}(f-\alpha)d\mu \right| \le \frac{1}{\mu(B)} \int_{B}|f-\alpha|d\mu \le r,
\end{align*}
which is impossible, since $A_{B}(f)\in S$ by assumption. Hence $\mu(B)=0$.
\end{proof}

\begin{definition}\label{def: regular}
A Borel measure $\mu$ on a topological space $(X, \tau)$, is a measure defined on all open sets, $U\in \tau$, hence defined on all the Borel sets. A non-negative Borel measure on a locally compact Hausdorff space $X$ is called regular if
\begin{enumerate}
\item $\mu(K)<\infty$ for every compact $K$,
\item (Outer regularity) For every Borel set $A$
\begin{align*}
	\mu(A)=\inf\{ \mu(U) | A\subseteq U, U \text{ open} \}
\end{align*}
\item (Inner regularity) For every open set $A$, or measurable set $A\in \m{A}$ with $\mu(A)<\infty$
\begin{align*}
	\mu(A)=\sup\{ \mu(K) | K\subseteq A, K \text{ compact} \}.
\end{align*}
\end{enumerate}
\end{definition}

We state without proof the following theorem, which we prove in a more general case in \cref{thm: Riesz-markov}.

\begin{theorem}[Riesz-Markov-Kakutani representation theorem]\label{thm: Riesz-Markov-Kakutani representation theorem}
Let $X$ be a locally compact Hausdorff space, and let $T$ be a positive linear functional on $C_{c}(X)$. Then there exists a $\sigma$-algebra $\m{A}$ in $X$ which contains all Borel sets in $X$, and there exists a unique regular positive measure $\mu$ on $\m{A}$ satisfying
\begin{align*}
	Tf=\int_{X}fd\mu
\end{align*}
for every $f\in C_{c}(X)$.
\end{theorem}

To clarify, a positive linear functional, $T$, is a linear functional satisfying that if $f(X)\subseteq [0,\infty)$, then $T(f)\in [0,\infty)$.

\end{document}


\lesson{2}{Oct 12 2021 Tue (09:23:42)}{Factoring by Grouping}{Unit 2}

\subsubsection*{Factoring by Grouping (Four-Term Polynomials) }

Let's just jump into an example:

\begin{example}[Factor $30c^3 - 20c^2 - 15c + 10$]
    \begin{align}
        30c^2 - 20c^2 -15c + 10 &= 5(6c^3 - 4c^2 - 3c + 2) \\
                                &= 5[2c^2 (3c - 2) - 1 (3c - 2)] \\
                                &= 5[2c^2 (3c - 2) - 1 = (3c - 2)] \\
                                &= 5(3c - 2)(2c^2 - 1)
    \end{align}
\end{example}

\newpage


% jam 2004-08-28

\section{Simplex Volume}
\label{sec:simplex_volume}

\nocite{graphics-gems-4-1994}
\nocite{goodman-orourke-hdcg-2004}

This section describes how to compute
the volume of a $m$-simplex in $\Reals^n$ (with $m \le n$)
and its derivatives with respect to the vertex positions.
In what follows, let $S$ be the geometric $m$-simplex
spanned by the $m+1$ points $\{\p_0  \ldots  \p_m\}$,
where $\p_i \in \Reals^n$.
As in \autoref{sec:barycentric-coordinates},
let $\v_i = (\p_i - \p_m); i = 0 \ldots (m-1)$
and ${\mathbf V} = \sum_{i=0}^{m-1} \v_i \otimes \e_i$
(which can be represented by a matrix whose columns are the $\v_i$).

To simplify the discussion, I will describe computing the
value of the volume form: $\rho(S) = m! \volume(S)$,
which is the volume of the parallelpiped with sides $\v_i$.

Most discussions of simplex volume consider
only the case of a $n$-simplex in $\Reals^n$.
In that case, the $\rho(S) = \det({\mathbf V)}$
\cite{henk-richter-gebet-ziegler-hdcg-16-2004}.

When $m < n$, ${\mathbf V}$ is no longer square,
so $\det({\mathbf V})$ doesn't work.
Hanson \cite{hanson-1994} suggests:
\begin{equation}
\rho(S)^2 = \det({\mathbf V}^{\dagger} {\mathbf V})
\end{equation}


\subsubsection{Toy Example}
\noindent
Say we wish to maximize $f(x,y) = x+y$ subject to the constraint $g(x,y) = x^2 + y^2 = 1$.
We can do this y finding the C-level curve that is tangent to our constraint, as this curve will have the extrema.\\
At this point, $\nabla f$ will be in the same direction as $\nabla g$.
That is,
\begin{equation*}
	\begin{cases}
		f_x = \lambda g_x \\
		f_y = \lambda g_y
	\end{cases}.
\end{equation*}
We also add the constraint itself, $g(x,y)$ equals some constant $k$, giving us a system of equations
\begin{equation*}
	\begin{cases}
		f_x = \lambda g_x \\
		f_y = \lambda g_y \\
		g(x,y)=k
	\end{cases}.
\end{equation*}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.33\textwidth]{./differentialMultivariableCalculus/lagrange_slice.png}
	\includegraphics[width=0.33\textwidth]{./differentialMultivariableCalculus/lagrange_curves.png}
	\caption{Extremas when the constraints (black) are tangent to the level curves.}
\end{figure}


%
% Chapter Two
%

\chapter{STELLAR REACTION RATES}

\section{Introduction}
Consider a nuclear reaction A(a,b)B, with number densities $n_A$ and $n_a$ in units of particles per volume, respectively. The flux $j$ of particles $a$ with a relative velocity $v$ will be
 \begin{equation}
    \label{j_a}
    \begin{aligned}
        j = n_a v
    \end{aligned}
\end{equation}
in units of particles per unit area per unit time. So the scatterings per unit time will be the product of $j$ and the cross-section $\sigma$ i.e. $j \sigma=\sigma n_a v$ for one target nucleus. Therefore, the total reaction rate per second per unit volume $r_{Aa}$ can be expressed as
 \begin{equation}
    \label{r12}
    \begin{aligned}
    r_{Aa}=n_a n_A \sigma v
    \end{aligned}
\end{equation}

In the stellar plasma, the relative velocity between interacting particles $v$ is represented by a velocity distribution $\varphi(v)$  normalized by $\int_{0}^{\infty}\varphi(v)dv=1$. Then the average scattering rate will be
 \begin{equation}
    \label{sigmav_0}
    \begin{aligned}
    \langle \sigma v\rangle = \int_{0}^{\infty}\sigma(E) \varphi(v) v dv
    \end{aligned}
\end{equation}
which is also known as the reaction rate per particle pair.
%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

In a normal stellar environment, the plasma is in thermodynamic equilibrium and particles are interacting under non-relativistic mechanics. The velocity distribution of nuclei, therefore, can be described by the Maxwell-Boltzmann velocity distribution given by
\begin{equation}
    \label{MB}
    \begin{aligned}
        \varphi(v)= 4 \pi v^2 (\frac{m}{2\pi kT})^{3/2} \exp(-\frac{mv^2}{2kT})
    \end{aligned}
\end{equation}
where $T$ refers to the plasma temperature, $m$ to the mass of the nucleus and $k$ to the Boltzmann constant.

The reaction rate per pair of particles, $\langle \sigma v \rangle$, as defined, is the double integral over two velocity distributions:
\begin{equation}
    \label{reactionrate1}
    \begin{aligned}
         \langle \sigma v \rangle=\iint \sigma(v)v\varphi(v_a)\varphi(v_A)dv_adv_A
    \end{aligned}
\end{equation}
where $v_a$ and $v_A$ are the velocity of the projectile and the target, respectively. These individual velocities can be represented in terms of $v$ and $V$(the center of mass velocity of particles a and A) using the kinematic relations:
\begin{equation}
    \label{kinematics}
    \begin{aligned}
        v_a = V + \dfrac{m_A}{m_a + m_A}  v  \\
        v_A = V - \dfrac{m_a}{m_a + m_A}  v
    \end{aligned}
\end{equation}
The reaction rate then becomes
\begin{equation}
    \label{reactionrate_cm}
    \begin{aligned}
        \langle \sigma v \rangle=\iint \sigma(v)v\varphi(V)\varphi(v)dVdv
    \end{aligned}
\end{equation}
where the transformed velocity distributions $\varphi(V)$ and $\varphi(v)$ are
\begin{equation}
    \label{V}
    \begin{aligned}
        \varphi(V)=4\pi V^2 (\frac{M}{2\pi kT})^{3/2} \exp(-\frac{MV^2}{2kT})
    \end{aligned}
\end{equation}
\begin{equation}
    \label{v}
    \begin{aligned}
        \varphi(v)=4\pi v^2 (\frac{\mu}{2\pi kT})^{3/2} \exp(-\frac{\mu v^2}{2kT})
    \end{aligned}
\end{equation}
where $M=m_a+m_A$, $\mu=m_a m_A/(m_a + m_A)$ and $m_i$  refer to the total mass, the reduced mass of the reacting particles and the masses of the particle $i$, respectively. Notice that Eq.~\ref{reactionrate_cm} is the integral of two independent Maxwell-Boltzmann distributions and the cross-section $\sigma$ should only depend on the relative velocity $v$. Along with the normalized velocity $\int_{0}^{\infty} \varphi(V)dV=1$, Eq.~\ref{reactionrate_cm} can be reduced to:
 \begin{equation}
    \label{reactionrate3}
    \begin{aligned}
        \langle \sigma v \rangle =\int_{0}^{\infty} \sigma(v)v\varphi(v)dv
    \end{aligned}
\end{equation}
Inserting Eq.~\ref{v} one gets
\begin{equation}
    \label{reactionrate4}
    \begin{aligned}
        \langle \sigma v \rangle = 4\pi (\frac{\mu}{2\pi kT})^{3/2} \int_{0}^{\infty}v^3 \sigma(v) \exp(\frac{\mu v^2}{2kT})dv
    \end{aligned}
\end{equation}
Converting the relative velocity $v$ to the center of mass energy $E$ by $E=\dfrac{1}{2}\mu v^2$ and substituting it into Eq.~\ref{reactionrate4} one can obtain the energy-dependent reaction rate:
\begin{equation}
    \label{crosssection_1}
    \begin{aligned}
        \langle \sigma v \rangle = (\frac{8}{\pi \mu})^{1/2}(\frac{1}{kT})^{3/2} \int_{0}^{\infty} \sigma(E) E \exp(-E/kT)dE
    \end{aligned}
\end{equation}
The integrand $E\sigma(E)\exp(-E/kT)$ is called the Gamow distribution function, which shows how the energy dependence of the cross-section is weighted by the thermal distribution of energies in the reaction rate.

The mathematical methods for determining reaction rates by Eq.~\ref{crosssection_1} depends on the energy-dependent cross-section $\sigma(E)$, which can be nonresonant or resonant. Cross-sections of the nonresonance part vary slowly with relative energies $E$, while the resonant parts of the cross-sections are sharply peaked. Both contributions will be discussed in the following sections.

\subsection{Charged-Particle Nonresonance Reaction}

%decreb
For charged-particle reactions, the Coulomb potential and the nuclear potential are equally important so that both need to be taken into consideration.
At astrophysically interesting low energy region, there are two approximations of  $\sigma(E)$ that are non-nuclear energy-dependent.  The first approximation is
\begin{equation}
    \begin{aligned}
        \sigma(E) \propto \pi \lambda^2  \propto \frac{1}{E}
    \end{aligned}
\end{equation}
where the de Broglie wavelength $\lambda$ indicates the fact that  the  cross-section depends on the physical size of the particle.

The second approximation is about the Coulomb penetrability. The cross-section for charged-particle-induced nuclear reactions drops rapidly below the Coulomb barrier as the tunneling probability drops exponentially with decreasing energy:
\begin{equation}
    \begin{aligned}
        \sigma(E) \propto \exp(-2\pi z_a Z_A e^2\hbar v) = \exp (-2\pi \eta)
    \end{aligned}
\end{equation}
where $z_a$ and $Z_A$ are the nuclear charges of projectile and target respectively, $\eta = \dfrac{Z_a Z_A e^2}{\hbar v}$ is called the Sommerfeld parameter and the term $\exp(-2\pi\eta)$ is referred as the Gamow factor.

Combining both relations, the cross-section can be written as
\begin{equation}
    \label{eq:Sfactor}
    \begin{aligned}
        \sigma(E) = \dfrac{1}{E}\exp(-2\pi\eta)S(E)
    \end{aligned}
\end{equation}
where the function $S(E)$, referred to as the nuclear S-factor, contains all   nuclear effects of the cross-section.
Inserting Eq.~\ref{eq:Sfactor} into Eq.~\ref{crosssection_1}, the cross-section can be expressed as
\begin{equation}
    \label{crosssection_S}
    \begin{aligned}
     \langle\sigma v \rangle =(\frac{1}{\pi \mu})^{1/2} (\frac{1}{kT})^{3/2} \int_0^\infty S(E) \exp(-bE^{-1/2}-\frac{E}{kT})dE
    \end{aligned}
\end{equation}
where $b=(2\mu)^{1/2}\pi e^2 Z_1 Z_2/\hbar$ and $b^2$ is known as the Gamow energy $E_0$. Since the S-factor varies smoothly with the energy for nonresonance reactions, the integrand of Eq.\ref{crosssection_S} is dominated by the Coulomb penetrability $\exp(-bE^{-1/2})$
and the Boltzmann factor $\exp(-E/kT)$. The former increases with energy as $\exp(E^{-1/2})$ while the latter decreases as $\exp(-E)$. The product of the two terms produces the Gamow peak near the Gamow energy $E_0$, which determines the energy window at which reactions will take place for a given stellar temperature $T$ (See Fig. ~\ref{fig:gamow_window} ).
\begin{figure}[tpb]
  \begin{center}
    \centerline{\includegraphics[scale=0.6]{graph/ch2/Gamow_window}}
    \caption{The schematic diagram of the Gamow peak. The hatched area is the product of Maxwell-Boltzmann distribution term and the  Coulomb penetrability term. $E_0$ shows the position of the maximum and $\Delta E_0$ indicates the Gamow window.}
    \label{fig:gamow_window}
  \end{center}
\end{figure}

The S-factor in the Gamow window can be considered as constant:
\begin{equation}
    \begin{aligned}
       S(E)=S(E_0)
    \end{aligned}
\end{equation}
Therefore, Eq.\ref{crosssection_S} reduces to
\begin{equation}
    \label{crosssection_S0}
    \begin{aligned}
     \langle\sigma v \rangle =(\frac{1}{\pi \mu})^{1/2} (\frac{1}{kT})^{3/2} S(E_0)\int_0^\infty  \exp(-\frac{E}{kT}-bE^{-1/2})dE
    \end{aligned}
\end{equation}

By calculating the maximum value of the integrand of Eq.\ref{crosssection_S0} one can get the effective burning energy
\begin{equation}
    \label{E_0}
    \begin{aligned}
       E_0=(\frac{bkT}{2})^{2/3}=1.22(Z_a^2 Z_A^2  \mu T_6^2)^{1/3}
    \end{aligned}
\end{equation}
where $\mu$ is in units of amu,  the stellar temperature $T_6$ is in units of $10^6$K and $E_0$  is in units of keV.

Substituting Eq.\ref{E_0} back into Eq.\ref{crosssection_S0}, one obtains the maximum of the reaction rate:
\begin{equation}
    \label{I_max}
    \begin{aligned}
        I_{max} = \exp(-\frac{3E_0}{kT})
    \end{aligned}
\end{equation}
and the exponential term in the integrand of Eq.\ref{crosssection_S0} can be approximated by a Gaussian function:
\begin{equation}
    \label{exp_gaus}
    \begin{aligned}
        \exp{(-\frac{E}{kT}-bE^{-1/2})} = I_{max}\exp[-(\frac{E-E_0}{\Delta /2})^2]
    \end{aligned}
\end{equation}
where $\Delta$ is the effective width of the energy window at  $1/e$ of the height of the Gamow peak and can be expressed by:
\begin{equation}
    \label{delta}
    \begin{aligned}
        \Delta = (4/3)^{1/2}(E_0kT)^{1/2}=0.749(z_a^2 Z_A^2 \mu T_6^5)^{1/6} \ keV
    \end{aligned}
\end{equation}

The energy region that contributes the most to the integrand falls into the Gamow window $(E_0\pm \Delta/2)$. Applying this approximation to Eq.\ref{exp_gaus}, the reaction rate becomes
\begin{equation}
    \label{crosssection_E0}
    \begin{aligned}
        \langle \sigma v \rangle  =  (\frac{2}{\mu})^{1/2} \frac{\Delta}{(kT)^{3/2}}S(E_0)\exp(-\frac{3E_0}{kT})
    \end{aligned}
\end{equation}

\subsection{Resonant Reaction Rates}

Unlike the one-step direct capture (nonresonant) reaction described above, the resonance reaction is a two-step process that is characterized by the strongly varying S-factor caused by a resonance. For an isolated resonance the cross-section is described by the Breit-Wigner formula (all quantities are in the center of mass system):
\begin{equation}
    \label{crosssection_BW}
    \begin{aligned}
        \sigma_{BW}(E) = \pi (\lambda/2\pi)^2 \frac{2J+1}{(2J_a+1)(2J_A+1)} \frac{\Gamma_a(E) \Gamma_b(E)}{(E-E_R)^2+(\Gamma(E)/2)^2}
    \end{aligned}
\end{equation}
where $\lambda$ is the de Broglie wavelength of the projectile defined by $\dfrac{\lambda^2}{2}=\dfrac{(\pi \hbar)^2}{\mu E}$, $E_R$ is the resonance energy and   $\Gamma_a(E)$, $\Gamma_b(E)$ and $\Gamma(E)$ are the energy-dependent partial widths of particle $a$, $b$ and the total resonance width, respectively. One can define the statistical factor  $\omega$ by the spins of the projectile $J_a$, target $J_A$ and resonant state $J$:
\begin{equation}
    \label{statistial_factor}
    \begin{aligned}
        \omega = \frac{2J+1}{(2J_a+1)(2J_A+1)}
    \end{aligned}
\end{equation}

Substituting Eq.\ref{crosssection_BW} and Eq.\ref{statistial_factor} into Eq.\ref{crosssection_1} the reaction rate per particle pair becomes:
\begin{equation}
    \label{crosssection_gamma}
    \begin{aligned}
        \langle \sigma v \rangle = \hbar^2 \omega \frac{\sqrt{2\pi}}{(\mu kT)^{3/2}} \int_0^\infty \frac{\Gamma_a(E) \Gamma_b(E)}{(E-E_R)^2 + (\Gamma(E)/2)^2} \exp(-E/kT)dE
    \end{aligned}
\end{equation}

If the partial width $\Gamma_i \ll E_R$, the resonance is considered to be narrow. In this case, the  Boltzmann factor $\exp(-E/kT)$ does not change significantly over the resonance region. Therefore, one can make the approximation that the partial widths and the exponential term in the integrand in Eq.\ref{crosssection_gamma} are independent of the energy $E$. Integrating Eq.\ref{crosssection_gamma} one gets
\begin{equation}
    \label{crosssection_width}
    \begin{aligned}
        \langle \sigma v \rangle = (\frac{2 \pi}{\mu k T})^{3/2} \hbar^2 (\omega \gamma)_R \exp(-E_R/kT)
    \end{aligned}
\end{equation}
where the width ratio is $\gamma = \Gamma_a\Gamma_b/\Gamma$. The strength of a resonance is defined by the product of these two terms $(\omega \gamma)_R$, as it refers to the integrated cross-section.

Eq.\ref{crosssection_width} is the stellar reaction rate per particle for a single narrow resonance. In the event of several narrow resonances, their contributions to the reaction rate are simply summed as
\begin{equation}
    \label{crosssection_sum}
    \begin{aligned}
        \langle \sigma v \rangle = (\frac{2 \pi}{\mu k T})^{3/2} \hbar^2 \sum_i(\omega \gamma)_i \exp(-E_i/kT)
    \end{aligned}
\end{equation}
or numerically, the reaction rate is given as
\begin{equation}
    \begin{aligned}
        N_A\langle \sigma v \rangle = 1.54\times10^5(\mu T_9)^{-3/2} \sum_i(\omega \gamma)_i \exp(-11.605E_i/T_9)
    \end{aligned}
\end{equation}
in units of cm$^{-3}$s$^{-1}$mol$^{-1}$. Here $T_9$ is the stellar temperature in units of $10^9$K, the resonance strength of the $i_{th}$ resonance $(\omega \gamma)_i$ and the $i_{th}$ resonate energy in the center of mass frame $E_i$ are in units of eV and MeV respectively.

\section{Indirect Measurement: Direct Reaction as a Spectroscopic Tool}

Many reaction rates of direct reactions involving charged particles are relevant for astrophysics at low energies where the Coulomb repulsion makes the cross-section very small and, therefore, extremely difficult to measure by  direct methods. Therefore, indirect methods are used to extract required information such as spectroscopic coefficients.

The Coulomb barrier can be associated with the penetrability which refers to the ability of particles that are trapped inside the potential barrier to tunnel through the barrier and escape from the nucleus. One can relate the partial widths  $\Gamma_{\lambda l}$ directly to the nuclear structure of the states of interest by treating the penetrability separately.

The wavefunction for a partial wave $l$ can be written as
\begin{equation}
    \label{wave_function}
    \begin{aligned}
        \Phi_{lm}(r,\theta, \varphi)=\frac{u_l(r)}{r} Y_{lm}(\theta, \varphi)
    \end{aligned}
\end{equation}
then the radial component of the solution of the Schrodinger equation for $u_l(r)$ becomes
\begin{equation}
    \label{ul}
    \begin{aligned}
        -\frac{\hbar^2}{2 \mu} \frac{d^2 u_l(r)}{dr^2} + [l(l+1)\frac{\hbar^2}{2\mu r^2}+ V(r) -E]u_l(r) =0
    \end{aligned}
\end{equation}
where the potential $V(r)$ has the form
\begin{equation}
    \label{Vr}
    V(r)=\left\{
    \begin{aligned}
    &V_{Coulomb} = z_1 Z_1 e^2/r, \ &r>R_n  \\
    &V_C + V_{nuc}, \  &r<R_n
    \end{aligned}
    \right.
\end{equation}
and $R_n$ refers to the radius of the nuclear part of the interaction potential between $a$ and $A$.

To relate the nuclear structure to the partial wave, one can assume that the actual wavefunction, in general, involves many configurations:
\begin{equation}
    \label{configuration}
    \begin{aligned}
    u_l = \sum_j \Theta_{ij} u_{lj}
    \end{aligned}
\end{equation}
where ${u_{ij}}$ could be the states in the particle-core coupling model. The coefficients $\Theta_{lj}$ ($0<\Theta_{lj}<1$) indicate the amplitudes of each of the configuration in the wavefunction. $\Theta^2_{lj}$ results in the probability of the configuration $u_{lj}$, as well as the probability of decay of each compound nuclear state to each state in the residual nucleus. In other words, they represent the spectroscopic strength of their specific wavefunction configuration. For example, in the particle-core coupling model, this  represents the decay to a continuum proton plus the core states indicated in $u_{ij}$. In some cases some of $u_{ij}$ might have the same core states. (For example, a $d_{3/2}$, $d_{5/2}$ and $s_{1/2}$ neutron coupled to a $2^+$ core state could form $J^{\pi}$ = 3/2${^+}$ or 5/2$^{+}$ states.) Then all such states could decay to that core state. This approach does allow us to develop a relationship between the width of the state $\Gamma_{lj}$ and the coefficients in the wavefunction, the $\Theta{ij}$
\begin{equation}
    \label{spectroscopic_relation}
    \begin{aligned}
    \Gamma_p = C^2S \Gamma_{sp}
    \end{aligned}
\end{equation}
where $\Gamma_{sp}$ denotes the partial width of a single-particle resonance located at the same energy as the resonance of interest. $C$ is the Clebsch-Gordan coefficient.

Typically the spectroscopic factor $S$ are extracted in transfer reactions by a comparison of experimental cross-sections and the result of DWBA calculations by appropriately choosing the optical-model potential. Considering a transfer reaction A$+$c $\rightarrow$ B$+$b (c$=$a$+$b), the reaction process can be divided into two steps. Firstly, particle c breaks up into a and b near the core A (c$\rightarrow$ a$+$b). Secondly, a is captured by core A thus generates core B (a$+$A $\rightarrow$ B), as  shown schematically in Fig.~\ref{fig:transfer}

The transfer reaction A$+$c$\rightarrow$ B$+$b is composed by the capture reaction a$+$A $\rightarrow$ B$+$b and the inverse process a$+$b $\rightarrow$ c$+$$\gamma$. Therefore, the cross-section should be associated with  two spectroscopic factors $S_{ab}$ and $S_{Aa}$ by
\begin{equation}
    \label{transfer_crosssection}
    \begin{aligned}
    \sigma  = \sum_{j_B j_c} S_{A a l_B j_B} S_{a b l_c j_c} \sigma^{DWBA}_{l_B j_B l_c j_c}
    \end{aligned}
\end{equation}
 where $\sigma^{DWBA}_{l_B j_B l_c j_c}$ is the cross-section calculated by DWBA. By experimentally measuring the cross-sections of the transfer reaction $A+c \rightarrow B+b$ and theoretically  calculating $\sigma^{DWBA}_{l_B j_B l_c j_c}$,  the  spectroscopic  factor $S_{Aa}$ can be obtained if $S_{ab}$ is known.

\begin{figure}[tpb]
  \begin{center}
    \centerline{\includegraphics[scale=0.6]{graph/ch2/transfer}}
    \caption{The process of the transfer reaction  $A+c \rightarrow B+b$}
    \label{fig:transfer}
  \end{center}
\end{figure}

 As  mentioned above, $S_{Aa}$ is sensitive to the optical model potentials. However, in terms of particle widths of unbound states, it is shown that the experimentally measured particle width $\Gamma_p$ does not critically depend on the selected potential. This is a consequence of the fact that $\Gamma_{sp}$ also depends on the potential resulting from Eq.~\ref{spectroscopic_relation}. This cancels most of the potential dependence as long as both values are extracted with the same potential.  Thus the particle width can be determined in the same theoretical framework in which the spectroscopic factor is determined.

% To subtract the spectroscopic factor $S$, $\Gamma_p$ is obtained by the experimental data and $\Gamma_{sp}$ can be computed numerically by solving Schrodinger equation for the elastic scattering

% The spectroscopic factor is a tool to get the cross section of the direct measurement.
% \begin{equation}
%     \begin{aligned}
%         \sigma = \lambda \dot |M|^2
%     \end{aligned}
% \end{equation}
% where $\lambda$ is the kinematic factor, $M$ is the transition amplitude of the reaction,
% \begin{equation}
%     \begin{aligned}
%         M=\langle \varphi_B(\zeta_A,\zeta_a,\textbf{r})|\hat{O}(\textbf{r})|\varphi_A(\zeta_A)\zeta_a (\xi_a)\phi^{(+)}_{k_i}(\textbf{r}) \rangle
%     \end{aligned}
% \end{equation}
% where $\varphi_i$, $\zeta_i$ are the wave function of the bound state and the intrinsic coordinates
%  the nuclei $i$, respectively; $\textbf{r}$ is the relative distance between $a$ and $A$; $\hat{O}$ is the electronic transition operator; $\phi^{(+)}_{k_i}$ is the wave function of the incoming wave. Integral to the intrinsic coordinate to get the stacked wave function.
%  \begin{equation}
%     \begin{aligned}
%         I_{Aa}^B(\textbf{r}) = (A+a)^{1/2}\langle\varphi_A(\zeta_A)\varphi_a(\zeta_a)|\varphi_B(\zeta_A, \zeta_a,\textbf{r})\rangle
%     \end{aligned}
% \end{equation}

% The physics meaning of $I_{Aa}^B(\textbf{r})$ is the wave function of the bound state of $B=A+a$  $\varphi_B$ , project to

%  \begin{equation}
%     \begin{aligned}
%         M=\langle I_{Aa}^b(\textbf{r})|\hat{O}| \phi^{(+)}_{k_i}(\textbf{r}) \rangle
%     \end{aligned}
% \end{equation}

%  $I_{Aa}^b(\textbf{r})$ is not the bound state B.

%   \begin{equation}
%     \begin{aligned}
%         S_{Aa}^B = \int_{0}^{\infty} (I_{Aa}^B(\textbf{r}))^2 d{\textbf{r}}
%     \end{aligned}
% \end{equation}

% is the spectroscopic factor.
% \begin{equation}
%     \begin{aligned}
%         I_{Aa}^B(\textbf{r}) =& (A+a)^{1/2} \langle \varphi_A(\zeta_A) \varphi_B(\zeta_A, \zeta_a, \textbf{r})\rangle \\
%                              =& \sum_{l_B m_{l_B} j_B m_{j_B}} \langle J_A M_A j_B m_{jB}|J_B M_B \rangle \\
%                               &\times \langle J_a M_a l_B m_{j_B}|j_B m_{l_B}\rangle i^{l_B} Y_{l_B m_B}(\hat{\textbf{r}}) I^B_{Aal_B J_B}(r)
%     \end{aligned}
% \end{equation}

% where $J_i$, $M_i$ is the spin and projection of the nuclei $i$, $\langle J_a M_a l_B m_{l_B} | j_B m_{j_B}\rangle$ is the C-G coefficient, $Y_{l_B m_B}(\hat{\textbf{r}})$ is the Spherical Harmonic Function, $I^B_{Aal_BJ_B}(r)$ is the radius integral of the dieji wave function.

% In the model of the single particle, the dieji wave function $I^B_{Aal_BJ_B}(r)$ can be considered as the production of the spectroscopic factor and the bound state wave function of the particle.

%   \begin{equation}
%     \begin{aligned}
%         I^B_{Aal_BJ_B(r)} \approx (S_{l_B j_B})^{1/2} \varphi_{n_B l_B j_B}(r)
%     \end{aligned}
% \end{equation}
% where  $\varphi_{n_B l_B j_B}(r)$ is the normalized jingxiang  wave function of $B=A+a$, which can be solve from the bound state Schrodinger function. As a  result, calculating the $ I^B_{Aal_BJ_B}(r)$ became calculating the spectroscopic factor $S_{l_B j_B}$.

% The spectroscopic factor can be obtained by calculating the cross section of the transferred reaction. For the transfer reaction $A+c \rightarrow B+b(c=a+b)$ the reaction can be considered as two steps: The first step is the breakup of $c$ to $a$ and $b$ near core $A$ ($c \rightarrow a+b$). The second step is $a$ is captured by core $A$ and produce $B$ ($a+A \rightarrow B$).

% The transfer reaction $A+c \rightarrow B+b$ can be considered as the radiation capture reaction $a+A \rightarrow B+\gamma$ and the inverse process $a+b \rightarrow c + \gamma$.

% % uncomment the following lines,
% if using chapter-wise bibliography
%
% \bibliographystyle{ndnatbib}
% \bibliography{example}


\documentclass{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsfonts}
\usepackage{amsmath}

\setcounter{MaxMatrixCols}{10}
%TCIDATA{OutputFilter=LATEX.DLL}
%TCIDATA{Version=5.50.0.2960}
%TCIDATA{<META NAME="SaveForMode" CONTENT="1">}
%TCIDATA{BibliographyScheme=Manual}
%TCIDATA{Created=Sunday, December 09, 2012 07:04:33}
%TCIDATA{LastRevised=Monday, January 07, 2013 12:45:42}
%TCIDATA{<META NAME="GraphicsSave" CONTENT="32">}
%TCIDATA{<META NAME="DocumentShell" CONTENT="Standard LaTeX\Standard LaTeX Article">}
%TCIDATA{CSTFile=USTDC-BriefReport.cst}

\newtheorem{theorem}{Theorem}
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{conclusion}[theorem]{Conclusion}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{solution}[theorem]{Solution}
\newtheorem{summary}[theorem]{Summary}
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\input{tcilatex}
\begin{document}

\title{Standard
%TCIMACRO{\TeXButton{LaTeX}{\LaTeX{}} }%
%BeginExpansion
\LaTeX{}
%EndExpansion
Article}
\author{A. U. Thor \\
%EndAName
The University of Stewart Island}
\maketitle

\begin{abstract}
We study the effects of warm water on the local penguin population. The
major finding is that it is extremely difficult to induce penguins to drink
warm water. The success factor is approximately $-e^{-i\pi }-1$.
\end{abstract}

\section{Nonlinear least square fitting}

I define a test function and data for which I can obtain the residual, its
square, and its partial derivatives in closed form.

\subsection{Example data and test function}

For the data I consider the exact function
\begin{equation}
y_{i}=ae^{-bi}  \label{def:y_i}
\end{equation}%
with
\begin{equation}
i=0,1,\ldots ,9  \label{def:i:0-9}
\end{equation}%
modeled by the two parameter curve%
\begin{equation}
y=Ae^{-Bi}  \label{def:y(i)}
\end{equation}

\subsection{Residual and its derivative}

The residual is%
\begin{eqnarray}
r_{i} &=&y_{i}-y\left( i\right) \\
&=&ae^{-bi}-Ae^{-Bi}  \label{eq:r_i^2}
\end{eqnarray}%
Its residual with respect to $A$ and $B$ is calculated next. For $A$,%
\begin{eqnarray}
\frac{\partial r_{i}}{\partial A} &=&-\frac{\partial y}{\partial A} \\
&=&-e^{-Bi}
\end{eqnarray}%
and for $B$%
\begin{eqnarray}
\frac{\partial r_{i}}{\partial B} &=&-\frac{\partial y}{\partial B} \\
&=&Aie^{-Bi}
\end{eqnarray}

The residual squared is%
\begin{eqnarray}
r_{i}^{2} &=&\left( ae^{-bi}-Ae^{-Bi}\right) ^{2} \\
&=&a^{2}e^{-2bi}-2aAe^{-\left( b+B\right) i}+A^{2}e^{-2Bi}
\end{eqnarray}%
which is written as%
\begin{equation}
r_{i}^{2}=a^{2}\left( e^{-2b}\right) ^{i}-2aA\left( e^{-\left( b+B\right)
}\right) ^{i}+A^{2}\left( e^{-2B}\right) ^{i}
\end{equation}

Introducint%
\begin{eqnarray}
\alpha &=&e^{-2b}  \label{def:alpha} \\
\beta &=&e^{-\left( b+B\right) }  \label{def:beta} \\
\gamma &=&e^{-2B}  \label{def:gamma}
\end{eqnarray}%
the residual squared is%
\begin{equation}
r_{i}^{2}=a^{2}\alpha ^{i}-2aA\beta ^{i}+A^{2}\gamma ^{i}
\label{eq:r_i^2(alpha,beta,gamma)}
\end{equation}%
and their sum is%
\begin{eqnarray}
S &=&\sum r_{i}^{2} \\
&=&a^{2}\sum \alpha ^{i}-2aA\sum \beta ^{i}+A^{2}\sum \gamma ^{i}
\label{eq:S}
\end{eqnarray}

\subsection{Summation function}

I will be using the summation identity%
\begin{eqnarray}
\sum_{i=0}^{n}c^{i} &=&\frac{1-c^{n+1}}{1-c} \\
&=&\sigma _{n}\left( c\right)  \label{def:sigma-fun}
\end{eqnarray}%
and its derivativeThe derivative of $\sigma $ is%
\begin{eqnarray}
\frac{d\sigma }{dc} &=&\frac{d}{dc}\left( \frac{1-c^{n+1}}{1-c}\right) \\
&=&\frac{\left( 1-c\right) \left( -\left( n+1\right) c^{n}\right) -\left(
1-c^{n+1}\right) \left( -1\right) }{1-c^{2}} \\
&=&\frac{cc^{n}n-c^{n}-c^{n}n+1}{1-c^{2}} \\
&=&\frac{nc^{n+1}-\left( n+1\right) c^{n}+1}{1-c^{2}} \\
&=&\frac{c^{n}\left( n\left( c-1\right) -1\right) +1}{1-c^{2}}
\label{eq:sigma'}
\end{eqnarray}

Using $\sigma $, the sum of residual squared is%
\begin{equation}
S=a^{2}\sigma _{n}\left( \alpha \right) -2aA\sigma \left( \beta \right)
+A^{2}\sigma \left( \gamma \right)  \label{eq:S(sigma,alpha,beta,gamma)}
\end{equation}

\subsection{Partial derivatives of $S$}

I\ now derive the partial derivatives of $S$. I make sure that at match%
\begin{eqnarray}
A &=&a  \label{def:match} \\
B &=&b
\end{eqnarray}%
the partial derivative is zero.

The derivative of $S$ with respect to $A$ is%
\begin{equation}
\frac{\partial S}{\partial A}=-2a\sigma \left( \beta \right) +2A\sigma
\left( \gamma \right)
\end{equation}%
At match, this becomes%
\begin{eqnarray}
\frac{\partial S}{\partial A} &=&a\sigma \left( \beta \right) +2a\sigma
\left( \beta \right) \\
&=&0
\end{eqnarray}

The derivative of $S$ with respect to $B$ is%
\begin{equation}
\frac{\partial S}{\partial B}=-2aA\frac{d\sigma \left( \beta \right) }{%
d\beta }\frac{\partial \beta }{\partial B}+A^{2}\frac{d\sigma \left( \gamma
\right) }{d\gamma }\frac{\partial \gamma }{\partial B}
\end{equation}

The derivatives of $\beta $ and $\gamma $ are%
\begin{eqnarray}
\frac{\partial \beta }{\partial B} &=&-\beta \\
&=&-\gamma \\
\frac{\partial \gamma }{\partial B} &=&-2\gamma
\end{eqnarray}%
The partial derivative is%
\begin{equation}
\frac{\partial S}{\partial B}=2aA\gamma \frac{d\sigma \left( \beta \right) }{%
d\beta }-2A^{2}\gamma \frac{d\sigma \left( \gamma \right) }{d\gamma }
\end{equation}

At match this becomes%
\begin{eqnarray}
\frac{\partial S}{\partial A} &=&2a^{2}\gamma \frac{d\sigma \left( \beta
\right) }{d\beta }-2a^{2}\gamma \frac{d\sigma \left( \beta \right) }{d\beta }
\\
&=&0
\end{eqnarray}

\section{Another function}

\begin{equation}
y=A10^{B\left( x-1650\right) }
\end{equation}%
the Jacobian is%
\begin{eqnarray}
\frac{d}{dA}\left( A10^{B\left( x-1650\right) }\right)  &=&10^{B\left(
x-1650\right) } \\
\frac{d}{dB}\left( A10^{B\left( x-1650\right) }\right)  &=&10^{B\left(
x-1650\right) }A\left( \ln 10\right) \left( x-1650\right)  \\
&=&\left( \ln 10\right) A\left( x-1650\right) 10^{B\left( x-1650\right) }
\end{eqnarray}%
Derivative
\begin{equation}
\log _{10}y=\log _{10}A+Bx
\end{equation}

\end{document}


\chapter[Differential Equations]{Differential Equations}

% Introduction
\chapterinitial{S}{ystems} often change in a way that depends on their current
state. For example, the speed at which a cup of coffee cools down depends on its
current temperature. These types of systems are called dynamical systems and are
modelled mathematically using differential equations. This chapter will
consider a direct solution approach using symbolic mathematics.

\section{Problem}\label{sec:differential_equations_problem}

Consider the following situation: the entire population of a small rural town
has caught a cold. All 100 individuals will recover at an average rate of 2 per
day. The town leadership have noticed that being ill costs approximately
\(\pounds10\) per day, this is due to general lack of productivity, poorer mood and
other intangible aspects. They need to decide whether or not to order cold
medicine which would \textbf{double} the recovery rate. The cost of of the cold
medicine is a one off cost of \(\pounds5\) per person.

\section{Theory}\label{sec:differential_equations_theory}

In the case of this town, the overall rate at which people get better is
dependent on the number of people who are ill. This can be represented
mathematically using a differential equation which is a way of relating the rate
of change of a system to the state of the system itself.

In general the objects of interest are the variable \(x\) over time \(t\), and
the rate at which \(x\) changes with \(t\), its derivative\index{derivative}
\(\frac{dx}{dt}\).
The differential equation\index{differential equation} describing this will be
of the form:

\begin{equation}
    \frac{dx}{dt} = f(x)
\end{equation}

for some function \(f\).
In this case,
the number of infected individuals will be denoted as \(I\), which will
implicitly mean that \(I\) is a function of time: \(I=I(t)\), and the rate at
which individuals recover will be denoted by \(\alpha\), then the
differential equation that describes the above situation is:

\begin{equation}
    \frac{dI}{dt} = -\alpha I
\end{equation}

Finding a solution to this differential equation means finding an expression for
\(I\) that when differentiated gives \(- \alpha I\).

In this particular case, one such function is:

\begin{equation}
    I(t) = e ^ {-\alpha t}
\end{equation}

This is a solution because:
\(\frac{dI}{dt} = -\alpha e ^ {-\alpha y} = -\alpha I\).

However here \(I(0) = 1\), whereas for this problem we know that at time \(t=0\)
there are 100 infected individuals. In general there are many such functions
that can satisfy a differential equation, known as a family of solutions. To
know which particular solution is relevant to the situation, some sort of
initial condition is required. Here this would
be:

\begin{equation}
    I(t) = 100e ^ {-\alpha t}
\end{equation}

To evaluate the cost the sum of the values of that function over time is needed.
Integration\index{integration} gives exactly this, so the cost would be:

\begin{equation}
    K \int_{0}^{\infty}I(t)dt
\end{equation}

where \(K\) is the cost per person per unit time.
Therefore the overall cost would be the cost of being unproductive, plus the cost
of the medicine, \(M\), and is given by:

\begin{equation}
K \int_{0}^{\infty}I(t)dt + M I(0)
\end{equation}

In the upcoming sections code will be used to confirm to carry out the above
efficiently so as to answer the original question.

\section{Solving with Python}\label{sec:differential_equations_solving-with-python}

The first step is to define the symbolic variables that will be used. The
Python library SymPy\index{SymPy}~\cite{meurer2017sympy} is used.

\begin{pyin}
import sympy as sym

t = sym.Symbol("t")
alpha = sym.Symbol("alpha")
I_0 = sym.Symbol("I_0")
I = sym.Function("I")
\end{pyin}

Now write a function to obtain the differential equation.

\begin{pyin}
def get_equation(alpha=alpha):
    """Return the differential equation.

    Args:
        alpha: a float (default: symbolic alpha)

    Returns:
        A symbolic equation
    """
    return sym.Eq(sym.Derivative(I(t), t), -alpha * I(t))
\end{pyin}

This gives an equation that defines the population change over time:

\begin{pyin}
eq = get_equation()
print(eq)
\end{pyin}

which gives:

\begin{pyout}
Eq(Derivative(I(t), t), -alpha*I(t))
\end{pyout}

Note that if Jupyter\index{Jupyter}~\cite{kluyver2016jupyter} notebooks are used
then output will actually be a well rendered mathematical equation:

\[
\frac{d}{d t} I{\left(t \right)} = - \alpha I{\left(t \right)}
\]

A value of \(\alpha\) can be passed if required:

\begin{pyin}
eq = get_equation(alpha=1)
print(eq)
\end{pyin}

\begin{pyout}
Eq(Derivative(I(t), t), -I(t))
\end{pyout}

Now a function will be written to obtain the solution to this differential
equation with initial condition \(I(0) = I_0\):

\begin{pyin}
def get_solution(I_0=I_0, alpha=alpha):
    """Return the solution to the differential equation.

    Args:
        I_0: a float (default: symbolic I_0)
        alpha: a float (default: symbolic alpha)

    Returns:
        A symbolic equation
    """
    eq = get_equation(alpha=alpha)
    return sym.dsolve(eq, I(t), ics={I(0): I_0})
\end{pyin}

This can verify the solution discussed previously:

\begin{pyin}
sol = get_solution()
print(sol)
\end{pyin}

which gives:

\begin{pyout}
Eq(I(t), I_0*exp(-alpha*t))
\end{pyout}

\[I(t) = I_0 e ^{-\alpha t}\]

SymPy itself can be used to verify the result, by taking the derivative of the
right hand side of our solution.

\begin{pyin}
print(sym.diff(sol.rhs, t) == -alpha * sol.rhs)
\end{pyin}

which gives:

\begin{pyout}
True
\end{pyout}

All of the above has given the general solution in terms of \(I(0)=I_0\) and
\(\alpha\), however the code is written in such a way as we can pass the actual
parameters:

\begin{pyin}
sol = get_solution(alpha=2, I_0=100)
print(sol)
\end{pyin}

which gives:

\begin{pyout}
Eq(I(t), 100*exp(-2*t))
\end{pyout}

Now, to calculate the cost write a function to integrate the result:

\begin{pyin}
def get_cost(
    I_0=I_0,
    alpha=alpha,
    per_person_cost=10,
    cure_cost=0,
):
    """Return the cost.

    Args:
        I_0: a float (default: symbolic I_0)
        alpha: a float (default: symbolic alpha)
        per_person_cost: a float (default: 10)
        cure_cost: a float (default: 0)

    Returns:
        A symbolic expression
    """
    I_sol = get_solution(I_0=I_0, alpha=alpha)
    area = sym.integrate(I_sol.rhs, (t, 0, sym.oo))
    productivity_cost = area * per_person_cost
    total_cost_of_cure = cure_cost * I_0
    return productivity_cost + total_cost_of_cure
\end{pyin}

The cost without purchasing the cure is:

\begin{pyin}
alpha = 2
cost_without_cure = get_cost(I_0=100, alpha=alpha)
print(cost_without_cure)
\end{pyin}

which gives:

\begin{pyout}
500
\end{pyout}

The cost with cure can use the above with a modified \(\alpha\) and a non zero
cost of the cure itself:

\begin{pyin}
cost_with_cure = get_cost(I_0=100, alpha=2 * alpha, cure_cost=5)
print(cost_with_cure)
\end{pyin}

which gives:

\begin{pyout}
750
\end{pyout}

So given the current parameters it is not worth purchasing the cure.

\section{Solving with R}\label{sec:differential_equations_solving-with-R}

R has some capability for symbolic mathematics, however at the time of writing
the options available are somewhat limited and/or not reliable. As such, in R
the problem will be solved using a numerical integration approach. For an
outline of the theory behind this approach see Chapter
\ref{chp:system_dynamics}.

First a function to give the derivative for a given value of \(I\) is needed:

\begin{Rin}
#' Returns the numerical value of the derivative.
#'
#' @param t a set of time points
#' @param y a function
#' @param parameters the set of all parameters passed to y

#' @return a float
derivative <- function(t, y, parameters) {
  with(
    as.list(c(y, parameters)), {
      dIdt <- -alpha * I  # nolint
      list(dIdt)  # nolint
    }
  )
}
\end{Rin}

For example, to see the value of the derivative when \(I=0\):

\begin{Rin}
dv <- derivative(t = 0, y = c(I = 100), parameters = c(alpha = 2))
print(dv)
\end{Rin}

This gives:

\begin{Rout}
[[1]]
[1] -200

\end{Rout}

Now the deSolve\index{deSolve}~\cite{soetaert2010solving} library will be used
for solving differential equations numerically:

\begin{Rin}
library(deSolve)  # nolint
#' Return the solution to the differential equation.
#'
#' @param times: a vector of time points
#' @param y_0: a float (default: 100)
#' @param alpha: a float (default: 2)

#' @return A vector of numerical values
get_solution <- function(times,
                         y0 = c(I = 100),
                         alpha = 2) {
  params <- c(alpha = alpha)
  ode(y = y0, times = times, func = derivative, parms = params)
}
\end{Rin}

This will return a sequence of time point and values of \(I\) at those time
points. Using this we can compute the cost.

\begin{Rin}
#' Return the cost.
#'
#' @param I_0: a float (default: symbolic I_0)
#' @param alpha: a float (default: symbolic alpha)
#' @param per_person_cost: a float (default: 10)
#' @param cure_cost: a float (default: 0)
#' @param step_size: a float (default: 0.0001)
#' @param max_time: an integer (default: 10)

#' @return A numeric value
get_cost <- function(I_0 = 100,
                     alpha = 2,
                     per_person_cost = 10,
                     cure_cost = 0,
                     step_size = 0.0001,
                     max_time = 10) {
  times <- seq(0, max_time, by = step_size)
  out <- get_solution(times, y0 = c(I = I_0), alpha = alpha)
  number_of_observations <- length(out[, "I"])
  time_intervals <- diff(out[, "time"])
  area <- sum(time_intervals * out[-number_of_observations, "I"])
  productivity_cost <- area * per_person_cost
  total_cost_of_cure <- cure_cost * I_0
  productivity_cost + total_cost_of_cure
}
\end{Rin}

The cost without purchasing the cure is:

\begin{Rin}
alpha <- 2
cost_without_cure <- get_cost(alpha = alpha)
print(round(cost_without_cure))
\end{Rin}

which gives:

\begin{Rout}
[1] 500
\end{Rout}

The cost with cure can use the above with a modified \(\alpha\) and a non zero
cost of the cure itself:

\begin{Rin}
cost_with_cure <- get_cost(alpha = 2 * alpha, cure_cost = 5)
print(round(cost_with_cure))
\end{Rin}

which gives:

\begin{Rout}
[1] 750
\end{Rout}

So given the current parameters it is not worth purchasing the cure.

\section{Wider context}\label{sec:differential_equations_wider_context}

There are a number of further areas related to the study of as well as the use
of differential equations. Topics omitted here include the actual solution
approaches which in this chapter are taken
care of using open-source software. Chapters 9, 14 and 16
of~\cite{stewart2009calculus} provide a good introduction to some of
these concepts as well as a general discussion of the area of mathematics in
which they sit: \index{calculus}.

Differential equations have been applied in many settings.
In~\cite{lanchester1916aircraft} differential equations were used to model
attrition in warfare\index{warfare}, the insights from these differential
equations are referred to as Lanchester's square
law\index{Lanchester's square law}. This has been historically fitted to a
number of battles with varying levels of success.

In~\cite{syms2015dynamic} differential equations are used to build a
generic model of regime change. A detailed analysis of the
stability\index{stability} of the system is included. The model offers some
explanation of why oppressive regimes can follow an overthrow of a similarly
oppressive regime: the underlying mathematical system is a stable cycle from
which it is difficult to escape.

\cite{vandergraft1983fluid} uses differential equations as a framework for
modelling queueing\index{queueing} networks. This is interesting in its
inception as differential equations are models for continuous quantities whereas
queues are discrete type events (see Chapter~\ref{chp:markov_chains}
and~\ref{chp:discrete_event_simulation} for more on this). The advantages of
using differential equations are mainly in the computational efficiency.

The model presented in this chapter is deterministic: there is a single solution
that remains the same. This is not always a precise model of reality: often
systems are stochastic so that the inputs are not constant parameters but follow
some random distribution. This is where stochastic differential
equations\index{stochastic differential equation} are applied, which is the
subject of~\cite{sarkka2019applied}.


\subsection{Linear forms}

A linear form is a linear map from a vector space to a scalar from the vector space's underlying field.

\(\hom (V, F)\)

\subsubsection{Matrix operators}

Linear forms can be represented as matrix operators.

\(v^TM=f\)

Where \(M\) has only one column.

\subsubsection{Stuff}

\(f(M)=f(v)\)

We introduce \(e_i\), the element vector. This is \(0\) for all entries except for \(i\) where it is \(1\). Any vector can be shown as a sum of these vectors multiplied by a scalar.

\(f(M)=f(\sum^m_{i=1}a_{i}e_i)\)

\(f(M)=\sum_{i=1}^mf(a_{i}e_i)\)

\(f(M)=\sum_{i=1}^ma_if(e_i)\)

\(f(M)=\sum_{i=1}^ma_if(e_i)\)

\subsubsection{Orthonormal basis}

\(f(M)=\sum_{i=1}^ma_i\)


\subsection{Utility functions}

Given that an agent chooses a selection from a set, how can we model this?

As the outcome of the function is one of the options available to the agent, we can model it by putting a value number on each choice, and where the choice is the selection with the largest value. We can do this by applying a function to each element in the choice set.

This holds only if the agent is rational, that is, if they prefer A to B, they do not switch to B if C is offered. This is due to the transitive properties of real numbers. That is, if \(a\ge b\) and \(b\ge c\) then \(a\ge c\).

If there are multiple elements with the largest value, then the agent would be indifferent between these choices.

A simple example would be choosing the number of apples to consume.

If the agent always prefers more apples, we can have a function which is always increasing when the number of apples increases.

This could be modelled by:

\(f=x\)

\(f=(x-1)^2+1\)

\(f=2(x-1)^2-10\)

\(f=cos(x)\)

\(f=c\)

These correspond to different preferences. In the first the agent prefers more and more apples. In the second and third the agent prefers one apple. These two formulas are monotonic transformations of each other and so are identical for describing preferences. The fourth describes an infinite number of optimal numbers of apples, but is unlikely to correspond to any real preferences, and the fifth shows that agent doesn’t care about apples.

The last gives a real number as output, but doesn’t necessarily take in a real number. Utility functions generally take real numbers, and always give out real numbers.

\subsubsection{Solving}

Option which maximises utility


\newpage

\appendix

%\end{figure}

\section{Condensing to One Point in Linear Time}\label{app:onepoint}

In this section, we present an algorithm to reduce two claims about $\tV_{i+1}$ to one in linear time. Recall that as described in Section~\ref{subsec::GKR}, in the $i$-th layer, after the sumcheck, the verifier receives two claims $\tV(u), \tV(v)$. (Again we omit the superscript and subscript of $i$ for the ease of interpretation.) She then defines a line $\gamma(x): \mathbb{F}\rightarrow\mathbb{F}^{s}$ such that $\gamma(0) = u, \gamma(1)=v$ and the prover needs to provide $\tV(\gamma(x))$, a degree $s$ univariate polynomial, to $\V$. If the prover computes it naively, which was done in all prior papers, it incurs $O(s2^{s})$ time, as it is equivalent to evaluating $\tV()$ at $s+1$ points.

\begin{figure}[H]
	\begin{algorithm}[H]

		\caption{Compute $\tV(\gamma(x)) = \sum_{y\in\binary^s}I(\gamma(x), y)\tV(y)$}\label{alg::comb}
		\begin{algorithmic}[1]
			\State Initialize a binary tree $T$ with $s$ levels. We use $T_j[b]$ to denote the $b$-th node at level $j$.
			\For{$b\in\binary^s$}
				\State $T_s[b] = \tV(b)$.
				\State Multiply $T_s[b]$ with $b_s(c_s x+ d_s)+(1-b_s)(1-c_s x- d_s)$.
			\EndFor
			\For{$j = s-1, \ldots, 1$}
				\For{$b\in\binary^{j}$}
					\State $T_j[b] = T_{j+1}[b,0]+T_{j+1}[b,1]$.
					\State $T_j[b] = T_j[b] \cdot (b_j(c_j x+ d_j)+(1-b_j)(1-c_j x- d_j))$.
				\EndFor
			\EndFor
			\State Output $T_1[0]$.
		\end{algorithmic}
	\end{algorithm}
\end{figure}

In our new algorithm, we write $\tV(\gamma(x)) = \sum_{y\in\binary^s}I(\gamma(x), y)\tV(y)$, where $I(a,b)$ is an identity polynomial $I(a,b)=0$ iff $a=b$. This holds by inspection of both sides on the Boolean hypercube. We then evaluate the right side in linear time with a binary tree structure. The key observation is that the identity polynomial can be written as $I(a,b) = \prod_{j=1}^s (a_jb_j+(1-a_j)(1-b_j))$, and we can process one variable ($a_j,b_j$) at a time and multiply them together to get the final result.

We construct a binary tree with $2^s$ leaves and initialize each leaf $b\in\binary^s$ with $\tV(b)$. As $\gamma(x)$ is a linear polynomial, we write it as $\gamma(x) = [c_1, \ldots, c_s]^T x+ [d_1, \ldots, d_s]^T$. At the leaf level, we only consider the last variable of $I(\gamma(x), y)$. For each leaf $b\in\binary^s$, we multiply the value with $b_s(c_s x+ d_s)+(1-b_s)(1-c_s x- d_s)$, the result of which is a linear polynomial. For a node $b\in\binary^j$ in the intermediate level $j$, we add the polynomials from its two children, and multiply it with $b_j(c_j x+ d_j)+(1-b_j)(1-c_j x- d_j)$, the part in $I$ that corresponds to the $j$-th variable. In this way, each node in the $j$-th level stores a degree $j$ polynomial. Eventually, the root is the polynomial on the right side of degree $s$, which equals to $\tV(\gamma(x))$. The algorithm is given in Algorithm~\ref{alg::comb}.

To see the complexity of Algorithm~\ref{alg::comb}, both the storage and the polynomial multiplication at level $j$ is $O(s-j+1)$ in each node. So the total time is $O(\sum_{j=1}^s 2^j (s-j+1)) = O(2^s)$, which is linear to the number of gates in the layer.

An alternative way to interpret this result is to add an additional layer for each layer of the circuit in GKR relaying the values. That is, $$\tV_{i}(g) = \sum_{x\in\binary^{s_i}}I(g,x)\tV_{i+1}(x),$$ where $\tV_i = \tV_{i+1}$. Then when using the random linear combination approach, the sumcheck is executed on $$\alpha\tV_{i}(u)+\beta\tV_i(v) = \sum_{x\in\binary^{s_i}}(\alpha I(u,x)+\beta I(v,x))\tV_{i+1}(x).$$
At the end of the sumcheck, the verifier receives a single claim on $\tV_{i+1} = \tV_{i}$. The sumcheck can obviously run in linear time, and the relay layers do not change the result of the circuit. This approach is actually the same as the condensing to one point in linear time above conceptually.


\section{Maps}

\begin{frame}{Maps}

  \begin{alertblock}{Definition of map}
    A map from a set $A$ to a set $B$ is a subset $M$ of $A \times B$ where each element of $A$ appears as the first element of a tuple in $M$ exactly once.
  \end{alertblock}

  \begin{topdisp}
    $$A = \{a,b,c\} \qquad B = \{x,y,z\}$$
  \end{topdisp}

  \begin{minipage}[t]{0.48\linewidth}
  \begin{exampleblock}{Maps}
    \begin{itemize}
      \item $\{(a,x),(b,x),(c,x)\}$
      \item $\{(a,x),(b,y),(c,z)\}$
    \end{itemize}
  \end{exampleblock}
\end{minipage}
\begin{minipage}[t]{0.48\linewidth}
  \begin{exampleblock}{Not maps}
    \begin{itemize}
      \item $\{(a,x),(a,y),(b,x),(c,x)\}$
      \item $\{(a,x),(b,y)\}$
    \end{itemize}
  \end{exampleblock}
\end{minipage}
\end{frame}

\begin{frame}{One-to-one map}
  \begin{topdisp}
    $$ A = \{1,2,3\} \quad  B = \{a,b,c,d\} \quad  M = \{ (1,a), (2,b), (3,d) \} $$
  \end{topdisp}
  \begin{itemize}
    \setlength\itemsep{3mm}
    \item In a map, $M \subseteq A \times B$, two or more distinct elements of $A$ can be mapped to the same element of $B$.
    \item A map where this does not happen is described as \textbf{one-to-one}.
    \item So, a map in which distinct elements of $A$ go to distinct elements of $B$ is one-to-one.
  \end{itemize}
\end{frame}

\begin{frame}{Onto map}
  \begin{topdisp}
    $$ A = \{1,2,3\} \quad  B = \{a,b,c,d\} \quad  M = \{ (1,a), (2,a), (3,b) \} $$
  \end{topdisp}
  \begin{itemize}
    \setlength\itemsep{3mm}
    \item In a map, not all of the elements of $B$ need to be involved in the map.
    \item A map in which they are all involved is described as \textbf{onto}.
    \item So, a map in which each element of $B$ is paired with an element of $A$ is onto.
  \end{itemize}
\end{frame}

\begin{frame}{Bijections}
  \begin{topdisp}
    $$ A = \{1,2,3\} \quad  B = \{a,b,c\} \quad  M = \{ (1,a), (2,c), (3,b) \} $$
  \end{topdisp}
  \begin{itemize}
    \setlength\itemsep{3mm}
    \item Maps can be neither one-to-one nor onto, one or the other, or both.
    \item A \textbf{bijection} is map that is both one-to-one and onto.
    \item Both $A$ and $B$ must have the same size in a bijection.
  \end{itemize}
\end{frame}

\begin{frame}{Partial maps}
  \begin{topdisp}
    $$ A = \{1,2,3\} \quad  B = \{a,b,c\} \quad  P = \{ (1,a), (3,c) \} $$
  \end{topdisp}
  \begin{itemize}
    \setlength\itemsep{3mm}
    \item A map $M$ from a set $A$ to a set $B$ must involve every element of $A$.
    \item A partial map is like a map, but with that condition relaxed.
    \item A partial map from a set $A$ to a set $B$ is a subset of $A \times B$ where any element of $A$ that appears as the first element in a tuple does so exactly once.
    \item The term \emph{partial map} is a bit of a misnomer, as a partial map is not necessarily a map, but a map is a partial map.
  \end{itemize}
\end{frame}