\documentclass[prb,preprint]{revtex4-1}
% The line above defines the type of LaTeX document.
% Note that AJP uses the same style as Phys. Rev. B (prb).

% The % character begins a comment, which continues to the end of the line.

\usepackage{amsmath}  % needed for \tfrac, \bmatrix, etc.
\usepackage{amsfonts} % needed for bold Greek, Fraktur, and blackboard bold
\usepackage{graphicx} % needed for figures

\DeclareMathOperator{\dd}{d\!}
\DeclareMathOperator{\ddd}{\mathrm{d}}

\begin{document}

\title{Demystifying the Lagrangian formalism for field theories}

\author{Gerd Wagner}
\email{gerdhwagner@t-online.de} % optional
\affiliation{Mayener Str. 131, 56070 Koblenz, Germany} % optional second address
% If there were a second author at the same address, we would put another
% \author{} statement here.  Don't combine multiple authors in a single
% \author statement.
%\affiliation{mailing address}
% Please provide a full mailing address here.

\author{Matthew W. Guthrie}
\email{matthew.guthrie@ucf.edu}
\affiliation{Department of Physics, University of Central Florida, Orlando, FL 32816}

% See the REVTeX documentation for more examples of author and affiliation lists.

\date{\today}

\begin{abstract} This paper expands on previous work\cite{guthrie2019demystifying} to derive and motivate the Lagrangian formulation of field theories.
In the process, we take three deliberate steps.
First, we give the definition of the action and derive Euler-Lagrange equations for field theories.
Second, we prove the Euler-Lagrange equations are independent under arbitrary coordinate transformations and motivate that this independence is desirable for field theories in physics.
We then use the Lagrangian for Electrodynamics as an example field Lagrangian and prove that the related Euler-Lagrange equations lead to Maxwell's equations.
\end{abstract}

\maketitle

\section{Introduction}

When Lagrangian field theory is introduced it is often presented as a generalization of the Lagrangian formalism of classical mechanics, and this profoundly shapes physicists' understanding of the subject.
For the most common modern example, see Goldstein's treatment of classical field theories \cite{goldstein2002classical}, which appears in one of the common graduate texts in classical mechanics.
The approach of this paper differs from traditional approaches in that we start by presenting the Lagrangian formulation of field theories as a purely mathematical formalism.
We find that the Lagrangian formulation has very well defined coordinate and field transformation properties.
Because we consider these properties extremely useful for physical field theories, the desire to find Lagrangians for these theories in order to turn their field equations into Euler-Lagrange equations is well motivated.
As a proof of concept, we provide the Lagrangian for Electrodynamics as a definition and show that it leads to Maxwell's equations.
The domain of this work is purely non-relativistic which means neither the Lagrangian formulation of the field theories nor the treatment of Electrodynamics requires invoking concepts from special relativity.

\section{Definition of the Lagrangian formalism for fields}\label{definition}

The experienced reader may recognize the symbols and names used in this section.
Nonetheless, this section should be thought of as containing purely mathematical definitions and conclusions.
We define a field as a function $\psi(t,x)$ of time $t$ and of three spatial coordinates denoted by $x$.
The field's values may be multidimensional.
A well-known example is the electric field, which has a direction in space and whose values are thus three-dimensional.

A Lagrangian $\mathcal{L}$ of $\psi$ is defined as a function that may depend on $\psi$ itself as well as on its time and spatial derivatives:
\begin{equation}
\mathcal{L} = \mathcal{L}\left(\psi, \frac{\partial \psi}{\partial t}, \frac{\partial \psi}{\partial x}\right).
\end{equation}
The action $S$ for two points $t_1$ and $t_2$ in time and a three dimensional area of space $A$ is defined as the following integral of the Lagrangian:
\begin{equation}
S := \int\limits_{t_1}^{t_2} \int_{A} \mathcal{L}\left(\psi, \frac{\partial \psi}{\partial t}, \frac{\partial \psi}{\partial x}\right) \dd x^3 \dd t.
\end{equation}

Next, we are interested in the conditions that $\mathcal{L}$ must fulfill to make $S$ stationary.
To do so we consider arbitrary but small variations $\delta\psi$ of the field and calculate the resulting variation $\delta S$ of $S$. We require the variations $\delta\psi$ to vanish at $t_1$ and $t_2$ as well as on the surface of $A$,
\begin{equation}\label{integrands}
\delta S = \int\limits_{t_1}^{t_2} \int_{A}
\frac{\partial \mathcal{L}}{\partial \psi} \cdot \delta \psi
+ \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial t}} \; \delta \left(\frac{\partial \psi} {\partial t}\right)
+ \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial x}}  \; \delta \left(\frac{\partial \psi} {\partial x}\right)
\dd x^3 \dd t.
\end{equation}
If we consider the possibly multidimensional values of $\psi$ indexed by $j$ and the three spacial dimensions indexed by $i$, the integrands in equation \eqref{integrands} can be rewritten as:
\begin{align}
\frac{\partial \mathcal{L}}{\partial \psi} \; \delta \psi
&= \sum_{j} \frac{\partial \mathcal{L}}{\partial \psi_{j}} \; \delta \psi_{j}, \\
\frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial t}} \; \delta \left(\frac{\partial \psi} {\partial t}\right)
&= \sum_{j} \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi_{j}}{\partial t}} \; \delta \left(\frac{\partial \psi_{j}} {\partial t}\right), \\
\frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial x}} \; \delta \left(\frac{\partial \psi} {\partial x}\right)
&= \sum_{i,j} \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi_{j}}{\partial x_{i}}} \; \delta \left(\frac{\partial \psi_{j}} {\partial x_{i}}\right).
\end{align}

We now integrate the second summand by parts over time and the third summand by parts over space.
To do so, we use the identities
$\delta \left(\frac{\partial \psi} {\partial t}\right)
= \frac{\partial \psi_2} {\partial t} - \frac{\partial \psi_1} {\partial t}
= \frac{\partial (\psi_2 - \psi_1)} {\partial t}
= \frac{\partial \delta \psi} {\partial t}$
and
$\delta \left(\frac{\partial \psi} {\partial x}\right)
= \frac{\partial \psi_2} {\partial x} - \frac{\partial \psi_1} {\partial x}
= \frac{\partial (\psi_2 - \psi_1)} {\partial x}
= \frac{\partial \delta \psi} {\partial x}$.
The integral is performed as follows:
\begin{equation} \label{calcDeltaSSection2}
\begin{split}
\delta S = \int\limits_{t_1}^{t_2} \int_{A}
\frac{\partial \mathcal{L}}{\partial \psi} \delta \psi
-\left(\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial t}} \right)\right) \delta \psi
-\left(\frac{\partial}{\partial x} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial x}} \right)\right) \delta \psi \;
\dd x^3 \dd t \\
+ \int_{A} \int\limits_{t_1}^{t_2} \frac{\partial}{\partial t} \left(\frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial t}} \; \delta \psi \right) \dd t \dd x^3
+ \int\limits_{t_1}^{t_2}
\int_{A} \frac{\partial}{\partial x} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial x}} \; \delta \psi \right) \dd x^3  \dd t.
\end{split}
\end{equation}
with ``$\frac{\partial}{\partial x} \cdot$'' denoting the divergence with respect to the coordinates $x$ (we refrain from using the usual ``$\nabla \cdot$'' because later the divergence with respect to variables other than $x$ will occur).

The second integral vanishes as a result of the fundamental theorem of calculus and because $\delta \psi(t_1) = \delta \psi(t_2) = 0$.
The third integral vanishes from use of Gauss's theorem and because $\delta \psi(x) = 0$ for any $x$ on the surface of $A$. Thus,
\begin{equation}
\delta S = \int\limits_{t_1}^{t_2} \int_{A}
\frac{\partial \mathcal{L}}{\partial \psi} \delta \psi
-\left(\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial t}} \right)\right) \delta \psi
-\left(\frac{\partial}{\partial x} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial x}} \right)\right) \delta \psi \;\;
\dd x^3 \dd t.
\end{equation}
If we use the same index conventions for the possibly multidimensional values of $\psi$ and the three spacial dimensions as we did above, the last two summands of the integrand become:
\begin{align}
\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial t}} \right) \; \delta \psi
&= \sum_j \frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi_j}{\partial t}} \right) \; \delta \psi_j \\
\left(\frac{\partial}{\partial x} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial x}} \right)\right) \; \delta \psi
&= \sum_j \left(\sum_i \frac{\partial}{\partial x_i} \; \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi_j}{\partial x_i}} \right)\right) \; \delta \psi_j.
\end{align}

The last rewrite of $\delta S$ we wish to do is
\begin{equation}
\delta S = \int\limits_{t_1}^{t_2} \int_{A}
\left(
\frac{\partial \mathcal{L}}{\partial \psi}
-\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial t}} \right)
-\frac{\partial}{\partial x} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial x}} \right)\right) \delta \psi \;
\dd x^3 \dd t.
\end{equation}
Because $\delta \psi$ is arbitrary except for its boundary conditions, the only way to make $S$ stationary (which is equivalent to requiring that $\delta S = 0$) is that $\mathcal{L}$ fulfills the condition

\begin{equation}
0 = \frac{\partial \mathcal{L}}{\partial \psi}
-\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial t}} \right)
-\frac{\partial}{\partial x} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial x}} \right).
\end{equation}

This is the Euler-Lagrange equation for field theory.
It can be seen as a counterpart of the Euler-Lagrange equation for classical particles discussed in previous work \cite{guthrie2019demystifying}.
The procedure of looking for a condition to make $S$ stationary under a Lagrangian $\mathcal{L}\left(\psi, \frac{\partial \psi}{\partial t}, \frac{\partial \psi}{\partial x}\right)$ is called the Lagrangian formalism for field theory.

\section{Invariance of the Euler-Lagrange equation for field theory under transformations} \label{sectionInvariance}

Let $x=f(\bar{x})$ be an invertible and differentiable transformation of the spatial coordinates and $\psi=F(\bar{\psi})$ be an invertible and differentiable transformation of the field (for a discussion of this transformation see appendix \ref{appendixDiscussionTransform}).
We define the transformed Lagrangian  $\bar{\mathcal{L}}$ as

\begin{equation} \label{LagrTransform}
\bar{\mathcal{L}}\left(\bar{\psi}, \frac{\partial \bar{\psi}}{\partial t}, \frac{\partial \bar{\psi}}{\partial \bar{x}}\right)
:= \mathcal{L}\left(F(\bar{\psi}), \frac{\partial F(\bar{\psi})}{\partial t}, \frac{\partial F(\bar{\psi})}{\partial f}\right)
\left| \det \frac{\partial f}{\partial \bar{x}} \right|,
\end{equation}
where $\left| \det \frac{\partial f}{\partial \bar{x}} \right|$ is the absolute value of the determinant of the Jacobian matrix of $f$ with respect to the spatial coordinates $\bar{x}$. \\

We will prove that, by requiring $S$ to be stationary, the equations

\begin{equation} \label{ELGTransformed}
0 = \frac{\partial \bar{\mathcal{L}}}{\partial \bar{\psi}}
-\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{\bar{L}}}{\partial \frac{\partial \bar{\psi}}{\partial t}} \right)
-\frac{\partial}{\partial \bar{x}} \cdot \left( \frac{\partial \mathcal{\bar{L}}}{\partial \frac{\partial \bar{\psi}}{\partial \bar{x}}} \right)
\end{equation}
and
\begin{equation} \label{ELGUntransformed}
0 = \frac{\partial \mathcal{L}}{\partial \psi}
-\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial t}} \right)
-\frac{\partial}{\partial x} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \psi}{\partial x}} \right)
\end{equation}
follow, and thus that the Euler-Lagrange equation for field theory is independent of arbitrary coordinate and field transformations as long as the transformation of the Lagrangian is given by equation \eqref{LagrTransform}. \\

To do so, we consider arbitrary but small variations $\delta \bar{\psi}$ of the field $\bar{\psi}$ that vanish at $t_1$, $t_2$, and on the surface of an area of space $\bar{A}$. We use these to find the condition for
\begin{equation}
S = \int\limits_{t_1}^{t_2} \int_{\bar{A}} \bar{\mathcal{L}}\left(\bar{\psi}, \frac{\partial \bar{\psi}}{\partial t}, \frac{\partial \bar{\psi}}{\partial \bar{x}}\right) \dd \bar{x}^3 \dd t
= \int\limits_{t_1}^{t_2} \int_{\bar{A}} \mathcal{L}\left(F(\bar{\psi}), \frac{\partial F(\bar{\psi})}{\partial t}, \frac{\partial F(\bar{\psi})}{\partial f}\right)
\left| \det \frac{\partial f}{\partial \bar{x}} \right| \dd \bar{x}^3 \dd t
\end{equation}
to become stationary.
Equation \eqref{ELGTransformed} follows from repeating the considerations of section \ref{definition}.
To prove equation \eqref{ELGUntransformed}, we look at
\begin{equation}
S = \int\limits_{t_1}^{t_2} \int_{\bar{A}} \mathcal{L}\left(F(\bar{\psi}), \frac{\partial F(\bar{\psi})}{\partial t}, \frac{\partial F(\bar{\psi})}{\partial f}\right)
\left| \det \frac{\partial f}{\partial \bar{x}} \right| \dd \bar{x}^3 \dd t
\end{equation}
which, using the transformation formula of multidimensional integrals (see Appendix \ref{TranformationFormula}), can be transformed into
\begin{equation}
S = \int\limits_{t_1}^{t_2} \int_{f(\bar{A})} \mathcal{L}\left(F(\bar{\psi}), \frac{\partial F(\bar{\psi})}{\partial t}, \frac{\partial F(\bar{\psi})}{\partial f}\right)
\dd f^3 \dd t,
\end{equation}
where $f(\bar{A})$ is the representation of $\bar{A}$ under the coordinate transformation $f$.
Based on this formula, the variation $\delta S$ of $S$ is given by
\begin{equation}
\delta S = \int\limits_{t_1}^{t_2} \int_{f(\bar{A})}
\frac{\partial \mathcal{L}}{\partial F} \; \delta F
+ \frac{\partial \mathcal{L}}{\partial \frac{\partial F}{\partial t}} \; \delta \left(\frac{\partial F}{\partial t}\right)
+ \frac{\partial \mathcal{L}}{\partial \frac{\partial F}{\partial f}} \; \delta \left(\frac{\partial F} {\partial f}\right)
\dd f^3 \dd t,
\end{equation}
where
\begin{equation} \label{deltaFDefinition}
\delta F = \frac{\partial F}{\partial \bar{\psi}} \delta \bar{\psi}.
\end{equation}
Integration by parts of the second and the third term leads to
\begin{equation} \label{calcDeltaSSection3}
\begin{split}
\delta S = \int\limits_{t_1}^{t_2} \int_{f(\bar{A})}
\frac{\partial \mathcal{L}}{\partial F} \delta F
-\left(\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial F}{\partial t}} \right)\right) \delta F
-\left(\frac{\partial}{\partial f} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial F}{\partial f}} \right)\right) \delta F \;
\dd f^3 \dd t \\
+ \int_{f(\bar{A})} \int\limits_{t_1}^{t_2} \frac{\partial}{\partial t} \left(\frac{\partial \mathcal{L}}{\partial \frac{\partial F}{\partial t}} \; \delta F \right) \dd t \dd f^3
+ \int\limits_{t_1}^{t_2}
\int_{f(\bar{A})} \frac{\partial}{\partial f} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial F}{\partial f}} \; \delta F \right) \dd f^3 \dd t,
\end{split}
\end{equation}
where the identities $\delta \left(\frac{\partial F} {\partial t}\right)
= \frac{\partial F_2} {\partial t} - \frac{\partial F_1} {\partial t}
= \frac{\partial (F_2 - F_1)} {\partial t}
= \frac{\partial \delta F} {\partial t}$
and
$\delta \left(\frac{\partial F} {\partial f}\right)
= \frac{\partial F_2} {\partial f} - \frac{\partial F_1} {\partial f}
= \frac{\partial (F_2 - F_1)} {\partial f}
= \frac{\partial \delta F} {\partial f}$
were used.
Following from equation \eqref{deltaFDefinition}, $\delta F$ vanishes at $t_1$ and $t_2$ as $\delta \bar{\psi}$ does, and the second term in \eqref{calcDeltaSSection3} is zero because of the fundamental theorem of calculus.
Using Gauss's theorem, the third term can be transformed into an integral over the surface of $f(\bar{A})$ which we denote by $\partial (f(\bar{A}))$.
This surface is the same as the representation of the surface of $\bar{A}$ under $f$:
\begin{equation} \label{surfaceEquality}
\partial (f(\bar{A})) = f(\partial \bar{A}).
\footnote{The simplest way to picture this equation is to imagine a real area in space, which is described from within two systems of coordinates.}
\end{equation}
To show that the third term vanishes, we will prove that $\delta F$ is zero for any $x \in \partial (f(\bar{A}))$.

First, let $x$ be an element of $\partial (f(\bar{A}))$.
\footnote{The simplest way to picture this element is to imagine a real point on the surface of the area in space, which is described from within two systems of coordinates.}
Then for $x$ there exists a unique $\bar{x} \in \partial \bar{A}$ which is defined by $x=f(\bar{x})$. We use the fact from above that $\delta \bar{\psi}(\bar{x}) = 0$ and recall that the variation $\delta \bar{\psi}$ is a difference between two fields (which we denote $\bar{\psi}_1$ and $\bar{\psi}_2$) such that
\begin{equation}
\delta \bar{\psi} = \bar{\psi}_2 - \bar{\psi}_1.
\end{equation}
The value of $F$ considered as a function of $x$ is given by
\begin{equation} \label{defineFOfx}
F(x) = F(\bar{\psi}(\bar{x})) \;\; \text{with} \;\; \bar{x} \;\; \text{defined through} \;\; x=f(\bar{x})
\iff \bar{x} = f^{-1}(x).
\end{equation}
For a discussion of formula \eqref{defineFOfx}, see appendix \ref{appendixDiscussionTransform}.
The variation $\delta F$ that results from the difference $\delta \bar{\psi}$ between $\bar{\psi}_1$ and $\bar{\psi}_2$ is given by
\begin{equation}
\delta F(x) = F(\bar{\psi}_2(\bar{x})) - F(\bar{\psi}_1(\bar{x}))
= F(\bar{\psi}_1(\bar{x}) + \delta \bar{\psi} (\bar{x})) - F(\bar{\psi}_1(\bar{x}))
= \frac{\partial F}{\partial \bar{\psi}} \delta \bar{\psi} (\bar{x}).
\end{equation}
Because $\delta \bar{\psi}(\bar{x})$ is zero by assumption, $\delta F(x)$ is zero, too, which finishes the proof.

As for $\delta S$, we are now left with
\begin{equation}
\delta S = \int\limits_{t_1}^{t_2} \int_{f(\bar{A})}
\left(
\frac{\partial \mathcal{L}}{\partial F}
-\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial F}{\partial t}} \right)
-\frac{\partial}{\partial f} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial F}{\partial f}} \right)\right) \delta F \;\;
\dd f^3 \dd t.
\end{equation}
Because of equation \eqref{deltaFDefinition}, $\delta F$ is as arbitrary as $\delta \bar{\psi}$. Thus, the only way for $\delta S$ to vanish is
\begin{equation} \label{lastEqToProveInvariance}
0 =
\frac{\partial \mathcal{L}}{\partial F}
-\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial F}{\partial t}} \right)
-\frac{\partial}{\partial f} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial F}{\partial f}} \right).
\end{equation}
If we now replace $F$ and $f$ according to their definitions by $\psi$ and $x$ this equation transforms into equation \eqref{ELGUntransformed} and thus finishes the proof.

\section{Application to physics: The Lagrangian for Electrodynamics}
The transformation properties for the Euler-Lagrange equations for field theories that we found on a purely mathematical basis makes the Euler-Lagrange formalism for field theories desirable for physics.
To make the formalism useful for physics we must turn the physical field equations into Euler-Lagrange equations.
This first requires finding a Lagrangian for the physical field theory in question.
This has been done for many existing physical field theories, such as Electrodynamics, General relativity, Schr\"odinger's equation, Dirac's equation, the Klein-Gordon equation, and the Standard model of particle physics.

As an example, we define the Lagrangian of Electrodynamics and show that Maxwell's equations can be derived from its Euler-Lagrange equations.
We start with some remarks on Maxwell's equations that can be found in greater detail in several textbooks, Jackson\cite{jackson1999classical} or Griffiths\cite{griffiths2017introduction} being two common examples.

With
\begin{itemize}
  \item $E$ denoting the three components of the electric field,
  \item $B$ denoting the three components of the magnetic field,
  \item $j$ denoting the three components of the electric current density,
  \item $\rho$ denoting the electric charge density,
  \item $\mu_0$ denoting permeability constant of empty space,
  \item $\epsilon_0$ denoting dielectric constant of empty space,
  \item $c$ denoting the speed of light,
\end{itemize}
Maxwell's equations in empty space are given by
\begin{align}
\nabla \times E &= - \frac{\partial B}{\partial t}, \label{Faraday} \\
\nabla \times B &= \mu_0 j +  \frac{1}{c^2} \frac{\partial E}{\partial t}, \\
\nabla \cdot E &= \frac{\rho}{\epsilon_0}, \\
\nabla \cdot B &= 0, \label{noMonopole}
\end{align}
where
\begin{equation}
\mu_0 = \frac{1}{\epsilon_0 c^2}.
\end{equation}
Because $\nabla \cdot B = 0$, there exists some vector potential $A$ such that
\begin{equation} \label{BbyA}
B = \nabla \times A.
\end{equation}
With that, equation \eqref{Faraday} can be rewritten as
\begin{equation}
\nabla \times \left( E + \frac{\partial A}{\partial t} \right) = 0.
\end{equation}
When the curl of a field is zero, the field can be expressed by the gradient of a scalar potential $\phi$. Thus, we can write
\begin{equation} \label{EbyAPhi}
E + \frac{\partial A}{\partial t} = - \nabla \phi
\iff
E = - \nabla \phi - \frac{\partial A}{\partial t}.
\end{equation}
To find equations \eqref{BbyA} and \eqref{EbyAPhi}, we refer to equations \eqref{noMonopole} and \eqref{Faraday}.
We now use equations \eqref{BbyA} and \eqref{EbyAPhi} to express the remaining two Maxwell equations using only $A$ and $\phi$:
\begin{align}
\nabla \times ( \nabla \times A) &= \mu_0 j + \frac{1}{c^2} \frac{\partial}{\partial t} \left(- \nabla \phi - \frac{\partial A}{\partial t} \right) \label{MaxwellAPhi1} \\
\nabla \cdot \left( -\nabla \phi - \frac{\partial A}{\partial t} \right) &= \frac{\rho}{\epsilon_0} . \label{MaxwellAPhi2}
\end{align}
We assert that these equations are the Euler-Lagrange equations of the Lagrangian
\begin{equation}
\mathcal{L} = \epsilon_0 \frac{E^2 - c^2 B^2}{2} - \rho\phi + j \cdot A
= \epsilon_0 \frac{(-\nabla\phi - \frac{\partial A}{\partial t})^2 - c^2 (\nabla \times A)^2}{2} - \rho\phi + j \cdot A.
\end{equation}
To prove this assertion, we first calculate the Euler-Lagrange equation for $\phi$
\begin{equation} \label{ELPhi}
0 = \frac{\partial \mathcal{L}}{\partial \phi}
-\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \phi}{\partial t}} \right)
-\frac{\partial}{\partial x} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \phi}{\partial x}} \right).
\end{equation}
We calculate the terms separately,
\begin{align}
\frac{\partial \mathcal{L}}{\partial \phi} &= -\rho \\
\frac{\partial \mathcal{L}}{\partial \frac{\partial \phi}{\partial t}} &= 0
\implies \frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial \phi}{\partial t}}\right) = 0 \\
\frac{\partial \mathcal{L}}{\partial \frac{\partial \phi}{\partial x}}
&= \frac{\epsilon_0}{2} \cdot 2 \left(-\nabla \phi - \frac{\partial A}{\partial t} \right) (-1)
= \epsilon_0 \left(\nabla \phi + \frac{\partial A}{\partial t} \right) \\
\frac{\partial}{\partial x} \cdot \left(\frac{\partial \mathcal{L}}{\partial \frac{\partial \phi}{\partial x}} \right)
&= \nabla \cdot \left[\epsilon_0 \left(\nabla \phi + \frac{\partial A}{\partial t} \right)\right].
\end{align}
Substituting these results into equation \eqref{ELPhi} results in
\begin{equation}
0 = -\rho - 0 -\nabla \cdot \left[\epsilon_0 \left(\nabla \phi + \frac{\partial A}{\partial t} \right)\right],
\end{equation}
which is equivalent to equation \eqref{MaxwellAPhi2}.
With that, the first part of the proof is done.

For the second part we must prove that
\begin{equation} \label{ELA}
0 = \frac{\partial \mathcal{L}}{\partial A}
-\frac{\partial}{\partial t} \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial A}{\partial t}} \right)
-\frac{\partial}{\partial x} \cdot \left( \frac{\partial \mathcal{L}}{\partial \frac{\partial A}{\partial x}} \right)
\end{equation}
is equivalent to equation \eqref{MaxwellAPhi1}.
We do this for the first component $A_1$ of $A$ only (note that equation \eqref{ELA} actually represents one equation for each component of $A$).
Again, we calculate the terms separately:
\begin{align}
\frac{\partial \mathcal{L}}{\partial A_1} &= j_1 \\
\frac{\partial \mathcal{L}}{\partial \frac{\partial A_1}{\partial t} }
&= \frac{\epsilon_0}{2} \cdot 2 \left(-\frac{\partial \phi}{\partial x_1} - \frac{\partial A_1}{\partial t}\right) (-1) \\
\frac{\partial}{\partial t} \left(\frac{\partial \mathcal{L}}{\partial \frac{\partial A_1}{\partial t} } \right)
&= \epsilon_0 \frac{\partial}{\partial t} \left(\frac{\partial \phi}{\partial x_1} + \frac{\partial A_1}{\partial t}\right)
\end{align}

\begin{align}
\frac{\partial \mathcal{L}}{\partial \frac{\partial A_1}{\partial x} }
&= - \frac{\epsilon_0 c^2}{2} \frac{\partial}{\partial \frac{\partial A_1}{\partial x}}
\left[
\left(\frac{\partial A_3}{\partial x_2} - \frac{\partial A_2}{\partial x_3} \right)^2
+ \left(\frac{\partial A_1}{\partial x_3} - \frac{\partial A_3}{\partial x_1} \right)^2
+ \left(\frac{\partial A_2}{\partial x_1} - \frac{\partial A_1}{\partial x_2} \right)^2
\right] \\
&=
- \frac{\epsilon_0 c^2}{2}
\left(
\begin{array}{c}
0
\\
2 \left(\frac{\partial A_2}{\partial x_1} - \frac{\partial A_1}{\partial x_2} \right) (-1)
\\
2 \left(\frac{\partial A_1}{\partial x_3} - \frac{\partial A_3}{\partial x_1} \right)
\end{array}
\right)
=
- \epsilon_0 c^2
\left(
\begin{array}{c}
0
\\
\left(\frac{\partial A_1}{\partial x_2} - \frac{\partial A_2}{\partial x_1} \right)
\\
\left(\frac{\partial A_1}{\partial x_3} - \frac{\partial A_3}{\partial x_1} \right)
\end{array}
\right) \\ \nonumber \\
\frac{\partial}{\partial x} \cdot \frac{\partial \mathcal{L}}{\partial \frac{\partial A_1}{\partial x} }
&= - \epsilon_0 c^2
\left( \frac{\partial^2 A_1}{{\partial x_2}^2} - \frac{\partial^2 A_2}{\partial x_2 \partial x_1}
+ \frac{\partial^2 A_1}{{\partial x_3}^2} - \frac{\partial^2 A_3}{\partial x_3 \partial x_1} \right).
\end{align}
Substituting these results into equation \eqref{ELA} results in
\begin{equation}
0= j_1
- \epsilon_0 \frac{\partial}{\partial t} \left(\frac{\partial \phi}{\partial x_1} + \frac{\partial A_1}{\partial t} \right)
+ \epsilon_0 c^2
\left( \frac{\partial^2 A_1}{{\partial x_2}^2} - \frac{\partial^2 A_2}{\partial x_2 \partial x_1}
+ \frac{\partial^2 A_1}{{\partial x_3}^2} - \frac{\partial^2 A_3}{\partial x_3 \partial x_1} \right).
\end{equation}
Using $\mu_0 = \frac{1}{\epsilon_0 c^2}$, this can be represented as
\begin{equation}
 - \frac{\partial^2 A_1}{{\partial x_2}^2} + \frac{\partial^2 A_2}{\partial x_2 \partial x_1}
- \frac{\partial^2 A_1}{{\partial x_3}^2} + \frac{\partial^2 A_3}{\partial x_3 \partial x_1}
= \mu_0 j_1
+ \frac{1}{c^2} \frac{\partial}{\partial t} \left(-\frac{\partial \phi}{\partial x_1} - \frac{\partial A_1}{\partial t} \right).
\end{equation}
The right hand side of this equation is equal to the first component of the right hand side of equation \eqref{MaxwellAPhi1}.
Now we need to prove that the first component of $\nabla \times \left( \nabla \times A\right)$ equals the left hand side of this equation.
To do so we use the formula
$\nabla \times \left( \nabla \times A\right) = \nabla\left(\nabla \cdot A\right) - \Delta A$:
\begin{align}
[\nabla(\nabla \cdot A) - \Delta A]_1 &=
\frac{\partial}{\partial x_1} \left( \frac{\partial A_1}{\partial x_1} + \frac{\partial A_2}{\partial x_2} + \frac{\partial A_3}{\partial x_3} \right)
- \left( \frac{\partial^2 A_1}{{\partial x_1}^2} + \frac{\partial^2 A_1}{{\partial x_2}^2} + \frac{\partial^2 A_1}{{\partial x_3}^2} \right) \nonumber \\
&=
\frac{\partial^2 A_2}{\partial x_1 \partial x_2} + \frac{\partial^2 A_3}{\partial x_1 \partial x_3}
- \frac{\partial^2 A_1}{{\partial x_2}^2} - \frac{\partial^2 A_1}{{\partial x_3}^2}.
\end{align}
With this, we found that the Euler-Lagrange equation for $A_1$ is equivalent to the first component of equation \eqref{MaxwellAPhi1}. To finish the proof, the last calculation must only to be repeated for the remaining Euler-Lagrange equations and components of equation \eqref{MaxwellAPhi1}.

\section{Conclusion}
The Euler-Lagrange formalism for field theories was presented as a purely mathematical framework that provides us with field equations which are invariant under any coordinate and field transformation as long as the associated Lagrangian $\mathcal{L}$ has the very simple and well defined transformation property given by equation \eqref{LagrTransform}.
Based on this mathematical result, we are well motivated to reformulate physical field equations in such a way that they become Euler-Lagrange equations.
The critical part of this reformulation is finding the Lagrangian for the field theory that we want to reformulate.

\appendix

\section{Discussion of the coordinate and field transformation defined in the beginning of section \ref{sectionInvariance}} \label{appendixDiscussionTransform}
The transformations
\begin{align}
  &x=f(\bar{x}) \;\; \text{for the spacial coordinates}\\
  &\psi=F(\bar{\psi}) \;\; \text{for the fields}
\end{align}
can be given precise meaning if we consider a particle from within two coordinate systems $\bar{T}$ and $T$.
If in $\bar{T}$ the particle's coordinates are given by $\bar{x}$, then in $T$ they are given by $x = f(\bar{x})$.

Next, we assume that in $\bar{T}$ there is a field $\bar{\psi}$ which at the particle's position $\bar{x}$ has the value $\bar{\psi}(\bar{x})$.\footnote{Of course the field may have multiple components as it would in the case of an electric field.}
We now want to know the field's value at the particle's position $x$ in $T$, which we denote by $\psi(x)$, which is where the transformation $F$ of the field comes into play.
$F$ is meant to be defined in such a way that $\psi(x)$ is given by
\footnote{A notable special case is when $F$ is the identity function.
Equation \ref{defFByArg} then reads $$\psi(x) = \bar{\psi}(\bar{x}) \iff \psi(f(\bar{x})) = \bar{\psi}(\bar{x}).$$
Fields that transform this way are called scalar fields.
The Higgs field is a famous example of a scalar field.}
\begin{equation} \label{defFByArg}
  \psi(x) = F(\bar{\psi}(\bar{x})) \iff \psi(f(\bar{x})) = F(\bar{\psi}(\bar{x}))
\end{equation}
The second equation allows to write the functional identity:
\begin{equation} \label{defFByFunctional}
  \psi \circ f = F \circ \bar{\psi} \;\; \text{defined on the coordinates $\bar{x}$ of $\bar{T}$}
\end{equation}
These results allow us to state two parts of section \ref{sectionInvariance} more precisely.
In fact, equations \eqref{defFByArg} and \eqref{defFByFunctional} were used in these parts:
\begin{itemize}
  \item
  In equations \eqref{lastEqToProveInvariance} and \eqref{LagrTransform} we use the derivative $\frac{\partial F(\bar{\psi})}{\partial f}$.
  For this, according to equations \eqref{defFByFunctional} and \eqref{defFByArg}, the following equation holds:
  \begin{equation}
    \frac{\partial F(\bar{\psi})}{\partial f} = \frac{\partial \psi}{\partial f} = \frac{\partial \psi}{\partial x},
  \end{equation}
  which is used to follow the equivalence of equations \eqref{lastEqToProveInvariance} and \eqref{ELGUntransformed}.
  \item
  With equation \eqref{defFByArg} it is clear that $F(x)$, which is used in equation \eqref{defineFOfx}, is well defined.
\end{itemize}

\section{Alternative to the transformation formula of multidimensional integrals} \label{TranformationFormula}

The proof of the transformation formula of multidimensional integrals is not trivial.
A heuristic explanation is given by Sterman \cite{Sterman}.
There,
\begin{equation}
\left|\det \frac{\partial f}{\partial \bar{x}} \right| =  \left|\det \frac{\partial x}{\partial \bar{x}} \right|
\end{equation}
is written as $\dd x^3 / \dd \bar{x}^3$ and is explained to be the ratio of the differentials in the transformed and untransformed coordinates.

%\acknowledgments{Acknowledgments}

\bibliographystyle{unsrt}
\bibliography{bibliography}

%\begin{thebibliography}{9}
%
%\bibitem{guthrie2019demystifying} Gerd Wagner and Matt Guthrie, Demystifying the Lagrangian of Classical Mechanics
%
%\bibitem{goldstein2002classical Goldstein, Poole and Safko, Classical Mechanics, Chapter 13
%
%\bibitem{Jackson} J.D. Jackson, Classical Electrodynamics, section 6.4
%
%\bibitem{Stackexchange} \url{https://physics.stackexchange.com/questions/34241/deriving-lagrangian-density-for-electromagnetic-field}
%
%\bibitem{Sterman} George Sterman - An Introduction to Quantum Field Theory - Section 1.3 Invariance and conservation
%
%\bibitem{griffiths} Griffiths introduction to electrodynamics.
%
%\end{thebibliography}

\end{document}


\subsection{Autoregressive Distributed Lag (ARDL) model}

Include lagged y and lagged x (and current x)


%              %
%%            %%
%%% PREAMBLE %%%
%%            %%
%              %

% Document class
\documentclass[11pt]{beamer}

\usetheme{Boadilla}
\usecolortheme{beaver}
\useinnertheme{rectangles}

\setbeamertemplate{navigation symbols}{}

% Font
\usepackage{fontspec}
\setmainfont{Latin Modern Roman}

% Language and typography
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{french}

\usepackage{csquotes}

\usepackage{microtype}

% Mathematics
\usepackage{mathtools}
\usepackage{cases}
\usepackage{systeme}

% Floats
\usepackage{float}
\usepackage{booktabs}
\usepackage{multicol}

% References
\usepackage{cleveref}

%              %
%%            %%
%%% DOCUMENT %%%
%%            %%
%              %

% Information
\title{Mathematics}
\subtitle{Systems of equations}
\author[A. Quenon]{Alexandre Quenon}

% Text
\begin{document}
% *** Title page *** %
\begin{frame}
	\titlepage
\end{frame}

% *** Contents *** %
\begin{frame}
	\frametitle{Overview}

	\tableofcontents
\end{frame}

% *** Tutorial *** %
%-----
\section{Useful packages}

\begin{frame}
	\frametitle{Packages for systems of equations}

	Some packages very useful for mathematics are listed here below:
	\begin{itemize}
		\item \emph{mathtools} which is mainly an upgrade of the very well-known \enquote{amsmath} package (the backbone for mathematics with \LaTeX{}),
		\item \emph{cases} which provides the \texttt{numcases} command to number all lines of a system of equations, and
		\item \emph{systeme} which proposes tools to improve the display of the variables of the system.
	\end{itemize}
\end{frame}

%-----
\section{Functions defined by domain}

\begin{frame}
	\frametitle{Functions defined by domain}

	\structure{Tool}: \texttt{cases} environment, \textbackslash\textbackslash{} before starting a new line, maximum one \& per line.
	Must be included inside another mathematical equation environment.

	For examples:
	\begin{equation}
		a = \begin{cases}
			x^2 + 2					& \text{if} x<2  \\
			\int x-3\, \mathrm{d}x	& \text{if} x \geq 2
		\end{cases}
	\end{equation}
	\begin{equation}
		a = \begin{dcases*}
			x^2 + 2					& if  $x<2$  \\
			\int x-3\, \mathrm{d}x	& otherwise
		\end{dcases*}
	\end{equation}

	\structure{Extra}: a starred version makes the right column \emph{text-mode} instead of \emph{math-mode}.
	A \texttt{dcases} variant makes the environment \emph{displaystyle}.
	An \texttt{rcases} variant creates a closing bracket on the right side.
\end{frame}

%-----
\section{Systems of equations}

\begin{frame}
	\frametitle{Systems of equations}
	\framesubtitle{One number for the whole system}

	\structure{Tool}:  \texttt{cases} environment (same as for defined-by-domain function).

	Example:
	\begin{align}
		\begin{cases}
			x  +2y - z  = 1 \\
			x  -3y + 2z = 4 \\
			-x +y  +z   = 0
		\end{cases}
	\end{align}

	\structure{Issues}:
	\begin{enumerate}
		\item only one number the whole system but it would be useful to number each line of the system $\rightarrow$ see the \emph{cases} package,
		\item there is no alignment between the variables like it is sometimes done in algebra $\rightarrow$ see the \emph{systeme} package.
	\end{enumerate}
\end{frame}

\begin{frame}
	\frametitle{Systems of equations}
	\framesubtitle{Numbering all lines of the system (1)}

	\structure{Tool}: \texttt{numcases} environment from the \emph{cases} package, \textbackslash\textbackslash{} before starting a new line, maximum one \& per line.

	Examples:
	\begin{numcases}{}
		x  +2y - z  = 1 \\
		x  -3y + 2z = 4 \\
		-x +y  +z   = 0
	\end{numcases}

	\begin{numcases}{a=}
		x^2 + 2					& if  $x<2$  \\
		\int x-3\, \mathrm{d}x	& otherwise
	\end{numcases}

	\structure{Extra}: it corresponds to \texttt{dcases*} with all lines numbered, which means that:
	\begin{itemize}
		\item it is directly in \emph{displaystyle},
		\item the right column is in \emph{text-mode}.
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Systems of equations}
	\framesubtitle{Numbering all lines of the system (2)}

	\structure{Numbering style}: \texttt{subnumcases} uses the same number and adds a letter in the equation tag.

	Example:
	\begin{subnumcases}{}
		x  +2y - z  = 1 \\
		x  -3y + 2z = 4 \\
		-x +y  +z   = 0
	\end{subnumcases}
\end{frame}

\begin{frame}
	\frametitle{Systems of equations}
	\framesubtitle{Alignment on variables}

	\structure{Tool}: \texttt{systeme} command from the \emph{systeme} package, commas (,) used to separate equations.
	Works outside any math environment as well as inside \texttt{equation}.

	Example:
	\begin{equation}
		\systeme{%
			x  +2y - z  = 1,
			x  -3y + 2z = 4,
			-x +y  +z   = 0}
	\end{equation}

	\structure{Issue}: the numbering counter used by the \texttt{systeme} command seems to not work properly the \LaTeX{}'s equation internal counter.
	Consequently, use it inside an \texttt{equation} environment.
\end{frame}

% *** END *** %
\end{document}


\chapter{Data Fusion and State Estimation}
This chapter is dedicated to explaining the mathematical methods and models used to fuse data generated by the cameras and smartphone. It details the design and implementation of an EKF using MATLAB software. Kim et al. \cite{kim2011kalman} and source code provided by Patel served as the foundation of this chapter. All files pertaining to the filter have been included on the accompanying CD.

A good starting point for this chapter would be to define the states of interest of our system. We choose our states to be various parameters relating to the human gait and the bodies pose and position in the inertial frame. The model used in this work has various constants (the lengths of the rigid beams making up the limbs), but many changing parameters (the angles these rigid beams make with each other). These angles quantify the position of the various joints during steady state running and have therefore been chosen as states.

We cannot directly measure these angles since we have no sensors directly connected to them. All the system states are predicted by the EKF using various measurements relating directly and indirectly to them. The following table specifies the parameters used to symbolize the states of the system.

\begin{table}[!ht]
\captionsetup{width=0.8\linewidth, font=small}
\centering
\label{statesForEkf}
\begin{tabular}{ll}
State & Description \\
$x_{body}$  	&x Position of body w.r.t. the inertial frame\\
$y_{body}$     &y Position of body w.r.t. the inertial frame\\
$z_{body}$     &z Position of body w.r.t. the inertial frame\\
$\phi_{body}$      &Roll of body w.r.t. the inertial frame\\
$\theta_{body}$    &Pitch of body w.r.t. the inertial frame\\
$\psi_{body}$      &Yaw of body w.r.t. the inertial frame\\
$\theta_{LH}$     &Pitch of left thigh w.r.t. left hip\\
$\psi_{LH}$      &Yaw of left thigh w.r.t. left hip\\
$\theta_{LK}$    &Pitch of left calf w.r.t. left knee\\
$\theta_{LA}$   &Pitch of left foot w.r.t. left ankle\\
$\theta_{RH}$    &Pitch of right thigh w.r.t. right hip\\
$\psi_{RH}$      &Yaw of right thigh w.r.t. right hip\\
$\theta_{RK}$   &Pitch of the right calf w.r.t. right knee\\
$\theta_{RA}$  &Pitch of the right foot w.r.t. the right ankle\\
\end{tabular}
\caption{Table showing the different states of the model to be determined by the EKF}
\end{table}

\newpage
Our system is not only concerned with these positional and angular elements, but also how they change over time. These rates where defined as the derivative of the states with respect to time. The first derivative serving as velocity and angular velocity, while the second derivative serves as acceleration and angular acceleration. Here the vector \textbf{x} serves as a element of our state vector \textbf{X}.

$$\textbf{x} = [ x_{body} \; y_{body} \; z_{body} \; \phi_{body} \;    		    \theta_{body}  \; \psi_{body}\;  \theta_{LH}\; \psi_{LH}   \;\theta_{LK} 	\;\theta_{LA} 	\;\theta_{RH} \;\psi_{RH}   	\;\theta_{RK}   \; \theta_{RA}  		]$$

$$	\textbf{X}=[\textbf{x} \; \dot{\textbf{x}} \; \ddot{\textbf{x}}] $$

The vector \textbf{x} contains 14 elements. From the above equations it is clear that our state vector \textbf{X} contains 42 elements. With the states of our system defined we must discuss state estimation and the critical elements of the EKF.

\section{State Estimation}
The key purpose of the Kalman Filter is the ability to estimate the various states of our system. To understand how this estimation will occur we need to firstly understand the KF. The following diagram shows the critical parts of the KF.

\begin{figure}[!ht]
\captionsetup{width=0.8\linewidth, font=small}
\includegraphics[width=0.6\linewidth]{figures/kf.png}
\caption{Figure showing the interplay of various elements of the KF, adapted from \cite{kfkfkf}}
\label{fig:kf}
\end{figure}

The critical elements of the KF as seen in the diagram are: the states themselves, a prediction model, an update model, measurements, initialization values, and various uncertainty models.

The underlying equation of the KF is the \textit{process equations}, where the state value at the next time instance $ X_{k+1} $ is predicted by applying the transition matrix $ F_{k+1} $ to the state values at the current time instance $ X_{k} $ and adding a zero mean Gaussian noise term $ w_{k} $. The $ w $ element of this equation is collected in the process noise matrix $ Q $.

$$ X_{k+1} = F_{k+1}X_{k} + w_{k}  $$

Another underlying equation of the KF is the \textit{measurement equation}. Here the observable measurements contained in $ Y_k $ are related to the states at the current time instance $ X_{k} $ through the measurement matrix $ H_{k} $. A zero mean Gaussian noise term $ v_{k} $ is added to account for measurement uncertainty. The various measurement uncertainties are collected in the measurements noise matrix $ R $.

$$ Y_k = H_{k}X_{k} + v_{k} $$

As discussed in the literature review, the KF can only be applied to linear systems. The EKF is the extension of the filter so that it may be applied to nonlinear systems. To introduce the workings of the EKF we start by defining a classic nonlinear system defined by the state space model

$$ X_{k+1} = f(k,X_{k}) + w_{k}  $$

$$ Y_k = h(k,X_{k}) + v_{k} $$

In this representation $ w_{k} $ and $ v_{k} $ are consistent with definitions given for the KF and are contained in matrices $ Q $ and $ R $ respectively. From the state space equations one can see that we now predict states using a nonlinear transition matrix function $ f $ and $ h $.

These functions can be defined by their anti-derivative matrices $F$ and $H$ respectively.

$$ F_{k+1,k} = \frac{\delta f(k,X_{k})}{\delta x} $$

$$ H_{k} = \frac{\delta h(k,X_{k})}{\delta x} $$

These are the fundamental equations of the KF and EKF. We can now

\section{Process Equations}
The fundamental assumption made when deriving the prediction equations for our states was that the acceleration (both linear and angular) was constant between sampling intervals. It would therefore stand that the positional states of the filter $[x_{body} \; y_{body} \; z_{body}]$ and the angular states of the filter $[\theta_{body} \; ... \; \theta_{RA}]$ could be predicted using:

$$ \ddot{p}_{k+1} = \ddot{p}_{k} + \sigma_{\ddot{p}}^{2} $$
$$ \dot{p}_{k+1} = \dot{p}_{k} + \ddot{p}_{k}T + \sigma_{\dot{p}}^{2} $$
$$ p_{k+1} = p_{k} + \dot{p}_{k}T + \sigma_{p}^{2} $$

for the positional states, and:

$$ \ddot{\alpha}_{k+1} = \ddot{\alpha}_{k} + \sigma_{\ddot{\alpha}}^{2} $$
$$ \dot{\alpha}_{k+1} = \dot{\alpha}_{k} + \ddot{\alpha}_{k}T + \sigma_{\dot{\alpha}}^{2} $$
$$ \alpha_{k+1} = \alpha_{k} + \dot{\alpha}_{k}T + \sigma_{\alpha}^{2} $$

for the angular states.

These prediction equations where created in MATLAB using symbolic functions. The sigma associated each equations takes into account the prediction uncertainties contained in the Q matrix. By adjusting these values we can increase the filter performance. This is discussed further in a later section.

\section{Measurement Equations}
The measurement equations for the lower limbs where generated using inverse kinematics. This requires a model

\subsection{Euler Matrices}
The following matrices are the rotational matrices for rotating a point in 3D space along a certain axis.

$$
Roll(\phi) =
\begin{bmatrix}
1 & 0 & 0 \\
0 & \cos{\phi} & -\sin{\phi} \\
0 & \sin{\phi} & \cos{\phi}
\end{bmatrix}
$$

$$
Pitch(\theta) =
\begin{bmatrix}
\cos{\theta} & 0 & \sin{\theta} \\
0 & 1 & 0 \\
-\sin{\theta} & 0 & \cos{\theta}
\end{bmatrix}
$$

$$
Yaw(\psi) =
\begin{bmatrix}
\cos{\psi} & -\sin{\psi} & 0 \\
\sin{\psi} & \cos{\psi} & 0 \\
0 & 0 & 1
\end{bmatrix}
$$

\subsection{Direct Cosine Matrix}

\subsection{Forward Kinematics}

\textbf{front}\\
right knee
$$ p1xyz = bodyY + bodyZ + R1 * Thigh $$
left knee
$$ p2xyz = bodyY + bodyZ + R1 * Thigh $$
right foot
$$ p3xyz = bodyY + bodyZ + R1 * Thigh + R2 * Calf + R3 * Foot $$
left foot
$$ p4xyz = bodyY + bodyZ + R1 * Thigh + R2 * Calf + R3 * Foot $$

\textbf{back}\\
right calf
$$ p1xyz = bodyY + bodyZ + R1 * Thigh + R2 * 0.5 * Calf $$
left calf
$$ p2xyz = bodyY + bodyZ + R1 * Thigh + R2 * 0.5 * Calf $$
right heel
$$ p2xyz = bodyY + bodyZ + R1 * Thigh + R2 * Calf $$
left heel
$$ p2xyz = bodyY + bodyZ + R1 * Thigh + R2 * Calf $$

\section{Camera Matrix}

It is important to understand the different parameters that mathematically quantify cameras. These parameters can be devided into \textit{extrinsic} and \textit{extrinsic}. Extrinsic camera variables related to the cameras position in the inertial frame and the direction the camera is facing. These can be summarized by the extrinsic camera matrix

$$[ R \, |\, \boldsymbol{t}] =
\left[ \begin{array}{ccc|c}
r_{1,1} & r_{1,2} & r_{1,3} & t_1 \\
r_{2,1} & r_{2,2} & r_{2,3} & t_2 \\
r_{3,1} & r_{3,2} & r_{3,3} & t_3 \\
\end{array} \right]$$

\section{Q Matrix, R Matrix and Initialization}
This section will discuss the final components of the EKF namely the Q matrix containing the various process noise variations, R matrix containing the various measurement noise variances and the initial state values.

\subsection{Defining the Q Matrix}
From the above equations we can see that the Q matrix must have dimensions of $n*n$, where $n$ in this equation is the total amount of states. As previously defined in this section our filter operates over 42 states, giving Q a size of $42*42$. All the variance parameters will be contained on the diagonal of the matrix with all other entries being zero.

To find the initial values of these uncertainties the derivative of the various accelerations where taken. The maximum element from that set was selected as the uncertainty parameter.

\subsection{Defining the R Matrix}
The R matrix relates to the measurement variables and must therefore have size of $m*m$, where $m$ is the amount of inputs the EKF. These are elements of the sensors themselves and can be found by researching the relative data sheets for the smartphone IMU. As for the cameras a relatively large uncertainty of about 5 pixels was assumed.

\subsection{Choosing Initial States}
The subject was stationary during the initial stages of the run. This allows us to initialize our state vector with all states initially zero. The filter will therefore track the transience and steady state estimation of a running subject, giving insight into the filters performance under different conditions.

\subsection{Initializing the Covariance Matrix P}
following on from the previous section zeroing the initial states of the system allows us to have a relatively small initial covariance matrix due to the relative certainty we have that the states are truly zero.


\section{Introduction}

\begin{figure}[h]
    \centering
    \begin{tikzpicture}[-, node distance = 3cm, auto]
        \node[anchor=north](H1){\(H_1\)};
        \node[anchor=north](H1_d1) at (3, 2){.};
        \node[anchor=north](H1_d2) at (3, -2){.};

        \path(H1) edge node {}(H1_d1);
        \path(H1) edge node {}(H1_d2);
        \path(H1_d1) edge [bend left] node {}(H1_d2);
        \path(H1_d1) [dashed] edge node {}(H1_d2);

        \node[anchor=north](H2) at (3.9, 0){\(H_2\)};
        \node[anchor=north](H2_d1) at (6.9, 2){.};
        \node[anchor=north](H2_d2) at (6.9, -2){.};

        \path(H2) edge node {}(H2_d1);
        \path(H2) edge node {}(H2_d2);
        \path(H2_d1) edge [bend left] node {}(H2_d2);

        \node[anchor=north](A) at (7.8, 0){\(A\)};
        \node[anchor=north](A_d1) at (10.8, 2){.};
        \node[anchor=north](A_d2) at (10.8, -2){.};

        \path(A) edge node {}(A_d1);
        \path(A) edge node {}(A_d2);
        \path(A_d1) edge [bend left] node {}(A_d2);

    \end{tikzpicture}
    \caption{Ambulance Decision Problem}
    \label{Ambulance_Problem}
\end{figure}

{\Large\textbf{States:}}

\begin{enumerate}
    \item \(A\) = Ambulance
    \item \(H_i\) = Hospital i
\end{enumerate}

{\Large\textbf{Notation:}}
\begin{itemize}
    \item \(\Lambda\) = total number of patients that need to be hospitalised
    \item \(p_i\) = proportion of patients going to Hospital i (\(p_i\Lambda\)
    = number of patients going to hospital i)
    \item \(d_i\) = distance from Hospital i
    \item \(\hat{c_i}\) = capacity of hospital i
    \item \(W(c, \lambda\, \mu)\) = waiting time in the system function
    \item \(\mu_i\) = service rate of hospital i
    \item \(\lambda_i^o\) = arrival rate of other patients to the hospital
    (not by ambulance)
    \item \(C_i(p_i) = d_i + W(c = \hat{c_i},\hspace{0.1cm} \lambda =
    p_i\Lambda + \lambda_i^o, \hspace{0.1cm} \mu = \mu_i)\)
\end{itemize}


\chapter{Short-cutting heuristics}

\section{Simple Heuristic}
\begin{enumerate}
    \item {The order of appearance of points in the hamiltonian cycle is the order of their appearance in the Euler tour. (For each of the points, we retain the first occurence of the point and discard the remaining).}
    % \item Remove repeated points in the Euler tour to get a Hamiltonian cycle.
    \item Time complexity is $O(n)$.
\end{enumerate}
% \includegraphics[scale=0.5]{simple.png}

\section{Tri-Opt Heuristic}

\begin{enumerate}
    \item In this heuristic we take a Euler tour and greedily remove the repeated vertices which have higher heuristic value.
    \item The heuristic value used is sum of distances from the vertex to adjacent vertices minus distance between the adjacent vertices.
    \item We can see that this is better than previous one but we are performing it on a Euler tour, hence there is still room for imprevement.
    \item Time complexity is $O(n)$.
\end{enumerate}
% \includegraphics[scale=0.5]{simple.png}

\section{Tri-Comp Heuristic}

\begin{enumerate}
    \item This heuristic is applied on Multi graph (H) instead of one Euler tour.
    \item Here we start with vertices of order greater than two and greedily remove its edges until its order is two.
    \item The idea is that in the final hamiltonian cycle which we need to arrive by short cutting has degree two for all the vertices.
    \item Two things we need to do are - pair up the free vertices formed greedily and make sure the process does not result in two disjoint components
    \item The heuristic value here is sum of distances between paired up vertices and distace of two edges that remained with our vertex.
    \item Since our problem is in 2d space, each vertex in MST will have a degree of maximum 5, so our multi graph will have a maximum degree of 6. This property highly affect the theoritical complexity of our heuristic.
    \item Time complexity for checking the graph connectivity is $O(n)$ and therefore, time complexity for the tri-compt heuristic is $O(n^2)$.
\end{enumerate}
% \includegraphics[scale=0.5]{simple.png}

\section{DIH-Tri-Comp Heuristic}
\begin{figure}[h]
    \centering
    \includegraphics[scale=0.3]{5.jpg}
    \caption{Pseudo code for DIH heuristic}
\end{figure}
\begin{figure}[h]
    \centering
    \includegraphics[scale=0.3]{4.jpg}
    \caption{Applying DIH on $T$(left) to get $T'$(right)}
\end{figure}
\begin{enumerate}
    \item This heuristic is DIH(Degree Increasing Heuristic) optimization applied on the MST $T$ to get a new tree $T'$, then creating a multigraph $H'$ from $T'$, followed by applying Tri-compt heuristic on the multigraph $H'$.
    \item We want to increase the order of a vertex in MST by adding the vertices  of its children to itself
    \item We can see that the tree $T'$ is no longer MST but this process preserves the Euler tours i.e. the set of Euler tours of this tree $T'$ is super set of that of the MST $T$.
    \item This way we are applying heuristic on a bigger space than that of the former one and might have a chance of getting better results.
    \item  DIH can be implemented with $O(n)$, so comp heuristic is the bottleneck here. Overall time complexity is $O(n^2)$
\end{enumerate}
\vspace{7in}
\section{Performance analysis of heuristics}

We measured the performance of the four heuristics over 100 TSP problems from TSPLIB which is a library of sample instances for the TSP (and related problems) from various sources and of various types.

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.22]{6.jpg}
    \caption{Performance of heuristics on different families of datasets}
\end{figure}


\section{The Sorting Problem}

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Algorithms}
  % \begin{center}
  %   An algorithm is a sequence of operations \\
  %   that transform the input into the output.
  % \end{center}
  \begin{center}
	What is an algorithm? \qquad \pause What is computation?
  \end{center}

  \pause

  \fignocaption{width = 0.50\textwidth}{figs/algorithm-def.pdf}

  \pause
  \vspace{-0.60cm}
  \begin{center}
	\textcolor{red}{Correctness!}
  \end{center}

  \pause

  \begin{description}[Effectiveness:]
	\item[Definiteness:] precisely defined operations
	  \pause
	\item[Finiteness:] termination
	  \pause
	\item[Effectiveness:] a reasonable model; basic operations % RAM {\scriptsize (Random-Access Machine)} model
	  \pause
	  \begin{itemize}
		% \item unrealistic: \texttt{sort} operation
		% \item realistic: arithmetic, data movement, and control
		%   \pause
		\item for sorting: compare, swap
	  \end{itemize}
  \end{description}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Sorting}
  The sorting problem:
  \begin{description}
	\item[Input:] A sequence of $n$ integers $A$:\seq{$a_1, a_2, \cdots, a_n$}.
	\item[Output:] A permutation $A'$:\seq{$a'_1, a'_2, \ldots, a'_n$} of $A$ \emph{s.t.} $a'_1 \le a'_2 \le \cdots \le a'_n$ {\small (non-decreasing order)}.
  \end{description}

  \[
	3\quad 1\quad 4\quad 2\quad \Longrightarrow 1\quad 2\quad 3\quad 4
  \]

  \pause
  \vspace{0.50cm}

  \fignocaption{width = 0.50\textwidth}{figs/sorting-alg-def.pdf}
  % sortable
  % A little more formalism: ordering relation ``$<$'' on $A$.

  % \vspace{0.20cm}
  % $\forall a, b, c \in A$,
  % \begin{description}[Transitivity:]
  %   \item[Trichotomy:] $a < b, a = b, a > b$
  %   \item[Transitivity:] $a < b \land b < c \implies a < c$
  % \end{description}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Inversions}
  \[
	A = a_1\quad a_2\quad \cdots\quad a_i\quad \cdots\quad a_j\quad \cdots\quad a_n.
  \]

  \begin{center}
	If $i < j$ and $a_{i} > a_{j}$, then $(a_i, a_j)$ is an \textcolor{red}{\bf inversion}.\\[8pt] \pause
	\textcolor{blue}{Adjacent} inversion: $(a_i, a_{i+1})$
  \end{center}

  \pause
  \vspace{-0.50cm}

  \begin{columns}
	\column{0.50\textwidth}
	  \fignocaption{width = 0.50\textwidth}{figs/inversions-example.pdf}
	\column{0.50\textwidth}
	{\small
	  \begin{center}
		\#inversions = 3\\
		\#adjacent inversions = 2
	  \end{center}
	}
  \end{columns}

  \pause
  \begin{columns}
	\column{0.50\textwidth}
	  \fignocaption{width = 0.50\textwidth}{figs/inversions-example-nonincreasing.pdf}
	\column{0.50\textwidth}
	{\small
	  \begin{center}
		\#inversions = 3 + 2 + 1 = 6\\
		\#adjacent inversions = 3
	  \end{center}
	}
  \end{columns}

  \pause
  \begin{columns}
	\column{0.50\textwidth}
	  \fignocaption{width = 0.50\textwidth}{figs/inversions-example-nondecreasing.pdf}
	\column{0.50\textwidth}
	{\small
	  \begin{center}
		\#inversions = 0\\
		\#adjacent inversions = 0
	  \end{center}
	}
  \end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Inversions}
  \begin{center}
	\fbox{\textcolor{blue}{Theorem:} $A$ is sorted $\iff$ $A$ has no adjacent inversions.}
  \end{center}

  \begin{align*}
	\onslide<2->{A \text{ is sorted } \Longrightarrow A \text{ has no adjacent inversions}.}
  \end{align*}

  \vspace{-0.50cm}

  \begin{align*}
	\onslide<3->{A \text{ has no adjacent inversions } &\Longrightarrow \forall i \in [1,n-1]: a_{i} \le a_{i+1} \\}
	  \onslide<4->{&\Longrightarrow A \text{ is sorted}.}
  \end{align*}
\end{frame}
%%%%%%%%%%%%%%%%%%%%


\chapter{Rate-Energy Tradeoff}
In this section, we first define the rate-energy (R-E) region for the proposed system, then formulate the characterization into a general optimization problem. On top of it, we decouple the spatial and frequency design, investigate the lower bound of the superposed waveform, consider the PAPR constraint, and extend the approach to MIMO cases.

\section{Rate-Energy Region}\label{sec:rate-energy-region}
  \input{rate-energy-tradeoff/rate-energy-region.tex}

\section{Problem Formulation}\label{sec:problem-formulation}
  \input{rate-energy-tradeoff/problem-formulation.tex}

\section{Iterative Algorithms}\label{sec:iterative-algorithms}
  \input{rate-energy-tradeoff/iterative-algorithms.tex}


%\section{Land Physics}
{\bf \Large
\begin{tabular}{ccc}
\hline
  Corresponding author & : & Tsuyoshi Yamaura\\
\hline
\end{tabular}
}

\subsection{Ocean physics: slab model}

The ocean slab model estimates sea temperature tendencies using a single-layered model.
The governing equations of the internal energy $E$ (J/m$^2$) and mass of ocean $M$ (kg/m$^2$) are
\begin{align}
  \frac{\partial E}{\partial t} &= G + e_{prec} - e_{evap} + Q_{ext}, \label{eq:Ocean-Tdt} \\
  \frac{\partial M}{\partial t} &= F_{prec} - F_{evap},
\end{align}
where
$G$ is the downward surface heat flux (J/m$^2$/s);
$e_{prec}$ and $e_{evap}$ are the downward surface internal energy flux (J/m$^2$/s) of the precipitation and evaporation, respectively;
$Q_{ext}$ is external heat source (J/m$^2$/s);
and $F_{prec}$ and $F_{evap}$ are the surface mass flux (kg/m$^2$/s) of the precipitation and evaporation, respectively.

The internal energy E (J/m$^2$) is
\begin{align}
 E = c_l M T,
\end{align}
where $M$ and $T$ are total mass of water (kg/m$^2$) and temperature, and
$c_l$ is the specific heat capacity of water (J/K/kg),

The surface preciptaion flux is
\begin{align}
 F_{prec} &= F_{rain} + F_{snow},
\end{align}
where $F_{rain}$ and $F_{snow}$ are the surface flux of rain and snow, respectively.
The internal energy fluxes are
\begin{align}
 e_{prec} &= c_lT_{rain}F_{rain} + ( c_iT_{snow} - L_f ) F_{snow}, \\
 e_{evap} &= c_lT_{evap}F_{evap},
\end{align}
where $c_i$ is the specific heat capacity of ice (J/K/kg);
$T_{rain}, T_{snow}$ and $T_{evap}$ are the temperature of rain, snow, and evaporated water, respectively;
Note that the fluxes of the rain and snow are positive for the downward direction and that of the evapolation is positive for the upward.
These ground surface fluxes are calculated in the surface scheme.

In the calculation of change of temperature, the mass change is taken into the account.
However, the mass change is ignored after the calculation and then $M = \rho_w D$,
where
$\rho_w$ is the water density (kg/m$^3$),
and $D$ is the water depth of the slab model.

Eq. (\ref{eq:Ocean-Tdt}) is discretized as follows:
\begin{align}
  T^{n+1}
 &= \frac{ C_w T^n + \Delta t ( G + e_{prec} - e_{evap} + Q_{ext} ) }{ C_w + \Delta t c_l ( F_{prec} - F_{evap} ) }, \nonumber\\
 &= T^n + \Delta t \frac{ G + e_{prec} - e_{evap} + Q_{ext} - c_l ( F_{prec} - F_{evap} ) T^n }{ C_w + \Delta t c_l ( F_{prec} - F_{evap} ) },
\end{align}
where
$C_w$ is the heat capacity of the slab layer (J/K/m$^2$) and $C_w = \rho_w c_l D$.

Note that the internal energy is not conserved, since the mass change is ignored.

\subsection{Sea ice}
\subsubsection{Governing equation}
The equations of budget of the mass (kg/m$^2$) and internal energy (J/m$^2$) in the ocean and sea ice are
\begin{align}
 \frac{\partial M_i}{\partial t} &= f_i ( F_{prec}- F_{subl} ) - m_{mlt} + m_{frz}, \\
 \frac{\partial E_i}{\partial t} &= f_i ( G_i - G_{oi} + e_{prec} - e_{subl} ) - c_lT_0m_{mlt} + ( c_iT_0 - L_f ) m_{frz}, \\
 \frac{\partial M}{\partial t} &= (1-f_i) ( F_{prec} - F_{evap} ) + m_{mlt} - m_{frz}, \\
 \frac{\partial E}{\partial t} &= (1-f_i) ( G_o + e_{prec} - e_{evap} ) + f_i G_{oi} + c_lT_0m_{mlt} - ( c_iT_0 - L_f )m_{frz},
\end{align}
where
$f_i$ is the fraction of the sea ice;
$m_{mlt}$ and $m_{frz}$ are the mass change (kg/m$^2$/s) by melting of ice and freezing of sea water;
and $G_i, G_o$ and $G_{oi}$ are the heat flux (J/m$^2$/s) at the ice-atmosphere, ocean-atmosphere, and ice-ocean surfaces, respectively;
$F_{subl}$ is the upward mass flux due to the sublimation of ice (kg/m$^2$/s);
and $e_{subl}$ is the upward internal energy flux at the surface (J/m$^2$/s) of the sublimated ice as
\begin{align}
 e_{subl} &= (c_iT_{subl}-L_f)F_{subl}.
\end{align}

As noted in the previous section, the mass change in the sea water is ignored after the calculation of change in the ocean temperature.

The $G_{oi}$ is estimated by the diffusion equation
\begin{align}
 G_{oi} &= \nu_i \frac{T_i - T}{D_i/2}, \\
 D_i &= \frac{M_i}{\rho_i f_i},
\end{align}
where $T_i$ is the temperature of the sea ice;
$\nu_i$ and $D_i$ are the thermal conductivity of ice (J/K/m$^3$/s) and depth of the sea ice (m).

The fraction is estimated as
\begin{align}
 f_i &= \sqrt{ \frac{M_i}{M_c} },
\end{align}
where $M_c$ is the critical ice mass (kg/m$^2$).

The amount of the melting during a time step is estimated to  satisfy the conservation of mass and internal energy of the sea ice as
\begin{align}
 M_{mlt} &= \int_t^{t+\Delta t} m_{mlt} dt \nonumber\\
 &= \min\left\{ \max\left\{ \frac{ c_i(T_i-T_0) }{ (c_w-c_i) T_0 + L_f } M_i, 0\right\}, M_i\right\}.
\end{align}

The amount of the freezing is estimated to satisfy the conservation of mass and internal energy of the ocean as
\begin{align}
 M_{frz} &= \int_t^{t+\Delta t} m_{frz} dt \nonumber\\
 &= \min\left\{ \max\left\{ \frac{ c_l \rho_w D ( T_0 - T ) }{ (c_l - c_i)T_0 + L_f }, 0\right\}, \rho_w D\right\},
\end{align}
where $T_0$ is the freezing tempearture.

\subsubsection{Time integration}
The governing equation is solved by a spliting method.
In the first step, the mass and internal energy budgets of the ice without the phase change is solved.
In the second step, the melting of sea ice is estimated by the mass and internal energy conservation.
In the next step, then the temperature change of ocean is calculated in the ocean scheme.
In the last step, the freezing ocean water is estimated and the mass and temperature of ice and ocean is updated.

The followings are the summary of the sequence of calculation.
Here, the superscript ``$n$'' indicates the quantites at the time step $n$, and ``$n_1$'', ``$n_2$'', ``$n_3$'', and ``$n+1$'' are those after calculation of the first, seccond, third and the last step, respectively.

\begin{description}

\item[First step]
\begin{align}
 \Delta M_i^{n_1} &= \Delta t f_i^n ( F_{prec} - F_{subl} ), \\
 \Delta E_i^{n_1} &= \Delta t f_i ( G_i - G_{oi} + e_{prec} - e_{subl} ), \\
 M_i^{n_1} &= M_i^n + \Delta M_i^{n_1}, \\
 T_i^{n_1} &= T_i^n + \frac{ \Delta E_i^{n_1} - ( c_iT_i^n - L_f ) \Delta M_i^{n_1} }{c_i M_i^{n_1}}.
\end{align}

\item[Second step]
\begin{align}
 M_{mlt} &= \min\left\{ \max\left\{ \frac{ c_i(T_i^{n_1}-T_0)M_i^{n_1} }{ (c_w-c_i) T_0 + L_f }, 0\right\}, M_i^{n_1}\right\}, \\
 M_i^{n_2} &= M_i^{n_1} - M_{mlt}, \\
 T_i^{n_2} &= T_i^{n_1} + \frac{ - c_l T_0  + ( c_iT_i^{n_1} - L_f )}{c_i M_i^{n_2}}M_{mlt}.
\end{align}

\item[Third step] (Ocean model)
\begin{align}
 \Delta E^{n_3} &= \Delta t \{ (1-f_i)(G_o + e_{prec} - e_{evap}) + f_i G_{oi} \} + c_l T_0 M_{mlt}, \\
 \Delta M^{n_3} &= \Delta t (1-f_i)(F_{prec}-F_{evap}) + M_{mlt}, \\
 T^{n_3} &= T^n + \frac{ \Delta E^{n_3} - c_l T^n \Delta M^{n_3} }{c_l \{\rho_w D + \Delta M^{n_3} \}}.
\end{align}

\item[Forth step]
\begin{align}
 M_{frz} &= \min\left\{ \max\left\{ \frac{ c_l \rho_w D ( T_0 - T^{n_3} ) }{ (c_l - c_i)T_0 + L_f }, 0\right\}, \rho_w D\right\}, \\
 M_i^{n+1} &= M_i^{n_2} + M_{frz}, \\
 T_i^{n+1} &= T_i^{n_3} + ( T_0 - T_i^{n_3} ) \frac{M_{frz}}{M_i^{n+1}}, \\
 T^{n+1} &= T^{n_3} + \frac{ - ( c_i T_0 - L_f ) + c_l T^{n_3} }{c_l (\rho_w D - M_{frz}) } M_{frz}.
\end{align}

\end{description}

\subsection{Sea surface albedo}
\subsubsection{Nakajima et al. (2000) model}
\citet{nakajima_2000} provided the albedo for the short wave on the sea surface $A$:
\begin{align}
  A = \exp \left[ \Sigma_{i=1}^{3} \Sigma_{j=1}^{5} C_{ij} t^{j-1} \mu_0^{i-1} \right],
\end{align}
where
$C_{ij}$ is the empirical optical parameters,
$t$ is the flux transmissivity for short-wave radiation,
and $\mu_0$ is cosine of the solar zenith angle.

\subsection{Roughness length}
\subsubsection{Miller et al. (1992) model}
\citet{miller_1992} provides the roughness length over the tropical ocean,
based on numerical calculations by combining smooth surface values
with the Charnock relation for aerodynamic roughness length
and constant values for heat and moisture in accordance with \citet{Smith_1988,Smith_1989} suggestions:
\begin{align}
  z_0 &= 0.11u/\nu_* + 0.018u_*^2/g, \label{eq: z_0} \\
  z_t &= 0.40u/\nu_* + 1.4 \times 10^{-5}, \label{eq: z_t} \\
  z_q &= 0.62u/\nu_* + 1.3 \times 10^{-4}, \label{eq: z_q}
\end{align}
where $\nu_*$ is the kinematic viscosity of air ($\sim 1.5 \times 10^{-5}$), and $z_0, z_t$,
and $z_q$ are the roughness length for momentum, heat, and vapor, respectively.

\subsubsection{Moon et al. (2007) model}
\citet{moon_2007} provides the air--sea momentum flux at high wind speeds
based on the coupled wave--wind model simulations for hurricanes.
At first, the wind speed $U$ at 10-m height is estimated from the previous roughness length $z_0$, as follows:
\begin{align}
  U =\frac{u_{*}}{\kappa} \ln \frac{10}{z_0},
\end{align}
where
$u_{*}$ is friction velocity (m/s)
and $\kappa$ is von Kalman constant.
And then, new roughness length $z_0$ is iteratively estimated from the wind speed:
\begin{equation}
  z_0   = \left\{
  \begin{array}{lll}
    \frac{0.0185}{g} u_{*}^2 & \mathrm{for} & U < 12.5, \\
    \left[ 0.085 \left( -0.56 u_{*}^2 + 20.255 u_{*} + 2.458 \right) - 0.58 \right] \times 10^{-3} & \mathrm{for} & U \ge 12.5.
   \end{array} \right.
\end{equation}

Furthermore, \citet{Fairall_2003} provides the roughness length for the heat and vapor
using that for momentum, as follows:
\begin{align}
  z_t &= \frac{ 5.5 \times 10^{-5} }{ ( z_0 u_{*} / \nu_{*} )^{0.6} }, \\
  z_q &= z_t.
\end{align}


\documentclass[11pt]{article}
\usepackage{enumitem}
\usepackage{amsmath}
\begin{document}
\title{MAT1830 --- Assignment 2}
\author{Dylan Pinn --- 24160547}
\maketitle

\section*{Question 1}
Use truth tables to determine whether $(a \land \neg b) \to (b \lor c)$ is logically equivalent to $\neg a \lor b \lor c$.

\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
$a$ & $b$ & $c$ & $a \land \neg $ & $b \lor c$ & $(a \land \neg b) \to (b \lor c)$ & $\neg a \lor b \lor c$ \\ \hline
T & T & T & F & T & T & T \\ \hline
T & T & F & F & T & T & T \\ \hline
T & F & T & T & T & T & T \\ \hline
T & F & F & T & T & T & F \\ \hline
F & T & T & F & T & T & T \\ \hline
F & T & F & F & F & T & T \\ \hline
F & F & T & F & T & T & T \\ \hline
F & F & F & F & F & F & T \\ \hline
\end{tabular}

Because they have different values they are not equivalent.

\break

\section*{Question 2}
Use laws of logic to show that $\neg (p \lor \neg (p \to q)) \lor p$ is a tautology.

\begin{equation}
	\neg (p \lor \neg (p \to q)) \lor p
\end{equation}
\begin{equation} \label{eq:1}
	\neg (p \lor \neg (\neg p \lor q)) \lor p
\end{equation}
Equation \ref{eq:1} uses Implication law.
\begin{equation} \label{eq:2}
	\neg (p \lor \neg (\neg p) \land \neg q) \lor p)
\end{equation}
Equation \ref{eq:2} uses De Morgan's law.
\begin{equation} \label{eq:3}
	\neg (p \lor p \land \neg q) \lor p
\end{equation}
Equation \ref{eq:3} uses Double Negation law.
\begin{equation} \label{eq:4}
	\neg (p \land \neg q) \lor p
\end{equation}
Equation \ref{eq:4} uses Idempotent law.
\begin{equation} \label{eq:5}
	\neg p \land \neg (\neg q) \lor p
\end{equation}
Equation \ref{eq:5} uses De Morgan's law.
\begin{equation} \label{eq:6}
	\neg  p \lor q \lor p
\end{equation}
Equation \ref{eq:6} uses Double Negation law.
\begin{equation} \label{eq:7}
	T \lor q
\end{equation}
Equation \ref{eq:7} uses Inverse law.
\begin{equation} \label{eq:8}
	T
\end{equation}
Equation \ref{eq:8} uses Annihilation law.

This shows that it is a tautology.

\break

\section*{Question 3}
For each of the following statements, write down the statement's contrapositive and then write down the statement's negation.

\begin{enumerate}[label=(\roman*)]
\item "If the function is differentiable, then it is continuous."

	\textbf{Contrapositive}

	"If it isn't continuous, then the function is not differentiable."

	\textbf{Negation}

	"There exists a continuous function that is not differentiable."

\item "If a weak key was used, then the encryption wasn't secure."

	\textbf{Contrapositive}

	"If the encryption was secure, then a weak key wasn't used."

	\textbf{Negation}

	"The encryption was secure and a weak key was used."

\end{enumerate}
\break

\section*{Question 4}

Pei Ann has been dealt two cards from a standard 52 card deck. She holds one in her left hand and one in her right.

Let $p$ be the proposition "The card in Pei Ann's left hand is an ace".

Let $q$ be the proposition "The card in Pei Ann's right hand is an ace".

Let $r$ be the proposition "The card in Pei Ann's left hand is a club".

Let $s$ be the proposition "The card in Pei Ann's right hand is a club".

Write down propositions (using just $p$, $q$, $r$, $s$ and logical connectives) corresponding to the following statements.

\begin{enumerate}[label=(\roman*)]

\item Neither of Pei Ann's cards is an ace.

$$\neg p \land \neg q$$

\item If Pei Ann has the ace of clubs in her right hand, then she doesn't have a club in her left hand

$$(q \land s) \to \neg r $$

\item Pei Ann has the ace of clubs and another club.

$$((p \land r) \lor (q \land s)) \land (r \lor s) $$

\end{enumerate}

\end{document}


\section{Proof Outline}

\begin{itemize}

\item A logical region $L$ is a set of abstract memory locations $a_i, a_j, ... \in A$.

\item A coloring function $c : A \rightarrow C$ is a function from abstract memory locations to ``colors''.

\item A partitioning $P_{L,c} : C \rightarrow 2^A$ of a region $L$ with a coloring function $c$ is a function from a color to a subregion of L, satisfying:

\begin{itemize}

\item $\forall L,c,i,a . a \in L \wedge c(a) = i \leftrightarrow a \in P_{L,c}(i)$

\item $\forall L,c,i_1,i_2 . i_1 \neq i_2 \rightarrow P_{L,c}(i_1) * P_{L,c}(i_2)$

\end{itemize}

\item A static effect $E$ is a set of tuples $\langle L, op \rangle$ where $op \in \{ read, write \} \cup \{ reduce_f : f \text{is a reduction function} \}$.

\item Physical memory locations are represented by the set $m_1, m_2, ... \in M$, along with a mapping function $\alpha : M \rightarrow A$ that describes which abstract location a physical memory location corresponds to.

\item A dynamic trace $D = \langle \hat E, \hat O \rangle$ is a directed acyclic graph whose nodes $\hat E$ are actual memory operations $\langle m, op \rangle$ and edges $\hat O$ describe a partial ordering $\hat e_1 \prec \hat e_2$ of those memoory operations.  (Hmm...  Need notation that makes it clear that the same memory operation can be performed on the same memory address multiple times.)

\item Soundness of effects: If $\vdash t : ^ET$ then the mapping function $\alpha$ and dynamic trace $D = \langle \hat E, \hat O \rangle$ that results from evaluating $t$ have the following properties:

\begin{itemize}

\item $\forall m . \langle m, read \rangle \in \hat E \rightarrow \exists L . \alpha(m) \in L \wedge \langle L, read \rangle \in E$

\item $\forall m . \langle m, write \rangle \in \hat E \rightarrow \exists L . \alpha(m) \in L \wedge \langle L, write \rangle \in E$

\item $\forall m, f . \langle m, reduce_f \rangle \in \hat E \rightarrow ( \exists L . \alpha(m) \in L \wedge \langle L, reduce_f \rangle \in E ) \vee ( \exists L_1, L_2 . \alpha(m) \in L_1 \wedge \langle L_1, read \rangle \in E \wedge \alpha(m) \in L_2 \wedge \langle L_2, write \rangle \in E )$

\end{itemize}

\item Two dynamic subtraces $D_1 = \langle \hat E_1, \hat O_1 \rangle$, and $D_2 = \langle \hat E_2, \hat O_2 \rangle$ are ``memory ordered'' (written $D_1 \prec_D D_2$) within a larger trace $D = \langle \hat E_1 \cup \hat E_2 \cup \hat E', \hat O_1 \cup \hat O_2 \cup \hat O' \rangle$ if $D_2$ sees all the results of $D_1$'s memory operations and $D_1$ sees none of the results of $D_2$'s memory operations:

\begin{tabular}{l@{}l@{}l}
$D_1 \prec_D D_2 \leftrightarrow \forall$ & $\hat e_1 = \langle m_1, op_1 \rangle \in \hat E_1,$ \\
& $\hat e_2 = \langle m_2, op_2 \rangle \in \hat E_2 . \big($ & $m_1 \neq m_2 \vee$  \\
&& $( op_1 = read \wedge op_2 = read ) \vee$ \\
&& $( op_1 = reduce_f \wedge op_2 = reduce_f ) \vee$ \\
&& $( \hat e_1 \prec \hat e_2 \in \hat O' ) \big)$
\end{tabular}

\item Note that if $D_1$ and $D_2$ have no memory addresses in common, then you have $D_1 \prec_D D_2$ and $D_2 \prec_D D_1$ for all D.  Maybe $\prec$ is the wrong symbol to use?

\item Tasks are annotated with a coherence requirements $H_{excl}, H_{atom} \subseteq A$.  The default annotation is $H_{excl} = \bigcup_{\langle L, op \rangle \in E} L, H_{atom} = \emptyset$.

\item The runtime enforces an execution order $\prec_E$ between two tasks $S_1$ and $S_2$ as follows:

\begin{itemize}

\item Strict ordering: when the two tasks have exclusive coherence requirements on two regions that can't be proven disjoint (i.e. $\not\vdash H_{excl_1} * H_{excl_2}$), we enforce $S_1 \prec_E S_2$.

\item Serializability: when the two tasks have atomic coherence requirements on two regions that can't be proven disjoint, we enforce $S_1 \prec_E S_2 \vee S_2 \prec_E S_1$.

\end{itemize}

\item Execution order is stronger than memory order: $(S_1 \prec_E S_2) \rightarrow ( \forall \hat e_1 \in \hat E_1, \hat e_2 \in \hat E_2 . \hat e_1 \prec \hat e_2 ) \rightarrow (\forall D. D_1 \prec_D D_2)$.

\item Coherence of sibling tasks:  If sibling tasks $S_1$ and $S_2$ are program ordered (i.e. $S_1 \prec_P S_2$) within their parent task:

\begin{itemize}

\item Overlap in exclusivity requirements guarantees memory ordering: $H_{excl_1} \cap H_{excl_2} \neq \emptyset \rightarrow D_1 \prec_D D_2$.  (If $\vdash (E_1 \cap H_{excl_1}) * (E_2 \cap H_{excl_2})$, soundness of effects guarantees disjointness of memory addresses and therefore memory ordering.  If not, the runtime enforces execution order and therefore memory ordering.)

\item Overlap in atomic requirements guarantees serializability: $H_{atom_1} \cap H_{atom_2} \neq \emptyset \rightarrow D_1 \prec_D D_2 \vee D_2 \prec_D D_1$.  (Parallels proof above.)

\end{itemize}

\end{itemize}


\chapter{Miscellaneous Services}

The modules described in this chapter provide miscellaneous services
that are available in all Python versions.  Here's an overview:

\begin{description}

\item[math]
--- Mathematical functions (\code{sin()} etc.).

\item[rand]
--- Integer random number generator.

\item[whrandom]
--- Floating point random number generator.

\item[array]
--- Efficient arrays of uniformly typed numeric values.

\end{description}


\section{Scheduling and Partial Orders}

\frame{
{Part 3: Scheduling and Partial Orders}

\tableofcontents[currentsection,hideallsubsections, firstsection=1, sections={1-3}]
}

\subsection{Scheduling}

\begin{frame}
  \frametitle{Using DAGs for Scheduling}

  Let's consider again using DAGs for calculating course prerequisites.\medskip

  \begin{columns}[T]
    \column{0.3\textwidth}
    $18.01 \rightarrow 6.042$\\
    $18.01 \rightarrow 18.02$\\
    $18.01 \rightarrow 18.03$
    \column{0.35\textwidth}
    $6.001 \rightarrow 6.034$\\
    $6.042 \rightarrow 6.046$\\
    $8.02 \rightarrow 6.002$\\
    $18.03, 6.002 \rightarrow 6.004$
    \column{0.35\textwidth}
    $6.001, 6.004 \rightarrow 6.033$\\
    $6.033 \rightarrow 6.857$\\
    $6.046 \rightarrow 6.840$
  \end{columns}

  \vfill

  We say that $u$ is a \structure{indirect prerequisite} of $v$ if there is a positive length walk in graph $R$:

    \begin{center}
      $18.01 \rightarrow 6.042 \rightarrow 6.046 \rightarrow 6.840$
    \end{center}
\end{frame}

\begin{frame}{DAGs and Scheduling}{Minimal, Minimum, Maximal, Maximum of a DAG}
  \begin{columns}
    \column{0.4\textwidth}
      \includegraphics[width=1\textwidth]{../img/greedy_schedule}

      \column{0.6\textwidth}
    \begin{itemize}
    \item A \structure{minimal} course is does not have any prerequisites:
    \begin{itemize}
      \item $\emptyset \to 18.01$, $\emptyset \to 6.001$, $\emptyset \to  8.02$
    \end{itemize}\bigskip

    \item A \structure{minimum} course is an indirect prerequisite of {\bf all} courses.
    \begin{itemize}
      \item none in this example!
      \item if we add a course $x \to \{18.01, 8.02, 6.001\}$, then $x$ would be the minimum.
    \end{itemize}\bigskip

    \item \structure{Maximal} and \structure{maximum} courses have a similar definition.
    \begin{itemize}
      \item $\{18.02, 6.840, 6.857, 6.034\}\to \emptyset$ are maximal.
    \end{itemize}
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}{DAG and Scheduling}{How to Schedule}

  \begin{columns}
    \column{0.4\textwidth}
      \includegraphics[width=1\textwidth]{../img/greedy_schedule}

    \column{0.6\textwidth}
      If we have the graph of course requirements, how do we select the courses for each semester? \medskip

      \structure{Greedy Scheduling}:
      \begin{enumerate}
      \item Identify Minimal Subjects;
      \item Add Minimal Subjects to Schedule;
      \item Remove Minimal Subjects;
      \item Return to Step 1
      \end{enumerate}
  \end{columns}\medskip

  Schedule:\\
  $\{18.01, 8.02, 6.001\} \to \{18.02, 6.042, 18.03, 6.002, 6.034\} \to \{6.046, 6.004\} \to \{ 6.840, 6.033\} \to 6.857$
\end{frame}

\begin{frame}{DAG and Scheduling}{Anti-Chains}
  \begin{columns}
  \column{0.4\textwidth}
    \includegraphics[width=1\textwidth]{../img/greedy_schedule}

  \column{0.6\textwidth}

    \begin{itemize}
    \item An \structure{anti-chain} is a set of vertices (courses) where there is no direct or indirect requisite relation among them.\medskip

    \item This means that the courses in an anti-chain can be taken in any order, even all at the same time.\medskip

    \item Members of an anti-chain are \structure{imcomparable}: It is not possible to say which one comes first.\medskip

    \item A relation graph can have multiple anti-chains. Example:
    \begin{itemize}
      \item $\{6.046, 6.004\}$
      \item $\{6.046, 18.03, 6.001\}$
    \end{itemize}
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}{DAG and Scheduling}{Chains and Topological Sort}

  \begin{block}{Chains}
    Just like anti-chain is a set of vertices that have no relation among themselves, a \structure{chain} is a set of vertices that {\bf all} have a relation among themselves.
  \end{block}\medskip

  Using of chains and anti-chains, we define a \structure{Topological Sort}. A topological sort is an ordering of all vertices in $G$ that obeys the requisite relations.
  \begin{itemize}
    \item 18.01, 6.001, 8.02, 6.002, 18.03, 6.034, 6.042, 18.02, 6.004, 6.046, 6.033, 6.840, 6.857
    \item 6.001, 8.02, 6.002, 18.01, 6.034, 18.03, 18.02, 6.042, 6.004, 6.046, 6.033, 6.857, 6.840
  \end{itemize}
  If $G$ has anti-chains, it will also have multiple topological sorts.

\end{frame}

\begin{frame}{DAG and Scheduling}{Parallel Processing}

  We can use the same way of thinking to describe \structure{parallel scheduling} of tasks.\bigskip

  \begin{itemize}
    \item $n$ tasks have to be executed by $p$ processors.
    \item some pairs of tasks have a {\bf prerequisite} relation.
    \item \structure{Minimum Parallel Time}: minimum time to complete all tasks (assuming no limits on $p$)
      \begin{itemize}
        \item Minimum Parallel Time = Maximum Chain Size
      \end{itemize}
    \item \structure{Maximum Parallel Load}: value of $p$ necessary to achieve the Minimum Parallel Time
    \begin{itemize}
      \item Maximum Parallel Load $\leq$ Maximum Anti-chain Size
    \end{itemize}
  \end{itemize}
\end{frame}

%\section{Partial Orders and Equivalence}

\begin{frame}{Partial orders: Transitivity}

  In a graph $G$, if there is a walk from $u$ to $v$, and a walk from $v$ to $w$, then there is a walk from $u$ to $w$
  \begin{center}
    \begin{tikzpicture}[scale=.5,auto,swap]
      \tikzset{edge/.style = {->,>=latex'}}
      \node[vertex] (a) at (0,0) {u};
      \node[vertex] (b) at (3,0) {v};
      \node[vertex] (c) at (6,0) {w};
      \draw[edge] (a) to (b);
      \draw[edge] (b) to (c);
      \draw[dotted] (a) to[bend right] (c);
    \end{tikzpicture}
  \end{center}\bigskip

  Representing this in terms of \structure{walk relation} in $G$:
  \begin{equation*}
    uG^+v \land vG^+w \implies uG^+w
  \end{equation*}\bigskip

  \begin{block}{Definition: Transitive Relations}
    A relation {\bf R} is transitive if:\hspace{1cm} $xRy \land yRz \implies xRz$
  \end{block}
\end{frame}

\begin{frame}{Partial Orders: Assimetry}

  In an \structure{acyclic digraph G}, we can observe that for any two vertices $v$ and $u$, if there is a walk from $v$ to $u$, then there is no walk from $u$ to $v$.\bigskip

  \begin{block}{Definition: Assimetric Relation}
    A relation {\bf R} is assimetric if: $uD^+v \implies \text{NOT}(vD^+u)$
  \end{block}
\end{frame}

\begin{frame}{Strict Partial Order}

  A relation $R$ is a \structure{Strict Partial Order}(SPO) {\bf iff} it is {\bf Transitive} and {\bf Assimetric}.\bigskip

  Examples:
  \begin{itemize}
  \item The $\subset$ relation on sets
  \item The ``indirect prerequisite'' relationship on subjects.
  \item The $<$ relationship on $\mathbb{R}$
  \end{itemize}\bigskip

  Another way to say it, is that $R$ is a \structure{SPO} {\bf iff} $R$ is the walk relation $D^+$ for some DAG $D$.
\end{frame}

\begin{frame}{Path Total Orders}

    A \structure{Strict Partial Order} is also \structure{Path Total} if, for any two distinct elements, one will always be ``greater than'' another.

    \bigskip

    Example: $<$ on $\mathbb{R}$: if $x,y \in \mathbb{R},
    x\neq y \implies x>y \text{ or } y>x$

    \bigskip

    Counter-Example: $\subset$ in POW($\mathbb{N}$): $\{1,3\} \not\subset \{2,5\} \not\subset \{1,3\}$

    \vfill

    \begin{itemize}
    \item Relation $R$ is \structure{path total}: if $x \neq y \implies xRy \lor yRx$
    \item This means there are \alert{no imcomparable elements}
    \end{itemize}

    In a \structure{path total} relation, the whole graph is a
    \structure{chain}
  \begin{center}
    \begin{tikzpicture}[scale=.8,auto,swap]
      \tikzset{edge/.style = {->,>=latex'}}
      \node[vertex] (a) at (0,0) {};
      \node[vertex] (b) at (1,0) {};
      \node[vertex] (c) at (2,0) {};
      \node[vertex] (d) at (4,0) {};
      \node[vertex] (e) at (5,0) {};
      \node[vertex] (f) at (6,0) {};
      \draw[edge] (a) to (b);
      \draw[edge] (b) to (c);
      \draw[dotted] (c) to (d);
      \draw[edge] (d) to (e);
      \draw[edge] (e) to (f);
    \end{tikzpicture}
  \end{center}
\end{frame}

\begin{frame}{Weak Partial Order}

  A \structure{weak partial order} is the same as a \structure{strict
    partial order} R, except that $aRa$ always holds:
  \begin{center}
    \begin{tikzpicture}[scale=.8,auto,swap]
      \tikzset{edge/.style = {->,>=latex'}}
      \node[vertex] (a) at (0,0) {};
      \node[vertex] (b) at (1,0) {};
      \node[vertex] (c) at (2,0) {};
      \node[vertex] (d) at (4,0) {};
      \node[vertex] (e) at (5,0) {};
      \node[vertex] (f) at (6,0) {};
      \draw[edge] (a) to (b);
      \draw[edge] (b) to (c);
      \draw[dotted] (c) to (d);
      \draw[edge] (d) to (e);
      \draw[edge] (e) to (f);
      \draw[edge] (a) to[loop] (a);
      \draw[edge] (b) to[loop] (b);
      \draw[edge] (c) to[loop] (c);
      \draw[edge] (d) to[loop] (d);
      \draw[edge] (e) to[loop] (e);
      \draw[edge] (f) to[loop] (f);
    \end{tikzpicture}
  \end{center}

  \bigskip

  \begin{itemize}
  \item Examples: $\subseteq$ on sets, $\leq$ on $\mathbb{R}$
  \item Weak Partial Orders define the property of
    \structure{Reflexivity}
  \item Relation $R$ on $A$ is \structure{reflexive} {\bf iff} $aRa,
    \forall a\in A$
  \end{itemize}

  Another way to define a weak partial order is that $R$ is a WPO {\bf iff}\\ $R = D^*$ for some DAG $D$
\end{frame}

\begin{frame}
  \frametitle{Assimetry and Antissimetry}

  {\larger

    \begin{block}{Assimetry}
      \begin{itemize}
      \item Reflexibility is \alert{never} allowed
      \item R is \structure{assimetric} {\bf iff}:
        \begin{equation*}
          xRy \implies \text{NOT}(yRx)
        \end{equation*}
      \end{itemize}

    \end{block}

    \begin{block}{Antissimetry}
      \begin{itemize}
      \item Reflexibility is \alert{sometimes} allowed
      \item R is \structure{antissimetric} {\bf iff}
        \begin{equation*}
          xRy \implies \text{NOT}(yRx), \text{ for } x \neq y
        \end{equation*}
      \end{itemize}
    \end{block}
  }
\end{frame}

\subsection{Partial Orders and Isomorphisms}

\begin{frame}{Partial Orders and Isomorphism}{Proper Subset Relation}
  \frametitle{Proper Subset Relation}

  The proper subset relation: $A \subset B$ represents a partial order.\bigskip

  For example, the proper subset relation defined on the power set of $\{1,2,3,5,10,15,30\} - \emptyset$ is as follows:

\begin{center}
    \begin{tikzpicture}[scale=1.2,auto,swap]
      \tikzset{edge/.style = {->,>=latex'}}
      \node[vertex,label={1}] (a) at (0,1) {};
      \node[vertex,label={1,3}] (b) at (2,0) {};
      \node[vertex,label={1,5}] (c) at (2,1) {};
      \node[vertex,label={1,2}] (d) at (2,2) {};
      \node[vertex,label={1,3,5,15}] (e) at (4,0) {};
      \node[vertex,label={1,2,5,10}] (f) at (4,2) {};
      \node[vertex,label={1,2,3,5,10,15,30}] (g) at (5,1) {};
      \draw[edge] (a) to (b);
      \draw[edge] (a) to (c);
      \draw[edge] (a) to (d);
      \draw[edge] (c) to (e);
      \draw[edge] (b) to (e);
      \draw[edge] (c) to (f);
      \draw[edge] (d) to (f);
      \draw[edge] (e) to (g);
      \draw[edge] (f) to (g);
    \end{tikzpicture}
  \end{center}
\end{frame}

\begin{frame}{Partial Orders and Isomorphism}{Proper Divide Relation}

  The \structure{proper divide} relation is defined as $a R b$ if $a|b$ and $a \neq b$.\bigskip

  We can see that, for the set $\{1,2,3,5,10,15,30\}$, the proper subset relation and the proper division relation have {\bf the same relationship DAG}.\bigskip

  This means that the two relations are \structure{{\bf isomorphic}}

  \begin{center}
    \begin{tikzpicture}[scale=1.2,auto,swap]
      \tikzset{edge/.style = {->,>=latex'}}
      \node[vertex,label={1}] (a) at (0,1) {};
      \node[vertex,label={3}] (b) at (2,0) {};
      \node[vertex,label={5}] (c) at (2,1) {};
      \node[vertex,label={2}] (d) at (2,2) {};
      \node[vertex,label={15}] (e) at (4,0) {};
      \node[vertex,label={10}] (f) at (4,2) {};
      \node[vertex,label={30}] (g) at (5,1) {};
      \draw[edge] (a) to (b);
      \draw[edge] (a) to (c);
      \draw[edge] (a) to (d);
      \draw[edge] (c) to (e);
      \draw[edge] (b) to (e);
      \draw[edge] (c) to (f);
      \draw[edge] (d) to (f);
      \draw[edge] (e) to (g);
      \draw[edge] (f) to (g);
    \end{tikzpicture}
  \end{center}
\end{frame}

\begin{frame}{Isomorphism}

    \begin{itemize}
    \item Two graphs are \structure{isomorphic} if they have the same \structure{set of vertices and set of edges}\bigskip

    \item More formally, two graphs $G_1, G_2$ are \structure{isomorphic} if there is a relation $M$ which is an \emph{edge preserving maching} between their vertices.\bigskip

    \item $G_1 \text{ isomorphic } G_2 \iff \exists \text { bijection
    } M:V_1\to V_2$\\\hfill with $(u,v) \in E_1 \iff
      (M(u),M(v)) \in E_2$

    \end{itemize}
\end{frame}

%% TODO: Remember why this is important and then re-add to the lecture
% \begin{frame}
%   \frametitle{Isomorphism, $\subset$ and partial orders}
%
%   {\larger
%     {\bf Theorem:} Every strict p.o. $R$ is isomorphic to some
%     collection of sets partially ordered by $\subset$.
%
%     \bigskip
%
%     {\bf Proof (by construction):}
%     \begin{itemize}
%     \item Map element $a$ to the set of elements below it.
%     \item in other words, $a$ maps to $\{b \in A| bRa \lor b = a\}$\\
%       \hfill(remember that NOT$(aRa)$)
%     \item in other words, $f(a) ::= R^{-1}(a) \cup \{a\}$
%     \end{itemize}
%
%     \bigskip
%
%     {\bf Example:} from divides
%     \begin{itemize}
%     \item $f(10) = 1|10, 2|10, 5|10, \cup \{10\} = \{1,2,5,10\}$
%     \item $f(3) = 1|3, \cup \{3\} = \{1,3\}$
%     \end{itemize}
%   }
% \end{frame}

\subsection{Equivalence Relations}

\begin{frame}
  \frametitle{Symmetric Relations and Equivalence Relations}

  \begin{itemize}
    \item If there is a walk from $u$ to $v$ and a walk from $v$ to
      $u$, then we say that $u$ and $v$ are \structure{strongly
      connected}.
      \begin{itemize}
        \item $uG^*v$ and $vG^*u$
      \end{itemize}\bigskip

    \item The relation $R$ is \structure{symmetric} if $aRb \implies bRa$.
    \begin{itemize}
      \item The walk relation of A \structure{strongly connected} graph is symmetric.
    \end{itemize}\bigskip

    \item An \structure{equivalence relation} $R$ is: transitive,
      symmetric and reflexive.\bigskip

    \item This means that $R$ is an \structure{equivalence relation} {\bf iff} $R$ is the \structure{strongly connected} relation of some DiGraph.
    \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Equivalence Relations Examples}

  The definitions of the last slide allows us to formally define an \emph{equivalence equation}.\bigskip

  {\larger
    Examples:
    \begin{itemize}
    \item Equality: $=$
    \item $\equiv $(mod n)
    \item Same Size, Same Color, etc.
    \end{itemize}
  }\bigskip

  It may seem that an equivalence relation is too obvious to need a definition (specially for numbers!), but this can be useful when we want to define equivalence for more complex things, like sets.

\end{frame}

\begin{frame}
  \frametitle{Relation Properties: Graphical Review}

  {\larger

    \begin{columns}
      \column{0.5\textwidth}
      \begin{center}
      Reflexive:\\
      \begin{tikzpicture}[scale=1,auto,swap]
        \tikzset{edge/.style = {->,>=latex'}}
        \node[vertex] (a) at (0,0) {};
        \node[vertex] (b) at (1,0) {};
        \node[vertex] (c) at (0,1) {};
        \draw[edge] (a) to[loop] (a);
        \draw[edge] (b) to[loop](b);
        \draw[edge] (c) to[loop] (c);
        \draw[edge] (c) to (b);
      \end{tikzpicture}

      \bigskip

      Transitive:\\
      \begin{tikzpicture}[scale=1,auto,swap]
        \tikzset{edge/.style = {->,>=latex'}}
        \node[vertex] (a) at (0,0) {};
        \node[vertex] (b) at (1,0) {};
        \node[vertex] (c) at (2,0) {};
        \draw[edge] (a) to (b);
        \draw[edge] (b) to (c);
        \draw[dotted] (a) to[bend right] (c);
      \end{tikzpicture}
      \end{center}
      \column{0.5\textwidth}
      \begin{center}
      Assymetric:\\
      \begin{tikzpicture}[scale=1,auto,swap]
        \tikzset{edge/.style = {->,>=latex'}}
        \node[vertex] (a) at (0,0) {};
        \node[vertex] (b) at (1,1) {};
        \node[vertex] (c) at (2,0) {};
        \draw[edge] (a) to (b);
        \draw[edge] (b) to (c);
        \draw[edge] (a) to (c);
      \end{tikzpicture}

      \bigskip

      Symetric:\\
      \begin{tikzpicture}[scale=1,auto,swap]
        \tikzset{edge/.style = {->,>=latex'}}
        \node[vertex] (a) at (0,0) {};
        \node[vertex] (b) at (1,0) {};
        \node[vertex] (c) at (2,0) {};
        \draw[edge] (a) to[bend left] (b);
        \draw[edge] (b) to[bend left] (a);
        \draw[edge] (b) to[bend left] (c);
        \draw[edge] (c) to[bend left] (b);
      \end{tikzpicture}

      \end{center}
    \end{columns}
  }
\end{frame}

% TODO: Remember why this is important and re-introduce it!
% \begin{frame}
%   \frametitle{Representing Equivalence}
%   {\larger
%
%     \begin{itemize}
%     \item For a total function $f:A\rightarrow B$
%     \item We can define an equivalence relation: $\equiv_f$ on $A$:
%       \begin{equation}
%         a \equiv_f a' \iff f(a) = f(a')
%       \end{equation}
%
%       \bigskip
%
%     \item {\bf Theorem:} Relation $R$ on set $A$ is an equiv. relation
%       {\bf iff}: $R$ is $\equiv_f$ for some $f:A\rightarrow B$
%
%       \bigskip
%
%     \item {\bf Example:} $\equiv$ (mod n) is $\equiv_f$
%       \structure{where} $f(k) ::= \text{rem}(k,n)$
%     \end{itemize}
%   }
% \end{frame}
%
% \begin{frame}
%   \frametitle{Equivalence and Partition}
%
%   {\larger
%     \begin{itemize}
%     \item We define a \structure{partition} $\Pi$ of a set $A$, where
%       $\$Pi$ is a collection of subsets of $A$ that cover all elements
%       but do not overlap.
%
%       \bigskip
%
%       {\bf Example:} For A = $\{a,b,c,d,e\}$ one partition could be:
%       $\{a,b\},\{c,e\},\{d\}$
%
%
%       \bigskip
%
%     \item We define a relatin $\equiv_{\Pi}$ on A: $a \equiv_{\Pi} a'$
%       if both $a$ and $a'$ are in the same subset of $\Pi$
%
%       \bigskip
%
%     \item A relation $R$ on set $A$ is an equivalence relation {\bf
%       iff} $R$ is $\equiv_{\Pi}$ for some partition $\Pi$ of $A$.
%     \end{itemize}
%
%   }
% \end{frame}