\documentclass{article}
%\usepackage{polski} %to replace latex keywords in the document to Polish
\usepackage[utf8]{inputenc} %sets input encoding to UTF-8, needed for Polish, Japanese, etc.
\usepackage[T1]{fontenc} %needed for Polish characters
\usepackage{lmodern} %this font handles Polish characters properly
\usepackage[cm]{fullpage} %very small margins (around 1.5cm)
\usepackage{multicol} %use \begin{multicols}{#} for # columns
\usepackage{amssymb} %big bracets and other useful symbols
\usepackage{amsmath} %some mathematical symbols
\usepackage{enumitem} %remove vertical space in itemize with: [noitemsep,nolistsep]
\usepackage{url} %use \url{} in the document
%\usepackage{tipa} % \textpolhook{a}

\newcommand{\nodata}{\emph{no data yet}}
\newcommand{\samplecustom}[2]{X_{#1}, \ldots, X_{#2}}
\newcommand{\sample}{\samplecustom{1}{n}}

\newcommand{\distbernoulli}{\textrm{Bern}}
\newcommand{\distbinomial}{\textrm{Bin}}
\newcommand{\distpoisson}{\textrm{Pois}}
\newcommand{\distgeometric}{\textrm{G}}
\newcommand{\disthypergeometric}{\textrm{Hy}}
\newcommand{\distuniform}{\textrm{U}}
\newcommand{\distnormal}{\textrm{N}}
\newcommand{\distexponential}{\textrm{Exp}}
\newcommand{\distgamma}{\Gamma}
\newcommand{\distchisquare}{\chi^2}
\newcommand{\diststudentt}{\textrm{t}}
\newcommand{\distf}{\textrm{F}}

\newcommand{\param}{\theta}
\newcommand{\estim}{\hat{\theta}}
\newcommand{\limit}[2]{\underset{#1 \rightarrow #2}{\lim}}
\newcommand{\mean}{\overline{X}}
\newcommand{\quantile}[2]{\textrm{#1-quantile}_{#2}}
\newcommand{\qquantile}[1]{\quantile{q}{#1}}
\newcommand{\qqquantile}[1]{\textrm{quantile}_{#1}}
\newcommand{\med}{\textrm{MED}}
\newcommand{\mad}{\textrm{MAD}}
\newcommand{\var}{\textrm{Var}}
\newcommand{\statspace}{\left( \mathcal{H}, \mathcal{A}, \mathcal{P} = \left\{ p_\theta : \theta \in \Theta \right\} \right)}

\begin{document}

\title{Theory and formulas for \emph{Computer Statistics} course on MiNI on WUT}
\date{\today}
\author{Mateusz Bysiek, Computer Science, MiNI, WUT}
\maketitle

%\pagebreak[4]

\tableofcontents

\newpage

\section{Theory}

\subsection{Review of probability theory}

\subsubsection{Review of basic probability distributions}
\begin{multicols}{2}
\input{cs_1_probability}
\end{multicols}

\newpage

\subsection{Descriptive statistics}

\subsubsection{Basic notions}
\input{cs_2a_basics}

\newpage

\begin{multicols}{2}

\subsubsection{Measures of location: central tendency}
\input{cs_2b_measures_central}

\vfill
\columnbreak

\subsubsection{Measures of location: position}
\input{cs_2c_measures_position}

\subsubsection{Measures of dispersion}
\input{cs_2d_measures_dispersion}

\subsubsection{Measures of shape}
\input{cs_2e_measures_shape}

\end{multicols}

\newpage

\subsection{Inferential statistics}

\subsubsection{Basics, more on probability distributions}

\begin{multicols}{2}
\input{cs_3_probability_adv}
\end{multicols}

\newpage

\subsubsection{Point estimation}

\begin{multicols}{2}
\input{cs_4_estim_point}
\end{multicols}

\newpage

\subsubsection{Interval estimation}

\begin{multicols}{2}
\input{cs_5a_estim_interval}
\end{multicols}

\subsubsection{Selected confidence intervals}

\begin{multicols}{3}
\input{cs_5b_estim_interval_example}
\end{multicols}

\subsubsection{Planning experiments}

\begin{multicols}{2}
\input{cs_6_planning}
\end{multicols}

\newpage

\subsubsection{Hypothesis testing}

\begin{multicols}{2}
\input{cs_7a_tests}
\end{multicols}

\newpage

\subsubsection{Selected parametric tests}

\begin{multicols}{2}
\input{cs_7b_tests_parametric_example}
\end{multicols}

\newpage

\subsubsection{Advanced hypothesis testing}

\begin{multicols}{2}
\input{cs_7c_tests_adv}
\end{multicols}

\subsubsection{Selected non-parametric tests}

\begin{multicols}{2}
\input{cs_7d_tests_nonparam_example}
\end{multicols}

\newpage

\subsubsection{Linear regression}

\begin{multicols}{2}
\input{cs_8_regression}
\end{multicols}

\newpage

\hspace{0pt}

\newpage

\thispagestyle{empty}

\section{Formulas for the exam}

\section*{Formulas: confidence intervals}
\begin{multicols}{3}
\input{cs_5b_estim_interval_example}
\end{multicols}

\section*{Formulas: non-parametric tests}
\begin{multicols}{2}
\input{cs_7d_tests_nonparam_example}
\end{multicols}

\newpage

\thispagestyle{empty}

\section*{Formulas: parametric tests}
\begin{multicols}{2}
\input{cs_7b_tests_parametric_example}
\end{multicols}

\newpage

\section{Sources, references}

If you find any mistakes, please send message to \url{bysiekm {at} student.mini.pw.edu.pl}

\vspace{10pt} \noindent Thanks to\ldots
\begin{itemize}
  \item P. Grzegorzewski and M. Gągolewski, for this whole theory and formulas
  \item group AP, for many of the formulas
  \item Karo, for notes
  \item lots of other people, for suggestions, corrections, etc.
  \item Wikipedia
\end{itemize}

\end{document}


\documentclass{article}

% the purpose of this particular document is to serve as a staging area potential blog posts, for the purpose of editing, revision, and review.

% packages
	\usepackage{amsmath, amsthm, mathtools}
	\usepackage{mdframed}
	\usepackage{geometry, enumerate}
	\usepackage{parskip}
	\usepackage{graphicx}

% theorems and such
  	\newtheorem{theorem}{Theorem}
  	\newtheorem{corollary}{Corollary}
  	\newtheorem{lemma}[theorem]{Lemma}
  	\newtheorem*{remark}{Remark}
  	\newtheorem*{exe}{Exercise}
  	\newtheorem{prop}{Proposition}
  	\newtheorem{example}{Example}

% custom commands
	\newcommand{\ceil}[1]{\left \lceil #1 \right \rceil}
	\newcommand{\floor}[1]{\lfloor #1 \rfloor}
	\newcommand{\X}[1]{\, \text{mod} \, #1}
	\newcommand{\divv}{\,|\,}
	\newcommand{\GCD}[2]{GCD\,(#1, #2)}
	\newcommand{\LCM}[2]{LCM\,(#1, #2)}

\begin{document}

\title{Elementary Number Theory : \S 2}
\author{Henry Slayer $|$ University of California, Santa Cruz}
\date{}
\maketitle

\section*{Linear Diophantine Equations}
The Euclidean algorithm studies the relationships between numbers, comparing their parts, and measuring how two integers can be decomposed into smaller and smaller portions of themselves. This decomposition is governed by the greatest common divisor, which exists hand in hand with the least common multiple, as we have seen. Rising more or less naturally from the interplay between various integers, we encounter linear Diophantine equations. A linear Diophantine equation is an equation of the form
\[ax + by = c\]
For integers $a, b, c, x, y$. This probably isn't the first time that you've seen an equation of this form. It's really nothing more than a line in $\mathbf{R}^2$. However, our approach to these types of equations will likely be different from what's typically done in high school algebra or calculus courses. We are interested in three things
\begin{enumerate}[(i)]
\item Does $ax + by = c$ have integer solutions?
\item Provided it does, how do we find them?
\item Given (i) and (ii), can we generalize infinite families of integer solutions?
\end{enumerate}
The answer to the first question is a blunt consequence of divisibility, and our method of solution will give us direction for the latter two questions.

\subsubsection*{Solubility of Linear Diophantine Equations}
We find that solubility os $ax + by = c$ is a direct consequence of $\GCD{a}{b}$.
\begin{mdframed}
\begin{theorem}
Let $a, b, c, x, y$ be integers. Then, the equation $ax + by = c$ has integer solutions $(x, y)$ if and only if $\GCD{a}{b}\divv c$.
\end{theorem}
\begin{proof}
First, assume that $ax + by = c$ has an integer solution. By the properties of the greatest common divisor, $\GCD{a}{b}\divv ax$, $\GCD{a}{b}\divv by$, and so $\GCD{a}{b}$ must also divide $c$. \\
Conversely, suppose that $\GCD{a}{b}\divv c$. In the penultimate line of Euclid's algorithm, when performed on $a$ and $b$, we will obtain something that looks like
\[r_i = q_{i+1}(r_{i+1}) + \GCD{a}{b}\]
Pulling the quotient to one side, we obtain
\[r_i = q_{i+1}(r_{i+1}) = \GCD{a}{b}\]
Now, the left-hand side of the equation above, through the iterative process of back-substitution, can bring us back to a linear combination of our initial values $a$ and $b$ (as we will show in a subsequent example). Thus, for integers $x_0, y_0$,
\[ax_0 + by_0 = \GCD{a}{b}\]
As $\GCD{a}{b}\divv c$, this equation can be scaled to
\[ax + by = c\]
for integers $x$ and $y$.
\end{proof}
\end{mdframed}
The converse of the theorem above suggests a method for finding a particular solution to linear diophantine equations. This method is effective, and we do most of the work in the beginning, when we're seeking to determine if $c$ is a multiple of the greatest common divisor.
\begin{mdframed}
\begin{example}
Does $763x + 129y = 1$ have integer solutions? If so, find a particular solution $(x, y)$.
\end{example}
\begin{proof}
We know that this equation will have integer solutions if 1 is a multiple of the greatest common divisor of 763 and 129. In this case, then, the greatest common divisor must be 1. So, we proceed by Euclid's algorithm.
\begin{align}
763 &= 5(129) + 118 \\
129 &= 1(118) + 11 \\
118 &= 10(11) + 8 \\
11 &= 1(8) + 3 \\
8 &= 2(3) + 2 \\
3 &= 1(2) + 1\\
2 &= 2(1) + 0
\end{align}
The second-to-last line tells us that 763 and 129 have a greatest common divisor of 1, which means that we can find integer solutions for the equation above. To find a particular solution, all that we need to do is reverse the Euclidean algorithm, working our way back up by reverse-substitution. Because Euclid's algorithm gives us a system of equations, we can 'look up' to the line above, and make substitutions to bring ourselves closer to our initial values of $a$ and $b$. Starting with the final line:
\begin{align*}
1 &= 3 - 2(1) \\
 &= 3 - (8 - 2(3)) = 3(3) - 8 \qquad \quad \textit{by line 5} \\
 &= 3(11 - 8) - 8 = 3(11) - 4(8) \qquad \quad \textit{by line 4} \\
 &= 3(11) - 4(118 - 10(11)) = 43(11) - 4(118) \qquad \textit{by line 3}  \\
 &= 43(129 - 118) - 4(118) = 34(129) - 47(118) \qquad \textit{by line 2}\\
 &= 43(129) - 47(763 - 5(129)) \qquad \quad \textit{by line 1} \\
 &= 278(129) - 47(763)
\end{align*}
So, our particular solution to the equation $736x + 129y = 1$ is $(-47, 278)$.
\end{proof}
\end{mdframed}
This method is extremely effective for finding particular solutions to linear diophantine equations. However, the bookkeeping can certainly get a bit tangled, and it's easy to get lost in the line-by-line calculations. Be sure to check your work along the way.

\subsubsection*{Families of Solutions}
So, we've determined that $ax + by = c$ is solvable, and we've found some integral solution $(x_0, y_0)$, all thanks to the Euclidean algorithm. To characterize \textit{all} solutions to a given linear diophantine equation, we turn our attention towards a clever use of \textit{homogeneous} linear diophantine equations, which look like
\[ax + by = 0\]
So, suppose that $ax + by = c$ is satisfied by a particular solution $(x_0, y_0)$. If we consider $x$ and $y$ to be 'general solution' terms, it follows, then, that
\[ax + by = ax_0 + by_0 = c\]
Which, in turn, means that
\[a(x-x_0) + b(y - y_0) = 0\]
\[a(x-x_0) = - b(y - y_0)\]
We interpret this equality to generate 'solution sets' for the linear diophantine form $ax +by = c$, provided that it is solvable. We'll prove the general case for one term, and the second follows by symmetry. \\
Because we have equality above, we know that $-b(y-y_0)$ must be a multiple of the $\LCM{a}{b}$. So, assume then that
\[a(x - x_0) = n \cdot \LCM{a}{b} \]
Which means
\[x = x_0 + \frac{n\cdot\LCM{a}{b}}{a}\]
Furthermore, the $GCD/LCM$ product formula tells us that $\frac{\LCM{a}{b}}{a} = \frac{b}{\GCD{a}{b}}$. So, given $ax + by = c$, and a particular solution $(x_0, y_0)$, we can generate all solutions for $x$ by
\[x = x_0 + \frac{n\cdot b}{\GCD{a}{b}}\]
A similar argument justifies the following for $y$
\[y = y_0 - \frac{n\cdot a}{\GCD{a}{b}}\]
Where the sign has been flipped, and $n$ is the same $n$ as above (as $a(x-x_0) = -b(y - y_0) = n \cdot \LCM{a}{b}.$
\begin{mdframed}
\begin{theorem}
Let $a, b, c, x, y$ be integers. Then, the equation $ax + by = c$ has integer solutions when $\GCD{a}{b}\divv c$. Based on a particular solution $(x_0, y_0)$, all solutions to this equation can be generated by
\[x = x_0 + \frac{n\cdot b}{\GCD{a}{b}}, \qquad y = y_0 - \frac{n\cdot a}{\GCD{a}{b}}\]
\end{theorem}
\end{mdframed}
Writing these expressions in terms of the $GCD$ is more out of preference rather than necessity. The $GCD$ arises naturally when we perform the Euclidean algorithm, and so it's favorable to capitalize on this construction's computational convenience.\\\\ We can extend our study of linear diophantine equations into three variables (and more!). The process is mostly the same, so we will simply conclude this section with an example.

\subsubsection*{Linear Diophantine Equations in 3 Variables}
Extending into a 3-variable case can be a bit tricky. For equations of the form $ax + by + cz = d$, we need to work in parts, solving for pariwise sub-relationships that tie the three-variable dynamic together. \\
\begin{mdframed}
\begin{example}
Let $x, y, z$ be integers. Characterize all integer solutions to the equation $3x + 5y + 4z = 9$, if such integer solutions exist.
\end{example}
\begin{proof}
The first thing that we want to do is ensure that the $GCD(a, b, c)$ is a divisor of 9. A quick look tells us that because 3 and 5 are prime, they share no common divisors, and neither divide 4. Thus, the three values are pairwise coprime, which means that $GCD(a, b, c) = 1$, and 1 certainly divides 9. So, we know that solutions certainly exist. In order to solve this equation, we're going to want to break it down into two smaller systems. We start by taking a look at $3x + 5y$. We know from solving two-variable LDE's that this linear combination will give us compound moves that are multiples of $\GCD{a}{b}$. So, we start by solving this subsystem for $\GCD{3}{5} = 1$. We find (and the reader should be sure to check) that $(2, -1)$ is a particular solution to $3x + 5y = 1$, which means that if $3x + 5y = v$, $x$ and $y$ will be characterized by $(2v, -v)$. So, we store that information for later. It will come in handy. \\
Now that we've established a connection between 3 and 5, we can use that 'common ratio' back in our original equation, which becomes
\[v + 4z = 9\]
A quick glance tells us that $(1, 2)$ is a particular $(v, z)$ solution, which implies that
\[v = 1 + 4n, \qquad z = 2 - n\]
Are our general solutions, which we obtained from the theorem proved earlier. Translating $v$ into the language of $x$ and $y$ by what we had previously established,
\[x = 2v = 2 + 8n, \quad y = -v = -1 -4n, \quad z = 2 - n\]
And so, we've obtained general sets of solutions for $3x + 5y + 4z = 9$, by first solving a smaller linear relationship, which we then used as a placeholder to shed light on the larger linear dynamics at play.
\end{proof}
\end{mdframed}
\end{document}


\section{The discretization of spatial differential operators}

\begin{myDef}[Conservative Operator]
For...
\begin{packed_itemize}
  \item a list of \emph{domain variables}, $U := (u_0,\cdots,u_{\Lambda-1}) \in \ceins(\Omega)^\Lambda$ and
  \item a list of \emph{codomain variables}, $W := (w_0,\cdots,w_{\Gamma-1}) \in L^2(\Omega)^\Gamma$
\end{packed_itemize}
a mapping
\[
Op:\ceins(\Omega)^\Lambda \rightarrow L^2(\Omega)^\Gamma, \ U \mapsto W = Op(U)
\]
is called \emph{conservative operator} if
every codomain variable $w_\gamma$ can be written as
\[
  w_\gamma = \divergence{ \vec{f}_\gamma(\vec{x},U) } + q_\gamma(\vec{x},U).
\]
The functions
\begin{packed_itemize}
 \item $ \vec{f}_\gamma(\vec{x},U) \in \left( \ceins (\real^D \times \real^\Lambda) \right)^D$
      are called the flux and
 \item $  q_\gamma(\vec{x},U) \in L^2(\real^D \times \real^\Lambda)$
      are called the source
\end{packed_itemize}
of codomain variable $w_\gamma$.
\label{ConservativeOp}
\end{myDef}

\begin{myNot}[Outer normal]
For $\vec{x} \in \partial K_j$, $\vec{n}_\vec{x} \in \partial \mathcal{S}_D$ denotes an outer normal
field for $K_{\tau(j)}$, for
those points of $\partial K$ where an outer normal is defined, which may not be the case
for a null-subset of $\partial K$
i.e. ``edges'' and ``corners''.
\end{myNot}

\begin{myDef}[Conservative operators on product spaces of $DG_p$]
Again, like in (\ref{ConservativeOp}), there is
a list of domain variables,
$U := (u_0,\cdots,u_{\Lambda-1}) \in DG_{(p_0, \cdots, p_{\Lambda-1})} =: Dom$
and a list of codomain variables
$W := (w_0,\cdots,w_{\Gamma-1}) \in DG_{(l_0, \cdots, l_{\Gamma-1})} =: Cod$.
A mapping
\[
 OP_h :
 DG_{p_0} \times \cdots \times DG_{p_{\Lambda-1}}
 \rightarrow
 DG_{l_0} \times \cdots \times DG_{l_{\Gamma-1}},
 \
 U \mapsto W = Op_h(U)
\]
is called a DG-discretization of the conservative operator $Op$
if the $n$-th DG coordinate of variable $w_\gamma$ in cell $K_{\tau(j)}$, $\tilde{w}_{\gamma,j,n}$
can be written as
\[
  \tilde{w}_{\gamma,j,n} =
  \int_{\partial K_{\tau(j)}}
       F_\delta \ \phi_{j,n}
  \ \textrm{dS}
  -
  \int_{K_{\tau(j)}} \left(
       \vec{f}_\gamma \cdot \nabla \phi_{j,n}
       -
       q_i \ \Phi_{j,n}
  \right) \ \textrm{d}\vec{x}
  .
\]
The function $F_\delta(\vec{x},U^\textrm{in},U^\textrm{out},\vec{n}_\vec{x})$ is called the \emph{Riemannian}
for the flux $\vec{f}_\gamma(\vec{x},U)$. Their properties are described in below, see (\ref{riemannians}).
Here, for $\vec{x} \in \partial K_{\tau(j)}$
\[
  U^\textrm{in} := \lim_{\stackrel{\vec{y} \rightarrow \vec{x}}{\vec{y} \in K_{\tau(j)}}}(U(\vec{y}))
  \textrm{ and }
  U^\textrm{out} := \lim_{\stackrel{\vec{y} \rightarrow \vec{x}}{\vec{y} \notin K_{\tau(j)}}}(U(\vec{y}))
  .
\]
By coordinate mappings, the conservative operator can be written as a mapping
\[
  Op_h: \real^{dim(Dom)} \rightarrow \real^{dim(Cod)}, \quad \tilde{U} \mapsto \tilde{W}.
\]
\label{ConservativeOp_h}
\end{myDef}

\begin{myRem}[On Riemannians]
The following properties are essential for proper defined Riemannians:
\begin{packed_itemize}
  \item $F_\gamma(\vec{x},U,U,\vec{n}_{\vec{x}}) = \vec{n}_{\vec{x}} \cdot \vec{f}_\gamma(\vec{x},U)$,
  i.e ``$F_\gamma$ is an approximation to $\vec{n}_{\vec{x}} \cdot \vec{f}_\gamma$''
  \item $F_\gamma(\vec{x},U,V,\vec{n}_{\vec{x}}) = -F_\gamma(\vec{x},V,U,-\vec{n}_{\vec{x}})$
  \item $\left| F_\gamma(\vec{x},U,V,\vec{n}_{\vec{x}}) - \vec{n}_{\vec{x}} \cdot \vec{f}_\gamma(\vec{x},U) \right| \leq L | U-V |$
  for some Lipschitz constant $L \in \realpos$
\end{packed_itemize}
\label{riemannians}
\end{myRem}

\begin{myDef}[Consistency of operators]
An operator $Op_h$ like in (\ref{ConservativeOp_h}) is called consistent
with an operator $Op$ like in (\ref{ConservativeOp}) with convergence
order $k$ if
\[
 \left\| Op_h(Proj_p(U)) - Proj_p( Op(U) ) \right\|_2 \leq h_\textrm{max}^k \cdot c(U)
\]
for any $U \in \ceins(\Omega)^\Lambda$ and a constant $c(U) \in \realpos$ which depends on $U$.
\label{consistency_of_operators}
\end{myDef}

\begin{myRem}
The motivation for (\ref{consistency_of_operators}) is the
following ``approximately'' commutative diagram:
%\begin{center}
\[
\begin{xy}
  \xymatrix{
      H^1(\Omega)^\Lambda \ar[r]^{Op} \ar[d]_{Proj}  &   (L^2(\Omega))^\Gamma  \ar[d]^{Proj}  \\
      \prod_\delta DG_{p_\delta} \ar[r]_{Op_h}       &  \prod_\gamma DG_{l_\gamma}
  }
\end{xy}
% ----------------------------------------#
\quad
\begin{xy}
  \xymatrix{
      U \ar@{|->}[rrrr]^{Op} \ar@{|->}[d]_{Proj} & &             &          &  W  \ar@{|->}[d]^{Proj}  \\
      U_h \ar@{|->}[rr]_{Op_h}                   & &  Op_h(U_h)  &  \approx &  W_h
  }
\end{xy}
\]
(Here, $Proj$ is an abbreviation for
$( Proj_{p_0}, \cdots, Proj_{p_{\Lambda-1}} )$
and
$( Proj_{l_0}, \cdots, Proj_{l_{\Gamma-1}} )$.
\end{myRem}

\begin{myRem}[Additive component decomposition of conservative operators in BoSSS]
In BoSSS, a conservative operator is called
\emph{spatial difference operator}\coderm{BoSSS.Foundation.SpatialDifferenceOperator}
and is specified as an additive composition of operators, which are called
\emph{equation components}\coderm{BoSSS.Foundation.IEquationComponent}.
The domain and codomain variables for the  spatial difference operator, are specified as lists
of symbolic names\coderm{BoSSS.Foundation.SpatialDifferentialOperator.DomainVar} \coderm{BoSSS.Foundation.SpatialDifferentialOperator.CodomainVar}.
Each equation component itself is a conservative operator with exactly one codomain variable,
i.e. it maps $\prod_\delta DG_{p_\gamma} \rightarrow DG_l$.
The domain variables of the equation components are specified as some
sub-list\coderm{BoSSS.Foundation.IEquationComponent.ArgumentOrdering}
of the domain variables list of the spatial difference operator.
The equation components may be classified into \emph{fluxes} and \emph{sources},
and wether they are either \emph{linear} or \emph{nonlinear}:
\begin{packed_itemize}
  \item nonlinear fluxes\coderm{BoSSS.Foundation.INonlinearFlux},\coderm{BoSSS.Foundation.INonlinearFluxEx};
  \item nonlinear sources\coderm{BoSSS.Foundation.INonlinearSource};
  \item linear fluxes\coderm{BoSSS.Foundation.ILinearFlux};
  \item linear sources\coderm{BoSSS.Foundation.ILinearSource};
\end{packed_itemize}
If more than one equation component is specified for one codomain variable, they are
added\coderm{BoSSS.Foundation.SpatialDifferentialOperator.EquationComponents}.
\end{myRem}

\begin{myRem}[Evaluation of conservative operators in BoSSS]
A conservative operator, or spatial differential operator $Op_h$ can be evaluated
in BoSSS
by\coderm{BoSSS.Foundation.SpatialDifferentialOperator.Evaluate(...)}
or\coderm{BoSSS.Foundation.SpatialDifferentialOperator.Evaluator.Evaluate(...)}.
If $Op_h$ is affine-linear, i.e.
\[
  Op_h(\tilde{U}) = \mathcal{M} \cdot \tilde{U} + b,
\]
the (sparse) matrix $\mathcal{M}$ and the affine vector $b$ can
be computed
by\coderm{BoSSS.Foundation.SpatialDifferentialOperator.ComputeMatrix(...)}.
\end{myRem}

%\subsection{Nonlinear fluxes}

%\subsection{Nonlinear sources}

%\subsection{Linear sources}

%\subsection{Fluxes for Interior Penalty Methods}


%!TEX root = morusAC.tex

\section{Trail for Full \MORUS}
\label{sec/fulltrails}

In the previous section, we presented a linear trail for the reduced ciphers \MiniMORUS[1280] and \MiniMORUS[640]. We now turn to the full ciphers \MORUS[1280] and \MORUS[640].

\subsection{Symmetrizing the Trail}
In order to build a trail for the full \MORUS, we proceed exactly as we did for \MiniMORUS, following the same path down to step and word rotation values, with one difference: in order to move from the one-word registers of \MiniMORUS to the four-word registers of full \MORUS, we make every term $S^t_{i,j}$ and $C^t_j$ symmetric, in the sense of \Cref{sec/introminimorus}.
That is, for every $S^t_{i,j}$ (resp. $C^t_j$) component in every trail fragment and every equation, we \emph{symmetrize} the term by adding in the terms $S^t_{i,j+w}$, $S^t_{i,j+2w}$, $S^t_{i,j+3w}$ (resp. $C^t_{j+w}$, $C^t_{j+2w}$, $C^t_{j+3w}$), where as usual $w$ denotes the word size. For example, if $w=64$ (for \MORUS[1280]), the term $S^3_{2,0}$ is symmetrized into:
\[
S^3_{2,0} \oplus S^3_{2,64} \oplus S^3_{2,128} \oplus S^3_{2,192}.
\]

Thus, translating the trail from one of the \MiniMORUS ciphers to the corresponding full \MORUS cipher amounts to making every linear combination symmetric---indeed, that was the point of introducing \MiniMORUS in the first place.
Concretely, in order to build the full trail equation for \MORUS, we write symmetric versions of equations $A^t_i$, $B^t_i$, $C^t_i$, $D^t_i$, $E^t_i$ from \Cref{sec:minitraileq}, and then combine them in exactly the same manner as before.
This way, the biased linear combination on \MiniMORUS[1280] given in \Cref{sec:minitraileq}, namely:
\begin{align*}
&C^0_{51} \oplus C^1_{0} \oplus C^1_{25} \oplus C^1_{33} \oplus C^1_{55} \oplus C^2_{4} \oplus C^2_{7} \oplus C^2_{29} \oplus C^2_{37}\\
\oplus\; &C^2_{38} \oplus C^2_{46} \oplus C^2_{51} \oplus C^3_{11} \oplus C^3_{20} \oplus C^3_{42} \oplus C^3_{50} \oplus C^4_{24}
\end{align*}
ultimately yields the following biased symmetrized linear combination on the full \MORUS[1280]:
\begin{align*}
&C^0_{51} \oplus C^0_{115} \oplus C^0_{179} \oplus C^0_{243} \oplus C^1_{0} \oplus C^1_{25} \oplus C^1_{33} \oplus C^1_{55} \oplus C^1_{64} \oplus C^1_{89}\\
\oplus\; & C^1_{97} \oplus C^1_{119} \oplus C^1_{128} \oplus C^1_{153} \oplus C^1_{161} \oplus C^1_{183} \oplus C^1_{192} \oplus C^1_{217} \oplus C^1_{225} \oplus C^1_{247}\\
\oplus\; & C^2_{4} \oplus C^2_{7} \oplus C^2_{29} \oplus C^2_{37} \oplus C^2_{38} \oplus C^2_{46} \oplus C^2_{51} \oplus C^2_{68} \oplus C^2_{71} \oplus C^2_{93}\\
\oplus\; & C^2_{101} \oplus C^2_{102} \oplus C^2_{110} \oplus C^2_{115} \oplus C^2_{132} \oplus C^2_{135} \oplus C^2_{157} \oplus C^2_{165} \oplus C^2_{166} \oplus C^2_{174}\\
\oplus\; & C^2_{179} \oplus C^2_{196} \oplus C^2_{199} \oplus C^2_{221} \oplus C^2_{229} \oplus C^2_{230} \oplus C^2_{238} \oplus C^2_{243} \oplus C^3_{11} \oplus C^3_{20}\\
\oplus\; & C^3_{42} \oplus C^3_{50} \oplus C^3_{75} \oplus C^3_{84} \oplus C^3_{106} \oplus C^3_{114} \oplus C^3_{139} \oplus C^3_{148} \oplus C^3_{170} \oplus C^3_{178}\\
\oplus\; & C^3_{203} \oplus C^3_{212} \oplus C^3_{234} \oplus C^3_{242} \oplus C^4_{24} \oplus C^4_{88} \oplus C^4_{152} \oplus C^4_{216}
\end{align*}
We refer the reader to \Cref{sec:traileq} for the corresponding linear combination on \MORUS[640].

\subsection{Correlation of the Full Trail}

The symmetrized trail on full \MORUS may be intuitively understood as consisting of four copies of the original trail on \MiniMORUS. Indeed, the only difference between full \MORUS (for either version of \MORUS) and four independent copies of \MiniMORUS comes from register-wise rotations, which permute words within a register. But as observed in \Cref{sec/introminimorus}, register-wise rotations leave symmetric linear combinations invariant; and so, insofar as we only ever use symmetric linear combinations on all registers along the trail, register-wise rotations have no effect.

Following the previous intuition, one may expect that the weight of the symmetrized trail should simply be four times the weight of the corresponding \MiniMORUS trail, namely 64 for both \MORUS[1280] and \MORUS[640]. However, reality is a little more complex, as the symmetrized trail does not exactly behave as four copies of the original trail when one considers nonlinear terms.

To understand why that might be the case, assume a nonlinear term $S^0_{2,0} \cdot S^0_{3,0}$ arising from some part of the trail, and another term $S^0_{2,0} \cdot S^0_{3,w}$ arising from a different part of the trail (where $w$ denotes the word size). Then when we XOR the various trail fragments together, in \MiniMORUS these two terms are actually equal and will cancel out, since register-wise rotations by multiples of $w$ bits are ignored. However in the real \MORUS these terms are of course distinct and do not cancel each other.

In the actual trail for (either version of) full \MORUS, this exact situation occurs when combining trail fragments $\beta^t_i$ and $\gamma^t_i$. Indeed, $\beta^t_i$ requires approximating the term $S^t_{2,i} \cdot S^t_{3,i}$, while $\gamma^t_i$ requires approximating the term $S^t_{2,i} \cdot S^t_{3,i-w}$ (cf. \Cref{fig:trailcollision}). While in \MiniMORUS, these terms cancel out, in the full \MORUS, when adding all symmetric copies of the trail, we end up with the sum:
{
\allowdisplaybreaks[0]
\begin{align}
&S^t_{2,i} \cdot S^t_{3,i} \oplus S^t_{3,i} \cdot S^t_{2,i+w}
\oplus S^t_{2,i+w} \cdot S^t_{3,i+w} \oplus S^t_{3,i+w} \cdot S^t_{2,i+2w}\notag\\
\oplus\; &S^t_{2,i+2w} \cdot S^t_{3,i+2w} \oplus S^t_{3,i+2w} \cdot S^t_{2,i+3w}
\oplus S^t_{2,i+3w} \cdot S^t_{3,i+3w} \oplus S^t_{3,i+3w} \cdot S^t_{2,i}.\label{eq:8circle}
\end{align}
}
It may be observed that the products occurring in the equation above involve eight terms forming a ring. The weight of this expression can be computed by brute force, and is equal to $3$.

\begin{figure}[t!]
  \substatesfalse
  % \substatesfalse to label state words and/or masks
  \centering
  \begin{subfigure}{.4\textwidth}
  \centering
  \begin{tikzpicture}[xscale=0.75,yscale=1.5]%{{{
    \printstate
    \draw[trail, beta]
      (C) -- node[right] {$i$} (lll-1)
      (lll-1) -- (tlll-1) (lll-1) -- (xor-1) (xor-1) -- (xnd-1)
      (tlll-1) -- (W-20) node[above] {$i$}
      (xor-1) -- (txor-1) %(txor-1) -- (W-21) node[above] {$i$}
      %(xnd-1) -- (and-1)
      (W40) node[below] {\phantom{$i$}}
      ;
    \draw[trail, gamma]
      %(W-21) node[above] {$i$}
      (txor-1) -- (xnd1)
      (xnd1) -- (xor1) (xor1) -- (lll1)
      %(xnd1) -- (and1)
      (xor1) -- (txor1)
      (txor1) -- (W-24) node[above] {$i$}
      (lll1) -- (W41) node[below] {$i+b_1$}
      ;
    %\draw[trail, beta,  dotted] (and-1) -- (and-1-|and1);
    %\draw[trail, gamma, dotted] (and1)  -- (and-1-|and1) node[above, black] {=};
    \node (eq) at ($(and-1|-and1)+(-1,-2.4pt)$) {=};
    \draw[beta,{Circle[sep=-1.8pt]}-]  ($(and-1)+(0,-2.4pt)$) -| (eq);
    \draw[gamma,{Circle[sep=-1.8pt]}-] ($(and1)+(0,-2.4pt)$) -- (eq);
  \end{tikzpicture}%}}}
  \caption*{\MiniMORUS: weight 0 (not 2)} %$S^{j,1}_i, S^{j,4}_i, S^{j+1,1}_{i-1}$ ($w\!=\!1$)}
  \end{subfigure}
  \qquad
  \begin{subfigure}{.4\textwidth}
  \centering
  \begin{tikzpicture}[xscale=0.75,yscale=1.5]%{{{
    \printstate
    \draw[trail, beta]
      (C) -- node[right] {$i$} (lll-1)
      (lll-1) -- (tlll-1) (lll-1) -- (xor-1) (xor-1) -- (xnd-1)
      (tlll-1) -- (W-20) node[above] {$i$}
      (xor-1) -- (txor-1) %(txor-1) -- (W-21) node[above] {$i$}
      (xnd-1) -- (and-1)
      (W40) node[below] {\phantom{$i$}}
      ;
    \draw[trail, gamma]
      %(W-21) node[above] {$i$}
      (txor-1) -- (xnd1)
      (xnd1) -- (xor1) (xor1) -- (lll1)
      (xnd1) -- (and1)
      (xor1) -- (txor1)
      (txor1) -- (W-24) node[above] {$i$}
      (lll1) -- (W41) node[below] {$i+b_1$}
      ;
    \draw[trail, beta,  dashed] (and-1.east|-tanB-1) -- (tanB-1);
    \draw[trail, gamma, dashed] (tanB-1)  -- (tanB1) -- (tanB1-|and1.east);
  \end{tikzpicture}%}}}
  \caption*{\MORUS: weight $4 \times 1$ (not $4 \times 2$)} %$S^{j,1}_i, S^{j,4}_i, S^{j+1,1}_{i-1}$ ($w\!=\!1$)}
  \end{subfigure}
  \caption{Weight of $\beta^t_i \oplus \gamma^t_i$ for \MiniMORUS and \MORUS.}
  \label{fig:trailcollision}
\end{figure}

For \MORUS[1280], since the trail fragment $\gamma^t_i$ is used four times, this phenomenon adds a contribution of $4 \cdot 3 = 12$ to the overall weight of the full trail. This results in a total weight of $4 \cdot 16 + 12 = 76$ (recall that the weight of the trail on \MiniMORUS[1280] is 16). We have confirmed this by explicitly computing the full trail equation in \Cref{sec:traileq}, and evaluating its exact weight like we did for \MiniMORUS in \Cref{sec:minibias}. That is, since the equation is quadratic, we may view it as a graph, which we split into connected components; we then compute the weight of each connected component separately by brute force, and then add up the weights of all components per the Piling-Up Lemma. Overall, the full trail equation given in \Cref{sec:traileq} yields a weight of 76 for the full trail on \MORUS[1280].

In the case of \MORUS[640], collisions between rotation constants further complicate the analysis. Specifically, when using trail fragment $\beta^t_i$, the term $S^t_{2,i} \cdot S^t_{3,i}$ occurs. As explained previously, a partial collision with the term $S^t_{2,i} \cdot S^t_{3,i-w}$ from trail fragment $\gamma^t_i$ results in \Cref{eq:8circle}. However trail fragment $\alpha^t_{i+d}$ is once used in the course of the full trail with an offset of $d = b_1+b_4-b_0-b_2$ (relative to $\gamma^t_i$), which in the case of \MORUS[640] is equal to $31+13-5-7 = 0 \;\text{mod}\; 32$. This creates another term $S^t_{2,i} \cdot S^t_{3,i}$, which ultimately destroys one of the four occurrences of \Cref{eq:8circle}. Therefore, when computing the full trail equation on \MORUS[640], we get that the weight of the trail is 73 (cf. \Cref{sec:traileq}).

%TODO: check $\alpha_i \oplus \beta_i \oplus \gamma_i$ in step 2 of $\cipher{MORUS-640}$
%(maybe not relevant due to overall complexity\dots)

\subsection{Taking Variable Plaintext into Account}
\label{subsec:variable}

In our analysis so far, for the sake of simplicity, we have assumed that all plaintext blocks are zero. We now examine what happens if we remove that assumption, and integrate plaintext variables into our analysis. What we show is that plaintext variables only contribute linearly to the trail. In other words, the full trail equation with plaintext variables is equal to the full trail equation with all-zero plaintext XORed with a linear combination of plaintext variables.

To see this, recall that plaintext bits contribute to the encryption process in two ways (cf. \Cref{subsec/Spec}):
\begin{enumerate}
\item They are added to some bits derived from the state to form the ciphertext.\label{item:1}
\item During each encryption step, the \StateUpdate{} function adds a plaintext block to every register except $S_0$.\label{item:2}
\end{enumerate}

The effect of \Cref{item:1} is that whenever we use a ciphertext bit in our full trail equation, the corresponding plaintext bit also needs to be XORed in. Because ciphertext bits only contribute linearly to the trail equation, this only adds a linear combination of plaintext bits to the equation.

Regarding \Cref{item:2}, recall that the full trail equation is a linear combination of (the symmetrized version of) equations $A^t_i$, $B^t_i$, $C^t_i$, $D^t_i$, $E^t_i$ in \Cref{sec:minitraileq}. Also observe that in each equation, state bits that are shifted by a word-wise rotation only contribute linearly. Because plaintext bits are XORed into each register at the same time word-wise rotation is performed, this implies that plaintext bits resulting from \Cref{item:2} also only contribute linearly.
In fact in all cases, it so happens that updating the equation to take plaintext variables into account simply involves XORing in the plaintext bit $M^t_i$.

It may be observed that message blocks in the \StateUpdate{} function only contribute linearly to the state, and in that regard play a role similar to key bits in an SPN cipher; and indeed in SPN ciphers, it is the case that key bits contribute linearly to linear trails \cite{eurocryptMatsui93}. In this light the previous result may not be surprising.

In the end, with variable plaintext, our trail yields a biased linear combination of ciphertext bits and plaintext bits.
In regards to attacks, this means the situation is effectively the same as with a biased stream cipher: in particular if the plaintext is known we obtain a distinguisher; and if a fixed unknown plaintext is encrypted multiple times (possibly also with some known variable part) then our trail yields a plaintext recovery attack.

%%% Local Variables:
%%% TeX-master: "morusAC"
%%% End:


\documentclass{beamer}
\usefonttheme[onlymath]{serif}
\usepackage[english]{babel}							%For internationalization
\usepackage[utf8]{inputenc}							%For character encoding
\usepackage{amsmath}								%For mathematical typesetting
\usepackage{amssymb}								%For mathematical typesetting
\usepackage{graphicx}								%For handling graphics

\newcommand{\be}{\begin{equation}}
\newcommand{\bea}{\begin{equation*}}
\newcommand{\ben}[1]{\begin{equation}\label{#1}}
\newcommand{\ee}{\end{equation}}
\newcommand{\eea}{\end{equation*}}
\newcommand{\aq}{\overset{\sim}{q}}

\mathchardef\mhyphen="2D

\title
{An Introduction to Discontinuous Galerkin Methods}
\subtitle{Module 3B: To Higher-Orders - Discrete System}
\author[Bevan]
{J.~Bevan}
\institute[UMass Lowell]
{
  Department of Mechanical Engineering, Grad Student\\
  University of Massachusetts at Lowell
}
\date[Fall 2014]
{}
\subject{Discontinuous Galerkin}

\begin{document}
\frame{\titlepage}
\frame{\frametitle{Module 3B: To Higher-Orders - Discrete System}\tableofcontents}

%NEW SECTION
\section{Numerical Quadrature (Gauss)}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We now have a method for generating a robust arbitrary order solution approximation, but unlike before it isn't practical to analytically pre-calculate all the integrals.
\item We can use a numerical quadrature technique to do this instead, able to integrate arbitrary functions
\item If we call the interpolation of a function $In f$ then we assume that for a sufficiently accurate interpolation, we can use the interpolation of the function wherever we could use the function itself before. This is in general M-1 order accurate.
\be f \approx In f =\sum_{i=0}^M f(x_i)L_i(x) \ee
\end{itemize}
\be \int f \approx \int In f = \int \sum_{i=0}^M f(x_i)L_i(x) =  \sum_{i=0}^M f(x_i) \int L_i(x) =  \sum_{i=0}^M f(x_i)w_i\ee
}

%NEW SECTION
\section{Hermite Interpolation (and quadrature)}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item Recall: Hermite interpolation includes derivatives of interpolated function as well
\item Consider a Hermite interpolation polynomial that includes first derivatives as well, the interpolation would be $2M-1$ accurate. The quadrature using this polynomial would look like:
\be \int f \, dx \approx \sum_{i=0}^M f(x_i)w_i+\sum_{i=0}^M\left[ f'(x_i)\int (x-x_i)L_i^2(x) \, dx \right] \ee
\item It turns out if we choose our quadrature/interpolation points to be the Legendre roots, the integral for the second term is zero. Thus no first derivative terms are needed for the Hermite quadrature, even though it is $2M-1$ order accurate.
\end{itemize}
}

%NEW SECTION
\section{Truncation error/exact quadrature}
\frame[shrink]{\frametitle{\textbf{\secname}}
\begin{itemize}
\item It is important to consider error sources from the approximation to the solution and integrals, these can affect convergence
\item Three main error sources in quadrature: aliasing, truncation, and inexact quadrature
\item Aliasing occurs if the function is not sampled frequently enough, it is assumed that the sol'n is sufficiently smooth and the discretization suitably fine to avoid this in most cases
\item Truncation is unavoidable except where the exact function is of equal or lesser order than the interpolation/quadrature. Higher order terms present in the exact function are left off.
\item Inexact quadrature occurs when the total polynomial order of the product of the interpolated functions undergoing quadrature exceeds the exactness of the quadrature. For Gauss-Legendre quadrature this isn't a problem for one and even two functions in the integrand. Each function is of order M-1 and the quadrature is exact for 2M-1, so the quadrature is able to exactly integrate the interpolation
\end{itemize}
}

%NEW SECTION
\section{GL Lagrange Orthogonality}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item A final useful property of the Lagrange basis with Legendre interpolation points is orthogonality
\item The product of two $M-1$ order Lagrange bases can be rearranged to be a Legendre poly of order $M$ and a remainder polynomial of order $M-2$
\item The remainder polynomial can be expressed as a linear combination of Legendre polys all of order $<M$, all are orthogonal to the order $M$ Legendre, so
\be \int_{-1}^1 L_i(x)L_j(x) \,dx = \delta_{ij}w_i \ee
\end{itemize}
}

%NEW SECTION
\section{Local Mapping Function (Jacobian)}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item The domain of orthogonality for Legendre polynomials (and by extension GL Lagrange) is $[-1, 1]$
\item Elements may be arbitrary sizes though, we'd like to be able to transform $x \in [x_L, x_R] \rightarrow X \in [-1, 1]$ by means of a mapping $x=g(X)$ and it's inverse $X=G(x)$
\be x=g(X)=\frac{X+1}{2}\Delta x + x_L\quad ,\quad X=G(x)=\frac{2(x-x_L)}{\Delta x}+1 \ee
\item Applying a change of variables for the mapping
\be \int_{x_L}^{x_R} L_i(x) L_j(x) \,dx \rightarrow \int_{-1}^1 L_i(g(X))L_j(g(X)) g' \, dX \ee
\item $J=g'=\frac{\Delta x}{2}$ is called the determinant of the Jacobian matrix
\end{itemize}
}

%NEW SECTION
\section{Mass Matrix- Diagonalization}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We have done what seems like quite a bit of tangential work, but it now pays off
\be \sum_{i=0}^M \frac{d \aq_i}{dt} \int_k \psi_i(x) \phi_j(x) \,dx = \sum_{i=0}^M \frac{d \aq_i}{dt} \int_I L_i(X) L_j(X) \frac{\Delta x}{2} \,dX \ee
\be=   \frac{\Delta x}{2} \sum_{i=0}^M \frac{d q_i}{dt} \delta_{ij}w_i =  \frac{\Delta x}{2}q_j'w_j \quad for\,all\, j \ee
\item We've reduced the full mass matrix into a diagonal mass matrix with all other terms zero, compared to Module 2 solver case the mass matrix is trivially invertible. We have: $\frac{\Delta x}{2}\mathbf{q' \,M}$ where $\mathbf{M}_{jj} = w_j$
\end{itemize}
}

%NEW SECTION
\section{Log differentiation}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We can get a closed form expression for $L_j'(x)$ in the stiffness term by using logarithmic differentiation
\item The main idea is that in general $f'/f = ln(f)$ so applying this to our Lagrange basis
\be L_j'(x) = L_j \sum_{r=0,r\neq j}^N \frac{1}{x-x_r} \ee
\item using our previous function code for "\textit{Lag(x)}" we can get a general expression
\textit{dLag= @(x,nv) Lag(x,nv).*sum(1./bsxfun(@minus,x,nn(nv,:,:)),3)}
\item We need a more involved method for evaluation at the interp points (see dLagrange.m)
\end{itemize}
}

%NEW SECTION
\section{Stiffness Integral}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We now have a routine for calculating $L_j'$, and suitable quadrature; we can evaluate the stiffness integral
\be \int_k \, \sum_{i=0}^M\left[ c\aq_i \psi_i(x)\right] \phi'_j(x) \,dx = \sum_{i=0}^M c\aq_i \int_I L_i(X) L_j'(X) \,dX \ee
\item No Jacobian term from the mapping. The derivative in the integrand produces a complementary $1/J$ that cancels due to the change of variables.
\item No tricks to be had for reducing the stiffness matrix, it is a full matrix. We have: $c\mathbf{K}_{ji} \, \mathbf{\aq}$
\end{itemize}
}

%NEW SECTION
\section{Numerical Flux (Extrapolated)}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item One downside of using Gauss-Legendre points is there are no points on the boundary
\item It is easy to calculate the boundary solution values from the solution interpolation at the left end (same idea for the right)
\be \aq(x_L) = \sum_{i=0}^M \aq_i L_i(x_L) \ee
\item Call $L_i(x_L) = L_{iL}$, the vector notation is then $\aq_L = \mathbf{L}_{iL}^T \, \mathbf{\aq}$
\item So that our numerical flux vector is $\mathbf{\hat{f}} =c(\overset{k}{q}_R\mathbf{L}_{jR}-\overset{k-1}{q_R}\mathbf{L}_{jL})$
\item Lobatto alternative gives boundary points, but would make the mass matrix a full matrix. Inversion is likely more expensive than interpolation
\end{itemize}
}

%NEW SECTION
\section{Assembly of System}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We can now combine the mass, stiffness, and numerical flux terms
\be \frac{\Delta x}{2}\mathbf{q' \,M} + \mathbf{\hat{f}} -  c\mathbf{K}_{ji} \, \mathbf{\aq}=0 \ee
\item solving for $q'$
\be \mathbf{\aq}' = \frac{2}{\Delta x} (c\mathbf{K}_{ji} \, \mathbf{\aq} -\mathbf{\hat{f}}) \mathbf{M}^{-1} \ee
\item it is also possible to represent it componentwise easily thanks to the diagonal mass matrix
\be \aq_j' = \frac{2}{w_j\Delta x }(c \mathbf{K}_{j\mhyphen}\mathbf{\aq}-\hat{f}_j)\ee
\end{itemize}
}

%NEW SECTION
\section{RK4 Time discretization}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item Compared to the simple linear DG solver, we'd like to use a higher order time discretization, Runge-Kutta 4th order: RK4. We can express as a function: $\mathbf{\aq}'(\mathbf{\aq})$ from our discrete system. RK4 consists of 4 trial steps:

$k_1 =  \mathbf{\aq}'(\mathbf{\aq}) \, \Delta t$\\
$k_2 =  \mathbf{\aq}'(\mathbf{\aq}+\frac{k_1}{2}) \, \Delta t$\\
$k_3 =  \mathbf{\aq}'(\mathbf{\aq}+\frac{k_2}{2}) \, \Delta t$\\
$k_4 =  \mathbf{\aq}'(\mathbf{\aq}+k_3) \, \Delta t$\\
$\mathbf{q}(t+1) = \mathbf{q} + \frac{k_1}{6}+ \frac{k_2}{3}+ \frac{k_3}{3}+ \frac{k_4}{6}$
\end{itemize}
}

%NEW SECTION
\section{Investigate p-Convergence}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item How does the p-convergence rate compare with h-convergence?
\item Does the smoothness of the initial sol'n seem to effect the rate of convergence? (e.g. sin(x) vs gaussian curve)
\item Does h or p refinement seem to be more efficient?
\end{itemize}
}

\end{document}


\section{Introduction}

The interpretation of total-field anomalies on the surface of the Earth is an
important challenge in exploration geophysics due to the nonuniqueness of 3-D magnetic
inversion. It is well-known that several magnetization distributions in the subsurface
can reproduce the same magnetic data with the same accuracy.
To overcome this inherent ambiguity, a priori information needs to be introduced
for reducing the number of possible solutions that are coherent with the local geology.
The available a priori information determines the suitable inversion method to be applied.
As explained below, we identified, in the literature, three groups of 3-D magnetic inversion methods.

The first group of inverse methods approximates the source by a geometrically
simple causative body having its geometry defined by a small number of parameters
\cite[e.g., ][]{ballantyne-1980,bhattacharyya-1980,silva-1983,medeiros_silva1995}. These methods
estimate both the geometry and the physical property of the source by solving
a nonlinear inverse problem. Due to the very restrictive parametrization,
such methods usually do not have severe problems with ambiguity.

The second group of inverse methods is formed by the vast majority of methods.
These methods approximate the subsurface by a grid of juxtaposed rectangular prisms having
a constant total-magnetization direction. Some methods presume a purely induced
magnetization and the isotropic magnetic susceptibility of the prisms is the quantity estimated by solving a linear inverse problem.
Some examples of this linear inversion are presented by \cite{cribb-1976}, \cite{li_3-d_1996} and \cite{pilkington_3-d_1997}.
Different approaches have improved this linear inversion to obtain focused images of the subsurface.
For example, \cite{portniaguine_focusing_1999} and \cite{portniaguine_3d_2002} introduced the minimum gradient support functional, similar to the one proposed by
\cite{last-1983} that minimizes the volumes of the sources in a gravity data inversion.
By inverting magnetic anomaly and any component of the total anomalous field, this functional estimates a magnetization distribution that generates a non blurry (focused) 3-D image of the geologic bodies in the subsurface.
\cite{barbosa_interactive_2006} presented a method for inverting interfering magnetic anomalies produced by multiple sources by combining features of the forward modeling (the interactivity) and traditional inversion (the automatic data fitting). Other studies introduced strategies to constraint the nonuniqueness and delineate the source \cite[]{tontini,pilkington_3d_2009,shamsipour_3d_2011,cella_inversion_2012,abedi-2015}.
Some of these methods allowed remanent magnetization \cite[e.g., ][]{pignatelli-2006}.
In this case, the parameters to be estimated are the total-magnetization intensities
of the prisms.
In all these methods, the geometries of the magnetic sources are indirectly retrieved by interpreting the estimated total-magnetization intensity
distribution.
Theoretically, these inversion methods are capable of recovering the geometry of complex
sources. However, they require a plethora of a priori information to overcome
their nonuniqueness and instability due to the large number of parameters
to be estimated. Additionally, they are characterized by a high
computational cost associated with the solution of large linear systems.

The third group of 3-D magnetic inversion methods requires some knowledge about the
physical property distribution to estimate the geometry of the sources.
They are usually formulated as nonlinear inverse problems.
\cite{wang_inversion_1990} approximated the source by a polyhedron and estimate
the position of its vertices in the Fourier domain.
\cite{wenbin-2017} developed a multiple level-set method to estimate geometry
of a set of causative bodies with uniform magnetic susceptibility.
\cite{hidalgo-2019} inverted the total-field anomaly for estimating the depths to the top of a magnetic basement of a sedimentary basin with known magnetization intensity but unknown magnetization direction.
An inverse method in this third group has a small number of parameters to be estimated by inversion and has much less ambiguity in comparison to the second group.

By following the third group of 3-D magnetic inversion methods,
we present a method to estimate the geometry, position and total-magnetization
intensity of an isolated and uniformly magnetized 3-D source with known
total-magnetization direction.
Our method is an extension of the methods presented
by \cite{oliveirajr-etal2011} and \cite{oliveirajr-barbosa2013} for inverting, respectively,
gravity and gravity-gradient data, applied to the total-field anomaly.
We approximate the source by a stack of vertically juxtaposed
right prisms with polygonal horizontal cross-sections and the same number of vertices.
All prisms have the same thickness and total-magnetization intensity.
Differently from \cite{oliveirajr-etal2011} and \cite{oliveirajr-barbosa2013},
our method estimates not only the horizontal Cartesian coordinates of the origins and the radii of the vertices describing the horizontal cross-sections of all prisms but also the thickness of all prisms comprising the interpretation model, as well as
two additional parameters: the depth to the top of the shallowest prism and the
total-magnetization intensity of all prisms.
We perform a series of inversion runs using different value combinations of these two parameters and compute a goal function associated with each of the trial solutions.
Among the estimated models, those producing the
lowest values of goal function form the set of candidate models.
To obtain stable solutions, we use the same set of regularizing functions proposed by
\cite{oliveirajr-etal2011} and also propose a new one for constraining the
thickness of the prisms.
Following \cite{oliveirajr-etal2011} and \cite{oliveirajr-barbosa2013}, we refer to the proposed method as \textit{radial inversion} because our method estimates the radii of the vertices describing the horizontal cross-sections of all prisms.
Tests on synthetic data and on airborne magnetic data collected over the alkaline-carbonatitic complex of Anit{\'a}polis, in southern Brazil, show the potential of our method in retrieving 3-D magnetic bodies even if they exhibit a variety of shapes and depths.


I put a lot of blood sweat and tears into making my code work.  It is available on my github page: \url{github.com/jgoodknight}.  I made heavy use of the numpy and scipy libraries~\cite{scipy,numpy}  There are some details I wish to point out, however, in my thesis and this seems the appropriate place to do so.

\section{Working with Natural Units: or, Why Mess with SI?}

While an experimentalist needs a systems of units he or she can measure, we theorists prefer to have a system of units which is easy to write down, so we can worry less about dropping factors here and there.  Take for example the hydrogen atom Hamiltonian:

\begin{align*}
	\hat{H} = -\frac{\hbar ^2}{2 m_e} \nabla^2 - \frac{1}{4 \pi \epsilon_0} \frac{e^2}{r}
\end{align*}
That is a lot of constants.  Wouldn't it be better if we could just write this out:
\begin{align*}
	\hat{H} = -\frac{1}{2 } \nabla^2 -  \frac{1}{r}
\end{align*}
This easy-to-not-mess-up Hamiltonian can be yours with a little algebra and a bit of thought.

\subsection{Setting Constants equal to 1}
The astute observer will note that one can get the miraculous Hamiltonian Transformation by making the following algebraic declarations:
\begin{align*}
	\hbar &= 1 \\
	e &= 1 \\
	m_e &= 1 \\
	\frac{1}{4 \pi \epsilon_0} = k_e &= 1
\end{align*}
You may now be wondering how they can be 1.  You've probably had many professors talk to you for many hours about the painstaking effort that went into determining the exact values of these constants throughout the history of physics, and here I go, willy-nilly just setting them to one: doesn't this throw off all of physics into non-physical nonsense?  Yes and no.

There is, unsurprisingly, a limit to the number of units you can set to being 1.  This limit is imposed by the fine-structure constant $\alpha$:
\begin{align*}
	\alpha = \frac{k_e e^2}{\hbar c}
\end{align*}
Which, unless you listen to some theoretical cosmologists, is completely constant in our universe and has a value of $^\sim 1/137$.  So in our system of units we have set all but one of these constants which make up the fine-structure constant to be unity (the absolute limit), so we must get out that $c = \frac{1}{\alpha}$ to keep our system of units from describing a universe other than our own.

\subsection{Setting units equal to 1 or: Finding the ``Natural'' units}
The only reason we are able to set these units to be one is because we now measure things like energy, distance and time in units which MAKE the constants one.  $\hbar$ for example is not really just 1; it's 1 atomic-energy-unit-atomic-time-unit or $1 E_a \cdot t_a$.  To figure out exactly what these atomic units are, we do this for each constant noting that energy will be $E_a = m_a l_a^2/t_a^2$:

\begin{align*}
	\hbar &= 1 E_a \cdot t_a = m_a \frac{l_a^2}{t_a}\\
	k_e &= 1 \frac{E_n \cdot l_a}{q_a ^2}
\end{align*}
We've already defined our charge units to be $e$ and our mass units to be $m_e$  (although that can easily change).
\begin{align*}
	\frac{\hbar}{m_e} &= \frac{l_a^2}{t_a}\\
	k_e e^2 &= m_e \frac{l_a^2}{t_a^2} \cdot l_a
\end{align*}
Now with two equations and two unknowns, we begin to solve
\begin{align*}
	\frac{\hbar}{m_e} &= \frac{l_a^2}{t_a}\\
	t_a &= \frac{l_a^2 m_e}{\hbar} \\
	t_a^2 &= \frac{l_a^3 m_e}{k_e e^2} \\
	\frac{l_a^4 m_e^2}{\hbar^2} &= \frac{l_a^3 m_e}{k_e e^2} \\
	l_a &= \frac{\hbar^2}{m_e k_e e^2}
\end{align*}
Which the astute observer will note has an $\alpha$ hidden in there... somewhere:
\begin{align*}
	l_a &= \frac{\hbar}{m_e \alpha c}
\end{align*}
And the even more astute observer will notice that it is the Bohr radius.  This quickly emits the time and then energy units:
\begin{align*}
	1 l_a &= \frac{\hbar}{m_e \alpha c} = a_0 \approx 5.29 \times 10^{-11}\text{ m} \\
	1 t_a &= \frac{\hbar}{m_e \alpha^2 c^2 } \approx 2.419 \times 10^{-17} \text{ s} \\
	1 E_a &= m_e \alpha^2 c^2 \approx 4.3597 \times 10^{-18} \text{ J}
\end{align*}
wavenumbers come up a lot on spectroscopy so let's figure out what the atomic wavenumber unit is:
\begin{align*}
	1 \omega_a &= \frac{1 E_a}{h c} = 219474.6 \text{ cm}^{-1} = \frac{1}{1 l_a} \\
	hc &= 2 \pi \hbar c = \frac{2 \pi}{\alpha} = 861.022576 E_a \cdot l_a
\end{align*}
So to convert a wavenumber $\omega$ into an atomic energy unit:
 \begin{align*}
	E_a (\omega) &= \frac{\omega}{1 \omega_a} \frac{2 \pi}{\alpha} \\
	&= \omega \left( 0.00392310807 \frac{E_a}{\text{cm}^{-1}} \right)
\end{align*}

\subsection{Setting other things equal to 1}
Now let's say you are reading a paper which quotes all of its energy units in wavenumbers, all of its position units in square-root-centimeters and time units in femtoseconds.  How do you make sense of this?

Let's say this particular paper is talking about harmonic oscillators, the Hamiltonian of which looks like so:
\begin{align*}
	\hat{H} = \frac{\hbar^2 p^2}{2 m	} + \frac{1}{2} m \omega^2 (x - x_0)^2
\end{align*}
In the paper, however, the author quotes the Hamiltonian as being thus:

\begin{align*}
	\hat{H} = \frac{p^2}{2} + \frac{1}{2} \omega^2 (x - x_0)^2
\end{align*}
and all energy units are given in terms of wavenumbers.  All-together, these implies 3 unitary unit relationships:
\begin{align*}
	\hbar = 1 \\
	hc = 1 \\
	m = 1
\end{align*}
Luckily, we don't care about coulomb relations so we can just set $c=2 \pi$ and let the electron charge and Coulomb constant float to strange numbers.  Anyway, as we know from earlier, these really do have units associated with them so we add them in, calling them $j$ units.
\begin{align*}
	\hbar = 1 E_j \cdot t_j \\
	m = 1 m_j
\end{align*}
The author has chosen wavenumbers as the units of choice for energy: specifically 100 wavenumbers.
\begin{align*}
	1 E_j &\sim 100.0 \text{ cm}^{-1} \\
	1 E_j &= h c (100.0 \text{ cm}^{-1}) = 1.986 \times 10^{-21} \text{J}
\end{align*}
which also gives us the natural units for time:
\begin{align*}
	1 t_j = \frac{\hbar}{1 E_j} = 5.308837 \times 10^{-12} \text{s} = 5.3 \text{ ps}
\end{align*}

\subsection{Conclusion on Units}
I have shown you the basic derivation for how to get the system of natural units (units with a bunch of constants equal to one)  known as atomic units.  Hopefully you can follow my logic to create any easy-to-derive-with system of units that you desire.  Up for a challenge?  Let the mass and charge float, set $c=1$ and then figure out how to set Boltzmann's constant and the universal gravitational constant equal to 1 also.  These are known as the Planck units and are cool because they set all the fundamental constants of the forces to 1, instead of any property of an object

\section{Discrete Fourier Transform}
Let's say you want a computer to do the following integral
\begin{align}
	\tilde{f} (\omega) = \int e^{i \omega t} f(t) dt
\end{align}
And your t values stretch from $0\rightarrow n \delta t$.  We could then do the integral like a Riemann Sum:
\begin{align}
	\tilde{f} (\omega) = \delta t \sum_{j=0}^{n}  e^{i \omega j \delta t} f( j \delta t )
\end{align}
but how to discretize $\omega$?  I'm going to skip over why but say that Numpy's Fast Fourier Transform algorithm takes a list of function values $\{f_m\}$ and returns:
\begin{align}
	\tilde{f}_k = \sum_{m=0}^{n - 1}  e^{- 2 \pi i \frac{m k}{n}} f_m
\end{align}
which implies we get $d\omega = \frac{ 2 \pi }{n \delta t}$ with $-\frac{n-1}{2} < k < \frac{n-1}{2} $.  But we defined our Fourier transforms in terms of the positive exponent.  We're in luck, however, because numpy's inverse FFT algorithm looks like this:
\begin{align}
	 f_m = \frac{1}{n} \sum_{k=0}^{n - 1}  e^{2 \pi i \frac{m k}{n}} \tilde{f}_k
\end{align}

\section{Choosing the Parameters of Space}
In the course of simulation, we have to figure out a proper value for the box we put our wavefunctions in that doesn't affect the observables.  So we need something big enough in position space and big enough in momentum space (small enough $\Delta x$.  Let's look at a ladder of harmonic oscillators:
\begin{align}
	H_i = \frac{1}{2m_i} \hat{p}^2 + \frac{1}{2} m_i \omega_i^2 \left( x - \bar{x}_i \right)^2
\end{align}
for the sake of simplicity, we'll say that all the oscillators are accessible to each other via transition dipole moments and that oscillator 0 is the leftmost.  The ground state we will say has non-negligible amplitude from $x_0 \pm n \sigma_0$ where $\sigma_0 = \sqrt{\frac{\hbar}{m \omega_i}}$.

When the ground state (or any initial state but we're being simple here) from the 0th state end ups in the oscillator $j$ whose center is furthest away from its center, the center's have distance $\Delta x_{\max} =  \Delta x_{0j} = ( x_j - x_0)$.  Because of the magic of Gaussian wavepackets in harmonic potentials, the wavepacket will distort and swing to the other side of the potential energy surface and settle at the classical turning point intact.  That wavepacket will now have approximate extent of $x_0 + 2 \Delta x_{\max} + n \sigma_0$.  Which, is the furthest out the wavepacket can ever get.  So If we're only \textbf{simulating a one-interaction experiment},
\begin{align}
	x_{\min} &= x_0 - n \sigma_0 \\
	x_{\max} &= x_0 + 2 \Delta x_{\max} + n \sigma_0 \\
	x_{\max} - x_{\min} &= 2 \Delta x_{\max} + 2n \sigma_0
\end{align}
If, however, we are interacting more than once, things get slightly more complicated.  We have to assume that at some point, the wavepacket centered about $x = x_0 + 2 \Delta x_{\max}$ will once again end up in the 0th oscillator.  Which means that it will swing all the way over to center around  $x = x_0 - 2 \Delta x_{\max}$ and thus for more than two interactions:
\begin{align}
	x_{\min} &= x_0 - 2 \Delta x_{\max} - n \sigma_0 \\
	x_{\max} &= x_0 + 2 \Delta x_{\max} + n \sigma_0 \\
	x_{\max} - x_{\min} &= 4 \Delta x_{\max} + 2n \sigma_0
\end{align}

\subsection{Momentum-Space Considerations  }
Alas, if only computers did not require us to simulate things discretely, we would not have to worry about momentum space but they do and thus we do.  We must chose $N$ points to simulate the system on.  When you discrete Fourier transform a function in $x$, you get values of k ranging from roughly $-\frac{\pi}{ dx}$ to $\frac{\pi}{dx}$ which means we must chose a $dx$ which is small enough to study the largest momentum the problem will end up seeing.
\subsection{One-Interaction}
How do we do this?  Well, consider that our rightmost amplitude is at $x = x_0 + 2 \Delta x_{\max} + n \sigma_0$.  For one interaction, the highest momentum we will see is when it gets to the center of the $j$th well.  Thinking classically, that rightmost piece of amplitude will be motionless at the top and then be potential energy-less at the center so we can say:
\begin{align}
	\frac{p_{\max}^2}{2 m_j} = V_j(x_0 + 2 \Delta x_{\max} + n \sigma_0)
\end{align}
Since $p = \hbar k$ and we already know the form of the potential energy surface:
\begin{align}
	\frac{\left( \hbar k_{\max} \right)^2}{2 m_j} &= \frac{1}{2} m_j \omega_j^2 \left(x_0 + 2 \Delta x_{\max} + n \sigma_0 - x_j \right)^2 \\
	k_{\max} &= \frac{1}{\hbar} m_j \omega_j \left( \Delta x_{\max} + n \sigma_0\right) = \frac{\pi}{dx} \\
	dx &= \frac{\pi \hbar}{m_j \omega_j \left( \Delta x_{\max} + n \sigma_0\right)} = \frac{x_{max} - x_{\min}}{N} \\
	\frac{\pi \hbar}{m_j \omega_j \left( \Delta x_{\max} + n \sigma_0\right)} &= \frac{2 \Delta x_{\max} + 2n \sigma_0}{N}	\\
	N &= \frac{2 m_j \omega_j \left( \Delta x_{\max} + n \sigma_0\right)^2 }{\pi \hbar}
\end{align}

\subsection{Two-Interactions}
But what if that wavepacket at it's absolute rightmost position is then suddenly plummeted down to the leftmost 0th potential energy well?  Then there will be a non-trivially larger maximum momentum as it will have much further to travel to get to the center of the potential energy well.
\begin{align}
	\frac{\left( \hbar k_{\max} \right)^2}{2 m_0}  &= V_0(x_0 + 2 \Delta x_{\max} + n \sigma_0) \\
	k_{\max} &= \frac{1}{\hbar} m_0 \omega_0 \left( x_0 + 2 \Delta x_{\max} + n \sigma_0 -x_0 \right) = \frac{\pi}{ dx} \\
	dx &= \frac{\pi \hbar}{ m_0 \omega_0 \left( 2\Delta x_{\max} + n \sigma_0\right)} = \frac{x_{max} - x_{\min}}{N} \\
	\frac{\hbar \pi}{ m_0 \omega_0 \left( 2\Delta x_{\max} + n \sigma_0\right)} &= \frac{4 \Delta x_{\max} + 2n \sigma_0}{N}\\
	N &= \frac{2 m_0 \omega_0 \left(2\Delta x_{\max} + n \sigma_0 \right)^2}{\pi  \hbar}
\end{align}

\subsection{Summarize}
\subsubsection{One-Interaction}
\begin{align}
	x_{\min} &= x_0 - n \sigma_0 \\
	x_{\max} &= x_0 + 2 \Delta x_{\max} + n \sigma_0 \\
	N &= \frac{2 \pi m_j \omega_j \left( \Delta x_{\max} + n \sigma_0\right)^2 }{\hbar} \\
	dx &= \frac{\hbar}{\pi m_j \omega_j \left( \Delta x_{\max} + n \sigma_0\right)}
\end{align}

\subsubsection{Two-Interactions}
\begin{align}
	x_{\min} &= x_0 - 2 \Delta x_{\max} - n \sigma_0 \\
	x_{\max} &= x_0 + 2 \Delta x_{\max} + n \sigma_0 \\
	N &= \frac{2 \pi m_0 \omega_0 \left(2\Delta x_{\max} + n \sigma_0 \right)^2}{\hbar}\\
	dx &= \frac{\hbar}{\pi m_0 \omega_0 \left( 2\Delta x_{\max} + n \sigma_0\right)}
\end{align}

\subsubsection{More-Than-Two-Interactions}
With a third interaction, one must consider the scenario where the wavepacket at its leftmost is promoted to the rightmost potential energy well where it can again go out to the rightmost edge of the $j$th potential energy well giving us a different maximum distance needed and different maximum potential needed.

\section{Applying $U(t)$ Numerically: the Split Operator Method}
Let's say you want to apply an exponential operator to something:
\begin{align*}
	U = e^{-i t \mathcal{H} / \hbar}
\end{align*}
This does not appear to be terribly difficult at first sight if you know how to take the exponential of whatever $\mathcal{H}$ is.  Let's just make life difficult and call $\mathcal{H}$ the Hamiltonian of a quantum system which would make $U$ the time-evolution operator:
\begin{align*}
	U = e^{-i t / \hbar \mathcal{H}(p, x) } = e^{-i t / \hbar (\mathcal{T}(p) + \mathcal{V}(x) ) }
\end{align*}
So now it appears to be rather difficult as the potential energy is best expressed in the position basis whereas the kinetic energy is best expressed in the momentum basis.  We might consider doing this (to make our lives easier, define $\lambda = \frac{- i t}{\hbar}$) to make things simpler:
\begin{align*}
	U &= e^{\lambda (\mathcal{T} + \mathcal{V} ) }  = e^{\lambda \mathcal{T} } e^{\lambda  \mathcal{V} }
\end{align*}
Then we could apply the first bit, Fourier transform, apply the second bit and then inverse Fourier transform back to the original basis.  Is this, correct, though?  Let's look at the Taylor Series for the two.  First the ``correct'' operator:
\begin{align*}
	U &= e^{\lambda (\mathcal{T} + \mathcal{V} ) } \\
	&= \sum_{k=0}^{\infty} \frac{\lambda^k}{k!} (\mathcal{T} + \mathcal{V} )^k \\
	&= 1 + \lambda (\mathcal{T} + \mathcal{V} ) + \frac{\lambda^2}{2}(\mathcal{T}^2 + \mathcal{V}^2  + \mathcal{T}\mathcal{V} + \mathcal{V}\mathcal{T}) \\
	&+ \frac{\lambda^3}{6}(\mathcal{T}^3+ \mathcal{V}^3 + \mathcal{T}\mathcal{V}^2 + \mathcal{T}^2\mathcal{V} + \mathcal{T}\mathcal{V}\mathcal{T} + \mathcal{V}\mathcal{T}^2 + \mathcal{V}\mathcal{T} \mathcal{V} + \mathcal{V}^2\mathcal{T}  ) + O(\lambda^4)
\end{align*}
Now the proposed correction:
\begin{align*}
	U &= e^{\lambda \mathcal{T} } e^{\lambda  \mathcal{V} }  \\
	&= \sum_{k=0}^{\infty} \frac{\lambda^k}{k!} \mathcal{T}^k \sum_{l=0}^{\infty} \frac{\lambda^l}{l!} \mathcal{V}^k \\
	&= 1 + \lambda (\mathcal{T} + \mathcal{V}) + \frac{\lambda^2}{2}(\mathcal{T}^2 + \mathcal{V}^2 + 2 \mathcal{T} \mathcal{V}) + \frac{\lambda^3}{6}(\mathcal{T}^3 + \mathcal{V}^3  + 3\mathcal{T}\mathcal{V}^2 + 3\mathcal{T}^2 \mathcal{V}  ) + O(\lambda^4)
\end{align*}
So because normally you have commutivity $xy = yx$, because the kinetic and potential operators don't necessarily commute, there is an error term here:
\begin{align*}
	E &=  e^{\lambda (\mathcal{T} + \mathcal{V} ) } - e^{\lambda \mathcal{T} } e^{\lambda  \mathcal{V} }  \\
	&= \frac{\lambda^2}{2} ( \mathcal{T} \mathcal{V} - \mathcal{V} \mathcal{T} ) + O(\lambda^3) \\
	&= \frac{\lambda^2}{2} [ \mathcal{T}, \mathcal{V}] + O(\lambda^3)
\end{align*}
So our approximation is good, so long as $\lambda$ is small enough to keep $\lambda^2$ sufficiently small.  This can be accomplished by letting $t=N\Delta t$ and applying the operator for $\Delta t$, $N$ times.

You can get even better accuracy at the cost of more Fourier transforms using certain schemes as shown below.  (I will spare you the proofs of these)
\begin{align*}
	U &\approx e^{\lambda \mathcal{T} / 2 } e^{\lambda  \mathcal{V} } e^{\lambda \mathcal{T} / 2 } + O(\lambda^3) \\
	U &\approx \left(  e^{\gamma \lambda \mathcal{T} / 2 } e^{\gamma \lambda  \mathcal{V} } e^{\gamma \lambda \mathcal{T} / 2 } \right) \left( e^{(1- 2\gamma) \lambda \mathcal{T} / 2 } e^{(1- 2\gamma) \lambda  \mathcal{V} } e^{(1- 2\gamma) \lambda \mathcal{T} / 2 } \right) \left( e^{\gamma \lambda \mathcal{T} / 2 } e^{\gamma \lambda  \mathcal{V} } e^{\gamma \lambda \mathcal{T} / 2 } \right)+ O(\lambda^4) \\
	&= e^{\gamma \lambda \mathcal{T} / 2 } e^{\gamma \lambda  \mathcal{V} } e^{(1-\gamma) \lambda \mathcal{T} / 2 } e^{(1- 2\gamma) \lambda  \mathcal{V} } e^{(1-\gamma) \lambda \mathcal{T} / 2 }  e^{\gamma \lambda  \mathcal{V} } e^{\gamma \lambda \mathcal{T} / 2 } + O(\lambda^4) \\
	\gamma &= \frac{1}{2 - \sqrt[3]{2}}
\end{align*}
You can, in principle, get a splitting method for an arbitrary level of accuracy, but it will involve more computational time.\footnote{Referenced http://www.pci.uni-heidelberg.de/tc/usr/andreasm/academic/handouthtml/node13.html for part of this derivation}

\section{Trapezoidal Integration for Perturbation Theory Calculations with Smaller Time Discretization}

The integral one performs to do one ``interaction'' with a perturbative Hamiltonian $H'(t)$ with a time-independent Hamiltonian $H_0$ is:
\begin{align*}
	\ket{\Psi'(t)} = -\frac{i}{\hbar} \int_{-\infty}^{t} e^{-\frac{i}{\hbar} H_0 (t - \tau)} H'(\tau) \ket{\Psi (\tau)} d\tau
\end{align*}
Where $\ket{\Psi (\tau)} $ is the underlying wavefunction being interacted with, $\tau$ represents the different times that the interaction can happen at and $e^{-\frac{i}{\hbar} H_0 (t - \tau)} = U_0 (t, \tau)$ is the non-perturbative time-evolution operator.  This integral  phenomenologically represents some field represented by $H'$ having being able to interact at many different points in time--all where the field is nonzero.  At each of these points in time (represented by $\tau$), one must interact the field with the underlying wavefunction and then propagate that wavefunction out to the time-point of interest.  Then, for every $\tau$ before $t$ there is a contribution to the interacted wavefunction at time $t$ that is averaged over by the integral.

Now it is not hard to imagine that a naive implementation of this integral would be numerically very expensive.  Indeed, if you turn my above paragraph into an algorithm directly, if the perturbation is ``on'' for $N$ time steps, you are storing $O(N^2)$ wavefunctions which gets hairy very quickly.

We can do better, though and we will: to start with, we will assume that our perturbation can be ``turned on'' at a time $t_0 > -\infty$ without affecting the calculation at all, the integral reduces to this.
\begin{align*}
	\ket{\Psi'(t)} = -\frac{i}{\hbar} \int_{t_0}^{t} U_0 (t, \tau) H'(\tau) \ket{\Psi (\tau)} d\tau
\end{align*}
now we shall discretize time: $t_i = t_0 + i \delta t$ and $\tau_j = t_0 + j \delta t$.  $t$ and $\tau$ have the same initial value because $\tau$ is never lower than $t$.  Later on we will exploit this to simplify the expression but for now, I shall keep $\tau$ separate to make it abundantly clear that it is the variable which represents the point at which the perturbation acts on the system.

We decide to perform the integral with a simple Riemann sum:
\begin{align*}
	\int_{t_0}^{t_f} f(t) dt =\delta t \sum_{n} f(t_n) + O(\delta t^2)
\end{align*}
which gives us:
\begin{align*}
	\ket{\Psi'(t_i)} = -\frac{i}{\hbar} \delta t  \sum_{j=0}^{j=i}   U_0 (t_i, \tau_j) H'(\tau_j) \ket{\Psi (\tau_j)}
\end{align*}
now at this point, we decide to try mathematical induction for the heck of it and we calculate
\begin{align*}
	\ket{\Psi'(t_{i+1})} &= -\frac{i}{\hbar} \delta t  \sum_{j=0}^{j=i+1}   U_0 (t_{i+1}, \tau_j) H'(\tau_j) \ket{\Psi (\tau_j)} \\
									&= -\frac{i}{\hbar} \delta t \left[ \sum_{j=0}^{j=i}   U_0 (\delta t) U_0 (t_{i}, \tau_j) H'(\tau_j) \ket{\Psi (\tau_j)}  + U_0 (t_{i+1}, \tau_{i+1}) H'(\tau_{i+1}) \ket{\Psi (\tau_{\tau_{i+1})}} \right]
\end{align*}
which, since $t_n = \tau_n $ we can say
\begin{align*}
	\ket{\Psi'(t_{i+1})} = U_0 (\delta t)\ket{\Psi'(t_i)} -\frac{i}{\hbar} \delta t H'(\tau_{i+1}) \ket{\Psi (\tau_{\tau_{i+1})}}
\end{align*}
which has a really interesting interpretation.  At each time step, we merely take the previous time step's perturbation and propagate it forward one step in time.  Then, we take the perturbation and interact it with the current step of the wavefunction and add it to the propagated step and that is the current step's perturbed wavefunction.  This is a phenomenal savings in space and time of calculation over an naive implementation of the integral.

This is not without it's problems, however.  The error in this integration is of the order $\delta t^2$ whereas the error for most split-operator propagation methods (if one is being smart) is of the order $\delta t^3$.  This is entirely a failing of the Riemann sum algorithm.  Remembering back to High school calculus, though, one might recall another method called trapezoidal rule for integration.
\begin{align*}
	\int_{t_0}^{t_f} f(t) dt =\frac{\delta t}{2} \left[ f(t_0) + f(f_f) + 2  \sum_{n=1}^{n=f-1} f(t_n) \right] + O(\delta t^3)
\end{align*}
which we make use of to get an even lower error
\begin{align*}
	\ket{\Psi'(t_{i+1})} = U_0 (\delta t)\ket{\Psi'(t_{i})} -\frac{i}{\hbar}  \frac{\delta t}{2} U_0 (\delta t) H'(\tau_{i}) \ket{\Psi (\tau_{i})} -\frac{i}{\hbar} \frac{\delta t}{2} H'(\tau_{i+1}) \ket{\Psi (\tau_{i+1})}
\end{align*}

\section{Calculation Method For Heating Calculations}
To look at molecular heating, we would care most about the average vibrational quantum number
\begin{align*}
	\bar{n}(t) &= \sum_{n} n \left| \bra{g}\braket{n_{\gamma} | \Psi(t)} \right|^2
\end{align*}
But then what does the time-dependent wavefunction look like?  We're interested in the exact picture.  The interaction Hamiltonian is
\begin{align*}
	\hat{H}'(t) &= E(t)  \left(\ket{g}\bra{e} + \ket{e}\bra{g}\right)\mu(x)
\end{align*}
and the time-independent Hamiltonian is as above:
\begin{align}
	H_0 &=  \sum_n \hbar \omega_{\gamma}  \left(n + \frac{1}{2} \right)  \ket{n_{\gamma}}\ket{g}\bra{g} \bra{n_{\gamma}} \\
   &+ \sum_m \left(  \hbar \omega_{\epsilon}  \left(m + \frac{1}{2} \right) + \omega_e \right)  \ket{m_{\epsilon}} \ket{e}\bra{e} \bra{m_{\epsilon}}
\end{align}
If we turn the electronic degrees of freedom, putting it into Matrix form, we then have:
\begin{align*}
	\hat{H}(t) &=
	\begin{bmatrix}
	H_{\gamma}(x) & E(t)\mu(x) \\
	E(t)\mu(x) & H_{\epsilon}(x)
	\end{bmatrix}
\end{align*}
no that won't work since the coefficients of the Pauli matrices won't commute...

Let's try a blast form undergrad and calculate the time-dependent coefficients!  We assume the following form of the time-varying wavefunction:

\begin{align*}
	\ket{\Psi(t)} = \sum_{a} G_a(t) \ket{a_{\gamma}} \ket{g}  + \sum_{b} E_b(t) \ket{b_{\epsilon}} \ket{e}
\end{align*}
where we know the initial conditions are $G_0(0) = 1, G_{a\neq0}(0) = 0, E_b(0) = 0$.
We now take the full time-dependent Schrodinger equation:
\begin{align*}
	\frac{d}{dt}\ket{\Psi(t)} = -\frac{i}{\hbar}\hat{H}(t)\ket{\Psi(t)}
\end{align*}
starting with the left and simplest side:
\begin{align*}
	\frac{d}{dt}\ket{\Psi(t)} = \sum_{a} \frac{d G_a(t)}{dt} \ket{a_{\gamma}} \ket{g}  + \sum_{b} \frac{d E_b(t)}{dt} \ket{b_{\epsilon}} \ket{e}
\end{align*}
Then the right side can be split in twain:
\begin{align*}
	-\frac{i}{\hbar}\left( \hat{H}_0 + \hat{H}'(t)  \right) \ket{\Psi(t)}
\end{align*}
the easiest part of that being:
\begin{align*}
	\hat{H}_0  \ket{\Psi(t)} &= \sum_{a} G_a(t) \left[E_g + E_{\gamma}\left(a + \frac{1}{2}\right) \right]\ket{a_{\gamma}} \ket{g}  \\
	&+ \sum_{b} E_b(t) \left[E_e + E_{\epsilon}\left(b + \frac{1}{2}\right) \right] \ket{b_{\epsilon}} \ket{e}\\
	&= \sum_{a} G_a(t) \Omega_{(a)} \ket{a_{\gamma}} \ket{g}  \\
	&+ \sum_{b} E_b(t) \Omega^{(b)} \ket{b_{\epsilon}} \ket{e}
\end{align*}
and now for the interaction term:
\begin{align*}
	\frac{\hat{H}'(t)}{E(t)}  \ket{\Psi(t)} &= \sum_{a} G_a(t) \mu(x)\ket{a_{\gamma}} \ket{e}  + \sum_{b} E_b(t) \mu(x)\ket{b_{\epsilon}} \ket{g}
\end{align*}
we may find it useful to diagonalize the vibrational eigenstates into the same manifold as the electronic state using the identities: $\sum_{q}
\ket{q_{\gamma}}\bra{q_{\gamma}}$ and $\sum_{j}
\ket{j_{\epsilon}}\bra{j_{\epsilon}}$.  We also define $\mu_{a}^{b} = \bra{a_{\gamma}} \mu(x) \ket{b_{\epsilon}}$:
\begin{align*}
	\frac{\hat{H}'(t)}{E(t)}  \ket{\Psi(t)} &= \sum_{a, q} G_a(t) \mu_{a}^{q}\ket{q_{\epsilon}} \ket{e}  + \sum_{b,r} E_b(t) \mu_{r}^{b}\ket{r_{\gamma}} \ket{g}
\end{align*}
Now we put everything together:
\begin{align*}
	\left(\frac{d}{dt} +\frac{i}{\hbar}\hat{H}_0 \right)\ket{\Psi(t)}  = -\frac{i}{\hbar}\hat{H}''(t)\ket{\Psi(t)} \\
	\sum_{a} \left(\frac{d G_a(t)}{dt} + \frac{i}{\hbar}\Omega_{(a)}\right)\ket{a_{\gamma}} \ket{g}  + \sum_{b} \left(\frac{d E_b(t)}{dt} + \frac{i}{\hbar} \Omega^{(b)} \right)\ket{b_{\epsilon}} \ket{e}\\
	=-E(t)\frac{i}{\hbar} \left[\sum_{a, q} G_a(t) \mu_{a}^{q}\ket{q_{\epsilon}} \ket{e}  + \sum_{b,r} E_b(t) \mu_{r}^{b}\ket{r_{\gamma}} \ket{g} \right]
\end{align*}
Now we can pick out specific terms by ket-ing in with $\ket{g}\ket{a_{\gamma}}$ and $\ket{b}\ket{b_{\epsilon}}$.
\begin{align*}
	\left(\frac{d G_a(t)}{dt} + \frac{i}{\hbar}\Omega_{(a)}\right) &=-E(t)\frac{i}{\hbar}  \sum_{b} E_b(t) \mu_{a}^{b}
\end{align*}
and then:
\begin{align*}
	\left(\frac{d E_b(t)}{dt} + \frac{i}{\hbar} \Omega^{(b)} \right) =-E(t)\frac{i}{\hbar} \sum_{a} G_a(t) \mu_{a}^{b}
\end{align*}

This can be re-cast as a matrix problem,
\begin{align*}
	\frac{d}{dt}\begin{bmatrix}
		G_a(t) \\
		E_b(t)
	\end{bmatrix}
	= -\frac{i}{\hbar}
	\begin{bmatrix}
		\Omega_{(a)} & E(t) \mu_{a}^{b} \\
		E(t) \mu_{a}^{b} & \Omega^{b}
	\end{bmatrix}
	\cdot
	\begin{bmatrix}
		G_a(t) \\
		E_b(t)
	\end{bmatrix}
\end{align*}
Then this is put into a numeric first order differential equation solver.  At every point I make sure there is not too much amplitude in the highest vibrational state and then re-start the calculation if so, ensuring no nonphysical results from truncation of the Hilbert Space.

\section{Notorious RWA: the Rotating Wave Approximation}

There's another trick we can use to save a lot of computational time called the rotating wave approximation.  Let's take a look at some laser excitation operator:
\begin{align*}
	\hat{H}_{+}'(t) = E_0 e^{-i \omega_c \tau} e^{\frac{\tau^2 }{2 \sigma^2}}  \ket{e}\bra{g}
\end{align*}
if we assume the ground state has zero energy and the excited state has energy/frequency (because $\hbar=1$ here) $\Omega$ then we expect the zero and first order perturbation to look like:
\begin{align*}
	\ket{\psi_0 (t)} &= \ket{g} \\
	\ket{\psi_{+} (t)} &= -\frac{i}{\hbar} \int_{-\infty}^{t} U(t, \tau) \hat{H}_{+}'(\tau) \ket{g} d \tau \\
	&= -\frac{iE_0}{\hbar} \int_{-\infty}^{t} U(t, \tau)e^{-i \omega_c \tau} e^{\frac{\tau^2  }{2 \sigma^2}}  \ket{e} d \tau \\
	&= -\frac{iE_0}{\hbar} \int_{-\infty}^{t} e^{ -i\Omega (t - \tau)}e^{-i \omega_c \tau} e^{\frac{\tau^2 }{2 \sigma^2}}  \ket{e} d \tau \\
	&= -\frac{iE_0}{\hbar} e^{ -i\Omega t} \ket{e} \int_{-\infty}^{t} e^{-i ( \omega_c - \Omega) \tau} e^{\frac{\tau^2 }{2 \sigma^2}} d \tau
\end{align*}
so we see that after the excitation perturbation only depends on $\omega_c - \Omega$ or the difference between the central frequency of the pulse and the laser.  Which means that we can wrap those two things together and say that the energy of the excited state is zero and that the laser oscillates at a frequency of $\omega_c - \Omega$ instead.
\begin{align*}
	\ket{\psi_0 (t)} &= \ket{g} \\
	\ket{\psi_{+} (t)} &= -\frac{iE_0}{\hbar}\ket{e} \int_{-\infty}^{t} e^{-i \delta \omega \tau} e^{\frac{\tau^2 }{2 \sigma^2}} d \tau
\end{align*}
What does that give us computationally?  It means, primarily, that we can use a smaller time step and have the same accuracy, which will greatly speed up the calculation.  One must be careful, though.  It only works for diagonal Hamiltonians.  Once one has a diagonal (or block diagonal) Hamiltonian, one can use this trick to consider the possible transitions between the diagonal states.