%!TEX root = TDT4265-Summary.tex
\section{Morphological image processing}
Morphology is image manipulation via set theory. It's pretty cool. Sort of like spatial filtering, but with nonlinear operations.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Preliminaries}
In morphology, images are represented as sets. Usually images are binary, and the set of an image is the set of 1-valued pixels, defined on $\mathbb{Z}^2$. An extension in $\mathbb{Z}^3$ to greyscale exists, and also to color and so on.

\subsubsection{Some set theory}
\begin{itemize}
    \item The absolute complement of a set $A$ is
    \begin{equation}
        A^c = \{ w | w \notin A \},
    \end{equation}
    which is all elements outside of $A$.
    \item The relative complement between two sets $A$ and $B$ is
    \begin{equation}
        A \setminus B = \{ w | w \in A, w \notin B \},
    \end{equation}
    which is all elements that are \emph{only} in $A$.
    \item The reflection (180 degree rotation) of a set is
    \begin{equation}
        \hat{B} = \{ w | w = -b \mbox{ for } b \in B \}.
    \end{equation}
    \item The translation of a set $A$ by a vector $z = (z_1, z_2)$ is
    \begin{equation}
        (B)_z = \{ c | c = b + z \mbox{ for } b \in B \}
    \end{equation}
\end{itemize}

\subsubsection{Structuring elements (SEs)}
An SE is a small subimage or subset that is used to find properties of the image. They are usually symmetric and with their center defined in the middle.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Erosion and dilation}

\subsubsection{Erosion}
The erosion of $A$ by $B$ is defined as
\begin{equation}
    A \erode B = \left\{ z | (B)_z \subseteq A \right\},
\end{equation}
which is the set of all points where $B$ is completely inside $A$. ($A$ is an image and $B$ is an SE.) The operation shrinks objects, and removes anything smaller/thinner than the SE, such as thin lines.

\subsubsection{Dilation}
The dilation of $A$ by $B$ is defined as
\begin{equation}
    A \dilate B = \left\{ z | (\hat{B})_z \cap A \neq \emptyset \right\}
\end{equation}
which is the set of all points where $\hat{B}$ (the reflection of $B$) overlaps with $A$ by at least one element. This operation grows objects, and can fill gaps and small holes.

\subsubsection{Duality}
Erosion and dilation are dual operations:
\begin{equation}
\begin{split}
    (A \erode  B)^c &= A^c \dilate \hat{B} \\
    (A \dilate B)^c &= A^c \erode  \hat{B} \\
\end{split}
\end{equation}
This is useful for symmetric SEs ($\hat{B} = B$), because then we can erode $A$ by instead dilating the background $A^c$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Opening and closing}\label{ssec:open-close}
\emph{Opening} is defined as
\begin{subequations}
\begin{align}
    A \open B &= (A \erode B) \dilate B \\
              &= \bigcup \left\{ (B)_z | (B)_z \subseteq A \right\} \label{eq:opening-as-set}
\end{align}
\end{subequations}
It is analogous to the area defined by moving a ball (or other shape) along the inner boundary of a set, as in Figure \ref{fig:openclose}. Equation \eqref{eq:opening-as-set} shows that opening can be expressed as ``all translates of $B$ that fit inside $A$''. Used for e.g. removing thin connections between components and removing noise pixels.

\emph{Closing} is defined as
\begin{equation}
    A \close B = (A \dilate B) \erode B,
\end{equation}
which is analogous to the area defined by moving e.g. a ball along the outer boundary of a set, as in Figure \ref{fig:openclose}. Used for e.g. filling holes.

\begin{figure}[htbp]
    \centering
    \subfigure[Opening]{\includegraphics[width=.9\linewidth]{images/opening.png}} \\
    \subfigure[Closing]{\includegraphics[width=.9\linewidth]{images/closing.png}}
    \caption{Analogies to the opening and closing operations}
    \label{fig:openclose}
\end{figure}

Note that both opening and closing are idempotent operations.

\paragraph{Combining opening and closing}
Opening followed by closing can remove noise, both specks of object pixels on the background and background pixels where there should be object. However, some connectivity may be lost.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{The hit-or-miss transformation}
A basic tool for shape detection. Let $B = (B_1, B_2)$, $B_1$ be an object, and $B_2$ its background. Then the matches of $B$ in $A$ is
\begin{equation}
    A \match B = (A \erode B_1) \cap (A^c \erode B_2).
\end{equation}
The set $(A \erode B_1)$ are all locations where the object fits in, and $(A^c \erode B_2)$ are all locations where the background fits. Locations where both fit are locations of all shapes in $A$ that perfectly match $B$. We assume that each object we want to find is separate from the other objects, and therefore each has a complete local background at least one pixel wide.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Some basic morphological algorithms}
Now we can finally use this stuff.

\subsubsection{Boundary extraction}
Get the boundary by subracting the eroded image from the original.
\begin{equation}
    \beta(A) = A - (A \erode B)
\end{equation}
The erosion gives a ``smaller'' version of $A$, and subtracting that from the image leaves only the border.

\subsubsection{Hole filling}
Same principle as in Section \ref{sec:extract-connected} below.
\begin{equation}
    X_k = (X_{k-1} \dilate B) \cap A^c
\end{equation}
The seed pixel must be in a hole. It will grow until it fills the hole. Stop when no further change happens.

\subsubsection{Extraction of connected components}\label{sec:extract-connected}
Done by iteration:
\begin{equation}
    X_k = (X_{k-1} \dilate B) \cap A
\end{equation}
Choose a starting pixel (seed) $X_0$. Dilate $X_0$, but only keep the pixels that are in the original. Continue dilating and only keeping pixels present in $A$ until convergence.

\subsubsection{Convex hull}\label{sec:convex-hull}
A set is convex if any line segment between two points in the set lies fully within the set. The \emph{convex hull} $H$ of a set $S$ is the smallest convex set containing $S$. The difference $H - S$ is the \emph{convex decifiency} of $S$. It can be computed by iterating
\begin{equation}
    X_k^i = (X_{k-1} \match B^i) \cup A
    ,\quad i = 1,2,3,4
    ,\quad k = 1,2,\dots
\end{equation}
with $X_0^i = A$ and $B^i$ being as shown in Figure \ref{fig:convex-hull-SE}. For each SE, let $D^i = X_k^i$ when its iteration converges. Then the convex hull is
\begin{equation}
    C(A) = \bigcup_{i=4}^{4} D^i
\end{equation}

\begin{figure}[htbp]
    \centering
    \includegraphics[width=.5\linewidth]{images/SE-for-convex-hull.png}
    \caption{SEs for convex hull extraction}
    \label{fig:convex-hull-SE}
\end{figure}

\subsubsection{Thinning}\label{sec:thinning}
Used e.g. for skeletonization and to thin edge detector output. It is defined in terms of the hit-or-miss transformation as
\begin{equation}
    A \thin B = A \cap (A \match B)^c
\end{equation}
with a sequence of SEs
\begin{equation}
    \{ B \} = \{ B^1, \dots, B^n \}
\end{equation}
where $B^i$ is a rotated $B^{i-1}$. Then just keep applying hit-or-miss with $B$ repeatedly, until continuing has no effect.

One pass of thinning is written as
\begin{equation}
    A \thin \{ B \} = ((\dots ((A \thin B^1) \thin B^2) \dots ) \thin B^n)
\end{equation}

\subsubsection{Thickening}
Thickening is the dual of thinning:
\begin{equation}
    A \thick B = A \cup (A \match B)
\end{equation}

\subsubsection{Skeletons}
The skeleton is
\begin{equation}
    S(A) = \bigcup_{k=0}^{K} (A \erode kB) - (A \erode kB) \open B
\end{equation}
where $B$ is an SE and $(A \erode kB)$ indicates $k$ successive erosions of $A$. $K$ is the number of erosions possible before resulting in the empty set.

\subsubsection{Pruning}
Skeletons often have unwanted ``spurs''. Assuming the spurs are sufficiently small, pruning can remove them. We perform thinning with SEs designed to only detect end points.
\begin{equation}
    X_1 = A \thin \{B\}
\end{equation}
The SEs used are shown in Figure \ref{fig:se-for-pruning}.

\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.5\linewidth]{images/SE-for-pruning.PNG}
    \caption{SEs for pruning}
    \label{fig:se-for-pruning}
\end{figure}

\subsubsection{Morphological reconstruction}
Uses two images, a marker $F$ with starting points, and a mask $G$ that constrains the transformation.

\paragraph{Geodesic dilation}
Geodesic dilation is the intersection of the mask and the dilated marker. One pass is
\begin{equation}\label{eq:geo-dilation}
    D_G^{(1)}(F) = (F \dilate B) \cap G.
\end{equation}
Several passes, denoted $D_G^{(n)}$, is just repeating the operation $n$ times.

\paragraph{Geodesic erosion}
Geodesic erosion is the union of the mask and the eroded marker. One pass is
\begin{equation}\label{eq:geo-erosion}
    E_G^{(1)}(F) = (F \erode B) \cup G.
\end{equation}

\paragraph{Morphological reconstruction by dilation}
Reconstruction by dilation is just repeating \eqref{eq:geo-dilation} until more passes have to effect:
\begin{equation}
    R_G^D(F) = D_G^{(k)}(F)
\end{equation}

\paragraph{Morphological reconstruction by erosion}
Same as by dilation, but using erosion:
\begin{equation}
    R_G^E(F) = E_G^{(k)}(F)
\end{equation}

\paragraph{Opening by reconstruction}
With normal opening (Section \ref{ssec:open-close}), erosion removes small things and dilation restores the original size/shape. Opening by reconstruction restores the precise original shape, and is done as reconstruction by dilation of $F$, from the erosion of size $n$ of $F$:
\begin{equation}
    O_R^{(n)}(F) = R_F^D \left[ (F \erode nB) \right]
\end{equation}
where $(F \erode nb)$ indicates $n$ erosions.

The SE for erosion $B$ determines the shapes we want to identify. The erosion itself leaves us with markers for all matching objects (because they are not removed by the erosion). Then, the image $F$ is used as a mask, and reconstruction is done by dilating the markers, subject to the mask. That way, all objects marked will be completely filled, and the result is removing all unmarked objects.

\paragraph{Filling holes}
With morphological reconstruction we can fill holes automatically, without knowing where they are. Create a marker image $F$ of zeros, except for the border, where it is $1 - I$. Then
\begin{equation}
    H = \left[ R_{I^c}^D(F) \right]^c
\end{equation}
is $I$ with all holes filled.

\paragraph{Border clearing}
Morphological reconstruction can also be used to remove objects connected to the borders of an image. Create a marker image $F$ that is equal to the input image $I$ at the border, and 0 elsewhere. We can extract all border-touching objects by the morphological reconstruction $R_I^D(F)$, and subtract it from the original to get an image without border objects $X$:
\begin{equation}
    X = I - R_I^D(F)
\end{equation}

\subsubsection{Summary}
We have now defined the following morphological operations:
\begin{itemize}
    \item Basic set operations:
    \begin{itemize}
        \item Translation
        \item Reflection
        \item Complement
        \item Difference
    \end{itemize}
    \item Basic morphological operations:
    \begin{itemize}
        \item Erosion
        \item Dilation
        \item Opening
        \item Closing
    \end{itemize}
    \item Complex morphological operations:
    \begin{itemize}
        \item Hit-or-miss transform
        \item Boundary extraction
        \item Hole filling
        \item Connected components
        \item Convex hull
        \item Thinning
        \item Thickening
        \item Skeletons
        \item Pruning
    \end{itemize}
    \item Morphological reconstruction operations:
    \begin{itemize}
        \item Geodesic dilation
        \item Geodesic erosion
        \item Morphological reconstruction by dilation
        \item Morphological reconstruction by erosion
        \item Opening by reconstruction
        \item Closing by reconstruction
        \item Hole filling
        \item Border clearing
    \end{itemize}
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Grey-scale morphology}
We can dilate, erode, open, and close grey-scale images too! Now we use images $f(x,y)$ and SEs $b(x,y)$. The SEs can now be either flat (uniform) or nonflat. We stick to flat SEs for simplicity.

\subsubsection{Erosion and dilation}
Erosion of $f$ by a flat SE $b$ is the minimum value of the image in the region covered by the SE:
\begin{equation}
    \left[ f \erode b \right](x,y) = \min_{(s,t) \in b} \left\{ f(x+s, y+t) \right\}.
\end{equation}
Dilation is similarly
\begin{equation}
    \left[ f \dilate b \right](x,y) = \max_{(s,t) \in b}  \left\{ f(x-s, y-t) \right\},
\end{equation}
which uses  $\hat{b} = b(-x,-y)$.

\subsubsection{Opening and closing}\label{sssec:greyscale-open-close}
This is mathematically just as before:
\begin{subequations}
\begin{align}
    f \open b = (f \erode b) \dilate b \\
    f \close b = (f \dilate b) \erode b
\end{align}
\end{subequations}

Looking at the image as a topographic surface, opening is pushing the SE up from below, clipping all peaks where it doesn't fit, and closing is pushing the SE down from above, clipping all valleys where it doesn't fit. See Figure \ref{fig:greyscale-opening-closing}. This means that opening removes small, bright details, and closing removes small, dark details.

\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.8\linewidth]{images/greyscale-opening-closing}
    \caption{Analogy to opening and closing greyscale images}
    \label{fig:greyscale-opening-closing}
\end{figure}

\subsubsection{Some basic greyscale morphological algorithms}

\paragraph{Smoothing}
The ``small bright/dark details'' mentioned in Section \ref{sssec:greyscale-open-close} might be noise. This means we can remove this type of noise by opening and then closing. The size of the SE then sets a threshold for what is image and what is noise.

\paragraph{Morphological gradient}
The morphological gradient is
\begin{equation}
    g = (f \dilate b) - (f \erode b).
\end{equation}
The dilation thickens objects in the image, and the erosion shrinks them. Differencing these emphasises edges and removes homogenous areas, which gives a gradientlike effect.

\paragraph{Top-hat and bottom-hat transformations}\label{par:top-hat}
Subtracting the opening of an image from the image itself defined the top-hat transformation
\begin{equation}
    T\sub{hat}(f) = f - (f \open b).
\end{equation}
The bottom-hat transformation is defined similarly:
\begin{equation}
    B\sub{hat}(f) = (f \close b) - f
\end{equation}

Top-hat can isolate light objects on a dark background, and bottom-hat does the opposite. This is a type of segmentation, and works well even with uneven lightning.

Opening with an SE that is too large to fit in the objects you want to segment will remove all such objects and leave only an approximation of the background, including any uneven lightning. If you subtract the approximate background from the original, the unevenness will be reduced, and now thresholding methods can be used with success.

\paragraph{Granulometry}
(Assuming light objects on a dark background.) Open the image with gradually larger SEs, and compute the sum of pixel values. As the SEs grow larger than the objects, they disappear, and the pixel sum decreases. Plotting pixel sum against SE size indicates by peaks in the plot the predominant sizes of objects in the image. This can be used to simply get the size distribution of objects, but also to identify defect objects (sizewise).

\paragraph{Textural segmentation}
(Assuming light objects on a dark background.) Textural segmentation is to divide an image into regions based on their texture contents. If you have an image with some coarse and some fine texture, you can close it with an SE large enough to remove the fine objects. Then open it with an SE large enough to fill the gaps between the coarse objects. Now coarse areas are dark, and fine areas are bright, and the boundary can be extracted by e.g. a morph. gradient.

\subsubsection{Greyscale morphological reconstruction}
Let $f$ be the marker, and $g$ be the mask. The basic operations are similar to their black-and-white counterparts.
\begin{itemize}
    \item Geodesic dilation:
    \begin{equation}
        D_g^{(1)}(f) = (f \dilate b) \wedge g
    \end{equation}
    \item Geodesic erosion:
    \begin{equation}
        E_g^{(1)}(f) = (f \erode b) \vee g
    \end{equation}
    \item Reconstruction by dilation:
    \begin{equation}
        R_g^D(f) = D_g^{(k)}(f)
    \end{equation}
    \item Reconstruction by erosion:
    \begin{equation}
        R_g^E(f) = E_g^{(k)}(f)
    \end{equation}
    \item Opening by reconstruction:
    \begin{equation}
        O_R^{(n)}(f) = R_f^D \left[ (f \erode nb) \right]
    \end{equation}
    \item Closing by reconstruction:
    \begin{equation}
        C_R^{(n)}(f) = R_f^E \left[ (f \dilate nb) \right]
    \end{equation}
\end{itemize}

\paragraph{Top-hat by reconstruction}
This method consists of subtracting an image's opening by reconstruction from the image.


%!TEX root = ../gfkg.tex
\subsection{Chapter 4}
\begin{p}
{Show that $\omega+\mu$ and $f\omega$ are really 1-forms, i.e.\ show linearity over $C^\infty(M)$.}
\end{p}

That $\omega$ and $\mu$ are 1-forms means they are (separately) linear over $C^\infty(M)$. So $[\omega+\mu](v+w)=
\omega(v+w)+\mu(v+w)=\omega(v)+\omega(w)+\mu(v)+\mu(w)=[\omega+\mu](v)+[\omega+\mu](w)$. $f\omega$ is just
multiplication by $f$ of the result of applying $\omega$, so $[f\omega](v+w)=f\omega(v+w)=f\omega(v)+f\omega(w)$.

\begin{p}{Show that $\Omega^1(M)$ is a module over $C^\infty(M)$.}
\end{p}

There are four conditions to check. Let $f,g\in C^\infty(M)$ and $\omega,\mu\in C^\infty(M)$. The first condition
is $f(\omega+\mu)=f\omega+f\mu$, which is true by applying each side of the equation to a test vector $v$ and
using the previous exercise to show the two resulting expressions are equal. Same for the conditions $(f+g)\omega=f\omega+g\omega$,
$(fg)\omega=f(g\omega)$, and $1\omega=omega$. Basically the point is that by applying the 1-forms to test vectors, everything
turns into functions and the equality of the different expressions follows immediately.\\

\begin{p}
{Show that $d(f+g)=df+dg, d(\alpha f)=\alpha\, df, (f+g)dh=f\,dh+g\,dh$, and $d(fg)=f(dg)+g(df)$ for any
$f,g,h\in C^\infty(M)$ and any $\alpha\in \R$.}
\end{p}

The differential map $d$ is defined by $df(v)=vf$. Applying this definition to the first equation, we obtain $d(f+g)v=v(f+g)=vf+vg=df(v)+dg(v)=[df+dg](v)$ as intended. Similarly, $d(\alpha f)(v)=v(\alpha f)=\alpha vf=\alpha df(v)$
and $(f+g)dh(v)=(f+g)vh=f\,vh+g\,vh=[f\,dh+g\,dh](v)$. For the last condition, compute $d(fg)(v)=v(fg).$ By the definition
of $v$ as a vector field, $v(fg)=gv(f)+fv(g)$, so we obtain $d(fg)(v)=[f(dg)+g(df)](v)$.\\

\begin{p}{Suppose $f(x^1,\dots,x^n)$ is a function on $\R^n$. Show that $df=\partial_\mu f\,dx^\mu$.}
\end{p}

Consider an arbitrary vector field $v=v^\nu \partial_\nu$. Then $df(v)=vf=v^\nu \partial_\nu f$. On the other hand, $(\partial_\mu f\,dx^\mu)v=\partial_\mu f\, vx^\mu=\partial_\mu f\, v^\nu\partial_\nu x^\mu=\partial_\mu f\, v^\nu \delta_\nu^\mu=v^\nu \partial_\nu f$.
So $df=\partial_\mu f\,dx^\mu$ as intended.

{\begin{p}{Show that the 1-forms $\{dx^\mu\}$ are linearly independent.}
\end{p}

Suppose $\omega=\omega_\mu\,dx^\mu=0$. Then $\omega(\partial_\nu)=\omega_\mu\,dx^\mu(\partial_\nu)=\omega_\mu \partial_\nu x^\mu
=\omega_\nu=0$.

\begin{p}{Show that $\omega(v)(p)$ really depends only on $v_p$, not on
the values of $v$ at other points. Also, show that a 1-form is determined by its values at points.
In other words, if $\omega, \nu$ are two 1-forms on $M$ with $\omega_p=\nu_p$ for
every point $p\in M$, then $\omega=\nu$. }
\end{p}

Suppose $w$ is a vector field for which $w_p=0$ but generally $w_q\neq 0$. By linearity, $\omega(v+w)=\omega(v)+\omega(w)$.
Specializing to the point $p$, we have $\omega(v+w)(p)=\omega(v)(p)+\omega(w)(p)=\omega_p(v_p)+\omega_p(w_p)$. But
since $w_p=0$, the latter term is zero, and $\omega(v+w)(p)=\omega(v)(p)$. This means we can change the field $v$ at points
distinct from $p$ and still obtain the same action by $omega$ at the desired point. Note that this works due to the linearity of the
map $\omega$.\\

Since we can ``decompose'' the field $v$ into tangent vectors $v_p$ at each point $p\in M$, (excercise 10), we have
$\omega_p(v_p)=\nu_p(v_p) = \omega(v)(p)=\nu(v)(p)$. This has to hold for any $v$ and all $p$, so $\omega=\nu$.\\

\begin{p}{Show that the dual of the identity map on a vector space $V$ is the identity map on $V^*$. Suppose
that we have linear maps $f:V\rightarrow W$ and $g:W\rightarrow X$. Show that $(gf)^*=f^*g^*$. }
\end{p}

The dual of a function $f$ is defined by $(f^*\omega)(v)=\omega(f(v))$. So if $f$ is the identity, then $(f^*\omega)(v)=\omega(v)$,
meaning that $f^*$ must be the identity as well.
Now we find $[(gf)^*\omega](v)=\omega(g(f(v)))=[g^*\omega](f(v))=[f^*g^*\omega](v)$,
so  $(gf)^*=f^*g^*$.

\begin{p}{Show that the pullback defined by the equation $(\phi^*\omega)_p=\phi^*(\omega_q)$, where $\phi(p)=q$,
really exists and is unique.}
\end{p}

Start with  $(\phi^*\omega)_p(v_p)=\phi^*\omega(v)(p)=\omega(\phi_*v)(\phi(p))=\omega(\phi_*v)(q)$. The other
side of the equation gives $\phi^*(\omega_q)v_q=\omega_q(\phi_* v_q)$, the same. Uniqueness follows from linearity: if there were
two possible outputs, we could consider their difference. By linearity this would be the result of applying the map to the difference of the
fixed input, which is zero. But the output of zero is zero, so the two possible outputs are equal.\\

\begin{p}{Let $\phi:\R\rightarrow \R$ be given by $\phi(t)=\sin t$. Let $dx$ be the usual
1-form on $\R$. Show that $\phi^*dx=\cos t\,dt$.}
\end{p}

$\phi^*(df)=d(\phi^*f)$ since the exterior derivative is natural. Thus $\phi^*(df)=d(\sin t)=\cos t\,dt$.

\begin{p}{Let $\phi:\R^2\rightarrow \R^2$ denote rotation counterclockwise by the
angle $\theta$. Let $dx, dy$ be the usual basis of 1-forms on $\R^2$. Show that $\phi^*dx=\cos\theta\,dx-\sin\theta\,dy$
and $\phi^*dy=\sin\theta\,dx+\cos\theta\,dy$. }
\end{p}

$\phi^*dx=d(\phi^*x)=d(x\cos\theta-y\sin\theta)=\cos\theta\,dx-\sin\theta\,dy$. Similarly for $\phi^*dy$.

\begin{p}{Show that the coordinate 1-forms $dx^\mu$ really are the differentials of the local coordinates $x^\mu$ on $U$.}
\end{p}

Technically, $x^\mu$ is the local coordinate on $\R^n$ which picks out the $\mu$th component. When speaking
of $x^\mu$ on $U$, we really mean $\phi^*x^\mu$, where $\phi$ is the map from $U$ to $\R^n$. Thus
$dx^\mu$ is really $d(\phi^*x^\mu)=\phi^*dx^\mu$, so the sloppiness of the notation doesn't injure the relationship
between functions and 1-forms.

\begin{p}{Show that $dx'^\nu=\frac{\partial x'^\nu}{\partial x^\mu}dx^\mu$. Show that for any 1-form $\omega$ on $\R^n$,
writing $\om=\om_\mu dx^\mu=\om'_\nu dx'^\nu$, the components $\omega'_\nu$ are related to the components $\omega_\mu$ by
$\omega'_\nu=\frac{\partial x^\mu}{\partial x'^\nu}\om_\mu$.}
\end{p}

For the first equation, apply both sides to the partial $\partial_\alpha$: $dx'^\nu(\partial_\alpha)=
\partial_\alpha(x'^\nu)$ and $\frac{\partial x'^\nu}{\partial x^\mu}dx^\mu(\partial_\alpha)=
\frac{\partial x'^\nu}{\partial x^\mu}\partial_\alpha(x^\mu)=
\frac{\partial x'^\nu}{\partial x^\mu}\delta^\mu_\alpha=\frac{\partial x'^\nu}{\partial x^\alpha}=
\partial_\alpha(x'^\nu)$. For the second, use the same trick. Apply $\om$ to
$\frac{\partial}{\partial x'^\alpha}$. The left expression gives $\om_\mu dx^\mu(\frac{\partial}{\partial x'^\alpha})=
\om_\mu\frac{\partial x^\mu}{\partial x'^\alpha}$, while the right expression gives $\om'_\alpha$.\\

\begin{p}{Show that $\phi^*(dx'^\nu)=\frac{\partial x'^\nu}{\partial x^\mu}dx^\mu$.}
\end{p}

$\phi^*(dx'^\nu)\partial_\mu=d(\phi^*x'^\nu)\partial_\mu=\partial_\mu(\phi^* x'^\nu)=\frac{\partial x'^\nu}{\partial x^\mu}$.

\begin{p}{Let $e_\mu=T^\nu_\mu\partial_\nu$, where $\partial_\nu$ are the coordinate vector fields associated to local coordinates on
an open set $U$ and $T^\nu_\mu$ are functions on $U$. Show that the vector fields $e_\mu$ are a basis of vector fields on $U$ iff for
each $p\in U$ the matrix $T^\nu_\mu(p)$ is invertible.}
\end{p}

\begin{itemize}
\item[$\Rightarrow$] The matrix $T^\nu_\mu(p)$ is invertible, so det$T\neq 0$, meaning the $e_u$ are linearly independent at $p$ and thus
form a basis at $p$. Since this works for all $p$, the vector fields $e_\mu$ are a basis.
\item[$\Leftarrow$] Try to expand an arbitrary $\om$ in terms of the $e_\mu$: $\om=\om^\mu e_\mu$. We can also express
$\om$ in terms of the $\partial_\nu$ as $\om=\om'^\nu\partial_\nu$, with $\om'^\nu= T^\nu_\mu \om^\mu$. If $T$ were not invertible,
we would not be able to construct the $\om^\mu$ from the $\om'^\nu$ (which are the ones guaranteed to exist), so $e_\mu$ wouldn't be
a basis. Since it is a basis, $T$ must be invertible.
\end{itemize}

\begin{p}{Use the previous exercise to show that the dual basis exists and is unique}
\end{p}

Let $f^\mu$ be the putative dual basis to the $e_\nu$. Then $f^\mu(e_\nu)=\delta^\mu_\nu=T^\lambda_\nu f^\mu\partial_\lambda$.
Now suppose $f^\mu=S^\mu_\lambda dx^\lambda$. Inserting into the previous equation we obtain $T^\lambda_\nu S^\mu_\lambda=\delta^\mu_\nu$, so $S$ is the inverse of $T$. Since $T$ is invertible, the $f^\mu$ are well-defined and unique.

\begin{p}{Let $e_\mu$ be a basis of vector fields on $U$ and let $f^\mu$ be the dual basis of 1-forms. Let $e'_\mu=T^\nu_\mu e_\nu$
be another basis of vector fields, and let $f'^\mu$ be the corresponding dual basis of 1-forms. Show that $f'^\mu=(T^{-1})^\mu_\nu f^\nu$. Show
that if $v=v^\mu e_\mu=v'^\mu e'_\mu$, then $v'^\mu=(T^{-1})^\mu_\nu v^\nu$ and that if
$\om=\om_\mu f^\mu=\om'_\mu f'^\mu$ then $\om'_\mu=T^\nu_\mu \om_\nu$.}
\end{p}

This is where the ``historical'' definitions of co- and contra-variant come from, specifying whether something transforms like the components
of a vector or like the basis vectors themselves. (Vectors, being susceptible to pushforward, are covariant. 1-forms are contravariant, but the components of a vector are also contravariant, while the components of 1-forms are covariant.) For $f'^\mu$, apply it to $e'_\nu$:
$f'^\mu(e'_\nu)=\delta^\mu_\nu$. Using the definition of $e'_\nu$, $\delta^\mu_\nu=T_\nu^\lambda f'^\mu(e_\lambda)$.
This works if $f'^\mu=(T^{-1})^\mu_\nu f^\nu$. All this can be done more easily in matrix notation. For the next case, let $\mathbf{v}$ be the
ordered set of $v^\mu$ and likewise $\mathbf{e}$ the set of $e_\mu$. Then $v=\mathbf{v}\cdot\mathbf{e}$. Meanwhile, $\mathbf{e}'=T\mathbf{e}$, so clearly we're going to need $\mathbf{v}'=(T^{-1})^T\mathbf{v}$ so that
$\mathbf{v}'\cdot\mathbf{e}'=\mathbf{v}T^{-1}T\mathbf{e}=v$. Thus, we predict that $v'^\mu=(T^{-1})^\mu_\nu v^\nu$, using
the inverse and transposed $T$ as given in the definition of $e'_\mu$. Similarly $\om=\mathbf{\om}\cdot\mathbf{f}$, so
$\om'_\mu=T^\nu_\mu \om_\nu$.

\begin{p}{Show that $u\wedge v\wedge w={\rm det}\left(\begin{array}{ccc} u_x & u_y & u_z \\
v_x & v_y & v_z\\ w_x & w_y & w_z\end{array}\right)\,dx\wedge dy\wedge dz$. Compare this to $\vec{u}\cdot(\vec{v}\times\vec{w})$.}
\end{p}

...algebra

\begin{p}{Show that if $a,b,c,d$ are four 1-forms in a 3-dimensional space, then $a\wedge b\wedge c\wedge d=0$.}
\end{p}

Since there are only three linearly independent 1-forms in this space, the 4-fold wedge product will always contain two of the basis
elements twice, which by antisymmetry, means the entire expression must be zero.

\begin{p}{Describe $\bigwedge V$ if $V$ is 1-,2-,3-, or 4-dimensional.}
\end{p}

1-dimensional: scalars and vectors. 2-dimensional: scalars, vectors, and areas. 3-dimensional: scalars, vectors, areas, and volumes. 4-dimensional:
all the previous, plus 4-volumes.

\begin{p}{Let $V$ be an n-dimensional vector space. Show that $\bigwedge^{\!p} V$ is empty for $p>n$ and that for $0\leq p\leq n$ the dimension of $\bigwedge^{\!p} V$ is $n!/p!(n-p)!$.}
\end{p}

As in exercise 42, elements of $\bigwedge^{\!p} V$ are wedge products of $p$ different terms, but since there are only $n$ independent possibilities,
$\bigwedge^{\!p} V$ is empty for $p>n$. Wedging $p$ different terms for $p\leq n$ can be done in $\binom{n}{p}$ ways since by antisymmetry
the order of the terms can only affect the sign of the result.

\begin{p}
{Show that $\bigwedge V=\bigoplus_p \bigwedge^{\!p} V$.}
\end{p}

Since we've defined $\bigwedge V$ formally, as the linear space of wedge products of elements of $V$, we then immediately have
that the different sectors corresponding to different number of wedgings $p$ are disjoint. Thus we can treat these
completely independently from one another and form $n$-tuples containing entries from each sector. This will be an element of
$\bigwedge V$ since adding elements of distinct grade is also purely formal and can always be resolved into the various
graded components. Thus, $\bigwedge V=\bigoplus_p \bigwedge^{\!p} V$.

\begin{p}{Given a vector space $V$, show that $\bigwedge V$ is a graded commutative or supercommutative algebra;
that is, if $\om\in \bigwedge^{\!p}V$ and $\mu\in\bigwedge^{\!q}V$, then $\om\wedge\mu=(-1)^{pq}\mu\wedge\om$.}
\end{p}

This is essentially just a counting argument. $\om$ is the wedge of $p$ things, $\mu$ $q$. So to invert the order of wedging
them together means transporting $p$ elements of $V$ past $q$ elements of $V$, each time picking up a minus one.

\begin{p}{Show that differential forms are contravariant. That is, show that if $\phi:M\rightarrow N$ is a map from the manifold
$M$ to the manifold $N$, there is a unique pullback map $\phi^*:\Omega(N)\rightarrow\Omega(M)$ agreeing with the usual pullback
on 0-forms (functions) and 1-forms, satisfying $\phi^*(\alpha\om)=\alpha\phi^*\om$, $\phi^*(\om+\mu)=\phi^*\om+\phi^*\mu$ and
$\phi^*(\om\wedge \mu)=\phi^*\om\wedge\phi^*\mu$, for all $\om,\mu\in\Omega(N)$ and $\alpha\in\R$.}
\end{p}

I take the three conditions to almost be the definition of the map. For a general $\om$, resolve it into a linear combination of
graded components using an arbitrary basis of 1-forms to generate the $p$-forms. The by condition two the pullback applies to each
term separately. By condition one the coefficients of each term don't interfere with the pullback. Finally, by condition three we apply the pullback
to each of the 1-forms making up the basis $p$-forms, so the map is well-defined. Its unique because the pullback applied to 1-forms and
functions is unique.

\begin{p}{Compare the transformation properties of 1-forms and 2-forms on $\R^3$ under parity. That is, let $P:\R^3\rightarrow\R^3$ be the map $P(x,y,z)=(-x,-y,-z)$, known as the `parity transformation'.
Note that $P$ maps right-handed bases to left-handed bases and vice versa. Compute $\phi^*\om$ when $\om$ is the 1-form
$\om_\mu dx^\mu$ and when it is the 2-form $\frac{1}{2}\omega_{\mu,\nu} dx^\mu\wedge dx^\nu$.}
\end{p}

If prime variables refer to the output space, for instance $x'=-x$, the
essential point is that $\phi^*(dx'^\mu)=d(\phi^* x'^\mu)=d(-x^\mu)=-dx^\mu$. Thus
$\phi^*\om^{(1)}=-\om$ and $\phi^*\om^{(2)}=\om^{(2)}$.

\begin{p}{Show that on $\rn$ the exterior derivative of any 1-form is given by $d(\om_\mu dx^\mu)=\partial_\nu\om_\mu dx^\nu\wedge dx^\mu$.}
\end{p}

$d(\om_\mu dx^\mu)=d\om_\mu\wedge dx^\mu=\partial_\nu\om_\mu dx^\nu\wedge dx^\mu$.


\chapter{Matrices}

The plural of \emph{matrix} is \emph{matrices}.

Matrices were invented to abbreviate systems of linear equations?%
\footnote{\url{https://en.wikipedia.org/wiki/Matrix_(mathematics)\#History}}

A matrix is a rectangular array of numbers.

We write \(A_{ij}\) or \(A(i,j)\) to mean the cell at row \(i\) column \(j\).

\paragraph{Finding the dimension of a matrix}

We say that the dimension of a matrix \(A\) is \((m,n)\),
written \(\dim(A) = (m,n)\),
iff the matrix has \(m\) rows and \(n\) columns.

\paragraph{Example}
The following matrix has 2 rows and 3 columns, so its dimension is \((2,3)\).
\Formula{\NoNumber
    \Matrix{
        A_{11} & A_{12} & A_{13}
        \\
        A_{21} & A_{22} & A_{23}
    }
}

\section*{Don't confuse vectors and coordinate tuples}

Use the phrases \emph{column matrix} and \emph{row matrix}
instead of \emph{column vector} and \emph{row vector}.%
\footnote{\url{https://en.wikipedia.org/wiki/Row_and_column_vectors}}

The phrase \emph{column vector} confuses a geometric vector and
the coordinate tuple that describes the vector.

A vector is \emph{not} a bunch numbers.
A vector is a geometric object with length and direction.
A vector can be \emph{described} by a coordinate tuple under a coordinate system.

\section{Working with matrices}

\subsection{Multiplying matrices}

Matrix addition is simple:
add the elements at the same positions:
\Formula{
    (AB)_{ij} = A_{ij} + B_{ij}
}

The cell \((AB)_{ij}\) depends on row \(i\) of \(A\) and column \(j\) of \(B\).
\Formula{
    (AB)_{ij} = \sum_k A_{ik} B_{kj}
}

\subsection{Abbreviating a system of linear equations into a matrix equation}

A matrix \enquote{packs} a system of linear equations into one equation.

\[ AB = C \]

\subsection{Linear function? Using matrix to describe a linear transformation?}

A matrix is a linear map?

A matrix is a vector of covectors?

A linear function is called linear because it describes a line.

A function \(f\) is \emph{linear} iff \( f(x+y) = f(x) + f(y) \).

A \emph{transformation} is another word for function.

Transformation.
Linear transformation.
$T(ax+by) = aTx + bTy$.

Matrix arises naturally for describing linear transformations on a vector space.

\section{Generalizing vectors, matrices, and tensors to functions of indexes}

The notation \(A(i)\) suggests that a vector is a function \( I \to \Real \).
The notation \(A(i,j)\) suggests that a matrix is a function \( (I,J) \to \Real \).

\section{Thinking of a matrix as a linear operator}

\section{Tuple vs array vs matrix vs tensor}

An array is a bunch of numbers.

A matrix is a \emph{rectangular} array for which matrix operations are defined.

A tensor carries with it a coordinate system?

A tensor is \emph{not only} a multi-dimensional array of numbers.

A tuple is a one-dimensional (linear) array.

A matrix is a two-dimensional (rectangular) array.

A tensor is a multi-dimensional array.


\section{A short application to chemistry}

The following section applies the concepts of spanning and linear independence to the subject of chemistry.

When working with chemical reactions, there are sometimes a large number of reactions and some are in a sense redundant. Suppose you have the following chemical
reactions.
\begin{equation*}
\begin{array}{c}
CO+\vspace{0.05in}\frac{1}{2}O_{2}\rightarrow CO_{2} \\
H_{2}+\vspace{0.05in}\frac{1}{2}O_{2}\rightarrow H_{2}O \\
CH_{4}+\vspace{0.05in}\frac{3}{2}O_{2}\rightarrow CO+2H_{2}O \\
CH_{4}+2O_{2}\rightarrow CO_{2}+2H_{2}O
\end{array}
\end{equation*}
There are four chemical reactions here but they are not independent
reactions. There is some redundancy. What are the independent reactions? Is
there a way to consider a shorter list of reactions? To analyze this
situation, we can write the reactions in a matrix as follows
\begin{equation*}
\begin{mymatrix}{cccccc}
CO & O_{2} & CO_{2} & H_{2} & H_{2}O & CH_{4} \\
1 & 1/2 & -1 & 0 & 0 & 0 \\
0 & 1/2 & 0 & 1 & -1 & 0 \\
-1 & 3/2 & 0 & 0 & -2 & 1 \\
0 & 2 & -1 & 0 & -2 & 1
\end{mymatrix}
\end{equation*}

Each row contains the coefficients of the respective elements in each reaction. For example, the top row of numbers comes from $CO+\frac{1}{2}O_{2}-CO_{2}=0$ which
represents the first of the chemical reactions.

We can write these coefficients in the following matrix
\begin{equation*}
\begin{mymatrix}{rrrrrr}
1 & 1/2 & -1 & 0 & 0 & 0 \\
0 & 1/2 & 0 & 1 & -1 & 0 \\
-1 & 3/2 & 0 & 0 & -2 & 1 \\
0 & 2 & -1 & 0 & -2 & 1
\end{mymatrix}
\end{equation*}
Rather than listing all of the
reactions as above, it would be more efficient to only list those which are independent by throwing out that which is redundant. We can use the concepts of the previous section to accomplish this.

First, take the {\rref} of the above matrix.
\begin{equation*}
\begin{mymatrix}{rrrrrr}
1 & 0 & 0 & 3 & -1 & -1 \\
0 & 1 & 0 & 2 & -2 & 0 \\
0 & 0 & 1 & 4 & -2 & -1 \\
0 & 0 & 0 & 0 & 0 & 0
\end{mymatrix}
\end{equation*}
The top three rows represent \textquotedblleft independent" reactions which
come from the original four reactions. One can obtain each of the original
four rows of the  matrix given above by taking a suitable
linear combination of rows of this {\rref} matrix.

With the redundant reaction removed, we can consider the simplified reactions as the following equations
\begin{equation*}
\begin{array}{c}
CO+3H_{2}-1H_{2}O-1CH_{4}=0 \\
O_{2}+2H_{2}-2H_{2}O=0 \\
CO_{2}+4H_{2}-2H_{2}O-1CH_{4}=0
\end{array}
\end{equation*}
In terms of the original notation, these are the reactions
\begin{equation*}
\begin{array}{c}
CO+3H_{2}\rightarrow H_{2}O+CH_{4} \\
O_{2}+2H_{2}\rightarrow 2H_{2}O \\
CO_{2}+4H_{2}\rightarrow 2H_{2}O+CH_{4}
\end{array}
\end{equation*}

These three reactions provide an equivalent system to the original four equations. The idea is that, in terms of what happens chemically, you
obtain the same information with the shorter list of reactions. Such a simplification is especially useful when dealing with very large lists of reactions which may result from experimental evidence.


\subsection{Numerical Experiments}

    Now, we will proceed to describe the steps necessary to implement the method based on the above:
    \begin{enumerate}
    	\item We are going to consider the interval given by $[0, 1]$, which represents the domain of physical space, and similarly, the time will be set by the real value $t_f>0$ such that $[0, t_f]$. So, as a first step, we must define the problem well by choosing the parameters identified and required by the problem \ref{infinite_system}, which in the same way will be denoted by: $N$, $M$, $N_1 \in \mathbb{N}$, and $\alpha \in \mathbb{R}^+$.

    	\item Given the above information, it is possible to follow the same methodology that we have analyzed in \ref{finite_system}, and define as a second step the calculation of the set $J^{M, N}$ given by \ref{Conjunto_J}, and then, as an intermediate step, obtain the set of points for each domain that we have defined above.

    	As an observation, the choice of the set of points, in this case, is arbitrary, and for example, We could obtain them by calculating the points $\xi_i \in [0, 1]$ defined for each $i = 0, 1, \dots, p \in \mathbb{N}^+$ as
    	\begin{align*}
    		\xi_i = \xi_0 + i \Delta \xi, \hspace{2mm} i = 0, 1, \dots, p
    	\end{align*}
    	and similarly for $t_j \in [t_0, t_f]$ with $j = 0, 1, \dots, l \in \mathbb{N}^+$ to obtain the following
    	\begin{align*}
    		t_j = t_0 + j \Delta t, \hspace{2mm} \Delta t = \frac{t_f - t_0}{l}
    	\end{align*}

    	\item Concluding with the previous steps will allow us to obtain everything that is required to begin to construct the initial value problem of the system \ref{finite_system_vectorial}, which could be considered as the step that requires more attention because we must obtain the matrix $\bar{C}_{n, m}$ using the simplification given in \ref{Cnm}.

    	However, this calculation gives the impression that it will give us a lot of work, but when observing its expression we can notice that we only have to focus on each of the combinations given by the multiplication of the Hermite polynomials that we must then integrate, for example, using some quadrature rule, and finally make its summation.

    	\item Successfully achieving this last step, what remains are to solve an eigenvalue problem given by \ref{eigen}, which is solved by some conventional numerical method to obtain the eigenvalues $\eta_i$ with their respective eigenvectors $V_i$.

    	Then, Using the functional $u_0$ as in \ref{IC_approx} to calculate the constants $c_k$ for each $k = 1, \dots, M$, and by using the expansion given by \ref{solution_finite_system} to obtain the solution of the problem as follows

    	\begin{align*}
    		u^M(x_i, t_j) = \displaystyle \sum_{k=1}^{M} u_k (t_j) H_k (x_i), \hspace{2mm} \left\{x_i\right\}_{i=0}^{p} \in \left[ 0, 1 \right], \left\{t_j\right\}_{j=0}^{l} \in \left[ 0, t_f \right]
    	\end{align*}
    \end{enumerate}

    The following simulations that will be shown were performed using a discretization of $2048$ points in the spatial variable $\xi$ over the interval $[0, 1]$, and $1024$ points in the variable time $t$ over the interval $[0, 10]$. In addition, the values of the parameters $N = 5$, $M = 11$, and $\alpha = 1.0 \times 10^{-2}$ were considered. With this information, the solutions obtained were calculated using the following initial condition and its truncated Chebysheb expansion given by
    \begin{align*}
    	x(\xi) = \sin(\pi \xi), \hspace{3mm} y(\xi) = \displaystyle \sum^{N}_{k=0} c_k T_k (\xi),
    \end{align*}

    This numerical experiment consists of illustrating an interesting result given in \cite{Delgado2019}, which tells us that the solutions obtained from two close initial conditions also remain close. This behavior allows characterizing what is known as the stability of the approximation, and it is described by means of continuity with respect to the initial conditions of the numerical approximations of the equation (\ref{kolmogorov}). \\

    To understand this better, let us denote by $\Psi^{x}_t$ the solution of (\ref{kolmogorov}) obtained by
    \begin{align*}
    	u(x, t) = \mathbb{E} \left[ \varphi (X^x_t) \right].
    \end{align*}
    where $\varphi: \mathcal{H} \rightarrow \mathbb{R}$ is Lipschitz and $X^x_t$ is the solution to (\ref{stochastic_equation}) with initial conditions $X_0 = x \in \mathcal{H}$. So, as before, its expansion is given by
    \begin{align*}
    	\Psi^{x}_t = \displaystyle \sum _{n \in \mathcal{J}} u_n (t) H_n (x), \hspace{2mm} x \in \mathcal{H}, \hspace{2mm} t \in [0, T].
    \end{align*}

    Therefore, following our reference, the above is summarized as follows: Given two different initial conditions $x, y \in \mathcal{H}$, then we have the following estimate
	\begin{align*}
		\| \Psi^x_t - \Psi^y_t \|^2_{\left( L^2 (\mathcal{H}, \mu)\right)^2} \leq \exp(Ct) \displaystyle \int_{\mathcal{H} \times \mathcal{H}} \|x - y \|^2_{\mathcal{H}} \mu (dx) \mu (dy) + f(t) \|x - y\|_{\mathcal{H}},
	\end{align*}
	for some $C$ finite and $f(t)$ is given by
	\begin{align*}
		f(t) = \displaystyle \sum_{n \in J} \left[u^y_n (t)\right]^2 + \int_{\mathcal{H}} \mathbb{E}^2 \left[\varphi (X^y_t)\right] \mu (dy).
	\end{align*}

	From the above, we can see that if $ \| x - y \|_{\mathcal{H}} \leq \delta$, so we have to $\| \Psi^x_t - \Psi^y_t \| \leq G (t) \delta$. As we have already mentioned, this continuity defines a type of stability for approximations, which is of utmost importance in this field since characterizations of this type are still under construction and are essential for the analysis of a numerical method. \\

	This behavior is shown in the following figures, which were obtained using codes that were created following the previous steps, and which can be found in \url{https://github.com/alanmatzumiya/Paper.git}. In figure \ref{IC_Cheb} it shows us the two initial conditions for which the equation (\ref{kolmogorov}) will be solved by associating it with (\ref{burgers_stochastic}), and in figure \ref{Stochastic_Solutions} we can see that the solutions keep the distance. Finally, the figure \ref{Continuity} shows the distances for each instant of time $t$, showing that they are actually getting closer as time passes.

\newpage
	\begin{figure}[H]
		\centering
		\includegraphics[width=.55\textwidth]{burgers_equation/stochastic/numerical_experiments/figures/IC.png}
		\caption{Initial condition for (\ref{burgers_stochastic2}) and its approximation.}
		\label{IC_Cheb}
		\includegraphics[width=.9\textwidth]{burgers_equation/stochastic/numerical_experiments/figures/Numerical_Solution_Stochastic.png}
		\caption{Numerical solutions for (\ref{burgers_stochastic2}) with initial conditions $x(\xi)$ and $y(\xi)$.}
		\label{Stochastic_Solutions}
	\end{figure}
\newpage
	\begin{figure}[H]
	\centering
		\includegraphics[width=.7\textwidth]{burgers_equation/stochastic/numerical_experiments/figures/norms.png}
		\caption{Distance between the numerical solutions for equation (\ref{burgers_stochastic2}) with initial conditions $x(\xi)$, and $y(\xi)$.}
		\label{Continuity}
	\end{figure}


\section{L'H\^opital's Rule}\label{sec:LH}
The following application of derivatives allows us to compute certain limits.

\begin{definition}{Limits of the Indeterminate Forms $\frac{0}{0}$ and $\frac{\infty}{\infty}$}{IndeterminateLimits}
A limit of a quotient $\lim\limits_{x\rightarrow a}\frac{f\left( x\right) }{%
	g\left( x\right) }$ is said to be an \textbf{indeterminate form of the type }%
$\frac{0}{0}$ if both $f\left( x\right) \rightarrow 0$ and $g\left( x\right)
\rightarrow 0$ as $x\rightarrow a.$ Likewise, it is said to be an \textbf{%
	indeterminate form of the type} $\frac{\infty }{\infty }$ if both $f\left(
x\right) \rightarrow \pm \infty $ and $g\left( x\right) \rightarrow \pm
\infty $ as $x\rightarrow a$ (Here, the two $\pm $ signs are independent of
each other).
\end{definition}

\begin{theorem}{L'H\^opital's Rule}{LHRule}
For a limit $\lim\limits_{x\rightarrow a}\frac{f\left( x\right) }{g\left(
	x\right) }$ of the indeterminate form $\frac{0}{0}$ or $\frac{\infty }{%
	\infty },$ $\lim\limits_{x\rightarrow a}\frac{f\left( x\right) }{g\left(
	x\right) }=\lim\limits_{x\rightarrow a}\frac{f^{\prime }\left( x\right) }{%
	g^{\prime }\left( x\right) }$ if $\lim\limits_{x\rightarrow a}\frac{%
	f^{\prime }\left( x\right) }{g^{\prime }\left( x\right) }$ exists or equals $%
\infty $ or $-\infty$.
\end{theorem}

This theorem is somewhat difficult to prove, in part because it
incorporates so many different possibilities, so we will not prove it
here.

We should also note that there may be instances where we would need to apply L'H\^opital's Rule multiple times, but we must confirm that $\lim_{x\to a}\frac{f'(x)}{g'(x)}$ is still indeterminate before we attempt to apply L'H\^opital's Rule again. Finally, we want to mention that L'H\^opital's rule is also valid for one-sided limits and limits at infinity.

\begin{example}{L'H\^opital's Rule}{lhrule0}
Compute $\ds\lim_{x\to \pi}\frac{x^2-\pi^2}{\sin x}$.
\end{example}

\begin{solution}
We use L'H\^opital's Rule: Since the numerator and denominator
both approach zero,
$$\lim_{x\to \pi}\frac{x^2-\pi^2}{\sin x}=
\lim_{x\to \pi}\frac{2x}{\cos x},$$
provided the latter exists. But in fact this is an easy limit, since
the denominator now approaches $-1$, so
$$\lim_{x\to \pi}\frac{x^2-\pi^2}{\sin x}=\frac{2\pi}{-1} = -2\pi.$$
\end{solution}

\begin{example}{L'H\^opital's Rule}{LHRule1}
Compute $\ds\lim_{x\to \infty}{2x^2-3x+7\over
x^2+47x+1}$.
\end{example}

\begin{solution}
As $x$ goes to infinity, both the numerator and denominator go to
infinity, so we may apply L'H\^opital's Rule:
$$\lim_{x\to \infty}\frac{2x^2-3x+7}{x^2+47x+1}=
\lim_{x\to \infty}\frac{4x-3}{2x+47}.$$
In the second quotient, it is still the case that the numerator and
denominator both go to infinity, so we are allowed to use
L'H\^opital's Rule again:
$$\lim_{x\to \infty}\frac{4x-3}{2x+47}=\lim_{x\to \infty}\frac{4}{2}=2.$$
So the original limit is 2 as well.
\end{solution}

\begin{example} {L'H\^opital's Rule}{LHRule2}
Compute $\ds\lim_{x\to 0}\frac{\sec x - 1}{\sin x}$.
\end{example}

\begin{solution}
Both the numerator and denominator approach zero, so applying
L'H\^opital's Rule:
$$\lim_{x\to 0}\frac{\sec x - 1}{\sin x}=
\lim_{x\to 0}\frac{\sec x\tan x}{\cos x}=\frac{1\cdot 0}{1}=0.$$
\end{solution}

L'H\^{o}pital's rule concerns limits of a quotient that are indeterminate forms. But not all
functions are given in the form of a quotient. But all the same, nothing
prevents us from re-writing a given function in the form of a quotient.
Indeed, some functions whose given form involve either a product $f\left(
x\right) g\left( x\right) $ or a power $f\left( x\right) ^{g\left( x\right)
} $ carry indeterminacies such as $0\cdot \pm \infty $ and $1^{\pm \infty }.$
Something small times something numerically large (positive or negative)
could be anything. It depends on how small and how large each piece turns
out to be. A number close to 1 raised to a numerically large (positive or
negative) power could be anything. It depends on how close to 1 the base is,
whether the base is larger than or smaller than 1, and how large the
exponent is (and its sign). We can use suitable algebraic manipulations to
relate them to indeterminate quotients. We will illustrate with two
examples, first a product and then a power.

\begin{example}{L'H\^opital's Rule}{LHRule3}
Compute $\ds\lim_{x\to 0^+} x\ln x$.
\end{example}

\begin{solution}
This doesn't appear to be suitable for L'H\^opital's Rule, but it also
is not ``obvious''. As $x$ approaches zero, $\ln x$ goes to $-\infty$,
so the product looks like:
$$(\hbox{something very small})\cdot(\hbox{something very large and negative}).$$
This could be anything: it depends on {\it how small} and
{\it how large} each piece of the function turns out to be.
As defined earlier, this is a type of $\pm\mathquotes{0\cdot\infty}$, which is
indeterminate. So we can in fact apply L'H\^opital's Rule after re-writing
it in the form $\frac{\infty }{\infty }$:
$$x\ln x = \frac{\ln x}{1/x}=\frac{\ln x}{x^{-1}}.$$
Now as $x$ approaches zero, both the numerator and denominator
approach infinity (one $-\infty$ and one $+\infty$, but only the size
is important). Using  L'H\^opital's Rule:
$$\lim_{x\to 0^+} {\ln x\over x^{-1}}=
\lim_{x\to 0^+} {1/x\over -x^{-2}} =\lim_{x\to 0^+} {1\over x}(-x^2)=
\lim_{x\to 0^+} -x = 0.$$
One way to interpret this is that since $\ds\lim_{x\to
  0^+}x\ln x = 0$, the $x$ approaches zero much faster than the $\ln x$
approaches $-\infty$.
\end{solution}

Finally, we illustrate how a limit of the type $\mathquotes{1^\infty}$ can be indeterminate.

\begin{example} {L'H\^opital's Rule}{LHRule4}
Evaluate $\ds{\lim_{x\to 1^+}x^{1/(x-1)}}.$
\end{example}

\begin{solution}
Plugging in $x=1$ (from the right) gives a limit of the type $\mathquotes{1^\infty}$.
To deal with this type of limit we will use logarithms.
Let
$$L=\lim_{x\to 1^+}x^{1/(x-1)}.$$
Now, take the natural log of both sides:
$$\ln L=\lim_{x\to 1^+}\ln\left(x^{1/(x-1)}\right).$$
Using log properties we have:
$$\ln L=\lim_{x\to 1^+}\frac{\ln x}{x-1}.$$
The right side limit is now of the type $0/0$, therefore, we can apply L'H\^opital's Rule:
$$\ln L=\lim_{x\to 1^+}\frac{\ln x}{x-1}=\lim_{x\to 1^+}\frac{1/x}{1}=1$$
Thus, $\ln L=1$ and hence, our original limit (denoted by $L$) is: $L=e^1=e$. That is,
$$L=\lim_{x\to 1^+}x^{1/(x-1)}=e.$$
In this case, even though our limit had a type of $\mathquotes{1^\infty}$, it actually had a value of $e$.
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:LH}}

\begin{enumialphparenastyle}

Compute the following limits.

%%%%%%%%%%
\begin{ex}
$\ds\lim_{x\to 0} {\cos x -1\over \sin x}$
\begin{sol}
 $0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
$\ds\lim_{x\to \infty} {e^x\over x^3}$
\begin{sol}
 $\infty$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
$\ds\lim_{x\to \infty} {\ln x\over x}$
\begin{sol}
 $0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
$\ds\lim_{x\to \infty} {\ln x\over \sqrt{x}}$
\begin{sol}
 $0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
$\ds\lim_{x\to0}{\sqrt{9+x}-3\over x}$
\begin{sol}
 $1/6$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
$\ds\lim_{x\to2}{2-\sqrt{x+2}\over 4-x^2}$
\begin{sol}
 $1/16$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to1}{\sqrt{x}-1\over \root 1/3\of{x}-1}$
\begin{sol}
 $3/2$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to0}{(1-x)^{1/4}-1\over x}$
\begin{sol}
 $-1/4$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{t\to 0}{\left(t+{1\over t}\right)((4-t)^{3/2}-8)}$
\begin{sol}
 $-3$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{t\to 0^+}\left({1\over t}+{1\over\sqrt{t}}\right)
(\sqrt{t+1}-1)$
\begin{sol}
 $1/2$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to 0}{x^2\over\sqrt{2x+1}-1}$
\begin{sol}
 $0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{u\to 1}{(u-1)^3\over (1/u)-u^2+3/u-3}$
\begin{sol}
 $-1$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to 0}{2+(1/x)\over 3-(2/x)}$
\begin{sol}
 $-1/2$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to 0^+}{1+5/\sqrt{x}\over 2+1/\sqrt{x}}$
\begin{sol}
 $5$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to\pi/2}{\cos x\over (\pi/2)-x}$
\begin{sol}
 $1$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to0}{e^x-1\over x}$
\begin{sol}
 $1$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to0}{x^2\over e^x-x-1}$
\begin{sol}
 $2$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to1}{\ln x\over x-1}$
\begin{sol}
 $1$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to0}{\ln(x^2+1)\over x}$
\begin{sol}
 $0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to1}{x\ln x\over x^2-1}$
\begin{sol}
 $1/2$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to0}{\sin(2x)\over\ln(x+1)}$
\begin{sol}
 $2$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to1}{x^{1/4}-1\over x}$
\begin{sol}
 $0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to1}{\sqrt{x}-1\over x-1}$
\begin{sol}
 $1/2$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to0}{3x^2+x+2\over x-4}$
\begin{sol}
 $-1/2$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to0}{\sqrt{x+1}-1\over \sqrt{x+4}-2}$
\begin{sol}
 $2$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to0}{\sqrt{x+1}-1\over \sqrt{x+2}-2}$
\begin{sol}
 $0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to0^+}{\sqrt{x+1}+1\over\sqrt{x+1}-1}$
\begin{sol}
 $\infty$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to0}{\sqrt{x^2+1}-1\over\sqrt{x+1}-1}$
\begin{sol}
 $0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to1}{(x+5)\left({1\over 2x}+{1\over x+2}\right)}$
\begin{sol}
 $5$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds\lim_{x\to2}{x^3-6x-2\over x^3+4}$
\begin{sol}
 $-1/2$
\end{sol}
\end{ex}

\begin{ex}
Discuss what happens if we try to use L'H\^{o}pital's rule to find the limit $\lim\limits_{x\rightarrow \infty}\dfrac{x+\sin x}{x+1}$.
\end{ex}

\end{enumialphparenastyle}


\documentclass{amsart}

\title{Abstract Data Types}
\author{Todd D. Vance}
\date{\today}

\begin{document}
\maketitle{}

\section{Abstract Data Type}
One method for designing classes in an object-oriented fashion is via an \emph{abstract data type}.  The various abstract data types can be defined formally or semi-formally, or in a casual language.  There are benefits to each of the various levels of formality.  The author proposes an axiomatic approach (similar to Nell/Walker (http://dl.acm.org/citation.cfm?id=230973), though perhaps less formally; see also Liskov/Zilles 1974, Programming with Abstract Data Types) as a way of accurately communicating the specification of a class as well as unit tests.  This approach to abstract data types can be thought of as being to the design of a system as ``test driven development'' is to the writing of the programs for a system.

\section{Set}
The ADT $\mathbf{set}$ can be specified by the following operations and axioms.  We assume another type $\mathbf{E}$ representing the type of the elements of the set.  This specifies an immutable set, where elements are added or removed by returning a new set.  Here are the supported operations:

\begin{enumerate}
\item $\mathrm{empty}:\emptyset\rightarrow\mathbf{set}$.
\item $\mathrm{size}:\mathbf{set}\rightarrow\mathbf{N}$ (where $\mathbf{N}$ represents nonnegative integers).
\item $\mathrm{contains}:\mathbf{set}\times\mathbf{E}\rightarrow\mathbf{bool}$ (where $\mathbf{bool}=\{\mathrm{true},\mathrm{false}\}$ represents the Boolean type).
\item $\mathrm{add}:\mathbf{set}\times\mathbf{E}\rightarrow\mathbf{set}$
\item $\mathrm{remove}:\mathbf{set}\times\mathbf{E}\rightarrow\mathbf{set}$
\end{enumerate}

Informally, $\mathrm{empy}$ is a nullary operation, that is, a constant.  It represents the empty set.  The $\mathrm{size}$ operation applied to any set returns the number of elements.  The $\mathrm{contains}$ operation applied to a set and an element returns $\mathrm{true}$ if the element is in the set.  Otherwise, it returns $\mathrm{false}$.  The $\mathrm{add}$ operation applied to a set and an element returns the set whose elements are the elements of the specified set along with the specified element.  The $\mathrm{remove}$ operation applied to a set and an element returns the set whose elements are the elements of the specified set except for the specified element.

The axioms specifying the behavior of the operations are as follows:

\begin{enumerate}
\item $\mathrm{size}(\mathrm{empty})=0$
\item if $\mathrm{contains}(s, e)=\mathrm{false}$, then $\mathrm{size}(\mathrm{add}(s, e)) = \mathrm{size}(s) + 1$
\item if $\mathrm{contains}(s, e)=\mathrm{true}$, then $\mathrm{add}(s, e) = s$
\item if $\mathrm{contains}(s, e)=\mathrm{true}$, then $\mathrm{size}(\mathrm{remove}(s, e)) = \mathrm{size}(s) - 1$
\item if $\mathrm{contains}(s, e)=\mathrm{false}$, then $\mathrm{remove}(s, e) = s$
\item $\mathrm{contains}(empty, e) = \mathrm{false}$
\item $\mathrm{contains}(\mathrm{add}(s, e), e)=\mathrm{true}$
\item If $e\ne{f}$, then $\mathrm{contains}(\mathrm{add}(s, e), f)=\mathrm{contains}(s,f)$
\item $\mathrm{contains}(\mathrm{remove}(s, e), e)=\mathrm{false}$
\item If $e\ne{f}$, then $\mathrm{contains}(\mathrm{remove}(s, e), f)=\mathrm{contains}(s,f)$
\end{enumerate}

One could specify a mutable version of $\mathbf{set}$ as a structure having just one modifiable attribute: the immutable set.  Thus, we have something like $s$, such that $s.\mathrm{set}$ is a $\mathbf{set}$.  We can modify $s$: $s.\mathrm{set} \leftarrow t$ where $t$ is some $\mathbf{set}$.

Instead of $\mathrm{empty}$ is $\mathrm{new~\mathbf{set}}$ which is a structure whose attribute is equal to $\mathrm{empty}$.    So, $s\leftarrow \mathrm{new~\mathbf{set}}$ causes $s.\mathrm{set}$ to equal $\mathrm{empty}$.

The $\mathrm{add}$ operation then modifies $s$ as follows: $\mathrm{add}(s, e)$ performs the operation $s.\mathrm{set}\leftarrow \mathrm{add}(\mathrm{set}, e)$.

Similarly, the $\mathrm{remove}$ operation modifies $s$ as follows: $\mathrm{remove}(s, e)$ performs the operation $s.\mathrm{set}\leftarrow \mathrm{remove}(\mathrm{set}, e)$.

The remaining operations just operate directly on $s.\mathrm{set}$.  So, $\mathrm{contains}(s, e)$ is equal to $\mathrm{contains}(s.\mathrm{set}, e)$, and likewise for the other operations.

The analogous scheme can be used to turn any immutable ADT having operations that return different instances of the ADT into a corresponding mutable ADT.

\end{document}


\section{Estimating with Sums}
If we know how something changes, we can use sums to estimate, or sometimes even know exactly the net change.

\begin{example}
	A train moves at 80 miles per hour for 3 hours.
	How far does it travel?
\end{example}
\begin{answer}
	This is the kind of simple problem you might see in a physics class.
	\begin{equation*}
		\frac{80\text{mi}}{\text{hr}} \hspace{3pt} 3\text{hr} = 80\cdot 3\text{mi} = 240 \text{mi}.
	\end{equation*}
	However, if we take a look at a graph of this situation, with speed in miles per hour on the $y$ axis and time in hours on the $x$ axis, we see that the area underneath the curve from $x=0\text{hr}$ to $x=3\text{hr}$ is exactly our answer of 240 miles.
	This is not a coincidence, as what we effectively did mathematically is find the area of this rectangle.

	\begin{figure}[H]
		\label{constant_graph}
		\centering
		\includegraphics[width = 0.33\textwidth]{./integrals/constant_graph.png}
		\caption{\hyperref{}{}{}{Our answer is the area under the curve.}}
	\end{figure}
	\end{answer}

The same idea of finding the area under the curve works not just for constant speeds.
\begin{example}
	A particle moves at velocity $v(t) = 3t + 3$ meters per second for time $t \geq 0$.
	What is the position of the particle at $t = 2$ seconds?
\end{example}
\begin{answer}
	\begin{figure}[H]
		\label{linear_graph}
		\centering
		\includegraphics[width = 0.5\textwidth]{./integrals/linear_graph.png}
		\caption{\hyperref{}{}{}{Our answer is still the area under the curve.}}
	\end{figure}
	\begin{align*}
		A &= \frac{1}{2}h(b_1 + b_2) \\
		&= \frac{1}{2}(2\text{s}-0\text{s})(v(0) + v(2)) \\
		&= \frac{1}{2}(2\text{s})(3\text{m/s} + 9\text{m/s}) \\
		&= 12\text{m}.
	\end{align*}
\end{answer}

\subsubsection{Left Endpoint Approximation}
In fact, the area under the curve even works for more complicated, non-linear curves like $v(t) = t^2 + 1$.
We just need a way to find the area underneath these curves.
One idea that was used to find areas as far back as Archimedes was to estimate the complex shape using easier shapes like rectangles.
The narrower the width of each rectangle, the better the estimate becomes.

\begin{figure}[H]
	\label{cos_blocks}
	\centering
	\includegraphics[width = 0.3\textwidth]{./integrals/cos_blocks1.png}
	\includegraphics[width = 0.3\textwidth]{./integrals/cos_blocks2.png}
	\includegraphics[width = 0.3\textwidth]{./integrals/cos_blocks3.png}
	\caption{\hyperref{}{}{}{Left Endpoint: Block widths of 1/3, 1/10, and 1/100.}}
\end{figure}

Although above we've used a left endpoint approximation, we could have also used the right endpoint or midpoint, which might give better approximations for certain types of curves.
No matter the approximation type, the estimate tends to get closer to the true area as the rectangle width is decreased.
The formulas for estimating the area of $f$ from $a$ to $b$ with $n$ rectangles are
\begin{align*}
	A_\text{left} &= \sum_{k=0}^{n-1}{f\left(a+k\Delta x\right)\Delta x} \\
	A_\text{right} &= \sum_{k=0}^{n-1}{f\left(a+(k+1)\Delta x\right)\Delta x} \\
	A_\text{mid} &= \sum_{k=0}^{n-1}{f\left(a+\frac{2k+1}{2}\Delta x\right)\Delta x} \\
	\text{where }\Delta x &= \frac{b-a}{n}.
\end{align*}

\subsubsection{Trapezoidal Rule}
Another common shape to use rather than rectangles is trapezoids.
Trapezoids allow us to find the exact area of functions made of straight lines\footnote{There are higher-order, more accurate estimations than the trapezoidal rule. The most common is Simpson's Rule. $A = \frac{2M+T}{3}$ where $M$ is the midpoint formula area and $T$ is the trapezoidal rule area. It can exactly give the area of quadratics because it corresponds to estimating areas using parabolas that intersect the curve at the left, middle, and right of each ``strip''.} and like the left endpoint approximation, get better the narrower the width of each trapezoid.
Starting from the formula, we can make some simplifications.
\begin{equation*}
	A = \frac{1}{2}(b_1 + b_2)h.
\end{equation*}
Now summing each of these trapezoids' areas to approximate our function $f$ from $a$ to $b$,
\begin{align*}
	A_\text{trap} &= \sum_{k=0}^{n-1}{\frac{1}{2}\left(f(a+i\Delta a) + f(a + (i+1)\Delta x)\right)\Delta x} \\
	&= \frac{\Delta x}{2}\sum_{k=0}^{n-1}{f(a + i\Delta x) + f(a + (i+1)\Delta x)} \\
	&= \frac{\Delta x}{2}\left(\left(f(a)+f(a+\Delta x)\right)+\left(f(a+\Delta x)+f(a+2\Delta x)\right)+\ldots+\left(f(a+(n-1)\Delta x)+f(a+n\Delta x)\right)\right) \\
	&= \frac{\Delta x}{2}\left(f(a) + 2f(a+\Delta x) + 2f(a + 2\Delta x) + \ldots + 2f(a+(n-1)\Delta x) + f(a+n\Delta x)\right) \\
	&= \frac{A_\text{left} + A_\text{right}}{2}.
\end{align*}

The trapezoidal rule overestimates areas when the curve is concave up and underestimates when the curve is concave down.


\section{The Jordan Normal Form}
We are interested in how nice a matrix can an arbitrary $\alpha\in L(\mathbb C^n)$ possibly have.
\begin{definition}
    Let $A\in M_n(\mathbb C)$.
    We say $A$ is in Jordan Normal Form (JNF) if it is a block diagonal matrix
    $$A=\begin{pmatrix}
        J_{n_1}(\lambda_1)&&&\\
        &J_{n_2}(\lambda_2)&&\\
        &&\ddots&\\
        &&&J_{n_k}(\lambda_k)
    \end{pmatrix}$$
    for $\{\lambda_i\}\in\mathbb C$ not necessarily distinct, $\sum_in_i=n$ and $J_r(\lambda)\in M_r(\mathbb C)$ are Jordan blocks of the form
    $$J_r(\lambda)=\begin{pmatrix}
        \lambda&1&&\\
        &\ddots&\ddots&\\
        &&\lambda&1\\
        &&&\lambda
    \end{pmatrix}$$
\end{definition}
\begin{theorem}
    Every matrix $A\in M_n(\mathbb C)$ is similar to a matrix in JNF which is unique up to reordering the Jordan blocks.
\end{theorem}
\begin{proof}
    Omitted.
\end{proof}
\begin{example}
    For $n=2$, the possible JNFs are simply ($\lambda,\lambda_1,\lambda_2\in F,\lambda_1\neq\lambda_2$)
    $$\begin{pmatrix}
        \lambda_1&0\\
        0&\lambda_2
    \end{pmatrix},\begin{pmatrix}
        \lambda&0\\
        0&\lambda
    \end{pmatrix},\begin{pmatrix}
        \lambda&1\\
        0&\lambda
    \end{pmatrix}$$
    with minimal polynomials $(t-\lambda_1)(t-\lambda_2),t-\lambda,(t-\lambda)^2$ respectively.\\
    For $n=3$, the JNFs (and their respective minimal polynomials) are, up to reordering of the blocks, ($\lambda,\lambda_1,\lambda_2,\lambda_3\in F$, $\lambda_1,\lambda_2,\lambda_3$ all distinct)
    $$\begin{pmatrix}
        \lambda_1&&\\
        &\lambda_2&\\
        &&\lambda_3
    \end{pmatrix}:(t-\lambda_1)(t-\lambda_2)(t-\lambda_3);\begin{pmatrix}
        \lambda_1&&\\
        &\lambda_2&\\
        &&\lambda_2
    \end{pmatrix}:(t-\lambda_1)(t-\lambda_2)$$
    $$\begin{pmatrix}
        \lambda_1&&\\
        &\lambda_2&1\\
        &&\lambda_2
    \end{pmatrix}:(t-\lambda_1)(t-\lambda_2)^2;\begin{pmatrix}
        \lambda&&\\
        &\lambda&\\
        &&\lambda
    \end{pmatrix}:(t-\lambda)$$
    $$\begin{pmatrix}
        \lambda&&\\
        &\lambda&1\\
        &&\lambda
    \end{pmatrix}:(t-\lambda)^2;\begin{pmatrix}
        \lambda&1&\\
        &\lambda&1\\
        &&\lambda
    \end{pmatrix}:(t-\lambda)^3$$
\end{example}
\begin{theorem}[Generalised Eigenspace Decomposition]
    Let $V$ be a finite dimensional vector space over $\mathbb C$ and $\alpha\in L(V)$.
    Let $\lambda+_1,\ldots,\lambda_k$ be distinct eigenvalues of $\alpha$ such that $m_\alpha(t)=(t-\lambda_1)^{c_1}\cdots(t-\lambda_k)^{c_k}$, then
    $$V=\bigoplus_{i=1}^kV_j,V_j=\ker((\alpha-\lambda_j\operatorname{id})^{c_j})$$
\end{theorem}
Here $V_j$ is called the generalised eigenspace.
\begin{remark}
    When $\alpha$ is diagonalisable, then $c_j=1$ for all $j$, consequently $V=\bigoplus_j\ker(\alpha-\lambda_j\operatorname{id})$ as we already know.
\end{remark}
\begin{proof}
    Define $p_j(t)=\prod_{i\neq j}(t-\lambda_i)^{c_i}$, then $\{p_j\}$ has no common factor, so we can find $q_1,\ldots,q_k$ such that $q_1p_1+\cdots+q_kp_k=1$.
    Define $\pi_j=q_jp_j(\alpha)$, then it follows that $\sum_j\pi_j=\operatorname{id}$.
    Also $(\alpha-\lambda_j\operatorname{id})^{c_j}\pi_j=0$, so $\operatorname{Im}\pi_j\subset V_j$, hence $V$ is the sum of all $V_j$.
    To see this sum is direct, simply observe that $\pi_i\pi_j=\delta_{ij}\pi_i$ for all $i,j$, so $\pi_i|_{V_j}=\delta_{ij}\operatorname{id}$.
    This completes the proof.
\end{proof}
\begin{remark}
    1. This decomposition allows us to reduce the proof of JNF to just one eigenvalue, which can be done via the study of nilpotent matrices.
    \footnote{That is if you want to do it the linear algebra way -- I like the $\mathbb C[X]$-module approach more.}
    The relation is found from the observation
    $$(J_m(\lambda)-\lambda\operatorname{id})^k=\begin{cases}
        \begin{pmatrix}
            0&I_{m-k}\\
            0&0
        \end{pmatrix}\text{, if $k<m$}\\
        0\text{, otherwise}
    \end{cases}$$
    2. We can very easily compute $a_\lambda,g_\lambda$ and $c_\lambda$ if we know the JNF.
    Indeed, $a_\lambda$ is the sum of sizes if the blocks with eigenvalue $\lambda$, $g_\lambda$ is the number of Jordan blocks with eigenvalue $\lambda$ and $c_\lambda$ is the size of the largest Jordan block with eigenvalue $\lambda$.
    This can (sometimes) be used to compute the JNF as well.
\end{remark}
\begin{example}
    Take
    $$A=\begin{pmatrix}
        0&-1\\
        1&2
    \end{pmatrix}$$
    We want to find a basis in which $A$ is in JNF.
    Now $\chi_A(t)=m_A(t)=(t-1)^2$, so the JNF is in the form
    $$\begin{pmatrix}
        1&1\\
        0&1
    \end{pmatrix}$$
    We want the basis, which naturally consists of eigenvectors.
    Indeed, $\ker(A-\operatorname{id})$ is spanned by $(1,-1)^\top$.
    Choose $v_2$ such that $(A-\operatorname{id})v_2=v_1$, which is nonunique but we can take $v_2=(-1,0)^\top$.
    So take the basis $\{v_1,v_2\}$ works.
    To put it concretely,
    $$A=\begin{pmatrix}
        1&-1\\
        -1&0
    \end{pmatrix}\begin{pmatrix}
        1&1\\
        0&1
    \end{pmatrix}\begin{pmatrix}
        1&-1\\
        -1&0
    \end{pmatrix}^{-1}$$
\end{example}


\section{Brownian Motion}

\problem{Brownian Motion. Finite-dimensional distributions.}
Let $0=s_0 < s_1 < \cdots < s_n$ be positive real numbers and $(B_{s_{1}},\dots ,B_{s_n})$
be a $n$-dimensional random vector with density given by
\begin{equation*}
    f(y_1,\dots ,y_n) = p(s_1, y_1, 0)p(s_2-s_1,y_2, y_1)\dots p(s_n-s_{n-1}, y_n, y_{n-1})
\end{equation*}
with
\begin{equation*}
    p(t, x,y ) = \frac{1}{\sqrt{2\pi t}} \exp(-\frac{(x-y)^2}{2t}).
\end{equation*}
Show that:
\begin{enumerate}
    \item The random variables $(B_{s_1}, B_{s_2}-B_{s_1},\dots ,B_{s_n}-B_{s_{n-1}})$
        are independent.
    \item The distribution of $B_{s_i}-B_{s_{i-1}}$ is $\cN(0, s_{i}-s_{i-1})$.
\end{enumerate}

\solution Use Jacobi's transformation formula with
$g:\bR^{n}\to\bR^{n}, (y_1,\dots ,y_n)\mapsto(y_1, y_2-y_1,\dots
,y_n-y_{n-1})$.

\problem{Maximum processes of the Brownian Motion. } Show that the process $W
- W^*$ has independent increments. $W$ denotes Brownian Motion and $X^*_t=
\max_{0 \leq s \leq t} X_s$ is the maximum process of a c\`adl\`ag process $X$.

\problem{Independence and transformations. } Let random variables
$X_1,\ldots,X_n$ and $Y_1,\ldots,Y_k$ satisfy $X_i \upmodels Y_j$ for all $i$
and $i$.
\begin{enumerate}
    \item It follows that $g(X_i)$ and $h(Y_j)$ are independent for any $i$ and
        $j$.
    \item A generalization of the above result is not true. Given any Borel
        functions $f$ and $g$ of suitable dimensionality $f(X_1,\ldots,X_n)$
        may be not independent of $g(Y_1,\ldots,Y_k)$.
\end{enumerate}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CS622: Theory of Formal Languages
% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>
% Creative Commons Attribution-ShareAlike 4.0 International License
% More info: https://github.com/ghorbanzade/beacon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{Question 4}

Let $ G $ be the context-free grammar $G = (\{S,X_1,X_2,X_3\},\{a,b,c\},S,P)$.
Construct an equivalent grammar in Chomsky's normal form if

\begin{equation}
\begin{aligned}
P =\ & \{ S\rightarrow X_1 X_2 X_3 X_1,\ S\rightarrow X_1 a X_2,\ X_1 \rightarrow X_1 X_2 X_3,\\
& X_1 \rightarrow a, X_2 \rightarrow X_3 X_1, X_2 \rightarrow b, X_3 \rightarrow c\}
\end{aligned}
\end{equation}

\subsection*{Solution}

A Context-free grammar is in \textit{Chomsky Normal Form} if all its productions are either of the form $X\rightarrow YZ$ or of the form $X\rightarrow a$ where $X,Y,Z \in A_N$ and $a\in A_T$.
By introducing the non-terminal symbol $X_a$ to $G$ we obtain

\begin{equation}
G_1 = (\{S, X_1, X_2, X_3, X_a\},\{a, b, c\},S,P_1)
\end{equation}

where

\begin{equation}
\begin{aligned}
P_1 =\ & \{ S\rightarrow X_1 X_2 X_3 X_1,\ S\rightarrow X_1 X_a X_2,\ X_1 \rightarrow X_1 X_2 X_3,\ X_2 \rightarrow X_3 X_1,\\
& X_1 \rightarrow a,\ X_2 \rightarrow b,\ X_3 \rightarrow c,\ X_a \rightarrow a\}
\end{aligned}
\end{equation}

Although $G_1$ has no chain productions and every production in $G_1$ that contains a terminal symbol is of the form $X\rightarrow a$, three productions $S\rightarrow X_1 X_2 X_3 X_1$, $S\rightarrow X_1 X_a X_2$ and $X_1 \rightarrow X_1 X_2 X_3$ violate Chomsky Normal form.
Thus, $Z_0$, $Z_1$, $Z_2$ are introduced as new non-terminal symbols.
A new equivalent grammar $G_2$ can be obtained as

\begin{equation}
G_2 = (\{S, X_1, X_2, X_3, X_a, Z_0, Z_1, Z_2\},\{a, b, c\},S,P_2)
\end{equation}

where

\begin{equation}
\begin{aligned}
P_2 =\ & \{ X_2 \rightarrow X_3 X_1,\ X_1 \rightarrow a,\ X_2 \rightarrow b,\ X_3 \rightarrow c,\ X_a \rightarrow a, \\
& S\rightarrow Z_0X_1,\ S\rightarrow X_1Z_2,\ X_1\rightarrow Z_1X_3, \\
& Z_0\rightarrow Z_1X_3,\ Z_1\rightarrow X_1X_2,\ Z_2\rightarrow X_aX_2 \}
\end{aligned}
\end{equation}

where all productions in $G_2$ follow conditions of a grammar in Chomsky Normal form.


% !TEX root = main.tex

%-------------------------------------------------
\section{Order statistics}\label{sec:orderstats}

% defn: quantile
\begin{definition}
Let $X$ be a continuous random variable and let $F(x)$ denote its CDF. For $p\in[0,1]$, the \emph{$p$th quantile} of the distribution is the value $x_p = F^{-1}(p)$, i.e.\ the value $x_p\in\R$ for which
\[
\prob(X\leq x_p) = p \qquad\text{for $p\in[0,1]$.}
\]
In particular,
\bit
\it $x_{0.5}$ is the \emph{median} of the distribution,
\it $x_{0.25}$ is the \emph{lower quartile},
\it $x_{0.75}$ is the \emph{upper quartile},
\it $x_{0.75}-x_{0.25}$ is the \emph{inter-quartile range}.
\eit
\end{definition}

% remark: location and scale
\begin{remark}
As we shall see, the median and inter-quartile range represent \emph{location} and \emph{scale} respectively.
\end{remark}

\begin{example}
Find the median and inter-quartile range of the $\text{Exponential}(\lambda)$ distribution, where $\lambda>0$ is a rate parameter.
\begin{solution}
Let $X\sim\text{Exponential}(\lambda)$. Then $F(x) = 1 - e^{-\lambda x}$, so
\[
x_p = F^{-1}(p) = -\frac{1}{\lambda}\log(1-p).
\]
Thus the median is $\log(2)/\lambda$ and the inter-quartile range is $\log(3)/\lambda$.
\end{solution}
\end{example}

%-----------------------------
\subsection{Order statistics}
The quantiles of a distribution can be estimated using the \emph{order statistics} of a random sample.

%\begin{definition}
%Let $X_1,X_2,\ldots,X_n$ be a random sample from an unknown distribution, let $X_{(1)}$ denote the smallest observation, let $X_{(2)}$ denote the second-smallest observation, and so on:
%\[
%X_{(1)} \leq X_{(2)} \leq \ldots \leq X_{(n)}.
%\]
%$X_{(1)},X_{(2)},\ldots,X_{(n)}$ are called the \emph{order statistics} of the random sample $X_1,X_2,\ldots,X_n$.
%\end{definition}

\begin{definition}
Let $X_1,X_2,\ldots,X_n$ be a random sample from an unknown distribution. The \emph{order statistic of rank $k$} is the $k$th smallest observation in the sample and denoted by $X_{(k)}$.
\end{definition}

Certain functions of the order statistics $X_{(1)},X_{(2)},\ldots,X_{(n)}$ are important statistics in their own right:
\bit
\it $X_{(1)}$ is the \emph{sample minimum}.
\it $X_{(n)}$ is the \emph{sample maximum}.
\it $X_{(n)} - X_{(1)}$ is the \emph{sample range}.
\it
The \emph{sample median} is $\begin{cases} X_{(n/2+1/2)} & \quad\text{if $n$ is odd,} \\[2ex] \frac{1}{2}\big[X_{(n/2)}+X_{(n/2+1)}\big] & \quad\text{if $n$ is even.} \end{cases}$
\it
The \emph{lower quartile} is the median of $X_{(1)},\ldots,X_{(n/2)}$ if $n$ is even or $X_{(1)},\ldots,X_{(n/2-1/2)}$ if $n$ is odd.
\it
The \emph{upper quartile} is the median of $X_{(n/2+1)},\ldots,X_{(n)}$ if $n$ is even or $X_{(n/2+3/2)},\ldots,X_{(n)}$ if $n$ is odd.
\eit

\begin{remark}
The \emph{five number summary} is a commonly used set of descriptive statistics consisting of the five most important sample quantiles:
\begin{center}
[ sample minimum, lower quartile, median, upper quartile, sample maximum ]
\end{center}
These are sometimes illustrated using \emph{box plots}.
\end{remark}

% thm: distribution of order statistic
The distribution of $X_{(k)}$ can be expressed in terms of the common CDF of the sample points.
\begin{theorem}
Let $X_1,X_2,\ldots,X_n$ be a random sample from an unknown distribution and let $F$ denote their common CDF. Then the CDF of the $k$th order statistic $X_{(k)}$ is
\[
\prob(X_{(k)}\leq x) = \prob(W\geq k) \quad\text{where}\quad W\sim\text{Binomial}\big(n,F(x)\big).
\]
\begin{proof}
By independence,
\begin{align*}
\prob(X_{(k)}\leq x)
	& = \prob(\text{at least $k$ observations are $\leq x$}) \\
	& = \prob\big(\text{at least $k$ successes in $n$ Bernoulli trials where P(success)$=F(x)$}\big) \\
	& = \prob(W\geq k) \quad\text{where}\quad W\sim\text{Binomial}\big(n,F(x)\big).
\end{align*}
\end{proof}
\end{theorem}

%-----------------------------
\subsection{Empirical distribution functions}

%%-------------------------------------------------
%\section{Empirical CDFs}

Let $X$ be a random variable whose distribution is unknown, and let $X_1,X_2,\ldots,X_n$ be a random sample from the distribution of $X$.
\begin{definition}\label{def:empirical_cdf}
The \emph{empirical cumulative distribution function} (ECDF) of $X$ is
\[
\hat{F}_X(x) = \frac{1}{n}\sum_{i=1}^n I(X_i\leq x)
\]
where $I(X_i\leq x)$ is the indicator variable of the event $\{\omega:X_i(\omega)\leq x\}$.
\end{definition}

In terms of order statistics, the ECDF can be written as
\[
\hat{F}_X(x) = \begin{cases}
	0	& \text{ for $x < X_{(1)}$,} \\
	i/n	& \text{ for $X_{(i)} < x \leq X_{(i+1)}$,} \\
	1	& \text{ for $x \geq X_{(n)}$.}
\end{cases}
\]

\begin{remark}
$\hat{F}_X(x)$ is the proportion of observations that are less than or equal to $x$. By the law of large numbers applied to the indicator variables $I(X_i\leq x)$,
\[
\hat{F}_X(x) \to \prob(X\leq x) \quad\text{in probability as the sample size $n\to\infty$ for all $x\in\R$.}
\]
\end{remark}

% remark: goodness of fit
\begin{remark}[Goodness-of-fit]
Let $F$ be an estimate for the CDF of $X$. We can quanify the so-called \emph{goodness of fit} using a number of test statistics based on the empirical $CDF$ of a random sample taken from the distribution of $X$, some of which are shown in Table~\ref{tab:gof}.

\begin{table}[ht]
\centering
\begin{tabular}{ll} \hline
%Test & Test statistic \\
\strut Kolmogorov-Smirnov &
%$\displaystyle T_n =
$\displaystyle \max|\hat{F}(x) - F(x)|$ \\[2ex]
Cramer-von~Mises &
%$\displaystyle T_n =
$\displaystyle \int_{-\infty}^{\infty} \big[\hat{F}(x) - F(x)\big]^2 f(x)\,dx$ \\[2ex]
Anderson-Darling &
%$\displaystyle T_n =
$\displaystyle \int_{-\infty}^{\infty} \frac{\big[\hat{F}(x) - F(x)\big]^2}{F(x)\big[1-F(x)]} f(x)\,dx$ \\[2ex] \hline
\end{tabular}
\caption{Test statistics for goodness-of-fit.\label{tab:gof}}
\end{table}
\end{remark}


\subsection{Diagonalization and Properties}

Diagonal matrix has entries not along the main diagonal be all 0. Example:

\[A=\begin{bmatrix}1&0&0\\0&3&0\\0&0&-1\\ \end{bmatrix}\]

Characteristic polynomial ends up being

\begin{align*}
    p_A(\lambda)&=\mbox{det}\begin{bmatrix}1-\lambda&0&0\\ 0&3-\lambda&0\\ 0&0&-1-\lambda\\ \end{bmatrix}\\
    p_A(\lambda)&=(1-\lambda)(3-\lambda)(-1-\lambda)
\end{align*}

\noindent
Matrix similar to diagonal matrix is \textbf{diagonalizable}. Thus, $A$ is diagonalizable if
there exists an invertible $S$ and diagonal matrix $D$ such that $\boxed{S^{-1}AS=D}$.
Because it is known that if $A\sim B$, $p_A(\lambda)=p_B(\lambda)$, whenever $A$ is diagonalizable, the
eigenvalues of $A$ will be diagonal entries of any diagonal matrix $A$ is similar to.

\noindent
Also note that for a diagonal matrix $D$, $D^t$ consists of all the diagonal entries $\lambda_1^t, \lambda_2^t\cdots, \lambda_n^t$:

\[D^t=\begin{bmatrix}
    \lambda_1^t&0&0&0\\
    0&\lambda_2^t&0&0\\
    0&0&\ddots&0\\
    0&0&0&\lambda_n^t\\
\end{bmatrix}\]

It then follows that if $S^{-1}AS=D$:

\begin{align*}
    S^{-1}AS&=D\\
    (S^{-1}AS)^t&=D^t\\
    (S^{-1}AS)(S^{-1}AS)(S^{-1}AS)\dots(S^{-1}AS)&=D^t\\
    S^{-1}A^tS&=D\\
    A^t&=SD^tS^{-1}\\
\end{align*}

\subsection{Diagonalization and Eigenbasis}

\textbf{A square matrix is diagonalizable if it has an eigenbasis.}

\noindent
Let the eigenbasis be $\mathfrak{E}=\left\{\tb v_1, \tb v_2, \tb v_3, \dots, \tb v_n\right\}$.
To show $A$ is diagonalizable, the $\mathfrak{E}$-matrix can be shown to be diagonal. First, let
$A$'s transformation be $T_A(\tb{x})=A\tb{x}$. The $\mathfrak{E}$-matrix is $D$. Thus, $\boxed{D[\tb x]_\mathfrak{E}=[T_A(\tb x)]_\mathfrak{E}}$.
The first column of $D$ is $[T_A(\tb{v}_1)]_\mathfrak{E}$. However, because $\mathfrak{E}$ is an eigenbasis for $A$,
it must hold true that:

\[A\tb v_1=T_A(\tb v_1)=\lambda_1 \tb v_1\]

\noindent
Thus, first column of $D$ is $[\lambda_1\tb{v}_1]_\mathfrak{E}$. Since $\lambda _1 \tb v_1=\lambda_1 \tb v_2+0\tb v_2+0\tb v_3+\dots+0\tb v_n$
as it is part of an eigenbasis, $[\lambda _1 \tb v_1]_\mathfrak{E}=\begin{bmatrix}\lambda_1\\0\\0\\ \vdots \\ 0 \end{bmatrix}$.
If repeated for all vectors in $\mathfrak{E}$, it ends up being that:

\[D=\begin{bmatrix}\lambda_1&0&0&0\\
    0&\lambda_2&0&0\\
    0&0&\ddots&0\\
    0&0&0&\lambda_n
\end{bmatrix}\]

It must also hold true that if $A$ is diagonalizable, it has an eigenbasis. It is known that:

\[S^{-1}AS=D=\begin{bmatrix}\lambda_1&0&0&0\\0&\lambda_2&0&0\\ 0&0&\ddots&0\\ 0&0&0&\lambda_n \end{bmatrix}\]

so a basis in $\R^n$ consisting of eigenvectors must be found. This is found in the columns of $S$, the change of basis matrix.
The similarity formula can be rearranged to get $AS=SD$. Thus, for the first column of $S$, $S\tb{e}_1$:

\begin{align*}
    A(S\tb e_1)&=(AS)\tb e_1\\
    &=(SD)\tb e_1\\
    &=S(D \tb e_1)\\
    &=S(\lambda_1 \tb e_1)\\
    &=\lambda_1 (S\tb e_1)\\
\end{align*}

\noindent
This is indeed a basis as $S$ is required to be invertible.


\subsection{Uncertainty of the slope of $T^2\ vs.\ M$}
The uncertainty of one period is $u_T/10=1\times10^{-5}s$ and the uncertainty of mass is
\[
\begin{split}
    M&=m_{objI}+\frac{1}{3}m_{spr1}+\frac{1}{3}m_{spr2}+m_i,\\
    u_M&=\sqrt{
     (\frac{\partial M}{\partial m_{objI}})^2(u_{m_{objI}})^2
    +(\frac{\partial M}{\partial m_{spr1}})^2(u_{m_{spr1}})^2
    +(\frac{\partial M}{\partial m_{spr2}})^2(u_{m_{spr2}})^2
    +(\frac{\partial M}{\partial m_i})^2(u_{m_i})^2
    }\\
    &=\sqrt{
     (1)^2(u_{m_{objI}})^2
    +(\frac{1}{3})^2(u_{m_{spr1}})^2
    +(\frac{1}{3})^2(u_{m_{spr2}})^2
    +(1)^2(u_{m_i})^2
    }
\end{split}
\]

As data provided
$m_{objI}=(176.87\pm0.01)\times10^{-3}kg$, $m_{spr1}=(11.23\pm0.01)\times10^{-3}kg$, $m_{spr2}=(10.54\pm0.01)\times10^{-3}kg$ and $m_1=(4.65\pm0.01)\times10^{-3}kg$

\[
\begin{split}
    u_M & = \sqrt{0.00001^2+0.00001^2/9+0.00001^2/9+0.00001^2}=0.0000153\\
        & = 1.5\times10^{-5}kg.
\end{split}
\]

For $T^2$,
$$   u_{T^2}=\sqrt{(2T)^2(u_T)^2}=2Tu_T$$

From the formula $T=2\pi\sqrt{\frac{M}{k}}$
we can drive the slope of $T^2\ vs.\ M$ is

$$	slope=\frac{T^2}{M}=\frac{4\pi^2}{k}$$

where k is the effective spring constant. In this experiment, the effective spring constant can be calculated by

$$  F =k_1\Delta x+k_2\Delta x  =k_{eff}\Delta x   $$

%NOTE: finish here

\[
\begin{split}
u_{slope} & = \sqrt{
	(\frac{\partial slope}{\partial slope_{hor}})^2\cdot(u_{slope_{hor}})^2
	+(\frac{\partial slope}{\partial slope_{inc1}})^2\cdot(u_{sloinc1})^2
	+(\frac{\partial slope}{\partial slope_{inc2}})^2\cdot(u_{slope_{inc2}})^2} \\
& = \sqrt{
	(\frac{1}{3})^2 \cdot (0.22)^2
	+(\frac{1}{3})^2 \cdot (0.05)^2
	+(\frac{1}{3})^2 \cdot (0.22)^2} = 0.18s^2/kg\\
\end{split}
\]

$$ u_{r,slope} = \frac{u_{slope}}{\bar{slope}} \times 100 \%
               =\frac{0.18}{8.37} \times 100 \% = 2.15\% $$

Comparing the calculated data with the experiment data,
$$   \Delta slope = 8.37 - 8.45 = -0.08 s^2/kg        				   $$
$$   \Delta_r slope = \frac{ 8.37 - 8.45}{8.45} \times 100\% = 0.95 \%  $$

For the deviation between theory calculation is not very large, it indicates that the experiment is quite success.

%NOTE: finish here

\subsection{Uncertainty in the $v_{\max}^2\ vs.\ A^2$ relation}

For analyzing the uncertainty of $\Delta x$,
First, investigate the uncertainty of $x_{in}$ and $x_{out}$.
The uncertainty of type-B of a calliper is

$$\Delta_{x,B} = \Delta{dev} = 0.02 \times 10^m   $$

Take the mean value of the three time measurements of the distance.
To determine type-A uncertainty, the standard deviation of the average value is

$$   s_{\overline{x_{in}}} = \sqrt{\frac{1}{n(n-1)}\sum_{i=1}^n(x_{in,i}-\overline{x_{in}})^2} $$
$$   s_{\overline{x_{in}}} = 5.3 \times 10^{-3} m 		$$

$$  u_{x_{in}}=\sqrt{\Delta_{x_{in},A}^2+\Delta_{x_{in},B}^2}
     = \sqrt{(0.02 \times 10^{-3} )^2
	 +(5.3 \times 10^{-3})^2}
	 = 5.3 \times 10^{-3} m $$
$$  u_{r,x_{in}}=\frac{u_{x_{in}}}{\overline{x_{in}}}\times 100\%=1.8\%$$

Similarly, we can calculate $x_{out}$ that
\[
\begin{split}
    &\Delta_{x_{out},A}=t_{0.95}\cdot s_{\overline{x_{out}}}=0.0287\times10^{-3}m\\
    &\Delta_{x,B}=0.02\times10^{-3}m\\
    &u_{x_{out}}=0.03\times10^{-3}m,\quad
    u_{r,x_{out}}=0.2 \%    \\
    &x_{out}=(15.41\pm 0.03) \times10^{-3}m,\quad u_{r,x_{out}}=0.2\%.
\end{split}
\]

Then we can calculate the propagated uncertainty of $\Delta x$

$$\frac{\partial\Delta x}{\partial x_{in}}=\frac{\partial\Delta x}{\partial x_{out}}=\frac{1}{2}  $$

\[
\begin{split}
    u_{\Delta x}&=\sqrt{(\frac{\partial\Delta x}{\partial x_{in}})^2(u_{x_{in}})^2
	+(\frac{\partial\Delta x}{\partial x_{out}})^2(u_{x_{out}})^2}\\
    &=0.04\times10^{-3}m,\\
\end{split}
\]

$$    u_{r,\Delta x}=\frac{u_{\Delta x}}{\Delta x}\times100\%=0.4\% $$
$$     \Delta x=(9.95\pm0.04)\times10^{-3}m,\quad u_{r,\Delta x}=0.4\%  $$

For the Uncertainty of the maximum speed $v_{\max}$
Then we can calculate the propagated uncertainty of $v_{\max}=\Delta x/\Delta t$. The partial derivatives are
\[
\begin{split}
    \frac{\partial v_{\max}}{\partial \Delta x}&=\frac{1}{\Delta t}.\\[0.5cm]
    \frac{\partial v_{\max}}{\partial \Delta t}&= - \frac{\Delta x}{(\Delta t)^2}.
\end{split}
\]

\[
\begin{split}
    u_{v_{\max}}&=\sqrt{(\frac{\partial v_{\max}}{\partial \Delta x})^2(u_{\Delta x})^2+(\frac{\partial v_{\max}}{\partial \Delta t})^2(u_{\Delta t})^2}     \\
    &=\sqrt{(\frac{1}{\Delta t})^2(u_{\Delta x})^2+(\frac{\Delta x}{(\Delta t)^2})^2(u_{\Delta t})^2}
\end{split}
\]


\chapter{Nonlinear system stability}

All material is sourced from Ref. \cite{hurtado2015}

\section{Linearization test}

If the linearized system's eigenvalues all satisfy $Re(\lambda_i) < 0$, then the nonlinear system is stable.

If the any eigenvalues of the linearized system have positive real part, the nonlinear system is unstable.

If any eigenvalue has zero real part, nothing about stability of the nonlinear system is concluded.

\section{Lyapunov's direct method}

Lyapunov's direct method provides a test for stability of a system $\dvec{x} = f(\vec{x},t)$ about an equilibrium point $\vec{x}^*$. A precondition for the test is the existence of function $V(\vec{x})$ having the following three properties: (1) $V(\vec{x}^*) = 0$; (2) $V(\vec{x}\neq \vec{x}^*) > 0, \vec{x}\in W$; (3) $\dot{V}(\vec{x}^*) = 0$.

If the Lyapunov function may satisfy the following additional conditions, proving certain stability properties:

\begin{itemize}
	\item $\dot{V}(\vec{x}\neq\vec{x}^*) \leq 0, \vec{x}\in W$ $\rightarrow$ the system is \textbf{locally stable} (or locally marginally stable).
	\item $\dot{V}(\vec{x}\neq\vec{x}^*) < 0, \vec{x}\in W$ $\rightarrow$ the system is \textbf{locally asymptotically stable} ($\vec{x} \in W$ tends to $\vec{x}^*$ as $t\rightarrow\infty$).
	\item $V(\vec{x})$ is radially unbounded AND $\dot{V}(\vec{x}) < 0 \ \forall \ \vec{x}\neq\vec{x}^*$ $\rightarrow$ the system is \textbf{globally asymptotically stable}.
	\item $\dot{V}(\vec{x}\neq\vec{x}^*) > 0, \vec{x}\in W$ $\rightarrow$ the system is \textbf{unstable}.
\end{itemize}

\section{Mukherjee and Chen's theorem}

Sometimes $\dot{V}(\vec{x}\neq\vec{x}^*) \leq 0$ when the system is truly asymptotically stable. An extended test exists provided that $\dot{V}(\vec{x}\neq\vec{x}^*) < 0 \ \forall \ \vec{x} \in Z \subset W$.
Motion is asymptotically stable provided that $V(\vec{x})$ is a Lyapunov function and the following are satisfied:

\begin{enumerate}
	\item $\dot{V}(\vec{x}\neq\vec{x}^*) < 0 \ \forall \ \vec{x} \in Z \subset W$
	\item $ \frac{d^i V}{dt^i} (\vec{x}) = 0 \ \forall \ \vec{x} \in Z, i = 2,\dots,k-1$
	\item $ \frac{d^k V}{dt^k} (\vec{x}^*) = 0$
	\item $ \frac{d^k V}{dt^k} (\vec{x}) < 0 \ \forall \ \vec{x} \in Z, k = \mathrm{odd}$
\end{enumerate}


\sec{Picard's Iterates}
\subsection{Introduction}
\begin{mdframed}[style=boxstyle, frametitle={The Setup}]
	Consider the initial value problem (IVP)
	\[y' = f(t, y); \;\; y(a) = b.\]
	Corresponding to this, we set up the following \emph{integral equation}
	\[\phi(t) = b + \int_{a}^{t} f(s, \phi(s)) ds.\]
	It can be verified a solution $\phi_0$ to the integral equation is a solution of the original DE as well. (And vice-versa.)\\
\end{mdframed}
Now, we describe a method to solve the integral equation.

\newpage

\begin{mdframed}[style=boxstyle, frametitle={Picard's Iteration Method}]
	We recursively define a family of functions $\phi_n(t)$ for every $n \ge 0$ as follows:
	\begin{align*}
		\phi_0 &\equiv b,\\
		\phi_{n + 1}(t) &= b + \int_{a}^{t} f(s, \phi_n(s)) ds \quad \text{for }n \ge 0.
	\end{align*}
\end{mdframed}
Under suitable conditions, the sequence of functions $\left(\phi_n\right)$ converges to a function
\[\phi(t) = \lim_{n\to \infty}\phi_n(t),\]
which is a solution to the IVP.

\exercise{%
Solve the IVP:
\[y'(t) = 2t(1 + y); \;\; y(0) = 0.\]
}