\chapter{Differential Geometry}
As we have noted before, general relativity is a inherent local theory. It is
convenient to formulate it in terms of differential geometry.
\section{Manifolds}
\begin{definition}
A $n$ dimensional manifold $M$ is a Hausdorff space with countable basis, that
is locally homeomorphic to $\mathbb{R}^n$.
\end{definition}
%TODO picture
We will give a short introduction to
the most important terms.
\begin{remark}
The requirements Hausdorff and countable basis are of a more technical nature and are satisfied for most of the objects one can imagine
except some pathological examples (we won't go into the details on this).

Locally homeomorphic to $\mathbb{R}^n$ means there exists a set of \emph{charts}
$(\varphi,U^\varphi)$ called an \emph{atlas} $\mathcal{A}$ with $\cup_{\varphi\in\mathcal{A}} U^\varphi =M$,
i.e. the charts cover the whole manifold. The maps $\varphi:U^\varphi\to \varphi(U^\varphi)\subset\mathbb{R}^n $ are homeomorphisms,
meaning that $U^\varphi$ is open, $\varphi$ is onto and both $\varphi$ and
$\varphi^{-1}$ are continuous.
Further for any two $\varphi,\psi\in \mathcal{A}$, the coordinate changes
$\varphi\circ\psi^{-1}:\psi(U^\psi\cup U^\varphi)\to \phi(U^\psi\cup U^\varphi)$
be smooth\footnotemark .
\end{remark}
\begin{figure}[hbtp!]
\centering
 \includegraphics{coordinateenvironment.pdf}
\caption{Coordinate change}
%TODO Caption
\end{figure}

\footnotetext{Infinitely often differentiable or short $C^\infty$.}
We can now reduce differentiation on the manifold to the ordinary differentiation in $\mathbb{R}^n$.
Since physical laws are described in terms of differential equations, we can formulate them on $M$.
The fact that the coordinate changes are smooth ensures that differentiability
is well defined (and thus the physical laws are).

\begin{sidenote}[Differential Structures]
There can be different \emph{differential structures} on a manifold,
which means there are multiple (maximal)alases, which
could not be merged because the coordinate changes would not be $C^\infty$. Those differentiable structures therefore imply different notions of differentiability.
Remarkably this may even play a role in some physical theories.
As an example an 11d-supergravity can be described as a product
$\Reals^{3+1}\times \Sphere^7$.
Where $\Sphere^7$ is the seven-sphere and $\Reals^{3+1}$ Minkovski space.
This means on every point in the $\mathbb{R}^{3+1}$ there is a (small) $\Sphere^7$  located that contains additional spatial dimensions.
The $\Sphere^7$ has 28 different differential structures, so the choice of
such a structure affects the theory for the above reasons.
\end{sidenote}
All simple examples we come of can be embedded in a higher space. The
\name{Whitney} embedding theorem states that every real $n$-dimensional Manifold
can be embedded to $\Reals^{2n}$ (This is however not true for complex, i.e. analytic manifolds).
For example the $\Sphere^2$ can be interpreted as submanifold of the
$\Reals^3$.
However manifolds are objects that exists independent of such embeddings.
For example a torus can be thought of as a square with the opposite sides identified (leaving to the left results in re-entering in the left).
\begin{sidenote}[Topology of the Universe]
In addition to the local structure, we may question the global, i.e. the
topological structure of the universe.
On may for example imagine that we live on the surface of a three-sphere (finite
but boundless universe).
However this might be observable in cross-corelation in the cosmic microwave
background from photons reaching us from different directions but coming from the same event. There is no evidence of such phenomena so far.
Most models can be excluded to some certainty. A cylindrical
universe is still possible (finite in one, infinite in the
other directions).
\end{sidenote}
\section{Vectors}
Vectors are important objects describing physics. The naive view as an 'arrow
pointing frow one point to another' is flawed.
For example on a sphere an arrow connecting two points does not make much sense.
We want to find a description of vectors as objects that are naturally related to the structure of the manifold independent of the embedding.
\subsection{Definitions}
There are three equivalent definitions for a
(contravariant) vector:
\begin{enumerate}
    \item algebraic
    \item physical
    \item geometrical.
\end{enumerate}
We start by giving the algebraic definition which is the most
abstract and preferred by mathematicians, because it is suitable for proofs.
Vectors are identified with derivatives, which are formally defined by
\begin{definition}[Derivation]
A derivation $D$ satisfies the following rules, for all $f,g\in
C^\infty(M,\Reals)$ and $\lambda \in \Reals$:
\begin{align}
    D(af+bg) &=Df+Dg\,,\\
    D(\lambda f)&=\lambda f\,,\\
    D(fg)&= (Df)g+f(Dg)\,.
\end{align}
\end{definition}
We then define a vector by
\begin{definition}[Vector,
algebraic] A vector in $p$ is a derivation on the germ at $p$.
\end{definition}
The germ is the set of all functions $f\in C^\infty(M,\Reals)$, where we
identify all functions that are equal in some neighbourhood of $p$, i.e. vectors are local objects.
Given two vectors we can construct a new one, the \emph{Lie bracket}
\begin{equation}
    [X,Y]f:=X(Yf)-Y(Xf)\, .\label{eq:LieBraket}
\end{equation}
The only property that has to be checked is that it satisfies the Leibniz rule.
\begin{equation}
    XY(fg)=X[(Yf)g+f(Yg)]=(XYf)g+(Yf)(Xg)+(Yg)(Xf)+(XYg)f\\
\end{equation}
Subtracting $YX(fg)$ proves that $[X,Y]$ is indeed a vector. The fact that we
have a natural vector space structure on the set of vectors at $p$ motivates the
following
\begin{definition}
The tangent space $T_pM$ is the space of all vectors in $p\in M$.
\end{definition}
A basis of $T_pM$ is given by the derivation along the
coordinates $\partial_i$, therefore its dimension is equal to that of the manifold $M$.
Proof sketch:
\begin{enumerate}
    \item Show $f(x^i)=f(0)+x^i\tilde{f}(x^i)$
    \item Write $X=a^i\partial_i$
    \item Show $Xf=0\quad \forall f \iff X=0$
\end{enumerate}
Every vector $A$ can be written as $A=A^i\pd{}{{x^i}}$, where $A^i$ are the
components of the vector. We can now look how the components of the vector
transform under a change of coordinates \footnote{The vector itself is
invariant!}.
We usually denote the elements of the transformed systems with a bar.
By the chain rule we have
\begin{equation}
    A= a^k\pd{}{{x^k}}= a^k\pd{\overline{x}^i}{{x^k}}\pd{}{{\overline{x}^k}}\, .
\end{equation}
We can also express $A$ directly in the new basis
\begin{equation}
    A= \overline{a}^i\pd{}{{\overline{x}^i}}\, .
\end{equation}
Comparing the coefficients gives the vector transformation law
\begin{equation}
    \overline{a}^i=a^k\pd{\overline{x}^i}{{x^k}}\label{eq:coefftrafo}\, .
\end{equation}
\begin{definition}[Vector,
physical] A vector with components $A^i$ is a object that transforms according
to \ref{eq:coefftrafo} under a change of coordinates.
\end{definition}
Consider a curve on a Manifold $M$, i.e. a
map $\gamma:\mathbb{R}\to M$, with $\gamma(0)=p$, $\dot{\gamma}(0)=X$. Then $D_X f=\od{}{t}(f\circ\gamma)(0)$ is
a derivative, namely the directional derivative along $X$.
Consider the special curves $\gamma_i(t)=\varphi(p+te_i)$, with $\varphi$ a
chart of $M$. Then $D_{\dot{\gamma}_i} f=\partial_if$,  so $D_{\dot{\gamma}_i}$
represents a the directional derivative and we can relate derivatives to the
geometrical tangent space.

Since we have a basis, we can work in (local) coordinates and will do so most of
the time.
\begin{example}[Lie brackets in local coordinates]
Let $A=A^i\partial_i$, $B=B^i\partial_i$ be vectors, then the \name{Lie} bracket
\eqref{eq:LieBraket} in local coordinates is given as
\begin{equation}
    [A,B]^j=A^i\partial_iB^j-B^i\partial_iA^i\, .
\end{equation}
\end{example}
Since the tangent space is a vector space, we can define its dual space
\begin{definition}[Cotangent space] The cotangent space $T_pM^*$ is the set of
linear maps from $T_pM$ to $\mathbb{R}$, i.e.
\begin{equation}
    T_pM^*:=\{L:T_pM\to \mathbb{R}\, |\, L \text{ linear}\}\, .
\end{equation}
\end{definition}
The cotangent space is again a vector space of the same dimension. Its elements
are called \emph{dual} or \emph{covariant} vectors.
We can define a basis on $	T_pM^*$, which we denote by $\dif x^i$ and  which acts on $T_pM$ via
\begin{equation}
    \dif x^i(\partial_j)=\delta^i_j\, . \label{eq:orthdual}
\end{equation}
It can easily deduced by \eqref{eq:orthdual} that the components of a dual vector transform as
\begin{equation}
    \overline{a}_i=\pd{x^k}{{\overline{x}^i}}a_k\, .
\end{equation}
\begin{remark}[Dual vectors in euclidean space]
If $\vec{a},\vec{b}\in\mathbb{R}^n$ contain the components of a vector and a
dual vector respectively, then the transformation can be written in matrix form
\begin{align}
    \vec{a}&\to\overline{\vec{a}}= V\vec{a}\, ,\\
    \vec{b}&\to\overline{\vec{b}}=\left(V\transpose\right)^{-1}\vec{b}\, ,
\end{align}
with $V_{ij}=\dpd{\overline{x}^i}{{x^j}}$ the
Jacobian of the transformation.
In normal calculus we restrict ourselves to orthogonal transformations (i.e.
mapping orthonormal bases onto each other) for which
$\left(O\transpose\right)^{-1}=O$.
Which is the reason why we do not bother to distinguish between vectors and dual vectors because they transform identically.
In special relativity we have e.g.
$\left(\Lambda\transpose\right)^{-1}\neq\Lambda$ for a boost and the difference
becomes even more important in general relativity where the relation can become arbitrarily complicated.
\end{remark}
\section{Tensors}
From vectors $A$ ,$B$ we can construct new objects with multiple indices that posses well defined transformation behaviour.
For example consider
\begin{equation}
    \overline{T}^{ij}=a^ib^j\, ,
\end{equation}
which transforms as
\begin{equation}
    T^{ij}=\pd{\overline{x}^i}{{x^k}}\pd{\overline{x}^j}{{x^l}}a^kb^l=\pd{\overline{x}^i}{{x^k}}\pd{\overline{x}^j}{{x^l}}T^{kl}\,
   .\label{eq:tensortrafo}
\end{equation}
We call an object that transforms in this way a \emph{tensor}.
As with vectors, it is possible to define tensors in a coordinate independent
way.
At this point we will make things easier and only consider the physical
definition, i.e. classify tensors by a transformation according to \eqref{eq:tensortrafo}.

A tensor is said to be symmetric in two indices if it stays invariant when exchanging those indices, e.g.
\begin{equation}
    T_{ab}=T_{ba}\, .
\end{equation}
\begin{remark}
We have not yet established a relation between upper and lower indices, i.e. we have no metric. Expressions of the form
\begin{equation}
    \tensor{T}{^a_b}=\tensor{T}{^b_a}
\end{equation}
therefore make no sense.
\end{remark}
\section{The Metric}
So far we have not defined a length scale on manifolds yet. We will do so now by
introducing a \emph{metric}
\begin{definition}[Metric]
A metric $g$ on a manifold $M$, is a non-degenerate ($\det(g)\neq 0$), symmetric
covariant two tensor.
\end{definition}
We have already seen examples of metrics for the flat space, e.g. in spherical coordinates $g$ was given as
\begin{equation}
    g=
    \begin{bmatrix}
        1 & 0\\
        0 & r^2\\
    \end{bmatrix}\,.
\end{equation}
A metric that is positive definite is called \emph{\name{Riemann}ian metric}. In
relativity we deal with \emph{\name{Lorentz}ian metrics}, for which there are
vectors beside the zero vector which have zero 'length'. In flat space we have
$\tensor{g}{_i_j}=\tensor{\eta}{_i_j}$.
A metric gives two natural notions on the tangent space of the manifold.
Inner product
\begin{equation}
g(A,B)=\tensor{g}{_i_j}\tensor{A}{^i}\tensor{B}{^j}
\end{equation}
Pseudo\footnote{Not positive definite.} norm
\begin{equation}
g(A,A)=\tensor{g}{_i_j}\tensor{A}{^i}\tensor{A}{^j}
\end{equation}
\begin{remark}[About
raising and lowering indices] Suppose we have given a vector $A=A^i\partial_i$
with coordinates $A^i$, then we can relate it
in a natural way to a linear form $A^\flat\footnote{The symbols
$\flat$ and $\sharp$ are borrowed from musical notation.}:=g(A,\cdot)$,
\begin{equation}
\begin{split}
 A^\flat\,\colon T_pM &\to \Reals\\
 X &\mapsto g(A,X)\, ,
\end{split}
\end{equation}
i.e. a dual vector. The components of this dual vector are given by its action
on the basis elements of the tangent space
\begin{equation}
A_i:=(A^\flat)_i=g(A,\partial_i)=A^jg(\partial_j,\partial_i)=g_{ji}A^j\,,
\end{equation}
which is exactly the law for lowering indices. Given the inverse metric we can
multiply this equation by it to obtain $A^i$ in terms of $A_i$.
\end{remark}
\section{Affine Connections}
To derive a vector field, we have to relate different tangent spaces. The idea
is again to generalize from flat space. The connection is established by
introducing a affine connection.
\subsection{Parallel Transport}
We consider a the parallel transport of a
vector.
%TODO pictures
If we express a vector in non-Cartesian coordinates and shift it it's
coordinates do not change.
We take a look on two operations:
\begin{enumerate}
\item the change of the vector itself
\item the change of its coordinates.
\end{enumerate}
Let $A_i$ be the coordinates of a vector in a system $x^i$ and $B_i$ in a
system associated with coordinates $y^i$ respectively. They are therefore
related by
\begin{equation}
A_i=\dpd{{y^j}}{{x^i}}B_j\, ,\quad B_i=\pd{{x^j}}{{y^i}}A_j\, .
\end{equation}
We look at vectors whose coordinates in the system $y^i$ do not change i.e.\
$\delta B_i=0$. The variation of $A_i$ is given by
\begin{equation}
\delta
A_i=\delta\left(\dpd{{y^j}}{{x^i}}\right)B_j
=\md{{y^j}}{2}{{x^i}}{}{{x^k}}{}\delta
x^k B_j\, .
\end{equation}
Expressing $B_i$ in terms of $A_i$ yields
\begin{equation}
\delta A_i = \md{{y^j}}{2}{{x^i}}{}{{x^k}}{}\pd{{x^l}}{{y^j}}A_l\delta x^k
=:\affin{l}{i}{k}A_l\delta x^k
\end{equation}
$\affin{l}{i}{k}$ is called \emph{affine connection} or short affinity.
\begin{remark}
We can always find a coordinate system in which $\affin{l}{i}{k}\equiv 0$, this
system is called \emph{\name{Riemann}ian normal coordinate system} (RNCS).
\end{remark}
%TODO construction i.e. geodesic coordinates
We notice that if
\begin{equation}
\left(\dpd{{A_i}}{{x^j}}-\affin{l}{i}{k}A_l\right)\delta x^k = 0\,
,\label{eq:covdev}
\end{equation}
The vector $A$ does not change its coordinates. We define a \emph{covariant
derivative}
\begin{equation}
\tensor{A}{_i_;_j}:=\tensor{\nabla}{_j}\tensor{A}{_i}:=\pd{{A_i}}{{x^j}}-\affin{l}{i}{k}A_l\,
.
\end{equation}
It can easily be seen that the covariant derivative of a tensor transforms as a
tensor, by inspecting \eqref{eq:covdev} and applying the quotient theorem.
\begin{remark}[The
Covariant Derivative in Electrodynamics] Example from Electrodynamics concerning the covariant derivative.
The theory is invariant under transformations $\phi\to e^{\imI \alpha}\phi$,
because $\phi^*\phi$ and $\phi^*\nabla\phi-\phi\nabla\phi^*$ do not change.
In order to make the Lagrangian gauge invariant we exchange
\begin{equation}
\tensor{\partial}{_\mu}\to\tensor{D}{_\mu}+\imI\tensor{A}{_\mu}\, ,
\end{equation}
which effectively produces additional terms in the Lagrangian, namely
\begin{equation}
\tensor{A}{^\mu}\left(\phi^*\tensor{\partial}{_\mu}\phi
-\phi\tensor{\partial}{_\mu}\phi^*\right)=\tensor{A}{^\mu}\tensor{J}{_\mu}\,,
\quad\tensor{A}{_\mu}\tensor{A}{^\mu}\phi^2\,.
\end{equation}
The commutator between the covariant derivatives calculates to
\begin{equation}
\left[\tensor{D}{_\mu},\tensor{D}{_\nu}\right]=\imI \tensor{F}{_\mu_\nu}\,.
\end{equation}
So the noncommutativity is associated with the presence of a field. This is
similar to GR where it was related with curvature.
\end{remark}
Since we have now established a relation between vectors and dual vectors, we
can also determine the covariant derivative of a dual vector. Therefore we
consider the scalar $A_iB^i$. Since the covariant derivative satisfies the
Leibniz rule we get
\begin{align}
\tensor{(A_iB^i)}{_{;j}} =
\tensor{A}{_i_;_j}\tensor{B}{^i}+\tensor{A}{_i}\tensor{B}{^i_;_j}\,.
\end{align}
But for scalars the covariant derivative is identical to the normal derivative
so that
\begin{align}
(A_iB^i)_{;j} =(A_iB^i)_{,j}=
\tensor{A}{_i_,_j}\tensor{B}{^i}+\tensor{A}{_i}\tensor{B}{^i_,_j}
\end{align}
If we put in the covariant derivative of a we get
\begin{equation}
\tensor{A}{_i}\tensor{B}{^i_;_j}=\tensor{A}{_i}\left(\tensor{B}{^i_{,j}}+\Gamma^i_{kj}\tensor{B}{^k}\right)
\end{equation}
Since $A$ was arbitrary, we can deduce that
\begin{equation}
\tensor{B}{^i_;_j}=\left(\tensor{B}{^i_{,j}}+\Gamma^i_{kj}\tensor{B}{^k}\right)
\end{equation}
for a (1,1)-tensor we get:
\begin{equation}
\tensor{A}{^i_j_;_k}=\tensor{A}{^i_j_{,k}}-\Gamma^a_{jk}\tensor{A}{^i_a}+\Gamma^i_{ak}\tensor{A}{^a_j}\,
.\end{equation}
Similar expressions hold for tensors of arbitrary rank, where each index gives
an additional term containing a contraction with the affinity $\Gamma^i_{jk}$.
We now want to consider curved spaces. This can not immediately be determined by
the metric, for example the polar coordinates do not look flat even though they
describe the ordinary $\Reals^2$.
\subsection{Geodesics}
A curve is a map $\gamma:\Reals\to M$. The parametrisation is arbitrary e.g.
\begin{equation}
\begin{split}
\gamma:\, &\Reals\to \Reals^2\\
& t\mapsto
\frac{1}{2} t^2
\begin{bmatrix}
1 \\
1
\end{bmatrix}\, ,
\end{split}
\end{equation}
clearly describes a straight line with $y=x$.
However, we notice that $\od{\tensor{\gamma}{^i}}{t}$ is parallel to
$\od[2]{\tensor{\gamma}{^i}}{t}$. This gives rise to another possible
generalisation of a straight line.
In curved coordinates we have
\begin{equation}
\nabla \left( \dod{\tensor{x}{^j}}{t} \right)  =
\od[2]{\tensor{x}{^i}}{t}+\affin{i}{j}{k}\od{\tensor{x}{^j}}{t}\od{\tensor{x}{^k}}{t}
=\lambda(t)\od{\tensor{x}{^j}}{t}\,.
\end{equation}
Suppose we have a different parametrisation $s(t)$
\begin{equation}
\od{\tensor{x}{^i}}{t}=\od{\tensor{x}{^i}}{s}\od{s}{t}\,,\quad
\od[2]{\tensor{x}{^i}}{t}=\od[2]{\tensor{x}{^i}}{s}\left(\dod{s}{t}\right)^2
+\od{\tensor{x}{^i}}{s}\dod[2]{s}{t}\, ,
\end{equation}
then the equation for a straight line reads as
\begin{equation}
\left(\dod[2]{\tensor{x}{^i}}{s}+\affin{i}{j}{k}\dod{\tensor{x}{^j}}{s}\dod{\tensor{x}{^k}}{s}
\right)\left(\dod{s}{t}\right)^2+\dod[2]{s}{t}\dod{\tensor{x}{^i}}{s}
=\lambda(t)\dod{\tensor{x}{^j}}{t}\dod{s}{t}\,.
\end{equation}
To get to the usual form of the geodesic equation we choose $s$ so that
\begin{equation}
\dod[2]{s}{t}=\lambda(t)\dod{s}{t}\label{eq:bedaffpara}
\end{equation}
Which is an ordinary differential equation of type $\ddot{s}=\lambda\dot{s}$
that should posses a solution.
For this special choice of parametrisation we have
\begin{equation}
\dod[2]{\tensor{x}{^i}}{s}+\affin{i}{j}{k}\dod{\tensor{x}{^j}}{s}\od{\tensor{x}{^k}}{s}
=0\,.\label{eq:affingeod}
\end{equation}
We therefore have a preferred set of parameters
called affine parameters that satisfy \eqref{eq:bedaffpara}. The character
of the differential equation implies that the affine parameter is only
defined modulo affine transformations $s\to as+b$. This freedom once more
reflects some kind of gauge invariance.
\begin{remark}
Only the symmetric part of the affinity does contribute to
the geodesic equation \eqref{eq:affingeod}. As long as you are on a geodesic you
can always compare lengths without needing a metric, by the affine parameter.
The 'length' defined this way does not have to concede with the length given by
the metric and is also defined for example for lightlike curves (which cannot
be parametrised by the arc length).
\end{remark}
If we demand that the two definitions of a geodesic \eqref{eq:affingeod} is
identical to \eqref{eq:geodeq} coincide, we get a preferred
connection.
This corresponds to the choice $\affin{k}{i}{j}=\cSym{k}{i}{j}$.
This is called the \emph{metric}, \emph{Levi-Civita} or \emph{Christoffel
connection}, and we will always choose it in the following.
A general metric compatible
connection\footnote{$\tensor{\nabla}{_k}\tensor{g}{_i_j}=0$} satisfies
\begin{equation}
\affin{k}{i}{j}=\cSym{k}{i}{j}+\tensor{T}{^k_i_j}
+\tensor{g}{^i^r}\left(\tensor{T}{^s_j_r}\tensor{g}{_s_i}+\tensor{T}{^s_i_r}\tensor{g}{_s_j}\right)\,,
\end{equation}
with the torsion tensor
\begin{equation}
\tensor{T}{^k_i_j}=\frac{1}{2}\left(\affin{k}{i}{j}-\affin{k}{j}{i}\right)\,.
\end{equation}
Therefore the Christoffel connection is the unique metric compatible
symmetric connection.
\begin{remark}
Non-Christoffel connections play a role, for example when dealing with spinors.
\end{remark}
\begin{figure}[hbtp!]
\centering
 \includegraphics{fold1.pdf}\qquad\qquad
 \includegraphics{fold2.pdf}\qquad\qquad
 \includegraphics{fold3.pdf}
\caption{The geodesics on a cylinder can be obtained by ``folding'' flat space.}
\end{figure}
%TODO pictures
\section{The Riemannian Curvature Tensor}
%TODO Missing definition of R
We can contract indices on the Riemann Tensor
\begin{equation}
\tensor{R}{^i_i_k_l}=\pd{{\Gamma^i_{il}}}{{x^k}}-\pd{{\Gamma^i_{ik}}}{{x^l}}\,,
\end{equation}
which is zero for a metric affinity. The Ricci tensor is given by
\begin{equation}
\tensor{R}{_j_k}=\tensor{R}{^i_j_k_i}\, .
\end{equation}
Because of the symmetry this are all independent
contractions.
Notice that at this point we cannot raise or lower indices to contract different indices.
Given a metric the curvature or Ricci skalar is defined as
\begin{equation}
\tensor{R}{^i_i}=\tensor{g}{^i^j}\tensor{R}{_j_i}\, .
\end{equation}
%TODO here we assume we have not metric..
Since we can express the \name{Riemann} tensor in terms of commutators there is
a also a symmetry that can be derived from the Jacobi identity:
\begin{equation}
\left[A\left[B,C\right]\right]
+\left[C\left[A,B\right]\right]
+\left[B\left[C,A\right]\right]=0\,.
\end{equation}
Physics can be described in terms of differential equations. We for example
would like to have a object similar to the Laplacian in curved coordinates.
However $\partial_i\partial_i$ is not coordinate invariant. We therefore
introduce a metric. The equivalence principle implies that space is locally
Minkovski.
\begin{sidenote}
There are certain theories that can be formulated without a metric. An example
being three dimensional gravity, which is non-dynamic.
\end{sidenote}
Since the connection and the metric are not related, we still don't have a length
scale on the manifold
% \begin{equation}
% \tensor{R}{_i_j_k_l}:=\tensor{g}{_i_a}\tensor{R}{^a_j_k_l}
% \end{equation}
% Only useful if $R$ and $g$ are related i.e. metric connection.
% (Bilder)
% TODO the following is fits better into parallel transport section, we can
% possibly leave out what is written there

\subsection{Symmetries of the Riemann Tensor}
\begin{equation}
\tensor{R}{^i_j_k_l}=-\tensor{R}{^i_j_l_k}\,.
\end{equation}
Bianci identities for the Riemann tensor
\begin{equation}
\tensor{R}{^i_j_k_l_{;m}}+\tensor{R}{^i_j_m_k_{;l}}+\tensor{R}{^i_j_l_m_{;k}}=0
\end{equation}
Proof: If we would write it all out we wold have to write 22 terms. Instead we
use a RNCS so that the Riemann tensor simplifies to
\begin{equation}
\tensor{R}{^i_j_k_l}
=\tensor{\partial}{_k}\affin{i}{j}{l}
-\tensor{\partial}{_l}\affin{i}{j}{k}
\end{equation}
And with $\tensor{\nabla}{_k}=\tensor{\partial}{_k}$ we get
\begin{equation}
\tensor{R}{^i_j_k_l_{;m}}
=\tensor{\partial}{_m}\tensor{R}{^i_j_k_l}
=\tensor{\partial}{_k}\tensor{\partial}{_m}\affin{i}{j}{l}
-\tensor{\partial}{_l}\tensor{\partial}{_m}\affin{i}{j}{k}\,.
\end{equation}
Plugging in gives the result in the RNCS system, but since the equation is
tensorial, it holds in all systems. Notice the similarity to
\begin{equation}
\tensor{\partial}{_m}\tensor{F}{_a_b}
=\tensor{\partial}{_b}\tensor{\partial}{_m}\tensor{A}{^a}
-\tensor{\partial}{_a}\tensor{\partial}{_m}\tensor{A}{^b}
\end{equation}
Therefore the second set of Maxwell's
equations \eqref{eq:maxwell_eqs} is in fact a the Bianchi identity.
If the affinity is symmetrical $\affin{k}{i}{j}=\affin{k}{j}{i}$ we further have
the identity
\begin{equation}
\tensor{R}{^i_j_k_l}+\tensor{R}{^i_l_j_k}+\tensor{R}{^i_k_l_j}=0
\end{equation}
Given a metric $\tensor{g}{_i_j}$, we can raise and lower
indices
\begin{equation}
\begin{split}
\tensor{R}{_i_j_k_l}
&=\tensor{g}{_i_a}\tensor{R}{^a_j_k_l}\\
&=\tensor{g}{_i_a}\left(\tensor{\partial}{_k}\affin{i}{j}{l}
-\tensor{\partial}{_l}\affin{i}{j}{k}\right)\\
&=\tensor{g}{_i_a}\left(\tensor{\partial}{_k}\tensor{g}{^a^s}\csym{j}{l}{s}
-\tensor{\partial}{_l}\tensor{g}{^a^s}\csym{j}{k}{s}\right)\\
&=\tensor{\partial}{_k}\csym{j}{l}{i}
-\tensor{\partial}{_l}\csym{j}{k}{i}\\
&=\frac{1}{2}\left(
\dmd{{\tensor{g}{_i_l}}}{2}{\tensor{x}{^j}}{}{\tensor{x}{^k}}{}
+\dmd{{\tensor{g}{_j_k}}}{2}{\tensor{x}{^i}}{}{\tensor{x}{^l}}{}
-\dmd{{\tensor{g}{_i_k}}}{2}{\tensor{x}{^j}}{}{\tensor{x}{^l}}{}
-\dmd{{\tensor{g}{_j_l}}}{2}{\tensor{x}{^i}}{}{\tensor{x}{^j}}{}\right)
\end{split}
\end{equation}
Immediately we can extract symmetries
\begin{align}
\tensor{R}{_i_j_k_l}&=-\tensor{R}{_j_i_k_l}\\
\tensor{R}{_i_j_k_l}&=-\tensor{R}{_i_j_l_k}
\end{align}
If we further introduce multi-indices $A=(i,j)$, $B=(k,l)$ (by antisymmetry
there are six independent components for $A,B$ each)
\begin{equation}
\tensor{R}{_A_B} = \tensor{R}{_B_A}
\end{equation}
So $R$ can be thought as a $6\times 6$ matrix.
\begin{table}
    \centering
        \caption{Number of independent components of Riemann
    and \name{Ricci} tensor.\label{tab:Nindcomp}}
    \begin{tabulars}{rrr}
      	\toprule
		dimension&Riemann tensor &Ricci tensor \\
		\midrule
		1&0&0\\
		2&1&1\\
		3&6&6\\
		4&20&10\\
		$n$&$\frac{1}{12}n^2(n^2-1)$&$\frac{1}{2}n(n+1)$\\
		\bottomrule
    \end{tabulars}
\end{table}
Table~\ref{tab:Nindcomp} lists the number of independent components of the
curvature tensor and the \name{Ricci} tensor in various dimensions. Thereby a
one dimensional space is always flat, a two dimensional is characterised by the
curvature scalar $R$ alone and in three dimensions the Ricci tensor is
sufficient to know the Riemann tensor. Therefore four is the lowest dimension in
which the Riemann tensor contains additional information of the curvature of
space.


\Lecture{Jayalal Sharma}{Sept 19, 2020}{07}{From Bijections to PIE}{Anshu Yadav}{$\alpha$}{JS}

\section{Introduction}
In this lecture, we will continue with the use of bijections and use it in formally proving the two identities that we discussed in class and then see their relationship to the Principal of Inclusion and Exclusion.

\section{The Identities}
Recall that we proved following two identities in one of the discussion sessions
\begin{align}
     \sum_{k=0}^n (-1)^k{n\choose k} &= 0 \label{REV1}\\
     \sum_{k=0}^m (-1)^k{n\choose k} &= (-1)^m{n-1\choose m} \label{REV2}
\end{align}
In this section, we will see the proofs for the above equations is detail
\subsection{Proof for Eqn. \eqref{REV1}} \label{subsec:identity-even-odd-1}
$$\sum_{k=0}^n (-1)^k{n\choose k} = 0$$
\begin{proof}
    The LHS counts the number of even sized subsets of $[n]$ with positive sign and odd size subsets with negative sign. Then we proved the result using bijection between even sized and odd sized subsets of $[n]$. Hence, we get 0 on RHS. Let us formally define the bijection here.

    Let $E$ be the set of all even sized subsets of $[n]$ and $O$ be the set of all odd sized subsets of $[n]$. Then the bijection  $\phi_i:E\rightarrow O$ is defined with respect to an element $i\in[n]$ as follows.

    Let $X\subseteq [n]$, such that $|X|$ is even. Then
    \[
        \phi_i(X) =
        \begin{cases}
            X\setminus \{i\} & ~~~~~\text{ if } i\in X\\
            X\cup\{i\} & ~~~~~\text{ if } i\not\in X
        \end{cases}
    \]
    \underline{Proof of bijection:}
    \begin{description}
        \item \textit{Well-defined:} Given any even sized subset $X$, there are two possibilities: (i) $i\in X$, (ii) $i\not\in X$. In first case, $i$ is removed from $X$, hence its size reduces by one and becomes odd. In the second case, $i$ is added, hence the size of the subset increases by one and becomes odd. Hence, $\phi$ is well defined.
        \item \textit{Injective:} Let $X$ and $X'$ be two distinct subsets of $[n]$. Then $\exists j\in[n]$ such that $j$ is present in exactly one of the two subsets. Wlog, let $j\in X$ and $j\not\in X'$. Now, if $j\neq i$, then $j\in \phi(X)$ and $j\not\in \phi(X')$ and hence $\phi(X)\neq \phi(X')$. On the other hand, if $j=i$, then $j\not\in \phi(X)$ and $j\in \phi(X')$. Hence, $\phi(X)\neq \phi(X')$.
        \item \textit{Surjective:} Let $Y\in O$ be an odd sized subset of $[n]$. From $Y$, we can recover $X$ such that $\phi(X) = Y$ by the same operation as in $\phi$. That is,
        \[
        X= \begin{cases}
            Y\setminus \{i\} & ~~~~~\text{ if } i\in Y\\
            Y\cup\{i\} & ~~~~~\text{ if } i\not\in Y
        \end{cases}
        \]
        It can easily be verified that in both the cases, $X$ is an even sized subset of $[n]$.
    \end{description}
    This completes the proof.
\end{proof}
%
%
\subsection{Proof for Eqn. \eqref{REV2}} \label{subsec:identity-even-odd-2}
$$\sum_{k=0}^m (-1)^k{n\choose k} = {n-1\choose m}$$
\begin{proof}
Now we look at the second identity which is even more interesting. To prove this identity we use \emph{almost bijection} where the bijection is between a set and subset of another set.

In words, the identity to prove, can be described as
$$\Large\substack{\# \textrm{ of even sized subsets of  $[n]$}\\  \textrm{of size atmost $m$}} - \substack{\# \textrm{ of odd sized subsets of $[n]$} \\ \textrm{of size atmost $m$}} = (-1)^m{n-1\choose m}.$$ Clearly, there cannot be a bijection between the two sets (even sized subsets and odd sized subsets) in this case, since their difference is non-zero. This is where we use almost bijection.

We use following case analysis.
\begin{description}
\item \underline{\textbf{Case1:} $m$ is even:} Then the identity to prove is:
\begin{equation} \label{eq:even-odd}
    \sum_{k=0}^m (-1)^k{n\choose k} = {n-1\choose m}
\end{equation}
This can be interpreted as
\begin{equation} \label{eq:even-odd-1}
    \sum_{\substack{k=0,\\k\text{ is even}}}^m {n\choose k} -  \sum_{\substack{k=1,\\k\text{ is odd}}}^{m-1} {n\choose k} = {n-1\choose m}
\end{equation}
Let $E$ be the set of all the even sized subsets of $[n]$ of size at most $m$ and $O$ be the set of odd sized subsets of $[n]$ having size at most $m-1$. Then, Eqn.~\eqref{eq:even-odd-1} can intuitively interpreted as follows: there is a subset $E'\subseteq E$, such that $E'$ is in bijection with $O$ and $|E\setminus E'| = {n-1\choose m}$. Thus, we have three tasks at hand
\begin{itemize}
    \item identify the set $E'$, and
    \item define and prove the bijection between $E'$ and $O$.
    \item prove that $|E\setminus E'| = {n-1\choose m}$
\end{itemize}
\underline{Defining the set $E'$:} Set $E'$ is the union of two sets:
$$E' = \{X\subseteq [n]: |X| \textrm{ is even and } |X|\le m-2\}\cup\{X\subseteq [n]: i\in X \textrm{ and } |X| = m\}$$
\underline{Defining the bijection:} The bijection $\phi:E'\rightarrow B$ is defined in the same way as we defined it for first identity. That is, for $X\in E'$,
\[
\phi(X) =
\begin{cases}
X\setminus \{i\} & ~~~~~\text{ if } i\in X\\
X\cup\{i\} & ~~~~~\text{ if } i\not\in X
\end{cases}
\]
\underline{Proof of bijection}
\begin{description}
\item \textit{Well-defined:} Let $X\in E'$, then (i) if $|X|\le m-2$, then $|\phi(X)|$ is odd and $|\phi(X)|\le m-1$, (ii) if $|X| = m$, then $i\in X$, hence $\phi(X) = X\setminus \{i\}$. This implies $|\phi(X)| = m-1$. Thus, in both the cases $\phi(X)\in O$.
\item \textit{Injective:} Since, the function is same as in the previous case, the same argument for injectivity works.
\item \textit{Surjective:} Let $Y\in O$ be an odd sized subset of $[n]$. From $Y$, we can recover $X\in E'$ such that $\phi(X) = Y$ by the same operation as in $\phi$. That is,
 \[
 X=
 \begin{cases}
Y\setminus \{i\} & ~~~~~\text{ if } i\in Y\\
Y\cup\{i\} & ~~~~~\text{ if } i\not\in Y
 \end{cases}
 \]
 It can easily be verified that in both the cases, $|X|$ is even.
 In first case, since $|Y|\le m-1, |X|\le m-2$, hence $X\in E'$. In second case, since $i\not\in Y$ and $|Y|\le m-1$, $|X|\le m$ and $i\in X$. Hence $X\in E'$, by definition.
\end{description}
This proves the bijection between $E'$ and $O$.

\underline{Proof for: $|E\setminus E'| = {n-1\choose m}$}

From the above definitions, $E\setminus E' = \{X\subseteq [n]: |X| = m, i\not\in X\}$. This can be interpreted as $E\setminus E' = \{X\subseteq [n]\setminus \{i\}: |X| = m\}$. Hence, $|E\setminus E'| = {n-1\choose m}$.

\item \underline{\textbf{Case2:} $m$ is odd:} In this case the identity to prove is:
\begin{equation}
\label{eq:even-odd-3}
    \sum_{k=0}^m (-1)^k{n\choose k} = - {n-1\choose m}
\end{equation}
This can be interpreted as
\begin{equation}
\label{eq:even-odd-2}
    \sum_{\substack{k=0,\\k\text{ is even}}}^{m-1} {n\choose k} -  \sum_{\substack{k=1,\\k\text{ is odd}}}^{m} {n\choose k} = -{n-1\choose m}
\end{equation}
Equivalently,
\begin{equation}
\label{eq:odd-even-1}
    \sum_{\substack{k=1,\\k\text{ is odd}}}^{m} {n\choose k} - \sum_{\substack{k=0,\\k\text{ is even}}}^{m-1} {n\choose k}  = {n-1\choose m}
\end{equation}
This time the set of odd sized subsets of $[n]$ of size at most $m$ is bigger than the even sized subsets of $[n]$ of size at most $m$.
The proof is same as that for the case of even $m$.
Let $E$ be the set of all the even sized subsets of $[n]$ of size at most $m-1$ (since $m$ is odd) and $O$ be the set of odd sized subsets of $[n]$ having size at most $m$. Then~\eqref{eq:odd-even-1} can be interpreted as follows: there is a subset $O'\subseteq O$, such that $E$ is in bijection with $O'$ and $|O\setminus O'| = {n-1\choose m}$.

Thus, we have two task at hand
\begin{itemize}
    \item identify the set $O'$, and
    \item define and prove the bijection between $E$ and $O'$.
    \item prove that $|O\setminus O'| = {n-1\choose m}$
\end{itemize}
\underline{Defining the set $O'$:} Set $O'$ to be the union of two sets:
$$O' = \{Y\subseteq [n]: |Y| \text{ is odd and } |Y|\le m-2\}\cup\{Y\subseteq [n]: i\in Y \text{ and } |Y| = m\}$$
\underline{Defining the bijection:} The bijection $\phi:E\rightarrow O'$ is defined in the same way as we defined it for first identity. That is, for $X\in E$,
\[
\phi(X) =
\begin{cases}
X\setminus \{i\} & ~~~~~\text{ if } i\in X\\
X\cup\{i\} & ~~~~~\text{ if } i\not\in X
\end{cases}
\]
\underline{Proof of bijection}
\begin{description}
\item \textit{Well-defined:} Let $X\in E$, then $\phi(X)$ is of odd size because either an element is added or removed from $X$, which is of even size. Now, (i) if $i\in X$, then $\phi(X) = X\setminus\{i\}$. Hence, $|\phi(X)|\le m-2$ (because $|X|\le m-1$) which implies $\phi(X)\in O'$ (ii) if $i\not\in X$, then, $\phi(X) = X\cup \{i\}$. This implies $|\phi(X)| \le m$. But since, $i\in \phi(X)$, $\phi(X)\in O'$. This proves that $\phi$ is well- defined.
\item \textit{Injective:} Since, the function is same as in sub section~\ref{subsec:identity-even-odd-1}, the same argument for injectivity works.
\item \textit{Surjective:} Let $Y\in O'$ be an odd sized subset of $[n]$. From $Y$, we can recover $X\in E$ such that $\phi(X) = Y$ by the same operation as in $\phi$. That is,
 \[
 X=
 \begin{cases}
Y\setminus \{i\} & ~~~~~\text{ if } i\in Y\\
Y\cup\{i\} & ~~~~~\text{ if } i\not\in Y
 \end{cases}
 \]
 It can easily be verified that in both the cases, $|X|$ is even.
 In first case, $|Y|\le m$ and hence $|X|\le m-1$. So, $X\in E$. In second case, since $i\not\in Y$, $|Y|\le m-2$ (by definition) and hence $|X|\le m-1$. Hence $X\in E$.
\end{description}
This proves the bijection between $E$ and $O'$.

\underline{Proof for: $|O\setminus O'| = {n-1\choose m}$}\\
From the above definitions, $O\setminus O' = \{Y\subseteq [n]: |Y| = m, i\not\in Y\}$. This can be interpreted as $O\setminus O' = \{Y\subseteq [n]\setminus \{i\}: |Y| = m\}$. Hence, $|O\setminus O'| = {n-1\choose m}$.
\end{description}
This completes the proof
\end{proof}
This proves both the identities.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Principle of Inclusion and Exclusion}
Suppose we are given $n$ sets $A_1, A_2, \ldots, A_n\subseteq G$, where $G$ is some ground set. We are interested in finding the size of $A= A_1\cup A_2\cup\ldots\cup A_n$. This is very abstract scenario and we will see specific examples later, but here we are going to see classic use of the above identities in deriving this number.

So, we are interested in finding $|A| = |A_1\cup A_2\cup\ldots\cup A_n|$.

So, here is a thought process -
Clearly, we can add the size of individual sets as
$|A| = |A_1|+|A_2|+\ldots +|A_n|$, but this will over-count if there are some elements present in more than one sets. So, for that we need to subtract the double counting. For e.g. if $x\in A_1$ and $x\in A_2$, then it gets counted twice and to compensate for that we need to subtract $|A|=|A_1\cap A_2|$ and we might attempt $|A| = |A_1|+|A_2|+\ldots +|A_n| - \sum_{1\le i < j\le n}|A_i\cap A_j|$. But then, if $x$ is present in $A_1, A_2$ and $A_3$, the it is under-counted (added thrice and subtracted thrice). So, again we need to compensate for that by adding $\sum_{1\le i \le j\le k\le n}|A_i\cap A_j\cap A_k|$ in the above expression and this sequence goes on for any element being present in $k\le n$ sets and finally we get the expression for $|A|$  as follows
\begin{equation} \label{eq:pie-1}
    |A| = |A_1|+\cdots+|A_n|-\sum_{1\le i< j\le n}|A_i\cap A_j| +\sum_{1\le i<j<k}|A_i\cap A_j\cap A_k| -\cdots + (-1)^{n+1}|A_1\cap A_2\cap\cdots\cap A_n|
\end{equation}
For $n=2$, the above expression gives
$$|A| = |A_1|+|A_2|-|A_1\cap A_2|$$
which we all must have seen before and can easily prove using Venn diagram.

In this section, we will formally prove the above expression for general $n$ using the two identities we proved in previous section.
\begin{proof}
Consider any $x\in A_1\cup A_2\cup\cdots\cup A_n$. Let $x$ appears in $k$ of the $A_i$'s. Then let us see how $x$ gets counted
\begin{itemize}
    \item[-] $|A_1|+|A_2|+\cdots +|A_n|$: counts $x$ $k$ times (added)
    \item[-] $\sum_{1\le i<j\le n}|A_i\cap A_j|$: counts $x$ ${k\choose 2}$ times (subtracted)
    \item[-] $\sum_{1\le i<j<k\le n}|A_i\cap A_j\cap A_k|$: counts $x$ ${k\choose 3}$ times (added)
    \item[-] and so on $\ldots$
\end{itemize}
Notice that in terms involving intersection of more than $k$ sets, $x$ never appears.

Thus,
\begin{eqnarray*}
{\Large\substack{\# \text{of times $x$}\\ \text{gets counted}}} &=& k+{k\choose 2}-{k\choose 3}+\cdots +(-1)^{k+1}{k\choose k}\\
&=&-{k\choose 0}+{k\choose 1}+{k\choose 2}-{k\choose 3}+\cdots +(-1)^{k+1}{k\choose k}+{k\choose 0}\\
&=&-\sum_{i=0}^k(-1)^{i}{k\choose i}+{k\choose 0}\\
%&&\text{from~\eqref{eq:identity-1}, $\sum_{i=0}^k(-1)^k{k\choose i} = 0$}\\
&=&{k\choose 0} ~~~~~~~~~~~~~~~~~~~~~~~\text{from ~\eqref{REV1}}\\
&=& 1
\end{eqnarray*}
Thus, irrespective of the value of $k$, any element $x\in A_1\cup A_2\cup\cdots\cup A_n$ is counted exactly once. Hence, every $x\in A_1\cup A_2\cup\cdots\cup A_n$ is counted exactly once in RHS in~\eqref{eq:pie-1}.

This proves the PIE
\end{proof}
Now let us look at the application of second identity that we derived. This identity is used in deriving a version of PIE which appears very naturally in several context. Let us look at one such example.

PIE says that if we want to derive $|A_1\cup\A_2\cup\cdots\cup A_n|$, then the following expression does not give the correct count.
$$|A_1\cup\A_2\cup\cdots\cup A_n| = |A_1|+|\A_2|+\cdots+|A_n|$$
But we can ask, does this expression gives a lower or an upper bound? As we saw, this does over-counting, hence we can write
$$|A_1\cup\A_2\cup\cdots\cup A_n| \le |A_1|+|\A_2|+\cdots+|A_n|$$
Now, suppose we include the next component, i.e. $$|A_1|+|\A_2|+\cdots+|A_n|-\sum_{1\le i<j\le n}|A_i\cap A_j|$$
Again from PIE we know that this also does not give the correct count. But we ask the same question again - does it give any lower or upper bound. And as we saw that this term can do some over-subtraction and hence we can say that this expression gives the lower bound. That is,
$$|A_1\cup\A_2\cup\cdots\cup A_n| \ge |A_1|+|\A_2|+\cdots+|A_n|-\sum_{1\le i<j\le n}|A_i\cap A_j|$$
Similarly,
$$|A_1\cup\A_2\cup\cdots\cup A_n| \le |A_1|+|\A_2|+\cdots+|A_n|-\sum_{1\le i<j\le n}|A_i\cap A_j|+\sum_{1\le i<j<k\le n}|A_i\cap A_j\cap A_k|$$
and we continue like this.

Let us now formally establish this observation. We use the same technique that we used in the proof of PIE.

Let $x$ appears in $k$ of the sets in $A_1, A_2, \ldots, A_n$. Suppose we cut off the PIE after $m\le n$ sized intersections. Then
\begin{eqnarray*}
{\Large\substack{\# \text{of times $x$}\\ \text{gets counted}}} &=& {k\choose 1}-{k\choose 2}+\cdots+(-1)^{m+1}{k\choose m}\\
%&=&-{k\choose 0}+{k\choose 1}+{k\choose 2}-{k\choose 3}+\cdots +(-1)^{k+1}{k\choose k}+{k\choose 0}\\
&=&-\sum_{i=0}^m(-1)^{i}{k\choose i}+{k\choose 0}\\
%&&\text{from~\eqref{eq:identity-1}, $\sum_{i=0}^k(-1)^k{k\choose i} = 0$}\\
&=& 1+(-1)^{m+1}{k-1\choose m} ~~~~~~~~~~~~~~~~~~~~~~~\text{from ~\eqref{REV2}}
\end{eqnarray*}
Thus, $x$ is over counted or under counted depending on whether the second term on RHS is positive or negative. Let us analyze this for two cases.
\begin{description}
\item Case1: $k\le m$

Since, $x$ appears in only $k\le m$ sets and we are cutting down only after $m$, then this means that all possible intersections of this particular $x$ are added and subtracted and $x$ can not appear in any of the intersections of more than $k$ sets. Hence, $x$ is neither under counted nor over counted. In the expression, ${k-1\choose m} = 0$ Hence,
$$\# \text{of times $x$ is counted } = 1$$
\item Case2: $k>m$

In this case, $x$ can be under counted or over counted depending upon whether $m$ is even or odd.
If $m$ is odd then $x$ is over counted.

If $m$ is even then $x$ is under counted.
\end{description}
Notice that either all $x\in A_1\cup\A_2\cup\cdots\cup A_n$ are correctly counted or under counted or all $x$ are correctly counted or over counted based on the parity of $m$. Thus, whether a PIE cut down after $m$ intersections gives lower bound or upper bound depends only on the parity of $m$. This principle is also called the \emph{Bon Ferroni's inequality}.
\begin{remark}
    We used the equality in~\eqref{eq:even-odd} to prove PIE. We can actually do the other way round as well, i.e. we can use PIE to prove this equality too.
\end{remark}
This completes this lecture. In the next lecture we will look at some applications of PIE.


\documentclass[12pt]{article}

\title{CSC 420 - Assignment 3}
\author{Robert Krency, kre1188@calu.edu \\}
\date{\today}

\usepackage{tikz}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{listings}

% Geometry
\usepackage{geometry}
\geometry{letterpaper, left=20mm, top=20mm, right=20mm, bottom=20mm}

% Add vertical spacing to tables
\renewcommand{\arraystretch}{1.4}

% Macros
\newcommand{\definition}[1]{\underline{\textbf{#1}}}

\newenvironment{rcases}
  {\left.\begin{aligned}}
  {\end{aligned}\right\rbrace}

% Begin Document
\begin{document}

\maketitle

\section{Question 1}

The Magic 3x3 Square is a 3x3 grid of the digits 1 to 9. Each grid cell has a unique number, and when arranged in a certain order,
the sum of each row, column, and diagonal will each be 15.

Consider the following square, with letters marking each grid tile, and a possible solution:

\begin{center}

\begin{tabular}{c c}

\begin{tabular}{| c | c | c |}
    \hline
    A & B & C \\ \hline
    D & E & F \\ \hline
    G & H & I \\ \hline
\end{tabular}

&

\begin{tabular}{| c | c | c |}
    \hline
    6 & 1 & 8 \\ \hline
    7 & 5 & 3 \\ \hline
    2 & 9 & 4 \\ \hline
\end{tabular}

\end{tabular}
\end{center}

This problem can be formulated as a Constraint Satisfaction Problem, with the following properties:

\begin{itemize}
    \item Variables: $X$ = \{ A, B, C, D, E, F, G, H, I \}
    \item Domains: $X_i$ = \{ 1, 2, 3, 4, 5, 6, 7, 8, 9 \}
    \item Constraints: $C$ = \{
    \begin{itemize}
        \item AllDifferent\{ A, B, C, D, E, F, G, H, I \},
        \item A + B + C = 15,
        \item D + E + F = 15,
        \item G + H + I = 15,
        \item A + D + G = 15,
        \item B + E + H = 15,
        \item C + F + I = 15,
        \item A + E + I = 15,
        \item C + E + G = 15 \}
    \end{itemize}
\end{itemize}

\pagebreak

\section{Question 2}

The attached MiniZinc script produces the following output:

\begin{lstlisting}
    Running Magic15Square.mzn
    847msec

    4 9 2
    3 5 7
    8 1 6
    ----------
    Finished in 847msec.
\end{lstlisting}

\end{document}


\documentclass{article}
\title{Distributions and copulas in GOSM}
\author{Ma\"{e}l Forcier}
\date{April 2017}

\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{relsize}
\usepackage{dsfont}
\usepackage[all]{xy}
\usepackage{float}
\usepackage{color}
\usepackage{comment}
\newcommand{\mf}[1]{\textcolor{red}{$\textrm{Mael: }${#1}}}
\newcommand{\code}[2]{\texttt{#1}}

\begin{document}
   \maketitle
   \section{Introduction}

	We present a python library to use distribution with copulas.

	We want to model the random properties of a data. In this section we will take the example of the production of wind power that we want to model by a gaussian.

	Today we do not know what wind production there would be tomorrow., so we model this wind production by a random variable $X$ that has a lot of properties.

	\section{Mathematical Definitions}
	\newtheorem{definition}{Definition}
	\newtheorem{property}{Property}
	\begin{definition}
	The cumulative density function (cdf) of a random variable $X \in \mathbb{R}$ is the function $F : \mathbb{R} \to [0,1]$ where :
	\begin{equation*}
	F(x) = \mathbb{P}(X\leq x)
	\end{equation*}
	\end{definition}

	This definition also works when X is a multidimensional random	variable i.e. $\in \mathbb{R}^d$ if we use the notation $(x_1,...,x_d) \leq (y_1,...,y_d) \Leftrightarrow \forall i, x_i \leq y_i$

	\begin{definition}
	If the cdf of $X \in \mathbb{R}$ is differentiable, the probability density function (pdf) of X is the function $f : \mathbb{R} \to [0,1]$ where :
	\begin{equation*}
	f(x) = \frac{dF(x)}{dx} = \frac{d\mathbb{P}(X\leq x)}{dx}
	\end{equation*}
	If $X \in \mathbb{R}^d$ and F is regular enough, the probability density function pdf of X is the function $f : \mathbb{R} \to [0,1]$ :
	\begin{equation*}
	f(x) = \frac{d^d F(x)}{dx_1...dx_d}
	\end{equation*}
	\end{definition}

	Each one of these two functions gives all the informations about how the random variable X behaves. With them, we can compute different charasteristic values of the distribution.

	\begin{definition}
	The mean of a random variable $X \in \mathbb{R}^d$ is :
	\begin{equation*}
	\mathbb{E}(X) = \int_{\mathbb{R}^d} xf(x)dx
	\end{equation*}
	\end{definition}

	\begin{definition}
	The variance of a random variable $X \in \mathbb{R}^d$ is :
	\begin{equation*}
	Var(X) = \mathbb{E}((X-\mathbb{E}(X))^2) = \int_{\mathbb{R}^d} (x-\mathbb{E}(X))^2f(x)dx
	\end{equation*}
	\end{definition}

	\begin{property}
	If $X \in \mathbb{R}$ is a random variable with a continuous cdf F,
	\begin{equation*}
	\text{then } U = F(X) \text{ is a uniform random variable in [0,1]}
	\end{equation*}
	\end{property}

	\section{Distribution user manual}

	To model the random properties of data (for example the production of wind power or wind forecast errors). We define distribution as a python object that contains several methods. NB : This distribution python object does not correspond strictly to the mathematical definition of a distribution because it contains several different methods that describe many things linked to the probability law of the variable. To simplify, when we will talk about distribution, it will refer to this distribution python object.

	\begin{figure}[H]
\[
   	\xymatrix{
   		 & \boxed{input\_data} \ar[dd]_{\_\_init\_\_} & \\
   		 & & \\
   		 & \boxed{parameters} \ar[ldd]_{generates\_X} \ar[rdd]^{calculus} & \\
   		 & & \\
   		\boxed{sample} \ar@/_/[rr]_{counting} & & \boxed{functions} \ar@/_/[ll]_{CDF^{-1}(Uniform\text{ }variable)}
   	}
   \]
   \caption{Simplified diagram of how a distribution object  works}
	\end{figure}

	\subsection{Methods and parameters of a distribution object}
	\subsubsection{cdf, pdf and other functions}
	The methods cdf and pdf compute the two chararacteristic functions defined above. If the object \texttt{distrobject}  represents a random variable X with cdf F and pdf f, \texttt{distrobject.cdf(x)} will return the value of $F(x)$ and \texttt{distrobject.pdf(x)} will return the value of $f(x)$. Most of the time, this value are calculated using analytical formulas.

	For example, the pdf of a normal distribution is calculated using the formula
	\begin{equation*}
	f(x) = \frac{1}{\sqrt{2\pi}}exp(\frac{(x-\mu)^2}{2\sigma^2})
	\end{equation*}

	To make others calculus and depending on the class of the object, one might need other functions linked to the cdf and the pdf. For example, the method \texttt{cdf\_inverse}  will compute the inverse of the cdf. \texttt{distrobject.cdf\_inverse(x)} will return the value $F^{-1}(x)$.

	\subsubsection{mean, var and other parameters}
	One can see that these formulas depend on parameters. In the previous normal case, they are $\mu$ and $\sigma$. \newline

	Althought the mean and the variance can be interesting values that we calculate using the cdf or the pdf. They also can be considered as parameters. In the normal case, $\mu$ is also the mean and $\sigma^2$ the variance. If the object \texttt{distrobject} represents a random variable X, \texttt{distrobject.mean} will return the value of $\mathbb{E}(x)$ and \texttt{distrobject.var} will return the value of $Var(x)$. \newline

	 Depending on the class of the object, it could have other parameters that would be explained in detail while presenting the different classes. For instance, we can quote the degree of freedom (\texttt{df}) for student distributions, the covariance matrix (\texttt{cov}) for multivariate distribution or the theta parameters (\texttt{theta}) for archimedian copulas.

	\subsubsection{Initializing Distributions}

	The method \_\_init\_\_ creates a new object of a distribution class. It will be called with the specific parameters fo the distribution. For instance, $distrobject = UnivariateNormalDistribution(mean=mu,var=sigma**2)$ will return an Normal distribution object with the parameters \texttt{mu} for the mean and \texttt{sigma**2} for the variance.
	But, in practice, it is very useful to fit a distribution to a data set.
	This can be done by calling the \texttt{fit} method of any distribution class with the fit method.
	This method will estimate the parameters for the distribution from the
	input data. For instance, \texttt{UnivariateNormalDistribution.fit(data = Y)} will return a normal distribution with the
	mean and variance fit to the data (in this case, these parameters are
	just taken to be the sample mean and sample variance of the data).

	\subsubsection{\texttt{generates\_X} and sample}

	A distribution object modelizing a random variable X also has a method that can generates realisations of X following the probability law.

	For instance, in the normal case we call the numpy function \texttt{numpy.random.randn} with the good parameters to generates such variables. In the case of univariate distribution it can also be obtained by generating a uniform variable in [0,1] and composing by the inverse of the cdf. $F^{-1}(U)$, where U is uniformly distributed on [0,1], follows the same probability law as X.

	Because sometimes generating a lot of variables can be long, they are stored automatically in \texttt{distrobject.X}. Then,  \texttt{distrobject.generates\_X(n)} returns a vector of n independent realisations of X and store them in the attribute \texttt{mydistrobject.X} by appending this n new values by appending it to the old attribute.

	 \subsection{Files and classes}

	 In order to make comparisons and find the best distribution model for a variable, I implemented several different distributions. Even if they follow the same global pattern described above, their parameters, their functions and the way they are implemented can be very different because of a need to speed up the computation or simply because the mathetical object are really different. All the distributions are coded with classes that one can find in a certain file. I explain in this section how the files are organized and how the classes work. At the beginning of each file's subsection, one can see the whole list of the class it contains.

	 \subsubsection{base\_distribution.py}
	 This file contains various abstract classes that define interfaces and common functions for distributions :\newline
	 \newline
	 \texttt{BaseDistribution} \newline
	 \texttt{UnivariateDistribution} \newline
	 \texttt{MultivariateDistribution} \newline

	 \texttt{BaseDistribution} is the base class from which all the distributions classes will inherit. This class describes at a minimum, what all distributions must have.
	 For our purposes, we expect all distributions to define a \texttt{pdf} method and a \texttt{fit} method.\newline

	 \texttt{UnivariateDistribution} inherits from \texttt{BaseDistribution}. It serves as the base class for all univariate distributions.
	 This exports basic methods for computing the cdf, the inverse cdf, and the expectation over a specific region.

	 \texttt{MultivariateDistribution} inherits from \texttt{BaseDistribution}. It is the abstract class from which all the distributions with more than one variable will inherit. The particularity of multivariate distribution is that it works with dictionnaries. This permits not to confuse the different coordinates of the distribution. To this end, any distribution can be constructed or fit by passing by the keyword \texttt{dimkeys} a list of strings which will serve as names for the dimensions. Then one can call a function which expects a vector as input (say the pdf) with the a dictionary mapping dimension names to the values. This abstract class also contains the method \texttt{rect\_prob} that computes the probability for the random variable to be in a n dimension rectangle defined by two opposed points \texttt{lowerdict} and \texttt{upperdict}. Even thaugh this calculus requires a non trivial recursion, it only needs the cdf to be computed and it is the same calculus for all multivariate distribution.

	 \subsubsection{distributions.py}

	 This file contains all the concrete classes of the classical distributions that are not built with copulas. If they are called Univariate, they directly inherit from \texttt{BaseDistribution}, if they are called Multi they inherit form \texttt{MultivariateDistribution} : \newline
\newline
	 \texttt{UnivariateBasicEmpiricalDistribution} \newline
	 \texttt{UnivariateEmpiricalDistribution} \newline
	 \texttt{UnivariateEpiSplineDistribution} \newline
	 \texttt{UnivariateUniformDistribution} \newline
	 \texttt{UnivariateNormalDistribution} \newline
	 \texttt{UnivariateStudentDistribution} \newline
	 \texttt{MultiNormalDistribution} \newline
	 \texttt{MultiStudentDistribution} \newline

	 \texttt{UnivariateBasicEmpiricalDistribution} is the simplest distribution you can build without making an hypothesis on the model. It assumes that all the results in the \texttt{input\_data} are the only possible ones and that they are equiprobable. This gives us a method to generate a sample, we simply pick randomly one element of \texttt{input\_data}. If we note $Y = (Y_1,...,Y_n) = \texttt{input\_data}$, the functions would be :
	\begin{equation*}
  	F(x) = \frac{1}{n}\sum_{k=1}^n \mathds{1}_{Y_k\leq x}
  	\end{equation*}
  	\begin{equation*}
  	\mathbb{P}(X=x) = \frac{1}{n}\sum_{k=1}^n \mathds{1}_{Y_k = x}
  	\end{equation*}
  	One can notice that F is not continuous, that implies that f is not well defined. \newline

	 \texttt{UnivariateEmpiricalDistribution} works almost like \texttt{UnivariateBasicEmpirical} but avoids the problem of continuity by cleverly interpolating lines between the points we have. When the set of data is big enough it gives the same result than \texttt{UnivariateBasicEmpricalDistribution}. \newline

	 \texttt{UnivariateEpiSplineDistribution} is a more clever object obtained thanks to the resolution of an optimization problem where the cdf as a particular shape : \newline
	 \begin{equation*}
  	F(x) = e^{-g(x)}\text{, where }g\text{ is a piecewise defined polynomial}
  	\end{equation*}
  	 For example, one can choose the number N which indicates how much subsegments we want to divide our initial segment to create each piece of the polynomial function. Plus, this class needs the installation of the language pyomo and of the solver ipopt. To learn more about these installation, check \texttt{GOSM} user manual. This class is unusual because it was extracted from an earlier version of software called \texttt{Prescient}.\newline

	 \texttt{UnivariateUniformDistribution} contains only two parameters called \texttt{a} and \texttt{b} who represent respectively the minimum and the maximum of the distribution. When an object of this class is called with \texttt{input\_data}, the \texttt{\_\_init\_\_} method, assign the minimum of \texttt{input\_data} to $a$ and its maximum to $b$.
	 \begin{equation*}
	 a = \texttt{a} = \texttt{min(input\_data)}
	 \end{equation*}
	 \begin{equation*}
	 b = \texttt{b}= \texttt{max(input\_data)}
	 \end{equation*}
	 \[
   		f(x) =
   		\begin{cases}

    	\frac{1}{b-a} & \quad \text{if } x \in [a,b]\\
    	0  & \quad \text{else}\\
  \end{cases}
  \]
	 \[
   		F(x) =
   		\begin{cases}
        0  & \quad \text{if } x \leq a \\
    	1 & \quad \text{if } x \geq b \\
    	\frac{x-a}{b-a} & \quad \text{else}
  \end{cases}
  \]

  \texttt{UnivariateNormalDistribution} has two parameters \texttt{mean} and \texttt{var} which are stored as attributes. We present below the main formulas that define this class. Each time we represent parameters with their names in the python code and with its usual mathematical notation so that the formulas are not too hard to read.
  	\begin{equation*}
  	\mu = \texttt{mean} =  \texttt{mean(input\_data})
  	\end{equation*}
  	\begin{equation*}
  	\sigma^2 = \texttt{var} = \texttt{var(input\_data})
  	\end{equation*}
  	\begin{equation*}
  	f(x) = \frac{1}{\sqrt{2\pi \sigma^2}}e^{-\frac{(x-\mu)^2}{\sigma^2}}
  	\end{equation*}
  	\begin{equation*}
  	F(x) = \int_{-\infty}^x \frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{(y-\mu)^2}{\sigma^2}}dy
  	\end{equation*}

  	\texttt{UnivariateStudentDistribution}

  	\begin{equation*}
  	\mu = \texttt{mean} = \texttt{mean(input\_data)}
  	\end{equation*}
  	\begin{equation*}
  	\nu = \texttt{df} = \texttt{2var(input\_data)/(var(input\_data)-1)}
  	\end{equation*}
  	\begin{equation*}
  	f(x) = \frac{1}{\sqrt{\nu\pi}}\frac{\Gamma(\frac{\nu+1}{2})}{\Gamma(\frac{\nu}{2})}\left(1+\frac{(x-\mu)^2}{\nu}\right)^{-\frac{\nu+1}{2}}
  	\end{equation*}
  	\begin{equation*}
  	F(x) = \int_{-\infty}^x \frac{1}{\sqrt{\nu\pi}}\frac{\Gamma(\frac{\nu+1}{2})}{\Gamma(\frac{\nu}{2})}\left(1+\frac{(y-\mu)^2}{\nu}\right)^{-\frac{\nu+1}{2}}dy
  	\end{equation*}

	 \texttt{MultiNormalDistribution}

  	\begin{equation*}
  	\mu = \texttt{mean} = \texttt{mean(input\_data)}
  	\end{equation*}
  	\begin{equation*}
  	K = \texttt{cov} = \texttt{cov(input\_data)}
  	\end{equation*}
  	\begin{equation*}
  	f(x) = \frac{1}{(2\pi)^{\frac{d}{2}}\sqrt{det(K)}}e^{-\frac{(x-\mu)^\top K^{-1} (x-\mu)x}{2}}
  	\end{equation*}
  	\begin{equation*}
  	F(x) = \int_{-\infty}^x \frac{1}{(2\pi)^{\frac{d}{2}}\sqrt{det(K)}}e^{-\frac{(y-\mu)^\top K^{-1} (y-\mu)}{2}}dy
  	\end{equation*}

  	\texttt{MultiStudentDistribution}

  	\begin{equation*}
  	\mu = \texttt{mean} = \texttt{mean(input\_data)}
  	\end{equation*}
  	\begin{equation*}
  	\nu = \texttt{df}
  	\end{equation*}
  	\begin{equation*}
  	K = \texttt{cov} = \texttt{cov(input\_data)}
  	\end{equation*}
  	\begin{equation*}
  	f(x) = \frac{\Gamma (\frac{\nu +d}{2})}{\Gamma
	 (\frac{\nu}{2})(\nu \pi)^{\frac{d}{2}}\sqrt{det(K)}}\left(1+\frac{1}{\nu}(x-\mu)^\top K^{-1} (x-\mu) \right)^{-\frac{\nu +d}{2}}
  	\end{equation*}
  	\begin{equation*}
  	F(x) = \int_{-\infty}^x \frac{1}{\sqrt{\nu\pi}}\frac{\Gamma(\frac{\nu+1}{2})}{\Gamma(\frac{\nu}{2})}\left(1+\frac{(y-\mu)^2}{\nu}\right)^{-\frac{\nu+1}{2}}dy
  	\end{equation*}

	 \subsubsection{copula.py}
	 This file contains the abstract class \texttt{CopulaBase} which inherits from \texttt{MultivariateDistribution} and from which all the concrete copula classes inherit. The mathematical details of copulas are explained in the next sections. As was the case with our distribution objects and classes in python, our copula objects and classes in python are different from the strict mathematical definition of a copula which is just what we call a C function. The inheritance from \texttt{MultivariateDistribution} is very convenient in our applications, but is non-standard for copula classes.\newline
\newline
	 \texttt{CopulaBase} \newline
	 \texttt{GaussianCopula} \newline
	 \texttt{StudentCopula} \newline
	 \texttt{FrankCopula} \newline
	 \texttt{ClaytonCopula} \newline
	 \texttt{GumbelCopula} \newline
	 \texttt{WeigthedCombinedCopula} \newline
	 \texttt{IndependenceCopula} \newline
	 \texttt{EmpiricalCopula} \newline

	 \texttt{CopulaBase} is the abstract class that contains the attributes and methods that all the copula classes have in common. The method is to use what we presented as property 1 on each diagonal. Instead of working on the dependence between $X_1$, $X_2$ ... and $X_n$, we prefer to focus on the dependence between $U_1=F_1(X_1)$, $U_2=F_2(X_2)$ ... and $U_n=F_n(X_n)$. It is now much easier to compare the dependence between coordonates that all have the same distribution which is uniform in [0,1]. We work in what we call the U-space, $[0,1]^d$, as opposed to the X-space, $\mathbb{R}^d$. One can easily pass from one to the other by composing coordonate by coordonate with the $F_i$ or by using the formulas presented in the next sections. Like all the children of \texttt{MultivariateDistribution} a copula object has methods and attributes in the X-space, but it contains also its twins in the U-space, just like if a copula object contained the distribution of X and the distribution of U. Considering this analogy, C (as the cdf of U) plays in the U-space the role of cdf in the X-space. c (as the pdf of U) plays in the U-space the role of pdf in the X-space. Finally, generates\_U permits to return samples of U with the good dependence, it plays in the U-space the same role as generates\_X in the X-space.

	 \subsubsection{vine.py}
	 Vine copulas are copulas that are built using other bivariate copulas. I explain them with more details in the next section.\newline
	 \newline
	 \texttt{CVineCopula} \newline
	 \texttt{DVineCopula}

	\subsubsection{distribution\_factory.py}

	 In all the previous files, each definition of a new concrete class begins with \texttt{@register\_distribution(name="name-of-the-class")}. This permits to give string names to the class. The file distribution\_factory.py contains the code that allow us to write :\newline \texttt{distr\_class = distribution\_factory(copula\_string)}\newline
    \texttt{distr\_object = distr\_class(input)}\newline

     instead of\newline\texttt{if copula\_string =="univariate-uniform":}

    \texttt{distr\_object = UnivariateUniformDistribution(input)} \newline
    \texttt{if copula\_string =="univariate-normal":}

    \texttt{distr\_object = UnivariateNormalDistribution(input)} \newline etc, for all the cases. \newline

    This pratical way of selecting the classes is also used to build distributions that are created thanks to other ones such as combined copulas or vine copulas.

	 \subsubsection{tester.py}
	This file contains several unittests to check the distribution classes attempt. Some are just quick tests to check if the code runs. But most of them attempt to verify if the implemented formulas are correct. In order to do that,the method is trying to obtain the same result by different ways or by making a loop on diagram that should be commutative like the one in figure 1. For instance, \texttt{test\_pdf\_cdf} integrates the pdf to compare it to the cdf and differentiate the cdf to verify if it is equal to the pdf. \texttt{test\_c\_with\_C\_2\_dim} integrates twice \texttt{c} and verify if the value is equal to \texttt{C}. \texttt{test\_C\_with\_sample} checks the low loop of diagram in figure 1 in the U-space : with a big data set created by \texttt{generates\_U}, it creates an empirical cdf of U (called \texttt{C\_from\_sample}) and compares it to the actual cdf of U which is \texttt{C}. Another example is \texttt{test\_with\_gaussian\_copula\_3\_dim} which checks if making a distribution with normal (or gaussian) marginals and a gaussian copula give the same result than a creating directly a multinormal (or multigaussian) distribution. \newline
\newline
	 \texttt{MultiNormalDistributionTester} \newline
	 \texttt{UnivariateNormalDistributionTester} \newline
	 \texttt{MultiStudentDistributionTester} \newline
	 \texttt{UnivariateStudentDistributionTester}\newline
	 \texttt{CopulaTester} \newline
	 \texttt{VineCopulaTester}

   \section{Copulas properties}

	In order to study the dependance of several correlated random variables, we need to focus on a tool called copula. It is more practical to consider our different variables together as a multidimensional variable. The distribution univariate random variables are then called marginals. Copulas permit measurement of the dependance without caring about the marginals. In our object oriented program, it is really practical because one can work on the dependance with the copula while the marginals are just input variables. To introduce and define the copulas, let us quote Sklar's theorem :
	\newtheorem{Sklar}{Theorem}
	\begin{Sklar}
		Sklar, 1959. Let us consider a random vector $X = (X_{1},...,X_{d})$ with a 			cumulative distibution function $F(x_{1},...,x_{d})= \mathbb{P}(X_{1}\leq 	x_{1},..,X_{d}\leq x_{d}).$ \newline
	Then, exists a function C called copula $C : [0,1]^{d}\to [0,1]$ so that :
	\begin{equation*}
	F(x_{1},...x_{d})=C(F_{1}(x_{1}),...,F_{d}(x_{d}))
	\end{equation*}
	where $F_{i}$ is the cumulative density function of the ith marginal.\newline
	The copula C is unique if the marginals are continuous.
	\end{Sklar}

	We will also use the density of the copula :

	\begin{definition}
	The copula density of a copula C is the function $c : [0,1]^{d}\to \mathbb{R^+}$:\newline
	\begin{equation*}
	c(u,v) = \frac{\partial^d C}{\partial u_{1} ... \partial u_{d}} (u,v)
	\end{equation*}
	\newline
	By differentiating, we obtain the equation :
	\begin{equation*}
		f(x_1,...,x_d) = c(F_1(x_1),...,F_d(x_d))f_1(x_1)...f_d(x_d)
	\end{equation*}

	\end{definition}

	\begin{definition}
	The Kendall distribution function  $\mathcal{K}_F : [0,1]\to [0,1]$ of a distribution of cumulative density function F is : \newline
	\begin{equation*}
	\mathcal{K}_F (u) = \mathbb{P} (F(X) \leq u)
	\end{equation*}
	where X is a random variable following the distribution defined by F.
	\end{definition}

	\begin{multline*}
	\begin{split}
	\mathcal{K}_F (u)	&= \mathbb{P} (F(X) \leq u) \\
						&= \mathlarger{ \int_{\mathbb{R}^d} \mathds{1}_{F(x) \leq u}f(x) dx} \\
						&= \mathlarger{ \int_{\mathbb{R}^d} \mathds{1}_{C(F_1(x_1),...,F_d(x_d)) \leq u} c(F_1(x_1),...,F_d(x_d)) f_1(x_1)...f_d(x_d) dx} \\
						&= \mathlarger{ \int_{[0,1]^d} \mathds{1}_{C(y) \leq u} c(y) dy}\\
						&= \mathlarger{ \int_{K_u} c(y) dy} \text{	, where } K_u = \{ y\in [0,1]^d, C(y) \leq u \}\\
						&= \mathbb{P} (C(U) \leq u)
	\end{split}
	\end{multline*}
	Where U is a random variable on $[0,1]^d$ with cdf C (and uniform marginals).

	Intuitively, when we do the changing of variable $y_i=F_i(x_i)$ :\newline We have $dy_i = F_i^\prime (x_i) dx_i = f_i(x_i)dx_i$. So, indeed $dy = f_1(x_1)...f_d(x_d)dx$.\newline
	The meticulous proof with the Jacobian determinant gives the same result.
	\newline

	$\mathcal{K}_F$ only depends on the copula C of the distribution function.\newline
	Thus, we will use the notation $\mathcal{K}_C$. \newline
	If we write $\Gamma_{u_2,...,u_{d}}(x) = C(x,u_2,...,u_d)$, we also have :
	\begin{equation*}
	\mathcal{K}_C (u) = \mathlarger{ \int_0^1 ... \int_0^1 \bigg(\int_0^{\Gamma_{y_2,...,y_{d}}^{-1}(u)} c(y) dy_1 \bigg) dy_2...dy_d}
	\end{equation*}
	\newline

	We want to use Vine copulas to study multidimensional dependance. To compute such vine copulas, we need to have the partial derivative of C function and its inverse. For each of the following copulas in 2 dimensions, I calculated the partial derivate \begin{math} h(u,v,\theta) = \frac{\partial C_{\theta}}{\partial v} (u,v) \end{math}. I also calculated its inverse \begin{math} h^{-1} \end{math} considering its first variable : \begin{math} h(h^{-1}(u,v,\theta),v,\theta)=u \end{math}

	\begin{figure}
	\[
   	\xymatrix{
   		 & C \ar[ldd]_{\frac{\partial}{\partial u_{1}}} \ar[rdd]^{\frac{\partial^d}{\partial u_{1} ... \partial u_{d}}} & \\
   		 & & \\
   		\frac{\partial C}{\partial u_{1}} \ar@/_/[rr]_{\frac{\partial^{d-1}}{\partial u_{2} ... \partial u_{d}}} & & c \ar@/_/[ll]_{\int ... \int}
   	}
   \]
	\caption{Relations between copula functions}
	\end{figure}

   \section{Elliptic Copulas}
   Explain that they are copulas of multidimensional distributed vector with different law.
   Add the difference between correlation matrix and covariance matrix and say we only consider 1 on the diagonal.

	\subsection{Gaussian Copula}

	The gaussian copula of correlation matrix K is the copula of a gaussian vector \begin{math} \mathcal{N}(0,K) \end{math}.\newline
	\newline
	Because one can change the variance of each marginal, we will only consider covariance matrix where there are only 1 in the diagonal.
	\newline
	\newline
	We will note \begin{math} \mathcal{N}(x)=\frac{1}{\sqrt{2\pi}}\int_{-\infty}^{x} e^{-\frac{t^{2}}{2}}dt \end{math}, the cumulative density function of the standard normal distribution and \begin{math} \mathcal{N}^{-1} \end{math} its inverse.

	\subsubsection{C function in dimension n}

	\begin{math}
	 C_{K}(u_{1},...u_{d})= \mathlarger{ \int_{-\infty}^{\mathcal{N}^{-1}(u_{1})}...\int_{-\infty}^{\mathcal{N}^{-1}(u_{d})} \frac{1}{(2\pi)^{\frac{d}{2}}\sqrt{det(K)}}e^{-\frac{x^\top K^{-1} x}{2}}dx}
	\end{math}
	\newline
	\newline
	With a change of variable, we have also \newline
	\newline
	\begin{math}
	C_{K}(u_{1},...u_{d})=  \mathlarger{ \int_{0}^{u_{1}}...\int_{0}^{u_{d}} \frac{1}{\sqrt{det(K)}}e^{-\frac{\mathcal{N}^{-1}(x)^\top (K^{-1}-I_{d}) \mathcal{N}^{-1}(x)}{2}}dx}
	\end{math}
	\newline
	\newline
	\newline
	where \begin{math} \mathcal{N}^{-1}(x) =  \begin{pmatrix}
   \mathcal{N}^{-1}(x_{1}) \\
  \vdots   \\
   \mathcal{N}^{-1}(x_{d})
 \end{pmatrix}\end{math}

\subsubsection{C function in dimension 2}

 	In dimension 2, all matrix of correlation can be written \begin{math} K =
 \begin{pmatrix}
  1 & \rho \\
  \rho & 1
 \end{pmatrix}
\end{math}. So we will only consider one parameter \begin{math} \rho \end{math}.\newline
\newline

\begin{math}
	C_{\rho} (u,v) = \mathlarger{\int_{-\infty}^{\mathcal{N}^{-1}(u)}\int_{-\infty}^{\mathcal{N}^{-1}(v)} \frac{1}{2\pi\sqrt{1-\rho^{2}}}e^{-\frac{x^2-2\rho x y +y^{2}}{2(1-\rho^{2})} }dx dy}
\end{math}
\newline
\newline
With the same change of variable, we have also
\newline
\begin{math}
	C_{\rho} (u,v) = \mathlarger{\int_{0}^{u}\int_{0}^{v} \frac{1}{\sqrt{1-\rho^{2}}}e^{-\frac{\rho^{2}\mathcal{N}^{-1}(x)^2-2\rho\mathcal{N}^{-1}(x)\mathcal{N}^{-1}(y) + \rho^{2} \mathcal{N}^{-1}(y)^{2}}{2(1-\rho^{2})} }dx dy}
\end{math}

\subsubsection{Partial derivative of C}

If we derivate the second formula, we have \newline
\begin{math}
h(u,v,\rho)=\frac{\partial C_{\rho}}{\partial v} (u,v) = \mathlarger{\int_{0}^{u} \frac{1}{\sqrt{1-\rho^{2}}}e^{-\frac{\rho^{2}\mathcal{N}^{-1}(x)^2-2\rho\mathcal{N}^{-1}(x)\mathcal{N}^{-1}(v) + \rho^{2} \mathcal{N}^{-1}(v)^{2}}{2(1-\rho^{2})} }dx}
\end{math}
\newline
\newline
If we derivate the first formula above, we obtain \newline
\begin{math}
h(u,v,\rho)=\frac{\partial C_{\rho}}{\partial v} (u,v) = \mathlarger{\frac{1}{\mathcal{N}^{'}(\mathcal{N}^{-1}(v))}\int_{-\infty}^{\mathcal{N}^{-1}(u)} \frac{1}{2\pi\sqrt{1-\rho^{2}}}e^{-\frac{x^2-2\rho x \mathcal{N}^{-1}(v) +\mathcal{N}^{-1}(v)^{2}}{2(1-\rho^{2})} }dx}
\newline
\newline
h(u,v,\rho)=\mathlarger{\int_{-\infty}^{\mathcal{N}^{-1}(u)} \frac{1}{\sqrt{2\pi}}e^{-\frac{(x-\rho \mathcal{N}^{-1}(v))^2}{2(1-\rho^{2})}}dx }
\newline
\newline
h(u,v,\rho)=\mathlarger{\int_{-\infty}^{\frac{\mathcal{N}^{-1}(u)-\rho \mathcal{N}^{-1}(v)}{\sqrt{1-\rho^{2}}}} \frac{1}{\sqrt{2\pi}}e^{-\frac{y^2}{2}dy }}
\newline
\newline
h(u,v,\rho)=\mathlarger{  \mathcal{N}(\frac{\mathcal{N}^{-1}(u)-\rho\mathcal{N}^{-1}(v)}{\sqrt{1-\rho^{2}}})}
\end{math}
\newline
\newline
If we inverse this function, we obtain\newline
\newline
\begin{math}
h^{-1}(u,v,\rho) = \mathcal{N}(\sqrt{1-\rho^2}\mathcal{N}^{-1}(u)+\rho \mathcal{N}^{-1}(v))
\end{math}

	\subsubsection{c function in dimension n}
	\begin{equation*}
	c_{K}(u_1,...,u_d)=\frac{1}{\sqrt{det(K)}}e^{-\frac{\mathcal{N}^{-1}(u)^\top (K^{-1}-I_{d}) \mathcal{N}^{-1}(u)}{2}}
	\end{equation*}

	where \begin{math} \mathcal{N}^{-1}(u) =  \begin{pmatrix}
   \mathcal{N}^{-1}(u_{1}) \\
  \vdots   \\
   \mathcal{N}^{-1}(u_{d})
 \end{pmatrix}\end{math}

	\subsubsection{c function in dimension 2}
	\begin{math}
		c_\theta (u,v) = \frac{1}{\sqrt{1-\rho ^2}} e^{-\frac{\rho ^2(\mathcal{N}^{-1}(u)^2+\mathcal{N}^{-1}(v)^2) - 2 \rho \mathcal{N}^{-1}(u) \mathcal{N}^{-1}(v)}{2 (1-\rho ^2)}}
	\end{math}

	\subsection{Student Copula}
	The student copula of correlation matrix K and of degree of freedom \begin{math} \nu \end{math} is the copula of a student random vector \begin{math} t_\nu (0,K) \end{math}.\newline
	\newline
	Because one can change the variance of each marginal, we will only consider covariance matrix where there are only 1 in the diagonal.
	\newline
	\newline
	We will note \begin{math} t_\nu(x)=\frac{\Gamma (\frac{\nu+1}{2})}{\sqrt{\nu \pi} \Gamma (\frac{\nu}{2})}\int_{-\infty}^{x} \left(1+\frac{t^2}{\nu}\right)^{-\frac{\nu +1}{2}}dt \end{math}, the cumulative density function of the student distribution with degree of freedom \begin{math} \nu \end{math} and \begin{math}  t_\nu^{-1} \end{math} its inverse. \newline
	We could write both with the regularized incomplete Beta function \newline \begin{math} I_{a,b}(x) = \frac{1}{B(a,b)} \int_{0}^{x} t^{a-1}(1-t)^{b-1}dt \newline = \frac{\Gamma (a+b)}{\Gamma (a)\Gamma (b)} \int_{0}^{x} t^{a-1}(1-t)^{b-1}dt\end{math} \newline
	\newline
	and its inverse \begin{math} I_{a,b}^{-1} \end{math} : \newline
	\[
   		t_\nu (x) =  \begin{cases}
        I_{\frac{\nu}{2},\frac{1}{2}}(\frac{\nu}{x^2+\nu})  & \quad \text{if } x \leq 0 \\
    	1-I_{\frac{\nu}{2},\frac{1}{2}}(\frac{\nu}{x^2+\nu}) & \quad \text{if } x \geq 0\\
  	\end{cases}
  	\]

  	and \newline
  	\[
   		t_\nu^{-1} (x) =  \begin{cases}
        -\sqrt{\nu (\frac{1}{I^{-1}_{\frac{\nu}{2},\frac{1}{2}}(2y)}-1)}  & \quad \text{if } x \leq \frac{1}{2} \\
    	\sqrt{\nu (\frac{1}{I^{-1}_{\frac{\nu}{2},\frac{1}{2}}(2(1-y))}-1)}  & \quad \text{if } x \geq \frac{1}{2}\\
  	\end{cases}
  	\]

	\subsubsection{Generates X}
	To generates our U vector in the $[0,1]^d$ space, we need to first generates a X vector in the $\mathbb{R}^d$ space following a Multivariate Student Distribution. Thus, we use the equality in law :
	\begin{equation*}
	\sqrt{\frac{\nu}{S}} Z \sim t_\nu (0,K)
	\end{equation*}
	where $s \sim \chi_\nu^2$ and $Z \sim \mathcal{N} (0,K)$

	\subsubsection{C function in dimension n}

	\begin{math}
	 C_{K}(u_{1},...u_{d})= \mathlarger{ \int_{-\infty}^{t_\nu^{-1}(u_{1})}...\int_{-\infty}^{t_\nu^{-1}(u_{d})} \frac{\Gamma (\frac{\nu +d}{2})}{\Gamma
	 (\frac{\nu}{2})(\nu \pi)^{\frac{d}{2}}\sqrt{det(K)}}\left(1+\frac{1}{\nu}x^\top K^{-1} x \right)^{-\frac{\nu +d}{2}}dx}
	\end{math}
	\newline
	\newline
	With a change of variable, we have also \newline
	\newline
	\begin{math}
	C_{K}(u_{1},...u_{d})=  \mathlarger{ \int_{0}^{u_{1}}...\int_{0}^{u_{d}} \frac{\Gamma (\frac{\nu +d}{2}) \Gamma (\frac{\nu}{2})^{^{d-1}}}{\sqrt{det(K)}\Gamma (\frac{\nu +1}{2})^{^{d}}\Pi_{j=1}^d 1+\frac{t_\nu^{-1}(x_j)^2}{2})^{-\frac{\nu+1}{2}}}\left(1+\frac{1}{\nu}t_\nu^{-1}(x)^\top K^{-1} t_\nu^{-1}(x) \right)^{-\frac{\nu +d}{2}}dx}
	\end{math}
	\newline
	\newline
	\newline
	where \begin{math} t_\nu^{-1}(x) =  \begin{pmatrix}
   t_\nu^{-1}(x_{1}) \\
  \vdots   \\
   t_\nu^{-1}(x_{d})
 \end{pmatrix}\end{math}

\subsubsection{C function in dimension 2}

 	In dimension 2, all matrix of correlation can be written \begin{math} K =
 \begin{pmatrix}
  1 & \rho \\
  \rho & 1
 \end{pmatrix}
\end{math}. So we will only consider one parameter \begin{math} \rho \end{math}.\newline
\newline

\begin{math}
	C_{\rho,\nu} (u,v) = \mathlarger{\int_{-\infty}^{t_\nu^{-1}(u)}\int_{-\infty}^{t_\nu^{-1}(v)} \frac{1}{2\pi\sqrt{1-\rho^{2}}}\left(1+\frac{x^2 -\rho x y + y^2}{\nu (1-\rho^2)}\right)^{-\frac{\nu +2}{2}}dx dy}
\end{math}
\newline

\subsubsection{Partial derivative of C}

If we derivate the formula above, we obtain (cf Pair copula constructions of muliple dependance) : \newline
\begin{math}
h(u,v,\rho,\nu)=\frac{\partial C_{\rho,\nu}}{\partial v} (u,v) = t_\nu \bigg(\frac{t_\nu^{-1}(u)-\rho t_\nu^{-1}(v)}{\sqrt{\frac{(\nu+t_\nu^{-1}(v)^2)(1-\rho ^2)}{\nu+1}}}\bigg)
\end{math}

If we inverse this function, we obtain\newline
\newline
\begin{math}
h^{-1}(u,v,\rho,\nu) = t_\nu (\sqrt{\frac{(\nu+t_\nu^{-1}(v)^2)(1-\rho)}{\nu+1}}t_\nu^{-1}(u)+\rho t_\nu^{-1}(v))
\end{math}

	\subsubsection{c function in dimension n}

	\begin{equation*}
	 c_{K,\nu} (u_{1},...,u_{d}) = \frac{\Gamma (\frac{\nu +d}{2}) \Gamma (\frac{\nu}{2})^{^{d-1}}}{\sqrt{det(K)}\Gamma (\frac{\nu +1}{2})^{^{d}}\Pi_{j=1}^d (1+\frac{t_\nu^{-1}(u_{j})^2}{2})^{-\frac{\nu+1}{2}}}\left(1+\frac{1}{\nu}t_\nu^{-1}(u)^\top K^{-1} t_\nu^{-1}(u) \right)^{-\frac{\nu +d}{2}}
	\end{equation*}
	\newline
	 where \begin{math} t_\nu^{-1}(u) =  \begin{pmatrix}
   t_\nu^{-1}(u_{1}) \\
  \vdots   \\
   t_\nu^{-1}(u_{d})
 \end{pmatrix}\end{math}
	\subsubsection{c function in dimension 2}

	\begin{equation*}
		c_\theta (u,v) = \frac{\Gamma (\frac{\nu}{2})\Gamma (\frac{\nu +2}{2})}{\Gamma(\frac{\nu+1}{2})^2 (1+\frac{t_\nu^{-1} (u)^2}{\nu})^{-\frac{\nu+1}{2}} (1+\frac{t_\nu^{-1} (v)^2}{\nu})^{-\frac{\nu+1}{2}} \sqrt{ 1-\rho^2} } \left(1 + \frac{t_\nu^{-1} (u)^2 + t_\nu^{-1} (v)^2 - 2 \rho t_\nu^{-1} (u) t_\nu^{-1} (v)}{\nu (1-\rho^2)}\right)^{-\frac{\nu +1}{2}}
	\end{equation*}

   \section{Archimedean Copulas}
   Archimedean copulas take the form :
   \newline
   \newline
   \begin{math}
   C(u_{1},...,u_{d})= \Phi(\Phi^{-1}(u_{1})+...+\Phi^{-1}(u_{d}))
   \end{math}
   \newline
   \newline
   where \begin{math} \Phi \end{math} is the Laplace transform of a positive nonzero random variable Y :
	\begin{math} \Phi (u)=\mathbb{E}(e^{-uY})
	\newline
	\newline
	\Phi \end{math} is called the generator function.
	\newline
	It generally depends on a parameter called \begin{math} \theta \end{math}.
	\newline
	In some papers, the definition of the generator function and its inverse can be inverted. We will use the definition above which gives us simpler formulas.
	\newline

	All of the next formulas can be expressed with the generator function.\newline
	For example, if we refer to \cite{archimedeancopulas}, we can write the Kendall distribution function thanks to the generator function :
	\[
   		\mathcal{K}_C (x) =
   		\begin{cases}
        \frac{(-1)^{d-1}(\Phi^{-1}(0))^{d-1}}{(d-1)!}\Phi_-^{(d-1)}(\Phi^{-1}(0))  & \quad \text{if } x=0 \\
    \sum\limits_{k=0}^{d-2}\frac{(-1)^{k}(\Phi^{-1}(x))^{k}\Phi^{(k)}(\Phi^{-1}(x))}{k!}+\frac{(-1)^{d-1}(\Phi^{-1}(x))^{d-1}\Phi_-^{(d-1)}(\Phi^{-1}(x))}{(d-1)!} & \quad \text{if } x \in ]0,1] \\
  \end{cases}
  \]
   	\subsection{Frank Copula}
   	\subsubsection{Generator, generator inverse and derivatives}
   	\begin{math}
   		\theta \in \mathbb{R} \backslash \{ 0 \} \newline
   		\newline
   		\Phi_{\theta}(t)= -\frac{1}{\theta}log(1+e^{-t}(e^{-\theta}-1))
   		\newline
   		\newline
   		\Phi_{\theta}^{-1}(t)=-log(\frac{e^{-\theta t}-1}{e^{-\theta}-1})
   		\newline
   		\newline
   		\Phi_{\theta}^\prime (t)= \frac{e^{-t}}{\theta (\frac{1}{e^{-\theta} -1}+e^{-t})}
   		\newline
   		\newline
   		\Phi_{\theta}^{\prime \prime} (t)= \frac{-e^{-t}}{\theta (e^{-\theta} -1) (\frac{1}{e^{-\theta} -1}+e^{-t})^2}
   	\end{math}

   	\subsubsection{C function in dimension 2}
   	\begin{math}
   		C_{\theta}(u,v) = -\frac{1}{\theta}log(1+\frac{(e^{\theta u}-1)(e^{\theta v}-1)}{e^{-\theta}-1})
   	\end{math}

   	\subsubsection{Partial derivative of C and inverse}
   	\begin{math}
   		h(u,v,\theta)=\frac{\partial C_{\theta}}{\partial v} (u,v) = \frac{e^{\theta u}-1}{e^{\theta u}+e^{\theta v}-e^{\theta (u+v-1)}-1}
   	\newline
	\newline
	\text{We first solve } \frac{a X + b}{c X + d}=y \text{, where } a = 1, b =-1, c= 1-e^{\theta (v-1)}, d = e^{\theta v}-1\newline
	\newline
	\text{We have then } X = \frac{dy-b}{a-cy}\newline
	\newline
	\text{We solve } e^{\theta u}=X : u = \frac{1}{\theta}log(X)\newline
	\newline
	\text{So, we now have}\newline
  	h^{-1}(u,v,\theta) = \frac{1}{\theta}log(\frac{(e^{\theta v}-1)u+1}{1-(1-e^{\theta (v-1)})u})
   	\end{math}

   	\subsubsection{c function in dimension 2}

   	\begin{math}
   	c_\theta (u,v) = \frac{\theta e^{\theta (u+v)} (1-e^{-\theta})}{(e^{\theta u}+e^{\theta v}-e^{\theta (u+v-1)}-1)^2}
   	\end{math}

   	\subsection{Gumbel Copula}
   	\subsubsection{Generator and generator inverse}
   	\begin{math}
   		\theta \in  [1,\infty[ \newline
   		\newline
   		\Phi_{\theta}(t)= e^{-t^{ \frac{1}{\theta} }}
   		\newline
   		\Phi_{\theta}^{-1}(t)=(-log(t))^{\theta} \newline
   		\Phi_{\theta}^\prime (t) = -\frac{1}{\theta} t^{ \frac{1-\theta}{\theta}} e^{-t^{ \frac{1}{\theta} }} \newline
   		\Phi_{\theta}^{\prime \prime} (t) = ((-\frac{1}{\theta} t^{ \frac{1-\theta}{\theta}})^2 - \frac{1-\theta}{\theta^2} t^{ \frac{1-2\theta}{\theta}}) e^{-t^{ \frac{1}{\theta} }}
   	\end{math}
   	\subsubsection{C function in dimension 2}
   	\begin{math}
   		C_{\theta}(u,v) = e^{-((-log(u))^{\theta}+(-log(v))^{\theta})^{\frac{1}{\theta}}}
   	\end{math}
   	\subsubsection{Partial derivative of C and inverse}
   	\begin{math}
   		h(u,v,\theta)=\frac{\partial C_{\theta}}{\partial v} (u,v) = \frac{1}{v}(-log(v))^{\theta-1}((-log(u))^{\theta}+(-log(v))^{\theta})^{\frac{1}{\theta}-1}e^{-((-log(u)^{\theta}+(-log(v))^{\theta})^{\frac{1}{\theta}}}
	\newline
	\newline
	\text{We have to introduce the lambert W function which is the inverse of } x \to x e^{x} :\newline
	W(x)e^{W(x)}=x
	\newline\newline
	\text{For } x \geq 0, ye^{y}= x \text{ has only one solution y.}\newline
	\text{So, there is no ambiguity to define } W(x) \text{ if } x\geq 0.
	\newline
	\newline
	\text{We first solve } \lambda X^\alpha e^{-X} = y \text{ where } \lambda = \frac{(-log(v))^{\theta-1}}{v}, \alpha = 1-\theta
	\newline
	\newline
	\text{We obtain } X = \alpha W(\frac{1}{\alpha}(\frac{y}{\lambda})^{\frac{-1}{\theta-1}})
	\newline
	\newline
	\text{Then, we solve } X = ((-log(u))^{\theta}+(-log(v))^{\theta})^{\frac{1}{\theta}}
	\newline
	\newline
	\text{which gives us } u = e^{-(X^{\theta}-(-log(v))^{\theta})^{\frac{1}{\theta}}}
	\newline
	\newline
	\text{Finally, we have }
  	h^{-1}(u,v,\theta) = e^{-(((\theta-1)W(\frac{-log(v)}{\theta-1}(vu)^{\frac{-1}{\theta -1}}))^{\theta}-(-log(v))^{\theta})^{\frac{1}{\theta}}}
	\end{math}

	\subsubsection{c function in dimension 2}

	\begin{math}
		c_\theta (u,v) =  \frac{C_\theta (u,v)}{u v} ((-log(u)^{\theta}+(-log(v))^{\theta})^{-2+\frac{2}{\theta}} [1+ (\theta -1)((-log(u)^{\theta}+(-log(v))^{\theta})^{-\frac{1}{\theta}}]
	\end{math}

   	\subsection{Clayton Copula}
   	\subsubsection{Generator, generator inverse and derivatives}
   	\begin{math}
   		\theta \in  [-1,\infty[ \backslash \{ 0 \} \newline
   		\newline
   		\Phi_{\theta}(t)= (1+\theta t)_+^{-\frac{1}{\theta} }
   		\newline
   		\Phi_{\theta}^{-1}(t)=\frac{1}{\theta}(t^{-\theta}-1) \newline
   		\newline
   		\Phi_{\theta}^{(n)}(t) = (-1)^n (1+\theta t)^{-\frac{1+n \theta}{\theta}} \prod\limits_{k=0}^{n-1} (1 + k \theta)
   	\end{math}

	\subsubsection{C function in dimension 2}
   	\begin{math}
   		C_{\theta}(u,v) = (max\{u^{-\theta}+v^{-\theta}-1;0\})^{-\frac{1}{\theta}}
   	\end{math}
	\subsubsection{Partial derivative of C and inverse}
   	\[
   		h(u,v,\theta)=\frac{\partial C_{\theta}}{\partial v} (u,v) = \begin{cases}
        v^{-\theta-1}(u^{-\theta}+v^{-\theta}-1)^{-\frac{1}{\theta}-1}  & \quad \text{if } u^{-\theta}+v^{-\theta} \geq 1 \\
    0  & \quad \text{else} \\
  \end{cases}
  \]

  	\begin{math}
  	h^{-1}(u,v,\theta) = (u^{-\frac{\theta}{\theta+1}}v^{-\theta}-v^{\theta}+1)^{-\frac{1}{\theta}}
	\end{math}
	where u must be nonzero.

	\subsubsection{c function in dimension 2}
	\begin{math}
		c_\theta (u,v) = (1+\theta)(u v)^{-1-\theta}(u^{-\theta}+v^{-\theta}-1)^{-\frac{1}{\theta}-2}
	\end{math}

	\section{Empirical Copula}
	Having a sample of multivariate random variables, we can define the finite empirical distribution of this sample where each realisation of the sample is equiprobable. The empirical copula is the copula of this empirical distribution. Contrary to the other ones, the empirical copula depends on its marginals.

	\begin{equation*}
	C(u_1,...,u_d) = \sum_{k=1}^n \mathds{1}_{\forall i, F_i(x_k)\leq u_i}
	\end{equation*}

	where, $F_i$ is the cdf of the marginal i.

	\section{Vine Copulas}

	\subsection{Canonical Vine Copula}

	\subsubsection{Global probability density function}

	\begin{equation*}
		f(x_1,...,x_d)= \prod_{k=1}^d f(x_k) \prod_{j=1}^{d-1} \prod_{i=1}^{d-j} c_{j,j+i|1,...,j-1}(F(x_j|x_1,...,x_{j-1}),F(x_{j+i}|x_1,...,x_{j-1}))
	\end{equation*}

	\subsubsection{c function in dimension n}
	By identifying c in the previous equation, we have :

	\begin{equation*}
		c_{1,...,d}(F_1(x_1),...,F_d(x_d))=  \prod_{j=1}^{d-1} \prod_{i=1}^{d-j} c_{j,j+i|1,...,j-1}(F(x_j|x_1,...,x_{j-1}),F(x_{j+i}|x_1,...,x_{j-1}))
	\end{equation*}

	We now do an approximation of conditional independance : \newline
	\begin{math} c_{j,j+i|1,...,j-1}=1 \end{math} when \begin{math} (1,...,j-1) \neq \emptyset \Leftrightarrow j \neq 1\end{math}
	\newline
	\newline
	We obtain :\newline
	\begin{equation*}
		c_{1,...,d}(F_1(x_1),...,F_d(x_d)) = \prod_{i=1}^{d-1} c_{1,i+1} (F_1(x_1),F_{i+1}(x_{i+1}))
	\end{equation*}

	Then,

	\begin{equation*}
		c_{1,...,d}(u_1,...,u_d) = \prod_{i=1}^{d-1} c_{1,i+1} (u_1,u_d)
	\end{equation*}

	\subsection{D Vine Copula}

	\subsubsection{Global probability density function}

	\begin{equation*}
		f(x_1,...,x_d)= \prod_{k=1}^d f(x_k) \prod_{j=1}^{d-1} \prod_{i=1}^{d-j} c_{i,i+j|i+1,...,i+j-1}(F(x_i|x_{i+1},...,x_{i+j-1}),F(x_{i+j}|x_{i+1},...,x_{i+j-1}))
	\end{equation*}

	\subsubsection{c function in dimension n}
	By identifying c in the previous equation, we have :

	\begin{equation*}
		c_{1,...,d}(F_1(x_1),...,F_d(x_d))= \prod_{j=1}^{d-1} \prod_{i=1}^{d-j} c_{i,i+j|i+1,...,i+j-1}(F(x_i|x_{i+1},...,x_{i+j-1}),F(x_{i+j}|x_{i+1},...,x_{i+j-1}))
	\end{equation*}

	We now do an approximation of conditional independance : \newline
	\begin{math} c_{i,i+j|i+1,...,i+j-1}=1 \end{math} when \begin{math} (i+1,...,i+j-1) \neq \emptyset \Leftrightarrow j\neq 1\end{math}

	We obtain :\newline
	\begin{equation*}
		c_{1,...,d}(F_1(x_1),...,F_d(x_d)) = \prod_{i=1}^{d-1} c_{i,i+1} (F_i(x_i),F_{i+1}(x_{i+1}))
	\end{equation*}

	Then,
	\begin{equation*}
		c_{1,...,d}(u_1,...,u_d) = \prod_{i=1}^{d-1} c_{i,i+1} (u_i,u_{i+1})
	\end{equation*}

\begin{thebibliography}{9}

	\bibitem{archimedeancopulas}
  	Alexander J. McNeil, Johanna Neslehova
 	 \emph{Multivariate Archimedean Copulas, d-monotone Functions and l1-norm Symmetric Distributions},Ann. Stat., 37:3059-3097, 2009.

	\bibitem{vineconstruction}
  	Kjersti Aas, Claudia Czado, Arnoldo Frigessi, Henrik Bakken,
 	 \emph{Pair-copula construction of multiple dependence},
  	2007.

  	\bibitem{fourcopulas}
  	Kjersti Aas,
 	 \emph{Modeling the dependance structure of financial assets : A survey of four copulas}
  	2004.

  	\bibitem{kendallfunction}
  	Johanna F. Ziegel, Tilmann Gneiting,
 	 \emph{Copula Calibration}, Electronic Journal of Statistics,
  	2014.

	\end{thebibliography}
\end{document}


\documentclass{article}
\usepackage{hyperref,lipsum,amsmath,amssymb}
\hypersetup{colorlinks=true} % make sure our hyperlinks are coloured for visibility
% We define an Author, Title and Date
\author{\emph{Your Name Here}}
\title{A Short \LaTeX{} Worksheet \\ \small Created by Sam Fearn -- s.m.fearn@durham.ac.uk}
\date{March 15\textsuperscript{th}, 2018}

\begin{document}
% Create a title from our Author, Title and Date
\maketitle
% We put our content into section environments
\section{Introduction}
\label{sec:introduction}
% I didn't have time to discuss labels today, but adding labels to your document allows you to refer back to the relevant place later in your document using the \ref{label} command. For example, I could refer to the introduction later in my document by saying `see section \ref{sec:introduction}'. This would produce the output `see section 1'. The advantage os using labels, is that if I add a reference to section 2, and then later add a new section before the old section 2, the reference will automatically be updated to say section 3. Try adding some references to the various sections and subsections of this document.
This worksheet has been created using the \LaTeX{} typesetting system. By reproducing this document you should be able to develop your skills with \LaTeX{}. You should \emph{typeset} your file regularly to see whether it is looking correct. Try it now if you haven't already. If everything has worked properly you should now have a PDF file of the worksheet up to this point.

\section{Content}
\label{sec:content}

\emph{Sections} allow us to add structure our documents. For a short document such as this, we will use \emph{sections} and \emph{subsections}. A longer document such as a thesis would also use \emph{chapters} (and the \emph{report} document class). The first this we will discuss is how to typeset mathematics. To start with, ignore the `verbatim' code and hyperlinks in the following subsection, these will be explained later. A good reference for some of the symbols and commands in the following subsections is \href{https://wch.github.io/latexsheet/latexsheet.pdf}{the \LaTeXe{} cheat sheet}.

\subsection{Typesetting Mathematics}
\label{sub:typesetting_mathematics}

One of the reasons to use \LaTeX{} is that it can produce very good looking mathematical formulae. We have already seen some examples in the talk. \LaTeX{} only recognises mathematical commands while in `maths mode'. There are a few ways to enter maths mode -- which one we use depends on how we want the output to be formatted. If I want the maths to be `inline', part of the current line, then I place it between dollar symbols. Therefore \$ x = 4 \$ produces $x=4$. If I want to produce an equation which is placed on its own line then I can use the \emph{\textbf{equation} environment}.
\begin{verbatim}
	\begin{equation}
	    x^3 + 2 \ge 6.
	\end{equation}
\end{verbatim}
This produces
\begin{equation}
	x^3 + 2 \ge 6.
\end{equation}
See \href{https://www.sharelatex.com/learn/Mathematical_expressions}{this webpage} for more information on mathematics modes. Try to reproduce the rest of this subsection as closely as you can.

A \emph{bijection} is a map between two sets which is both \emph{injective} and \emph{surjective}. Let us now define these terms. Given two sets $A$ and $B$, a map $\phi:A \to B$ is said to be injective if
\begin{equation}\label{eq:injective} % I can also add referenecs to my equations using labels.
	\phi(a_1) = \phi(a_2) \iff a_1 = a_2,\ \forall\ a_1,a_2 \in A.
\end{equation}
Furthermore, the map is surjective if
\begin{equation}\label{eq:surjective}
	\forall\ b \in B,\ \exists\ a \in A\ |\ \phi(a)=b.
\end{equation}
% Try uncommenting the following line.
% If both equation \ref{eq:injective} and equation \ref{eq:surjective} are satisfied, then the map is said to be \emph{bijective}.

The talk also covered the import result of the \emph{Gaussian integral}
\begin{equation}
	\int_{-\infty}^\infty e^{-\frac{1}{2}\left( \frac{x - \mu}{\sigma} \right)^2} dx = \sigma\sqrt{2 \pi}.
\end{equation}

In the partitions project, we saw how the geometric progression formula
\begin{equation}
	\frac{1}{1-x} = 1 + x + x^2 + \ldots + x^n + \ldots = \sum_{n=0}^\infty x^n,
\end{equation}
could be used to deduce the generating function for the partition number $p(n)$,
\begin{equation}
	\sum_{n=0}^\infty p(n) x^n = \prod_{n=1}^\infty \frac{1}{1-x^n}.
\end{equation}

\subsection{Verbatim} % (fold)
\label{sub:verbatim}

In order to explain some of the commands that you will need to add to your file, we will need to show the names of the commands on the worksheet. In order for \LaTeX{} to display the command rather than process it we use an \emph{environment} called \textbf{Verbatim}.
\begin{verbatim}
	\begin{verbatim}
	    \LaTeX{} is now printed rather than processed.
	\end{verbatim }
\end{verbatim}
% Note the space after in the inner \end{verbatim }. This is so \LaTeX{} understand the difference between the one I want to print verbatim and the actual end of the verbatim environment.
We can also produce verbatim output in the middle of a line using \verb!\verb|\LaTeX{}|!.
% We can use both the exclamation mark or the pipe mark to indicate what content is to be inline verbatim. As previously, I have to use one of each to ensure that \LaTeX{} understands which one ends the actual verb environment, and which is to be printed verbatim.
\subsection{Packages}
\label{sub:packages}

One of the advantages of \LaTeX{} (or \TeX{}) is that it can be extended using \emph{packages}. A package is \emph{loaded} by adding the the line
\begin{verbatim}
	\usepackage{package_name}
\end{verbatim}
into the \emph{preamble} of your tex file. The preamble is the part of the file before the line \verb|\begin{document}|. Everything between \verb|\begin{document}| and \verb|\end{document}| is called the \emph{body} of the document. We can use a package called \href{https://ctan.org/pkg/lipsum?lang=en}{lipsum} to produce dummy text. This hyperlink was in turn created with a package called \href{latex hyperref}{hyperref} and the command used was
\begin{verbatim}
	\href{https://ctan.org/pkg/lipsum?lang=en}{lipsum}.
\end{verbatim}
The following paragraph is produce using the lipsum package, you can read about how to use this package from the package documentation on the previously linked webpage for lipsum -- the following is the lipsum paragraph 66.

\lipsum[66]

Two packages that we will often want to use are the \href{https://michael-prokop.at/latextug/amsldoc.pdf}{amsmath and amssymb} packages, which are documented at the previously linked page. They add more mathematical commands that you can then use in you documents, such as matrices, unnumbered environments and mathematical fonts. Once I have loaded amsmath and amssymb, I can prodcue the output
\begin{equation*}
	A = \begin{pmatrix}
		4 - 2i & i \\
		-i & a
	\end{pmatrix} \in M_2(\mathbb{C}).
\end{equation*}
These packages also allow us to align equations using the \textbf{align} environment. We can use this to define two block matrices $B$ and $C$. We can then give the multiplication of these matrices in a new equation environment. If
\begin{align}
	B &= \left(\begin{array}{c | c} % The c here is to centre align the array columns.
		P & Q \\
		\hline
		R & S
	\end{array}\right),\nonumber \\
	C &= \left(\begin{array}{c | c}
		W & X \\
		\hline
		Y & Z
	\end{array}\right),
\end{align}
then
\begin{equation}
	BC = \left(\begin{array}{c | c}
		PW + QY & PX + QZ \\
		\hline
		RW + SY & RX + SZ
	\end{array}\right).
\end{equation}
% There's quite a lot going on in the previous few lines, this was supposed to be the hardest part to reproduce for anyone who already had some experience with latex. The \left( and \right) commands are used to produce parentheses which scale automatically based on what is inside them. The array environment lets me format content in columns and specify a serperator. I use this to produce the vertical line of the block matrix, the horizontal line is produced with the \hline command. The ampersand character & is used by \LaTeX{} to align elements. It is used between the B and the equals and between the C and the equals to align these two lines. The double slash \\ after the first right) is used to end the first line and stat a new line. The ampersand is also used inside the array environment to tell \LaTeX{} how to align the elements of the columns. Finally, the \nonumber command suppresses the equation number for the first line of the align environment.

\section{Conclusion}
\label{sec:conclusion}
Regardless of how much of this sheet you have been able to reproduce, I hope you have learnt something about \LaTeX{}. In my opinion, it is best to learn \LaTeX{} simply by starting to use it, and answering any questions you have as you go by using the many excellent resources online. The \href{https://www.sharelatex.com/learn}{ShareLaTeX} website contains a lot of useful help, as does \href{https://tobi.oetiker.ch/lshort/lshort.pdf}{The Not So Short Introduction To \LaTeXe{}}. The tex file used to produce this talk will be available shortly so that you can compare with your tex file. I have also added some comments to my file to explain some additional things, so I encourage you to read through if you are interested.

\end{document}