\documentclass[12pt]{article}
\usepackage{amsfonts}
\usepackage{bm}

% bold math italic font
\newcommand{\mbf}[1]{\mbox{\boldmath $#1$}}

% symbol used for sqrt(-1)
\newcommand{\Ci}{{\rm i}}

\newcommand{\C}{\mathbb{C}}
\newcommand{\R}{\mathbb{R}}

\newcommand{\var}{\rm Var}
\newcommand{\trace}{\rm Tr}

\newcommand{\code}[1]{{\tt{#1}}}

\newcommand{\rotation}[3]{{\ensuremath{ {\bf R}^{#3}_{#1}({#2}) }}}
\newcommand{\rotat}[1][\bm{\hat{n}}]{\rotation{#1}{\phi}{ }}

\newcommand{\boost}[1][m]{{\ensuremath{ {\bf B}_{\bm{\hat {#1}}}(\beta) }}}

\newcommand{\pauli}[1]{\ensuremath{ {\bm\sigma}_{\rm #1} }}
\newcommand{\para}[1][ ]{\ensuremath{ {\Phi}_{{\rm PA}{#1}} }}

\newcommand{\model}[1][ ]{\ensuremath{{\bm\rho}_j({{\bf T}_{#1}};{\mbf{a}}) }}
\newcommand{\obs}{\ensuremath{ {\bm\rho}_{j,i} }}

\begin{document}

\section{Introduction}

The document discusses the general problem of determining the
polarimetric response of a system using a number of unknown input
polarization states.  In the case of pulsar observations, the unknown
input states are any number of the on-pulse phase bins of the
polarimetric pulse profile.

Let $M$ be the number of polarization states under consideration.  The
unknown input states, $\{\bm\rho_j; 1\le j\le M\}$, are transformed by
both a known transformation, {\bf T}, and the unknown transformation
of the system response, {\bf J}.  In the case of pulsar observations
at multiple parallactic angles, the known transformation, {\bf T}, is
equal to a rotation about the Stokes V axis by the parallactic angle,
\para.

Let $N$ be the number of observations made, each at a different epoch.
For each observation, there exists a known transformation, ${\bf
T}_i$, and a set of measured output states, $\{\obs; 1\le j\le M\}$.

The model to be fitted must predict the value for each of the measured
output states, given the known transformation, {\bf T}.  Let this model
be represented by
\begin{equation}
\model; \;\; 1\le j\le M
\end{equation}
where $\bm{a}$ is a vector of scalar model parameters describing both
the system response and the set of $M$ input states.  This
parameterization will be discussed in the next section.  The best-fit
model will minimize the $\chi^2$ merit function
\begin{equation}
\chi^2(\bm{a}) = \sum_{i=1}^N {1\over\sigma_i^2} \sum_{j=1}^M
	{\var[\obs - \model[i])]}
\end{equation}
where \obs\ is the $i$th observation of the $j$th
polarization state, and $\var({\bf M})$ is the square of the Frobenius
norm, given by
\begin{equation}
\var({\bf M})=\trace({\bf M}{\bf M}^\dagger).
\end{equation}
Here, $\trace({\bf M})$ is the matrix trace and ${\bf M}^\dagger$ is the
Hermitian transpose.  The gradient of $\chi^2$ with respect to the
parameters $\bm{a}$ has components
\begin{equation}
{\partial\chi^2\over\partial a_k} = -2 \sum_{i=1}^N {1\over\sigma_i^2}
	\sum_{j=1}^M \trace\left( [\obs - \model[i]]
	{\partial\model[i]\over\partial a_k} \right)
\end{equation}
(Note that $\bm\rho=\bm\rho^\dagger$, $\trace({\bf A}+{\bf B})=\trace({\bf
A})+\trace({\bf B})$, and $\trace({\bf AB})=\trace({\bf BA})$.)
Taking an additional partial derivative gives
\begin{equation}
{\partial^2\chi^2\over\partial a_l\partial a_k} =
	2 \sum_{i=1}^N {1\over\sigma_i^2} \sum_{j=1}^M \trace({\bf D}_{i,j})
\end{equation}
where
\begin{equation}
{\bf D}_{i,j} =
{\partial\model[i]\over\partial a_l} {\partial\model[i]\over\partial a_k}
	- [\obs - \model[i]] {\partial^2\model[i]\over\partial a_l\partial a_k}
\end{equation}
Referring to the discussion in Numerical Recipes, $\S 15.5$
(hereafter, NR), it is conventional to ignore the second derivatives
of \model[i].  Furthermore, by adopting the NR notation, wherein
\begin{equation}
\beta_k = \sum_{i=1}^N {1\over\sigma_i^2}\sum_{j=1}^M \trace\left(
	[\obs - \model[i]] {\partial{\bm\rho}\over\partial a_k}\right)
\end{equation}
and
\begin{equation}
\alpha_{lk} = \sum_{i=1}^N {1\over\sigma_i^2}\sum_{j=1}^M
	\trace\left( {\partial\model[i]\over\partial a_l}
		{\partial\model[i]\over\partial a_k} \right) = \alpha_{kl}
\end{equation}
the least-squares minimization problem may be reduced to that of
finding the partial derivatives of the matrix function, \model, with
respect to its scalar parameters $a_k$.

\section{Parameterization of the Model}

Let the model of the system response be represented by the $2\times2$
complex Jones matrix, ${\bf J}$, and the model of each of the input states
be represented by the set of coherency matrices, $\{\bm\rho_j; 1\le j\le M\}$,
so that
\begin{equation}\label{eqn:model}
\model = {\bf JT}{\bm\rho}_j{\bf T}^\dagger{\bf J}^\dagger
\end{equation}
An arbitrary matrix, ${\bf J}$, may be represented by its polar decomposition,
\begin{equation}
{\bf J} = J \; \boost \rotat
\end{equation}
where $J=(\det{\bf J})^{1/2}$, \boost\ is a Hermitian matrix (or boost
transformation) and \rotat\ is a unitary matrix (or rotation
transformation).  As shown by Euler, any rotation about an arbitrary
axis may be decomposed into a series of rotations about three
perpendicular axis.  Furthermore, it can be trivially shown that if
{\bf J} satisfies Equation~\ref{eqn:model}, then so does
${\bf J}^\prime = e^{i\phi}{\bf J}$.  Therefore, the phase information of the
complex-valued $J$ may be arbitrarily chosen, and $J$ may be replaced by the
real-valued gain, $G=|J|$, so that the system response may be
parameterized by
\begin{equation}
{\bf J} = G \; \boost \prod_{i=1}^3 \rotation{i}{\phi_i}{ }.
\label{eqn:polar_decomposition}
\end{equation}
Referring to Britton (2000) or Hamaker (2000):
\begin{eqnarray}\label{eqn:boost}
\boost &=& \bm{\sigma}_0\cosh\beta + \bm{\hat{m}\cdot\sigma}\sinh\beta, \\
\rotation{i}{\phi_i}{ } &=& \bm{\sigma}_0\cos\phi_i + i\bm{\sigma}_i\sin\phi_i.
\label{eqn:rotation}
\end{eqnarray}
The coherency matrix of each input polarization state is given by
\begin{equation}\label{eqn:stokes}
{\bm\rho}_j = {1\over2}\sum_{i=0}^3 S_{i,j}\bm{\sigma}_i
\end{equation}
where $S_i$ are the Stokes parameters.
By defining $\bm{b}=(b_1,b_2,b_3)=\bm{\hat{m}}\sinh\beta$, the model of
the receiver and source polarization states is completely specified by $G$,
$b_{1-3}$, $\phi_{1-3}$, and $\{S_{0-3}\}_j$.

\subsection{Partial Derivatives}
Referring to Equations~\ref{eqn:boost} to~\ref{eqn:stokes} and the definition
of $\bm{b}$, the partial derivatives of the model may be derived without
any ``small value'' approximations:
\begin{equation}
{\partial\boost\over\partial b_i} =
	\bm{\sigma}_0{b_i\over\sqrt{1+|\bm{b}|}} + \bm{\sigma}_i
\end{equation}

\begin{equation}
{\partial\rotation{i}{\phi_i}{ }\over\partial \phi_i} =
	-\bm{\sigma}_0\sin\phi_i + i\bm{\sigma}_i\cos\phi_i.
\end{equation}

\begin{equation}
{\partial{\bm\rho}_j\over\partial S_{i,j}} = {\bm{\sigma}_i\over2}
\end{equation}

\section{Degeneracy under Commutation}

Using the multiplication rule
\begin{equation}
\bm{AB}=(a\bm{\sigma}_0+\bm{a\cdot\sigma})(b\bm{\sigma}_0 + \bm{b\cdot\sigma})
= ab + \bm{a\cdot b} + (a\bm{b} + b\bm{a} + \Ci \bm{a\times b})\bm{\cdot\sigma}
\end{equation}
it can be seen that $\bm{A}$ and $\bm{B}$ commute
(ie. $\bm{AB}=\bm{BA}$) when $\bm{a}$ and $\bm{b}$ are parallel (so
that $\bm{a\times b}=0$).  This observation enables simple statements to
be made regarding the uniqueness of any solution.

Consider the observation of source polarization states at multiple
parallactic angles.  In this case, the transformation, {\bf T}, is
given by a rotation about the V-axis:
\begin{equation}
{\bf T}=\rotation{3}{\Phi_{\rm PA}}{ } = \bm{\sigma}_0\cos\Phi_{\rm PA}
	 + i\bm{\sigma}_3\sin\Phi_{\rm PA}.
\end{equation}
An arbitrary matrix of the form, ${\bf U}_3= u_0\bm{\sigma}_0 +
u_3\bm{\sigma}_3$ commutes freely with $\rotation{3}{\Phi_{\rm PA}}{
}$.  If ${\bf U}_3$ has unit determinant, and if {\bf J} and
${\bm\rho}_j$ satisfy Equation~\ref{eqn:model}, namely
\begin{equation}
{\bm\rho}^\prime_j = {\bf J}\rotation{3}{\Phi_{{\rm PA},i}}{ }{\bm\rho}_j{\rotation{3}{\Phi_{{\rm PA},i}}{ }}^\dagger{\bf J}^\dagger
\end{equation}
then
\begin{equation}
{\bf J}_u = {\bf JU}_3 \hspace{1cm} {\rm and} \hspace{1cm}
{\bm\rho}_{j,u} = {\bf U}^{-1}_3{\bm\rho}_j{\bf U}^{\dagger-1}_3
\end{equation}
are also solutions to this equation.  This degeneracy exists
regardless of the parameterization of {\bf J} or ${\bm\rho}_j$,
proving that there is no unique solution to the pulsar
self-calibration problem based solely on observations of the pulsar at
multiple parallactic angles.

\subsection{Additional Constraints}

The arbitrary matrix, ${\bf U}_3$, may also be decomposed into a boost
along the Stokes V axis and a rotation about this axis.  As shown by
Hamaker, an observation of an unpolarized source may be used to
completely constrain the boost component of the system response.  In
addition to constraining the boost along Stokes V, such additional
information may also be used to allow the system gain (and
differential gain) to vary from observation to observation.

The rotation about the Stokes V axis will remain unconstrained unless
a source with a well-known position angle (and rotation measure) can
be observed.

\end{document}


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

\marginpar{Monday\\ 2021-6-14, \\ compiled \\ \today}

Last time we discussed the STF decomposition as a way to do spherical harmonics in Cartesian coordinates.

The very nice thing is that the general solutions we find in this way are not only valid for flat spacetime: if we substitute the stress-energy tensor appropriately (including the Isaacson tensor), we can apply them to any background.

\section{Multipolar expansion and tensor spherical harmonics}

The TT expression is
%
\begin{align}
h_{ij}^{TT} = \frac{G}{c^{4}} \frac{1}{r} \Lambda_{ij}^{kl} \sum _{a=0} \frac{1}{a!} \partial_{t}^{a} S^{kl i_1 \dots i_a} (u) n_{i_1 } \dots n_{i_a}
\,,
\end{align}
%
where
%
\begin{align}
S^{kl i_1 \dots i_a} \sim \int \dd[3]{x} T^{kl} x^{i_1 } \dots x^{i_a}
\,.
\end{align}

There is a STF formula which we discussed last time.

Finally, there is a tensor spherical harmonics expression:
%
\begin{align}
h_{ij}^{TT} = \frac{G}{c^{4}} \frac{1}{r} \sum _{\ell=2} sum_{m= - \ell}^{\ell} \qty[
    u_{\ell m} (n) \qty(Y^{E2}_{\ell m})_j (\theta , \varphi )
    +
    v_{\ell m} (n) \qty( Y^{B2}_{\ell m})_{ij} (\theta , \varphi )
]
\,,
\end{align}
%
where the \(Y\) are called tensor spherical harmonics, of electric and magnetic type, while the \(u\) and \(v\) are coefficients.

The relation between these three expression is as follows: using the orthogonality property of the \(Y_{\ell m}\) we can extract the coefficients.
A sketch of the calculation is as follows, if \(1a\), \(1b\) and \(1c\) are the three alternative expressions:
%
\begin{align}
\int (1a) \qty(Y^{E2}_{\ell m})_{ij}^{*} \dd{\Omega } =
\int (1c) \qty(Y^{E2}_{\ell m})_{ij}^{*} \dd{\Omega } = u_{\ell m}
\,,
\end{align}
%
whose first component will read
%
\begin{align}
\sum _{a=0} \frac{1}{a!} \partial^{a}_{t} S^{k \ell i_1 \dots i_a}
\underbrace{\int \dd{\Omega } \qty(Y^{E2}_{\ell m})^{*}_{ij} \Lambda_{ij}^{k \ell} n_{i_1 } \dots n_{i_a}}_{= \mathcal{Y}_{i_1 \dots i_a}^{\ell m *} + \order{c^{-2}}}
\,,
\end{align}
%
where the brace identification is the result of a long calculation.

The result is then
%
\begin{align}
\sum _{a=0} \frac{1}{a!} \partial_{t}^{a} S^{k \ell i_1 \dots i_a} \mathcal{Y}^{\ell m *}_{i_1 \dots i_ a} =
\dv[\ell]{u} M^{i_1 \dots i_\ell} \mathcal{Y}^{\ell m *}_{i_1 \dots i_\ell} \sim
\int \dd[3]{x} r^{\ell} T^{00} Y_{\ell m}^{*}
\,.
\end{align}

Thinking ``quantum mechanically'', we have \(\vec{J} = \vec{L} + \vec{S}\). We define the Tensor Spherical Harmonics \(Y\) of a field of spin \(s\) as the simultaneous eigenfunctions of these operators: neglecting indices for the moment, we have
%
\begin{align}
J^2 Y &= j (j+1) Y \\
J_z Y &= j_z Y \\
L^2 Y &= L (L+1) Y \\
S^2 Y &= s (s+1) Y
\,.
\end{align}

In the spin-\(1/2\) case this is a spinor.

These objects read
%
\begin{align}
\ket{j j_z} = \sum _{L_z = -L}^{L} \sum _{s_z = -s}^{s} \braket{L L_z s s_z}{j s_z} \ket{L L_z s s_z}
\,,
\end{align}
%
and the total angular momentum obeys \(\abs{L -s} \leq j \leq L + s\).

How do we construct these eigenfunctions? We take the scalar eigenfunctions of the angular momentum
%
\begin{align}
L^2 Y_{L L_z} = L (L+1) Y_{L L_z}
\,,
\end{align}
%
and the spin eigenfunctions (ignoring indices)
%
\begin{align}
S^2 X_{s s_z} = s (s+1) X_{s s_z}
\,,
\end{align}
%
we can make use of the Clebsh-Gordan coefficients:
%
\begin{align}
Y = \sum _{L_z} \sum _{s_z} \braket{L L_z s s_z}{j s_z} Y_{L L_z} X_{S S_z}
\,.
\end{align}

Let us particularize to the spin-\(1/2\) case, in which \(X_{1/2} = \qty{ (0,1)^{\top}, (1, 0)^{\top}}\).
The vector spherical harmonics are
%
\begin{align}
X_{1 \pm 1} = \mp \frac{1}{\sqrt{2}} \qty(\hat{x} \pm i \hat{y})
\,,
\end{align}
%
while \(X_{10} = \hat{z}\).

The solutions of \(\square v^{i} = 0\) can be represented as an expansion in \(Y_{s=1}\).
These harmonics are usually combined in a new orthonormal basis:
%
\begin{align}
Y^{R}_{j j_z} &= \sqrt{2 j + 1} \qty[ j^{1/2} Y^{j-1}_{j j_z} - (j+1)^{1/2} Y^{j+1}_{j j_z}] = Y_{j j_z} \hat{n} \\
Y^{E}_{j j_z} &= \sqrt{2j+1} \qty[ (j+1)^{1/2} Y^{j-1}_{j j_z} + j^{1/2} Y^{j+1}_{j j_z}] = \sqrt{j (j+1)} r \cdot \nabla Y_{j j_z} \\
Y^{B}_{j j_z} &= i Y^{j}_{j j_z} = \hat{n} \times Y^{E}_{j j_z}
\,.
\end{align}

The direction along the propagation direction \(\hat{n}\) is longitudinal, and orthogonal to it we have electric and magnetic types.
Under parity the electric type transforms as \((-)^{\ell}\), the magnetic type transforms as \((-)^{\ell +1}\).

In terms of notation, we move from \((j, j_z)\) to \(\ell, m\).

The solution of the vector wave operator reads
%
\begin{align}
V^{i} (t, r, \theta , \varphi ) = \sum _{\ell = 0} \sum _{m=- \ell}^{\ell} R_{\ell m}(t, r) \qty(Y^{R}_{\ell m} (\theta , \varphi ))^{i}
+ \sum _{\ell} \sum _{m} E_{\ell m}(t, r) \qty(Y^{E}_{\ell m}(\theta , \varphi ))^{i} +
\sum _{\ell} \sum _{m} B_{\ell m} \qty(Y^{B}_{\ell m}(\theta , \varphi ))^{i}
\,.
\end{align}

How do we use this for electromagnetism?
The vector potential \(A^{i}\) is described by such a vector SH decomposition, with \(R_{\ell m} = 0\), while  \(E_{\ell m}\) and \(B_{\ell m}\) are the components of the electromagnetic field.

For the spin-2 case we have harmonics going from \(Y^{j-2}\) to \(Y^{j + 2}\).
These can be used to make a new orthornormal basis:
%
\begin{align}
Y^{S0}_{\ell m},
Y^{E1}_{\ell m},
Y^{E2}_{\ell m},
Y^{B1}_{\ell m},
Y^{B2}_{\ell m},
\,.
\end{align}

The generic 2-tensor is a combination of these, but since the graviton is massless only the two transverse ones matter --- E2 and B2.

GW have a \(h_+\) and \(h_\times \) polarization --- these are precisely related to these two fundamental transverse modes.

In alternative theories of gravity this might not be the case; there can be up to 6 multipole polarizations.

The geodesic deviation equation reads
%
\begin{align}
\ddot{x}_{i} = - R_{0i0j}x^{j} =  S_{ij} x^{i} =
\left[\begin{array}{ccc}
A_S + A_+ & A_\times  & A_1 \\
0 & A_S - A_+ & A_2 \\
0 & 0 & A_L
\end{array}\right] x^{j}
\,.
\end{align}

In the regular GR case we only have \(A_+\) and \(A_\times \); in an alternative metric theory of gravity the other 4 polarizations may be nonzero.

This is something which can be tested with a network of interferometers!

\end{document}


% easychair.tex,v 3.5 2017/03/15

\documentclass{easychair}
%\documentclass[EPiC]{easychair}
%\documentclass[EPiCempty]{easychair}
%\documentclass[debug]{easychair}
%\documentclass[verbose]{easychair}
%\documentclass[notimes]{easychair}
%\documentclass[withtimes]{easychair}
%\documentclass[a4paper]{easychair}
%\documentclass[letterpaper]{easychair}
\usepackage{fullpage}
\usepackage[]{minted}
\usepackage{amsmath,amsthm}

\newmintinline[icoq]{coq}{}
\setminted[coq]{escapeinside=\#\#,mathescape=true} %,fontsize=\footnotesize}
\newtheorem{example}{Example}

%
\title{À la Nelson-Oppen Combination for \icoq{congruence}, \icoq{lia} and \icoq{lra}}
%
\author{ Frédéric Besson}

% Institutes for affiliations are also joined by \and,
\institute{Inria, Rennes, France}

\authorrunning{F. Besson}

\titlerunning{À la Nelson-Oppen Combination for \icoq{congruence}, \icoq{lia} and \icoq{lra}}

\begin{document}

\maketitle

\begin{abstract}
  We propose a tactic for combining decision procedures using a
  black-box Nelson-Oppen scheme.
  %
  The tactic is instantiated for \icoq{congruence} and either \icoq{lia} or \icoq{lra}.
  %
  The development is available at \url{https://gitlab.inria.fr/fbesson/itauto}.
\end{abstract}

\section{Introduction}
\label{sect:introduction}

The Coq proof-assistant provides decision procedures for various logic
fragments. In practice, most of the goals do not fall in those
restricted fragments and, in that case, an interactive proof is
required.
%
However, there is sometimes a sweet spot when the goal can be solved by a
collaboration of decision procedures.
%
For instance, \icoq{intuition tac} enhances the expressive power of a
tactic \icoq{tac} by providing support for propositional logic.  Our
recent \icoq{itauto tac}~\cite{Itauto} shares the same goal but aims at improving the
completeness and efficiency of the combination.
%

Unfortunately, there is currently no support for solving goals that are
expressed in the combined decidable logic fragments of EUF~\cite{Ackermann} (Equality Logic with
Uninterpreted Functions) and LIA~\cite{presburger} (Linear Integer Arithmetic).
%
Yet, \icoq{congruence}\footnote{\url{https://coq.inria.fr/distrib/V8.13.0/refman/proofs/automatic-tactics/logic.html\#coq:tacn.congruence}}~\cite{Corbineau06} subsumes EUF and \icoq{lia}\footnote{\url{https://coq.inria.fr/distrib/V8.13.0/refman/addendum/micromega.html\#coq:tacn.lia}}~\cite{BessonCP11,Besson06} solves LIA.
Moreover, Nelson and Oppen~\cite{NelsonO79} propose a combination scheme which is complete for the combination EUF+LIA.

In the following, we present our \icoq{smt}
tactic\footnote{\url{https://gitlab.inria.fr/fbesson/itauto}} which implements the Nelson-Oppen combination scheme in a black-box manner.

\section{Motivating Example}
The crux of the Nelson-Oppen scheme is that equality sharing is
sufficient\footnote{Under technical conditions that are not detailed here} for
a complete combination of two decidable theories  when
the unique shared symbol is equality. The following example
illustrates a somewhat painful interactive proof that is automated by our
\icoq{smt} tactic.
\begin{example}
  \label{exa:motivating}
  Consider the following goal.
\begin{minted}{coq}
Goal #$\forall$# (x y: Z) (P:Z -> Prop), x :: nil = y + 1 :: nil -> P (x - y) -> P 1.
\end{minted}
Neither \icoq{congruence} nor \icoq{lia} solves the goal. Yet, it can
be solved by only asserting equalities that are solved by either \icoq{congruence} or \icoq{lia}.
This is illustrated by the following proof script.
\begin{minted}{coq}
Proof. intros. assert (x = y+1) by congruence. assert (x-y = 1) by lia. congruence. Qed.
\end{minted}
\end{example}

\section{Nelson-Oppen Algorithm}
The first task of the \icoq{smt} tactic is the so-called
\emph{purification} phase which identifies terms that are shared across
theories. The second task consists in propagating equalities between
\emph{pure} terms until the goal is solved. These two phases are implemented
as an OCaml plugin.

\paragraph{Purification}
The \emph{purification} introduces fresh variables and
equations so that every term belongs to one and only one theory.
For Example~\ref{exa:motivating}, we would obtain the following goal.
\begin{minted}{coq}
  hpr1 : 1 = pr1,  hpr3 : y + pr1 = pr3,  hpr2 : x - y = pr2
  H  : x :: nil = pr3 :: nil,  H0 : P pr2
  ==========================================================
  P pr1
\end{minted}
The set of potential equations is then defined as
$
\{ x = y \mid (x,y) \in \mathit{Var} \times \mathit{Var} \}
$
where $\mathit{Var} = \{\icoq{pr1},\icoq{pr2}, \icoq{pr3}, \icoq{x} \}$.
%
The set of variables contains fresh variables but also the existing
variables that are at the interface between the two theories.  Here,
the variable \icoq{x} is an arithmetic variable using as argument of
the constructor \icoq{::}.

\paragraph{Theory Description} In order to perform the purification
phase, it is necessary to have the signature of the theory that is combined with EUF
\emph{i.e.}, the set of arithmetic types and operators.
%
This is done by declaring instances of the two following type-classes.
\begin{minted}{coq}
Class TheoryType(Tid:Type)(T:Type):Type. Class TheorySig(Tid:Type){T:Type}(Op:T):Type.
\end{minted}
Note that the type-classes are parametrised by an uninterpreted type
\icoq{Tid} that only used to identify a theory. In our case, \icoq{ZarithThy} is associated to
\icoq{lia} and \icoq{RarithThy} is associated to \icoq{lra}.

\paragraph{Equality Sharing} Our current Nelson-Oppen tactic is binary and can combine
\icoq{congruence} with either \icoq{lia} or \icoq{lra}.
%
After purification, we recursively try to prove one of the equality
using either \icoq{congruence} or the arithmetic tactic.  If tactic
$T_1$ succeeds at asserting an equation, we try to solve the goal
using tactic $T_2$. If $T_2$ fails, we iterate the process until none
of the equation can be proved.
%
As there is a quadratic number of possible equations, the combination
requires, in the worst case, a cubic number of calls to the decision
procedures.

\section{Conclusion and Limitations}
Our \icoq{smt} tactic improves automation and has the advantage of
reusing the existing tactics \icoq{congruence}, \icoq{lia} and \icoq{lra} in a
black-box manner. More experiments are needed to assess to what extent
automation is increased in practice and whether efficiency is satisfactory.
%
Improving efficiency would require to adapt the decision procedures so
that they either prove a goal or assert equations.
%
Though this might not be a problem in practice, our implementation is
not complete. LIA is a so-called \emph{non-convex} theory which
requires propagating not only equalities but disjunctions of
equalities. Moreover, \icoq{lia} is first running \icoq{zify}. It is
currently unclear how this impacts the Nelson-Oppen scheme.

\label{sect:bib}
\bibliographystyle{plain}
%\bibliographystyle{alpha}
%\bibliographystyle{unsrt}
%\bibliographystyle{abbrv}
\bibliography{biblio}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-engine: default
%%% TeX-master: t
%%% TeX-command-extra-options: "-shell-escape"
%%% mode: flyspell
%%% ispell-local-dictionary: "british"
%%% End:


\documentclass[12]{scrartcl}
\usepackage{amssymb,amsmath,gensymb,dsfont,calc,multicol,fullpage}
\usepackage{float}
\restylefloat{table}
\makeatletter
\newcommand\Aboxed[1]{
   \@Aboxed#1\ENDDNE}
\def\@Aboxed#1&#2\ENDDNE{%
   &
   \settowidth\@tempdima{$\displaystyle#1{}$}
   \setlength\@tempdima{\@tempdima+\fboxsep+\fboxrule}
   \kern-\@tempdima
   \boxed{#1#2}
}
\makeatother

\begin{document}

\title{Homework 29, Section 5.4 2, 7, 10, 14, 18 (a formula answer is sufficient), 20, and the problem below.}
\author{Alex Gordon}
\date{\today}
\maketitle
\section*{Homework}
\subsection*{2. A)}
$C(8,6) = 28 possibilities$
\subsection*{2. B)}
$Same question, so 28$
\subsection*{2. C)}
$2^8 - C(8,1) = 247$
\subsection*{7.}
$C(4,4) \cdot C(7,3) \cdot C(10,3) = 4,200$
\subsection*{10.}
$C(11,2) \cdot C(9,2) \cdot 5 \cdot C(7,2) = 9,989,600$
\subsection*{14.}
\begin{table}[H]
    \begin{tabular}{|l|l|l|}
    \hline
    Fruit  & Equation        & Binary Sequence \\ \hline
    5a, 5b & 5 + 5 + 0 = 10  & 000001000001    \\ \hline
    5a, 5p & 5 + 5 + 0 = 10  & 000001100000    \\ \hline
    1a, 9p & 1 + 0 + 9 = 10  & 011000000000    \\ \hline
    10 b   & 0 + 10 + 0 = 10 & 100000000001    \\ \hline
    \end{tabular}
\end{table}
\subsection*{18.}
$C(49,20) =$ Some really big number I'm too lazy to copy.
\subsection*{The "Problem below" A)}
$C(13,6) =1716$
\subsection*{The "Problem below" B)}
$C(19,12) =50,388$
\subsection*{The "Problem below" C)}
$C(31,24) = Some big number$
\subsection*{The "Problem below" D)}
$C(11,4) = 330$
\subsection*{The "Problem below" E)}
$C(15,9) = 5005$
\end{document}


\documentclass{article}
    % General document formatting
    \usepackage[margin=0.7in]{geometry}
    \usepackage[parfill]{parskip}
    \usepackage[utf8]{inputenc}
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{tikz}
    \usepackage{fancyhdr}
    \usepackage{listings}

\pagestyle{fancy}
\fancyhf{}
\rhead{Edgar Jacob Rivera Rios - A01184125}

\begin{document}
\begin{titlepage}

    \newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % Defines a new command for the horizontal lines, change thickness here

    \center % Center everything on the page

    %----------------------------------------------------------------------------------------
    %	HEADING SECTIONS
    %----------------------------------------------------------------------------------------

    \textsc{\LARGE Tecnológico de Monterrey}\\[1.5cm] % Name of your university/college
    \textsc{\Large Fundamentos de computación}\\[0.5cm] % Major heading such as course name
    %\textsc{\large Minor Heading}\\[0.5cm] % Minor heading such as course title

    %----------------------------------------------------------------------------------------
    %	TITLE SECTION
    %----------------------------------------------------------------------------------------

    \HRule \\[0.4cm]
    { \huge \bfseries Homework 6}\\[0.4cm] % Title of your document
    \HRule \\[1.5cm]

    %----------------------------------------------------------------------------------------
    %	AUTHOR SECTION
    %----------------------------------------------------------------------------------------

    \begin{minipage}{0.4\textwidth}
    \begin{flushleft} \large
    \emph{Student:}\\
    Jacob \textsc{Rivera} % Your name
    \end{flushleft}
    \end{minipage}
    ~
    \begin{minipage}{0.4\textwidth}
    \begin{flushright} \large
    \emph{Professor:} \\
    Dr. Hugo \textsc{Terashima} % Supervisor's Name
    \end{flushright}
    \end{minipage}\\[2cm]

    % If you don't want a supervisor, uncomment the two lines below and remove the section above
    %\Large \emph{Author:}\\
    %John \textsc{Smith}\\[3cm] % Your name

    %----------------------------------------------------------------------------------------
    %	DATE SECTION
    %----------------------------------------------------------------------------------------

    {\large \today}\\[2cm] % Date, change the \today to a set date if you want to be precise

    %----------------------------------------------------------------------------------------
    %	LOGO SECTION
    %----------------------------------------------------------------------------------------

    \includegraphics[width=0.4\textwidth,height=\textheight,keepaspectratio]{logo-tec-negro.png} % Include a department/university logo - this will require the graphicx package

    %----------------------------------------------------------------------------------------

    \vfill % Fill the rest of the page with whitespace

\end{titlepage}

\section{Problems}
Solve the following problems:
\begin{enumerate}
    \item For the selection algorithm, analyze and discuss the resulting complexity when the initial list is divided into groups of 19 elements (instead of 15). Derive the proper conclusions.\\
    The base equations are changed ass follows:
    \begin{align*}
        T(n) &= 58\frac{n}{19} + T'(n)\\
        T'(n) &= T(\frac{n}{19}) + 3(\frac{n}{19}) + 19(\frac{1}{2})(\frac{n}{38}) + T'(\frac{3}{4}n)\\
        T'(n) &= 58\frac{n}{19^2} + T'(\frac{n}{19}) + 3(\frac{n}{19}) + 19(\frac{1}{2})(\frac{n}{38}) + T'(\frac{3}{4}n)\\
        T'(n) &= 0.16066n +0.15789n + 0.25n + T'(\frac{n}{19}) + T'(\frac{3}{4}n)\\
        T'(n) &= 0.56855n + T'(\frac{n}{19}) + T'(\frac{3}{4}n)\\
        \alpha n &=0.56855n + \alpha \frac{n}{19} + \alpha \frac{3}{4}n\\
        \alpha &=0.56855 + \frac{\alpha}{19} + \alpha \frac{3}{4}\\
        \alpha &= 2.88\\
        T'(n) &\leq 2.88n\\
        T(n) &= 3.05n + 2.88n = 5.93n
    \end{align*}
    We can see that when the groups are contain 19 elements, the total complexity is reduced by a slight margin when compared to groups of 15 elements. We can also observe that in the 19 case, the way it's composed is different than in the 15 one. When you have 19 items in the group, the number of comparisons needed to find the quartile after broken and sorted is bigger, but the number of comparisons needed to find the $k^{th}$ quartile is smaller. This is clearly because the quartiles are bigger and for that, there are less groups to check.

    \item Given  a  set  of $n$ numbers,  we  want  to  find  the $i$ largest  in  sorted  order  using  a  comparison-based algorithm. Analyze and compare the following methods in terms of $n$ and $i$:
    \begin{enumerate}
        \item Sort the numbers, and list the $i$ largest.\\
        $O(nlog(n) + i )$
        \item Build a max-priority queue (like a heap) with the numbers and extract the minimum $i$ items.\\
        $O(nlog(n) + log(n) * i)$
        \item Use the k-max (session 06) to find the $i$-th largest, partition around that number, and sort the $i$ largest.
        $O(nlog(n) + (n-i)log(n - i))$
    \end{enumerate}

    \item For $n$ distinct elements $x_1, x_2, ..., x_n$ with positive weights $w_1, w_2, ..., w_n$ such that $\sum^{n}_{i=1} w_i= 1$, the weighted (lower) median is the element $x_k$ satisfying $\sum_{x_i<x_k}w_i < \frac{1}{2}$ and $\sum_{x_i>x_k}w_i \leq \frac{1}{2}$

    For example, if the elements are 0.1, 0.35, 0.05, 0.1, 0.15, 0.05, 0.2 and each element equals its weight then the median is 0.1, but the weighted median is 0.2.
    \begin{enumerate}
        \item Argue that the median of $x_1, x_2, ..., x_n$ is the weighted median of the $x_i$ with weights $w_i= 1/n$ for $i=1,2, ..., n$\\
        This is true, given that the median of a set of numbers is defined as the item in the middle when the set is sorted. This means that each one of the elements is as important as the next, ignoring its value or any other metric. This means that the weight of each one would be considered as $1/n$ and using the weighted sorted algorithm with this weight would yield the same result than the classical median.
        \item Show how to compute the weighted median of $n$ elements in $O(nlog(n))$ worst-case using sorting.\\
        For this, we would simply order the array, which gives us the term of $O(nlog(n))$ after which we would just add the weights until we find the one in which the sum surpasses 0.5, that would be the weighted median. That would take us at worst $O(n)$ time, and so the final result is that the complexity is $O(nlog(n))$.
        \item Show how to compute the weighted median of $n$ elements in $O(n)$ worst-case.\\
        First, you have to find the lower median, using the selection algorithm, it takes $O(n)$, then you partition the array in two parts split by the median which also costs $O(n)$. Then, you sum the weights of each part and check if the results meet the criteria layed above, again $O(n)$. If true, that's the weighted median, if not, you add the accumulated cost of the lighter part to the cost of the selected median and add it to the other part. Then apply the algorithm recursively in that partition. This all adds to a complexity of $O(n)$.
    \end{enumerate}

    \item Investigate on how the adversary argument concept can be used to determine the lower bound of merging two ordered lists.\\
    If we assume that there exists two sorted lists of size $n$, we can say that exists an algorithm $A$ that runs in $2n-2$ comparisons which merges the two lists correctly. Then, we say a list called $X$ contains the elements $x_i= 2i -1$ for $i=1$ to $n$ or odd numbers and a list $Y$ with elements $_i= 2i $ for $i=1$ to $n$ or even numbers. When we apply the algorithm $A$ in $X$ and $Y$. Because of the number of comparisons, we know that there exists an element of $X$, $x_i$ which was not compared to $y_i$ and $y_{i + 1}$. As such, there are two cases, that it was compared to $y_i$ or to $y_{i +1}$. In the first case, if we switch $x_i$ to $y_i$, the order of the lists will not be affected, but if we run the algorithm again, the resulting list will be wrong. Thus, there cannot exist any correct comparison-based algorithm that merges two sorted lists of size $n$ in less than $2n-1$ comparisons.
\end{enumerate}
\end{document}


\documentclass{article}
%\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsmath, hyperref}
\usepackage{fancyhdr}
\usepackage[title]{appendix}
\usepackage{enumitem}
\pagestyle{fancy}
\fancyhf{}
\rhead{Math - 6373}
\lhead{Project 2}
\chead{Autoencoders}
\rfoot{Page \thepage}
\lfoot{A. Radillo}
\usepackage{graphicx}
\usepackage{xcolor}
\title{Autoencoders training for handwritten digits classification {\color{blue}(version 2)} \\ {\large Project 2 - Math-6373 - Prof. Azencott}}
\author{Adrian Radillo - PSID: 1328335}
\newcommand{\bi}{\begin{itemize}}
\newcommand{\ei}{\end{itemize}}
\makeatletter
\g@addto@macro\@floatboxreset\centering
\makeatother

\usepackage{tabularx,ragged2e,booktabs,caption}
\newcolumntype{C}[1]{>{\Centering}m{#1}}
\renewcommand\tabularxcolumn[1]{C{#1}}

\usepackage{listings}
\usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
\newcommand{\lp}{\left(}
\newcommand{\rp}{\right)}
%\usepackage{mdframed}
\begin{document}

\lstset{language=Matlab,%
    %basicstyle=\color{red},
    breaklines=true,%
    morekeywords={matlab2tikz},
    keywordstyle=\color{blue},%
    morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
    identifierstyle=\color{black},%
    stringstyle=\color{mylilas},
    commentstyle=\color{mygreen},%
    showstringspaces=false,%without this there will be a symbol in the places where there is a space
    numbers=left,%
    numberstyle={\tiny \color{black}},% size of the numbers
    numbersep=9pt, % this defines how far the numbers are from the text
    emph=[1]{for,end,break},emphstyle=[1]\color{red}, %some words to emphasise
    %emph=[2]{word1,word2}, emphstyle=[2]{style},
}

\maketitle
{\color{blue}
\begin{description}
\item[Remarks:] Everything that is in blue has been added in version 2.\\
\item[GitHub:] This whole project is available at the public repository,\\ \url{https://github.com/aernesto/autoencoders_MATLAB}
\end{description}
}

% -----------------------------------------------------------------------------------------
% DATABASE
% -----------------------------------------------------------------------------------------
\section{Database}
I use the task and data as in project 1. This is a set of
60,000 14x14 grayscale images of handwritten digits for the training set and
10,000 images for the test set, all taken from the MNIST database and pre-processed by myself
in project 1.
% -----------------------------------------------------------------------------------------
% Autoencoder ARCHITECTURE
% -----------------------------------------------------------------------------------------
\section{Autoencoder architecture}
\begin{itemize}
\item The input and output layers have $14\times14=196$ units. The range of each one of these units
is $[0,1]$ as the initial pixel intensities ranging from 0 to 255 were rescaled by 1/255.
\item My tentative values for $h$ are $50,100,150$ for the $h<n_1$ case, and $h=250,300,350$ for the $h>n_1$ case.
\end{itemize}
% -----------------------------------------------------------------------------------------
% FIRST EXPERIMENT
% -----------------------------------------------------------------------------------------
\section{First experiment}
\begin{itemize}
\item My {\color{blue}Software Tool (}ST{\color{blue})} is MATLAB, and more specifically, the Neural Network Toolbox from the R2015b version. I created custom neural networks for the three small {\color{blue}($h<n_1$)} autoencoders with the function create\_NN() presented in appendix~\ref{app:create}.
\item {\color{blue}Below} are short and non-exhaustive descriptions of the options available in this toolbox:
\begin{description}
\item[learning] A neural network object has a property called trainFcn. This object property can be set to many
different values, which correspond to a variety of learning algorithms {\color{blue}(see figure~\ref{fig:trainFcn})}. The backpropagation gradient descent
algorithm corresponds to the name `traingd'. However, in order to update the weights after the presentation of a whole batch I believe that the name `trainb' is more appropriate. But I really struggled to find clear documentation on this
point. Below is a list of all the other options offered by the ST:
\begin{figure}[bth!]
\centering
\fbox{\includegraphics[width=\textwidth]{trainFcn.png}}
\caption{Existing built-in training functions in my ST. Taken from~\cite{Demuth2006}}\label{fig:trainFcn}
\end{figure}
\item[initialization] I used the `rands' initFcn property value for both the weights and the biases. This samples
independent values from the uniform distribution over the interval $[-1,1]$ for each weight and bias. {\color{blue}See figure~\ref{fig:initFcn} for a list of the other available options.}
\begin{figure}[bth!]
\centering
\fbox{\includegraphics[width=\textwidth]{initFcn.png}}
\caption{Existing built-in initializing functions in my ST. Taken from~\cite{Demuth2006}. This picture only concerns the inputWeights property but `rands' exists as well for the layerWeights and biases properties.}\label{fig:initFcn}
\end{figure}
\item[batch learning] The ideal batch learning option that would have suited my needs in the MATLAB Neural Network Toolbox is the `trainingOptions' function called for a convolutional neural network object with the stochastic gradient descent with momentum (`sgdm') solver in the R2016b release of MATLAB. However, my version of MATLAB didn't have this option,
so I set out to produce my training batches myself (as in project 1).

I produced 3,000 batches containing 500 cases each {\color{blue}(this is the batch size)}, taken from the 60,000 cases in the training set. Consecutive
batches were constructed with an overlap of 100 cases, and the whole training set was used 20 times in order to
produce the batches. Each sweep through the training set was preceded by a shuffling of its elements order.
I refer you to the make\_batches.m function in the appendix of my project 1 to see the source code of this function.
In appendix~\ref{app:train_diabolo} I show how the train() function from my ST was called sequentially for each batch
in order to train my autoencoder.
\item[step size] The step size is controlled by the `lr' property of trainFcn property. The ST offered a learning algorithm
based on gradient descent with adapting learning rate (`traingda'), but I was not sure that this corresponded to
the equations seen in class. The `traingd' learning function, that I used, uses a fixed learning rate.
Since I called the train() function sequentially on each batch, I only set the number of Epochs in the training properties to 1, for each iteration. Then, in between iterations, I wasn't sure whether I should change the learning rate manually, or
if the training algorithm would do it for me. This is why there are a lot of commented lines in appendix~\ref{app:train_diabolo}. {\color{blue}In any case, in my code, I used the default value of 0.01 for the learning rate property `lr'.}
\item[{\color{blue}stop training}] {\color{blue} When training the `diabolo' autoencoders, my criterion to stop the training was simply to stop after the 20$^\text{th}$sweep through the training set, or in other words, after the presentation of the last batch, \# 3,000. For the sparse autoencoders with $h>n_1$, I used the `trainscg' function, for which the training was stopped as soon as one of the following criterion was met\footnote{\href{https://www.mathworks.com/help/nnet/ref/trainscg.html?searchHighlight=trainscg&s_tid=doc_srchtitle}{{\color{blue}MATLAB manual reference}}}:
\renewcommand{\labelitemii}{$\bullet$}%options for bullet symbol
\begin{itemize}
\item The maximum number of epochs (sweeps) is reached (I set it to 20).
\item The maximum amount of time is exceeded (I left it at its default value, which is $\infty$)
\item Performance is minimized to the goal (I set it to $MSE=0$).
\item The performance gradient falls below min\_grad (I left it at its default value, which is $\|\text{grad}(MSE(W)) \|=10^{-6}$).
\item Validation performance has increased more than max\_fail times since the last time it decreased (irrelevant for me as I didn't use validation).
\end{itemize}}
\end{description}
\end{itemize}
% -----------------------------------------------------------------------------------------
% Training `small' autoencoders
% -----------------------------------------------------------------------------------------
\section*{Training {\color{blue}`diabolo'} autoencoders}
{ \color{blue}
\subsection*{Training autoencoders and plotting RMSEn}
As mentioned above,
appendix~\ref{app:create} contains the code used to create custom autoencoders with respective hidden layer sizes: 50, 100, 150 (recall that $n_1=196$). Each one of these neural network was subsequently trained according to the source code contained in appendix~\ref{app:train_diabolo}.

Figure~\ref{fig:mse_diabolo} shows the resulting RMSE as a function of the batch number for the three distinct hidden layer sizes.
The three curves are very similar I am therefore quite doubtful about the correctness of my algorithm in appendix~\ref{app:train_diabolo}.

\subsection*{RMSE$^*$ of trained autoencoders}
The RMSE for the trained autoencoders was computed by taking the square root of the output of the script presented in appendix~\ref{app:msemat}. The results are presented in figure~\ref{fig:rmse_global}, together with the results from the sparse autoencoders ($h>n_1$). Once again, values of the RMSE$^*$ above 0.5 indicate that my training was inefficient for the `diabolo' autoencoders. Such inefficient training might have come from an erroneous algorithm, or from a too small number of sweeps during training, or from a too low learning rate. Also, I obtained very similar RMSE values for the three hidden layer sizes. This probably indicates that my training algorithm was erroneous.
}
\begin{figure}[bth!]
\centering
\fbox{\includegraphics[width=0.65\textwidth]{mse_diabolo.png}}
\caption{{\color{blue}Evolution of the RMSE through training, for the three distinct hidden layer sizes. The abscissa has the same unit for all plots.}}\label{fig:mse_diabolo}
\end{figure}

\subsection*{{\color{blue}Explicit mathematical expression to compute $\text{grad}(MSE(W))$}}
Below is a list of mathematical notation that I used to derive the retro-propagation rule by hand.
The final result is expressed in equations~\eqref{one} and~\eqref{two}.
\begin{itemize}
\item Matrix of weights between input and hidden layer:
\[
W=\left(w_{ij}^{(1)}\right)_{ij}, \quad 1\leq i\leq n_2; \quad1\leq j \leq n_1+1,
\]
where $w_{in_1+1}^{(1)}$ is always the threshold of unit $i$.
\item Matrix of weights between hidden and output layer:
\[
W=\left(w_{ij}^{(2)}\right)_{ij}, \quad 1\leq i\leq n_3; \quad1\leq j \leq n_2+1,
\]
where $w_{in_2+1}^{(1)}$ is always the threshold of unit $i$.
\item The total number of cases in the training set or in the batch is denoted by $M$.
\item The state of input unit $i$ under presentation of case $m$ is denoted $x_i$.
\item The state of hidden unit $j$ under presentation of case $m$ is denoted $h_j(W,m)$.
\item The state of unit $k$ on the output layer under presentation of case $m$ is denoted $o_k(W,m)$.
Hence, the output units states are: $o_1(W,m),\ldots,o_{n_3}(W,m)$.
\item Linear output of hidden unit $i$:
\[
A_i^{(1)}(W,m)=\sum_{j=1}^{n_1+1}x_jw_{ij}^{(1)}
\]
\item Logistic function is denoted $\sigma$. We have:
\[
\sigma(v)=\frac{1}{1+e^{-v}}\qquad \sigma'(v)=\frac{e^{-v}}{\lp1+e^{-v}\rp^2}
\]
\item Output of unit $j$ in hidden layer, under presentation of case $m$:
\[
h_j(W,m)=\sigma\lp A_j^{(1)}(W,m) \rp
\]
\item Linear output of the output layer unit $i$:
\[
A_i^{(2)}(W,m)=\sum_{j=1}^{n_2+1}h_j(W,m)w_{ij}^{(2)}
\]
\item Output of unit $i$ in output layer, under presentation of case $m$:
\[
o_i(W,m)=\sigma\lp A_i^{(2)}(W,m) \rp
\]
\item Denote by $\delta_{x,y}$ the Kronecker delta which is 1 only when $x=y$ and zero otherwise.
\item Also, define $\iota$ to be the function that maps each case $m$ to the output unit index $\iota(m)$
which codes for the correct label of this case. Hence, if case 36 represents a 4, then unit $o_5$ will code
for it in $\text{OUT}_{36}$ and therefore $\iota(36)=5$.
\item We denote the MSE function by the letter $f$:
\begin{align}
f(W)&=\frac{1}{M}\sum_{m=1}^{M}\left |\left| \widehat{\text{OUT}}_m-\text{OUT}_m \right |\right |_2^2\\
	&=\frac{1}{M}\sum_{m=1}^M \sum_{k=1}^{n_3}\lp o_{k}(W,m)-\delta_{k,\iota(m)}\rp^2
\end{align}
\item The update rule for the weights is:
\[
\Delta W_n=-\text{grad} \lp f(W)\rp\cdot \frac{\gamma}{\epsilon_n}
\]
\end{itemize}
The formula for the partial derivative of the MSE with respect to a weight from the H-OUT layer, $w^{(2)}_{ij}$, is:
\begin{equation}
\frac{\partial f}{\partial w^{(2)}_{ij}}(W)=\frac{2}{M}\sum_{m=1}^M\sigma'\left(A_i^{(2)}(W,m)\right)h_j(W,m)\left[o_i(W,m)-\delta_{\iota(m),i}\right] \label{one}
\end{equation}
And when it is with respect to a weight from the IN-to-H layer, $w^{(1)}_{ij}$, we get:
\begin{equation}
\frac{\partial f}{\partial w^{(1)}_{ij}}(W)=\frac{2}{M}
\sum_{m=1}^M\left[\sigma'\left(A_i^{(1)}(W,m)\right)x_j
\sum_{k=1}^{n_3}\sigma'\left(A_k^{(2)}(W,m)\right) w^{(2)}_{ki}\left[o_k(W,m)-\delta_{\iota(m),k}\right] \right]\label{two}
\end{equation}
% -----------------------------------------------------------------------------------------
% SECOND EXPERIMENT: `large' autoencoders with sparsity
% -----------------------------------------------------------------------------------------
\section{Second experiment: `large' autoencoders with sparsity}
I trained the `large autoencoders' with the code presented in appendix~\ref{app:sparse}
\subsection{Results}
The following table {\color{blue}in figure~\ref{fig:rmse_global}} was generated with the script presented in appendix~\ref{app:msemat} after training the 9 autoencoders. {\color{blue}We observe that the RMSE of the trained sparse autoencoders is generally smaller than half the magnitude of the RMSE for the `diabolo' autoencoders.

For the sparsity target $\rho=5$\% we observe no difference in RMSE across hidden layer size (h=250, 300, 350). This might be due to the relatively small number of sweeps used in training (20).
For the sparsity target $\rho=15$\%, the RMSE of the trained autoencoders decreases slightly as the hidden layer size increases.}
\begin{figure}[bth!]
\centering
{\color{blue}
\begin{tabular}{|l | c  cc|ccc|ccc|}
\hline
$h$& $50$&$100$&$150$&
$250$&$300$&$350$&
$250$&$300$&$350$\\
$\rho$& &&&
$ 0.05$&$0.05$&$ 0.05$&
$ 0.15$&$0.15$&$0.15$\\
\hline
training & 0.59   & 0.58  &  0.58  &  0.27    &0.27  &  0.27&    0.27 &   0.26   &0.25\\

test &  0.59&0.58&0.58&0.27&0.27&0.27&0.27&0.26&0.25\\
\hline
\end{tabular}}
\caption{{\color{blue}RMSE (bottom two rows) for the nine \emph{trained} autoencoders (one per column), computed over both the training and the test set. The first two rows of the table designate the hidden size $h$ and the sparsity target $\rho$ of each autoencoder.}}\label{fig:rmse_global}
\end{figure}
\section{Detailed analysis of hidden layer structure and efficiency}
I did not have time to do this part of the homework.
{\color{blue}The activations of the hidden layer of each trained autoencoder was computed and projected onto the first three Principal Components, using the scripts presented in appendix~\ref{app:pca}. The 3D scatter plots of these projections are presented in figure~\ref{fig:pca}.}
\begin{figure}[bth!]
\centering
\fbox{\includegraphics[width=\textwidth]{pca.png}}
\caption{{\color{blue}Projection of the activations of the hidden layers of each of the 9 autoencoders, onto the first three principal components. Hidden layer size is h and k represents the smallest number of PCA dimensions required to explain 90\% of the variance of the hidden layer activations. Top row of plots is for the cases $h<n_1$. Middle row is for the cases $h>n_1$ AND $\rho=5$\%. Bottom row is for $\rho=15$\%.}}\label{fig:pca}
\end{figure}
{\color{blue}
For each network, let $k$ be the smallest number of eigenvalues that, jointly, explain more than 90\% of the variance in the activations of the hidden layer.

I do not know why $k$ could  not be computed for the two sparse autoencoders having hidden layer sizes $h=250$ and $300$, and sparsity target $\rho=5$\%.

I observe that the value of $k$ varies greatly between the `diabolo' and the sparse autoencoders.

I do not observe any clustering of the points in the PCA projection space. I hypothesize that none of my networks was sufficiently trained.}
{\color{blue}
\section{Autoencoding efficiency}
I did not have time to address this question.}
\bibliographystyle{plain}
\bibliography{auto}
\begin{appendices}
% -----------------------------------------------------------------------------------------
% MATLAB code
% -----------------------------------------------------------------------------------------
\section{MATLAB code}
\subsection{Custom network with NN Toolbox in MATLAB}
\label{app:create}
\lstinputlisting{create_NN.m}
\subsection{Training the `diabolo'-autoencoders}
{\color{blue}When training the networks with hidden layer sizes 100 and 150, the string `net\_50' below was replaced by
`net\_100' and `net\_150' respectively. Also, the commented lines were never used in my final results, they are merely vestiges of my trials and errors.}
\label{app:train_diabolo}
\lstinputlisting{train_autoencoder.m}
\subsection{Training autoencoders with sparsity constraint}
\label{app:sparse}
\lstinputlisting{train_sparse.m}
\begin{center}
\line(1,0){250}
\end{center}
\lstinputlisting{train_sparse_UH.m}
\subsection{Generating matrix of MSE on training and test sets for all autoencoders}
\label{app:msemat}
\lstinputlisting{mse_perf_small.m}
\subsection{PCA on hidden layers}
\label{app:pca}
\lstinputlisting{pca_hidden.m}
\begin{center}
\line(1,0){250}
\end{center}
\lstinputlisting{create_IH.m}
\begin{center}
\line(1,0){250}
\end{center}
{\color{blue}The following is the script used to produce figure~\ref{fig:pca}.}
\lstinputlisting{pca_global.m}
\end{appendices}
\end{document}


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{physics}
\usepackage{amssymb}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}

\usetikzlibrary{automata,positioning}

% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\bea}{\begin{flalign*}}
\newcommand{\eea}{\end{flalign*}}

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Assignment\ \#3}
\newcommand{\hmwkDueDate}{Due 5th October 2018}
\newcommand{\hmwkClass}{Classical Mechanics}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{Prof.Manas Kulkarni}
\newcommand{\hmwkAuthorName}{\textbf{Aditya Vijaykumar}}

%
% Title Page
%

\title{
    %\vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{\hmwkDueDate\ }\\
%    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}
\maketitle
\begin{homeworkProblem}[1]	\textbf{Part (a)}\\
	For $ m=constant $
	\begin{align*}
	T &= \dfrac{m \va{v} \vdot \va{v} }{2}\\
	\dv{T}{t} &= m \dot{\va{v}}  \vdot \va{v}
	= \va{F} \vdot \va{v}
	\end{align*}

	If $ m $ varies with time,
	\begin{align*}
	mT &= \dfrac{m^2 \va{v} \vdot \va{v} }{2}\\
	\dv{(mT)}{t} &= m^2 \dot{\va{v}}  \vdot \va{v} + m \dot{m} \va{v} \vdot \va{v}\\
	&= (m {\va{v}}) \vdot (m \dot{\va{v}} + \dot{m} {\va{v}})\\
	\dv{(mT)}{t}&= \va{p}\vdot \va{F}
	\end{align*}

	\textbf{Part (b)}\\
	We know that,
	\begin{equation*}
	M_1 \dv[2]{\va{r_1}}{t} + M_2 \dv[2]{\va{r_2}}{t} = \va{F}^{ext} + \va{F}_{12}^i + \va{F}_{21}^i
	\end{equation*}
	where $ \va{F}^{ext} $ and $ \va{F}^i $ are the external and interaction forces respectively. But we also know that,
	\begin{equation*}
	M_1 \dv[2]{\va{r_1}}{t} + M_2 \dv[2]{\va{r_2}}{t} = M \dv[2]{\va{R}}{t} = \va{F}^{ext}
	\end{equation*}

	Comparing the preceding equations, we get,
	\begin{equation*}
	\va{F}_{12}^i + \va{F}_{21}^i = 0 \implies \va{F}_{12}^i = - \va{F}_{21}^i
	\end{equation*}
	This is the weak form of Newton's third law.

	On similar lines,
	\begin{equation*}
	I_1 \va{r}_1 \cross \dot{\va{p}}_1 + I_2 \va{r}_2 \cross \dot{\va{p}}_2 = \va{\tau}^{ext} + \va{\tau}_{12}^i + \va{\tau}_{21}^i \qq{and} I_1 \va{r}_1 \cross \dot{\va{p}}_1 + I_2 \va{r}_2 \cross \dot{\va{p}}_2 = I \va{R} \cross \dot{\va{p}} = \va{\tau}^{ext}
	\end{equation*}
	\begin{align*}
	\implies \va{\tau}_{12}^i + \va{\tau}_{21}^i &= 0\\
	\va{r}_1 \cross \va{F}_{12}^i + \va{r}_2 \cross \va{F}_{21}^i &= 0 \\
	\va{r}_1 \cross \va{F}_{12}^i - \va{r}_2 \cross \va{F}_{12}^i &= 0 \\
	(\va{r}_1-\va{r}_2) \cross \va{F}_{12}^i  &= 0
	\end{align*}
	This means that the action-reaction pair acts along the line joining the two particles. This proves the strong form of the third law.
\end{homeworkProblem}

\begin{homeworkProblem}[2]
	Let $ R $ be the radius of the disc. The generalized coordinates for the motion are the planar coordinates $ x , y$ and angular coordinate $ \theta $ of the disc. For rolling, we have,
	\begin{equation*}
	R \dot{\theta} = v
	\end{equation*}
	Let's assume that the velocity vector makes an angle $ \phi $ with the positive $ x $-axis. We then have,
	\begin{align*}
	\dot{x} = v \cos \phi \qq{and} \dot{y} = v \sin \phi
	&\implies \dot{x} = 	R \dot{\theta} \cos \phi \qq{and} \dot{y} = 	R \dot{\theta} \sin \phi\\
	\therefore d{x} - 	R d{\theta} \cos \phi = 0  &\qq{and} d{y} - R d{\theta} \sin \phi = 0 \\
	\therefore d{x} +  dy &- R (\cos \phi + \sin \phi)d\theta = 0
	\end{align*}
	It is straightforward to see that the above equations are specific instances of an equation of the form,
	\begin{equation*}
	\sum_{i=1}^{n} g_i(x_1,x_2,\ldots, x_n) d x_i = 0
	\end{equation*}
	For the constraint to be holonomic there should be an integrating factor $ f = f(x,y,\theta,\phi) $ which satisfies,
	\begin{equation*}
	\pdv{fg_i}{x_j} = \pdv{fg_j}{x_i}
	\end{equation*}
	Let's say $ f(x,y,\theta,\phi)= X(x) Y(y) \Theta(\theta) \Phi(\phi) $. Consider the following,
	\begin{align*}
	\pdv{fg_x}{\theta} &= \pdv{fg_\theta}{x}\\
	\dfrac{1}{f}\pdv{f}{\theta} &= -\dfrac{1}{f} R \sin \phi \pdv{f}{x}\\
	\dfrac{1}{\Theta}\pdv{\Theta}{\theta} &= -\dfrac{1}{X} R \sin \phi \dv{X}{x}
	\end{align*}
	The RHS is a function of $ x $ multiplied by $ \sin \phi $, while the LHS is purely a function of $ \theta $. They can never be equal, and hence an integrating factor $ f $ never exists.
\end{homeworkProblem}

\begin{homeworkProblem}[3]
	\textbf{Part (a)}\\
	Let $ r, \theta, \phi $ be the generalized coordinates in their usual polar form, and $ l_0 $ be the equilibrium length of the spring. The Lagrangian of the problem $ L $ can be written as,
	\begin{equation*}
	L = \dfrac{m(\dot{r}^2 + r^2\dot{\theta}^2 + r^2 \sin^2 \theta \dot{\phi}^2)}{2} + mgr\cos \theta - \dfrac{k(r - l_0)^2}{2}
	\end{equation*}
	The equations of motion are,
	\begin{align*}
	m\ddot{r} &= mr\dot{\theta}^2 + mr \sin^2 \theta \dot{\phi}^2 + mg \cos \theta  - k(r - l_0)\\
	m r^2 \ddot{\theta} + 2 m r \dot{r} \dot{\theta} &= mr^2 \sin \theta \cos \theta \dot{\phi}^2 - mgr \sin \theta\\
	mr^2 \sin^2 \theta \ddot{\phi} + 2 m r \sin^2 \theta \dot{r} \dot{\phi} + 2 m r^2 \sin \theta \cos \theta \dot{\theta} \dot{\phi} &= 0
	\end{align*}
	Constraining the motion in a plane implies using $ \phi = constant \implies \dot{\phi} = \ddot{\phi} = 0$. \textcolor{red}{Is constraining possible? - yes, one just needs to give it initial velocity in the plane}. Our equations then reduce to,
	\begin{align*}
	m\ddot{r} &= mr\dot{\theta}^2 + mg \cos \theta  - k(r - l_0)\\
	m r^2 \ddot{\theta} + 2 m r \dot{r} \dot{\theta} &= - mgr \sin \theta
	\end{align*}
	The equilibrium positions can be found by substituting all time derivatives of $ r $ and $ \theta $ as zero. This gives the equilibrium $ r_0 = l_0 + \dfrac{mg}{k} $ and $ \theta_0 = 0 $.
	We need to solve the above for small stretching in $ r $ and small angular displacements $ \theta $. Let's substitute $ r = r_0 + \epsilon x $ and $ \theta = \epsilon \alpha $ in the equations. We get,
	\begin{align*}
	m\epsilon \ddot{x} &= m(r_0 + \epsilon x) \epsilon^2 \dot{\alpha}^2 + mg \left( 1 - \dfrac{\alpha^2}{2} \epsilon^2 + \ldots\right)   - k(\epsilon x + r_0 - l_0)\\
	m ( r_0 + \epsilon x)^2 \epsilon \ddot{\alpha} + 2 m \epsilon^2 ( r_0 + \epsilon x) \dot{x} \dot{\alpha} &= - mg( r_0 + \epsilon x ) \left(\epsilon \alpha + \ldots \right)
	\end{align*}
	Using only $ \order{\epsilon} $ terms,
	\begin{align*}
	\ddot{x} &= -\dfrac{k}{m} x\\
	\ddot{\alpha} &= - \dfrac{g}{r_0}\alpha
	\end{align*}

	\textbf{Part (b)}\\
	The Lagrangian is given as,
	\begin{equation*}
	L = e^{\gamma t}\qty(\dfrac{m\dot{q}^2}{2} - \dfrac{k q^2}{2})
	\end{equation*}
	Writing down the equations of motion for hte generalized coordinate $ q $,
	\begin{align*}
	\derivative{t}\qty(e^{\gamma t}m \dot{q}) &= -e^{\gamma t} k {q}\\
	\implies e^{\gamma t} \qty(\gamma m \dot{q} + m \ddot{q}) &= -e^{\gamma t} k {q}\\
	\implies   \ddot{q} + \gamma  \dot{q}+ \dfrac{k}{m}q &= 0
	\end{align*}
	This is the equation of motion for a damped harmonic oscillator.

	Let's perform the transformation $ s = e^{\gamma t} q \implies \dot{s} = e^{\gamma t} (\gamma q + \dot{q}) = \gamma s + e^{\gamma t} \dot{q} $. Inverting these, we have the following,
	\begin{align*}
	q &= e^{-\gamma t} s\\
	\dot{q} &= e^{-\gamma t}(\dot{s} - \gamma s)
	\end{align*}
	Substituting this back into the expression for $ L $,
	\begin{equation*}
	L = e^{-\gamma t}\qty(\dfrac{m\dot{s}^2}{2} + \dfrac{(m\gamma^2 - k) s^2}{2} - m\gamma s \dot{s})
	\end{equation*}
	Writing the equations of motion for $ s $,
	\begin{align*}
	\derivative{t}\qty(e^{-\gamma t}(m \dot{s} - m\gamma s)) &= -e^{-\gamma t} ((k - m\gamma^2) {s} - m\gamma \dot{s})\\
	m \ddot{s} - m\gamma \dot{s} -\gamma (m \dot{s} - m \gamma s) &=  (k - m \gamma^2) {s} - m\gamma \dot{s}\\
	\ddot{s} -\gamma \dot{s} + \qty(2  \gamma^2-\dfrac{k}{m}) s &=  0
	\end{align*}
\end{homeworkProblem}

\begin{homeworkProblem}[4]
	\textbf{Part (a)}\\
	As given, we take $ y = at + bt^2 \implies \dot{y} = a + 2bt$. The Lagrangian $ L $ can be written as follows,
	\begin{align*}
	L &= \dfrac{m \dot{y}^2}{2} - mgy = \dfrac{m (a+2bt)^2}{2} - mg (at + bt^2)\\
	&= \dfrac{ma^2 }{2}+ (2mab - mga)t + (2mb^2 - mgb)t^2
	\end{align*}
	Let's evaluate $ \int L dt $,
	\begin{align*}
	\int_0^{t_0} L dt &= \int_0^{t_0} [\dfrac{ma^2}{2} + (2mab - mga)t + (2mb^2 - mgb)t^2] dt\\
	& = \dfrac{ma^2}{2} t_0 + \dfrac{2mab - mga}{2}t_0^2 + \dfrac{2mb^2 - mgb}{3}t_0^3\\
	& = \dfrac{ma^2}{2} \sqrt{\dfrac{2y_0}{g}} + \dfrac{2mab - mga}{2}\dfrac{2y_0}{g} + \dfrac{2mb^2 - mgb}{3}\dfrac{2y_0}{g}\sqrt{\dfrac{2y_0}{g}}\\
	&= 0 \impliedby \left(a=0 \qq{and} b = \dfrac{g}{2}\right)
	\end{align*}
	\textit{Hence Proved.}
	\\

	\textbf{Part (b)}
	Given, $ L = L(q_i, \dot{q_i}, \ddot{q_i},t) $, and we know that $ S = \int_{t_i}^{t_f} L(q_i, \dot{q_i}, \ddot{q_i},t) dt  $. Variation of the action can be written as,
	\begin{align*}
	\delta S &= \int_{t_i}^{t_f} \delta L dt = 0\\
	&= \int_{t_i}^{t_f} \sum_{i} \qty(\pdv{L}{q_i} \delta q_i+ \pdv{L}{\dot{q_i}} \delta \dot{q_i} + \pdv{L}{\ddot{q_i}} \delta \ddot{q_i})dt\\
	&= \int_{t_i}^{t_f} \sum_{i} \qty(\pdv{L}{q_i} \delta q_i+ \qty(\pdv{L}{\dot{q_i}} - \dv{t}\pdv{L}{\ddot{q_i}} ) \delta \dot{q_i} + \dv{t} \qty(\pdv{L}{\ddot{q_i}} \delta \dot{q_i}))dt\\
	&= \int_{t_i}^{t_f} \sum_{i} \qty[ \qty{\pdv{L}{q_i} - \dv{t}\qty(\pdv{L}{\dot{q_i}} - \dv{t}\pdv{L}{\ddot{q_i}} )} \delta q_i + \dv{t}\qty(\qty(\pdv{L}{\dot{q_i}} - \dv{t}\pdv{L}{\ddot{q_i}} ) \delta {q_i}) + \dv{t} \qty(\pdv{L}{\ddot{q_i}} \delta \dot{q_i})]dt
	\end{align*}
	As the variation of $ q_i $ and $ \dot{q_i} $ at the endpoints is zero, the total derivative terms vanish. Accounting for the fact that all $ q_i $'s are independent, one can write the equation of motion as,
	\begin{equation*}
	\boxed{\pdv{L}{q_i} - \dv{t}\pdv{L}{\dot{q_i}} + \dv[2]{t}\pdv{L}{\ddot{q_i}} = 0}
	\end{equation*}
	Taking $ L = -\dfrac{m}{2}q \ddot{q} - \dfrac{k}{2}q^2$, we can write,
	\begin{equation*}
	kq + \dfrac{m}{2}\ddot{q} = 0 \implies \ddot{q} + \dfrac{2k}{m}q  = 0
	\end{equation*}
	This turns out to be the equation of the simple harmonic oscillator.
\end{homeworkProblem}

\begin{homeworkProblem}[5]
	In all the parts, time translation is an implied conserved quantity, and energy is the corresponding conserved quantity.\\
	\textbf{Part (a)} -
The potential energy in this case will only be a function of z. Hence, the $ x $ and $ y $ momenta will be conserved.

\textbf{Part (b)} -
Let's consider the half-plane in a way that only the part with $ x>0 $ has uniform mass distribution. Here, only $ y $-translations are symmetries and Hence, only $ p_y $ will be conserved.

\textbf{Part (c)} -
An infinite cylinder possesses $ z $-translation and $ z $-rotation symmetry, and hence $ p_z $ and $ L_z $ will be conserved.

\textbf{Part (d)} -
A finite cylinder only has $ z $-rotation symmetry. So, only $ L_z $ is the conserved quantity.

\textbf{Part (e)} -
The infinite right elliptical cylinder only has $ z $-translation symmetry. So, only $ p_z $ is the conserved quantity.

\textbf{Part (f)} -
The dumbell only has $ z $-translation symmetry. So, only $ p_z $ is the conserved quantity.

\textbf{Part (g)} -
The infinite helical solenoid has$ z $-translation and $ z $-rotation symmetries, and hence $ p_z$ and $ L_z $ are the conserved quantities.
\end{homeworkProblem}

\begin{homeworkProblem}[6]
	The Lagrangian for the problem is,
	\begin{equation*}
	L = \dfrac{m(\dot{r}^2 + r^2 \dot{\theta}^2 )}{2} - V(r)
	\end{equation*}
	The equations of motion for this Lagrangian, with $ V(r) = -V_0 e^{-\lambda^2 r^2} $, are,
	\begin{align*}
	m r^2 \dot{\theta} &= constant = L_0 \qq{and}\\
	m \ddot{r} &= m r \dot{\theta}^2 + (2 \lambda^2 r) V(r)\\
	\implies m\ddot{r}&= \dfrac{L_0^2}{m r^3} + (2 \lambda^2 r) V(r)
	\end{align*}
	For stable circular orbit, $ \dot{r} = \ddot{r} = 0 $. Let $ r_0 $ be radius of stable circular orbit. We can see that $ r_0 $ will be given by the root of the equation,
	\begin{equation*}
	\dfrac{L_0^2}{m r_0^3} - 2 \lambda^2 r_0 V_0 e^{-\lambda^2 r_0^2} = 0\\
	\implies {L_0^2} = 2 \lambda^2 m r_0^4 V_0 e^{-\lambda^2 r_0^2}
	\end{equation*}
	Note that $ L_0^2 $ has a functional dependence on $ r_0 $ $ (\sim r_0^4 e^{-\lambda^2 r_0^2}) $. This functional dependence has a maxima at $ r_0^2 = \dfrac{2}{\lambda^2} $, where the value of the function is $\dfrac{4}{\lambda^2 e^2}$. $ L_0^2 $ should be lesser than this maximum value for it to be realizable. Hence,
	\begin{equation*}
	L_0^2 \le \dfrac{8mV_0}{e^2} \implies L_0 \le \dfrac{\sqrt{8mV_0}}{e}
	\end{equation*}

	So, $ L_0 $ cannot exceed $ \dfrac{\sqrt{8mV_0}}{e} $.

\end{homeworkProblem}

\begin{homeworkProblem}[7]
	The radius of the circle $ r $ and the angle covered around the circle $ \theta $ are the generalized coordinates. The Cartesian coordinates of the particle are,
	\begin{equation*}
	x = r \cos \theta, y = r \sin \theta, z = r \cot \alpha \implies v^2 = \dot{r}^2 \csc^2 \alpha + r^2 \dot{\theta}^2
	\end{equation*}The Lagrangian $ L $ can be written as,
	\begin{equation*}
	L =  \dfrac{m (\dot{r}^2 \csc^2 \alpha + r^2 \dot{\theta}^2)}{2}- mg r \cot \alpha
	\end{equation*}
	The equations of motion are,
	\begin{align*}
	r^2 \dot{\theta} &= constant = L_0\\
	\ddot{r}\csc^2 \alpha &= r\dot{\theta}^2 - g\cot \alpha \implies \ddot{r} \csc^2 \alpha = \dfrac{L_0^2}{r^3} - g\cot \alpha
	\end{align*}

	\textbf{Part (b)}\\
	If $ r = r_0 $, $ \ddot{r} =0 $ and,
	\begin{equation*}
	L_0^2 = r_0^4 \omega^2 =   g r_0^3 \cot \alpha \implies \boxed{\omega = \sqrt{\frac{g \cot \alpha}{r_0}}} \implies L_0 = r_0^3 g \cot \alpha
	\end{equation*}

	\textbf{Part (c)}\\

	We consider perturbations along the surface of the cone ie $ l = r_0 \csc \alpha + \epsilon x $. This in turn corresponds to a radial perturbation of the form $ r = r_0 + \epsilon x \sin \alpha $, $ \epsilon \ll 1 $. Substituting this into the equation of motion for $ r $,
	\begin{align*}
	\epsilon \ddot{x} \csc \alpha &= \dfrac{L_0^2}{(r_0 + \epsilon x \sin \alpha)^3} - g \cot \alpha\\
	&=\dfrac{L_0^2}{r_0^3}\qty(1 - \dfrac{3 \epsilon x \sin \alpha}{r_0} + \ldots) - g \cot \alpha\\
	\epsilon \ddot{x} \csc \alpha &=\dfrac{L_0^2}{r_0^3}\qty(- \dfrac{3 \epsilon x \sin \alpha}{r_0} + \ldots) \\
	\end{align*}
	Choosing only the term first order in $ \epsilon $,
	\begin{equation*}
	\ddot{x} = -\dfrac{3 g \cot \alpha}{r_0}(\sin^2 \alpha) x \implies \boxed{\Omega = \sqrt{\dfrac{3 g \cot \alpha	}{r_0}}\sin \alpha}
	\end{equation*}
	For $ \Omega = \omega $, we can see that,
	\begin{equation*}
	\sin \alpha = \dfrac{1}{\sqrt{3}} \implies \alpha = \sin[-1](\dfrac{1}{\sqrt{3}})
	\end{equation*}
\end{homeworkProblem}

\begin{homeworkProblem}[8]
	Let $ \theta_1 $ and $ \theta_2 $ be the angles that the sticks make with the vertical. Each stick is of length $ 2r $. $ \theta_1 $ (lower stick) and $ \theta_2 $ (upper stick) are the generalized coordinates. The position coordinates of the lower and upper masses are,
	\begin{equation*}
	(x_1,y_1) = (r \sin \theta_1, r \cos \theta_1) \qq{and} (x_2,y_2) = (2r \sin \theta_1 + r \sin \theta_2, 2r \cos \theta_1 + r \cos \theta_2)
	\end{equation*}
	\begin{equation*}
	\implies v_1^2 = r^2 \dot{\theta}_1^2 \qq{and} v_2^2 = 4r^2 \dot{\theta}_1^2 + r^2 \dot{\theta}_2^2 + 4r^2 \cos (\theta_1 - \theta_2) \dot{\theta}_1 \dot{\theta}_2
	\end{equation*}

	The Lagrangian can be written as,
	\begin{equation*}
	L = \dfrac{ mr^2 }{2}\dot{\theta}_1^2 + \dfrac{ m(4r^2 \dot{\theta}_1^2 + r^2 \dot{\theta}_2^2 + 4r^2 \cos (\theta_1 - \theta_2) \dot{\theta}_1 \dot{\theta}_2) }{2} - mgr \cos \theta_1 - mg (2r\cos \theta_1 + r \cos \theta_2)
	\end{equation*}
	The equations of motion are,
	\begin{align*}
	mr^2 \ddot{\theta}_1 + 4mr^2 \ddot{\theta}_1 + 2mr^2 \cos (\theta_1 - \theta_2) \ddot{\theta}_2 +  2mr^2 \cos (\theta_1 - \theta_2) \dot{\theta}_2 (\dot{\theta}_2 - \dot{\theta}_1)  =\\ - 2mr^2 \sin (\theta_1 - \theta_2)\dot{\theta}_1 \dot{\theta}_2 + mgr\sin \theta_1 + 2mgr \sin \theta_1
	\end{align*}
	\begin{equation*}
	mr^2 \ddot{\theta}_2 + 2mr^2 \cos (\theta_1 - \theta_2) \ddot{\theta}_1 +  2mr^2 \cos (\theta_1 - \theta_2) \dot{\theta}_1 (\dot{\theta}_2 - \dot{\theta}_1) = 2mr^2 \sin (\theta_1 - \theta_2)\dot{\theta}_1 \dot{\theta}_2 + mgr \sin \theta_2
	\end{equation*}
	In the above equations of motion, we substitute, $ \theta_1 = 0, \theta_2 = \epsilon \ll 1, \dot{\theta}_1 = \dot{\theta}_2 = 0 $,
	\begin{align*}
	5mr^2 \ddot{\theta}_1 + 2mr^2 \ddot{\theta}_2  &= 0 \qq{and}\\
	mr^2 \ddot{\theta}_2 + 2mr^2 \ddot{\theta}_1 &= mgr  \epsilon
	\end{align*}
	\begin{equation*}
	\boxed{\ddot{\theta}_1 = -\dfrac{2g \epsilon}{r} \qq{and} \ddot{\theta}_2 = \dfrac{5g \epsilon}{r}}
	\end{equation*}
\end{homeworkProblem}

\end{document}


\subsection{Six-class Single-moment Bulk Scheme (Tomita 2008)}
Six-class single-moment bulk scheme in the SCALE was developed by \citet{tomita_2008}.
This scheme predicts mass exchange among six categories of water substances (water vapor, cloud water, rain, cloud ice, snow, and graupel), which is largely based on the method of \citet{lin_etal_1983}.
However, there are some modifications from the original method of \citet{lin_etal_1983}: Both cloud water and cloud ice are generated only by a saturation adjustment process, and wet growth process of graupel is omitted.
According to \citet{tomita_2008}, these modifications result in 20\% reduction in computational cost compared to \citet{lin_etal_1983} without significant changes on physical performance.
In this subsection, the formulations of the microphysical scheme of \citet{tomita_2008} are described.
Mass concentrations of water vapor, cloud water, rain, cloud ice, snow, and graupel are indicated by $q_{v}$, $Q_{W}$, $Q_{R}$, $Q_{I}$, $Q_{S}$, and $Q_{G}$ respectively.

In \citet{tomita_2008}, cloud microphysics processes except for the saturation adjustment process consist of auto-conversion, accretion, evaporation, sublimation, deposition, melting, freezing, and Bergeron process. When $T < T_{0}$ (= 273.15 K), the tendency of each water substance by these processes can be written as follows:
\begin{align}
  \frac{\partial Q_{W}}{\partial t} &= -P_{RAUT}-P_{RACW}-P_{SACW}-P_{GACW}-P_{SFW}, \\
  \frac{\partial Q_{I}}{\partial t} &= -P_{SAUT}-P_{RACI}-P_{SACI}-P_{GACI}-P_{SFI}, \\
  \frac{\partial Q_{R}}{\partial t} &= P_{RAUT}+P_{RACW}-P_{IACR}-P_{SACR}-P_{GACR}-P_{GFRZ}-P_{REVP}, \\
  \frac{\partial Q_{S}}{\partial t} &= P_{SAUT}-P_{GAUT} \nonumber \\
  &+P_{SACW}+P_{SACI}+(1-\delta_{1})P_{RACI}+(1-\delta_{1})P_{IACR}+\delta_{2}P_{SACR}-(1-\delta_{2})P_{RACS}-P_{GACS} \nonumber \\
  &-(1-\delta_{3})P_{SSUB}+\delta_{3}P_{SDEP}+P_{SFW}+P_{SFI}, \\
  \frac{\partial Q_{G}}{\partial t} &= P_{GAUT} \nonumber \\
  &+P_{GACW}+P_{GACI}+P_{GACR}+P_{GACS}+\delta_{1}P_{RACI}+\delta_{1}P_{IACR}+(1-\delta_{2})P_{SACR}+(1-\delta_{2})P_{RACS} \nonumber \\
  &-(1-\delta_{3})P_{GSUB}+\delta_{3}P_{GDEP}+P_{GFRZ}, \\
  \frac{\partial q_{v}}{\partial t} &= P_{REVP}+(1-\delta_{3})P_{SSUB}+(1-\delta_{3})P_{GSUB}-\delta_{3}P_{SDEP}-\delta_{3}P_{GDEP},
\end{align}
where $P_{*}$ in the right hand sides are conversion terms listed in Table \ref{table-tomita08-1}, and $\delta_{1}$, $\delta_{2}$, and $\delta_{3}$ are defined as
\begin{align}
\delta_{1} &=
\begin{cases}
  1, &{\rm for\ } Q_{R} \geq 10^{-4} {\rm \ kg/kg}\\
  0, &{\rm otherwise}\\
\end{cases},
\\
\delta_{2} &=
\begin{cases}
  1, &{\rm for\ } Q_{R} \leq 10^{-4} {\rm \ kg/kg\ and\ } Q_{S} \leq 10^{-4} {\rm \ kg/kg}\\
  0, &{\rm otherwise}\\
\end{cases},
\\
\delta_{3} &=
\begin{cases}
  1, &{\rm for\ } S_{ice} \geq 1\\
  0, &{\rm otherwise}\\
\end{cases},
\end{align}
where $S_{ice}$ is saturation ratio over ice. When $T \geq T_{0}$, the tendencies of each water substance can be written as follows:
\begin{align}
  \frac{\partial Q_{W}}{\partial t} &= -P_{RAUT}-P_{RACW}-P_{SACW}-P_{GACW}, \\
  \frac{\partial Q_{I}}{\partial t} &= 0, \\
  \frac{\partial Q_{R}}{\partial t} &= P_{RAUT}+P_{RACW}+P_{SACW}+P_{GACW}+P_{SMLT}+P_{GMLT}-P_{REVP}, \\
  \frac{\partial Q_{S}}{\partial t} &= -P_{GACS}-P_{SMLT}, \\
  \frac{\partial Q_{G}}{\partial t} &= P_{GACS}-P_{GMLT}, \\
  \frac{\partial q_{v}}{\partial t} &= P_{REVP}.
\end{align}
Formulation of each term is described later.
\begin{table}[tbh]
\begin{center}
\caption{List of conversion terms used in six-class single-moment bulk scheme of \citet{tomita_2008}}
\label{table-tomita08-1}
\scalebox{0.7}{
\begin{tabular}{llll}
\hline
Notation&Description&Direction&Conditions \\ \hline \hline
$P_{RAUT}$&Auto-conversion rate of cloud water to form rain&$Q_{W} \longrightarrow Q_{R}$& \\ \hline
$P_{SAUT}$&Auto-conversion rate of cloud ice to form snow&$Q_{I} \longrightarrow Q_{S}$&$T < T_{0}$ \\ \hline
$P_{GAUT}$&Auto-conversion rate of snow to form graupel&$Q_{S} \longrightarrow Q_{G}$&$T < T_{0}$ \\ \hline
$P_{RACW}$&Accretion rate of cloud water by rain&$Q_{W} \longrightarrow Q_{R}$& \\ \hline
$P_{SACW}$&Accretion rate of cloud water by snow&$Q_{W} \longrightarrow Q_{S}$&$T < T_{0}$ \\
&&$Q_{W} \longrightarrow Q_{R}$&$T \geq T_{0}$ \\ \hline
$P_{GACW}$&Accretion rate of cloud water by graupel&$Q_{W} \longrightarrow Q_{G}$&$T < T_{0}$ \\
&&$Q_{W} \longrightarrow Q_{R}$&$T \geq T_{0}$ \\ \hline
$P_{RACI}$&Accretion rate of cloud ice by rain&$Q_{I} \longrightarrow Q_{S}$&$T < T_{0}$ and $Q_{R} < 10^{-4}$ kg/kg \\
&&$Q_{I} \longrightarrow Q_{G}$&$T < T_{0}$ and $Q_{R} \geq 10^{-4}$ kg/kg \\ \hline
$P_{SACI}$&Accretion rate of cloud ice by snow&$Q_{I} \longrightarrow Q_{S}$&$T < T_{0}$ \\ \hline
$P_{GACI}$&Accretion rate of cloud ice by graupel&$Q_{I} \longrightarrow Q_{G}$&$T < T_{0}$ \\ \hline
$P_{IACR}$&Accretion rate of rain by cloud ice&$Q_{R} \longrightarrow Q_{S}$&$T < T_{0}$ and $Q_{R} < 10^{-4}$ kg/kg \\
&&$Q_{R} \longrightarrow Q_{G}$&$T < T_{0}$ and $Q_{R} \geq 10^{-4}$ kg/kg \\ \hline
$P_{SACR}$&Accretion rate of rain by snow&$Q_{R} \longrightarrow Q_{S}$&$T < T_{0}$, $Q_{R} \leq 10^{-4}$ kg/kg, and $Q_{S} \leq 10^{-4}$ kg/kg \\
&&$Q_{R} \longrightarrow Q_{G}$&$T < T_{0}$ and ($Q_{R}$ or $Q_{S}$) $> 10^{-4}$ kg/kg \\ \hline
$P_{GACR}$&Accretion rate of rain by graupel&$Q_{R} \longrightarrow Q_{G}$&$T < T_{0}$ \\ \hline
$P_{RACS}$&Accretion rate of snow by rain&$Q_{S} \longrightarrow Q_{G}$&$T < T_{0}$ and ($Q_{R}$ or $Q_{S}$) $> 10^{-4}$ kg/kg \\ \hline
$P_{GACS}$&Accretion rate of snow by graupel&$Q_{S} \longrightarrow Q_{G}$& \\ \hline
$P_{REVP}$&Evaporation rate of rain&$Q_{R} \longrightarrow q_{v}$& \\ \hline
$P_{SSUB}$&Sublimation rate of snow&$Q_{S} \longrightarrow q_{v}$&$S_{ice} < 1$ \\ \hline
$P_{GSUB}$&Sublimation rate of graupel&$Q_{G} \longrightarrow q_{v}$&$S_{ice} < 1$ \\ \hline
$P_{SDEP}$&Deposition rate of water vapor for snow&$q_{v} \longrightarrow Q_{S}$&$S_{ice} \geq 1$ \\ \hline
$P_{GDEP}$&Deposition rate of water vapor for graupel&$q_{v} \longrightarrow Q_{G}$&$S_{ice} \geq 1$ \\ \hline
$P_{SMLT}$&Melting rate of snow&$Q_{S} \longrightarrow Q_{R}$&$T \geq T_{0}$ \\ \hline
$P_{GMLT}$&Melting rate of graupel&$Q_{G} \longrightarrow Q_{R}$&$T \geq T_{0}$ \\ \hline
$P_{GFRZ}$&Freezing rate of rain to form graupel&$Q_{R} \longrightarrow Q_{G}$&$T < T_{0}$ \\ \hline
$P_{SFW}$&Growth rate of snow by Bergeron process from cloud water&$Q_{W} \longrightarrow Q_{S}$& 243.15 K $\leq T < T_{0}$ \\ \hline
$P_{SFI}$&Growth rate of snow by Bergeron process from cloud ice&$Q_{I} \longrightarrow Q_{S}$& 243.15 K $\leq T < T_{0}$ \\ \hline
\end{tabular}
}
\end{center}
\end{table}

\subsubsection{The saturation adjustment}
Mass exchange among water vapor, cloud water, and cloud ice is controlled by the saturation adjustment.
In the SCALE, the saturation adjustment is calculated after the aforementioned conversion processes of the microphysics.
To calculate the adjustment process, saturated mass concentration of water vapor is defined as follows:
\begin{equation}
  q^{*}_{v}(T) = q^{*}_{vl}(T)+[1-\alpha (T)]q^{*}_{vi}(T)\label{eq:satuqv},
\end{equation}
where $q^{*}_{vl}(T)$ is saturated mass concentration of water vapor against liquid phase, $q^{*}_{vi}(T)$ is that for ice phase, and $\alpha (T)$ is a continuous function which satisfies
\begin{align}
\begin{cases}
  \alpha (T) = 1, & {\rm \ for\ } T \geq {\rm \ 273.15 \ K} ,\\
  \alpha (T) = \frac{T-233.15}{40.0}, & {\rm \ for\ 233.15\ K \ } < T < {\rm \ 273.15 \ K},\\
  \alpha (T) = 0, & {\rm \ for\ } T \leq {\rm \ 233.15 \ K}.
\end{cases}
\end{align}
If it is supersaturated, water vapor is converted into cloud water and cloud ice.
If it is unsaturated, cloud water and cloud ice are converted into water vapor.
As a conserved quantity for the adjustment process, the moist internal energy is also defined as follows:
\begin{align}
  U_{0}&=[q_{d}c_{vd}+q_{v}c_{vv}+(Q_{W}+Q_{R})c_{l}+(Q_{I}+Q_{S}+Q_{G})c_{s}]T \nonumber \\
  &+q_{v}L_{v}-(Q_{I}+Q_{S}+Q_{G})L_{f},
\end{align}
where $L_{v}$ is the latent heat between water vapor and liquid water, $L_{f}$ is that between liquid water and solid water. In addition, the sum of the mass concentration of water vapor, cloud water, and cloud ice
\begin{equation}
  q_{sum}=q_{v}+Q_{W}+Q_{I},
\end{equation}
does not change through the saturation adjustment.

First, it is assumed that all of the cloud water $Q_{W}$ and cloud ice $Q_{I}$ evaporate.
In this case, the mass concentration of water vapor becomes equal to $q_{sum}$ and the temperature decreases due to the evaporation.
The moist internal energy can be written as
\begin{align}
  U_{1}&=[q_{d}c_{vd}+q_{sum}c_{vv}+Q_{R}c_{l}+(Q_{S}+Q_{G})c_{s}]T_{1} \nonumber \\
  &+q_{sum}L_{v}-(Q_{S}+Q_{G})L_{f}.
\end{align}
Since the moist internal energy does not change through the saturation adjustment, we can obtain the new temperature value $T_{1}$ easily by solving $U_{0}=U_{1}$. Then, if $q_{sum}$ is less than saturated mass concentration of water vapor at this temperature (i.e. $q_{sum}<q^{*}_{v} (T_{1})$), no saturation occurs and the new values of water vapor $q^{\prime}_{v}$, cloud water $Q^{\prime}_{W}$, cloud ice $Q^{\prime}_{I}$, and temperature $T^{\prime}$ are determined as
\begin{align}
\begin{cases}
  q^{\prime}_{v} &= q_{sum}, \\
  Q^{\prime}_{W} &= 0, \\
  Q^{\prime}_{I} &= 0, \\
  T^{\prime} &= T_{1}.
\end{cases}
\end{align}

If $q_{sum}$ exceeds $q^{*}_{v} (T_{1})$, saturation occurs. In this case, new temperature value $T_{2}$ should be determined by satisfying the equations of
\begin{align}
  U_{0}&=[q_{d}c_{vd}+q^{*}_{v}(T_{2})c_{vv}+(Q_{W2}+Q_{R})c_{l}+(Q_{I2}+Q_{S}+Q_{G})c_{s}]T_{2} \nonumber \\
  &+q^{*}_{v}(T_{2})L_{v}-(Q_{I2}+Q_{S}+Q_{G})L_{f}\label{eq:newu}, \\
  Q_{W2}&=[q_{sum}-q^{*}_{v}(T_{2})]\alpha (T_{2})\label{eq:newqw}, \\
  Q_{I2}&=[q_{sum}-q^{*}_{v}(T_{2})](1-\alpha (T_{2}))\label{eq:newqi}.
\end{align}
Eqs. (\ref{eq:satuqv}) and (\ref{eq:newu}-\ref{eq:newqi}) are solved numerically and the new values are determined as
\begin{align}
\begin{cases}
  q^{\prime}_{v} &= q^{*}_{v}(T_{2}), \\
  Q^{\prime}_{W} &= Q_{W2}, \\
  Q^{\prime}_{I} &= Q_{I2}, \\
  T^{\prime} &= T_{2}.
\end{cases}
\end{align}

\subsubsection{Fundamental characteristics of precipitation particles}
In the reminder of this subsection, the formulations of all conversion terms listed in Table \ref{table-tomita08-1} are shown.
Before that, however, it is necessary to clarify assumptions about the characteristics of precipitation particles (rain, snow, and graupel).
In \citet{tomita_2008}, it is assumed that seizes of precipitation particles obey the Marshall-Palmer exponential size distribution:
\begin{equation}
  n_{[R,S,G]}(D) = N_{0[R,S,G]}\exp(-\lambda_{[R,S,G]}D)\label{eq:size_dist},
\end{equation}
where $D$ is the diameter of particle, $N_{0}$ is an intercept parameter, and $\lambda$ is a slope parameter. The subscriptions of $R$, $S$, and $G$ denote rain, snow, and graupel, respectively. In the SCALE, each intercept parameter has values of
\begin{align}
\begin{cases}
  N_{0R}&=8.0\times 10^{6}{\rm \ m^{-4}}, \\
  N_{0S}&=3.0\times 10^{6}{\rm \ m^{-4}}, \\
  N_{0G}&=4.0\times 10^{6}{\rm \ m^{-4}}.
\end{cases}
\end{align}
The mass and terminal velocity of each particle are described as
\begin{align}
  m_{[R,S,G]}(D) &= a_{[R,S,G]}D^{b_{[R,S,G]}}\label{eq:particle_mass} \\
  v_{t[R,S,G]}(D) &= c_{[R,S,G]}D^{d_{[R,S,G]}}\left(\frac{\rho_{0}}{\rho}\right)^{1/2}
\end{align}
where $\rho_{0}$ ($=1.28\rm \ kg/m^{3}$) is a reference density, and $a$, $b$, $c$, and $d$ are coefficients depending on the particle shape. All precipitation particles are treated as spherical, thus
\begin{align}
  &a_{R}=\pi \rho_{w}/6,\quad a_{S}=\pi \rho_{S}/6,\quad a_{G}=\pi \rho_{G}/6, \\
  &b_{R}=b_{S}=b_{G}=3,
\end{align}
where $\rho_{w}=1000 {\rm \ kg/m^{3}}$, $\rho_{S}=100 {\rm \ kg/m^{3}}$, $\rho_{G}=400 {\rm \ kg/m^{3}}$. The coefficients $c$ and $d$ are determined empirically. In the SCALE, their values are
\begin{align}
  c_{R}=130.0,\quad c_{S}=4.84,\quad c_{G}=82.5, \\
  d_{R}=0.5,\quad d_{S}=0.25,\quad d_{G}=0.5,
\end{align}
The slope parameters are determined from Eqs. (\ref{eq:size_dist}) and (\ref{eq:particle_mass}) as
\begin{equation}
  \lambda=\left[\frac{aN_{0}\Gamma (b+1)}{\rho Q}\right]^{1/(b+1)}\label{eq:lambda},
\end{equation}
where $\Gamma$ is the gamma function. The bulk terminal velocities are derived as
\begin{equation}
  V_{T}=c\left(\frac{\rho_{0}}{\rho}\right)^{1/2}\frac{\Gamma(b+d+1)}{\Gamma(b+1)\lambda^{d}}\label{eq:tvelocity}.
\end{equation}
Note that subscription $R$, $S$, and $G$ in Eqs. (\ref{eq:lambda}) and (\ref{eq:tvelocity}) are omitted for simplicity.

\subsubsection{Auto-conversion terms}
The auto-conversion rate of cloud water to form rain ($P_{RAUT}$) is given as
\begin{equation}
  P_{RAUT}=\frac{1}{\rho}\left[16.7\times(\rho Q_{W})^{2}\left(5+\frac{3.6\times10^{-5}N_{d}}{D_{d}\rho Q_{W}}\right)^{-1}\right],
\end{equation}
where $N_{d}$ is the number concentration of cloud water ($N_{d}=50 {\rm \ cm^{-3}}$ in the SCALE) and $D_{d}$ is given as
\begin{equation}
  D_{d}=0.146-5.964\times10^{-2}\ln{\frac{N_{d}}{2000}}.
\end{equation}
The auto-conversion rate of cloud ice to form snow ($P_{SAUT}$) is given as
\begin{equation}
  P_{SAUT}=\beta_{1}(Q_{I}-Q_{I0}),
\end{equation}
where $Q_{I0}$ is set to 0 kg/kg and $\beta_{1}$ is formulated as
\begin{equation}
  \beta_{1}=\beta_{10}\exp[\gamma_{SAUT}(T-T_{0})].
\end{equation}
$\beta_{10}$ and $\gamma_{SAUT}$ are set to 0.001 and 0.025, respectively, in \citet{tomita_2008}. In the SCALE, however, they are set to 0.006 and 0.06 as default settings. The auto-conversion rate of snow to form graupel ($P_{GAUT}$) is given as
\begin{equation}
  P_{GAUT}=\beta_{2}(Q_{S}-Q_{S0}),
\end{equation}
where $Q_{S0}$ is set to $6\times10^{-4}$ kg/kg and $\beta_{2}$ is formulated as
\begin{equation}
  \beta_{2}=\beta_{20}\exp[\gamma_{GAUT}(T-T_{0})].
\end{equation}
$\beta_{20}$ and $\gamma_{GAUT}$ are set to 0.001 and 0.09, respectively, in \citet{tomita_2008}. In the SCALE, however, $\beta_{20} = 0$ as a default setting, which means that auto-conversion of snow to graupel is turned off.

\subsubsection{Accretion terms}
Accretion of cloud particles by precipitation particles ($P_{RACW}$, $P_{SACW}$, $P_{GACW}$, $P_{RACI}$, $P_{SACI}$, and $P_{GACI}$) can be derived as
\begin{align}
  P_{RACW} &=E_{RW}Q_{W}\int_{0}^{\infty}\frac{\pi}{4}D^{2}v_{tR}(D)n_{R}(D)dD \nonumber \\
  &=\frac{\pi E_{RW}N_{0R}c_{R}Q_{W}\Gamma(3+d_{R})}{4\lambda^{3+d_{R}}_{R}}\left(\frac{\rho_{0}}{\rho}\right)^{1/2}, \\
  P_{SACW} &=\frac{\pi E_{SW}N_{0S}c_{S}Q_{W}\Gamma(3+d_{S})}{4\lambda^{3+d_{S}}_{S}}\left(\frac{\rho_{0}}{\rho}\right)^{1/2}, \\
  P_{GACW} &=\frac{\pi E_{GW}N_{0G}c_{G}Q_{W}\Gamma(3+d_{G})}{4\lambda^{3+d_{G}}_{G}}\left(\frac{\rho_{0}}{\rho}\right)^{1/2}, \\
  P_{RACI} &=\frac{\pi E_{RI}N_{0R}c_{R}Q_{I}\Gamma(3+d_{R})}{4\lambda^{3+d_{R}}_{R}}\left(\frac{\rho_{0}}{\rho}\right)^{1/2}, \\
  P_{SACI} &=\frac{\pi E_{SI}N_{0S}c_{S}Q_{I}\Gamma(3+d_{S})}{4\lambda^{3+d_{S}}_{S}}\left(\frac{\rho_{0}}{\rho}\right)^{1/2}, \\
  P_{GACI} &=\frac{\pi E_{GI}N_{0G}c_{G}Q_{I}\Gamma(3+d_{G})}{4\lambda^{3+d_{G}}_{G}}\left(\frac{\rho_{0}}{\rho}\right)^{1/2},
\end{align}
where $E_{RW}$, $E_{SW}$, $E_{GW}$, $E_{RI}$, $E_{SI}$, and $E_{GI}$ are collection efficiency of each accretion process. In the SCALE, $E_{RW} = E_{SW} = E_{GW} = E_{RI} = 1$, $E_{GI} = 0.1$, and $E_{SI}$ is formulated as
\begin{equation}
  E_{SI}=\exp[\gamma_{SACI}(T-T_{0})],
\end{equation}
where $\gamma_{SACI}$ is set to 0.025.
When the accretion of cloud ice by rain occurs, rain freezes to become snow or graupel.
Thus, the conversion term from rain to these particles ($P_{IACR}$) should be considered.
It is derived as
\begin{align}
  P_{IACR}&=\frac{1}{\rho}\int_{0}^{\infty}N_{I}E_{RI}\frac{\pi}{4}D^{2}v_{tR}(D)m_{R}(D)n_{R}(D)dD \nonumber \\
  &=\frac{\pi a_{R}E_{RI}Q_{I}N_{0R}c_{R}\Gamma(6+d_{R})}{4M_{I}\lambda^{6+d_{R}}_{R}}\left(\frac{\rho_{0}}{\rho}\right)^{1/2},
\end{align}
where $N_{I}$ is the number concentration of cloud ice, and $M_{I}$ ($=4.19\times10^{-13}$ kg) is mass of cloud ice particle.

Accretion of precipitation particles ($P_{SACR}$, $P_{GACR}$, and $P_{GACS}$) can be derived as
\begin{align}
  P_{SACR}&= \frac{1}{\rho}\int_{0}^{\infty}E_{SR}m_{R}(D_{R})n_{R}(D_{R})\left[\int_{0}^{\infty}\frac{\pi}{4}(D_{S}+D_{R})^{2}|V_{TS}-V_{TR}|n_{S}(D_{S})dD_{S}\right]dD_{R} \nonumber \\
  &=\frac{\pi a_{R}|V_{TS}-V_{TR}|E_{SR}N_{0S}N_{0R}}{4\rho} \nonumber \\
  &\times\left[\frac{\Gamma(b_{R}+1)\Gamma(3)}{\lambda^{b_{R}+1}_{R}\lambda^{3}_{S}}+2\frac{\Gamma(b_{R}+2)\Gamma(2)}{\lambda^{b_{R}+2}_{R}\lambda^{2}_{S}}+\frac{\Gamma(b_{R}+3)\Gamma(1)}{\lambda^{b_{R}+3}_{R}\lambda_{S}}\right], \\
  P_{GACR}&=\frac{\pi a_{R}|V_{TG}-V_{TR}|E_{GR}N_{0G}N_{0R}}{4\rho} \nonumber \\
  &\times\left[\frac{\Gamma(b_{R}+1)\Gamma(3)}{\lambda^{b_{R}+1}_{R}\lambda^{3}_{G}}+2\frac{\Gamma(b_{R}+2)\Gamma(2)}{\lambda^{b_{R}+2}_{R}\lambda^{2}_{G}}+\frac{\Gamma(b_{R}+3)\Gamma(1)}{\lambda^{b_{R}+3}_{R}\lambda_{G}}\right], \\
  P_{GACS}&=\frac{\pi a_{S}|V_{TG}-V_{TS}|E_{GS}N_{0G}N_{0S}}{4\rho} \nonumber \\
  &\times\left[\frac{\Gamma(b_{S}+1)\Gamma(3)}{\lambda^{b_{S}+1}_{S}\lambda^{3}_{G}}+2\frac{\Gamma(b_{S}+2)\Gamma(2)}{\lambda^{b_{S}+2}_{S}\lambda^{2}_{G}}+\frac{\Gamma(b_{S}+3)\Gamma(1)}{\lambda^{b_{S}+3}_{S}\lambda_{G}}\right],
\end{align}
where $E_{SR}$, $E_{GR}$, and $E_{GS}$ are collection efficiency of each accretion process. Note that terminal velocity for each particle size is approximated by the bulk terminal velocity (e.g. $|v_{tS}(D_{S})-v_{tR}(D_{R})| \simeq |V_{TS}-V_{TR}|$). In the SCALE, $E_{SR} = E_{GR} = 1$, and $E_{GS}$ is formulated as
\begin{equation}
  E_{GS}=\min(1,\exp[\gamma_{GACS}(T-T_{0})]),
\end{equation}
where $\gamma_{GACS}$ is set to 0.09.
When the accretion of rain by snow occurs under the condition of $Q_{R} > 10^{-4}$ kg/kg or $Q_{S} > 10^{-4}$ kg/kg, graupel particle is generated.
Thus, the conversion term from snow to graupel ($P_{RACS}$) should be also considered.
It can be written as
\begin{align}
  P_{RACS}&=\frac{\pi a_{S}|V_{TR}-V_{TS}|E_{SR}N_{0R}N_{0S}}{4\rho} \nonumber \\
  &\times\left[\frac{\Gamma(b_{S}+1)\Gamma(3)}{\lambda^{b_{S}+1}_{S}\lambda^{3}_{R}}+2\frac{\Gamma(b_{S}+2)\Gamma(2)}{\lambda^{b_{S}+2}_{S}\lambda^{2}_{R}}+\frac{\Gamma(b_{S}+3)\Gamma(1)}{\lambda^{b_{S}+3}_{S}\lambda_{R}}\right].
\end{align}

\subsubsection{Evaporation, sublimation, and deposition}
Evaporation rate of rain ($P_{REVP}$) is described as
\begin{align}
  P_{REVP}&=\frac{2\pi N_{0R}(1-\min(S_{liq},1))G_{w}(T)}{\rho} \nonumber \\
  &\times\left[f_{1R}\frac{\Gamma(2)}{\lambda^{2}_{R}}+f_{2R}c^{1/2}_{R}\left(\frac{\rho_{0}}{\rho}\right)^{1/4}\nu^{-1/2}\frac{\Gamma(\frac{5+d_{R}}{2})}{\lambda^{\frac{5+d_{R}}{2}}_{R}}\right],
\end{align}
where $S_{liq}$ is saturation ratio over liquid, coefficients $f_{1R}$ and $f_{2R}$ are 0.78 and 0.27 respectively, $\nu$ is the kinematic viscosity of air, and $G_{w}(T)$ is the thermodynamic function for liquid water given as
\begin{equation}
  G_{w}(T)=\left[\frac{L_{v}}{K_{a}T}\left(\frac{L_{v}}{R_{v}T}-1\right)+\frac{1}{\rho q^{*}_{vl}(T)K_{d}}\right]^{-1},
\end{equation}
where $K_{a}$ is the thermal diffusion coefficient of air and $K_{d}$ is the diffusion coefficient of water vapor in air. $P_{REVP}$ works only when $S_{liq}$ is less than 1 (i.e. unsaturated condition).

Sublimation and deposition rates for snow ($P_{SSUB}$ and $P_{SDEP}$) are described by the same equation:
\begin{align}
  P^{*}_{SSUB,SDEP}&=\frac{2\pi N_{0S}(1-S_{ice})G_{i}(T)}{\rho} \nonumber \\
  &\times\left[f_{1S}\frac{\Gamma(2)}{\lambda^{2}_{S}}+f_{2S}c^{1/2}_{S}\left(\frac{\rho_{0}}{\rho}\right)^{1/4}\nu^{-1/2}\frac{\Gamma(\frac{5+d_{S}}{2})}{\lambda^{\frac{5+d_{S}}{2}}_{S}}\right],
\end{align}
where coefficients $f_{1S}$ and $f_{2S}$ are 0.65 and 0.39 respectively, and $G_{i}(T)$ is the thermodynamic function for ice water given as
\begin{equation}
  G_{i}(T)=\left[\frac{L_{s}}{K_{a}T}\left(\frac{L_{s}}{R_{v}T}-1\right)+\frac{1}{\rho q^{*}_{vi}(T)K_{d}}\right]^{-1},
\end{equation}
where $L_{s}$ is the latent heat between water vapor and solid water. If it is unsaturated ($S_{ice} < 1$), the sublimation rate of snow is given as
\begin{equation}
  P_{SSUB}=P^{*}_{SSUB,SDEP}.
\end{equation}
If it is supersaturated ($S_{ice} \geq 1$), the deposition rate of water vapor for snow is given as
\begin{equation}
  P_{SDEP}=-P^{*}_{SSUB,SDEP}.
\end{equation}
Also sublimation and deposition rates for graupel ($P_{GSUB}$ and $P_{GDEP}$) are described by
\begin{align}
  P^{*}_{GSUB,GDEP}&=\frac{2\pi N_{0G}(1-S_{ice})G_{i}(T)}{\rho} \nonumber \\
  &\times\left[f_{1G}\frac{\Gamma(2)}{\lambda^{2}_{G}}+f_{2G}c^{1/2}_{G}\left(\frac{\rho_{0}}{\rho}\right)^{1/4}\nu^{-1/2}\frac{\Gamma(\frac{5+d_{G}}{2})}{\lambda^{\frac{5+d_{G}}{2}}_{G}}\right],
\end{align}
where coefficients $f_{1G}$ and $f_{2G}$ are 0.78 and 0.27 respectively. If it is unsaturated ($S_{ice} < 1$), the sublimation rate of graupel is given as
\begin{equation}
  P_{GSUB}=P^{*}_{GSUB,GDEP}.
\end{equation}
If it is supersaturated ($S_{ice} \geq 1$), the deposition rate of water vapor for graupel is given as
\begin{equation}
  P_{GDEP}=-P^{*}_{GSUB,GDEP}.
\end{equation}

\subsubsection{Melting and freezing}
When $T \geq T_{0}$, snow particle melts to become rain. The melting rate of snow is described as
\begin{align}
  P_{SMLT}&=\frac{2\pi K_{a}(T-T_{0})N_{0S}}{\rho L_{f}} \nonumber \\
  &\times\left[f_{1S}\frac{\Gamma(2)}{\lambda^{2}_{S}}+f_{2S}c^{1/2}_{S}\left(\frac{\rho_{0}}{\rho}\right)^{1/4}\nu^{-1/2}\frac{\Gamma(\frac{5+d_{S}}{2})}{\lambda^{\frac{5+d_{S}}{2}}_{S}}\right] \nonumber \\
  &+\frac{c_{l}(T-T_{0})}{L_{f}}(P_{SACW}+P_{SACR}).
\end{align}
The last term indicates that the accretions of cloud water and rain promote snow melting. Similarly, the melting rate of graupel is described as
\begin{align}
  P_{GMLT}&=\frac{2\pi K_{a}(T-T_{0})N_{0G}}{\rho L_{f}} \nonumber \\
  &\times\left[f_{1G}\frac{\Gamma(2)}{\lambda^{2}_{G}}+f_{2G}c^{1/2}_{G}\left(\frac{\rho_{0}}{\rho}\right)^{1/4}\nu^{-1/2}\frac{\Gamma(\frac{5+d_{G}}{2})}{\lambda^{\frac{5+d_{G}}{2}}_{G}}\right] \nonumber \\
  &+\frac{c_{l}(T-T_{0})}{L_{f}}(P_{GACW}+P_{GACR}).
\end{align}

When $T < T_{0}$, rain particle freezes to become graupel. The freezing rate of rain is described as
\begin{equation}
  P_{GFRZ}=20\pi^{2}B^{\prime}N_{0R}\frac{\rho_{w}}{\rho}\frac{\exp[A^{\prime}(T_{0}-T)]-1}{\lambda^{7}_{R}},
\end{equation}
where $A^{\prime}=0.66 {\rm \ K^{-1}}$ and $B^{\prime}=100 {\rm \ m^{-3} \ s^{-1}}$.

\subsubsection{Bergeron process}
When cloud water and cloud ice coexist under the condition of $T < T_{0}$, supercooled cloud water evaporates and diffuses to cloud ice because the saturated vapor pressure over liquid water is higher than that for solid water. This process is called Bergeron process. Through this process, cloud ice particle grows to become precipitating snow particle. Thus, mass conversion from cloud water and cloud ice to snow occurs. Conversion rates of cloud water ($P_{SFW}$) and cloud ice ($P_{SFI}$) are formulated as
\begin{align}
  P_{SFW}&=N_{I50}(a_{1}m^{a_{2}}_{I50}+\pi E_{IW}\rho Q_{W}R^2_{I50}U_{I50}), \\
  P_{SFI}&=Q_{I}/\Delta t_{1},
\end{align}
where $m_{I50}$ ($=4.8\times10^{-10} {\rm \ kg}$) and $U_{I50}$ ($=1{\rm \ m/s}$) denotes mass and terminal velocity of ice particle having a radius of 50 ${\rm \mu m}$ ($\equiv R_{I50}$), and $E_{IW}=1$ is collection efficiency of cloud ice for cloud water. The values of $a_{1}$ and $a_{2}$ is determined from a laboratory experiment by \citet{koenig_1971}. $\Delta t_{1}$ is the time during which an ice particle of 40 ${\rm \mu m}$ grows to 50 ${\rm \mu m}$, which is formulated as
\begin{equation}
  \Delta t_{1}=\frac{1}{a_{1}(1-a_{2})}\left[m^{1-a_{2}}_{I50}-m^{1-a_{2}}_{I40}\right],
\end{equation}
where $m_{I40}=2.46\times10^{-10} {\rm \ kg}$. $N_{I50}$ is the number concentration of 50 ${\rm \mu m}$ ice particle which is formulated as
\begin{equation}
  N_{I50}=q_{I50}/m_{I50}=\frac{Q_{I}\Delta t}{m_{I50}\Delta t_{1}}.
\end{equation}
In the SCALE, the Bergeron process occurs only when 243.15 K $\leq T<T_{0}$.

\subsubsection{Optional schemes in the SCALE}
There are some optional schemes which can be applied to the six-class single-moment bulk microphysics. Cloud ice generation can be explicitly solved as the original method of \citet{lin_etal_1983}, instead of the saturation adjustment process. Conversion terms of cloud water to rain ($P_{RAUT}$ and $P_{RACW}$) can be replaced with those used in \citet{khairoutdinov_and_kogan_2000}. Intercept parameters of particle size distribution ($N_{0R}$, $N_{0S}$, $N_{0G}$) can be diagnostically derived by using the equation of \citet{wainwright_etal_2014}, instead of the constant values. Bimodal particle size distribution can be applied to snow following \citet{roh_and_satoh_2007}, instead of the Marshall-Palmer exponential size distribution.