\section{Conclusion}\label{sec:conclusion}

We presented a tuning prescription for a two-particle lattice system interacting through a contact interaction in 1-, 2- and 3-dimensions.
For this interaction, the tuning prescription allows us to compute infinite volume continuum scattering observables %(which are independent from unphysical artifacts)
from data computed in the finite volume and discrete space.
Furthermore we derived a \Luscher-like formalism which directly converts the associated finite-volume finite-spacing spectra to infinite-volume continuum phase shifts for the contact interaction.

In 3-dimensions, we analyzed three different approaches in detail:
\begin{enumerate}
	\item we tuned the interaction parameter in a finite volume with a finite lattice spacing to the intersections of the \Luscher zeta function and the phase shifts, extracted the continuum-extrapolated spectrum, and used the same \Luscher zeta function to re-obtain the phase shifts,
	\item we repeated the same procedure without extrapolating the spectrum to the continuum and found phase shifts with induced energy-dependence,
	\item we derived a dispersion-aware zeta function which removed the energy dependence in the phase shifts,
	\item we perturbatively computed the discretization dependent coefficients which describe the difference in the effective range expansion between continuum extrapolated results and results obtained at a finite spacing.
\end{enumerate}

The first approach follows the logic of \Luscher's original work and reproduces the expected phase shifts.
Even though we had full control over numerical errors, the continuum extrapolation of the spectrum suffered from systematic artifacts and induced significant uncertainties (on a relative scale) when put through the zeta function.
In general the best discretization allows the best extrapolation and for smaller energy values, continuum results are more precise.
It is possible to find discretizations in which the finite spacing spectrum is close to its continuum result but the extrapolation uncertainties can be larger because of non-monotonic behavior of individual energy levels in dependence of the lattice spacing.

The second approach, applying the infinite-volume map to finite-spacing energy levels---the approach of most recent lattice QCD work---suffers in the case of the analyzed interaction from notable discretization artifacts.
These artifacts induce an energy dependence in the phase shifts at any finite spacing.
For example, we found induced effective range (and higher order) effects which we analytically estimated.
These induced terms can be extrapolated to zero in a stable manner in the continuum if one only considers energy values in the scaling region.
We provide tables of coefficients which estimate the size of errors in the phase shifts caused by the discretization.

The third approach allows a direct conversion from finite-spacing finite-volume energy levels to continuum infinite-volume phase shifts without any extrapolation.
Thus it was possible to consistently tune the interaction parameter to high precision.
Further, this tuning allows one to distinguish between kinetic discretization effects and discretization effects affecting the regulator of the theory and thus allows one to determine the interaction consistently.

Finally, we repeated our three-dimensional analysis above to both one- and two-dimensional systems.
The latter is further complicated by logarithmic singularities as opposed to power law divergences, and so here we proposed a slightly modified \Luscher equation in two dimensions to account for the logarithmic singularity near $p\sim 0$.
In both cases our results are consistent with those found in the literature.

We expect our discretization-specific tuning for the contact interaction parameter can be carried beyond the two-body sector and used in many-body computations, so that calculations of the Bertsch parameter should benefit from having a systematically correct tuned interaction, which we plan to investigate in future work.
We note, however, that while it would be desirable to find a similar dispersion formalism and tuning prescription for any interaction (for example, finite-range interactions), the derivation of this prescription in this case would depend on an explicit knowledge of the short-distance parts of the interaction.
We do not rule out, however, that our dispersion formalism might be applicable to other specific interactions, or maybe even generalizes in a perturbative manner for general interactions.  %, it seems unlikely to us that it generalizes to scenarios where the effective interaction between emergent objects is not explicitly known.

%I like coffee a lot.
%Without coffee, I would be tired each morning.
%Accounting for the tiredness overhead, I am certain that my productivity would be considerably smaller.
%Thus I think there should be free coffee for any scientist.
%Well, for any human (which is capable of properly digesting coffee) I guess.
%Cheers to coffee!


\section{Schrödinger problem for Landau levels in dressed 2DEG}

Our analysis start with considering 2 dimentional free electronic gas which has been distrubuted in confined $(x,y)$ plane in configuration space.
\begin{figure}[ht!]
  \centering
  \includegraphics[scale=0.9]{figures/fig0.pdf}
  \caption{Confined 2DEG in configuration space with the size of $A=L_xL_y$.}
  \label{fig:1.0}
\end{figure}

\noindent
We are going to examine the properties of 2DEG with stationary magnetic field
\begin{equation} \label{1.1}
  \vb{B} = (0,0,B)^T
\end{equation}
which directed on $z$ axis and a linearly $y$-polarized strong electomagnetic wave (dressing field) with electric field given by
\begin{equation} \label{1.2}
  \vb{E} = (0,E\sin(\omega t),0)^T
\end{equation}
which also propagate in $z$ direction. Here $B$ and $E$ represent the amplitude of the stationary magnetic field and electric field of dressing field.
\begin{figure}[ht!]
  \centering
  \includegraphics[scale=0.9]{figures/fig1.pdf}
  \caption{Stationary magnetic filed (blue color) and Strong EM wave (red color) applied to the 2DEG.}
  \label{fig:1.1}
\end{figure}

\noindent
Using Landau gauge for the stationary magnetic field we can represent it using vector potential as
\begin{equation} \label{1.3}
  \vb{A}_{s} = (-By,0,0)^T
\end{equation}
and choosing Coulomb gauge the dressing field can be present as the following vector potential
\begin{equation} \label{1.4}
  \vb{A}_{d}(t) = (0,[E/\omega ]\cos(\omega t),0)^T.
\end{equation}
Now the Hamiltonian of an electron in 2DEG can be reads as
\begin{equation} \label{1.5}
  \hat{H}_e(t) = \frac{1}{2m_e}\Big[\hat{\vb{p}} - e\big(\vb{A}_{s}+\vb{A}_{d}(t)\big)\Big]^2
\end{equation}
where $m_e$ is the effective mass of the electron and $e$ is the magnitude (without considering the sign of the charge) of the electron charge. This can be simplified to
\begin{equation} \label{1.6}
  \hat{H}_e(t) = \frac{1}{2m_e}\Big[
    (\hat{p}_x + eBy)\vb{e}_x +
    (\hat{p}_y - \frac{eE}{\omega}\cos(\omega t))\vb{e}_y
  \Big]^2
\end{equation}
where $\vb{e}_x$ and $\vb{e}_y$ are unit vectors along $x$ and $y$ directions respectively. Moreover,
\begin{equation} \label{1.7}
  \hat{H}_e(t) = \frac{1}{2m_e}\Big[
    (\hat{p}_x + eBy)^2 +
    (\hat{p}_y - \frac{eE}{\omega}\cos(\omega t))^2
  \Big]
\end{equation}
Since $[\hat{H}_e(t),\hat{p}_x] =0$ both operators share same (simultaneous) eigen functions which are free electron wave functions
($\frac{1}{\sqrt{L_x}}\exp(\frac{ip_x x}{\hbar})$).
Therefore we can modify the Hamiltonian as follows
\begin{equation} \label{1.8}
  \hat{H}_e(t) = \frac{1}{2m_e}\Big[
    ({p}_x + eBy)^2 +
    (\hat{p}_y - \frac{eE}{\omega}\cos(\omega t))^2
  \Big].
\end{equation}
Using momentum operator definition
\begin{equation} \label{1.9}
  \hat{p}_y = -i\hbar \pdv{y}
\end{equation}
we can modify Eq. \eqref{1.8} as
\begin{equation} \label{1.10}
  \begin{aligned}
    \hat{H}_e(t) & = \frac{1}{2m_e}\Big[
      ({p}_x + eBy)^2 +
      \Big(-i\hbar \pdv{y}- \frac{eE}{\omega}\cos(\omega t)\Big)^2
    \Big] \\
    & = \frac{1}{2m_e}\Big[
      ({p}_x + eBy)^2 +
      \Big(i\hbar \pdv{y} + \frac{eE}{\omega}\cos(\omega t)\Big)^2
    \Big].
  \end{aligned}
\end{equation}
Define the \textit{center of the cyclotron orbit} along $y$ axis as
\begin{equation} \label{1.11}
  y_0 \equiv \frac{-p_x}{eB}
\end{equation}
and the \textit{cyclotron frequency} as
\begin{equation} \label{1.12}
  \omega_0 \equiv \frac{eB}{m_e}.
\end{equation}
\begin{figure}[ht!]
  \centering
  \includegraphics[scale=0.9]{figures/fig02.pdf}
  \caption{Paramters of the cyclotron orbits in the classical interpretation.}
  \label{fig:1.02}
\end{figure}

\noindent
Then the Hamiltonian will leads to
\begin{equation} \label{1.13}
    \hat{H}_e(t) =
      \frac{m_e \omega_0^2}{2}(y-y_0)^2 +
      \frac{1}{2m_e}\Big(i\hbar \pdv{y}+\frac{eE}{\omega}\cos(\omega t)\Big)^2
\end{equation}
\begin{equation} \label{1.14}
  \begin{aligned}
    \hat{H}_e(t) =
      \frac{m_e \omega_0^2}{2}(y-y_0)^2 +
      \frac{1}{2m_e}\Big(
      -\hbar^2 \pdv[2]{y} & +
      i\hbar \pdv{y}\bigg[\frac{eE}{\omega}\cos(\omega t) \bigg] \\ & +
      \frac{i\hbar eE}{\omega}\cos(\omega t) \pdv{y}+
      \frac{e^2E^2}{\omega^2}\cos[2](\omega t)
      \Big)
  \end{aligned}
\end{equation}
\begin{equation} \label{1.15}
  \begin{aligned}
    \hat{H}_e(t) =
      \frac{m_e \omega_0^2}{2}(y-y_0)^2 +
      \frac{1}{2m_e}\Big(
      -\hbar^2 \pdv[2]{y} +
      \frac{2i\hbar eE}{\omega}\cos(\omega t) \pdv{y}+
      \frac{e^2E^2}{\omega^2}\cos[2](\omega t)
      \Big).
  \end{aligned}
\end{equation}
Let
\begin{equation} \label{1.16}
    \tilde{y} = (y - y_0) \longrightarrow dy = d\tilde{y}
\end{equation}
and then this becomes
\begin{equation} \label{1.17}
  \begin{aligned}
    \hat{H}_e(t) =
      \frac{m_e \omega_0^2}{2}\tilde{y}^2 +
      \frac{1}{2m_e}\Big(
      -\hbar^2 \pdv[2]{\tilde{y}} +
      \frac{2i\hbar eE}{\omega}\cos(\omega t) \pdv{\tilde{y}}+
      \frac{e^2E^2}{\omega^2}\cos[2](\omega t)
      \Big).
  \end{aligned}
\end{equation}
Now assume that the solution for the time-dependent schrödinger equation
\begin{equation} \label{1.18}
    i \hbar \dv{\psi}{t} = \hat{H}_e(t)\psi
\end{equation}
can be represent by the following form
\begin{equation} \label{1.19}
    \psi(\vb{r},t) = \frac{1}{\sqrt{L_x}} \exp\bigg(
      \frac{ip_x x}{\hbar} +
      \frac{ieE(y-y_0)}{\hbar \omega}\cos(\omega t)
    \bigg) \phi(y-y_0,t).
\end{equation}
Using the same subtution from Eq. \eqref{1.16} this becomes
\begin{equation} \label{1.20}
    \psi(x,\tilde{y},t) = \frac{1}{\sqrt{L_x}} \exp\bigg(
      \frac{ip_x x}{\hbar} +
      \frac{ieE\tilde{y}}{\hbar \omega}\cos(\omega t)
    \bigg) \phi(\tilde{y},t).
\end{equation}
Defining
\begin{equation} \label{1.21}
    \varphi(x,\tilde{y},t) \equiv \frac{1}{\sqrt{L_x}} \exp\bigg(
      \frac{ip_x x}{\hbar} +
      \frac{ieE\tilde{y}}{\hbar \omega}\cos(\omega t)
    \bigg)
\end{equation}
we can simply the the Eq. \eqref{1.20} as
\begin{equation} \label{1.22}
    \psi(x,\tilde{y},t) = \varphi(x,\tilde{y},t) \phi(\tilde{y},t).
\end{equation}
Let's subtitue Eq. \eqref{1.20} and Eq. \eqref{1.17} into Eq. \eqref{1.18} and we can observe that
\begin{equation} \label{1.23}
  \begin{aligned}
    \text{L.H.S} & = i \hbar \dv{\psi}{t} =
    i \hbar \bigg( \dv{\varphi}{t} \phi + \dv{\phi}{t} \varphi \bigg) =
    i \hbar \bigg(
      \Big[\frac{-ieE\tilde{y}}{\hbar}\sin(\omega t)\Big]\varphi\phi +
      \varphi  \dv{\phi}{t}
    \bigg) \\
    & =
    \big[{eE\tilde{y}}\sin(\omega t)\big]\varphi\phi +
    i \hbar\varphi  \dv{\phi}{t}
  \end{aligned}
\end{equation}
and
\begin{equation} \label{1.24}
  \begin{aligned}
    \text{R.H.S} & = \hat{H}_e(t)\psi \\
    & =
    \bigg[
    \frac{m_e \omega_0^2}{2}\tilde{y}^2 +
    \frac{1}{2m_e}\Big(
    -\hbar^2 \pdv[2]{\tilde{y}} +
    \frac{2i\hbar eE}{\omega}\cos(\omega t) \pdv{\tilde{y}}+
    \frac{e^2E^2}{\omega^2}\cos[2](\omega t)
    \Big) \bigg]
    \varphi\phi
  \end{aligned}
\end{equation}
where we will can calculate this part by part as follows:
\begin{equation} \label{1.25}
  \begin{aligned}
    \frac{-\hbar^2}{2m_e}\pdv[2]{\tilde{y}}(\varphi\phi) & =
    \frac{-\hbar^2}{2m_e} \pdv{\tilde{y}}\bigg[
      \Big(\frac{ieE}{\hbar \omega} \cos(\omega)t\Big)\varphi\phi +
      \varphi\pdv{\phi}{\tilde{y}}
    \bigg] \\
    & =
    \frac{-\hbar^2}{2m_e} \bigg[
      \Big(\frac{ieE}{\hbar \omega} \cos(\omega)t\Big)^2\varphi\phi +
      \Big(\frac{ieE}{\hbar \omega} \cos(\omega)t\Big)\varphi\pdv{\phi}{\tilde{y}} +
      \Big(\frac{ieE}{\hbar \omega} \cos(\omega)t\Big)\varphi\pdv{\phi}{\tilde{y}} +
      \varphi\pdv[2]{\phi}{\tilde{y}}
    \bigg] \\
    & =
    \Big(\frac{e^2E^2}{ 2m_e\omega^2} \cos[2](\omega)t\Big)\varphi\phi -
    \Big(\frac{ieE \hbar}{m_e\omega} \cos(\omega)t\Big)\varphi\pdv{\phi}{\tilde{y}} -
    \frac{\hbar^2}{2m_e}
    \varphi\pdv[2]{\phi}{\tilde{y}}
  \end{aligned}
\end{equation}
and
\begin{equation} \label{1.26}
  \begin{aligned}
    \frac{2i\hbar eE}{2m_e\omega}\cos(\omega t) \pdv{\tilde{y}} (\varphi\phi)& =
    \frac{i\hbar eE}{m_e\omega}\cos(\omega t)
    \bigg[
      \Big(\frac{ieE}{\hbar \omega} \cos(\omega)t\Big)\varphi\phi +
      \varphi\pdv{\phi}{\tilde{y}}
    \bigg] \\
    & =
    \Big(\frac{-e^2E^2}{m_e\omega^2} \cos(\omega)t\Big)\varphi\phi +
    \frac{i\hbar eE}{m_e\omega}\cos(\omega t)\varphi\pdv{\phi}{\tilde{y}}.
  \end{aligned}
\end{equation}
Therefore we can derive that
\begin{equation} \label{1.27}
  \begin{aligned}
    \text{R.H.S} =
    \bigg[
    \frac{m_e \omega_0^2}{2}\tilde{y}^2 \varphi\phi
    -
    \frac{\hbar^2}{2m_e}
    \varphi\pdv[2]{\phi}{\tilde{y}} \bigg].
  \end{aligned}
\end{equation}
To satisfy the condition L.H.S$=$R.H.S we need to find a function $\phi(\tilde{y},t)$ such that
\begin{equation} \label{1.28}
  \begin{aligned}
    \big[{eE\tilde{y}}\sin(\omega t)\big]\varphi\phi +
    i \hbar\varphi  \dv{\phi}{t}
    =
    \bigg[
    \frac{m_e \omega_0^2}{2}\tilde{y}^2 \varphi\phi
    -
    \frac{\hbar^2}{2m_e}
    \varphi\pdv[2]{\phi}{\tilde{y}} \bigg]
  \end{aligned}
\end{equation}
by removing $\varphi$ this can be simplyfied as
\begin{equation} \label{1.29}
  \begin{aligned}
    \bigg[
    \frac{m_e \omega_0^2}{2}\tilde{y}^2
    - {eE\tilde{y}}\sin(\omega t)
    -
    \frac{\hbar^2}{2m_e}
    \pdv[2]{\tilde{y}}
    - i \hbar \dv{t}
    \bigg]
    \phi(\tilde{y},t) = 0.
  \end{aligned}
\end{equation}
If we turn off the external dressing field, this equation leads to simple harmonic oscillator Hamiltonian as follows
\begin{equation} \label{1.30}
  \begin{aligned}
    \bigg[
    \frac{m_e \omega_0^2}{2}\tilde{y}^2
    -
    \frac{\hbar^2}{2m_e}
    \pdv[2]{\tilde{y}}
    - i \hbar \dv{t}
    \bigg]
    \phi(\tilde{y},t) = 0
  \end{aligned}
\end{equation}
\begin{equation} \label{1.31}
  \begin{aligned}
     i \hbar \dv{\phi(\tilde{y},t)}{t} =
    \bigg[
    \frac{\hat{p}_{\tilde{y}}^2}{2m_e} +
    \frac{1}{2}m_e \omega_0^2\tilde{y}^2
    \bigg]
    \phi(\tilde{y},t).
  \end{aligned}
\end{equation}
Therefore we can identify the $S(t) \equiv eE\sin(\omega t)$ part as a external force act on the harmonic oscillator and we can solve this as a forced harmonic oscillator in $\tilde{y}$ axis.
\begin{equation} \label{1.32}
  \begin{aligned}
    i \hbar \dv{\phi(\tilde{y},t)}{t} =
    \bigg[
    -
    \frac{\hbar^2}{2m_e}
    \pdv[2]{\tilde{y}} +
    \frac{1}{2}m_e \omega_0^2\tilde{y}^2
    - \tilde{y}S(t)]
    \bigg]
    \phi(\tilde{y},t).
  \end{aligned}
\end{equation}
This system can be extacly solvable and we can solve this equation using the methods explained by Husimi [*Ref:1] as follows.

\noindent
First we can introduce the time dependent shifted corrdinte as
\begin{equation} \label{1.33}
    \tilde{y} \rightarrow y' = \tilde{y} - \zeta(t) \quad \Rightarrow \quad
    \tilde{y} = y' + \zeta(t)
\end{equation}
and this implies that
\begin{equation} \label{1.34}
    \dv{\phi(y',t)}{t} = \pdv{\phi(y',t)}{t} + \pdv{\phi(y',t)}{y'}\pdv{y'}{t} =
    \pdv{\phi(y',t)}{t} - \dot{\zeta}(t)\pdv{\phi(y',t)}{y'}
\end{equation}
where $\dot{\zeta}(t) = \pdv{\zeta(t)}{t}$.
Therefore, Eq. \eqref{1.32} will be modified to
\begin{equation} \label{1.35}
  \begin{aligned}
    i \hbar \pdv{\phi(y',t)}{t}  =
    \bigg[
    i \hbar\dot{\zeta}\pdv{y'}
    -
    \frac{\hbar^2}{2m_e}
    \pdv[2]{{y'}} +
    \frac{1}{2}m_e \omega_0^2(y' + \zeta)^2
    - (y' + \zeta) S(t)
    \bigg]
    \phi(y',t).
  \end{aligned}
\end{equation}
Let's tranform the wave function using following unitary trasnform
\begin{equation} \label{1.36}
    \phi(y',t) = \exp(\frac{im_e\dot{\zeta}y'}{\hbar})\varphi(y',t)
\end{equation}
and subtitte this into the Eq. \eqref{1.35} and we will get the following
\begin{equation} \label{1.37}
  \text{L.H.S} =  \bigg[ i \hbar \pdv{t} -
i \hbar \Big(\frac{im_e \ddot{\zeta} y'}{\hbar}\Big)\bigg]  \exp(\frac{-im_e\dot{\zeta}y'}{\hbar})\varphi(y',t)
\end{equation}
and
\begin{equation} \label{1.38}
  \begin{aligned}
    \text{R.H.S} & =  \bigg[
      i \hbar \dot{\zeta}  \Big(\frac{im_e \dot{\zeta}}{\hbar}\Big)  +
      i \hbar \dot{\zeta} \pdv{y'} \\
      &
      -
      \frac{\hbar^2}{2m_e}\Big[
        \Big(\frac{im_e \dot{\zeta}}{\hbar}\Big)^2
        + \Big(\frac{2im_e \dot{\zeta}}{\hbar}\Big) \pdv{{y'}}
        + \pdv[2]{{y'}}
      \Big] \\
      &
      +\frac{1}{2}m_e\omega_0^2 {y'}^2 + \frac{1}{2}m_e\omega_0^2 \zeta^2 +
      m_e\omega_0^2 y'\zeta \\
      & -
      y'S(t) - \zeta S(t)
    \bigg]  \exp(\frac{-im_e\dot{\zeta}y'}{\hbar})\varphi(y',t).
  \end{aligned}
\end{equation}
Combining these two and removing exponential terms we can derive that
\begin{equation} \label{1.39}
  \begin{aligned}
    i \hbar \pdv{\varphi(y',t)}{t}   =
    \bigg[
        -  \frac{\hbar^2}{2m_e}\pdv[2]{{y'}}
        & + \frac{1}{2} m_e \omega_0^2 y'^2 +
        \Big[
            m_e\ddot{\zeta} + m_e\omega_0^2\zeta - S(t)
        \Big]y' \\
        &
        +
        \Big[
            - \frac{1}{2} m_e\dot{\zeta}^2 + \frac{1}{2}m_e\omega_0^2 \zeta^2 - \zeta S(t)
        \Big]
    \bigg]\varphi(y',t).
  \end{aligned}
\end{equation}
Then we can restrict our $\zeta(t)$ function such that
\begin{equation} \label{1.40}
  m_e\ddot{\zeta} + m_e\omega_0^2\zeta = S(t)
\end{equation}
and that leads to
\begin{equation} \label{1.41}
  \begin{aligned}
    i \hbar \pdv{\varphi(y',t)}{t}   =
    \bigg[
        -  \frac{\hbar^2}{2m_e}\pdv[2]{{y'}}
        + \frac{1}{2} m_e \omega_0^2 {y'}^2
        - L(\zeta,\dot{\zeta},t)
    \bigg]\varphi(y',t)
  \end{aligned}
\end{equation}
where
\begin{equation} \label{1.42}
  L(\zeta,\dot{\zeta},t) \equiv \frac{1}{2} m_e\dot{\zeta}^2 - \frac{1}{2}m_e\omega_0^2 \zeta^2 + \zeta S(t)
\end{equation}
is the largrangian of a classical driven oscillator.

\vspace{5mm}
\noindent
Now introduce new unitary transormation for the wavefunction as follows
\begin{equation} \label{1.43}
    \varphi(y',t) = \exp(\frac{i}{\hbar}\int_0^{t}dt'L(\zeta,\dot{\zeta},t')) \chi(y',t)
\end{equation}
and subtite this into the Eq. \eqref{1.41} and gets
\begin{equation} \label{1.44}
  \begin{aligned}
    i \hbar \bigg[
      & \exp(\frac{i}{\hbar}\int_0^{t}dt'L(\zeta,\dot{\zeta},t')) \pdv{t}
      +
      i \hbar L(\zeta,\dot{\zeta},t) \exp(\frac{i}{\hbar}\int_0^{t}dt'L(\zeta,\dot{\zeta},t'))
    \bigg]\chi(y',t) \\
    & =
    \bigg[
        -  \frac{\hbar^2}{2m_e}\pdv[2]{{y'}}
        + \frac{1}{2} m_e \omega_0^2 {y'}^2
        - L(\zeta,\dot{\zeta},t)
    \bigg] \exp(\frac{i}{\hbar}\int_0^{t}dt'L(\zeta,\dot{\zeta},t')) \chi(y',t)
  \end{aligned}
\end{equation}
removing exponential terms finally we can derive that
\begin{equation} \label{1.45}
  \begin{aligned}
    i \hbar \pdv{t} \chi(y',t)  =
    \bigg[
        -  \frac{\hbar^2}{2m_e}\pdv[2]{{y'}}
        + \frac{1}{2} m_e \omega_0^2 {y'}^2
    \bigg] \chi(y',t).
  \end{aligned}
\end{equation}
This is the well known Schrodinger equation of a stationary quantum harmonic oscillator.
In terms of the eigenvalues
\begin{equation} \label{1.46}
  E_n = \hbar \omega_0 \big(n + \frac{1}{2}\big)
\end{equation}
of well-known harmonic eigenfucntions (using Gauss-Hermite functions $\vartheta$)
\begin{equation} \label{1.47}
  \chi_n(x) \equiv
  \sqrt{\kappa} \vartheta(\kappa x) \quad \text{where}
  \quad
  \vartheta(x) =
   \frac{1}{\sqrt{2^{n}n!}}
  e^{-x^2/2}
  \mathcal{H}_n \qty(x) \quad \text{with}
  \quad
  \kappa = \sqrt{\frac{m_e \omega_0}{\hbar}}
\end{equation}
being propositional to the Hermite functions $\mathcal{H}_n$, the solutions of Eq. \eqref{1.32} can be represent as
\begin{equation} \label{1.48}
  \phi_n(\tilde{y},t) = \chi_n(\tilde{y} - \zeta(t))
  \exp(\frac{i}{\hbar}\bigg[- E_nt +
  m_e\dot{\zeta(t)}\big(\tilde{y}-\zeta(t)\big)
   + \int_0^{t}dt'L(\zeta,\dot{\zeta},t')\bigg])
\end{equation}
The set $\{\chi_n(x)\}$ forms a complete set and thus any general solution $\phi_(\tilde{y},t)$ can be expaned in terms of the solutions in Eq. \eqref{1.48}.

\vspace{5mm}
\noindent
Next we consider special case where we assumed
\begin{equation} \label{1.49}
  S(t) = eE\sin(\omega t)
\end{equation}
and one can derive the Eq. \eqref{1.40} for $\zeta(t)$
\begin{equation} \label{1.50}
  m_e\ddot{\zeta} + m_e\omega_0^2\zeta = eE\sin(\omega t)
\end{equation}
and using Green function method the solution can be write as
\begin{equation} \label{1.51}
  \zeta(t) = \frac{eE}{m_e(\omega_0^2 - \omega^2)}\sin(\omega t).
\end{equation}
form this solutions we are able to derive the final solutions $\alpha=(n,m)$ where $n \in \mathbb{Z}^{+}_0 and m \in \mathbb{Z} $ are two quantum numbers that describe the state of the electron, can be present as
\begin{equation} \label{1.52}
  \begin{aligned}
    \psi_{\alpha}(x,\tilde{y},t)  = & \frac{1}{\sqrt{L_x}} \chi_n\big(\tilde{y} - \zeta(t)\big) \\
    & \times
      \exp(
     \frac{i}{\hbar}\bigg[- E_nt +
    p_x x +
    \frac{eE\tilde{y}}{\omega}\cos(\omega t)+
    m_e\dot{\zeta(t)}\big[\tilde{y}-\zeta(t)\big]
     + \int_0^{t}dt'L(\zeta,\dot{\zeta},t')\bigg])
  \end{aligned}
\end{equation}
and the exponential phase shifts represent the effect done by the stationary magnetic field and strong dressing field. In here $p_x$ is qunatized with the quantum number $m$ due to the spacial confinemnet in $x$ direction.
\begin{equation} \label{1.53}
  p_x = m\frac{2\pi \hbar}{L_x} \quad , \quad m = 0,\pm1,\pm2,...
\end{equation}
Therefore we can assume that the magnetitranport properties of 2DEG will be renormalized by the magnetic field as well as the dressing field.
\hfill$\blacksquare$


\chapter{Basics}

Little-$o()$ notation is used to denote that some expression is small relative to some other value.

\begin{marginfigure}
\includegraphics[width=0.75\linewidth]{graphics/basics1.pdf}
\caption[$(1 + h )^3 = 1 + 3 h + o(h)$ as $h \rightarrow 0$.]{$(1 + h )^3 = 1 + 3 h + o(h)$ as $h \rightarrow 0$.  Notice how the curves are {\em tangent} (touch and align) at $h=0$.}
\label{fig:basics1}
\end{marginfigure}
For example, if we say:
\begin{equation*}
(1 + h)^3 = 1 + 3 h + o(h)\text{\ as\ }h \rightarrow 0\,.
\end{equation*}
We mean that, as the magnitude of $h$ gets smaller, the magnitude of the difference between the left-hand side  $L = (1 + h )^3$ and the  right-hand side $R = 1 + 3 h$  is so small that, even when divided by $h$,  it is still small.

We can check this ratio empirically:
\begin{table}
\caption{$(1 + h )^3 = 1 + 3 h + o(h)$ as $h \rightarrow 0$.}
\label{tab:basic1}
\begin{tabular}{|S[table-format=2.3]|S[table-format=2.9]|S[table-format=2.3]|S[table-format=2.11]|S[table-format=2.6]|}
\multicolumn{1}{c}{$h$} &
\multicolumn{1}{c}{$L=(1+h)^3$} &
\multicolumn{1}{c}{$R=1+3h$} &
\multicolumn{1}{c}{$E=L-R$} &
\multicolumn{1}{c}{$r=\left|\frac{E}{h}\right|$} \\
\hline
0.1  & 1.331 & 1.3 & 0.031 & 0.31 \\
\hline
-0.01 & 0.970299 & 0.97 & 0.000299 & 0.0299 \\
\hline
0.001 & 1.003003001 & 1.003 & 0.00000030001 & 0.003001 \\
\hline
\end{tabular}
\end{table}

Notice how the ratio  $r=|E/h|$ shrinks as the magnitude of $h$ shrinks.  When we say an expression  $E$  is $o(h)$ as  $h \rightarrow 0$,  we mean the magnitude of $|E/h|$  gets small as the magnitude of $h$ gets small.

Graphically, smooth expressions that differ by $o(h)$ are {\em tangent} (touch and align) at $h=0$.  This is illustrated for this example in figure~\ref{fig:basics1}.

\begin{marginfigure}
\includegraphics[width=0.75\linewidth]{graphics/basics2.pdf}
\caption{$2k^3+5k^2-7k+3=2k^3+o(k^3)$ as $k \rightarrow \infty$.  Note how similar the curves are for large magnitude $k$.}
\label{fig:basics2}
\end{marginfigure}
\begin{marginfigure}
\includegraphics[width=0.75\linewidth]{graphics/basics3.pdf}
\caption{$2k^3+5k^2-7k+3=2k^3+o(k^3)$ as $k \rightarrow \infty$.  Note how dissimilar the curves are for small magnitude $k$.}
\label{fig:basics3}
\end{marginfigure}
The  $o()$  notation allows for more general expressions for the relative comparison of smallness,  such as  $o(h^2)$ or  $o(h \ln(h))$. In each case, we are saying that the expression in question is small in magnitude when divided by the expression in the $o()$  as the parameter ($h$ in this case) gets small in magnitude.

The notation works for large parameters as well.  For example:
\begin{equation}
2k^3 + 5 k^2 - 7 k + 3 = 2k^3 + o (k^3 )\text{\ as\ }k \rightarrow \infty \,.
\end{equation}
This means, as the magnitude of  $k$ gets larger and larger, the cubic polynomial on the left is approximately the leading order term (term with the highest power of  $k$) plus an error small relative to the size of that term.   Comparing figure~\ref{fig:basics2} and figure~\ref{fig:basics3} illustrates this trend, and table~\ref{tab:basics2} gives example values as $k \rightarrow \infty$.

\begin{table}
\caption[$2k^3 + 5 k^2 - 7 k + 3=2k^3+o(k^3)$]{$2k^3 + 5 k^2 - 7 k + 3=2k^3+o(k^3)$.  Notice how the error $E$ grows, but it is still small when compared to $\varepsilon(k) = k^3$.}
\label{tab:basics2}
\begin{tabular}{|S[table-format=4]|S[table-format=10]|S[table-format=10]|S[table-format=7]|S[table-format=10]|S[table-format=1.5]|}
\multicolumn{6}{c}{\vspace{2em}} \\
\multicolumn{1}{l}{$k$} &
\multicolumn{1}{l}{$\begin{array}{c}L=2k^3+ 5 k^2 \\ - 7 k + 3\end{array}$} &\multicolumn{1}{l}{$R=2k^3$} &
\multicolumn{1}{l}{$E=L-R$} &
\multicolumn{1}{l}{$\varepsilon(k)=k^3$} &
\multicolumn{1}{l}{$r=\left|\frac{E}{\varepsilon(k)}\right| $} \\
\hline
10  & 2433 & 2000 & 433 & 1000 & 0.43300 \\
-100 & -1949297 &  -2000000 & 50703 & -1000000 & 0.05070 \\
1000 & 2004993003 & 2000000000 & 4993003 & 1000000000 & 0.00499 \\
\hline
\end{tabular}
\end{table}

\section{Euler's constant, $e$.}
Euler's constant $e \approx \num{2.718281828459045}$ is fundamental for exponents and logarithms, just as  $\pi \approx \num{3.141592653589793} $ is fundamental in trigonometry.

The value $e$ can be thought of as the value of the expression $(1 + h)^{1/h}$ as $h \rightarrow 0$.  In $o()$ notation\footnote{Writing $1$ as  $h^0$ in $o(h^0)$ may seem surprising, but it is a way of noting what parameter is getting small.}:

\begin{equation}
(1 + h)^{1/h}=e+o(h^0)\text{\ as\ } h \rightarrow 0\,.
\end{equation}

This means, as the magnitude of  $h$ gets smaller and smaller, the expression on the left is approximately $e$, plus an error small relative to $h^0=1$.  Figure~\ref{fig:e} and table~\ref{tab:e} demonstrate this.  Notice $(1 + h )^{1/h}$ is not defined for $h=0$, but we only care about small {\em nonzero} values of $h$.

Curves that differ by $o(h^0)$ need only try to touch at $h=0$ (unlike $o(h)$ errors, where they need to be tangent).

\begin{table}
\caption{$(1 + h )^{1/h}=e+o(h^0)$.}
\label{tab:e}
\begin{tabular}{|S[table-format=2.6]|S[table-format=2.9]|S[table-format=1.8]|}
\multicolumn{1}{c}{$h$} &
\multicolumn{1}{c}{$(1+h)^{1/h}$} &
\multicolumn{1}{c}{$r=\left|\frac{(1+h)^{1/h}-e}{1}\right| $} \\
\hline
0.01 & 2.704813829 & 0.0135 \\
-0.0001 & 2.718417755 & 0.000136 \\
0.000001 & 2.718280469 & 0.00000136 \\
\hline
\end{tabular}
\end{table}
\vspace{4em}
\begin{marginfigure}
\includegraphics{graphics/e.pdf}
\caption[$(1 + h )^{1/h}=e+o(h^0)$]{$(1 + h )^{1/h}=e+o(h^0)$.  Notice the curves only try to touch (instead of be tangent) at $h=0$.}
\label{fig:e}
\end{marginfigure}

\section{Sine.}
As $h \rightarrow 0$,  $\sin(x+h)=\sin(x)+\cos(x)h + o(h)$.
\begin{marginfigure}
\includegraphics{graphics/sine.pdf}
\caption{$\sin(x+h)=\sin(x)+\cos(x) h+o(h)$ for $x=1$ and $\pi$.}
\label{fig:sine}
\end{marginfigure}

We will show this is true later, but, geometrically, it means that evaluating  $y=\sin(x)$ near $x$ is approximately a line\footnote{A line going through the point $(x_0,y_0)$ with slope $m$ is $y=y_0+m \cdot (x-x_0)$.} going through the point  $(x,\sin(x))$ with slope  $\cos(x)$.

\begin{figure}
\includegraphics{graphics/calc.pdf}
\caption[Differential calculus.]{Differential calculus in a nutshell: often, the value of $f(x)$ near $x$ is approximately a line: $f(x+h)=f(x)+f'(x)h+o(h)\,$.}
\label{fig:calc}
\end{figure}
{\em This last example is really important.}  The idea that, near a given point  $x$,  many functions are well approximated by a line is a foundational idea of differential calculus.  We call such a function differentiable at $x$, and the slope of its tangent line  $f'(x)$, so that $f(x+h)=f(x)+f'(x)h+o(h)$.  For the example of figure~\ref{fig:sine}, we are saying that, if $f(x) = \sin(x)$, then  $f'(x)=\cos(x)$.

\marginnote{Always writing ``as  $h \rightarrow 0$'' is tedious.  It will be clear from the $o()$ notation which parameter we consider large or small.}

In general, $o(h^0)$ approximations touch at $h=0$, $o(h^1)$ approximations have the same tangent (best fitting line), and $o(h^2)$ approximations have the same curvature (best fitting circle).  Figure~\ref{fig:rates} illustrates this with approximations of $e^h$.
\begin{figure}
\begin{center}
\includegraphics[width=4in]{graphics/rates.pdf}
\end{center}
\caption[Comparing $o(h^p)$]{Three progressively better approximations of $e^h$ as $h \rightarrow 0$:

$e^h=1+o(h^0)$,

$e^h=1+h+o(h^1)$, and

$e^h=1+h+\frac{h^2}{2}+o(h^2)$.

Notice the $o(h^0)=o(1)$ approximation touches, the $o(h^1)=o(h)$ approximation is tangent (best fitting line), and the $o(h^2)$ approximation has the same curvature (best fitting circle) at $h=0$.}
\label{fig:rates}
\end{figure}

\section{Formalities}
\begin{figure}
\begin{center}
\includegraphics[width=4in]{graphics/littleo.png}
\end{center}
\caption[$o()$ sketch.]{Sketch of the meaning of $o()$.  Redraw this in your notes so you remember the definition of little-$o()$.}
\label{fig:littleo}
\end{figure}

An expression $E$ is  $o(\varepsilon(h))$ as $h \rightarrow 0$ when the ratio $r = \left| \frac{E}{\varepsilon(h)} \right|$ is smaller than any positive bound $r_b$, provided we force the magnitude of $h$ to be small enough (but not zero).

Specifically\footnote{If you are familiar with limit notation, $E$ is  $o(\varepsilon(h))$ as $h \rightarrow 0$ means $\lim_{h\rightarrow 0} \left|\frac{E}{\varepsilon(h)}\right| = 0$.} $E$ is  $o(\varepsilon(h))$ if, and only if, for any bound $r_b>0$, there exists a bound $h_b>0$, so that $r=|E/\varepsilon(h)|<r_b$ whenever $0 < |h| < h_b$.

We define\footnote{If you are familiar with limit notation, $E$ is  $o(\varepsilon(k))$ as $k \rightarrow \infty$ means $\lim_{k\rightarrow \infty} \left|\frac{E}{\varepsilon(k)}\right| = 0$.} large $k$ in terms of small $h$ by saying $E$ is $o(\varepsilon(k))$ as $k \rightarrow \infty$ means $E$ is $o(\varepsilon(1/h)$ as $h \rightarrow 0$.  In other words, for any bound $r_b>0$, there exists a bound $k_b>0$, so that $r=|E/\varepsilon(h)|<r_b$ whenever $|k|>k_b$.

Note that we divide $E$ by $\varepsilon(h)$ to get $r$  in the above definition for some range of nonzero values of $h$. So, for any expression to be $o(\varepsilon(h))$,  $\varepsilon(h)$  must be defined and nonzero for some range of nonzero values of $h$.  We therefore restrict $\varepsilon(h)$ to such admissible functions:

\begin{quote}
For $\varepsilon(h)$ to be admissible in $o(\varepsilon(h))$ notation, there must exist some  $h_0 > 0$ so that $\varepsilon(h)$ is defined (finite) and nonzero for  $0 < |h| < h_0$.  This way we can form the ratio $r=|E/\varepsilon(h)|$ without dividing by zero for at least some range of $h$.
\end{quote}

We only use admissible $\varepsilon(h)$ in these notes.  In particular, $\varepsilon(h) = {|h|}^p$  is admissible for any value of  $p$ , and $\varepsilon(h) = h^p$ is admissible for any integer value of $p$.

\section{Summary}
\begin{itemize}
\item
Little-$o()$ notation is a way of describing an expression as small in comparison to some other value:
\begin{quote}
  $E$ is $o(\varepsilon(h))$ as $h \rightarrow 0$ means the ratio  $r = |E/\varepsilon(h)|$  can be made as small as desired provided the magnitude of $h$ is small enough (but not zero).
\end{quote}

\item
Graphically, expressions that differ by $o(h^0)$ need to touch at $h=0$, but expressions that differ by $o(h^1)$ also need to be tangent at $h=0$.

\item
Specifically,  $E$ is $o(\varepsilon(h))$  as $h \rightarrow 0$  means:
\begin{quote}
For any  $r_b > 0$,  there exists $h_b > 0$,  so that:
\begin{equation*}
\text{if\ } 0 < | h | < h_b\,,\text{\ then\ }r=\left|\frac{E}{\varepsilon(h)}\right|<r_b\,.
\end{equation*}
\end{quote}

\item
$E$ is $o(\varepsilon(k))$ as $k \rightarrow \infty$ means
\begin{quote}
$E$ is $o(\varepsilon(1/h)$ as $h \rightarrow 0$.
\end{quote}
or
\begin{quote}
For any  $r_b > 0$,  there exists $k_b > 0$,  so that:
\begin{equation*}
\text{if\ } |k| > k_b\,,\text{\ then\ }r=\left|\frac{E}{\varepsilon(h)}\right|<r_b\,.
\end{equation*}
\end{quote}

\item
For differentiable functions, the value $f(x+h)$ near a given point $x$ is well  approximated by a line called the tangent line of $y=f(x)$  at $x$ with slope $f'(x)$.

\item ${(1+h)}^{(1/h)} = e + o(h^0)$ as $h \rightarrow 0$,  where  $e \approx 2.718$ is Euler's constant.

\item Because an expression $E$ is divided by $\varepsilon(h)$ in the definition of $o(\varepsilon(h))$, $\varepsilon(h)$  is admissible in $o(\varepsilon(h))$ notation only if it is defined and nonzero for small enough nonzero $h$.
\begin{quote}
For $\varepsilon(h)$ to be admissible in $o(\varepsilon(h))$, there must exist $h_0 > 0$ so that $\varepsilon(h)$ is defined (finite) and nonzero for $0 < | h | < h_0$.
\end{quote}

\item We only use admissible $\varepsilon(h)$ in these notes.  In particular,  $\varepsilon(h) = {|h|}^p$ is admissible for any value of $p$,  and $\varepsilon(h) = h^p$ is admissible for any integer value of $p$.
\end{itemize}

\begin{figure}
\begin{center}
\includegraphics[width=4in]{graphics/model_rail.png}
\end{center}
\caption[xkcd 878: model rail]{\url{http://xkcd.com/878}  Math is not limited by physics, however.}
\label{fig:xkcd878}
\end{figure}


\chapter*{Add Noise Plugin}
\setcounter{chapter}{1}
\emph{Add some noise}
\section{Introduction}
The purpose of the \emph{AddNoise} plugin is to introduce random noise to \emph{Tellurium} data.

Noise generation uses the fact that a Rayleigh-distributed random variable $R$, with
the probability distribution $F(R) = 0$ if $R < 0$ and $F(R) = 1 - exp(-R^2/2*\sigma^2)$ if $R >= 0, $
is related to a pair of Gaussian variables $C$ and $D$ through the transformation $C = R * cos(\theta)$ and
$D = R * sin(\theta)$, where $\theta$ is a uniformly distributed variable
in the interval $(0, 2*\pi())$ \footnote{From Contemporary Communication Systems
USING MATLAB(R), by John G. Proakis and Masoud Salehi, published by
PWS Publishing Company, 1998, pp 49-50.}

Currently only Gaussian noise is implemented.

\section{Plugin Parameters}
Table \ref{table:AddNoisePluginParameters} lists available plugin property names, along with their data type and purpose.

\begin{table}[ht]
\centering % used for centering table
\begin{tabular}{l l p{7.5cm}} % centered columns (4 columns)

Parameter Name & Data Type & Purpose \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
InputData         		& 	TelluriumData & Data on which noise will be applied to. \\
Sigma,($\sigma$)      	& 	double & Size of applied noise. Noise is generated for each single data value, with a probability corresponding to a Gaussian distribution, centered around the value, and with a variance equal to $\sigma^2$ .\\
NoiseType      	& 	int    & Type of noise applied on data. Only Gaussian noise is currently supported. \\
Progress     	& 	double  & The progress property communicates the progress (in percent) of Noise application. \\

\hline %inserts single line
\end{tabular}
\caption{Add noise Plugin Parameters}
\label{table:AddNoisePluginParameters}
\end{table}

\section{Plugin Events}
The AddNoiseplugin uses all of the available plugin events, i.e. the \emph{PluginStarted}, \emph{PluginProgress} and the \emph{PluginFinished} events.

The available data variables for each event are internally treated as \emph{pass trough} variables, so any data, for any of the events, assigned prior to
the plugin's execute function (in the assignOn() family of functions), can be retrieved \emph{unmodified} in the corresponding event function.
\begin{table}[ht]
\centering % used for centering table
\begin{tabular}{l l p{7.5cm}} % centered columns (4 columns)

Event & Arguments & Purpose \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
\hline % inserts single horizontal line
PluginStarted  	& 	void*, void*  & Signals to application that the plugin has started applying noise on data. Both parameters are \emph{pass through} parameters and are unused internally by the plugin.\\[0.5ex]
PluginProgress	& 	void*, void*  & Communicates progress of noise generation. Both parameters are \emph{pass through} parameters and are unused internally by the plugin. \\[0.5ex]
PluginFinished	& 	void*, void*  & Signals to application that execution of the plugin has finished. Both parameters are \emph{pass through} parameters and are unused internally by the plugin.\\

\hline %inserts single line
\end{tabular}
\caption{AddNoise Plugin Events}
\label{table:AddNoisePluginEvents}
\end{table}

\section{The \texttt{execute(bool inThread)} function}
The \verb|execute()| function will apply noise to all rows and columns of the assigned data, with one exception. Data not affected are data in the first column, and if, and only if, its column header equals "time" (case insensitive).

The \verb|execute(bool inThread)| method supports a boolean argument indicating if the execution of the plugin work will be done in a thread, or not. Threading is fully implemented in the AddNoise plugin.

The inThread argument defaults to \textbf{false}.

\section{Python examples}

\subsection{Add noise to data acquired from RoadRunner}
The python script below shows how to acquire simulation data from RoadRunner and pass it to the noise plugin. The format of this data, which is obtained from the \verb|simulate()| function (line 8), is not directly compatible with the Noise plugin's InputData property. This incompatibility is handled by an intermediate data structure in Python, called DataSeries (line 14).

The plugin's properties, InputData and Sigma, are assigned on line 17 and 20 respectively.

Line 23 denotes the execution of the noise plugin, and after that has finished, data can be visualized by using the \verb|plot| function (line 26). The output is shown below the script.

\begin{singlespace}
\lstinputlisting[label=plugin_addNoise_header,caption={Add noise example.},language=Python]{Examples/telNoisePluginEx1.py}
\end{singlespace}

\begin{figure}[ht]
\centering
\includegraphics[width=\textwidth]{AddNoise.png}
\caption{Output for the AddNoise python example script discussed above}
\label{fig:addNoiseFig1}
\end{figure}

\subsection{Visualization of the noise distribution used in the AddNoise plugin}
The Python script below demonstrates how to obtain and visualize the actual distribution (Gaussian) of noise that is applied on data.

\begin{singlespace}
\lstinputlisting[label=plugin_addNoise_header,caption={Noise distribution example.},language=Python]{Examples/telNoisePluginEx2.py}
\end{singlespace}

\begin{figure}[ht]
\centering
\includegraphics[width=\textwidth]{AddNoise2.png}
\caption{Output for the AddNoise python example script discussed above}
\label{fig:addNoiseFig2}
\end{figure}


\subsection{Group presentations}\label{subsec:group_presentations}

\begin{definition}\label{def:free_monoid}
  Let \( \mscrS \) be an arbitrary set. We associate with \( \mscrS \) its \term{free monoid} \( F(\mscrS) \coloneqq (\mscrS^{\ast}, \cdot) \), where \( \mscrS^{\ast} \) is the \hyperref[def:formal_language/kleene_star]{Kleene star} and \( \cdot \) is \hyperref[def:formal_language/concatenation]{concatenation}. It is a monoid due to \fullref{thm:kleene_star_is_monoid}.
\end{definition}

\begin{proposition}\label{thm:free_monoid_is_free_functor}
  The functor \( F: \cat{Set} \to \cat{Mon} \), defined pointwise in \fullref{def:free_monoid}, is \hyperref[def:category_adjunction]{free}.
\end{proposition}
\begin{proof}
  Let \( U: \cat{Mon} \to \cat{Set} \) be the corresponding forgetful functor and let \( \mscrM \in \cat{Mon} \), \( \mscrS \in \cat{Set} \). We will first show that
  \begin{equation*}
    \cat{Mon}(F(\mscrS), \mscrM) = \cat{Set}(\mscrS, U(\mscrM)),
  \end{equation*}
  where equality means that all the underlying functions are equal.

  Every monoid homomorphism is a function, so obviously
  \begin{equation*}
    \cat{Mon}(F(\mscrS), \mscrM) \subseteq \cat{Set}(\mscrS, U(\mscrM)).
  \end{equation*}

  Now consider a function \( f: \mscrS \to U(\mscrM) \). Define the function
  \begin{balign*}
     &\varphi: F(\mscrS) \to \mscrM \\
     &\varphi\left( \{ x_k \}_{k \in \mscrK} \right) \coloneqq \prod_{k \in \mscrK} x_k.
  \end{balign*}

  Obviously \( \varphi \) is a homomorphism from \( F(\mscrS) \) to \( \mscrM \). Hence,
  \begin{equation*}
    \cat{Set}(\mscrS, U(\mscrM)) \subseteq \cat{Mon}(F(\mscrS), \mscrM).
  \end{equation*}
\end{proof}

\begin{definition}\label{def:free_group}
  Let \( \mscrS \) be an arbitrary set. We will now construct the \term{free group} \( F(\mscrS) \) of \( \mscrS \). The construction is similar to that of \hyperref[def:free_monoid]{free monoids}, but it is much more complicated because of special reduction rules for \hyperref[def:unital_magma_inverse_element]{inverse elements}. Refer to \cite{code:free_group_grammar_verification} for a, software implementation of the construction.

  Let \( \star \) be a \hyperref[def:formal_language/symbol]{symbol} not in \( \mscrS \). Our goal is, for each \( a \in S \), to make the word \( a{\star} \) behave like the inverse of \( a \) in a group. Rather than considering the \hyperref[def:formal_language/kleene_star]{Kleene star} \( (S \cup \{ \star \})^* \) and removing elements via \enquote{reductions} as in \cite{code:free_group_reduction_verification} and \cite[306]{Knapp2016BasicAlgebra}, we directly build a language of \term{reduced words} using the mutually recursive \hyperref[def:formal_grammar]{grammar}
  \begin{alignedeq}\label{eq:def:free_group/grammar}
    &I \to \varepsilon,           &&                        && \text{\( I \) is the initial state} \\
    &I \to S_a \mid D_a,             && a \in S              && \\
    &S_a \to a \mid a S_a,           && a \in S              && S_a \text{ does not produce words beginning with } a\star \\
    &S_a \to a D_b,               && a, b \in S, a \neq b && \\
    &D_a \to a\star S_b,          && a, b \in S, a \neq b && D_a \text{ does not produce words beginning with } a \\
    &D_a \to a\star \mid a\star D_a, && a \in S              && \\
  \end{alignedeq}

  The \term{free group} \( F(\mscrS) \) is defined to be the language of \eqref{eq:def:free_group/grammar} equipped with the inductively defined operation
  \begin{equation}\label{eq:def:free_group/operation}
    w_1 \odot w_2 \coloneqq \begin{cases}
     p \odot s, &w_1 = p a \T{and} w_2 = a\star s \text{ for some } a \in S, \\
     p \odot s, &w_1 = p a\star \T{and} w_2 = as \T{and} s \neq \star t \text{ for some } a \in S, \\
     ps,        &\text{otherwise}.
   \end{cases}
  \end{equation}

  The inverse of the word \( w = a_1 \ldots a_n \) is \( w^{-1} \coloneqq b_1 \ldots b_n \), where
   \begin{equation}\label{eq:def:free_group/inverse}
     b_{n-k+1} \coloneqq \begin{cases}
       \varnothing, &a_k = {\star} \\
       a_k{\star},  &a_k \neq {\star} \T{and} k = n \\
       a_k{\star},  &a_k \neq {\star} \T{and} a_{k+1} \neq {\star} \\
       a_k,         &a_k \neq {\star} \T{and} k \neq n \T{and} a_{k+1} = {\star} \\
     \end{cases}
   \end{equation}
   for \( k = 1, \ldots, n \).

  The group \( (F(\mscrS), \odot) \) is called the \term{free group} generated by \( \mscrS \).
\end{definition}
\begin{proof}
  The proof of the well-definedness of the group structure of \( F(\mscrS) \) is a straightforward (but tedious) application of induction.
\end{proof}

\begin{proposition}\label{thm:free_group_is_free_functor}
  The functor \( F: \cat{Set} \to \cat{Grp} \), defined pointwise in \fullref{def:free_group}, is \hyperref[def:category_adjunction]{free}.
\end{proposition}
\begin{proof}
  The outline of the proof is similar to the proof of \fullref{thm:free_monoid_is_free_functor}.
\end{proof}

\begin{definition}\label{def:group_presentation}\mcite[314]{Knapp2016BasicAlgebra}
  Let \( \mscrS \) be a set, \( F(\mscrS) \) be the \hyperref[def:free_group]{free group} and \( \mscrR \subseteq F(\mscrS) \) be a subset. Denote by \( \mscrN(\mscrR) \) the smallest normal subgroup of \( F(\mscrS) \) that includes \( \mscrR \) as a subset.

  We define the group
  \begin{equation}\label{eq:def:group_presentation/presentation}
    \mscrG = \braket{ \mscrS \mid \mscrR} \coloneqq F(\mscrS) / \mscrN(\mscrR)
  \end{equation}
  called the group with \term{generators} \( \mscrS \) and \term{relators} \( \mscrR \). The expression \eqref{eq:def:group_presentation/presentation} is called a \term{presentation} of \( \mscrG \).

  If there exists a presentation for \( \mscrG \) such that \( \mscrS \) is finite, it is called a \term{finitely generated} group. If there exists a presentation such that both \( \mscrS \) and \( \mscrR \) are finite, it is called \term{finitely presented}.

  If \( \mscrR = \varnothing \), there are no restrictions and we use the notation
  \begin{equation}\label{eq:def:group_presentation/free}
    \mscrG = \braket{ \mscrS } \coloneqq F(\mscrS)
  \end{equation}
  for the free group.
\end{definition}

\begin{theorem}\label{thm:every_group_is_representable}\mcite[prop. 7.7]{Knapp2016BasicAlgebra}
  Every group \( \mscrG \) has at least one \hyperref[def:group_presentation]{presentation}.
\end{theorem}
\begin{proof}
  Let \( \mscrG \) be an arbitrary group and let \( \mscrS \coloneqq U(\mscrG) \) be the underlying set. Let \( F(\mscrS) \) be the corresponding free group with \( \iota: \mscrS \to F(\mscrS) \) sending elements of \( \mscrS \) to singleton words in \( F(\mscrS) \). By \fullref{thm:free_group_is_free_functor}, there exists a unique homomorphism \( \varphi: F(\mscrS) \to \mscrG \) such that
  \begin{equation*}
    \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
      beginfig(1);
      input metapost/graphs;

      v1 := thelabel("$\mscrS$", origin);
      v2 := thelabel("$U(F(\mscrS))$", (-1, -1) scaled u);
      v3 := thelabel("$U(G)$", (1, -1) scaled u);

      a1 := straight_arc(v1, v2);
      a2 := straight_arc(v1, v3);

      d1 := straight_arc(v2, v3);

      draw_vertices(v);
      draw_arcs(a);

      drawarrow d1 dotted;

      label.ulft("$\iota$", straight_arc_midpoint of a1);
      label.urt("$\id$", straight_arc_midpoint of a2);
      label.top("$U(\varphi)$", straight_arc_midpoint of d1);
      endfig;
    \end{mplibcode}\fi
  \end{equation*}
  that is, \( U(\varphi) \circ \iota = \id \). Thus, \( G = \mscrS \subseteq \ker \varphi \). Define \( \mscrR \coloneqq \ker \varphi \). By \fullref{def:normal_subgroup}, \( \mscrR \) is a normal subgroup of \( F(\mscrS) \), thus
  \begin{equation*}
    G = \varphi(F(\mscrS)) \cong F(\mscrS) / \ker \varphi = \braket{ \mscrS \mid \mscrR }.
  \end{equation*}
\end{proof}

\begin{definition}\label{def:cyclic_group}
  For a singleton alphabet \( \set{ a } \), we define the \term{infinite cyclic group}
  \begin{equation*}
    C \coloneqq \braket{a}
  \end{equation*}
  and, for positive integers \( n \), the \term{finite cyclic group} of \term{order} \( n \) as
  \begin{equation*}
    C_n \coloneqq \braket{a \given a^n}.
  \end{equation*}

  We use the same notation independent of \( a \) because all cyclic groups of the same order are obviously \hyperref[def:group/homomorphism]{isomorphic}.

  See \fullref{thm:cyclic_group_isomorphic_to_integers_modulo_n}.
\end{definition}

\begin{definition}\label{def:group_free_product}\mcite[323]{Knapp2016BasicAlgebra}
  The \term{free product} of a nonempty family of groups \( \seq{ \mscrX_k }_{k \in \mscrK} \) with presentations \( \braket{\mscrS_k \mid \mscrR_k}, k \in \mscrK \) is the group
  \begin{equation*}
    \Ast_{k \in \mscrK} \mscrX_k \coloneqq \braket*{ \coprod_{k \in \mscrK} \mscrS_k \given* \coprod_{k \in \mscrK} \mscrR_k },
  \end{equation*}
  where \( \coprod \) is the \hyperref[def:disjoint_union]{disjoint union}.
\end{definition}

\begin{definition}\label{def:free_abelian_group}
  A \term{free abelian group} is a \hyperref[def:free_left_module]{free} \hyperref[thm:abelian_group_iff_z_module]{\( \BbbZ \)-module}. This definition of a free abelian group is different from the definition of a \hyperref[def:free_group]{free group}.
\end{definition}


\documentclass[11pt,twoside]{article}

\usepackage[headings]{fullpage}
\usepackage[utopia]{mathdesign}

\pagestyle{myheadings}
\markboth{Chemotaxis}{Chemotaxis}

\input{../../fncextra}

\begin{document}

\begin{center}
    \bf You've been slimed
\end{center}

Slime mold cells are able to spontaneously aggregate by secreting a chemical attractant in a process called \emph{chemotaxis}. A nondimensional 1D model for the process is
\begin{equation}
\label{eq:1}
    \begin{split}
    u_t &= u_{xx} - \chi (uv_x)_x, \qquad -1\le x \le 1, \quad t\ge0, \\
    v_t &= \epsilon v_{xx} + u - v,
    \end{split}
\end{equation}
where $u(x,t)$ represents a scaled cell density function, $v(x,t)$
represents the attractant concentration, and $\chi$ and $\epsilon$ are nonnegative constants. We will use periodic end conditions.

In order to apply the method of lines to~\eqref{eq:1}, first discretize in space using finite differences to get
\begin{equation}
\label{eq:mol}
    \begin{split}
    \bfu' &= \bff\,(\bfu,\bfv) = \mD_{xx} \bfu - \chi \mD_x \bigl[\bfu \odot \bigl(\mD_{x} \bfv \bigr)\bigr]
    \\
    \bfv' &= \bfg\,(\bfu,\bfv) = \epsilon \mD_{xx} \bfv + \bfu - \bfv,
    \end{split}
\end{equation}
where $\odot$ is the elementwise product \verb|.*| in MATLAB. Choosing the Euler time stepping method, for example, leads to this iteration in the time step $j$:
\begin{equation}
\label{eq:euler}
\begin{split}
\bfu_{j+1} &= \bfu_j + \tau \bff\,(\bfu_j,\bfv_j) \\
\bfv_{j+1} &= \bfv_j + \tau \bfg\,(\bfu_j,\bfv_j).
\end{split}
\end{equation}

To apply a built-in IVP solver, equation~\eqref{eq:mol} has to be expressed as a single first-order vector equation. The two ``variables'' of the system are actually the two $m$-vectors $\bfu$ and $\bfv$, which are combined into a column vector $\bfz=\bigl[ \bfu\;;\; \bfv \bigr]$, leading to a system in the standard form $\bfz'=\bfF\,(t,\bfz)$.

\subsection*{Goals}

You will simulate the chemotaxis of slime mold and observe concentration of cells around initially small increases in attractant. You will use both the Euler and \texttt{ode15s} timestepping methods.

\subsection*{Preparation}

Read section 11.4.

\subsection*{Procedure}

Throughout all of these steps, let  $\chi=6$ and $\epsilon=0.1$ in all the equations above.

\begin{enumerate}
\item Let $m=50$, $u(x,0)=1$, and $v(x,0)=1+0.1e^{-100x^2}$, representing a small drop of extra attractant. (Note: the initial $v$ is not truly periodic, but the exponential is so small at $x=\pm1$ that is practically so.) Use the Euler timestepping method as shown in~\eqref{eq:euler} to solve over $0\le t \le0.05$ with $n=100$ time steps. Make a waterfall plot of the solution.

\item Now you will repeat step~1 with $m=200$ and for $0\le t \le 0.6$. Due to absolute stability restrictions, there is a minimum acceptable value of $n$. Start with $n=2000$ and increment $n$ repeatedly by 500 until the solution at the final time is finite. (Use the syntax \texttt{all(isfinite(w))} to determine if a vector is finite.) Output the minimum stable $n$ and plot $u(x,0.6)$.

\item The next goal is to use the built-in solver \texttt{ode15s} that works well for stiff problems. To do this, write a function \texttt{timederiv.m} with headline
    \begin{verbatim}
      function dzdt = timederiv(u,v,chi,Dx,Dxx)
    \end{verbatim}
  and returning $\bfz'=\bigl[ \bfu'\;;\; \bfv' \bigr]$ for the given inputs.

\item Now solve (with the same $m$ and initial conditions as step~2) using \texttt{ode15s} for $0\le t \le 15$. You will need to write an anonymous function of $t$ and $\bfz$ only that encapsulates a call to \texttt{timederiv}. Print out the number of time steps that were taken and make a waterfall plot of the solution.

\item You would expect that if there were two symmetrically placed drops of attractant, the solution would remain symmetric for all time. However, that solution is unstable in time and one of the drops will eventually ``win.'' Repeat step~4 using $$v(x,0)=1+0.1e^{-100(x-0.5)^2}+0.1e^{-100(x+0.5)^2}.$$

\end{enumerate}

% \subsection*{Extras}
% \begin{enumerate}
%   \item[E1.] Observe that
%   $$\frac{d}{dt} \int_{-1}^{1} u\, dx = \int_{-1}^{1} u_t \,dx = \int_{-1}^{1} \bigl[u_x - \chi(uv_x)\bigr]_x \,dx = 0,$$
%   due to the periodicity in $x$. Thus the total ``mass'' $M(t)=\int u\,dx$ is conserved in the exact solution. Use the trapezoidal quadrature formula to make a plot of $M(t)$ for the numerical solution of step~5 and check the conservation property. Make sure you apply the formula correctly over the entire interval and account for the periodicity of $u$.
% \end{enumerate}

\end{document}

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


%!TEX root = TTK4150-Summary.tex
\section{Feedback linearisation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Input-output linearisation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{align}
	\dot{x} &= f(x) + g(x)u \label{eq:siso-x} \\
	y       &= h(x)         \label{eq:siso-y}
\end{align}

\paragraph{Definition 13.2 (relative degree)}
The relative degree $\rho$ of \eqref{eq:siso-x}--\eqref{eq:siso-y} is equal to the number of times $y$ must be differentiated until $u$ appears.

\paragraph{Theorem 13.1}
The system \eqref{eq:siso-x} can be input-output linearised if the relative degree is well defined in the region of interest $\mathbb{D}_0$.

\paragraph{Minimum phase}
The system \eqref{eq:siso-x}--\eqref{eq:siso-y} is \emph{minimum phase} if, for the zero-dynamics $\dot{\eta} = f_0(\eta,0)$, $\eta = 0$ is AS.

\paragraph{Method}
The system is given by \eqref{eq:siso-x}--\eqref{eq:siso-y}. First determine relative degree $\rho$. Define
\begin{equation}
	\xi =
	\begin{bmatrix}
		\xi_1 \\ \vdots \\ \xi_\rho
	\end{bmatrix}
	=
	\begin{bmatrix}
		y \\ \vdots \\ y^{(\rho-1)}
	\end{bmatrix}
\end{equation}
so that
\begin{equation}
	\dot{\xi} =
	\begin{bmatrix}
		\dot{\xi}_1 \\ \vdots \\ \dot{\xi}_\rho
	\end{bmatrix}
	=
	\begin{bmatrix}
		\xi_2 \\ \vdots \\ L_f^\rho h + L_g L_f^{\rho-1} h \cdot u
	\end{bmatrix}
	.
\end{equation}
Then choose $n-\rho$ coordinates
\begin{equation}
	\eta =
	\begin{bmatrix}
		\eta_1 \\ \vdots \\ \eta_{n-\rho}
	\end{bmatrix}
\end{equation}
with the coordinate transformation
\begin{equation}
	z = T(x) =
	\begin{bmatrix}
		\eta_1 \\ \vdots \\ \eta_{n-\rho} \\ \xi_1 \\ \vdots \\ \xi_\rho
	\end{bmatrix}
\end{equation}
and choose $\eta$ such that
\begin{itemize}
	\item $T$ is a diffeomorphism,
	\item $L_g \eta_i = 0$,
	\item $\eta_i(0) = 0$.
\end{itemize}
We have then that
\begin{equation}
	\dot{\eta}_j = \pd{\eta_j}{x} \dot{x} = L_f \eta_j + \underbrace{L_g \eta_j}_{= 0} \cdot u = f_{0_j} (\eta_i, \xi_i)
\end{equation}
and we can write the system on normal form
\begin{equation}
	\begin{bmatrix}
		\dot{\eta}_1        \\
		\vdots              \\
		\dot{\eta}_{n-\rho} \\
		\dot{\xi}_1         \\
		\vdots              \\
		\dot{\xi}_\rho
	\end{bmatrix}
	=
	\begin{bmatrix}
		f_{0_1}(\eta_i, \xi_i)        \\
		\vdots                        \\
		f_{0_{n-\rho}}(\eta_i, \xi_i) \\
		\xi_2                         \\
		\vdots                        \\
		L_f^\rho h + L_g L_f^{\rho-1} h \cdot u
	\end{bmatrix}
	.
\end{equation}
Then choose $u$ to cancel the nonlinearities:
\begin{equation}
	u = \frac{1}{L_g L_f^{\rho-1} h} (-L_f^\rho h + v)
\end{equation}
This leads to
\begin{gather}
	\dot{\eta} = f_0(\eta,\xi) \\
	\dot{\xi} =
	\begin{bmatrix}
		\xi_2 \\ \vdots \\ v
	\end{bmatrix}
\end{gather}
Then analyse the zero-dynamics---the internal dynamics when the output is kept zero by the input:
\begin{equation}
	\dot{\eta} = f_0(\eta,0)
\end{equation}

TTK4150 Nonlinear control systems/sec-feedback-lin.tex


\subsection{The Lorentz group}

The Lorentz group is the \(O(1,3)\) group.
\subsubsection{Symmetries of the Lorentz group}

We can do the usual \(3\) rotations, however there are additional \(3\) symmetries, making the Lorzentz group \(6\)-dimensional.

These are the Lorentz boosts.

A symmetry has:

\(t'^2 - x'2 - y'^2 - z'^2 = t^2 - x^2 - y^2 - z^2\)

We consider the case where we just boost on \(x\), so \(y = y'\) and \(z = z'\).

\(t'^2 - x'2 = t^2 - x^2\)

Or with \(c\):

\(c^2t'^2 - x'2 = ct^2 - x^2\)

\subsubsection{New}
\(s^2 = t^2 - x^2 - y^z - z^2\)

\(s'^2 = t'^2 - x'^2 - y'^2 - z'^2\)

\(ds^2 = s'^2 - s^2\)

\(ds^2 = (t'^2 - x'^2 - y'^2 - z'^2) - (t^2 - x^2 - y^z - z^2)\)

\(ds^2 = (t'^2 - t^2) - (x'^2 - x^2) - (y'^2 - y^2) - (z'^2 - z^2)\)

\(ds^2 = dt^2 - dx^2 - dy^2 - dz^2\)

boost:
\(s^2 = c^2t^2 - x^2 - y^z - z^2\)

we want new t and x where distance is same
\(c^2t'^2 - x'^2 - y^z - z^2 = c^2t^2 - x^2 - y^z -z^2\)
\(c^2t'^2 - x'^2 = c^2t^2 - x^2\)

We know that both transformations are linear [WHY??], therefore
\(x' = Ax + Bt\)
\(t' = Cx+Dt\)

we transform to \(x' = 0\). so
\(Ax + Bt = 0\)

We define
\(v = \dfrac{x}{t}\)

So:
\(x = vt\)

We can plug these in:
\(Avt + Bt = 0\)
\(Av + B = 0\)
\(\dfrac{A}{B} = -v\)


\lab{The Arnoldi Iteration}{The Arnoldi Iteration}
\objective{The Arnoldi Iteration is an efficient method for finding the eigenvalues of extremely large matrices.
Instead of using standard methods, the iteration uses Krylov subspaces to approximate how a linear operator acts on vectors.
With this approach, the Arnoldi Iteration facilitates the computation of eigenvalues for enormous matrices without needing to physically create the matrix in memory.
We will explore this subject by implementing the Arnoldi iteration algorithm, using our implementation for eigenvalue computation, and then graphically representing the accuracy of our approximated eigenvalues.}

\section*{Krylov Subspaces} % =================================================

One of the biggest difficulties in numerical linear algebra is the amount of memory needed to store a large matrix and the amount of time needed to read its entries.
Methods using Krylov subspaces avoid this difficulty by studying how a matrix acts on vectors, making it unnecessary in many cases to create the matrix itself.

The \emph{Arnoldi Iteration} is an algorithm for finding an orthonormal basis of a Krylov subspace.
One of its strengths is that it can run on any linear operator without knowing the operator's underlying matrix representation.
The outputs of the Arnoldi algorithm can then be used to approximate the eigenvalues of the matrix of the linear operator.

The order-$n$ Krylov subspace of $A$ generated by $\x$ is
\[
\mathcal{K}_n(A, \x) =\text{span} \{\x, A\x, A^2\x, \ldots, A^{n-1}\x\}.
\]
If the vectors $\{\x, A\x, A^2\x, \ldots, A^{n-1}\x\}$ are linearly independent, then they form a basis for $\mathcal{K}_n(A,\x)$.
However, $A^n x$ frequently converges to a dominant eigenvector of $A$ as $n$ gets large, which fills the basis with many almost parallel vectors.
This yields a basis prone to ill-conditioned computations and numerical instability.

\section*{The Arnoldi Iteration Algorithm} % ==================================

The Arnoldi iteration focuses on efficiently creating an orthonormal basis for $\mathcal{K}_n(A,\x)$ by integrating the creation of $\{\x, A\x, A^2\x, \ldots, A^{n-1}\x\}$ with the modified Gram-Schmidt algorithm.
This process yields an orthonormal basis for $\mathcal{K}_n(A,\x)$ that can be used for further computations.
%A brief walkthrough of this method and a psuedo code representation of it are contained below.

\begin{comment}
Before discussing the specific uses of the Krylov subspace in linear systems and eigenvalue problems, let us address a very practical concern: how can we best compute a basis for the Krylov subspace?
The obvious answer is simply to calculate the vectors $x, ax, a^2x, \ldots, a^{n-1} x$, which we can accomplish using only matrix-vector multiplication.
Straightforward though this may be, there is a major problem: $a^n x$ tends to converge to a dominant eigenvector of $a$ as $n$ gets large, and consequently these vectors become nearly parallel.
Thus, the basis $\{x, ax, a^2x, \ldots, a^{n-1} x\}$ is far from orthogonal, and matrix computations associated with this basis will likely be ill-conditioned and prone to numerical instability.
To redress this problem, we may think to apply the Gram-Schmidt orthogonalization process to the basis, obtaining an orthonormal basis for the krylov subspace that enjoys much better numerical properties.
This turns out to be a useful thought, and is the basis for the Arnoldi iteration.

You may recall from lab \ref{lab:qrdecomp} that the modified Gram-Schmidt algorithm allows us to find an increasing number of orthogonal vectors but does not require that we run the algorithm to its completion to find a full basis.
Our goal is to find an orthonormal set of vectors $q_1,\ldots,q_n$ having the same span as $x, ax, a^2x, \ldots, a^{n-1} x$.
We start things off by setting
\[
q_1 = \frac{x}{\|x\|_2}.
\]
now, assuming we have obtained $q_1,\ldots,q_n$, we obtain $q_{n+1}$ by projecting $a q_n$ onto the previous vectors, subtracting out these projections, and then normalizing.
To make this more precise, let $h_{i,n} = \langle q_i, a q_n\rangle$ for $i = 1,\ldots, n$. subtract out these projections by calculating
\[
p_{n+1} = a^n x - \sum_{i=1}^n h_{i,n}q_i.
\]
define $h_{n+1,n} = \|p_{n+1}\|_2$, and normalize $p_{n+1}$ by calculating
\[
q_{n+1} = \frac{p_{n+1}}{h_{n+1,n}},
\]
our next basis vector.
This procedure is outlined (in slightly more python-friendly notation) in algorithm \ref{alg:arnoldi_iteration}.

Perhaps you noticed a slight discrepancy between the Arnoldi iteration as described above, and the usual Gram-Schmidt procedure.
Specifically, you might have expected to compute $q_{n+1}$ by projecting $a^n x$, rather than $a q_n$, onto the previous vectors.
Thankfully, it is straightforward to show that our algorithm produces a valid orthonormal basis for the Krylov subspace, despite this difference, and because of this detail, we do not need to compute and store the original Krylov basis $x, ax, \ldots, a^{n-1}x$.
Additionally, each iteration only requires one matrix-vector calculation, and the individual entries in $a$ are never referenced or modified.
Thus, even if the matrix $a$ is very large in theory, as long as we have a reasonably efficient subroutine to calculate $ax$ for any vector $x$, the Arnoldi iteration is computationally tractable.

This algorithm produces an orthonormal basis $q_1,\ldots,q_n$ for the order-$n$ Krylov subspace generated by $a$ and $x$, as well as a collection of numbers $h_{i,j}$.
If we define a matrix $h_n$ whose $i,j$'th entry is $h_{i,j}$ for $i \leq j+1$ and is $0$ otherwise, we now have an upper Hessenberg matrix.
Recall that an upper Hessenberg matrix has the property that all entries below the first subdiagonal are equal to zero.
Any square matrix is unitarily similar to an upper Hessenberg matrix.
Dealing with a Hessenberg matrix is often more convenient than dealing with a general matrix, especially when it comes to finding eigenvalues or solving systems of equations, since efficient algorithms designed for these types of matrices exist.
It turns out that there is a Hessenberg factorization of $a$, given by
\[
a  = qhq^*,
\]
Where $q$ is a unitary matrix and $h$ is upper Hessenberg such that the first $n$ columns of $q$ are $q_1,\ldots,q_n$, and the upper left $n \times n$ submatrix of $h$ is equal to $h_n$.
Hence, the Arnoldi iteration provides a connection between the Krylov subspace and the Hessenberg factorization of a matrix.
Each step in the Arnoldi iteration can be thought of as computing another step in the Hessenberg reduction of $a$.
Each $h_n$ is really just the $n \times n + 1$ upper-left block of $h$.
Solving eigenvalue problems or systems of equations for a general square matrix can thus be reduced, via Arnoldi iteration, to solving these problems for a Hessenberg matrix, a much easier task.

At this point, we can view the Arnoldi iteration as a means to compute an orthonormal basis for a Krylov subspace, or alternatively, to compute a partial Hessenberg factorization of a matrix.
But in lab \ref{lab:canonical_transformations}, we discussed how orthogonal transformations can be used to transform a matrix to upper Hessenberg form.
We were able to find the eigenvalues of such upper Hessenberg matrices in lab \ref{lab:eigsolve}.
So what have we really gained by this new approach?
These previous approaches were based on matrix-matrix multiplication and required us to manipulate individual entries of the matrix.
The Arnoldi iteration avoids this and relies only on our ability to calculate matrix-vector multiplication.
Further, our present approach will allow us to compute only a partial Hessenberg factorization.
This is advantageous when, as is often the case, the behavior and properties of a matrix can be well-approximated by only a small portion of its Hessenberg form.
\end{comment}

The algorithm begins by initializing a matrix $H$ which will be an upper Hessenberg matrix and a matrix $Q$ which will be filled with the basis vectors of our Krylov subspace.
It also requires an initial vector $\b \neq 0$ which is normalized to get $\q_1 = \b/\norm{\b}$.
This represents the basis for the initial Krylov subspace, $\mathcal{K}_1(A,\b)$.

For the $k$th iteration, compute the next basis vector $\q_{k+1}$ by using the modified Gram-Schmidt process to make $A\q_k$ orthonormal to $\q_k$.
This entails making each column of $Q$ orthogonal to $\q_k$ before proceeding to the next iteration.
The vectors $\{\q_i\}_{i=1}^k$ are then a basis for $\mathcal{K}_k(A,\b)$.
If $\norm{\q_{k+1}}$ is below a certain tolerance, stop and return $H$ and $Q$.
Otherwise, normalize the new basis vector new $\q_{k+1}$ and continue to the next iteration.
% This process continues until we have an orthonormal basis of an order $k+1$ Krylov subspace.

%This algorithm is described in algorithm \ref{alg:arnoldi_iteration} for an order $k+1$ Krylov subspace, where $k$ is the number of times we multiply by $A$.

\begin{algorithm}
\begin{algorithmic}[1]
\Procedure{Arnoldi}{$\b$, $A$, $k$, \li{tol}}
	\State $Q \gets \allocate{\size{\b}}{k+1}$			\Comment{Some initialization steps}
	\State $H \gets \zeros{ k+1}{ k}$
	\State $Q_{:,0} \gets \b/\norm{\b}_2$
	\For{$j=0\ldots k-1$}							\Comment{Perform the actual iteration.}
		\State $Q_{:,j+1} \gets A(Q_{:,j})$
		\For{$i=0\ldots j$}					\Comment{Modified Gram-Schmidt.}
			\State $H_{i,j} \gets Q_{:,i}\hrm Q_{:,j+1}$
			\State $Q_{:,j+1} \gets Q_{:,j+1} - H_{i,j} Q_{:,i}$
		\EndFor
		\State $H_{j+1,j} \gets \norm{Q_{:,j+1}}_2$			\Comment{Set subdiagonal element of $H$.}
            \If{$|H_{j+1,j}|<$ \li{tol}}					\Comment{Stop if $\norm{Q_{:,j+1}}_2$ is small enough.}
			\State \pseudoli{return} $H_{:j+1,:j+1}$, $Q_{:,:j+1}$
		\EndIf
		\State $Q_{:,j+1} \gets Q_{:,j+1}/H_{j+1,j}$				\Comment{Normalize $\q_{j+1}$.}
	\EndFor
	\State \pseudoli{return} $H_{:-1, :}$, $Q$			\Comment{Return $H_k$ and $Q$.}
\EndProcedure
\end{algorithmic}
\caption{The Arnoldi iteration.
This algorithm accepts a square matrix $A$ and a starting vector $\b$.
It iterates $k$ times or until the norm of the next vector in the iteration is less than \li{tol}.
The algorithm returns an upper Hessenberg $H$ and an orthonormal $Q$ such that $H = Q^{\mathsf{H}}AQ$.}
\label{alg:arnoldi_iteration}
\end{algorithm}

\begin{warn}
If the starting vector $\x$ is an eigenvector of $A$ with corresponding eigenvalue $\lambda$, then by definition $\mathcal{K}_k(A, \x)=\text{span}\{\x, \lambda \x, \lambda^2\x, \ldots, \lambda^k \x\}$, which is equal to the span of $\x$.
So, when $\x$ is normalized with $\q_1 = \x/\|\x\|$, $\q_2 = A\q_1 = \lambda \q_1$.

The vector $\q_2$ is supposed to be the next vector in the orthonormal basis for $\mathcal{K}_k(A, \x)$, but it is not linearly independent of $\q_1$.
In fact, $\q_1$ already spans $\mathcal{K}_k(A, \x)$.
Hence, the Gram-Schmidt process fails and results in a \li{ZeroDivisionError} or an extremely early termination of the algorithm.
A similar phenomenon may occur if the starting vector $\x$ is contained in a proper invariant subspace of $A$.
\end{warn}

\section*{Arnoldi Iteration on Linear Operators} % ============================

A major strength of the Arnoldi iteration is that it can run on a linear operator, even without knowing the matrix representation of the operator.
If $L$ is some linear function, then we can modify the pseudocode above by replacing $AQ_{:,j}$ with $A_{mul}(Q_{:,j})$.
This makes it possible to find the eigenvalues of an arbitrary linear transformation.

\begin{problem}\label{prob:arnoldi}
Write a function that accepts a starting vector $\b$ for the Arnoldi Iteration, a function handle $L$ that describes a linear operator, the number of times $n$ to perform the iteration, and a tolerance \li{tol} that defaults to $10^{-8}$.
Use Algorithm \ref{alg:arnoldi_iteration} to implement the Arnoldi Iteration with these parameters.
Return the upper Hessenberg matrix $H$ and the orthonormal matrix $Q$ from the iteration.

Consider the following implementation details.
\begin{enumerate}
\item Since $H$ and $Q$ will eventually hold complex numbers, initialize them as complex arrays (e.g., \li{A = np.empty((3,3), dtype=np.complex128)}).
\item This function can be tested on a matrix A by passing in \li{A.dot} for a linear operator.
\item Remember to use complex inner products. Here is an example of how to evaluate $A^HA$:
\begin{lstlisting}
b = A.conj() @ B
\end{lstlisting}
\end{enumerate}
Test your function by comparing the resulting $H$ with $Q\hrm A Q$.
\end{problem}

\section*{Finding Eigenvalues Using the Arnoldi Iteration} % ==================

Let $A$ be an $n \times n$ matrix.
Let $Q_k$ be the matrix whose columns $\q_1, \ldots, \q_k$ are the orthonormal basis for $\mathcal{K}_m(A, \x)$ generated by the Arnoldi algorithm, and let $H_k$ be the $k\times k$ upper Hessenburg matrix defined at the $k$th stage of the algorithm.
Then these matrices satisfy
\begin{equation}\label{eq:arnoldi-hqa}
H_k = Q_k^{\mathsf H} A Q_k.
\end{equation}
If $k<n$, then $H_k$ is a low-rank approximation to $A$  and the eigenvalues of $H_k$ may be used as approximations for the eigenvalues of $A$.
The eigenvalues of $H_k$ are called \emph{Ritz Values}, and we will later show that they converge quickly to the largest eigenvalues of $A$.

\begin{problem}\label{prob:ritz}
Write a function that accepts a function handle $L$ that describes a linear operator, the dimension of the space \li{dim} that the linear operator works on, the number of times $k$ to perform the Arnoldi Iteration, and the number of Ritz values $n$ to return.
Use the previous implementation of the Arnoldi Iteration and an eigenvalue function such as \li{scipy.linalg.eigs()} to compute the largest Ritz values of the given operator.
Return the \li{n} largest Ritz values.
\end{problem}

One application of the Arnoldi iteration is to find the eigenvalues of linear operators that are too large to store in memory.
For example, if an operator acts on a vector $\x \in \mathbb{C}^{2^{20}}$, then its matrix representation contains $2^{40}$ complex values.
Storing such a matrix would require 64 terabytes of memory!

An example of such an operator is the Fast Fourier Transform, cited by SIAM as one of the top algorithms of the century \cite{cipra2000}.
The Fast Fourier Transform is used very commonly in signal processing.

\begin{problem}
\label{prob:fourier_eigs}
The four largest eigenvalues of the Fast Fourier Transform are known to be $\{ -\sqrt{n}, \sqrt{n}, -i\sqrt{n}, i\sqrt{n} \}$ where $n$ is the dimension of the space on which the transform acts.

Use your function from Problem \ref{prob:ritz} to approximate the eigenvalues of the Fast Fourier Transform.
Set $k = 10$ and \li{dim} = $2^{20}$.
For the argument $L$, use the \li{scipy.fftpack.fft()}.
\end{problem}

The Arnoldi iteration for finding eigenvalues is implemented in a Fortran library called ARPACK.
Scipy interfaces with the Arnoldi iteration in this library via the function \li{scipy.sparse.linalg.eigs()}.
This function has many more options than the implementation we wrote in Problem \ref{prob:ritz}.
In this example, the keyword argument \li{k=5} specifies that we want five Ritz values.
Note that even though this function comes from the \li{sparse} library in Scipy, we can still call it on regular Numpy arrays.

\begin{lstlisting}
>>> from scipy.sparse import linalg as spla
>>> B = np.random.random((100,100))
>>> spla.eigs(B, k=5, return_eigenvectors=false)
array([ -1.15577072-2.59438308j,  -2.63675878-1.09571889j,
        -2.63675878+1.09571889j,  -3.00915592+0.j        ,  50.14472893+0.j ])
\end{lstlisting}

\subsection*{Convergence} % ---------------------------------------------------
As more iterations of the Arnoldi method are performed, our approximations are of higher rank.
Consequently, the Ritz values become more accurate approximations to the eigenvalues of the linear operator.

This technique converges quickly to eigenvalues whose magnitude is distinctly larger than the rest.
For example, matrices with random entries tend to have one eigenvalue of distinctly greatest magnitude.
Convergence of the Ritz values for such a matrix is plotted in Figure \ref{fig:arnoldi_random_val_conv}.

However, Ritz values converge more slowly for matrices with random eigenvalues.
Figure \ref{fig:arnoldi_random_eig_conv} plots convergence of the Ritz values for a matrix with eigenvalues uniformly distributed in $[0,1)$.

\begin{figure}
\centering
\begin{subfigure}[b]{.49\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/rand_vals_conv.pdf}
    \caption{}
    \label{fig:arnoldi_random_val_conv}
\end{subfigure}
\begin{subfigure}[b]{.49\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/rand_eigs_conv.pdf}
    \caption{}
    \label{fig:arnoldi_random_eig_conv}
\end{subfigure}
\caption{These plots show the relative error of the ritz values as approximations to the eigenvalues of a matrix.
The figure on the left plots the largest 15 Ritz values for a $500\times 500$ matrix with random entries and demonstrates that the largest eigenvalue (the blue line) converges after 20 iterations.
The figure at right plots the largest 15 Ritz values for a $500\times 500$ matrix with uniformly distributed eigenvalues in $[0,1)$ and demonstrates that all the eigenvalues take from 150 to 250 iterations to converge.}
\end{figure}

% todo: this problem may be too difficult but we have added a great deal of supplementary code to make it more doable.
\begin{problem}
Write a function that accepts a linear operator $A$, the number of Ritz values to plot $n$, and the the number of times to perform the Arnoldi iteration \li{iters}.
Use these parameters to create a plot of the absolute error between the largest Ritz values of $A$ and the largest eigenvalues of $A$.
\begin{enumerate}
    \item Find $n$ eigenvalues of $A$ of largest magnitude. Store these in order.
    \item Create an empty array to store the relative errors for every $k=0,1,\ldots,$ \li{iters}.
    \begin{enumerate}
    	\item Use your Ritz function to find the $n$ largest Ritz values of the operator. Note that for small $k$, the matrix $H_k$ may not have this many eigenvalues. Due to this, the graphs of some eigenvalues have to begin after a few iterations.
        \item Store the absolute error between the eigenvalues of A and the Ritz values of H. Make sure that the errors are stored in the correct order.
    \end{enumerate}
    %\item Use array broadcasting to compute the absolute error.
    \item Iteratively plot the errors for each eigenvalue with the range of the iterations.
\end{enumerate}
Hints:
If $\tilde{\x}$ is an an approximation to $\x$, then the \emph{absolute error} in the approximation is $\|\x - \tilde{\x}\|$.

Sort your eigenvalues from greatest to least.
An example of how to do this is included:
\begin{lstlisting}
# Evaluate the eigenvalues
eigvalues = la.eig(A)[0]
# Sort them from greatest to least (use np.abs to account for complex parts)
eigvalues = eigvalues[np.sort(np.<<abs>>(eigvalues))[::-1]]
\end{lstlisting}
In addition, remember that certain eigenvalues of $H$ will not appear until we are computing enough iterations in the Arnoldi algorithm.
As a result, we will have to begin the graphs of several eigenvalues after we are computing sufficient iterations of the algorithm.
%To be able to keep our graph readable, use masking such as the following to remove any extreme errors that arise in the first iterations.
%\begin{lstlisting}
%errors[errors > 10] = 10.
%\end{lstlisting}

Run your function on these examples.
The plots should be fairly similar to Figures \ref{fig:arnoldi_random_eig_conv} and \ref{fig:arnoldi_random_val_conv}.

\begin{lstlisting}
>>> A = np.random.rand(300, 300)
>>> plot_ritz(a, 10, 175)

>>> # A matrix with uniformly distributed eigenvalues
>>> d = np.diag(np.random.rand(300))
>>> B = A @ d @ la.inv(A)
>>> plot_ritz(B, 10, 175)
\end{lstlisting}
% These may take some time to run.
\end{problem}

% once the eigenvalue lab has been rewritten, have them use their own solver to find the eigenvalues of the $h_k$.

% this problem is very ill-conditioned.
\begin{comment}
\begin{problem}
finding the roots of a polynomial can be represented as an eigenvalue problem.
finding the roots of a monic polynomial (a polynomial with leading coefficient 1) $p = c_0 + c_1 x + \dots + c_{n-1} x^{n-1} + x^n$ is equivalent to finding the eigenvalues of the matrix
\[c = \begin{bmatrix}
0 & 0 & \dots & 0 & -c_0 \\
1 & 0 & \dots & 0 & -c_1 \\
0 & 1 & \dots & 0 & -c_2 \\
\vdots & \vdots & \ddots & \vdots & \vdots \\
0 & 0 & \dots & 1 & -c_{n-1} \end{bmatrix}\]
this matrix is called the companion matrix of the polynomial $p$.
as it happens, every matrix is similar to the companion matrix of its characteristic polynomial, but we won't use that fact here.

The following is a function that, given an array containing the coefficients $c_0, c_1, \dots, c_{n-1}$ for a monic polynomial $p$, performs matrix multiplication by the corresponding companion matrix.

\begin{lstlisting}
def companion_multiply(c, u):
    v = np.empty_like(u)
    v[0] = - c[0] * u[-1]
    v[1:] = u[:-1] - c[1:] * u[-1]
    return v
\end{lstlisting}

Use the Arnoldi iteration to estimate the five zeros of largest norm of a degree $1000$ monic polynomial with randomly chosen coefficients (the leading coefficient still needs to be 1).
Run $50$ steps of the Arnoldi iteration.
Compare your results with the roots of the polynomial computed using NumPy's \li{poly1d} class.
This computation can be done like this (where \li{c} is the array of random coefficients for the polynomial)

\begin{lstlisting}
p = np.poly1d([1] + list(c[::-1]))
roots = p.roots
# Now sort by absolute value from largest to smallest
roots = roots[np.<<abs>>(roots).argsort()][::-1]
\end{lstlisting}

How close are the first few zeros of largest norm?
\end{problem}
\end{comment}

\newpage

\section*{Additional Material} % ==============================================

\subsection*{The Lanczos Iteration} % -----------------------------------------

The Lanczos iteration is a version of the Arnoldi iteration that is optimized to operate on symmetric matrices.
If A is symmetric, then \eqref{eq:arnoldi-hqa} shows that $H_k$ is symmetric and hence tridiagonal.
This leads to two simplifications of the Arnoldi algorithm.

First, we have $0=H_{k, n}=\langle \q_k, A\q_n \rangle$ for $k \leq n-2$; i.e., $A\q_n$ is orthogonal to $\q_1, \ldots, \q_{n-2}$.
Thus, if the goal is only to compute $H_k$ (say to find the Ritz values), then we only need to store the two most recently computed columns of $Q$.
Second, the data of $H_k$ can also be stored in two vectors, one containing the main diagonal and one containing the first subdiagonal of $H_k$
(by symmetry, the first superdiagonal equals the first subdiagonal of $H_k$).

\begin{algorithm}[H]
\begin{algorithmic}[1]
\Procedure{Lanczos}{$\b, A, k, tol$}
	\State $\q_0 \gets \zeros{\size{\b}}$								\Comment{Some initialization}
	\State $\q_1 \gets \b/\norm{\b}_2$
	\State $\x \gets \allocate{k}$
	\State $\y \gets \allocate{k}$
	\For{$i=0\ldots k-1$}									\Comment{Perform the iteration.}
		\State $\z \gets A\q_1$					\Comment{$\z$ is a temporary vector to store $\q_{i+1}$.}
		\State $\x[i] \gets \q_1\trp \z$				\Comment{$\q_1$ is used to store the previous $\q_i$.}
		\State $\z \gets \z - \x[i] \q_1 + \y[i-1] \q_0$				\Comment{$\q_0$ is used to store $\q_{i-1}$.}
		\State $\y[i] = \norm{\z}_2$						\Comment{Initialize $\y[i]$.}
		\If{$\y[i]<tol$}								\Comment{Stop if $\norm{ \q_{i+1}}_2$ is too small.}
			\State \pseudoli{return} $\x[: i+1]$, $\y[: i]$
		\EndIf
		\State $\z = \z/ \y[i]$
		\State $\q_0, \q_1 = \q_1, \z$						\Comment{Store new $\q_{i+1}$ and $\q_i$ on top of $\q_1$ and $\q_0$.}
	\EndFor
	\State \pseudoli{return} $\x$, $\y[: -1]$
\EndProcedure
\end{algorithmic}
\caption{The Lanczos Iteration. This algorithm operates on a vector $\b$ of length $n$ and an $n \times n$ symmetric matrix $A$. It iterates $k$ times or until the norm of the next vector in the iteration is less than $tol$. It returns two vectors $\x$ and $\y$ that respectively contain the main diagonal and first subdiagonal of the current Hessenberg approximation.}
\label{alg:lanczos_iteration}
\end{algorithm}

\begin{comment}
\begin{problem}
\label{prob:lanczos}
Implement Algorithm \ref{alg:lanczos_iteration} by completing the following function.
Write it so that it can operate on complex arrays.
\begin{lstlisting}
def lanczos(b, L, k, tol=1E-8):
    '''Perform `k' steps of the Lanczos iteration on the symmetric linear
    operator defined by `L', starting with the vector 'b'.

    INPUTS:
    b    - A NumPy array. The starting vector for the Lanczos iteration.
    L - A function handle. Should describe a symmetric linear operator.
    k    - Number of times to perform the Lanczos iteration.
    tol  - Stop iterating if the next vector in the Lanczos iteration has
          norm less than `tol'. Defaults to 1E-8.

    RETURN:
    Return (alpha, beta) where alpha and beta are the main diagonal and
    first subdiagonal of the tridiagonal matrix computed by the Lanczos
    iteration.
    '''
\end{lstlisting}
\end{problem}
\end{comment}

As it is described in Algorithm \ref{alg:lanczos_iteration}, the Lanczos iteration is not stable.
Roundoff error may cause the $\q_i$ to be far from orthogonal.
In fact, it is possible for the $\q_i$ to be so adulterated by roundoff error that they are no longer linearly independent.
% If needed we could make a separate lab on the Lanczos iteration and the Implicitly Restarted Lanczos Method.
% There isn't time or space here for it though.

\begin{comment}
\begin{problem}
The following code performs multiplication by a tridiagonal symmetric matrix.

\begin{lstlisting}
def tri_mul(a, b, u):
   ''' Return Au where A is the tridiagonal symmetric matrix with main
   diagonal a and subdiagonal b.
   '''
    v = a * u
    v[:-1] += b * u[1:]
    v[1:] += b * u[:-1]
    return v
\end{lstlisting}

Let $A$ be a $1000\times 1000$ symmetric tridiagonal matrix with random values in its nonzero diagonals.
Use the function \li{lanczos()} from Problem \ref{prob:lanczos} with 100 iterations to estimate the 5 eigenvalues of $A$ of largest norm.
Compare these to the 5 largest true eigenvalues of $A$

If you do this problem for different vectors $a$ and $b$, you may notice that occasionally the largest Ritz value is repeated.
This happens because the vectors used in the Lanczos iteration may not be orthogonal.
These erroneous eigenvalues are called ``ghost eigenvalues.''
%They generally converge to actual eigenvalues of the matrix and can make the multiplicity of an eigenvalue look higher than it really is.
\end{problem}
\end{comment}

There are modified versions of the Lanczos iteration that are numerically stable.
One of these, the Implicitly Restarted Lanczos Method, is found in SciPy as \li{scipy.sparse.linalg.eigsh()}.


\section{Factorization in Integral Domains}
In this section, $R$ will always denote an integral domain.
\subsection{Prime and Irreducible Elements}
\begin{definition}
    $a\in R$ is said to divide $b\in R$, written as $a|b$, if $\exists c\in R,b=ac$.
    Or equivalently, $(b)\subset (a)$.\\
    $a,b\in R$ are associates if $a=bc$ for some unit $c\in R$.
    Equivalently, $(a)=(b)$.\\
    $r\in R$ is irreducible if it is nonzero and not a unit, also $ab=r$ implies at least one of $a,b$ is a unit.
    It is prime if it is nonzero and not a unit, and $r|ab\implies r|a\lor r|b$.
\end{definition}
Note that these properties depend on the underlying ring $R$.
For example, $2$ is irreducible and prime in $\mathbb Z$ but not in $\mathbb Q$.
Also $2X$ is irreducible in $\mathbb Q[X]$ but not in $\mathbb Z[X]$.
\begin{lemma}
    For a $r\in R$, $(r)$ is prime iff $r=0$ or $r$ is prime.
\end{lemma}
\begin{proof}
    If $(r)$ is prime and $r\neq 0$, then since $(r)$ is proper $r$ is not a unit, and if $r|ab$, then $ab\in (r)$, so $a\in (r)$ or $b\in (r)$, so $r|a$ or $r|b$, so $r$ is prime.\\
    Conversely, $(0)$ is prime and for $r$ a prime, $ab\in (r)\implies r|ab\implies r|a\lor r|b\implies a\in (r)\lor b\in (r)$, so $(r)$ is a prime ideal.
\end{proof}
One find that an integer is maximal iff it is prime.
We want to generalize this to some other integral domains.
\begin{lemma}
    A prime element is irreducible.
\end{lemma}
\begin{proof}
    Suppose $r\in R$ is prime, then it is nonzero and not a unit.
    If $r=ab$, then $r|a$ or $r|b$.
    WLOG $r|a$, then $a=rc$ for some $c\in R$, then $r=rcb\implies r(cb-1)=0$, but $r\neq 0$, so $cb=1$, hence $b$ is unit.
    Therefore $r$ is irreducible.
\end{proof}
The converse, sadly, does not hold in general.
\begin{example}[Non-example]
    Let $R=\mathbb Z[\sqrt{-5}]$, which is the subring of the field $\mathbb C$, hence is an integral domain.
    Define the norm $N:R\to\mathbb Z_{\ge 0}$ by $a+b\sqrt{-5}\mapsto a^2+5b^2$, which one can verify is multiplicative and $N(r)=1\implies r=\pm 1$.
    Now the only units in $R$ are $\pm 1$.
    Indeed if $rs=1$, then $1=N(rs)=N(r)N(s)$, so $N(r)=N(s)=1$, so $r,s\in\{\pm 1\}$.\\
    We claim that $2$ is irreducible in $R$.
    Suppose $2=rs$, then $N(r)N(s)=N(rs)=4$, but one can show that there is no element with norm $2$, so one of $N(r),N(s)$ must be $1$, which means that it is a unit.
    Similarly, $3,1+\sqrt{-5},1-\sqrt{-5}$ are all irreducible using exactly the same way.
    However, $(1+\sqrt{-5})(1-\sqrt{-5})=6=2\cdot 3$, but neither $1+\sqrt{-5}$ nor $1-\sqrt{-5}$ is divisible by $2$ (by either taking norms or finding out directly), therefore $2$ is not prime.
\end{example}
Also, in this particular ring $R$, unique Factorization fails as we can factorize $6$ into two different products of irreducibles which cannot be saved by multiplying a unit.
\subsection{Principal Ideal Domains}
\begin{definition}
    An integral domain $R$ is a principal ideal domain (PID) if every ideal of $R$ is principal.
\end{definition}
\begin{example}
    $\mathbb Z$ is a PID.
\end{example}
We will later show that $\mathbb Z[i]$ and $\mathbb F[X]$ for a field $\mathbb F$ are also PIDs.
\begin{lemma}
    Let $0\neq r\in R$, if $(r)$ is maximal, then $r$ is irreducible.
    If $R$ is a PID, then the converse holds.
\end{lemma}
\begin{proof}
    We have $(r)\neq 0,R$ by assumption, so $r$ is neither $0$ or a unit.
    If $r=ab$ for some $a,b\in R$, then $(r)\subset (a)\subset R$.
    Hence $(a)=R$ so $a$ is a unit, or $(r)=(a)$, therefore $r=au$ for a unit $u$.
    So $au=ab\implies b=u$ is a unit.
    Hence $r$ is irreducible.
    Conversely, given that $R$ is a PID, suppose $r$ is irreducible, then if $(r)\subset J\subset R$ for some ideal $J=(a)$ for some $a\in R$.
    Then $r=ab$ for some $b\in R$, but $r$ is irreducible, so either $b$ is a unit whence $(r)=(a)=J$, or $a$ is a unit whence $J=R$, therefore $(r)$ is maximal.
\end{proof}
\begin{proposition}
    Let $R$ be a PID, every irreducible element is prime.
\end{proposition}
\begin{proof}[First proof]
    Start with an irreducible $p\in R$.
    So $p$ is nonzero and not a unit.
    Suppose $p|ab$ and $p\nmid a$.
    Consider the ideal $(a,p)=(d)$ for some $d\in R$ since $R$ is a PID.
    Then $p=cd$ for some $c\in R$, so either $c$ or $d$ is a unit.\\
    If $c$ is a unit, then $(p)=(d)=(a,p)$, therefore $p|a$ contradiction.
    If $d$ is a unit, then $(a,p)=(d)=R$, so there is some $r,s$ such that $ar+ps=1$, hence $rab+sbp=b$, so $p|b$.
\end{proof}
\begin{proof}[Second proof]
    Given $p\in R$ irreducible, then $(p)$ is maximal, so $R/(p)$ is a field, which is an integral domain, hence $(p)$ is a prime ideal, which means that $p$ is prime.
\end{proof}
\begin{definition}
    An integral domain $R$ is called an Euclidean domain (ED) if there is a function $\phi:R\setminus\{0\}\to\mathbb Z_{\ge 0}$ (the Euclidean function) such that for any $a,b\in R$:\\
    1. If $a,b\neq 0$ and $a|b$, then $\phi(b)\ge \phi(a)$.\\
    2. If $b\neq 0$, then $\exists q,r>0,a=qb+r$ such that either $r=0$ or $\phi(r)<\phi(b)$.
\end{definition}
\begin{proposition}
    If $R$ is an Euclidean domain, then it is a PID.
\end{proposition}
\begin{proof}
    Let $\phi$ be the Euclidean function and $0\neq I\lhd R$ an ideal.
    Choose $b\in I$ such that it is nonzero and $\phi(b)$ is minimal.
    We shall show that $I=(b)$.
    Note that we immediately have $(b)\subset I$.
    For the other way, choose $0\neq a\in I$, we write $a=qb+r$ with $q,r\in R$ and either $r=0$ or $\phi(r)<\phi(b)$.
    If $r=0$ then $a\in (b)$.
    Otherwise, note that $r=a-qb\in I$, but $\phi(r)<\phi(b)$, contradicting the minimality of $b$.
    So we must have $a\in (b)$, hence $I=(b)$.
\end{proof}
\begin{remark}
    Note that we did not use the first criterion to define the Euclidean function in the above proof.
    The reason for us to include that in the definition of a ED is that it allows us to describe the units in $R$ in the way that $\phi(a)=\phi(1)$ iff $a$ is unit.
\end{remark}
\begin{example}
    1. $\mathbb Z$ is a ED since we can take $\phi(n)=|n|$.\\
    2. For a field $\mathbb F$, $\mathbb F[X]$ is a ED by taking $\phi(P)=\deg P$ since we can do division with remainder in the polynomial ring of a field.\\
    3. Consider the Gaussian integer $R=\mathbb Z[i]\le C$ by taking $\phi(a+ib)=a^2+b^2$, so $\phi$ is multiplicative therefore we get the first criterion.
    For the second, let $z_1,z_2\in R$.
    Consider $z_1/z_2\in\mathbb C$, which has distance strictly less than $1$ from the nearest Gaussian integer, so $z_1/z_2=q+\epsilon$ where $q\in R$ and $|\epsilon|<1$, so $z_1=qz_2+r$ where $r=\epsilon z_2=z_1-qz_2\in R$ and $\phi(r)=|\epsilon z_2|^2=|\epsilon|^2\phi(z_2)<\phi(z_2)$.
\end{example}
The above examples are all also PIDs by the preceding proposition.
\begin{example}
    1. Let $A$ be an $n\times n$ matrix in the field $\mathbb F$, and let $I$ be the set of all $f\in \mathbb F[X]$ such that $f(A)=0$.
    Now $I$ is trivially an ideal.
    But this ideal is principal since $\mathbb F[X]$ is a ED hence PID.
    Suppose $I=(f)$, then for any $g\in\mathbb F[X]$ such that $g(A)=0$, we have $f|g$.
    So $f$ is the minimal polynomial of $A$.\\
    2. Consider $\mathbb F_2=\mathbb Z/2\mathbb Z$ and let $f(X)=X^3+X+1\in\mathbb F_2[X]$.
    We want to show that $f$ is irreducible.
    Suppose $f(X)=g(X)h(X)$ with $\deg g,\deg h>0$.
    So one of $\deg g$ and $\deg f$ must be $1$ since $f$ has degree $3$, so $f$ has a root, but it does not, contradiction.\\
    But $\mathbb F_2[X]$ is a ED hence PID, therefore $(f)$ is maximal, so we get to construct a field $\mathbb F_2[X]/(X^3+X+1)$.
    The quotient looks like $\{aX^2+bX+c+(X^3+X+1):a,b,c\in\mathbb F_2\}$, but $a,b,c$ uniquely determines the ideal, so this is a field of order $8$.\\
    3. (non-example) The ring $\mathbb Z[X]$ is not a PID.
    Indeed, consider the ideal $I=(2,X)$, then $I=\{2f_1(X)+Xf_2(X):f_1,f_2\in\mathbb Z[X]\}=\{f(X)\in\mathbb Z[X]:f(0)\text{ is even}\}$.
    Suppose $I$ is generated by some polynomial $f\in\mathbb Z[X]$, so $2=fg$ for some $g\in\mathbb Z[X]$.
    But degrees add when polynomials multiply, hence $f,g$ has to be constant.
    Therefore $I$ can only be $\mathbb Z[X]$ or $2\mathbb Z[X]$, but both are impossible since $1\notin I$ (so $I$ is not the entire ring) and $X\in I$ (but $X\notin 2\mathbb Z[X]$).
\end{example}
\subsection{Unique Factorization Domains}
\begin{definition}
    An integral domain $R$ is called a unique factorization domain (UFD) if\\
    1. Every nonzero and nonunit $r\in R$ is a product of irreducibles.\\
    2. If $p_1\cdots p_m=q_1\cdots q_n$ where $p_i,q_i$ are irreducibles, then $m=n$ and $\exists\sigma\in S_n$ such that $p_i$ is an associate with $q_{\sigma(i)}$.
\end{definition}
\begin{proposition}\label{irred_prime_uniq}
    Let $R$ be an integral domain having the first property stated above, then $R$ is a UFD iff every irreducible is prime.
\end{proposition}
\begin{proof}
    If $R$ is a UFD and $r\in R$ is irreducible and $p|ab$, then $pc=ab$ for some $c\in R$.
    By the first condition, we can write $a,b,c$ as products of irreducibles, so an associate of $p$ must appear in the factorization of $a$ or $b$ by the second condition, so $p|a$ or $p|b$, hence $p$ is prime.\\
    Suppose every irreducible is prime.
    If $p_1\cdots p_m=q_1\cdots q_n$.
    Now since $p_1$ is prime, then $p_1|q_i$ for some $i$.
    But $q_i,p_1$ are both irreducible, so they are associates.
    By reordering, we can write $i=1$, and by cancellation law, $p_2\cdots p_m=q_2\cdots q_n$.
    The proof is finished by descent (or equivalently, induction).
\end{proof}
\begin{lemma}
    Let $R$ be a PID and there is a nested sequence of ideals $I_1\subset I_2\subset\cdots$, then there exists some $N\in\mathbb N$ such that $I_n=I_N$ for every $n\ge N$.
\end{lemma}
\begin{remark}
    This condition is one of the formulations of the definition of a Noetherian ring.
\end{remark}
\begin{proof}
    Consider the union $I=I_1\cup I_2\cup\cdots$.
    $I$ is obviously an ideal, so $I=(a)$ for some $a\in R$.
    But $a\in I_N$ for some $N\in\mathbb N$, so for any $n\ge N$, we have $(a)\subset I_n\subset I=(a)$, hence $I_n=(a)=I_N$.
\end{proof}
\begin{theorem}
    Every PID is a UFD.
\end{theorem}
\begin{proof}
    Let $R$ be a PID.
    By Proposition \ref{irred_prime_uniq}, since every irreducible in a PID is prime, it suffices to show the first condition of a UFD.
    Let $x\in R$ be nonzero and nonunit.
    Suppose $x$ cannot be written as a product of irreducibles, so in particular $x$ is not irreducible.
    Therefore we can write $x=x_1y_1$ for nonunit $x_1,y_1$.
    But not both of $x_1,y_1$ can be written as a product of irreducibles.
    WLOG $x_1$ is not a product of irreducibles, also we have $(x)\subsetneq (x_1)$ since $y_1$ is not a unit.
    Continue the process over and again gives a sequence of strictly nested ideals $(x)\subsetneq (x_1)\subsetneq\cdots$, but this is a sequence of nested ideals that does not terminate, hence contradiction to the preceding lemma.
\end{proof}
\begin{example}
    We know that ED implies PID implies UFD implies integral, so we have the following table of examples:
    \begin{center}
        \begin{tabular}{c|c|c|c|c|l}
            &ED&PID&UFD&Integral&\\
            $\mathbb Z/4\mathbb Z$&&&&No&\\
            $\mathbb Z[\sqrt{5}]$&&&No&Yes&See later.\\
            $\mathbb Z[X]$&&No&Yes&&See later.\\
            $\mathbb Z\left[\frac{1+\sqrt{-19}}{2}\right]$&No&Yes&&&See in Number Fields.\\
            $\mathbb Z[i]$&Yes&&&&
        \end{tabular}
    \end{center}
\end{example}
\subsection{Greatest Common Factors and Least Common Multiples}
\begin{definition}
    Let $R$ be a integral domain.
    We say $d$ is a greatest common divisor of $a_1,\ldots,a_n\in R$ if $d|a_i$ for each $i$ and if $\forall i,d'|a_i$, then $d'|d$.
    We say $m$ is a least common multiple of $a_1,\ldots,a_n\in R$ if $a_i|d$ for each $i$ and if $\forall i,a_i|d'$, then $d|d'$.
\end{definition}
Both GCDs and LCMs, when they exists, they are unique up to associates.
\begin{proposition}
    In a UFD, both LCMs and GCDs exist.
\end{proposition}
\begin{proof}
    Obvious.
\end{proof}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PROBLEM 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Problem 2}

Consider an infinite slab of material described by diffusion coefficient $D$ and macroscopic cross section $\Sigma_a$.
The material extends infinitely in two dimensions, but has vacuum boundaries at $x=\pm a$.
Inside the slab is a uniformly distributed source with strength $s'''$ [neutrons per volume].
Find the flux in this geometry.
(You may use the substitution $L = \sqrt{\frac{D}{\Sigma_a}}$.)