\documentclass[11pt]{amsart}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{xcolor}

\usetikzlibrary{
  arrows,
  calc,
  decorations.markings,
  decorations.pathreplacing,
  dsp,
  fit,
  positioning
}
\input{../util/airfoils.tex}
\input{../util/wing.tex}
\input{../util/coordinate_systems.tex}
\input{../util/control.tex}

\newcommand{\aero}{\mathrm{aero}}
\newcommand{\airgrid}{\mathrm{air-grid}}
\newcommand{\app}{a}
\newcommand{\climb}{\mathrm{climb}}
\newcommand{\cmd}{\mathrm{cmd}}
\newcommand{\cutin}{\mathrm{cut-in}}
\newcommand{\cutout}{\mathrm{cut-out}}
\newcommand{\cw}{\mathrm{cw}}
\newcommand{\eff}{\mathrm{eff}}
\newcommand{\extra}{\mathrm{extra}}
\newcommand{\figureeight}{\mathrm{figure-eight}}
\newcommand{\grav}{\mathrm{grav}}
\newcommand{\groundinverter}{\mathrm{ground\;inv.}}
\newcommand{\hover}{\mathrm{hover}}
\newcommand{\kiteinverter}{\mathrm{kite\;inv.}}
\newcommand{\kite}{\mathrm{kite}}
\newcommand{\lp}{\mathrm{loop}}
\newcommand{\mx}{\mathrm{max}}
\newcommand{\mn}{\mathrm{min}}
\newcommand{\motor}{\mathrm{motor}}
\newcommand{\nominal}{\mathrm{nom}}
\newcommand{\path}{\mathrm{path}}
\newcommand{\prop}{\mathrm{prop}}
\newcommand{\shaftgrid}{\mathrm{shaft-grid}}
\newcommand{\swept}{\mathrm{swept}}
\newcommand{\tether}{\mathrm{tether}}
\newcommand{\total}{\mathrm{tot}}
\newcommand{\wind}{\mathrm{wind}}
\newcommand{\mass}{\mathrm{mass}}
\newcommand{\power}{\mathrm{power}}
\newcommand{\powertrain}{\mathrm{powertrain}}
\newcommand{\motorout}{\mathrm{motor-out}}

\definecolor{matlab1}{rgb}{0, 0.4470, 0.7410}
\definecolor{matlab2}{rgb}{0.8500, 0.3250, 0.0980}
\definecolor{matlab3}{rgb}{0.9290, 0.6940, 0.1250}
\definecolor{matlab4}{rgb}{0.4940, 0.1840, 0.5560}
\definecolor{matlab5}{rgb}{0.4660, 0.6740, 0.1880}
\definecolor{matlab6}{rgb}{0.3010, 0.7450, 0.9330}
\definecolor{matlab7}{rgb}{0.6350, 0.0780, 0.1840}

\title{Limits on kite mass}
\author{Makani Technologies LLC}
\date{October 6, 2016}

\begin{document}
\maketitle

% \section*{Nomenclature}

% \begin{tabular}{ll}
%   $m_{\kite}$       & Kite mass \\
%   $m_{\total}$      & Combined kite and tether mass \\
%   $m_{\eff}$        & Effective mass ($m_{\eff} = m_{\kite} + m_{\tether}/3)$ for modeling dynamics \\
%   $\mathit{TWR}$    & Thrust-to-weight ratio \\
%   $\eta_{\airgrid}$ & Efficiency of power conversion from the grid to aerodynamic power \\

% \end{tabular}

\section{Vertical take-off and landing}

The relationship between the required grid power for hover and mass
is:
%
\begin{equation}
  \label{eqn:hover_power}
  P_{\hover} = \frac{1}{\eta_{\shaftgrid} \cdot \mathit{FM}}
               \sqrt{\frac{(\mathit{TWR} \cdot m_{\total} g)^3}
                          {2 \rho_{\mn} f N_{\prop} A_{\prop}}}
\end{equation}
%
where $\mathit{FM}$ is the figure-of-merit of the propellers,
$\mathit{TWR}$ is the thrust-to-weight ratio, $f$ is the fraction of
motors available in a motor-out situation, and $m_{\total}$ is the
combined kite and tether mass.\footnote{The strict limits that
  vertical take-off and landing places on mass and power have
  been covered extensively in other documents
  \cite{tvanalsenoy_power_train}}

Because of the significant cost of the ground-side inverter and other
power components, which scales approximately linearly with power,
vertical take-off and landing (VTOL) systems likely do not make
economic sense unless $P_{\hover} \le P_{\mx}$.  This constraint may
be relaxed somewhat for multi-kite systems, if it is only necessary to
hover a single kite at a time.  In this case, the kite is likely
limited by the available shaft power from the motors.  In a
well-designed system, the available shaft power from the motors should
be approximately, $P_{\mx} / \eta_{\shaftgrid}$, where $P_{\mx}$ is
the per-kite rated power, so that the power system is fully utilized
during generation.  In this case, the constraint imposed by VTOL is:
$\eta_{\shaftgrid}^2 P_{\hover} / f \le P_{\mx}$.  Note that the extra
factor of $\eta_{\shaftgrid} / f$ accounts for the fact that
Eq. \ref{eqn:hover_power} is written in terms of ground power, and
also that it is necessary to acccount for the motor-out fraction again
in a shaft power limited system.

For a single kite M600-like system, assuming $P_{\mx} = 600$ kW,
$\eta_{\shaftgrid} = 0.83$, $\mathit{FM} = 0.68$, $\rho_{\mn} = 0.95$
kg/m$^3$, $A_{\prop} = 3.8$ m$^2$, and $\mathit{TWR} = 1.3$,
$f = 3/4$, this sets a reasonable mass limit of $m_{\total} < 1338$
kg.  For a multi-kite M600-like system, with equivalent parameters,
the mass limit is $m_{\total} < 1416$ kg.  If the motor-out fraction
is increased to $f = 7/8$, then the single- and multi-kite limits are
1409 kg and 1652 kg, respectively.  Above these mass limits, VTOL
becomes expensive quickly, scaling as
$P_{\hover} \propto (m/m_{\nominal})^{3/2}$.

It is of course possible to increase the VTOL lifting ability through
significant design changes to the M600.  The most significant
parameter to change is rotor disk area.  In particular,
Eq. \ref{eqn:hover_power} can be used to solve for the rotor disk area
that meets a given power requirement.  Later in this paper, limits on
the power density of a kite system will be derived, so it is actually
more useful to reexpress Eq. \ref{eqn:hover_power} as a relationship
between maximum power density and disk mass loading:
%
\begin{equation}
  \label{eqn:hover_power2}
  \left(\frac{P_{\mx}}{m_{\total}}\right)^2 >
  k \left(\frac{m_{\total}}{N_{\prop} A_{\prop}}\right)
\end{equation}
%
Assuming the same values as above, the proportionality constant here
is $k \approx 6400$ W$^2$-m$^2$/kg$^3$.  To get a feel for the range
of values this constant could take across kite systems, the value
without motor-out capability is $k \approx 2700$ W$^2$-m$^2$/kg$^3$.

\section{Crosswind flight}

Crosswind flight does not place as strict of a limit on mass as VTOL;
however it still imposes mass limitations stricter than what would be
required for traditional flight vehicles.  The main consequences of
increased mass in crosswind flight are 1) an increase in power
required to maintain a minimum airspeed during climb, 2) an increase
in minimum turning radius, and 3) an increase in power and tension
variations around a loop.  Each of these consequences are analyzed in
detail below.

\subsection{Minimum airspeed climb}

A reasonable requirement for a kite system is to be able to maintain
the minimum allowed airspeed, $v_{\app,\mn}$, while climbing up the loop
with low or zero wind.  Assuming a circular flight path, this results
in the power requirement for climbing of
%
\begin{equation}
  P_{\climb} = \frac{m_{\eff} g_{\parallel} v_{\app,\mn}}{\eta_{\airgrid}}
\end{equation}
%
which may be converted to a limitation on the maximum reasonable
effective mass:
%
\begin{equation}
  \label{eqn:mass_minimum_airspeed_climb}
  m_{\eff} < \frac{\eta_{\airgrid} P_{\mx}}{g_{\parallel} v_{\app,\mn}}
\end{equation}
%
For an M600-like system, assuming $P_{\mx} = 600$ kW,
$\eta_{\airgrid} = 0.67$, a flight path elevation angle of
25$^{\circ}$, and $v_{\app,\mn} = 30$ m/s, the maximum reasonable
effective mass is $m_{\eff} = 1507$ kg.\footnote{TODO: Add drag to
  calculation.}

\begin{figure}[h]
\begin{center}
  \begin{tikzpicture}
    \begin{scope}[scale=2]]
      % Downstrokes.
      \draw[arrows={latex-}] ({sqrt(2) + 1}, 0) arc (0:135:1);
      \draw                  ({sqrt(2) + 1}, 0) arc (0:-135:1);

      \draw[arrows={latex-}] ({-(sqrt(2) + 1)}, 0) arc (180:45:1);
      \draw                  ({-(sqrt(2) + 1)}, 0) arc (180:315:1);

      % Upstrokes.
      \draw[arrows={-latex}] ({-sqrt(2)/2}, {-sqrt(2)/2}) --
      ({ sqrt(2)/2}, { sqrt(2)/2});
      \draw[arrows={-latex}] ({ sqrt(2)/2}, {-sqrt(2)/2}) --
      ({-sqrt(2)/2}, { sqrt(2)/2});

      \draw ({-sqrt(2) - 0.1}, 0) -- ({-sqrt(2) + 0.1}, 0);
      \draw ({-sqrt(2)}, -0.1) -- ({-sqrt(2)}, 0.1);

      \draw ({sqrt(2) - 0.1}, 0) -- ({sqrt(2) + 0.1}, 0);
      \draw ({sqrt(2)}, -0.1) -- ({sqrt(2)}, 0.1);

      \draw[dashed] (0, 0) -- ({sqrt(2)}, 0);
    \end{scope}

    \draw[arrows={latex-latex}] (1, 0) arc (0:45:1);
    \path (1, 0) arc (0:22.5:1) node[above right] {$\psi_{\climb}$};

    \draw [decorate, decoration={brace, amplitude=5pt}]
      ({-sqrt(2)*2}, 0) -- ({-sqrt(2)*2 - 1}, {sqrt(3)})
      node[midway, below left] {$R_{\path}$};

    \draw [decorate, decoration={brace, amplitude=5pt}]
      (0, 0) -- ({-(sqrt(2) * 2)}, 0)
      node[midway, below=0.2] {$\delta$};

  \end{tikzpicture}
  \caption{Figure-eight flight path.}
\end{center}
\end{figure}

One concept that attempts to relax the constraints imposed by a
minimum airspeed climb is to fly figure-eights where the upstrokes are
the long paths between downstrokes.  Now the power to climb is reduced
by the sine of the climb angle:
%
\begin{equation}
  \label{eqn:mass_minimum_airspeed_climb2}
  P_{\climb} = \frac{m_{\eff} g_{\parallel} v_{\app,\mn} \sin \psi_{\climb}}
                    {\eta_{\airgrid}}
\end{equation}
%
Unfortunately, the figure-eight pattern has significant negative
effects on power generation.  One effect is that it pushes part of the
path off-downwind.  Specifically, the center of each of the loops of
the eight will be approximately
$\delta = R_{\path} / \sin \psi_{\climb}$ off-downwind.  Thus, there
will be a power loss roughly proportional to
%
\begin{equation}
  \eta_{\figureeight} \sim \cos^3 (\sin^{-1}(\sin \gamma / \sin \psi_{\climb}))
\end{equation}
%
where $\gamma$ is the half-cone angle of the flight path.  Even for
moderate climb angles, say $\psi_{\climb} = 45^{\circ}$, these losses
are substantial, $\eta_{\figureeight} \sim 0.67$ assuming
$\gamma = 20^{\circ}$ \footnote{For single kite systems, the required
  low elevation angle of the flight path puts a strict limit on the
  maximum half-cone angle.  This can be relaxed somewhat for
  multi-kite systems.}.  And the estimated efficiency drops off
quickly with shallower climb angles, $\eta_{\figureeight} = 0.38$ at
$\psi_{\climb} = 30^{\circ}$.  A second slightly harder to quantify
effect is that the figure-eight will take longer to fly than the
equivalent set of two independent circles, which also reduces power
efficiency.

Nonetheless, flying figure-eights does offer an approach to increasing
the maximum mass calculated with
Eq. \ref{eqn:mass_minimum_airspeed_climb} by a factor of, very
roughly, 1.5, while sacrificing some power efficiency.  For an
M600-like system flying figure-eights, the maximum reasonable
effective mass is, again very roughly, 2300 kg.

Equations \ref{eqn:mass_minimum_airspeed_climb} and
\ref{eqn:mass_minimum_airspeed_climb2} set a fairly strict limit on
the power density of kite systems, which is independent of system
scale.  Using the same parameters used above for the M600 system,
which should apply equally well to a generic kite system, the power
density for a kite system flying a circular path must be greater than
400 W/kg, and the power density for a kite system flying a
figure-eight must be greater than roughly 265 W/kg.

\subsection{Turning radius}

The ability of a kite to turn around a tight circular path is
inversely proportional to its mass.  Higher masses will eventually
force either a larger path radius or an excessively large roll angle.
A larger path radius leads to a longer, draggier, and heavier tether
as well as larger swings in tension and power.  Similarly, an
excessively large roll angle has negative consequences due to the
reduced projected wing area normal to the wind.

To quantify these effects, it is useful to derive the exact
relationship between wing mass and turning radius.  This relationship
can be found by balancing forces in the stability axes' y-z plane.  To
simplify the calculation, the tether is appoximated as a straight line
from the ground-station to the bridle point.  Other effects on the
tether such as the catenary from gravity are ignored.

\begin{figure}[h]
\begin{center}
  \begin{tikzpicture}[scale=0.5]
    \begin{scope}[shift={(-5, 0)}, scale=0.3, rotate=-10]
      \DrawWingFront[]
      \draw[line width=1.5pt, -latex] (4, 1) -- (9, 1) node[midway, above] {$-Y$};
      \draw[line width=1.5pt, -latex] (0, 5) -- (0, 12) node[midway, right] {$L$};
      \draw (-5.86, -0.13) -- (0, -4.92);
      \draw (5.86, -0.13) -- (0, -4.92);
      \draw[dashed] (0, -4.92) -- (0, -15);
    \end{scope}
    \node at (-5, -3) {$\phi_t$};
    \draw[line width=1.5pt, -latex] (-5.25, -1.45) --
    (-3.5, -4.3) node[midway, above right] {$t$};
    \draw[line width=1.5pt, -latex] (-3.5, -1) -- (-2, -2)
    node[below right] {$W$};
    \draw (-5.25, -1.45) -- (0, -10) node[midway, above right] {$l_t$};
    %\draw[dashed] (-5.25, -1.45) -- (-0.975, 1.175);
    \node at (-0.5, -8.5) {$\gamma$};
    \draw[dashed] (0, -10) -- (0, -5);
    %\draw[dashed] (-5, 0) -- (-10, 0) node[near end, above] {$-\phi$};
    %\draw[line width=1.5pt, -latex] (-7, 0) -- (-9, 0) node[midway, below]
    %{$mv^2/R$};
    \DrawCoordinateSystem{shift={(0, -10)}, scale=1}
                         {$x_{\cw}$}{$y_{\cw}$}{$z_{\cw}$}
  \end{tikzpicture}
  \caption{Diagram of force balance in the stability axes' y-z plane.}
\end{center}
\end{figure}

It is easiest to conduct the force balance along axes that are
parallel and perpendicular to the tether.  Because the wing is forced
to fly on the surface of a sphere with radius equal to the tether
length, $l_t$, the acceleration parallel to the tether is
$a_{\parallel} = v_i^2/l_t$.  The lift, pylon side force, and weight
each have components along the direction perpendicular to the tether.
Together, these create an acceleration perpendicular to the tether
given by
%
\begin{equation}
m_{\eff} a_{\bot} = L \sin \phi_t - Y \cos \phi_t -
W_{\cw, x} \cos \gamma - W_{\cw, z} \sin \gamma
\end{equation}
%
Here $m_{\eff}$ is the effective mass of the kite, which is given by
$m_{\eff} = m_{\kite} + m_{\mathrm{tether}} / 3$.  The extra term from
the tether mass comes from calculating the acceleration of a point
mass at the end of a rigid rod due to a force applied at the point
mass.  Also, a few small approximations were made such as ignoring
forces from motor thrust, ignoring the component of drag along the
stability z-axis, and ignoring the cosine term from projecting the
lift vector onto the stability z-axis.

The acceleration projected onto the crosswind flight plane is the
acceleration relevant for following a circular path.  The parallel and
perpendicular accelerations can be combined, projected onto the
crosswind $x$-axis as follows:
%
\begin{align}
  \label{eqn:full_curvature}
  \frac{m_{\eff} v_i^2}{r} =&\;
    \frac{m_{\eff} v_i^2}{l_t} \sin \gamma +
    \frac{1}{2} \rho A v_{\app}^2 \left(C_L \sin \phi_t - C_Y \cos \phi_t \right) \cos \gamma \\ \notag
  & - m (g_{\cw,x} \cos \gamma +
  g_{\cw,z} \sin \gamma) \cos \gamma
\end{align}
%
For the purposes of this discussion, Eq. \ref{eqn:full_curvature} may
be simplified for the turn about the bottom of the loop, directly
downwind, while ignoring some of the smaller terms:
%
\begin{equation}
  r \approx \frac{m_{\eff} v_i^2}
                 {\frac{1}{2} \rho A v_{\app}^2 C_L \sin \phi_t \cos \gamma -
                 m g_{\parallel} \cos^2 \gamma}
\end{equation}

The tether roll angle, $\phi_t$, is the primary control variable for
turning the kite around the path.  It is also possible to use $C_L$ or
$C_Y$ to turn, but these variables significantly affect power
production, so they are likely set by other considerations.  At the
absolute minimum, it is necessary to be able to set $\phi_t$ such that
$r = R_{\path}$ to fly a circle.  However, to be able to {\it control}
the kite it is necessary to have an available-to-desired centripetal
force ratio, $\mathit{CFR}$, greater than one, a similar concept to a
thrust-to-weight ratio.  Thus, the constraint is that there is some
$\phi_t$ such that $1/r > \mathit{CFR} / R_{\path}$.  A realistic
centripetal force ratio may be $\mathit{CFR} \sim 1.5$.  The above
considerations result in the following constraint on path radius:
%
\begin{equation}
  R_{\path} > \mathit{CFR} \cdot
              \frac{m v_{i,\mn}^2}
                   {\frac{1}{2} \rho v_{i,\mn}^2 C_L A \sin \phi_{t,\mx} \cos \gamma_{\mx} -
                    m g_{\parallel} \cos^2 \gamma_{\mx}}
\end{equation}
%
Note that the apparent wind speed was replaced by an inertial speed
because it should still be possible to turn without wind!

The constraint on path radius can be converted to a constraint on
minimum tether length for a given kite mass:
%
\begin{equation}
  l_{t,\mn} > l_{t_0} \frac{m}{m_0 - m}
\end{equation}
%
where the characteristic tether length $l_{t_0}$ is:
%
\begin{equation}
  l_{t_0} = \mathit{CFR} \cdot
  \frac{m_{\eff} v_{i,\mn}^2}{m g_{\parallel} \sin(\gamma_{\mx}) \cos^2(\gamma_{\mx})}
\end{equation}
%
and the characteristic mass $m_0$ is:
%
\begin{equation}
  \label{eqn:characteristic_mass}
  m_0 = \frac{\frac{1}{2} \rho v_{i,\mn}^2 A C_L \sin(\gamma_{\mx} + \phi_{\mx})}
             {g_{\parallel} \cos(\gamma_{\mx})}
\end{equation}

Clearly, this gives an absolute hard limit on mass of $m < m_0$.  This
limit can be tightened somewhat by additionally specifying that the
derivative of the {\it minimum} tether length with respect to
effective mass should not grow faster than the derivative of the
tether length with respect to effective mass:
%
\begin{equation}
  m < m_0 - \sqrt{\frac{l_{t_0} m_0 \lambda_t}{3}}
\end{equation}
%
where $\lambda_t$ is the linear mass density of the tether.

For an M600-like system, assuming $\mathit{CFR} = 1.5$, $\rho = 0.95$
kg/m$^3$, $v_{i,\mn} = 30$ m/s, $\gamma_{\mx} = 20^{\circ}$,
$\phi_{\mx} = 30^{\circ}$, $\lambda_t = 1$ kg/m, and a flight path
elevation angle of $25^{\circ}$, $m_0 \approx 2700$ kg and
$l_{t_0} \approx 540$ m. This implies that $m_{\kite} < 2000$ kg.
And, ideally $m_{\kite}$ should be significantly less to avoid a
runaway in mass.

Equation \ref{eqn:characteristic_mass} sets a fairly strict limit on
wing mass loading, which is independent of system scale.
Specifically, to be able to fly in a circle on a reasonable length
tether, a kite system must have a wing mass loading of less than 60
kg/m$^2$.

\subsection{Tension and power variation}
This section is not finished yet.

% \section{Designing a kite}

% \begin{table}[h]
%   \begin{tabular}{cccc}
%     \hline
%     \hline
%     Parameter               & Symbol               & Value              & Units \\
%     \hline
%     Min. power density      & $\rho_{\power}$      & 400                & W/kg \\
%     Max. wing mass loading  & $\sigma_{\mass}$     & 60                 & kg/m$^2$ \\
%     M600 powertrain density & $\rho_{\powertrain}$ & $1.25 \times 10^3$ & W/kg \\
%     \hline
%     \hline
%   \end{tabular}
% \end{table}

% Choose a rated power: $P_{\mx} = 600$ kW.

% Use the minimum power density to find the maximum effective mass: $P_{\mx} / \rho_{\power} = 1500$ kg.

% Select a lower mass for margin: $m_{\eff, \mx} = 1200$ kg.

% Estimate the amount of kite mass: $m_{\kite, \mx} = 1100$ kg.

% Estimate the total mass: $m_{\total, \mx} = 1400$ kg.

% Use Eq. \ref{} to estimate total rotor area: $N_{\prop} A_{\prop} > 48.8$ m$^2$.

% For current motors, $P_{\mx} = 600$ kW implies $N_{\prop} = 8$.

% Thus, $A_{\prop} = 6.1$ m$^2$ and $R_{\prop} = 1.4$ m.

% Use maximum wing mass loading to determine a minimum wing area:
% $m_{\kite, \mx} / \sigma_{\mass} = 18$ m$^2$.

% Select a higher area for margin: $A_{\kite} = 25$ m$^2$.

\section{Conclusions}

\begin{itemize}

\item For a system with the same aerodynamic and geometric properties
  as the M600, VTOL imposes a {\it total} mass limit of 1200 kg; the
  minimum airspeed climb imposes an {\it effective} mass limit of 1500
  kg (this increases to 2300 kg for a figure-eight flight path); and
  the turning radius imposes a {\it kite} mass limit of 2000 kg.

\item According to the minimum airspeed climb criterion, a kite that
  flies circles must have a power density, referenced to {\it
    effective} mass, of greater than 400 W/kg.  A kite that flies
  figure-eights may relax this to roughly 265 W/kg.  A kite with a
  ground-based power system (i.e. pumping kite) can relax these limits
  even further, potentially to 200 W/kg for figure-eights, due to a
  more efficient power conversion process. These limits are
  essentially independent of scale.

\item Given that the specific power of our powertrains is ~1.25 kW/kg,
  approximately 1/3 to 1/2 of the system weight will be the
  powertrain, independent of scale.  For an M600-like VTOL system,
  this leaves $\sim 500$ kg for structure, servos, etc.

\item After a power density is selected, which meets the limit above,
  Eq. \ref{eqn:hover_power2} may be used to size the total rotor area.

\item According to the turning radius criterion, a kite must have a
  wing mass loading, referenced to {\it kite} mass, of less than 60
  kg/m$^2$.  Again, this limit is independent of scale.

\item At the 600 kW scale, designing a system that supports VTOL will
  require substantially reducing the maximum tension.  Because of the
  square-cube law, larger scales will likely require significant
  topology changes (e.g. more bridling, tailless variants, or
  multi-kites) coupled with a reduction in maximum tension.
\end{itemize}

\begin{thebibliography}{1}
\bibitem{tvanalsenoy_power_train} Alsenoy, Thomas.
  ``Airborne wind powertrain trade-off study.''
  \texttt{Drive > Makani Teams > Engineering > 01\_System\_Engineering > Papers (internal)}. 2016.
\end{thebibliography}

\end{document}


%!TEX root = ../main.tex

\chapter{FFTbor}
\label{ch:fftbor}

\lhead{FFTbor: Coarse-Grained Energy Landscapes}

\section{Introduction}
\label{sec:fftbor:intro}

In this chapter, we present the \fftbor algorithm and accompanying software.
\fftbor is a novel algorithm developed with the intent of efficiently computing
the Boltzmann probability of those structures which, for a given input RNA
sequence \seq, differ by $k$ base pairs. By leveraging polynomial interpolation
via the \fft, this algorithm runs in \On{4} time and
\On{2} space, a significant improvement over its predecessor. The accompanying
software which implements this algorithm has been used to evaluate the
correlation between kinetic folding speed and landscape ruggedness.

\subsection{Organization}
\label{subsec:fftbor:org}

This chapter is organized in the following fashion. First, we provide
background on
the problem which \fftbor aims to address, as well as a brief overview of
existing approaches. We follow by a formal explanation of the problem, and
proceed to describe how the energy landscape is partitioned into discrete bins.
We then develop the recursions for the parameterized partition function using
the Nussinov-Jacobson energy model, which allows us to highlight the novel aspects
of the algorithm. After developing the recursions, we indicate how they can be
reformulated as a polynomial whose coefficients $z_k=\bfZ{k}{1,n}$. We then
describe how the \fft can be employed to efficiently compute the coefficients
$z_k$, finishing our description of the underlying algorithm. Then we proceed
to present an application of \fftbor, in the area of RNA folding kinetics.

\section{Background}
\label{sec:fftbor:bkgrnd}

In \citep{freyhult.b07}, a dynamic programming algorithm
\rnabor---pronounced {\em RNA neighbor}---was developed which simultaneously
computes for
each integer $k$, the Boltzmann probability $\pk = \frac{\bfZ{k}{}}{\fullZ}$
of the subensemble of structures
whose \bpd to a given {\em initial}, or
{\em reference}, structure \strSt is $k$.
\footnote{As later
explained, \fullZ denotes the partition function, defined as the sum of
all Boltzmann factors \boltzf{\str}, over all secondary structures \str
of a given RNA sequence, and $R$ denotes the universal
gas constant and $T$ absolute temperature. Similarly \bfZ{k}{} denotes the
sum of all Boltzmann factors of all structures \str, whose \bpd
to the initial structure \strSt is exactly $k$.}
\rnabor stores the value of the (partial)
partition functions \bfZ{k}{i,j} for all $1 \leq i \leq j \leq n$ and
$0 \leq k \leq n$, each of which requires quadratic time to compute.
Thus it follows that \rnabor runs in time \On{5} and space
\On{3}, which severely limits its applicability to genomic annotation.
This restriction is somewhat mitigated by the fact that
in \citep{cloteloulorenz}, we showed how to use sampling
\citep{ding.nar03} to efficiently approximate
\rnabor in cubic time \On{3} and quadratic space \On{2},
{\em provided} that the starting structure \strSt is the \mfe
(MFE) structure. We expect that a more efficient version of
\rnabor could be used in applications in genomics and synthetic
biology, to detect potential conformational switches---
RNA sequences containing two or more (distinct) metastable structures.

In this chapter, we describe a radically different algorithm, \fftbor
\citep{senter.po12},
prounounced {\em FFT neighbor},
that uses polynomial interpolation to compute the
coefficients $p_0,\ldots,p_{n-1}$ of the polynomial defined in
\eqnref{fftbor:pOfX},
where \pk is defined by $\pk = \frac{\bfZ{k}{}}{\fullZ}$.
Due to severe numerical instability issues in both the Lagrange
interpolation formula and in Gaussian elimination, we employ
the \fft (FFT) to compute the \idft (DFT) on values $y_0,\ldots,y_{n-1}$,
where $y_k = p(\omega^k)$ and
$\omega = \pRoU$ is the principal \nRoU and
$p(x)$ is defined in \eqnref{fftbor:pOfX}. This
gives rise to an improved version of \rnabor, denoted \fftbor,
which runs in time \On{4} and space \On{2}.

\section{Formalization of the problem}
\label{sec:fftbor:formal}

\fftbor aims to compute the coefficients $p_0,\dots,p_{n-1}$ of the polynomial

\begin{align}
\label{eq:fftbor:pOfX}
p(x) = p_0 + p_1 x + p_2 x^2 + \dots + p_{n-1} x^{n-1},
\end{align}

where \pk is defined as $\pk = \frac{\bfZ{k}{}}{\fullZ}$. We employ the \fft to compute
the \idft on values $y_0,\dots,y_{n-1}$, where
$y_k = p(\omega^k)$ and $\omega = \pRoU$ is the principal \nRoU and $p(x)$ is defined in
\eqnref{fftbor:pOfX}. By leveraging
\nRoUs in conjunction with the \idft the we subvert numeric instability
issues observed with both Lagrange interpolation and Gaussian elimination.

Consider an RNA sequence $\seq = \seqN$, where
$s_i \in \{\text{A,\,U,\,G,\,C}\}$, i.e. a sequence of nucleotides. We can describe a
secondary structure \str which is compatible with \seq as a collection of
base pair tuples $(i,j)$, where $1 \le i \le i+\theta < j \le n$ and
$\theta \ge 0$ (generally taken to be $3$), the minimum number of unpaired bases
in a hairpin loop due to steric constraints.

To more simply develop the underlying recursions for \fftbor, we introduce a
number of constraints on the base pairs within \str. Firstly, we require that
each base pair is either a Watson-Crick or G-U wobble, i.e. base pair $(i,j)$
for sequence \seq has corresponding nucleotides $(s_i,s_j)$, which are
restricted to the set

\begin{align}
\label{eq:fftbor:validBP}
\bpSet =
\{\text{(A,\,U),\,(U,\,A),\,(G,\,C),\,(C,\,G),\,(G,\,U),\,(U,\,G)}\}.
\end{align}

With
this constraint satisfied we say that \str is {\em compatible} with \seq, and
for the remainder of this chapter will only consider those structures which are
compatible with \seq.
Secondly, we insist that given two base pairs $(i,j), (x,y)$ from \str,
$i=x \iff j=y$ (bases have at most one partner). Finally, we require that
$i<x<j \iff i<y<j$ (no pseudoknots are allowed). While pseudoknots have been
shown to be present in some biologically relevant RNAs, their inclusion greatly
complicates the recursive decomposition of the structure, and thus it is common
to ignore them. As a result, sequences known to contain
pseudoknots---such as RNase P \citep{haas:1991vl}---are
not well suited for \fftbor, and whenever possible investigators should take
care to consider the likely structure for their sequences before proceeding with
computational analysis.

Provided two secondary structures \strST, we can define a notion of
distance between them. There are a number of different definitions of distance
used across the literature; we will use {\em \bpd} for \fftbor.
\Bpd is defined as the symmetric difference between the sets
\strST:

\begin{align}
\label{eq:fftbor:dBP}
\dBP{\str}{\strT} = |\str \cup \strT| - |\str \cap \strT|.
\end{align}

Given this definition of distance, two structures \str and \strT are said to
be \kNbrs if $\dBP{\str}{\strT} = k$. It is important to note that
the notion of \bpd is also applicable to restrictions of secondary structures
on the subsequence $\seq_{i,j}$,
i.e. $\str_{[i,j]} = \{ (x,y) \,:\, i \leq  x < y \leq j,  (x,y) \in \str \}$.

For a restriction of base pairs for a given structure $\str_{[i,j]}$,
$\strT_{[i,j]}$ is said to be a \kNbr of $\str_{[i,j]}$ if

\begin{align}
\label{eq:fftbor:dBPonRestriction}
\dBP{\str_{[i,j]}}{\strT_{[i,j]}} =
|\{ (x,y): i \leq x<y\leq j,
(x,y) \in \str - \strT \text{or} (x,y) \in \strT - \str \}| = k.
\end{align}

\section{Derivation of the \fftbor algorithm}
\label{sec:fftbor:math}

Given an RNA sequence $\seq=\seqN$ and compatible secondary structure
\strSt, let \bfZ{k}{} denote the sum of the Boltzmann factors
\boltzf{\str} of all \kNbrs \str of \strSt; i.e.

\begin{align}
\bfZ{k}{} = \bfZ{k}{1,n} =
\sum_{\mathclap{\substack{\str \text{ such that } \rule[-.5ex]{0pt}{0pt} \\
 \dBP{\str}{\strSt}=k}}}\;
\boltzF{\str}
\end{align}

where $E(\str)$ denotes the Turner (nearest neighbor)
energy \citep{xia:RNA}
of \str, $R = \kmolk{0.00198}$ denotes the universal
gas constant and $T$ denotes absolute temperature. From this, it follows that
the full partition function is defined as

\begin{align}
\label{eq:fftbor:partFunc}
\fullZ = \bfZ{}{1,n} = \sum_{k=0}^n \bfZ{k}{1,n}
\end{align}

since the \bpd between \strSt and \str is at most

\begin{align}
\label{eq:fftbor:maxDist}
\dBP{\strSt}{\str} \leq |\strSt| + \lfloor \frac{n-\theta}{2} \rfloor \leq n.
\end{align}

We can then define the Boltzmann probability of all \kNbrs of \strSt as

\begin{align}
\label{eq:fftbor:probK}
p(k) =\frac{\bfZ{k}{1,n}}{\bfZ{}{1,n}}.
\end{align}

By visualizing the probabilities \pk as a function of $k$, we generate a
coarse-grained view of the one-dimensional energy landscape of \seq with
respect to \strSt. When \strSt is taken to be the \mfes for example, one would
anticipate to see a peak at $k=0$, with additional peaks implying additional
metastable structures; local energy minima which could suggest an energetic
trap while folding.

\subsection{Definition of the partition function
\texorpdfstring{\bfZ{k}{1,n}}{}}
\label{subsec:fftbor:recursions}

For the rest of the chapter, we consider both \seq as well as the
secondary structure \strSt on \seq to be fixed. We now recall the
recursions from Freyhult et al. \citep{Freyhult.ab05} to determine
the partition function \bfZ{k}{i,j} with
respect to the Nussinov-Jacobson
energy $E_0$ model \citep{nussinovjacobson}, defined by
$-1$ times the number of base pairs; i.e. $E_0(S) = -1 \cdot |S|$.
Although we describe here the recursions for the Nussinov-Jacobson
model, for the sake of
simplicity of exposition, both \rnabor
\citep{Freyhult.ab05} as well as our current software \fftbor,
concern the Turner energy model (described in \Secref{sec:fftbor:turner}), consisting of free energy parameters for
stacked bases, hairpins, bulges, internal loops and multiloops.

% The full
% recursions for \fftbor are described for the
% the Turner energy model in the appendix.

The base case for \bfZ{k}{i,j} is given by

\begin{align}
\label{eq:fftbor:initZpart1}
\bfZ{0}{i,j} = 1, \text{ for } i \le j,
\end{align}

since the only $0$-neighbor to a structure \strSt
is the structure \strSt itself, and

\begin{align}
\label{eq:fftbor:initZpart2}
\bfZ{k}{i,j} = 0, \text{ for } k > 0, i \le j \leq i + \theta,
\end{align}

since the empty structure is the only possible structure for a
sequence shorter than $\theta + 2$ nucleotides, and so there are no
\kNbrs for $k>0$. The recursion used to compute
\bfZ{k}{i,j} for $k > 0$ and $j > i+\theta$ is

\begin{align}
\label{eq:fftbor:bfZkij}
\bfZ{k}{i,j} = \bfZ{k-b_0}{i,j-1}\enspace +
\sum_{\substack{(s_r,s_j) \in \bpSet, \\ i \leq r<j}}\qquad
\sum_{\mathclap{w+w'=k-b(r)}}\enspace
\exp(-E_0(r,j)/RT) \cdot \bfZ{w}{i,r-1} \bfZ{w'}{r+1,j-1},
\end{align}

where $E_0(r,j) = -1$ if positions $r,j$ can pair in sequence \seq,
and otherwise $E_0(r,j) = +\infty$. Additionally,
$b_0 = 1$ if $j$ is base-paired
in $\strSt_{[i,j]}$ and $0$ otherwise, and
$b(r)=\dBP{\strSt_{[i,j]}}{\strSt_{[i,r-1]} \cup \strSt_{[r+1,j-1]} \cup\{(r,j)\}}$.
This holds since in a secondary
structure $\strT_{[i,j]}$ on \seqIJ that is a \kNbr of
$\strSt_{[i,j]}$,
either nucleotide $j$ is unpaired in $[i,j]$ or it is
paired to a nucleotide $r$ such that $i \leq r < j$. In this
latter case it is enough to study the smaller sequence segments
$[i,r-1]$ and $[r+1,j-1]$ noting that, except for $(r,j)$,
base pairs outside of these regions are not allowed, since there
are no pseudoknots. In addition,
for $\dBP{\strSt_{[i,j]}}{\strT_{[i,j]}} = k$ to hold,
it is necessary for $w+w' = k -b(r)$ to hold, where $w =
\dBP{\strSt_{[i,r-1]}}{\strT_{[i,r-1]}}$ and $w' =
\dBP{\strSt_{[r+1,j-1]}}{\strT_{[r+1,j-1]}}$, since $b(r)$ is the
number of base pairs that differ between $\strSt_{[i,j]}$ and a
structure $\strT_{[i,j]}$, due to the introduction of the base pair
$(r,j)$.

Given RNA sequence \seq and compatible initial structure \strSt,
we define the {\em polynomial}

\begin{align}
\label{eq:fftbor:zOfX}
\fullZx = \sum_{k=0}^n z_k x^k
\end{align}

where coefficients $z_k=\bfZ{k}{1,n}$. Moreover, because of
\eqnref{fftbor:maxDist} and the fact that the minimum number of
unpaired bases in a hairpin loop $\theta$ is $3$, we know that $z_n=0$,
so that \fullZx is a polynomial of degree strictly less than $n$.
If we evaluate the polynomial \fullZx for $n$ distinct values

\begin{align}
\label{eq:fftbor:solutionsForAlpha}
\emZof{}{a_1} = y_1, \dots, \emZof{}{a_n} = y_n,
\end{align}

then the Lagrange polynomial interpolation formula guarantees that
$\fullZx = \sum_{k=1}^n y_k P_k(x)$, where the polynomials $P_k(x)$ have degree
at most $n-1$ and are given by the Lagrange formula

\begin{align}
\label{eq:fftbor:lagrangeInterpolation}
P_k(x) = \frac{\prod_{i\ne k} (x-x_i)}{\prod_{i \ne k} (x_k-x_i)}.
\end{align}

Since the polynomials $P_k(x)$ can be explicitly computed, it follows that
we can compute the coefficients $z_k$ of polynomial \fullZx. As we describe
below, the evaluation of \fullZx for a fixed value of $x$ can be done in
time \On{3} and space \On{2}.  It follows that the coefficients
$z_k=\bfZ{k}{1,n}$ can be computed after
$n$ evaluations of \fullZx, where the space for each evaluation of \fullZx
is re-used; hence these evaluations can be performed in time \On{4} and space
\On{2}. Finally,
Lagrange interpolation is clearly computable in time \On{3}.
Although this approach is theoretically sound, there are severe
numerical stability issues related to the interpolation method
\citep{highambarycentricinterpolation},
the choice of values $a_1,\dots,a_{n}$ in the interpolation,
and floating point arithmetic (round-off error) related to the
astronomically large values of the partition functions
\bfZ{k}{1,n}, for $0 \leq k < n$. After many unsuccessful
approaches including scaling we obtained excellent results by
interpolating the polynomial $p(x)$, defined in \eqnref{fftbor:pOfX},
rather than the polynomial \fullZx, defined in \eqnref{fftbor:zOfX},
and performing interpolation with the \fft (FFT) \citep{cormen}
where \alphaN are
chosen to be \nRoUs,
$\alpha_k = \kRoU$.
One
advantage of the FFT is that interpolation can be performed in $O(n \log n)$
time, rather than the cubic time required by using the Lagrange formula
shown in \eqnref{fftbor:lagrangeInterpolation} or by Gaussian elimination. Fewer
numerical operations implies increased numerical stability in our application.

\subsection{Recursions to compute the polynomial
\texorpdfstring{\emZ{i,j}}{}}
\label{subsec:fftbor:polynomial}

Given an initial secondary structure \strSt of a
given RNA sequence \seq, our goal is to compute

\begin{align}
\label{eq:fftbor:defZofK}
\bfZ{k}{1,n} = \sum_{\mathclap{\substack{\str \text{ such that }\\ \dBP{\str}{\strSt}=k}}}\;
\boltzNuss{\str}
\end{align}

where \str can be any structure compatible with \seq.
As previously mentioned, the recurrence relation for \rnabor
with respect to the Nussinov energy model $E_0$ is

\begin{align}
\label{eq:fftbor:rnaborNuss}
\bfZ{k}{i,j} = \bfZ{k-b_0}{i,j-1}\enspace +
\sum_{\substack{(s_r,s_j) \in \bpSet, \\ i \le r<j}}
\left(
\boltzNuss{r,j}\enspace \sum_{\mathclap{w+w'=k-b(r)}}\quad
\bfZ{w}{i,r-1} \bfZ{w'}{r+1,j-1}
\right)
\end{align}

where $E_0(r,j)=-1$ if $r$ and $j$ can base-pair and otherwise
$+\infty$, and
$b_0 = 1$ if $j$ is base paired in $\strSt_{[i,j]}$ and $0$ otherwise, and
$b(r)=\dBP{\strSt_{[i,j]}}{\strSt_{[i,r-1]} \cup \strSt_{[r+1,j-1]} \cup\{(r,j)\}}$.
The following theorem shows that an analogous recursion can be used to compute
the {\em polynomial} $\emZ{i,j}$ defined by

\begin{align}
\label{eq:fftbor:polynomialZij}
\emZ{i,j} = \sum_{k=0}^n z_k(i,j)\,x^k
\end{align}

where

\begin{align}
z_k(i,j)\>=\>
\bfZ{k}{i,j}\enspace=\enspace
\sum_{\mathclap{\substack{\str \text{ such that } \\
\dBP{\str}{\strSt_{[i,j]}}=k}}}\enspace
\boltzNuss{\str}.
\end{align}

Here, in the summation, \str runs over structures on \seqIJ, which
are \kNbrs of the restriction $\strSt_{[i,j]}$ of initial structure
\strSt to interval $[i,j]$, and
$E_0(S)=-1 \cdot |S|$ denotes the Nussinov-Jacobson energy of \str.

\begin{theorem}
\label{thm:fftbor:recursions}
Let \seqN be a given RNA sequence.
For any integers $1 \leq i \leq j \leq n$, let

\begin{align}
\emZ{i,j} = \sum_{k=0}^n z_k\,x^k
\end{align}

where

\begin{align}
z_k(i,j) = \bfZ{k}{i,j}.
\end{align}

Then for $i\leq j \leq i+\theta$, $\emZ{i,j}=1$ and for
$j>i+\theta$ we have the recurrence relation

\begin{align}
\label{eq:fftbor:fftborNussPoly}
\emZ{i,j} = \emZ{i,j-1} \cdot x^{b_0} +
\sum_{\substack{(s_r,s_j) \in \bpSet, \\ i\le r<j}}
\left(
\boltzNuss{r,j} \cdot \emZ{i,r-1} \cdot \emZ{r+1,j-1} \cdot x^{b(r)}
\right).
\end{align}

where $b_0 = 1$ if $j$ is base-paired in $\strSt_{[i,j]}$ and $0$ otherwise, and
$b(r) =
\dBP{\strSt_{[i,j]}}{\strSt_{[i,r-1]} \cup \strSt_{[r+1,j-1]} \cup \{(r,j)\}}$.
\end{theorem}

\begin{proof}
First, some notation is necessary.
Recall that if $F$ is an arbitrary
polynomial [resp. analytic] function, then $[x^k]F(x)$
denotes the coefficient of $x^k$ [resp. the $k$th Taylor coefficient in the
Taylor expansion of $F(x)$]. For instance, in
\eqnref{fftbor:pOfX}, $[x^k]p(x) = \pk$, and in
\eqnref{fftbor:zOfX}, $[x^k]\fullZx = z_k$.

By definition, it is clear that $\emZ{i,j}=1$ if $i \leq j \leq i + \theta$,
where we recall that $\theta = 3$ is the minimum number of unpaired bases in
a hairpin loop. For $j > i + \theta$, we have

\begin{align}
\begin{split}
[x^k] \emZ{i,j} &= z_k(i,j) = \bfZ{k}{i,j} \\
&= \bfZ{k-b_0}{i,j-1} +
\sum_{r=i}^{j-1}\hspace{2.25em} \sum_{\mathclap{k_0+k_1=k-b(r)}}\hspace{1.5em}
\left( \boltzNuss{r,j} \cdot \bfZ{k_0}{i,r-1} \cdot \bfZ{k_1}{r+1,j-1} \right) \\
&= [x^{k-b_0}] \emZ{i,j-1} \\
&+ \sum_{r=i}^{j-1}\hspace{2.25em} \sum_{\mathclap{k_0+k_1=k-b(r)}}\hspace{1.5em}
\left( \boltzNuss{r,j} \cdot \left( [x^{k_0}] \emZ{i,r-1} \right) \cdot
\left( [x^{k_1}] \emZ{r+1,j-1} \right) \right) \\
&= [x^{k-b_0}] \emZ{i,j-1} \\
&+ \sum_{r=i}^{j-1}\hspace{2.25em} \sum_{\mathclap{k_0+k_1=k-b(r)}}\hspace{1.5em}
\left( \boltzNuss{r,j} \cdot [x^{k_0+k_1}]
\left( \emZ{i,r-1} \cdot \emZ{r+1,j-1} \right) \right).\\
\end{split}
\end{align}

By induction, the proof of the theorem now follows.
\end{proof}

Notice that if one were to compute all terms of the polynomial $\emZ{1,n}$
by explicitly performing polynomial multiplications,
then the computation would require \On{5} time and \On{3} space.
Instead of explicitly performing polynomial expansion in {\em variable} $x$,
we instantiate $x$ to a fixed complex number $\alpha \in \mathbb{C}$, and apply
the following recursion for this instantiation:

\begin{align}
\label{eq:fftbor:fftborNussPolyAlpha}
\emZof{i,j}{\alpha} = \emZof{i,j-1}{\alpha} \cdot \alpha^{b_0} +
\sum_{\substack{(s_r,s_j) \in \bpSet, \\ i \le r<j}}
\left(
\boltzNuss{r,j} \cdot
\emZof{i,r-1}{\alpha} \cdot \emZof{r+1,j-1}{\alpha} \cdot \alpha^{b(r)}
\right).
\end{align}

In this fashion, we can compute $\emZof{}{\alpha}=\emZof{1,n}{\alpha}$ in
\On{3} time and \On{2} space. For $n$ distinct complex values
\alphaN, we can compute and save only the
values $\emZof{}{\alpha_0},\dots,\emZof{}{\alpha_{n-1}}$, each time re-using the
\On{2} space for the next computation of $\emZof{}{\alpha_k}$. It follows that
the computation resources used to determine the (column) vector

\begin{align}
\label{eq:fftbor:yColumn}
\bfY = (y_0,\dots,y_{n-1})^{\text T} =
\left(
\begin{array}{l}
y_0 \\
y_1 \\
\vdots \\
y_{n-1} \\
\end{array}
\right)
\end{align}

where
$y_0=\emZof{}{\alpha_0},\dots,y_{n-1}=\emZof{}{\alpha_{n-1}}$ is thus quartic time \On{4} and quadratic space \On{2}.

\subsection{Polynomial interpolation to evaluate
\texorpdfstring{\emZ{i,j}}{}}
\label{subsec:fftbor:fft}

Let $\omega = \pRoU$ be the principal \nRoU.
Recall that the Vandermonde matrix $V_n$ is defined to be the
$n \times n$ matrix, whose $i,j$ entry is $\omega^{i \cdot j}$; i.e.

\begin{align}
\label{eq:fftbor:vandermonde}
V_n =
\left(
\begin{array}{rrrrr}
1 & 1 & 1 & \dots & 1 \\
1 & \omega & \omega^2 & \dots & \omega^{n-1} \\
1 & \omega^2 & \omega^4 & \dots & \omega^{2(n-1)} \\
1 & \omega^3 & \omega^6 & \dots & \omega^{3(n-1)} \\
\vdots & \vdots & \vdots & \vdots & \vdots \\
1 & \omega^{n-1} & \omega^{2(n-1)} & \dots & \omega^{(n-1)(n-1)} \\
\end{array}
\right)
\end{align}

The \fft is defined to be the $O(n \log n)$
algorithm to compute the Discrete Fourier Transform (DFT), defined
as the matrix product $\bfY = V_n {\bf A}$:

\begin{align}
\label{eq:fftbor:dftMatrix}
\left(
\begin{array}{l}
y_0 \\
y_1 \\
y_2 \\
\vdots \\
y_{n-1} \\
\end{array}
\right)
= V_n \cdot
\left(
\begin{array}{l}
a_0 \\
a_1 \\
a_2 \\
\vdots \\
a_{n-1} \\
\end{array}
\right)
\end{align}

On page $837$ of \citep{cormen}, it is shown that the
$(i,j)$ entry of $V_n^{-1}$ is $\frac{\omega^{-j i}}{n}$
and that

\begin{align}
\label{eq:fftbor:aFromY}
a_j = \frac{1}{n} \sum_{k=0}^{n-1} y_k\,\omega^{-kj}
\end{align}

for $j=0,\dots,n-1$.

Since we defined \bfY in \eqnref{fftbor:yColumn} by $\bfY =
(y_0,\dots,y_{n-1})^{\text T}$, where
$y_0=\emZof{}{\alpha_0},\dots,y_{n-1}=\emZof{}{\alpha_{n-1}}$
and $\alpha_k = \omega^k \kRoU$, it follows that the coefficients
$z_k=\bfZ{k}{1,n}$ in the polynomial
$\fullZx = z_0 + z_1 x + \dots + z_{n-1} x^{n-1}$ defined in
\eqnref{fftbor:zOfX} can be computed, at least in principle,
by using the \fft. It turns out, however, that the values of
\bfZ{k}{1,n} are so astronomically large, that the ensuing numerical
instability makes even this approach infeasible for values of $n$
that exceed $56$ (data not shown).
Nevertheless, our approach can be modified as follows.
Define \bfY by $\bfY = (y_1,\dots,y_n)^{\text T}$, where
$y_1=\frac{\emZof{}{\alpha_1}}{\fullZ},\dots,
y_{n}=\frac{\emZof{}{\alpha_n}}{\fullZ}$, and
\fullZ is the partition function defined in \eqnref{fftbor:partFunc}.
Using the \fft to compute the \idft, it follows from
\eqnref{fftbor:aFromY} that we can compute the probabilities $p_0,\dots,p_{n-1}$
that are coefficients of the polynomial
$p(x) = p_0 + p_1 x + \dots + p_{n-1}x^{n-1}$
defined in \eqnref{fftbor:pOfX}. For genomics applications, we are
only interested in the $m$ most significant digits of each \pk, as described
in the pseudocode on the following page.
\medskip

\begin{figure}[!ht]
% \hrule \rule[0ex]{0pt}{0pt}
\begin{center}
{\large Pseudocode for \fftbor} \\
\end{center}
\begin{tabular*}{\textwidth}{ll}
{\sc Purpose:} & Computes the $m$ most significant digits
of probabilities $\pk = \rfrac{\bfZ{k}{1,n}}{\fullZ}$ \rule[-1.5ex]{0pt}{0pt} \\
{\sc Input:} & RNA sequence $\seq = \seqN$, secondary
structure \strSt of \seq, integer $m$ \rule[-1.5ex]{0pt}{0pt} \\
{\sc Output:} & Probabilities $\pk = \rfrac{\bfZ{k}{1,n}}{\fullZ}$ to $m$ significant digits for $k=0,\dots,n-1$ \rule[-1.75em]{0pt}{0pt} \\
\hline \rule[0ex]{0pt}{0pt}
\end{tabular*}
\begin{algorithmic}[1]
\Function{FFTbor}{\seq, \strSt, $m$}
\State $n \gets \textit{length}(\seq)$
\For{$k \gets 0, n-1$}
\Comment{Compute all \nRoUs}
\State $\omega_k \gets \exp(\frac{2 \pi i k}{n})$
\EndFor
\For{$k \gets 0, n-1$}
\Comment{Note that $\emZof{}{\omega_0} = \fullZ$}
\State $y_k \gets 10^m \cdot \frac{\emZof{}{\omega_k}}{\emZof{}{\omega_0}}$
\EndFor
\For{$k \gets 0, n-1$}
\Comment{Compute IDFT from \eqnref{fftbor:aFromY}}
\State $a_k \gets \frac{1}{n} \sum_{j=0}^{n-1} y_j\, \omega^{-kj}$
\State $\pk \gets 10^{-m} \cdot \lfloor a_k \rfloor$
\Comment{Truncate to $m$ significant digits}
\EndFor
\State \textbf{return} $p_0,\dots,p_{n-1}$
\Comment{Return all \pk for $0 \leq k < n$,
from \eqnref{fftbor:probK}}
\EndFunction
\rule[-0.35ex]{0pt}{0pt}
\end{algorithmic}
\caption[Pseudocode for \fftbor]{The function {\sc FFTbor} computes the $m$ most significant digits
of $p_0,\dots,p_{n-1}$, where $\pk = \frac{\bfZ{k}{}}{\fullZ}$. This algorithm
operates in \On{4} time and \On{2} space, a significant improvement over its
predecessor \rnabor.}
\label{fig:fftbor:algo}
\rule[0ex]{0pt}{1.5em} \hrule
\end{figure}

\section{Benchmarking and performance considerations}
\label{sec:fftbor:benchmarking}

In this subsection, we show that we need only evaluate the polynomial
\fullZx, as defined in
\eqnref{fftbor:zOfX}, for $n/2$ of the \nRoUs.
 It is first necessary to recall the definition of complex
conjugate.
Recall that the complex conjugate of $z$ is denoted by $\overline{z}$;
i.e. if $z=\aPbi$ where $a,b \in \mathbb{R}$ are real numbers and
$i = \sqrt{-1}$,  then $\overline{z} = \aMbi$.

\begin{lemma}
\label{lem:fftbor:compconj}

If \fullZx is the complex polynomial defined in
\eqnref{fftbor:zOfX}, then for any \nRoU
 $\alpha$, it is the case that $\emZof{}{\overline{\alpha}} =
\overline{\emZof{}{\alpha}}$. In other words, if $\alpha$ is a \nRoU
 of the form \aPbi, where $a,b \in \mathbb{R}$ and $b>0$, and
if $\emZof{}{\aPbi} = A + Bi$ where $A,B \in \mathbb{R}$, then it is the case that

\begin{align}
\emZof{}{\aMbi} = A - Bi.
\end{align}

This comes from the well known fact that
$\emZof{}{\overline{\alpha}} = \overline{\emZof{}{\alpha}}$
for any polynomial with real coefficients.
\end{lemma}

Lemma \ref{lem:fftbor:compconj} immediately entails that we need only to evaluate \fullZx on $n/2$
many of the \nRoUs---namely, those of the form
\aPbi, where $b \geq 0$. The remaining values of \fullZx are obtained by
taking conplex conjugates of the first $n/2$ values. This, along with a
precomputation of powers of the \nRoUs, leads to an
enormous performance speed-up in our implementation of \fftbor.

\section{Coarse-grained kinetics with \fftbor}
\label{sec:fftbor:kinetics}

The output of \fftbor, as shown in
\Figref{fftbor:tppDistributions}, is a probability distribution,
where the $x$-axis represents the \bpd from an arbitrary,
but fixed secondary structure \strSt, and the $y$-axis represents the
Boltzmann probability $p(k) = \frac{\bfZ{k}{}}{\fullZ}$ that a secondary structure
has \bpd $k$ from \strSt. Arguably, this probability distribution
is an accurate one-dimensional projection of the rugged, high dimensional energy
landscape near structure \strSt,
of the sort artistically rendered in the well-known
energy landscape depicted in Figure 1 of \citep{wolynes.ptam05}.
A hypothesis behind theoretical work in biomolecular folding theory in
\citep{bryngelson.p95}
is that kinetic folding slows down as the energy landscape becomes more
{\em rugged}. This is borne out in our computational experiments for RNA
using \fftbor, as reported
in \Figref{fftbor:tppDistributions}.

We randomly chose two TPP \rb
aptamers from the seed alignment for
Rfam family RF$00059$. The first sequence from {\em B. bacteriovorus} has EMBL accession code
BX$842649.1$ $277414$--$277318$ and is composed of the $97$ nt sequence
\seqsplit{%
  ACCUGACGCUAGGGGUGUUGGUGAAUUCACCGACUGAGAAUAACCCUUU%
  GAACCUGAUAGAGAUAAUGCUCGCGCAGGGAAGCAAGAAUAGAAAGAU%
}. The second sequence from the marine metagenome has
EMBL accession code AACY$022101973.1$ $389$--$487$ and is composed of the $99$
nt sequence
\seqsplit{%
  UAUAAGUCCAAGGGGUGCCAAUUGGCUGAGAUGGUUUUAACCAAUCCCUU%
  UGAACCUGAUCCGGUUAAUACCGGCGUAGGAAUGGAUUUUCUCUACAGC%
}.
Rfam consensus and \mfess for both sequences are
depicted in \Figref{fftbor:tppConsensusAndMfe}.
Despite the fact that there is no sequence similarity according to
pairwise BLAST \citep{blast}, this figure clearly demonstrates that
consensus and
\mfess closely resemble each other, and that the
structures of both TPP \rb aptamers are quite similar, with the
exception of the leftmost hairpin loop [resp. multiloop].
The MFE structures differ
from the consensus structures principally by the addition of base pairs not
determined by covariation in the Rfam alignment.
Indeed, if we let $\str_0,\,\str_1$
denote the Rfam consensus structure [resp. MFE structure] for the $97$ nt
sequence with EMBL accession code BX$842649.1$ $277414$--$277318$, then
$\str_0 \setminus \str_1$ has $4$ base pairs, and $\str_1 \setminus \str_0$
 has $7$
base pairs. If we let $\strT_0,\,\strT_1$
denote the Rfam consensus structure [resp. MFE structure] for the $99$ nt
sequence with EMBL accession code
AACY$022101973.1$ $389$--$487$, then
$\strT_0 \setminus \strT_1$ has $1$ base pair, and $\strT_1 \setminus \strT_0$ has $5$
base pairs.

\begin{figure}[!ht]
\centering
\includegraphics[width=.9\textwidth]{Figures/FFTbor/tppConsensusAndMfe.pdf}
\caption[Rfam consensus structures (Rfam) and \mfe (MFE)
secondary structures for two thiamine pyrophosphate (TPP) \rb aptamers]{Rfam consensus structures (Rfam) and \mfe (MFE)
secondary structures for two thiamine pyrophosphate (TPP) \rb aptamers,
chosen at random from RF$00059$ Rfam family seed alignment
\citep{Gardner.nar11}. Using pairwise BLAST \citep{blast}, there is no
sequence similarity, although the secondary structures are very similar,
as shown in this figure. From left to right:
{\em (A)} MFE structure for BX$842649.1$ $277414$--$277318$.
{\em (B)} Rfam consensus structure for BX$842649.1$ $277414$--$277318$.
{\em (C)} MFE structure for AACY$022101973.1$ $389$--$487$.
{\em (D)} Rfam consensus structure for AACY$022101973.1$ $389$--$487$.
}
\label{fig:fftbor:tppConsensusAndMfe}
\end{figure}

We ran \fftbor on each of the TPP \rb aptamer
sequences, with the MFE structure of each
sequence taken as the initial structure \strSt for that sequence. For the
first sequence, BX$842649.1$ $277414$--$277318$, the \fftbor output
suggests that there are low energy structures
at a distance from the MFE structure, which might compete with the MFE
structure and hence slow the kinetics of folding. In contrast, for the
second sequence, AACY$022101973.1$ $389$--$487$, the \fftbor output suggests
that there are no such competing low energy structures, hence
the second sequence should fold more quickly than the first.

\begin{figure}[!ht]
\centering
\includegraphics[width=.45\textwidth]{Figures/FFTbor/FFTbor_BX842649_1.pdf}
\quad
\includegraphics[width=.45\textwidth]{Figures/FFTbor/FFTbor_AACY022101973_1.pdf}
\caption[Output from \fftbor on two randomly selected
thiamine pyrophosphate \rb (TPP) aptamers]{Output from \fftbor on two randomly selected
thiamine pyrophosphate \rb (TPP) aptamers, taken from the Rfam database
\citep{Gardner.nar11}. The $x$-axis represents \bpd from the
\mfes for each given sequence; the $y$-axis represents
Boltzmann probabilities $p(k) = \frac{\bfZ{k}{}}{\fullZ}$, where
\bfZ{k}{} denotes the sum of Boltzmann factors or all secondary structures,
whose \bpd from the MFE structure is exactly $k$.
{\em (Left)}
The $97$ nt sequence BX$842649.1$ $277414$--$277318$ appears to have a rugged energy
landscape near its \mfes, with distinct
low energy structures that may compete with the MFE structure during the
folding process.
{\em (Right)}
The $99$ nt sequence, AACY$022101973.1$ $389$--$487$ appears to have a smooth energy
landscape near its MFE structure, with no distinct low energy structures
to might compete with the MFE structure.
Based on the \fftbor output or {\em structural profile} near MFE
structure \strSt, one might expect
folding time for the first sequence to increase due to competition from
metastable structures, while one might expect the second sequence to have
rapid folding time.
Computational Monte Carlo folding experiments bear out this fact.
\kinfold \citep{flamm} simulations clearly show that the second
sequence folds
at least four times more quickly than the first sequence. See section
\ref{sec:fftbor:kinetics} for
details.}
\label{fig:fftbor:tppDistributions}
\end{figure}

To test the hypothesis that folding is slower for rugged energy landscapes,
we ran the kinetic folding software, \kinfold \citep{flamm},
on each of the two TPP \rb aptamer sequences,
BX$842649.1$ $277414$--$277318$ and AACY$022101973.1$ $389$--$487$,
to determine the \mfpt (MFPT) to
fold into the MFE structure, when starting from the empty structure.
In this computational
experiment, we took MFPT to be the average number of Monte Carlo steps
taken by \kinfold---each step consisting of the addition or removal
of a single base pair---to fold the
empty structure into the MFE
structure, where the average was taken over $30$ runs, with an absolute
maximum number of Monte Carlo steps taken to be $500,000$.
The first sequence, BX$842649.1$ $277414$--$277318$, converged within $500,000$
steps only for $20$ out of $30$ runs. Assigning the maximum step count of
$500,000$ for the $10$ runs that did not converge, we found a \mfpt
of $311,075.06$ steps for this sequence.
The second sequence, AACY$022101973.1$ $389$--$487$, converged within $500,000$
steps in $29$ out of $30$ runs, and we found a \mfpt of
$61,575.69$ steps for this sequence. From computational experiments of this
type, it is suggestive that \fftbor may prove useful in synthetic
biology,
where one would like to design rapidly folding RNA molecules that
fold into a designated target structure.

In order to more systematically determine the relation between kinetic
folding speed and the ruggedness of an energy landscape near the MFE structure,
we need to numerically quantify ruggedness. To this end, in the following
we define the notion of \ebpd to a designated
structure. Let \strSt be an arbitrary secondary structure of the RNA sequence
$\seq = \seqN$.
The expected \bpd to \strSt is defined by

\begin{align}
E[ \{ \dBP{\str}{\strSt} : \str \in \mathbb{S}(\seqN)\} ] =
\sum_{\str} P(\str) \cdot \dBP{\str}{\strSt}
\end{align}

where
$\mathbb{S}(\seqN)$ denotes the set of secondary structures for
$\seq = \seqN$, $P(\str) = \frac{\boltzf{\str}}{\fullZ}$ is the Boltzmann
probability of \str, and
\dBP{\str}{\strSt} denotes \bpd between \str and \strSt.
If we run \fftbor on an input sequence \seq and secondary structure
\strSt, then clearly
$E[ \{ \dBP{\str}{\strSt} : \str \in \mathbb{S}(\seqN)\} ] =
\sum_{k} k \cdot p(k)$, where $p(k)=\frac{\bfZ{k}{}}{\fullZ}$, obtained from the
program output.  If \strSt is the empty structure, then \fftbor output
is simply the probability distribution of the number of base pairs per
secondary structure, taken over the Boltzmann ensemble of all structures.

For the benchmarking assay, we took all $61$ selenocysteine insertion sequence
(SECIS) sequences from the seed alignment of Rfam family RF$00031$
\citep{Gardner.nar11}. Average length was $64.32 \pm 2.83$ nt.
For each sequence, we ran both \fftbor (when starting
from the empty structure rather than the MFE structure) and a Monte Carlo
folding algorithm, developed by E. Freyhult and P. Clote (unpublished).
Using the Monte Carlo algorithm, we
determined the \mfpt (MFPT), defined as the average
taken over $50$ runs, of the number of Monte Carlo steps taken to fold
the empty structure into the MFE structure, where an absolute upper bound
of $5$ million steps was allowed in the simulation.

Surprisingly, we found that there is a significant
correlation of $0.4847$ with one-tailed
$p$-value of $0.0002$ between the
standard deviation of the \fftbor output (when starting from the
empty structure) and logarithm base $10$ of the \mfpt.
As described above, \fftbor output is simply
the probability distribution
for the number of base pairs per structure, taken over the ensemble
of all secondary structure for the input RNA
sequence. The standard deviation of this probability distribution corresponds
to a notion of the width of the distribution. It is possible that those
sequences having distributions tightly centered around the
mean have faster folding times than those with a wider distribution
due to other local minima causing the RNA to get trapped while folding.
\medskip

\begin{table}[!ht]
\centering
\begin{tabularx}{\linewidth}{c *{6}{R}}
  \toprule
  ~ & \small{$\mu$} & \small{$\sigma$} & \small{$\rfrac{\sigma}{\mu}$} & \small{$n$} & \small{MFE} & \small{$\log_{10}(\text{MFPT})$} \\
  \cmidrule(l){2-7}
  \small{$\mu$} & $1$ & & & & \\
  \small{$\sigma$} & $-0.4372$ & $1$ & & & \\
  \small{$\rfrac{\sigma}{\mu}$} & $-0.6914$ & $0.9437$ & $1$ & & & \\
  \small{$n$} & $0.7077$ & $-0.1590$ & $-0.3646$ & $1$ & &  \\
  \small{MFE} & $-0.5695$ & $0.7395$ & $0.7596$ & $-0.3685$ & $1$ & \\
  \small{$\log_{10}(\text{MFPT})$} & $-0.0363$ & $0.4844$ & $0.3762$ & $0.4059$ & $0.3990$ & $1$ \\
  % puts data.chomp.split(/\\/).map { |line| line.split("&")[1..-1].map { |item| item.gsub(/\s+/, "") }.reject { |item| item.empty? }.map { |number| "%.4f" % number.to_f }.join(" & ") + " \\\\" }.join(?\n)
  \bottomrule
\end{tabularx}
\caption[Pearson correlation between various aspects of selenocysteine
insertion sequences from the seed alignment of Rfam family
RF$00031$]{\small Pearson correlation between various aspects of selenocysteine
insertion sequences from the seed alignment of Rfam family
RF$00031$ \citep{Gardner.nar11}.
For each of the $61$ RNA sequences, we ran \fftbor, starting
from empty initial structure \strSt, and we ran a Monte Carlo
folding algorithm, developed by E. Freyhult and P. Clote (unpublished).
Using the Monte Carlo algorithm, we
determined the \mfpt (MFPT), defined as the average
taken over $50$ runs, of the number of Monte Carlo steps taken to fold
the empty structure into the MFE structure, where an absolute upper bound
of $5$ million steps was allowed in the simulation.  From the output of
\fftbor, we computed
{\em 1})\, the mean number ($\mu$) of base pairs per structure, taken over
the ensemble of all secondary structures for the given sequence;
{\em 2})\, the standard deviation ($\sigma$) of the number of base pairs per
structure;
{\em 3})\, the coefficient of variation $\frac{\sigma}{\mu}$;
{\em 4})\, the RNA sequence length $n$; and
{\em 5})\, the \mfe (MFE).
Additionally, we computed the logarithm base $10$ of \mfpt
($\log_{10}(\text{MFPT})$), taken over $50$ Monte Carlo runs per sequence
(log base $10$ of the standard deviation of number of Monte Carlo
steps per run was approximately
9\% of $\log_{10}(\text{MFPT})$ on average). The table shows the correlation between each of these aspects.
Some correlations are obvious---for example,
{\em i})\;
the standard deviation $\sigma$ is highly correlated with the
coefficient of variation $\frac{\sigma}{\mu}$;
{\em ii})\;
the mean $\mu$ is negatively correlated with the
coefficient of variation $\frac{\sigma}{\mu}$;
{\em iii})\;
the mean $\mu$ is negatively correlated with the
\mfe (MFE) --- if most low energy structures in the ensemble
have many base pairs, then it is likely that the \mfe is very
low (i.e. since MFE is negative, the absolute value of MFE increases); and
{\em iv})\;
sequence length is negatively correlated with MFE --- as sequence length
increases, the \mfe (MFE) decreases.
However, it may appear surprising that
{\em v})\; the
mean $\mu$ number of base pairs per structure is independent of MFPT
(correlation $-0.0363$), although
{\em vi})\; MFE is correlated with MFPT
(correlation $0.3990$) --- i.e. from {\em (iii)},
lower MFE is correlated with a larger average $\mu$ number of base pairs per
structure, from ({\em vi})
higher MFE is correlated with longer folding time, but
from ({\em v}) the average $\mu$  number of base pairs per structure is
independent of folding time.
The most important insight from this table is that
{\em vii})\;
standard deviation $\sigma$ is correlated with \mfpt---the correlation is statistically significant, with one-tailed
$p$-value of $0.0002$.}
\label{table:correlationFFTborEmpty}
\end{table}

\begin{figure}[!ht]
\centering
\includegraphics[width=.3\textwidth]{Figures/FFTbor/AB030643_1_4176-4241.pdf}
\includegraphics[width=.3\textwidth]{Figures/FFTbor/AL645723_11_192421-192359.pdf}
\includegraphics[width=.3\textwidth]{Figures/FFTbor/FFTborOutputFromEmptyStrForTPPriboswitches.pdf}
\caption[Example of the graphical output of \fftbor, when the empty structure is chosen as initial structure \strSt]{This figure represents the
graphical output of \fftbor, when the empty structure is chosen as
initial structure \strSt.
The $x$-axis represents the number of base pairs per structure,
taken over the ensemble of all secondary structures for the given RNA
sequence; the $y$-axis represents Boltzmann probability
$p(k) = \frac{\bfZ{k}{}}{\fullZ}$,
where \fullZ is the partition function for all secondary structures
having exactly $k$ base pairs.
{\em (Left)}
For the {\em M. musculus} selenocysteine (SECIS) element AB$030643.1$ $4176$--$4241$ from Rfam family
RF$00031$, the standard deviation $\sigma$ of the number of base pairs,
taken over the ensemble of all secondary structures, is
$0.7276$, while the logarithm base $10$ of the \mfpt ($\log_{10}(\text{MFPT})$)
is $4.75$.
{\em (Center)}
For the {\em M. musculus} selenocysteine (SECIS) element
AL$645723.11$ $192421$--$192359$ from Rfam family
RF$00031$, the standard deviation $\sigma$ of the number of base pairs,
taken over the ensemble of all secondary structures, is
$2.6794$, while $\log_{10}(\text{MFPT})$ is $5.69$.
Among the $61$ sequences in the seed alignment of RF$00031$,
AB$030643.1$ $4176$--$4241$ was the fastest folder, while
AL$645723.11$ $192421$--$192359$ was the slowest folder.
{\em (Right)}
Superimposition of output of \fftbor for two TPP \rb aptamers: the
$97$ nt sequence BX$842649.1$ $277414$--$277318$ from {\em B. bacteriovorus} and the
$99$ nt sequence AACY$022101973.1$ $389$--$487$ from the marine metagenome, both obtained when
taking the empty structure for the initial structure \strSt.
The mean $\mu$ for the \fftbor structural profile near the empty
structure is $23.0203$  [resp. $27.5821$], the
standard deviation $\sigma$ for the \fftbor structural profile
is $2.2253$  [resp. $1.9857$], and the \kinfold MFPT is
$311,075.06$ [resp. $61,575.69$] for the TPP \rb aptamer
BX$842649.1$ $277414$--$277318$ [resp. AACY$022101973.1$ $389$--$487$].
The right panel of this figure should be compared with Figure
\ref{fig:fftbor:tppDistributions}.
These anecdotal results bear up the correlation between standard deviation
$\sigma$ and $\log_{10}(\text{MFPT})$ described in Table \ref{table:correlationFFTborEmpty}.
}
\label{fig:fftbor:correlationFFTborEmpty}
\end{figure}

In the right panel of \Figref{fftbor:correlationFFTborEmpty}, we
applied \fftbor to each of the two randomly chosen TPP \rb
aptamers BX$842649.1$ $277414$--$277318$ from {\em B. bacteriovorus}
and AACY$022101973.1$ $389$--$487$ from the marine metagenome, starting
from the empty reference structure $\strSt=\varnothing$.
The mean for the \fftbor structural profile near the empty
structure is $\mu_1=23.0203$  [resp. $\mu_2=27.5821$], the
standard deviation $\sigma$ for the \fftbor structural profile
is $\sigma_1=2.2253$  [resp. $\sigma_2=1.9857$], and the \kinfold MFPT is
$311,075.06$ [resp. $61,575.69$] for the TPP \rb aptamer
BX$842649.1$ $277414$--$277318$ [resp. AACY$022101973.1$ $389$--$487$]. This
anecdotal evidence supports the hypothesis that small standard deviation
in \fftbor distribution is correlated with fast folding.

We randomized the TPP \rbs BX$842649.1$ $277414$--$277318$ and
AACY$022101973.1$ $389$--$487$ by using our implementation of the
Altschul-Erikson dinucleotide shuffle algorithm
\citep{altschulErikson:dinucleotideShuffle}, and then applied \fftbor to these
sequences, starting from the empty structure.  The mean $\mu_1$ and standard
deviation $\sigma_1$ for the \fftbor distribution for randomized BX$842649.1$ are
respectively $\mu_1=19.93$ and $\sigma_1=2.88$, while those for randomized
AACY$022101973.1$ are $\mu_2=24.39$ and $\sigma_2=24.00$. Running \kinfold, with a
maximum of $500,000$ steps with $30$ replicates (as explained in the text), we
found
that for randomized BX$842649$, all $30$ runs converged yielding a \mfpt
(MFPT) of $13,022.58$ with standard deviation of $15,221.78$. In contrast for
randomized AACY$022101973.1$, only $15$ out of $30$ runs converged within $500,000$ steps,
and discounting these nonconvergent data, we obtain an average \mfpt
(MFPT) of $94,446.93$ with standard deviation of $157,107.43$. This additional
test provides more anecdotal evidence supporting our hypothesis that small
standard deviation $\sigma$ in \fftbor probability density is correlated with fast folding, as measured by MFPT.

This notion of correlation between the coarse-grained energy landscape and
kinetics is what motivates the work described in Chapters \ref{ch:ffttwo}
and \ref{ch:hermes}, where a more detailed explanation of kinetics is provided,
and additional evidence is provided to support this claim.

\section{Performance characteristics of \fftbor and \rnabor}
\label{sec:fftbor:speed}

As visible from the defining recursions, the algorithmic time complexity of
\rnabor is \On{5} and space complexity is \On{3}, where $n$ is
the length of input RNA sequence. In contrast, the time complexity of
\fftbor is \On{4} and space complexity is \On{2}.
While \fftbor saves an order of magnitude in performance and memory,
\rnabor has the benefit of producing suboptimal structures $\text{MFE}_k$
for all $0 \leq k \leq n$, whose free energy is minimal across all structures
having \bpd $k$ from input structures \strSt.
\Figref{fftbor:benchmarking} displays run time curves for both
\rnabor and \fftbor, when the initial structure \strSt is
taken to be either the empty structure or the \mfe
(MFE) structure.

Here, we compare the run time of \rnabor \citep{freyhult.b07} and
the (unparallelized version of) \fftbor, using
a Dell Power Edge $1950$, $2$ x Intel Xeon E$5430$ Quad
core with $2.80$ GHz and $16$ GB RAM. For $n = 20,40,60,\dots,300$, in step
size of $20$ nt, we generated $n$ random RNA sequences of length $n$ with equal
probability for each nucleotide A,C,G,U (i.e. a 0th order Markov chain).
For values of $n \leq 200$, $100$ random sequences of length
$n$ were generated, while for values of $220 \leq n \leq 300$, only
$10$ sequences of length $n$ were generated.
RNA sequences larger than $300$ nt were not tested,
due to \On{3} memory constraints required by \rnabor.
For each RNA sequence, \rnabor and \fftbor were both run,
each starting with empty initial structure \strSt, and also
with initial sequence \strSt taken to be the MFE structure.
Each data point in the table comprises the average run time for three
independent evaluations.

\begin{figure}[!ht]
\centering
\includegraphics[width=.9\textwidth]{Figures/FFTbor/rnaborfftborRunTimeEvan.pdf}
\caption[Run times in seconds for \rnabor and \fftbor, on random RNA
of length $20$--$300$ in step size of $20$ nt]{Run times in seconds for \rnabor and \fftbor, on random RNA
of length $20,40,60,\dots,300$ in step size of $20$ nt. Each algorithm
was run with the empty initial structure \strSt, see rows
\rnabor (empty), \fftbor (empty), and with the \mfes as the initial structure
\strSt, see rows
\rnabor (MFE) and \fftbor (MFE). Note that for both \rnabor
and \fftbor, the run time increases when \strSt is the MFE structure,
rather than the empty structure. Notice the radical improvement in the
run time of \fftbor over that of \rnabor.
}
\label{fig:fftbor:benchmarking}
\end{figure}

\subsection{OpenMP parallelization of \fftbor}
\label{subsec:fftbor:openmp}

OpenMP is a simple and flexible
multi-platform shared-memory parallel programming environment, that supports
parallelizations of C/C++ code---see \url{http://openmp.org/}.
Using OpenMP primitives, we created multiple threads to evaluate the polynomial
\fullZx on different \nRoUs. \Figref{fftbor:benchmarkingParallel}
presents benchmarks, executed on
a $24$-core AMD Opteron $6172$ with $2.10$GHz and $64$GB RAM, for the speedup
of \fftbor as a function of the number of cores.
The data in Table \ref{table:fftborBenchmarkingParallel} describes average
run time in seconds ($\pm$ one standard deviation) for running \fftbor
on random RNA of length $200,250,300,400,450,500$ with either $1$ or $2$ cores.
\Figref{fftbor:benchmarkingParallel}
presents similar data for running
\fftbor on $2,3,6,4,12,15,20$ cores.
\medskip

\begin{table}[!ht]
\centering
\begin{tabularx}{\linewidth}{c *{2}{R}}
\toprule
\small{$n$} & \small{Single core} & \small{Two cores} \\
\cmidrule(lr){1-3}
$200$ & $123.2 \pm 16.2$ & $61.8 \pm 8.0$ \\
$250$ & $331.1 \pm 27.2$ & $166.1 \pm 13.7$ \\
$300$ & $723.4 \pm 59.9$ & $365.2 \pm 30.1$ \\
$350$ & $1,380.8 \pm 95.2$ & $698.4 \pm 46.9$ \\
$400$ & $2,239.1 \pm 210.9$ & $1,129.5 \pm 104.3$ \\
$450$ & $3,635.0 \pm 857.4$ & $1,980.9 \pm 126.5$ \\
$500$ & $5,076.7 \pm 1,292.1$ & $3,389.8 \pm 788.4$ \\
\bottomrule
\end{tabularx}
\caption[Table showing parallel run times in seconds
for \fftbor, using OpenMP]{Table showing parallel run times in seconds
for \fftbor, using OpenMP---\url{http://openmp.org/}.
For each sequence length $200,\dots,500$,
five random RNAs were generated using equal probability for each nucleotide
A,C,G,U. Run time in seconds, plus or minus one standard deviation, are
given for a $24$-core
AMD Opteron $6172$ running at $2.10$GHz with $64$GB RAM, with only $1$ [resp. $2$] cores
used.}
\label{table:fftborBenchmarkingParallel}
\end{table}

\begin{figure}[!ht]
\centering
\includegraphics[width=.75\textwidth]{Figures/FFTbor/fftborParallelRunTimes.pdf}
\caption[]{Graph showing parallel run time of \fftbor as a function of
sequence length, running on an AMD Opteron $6172$ running at $2.10$GHz with $64$GB RAM,
using respectively $1,2,3,4,6,9,12,15,20$ cores.
}
\label{fig:fftbor:benchmarkingParallel}
\end{figure}


\paragraph{}
In order to speed up the testing of the program, some basic test scenarios have been defined in order to provide a known system that can be loaded into the application during testing in order to speed up the testing process.
\vspace{12pt}
\begin{enumerate}
\item \textbf{(Ref: TS1)} Single Body with no velocity.
  \begin{itemize}
  \item Should stay completely stationary.
  \item \textbf{IDT:} 0.1 (Simulation Delta Time)
  \item \textbf{UGC:} 0.1 (Gravitational Constant)
  \item \textbf{BC:} 1 (Body Count)
    \begin{itemize}
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} 0 \textbf{Y:} 0, \textbf{Vel X:} 0 \textbf{Y:} 0
    \end{itemize}
  \end{itemize}

\vspace{12pt}
\item \textbf{(Ref: TS2)} Two body orbital system, orbital velocity.
  \begin{itemize}
  \item Outer body has the velocity required for a circular orbit around the central body.
  \item This is calculated using $v_{circular}=\sqrt{\frac{G(M+m)}{r}}$.
  \item Orbital period can be found using $T=\sqrt{\frac{4\pi^2r^3}{Gm}}$.
  \item It should take $628.3$ seconds or $6283$ Iterations to complete one orbit. ($T/IDT$)
  \item \textbf{IDT:} 0.1
  \item \textbf{UGC:} 0.1
  \item \textbf{BC:} 2
    \begin{itemize}
    \item \textbf{Mass:} 1000, \textbf{Radius:} 10, \textbf{Pos X:} 0 \textbf{Y:} 0, \textbf{Vel X:} 0 \textbf{Y:} 0
    \item \textbf{Mass:} 0.1, \textbf{Radius:} 1, \textbf{Pos X:} 100 \textbf{Y:} 0, \textbf{Vel X:} 0 \textbf{Y:} 1.00005
    \end{itemize}
  \end{itemize}

\vspace{12pt}
\item \textbf{(Ref: TS3)} Two body collision test, no gravity.
  \begin{itemize}
  \item Both bodies start with velocity which will lead to a collision.
  \item Gravitational constant is 0 to keep the velocity constant.
  \item Bodies merge according to $p=mv$, $m_n=m_1+m_2$, $v_n=(p_1+p_2)/m_n$.
  \item New radius is calculated by adding together circular areas $\pi r^2$.
  \item \textbf{IDT:} 0.1
  \item \textbf{UGC:} 0.0
  \item \textbf{BC:} 2
    \begin{itemize}
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} -10 \textbf{Y:} 0, \textbf{Vel X:} 1 \textbf{Y:} 0
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} 10 \textbf{Y:} 0, \textbf{Vel X:} -1 \textbf{Y:} 0
    \end{itemize}
  \end{itemize}

\vspace{12pt}
\item \textbf{(Ref: TS4)} Defines a superstructure.
  \begin{itemize}
  \item Starts the simulation with a superstructure, variable body count.
  \item Relies on a separate variable to set body count.
  \item \textbf{IDT:} 0.1
  \item \textbf{UGC:} 0.1
  \item \textbf{BC:} Variable
    \begin{itemize}
    \item \textbf{Superstructure}
      \begin{itemize}
      \item \textbf{Bodies:} Variable
      \item \textbf{Central Mass:} $\num{1e5}$
      \item \textbf{Outer Mass:} 0.1
      \item \textbf{Central Radius:} 10
      \item \textbf{Outer Radius:} 0.1
      \item \textbf{Central Pos X:} 0
      \item \textbf{Central Pos Y:} 0
      \item \textbf{Central Vel X:} 0
      \item \textbf{Central Vel Y:} 0
      \item \textbf{Central Spacing:} 50
      \item \textbf{System Radius:} 1000
      \end{itemize}
    \end{itemize}
  \end{itemize}

\vspace{12pt}
\item \textbf{(Ref: TS5)} Body travels beyond simulation limits.
  \begin{itemize}
  \item Should be destroyed once beyond simulation bounds.
  \item \textbf{IDT:} 0.1 (Simulation Delta Time)
  \item \textbf{UGC:} 0.1 (Gravitational Constant)
  \item \textbf{BC:} 1 (Body Count)
    \begin{itemize}
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} $\num{9.999e15}$ \textbf{Y:} 0, \textbf{Vel X:} $\num{1e8}$ \textbf{Y:} 0
    \end{itemize}
  \end{itemize}

\vspace{12pt}
\item \textbf{(Ref: TS6)} Body travelling faster than the speed of light.
  \begin{itemize}
  \item Should be destroyed on iteration.
  \item \textbf{IDT:} 0.1
  \item \textbf{UGC:} 0.1
  \item \textbf{BC:} 1
    \begin{itemize}
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} 0 \textbf{Y:} 0, \textbf{Vel X:} $\num{3.00e8}$ \textbf{Y:} 0
    \end{itemize}
  \end{itemize}

\pagebreak
\item \textbf{(Ref: TS7)} Grid of bodies for testing coordinate mapping and rendering precision.
  \begin{itemize}
  \item All bodies are fixed, velocity is ignored and not calculated.
  \item Bodies in center are positioned at 10 and 100 positions respectively.
  \item To the right of the system exists 4 bodies spaced an order of magnitude apart in order to show the loss of rendering precision.
  \item \textbf{IDT:} 0.1
  \item \textbf{UGC:} 0.1
  \item \textbf{BC:} 20
    \begin{itemize}
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} 10 \textbf{Y:} 0
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} -10 \textbf{Y:} 0
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} 0 \textbf{Y:} 10
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} 0 \textbf{Y:} -10
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} -10 \textbf{Y:} -10
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} 10 \textbf{Y:} -10
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} -10 \textbf{Y:} 10
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} 10 \textbf{Y:} 10
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} 100 \textbf{Y:} 0
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} -100 \textbf{Y:} 0
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} 0 \textbf{Y:} 100
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} 0 \textbf{Y:} -100
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} -100 \textbf{Y:} -100
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} 100 \textbf{Y:} -100
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} -100 \textbf{Y:} 100
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} 100 \textbf{Y:} 100
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} $\num{1e5}$ \textbf{Y:} 0
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} $\num{1e6}$ \textbf{Y:} 0
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} $\num{1e7}$ \textbf{Y:} 0
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 1, \textbf{Pos X:} $\num{1e8}$ \textbf{Y:} 0
    \end{itemize}
  \end{itemize}

\pagebreak
\item \textbf{(Ref: TS8)} Three body system, Sun - Planet - Moon.
  \begin{itemize}
  \item An outer body orbits a massive central body.
  \item Another body orbits the outer body.
  \item \textbf{IDT:} 0.1
  \item \textbf{UGC:} 0.1
  \item \textbf{BC:} 3
    \begin{itemize}
    \item \textbf{Mass:} 200, \textbf{Radius:} 5, \textbf{Pos X:} 0 \textbf{Y:} 0, \textbf{Vel X:} 0 \textbf{Y:} 0
    \item \textbf{Mass:} 1, \textbf{Radius:} 0.5, \textbf{Pos X:} 20 \textbf{Y:} 0, \textbf{Vel X:} 0 \textbf{Y:} 1.00005
    \item \textbf{Mass:} 0.001, \textbf{Radius:} 0.1, \textbf{Pos X:} 20 \textbf{Y:} 1, \textbf{Vel X:} 0.316 \textbf{Y:} 1.00005
    \end{itemize}
  \end{itemize}

\vspace{12pt}
\item \textbf{(Ref: TS9)} Simple two body system.
  \begin{itemize}
  \item This system is simple enough to be easy to create a trace table for.
  \item The central body is fixed, making it much faster to run calculations.
  \item A large time-step is used in order to make the numbers easier to handle.
  \item \textbf{IDT:} 2
  \item \textbf{UGC:} 0.1
  \item \textbf{BC:} 2
    \begin{itemize}
    \item \textbf{Mass:} 99, \textbf{Radius:} 1, \textbf{Pos X:} 0 \textbf{Y:} 0, \textbf{Fixed}
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} 10 \textbf{Y:} 0, \textbf{Vel X:} 0 \textbf{Y:} 1
    \end{itemize}
  \end{itemize}

\pagebreak
\item \textbf{(Ref: TS10)} Defines a simple two body system using a superstructure.
  \begin{itemize}
  \item Creates a superstructure with the generation of a single body constrained to 100.
  \item \textbf{IDT:} 0.1
  \item \textbf{UGC:} 0.1
  \item \textbf{BC:} 2
    \begin{itemize}
    \item \textbf{Superstructure}
      \begin{itemize}
      \item \textbf{Bodies:} 1
      \item \textbf{Central Mass:} $\num{1e5}$
      \item \textbf{Outer Mass:} 0.1
      \item \textbf{Central Radius:} 10
      \item \textbf{Outer Radius:} 0.1
      \item \textbf{Central Pos X:} 0
      \item \textbf{Central Pos Y:} 0
      \item \textbf{Central Vel X:} 0
      \item \textbf{Central Vel Y:} 0
      \item \textbf{Central Spacing:} 100.0
      \item \textbf{System Radius:} 100.001
      \end{itemize}
    \end{itemize}
  \end{itemize}

\vspace{12pt}
\item (Ref: TS11) Stable three body system.
  \begin{itemize}
  \item This system is a three-body system which remains stable. (Unless perturbed.)
  \item The outer bodies have velocity such that they precess around each other.
  \item Their presence applies an equal force to both sides of the central body, thus balancing to 0.
  \item Any change will send the system into chaotic motion.
  \item \textbf{IDT:} 0.01
  \item \textbf{UGC:} 0.1
  \item \textbf{BC:} 3
    \begin{itemize}
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} 0 \textbf{Y:} 0, \textbf{Vel X:} 0 \textbf{Y:} 0
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} 10 \textbf{Y:} 0, \textbf{Vel X:} 0 \textbf{Y:} 0.11
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} -10 \textbf{Y:} 0, \textbf{Vel X:} 0 \textbf{Y:} -0.11
    \end{itemize}
  \end{itemize}

\pagebreak
\item (Ref: TS12) Many Body System
  \begin{itemize}
  \item This system contains several bodies which will very clearly show the interactions occurring correctly between every body.
  \item \textbf{IDT:} 0.01
  \item \textbf{UGC:} 10
  \item \textbf{BC:} 6
    \begin{itemize}
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} 10 \textbf{Y:} 2, \textbf{Vel X:} 0 \textbf{Y:} 0
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} -4 \textbf{Y:} 4, \textbf{Vel X:} 0 \textbf{Y:} 0
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} -18 \textbf{Y:} 16, \textbf{Vel X:} 0 \textbf{Y:} 0
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} -8 \textbf{Y:} -12, \textbf{Vel X:} 0 \textbf{Y:} 0
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} 6 \textbf{Y:} -13, \textbf{Vel X:} 0 \textbf{Y:} 0
    \item \textbf{Mass:} 1, \textbf{Radius:} 1, \textbf{Pos X:} 8 \textbf{Y:} 11, \textbf{Vel X:} 0 \textbf{Y:} 0
    \end{itemize}
  \end{itemize}
\end{enumerate}


\section{Results}
\label{chp:study:sec:results}
In this chapter we present the results of the executed study which we base the later discussion upon.
Specifically, we state the calculated metrics of the two runs.

First we look at the metrics of the first run in which we use the crowdsourced dataset $D_{crowd}$.
Here all three models achieve mostly similar metrics when classifying $D_{crowd_{test}}$.
All metrics are listed in \cref{tab:study:results:first_run} for each model.
\begin{table}[htpb]
    \centering
    \begin{tabular}{l | l l l l }
        \toprule
         Model & Precision & Recall & $F_1$ Score & Average Precision \\
        \midrule
        \ac{BERT} & $0.36$ & $0.82$ & $0.51$ & $0.50$\\
        \ac{DistilBERT} & $0.31$ & $0.79$ & $0.45$ & $0.47$\\
        \ac{ERNIE2.0} & $0.48$ & $0.52$ & $0.50$ & $0.47$\\
        \bottomrule
    \end{tabular}
    \caption[Study Results on Crowdsourced Dataset]{The results for the crowdsourced dataset $D_{crowd_{test}}$.}\label{tab:study:results:first_run}
\end{table}

As we describe in \cref{chp:study:sec:execution}, we performed a second run similar to the first one.
The only difference is that the more extensive dataset $D_{all_{train}}$ was used for the training and $D_{all_{test}}$ to calculate the resulting metrics correspondingly.
The results of this second run are shown in \cref{tab:study:results:second_run}.
\begin{table}[htpb]
    \centering
    \begin{tabular}{l | l l l l }
        \toprule
         Model & Precision & Recall & $F_1$ Score & Average Precision \\
        \midrule
        \ac{BERT} & $0.45$ & $0.53$ & $0.48$ & $0.46$\\
        \ac{DistilBERT} & $0.33$ & $0.71$ & $0.48$ & $0.46$\\
        \ac{ERNIE2.0} & $0.35$ & $0.85$ & $0.50$ & $0.43$\\
        \bottomrule
    \end{tabular}
    \caption[Study Results on Complete Dataset]{The results for the dataset $D_{all_{test}}$.}\label{tab:study:results:second_run}
\end{table}


\section{Delegation}
\label{sec:delegation}

An agent owning a key that can sign new blocks can delegate its signing rights
to another key by means of \textit{delegation certificates}. These certificates
are included in the ledger, and therefore also included in the body of the
blocks in the blockchain.

There are several restrictions on a certificate posted on the blockchain:
\begin{enumerate}
\item Only genesis keys can delegate.
\item Certificates must be properly signed by the delegator.
\item Any given key can delegate at most once per-epoch.
\item Any given key can issue at most one certificate in a given slot.
\item The epochs in the certificates must refer to the current or to the next
  epoch. We do not want to allow certificates from past epochs so that a
  delegation certificate cannot be replayed. On the other hand if we allow
  certificates with arbitrary future epochs, then a malicious key can issue a
  delegation certificate per-slot, setting the epoch to a sufficiently large
  value. This will cause a blow up in the size of the ledger state since we
  will not be able to clean $\var{eks}$ (we only clean past epochs). Also note
  that we do not check the relation between the certificate epoch and the slot
  in which the certificate becomes active. This would bring additional
  complexity without any obvious benefit.
\item Certificates do not become active immediately, but they require a certain
  number of slots till they become stable in all the nodes.
\end{enumerate}
These conditions are formalized in \cref{fig:rules:delegation-scheduling}.
Rule~\ref{eq:rule:delegation-scheduling} determines when a certificate can
become ``scheduled''. The definitions used in these rules are presented in
\cref{fig:defs:delegation-scheduling}, and the types of the system induced by
$\trans{sdeleg}{\wcard}$ are presented in
\cref{fig:ts-types:delegation-scheduling}. Here and in the remaining rules we
will be using $k$ as an abstract constant that gives us the chain stability
parameter.

\begin{figure}[htb]
  \emph{Abstract types}
  \begin{equation*}
    \begin{array}{r@{~\in~}lr}
      c & \DCert & \text{delegation certificate}\\
      \var{vk_g} & \VKeyGen & \text{genesis verification key}\\
    \end{array}
  \end{equation*}

  \emph{Derived types}
  \begin{equation*}
    \begin{array}{r@{~\in~}l@{\qquad=\qquad}r@{~\in~}lr}
      \var{e} & \Epoch & n & \mathbb{N} & \text{epoch}\\
      \var{s} & \Slot & s & \mathbb{N} & \text{slot}\\
      \var{d} & \SlotCount & s & \mathbb{N} & \text{slot}
    \end{array}
  \end{equation*}

  \emph{Constraints}
  \begin{align*}
    \VKeyGen \subseteq \VKey
  \end{align*}

  \emph{Abstract functions}
  \begin{equation*}
    \begin{array}{r@{~\in~}lr}
      \fun{dbody} & \DCert \to (\VKey \times \Epoch)
      & \text{body of the delegation certificate}\\
      \fun{dwit} & \DCert \to (\VKeyGen \times \Sig)
      & \text{witness for the delegation certificate}\\
      \fun{dwho} & \DCert \mapsto (\VKeyGen \times \VKey)
      & \text{who delegates to whom in the certificate}\\
      \fun{depoch} & \DCert \mapsto \Epoch
      & \text{certificate epoch}\\
      \var{k} & \mathbb{N} & \text{chain stability parameter}
    \end{array}
  \end{equation*}
  \caption{Delegation scheduling definitions}
  \label{fig:defs:delegation-scheduling}
\end{figure}

\begin{figure}[htb]
  \emph{Delegation scheduling environments}
  \begin{equation*}
    \DSEnv =
    \left(
      \begin{array}{r@{~\in~}lr}
        \mathcal{K} & \powerset{\VKeyGen} & \text{allowed delegators}\\
        \var{e} & \Epoch & \text{epoch}\\
        \var{s} & \Slot & \text{slot}\\
      \end{array}
    \right)
  \end{equation*}

  \emph{Delegation scheduling states}
  \begin{equation*}
    \DSState
    = \left(
      \begin{array}{r@{~\in~}lr}
        \var{sds} & \seqof{(\Slot \times (\VKeyGen \times \VKey))} & \text{scheduled delegations}\\
        \var{eks} & \powerset{(\Epoch \times \VKeyGen)} & \text{key-epoch delegations}
      \end{array}
    \right)
  \end{equation*}

  \emph{Delegation scheduling transitions}
  \begin{equation*}
    \var{\_} \vdash
    \var{\_} \trans{sdeleg}{\_} \var{\_}
    \subseteq \powerset (\DSEnv \times \DSState \times \DCert \times \DSState)
  \end{equation*}
  \caption{Delegation scheduling transition-system types}
  \label{fig:ts-types:delegation-scheduling}
\end{figure}

\begin{figure}[htb]
  \begin{equation}
    \label{eq:sdeleg-bootstrap}
    \inference
    {
      \var{sds_0} \leteq \epsilon
      &
      \var{eks_0} \leteq \emptyset
    }
    {
      {\left(\begin{array}{l}
       \mathcal{K}\\
        e\\
        s
      \end{array}\right)}
      \vdash
      \trans{sdeleg}{}
      \left(
        \begin{array}{l}
          \var{sds_0}\\
          \var{eks_0}
        \end{array}
      \right)
    }
  \end{equation}
  \nextdef
  \begin{equation}
    \label{eq:rule:delegation-scheduling}
    \inference
    {
      (\var{vk_s},~ \sigma) \leteq \dwit{c}
      & \verify{vk_s}{\serialised{\dbody{c}}}{\sigma} & vk_s \in \mathcal{K}\\ ~ \\
      (\var{vk_s},~ \var{vk_d}) \leteq \dwho{c} & e_d \leteq \depoch{c}
      & (e_d,~ \var{vk_s}) \notin \var{eks} & 0 \leq e_d - e \leq 1 \\ ~ \\
      d \leteq 2 \cdot k & (s + d,~ (\var{vk_s},~ \wcard)) \notin \var{sds}\\
    }
    {
      {\left(\begin{array}{l}
       \mathcal{K}\\
        e\\
        s
      \end{array}\right)}
      \vdash
      {
        \left(
          \begin{array}{l}
            \var{sds}\\
            \var{eks}
          \end{array}
        \right)
      }
      \trans{sdeleg}{c}
      {
        \left(
          \begin{array}{l}
            \var{sds}; (s + d,~ (\var{vk_s},~ \var{vk_d}))\\
            \var{eks} \cup \{(e_d,~ \var{vk_s})\}
          \end{array}
        \right)
      }
    }
  \end{equation}
  \caption{Delegation scheduling rules}
  \label{fig:rules:delegation-scheduling}
\end{figure}

\clearpage

The rules in Figure~\ref{fig:rules:delegation} model the activation of
delegation certificates. Once a scheduled certificate becomes active
(see~\cref{sec:delegation-interface-rules}), the delegation map is changed by
it only if:
\begin{itemize}
\item The delegating key ($\var{vk_s}$) did not activate a delegation
  certificate in a slot greater or equal than the certificate slot ($s$). This
  check is performed to avoid having the constraint that the delegation
  certificates have to be activated in slot order.
\item The key being delegated to ($\var{vk_d}$) has not been delegated by
  another key (injectivity constraint).
\end{itemize}
The reason why we check that the delegation map is injective is to avoid a
potential risk (during the OBFT era) in which a malicious node gets control of
a genesis key $\var{vk_m}$ that issued the maximum number of blocks in a given
window. By delegating to another key $\var{vk_d}$, which was already delegated to
by some other key $\var{vk_g}$, the malicious node could prevent $\var{vk_g}$
from issuing blocks. Even though the delegation certificates take several slots
to become effective, the malicious node could calculate when the certificate
would become active, and issue a delegation certificate at the right time.

As an additional advantage, by having an injective delegation map, we are able
to simplify our specification when it comes to counting the blocks issued by
(delegates of) genesis keys.

Note also, that we could not impose the injectivity constraint in
Rule~\ref{eq:rule:delegation-scheduling} since we do not have information about
the delegations that will become effective. We could of course detect a
violation in the injectivity constraint when scheduling a delegation
certificate, but this will lead to a complex computation and larger state in
said rule.

Finally, note that we do not want to reject a scheduled delegation that would
violate the injectivity constraint (since delegation might not have been
scheduled by the node issuing the block). Instead, we simply ignore the
delegation certificate (Rule~\ref{eq:rule:delegation-nop}).

\begin{figure}[htb]
  \begin{align*}
    & \unionoverrideRight \in (A \mapsto B) \to (A \mapsto B) \to (A \mapsto B)
    & \text{union override}\\
    & d_0 \unionoverrideRight d_1 = d_1 \cup (\dom d_1 \subtractdom d_0)
  \end{align*}
  \caption{Functions used in delegation rules}
  \label{fig:funcs:delegation}
\end{figure}

\begin{figure}[htb]
  \emph{Delegation environments}
  \begin{equation*}
    \DEnv =
    \left(
      \begin{array}{r@{~\in~}lr}
        \mathcal{K} & \powerset{\VKeyGen} & \text{allowed delegators}
      \end{array}
    \right)
  \end{equation*}

  \emph{Delegation states}
  \begin{align*}
    & \DState
      = \left(
        \begin{array}{r@{~\in~}lr}
          \var{dms} & \VKeyGen \mapsto \VKey & \text{delegation map}\\
          \var{dws} & \VKeyGen \mapsto \Slot & \text{when last delegation occurred}\\
        \end{array}\right)
  \end{align*}
  \emph{Delegation transitions}
  \begin{equation*}
    \_ \vdash \_ \trans{adeleg}{\_} \_ \in
    \powerset (\DEnv \times \DState \times (\Slot \times (\VKeyGen \times \VKey)) \times \DState)
    \end{equation*}
  \caption{Delegation transition-system types}
  \label{fig:ts-types:delegation}
\end{figure}

\begin{figure}[htb]
  \begin{equation}
    \label{eq:adeleg-bootstrap}
    \inference
    {
      \var{dms_0} \leteq \Set{k \mapsto k}{k \in \mathcal{K}} &
      \var{dws_0} \leteq \Set{k \mapsto 0}{k \in \mathcal{K}}
    }
    {
      \left(
        \mathcal{K}
      \right)
      \vdash
      \trans{adeleg}{}
      \left(
        \begin{array}{l}
          \var{dms_0}\\
          \var{dws_0}
        \end{array}
      \right)
    }
  \end{equation}
  \nextdef
  \begin{equation}\label{eq:rule:delegation-change}
    \inference
    {
      \var{vk_d} \notin \range~\var{dms} & (\var{vk_s} \mapsto s_p \in \var{dws} \Rightarrow s_p < s)
    }
    {
      \left(\mathcal{K}\right)
      \vdash
      \left(
      \begin{array}{r}
        \var{dms}\\
        \var{dws}
      \end{array}
      \right)
      \trans{adeleg}{(s,~ (vk_s,~ vk_d))}
      \left(
      \begin{array}{lcl}
        \var{dms} & \unionoverrideRight & \{\var{vk_s} \mapsto \var{vk_d}\}\\
        \var{dws} & \unionoverrideRight & \{\var{vk_s} \mapsto s \}
      \end{array}
      \right)
    }
  \end{equation}
  \nextdef
  \begin{equation}\label{eq:rule:delegation-nop}
    \inference
    {\var{vk_d} \in \range~\var{dms} \vee (\var{vk_s} \mapsto s_p  \in \var{dws}  \wedge s \leq s_p)
    }
    {
      \left(\mathcal{K}\right)
      \vdash
      \left(
      \begin{array}{r}
        \var{dms}\\
        \var{dws}
      \end{array}
      \right)
      \trans{adeleg}{(s,~ (\var{vk_s},~ \var{vk_d}))}
      \left(
      \begin{array}{lcl}
        \var{dms}\\
        \var{dws}
      \end{array}
      \right)
    }
  \end{equation}
  \caption{Delegation inference rules}
  \label{fig:rules:delegation}
\end{figure}

\clearpage

\subsection{Delegation sequences}
\label{sec:delegation-sequences}

This section presents the rules that model the effect that sequences of
delegations have on the ledger.

\begin{figure}[htb]
  \begin{equation}
    \inference
    {
      {\begin{array}{l}
         \var{delegEnv}
      \end{array}}
      \vdash
      \trans{\hyperref[eq:sdeleg-bootstrap]{sdeleg}}{}
      \var{delegSt}
    }
    {
      {\begin{array}{l}
         \var{delegEnv}
      \end{array}}
      \vdash
      \trans{sdelegs}{}
      \var{delegSt}
    }
  \end{equation}
  \nextdef
  \begin{equation}
    \label{eq:rule:delegation-scheduling-seq-base}
    \inference
    {}
    {
      \var{delegEnv}
      \vdash
      \var{delegSt}
      \trans{sdelegs}{\epsilon}
      \var{delegSt}
    }
  \end{equation}
  \nextdef
  \begin{equation}
    \label{eq:rule:delegation-scheduling-seq-ind}
    \inference
    {
      \var{delegEnv}
      \vdash
      \var{delegSt}
      \trans{sdelegs}{\Gamma}
      \var{delegSt'}
      &
      \var{delegEnv}
      \vdash
      \var{delegSt'}
      \trans{\hyperref[fig:rules:delegation-scheduling]{sdeleg}}{c}
      \var{delegSt''}
    }
    {
      \var{delegEnv}
      \vdash
      \var{delegSt}
      \trans{sdelegs}{\Gamma; c}
      \var{delegSt''}
    }
  \end{equation}
  \caption{Delegation scheduling sequence rules}
  \label{fig:rules:delegation-scheduling-seq}
\end{figure}

\begin{figure}
  \begin{equation}
    \inference
    {
      {\begin{array}{l}
         \var{delegEnv}
      \end{array}}
      \vdash
      \trans{\hyperref[eq:adeleg-bootstrap]{adeleg}}{}
      \var{delegSt}
    }
    {
      {\begin{array}{l}
         \var{delegEnv}
      \end{array}}
      \vdash
      \trans{adelegs}{}
      \var{delegSt}
    }
  \end{equation}
  \nextdef
  \begin{equation}
    \label{eq:rule:delegation-seq-base}
    \inference
    {}
    {
      \var{delegEnv}
      \vdash
      \var{delegSt}
      \trans{adelegs}{\epsilon}
      \var{delegSt}
    }
  \end{equation}
  \nextdef
  \begin{equation}
    \label{eq:rule:delegation-seq-ind}
    \inference
    {
      \var{delegEnv}
      \vdash
      \var{delegSt}
      \trans{adelegs}{\Gamma}
      \var{delegSt'}
      &
      \var{delegEnv}
      \vdash
      \var{delegSt'}
      \trans{\hyperref[fig:rules:delegation]{adeleg}}{c}
      \var{delegSt''}
    }
    {
      \var{delegEnv}
      \vdash
      \var{delegSt}
      \trans{adelegs}{\Gamma; c}
      \var{delegSt''}
    }
  \end{equation}
  \caption{Delegations sequence rules}
  \label{fig:rules:delegation-seq}
\end{figure}

\subsection{Deviation from the \texttt{cardano-sl} implementation}
\label{sec:delegation:deviation-cardano-sl-imp}

In the \texttt{cardano-sl} implementation, the block issuer needs to include a
delegation certificate in the block, which witness the fact that a genesis key
gave the issuer the rights of issuing blocks on behalf of this genesis key. The
reasons why this was implemented in this way in \texttt{cardano-sl} are not
clear, since the delegation certificates are posted on the chain, so the ledger
state contains the information about who delegates to whom. Hence in the
current specification we use a heavyweight delegation scheme, i.e. where the
certificates are posted on the chain, but an implementation of this rules that
aims at being compatible with the implementation in \texttt{cardano-sl} has to
take the fact that delegation certificates are also present in a block into
account.