\documentclass{amsart}
\usepackage{hyperref,amsmath,amsfonts}

\begin{document}
\title{Library for Quadratic Programming}
\author{Vojt\v{e}ch Franc\\ xfrancv at cmp.felk.cvut.cz}
\maketitle
%\tableofcontents

\def\x{\mathbf x}
\def\f{\mathbf f}
\def\a{\mathbf a}
\def\H{\mathbf H}
\def\Sequ{\rm S_{\rm equ}}
\def\Sneq{\rm S_{\rm neq}}
\renewcommand{\Re}{\mathbb{R}}

\section*{Introduction}

LIBQP is C library which implements algorithms for solving two special instances of
convex Quadratic Programming (QP):

%\begin{enumerate}
 % \item

\large
\subsection*{QP task with simplex constraints} This QP task is defined as follows
\[
   \begin{array}{lrcll}
     \mbox{minimize} &\multicolumn{4}{l}{\displaystyle\frac{1}{2}\x^T \H \x +
       \x^T \f} \\ \\
     \mbox{subject to}
     & \displaystyle\sum_{i\in I_k} x_i & = & b_k\:, & k\in \Sequ \\
     & \displaystyle\sum_{i\in I_k} x_i & \leq & b_k\:, & k\in \Sneq \\
     & x_i & \geq & 0\:, & i\in I \:.
   \end{array}
\]
where \(\x = (x_1,\ldots,x_n)\in\Re^n\) is the optimized vector, \(\H
\in\Re^{n\times n}\) is a symmetric positive semi-definite matrix,
\(\f\in\Re^n\) is a vector, \(I =
\{1,\ldots,n\}\) is an index set, \(\{I_1,\ldots,I_m\}\) are subsets of \(I\)
such that  \(I_1\cup \ldots \cup I_k = I\) and \(I_1 \cap \ldots \cap I_k =
\emptyset\), \(\Sequ\) and \(\Sneq\) are index sets such that
\(\Sequ \cup \Sneq = \{1,\ldots,m\}\) and \(\Sequ \cap \Sneq = \emptyset\),
\((b_1,\ldots,b_m)\in\Re^m\) are positive numbers.

The implemented solver (\verb|libqp_splx.c|) is a generalization of the method
proposed in~\cite{Franc-TR-2006-04,Fan-JMLR05}. It is based on the Sequential Minimal
Optimization (SMO) algorithm with an improved working set selection
strategy. Solving instances of this QP task is required, for example, in machine
learning methods like Structured SVM learning, Bundle Methods for Risk
Minimization, binary SVM with L2-soft margin, etc.

\subsection*{QP task with box constraints and a single linear equality constraint}
This QP task is defined as follows
\[
  \begin{array}{lrcl}
    \mbox{minimize} &\multicolumn{3}{l}{\displaystyle\frac{1}{2}\x^T \H \x +
      \x^T \f} \\ \\
    \mbox{subject to}
    & \displaystyle\x^T \a & = & b\:, \\
    & \multicolumn{3}{c}{\displaystyle l_i \leq x_i \leq u_i\:, \qquad i=1,\ldots,n}\:,
  \end{array}
\]
where \(\x = (x_1,\ldots,x_n)\in\Re^n\) is the optimized vector, \(\H
\in\Re^{n\times n}\) is a symmetric positive semi-definite matrix,
\(\f\in\Re^n\) is a vector, $\a\in\Re^n$ is a vector with non-zero entries,
$b\in\Re$ is a scalar, $(l_1,\ldots,l_n)\in(\Re \cup \{-\infty\})^n$ and
$(u_1,\ldots,u_n)\in(\Re\cup\{\infty\})^n$ are lower and upper bounds,
respectively.

The solver (\verb|libqp_gsmo.c|) is the exact implementation of the
Generalized Sequential Minimal Optimizer proposed in~\cite{Keerthi-00}.
Solving this QP task is required, for example, when training binary
SVM with L1-soft margin.

\section*{Interfaces}

LIBQP is implemented in C language and interfaces to Matlab.

\section*{Platforms}

GNU/Linux. It should run also under Windows though not tested.

\section*{Installation}

LIBQP can be downloaded from \url{http://cmp.felk.cvut.cz/~xfrancv/libqp/libqp.zip}.

\subsection*{MATLAB}

\begin{enumerate}
  \item Run Matlab and go to the folder \verb|libqp_root/matlab|
    \begin{verbatim}
      cd libqp_root/matlab
    \end{verbatim}
  \item Compile mex files by running
    \begin{verbatim}
      libqp_compile
    \end{verbatim}
\end{enumerate}
Now you can use \verb|libqp_splx| and \verb|libqp_gsmo| solvers located in
\verb|libqp_root/matlab|. To make these function visible from Matlab you
need to add
\begin{verbatim}
    addpath('libqp_root/matlab')
\end{verbatim}
to your \verb|startup.m| file.

\noindent
To test the solvers run scripts
\begin{verbatim}
  libqp_splx_test
  libqp_gsmo_test
\end{verbatim}

\subsection*{Example application}

\begin{enumerate}
  \item Go to the folder \verb|libqp_root/examples|
    \begin{verbatim}
      cd libqp_root/examples
    \end{verbatim}
  \item Issue make
    \begin{verbatim}
      make
    \end{verbatim}
\end{enumerate}
Now you can run test script
\begin{verbatim}
    ./run_test
\end{verbatim}

\section*{License}

LIBQP is licensed under the GPL version 3 (\url{http://gplv3.fsf.org/}).

\begin{thebibliography}{00}
\bibitem[1]{Franc-TR-2006-04}
V. Franc, V. Hlavac. A Novel Algorithm for Learning Support Vector Machines
with Structured Output Spaces. Research Report K333 22/06, CTU-CMP-2006-04.
May, 2006.
\url{ftp://cmp.felk.cvut.cz/pub/cmp/articles/franc/Franc-TR-2006-04.ps}
\bibitem[2]{Fan-JMLR05}
R.-E. Fan, P.-H. Chen, C.-J. Lin. Working Set Selection Using Second Order
Information for Training SVM. JMLR. vol 6. 2005.
\url{TBA}
\bibitem[3]{Keerthi-00}
S.-S. Keerthi, E.G.Gilbert. Convergence of a Generalized SMO Algorithm for SVM
Classifier Design. Technical Report CD-00-01, Control Division, Dept. of Mechanical
and Production Engineering, National University of Singapore, 2000.
\url{http://citeseer.ist.psu.edu/keerthi00convergence.html}
\end{thebibliography}
\end{document}


\section{ReLU multigrid method for nonnegative solution}
Considering $f = (1, 1, ..., 1)^\top$,
\begin{breakablealgorithm}%[!htb]
	\caption{$(u^{1}, u^2, \cdots, u^J) = {\text{MG0}}(f; u^0; J,\nu_1, \cdots, \nu_J)$}
	\label{alg:L-ReLUSlash0}
	\begin{algorithmic}
		\State Set up
		$$
		f^1 = f, \quad u^{1}=u^0.
		$$
		\State Smoothing and restriction from fine to coarse level (nested)
		\For{$\ell = 1:J$}
		\For{$i = 1:\nu_\ell$}
		\State
		\begin{equation}\label{eq:smoothing}
		u^{\ell} \leftarrow u^{\ell} + S^\ell \ast \text{Relu}( (f^\ell - A_\ell \ast u^{\ell})).
		\end{equation}
		\EndFor
		\State Form restricted residual and set initial guess:
		$$
		u^{\ell+1,0} \leftarrow 0, \quad f^{\ell+1} \leftarrow R \ast_2 (f^\ell -  A_\ell \ast u^{\ell}), A_{\ell+1} = R \ast_2 A_\ell \ast (R\ast_2^\top).
		$$
		\EndFor
	\end{algorithmic}
\end{breakablealgorithm}
Algorithm 5 is not convergent.

\newpage
\begin{breakablealgorithm}%[!htb]
	\caption{$(u^{1}, u^2, \cdots, u^J) = {\text{MG0}}(f; u^0; J,\nu_1, \cdots, \nu_J)$}
	\label{alg:L-ReLUSlash1}
	\begin{algorithmic}
		\State Set up
		$$
		f^1 = f, \quad u^{1}=u^0.
		$$
		\State Smoothing and restriction from fine to coarse level (nested)
		\For{$\ell = 1:J$}
		\For{$i = 1:\nu_\ell$}
		\State
		\begin{equation}\label{eq:smoothing}
		u^{\ell} \leftarrow u^{\ell} +\text{Relu}( S^\ell \ast  (f^\ell - A_\ell \ast u^{\ell})).
		\end{equation}
		\EndFor
		\State Form restricted residual and set initial guess:
		$$
		u^{\ell+1,0} \leftarrow 0, \quad f^{\ell+1} \leftarrow R \ast_2 (f^\ell -  A_\ell \ast u^{\ell}), A_{\ell+1} = R \ast_2 A_\ell \ast (R\ast_2^\top).
		$$
		\EndFor
	\end{algorithmic}
\end{breakablealgorithm}

Algorithm 6 is convergent, the iterative steps is list below. $l = 2$
\\
\begin{tabular}{c|c|c|}
	J &MG& Algorithm 6\\ \hline
	2 & 15 & 27 \\\hline
	3 & 16 & 35 \\\hline
	4 & 17 & 38 \\\hline
\end{tabular}

\subsection{$\Pi$ is interpolation}
\textbf{Not Convergent}
		\begin{equation}
		u^{\ell,i} \leftarrow u^{\ell,i-1} + \text{Relu}\circ B_{\ell,i}  ({f^\ell -  A^{\ell} (u^{\ell,i-1})}).
		\end{equation}
	 \begin{equation}
	 u^{\ell,i} \leftarrow u^{\ell,i-1} + B_{\ell,i}\circ\text{Relu}({f^\ell -  A^{\ell} (u^{\ell,i-1})}).
	 \end{equation}
\textbf{Almost the same as without Relu}
	 \begin{equation}
	 u^{\ell,i} \leftarrow u^{\ell,i-1} +B_{\ell,i}  ({f^\ell -   \text{Relu}\circ A^{\ell} (u^{\ell,i-1})}).
	 \end{equation}
	 \begin{equation}
	 u^{\ell,i} \leftarrow u^{\ell,i-1} + B_{\ell,i}  ({f^\ell -  A^{\ell} \circ\text{Relu}(u^{\ell,i-1})}).
	 \end{equation}

497-6DL/8 Convolutional Multigrid Method/8.13-ReLU-multigrid.tex


\chapter{Exponents}

Let's quickly review exponents. Ancient scientists started coming up
with a lot of formulas that involved multiplying the same number
several times.  For example, if they knew that if a sphere was $r$
centimeters in radius, its volume in milliliters was

$$V = \frac{4}{3} \times \pi \times r \times r \times r$$

They did two things to make the notation less messy.  First, they
decided that if two numbers were written next to each other, the
reader would assume that meant ``multiply them''.  Second, they came
up with the exponent, a little number that was lifted up off the
baseline of the text, that meant ``multiply it by itself''.  For
example $5^3$ was the same as $5 \times 5 \times 5$.\index{exponents}

Now the formula for the volume of a sphere is written

$$V = \frac{4}{3} \pi r^3$$

Tidy, right? In an exponent expression like this, we say that $r$ is
\textit{the base} and $3$ is \textit{the exponent}.

\section{Identities for Exponents}

What about exponents of exponents?  What is $\left(5^3\right)^2$?

$$\left(5^3\right)^2 = (5 \times 5 \times 5)^2 = (5 \times 5 \times 5)(5 \times 5 \times 5) = 5^6$$

In general, for any $a$, $b$, and $c$:

$$\left(a^b\right)^c = a^{(bc)}$$

If you have $\left( 5^3 \right) \left(5^4 \right)$ that is just $5 \times 5 \times 5 \times 5 \times 5 \times 5 \times 5$ or $5^7$

The general rule is, for any $a$, $b$, and $c$

$$\left(a^b\right)\left(a^c\right) = a^{(b + c)}$$

Mathematicians \textit{love} this rule, so we keep extending the idea
of exponents to keep this rule true. For example, at some point
someone asked ``What about $5^0$?'' According to the rule, $5^{2}$
must equal $5^{(2 + 0)}$ which must equal
$\left(5^2\right)\left(5^0\right)$.  Thus, $5^2$ must be 1. So
mathematicians declared ``Anything to the power of 0 is 1''.\index{exponents!zero}

Actually, we don't typically assume that $0^0 = 1$. It is just too
weird. So we say, that for any $a$ not equal to zero,

$$a^0 = 1$$

What about $5^{(-2)}$?  By our beloved rule, we know that
$\left(5^{-2}\right)\left(5^5\right)$ must be equal to $5^3$, right?
So $5^{-2}$ must be equal to $\frac{1}{5^2}$.\index{exponents!negative}

We say, for any $a$ not equal to zero and any $b$,

$$a^{-b} = \frac{1}{a^{b}}$$

This make dividing one exponentional expression by another (with the same base) easy:

$$\frac{a^b}{a^c} = a^{(b-c)}$$

We often say ``cancel out'' for this.  Here I can ``cancel out'' $x^2$:

$$\frac{x^5}{x^2} = x^3$$

What about $5^{\frac{1}{3}}$? By the beloved rule, we know that $5^{\frac{1}{3}}5^{\frac{1}{3}}5^{\frac{1}{3}}$ must equal $5^1$. Thus $5^{\frac{1}{3}} = \sqrt[3]{5}$.\index{exponents!fractions}

We say, for any $a$ and $b$ not equal to zero and any $c$ greater than zero,

$$a^{\frac{b}{c}} = a^b \sqrt[c]{a}$$

Before you go on to the exercises, note that the beloved rule demands a common base.
\begin{itemize}
\item We can combine these: $\left(5^2\right)\left(5^4\right) = 5^6$
\item We cannot combine: $\left(5^2\right)\left(3^5\right)$
\end{itemize}

With that said, we note that, for any $a$,$b$, and $c$:

$$\left(ab\right)^c = \left(a^c\right) \left(b^c\right)$$

So, for example, if I were asked to simplify
$\left(3^4\right)\left(6^2\right)$, I would note that $6 = 2 \times
3$, so

$$\left(3^4\right)\left(6^2\right) = \left(3^4\right)\left(3^2\right)\left(2^2\right)  = \left(3^6\right)\left(2^2\right)$$

If these ideas are new to you (or maybe they have been forgotten),
watch the Khan Academy's \textbf{Intro to rational exponents} video at
\url{https://youtu.be/lZfXc4nHooo}.


% \section*{Why $S^1$ is a double cover of the Mobius strip.}
% \newpage
\section{Galois covers}
\label{sec:GaloisCovers}

We  will assume that all our maps are simplicial and all our group actions are via simplicial maps.
For a space $X$, denote by $X_0$, $X_1$, $X_2$ the vertices, edges, and faces of $X$.
All our spaces are connected and locally finite.

We can construct covering maps using group actions.
A left group action of a group  $G$ on a space $Y$, denoted $G \groupaction Y$, is a collection of simplicial maps
\begin{align*}
  g \cdot (-) : Y &\longrightarrow Y
\end{align*}
for $g \in G$ satisfying
\begin{enumerate}
  \item ${\mathbb{1}} \cdot (-) = \id$,
  \item $g \cdot (h \cdot (-)) = (gh) \cdot (-)$.
\end{enumerate}
\begin{qbox}
  Show that a group always acts via isomorphisms i.e. $g \cdot (-) : Y \rightarrow Y$ is an isomorphism.
\end{qbox}

\begin{definition}
  We say that the action of $G$ on $Y$ is \emph{free} if the induced group action on sets $Y_0$, $Y_1$, and $Y_2$ is free.
  The \emph{quotient space} $Y/G$ is the space with vertices, edges, and faces given by $Y_0/G$, $Y_1/G$, and $Y_2/G$ respectively.
\end{definition}

\begin{ex}
  If $d | n$ then the cyclic group $\bbz/d$ acts freely on $nS^1$ and the quotient space is precisely $(n/d)S^1$.
\end{ex}

\begin{qbox}
  Check that if $G \groupaction Y$ is free then $Y \rightarrow Y/G$ is a cover.\tablefootnote{For groups acting via continuous maps (and not simplicial maps) it is not true that $Y \rightarrow Y / G$ is always a covering space. We further require the group action to be \emph{properly discontinuous}. Fortunately, a group action via simplicial maps is always properly discontinuous.}
\end{qbox}
\begin{definition}
  We say that a cover $p:Y \rightarrow X$ is \emph{Galois} if there exists a left group action $G \groupaction Y$ such that $X \cong Y/G$.
\end{definition}
This definition is less that ideal as it relies on the existence of an abstract group $G$.
We will find an equivalent criterion for $p:Y \rightarrow X$ to be Galois which is completely intrinsic to the cover $p$.

\subsection{Paths and covers}
For the rest of Section \ref{sec:GaloisCovers}, fix a connected cover $p: Y \longrightarrow X$.

\begin{definition}
  For a vertex $x$ in $X$, $p^{-1}(x)$ is the \emph{fiber} over $x$.
\end{definition}

A \emph{path} of length $k$ in $X$ is a finite sequence of edges $\gamma = e_1 e_2 \dots e_k$, where we allow inverses, such that $d_1 e_i = d_0 e_{i+1}$ for $1 \le i \le k-1$.
Define $d_0 \gamma = d_0 e_1$ and $d_1 \gamma = d_1 e_k$.
Denote by $\gamma^{-1}$ the reverse path $e_k^{-1} \dots e_2^{-1} e_1^{-1}$.
% Two paths $\gamma_1, \gamma_2$ with $d_1 \gamma_1 = d_0 \gamma_2$ can be concatenated to get a path $\gamma_1 \cdot \gamma_2$ from $d_0 \gamma_1$ to $d_1 \gamma_2$.
% For $x \in X$, we'll denote by $\mathbb{1}_x$ the ``path of length 0'' at $x$.

  \begin{theorem}[Unique lifting of paths]
    \label{theorem:uniqueLiftingPaths}
    For every vertex $x$ in $X$, every path $\gamma$ in $X$ starting at $x$, and every vertex $y$ in the fiber $p^{-1}(x)$, there exists a unique path $\widetilde{\gamma}$ in $Y$ such that
    \begin{align*}
      \widetilde{\gamma} & \mbox{ starts at } y, \\
      p (\widetilde{\gamma}) &= \gamma.
    \end{align*}
    $\widetilde{\gamma}$ is called a \emph{lift} of $\gamma$.
  \end{theorem}

  \begin{qbox}
    Pick a path $\gamma$ of length 5 in $S^1 \vee S^1$.
    Draw lifts of $\gamma$ starting at the three different vertices in cover $(10)$ in Figure \ref{fig:CoveringsOfS1S1}.
  \end{qbox}

  \begin{proof}[Proof of Theorem \ref{theorem:uniqueLiftingPaths}]
    Proof is by induction on the length of $\gamma$.

    \emph{Base case: length of $\gamma = 1$.}
    Let $\gamma = e$ with $d_0 e = x$.
    Because $p$ is a covering map, there is a neighborhood of $x$ that is evenly covered. Hence, there is a unique edge (possibly an inverse) $\widetilde{e}$ with $d_0 \widetilde{e} = y$ and $p(\widetilde{e}) = e$. Then $\widetilde{\gamma} = \widetilde{e}$ is the required lift.
    \begin{qbox}
      Complete the induction step.
    \end{qbox}
  \end{proof}

    \begin{corollary}
      \label{corollary:surjectivityOfCovers}
      $p:Y \rightarrow X$ is surjective.
    \end{corollary}
    \begin{qbox}
      Prove that $p:Y_0 \rightarrow X_0$ is surjective by lifting appropriate paths. (Optional: Extend this proof to edges and faces.)
    \end{qbox}
    \begin{corollary}
      \label{corollary:cardinalityOfFibers}
      Every path $\gamma$ from $x_0$ to $x_1$ in $X$ naturally defines a bijection
      \begin{align*}
        p^{-1}(x_0) \longrightarrow p^{-1}(x_1).
      \end{align*}
      Hence, the fibers over any two vertices $x_0$, $x_1 \in X_0$, have the same cardinality.
    \end{corollary}
    \begin{qbox}
      Prove Corollary \ref{corollary:cardinalityOfFibers} using the lift of an appropriate path and it's inverse.
    \end{qbox}

\subsection{Deck transformations}
% Our goal is to come up with a criterion for $p$ being Galois.
% There is a very intricate relation between covering spaces and paths in the base space.

\begin{definition}
  A \emph{deck transformation} of $p$ is a simplicial map $\varphi: X \rightarrow X$ that commutes with $p$ i.e. $p = p \circ \varphi$.
  \begin{equation*}
    \begin{tikzcd}
      Y \ar[rr, "\varphi"] \ar[rd, "p"'] & & Y \ar[ld,"p"] \\
      & X
    \end{tikzcd}
  \end{equation*}
\end{definition}

\begin{qbox}
  Show that deck transformations of $p$ form a group.
\end{qbox}
Let $\Gal(Y|X)$ denote the group of deck transformations of $p: Y \rightarrow X$.
There is a natural left action of the group $\Gal(Y|X)$ on the space $Y$.

\begin{ex}
  For example, the Galois groups of the covers $(1)$, $(3)$, $(5)$ of $S^1 \vee S^1$ in Figure \ref{fig:CoveringsOfS1S1} are $\bbz/2$, $\set{\mathbb{1}}$, $\bbz/3$ respectively.
\end{ex}

\begin{qbox}
  Find the group of deck transformations of the covers $(2)$, $(6)$, $(7)$, $(8)$, $(9)$, $(10)$, $(11)$ of $S^1 \vee S^1$ in Figure \ref{fig:CoveringsOfS1S1}.
  For each of these covers $Y$, find quotient $Y / G$ where $G=\Gal(Y| S^1 \vee S^1)$.
\end{qbox}

\begin{qbox}
  Prov that for any vertex $x \in X$ and every deck transformation $\varphi \in \Gal(Y|X)$, we have $\varphi(p^{-1}(x)) = p^{-1}(x)$.
  Hence, the deck transformations permute the fibers over $x$.\tablefootnote{
  One can think of this as shuffling a deck of cards, hence the name ``deck'' transformations.}
\end{qbox}

% \begin{ex}
%   If $G \groupaction X$ freely then every element $ g \in G$ defines a decktransformation of $p: X \rightarrow G \backslash X$.
% \end{ex}

\begin{theorem}
  \label{theorem:freenessGaloisAction}
  The action of $\Gal(Y|X)$ on $Y$ is free.
\end{theorem}
\begin{proof}
  We will show that if a deck transformation $\varphi \in \Gal(Y|X)$ does not act freely on $ Y$, then $\varphi$ fixes everything and hence is the identity element in $\Gal(Y|X)$.

  Suppose the action of $\varphi$ is not free. It suffices to assume that $g$ fixes some vertex, as if $\varphi$ fixes some edge or a face then it also fixes the vertices of the edge or the face respectively. Suppose $\varphi y_0 = y_0$ for $y_0 \in Y$.

  Consider another vertex $y$ in $Y$. Let $x_0 = p(y_0)$ and $x = p(y)$.
  \begin{qbox}
    Using a path $\gamma$ in $Y$ from $y_0$ to $y$ show that $\varphi$ fixes $y$, thereby completing the proof of the proposition.
  \end{qbox}
\end{proof}

\begin{corollary}
  \label{cor:deckTransforms}
  Let $y$ be a vertex in $Y$ and let $\varphi, \varphi' \in \Gal(Y|X)$ be two deck transformations. If $\varphi(y) = \varphi'(y)$ then $\varphi = \varphi'$. Hence, a deck transformation is completely determined by where it sends one vertex!
\end{corollary}
\begin{qbox}
  Prove this.\hint{Look at $\varphi^{-1} \circ \varphi'$.}
\end{qbox}

\begin{theorem}
  \label{theorem:GaloisCriterion}
  A cover $p:Y \rightarrow X$ is Galois if and only if $\Gal(Y|X)$ acts freely, transitively on each of the sets $p^{-1}(x)$ where $x$ is a vertex, an edge, or a face in $X$.
\end{theorem}
\begin{proof}
  This is equivalent to showing that $p:Y \rightarrow X$ is Galois if and only if for any two $y_1$, $y_2 \in p^{-1}(x)$ there is a unique deck transformation $g \in \Gal(Y|X)$ such that $g \cdot y_1 = y_2$.

  $(\Leftarrow)$ As $\Gal(Y|X)$ acts freely on $Y$, we can form the quotient $Y / \Gal(Y|X)$. Because the action is transitive, $X$ is isomorphic to $Y/G$.
  This proves one direction.

  $(\Rightarrow)$ Suppose $p$ is Galois and $X = Y/G$. We will show that the group of deck transformations of $p: Y \rightarrow Y/G$ is precisely $G$.
  Let $y$ be a vertex in $Y$ and let $x = p(y)$ be a vertex in $X$.
  By definition, The elements of $G$ act freely, transitively on the fiber $p^{-1}(x)$.
  By Corollary \ref{cor:deckTransforms} there can be no other deck transformations.
  Hence, $\Gal(Y|X) = G$.
  This proves the other direction.
\end{proof}

\begin{qbox}
  Which of the covers in Figure \ref{fig:CoveringsOfS1S1} are Galois?
\end{qbox}
\begin{qbox}
  Show that the 2-covers
  \begin{align*}
    \mbox{Cylinder} &\longrightarrow \mbox{Mobius Strip} \\
    \mbox{Torus} &\longrightarrow \mbox{Klein Bottle} \\
    \mbox{Sphere } S^2 &\longrightarrow \mbox{Real projective space}
  \end{align*}
  are all Galois.
\end{qbox}

Galois covers are completely symmetric covers.
By the evenly covered property of a covering space, small. neighborhoods of points in the fiber $p^{-1}(x)$ look the same as neighborhoods of $x$.
But in a Galois cover, the entire space $Y$ looks the same ``as seen from any point in the fiber''.
In general, an oject being Galois means that it is as symmetric as possible.

\begin{remark}
  The analogy with field theory is very clear here.
  We study field extensions $E \rightarrow F$ in the Galois extensions of fields.
  The deck transformations are replaced by automorphisms of $F$ which fix $E$, group quotients are replaced by fixed points.
  An extension is Galois precisely when $F^{\Gal(E|F)} = E$.
\end{remark}

\begin{figure}[p]
\centering
  \includegraphics[width=\textwidth]{coveringsOfS1S1.jpg}
  \caption*{Coverings of $S^1 \vee S^1$. Image from Algebraic Topology, Allen Hatcher, Chapter 1.}
  % \label{fig:CoveringsOfS1S1}
\end{figure}


\section{Introduction}

This short tutorial shows how to make a simple calculator.
The calculator will compute basic mathematical expressions (\verb|+, -, *, /|) possibly nested in parenthesis.
We assume the reader is familiar with regular expressions.

\section{Defining the grammar}

Expressions are defined with a grammar.
For example an expression is a sum of terms and a term is a product of factors. A factor is either a number or a complete expression in parenthesis.

We describe such grammars with rules. A rule describe the composition of an item of the language. In our grammar we have 3 items (Expr, Term, Factor). We will call these items `symbols' or `non terminal symbols'. The decomposition of a symbol is symbolized with $\to$.
The grammar of this tutorial is given in figure~\ref{tut:gramsymb_calc}.

\begin{tableau}
\caption{Grammar for expressions}                           \label{tut:gramsymb_calc}
\begin{tabular}{| l | p{7cm} |}
\hline
    Grammar rule & Description \\
\hline
\hline
    $Expr~\to~Term~(('+'|'-')~Term)*$
        & An expression is a term eventually followed with a plus ($'+'$) or a minus ($'-'$) sign and an other term any number of times ($*$ is a repetition of an expression 0 or more times). \\
\hline
    $Term~\to~Fact~(('*'|'/')~Fact)*$
        & A term is a factor eventually followed with a $'*'$ or $'/'$ sign and an other factor any number of times. \\
\hline
    $Fact~\to~number~|~'('~Expr~')'$
        & A factor is either a number or an expression in parenthesis. \\
\hline
\end{tabular}
\end{tableau}

We have defined here the grammar rules (i.e. the sentences of the language). We now need to describe the lexical items (i.e. the words of the language). These words - also called \emph{terminal symbols} - are described using regular expressions. In the rules we have written some of these terminal symbols ($+, -, *, /, (, )$). We have to define \emph{number}. For sake of simplicity numbers are integers composed of digits (the corresponding regular expression can be $[0-9]+$).
To simplify the grammar and then the Python script we define two terminal symbols to group the operators (additive and multiplicative operators). We can also define a special symbol that is ignored by TPG. This symbol is used as a separator. This is generaly usefull for white spaces and comments. The terminal symbols are given in figure~\ref{tut:token_calc}

\begin{tableau}
\caption{Terminal symbol definition for expressions}        \label{tut:token_calc}
\begin{tabular}{| l | l | l |}
\hline
    Terminal symbol & Regular expression & Comment \\
\hline
\hline
    number & $[0-9]+$ or $\backslash d+$ & One or more digits \\
\hline
    add & $[+-]$ & a $+$ or a $-$ \\
\hline
    mul & $[*/]$ & a $*$ or a $/$ \\
\hline
    spaces & $\backslash s+$ & One or more spaces \\
\hline
\end{tabular}
\end{tableau}

This is sufficient to define our parser with TPG. The grammar of the expressions in TPG can be found in figure~\ref{tut:recognizer}.

\begin{code}
\caption{Grammar of the expression recognizer}              \label{tut:recognizer}
\begin{verbatimtab}[4]
class Calc(tpg.Parser):
    r"""

    separator spaces: '\s+' ;
    token number: '\d+' ;
    token add: '[+-]' ;
    token mul: '[*/]' ;

    START -> Expr ;

    Expr -> Term ( add Term )* ;

    Term -> Fact ( mul Fact )* ;

    Fact -> number | '\(' Expr '\)' ;

    """
\end{verbatimtab}
\end{code}

\emph{Calc} is the name of the Python class generated by TPG. \emph{START} is a special non terminal symbol treated as the \emph{axiom}\footnote{The axiom is the symbol from which the parsing starts} of the grammar.

With this small grammar we can only recognize a correct expression. We will see in the next sections how to read the actual expression and to compute its value.

\section{Reading the input and returning values}

The input of the grammar is a string. To do something useful we need to read this string in order to transform it into an expected result.

This string can be read by catching the return value of terminal symbols. By default any terminal symbol returns a string containing the current token. So the token $'\backslash('$ always returns the string $'('$. For some tokens it may be useful to compute a Python object from the token. For example \emph{number} should return an integer instead of a string, \emph{add} and \emph{mul} should return a function corresponding to the operator. That why we will add a function to the token definitions. So we associate \emph{int} to \emph{number} and \emph{make\_op} to \emph{add} and \emph{mul}.

\emph{int} is a Python function converting objects to integers and \emph{make\_op} is a user defined function (figure~\ref{tut:make_op}).

\begin{code}
\caption{\emph{make\_op} function}                          \label{tut:make_op}
\begin{verbatimtab}[4]
def make_op(s):
    return {
        '+': lambda x,y: x+y,
        '-': lambda x,y: x-y,
        '*': lambda x,y: x*y,
        '/': lambda x,y: x/y,
    }[s]
\end{verbatimtab}
\end{code}

To associate a function to a token it must be added after the token definition as in figure~\ref{tut:tokens}

\begin{code}
\caption{Token definitions with functions}                  \label{tut:tokens}
\begin{verbatimtab}[4]
    separator spaces: '\s+' ;
    token number: '\d+' int ;
    token add: '[+-]' make_op;
    token mul: '[*/]' make_op;
\end{verbatimtab}
\end{code}

We have specified the value returned by the token. To read this value after a terminal symbol is recognized we will store it in a Python variable. For example to save a \emph{number} in a variable \emph{n} we write \emph{number/n}.
In fact terminal and non terminal symbols can return a value. The syntax is the same for both sort of symbols. In non terminal symbol definitions the return value defined at the left hand side is the expression return by the symbol. The return values defined in the right hand side are just variables to which values are saved. A small example may be easier to understand (figure~\ref{tut:ret_val}).

\begin{tableau}
\caption{Return values for (non) terminal symbols}          \label{tut:ret_val}
\begin{tabular}{| l | p{9cm} |}
\hline
    Rule & Comment \\
\hline
    \verb!X/x ->!           & Defines a symbol \emph{X}. When \emph{X} is called, \emph{x} is returned. \\
    \verb!Y/y!              & \emph{X} starts with a \emph{Y}. The return value of \emph{Y} is saved in \emph{y}. \\
    \verb!Z/z!              & The return value of \emph{Z} is saved in \emph{z}. \\
    \verb!$ x = y+z $!      & Computes \emph{x}. \\
    \verb!;!                & Returns \emph{x}. \\
\hline
\end{tabular}
\end{tableau}

In the example described in this tutorial the computation of a \emph{Term} is made by applying the operator to the factors, this value is then returned:

\begin{verbatimtab}[4]
    Expr/t -> Term/t ( add/op Term/f $t=op(t,f)$ )* ;
\end{verbatimtab}

This example shows how to include Python code in a rule. Here \verb!$...$! is copied verbatim in the generated parser.

Finally the complete parser is given in figure~\ref{tut:parser}.

\begin{code}
\caption{Expression recognizer and evaluator}               \label{tut:parser}
\begin{verbatimtab}[4]
class Calc(tpg.Parser):
    r"""

    separator spaces: '\s+' ;

    token number: '\d+' int ;
    token add: '[+-]' make_op ;
    token mul: '[*/]' make_op ;

    START -> Expr ;

    Expr/t -> Term/t ( add/op Term/f $t=op(t,f)$ )* ;

    Term/f -> Fact/f ( mul Fact/a $f=op(f,a)$ )* ;

    Fact/a -> number/a | '\(' Expr/a '\)' ;

    """
\end{verbatimtab}
\end{code}

\section{Embeding the parser in a script}

Since TPG 3 embeding parsers in a script is very easy since the grammar is the doc string\footnote{It may be a good pratice to use only raw strings. This will ease the pain of writing regular expressions.} of a class (see figure~\ref{tut:build_scheme}).

\begin{code}
\caption{Writting TPG grammars in Python}             \label{tut:build_scheme}
\begin{verbatimtab}[4]
import tpg

class MyParser(tpg.Parser):
    r""" # Your grammar here """

# You can instanciate your parser here
my_parser = MyParser()
\end{verbatimtab}
\end{code}

To use this parser you now just need to instanciate an object of the class \emph{Calc} as in figure~\ref{tut:calc}.

\begin{code}
\caption{Complete Python script with expression parser}     \label{tut:calc}
\begin{verbatimtab}[4]
import tpg

def make_op(s):
    return {
        '+': lambda x,y: x+y,
        '-': lambda x,y: x-y,
        '*': lambda x,y: x*y,
        '/': lambda x,y: x/y,
    }[s]

class Calc(tpg.Parser):
    r"""

    separator spaces: '\s+' ;

    token number: '\d+' int ;
    token add: '[+-]' make_op ;
    token mul: '[*/]' make_op ;

    START/e -> Term/e ;
    Term/t -> Fact/t ( add/op Fact/f $t=op(t,f)$ )* ;
    Fact/f -> Atom/f ( mul/op Atom/a $f=op(f,a)$ )* ;
    Atom/a -> number/a | '\(' Term/a '\)' ;

    """

calc = Calc()
expr = raw_input('Enter an expression: ')
print expr, '=', calc(expr)
\end{verbatimtab}
\end{code}

\clearpage

\section{Conclusion}

This tutorial shows some of the possibilities of TPG.
If you have read it carefully you may be able to start with TPG.
The next chapters present TPG more precisely.
They contain more examples to illustrate all the features of TPG.

Happy TPG'ing!


\chapter{Introduction to Modules}
\section{\textbf{Definition of Module}}
\begin{defn}  [\textbf{Left Module}]

 Let $ R $ be a ring with identity and $ M $ be an abelian group with addition. We say $ M $ is a left $R-$module if there exists a mapping\footnote{often called as scaler multiplication.}
\begin{equation*}
R \times M \rightarrow M
\end{equation*}
defined by
\begin{equation*}
(a \ , \ x) \rightarrow ax
\end{equation*}\marginnote[-2em]{$\forall \ a \in \ R$ and $x$ $\in \ M$}
satisfying following properties :
\begin{align}
(a+b) x =& ax + bx \\ a(x+y) =& ax + ay \\ (ab)x =& a(bx) \\ 1x =& x
\end{align}\marginnote[-7em]{\large{$\forall$ $ a\ , \ b \in R$ \newline $x \ , y \ \in M$}}
and denoted by $_{R}M$
\end{defn}
\bigskip
\begin{defn}[\textbf{Right Module}]
 Let $ R $ be a ring with identity and $ M $ be an abelian group with addition. We say $ M $ is a right $R-$module if there exists a mapping
\begin{equation*}
M \times R \rightarrow M
\end{equation*}
defined by
\begin{equation*}
(x \ ,\ a) \rightarrow xa
\end{equation*}
\marginnote[-1em]{$ \forall \ a$ $\in$ $R$ and $x$ $\in$ $M$} satisfying following properties\marginnote[4em]{\large{$\forall$ $ a\ , \ b \in R$ \newline $x \ , y \ \in M$}} :
\begin{align}
x (a+b)  &= xa + xb \\ (x+y) a &= xa + ya \\ x (ab) &= (xa)b \\ x1 &= x
\end{align}
and denoted by $M_{R}$.         \end{defn}

\subsection{Examples :}
\begin{enumerate}
\item Let $V$ be a vector space over a field $F$ then $V$ is a left as well as right $F-$Module.\newline \bigskip
\item Let $G$ be any abelian group under addition , then $G$ is a $\mathbb{Z-}$Module where $\mathbb{Z}$ is set of integers.\newline \bigskip
\item Let $R$ be ring and $M= R[x]$ \marginnote{Suppose ring $R$ is a field then $R-$Module $R[x]$ is a vector space over field $R$.} where $R[x]$ is a group of all polynomials with coefficents in $R$ then $M$ is a left as well as a right $R-$Module with scaler multiplication being usual multiplication.\newline \bigskip
\item Let $M$ be collection of all $m \times n $ matrices over ring $R$ , then $M$ is left $R-$Module where scaler multiplication being usual multiplication of a scaler to a matrix. \newline
\bigskip
In particular, if $M$ is a set of $1 \times n$ matrices over $R$ or $M = R^n$(set of $n-$tuples) then $R^n$ is a left $R-$module.
\end{enumerate}
\bigskip
\begin{remark}
	Let $R$ be a commutative ring then every left $R-$module can be transformed to right $R-$module and vice-versa.
	\end{remark}
\begin{proof} Let $M$ be left $R-$module and $R$ be a commutative ring. \newline
	so, $\exists$ a mapping
\begin{equation*}
R \times M \rightarrow M
\end{equation*}
defined by
\begin{equation*}
(a \ , \ x) \rightarrow ax
\end{equation*}
for each $a$ $\in$ $R$ and $x$ $\in$ $M$ satisfying following properties :
\marginnote{$\forall$ $ a\ , \ b \in R$ and $x \ , y \ \in M$  }
\begin{eqnarray*}
(a+b) x &=& ax + bx \\ a(x+y) &=& ax + ay \\ (ab)x &=& a(bx) \\ 1x &=& x
\end{eqnarray*}
$\because \ R$ is a commutative ring.\newline
Now, Define an another mapping
 \begin{equation*}
 M \times R \rightarrow M
 \end{equation*}
 defined by
 \begin{equation*}
 (x \ ,\ a) \rightarrow x*a \ = \ ax
 \end{equation*}
To check $M$ is a right $R-$Module , we need to verify properties number \eqref{eq1.5}-\eqref{eq1.8}
 \begin{description}
 	\item[(i) Distribuitive Law]
 	\begin{align*}
 		x*(a+b) &= (a+b)x \\ &= ax + bx \\ &= (x*a) + (x*b)
 	\end{align*}
 	\item[(ii) Distributive Law] \begin{align*}
 		(x+y)*a &= a(x+y) \\ &= ax + ay \\ &= (x*a) + (y*a)
 	      \end{align*}
       \item[(iii)]  \begin{align*}
       x*(ab) &= (ab)x \\ &= (ba)x \\ &= b(ax) \\ &= (ax)*b
       \end{align*}
   \item[(iv)] \begin{align*}
   x*1 &= 1x \\  &= x
   \end{align*}
Thus, $_{R}M$ is transformed to $M_R$.\newline
Similarly, Converse statement can be verified.
\end{description}
\end{proof} \bigskip
\begin{remark}
	Let $S$ be a subring of ring $R$ then $_{S}M$ exists \marginnote{by existance means $M$ is a valid left module over mentioned ring or subring. i.e. satisfying those four properties.}  only if $_{R}M$ exists.
\end{remark} \bigskip
\begin{remark}
	Same Abelian group\marginnote{For Instance,  The field $\mathbb{R}$ is $\mathbb{R}-$module,$\mathbb{Q}-$module and $\mathbb{Z}-$module.} can have the structure of a Module for a number of different rings.
\end{remark} \bigskip
\begin{remark}
Let $I$ be left ideal of $R$ then quotient ring $\bigslant{R}{I}$ is a left $R$-module.\marginnote{Here scaler multiplication is \newline \begin{equation*}
	R \times \bigslant{R}{I} \rightarrow \bigslant{R}{I}
	\end{equation*}
defined as
\begin{equation*}
(a \ , \ x+I) \rightarrow ax+I
\end{equation*}

$\forall \ a \in R$ and $\forall \ x+I \in \bigslant{R}{I}$}

\end{remark}
\begin{proof}[verification:]
	Left to reader\newline \bigskip
	\textbf{Hint:} you need to verify those four properties: \eqref{eq1.1}-\eqref{eq1.4}
\end{proof}
\bigskip

\begin{thm}{\textbf{(Elementry Properties:)}}\newline
	Let $M$ be a left $R$-module . Suppose $0_m \ \text{and} \ 0_r$ denotes additive identities of $M$ and $R$ respectively. Then,  for each $x \ \in M$ and $r \ \in R$ \newline
\begin{description}
\item (i)
	\begin{equation*}
	0_m = 0_r\ x = r\ 0_m
	\end{equation*}
\item (ii)
	\begin{equation*}
	r(-x) =  (-r)x = -rx
	\end{equation*}
\end{description}
\end{thm}
\begin{proof}
	\begin{description}
		\item[(i)]
As $0_m$ is the additive identity of $M$. so, $0_m = 0_m + 0_m$\newline
Consider \marginnote{$ \because \ (r\ ,\ 0_m)\rightarrow r\ 0_m \in M$\newline so, $r\ 0_m = r\ 0_m + 0_m$}
 $ r(0_m + 0_m) = r\ 0_m  = r\ 0_m +0_m $\newline
but, $r(0_m + 0_m) = (r\ 0_m) +(r\ 0_m)$ \marginnote{
	$ \because \ M$ is a left $R$-module.\newline (using distribuitive property)}\newline
so, we have \begin{equation*}
r\ 0_m +r\ 0_m = r\ 0_m + 0_m
\end{equation*}
as ($M,+$) is an abelian group so left and right cancellation law holds.
\begin{eqnarray*}
\cancel{r\ 0_m} +r\ 0_m &=& \cancel{r\ 0_m} + 0_m \\ r\ 0_m &=& 0_m
\end{eqnarray*}
a similiar argument can be used to prove $0_m = 0_r\ x$.
\item[(ii)]
as $M$ is a left $R$-module so $(r \ , x )\ \rightarrow rx \in M$ \newline
Now, Consider $(-r)x + rx$
\begin{eqnarray*}
\text{using distribuitive law} \\ (-r)x + rx &=& (-r + r)x \\  &=& 0_r \ x \\ &=& 0_m
\end{eqnarray*}
i.e. $(-r)x$ is additive inverse of  $(rx)$ but additive inverse of $(rx)$ is $-rx$ and it is unique for an abelian group($M$ here)
\begin{equation*}
\therefore \ (-r)x = -rx
\end{equation*}
a similar argument can be used to prove that $r(-x)  = -r x$.
\end{description}
\end{proof}
\bigskip
\begin{defn}[ \textbf{Ring Homomorphism}]
	Let\marginnote{often called as ring homo} $R$ and $S$ be two rings with identities $1_r \ , 1_s$ respectively then a map(say $f$)
	\begin{equation*}
	f : R \rightarrow S
	\end{equation*}
	is said to be a ring homomorphism or ring linear map if for every $a \ ,\ b \in R$ following properties holds\marginnote[-2.55em]{if $R$ = $S$ then we call ring homo as ring endomorphism. For instance , let $f$ be ring homo from $R$ to $R$ . we say $f$ is endomorphism of $R$ and denoted by $End \ R$}
	\begin{description}
		\item[(i) \centering{Preserves Addition}]\begin{equation*}
		(a+b)f = (a)f +(b)f
		\end{equation*}
		\item[(ii) \centering{Preservers Multiplication} ]\begin{equation*}
		(ab)f = (a)f . (b)f
		\end{equation*}
		\item[(iii) \centering{ Maps identity to identity}]\begin{equation*}
		(1_r)f = 1_s
		\end{equation*}
	\end{description}
\end{defn}
\begin{remark}
	Such a mapping need not to be bijective. if it is bijective then we say it is a ring isomorphism or rings are isomorphic.
\end{remark}
\bigskip
\begin{thm}
	Let\marginnote{\[ M \ \text{is a right R-module} \] \[\centering\Updownarrow \] \[\newline\exists \ f: R \ \xrightarrow[\text{Homo}]{\text{Ring}} End \ M \] } $R$ be a ring and $M$ be any abelian group with addition. then $M$ is a right $R$-module if and only if there exists a map which is ring homomorphism from $R$ to $End \ M$
\end{thm}
\begin{proof}
\begin{description}
	\item[(Forward Part)\newline]
	Let us suppose that $ M $ is a right $ R $-module.\newline
	\textbf{Claim:} there exists a map which is ring homomorphism from $R$ to $End \ M$\newline
   $ \because \ M  $ is a left $ R $-module , so there exist a map\newline
   \[ f: M \times R \rightarrow M  \]
   defined by
   \[ (x \ , a) \rightarrow ax \]
   satisfying following properties:
    \begin{align*} (x+y)a &= (x)a+(y)a \\
     x(a+b)\mathnote{ $$\forall \ x , y \ \in M \ \&  \ a ,b \in R$$ } &= xa + xb \\
     x(ab) &= (xa)b \\
     x 1 &= x
     \end{align*}
   for each $ a \in R $ , define a map(say $\phi_a $)
   \[ \phi_a: M\rightarrow\ M \]
   such that for each $x\in  M$
   \[ (x )\phi_a = xa \in \ M \]
   Now, we'll show that $ \phi_a \in \ End \ M $\newline
   Let $ x , y \in M $ \newline Consider  $  (x+y)\phi_a$
   \begin{align*}
   	&= (x+y)a  \\ &= xa + ya  \\ &= (x)\phi_a + (y)\phi_a
   \end{align*}\marginnote[-5.5em]{using defination of $\phi_a$} \marginnote[-4em]{using \eqref{eq1.9}}
   so, $\phi_a$ preserves addition and is a group homo from $M$ to $M$.
   \newline i.e. $\phi_a \in End \ M$ \newline
   Now, we can define a map (say $f$)
   \begin{align*}
   &f : R \rightarrow End \ M \\ \text{defined as} \\&(a)f \rightarrow \phi_a \mathnote{$\forall a \in R$ and $\phi_a \in End \ M$}
   \end{align*}
Now, We'll show that $ f $ is a ring homomorphism.\newline
\begin{description}
	\item[(A)]
	  \begin{align*}
	(a+b)f &= \phi_{a+b}
	\mathnote{\[ \text{for each}\  x \in M \ \text{we have,}\] \begin{align*}
		(x)\phi_{a+b} &= x(a+b) \ =xa+xb \\ &=(x)\phi_a +(y)\phi_b \\ \therefore \ \phi_{a+b} &= \phi_a +\phi_b
		\end{align*}}
		  \\  &= \phi_a +\phi_b \\&= (a)f +(b)f
	\end{align*}
    \item[(B)] \begin{align*}
    (ab)f &= \phi_{ab}\mathnote{\[ \text{for each}\  x \in M \ \text{we have,}\] \begin{align*} (x)\phi_{ab} &= x(ab)   = (xa)b \\ &= (xa)\phi_b = (x)\phi_a \circ\phi_b \\ \therefore \ \phi_{ab} &= \phi_a\circ\phi_b \end{align*} } \\  &= \phi_a\circ\phi_b \\&= (a)f\ (b)f
    \end{align*}
\item[(C)] \begin{align*}
(1)f\mathnote{\[ \text{for each}\  x \in M \ \text{we have,}\] \begin{align*} (x)\phi_{1} &= x(1) \\&=x \end{align*}\[ \therefore \ \phi_{1} \ \text{is identity of}End \ M \]} &= \phi_{1}
\end{align*}

   \end{description}
\bigskip
Thus, Forward Part is proved.\newline\bigskip
\item[(Converse Part)]
\bigskip
Assume that $\exists$ a ring homo.( say $f$)
\[ f: R\xrightarrow[\text{Homo}]{\text{Ring}} End \ M \]
for any $a \in R$,we denote the $(a)f$ by $f_a \in End \ M$\newline
\textbf{Claim:} $M$ is a right $R$-module.\newline
so let's define a map
\[ R\times M \longrightarrow M \] defined by
\[ (a , x ) \rightarrow x*a = (x)f_a \]
to prove $M$ is a right $R$-module , we need to verify four properties $\eqref{eq1.5}$- $\eqref{eq1.9}$ of right $R$-module.
\begin{description}
	\item[(i)]
\end{description}
\begin{align*}
(x+y)*a &= (x+y)f_a \\& = (x)f_a +(y)f_a \mathnote{\[ \because\ f_a \ \in End \ M \]}\\& = x*a + y*a
\end{align*}
   \item{(ii)}
   \begin{align*}
   x*(a+b) &= (x)f_{a+b} \\ &= (x)(f_a + f_b) \mathnote{\[ \because\ f_a \ , \ f_b \in End \ M \]} \\&=(x)f_a + (x)f_b
 \\ &= (x*a) + (x*b)   \end{align*}
 \item{(iii)}
 \begin{align*}
 x*(ab) &= (x)f_{ab} \\ & = (x)f_a\circ f_b \\&=(x f_a)f_b \\&= (x*a)*b
 \end{align*}
 \item{(iv)}
 \[ x*1 = (x)f_1  = x\]\marginnote{\[ \because\ f_1 \text{is identity in} End \ M \]}
Thus, $ M $ is a right $R$-module.
\end{description}
\end{proof}
\begin{definition}[\textbf{Anti-Ring Homomorphism}]
	Let $R$ and $S$ be two rings with identities $1_r$ and $1_s$ respectively. Define a map $f$
	\[ f : R \rightarrow S \] satisfying following properties, for each $a , b \in R$ \newline
	\begin{description}
		\item[(i)] \[ (a+b)f = (a)f +(b)f \]
		\item[(ii)] \[ (ab)f  = (b)f\ (a)f \]
		\item[(iii)] \[ (1_r)f = 1_s \]

	\end{description}
	 Then, $f$	is called anti-ring homomorphism.
\end{definition}
\begin{thm}
	Let\marginnote{\[ M \ \text{is a left R-module} \] \[\centering\Updownarrow \] \[\newline\exists \ f: R \ \xrightarrow[\text{Homo}]{\text{Anti-Ring}} End \ M \] } $R$ be a ring and $M$ be any abelian group with addition. then $M$ is a left $R$-module if and only if there exists a map which is anti-ring homomorphism from $R$ to $End \ M$.
\end{thm}
\begin{proof}
	Left to reader.
\end{proof}
\bigskip
\begin{definition}[\textbf{SubModule}]
	Let $M$ be a left (right) $R$-module then a subset $N$ of $M$ is called a submodule of $M$ if \underline{$N$ is a left (right) $R$-module} \underline{under the operation induced from $M$.}\newline \bigskip
	In other words, A subset $N$ of $M$ is called submodule of $M$ if
	\begin{description}
		\item[(i)] $N$ is subgroup of $M$.
		\item[(ii)] $N$ is closed under induced scaler multiplication from $M$.
	\end{description}
\end{definition}
\bigskip
\begin{thm}[\textbf{Criterion for Checking Modules}]

	Let $M$ be a left (right) $R$-module and $N$ be a subset of $M$ then $N$ is a submodule of $M$ if and only if
	\begin{description}
		\item[(i)]
		\marginnote[2.5em]{\[ \forall \ x , y  \in N \] } \[ x-y \in N \]
		\item[(ii)]
		\marginnote[2.5em]{\[ \forall \ a \in R \ \&\ x \in N \]} \[ a x \in N \]
	\end{description}
\end{thm}
\begin{proof}
	Left to reader.
\end{proof}
\bigskip
\subsection{Examples:}
\begin{enumerate}
	\item As every Vector Space $V$ over a Field $F$ is a $F$-module. So, submodules of $V$ are subspaces of $V$.
	\item As every abelian group $G$ is a $\mathbb{Z}$-module. So, all subgroups of $G$ are submodules.
	\item Let $R$ be a ring then $R$ is a left as well as right $R$-module then left (right) ideals of $R$ are left (right) submodules of $R$.
	\item $\left\{0\right\}$ and $M$ are trivial submodules of any left (right) $R$-module $M$.
\end{enumerate}
\bigskip
\begin{remark}\qquad
	\begin{enumerate}
		\item Union of two submodules need not to be a submodule.\marginnote{Think an example !}

		\item Intersection of any number of submodules is again a submodule.\marginnote{\textbf{Hint:} Verify using criterion for checking modules.}
	\end{enumerate}
\end{remark}
\bigskip

\begin{remark}\textbf{(Smallest Submodule containing a set)}\newline
	  		Let $M$ be any left (right) $R$-module and $S$ be any subset of $M$. Suppose $\mathcal{F}$ be the family of all submodules of $M$ containing $S$. \[  \text{Let} \; P=\bigcap_{N \in \mathcal{F}}N  \] then $P$ is a submodule of $M$ containing $S$ as being intersection of an indexed family of submodules containing $S$.\newline \bigskip Moreover, $P$ is the smallest submodule of $M$ containing $S$. i.e. for any arbitrary submodule $K \in \mathcal{F}$ , we have $ P \subseteq K$. Such submodule $P$ of $M$ is said to be generated by set $S$ and is denoted by \[ P = \left\langle S \right\rangle  = (S) \]
\end{remark}
\bigskip
\begin{remark}\qquad
	\begin{description}
	\item Let $S$ be any subset of left $R$-module $M$ and $\left\langle S \right\rangle $ is the smallest submodule of $M$ containing $S$.\newline
	\begin{enumerate}
		\item if $S$ is non-empty and finite , $S = \left\lbrace x_1,x_2,x_3, \cdots , x_n \right\rbrace $ \[ \left\langle S \right\rangle = \left\langle \left\lbrace x_1,x_2,x_3, \cdots , x_n \right\rbrace \right\rangle  = \left\langle x_1,x_2,x_3, \cdots , x_n \right\rangle \] is said to be a finitely generated by $S$ and is smallest submodule of $M$ containing $S$.
		\item if $S = \phi$ \quad i.e. $S$ is an empty set \[ \left\langle S \right\rangle = \left\langle \phi \right\rangle = \left\lbrace 0 \right\rbrace \]
		\item if $S = \left\lbrace a\right\rbrace $ \quad i.e. $S $ is singleton then $\left\langle S \right\rangle = \left\langle a\right\rangle $ is said to be a \underline{cyclic submodule}.
	\end{enumerate}
\end{description}
\end{remark}
\bigskip
\begin{definition}[\textbf{Cyclic module}]   \cite{Cohn2005}
	A module $M$ is said to be a cyclic module if it can be   generated by a single element.
\end{definition}
\textit{For Example:}
	A ring $R$ over itself is a module and can be generated by identity element $ \left\lbrace 1\right\rbrace $ so is a cyclic module.
\bigskip
\begin{thm}
	Let $M$ be left $R$ module and $S$ being any subset of $M$.
	\begin{equation*} \left\langle S\right\rangle = \begin{cases}
	\left\lbrace 0\right\rbrace & \text{if $S = \phi$} \\ \left\lbrace \sum\limits_{i \in J_n} a_i x_i \ \middle\vert \  a_i \in R \ , x_i \in S\right\rbrace  & \text{otherwise}
	\end{cases}
	\end{equation*}
\end{thm}
\begin{proof}
\begin{description}
	\item[Case-I] Let us suppose that $S = \phi $ ,as $ \left\langle S\right\rangle $ is the intersection of all the submodules of $ M $ containing $S$\marginnote[-2em]{i.e. Every submodule of $M$ will contain $S$}. \newline \bigskip In particular, $ \left\lbrace 0\right\rbrace  $ also contains $S$ i.e. \[ \left\lbrace 0\right\rbrace  \in\mathnote{$\because \ \mathcal{F} \ \text{is a collection of all submodules of}\ M \newline \text{containing}\ S$ } \mathcal{F}  \]
	so, \begin{align*} \left\langle S\right\rangle &= \bigcap_{N \in \mathcal{F}}N  \\& = \left\lbrace 0\right\rbrace   \end{align*}
    \item[Case-II] Suppose $S$ is non-empty and let    \[ P = \left\lbrace \sum\limits_{i \in J_n} a_i x_i \ \middle\vert \  a_i \in R \ , x_i \in S\right\rbrace\]
         First , we'll show that $S\subseteq P$ \newline
         Let $x \in\ S$ then it can be expressed in following form:
         \[x = 1.x = \sum\limits_{i \in J_1} a_i x_i \] \marginnote[-2.5em]{with $a_1 = 1$ and $x_1 = x $}
         \[\therefore x \in  P \Rightarrow S \subseteq P \]  \marginnote[-2em]{$\because x$ was chosen arbitirary.}
         Now ,we'll show that $P$ is a submodule of $M$ using submodule criterion.           \newline
         Let $u\ ,\ v \in P$ . so, we need to show $u + \alpha v \in P$ \marginnote{for any $\alpha\in R$}
         \[u = \sum\limits_{i\in J_n} a_i x_i\] \marginnote[-2em]{$\forall x_i \in S \ \&\ a_i \in R$}
          \[v = \sum\limits_{j\in J_m} b_j y_j\]  \marginnote[-2em]{$\forall y_j \in S \ \&\ b_j \in R$}
          define, for any $\alpha \in R$
          \begin{align*} z_k = x_k \qquad ,\qquad c_k = a_k     \mathnote{$k \in J_n$}  \\
           z_{k+j} = y_j \qquad , \qquad c_{k+j} = \alpha b_j    \mathnote{$j \in J_m$}  \end{align*}
          Thus, we have
           \begin{align*}
            u+ \alpha v &= \sum\limits_{i\in J_n}a_i x_i + \alpha \sum\limits_{j\in J_m}b_j y_j  \\
             & =\sum\limits_{i\in J_n}a_i x_i + \sum\limits_{j\in J_m}\alpha b_j y_j  \\
             &= \sum\limits_{k\in J_n}c_k z_k + \sum\limits_{k = n+1}^{n+m} c_k z_k  \\
             &=  \sum\limits_{k \in J_{n+m}} c_k z_k
          \end{align*}
          so, $P$ is a submmodule of $M$ containing $S$.
          \newline Now, we'll show that $P$ is \underline{smallest} submmodule of $M$ containing $S$.
          \newline \bigskip
          Let $K$ be any arbitirary submodule of $M$ containing $S$
           \[\text{i.e.} \ K \ \in \mathcal{F}\]
          $\because  \ \ \ K $ is a submodule and $S \subseteq K$ \newline
          $\therefore \  K$  is closed under scaler multiplication and addition.
          \[\text{i.e}\qquad \sum\limits_{i \in J_n} a_i x_i  \in K \]  \marginnote[-2.5em]{$\forall \ a_i \in R \ \& \ x_i \in S $}
          so , \[P =\left\langle S\right\rangle \subseteq K \]
               Hence,  $P$ is smallest submmodule of $M$ containing $S$.
           \end{description}

\end{proof}
\bigskip
\begin{defn}[\textbf{Generating Set / Set of Generators}]
A set of generators for a left (right) $R$-module $M$ is a subet $S$ of $M$ such that
\[M = \left\langle S\right\rangle \]
if no proper submodule of $M$ contains $S$ then $S$ generates $M$ (verify ?)
\end{defn}
\bigskip
\subsection{Examples}
\begin{description}
  \item[1.] A   ring $R$ considered as left (right) $R$-module is generated by identity element $\lbrace1\rbrace$

  \item[2.] $\mathbb{Z}\times \mathbb{Z}$  over $ \mathbb{Z}  $ can be generated by
  \[S =\left\lbrace(0,1),(1,0)\right\rbrace\]
  \item[3.] All finite dimensional vector space can be generated by it's basis (finite), so is finitely generated submodule.
  \item[4.] Let $R$ be a ring, $I$ be left(right) ideal of $R$ then it is a left(right) $R$-module. So, every  finitely  generated left(right) ideals of $R$ are finitely generated submodule.
  \item[5.] A submodule of left $R$-module is cyclic iff it is prinicipal ideal of $_RR$.
\end{description}
\bigskip
\begin{defn}
  Let $M$ be a left $R$-module and $\left\lbrace N_\alpha\right\rbrace_{\alpha \in \Omega }$ \marginnote{where $\Omega$ is indexing set. } be family of submodules of $M$ then sum $\sum\limits_{\alpha \in \Omega } N_\alpha $ is defined to be a submodule of $M$ generated by $\bigcup\limits_{\alpha \in \Omega}N_\alpha $  \[\left\langle \bigcup_{\alpha \in \Omega}N_\alpha \right\rangle = \sum\limits_{\alpha \in \Omega } N_\alpha \] \bigskip
   Moreover, $\sum\limits_{\alpha \in \Omega } N_\alpha $ is smallest submodule of $M$ containing $N_\alpha $ \marginnote[-2em]{for each $\alpha \in \Omega$}
  \end{defn} \bigskip
  \begin{prop}
    Let $M$ be a left $R$-module and $\left\lbrace N_\alpha\right\rbrace_{\alpha \in \Omega }$ \marginnote{where $\Omega$ is indexing set. } be family of submodules of $M$ then sum \[\sum\limits_{\alpha \in \Omega } N_\alpha =\left\lbrace \sum\limits_{\alpha \in \Omega } x_\alpha \middle\vert\, x_\alpha \in N_\alpha \quad ,\  x_\alpha = 0 \; \textmd{for almost all} \; \alpha  \right\rbrace \] \marginnote[-2em]{for each $\alpha \in \Omega$}
    \begin{proof}
      Let \[P = \left\lbrace \sum\limits_{\alpha \in \Omega } x_\alpha \middle\vert\, x_\alpha \in N_\alpha \quad , \ x_\alpha = 0 \; \textmd{for almost all} \; \alpha\right\rbrace \]
      We need to show that $P$ is smallest submodule of $M$ containing each $N_\alpha$
      \newline  \bigskip
      \textbf{Claim 1 :}.  \qquad $P$ is submodule of $M$  \newline Clearly, $P$ is non-emptpy. Taking $x_\alpha = 0$ for each $\alpha \in \Omega$, we have \[\Rightarrow0 \in P\] Also, for a fixed but arbitirary $\alpha \in \Omega $ \newline Let $x\in N_\alpha$ and  choose \[ x_i = \begin{cases}
                                 x, & \mbox{if } i =\alpha \\
                                 0, & \mbox{otherwise}.
                               \end{cases}\]
            so $x =\sum x_i \in P$  we have $N_\alpha \subseteq P \qquad \forall \alpha \in \Omega$ \marginnote{$\because \ \alpha$ was arbitrary chosen}
      \newline  \bigskip
      Now , we'll show that $P$ is submodule of $M$ using submodule criterion.\newline
      \begin{description}
        \item[\textbf{$P$ is closed under addition and scaler multiplication}]   Let $u\ , \ v$ be two elements of $P$
        \[u = \sum_{\alpha} x_\alpha \] \marginnote[-2.5em]{where $x_\alpha \in N_\alpha$ and \newline $x_\alpha = 0$ for almost all $\alpha$}
        \begin{align*} v &= \sum_{\beta} y_\beta \mathnote{where $y_\beta \in N_\beta$ and \newline $y_\beta = 0$ for almost all $\beta$}
       \end{align*} \newpage
        Let $\Omega_1$ ,  $\Omega_2$ be finite subsets of  $\Omega$ for which  $x_\alpha$ and $y_\beta$ are non-zero respectively.
        \[x_\alpha = \begin{cases}
           \text{non-zero}, & \mbox{if } \alpha \in \Omega_1 \\
          0, & \mbox{otherwise}.
        \end{cases} \qquad , \qquad y_\beta = \begin{cases}
          \text{non-zero}, & \mbox{if } \beta \in \Omega_2 \\
          0, & \mbox{otherwise}.
        \end{cases} \]
        Also for any arbitirary scaler $c \in R$ , define
        \[z_r = \begin{cases}
                  x_r, & \mbox{if } r \in \Omega_1 \\
                  c y_r, & \mbox{if } r \in \Omega_2.

                   \end{cases} \qquad \Rightarrow z_r = x_r + c y_r \qquad \forall r\ \in \Omega_1 \cap \Omega_2\]
        Now ,  \begin{align*}u + c v & = \sum_{\alpha} x_\alpha + c \sum_{\beta} y_\beta \\ & = \sum_{\alpha \in \Omega_1} x_\alpha + c \sum_{\beta \in \Omega_2} y_\beta \\ & = \sum_{\alpha \in \Omega_1} x_\alpha +  \sum_{\beta \in \Omega_2} c y_\beta \\& = \sum_{r \in \Omega_1} x_r +  \sum_{r \in \Omega_2} c y_r + \sum_{r \in \Omega_1 \cap \Omega_2} (x_r + c y_r)      \\ \text{Thus , We have}\\ u+cv &= \sum_{r \in \Omega_1 \cup \Omega_2} z_r   \in P \mathnote{$z_r = 0 \quad \text{for almost all } r \newline \because \Omega_1 \cup \Omega_2 \text{ is also finite.}$}
        \end{align*}
         \end{description}
      \textbf{Claim 2 :}.  \qquad $P$ is smalleat submodule of $M$ containing each $N_\alpha$. \newline \bigskip
      Let $N$ be any submodule of $M$ containing each $N_\alpha$ \newline $\therefore \ N$ is closed under addition   so $N$ contains all finite sum of the form $\sum\limits_{\alpha}x_\alpha $  where $ x_\alpha \in N_\alpha \quad \& \quad x_\alpha = 0 \ ,\text{for almost all }\alpha $ \newline  It follows that  $P \subseteq N$     \marginnote{$\because \ N$ was chosen arbitirary}
      \newline \bigskip Thus, $P$ is smallest submodule of $M$ containing each $N_\alpha$ \end{proof}   \end{prop}
      \bigskip
      \begin{defn}[\textbf{Maximal Submodule}]
      Let $N$ be a submodule of left $R$-module $M$ then $N$ is said to be a maximal submodule of $M$ if there does not exist any proper submodule of $M$.\newline\bigskip
      In other words , for any sumodule $K$ of $M$ satisfing
      $N\subseteq K \subseteq M$ \newline we must have \[\text{either  } N = K \quad \text{or  } K = M  \] for $N$ to be a maximal submodule of $M$.
      \end{defn}
                   \bigskip

      \begin{thm}
        Let $M$ be a finitely generated left $R$-module then every proper submodule of $M$ is contained in maximal submodule of $M$.\newline In particular , if $M$ is non-trivial then $M$ contains a maximal submodule.
      \end{thm}
       \begin{proof}
         Left to Reader.
       \end{proof}
       \bigskip
       \begin{remark}
         $\mathbb{Q} $ is not finitely generated $\mathbb{Z}$-module.
       \end{remark}
       \begin{description}
         \item[Verification:] Let  $\mathbb{Q} $ is finitely generated over $\mathbb{Z}$ by
         \[ \left\lbrace\frac{p_i}{q_i} \ \middle\vert\ p_i , q_i \in \mathbb{Z} \ , \ q_i \neq 0 \quad \forall \ i \in J_n\right\rbrace \]      Without loss of generality , Assume that \[q_1 , q_2 , q_3 , \cdots , q_n > 0\] then we can always choose an integer (say $k$) such that
         \[k = q_1  q_2  q_3  \cdots  q_n > 0 \]
         <incomlete>
       \end{description}


\subsection{Variance analysis in backward propagation phase}
Recall the loss function
$$
L(\theta)=\mathbb{E}_{(x, y) \sim D} \ell \left(\operatorname{softmax}\left(f^{L}\right), y\right),
$$
where $ f^{L}(x; \theta) $  is the DNN function defined by
$$
\left\{\begin{array}{l}f^{1}(x)=W^{1} x+b^{1} \\ f^{l}(x)=W^{l} \sigma\left(f^{l-1}(x)\right)+b^{l} \quad \forall l=2, \cdots L\end{array}\right. .
$$
Then we have the following backward propagation ("BP") formula
$
\frac{\partial L(\theta)}{\partial W^{l}}=\frac{\partial L}{\partial f^{l}} \cdot \frac{\partial f^{l}}{\partial W^{l}},
$
where
$\frac{\partial L}{\partial t^{l}} \in \mathbb{R}^{n_e}, \frac{\partial f}{\partial W^{l}} \in \mathbb{R}^{n_{e} \times\left(n_{e} \times n_{e-1}\right)}$. More Precisely,
$$
\frac{\partial L(\theta)}{\partial W_{s t}^{l}}=\sum\limits_{i=1}^{n_{l}}\left(\frac{\partial L(\theta)}{\partial f_{i}^{l}} \cdot \frac{\partial f_{i}^{l}}{\partial W_{s t}^{l}}\right).
$$
Assume that
\begin{enumerate}
\item $\left\{\frac{\partial L(\theta)}{\partial f_{i}^{l}} \cdot \frac{\partial f_{i}^{l}}{\partial W_{s t}^{L}}\right\}_{i=1}^{n_{e}}$ are independent
\item For each i,   $ \frac{\partial L(\theta)}{\partial f_{i}^{l}}  $ and $\frac{\partial f_{i}^{l}}{\partial W_{s t}^{l}}$ are independent
\end{enumerate}
Actually, we can not such make general assumptions as $L(\theta), f_{i}^{l}, \frac{\partial f_{i}^{l}}{\partial W_{st}} \frac{\partial L(\theta)}{\partial f_{i}^{l}}$   are all fixed. We still make these assumption here to get some idea of the choice of $W_{s t}^{l}$.
\begin{lemma}\label{th:idnormal2}
If $\sigma =id$ and  the above assumption holds,
$$\mathbb{V}\left[\frac{\partial L (\theta)}{\partial W_{s t}^{l}}\right] = \prod\limits_{j=l+1}^{L-1} n_{j} \mathbb{V}\left[W_{s t}^{j}\right] \left(\mathbb{V}\left[W_{s t}^{L}\right]\sum\limits_{k=1}^{n_{L}} \mathbb{E}\left[\left(\frac{\partial L(\theta)}{\partial f_{k}^{2}}\right)^{2}\right]\right)
\prod\limits_{j=2}^{l-1} n_{j} \mathbb{V}\left[W_{s t}^{j}\right] \left(\mathbb{V}\left[W_{s t}^{1}\right]\sum\limits_{R=1}^{d} \mathbb{E}\left[ X_{k}^{2}\right]\right).
$$
\end{lemma}
\begin{proof}
The assumption leads to
\begin{equation}\label{normale0}
\mathbb{V}\left[\frac{\partial L(\theta)}{\partial W_{st}^{l}}\right]=\sum\limits_{i=1}^{n_{l}}\left( \mathbb{E}\left[\left(\frac{\partial L(\theta)}{\partial f^{l}_{i}}\right)^{2}\right] \mathbb{E}\left[\left(\frac{\partial f_{i}^{l}}{\partial W_{s t}^{l}}\right)^{2}\right] - \left(\mathbb{E}\left[\frac{\partial L(\theta)}{\partial f_{i}^{l}}\right] \mathbb{E}\left[\frac{\partial f_{i}^{l}}{\partial W_{s t}^{l}}\right]\right)^{2}\right) .
\end{equation}
This implies that we only need to consider $ \mathbb{E}\left[\left(\frac{\partial L(\theta)}{\partial f_{i}^{l}}\right)^{2}\right] $ and  $ \mathbb{E}\left[\left(\frac{\partial f_{i}^{l}}{\partial W_{s t}^{l}}\right)^{2}\right]$.
\begin{enumerate}
\item Consider $ \mathbb{E}\left[\left(\frac{\partial L(\theta)}{\partial f_{i}^{l}}\right)^{2}\right] $. By chain rule:
	$$
	\begin{aligned}
	\frac{\partial L(\theta)}{\partial f_{i}^{l}} &=\frac{\partial L(\theta)}{\partial f^{l+1}}\cdot \frac{\partial f^{l+1}}{\partial f_{i}^{l}} =\sum_{j=1}^{n_{l+1}} \frac{\partial L(\theta)}{\partial f_{j}^{l+1}} \frac{\partial f_{j}^{l+1}}{\partial f_{i}^{l}}
	 \\ &=\sum_{j=1}^{n_{l+1}} W_{j i}^{l+1} \sigma^{\prime}\left(f_{i}^{l}\right) \frac{\partial L(\theta)}{\partial f_{j}^{l+1}}=\sum\limits_{j=1}^{n_{l+1}} W_{j i}^{l+1} \frac{\partial L(\theta)}{\partial f_{j}^{l+1}}(\mbox{ if }\sigma=id)
	\end{aligned}
	$$
	Keep doing this:
	$$
	\frac{\partial L(\theta)}{\partial f^{l}}=\left[W^{l+1}\right]^{\top} \cdot\left[W^{l+2}\right]^{\top} \cdots\left[W^{L}\right]^{T} \frac{\partial L(\theta)}{\partial f^{L}}
	$$
	Assume the independence of $ \frac{\partial L(\theta)}{\partial f^{L}} $  with $W^{l+i}, i= 1,2, \dots$.
	( Still we make this assumption although this can not be ture, as $ \frac{\partial L(\theta)}{\partial f^{l}} $ contains  $W^{l+i}$.) Then
	$$
	\mathbb{E}\left[\frac{\partial L(\theta)}{\partial f_{i}^{l}}\right]=\sum\limits_{j} \mathbb{E}\left[W_{j i}^{l+1}\right] \mathbb{E}\left[\frac{\partial L(\theta)}{\partial f_{j}^{l }}\right]=0
	$$
	\begin{equation}\label{normale1}
	\mathbb{E}\left[\left(\frac{\partial L(\theta)}{\partial f_{i}^{l}}\right)^{2}\right]=\mathbb{V}\left[{\frac{\partial L(\theta)}{\partial f_{i}^{l}}}\right]=\prod\limits_{j=l+1}^{L-1} n_{j} \mathbb{V}\left[W_{s t}^{j}\right] \cdot\left(\mathbb{V}\left[W_{s t}^{L}\right] \sum\limits_{i=1}^{n_{L}} \mathbb{E}\left[\left(\frac{\partial L( \theta)}{\partial f_{i}^{L}}\right)^{2}\right]\right)
	\end{equation}
    \item Consider $ \mathbb{E}\left[\left(\frac{\partial f_{i}^{l}}{\partial W_{s t}^{l}}\right)^{2}\right]
    $. By definition,
    $
    \frac{\partial f_{i}^{l}}{\partial W_{s t}^{l}}=\delta_{i s} \sigma\left(f_{t}^{l-1}\right)
    $
    namely, only
	$
	\frac{\partial f_{s}^{l}}{\partial W_{s t}^{l}} \not = 0,
	$
	and $\frac{\partial f_{s}^{l}}{\partial W_{s t}^{l}} = \sigma\left(f^{l-1}_{t}\right)$. If $ \sigma $=id, apply the forward results
		\begin{enumerate}
		\item Expectation:
		$$
		\mathbb{E}\left[\left(\frac{\partial f_{s}^{l}}{\partial W_{s t}^{l}}\right)\right]=0.
		$$
		\item Variance:
		\begin{equation}\label{normale2}
		\begin{split}
		\mathbb{E}\left[\left(\frac{\partial f_{s}^{l}}{\partial W_{s t}^{l}}\right)^{2}\right]& =\mathbb{E}\left[\left(f_{t}^{l-1}\right)^{2}\right]=\mathbb{V}\left[ f_{t}^{l-1}\right]
		\\
		&=\prod\limits_{j=2}^{l-1} n_{j-1} \mathbb{V}\left[W_{s t}^{j}\right] \cdot\left(\mathbb{V}\left[W_{s t}^{1}\right] \sum\limits_{k=1}^{d} \mathbb{E}\left[X_k^{2}\right]\right).
		\end{split}
		\end{equation}
		\end{enumerate}
\end{enumerate}
A combination of \eqref{normale0}, \eqref{normale1} and \eqref{normale2} completes the proof.
\end{proof}

Next we consider $ \mathbb{V}\left[\frac{\partial L(\theta)}{\partial W^{l} _{st}}\right] $.
	\begin{equation*}
	\begin{split}
	&\mathbb{V}\left[\frac{\partial L(\theta)}{\partial W^{l} _{st}}\right] =\mathbb{V}\left[\frac{\partial L (\theta)}{\partial f_{s}^{l}}\right] \cdot \mathbb{V}\left[f^{l-1}_{t}\right]
	\\
	 =& \prod\limits_{j=l+1}^{L-1} n_{j} \mathbb{V}\left[W_{s t}^{j}\right] \left(\mathbb{V}\left[W_{s t}^{L}\right]\sum\limits_{k=1}^{n_{L}} \mathbb{E}\left[\left(\frac{\partial L(\theta)}{\partial f_{k}^{L}}\right)^{2}\right]\right) \times \prod\limits_{j=2}^{l-1} n_{j} V\left[W_{s t}^{j}\right] \left(\mathbb{V}\left[W_{s t}^{1}\right]\sum\limits_{R=1}^{d} \mathbb{E}\left[ X_{k}^{2}\right]\right),
	\end{split}
	\end{equation*}
	where $ \mathbb{V}_{1}=\left(\mathbb{V}\left[W_{s t}^{1}\right]\sum\limits_{k=1}^{d} \mathbb{E}\left[ X_{k}^{2}\right]\right)	$,
$  \mathbb{V}_{L}=\mathbb{V}\left[W_{s t}^{L}\right]\sum\limits_{k=1}^{n_{L}} \mathbb{E}\left[ (\frac{\partial L(\theta)}{\partial f_{k}^{L}})^{2}\right]$.

We consider
$$
	\mathbb{V}\left[W_{s t}^{l}\right]=f\left(n_{l}, n_{l-1}\right).
	$$
 We summarize Lemma \ref{th:idnormal} and Lemma \ref{th:idnormal2} as below
 \begin{enumerate}
\item
$
\mathbb{V}\left[f_{i}^{l}\right]  =\prod\limits_{j=2}^{l} n_{j-1} f\left(n_{j}, n_{j-1}\right)\left(\mathbb{V}\left[W_{s t}^{1}\right]\sum\limits_{k=1}^{d} \mathbb{E}\left[ X_{k}^{2}\right]\right)
$
\item $\mathbb{V}\left[\frac{\partial L(\theta)}{\partial f_{i}^{2}}\right]= \prod\limits_{j=1+1}^{L-1} n_{j} f\left(n_{j}, n_{j-1}\right)\cdot\left(\mathbb{V}\left[W_{s t}^{L}\right] \sum\limits_{i=1}^{n_{L}} \mathbb{E}\left[\left(\frac{\partial L( \theta)}{\partial f_{i}^{l}}\right)^{2}\right]\right)
$
\item $ \mathbb{V}\left[\frac{\partial L(\theta)}{\partial W^{l} _{st}}\right] = \prod\limits_{j=l+1}^{L-1}n_{j} \cdot f\left(n_{j}, n_{j-1}\right) \cdot \prod\limits_{j=2}^{l-1}n_{j-1}f\left(n_{j}, n_{j-1}\right) \times \mathbb{V}_{1} \times \mathbb{V}_{L}
$
\end{enumerate}
Based on the equations above, we have different choice of $\mathbb{V}\left[W_{s t}^{l}\right]$
\begin{enumerate}
	\item If $f\left(n_{1}, n_{j-1}\right)=\frac{1}{n_{j-1}}$ (control $W[f_{i}^{l}]$),
	$\mathbb{V}\left[\frac{\partial L(\theta)}{\partial W_{s t}^{l}}\right]$ will decrease as $l$ grow up. (Notice that $n_{l}>n_{k}$ if $l>k$)
	\item If $f\left(n_{j}, n_{j-1}\right)=\frac{1}{n_{j}}$ (control $V[\frac{\partial L(\theta)}{ \partial f_{i}^{L}} ]$),
	$
	\mathbb{V}\left[\frac{\partial L(\theta)}{\partial W_{s t}^{l}}\right]$
	 still decrease!
	\item If $f\left(n_{j}, n_{j-1}\right)=\frac{2}{n_{j}+n_{j-1}}( \leq \frac{1}{\sqrt{n_{j} n_{j-1}}})$,
	$
	\mathbb{V}\left[\frac{\partial L (\theta)}{\partial W^{l}_{st}}\right]=\frac{\sqrt{n_{L-1}} \cdot \sqrt{n_{1}}}{\sqrt{n_{l}} \cdot \sqrt{n_{l-1}}} \times \mathbb{V}_{1} \times \mathbb{V}_{L}
	$
	decrease!
\end{enumerate}

\paragraph{Question}
Can we design some other choices of  $ \mathbb{V}\left[ W^{l} _{st}\right]$ such  that  $\mathbb{V} \left[\frac{\partial L(\theta)}{\partial W^{l} _{st}}\right]$ admits the following properties:
\begin{itemize}
	\item Keep constant,
	\item Increase,
	\item Change with certain scale.
\end{itemize}


\subsection{Goal Objective}
\label{text:approach/objective/goal}
The goal objective gives an incentive for the optimizer to choose a solution that targets the goal state. It simply consists of the squared L2-norm between each robot trajectory point and the goal state $\goal$, normalized over the full planning horizon $T$:

\begin{equation}
J_{goal}(\x_{0:T}) = \frac{1}{T} \sum_{t = 0}^T (\x_t - \goal)^2
\label{eq:goal_unweighted}
\end{equation}

By normalization, the cost is independent of the length of the planning horizon $T$ and thus allows us to use the same weight $w_{goal}$ for different planning horizons.

\subsubsection{Horizon weighting}
Intuitively, as discussed in Chapter \ref{text:introduction} for socially aware navigation, socially aware objectives should be higher weighted than traditional control effort or travel time objectives. This is especially true at the beginning of the planning horizon. For this reason, a horizon-dependent weighting $\lambda_t$ is introduced into the stage cost of the goal objective, which is small at the beginning of the horizon and large at its end:

\begin{equation}
J_{goal}(\x_{0:T}) = \frac{1}{T} \sum_{t = 0}^T \lambda_t (\x_t - \goal)^2
\label{eq:goal_weighted}
\end{equation}

As shown later on, this modification empowers a fast convergence to the robot's evasive movements, when necessary, to avoid unsafe situations. At the same time, properties of $J_{goal}(\cdot)$, such as, most importantly, convexity, remain unchanged.

\subsubsection{Gradient}
Since the goal objective $J_{goal}(\x_{0:T})$ is only a function of the robot's planned trajectory and the goal state, its Jacobian can be derived without further knowledge of the pedestrian prediction model, merely using the (known) robot dynamics. As described in Section \ref{text:approach/overview}, the robot controls are optimized. Hence by applying the chain rule, we get:

\begin{equation}
\nabla J_{goal} = \pd{J_{goal}}{\u_{0:T-1}} = \pd{J_{goal}}{\x_{0:T}} \cdot \pd{\x_{0:T}}{\u_{0:T-1}}
\end{equation}

As demonstrated, the goal-objectives gradient can be derived by multiplying the gradient of the objective with respect to the robot's trajectory with the gradient of the robot's trajectory with respect to its control inputs. Since the goal-objective directly depends on the trajectory, deriving the first term is straightforward to derive. The second term $\delta \x_{0:T} / \delta \u_{0:T-1}$ is not trivial because of the iterative structure of rolling out state trajectories based on dynamics, and as the robot's dynamics $\f(\cdot)$ can be arbitrary. However, as described in Section \ref{text:approach/formulation}, double integrator dynamics are assumed for the robot so that the whole trajectory $\x_{0:T}$ can be expressed as a function of the initial state $\x_0$ and the control inputs $\u_{0:T-1}$ only, as shown in Equation \ref{eq:dynamics_stacked}. Then the term $\delta \x_{0:T} / \delta \u_{0:T-1}$ simplifies to a constant term:

\begin{align}
\pd{J_{goal}}{\x_{0:T}} &= \pd{}{\x_{0:T}} \frac{1}{N} \sum_{t = 0}^N (\x_t - \goal)^2 \\
&= \frac{2}{T} \begin{bmatrix} (\x_1 - \goal) & \hdots & (\x_T - \goal) \end{bmatrix}^T
\end{align}
\begin{align}
\pd{\x_{0:T}}{\u_{0:T-1}} &= \pd{}{\u_{0:T-1}} \begin{bmatrix} A \x_0 \\ A_n \x_0 + B_n \u_{0:T-1} \end{bmatrix} \\
&= \begin{bmatrix} \boldsymbol{0}_{n \times m} \\ B_n \end{bmatrix}
\label{eq:goal_gradient_dynamics}
\end{align}

with $A_n, B_n$, the stacked state-space description matrices as described in Section \ref{text:approach/runtime/unrolling}.
\newline
Overall, the goal objective and its gradient are very efficient, cheap to compute, having linear complexity with the length of the planning horizon $T$, and independent of the number of pedestrians. Furthermore, it is strictly convex, which improves the optimization convergence speed. Therefore, it is quite valuable for warm-starting the optimization algorithm, as further explained in Section \ref{text:approach/runtime/warm_starting}.


\section{The \selectionsort algorithm}
\Label{sec:selectionsort}

Our version of the \selectionsort algorithm has the signature

\begin{lstlisting}[style = acsl-block]

  void selection_sort(value_type* a, size_type n);
\end{lstlisting}

The \selectionsort algorithm sorts an array in increasing order, left to
right, by selecting in each step the minimum element of the remaining segment
and \emph{swaps} it with its first element.
%
This implies that each member of the increasingly ordered initial segment is less or equal than
each member of the remaining segment.

\begin{figure}[hbt]
\begin{center}
\includegraphics[width=0.65\textwidth]{Figures/selection_sort.pdf}
\caption{An iteration of \selectionsort}
\Label{fig:selectionsort-example}
\end{center}
\end{figure}

\FloatBarrier

Figure~\ref{fig:selectionsort-example} shows a typical situation in an
example run.
The algorithm will swap the \inl{28} at position \inl{i} with the
\inl{9} at position \inl{min} to extend the increasingly ordered initial segment
one field to the right.

\subsection{Formal specification of \selectionsort}

The following listing shows the specification of \selectionsort.

\input{Listings/selection_sort.h.tex}

\clearpage

\subsection{Implementation of \selectionsort}

The implementation of \selectionsort is shown in the next listing.
%
We use \specref{minelement} to find the minimum element of the remaining array segment.

\input{Listings/selection_sort.c.tex}

The loop invariants \inl{increasing} and \inl{lower} establish that the
initial segment \inl{a[0..i-1]} is in increasing order and, respectively,
state that \inl{a[i-1]} is a lower bound of the remaining segment \inl{a[i..n-1]}.
Since the \minelement call uses an address offset, we had
to employ again the \emph{shift lemmas} from the collection \logicref{ArrayBoundsShift}.

The loop invariant \inl{reorder}, on the other hand, states that the multiset of values in the
array \inl{a} are only \emph{rearranged} during the algorithm.
%
While this is intuitively most obvious (as the call to the \specref{swap}
routine, is the only code that modifies~\inl{a}),
it took considerable effort to prove it formally; including a statement contract
that captures the effects of calling \swap.

The main reason for introducing the statement contract is that it
\emph{transforms} the postcondition of the call to \specref{swap}
into the hypotheses for the lemma \logicref{MultisetSwapMiddle}.
This lemma, which relies on the lemmas about \logicref{MultisetReorder},
captures the fact that \emph{swapping two elements of an array} is a \emph{reordering}.

\clearpage


\Lecture{Jayalal Sarma}{Oct 26, 2020}{23}{Extremal Problems In Graphs-Three Proofs,Mantels Theorem}{Praharsh Allada}{$\alpha$}{JS}
\section{Introduction}
This week we are going to look at some extremal problems in graphs.The techniques we use to Solve the problems are more important than the problems themselves.In fact we will look at multiple ways of proving the same statement using different techniques to prove.\\
\section{Some Examples}
\textbf{Example 1:-}\\
Suppose an Undirected Graph G ,does not have triangle(no $k_3$), what is the maximum number of edges the graph G can have?\\
(OR)\\
What is the minimum number of edges that a graph G with n vertices should have so that it always contains at least 1 triangle?\\
\textbf{Solution:-}\\
The graph can be divided Into 2 sets of vertices of size $\frac{n}{2}$ and from all the possible edges from one set to another.In this case we put in $\frac{n^2}{4}$ edges.(From a little thought and AM$ \geq $GM we can see that the highest number of edges are produced when each set contains $\frac{n}{2}$ vertices).The answer to the question is this the best we can do is yes,this is the best that we can do, we can not have more than $\frac{n^2}{4}$ edges with no triangle in the graph.
\section{Mantel's theorem}
\begin{theorem}
Any graph G on n vertices having more than $\frac{n^2}{4}$ edges must contain a triangle
\end{theorem}
\begin{proof}
Let us prove Mantel's theorem using three simple techniques and shifting argument.Let us look at the three different techniques in this lecture and then look at shifting argument in the next.Later let us also look at generalisation of Mantel's theorem.The three techniques  we will be using are double counting argument(we will be using cauchy schwarz inequality),Arithmetic Mean-Geometric Mean Inequality,An application of P.H.P.\\
\textbf{Proof1:-Double Counting argument}\\
We define a mathematical quantity and find its upper and lower bound using two different methods thus calculating an inequality for the parameters involved.\\
Let m be the number of edges in a graph G that does not have any triangles we have to show that $m \le \frac{n^2}{4}$\\
Let, x,y $\in$ V and G contains the edge between x and y the x and y cannot have an edge with a common vertex.(i.e, adjacent vertices can not have common neighbours).
In other words d(x)+d(y)$\le$ n (Since,they cannot have any other common neighbours d(x)+d(y) $\leq$ n-2 without counting edge (x,y) and then we add 2 for the edge (x,y))\\
Now the quantity we are going to double count is $\sum_{x \in V} d(x)^2$
First let us find the Upper bound for this.Now the above quantity can be thought as d(x) being summed d(X) times\\
$$\implies \sum_{x \in V}d(x)^2=\sum_{(x,y) \in E}(d(x)+d(y)) \leq m*n(Since,\sum_{(x,y)\in E} \leq n)$$
Now we will calculate the lower bound on the above quantity in terms of m so that the upper and lower bounds to gather w=might give us a bound on m
Now for this let us first take a look at cauchy schwarz inequality.\\
\begin{theorem}
\textbf{cauchy schwarz inequality:-}\\
let u,v $\in R^n, $$< u,v >=\sum_{i=1}^n
u_i*v_i$, $||u||=< u,u >=\sum_{i=1}^n u_i^2$\\
$$|< u,v >|^2 \leq ||u||*||v||$$
$$i.e,(\sum_{i=1}^n u_i*v_i)^2 \leq (\sum_{i=1}^n u_i^2)(\sum_{i=1}^n v_i^2)$$
\begin{proof}
let us assume $u \neq 0$ and $\lambda \in \mathbb{R}$\\
$0\leq <\lambda u-v ,\lambda u-v >=\lambda^2 <u,u> -\lambda <u,v> -\lambda <v,u> +<v,v>\\
=\lambda^2 <u,u> -2\lambda <u,v>+<v,v>$\\
Choose $\lambda=\frac{<u,v>}{<u,u>} $ substituting in the equation yields
$$\frac{<u,v>^2}{<u,u>}-2\frac{<u,v>^2}{<u,u>}+<v,v> \geq 0$$
$$\implies <u,v>^2 \leq <u,u><v,v>$$
\end{proof}
\newpage
Now let us use the cauchy schwarz inequality to obtain the lower bound.
Let $V={x_1,x_2,....x_n}$ now let us define $u=(d(x_1),d(x_2),.....d(x_n),v=(1,1,1,...,1)$\\
$u_iv_i=d(x_i)\\
\implies \sum (u_i*v_i)^2=(\sum d(x))^2 \implies \sum (d(x)^2) \geq \frac{(\sum d(x)^2)}{n}=\frac{(2m)^2}{n}=\frac{4m^2}{n} \implies \frac{4m^2}{n}\leq mn \implies m \leq \frac{n^2}{4}$
\end{theorem}

\textbf{Proof 2:- AM-GM Inequality}

Neighbours of any vertex x $\in$ V can not have any edges among themselves.(i.e, they must form an independent set). Let A be the largest independent set in the graph, then we have $\forall x$
d(x) $\leq |A|$ .If we consider B=V-A then every edge has at least one end point in B(since we can not have edges between the vertices of A from definition).Sets such as B are vertex covers.If A is the largest Independent Set then B is the smallest vertex cover.Anyway, $|E| \leq \sum_{x \in B} d(x) \leq |B|*|A|\leq (\frac{|A|+|B|}{2})^2=\frac{n^2}{4}$\\
\textbf{Proof 3:- Using P.H.P}\\
Let us consider a graph with 2*n vertices and every such graph with more than $n^2+1$ edges must have a triangle.\\
Let us prove by Induction on n,\\
\textbf{Base case (n=1)}\\
If 2 vertex graph has $1^2+1=2$ vertices has edges from A to B and B to A making it a triangle with a 0 edge as the 3rd side\\
\textbf{Induction step}\\
Assume it is true for n=k and try to prove for n=k+1,
number of vertices =2*(k+1)=2k+2 and the number of edges =$(k+1)^2+1=k^2+2k+2$
Now let us consider an edge (x,y) $\in$ E and call the remaining graph and the edges among themselves as H.\\
\textbf{Case1:-}\\
If H has more than $k^2+1$ edges then since we know that the statement is true for k by induction and now since H has a triangle G also has a triangle and hence the statement is true for n=k+1
\textbf{Case2:-}\\
If H has less than $k^2+1 $ edges therefore number of edges between the vertices x,y to H are
total edges-(edges in H)-edge (x,y)$\geq (k+1)^2+1-k^2-1=2k+1$.Now if we consider each of the vertex in H as a Hole and the number of pigeons in a given hole as number of edges it has with vertices x,y  now since there are 2n holes (2k vertices in H) and at least 2k+1 pigeons (each pigeon represents a distinct edge) there exists a hole with more than 1 pigeon which means there exists a vertex with more than one edge to x,y which makes it a common neighbour to both x and y  (making (x,z) $\in$ E and (y,z) $\in$ E)thus forming a triangle and hence the statement is true for k+1
\textbf{conclusion} any graph with 2*n vertices and more than $n^2+1$ edges must have a triangle for all values of n.
\end{proof}

\Lecture{Jayalal Sarma}{Oct 28, 2020}{24}{The Shifting technique}{Praharsh Allada}{$\alpha$}{JS}

\section{Introduction}
In the last lecture we have seen 3 different techniques for mantel's theorem based on Double counting,AM-GM Inequality and Pigeon Hole principle.In this lecture we are going to look at a new technique to prove the existence of things in general.This technique is based on a principle called averaging principle which is like a cousin to pigeon hole principle.\\

\section{ proving existence using shifting technique}
\textbf{Averaging Principle}
The averaging principle states that every set of numbers contain at least one number which is as large as the average and one number which is as small as the average .\\
To Prove some Good object exist\\
* Assign weights to objects such that Objects with large weights are good\\
* Show that the average weight is large enough for it to be a good object
and hence there exists at least one object with as much weight as average and hence proved that at least one good object exists\\
Shifting would be used in computing the sum and finding the average.

\section{Some examples using Shifting technique}
\textbf{Example 1:-}\\
Let $n\leq m \leq 2n$ where m is the number of pigeons and n is number of hole.For any distribution where no hole is left empty there can be at most 2*(m-n) pigeons which are happy (Happy pigeons are not alone)\\
\textbf{Proof}\\
let us try to maximise the number of happy pigeon,consider any distribution of pigeons such that no hole is empty.if some hole contains grater than 2 pigeons then shift one of the pigeons from that hole to another hole with an unhappy pigeon.(thus increasing the number of happy pigeons by 1).Therefore the distribution which maximises the number of happy pigeons must necessarily have less than or equal to 2 pigeons in each hole.which  naturally gives the configuration which can be obtained bu putting one pigeon in each hole and then putting the remaining (m-n) pigeons in different holes thus making the total number of happy pigeons per filled hole as 2 and thus making the maximum number of happy pigeons as 2*(m-n)\\
\textbf{Example2:-}\\
\textbf{Graham and kleitman} Trail of a graph  is a walk in a graph without repeating edges.If the edges of a complete graph $k_n $ is labelled with distinct numbers ${1,2,3,....,{n\choose 2}}$,with no repetition then there is a trail of length n-1 with an increasing sequence of edge labels.\\
For n=3, take a triangle ABC  let us try to label the edges to avoid a trail of length 2 (n-1=2). If AB=1, in both the cases of BC=2 and CA=2 we will clearly have a trail of increasing edge labels.\\
For n=4, take a square ABCD with diagonals AC and BD and label the edges from 1 to 6 by trying to avoid 3 length trails of increasing length let us start with BD=1 and AC=2 to keep it disconnected then AD=3 because where ever we put 3 tail length will increase by 1 DC  cant be 4 because ADCA will form a trail of length 3 and also AB cant be 4 because in that case BCAB will from a trail of length 3 hence let us put BD=4.But now we cant get put CD=5 since CBDC will form a trail of length 3 with increasing labels  and also we cant put AB=5 since ACBA will form a trail of length 3 with increasing labels hence a trail of length 3 with  increasing labels is unavoidable.\\
\textbf{Proof}\\
We assign a weight to each vertex,x $\in$ v $->$ $W_x$ is it's weight.Where $W_x$ is the length of the longest increasing trail ending at x.Now, it suffices to argue $\exists x \in V,$such that $W_x\geq n-1$. Now we have to find argue the average weight,if we prove $\frac{1}{n}\sum_{x \in V} W_x \geq n-1$
the by averaging principle we have show the existence.This is equivalent to proving $\sum_{x \in V} W_x \geq n*(n-1)$.Shifting algorithm is problem dependent so in this case let us consider building the graph by adding edges one after the other.Let us add the edges in the order of increasing labels which keeps modifying the weights of vertices.
Initially $W_x = 0 \forall x$ we add edges in the increasing label order.\\
At some later instant let us say (x,y) is the edge being added now.So already some edges have been added so let us say there is a path ending at x and y the length of which is the weight of x and y respectively. SO now we update $W_x and W_y$.\\
\textbf{Case1:-} if
$W_x=W_y$  and all the already existing edges have smaller labels since edges are added in that order. Increase both $W_x and W_y by 1$.$W'_x=W_x+1 and W'_y=W_y+1$\\
\textbf{Case2:-}
if $W_x<W_y$ since now edge (x,y) is present the trail previously ending at y plus the edge (x,y) forms a new trail of length $W_y+1 >W_x$  ending at x and hence $W'_x=W_y+1 and W'_y=W_y$\\
\textbf{Case3:-}
if $W_x>W_y$ since now edge (x,y) is present the trail previously ending at x plus the edge (x,y) forms a new trail of length  $W_x+1 >W_y$ ending at y and hence $W'_y=W_x+1$ and $W'_x=W_x$\\
\newpage
\textbf{Observation}\\
The value of $W_x+W_y$ increase by 2 in case one and in case 2 it increased by $W_y-W_x+1$ and in case 3 it increased by  $W_x-W_y+1$ which are grater than or equal to 2 therefore for each edge added the value of $\sum_{x \in V} W_x$ increased by at least 2. Therefore by the time we add ${n \choose 2}$ edges the value of  $\sum_{x \in V} W_x \geq 2*{n \choose 2} \geq n*(n-1) $.Hence,Graham and kleitman has been proved

\Lecture{Jayalal Sarma}{Oct 29, 2020}{25}{Fourth Proof of Mantels Theorem, Turans Theorem}{Venkat Nikhil Kotagiri}{$\alpha$}{JS}
\section{Introduction}
In previous lectures, we have seen three different proofs of Mantel's theorem. In this lecture we will see a fourth proof using \textit{shifting method}.\\

\section{Proof of Mantel's theorem using shifting method}
\begin{theorem}
Any simple graph with $2n$ vertices and $\ge n^2+1$ edges must have a triangle.
\end{theorem}
\begin{proof}
Let $G$ be a simple graph on $2n$ vertices with no triangles.Let $m$ be number of edges in $G$.\\
It suffices to prove that $m\le n^2$.

Shifting argument includes assignment of weights to objects, and shifting those weight to maximize/minimize an objective function. The weights assignment, constraints we chose are problem dependent.

In this proof, for each vertex $x \in V$, we'll assign a weight
$w_x \in [0,1]$, such that $\sum_{x\in V}w_x=1$.\\
Let $S=\sum_{(x,y)\in E}w_xw_y$ and $S_{max}$ be the max value of $S$.\\
Consider the weight assignment in which every vertex is assigned equal weight, i.e.,\\ $w_x=\frac{1}{2n}, \forall x\in V$\\
Value of $S$ in this case is
\begin{align*}
    S&=\sum_{(x,y)\in E}w_xw_y\\
    S&=\sum_{(x,y)\in E}\frac{1}{4n^2}\\
    S&=\frac{m}{2n^2} ~~~~~~~~~~~~~ (\textit{each edge is counted twice})
\end{align*}
Therefore, lower bound for $S_{max}$ is $\frac{m}{2n^2}$,i.e.,
\begin{equation}
    S_{max}\ge \frac{m}{2n^2}
\end{equation}

We'll now use shifting argument to prove that $S_{max}\le \frac{1}{2}$.
Consider two vertices $x,y\in V$ such that $(x,y)\notin E$.
Let $\Gamma_x$ denote the sum of weights of neighbours of $x$, and $\Gamma_y$ denote the sum of weights of neighbours of $y$. $\Gamma_x=\sum_{(x,z)\in E}w_z, \Gamma_y=\sum_{(y,z)\in E}w_z$.
The contribution of $w_x$ towards $S$ is $w_x\sum_{(x,z)\in E}w_z = w_x\Gamma_x$. Similarly the contribution of $w_y$ towards $S$ is $w_y\Gamma_y$.

Without loss of generality assume that $\Gamma_x \ge \Gamma_y$, then by shifting a small weight $\epsilon$ from $y$ to $x$, the change in $S$ is equal to
\begin{align*}
    &=( (w_x+\epsilon)\Gamma_x + (w_y-\epsilon)\Gamma_y ) - ( w_x\Gamma_x + w_y\Gamma_y )
    &= \epsilon(\Gamma_x-\Gamma_y)
    &\ge 0~~~~~~~~~~~~~~~~(\textit{since $\epsilon \ge 0$ and $\Gamma_x\ge \Gamma_y$})
\end{align*}
Therefore, by shifting $\epsilon$ weight from $w_y$ to $w_x$, we have not decreased the value of $S$.

\begin{claim}
Max S is achieved when the weight is concentrated on a edge.
\end{claim}
\begin{proof}
Using the above argument,we can keep shifting the weight from vertex $y$ to vertex $x$ until $w_y$ becomes zero,without decreasing $S$.
Repeat this $\forall u,v \in V$ satisfying $(u,v)\notin E, w_u>0, w_v>0$.\\
Now, for two vertices $u,v$, if $w_u>0$ and $w_y>0$ then the edge $(u,v)$ must be present in $E$.\\
Therefore the weight is concentrated on a clique.
\end{proof}

Using the above claim, and using the fact that $G$ is triangle free, we can conclude that the total weight is
concentrated over a single edge (say (x,y)).
\begin{align*}
    S_{max} &\le max\{w_xw_y+w_yw_x|(x,y)\in E, w_x+w_y=1 \}\\
    S_{max} &\le \frac{1}{4}+\frac{1}{4}\\
    S_{max} &\le \frac{1}{2} ~\footnotemark\\
\end{align*}

Therefore using equation (25.88),
\begin{align*}
    \frac{m}{2n^2} &\le S_{max} \le \frac{1}{2} \\
    \frac{m}{2n^2} &\le \frac{1}{2}\\
    m &\le n^2
\end{align*}

\end{proof}
\footnotetext{$S_{max}=\frac{1}{2}$ if the graph contains at least one edge, otherwise $S_{max}=0$.}
\section{Generalization of Mantel's Theorem: Tur\'an’s theorem}
In this section we will see a generalization of Mantel's theorem, called Tur\'an’s theorem.
\begin{theorem}
If a simple graph $G=(V,E)$ with $n$ vertices has no k-cliques, the $|E|\le (1-\frac{1}{k-1})\frac{n^2}{2}$
\end{theorem}
\begin{proof}
We will restate the theorem as follows: If $G$ has no (k+1)-clique then $|E|\le (1-\frac{1}{k})\frac{n^2}{2}$.\\
We will use induction on number of vertices $n$.\\
\textbf{Induction hypothesis:} Assume that the threorem is true $\forall n^{'} < n$.

Consider $G$ that has max number of edges but still does not have a (k+1)-clique. Then $G$ must have a k-clique.Let $A\subseteq V, |A|=k$, be a k-clique in $G$. Let $B=V\setminus A$.
Let $E_A, E_B, E_{AB}$ denote the edges in $A$, edges in $B$, edges across $AB$ respectively. Clearly $E_A, E_B, E_{AB}$ is a partition of $E$. Therefore, we can write,
\begin{align*}
    |E| = |E_A|+|E_B|+|E_{AB}|
\end{align*}
Since $A$ is a k-clique, $E_A= \binom{k}{2}$\\
\textbf{Estimating $|E_{AB}|$}:

If a vertex $u$ in $B$ is connected to all the vertices in $A$, then $A \cup u$ is (k+1)-clique, which is a contradiction. Therefore every vertex in $B$ is connected to at-most $k-1$ vertices in $A$. Therefore, $|E_{AB}|\le |B|(k-1)=(n-k)(k-1)$.\\
\textbf{Estimating $|E_{B}|$}:

Since $B$ is simple graph which does not have (k+1)-cliques, we can use the induction hypothesis to estimate $E_B$.
$E_B \le (1-\frac{1}{k})\frac{(n-k)^2}{2}$\\
Therefore,
\begin{align*}
    |E| &\le \binom{k}{2} + (n-k)(k-1) + (1-\frac{1}{k})\frac{(n-k)^2}{2}\\
    |E| &\le (1-\frac{1}{k})\frac{n^2}{2}
\end{align*}

\end{proof}

\section{Complementary of Tur\'an’s theorem}
For a simple graph $G$, let $\alpha(G)$ be the maximum number of pairwise non-adjacent vertices of $G$. If $G$ has $n$ vertices and $\frac{nk}{2}$ edges then,
$\alpha(G) \le \frac{n}{k+1}$.\\\\
We will prove this by using \textit{probabilistic method}.\\
Before that, we will do a quick recap of probability.

\section{Recap of probability}

The set of all possible outcomes is called sample space($\Omega$). Events are subsets of sample space.\\
The probability distribution assigns values in $\Omega$ to $[0,1]$, such that
$\sum_{x\in \Omega}p(x)=1$.\\

\textbf{Random variable:} Random variable(X) is function that assigns real values to elements in the sample space.
$$X:\Omega\rightarrow \R$$

\textbf{Expected value of a Random variable:}The expected value of X, where X is a random variable, is the weighted average of the possible values that X can take, each value being weighted according to the probability of that event occurring.
$$E[X]=\sum_{w\in \Omega}p(w)X(w)$$
\textit{Linearity of Expectation:}\\
If $X_1,X_2$ are random variables such that $X_1,X_2: \Omega \rightarrow \R$, then
$$E[c_1X_1+c_2X_2]=c_1E[X_1]+c_2E[X_2]$$
One way to interpret averaging argument is that,\\
$$\exists w\in \Omega ~~\textit{such that}~~ X(w)\ge E[X]$$

%\Lecture{Jayalal Sarma}{Oct 29, 2020}{26}{Expectation method, Independence number}{Venkat Nikhil Kotagiri}{$\alpha$}{JS}
\section{Expection Method, Independence Number}
In this lecture, we will use expectation method to prove the complementary of Tur\'an’s theorem discussed in the previous lecture.
Before that, let's see an example on how to use expectation method.\\
\textbf{Statement:} $\exists$ graph $G$ that has $n$ vertices and at least 3 connected components.

Let each edge $(x,y)$ be present with probability $p$ and be absent with probability $1-p$. This is called random graph model.

The sample space $\Omega=$ set of all graphs with $n$ vertices.
Consider a random variable $X$, which maps an element $G$ in $\Omega$ to number of components in $G$,i.e, $X(G)=$ number of components in G.

To prove that there exists a graph with at least 3 connected components, we need to prove that $E(X)\ge 3$.\\

\section{Complementary of Tur\'an’s theorem}
\begin{theorem}
Let $G$ be a graph on $n$ vertices and let $d_i$ denote the degree of the $i^{th}$ vertex. Let $\alpha(G)$ be the Independence number (cardinality of the largest independent set) of $G$. Then $\alpha(G)\ge \sum_{i=1}^{n}\frac{1}{d_i+1}$
\end{theorem}
Our earlier statement is slightly different from the above theorem.\\
\textbf{Statement:} If $G$ has $n$ vertices and $\frac{nk}{2}$ edges then $\alpha(G)\ge \frac{n}{k+1}$
\begin{claim}
This statement can be derived from the above theorem.
\end{claim}
\begin{proof}
The theorem states that
\begin{equation}
    \alpha(G)\ge \sum_{i=1}^{n}\frac{1}{d_i+1}
\end{equation}
Let $d_i=k~\forall 1\le i\le n$, Then number of edges= $\frac{1}{2}\sum_{i=1}^{n}d_i=\frac{nk}{2}$.\\
Using equation (26.89),
\begin{align*}
    \alpha(G) &\ge \sum_{i=1}^{n}\frac{1}{d_i+1}\\
    \alpha(G) &\ge \sum_{i=1}^{n}\frac{1}{k+1}\\
    \alpha(G) &\ge \frac{n}{k+1}
\end{align*}
\end{proof}
We will now prove the above theorem.
\begin{proof}
Before moving forward with the proof, let's recall the recipe of a proof using expectation method
\begin{itemize}
  \item Set up an experiment
  \item Relate the quantity that we want to expectation
  \item Bound expectation
\end{itemize}
\textbf{Setting up the experiment:}

Let $V=\{1,2,\dots,n\}$, let $\pi:V\rightarrow V$ be a permutation of $V$.

\textit{Experiment:} Chose a permutation uniformly at random.\\\\
\textbf{Relating the required quantity to expectation:}

Let $A_i$ be the event that all neighbours $j$ of vertex $i$ are greater than $i$ in the ordering,i.e., $\forall j:(i,j)\in E, \pi(j)>\pi(i)$\\
Probability of event $A_i$ happening is $Pr(A_i)=\binom{n}{d_i+1}\frac{d_i!(n-d_i-1)!}{n!}$.\\\\
\textit{Idea:} If for x,y, $A_x$ and $A_y$ holds then $(x,y)\notin E$.\\\\
\textit{Aim:} To show that $\exists u\subseteq V$ such that $|u|\ge\sum_{i=1}^{n}\frac{1}{d_i+1}$, and for no vertex inside $u$, the event holds.\\\\
Using the expectation method, let $U$ be the set of vertices $i$ such that $A_i$ holds.\\
Define random variable,
$X_i =
\left\{
	\begin{array}{ll}
		1  & \mbox{if } A_i ~~\text{holds} \\
		0  & \mbox{otherwise }
	\end{array}
\right.$

\begin{align*}
    E[|U|] &= E[X_1+X_2+\dots,X_n]\\
           &= \sum_{i=1}^{n}E[X_i] \\
           &= \sum_{i=1}^{n}\sum_{w\in\Omega}X_i(w)Pr(w) \\
           &= \sum_{i=1}^{n}0.pr[X_i==0]+1.pr[X_i==1] \\
           &= \sum_{i=1}^{n}Pr[A_i] \\
           &= \sum_{i=1}^{n}\binom{n}{d_i+1}\frac{d_i!(n-d_i-1)}{n!}\\
           &= \sum_{i=1}^{n}\frac{n!}{(d_i+1)!(n-d_i-1)!}\frac{d_i!(n-d_i-1)!}{n!}\\
           &= \sum_{i=1}^{n}\frac{1}{d_i+1}
\end{align*}
So, there must exist $u\subseteq V$ such that, $|u|\ge \sum_{i=1}^{n}\frac{1}{d_i+1}$ and $\forall x \in u$, the event $A_x$ happens for a permutation. That implies $\exists$ an independent set $|u|\ge\sum_{i=1}^{n}\frac{1}{d_i+1}$. Therefore $$\alpha(G)\ge \sum_{i=1}^{n}\frac{1}{d_i+1}$$
\end{proof}


\subsection{Calibration of the Time Series Generation Process}
\label{params}

Independent of the concrete forecasting models, the time series generation
    must be calibrated.
We concentrate our forecasts on the pickup side for two reasons.
First, the restaurants come in a significantly lower number than the
    customers resulting in more aggregation in the order counts and thus a
    better pattern recognition.
Second, from an operational point of view, forecasts for the pickups are more
    valuable because of the waiting times due to meal preparation.
We choose pixel sizes of $0.5~\text{km}^2$, $1~\text{km}^2$, $2~\text{km}^2$,
    and $4~\text{km}^2$, and time steps covering 60, 90, and 120 minute windows
    resulting in $H_{60}=12$, $H_{90}=9$, and $H_{120}=6$ time steps per day
    with the platform operating between 11 a.m. and 11 p.m. and corresponding
    frequencies $k_{60}=7*12=84$, $k_{90}=7*9=63$, and $k_{120}=7*6=42$ for the
    vertical time series.
Smaller pixels and shorter time steps yield no recognizable patterns, yet would
    have been more beneficial for tactical routing.
90 and 120 minute time steps are most likely not desirable for routing; however,
    we keep them for comparison and note that a UDP may employ such forecasts
    to activate more couriers at short notice if a (too) high demand is
    forecasted in an hour from now.
This could, for example, be implemented by paying couriers a premium if they
    show up for work at short notice.
Discrete lengths of 3, 4, 5, 6, 7, and 8 weeks are chosen as training
    horizons.
We do so as the structure within the pixels (i.e., number and kind of
    restaurants) is not stable for more than two months in a row in the
    covered horizon.
That is confirmed by the empirical finding that forecasting accuracy
    improves with longer training horizon but this effect starts to
    level off after about six to seven weeks.
So, the demand patterns of more than two months ago do not resemble more
    recent ones.

In total, 100,000s of distinct time series are forecast in the study.