% !TEX root = manual.tex
\section{Hypercube}
\label{subsec:tutorial:hypercube}

Although never used at scale in a production system, the generalized hypercube is an important topology to understand, particularly for flattened butterfly and dragonfly.
The (k,n) generalized hypercube is geometrically an N-dimensional torus with each dimension having size k (although dimension sizes need not be equal).
Here we show a (4,2) generalized hypercube (Figure \ref{fig:topologies:hypercubeConnected}).  This would be specified in SST as:

\begin{ViFile}
topology.name = hypercube
topology.geometry = 4 4
\end{ViFile}
indicating size 4 in two dimensions.

While a torus only has nearest-neighbor connections, a hypercube has full connectivity within a row and column (Figure \ref{fig:topologies:hypercubeConnected}).
Any switches in the same row or same column can send packets with only a single hop.

\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{figures/tikz/hypercube/hypercube_connected.png}
\caption{Hypercube with links and connections within a row/column}
\label{fig:topologies:hypercubeConnected}
\end{figure}

This extra connectivity leads to greater path diversity and higher radix switches.
The cost tradeoff is that each link has lower bandwidth than a torus.
Whereas a torus has a few fat links connecting switches, a hypercube has many thin links.
A hypercube can have more dimensions and be asymmetric, e.g.

\begin{ViFile}
topology.name = hypercube
topology.geometry = 4 5 6
\end{ViFile}

where now we have full connections within horizontal rows, horizontal columns, and vertical columns.
Here each switch has radix 12 (3 connections in X, 4 connections in Y, 5 connections in Z).

\subsection{Allocation and indexing}
\label{subsec:hypercube:allocation}

A hypercube has the same coordinate system as a torus. For example, to create a very specific, irregular allocation on a hyerpcube:

\begin{ViFile}
node {
 app1 {
  launch_cmd = aprun -n 5
  indexing = coordinate
  allocation = coordinate
  coordinate_file = coords.txt
 }
}
\end{ViFile}
and then a coordinate file named \inlineshell{coords.txt}

\begin{ViFile}
5 2
0 0
0 1
1 1
2 0
3 3
\end{ViFile}
The first line indicates 5 entries each with 2 coordinates.
Each line then defines where MPI ranks 0-4 will be placed

\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{figures/tikz/hypercube/hypercube_allocation.png}
\caption{Hypercube allocation for given set of coordinates}
\label{fig:topologies:hypercubeAllocation}
\end{figure}

\subsection{Routing}
\label{subsec:hypercube:routing}

Hypercubes allow very path-diverse routing because of its extra connections.
In the case of minimal routing (Figure \ref{fig:topologies:hypercubePath}), two different minimal paths from blue to red are shown.
While dimension order routing would rigorously go X then Y, you can still route minimally over two paths either randomly selecting to balance load or routing based on congestion.

\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{figures/tikz/hypercube/hypercube_path.png}
\caption{Minimal routing within a hypercube showing path diversity. Packet travels from blue to red, passing through green intermediate switches.}
\label{fig:topologies:hypercubePath}
\end{figure}

To fully maximize path diversity on adversarial traffic patterns, though, path-diverse topologies can benefit from Valiant routing.
Here, rather than directly routing to the final destination, packets first route to random intermediate switches on a minimal path.
Then they route again from the intermediate switch to the final destination also on a minimal path (Figure \ref{fig:topologies:hypercubeValiant}).
Although it increases the hop count and therefore the point-to-point latency, it utilizes more paths and therefore increases the effective point-to-point bandwidth.

\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{figures/tikz/hypercube/hypercube_valiant.png}
\caption{Valiant routing within a hypercube.  Packet travels from blue to red via a random intermediate destination shown in gray. Additional intermediate switches are shown in green.}
\label{fig:topologies:hypercubeValiant}
\end{figure}


\documentclass[11pt]{amsart}
\usepackage{amsmath,amsfonts,amsthm,amssymb, amsaddr}
\usepackage{graphicx}

\title{Lorentz Transformations}

\author{Joe Bentley}

\date{\today}

\begin{document}

\maketitle

\newpage

\section{Galilean Tranformations}

Galilean transformations describe a set of transformations between two inertial frames in space. For frame $\Sigma'$ moving at velocity $v$ in the positive x-direction, away from a stationary frame $\Sigma$, we have the following for each coordinate in space and time,

\begin{align*}
x' &= x - vt \\
y' &= y \\
z' &= z \\
t' &= t \\
\end{align*}

y', z', and t' are all constant in time as the moving frame $\Sigma'$ is not changing in any of those directions, and time is considered universal across all reference frames. By differentiating the x coordinate with respect to time we can find an expression for the velocity $u'_x$ measured by $\Sigma'$ of a body moving at velocity $u_x$ in $\Sigma$. Of course we expect to see the velocity added to the frame's velocity. For example, if we are stationary and we throw a ball at 40mph, we
expect an observer moving towards the ball at 10mph to see the ball going 30mph. We see that this is indeed the case,

\begin{align}
\label{eq:galilean}
u'_x = u_x - v
\end{align}

\section{Lorentz Transformations}

Special relativity tells us that we would measure the same velocity for light in any reference frame, no matter our relative velocities. This means we may need a new set of transformations to describe transformations between these inertial frames of reference as our case of velocities adding as in eq.~\ref{eq:galilean}.

Again we will consider two frames, a stationary frame $\Sigma$ and a frame $\Sigma'$ moving at velocity $v$ in the $x$-direction. First we will consider the most general case of transformations. We will use constant before each term in our transformations, and find the value of these constants. Here is our general form,

\begin{align*}
x' &= Ax - Bct \text{  eq(a)} \\
y' &= y \\
z' &= z \\
ct' &= Ex - Dct \text{  eq(b)}
\end{align*}

Again we can say that there is no relative motion in the $y'$ and $z'$ as there is no velocity in those directions, but we will not make the assumption that time is universal in all frames of reference just yet, as that may be wrong due to special relativity. We use $ct$ in time so that everything has dimensions of length, and also we will use only linear terms or else the laws of physics would differ at different points in space, which we assume isn't true.

\section{Point of View from $\Sigma$}

Firstly we consider the view from $\Sigma$. $\Sigma$ sees the origin of $\Sigma'$ moving away at a velocity $v$. At this point we have $x = vt'$ and $x' = 0$ (as it is at the origin).

\begin{align*}
\text{in eq(a) we have  } \to 0 = Avt + Bct \implies B = -\frac{Av}{c}
\end{align*}

Thus we have,

\begin{align}
\label{eq:B}
B = -\frac{Av}{c}
\end{align}

\section{Point of View from $\Sigma'$}

We now consider that $\Sigma'$ sees the origin at $\Sigma$ moving away (in the negative x-direction). Now we have $x = -vt'$ and $x = 0$ (at the origin).

\begin{align*}
\text{in eq(a)  } \to -vt' &= 0 + Bct = -Avt \text{  from eq.~\ref{eq:B}} \\
\text{in eq(b)  } \to ct' &= 0 + Dct \implies t' = Dt \\
\end{align*}

Therefore we now have,

\begin{align*}
t' = Dt \to -vDt = -Avt \to D = A
\end{align*}

We now have another relation,

\begin{align}
\label{eq:D}
D = A
\end{align}

\section{$\Sigma$ Fires Beam of Light}

We now take the case where $\Sigma$ fires a beam of light along the x-axis at t = 0. The location given in $\Sigma$ and $\Sigma'$ is $x = ct$ and $x' = ct'$ respectively, because c is the same in all frames of reference.

\begin{align*}
\text{using eq(a):  } x' &= ct' = Ax + Bct = Act + Bct \\
\text{from eq~\ref{eq:B}  } ct' &= A\left(ct - vt\right) \\
\text{also, using eq(b)  } ct' &= Ect + Dct = Ect + Act \text{  (by eq~\ref{eq:D})} \\
\to A\left(ct - vt\right) &= Act - Avt = Ect + Act
\end{align*}

We therefore have that,

\begin{align}
\label{eq:E}
E = -\frac{Av}{c} = B
\end{align}

\section{Light Pulse emitted in y-direction}

Now we take the case as a light pulse is emitted in the y-direction in $\Sigma$ at $t = 0$. In $\Sigma'$ the pulse has both an x and y-component, as $\Sigma'$ is moving in the x-direction relative to $\Sigma$ and is thus moving relative to the light. We know however that the velocity is $c$ in both $\Sigma$ and $\Sigma'$ due to special relativity.

So, in $\Sigma$ we have $x = 0$ and $y = ct$, in $\Sigma'$ we have $x'^2 + y'^2 = c^2 t'^2$ (from Pythagoras' theorem).

In the x-direction we have,

\begin{align*}
\text{in eq(a):  } x'^2 &= \left(Ax + Bct\right)^2 \\
                        &= A^2\left(0 - vt\right)^2 \text{  using eq.~\ref{eq:B}} \\
                        &= A^2 v^2 t^2
\end{align*}

and in the y-direction we have,

\begin{align*}
y'^2 &= y^2 = c^2 t^2 \\
c^2 t'^2 &= \left(Ex + Dct\right)^2 = \left(0 + Act\right)^2 \text{  using eq.~\ref{eq:D}} \\
         &= A^2 c^2 t^2
\end{align*}

Therefore, from $x'^2 + y'^2 = c^2 t'^2$, and by substituting in $x'^2$ and $y'^2$, we have,

\begin{align*}
A^2 v^2 t^2 + c^2 t^2 &= A^2 c^2 t^2
\end{align*}

and then dividing through by $c^2$ and $t^2$,

\begin{align*}
A^2 \frac{v^2}{c^2} + 1 &= A^2 \\
1 &= A^2\left(1 - \frac{v^2}{c^2}\right)
\end{align*}

We thus arrive at our important result,

\begin{align}
\label{eq:gamma}
A = \frac{1}{\sqrt{1 - \frac{v^2}{c^2}}} = \gamma
\end{align}

and,

\begin{align*}
B = -\gamma \frac{v}{c}, D = \gamma, E = -\gamma \frac{v}{c}
\end{align*}

\section{Lorentz Transformations}

Now, by substituting back in all we now know, we arrive at the Lorentz transformations,

\begin{align*}
x' &= \gamma\left[x - vt\right] \\
y' &= y \\
z' &= z \\
ct' &= \gamma\left[ct - \frac{v}{c} x\right]
\end{align*}

One important result in this is the observation that space and time are clearly linked, that is, the spatial transformation includes time, and the temporal transformation includes space. This is the essence of space-time.

\section{Velocity Transformations}

By differentiating the x and t transformations and applying the chain rule, we can find expressions for the velocity, although this will not be shown here as it is quite easy,

\begin{align*}
u_x = \frac{u'_x + v}{1 + \frac{v u'_x}{c^2}}
\end{align*}

\section{Spacetime}

In this section we will define a useful concept known as the space-time interval, which will allow us to easily assess causality connections between events. First we will consider a flash of light in a frame $\Sigma'$ moving relative to a stationary frame $\Sigma$. An observer, $O'$ in the $\Sigma'$ frame will see the flash of light move at a speed $v' = c$. We can express the distance travelled by this light in some time $\Delta t'$ as,

\begin{align}
  \label{eq:spacetime1}
  \Delta r'^2 = c^2 \Delta t'^2
\end{align}

An observer $O$ in $\Sigma$ will also see the flash of light moving at velocity $v = c$,

\begin{align}
  \label{eq:spacetime2}
  \Delta r^2 = c^2 \Delta t^2
\end{align}

For both eq.~\ref{eq:spacetime1} and eq.~\ref{eq:spacetime2} we can see that both can be equated to a constant, zero, and can be equated,

\begin{align*}
  c^2 \Delta t^2 - \Delta r^2 = c^2 \Delta t'^2 - \Delta r'^2
\end{align*}

From this we can define a space-time interval, giving us an interval between two places in spacetime.

\begin{align*}
  \Delta s^2 = c^2 \Delta t^2 - \Delta r^2
\end{align*}

where $\Delta t$ is the difference in time between two events, and $\Delta r$ is the distance between the two points. $\Delta s^2$ is invariant under Lorentz transformation, that is, $c^2 \Delta t^2 - \Delta r^2 = c^2 \Delta t'^2 - \Delta r'^2$. This means that space and time are linked and completely connected, so in general we use a 4-vector to represent spacetime (a 4-vector has a time component as well as spatial components).

How can we interpret our space-time interval $\Delta s^2$? In the case where $\Delta s^2 > 0$ then this is called a "timelikeinterval". In this case the two events can reach each other without going faster than the speed of light, so the events are said to be causally conneted. Here time flows, and at a rate such that the proper time is $\Delta \tau = \left(c^2 \Delta t^2 - \Delta r^2\right)^{\frac{1}{2}}$. Next we will look at the $\Delta s^2 = 0$ which is called a "lightlike"
interval. In this interval no time flows; an observer going at the speed of light would not perceive any time to pass. This interval is such that the proper time $\Delta \tau = 0$. Lastly there is the case where $\Delta s^2 < 0$ called a "spacelike" interval. Here no signal can pass between, as the signal would have to travel faster than the speed of light to be able to do so. This interval is not in the future or past cone of the lightcone diagram, so there is no causal connection.

\section{Momentum in Special Relativity}

We can see that our classical equation for momentum, $\mathbf{p} = m\mathbf{v}$ will not work under the conditions that we need in special relativity. Firstly, if we have a large momentum then we can have a velocity greater than the speed of light; it seems unnatural to put an upper limit on momentum like this. Secondly, it doesn't allow massless particles like photons to have momentum, which we know they do. Also it does not conserve momentum in all reference frames due to velocity transformations. To find a relativistic momentum equation we will consider a glancing collision between two particles.

\includegraphics[scale=0.15]{frames}

To formulate an idea of what this might look like, first we will assume that $\mathbf{p}$ must be a function of $m$ and $\mathbf{v}$, and that $\mathbf{p} \to m\mathbf{v}$ as $\mathbf{v} \to 0$. So we will postulate a function of the following form,

\begin{align*}
  \mathbf{p} = \alpha(w) m \mathbf{w}
\end{align*}

where $\alpha(w)$ is some function of the velocity. We use $w$ as we have used both $v$ and $u$ in our diagram. Since $\mathbf{p} \to m\mathbf{v}$ as $\mathbf{v} \to 0$, this means that $\alpha(0) = 1$.

First we will look from A's frame of reference. We can see that B's speed before the collision is,

\begin{align*}
  w &= {\left(v^2 + \frac{u_0^2}{\gamma^2}\right)}^{\frac{1}{2}}
\end{align*}

and B's speed after the collision,

\begin{align*}
  w' &= {\left(v^2 + \frac{u'^2}{\gamma^2}\right)}^{\frac{1}{2}}
\end{align*}

By applying conservation of momentum in the x-direction (just of particle B, as A has no x-component),

\begin{align*}
  m\alpha(w)v &= m\alpha(w')v \\
  \implies \alpha(w) &= \alpha(w') \\
  \implies w &= w' \implies u_0 = u'
\end{align*}

therefore we see that the speed of B doesn't change during the collision. By applying conservation of momentum in the y-direction, now involving both particles. This time we won't write the factors of mass $m$ and we will use that $u_0 = u'$,

\begin{align*}
  -\alpha(u_0) u_0 + \alpha(w)\frac{u_0}{\gamma} &= \alpha(u_0)u_0 - \alpha(w)\frac{u_0}{\gamma} \\
  \alpha(w)\frac{u_0}{\gamma} &= \alpha(u_0) u_0 \\
  \implies \frac{\alpha(w)}{\gamma} &= \alpha(u_0)
\end{align*}

In the limit as $u_0 \to 0$,

\begin{align*}
  \alpha(v) &= \gamma \alpha(0) \\
  \implies \alpha(v) &= \gamma
\end{align*}

where $\gamma = \frac{1}{\sqrt{1-\frac{v^2}{c^2}}}$, the Lorentz factor. Now we have our relativistic equation of momentum,

\begin{align*}
  \mathbf{p} = \gamma m \mathbf{v}
\end{align*}

\end{document}


\documentclass{stdlocal}
\begin{document}
\section{Physical Simulations and Monte Carlo Methods} % (fold)
\label{sub:simulation_in_physics_and_mathematics}
  For our purposes, it is enough to explain the application of PRNGs to some given simulation procedures because there is no generic approach on how to randomize an arbitrary physical problem.
  Hence, we will not provide an excessive explanation to the theory of Monte Carlo methods and their application to general physical problems.
  Instead, the focus lies on the understanding of basic concepts and their implementation with respect to well-chosen examples.

  As mentioned in the introduction, section \ref{sec:introduction}, the simulation of physical and mathematical systems can be quite time intensive.
  Many degrees of freedom in a resulting partial differential equation make the problem infeasible to solve deterministically \autocite{landau2014}.
  This is typically called the \enquote{curse of dimensionality} \autocite{mueller2012}.
  As a consequence, we rely on probability theory to estimate the respective solutions and speed-up the simulation.
  Such randomized algorithms are in general called Monte Carlo methods \autocite{mueller2012,landau2014}.

  \begin{definition}[Monte Carlo Method]
    % A Monte Carlo method is an algorithm that uses the realization of random variables, also called random samples, to generate its result.
    A Monte Carlo method is a random variable that computes its result based on given random variables according to an algorithm.
    We call the realization of a Monte Carlo method a run or its execution.
  \end{definition}
  We will not give a rigorous definition of an algorithm but refer to \textcite{hromkovic2011} for detailed information.
  With this definition, the output of an execution of a Monte Carlo method is interpreted as a realization of random variables.
  In contrast to a deterministic algorithm, calling a Monte Carlo method twice with identical input arguments will not necessarily produce the same output again.
  This behavior lets them overcome the \enquote{curse of dimensionality} and as a result they represent an efficient family of generalized algorithms to solve high-dimensional problems.

  To get the idea behind Monte Carlo methods, the observation of direct simulations as given in \textcite{mueller2012} will serve perfectly.
  For some dimension $d\in\setNatural$, we want to approximate a value $r\in\setReal^d$ by a Monte Carlo method.
  Direct simulation needs an already existent sequence of iid random variables with their expectation value equal to $r$ which we interpret as random samples.
  But this does not impose strong restrictions because we are mostly able to find such random variables.

  \begin{lemma}[Direct Simulation]
    Let $d\in\setNatural$, $r\in\setReal^d$ and $(X_n)_{n\in\setNatural}$ a sequence of $\setReal^d$-valued iid random variables in $\setIntegrable^2\roundBrackets{\setReal^d,λ}$ with $\expect X_n = r$ for all $n\in\setNatural$.
    In this case, construct the following random variable for all $n\in\setNatural$.
    \[
      D_n \define \frac{1}{n}\sum_{k=1}^n X_k
    \]
    Then for arbitrary sample counts $n\in\setNatural$ the random variable $D_n$ is a Monte Carlo method which fulfills the following equations.
    \[
      \expect D_n = r
      % \separate
      % \var D_n = \frac{\var X_k}{n}
      \separate
      \stddev(D_n) = \frac{\stddev(X_1)}{\sqrt{n}}
      \separate
      \lim_{n\to\infty} \stddev(D_n) = 0
    \]
    % Using the SLLN, we get the following almost everywhere.
    Furthermore, the following limit holds almost everywhere.
    \[
      \lim_{n\to\infty} D_n = r
    \]
  \end{lemma}
  We will give no proof of this lemma and instead refer to \textcite{mueller2012}.
  Please note that the last limit follows from Theorem \ref{theorem:slln} the SLLN.
  The expectation value of the given method is always the result that we wanted to compute.
  This is not a special property.
  But looking at the standard deviation, the error of the direct simulation becomes smaller for a bigger sample count.
  Using a large number of samples will therefore estimate the actual result much more precisely.
  Additionally, the error is decreasing with $\frac{1}{\sqrt{n}}$.
  Hence, the error rate is independent of the given dimension which explains the overcoming of the \enquote{curse of dimensionality}.

  \subsection{Monte Carlo Integration and the Computation of $π$} % (fold)
  \label{sub:monte_carlo_integration}
    Many simulations involve the calculation of multidimensional integrals.
    As a consequence, the so-called Monte Carlo integration forms the natural application of the direct simulation.
    We want to estimate the integral of a function.
    For given uniformly distributed random variables, we will construct a sequence of random variables such that their expectation value will coincide with the integral.
    \autocite{mueller2012}

    \begin{definition}[Monte Carlo Integration]
    \label{definition:monte-carlo-integration}
      Let $d\in\setNatural$ be the dimension, $U\subset\setReal^d$ be a measurable and bounded subset, such that $0 < λ(U) < \infty$, and $f\in\setIntegrable^2(U,λ)$ the function to be integrated.
      Furthermore, let $(X_n)_{n\in\setNatural}$ be a sequence of iid, $U$-valued, and uniformly distributed random variables.
      Then the Monte Carlo integration of $f$ with $n$ samples on the domain $U$ is given by the following expression.
      \[
        \mathrm{MCI}_n(f) \define \frac{λ(U)}{n} \sum_{k=1}^n f\circ X_k
      \]
    \end{definition}
    The domain of definition has to be restricted so that the method has a chance of reducing the overall estimation error.
    Additionally, the function $f$ should be square-integrable such that we are able to get an upper bound on the standard deviation.
    The following lemma will show that Monte Carlo integration is indeed a Monte Carlo method with the properties of a direct simulation.
    \autocite{mueller2012}

    \begin{lemma}[Monte Carlo Integration Estimates Value of Integral]
    \label{lemma:monte-carlo-integration}
      Choose the same setting as in the above definition \ref{definition:monte-carlo-integration}.
      In this case for all $n\in\setNatural$, the Monte Carlo integration $\mathrm{MCI}_n(f)$ is a Monte Carlo method and the following statements for the expectation value and standard deviation are fulfilled.
      \[
        \expect \mathrm{MCI}_n(f) = \integral{U}{}{f}{λ}
        \separate
        \stddev\boxBrackets{\mathrm{MCI}_n(f)} \leq \sqrt{\frac{λ(U)}{n} \integral{U}{}{f^2}{λ}}
      \]
    \end{lemma}
    % \begin{proof}[Lemma \ref{lemma:monte-carlo-integration} on page \pageref{lemma:monte-carlo-integration}]
    %   Let $p$ be the probability density of $X_n$.
    %   Because the random variables are uniformly distributed on $U$, we can express it as follows.
    %   \[
    %     \function{p}{U}{[0,\infty)}
    %     \separate
    %     p(x) \define \frac{1}{λ(U)}
    %   \]
    %   By using substitution and chaining from propositions \ref{proposition:substitution} and \ref{proposition:chaining}, the expectation value can be directly computed.
    %   \[
    %     \begin{aligned}[t]
    %       \expect \mathrm{MCI}_n(f)
    %       &= \expect \boxBrackets{ \frac{λ(U)}{n} \sum_{k=1}^n f\circ X_k }
    %       = \frac{λ(U)}{n} \sum_{k=1}^n \expect(f\circ X_k) \\
    %       &= λ(U) \integral{U}{}{f(x) p(x)}{λ(x)}
    %       = \integral{U}{}{f}{λ}
    %     \end{aligned}
    %   \]
    %   For the standard deviation, first the variance will be observed.
    %   Since the sequence of random variables is stochastically independent, the sum can be taken out of the argument.
    %   Afterwards, we again apply substitution and chaining.
    %   \[
    %     \begin{aligned}
    %       \var \mathrm{MCI}_n(f) &= \var\boxBrackets{ \frac{λ(U)}{n} \sum_{k=1}^n f\circ X_k } = \frac{λ(U)^2}{n^2} \sum_{k=1}^n \var\roundBrackets{f\circ X_k} \\
    %       &= \frac{λ(U)^2}{n^2} \sum_{k=1}^n \expect\roundBrackets{f\circ X_k}^2 - \boxBrackets{\expect\roundBrackets{f\circ X_k}}^2 \\
    %       &\leq \frac{λ(U)^2}{n^2} \sum_{k=1}^n \expect\roundBrackets{f\circ X_k}^2 = \frac{λ(U)^2}{n} \integral{U}{}{f^2(x) p(x)}{λ(x)} \\
    %       &= \frac{λ(U)}{n} \integral{U}{}{f^2}{λ}
    %     \end{aligned}
    %   \]
    %   The inequality is now inferred by the definition of the standard deviation which proofs the lemma.
    %   \[
    %     \stddev\boxBrackets{\mathrm{MCI}_n(f)} = \sqrt{\var \mathrm{MCI}_n(f)} \leq \sqrt{\frac{λ(U)}{n} \integral{U}{}{f^2}{λ}}
    %   \]
    % \end{proof}
    In the proof, seen in appendix \ref{sec:proofs}, we basically applied the lemma about the direct simulation.
    So we get the same convergence rate for the expectation value with respect to the standard deviation.
    To get a deeper understanding of this method, consider the estimation of $π$ by Monte Carlo integration.
    For this, we would like to compute the area of a quarter of a circle which is strongly related to π.
    Figure \ref{fig:pi-computation-points} shows the execution of the following process for different realizations.

    \begin{figure}
      \center
      \begin{subfigure}[b]{0.32\linewidth}
        \center
        \includegraphics[width=\linewidth]{examples/monte_carlo_pi_100_87.pdf}
        \caption{%
          \quad
          \begin{minipage}[t]{0.5\linewidth}
            $n = 100$ \\
            $s = 87$ \\
            $μ = 3.48$ \\
            $ε \approx 1.07 \cdot 10^{-1}$
          \end{minipage}
        }
      \end{subfigure}
      \hfill
      \begin{subfigure}[b]{0.32\linewidth}
        \center
        \includegraphics[width=\linewidth]{examples/monte_carlo_pi_1000_765.pdf}
        \caption{%
          \quad
          \begin{minipage}[t]{0.5\linewidth}
            $n = 1000$ \\
            $s = 765$ \\
            $μ = 3.06$ \\
            $ε \approx 2.60 \cdot 10^{-2}$
          \end{minipage}
        }
      \end{subfigure}
      \hfill
      \begin{subfigure}[b]{0.32\linewidth}
        \center
        \includegraphics[width=\linewidth]{examples/monte_carlo_pi_10000_7856.pdf}
        \caption{%
          \quad
          \begin{minipage}[t]{0.5\linewidth}
            $n = 10000$ \\
            $s = 7856$ \\
            $μ = 3.1424$ \\
            $ε \approx 2.57 \cdot 10^{-4}$
          \end{minipage}
        }
      \end{subfigure}
      \caption[Monte Carlo Integration and the Computation of π]{%
        Sample points for different realizations of the Monte Carlo integration $\mathrm{MCI}_n(f)$ for the computation of π.
        Points that lie in the quarter of the unit circle are shown in blue color whereas other points are shown in orange color.
        The unit circle is represented by a black line.
        The result of the realizations is expressed by the sample mean μ and the relative error with respect to π is expressed by ε.
        The variable $s$ names the count of samples that lie in the unit circle.
      }
      \label{fig:pi-computation-points}
    \end{figure}

    Computing the area of a subset is in general done by integration.
    Therefore we choose $d=2$ and $U\define [0,1]^2$ with $λ(U) = 1$.
    Thus, the random variable $X_n$ will be uniformly distributed on $[0,1]^2$ for all $n\in\setNatural$.
    The last part consists of the construction of the function $f$.
    First, define the set which characterizes the quarter of the unit circle.
    \[
      G \define \set{x \in [0,1]^2}{\norm{x} \leq 1}
      \separate
      λ(G) = \frac{π}{4}
    \]
    Based on this set, the function $f$ can be expressed through the use of the characteristic function of $G$ and by scaling its value.
    \[
      f \define 4\cdot\mathds{1}_G
      \separate
      \expect \mathrm{MCI}_n(f) = \integral{U}{}{f}{λ} = 4 \integral{[0,1]^2}{}{\mathds{1}_G}{λ} = 4\cdotλ(G) = π
    \]
    Simulating the integral of $f$ will therefore give us an estimation of π.
    For a more detailed analysis, we will also compute the exact standard deviation of this Monte Carlo integration by using the above lemma \ref{lemma:monte-carlo-integration}.
    \[
      \integral{U}{}{f^2}{λ} = 16 \integral{[0,1]^2}{}{\mathds{1}_G}{λ} = 16\cdot λ(G) = 4π
    \]
    \[
      \begin{aligned}
        \var\roundBrackets{f\circ X_1}
        &= \expect\roundBrackets{f\circ X_1}^2 - \boxBrackets{\expect\roundBrackets{f\circ X_1}}^2
        = \integral{U}{}{f^2}{λ} - \roundBrackets{\integral{U}{}{f}{λ}}^2 \\
        &= 4π - π^2 = π(4-π)
      \end{aligned}
    \]
    \[
      \stddev\roundBrackets{\mathrm{MCI}_n(f)} = \sqrt{\frac{π(4-π)}{n}} \leq 2\sqrt{\frac{π}{n}} = \sqrt{\frac{λ(U)}{n} \integral{U}{}{f^2}{λ}}
    \]
    In figure \ref{fig:pi-computation-plots}, we can see this behavior for some actual simulations.
    By taking a larger amount of samples, the volume of the quarter of the unit circle becomes more occupied as can be seen in figure \ref{fig:pi-computation-points}.
    As a consequence, the estimation of π will be more precise.
    Furthermore, figure \ref{fig:pi-computation-plots} shows that the error of the estimation can also be estimated and will be more precise for a larger sample count.
    \autocite{mueller2012,landau2014,pharr2016}

    \begin{figure}
      \center
      \begin{subfigure}[b]{0.49\linewidth}
        \center
        \includegraphics[width=\linewidth]{examples/monte_carlo_pi_plot.pdf}
      \end{subfigure}
      \begin{subfigure}[b]{0.49\linewidth}
        \center
        \includegraphics[width=\linewidth]{examples/monte_carlo_pi_plot_error.pdf}
      \end{subfigure}
      \caption[Monte Carlo Integration Plots for the Computation of π]{%
        Each of the diagram shows two different versions, colored in orange and blue, of realizations of the Monte Carlo integration $\mathrm{MCI}_n(f)$ for the computation of π for different values of $n$.
        The left one displays the estimated value of π and the right one displays its relative error with respect to π.
        The black line hereby shows the exact relative standard deviation with respect to π of the Monte Carlo integration.
      }
      \label{fig:pi-computation-plots}
    \end{figure}

    Later, we will use the computation of π as benchmark routine to measure the performance of PRNGs with respect to different aspects of their implementation.
    In these cases, the error of π should be in some given range.
    Assume we want to use $10^8$ samples to estimate the value of π.
    According to the formula above for the standard deviation, we get an error of approximately $0.00016$ which means we should at least get a precision of four digits, such that π should approach the value $3.1415$ with a varying last digit.

    To use the described Monte Carlo integration for estimating π, an actual implementation in C++ is needed.
    The following code snippet provides the basic algorithm relying on the random utilities given by the STL of the C++ programming language.
    Because C++ is a strongly typed language which is working with templates for type abstraction, the given code uses templates to generalize the usage of different RNG types, as well as different real and integer number types.
    Typically, we will use the \code{float} type as the real number type and the \code{int} type as the integer type.

    \inputCodeBlock[title=Basic Monte Carlo π Computation]{code/monte_carlo_pi.hpp}
    The implementation of the algorithm does not introduce any irregularities and can directly be deduced from the mathematical formulation.
    First, we define the standard uniform distribution for the RNG and an integer number \code{samples\_in\_circle} as zero which will be used to count the number of samples that lie inside the unit circle.
    In the following \code{for} loop every run will construct two uniformly distributed random numbers which together will define the position of a random two-dimensional point in the unit square.
    We then evaluate the circle condition and add its result to \code{samples\_in\_circle} incrementing it by one if the condition is true and by zero otherwise.
    At the end, the code computes the correct result by calculating the division and scaling the output.

    % The application of the given library function is shown in the following source file.
    % \inputCodeBlock[title=monte\_carlo\_pi.cpp]{code/monte_carlo_pi.cpp}

    The computation of π is only an academic example that should not be used in reality because there are much more efficient ways to estimate it.
    But as we will see, it is perfectly suited as a benchmark to test different kinds of RNGs because the main part of the algorithm consists of generating a lot of random numbers while using their values to actually compute a result.
    Evaluating the circle condition for generated random numbers is fast and will not introduce a lot of bias in the actual measurement.
    Besides, it is the most common example of a non-trivial Monte Carlo integration.
    A lot of physical problems rely on Monte Carlo integration.
    In the end, all these problems can be broken down into similar forms as the computation of π.
    \autocite{mueller2012,landau2014,pharr2016}
  % subsection monte_carlo_integration_and_the_computation_of_ (end)

  % \subsection{Metropolis-Hastings Algorithm and the Ising Model} % (fold)
  % \label{sub:metropolis_hastings_algorithm_and_the_ising_model}

  % subsection metropolis_hastings_algorithm_and_the_ising_model (end)

  \subsection{Photon Propagation and Physically Based Rendering} % (fold)
  \label{sub:photon_propagation_and_physically_based_rendering}
    A photon is an elementary particle and the quantum of the electromagnetic field.
    It exhibits properties of both waves, like wavelength and polarization, and particles, such as position and momentum.
    This is also known as wave-particle duality.
    In vacuum, photons always move at the speed of light.
    Their invariant mass is zero and therefore they are thought of as massless particles.
    Due to Heisenberg's uncertainty principle, we are in general not able to measure their position and momentum at the same time with infinite precision.
    Because we are concerned about the photon propagation in space at a large scale, we will use an abstract concept of a photon to approximate physical laws and making simulations feasible.
    We think of an abstract photon as a packet of photons with a definite position and velocity representing their respective expectation values of all the photons inside the packet.
    Since the positions and velocities are then based on statistical calculations, this will allow us to ignore the uncertainty principle.
    Additionally, we assume no particular polarization or wavelength in the packet can be determined.
    Thus, the wavelength will be ignored and the abstract photon will be seen as unpolarized.
    \autocite{landau2014}

    In computer graphics, the rendering of realistic images based on physical principles requires the simulation of global illumination effects.
    Global illumination is formally described by the so-called rendering equation, also known as light transport equation (LTE).
    There exist several different formulations of the LTE, such as the surface form and the path integral formulation, which are all equivalent and are used to derive advanced methods to actually estimate the light distribution in space consisting of differing objects.
    The LTE can be derived by applying principles of geometric optics to the law of the conservation of energy for electromagnetic radiation.
    A detailed explanation is given in \textcite{pharr2016} and a mathematically rigorous discussion can be read in \textcite{pawellek2017}.

    \begin{figure}
      \center
      \includegraphics[width=0.9\textwidth]{images/audi_r8_path_tracing.png}
      \caption[Path Tracing Example]{%
        Example scene showing an Audi R8 rendered by the path tracing algorithm.
        The simulation included ideal reflections and refractions, as well as the diffuse scattering of light at the surfaces.
        The simulation used $1024$ samples per pixel to reduce the noise of the image.
        \autocite{pawellek2017}
      }
      \label{fig:path-tracing-r8}
    \end{figure}

    Typically, the LTE cannot be evaluated analytically for complex geometries.
    As a consequence, there are multiple famous simulation strategies, like path tracing, bidirectional path tracing, metropolis light transport, and photon mapping, to approximate its solutions.
    All of these strategies have in common that they are somehow estimating the light distribution in space through Monte Carlo methods.
    Because of the integral appearing inside the equation, all algorithms make great use of Monte Carlo integration in different ways.
    Path tracing, for example, is using the path integral formulation of the LTE by importance sampling different paths of light through the scene starting from the observer and ending at a light source.
    At every vertex of the path, \enquote{Russian roulette} decides if the ray has to be reflected, transmitted or absorbed.
    In general, the algorithm has to compute several hundreds of sample paths for every pixel on the screen to reduce the noise and get an acceptable estimation  of the actual light distribution.
    Figure \ref{fig:path-tracing-r8} shows an example scene rendered by the path tracing algorithm for which more than a thousand samples per pixel had to be generated.
    As a consequence, the tracing of rays and the propagation of photons through a scene needs to use a really large amount of random numbers.
    \autocite{pharr2016}

    The tracing of light rays is strongly connected to photon propagation in space.
    From an abstract point of view, we can think of light rays as packets of photons.
    Light rays are used to gather the radiance arriving at the observer whereas photons propagate flux from a light source.
    At large scale, both of them adhere to the same laws even if they are interpreted differently.
    Hence, photon tracing works exactly the same way as ray tracing.
    A usual application of this phenomenon is the photon mapping algorithm.
    The movement and transmission of differing photons or rays does not depend on each other.
    Due to the high amount of random numbers needed and the large degree of independence, the simulation of global illumination by using Monte Carlo methods seems to be convenient to measure the performance improvement by applying vectorized PRNGs.
    This claim is even supported by an already existing strong usage of SIMD instructions for the current most efficient ray and path tracing engines \autocite{embree}.

    In this thesis, it is not possible to provide a complete ray tracing framework to test the application of vectorized PRNGs.
    But we are able to construct a simplified version which is using the developed PRNGs to simulate the propagation of photons.
    This smaller simulation focuses on the most important physical effects and ignores subtleties that would introduce bias in the performance measurements.
    We will provide the physical background concerning photon propagation.

    % \begin{definition}[Photon]

    % \end{definition}

    % \subsubsection*{Surface Interaction} % (fold)
    % \label{ssub:surface_interaction}
    %   The interaction of photons with surfaces of objects is strongly associated with the properties of the materials the objects consist of.
    %   Typically, the behavior can be modeled by bidirectional scattering distribution functions (BSDFs) which give the portion of light scattered in the outgoing direction with respect to the incoming direction.
    %   Concerning photons, for a fixed incoming direction BSDFs can be thought of as probability densities over the outgoing direction of the photon after the surface scattering has taken place.
    %   We refer again to \textcite{pharr2016} and \textcite{pawellek2017}.
    %   To simulate complex optical properties of object materials BSDFs have to be sampled with the usage of appropriate random variables.
    %   In this context, we will only assume ideal reflection and refraction of photons to not introduce unnecessary complexness to the application.

    %   \begin{figure}
    %     \center
    %     \includegraphics[height=0.3\textwidth]{figures/reflection_refraction_scheme.pdf}
    %     \caption[Ideal Reflection and Refraction]{%
    %       Ideal reflection and refraction scheme and notation.
    %       The surface with surface normal $n$ separates the outer medium with refractive index $η_\mathrm{i}$ from the inner medium with refractive index $η_\mathrm{t}$.
    %       $ω_\mathrm{i}$, $ω_\mathrm{r}$, and $ω_\mathrm{t}$ denote the incoming, reflection, and refraction direction, respectively.
    %     }
    %     \label{fig:reflection-refraction-scheme}
    %   \end{figure}

    %   Ideal reflection of a photon means that the angle between its incoming direction and the surface normal is the same as the angle between the outgoing direction and the surface normal.
    %   In general, we can define it as follows.

    %   \begin{definition}[Ideal Reflection]
    %     For any incoming direction $ω_\mathrm{i}\in \mathscr{S}^2$ its ideally reflected direction $ω_\mathrm{r}$ with respect to a surface with surface normal $n\in\mathscr{S}^2$ is given by the following equation.
    %     \[
    %       ω_\mathrm{r} = ω_\mathrm{i} - 2 \scalarProduct{n}{ω_\mathrm{i}} n
    %     \]
    %   \end{definition}
    %   A refractive index is a dimensionless number and represents the slow-down in speed when light is traveling through the according medium.
    %   The ideal refraction of photons traveling through a surface which is separating two media with varying refractive indices can be described by the following definition.

    %   \begin{definition}[Ideal Refraction]
    %     For any incoming direction $ω_\mathrm{i}\in \mathscr{S}^2$ its ideally refracted direction $ω_\mathrm{t}$ with respect to a surface with surface normal $n\in\mathscr{S}^2$ is given by the following equation.
    %     \[
    %       ω_\mathrm{t} =
    %       \begin{cases}
    %         \frac{η_\mathrm{i}}{η_\mathrm{t}} \roundBrackets{ ω_\mathrm{i} - \scalarProduct{n}{ω_\mathrm{i}} n} - \sqrt{ξ} n & :ξ > 0 \\
    %         ω_\mathrm{r} & :ξ \leq 0
    %       \end{cases}
    %     \]
    %     \[
    %       ξ \define \frac{η^2_\mathrm{i}}{η^2_\mathrm{t}}\roundBrackets{1 - \scalarProduct{n}{ω_\mathrm{i}}^2}
    %     \]
    %     Hereby, we assume that $ω_\mathrm{r}$ is the ideally reflected direction and that the surface is separating the outer medium with refractive index $η_\mathrm{i}\in [1,\infty)$ from the inner medium with refractive index $η_\mathrm{t}\in [1,\infty)$.%
    %   \end{definition}
    %   Figure \ref{fig:reflection-refraction-scheme} shows ideal reflection and refraction schematically.
    %   The connection between the angle of incidence and the angle of emergence is given by Snell's law.
    %   If the outer medium exhibits a larger refractive index than the inner medium then there exists a critical incident angle at which total reflection of the incoming photon occurs.
    %   This explains the distinction of cases in the above definition.
    %   Here, the second case represents total reflection.

    %   A photon can either be reflected or transmitted but not both at the same time.
    %   Hence, the surface coefficients $α,β\in [0,1]$ for reflection and refraction with $α+β=1$ of photons should be interpreted as probabilities.
    %   The interaction process can then be described by a probability density $p_{\omega_\mathrm{i}}$ over the outgoing directions $ω_\mathrm{o}\in \mathscr{S}^2$ with a fixed incoming direction $ω_\mathrm{i}\in\mathscr{S}^2$.
    %   In the case of ideal reflection $ω_\mathrm{r}$ and refraction $ω_\mathrm{t}$, we have
    %   \[
    %     p_{ω_\mathrm{i}}(ω_\mathrm{o}) \define α δ_{ω_\mathrm{o}}(ω_\mathrm{r}) + β δ_{ω_\mathrm{o}}(ω_\mathrm{t})
    %   \]
    %   where $δ_{ω_\mathrm{o}}$ denotes the Dirac delta distribution over $\mathscr{S}^2$.
    %   To sample the photon paths from such a probability density, Russian roulette is used to choose between reflection and refraction.

    %   \begin{lemma}[Russian Roulette]
    %     Choose the same settings as in definition \ref{definition:monte-carlo-integration}.
    %     Furthermore, assume $α,β\in [0,1]$ with $α+β=1$ and $f=αf_1 + βf_2$ for functions $f_1,f_2\in\mathrm{L}^2(U,λ)$.
    %     We define the roulette function $R$ as follows.
    %     \[
    %       \function{R}{[0,1]}{\set{1,2}{}}
    %       \separate
    %       R(x) \define
    %       \begin{cases}
    %         1 &: x \leq α \\
    %         2 &: \mathrm{else}
    %       \end{cases}
    %     \]
    %     In this case, for all $x\in U$ and $k\in\setNatural$ the following equation holds.
    %     \[
    %       f(x) = \expect f_{R\circ X_k} (x)
    %     \]
    %   \end{lemma}
    %   We will give no proof of this lemma.
    %   Russian roulette does not introduce any bias and allows us to only choose one path for the photon.
    %   This comes at the cost of a higher variance of the estimation.
    %   If we would evaluate both, reflection and refraction, at once and scale the results according to α and β then the estimation would have a variance of zero.
    %   But always tracing the possible paths soon becomes infeasible due to the exponential growth of different paths for every surface interaction.
    %   Russian roulette reduces this computational amount.
      % \[
      %   \mathrm{RR} \define \frac{λ(U)}{n} \sum_{k=1}^n f_{R(X_{2k})}\circ X_{2k-1}
      % \]
    % subsubsection surface_interaction (end)

    \subsubsection*{Volume Scattering} % (fold)
    \label{ssub:volume_scattering}
      Photons propagating through participating media are affected by absorption and scattering.
      Both processes are in general modeled by statistical processes.
      For our purpose, absorption will be ignored to reduce the complexity of the physical simulation.
      Scattering changes the direction of the photon.
      This process is described by rotation matrices and therefore scattering is much more appropriate for vectorization than absorption.
      \autocite{pharr2016}

      As a photon passes through a medium, it may collide with other particles and be scattered in different directions.
      The probability of a scattering event is modeled by the scattering coefficient which in our case equals to the extinction.
      We will only assume homogeneous media with a constant extinction.
      Hence, the actual probability of a scattering event after traveling a short distance is given by Beer's law.
      Because we want to show the application of RNGs to physical simulations, it is sufficient to directly define this probability without using the extinction.
      \autocite{pharr2016}

      Scattering itself is described by phase functions which are probability densities.
      Based on an incoming direction, they give the probability that the photon will be scattered in a certain outgoing direction.
      In this thesis, isotropic phase functions are used.
      They are invariant under rotations and therefore only depend on the angle between the incoming and outgoing direction.
      According to \textcite{pharr2016}, a widely used family of phase functions was developed by Henyey and Greenstein in the year 1941.
      This family cannot be deduced by physical laws but instead was specifically designed to be easy to fit to measured scattering data by only using a single parameter.
      \autocite{pharr2016,wang1995}

      \begin{definition}[Henyey-Greenstein Family of Phase Functions]
        Let $g\in [-1,1]$ be the asymmetry parameter, $ω_\mathrm{i}\in\mathscr{S}^2$ be the incoming direction of a photon and $ω_\mathrm{o}\in\mathscr{S}^2$ be a possible outgoing direction.
        The probability density $\function{p}{[-1,1]}{[0,\infty)}$ describing the distribution of $\cos ϑ \define \scalarProduct{ω_\mathrm{i}}{ω_\mathrm{o}}$ after a scattering process has taken place is then given by the following equation.
        \[
          p_g(\cos ϑ) \define \frac{1}{2} \frac{1-g^2}{(1+g^2 - 2g\cos ϑ)^{\frac{3}{2}}}
        \]
      \end{definition}
      To actually use the probability density $p_g$, we have to sample it.
      That means we have to construct a sequence of iid random variables with a distribution given by $p_g$.
      For this we will rely on a uniformly distributed sequence of iid random variables by applying a transformation to change their distribution.
      The following lemma can be shown by using the inversion method.
      A detailed derivation is given in \textcite{wang1995}.

      \newpage

      \begin{lemma}[Sampling Henyey-Greenstein Phase Functions]
        Let $g\in [-1,1]$ be the asymmetry parameter, $(X_n)_{n\in\setNatural}$ be a uniformly distributed sequence of iid random variables in the unit interval.
        Furthermore, let $(\cos ϑ_n)_{n\in\setNatural}$ be a sequence of random variables given by the following transformation.
        \[
          \cos ϑ_n =
          \begin{cases}
            \frac{1}{2g} \boxBrackets{1 + g^2 - \roundBrackets{\frac{1-g^2}{1-g+2gX_n}}^2} &: g\neq 0 \\
            2X_n - 1 &: g = 0
          \end{cases}
        \]
        Then, $(\cos ϑ_n)$ is a sequence of iid random variables distributed according to $p_g$.
      \end{lemma}
      The given lemma makes it possible to simulate scattering processes adhering to the probability density $p_g$ only by using uniformly distributed random numbers in the unit interval.

    % subsubsection volume_scattering (end)
  % subsection photon_propagation_and_physically_based_rendering (end)
% section simulation_in_physics_and_mathematics (end)
\end{document}


%!TEX root=../paper.tex
The ChaCha cipher is a 256-bit stream cipher, designed by Bernstein in 2008~\cite{Ber:08}.
ChaCha based on the Salsa stream cipher has naturally a high-throughput performance on software platforms.
Compared to Salsa, ChaCha has better diffusion per round and conjecturally increasing resistance to cryptanalysis.

\subsection{Encryption and Decryption}
The ChaCha encryption and decryption can have the same process in which the input data stream is encrypted or decrypted by chopping the input into 64-byte blocks and Xor-ing them with the 64-byte output blocks of the ChaCha block function. The block function processes on the ChaCha state matrix of $4\times4$ word (32-bit) elements to generate the 64-byte output block.
The ChaCha state matrix is initiated by a 4-word constant, an 8-word secret key, 4 words of counter/nonce.
Note that the original ChaCha uses a 2-word nonce and a 2-word counter to allowing a practically unlimited amount of data to be encrypted while the IETF variant~\cite{RFC:18} increases the nonce size to 3 words, but reduces the counter size down to one word.
That limits the amount of encrypted data only up to 256 GB but helps the encryption more safely with a longer (key, nonce) pair.
This paper adopts the IETF variant of which the initial state matrix is shown in (\ref{equ:bg:ChaChaMatix}). %~\REFFIG{fig:bg:ChaChaMatix}.
The ChaCha process for encryption and decryption can be described as in Algorithm~\ref{alg::ChaCha::process}.

%\begin{figure}
%	\centering
%	\includegraphics[scale=0.5]{figures/ChaChaState.png}
%	\caption{ChaCha Initiate State Matrix}
%	\vspace{-10pt}
%	\label{fig:bg:ChaChaMatix}
%\end{figure}
\begin{equation}
S=
\begin{pmatrix}
$61707865$ & $3320646E$ & $79622D32$ & $6B206574$ \\
key[$0$] & key[$1$]   & key[$2$]   & key[$3$] \\
key[$4$] & key[$5$]   & key[$6$]   & key[$7$] \\
counter  & nonce[$0$] & nonce[$1$] & nonce[$2$] \\
\end{pmatrix}
\label{equ:bg:ChaChaMatix}
\end{equation}

\subsection{Block function}
ChaCha cipher family provides three variants which use different number
of operations performed on the state (i.e., $8$, $12$ or $20$ rounds).
A larger number of rounds increases data diffusion and therefore more secure, but longer processing time.
From now on, we focus on the ChaCha20 variant that executes $20$ rounds in a block function.
The block function processes a state matrix using odd rounds and even rounds alternately.
Then, the processed state matrix is added to the input state matrix to result in the output state matrix.
The operation of the block function is described in Algorithm~\ref{alg::ChaCha::block}.

\paragraph{Round function} Both of the odd and even rounds have 4 quarter rounds.
In the odd (column) round, the quarter rounds operate on four elements of the state matrix's columns,
while the quarter rounds of the even (diagonal) round operate on the diagonals of the state matrix.
For some implementations, one can view that a diagonal round can be equivalent to a column round, and vice versa, if the state matrix is rearranged (rotating the matrix's columns 1, 2, and 3) before the rounds.

\paragraph{Quarter-Round function} A quarter round updates four state words of the state matrix as shown in~Algorithm~\ref{alg::ChaCha::quarterround}.
The quarter round based on Add-Rotate-Xor (ARX) operations requires four sets of 32-bit Additions, Xors and  rotations operating on the state words.
Each word is updated twice and affected by all four input words.

\begin{algorithm}
	\KwData  { 256-bit $Key$, 96-bit $Nonce$, L-bit $P$
	}
	\KwResult{ L-bit $C$
	}
	\BlankLine
	\KwFn{$\ALG{ChaChaProcess}( Key, Nonce, P )$}{
		/*Init state matrix*/ \;
		$S[0] \ASN \VERB{0x61707865}, S[1] \ASN \VERB{0x3320646e}$ \;
		$S[2] \ASN \VERB{0x79622d32}, S[3] \ASN \VERB{0x6b206574}$ \;
		$S[4..11] \ASN Key, S[13..15] \ASN Nonce$ \;
		/*Encrypting loop*/ \;
		\For{$i = 0$ {\bf upto} $\lceil\frac{L}{512}\rceil - 1$} {
			$S[12] \ASN i$ \;%\tcp{update counter}
			$K_i \ASN \ALG {ChaChaBlock}( S )$ \;
			$C_i \ASN K_i \XOR P_i$   \;%\tcp{perform encryption}
		}
		$\KwRet{~C}$ \;
	}
	\caption{ChaCha Stream Cipher Process.}
	\label{alg::ChaCha::process}
\end{algorithm}

\begin{algorithm}
	\KwData  { input state matrix $S$ of 16 32-bit state elements
	}
	\KwResult{ output state matrix $K$
	}
	\BlankLine
	\KwFn{$\ALG{ChaChaBlock}( S )$}{
%		/*copy the original state*/ \;
		$X \ASN S$ \;
		\For{$i = 1$ {\bf upto} $10$} {
			/*Odd Round*/ \;
			$\ALG{QuarterRound}( X[0],~X[4],~X[8],~X[12] )$ \;
			$\ALG{QuarterRound}( X[1],~X[5],~X[9],~X[13] )$ \;
			$\ALG{QuarterRound}( X[2],~X[6],~X[10],X[14] )$ \;
			$\ALG{QuarterRound}( X[3],~X[7],~X[11],X[15] )$ \;
			/*Even round*/ \;
			$\ALG{QuarterRound}( X[0],~X[5],~X[10],X[15] )$ \;
			$\ALG{QuarterRound}( X[1],~X[6],~X[11],X[12] )$ \;
			$\ALG{QuarterRound}( X[2],~X[7],~X[8]~,X[13] )$ \;
			$\ALG{QuarterRound}( X[3],~X[4],~X[9]~,X[14] )$ \;
		}
		$K \ASN X + S$ \;
		$\KwRet{~K}$ \;
	}
	\caption{ChaCha Block function.}
	\label{alg::ChaCha::block}
\end{algorithm}

\begin{algorithm}
\KwData  { $A$, $B$, $C$, $D$ (32-bit state emelents).
}
\KwResult{ $A$, $B$, $C$, $D$ (Updated 32-bit state emelents).
}
\BlankLine
\KwFn{$\ALG{QuarterRound}( A, B, C, D )$}{
    /*Top half*/ \;
	$A \ASN A + B,~D \ASN D \XOR A,~D \ASN D \LRT 16$ \;
	$C \ASN C + D,~B \ASN B \XOR C,~B \ASN B \LRT 12$ \;
    /*Bottom half*/ \;
	$A \ASN A + B,~D \ASN D \XOR A,~D \ASN D \LRT  8$ \;
	$C \ASN C + D,~B \ASN B \XOR C,~B \ASN B \LRT  7$ \;
  $\KwRet{\TUPLE{ A, B, C, D }}$ \;
}
\caption{ChaCha Quarter Round.}
\label{alg::ChaCha::quarterround}
\end{algorithm}


% $Id: lpdo.tex 550 2010-02-24 19:31:24Z thomas-sturm $
\documentclass[a4paper]{article}

\usepackage{amsmath,amssymb}
\usepackage{enumerate}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Sym}{\operatorname{Sym}}
\newenvironment{reduce}{\begin{scriptsize}\begin{verbatim}}%
{\end{verbatim}\end{scriptsize}}

\newcommand{\txt}{\textrm}
\newenvironment{ebnf}{\begin{tabular}{rcll}}{\end{tabular}}
\newcommand{\ebnfvar}[1]{{\textit{#1}}\ \ }
\newcommand{\ebnfvara}[1]{$\left\langle \text{\textit{#1}}\right\rangle$\ \ }
\newcommand{\ebnfor}{\txt{\ $|$\ \ }}
\newcommand{\ebnfterm}[1]{\txt{\textbf{\texttt{#1}}}\ \ }
\newcommand{\ebnfoption}[1]{\txt{$\left[\;\text{#1}\;\right]$}\ \ }
\newcommand{\ebnfmult}[1]{\txt{$\left\{\;\text{#1}\;\right\}$}\ \ }
\newcommand{\ebnfattrib}[1]{{$\bigl\{$\ {#1}\ $\bigr\}$}\ \ }

\newcommand{\ebnfrule}[2]{{#1}&$\ \ \rightarrow\ \ $&{#2}&\\}
\newcommand{\ebnfrulev}[2]{{\ebnfvar{#1}}&$\ \ \rightarrow\ \ $&{#2}&\\}
\newcommand{\ebnfhalfrule}[1]{&&{\ebnfor {#1}}&\\}
\newcommand{\ebnfrulea}[3]{{#1}&$\ \ \rightarrow\ \ $&{#2}&{$\bigl\{$\ {#3}\ $\bigr\}$}\\}
\newcommand{\ebnfruleav}[3]{{\ebnfvar{#1}}&$\ \ \rightarrow\ \ $&{#2}&{$\bigl\{$\ {#3}\ $\bigr\}$}\\}
\newcommand{\ebnfhalfrulea}[2]{&&{\ebnfor {#1}}&{$\bigl\{$\ {#2}\ $\bigr\}$}\\}

\newcommand{\ebnfsinglerulev}[2]{\txt{{\ebnfvar{#1}}$\ \ \rightarrow\ \ ${#2}\\}}
\newcommand{\ebnfsinglerule}[2]{\txt{{#1}$\ \ \rightarrow\ \ ${#2}\\}}
\newcommand{\ebnfsingleruleav}[3]{\txt{{\ebnfvar{#1}}$\ \ \rightarrow\ \ ${#2}\ \ \ $\bigl\{$\ {#3}\ $\bigr\}$\\}}
\newcommand{\ebnfsinglerulea}[3]{\txt{{#1}$\ \ \rightarrow\ \ ${#2}\ \
    \ $\bigl\{$\ {#3}\ $\bigr\}$\\}}

\begin{document}
\title{LPDO: Linear Partial Differential Operators}
\author{Thomas Sturm\\
  Departamento de Matem\'aticas,
  Estad\'istica y Computaci\'on,\\
  Facultad de Ciencias,
  Universidad de Cantabria\\
  39071 Santander, Spain\\
  \texttt{sturmt@unican.es}}
\maketitle

\begin{abstract}

\end{abstract}

\section{Introduction}
Consider the field $F = \Q(x_1,\dots,x_n)$ of rational functions and a
set $\Delta = \{\partial_{x_1}$,\dots,~$\partial_{x_n}\}$ of
\emph{commuting derivations} acting on $F$. That is, for all
$\partial_{x_i}$, $\partial_{x_j} \in \Delta$ and all $f$, $g\in F$
the following properties are satisfied:
\begin{eqnarray}
\partial_{x_i}(f + g) &=& \partial_{x_i}(f) + \partial_{x_i}(g),\nonumber\\
\partial_{x_i}(f\cdot g) &=& f\cdot\partial_{x_i}(g)
  + \partial_{x_i}(f)\cdot g,\label{EQ:leibnitz}\\
\partial_{x_i}(\partial_{x_j}(f)) &=& \partial_{x_j}(\partial_{x_i}(f)).\label{EQ:comm}
\end{eqnarray}
%We call $(F,\Delta)$ a \emph{$\Delta$-field}.

Consider now the set $F[\partial_{x_1},\dots,\partial_{x_n}]$, where
the derivations are used as variables. This set forms a
non-commutative \emph{linear partial differential operator ring} with
pointwise addition, and multiplication defined as follows: For $f\in
F$ and $\partial_{x_i}$, $\partial_{x_j} \in \Delta$ we have for any
$g\in F$ that
\begin{eqnarray}
    (f \partial_{x_i})(g) &=& f \cdot \partial_{x_i}(g),\nonumber\\
    (\partial_{x_i} f)(g) &=& \partial_{x_i}(f \cdot g),\label{EQ:mult2}\\
    (\partial_{x_i} \partial_{x_j})(g) &=& \partial_{x_i}(\partial_{x_j}(g)).\label{EQ:mult3}
\end{eqnarray}
Here ``${}\cdot{}$'' denotes the multiplication in $F$. From
(\ref{EQ:mult3}) and (\ref{EQ:comm}) it follows that
$\partial_{x_i} \partial_{x_j}=\partial_{x_j} \partial_{x_i}$, and
using (\ref{EQ:mult2}) and (\ref{EQ:leibnitz}) the following
\emph{commutator} can be proved:
\begin{eqnarray*}
  \partial_{x_i} f &=& f \partial_{x_i} + \partial_{x_i}(f).
\end{eqnarray*}

A \emph{linear partial differential operator} (LPDO) of order $k$ is
an element
\begin{eqnarray*}
  D &=& \sum_{|j| \leq k} a_j \partial^j\in
  F[\partial_{x_1},\dots,\partial_{x_n}]
\end{eqnarray*}
in canonical form. Here the expression $|j| \leq k$ specifies the set
of all tuples of the form $j = (j_1,\dots,j_n) \in \N^n$ with
$\sum_{i=1}^n j_i \leq k$, and we define $\partial^j
= \partial_{x_1}^{j_1} \cdots \partial_{x_n}^{j_n}$.

A \emph{factorization} of $D$ is a non-trivial decomposition
\begin{eqnarray*}
D &=& D_1 \cdots D_r\in F[\partial_{x_1},\dots,\partial_{x_n}]
\end{eqnarray*}
into multiplicative factors, each of which is an LPDO $D_i$ of order
greater than $0$ and less than $k$. If such a factorization exists,
then $D$ is called \emph{reducible} or \emph{factorable}, else
\emph{irreducible}.

For the purpose of factorization it is helpful to temporarily consider
as regular commutative polynomials certain summands of the LPDO under
consideration. Consider a commutative polynomial ring over $F$ in new
indeterminates $y_1$, \dots,~$y_n$. Adopting the notational
conventions above, for $m\leq k$ the \emph{symbol of $D$ of order $m$}
is defined as
\begin{eqnarray*}
  \Sym_m(D) &=& \sum_{|j| = m} a_j y^j\in F[y_1,\dots,y_n].
\end{eqnarray*}
For $m=k$ we obtain as a special case the \emph{symbol $\Sym(D)$ of
  $D$}.

\section{Operators}

\subsection{\texttt{partial}}
There is a unary operator \texttt{partial($\cdot$)} denoting
$\partial$.

\begin{center}
  \begin{ebnf}
    \ebnfrule{\ebnfvara{partial-term}}{\ebnfterm{partial}\ebnfterm{(}\ebnfvara{id}\ebnfterm{)}}
  \end{ebnf}
\end{center}

\subsection{\texttt{***}}
There is a binary operator \texttt{***} for the non-commutative
multiplication involving partials $\partial_x$. All expressions
involving \texttt{***} are implicitly transformed into LPDOs, i.e.,
into the following normal form:
\begin{center}
  \begin{ebnf}
    \ebnfrule{\ebnfvara{normalized-lpdo}}{\ebnfvara{normalized-mon}\ebnfoption{\ebnfterm{+}\ebnfvara{normalized-lpdo}}}
    \ebnfrule{\ebnfvara{normalized-mon}}{\ebnfvara{F-element}\ebnfoption{\ebnfterm{***}\ebnfvara{partial-termprod}}}
%    \ebnfrule{\ebnfvara{F-element}}{\ebnfvara{standard-quotient}\ebnfor\ebnfvara{constant-operator}}
    \ebnfrule{\ebnfvara{partial-termprod}}{\ebnfvara{partial-term}\ebnfoption{\ebnfterm{***}\ebnfvara{partial-termprod}}}
  \end{ebnf}
\end{center}
The summands of the \textit{normalized-lpdo} are ordered in some
canonical way. As an example consider

\begin{footnotesize}
\begin{verbatim}
input: a()***partial(y)***b()***partial(x);

(a()*b()) *** partial(x) *** partial(y) + (a()*diff(b(),y,1)) *** partial(x)
\end{verbatim}
\end{footnotesize}
Here the \textit{F-elements} are polynomials, where the unknowns are
of the type \emph{constant-operator} denoting functions from $F$:

\begin{center}
  \begin{ebnf}
    \ebnfrule{\ebnfvara{constant-operator}}{\ebnfvara{id}\ebnfterm{(}\ebnfterm{)}}
  \end{ebnf}
\end{center}
We do not admit division of such constant operators since we cannot
exclude that such a constant operator denotes $0$.

The operator notation on the one hand emphasizes the fact that the
denoted elements are functions. On the other hand it distinguishes
\texttt{a()} from the variable \texttt{a} of a rational function,
which specifically denotes the corresponding projection. Consider e.g.

\begin{footnotesize}
\begin{verbatim}
input: (x+y)***partial(y)***(x-y)***partial(x);

  2    2
(x  - y ) *** partial(x) *** partial(y) + ( - x - y) *** partial(x)
\end{verbatim}
\end{footnotesize}
Here we use as \textit{F-elements} specific elements from $F=\Q(x,y)$.

\subsection{\texttt{diff}}
In our example with constant operators, the transformation into normal
form introduces a formal derivative operation
\texttt{diff($\cdot$,$\cdot$,$\cdot$)}, which cannot be evaluated.
Notice that we do not use the Reduce operator
\texttt{df($\cdot$,$\cdot$,$\cdot$)} here, which for technical reasons
cannot smoothly handle our constant operators.

In our second example with rational functions as \textit{F-elements},
derivative occurring with commutation can be computed such that
\texttt{diff} does not occur in the output.

\section{Shapes of F-elements}
Besides the generic computations with constant operators, we provide a
mechanism to globally fix a certain \emph{shape} for
\textit{F-elements} and to expand constant operators according to that
shape.
\subsection{\texttt{lpdoset}}
We give an example for a shape that fixes all constant operators to
denote generic bivariate affine linear functions:

\begin{footnotesize}
\begin{verbatim}
input: d := (a()+b())***partial(x1)***partial(x2)**2;

                                                2
d := (a() + b()) *** partial(x1) *** partial(x2)

input: lpdoset {!#10*x1+!#01*x2+!#00,x1,x2};

{-1}

input: d;

                                                                               2
(a00 + a01*x2 + a10*x1 + b00 + b01*x2 + b10*x1) *** partial(x1) *** partial(x2)
\end{verbatim}
\end{footnotesize}
Notice that the placeholder \texttt{\#} must be escaped with
\texttt{!}, which is a general convention for Rlisp/Reduce. Notice
that \texttt{lpdoset} returns the old shape and that \texttt{\{-1\}}
denotes the default state that there is no shape selected.

\subsection{\texttt{lpdoweyl}}
The command \texttt{lpdoweyl \{n,x1,x2,...\}} creates a shape for
generic polynomials of total degree \texttt{n} in variables
$\texttt{x1}$, $\texttt{x2}$, \dots.

\begin{footnotesize}
\begin{verbatim}
input: lpdoweyl(2,x1,x2);

                            2                                    2
{#_00_ + #_01_*x2 + #_02_*x2  + #_10_*x1 + #_11_*x1*x2 + #_20_*x1 ,x1,x2}

input: lpdoset ws;

{#10*x1 + #01*x2 + #00,x1,x2}

input: d;

                            2                                    2
(a_00_ + a_01_*x2 + a_02_*x2  + a_10_*x1 + a_11_*x1*x2 + a_20_*x1  + b_00_

                       2                                    2
  + b_01_*x2 + b_02_*x2  + b_10_*x1 + b_11_*x1*x2 + b_20_*x1 ) *** partial(x1)

                2
 *** partial(x2)
\end{verbatim}
\end{footnotesize}

\section{Commands}

\subsection{General}
\subsubsection{\texttt{lpdoord}}
The \emph{order} of an lpdo:
\begin{footnotesize}
\begin{verbatim}
input: lpdoord((a()+b())***partial(x1)***partial(x2)**2+3***partial(x1));

3
\end{verbatim}
\end{footnotesize}
%
\subsubsection{\texttt{lpdoptl}}
Returns the list of derivations (partials) occurring in its argument
LPDO $d$.

\begin{footnotesize}
\begin{verbatim}
input: lpdoptl(a()***partial(x1)***partial(x2)+partial(x4)+diff(a(),x3,1));

{partial(x1),partial(x2),partial(x4)}
\end{verbatim}
\end{footnotesize}
That is the smallest set $\{\dots,\partial_{x_i},\dots\}$ such that
$d$ is defined in $F[\dots,\partial_{x_i},\dots]$. Notice that formal
derivatives are not derivations in that sense.

\subsubsection{\texttt{lpdogp}}
Given a starting symbol $a$, a list of variables $l$, and a degree
$n$, \texttt{lpdogp($a$,$l$,$n$)} generates a generic (commutative)
polynomial of degree $n$ in variables $l$ with coefficients generated
from the starting symbol $a$:

\begin{footnotesize}
\begin{verbatim}
input: lpdogp(a,{x1,x2},2);

                           2                                    2
a_00_ + a_01_*x2 + a_02_*x2  + a_10_*x1 + a_11_*x1*x2 + a_20_*x1
\end{verbatim}
\end{footnotesize}

\subsubsection{\texttt{lpdogdp}}
Given a starting symbol $a$, a list of variables $l$, and a degree
$n$, \texttt{lpdogp($a$,$l$,$n$)} generates a generic differential
polynomial of degree $n$ in variables $l$ with coefficients generated
from the starting symbol $a$:

\begin{footnotesize}
\begin{verbatim}
input: lpdogdp(a,{x1,x2},2);

                     2                        2
a_20_ *** partial(x1)  + a_02_ *** partial(x2)

 + a_11_ *** partial(x1) *** partial(x2) + a_10_ *** partial(x1)

 + a_01_ *** partial(x2) + a_00_
\end{verbatim}
\end{footnotesize}

\subsection{Symbols}
\subsubsection{\texttt{lpdosym}}
The \emph{symbol} of an lpdo. That is the differential monomial of
highest order with the partials replaced by corresponding commutative
variables:

\begin{footnotesize}
\begin{verbatim}
input: lpdosym((a()+b())***partial(x1)***partial(x2)**2+3***partial(x1));

           2
y_x1_*y_x2_ *(a() + b())
\end{verbatim}
\end{footnotesize}
More generally, one can use a second optional arguments to specify a
the order of a different differential monomial to form the symbol of:

\begin{footnotesize}
\begin{verbatim}
input: lpdosym((a()+b())***partial(x1)***partial(x2)**2+3***partial(x1),1);

3*y_x1_
\end{verbatim}
\end{footnotesize}
Finally, a third optional argument can be used to specify an
alternative starting symbol for the commutative variable, which is
\texttt{y} by default. Altogether, the optional arguments default like
\texttt{lpdosym($\cdot$)}=\texttt{lpdosym($\cdot$,lpdoord($\cdot$),y)}.

\subsubsection{\texttt{lpdosym2dp}}
This converts a symbol obtained via \texttt{lpdosym} back into an LPDO
resulting in the corresponding differential monomial of the original
LPDO.

\begin{footnotesize}
\begin{verbatim}
input: d := a()***partial(x1)***partial(x2)+partial(x3)$

input: s := lpdosym d;

s := a()*y_x1_*y_x2_

input: lpdosym2dp s;

a() *** partial(x1) *** partial(x2)
\end{verbatim}
\end{footnotesize}
In analogy to \texttt{lpdosym} there is an optional argument for
specifying an alternative starting symbol for the commutative
variable, which is \texttt{y} by default.

\subsubsection{\texttt{lpdos}}
Given LPDOs $p$, $q$ and $m\in\N$ the function
\texttt{lpdos($p$,$q$,$m$)} computes the commutative polynomial $$S_m
= \sum_{|j| = m\atop |j| < k} \biggl(\sum_{i = 1}^n
p_i \partial_i(q_j) + p_0 q_j\biggr)y^{j}.$$ This is useful for the
factorization of LPDOs \cite{LasarukSturm:08b}.
\begin{footnotesize}
\begin{verbatim}
input: p := a()***partial(x1)+b()$

input: q := c()***partial(x1)+d()***partial(x2)$

input: lpdos(p,q,1);

a()*diff(c(),x1,1)*y_x1_ + a()*diff(d(),x1,1)*y_x2_ + b()*c()*y_x1_

 + b()*d()*y_x2_
\end{verbatim}
\end{footnotesize}

\subsection{Factorization}

\subsubsection{\texttt{lpdofactorize}}
Factorize the argument LPDO $d$. The ground field $F$ must be fixed via
\texttt{lpdoset}. The result is a list of lists
$\{\dots,(A_i,L_i),\dots\}$. $A_i$ is is genrally the identifiers
\texttt{true}, which indicates reducibility. The respective $L_i$ is a
list of two differential polynomial factors, the first of which has
order 1.

\begin{footnotesize}
\begin{verbatim}
input: bk := (partial(x)+partial(y)+(a10-a01)/2) ***
       (partial(x)-partial(y)+(a10+a01)/2);

                2             2
bk := partial(x)  - partial(y)  + a10 *** partial(x) + a01 *** partial(y)

          2      2
     - a01  + a10
 + ----------------
          4

input: lpdoset lpdoweyl(1,x,y);

{#_00_ + #_01_*y + #_10_*x,x,y}

input: lpdofactorize bk;

{{true,

                                 a01 - a10
  { - partial(x) - partial(y) + -----------,
                                     2

                                  - a01 - a10
    - partial(x) + partial(y) + --------------}}}
                                      2
\end{verbatim}
\end{footnotesize}
If the result is the empty list, then this guarantees that there is no
approximate factorization possible. In general it is possible to obtain
several sample factorizations. Note, however, that the result does not
provide a complete list of possible factorizations with a left factor of
order 1 but only at least one such sample factorization in case of
reducibility.

Furthermore, the procedure might fail due to polynomial degrees
exceeding certain bounds for the extended quantifier elimination by
virtual substitution used internally. In this case there is the
identifier \texttt{failed} returned. This must not be confused with the
empty list indicating irreducibility as described above.

Besides
\begin{enumerate}
\item the LPDO $d$,
\end{enumerate}
\texttt{lpdofactorizex} accepts several optional arguments:
\begin{enumerate}
\setcounter{enumi}{1}
\item An LPDO of order 1, which serves as a template for the left
  (linear) factor. The default is a generic linear LPDO with generic
  coefficient functions according from the ground field specified via
  \texttt{lpdoset}. The principle idea is to support the factorization
  by guessing that certain differential monomials are not present.
\item An LPDO of order $\operatorname{ord}(d)-1$, which serves as a
  template for the right factor. Similarly to the previous argument the
  default is fully generic.
\end{enumerate}

\subsubsection{\texttt{lpdofac}}
This is a low-level entry point to the factorization
\texttt{lpdofactorize}. It accepts the same arguments as
\texttt{lpdofactorize}. It generates factorization conditions as a quite
large first-order formula over the reals. This can be passed to extended
quantifier elimination. For example, consider \texttt{bk} as in the
example for \texttt{lpdofactorize} above:

{\samepage
\begin{footnotesize}
\begin{verbatim}
input: faccond := lpdofac bk$

input: rlqea faccond;

{{true,

               a01 - a10
  {p_00_00_ = -----------,
                   2

   p_00_01_ = 0, p_00_10_ = 0, p_01_00_ = -1, p_01_01_ = 0, p_01_10_ = 0,

   p_10_00_ = -1, p_10_01_ = 0, p_10_10_ = 0,

                - a01 - a10
   q_00_00_ = --------------,
                    2

   q_00_01_ = 0, q_00_10_ = 0, q_01_00_ = 1, q_01_01_ = 0, q_01_10_ = 0,

   q_10_00_ = -1, q_10_01_ = 0, q_10_10_ = 0}}}
\end{verbatim}
\end{footnotesize}
}
The result of the extended quantifier elimination provides coefficient
values for generic factor polynomials $p$ and $q$. These are
automatically interpreted and converted into differential polynomials
by \texttt{lpdofactorize}.

\subsection{Approximate Factorization}

\subsubsection{\texttt{lpdofactorizex}}
Approximately factorize the argument LPDO $d$. The ground field $F$ must
be fixed via \texttt{lpdoset}. The result is a list of lists
$\{\dots,(A_i,L_i),\dots\}$. Each $A_i$ is quantifier-free formula
possibly containing a variable $\texttt{epsilon}$, which describes the
precision of corresponding factorization $L_i$. $L_i$ is a list
containing two factors, the first of which is linear.

\begin{footnotesize}
\begin{verbatim}
input: off lpdocoeffnorm$

input: lpdoset lpdoweyl(0,x1,x2)$

input: f2 := partial(x1)***partial(x2) + 1$

input: lpdofactorizex f2;

{{epsilon - 1 >= 0,{partial(x1),partial(x2)}},

 {epsilon - 1 >= 0,{partial(x2),partial(x1)}}}
\end{verbatim}
\end{footnotesize}
If the result is the empty list, then this guarantees that there is no
approximate factorization possible. In our example we happen to obtain
two possible factorizations. Note, however, that the result in general
does not provide a complete list of factorizations with a left factor of
order 1 but only at least one such sample factorization.

Furthermore, the procedure might fail due to polynomial degrees
exceeding certain bounds for the extended quantifier elimination by
virtual substitution used internally. If this happens, the corresponding
$A_i$ will contain existential quantifiers \texttt{ex}, and $L_i$ will
be meaningless.\\
\verb!Da sollte besser ein failed kommen ...!

The first of the two subresults above has the semantics that
$\partial_{x_1}\partial_{x_2}$ is an approximate factorization of $f_2$
for all $\varepsilon\geq1$. Formally,
$||f_2-\partial_{x_1}\partial_{x_2}||\leq\varepsilon$ for all
$\varepsilon\geq1$, which is equivalent to
$||f_2-\partial_{x_1}\partial_{x_2}||\leq1$. That is, $1$ is an upper
bound for the approximation error over $\R^2$. Where there are two
possible choices for the seminorm $||\cdot||$:
\begin{enumerate}[(a)]
\item ...
\item ...
\end{enumerate}
\verb!explain switch lpdocoeffnorm ...!

Besides
\begin{enumerate}
\item the LPDO $d$,
\end{enumerate}
\texttt{lpdofactorizex} accepts several optional arguments:
\begin{enumerate}
\setcounter{enumi}{1}
\item A Boolean combination $\psi$ of equations, negated equations, and
  (possibly strict) ordering constraints. This $\psi$ describes a
  (semialgebraic) region over which to factorize approximately. The
  default is \texttt{true} specifying the entire $\R^n$. It is possible
  to choose $\psi$ parametrically. Then the parameters will in general
  occur in the conditions $A_i$ in the result.
\item[3., 4.] An LPDO of order 1, which serves as a template for the left
  (linear) factor, and an LPDO of order $\operatorname{ord}(d)-1$, which
  serves as a template for the right factor. See the documentation of
  \texttt{lpdofactorize} for defaults and details.
\item[5.] A bound $\varepsilon$ for describing the desired precision for
  approximate factorization. The default is the symbol \texttt{epsilon},
  i.e., a symbolic choice such that the optimal choice (with respect to
  parameters in $\psi$) is obtained during factorization. It is possible
  to fix $\varepsilon\in\Q$. This does, however, not considerably
  simplify the factorization process in most cases.
\end{enumerate}

\begin{footnotesize}
\begin{verbatim}
input: f3 := partial(x1) *** partial(x2) + x1$

input: psi1 := 0<=x1<=1 and 0<=x2<=1$

input: lpdofactorizex(f3,psi1,a()***partial(x1),b()***partial(x2));

{{epsilon - 1 >= 0,{partial(x1),partial(x2)}}}
\end{verbatim}
\end{footnotesize}

\subsubsection{\texttt{lpdofacx}}
This is a low-level entry point to the factorization
\texttt{lpdofactorizex}. It is analogous to \texttt{lpdofac} for
\texttt{lpdofactorize}; see the documentation there for details.

\subsubsection{\texttt{lpdohrect}}

\subsubsection{\texttt{lpdohcirc}}

\end{document}


\documentclass{memoir}
\usepackage{notestemplate}

% \begin{figure}[ht]
%     \centering
%     \incfig{riemmans-theorem}
%     \caption{Riemmans theorem}
%     \label{fig:riemmans-theorem}
% \end{figure}

\begin{document}
\section{Direct Sums of Rings}
\label{sec:direct_sums_of_rings}
\begin{defn}[Direct Sum]
	The \textbf{direct sum} of two rings \(R_1\oplus R_2\) (or direct product \(R_1\times R_2\)) is the ring of all ordered pairs \((r_1,r_2)\), with \(r_i \in R_i\), with addition and multiplication defined by adding and multiplying the components:
	\begin{align*}
		(r_1,r_2) + (s_1,s_2) = (r_1+s_1,r_2+s_2) \quad (r_1,r_2)(s_1,s_2) = (r_1s_1,r_2s_2).
	\end{align*}
\end{defn}
One can check that this indeed satisfies the properties of a ring.
\begin{defn}[Projection]
	The \textbf{projection} subsets are defined by
	\begin{align*}
		R_1^* := \left\{(r_1,0) \mid r_1 \in R_1 \right\} \\
		R_2^* := \left\{(0,r_2) \mid r_2 \in R_2 \right\}
	\end{align*}
\end{defn}
These projection subsets are isomorphic to \(R_1,R_2\) respectively. Furthermore, \(R_1^{*},R_2^{*}\) are ideals in \(R_1\oplus R_2\), and every \(c \in R_1 \oplus R_2\) has a unique decomposition \(c = c_1 + c_2\) with \(c_i \in R_i\).
\begin{prop}[Unique Decompositions]
	If \(I,J\) are ideals in a ring \(R\) such that every \(r \in R\) can be uniquely written as \(r = i + j\), with \(i \in I\), \(j \in J\), then \(R \cong I\oplus J\)
\end{prop}

\begin{thm}[More Isomorphism Theorems]
	Let \(R\) be a ring.
	\begin{itemize}
		\item \textit{(Second Isomorphism Theorem for Rings)} Let \(A\leq R\) and \(B \triangleleft R\). Then
			\begin{align*}
				A+B \leq R\\
				A\cap B \triangleleft A\\
				(A+B) / B \cong A / (A\cap B)
			\end{align*}
	\item \textit{(Third Isomorphism Theorem for Rings} Let \(I,J \triangleleft R\) with \(I\subset J\). Then
		\begin{align*}
			J / I \triangleleft R / I\\
			(R / I) / (J / I) \cong R / J
		\end{align*}
	\item Let \(I \triangleleft R\). Then there is a correspondence between subrings \(A<R\) that contain an ideal \(I\) and the subrings of \(R / I\) by \(A \leftrightarrow A / I\). Furthermore, if \(A\leq R\) contains \(I\), then \(A \triangleleft R\) if and only if \(A / I \triangleleft R / I\).
	\end{itemize}
\end{thm}

\end{document}

Abstract Algebra - Introductory/Algebra I/Notes/source/2020-02-25-RingProd.tex