\label{qft}
\begin{chapterbox}
\vspace{-60pt}
\chapter{Quantum Field Theory}
\vspace{-30pt}
\centering\normalsize\textit{Michaelmas Term 2017 - Professor B. Allanach}
\end{chapterbox}
\vspace{20pt}
%\begin{multicols*}{2}
\minitoc
\newpage
\section{Classical Field Theory}
\begin{definitionbox}
A field is a physical quantity defined at every point of spacetime $(\vec x, t)$. In field\index{field} theory we have a set of fields $\phi_a (\vec x, t)$, where both $\vec x$ and $a$ are labels, so there are an infinite number of degrees of freedom.
\end{definitionbox}
The dynamics of fields are governed by a Lagrangian\index{Lagrangian},
\begin{equation}
L = \int{\upd{^3 x} \mathcal{L}(\phi_a, \partial_\mu \phi_a)}
\end{equation}
where $\mathcal{L}$ is the Lagrangian density. Then the action is;
\begin{equation}
\mathcal{S} = \int_{t_0}^{t}{\upd{t} L} = \int{\upd{^4 x} \mathcal{L}(\phi_a, \partial_\mu \phi_a)}
\end{equation}
\subsection{Units}
We work in units where $c = \hbar = 1$ which implies that $\left[L\right] = \left[T\right] = \left[M\right]^{-1}$, so length and time are measured in units of inverse mass, or equivalently, energy. There are two things to note;
\begin{enumerate}
\item If a quantity $X$ has mass dimension $d$, then we say $X$ has dimension $d$
\item The action, $\mathcal{S}$ is dimensionless $\Rightarrow \left[\ud^4 x\right] = -4, \left[\mathcal{L}\right] = 4$
\end{enumerate}
\subsection{Dynamical Principles of Classical Field Theory}
Classical Field theory is built on the principle of stationary action; the fields evolve such that $\mathcal{S}$ is stationary with respect to variations in the fields;
\begin{dmath}
\delta \mathcal{S} = \sum_{a}{\int{\upd{^4 x} \left( \frac{\partial \mathcal{L}}{\partial \phi_a} \delta \phi_a +\frac{\partial \mathcal{L}}{\partial\left(\partial_\mu \phi_a \right)} \delta \left( \partial_\mu \phi_a \right)\right)}} = \sum_{a}{\int{\upd{^4 x} \left( \frac{\partial \mathcal{L}}{\partial \phi_a} \delta \phi_a - \partial_\mu \left(\frac{\partial \mathcal{L}}{\partial\left(\partial_\mu \phi_a \right)}\right) \delta  \phi_a \right) + \partial_\mu \left(\frac{\partial \mathcal{L}}{\partial\left(\partial_\mu \phi_a \right)} \delta \phi_a \right)}}
\end{dmath}
The last term vanishes for any Lagrangian that decays at spatial infinite and has $\delta \phi_a (\vec x, t_i) = \delta \phi_a (\vec x, t_f) = 0$. Thus $\delta \mathcal{S} = 0$ for all $\delta \phi_a$ gives us the Euler-Lagrange equations\index{equation!Euler-Lagrange} for the field:\footnote{For more on this, refer to Appendix \ref{sec:parttofield}.} \boxed{\textbf{I.i}}
\begin{equation}
\label{eq:EL}
\partial_\mu \left(\frac{\partial \mathcal{L}}{\del\left(\del_\mu \phi_a\right)}\right) - \frac{\partial \mathcal{L}}{\partial \phi_a} = 0
\end{equation}
As an example of this consider the Klein-Gordon field;
\begin{examplebox}[The Klein-Gordon Equation\index{equation!Klein-Gordon}]
Consider the Lagrangian;
\begin{equation*}
\mathcal{L} = \tfrac{1}{2}\etamn{^}\del_\mu \phi \del_\nu \phi - \tfrac{1}{2} m^2 \phi^2 = \tfrac{1}{2} \dot{\phi}^2 - \tfrac{1}{2}(\nabla \phi)^2 - \tfrac{1}{2} m^2 \phi^2
\end{equation*}
Then using \eqref{eq:EL} we find the Klein-Gordon equation;
\begin{equation}
\del_\mu \del^\mu \phi + m^2 \phi = 0
\end{equation}
\end{examplebox}
The realm of Quantum Field Theory are relativistic energies where quantum effects are important. The mass energy equivalence at these high energies mean that the quantum states are multi-particle ones, and the particle number is \emph{not fixed}. This is fundamentally different to normal quantum mechanics. The Schr{\"o}dinger equation is for a single particle, there is no mechanism to create more. Furthermore, interactions arise due to locality and symmetry, they do not arise from arbitrary potentials in the Lagrangian. Indeed, this is made explicit in \emph{Advanced Quantum Field Theory}, where symmetries of the path integral measure and the classical action remain manifest in the full quantum theory. This ensures that the interactions generated respect this symmetry. A special QFT is the free theory\index{free theory} where there are particles, but no interactions. This is a relativistic theory with an infinite number of quantised harmonic oscillators\index{harmonic oscillator}, at least one at each point in space. The interacting theory is then built perturbatively on top of this.
\subsubsection{Lorentz Invariance\index{Lorentz!invariance}}
The Lorentz matrices\footnotemark satisfy the relation; \boxed{\textbf{I.ii}}
\footnotetext{
Note that this expression implies the Lorentz invariance of quantities such as $p^\mu p_\mu$. Under a Lorentz transformation $p^{\mu} \rightarrow \Lambda\indices{^{\mu}_{\nu}}p^{\nu}$ so;
\begin{equation*}
p^\mu p_\mu = \eta_{\mu\nu}p^\mu p^\nu \rightarrow \eta_{\mu\nu} \Lambda\indices{^{\mu}_{\rho}}\Lambda\indices{^{\nu}_{\sigma}}\eta_{\rho\sigma}p^\rho p^\sigma = \eta_{\rho \sigma}p^{\rho} p^{\sigma}
\end{equation*}
}
\begin{equation}
\label{eq:LT}
\Lambda\indices{^\mu_\sigma}\eta\indices{^{\sigma \tau}}\Lambda\indices{_\tau ^\nu} = \etamn{^}
\end{equation}
Consider the Lorentz transformation\index{Lorentz!transformation} of a field, $\phi$ under the transformation;\footnotemark
\footnotetext{
This is really the statement that Lorentz transformations are isometries of the Minkowski metric, in other words, we can define the group in a co-ordinate free way via;
\begin{equation*}
\mO(3, 1) \coloneqq \set{M \in \text{GL}(\RR^{3, 1}) : \eta(M \vec{x}, M \vec{y}) = \eta(\vec{x}, \vec{y})}
\end{equation*}
}
\begin{equation*}
\Lambda : \phi \rightarrow \phi^{\prime}, \quad \phi^{\prime}(x^\mu) = \phi(x^{\prime \, \mu}), \quad x^{\prime \, \mu} = \left(\Lambda^{-1}\right)\indices{^\mu_\nu} x^\nu
\end{equation*}
This is an active transformation of the field, pulling the field value at $\Lambda^{-1} x$ to $x$. We say the Lorentz transformations have a \emph{representation} on the fields. For a scalar field\index{field!scalar}, this is just $\phi(x) \rightarrow \phi^{\prime}(x) = \phi(\Lambda^{-1} x)$. But we could equally have used a passive transformation where we relabel spacetime points, $\phi(x) \rightarrow \phi(\Lambda x)$. Since we work with Lorentz invariant theories it doesn't matter what we choose.

\paraskip
A Lorentz invariant theory is one where the action is invariant under a Lorentz transformation, e.g.
\begin{equation*}
\mathcal{S} = \int{\upd{^4 x} \tfrac{1}{2}\del_\mu \phi \del^\mu \phi - U(\phi)}
\end{equation*}
Under a Lorentz transformation;
\begin{itemize}
\item $U \rightarrow U\left(\phi(x^{\prime})\right) = U(x^{\prime})$
\item $\left(\del_\mu \phi\right)^{\prime} = \left(\Lambda^{-1}\right)\indices{^\sigma_\mu} \del^{\prime}_\sigma \phi(x^{\prime})$ (This is how a vector field transforms). But plugging this into the kinetic term, and using the relation in \eqref{eq:LT}, we see that the Lagrangian simply transforms as a scalar field.
\end{itemize}
So,
$$\mathcal{S}^{\prime} = \int{\upd{^4 x} \mathcal{L}(x^{\prime})}$$
The final step is to note that Lorentz transformations have determinants with modulus $1$. So,
\begin{equation}
\mathcal{S}^{\prime} = \int{\upd{^4 x^{\prime}} \mathcal{L}(x^{\prime})} = \mathcal{S}
\end{equation}
\subsection{Noether's Theorem\index{Noether's theorem} \& Symmetries}
\begin{thm}{Noether's Theorem}
Every continuous symmetry of the Lagrangian gives rise to a conserved current, $j^\mu (x)$ such that $\del_\mu j^\mu (x) = 0$. Furthermore, each conserved current has an associated conserved charge,
\begin{equation}
Q = \int_{\mathbb{R}^3}{\upd{^3 x} j^0 (x^{\mu})}
\end{equation}
which follows from the divergence theorem and the continuity equation as well as the assumption that $j$ decays sufficiently rapidly. Note that the current is only conserved \emph{on-shell}\index{on-shell} where the equations of motion hold. Furthermore, Noether's theorem holds for global symmetries \emph{as well as gauge symmetries} where $\alpha = \alpha(x)$. Indeed, the global symmetry is a special case of this.
\end{thm}
A transformation which induces a variation in the field, $\phi(x) \rightarrow \phi(x) + \alpha \Delta \phi(x)$, is a symmetry if it leaves the action invariant $\iff$ the Lagrangian is invariant up to a total derivative;
\begin{equation}
\label{eq:var}
\mathcal{L} \rightarrow \mathcal{L} + \alpha \del_\mu X^\mu (x)
\end{equation}
In detail,
\begin{dmath}
\mathcal{L}(x) \rightarrow \mathcal{L}(x) + \alpha \frac{\del \mathcal{L}}{\del \phi}\Delta \phi + \alpha \frac{\del \mathcal{L}}{\del \left(\del_\mu \phi\right)}\del_\mu \left(\Delta \phi\right) = \mathcal{L}(x) + \alpha\del_\mu \left(\frac{\del \mathcal{L}}{\del\left(\del_\mu \phi\right)} \Delta \phi \right)
\end{dmath}
where we have used the Euler Lagrange equations in the second line. So comparing to \eqref{eq:var}, we find the current, \boxed{\textbf{I.iii}}
\begin{equation}
\label{eq:current}
j^{\mu} = \frac{\del \mathcal{L}}{\del \left(\del_\mu \phi\right)} \Delta \phi - X^\mu, \quad \del_\mu j^\mu = 0
\end{equation}
We consider the example of a complex scalar\index{field!complex scalar} field to illustrate this,
\begin{examplebox}
We write the theory using $\psi$, $\psi^{\star}$ with Lagrangian;
\begin{equation}
\mathcal{L} = \del_\mu \psi^{\star} \del^\mu \psi - V\left( \left| \psi \right|^2 \right), \quad \textrm{e.g. } V\left( \left| \psi \right|^2 \right) = m^2 \psi^{\star} \psi - \tfrac{\lambda}{2}\left( \psi^{\star} \psi \right)^2
\end{equation}
The symmetry is a phase rotation $\psi \rightarrow e^{i \beta} \psi \rightarrow \Delta \psi = i \psi, \Delta \psi^{\star} = - i \psi^{\star}$. Lagrangian clearly invariant, so $X^{\mu} = 0$. Then we use \eqref{eq:current} to find,
\begin{equation}
j_\mu = i \left(\psi \del_\mu \psi^{\star} - \psi^{\star} \del_\mu \psi \right)
\end{equation}
and the conserved charge is the electric charge\index{electric charge}/particle number.
\end{examplebox}
Perhaps a more important example is that of translations, which leads to the energy-momentum tensor\index{tensor!energy-momentum};
\begin{examplebox}[The Energy-Momentum Tensor]
We consider the translation $x^\mu \rightarrow x^\mu - \xi^\mu$, so $\phi(x) \rightarrow \phi(x) + \xi^\mu \del_\mu \phi(x)$, where we use the fact that $\phi$ transforms under the inverse map. If $\mathcal{L}$ doesn't depend explicitly on time, then it transforms as a scalar field, then;
\begin{equation}
\mathcal{L}(x) \rightarrow \mathcal{L}(x) + \xi^\mu \del_\mu \mathcal{L} (x) = \mathcal{L}(x) + \xi^\nu \del_\mu \left( \delta\indices{^\mu_\nu}\mathcal{L}\right)
\end{equation}
We have one conserved current for each component of $\xi^\nu$, so identifying $\Delta \phi = \del_\mu \phi$, $X^\mu = \delta\indices{^\mu_\nu}\mathcal{L}$, we find;
\begin{equation}
j\indices{^\mu_\nu} \coloneqq T\indices{^\mu_\nu} = \frac{\del \mathcal{L}}{\del \left( \del_\mu \phi \right)}\del_\nu \phi - \delta\indices{^\mu_\nu}\mathcal{L}, \quad \del_\mu T\indices{^\mu_\nu} = 0
\end{equation}
This gives us the conserved charges;
\begin{itemize}
\item Total field energy, $E = \int{\upd{^3 x}} T^{00}$
\item Total field momentum, $P^{i} = \int{\upd{^3 x}} T^{0i}$
\end{itemize}
\end{examplebox}
\newpage
\section{Canonical Quantisation}
We can also use the Hamiltonian\index{Hamiltonian} formalism in field theories; the conjugate momentum\index{conjugate momentum} is defined by;
\begin{equation}
\pi_a (x) = \frac{\del \mL}{\del \dot{\phi}_a} \Rightarrow \hamilt = \sum_{a}{\pi_a (x) \dot{\phi}_a} - \mL(x)
\end{equation}
where $\hamilt$ is the Hamiltonian density\index{Hamiltonian!density}. For example, consider $\mL = \tfrac{1}{2} \dot{\phi}^2 - \tfrac{1}{2} \left(\nabla \phi \right)^2 - V(\phi) \Rightarrow \pi(x) = \dot{\phi}(x) \Rightarrow \hamilt = \tfrac{1}{2} \pi^2 + \tfrac{1}{2} \left(\nabla \phi \right)^2 + V(\phi)$. Hamilton's equations\index{equation!Hamilton's};
\begin{equation}
\dot{\phi} = \frac{\del \hamilt}{\del \pi}, \quad \dot{\pi} = - \frac{\del \hamilt}{\del \phi}
\end{equation}
In general it is not obvious that the Hamiltonian is manifestly Lorentz invariant, but the physics is unchanged, so it must be. Now, in quantum mechanics, the process of quantisation\index{canonical quantisation} takes co-ordinates $q_a$ and momenta $p_a$ and promotes them to operators, replacing the Poisson bracket\index{Poisson bracket} with commutators. We'll do the same here;
\begin{definitionbox}
A \emph{quantum field}\index{field!quantum} is an operator valued function of space obeying the commutation relations;
\begin{align}
\left[\phi_a(\vec x), \pi^b(\vec y)\right] &= i\delta\indices{^{a}_{b}}\delta^{(3)}(\vec x - \vec y) \\
\left[\phi_a(\vec x), \phi_b(\vec y)\right] &= 0 = \left[\pi^{a}(\vec x), \pi^{b}(\vec y)\right]
\end{align}
where we are in the Schr{\"o}dinger picture, so there is no time dependence in the fields.
\end{definitionbox}
It is usually not possible to know the spectrum of $\hamilt$ as there are an infinite number of degrees of freedom. In certain theories, the co-ordinates evolve independently, these are \emph{free theories}\index{free theory} where $\mL$ is quadratic in the fields, giving linear equations of motion. For example, the free theory of a scalar field leads to the Klein-Gordon equation\index{equation!Klein-Gordon} for the field $\phi(\vec, t)$;
\begin{equation}
\del_\mu \del^\mu + m^2 \phi = 0
\end{equation}
Taking the Fourier transform\index{Fourier transform};
\begin{equation}
\phi(\vec x, t) = \int{\frac{\ud^3 p}{(2\pi)^3} e^{i \vec p \cdot \vec x} \phi(\vec p, t)} \Rightarrow \left(\del^2_t + ( \vec{p}^2 + m^2 )\right) \phi(\vec p, t) = 0
\end{equation}
But this is just a harmonic oscillator with frequency $\omega_{p} = \sqrt{\vec{p}^2 + m^2}$. Then $\phi(\vec x, t)$ is just a superposition of an infinite number of harmonic oscillators that we need to quantise.
\subsection{Review of the Simple Harmonic Oscillator\index{harmonic oscillator}}
The main details of the harmonic oscillator can be found elsewhere, here we focus only on the concept of \emph{normal ordering}\index{normal ordering}. Often we are only interested in energy differences between states. So we set the zero point energy $\tfrac{1}{2} \omega \ket{n}$ to zero. This is not so drastic in the case of a single oscillator, it just results from fixing the Hamiltonian to be $\text{H} = \omega a\dagg a$. In the free theory of a full quantum field however, this zero point energy is infinite and thus in this context normal ordering represents a far more subtle process.
\subsection{Free Field Theory}
We take guidance from the simple harmonic oscillator where we write the position and momentum operators in terms of the ladder operators;
\begin{equation}
\label{eq:sho}
\phi = \tfrac{1}{\sqrt{2\omega}}\left(a + a\dagg\right), \quad \pi = -i \sqrt{\tfrac{\omega}{2}} \left(a - a\dagg\right)
\end{equation}
Then we can find the spectrum of the Klein-Gordon Hamiltonian using the same form, but now each Fourier mode of the field is treated as an independent oscillator with it's own $a$, $a\dagg$. So in analogy with \eqref{eq:sho}, we write;\footnote{Note that the second term in the expression for $\phi(\vec x)$ ensures that $\phi$ is a real field.}
\begin{definitionbox}[The Klein-Gordon Scalar Field]
\vspace{-10pt}
\begin{align}
\label{eq:kgfield}
\phi(\vec x) &= \int{\frac{\ud^3 p}{(2\pi)^3}\frac{1}{\sqrt{2\omega_p}} \left(a_{\vec p}\, e^{i\vec{p}
\cdot \vec{x}} + a_{\vec p}\dagg \,e^{-i\vec{p}\cdot\vec{x}}\right)} \\
\pi(\vec x) &= \int{\frac{\ud^3 p}{(2\pi)^3}(-i)\sqrt{\frac{\omega_p}{2}} \left(a_{\vec p}\, e^{i\vec{p}
\cdot \vec{x}} - a_{\vec p}\dagg\, e^{-i\vec{p}\cdot\vec{x}}\right)}
\end{align}
\end{definitionbox}
Importantly we can use this definition along with the identity;
\begin{equation}
\int{\frac{\ud^3 p}{(2\pi)^3}e^{i \vec{p} \cdot \vec{x}}} = \delta^{(3)}(\vec x)
\end{equation}
to show that;\footnote{It is the commutation relations in \eqref{eq:comm} that really motivate the definition in \eqref{eq:kgfield}. It is this algebraic structure that is the hallmark of the quantisation process, not the analogy with the simple harmonic oscillator}
\begin{multline}
\label{eq:comm}
\left[\phi(\vec x), \pi(\vec y)\right] = i\delta^{(3)}(\vec x - \vec y), \left[\phi(\vec x), \phi(\vec y)\right] = 0 = \left[\pi(\vec x), \pi(\vec y)\right] \\ \iff \left[a_{\vec p}, a_{\vec q}\right] = 0 = \left[a_{\vec p}\dagg, a_{\vec q}\dagg\right], \left[a_{\vec p}, a_{\vec q}\dagg\right] = (2\pi)^3 \delta^{(3)}(\vec p - \vec q)
\end{multline}
So, given these definitions, can we calculate the Hamiltonian in terms of the ladder operators? It is a lengthy, but relatively straightforward calculation to find that;
\begin{align}
\text{H} &= \frac{1}{2} \int{\upd{^3 x} \pi^2 + \left(\nabla \phi\right)^2 + m^2 \phi^2} \nonumber \\
&= \frac{1}{4} \int{\frac{\ud^3 p}{(2\pi)^3 \omega_p}\left(-\omega_p^2 + \vec{p}^2 + m^2\right)\left(a_{\vec p} a_{-\vec p} + a_{\vec p}\dagg a_{-\vec p}\dagg\right)} \nonumber \\
&\qquad\qquad\qquad+ \left(\omega_p^2 + \vec{p}^2 + m^2\right)\left(a_{\vec p} a_{\vec p}\dagg + a_{\vec p}\dagg a_{\vec p}\right)
\end{align}
But now we can use the fact that $\omega_p = \sqrt{\vec{p}^2 + m^2}$ to see that the first term vanishes and we are left with;
\begin{equation}
\text{H} = \int{\frac{\ud^3 p}{(2\pi)^3} \omega_p \left(a_{\vec p}\dagg a_{\vec p} + \frac{1}{2}\left[a_{\vec p}, a_{\vec p}\dagg\right]\right)}
\end{equation}
\subsubsection{The Vacuum}
We define the \emph{vacuum}\index{vacuum} of the theory, $\ket{0}$ by the condition that $a_{\vec p} \ket{0} = 0$ for all momenta $\vec p$. The energy is then given by $\text{H}\ket{0}$;
\begin{equation}
\text{H}\ket{0} = \frac{1}{2}\int{\frac{\ud^3 p}{(2\pi)^3} \omega_p (2\pi)^3 \delta^{(3)}(0) \ket{0}}
\end{equation}
but this is divergent (an \emph{ultra-violet divergence}\index{UV divergence}). To rectify this we apply the concept of normal ordering\index{normal ordering}. We are only interested in energy differences, so we redefine the normal ordered Hamiltonian to be;\footnotemark
\footnotetext{
There are actually two infinities here. The first is because space is infinitely large. If instead we put the system in a box of side length $L$, then;
\begin{equation*}
(2\pi)^3 \delta^{(3)}(0) = \lim_{L \rightarrow \infty}\int_{-L/2}^{L/2}{\upd{^3 x}\left.e^{i \vec{p}\cdot\vec{x}}\right|_{\vec{p} = 0}} = \lim_{L \rightarrow \infty}\int_{-L/2}^{L/2}{\upd{^3 x}} = V
\end{equation*}
This we can resolve then by simply considering the energy density $E/V \coloneqq \epsilon_0$. This still leaves;
\begin{equation*}8
\int{\frac{\ud^3 p}{(2\pi)^2}\frac{1}{2}\omega_{\vec{p}}} \rightarrow \infty
\end{equation*}
since $\omega_{\vec{p}}$ diverges. This is the UV divergence mentioned above.
}
\begin{equation}
\normord{\text{H}} = \int{\frac{\ud^3 p}{(2\pi)^3}\omega_p a_{\vec p}\dagg a_{\vec p}}
\end{equation}
\begin{definitionbox}[Normal Ordering]
In general, we define a normal ordering\index{normal ordering} string of operators $\phi_1(x_1)\cdots\phi_n(x_n)$ to be $\normord{\phi_1(x_1)\cdots\phi_n(x_n)}$ which is simply the normal product with all annihilation operators moved to the right of each term.
\end{definitionbox}
\subsubsection{Particles}
With this definition of normal ordering, we now have $\normord{\text{H}}\ket{0} = 0$. We can also verify that,
\begin{equation}
\left[\text{H}, a_{\vec p}\dagg\right] = \omega_p a_{\vec p}\dagg, \quad \left[\text{H}, a_{\vec p}\right] = -\omega_p a_{\vec p}
\end{equation}
So $a_{\vec p}\dagg$ increases the energy by $\omega_{\vec p}$. Let $\ket{\vec{p}\pr} = a_{\vec{p}\pr}\dagg \ket{0}$ then we may show that;
\begin{equation}
\text{H}\ket{\vec{p}\pr} = \omega_{\vec{p}\pr} a_{\vec{p}\pr}\dagg \ket{0} = \omega_{\vec{p}\pr}\ket{\vec{p}\pr}
\end{equation}
i.e. the energy is just $\omega_{\vec{p}\pr} = \sqrt{\vec{p}^{\prime^2} + m^2}$ which is the dispersions relation \index{dispersion relation} for a relativistic particle of mass $m$ and momentum $\vec{p}\pr$. We write $\omega_{\vec{p}} = E_{\vec{p}}$ from now on. We can also show that the total momentum and angular momentum operators;
\begin{align}
\vec P &= -\int{\upd{^3 x} \pi(\vec x) \nabla \phi(\vec x)} = \int{\frac{\ud^3 p}{(2\pi)^3} \vec p a_{\vec p}\dagg a_{\vec p}} \\
J_i &= -\frac{i}{2}\epsilon_{ijk}\int{\frac{\ud^3 p}{(2\pi)^3} a_{\vec p}\dagg\left(p_j \frac{\del}{\del p_k} - p_k \frac{\del}{\del p_j}\right)a_{\vec p}}
\end{align}
satisfy $\vec P \ket{\vec p} = \vec p \ket{\vec p}$ and $J_i \ket{\vec p = \vec 0} = 0$. This second equality tells us that the single particle states of the scalar field have spin $0$.

\paraskip
Now consider the more general multi-particle states, $\ket{\vec{p}_1, \ldots, \vec{p}_n} = a_{\vec{p}_1}\dagg \cdots a_{\vec{p}_n}\dagg\ket{0}$. The $a\dagg$ commute, so this is symmetric under interchange implying that the particles of the scalar field are also \emph{bosons}\index{boson}. The full Hilbert space\index{Hilbert space}, know as the \emph{Fock space}\index{Fock space} is spanned by
\begin{equation}
\set{\ket{0}, a_{\vec{p}_1}\dagg\ket{0}, a_{\vec{p}_1}\dagg a_{\vec{p}_2}\dagg\ket{0}, \ldots}
\end{equation}
The number operator\index{number operator} counts the number of particles;
\begin{equation}
N = \int{\frac{\ud^3 p}{(2\pi)^3} a_{\vec{p}}\dagg a_{\vec p}}, \quad N \ket{\vec{p}_1, \ldots, \vec{p}_n} = n\ket{\vec{p}_1, \ldots, \vec{p}_n}
\end{equation}
In the free theory, $\left[N, \text{H}\right] = 0$ so the particle number is actually conserved. This is certainly not true in the interacting theory\index{interacting theory} however.

\paraskip
Note that these momentum states are not localised in space, and even after taking a Fourier transform;
\begin{equation*}
\ket{\vec{x}} = \int{\frac{\ud^3 p}{(2\pi)^3}e^{i\vec{p}\cdot\vec{x}}\ket{\vec{p}}}
\end{equation*}
the localised states are still not normalisable; $\braket{\vec{x}}{\vec{x}} = \infty$. This is really the statement that $a_{\vec{p}}$ and $\phi(\vec{x})$ are not good operators on the Hilbert space. To construct well defined operators, we should consider a wave packet;
\begin{equation}
\ket{\varphi} = \int{\frac{\ud^3 p}{(2\pi)^3}e^{-i\vec{p}\cdot\vec{x}}\varphi(\vec{p})\ket{\vec{p}}} = \int{\frac{\ud^3 p}{(2\pi)^3}e^{-i\vec{p}\cdot\vec{x}}\varphi(\vec{p})a_{\vec{p}}\dagg \ket{0}}
\end{equation}
which we can show satisfies;
\begin{equation*}
\braket{\varphi}{\varphi} = \int{\upd{^3 p}\abs{\varphi(\vec{p})}^2}
\end{equation*}
So we deduce that states such that $\varphi(\vec{p})$ has a finite $L^2$ norm are good operators on the Hilbert space.
\subsection{Relativistic Normalisation}
We define the vacuum to be normalised; $\braket{0}{0} = 1$, then $\braket{\vec p}{\vec q} = \expval{a_{\vec p} a_{\vec q}\dagg}{0} = \expval{\left[a_{\vec p}, a_{\vec q}\dagg\right]}{0} = (2\pi)^3 \delta^{(3)}(\vec p - \vec q)$. We want to know if this is Lorentz invariant. Clearly the vacuum normalisation is since it is just a scalar but, a priori, the general one-particle state is not, and indeed it will need some modification. Consider a boost in the $3$-direction; then $p_3\pr = \gamma(p_3 + \beta E), E\pr = \gamma(E + \beta p_3)$. We can use a delta function identity;
\begin{equation}
\label{eq:deltaident}
\delta\left(f(x) - f(x_0)\right) = \frac{1}{\abs{f\pr(x_0)}} \delta(x - x_0)
\end{equation}
to deduce that;\footnote{Note that $E = \sqrt{p_i p^i + m^2} \Rightarrow \del_{p_3}E = \tfrac{p_3}{E}$ as claimed.}
\begin{align}
\delta^{(3)}(\vec p - \vec q) &= \delta(p_1 - q_1)\delta(p_2 - q_2)\delta(p_3 - q_3) \nonumber \\
&= \delta^{(3)}(\vec{p}\pr - \vec{q}\pr) \cdot \frac{\ud p_3\pr}{\ud p_3} = \delta^{(3)}(\vec{p}\pr - \vec{q}\pr) \gamma\left(1 + \beta \frac{\ud E}{\ud p_3}\right) \nonumber \\
&= \delta^{(3)}(\vec{p}\pr - \vec{q}\pr) \frac{\gamma}{E}(E + \beta p_3) = \delta^{(3)}(\vec{p}\pr - \vec{q}\pr)\frac{E\pr}{E}
\end{align}
We see then that whilst $\delta^{(3)}(\vec{p}- \vec{q})$ is not Lorentz invariant, $E_{\vec p}\delta^{(3)}(\vec{p} - \vec{q})$ is. Hence we define the normalised one particle states;
\begin{equation}
\ket{p} = \sqrt{2E_{\vec p}}a\dagg_{\vec p}\ket{0} \Rightarrow \braket{p}{q} = (2\pi)^3 \cdot 2\sqrt{E_{\vec p}E_{\vec q}} \delta^{(3)}(\vec p - \vec q)
\end{equation}
Because of this redefinition, we need to include factors of $\sqrt{2E_{\vec p}}$ elsewhere, for example. the identity on one particle states is now;
\begin{equation}
\left(\II\right)_{\text{one particle states}} = \int{\frac{\ud^3 p}{2 E_{\vec p}}\frac{1}{(2\pi)^3}\ket{p}\bra{p}}
\end{equation}
As a final point in this regard, note that, using \eqref{eq:deltaident};
\begin{equation}
\int{\upd{^4 p} \left.\delta(p_0^2 - \vec{p}^2 - m^2)\right|_{p_0 > 0}} = \int{\left.\frac{\ud^3 p}{2p_0}\right|_{p_0 = E_{\vec p}}}
\end{equation}
which justifies the fact that the integration measure $\left(\ud^3 p / 2E_{\vec p}\right)$ is Lorentz Invariant since the LHS is.\footnote{$\ud^4 p$ certainly is because $\det \text{M} = 1$ for $\text{M} \in \Orth{3,1}$, and the delta function is only dependent on Lorentz invariant quantities.}
\subsection{Complex Scalar Field\index{field!complex scalar}}
Consider now the Lagrangian;\footnote{If we write the complex field $\psi = \tfrac{1}{\sqrt{2}}(\phi_1 + i \phi_2)$, then expanding the Lagrangian gives the sum of the usual Lagrangian for two real scalar fields $\mL_i = \tfrac{1}{2}(\del \phi_i)^2 - \tfrac{1}{2}m^2 \phi_i^2$. Furthermore, this explains the presence of \emph{two} types of creation/annihilation operators, one for the real component of $\psi$ and one for the imaginary part.}
\begin{equation}
\mL = \del_\mu \psi^{\star} \del^\mu \psi - \mu^2 \psi^{\star} \psi
\end{equation}
which leads to the Euler-Lagrange equations\index{equation!Euler-Lagrange};
\begin{equation}
\del_\mu \del^\mu \psi + \mu^2 \psi = 0, \quad \del_\mu \del^\mu \psi^{\star} + \mu^2 \psi^{\star} = 0
\end{equation}
This allows us to expand;
\begin{align}
\psi &= \int{\frac{\ud^3 p}{(2\pi)^3}\frac{1}{\sqrt{2E_p}}\left(b_{\vec p}e^{i\vec{p}\cdot \vec{x}} + c\dagg_{\vec p}e^{-i \vec{p}\cdot \vec{x}}\right)} \\
\pi &=i \int{\frac{\ud^3 p}{(2\pi)^3}\sqrt{\frac{E_p}{2}}\left(b_{\vec p}\dagg e^{-i\vec{p}\cdot \vec{x}} + c_{\vec p}e^{i \vec{p}\cdot \vec{x}}\right)}
\end{align}
Then the commutation relations are $\left[\psi(\vec x), \pi(\vec y)\right] = i\delta^{(3)}(\vec x - \vec y)$ and $[\psi(\vec x), \pi\dagg(\vec y)] = 0$ etc. In terms of the creation and annihilation operators, $\left[b_{\vec p}, b\dagg_{\vec q}\right] = (2\pi)^3\delta^{(3)}(\vec p - \vec q) = \left[c_{\vec p}, c\dagg_{\vec q}\right]$ with all other commutators vanishing. The two Klein-Gordon equations\index{equation!Klein-Gordon} ensure that we have two types of creation operator, $b_{\vec p}\dagg, c_{\vec q}\dagg$, which we interpret as creating two types of particle with mass $\mu$; a particle and its anti-particle\index{anti-particle}. The conserved charge, after normal ordering is;
\begin{align}
Q &= i\int{\upd{^3 x} \dot{\psi}^{\star}\psi - \psi^{\star} \dot{\psi}} = i\int{\upd{^3 x}\pi\psi - \psi^{\star}\pi^{\star}} \nonumber \\
&= \int{\frac{\ud^3 p}{(2\pi)^3}\left(c_{\vec p}\dagg c_{\vec p} - b_{\vec p}\dagg b_{\vec p}\right)} \coloneqq N_c - N_b
\end{align}
We can also calculate the Hamiltonian;
\begin{equation}
\text{H} = \int{\frac{\ud^3 p}{(2\pi)^3} E_p \left(b\dagg_{\vec p} b_{\vec p} + c_{\vec p}\dagg c_{\vec p}\right)}
\end{equation}
from which we may deduce\footnotemark that $\left[\hamilt, Q\right] = 0$. In the free theory, it is true that $N_{c}$ and $N_{b}$ are conserved separately, however in the interacting theory (with the requisite symmetry), the total charge $Q$ still is.
\footnotetext{Define $B_{\vec p} \coloneqq b_{\vec p}\dagg b_{\vec p}$ and $C_{\vec p} \coloneqq c_{\vec p}\dagg c_{\vec p}$, then;
\begin{align*}
\left[\hamilt, Q\right] &= \int{\frac{\ud^3 p \ud^3 q}{(2\pi)^6}E_{p}\left[B_{\vec p} + C_{\vec p}, C_{\vec q} - B_{\vec q}\right]} \\
&= \int{\frac{\ud^3 p \ud^3 q}{(2\pi)^6}E_{p}\left(\left[C_{\vec p}, C_{\vec q}\right] - \left[B_{\vec p}, B_{\vec q}\right]\right)}
\end{align*}
Now, $\left[B_{\vec p}, B_{\vec q}\right] = b_{\vec p}\dagg b_{\vec p}b_{\vec q}\dagg b_{\vec q} - b_{\vec q}\dagg b_{\vec q}b_{\vec p}\dagg b_{\vec p} = b_{\vec p}\dagg \left[b_{\vec p}, b_{\vec q}\dagg\right] b_{\vec q} - b_{\vec q}\dagg \left[b_{\vec q}, b_{\vec p}\dagg\right] b_{\vec p}$, so;
\begin{equation*}
\left[\hamilt, Q\right] = \int{\frac{\ud^3 p \ud^3 q}{(2\pi)^3}E_p \delta^{(3)}(\vec p - \vec q)\left(c_{\vec p}\dagg c_{\vec q} - c_{\vec q}\dagg c_{\vec p} - b_{\vec p}\dagg b_{\vec q} + b_{\vec q}\dagg b_{\vec p}\right)}
\end{equation*}
which vanishes on integrating $\ud^3 p \ud^3 q$.
}
\subsection{The Heisenberg Picture\index{picture!Heisenberg}}
So far in the Schr{\"o}dinger picture\index{picture!Schr{\"o}dinger}, $\phi(\vec x)$ does not depend on time. In the Heisenberg picture all the time dependence is assigned to the operators;
\begin{equation}
\mO_{\hamilt}(t) = e^{iHt} \mO_{\mathcal{S}} e^{-iHt} \Rightarrow \frac{\ud \mO_{\hamilt}(t)}{\ud t} = i\left[\hamilt, \mO_{\hamilt}\right]
\end{equation}
Then the Heisenberg fields now satisfy equal time commutation relations;
\begin{equation}
\left[\phi(\vec x, t), \phi(\vec y, t)\right] = \left[\pi(\vec x, t), \pi(\vec y, t)\right] = 0
\end{equation}
\begin{equation}
\left[\phi(\vec x, t), \pi(\vec y, t)\right] = i\delta^{(3)}(\vec x - \vec y)
\end{equation}

%\end{multicols*}


\documentclass[10pt]{report}

\usepackage{subcaption} % for subfigures
\usepackage{amsthm} % for QED
%\usepackage{algpseudocode} % for pseudo-code
\usepackage{mathtools} % for delimiter

\usepackage{listings} % for code
\lstset
{
	language=Matlab,
	frame=single,
	basicstyle=\footnotesize,
	captionpos=b,
	numbers=left,
	stepnumber=1,
	showstringspaces=false,
	tabsize=4,
	breaklines=true,
	breakatwhitespace=false,
}

\usepackage{siunitx} % for scientific notation
% for `e' in scientific notation
\sisetup{output-exponent-marker=\ensuremath{\mathrm{e}}}

\usepackage{float} % for figure [H]
\usepackage{booktabs} % for tabular
\usepackage{caption} % for \caption*
\usepackage[export]{adjustbox} % for valign=t
\usepackage{array} % for column type m
\usepackage{verbatim}
\usepackage{graphicx}
\graphicspath{ {imgs/} }
\usepackage{fancyhdr}
\usepackage{amssymb}
\usepackage{amsmath}

%%%%%% Pagination
\setlength{\topmargin}{-.3 in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textheight}{9.in}
\setlength{\textwidth}{6.5in}

%Title page
\newcommand{\hwTitle}{Homework \#1}
\newcommand{\hwCourse}{Numerical Differential Equations/Computational Mathematics II}
\newcommand{\hmwkClassInstructor}{Professor Shuwang Li}

\title{
	\vspace{2in}
	\textmd{\textbf{\hwCourse\\\hwTitle}}\\
	\vspace{0.3in}\large{\textit{\hmwkClassInstructor}}
	\vspace{3in}
}

%\title{Homework 1}
\author{\textbf{Zhihao Ai}}
\date{}

%Header setting.
\pagestyle{fancy}
\fancyhead[L]{Zhihao Ai}
\fancyhead[C]{Math 478}
\fancyhead[R]{Homework 1}
%%%%%%

%Global setting.
\everymath{\displaystyle}
\setlength\parindent{0pt}

%Custom general commands.
\newcommand{\ds}{\displaystyle}
\newcommand{\f}[1] {f\left(#1\right)}
\newcommand{\eva}[2] {\left. #1 \right|_{#2}}
\newcommand{\dintt}[4] {\int_{#1}^{#2} #3 d#4}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{C}{M{3em}}
\newcolumntype{D}{M{5em}}

\DeclarePairedDelimiter{\paren}{(}{)}
\newcommand{\abs}[1] {\left| #1 \right|}

%Custom local commands
\newcommand{\varQa} {\sqrt{\frac{3}{5}}}

\begin{document}

\maketitle

\section*{Question 1.}
\begin{enumerate}
	\item
	(Section 6.1 Problem 23)\\
	Consider the data
	\\
	\[
		\begin{tabular}{l M{5em} M{2em} M{5em}}
			\toprule
			$x$ & $-\sqrt{\frac{3}{5}}$ & $0$ & $\sqrt{\frac{3}{5}}$ \\ \addlinespace[0.4em]
			\hline \addlinespace[0.4em]
			$f(x)$ & $\f{-\sqrt{\frac{3}{5}}}$ & $f(0)$ & $\f{\sqrt{\frac{3}{5}}}$ \\
			\bottomrule
		\end{tabular}
	\]
	\\
	What are the Newton interpolation polynomial and the Lagrange interpolation polynomial for these data?

	Newton:
	\[
	c_k = \frac{y_k - p_{k-1}(x_k)}{(x_k-x_0)(x_k-x_1)\cdots(x_k-x_{k-1})}
	\]
	\begin{align*}
		c_0 &= \f{-\sqrt{\frac{3}{5}}}
			& p_0(x)
			&= c_0
			\\
		c_1
			&= \frac{\f{0} - p_0(0)}{0 - \paren*{-\sqrt{\frac{3}{5}}}}
			& p_1(x)
			&= c_0 + c_1 \paren*{x - \paren*{-\sqrt{\frac{3}{5}}}}
			\\
		c_2
			&= \frac{\f{\sqrt{\frac{3}{5}}} - p_1\paren*{\sqrt{\frac{3}{5}}}}{\paren*{\sqrt{\frac{3}{5}} - \paren*{-\sqrt{\frac{3}{5}}}} \paren*{\sqrt{\frac{3}{5}} - 0}}
			& p_2(x)
			&= c_0 + c_1\paren*{x-\paren*{-\sqrt{\frac{3}{5}}}} + c_2\paren*{x-\paren*{-\sqrt{\frac{3}{5}}}} \paren*{x-0}
	\end{align*}

	Lagrange:
	\[
	l_i(x) = \prod_{\substack{j=0 \\ j\ne i}}^{n} \frac{x - x_j}{x_i - x_j}
	\]
	\begin{multline*}
	p_2(x) = \sum_{i=0}^{n} y_i l_i(x)
		= \f{-\sqrt{\frac{3}{5}}} \cdot \frac{\paren*{x-0} \paren*{x - \sqrt{\frac{3}{5}}}}{\paren*{-\sqrt{\frac{3}{5}} - 0} \paren*{-\sqrt{\frac{3}{5}} - \sqrt{\frac{3}{5}}}}
		+ \f{0} \cdot \frac{\paren*{x - \paren*{-\sqrt{\frac{3}{5}}}} \paren*{x - \sqrt{\frac{3}{5}}}}
		 {\paren*{0 - \paren*{-\sqrt{\frac{3}{5}}}} \paren*{0 - \sqrt{\frac{3}{5}}}}
		 \\
		+ \f{\sqrt{\frac{3}{5}}} \cdot \frac{\paren*{x - \paren*{-\sqrt{\frac{3}{5}}}} \paren*{x-0}} {\paren*{\sqrt{\frac{3}{5}} - \paren*{-\sqrt{\frac{3}{5}}}} \paren*{\sqrt{\frac{3}{5}} - 0}}
	\end{multline*}

	\item
	(Section 6.1 Problem 15)\\
	What is the final value of $v$ in the algorithm shown?

	$v \leftarrow c_{i-1}$\\
	\textbf{for} $j = i$ \textbf{to} $n$ \textbf{do}\\
	\hspace*{4ex} $v \leftarrow vx + c_j$\\
	\textbf{end do}

	What is the number of additions and substractions involved in this algorithm?
	\begin{align*}
		v &= ((((c_{i-1}x + c_i)x + c_{i+1})x + c_{i+2})x + \cdots c_{n-1})x + c_n\\
			&= c_{i-1}x^{n-i+1} + c_ix^{n-i} + \cdots + c_{n-1}x + c_n
	\end{align*}
	The number of additions is $n-i+1$; no substractions are involved.

	\item
	(Section 6.1 Problem 16)\\
	Write an efficient algorithm for evaluating
	\[
	u = \sum_{i=1}^{n} \prod_{j=1}^{i} d_j
	\]
	$u \leftarrow d_{n}$\\
	\textbf{for} $i = n-1$ \textbf{to} $1$ \textbf{step} $-1$ \textbf{do}\\
	\hspace*{4ex} $u \leftarrow d_i*(1+u)$\\
	\textbf{end do}
\end{enumerate}

\section*{Question 2.}
(Section 6.1 Problem 13)\\
Prove that if we take \textit{any} set of 23 nodes in the interval $[-1, 1]$ and interpolate the function $f(x) = \cosh{x}$ with a polynomial $p$ of degree 22, then the relative error $\abs{p(x)-f(x)}/\abs{f(x)}$ is no greater than $5 \times 10^{-16}$ on $[-1, 1]$.

Denote the nodes as $x_i, i=0,1,\cdots,22$. According to Theorem 2,
\[
f(x) - p(x) = \frac{1}{(n+1)!} \cdot f^{(n+1)}(\xi_x) \cdot \prod_{i=0}^{n} (x-x_i)
	= \frac{1}{23!} \cdot f^{(23)}(\xi_x) \cdot \prod_{i=0}^{22} (x-x_i)
\]
Since $f^{(23)}(\xi_x) = \sinh{\xi_x}$, which increases monotonically,
\[
f^{(23)}(\xi_x) < \sinh{1},\ \xi_x\in [-1, 1]
\]
Since $x\in [-1, 1]$,
\[
\prod_{i=0}^{22} (x-x_i) \le \prod_{i=0}^{22} 2 = 2^{23}
\]
Since $\cosh{x} \ge 1, f(x)\ge 1$. Therefore,
\[
\frac{\abs{p(x)-f(x)}}{\abs{f(x)}} < \frac{\frac{1}{23!} \cdot \sinh{1} \cdot 2^{23}}{1}
	\approx 3.81336\times 10^{-16}
	< 5 \times 10^{-16}
\]
\qed

\section*{Question 3.}
(Section 6.2 Problem 24)\\
Write the Newton interpolating polynomial for these data:
%\\
\[
	\begin{tabular}{lcccc}
		\toprule
		x & 4 & 2 & 0 & 3 \\ \midrule
		f(x) & 63 & 11 & 7 & 28 \\
		\bottomrule
	\end{tabular}
\]
\\
By Theorem 1,
\[
f[x_0, x_1, \cdots, x_n] = \frac{f[x_1, x_2, \cdots, x_n] - f[x_0, x_1, \cdots, x_{n-1}]}{x_n - x_0}
\]
we get the divided differences table:
\[
\begin{array}{cc|ccc}
4 & 63 & 26 & 6 & 1 \\
2 & 11  & 2   & 5 \\
0 & 7   & 7 \\
3 & 28
\end{array}
\]
Therefore the Newton polynomial is
\[
p(x) = 63 + 26(x-4) + 6(x-4)(x-2) + (x-4)(x-2)x
\]

\section*{Question 4.}
\begin{enumerate}
	\item
	(Section 6.4 Problem 14)\\
	Determine whether this function is a natural cubic spline:
	\[
	f(x) =
	\begin{cases}
		1+x-x^3, &x\in [0,1]\\
		1-2(x-1)-3(x-1)^2+4(x-1)^3, &x\in [1,2]\\
		4(x-2)+9(x-2)^2-3(x-2)^3, &x\in [2,3]\\
	\end{cases}
	\]
	By inspection, the order of $f(x)$ is no greater than 3.\\
	The first derivative of $f(x)$ is continuous:
	\[
	f'(x) =
	\begin{cases}
	1-3x^2, &x\in [0,1]\\
	-2-6(x-1)+12(x-1)^2, &x\in [1,2]\\
	4+18(x-2)-9(x-2)^2, &x\in [2,3]\\
	\end{cases}
	\]
	The second derivative of $f(x)$ is also continuous:
	\[
	f''(x) =
	\begin{cases}
	-6x, &x\in [0,1]\\
	-6+24x, &x\in [1,2]\\
	18-18(x-2), &x\in [2,3]\\
	\end{cases}
	\]
	Define $S_i(x),\ i=0,1,2$ as the sub-functions of $f(x)$ on $[0,1], [1,2], [2,3]$, respectively.
	\begin{align*}
		S_0(1) &= 1 = S_1(1) & S_1(2) &= 0 =S_2(2)\\
		S_0'(1) &= -1 = S_1'(1) & S_1'(2) &= 4 =S_2'(2)\\
		S_0''(1) &= -6 = S_1''(1) & S_1''(2) &= 18 =S_2''(2)
	\end{align*}
	Also we have
	\[
	f''(0) = f''(3) = 0
	\]
	Therefore, this function is a natural cubic spline.

	\item
	(Section 6.4 Problem 20)\\
	Determine whether the coefficients $a, b, c,$ and $d$ exist so that the function
	\[
	S(x) =
	\begin{cases}
	1-2x, &x\in (-\infty,-3]\\
	a+bx+cx^2+dx^3, &x\in [-3,4]\\
	157-32x, &x\in [4,+\infty)\\
	\end{cases}
	\]
	is a natural cubic spline for the interval $[-3, 4]$.

	Take the first and second derivatives of $S(x)$ and we have
	\[
	S'(x) =
	\begin{cases}
	-2, &x\in (-\infty,-3]\\
	b+2cx+3dx^2, &x\in [-3,4]\\
	-32, &x\in [4,+\infty)\\
	\end{cases}
	,\
	S''(x) =
	\begin{cases}
	0, &x\in (-\infty,-3]\\
	2c+6dx, &x\in [-3,4]\\
	0, &x\in [4,+\infty)\\
	\end{cases}
	\]
	For $S(x)$ to be a natural cubic spline, we need to satisfy
	\[
	\begin{cases}
	S_0(-3) = S_1(-3)\\
	S_0'(-3) = S_1'(-3)\\
	S_0''(-3) = S_1''(-3)\\
	S_1(4) = S_2(4)\\
	S_1'(4) = S_2'(4)\\
	S_1''(4) = S_2''(4)
	\end{cases}
	\Rightarrow
	\begin{cases}
	7 = a - 3 b + 9 c - 27 d\\
	-2 = b - 6 c + 27 d\\
	0 = 2 c - 18 d\\
	a + 4 b + 16 c + 64 d = 29\\
	b + 8 c + 48 d = -32\\
	2 c + 24 d = 0
	\end{cases}
	\]
	This system has no solution, as shown below:
	\[
	\left(
	\begin{array}{@{}cccc|c@{}}
		1& -3& 9& -27& 7\\
		0& 1& -6& 27& -2\\
		0& 0& 2& -18& 0\\
		1& 4& 16& 64& 29\\
		0& 1& 8& 48& -32\\
		0& 0& 2& 24& 0
	\end{array}
	\right)
	\xRightarrow{\text{R.R.}}
	\left(
	\begin{array}{@{}cccc|c@{}}
	1& 0& 0& 0& 0\\
	0& 1& 0& 0& 0\\
	0& 0& 1& 0& 0\\
	0& 0& 0& 1& 0\\
	0& 0& 0& 0& 1\\
	0& 0& 0& 0& 0
	\end{array}
	\right)
	\]
	Therefore, such $a,b,c,$ and $d$ do not exist.
\end{enumerate}

\section*{Question 5.}
(Section 6.1 Problem 37)\\
The first U.S. postage stamp was issued in 1885, with the cost to mail a letter set at 2 cents. In 1917, the cost was raised to 3 cents but then was returned to 2 cents in 1919. In 1932, it was upped to 3 cents again, where it remained for 26 years. Then a series of increases took place as follows: 1958 = 4 cents, 1963 = 5 cents, 1968 = 6 cents, 1971 = 8 cents, 1974 = 10 cents, 1978 = 15 cents, 1981 = 18 cents in March and 20 cents in October, 1985 = 22 cents, 1988 = 25 cents, 1991 = 29 cents, 1995 = 32 cents, 1999 = 33 cents, and 2001 = 34 cents. Determine the Newton interpolation polynomial for these data. Based on this, when will it cost \$1 to mail a letter? When will it cost \$10?

The following code is for calculating the coefficients and each $p(x)$:
\lstinputlisting[caption={Coefficients}]{coefficients.m}
\lstinputlisting[caption={Newton interpolation polynomial}]{newtonPoly.m}
The code below is for displaying coefficients and years when it will cost \$1 and \$10.
\lstinputlisting[caption={Find the year}]{q5p37stamp.m}

It produces the coefficent vector
\begin{multline*}
d=[2,
0.03125,
-0.015625,
1.15077741e-03,
-2.89440714e-05,
6.78486768e-07,
-1.52159492e-08,\\
8.18727496e-10,
-9.10167759e-11,
9.40668614e-12,
-9.18167360e-13,
1.69879421e-13,\\
-2.96877259e-14,
3.92879060e-15,
-3.91394609e-16,
2.83733707e-17,
-1.60579668e-18,\\
8.19150612e-20]
\end{multline*}
Therefore, the Newton interpolation polynomial is
\begin{multline*}
	p(x) = 2 + 0.03125(x-1885) - 0.015625(x-1885)(x-1917) + \cdots +
	\\ 8.19150612e-20(x-1885)(x-1917)\cdots(x-1999)(x-2001)
\end{multline*}
By this interpolation polynomial, it costs \$1 to mail a letter in 2001.030137, which is in January, 2001; it cost \$10 in 2001.309589, which is in April, 2001.

\section*{Computer Assignment}
(Section 6.1 Problem 36)\\
The function $1/(1+x^2)$ and $e^{-x^2}$ have a similar appearance. Do they behave similarly in the interpolation process for equally spaced nodes?\\
Use the Newton interpolating polynomial $p_n(x)$ with $n=5,10,15$ on $[-5, 5]$. In each case, compute the error $f(x) - p_n(x)$ for $N = 30$ equally spaced points on $[-5, 5]$. Comment on what you get.
\lstinputlisting[caption={Interpolation on {$[-5,5]$}}]{interp.m}
\lstinputlisting[caption={Plotting functions and calculating errors}]{runge.m}
Denote $1/(1+x^2)$ as $f_a(x)$ and $e^{-x^2}$ as $f_b(x)$. The code above produces the following plots:
\begin{figure}[H]
	\centering
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=\linewidth]{functiona.jpg}
		\caption*{$f_a(x)$ and its polynomial interpolations}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=\linewidth]{functionb.jpg}
		\caption*{$f_b(x)$ and its polynomial interpolations}
	\end{subfigure}%
\end{figure}
The errors for $N = 30$ equally spaced points on $[-5, 5]$ are:
\begin{align*}
	f_a(x) - p_{5}(x) &= 1.257120 & f_b(x) - p_{5}(x) &= 1.416331\\
	f_a(x) - p_{10}(x) &= -4.711533 & f_b(x) - p_{10}(x) &= -5.689687\\
	f_a(x) - p_{15}(x) &= -2.607657 & f_b(x) - p_{15}(x) &= -2.487981
\end{align*}
The interpolation process for equally spaced nodes for function $1/(1+x^2)$ and $e^{-x^2}$ behave similarly. For each function, the interpolating polynomial of degree 5 does not fit the curve well at the center, but on the other hand it is relatively close to the curve at the edges. In contrast, even though the polynomials of higher degree like $p_{10}(x)$ and $p_{15}(x)$ fit the curve nicely around the center, they oscillate dramatically at the edges of the interval, leading to errors even greater than the polynomial of degree 5. The comparison clearly demostrates Runge's phenomenon, which means using polynomials of high degree for interpolation can introduce much error.

\end{document}


\documentclass{article}
\usepackage{ws_template}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{a4wide}
\usepackage{graphicx}
\usepackage{booktabs}

\title{homework sheet 04}

\author{
	\name{Denys Sobchyshak}\\
	\imat{03636581}\\
	\email{denys.sobchyshak@gmail.com}
	\And
	\name{Sergey Zakharov}\\
	\imat{03636642}\\
	\email{ga39pad@mytum.de}
}

\begin{document}
\maketitle

\section{Still refreshing}
\textbf{Problem 1:} \\\\
	 Let X represent the number of flips which were made. Then the possible values of X
	are $1, 2, ... ,$ and the distribution function of X is deﬁned by.
	\[ m(i) =\frac{1}{2^i} \]
	Thus,
	\begin{eqnarray*}
  	E(X) & = & \sum_{i=1}^{\infty}{i \frac{1}{2^i}} \\
 	  & = & 1+ \frac{1}{2} +\frac{1}{2^2} + \dots \\
  	 & = & 2
	\end{eqnarray*}

	So, the expected number of flips until one head is thrown is 2. \\
	Now, Let T represent the expexted number of tails. The possible values of T are 0, 1 and 2. The corresponding probabilities are 1/4, 1/2 and 1/4. Thus,
	\[ E(T) = 0(\frac{1}{4}) + 1(\frac{1}{2}) + 2 (\frac{1}{4}) = 1\]
	The expected number of heads equals to the expected number of tails $E(T) = E(H) = 1$

\section{Parameter Estimation}
\subsection{Coins}
\textbf{Problem 2:}\\\\
	The likelihood function $L(\theta)$ is, by definition:
	\begin{eqnarray*}
  	L(\theta) & = &\prod_{i=i}^{n}{P(X_i = x_i|\theta)} \\
 	  & = & \theta^{x_1}(1-\theta)^{1-x_1} \times \theta^{x_2}(1-\theta)^{1-x_2} \times \dots \times \theta^{x_n}(1-\theta)^{1-x_n} \\
  	 & = & \theta^{\sum{x_i}}(1-\theta)^{n-\sum{x_i}}
	\end{eqnarray*}
Now, in order to implement the method of maximum likelihood, we need to find the $\theta$ that maximizes the likelihood $L(\theta)$.
\[ ln L(\theta) = (\sum{x_i})ln(\theta) + (n-\sum{x_i})ln(1-\theta) \]
Differentiating with respect to $\theta$ results in:
\[ \frac{d ln L(\theta)}{d\theta} = \frac{\sum{x_i}}{\theta} - \frac{n-\sum{x_i}}{1-\theta} \]
Setting the derivative to zero we get:
\begin{eqnarray*}
(\sum{x_i})(1- \theta) - (n-\sum{x_i})\theta = 0 \\
\sum{x_i} - n\theta = 0
\end{eqnarray*}
Therefore the MLE for $\theta$ is:
\[ \hat{\theta} = \frac{\sum{x_i}}{n} \]

\textbf{Problem 3:}\\\\
Given the observations and $\alpha$,$\beta$ as beta distribution parameters we can write the expected posterior mean for $\mu$ as follows:
\[ E_{\mu}[\mu|\mathcal{D}]=\frac{m+\alpha}{m+\ell+\alpha+\beta}=\frac{m}{m+\ell+\alpha+\beta}+
\frac{\alpha}{m+\ell+\alpha+\beta}\]
However:
\[\frac{m}{m+\ell+\alpha+\beta}=\frac{\frac{m}{m+\ell}}{\frac{m+\ell+\alpha+\beta}{m+\ell}}\]
\[\frac{\alpha}{m+\ell+\alpha+\beta}=\frac{\frac{\alpha}{\alpha+\beta}}{\frac{m+\ell+\alpha+\beta}{\alpha+\beta}}\]
Since $\frac{\alpha}{\alpha+\beta}$ is the prior mean value of $\mu$ and $\frac{m}{m+\ell}$ is the maximum likelyhood estimate we have shown what was being asked.

\subsection{Poisson distribution}
\textbf{Problem 4:}\\\\
The likelihood function is:
\[ L(\lambda) =\prod_{i=1}^{n}{\frac{\lambda^{x_i}e^{-\lambda}}{x_i !}} = \frac{\lambda^{\sum {x_i}}e^{-\lambda}}{\prod{x_i !}} \]
Then, taking the natural logarithm, we have:
\[ ln L(\lambda) = \sum_{i=1}^{n}{x_i ln \lambda} - n\lambda - \sum_{i=1}^{n}{ln(x_i !)} \]
Differentiating with respect to $\lambda$ results in:
\[ \frac{d ln L(\lambda)}{d\lambda} = \frac{\sum{x_i}}{\lambda} - n \]
Setting the derivative to zero we get:
\[ \frac{\sum{x_i}}{\lambda} - n = 0 \]
Therefore the MLE for $\lambda$ is:
\[  \hat{\lambda} = \frac{\sum{x_i}}{n}\]
To show that the maximum likelihood estimator is an unbiased estimator of $\lambda$ we have to show that $E(\hat{\lambda}) = p$.
\[ E(\hat{\lambda}) = E() = \frac{1}{n}\sum_{i=1}^{n}{E(X_i)} =\frac{1}{n}\sum_{i=1}^{n}{p} = \frac{1}{n}(np) = p \]
Thus, the estimator is unbiased.

\end{document}


\section{Solving and Estimating the Extended Model}

\subsection{Solution}

For this extended model I only use the Double Deep Q-Network agent, since it was shown with the simpler environment, to have comparable performance to the VFI implementation and Deep Q-network. The model is solved by running 3000 episodes. As was true for the simple model, the neural network has the best performance if states are scaled mean 0 and a standard deviation of 1. In practice this is done by implementing a transformer in my agent that scales the states.  The transformer is also capable of doing an inverse transformation. The rewards are also scaled. This slightly improves performance, but the primary reason is, that it helps track the learning. I scale the rewards to have a variance of about 1, and let them have the same mean conditional of the $\beta_L$  value! I train the algorithm for 3000 episodes, have the hyper parameters of the algorithm being: $\gamma=0.99$ representing the impatience of the agent. The agent is initialized with $\epsilon=1.0$ which decays by $0.9999$ for each step the agent performs. The learning rate is $\alpha=0.0005$. The size of the memory buffer is one million rows, and I train with a batch size=64. I let the minimum exploration rate in training be $0.01$.  The architecture of the network is identical to the one used previously: An input layer of same size as the state space, 2 fully connected layers of size 256 with rectified linear units as activation functions, and a linear output layer of the same size as the action space. At the beginning of each episode a random $\beta_L \sim Uniform(0, 60)$ is drawn, allowing the agent to step through an episode until termination with given $\beta_L$. Finally the target network inherits the policy weights every $100$'th step. A score for every 50'th episode is calculated, taking the average of the previous 50 episodes. If the current iteration of the model beats the high score, the weights of the neural network is saved. The estimation and simulation is performed with the weights that yields the highest score for 50 consecutive episodes.

\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.4]{figures/ddqn_extended_model_training_performance.png}
    \caption{Training Performance of Double DQN Agent - Extended Model}
    \label{fig:training_extended}
\end{figure}

Looking to figure \ref{fig:training_extended} the agent clearly learns to navigate in the environment. After about 1000 episodes the agent seems to have learned to navigate the environment! The maximum score appears at around episode 1400, which is the weights used for estimation and simulations. The asymptotic training performance is about 177 comparing to an initial score of approximately zero.

\subsection{Estimation}

As was the case with the simpler model, only a single parameter $\beta_L$ needs to be estimated. Again, just as was the case before with the simpler model, I extend the state space to contain $\beta_L$. I use a grid search in the range $\beta_L \in [0, 60]$, simulating $N=800$ observations, calculating the objective function. I use the same seed in each iteration of the optimization process. To address the short comings of the simple model, I expand the objective function of the optimization problem. In the initial model too many women choose not to be part of the labour force yielding unrealistic results. In response to this problem the new objective function extends to two broad goals: Let the right number of women be out of the labour force (around 15 \%) and fit the curve of number of working hours for women. The first objective, \textit{objective 1}, is formulated as:

\begin{equation}
    \text{objective 1} = \lsp\frac{\sum_{i=1}^{N} \sum_{q=Q_{\min}}^{Q_{\max}} \mathbf{1}\{H_{i,q} = 0\}}{ N \cdot (Q_{\max} - Q_{\min} )} - 15\% \rsp^2
\end{equation}

The second objective is formulated the same way as it was when first estimating the simple model, which correspond the conditional expectation of supplied number of working hours conditional on the age and of being in the labour force $ \E[H \mid Q=q, H>0]$. The desired outcome is for this to be true for all ages from 18 to 60. $\mu_q$ is the empirical moment found using the data \textbf{LIGEF15}:

\begin{equation}
    \text{Objective 2} = \sum_{q=Q_{\min}}^{Q_{\min}} \lsp \mu_q  - \frac{1}{\sum_{i=1}^{N} \mathbf{1}\{H_{i,q} > 0\}}\sum_{i=1}^N (H_{i,q})\rsp^2
\end{equation}
The description of the objectives can be translated into a more formal formulation. The number of moments are $\#_{moments} = 1 + (Q_{\max} - Q_{\min}) = 1 + 60 - 18 = 43$. The weighing of these moments would usually be done by some weight matrix $W$ in an equation of the form: $[\hat{m} - \tilde{m}]^{\top} W^{-1} [\hat{m} - \tilde{m}]$, where $\tilde{m}$ is a vector of empirical moments and $\hat{m}$ is a vector of simulated moments allowing for the methods of moments estimation. The choosing of the weight matrix is application specific. \textcite{eisenhauer_estimation_2015} suggests the choice in that setting should be the inverse variance of the empirical moments $\tilde{m}_j$, on the diagonal of the weight matrix (zeros else), letting the $j$'th moment correspond to the $j$'th weight. This is however not possible in this application, due to the fact, that I only have access to aggregated data from statistics Denmark. Instead, I manually choose scales such that \textit{objective 1} is equally weighted to \textit{objective 2}. This first and foremost requires a scaling of the moments. And secondly, all this requires a re-weighing since there are 42 moments composing \textit{objective 2} and only a single moment composing \textit{objective 1}. Since the distance between the empirical and the simulated moment is squared, the scaling must be performed before the squaring. Finally, since the weight matrix is chosen as it is, a transformation can be performed such that instead of a matrix product it can be considered a sum: $\sum_{j = 1}
^{43} ( \hat{m}_j - \tilde{m}_j )^2$, becoming a mean squared error optimization problem. It is implied that $N$ agents is simulated conditional on a value of $\beta_L$. The objective function is:

\begin{multline}
   \text{Objective}(\beta_L) =  \lsp 37 \cdot \lp\frac{\sum_{i=1}^{N} \sum_{q=Q_{\min}}^{Q_{\max}} \mathbf{1}\{H_{i,q} = 0\}}{ N \cdot (Q_{\max} - Q_{\min} )} - 15\% \rp \rsp^2 \\ + \frac{1}{Q_{\max} - Q_{\min}}\sum_{q=Q_{\min}}^{Q_{\max}} \lsp \mu_q - \frac{1}{\sum_{i=1}^{N} \mathbf{1}\{H_{i,q} > 0\}}\sum_{i=1}^N (H_{i,q})\rsp^2
\end{multline}

\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.4]{figures/ddqn_extended_model_estimation_beta_L.png}
    \caption{Estimation of $\beta_L$ for the Extended Model}
    \label{fig:estimation_extended}
\end{figure}

The estimated value of $\beta_L = 24.49$. Figure \ref{fig:estimation_extended} shows the grid search, and finds that optimization problem, contains a minimum at $\beta_L = 24.49$, suggesting that the range of the grid is adequate for the estimation problem. I take the $\log (\cdot)$ of the mean squared error to better represent it in figure \ref{fig:estimation_extended}.


\documentclass{parcfd2015}

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\title{PetIBM - A PETSc-based Immersed Boundary Method code}

\author{OLIVIER P. MESNARD$^{*}$, ANUSH KRISHNAN$^{*}$ \\ AND LORENA A. BARBA$^{*}$}

\heading{Olivier P. Mesnard, Anush Krishnan and Lorena A. Barba}

\address{$^{*}$ Mechanical and Aerospace Engineering, The George Washington University\\
Washington, DC, 20052, United-States\\
e-mail: mesnardo@gwu.edu, web page: lorenabarba.com}

\keywords{Immersed Boundary Method, PETSc, flying snake}

\abstract{A new, open-source \texttt{PETSc}-based immersed boundary method code is under development that uses a fully discrete projection formulation. Its initial purpose is to study the three-dimensional flow around an accurate cross-sectional shape of the flying snake species \textit{Chrysopelea paradisi}. We analyze vorticity structures in the wake and explain the enhanced lift generation of the snake at a particular angle of attack.}

\begin{document}
\maketitle

\section{IMMERSED BOUNDARY METHOD}

Immersed boundary methods (IBM) form a class of techniques in computational fluid dynamics where an immersed boundary is represented by a collection of Lagrangian points that do not coincide with the Eulerian grid nodes. They are particularly useful to simulate flows over complex and moving geometries. Simple, structured Cartesian meshes covering the entire physical domain (including the solid region) can be used, requiring low memory storage. The governing equations are solved over the whole domain and the key is finding a way to incorporate the boundary conditions on the immersed surface.

We use the method proposed by Taira and Colonius \cite{Taira_Colonius_2007} in which the momentum equations are augmented by a forcing term that acts as a Lagrange multiplier to bring the fluid to rest in the vicinity of the body surface. The fully-discrete modified Navier-Stokes equations produce an algebraic system that is solved via a projection method by performing a block LU decomposition \cite{Perot_1993}.

\section{PETIBM}

We use the open-source library \texttt{PETSc} \cite{PETSc_webpage_2014} to build the IBM code, taking advantage of its efficient data structures and routines to solve partial differential equations on multi-CPUs. The \texttt{PETSc} data structure \textit{distributed array} allows us to perform a logically Cartesian decomposition, such that nodal values spatially close in the physical domain are stored on the same process, thus, minimizing communications when using finite-difference stencils. Explicit terms of the Navier-Stokes system are stored using \textit{local vectors} that include ghost-cell values while \textit{global vectors} are used in sparse linear algebra routines.

The full code, named \texttt{PetIBM}, is open-source, released under an MIT License and hosted on the version-controlled platform GitHub \cite{PetIBM}.

\section{APPLICATION TO FLYING SNAKES}

We study the aerodynamics of the \textit{Chrysopelea paradisi}, a species of flying snake. Previous experimental work \cite{Holden_et_al_2014} reported enhanced lift force on a snake gliding at angle of attack of $35^o$ for flows with Reynolds number beyond $9000$. Two-dimensional numerical investigations confirmed a spike in the lift curve at this particular angle of attack ($Re=2000$) \cite{Krishnan_et_al_2014}. Using \texttt{PetIBM}, we aim to understand the three-dimensional wake structures responsible for high gliding performances of the paradise tree snake.

\begin{figure}[h!]
\centering
\includegraphics[width=8cm]{images/flying_snake_petibm.png}
\caption{Contours of the spanwise (red and blue) and streamwise (grey) components of the vorticity shed in the wake of an infinitely long cylinder with cross-section of the \textit{Chrysopelea paradisi}.}
\label{flying_snake_petibm}
\end{figure}

\begin{thebibliography}{99}
\bibitem{PETSc_webpage_2014} Balay S., Abhyankar S., Adams M.F., Brown J., Brune P., Buschelman K., Eijkhout V., Gropp W.D., Kaushik D., Knepley M.G., Curfman McInnes L., Rupp K., Smith B.F. and Zhang H. PETSc Web page. \texttt{http://www.mcs.anl.gov/petsc} (2014).
\bibitem{Holden_et_al_2014} Holden D., Socha J.J., Cardwell N.D. and Vlachos P.P. Aerodynamics of the flying snake Chrysopelea paradisi: how a bluff body cross-sectional shape contributes to gliding performance. \textit{J. Exp. Biol.} (2014) \textbf{217}:382--394.
\bibitem{PetIBM} Krishnan A. and Barba L.A. PetIBM - A 3D and parallel PETSc-based immersed boundary method code. \texttt{https://www.github.com/barbagroup/PetIBM}.
\bibitem{Krishnan_et_al_2014} Krishnan A., Socha J.J., Vlachos P.P. and Barba L.A. Lift and wakes of flying snakes. \textit{Phys. Fluids} (2014) \textbf{26(3)}:031901.
\bibitem{Perot_1993} Perot J.B. An analysis of the fractional step method. \textit{J. Comp. Phys.} (1993) \textbf{108(1)}:51--58.
\bibitem{Taira_Colonius_2007} Taira K. and Colonius T. The immersed boundary method: A projection approach. \textit{J. Comp. Phys.} (2007) \textbf{225(2)}:2118--2137.
\end{thebibliography}

\end{document}


\section{Instance models and instance graphs}
\label{sec:transformation_framework:instance_models_and_instance_graphs}

In the previous section, the structure of the framework was applied to type models and type graphs. In this section, the structure will be applied to instance models and instance graphs. Since instance models and instance graphs directly depend on type models and type graphs, some definitions will be borrowed from the previous section.

First, the general structure of the framework applied to instance models and instance graphs is discussed. Then the required definitions and theorems are given.

\begin{figure}
    \centering
    \begin{tikzpicture}
    \path
    (-3,4) node[circle,draw,minimum size=10mm,inner sep=0pt](ME) {$O$}
    (-4.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](MA) {$Im_A$}
    (-1.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](MB) {$Im_B$}
    (-3,0) node[circle,draw,minimum size=10mm,inner sep=0pt](MAB) {$Im_{AB}$}

    (3,4) node[circle,draw,minimum size=10mm,inner sep=0pt](GN) {$N$}
    (1.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](GA) {$IG_A$}
    (4.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](GB) {$IG_B$}
    (3,0) node[circle,draw,minimum size=10mm,inner sep=0pt](GAB) {$IG_{AB}$};

    \path[]
    (ME) [-, black, out=240, in=90] edge node[above] {} (MA)
    (ME) [-, black, out=300, in=90] edge node[above] {} (MB)

    (MA) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (MAB)
    (MB) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (MAB)

    (GN) [-, black, out=240, in=90] edge node[above] {} (GA)
    (GN) [-, black, out=300, in=90] edge node[above] {} (GB)

    (GA) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (GAB)
    (GB) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (GAB)

    (ME) [-{Latex[width=5]}, black, out=25, in=155] edge node[above] {$f$} (GN)
    (GN) [-{Latex[width=5]}, black, out=165, in=15] edge node[above] {} (ME)

    (MA) [-{Latex[width=5]}, black, out=35, in=145] edge node[above] {$f_A$} (GA)
    (GA) [-{Latex[width=5]}, black, out=155, in=25] edge node[above] {} (MA)

    (MB) [-{Latex[width=5]}, black, out=35, in=145] edge node[above] {$f_B$} (GB)
    (GB) [-{Latex[width=5]}, black, out=155, in=25] edge node[above] {} (MB)

    (MAB) [-{Latex[width=5]}, black, out=25, in=155] edge node[above] {$f_{A} \sqcup f_{B}$} (GAB)
    (GAB) [-{Latex[width=5]}, black, out=165, in=15] edge node[above] {} (MAB)
    ;
    \end{tikzpicture}
    \caption{Structure for transforming between instance models and instance graphs}
    \label{fig:transformation_framework:instance_models_and_instance_graphs:structure_instance_models_graphs}
\end{figure}

\cref{fig:transformation_framework:instance_models_and_instance_graphs:structure_instance_models_graphs} shows one more alternation of the structure proposed in \cref{sec:transformation_framework:structure}. This version of the structure is applied to instance models and instance graphs. As before, instance model $Im_A$ represents the partially build model which corresponds to instance graph $IG_A$ under the transformation function $f_A$. Instance model $Im_B$ represents the next building block to add to this model. It corresponds to instance graph $IG_B$ under the bijective transformation function $f_B$.

Instance models $Im_A$ and $Im_B$ are entirely distinct except for a set objects $O$, which means $O \subseteq Object_{Im_A} \land O \subseteq Object_{Im_B}$. In a similar way, instance graphs $IG_A$ and $IG_B$ are entirely distinct except for a set of nodes $N$, so $N \subseteq N_{IG_A} \land N \subseteq N_{IG_B}$.

Instance models $Im_A$ and $Im_B$ are combined into instance model $Im_{AB}$ using \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_instance_models:combine}. In a similar way instance graphs $IG_A$ and $IG_B$ are combined into instance graph $IG_{AB}$ using \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_instance_graphs:combine}. \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_instance_models:imod_combine_merge_correct} and \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_instance_graphs:ig_combine_merge_correct} respectively show that $Im_{AB}$ and $IG_{AB}$ are valid. Then \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:combination_transformation_function_instance_model_instance_graph} and \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:combination_transformation_function_instance_graph_instance_model} can be used to merge the transformation functions $f_A$ and $f_B$ into $f_{A} \sqcup f_{B}$, where \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:ig_combine_mapping_correct} and \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:ig_combine_mapping_function_correct} show that $f_{A} \sqcup f_{B}$ is again a valid transformation function transforming $Im_{AB}$ to $IG_{AB}$. Similarly, \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:imod_combine_mapping_correct} and \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:imod_combine_mapping_function_correct} show that the inverse function of $f_{A} \sqcup f_{B}$ is again a valid transformation function transforming $IG_{AB}$ to $Im_{AB}$.

\input{tex/04_transformation_framework/04_instance_models_and_instance_graphs/01_combining_instance_models.tex}
\input{tex/04_transformation_framework/04_instance_models_and_instance_graphs/02_combining_instance_graphs.tex}
\input{tex/04_transformation_framework/04_instance_models_and_instance_graphs/03_combining_transformation_functions.tex}


\section{The camera calibration problem}
\label{sec:teo-calibration}
The \textit{geometric camera calibration} is a process that allows to determine all the parameters introduced with the Equation \ref{eq:perspective_projection}. When we calibrate a single camera, we are determining only its intrinsic parameters, instead if we calibrate a couple of cameras (or, as in this case, a laser-camera pair) we are able to locate the points in the 3D space, and we can determine the extrinsic parameters of the equation. Accordingly with what we said in Subsection \ref{subsec:lenses}, lens distortions are critic when we need to reconstruct the 3D world from an image, so they have to be considered by calibration algorithms that, generally, implement non-linear optimization methods (note that the general model for lens distortions is non-linear). Furthermore, some algorithms (such as \cite{SchCameraCalib} and \cite{hamrouni2012new}) try to consider the distortion due to the lens tilt caused by, in turn, the use of the Scheimpflug principle. \\

In literature there is a multitude of calibration algorithms, most developed for stereocamera systems. In this subsection we briefly introduced two algorithms that can be used to calibrate laser triangulation systems, proposed by Tsai \cite{TsaiTvLenses} (the pioneer of camera calibration algorithms) and Zhang \cite{Zhang-calib}. Both the algorithms are based on the pinhole projective model, described in Equation \ref{eq:perspective_projection}, and take in input a grid of points, both in image and world reference systems, and give in output the camera parameters. As we can understand, the origin of the world reference system could be arbitrary, but the system must be consistent with the world.

The choice of to use these algorithms was done by their interest in our filed of study and by the availability of data to compare. However, the use of non-linear optimizations made it difficult to estimate some parameters of interest for the next analysis.

\subsubsection{Tsai}
Roger Tsai proposed its algorithm in 1987 in order to improve the already existing algorithms, that lacked of many informations, such as lens distortions. Thus, he introduced a two-step process: in the first step he evaluated the intrinsic parameters starting from the grid took in input; in the second step he applied a non-linear optimization to correctly evaluate intrinsic parameters, with particular attention with focal length and lens distortions. As shown in his article, he developed a very accurate, fast and versatile algorithm to calibrate cameras. Furthermore, one of the advantages of this technique is the ability to calibrate using a single planar view of the reference target. \\

As we can read in the Reg Wilson's FAQ\footnote{\url{http://www.ius.cs.cmu.edu/IUS/usrp2/rgw/www/faq.txt}, no longer available now.} we have to be cautious when we set Tsai parameters. First of all, it assumes that some nominal values, such as pixel sizes, sensor size and frame grabber are correct. In this way he simplifies some passages of the algorithm. Second we have to pay attention on the choice of the world reference system: if we consider the coplanar procedure, the origin of our coordinate reference system must to be far from the center of the sensor, otherwise the algorithm could be not work. \\
Both in coplanar and non-coplanar procedure, the input grid must have at least $11$ point to calibrate correctly. Furthermore, the points have to be taken broadly across the \acs{FOV} to let the non-linear optimization work properly. \\

Note that, in order to separate the effects of $f$ and $T_z$ on the image, there needs to be perspective distortion effects in the calibration data. For useable perspective distortion, the distance between the calibration points nearest and farthest from the camera should be on the same scale as the distance between the calibration points and the camera. This applies both to coplanar and non-coplanar calibration:

For co-planar calibration the worst situation is to have the 3D points lied in a plane parallel to the camera's image plane (all points at   equal distance away). Simple geometry tells us we can't separate the effects of $f$ and $T_z$. A relative angle of $30$ degrees or more is recommended to give some effective depth to the data points.

For non-coplanar calibration the worst case is to have the 3D points lied in a volume of space that is relatively small compared to the volume's distance to the camera. From a distance the image formation process is closer to orthographic (not perspective) projection and the calibration problem becomes poorly conditioned.

\subsubsection{Zhang}
Zhang developed an hybrid process that combines self-calibration (a grid similar to that of Tsai) and traditional calibration techniques (match between the same point in different images), which enables the linear estimation of all intrinsic parameters. To do that at least three images of a well known planar pattern (or reasonably considered such) are needed, taken in different positions. The motion of the pattern should not necessarily be known. The steps needed to calibrate the system are the following, to:
  \begin{enumerate}
    \item Print a pattern and attach it to a planar surface.
    \item Take a few images of the model plane under different orientations by moving either the plane or the camera. In the scenarios we are interested in, we will move the pattern keeping fixed the camera.
    \item Detect the feature points in the images.
    \item Estimate the five intrinsic parameters and all the extrinsic parameters using the closed-form solution.
    \item Refine all parameters, including lens distortion parameters.
  \end{enumerate}
Unlike Tsai, Zhang tries to estimate the lens distortions until the fourth degree. As the author admitted in the original paper, his algorithm could degenerate if the pattern took in the different frames, lies in parallel planes.

\bigskip
Now we can understand the importance of planar calibration algorithm in laser-based triangulation systems: the laser forms a flat plane in the 3D world reference system. All points we will acquire lie on this plane. From this point of view, Tsai is preferable with respect to Zhang, because it used a single view of scene, taken on the laser plane. Note that if we use a known pattern (i.e. a checkboard), we must be sure that the pattern lies on the laser plane, otherwise the map that obtained will be incorrect.


\input{../header_function}

%---------- start document ---------- %
 \section{squarefree -- Squarefreeness tests}\linkedzero{squarefree}

There are two method groups.
A function in one group raises \linkingone{squarefree}{Undetermined} when it cannot determine squarefreeness.
A function in another group returns {\tt None} in such cases.
The latter group of functions have ``\_ternary'' suffix on their names.
We refer a set \(\{{\tt True}, {\tt False}, {\tt None}\}\) as {\it ternary}\linkedone{squarefree}{ternary}.

The parameter type {\it integer}\linkedone{squarefree}{integer} means either {\it int}, {\it long} or \linkingone{rational}{Integer}.

This module provides an exception class.
\begin{description}
  \item[Undetermined]:\ Report undetermined state of calculation.
    The exception will be raised by
    \linkingone{squarefree}{lenstra} or
    \linkingone{squarefree}{trivial\_test}.
\end{description}

\subsection{Definition}

  We define squarefreeness as:\\
  \(n\) is squarefree \(\iff\) there is no prime \(p\) whose square divides \(n\).

\vspace{1em}
\noindent Examples:
  \begin{itemize}
  \item \(0\) is non-squarefree because any square of prime can divide \(0\).
  \item \(1\) is squarefree because there is no prime dividing \(1\).
  \item \(2\), \(3\), \(5\), and any other primes are squarefree.
  \item \(4\), \(8\), \(9\), \(12\), \(16\) are non-squarefree composites.
  \item \(6\), \(10\), \(14\), \(15\), \(21\) are squarefree composites.
\end{itemize}

 \subsection{lenstra -- Lenstra's condition}\linkedone{squarefree}{lenstra}
 \func{lenstra}{\hiki{n}{integer}}{\out{bool}}\\
 \spacing
 % document of basic document
 \quad If return value is True, \param{n} is squarefree.  Otherwise, the
 squarefreeness is still unknown and \linkingone{squarefree}{Undetermined} is raised.
 The algorithm is based on~\cite{Lenstra1979}. \\
 \spacing
 % added document
 \negok The condition is so strong that it seems \param{n} has to be a
 prime or a Carmichael number to satisfy it.\\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an odd \linkingone{squarefree}{integer}.
 %
 \subsection{trial\_division -- trial division}\linkedone{squarefree}{trial\_division}
 \func{trial\_division}{\hiki{n}{integer}}{\out{bool}}\\
 \spacing
 % document of basic document
 \quad Check whether \param{n} is squarefree or not. \\
 \spacing
 % added document
 The method is a kind of trial division and inefficient for large numbers. \\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
 \subsection{trivial\_test -- trivial tests}\linkedone{squarefree}{trivial\_test}
 \func{trivial\_test}{\hiki{n}{integer}}{\out{bool}}\\
 \spacing
 % document of basic document
 \quad Check whether \param{n} is squarefree or not.  If the squarefreeness is still unknown, then \linkingone{squarefree}{Undetermined} is raised. \\
 \spacing
 % added document
 This method do anything but factorization including Lenstra's method. \\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an odd \linkingone{squarefree}{integer}.
%
 \subsection{viafactor -- via factorization}\linkedone{squarefree}{viafactor}
 \func{viafactor}{\hiki{n}{integer}}{\out{bool}}\\
 \spacing
 % document of basic document
 \quad Check whether \param{n} is squarefree or not. \\
 \spacing
 % added document
 It is obvious that if one knows the prime factorization of the number, he/she can tell whether the number is squarefree or not. \\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
 \subsection{viadecomposition -- via partial factorization}\linkedone{squarefree}{viadecomposition}
 \func{viadecomposition}{\hiki{n}{integer}}{\out{bool}}\\
 \spacing
 % document of basic document
 \quad Test the squarefreeness of \param{n}.
 The return value is either one of {\tt True} or {\tt False};
 {\tt None} never be returned. \\
 \spacing
 % added document
 The method uses partial factorization into squarefree parts,
 if such partial factorization is possible.  In other cases,
 It completely factor \param{n} by trial division.
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
 \subsection{lenstra\_ternary -- Lenstra's condition, ternary version}\linkedone{squarefree}{lenstra\_ternary}
 \func{lenstra\_ternary}{\hiki{n}{integer}}{\out{ternary}}\\
 \spacing
 % document of basic document
 \quad Test the squarefreeness of \param{n}. The return value is one of the ternary logical constants.  If return value is {\tt True}, \param{n} is squarefree.  Otherwise, the squarefreeness is still unknown and {\tt None} is returned. \\
 \spacing
 % added document
 \negok The condition is so strong that it seems \param{n} has to be a
 prime or a Carmichael number to satisfy it.\\
 This is a ternary version of \linkingone{squarefree}{lenstra}. \\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an odd \linkingone{squarefree}{integer}.
 %
 \subsection{trivial\_test\_ternary -- trivial tests, ternary version}\linkedone{squarefree}{trivial\_test\_ternary}
 \func{trivial\_test\_ternary}{\hiki{n}{integer}}{\out{ternary}}\\
 \spacing
 % document of basic document
 \quad Test the squarefreeness of \param{n}.
 The return value is one of the ternary logical constants. \\
 \spacing
 % added document
 The method uses a series of trivial tests including \linkingone{squarefree}{lenstra\_ternary}. \\
 This is a ternary version of \linkingone{squarefree}{trivial\_test}. \\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
 \subsection{trial\_division\_ternary  -- trial division, ternary version}\linkedone{squarefree}{trial\_division\_ternary}
 \func{trial\_division\_ternary}{\hiki{n}{integer}}{\out{ternary}}\\
 \spacing
 % document of basic document
 \quad Test the squarefreeness of \param{n}.
 The return value is either one of {\tt True} or {\tt False};
 {\tt None} never be returned. \\
 \spacing
 % added document
 The method is a kind of trial division. \\
 This is a ternary version of \linkingone{squarefree}{trial\_division}.\\
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
 \subsection{viafactor\_ternary -- via factorization, ternary version}\linkedone{squarefree}{viafactor\_ternary}
 \func{viafactor\_ternary}{\hiki{n}{integer}}{\out{ternary}}\\
 \spacing
 % document of basic document
 \quad Just for symmetry, this function is defined as an alias of \linkingone{squarefree}{viafactor}. \\
 \spacing
 % added document
 \spacing
 % input, output document
 \quad Input parameter \param{n} ought to be an \linkingone{squarefree}{integer}.
%
\C

%---------- end document ---------- %

\input{../footer}