\chapter{Hamiltonian Equation of Motion}
 Hamiltonian method providing a framework for theoretical basis for further developments like Hamiltonian Jacobi theory, perturbation approaches and chaos. Outside classical mechanics Hamiltonian formulation provides much of the language with which present-day statistical mechanics and quantum mechanics is constructed. Throughout the chapter we are assuming mechanical systems are holonomic and the forces are monogenic.
 \begin{itemize}
 	\item In Hamiltonian formulation there can be no constraint equation among the coordinates.
 	\item If $n$ coordinates are not independent, a reduced set of $m$ coordinates, with $m<n$, must be used for the formulation of the problem
 \end{itemize}
\section{Hamiltonian Formulation}
\begin{itemize}
	\item Describe the motion in terms of first order equations of motion
	\item Number of initial conditions determining the motion are stil be $2n$
	\item $2n$ independent first order equations expressed in terms of $2n$ independent variables
	\item $2n$ equations of motion describe behavior of the system point in a phase space
	\item Out of $2n$ independent quantities half of them are $n$ generalized coordinates and other half set to be the generalized or conjugate momenta $p_i$
	\begin{equation}
	  p_i=\frac{\partial L(q_j,\dot{q}_j, t)}{\partial \dot{q}_j}
	\end{equation}
	where $j$ index shows the set of $q$'s and $\dot{q}$'s
	\item The quantities $(p,q)$ are known as the canonical variables
\end{itemize}
\section{Legendre Transformation}
Consider a function of only two variables $f(x,y)$ so that a differential of $f$ has the form
$$df=udx+vdy$$
where
$$u=\frac{\partial f}{dx},\quad v=\frac{\partial f}{dy}$$
To change the basis of description from $x,y$ to a new distinct set of variables $u,y$ so that differential quantities are expressed in terms of $du$ and $dy$
\begin{align*}
\intertext{Let $g$ be a function $u$ and $y$ defined by the equation}
g&=f-ux
\intertext{A differential of $g$ is then given as}
dg&=df-udx-xdu
\intertext{or}
dg&=vdy-xdu
\intertext{and we get}
x=\frac{-\partial g}{\partial u},&\quad v=\frac{\partial g}{\partial y}
\end{align*}
\section{Hamilton Equation of Motion}
Mathematically the transition from Lagrangian to Hamiltonian formulation corresponds to changing the variables in our mechanical functions from $(q, \dot{q}_j,t)$ to $(q,p,t)$ when $p$ is related to $q$ and $\dot{q}$ by
$$p_i=\frac{\partial L(q_j,\dot{q}_j,t)}{\partial \dot{q}_i}$$
The proceedure for switching variables in this manner is provided by the 'Legendre  transformation'.
\begin{align}
\text{Consider Lagrangian }&\ L(q,\dot{q},t)\ \text{ then}\notag\\
dL=\frac{\partial L}{\partial q_i}dq_i&+\frac{\partial L}{\partial \dot{q}_1}+\frac{\partial L}{\partial t}dt\\
\text{The canonical }&\text{momentum  was defined as }p_i=\frac{\partial L}{\partial \dot{q}_i}\notag\\
\text{Substituting it in }&\text{Lagrange equation we obtain}
\dot{p}_i=\frac{\partial L}{\partial {q}_i}\notag\\
\therefore dL&=\dot{p}_idq_i+p_id\dot{q}_i+\frac{\partial L}{\partial t}dt
\intertext{The Hamiltonian $H(q,p,t)$ is generated by the Legendre transformation}
H(q,p,t)&=\dot{q}_ip_i-L(q,\dot{q},t)
\intertext{and has the differential}
dH&=\dot{q}_1dp_i-\dot{p}_1dq_1-\frac{\partial L}{\partial t}dt
\intertext{Where the term $p_id\dot{q}_i$ removed by Legendre transformation since $dH$ can also written as }
dH&=\frac{\partial H}{\partial q_i}dq_1+\frac{\partial H}{\partial p_i}dp_i+\frac{\partial H}{dt}dt
\intertext{We obtain $2n+1$ relations}
&\left.\begin{array}{rl}\dot{q}_{i} & =\frac{\partial H}{\partial p_{i}} \label{HM-07}\\\\ -\dot{p}_{i} & =\frac{\partial H}{\partial q_{i}}\end{array}\right\}\\\notag\\
&-\frac{\partial L}{\partial t}=\frac{\partial H}{\partial t}\notag
\end{align}
Equation $\ref{HM-07}$ are known as the canonical equations of Hamiltonian
\section{Steps to construct Hamiltonian}
Hamiltonian for each problem must be constructed via the Lagrangian formulation.
\begin{enumerate}
	\item With chosen set of generalized coordinates, $q_i$ the Lagrangian $L(\dot{q},\dot{q}_i,t)$=T-V is constructed
	\item The conjugate momenta are defined as function of $q_i,\dot{q}_i$ and $t$ by equation
	$$p_i=\frac{\partial L}{\partial \dot{q}_i}$$
	\item Legendre transformation used to form the Hamiltonian. At this stage we have some mixed functions of $q_i,\dot{q}_i,p_i$ and $t$
	\item $p_i=\frac{\partial L}{\partial \dot{q}_i}$ then converted to obtain $\dot{q}_i$ as functions of $(q,p,t)\ (ie\quad \dot{q}_i=\frac{\partial H}{\partial p_i})$
	\item The result of the previous steps are then applied to eliminate $\dot{q}_i$ from $H$ so to express it solely as a function of $(q,p,t)$
\end{enumerate}
\begin{note}
	In many problems Lagrangian is the sum of functions each homogeneous in the generalized velocities of degree $0,1$ and $2$ respectively in that are
	$$ H=\dot{q}_1p_i-L=\dot{q}_ip-[L_0(q,t)+L_i(q,t)\dot{q}_k+L_1(q_i,t)\dot{q}_k\dot{q}_m]$$
	If equations defining generalized coordinates don't depend on time then $L_2 \dot{q}_k\dot{q}_m=T(K.E)$\\
	If forces are derivable from a consevative potential $V$ (ie work is independent of path), then $L_0=-V$
	When both there conditions are satisfied the Hamiltonian is automatically the total energy
	$$H=T+V=
	E$$
\end{note}
\begin{exercise}
	A particle of inass $m$ moves inside a bowl under gravity. If the surface of the bowl is given by the equation $z=\frac{1}{2} a\left(x^{2}+y^{2}\right)$, where $a$ is a constant.\\
	(A) Write down Lagrangian of the system in cylindrical co-ordinate.\\
	(a) Identified the cyclic coordinate and law of conservation of momentum.\\
	(b) Write down hamiltonion of the system in cylindrical coordinate system.
\end{exercise}
	\begin{answer}
	\begin{align*}
	\text{(A) }T&=\frac{1}{2} m\left(\dot{r}^{2}+r^{2} \dot{\theta}^{2}+\dot{z}^{2}\right)=\frac{m}{2}\left(\dot{r}^{2}+r^{2} \dot{\theta}^{2}+a^{2} r^{2} \dot{r}^{2}\right) \quad \because z=\frac{1}{2} a r^{2} \Rightarrow \quad \dot{z}=a r \dot{r}\\
	V&=m g z=\frac{1}{2} m g a r^{2} \\
	L&=\frac{m}{2}\left[\dot{r}^{2}\left(1+a^{2} r^{2}\right)+r^{2} \dot{\theta}^{2}-a g r^{2}\right]
	\intertext{	(a) $\theta$ is cyclic coordinate}
	\because \frac{\partial L}{\partial \theta}&=0, \Rightarrow \dot{p}_{\theta}=0 \Rightarrow P_{\theta}=\text{ constant}
	\intertext{(b) Hamiltonian}
	H&=\frac{p_{r}^{2}}{2 m\left(1+a^{2} r^{2}\right)}+\frac{p_{\theta}^{2}}{2 m r^{2}}+\frac{1}{2} m a g r^{2} \quad \\&\because \frac{\partial L}{\partial \dot{r}}=p_{r}=m\left(1+a^{2} r^{2}\right) \dot{r}\text{ and }\frac{\partial L}{\partial \dot{\theta}}=p_{\theta}=m r^{2} \dot{\theta}
	\end{align*}
\end{answer}
\begin{exercise}
	A particle of mass $m$ is attached to fixed point $O$ by a weightless inextensible string of length $a$. It is rotating under the gravity as shown in the figure.\\
	(a) Write down The Lagrangian of the system in spherical co-ordinate.\\
	(b) write down Hamiltonian of the system.
	\begin{figure}[H]
		\centering
		\includegraphics[height=4.5cm,width=3.5cm]{Assignment-HE-02}
	\end{figure}
\end{exercise}
	\begin{answer}
	\begin{align*}
	L&=\frac{1}{2} m\left(\dot{x}^{2}+\dot{y}^{2}+\dot{z}^{2}\right)-[m g(-z)]\\
	L&=\frac{1}{2} m\left(a^{2} \dot{\theta}^{2}+a^{2} \sin ^{2} \theta \dot{\phi}^{2}\right)+m g a \cos (\pi-\theta)\\
	L&=\frac{1}{2} m\left(a^{2} \dot{\theta}^{2}+a^{2} \sin ^{2} \theta \dot{\phi}^{2}\right)-m g a \cos (\theta)\\
	H&=\sum \dot{q}_{1} p_{1}-L\\
	H&=\frac{p_{\theta}^{2}}{2 m a^{2}}+\frac{p_{\phi}^{2}}{2 m a^{2} \sin ^{2} \theta}+m a g \cos \theta \because \frac{\partial L}{\partial \dot{\theta}}=p_{\theta}=m a^{2} \dot{\theta}\text{ and } \frac{\partial L}{\partial \dot{\phi}}=p_{\phi}=m a^{2} \sin ^{2} \theta \dot{\phi}
	\end{align*}
\end{answer}
\begin{exercise}
	Particle of mass $m$ slides under the gravity without friction along the parabotic path
	$y=a x^{2}$ axis shown in the figure. Here $a$ is a constant\\
	(a) Write down Lagrangian of the system .\\
	(b) Write down Lagranges equation of motion.\\
	(c) write down Hamiltonian of the system.
	\begin{figure}[H]
		\centering
		\includegraphics[height=3.5cm,width=4cm]{Assignment-HE-03}
	\end{figure}
\end{exercise}
	\begin{answer}
	\begin{align*}
	y&=a x^{2}\\
	\text{(a) }\dot{y}&=2 a x \dot{x}\\
	L&=\frac{m}{2}\left(\dot{x}^{2}+\dot{y}^{2}\right)-m g y=\frac{m}{2}\left(\dot{x}^{2}+4 a^{2} x^{2} \dot{x}^{2}\right)-m g a x^{2}\\
	L&=\frac{m}{2}\left(1+4 a^{2} x^{2}\right) \dot{x}^{2}-m g a x^{2}\\
	\text{	(b) }&\frac{d}{d t}\left(\frac{\partial L}{\partial \dot{x}}\right)-\frac{\partial L}{\partial x}=0\\
	\frac{d}{d t}&\left[m\left(1+4 a^{2} x^{2}\right) \dot{x}\right]-\left[4 m a^{2} \dot{x}^{2} x-2 \mathrm{~m} g\right.\text{ a }\left.x\right]=0\\
	m \ddot{x}&+4 m a^{2} \ddot{x} x^{2}+8 m a^{2} \dot{x} x \dot{x}-4 m a^{2} \dot{x}^{2} x+2 m g a x=0\\
	m \ddot{x}&+4 m a^{2} x^{2} \ddot{x}+4 m a^{2} x \dot{x}^{2}+2 m g a x=0\\
	\text{(c) }H&=\sum \dot{x} p_{x}-L\\
	H&=\frac{p_{x}^{2}}{2 m\left(1+4 a^{2} x^{2}\right)}+m g a x^{2} \quad \because \frac{\partial L}{\partial \dot{x}}=p_{x}=m\left(1+4 a^{2} x^{2}\right) \dot{x}
	\end{align*}
\end{answer}
\begin{exercise}
	The Lagrangian of a particle of mass $m$ moving in one dimension is $L=\exp (\alpha t)\left[\frac{m \dot{x}^{2}}{2}-\frac{k x^{2}}{2}\right]$, where $\alpha$ and $k$ are positive constants.\\
	(a) Find the Lagranges equation of motion of the particle.\\
	(b) Write down Hamiltonian of the system.
\end{exercise}
	\begin{answer}
	\begin{align*}
	L&=e^{\alpha t}\left(\frac{m \dot{x}^{2}}{2}-\frac{k x^{2}}{2}\right)\\
	\text{(a) }\frac{d}{d t}\left(e^{\alpha t} m \dot{x}\right)-e^{\alpha t} k x&=0 \Rightarrow e^{\alpha t} m \ddot{x}+m \dot{x} e^{\alpha t} \cdot \alpha-e^{\alpha t} k x=0 \Rightarrow e^{\alpha t}[m \ddot{x}+\alpha m \dot{x}-k x]=0\\
	\text{(b) }H&=e^{-\alpha t} \frac{p_{x}^{2}}{2 m}+e^{\alpha t} \frac{k x^{2}}{2}
	\because \frac{\partial L}{\partial \dot{x}}=p_{x}=e^{\alpha t} m \dot{x}
	\end{align*}
\end{answer}
\section{Cyclic Coordinate and Conservation Theorem}
If $q_j$ a cyclic coordinate then, its conjugate momentum $p_j$ is constant.\\
From Lagrangian and Hamiltonian equations of motions:
$$\dot{p}_{j}=\frac{\partial L}{\partial q_{j}}=-\frac{\partial H}{\partial q j}$$
$\therefore$ coordinate that is cyclic will thus also be absent from the Hamiltonian. Conversely if a generalized coordinate does not occur in $H$ the conjugate momentum is conserved.
\begin{itemize}
	\item If $L$ is not explicit function of $t$ then $H$ is a constant of motion
	\begin{align*}
	\frac{d H}{d t}&=\frac{\partial H}{\partial q_{i}} \dot{q}_{i}+\frac{\partial H}{\partial p_{i}} \dot{p}_{i}+\frac{\partial H}{\partial t}\\\text{substituting }\quad\frac{\partial H}{\partial q_{i}} &=-\dot{p}_{i}\quad\text{ and }\quad\frac{\partial H}{\partial p_{i}} =\dot{q}_{i}\quad\text{we get}\\
	\frac{d H}{d t}&=\frac{\partial H}{\partial t}=\frac{-\partial L}{\partial t}
	\end{align*}
	Therefore if $t$ doesn't appear explicity in $L$, it will also not be present in $H$ and $H$ will be constant in time
	\item If the equations of transformations that define the generalized coordinates
	\begin{equation}
	r_m=r_m(q_1,....q_n,t)\label{HE-02}
	\end{equation}
	do not depend explicity upon the time, and if potantial is velocity independent then $H$ is the total energy $H=T+V$
	\item The identification of $H$ as a constant of motion and as the total energy are two seperate matters. If equation \ref{HE-02} involve time explicity but $H$ doesnot, then $H$ is constant of motion but it is not the total energy.
	\item Unlike $L$, using different set of generalized coordinates in the definition of $H$ may leads to an entirely different quantity for Hamiltonian. It may be that for one set of generalized coordinates $H$ is conserved, but that for another it varies in time.
	\item Explicity first order equations in the $2^{\text{nd}}$ dynamical variables
	\begin{align*}
	\text{If }H&=H(q,p)\text{, ray(autonomous)}\\
	\frac{dH}{dt}&=\frac{\partial H}{\partial q}\dot{q} +\frac{\partial H}{\partial p}\dot{p}\\
	&=\frac{\partial H}{\partial q}\frac{\partial H}{\partial p}-\frac{\partial H}{\partial p}\frac{\partial H}{\partial q}=0\\
	\end{align*}
	Hamiltonian is a constant of motion as long as it is not explicity dependent on time.\\
	Hniltonian governs the time evolution of a system so we call it infinitesimal generator of time translations
\end{itemize}
\section{Other Constants of Motion}
\begin{align*}
\intertext{Suppose $F$ is a constant of motion}
F&=F(q,p,t), \text{it could be explicity time dependent}\\
\frac{dF}{dt}&=\frac{\partial F}{\partial q}\dot{q}+\frac{\partial F}{\partial p}\dot{p}+\frac{\partial F}{\partial t}\\
\frac{dF}{dt}&=\frac{\partial F}{\partial q}\frac{\partial H}{\partial p}-\frac{\partial F}{\partial p}\frac{\partial H}{\partial q}+\frac{\partial F}{\partial t}
\intertext{for $n$ degrees of freedom}
\frac{dF}{dt}&=\sum\limits_{i=1}^{n}\left( \frac{\partial F}{\partial q_i}  \frac{\partial H}{\partial p_i}-\frac{\partial F}{\partial p_i}  \frac{\partial H}{\partial q_i} \right)+\frac{dF}{dt}
\intertext{This constructed out of 2 functions of $F$ and $H$ is called the poisson bracket of $F$ with $H$}
\frac{dF}{dt}&\equiv \underset{poisson bracket}{\left\lbrace F,H\right\rbrace }+ \frac{\partial F}{\partial t}
\end{align*}
It plays the same role in classical mechanics as the commutators of matrices or operators would in quantum mechanics \\
$F$ is a constant of motion if $\frac{dF}{dt}$ vanishes identically\\
$F$= constant of motion if and only if
$$\left\lbrace F,H\right\rbrace +\frac{\partial F}{\partial t}=0$$
it's poisson commute with $H$ or to say $F$ and $H$ are said to be in involution with each other. Where the Hamiltonian itself is a constant of motion for autonomous systems.
\section{Poisson Bracket}
You could define poisson bracket of any two functions of phase variables
$$\left\lbrace A,B\right\rbrace =\frac{\partial A}{\partial \dot{q}}\ \frac{\partial B}{\partial p}-\frac{\partial A}{\partial p}\ \frac{\partial B}{\partial q}$$
\begin{itemize}
	\item $\left\lbrace A,B\right\rbrace =-\left\lbrace B,A\right\rbrace $ \quad (antisymmetry)\\
	\item $\left\lbrace A+B,C\right\rbrace =\left\lbrace A,C\right\rbrace +\left\lbrace B,C\right\rbrace $
	\item $\left\lbrace \alpha \ A,B\right\rbrace =\alpha\left\lbrace A,B\right\rbrace $
	\item $\left\lbrace A,B C\right\rbrace=B\left\lbrace A,C \right\rbrace+\left\lbrace A,B\right\rbrace C  $ (follow the order)
\end{itemize}
This is the way you could find poisson brackets of various complicated functions of the phase space variable given a few elementary poisson brackets
$$\left\lbrace A ,\left\lbrace B,C \right\rbrace \right\rbrace +\left\lbrace B ,\left\lbrace C,A \right\rbrace \right\rbrace +\left\lbrace C,\left\lbrace A,B \right\rbrace \right\rbrace =0$$
\section{Conjugate Momentum}
We have independent variable $(q_i...q_N,p_i...p_N)$
\begin{align*}
\left\lbrace q_k,q_l\right\rbrace &=\sum\limits_{i-1}^{n}\left(\frac{\partial q_k}{\partial q_i}\ \frac{\partial q_l}{\partial p_i}-\frac{\partial q_k}{\partial p_i}\ \frac{\partial q_l}{\partial q_i}\right)=0 \text{Since $p$ and $q$ are independent}\\
\left\lbrace p_k,p_l\right\rbrace  &=0  \\
\left\lbrace q_k,p_l\right\rbrace  &=\sum\limits_{i-1}^{n}\left(\frac{\partial q_k}{\partial q_i}\ \frac{\partial p_l}{\partial p_i}-\frac{\partial q_k}{\partial p_i}\ \frac{\partial p_l}{\partial q_i}\right)\\
\left\lbrace q_k,p_l\right\rbrace  &=\sum\limits_{i}\delta_{ik}\delta_{il}=\delta_{kl}
\end{align*}
\textbf{Canonical Poisson Bracket Relations}\\
${q_k,p_l}=\delta_{kl}$\\
${q_k,q_l}=0$\\
${p_k,p_l}=0$\\
once there relations are satisfied\\
momentum $P_K$ is conjugate to the generalized coordinates $q_k (q_k,p_k)$ form conjugate pair\\
for the poisson commutes with all other $p's$ except it's conjugate ${q_k,p_k}=1$

Classical Mechanics  -CSIR/chapter/Hamiltonian Equation of Motion.tex


% !TEX TS-program = pdflatexmk
\documentclass{article}

\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{amsthm}
\usepackage{natbib}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}

\title{Completely Random Measure}
\date{\today}
\author{Dongwoo Kim\\ANU}

\begin{document}

\maketitle

\section{Poisson Process}
\label{sec:pp}
Let $(S, \mathcal{S})$ be a measurable space and $\Pi$ be a random countable collection of points on $S$. Let  counting process $N(A) = |\Pi \cap A|$ for any measurable set $A$. $\Pi$ is a Poisson process if $N(A)$ and $N(B)$ are independent for every measurable disjoint sets $A$ and $B$ and $N(A)$ is Poisson distributed with mean $\mu(A)$ for a $\sigma$-finite measure $\mu$ (also called mean measure).

Let $f$ be a measurable function from $S$ to $\mathbb{R}$, then by the Campbell's theorem \citep{kingman1993poisson} $\sum_{x\in \Pi} f(x)$ is absolutely convergent with probability one if and only if
\begin{align}
\int_{S} \min(|f(x), 1|)\mu(dx) < \infty.
\end{align}
The Laplace functional of Poisson process for any $f \ge 0$ is then
\begin{align}
\mathbb{E}_{\Pi}[e^{-\sum_{x \in \Pi}f(x)}] = \exp \Bigg\{ - \int_{S} (1-e^{-f(x)})\mu(dx) \Bigg\}.
\end{align}

\section{Completely Random Measure}
Let $(\Omega, \mathcal{F}, \mathbb{P})$ be some probability space, $(M(S), \mathcal{B})$ be the space of all $\sigma$-finite measures on $(S, \mathcal{S})$. A completely random measure (CRM) $\Lambda$ on $(S, \mathcal{S})$ is a measurable function from $\Omega$ to $M(S)$ \footnote{This corresponds to a measure-theoretic definition of a random variable. So one can define a probability over a set random measures $\mathbb{P}(\Lambda^{-1}(A))$ where $A \in \mathcal{B}$. However, in the rest of the paper, we use $\Lambda(A)$ as a measure on $S$ where $A \in \mathcal{S}$.} such that
\begin{enumerate}
\item $\mathbb{P}(\Lambda(\emptyset) = 0)$
\item For any disjoint countable collection of sets $A_i$, the random variable $\Lambda(A_i)$ are independent, and $\Lambda(\cup A_i) = \sum_i \Lambda(A_i)$ a.s. (also known as independent increments)
\end{enumerate}
CRMs with random masses at random locations can be represented as $\Lambda = \sum_{i=1}^{\infty} w_i \delta_{x_i}$ where $x_i$ is a location and $w_i$ is a mass on that location.

\subsection{Completely Random Measure and Poisson Process}
The most important characteristic of CRM is its relation to the Poisson process. For any CRM $\Lambda$ on $(S, \mathcal{S})$ without any deterministic component, there is a corresponding Poisson Process $\Pi$ on $(\mathbb{R}_+ \times S, \mathcal{B}_{\mathbb{R}_+} \times \mathcal{S})$\footnote{Unlike Section \ref{sec:pp}, now the Poisson process is on the product space where each point corresponds to a pair $(w, x)$} such that
\begin{align}
\Lambda(A) = \sum_{(w, x) \in \Pi}w \mathbf{1}_{[x \in A]} = \int_{\mathbf{R}\times A} w \Pi(dw, dx).
\end{align}
Let $\nu(dw, dx)$ be a mean measure of Poisson Process $\Pi$, From the Campbell's theorem, one can easily derive the Laplace transform of $\Lambda(A)$ in $t\ge 0$ for a measurable set $A$:
\begin{align}
\mathbb{E}_\Lambda[e^{-t\Lambda(A)}] &= \mathbb{E}_{\Pi}[e^{-t \int_{\mathbf{R}\times A} w \Pi(dw, dx) }] \\
& = \exp\Bigg( - \int_{\mathbb{R}_+ \times A} (1- e^{-tw}) \nu(dw,dx) \Bigg),
\end{align}
which is derived from Laplace functional of Poison process where $f(w, x) = tw$.
If the mean measure $\nu(dw, dx) = \rho(dw)H_0(dx)$ where $\rho$ and $H_0$ is both $\sigma$-finite measures, then $\Lambda$ is known as homogeneous CRM, or if $\nu(dw, dx) = \rho(dw|dx)H_0(dx)$ then this is non-homogeneous CRM which implies that the masses $(w_i)$ of atoms in $\Lambda$ are dependent on the locations. In homogeneous case, the masses are independent of the locations and are distributed according to a Poisson process over $\mathbb{R}_+$ with mean intensity $\rho$, while the locations are i.i.d. from $H_0$. In practice, $H_0$ is usually referred as a base distribution (or base measure) which has some parametric probability density on $S$ (e.g. Gaussian distribution on $\mathbb{R}$).

By using some known properties about Poisson process, we can also deduce some known properties of CRM. For example, the expected number of points on $\mathbb{R}_+ \times S$ is computed as
\begin{align}
\mathbb{E}_\Pi[\Pi(\mathbb{R}_+ \times S)] = \int_{\mathbb{R}_+ \times S} \nu(dw,dx).
\end{align}
Sometimes (in most of the useful cases), the expected number of points might be diverge (i.e. $\mathbb{E}[\Pi(\mathbb{R}_+ \times S)] = \infty$, a.s.), however, even in this case the total mass of CRM $\Lambda(S)$ could be positive and finite with probability one if the following condition is satisfied\footnote{This condition is from the Laplace transform of $\lambda(S)$ where $t=1$ so that the exponent of Laplace transform does not diverge.}:
\begin{align}
\int_{\mathbb{R}_+ \times A} (1- e^{-w}) \rho(dw)H_0(S) < \infty.
\end{align}
If the above two conditions are satisfied, then $\Lambda$ has an infinite number of atoms (again, which corresponds to the expected number of points). This property is also important to construct a normalised random measure (NRM); since the total mass of CRM is positive and finite almost surely, one can construct a NRM through the normalisation of CRM.

\section{Special Case}
CRM shows different characteristics based on the choice of intensity on weights $\rho(dw)$.

\subsection{Generalised Gamma Process}
The L\'{e}vy intensity measure $\rho$ of the generalised Gamma process (GGP) is
\begin{align}
\rho_{\alpha, \sigma, \tau}(dw) = \frac{\alpha}{\Gamma(1-\sigma)}w^{-\sigma - 1}e^{-\tau w} dw
\end{align}
GGP encompasses several well-known processes based on the different configuration on parameter $\sigma$ and $\tau$:
\begin{itemize}
\item Finite activity case: $\int_w \rho_{\alpha, \sigma, \tau}(dw) < \infty$
\begin{itemize}
\item $(\sigma \le 0, \tau > 0)$: weights $w_i$ are i.i.d. from Gamma($-\sigma$,$\tau$).
\end{itemize}
\item Infinite activity case : $\int_w \rho_{\alpha, \sigma, \tau}(dw) = \infty$
\begin{itemize}
\item $(\sigma = 0, \tau > 0)$: the Gamma process. Normalised Gamma process = Dirichlet process.
\item $(\sigma = \frac{1}{2}, \tau > 0)$: the inverse-Gaussian process.
\item $(\sigma \in (0, 1), \tau = 0)$: the stable process
\end{itemize}
\end{itemize}

\textbf{Sum of weights from GGP}: As we saw in the previous section, for some intensity measure, the total mass $\Lambda(S)$ is finite a.s. If we consider $\Lambda(S)$ as a random variable, then the Laplace transform of the variable is
\begin{align}
\mathbb{E}[e^{-t\Lambda(S)}] = \exp\bigg\{-\int_{\mathbb{R}_+} (1- e^{-tw}) \rho_{\alpha, \sigma, \tau}(dw) \bigg\} = \exp\bigg\{-\frac{\alpha}{\sigma}\big((t+\tau)^\sigma - \tau^\sigma\big)\bigg\},
\end{align}
which corresponds to the Laplace transform of the exponentially tilted stable distribution where the exact sampler exists \citep{devroye2009random,hofert2011sampling}. Taking the derivative of $t$ and set $t=0$ shows the expected sum of weights is $\alpha \tau^{\sigma-1}$.

\subsubsection{Gamma Process}
If $\sigma = 0$, then the GGP will be the Gamma process of which normalisation is well known Dirichlet process.

The expected number of partitions $\mathbb{E}[N_k] = \sum_{i=1}^{n} \frac{\alpha}{\alpha + i - 1} = \alpha (\Psi(\alpha + n) - \Psi(\alpha)) = O(\alpha \log n)$, where $\Psi$ is a digamma function.

\subsection{Beta Process}
\begin{align}
\nu(dw, dx) = \alpha w^{-1}(1-w)^{\alpha-1} dw H_0(dx)
\end{align}

\section{Auxiliary}
\begin{itemize}
\item Stirling's approximation $\Gamma(n+1) \approx \sqrt{2\pi n}(n/e)^{n}$
\end{itemize}

\bibliographystyle{apalike}
\bibliography{ref}

\end{document}


\documentclass{article}

\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithm}
\usepackage{booktabs}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage[font=small]{caption}
%\usepackage{subcaption}
%\expandafter\def\csname ver@subfig.sty\endcsname{}
\usepackage{tabularx}
\usepackage{subfig}
\usepackage{pgffor}
\usepackage{hyperref}
\usepackage{soul}

% for tables
\newcommand{\centertab}[1]{\multicolumn{1}{|c|}{\textbf{#1} }}
\newcommand{\bigcell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}

\begin{document}
\input{math_definitions}

\section{KL divergence}
\begin{align*}
  D_{KL} (P \| Q) = \expected{x \sim P}{ \func{\log}{\dfrac{p(x)}{q(x)}}}
\end{align*}

\section{Expected value}
\begin{align*}
  \expected{}{X} = \int x f(x) dx
\end{align*}
\begin{itemize}
  \item \textbf{Linearity}
  \begin{align*}
    \expected{}{X + Y} &= \expected{}{X} + \expected{}{Y} \\
    \expected{}{a X} &= a \expected{}{X}
  \end{align*}
\end{itemize}

\section{Multivariate Normal Distribution}
\begin{align}
  p(\vx| \vmu, \vSigma) = \dfrac{1}{\sqrt{\group{2 \pi}^k \abs{\vSigma}}}
    \func{\exp}{-\dfrac{1}{2} (\vx - \vmu)^T \vSigma^{-1} (\vx - \vmu)}
\end{align}
\begin{itemize}
  \item \textbf{log likelihood}
  \begin{align*}
    \ln(p(\vx | \vmu, \vSigma))
      & = -\dfrac{k \func{\ln}{2 \pi}}{2} -\dfrac{\func{\ln}{\abs{\vSigma}}}{2}
          -\dfrac{1}{2}\group{\vx - \vmu}^T \vSigma^{-1} \group{\vx - \vmu} \\
      & = -\dfrac{1}{2} \sgroup{\func{\ln}{\group{2 \pi}^k \abs{\vSigma}}
            + \group{\vx - \vmu}^T \vSigma^{-1} \group{\vx - \vmu}
                                }
  \end{align*}
  \item \textbf{KL divergence}
  \begin{align*}
    \func{D_{KL}}{{\cal N}_a \| {\cal N}_b }
      & = \dfrac{1}{2}\group{
        \Tr{\vSigma_b^{-1} \vSigma_a}
        + \group{\vmu_b - \vmu_a} \vSigma_b^{-1} \group{\vmu_b - \vmu_a}
        - k + \log{\dfrac{\abs{\vSigma_b}}{\abs{\vSigma_a}}}
        } \\
      & = \dfrac{1}{2}\group{
        \fnorm{\vL_b \solve \vL_a}^2
        + \ltwogroup{\vL_b \solve \group{\vmu_b - \vmu_a}}^2
        %& \;\;\;\;\;\;\;\;\;\;\;\;\;
        - k + 2\group{  \log{\func{\diag}{{\vL_b}}^T \ones}
                      - \log{\func{\diag}{{\vL_a}}^T \ones} }
        }
  \end{align*}
  \item \textbf{Affine Transform}
  \begin{align*}
    \vx &\sim \normal{\vmu_x, \vSigma_x} \\
    \vy &= \vA \vx + \vb \\
    \vy &\sim \normal{\vA \vmu_x + \vb, \vA \Sigma_x \vA^T}
  \end{align*}
  \item \textbf{Linear Gaussian systems}
    Given a linear system:
    \begin{align*}
      p(\vx) = \normal{x \given \vmu_x, \vSigma_x} \\
      p(\vy \given \vx) = \normal{\vy \given \vA \vx + b, \vSigma_y}
    \end{align*}
    We have the following:
    \begin{align*}
      p(\vx \given \vy) &= \normal{x \given \vmu_{x \given y}, \vSigma_{x \given y}} \\
      \vmu_{x \given y} &= \vSigma_{x \given y} \sgroup{\vA^T \vSigma_y^{-1} (\vy - \vb) + \vSigma_x^{-1} \vmu_x}\\
      \vSigma_{x \given y} &= \vSigma_x^{-1} + \vA^T \vSigma_y^{-1} \vA
    \end{align*}
    \begin{align*}
      p(\vy) = \normal{\vy \given \vA \vmu_x + \vb,
                       \vSigma_y + \vA \vSigma_x \vA^T}
    \end{align*}
  \item \textbf{quadratic relations}
    \begin{itemize}
      \item $\expected{\vx \sim \normal{\vmu, \vSigma}}{\vx^T \vA \vx}
              = \Tr{\vA \vSigma} + \vmu^T \vA \vmu$
      \item
      $$\expected{\vx \sim \normal{\vb, \vB}}{
        \group{\va - \vA \vx}^T \Sigma^{-1} \group{\va - \vA \vx}}
        = \group{\va - \vA \vb}^T \vSigma^{-1} \group{\va - \vA \vb}
          + \Tr{\vA^T \vSigma^{-1} \vA \vB}$$
    \end{itemize}

\end{itemize}

\section{Gamma distribution}
  $x \sim Ga(a, b)$ where $a$ is called the shape and $b$ the rate.
  \begin{align*}
    Ga(x | a, b) = \dfrac{b^a}{\Gamma(a)} x^{a-1} \func{\exp}{-bx}
  \end{align*}

  \begin{itemize}
    \item $\expected{}{x} = \dfrac{a}{b}$
    \item \( \expected{x \sim Ga(a, b)}{\ln{x}} = \psi(a) - \func{\ln}{b} \) \\
    where $\psi$ is the polygamma function.
  \end{itemize}

\subsection{Inverse gamma}
  If $x \sim Ga(a, b)$ and $y=\dfrac{1}{x}$, then $y \sim IG(a, b)$
  \begin{align*}
    IG(y | a, b) = \dfrac{b^a}{\Gamma(a)} y^{-(a+1)} \func{\exp}{-b/y}
  \end{align*}

\subsection{Inverse Wishart (IW)}
This distribution is used in Bayesian statistics as the conjugate prior for the
  covariance matrix of a multivariate normal distribution:
  \begin{align*}
    \vSigma & \sim \func{IW}{\vS^{-1}, \upsilon + D + 1} \\
    \func{IW}{\vSigma \given \vS, \upsilon} &=
      \dfrac{1}{\func{\vZ}{\vS, \upsilon}} \abs{\vSigma}^{(\upsilon+D+1)/2}
        \func{\exp}{-\dfrac{1}{2} \Tr{\vS^{-1} \vSigma^{-1}}} \\
    \func{Z}{\vS, \upsilon} &= \abs{\vS}^{-\upsilon/2} 2^{\upsilon D/2} \Gamma_D{\upsilon/2}
  \end{align*}
where $\vS \succ 0$

\end{document}


%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex
\section{Formulation of a compartment model} \label{sec:fcm}
Recall that the evolution of the concentration $C(t,\b x)$ of a tracer in a domain $\Omega$ obeys the following equation:
\begin{equation} \label{eq:continuousproblem}
	\frac{\partial C}{\partial t} = q - \nabla \cdot (\b u C - \b K \cdot \nabla C),
\end{equation}
where $\b u$ is the velocity field and $q$ is the source or sink term, i.e. the rate at which the tracer is produced or destroyed. In the case of a passive tracer, $q = 0$. Under the Boussinesq approximation, the continuity equation simplifies to
\begin{equation}
	\nabla \cdot \b u = 0,
\end{equation}
namely the velocity field is divergence-free. As already stated, the diffusivity tensor $\b K$ is symmetric and positive definite.

In order to derive a compartment model from~\eqref{eq:continuousproblem}, $\Omega$ must be partitioned into $N$ subdomains $\Omega_1,\Omega_2,\dots,\Omega_N$ called the \textit{compartments}. Mathematically, the fact that these subdomains form a partition of $\Omega$ means that
\begin{equation}
	\bigcup_{i \in\{1,\dots,N\}} \Omega_i = \Omega \qquad \mbox{and} \qquad \Omega_i \cap \Omega_j = \varnothing \mbox{ if } i \neq j.
\end{equation}
In this section, unless otherwise stated, the subscripts $i$ and $j$ are implicitly assumed to be in $\{1,\dots,N\}$. The interface between the subdomains $\Omega_i$ and $\Omega_j$ is denoted $\Gamma_{i,j}$ and the interface between $\Omega_i$ and the environment is denoted $\Gamma_{i,e}$. Obviously, $\Gamma_{i,j} = \Gamma_{j,i}$ and $\cup_{i\in\{1,\dots,N\}} \Gamma_{i,e} = \partial \Omega$. In a compartment model, only the averages over the compartments are considered. The mean tracer concentration over compartment $i$ is
\begin{equation} \label{eq:C_i(t)}
	C_i(t) = \frac{1}{|\Omega_i|} \int_{\Omega_i} C(t,\b x) \rm d\Omega_i,
\end{equation}
and the net production rate over the subdomain $i$ is
\begin{equation}
	q_i(t) =  \frac{1}{|\Omega_i|} \int_{\Omega_i} q(t,\b x) \rm d\Omega_i.
\end{equation}
The equation governing the evolution of $C_i(t)$, the average concentration over compartment $i$, is obtained by integrating~\eqref{eq:continuousproblem} over $\Omega_i$. This yields, using the divergence theorem:
\begin{equation}
	|\Omega_i| \frac{d C_i}{d t} = |\Omega_i| q_i - \sum_{\subalign{j&=1 \\j &\neq i}}^N \underbrace{\int_{\Gamma_{i,j}} (\b u C - \b K \cdot \nabla C)\cdot \b n_{i,j} \rm d\Gamma_{i,j}}_{:= \phi_{i,j}} - \underbrace{\int_{\Gamma_{i,e}} (\b u C - \b K \cdot \nabla C)\cdot \b n_{i,e} \rm d\Gamma_{i,e}}_{:= \phi_{i,e}},
\end{equation}
where $\phi_{i,j}$ is interpreted as the tracer flux from compartment $i$ to compartment $j$, and $\phi_{i,e}$ is the flux of tracer leaving compartment $i$ towards the environment. In the framework of a compartment model, only the mean concentration in each compartment are available, making it impossible to evaluate the integrals in the right-hand side exactly. The flux $\phi_{i,j}$ can be split into an advective and a diffusive part:
\begin{equation} \label{eq:phi_i,j}
	\phi_{i,j} = \underbrace{\int_{\Gamma_{i,j}} (\b u C)\cdot \b n_{i,j} \rm d\Gamma_{i,j}}_{:= \phi_{i,j}^A \mbox{ \footnotesize (advective part)}} + \underbrace{\int_{\Gamma_{i,j}} (-\b K \cdot \nabla C)\cdot \b n_{i,j} \rm d\Gamma_{i,j}}_{:= \phi_{i,j}^D \mbox{ \footnotesize (diffusive part)}}.
\end{equation}
A natural approximation of the advective flux $\phi_{i,j}^A$ is obtained as
\begin{equation}
	\phi_{i,j}^A \approx \frac{C_i + C_j}{2} \int_{\Gamma_{i,j}} \b u \cdot \b n_{i,j} \rm d\Gamma_{i,j} =  \frac{C_i + C_j}{2} |\Gamma_{i,j}| u_{i,j},
\end{equation}
where a characteristic speed $u_{i,j}$ has been introduced such that
\begin{equation} \label{eq:def_uij}
	|\Gamma_{i,j}|u_{i,j} = \int_{\Gamma_{i,j}}\b u \cdot \b n_{i,j} \rm d\Gamma_{i,j}.
\end{equation}
Since $\phi_{i,j}^A = - \phi_{j,i}^A$ and $\Gamma_{i,j} = \Gamma_{j,i}$, the characteristic speed must satisfy
\begin{equation}
	u_{i,j} = - u_{j,i}.
\end{equation}
The definition~\eqref{eq:def_uij} satisfies that condition.
The diffusive flux $\phi_{i,j}^D$ involves the gradient of the concentration at the interface. A possible approximation is given by
\begin{equation}
	\phi_{i,j}^D = - |\Gamma_{i,j}| k_{i,j} \frac{C_j-C_i}{l_{i,j}},
\end{equation}
where $k_{i,j} > 0$ is a characteristic diffusivity and $l_{i,j} > 0$ is a characteristic length. Obviously, $\phi_{i,j}^D = -\phi_{j,i}^D$ hence $k_{i,j} = k_{j,i}$ and $l_{i,j} = l_{j,i}$. In \cite{deleersnijder2014compartment}, \textit{Deleersnijder} proposes to simplify those notations by introducing advective and diffusive "fluxes" $U_{i,j}$ and $V_{i,j}$:
\begin{equation} \label{eq:def_Uij_Vij}
	U_{i,j} = |\Gamma_{i,j}|u_{i,j} \quad \mbox{and} \quad V_{i,j} = \frac{|\Gamma_{i,j}|k_{i,j}}{l_{i,j}}.
\end{equation}
By the previously mentioned properties, it is obvious that
\begin{equation} \label{eq:Uprop}
	U_{i,j} = -U_{j,i}
\end{equation}
and that
\begin{equation} \label{eq:Vprop}
	V_{i,j} = V_{j,i} > 0.
\end{equation}
Using those notations, the flux from compartment $i$ to compartment $j$ is approximated by
\begin{equation}
	\phi_{i,j} \approx U_{i,j} \frac{C_i + C_j}{2} - V_{i,j}(C_j - C_i),
\end{equation}
and the equation governing the evolution of the concentration in compartment $i$ is obtained as
\begin{equation} \label{eq:compartmentmodel}
	\Omega_i \frac{dC_i}{dt} = \Omega_i q_i - \sum_{\subalign{j&=1 \\j &\neq i}}^N \left[ U_{i,j}\frac{C_i + C_j}{2} - V_{i,j} (C_j-C_i)\right] - \phi_{i,e}.
\end{equation}
Let us fix the convention $U_{i,i} = 0$ and $V_{i,i} = 0$ so that the summation subscript $j \neq i$ becomes unnecessary.
Note that by~\eqref{eq:def_Uij_Vij},~\eqref{eq:def_uij} and the divergence theorem,
\begin{equation} \label{eq:continuitycompartment}
	\sum_{j=1}^N U_{i,j} + U_{i,e} = \sum_{\subalign{j&=1 \\j &\neq i}}^N \int_{\Gamma_{i,j}}\b u \cdot \b n_{i,j} \rm d\Gamma_{i,j} + \int_{\Gamma_{i,e}}\b u \cdot \b n_{i,e} \rm d\Gamma_{i,e} = \int_{\Omega_{i}} (\nabla \cdot \b u) \rm d\Omega_{i} = 0,
\end{equation}
the counterpart to the continuity equation.


\section{Safety Check}

Naturally, we prefer error alerts right after inputting rather than let the system run till crash.
Parser helps filter bad inputs, type check verifies the transaction between term and term, while
neither of them guarantees termination.\par
In this part, we will demonstrate how to prevent non-halting definition from getting accepted into
the system.

\subsection{Fixpoint}

The introduction of {\it Fixpoint} gives a wide range of flexibility of the program, without which recursive
function can not formulate. On the other hand, the risk of non-terminating appears.\par
To avoid this, we put a strong constraint on recursive function, which is that it must descend on at least one
argument.
\begin{Prop}[Termination of Fixpoint]
If a recursive function descends on at least one argument, it will always terminate in reduction.
\end{Prop}
\begin{Def}[Descending]
Recursive function $f(x_1,x_2,\cdots,x_n)$ is descending on $x_k$ if any occurrence of $f$ in function definition has the
form $f(y_1,y_2,\cdots,y_n)$, where $y_k$ is inferior to $x_k$.
\end{Def}
\begin{Def}[Inferior]
In a function definition, $x$ is inferior to $y$ if $y\to_m y_1\to_m \cdots\to_m y_s\equiv x$.
$a \to_m b$ means a pattern match directly from $a$ to $b$.
\end{Def}
Here is an example.
\begin{center}
\begin{minted}{coq}
(* accepted *)                                 (* rejected *)
Fixpoint plus (n:nat)(m:nat) : nat :=          Fixpoint plus (n:nat)(m:nat) : nat :=
    match n as n0 in nat return (nat) with         match n as n0 in nat return (nat) with
    | O => m                                       | O => m
    | S p => S (plus p m)                          | S p => S (plus m p)
    end.                                           end.
\end{minted}
\end{center}

\subsubsection*{Implementation}

Check every argument of the recursive function. For a specific argument, maintain a list of terms inferior to it
during the process and verify every occurrence of the recursive function.

\subsection{Inductive Type}

The inductive type is actually a recursive definition, which is so powerful that we can create non-terminating program
without actually defining a recursive function.
\begin{center}
\begin{minipage}{0.7\textwidth}
\begin{minted}{coq}
Inductive ill : Type :=
| malf : (ill -> ill) -> ill.

Definition extract (t:ill) : ill :=
    match t as t0 in ill return (ill) with
    | malf f => f t
    end.

extract (malf extract)  (* not terminating *)
\end{minted}
\end{minipage}
\end{center}

\begin{Prop}[Termination of Inductive Type]
If the type of constructor of the inductive definition satisfies the positivity condition for
the inductive type, it will always terminate in reduction.
\end{Prop}

\begin{Def}[Positivity]
The type of constructor $\tt T$ satisfies \textit{the positivity condition} for a constant $\tt X$ if
\begin{itemize}\normalfont
    \item $\tt T\equiv (X\ t_1\ \cdots\ t_n)$ and $\tt X$ does not occur free in $\tt t_i$
    \item $\tt T\equiv \forall x:U,V$ and $\tt X$ occurs only \textit{strictly positively} in $\tt U$ and
        $\tt V$ satisfies \textit{the positivity condition} for $\tt X$
\end{itemize}
\end{Def}

\begin{Def}[Strictly Positivity]
The constant $\tt X$ occurs \textit{strictly positively} in $\tt T$ if
\begin{itemize}\normalfont
    \item $\tt X$ does not occur in $\tt T$
    \item $\tt T\mathop{\rhd}^*\tt (X\ t_1\ \cdots\ t_n)$ and $\tt X$ does not occur in $\tt t_i$
    \item $\tt T\mathop{\rhd}^*\tt \forall x:U,V$ and $\tt X$ does not occur in $\tt U$ but occurs
        \textit{strictly positively} in $\tt V$
    \item $\tt T\mathop{\rhd}^*\tt (I\ a_1\ \cdots\ a_m\ t_1\ \cdots\ t_p)$, where
        ${\tt Ind}[m](\tt I:A:=c_1:\forall p_1:P_1,\dots\forall p_m:P_m,C_1;\cdots;c_n:\forall p_1:P_1,\dots,
        \forall p_m:P_m,C_n)$, and $\tt X$ does not occur in $t_i$, and the types of constructor
        $\tt C_i\{p_j/a_j\}_{j=1..m}$ satisfies \textit{the nested positivity condition} for $\tt X$
\end{itemize}
\end{Def}

\begin{Def}[Nested Positivity]
The type of constructor $\tt T$ satisfies \textit{the nested positivity condition} for a constant $\tt X$ if
\begin{itemize}\normalfont
    \item $\tt T\equiv(I\ b_1\ \cdots\ b_m\ u_1\ \cdots\ u_p)$, where $\tt I$ is an inductive definition with $m$
        parameters and $\tt X$ does not occur in $u_i$
    \item $\tt T\equiv\forall x:U,V$ and $\tt X$ occurs \textit{strictly positively} in $\tt U$ and $\tt V$
        satisfies \textit{the nested positivity condition} for $\tt X$
\end{itemize}
\end{Def}