% !TEX root = main.tex

%-------------------------------------------------
\section{PMFs and PDFs}\label{sec:pmfs_pdfs}

\begin{definition}
A random variable is called
\ben
\it \emph{simple} if it takes only finitely many values;
\it \emph{discrete} if it takes only countably many values;
\it \emph{continous} if it takes uncountably many values (and satisfies some other conditions).
\een
\end{definition}
Because finte sets are countable, simple random variables are also discrete random variables.
%-----------------------------
\subsection{Discrete distributions}

Discrete random variables are completely described by their PMFs.
\begin{definition}\label{def:pmf}
The \emph{probability mass function} (PMF) of a discrete random variable $X$ is a function
\[
\begin{array}{rccl}
f:	& \R	& \to 		& [0,1] \\
	& x		& \mapsto 	& \prob (X=x),
\end{array}
\]
with the property that $\sum_{i=1}^{\infty}x_i f(x_i) = 1$, where $\{x_1,x_2,\ldots\}$ is the range of $X$.
\end{definition}

\begin{example}\label{example:coloured_dice_game}
Two fair dice are rolled independently. Each die has two faces coloured red, two coloured blue and two coloured green. Suppose we win \pounds 10 if both dice show the same colour but lose \pounds 5 if they show different colours. Let $X$ be the amount won.
%\begin{blankbox}
\bit
\it The sample space can be expressed as $\Omega=\{RR,RB,RG,BR,BB,BG,GR,GB,GG\}$.
\it The random variable $X:\Omega\to\R$ can then be defined by
\[
X(\omega) = \begin{cases}
	-5	& \text{if $\omega\in\{RB,RG,BR,BG,GR,GB\}$,} \\
	10	& \text{if $\omega\in\{RR,BB,GG\}$.}
\end{cases}
\]
\it The range of $X$ is the set $\{-5,10\}$.
\it The PMF and CDF of $X$ are the functions
\[
f(x) = \begin{cases}
	2/3	& \text{if $x = -5$} \\
	1/3	& \text{if $x = 10$} \\
	0	& \text{otherwise}
\end{cases}
\quad\text{and}\quad
%\]
%\it The CDF of $X$ is the function
%\[
F(x) = \begin{cases}
	0	& \text{if $x < -5$} \\
	2/3	& \text{if $-5 \leq x < 10$} \\
	1	& \text{if $x \geq 10$}
\end{cases}
\quad\text{respectively}.
\]
\eit
%\end{blankbox}
\end{example}

\subsubsection*{Fundamental discrete distributions}
A simple random variable taking all values in its range with equal probability is said to have a (discrete) \emph{uniform} distribution. For example, if $X$ represents the score on a fair die, we say that $X$ is uniformly distributed over the set $\{1,2,3,4,5,6\}$.

The \emph{Bernoulli} distribution is the distribution of an indicator variable. For example, suppose a coin has probability $p$ of landing on heads. If $X$ is the indicator variable of this event we say that $X$ has the $\text{Bernoullii}(p)$ distribution.

Three other fundamental discrete distributions are derived from the following convergent series,
\[
\begin{array}{ll}
\displaystyle\sum_{k=0}^n p^k(1-p)^{n-k} 		= 1  						& \text{(binomial theorem)}, \\
\displaystyle\sum_{k=0}^{\infty} (1-p)^k 		= 1/p \quad\text{for $|p|<1$} 	& \text{(geometric series)}, \\
\displaystyle\sum_{k=0}^{\infty} \lambda^k/k!	= e^{\lambda}	 			& \text{(exponential function)}.
\end{array}
\]
which yield the binomial, geometric, and Poisson distributions respectively.

\begin{table}[h]
\[\begin{array}{lclcl}\hline
\text{Distribution} 			& & \text{PMF}					& & \text{Range}	\\ \hline
X\sim\text{Uniform}(n)			& & 1/n 						& & \{1,2,\ldots,n\}\\
X\sim\text{Bernoulli}(p)		& & p^x(1-p)^{1-x} 				& & \{0,1\}			\\
X\sim\text{Binomial}(n,p)		& & \binom{n}{x}p^x(1-p)^{n-x} 	& & \{0,1,\ldots,n\}\\
X\sim\text{Geometric}(p)		& & (1-p)^{x}p 					& & \{0,1,\ldots\}	\\
X\sim\text{Poisson}(\lambda)	& & \lambda^x e^{-\lambda}/x! 	& & \{0,1,\ldots\} 	\\ \hline
\end{array}\]
\caption{Fundamental discrete distributions\label{tab:basic_discrete}}
\end{table}

\begin{exercise}
For each distribution shown in the Table~\ref{tab:basic_discrete} verify that the expressions given for their PMFs are indeed PMFs.
\end{exercise}

%-----------------------------
\subsection{Continuous distributions}

Consider a random experiment which involves measuring the lifetime of a lightbulb. Let $X$ be the time elapsed between the start of the experiment and the point at which the lightbulb fails. Then $X$ can take any value in the non-negative real numbers $[0,\infty)$, which is an \emph{uncountable} set. The distribution of $X$ cannot therefore be specified by a probability mass function. Subject to a condition on its CDF however, the distribution of $X$ can be specified by a \emph{probability density function}.

\begin{definition}\label{def:cts_rvs}
Let $X$ be a random variable and let $F$ denote its CDF. If there exists an integrable function $f:\R\to [0,\infty)$ such that
\[
F(x) = \int_{-\infty}^x f(t)\,dt \text{\quad for all\quad} x\in\R,
\]
then $X$ is called a \emph{continuous random variable} and $f$ is called its \emph{probability density function} (PDF).
\end{definition}
By the second fundamental theorem of calculus, $f(x) = F'(x)$. Note also that if $X$ is a continuous random variable then $\prob(X=x)=0$ for any $x\in\R$ (this is analagous to saying that the length of a point is zero). The following result is sometimes called the \emph{law of total probability}.
\begin{proposition}
For any PDF,
\[
\displaystyle\int_{-\infty}^{\infty} f(x)\,dx = 1.
\]
\begin{proof}
By Theorem~\ref{thm:props_cdfs},
\[
\int_{-\infty}^{\infty} f(x)\,dx
	= \lim_{x\to\infty}\int_{-\infty}^{x} f(t)\,dt
	= \lim_{x\to\infty}F(x)
	= 1.
\]
\end{proof}
\end{proposition}

%\begin{remark}
%To say that $X$ is a continuous random variable refers to the (absolute) continuity of its CDF, rather than to the continuity (or otherwise) of $X$ as a function on $\Omega$. In fact, the idea of a continuous function on $\Omega$ might not even make sense (because $\Omega$ is just a set and the notion of distance between its elements may not be defined).
%\end{remark}

\subsubsection*{Fundamental continuous distributions}

The fundamental continuous distributions are derived from the following definite inegrals,
\[
\int_0^1\,dx = 1,\qquad \int_0^{\infty} e^{-x}\,dx = 1, \qquad \int_{-\infty}^{\infty} e^{-x^2} = \sqrt{\pi},
\]
which yield the standard uniform, exponential and normal distributions respectively. These standard distributions can be scaled and shifted to yield the parameterized families of distributions shown in Table~\ref{tab:basic_cts}.
\begin{table}[ht]
\[\begin{array}{lclcl}\hline
\text{Distribution} 		& & \text{PDF}											& & \text{Range}	\\ \hline
\text{Uniform}(a,b)			& & 1/(b-a)												& & [a,b]			\\
\text{Exponential}(\lambda)	& & \lambda e^{-\lambda x} 								& & [0,\infty)		\\
\text{Normal}(\mu,\sigma^2)	& & \exp\big[-(x-\mu)^2/2\sigma^2\big]/\sigma\sqrt{2\pi}& & (-\infty,\infty)\\ \hline
\end{array}\]
\caption{The fundamental continuous distributions\label{tab:basic_cts}}
\end{table}

Two other notable continuous distributions are based on the following definite integrals,
\[
B(\alpha,\beta) = \int_0^1 t^{\alpha-1}(1-t)^{\beta-1}\,dt
\qquad\text{and}\qquad
\Gamma(\alpha) = \int_0^{\infty} t^{\alpha-1}e^{-t}\,dt.
\]
These are special functions known the \emph{beta function} and the \emph{gamma function} respectively, and have been widely studied. Unsurprisingly the corresponding distriubtions are known as the beta distribution and the gamma distributions, as shown in Table~\ref{tab:beta_gamma}.
\begin{table}[ht]
\[\begin{array}{lclcl}\hline
\text{Distribution} 		& & \text{PDF}											& & \text{Range}	\\ \hline
\text{Beta}(\alpha,\beta)	& & x^{\alpha-1}(1-x)^{\beta-1}/B(\alpha,\beta)		& & [0,1]			\\
\text{Gamma}(\alpha,\beta)		& & \beta^{\alpha}x^{\alpha-1}e^{-\beta x}/\Gamma(\alpha)& & [0,\infty)		\\ \hline
\end{array}\]
\caption{The beta and gamma distributions\label{tab:beta_gamma}}
\end{table}

\begin{exercise}
For each distribution shown in Tables~\ref{tab:basic_cts} and \ref{tab:beta_gamma} verify that the expressions given for their PDFs are indeed PDFs.
\end{exercise}

\begin{exercise}
\begin{questions}
\question % MA0266
The PDF of a continuous random variable $X$ is given by
\[
f(x) = \left\{\begin{array}{ll}
	cx^2 	& 1\leq x\leq 2,  \\
	0		& \text{otherwise.}
\end{array}\right.
\]
\begin{parts}
\part Find the value of the constant $c$, and sketch the PDF of $X$.
\begin{answer}
 The PDF must integrate to 1:
\[
\int_{-\infty}^{\infty}f(x)\,dx
	= \int_{1}^{2} cx^{2}\,dx
	= \left[\frac{cx^{3}}{3} \right]_{1}^{2}
	= \frac{7c}{3}
	 = 1
\]
so $c=3/7$. (The sketch is a quadratic curve between $x=1$ and $x=2$.)
\end{answer}
\part Show that $\prob(X > 3/2) = 37/56$.
\begin{answer}
\[
\prob(X > 3/2) 	= \int_{3/2}^{2}\frac{3x^{2}}{7}\,dx
			= \left[\frac{x^{3}}{7}\right]_{3/2}^{2}
			= \frac{37}{56}
\]
\end{answer}
\part Find the CDF of $X$.
\begin{answer}
For $1\leq x\leq 2$,
\[
F(x) 	= \int_{-\infty}^{x} f(x)\,dx
		= \int_{1}^{x}\frac{3x^{2}}{7}\,dx
		= \left[ \frac{x^{3} }{7} \right] _{1}^{x}
		= \frac{x^{3}-1}{7}
\]
so the CDF of $X$ is
\[
F(x) = \begin{cases}
	0				& x < 1 \\
	(x^{3}-1)/7		& 1\leq x < 2 \\
	1				& x \geq 2
\end{cases}
\]
\end{answer}
\end{parts}

\question % GS 2.3.5(a)
Consider the function
\[
f(x) = \begin{cases}
	c/x^d	& x > 1, \\
	0		& \text{otherwise.}
\end{cases}
\]
\begin{parts}
\part Why can $f$ be a PDF only when $d>1$?
\begin{answer}
The function $f(x)=c/x^d$ is only integrable when $d>1$. in which case
\[
\int_{-\infty}^\infty f(x)\,dx = \int_1^\infty \frac{c}{x^d}\,dx = \left[\frac{-c}{(d-1)x^{d-1}}\right]_1^{\infty} = \frac{c}{d-1}
\]
\end{answer}
\part If $d>1$, find the value of $c$ and the corresponding CDF.
\begin{answer}
If $d>1$,
\[
\int_{-\infty}^\infty f(x)\,dx = \int_1^\infty \frac{c}{x^d}\,dx = \left[\frac{-c}{(d-1)x^{d-1}}\right]_1^{\infty} = \frac{c}{d-1}
\]
If $f$ is a PDF, we need that $\int_{-\infty}^\infty f(x)\,dx = 1$, so we must have that $c = d-1$. The corresponding CDF is
\[
F(x) = \int_{-\infty}^x f(u)\,du
	= \int_1^\infty \frac{d-1}{u^d}\,du
	= \left[\frac{-1}{x^{d-1}}\right]_1^x
	= 1 - \frac{1}{x^{d-1}}
\]
for $x>1$, and zero otherwise.
\end{answer}
\end{parts}

\end{questions}
\end{exercise}


%% ps1_q1.tex
\section{ Functions in mathematics and Haskell. }
We're tasked with implementation of two base functions in Haskell, $f(x) := x^2$ and $g(x) := x + 1.$
These are pretty straightforward:
\inputminted[firstline=7,
             lastline=11,
             fontsize=\footnotesize, tabsize=4]{haskell}{ps1.hs}
In order to implement the and-then composition, we introduce a helper function, {\tt andThen} for $\fatsemi$:
\inputminted[firstline=13,
             lastline=14,
             fontsize=\footnotesize, tabsize=4]{haskell}{ps1.hs}
Now we can implement both $h = f \circ g$ and $i = f \fatsemi g$:
\inputminted[firstline=16,
             lastline=20,
             fontsize=\footnotesize, tabsize=4]{haskell}{ps1.hs}
and the answers are as follows: $h(2) = 9,\ i(2) = 5.$


\subsection{Forms on real functions}

A form takes two vectors and produces a scalar.

\subsubsection{Integration as a form}

We can use integration to get a bilinear form.

\(\int f(x) g(x) dx\)

If we instead want a sesquilinear form we can instead use:

\(\int \bar {f(x)} g(x) dx\)


\subsection{Example with transformation}

The $2\times 2$ matrix $A$ with property $R_\theta(\tb{v})=A\tb{v}$ rotates the vector by $\theta$.
Using the unit circle to find the coordinates using the basis vectors $\tb{e}_1$ and $\tb{e}_2$:

\[
    R_{\theta}\left(\tb{e}_{1}\right)=\left[\begin{array}{l}
    \cos \theta \\
    \sin \theta
    \end{array}\right]
\]

\[
    R_{\theta}\left(\tb{e}_{2}\right)=\left[\begin{array}{c}
    -\sin \theta \\
    \cos \theta
    \end{array}\right]
\]

This results in $A$:

\[
    \left[\begin{array}{cc}
    \cos \theta & -\sin \theta \\
    \sin \theta & \cos \theta
    \end{array}\right]
\]

Finding the inverse of this is simply rotating back by $\theta$, so finding $R^{-1}_{\theta}$:

\[
    \left[\begin{array}{cc}
    \cos (-\theta) & -\sin (-\theta) \\
    \sin (-\theta) & \cos (-\theta)
    \end{array}\right]
    =
    \left[\begin{array}{cc}
    \cos \theta & \sin \theta \\
    -\sin \theta & \cos \theta
    \end{array}\right]
\]


\title{Distribution of Angle between Two Linked Triangles}
\author{
        Daniel Johnson \\
                Division of Applied Mathematics\\
        Brown University
}
\date{\today}

\documentclass[12pt]{article}

\usepackage{graphicx,amsfonts,amsbsy,bbm, amsmath}
\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%

\begin{document}
\maketitle

\section{One Dimensional Constraint Manifold}
First we consider the case in which one triangle is fixed with the coordinates $(0, 1/2, 0), (0, -1/2, 0), (\sqrt{3}/2, 0, 0)$. The second face will share the vertices $(0, 1/2, 0)$ and $(0, -1/2, 0)$ and its third vertex $v$ is allowed to vary subject to the constraints of being unit distance from the other vertices. The corresponding constraint space can be described by parameterizing $v$ by $\theta$, the dihedral angle between faces.
\begin{align}
v(\theta) &= \left[\sqrt{3}/2\cos\theta, 0, \sqrt{3}/2\sin\theta\right]^T
\end{align}

Diaconis et al. outline a method for sampling uniformly from a manifold $\mathcal{M}$. If the manifold is of $m$ dimensions sitting in an $n$ dimensional ambient space, and a parameterization $f: \mathbbm{R}^m \to \mathbbm{R}^n$ the sampling distribution on the parameters that corresponds to a uniform sampling on $\mathcal{M}$ is given by $h(\omega, \theta, \phi) \propto \left(\det\left[(Df)^TDf\right]\right)^{1/2}$.

In this example, we have the following parameterization.
\begin{align}
f(\theta) &= \Scale[1.0]{\begin{bmatrix}
0 \\ 1/2 \\ 0 \\ 0 \\ -1/2 \\ 0 \\ \sqrt{3}/2 \\ 0 \\ 0 \\\sqrt{3}/2 \cos\theta \\ 0 \\ \sqrt{3}/2\sin\theta
\end{bmatrix}} \\
Df(\theta) &= \Scale[1.0]{\begin{bmatrix}
0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ -\sqrt{3}/2\sin\theta \\ 0 \\ \sqrt{3}/2\cos\theta
\end{bmatrix}}
\end{align}
Thus the sampling distribution on $\theta$ is uniform.
\begin{align}
h(\theta) &\propto \sqrt{\det\left[3/4\right]}\\
&\propto 1
\end{align}

\section{Three Dimensional Constraint Manifold}

Now we let the common edge rotate about the x-axis while its center remains fixed at the origin. More formally, define the point $u = \left[0, \frac{1}{2}\cos\omega, \frac{1}{2}\sin\omega\right]^T$ in the y-z plane. Then, we parameterize the shared edge by $\omega \in [0, 2\pi)$ with its endpoints being $u(\omega)$ and $-u(\omega)$. Then we use $\theta$ and $\phi$ to parameterize the remaining two vertices $v_1$ and $v_2$ as follows.
\begin{align}
v_1 &= \left[\frac{\sqrt{3}}{2}\cos\theta, \frac{\sqrt{3}}{2}\sin\theta\sin\omega, -\frac{\sqrt{3}}{2}\sin\theta\cos\omega\right]^T \\
v_2 &= \left[\frac{\sqrt{3}}{2}\cos(\theta+\phi), \frac{\sqrt{3}}{2}\sin(\theta+\phi)\sin\omega, -\frac{\sqrt{3}}{2}\sin(\theta+\phi)\cos\omega\right]^T
\end{align}
With these parameterizations, it is trivial to verify that the constrains $|u - (-u)| = |v_1 - u| = |v_1 + u| =|v_2 - u| = |v_2 + u| = 1$ are all satisfied for any choice of $(\omega, \theta, \phi)$. Additionally, the dihedral angle between the two triangles is given by $\phi$.

We proceed in deriving the sampling distributions of the 3 parameters that corresponds to uniform sampling of the 3 dimensional constraint manifold embedded in $\mathbbm{R}^{12}$ using the method outlined in Diaconis et al. First we concatenate our parameterizations into a function $f: \mathbbm{R}^3 \to \mathbbm{R}^{12}$ That maps $(\omega, \theta, \phi) \in [0, 2\pi)^3$ onto the constraint manifold.
\begin{align}
f(\omega, \theta, \phi) &= \Scale[1.0]{\begin{bmatrix}
0 \\ \frac{1}{2}\cos\omega \\ \frac{1}{2}\sin\omega \\ 0 \\ -\frac{1}{2}\cos\omega \\ -\frac{1}{2}\sin\omega \\
\frac{\sqrt{3}}{2}\cos\theta \\ \frac{\sqrt{3}}{2}\sin\theta\sin\omega \\ -\frac{\sqrt{3}}{2}\sin\theta\cos\omega  \\
\frac{\sqrt{3}}{2}\cos(\theta+\phi) \\ \frac{\sqrt{3}}{2}\sin(\theta+\phi)\sin\omega \\ -\frac{\sqrt{3}}{2}\sin(\theta+\phi)\cos\omega
\end{bmatrix}} \\
Df(\omega, \theta, \phi) &= \Scale[1.0]{\begin{bmatrix}
0 & 0 & 0\\
-\frac{1}{2}\sin\omega  & 0 & 0 \\
\frac{1}{2}\cos\omega  & 0 & 0 \\
0  & 0 & 0 \\
\frac{1}{2}\sin\omega  & 0 & 0 \\
-\frac{1}{2}\cos\omega  & 0 & 0 \\
0 & -\frac{\sqrt{3}}{2}\sin\theta & 0 \\
\frac{\sqrt{3}}{2}\sin\theta\cos\omega &\frac{\sqrt{3}}{2}\cos\theta\sin\omega & 0 \\
\frac{\sqrt{3}}{2}\sin\theta\sin\omega   & -\frac{\sqrt{3}}{2}\cos\theta\cos\omega & 0 \\
0 & -\frac{\sqrt{3}}{2}\sin(\theta+\phi) & -\frac{\sqrt{3}}{2}\sin(\theta+\phi) \\
\frac{\sqrt{3}}{2}\sin(\theta+\phi)\cos\omega & \frac{\sqrt{3}}{2}\cos(\theta+\phi)\sin\omega & \frac{\sqrt{3}}{2}\cos(\theta+\phi)\sin\omega   \\
\frac{\sqrt{3}}{2}\sin(\theta+\phi)\sin\omega & -\frac{\sqrt{3}}{2}\cos(\theta+\phi)\cos\omega  & -\frac{\sqrt{3}}{2}\cos(\theta+\phi)\cos\omega
\end{bmatrix}} \\
(Df)^TDf &= \Scale[1.0]{\begin{bmatrix}
\frac{1}{2} + \frac{3}{4}\sin^2\theta + \frac{3}{4}\sin^2(\theta + \phi) & 0 & 0 \\
0 & \frac{3}{2} & \frac{3}{4} \\
0 & \frac{3}{4} & \frac{3}{4}
\end{bmatrix}}
\end{align}
Thus the sampling distribution is computed.
\begin{align}
h(\omega, \theta, \phi) &\propto \sqrt{1 + \frac{3}{2}\sin^2\theta + \frac{3}{2}\sin^2(\theta + \phi)}
\end{align}

\section{Four Dimensional Constraint Manifold}

Suppose we relax the constraints of the previous calculation. Fix the midpoint of the shared edge at the origin, but allow it the freedom to rotate in any direction. Then, the endpoints of the shared edge lie at opposite ends of the sphere with radius $1/2$. We use spherical coordinates to parameterize the axis $[-u(\phi,\omega),u(\phi,\omega)]$.
\begin{align}
u(\phi,\omega) &= \left(\frac{1}{2}\cos(\phi),\frac{1}{2}\sin(\phi)\cos(\omega), \frac{1}{2}\sin(\phi)\sin(\omega) \right)
\end{align}
Now we parameterize the remaining two vertices as $v_1 = R(2u, \theta)v_0$ and $v_2 = R(2u, \theta + \xi)v_0$ where $v_0$ is any fixed point satisfying $|v_0 - u| = |v_0 + u| = 1$ and $R(\hat{u},\hat{\theta})$ is the rotation matrix with unit axis of rotation $\hat{u}$ and angle of rotation $\hat{\theta}$.
\begin{align}
v_1 &= R(2u, \theta)v_0 \\
&= \left(\cos\theta I + 4(1-\cos\theta)uu^T + 2\sin\theta[u]_\times\right)v_0 \\
&= \cos\theta v_0 + 4(1-\cos\theta)u(u\cdot v_0) + 2\sin\theta (u\times v_0) \\
&= \cos\theta v_0 + 2\sin\theta (u\times v_0) \\
v_2 &= R(2u, \theta + \xi)v_0 \\
&= \cos(\theta+\xi) v_0 + 2\sin(\theta + \xi) (u\times v_0)
\end{align}

%\begin{align}
%R(2u,\theta) &= \Scale[0.75]{\begin{bmatrix} \cos \theta + 4u_x^2 \left(1-\cos \theta\right) & 4u_x u_y \left(1-\cos \theta\right) - 2u_z \sin \theta & 4u_x u_z \left(1-\cos \theta\right) + 2u_y \sin \theta \\ 4u_y u_x \left(1-\cos \theta\right) + 2u_z \sin \theta & \cos \theta + 4u_y^2\left(1-\cos \theta\right) & 4u_y u_z \left(1-\cos \theta\right) - 2u_x \sin \theta \\ 4u_z u_x \left(1-\cos \theta\right) - 2u_y \sin \theta   & 4u_z u_y \left(1-\cos \theta\right) + 2u_x \sin \theta & \cos \theta + 4u_z^2\left(1-\cos \theta\right)
%\end{bmatrix}} \\
%&= \cos\theta I + 4(1-\cos\theta)uu^T + 2\sin\theta[u]_\times \\
%\end{align}

Thus, we compute as follows.
\begin{align}
  f(\phi, \omega, \theta, \xi) &= \begin{bmatrix} u \\ -u \\ v_1 \\ v_2 \end{bmatrix} \\
  Df(\phi, \omega, \theta, \xi) &= \begin{bmatrix} Du \\ -Du \\ Dv_1 \\ Dv_2 \end{bmatrix} \\
  \left(Df\right)^TDf &=   2\left(Du\right)^TDu  + \left(Dv_1\right)^TDv_1 + \left(Dv_2\right)^TDv_2
\end{align}

\begin{align}
  Du(\phi, \omega, \theta, \xi) &= \begin{bmatrix} -\frac{1}{2}\sin\phi & 0 & 0 & 0 \\ \frac{1}{2}\cos\phi\cos\omega & -\frac{1}{2}\sin\phi\sin\omega & 0 & 0\\  \frac{1}{2}\cos\phi\sin\omega & \frac{1}{2}\sin\phi\cos\omega & 0 & 0\end{bmatrix} \\
  \left(Du\right)^TDu &= \Scale[0.50]{\begin{bmatrix}
\frac{1}{4}\sin^2\phi + \frac{1}{4}\cos^2\phi\cos^2\omega+ \frac{1}{4}\cos^2\phi\sin^2\omega
&  \frac{1}{4}\cos\phi\cos\omega\sin\phi\sin\omega - \frac{1}{4}\cos\phi\cos\omega\sin\phi\sin\omega
& 0 & 0
\\ \frac{1}{4}\cos\phi\cos\omega\sin\phi\sin\omega - \frac{1}{4}\cos\phi\cos\omega\sin\phi\sin\omega
& \frac{1}{4}\sin^2\phi\sin^2\omega + \frac{1}{4}\sin^2\phi\cos^2\omega
& 0 & 0
\\ 0
& 0
& 0 & 0\\ 0
& 0
& 0 & 0 \end{bmatrix}} \\
 &= \Scale[1.00]{\begin{bmatrix}
\frac{1}{4}
& 0
& 0 & 0
\\ 0
& \frac{1}{4}\sin^2\phi
& 0 & 0
\\ 0
& 0
& 0 & 0\\ 0
& 0
& 0 & 0 \end{bmatrix}}
\end{align} \\

\begin{align}
v_1 &= R(2u, \theta)v_0 \\
&= \left(\cos\theta I + 4(1-\cos\theta)uu^T + 2\sin\theta[u]_\times\right)v_0 \\
&= \cos\theta v_0 + 4(1-\cos\theta)u(u\cdot v_0) + 2\sin\theta (u\times v_0) \\
&= \cos\theta v_0 + 2\sin\theta (u\times v_0) \\
v_2 &= R(2u, \theta + \xi)v_0 \\
&= \cos(\theta+\xi) v_0 + 2\sin(\theta + \xi) (u\times v_0)
\end{align}

\begin{align}
\nabla_\phi v_1 &= 2\sin\theta(\nabla_\phi u \times v_0) \\
\nabla_\omega v_1 &= 2\sin\theta(\nabla_\omega u \times v_0) \\
\nabla_\theta v_1 &= -\sin\theta v_0 + 2\cos\theta(u\times v_0) \\
\nabla_\xi v_1 &= 0
\end{align}

\begin{align}
\nabla_\phi v_2 &= 2\sin(\theta+\xi)(\nabla_\phi u \times v_0) \\
\nabla_\omega v_2 &= 2\sin(\theta+\xi)(\nabla_\omega u \times v_0) \\
\nabla_\theta v_2 &= -\sin(\theta+\xi) v_0 + 2\cos(\theta+\xi)(u\times v_0) \\
\nabla_\xi v_2 &= -\sin(\theta+\xi) v_0 + 2\cos(\theta+\xi)(u\times v_0) \\
\end{align}

\begin{align}
Dv_1 &= \Scale[1.00]{\begin{bmatrix}
\nabla_\phi v_1 &
\nabla_\omega v_1 &
\nabla_\theta v_1 &
\nabla_\xi v_1
\end{bmatrix}} \\
 \left(Dv_1\right)^TDv_1 &= \Scale[1.00]{\begin{bmatrix}
 \frac{3}{4}\sin^2\theta & 0 & 0 & 0 \\
 0 & \frac{3}{4}\sin^2\theta \sin^2\omega & 0 & 0\\
 0 & 0 & \frac{3}{4}& 0\\
 0 & 0 & 0 & 0
\end{bmatrix}}
\end{align}

\begin{align}
 \left(Dv_2\right)^TDv_2 &= \Scale[1.00]{\begin{bmatrix}
 \frac{3}{4}\sin^2(\theta+\xi) & 0 & 0 & 0 \\
 0 & \frac{3}{4}\sin^2(\theta+\xi) \sin^2\omega & 0 & 0\\
 0 & 0 & \frac{3}{4} & \frac{3}{4}\\
 0 & 0 & \frac{3}{4} & \frac{3}{4}
\end{bmatrix}}
\end{align}

\begin{align}
 \left(Df\right)^TDf &= \Scale[0.70]{\begin{bmatrix}
 \frac{3}{4}\sin^2\theta + \frac{3}{4}\sin^2(\theta+\xi) + \frac{1}{2} & 0 & 0 & 0 \\
 0 & \frac{3}{4}\sin^2\theta \sin^2\omega + \frac{3}{4}\sin^2(\theta+\xi) \sin^2\omega + \frac{1}{2}\sin^2\phi & 0 & 0\\
 0 & 0 & \frac{3}{2} & \frac{3}{4}\\
 0 & 0 & \frac{3}{4} & \frac{3}{4}
\end{bmatrix}}
\end{align}

\begin{align}
h(\phi, \omega, \theta, \xi) &\propto \sqrt{\det\left(\left(Df\right)^TDf\right)} \\
&\propto \sqrt{\left( \frac{3}{4}\sin^2\theta + \frac{3}{4}\sin^2(\theta+\xi) + \frac{1}{2} \right)\left(\frac{3}{4}\sin^2\theta \sin^2\omega + \frac{3}{4}\sin^2(\theta+\xi) \sin^2\omega + \frac{1}{2}\sin^2\phi\right)} \\
&\propto \sqrt{\left(3\sin^2\theta + 3\sin^2(\theta+\xi) + 2\right)\left(3\sin^2\theta \sin^2\omega + 3\sin^2(\theta+\xi) \sin^2\omega + 2\sin^2\phi\right)}
\end{align}

\end{document}

\begin{align}
Dv(\phi, \omega, \theta, \xi) &= \Scale[1.0]{\begin{bmatrix}
\frac{\partial R}{\partial\phi}v_0 & \frac{\partial R}{\partial\omega}v_0 & \frac{\partial R}{\partial\theta}v_0
\end{bmatrix}} \\
\left(Dv\right)^TDv &= \Scale[1.0]{\begin{bmatrix}
(v_0)^T(\frac{\partial R}{\partial\phi})^T\frac{\partial R}{\partial\phi}v_0 & (v_0)^T(\frac{\partial R}{\partial\phi})^T\frac{\partial R}{\partial\omega}v_0 & (v_0)^T(\frac{\partial R}{\partial\phi})^T\frac{\partial R}{\partial\theta}v_0 \\
(v_0)^T(\frac{\partial R}{\partial\omega})^T\frac{\partial R}{\partial\phi}v_0 & (v_0)^T(\frac{\partial R}{\partial\omega})^T\frac{\partial R}{\partial\omega}v_0 & (v_0)^T(\frac{\partial R}{\partial\omega})^T\frac{\partial R}{\partial\theta}v_0 \\
    (v_0)^T(\frac{\partial R}{\partial\theta})^T\frac{\partial R}{\partial\phi}v_0 & (v_0)^T(\frac{\partial R}{\partial\theta})^T\frac{\partial R}{\partial\omega}v_0 & (v_0)^T(\frac{\partial R}{\partial\theta})^T\frac{\partial R}{\partial\theta}v_0
\end{bmatrix}}
\end{align}

\begin{align}
  R &= \cos\theta I + 4(1-\cos\theta)uu^T + 2\sin\theta[u]_\times \\
  \frac{\partial R}{\partial\phi} &= 4(1-\cos\theta)(u\frac{\partial u^T}{\partial\phi} + \frac{\partial u}{\partial\phi}u^T) + 2\sin\theta\frac{\partial [u]_\times}{\partial\phi} \\
  \frac{\partial R}{\partial\omega} &= 4(1-\cos\theta)(u\frac{\partial u^T}{\partial\omega} + \frac{\partial u}{\partial\omega}u^T) + 2\sin\theta\frac{\partial [u]_\times}{\partial\omega}  \\
  \frac{\partial R}{\partial\theta} &= -\sin\theta I + 4\sin\theta uu^T + 2\cos\theta[u]_\times \\
\end{align}

\begin{align}
\frac{\partial u}{\partial\phi}u^T &= \frac{1}{4}\Scale[1.0]{\begin{bmatrix}
-\cos\phi\sin\phi & \cos^2\phi\cos\omega & \cos^2\phi\sin\omega \\
-\sin^2\phi\cos\omega & \sin\phi\cos\phi\cos^2\omega & \sin\phi\cos\phi\sin\omega\cos\omega \\
-\sin^2\phi\sin\omega & \sin\phi\cos\phi\sin\omega\cos\omega  & \sin\phi\cos\phi\sin^2\omega
\end{bmatrix}} \\
u\frac{\partial u^T}{\partial\phi} + \frac{\partial u}{\partial\phi}u^T &= \frac{1}{4}\Scale[1.0]{\begin{bmatrix}
-\sin 2\phi & \cos 2\phi \cos\omega & \cos 2\phi\sin\omega \\
\cos 2\phi\omega & \sin 2\phi\cos^2\omega & \sin 2\phi\sin 2\omega \\
\cos 2\phi\sin\omega & \sin 2\phi\sin 2\omega & \sin 2\phi\sin^2\omega
\end{bmatrix}}
\end{align}

\begin{align}
\frac{\partial u}{\partial\omega}u^T &= \frac{1}{4}\Scale[1.0]{\begin{bmatrix}
0 & -\sin\phi\cos\phi\sin\omega & \sin\phi\cos\phi\cos\omega \\
0 & -\sin^2\phi\sin\omega\cos\omega & \sin^2\phi\cos^2\omega \\
0 & -\sin^2\phi\sin^2\omega & \sin^2\phi\sin\omega\cos\omega
\end{bmatrix}} \\
u\frac{\partial u^T}{\partial\omega} + \frac{\partial u}{\partial\omega}u^T &= \frac{1}{4}\Scale[1.0]{\begin{bmatrix}
0 & -\sin\phi\cos\phi\sin\omega & \sin\phi\cos\phi\cos\omega \\
-\sin\phi\cos\phi\sin\omega & -\sin^2\phi\sin 2\omega & \sin^2\phi\cos 2\omega \\
\sin\phi\cos\phi\cos\omega & \sin^2\phi\cos 2\omega & \sin^2\phi\sin 2\omega
\end{bmatrix}}
\end{align}

\begin{align}
uu^T &= \frac{1}{4}\Scale[1.0]{\begin{bmatrix}
\cos^2\phi & \sin\phi\cos\phi\cos\omega & \sin\phi\cos\phi\sin\omega \\
\sin\phi\cos\phi\cos\omega & \sin^2\phi\cos^2\omega & \sin^2\phi\sin\omega\cos\omega \\
\sin\phi\cos\phi\sin\omega & \sin^2\phi\sin\omega\cos\omega & \sin^2\phi\sin^2\omega
\end{bmatrix}}
\end{align}

\begin{align}
[u]_\times &= \frac{1}{2}\Scale[1.0]{\begin{bmatrix}
0 & -\sin\phi\sin\omega & \sin\phi\cos\omega \\
\sin\phi\sin\omega & 0 & -\cos\phi \\
-\sin\phi\cos\omega & \cos\phi & 0
\end{bmatrix}}
\end{align}

\begin{align}
\frac{\partial[u]_\times}{\partial\phi} &= \frac{1}{2}\Scale[1.0]{\begin{bmatrix}
0 & -\cos\phi\sin\omega & \cos\phi\cos\omega \\
\cos\phi\sin\omega & 0 & \sin\phi \\
-\cos\phi\cos\omega & -\sin\phi & 0
\end{bmatrix}}
\end{align}

\begin{align}
\frac{\partial[u]_\times}{\partial\omega} &= \frac{1}{2}\Scale[1.0]{\begin{bmatrix}
0 & -\sin\phi\cos\omega & -\sin\phi\sin\omega \\
\sin\phi\cos\omega & 0 & 0 \\
\sin\phi\sin\omega & 0 & 0
\end{bmatrix}}
\end{align}

\begin{align}
[u]^T_\times[u]_\times &= \frac{1}{4}\Scale[1.0]{\begin{bmatrix}
\sin^2\phi & -\sin\phi\cos\phi\cos\omega & -\sin\phi\cos\phi\sin\omega \\
-\sin\phi\cos\phi\cos\omega & \sin^2\phi\sin^2\omega + \cos^2\phi & -\sin^2\phi\sin\omega\cos\omega\\
-\sin\phi\cos\phi\sin\omega & -\sin^2\phi\sin\omega\cos\omega & \sin^2\phi\cos^2\phi + \cos^2\omega
\end{bmatrix}}
\end{align}

\begin{align}
(\frac{\partial R}{\partial\theta})^T\frac{\partial R}{\partial\theta} &=  (-\sin\theta I + 4\sin\theta uu^T + 2\cos\theta[u]_\times)^T(-\sin\theta I + 4\sin\theta uu^T + 2\cos\theta[u]_\times) \\
%  &=  \sin^2\theta I - 4\sin^2\theta uu^T - 2\sin\theta\cos\theta[u]_\times - 4\sin^2\theta uu^T + 16\sin^2uu^Tuu^T+ 8\sin\theta\cos\theta uu^T\theta[u]_\times - 2\sin\theta\cos\theta[u]_\times^T + 8\sin\theta\cos\theta \theta[u]_\times^T uu^T  + 4\cos^2 \theta[u]_\times^T\theta[u]_\times
  &=  \sin^2\theta I - 8\sin^2\theta uu^T  + 16\sin^2\theta uu^Tuu^T  + 4\cos^2 \theta[u]_\times^T\theta[u]_\times  \\
  &=  \sin^2\theta I - 8\sin^2\theta uu^T  + 4\sin^2\theta uu^T  + 4\cos^2 \theta[u]_\times^T\theta[u]_\times  \\
  &=  \sin^2\theta I - 4\sin^2\theta uu^T  + 4\cos^2 \theta[u]_\times^T\theta[u]_\times
\end{align}

%\begin{align}
%\frac{\partial R}{\partial\phi} &= \Scale[0.60]{\begin{bmatrix}
%8u_x\frac{\partial u_x}{\partial\phi} \left(1-\cos \theta\right)
%& 4(u_x\frac{\partial u_y}{\partial\phi} +  u_y\frac{\partial u_x}{\partial\phi}) \left(1-\cos \theta\right) - 2\frac{\partial u_z}{\partial\phi} \sin \theta
%& 4(u_x\frac{\partial u_z}{\partial\phi} +  u_z\frac{\partial u_x}{\partial\phi}) \left(1-\cos \theta\right) + 2\frac{\partial u_y}{\partial\phi} \sin \theta
%\\ 4(u_x\frac{\partial u_y}{\partial\phi} +  u_y\frac{\partial u_x}{\partial\phi}) \left(1-\cos \theta\right) + 2\frac{\partial u_z}{\partial\phi} \sin \theta
%& 8u_y\frac{\partial u_y}{\partial\phi} \left(1-\cos \theta\right)
%& 4(u_y\frac{\partial u_z}{\partial\phi} +  u_z\frac{\partial u_y}{\partial\phi}) \left(1-\cos \theta\right) - 2\frac{\partial u_x}{\partial\phi} \sin \theta
%\\ 4(u_x\frac{\partial u_z}{\partial\phi} +  u_z\frac{\partial u_x}{\partial\phi}) \left(1-\cos \theta\right) - 2\frac{\partial u_y}{\partial\phi} \sin \theta
%& 4(u_y\frac{\partial u_z}{\partial\phi} +  u_z\frac{\partial u_y}{\partial\phi}) \left(1-\cos \theta\right) + 2\frac{\partial u_x}{\partial\phi} \sin \theta
%& 8u_z\frac{\partial u_z}{\partial\phi} \left(1-\cos \theta\right) \end{bmatrix}} \\
%\frac{\partial R}{\partial\omega} &= \Scale[0.60]{\begin{bmatrix}
%8u_x\frac{\partial u_x}{\partial\omega} \left(1-\cos \theta\right)
%& 4(u_x\frac{\partial u_y}{\partial\omega} +  u_y\frac{\partial u_x}{\partial\omega}) \left(1-\cos \theta\right) - 2\frac{\partial u_z}{\partial\omega} \sin \theta
%& 4(u_x\frac{\partial u_z}{\partial\omega} +  u_z\frac{\partial u_x}{\partial\omega}) \left(1-\cos \theta\right) + 2\frac{\partial u_y}{\partial\omega} \sin \theta
%\\ 4(u_x\frac{\partial u_y}{\partial\omega} +  u_y\frac{\partial u_x}{\partial\omega}) \left(1-\cos \theta\right) + 2\frac{\partial u_z}{\partial\omega} \sin \theta
%& 8u_y\frac{\partial u_y}{\partial\omega} \left(1-\cos \theta\right)
%& 4(u_y\frac{\partial u_z}{\partial\omega} +  u_z\frac{\partial u_y}{\partial\omega}) \left(1-\cos \theta\right) - 2\frac{\partial u_x}{\partial\omega} \sin \theta
%\\ 4(u_x\frac{\partial u_z}{\partial\omega} +  u_z\frac{\partial u_x}{\partial\omega}) \left(1-\cos \theta\right) - 2\frac{\partial u_y}{\partial\omega} \sin \theta
%& 4(u_y\frac{\partial u_z}{\partial\omega} +  u_z\frac{\partial u_y}{\partial\omega}) \left(1-\cos \theta\right) + 2\frac{\partial u_x}{\partial\omega} \sin \theta
%& 8u_z\frac{\partial u_z}{\partial\omega} \left(1-\cos \theta\right) \end{bmatrix}} \\
%\frac{\partial R}{\partial\theta} &= \Scale[0.75]{\begin{bmatrix}
%-\sin \theta + 4u_x^2 \sin \theta
%& 4u_x u_y \sin \theta - 2u_z \cos \theta
%& 4u_x u_z \sin \theta + 2u_y \cos \theta
%\\ 4u_y u_x \sin \theta + 2u_z \cos \theta
%& -\sin \theta + 4u_y^2\sin \theta
%& 4u_y u_z \sin \theta - 2u_x \cos \theta
%\\ 4u_z u_x \sin \theta - 2u_y \cos \theta
%& 4u_z u_y \sin \theta + 2u_x \cos \theta
%& -\sin \theta + 4u_z^2\sin \theta
%\end{bmatrix}}
%\end{align}

\end{document}


\section{Evaluating a decision tree}
In addition to the standard metrics, such as classification accuracy, we
evaluate decision trees as follows. Every element of the data set is
fed into the decision tree, thereby
assigning each one to a leaf. Now, for each leaf, we have four numbers.
\be
\item \(n^H_1, n^T_1\) which is the number of testing samples assigned
to the leaf that were labeled heads and tails respectively. The ``weight'' of a
leaf is \(n^H_1 + n^T_1\)
\item \(n^H_0, n^T_0\) same as above but for the training samples
\ee

These numbers are used follows. Continuing our gambling metaphor,
the house is given only \(n^H_0, n^T_0\) to set the odds, whereas the gambler
has access to all four.
The ``true'' probability of heads, \(\rho\), is assumed to be
\(\frac{n^H_1}{n^H_1+ n^T_1}\).

Consider three examples, in all of which \(n^H_0, n^T_0 = 60, 40\).
The benefit, \(b\) that the gambler can expect to make per trial varies
depending on \(rho\) as follows.
\be
\item \(\rho = 0.8\). The adversary would bet heads.
\(b = 0.8 \times \frac{40}{60} + 0.2 \times -1 = \frac{1}{3}\)
\item \(\rho = 0.6\). If the adversary bet heads,
\(b = 0.6 \times \frac{40}{60} + 0.4 \times -1 = 0\)
If the adversary bet tails,
\(b = 0.6 \times -1 + 0.4 \times \frac{60}{40} = 0\).
\item \(\rho = 0.4\). The adversary would bet tails.
\(b = 0.4 \times -1 + 0.6 \times \frac{60}{40} = \frac{1}{2}\)
\ee

The weighted benefit of a leaf is simply \(w \times b\).
The ``cost'' of the decision tree is sum over the
weighted benefit, normalized by the weights of all leaves
\(= \frac{\sum_l w_l \times b_l}{\sum_l w_l}\)


\subsection{Submanifolds}

Submanifold: subset of manifold which is also manifold

Eg: circle inside a sphere


\documentclass{article}
\usepackage{amsmath, amssymb, amsfonts, amsthm}
\usepackage{bm}
\usepackage{color}
\newcommand{\pd}[2]{\frac{\partial{#1}}{\partial{#2}}}

\numberwithin{equation}{section}
\let\vec\bm

\theoremstyle{plain}
\newtheorem{thm}{Theorem}
\numberwithin{thm}{section}

\theoremstyle{plain}
\newtheorem{prop}{Proposition}
\numberwithin{prop}{section}

\theoremstyle{definition}
\newtheorem{defn}{Definition}
\numberwithin{defn}{section}

\theoremstyle{remark}
\newtheorem*{rem}{Remark}

\newtheorem*{cor}{Corollary}

\title{Hamiltonian Mechanics - A Quick Recapitulation}
\author{Amey Joshi}
\date{06-Mar-2021}
\begin{document}

\maketitle
\abstract{This article summarises the main ideas of Hamiltonian mechanics and
illustrates them with a few examples.}

\section{The Hamiltonian function}\label{s1}
Consider a system of $n$ degrees of freedom described by the generalised
coordinates $q_1, \ldots, q_n$ and a Lagrangian function $L(q_i, \dot{q}_i, t)$.
The generalised momentum is defined as
\begin{equation}\label{s1e1}
p_i = \frac{\partial{L}}{\partial\dot{q}_i}.
\end{equation}
The Legendre-Fenchel transformation of a function $f:X \rightarrow
\mathbf{R}$, where $X \subset \mathbf{R}^n$ is defined as
\begin{equation}\label{s1e2}
f^\ast(x^\ast) = \sup_{x \in X}\left((x^\ast, x) - f(x)\right),
\end{equation}
for all $x^\ast \in X^\ast$. The set $X^\ast$ is
\begin{equation}\label{s1e3}
X^\ast = \left\{x^\ast \in \mathbf{R}^n : \sup_{x \in X}
         \left((x^\ast, x) - f(x)\right) < \infty\right\}.
\end{equation}
The expression $(x^\ast, x)$ is the dot product of $x^\ast$ and $x$. Let us
assume that the function $f$ is differentiable and let us define
\begin{equation}\label{s1e4}
F(x, x^\ast) = (x^\ast, x) - f(x).
\end{equation}
Then,
\[
\frac{\partial F}{\partial x_i} = x^\ast_i - \frac{\partial f}{\partial x_i}
\]
so that the supremum of the set $(x^\ast, x) - f(x)$ is indeed the maximum
of the function $F$. In this case, the Legendre-Fenchel transform becomes
\begin{equation}\label{s1e5}
f^\ast(x^\ast) = \left((x^\ast, D_x(f)) - f(x)\right).
\end{equation}
The symbol $D_x(f)$ stands for the gradient of $f$ with respect to $x$.

The Lagrangian $L(q_i, \dot{q}_i, t)$ is assumed to be a differentiable
throughout its domain so that its Legendre-Fenchel transformation with respect
to the variables $\dot{q}_i^\ast$ is
\begin{equation}\label{s1e6}
L^\ast(q_i, \dot{q}_i^\ast, t) = \sum_{i=1}^n \dot{q}_i^\ast \dot{q}_i -
L(q_i, \dot{q}_i^\ast, t),
\end{equation}
where
\begin{equation}\label{s1e7}
\dot{q}_i^\ast = \frac{\partial L}{\partial\dot{q}_i}.
\end{equation}
The right hand side is defined, in equation \eqref{s1e1}, to be the generalised
momeumtum $p_i$. Therefore, equation \eqref{s1e6} is written as
\begin{equation}\label{s1e8}
L^\ast(q_i, p_i, t) = \sum_{i=1}^n p_i\dot{q}_i - L(q_i, \dot{q}_i, t).
\end{equation}
The function $L^\ast$ is called the Hamiltonian of the system and is denoted
by $H$.

Why did we not define the function $H$ as
\begin{equation}\label{s1e9}
H(q_i, p_i, t) = \sum_{i=1}^n p_i\dot{q}_i - L(q_i, \dot{q}_i, t)?
\end{equation}
Written in this manner, the right hand side is a function of $q_i, \dot{q}_i,
p_i$ and $t$. However, the supremum over $x$ in equation \eqref{s1e2} ensures
that the result is function of $x^\ast$ alone. The differentiability of $L$
results in the simple form of $L^\ast$, (or $H$), and we are also guaranteed
that this latter function does not depend on $\dot{q}_i$
\cite{touchette2005legendre}.

From equation \eqref{s1e9} we have
\begin{eqnarray}
\frac{\partial{H}}{\partial q_i} &=&
  -\frac{\partial L}{\partial q_i} \label{s1e10} \\
\frac{\partial{H}}{\partial p_i} &=& \dot{q}_i \label{s1e11}.
\end{eqnarray}
Since the Lagrangian $L$ satisfies the Euler-Lagrange equation
\begin{equation}\label{s1e12}
\frac{\partial L}{\partial q_i} = \frac{d}{dt}
\frac{\partial L}{\partial\dot{q}_i} = \dot{p}_i,
\end{equation}
the pair of equations \eqref{s1e10} and \eqref{s1e11} become
\begin{eqnarray}
\frac{\partial{H}}{\partial q_i} &=& -\dot{p}_i \label{s1e13} \\
\frac{\partial{H}}{\partial p_i} &=& \dot{q}_i. \label{s1e14}
\end{eqnarray}
These are Hamilton's canonical equations.

\section{The physical significance of the Hamiltonian function}\label{s2}
Let us assume that our system can also be described using $N$ cartesian
coordinates
\begin{equation}\label{s2e1}
x_i = x_i(q_1, \ldots, q_n), i = 1, \ldots, N.
\end{equation}
We can then write
\begin{equation}\label{s2e2}
\dot{x}_i = \sum_{j=1}^n\frac{\partial x_i}{\partial q_j}\dot{q}_j.
\end{equation}
If $m_i$ is the mass associated with the coordinate $x_i$ then its kinetic
energy is
\begin{equation}\label{s2e3}
T = \frac{1}{2}\sum_{i=1}^N m_i\dot{x}_i^2 =
\sum_{j,k=1}^n \alpha_{j,k}\dot{q}_j\dot{q}_k,
\end{equation}
where
\begin{equation}\label{s2e4}
\alpha_{j, k} = \sum_{i=1}^N m_i\frac{\partial x_i}{\partial q_j}
\frac{\partial x_i}{\partial q_k}
\end{equation}
is a function of $q_j, q_k$ alone.
\begin{prop}\label{s2p1}
$T$ is a homogeneous function of the generalised velocities.
\end{prop}
\begin{proof}
\[
T(q_1, \ldots, q_n, \lambda\dot{q}_1, \ldots, \lambda\dot{q}_n) =
\lambda^2 T(q_1, \ldots, q_n, \dot{q}_1, \ldots, \dot{q}_n).
\]
\end{proof}
By Euler's theorem on homogeneous functions,
\begin{equation}\label{s2e5}
\sum_{i=1}^n \dot{q}_i\frac{\partial T}{\partial\dot{q}_i} = 2T.
\end{equation}
\begin{prop}\label{s2p2}
If the potential energy of the system is independent of the generalised
velocities and time then
\[
\sum_{i=1}^n \dot{q}_ip_i = 2T.
\]
\end{prop}
\begin{proof}
We can write the Lagrangian as
\[
L(q_i, \dot{q}_i) = T(q_i, \dot{q}_i) - V(q_i)
\]
so that
\[
\frac{\partial L}{\partial\dot{q}_i} = \frac{\partial T}{\partial\dot{q}_i}.
\]
The proposition follows from the above equation and \eqref{s1e1}.
\end{proof}
\begin{rem}
The Lagrangian of a point mass descending in a column of viscous fluid is
\begin{equation}\label{s2e6}
L = \exp\left(\frac{\gamma t}{m}\right)\left(\frac{m\dot{x}^2}{2} - U(x)\right),
\end{equation}
which is not of the form $T - V$.

The Lagrangian of a particle of charge $q$ and mass $m$ in an electromagnetic
field is
\begin{equation}\label{s2e7}
L = \frac{1}{2}mv^2 + q\vec{A}\cdot\vec{v} - q\phi,
\end{equation}
where $\vec{A}$ and $\phi$ are the vector and scalar potentials of the fields.
Neither is this function a difference of the kinetic energy $mv^2/2$ and
the potential energy $q\phi$.
\end{rem}

\begin{prop}\label{s2p3}
If the potential energy of the system is independent of the generalised
velocities and time then $H = T + V$.
\end{prop}
\begin{proof}
The Lagrangian can be written as $L(q_i, \dot{q}_i) = T(q_i, \dot{q}_i)
- V(q_i)$. The proposition follows from this form of the Lagrangian, the
definition \eqref{s1e9} of the Hamiltonian and proposition \ref{s2p2}.
\end{proof}

\begin{prop}\label{s2p4}
If the Lagrangian is independent of time then the Hamiltonian is a constant
of motion.
\end{prop}
\begin{proof}
\[
\frac{dH}{dt} = \sum_{i=1}^n\dot{p}_i\dot{q}_i + \sum_{i=1}^np_i\ddot{q}_i
- \sum_{i=1}^n\frac{\partial L}{\partial q_i}\dot{q}_i
- \sum_{i=1}^n\frac{\partial L}{\partial\dot{q}_i}\ddot{q}_i = 0.
\]
\end{proof}

From propositions \ref{s2p3} and \ref{s2p4} it follows that
\begin{thm}\label{s2t1}
If a system can be described the Lagarangian of the form
\[
L(q_i, \dot{q}_i) = T(q_i, \dot{q}_i) - V(q_i)
\]
then the Hamiltonian of the system is the total energy of the system and it
is a constant.
\end{thm}

\section{The phase space}\label{s3}
A system with $n$ degrees of freedom can be described by $n$ generalised
coordinates $q_1, \ldots, q_n$. Its behaviour can be described either by the
Lagrangian $L(q_i, \dot{q}_i, t)$ or the Hamiltonian $H(q_i, p_i, t)$. In
the former case, the system can be represented as a point in a
$n+1$-dimensional configuration space whose coordinates as $q_1, \ldots, q_n, t$
or a $2n+1$-dimensional phase space whose coordinates are $q_1, \ldots, q_n,
p_1, \ldots, p_n, t$.

The motion of the system appears as a curve in either the configuration space
or the phase space. The benefit of the phase space is that the curves
representing the motion of the system do not cross each other. For if they did
then at the point of intersection the system will have two possible ways of
evolution.

Consider an ensemble of systems represented by the \emph{same} Hamiltonian.
Each of these is represented by a point in the phase space. If $\rho$ is the
number density of the systems then it satisfies the equation of continuity,
\begin{equation}\label{s3e1}
\frac{\partial\rho}{\partial t} +
\sum_{j=1}^n\frac{\partial(\rho\dot{q}_j)}{\partial q_j} +
\sum_{j=1}^n\frac{\partial(\rho\dot{p}_j)}{\partial p_j} = 0
\end{equation}
analogous to the equation of continuity of a fluid of density $\rho_m$ and
moving with a velocity $\vec{v}$,
\begin{equation}\label{s3e2}
\frac{\partial\rho_m}{\partial t} + \nabla\cdot(\rho_m\vec{v}) = 0.
\end{equation}
Equation \eqref{s3e1} can be written as
\begin{equation}\label{s3e3}
\frac{\partial\rho}{\partial t} +
\sum_{j=1}^n\frac{\partial\rho}{\partial q_j} \dot{q}_j +
\sum_{j=1}^n\frac{\partial\rho}{\partial p_j} \dot{p}_j +
\rho\left(\sum_{j=1}^n\frac{\partial\dot{q}_j}{\partial q_j} +
\sum_{j=1}^n\frac{\partial\dot{p}_j}{\partial p_j}\right)  = 0
\end{equation}
The last term vanishes because of Hamilton's equations \eqref{s1e13} and
\eqref{s1e14} while the first three terms can be combined as the total
time derivative of $\rho$ giving us
\begin{equation}\label{s3e4}
\frac{d\rho}{dt} = 0.
\end{equation}
Thus, the ensemble of systems all described by the same Hamiltonian moves in the
phase space like an incompressible fluid.

\section{Canonical transformation}\label{s4}
Consider the transformations
\begin{eqnarray}
q^\ast_i &=& q^\ast_i(q_1, \ldots, q_n, p_1, \ldots, p_n) \label{s4e1} \\
p^\ast_i &=& p^\ast_i(q_1, \ldots, q_n, p_1, \ldots, p_n) \label{s4e2}
\end{eqnarray}
for all $i = 1, \ldots, n$, $n$ being the number of degrees of freedom of the
system. The form of the Hamiltonian is may not remain the same as a result of
these transformations. However, $H(q_i, p_i, t) \mapsto H^\ast(q^\ast_i,
p^\ast_i, t)$ and if
\begin{eqnarray}
\frac{\partial H^\ast}{\partial q^\ast_i} &=& -\dot{p}^\ast_i \label{s4e3} \\
\frac{\partial H^\ast}{\partial p^\ast_i} &=&  \dot{q}^\ast_i \label{s4e4}
\end{eqnarray}
then the transformations \eqref{s4e1} and \eqref{s4e2} are called \emph{
canonical transformations}. Canonically transformed variables obey canonical
equations of motions.

The simplest canonical transformations are the point transformations
\begin{eqnarray}
q^\ast_i &=& q^\ast_i(q_1, \ldots, q_n, t)\label{s4e5} \\
p^\ast_i &=& \frac{\partial L}{\partial \dot{q}^\ast_i} \label{s4e6}
\end{eqnarray}
The next simplest canonical transformation are
\begin{eqnarray}
q^\ast_i &=& p_i \label{s4e7} \\
p^\ast_i &=& q_i \label{s4e8}
\end{eqnarray}

The system can as well be described by the two Lagrangians
\begin{eqnarray}
L(q_i, \dot{q}_i, t) &=& \sum_{i=1}^n p_i\dot{q}_i - H(q_i, p_i, t)
\label{s4e9} \\
L^\ast(q^\ast_i, \dot{q}^\ast_i, t) &=& \sum_{i=1}^n p^\ast_i\dot{q}^\ast_i -
H(q^\ast_i, p^\ast_i, t) \label{s4e10}
\end{eqnarray}
each one of which satisfies the action principle. That is
\begin{eqnarray}
\delta\int_{t_1}^{t_2} L(q_i, \dot{q}_i, t)dt &=& 0 \label{s4e11} \\
\delta\int_{t_1}^{t_2} L^\ast(q^\ast_i, \dot{q}^\ast_i, t)dt &=& 0 \label{s4e12}
\end{eqnarray}
From equations \eqref{s4e11} and \eqref{s4e12} we infer that the two
Lagrangians are related as
\begin{equation}\label{s4e13}
L(q_i, \dot{q}_i, t) = L^\ast(q^\ast_i, \dot{q}^\ast_i, t) + \frac{dF}{dt},
\end{equation}
for some function $F$. Equivalently, we can write
\begin{equation}\label{s4e14}
\sum_{i=1}^n p_i\dot{q}_i - H(q_i, p_i, t) =
\sum_{i=1}^n p^\ast_i\dot{q}^\ast_i - H^\ast(q^\ast_i, p^\ast_i, t) +
\frac{dF}{dt}.
\end{equation}
On rearranging and writing it in terms or differentials,
\begin{equation}\label{s4e15}
\sum_{i=1}^n(p_i dq_i - p^\ast_i dq^\ast_i) = H^\ast dt - Hdt + dF.
\end{equation}

The function $F$ in \eqref{s4e14} is called the \emph{generating function}. One
might think that it depends on all $4n$ variables $q_i, p_i, q_i^\ast, p_i^\ast$
. However, there are $2n$ equations relating the two. Therefore, only half of
them are independent. Therefore, we choose it to depend on one `old' and one
`new' coordinate. Thus, the four possibilities are
\begin{eqnarray}
F = F(q_i, q_i^\ast) \label{s4e16} \\
F = F(q_i, p_i^\ast) \label{s4e17} \\
F = F(p_i, q_i^\ast) \label{s4e18} \\
F = F(p_i, p_i^\ast) \label{s4e19}
\end{eqnarray}
Assume that $F$ is of the form \eqref{s4e17} in equation \eqref{s4e15} to get
\begin{equation}\label{s4e20}
\sum_{i=1}^np_idq_i - Hdt = \sum_{i=1}^np^\ast_idq^\ast_i - H^\ast dt +
dF(q_i, p_i^\ast).
\end{equation}
Rearrange it as
\[
\sum_{i=1}^n(p_idq_i + q_i^\ast dp^\ast_i) + (H^\ast - H)dt =
d\left(\sum_{i=1}^n p_i^\ast q_i^\ast\right) + dF(q_i, p_i^\ast)
\]
Let
\begin{equation}\label{s4e21}
S = \sum_{i=1}^n p_i^\ast q_i + F
\end{equation}
then we have
\begin{equation}\label{s4e22}
\sum_{i=1}^n(p_idq_i + q_i^\ast dp^\ast_i) + (H^\ast - H)dt = dS.
\end{equation}
The left hand side suggest that $S$ can be considered to be a function of
$q_i, p_i^\ast, t$ and
\begin{eqnarray}
p_i &=& \pd{S}{q_i} \label{s4e23} \\
q_i^\ast &=& \pd{S}{p_i^\ast} \label{s4e24} \\
H^\ast - H &=& \pd{S}{t} \label{s4e25}
\end{eqnarray}
If we can find a transformation that can lead to $H^\ast = 0$, we get
\begin{equation}\label{s4e26}
\pd{S}{t} + H\left(q_i, p_i, t\right) = 0
\end{equation}
or, using equation \eqref{s4e23}
\begin{equation}\label{s4e27}
\pd{S}{t} + H\left(q_i, \pd{S}{q_i}, t\right) = 0.
\end{equation}
This is Hamilton-Jacobi equation.

Before we proceed for a more detailed consideration of the Hamilton-Jacobi
equation we will remark on why canonical transformations are interesting. If
we are able to find $q_i^\ast$ such that $H^\ast$ does not depend on any one
of them then all the conjugate momenta $p_i^\ast$ are constant because
\begin{equation}\label{s4e28}
p_i^\ast = \pd{H^\ast}{q_i^\ast} = 0.
\end{equation}
If we call the constant momenta
\begin{equation}\label{s4e29}
p_i^\ast = \beta_i
\end{equation}
then
\begin{equation}\label{s4e30}
q_i^\ast = \pd{H^\ast}{p_i^\ast} = \pd{H^\ast}{\beta_i} = \alpha_i,
\end{equation}
another constant. As a result,
\begin{equation}\label{s4e31}
q_i^\ast(t) = \alpha_i t + q_i^\ast(0).
\end{equation}

\section{Hamilton-Jacobi equation}\label{s5}
The Hamilton-Jacobi equation is a first order partial differential equation
in the unknown $S$ considered to be a real-valued function of $n+1$ variables
$q_1, \ldots, q_n$ and $t$. However, we had assumed $S$ to be a function of
$2n + 1$ variables $q_1, \ldots, q_n, p_1^\ast, \ldots, p_n^\ast$ and $t$.
We reconcile these facts by noting that the solution of \eqref{s4e27} will
have $n + 1$ constants of which one is additive while the rest are not. We
ignore the additive constant and express the solution as $S(q_1, \ldots, q_n,
\beta_1, \ldots, \beta_n, t)$. Thus,
\begin{equation}\label{s5e1}
p_i^\ast = \beta_i.
\end{equation}
Therefore, from equations \eqref{s4e23} and \eqref{s4e24} we get
\begin{eqnarray}
p_i &=& \pd{S}{q_i} \label{s5e2} \\
q_i^\ast &=& \pd{S}{\beta_i} \label{s5e3}
\end{eqnarray}
Since $H^\ast = 0$, $q_i^\ast$ and $p_i^\ast$ are both constants. Let us set
\begin{equation}\label{s5e4}
q_i^\ast = \gamma_i,
\end{equation}
so that $q_i$ can be evaluated in terms of the constants $\beta_i, \gamma_i$
and $t$. We will illustrate the use of Hamilton-Jacobi equation with an example.

\subsection{Simple harmonic oscillator}
The Hamiltonian of this conservative system is
\begin{equation}\label{s5e5}
H = \frac{p^2}{2m} + \frac{kq^2}{2},
\end{equation}
where $m$ is mass of the oscillator and $k$ is the spring constant. The
Hamilton-Jacobi equation is
\begin{equation}\label{s5e6}
\pd{S}{t} + H\left(q, \pd{S}{q}\right) = 0.
\end{equation}
Note that the Hamiltonian of a harmonic oscillator is independent of $t$.
Let us assume $S$ to be of the form $S(q, t) = S_1(q) + F(t)$. (Recall that
in the Hamilton-Jacobi equation $S$ is assumed to be a function of the $n+1$
variables $q_1, \ldots, q_n$ and $t$.) We thus have
\[
\pd{F}{t} = -H\left(q, \pd{S}{q}\right).
\]
The left hand side depends only on $t$ and the right hand side only on $q$,
each side can be equated to a constant $-E$, the total energy of the system.
Thus,
\begin{equation}\label{s5e7}
F = -\beta t
\end{equation}
where we ignore the additive constant. Now consider
\begin{equation}\label{s5e8}
H\left(p, \pd{S_1}{q}\right) = \beta.
\end{equation}
Use the form of Hamiltonian in equation \eqref{s5e5} to get
\begin{equation}\label{s5e9}
\frac{1}{2m}\left(\pd{S_1}{q}\right)^2 + \frac{kq^2}{2} = \beta.
\end{equation}
The solution of this equation is
\begin{equation}\label{s5e10}
S_1(q) = \int\sqrt{2m\beta - kmq^2}dq
\end{equation}
The function $S(q, t)$ is thus,
\begin{equation}\label{s5e11}
S(q, t) = \int\sqrt{2m\beta - kmq^2}dq - \beta t.
\end{equation}
Now,
\begin{equation}\label{s5e12}
q^\ast = \pd{S}{\beta} = m\int\frac{dq}{\sqrt{2m\beta - kmq^2}} - t.
\end{equation}
But $q^\ast$ is another constant, say $\gamma/\omega$, where
\begin{equation}\label{s5e13}
\omega^2 = \frac{k}{m}
\end{equation}
so that
\[
m\int\frac{dq}{\sqrt{2m\beta - kmq^2}} = \frac{\gamma}{\omega} + t.
\]
The integral can be readily evaluated to get
\begin{equation}\label{s5e14}
q = \sqrt{\frac{2\beta}{k}}\sin(\omega t + \gamma).
\end{equation}

\section{Action-angle variables}\label{s6}
If a conservative system is periodic then we define an `action variable' as
\begin{equation}\label{s6e1}
J_i = \oint p_idq_i.
\end{equation}
The time independent Hamilton-Jacobi equation is
\begin{equation}\label{s6e2}
H\left(q_i, \pd{S}{q_i}\right) = E.
\end{equation}
We can write the solution of this equation as
\begin{equation}\label{s6e3}
S(q_1, \ldots, q_n, \beta_1, \ldots, \beta_n) =
\sum_{i=1}^n S_i(q_i, \beta_1, \ldots, \beta_n).
\end{equation}
Now,
\begin{equation}\label{s6e4}
J_i = \oint p_i dq_i = \oint \pd{S}{q_i}dq_i = \oint \frac{dS_i}{dq_i}dq_i.
\end{equation}
From \eqref{s6e3} and \eqref{s6e4} it is clear that $J_i$ are a function of
$\beta_1, \ldots, \beta_n$. Thus,
\begin{equation}\label{s6e5}
J_i = J_i(\beta_1, \ldots, \beta_n)
\end{equation}
which can be inverted so that
\begin{equation}\label{s6e6}
\alpha_i = \alpha_i(J_1, \ldots, J_n).
\end{equation}
We can then write equation \eqref{s6e3} as
\begin{equation}\label{s6e7}
S = S(q_1, \ldots, q_n, J_1, \ldots, J_n).
\end{equation}
Equations \eqref{s5e2} and \eqref{s5e3} now become
\begin{eqnarray}
p_i &=& \pd{S}{q_i} \label{s6e8} \\
q_i^\ast &=& \pd{S}{J_i} \label{s6e9}
\end{eqnarray}
From equation \eqref{s4e25}
\begin{equation}\label{s6e10}
H^\ast = H = E(J_1, \ldots, J_n).
\end{equation}
Now,
\begin{equation}\label{s6e11}
\dot{p}_i^\ast = -\pd{H^\ast}{q_i^\ast} = 0
\end{equation}
but
\begin{equation}\label{s6e12}
\dot{q}_i^\ast = \pd{H^\ast}{p_i^\ast} = \pd{H^\ast}{J_i}
\end{equation}
because we regard $\beta_i$, or equivalently $J_i$, as $p_i^\ast$. From
\eqref{s6e10},
\begin{equation}\label{s6e13}
\dot{q}_i^\ast = \pd{E}{J_i} = \nu_i,
\end{equation}
a constant, from which we readily get
\begin{equation}\label{s6e14}
q_i^\ast = \nu_i t + \alpha_i,
\end{equation}
$\alpha_i$ being a constant of integration. Traditionally, $q_i^\ast$ are
denoted by $\omega_i$ so that equation \eqref{s6e15} becomes
\begin{equation}\label{s6e15}
\omega_i = \nu_i t + \alpha_i.
\end{equation}
$\omega_i$ are called the angle variables corresponding to $J_i$, the action
variables.

\bibliographystyle{plain}
\bibliography{hm}
\end{document}


\chapter{Background}\label{chap:background}
The following work is based on the book Reinforcement Learning:
An Introduction\cite{Sutton1998} from Richard S. Sutton and Andrew G. Barto
\section{Markov Decision Processes}
The Markov Decision Process (MPD)  is the mathematical framework of Reinforcement Learning and
is defined as a tuple < $\mathcal{S, A, R, T, }$ >
\begin{itemize}
\item $\mathcal{S}$ is a number of states, s $\in \mathcal{R}^{n}$
\item $\mathcal{A}$ is a of actions, a $ \in \mathcal{R}^{n}$
\item $\mathcal{T}$ is the transition probability function
\item $\mathcal{R}$ is the reward
\end{itemize}

Every state in a Markov Decision Process needs satisfy the Markov Property.
This means that "The future is independent of the past given the present".
The definition is given by an State Reward pair as

\begin{equation}
\mathcal{P}(S_{t+1}, R_{t+1}) | S_{t}, R_{t}) =  \mathcal{P}(S_{t+1}, R_{t+1}) | S_{t+1}, R_{t+1}, S_{t+1}, R_{t+1})
\end{equation}

Unfortunately for most real-world problem this assumption is violated. This is also the case for the
state transition function, which is definite as

\begin{equation}
  \mathcal{P}(S_{t+1}| R_{t+1}) | s_{t}, a_{t}) =  \mathcal{P}(S_{t+1}| S_{t} = s ,  A_{t} = a)
\end{equation}

The Reward is a function of state action pairs
\begin{equation}
  \mathcal{P}(S_{t+1}| R_{t+1}) | s_{t}, a_{t}) =  \mathcal{P}(S_{t+1}| S_{t} = s ,  A_{t} = a)
\end{equation}

The goal of the agent is to find the policy that maximizes the total reward.
This policy is a function that maps states to actions in the deterministic case.
While a stochastic policy has a certain probability to choose an action in a state.
For any MDP there is always at least one optimal policy.
In case the transition probability is given, the dynamic programming-based Value Iteration  Algorithm is one way to compute this policy.
Which is build upon the concept of a Value Function.

\subsection{Value Function}
The value function $V^{\pi}$ : $\mathcal{S}$ $\rightarrow$ $\mathcal{R}$, represents expeceted total reward of a policy in a given state and following the policy
It is defined as follows,

\begin{equation}
  \begin{aligned}
    V^{\pi}(s) &= \mathbb{E}_{\pi} [R_t | s_t = s] \\
    &= \mathbb{E}_{\pi} [\sum^{\infty}_{k=0} \gamma^{k} r_{t+k+1} | s_t = s] \label{MDP:eq1} \\
    &= \sum_{a \in \mathcal{A}} \pi(s, a) \sum_{s' \in \mathcal{S}} \mathcal{T}^{a}_{ss'}[\mathcal{R}^{a}_{ss'} + \gamma V^\pi(s')]
  \end{aligned}
\end{equation}

One way to find the optimal policy is the value Iteration Algorithm.
In each Iteration the value function is updated by the following equation,

\begin{equation}
  V_{i+1}(s) := \max_a \Big\{ \sum_{s', r} P(s',r| s,a) (r + \gamma V_i(s')) \Big\}
\end{equation}

\subsection{Q Function}

In many real-world problems, the transition function is unknown, and approximate the Value function is not feasible, because
it would require evaluating all possible actions in a single state every time step.
In this case the Q-value function helps by using the state action pair

\begin{equation}
  Q(s_t, a_t) \leftarrow Q(s_t, a_t) + \alpha[r_{t+1} + \gamma \max_a Q(s_{t+1}, a) - Q(s_t, a_t)]
\end{equation}

This update equation is used to find an optimal policy in the Q-Learning Algorithm, repesened in Algorithm \ref{alg:q-learning}

\input{figures/background/Q-learning.tex}

The fact that the policy for interacting with the environment is different from the one to update the Q-value Function makes it to an off-policy Algorithm

\section{Neural Network}

In complex environments, the state space is continuous, which makes it infeasible to use to store all state-action pairs in a table.
Advances in machine learning especially in deep learning make it possible to approximate this Q function.
A basic element of Deep learning is artificial neural networks which are inspired by the human brain.
Neural network have a structure of input layer connected to hidden layers followed by the output layer.
A standard Network has linear many hidden layers represented as nodes. The nodes between different layers are connected by weights.
The values of the weights can be trained iteratively by using an optimization  technique like stochastic gradient descent and backpropagation.
This simple architecture could be seen as matrix multiplications which makes it a linear function.
By adding nonlinear activation functions it is able to approximate more complex nonlinear functions.

\begin{figure}[h]
  \centering
  \includegraphics[width=0.5\textwidth]{figures/background/nn.png}
  \caption{Deep Neural Network with several hidden layers}
  \label{fig:tab-training}
\end{figure}


\section{Methodology}

\subsection{Echo State Networks}
An ``echo state network'' (also
called a ``liquid state machine'' \cite{lukosevicius_practical_2012}) is a type
of recurrent neural network that uses a single layer of many neurons called a
``reservoir''. The reservoir has an adjacency matrix $\bm{A}$ that is
\begin{enumerate}
	\item sparsely populated
	\item connected by uniformly random weights centered at zero
	\item has a large number of neurons
\end{enumerate}
A reservoir computer also satisfies the \textit{echo state property}
\cite{pathak_model-free_2018, lukosevicius_reservoir_2009}. This
property ensures that a system's state has a decaying influence on future states
(like an echo of sound or ripples on water). This property is satisfied in most
cases when the spectral radius (the absolute value of the greatest eigenvalue of
$\bm{A}$)\cite{lukosevicius_reservoir_2009} is,
\begin{align}
	\rho(\bm{A}) < 1.
\end{align}
However, the echo state property can still be satisfied for a spectral radius
greater than unity \cite{lukosevicius_practical_2012}.

\begin{figure}[H]
	\includegraphics[width=\columnwidth]{reservoir_network.jpg}
	\caption{A basic reservoir computer or echo state network. The connections in
	the reservoir are given by $\bm{A}$}
	\label{fig:RCmodel}
\end{figure}

Figure \ref{fig:RCmodel} gives a visual representation of a basic
\acrshort{ESN}. An
input vector of length \textit{K} is mapped to the reservoir layer by an input
weight matrix $\bm{W_{in}}$. The state of the reservoir is mapped to an output
layer of length \textit{N} with an output weight matrix $\bm{W_{out}}$. An ESN
does not require $K=N$, nor does it require $K \neq N$. In this
work, the input vector is a function of time, $\bm{u}(t)$, and the output
vector is the next state of the system, $\bm{u}_p(t+\Delta t)$. Ideally, the
difference between the prediction, $\bm{u}_p$, and the actual, $\bm{u}_a$, is
minimized. During training, the output weight matrix is trained through
backpropagation using a loss function like cross entropy
\cite{pathak_model-free_2018, vlachas_backpropagation_2020}.

\subsection{Hyperparameter Search}
Due to the architecture of \acrshort{ESN}s, the weights and connections
inside the reservoir do not need to be trained and, in our choice of
implementation, cannot be. This dramatically reduces the training time because
only the linear output layer needs to be trained. One drawback of this approach
is its sensitivity to hyperparameters, which must be carefully chosen before
running the network \cite{ pathak_model-free_2018,
lukosevicius_practical_2012, lukosevicius_reservoir_2009,gallicchio_deep_2019}.
Here, we perform grid searches
to establish which combination of hyperparameters minimizes the mean squared
error of the model,
\begin{align}
	MSE &= \frac{1}{N}\sum_i^N (\hat{y} - y_i)^2\\
	\intertext{where}
	\hat{y} &= \mbox{the average value of the ouput.}\nonumber
\end{align}

\subsection{Model Prediction}
The weights of the output layer, $\bm{W_{out}}$, are
trained through backpropagation by minimizing the error. When a trained model
is given some initial state and then makes a prediction, $\bm{u}_p(t+\Delta
t)$, this prediction becomes the initial state for the next prediction and so
on. Even a good model, like in Pathak et. al \cite{pathak_model-free_2018}, has
some propagating error that deteriorates the prediction fidelity.


\input{preamble.tex}
\title{String Quantization}

\begin{document}
\maketitle

\section{Discrete phonons}

Suppose we have a chain of masses m, each linked by a string of length a.
Each mass can be displaced about the equilibrium position vertically, by an amount
\(x_n\).

Then we have the following equations of motion:

\[m \ddot{x_n} = k \left(x_{n+1} + x_{n-1}\right) - 2 k x_n\]

We can work in the fourier basis, which decouples the motion of the masses into modes of vibrations labelled
by the wavenumber \(q \in (-\frac{\pi}{2}, \frac{\pi}{2})\):

\begin{align}
    & x_q = e^{i(qan-\omega(q) t)}\\
    & \omega_q^2 = -2k/m \cos(qa)- 2k/m
\end{align}

\subsection{Lagrangian and Hamiltonian Style}

It is nice to work in the Lagrangian and Hamiltonian scheme in preparation for quantization.
Let's set up a finite string of N masses, each mass m, separated by distance l in equilibrium.
The displacement of the ith mass is \(\phi_i\).

The Hamiltonian is KE +PE:

\begin{align}
    & H = \frac12 \sum_{i = 0}^{N-1} ( m(\dot{\phi_i}^2) + k (\phi_i- \phi_{i-1})^2) \\
    & \frac12 \sum_{i = 0}^{N-1} l \left( \frac{m}{l} \dot{\phi_i}^2 + k l^2 (\phi_i - \phi_{i-1}/l)^2 \right)
\end{align}

The lagrangian is:

\begin{align}
    & L = \frac12 \sum_{i = 0}^{N-1} ( m(\dot{\phi_i}^2) - k (\phi_i- \phi_{i-1})^2) \\
    & \frac12 \sum_{i = 0}^{N-1} \left(l \frac{m}{l} \dot{\phi_i}^2 - k l^2 (\phi_i - \phi_{i-1}/l)^2 \right))
\end{align}

In the limit N goes to infinity, l to 0 , we can define the ratio: \(l/m = \mu\), \(kl = T\).
The lagrangian density, \(\mathcal{L} = L/l\):

\begin{align}
    & \mathcal{L} = \int dx  \frac12 \left(\mu \dot{\phi}^2 - T \pd{\phi}{x}^2 \right)
\end{align}

The principle of least action guarantees that the variation of the action is 0:

\newcommand{\La}{\mathcal L}
\newcommand{\Ha}{\mathcal H}

\begin{align}
    &\delta \int d^4 x \mathcal{L}(\phi, \partial_{x^\mu}{\phi}) = 0 \\
    \arr & \int d^4 x \pd{\La}{\phi} \delta \phi + \pd{\La}{(\partial_\mu \phi)} \delta \partial_\mu(\phi) \\
    \arr & \int d^4 (\pd{\La}{\phi} \delta - \partial_\mu \pd{\La}{(\partial_\mu \phi)}) \delta \phi
    + \partial_\mu \left(\pd{\La}{(\partial_\mu \phi)} \delta \phi \right)
\end{align}

The last term is the 4-divergence, which can be converted to the difference between the spatial integrals
at the initial and final times, and therefore vanishes.

We therefore have the condition:

\begin{align}
    \partial_\mu \pd{\La}{(\partial_\mu \phi)} - \pd{\La}{\phi} = 0
\end{align}

Applying equation (11) to the string, we obtain the famous string equation:

\begin{align}
    \pdd{\phi}{x}-\frac{1}{v^2}\pdd{\phi}{t} = 0
\end{align}
where \(v^2 = \frac{T}{\mu}\)

\subsection{Classical Source Term}

\subsection{Canonical Momenta}

We can compute the following canonical momenta:

\begin{align}
    & \pd{L}{\dot{\phi}} = \mu \dot{\phi} - T \partial_x \phi v \\
    & \pd{L}{\partial_x \phi} = \frac{\mu}{v} \dot{\phi} - T \partial_x \phi
\end{align}

We see the canonical momenta is associated with the momentum of the transverse motion of the wave,
i.e. the larger \(\dot{\phi}\) is, the larger the canonical momentum.

\paragraph{Some redefinition}: for convenience purposes, we redefine the field \(\phi \arr \sqrt{T} \phi\),
so that T disappears from the equations. The field will have different units

\section{Decoupling the String into independent Oscillators}

\subsection{Normal Coordinates}

As with any wave equation, canonical quantization lends itself more nicely in a fourier basis.  We make the following guess:

\begin{align}
    & \phi_n = \frac{1}{\sqrt{L}} e^{i(k_n x- \omega_n t)}
\end{align}

Where we choose
\begin{itemize}
    \item \(\omega_n >0\)
    \item \(k_n = 2n \pi/L\) with \(n \in I\)(periodic Boundary Conditions)
    \item \(\omega_n^2 = v^2 k_n^2\) (Wave Equation)
\end{itemize}

We note that there are both positive and negative \(\omega and k_n\) solutions.
By Plancherel's theorem, the general solution can be written as follows.

\begin{align}
    & \phi(x,t)= \sum_{n= -\infty}^{\infty} c_n(a_n \phi_n + a_n* \phi_n*)
    & \phi(x,t)= \sum_{n = -\infty}^{\infty} c_n(a_n(t)e^{ik_n x} + a_n(t)* e^{-ik_n x})
\end{align}
Where \(a_n(t)= a(0)e^{-i \omega_n t}\)
We have indeed successfully decoupled the string into independent oscillators, since the coefficient \(a(t)\) satisfy:
\[\ddot{a_n}+ \omega_n^2 a_n = 0\]

The complex conjugate is there to ensure real solutions for the field.

We also have the following orthogonality identities:

\begin{align}:
    &\int_0^L \phi_n \phi_m = \delta_{n,-m} e^{-2i\omega_n t} \\
    &\int_0^L \phi_n* \phi_m = \delta_{n,m}
\end{align}

\subsection{Hamiltonian}

The new kinetic energy, potential energy and Hamitonian are:

\begin{align}
    & T = \frac{1}{2v^2} \int dx \dot{\phi}^2 \\
    & U = \frac{1}{2} \int dx \pd{\phi}{x}^2 \\
    & H = T + U = \sum_{-\infty}^{\infty} c_n^2(\frac{\omega^2}{v^2} + k_n^2) a_n^2(t) + c_n c_{-n} (k_n^2 - \frac{\omega_n^2}{v^2})Re(a_n a_{-n}) \\
\end{align}

Using the \(c_{-n} = -c_n\), we can rewrite:

\begin{align}
    & H = \sum_n 2 c_n^2 \frac{\omega_n^2}{v^2} a_n(t) a_n(t)*
\end{align}

We work in natural units, where \(h = c = 1\).
We can make a dimensionless by defining \(c_n = \sqrt{\frac{v^2}{2 \omega_n}}\).
THe hamiltonian takes the form of:
\[H = \sum_n \omega_n a_n a*_n\]

Remarks:

\begin{itemize}
    \item The number a and a* have a lot of similarity to raising and lowering operators
    \item To make real a real dynamical variable, we can define \(q_n = \frac{1}{\sqrt{2 \omega_n}}(a_n + a_n*)\)
    \item We can then define \(p_n = \ud{q}{t} = - i (\frac{\omega_n}{2})^{1/2} (a_n - a_n*)\)
    \item The hamiltonian takes the form: \(H = \frac12 \sum_n (p_n^2 + \omega_n^2 q_n^2)\)
    \item Re-expressing \(q_n = \sqrt{2\omega_n} q_n + i \sqrt{\frac{2}{\omega_n}} p_n\)
    \item \(p_n = \sqrt{2\omega_n} q_n - i \sqrt{\frac{2}{\omega_n}} p_n\)
\end{itemize}

\section{Canonical Quantization}

We are now ready to quantize the string.  The canonical commutation relations are:

\begin{align}
    & [q_n, q_m] = [p_m, p_n] = 0 \\
    & [q_n, p_m] = i \hbar \delta_{nm}
\end{align}

Those commutation relations immediately imply commutation relations for the raising & lowering operators:

\[
     [a_n, a_m *]= \delta_{mn}
     \]

\end{document}


\section{Notation}
Throghout this paper we assume that we are working in a three-dimensional
euclidian space. We shall use $P_1, P_2, \ldots$ to denote polytopes with
points in $\mathbb{R}^3$, and $\point{p_1}, \point{p_2}, \ldots$ to denote
points in $\mathbb{R}^3$, where in particular $\point{0} = (0, 0, 0)$.
For a $\point{p_i}$ we indicate its three components with $(p_{i_x}, p_{i_y}, p_{i_z})$.


\section{Partition function}

Theories with an action can be quantized using a path integral.
The partition function in Euclidean signature is defined as
% \footnote{
% Wick rotation analytically continues time to imaginary (Euclidean) time, $t\rightarrow -i t_E$,
% then the oscillatory exponential becomes decaying. }
% the same as the canonical partition function in statistical mechanics. }
\begin{equation}
 Z = \int D\phi \, e^{-S[\phi]},
\end{equation}
which is an infinite-dimensional integral,
over all possible field configurations (represented by the measure $D\phi$) on all of spacetime.

For $\mathcal{N}=2^*$ on $S^4$ and its limiting cases $\mathcal{N}=4$ (massless hypermultiplet) and pure $\mathcal{N}=2$ (infinitely-heavy hypermultiplet that is integrated out),
there is one localization locus.
It is the moduli space of Coulomb vacua,
parametrized by the vacuum expectation value of a scalar of the vector multiplet:
\begin{equation}\label{vevScalar}
 \braket{\Phi_0} = \text{diag}(a_1, \ldots, a_N),
\end{equation}
where $a_i$ are real numbers.
The Coulomb phase of the theory
is a consequence of the spontaneous symmetry breaking of the bosonic quartic potential $\sim [\Phi_I, \Phi_J]^2$,
that breaks the original gauge group $U(N)$ to $U(1)^{N}$.

The result for the localized partition function is of the form:
\begin{equation}\label{Zmatrixmodel}
 Z=\int \; d^N a \, \prod_{i<j} (a_i-a_j)^2 \; Z_\text{1-loop}(a)\; \left|Z_\text{inst}(a)\right|^2\; e^{- \frac{8\pi^2 N}{\lambda} \sum_k a_k^2}.
\end{equation}
The classical action comes from the curvature coupling of the scalars in \eqref{SS4}.

The 1-loop correction, for the different theories are
\begin{eqnarray}
 \text{$\mathcal{N}=2^*$ SYM:}  & & Z_\text{1-loop} = \prod_{i<j} \dfrac{H^2(a_i-a_j)}{H(a_i-a_j-MR) H(a_i-a_j+MR)}\\
 \text{$\mathcal{N}=2$ SYM:}  & & Z_\text{1-loop} = \prod_{i<j} H^2(a_i-a_j) \\
 \text{$\mathcal{N}=4$ SYM:}  & & Z_\text{1-loop} = 1
\end{eqnarray}
where
\begin{equation}
 H(x) \equiv \prod_{n=1}^{\infty}\left(1+\dfrac{x^2}{n^2}\right)^n e^{-\frac{x^2}{n}}.
\end{equation}
% This function is $1$ at the origin and vanishes very fast away from it.
We used the 't Hooft coupling $\lambda = g_{YM}^2 N$,
and $R$ is again the radius of the hypersphere.

The instanton partition function is the generating function of instantons of topological charge $k$:
\begin{equation}
 Z_\text{inst} = \sum_{k=0}^\infty (e^{i 2\pi\tau})^k Z_k,
\end{equation}
where $Z_0 = 1$ and
\begin{equation}
\tau = i \frac{4\pi}{g_\text{YM}^2} + \frac{\theta}{2\pi}
\end{equation}
is the complexified Yang-Mills coupling\footnote{
The instanton action is the pure Yang-Mills action with an additional topological term.
For an instanton of charge $k$, the action is given by:
\[
S_\text{YM} (k)=
    -\frac{1}{2 g_\text{YM}^2} \text{tr} \int d^4 x \sqrt{g} F_{\mu\nu} F^{\mu\nu}
    -i \frac{\theta}{8\pi^2} \text{tr} \int F \wedge F
    = \left( \frac{8\pi^2}{g_\text{YM}^2} - i \theta \right) k
    = - i 2 \pi \tau \, k.
\]
% This action breaks CP symmetry.
% In QCD, there is no experimental evidence of CP violation, hence $\theta$ must be very small,
% and it is a considered a fine-tuning problem called the strong CP problem.
}.
% Instantons are tunnelling events in Minkowski signature
% In QCD, the groundstate, called the $\theta$-vacuum, is considered the superposition of all vacua. }.

For the $\mathcal{N}=4$ case, $Z_\text{inst} = 1$, \cite{Okuda:2010ke}.
For the $\mathcal{N}=2$ cases, it is non-trivial, \cite{Nekrasov:2002qd}.
However, the regime of interest is the large $N$ limit:
\begin{equation}\label{largeNlimit}
 N\rightarrow \infty \quad \text{and} \quad \lambda = g_\text{YM}^2 N \quad \text{is kept finite},
\end{equation}
then the expansion parameter becomes
$$e^{i 2\pi\tau}=e^{-\frac{8\pi^2 N}{\lambda} + i \theta},$$
hence the instanton contributions are expected to be exponentially suppressed.
This is checked in \cite{Russo:2013kea}.

%
% for a single instanton in $\mathcal{N}=2^*$
% \begin{equation}
%  Z_\text{1-inst} = - e^{-\frac{8\pi^2 N}{\lambda} + i \theta} (M R)^2
% 		  \sum_{l=1}^N \prod_{j\neq l}^N \dfrac{ (a_l-a_j +i)^2 - (MR)^2}{(a_l-a_j) (a_l-a_j+2i)}
% \end{equation}
% Integral representation
% \begin{equation}
%  Z_\text{1-inst} = e^{-\frac{8\pi^2 N}{\lambda} + i \theta} \dfrac{2 (M R)^2}{(M R)^2+1}
% 		  \int \frac{dz}{2\pi} \prod_{j=1}^N \dfrac{(z-a_j)^2 - (MR)^2}{(z-a_j)^2+1}
% \end{equation}

\section{Large-$N$ matrix model}

The localized partition function \eqref{Zmatrixmodel} is a matrix model.
% Therefore, it is convenient to think of it as an analogous statistical model, as we shall see.
For the $\mathcal{N}=4$ case, the model is particularly simple,
it is the well-known Gaussian unitary ensemble (GUE) in the random matrix theory.
The product of the eigenvalue differences is the Vandermonde determinant squared,
which is essentially the Jacobian factor after diagonalizing the Hermitean matrix in \eqref{vevScalar}.
Writing it in terms of the effective action:
\begin{equation}\label{eq:ZGUE}
 Z_\text{GUE} = \int \; d^N a \;  e^{- S[a]},
 \quad S[a]=- \sum_{i\neq j}^N \log(|a_i-a_j|) + \frac{8\pi^2 N}{\lambda} \sum^N_k a_k^2
\end{equation}
we see that the Vandermonde determinant gives the 2d Coulomb potential.
This partition function is indeed identified with that of a 2d Coulomb gas confined on a line,
with the repulsive electrostatic force and an attractive harmonic force \cite{Dyson:1962es}.

% Exact methods exist,
% such as the orthogonal polynomial method,
% to solve the spectral distribution.
% These allow physicists to compute observables exactly for $\mathcal{N}=4$ (cite Genis).

For $\mathcal{N}=2^*$, the matrix model is highly non-trivial,
but we can solve it systematically in the large $N$ limit,
where the saddle-point approximation and the continuous approximation in principle apply.
The only relevant quantity to compute then is the distribution of the eigenvalues:
\begin{equation} \label{def:rho}
\rho(x) = \dfrac{1}{N} \, \sum_{i=1}^N \delta(x-a_i) .
\end{equation}
It must have a compact support, i.e. $\rho(\pm \mu) = 0$,
where the endpoint $\mu$ determines the scale of the spontaneous symmetry breaking.
By definition, it is also unit-normalized:
\begin{equation}
 \int_{-\mu}^\mu dx\, \rho(x) = 1.
\end{equation}

The saddle-point equation, from extremizing the effective action \eqref{eq:ZGUE} in terms of \eqref{def:rho},
is a singular (principal value) integral equation:
\begin{equation} \label{saddlepointEq}
 \dfrac{\delta S [\rho]}{\delta \rho(x)} = 0 \quad
 \Rightarrow \quad
 \fint_{-\mu}^\mu dy \, K(x-y) \rho(y) = \dfrac{8\pi^2}{\lambda}x.
\end{equation}
The singular kernel for the GUE case is just the Hilbert kernel\footnote{
The name is in relation with the Hilbert transform.
It is also known as Cauchy kernel in the literature.},
that is
\begin{equation}
 K_\text{Hilbert}(x)=\dfrac{1}{x}.
\end{equation}
In the Coulomb gas picture, the saddle-point equation determines the equilibrium distribution due to the force balance.
The result is the well-known Wigner's semicircle distribution
\begin{equation}\label{semicircle}
 \rho(x) = \dfrac{2}{\pi \mu^2} \sqrt{\mu^2-x^2},
 \quad \mu = \dfrac{\sqrt{\lambda}}{2\pi},
\end{equation}
shown in figure \ref{fig:semicircle}.

\begin{figure}[t]
\begin{center}
 \centerline{\includegraphics[width=0.8\textwidth]{Images/semicircle.pdf}}
 \caption{\label{fig:semicircle} Wigner's semicircle distribution, solution to the Gaussian unitary ensemble (GUE).}
\end{center}
\end{figure}

For the $\mathcal{N}=2^*$ SYM, the kernel is
\begin{equation}
 K(x)=\dfrac{1}{x}-\mathcal{K}(x)+\dfrac{1}{2}\,\mathcal{K}(x+MR)+\dfrac{1}{2}\,\mathcal{K}(x-MR),
\end{equation}
where
\begin{equation}
 \mathcal{K}(x) \equiv -\dfrac{H'(x)}{H(x)}
                = 2x\sum_{n=1}^{\infty} \left(\dfrac{1}{n}-\dfrac{n}{n^2+x^2} \right),
\end{equation}
and much more interesting features show up in the saddle-point solution, as shown in figure \ref{fig:phaseDiagram}.
Let us briefly review these results.

In the strong-coupling regime, the bulk of the distribution is also a semicircle but with a rescaled endpoint:
\begin{equation}\label{semicircleN=2*}
 \rho(x) = \dfrac{2}{\pi \mu^2} \sqrt{\mu^2-x^2},
 \quad
 \mu=\dfrac{\sqrt{\lambda (1+(MR)^2)}}{2\pi},
 \quad (\lambda \rightarrow \infty).
\end{equation}
This is due to the fact that the kernel is approximately a Hilbert kernel \cite{Buchel:2013id}:
\begin{equation} \label{Kapprox}
 K(x) \approx \dfrac{1+(MR)^2}{x}, \quad (\lambda \rightarrow \infty).
\end{equation}
Close to the edge-points, this approximation no longer holds,
and it was the goal of Paper I to find the endpoint distribution in the strong coupling regime.

We computed the endpoint distribution exactly using the so-called Wiener-Hopf method,
which is essentially the Fourier transform of the convolution integral in \eqref{saddlepointEq} in a semi-infinite interval
(zero being at the endpoint),
that relies on a certain factorization of the kernel.

The distribution exhibits oscillatory behavior with a period proportional to the scale $M R$.
In the decompactification limit $MR\rightarrow \infty$ (but $\mu\gg MR$ because we remain in the strong coupling limit),
the peaks of the oscillation diverge, see figure \ref{fig:phaseDiagram}.
The analytical endpoint distribution at strictly infinite coupling and flat space, with $\xi\equiv\mu-x$, is summarized below:
\begin{equation}
 \rho(\xi )= \frac{2^{3/2}}{\pi \mu^{3/2}}
% \frac{\sqrt{2 M R}}{\pi \mu^{3/2}}
 \begin{cases}
   MR \sqrt{\xi},
   &\quad (\xi \sim 1)\\
   \dfrac{\sqrt{M R}}{2}\sum_{k=0}^{\left[\frac{\xi }{MR}\right]}
             \left(\left\{\frac{\xi }{MR}\right\} + k\right)^{-1/2}
   &\quad (\xi \sim M R),
 \end{cases}
\end{equation}
where $[\cdot]$ and $\{\cdot\}$ denote the integer and the fractional part, respectively,
and $\mu=MR\sqrt{\lambda}/(2\pi)$, from \eqref{semicircleN=2*}.

Physically, the cusps appear due to a resonance phenomena
\begin{equation}
m_{ij} = |a_i-a_j \pm MR| \approx 0
\end{equation}
of very light states in the hypermultiplet sector.
Similar features were already observed for finite couplings in the flat space limit \cite{Russo:2013qaa},
and it was numerically shown that there are infinite-many critical couplings defined by
\begin{equation}
 \mu = g(\lambda_c^{(n)}) M R, \quad g(\lambda_c^{(n)}) = \dfrac{n}{2}, \quad n=1,\ldots
\end{equation}
This means there are infinitely many phase transitions, where the phases are distinguished by the number of cusps of the distribution,
and the coupling $\lambda$ is the order parameter.
At strong coupling, the critical behavior persists and matches with the one obtained from the decompactification limit,
hence these two limits commute \cite{Zarembo:2014ooa}.

\begin{figure}[t]
\begin{center}
 \centerline{\includegraphics[width=0.9\textwidth]{Images/phaseDiagram.pdf}}
\end{center}
\caption{\label{fig:phaseDiagram} Phase diagram for the partition function of $\mathcal{N}=2^*$ SYM on $S^4$, in the large $N$ limit.
The plots at the decompactification limit are taken from \cite{Russo:2013qaa}, and the ones at strong coupling limit are from Paper I, where only close to the endpoint is shown and $R=1$.
In the zero mass limit, we have $\mathcal{N}=4$ SYM, where the distribution is the Wigner semicircle for any coupling.}
\end{figure}

Such phase transitions are common among large-$N$ matrix models,
and have been observed in e.g. ABJM models \cite{Anderson:2014hxa}, 5d $\mathcal{N}=1$ SYM with massive matter multiplets \cite{Nedelin:2015mta}.
In our case, the gauge/string duality in principle gives us an opportunity to understand them from the point of view of gravity.
The physical observables we use to probe the infinite-coupling phase are Wilson loops, the topic of the next chapter.


\section{Application: Dimensionless variables}

This section shows how solving systems of equations can be used to
determine appropriate dimensionless variables. It is only an
introduction to this topic and considers a specific example of a
simple airplane wing shown below. We assume for simplicity that it is
a flat plane at an angle to the wind which is blowing against it with
speed $V$ as shown.

\begin{center}
  \begin{tikzpicture}
    \draw[fill=cyan](-5,1)--(0, 2)--(1.75,1.25)--(-3.25,0.25)--(-5,1);
    \draw(-3.25,0.25)--(-5,0.25);
    \draw[->](-6,1.5)--(-3.5,1.5);
    \node[above right] at (-4,0.5){$A$};
    \node[right] at (-1,0.5){$B$};
    \node[above right] at (-4.75,0.25){$\theta$};
    \node[above] at (-5,1.5){$V$};
  \end{tikzpicture}
\end{center}

The angle $\theta$ is called the angle of incidence, $B$ is the span
of the wing and $A$ is called the chord. Denote by $l$ the lift. Then
this should depend on various quantities like $\theta,V,B,A$ and so
forth. Here is a table which indicates various quantities on which it
is reasonable to expect $l$ to depend.
\begin{equation*}
  \begin{tabular}{|l|l|l|}
    \hline
    Variable & Symbol & Units \\ \hline
    chord & $A$ & $\m$ \\ \hline
    span & $B$ & $\m$ \\ \hline
    angle incidence & $\theta$ & $\m^0\kg^0\s^0$ \\ \hline
    speed of wind & $V$ & $\m\s^{-1}$ \\ \hline
    speed of sound & $V_0$ & $\m\s^{-1}$ \\ \hline
    density of air & $\rho$ & $\kg\m^{-3}$ \\ \hline
    viscosity & $\mu$ & $\kg\s^{-1}\m^{-1}$ \\ \hline
    lift & $l$ & $\kg\s^{-2}\m$ \\ \hline
  \end{tabular}
\end{equation*}
Here $\m$ denotes meters, $\s$ refers to seconds and $\kg$ refers to
kilograms. All of these are likely familiar except for $\mu$, which we
will discuss in further detail now.

Viscosity is a measure of how much internal friction is experienced
when the fluid moves. It is roughly a measure of how \textquotedblleft
sticky" the fluid is. Consider a piece of area parallel to the
direction of motion of the fluid. To say that the viscosity is large
is to say that the tangential force applied to this area must be large
in order to achieve a given change in speed of the fluid in a
direction normal to the tangential force. Thus
\begin{equation*}
  \mu (\text{area}) (\text{velocity gradient}) =\text{
    tangential force}
\end{equation*}
Hence
\begin{equation*}
  (\text{units of $\mu$}) \m^2\paren{\frac{\m}{\s \m}}
  = \kg\s^{-2}\m
\end{equation*}
Thus the units of $\mu$ are
\begin{equation*}
  \kg\s^{-1}\m^{-1}
\end{equation*}
as claimed above.

Returning to our original discussion, you may think that we would want
\begin{equation*}
  l=f(A,B,\theta,V,V_0,\rho,\mu)
\end{equation*}
This is very cumbersome because it depends on seven variables. Also,
it is likely that without much care, a change in the units such as
going from meters to centimeters would result in an incorrect value
for $l$. The way to get around this problem is to look for $l$ as a
function of dimensionless variables multiplied by something which has
units of force. It is helpful because first of all, you will likely
have fewer independent variables and secondly, you could expect the
formula to hold independent of the way of specifying length, mass and
so forth. One looks for
\begin{equation*}
  l=f(g_1,\ldots,g_k) \rho V^2AB
\end{equation*}
where the units of $\rho V^2AB$ are
\begin{equation*}
  \frac{\kg}{\m^3}\paren{\frac{\m}{\s}}^2\m^2=\frac{\kg\times \m}{\s^2}
\end{equation*}
which are the units of force. Each of these $g_i$ is of the form
\begin{equation}
  A^{x_1}B^{x_2}\theta^{x_3}V^{x_4}V_0^{x_5}\rho^{x_6}\mu
  ^{x_7}  \label{11-july-e1f}
\end{equation}
and each $g_i$ is independent of the dimensions. That is, this
expression must not depend on meters, kilograms, seconds, etc. Thus,
placing in the units for each of these quantities, one needs
\begin{equation*}
  \m^{x_1}\m^{x_2}(\m^{x_4}\s^{-x_4}) (\m^{x_5}\s
  ^{-x_5}) (\kg\m^{-3})^{x_6}(\kg\s
  ^{-1}\m^{-1})^{x_7}=\m^0\kg^0\s^0
\end{equation*}
Notice that there are no units of $\theta$ because it is just the
radian measure of an angle. Hence its dimensions consist of length
divided by length, thus it is dimensionless. Then this leads to the
following equations for the $x_i$.
\begin{equation*}
  \begin{array}{cc}
    \m: & x_1+x_2+x_4+x_5-3x_6-x_7=0 \\
    \s :\  & -x_4-x_5-x_7=0 \\
    \kg: & x_6+x_7=0
  \end{array}
\end{equation*}
The augmented matrix for this system is
\begin{equation*}
  \begin{mymatrix}{rrrrrrr|r}
    1 & 1 & 0 & 1 & 1 & -3 & -1 & 0 \\
    0 & 0 & 0 & 1 & 1 & 0 & 1 & 0 \\
    0 & 0 & 0 & 0 & 0 & 1 & 1 & 0
  \end{mymatrix}
\end{equation*}
The {\rref} is given by
\begin{equation*}
  \begin{mymatrix}{rrrrrrr|r}
    1 & 1 & 0 & 0 & 0 & 0 & 1 & 0 \\
    0 & 0 & 0 & 1 & 1 & 0 & 1 & 0 \\
    0 & 0 & 0 & 0 & 0 & 1 & 1 & 0
  \end{mymatrix}
\end{equation*}
and so the solutions are of the form
\begin{eqnarray*}
  x_1 &=& -x_2-x_7 \\
  x_3 &=& x_3 \\
  x_4 &=& -x_5-x_7 \\
  x_6 &=& -x_7
\end{eqnarray*}
Thus, in terms of vectors, the solution is
\begin{equation*}
  \begin{mymatrix}{c}
    x_1 \\
    x_2 \\
    x_3 \\
    x_4 \\
    x_5 \\
    x_6 \\
    x_7
  \end{mymatrix} =\begin{mymatrix}{c}
    -x_2-x_7 \\
    x_2 \\
    x_3 \\
    -x_5-x_7 \\
    x_5 \\
    -x_7 \\
    x_7
  \end{mymatrix}
\end{equation*}
Thus the free variables are $x_2,x_3,x_5,x_7$. By assigning values to
these, we can obtain dimensionless variables by placing the values
obtained for the $x_i$ in the formula {\eqref{11-july-e1f}}. For
example, let $x_2=1$ and all the rest of the free variables are
0. This yields
\begin{equation*}
  x_1=-1,x_2=1,x_3=0,x_4=0,x_5=0,x_6=0,x_7=0
\end{equation*}
The dimensionless variable is then $A^{-1}B^{1}$. This is the ratio
between the span and the chord. It is called the aspect ratio, denoted
as $AR$. Next let $x_3=1$ and all others equal zero. This gives for a
dimensionless quantity the angle $\theta$. Next let $x_5=1$ and all
others equal zero.  This gives
\begin{equation*}
  x_1=0,x_2=0,x_3=0,x_4=-1,x_5=1,x_6=0,x_7=0
\end{equation*}
Then the dimensionless variable is $V^{-1}V_0^{1}$. However, it is
written as $V/V_0$. This is called the Mach number
$\mathcal{M}$. Finally, let $x_7=1$ and all the other free variables
equal 0. Then
\begin{equation*}
  x_1=-1,x_2=0,x_3=0,x_4=-1,x_5=0,x_6=-1,x_7=1
\end{equation*}
then the dimensionless variable which results from this is
$A^{-1}V^{-1}\rho ^{-1}\mu$. It is customary to write it as
$\Reynolds=(AV\rho) /\mu$. This one is called the Reynold's number. It
is the one which involves viscosity. Thus we would look for
\begin{equation*}
  l=f(\Reynolds,AR,\theta,\mathcal{M}) \kg\times \m/\s^2
\end{equation*}
This is quite interesting because it is easy to vary $\Reynolds$ by
simply adjusting the velocity or $A$ but it is hard to vary things
like $\mu$ or $\rho$. Note that all the quantities are easy to
adjust. Now this could be used, along with wind tunnel experiments, to
get a formula for the lift that would be reasonable. You could also
consider more variables and more complicated situations in the same
way.