\title{Teaching the Geometry of Schemes}
\titlerunning{Teaching the Geometry of Schemes}
\toctitle{Teaching the Geometry of Schemes}

\author{Gregory G.~Smith \and Bernd Sturmfels}
\authorrunning{G. G. Smith and B. Sturmfels}
% \institute{Department of Mathematics, University of California,
% Berkeley, California 94720, USA}

\maketitle

%%----------------------------------------------------------
\newtheorem*{problem*}{Problem}{\bfseries\upshape}{\itshape}
\newtheorem*{solution*}{Solution}{\itshape}{\rmfamily}

\newcommand{\Spec}{\operatorname{Spec}}
\newcommand{\Proj}{\operatorname{Proj}}
\newcommand{\codim}{\operatorname{codim}}
%%----------------------------------------------------------

\begin{abstract}
This chapter presents a collection of graduate level problems in
algebraic geometry illustrating the power of \Mtwo as an educational
tool.
\end{abstract}

When teaching an advanced subject, like the language of schemes, we
think it is important to provide plenty of concrete instances of the
theory.  Computer algebra systems, such as \Mtwo, provide students
with an invaluable tool for studying complicated examples.
Furthermore, we believe that the explicit nature of a computational
approach leads to a better understanding of the objects being
examined.  This chapter presents some problems which we feel
illustrate this point of view.

Our examples are selected from the homework of an algebraic geometry
class given at the University of California at Berkeley in the fall of 1999.
This graduate course was taught by the second author with assistance from the
first author.  Our choice of problems, as the title suggests, follows the
material in David Eisenbud and Joe Harris' textbook {\em The Geometry of
  Schemes} \cite{SC:EH}.

%%----------------------------------------------------------
\section{Distinguished Open Sets}

We begin with a simple example involving the Zariski topology of an affine
scheme\index{scheme!affine}. This example also indicates some of the
subtleties involved in working with arithmetic
schemes\index{scheme!arithmetic}.

\begin{problem*}
Let $S = \bbbz[x,y,z]$ and $X = \Spec(S)$.  If $f = x$ and $X_{f}$ is
the corresponding basic open subset in $X$, then establish the
following:
\begin{enumerate}
\item[$(1)$] If $e_{1} = x+y+z$, $e_{2} = xy+xz+yz$ and $e_{3} = xyz$
are the elementary symmetric functions then the set $\{X_{e_{i}}\}_{1
\leq i \leq 3}$ is an open cover of $X_{f}$.
\item[$(2)$] If $p_{1} = x+y+z$, $p_{2} = x^{2}+y^{2}+z^{2}$ and $p_{3}
= x^{3}+y^{3}+z^{3}$ are the power sum symmetric functions then
$\{X_{p_{i}}\}_{1 \leq i \leq 3}$ is {\em not} an open cover of
$X_{f}$.
\end{enumerate}
\end{problem*}

\begin{solution*}
$(1)$ To prove that $\{X_{e_{i}}\}_{1 \leq i \leq 3}$ is an open cover
of $X_{f}$, it suffices to show that $e_{1}$, $e_{2}$ and $e_{3}$
generate the unit ideal in $S_{f}$; see Lemma I-16 in Eisenbud and
Harris~\cite{SC:EH}.  This is equivalent to showing that $x^{m}$
belongs to the $S$-ideal $\langle e_{1}, e_{2}, e_{3} \rangle$ for
some $m \in \bbbn$.  In other words, the saturation\index{saturation}
$\big( \langle e_{1}, e_{2}, e_{3} \rangle : x^{\infty} \big)$ is the
unit ideal if and only if $\{X_{e_{i}}\}_{1 \leq i \leq 3}$ is an open
cover of $X_{f}$.  We verify this in \Mtwo as follows:
<<<S = ZZ[x, y, z];>>>
<<<elementaryBasis = ideal(x+y+z, x*y+x*z+y*z, x*y*z);>>>
<<<saturate(elementaryBasis, x)>>>
$(2)$ Similarly, to show that $\{X_{p_{i}}\}_{1 \leq i \leq 3}$ is not
an open cover of $X_{f}$, we prove that $\big( \langle p_{1}, p_{2},
p_{3} \rangle : x^{\infty} \big)$ is not the unit ideal.  Calculating
this saturation, we find
<<<powerSumBasis = ideal(x+y+z, x^2+y^2+z^2, x^3+y^3+z^3);>>>
<<<saturate(powerSumBasis, x)>>>
<<<clearAll>>>
which is not the unit ideal.\qed
\end{solution*}

The fact that $6$ is a generator of the ideal $\big( \langle p_{1},
p_{2}, p_{3} \rangle : x^{\infty} \big)$ indicates that
$\{X_{p_{i}}\}_{1 \leq i \leq 3}$ does not contain the points in $X$
lying over the points $\langle 2 \rangle$ and $\langle 3 \rangle$ in
$\Spec(\bbbz)$.  If we work over a base ring in which $6$ is a unit,
then $\{X_{p_{i}}\}_{1 \leq i \leq 3}$ would, in fact, be an open
cover of $X_{f}$.

%%----------------------------------------------------------
\section{Irreducibility}

The study of complex semisimple Lie algebras gives rise to an
important family of algebraic varieties called nilpotent
orbits\index{nilpotent orbits}.  The next problem examines the
irreducibility\index{scheme!irreducible} of a particular nilpotent
orbit.

\begin{problem*}
Let $X$ be the set of nilpotent complex $3 \times 3$ matrices.  Show
that $X$ is an irreducible algebraic variety.
\end{problem*}

\begin{solution*}
A $3 \times 3$ matrix $M$ is nilpotent if and only if its minimal
polynomial $p(\sf T)$ equals ${\sf T}^{k}$, for some $k \in \bbbn$.
Since each irreducible factor of the characteristic polynomial of $M$
is also a factor of $p(\sf T)$, it follows that the characteristic
polynomial of $M$ is ${\sf T}^{3}$.  We conclude that the coefficients
of the characteristic polynomial of a generic $3 \times 3$ matrix
define the algebraic variety $X$.

To prove that $X$ is irreducible over $\bbbc$, we construct a rational
parameterization\index{rational parameterization}.  First, observe
that ${\rm GL}_{3}(\bbbc)$ acts on $X$ by conjugation.  Jordan's
canonical form theorem implies that there are exactly three orbits;
one for each of the following matrices:
\[
N_{(1,1,1)} =\left[ \begin{smallmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 &
0 & 0 \end{smallmatrix} \right], \quad
N_{(2,1)} = \left[ \begin{smallmatrix} 0 & 1 & 0 \\ 0 & 0 & 0 \\ 0 & 0
& 0 \end{smallmatrix} \right] \text{ and }
N_{(3)} = \left[ \begin{smallmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 &
0 \end{smallmatrix} \right] \enspace .
\]
Each orbit is defined by a rational parameterization, so it suffices
to show that the closure of the orbit containing $N_{(3)}$ is the
entire variety $X$.  We demonstrate this as follows:
<<<S = QQ[t, y_0 .. y_8, a..i, MonomialOrder => Eliminate 10];>>>
<<<N3 = (matrix {{0,1,0},{0,0,1},{0,0,0}}) ** S>>>
<<<G = genericMatrix(S, y_0, 3, 3)>>>
To determine the entries in $G \cdot N_{(3)} \cdot G^{-1}$, we use the
classical adjoint\index{classical adjoint} to construct the matrix
$\det(G) \cdot G^{-1}$.
<<<classicalAdjoint = (G) -> (
     n := degree target G;
     m := degree source G;
     matrix table(n, n, (i, j) -> (-1)^(i+j) * det(
               submatrix(G, {0..j-1, j+1..n-1},
                    {0..i-1, i+1..m-1}))));>>>
<<<num = G * N3 * classicalAdjoint(G);>>>
<<<D = det(G);>>>
<<<M = genericMatrix(S, a, 3, 3);>>>
The entries in $G \cdot N_{(3)} \cdot G^{-1}$ give a rational
parameterization of the orbit generated by $N_{(3)}$.  Using
elimination theory\index{elimination theory} --- see section~3.3 in
Cox, Little and O`Shea~\cite{SC:CLO} --- we give an ``implicit
representation'' of this variety.
<<<elimIdeal = minors(1, (D*id_(S^3))*M - num) + ideal(1-D*t);>>>
<<<closureOfOrbit = ideal selectInSubring(1, gens gb elimIdeal);>>>

Finally, we verify that this orbit closure equals $X$
scheme-theoretically.  Recall that $X$ is defined by the coefficients
of the characteristic polynomial of a generic $3 \times 3$ matrix {\tt
M}.
%% was X = ideal submatrix( (coeff-icients({0}, det(M - t*id_(S^3))))_1,
%% {1,2,3} ), but 'coeff-icients' is to be redesigned, and 'contract' is
%% more self-explanatory, anyway.
<<<X = ideal substitute(
        contract(matrix{{t^2,t,1}}, det(t-M)),
        {t => 0_S})>>>
<<<closureOfOrbit == X>>>
<<<clearAll>>>
This completes our solution.\qed
\end{solution*}

More generally, Kostant shows that the set of all nilpotent elements
in a complex semisimple Lie algebra\index{Lie algebra} form an
irreducible variety.  We refer the reader to Chriss and
Ginzburg~\cite{SC:CV} for a proof of this result (Corollary~3.2.8) and
a discussion of its applications in representation theory.

%%----------------------------------------------------------
\section{Singular Points}

In our third question, we study the singular locus\index{singular
locus} of a family of elliptic curves\index{elliptic curve}.

\begin{problem*}
Consider a general form of degree $3$ in $\bbbq[x,y,z]$:
\[
F = ax^{3} + bx^{2}y + cx^{2}z + dxy^{2} + exyz + fxz^{2} + gy^{3} +
hy^{2}z + iyz^{2} + jz^{3} \enspace .
\]
Give necessary and sufficient conditions in terms of $a, \ldots, j$
for the cubic curve $\Proj\big( \bbbq[x,y,z] / \langle F \rangle
\big)$ to have a singular point.
\end{problem*}

\begin{solution*}
The singular locus of $F$ is defined by a polynomial of degree $12$ in
the $10$ variables $a, \dotsc, j$.  We calculate this polynomial in two
different ways.

Our first method is an elementary but time consuming elimination.
Carrying it out in \Mtwo, we have
<<<S = QQ[x, y, z, a..j, MonomialOrder => Eliminate 2];>>>
<<<F = a*x^3+b*x^2*y+c*x^2*z+d*x*y^2+e*x*y*z+f*x*z^2+g*y^3+h*y^2*z+
             i*y*z^2+j*z^3;>>>
<<<partials = submatrix(jacobian matrix{{F}}, {0..2}, {0})>>>
<<<singularities = ideal(partials) + ideal(F);>>>
<<<elimDiscr = time ideal selectInSubring(1,gens gb singularities);>>>
<<<elimDiscr = substitute(elimDiscr, {z => 1});>>>
On the other hand, there is also an elegant and more useful
determinantal formula for this discriminant\index{discriminant}; it is
a specialization of the formula (2.8) in section~3.2 of Cox, Little
and O`Shea~\cite{SC:CLO2}.  To apply this determinantal formula, we
first create the coefficient matrix {\tt A} of the partial derivatives
of $F$.
%% was A = (coeff-icients({0,1,2}, submatrix(jacobian matrix{{F}}, {0..2}, {0})))_1;
%% but 'coeff-icients' is deprecated.
<<<A = contract(matrix{{x^2,x*y,y^2,x*z,y*z,z^2}},
        diff(transpose matrix{{x,y,z}},F))>>>
We also construct the coefficient matrix {\tt B} of the partial
derivatives of the Hessian\index{hessian} of $F$.
<<<hess = det submatrix(jacobian ideal partials, {0..2}, {0..2});>>>
%% was B = (coeff-icients({0,1,2}, submatrix(jacobian matrix{{hess}}, {0..2}, {0})))_1;
%% but 'coeff-icients' is deprecated.
<<<B = contract(matrix{{x^2,x*y,y^2,x*z,y*z,z^2}},
        diff(transpose matrix{{x,y,z}},hess))>>>
To obtain the discriminant, we combine these two matrices and take the
determinant.
<<<detDiscr = ideal det (A || B);>>>
Finally, we check that our two discriminants are equal
<<<detDiscr == elimDiscr>>>
and examine the generator.
<<<detDiscr_0>>>
<<<numgens detDiscr>>>
<<<# terms detDiscr_0>>>
<<<clearAll>>>
Hence, the singular locus is given by a single polynomial of degree
$12$ with $2040$ terms.\qed
\end{solution*}

For a further discussion of singularities and discriminants see
Section~V.3 in Eisenbud and Harris~\cite{SC:EH}.  For information on
resultants and discriminants see Chapter~2 in Cox, Little and
O`Shea~\cite{SC:CLO2}.

%%----------------------------------------------------------
\section{Fields of Definition}

Schemes\index{scheme!over a number field} over non-algebraically
closed fields arise in number theory.  Our fourth problem looks at one
technique for working with number fields in \Mtwo.

\begin{problem*}[Exercise~II-6 in  \cite{SC:EH}]
An inclusion of fields $K \hookrightarrow L$ induces a map
$\mathbb{A}_{L}^{n} \to \mathbb{A}_{K}^{n}$.  Find the images in
$\mathbb{A}_{\bbbq}^{2}$ of the following points of
$\mathbb{A}_{\overline{\bbbq}}^{2}$ under this map.
\begin{enumerate}
\item[$(1)$] $\langle x - \sqrt{2}, y - \sqrt{2} \rangle ;$
\item[$(2)$] $\langle x - \sqrt{2}, y - \sqrt{3} \rangle ;$
\item[$(3)$] $\langle x - \zeta, y - \zeta^{-1} \rangle$ where $\zeta$
is a $5$-th root of unity $;$
\item[$(4)$] $\langle \sqrt{2}x- \sqrt{3}y \rangle ;$
\item[$(5)$] $\langle \sqrt{2}x- \sqrt{3}y-1 \rangle$.
\end{enumerate}
\end{problem*}

\begin{solution*}
The images can be determined by using the following three step
algorithm: (1) replace the coefficients not contained in $K$ with
indeterminates, (2) add the minimal polynomials of these coefficients
to the given ideal in $\mathbb{A}_{L}^{2}$, and (3) eliminate the new
indeterminates.  Here are the five examples:
<<<S = QQ[a,b,x,y, MonomialOrder => Eliminate 2];>>>
<<<I1 = ideal(x-a, y-a, a^2-2);>>>
<<<ideal selectInSubring(1, gens gb I1)>>>
<<<I2 = ideal(x-a, y-b, a^2-2, b^2-3);>>>
<<<ideal selectInSubring(1, gens gb I2)>>>
<<<I3 = ideal(x-a, y-a^4, a^4+a^3+a^2+a+1);>>>
<<<ideal selectInSubring(1, gens gb I3)>>>
<<<I4 = ideal(a*x+b*y, a^2-2, b^2-3);>>>
<<<ideal selectInSubring(1, gens gb I4)>>>
<<<I5 = ideal(a*x+b*y-1, a^2-2, b^2-3);>>>
<<<ideal selectInSubring(1, gens gb I5)>>>
<<<clearAll>>>
\qed
\end{solution*}

It is worth noting that the points in $\mathbb{A}_{\bbbq}^{n}$ correspond
to orbits of the action of ${\rm Gal}(\overline{\bbbq}/\bbbq)$ on the
points of $\mathbb{A}_{\overline{\bbbq}}^{n}$.  For more examples and
information, see section~II.2 in Eisenbud and Harris~\cite{SC:EH}.

%%----------------------------------------------------------
\section{Multiplicity}

The multiplicity\index{multiplicity} of a zero-dimensional scheme $X$
at a point $p \in X$ is defined to be the length of the local ring
$\mathcal{O}_{X,p}$.  Unfortunately, we cannot work directly in the
local ring in \Mtwo.  What we can do, however, is to compute the
multiplicity by computing the degree of the component of $X$ supported
at $p$; see page 66 in Eisenbud and Harris~\cite{SC:EH}.

\begin{problem*}
What is the multiplicity of the origin as a zero of the polynomial
equations $x^{5}+y^{3}+z^{3} = x^{3}+y^{5}+z^{3} = x^{3}+y^{3}+z^{5} =
0$?
\end{problem*}

\begin{solution*}
If $I$ is the ideal generated by $x^{5}+y^{3}+z^{3}$,
$x^{3}+y^{5}+z^{3}$ and $x^{3}+y^{3}+z^{5}$ in $\bbbq[x,y,z]$, then
the multiplicity of the origin is
\[
\dim_{\bbbq} \frac{\bbbq[x,y,z]_{\langle x,y,z \rangle}}
{I \bbbq[x,y,z]_{\langle x,y,z \rangle}} \, .
\]
It follows that the multiplicity is the vector space dimension of the
ring $\bbbq[x,y,z] / \varphi^{-1}(I \bbbq[x,y,z]_{\langle x,y,z
\rangle})$ where $\varphi \colon \bbbq[x,y,z] \to
\bbbq[x,y,z]_{\langle x,y,z \rangle}$ is the natural map.  Moreover,
we can express this using ideal quotients:
\[
\varphi^{-1}(I \bbbq[x,y,z]_{\langle x,y,z \rangle}) \,\,= \,\,
\big(I : (I : \langle x,y,z \rangle^{\infty})\big) \, .
\]
Carrying out this calculation in \Mtwo, we obtain:
<<<S = QQ[x, y, z];>>>
<<<I = ideal(x^5+y^3+z^3, x^3+y^5+z^3, x^3+y^3+z^5);>>>
<<<multiplicity = degree(I : saturate(I))>>>
<<<clearAll>>>
Thus, we conclude that the multiplicity is $27$.\qed
\end{solution*}

There are algorithms (not yet implemented in \Mtwo) for working
directly in the local ring $\bbbq[x,y,z]_{\langle x,y,z \rangle}$.  We
refer the interested reader to Chapter~4 in Cox, Little and
O`Shea~\cite{SC:CLO2}.

%%----------------------------------------------------------
\section{Flat Families}

Non-reduced schemes\index{scheme!non-reduced} arise naturally as flat
limits\index{flat limit} of a family of reduced
schemes\index{scheme!reduced}. Our next problem illustrates how a
family of skew lines in $\bbbp^{3}$ gives rise to a double line with
an embedded point\index{embedded point}.

\begin{problem*}[Exercise~III-68 in \cite{SC:EH}]
Let $L$ and $M $ be the lines in $\bbbp^{3}_{k[t]}$ given by $x=y=0$
and $x-tz = y+t^{2}w =0$ respectively.  Show that the flat limit as $t
\to 0$ of the union $L \cup M$ is the double line $x^{2} = y = 0$ with
an embedded point of degree $1$ located at the point $(0:0:0:1)$.
\end{problem*}

\begin{solution*}
We first find the flat limit by saturating\index{saturation} the
intersection ideal and setting $t = 0$.
<<<PP3 = QQ[t, x, y, z, w];>>>
<<<L = ideal(x, y);>>>
<<<M = ideal(x-t*z, y+t^2*w);>>>
<<<X = intersect(L, M);>>>
<<<Xzero = trim substitute(saturate(X, t), {t => 0})>>>
Secondly, we verify that this is the union of a double line and an
embedded point of degree $1$.
<<<Xzero == intersect(ideal(x^2, y), ideal(x, y^2, z))>>>
<<<degree(ideal(x^2, y ) / ideal(x, y^2, z))>>>
<<<clearAll>>>
\qed
\end{solution*}

Section~III.3.4 in Eisenbud and Harris~\cite{SC:EH} contains several
other interesting limits of various flat families.

%%----------------------------------------------------------
\section{B\'{e}zout's Theorem}

B\'{e}zout's Theorem\index{Bezout's Theorem@B\'ezout's Theorem} --- Theorem~III-78 in
Eisenbud and Harris~\cite{SC:EH} --- may fail without the
Cohen-Macaulay\index{Cohen-Macaulay} hypothesis.  Our seventh problem
is to demonstrate this.

\begin{problem*}[Exercise~III-81 in \cite{SC:EH}]
Find irreducible closed subvarieties $X$ and $Y$ in $\bbbp^{4}$ such
that
\begin{align*}
\codim(X \cap Y) &= \codim(X) + \codim(Y) \\
\deg(X \cap Y) &> \deg(X) \cdot \deg(Y) \, .
\end{align*}
\end{problem*}

\begin{solution*}
We show that the assertion holds when $X$ is the cone over the
nonsingular rational quartic curve\index{rational quartic curve} in
$\bbbp^{3}$ and $Y$ is a two-plane passing through the vertex of the
cone.  First, recall that the rational quartic curve is given by the
$2 \times 2$ minors of the matrix $\left[ \begin{smallmatrix} a &
b^{2} & bd & c \\ b & ac & c^2 & d \end{smallmatrix} \right]$; see
Exercise~18.8 in Eisenbud~\cite{SC:E}.  Thus, we have
<<<S = QQ[a, b, c, d, e];>>>
<<<IX = trim minors(2, matrix{{a, b^2, b*d, c},{b, a*c, c^2, d}})>>>
<<<IY = ideal(a, d);>>>
<<<codim IX + codim IY == codim (IX + IY)>>>
<<<(degree IX) * (degree IY)>>>
<<<degree (IX + IY)>>>
which establishes the assertion.\qed
\end{solution*}

To understand how this example works, it is enlightening to express
$Y$ as the intersection of two hyperplanes; one given by $a = 0$ and
the other given by $d = 0$.  Intersecting $X$ with the first
hyperplane yields
<<<J = ideal mingens (IX + ideal(a))>>>
However, this first intersection has an embedded point;
<<<J == intersect(ideal(a, b*c, b^2, c^3-b*d^2),
     ideal(a, d, b*c, c^3, b^3)) -- embedded point>>>
<<<clearAll>>>
The second hyperplane passes through this embedded
point\index{embedded point} which explains the extra intersection.

%%----------------------------------------------------------
\section{Constructing Blow-ups}

The blow-up\index{blow-up} of a scheme $X$ along a subscheme $Y$ can
be constructed from the Rees algebra\index{Rees algebra} associated to
the ideal sheaf of $Y$ in $X$; see Theorem~IV-22 in Eisenbud and
Harris~\cite{SC:EH}.  Gr\"{o}bner basis techniques allow one to
express the Rees algebra in terms of generators and relations.  We
illustrate this method in the next solution.

\begin{problem*}[Exercises~IV-43 \& IV-44 in \cite{SC:EH}]
Find the blow-up $X$ of the affine plane\index{scheme!affine}
$\mathbb{A}^{2} = \Spec\big( \bbbq[x, y] \big)$ along the subscheme
defined by $\langle x^{3}, xy, y^{2} \rangle$.  Show that $X$ is
nonsingular and its fiber over the origin is the union of two copies
of $\bbbp^{1}$ meeting at a point.
\end{problem*}

\begin{solution*}
We first provide a general function which returns the ideal of
relations for the Rees algebra.
<<<blowUpIdeal = (I) -> (
     r := numgens I;
     S := ring I;
     n := numgens S;
     K := coefficientRing S;
     tR := K[t, gens S, vars(0..r-1),
               MonomialOrder => Eliminate 1];
     f := map(tR, S, submatrix(vars tR, {1..n}));
     F := f(gens I);
     J := ideal apply(1..r, j -> (gens tR)_(n+j)-t*F_(0,(j-1)));
     L := ideal selectInSubring(1, gens gb J);
     R := K[gens S, vars(0..r-1)];
     g := map(R, tR, 0 | vars R);
     trim g(L));>>>
Now, applying the function to our specific case yields:
<<<S = QQ[x, y];>>>
<<<I = ideal(x^3, x*y, y^2);>>>
<<<J = blowUpIdeal(I)>>>
Therefore, the blow-up of the affine plane along the given subscheme
is
\[
X = \Proj\left( \frac{(\bbbq[x,y])[a,b,c]}{\langle yb-xc, xb^{2}-ac,
x^{2}b-ya, x^{3}c-y^{2}a \rangle} \right) \, .
\]
Using \Mtwo, we can also verify that the scheme $X$ is
nonsingular\index{singular locus};
<<<J + ideal jacobian J == ideal gens ring J>>>
<<<clearAll>>>
Since we have
\[
\frac{(\bbbq[x,y])[a,b,c]}{\langle yb-xc, xb^{2}-ac, x^{2}b-ya,
x^{3}c-y^{2}a \rangle} \otimes \frac{\bbbq[x,y]}{\langle x, y \rangle}
\cong \frac{\bbbq[a,b,c]}{\langle ac \rangle} \, ,
\]
the fiber over the origin $\langle x,y \rangle$ in $\mathbb{A}^{2}$ is
clearly a union of two copies of $\bbbp^{1}$ meeting at one point.  In
particular, the exceptional fiber is not a projective space.\qed
\end{solution*}

Many other interesting blow-ups can be found in section~II.2 in
Eisenbud and Harris~\cite{SC:EH}.

%%----------------------------------------------------------
\section{A Classic Blow-up}

We consider the blow-up\index{blow-up} of the projective plane
$\bbbp^{2}$ at a point.

\vbox{
\begin{problem*}
Show that the following varieties are isomorphic.
\begin{enumerate}
\item[$(a)$] the image of the rational map from $\bbbp^{2}$ to
$\bbbp^{4}$ given by
\[
(r:s:t) \mapsto (r^{2}:s^{2}:rs:rt:st) \, ;
\]
\item[$(b)$] the blow-up of the plane $\bbbp^{2}$ at the point
$(0:0:1)$;
\item[$(c)$] the determinantal variety\index{determinantal variety}
defined by the $2 \times 2$ minors of the matrix $\left[
\begin{smallmatrix} a & c & d \\ b & d & e \end{smallmatrix} \right]$
where $\bbbp^{4} = \Proj\big( k[a,b,c,d,e] \big)$.
\end{enumerate}
This surface is called the {\em cubic scroll}\index{cubic scroll} in
$\bbbp^{4}$.
\end{problem*}
}

\begin{solution*}
We find the ideal in part~$(a)$ by elimination
theory\index{elimination theory}.
<<<PP4 = QQ[a..e];>>>
<<<S = QQ[r..t, A..E, MonomialOrder => Eliminate 3];>>>
<<<I = ideal(A - r^2, B - s^2, C - r*s, D - r*t, E - s*t);>>>
<<<phi = map(PP4, S, matrix{{0_PP4, 0_PP4, 0_PP4}} | vars PP4)>>>
<<<surfaceA = phi ideal selectInSubring(1, gens gb I)>>>
Next, we determine the surface in part~$(b)$.  We construct the ideal
defining the blow-up of $\bbbp^{2}$
<<<R = QQ[t, x, y, z, u, v, MonomialOrder => Eliminate 1];>>>
<<<blowUpIdeal = ideal selectInSubring(1, gens gb ideal(u-t*x,
     v-t*y))>>>
and embed it in $\bbbp^{2} \times \bbbp^{1}$.
<<<PP2xPP1 = QQ[x, y, z, u, v];>>>
<<<embed = map(PP2xPP1, R, 0 | vars PP2xPP1);>>>
<<<blowUp = PP2xPP1 / embed(blowUpIdeal);>>>
We then map this surface into $\bbbp^{5}$ using the Segre
embedding\index{Segre embedding}.
<<<PP5 = QQ[A .. F];>>>
<<<segre = map(blowUp, PP5, matrix{{x*u,y*u,z*u,x*v,y*v,z*v}});>>>
<<<ker segre>>>
Note that the image under the Segre map lies on a hyperplane in
$\bbbp^{5}$.  To get the desired surface in $\bbbp^{4}$, we project
<<<projection = map(PP4, PP5, matrix{{a, c, d, c, b, e}})>>>
<<<surfaceB = trim projection ker segre>>>
Finally, we compute the surface in part~$(c)$.
<<<determinantal = minors(2, matrix{{a, c, d}, {b, d, e}})>>>
<<<sigma = map( PP4, PP4, matrix{{d, e, a, c, b}});>>>
<<<surfaceC = sigma determinantal>>>
By incorporating a permutation of the variables into definition of
{\tt surfaceC}, we obtain the desired isomorphisms
<<<surfaceA == surfaceB>>>
<<<surfaceB == surfaceC>>>
<<<clearAll>>>
which completes the solution.\qed
\end{solution*}

For more information of the geometry of rational normal scrolls, see
Lecture~8 in Harris~\cite{SC:H}.

%%----------------------------------------------------------
\section{Fano Schemes}

Our final example concerns the family of Fano schemes\index{Fano
scheme} associated to a flat family of quadrics.
Recall that the $k$-th Fano scheme $F_{k}(X)$ of a
scheme $X \subseteq \bbbp^{n}$ is the subscheme of
the Grassmannian parametrizing $k$-planes
contained in $X$.

\begin{problem*}[Exercise~IV-69 in \cite{SC:EH}]
Consider the one-parameter family\index{one-parameter family} of
quadrics tending to a double plane with equation
\[
Q = V(tx^{2}+ty^{2}+tz^{2}+w^{2}) \subseteq \bbbp^{3}_{\bbbq[t]} =
\Proj\big(\bbbq[t][x,y,z,w]\big) \enspace .
\]
What is the flat limit\index{flat limit} of the Fano schemes
$F_{1}(Q_{t})$?
\end{problem*}

\begin{solution*}
We first compute the ideal defining $F_{1}(Q_{t})$, the scheme
parametrizing lines in $Q$.
<<<PP3 = QQ[t, x, y, z, w];>>>
<<<Q = ideal( t*x^2+t*y^2+t*z^2+w^2 );>>>
To parametrize a line in our projective space, we introduce
indeterminates $u, v$ and $A, \dotsc, H$.
<<<R = QQ[t, u, v, A .. H];>>>
We then make a map {\tt phi} from {\tt PP3} to {\tt R} sending the
variables to the coordinates of the general point on a line.
<<<phi = map(R, PP3, matrix{{t}} |
        u*matrix{{A, B, C, D}} + v*matrix{{E, F, G, H}});>>>
<<<imageFamily = phi Q;>>>
For a line to belong to $Q$, the {\tt imageFamily} must vanish
identically.  In other words, $F_{1}(Q)$ is defined by the
coefficients of the generators of {\tt imageFamily}.
%% removing a final use of 'coefficients'
%% coeffOfFamily = (coefficients ({1,2}, gens imageFamily))_1;
<<<coeffOfFamily = contract(matrix{{u^2,u*v,v^2}}, gens imageFamily)>>>
Since we don't need the variables $u$ and $v$, we get rid of them.
<<<S = QQ[t, A..H];>>>
<<<coeffOfFamily = substitute(coeffOfFamily, S);>>>
<<<Sbar = S / (ideal coeffOfFamily);>>>
Next, we move to the Grassmannian\index{Grassmannian} $\mathbb{G}(1,3)
\subset \bbbp^{5}$.  Recall the homogeneous coordinates on
$\bbbp^{5}$ correspond to the $2 \times 2$ minors of a $2 \times 4$
matrix.  We obtain these minors using the {\tt exteriorPower} function
in \Mtwo.
<<<psi = matrix{{t}} | exteriorPower(2,
            matrix{{A, B, C, D}, {E, F, G, H}})>>>
<<<PP5 = QQ[t, a..f];>>>
<<<fanoOfFamily = trim ker map(Sbar, PP5, psi);>>>
Now, to answer the question, we determine the limit as $t$ tends to $0$.
<<<zeroFibre = trim substitute(saturate(fanoOfFamily, t), {t=>0})>>>
Let's transpose the matrix of generators so all of its elements are visible
on the printed page.
<<<transpose gens zeroFibre>>>
We see that $F_{1}(Q_{0})$ is supported on the plane conic $\langle d,
e, f, a^{2}+b^{2}+c^{2} \rangle$.  However, $F_{1}(Q_{0})$ is not
reduced\index{scheme!non-reduced}; it has
multiplicity\index{multiplicity} two.  On the other hand, the generic
fiber is
<<<oneFibre = trim substitute(saturate(fanoOfFamily, t), {t => 1})>>>
<<<oneFibre == intersect(ideal(c-d, b+e, a-f, d^2+e^2+f^2),
     ideal(c+d, b-e, a+f, d^2+e^2+f^2))>>>
Hence, for $t \neq 0$, $F_{1}(Q_{t})$ is the union of two conics lying
in complementary planes and $F_{1}(Q_{0})$ is the double conic
obtained when the two conics move together.\qed
\end{solution*}

% Local Variables:
% mode: latex
% mode: reftex
% tex-main-file: "chapter-wrapper.tex"
% reftex-keep-temporary-buffers: t
% reftex-use-external-file-finders: t
% reftex-external-file-finders: (("tex" . "make FILE=%f find-tex") ("bib" . "make FILE=%f find-bib"))
% End:


\section{Linear transformations defined on a basis}

\begin{outcome}
  \begin{enumerate}
  \item Check whether two linear transformations are equal by
    considering their action on a spanning set.
  \item Specify a linear transformation by considering its action on a
    basis.
  \end{enumerate}
\end{outcome}

Recall that, by definition, two linear transformations $S,T:V\to W$
are equal if and only if for all $\vect{v}\in V$, we have
$S(\vect{v}) = T(\vect{v})$.  However, this is not a very practical
way of checking whether $S=T$, as it theoretically requires checking
$S(\vect{v}) = T(\vect{v})$ for each one of infinitely many vectors
$\vect{v}$. The following proposition states that it is sufficient to
check the actions of $S$ and $T$ on a spanning set of vectors.

\begin{proposition}{Equality of linear transformations}{transformation-spanning-set}
  Let $V$ and $W$ be vector spaces over a field $K$, and let
  $S,T:V\to W$ be linear transformations. Moreover, let $X\subseteq V$
  be a spanning set of $V$, i.e., such that $V=\sspan X$.
  If $S(\vect{v}) = T(\vect{v})$ for all $\vect{v}\in X$, then $S=T$.%
  \index{linear transformation!equality of}%
  \index{equality!of linear transformations}
\end{proposition}

\begin{proof}
  Assume that $S(\vect{v}) = T(\vect{v})$ holds for all $\vect{v}\in X$. To
  show that $S=T$, let $\vect{u}\in V$ be an arbitrary vector. Since
  $X$ is a spanning set, we can write
  $\vect{u}=a_1\vect{v}_1+\ldots+a_n\vect{v}_n$, for some
  $\vect{v}_1,\ldots,\vect{v}_n\in X$ and $a_1,\ldots,a_n\in K$.
  By assumption, $S(\vect{v}_i) = T(\vect{v}_i)$ for all $i$, because
  $\vect{v}_i\in X$. Then we have
  \begin{eqnarray*}
    S(\vect{u})
    &=& S(a_1\vect{v}_1+\ldots+a_n\vect{v}_n) \\
    &=& a_1S(\vect{v}_1)+\ldots+a_nS(\vect{v}_n) \\
    &=& a_1T(\vect{v}_1)+\ldots+a_nT(\vect{v}_n) \\
    &=& T(a_1\vect{v}_1+\ldots+a_n\vect{v}_n) \\
    &=& T(\vect{u}).
  \end{eqnarray*}
  Since $\vect{u}\in V$ was arbitrary, it follows that $S=T$.
\end{proof}

Therefore, if we know how a linear transformation acts on a spanning
set (and in particular, on a basis), then we know how it acts on the
entire space. There is also a kind of converse to this: given a basis
of $V$, we can map the basis vectors to any elements of $W$ we like,
and this will always determine a unique linear transformations. This
is the content of the following theorem.

\begin{theorem}{Linear transformation defined on a basis}{transformation-basis}
  Suppose $V$ and $W$ are vector spaces over a field $K$. Suppose
  $\vect{v}_1,\vect{v}_2,\ldots,\vect{v}_n$ is a basis of $V$, and
  $\vect{w}_1,\vect{w}_2,\ldots,\vect{w}_n$ are any vectors in $W$
  (which may or may not be distinct). Then there exists a unique
  linear transformation%
  \index{linear transformation!defined on a basis}
  $T:V\to W$ such that
  \begin{equation*}
    T(\vect{v}_1) = \vect{w}_1,
    \quad
    T(\vect{v}_2) = \vect{w}_2,
    \quad\ldots\quad
    T(\vect{v}_n) = \vect{w}_n.
  \end{equation*}
\end{theorem}

\begin{proof}
  To show that such a linear transformation $T$ exists, we first
  define a function $T:V\to W$ as follows. Given any $\vect{v}\in V$,
  there exists a unique set of coordinates $a_1,\ldots,a_n\in K$ such
  that
  \begin{equation*}
    \vect{v} = a_1\vect{v}_1 + \ldots + a_n\vect{v}_n.
  \end{equation*}
  Then define
  \begin{equation*}
    T(\vect{v}) = a_1\vect{w}_1 + \ldots + a_n\vect{w}_n.
  \end{equation*}
  This defines a function $T:V\to W$.  Next, we must check that $T$ is
  linear. To show that $T$ preserves addition, consider
  $\vect{v},\vect{v}'\in V$, with
  $\vect{v} = a_1\vect{v}_1 + \ldots + a_n\vect{v}_n$ and
  $\vect{v}' = b_1\vect{v}_1 + \ldots + b_n\vect{v}_n$.  Then
  \begin{eqnarray*}
    T(\vect{v}+\vect{v}')
    &=& T((a_1+b_1)\vect{v}_1 + \ldots + (a_n+b_n)\vect{v}_n) \\
    &=& (a_1+b_1)\vect{w}_1 + \ldots + (a_n+b_n)\vect{w}_n \\
    &=& (a_1\vect{w}_1 + \ldots + a_n\vect{w}_n)
        + (b_1\vect{w}_1 + \ldots + b_n\vect{w}_n) \\
    &=& T(\vect{v}) + T(\vect{v}').
  \end{eqnarray*}
  Therefore, $T$ preserves addition. To show that $T$ preserves scalar
  multiplication, consider $\vect{v} = a_1\vect{v}_1 + \ldots +
  a_n\vect{v}_n$ and $k\in K$. Then
  \begin{eqnarray*}
    T(k\vect{v})
    &=& T(ka_1\vect{v}_1 + \ldots + ka_n\vect{v}_n) \\
    &=& ka_1\vect{w}_1 + \ldots + ka_n\vect{w}_n \\
    &=& k(a_1\vect{w}_1 + \ldots + a_n\vect{w}_n) \\
    &=& kT(\vect{v}).
  \end{eqnarray*}
  Therefore, $T$ preserves scalar multiplication. It follows that $T$
  is linear. Next, we must show that $T$ satisfies the condition of
  the theorem, i.e., that $T(\vect{v}_i) = \vect{w}_i$ for each $i$.
  But this is clearly the case, because in this case, $a_i=1$ and
  $a_j=0$ for all $j\neq i$. We have shown that there exists a linear
  function $T$ satisfying all of the conditions required by the
  theorem.

  Finally, the only thing left to show is uniqueness. But this follows
  from Proposition~\ref{prop:transformation-spanning-set}. Namely, if
  $T'$ is another linear transformation such that
  $T'(\vect{v}_i) = \vect{w}_i$ for all $i$, then $T$ and $T'$ agree
  on $\vect{v}_1,\ldots,\vect{v}_n$, which is a basis and hence a
  spanning set. By Proposition~\ref{prop:transformation-spanning-set},
  $T=T'$.
\end{proof}

\begin{example}{Linear transformation defined on a basis}{transformation-basis}
  Recall that $\set{x^2, (x+1)^2, (x+2)^2}$ is a basis of $\Poly_2$.
  Consider the linear function $T:\Poly_2\to\Mat_{22}$ defined by
  \begin{equation*}
    T(x^2) = \begin{mymatrix}{rr} 1 & 1 \\ 0 & 0 \end{mymatrix},\quad
    T((x+1)^2) = \begin{mymatrix}{rr} 0 & 1 \\ 0 & 1 \end{mymatrix},\quad
    T((x+2)^2) = \begin{mymatrix}{rr} 0 & 0 \\ 1 & 1 \end{mymatrix}.
  \end{equation*}
  Find $T(4x)$.
\end{example}

\begin{solution}
  Let $\vect{v}_1=x^2$, $\vect{v}_2=(x+1)^2$, $\vect{v}_3=(x+2)^2$,
  $\vect{w}_1 = \begin{mysmallmatrix}{rr} 1 & 1 \\ 0 & 0 \end{mysmallmatrix}$,
  $\vect{w}_2 = \begin{mysmallmatrix}{rr} 0 & 1 \\ 0 & 1 \end{mysmallmatrix}$,
  and
  $\vect{w}_3 = \begin{mysmallmatrix}{rr} 0 & 0 \\ 1 & 1 \end{mysmallmatrix}$.
  We must first find $a,b,c$ such that
  $4x=a\vect{v}_1+b\vect{v}_2+c\vect{v}_3$. We do this by solving a
  system of equations, using the same method as in
  Example~\ref{exa:linear-combination-polynomials}. We find that
  $a=-3$, $b=4$, and $c=-1$.  Therefore
  \begin{equation*}
    T(4x)
    ~=~ T(-3\vect{v}_1 + 4\vect{v}_2 - \vect{v}_3)
    ~=~ -3\vect{w}_1 + 4\vect{w}_2 - \vect{w}_3
    ~=~ \begin{mymatrix}{rr}
      -3 & 1 \\
      -1 & 3 \\
    \end{mymatrix}.
  \end{equation*}
\end{solution}


\section{The Structure Theorem}
Until further notice, we take our ring to be a ED and we denote its Euclidean function by $\phi:R^\times\to\mathbb Z_{\ge 0}$.
let $A$ be an $m\times n$ matrix with entries in $R$.
\begin{definition}
    The elementary row operations are as follows:\\
    1. Add $\lambda\in R$ times the $j^{th}$ row to the $i^{th}$ row for $i\neq j$.\\
    2. Swap the $i^{th}$ and $j^{th}$ row.\\
    3. Multiply the $i^{th}$ row by a unit $u$.
\end{definition}
Note that all these operations are reversible.
Also, each of the operations may be realized by multiplying in the left by an $m\times m$ invertible matrix.
To wit, the first operation is the left multiplication of the matrix $I+\lambda E_{ij}$ where $E_{ij}$ is the matrix with $1$ on the $(i,j)$ entry and $0$ otherwise.
The second is $I+E_{ij}+E_{ji}-E_{ii}-E_{jj}$ and the third is $I+(u-1)E_{ii}$.
We can similarly define the column operations, and the realization becomes the matrix multiplication on the right by an $n\times n$ invertible matrix analogous to before.
\begin{definition}
    Two $m\times n$ matrices $A,B$ are equivalent if there is a sequence of elementary row and column operations taking $A$ to $B$.
\end{definition}
It is obvious that this is an equivalence relation due to reversibility.
So if $A,B$ are equivalent, there exists invertible square matrices $P,Q$ with $B=QAP$.
\begin{theorem}[Smith Normal Form]
    An $m\times n$ matrix $A=(a_{ij})$ with entries in $R$ is equivalent to a diagonal matrix of the form
    $$\begin{pmatrix}
        d_1&&&&&&\\
        &d_2&&&&&\\
        &&\ddots&&&&\\
        &&&d_t&&&\\
        &&&&0&&\\
        &&&&&\ddots&\\
        &&&&&&0
    \end{pmatrix}$$
    where $d_i\neq 0$ for all $i$ and $d_1|d_2|\cdots |d_t$.
\end{theorem}
The $d_i$'s are called covariant factors and are unique up to associates (show later).
\begin{proof}
    If $A=0$ then we are done.
    So assume that $a_{11}\neq 0$.
    Suppose $a_{11}\nmid a_{1j}$ for some $j\ge 2$, then we use the Euclidean algorithm to get $a_{1j}=qa_{11}+r$ with $q,r\in R$ and $\phi(r)<\phi(a_{11})$.
    So we substract $q$ times the first column from the $j^{th}$ column and swap them.
    This makes the top left entry $r$.
    Likewise, we can do the same thing if $a_{11}\nmid a_{i1}$ for some $i\ge 2$ by row operations.
    The cases above each decrease the top left entry (in terms of its value in the Euclidean function), thus it must eventually stops, at which time $a_{11}$ divides everything in the first row or the first column.
    Then substracting multiples of the first row or first column can clear up every other entry in the first column or first row except $a_{11}$.
    Now if $a_{11}$ does not divide $a_{ij}$ for $i,j\ge 2$, then add the $i^{th}$ row to the first row, and so we can do the same column operations to decrease $\phi(a_{11})$ further till it terminates.
    Do this over and over again (but finitely many times) we can get $a_{11}|a_{ij}$ for any $i,j\ge 2$ and $a_{ij}=0$ whenever $i\neg j$ and one of $i,j$ is $1$.
    We rename $a_{11}$ as $d_1$ and repeat the process on the smaller matrix by removing the first row and first column to give the existence.
\end{proof}
\begin{definition}
    A $k\times k$ minor of a matrix $A$ is the determinant of a $k\times k$ submatrix of $A$.
\end{definition}
\begin{definition}
    For a matrix $A$ over a ring $R$, we define the $k^{th}$ Fitting ideal $\operatorname{Fit}_k(A)$ be the ideal generated by all the $k\times k$ minors of $A$.
\end{definition}
\begin{lemma}
    If $A,B$ are equivalent matrices, then $\operatorname{Fit}_k(A)=\operatorname{Fit}_k(B)$ for any $k$ (such that the Fitting ideal makes sense).
\end{lemma}
\begin{proof}
    Suffices to show that the elementary operations do not change the Fitting ideal.
    The second and third row operations are trivial.
    For the first kind of row operation, suppose we add $\lambda$ times the second row to the first row so that $A=(a_{ij})$ becomes
    $$A'=\begin{pmatrix}
        a_11+\lambda a_{21}&a_{12}+\lambda a_{22}&\dots&a_{1n}+\lambda a_{2n}\\
        a_{21}&a_{22}&\dots&a_{2n}\\
        \vdots&\vdots&\ddots&\vdots\\
    \end{pmatrix}$$
    Let $C$ be a $k\times k$ submatrix of $A$ and $C'$ be its correspondent submatrix in $A'$.
    If $C$ does not intersect the first row, then $\det C=\det C'$.
    If $C$ intersect both the first and second row, we also have $\det C=\det C'$ since its simply a row operation on the $k\times k$ submatrix.
    If $C$ intersects the first but not the second row, then by expanding along the first row, the determinant of $\det C'$ would be $\det C+\lambda\det D$ for some other $k\times k$ submatrix of $A$.
    So $\det C'\in \operatorname{Fit}_k(A)$, so $\operatorname{Fit}_k(A')\subset \operatorname{Fit}_k(A)$.
    Since row operations are reversible, we also have the reverse inclusion.
\end{proof}
\begin{proposition}
    The covarient factors are unique up to associates.
\end{proposition}
\begin{proof}
    Look at the Fitting ideals.
\end{proof}
\begin{example}
    Consider the following matrix (here $\to$ represents row/column operations)
    $$A=\begin{pmatrix}
        2&-1\\
        1&2
    \end{pmatrix}\to\begin{pmatrix}
        1&-1\\
        3&2
    \end{pmatrix}\to\begin{pmatrix}
        1&0\\
        3&5
    \end{pmatrix}\to\begin{pmatrix}
        1&0\\
        0&5
    \end{pmatrix}$$
    One can also get its Smith normal form by considering the minors.
    Indeed, $\operatorname{Fit}_1(A)=(1)$, so $d_1=\pm 1$.
    Also $\operatorname{Fit}_2(A)=(5)$, hence $d_2=\pm 5$.
    So we obtain the Smith normal form.
\end{example}
\begin{theorem}
    Let $R$ be an Euclidean domain and $N$ is an $R$-submodule of $R^n$, then there is a free basis $x_1,\ldots,x_m$ of $R^m$ such that $N$ is generated as an $R$-module by $d_1x_1,\ldots,d_tx_t$ for some $t\le m$ and $d_1|d_2|\cdots|d_t$.
\end{theorem}
\begin{proof}
    $R$ is a ED hence a PID, hence $N$ is generated by some $y_1,\ldots,y_n$ for some $n\le m$.
    Now each $y_i$ is in $R^n$, so we can form an $n\times n$ matrix $A$ whose columns are the $y_i$'s.
    By the preceding theorem, $A$ is equivalent to $A'=\operatorname{diag}(d_1,\ldots,d_t,0,\ldots,0)$ with $t\le n$ and $d_1|d_2|\ldots|d_t$.
    Now $A'$ is obtained from $A$ by elementary row and column operations.
    Each row operation corresponds to changing of our choice of free basis for $R^n$, and every column operation changes the generating set for $R^n$.
    So after changing the free basis for $R^n$ to, say, $x_1,\ldots, x_n$, then $N$ is generated by $d_1x_1,\ldots,d_tx_t$.
\end{proof}
\begin{theorem}[Structure Theorem]
    Let $R$ be a Euclidean Domain and $M$ a finitely-generated $R$-module, then $M\cong R/(d_1)\oplus\cdots\oplus R/(d_t)\oplus R\oplus\cdots\oplus R$ for some $d_i\in R$ and $d_1|d_2|\cdots|d_t$.
\end{theorem}
These $d_i$'s are called invariant factors.
\begin{proof}
    Since $M$ is finitely generated, then we can find a surjective $R$-module map $\phi:R^m\to M$ for some $m$.
    Then $M\cong R^m/\ker\phi$, but by the preceding theorem, there exists a free basis $x_1,\ldots,x_n$ for $R^m$ such that $N=\ker\phi=Rd_1x_1+\cdots Rd_tx_t$ for $d_1|d_2|\cdots|d_t$, hence
    $$M\cong\frac{R\oplus R\oplus\cdots\oplus R\oplus R\oplus\cdots\oplus R}{Rd_1\oplus Rd_2\oplus\cdots\oplus Rd_t\oplus 0\oplus\cdots\oplus 0}\cong R/(d_1)\oplus\cdots\oplus R/(d_t)\oplus R\oplus\cdots\oplus R$$
    which is what we wanted.
\end{proof}
\begin{definition}
    Let $M$ be an $R$-module.
    An element $m\in M$ is called torsion if $\exists r\in R\setminus\{0\},rm=0$.\\
    $M$ is called a torsion module if every $m\in M$ is torsion.
    $M$ is called torsion-free if the only torsion is $0$.
\end{definition}
\begin{corollary}
    Let $R$ be an Euclidean domain, then any finitely generated torsion-free $R$-module is free.
\end{corollary}
\begin{proof}
    By the preceding theorem $M\cong R/(d_1)\oplus\cdots\oplus R/(d_t)\oplus R\oplus\cdots\oplus R$, but as $M$ is torsion-free, it cannot contain any of $R/(d_i)$ as $R$-submodule as they would contain torsions.
    Hence $M\cong R\oplus\cdots\oplus R$, therefore $M$ is free.
\end{proof}
\begin{remark}
    The structure theorem in fact holds whenever $R$ is a PID.
    Also, there is also a uniqueness statement in the structure theorem: Suppose no $d_i$'s is a unit (otherwise they only contribute $0$ factors to the product), then the module $M$ uniquely determines $d_1,\ldots,d_t$.
\end{remark}
\begin{example}
    Consider an abelian groupn $G$ generated by $a,b$ subject to relations $2a+b=-a+2b=0$.
    So $G\cong\mathbb Z^2/N$ where $N$ is generated by $(2,1),(-1,2)$, so we take (as in the proof of the structure theorem)
    $$A=\begin{pmatrix}
        2&-1\\
        1&2
    \end{pmatrix}\to\begin{pmatrix}
        1&0\\
        0&5
    \end{pmatrix}$$
    as seen before.
    So we can change basis for $\mathbb Z^2$ to generate $N$ by $(1,0),(0,5)$, hence $G\cong\mathbb Z\oplus\mathbb Z/(\mathbb Z\oplus 5\mathbb Z)\cong\mathbb Z/5\mathbb Z$.
\end{example}
More generally, for finitely generated abelian groups, we have the following:
\begin{theorem}
    Any finitely generated abelian group $G$ is isomorphic to
    $$\mathbb Z/d_1\mathbb Z\oplus\cdots\oplus\mathbb Z/d_t\mathbb Z\oplus\mathbb Z^r$$
    where $r\ge 0$ and $d_1|d_2|\cdots|d_t$.
\end{theorem}
The $r$ here stands for the rank of the group.
\begin{proof}
    Take $R=\mathbb Z$ in the structure theorem.
\end{proof}
In the special case that $G$ is finite, we immediately obtain Theorem \ref{fin_abe_struct}.
\begin{remark}
    Let $A,B$ be square matrices over $R$, then $\det (AB)=\det A\det B$, also $\operatorname{adj}(A)A=A\operatorname{adj}(A)=\det(A)I$.
    In particular, $A$ is invertible iff $\det A$ is a unit.
\end{remark}
\begin{theorem}[Cayley-Hamilton]
    Let $A=(a_{ij})$ be a $n\times n$ matrix over a field $F$.
    Let $\chi_A(X)=\det (XI-A)\in F[X]$, then $\chi_A(A)=0$.
\end{theorem}
\begin{proof}
    Consider $V=F^n$ as a $F[X]$-module. with $X$ acting as $A$, i.e. $f(X)\cdot v=f(A)v$.
    Let $e_1,\ldots,e_n$ be the standard basis for $F^n$, so for any $j$, $X\cdot e_j=\sum_{i=1}^na_{ij}e_i$, hence
    $$(XI-A)\begin{pmatrix}
        e_1\\
        \vdots\\
        e_n
    \end{pmatrix}=0$$
    By multiplying both sides by the adjugate of $XI-A$, we know that for any $i$,
    $$\chi_A(X)\cdot e_i=\det(XI-A)\cdot e_i=0\implies\chi_A(A)e_i=0$$
    But this can only happen when $\chi_A(A)=0$.
\end{proof}
Recall that we have mentioned Theorem \ref{classify_fin_abe}, which is yet another way of classifying the finite abelian groups by writing it as a product of cyclic $p$-groups.
Indeed, we can achieve this by generalising our structure theorem one step further.
\begin{lemma}
    Let $R$ be a PID and $a,b\in R$ has $\gcd(a,b)=1$ (up to associates), then there is an isomorphism of $R$-modules
    $$R/(ab)\cong R/(a)\oplus R/(b)$$
\end{lemma}
\begin{proof}
    Since $R$ is a PID, $(a,b)=(d)$ for some $d\in R$, so $d=\gcd(a,b)$ by certain questions in example sheet.
    Hence $(a,b)=R$ since $d$ must be a unit by hypothesis, so there is $r,s\in R$ with $ra+sb=1$.
    Define an $R$-module homomorphism $\phi:R\to R/(a)\oplus R/(b)$ by $x\mapsto (x+(a),x+(b))$.
    To see it is surjective, $\phi(sb)=(1+(a),0+(b)),\phi(ra)=(0+(a),1+(b))$, hence $\phi(sbx+ray)=(x+(a),y+(b))$.
    Now if $\phi(x)=(0+(a),0+(b))$, then $x\in (a)\cap(b)$, so $x=x(ra+sb)=rax+sxb\in (ab)$.
    It is obvious that anything in $(ab)$ is mapped to zero, hence $\ker\phi=(ab)$, so we deduce the theorem from isomorphism theorem.
\end{proof}
This reduced to Chinese Remainder Theorem when we set $R=\mathbb Z$.
\begin{theorem}[Prime Decomposition Theorem]\label{prime_decomp}
    Let $R$ be a ED and let $M$ be a finitely generated $R$-module.
    Then
    $$M\cong R/(p_1^{n_1})\oplus\cdots\oplus R/(p_k^{n_k})\oplus R^m$$
    where $p_1,\ldots,p_k$ are prime in $R$.
\end{theorem}
Note that $p_1,\ldots,p_k$ need not to be distinct.
\begin{proof}
    By the structure theorem, we have
    $$M\cong R/(d_1)\oplus\cdots\oplus R/(d_t)\oplus R^m$$
    So it suffices to write each $R/(d_i)$ in the desired form.
    Choose $i$ and write $d_i=up_1^{\alpha_1}\cdots p_r^{\alpha_r}$ where $p_i$ are pairwise non-associates and $u$ is a unit.
    So by the preceding lemma, we have
    $$R/(d_i)\cong R/(p_1^{\alpha_1})\oplus\cdots\oplus R/(p_r^{\alpha_r})$$
    which establishes the theorem.
\end{proof}
Note that Theorem \ref{classify_fin_abe} is a direct consequence of this.\\
Let $V$ be a vector space over a field $F$ and let $\alpha:V\to V$ be an endomorphism, then we can make $V$ an $F[X]$-module (written as $V_\alpha$) by $f(X)\cdot v=f(\alpha)v$.
\begin{lemma}
    If $V$ is finite-dimensional, then $V_\alpha$ is finitely generated as an $F[X]$-module.
\end{lemma}
\begin{proof}
    If $v_1,\ldots,v_n$ generates $V$ as a vector space, then they also generate $V_\alpha$ as an $F[X]$-module since $F\le F[X]$.
\end{proof}
The lemma itself is trivial, but the thing to take from here is that $V_\alpha$, being also an $F$-vector space, is isomorphic to $V$.
This is very useful if we want to analyze the behaviour of $\alpha$ in $V$:
If we know that $V_\alpha$ is isomorphic to some $F[X]$-modules (via e.g. Theorem \ref{prime_decomp}) that are easier to study, then they are also automatically isomorphic as $F$-vector spaces.
So by choosing a nice basis for this $F[X]$-module (as a vector space), we can obtain a nice matrix of $\alpha$.
\begin{example}
    1. Suppose $V_\alpha\cong F[X]/(X^n)$ as $F[X]$-module, then we can choose the basis $1,X,\ldots,X^{n-1}$ for it to be an $F$-vector space, so $\alpha$ would have matrix
    $$(\star)=\begin{pmatrix}
        0&&&\\
        1&0&&\\
        &\ddots&\ddots&\\
        &&1&0
    \end{pmatrix}$$
    Since $\alpha$ acts as multiplication by $X$.\\
    2. Suppose $V_\alpha\cong F[X]/(X-\lambda)^n$ as an $F[X]$-module, then wrt the basis $1,X-\lambda,\ldots,(X-\lambda)^{n-1}$, $\alpha-\lambda\operatorname{id}$ has matrix $(\star)$, so $\alpha$ exists as a Jordan block.\\
    3. Suppose $V_\alpha\cong F[X]/(f)$ where $f\in F[X]$ is in the form $f(X)=a_0+a_1X+\cdots +a_{n-1}X^{n-1}+X^n$, then with respect to $1,X,\ldots,X^{n-1}$, $\alpha$ has the matrix
    $$C(f)=\begin{pmatrix}
        0&&&-a_0\\
        1&\ddots&&-a_1\\
        &\ddots&0&\vdots\\
        &&1&-a_{n-1}
    \end{pmatrix}$$
    which is called the companion matrix of $f$.
\end{example}
\begin{theorem}[Rational Canonical Form]
    Let $\alpha:V\to V$ be an endomorphism of a finite dimensional vector space $V$ over a field $F$, then
    $$V_\alpha\cong F[X]/(f_1)\oplus\cdots\oplus F[X]/(f_t)$$
    where $f_i\in F[X]$ are monic and $f_1|f_2|\cdots|f_t$.
    Moreover, with respect to a suitably chosen basis for $V$, $\alpha$ has matrix of the form
    $$\begin{pmatrix}
        C(f_1)&&&\\
        &C(f_2)&&\\
        &&\ddots&\\
        &&&C(f_t)
    \end{pmatrix}$$
\end{theorem}
\begin{proof}
    $V_\alpha$ is finitely generated as an $F[X]$-module and since $F[X]$ is a ED, we can apply the structure theorem to get
    $$V_\alpha\cong F[X]/(f_1)\oplus\cdots\oplus F[X]/(f_t)\oplus F[X]^m$$
    where $f_i\in F[X]$ are monic and $f_1|f_2|\cdots|f_t$.
    $m=0$ since $V$ is finite dimensional over $F$.
    The result is immediate.
\end{proof}
\begin{remark}
    1. If we start by an $n\times n$ matrix of $\alpha$, then this matrix must be similar to the above form.\\
    2. The minimal polynomial of $\alpha$ is $f_t$.\\
    3. The characteristic polynomial of $\alpha$ is $f_1\cdots f_t$ (up to associates).
    Hence the minimal polynomial divides the characteristic polynomial, so we immediately have Cayley-Hamilton.
\end{remark}
\begin{example}
    When $V$ is $2$-dimensional vector space over $F$, then one of the following cases happen
    $$V_\alpha\cong F[X]/(X-\lambda_1)\oplus F[X]/(X-\lambda_2),V_\alpha\cong F[X]/(f)$$
    where $(X-\lambda_1)(X-\lambda_2)$ or $f$ is the characteristic polynomial of $\alpha$.
\end{example}
\begin{corollary}
    Let $A,B\in\operatorname{GL}_2(F)$ that are not scalar matrices, then $A,B$ are conjugate iff they have the same characteristic polynomial.
\end{corollary}
\begin{proof}
    Immediate.
\end{proof}
\begin{lemma}
    Primes in $\mathbb C[X]$ are polynomials $X-\lambda$ where $\lambda$ is any complex number (up to associates).
\end{lemma}
\begin{proof}
    FTA.
\end{proof}
\begin{theorem}[Jordan Normal Form]
    Let $\alpha:V\to V$ be an endomorphism of a finite dimensional vector space over $\mathbb C$.
    Let $V_\alpha$ be $V$ as the $\mathbb C[X]$-module with $X$ acting as $\alpha$.
    Then there is an isomorphism of $\mathbb C[X]$-modules
    $$V_\alpha\cong\mathbb C[X]/(X-\lambda_1)^{n_1}\oplus\cdots\oplus\mathbb C[X]/(X-\lambda_t)^{n_t}$$
    where $\lambda_i\in\mathbb C$ are not necessarily distinct and $n_i\in\mathbb N$.
    In particular, there is a basis for $V$ such that $\alpha$ has the matrix
    $$\begin{pmatrix}
        J_{n_1}(\lambda_1)&&\\
        &\ddots&\\
        &&J_{n_t}(\lambda_t)
    \end{pmatrix},J_n(\lambda)=\begin{pmatrix}
        \lambda&&&\\
        1&\lambda&&\\
        &\ddots&\ddots&\\
        &&1&\lambda
    \end{pmatrix}$$
\end{theorem}
\begin{proof}
    We know that $\mathbb C[X]$ is a ED and $V_\alpha$ is finitely generated as $V$ is finite dimensional.
    By Prime Decomposition Theorem, noting that primes in $\mathbb C[X]$ are linear factors, and we cannot have any copy of $\mathbb C[X]$ as the dimension is finite.
    Then we already have the isomorphism.
    Now $J_n(\lambda)$ represents the multiplication by $X$ on $\mathbb C[X]/(X-\lambda)^n$ wrt the basis $1,X-\lambda,\ldots,(X-\lambda)^{n-1}$.
    This shows the theorem.
\end{proof}
\begin{remark}
    1. The theorem implies that any matrix with entries in $\mathbb C$ is similar to a matrix in the said form.\\
    2. The Jordan blocks are unique up to reordering.\\
    3. The minimal polynomial of $\alpha$ is $\prod_i(X-\lambda_i)^{c_i}$ where $c_i$ is the size of the largest block with eigenvalue $\lambda_i$.\\
    4. The characteristic polynomial of $\alpha$ is $\prod_i(X-\lambda_i)^{a_i}$ where $a_i$ is the sum of the sizes of the blocks with eigenvalue $\lambda_i$.\\
    5. The eigenspace of $\lambda_i$ has dimension equal to the number of blocks with eigenvalue $\lambda$.\\
    6. The uniqueness statement may be proved by considering the dimension of the generalized eigenspaces $\ker((\alpha-\lambda_iI)^n)$, $n=1,2,\ldots$.
\end{remark}
\begin{theorem}
    The structure theorem is true for any PIDs.
\end{theorem}
We will not prove this in the course, but we will illustrate the trick that is used for this extension.
\begin{theorem}\label{pid_tf_free}
    Let $R$ be a PID, then any finitely generated torsion-free $R$-module is free.
\end{theorem}
Note that for $R$ a ED, this is a corollary of the structure theorem.
\begin{lemma}
    Let $R$ be a PID and $M$ an $R$-module.
    Let $r_1,r_2\in R$ that are not both $0$.
    Let $d=\gcd(r_1,r_2)$.\\
    1. There is a matrix $A\in\operatorname{SL}_2(R)$ such that
    $$A\begin{pmatrix}
        r_1\\
        r_2
    \end{pmatrix}=\begin{pmatrix}
        d\\
        0
    \end{pmatrix}$$
    2. If $x_1,x_2\in M$, then there is $x_1',x_2'\in M$ such that $Rx_1+Rx_2=Rx_1'+Rx_2'$ and $r_1x_1+r_2x_2=dx_1'+0x_2'$.
\end{lemma}
\begin{proof}
    We know that $(r_1,r_2)=(d)$, so there is $\alpha,\beta\in R$ such that $\alpha r_1+\beta r_2=d$.
    Write $r_1=s_1d,r_2=s_2d$ with $s_1,s_2\in R$.
    We simply take the matrix
    $$A=\begin{pmatrix}
        \alpha&\beta\\
        -s_2&s_1
    \end{pmatrix}\in\operatorname{SL}_2(R)$$
    and it works for the first part.
    For the second part, we can take $x_1'=s_1x_1+s_2x_2,x_2'=-\beta x_1+\alpha x_2$.
\end{proof}
\begin{proof}[Proof of Theorem \ref{pid_tf_free}]
    Say $M=Rx_1+\cdots+Rx_n$ with $n$ minimal.
    If $x_1,\ldots,x_n$ are independent, then the module is free.
    Otherwise, there is $r_1,\ldots,r_n\in R$ such that $r_1x_1+\cdots+r_nx_n=0$ where WLOG $r_1\neq 0$.
    By the preceding lemma, we can choose $x_1',x_2'$ such that $Rx_1+Rx_2=Rx_1'+Rx_2'$, so $M=Rx_1'+Rx_2'+Rx_3+\cdots+Rx_n$ and $dx_1'+r_3x_3+\cdots+r_nx_n=0$ for $d=\gcd(r_1,r_2)\neq 0$.
    Continue the process to $3,\ldots,n$ to reduce the case to $rx_1=0$ for some $r\neq 0$, but $R$ is torsion-free, so $x_1=0$, contradicting the minimality of $n$.
\end{proof}


\subsubsection{Time Series Normalization} \label{time_series_normalization}
When using DTW to determine the similarity of two time series, it is a common approach to z-normalize or Z-score the
time series in front of the calculation \cite{ding2008querying}. In \cite{das1998rule} two different time series
normalizations are presented. Both time series normalizations $\eta$ and $\eta '$ are explained in the following
section.

Given is a time series $Q = (q_1, q_2, \dots, q_i, \dots, q_l)$ with length $l$ over the domain set $\mathbb{U}$ and a
distance measure function $d$ with $d: \mathbb{U} \times \mathbb{U} \to \mathbb{R}$. The first time series normalization
$\eta$ transforms every data
point of the given time series $Q$ as follows.
\begin{equation}
    \eta (q) = q -\bar{q}
\end{equation}
where $\bar{q}$ is the mean of the time series $Q$
\begin{equation}
    \bar{q} = \frac{1}{l} \sum \limits_{i=1}^{l} q_i
\end{equation}
Figure \ref{fig:norm1} shows the impact of the $\eta$ normalization on DTW compared to plain DTW in figure
\ref{fig:dynamictimewarping}.

\begin{figure}
    \begin{center}
        \resizebox {\textwidth} {!} {
            \begin{tabular}{cc}
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            xmin=0,
                            xmax=47,
                            xlabel=time,
                            ylabel=acceleration,
                            width=\axisdefaultwidth,
                            height=0.7*\axisdefaultheight,
                            reverse legend,
                            legend pos=south east]
                            \addplot[gray, quiver={u=\thisrow{u}, v=\thisrow{v}}] table {../data/fig/norm1/path.dat};
                            \addplot[red, thick, mark=none] table {../data/fig/norm1/q.dat};
                            \addlegendentry{Q}
                            \addplot[blue, thick, mark=none] table {../data/fig/norm1/c.dat};
                            \addlegendentry{C}
                        \end{axis}
                    \end{tikzpicture}
                } & \quad
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tabular}[b]{ll}
                        \begin{turn}{90}
                            \begin{tikzpicture}
                                \begin{axis}[
                                    xmin=0,
                                    xmax=47,
                                    ymin=-40,
                                    ymax=40,
                                    hide x axis,
                                    hide y axis,
                                    width=\axisdefaultwidth,
                                    height=0.7*\axisdefaultheight]
                                    \addplot[red, ultra thick, mark=none] table {../data/fig/norm1/q.dat};
                                \end{axis}
                            \end{tikzpicture}
                        \end{turn} \hspace*{3em} &
                        \begin{tikzpicture}
                            \begin{axis}[
                                enlargelimits=false,
                                ymin=0,
                                ymax=47,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=\axisdefaultwidth,
                                colorbar,
                                colormap/viridis high res]
                                \addplot[matrix plot*,
                                    mesh/cols=48,
                                    point meta=explicit] table[meta=C] {../data/fig/norm1/matrix.dat};
                                \addplot[white, ultra thick, mark=*, mark size=1] table {../data/fig/norm1/matrix_path.dat};
                            \end{axis}
                        \end{tikzpicture}\\
                        &
                        \\[1em]
                        &
                        \begin{tikzpicture}
                            \begin{axis}[
                                xmin=0,
                                xmax=47,
                                ymin=-40,
                                ymax=40,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=0.7*\axisdefaultheight]
                                \addplot[blue, ultra thick, mark=none] table {../data/fig/norm1/c.dat};
                            \end{axis}
                        \end{tikzpicture}
                    \end{tabular}
                }
            \end{tabular}
        }
    \end{center}
    \caption{The same two time series $Q$ and $C$ from figure \ref{fig:dynamictimewarping} normalized by $\eta$. On the
    left plot are both time series graphs, the gray lines are representing the warping path of plain DTW. The right plot
    shows the associated matrix containing the distances between the time series data points. Starting in the lower left
    corner and ending in the upper right corner, the warping path is illustrated as a white graph.}
    \label{fig:norm1}
\end{figure}

The second time series normalization $\eta '$ transforms every data point of the given time series $Q$ as follows.
\begin{equation}
    \eta '(q) = \frac{\eta (q)}{\sigma}
\end{equation}
where $\sigma$ is the standard deviation of the time series $Q$
\begin{equation}
    \sigma = \frac{1}{l-1} \sum \limits_{i=1}^{l} d(q_i, \bar{q})^2
\end{equation}
Figure \ref{fig:norm2} shows the impact of the $\eta '$ normalization on DTW compared to plain DTW in
figure \ref{fig:dynamictimewarping}.

\begin{figure}
    \begin{center}
        \resizebox {\textwidth} {!} {
            \begin{tabular}{cc}
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            xmin=0,
                            xmax=47,
                            xlabel=time,
                            ylabel=acceleration,
                            width=\axisdefaultwidth,
                            height=0.7*\axisdefaultheight,
                            reverse legend,
                            legend pos=south east]
                            \addplot[gray, quiver={u=\thisrow{u}, v=\thisrow{v}}] table {../data/fig/norm2/path.dat};
                            \addplot[red, thick, mark=none] table {../data/fig/norm2/q.dat};
                            \addlegendentry{Q}
                            \addplot[blue, thick, mark=none] table {../data/fig/norm2/c.dat};
                            \addlegendentry{C}
                        \end{axis}
                    \end{tikzpicture}
                } & \quad
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tabular}[b]{ll}
                        \begin{turn}{90}
                            \begin{tikzpicture}
                                \begin{axis}[
                                    xmin=0,
                                    xmax=47,
                                    ymin=-2,
                                    ymax=2,
                                    hide x axis,
                                    hide y axis,
                                    width=\axisdefaultwidth,
                                    height=0.7*\axisdefaultheight]
                                    \addplot[red, ultra thick, mark=none] table {../data/fig/norm2/q.dat};
                                \end{axis}
                            \end{tikzpicture}
                        \end{turn} \hspace*{3em} &
                        \begin{tikzpicture}
                            \begin{axis}[
                                enlargelimits=false,
                                ymin=0,
                                ymax=47,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=\axisdefaultwidth,
                                colorbar,
                                colormap/viridis high res]
                                \addplot[matrix plot*,
                                    mesh/cols=48,
                                    point meta=explicit] table[meta=C] {../data/fig/norm2/matrix.dat};
                                \addplot[white, ultra thick, mark=*, mark size=1] table {../data/fig/norm2/matrix_path.dat};
                            \end{axis}
                        \end{tikzpicture}\\
                        &
                        \\[1em]
                        &
                        \begin{tikzpicture}
                            \begin{axis}[
                                xmin=0,
                                xmax=47,
                                ymin=-2,
                                ymax=2,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=0.7*\axisdefaultheight]
                                \addplot[blue, ultra thick, mark=none] table {../data/fig/norm2/c.dat};
                            \end{axis}
                        \end{tikzpicture}
                    \end{tabular}
                }
            \end{tabular}
        }
    \end{center}
    \caption{The same two time series $Q$ and $C$ from figure \ref{fig:dynamictimewarping} normalized by $\eta '$. On the
    left are plot both time series graphs, the gray lines are representing the warping path of plain DTW. The right plot
    shows the associated matrix containing the distances between the time series data points. Starting in the lower left
    corner and ending in the upper right corner, the warping path is illustrated as a white graph.}
    \label{fig:norm2}
\end{figure}


\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{fancyhdr}
\usepackage[margin=.7in]{geometry}
\usepackage{exsheets}
\usepackage{enumerate}

\usepackage{./Style/linearProgramsStyle} % This is a set of commands for maths content.

\pagestyle{fancy}

\renewcommand{\headrulewidth}{2pt}
\fancyhead[L]{EPITA\_ING1\_BING\_2020\_S5\_PROL}
\fancyhead[R]{January 2018}

\fancyfoot[C]{\textbf{\thepage}}
\fancyfoot[L]{}

\pretitle{\vspace{-.5\baselineskip} \begin{center}}
\title{%
  { \huge Linear Programming (PROL)}%
}
\posttitle{
\end{center}
  \begin{flushleft}
    \vspace{3\baselineskip} \textit{
      \!\!\emph{Duration: 1h30.}\\
      \! \emph{No documents are allowed.}  \\
      Only \emph{non-programmable} pocket calculators are allowed.
    }
  \end{flushleft}
  \rule{\textwidth}{1.5pt}
  \vspace{-5\baselineskip}
}
\author{}
\date{}

\pdfinfo{
   /Author (Bashar Dudin)
   /Title  (PROL Exam -- 2018)
   /Subject (Linear Programming)
}

\begin{document}

\maketitle\thispagestyle{fancy}

We're considering the following list of linear programs respectively
given the names $(A)$, $(B)$, $(C)$, $(D)$ and $(E)$, $(F)$.
\[
(A) \;
\left\{
  \begin{linearProg}{
      maximize
    }{
      $x_1 + x_2 + x_3$
    }{
      \systeme{
        2x_1 + 3x_2 + x_3 \leq 1,
        x_1 - 4x_2 + 3x_3 \geq 2
      }
    }{
      $x_1$, $x_2 \geq 0.$
    }
  \end{linearProg}
\right.
\qquad (B)\;
\left\{
  \begin{linearProg}{
      minimize
    }{
      $- x_1 - x_2 - x_3 + x_4$
    }{
      \systeme{
        2x_1 + 3x_2 + x_3 - x_4 + \leq 1,
        -x_1 + 4x_2 - 3x_3 + 3x_4 \leq -2
      }
    }{
      $x_1$, $x_2$, $x_3$, $x_4 \geq 0.$
    }
  \end{linearProg}
\right.
\]
\[
(C) \;
\left\{
  \begin{linearProg}{
      minimize
    }{
      $-5x_1 - 6x_2 - 9x_3 - 8x_4$
    }{
      \systeme{
        x_1 + 2x_2 + 3x_3 + x_4 \leq 5,
        -x_1 - x_2 - 2x_3 - 3x_4 \geq -3
      }
    }{
      $x_1$, $x_2$, $x_3$, $x_4 \geq 0.$
    }
  \end{linearProg}
\right.
\qquad (D) \;
\left\{
  \begin{linearProg}{
      maximize
    }{
      $5x_1 + 6x_2 + 9x_3 + 8x_4$
    }{
      \systeme{
        x_1 + 2x_2 + 3x_3 + x_4 \leq 5,
        x_1 + x_2 + 2x_3 + 3x_4 \leq 3
      }
    }{
      $x_1$, $x_2$, $x_3$, $x_4 \geq 0.$
    }
  \end{linearProg}
\right.
\]
\[
(E) \;
\left\{
  \begin{linearProg}{
      maximize
    }{
      $x_1 - 2x_2 - x_3$
    }{
      \systeme{
        2x_1 + x_2 - x_3 \leq -1,
        x_1 - 2x_2 + x_3 \leq -2
      }
    }{
      $x_1$, $x_2$, $x_3 \geq 0.$
    }
  \end{linearProg}
\right.\qquad (F)\;
\left\{
  \begin{linearProg}{
      maximize
    }{
      $5x_1 + 6x_2 + 9x_3 + 8x_4$
    }{
      \systeme{
        x_1 + 2x_2 + 3x_3 + x_4 \leq 5,
        x_1 + x_2 + 2x_3 + 3x_4 + x_5 = 3
      }
    }{
      $x_1$, $x_2$, $x_3$, $x_4$, $x_5 \geq 0.$
    }
  \end{linearProg}
\right.
\]

\section{Equivalence and Duality}

\begin{question}
  Which previous programs are equivalent to each others? Sort them
  into groups of equivalent classes.
\end{question}

\begin{question}
  Give standard form of $(F)$. What is the slack form of $(E)$?
\end{question}

\begin{question}
  What are the dual programs $(C)$ and $(D)$?
\end{question}

\begin{question}
  Which programs $(D)$, $(E)$ and $(F)$ have basic feasible
  solution?  Give a feasible solution of $(A)$.
\end{question}

\newpage
\section{Simplex Algorithm}

\begin{question}
  Solve linear program $(D)$.
\end{question}

\begin{question}
  Out of previous solution of $(D)$ give a solution of its dual.
\end{question}

\begin{question}
  Transform program $(E)$ into an equivalent linear program having
  feasible basic solution.
\end{question}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:


\chapter{Predefined Variables}\label{ch:predefined}

A few commonly used variables are predefined in
\aprepro{}\footnote{The units system described in
Chapter~\ref{ch:units} also predefines several variables when it is
activated}. These are listed below. The default output format
\cmd{\_FORMAT} is specified as a C language format string, see your C
language documentation for more information. The default output format
(\cmd{\_FORMAT}) and comment (\cmd{\_C\_}) variables are defined with
a leading underscore in their name so they can be redefined without
generating an error message.

\begin{longtable}{lll}
\caption{Predefined Variables}\\
Name & Value & Description \\
\hline
 PI      & 3.14159265358979323846 & $\pi$ \\
 PI\_2   & 1.57079632679489661923 & $\pi/2$ \\
 TAU     & 6.28318530717958623200 & $2\pi$ \\
 SQRT2   & 1.41421356237309504880 & $\sqrt{2}$ \\
 DEG     & 57.2957795130823208768 & $180/\pi$ degrees per radian \\
 RAD     & 0.01745329251994329576 & $\pi/180$ radians per degree \\
 E       & 2.71828182845904523536 & base of natural logarithm \\
 GAMMA   & 0.57721566490153286060 & $\gamma$, euler-mascheroni constant \\
 PHI     & 1.61803398874989484820 & golden ratio $(\sqrt{5}+1)/2$ \\
 VERSION & Varies, string value   & current version of \aprepro \\
 \_FORMAT& \texttt{"}\%.10g\texttt{"} & default output format \\
  \_C\_  &  \texttt{"}\$\texttt{"} &  default comment character \\
\end{longtable}

Note that the output format is used to output both integers and floating point
numbers. Therefore, it should use the \%g format descriptor which will use either
the decimal (\%d), exponential (\%e), or float (\%f) format, whichever is shorter,
with insignificant zeros suppressed. The table below illustrates the effect of
different format specifications on the output of the variable \textbf{PI} and the
value 1.0 . See the documentation of your C compiler for more information. For
most cases, the default value is sufficient.

\begin{longtable}{lll}
\caption{Effect of various output format specifications}\\
Format & PI Output & 1.0 Output \\
\hline
\%.10g &  3.141592654      & 1  \\
\%.10e &  3.1415926536e+00 & 1.0000000000e+00  \\
\%.10f &  3.1415926536     & 1.0000000000  \\
\%.10d &  1413754136       & 0000000000  \\
\end{longtable}

The comment character should be set to the character that the program
which will read the processed file uses as a comment character. The
default value of \texttt{"}\$\texttt{"} is the comment character used
by the SEACAS codes at Sandia National Laboratories.  The \textbf{-c}
command line option (described in Chapter~\ref{ch:execution}) changes
the value of the comment variable to match the character specified on
the command line.


\lab{Complex Integration}{Integration in the Complex Plane Part 2}{Integration in the Complex Plane Part II}

\objective{Apply Residues to Integration in the Complex Plane}

As we noted in the last lab, there are some important links between the residues of a rational function and its partial fraction decomposition.
Here we will discuss the connection between residues and integrals along the real line and we will also discuss some important applications of residues.

\section*{Evaluating Residues Using Limits and Derivatives}
Often it is faster to evaluate a residue using limits instead of its direct integral definition.
To see how this might be done, consider some function $f$ with a pole of order $1$ at $z_0$.
We say $f$ has a pole of order $n$ at $z_0$ if the first nonzero term in the Laurent Series expansion of is the term corresponding to $(z-z_0)^{-n}$.
We then have
$$f(z)=c_{-1}(z-z_0)^{-1}+c_0 (z-z_0) +c_1 (z-z_0) + \dots$$
So,
$$f(z)(z-z_0)=c_{-1}+c_0 (z-z_0) + c_1 (z-z_0)^2 + \dots$$
Since the right hand side of the Laurent series converges within some nonzero distance of $z_0$, this series will also converge on that domain.
It is an ordinary power series, so it will also be continuous on that domain (it will actually be analytic, but continuity is sufficient here).
This means that we may take the limit of this expression as $z$ approaches $z_0$.
Taking this limit, the only nonzero term of the series remaining is $c_{-1}$, so we have
\begin{equation*}
\lim_{z\to z_0} f(z)(z-z_0) = c_{-1} = \Res_{z=z_0} f(z)
\end{equation*}
Now for some $f(z)$ with a pole of order $n$ at $z_0$ we have that within some nonzero distance of $z_0$, the Laurent series of $f$ converges and is of the form
$$f(z)=c_{-n}(z-z_0)^{-n}+\dots+c_0+c_1(z-z_0)+\dots$$
Multiplying by $(z-z_0)^{n}$ and differentiating $n-1$ times, we have
$$\frac{d^{n-1}}{dz^{n-1}}(f(z)(z-z_0)^{n})=(n-1)! c_{-1} + \frac{n!}{1!} c_0 (z-z_0) + \frac{(n+1)!}{2} c_1 (z-z_0)^2!+\dots$$
Taking the limit, we have
\begin{equation*}
\lim_{z\to z_0}\frac{d^{n-1}}{dz^{n-1}}((z-z_0)^n f(z)) = (n-1)! c_{-1}
\end{equation*}
Which implies
\begin{equation*}
\Res_{z=z_0}f(z)=\frac{1}{(n-1)!}\lim_{z\to z_0}\frac{d^{n-1}}{dz^{n-1}}((z-z_0)^n f(z))
\end{equation*}
Another useful trick involving poles and residues involves the logarithmic residue, i.e. the residue of the logarithmic derivative $\frac{d}{dz}(\ln(f(z))) = \frac{f'(z)}{f(z)}$.
A natural consequence of the Laurent series expansion of $f(z)$ and $f'(z)$ at a pole $z_0$ is that, where $d$ is the degree of the pole at $z_0$ is that
\begin{equation*}
\Res_{z=z_0} \frac{f'(z)}{f(z)} = d
\end{equation*}
This is a useful bit of information that may be used to simplify computation of residues or of the Laurent series expansion of a function.
Another way we can evaluate residues is by the following theorem.
\begin{theorem}
Let $f(z)=\frac{p(z)}{q(z)}$ and let $p$ and $q$ be holomorphic at $z_0$. Let $p(z_0) \neq 0$ and $q(z_0)=0$. Suppose that $z_0$ is a pole of order $1$ of $f$. Then
\begin{equation*}
\Res_{z=z_0} f(z) = \frac{p(z_0)}{q'(z)}
\end{equation*}
\end{theorem}

\begin{problem}
Write a python function, which, using symbolic integration in SymPy, returns the Laurent series expansion of a function about a given pole.
Use the trick involving logarithmic residues to figure out what the degree of the pole is, then use symbolic limits and derivatives to compute the coefficients of the corresponding Laurent series expansion.
You may assume that the pole is not an essential singular point.
(Recall that, as we defined it, a pole is not an essential singular point, so it will always have a finite degree).
\end{problem}

\begin{problem}
Write a function which uses SymPy to evaluate the residue of a function $f$ at a pole of $f$ $z_0$ in the case that: $f$ may be written as the quotient of two functions analytic everywhere within some nonzero distance of $z_0$ and the pole of $f$ at $z_0$ is of order $1$.
\end{problem}

\section*{Evaluating Indefinite Integrals Using Residues}

One convenient use of residues is the evaluation of integrals that are difficult to evaluate symbolically in other ways.
Often, when we cannot directly assign a value to one of these integrals, residues can still help us evaluate the Cauchy principal value of the integral.
Recall that for an integral $\int_{-\infty}^{\infty} f(x)dx$ the Cauchy principal value is $\lim_{r\to \infty} \int_{r}^{r} f(x) dx$. This limit may exist, even though the limit itself may not.

Consider the integral $\int_{-\infty}^{\infty}\frac{z^2}{z^4+1}$. Let $f(z)=\frac{z^2}{z^4+1}$.
Notice that this function has poles at $e^{\frac{\pi i}{4}}$, $e^{\frac{3\pi i}{4}}$, $e^{\frac{5\pi i}{4}}$, and $e^{\frac{7\pi i}{4}}$.
For notation, let these be $p_1$, $p_2$, $p_3$, and $p_4$.
For some real $R>1$, consider the contour $C$ from $-R$ to $R$ and then continuing continuing counterclockwise along the circle centered at $0$ of radius $R$.
Let $A$ be this second portion of $C$.
Note that, since $R>1$ we have
\begin{equation*}
\int_C f(z)dz = 2\pi i (\Res_{z=p_0} f(z) +\Res_{z=p_1} f(z))
\end{equation*}
So, rewriting, we have
\begin{equation*}
\int_{-R}^R f(z) dz = 2\pi i (\Res_{z=p_0} f(z) +\Res_{z=p_1} f(z)) - \int_A f(z) dz
\end{equation*}
so
\begin{equation*}
\int_{-\infty}^{\infty} f(z) dz = \lim_{R\to \infty} \int_{-R}^R f(z) dz = 2\pi i (\Res_{z=p_0} f(z) +\Res_{z=p_1} f(z)) - \lim_{R\to \infty} \int_A f(z) dz
\end{equation*}
We would like to show that that $\lim_{R\to\infty} \int_A f(z) dz = 0$, so note that on $A$, $\abs{z}=R$.
It follows from the triangle inequality that $\abs{z^4+1}\geq \abs{\abs{z}^4-1} = R^4 -1$, so we have that
$$\abs{\int_A f(z) dz}\leq \int_A \abs{f(z)} dz \leq \int_A \frac{R^2}{R^4 -1}dz = \pi R \frac{R^2}{R^4-1}$$
so $\lim_{R\to\infty} \int_A f(z) dz = 0$ as desired.
This then implies that
\begin{equation*}
 \int_{-\infty}^{\infty} f(z) dz = 2\pi i (\Res_{z=p_0} f(z) +\Res_{z=p_1} f(z))
\end{equation*}
Evaluating the residues at $p_0$ and $p_1$ we have
$$\int_{-\infty}^{\infty} f(z) dz = \frac{\pi}{\sqrt{2}}$$

\begin{problem}
Write a python function which, given the coefficients for the polynomials in the numerator and denominator of a rational function $f$, evaluates the sum
\begin{equation*}
\sum 2\pi i (\Res_{z=p} f(z)
\end{equation*}
over all poles $p$ of $f$ such that $Im(p)>0$.
Use that function to numerically evaluate the following integrals.
$$\int_{-\infty}^{\infty} \frac{z^2}{z^6+1}dz$$
$$\int_{-\infty}^{\infty} \frac{z^{12}-5z^{10}+3z^8-16z^6+4z^4-z^2-4}{4z^{14}+6z^6+12}dz$$
\end{problem}

\begin{problem}
Similar arguments can be used to evaluate integrals of functions that can be compared to the rational functions in question.
Write a modified version of the function you just wrote and use it to evaluate the following integrals.
$$\int_{-\infty}^{\infty}\frac{cos(z)}{z^4+1}dz$$
$$\int_{-\infty}^{\infty}\frac{sin^2(z)}{z^{20}+1}dz$$
\end{problem}

The general conditions in which we may apply this particular way of evaluating integrals come from Jordan's Lemma, which states
\begin{lemma}[Jordan's Lemma]
If for some $f(z)$ on $\mathbb{C}$, $f$ is analytic for all points $z$ in the upper half plane such that $\abs{z}>R_0$ for some $R_0 \in \mathbb{R}$ where $R_0 >0$ and that, where $C_R$ denotes the semicircle $z=Re^{i\theta}$ for $0\leq \theta \leq \pi$, there exists some positive constant $M_R$ such that for all $z$ on $C_R$, $\abs{f(z)} \leq M_R$ and $\lim_{R \to \infty} M_R = 0$, then for every positive constant $a$, we have
$$\lim_{R \to \infty} \int_{C_R} f(z) e^{iaz} dz = 0$$
\end{lemma}
\begin{problem}
Use the function you just wrote to evaluate the Cauchy Principal Value of the integral
$$\int_{\infty}^{-\infty} \frac{z sin(z)}{z^2+1}$$
\end{problem}

If a function has a singularity on the real line, we can often still evaluate the value of $\int_{-\infty}^{\infty} f(z) dz$ using a similar argument as before, but by indenting the path along the real axis around a small path around the singularity, then, as we take the limit as our outer contour moves out toward infinity, we can let the small contour around the singularity approach the singularity.

The following is a useful theorem involving these ``indented path" methods.
\begin{theorem}
Consider a function $f$ with a pole of order $1$ at $z=x_0$ with a Laurent series representation in a punctured disk of radius $R$ about $x_0$ and residue $B_0$ at $x_0$.
Let $C_r$ be the upper half of a circle $\abs{z-x_0}=r$ where $r<R$ oriented in the clockwise direction, then
$$\lim_{r\to 0} \int_{C_r} f(z) dz = - B_0 \pi i$$
\end{theorem}
As a consequence of this, for a function $f$ on $\mathbb{C}$ with only zeros of at most order $1$ on $\mathbb{R}$, where $A$ is the sum of the residues of $f$ on the upper half plane and $B$ is the sum of the residues of $f$ on $\mathbb{R}$,
$$CPV = \int_{-\infty}^{\infty} f(z) dz = \pi i (B+2A)$$
When that Cauchy Principal Value exists.

\begin{problem}
Using the function you just wrote, evaluate
$$\int_{0}^{\infty} \frac{sin(z)}{z} dz$$

Hint: Since $z$ and $sin(z)$ are odd, $\frac{sin(z)}{z}$ will be even, so
$\int_{-\infty}^{\infty} \frac{sin(z)}{z} dz = 2 \int_{0}^{\infty} \frac{sin(z)}{z} dz$.
\end{problem}

%% Add example here?

\begin{problem}
Modify the function you wrote earlier to evaluate the CPV of $\int_{-\infty}^{\infty} f(z) dz$ for a meromorphic function $f$ where $f$ has only poles of order $1$ along the real axis.
\end{problem}

Integration techniques using residues can also be extended to integration around branch points, some types of integrals involving sines and cosines, inverse Laplace transforms, and many other difficult integration problems.


\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[T1]{fontenc}
\usepackage{pagecolor}
\usepackage{amssymb}
\usepackage{lmodern}
\usepackage{mathtools, nccmath}
\usepackage{courier}
\usepackage[dvipsnames]{xcolor}

\definecolor{myyellow}{RGB}{225,225,100}
\definecolor{myred}{RGB}{220,100,100}
\definecolor{mygreen}{RGB}{120,225,120}
\definecolor{myblue}{RGB}{100,200,255}
\definecolor{mypurple}{RGB}{200,50,255}
\color{white}
\title{\Huge{Multivariable calculus \#1}}
\author{@all.about.mathematics}

\begin{document}

\maketitle
\pagecolor{black}
\Large{\section{Introduction}
In this post, we talk about local linearization, which is the analog to finding the tangent line to a single-variable function. Basically, we try to find the equation of the tangent \textbf{plane} to a multivariable function and use some vector notation to extend it to more dimensions.}
\newpage
\section{Finding tangent planes}
\Large{Before we try to figure out the tangent plane to a specific function, let's figure out the equation of a plane in 3D. The easiest way to represent a plane is $$P(x,y)=ax+by+c$$From this, we have $$\color{myred}\frac{\partial P}{\partial x}=a\:,\: \frac{\partial P}{\partial y}=b$$To guarantee that the plane passes through a specific point $(x_0,y_0,z_0)$, let's change our equation a little bit $$\color{mygreen}L(x,y)=a(x-x_0)+b(y-y_0)+c$$So, if we wanted to find the tangent plane to $f(x,y)$ at the point $(x_0,y_0,f(x_0,y_0))$, we could easily express it as $$\color{mygreen}L_f(x,y)=a(x-x_0)+b(y-y_0)+f(x_0,y_0)$$We can also see check that $\color{myred}\frac{\partial L_f}{\partial x}=a$ and $\color{myred} \frac{\partial L_f}{\partial y}=b$.Finally, we obtain the formula for a tangent plane:$$\color{myblue}L_f(x,y)=f(x_0,y_0)+f_x(x_0,y_0)(x-x_0)+f_y(x_0,y_0)(y-y_0)$$ }

\newpage
\section{Generalization with vectors}
\Large{The formula $$L_f(x,y)=\textcolor{myyellow}{f(x_0,y_0)}+\textcolor {mygreen}{f_x(x_0,y_0)}\textcolor{myred}{(x-x_0)}+\textcolor {mygreen}{f_y(x_0,y_0)}\textcolor{myred}{(y-y_0)}$$is also called the local linearization of $f$ near $(x_0,y_0)$. It satisfies 2 important properties. It has the same value and the same partial derivatives at $(x_0,y_0)$ as $f$. We can see that it contains a \textcolor{myyellow}{constant term}, the \textcolor{mygreen}{partial derivatives of $f$ at $(x_0,y_0)$} multiplied with a \textcolor{myred}{variable term minus the constant term respectively.}

\noindent{Now let $\bold{x_0}=(x_0,y_0)^{T}$ and $\bold{x}=(x,y)^{T}$. Then we can rewrite it as $$L_f(x,y)=\textcolor{myyellow}{f(\bold{x_0})}+\textcolor{mygreen}{\nabla f(\bold{x_0})}\cdot\textcolor{myred}{ (\bold{x}-\bold{x_0})}$$}Where $\textcolor{mygreen}{\nabla f(\bold{x_0})=(f_x(x_0,y_0),f_y(x_0,y_0))^T}$ is the gradient of $f$ at $(x_0,y_0)$. }
\newpage
\section{Example}
\large{Let's say we wanted to approximate $$a=\sqrt{6.99+\sqrt{2.01+\sqrt{3.99}}}$$We can let $f(x,y,z)=\sqrt{x+\sqrt{y+\sqrt{z}}}$ and find the local linearization of $f$ near $\bold(x_0)=(7,2,4)$. First, we evaluate the constant term $$\textcolor{myyellow}{f(\bold{x_0})=f(7,2,4)=\sqrt{7+\sqrt{2+\sqrt{4}}}=3}$$Then we evaluate the partial derivatives and plug in the values
$$\textcolor{mygreen}{\nabla f(\bold{x})=\left(\frac{\partial f}{\partial x},\frac{\partial f}{\partial y},\frac{\partial f}{\partial z}\right)^T}$$$$\frac{\partial f}{\partial x}=\frac{1}{2\sqrt{x+\sqrt{y+\sqrt{z}}}}\:,\:\frac{\partial f}{\partial y}=\frac{1}{2\sqrt{x+\sqrt{y+\sqrt{z}}}}\cdot\frac{1}{2\sqrt{y+\sqrt{z}}}$$$$\frac{\partial f}{\partial z}=\frac{1}{2\sqrt{x+\sqrt{y+\sqrt{z}}}}\cdot\frac{1}{2\sqrt{y+\sqrt{z}}}\cdot\frac{1}{2\sqrt{z}}$$$$\textcolor{mygreen}{\nabla f(\bold{x_0})=\left(\frac{1}{6},\frac{1}{24},\frac{1}{96}\right)^T}$$Plugging everything in the formula,$$L_f(x,y,z)=\textcolor{myyellow}{f(\bold{x_0})}+\textcolor{mygreen}{\nabla f(\bold{x_0})}\cdot\textcolor{myred}{ (\bold{x}-\bold{x_0})}$$$$=\textcolor{myyellow}{f(\bold{x_0})}+\textcolor{mygreen}{f_x(\bold{x_0})}\textcolor{myred}{(x-x_0)}+\textcolor{mygreen}{f_y(\bold{x_0})}\textcolor{myred}{(y-y_0)}+\textcolor{mygreen}{f_z(\bold{x_0})}\textcolor{myred}{(z-z_0)}$$$$=3+\frac{1}{6}(x-7)+\frac{1}{24}(y-2)+\frac{1}{96}(z-4)$$To approximate $a$, substitute $(x,y,z)=(6.99,2.01,3.99)$ $$L_f(x,y,z))=3+\frac{1}{6}(6.99-7)+\frac{1}{24}(2.01-2)+\frac{1}{96}(3.99-4)\approx2.9986458$$Using a calculator, $a\approx2.9986453$, and our approximation is very accurate.}

\end{document}


\section{Conclusions}
This paper introduces the Elo-MMR rating system, which is in part a generalization of the two-player Glicko system, allowing any number of players. By developing a Bayesian model and taking the limit as the number of participants goes to infinity, we obtained simple, human-interpretable rating update formulas. Furthermore, we saw that the algorithm is incentive-compatible, robust to extreme performances, asymptotically fast, and embarrassingly parallel. To our knowledge, our system is the first to rigorously prove all these properties in a setting with more than two individually ranked players. In terms of practical performance, we saw that it outperforms existing industry systems in both prediction accuracy and computation speed.
%In particular, we compare against the popular CodeForces, Topcoder, and TrueSkill rating systems, which are deployed on platforms with hundreds of thousands to millions of users.

This work can be extended in several directions. First, the choices we made in modeling ties, pseudodiffusions, and opponent subsampling are by no means the only possibilities consistent with our Bayesian model of skills and performances. Second, it may be possible to further improve accuracy by fitting more flexible performance and skill evolution models to application-specific data.

Another useful extension would be to team competitions. Given a performance model for teams, Elo-MMR infers each team's performance. To make this useful in settings where teams are frequently reassigned, we must model teams in terms of their individual members; unfortunately, it's not possible to precisely infer an individual's performance from team rankings alone. Therefore, it becomes necessary to condition an individual's skill on their team's performance. In the case where a team's performance is modeled as the sum of its members' independent Gaussian contributions, elementary facts about multivariate Gaussian distributions enable posterior skill inferences at the individual level. Generalizing this approach to other models remains an open challenge.

% Probably redundant: The algorithm itself is trivially parallelizable, and further speedup can be attained through a simple sub-sampling strategy. We believe there is potential to improve the performance even more, either through a more sophisticated sub-sampling strategy, interpolation, or by combining our two-phase approach with a factor graph framework similar to that of TrueSkill~\cite{HMG06, KFL01}.

Over the past decade, online competition communities such as Codeforces have grown exponentially. As such, considerable work has gone into engineering scalable and reliable rating systems. Unfortunately, many of these systems have not been rigorously analyzed in the academic community. We hope that our paper and open-source release will open new explorations in this area.

%In addition, we invite non-technical sporting communities, such as the Spartan Race and DanceSport, to find uses of our skill estimation package.


\documentclass[12pt]{article}

\usepackage[left=1cm,right=1cm,
    top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}
\usepackage{braket}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage[T2A]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\parindent=0.5cm

\usepackage{hyperref}
\usepackage{indentfirst}

\numberwithin{equation}{section}
%\usepackage{showkeys}

\begin{document}
\section*{MSAI Statistics \& Probability – Week 3 Seminar \& HW}\\

\textbf{Problem 1:} Let $\mathrm{P}$ be a distribution on $\mathbb{R}$ and $F$ be its distribution function. Are the following equalities true?
\begin{enumerate}
    \item $P([a,b])=F(b)-F(a-)$
    \item $P((a,b))=F(b-)-F(a)$
    \item $P([a,b))=F(b-)-F(a-)$
    \item $P(\{x\})=F(x)-F(x-)$
\end{enumerate}
\\

\textbf{Problem 2:} Let $\mathrm{P}$ have density $p$. Find its distribution, $F,$ if
\begin{enumerate}
    \item $p(t)=\frac{I_{[a,b]}(t)}{b-a}$
    \item $p(t)=\lambda e^{-\lambda t} I_{(0,\infty)}(t)$
    \item $p(t)=\frac{\theta}{\pi(t^2+\theta^2)}$
\end{enumerate}
Find the product of $F_1(2b)F_2(\ln 2/\lambda)F_3(0)$.
\\

\textbf{Problem 3:} Let $\mathrm{P}$ be a discrete distribution on $\mathbb{R}$, $p(x)=\mathrm{P}(\{x\})$
\begin{enumerate}
    \item $p(x)=\frac{\lambda^x e^{-\lambda}}{x!},~x\in\mathbb{Z}_+$ (Poisson distribution). Find $\mathrm{P}(2\mathbb{Z}_+).$
    \item $p(x)=p(1-p)^{x-1},~x\in\mathbb{N}$ (geometric distribution). Find the distribution function and $\mathrm{P}(2\mathbb{Z}_+).$
\end{enumerate}
Find numerical values for both distributions if $\lambda=\ln 2/2, ~p=1/3$
\\

\textbf{Problem 4:} Let $\matbrm{P}$ be the uniform distribution on the quarter disk $D=\{(x,y):~x^2+y^2<1,~x>0,~y>0\}.$ Let $P_1(x)$ be its \textit{marginal distribution} (marginalized $y$). Find the density function $p_1(x)$ of it, as well as the distribution function $F_1$. Find the numerical value of $p_1(\sqrt{1-(\pi/4)^2}).$
\end{document}


\section{Radius of Convergence}
We've established some tests to determine if an infinite series is or isn't convergent, but like we saw with geometric and Taylor series, it's possible that a series only converges over some interval.
We'd like to be able to find this interval so we know if we can rightly use Taylor series to approximate a function.

\subsection{Convergence Theorem for Power Series}
\begin{theorem}[Convergence Theorem for Power Series]
	There are three possibilities for any power series of the form
	\begin{equation*}
		\sum_{k=0}^{\infty}{c_k(x-a)^k}
	\end{equation*}
	with respect to convergence.
	\begin{enumerate}
		\item The power series converges, but only on some finite interval centered at $x=a$.
			That is, there is a positive real number $r$ such that the series converges for $\abs{x-a}<r$ and diverges otherwise.
			The series may or may not converge at the endpoints.
		\item The power series converges for all real numbers.
		\item The power series converge only at $x=a$ and diverges elsewhere (i.e $r=0$).
	\end{enumerate}
	We call this value $r$ the radius of convergence.
\end{theorem}

Generally, we start by applying the ratio test to determine where the series converges absolutely.
If we find the series converges for all real numbers of just at $x=a$, we are done.
Otherwise the series converges for some finite interval and we need to apply a different test to determine convergence at endpoints.

\begin{example}
	Determine the radius of convergence for the following series:
	\begin{equation*}
		\sum_{k=0}^{\infty}{\frac{kx^k}{10^k}}.
	\end{equation*}
\end{example}
\begin{answer}
	Since this series isn't quite geometric enough for an nth root test but does have all poitive terms, it seems most suited for a ratio test.
	\begin{equation*}
		\lim_{n\to\infty}{\frac{\frac{(n+1)x^{n+1}}{10^{n+1}}}{\frac{nx^n}{10^n}}} = \lim_{n\to\infty}{\frac{(n+1)x^{n+1}}{10nx^n}} = \lim_{n\to\infty}{\frac{(n+1)x}{10n}} = \frac{x}{10}.
	\end{equation*}

	$x$ can be positive or negative.
	Recall that with a ratio test, the series converges if the limit is less than 1.
	\begin{align*}
		\abs{\frac{x}{10}} &< 1 \\
		\abs{x} &< 10.
	\end{align*}

	So, the radius of convergence is 10.
	Note that this analysis doesn't tell us for sure of the series converges for $x=\pm 10$ (it happens to not converge in this case).
\end{answer}

\begin{example}
	Determine the radius of convergence for the following series:
	\begin{equation*}
		\sum_{k=0}^{\infty}{k!x^k}.
	\end{equation*}
\end{example}
\begin{answer}
	We can again use a ratio test.
	\begin{equation*}
		\lim_{n\to\infty}{\frac{(n+1)!x^{n+1}}{n!x^n}} = \lim_{n\to\infty}{(n+1)x} = \begin{cases} \infty & x\neq 0 \\ 0 & x = 0 \end{cases}.
	\end{equation*}

	We see that the only time the limit is less than 1 is when $x=0$.
	So, the radius of convergence is 0.
\end{answer}

\begin{example}
	Determine the radius of convergence for the following series\footnote{You might recognize this as the Maclaurin series for $e^x$.}:
	\begin{equation*}
		\sum_{k=0}^{\infty}{\frac{x^k}{k!}}.
	\end{equation*}
\end{example}
\begin{answer}
	Applying the ratio test,
	\begin{equation*}
		\lim_{n\to\infty}{\frac{\frac{x^{n+1}}{(n+1)!}}{\frac{x^n}{n!}}} = \lim_{n\to\infty}{\frac{x}{n+1}} = 0.
	\end{equation*}

	Since the limit is less than 1 everywhere, the series converges for all real $x$.
\end{answer}

\subsection{Convergence at Endpoints}
If a series only converges over some finite interval, our method of applying the ratio test is inconclusive.
Instead, we plug in the endpoint value for $x$ into our series and apply a different test, which usually depends on the specific series we're working with.
The most common tests to use are the direct comparison test, the limit comparison test, the integral test, and the alternating series test.

\begin{example}
	Given that the following series converges by the ratio test for $\abs{x}<10$, determine convergence at the endpoints.
	\begin{equation*}
		\sum_{k=0}^{\infty}{\frac{kx^k}{10^k}}.
	\end{equation*}
\end{example}
\begin{answer}
	Plugging in $x=\pm10$,
	\begin{equation*}
		\sum_{k=0}^{\infty}{\frac{k(\pm10)^k}{10^k}} = \sum_{k=0}^{\infty}{(\pm 1)^k k}.
	\end{equation*}

	This series diverges by the nth term test for both $x=10$ and $x=-10$.
	So the radius of convergence is $\abs{x} < 10$.
\end{answer}

\begin{example}
	For what values of $x$ does the following series converge:
	\begin{equation*}
		\sum_{k=1}^{\infty}{(-1)^{k+1}\frac{x^{2k}}{2k}}.
	\end{equation*}
\end{example}
\begin{answer}
	Applying the ratio test to the absolute series,
	\begin{equation*}
		\lim_{n\to\infty}{\frac{\frac{x^{2n+2}}{2n+2}}{\frac{x^{2n}}{2n}}} = \lim_{n\to\infty}{\frac{2nx^2}{2n+2}} = x^2.
	\end{equation*}

	So, by the ratio test, the series converges absolutely when $\abs{x}<1$.
	The series is the same at $x=1$ and $x=-1$.
	\begin{equation*}
		\sum_{k=0}^{\infty}{\frac{(-1)^{k+1}}{2k}}.
	\end{equation*}

	Since the series, disregarding the $(-1)^{k+1}$ has all terms positive and decreasing and passes the nth term test, it converges by the alternating series test.
	Therefore the interval of convergence is $[-1,1]$.
\end{answer}

It's important to remember that although a series might converge over some interval it might do so very slowly, especially at endpoints.
That is why when estimating a function value using a Taylor series we still need to estimate the error.