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

\marginpar{Wednesday\\ 2020-11-4, \\ compiled \\ \today}

Then, the power spectrum at the second horizon crossing reads
%
\begin{align}\label{eq:density-perturbation-power-spectrum}
\Delta_{ \delta \rho / \rho  } (k)
= \qty(\frac{H^2}{2 \pi \dot{\varphi}})^2 \qty(\frac{k}{aH})^{3-2\nu }
\,,
\end{align}
%
where \(3 - 2 \nu = 2 \eta _V - 6 \epsilon = n_s -1\).
The last equality comes from the definition
%
\begin{align}
n_s - 1 = \dv{\log \Delta }{\log k}
\,.
\end{align}
%

A power spectrum with \(n_s = 1\) is called a Harrison-Zel'dovich spectrum, and it is scale-invariant.
If \(n_s > 1\) the spectrum is ``blue'', while if \(n_s < 1\) the spectrum is ``red'' (or, respectively, red or blue ``tilted'').
In the two cases, we have either more energy at longer or shorter wavelengths.

This deviation from \(n_s = 1\) is a specific prediction of single-field models.
If we had \(n_s = 1\) exactly, we would expect there to be some symmetry which prevents \(n_s \neq 1\).
The detection of a spectral index \(n_s \neq 1\) is a good indication of an inflation-like process.

From CMB data \cite[eq.\ 21]{planckcollaborationPlanck2018Results2019} we have \(n_s = \num{.9649(42)}\) at a \SI{68}{\percent} CL: the spectrum is red, and we can be quite confident of this fact.

Recall the definition of \(\zeta \): for \(k \ll aH\) it is constant, and it is given by
%
\begin{align}
\zeta = \frac{1}{4} \frac{ \delta \rho _\gamma }{\rho _\gamma }
\,,
\end{align}
%
but we also know that \(\rho _\gamma \propto T^{4}\), so \(\zeta \sim \delta T / T\).

\subsection{Power spectrum of primordial gravitational waves}

The two polarization states evolve like two scalar fields:
%
\begin{align}
h_{+, \times } = \sqrt{32 \pi G} \phi_{+, \times}
\,,
\end{align}
%
so
%
\begin{align}
\Delta_{h_{+, \times }} (k) = 32 \pi G \Delta_{\phi_{+, \times }}
\,,
\end{align}
%
and we know that for a massless scalar field \(\phi  \)
%
\begin{align}
\Delta_{\phi} = \qty(\frac{H}{2 \pi })^{2} \qty(\frac{k}{aH})^{-2\epsilon }
\marginnote{See equation \eqref{eq:primordial-gw-power-spectral-amplitude}.}
\,,
\end{align}
%
therefore
%
\begin{align}
\Delta_{h_{+, \times }} (k)
&= \frac{32 \pi }{M_P^2} \qty(\frac{H}{2 \pi })^2 \qty(\frac{k}{aH})^{-2 \epsilon }  \\
&= \frac{8}{\pi M_P^2} H^2 \qty(\frac{k}{aH})^{-2 \epsilon }
\,.
\end{align}

Note that we are \emph{not} using \(3- 2\nu = 2 \eta _V - 6 \epsilon \): that result is the most general for a scalar field, accounting for its effect on the geometry of spacetime. This is not applicable here: the polarizations of GWs do behave like scalar fields, but to first order they are decoupled from other perturbations of the metric. So,

Once again, we find a powerlaw as a function of \(k\).
The amplitude is of the order \(H^2 / M_P^2\), but \(H\) is determined by the vacuum energy density of the inflaton, so
%
\begin{align}
\frac{H^2}{M_P^2} = \frac{8 \pi }{3} \frac{V(\varphi )}{M_P^4}
\,.
\end{align}

If we define the characteristic energy of inflation as \(E_{\text{inf}} = V^{1/4}\) (recall that \(V\) is an energy density, with dimensions of a mass to the fourth power) we find that the amplitude of the GW spectrum is of the order \(E _{\text{inf}} / M_P\).
Measuring the primordial SGWB amplitude gives us directly the energy scale of inflation.

The ``tensor spectral index'' is defined as
%
\begin{align}
n_T = \dv{\log \Delta _T}{\log k} = - 2 \epsilon
\,,
\end{align}
%
where \(\Delta _T\) is the total tensor amplitude: we just by 2 to account for the two polarizations,
%
\begin{align}
\Delta_T = \frac{16}{\pi M_P^2} H^2 \qty(\frac{k}{aH})^{-2\epsilon }
\,.
\end{align}

In single-field models \(\epsilon > 0\) always, therefore \(n_T \) will always be red-tilted.

We can also write
%
\begin{align}
\Delta_{h_{+, \times }} = \frac{8}{M_P^2 \pi } H^2_*
\,,
\end{align}
%
where the star means we calculate the Hubble rate at the time of horizon crossing during inflation.

This is because the fluctuation remains constant when it is on superhorizon scales: so, its value is set by whatever it is at horizon crossing, \(k = aH\).
The term \(k / aH\) then simplifies, and we find the aforementioned expression.

We need to define a few observationally relevant quantities.
The \textbf{tensor-to-scalar ratio} \(r\) is defined as
%
\begin{align}
r = \frac{\Delta _T}{\Delta _\zeta }
= \frac{ \frac{16}{M_P^2 \pi } H^2_*}{\Delta _\zeta }
\,.
\end{align}

This measures the level of primordial GWs compared to the amount of primordial scalar perturbations.
From CMB temperature anisotropies we can measure \(\zeta \), since at large scales \(\zeta \sim \delta T / T \sim \num{e-5}\). Therefore, \(\Delta_\zeta \sim \zeta^2 \sim \num{e-10}\) (this is known to a better precision, we just give an order of magnitude here).

The energy scale of inflation then can be written as
%
\begin{align}
E _{\text{inf}} \approx \SI{e16}{GeV} \qty(\frac{r}{\num{.01}})^{1/4}
\,.
\end{align}

Measuring \(r\) can allow us to probe extremely high energy scales.
The energy scale is reminiscent of Grand Unification Theories.
In modern models the connection to GUT theories is less strong.

The latest measurements, using \(B\)-mode polarization of CMB photons, which is characteristic of tensor perturbations, give a bound \(r < \num{.044}\) at a \SI{95}{\percent} CL. This number also includes \(B\)-mode data.
In the future we hope to be able to measure \(r \sim \num{e-2} \divisionsymbol \num{e-3}\).

The overall amplitude of tensor perturbations is
%
\begin{align}
\Delta _T = \frac{16}{\pi M_P^2} H^2_*
\,,
\end{align}
%
so
%
\begin{align}
\Delta_{\zeta } = \frac{H^2}{4 \pi^2} \frac{H^2}{\dot{\varphi}^2}
\marginnote{See equation \eqref{eq:density-perturbation-power-spectrum}.}
\,,
\end{align}
%
and \(\dot{H} = - 4 \pi G \dot{\varphi}^2\) (see \eqref{eq:derivative-Hubble-parameter-scalar-field}).
% \todo[inline]{Check: this is an exact expression, we just differentiate \(H^2= \frac{8 \pi G}{3} \qty( \dot{\varphi}/2 + V(\varphi ))\) and the use the equation of motion.}
This means that
%
\begin{align}
\epsilon  = - \frac{\dot{H}}{H^2} = + 4 \pi G \frac{\dot{\varphi}^2}{H^2}
\,.
\end{align}

So,
%
\begin{align}
\frac{H^2}{\dot{\varphi}^2} = \frac{4 \pi }{M_P^2} \frac{1}{\epsilon } \implies
\Delta_\zeta = \frac{H^2}{4 \pi } \frac{4 \pi }{M_P^2} \frac{1}{\epsilon } = \frac{H^2}{\pi M_P^2 } \frac{1}{\epsilon }
\,.
\end{align}

This allows us to express the tensor-to-scalar ratio as
%
\begin{align}
r =\frac{\Delta _T}{\Delta _\zeta } = 16 \epsilon
\,.
\end{align}

This gives us the \emph{consistency relation} for single-field models: \(n_T = - 2 \epsilon\), therefore \(r = - 8 n_T\).
It relates two observable variables: it can be used as a check.
This is why it is called the ``Holy Grail of cosmology''. If we saw it holds, we would be rather sure that inflation actually occurred.

This is extremely difficult to measure, it would be very hard to see even \(r\), \(n_T\) typically will have much larger errorbars.

\subsection{Base observational predictions}

We predict a scalar power spectrum
%
\begin{align}
\Delta_{\zeta } (k) = \Delta_\zeta (k_0 ) \qty( \frac{k}{k_0 })^{n_s-1}
\,,
\end{align}
%
where \(k_0 \) is the \emph{pivot scale}.
In the Planck data release \cite[]{planckcollaborationPlanck2018Results2019} the value of \(r\) is reported as \(r_{\num{.002}}\), where the index corresponds to the pivot scale \(k_0  = \SI{.002}{Mpc^{-1}}\).
The spectral index as usual is \(n_s - 1 = 2 \eta _V - 6\epsilon \).

Also,
%
\begin{align}
\Delta _T (k) = \Delta _T (k_0 ) \qty(\frac{k}{k_0 })^{n_T}
\,,
\end{align}
%
where \(n_T = - 2 \epsilon \).
At the pivot scale we have
%
\begin{align}
\Delta _\zeta (k_0 ) &= \eval{\frac{H^2}{\pi M_P^2 \epsilon }}_{k_0 }  \\
\Delta _T (k_0 ) &= \eval{\frac{16 H^2}{\pi M_P^2} }_{k_0 }
\,.
\end{align}

The value of \(H\) is determined by the potential \(V(\varphi )\), while the value of \(\epsilon \) depends on the derivative \(V' (\varphi )\), and the value of \(\eta _V\) depends on the second derivative \(V''(\varphi )\): recall
%
\begin{align}
H^2 &= \frac{8 \pi G}{3} V(\varphi )  \\
\epsilon &= \frac{1}{16 \pi G} \qty(\frac{V'}{V})^2  \\
\eta _V &= \frac{1}{8 \pi G} \qty(\frac{V''}{V})
\,.
\end{align}
%

If we are able to constrain the two (scalar and tensor) amplitudes and spectral indices we can reconstruct the inflationary potential.
We can reduce this four-parameter space: on the largest angular scales, \(\Delta T / T \sim \Delta _\zeta + \Delta _T\). This is very imprecise, there are transfer functions involved, however the basic idea is that there are contributions from both terms.

But \(\Delta T / T\) is well-known, so instead of the two amplitudes we can just measure \(r = \Delta _T / \Delta _\zeta \).
If we assume that the consistency relation holds, we have \(r = - 8 n_T\)
which reduces the parameter space to two parameters only: \((r, n_s)\).
This is commonly used in order to visualize inflationary models, since we can plot contours in a plane.
There, we can show observational constraints as in the lower row of figure 26 in the Planck 2018 release \cite[]{planckcollaborationPlanck2018Results2019}.

Large-field models have \(0 < \eta _V < 2 \epsilon \), while small field models have \(\eta _V < 0\).
% Recall that \(\eta _V = V'' / (3 H^2)\), so
Generally, small-field models predict low levels of GWs: we can express
%
\begin{align}
n_s -1 = 2 \eta _V - 6 \epsilon = 2 \eta _V - \frac{3}{8} r
\,,
\end{align}
%
so we can express \(r = r (n_s, \eta _V )\).
For more details see \textcite[]{kinneyNewConstraintsInflation2000}.
Small field models have \(V'' < 0\), large field models have \(V'' > 0\).

\subsubsection{Some examples of inflationary models}

Large field models could be \(V \propto \phi^{p}\) (a chaotic inflation scenario) or \(V \propto \exp(\phi / \mu )\) (powerlaw inflation).\footnote{Note that inflation cannot be exactly De Sitter! It would never end.} These have \(0 < \eta _V < 2 \epsilon \).

Small field models could be \(V \propto
1 - (\phi / \mu )^{p}\) (from SSB of, say, axion models) or \(V \propto 1 + (\phi / \mu )^{p}\) (from SUSY, often involving a second field).
These have \(\eta _V < 0 \).

There are also hybrid models, mixing small-field and large-field characteristics.
These are among the earlier examples of two-field models: \(\phi \) starts off similarly to large-field models, and moves towards a minimum with a nonzero VEV, provided by a second field \(\psi \), which is stuck to the minimum of its potential.

This second field is necessary for the model but it is not dynamical in this first phase, however it becomes unstable at the end of inflation, triggering it.
These models have \(\eta _V > 2 \epsilon \).

We can have these kinds of models arising from adding an \(R^2\) term to the Einstein-Hilbert action.
This corresponds to a new degree of freedom, with a transformation \(g_{\mu \nu } \to e^{-2 \omega } g_{\mu \nu }\) and a field \(\phi  \propto \omega \).
The potential is in the form
%
\begin{align}
V \propto \qty(1 - e^{-2 \omega })^2
\,.
\end{align}

We also have \emph{natural inflation}, with \(V \propto 1 - \cos(\phi / \mu )\): this is related to a shift symmetry \(\phi \to \phi + c\).
If this symmetry were exact we would have \(V = \const\), but if instead it is broken we have the aforementioned potential.
These are axion-like models: the shift symmetry arises naturally if \(\phi \) is a phase, corresponding to a \(U(1)\) symmetry like the Peccei-Quinn one.
The inflaton would not be the axion itself, but they would have similar properties.

\end{document}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{physics}
\usepackage{xcolor}
\usepackage{graphicx}
\definecolor{codegray}{rgb}{0.9,0.9,0.9}
\usepackage{listings}
\newcommand{\morpho}{\textit{morpho}}
\newcommand{\Morpho}{\textit{Morpho}}
\title{Q-tensor model of nematics}
\author{Chaitanya Joshi}
\date{October 2021}

\begin{document}
\lstset{
language=Java,
tabsize=4,
basicstyle=\ttfamily,
backgroundcolor=\color{codegray},
showstringspaces=false
}
\maketitle

\section{Introduction}
In 2D, for a uniaxial nematic, we can define a Q-tensor:
\[
Q_{ij} = S (n_i n_j - 1/2 \delta_{ij})
\]
Here, the $-1/2 \delta_{ij}$ is added for convenience, to make the matrix traceless:
\[\text{Tr}(\mathbf{Q}) = Q_{ii} = S(n_i n_i - 1/2 \delta_{ii}) = S(1 - 1/2(2)) = 0
\]
Now, the Q-tensor is also symmetric by definition:
\[
Q_{ij} = Q_{ji}
\]
Due to these two reasons we can write the Q-tensor as a function of only $Q_{xx}$ and $Q_{xy}$:
\[
\mathbf{Q} = \begin{bmatrix}Q_{xx} & Q_{xy} \\ Q_{xy} & -Q_{xx} \end{bmatrix}
\]
\subsection{Simple Passive Nematic Model}
The Landau-de Gennes equilibrium free energy for a nematic liquid crystal can be written in terms of the Q-tensor:
\begin{align*}
F_{LDG} = &\int_\Omega d^2{\bf x} \ \left(\frac{a_2}{2} \text{Tr}(\mathbf{Q}^2) + \frac{a_4}{4} (\text{Tr} \mathbf{Q}^2)^2 + \frac{K}{2}(\nabla\mathbf{Q})^2 \right) \\
&+ \oint_{\partial\Omega} d{\bf x} \frac{1}{2}E_A \text{Tr}[(\mathbf{Q}-\mathbf{W})^2]
\end{align*}
where $a_2 = (\rho-1)$ and $a_4 = (\rho+1)/\rho^2$
set the isotropic to nematic transition with $\rho$ being the non-dimensional density. The system is in the isotropic state for $\rho<1$ and in the nematic phase when $\rho>1$. In the nematic phase, $\ell_n = \sqrt{K/a_2}$ sets the nematic coherence length. Now,
\[
\mathbf{Q}^2 = \begin{bmatrix}Q_{xx} & Q_{xy} \\ Q_{xy} & -Q_{xx} \end{bmatrix} \begin{bmatrix}Q_{xx} & Q_{xy} \\ Q_{xy} & -Q_{xx} \end{bmatrix} = (Q_{xx}^2+Q_{xy}^2) \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}
\]
Hence,
\[
\text{Tr}(\mathbf{Q}^2) = 2(Q_{xx}^2+Q_{xy}^2)
\]
Similarly,
\[
(\nabla \mathbf{Q})^2 = \partial_i Q_{kj}\partial_i Q_{kj} = 2 \{ (\partial_x Q_{xx})^2+(\partial_xQ_{xy})^2 + (\partial_y Q_{xx})^2+(\partial_y Q_{xy})^2 \}
\]
Now, the second term is a boundary integral, with $E_A$ being the anchoring strength. $\mathbf{W}$ is the tensor corresponding to the boundary condition. For instance, for parallel anchoring,
\[
W_{ij} = (t_i t_j - 1/2 \delta_{ij})
\]
where $t_i$ is a component of the tangent vector at the boundary.
$\mathbf{W}$ is also a symmetric traceless tensor with two independent components $W_{xx}$ and $W_{xy}$.
The boundary term becomes:
\[ \text{Tr}[(\mathbf{Q}-\mathbf{W})^2] = 2\{ Q_{xx}^2 + Q_{xy}^2 - 2(Q_{xx}W_{xx} + Q_{xy}W_{xy}) + W_{xx}^2 + W_{xy}^2 \}
\]
\section{Vector formulation}
We can formulate all these expressions in terms of vector quantities:
\[\vec{q} \equiv \{ Q_{xx}, Q_{xy}\}\]
\[\vec{w} \equiv \{ w_{xx}, w_{xy}\}\]
Thus,
\[
\text{Tr}(\mathbf{Q}^2) = 2 ||\vec{q}||^2
\]

\[
(\nabla \mathbf{Q})^2 = 2 ||\nabla \vec{q}||^2
\]

\[
\text{Tr}[(\mathbf{Q}-\mathbf{W})^2] = 2 ||\vec{q}-\vec{w}||^2
\]
With these, we want to minimize the area-integral of
\[
F = \int_\Omega d^2{\bf x} \ \left( a_2 ||\vec{q}||^2 + a_4 ||\vec{q}||^4 + K||\nabla\vec{q}||^2 \right)
\]
together with the line-integral energy
\[
\oint_{\partial\Omega} d{\bf x} \ E_A ||\vec{q}-\vec{w}||^2
\]

\section{\Morpho \ implementation}
This free energy is readily set up in \morpho. For this problem, we will consider a 2D disk geometry with unit radius. We use $\rho=1.3$, so that we are deep in the nematic regime. We fix $E_{\text{A}}=3$, which sets strong anchoring at the boundary. With this strong tangential anchoring, we get a topological charge of $+1$ at the boundary, and this acts as a constraint. When the nematic coherence length is comparable to the disk diameter ($\ell_n \sim R$), the $+1$ charge penetrates throughout the disk, whereas if ($\ell_n \ll R$), then a formation with 2 $+1/2$ defects is more stable. To test this, we use two different values of $K$:, 0.01 and 1.0.

We first define all our parameters and import $\texttt{disk.mesh}$ from the tactoid example:
\begin{lstlisting}
var rho = 1.3 // Deep in the nematic phase
var EA = 3 // Anchoring strength
var K = 0.01 // Bending modulus

var a2 = (1-rho)
var a4 = (1+rho)/rho^2

var m = Mesh("disk.mesh")
var m = refinemesh(m) // Refining for a better result
var bnd = Selection(m, boundary=true)
bnd.addgrade(0) // add point elements

\end{lstlisting}
We define the Q-tensor in its vector form as discussed above, initializing it to small random values:
\begin{lstlisting}
var q_tensor = Field(m, fn(x,y,z)
Matrix([0.01*random(1), 0.01*random(1)]))
\end{lstlisting}
Note that this incidentally makes the director parallel to a 45 degree line.
We now define the bulk energy, the anchoring energy and the distortion free energy as follows:
\begin{lstlisting}
// Define bulk free energy
fn landau(x, q) {
  var qt = q.norm()
  var qt2=qt*qt
  return a2*qt2 + a4*qt2*qt2
}
// Define anchoring energy at the boundary
fn anchoring(x, q) {
  var t = tangent()
  var wxx = t[0]*t[0]-0.5
  var wxy = t[0]*t[1]
  return (q[0]-wxx)^2+(q[1]-wxy)^2
}

var bulk = AreaIntegral(landau, q_tensor)
var anchor = LineIntegral(anchoring, q_tensor)
var elastic = GradSq(q_tensor)
\end{lstlisting}
Equipped with the energies, we define the \texttt{OptimizationProblem}:
\begin{lstlisting}
var problem = OptimizationProblem(m)
problem.addenergy(bulk)
problem.addenergy(elastic, prefactor = K)
problem.addenergy(anchor, selection=bnd, prefactor=EA)
\end{lstlisting}
To minimize the energy with respect to the field, we define the \texttt{FieldOptimizer} and perform a \texttt{linesearch}:
\begin{lstlisting}
var opt = FieldOptimizer(problem, q_tensor)
opt.linesearch(500)
\end{lstlisting}
\section{Visualizing the result}
For visualizing the final configuration, we use the same piece of code we used for the tactoid example, and define some additional helper functions to extract the director and the order from the Q-tensor.
\begin{lstlisting}
fn sign(x) {
  if (x<0.0) return -1.0
  else if (x>0.0) return 1.0
  return 0.0
}
\end{lstlisting}
\begin{lstlisting}
fn qtodirector(q) {
  var S = 2*q.norm()
  var Q = q/S
  var nx = sqrt(Q[0]+0.5)
  var ny = abs(Q[1]/nx)
  nx*=sign(Q[1])
  return Matrix([nx,ny,0])
}
\end{lstlisting}
\begin{lstlisting}
fn qtoorder(q) {
  var S = 2*q.norm()
  return S
}
\end{lstlisting}
\begin{lstlisting}
// Convert the q-tensor to the director and order
var nn = Field(m, Matrix([1,0,0]))
for (i in 0...m.count()) nn[i]=qtodirector(q_tensor[i])
var S = Field(m, 0)
for (i in 0...m.count()) S[i]=qtoorder(q_tensor[i])
\end{lstlisting}
\begin{lstlisting}
// Function to visualize a director field
fn visualize(m, nn, dl) {
  var v = m.vertexmatrix()
  var nv = v.dimensions()[1]
  var g = Graphics()
  for (i in 0...nv) {
    var x = v.column(i)
    g.display(Cylinder(x-nn[i]*dl, x+nn[i]*dl,
    aspectratio=0.3))
  }
  return g
}

// Visualize the result
// var g=plotmesh(m, grade=1)
var splot = plotfield(S, style="interpolate")
var gnn=visualize(m, nn, 0.05)
var gdisp = splot+gnn
Show(gdisp)
\end{lstlisting}
We can go further and use the \texttt{povray} module to render a \texttt{.png} output:
\begin{lstlisting}
var pov = POVRaytracer(gdisp)
pov.viewangle=35
pov.render("Qtensor_K_${K}.pov")
\end{lstlisting}
\begin{figure}
    \centering
    \includegraphics[width=0.45\linewidth]{Qtensor_K_1.png}
    \includegraphics[width=0.45\linewidth]{Qtensor_K_0.01.png}
    \caption{Final configuration of the director and order for (left) $K=1$ and (right) $K=0.01$. The cylinders indicate the nematic director whereas the color indicates the scalar order parameter. Note how the $K=1$ case has a single $+1$ defect at the center whereas the $K=0.01$ case has two $+1/2$ defects.}
    \label{fig:qtensor}
\end{figure}
This creates beautiful plots of the nematic, as seen in the example Figure \ref{fig:qtensor}.
Like the tactoid example, we can do adaptive mesh refinement based on the elastic energy density as well. The full code, along with the optional adaptive refinement can be found under \texttt{examples/qtensor/qtensor.morpho}.
\end{document}


\documentclass{article}

% include some useful things
\usepackage{verbatim}  % for printing unformatted text
\usepackage{float}         % for controlling the location of figure and graphics on the page
\usepackage{blindtext}
\usepackage{graphicx}\usepackage{amsmath}
\usepackage{amsmath}
\usepackage{amssymb}
%  Begin writing content below this line
\begin{document}

%  Print your name and the assignment number
\begin{center}{\huge  Deepayan Bhadra - hmwk1 Solutions}\end{center}

\section*{Solution to Q1}

Hilbert matrices are known for being ill-conditioned. Thus, due to the high condition number, the noise amplifies during reconstruction. The amplification added to the trailing eigen-vector is $1/\lambda_{min}$

\section*{Solution to Q2}
The dual norm of $\|\cdot\|$ is defined as
$$\|x\|_*  = \max_{\|z\|\le 1} z^Tx.$$
We need to prove that the dual norm is indeed a norm. Thus, we need to verify if the dual norm satisfies the properties of a norm as follows:\\ \newline
1. $||x||$  $\geq$ 0 $\forall$ x$\in R^n$, and $||x||$ = 0 iff x = 0 (Non-negativity)\newline
2. $||\alpha x||$ = $|\alpha|||x|| \quad\forall x \in R^n \quad\forall \alpha \in R$ (Homogeneity) \newline
3. Triangle inequality: $||x+y|| \leq ||x|| + ||y|| \quad \forall x,y \in R^n$
\\\\
The first two properties are easy to verify as follows: \newline

1. $z$ can always be chosen such $||x||_* \geq 0$. Since $z$ can also be $> 0$, $||x||_*=0$ iff $x=0$. Hence.

2. $\|\alpha x\|_*  = \max_{\|z\|\le 1} z^T (\alpha x) = |\alpha| \max_{\|z\|\le 1} z^Tx = |\alpha|\|x\|_* $

3. $||x+y||_* = \max_{\|z\|\le 1} (z^Tx + z^Ty) \leq  \max_{\|z\|\le 1} z^Tx +  \max_{\|z\|\le 1} z^Ty = \|x\|_* + \|y\|_*$

\section*{Solution to Q3}

We have $||\hat{x} - x|| = ||A^{-1} \hat{b} - A^{-1} b|| \leq ||A^{-1}||||\hat{b}-b|| $ \newline \newline Also, $||Ax|| = ||b|| \leq ||A||||x|| $ \newline \newline Dividing the first inequality by the latter one yields \newline \newline $\frac{||\hat{x}-x||}{||A||||x||} \leq \frac{||A^{-1}||||\hat{b}-b||}{||b||} $ \newline \newline Condition number of a square nonsingular matrix A is defined as $||A||.||A||^{-1}$ \newline Thus re-arranging the inequality, we get our desired result.

\section*{Solution to Q4}
We have \\\\
$p(y|x) = \frac{1}{\sqrt{(2\pi)^m|\Sigma|}} exp\big( -\frac{1}{2}(y-Dx)^T\Sigma^{-1}(y-Dx)\big) $
$p(x) = \Pi_{i} \frac{1}{2b}exp(-\frac{|x_i|}{b}) = \frac{1}{(2b)^n} exp(-\frac{||x||_1}{b}) $
From Baye's rule, we have \\\\
$ p(x|y) \sim p(y|x)p(x) = \frac{1}{\sqrt{(2\pi)^m|\Sigma|}} exp \big( -\frac{1}{2}(y-Dx)^T\Sigma^{-1}(y-Dx) \big) \frac{1}{(2b)^n}exp(-\frac{||x||_1}{b}) $
The log-likelihood (LL) follows by taking log \\\\
$-\frac{m}{2}log(2\pi) -\frac{1}{2}log|\Sigma| -\frac{1}{2} (y-Dx)^T\Sigma^{-1}(y-Dx) - nlog(2b) -\frac{1}{b}||x||_1 $ \\\\
The negative log-likelihood (NLL) occurs by multiplying with -1 and re-arranging :\\\\
$ \frac{1}{b}||x||_1 + \frac{1}{2}(y-Dx)^T\Sigma^{-1}(y-Dx) + \frac{1}{2}(mlog(2\pi) + log|\Sigma|) + nlog(2b) $ \\\\
For minimization, we can ignore the constant terms and simply : \\\\
Minimize $ \frac{1}{b}||x||_1 + \frac{1}{2}(y-Dx)^T\Sigma^{-1}(y-Dx). $

\newpage % Put the console output on a fresh page to make it look all pretty.
\section*{Solution to Q5:  Code from hmwk1.py}
% The verbatim environment is good for reproducing text without having latex try to format it for you.
\begin{verbatim}

import numpy as np
def buildmat(m,n,condNumber):
    A = np.random.randn(m, n)
    np.linalg.cond(A)
    U, S, V = np.linalg.svd(A)
    S = np.array([[S[j] if i==j else 0 for j in range(n)] for i in range(m)])
    S[S!=0]= np.linspace(condNumber,1,min(m,n))
    A=U.dot(S).dot(V)
    return A
# For a 3x5 matrix

m,n,condNumber = 3,5,2
print("The 3x5 matrix A and the condition no. are\n")
A = buildmat(m,n,condNumber)
print(np.matrix(A),"\n")
print(np.linalg.cond(A),"\n")

# For a 5x4 matrix

m,n,condNumber = 5,4,4
print("The 5x4 matrix A and the condition no. are\n")
A = buildmat(m,n,condNumber)
print(np.matrix(A),"\n")
print(np.linalg.cond(A),"\n")

\end{verbatim}

\end{document}


% !TEX root=/home/tavant/these/manuscript/src/manuscript.tex

\section{Propulsion system for spacecrafts}
\label{sec-propulsion}
% \addcontentsline{toc}{section}{Propulsion system for spacecrafts}

In order to move in space, satellites, scientific probes, and spacecrafts in general rely on a propulsion system.
The cost to go from one location to another can be expressed as $\Delta v$, a measure of impulse needed to maneuver.
\nomenclature[Q]{$\Delta v$}{Measure of impulse needed for a space manoeuvre}
\Cref{fig-subway_DV} illustrates the $\Delta v$ required to evolve in the solar system.
We can see that reaching \ac{LEO} needs a $\Delta v$ of 9400 m/s while the \ac{GEO} is 3910 m/s further.
Landing on the Moon from the Earth ground requires a total of 15 km/s, while landing on Neptune requires $\Delta v =43.7$\,km/s.
For a spacecraft of instantaneous mass $M(t)$, with a propulsion system generating a thrust $T(t)$, the $\Delta v$ between $t_1$ and $t_2$ is
\begin{equation} \label{eq-dv}
  \Delta v = \int_{t_1}^{t_2} \frac{ \norm{T(t)}}{M(t)} dt.
\end{equation}
As expected, we see from \cref{eq-dv} that for a more massive spacecraft, a more intense, or a longer thrust is needed in order to obtain the same $\Delta v$.
\nomenclature[Q]{\ensuremath{ t}}{Time}
\nomenclature[Q]{\ensuremath{ T}}{Thrust}
\nomenclature[Q]{\ensuremath{ M}}{Mass of a spacecraft}
\begin{figure}[!hbt]
  \centering
  \includegraphics[width=\textwidth]{subway_map_legend}
  \caption{Representation of the different $\Delta v$ needed to go around the solar system, from \citet{reddit-subway}}
  \label{fig-subway_DV}
\end{figure}

\subsection{The rocket equation}
The thrust $T$ generated by ejecting mass at high velocity is
\begin{equation} \label{eq-thurst}
  T = v_{\rm ex} \dot{M}
\end{equation}
with $v_{\rm ex}$ the exhaust velocity of the propellant, and $\dot{M}$ the propellant mass flow rate through the thruster.
Hence,
\begin{equation} \label{eq-rocket}
  \Delta v = \int_{t_1}^{t_2} v_{\rm ex} \frac{ \norm{\dot{M}}}{M(t)} dt = v_{\rm ex} \ln \lp \frac{M_0}{M_1} \rp
\end{equation}
with $M_0 = M(t_0)$ and $M_1=M(t_1)$, and supposing that $v_{\rm ex}$ is constant.
We see from \cref{eq-rocket} that for a spacecraft of dry mass $M_1$ to have a given $\Delta v$, the exhaust velocity is directly linked to the initial \emph{wet} mass $M_0 = M_1 + M_{\rm prop}$, with $M_{\rm prop}$ the propellant mass.
\Cref{eq-rocket} is known as the rocket equation, or Tsiolkovsky's equation.
Usually, instead of the exhaust velocity $v_{\rm ex}$, the specific impulse ${\Isp} = g_0 v_{\rm ex}$, with $g_0$ the standard gravity, is used.
\nomenclature[Q]{\ensuremath{ \Isp}}{ Specific impulse, related to the exhaust velocity of a propellant}
\nomenclature[P]{\ensuremath{ g_0}}{  Standard acceleration due to gravity \nomunit{9.80665 m/s$^2$}}

\subsection{Chemical propulsion systems}
The usual rocket thruster uses a chemical reaction to generate the thrust.
For instance, the Vulcain (the thruster engine of the main stage of the European Ariane 5 and 6, developed by ArianeGroup, ex. Safran) uses the oxygen-hydrogen combustion, the most efficient chemical reaction for chemical thrusters \citep{nasa-H2O2}
\begin{equation*}
  2 {\rm H_2} + { \rm O_2} = 2 {\rm H_2 O} + 572 \text{~kJ},
\end{equation*}
with the energy of $572\,\kilo\joule$ of heat generated by $1\,\mole$ of oxygen.
This means that burning $1\,\kilo\gram$ of hydrogen-oxygen mixture generates a total energy of $13\,\mega\joule$.
Supposing that the entire energy is converted into the exhaust of the water produced, its velocity would be of $5.1 \,\kms$.
In reality, the exhaust velocity of the Vulcain is of $4.2 \,\kms$, corresponding to $\Isp=431 \,\second$.
The efficiency of the Vulcain is close to 80\%, which is a very high efficiency, and it would be difficult to increase it significantly.

In chemical propulsion systems, the fact that the energy released is related to the propellant mass gives an upper limit of exhaust velocity for a given combustion.
Electric propulsion engines, on the other hand, decouple the mass ejected (the propellant) from the energy source.
This decoupling allows a theoretical unlimited exhaust velocity.
Another advantage is the absence of reactive species, which lowers the security requirements impacting the spacecrafts.
Unfortunately, electric propulsion engines only work in vacuum and do not deliver sufficient thrust to compensate the earth gravity.
Hence, while electric propulsion can be used on spacecrafts, chemical propulsion is the only solution for rockets.

\subsection{Electric propulsion systems} \label{subsec-EP}
\ac{EP} systems mostly rely on plasmas \citep{charles2009,mazouffre2016}.
They have been successfully used since the 1960s by governments, but their complexity, the limited electric power available, and the inherent risk aversion of the space industry kept the \ac{EP} technologies hidden from the commercial applications \citep{lev2019}.
The breakthrough came in the '90s when the former Soviet Union's companies licensed the technology to Western propulsion companies.
However, many commercial satellite manufacturers were skeptical, until the first decade of the 21st century, which brought strong evidence of the competitiveness of \ac{EP}.
The landmark of commercial use of \ac{EP} is the selling of four all-electric satellites for \ac{GEO} by Boeing in 2012, the first two of which were launched in March 2015.

The two leading \ac{EP} technologies used are
\begin{itemize}
  \item the \ac{HET}, also known as Stationary Plasma Thruster (SPT) in Russia
  \item the Gridded Ion Thruster (GIT), usually referred simply as Ion Thruster
\end{itemize}

 \paragraph{The Gridded Ion Thruster} is a plasma chamber closed at one end by two or more grids.
 The plasma source can be an emitting cathode, generating energetic electrons that ionize the propellant (usually Xenon), or a \ac{RF} source.
 The potential difference between the grids accelerates the ions.
 Another cathode is used to neutralize the ion beam.
 Compared to \ac{HET}s, it produces an ion beam with less divergence and a higher \Isp of the order of 3000 to 4000~s.
 \Cref{fig-iongridded} shows a picture of the ion thruster used for the BepiColombo mission toward Mercury.
 We see the neutralizing cathode, the accelerating grid, and the ion beam.

\begin{figure}[!hbt]
  \centering
  \includegraphics[width=\defaultwidth]{ion_Bepi.png}
  \caption{The T6 ion thruster will help send BepiColombo to Mercury. The neutralizing cathode is in the upper left quadrant of the thruster. (Credit\string: QinetiQ)}
  \label{fig-iongridded}
\end{figure}

 \paragraph{Hall Effect thrusters} use a magnetic barrier to both increase the ionization of the propellant and create the accelerating electric field.
 A detailed description of the \ac{HET} is presented in the next section.
 One cathode is used to start the discharge and neutralize the ion beam.
 Compared to GITs, \ac{HET}s need less power, hence reaching better thrust per power ratio and a smaller (therefore lighter) Power Processing Unit.
 Recently, the first satellites of two mega-constellations (OneWeb, 648 satellites planned, from which six were launched on February, \nth{26} 2019, and Starlink, 12~000 satellites planned, from which 62 were launched on May, \nth{23} 2019) were sent to Low Earth orbit, both using \ac{HET}s.
 % Compared to GITs, \ac{HET}s need less power, and fewer power sources, hence reaching better thrust per power ratio and smaller (therefore lighter) Power Processing Unit.
 Their typical \Isp is of the order of 1500~s.
 \Cref{fig-13kWHET} shows a high power prototype firing.
 We see the emitting cathode, in this design at the center, and the ion beam.
 \begin{figure}[!hbt]
   \centering
   \includegraphics[width=\defaultwidth]{HET_X3_light.png}
   \caption{A 13 kilowatt \acs{HET} prototype on a testing bench in a vacuum chamber (Credit\string: NASA).  }
   \label{fig-13kWHET}
 \end{figure}

 \subsection{Electric propulsion environment in France} \label{subsec-HET_thruster}

 France is a leader country in the aerospace industry in both Europe and the world, with companies such as  Airbus, Thales, Safran, and ArianeGroup (join-venture of Safran and Airbus).
 As a consequence, the French ecosystem of electric propulsion is vibrant.
 The main thrusters produced in France are the PPS series by Safran, with the \PPS1350 (version G at 1.5~kW nominal power, and the version E at 2.7~kW), and the \PPS5000, a high power \ac{HET} at 5~kW, the first models of which have been delivered to Boeing in May 2019.
 A low-power version (between 500W and 1kW) of the \PPS{}  is currently developed\citep{vaudolon2018}.
 A list for the \PPS{} series elements and their respective characteristics can be seen in \cref{tab-ppsfamily}.
 \begin{table}[!hbt]
 \ra{1.3}
   \centering
   \caption{Members of the \PPS{} series developed by Safran Aircraft Engines \citep{boniface2017,duchemin2017,vaudolon2018}. The nominal operating condition of the \PPS{X00} is not fixed yet.}
   \label{tab-ppsfamily}
   \begin{tabular}{@{}llll@{}} \toprule
   Name & Power & Thrust & \Isp \\ \midrule
   \PPS1350-G & 1.5~kW & 89~mN  & 1650~s \\
   \PPS1350-E & 2.7~kW & 140~mN  & 1800~s \\
   \PPS5000 & $3-5$~kW & $150-300$~mN  & $1850-1700$~s \\
   \PPS{X00} & $\sim 650$W &  $\sim$40~mN & $\sim 1450$~s \\
   \bottomrule
   \end{tabular}
 \end{table}

 Several initiatives concerning the small-sat sector are also undertaken, such as the start-ups Exotrail (micro \ac{HET}) and Thrust Me (radio frequency Ion Thruster), or the Electron Cyclotron Resonance Thruster at ONERA.
 Since 1996, numerous research projects have been carried out in France on HET with  the \ac{CNES}, SAFRAN and several research laboratories: ICARE, LAPLACE, CPHT, LPP, etc. \citep{boniface2017}.
 These numerous actors, combined with the support of the French and European space agencies, compose a stimulating environment that contributes both to the most mature technologies and the promising \ac{EP} concepts that could disrupt the propulsion sector.


% A '%' character causes TeX to ignore all remaining text on the line,
% and is used for comments like this one.
% All LaTex files require the commands:
% \documentclass (with argument)
% \begin{document} command
% \end{document} command

% specifies the document class. We usually use article but there are others.
\documentclass{article}

% these are standard packages used for the math symbols
\usepackage{amsmath,amssymb,amsthm, graphicx, color, gensymb,mathpazo, enumitem}

% These commands below is to make sure the numbering of these are consistent with theorem
% If you are not sure what something means, delete them, build a new file and see the
% difference between the files. You can ignore this part for now.
\newtheorem{theorem}{Theorem}[section]
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{example}[theorem]{Example}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{notation}[theorem]{Notation}

\begin{document}

% Title of my document
\title{\Large Infinite Stream of Electrons}

% The author command places text right after title
\author{Prannaya Gupta}
\date{\today}
\maketitle

\section{Question}
Let's say you have an infinite stream of electrons spaced $s = 1mm$ apart. These electrons are initially charged with an initial kinetic energy of $E_k = 20keV$. These electrons enter a changing magnetic field $B_1 = B_o\sqrt{e^{t^2-1}+5}$, where $B_o = 2.3232323232...T$ facing out of the page. Certainly, we can therefore gather that the stream tilts upwards, but let's just assume the radius r is constant.
\\
\\
After a time $T = 5s$, this stream exits the magnetic field to move an arbitrary distance upwards to enter a wire loop of mass $M = 16kg$ and diameter $d = 3cm$. After exiting the loop, the electrons just leave to an electron storage, never to be seen again. Now, once there is assured to be absolutely no change in the current of the loop, a uniform magnetic field $B_2 = 2.1111111...T$ facing downwards perpendicular to the electrons' motion before entering the loop is placed on the loop, and a torque is therefore exerted. Find the angular velocity of the loop when it rotates exactly $\frac{\pi}{2}$ radians.
\\
\\
The moment of inertia of a hoop about any diameter, $I_{loop} = \frac{1}{2}MR^2$.
\\
The mass of an electron, $m_e = 9.109383701528 \times 10^{-31} kg$.
\\
The elementary charge, $q_e = 1.602176634 \times 10^{-19} C$.

\begin{enumerate}[label=\uppercase\alph*)]
  \item $3.26 \times 10^{-6}$ rad/s
  \item 0.00181 rad/s
  \item 0.00219 rad/s
  \item \textbf{0.0426 rad/s}
  \item $1.37 \times 10^{13}$ rad/s
\end{enumerate}

\section{Solution}

\begin{align*}
r &= \frac{mv}{qB_o} \\
&= \frac{\sqrt{2m_eE_k}}{qB_o} \\
\\
qvB_1 &= \frac{mv^2}{r} \\
v &= \frac{rq}{m}B_1 \\
a &= \frac{rq}{m}\dot{B_1} \\
F_{net} &= rq\dot{B_1} \\
J &= \int_0^T F_{net} dt \\
&= rq[B_1(T) - B_1(0)] \\
&= \frac{\sqrt{2m_eE_k}}{B_o}[B_o\sqrt{e^{T^2-1}+5} - B_o\sqrt{e^{0^2-1}+5}] \\
\\
p_f &= p_i + J \\
&= \sqrt{2m_eE_k} + \frac{\sqrt{2m_eE_k}}{B_o}[B_o\sqrt{e^{T^2-1}+5} - B_o\sqrt{e^{0^2-1}+5}] \\
&= \sqrt{2m_eE_k} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}]\\
\\
\therefore v &= \sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}] \\
\\
I &= nAqv \\
&= \frac{N}{\pi d}q_ev \\
&= \frac{\pi d}{s} \frac{1}{\pi d} q_ev \\
&= \frac{q_ev}{s} \\
&= \frac{q_e}{s}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}]
\end{align*}

\begin{align*}
\tau &= IAB_2 \\
&= \frac{q_e}{s}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}] \cdot \pi (\frac{d}{2})^2\cos{\theta} \times B_2 \\
&= \frac{\pi d^2q_eB_2\cos{\theta}}{4s}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}] \\
\\
E &= \int_0^\frac{\pi}{2}\tau d\theta \\
&= \int_0^\frac{\pi}{2} \frac{\pi d^2q_eB_2}{4s}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}]\cos{\theta}  d\theta \\
&= \frac{\pi d^2q_eB_2}{4s}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}] \int_0^\frac{\pi}{2}\cos{\theta}  d\theta \\
&= \frac{\pi d^2q_eB_2}{4s}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}][sin(\frac{\pi}{2}) - sin(0)] \\
&= \frac{\pi d^2q_eB_2}{4s}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}] \\
&= I_{loop}\omega^2
\\\\
I_{loop} &= \frac{1}{2}MR^2 \\
&= \frac{1}{2}M(\frac{d}{2})^2 \\
&= \frac{1}{8}Md^2
\\\\
I_{loop}\omega^2 &= \frac{\pi d^2q_eB_2}{4s}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}] \\
\frac{1}{8}Md^2\omega^2 &= \frac{\pi d^2q_eB_2}{4s}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}] \\
% \omega^2 &= \frac{2\pi q_eB_2}{Ms}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}] \\
\omega &= \sqrt{\frac{2\pi q_eB_2}{Ms}\sqrt{\frac{2E_k}{m_e}} [1 + \sqrt{e^{T^2-1}+5} - \sqrt{e^{0^2-1}+5}]} \\
\end{align*}
Upon substitution, we get $\omega$ = 0.042582009977078686 rad/s $\approx$ \textbf{0.0426 rad/s}

\end{document}


% !TeX root = ../main.tex
% Add the above to each chapter to make compiling the PDF easier in some editors.

\chapter{Offline Algorithms}\label{chapter:offline_algorithms}

To later measure the performance of online algorithms, we must first describe efficient offline algorithms that can be used to find optimal (or nearly optimal) solutions. In this chapter, we, therefore, describe algorithms for fractional and integral smoothed convex optimization. We begin with a general investigation of (fractional) convex optimization. Then, we turn to specific algorithms described in the literature for the uni-dimensional and multi-dimensional settings.

In our general argument, we want to use that the cost function $c_{\text{SCO}}$ is convex on $\mathcal{X}^T$ implying that algorithms for convex optimization can be used to solve the fractional offline case optimally.

\begin{lemma}
$c_{\text{SCO}}(X) = \sum_{t=1}^T f_t(X_t) + \norm{X_t - X_{t-1}}$ is convex on $\mathcal{X}^T$.
\end{lemma}
\begin{proof}
By definition $f_t$ is convex on $\mathcal{X}$. Every norm $\norm{\cdot}$ on $\mathcal{X}$ is convex by the triangle inequality as shown by the following argument: \begin{align*}
    \forall x, y \in \mathcal{X}.\ \forall \lambda \in [0,1].\ \norm{\lambda x + (1 - \lambda) y} \leq \norm{\lambda x} + \norm{(1 - \lambda) y} = \lambda \norm{x} + (1 - \lambda) \norm{y}.
\end{align*} In total we get that the sum of convex functions is also convex.
\end{proof}

\section{Convex Optimization}\label{section:offline_algorithms:convex_optimization}

As the offline variant of SCO simply is the problem of minimizing $c_{\text{SCO}}$, it is easy to see that we can use a convex optimization solver to obtain the optimal schedule $\hat{X}$. Throughout our discussion of algorithms, we denote schedules by $X$ and optimal solutions by $\hat{\cdot}$. Further, as we do not impose any constraints beyond the bounds of the decision space $\mathcal{X} \subset \mathbb{R}^d$ it suffices to find the local optimum of $c_{\text{SCO}}$ with respect to $\mathcal{X}$. By the convexity of $c_{\text{SCO}}$ we know that any local optimum will also be a global optimum~\cite{Bubeck2015}. We can choose the algorithm for finding the local optimum based on our knowledge of the properties of $c_{\text{SCO}}$. If, for example, $c_{\text{SCO}}$ is differentiable on $\mathcal{X}$ we could use gradient descent. In general, even if we cannot be sure of the differentiability of $c_{\text{SCO}}$ we can always find a subgradient in the interior of $\mathcal{X}$~\cite{Bubeck2015}. We denote by $\partial c_{\text{SCO}}(x)$ the set of subgradients of $c_{SCO}$ at the point $x \in \mathcal{X}$.

We are interested in finding good approximations of $\hat{x}$. To that end, we call a solution $\hat{x}$ \emph{$\epsilon$-optimal}\index{$\epsilon$-optimal solution} if $\norm{g(\hat{x})}^2 \leq \epsilon$ where $g \in \partial c_{\text{SCO}}(\hat{x})$. Using the projected subgradient method we are able to find an $\epsilon$-optimal solution $\hat{x}$ in $\mathcal{O}(1 / \epsilon^2)$ iterations~\cite{Boyd2003}. Note that this convergence rate is dimension-independent.

In our implementation, we use two different algorithms for derivative-free local optimization. We use the Subplex method, which extends the Nelder-Mead method if there are no equality or inequality constraints beyond the bounds on the decision space~\cite{Rowan1990}. If we impose such constraints, we use the COBYLA (Constrained Optimization BY Linear Approximations) algorithm, which iteratively constructs linear approximations of the objective functions and approximates constraints using a simplex in $d+1$ dimensions~\cite{Powell1994, Powell1998}. We use implementations from the NLopt library~\cite{Johnson}.

To be able to solve the optimization problem efficiently, it is crucial to quickly find a point $x \in \mathcal{X}$ of which the associated cost is finite. Until such a point is found, the algorithms sample values from the decision space without direction. Our primary use of convex optimization solvers is to determine a minimizer of the hitting cost. Furthermore, in the application of dynamically right-sizing data centers, hitting costs are always finite for the upper bound of the decision space. We, therefore, use this upper bound as the first guess for finding the minimizer even if this guess may be farther away from the minimizer than the lower bound. A convex optimization that does not terminate thus indicates that the problem is infeasible, for example, because the provided load profile is infeasible.

Note that we cannot draw this conclusion if we solve for a different objective, such as \cref{eq:heterogeneous_load_balancing_convex_program} or \cref{eq:multiple_load_types_load_balancing_convex_program}. In these cases, there is no guarantee that the solver will find a feasible point unless it searches over the entire decision space. In the given example, however, choosing the uniform distribution across all active server types performs well in practice. This heuristic ensures that no server type without at least one active server is assigned load, which would incur an infinite cost by definition.

We have seen a general method of solving high-dimensional (fractional) SCO, though the convergence rate could be increased using an accelerated gradient method if the hitting costs are strongly convex or conditional gradient descent if the hitting costs are smooth~\cite{Bubeck2015}. Denoting the complexity of computing the hitting cost $f_t$ by $\mathcal{O}(C)$ and the convergence rate of a convex optimization with $\alpha$ dimensions by $\mathcal{O}(O_{\epsilon}^{\alpha})$ we obtain a total complexity of $\mathcal{O}(T C O_{\epsilon}^{T d})$. We observe, however, that our method does not extend to the integral case, which is of particular importance for the application of right-sizing data centers. We, therefore, devote much of the remaining chapter to the discussion of algorithms for integral variants of SCO.

\section{Uni-Dimensional}

We now limit our attention to the uni-dimensional setting, i.e. $\mathcal{X} \subset \mathbb{R}$.

\subsection{Backward-Recurrent Capacity Provisioning}\label{section:offline_algorithms:ud:capacity_provisioning}

Before discussing algorithms for Int-SSCO, we discuss a simple backward-recurrent algorithm for SSCO proposed by \citeauthor{Lin2011}~\cite{Lin2011} based on capacity provisioning. They extend this idea to formulate an online algorithm which we discuss in \cref{section:online_algorithms:ud:lazy_capacity_provisioning}.

\citeauthor{Lin2011}~\cite{Lin2011} observed that the optimal offline solution can be characterized by two bounds corresponding to charging the switching cost for powering-up and powering-down servers, respectively. Let $\tau \in [T]$ be a time slot. Then the optimal offline solution $\hat{X}_{\tau}$ during time slot $\tau$ is lower bounded by $X_{\tau,\tau}^L$ where $X_{\tau}^L$ is the smallest vector minimizing \begin{align}\label{eq:ud:brcp:lower}
    c_{\tau}^L(X) = \sum_{t=1}^{\tau} f_t(X_t) + \beta (X_t - X_{t-1})^+.
\end{align} Conversely, $\hat{X}_{\tau}$ is upper bounded by $X_{\tau,\tau}^U$ where $X_{\tau}^U$ is the largest vector minimizing \begin{align}\label{eq:ud:brcp:upper}
    c_{\tau}^U(X) = \sum_{t=1}^{\tau} f_t(X_t) + \beta (X_{t-1} - X_t)^+.
\end{align} Overall we have $X_{\tau,\tau}^L \leq \hat{X}_{\tau} \leq X_{\tau,\tau}^U$~\cite{Lin2011}. Note that the switching cost is paid for powering up a server for the lower bound, while for the upper bound, the switching cost is paid for powering down a server. Further, it is easy to see that the bounds for time slot $\tau$ do not depend on any time slots $t > \tau$.

An optimal offline algorithm can be described as determining the optimal schedule moving backward in time. We begin by setting $\hat{X}_{T+1} = 0$. For each previous time slot $\tau$, we set $\hat{X}_{\tau} = \hat{X}_{\tau + 1}$ unless this violates the bounds, in which case we make the smallest possible change: \begin{align*}
    \hat{X}_{\tau} = \begin{cases}
        0 & \tau > T \\
        (\hat{X}_{\tau+1})_{X_{\tau,\tau}^L}^{X_{\tau,\tau}^U} & \tau \leq T
    \end{cases}
\end{align*} where $(\hat{X}_{\tau+1})_{X_{\tau,\tau}^L}^{X_{\tau,\tau}^U}$ is the projection of $\hat{X}_{\tau+1}$ onto $[X_{\tau,\tau}^L, X_{\tau,\tau}^U]$~\cite{Lin2011}. The resulting algorithm is described in \cref{alg:brcp}. We can use algorithms for convex optimization to compute the upper and lower bounds. Hence, we obtain a complexity of $\mathcal{O}(T^2 C O_{\epsilon}^T)$ for $\epsilon$-optimal upper and lower bounds. An example of Backward-Recurrent Capacity Provisioning is given in \cref{fig:backward_recurrent_capacity_provisioing_vs_lazy_capacity_provisioning}.

\begin{algorithm}
    \caption{Backward-Recurrent Capacity Provisioning~\cite{Lin2011}}\label{alg:brcp}
    \SetKwInOut{Input}{Input}
    \Input{$\mathcal{I}_{\text{SSCO}} = (T \in \mathbb{N}, m \in \mathbb{N}, \beta \in \mathbb{R}_{>0}, (f_1, \dots, f_T) \in (\mathbb{R}_{\geq 0} \to \mathbb{R}_{\geq 0})^T)$}
    $\hat{X}_{T+1} \gets 0$\;
    \For{$\tau \gets T$ \KwTo $1$}{
        find $X_{\tau,\tau}^L$ using the optimization described by \cref{eq:ud:brcp:lower}\;
        find $X_{\tau,\tau}^U$ using the optimization described by \cref{eq:ud:brcp:upper}\;
        $\hat{X}_{\tau} \gets (\hat{X}_{\tau+1})_{X_{\tau,\tau}^L}^{X_{\tau,\tau}^U}$\;
    }
    \Return $\hat{X}$\;
\end{algorithm}

\subsection{Graph-Based Optimal Integral Algorithm}\label{section:offline_algorithms:ud:graph_based}

We now turn to the uni-dimensional integral case of simplified smoothed convex optimization, i.e., our decision space is given as $\mathcal{X} := [m]_0$ where $m \in \mathbb{N}$ is the maximum number of servers a data center can employ at the same time. As our decision space is discrete and finite, it is natural to model our problem as a weighted directed graph which is comprised of vertices $v_{t,j}$ for each $t \in [T]$ and $j \in [m]_0$ describing the state that during time slot $t$ exactly $j$ servers are active. For the initial and final state $X_0 = X_{T+1} = 0$ we have two additional vertices $v_{0,0}$ and $v_{T+1,0}$. For each vertice associated with time slot $t \in [T]_0$ we add an edge to all vertices associated with the subsequent time slot $t + 1$. With each edge from $v_{t,i}$ to $v_{t+1,j}$ we associate the switching cost incurred by the represented action, i.e. $\beta (j - i)^+$, and the hitting cost incurred by the state represented by the vertice $v_{t+1,j}$, i.e. $f_{t+1}(j)$. The structure of this graph is presented in \cref{fig:underlying_graph_of_uni_dimensional_integral_offline_algorithm}.

\begin{figure}
    \centering
    \resizebox{\textwidth}{!}{\input{thesis/figures/graph_1d}}
    \caption{Underlying graph of uni-dimensional integral offline algorithm. The algorithm finds a shortest path from $v_{0,0}$ (red) to $v_{T+1,0}$ (blue).}
    \label{fig:underlying_graph_of_uni_dimensional_integral_offline_algorithm}
\end{figure}

\citeauthor{Albers2018}~\cite{Albers2018} show that an optimal schedule is given by the shortest path from $v_{0,0}$ to $v_{T+1,0}$ within our constructed graph. We observe that our graph follows a particular structure. Each vertice representing an action during time slot $t$ can only be reached by a path that includes precisely one vertice representing time slots $0$ through $t - 1$ and, crucially, whether this path is optimal up to time $t$ does not depend on any time slot past $t$. Bellman's principle of optimality states that any part of an optimal path must itself be optimal~\cite{Bellman1954}. Based on this principle and using our previous observation, we can use dynamic programming to sequentially determine the optimal paths to the vertices of time slot $t$.

Moreover, we observe a second property of the graph of interest. Namely, for each time slot $t \in [T]$ (in the following called columns), the graph has precisely $m$ vertices (in the following called rows), which can only be reached through edges from vertices representing time slot $t - 1$ and all outgoing edges lead to vertices representing time slot $t + 1$. We are, therefore, able to iteratively solve the problem of finding a shortest path for subgraphs of our original graph using binary search. During each iteration, we only consider a constant number of rows.

To simplify the selection of rows, the algorithm assumes $m$ to be a power of two. Instances $\mathcal{I} = (T, m, \beta, F)$ where $m$ is not a power of two can be transformed into an instance $\mathcal{I}' = (T, m', \beta, F')$ with $m' = 2^{\lceil \log_2 m \rceil}$, $F' = (f'_1, \dots f'_T)$, and \begin{align*}
    f'_t(x) = \begin{cases}
        f_t(x) & x \leq m \\
        x (f_t(m) + \epsilon) & \text{otherwise} \\
    \end{cases}
\end{align*} for $\epsilon > 0$. The algorithm using $\log_2 m - 1$ iterations is described in \cref{alg:ud:optimal_graph_search}. During each iteration the algorithm finds the shortest path in a subgraph comprised of only five rows in $\mathcal{O}(T C)$ time. Overall, we thus find an optimal schedule in $\mathcal{O}(T C \log_2 m)$ time. \citeauthor{Albers2018}~\cite{Albers2018} show that in the final iteration, the algorithm obtains an optimal schedule for the original problem instance.

\begin{algorithm}
    \caption{Uni-Dimensional Optimal Graph Search~\cite{Albers2018}}\label{alg:ud:optimal_graph_search}
    \KwIn{$\mathcal{I}_{\text{Int-SSCO}} = (T \in \mathbb{N}, m \in \mathbb{N}, \beta \in \mathbb{R}_{>0}, (f_1, \dots, f_T) \in ([m]_0 \to \mathbb{R}_{\geq 0})^T)$ with $m$ a power of two}
    \eIf{$m > 2$}{$K \gets \log_2 m - 2$ }{$K \gets 0$ }
    $V^K \gets \{v_{0,0}, v_{T+1,0}\} \cup \{v_{t,\xi m / 4} \mid t \in [T], \xi \in [4]_0\}$\;
    $\hat{X}^K \gets \text{\ref{proc:ud:optimal_graph_search:shortest_path}}(\mathcal{I}_{Int-SSCO}, V^K)$\;
    \For{$k \gets K - 1$ \KwTo $0$}{
        $V_t^k \gets \{\hat{X}_t^{k+1} + \xi 2^k \mid \xi \in \{-2, -1, 0, 1, 2\}\} \cap [m]_0$\;
        $V^k \gets \{v_{0,0}, v_{T+1,0}\} \cup \{v_{t,j} \mid t \in [T], j \in V_t^k\}$\;
        $\hat{X}^k \gets \text{\ref{proc:ud:optimal_graph_search:shortest_path}}(\mathcal{I}_{Int-SSCO}, V^k)$\;
    }
    \Return $\hat{X}^0$\;
\end{algorithm}

\begin{function}
	\caption{ShortestPath($\mathcal{I}, V$)}\label{proc:ud:optimal_graph_search:shortest_path}
	\For{$t \gets 1$ \KwTo $T$}{
        \ForEach{$v_{t,j} \in V$}{
            $\hat{c}^{v_{t,j}} \gets \infty$\;
            \ForEach{$v_{t-1,i} \in V$}{
                $c^{v_{t,j}} \gets \hat{c}^{v_{t-1,i}} + f_t(j) + \beta (j - i)^+$\;
                \If{$c^{v_{t,j}} < \hat{c}^{v_{t,j}}$}{
                    $\hat{c}^{v_{t,j}} \gets c^{v_{t,j}}$\;
                    $\hat{X}^{v_{t,j}} \gets \hat{X}^{v_{t-1,i}}$\;
                }
            }
            $\hat{X}_t^{v_{t,j}} \gets j$\;
        }
    }
    $\hat{v} \gets \argmin_{v_{T,j} \in V} \hat{c}^{v_{T,j}}$\;
	\Return $\hat{X}^{\hat{v}}$\;
\end{function}

\section{Multi-Dimensional}

\subsection{Graph-Based Optimal Integral Algorithm}

We now lift the restriction on $d$ and also consider multi-dimensional instances of Int-SSCO. Again, an intuitive approach is to model the offline problem using a graph. Previously, with $d = 1$, the vertices where arranged in a two-dimensional grid (time being the first dimension). We now arrange the vertices in a $(d+1)$-dimensional grid. We call $x = (x_1, \dots, x_d) \in \mathcal{M}$ a \emph{configuration}\index{configuration} (also called a state in the literature) where $M_k := [m_k]_0$ and $\mathcal{M} := M_1 \times \dots \times M_d = \mathcal{X}$ is the set of all configurations. For each configuration $x$ and each time slot $t$ we introduce two vertices. $v_{t,x}^{\uparrow}$ represents the configuration in the beginning of time slot $t$ while $v_{t,x}^{\downarrow}$ represents the configuration at the end of time slot $t$. Thus, the first dimension has $2 T$ \emph{layers} where each layer only consists of powering-up or powering-down vertices.

In our graph we have edges $e_{t,x,k}^{\uparrow}$ representing the powering-up of a server of type $k$ in the beginning of time slot $t$, edges $e_{t,x}^{\text{op}}$ representing operating configuration $x$ during time slot $t$, edges $e_{t,x,k}^{\downarrow}$ representing the powering-down of a server of type $k$ at the end of time slot $t$, and edges $e_{t,x}^{\rightarrow}$ transitioning to the next time slot. For each $k \in [d]$ and $x = (x_1, \dots, x_d) \in [m_1]_0 \times \dots \times [m_k - 1]_0 \times \dots \times [m_d]_0$ let $x' = (x_1, \dots, x_k + 1, \dots, x_d)$. We add an edge $e_{t,x,k}^{\uparrow}$ between $v_{t,x}^{\uparrow}$ and $v_{t,x'}^{\uparrow}$ with weight $\beta_k$ and another edge $e_{t,x,k}^{\downarrow}$ between $v_{t,x'}^{\downarrow}$ and $v_{t,x}^{\downarrow}$ with weight $0$. For each time slot $t \in [T]$ and $x \in \mathcal{M}$, we add the edge $e_{t,x}^{\text{op}}$ from $v_{t,x}^{\uparrow}$ to $v_{t,x}^{\downarrow}$ with weight $f_t(x)$. Lastly, for each $t \in [T-1]$ and $x \in \mathcal{M}$, we add the edge $e_{t,x}^{\rightarrow}$ from $v_{t,x}^{\downarrow}$ to $v_{t+1,x}^{\uparrow}$ with weight $0$.  To simplify the algorithm we add an additional vertice $v_{T+1,\mathbf{0}}^{\uparrow}$ which can be reached through the edge $e_{t,\mathbf{0}}^{\rightarrow}$ from $v_{t,\mathbf{0}}^{\downarrow}$. The structure of this graph is presented in \cref{fig:underlying_graph_of_the_multi_dimensional_integral_offline_algorithm}.

\begin{figure}
    \centering
    \resizebox{\textwidth}{!}{\input{thesis/figures/graph_md}}
    \caption{Underlying graph of the multi-dimensional integral offline algorithm. In this example, $T = 2$, $d = 2$, $m_1 = 2$, and $m_2 = 1$. The algorithm finds a shortest path from $v_{1,\mathbf{0}}^{\uparrow}$ (red) to $v_{2,\mathbf{0}}^{\downarrow}$ (blue). A shortest path corresponding to the optimal schedule $X_1 = (2,0)$ and $X_2 = (1,1)$ is shown in green \cite{Albers2021_2}.}
    \label{fig:underlying_graph_of_the_multi_dimensional_integral_offline_algorithm}
\end{figure}

Any path from $v_{0,\mathbf{0}}^{\uparrow}$ to $v_{T,\mathbf{0}}^{\downarrow}$ must traverse exactly one edge $e_{t,x}^{\text{op}}$ for each time slot $t \in [T]$. The \emph{induced schedule} $X^P$ by a path $P$ assigns each time slot $t$ the configuration $x$ of the traversed edge $e_{t,x}^{\text{op}}$. \citeauthor{Albers2021_2}~\cite{Albers2021_2} show that a shortest path from $v_{0,\mathbf{0}}^{\uparrow}$ to $v_{T,\mathbf{0}}^{\downarrow}$ induces an optimal schedule. They also show that the cost of any induced schedule $X^P$ is given by the cost of the path $P$ when the sub-path between $v_{t,X_t^P}^{\downarrow}$ and $v_{t+1,X_{t+1}^P}^{\uparrow}$ is the shortest sub-path for all $t \in [T-1]$.

Again, we are able to use dynamic programming to obtain a shortest path from $v_{0,\mathbf{0}}^{\uparrow}$ to $v_{T,\mathbf{0}}^{\downarrow}$. Using Bellman's principle of optimality, we conclude that any such shortest path $P$ must consist of shortest sub-paths between the vertices of two subsequent layers. The algorithm works as follows: For each layer of each time slot $t$, we sequentially update the shortest path to each vertice of that layer. In layers consisting of powering-up vertices, we begin with the vertice $v_{t,\mathbf{0}}^{\uparrow}$ and then sequentially increase the values of each dimension beginning with dimension $1$. It is easy to see that by updating the vertices in this order, the predecessors of any newly reached vertice have already been updated. Conversely, in layers consisting of powering-down vertices, we begin with the vertice $v_{t,(m_1,\dots,m_d)}^{\downarrow}$ and iterate the dimensions from dimension $d$ through dimension $1$. The resulting algorithm is described in \cref{alg:md:optimal_graph_search}. We denote by $\hat{X}^v$ the optimal schedule up to vertice $v$ and by $\hat{c}^v$ the cost of the optimal schedule up to vertice $v$.

\begin{algorithm}
    \caption{Multi-Dimensional Optimal Graph Search~\cite{Albers2021_2}}\label{alg:md:optimal_graph_search}
    \KwIn{$\mathcal{I}_{\text{Int-SSCO}} = (d \in \mathbb{N}, T \in \mathbb{N}, m \in \mathbb{N}^d, \beta \in \mathbb{R}_{>0}^d, (f_1, \dots, f_T) \in (\mathcal{M} \to \mathbb{R}_{\geq 0})^T)$}
    \For{$t \gets 1$ \KwTo $T$}{
        $(\hat{X}, \hat{c}) \gets \text{\ref{proc:md:optimal_graph_search:handle_first_layer}}(\mathcal{I}_{Int-SSCO}, \mathcal{M}, \hat{X}, \hat{c}, t, 1, \{\mathbf{0}\})$\;
        $(\hat{X}, \hat{c}) \gets \text{\ref{proc:md:optimal_graph_search:handle_second_layer}}(\mathcal{I}_{Int-SSCO}, \mathcal{M}, \hat{X}, \hat{c}, t, d, \{(m_1,\dots,m_d)\})$\;
    }
    \Return $\hat{X}^{v_{T,\mathbf{0}}^{\downarrow}}$\;
\end{algorithm}

Here, the functions \ref{proc:md:optimal_graph_search:handle_first_layer} and \ref{proc:md:optimal_graph_search:handle_second_layer} update the vertices of the respective layer during time slot $t$. $k$ denotes the dimension that is expanded in the current iteration and $\mathcal{B}$ is the set of configurations from previous iterations the current expansion is based upon. $E \subset V \times \mathbb{R}$ is the set of all predecessors of the vertice $v_{t,x}^{\xi}$ along with the cost of the respective edge.

\begin{function}
	\caption{HandleFirstLayer($\mathcal{I}, \mathcal{M}, \hat{X}, \hat{c}, t, k, \mathcal{B}$)}\label{proc:md:optimal_graph_search:handle_first_layer}
	\lIf{$k > d$}{
	    \Return $(\hat{X}, \hat{c})$
	}
	$\mathcal{B}' \gets \mathcal{B}$\;
	\ForEach{$y \in \mathcal{B}$}{
	    \ForEach{$j \in M_k$}{
	        $x \gets y_{k \gets j}$\;
	        $E \gets \{(v_{t,x_{l \gets P_k(x_l)}}^{\uparrow}, \beta_l (x_l - P_k(x_l))) \mid l \in [k]_0, x_l > 0\}$\;
	        \If{$t > 1$}{$E \gets \{(v_{t-1,x}^{\downarrow}, 0)\} \cup E$\;}
	        $(\hat{X}, \hat{c}) \gets \text{\ref{proc:md:optimal_graph_search:update_paths}}(\hat{X}, \hat{c}, v_{t,x}^{\uparrow}, E)$\;
	        $\mathcal{B}' \gets \mathcal{B}' \cup \{x\}$\;
        }
    }
    \Return $\text{\ref{proc:md:optimal_graph_search:handle_first_layer}}(\mathcal{I}_{Int-SSCO}, \mathcal{M}, \hat{X}, \hat{c}, t, k+1, \mathcal{B}')$\;
\end{function}

\begin{function}
	\caption{HandleSecondLayer($\mathcal{I}, \mathcal{M}, \hat{X}, \hat{c}, t, k, \mathcal{B}$)}\label{proc:md:optimal_graph_search:handle_second_layer}
	\lIf{$k < 1$}{
	    \Return $(\hat{X}, \hat{c})$
	}
	$\mathcal{B}' \gets \mathcal{B}$\;
	\ForEach{$y \in \mathcal{B}$}{
	    \ForEach{$j \in M_k$}{
	        $x \gets y_{k \gets j}$\;
	        $E \gets \{(v_{t,x}^{\uparrow}, f_t(x))\} \cup \{(v_{t,x_{l \gets N_k(x_l)}}^{\downarrow}, 0) \mid l \in [k]_0, x_l < m_l\}$\;
	        $(\hat{X}, \hat{c}) \gets \text{\ref{proc:md:optimal_graph_search:update_paths}}(\hat{X}, \hat{c}, v_{t,x}^{\downarrow}, E)$\;
	        $\mathcal{B}' \gets \mathcal{B}' \cup \{x\}$\;
        }
    }
    \Return $\text{\ref{proc:md:optimal_graph_search:handle_second_layer}}(\mathcal{I}_{Int-SSCO}, \mathcal{M}, \hat{X}, \hat{c}, t, k-1, \mathcal{B}')$\;
\end{function}

$x_{k \gets j}$ denotes the update of configuration $x$ in dimension $k$ to the value $j$. We assume $M_k$ to be in ascending order for the first layer and in descending order for the second layer. $P_k(j)$ and $N_k(j)$ denote the previous and next values to $j$ in $M_k$, respectively. We keep the definitions abstract to allow for the generalization of this algorithm to an approximation algorithm. In the case of the optimal algorithm $P_k(j) = j-1$ and $N_k(j) = j+1$ for all $k \in [d]$. It is easy to verify that during the last iteration $\mathcal{B} = \mathcal{M}$.

\begin{function}
	\caption{UpdatePaths($\hat{X}, \hat{c}, v_{t,x}^{\xi}, E$)}\label{proc:md:optimal_graph_search:update_paths}
	$\hat{c}^{v_{t,x}^{\xi}} \gets \infty$\;
	\ForEach{$(v_{\tau,y}^{\kappa}, c^{v_{\tau,y}^{\kappa}}) \in E$}{
	    $c^{v_{t,x}^{\xi}} \gets \hat{c}^{v_{\tau,y}^{\kappa}} + c^{v_{\tau,y}^{\kappa}}$\;
	    \If{$c^{v_{t,x}^{\xi}} < \hat{c}^{v_{t,x}^{\xi}}$}{
	        $\hat{c}^{v_{t,x}^{\xi}} \gets c^{v_{t,x}^{\xi}}$\;
	        $\hat{X}^{v_{t,x}^{\xi}} \gets \hat{X}^{v_{\tau,y}^{\kappa}}$\;
	        \lIf{$\kappa = {\uparrow} \land \xi = {\downarrow}$}{$\hat{X}_t^{v_{t,x}^{\xi}} \gets x$}
	    }
	}
    \Return $(\hat{X}, \hat{c})$\;
\end{function}

\ref{proc:md:optimal_graph_search:update_paths} determines the shortest path to $v$ through its predecessors $E$ and updates the optimal schedule $\hat{X}^v$ (if necessary) and optimal cost $\hat{c}^v$. \Cref{fig:underlying_graph_of_the_multi_dimensional_integral_offline_algorithm} shows an example for a shortest path in the underlying graph.

\ref{proc:md:optimal_graph_search:update_paths} runs in $\mathcal{O}(|E|)$ time. Due to the structure of the graph, we can follow $|E| \in \mathcal{O}(d)$ and thus \ref{proc:md:optimal_graph_search:handle_first_layer} runs in $\mathcal{O}(|\mathcal{M}| d)$ time while \ref{proc:md:optimal_graph_search:handle_second_layer} runs in $\mathcal{O}(|\mathcal{M}| C d)$ time. Therefore, the overall time complexity of \cref{alg:md:optimal_graph_search} is in $\mathcal{O}(T |\mathcal{M}| C d)$ where $\mathcal{O}(T |\mathcal{M}|)$ is the size of the underlying graph. Note, that this running time is not polynomial in the size of the problem instance which is given by $\mathcal{O}(T + \sum_{k=1}^d \log_2 m_k)$ even when $d$ is assumed a constant as $|\mathcal{M}| \in \mathcal{O}(\prod_{k=1}^d m_k)$. For this reason, \citeauthor{Albers2021_2}~\cite{Albers2021_2} developed an approximation algorithm which we discuss next.

\subsection{Graph-Based Integral Polynomial-Time Approximation Scheme}

\citeauthor{Albers2021_2}~\cite{Albers2021_2} extend the graph-based algorithm from the previous section to a polynomial-time approximation scheme for SBLO. Their algorithm is a generalization of an approximation algorithm that was previously proposed by \citeauthor{Kappelmann2017}~\cite{Kappelmann2017} for the uni-dimensional setting. The idea is to restrict the possible values of $x_{t,k}$. In addition to requiring $x_{t,k} \in [m_k]_0$, we also require $x_{t,k}$ to be a power of some $\gamma > 1$. The possible numbers of active servers of type $k$ are now given as \begin{align*}
    M_k^{\gamma} := &\{0, m_k\} \cup \{\lfloor\gamma^i\rfloor \in [m_k]_0 \mid i \in \mathbb{N}\} \cup \{\lceil\gamma^i\rceil \in [m_k]_0 \mid i \in \mathbb{N}\} \\
                    &\{0, \lfloor\gamma^1\rfloor, \lceil\gamma^1\rceil, \lfloor\gamma^2\rfloor, \lceil\gamma^2\rceil, \dots, m_k\}.
\end{align*} It is easy to see that the ratio between two consecutive values in the ordered set $M_k^{\gamma}$ is not larger than $\gamma$. Also, $|M_k^{\gamma}| \in \mathcal{O}(\log_{\gamma} m_k)$. We define $\mathcal{M}^{\gamma} := M_1^{\gamma} \times \dots \times M_d^{\gamma}$ which results in $|\mathcal{M}^{\gamma}| \in \mathcal{O}(\prod_{k=1}^d \log_{\gamma} m_k)$. \Cref{fig:a_schedule_found_by_the_multi_dimensional_integral_offline_approximation_algorithm} shows an example for a schedule found by the approximation algorithm compared to an optimal schedule.

\begin{figure}
    \centering
    \input{thesis/figures/approx_graph_search_schedule}
    \caption{A comparison of the optimal schedule and a schedule found by the approximation algorithm with $\gamma = 2$. The example uses the Facebook 2009-0 trace under our second model. Note that the approximation algorithm is limited to server configurations that are powers of two.}
    \label{fig:a_schedule_found_by_the_multi_dimensional_integral_offline_approximation_algorithm}
\end{figure}

Let $G^{\gamma}$ be the described graph parametrized by $\gamma > 1$. \citeauthor{Albers2021_2}~\cite{Albers2021_2} show that, assuming we are given an instance of SBLO, given a shortest path $P^{\gamma}$ in $G^{\gamma}$, its induced schedule $X^{P^{\gamma}}$ is a $(2\gamma + 1)$-approximation of the optimal schedule $\hat{x}$. Further, the total number of vertices in $G^{\gamma}$ is \begin{align*}
    \mathcal{O}(T |\mathcal{M}|^{\gamma}) = \mathcal{O}(T \prod_{k=1}^d \log_{1+\epsilon} m_k)
\end{align*} as $|M_k^{\gamma}| \in \mathcal{O}(\log_{\gamma} m_k) = \mathcal{O}(\log_{1 + \epsilon} m_k)$. Using the same graph search algorithm that was described in the previous section we are able to find $X^{P^{\gamma}}$ in $\mathcal{O}(T C d \prod_{k=1}^d \log_{1 + \epsilon} m_k)$ time. Hence, setting $\gamma = 1 + \epsilon / 2$ for some $\epsilon > 0$ yields a $(1+\epsilon)$-approximation. The algorithm is described in \cref{alg:md:approximate_graph_search}.

\begin{algorithm}
    \caption{Multi-Dimensional Approximate Graph Search~\cite{Albers2021_2}}\label{alg:md:approximate_graph_search}
    \KwIn{$\mathcal{I}_{\text{Int-SSCO}} = (d \in \mathbb{N}, T \in \mathbb{N}, m \in \mathbb{N}^d, \beta \in \mathbb{R}_{>0}^d, (f_1, \dots, f_T) \in (\mathcal{M} \to \mathbb{R}_{\geq 0})^T)$}
    \For{$t \gets 1$ \KwTo $T$}{
        $(\hat{X}, \hat{c}) \gets \text{\ref{proc:md:optimal_graph_search:handle_first_layer}}(\mathcal{I}_{Int-SSCO}, \mathcal{M}^{\gamma}, \hat{X}, \hat{c}, t, 1, \{\mathbf{0}\})$\;
        $(\hat{X}, \hat{c}) \gets \text{\ref{proc:md:optimal_graph_search:handle_second_layer}}(\mathcal{I}_{Int-SSCO}, \mathcal{M}^{\gamma}, \hat{X}, \hat{c}, t, d, \{(m_1,\dots,m_d)\})$\;
    }
    \Return $\hat{X}^{v_{T,\mathbf{0}}^{\downarrow}}$\;
\end{algorithm}

One important question regarding the approximation algorithm remains. Namely, how to compute the powers of gamma $\gamma^i$ such that $\lfloor\gamma^i\rfloor \in [m_k]$ or $\lceil\gamma^i\rceil \in [m_k]$ for some $k \in [d]$. The simplest solution is to iteratively increase $i \in \mathbb{N}$ until $\gamma^i$ is greater than $\max_{k \in [d]} m_k$. We then keep track of all $\lfloor\gamma^i\rfloor$ and $\lceil\gamma^i\rceil$ that were generated in this way. We observe that this simple approach takes $\mathcal{O}(\log_{\gamma} m_k)$, not altering the runtime of the algorithm. We have thus discussed a polynomial-time approximation scheme for multi-dimensional instances of Int-SSCO.

\begin{figure}
    \begin{subfigure}[b]{.5\linewidth}
    \resizebox{\textwidth}{!}{\input{thesis/figures/approx_graph_search_cost}}
    \caption{Cost}\label{fig:approx_graph_search:cost}
    \end{subfigure}
    \begin{subfigure}[b]{.5\linewidth}
    \resizebox{\textwidth}{!}{\input{thesis/figures/approx_graph_search_runtime}}
    \caption{Runtime}\label{fig:approx_graph_search:runtime}
    \end{subfigure}
    \caption{Normalized cost and runtime of the approximate graph search algorithm for the Facebook 2009-1 trace.}
\end{figure}

In practice, we observe that cost grows linearly with $\gamma$. The normalized cost when used with the Facebook 2009-1 trace is shown in \cref{fig:approx_graph_search:cost}. In contrast, the most significant decrease in runtime occurs for $\gamma \in (1, 2]$ as shown in \cref{fig:approx_graph_search:runtime}.


\documentclass[a4paper, 12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[american]{babel}
\usepackage[margin=1in]{geometry}
\usepackage{mathtools}
\usepackage{fancyhdr}
\setlength{\headheight}{15.2pt}
\pagestyle{fancy}
\lhead[]{Joseph Petitti}
\rhead[]{Homework 1}
\chead[]{Database Systems II}

\begin{document}

\section*{Problem 1}

\subsection*{Q1}

\[ \text{Disk capacity} = 10 \text{ surfaces} \times 8000 \text{ tracks} \times
		208 \text{ sectors} \times 512 \text{ Bytes}  \]

\[ \text{Disk capacity} = 8519680000 \text{ B} = 8320000 \text{ KB} = 8125
		\text{ MB} = \textbf{7.935 GB} \]

\subsection*{Q2}

\[ 8519680000 \text{ B} \div 8192 \text{ Bytes per block} = \textbf{ 1040000
				blocks} \]

\subsection*{Q3}

\begin{table}[h]
	\centering
	\begin{tabular}{l c c c c c c r}
		& Seek time & & Rotational latency & & Transfer time & &  Total \\

		\hline

		Minimum & 0 ms & + & 0 ms & + & 0.8 ms & = & \textbf{0.8 ms} \\

		Maximum & 17 ms & + & 11.1 ms & + & 0.8 ms & = & \textbf{28.9 ms}  \\

		Average & 9 ms & + & 5.6 ms & + & 0.8 ms & = & \textbf{15.4 ms} \\

	\end{tabular}
\end{table}

\subsection*{Q4}

\begin{itemize}
	\item $ 8192 \text{ Bytes per block} \div 128 \text{ Bytes per record} =
			\textbf{64 records per block}  $
	\item $ 100000 \text{ records} \div 64 \text{ records per block} =
			\textbf{1563 blocks} $
	\item $ 1563 \text{ blocks} \times 16 \text{ sectors per block} =
			\textbf{25008 sectors} $
\end{itemize}

\subsection*{Q5}

\[ 5.6 \text{ ms (initial half rotation)} + 1.2 \text{ ms (seek time)} + 8
		\text{ ms (transfer time)} = \textbf{14.8 ms} \]

\subsection*{Q6}

\[ 208 \text{ sectors per track} \div 16 \text{ sectors per block} = 13 \text{
				blocks per track} \]

\[ 13 \text{ blocks per track} * 10 \text{ surfaces} = \textbf{130 blocks per
				cylinder} \]

\subsection*{Q7}

The most efficient way to store blocks in a file, in order to speed up the
sequential read of that file, is to start with $B_1$, $B_2$, ... $B_{10}$
aligned under each other on all ten surfaces of the innermost cylinder. This
way, once the disk arms are in position the first ten blocks can all be read in
0.8 ms. Then the next ten blocks should be in the next sixteen sectors per
surface in the direction of rotation on the same cylinder. This should continue
until all 130 blocks on the innermost cylinder are filled. Then, the next ten
blocks should be written on the second-to-innermost cylinder approximately 10\%
of the circumference of the disk away from where $B_{130}$ was written. Once the
disk arms are done reading $B_{130}$, they need to move out to the
second-to-innermost track, which takes about 1.002 ms. In this time, the disk
will have rotated by about 9.027\%, so if $B_{131}$ starts about 10\% of the
disk circumference away from $B_{130}$ the disk arms will arrive at the right
track just in time to start reading it.  Continue in the same spiral pattern out
from the center of the disk until $B_{last}$.

The average time to read this file is, in milliseconds:

\[ 14.6 + \frac{0.8 n}{10} + \left ( \left \lfloor{\frac{n}{130}}\right \rfloor
				\times 1.002 \right ) \]

Where $n$ is the number of blocks in the file. The 14.6 ms accounts for initial
5.6 ms of rotational latency and 9 ms of seek time. The time to read each block
is 0.8 ms, multiplied by $n$ divided by 10 (because ten blocks are read at a
time). The final component is the floor of $ \frac{n}{130} $, which is the
number of cylinders necessary to store the file, multiplied by the 1.002 ms it
takes to seek to the next cylinder while reading.

A file with 100,000 records, with each record being 128 bytes, would have 1,563
blocks. This file's average read time would be:

\[ 14.6 + \frac{(0.8 \times 1563)}{10} + \left ( \left
						\lfloor{\frac{1563}{130}}\right \rfloor \times 1.002
		\right ) = \textbf{151.7 ms} \]

\section*{Problem 2}

\begin{table}[h]
	\centering
	\begin{tabular}{ l c | l c }
		\multicolumn{2}{c}{4-byte} &
		\multicolumn{2}{c}{8-byte} \\

		Field & Index & Field & Index \\

		\hline

		Header & 0 & Header & 0\\
		ID & 8 & ID & 8 \\
		Name & 12 & Name & 16 \\
		Age & 40 & Age & 48 \\
		DoB & 44 & DoB & 48 \\
		Gender & 56 & Gender & 72 \\
		Address & 60 & Address & 80 \\
		State & 120 & State & 144
	\end{tabular}
\end{table}

\subsection*{Q1}

Each record would be 128 bytes.

\subsection*{Q2}

Each record would be 152 bytes.

\subsection*{Q3}

\subsubsection*{4-Byte Boundaries}

\[ 4096 \text{ B} = 64 \text{ B} + ( 128 \text{ B} \times n ) \]

\[ n = \textbf{31 records} \]

\subsubsection*{8-Byte Boundaries}

\[ 4096 \text{ B} = 64 \text{ B} + ( 152 \text{ B} \times n ) \]

\[ n = \textbf{26 records} \]

\end{document}