\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{amsmath}
\usepackage{slashed}
\usepackage{tikz}

\begin{document}

\noindent
Compton scattering occurs when a high energy photon such as a gamma ray interacts with an electron.
In typical Compton scattering experiments the incident electron is at rest with zero velocity.
However, it is easier to develop a theory using the center of mass frame in which
the photon and the electron have equal and opposite momentum.
The following diagram shows the photon and electron scattering through angle $\theta$
in the center of mass frame.
\begin{center}
\begin{tikzpicture}
\draw[dashed] (0,0) circle (0.5cm);
\draw[thick,->] (2,0) node[anchor=west] {$e^-$} -- (0.6,0);
\draw[thick,->] (-2,0) node[anchor=east] {$\gamma$} -- (-0.6,0);
\draw[thick,->] (0.40,0.40) -- (1.3,1.3) node[anchor=south west] {$\gamma$};
\draw[thick,->] (-0.4,-0.4) -- (-1.3,-1.3) node[anchor=north east] {$e^-$};
\draw (1,0.5) node {$\theta$};
\end{tikzpicture}
\end{center}

\noindent
Here is the same diagram with momentum and spinor labels.
\begin{center}
\begin{tikzpicture}
\draw[dashed] (0,0) circle (0.5cm);
\draw[thick,->] (2,0) node[anchor=west] {$p_2, u_2$} -- (0.6,0);
\draw[thick,->] (-2,0) node[anchor=east] {$p_1$} -- (-0.6,0);
\draw[thick,->] (0.40,0.40) -- (1.3,1.3) node[anchor=south west] {$p_3$};
\draw[thick,->] (-0.4,-0.4) -- (-1.3,-1.3) node[anchor=north east] {$p_4, u_4$};
\draw (1,0.5) node {$\theta$};
\end{tikzpicture}
\end{center}

\noindent
In center of mass coordinates the momentum vectors are
\begin{equation*}
\underset{\text{inbound photon}}
{
p_1=\begin{pmatrix}\omega\\0\\0\\ \omega\end{pmatrix}
}
\qquad
\underset{\text{inbound electron}}
{
p_2=\begin{pmatrix}E\\0\\0\\-\omega\end{pmatrix}
}
\qquad
\underset{\text{outbound photon}}
{
p_3=\begin{pmatrix}
\omega\\
\omega\sin\theta\cos\phi\\
\omega\sin\theta\sin\phi\\
\omega\cos\theta
\end{pmatrix}
}
\qquad
\underset{\text{outbound electron}}
{
p_4=\begin{pmatrix}
E\\
-\omega\sin\theta\cos\phi\\
-\omega\sin\theta\sin\phi\\
-\omega\cos\theta
\end{pmatrix}
}
\end{equation*}

\noindent
Symbol $\omega$ is incident momentum,
$E$ is total energy $E=\sqrt{\omega^2+m^2}$,
and $m$ is electron mass.
Polar angle $\theta$ is the observed scattering angle.
Azimuth angle $\phi$ cancels out in scattering calculations.

\bigskip
\noindent
The spinors are
\begin{equation*}
\underset{\text{inbound electron, spin up}}
{
u_{21}=\begin{pmatrix}
E+m\\
0\\
-\omega\\
0
\end{pmatrix}
}
\qquad
\underset{\text{inbound electron, spin down}}
{
u_{22}=\begin{pmatrix}
0\\
E+m\\
0\\
\omega
\end{pmatrix}
}
\qquad
\underset{\text{outbound electron, spin up}}
{
u_{41}=\begin{pmatrix}
E+m\\
0\\
p_{4z}\\
p_{4x}+ip_{4y}
\end{pmatrix}
}
\qquad
\underset{\text{outbound electron, spin down}}
{
u_{42}=\begin{pmatrix}
0\\
E+m\\
p_{4x}-ip_{4y}\\
-p_{4z}
\end{pmatrix}
}
\end{equation*}

\noindent
The spinors shown above are not individually normalized.
Instead, a combined spinor normalization constant $N=(E+m)^2$ will be used.

\bigskip
\noindent
The following formula computes a probability density $|\mathcal{M}_{ab}|^2$
for Compton scattering where $a$ is the spin state of the inbound electron
and $b$ is the spin state of the outbound electron.
\begin{equation*}
|\mathcal{M}_{ab}|^2
=
\frac{e^4}{N}
\left|
-\frac{\bar{u}_{4b}\gamma^\mu(\slashed{q}_1+m)\gamma^\nu u_{2a}}{s-m^2}
-\frac{\bar{u}_{4b}\gamma^\nu(\slashed{q}_2+m)\gamma^\mu u_{2a}}{u-m^2}
\right|^2
\end{equation*}
Symbol $e$ is electron charge.
Symbols $q_1$ and $q_2$ are
\begin{align*}
q_1&=p_1+p_2
\\
q_2&=p_4-p_1=p_2-p_3
\end{align*}

\noindent
Symbols $s$ and $u$ are Mandelstam variables
\begin{align*}
s&=(p_1+p_2)^2
\\
u&=(p_1-p_4)^2
\end{align*}

\noindent
Let
\begin{equation*}
a_1=\bar{u}_{4b}\gamma^\mu(\slashed{q}_1+m)\gamma^\nu u_{2a}
\qquad
a_2=\bar{u}_{4b}\gamma^\nu(\slashed{q}_2+m)\gamma^\mu u_{2a}
\end{equation*}

\noindent
Then
\begin{align*}
|\mathcal{M}_{ab}|^2&=\frac{e^4}{N}\left|-\frac{a_1}{s-m^2}-\frac{a_2}{u-m^2}\right|^2\\
&=
\frac{e^4}{N}
\left(-\frac{a_1}{s-m^2}-\frac{a_2}{u-m^2}\right)
\left(-\frac{a_1}{s-m^2}-\frac{a_2}{u-m^2}\right)^*\\
&=
\frac{e^4}{N}\left(
\frac{a_1a_1^*}{(s-m^2)^2}
+\frac{a_1a_2^*}{(s-m^2)(u-m^2)}
+\frac{a_1^*a_2}{(s-m^2)(u-m^2)}
+\frac{a_2a_2^*}{(u-m^2)^2}
\right)
\end{align*}

\noindent
The expected probability density $\langle|\mathcal{M}|^2\rangle$ is
computed by summing $|\mathcal{M}_{ab}|^2$ over all spin and polarization states
and then dividing by the number of inbound states.
There are four inbound states.
The sum over polarizations is already accomplished by contraction of $aa^*$ over $\mu$ and $\nu$.
\begin{align*}
\langle|\mathcal{M}|^2\rangle
&=\frac{1}{4}\sum_{a=1}^2\sum_{b=1}^2|\mathcal{M}_{ab}|^2\\
&=\frac{e^4}{4N}\sum_{a=1}^2\sum_{b=1}^2
\left(
\frac{a_1a_1^*}{(s-m^2)^2}
+\frac{a_1a_2^*}{(s-m^2)(u-m^2)}
+\frac{a_1^*a_2}{(s-m^2)(u-m^2)}
+\frac{a_2a_2^*}{(u-m^2)^2}
\right)
\end{align*}

\noindent
Use the Casimir trick to replace sums over spins with matrix products.
\begin{align*}
f_{11}&=\frac{1}{N} \sum_{a=1}^2\sum_{b=1}^2 a_1a_1^*=\mathop{\rm Tr}
\left(
(\slashed{p}_2+m)\gamma^\mu(\slashed{q}_1+m)\gamma^\nu(\slashed{p}_4+m)\gamma_\nu(\slashed{q}_1+m)\gamma_\mu
\right)
\\
f_{12}&=\frac{1}{N} \sum_{a=1}^2\sum_{b=1}^2 a_1a_2^*=\mathop{\rm Tr}
\left(
(\slashed{p}_2+m)\gamma^\mu(\slashed{q}_2+m)\gamma^\nu(\slashed{p}_4+m)\gamma_\mu(\slashed{q}_1+m)\gamma_\nu
\right)
\\
f_{22}&=\frac{1}{N} \sum_{a=1}^2\sum_{b=1}^2 a_2a_2^*=\mathop{\rm Tr}
\left(
(\slashed{p}_2+m)\gamma^\mu(\slashed{q}_2+m)\gamma^\nu(\slashed{p}_4+m)\gamma_\nu(\slashed{q}_2+m)\gamma_\mu
\right)
\end{align*}

\noindent
Hence
\begin{equation}
\langle|\mathcal{M}|^2\rangle
=
\frac{e^4}{4}
\left(
\frac{f_{11}}{(s-m^2)^2}
+\frac{f_{12}}{(s-m^2)(u-m^2)}
+\frac{f_{12}^*}{(s-m^2)(u-m^2)}
+\frac{f_{22}}{(u-m^2)^2}
\right)
\end{equation}

\noindent
Run ``compton-scattering-1.txt'' to verify the Casimir trick for Compton scattering.

\bigskip
\noindent
The following formulas are equivalent to the Casimir trick.
(Recall that $a\cdot b=a^\mu g_{\mu\nu}b^\nu$)
\begin{align*}
f_{11}&=
 32 (p_1 \cdot p_2) (p_1 \cdot p_4) +
 64 m^2 (p_1 \cdot p_2) -
 32 m^2 (p_1 \cdot p_3) -
 32 m^2 (p_1 \cdot p_4) + 32 m^4
\\
f_{12}&=16 m^2 (p_1 \cdot p_2) - 16 m^2 (p_1 \cdot p_4) + 32m^4
\\
f_{22}&=
32 (p_1 \cdot p_2) (p_1 \cdot p_4) +
32 m^2 (p_1 \cdot p_2) -
32 m^2 (p_1 \cdot p_3) -
64 m^2 (p_1 \cdot p_4) + 32 m^4
\end{align*}

\noindent
Using Mandelstam variables
\begin{align*}
s&=(p_1+p_2)^2
\\
t&=(p_1-p_3)^2
\\
u&=(p_1-p_4)^2
\end{align*}
the formulas are
\begin{equation}
\begin{aligned}
f_{11}&=-8 s u + 24 s m^2 + 8 u m^2 + 8 m^4
\\
f_{12}&=8 s m^2 + 8 u m^2 + 16 m^4
\\
f_{22}&=-8 s u + 8 s m^2 + 24 u m^2 + 8 m^4
\end{aligned}
\end{equation}

\noindent
Run ``compton-scattering-2.txt'' to verify.

\subsection*{High energy approximation}
For high energy experiments that have $\omega\gg m$,
a useful approximation is to set $m=0$ and obtain
\begin{align*}
f_{11}&=-8su
\\
f_{12}&=0
\\
f_{22}&=-8su
\end{align*}

\noindent
Hence
\begin{align*}
\langle|\mathcal{M}|^2\rangle
&=\frac{e^4}{4}
\left(\frac{-8su}{s^2}+\frac{-8su}{u^2}\right)
\\
&=2e^4
\left(-\frac{u}{s}-\frac{s}{u}\right)
\end{align*}

\noindent
Also for $m=0$ the Mandelstam variables $s$ and $u$ are
\begin{align*}
s&=4\omega^2
\\
u&=-2\omega^2(\cos\theta+1)
\end{align*}
Hence
\begin{equation}
\langle|\mathcal{M}|^2\rangle
=2e^4\left(
\frac{\cos\theta+1}{2}+\frac{2}{\cos\theta+1}
\right)
\end{equation}

\subsection*{Lab frame}
Compton scattering experiments are typically done in the ``lab'' frame where the electron is at rest.
The following Lorentz boost $\Lambda$ transforms momentum vectors from
the center of mass frame to the lab frame.
\begin{equation*}
\Lambda=
\begin{pmatrix}
E/m & 0 & 0 & \omega/m\\
0 & 1 & 0 & 0\\
0 & 0 & 1 & 0\\
\omega/m & 0 & 0 & E/m
\end{pmatrix},
\qquad
\Lambda p_2=\begin{pmatrix}m \\ 0 \\ 0 \\ 0\end{pmatrix}
\end{equation*}

\noindent
Mandelstam variables are invariant under a boost.
\begin{equation*}
\begin{aligned}
s&=(p_1+p_2)^2=(\Lambda p_1+\Lambda p_2)^2
\\
t&=(p_1-p_3)^2=(\Lambda p_1-\Lambda p_3)^2
\\
u&=(p_1-p_4)^2=(\Lambda p_1-\Lambda p_4)^2
\end{aligned}
\end{equation*}

\noindent
In the lab frame, let $\omega_L$ be the angular frequency of the incident photon
and let $\omega_L'$ be the angular frequency of the scattered photon.
\begin{equation*}
\begin{aligned}
\omega_L&=\Lambda p_1\cdot(1,0,0,0)=\frac{\omega^2}{m}+\frac{\omega E}{m}
\\
\omega_L'&=\Lambda p_3\cdot(1,0,0,0)=\frac{\omega^2\cos\theta}{m}+\frac{\omega E}{m}
\end{aligned}
\end{equation*}

\noindent
It follows that
\begin{equation*}
\begin{aligned}
s&=(p_1+p_2)^2=2m\omega_L+m^2
\\
t&=(p_1-p_3)^2=2m(\omega_L' - \omega_L)
\\
u&=(p_1-p_4)^2=-2 m \omega_L' + m^2
\end{aligned}
\end{equation*}

\noindent
Compute $\langle|\mathcal{M}|^2\rangle$ using equations (1) and (2)
and the above $s$, $t$, and $u$ that involve $\omega_L$ and $\omega_L'$.
\begin{equation*}
\langle|\mathcal{M}|^2\rangle=
2e^4\left(
\frac{\omega_L}{\omega_L'}+\frac{\omega_L'}{\omega_L}
+\left(\frac{m}{\omega_L}-\frac{m}{\omega_L'}+1\right)^2-1
\right)
\end{equation*}

\noindent
From the Compton formula
\begin{equation*}
\frac{1}{\omega_L'}-\frac{1}{\omega_L}=\frac{1-\cos\theta_L}{m}
\end{equation*}

\noindent
we have
\begin{equation*}
\cos\theta_L=\frac{m}{\omega_L}-\frac{m}{\omega_L'}+1
\end{equation*}

\noindent
Hence
\begin{equation*}
\langle|\mathcal{M}|^2\rangle=
2e^4\left(
\frac{\omega_L}{\omega_L'}+\frac{\omega_L'}{\omega_L}+\cos^2\theta_L-1
\right)
\end{equation*}

\noindent
Run ``compton-scattering-3.txt'' to verify lab frame formulas for Compton scattering.

\subsection*{Cross section}
Now that we have derived $\langle|\mathcal{M}|^2\rangle$
we can investigate the angular distribution of scattered photons.
For simplicity let us drop the $L$ subscript from lab variables.
From now on the symbols $\omega$, $\omega'$, and $\theta$ will be lab frame variables.

\bigskip
\noindent
The differential cross section for Compton scattering is
\begin{align*}
\frac{d\sigma}{d\Omega}&=\frac{\hbar^2}{64\pi^2m^2c^4}
\left(\frac{\omega'}{\omega}\right)^2\langle|\mathcal{M}|^2\rangle
\\
&=\frac{e^4\hbar^2}{32\pi^2m^2c^4}
\left(\frac{\omega'}{\omega}\right)^2
\left(
\frac{\omega}{\omega'}+\frac{\omega'}{\omega}+\cos^2\theta-1
\right)
\end{align*}

\noindent
Substitute $e^4=16\pi^2\alpha^2$ to obtain
\begin{equation*}
\frac{d\sigma}{d\Omega}
=\frac{\alpha^2\hbar^2}{2m^2c^4}
\left(\frac{\omega'}{\omega}\right)^2
\left(
\frac{\omega}{\omega'}+\frac{\omega'}{\omega}+\cos^2\theta-1
\right)
\end{equation*}

\noindent
The scattered photon frequency $\omega'$ is computed from the Compton equation.
\begin{equation*}
\omega'=\frac{m\omega}{m+\omega(1-\cos\theta)}
\end{equation*}

\noindent
We can integrate $d\sigma$ to obtain a cumulative distribution function.
Recall that
\begin{equation*}
d\Omega=\sin\theta\,d\theta\,d\phi
\end{equation*}
Hence
\begin{equation*}
d\sigma
=\frac{\alpha^2\hbar^2}{2m^2c^4}
\left(\frac{\omega'}{\omega}\right)^2
\left(\frac{\omega}{\omega'}+\frac{\omega'}{\omega}+\cos^2\theta-1\right)
\sin\theta\,d\theta\,d\phi
\end{equation*}

\bigskip
\noindent
Let $I(\theta)$ be the following integral of $d\sigma$.
\begin{align*}
I(\theta)
&=\left(\frac{2m^2c^4}{\alpha^2\hbar^2}\right)\frac{1}{2\pi}\int_0^{2\pi}\int d\sigma
\\
&=\int
\left(\frac{\omega'}{\omega}\right)^2
\left(\frac{\omega}{\omega'}+\frac{\omega'}{\omega}+\cos^2\theta-1\right)
\sin\theta\,d\theta,
\quad0\le\theta\le\pi
\end{align*}

\noindent
Assume that $I(\theta)-I(0)$ is computable given $\theta$ by either symbolic or numerical integration.

\bigskip
\noindent
Let $C$ be the normalization constant
\begin{equation*}
C=I(\pi)-I(0)
\end{equation*}

\noindent
Then the cumulative distribution function $F(\theta)$ is
\begin{equation*}
F(\theta)=\frac{I(\theta)-I(0)}{C},
\quad0\le\theta\le\pi
\end{equation*}

\noindent
The probability of observing scattering events in the interval
$\theta_1$ to $\theta_2$ can now be computed.
\begin{equation*}
P(\theta_1\le\theta\le\theta_2)=F(\theta_2)-F(\theta_1)
\end{equation*}

\noindent
The probability density function $f(\theta)$ is the derivative of $F(\theta)$.
\begin{equation*}
f(\theta)=\frac{dF(\theta)}{d\theta}
=\frac{1}{C}
\left(\frac{\omega'}{\omega}\right)^2
\left(\frac{\omega}{\omega'}+\frac{\omega'}{\omega}+\cos^2\theta-1\right)
\sin\theta
\end{equation*}

\noindent
Run ``compton-scattering-4.txt'' to draw a graph of $f(\theta)$ for
$\omega=500\,\text{keV}=1.2\times10^{20}\,\text{Hz}$.

\begin{center}
\includegraphics[scale=0.5]{compton-scattering.png}
\end{center}

\noindent
Probability distribution for $45^\circ$ bins
($\omega=500\,\text{keV}=1.2\times10^{20}\,\text{Hz}$).

\begin{center}
\begin{tabular}{|c|c|c|}
\hline
$\theta_1$ & $\theta_2$ & $P(\theta_1\le\theta\le\theta_2)$\\
\hline
$0^\circ$ & $45^\circ$ & 0.35 \\
$45^\circ$ & $90^\circ$ & 0.34 \\
$90^\circ$ & $135^\circ$ & 0.22 \\
$135^\circ$ & $180^\circ$ & 0.09 \\
\hline
\end{tabular}
\end{center}

\subsection*{Thomson scattering}
When $\omega$ is much smaller than the electron mass $m$ we have
\begin{equation*}
\frac{m}{m+\omega(1-\cos\theta)}\approx1
\end{equation*}

\noindent
Hence for $\omega\ll m$ the differential cross section is approximately
\begin{equation*}
\frac{d\sigma}{d\Omega}=\frac{\alpha^2}{2m^2}(1+\cos^2\theta)
\end{equation*}

\noindent
which is the formula for Thomson scattering.

\subsection*{Data from a CERN LEP experiment}
See ``Compton Scattering of Quasi-Real Virtual Photons at LEP,''
arxiv.org/abs/hep-ex/0504012.

\begin{center}
\begin{tabular}{|c|c|}
\hline
$x$ & $y$\\
\hline
$-0.74$ & $13380$\\
$-0.60$ & $\phantom{0}7720$\\
$-0.47$ & $\phantom{0}6360$\\
$-0.34$ & $\phantom{0}4600$\\
$-0.20$ & $\phantom{0}4310$\\
$-0.07$ & $\phantom{0}3700$\\
$\phantom{+}0.06$ & $\phantom{0}3640$\\
$\phantom{+}0.20$ & $\phantom{0}3340$\\
$\phantom{+}0.33$ & $\phantom{0}3500$\\
$\phantom{+}0.46$ & $\phantom{0}3010$\\
$\phantom{+}0.60$ & $\phantom{0}3310$\\
$\phantom{+}0.73$ & $\phantom{0}3330$\\
\hline
\end{tabular}
\end{center}

\noindent
The data are for the center of mass frame and have the following relationship with the differential cross section formula.
\begin{equation*}
x=\cos\theta\qquad y=\frac{d\sigma}{d\cos\theta}=2\pi\frac{d\sigma}{d\Omega}
\end{equation*}

\noindent
From equation (3) we have for the center of mass frame
\begin{equation*}
\langle|\mathcal{M}|^2\rangle
=
2e^4\left(
\frac{\cos\theta+1}{2}+\frac{2}{\cos\theta+1}
\right)
\end{equation*}

\noindent
The corresponding cross section formula is
\begin{equation*}
\frac{d\sigma}{d\Omega}
=\frac{\langle|\mathcal{M}|^2\rangle}{64\pi^2s}
=\frac{e^4}{32\pi^2s}
\left(
\frac{\cos\theta+1}{2}+\frac{2}{\cos\theta+1}
\right),\quad s\gg m
\end{equation*}

\noindent
Substituting $e^4=16\pi^2\alpha^2$ yields
\begin{equation*}
\frac{d\sigma}{d\Omega}
=\frac{\alpha^2}{2s}
\left(
\frac{\cos\theta+1}{2}+\frac{2}{\cos\theta+1}
\right)
\end{equation*}

\noindent
Multiply by $2\pi$ to obtain
\begin{equation*}
\frac{d\sigma}{d\cos\theta}
=\frac{\pi\alpha^2}{s}\left(
\frac{\cos\theta+1}{2}+\frac{2}{\cos\theta+1}
\right)
\end{equation*}

\noindent
To compute predicted values $\hat{y}$ from the above formula,
multiply by $(\hbar c)^2$ to convert to SI
and multiply by $10^{40}$ to convert square meters to picobarns.
\begin{equation*}
\hat{y}
=
\frac{\pi\alpha^2}{s}
\left(
\frac{x+1}{2}+
\frac{2}{x+1}
\right)
\times(\hbar c)^2
\times10^{40}
\end{equation*}

\noindent
The following table shows $\hat{y}$
for $s=40\,\text{GeV}^2$ (i.e., $\omega=100\,\text{MeV}$).

\begin{center}
\begin{tabular}{|c|c|c|}
\hline
$x$ & $y$ & $\hat{y}$\\
\hline
$-0.74$ & $13380$ & $12739$\\
$-0.60$ & $\phantom{0}7720$ & $\phantom{0}8468$\\
$-0.47$ & $\phantom{0}6360$ & $\phantom{0}6577$\\
$-0.34$ & $\phantom{0}4600$ & $\phantom{0}5472$\\
$-0.20$ & $\phantom{0}4310$ & $\phantom{0}4723$\\
$-0.07$ & $\phantom{0}3700$ & $\phantom{0}4259$\\
$\phantom{+}0.06$ & $\phantom{0}3640$ & $\phantom{0}3936$\\
$\phantom{+}0.20$ & $\phantom{0}3340$ & $\phantom{0}3691$\\
$\phantom{+}0.33$ & $\phantom{0}3500$ & $\phantom{0}3532$\\
$\phantom{+}0.46$ & $\phantom{0}3010$ & $\phantom{0}3420$\\
$\phantom{+}0.60$ & $\phantom{0}3310$ & $\phantom{0}3338$\\
$\phantom{+}0.73$ & $\phantom{0}3330$ & $\phantom{0}3291$\\
\hline
\end{tabular}
\end{center}

\noindent
The coefficient of determination $R^2$ measures how well predicted values fit the real data.
\begin{equation*}
R^2=1-\frac{\sum(y-\hat{y})^2}{\sum(y-\bar{y})^2}=0.97
\end{equation*}

\noindent
The result indicates that the model $d\sigma$ explains 97\% of the variance in the data.

\subsection*{Notes}
Here are a few notes regarding the Eigenmath scripts.

\bigskip
\noindent
Start by writing out $a_1$ and $a_2$ in full component form.
\begin{equation*}
a_1^{\mu\nu}
=\bar{u}_{4\alpha}\gamma^{\mu\alpha}{}_\beta(\slashed{q}_1+m)^\beta{}_\rho\gamma^{\nu\rho}{}_\sigma u_2^\sigma
\qquad
a_2^{\nu\mu}
=\bar{u}_{4\alpha}\gamma^{\nu\alpha}{}_\beta(\slashed{q}_2+m)^\beta{}_\rho\gamma^{\mu\rho}{}_\sigma u_2^\sigma
\end{equation*}

\noindent
Transpose $\gamma$ tensors to form inner products over $\alpha$ and $\rho$.
\begin{equation*}
a_1^{\mu\nu}
=\bar{u}_{4\alpha}\gamma^{\alpha\mu}{}_\beta(\slashed{q}_1+m)^\beta{}_\rho\gamma^{\rho\nu}{}_\sigma u_2^\sigma
\qquad
a_2^{\nu\mu}
=\bar{u}_{4\alpha}\gamma^{\alpha\nu}{}_\beta(\slashed{q}_2+m)^\beta{}_\rho\gamma^{\rho\mu}{}_\sigma u_2^\sigma
\end{equation*}

\noindent
Convert transposed $\gamma$ to Eigenmath code.
\begin{equation*}
\gamma^{\alpha\mu}{}_\beta
\quad\rightarrow\quad
\text{\tt gammaT = transpose(gamma)}
\end{equation*}

\noindent
Then to compute $a_1$ we have
\begin{multline*}
a_1=\bar{u}_{4\alpha}\gamma^{\alpha\mu}{}_\beta(\slashed{q}_1+m)^\beta{}_\rho\gamma^{\rho\nu}{}_\sigma u_2^\sigma
\\
\rightarrow\quad
\text{\tt a1 = dot(u4bar[s4],gammaT,qslash1 + m I,gammaT,u2[s2])}
\end{multline*}

\noindent
where $s_2$ and $s_4$ are spin indices.
Similarly for $a_2$ we have
\begin{multline*}
a_2=\bar{u}_{4\alpha}\gamma^{\alpha\nu}{}_\beta(\slashed{q}_2+m)^\beta{}_\rho\gamma^{\rho\mu}{}_\sigma u_2^\sigma
\\
\rightarrow\quad
\text{\tt a2 = dot(u4bar[s4],gammaT,qslash2 + m I,gammaT,u2[s2])}
\end{multline*}

\noindent
In component notation the product $a_1a_1^*$ is
\begin{equation*}
a_1a_1^*=a_1^{\mu\nu}a_1^{*\mu\nu}
\end{equation*}

\noindent
To sum over $\mu$ and $\nu$ it is necessary to lower indices with the metric tensor.
Also, transpose $a_1^*$ to form an inner product with $\nu$.
\begin{equation*}
a_1a_1^*=a_1^{\mu\nu}a_{1\nu\mu}^*
\end{equation*}

\noindent
Convert to Eigenmath code.
The dot function sums over $\nu$ and the contract function sums over $\mu$.
\begin{equation*}
a_1a_1^*
\quad\rightarrow\quad
\text{\tt a11 = contract(dot(a1,gmunu,transpose(conj(a1)),gmunu))}
\end{equation*}

\noindent
Similarly for $a_2a_2^*$ we have
\begin{equation*}
a_2a_2^*
\quad\rightarrow\quad
\text{\tt a22 = contract(dot(a2,gmunu,transpose(conj(a2)),gmunu))}
\end{equation*}

\noindent
The product $a_1a_2^*$ does not require a transpose because $a_1a_2^*=a_1^{\mu\nu}a_2^{*\nu\mu}$.
\begin{equation*}
a_1a_2^*
\quad\rightarrow\quad
\text{\tt a12 = contract(dot(a1,gmunu,conj(a2),gmunu))}
\end{equation*}

\noindent
In component notation, a trace operator becomes a sum over an index, in this case $\alpha$.
\begin{align*}
f_{11}
&=
\mathop{\rm Tr}
\left(
(\slashed{p}_2+m)\gamma^\mu(\slashed{q}_1+m)\gamma^\nu(\slashed{p}_4+m)\gamma_\nu(\slashed{q}_1+m)\gamma_\mu
\right)\\
&=
(\slashed{p}_2+m)^\alpha{}_\beta
\gamma^{\mu\beta}{}_\rho
(\slashed{q}_1+m)^\rho{}_\sigma
\gamma^{\nu\sigma}{}_\tau
(\slashed{p}_4+m)^\tau{}_\delta
\gamma_\nu{}^\delta{}_\eta
(\slashed{q}_1+m)^\eta{}_\xi
\gamma_\mu{}^\xi{}_\alpha
\end{align*}

\noindent
As before, transpose $\gamma$ tensors to form inner products.
\begin{equation*}
f_{11}=
(\slashed{p}_2+m)^\alpha{}_\beta
\gamma^{\beta\mu}{}_\rho
(\slashed{q}_1+m)^\rho{}_\sigma
\gamma^{\sigma\nu}{}_\tau
(\slashed{p}_4+m)^\tau{}_\delta
\gamma^\delta{}_{\nu\eta}
(\slashed{q}_1+m)^\eta{}_\xi
\gamma^\xi{}_{\mu\alpha}
\end{equation*}

\noindent
To convert to Eigenmath code, use an intermediate variable for the inner product.
\begin{equation*}
T^{\alpha\mu\nu}{}_{\nu\mu\alpha}
\quad\rightarrow\quad
\text{\tt T = dot(P2,gammaT,Q1,gammaT,P4,gammaL,Q1,gammaL)}
\end{equation*}

\noindent
Now sum over the indices of $T$.
The innermost contract sums over $\nu$ then the next contract sums over $\mu$.
Finally the outermost contract sums over $\alpha$.
\begin{equation*}
f_{11}\quad\rightarrow\quad
\text{\tt f11 = contract(contract(contract(T,3,4),2,3))}
\end{equation*}

\noindent
Follow suit for $f_{22}$.
For $f_{12}$ the order of the rightmost $\mu$ and $\nu$ is reversed.
\begin{equation*}
f_{12}=\mathop{\rm Tr}
\left(
(\slashed{p}_2+m)\gamma^\mu(\slashed{q}_2+m)\gamma^\nu(\slashed{p}_4+m)\gamma_\mu(\slashed{q}_1+m)\gamma_\nu
\right)
\end{equation*}

\noindent
The resulting inner product is $T^{\alpha\mu\nu}{}_{\mu\nu\alpha}$
so the contraction is different.
\begin{equation*}
f_{12}
\quad\rightarrow\quad
\text{\tt f12 = contract(contract(contract(T,3,5),2,3))}
\end{equation*}

\noindent
The innermost contract sums over $\nu$ followed by sum over $\mu$ then sum over $\alpha$.

\end{document}


\section{The Theory of Covering Spaces}
\begin{definition}
    Suppose $\pi:\tilde{X}\to X$ is a covering map and $\gamma:[0,1]\to X$ is a path.
    A lift of $\gamma$ along $\pi$ is a path $\tilde{\gamma}:[0,1]\to\tilde{X}$ such that $\pi\circ\tilde{\gamma}=\gamma$.
\end{definition}
Obviously, lifts are not usually unique.
\begin{example}
    The function $\exp:\mathbb C\to\mathbb C_\star$ is a covering map.
    Consider the path $\gamma:[0,1]\to \mathbb C$ representing the unit circle, i.e. $\gamma(t)=e^{2\pi it}$, then both $t\mapsto 2\pi it$ and $t\mapsto 2\pi i+2\pi it$ are lifts of $\gamma$.
\end{example}
An interesting observation is that although we exhibited two different lifts, they do start at different points.
And it is indeed a correct intuition.
\begin{proposition}[Uniqueness of Lifts]
    Suppose $\tilde{\gamma}_1,\tilde{\gamma}_2$ are both lifts of $\gamma$ along a covering $\pi:\tilde{X}\to X$.
    If $\tilde{\gamma}_1(0)=\tilde{\gamma}_2(0)$ then $\tilde{\gamma}_1=\tilde{\gamma}_2$.
\end{proposition}
\begin{proof}
    Consider the set
    $$I=\{t\in[0,1]:\tilde{\gamma}_1(t)=\tilde{\gamma}_2(t)\}$$
    We shall show that it is both open and closed, which shows the proposition as $[0,1]$ is connected.
    It is obviously closed as $\tilde{\gamma}_1,\tilde{\gamma}_2$ are continuous and $[0,1]^2$ is Hausdorff.
    So it remains to show it is open.
    Let $t\in I$.
    As $\pi$ is a covering map, $\tilde{\gamma}_1(t)=\tilde{\gamma}_2(t)$ has a neighbourhood $\tilde{N}$ such that $\pi|_{\tilde{N}}$ is a homeomorphism.
    As $\gamma$ is continuous, there is $\delta>0$ such that $\gamma(t-\delta,t+\delta)\in N$.
    But for any $s$, $\pi\circ\tilde{\gamma}_1(s)=\gamma(s)=\pi\circ\tilde{\gamma}_2(s)$.
    So pick any $s\in (t-\delta,t+\delta)$, we have
    $$\tilde{\gamma}_1(s)=(\pi|_{\tilde{N}})^{-1}\circ\gamma(s)=\tilde{\gamma}_2(s)$$
    Therefore $s\in I$.
    This shows that $I$ is open, as desired.
\end{proof}
Now, even if $\pi$ is surjective, lifts may not exist.
\begin{example}[Counterexample]
    Consider $X=\mathbb C_\star,\tilde{X}=\mathbb R+i(-\pi,2\pi)$ and $\pi=\exp|_D$, but then we cannot lift the path $t\mapsto e^{2\pi it}$.
\end{example}
But note that the $\pi$ in the example above is not a regular covering map.
In fact, a lift does exist if $\pi$ is regular.
\begin{proposition}[Path-Lifting Lemma]
    Let $\pi:\tilde{X}\to X$ be a regular covering map and $\gamma:[0,1]\to X$ is a path.
    Suppose $\pi(\tilde{x})=\gamma(0)$, then there is a unique lift $\tilde\gamma$ of $\gamma$ such that $\tilde{\gamma}(0)=\tilde{x}$.
\end{proposition}
\begin{proof}
    Suffices to show the existence.
    Let
    $$I=\{t\in [0,1]:\gamma|_{[0,t]}\text{ can be lifted to some }\tilde\gamma\text{ with }\tilde{\gamma}(0)=\tilde{x}\}$$
    Again we will show that $I$ is both open and closed.\\
    To see $I$ is closed, consider a sequence $t_n\to\tau$ where $t_n\in I$ for all $I$.
    We shall show that $\tau\in I$.
    As $\pi$ is regular, there is some open $U\ni\gamma(\tau)$ such that
    $$\pi^{-1}(U)\cong\coprod_{\delta\in D}U_\delta$$
    for some set $D$.
    Throwing away finitely many terms we can assume $\gamma(t_n)\in U$ for any $t$, consequently $\tilde{\gamma}(t_n)$ are all in the same $U_\delta$.
    Set $\tilde{\gamma}(\tau)=(\pi|_{U_\delta})^{-1}\circ\gamma(\tau)$ extends $\tilde{\gamma}$ continuous to $\tau$, so $\tau\in I$.\\
    To see $I$ is open, let $\tau\in I$ and choose open $U\ni \gamma(\tau)$ such that
    $$\pi^{-1}(U)\cong\coprod_{\delta\in D}U_\delta$$
    for a set $D$.
    There is a unique $\delta$ such that $\tilde{\gamma}(\tau)\in U_\delta$.
    Choose $\epsilon>0$ such that $|t-\tau|<\epsilon\implies \gamma(t)\in U$.
    So we want to extend $\tilde{\gamma}$ via $\tilde\gamma(t)=(\pi|_{U_\delta})^{-1}\circ\gamma(t)$ for $|t-\tau|<\epsilon$, which works.
    Therefore $I$ is open, as required.
\end{proof}
\begin{definition}
    Let $X$ be a topological space and $\alpha,\beta:[0,1]\to X$ paths with $\alpha(0)=\beta(0),\alpha(1)=\beta(1)$.
    We say $\alpha,\beta$ are homotopic (or $\alpha\simeq\beta$) if there is a family of paths $(\alpha_s)_{s\in[0,1]}$ such that:\\
    1. $\alpha_0=\alpha,\alpha_s(1)=\beta$.\\
    2. $\alpha_s(0)=\alpha(0),\alpha_s(1)=\alpha(1)$ for any $s$.\\
    3. The map $(t,s)\mapsto\alpha_s(t)$ is continuous.
\end{definition}
\begin{definition}
    A topological space $X$ is simply connected if:\\
    1. $X$ is path-connected.\\
    2. Every pair of paths $\alpha,\beta:[0,1]\to X$ with the same endpoints are homotopic.
\end{definition}
\begin{remark}
    Let $D\subset\mathbb C$ be a convex domain, then the formula
    $$\alpha_s(t)=(1-s)\alpha(t)+s\beta(t)$$
    gives a homotopy between any two paths $\alpha,\beta$ with same endpoints.
\end{remark}
\begin{example}
    $\mathbb C$, the unit disk and half-plane are simply connected.
\end{example}
\begin{theorem}[Monodromy Theorem, aka Homotopy Lifting Lemma]\label{monodromy}
    Let $\pi:\tilde{X}\to X$ be a covering map and $\alpha,\beta$ in $X$ be such that:\\
    1. $\alpha\simeq\beta$ in $X$.\\
    2. There are lifts $\tilde\alpha$ of $\alpha$ and $\tilde\beta$ of $\beta$ along the covering.\\
    3. Every path $\gamma$ in $X$ with $\gamma(0)=\alpha(0)=\beta(0)$ has a lift $\tilde{\gamma}$ to $\tilde{X}$ with $\tilde{\gamma}(0)\tilde{\alpha}(0)=\tilde{\beta}(0)$.\\
    Then $\tilde{\alpha}\simeq\tilde{\beta}$.
    In particular, $\tilde{\alpha}\simeq\tilde{\beta}$.
\end{theorem}
\begin{proof}
    See Algebraic Topology.
\end{proof}
\begin{note}
    The requirements (ii) and (iii) are automatically satisfied if $\pi$ is regular.
\end{note}


\section{First Order Homogeneous Linear Equations}\label{sec:first order homogeneous linear}
A simple, but important and useful, type of separable equation is the
\dfont{first order homogeneous linear equation}:

\begin{definition}{First Order Homogeneous Linear Equation}{First Order Homogeneous Linear Equation}\label{First Order Homogeneous Linear Equation}
A first order homogeneous linear differential equation
is one of
the form $\ds y' + p(t)y=0$
or equivalently
$\ds y' = -p(t)y$.
\end{definition}

``Homogeneous'' refers to the zero on the right side of the equation, provided that $y'$ and $y$ are on the left. ``Linear'' in this definition indicates that both $y'$ and $y$ appear independently and explicitly; we don't see $y'$ or $y$ to any power greater than 1, or multiplied by each other (i.e. $y'y$).

\begin{example}{Linear Examples}{Linear Examples}\label{Linear Examples}
 The equation $\ds y' = 2t(25-y)$ can be written
$\ds y' + 2ty= 50t$. This is linear, but not homogeneous. The
equation $\ds y'=ky$, or $\ds y'-ky=0$ is linear and
homogeneous, with a particularly simple $p(t)=-k$.
The equation $y'+y^2=0$ is homogeneous, but not linear.
\end{example}

Since first order homogeneous linear equations are separable, we can
solve them in the usual way:
\begin{eqnarray*}
y' &=& -p(t)y\cr
\int {1\over y}\,dy &=& \int -p(t)\,dt\cr
\ln|y| &=& P(t)+C\cr
y&=&\pm\,e^{P(t)}\cr
y&=&Ae^{P(t)},
\end{eqnarray*}
where $P(t)$ is an anti-derivative of $-p(t)$. As in previous
examples, if we allow $A=0$ we get the constant solution $y=0$.

\begin{example}{Solving an IVP}{Solving an IVP}\label{Solving an IVP}
 Solve the initial value problem
$$\ds y' + y\cos t =0,$$
subject to $y(0)=1/2$ and $y(2)=1/2$.
\end{example}

\begin{solution}
We start with
$$P(t)=\int -\cos t\,dt = -\sin t,$$
so the general solution to the differential equation is
$$y=Ae^{-\sin t}.$$
To compute $A$ we substitute:
$$ {1\over 2} = Ae^{-\sin 0} = A,$$
so the solutions is
$$ y = {1\over 2} e^{-\sin t}.$$
For the second problem,
\begin{eqnarray*}
{1\over 2} &=& Ae^{-\sin 2}\cr
A &=& {1\over 2}e^{\sin 2}
\end{eqnarray*}
so the solution is
$$ y = {1\over 2}e^{\sin 2}e^{-\sin t}.$$
\vskip-15pt\end{solution}

\begin{example}{}{}\label{}
 Solve the initial value problem $ty'+3y=0$, $y(1)=2$,
assuming $t>0$.
\end{example}

\begin{solution}
We write the equation in standard form: $y'+3y/t=0$. Then
$$P(t)=\int -{3\over t}\,dt=-3\ln t$$
and
$$ y=Ae^{-3\ln t}=At^{-3}.$$
Substituting to find $A$:
$\ds 2=A(1)^{-3}=A$, so the solution is $\ds y=2t^{-3}$.
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:first order homogeneous linear}}

\begin{enumialphparenastyle}

Find the general solution of each equation in the following exercises.

\begin{multicols}{2}
%%%%%%%%%%
\begin{ex}
 $\ds y'+5y=0$
\begin{sol}
 $\ds y=Ae^{-5t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds y'-2y=0$
\begin{sol}
 $\ds y=Ae^{2t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds y'+{y\over 1+t^2}=0$
\begin{sol}
 $\ds y=Ae^{-\arctan t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds y'+t^2y=0$
\begin{sol}
 $\ds y=Ae^{-t^3/3}$
\end{sol}
\end{ex}

\end{multicols}

In the following exercises, solve the initial value problem.

\begin{multicols}{2}

%%%%%%%%%%
\begin{ex}
 $\ds y' + y=0$, $y(0)=4$
\begin{sol}
 $\ds y=4e^{-t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds y' -3y=0$, $y(1)=-2$
\begin{sol}
 $\ds y=-2e^{3t-3}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds y' + y\sin t = 0$, $y(\pi)=1$
\begin{sol}
 $\ds y=e^{1+\cos t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds y' +ye^t=0$, $y(0)=e$
\begin{sol}
 $\ds y=e^2e^{-e^t}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds y' +y\sqrt{1+t^4}=0$, $y(0)=0$
\begin{sol}
 $\ds y=0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds y' + y\cos(e^t)=0$, $y(0)=0$
\begin{sol}
 $\ds y=0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds ty' - 2y = 0$, $y(1)=4$
\begin{sol}
 $\ds y=4t^2$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds t^2y' + y = 0$, $y(1)=-2$, $t>0$
\begin{sol}
 $\ds y=-2e^{(1/t)-1}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds t^3y' = 2y$, $y(1)=1$, $t>0$
\begin{sol}
 $\ds y=e^{1-t^{-2}}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 $\ds t^3y' = 2y$, $y(1)=0$, $t>0$
\begin{sol}
 $\ds y=0$
\end{sol}
\end{ex}

\end{multicols}

%%%%%%%%%%
\begin{ex}
 A function $y(t)$ is a solution of $\ds y' +
ky=0$. Suppose that $y(0)=100$ and $y(2)=4$. Find $k$ and find $y(t)$.
\begin{sol}
 $k=\ln 5$, $\ds y=100e^{-t\ln 5}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 A function $y(t)$ is a solution of $\ds y' +
t^ky=0$. Suppose that $y(0)=1$ and $y(1)=e^{-13}$. Find $k$ and find
$y(t)$.
\begin{sol}
 $k=-12/13$, $\ds y=\exp(-13 t^{1/13})$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 A bacterial culture grows at a rate proportional to its
population. If the population is one million at $t=0$ and 1.5
million at $t=1$ hour, find the population as a function of time.
\begin{sol}
 $\ds y=10^6e^{t\ln(3/2)}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 A radioactive element decays with a half-life of 6 years. If
a mass of the element weighs ten pounds at $t=0$, find the amount of
the element at time $t$.
\begin{sol}
 $\ds y=10e^{-t\ln(2)/6}$
\end{sol}
\end{ex}

\end{enumialphparenastyle}


%%%%%%%%%%%%%%%%%%%%%definitions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input{../../doc/related_pages/header.tex}
\input{../../doc/related_pages/newcommands.tex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DOCUMENT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\title{The heat diffusion project}
\author{ M.~Wiesenberger and M.~Held}
\maketitle

\begin{abstract}
  This is a program for the 3d heat diffusion in arbitrary magnetic field
  geometry.
  \end{abstract}

\section{Equations}
The temperature $T$ follows a non-isotropic heat diffusion equation
\begin{align}
\frac{\partial T}{\partial t} = \nu_\perp \Delta_\perp T + \nu_\parallel\Delta_\parallel T
\label{eq:temperature}
\end{align}
with
\begin{align}
\Delta_\parallel T &= \nabla\cdot ( \bhat\bhat\cdot\nabla T) \\
\Delta_\perp T     &= -\nabla\cdot( \bhat\times(\bhat\times \nabla T)) \equiv \nabla\cdot (h \nabla T) \\
h^{ij} &= g^{ij} - b^ib^j
\end{align}
$\bhat = \bhat(\vec x)$ is the prescribed magnetic field unit vector, $g$ is the
metric and $h$ is the projection
tensor.
$\nu_\parallel$ and $\nu_\perp$ are the respective conduction
coefficients parallel and perpendicular to this field.

\subsection{Simulation domain}
We define the simulation box as
$[ R_{\min}, R_{\max}]\times [Z_{\min}, Z_{\max}] \times [0,2\pi]$,
where we define
\begin{align} \label{eq:box}
    R_{\min}&=R_0-\varepsilon^{R-}a\quad
    &&R_{\max}=R_0+\varepsilon^{R+}a\nonumber\\
    Z_{\min}&=-\varepsilon^{Z-}ae\quad
    &&Z_{\max}=\varepsilon^{Z+}ae
\end{align}
where $a$ is the minor radius, $e$ is the elongation of the flux surfaces and
the $\varepsilon$ are free parameters to be specified by the user.

\subsection{Initialization}
Initialization of $T$ is a Gaussian
\begin{align} \label{eq:initial}
  T(R,Z,\varphi) = 1 + A\exp\left(
      -\frac{(R-R_i)^2 + (Z-Z_i)^2}{2\sigma^2} - \frac{(\varphi-\pi)^2}{2\sigma_\varphi^2}\right)
\end{align}
where $R_i = p_x a$ and $Z_i = p_y a$ denote the initial position, $A$ is the amplitude and $\sigma$ the
radius of the blob.
\subsection{Diagnostics}
Integrating Eq.~\eqref{eq:temperature} over the volume yields
\begin{align}
 \frac{\partial}{\partial t} \int T \dV &=
    \int \dV ( \nu_\perp \Delta_\perp + \nu_\parallel \Delta_\parallel T) \\
 \frac{\partial}{\partial t} \int T^2/2 \dV &=
    \int \dV ( \nu_\perp T\Delta_\perp T + \nu_\parallel T\Delta_\parallel T)
\label{}
\end{align}
\section{Numerical methods}
discontinuous Galerkin on structured grid
\rowcolors{2}{gray!25}{white} %%% Use this line in front of longtable
\begin{longtable}{ll>{\RaggedRight}p{7cm}}
\toprule
\rowcolor{gray!50}\textbf{Term} &  \textbf{Method} & \textbf{Description}  \\ \midrule
coordinate system & Cylindrical 3D & equidistant discretization of $[R_0-a,R_0+a] \times [-a,a] \times [0,2\pi]$, equal number of Gaussian nodes in R and Z, one node in $\varphi$ \\
$\Delta_\parallel$ & FCI & forward-backward symmetric sym, See the documentation on DS\\
time &  Adaptive embedded ARK-4-2-3 & $3rd$ order accurate in both
explicit and implicit parts\\
\bottomrule
\end{longtable}

\section{Compilation and useage}
There are two programs heat.cu and heat\_hpc.cu . Compilation with
\begin{verbatim}
make device = <omp or gpu>
\end{verbatim}
Run with
\begin{verbatim}
path/to/feltor/src/heat/heat input.json geometry_params.json
path/to/feltor/src/heat/heat_hpc input.json geometry_params.json output.nc
\end{verbatim}
All programs write performance informations to std::cout.
The first opens a terminal window with life simulation results
the
other writes the results to disc. Both programs run on shared memory
systems.
For the hpc code, there is another mode:
\begin{verbatim}
path/to/feltor/src/heat/heat_hpc input.json geometry_params.json output.nc input.nc
\end{verbatim}
In this case the temperature field of \code{input.nc} at the last output
time is read
and taken as a reference solution.

\subsection{Input file structure}
Input file format: json

%%This is a booktabs table
\begin{longtable}{llll>{\RaggedRight}p{7cm}}
\toprule
\rowcolor{gray!50}\textbf{Name} &  \textbf{Type} & \textbf{Example} & \textbf{Default} & \textbf{Description}  \\ \midrule
  n      & integer & 3 & - &\# Gaussian nodes in x and y \\
  Nx     & integer &20& - &\# grid points in x \\
  Ny     & integer &40& - &\# grid points in y \\
  Nz     & integer &60& - &\# grid points in z \\
  dt     & integer &0.001& - &initial time step\\
  cx & integer & 2 & 1 & output contains n*Nx/cx points in x,
    has to divde Nx evenly\\
  cy & integer & 2 & 1 & output contains n*Ny/cy points in y,
    has to divde Ny evenly\\
  itstp  & integer &2  & - &   steps between outputs \\
  maxout & integer &100& - &      \# outputs excluding first \\
  eps\_time  & float &1e-10   & - & accuracy of implicit solver in time-stepper \\
  rtol  & float  & 1e-6  & - & desired tolerance of adaptive time-stepper \\
  nu\_parallel    & float &100   & - & parallel viscosity $\nu_\parallel$ \\
  nu\_perp    & float &0   & - & perpendicular viscosity $\nu_\perp$ \\
  amplitude  & float &0.1    & - & amplitude $A$ of the blob in Eq.~\eqref{eq:initial}\\
  sigma      & float &5     & - & blob radius $\sigma$ in $R$ and $Z$ in Eq.~\eqref{eq:initial} \\
  sigma\_z   & float &0.025  & - & variance in $\varphi$ in units of $R_0$ in Eq.~\eqref{eq:initial}  \\
  posX       & float &0.8    & - & blob $R$-position in units of $a$ in Eq.~\eqref{eq:initial} \\
  posY       & float &0    & - & blob $Z$-position in units of $a$ in Eq.~\eqref{eq:initial} \\
  bcx   & char & "NEU"      & - & boundary condition in R (one of PER, DIR, NEU, DIR\_NEU or NEU\_DIR) \\
  bcy   & char & "NEU"      & - & boundary condition in Z (one of PER, DIR, NEU, DIR\_NEU or NEU\_DIR) \\
  boxscaleRp & float &  1.05, & - & $\varepsilon^{R+}$ in Eq.~\eqref{eq:box} \\
  boxscaleRm & float &  1.05, & - & $\varepsilon^{R-}$ in Eq.~\eqref{eq:box} \\
  boxscaleZp & float &  1.05, & - & $\varepsilon^{Z+}$ in Eq.~\eqref{eq:box} \\
  boxscaleZm & float &  1.15, & - & $\varepsilon^{Z-}$ in Eq.~\eqref{eq:box} \\
  mx     & integer & 10 & - & refinement factor of DS in x \\
  my     & integer & 10 & - & refinement factor of DS in y \\
  rk4eps & float & 0.01 & 1e-5 & Accuracy of fieldline integration in DS \\
  diff       & char & non-adjoint & non-adjoint & adjoint, non-adjoint, elliptic (discretization for $\Delta_\parallel$) \\
\bottomrule
\end{longtable}

The default value is taken if the value name is not found in the input file. If there is no default and
the value is not found,
the program exits with an error message.

\subsection{Geometry file structure}
File format: json

%%This is a booktabs table
\begin{longtable}{llll>{\RaggedRight}p{7cm}}
\toprule
\rowcolor{gray!50}\textbf{Name} &  \textbf{Type} & \textbf{Example} & \textbf{Default} & \textbf{Description}  \\ \midrule
    A      & float & 1 &  - & Solovev parameter \\
    R\_0   & float & - & -  & Major radius in $\rho_s$ \\
    C      & float[12] &  - & - & Solovev coefficients \\
    elongation & float & 1 & - & Elongation \\
    triangularity & float & 0 & - & Triangularity \\
    inverseaspectratio & float & 0.16667 & - & $a/R_0$ \\
\bottomrule
\end{longtable}

\subsection{Structure of output file}
Output file format: netcdf-4/hdf5
%
%Name | Type | Dimensionality | Description
%---|---|---|---|
\begin{longtable}{lll>{\RaggedRight}p{7cm}}
\toprule
\rowcolor{gray!50}\textbf{Name} &  \textbf{Type} & \textbf{Dimension} & \textbf{Description}  \\ \midrule
inputfile  &     text attribute & 1 & verbose input file as a string \\
geomfile   &     text attribute & 1 & verbose geometry input file as a string \\
energy\_time     & Dataset & 1 & timesteps at which 1d variables are written \\
time             & Dataset & 1 & time at which temperature is written \\
x                & Dataset & 1 & x-coordinate  \\
y                & Dataset & 1 & y-coordinate \\
z                & Dataset & 1 & z-coordinate \\
T                & Dataset & 4 (time, z, y, x) & temperature $T$ \\
energy           & Dataset & 1 (energy\_time) & total energy integral  \\
entropy          & Dataset & 1 (energy\_time) & total entropy integral  \\
mass             & Dataset & 1 (energy\_time) & mass integral   \\
dEdt             & Dataset & 1 (energy\_time) & change of energy per time  \\
dissipation      & Dataset & 1 (energy\_time) & diffusion integrals  \\
accuracy         & Dataset & 1 (energy\_time) & accuracy in time  \\
error            & Dataset & 1 (energy\_time) & relative distance to temperature field at time 0\\
relerror         & Dataset & 1 (energy\_time) & relative difference to reference solution if one is provide, else 0 \\
\bottomrule
\end{longtable}

%..................................................................
\bibliography{../../doc/related_pages/references}
%..................................................................

\end{document}


\input{../../assignment-header}

%========================================================================
\title{Assignment 5:  Quadrotor Control via LQR}
\date{Assigned:  Feb 13  ---  Due:  Feb 27}
\author{Tufts ME 149:  Optimal Control For Robotics}
%========================================================================
\begin{document}
\maketitle
%=================================================

\section*{Introduction}

In this assignment you will design two controllers for a
planar model of a quadrotor helicopter.
The first controller will be designed using infinite-horizon LQR and
will be used to regular the state of the quadrotor in a stationary hover.
The second controller will be designed using finite-horizon (trajectory) LQR
and will stabilize an arbitrary reference trajectory that starts and ends in
a static hover.

\par
Unlike previous assignments, you will not need to submit any plots.
Instead, for each part of the assignment you will submit a Matlab function
that returns a function handle for a feedback controller.
Your controller will be evaluated by a set of automated unit tests.
These tests will run simulations of the closed loop system with a variety of
different perturbations, disturbances, and other error sources.

\par
You should write your own test scripts to ensure that your controllers work.
There are no direct requirements on these tests, although you should submit them
along with your other code. A few things that you could test,

\section*{Planar Quadrotor Model}

This assignment is centered around controlling a planar quadrotor model.
All of the dynamics functions that you will need are provided in the ME-149
code library:\\
\texttt{ME149/codeLibrary/modelSystems/planarQuadrotor/}.

\par
There are several parameters for the quadrotor. Your controller design function
should work for any valid set of parameters, but you may choose the following
set of nominal values for your tests:
\texttt{param.m = 0.4}, \texttt{param.w = 0.4}, \texttt{param.g = 10}

\par
In addition to the dynamics functions, the code library also provides a variety
of useful diagnostics tools for the quadrotor. For example, you can visualize the
output of a simulation using the
\texttt{planarQuadrotorPlot()} to generate a plot of the state and control versus time,
or \texttt{planarQuadrotorAnimate()} to generate an interactive animation.

\par
For the purposes of testing, I have included a special version of the dynamics
function:\\
\texttt{planarQuadrotorRealDyn()} that implements a more realistic
version of the dynamics. In particular, it adds a random disturbance force that
is a rough proxy for wind. By default it will always use the same disturbance,
but you can pass a seed to the random number generator to test additional disturbances.
You can also adjust the magnitude of the disturbances (see the help file for details).

\section*{Part One: Hover Controller}

For the first part of this assigment you will need to implement the file
\texttt{getHoverController.m}, included below. The output of this function is
a feedback controller (as a function handle) that can be passed into a simulation.

Also write a test for the controller (\texttt{TEST\_getHoverController.m}).
This function (or script) should generate one or more simulations that test
your controller and demonstrate that it is reliable.

\pagebreak
\lstinputlisting{getHoverController.m}

\section*{Part Two: Trajectory Tracking}

The second part of this assignment is similar to the first, except that now you
will design a trajectory tracking controller instead of a hovering controller.
As with the first part, you do not need to submit plots - instead you will
implement two matlab functions: \\
\texttt{getTrackingController.m} \\
\texttt{trajectoryLqr.m} \\

\par
The first function will design a trajectory tracking controller,
and the second function computes the time-varying LQR gains along a reference trajectory.
The details for implementation are included in the files.
Your controller will be evaluated by running it through a series of automated
test simulations.

\par
You should thoroughly test you controller before submitting to make sure that it works.
Submit the test script (\texttt{TEST\_getTrackingController.m}) to Trunk along with the rest of your code.
The only requirement for this test script is that it
should demonstrate that you controller works by running one or more simulations
and then generating some meaningful output.

\par
The assignment includes an single reference trajectory that guides the quadrotor
through a back-flip while moving horizontally between two static hover poses.
The function \texttt{importReferenceTrajectory.m} can be used to import this data and convert
it into a useful format.

\section*{Write-Up}

In addition to the Matlab files listed above, please also upload a short write-up
for this assignment: \\
\texttt{hw\_05\_studentName\_writeup.txt}
\vspace{-0.0em} \begin{itemize}  \setlength\itemsep{0em} \setlength\itemindent{18pt}
  \item Header: full name, date, assignment name and number
  \item List any other students that you worked with.
  \item How long did this assignment take you?
  \item Briefly describe your approach to testing your controllers.
\end{itemize}

%=================================================
\end{document}


\documentclass[pre,aps,superscriptaddress,nofootinbib]{revtex4}

\usepackage{amsmath,amsfonts,amssymb,bm,graphicx,hyperref,listings,xcolor,float}
\setlength{\parindent}{0pt}

\begin{document}

\title{2 RTPs on a ring}
\author{Yann-Edwin Keta}
\maketitle

% \maketitle

\nocite{Slowman2016, Nemoto2016, Chetrite2015}

\section{Model}

\subsection{Fokker-Planck equations}

We consider 2 run-and-tumble particles (RTPs), with swim speed $v_0$ and tumble rate $\tau^{-1}$ on a linear ring of length $L$. With $r_1, r_2 \in [0, L]$ the positions and $\alpha_1, \alpha_2 = \pm$ the states of each particles, and $V(r_1, r_2) = V(|r_1 - r_2|)$ the potential of interactions between these particles, we have the equations of motion
\begin{equation}
\dot{r}_i = \alpha_i v_0 - \partial_{r_i} V(|r_1 - r_2|)
\label{EOM}
\end{equation}
and the Fokker-Planck equations for the joint distribution of positions
\begin{equation}
\begin{aligned}
\dot{P}_{\alpha_1, \alpha_2}(r_1, r_2) =
  &- v_0(\alpha_1 \partial_{r_1} + \alpha_2 \partial_{r_2}) P_{\alpha_1\alpha_2}(r_1, r_2)
    &&\to \text{Propulsion}\\
  &+ \partial_{r_1} (P_{\alpha_1\alpha_2}(r_1, r_2)\partial_{r_1}V(|r_1 - r_2|))
    &&\to \text{Interaction}\\
  &+ \partial_{r_2} (P_{\alpha_1\alpha_2}(r_1, r_2)\partial_{r_2}V(|r_1 - r_2|))
    &&\\
  &+ \tau^{-1} (P_{\overline{\alpha_1}\alpha_2}(r_1, r_2) + P_{\alpha_1\overline{\alpha_2}}(r_1, r_2) - 2 P_{\alpha_1\alpha_2}(r_1, r_2))
    &&\to \text{Tumble}\\
  =& \, \mathcal{L}^{\dagger}_{\alpha_1\alpha_2} P_{\alpha_1\alpha_2}(r_1, r_2)
\end{aligned}
\label{FP0}
\end{equation}
with $\mathcal{L}^{\dagger}_{\alpha_1\alpha_2}$ the Fokker-Planck operator.\\

We introduce $r \equiv r_2 - r_1 \geq 0$, such that $\partial_{r_1} \equiv - \partial_r$ and $\partial_{r_2} = \partial_r$, with which we can define the symmetries
\begin{eqnarray}
\label{evensymmetry}
P_{++}(r) = P_{--}(r),\\
\label{oddsymmetry}
P_{+-}(r) = P_{-+}(L - r),
\end{eqnarray}
and the interaction potential
\begin{align*}
V(r) = \begin{cases} 0 &\text{ if } r \in ]0, L[ \\ \infty &\text{ otherwise} \end{cases}
\end{align*}
such that, with Eq. (\ref{EOM}), we get for particles with opposite directions
\begin{equation}
- \partial_r V(0) = \partial_r V(L) = v_0.
\end{equation}
because of mutual hindrance.\\

We can solve the steady state problem with the normalisation condition
\begin{equation}
\int_0^L \mathrm{d}r \, \sum_{\alpha_1\alpha_2} P_{\alpha_1\alpha_2}(r) = 1
\label{normalisation}
\end{equation}
the bulk equations
\begin{equation}
\dot{P}_{\alpha_1\alpha_2}(r \in ]0, L[) = 0
\label{bulk}
\end{equation}
the left boundary equations
\begin{equation}
\int_{0^-}^{0^+} \mathrm{d}r \, \dot{P}_{\alpha_1\alpha_2}(r) = 0
\label{leftboundary}
\end{equation}
and the right boundary equations
\begin{equation}
\int_{L^-}^{L^+} \mathrm{d}r \, \dot{P}_{\alpha_1\alpha_2}(r) = 0.
\label{rightboundary}
\end{equation}

\subsection{Biased ensemble}

We define our biasing quantity
\begin{equation}
\dot{Z} = \sum_{i=1}^2 - \partial_{r_i} V(r) \alpha_i v_0 = v_0 (\alpha_1 - \alpha_2) \partial_r V(r)
\end{equation}
which is non-zero only at contact, and the tilted generator
\begin{equation}
\mathcal{W}^{\dagger}_{\alpha_1\alpha_2} = \mathcal{L}^{\dagger}_{\alpha_1\alpha_2} - s \dot{Z}
\end{equation}
with $s$ the biasing parameter, which eigenvalue problem
\begin{equation}
\psi P_{\alpha_1\alpha_2}(r) = \mathcal{W}^{\dagger}_{\alpha_1\alpha_2} P_{\alpha_1\alpha_2}(r)
\label{eigenproblem}
\end{equation}
we have to solve for $\psi(s)$ its largest eigenvalue, which defines the dynamical free energy.\\

While the symmetries (Eqs. (\ref{evensymmetry}, \ref{oddsymmetry})) and the normalisation condition (Eq. (\ref{normalisation})) remains unchanged, we have that the bulk equations (Eq. (\ref{bulk})), the left boundary equations (Eq. \ref{leftboundary}), and the right boundary equations (Eq. \ref{rightboundary}) become
\begin{eqnarray}
\label{bulk:biased}
\psi P_{\alpha_1\alpha_2}(r \in ]0, L[) = \mathcal{W}^{\dagger}_{\alpha_1\alpha_2} P_{\alpha_1\alpha_2}(r \in ]0, L[)\\
\label{leftboundary:biased}
\int_{0^-}^{0^+} \mathrm{d}r \, \psi P_{\alpha_1\alpha_2}(r) = \int_{0^-}^{0^+} \mathrm{d}r \, \mathcal{W}^{\dagger}_{\alpha_1\alpha_2} P_{\alpha_1\alpha_2}(r)\\
\label{rightboundary:biased}
\int_{L^-}^{L^+} \mathrm{d}r \, \psi P_{\alpha_1\alpha_2}(r) = \int_{L^-}^{L^+} \mathrm{d}r \, \mathcal{W}^{\dagger}_{\alpha_1\alpha_2} P_{\alpha_1\alpha_2}(r)
\end{eqnarray}
respectively.

\section{Unbiased steady state distribution}

We use the following ansatz for the unbiased ($s = 0$) steady state distribution
\begin{equation}
P_{\alpha_1\alpha_2}(r) = a_{\alpha_1\alpha_2} + b_{\alpha_1\alpha_2} \delta(r) + c_{\alpha_1\alpha_2} \delta(L - r)
\end{equation}
which satisfies the normalisation condition (Eq. (\ref{normalisation}))
\begin{equation}
\sum_{\alpha_1\alpha_2} \left(L a_{\alpha_1\alpha_2} + b_{\alpha_1\alpha_2} + c_{\alpha_1\alpha_2}\right) = 1
\end{equation}
the bulk equations (Eq. (\ref{bulk}))
\begin{eqnarray}
\tau^{-1} (a_{+-} + a_{-+} - 2 a_{++}) = 0\\
\tau^{-1} (a_{+-} + a_{-+} - 2 a_{--}) = 0\\
\tau^{-1} (a_{++} + a_{--} - 2 a_{+-}) = 0\\
\tau^{-1} (a_{++} + a_{--} - 2 a_{-+}) = 0
\end{eqnarray}
the left boundary equations (Eq. (\ref{leftboundary}))
\begin{eqnarray}
\tau^{-1}(b_{+-} + b_{-+} - 2 b_{++}) = 0\\
\tau^{-1}(b_{+-} + b_{-+} - 2 b_{--}) = 0\\
2 v_0 a + \tau^{-1}(b_{++} + b_{--} - 2 b_{+-}) = 0\\
- 2 v_0 a + \tau^{-1}(b_{++} + b_{--} - 2 b_{-+}) = 0
\end{eqnarray}
the right boundary equations (Eq. (\ref{rightboundary}))
\begin{eqnarray}
\tau^{-1}(c_{+-} + c_{-+} - 2 c_{++}) = 0\\
\tau^{-1}(c_{+-} + c_{-+} - 2 c_{--}) = 0\\
- 2 v_0 a + \tau^{-1}(c_{++} + c_{--} - 2 c_{+-}) = 0\\
2 v_0 a + \tau^{-1}(c_{++} + c_{--} - 2 c_{-+}) = 0
\end{eqnarray}
and the symmetries (Eqs. (\ref{evensymmetry}, \ref{oddsymmetry})).\\

We get
\begin{eqnarray}
\label{s0++}
P_{++}(r) = a + l a \delta(r) + l a \delta(L - r)\\
\label{s0--}
P_{--}(r) = a + l a \delta(r) + l a \delta(L - r)\\
\label{s0+-}
P_{+-}(r) = a + 2 l a \delta(r)\\
\label{s0-+}
P_{-+}(r) = a + 2 l a \delta(L - r)
\end{eqnarray}
with
\begin{equation}
a = \frac{1}{4(L + 2l)}
\label{smooth_unbiased}
\end{equation}
and the persistence length $l = v_0 \tau$.

\section{Biased steady state distribution}
\label{sec:biased-distribution}

\subsection{Exact solution}

We use the following ans\"atze for the steady state distribution
\begin{eqnarray}
P_{++}(r) = P_{--}(r) = \beta(r) + \gamma_- \delta(r) + \gamma_+ \delta(L - r)\\
P_{+-}(r) = \varepsilon(r) + \zeta \delta(r)\\
P_{-+}(r) = \theta(r) + \zeta \delta(L - r)\\
\end{eqnarray}
with $\varepsilon(r) = \theta(L - r)$ according to Eq. (\ref{oddsymmetry}).\\

We write the eigenvalue equations (Eq. (\ref{eigenproblem}))
\begin{eqnarray}
\label{FP1}
\psi P_{\alpha\alpha}(r) = 2 \partial_r(P_{\alpha\alpha}(r) \partial_r V(r)) + \tau^{-1} (P_{+-}(r) + P_{-+}(r) - 2 P_{\alpha\alpha}(r))\\
\label{FP2}
\psi P_{+-}(r) = 2 v_0 \partial_r P_{+-}(r) + 2 \partial_r(P_{+-}(r) \partial_r V(r)) + \tau^{-1}(2 P_{\alpha\alpha}(r) - 2 P_{+-}(r)) - 2 s v_0 \partial_r V(r) P_{+-}(r)\\
\label{FP3}
\psi P_{-+}(r) = - 2 v_0 \partial_r P_{-+}(r) + 2 \partial_r(P_{-+}(r) \partial_r V(r)) + \tau^{-1}(2 P_{\alpha\alpha}(r) - 2 P_{-+}(r)) + 2 s v_0 \partial_r V(r) P_{-+}(r)
\end{eqnarray}
and integrate from Eqs. (\ref{FP1}, \ref{FP2}, \ref{FP3}) the sum of $\psi(2 P_{\alpha\alpha} + P_{+-} + P_{-+})$ between $0^-$ and $L^+$ to get
\begin{equation}
\psi = 4 s v_0 \partial_r V(L) \zeta = 4 s v_0^2 \zeta
\label{psiZeta}
\end{equation}
linking the dynamical free energy $\psi$ and the sticking term $\zeta$.\\

We have the bulk equations (Eq. (\ref{bulk:biased}))
\begin{eqnarray}
\label{bulk:biased1}
\psi \beta(r) = \tau^{-1} (\varepsilon(r) + \theta(r) - 2 \beta(r))\\
\label{bulk:biased2}
\psi \epsilon(r) = 2 v_0 \varepsilon^{\prime}(r) + \tau^{-1} (2 \beta(r) - 2 \varepsilon(r))\\
\label{bulk:biased3}
\psi \theta(r) = -2 v_0 \theta^{\prime}(r) + \tau^{-1} (2 \beta(r) - 2 \theta(r))
\end{eqnarray}
such that Eq. (\ref{bulk:biased1}) gives
\begin{equation}
\beta(r) = (2 + \tau\psi)^{-1} (\epsilon(r) + \theta(r))
\end{equation}
and the difference and sum of Eqs. (\ref{bulk:biased2}, \ref{bulk:biased3}) give
\begin{eqnarray}
2 l (\varepsilon(r) + \theta(r))^{\prime} = (2 + \tau \psi)(\varepsilon(r) - \theta(r))\\
\begin{aligned}
2 l (\varepsilon(r) - \theta(r))^{\prime} &= -4 \beta(r) + (\tau\psi + 2)(\varepsilon(r) + \theta(r))\\
&= \left((\tau\psi + 2) - \frac{4}{\tau\psi + 2}\right)(\varepsilon(r) + \theta(r))
\end{aligned}
\end{eqnarray}
where we set $A(r) = \varepsilon(r) + \theta(r)$ and $B(r) = \varepsilon(r) - \theta(r)$, which on the one hand verify
\begin{equation}
A^{\prime\prime}(r) - k^2 A(r) = 0
\end{equation}
where
\begin{equation}
k^2 l^2 = \tau \psi \left(\frac{\tau \psi}{4} + 1\right)
\label{kPsi}
\end{equation}
and which general solution is
\begin{equation}
A(r) = A_+ e^{- k r} + A_- e^{-k (L - r)}
\end{equation}
and on the other hand
\begin{equation}
B(r) = l(1 + \tau \psi/2)^{-1} A^{\prime}(r) = kl (1 + \tau\psi/2)^{-1} (A_- e^{-k(L - r)} - A_+ e^{-k r})
\end{equation}
from which we infer
\begin{eqnarray}
\label{epsilon}
\begin{aligned}
\varepsilon(r) &= \frac{1}{2} (A(r) + B(r))\\
&= \frac{1}{2}\left(1 - k l (1 + \psi \tau/2)^{-1}\right) A_+ e^{- k r} + \frac{1}{2}\left(1 + k l (1 + \psi \tau/2)^{-1}\right) A_- e^{- k (L - r)}
\end{aligned}
\mbox{}\\
\label{theta}
\begin{aligned}
\theta(r) &= \frac{1}{2} (A(r) - B(r))\\
&= \frac{1}{2}\left(1 + k l (1 + \psi \tau/2)^{-1}\right) A_+ e^{- k r} + \frac{1}{2}\left(1 - k l (1 + \psi \tau/2)^{-1}\right) A_- e^{- k (L - r)}
\end{aligned}
\end{eqnarray}
where we note that the symmetry condition of Eq. (\ref{oddsymmetry}) implies that $A_- = A_+$, and
\begin{equation}
\begin{aligned}
\beta(r) &= (\tau\psi + 2)^{-1}(\varepsilon(r) + \theta(r)) = (\tau \psi + 2)^{-1} A(r)\\
&= (1 + \tau\psi/2)^{-1}(A_+ e^{-k r} + A_- e^{-k (L - r)})
\end{aligned}
\label{beta}
\end{equation}
where we need to determine $A_+ = A_-$.\\

We have the left and right boundary equations (Eqs. (\ref{leftboundary:biased}, \ref{rightboundary:biased})) for $P_{\alpha\alpha}$
\begin{eqnarray}
\psi \gamma_- = \tau^{-1} (\zeta - 2 \gamma_-)\\
\psi \gamma_+ = \tau^{-1} (\zeta - 2 \gamma_+)
\end{eqnarray}
such that
\begin{equation}
\gamma = \gamma_- = \gamma_+ = (\tau \psi + 2)^{-1} \zeta
\label{ratio_gamma}
\end{equation}
which with Eq. (\ref{psiZeta}) gives
\begin{equation}
\psi = 4 s v_0^2 (\tau \psi + 2) \gamma
\label{gammaPsi}
\end{equation}
where we need to determine $\gamma$.\\

We have the left boundary equations (Eq. (\ref{leftboundary:biased})) for $P_{\alpha\overline{\alpha}}$
\begin{eqnarray}
\label{LBe1}
\psi \zeta = 2 v_0 \varepsilon(0^+) + \tau^{-1} (2 \gamma - 2 \zeta) - 2 s v_0 \partial_r V(0) \zeta\\
\label{LBe2}
0 = - 2 v_0 \varepsilon(L^-) + \tau^{-1} 2 \gamma
\end{eqnarray}
from which we get
\begin{eqnarray}
\label{S1}
\left[(\tau\psi + 2)(\tau\psi + 2 - 2 s l v_0) - 2\right] \gamma - l \left(1 - kl  (1 + \tau\psi/2)^{-1}\right) A_+ - l \left(1 + kl(1 + \tau\psi/2)^{-1}\right) e^{-kL} A_- = 0\\
\label{S2}
2 \gamma - l \left(1 - kl (1 + \tau\psi/2)^{-1}\right) e^{-kL} A_+ - l \left(1 + kl (1 + \tau\psi/2)^{-1}\right) A_- = 0
\end{eqnarray}
and the normalisation condition (Eq. (\ref{normalisation}))
\begin{equation}
(2 \tau \psi + 8) \gamma + \frac{1}{k} (1 - e^{-kL})(1 + (1 + \tau\psi/2)^{-1})(A_+ + A_-) = 1
% 2((\tau\psi + 2) + 1) \gamma + \frac{1}{k} \left(1 - e^{-kL}\right)\left(1 + (\tau\psi + 2)^{-1}\right) A_+ + \frac{1}{k} \left(1 - e^{-kL}\right)\left(1 + (\tau\psi + 2)^{-1}\right) A_- = 1
\label{S3}
\end{equation}
so we can solve the system of Eqs. (\ref{S1}, \ref{S2}, \ref{S3}) with respect to $\gamma$, $A_+$, $A_-$, or equivalently with $A_+ = A_-$
\begin{eqnarray}
\label{S01}
\left[(\tau\psi + 2)(\tau\psi + 2 - 2 s l v_0) - 2\right] \gamma - l \left[\left(1 - kl  (1 + \tau\psi/2)^{-1}\right) + \left(1 + kl(1 + \tau\psi/2)^{-1}\right) e^{-kL}\right] A_- = 0\\
\label{S02}
% 2((\tau\psi + 2) + 1) \gamma + \frac{2}{k} \left(1 - e^{-kL}\right)\left(1 + (\tau\psi + 2)^{-1}\right) A_+ = 1
(2 \tau \psi + 8) \gamma + \frac{2}{k} (1 - e^{-kL})(1 + (1 + \tau\psi/2)^{-1}) A_+ = 1
\end{eqnarray}
with respect to $A_+$ and $\gamma$.\\

We use \textsc{SageMath} to solve Eqs. (\ref{S01}, \ref{S02})
\begin{lstlisting}[backgroundcolor=\color{lightgray!20!white}, language=Python, xleftmargin=0.5cm, xrightmargin=0.5cm, framexleftmargin = 0.5em, frame=tlbr,framesep=4pt]
# variables
psi = var('psi')
tau = var('tau')
k = var('k')
L = var('L')
l = var('l')
v0 = var('v0')
s = var('s')

# system [gamma, A]
system = Matrix([

    [(tau*psi + 2)*(tau*psi + 2 - 2*s*l*v0) - 2,
    -l*((1 - k*l/(1 + (tau*psi)/2)) + (1 + k*l/(1 + (tau*psi)/2))*exp(-k*L))],

    [2*tau*psi + 8,
    (2/k)*(1 - exp(-k*L))*(1 + 1/(tau*psi + 2))]

])

# solution
[[gamma], [A]] = system \ Matrix([[0], [1]])
\end{lstlisting}
and get
\begin{eqnarray}
\gamma = -\frac{1}{2 \, {\left(\frac{{\left(\psi \tau + 4\right)} {\left({\left(\frac{2 \, k l}{\psi \tau + 2} + 1\right)} e^{\left(-L k\right)} - \frac{2 \, k l}{\psi \tau + 2} + 1\right)} l}{{\left(2 \, l s v_{0} - \psi \tau - 2\right)} {\left(\psi \tau + 2\right)} + 2} + \frac{{\left(\frac{1}{\psi \tau + 2} + 1\right)} {\left(e^{\left(-L k\right)} - 1\right)}}{k}\right)}}\\
A_+ = A_- = \frac{{\left({\left(\frac{2 \, k l}{\psi \tau + 2} + 1\right)} e^{\left(-L k\right)} - \frac{2 \, k l}{\psi \tau + 2} + 1\right)} l}{2 \, {\left({\left(2 \, l s v_{0} - \psi \tau - 2\right)} {\left(\psi \tau + 2\right)} + 2\right)} {\left(\frac{{\left(\psi \tau + 4\right)} {\left({\left(\frac{2 \, k l}{\psi \tau + 2} + 1\right)} e^{\left(-L k\right)} - \frac{2 \, k l}{\psi \tau + 2} + 1\right)} l}{{\left(2 \, l s v_{0} - \psi \tau - 2\right)} {\left(\psi \tau + 2\right)} + 2} + \frac{{\left(\frac{1}{\psi \tau + 2} + 1\right)} {\left(e^{\left(-L k\right)} - 1\right)}}{k}\right)}}.
\end{eqnarray}

\subsection{Scaling regime}

We assume there exists a scaling form
\begin{equation}
\psi(s) = L^{-2} \varphi(s L)
\end{equation}
so that for $s = \mathcal{O}(L^{-1})$ we have $\psi(s) = \mathcal{O}(L^{-2})$ and $k = \mathcal{O}(L^{-1})$ from Eq. (\ref{kPsi}).\\

We give an expression of Eqs. (\ref{S2}, \ref{S3}) at the lowest order of $L^{-1}$ and using $A_+ = A_-$
\begin{eqnarray}
\label{SC1}
2 \gamma - l(1 + e^{-kL}) A_+ = 0\\
\label{SC2}
8 \gamma + \frac{4}{k} (1 - e^{-kL}) A_+ = 1
\end{eqnarray}
from which we infer
\begin{equation}
\label{SCgamma}
\gamma = \frac{1}{8} k l \frac{1 + e^{-kL}}{1 - e^{-kL}}
\end{equation}
and an expression of Eq. (\ref{gammaPsi}) at the lowest order of $L^{-1}$
\begin{equation}
\gamma = \frac{\psi}{8 s v_0^2}
\end{equation}
which with Eq.(\ref{kPsi}) linking $k$ and $\psi$, also at the lowest order of $L^{-1}$,
\begin{equation}
\label{SCkl}
k^2 l^2 = \tau \psi \Rightarrow k = \begin{cases} \frac{1}{l} \sqrt{\tau\psi} &\text{ if } s > 0, \\ 0 &\text{ if } s = 0, \\ \mathrm{i} \, \frac{1}{l} \sqrt{- \tau\psi} &\text{ if } s < 0, \end{cases}
\end{equation}
give
\begin{eqnarray}
\frac{2}{s L v_0} = \frac{\coth\left(\sqrt{\frac{\psi L^2}{4 l v_0}}\right)}{\sqrt{\frac{\psi L^2}{4 l v_0}}} \Leftrightarrow \frac{1}{\Lambda} = \frac{\coth\left(\sqrt{\Psi}\right)}{\sqrt{\Psi}} &\qquad\qquad s > 0, \psi > 0\\
- \frac{2}{s L v_0} = \frac{\cot\left(\sqrt{\frac{|\psi| L^2}{4 l v_0}}\right)}{\sqrt{\frac{|\psi| L^2}{4 l v_0}}} \Leftrightarrow - \frac{1}{\Lambda} = \frac{\cot\left(\sqrt{|\Psi|}\right)}{\sqrt{|\Psi|}} &\qquad\qquad s < 0, \psi < 0
\end{eqnarray}
where we have set
\begin{eqnarray}
\label{Lambda}
\Lambda = \frac{s L v_0}{2}\\
\label{Phi}
\Psi = \frac{\psi L^2}{4 l v_0} = \frac{\varphi}{4 l v_0}
\end{eqnarray}
for convenience, and introduce
\begin{equation}
\Gamma = \frac{\Psi}{\Lambda} = \frac{\psi}{8 s v_0^2} \frac{4 L}{l} = \gamma \frac{4 L}{l}
\label{eqGamma}
\end{equation}
which we plot in Fig. \ref{Gamma}.

\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{gamma.eps}
\caption{Rescaled sticking term $\Gamma = (4L/l) \, \gamma$ as a function of rescaled biasing parameter $\Lambda = s L v_0/2$.}
\label{Gamma}
\end{figure}

At the lowest order in $L^{-1}$ we have from Eqs. (\ref{epsilon}, \ref{theta}, \ref{beta})
\begin{equation}
\varepsilon(r) = \theta(r) = \beta(r) = \frac{1}{2} A_+ (e^{-kr} + e^{-k(L-r)})
\end{equation}
and from Eqs. (\ref{SC1}, \ref{SC2}, \ref{SCgamma})
\begin{equation}
A_+ = \frac{2\gamma}{l} \frac{1}{1 + e^{-kL}} = \frac{k}{4(1 - e^{-kL})}
\end{equation}
so we can write with Eqs. (\ref{SCkl}, \ref{Lambda}, \ref{Phi}, \ref{eqGamma})
\begin{equation}
L \varepsilon(r) = \frac{1}{4} \Gamma \begin{cases} \frac{\cosh\left(\sqrt{\Psi}(1 - 2r/L)\right)}{\cosh\left(\sqrt{\Psi}\right)} &\text{ if } s > 0, \\ 1 &\text{ if } s = 0, \\ \frac{\cos\left(\sqrt{|\Psi|}(1 - 2r/L)\right)}{\cos\left(\sqrt{|\Psi|}\right)} &\text{ if } s < 0, \end{cases}
\end{equation}
which we plot in Fig. \ref{fig:epsilon}.

\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{epsilon.eps}
\caption{Rescaled regular part $L \varepsilon(r)$ as a function of rescaled distance $r/L$ for different values of the rescaled biasing parameter $\Lambda = s L v_0/2$.}
\label{fig:epsilon}
\end{figure}

\section{Solution to the adjoint eigenproblem}

\subsection{General solution}

We have computed the left eigenvectors $P_{\alpha_1\alpha_2}$ of Eq.~\ref{eigenproblem} corresponding to the SCGF $\psi(\lambda)$ in Sec.~\ref{sec:biased-distribution}, and will now compute the right eigenvectors $Q_{\alpha_1\alpha_2}$.
We introduce $Y_{\alpha_1\alpha_2}(r) = P_{\alpha_1\alpha_2}(r) Q_{\alpha_1\alpha_2}(r)$ which has the same symmetries as $P_{\alpha_1\alpha_2}(r)$, so that $Q_{\alpha_1\alpha_2}(r)$ also has these properties.\\

We assume that the normalisation condition
\begin{equation}
\int_0^L \sum_{\alpha_1, \alpha_2 = \pm 1} Y_{\alpha_1\alpha_2}(r) \, \mathrm{d}r = 1
\label{normalisation_pave}
\end{equation}
as well as the general form
\begin{eqnarray}
\label{gfY1}
Y_{\alpha\alpha}(r) = \hat{\varepsilon}_{\alpha\alpha}(r) + \hat{\gamma}_{\alpha\alpha} \delta (r) +  \hat{\gamma}_{\alpha\alpha} \delta (L - r)\\
\label{gfY2}
Y_{+-}(r) = \hat{\varepsilon}_{+-}(r) + \hat{\gamma}_{\alpha\overline{\alpha}} \delta (r)\\
\label{gfY3}
Y_{-+}(r) = \hat{\varepsilon}_{-+}(r) + \hat{\gamma}_{\alpha\overline{\alpha}} \delta (L - r)
\end{eqnarray}
also hold for $Y_{\alpha_1\alpha_2}$.\\

We write the hermitian adjoints of Eqs.~\ref{FP1}, \ref{FP2}, \ref{FP3} for the right eigenvectors
\begin{eqnarray}
\label{FPr1}
\psi Q_{\alpha\alpha}(r) = -2 \partial_r V(r) \partial_r Q_{\alpha\alpha}(r) + \tau^{-1} (Q_{\alpha\overline{\alpha}}(r) + Q_{\overline{\alpha}\alpha}(r) - 2 Q_{\alpha\alpha}(r))\\
\label{FPr2}
\psi Q_{\alpha\overline{\alpha}}(r) = - \alpha 2 v_0 \partial_r Q_{\alpha\overline{\alpha}}(r) - 2 \partial_r V(r) \partial_r Q_{\alpha\overline{\alpha}}(r) + \tau^{-1} (2 Q_{\alpha\alpha}(r) - 2 Q_{\alpha\overline{\alpha}}(r)) - \alpha 2 s v_0 \partial_r V(r) Q_{\alpha\overline{\alpha}}(r)
\end{eqnarray}
following the symmetries we have introduced.\\

We notice that the bulk equations for Eqs.~\ref{FPr1}, \ref{FPr2} are the bulk equations \eqref{bulk:biased1}, \eqref{bulk:biased2}, \eqref{bulk:biased3} under the transformation $\alpha \to \overline{\alpha}$ so we get on $]0;L[$
\begin{eqnarray}
\label{qaa}
Q_{\alpha\alpha}(r) = A^{\prime} (\tau \psi + 2)^{-1} (e^{-k r} + e^{-k (L - r)})\\
\label{qaoa}
2 Q_{\alpha\overline{\alpha}}(r) = \left(1 + \frac{\alpha 2 k l}{\tau \psi + 2}\right) A^{\prime} e^{- k r} + \left(1 - \frac{\alpha 2 k l}{\tau \psi + 2}\right) A^{\prime} e^{- k (L - r)}
\end{eqnarray}
where $k$ is defined by Eq.~\ref{kPsi} and $A^{\prime}$ is a new constant.

\subsubsection{Complete determination method}

We write for $Y_{\alpha_1\alpha_2}$ the equations
\begin{eqnarray}
\label{FPrY1}
\begin{aligned}
\psi Y_{\alpha\overline{\alpha}}(r) \frac{P_{\alpha\alpha}(r)}{P_{\alpha\overline{\alpha}}(r)} = &\left[- \alpha 2 v_0 \partial_r Q_{\alpha\overline{\alpha}}(r) - 2 \partial_r V(r) \partial_r Q_{\alpha\overline{\alpha}}(r)\right] P_{\alpha\alpha}(r)\\
&+ \tau^{-1} \left(2 Y_{\alpha\alpha}(r) - 2 Y_{\alpha\overline{\alpha}}(r) \frac{P_{\alpha\alpha}(r)}{P_{\alpha\overline{\alpha}}(r)}\right) - \alpha 2 s v_0 \partial_r V(r) Y_{\alpha\overline{\alpha}}(r) \frac{P_{\alpha\alpha}(r)}{P_{\alpha\overline{\alpha}}(r)}
\end{aligned}\\
% \label{FPrY1}
% \psi Y_{\alpha\alpha}(r) = - 2 \partial_r V(r) P_{\alpha\alpha}(r) \partial_r Q_{\alpha\alpha}(r) + \tau^{-1} \left(Y_{\alpha\overline{\alpha}}(r) \frac{P_{\alpha\alpha(r)}}{P_{\alpha\overline{\alpha}}(r)} + Y_{\overline{\alpha}\alpha}(r) \frac{P_{\alpha\alpha(r)}}{P_{\overline{\alpha}\alpha}(r)} - 2 Y_{\alpha\alpha}(r)\right)\\
% \label{FPrY2}
% \psi Y_{\alpha\alpha}(r) = 2 Q_{\alpha\alpha}(r) \partial_r (P_{\alpha\alpha}(r) \partial_r V(r)) + \tau^{-1} \left(Y_{\alpha\alpha}(r) \frac{P_{\alpha\overline{\alpha}}(r)}{P_{\alpha\alpha}(r)} + Y_{\alpha\alpha}(r) \frac{P_{\overline{\alpha}\alpha}(r)}{P_{\alpha\alpha}(r)} - 2 Y_{\alpha\alpha}(r)\right)\\
\label{FPrY3}
\begin{aligned}
\psi Y_{\alpha\overline{\alpha}}(r) = &- \alpha 2 v_0 P_{\alpha\overline{\alpha}}(r) \partial_r Q_{\alpha\overline{\alpha}}(r) - 2 \partial_r V(r) P_{\alpha\overline{\alpha}}(r) \partial_r Q_{\alpha\overline{\alpha}}(r) + \tau^{-1} \left(2 Y_{\alpha\alpha}(r) \frac{P_{\alpha\overline{\alpha}}(r)}{P_{\alpha\alpha}(r)} - 2 Y_{\alpha\overline{\alpha}}(r)\right)\\
&- \alpha 2 s v_0 \partial_r V(r) Y_{\alpha\overline{\alpha}}(r)
\end{aligned}\\
\label{FPrY4}
\begin{aligned}
\psi Y_{\alpha\overline{\alpha}}(r) = &\alpha 2 v_0 Q_{\alpha\overline{\alpha}}(r) \partial_r P_{\alpha\overline{\alpha}}(r) + 2 Q_{\alpha\overline{\alpha}}(r) \partial_r (Q_{\alpha\overline{\alpha}}(r) \partial_r V(r)) + \tau^{-1} \left(2 Y_{\alpha\overline{\alpha}}(r) \frac{P_{\alpha\alpha}(r)}{P_{\alpha\overline{\alpha}}(r)} - 2 Y_{\alpha\overline{\alpha}}(r)\right)\\
&- \alpha 2 s v_0 \partial_r V(r) Y_{\alpha\overline{\alpha}}(r)
\end{aligned}
\end{eqnarray}
where \eqref{FPrY1} is derived from the multiplication of \eqref{FPr2} by $P_{\alpha\alpha}(r)$,
% where \eqref{FPrY1} is derived from the multiplication of \eqref{FPr1} by $P_{\alpha\alpha}(r)$, \eqref{FPrY2} is derived from the multiplication of \eqref{FP1} by $Q_{\alpha\alpha}(r)$,
\eqref{FPrY3} is derived from the multiplication of \eqref{FPr2} by $P_{\alpha\overline{\alpha}}(r)$, \eqref{FPrY4} is derived from the multiplication of (\ref{FP2}, \ref{FP3}) by $Q_{\alpha\overline{\alpha}}(r)$
, and finally substract
%
% We substract Eqs.~\ref{FPrY1},~\ref{FPrY2}
% \begin{equation}
% 0 = - 2 \partial_r (\partial_r V(r) Y_{\alpha\alpha}(r)) + \tau^{-1} \left(Y_{\alpha\overline{\alpha}}(r) \frac{P_{\alpha\alpha(r)}}{P_{\alpha\overline{\alpha}}(r)} + Y_{\overline{\alpha}\alpha}(r) \frac{P_{\alpha\alpha(r)}}{P_{\overline{\alpha}\alpha}(r)} - Y_{\alpha\alpha}(r) \frac{P_{\alpha\overline{\alpha}}(r)}{P_{\alpha\alpha}(r)} - Y_{\alpha\alpha}(r) \frac{P_{\overline{\alpha}\alpha}(r)}{P_{\alpha\alpha}(r)}\right)
% \end{equation}
% and also
Eqs.~\ref{FPrY3},~\ref{FPrY4}
\begin{equation}
0 = - \alpha 2 v_0 \partial_r Y_{\alpha\overline{\alpha}}(r) - 2 \partial_r (Y_{\alpha\overline{\alpha}}(r) \partial_r V(r)) + \tau^{-1} \left(2 Y_{\alpha\alpha}(r) \frac{P_{\alpha\overline{\alpha}}(r)}{P_{\alpha\alpha}(r)} - 2 Y_{\alpha\overline{\alpha}}(r) \frac{P_{\alpha\alpha}(r)}{P_{\alpha\overline{\alpha}}(r)}\right)
\end{equation}
to get equations where derivatives should have nice integrals.\\

We integrate Eqs.~\ref{FPrY1},~\ref{FPrY4} between $0^-$ and $0^+$
\begin{eqnarray}
\label{BCr1}
\psi \hat{\gamma}_{\alpha\overline{\alpha}} \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}} = \tau^{-1} \left(2 \hat{\gamma}_{\alpha\alpha} - 2 \hat{\gamma}_{\alpha\overline{\alpha}} \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}}\right) + 2 s v_0^2 \hat{\gamma}_{\alpha\overline{\alpha}} \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}}\\
\label{BCr2}
0 = - v_0 \hat{\varepsilon}_{+-}(0^+) + \tau^{-1} \left(\hat{\gamma}_{\alpha\alpha} \frac{\gamma_{\alpha\overline{\alpha}}}{\gamma_{\alpha\alpha}} - \hat{\gamma}_{\alpha\overline{\alpha}} \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}}\right)
\end{eqnarray}
where we have discarded in \eqref{BCr1} the integral of the first term of the right hand side of \eqref{FPrY1} since $\partial_r V(0) = -v_0$, and with
\begin{eqnarray}
\label{he+-}
\begin{aligned}
\hat{\varepsilon}_{+-}(r) &= Q_{+-}(r) P_{+-}(r) \qquad (r \in ]0; L[)\\
&= \frac{A A^{\prime}}{4} \left[1 - \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right](e^{-2 k r} + e^{-2 k (L - r)})\\
&\quad+ \frac{A A^{\prime}}{4} \left[\left(1 + \frac{2 k l}{\tau \psi + 2}\right)^2 + \left(1 - \frac{2 k l}{\tau \psi + 2}\right)^2\right] e^{-k L}\\
&= \frac{A A^{\prime}}{4} \left[1 - \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right](e^{-2 k r} + e^{-2 k (L - r)}) + \frac{A A^{\prime}}{2} \left[1 + \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right] e^{-k L}
\end{aligned}\\
\end{eqnarray}
where we will introduce
\begin{equation}
\Omega = \frac{2 k l}{\tau \psi + 2}
\label{Omega}
\end{equation}
to get
\begin{eqnarray}
\label{he+-lim}
\begin{aligned}
\hat{\varepsilon}_{+-}(0^+) = \lim_{r \to 0^+} \hat{\varepsilon}_{+-}(r) &= \frac{A A^{\prime}}{4} \left[1 - \Omega^2\right](1 + e^{-2 k L}) + \frac{A A^{\prime}}{2} \left[1 + \Omega^2\right] e^{-k L}\\
&= A A^{\prime} e^{-k L} \left[\left(\frac{e^{kL} + e^{-k L}}{2}\right)^2 - \Omega^2 \left(\frac{e^{kL} - e^{-k L}}{2}\right)^2\right]
% &= \frac{A A^{\prime}}{2} e^{-k L}\left[\left(1 - \left(\frac{2 k l}{\tau\psi + 2}\right)^2\right) \cosh(k L) + \left(1 + \left(\frac{2 k l}{\tau\psi + 2}\right)^2\right)\right]
\end{aligned}
\end{eqnarray}
from Eqs.~\ref{epsilon},~\ref{qaoa}, with $A = A_{\pm}$ which appear in Eqs.~\ref{epsilon}, \ref{theta}, \ref{beta}. We solve Eqs.~\ref{BCr1},~\ref{BCr2} for $\hat{\gamma}_{\alpha\alpha}$ and $\hat{\gamma}_{\alpha\overline{\alpha}}$
\begin{eqnarray}
\label{hgaa}
\hat{\gamma}_{\alpha\alpha} = \frac{[(\tau\psi + 2) - 2 s l v_0] l \hat{\varepsilon}_{+-}(0^+)}{(\tau \psi + 2) [(\tau\psi + 2) - 2 s l v_0] - 2}\\
% \hat{\gamma}_{\alpha\alpha} = \frac{\left[\frac{1}{2} (\tau \psi + 2) - s l v_0\right] \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}} l \hat{\varepsilon}_{+-}(0^+)}{\frac{1}{2}(\tau\psi + 2) - s l v_0 - \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}}}\\
\label{hgaoa}
\hat{\gamma}_{\alpha\overline{\alpha}} = \frac{2 (\tau\psi + 2) l \hat{\varepsilon}_{+-}(0^+)}{(\tau \psi + 2) [(\tau\psi + 2) - 2 s l v_0] - 2}
% \hat{\gamma}_{\alpha\overline{\alpha}} = \frac{l \hat{\varepsilon}_{+-}(0^+)}{\frac{1}{2}(\tau\psi + 2) - s l v_0 - \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}}}
\end{eqnarray}
as a function of $\hat{\varepsilon}_{+-}(0^+)$ and where we have used $\gamma_{\alpha\alpha}/\gamma_{\alpha\overline{\alpha}} = (\tau \psi + 2)^{-1}$ \eqref{ratio_gamma}.\\

We can finally write the normalisation condition \eqref{normalisation_pave}
\begin{equation}
\begin{aligned}
1 &= 4 \hat{\gamma}_{\alpha\alpha} + 2 \hat{\gamma}_{\alpha\overline{\alpha}} + 2 \int_0^L \hat{\varepsilon}_{\alpha\alpha}(r) \, \mathrm{d}r + 2 \int_0^L \hat{\varepsilon}_{\alpha\overline{\alpha}}(r) \, \mathrm{d}r\\
&= 4 \hat{\gamma}_{\alpha\alpha} \left(1 + \frac{1}{2} \frac{\hat{\gamma}_{\alpha\overline{\alpha}}}{\hat{\gamma}_{\alpha\alpha}}\right) + 2 \int_0^L \hat{\varepsilon}_{\alpha\alpha}(r) \, \mathrm{d}r + 2 \int_0^L \hat{\varepsilon}_{\alpha\overline{\alpha}}(r) \, \mathrm{d}r
\label{normalisation_pave_full}
\end{aligned}
\end{equation}
where we have
\begin{equation}
\hat{\varepsilon}_{\alpha\alpha}(r) = P_{\alpha\alpha}(r \in ]0; L[) Q_{\alpha\alpha}(r \in ]0; L[) = \frac{A A^{\prime}}{(\tau \psi + 2)^2} \left(e^{-2 k r} + e^{-2 k (L - r)} + 2 e^{-k L}\right)
\label{heaa}
\end{equation}
according to Eqs.~\ref{beta},~\ref{qaa}. We compute from \eqref{heaa}
\begin{equation}
\int_0^L \hat{\varepsilon}_{\alpha\alpha}(r) \, \mathrm{d}r = A A^{\prime} e^{-k L} \frac{2}{(\tau \psi + 2)^2} \left[\frac{1}{k} \left(\frac{e^{k L} - e^{-k L}}{2}\right) + L\right]
\label{int_heaa}
\end{equation}
and from \eqref{he+-}
\begin{equation}
\int_0^L \hat{\varepsilon}_{\alpha\overline{\alpha}}(r) \, \mathrm{d}r = A A^{\prime} e^{-k L} \frac{1}{2} \left[\left(1 -\Omega^2\right) \frac{1}{k} \left(\frac{e^{k L} - e^{-k L}}{2}\right) + \left(1 + \Omega^2\right) L\right]
\end{equation}
on the one hand, and use on the other hand \eqref{he+-lim} to re-write \eqref{normalisation_pave_full}
\begin{equation}
\begin{aligned}
\tilde{\mathcal{N}} =~& (A A^{\prime} e^{-k L} l)^{-1}\\
=~& \frac{4 [(\tilde{\psi} + 2) - 2 \tilde{s}]}{(\tilde{\psi} + 2)[(\tilde{\psi} + 2) - 2 \tilde{s}] - 2} \left[1 + \frac{\tilde{\psi} + 2}{(\tilde{\psi} + 2) - 2 \tilde{s}}\right] \left[\left(\frac{e^{\tilde{k} \tilde{L}} + e^{-\tilde{k} \tilde{L}}}{2}\right)^2 - \Omega^2 \left(\frac{e^{\tilde{k} \tilde{L}} - e^{-\tilde{k} \tilde{L}}}{2}\right)^2\right]\\
&+ \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 - \Omega^2)\right] \frac{1}{\tilde{k}} \left(\frac{e^{\tilde{k} \tilde{L}} - e^{-\tilde{k} \tilde{L}}}{2}\right) + \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 + \Omega^2)\right] \tilde{L}
\end{aligned}
\label{normalisation_factor_pave}
\end{equation}
% \begin{equation}
% \begin{aligned}
% 1 = &\left[4 \frac{\left(\frac{1}{2}(\tau \psi + 2) - s l v_0\right) \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}} l}{\frac{1}{2}(\tau \psi + 2) - s l v_0 - \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}}} + 2 \frac{l}{\frac{1}{2}(\tau \psi + 2) - s l v_0 - \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}}}\right]\\
% &\qquad \times \frac{A A^{\prime}}{2} e^{-k L} \left[\left(1 - \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right) \cosh(k L) + \left(1 + \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right)\right]\\
% &+ \frac{4 A A^{\prime}}{(\tau \psi + 2)^2} e^{-k L} \left[\frac{1}{k}\sinh(kL) + L\right]\\
% &+ A A^{\prime} e^{-k L} \left[\left(1 - \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right) \frac{1}{k} \sinh(k L) + \left(1 + \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right) L\right]\\
% = & A A^{\prime} e^{-k L}\\
% &\times\Bigg[\frac{l}{\frac{1}{2}(\tau \psi + 2) - s l v_0 - \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}}} \left(2 \left(\frac{1}{2} (\tau \psi + 2) - s l v_0\right) \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}} + 1\right)\\
% &\qquad\qquad \times \left(\left(1 - \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right) \cosh(k L) + \left(1 + \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right)\right)\\
% &\qquad + \frac{4}{(\tau \psi + 2)^2} \left(\frac{1}{k}\sinh(kL) + L\right) + \left(1 - \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right) \frac{1}{k} \sinh(k L) + \left(1 + \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right) L\Bigg]
% \end{aligned}
% \end{equation}
% and conclude
% \begin{equation}
% \begin{aligned}
% A^{\prime} =& \frac{e^{k L}}{A}\\
% &\times\Bigg[\frac{l}{\frac{1}{2}(\tau \psi + 2)^2 - s l v_0 (\tau \psi + 2) - 1} \left(2 (\tau \psi + 2) - 2 s l v_0\right)\\
% &\qquad\qquad \times \left(\left(1 - \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right) \cosh(k L) + \left(1 + \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right)\right)\\
% &\qquad + \frac{4}{(\tau \psi + 2)^2} \left(\frac{1}{k}\sinh(kL) + L\right) + \left(1 - \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right) \frac{1}{k} \sinh(k L) + \left(1 + \left(\frac{2 k l}{\tau \psi + 2}\right)^2\right) L\Bigg]^{-1}
% \end{aligned}
% \end{equation}
where we have denoted the dimensionless quantities $\tilde{\psi} = \tau \psi$, $\tilde{k} = k l$, $\tilde{L} = L/l$, $\tilde{s} = s l v_0$, $\tilde{\mathcal{N}} = \mathcal{N}/l$.
% We can easily check that $\lim_{s \to 0} \tilde{\mathcal{N}^{-1}} = 8 + 4 \tilde{L}$, and
% \begin{eqnarray}
% \label{normalisation_factor_pave_sneg}
% \begin{aligned}
% \tilde{\mathcal{N}}^{-1}(s < 0) =~& \frac{4 [(\tilde{\psi} + 2) - 2 \tilde{s}]}{(\tilde{\psi} + 2)[(\tilde{\psi} + 2) - 2 \tilde{s}] - 2} \left[1 + \frac{\tilde{\psi} + 2}{(\tilde{\psi} + 2) - 2 \tilde{s}}\right]\left(\cos(|\tilde{k}| \tilde{L})^2 - |\Omega|^2 \sin(|\tilde{k}| \tilde{L})^2\right)\\
% &+ \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 + |\Omega|^2)\right] \frac{1}{|\tilde{k}|} \sin(|\tilde{k}| \tilde{L}) + \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 - |\Omega|^2)\right] \tilde{L}
% \end{aligned}\\
% \label{normalisation_factor_pave_spos}
% \begin{aligned}
% \tilde{\mathcal{N}}^{-1}(s > 0) =~& \frac{4 [(\tilde{\psi} + 2) - 2 \tilde{s}]}{(\tilde{\psi} + 2)[(\tilde{\psi} + 2) - 2 \tilde{s}] - 2} \left[1 + \frac{\tilde{\psi} + 2}{(\tilde{\psi} + 2) - 2 \tilde{s}}\right]\left(\cosh(\tilde{k} \tilde{L})^2 - \Omega^2 \sinh(\tilde{k} \tilde{L})^2\right)\\
% &+ \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 - \Omega^2)\right] \frac{1}{\tilde{k}} \sinh(\tilde{k} \tilde{L}) + \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 + \Omega^2)\right] \tilde{L}
% \end{aligned}
% \end{eqnarray}
% depending on the sign of $s$.\\
%
% We define the polarisation
% \begin{equation}
% \nu = 4 \hat{\gamma}_{\alpha\alpha} + 2 \int_0^L \hat{\varepsilon}_{\alpha\alpha}(r) \, \mathrm{d}r
% \label{polarisation_def}
% \end{equation}
% which we can compute with (\ref{hgaa}, \ref{int_heaa}, \ref{normalisation_factor_pave})
% \begin{equation}
% \begin{aligned}
% \nu =~& \tilde{\mathcal{N}} \frac{4 [(\tilde{\psi} + 2) - 2 \tilde{s}]}{(\tilde{\psi} + 2) [(\tilde{\psi} + 2) - 2 \tilde{s}] - 2} \left[\left(\frac{e^{\tilde{k} \tilde{L}} + e^{-\tilde{k} \tilde{L}}}{2}\right)^2 - \Omega^2 \left(\frac{e^{\tilde{k} \tilde{L}} - e^{-\tilde{k} \tilde{L}}}{2}\right)^2\right]\\
% &+ \tilde{\mathcal{N}} \frac{4}{(\tilde{\psi} + 2)^2} \left[\frac{1}{\tilde{k}} \left(\frac{e^{\tilde{k} \tilde{L}} - e^{-\tilde{k} \tilde{L}}}{2}\right) + \tilde{L}\right]
% \end{aligned}
% \label{polarisation_value}
% \end{equation}
% where we can check that $\lim_{s \to 0} \nu = 1/2$ and write depending on the sign of $s$
% \begin{eqnarray}
% \label{polarisation_sneg}
% \nu(s < 0) = \tilde{\mathcal{N}} \frac{4 [(\tilde{\psi} + 2) - 2 \tilde{s}]}{(\tilde{\psi} + 2) [(\tilde{\psi} + 2) - 2 \tilde{s}] - 2} \left(\cos(|\tilde{k}| \tilde{L})^2 - |\Omega|^2 \sin(|\tilde{k}| \tilde{L})^2\right) + \tilde{\mathcal{N}} \frac{4}{(\tilde{\psi} + 2)^2} \left[\frac{1}{|\tilde{k}|} \sin(|\tilde{k}| \tilde{L}) + \tilde{L}\right]\\
% \label{polarisation_spos}
% \nu(s > 0) = \tilde{\mathcal{N}} \frac{4 [(\tilde{\psi} + 2) - 2 \tilde{s}]}{(\tilde{\psi} + 2) [(\tilde{\psi} + 2) - 2 \tilde{s}] - 2} \left(\cosh(\tilde{k} \tilde{L})^2 - |\Omega|^2 \sinh(\tilde{k} \tilde{L})^2\right) + \tilde{\mathcal{N}} \frac{4}{(\tilde{\psi} + 2)^2} \left[\frac{1}{\tilde{k}} \sinh(\tilde{k} \tilde{L}) + \tilde{L}\right]
% \end{eqnarray}
% with (\ref{normalisation_factor_pave_sneg}, \ref{normalisation_factor_pave_spos}).

\subsubsection{Polarisation-oriented method}

We have that the form of Eqs.~\ref{FPr1}, \ref{FPr2} indicates that there cannot be $\delta$-function terms in the right eigenvectors $Q_{\alpha_1\alpha_2}$, therefore these are completely described by Eqs.~\ref{qaa}, \ref{qaoa}. We can thus write
\begin{eqnarray}
\hat{\varepsilon}_{\alpha\alpha}(r) = \frac{A^{\prime}}{A} \varepsilon_{\alpha\alpha}(r)^2\\
\hat{\varepsilon}_{\alpha\overline{\alpha}}(r) = \frac{A^{\prime}}{A} \varepsilon_{\alpha\overline{\alpha}}(r) \varepsilon_{\overline{\alpha}\alpha}(r)\\
\hat{\gamma}_{\alpha\alpha} = \gamma_{\alpha\alpha} \frac{A^{\prime}}{A} \varepsilon_{\alpha\alpha}(0^+)\\
\hat{\gamma}_{\alpha\overline{\alpha}} = \gamma_{\alpha\overline{\alpha}} \frac{A^{\prime}}{A} \varepsilon_{+-}(L^-)
\end{eqnarray}
with the notations of Eqs.~\ref{gfY1}, \ref{gfY2}, \ref{gfY3}.\\

We want to compute the average polarisation
\begin{equation}
\nu = 4 \hat{\gamma}_{\alpha\alpha} + 2 \int_0^L \hat{\varepsilon}_{\alpha\alpha}(r) \, \mathrm{d}r
\label{nu_pave}
\end{equation}
corresponding to the propensity of particles to be aligned, and use the normalisation condition \eqref{normalisation_pave_full} to re-write it
\begin{equation}
\begin{aligned}
\nu &= \frac{4 \hat{\gamma}_{\alpha\alpha} + 2 \int_0^L \hat{\varepsilon}_{\alpha\alpha}(r) \, \mathrm{d}r}{4 \hat{\gamma}_{\alpha\alpha} + 2 \hat{\gamma}_{\alpha\overline{\alpha}} + 2 \int_0^L \hat{\varepsilon}_{\alpha\alpha}(r) \, \mathrm{d}r + 2 \int_0^L \hat{\varepsilon}_{\alpha\overline{\alpha}}(r) \, \mathrm{d}r}\\
&= \frac{4 e^{k L} \frac{\gamma_{\alpha\alpha}}{A} \frac{\varepsilon_{\alpha\alpha}(0^+)}{A} + 2 e^{k L} \int_0^L \frac{\varepsilon_{\alpha\alpha}(r)^2}{A^2} \, \mathrm{d}r}{4 e^{k L} \frac{\gamma_{\alpha\alpha}}{A} \frac{\varepsilon_{\alpha\alpha}(0^+)}{A} + 2 e^{k L} \frac{\gamma_{\alpha\alpha}}{A} (\tau \psi + 2) \frac{\varepsilon_{+-}(L^-)}{A} + 2 e^{k L} \int_0^L \frac{\varepsilon_{\alpha\alpha}(r)^2}{A^2} \, \mathrm{d}r + 2 e^{k L} \int_0^L \frac{\varepsilon_{\alpha\overline{\alpha}}(r)\varepsilon_{\overline{\alpha}\alpha}(r)}{A^2} \, \mathrm{d}r}
\end{aligned}
\label{nu_pave_full}
\end{equation}
where we have used $\gamma_{\alpha\overline{\alpha}} = (\tau \psi + 2) \gamma_{\alpha\alpha}$ \eqref{ratio_gamma} from the first to the second line.\\

We can compute from Eqs.~\ref{epsilon}, \ref{LBe2}
\begin{equation}
\frac{\gamma_{\alpha\alpha}}{A} = l \frac{\varepsilon_{+-}(L^-)}{A} = \frac{l}{2} \left[(1 + e^{-k L}) + \Omega (1 - e^{-k L})\right]
\end{equation}
from Eqs.~\ref{epsilon}, \ref{theta}
\begin{eqnarray}
\frac{\varepsilon_{\alpha\alpha}(0^+)}{A} = \frac{1}{\tau\psi + 2}(1 + e^{-k L})\\
\begin{aligned}
\frac{\varepsilon_{+-}(L^-)}{A} &= \frac{1}{2} \left[(1 + e^{-k L}) + \Omega (1 - e^{-k L})\right]
\end{aligned}
\end{eqnarray}
and from Eqs.~\ref{heaa}, \ref{he+-}
\begin{eqnarray}
\int_0^L \frac{\varepsilon_{\alpha\alpha}(r)^2}{A^2} \, \mathrm{d}r = e^{-k L} \frac{2}{(\tau \psi + 2)^2} \left[\frac{1}{k} \left(\frac{e^{k L} - e^{- k L}}{2}\right) + L\right]\\
\int_0^L \frac{\varepsilon_{\alpha\overline{\alpha}}(r)\varepsilon_{\overline{\alpha}\alpha}(r)}{A^2} \, \mathrm{d}r = e^{-k L} \frac{1}{2} \left[(1 - \Omega^2) \frac{1}{k} \left(\frac{e^{k L} - e^{-k L}}{2}\right) + (1 + \Omega^2) L\right]
\end{eqnarray}
so that we can write
\begin{eqnarray}
\label{gaa-full}
e^{k L} \frac{\gamma_{\alpha\alpha}}{A} \frac{\varepsilon_{\alpha\alpha}(0^+)}{A} = \frac{1}{4} \left[2 \frac{\Omega}{k} \left(1 + \left(\frac{e^{k L} + e^{-k L}}{2}\right)\right) + 2 \frac{\Omega^2}{k} \left(\frac{e^{k L} - e^{-k L}}{2}\right)\right]\\
\label{gaba-full}
\begin{aligned}
e^{k L} \frac{\gamma_{\alpha\alpha}}{A} (\tau \psi + 2) \frac{\varepsilon_{+-}(L^-)}{A} = \frac{1}{2} \Bigg[l(\tau \psi + 2)(1 - \Omega^2) + l(\tau\psi + 2)(1 + \Omega^2)\left(\frac{e^{k L} + e^{-k L}}{2}\right)\\
+ (\tau \psi + 2)^2 \frac{\Omega^2}{k} \left(\frac{e^{k L} - e^{-k L}}{2}\right)\Bigg]
\end{aligned}\\
e^{k L} \int_0^L \frac{\varepsilon_{\alpha\alpha}(r)^2}{A^2} \, \mathrm{d}r = \frac{1}{2} \left[\frac{4}{(\tau\psi + 2)^2} \left(\frac{1}{k}\left(\frac{e^{k L} - e^{- k L}}{2}\right) + L\right)\right]\\
e^{k L} \int_0^L \frac{\varepsilon_{\alpha\overline{\alpha}}(r)\varepsilon_{\overline{\alpha}\alpha}(r)}{A^2} \, \mathrm{d}r = \frac{1}{2} \left[(1 - \Omega^2) \frac{1}{k}\left(\frac{e^{k L} - e^{-k L}}{2}\right) + (1 + \Omega^2) L\right]
\end{eqnarray}
where we have used the quantity $\Omega$ \eqref{Omega}.\\

We can first check
\begin{eqnarray}
\lim_{s \to 0} 4 e^{k L} \frac{\gamma_{\alpha\alpha}}{A} \frac{\varepsilon_{\alpha\alpha}(0^+)}{A} = 4 l\\
\lim_{s \to 0} 2 e^{k L} \frac{\gamma_{\alpha\alpha}}{A} (\tau \psi + 2) \frac{\varepsilon_{+-}(L^-)}{A} = 4 l\\
\lim_{s \to 0} 2 e^{k L} \int_0^L \frac{\varepsilon_{\alpha\alpha}(r)^2}{A^2} \, \mathrm{d}r = 2 L\\
\lim_{s \to 0} 2 e^{k L} \int_0^L \frac{\varepsilon_{\alpha\overline{\alpha}}(r)\varepsilon_{\overline{\alpha}\alpha}(r)}{A^2} \, \mathrm{d}r = 2 L
\end{eqnarray}
so that, replacing in \eqref{nu_pave_full}, we get $\lim_{s \to 0} \nu = 1/2$ as expected.\\

We finally give the full expressions for $s < 0$
\begin{equation}
\nu(s < 0) = \frac{
\begin{aligned}
2 \frac{|\Omega|}{|\tilde{k}|} \left(1 + \cos(|\tilde{k}| \tilde{L})\right) - 2 \frac{|\Omega|^2}{|\tilde{k}|} \sin(|\tilde{k}| \tilde{L}) + \frac{4}{(\tilde{\psi} + 2)^2} \left(\frac{1}{|\tilde{k}|} \sin(|\tilde{k}| \tilde{L}) + \tilde{L}\right)
\end{aligned}
}{
\begin{aligned}
2 \frac{|\Omega|}{|\tilde{k}|} \left(1 + \cos(|\tilde{k}| \tilde{L})\right) - (2 + (\tilde{\psi} + 2)^2) \frac{|\Omega|^2}{|\tilde{k}|} \sin(|\tilde{k}| \tilde{L}) + (\tilde{\psi} + 2)(1 + |\Omega|^2) + (\tilde{\psi} + 2)(1 - |\Omega|^2) \cos(|\tilde{k}| \tilde{L})\\
+ \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 + |\Omega|^2)\right] \frac{1}{|\tilde{k}|} \sin(|\tilde{k}|\tilde{L}) + \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 - |\Omega|^2)\right] \tilde{L}
\end{aligned}
}
\end{equation}
and for $s > 0$
\begin{equation}
\nu(s > 0) = \frac{
\begin{aligned}
2 \frac{\Omega}{\tilde{k}} \left(1 + \cosh(\tilde{k} \tilde{L})\right) + 2 \frac{\Omega^2}{\tilde{k}} \sinh(\tilde{k} \tilde{L}) + \frac{4}{(\tilde{\psi} + 2)^2} \left(\frac{1}{\tilde{k}} \sinh(\tilde{k} \tilde{L}) + \tilde{L}\right)
\end{aligned}
}{
\begin{aligned}
2 \frac{\Omega}{\tilde{k}} \left(1 + \cosh(\tilde{k} \tilde{L})\right) + (2 + (\tilde{\psi} + 2)^2) \frac{\Omega^2}{\tilde{k}} \sinh(\tilde{k} \tilde{L}) + (\tilde{\psi} + 2)(1 - \Omega^2) + (\tilde{\psi} + 2)(1 + \Omega^2) \cosh(\tilde{k} \tilde{L})\\
+ \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 - \Omega^2)\right] \frac{1}{\tilde{k}} \sinh(\tilde{k}\tilde{L}) + \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 + \Omega^2)\right] \tilde{L}
\end{aligned}
}
\end{equation}
where we have introduced the dimensionless quantities $\tilde{\psi} = \tau \psi$, $\tilde{k} = k l$ and $\tilde{L} = L/l$.

\subsubsection{Full expressions}

We summarise here our expressions for the full-time distributions.

We have the normalisation factor (Eq.~\ref{normalisation_factor_pave})
\begin{equation}
\begin{aligned}
\tilde{\mathcal{N}} =~&\left(A A^{\prime} e^{-\tilde{k}\tilde{L}} l\right)^{-1}\\
=~&2 \frac{\Omega}{\tilde{k}} \left(1 + \left(\frac{e^{\tilde{k} \tilde{L}} + e^{-\tilde{k} \tilde{L}}}{2}\right)\right) + (2 + (\tilde{\psi} + 2)^2) \frac{\Omega^2}{\tilde{k}} \left(\frac{e^{\tilde{k} \tilde{L}} - e^{-\tilde{k} \tilde{L}}}{2}\right)\\
&+ (\tilde{\psi} + 2)(1 - \Omega^2) + (\tilde{\psi} + 2)(1 + \Omega^2) \left(\frac{e^{\tilde{k} \tilde{L}} + e^{-\tilde{k} \tilde{L}}}{2}\right)\\
&+ \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 - \Omega^2)\right] \frac{1}{\tilde{k}} \left(\frac{e^{\tilde{k} \tilde{L}} - e^{-\tilde{k} \tilde{L}}}{2}\right) + \left[\frac{4}{(\tilde{\psi} + 2)^2} + (1 + \Omega^2)\right] \tilde{L}
\end{aligned}
\end{equation}
and write from Eqs.~\ref{Omega}, \ref{he+-}, \ref{heaa}, the regular part of the full-time distribution functions
\begin{align}
\tilde{\mathcal{N}} l \hat{\varepsilon}_{\alpha\alpha}(r) &= \frac{4}{(\tilde{\psi} + 2)^2} \left(\frac{e^{\tilde{k} \tilde{L} \left(1/2 - \tilde{r}/\tilde{L}\right)} + e^{-\tilde{k} \tilde{L} \left(1/2 - \tilde{r}/\tilde{L}\right)}}{2}\right)^2\\
\tilde{\mathcal{N}} l \hat{\varepsilon}_{\alpha\overline{\alpha}}(r) &= \frac{1}{2}\left(1 - \Omega^2\right) \left(\frac{e^{2 \tilde{k}\tilde{L}\left(1/2 - \tilde{r}/\tilde{L}\right)} + e^{-2 \tilde{k}\tilde{L}\left(1/2 - \tilde{r}/\tilde{L}\right)}}{2}\right) + \frac{1}{2}\left(1 + \Omega^2\right)
\end{align}
where $\tilde{r} = r/l$, such that we can check $\tilde{\mathcal{N}} \hat{\varepsilon}_{\alpha\alpha}(r) = \tilde{\mathcal{N}} \hat{\varepsilon}_{\alpha\overline{\alpha}}(r) = 1$ for $s = 0$, and from Eqs.~\ref{gaa-full}, \ref{gaba-full} the sticking terms
\begin{eqnarray}
\tilde{\mathcal{N}} \hat{\gamma}_{\alpha\alpha} = \frac{1}{2} \left[\frac{\Omega}{\tilde{k}} \left(1 + \left(\frac{e^{\tilde{k} \tilde{L}} + e^{-\tilde{k} \tilde{L}}}{2}\right)\right) + \frac{\Omega^2}{\tilde{k}} \left(\frac{e^{\tilde{k} \tilde{L}} - e^{-\tilde{k} \tilde{L}}}{2}\right)\right]\\
\begin{aligned}
\tilde{\mathcal{N}} \hat{\gamma}_{\alpha\overline{\alpha}} =~& \frac{1}{2} \Bigg[(\tilde{\psi} + 2)(1 - \Omega^2) + (\tilde{\psi} + 2)(1 + \Omega^2)\left(\frac{e^{\tilde{k} \tilde{L}} + e^{-\tilde{k} \tilde{L}}}{2}\right)\\
&+ (\tilde{\psi} + 2)^2 \frac{\Omega^2}{\tilde{k}} \left(\frac{e^{\tilde{k} \tilde{L}} - e^{-\tilde{k} \tilde{L}}}{2}\right)\Bigg]
\end{aligned}
\end{eqnarray}
which we plot in Fig.~\ref{fig-full-expr}.

\subsection{Unbiased ensemble check}

We have in the unbiased ensemble $\psi(s = 0) = 0$, therefore $k = 0$ according to \eqref{kPsi}. It follows that
\begin{equation}
\hat{\varepsilon}_{\alpha\alpha}(r, s=0) = \hat{\varepsilon}_{\alpha\overline{\alpha}}(r, s=0) = A A^{\prime}
\end{equation}
from Eqs.~\ref{he+-},~\ref{heaa}. We know from Eqs.~\ref{s0++}, \ref{s0--}, \ref{s0+-}, \ref{s0-+} that
\begin{equation}
\left. \frac{\gamma_{\alpha\alpha}}{\gamma_{\alpha\overline{\alpha}}} \right|_{s=0} = \frac{1}{2}
\end{equation}
therefore we get
\begin{eqnarray}
\hat{\gamma}_{\alpha\alpha}(s=0) = l A A^{\prime}\\
\hat{\gamma}_{\alpha\overline{\alpha}}(s=0) = 2 l A A^{\prime}
\end{eqnarray}
from Eqs.~\ref{hgaa},~\ref{hgaoa}. We can then write the normalisation condition \eqref{normalisation_pave_full}
\begin{equation}
1 = 4 l A A^{\prime} + 4 l A A^{\prime} + 2 A A^{\prime} L + 2 A A^{\prime} L
\end{equation}
such that
\begin{equation}
A^{\prime} = \frac{1}{A( 8 l + 4 L)} = 1
\end{equation}
where the second equality derives from Eq.~\ref{smooth_unbiased}, and which consequence is that
\begin{equation}
Q_{\alpha\alpha}(r, s=0) = Q_{\alpha\overline{\alpha}}(r, s=0) = 1
\end{equation}
according to Eqs.~\ref{qaa},~\ref{qaoa}.

%%%%%%%%%%%%%%
% REFERENCES %
%%%%%%%%%%%%%%

\bibliographystyle{alpha}
{\renewcommand{\bibname}{References}\bibliography{references}}

\end{document}


\subsection{Random optimisation}

This is similar to random search, however we use a multivariate Gaussian distribution around our current point rather than a hypersphere.